diff --git a/.gitignore b/.gitignore index 5b1e700..fefd354 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ sdkconfig.old /.vscode /.cache /managed_components +/03_QMI8658 +/.github diff --git a/assets/emotions/blink.json b/assets/emotions/blink.json new file mode 100644 index 0000000..1bc0616 --- /dev/null +++ b/assets/emotions/blink.json @@ -0,0 +1 @@ +{"fr":60,"h":448,"ip":0,"layers":[{"ind":3,"ty":4,"parent":2,"ks":{},"ip":0,"op":37,"st":0,"shapes":[{"ty":"rc","p":{"a":1,"k":[{"t":0,"s":[48.5,68],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":2.952,"s":[48.5,13.753],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":5.898,"s":[48.5,-2.831],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":11.802,"s":[48.5,0.118],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":17.76,"s":[48.5,-0.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":18,"s":[48.5,-0.005],"h":1},{"t":18,"s":[48.5,0],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":20.952,"s":[48.5,54.247],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":23.898,"s":[48.5,70.831],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":29.802,"s":[48.5,67.882],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":35.76,"s":[48.5,68.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":36,"s":[48.5,68.005],"h":1}]},"r":{"a":0,"k":20},"s":{"a":1,"k":[{"t":0,"s":[97,136],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":2.952,"s":[97,27.505],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":5.898,"s":[97,-5.662],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":11.802,"s":[97,0.236],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":17.76,"s":[97,-0.01],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":18,"s":[97,-0.01],"h":1},{"t":18,"s":[97,0],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":20.952,"s":[97,108.495],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":23.898,"s":[97,141.662],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":29.802,"s":[97,135.764],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":35.76,"s":[97,136.01],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":36,"s":[97,136.01],"h":1}]}},{"ty":"fl","c":{"a":0,"k":[1,1,1]},"o":{"a":0,"k":100}}]},{"ind":2,"ty":3,"parent":1,"ks":{"p":{"a":1,"k":[{"t":0,"s":[211,88],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":2.952,"s":[211,142.247],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":5.898,"s":[211,158.831],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":11.802,"s":[211,155.882],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":17.76,"s":[211,156.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":18,"s":[211,156.005],"h":1},{"t":18,"s":[211,156],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":20.952,"s":[211,101.753],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":23.898,"s":[211,85.169],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":29.802,"s":[211,88.118],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":35.76,"s":[211,87.995],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":36,"s":[211,87.995],"h":1}]}},"ip":0,"op":37,"st":0},{"ind":5,"ty":4,"parent":4,"ks":{},"ip":0,"op":37,"st":0,"shapes":[{"ty":"rc","p":{"a":1,"k":[{"t":0,"s":[48.5,66],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":2.952,"s":[48.5,13.348],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":5.898,"s":[48.5,-2.748],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":11.802,"s":[48.5,0.114],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":17.76,"s":[48.5,-0.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":18,"s":[48.5,-0.005],"h":1},{"t":18,"s":[48.5,0],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":20.952,"s":[48.5,54.247],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":23.898,"s":[48.5,70.831],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":29.802,"s":[48.5,67.882],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":35.76,"s":[48.5,68.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":36,"s":[48.5,68.005],"h":1}]},"r":{"a":0,"k":20},"s":{"a":1,"k":[{"t":0,"s":[97,132],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":2.952,"s":[97,26.696],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":5.898,"s":[97,-5.496],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":11.802,"s":[97,0.229],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":17.76,"s":[97,-0.01],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":18,"s":[97,-0.009],"h":1},{"t":18,"s":[97,0],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":20.952,"s":[97,108.495],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":23.898,"s":[97,141.662],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":29.802,"s":[97,135.764],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":35.76,"s":[97,136.01],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":36,"s":[97,136.01],"h":1}]}},{"ty":"fl","c":{"a":0,"k":[1,1,1]},"o":{"a":0,"k":100}}]},{"ind":4,"ty":3,"parent":1,"ks":{"a":{"a":1,"k":[{"t":0,"s":[48.5,66],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":2.952,"s":[48.5,13.348],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":5.898,"s":[48.5,-2.748],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":11.802,"s":[48.5,0.114],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":17.76,"s":[48.5,-0.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":18,"s":[48.5,-0.005],"h":1},{"t":18,"s":[48.5,0],"i":{"x":[1,0.537],"y":[1,0.625]},"o":{"x":[0,0.283],"y":[0,0.035]}},{"t":20.952,"s":[48.5,54.247],"i":{"x":[1,0.69],"y":[1,0.998]},"o":{"x":[0,0.343],"y":[0,0.908]}},{"t":23.898,"s":[48.5,70.831],"i":{"x":[1,0.282],"y":[1,0.996]},"o":{"x":[0,0.262],"y":[0,0.033]}},{"t":29.802,"s":[48.5,67.882],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":35.76,"s":[48.5,68.005],"i":{"x":[1,1],"y":[1,1]},"o":{"x":[0,0],"y":[0,0]}},{"t":36,"s":[48.5,68.005],"h":1}]},"p":{"a":0,"k":[108.5,157]}},"ip":0,"op":37,"st":0},{"ind":1,"ty":3,"parent":0,"ks":{},"ip":0,"op":37,"st":0},{"ind":6,"ty":4,"parent":0,"ks":{},"ip":0,"op":37,"st":0,"shapes":[{"ty":"rc","p":{"a":0,"k":[184,224]},"r":{"a":0,"k":0},"s":{"a":0,"k":[368,448]}},{"ty":"fl","c":{"a":0,"k":[0,0,0]},"o":{"a":0,"k":100}}]},{"ind":0,"ty":3,"ks":{},"ip":0,"op":37,"st":0}],"meta":{"g":"https://jitter.video"},"op":36,"v":"5.7.4","w":368} \ No newline at end of file diff --git a/components/SensorLib/CMakeLists.txt b/components/SensorLib/CMakeLists.txt new file mode 100644 index 0000000..04dcf14 --- /dev/null +++ b/components/SensorLib/CMakeLists.txt @@ -0,0 +1,10 @@ +set(src_dirs ./src + ./src/touch + ./src/platform) +set(include_dirs ./src + ./src/REG + ./src/touch + ./src/platform) +idf_component_register(SRC_DIRS ${src_dirs} + INCLUDE_DIRS ${include_dirs} + REQUIRES esp_timer esp_driver_gpio driver) diff --git a/components/SensorLib/src/DevicesPins.h b/components/SensorLib/src/DevicesPins.h new file mode 100644 index 0000000..0381c0f --- /dev/null +++ b/components/SensorLib/src/DevicesPins.h @@ -0,0 +1,95 @@ +/** + * @file DevicesPins.h + * @author Lewis He (lewishe@outlook.com) + * @license MIT + * @copyright Copyright (c) 2024 ShenZhen XinYuan Electronic Technology Co., Ltd + * @date 2024-09-14 + * + */ +#pragma once + + +#if defined(ARDUINO_T_DECK) +// T-Deck GT911 +#define SENSOR_SDA 18 +#define SENSOR_SCL 8 +#define SENSOR_IRQ 16 +#define SENSOR_RST -1 +#elif defined(ARDUINO_T_AMOLED_191) +// T-Display-AMOLED 1.91 Inch CST816T✅ +#define SENSOR_SDA 3 +#define SENSOR_SCL 2 +#define SENSOR_IRQ 21 +#define SENSOR_RST -1 +#elif defined(ARDUINO_T_AMOLED_191_QWIIC) +// T-Display-AMOLED 1.91 Inch QWIIC +#define SENSOR_SDA 3 +#define SENSOR_SCL 2 +#define SENSOR_IRQ TX +#define SENSOR_RST RX +#elif defined(ARDUINO_T_AMOLED_241) +// T4-S3 CST226SE ✅ +#define SENSOR_SDA 6 +#define SENSOR_SCL 7 +#define SENSOR_IRQ 8 +#define SENSOR_RST 17 +#elif defined(ARDUINO_T_AMOLED_147) +// T-Display-Lite 1.47 Inch CHSC5816 ✅ +#define SENSOR_SDA 1 +#define SENSOR_SCL 2 +#define SENSOR_IRQ 13 +#define SENSOR_RST 14 +#elif defined(ARDUINO_T_DISPLAY_S3_PRO) +// T-Display-S3-Pro CST226SE✅ +#define SENSOR_SDA 5 +#define SENSOR_SCL 6 +#define SENSOR_IRQ 7 +#define SENSOR_RST 13 +#elif defined(ARDUINO_T_DISPLAY_S3) +// T-Display-S3 CST816T✅ +#define SENSOR_SDA 18 +#define SENSOR_SCL 17 +#define SENSOR_IRQ 16 +#define SENSOR_RST 21 +#elif defined(ARDUINO_T_EPD47_S3) +// T-EPD47 S3 GT911 2 Point touch✅ +#define SENSOR_SDA 6 +#define SENSOR_SCL 5 +#define SENSOR_IRQ 15 +#define SENSOR_RST 41 +#elif defined(ARDUINO_T_WATCH_S3_U) +// T-Watch-S3-U +#define SENSOR_SDA 2 +#define SENSOR_SCL 3 +#define SENSOR_IRQ 12 +#define SENSOR_RST 16 + +#endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/SensorLib/src/ExtensionIOXL9555.hpp b/components/SensorLib/src/ExtensionIOXL9555.hpp new file mode 100644 index 0000000..890e543 --- /dev/null +++ b/components/SensorLib/src/ExtensionIOXL9555.hpp @@ -0,0 +1,291 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file ExtensionIOXL9555.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2022-12-27 + * + */ +#pragma once + +#include "REG/XL9555Constants.h" +#include "SensorCommon.tpp" +#include "ExtensionSPI.tpp" + + +typedef void (*gpio_event_t)(void *user_data); +typedef struct ioEvent { + uint8_t mode; + gpio_event_t cb; + void *user_data; + uint8_t last_state; + ioEvent() : mode(0), cb(NULL), user_data(NULL), last_state(LOW) + { + } +} ioEvent_t; + + + +class ExtensionIOXL9555 : + public SensorCommon, + public ExtensionSPI +{ + friend class SensorCommon; + friend class ExtensionSPI; +public: + + + enum { + PORT0, + PORT1, + }; + + enum ExtensionGPIO { + IO0, + IO1, + IO2, + IO3, + IO4, + IO5, + IO6, + IO7, + IO8, + IO9, + IO10, + IO11, + IO12, + IO13, + IO14, + IO15, + }; + + +#if defined(ARDUINO) + ExtensionIOXL9555(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = XL9555_UNKOWN_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + ExtensionIOXL9555() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = XL9555_UNKOWN_ADDRESS; + } + + ~ExtensionIOXL9555() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = XL9555_UNKOWN_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + + void pinMode(uint8_t pin, uint8_t mode) + { + uint8_t registers = 0; + if (pin >= IO8) { + pin -= IO8; + registers = XL9555_CTRL_CFG1; + } else { + registers = XL9555_CTRL_CFG0; + } + switch (mode) { + case INPUT: + setRegisterBit(registers, pin); + break; + case OUTPUT: + clrRegisterBit(registers, pin); + break; + default: + break; + } + } + + int digitalRead(uint8_t pin) + { + uint8_t registers = 0; + if (pin >= IO8) { + pin -= IO8; + registers = XL9555_CTRL_INP1; + } else { + registers = XL9555_CTRL_INP0; + } + return getRegisterBit(registers, pin); + } + + void digitalWrite(uint8_t pin, uint8_t val) + { + uint8_t registers = 0; + if (pin >= IO8) { + pin -= IO8; + registers = XL9555_CTRL_OUTP1; + } else { + registers = XL9555_CTRL_OUTP0; + } + val ? setRegisterBit(registers, pin) : clrRegisterBit(registers, pin); + } + + // Invert gpio + void digitalToggle(uint8_t pin) + { + int state = 1 - digitalRead(pin); + digitalWrite(pin, state); + } + + // Read 8-bit gpio input status + int readPort(uint8_t port) + { + return readRegister(port == PORT0 ? XL9555_CTRL_INP0 : XL9555_CTRL_INP1); + } + + // Write 8 bits of data to the specified port + int writePort(uint8_t port, uint8_t mask) + { + return writeRegister(port == PORT0 ? XL9555_CTRL_OUTP0 : XL9555_CTRL_OUTP1, mask); + } + + // Read 16-bit gpio input status + uint16_t read() + { + uint16_t val = 0x0; + readRegister(XL9555_CTRL_INP0, (uint8_t *)&val, 2); + return val; + } + + // Write 16-bit data to gpio, low bit port 0 + void write(uint16_t value) + { + uint8_t buffer[2] = {highByte(value), lowByte(value)}; + writeRegister(XL9555_CTRL_OUTP0, buffer, 2); + } + + // Read the specified port configuration status + int readConfig(uint8_t port) + { + return readRegister(port == PORT0 ? XL9555_CTRL_CFG0 : XL9555_CTRL_CFG1); + } + + // Configure the specified port as input or output , 0xFF = all pin input , 0x00 = all pin output + int configPort(uint8_t port, uint8_t mask) + { + return writeRegister(port == PORT0 ? XL9555_CTRL_CFG0 : XL9555_CTRL_CFG1, mask); + } + + void setPinEvent(uint8_t pin, uint8_t mode, gpio_event_t event, void *user_data) + { + if (pin > XL9555_MAX_PIN) { + log_e("XL9555 Max use io pin is 0 ~ 15 ."); + return; + } + this->event[pin].cb = event; + this->event[pin].mode = mode; + this->event[pin].user_data = user_data; + } + + void removePinEvent(uint8_t pin) + { + if (pin > XL9555_MAX_PIN) { + log_e("XL9555 Max use io pin is 0 ~ 15 ."); + return; + } + this->event[pin].cb = NULL; + } + + void update() + { + uint16_t val = this->read(); + + int i = XL9555_MAX_PIN; + + for (; i >= 0; i--) { + + uint8_t _index = XL9555_MAX_PIN - i; + + if (this->event[_index].cb != NULL) { + + if (!(val & 1)) { + if (this->event[_index].mode == LOW) { + this->event[_index].cb(this->event[_index].user_data); + } + this->event[_index].last_state = LOW; + } else { + if (this->event[_index].mode == HIGH && this->event[_index].last_state == LOW) { + this->event[_index].cb(this->event[_index].user_data); + } + this->event[_index].last_state = HIGH; + } + } + val >>= 1; + } + } + +private: + bool initImpl() + { + if (__addr == XL9555_UNKOWN_ADDRESS) { + for (uint8_t addr = XL9555_SLAVE_ADDRESS0; addr <= XL9555_SLAVE_ADDRESS7; ++addr) { + if (probe(addr)) { + log_e("Find the xl9555 chip address is 0x%X", addr); + __addr = addr; + return true; + } + } + log_e("No find the xl9555 chip ..."); + return false; + } + return probe(); + } + + int getReadMaskImpl() + { + return -1; + } + + ioEvent_t event[16]; + +protected: + +}; + + + diff --git a/components/SensorLib/src/ExtensionSPI.tpp b/components/SensorLib/src/ExtensionSPI.tpp new file mode 100644 index 0000000..2c002cc --- /dev/null +++ b/components/SensorLib/src/ExtensionSPI.tpp @@ -0,0 +1,124 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2024 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file ExtensionSPI.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2024-01-19 + * + */ +#pragma once + +#include "SensorLib.h" + +template +class ExtensionSPI +{ +public: + void beginSPI(int mosi, + int miso, + int sck, + int cs + ) + { + _mosi = mosi; + _miso = miso; + _sck = sck; + _cs = cs; + + thisChip().pinMode(_mosi, OUTPUT); + thisChip().pinMode(_sck, OUTPUT); + + if (_cs != SENSOR_PIN_NONE) { + thisChip().pinMode(_cs, OUTPUT); + thisChip().digitalWrite(_cs, HIGH); + } + + if (_miso != SENSOR_PIN_NONE) { + thisChip().pinMode(_miso, INPUT); + } + thisChip().digitalWrite(_mosi, HIGH); + thisChip().digitalWrite(_sck, HIGH); + + } + + void setBitOrder(uint8_t order) + { + _order = order & 1; + } + + uint8_t transfer8(uint8_t val) + { + return transferDataBits(val, 8); + } + + uint16_t transfer9(uint16_t val) + { + return transferDataBits(val, 9); + } + + uint32_t transferDataBits(uint32_t val, uint32_t bits) + { + uint32_t mask = _BV(bits - 1); + uint8_t out = 0; + if (_cs != SENSOR_PIN_NONE) { + thisChip().digitalWrite(_cs, LOW); + } + for (int i = 0; i < bits ; i++) { + thisChip().digitalWrite(_sck, LOW); + out <<= 1; + if (_miso != SENSOR_PIN_NONE) { + if (thisChip().digitalRead(_miso)) { + out |= 0x01; + } + } + thisChip().digitalWrite(_mosi, val & mask ? HIGH : LOW); + val <<= 1; + thisChip().digitalWrite(_sck, HIGH); + } + if (_cs != SENSOR_PIN_NONE) { + thisChip().digitalWrite(_cs, HIGH); + } + return out; + } + + +protected: + + inline const chipType &thisChip() const + { + return static_cast(*this); + } + + inline chipType &thisChip() + { + return static_cast(*this); + } + +private: + int _mosi; + int _sck; + int _miso; + int _order; + int _cs; +}; \ No newline at end of file diff --git a/components/SensorLib/src/REG/BMA423Constants.h b/components/SensorLib/src/REG/BMA423Constants.h new file mode 100644 index 0000000..d969cbd --- /dev/null +++ b/components/SensorLib/src/REG/BMA423Constants.h @@ -0,0 +1,726 @@ +#pragma once + + +#define BMA423_SLAVE_ADDRESS (0x19) + + +#define BAM423_SENSOR_RESOLUTION (12) + +#define BMA423_RESET_REG (0x7E) + +/**\name CHIP ID ADDRESS*/ +#define BMA4_CHIP_ID_ADDR (0x00) + +/**\name Chip ID of BMA423 sensor */ +#define BMA423_CHIP_ID (0x13) + +/**\name POWER_CTRL REGISTER*/ +#define BMA4_POWER_CONF_ADDR (0x7C) +#define BMA4_POWER_CTRL_ADDR (0x7D) + + +/**\name ADVANCE POWER SAVE POSITION AND MASK*/ +#define BMA4_ADVANCE_POWER_SAVE_MSK (0x01) + +/**\name MAP INTERRUPT 1 and 2 REGISTERS*/ +#define BMA4_INT_MAP_1_ADDR (0X56) +#define BMA4_INT_MAP_2_ADDR (0X57) +#define BMA4_INT_MAP_DATA_ADDR (0x58) +#define BMA4_INIT_CTRL_ADDR (0x59) + + +/**\name FEATURE CONFIG RELATED */ +#define BMA4_RESERVED_REG_5B_ADDR (0x5B) +#define BMA4_RESERVED_REG_5C_ADDR (0x5C) +#define BMA4_FEATURE_CONFIG_ADDR (0x5E) +#define BMA4_INTERNAL_ERROR (0x5F) + +/**\name GPIO REGISTERS*/ +#define BMA4_STEP_CNT_OUT_0_ADDR (0x1E) +#define BMA4_HIGH_G_OUT_ADDR (0x1F) +#define BMA4_ACTIVITY_OUT_ADDR (0x27) +#define BMA4_ORIENTATION_OUT_ADDR (0x28) +#define BMA4_INTERNAL_STAT (0x2A) + + + + +/**\name SENSOR TIME REGISTERS*/ +#define BMA4_SENSORTIME_0_ADDR (0X18) + +/**\name INTERRUPT/FEATURE STATUS REGISTERS*/ +#define BMA4_INT_STAT_0_ADDR (0X1C) + +/**\name INTERRUPT/FEATURE STATUS REGISTERS*/ +#define BMA4_INT_STAT_1_ADDR (0X1D) + +/**\name BUS READ AND WRITE LENGTH FOR MAG & ACCEL*/ +#define BMA4_MAG_TRIM_DATA_SIZE (16) +#define BMA4_MAG_XYZ_DATA_LENGTH (6) +#define BMA4_MAG_XYZR_DATA_LENGTH (8) +#define BMA4_ACCEL_DATA_LENGTH (6) +#define BMA4_FIFO_DATA_LENGTH (2) +#define BMA4_TEMP_DATA_SIZE (1) + +/**\name AUX/ACCEL DATA BASE ADDRESS REGISTERS*/ +#define BMA4_DATA_0_ADDR (0X0A) +#define BMA4_DATA_8_ADDR (0X12) + + +/**\name Feature offset address */ +#define BMA423_ANY_NO_MOTION_OFFSET (0x00) +#define BMA423_STEP_CNTR_OFFSET (0x36) +#define BMA423_STEP_CNTR_PARAM_OFFSET (0x04) +#define BMA423_WAKEUP_OFFSET (0x38) +#define BMA423_TILT_OFFSET (0x3A) +#define BMA423_CONFIG_ID_OFFSET (0x3C) +#define BMA423_AXES_REMAP_OFFSET (0x3E) + +/**\name Sensor feature size */ +#define BMA423_FEATURE_SIZE (64) +#define BMA423_ANYMOTION_EN_LEN (2) +#define BMA423_RD_WR_MIN_LEN (2) + +/**************************************************************/ +/**\name Remap Axes */ +/**************************************************************/ +#define BMA423_X_AXIS_MASK (0x03) +#define BMA423_X_AXIS_SIGN_MASK (0x04) +#define BMA423_Y_AXIS_MASK (0x18) +#define BMA423_Y_AXIS_SIGN_MASK (0x20) +#define BMA423_Z_AXIS_MASK (0xC0) +#define BMA423_Z_AXIS_SIGN_MASK (0x01) + + + +/**\name ACCELEROMETER ENABLE POSITION AND MASK*/ +#define BMA4_ACCEL_ENABLE_MSK (0x04) +#define BMA4_ASIC_INITIALIZED (0x01) + +#define BMA4_CONFIG_STREAM_SIZE (6144) + + +/**\name Feature configuration file */ +static const unsigned char bma423_config_file[] = { + 0x80, 0x2e, 0xfc, 0x00, 0x80, 0x2e, 0xfe, 0x00, 0xc8, 0x2e, 0x00, 0x2e, + 0x80, 0x2e, 0xfa, 0x00, 0x80, 0x2e, 0x23, 0xb1, 0x80, 0x2e, 0xfd, 0x00, + 0x80, 0x2e, 0xfb, 0x00, 0x80, 0x2e, 0x5a, 0xb1, 0x50, 0x39, 0x21, 0x2e, + 0xb0, 0xf0, 0x10, 0x30, 0x21, 0x2e, 0x16, 0xf0, 0x80, 0x2e, 0xfc, 0x01, + 0x5d, 0x50, 0x45, 0x52, 0x01, 0x42, 0x3b, 0x80, 0x41, 0x30, 0x01, 0x42, + 0x3c, 0x80, 0x00, 0x2e, 0x01, 0x40, 0x01, 0x42, 0x21, 0x2e, 0xff, 0xaf, + 0xb8, 0x2e, 0xb6, 0xd6, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0xfd, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x24, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x2e, + 0x99, 0x01, 0x20, 0x26, 0x98, 0x2e, 0xf6, 0x00, 0x98, 0x2e, 0xe9, 0x01, + 0x10, 0x30, 0x21, 0x2e, 0x59, 0xf0, 0x98, 0x2e, 0xd8, 0x00, 0x00, 0x2e, + 0x00, 0x2e, 0xd0, 0x2e, 0x98, 0x2e, 0xdd, 0x00, 0x01, 0x2e, 0x56, 0x00, + 0x00, 0xb2, 0x11, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0x56, 0x00, 0x41, 0x50, + 0x98, 0x2e, 0xcc, 0xb0, 0x41, 0x50, 0x98, 0x2e, 0x8f, 0xb4, 0x01, 0x2e, + 0x03, 0xf0, 0x0d, 0xbc, 0x0f, 0xb8, 0x00, 0x90, 0x02, 0x2f, 0x45, 0x50, + 0x21, 0x2e, 0xbc, 0xf0, 0x01, 0x2e, 0x55, 0x00, 0x00, 0xb2, 0x1a, 0x2f, + 0x00, 0x30, 0x21, 0x2e, 0x55, 0x00, 0x43, 0x50, 0x98, 0x2e, 0xcc, 0xb0, + 0x43, 0x50, 0x98, 0x2e, 0xdc, 0xb1, 0x43, 0x50, 0x98, 0x2e, 0x92, 0xb5, + 0x43, 0x50, 0x98, 0x2e, 0x00, 0xb0, 0x01, 0x2e, 0x1c, 0x01, 0x0f, 0xbc, + 0x0f, 0xb8, 0x00, 0x90, 0x45, 0x50, 0x02, 0x2f, 0x21, 0x2e, 0xbc, 0xf0, + 0x02, 0x2d, 0x21, 0x2e, 0xba, 0xf0, 0x98, 0x2e, 0xd8, 0x00, 0xc3, 0x2d, + 0x01, 0x2e, 0x55, 0xf0, 0xc0, 0x2e, 0x21, 0x2e, 0x55, 0xf0, 0x03, 0x2e, + 0x00, 0xf0, 0x45, 0x54, 0x01, 0x2e, 0x59, 0xf0, 0x4a, 0x0e, 0x02, 0x2f, + 0xf1, 0x33, 0x0d, 0x2c, 0x01, 0x08, 0xf2, 0x30, 0x4a, 0x08, 0x79, 0x84, + 0x82, 0xa2, 0x04, 0x2f, 0x02, 0x34, 0x82, 0x0a, 0x47, 0xa2, 0x03, 0x2c, + 0x10, 0x22, 0x45, 0x52, 0x01, 0x0a, 0xc0, 0x2e, 0x21, 0x2e, 0x59, 0xf0, + 0x00, 0x31, 0xc0, 0x2e, 0x21, 0x2e, 0xba, 0xf0, 0xc8, 0x2e, 0xc8, 0x2e, + 0xc8, 0x2e, 0xc8, 0x2e, 0xc8, 0x2e, 0x44, 0x47, 0xaa, 0x00, 0x05, 0x00, + 0x2d, 0x01, 0xd4, 0x7b, 0x3b, 0x01, 0xdb, 0x7a, 0x04, 0x00, 0x3f, 0x7b, + 0xcd, 0x6c, 0xc3, 0x04, 0x85, 0x09, 0xc3, 0x04, 0xec, 0xe6, 0x0c, 0x46, + 0x01, 0x00, 0x27, 0x00, 0x19, 0x00, 0x96, 0x00, 0xa0, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0xf0, 0x3c, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x43, 0x28, 0x88, 0x00, + 0x52, 0x00, 0x4f, 0x00, 0x80, 0x00, 0x5b, 0x00, 0x00, 0x40, 0xaf, 0x00, + 0xff, 0x00, 0xff, 0xb7, 0x00, 0x02, 0x00, 0xb0, 0x05, 0x80, 0xb1, 0xf0, + 0xc0, 0x00, 0x00, 0x01, 0x5e, 0xf0, 0x39, 0xf0, 0x89, 0xf0, 0x00, 0x20, + 0xff, 0x7f, 0x7d, 0x00, 0x5e, 0x00, 0x62, 0x00, 0x7c, 0x00, 0xff, 0xfb, + 0x52, 0xf0, 0x56, 0xf0, 0x33, 0x09, 0x33, 0x07, 0x00, 0x08, 0x90, 0x01, + 0x00, 0xf8, 0x67, 0x00, 0x4c, 0x04, 0xa0, 0x00, 0xe8, 0x03, 0x81, 0x00, + 0x82, 0x00, 0x6a, 0x00, 0x6d, 0x00, 0x6c, 0x00, 0xeb, 0x07, 0xae, 0x07, + 0x72, 0x00, 0x6f, 0x00, 0xa1, 0x01, 0x1e, 0x05, 0x47, 0xfd, 0x73, 0x00, + 0x77, 0x00, 0x79, 0x00, 0x76, 0x00, 0xcc, 0x00, 0x30, 0x50, 0x50, 0x40, + 0x00, 0x18, 0x50, 0x40, 0x56, 0x25, 0x47, 0x25, 0x00, 0x18, 0x2e, 0x00, + 0x41, 0x40, 0xa7, 0x02, 0x09, 0x18, 0xc6, 0x00, 0xfb, 0x7f, 0x00, 0x30, + 0x49, 0x52, 0x05, 0x30, 0x05, 0x2c, 0x17, 0x03, 0x1e, 0xbd, 0xd2, 0xba, + 0x92, 0xb8, 0x6a, 0x0b, 0x61, 0x0e, 0xf9, 0x2f, 0x61, 0x1a, 0x01, 0x2f, + 0x5d, 0x0e, 0xf5, 0x2f, 0xd4, 0x7f, 0x02, 0x30, 0x1f, 0x2c, 0xe3, 0x7f, + 0x85, 0x01, 0xd1, 0x03, 0x7c, 0x0e, 0x03, 0x2f, 0x7c, 0x1a, 0x0f, 0x2f, + 0x73, 0x0f, 0x0d, 0x2f, 0xe3, 0x6f, 0xde, 0x04, 0x5f, 0xba, 0x11, 0xbf, + 0xb4, 0x0b, 0xd4, 0x6f, 0x27, 0x07, 0xb3, 0x25, 0xd1, 0xbf, 0xeb, 0x7f, + 0x07, 0x00, 0xb4, 0x25, 0x96, 0x02, 0xdb, 0x7f, 0x2f, 0xbf, 0x9e, 0xbf, + 0x01, 0xb8, 0xd2, 0xba, 0x21, 0xb9, 0x92, 0xb8, 0x06, 0x0a, 0x6f, 0x0b, + 0x40, 0x90, 0xdf, 0x2f, 0x40, 0x91, 0xdd, 0x2f, 0xfb, 0x6f, 0xd0, 0x5f, + 0xb8, 0x2e, 0x57, 0x50, 0x41, 0x30, 0x02, 0x40, 0x51, 0x0a, 0x01, 0x42, + 0x18, 0x82, 0x4b, 0x50, 0x60, 0x42, 0x70, 0x3c, 0x4d, 0x54, 0x42, 0x42, + 0x69, 0x82, 0x82, 0x32, 0x43, 0x40, 0x18, 0x08, 0x02, 0x0a, 0x40, 0x42, + 0x42, 0x80, 0x02, 0x3f, 0x01, 0x40, 0x10, 0x50, 0x4a, 0x08, 0xfb, 0x7f, + 0x11, 0x42, 0x0b, 0x31, 0x0b, 0x42, 0x3e, 0x80, 0x01, 0x32, 0x01, 0x42, + 0x00, 0x2e, 0x01, 0x2e, 0x40, 0xf0, 0x13, 0x90, 0x20, 0x2f, 0x03, 0x30, + 0x51, 0x50, 0x4f, 0x54, 0xf4, 0x34, 0x06, 0x30, 0x55, 0x52, 0x55, 0x32, + 0x1d, 0x1a, 0xe3, 0x22, 0x18, 0x1a, 0x53, 0x58, 0xe3, 0x22, 0x04, 0x30, + 0xd5, 0x40, 0xb5, 0x0d, 0xe1, 0xbe, 0x6f, 0xbb, 0x80, 0x91, 0xa9, 0x0d, + 0x01, 0x89, 0xb5, 0x23, 0x10, 0xa1, 0xf7, 0x2f, 0xda, 0x0e, 0xf4, 0x34, + 0xeb, 0x2f, 0x01, 0x2e, 0x25, 0x00, 0x70, 0x1a, 0x00, 0x30, 0x21, 0x30, + 0x02, 0x2c, 0x08, 0x22, 0x30, 0x30, 0x00, 0xb2, 0x06, 0x2f, 0x21, 0x2e, + 0x59, 0xf0, 0x98, 0x2e, 0xd8, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, + 0xfb, 0x6f, 0xf0, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0xb1, 0xf0, 0x59, 0x52, + 0x01, 0x0a, 0x21, 0x2e, 0xb1, 0xf0, 0x01, 0x2e, 0x1c, 0x01, 0x0f, 0xbc, + 0x0f, 0xb8, 0x00, 0x90, 0x45, 0x50, 0x02, 0x2f, 0xc0, 0x2e, 0x21, 0x2e, + 0xbc, 0xf0, 0xc0, 0x2e, 0x21, 0x2e, 0xba, 0xf0, 0x1a, 0x24, 0x26, 0x00, + 0x80, 0x2e, 0x8f, 0x00, 0x03, 0x2e, 0x01, 0x01, 0x05, 0x2e, 0x01, 0x01, + 0x92, 0xbd, 0x20, 0x50, 0x03, 0x2e, 0x01, 0x01, 0xbf, 0xba, 0x21, 0xbd, + 0x2f, 0xbb, 0x1f, 0xba, 0x40, 0x91, 0xf0, 0x7f, 0x04, 0x2f, 0x80, 0x91, + 0x02, 0x2f, 0x00, 0xb3, 0x90, 0x2e, 0xc7, 0xb0, 0x03, 0x2e, 0x7b, 0x00, + 0x01, 0x80, 0x40, 0x90, 0x14, 0x2f, 0x41, 0x84, 0xf1, 0x6f, 0x25, 0x2e, + 0x7b, 0x00, 0x41, 0x40, 0x23, 0x2e, 0x5a, 0x00, 0x47, 0x52, 0x12, 0x40, + 0x52, 0x42, 0x02, 0x30, 0x00, 0x40, 0x40, 0x42, 0xe0, 0x5f, 0x25, 0x2e, + 0x57, 0x00, 0x25, 0x2e, 0x58, 0x00, 0x25, 0x2e, 0x5d, 0x00, 0xb8, 0x2e, + 0x07, 0x2e, 0x00, 0x01, 0x03, 0x2e, 0x01, 0x01, 0x05, 0x2e, 0x00, 0x01, + 0x24, 0xbd, 0x0f, 0x2e, 0x59, 0x00, 0xb5, 0xbd, 0x93, 0xbc, 0x2f, 0xb9, + 0xb5, 0xb9, 0x93, 0xb8, 0x3a, 0x1a, 0x06, 0x2f, 0x07, 0x30, 0x25, 0x2e, + 0x59, 0x00, 0x2f, 0x2e, 0x57, 0x00, 0x2f, 0x2e, 0x58, 0x00, 0x40, 0xb3, + 0x05, 0x30, 0x07, 0x30, 0x0a, 0x2f, 0xf7, 0x6f, 0xe6, 0x7f, 0x00, 0x2e, + 0xc6, 0x41, 0x0f, 0x2e, 0x5a, 0x00, 0xb7, 0x05, 0x80, 0xa9, 0xee, 0x05, + 0xf7, 0x23, 0xe6, 0x6f, 0x80, 0xb3, 0x06, 0x30, 0x09, 0x2f, 0xe7, 0x7f, + 0x00, 0x2e, 0x06, 0x40, 0x0f, 0x2e, 0x5b, 0x00, 0xb7, 0x05, 0x80, 0xa9, + 0xee, 0x05, 0xb7, 0x23, 0xe7, 0x6f, 0x00, 0xb3, 0x04, 0x30, 0x0b, 0x2f, + 0xf4, 0x6f, 0x02, 0x89, 0xe7, 0x7f, 0x00, 0x2e, 0x04, 0x41, 0x0f, 0x2e, + 0x5c, 0x00, 0x27, 0x05, 0x00, 0xa9, 0xec, 0x05, 0x27, 0x23, 0xe7, 0x6f, + 0x7b, 0x0f, 0x17, 0x30, 0x0b, 0x2f, 0x73, 0x0f, 0x05, 0x30, 0x17, 0x30, + 0x07, 0x2f, 0x63, 0x0f, 0x15, 0x30, 0x17, 0x30, 0x00, 0x2f, 0x07, 0x30, + 0xe3, 0x0e, 0x00, 0x2f, 0x05, 0x30, 0x80, 0x90, 0x05, 0x2e, 0x57, 0x00, + 0x13, 0x30, 0x13, 0x29, 0xf2, 0x6f, 0x47, 0x5c, 0x17, 0x2f, 0xc0, 0x91, + 0x05, 0x30, 0x0b, 0x2f, 0x07, 0x2e, 0x58, 0x00, 0xc1, 0x86, 0x2b, 0x2e, + 0x57, 0x00, 0x59, 0x0e, 0x27, 0x2e, 0x58, 0x00, 0x24, 0x2f, 0x2b, 0x2e, + 0x5d, 0x00, 0x22, 0x2d, 0x61, 0x0e, 0x29, 0x2e, 0x57, 0x00, 0x2b, 0x2e, + 0x58, 0x00, 0x1b, 0x2f, 0x27, 0x2e, 0x5d, 0x00, 0x19, 0x2d, 0x40, 0x91, + 0x05, 0x2f, 0x01, 0x30, 0x23, 0x2e, 0x57, 0x00, 0x23, 0x2e, 0x5d, 0x00, + 0x06, 0x2d, 0x29, 0x2e, 0x57, 0x00, 0x61, 0x0e, 0x01, 0x2f, 0x27, 0x2e, + 0x5d, 0x00, 0x81, 0x40, 0x23, 0x2e, 0x5a, 0x00, 0x30, 0x25, 0x47, 0x52, + 0xd4, 0x40, 0x54, 0x42, 0x00, 0x2e, 0xc3, 0x40, 0x43, 0x42, 0x00, 0x2e, + 0x03, 0x2e, 0x5d, 0x00, 0x40, 0xb2, 0x0d, 0x2f, 0x81, 0x40, 0x23, 0x2e, + 0x5a, 0x00, 0x11, 0x40, 0x91, 0x43, 0x01, 0x34, 0x00, 0x40, 0x80, 0x43, + 0x23, 0x2e, 0x5e, 0xf0, 0x03, 0x2d, 0x00, 0x30, 0x21, 0x2e, 0x7b, 0x00, + 0xe0, 0x5f, 0xb8, 0x2e, 0x50, 0x50, 0xf0, 0x7f, 0x1a, 0x25, 0x13, 0x40, + 0x7b, 0x84, 0xe0, 0x7f, 0x83, 0x42, 0x35, 0x30, 0x11, 0x40, 0x04, 0x40, + 0xc1, 0x7f, 0xd4, 0x7f, 0x86, 0x31, 0x07, 0x2e, 0x59, 0xf0, 0x03, 0x2e, + 0x1f, 0x01, 0x0d, 0x09, 0x02, 0xab, 0x05, 0x30, 0x8e, 0x09, 0x2c, 0x23, + 0xe3, 0xba, 0x42, 0xab, 0x16, 0x30, 0x75, 0x23, 0x59, 0x5c, 0x8e, 0x09, + 0x66, 0xbb, 0x82, 0xab, 0x27, 0x30, 0xbe, 0x23, 0x3e, 0x80, 0x25, 0x1a, + 0x06, 0x2f, 0x2e, 0x1a, 0x04, 0x2f, 0x26, 0x1a, 0x02, 0x2f, 0xf7, 0x3d, + 0x03, 0x2c, 0xdf, 0x08, 0x07, 0x32, 0xdf, 0x0a, 0x14, 0x01, 0x55, 0x01, + 0x04, 0x41, 0x14, 0x42, 0x16, 0x01, 0x42, 0x41, 0x45, 0x30, 0x4d, 0x09, + 0x04, 0x41, 0x12, 0x42, 0x04, 0x42, 0x40, 0xb3, 0x04, 0x2f, 0xf0, 0x6f, + 0x02, 0x30, 0x04, 0x40, 0x94, 0x04, 0x02, 0x42, 0x00, 0x32, 0x08, 0x08, + 0x00, 0xb2, 0x00, 0x30, 0x05, 0x2f, 0xe2, 0x6f, 0x00, 0x2e, 0x84, 0x40, + 0x04, 0x05, 0x84, 0x42, 0x00, 0x2e, 0x5b, 0x54, 0x4a, 0x08, 0x40, 0xb2, + 0xf1, 0x6f, 0x04, 0x2f, 0x42, 0x82, 0x00, 0x2e, 0x42, 0x40, 0x02, 0x04, + 0x40, 0x42, 0xb0, 0x5f, 0x27, 0x2e, 0x59, 0xf0, 0xb8, 0x2e, 0x50, 0x50, + 0xf7, 0x7f, 0x00, 0x2e, 0x0f, 0x2e, 0xb8, 0xf0, 0xf8, 0xbf, 0xff, 0xbb, + 0xc0, 0xb3, 0x2a, 0x2f, 0x0f, 0x2e, 0x01, 0xf0, 0xfe, 0xbf, 0xe6, 0x7f, + 0x7e, 0xbb, 0xd5, 0x7f, 0x37, 0x30, 0x5f, 0x5a, 0xbe, 0x05, 0x67, 0x41, + 0xc4, 0x7f, 0x78, 0xbe, 0x47, 0x41, 0x27, 0x0b, 0xb3, 0x7f, 0xe6, 0x11, + 0x41, 0x56, 0x43, 0x89, 0xd7, 0x42, 0x00, 0x2e, 0x27, 0x41, 0x05, 0x41, + 0xf8, 0xbf, 0x7d, 0x0b, 0x6e, 0x11, 0x03, 0x8f, 0xd5, 0x42, 0x14, 0x30, + 0xe5, 0x41, 0xc7, 0x41, 0xd8, 0xbe, 0x6f, 0x0b, 0x6e, 0x11, 0xc5, 0x42, + 0x29, 0x2e, 0x56, 0x00, 0x45, 0x56, 0x27, 0x2e, 0xb8, 0xf0, 0xe6, 0x6f, + 0xd5, 0x6f, 0xc4, 0x6f, 0xb3, 0x6f, 0xf7, 0x6f, 0xb0, 0x5f, 0xc8, 0x2e, + 0x50, 0x50, 0xe5, 0x7f, 0xd7, 0x7f, 0xf6, 0x7f, 0x36, 0x30, 0x0b, 0x2e, + 0x01, 0xf0, 0xde, 0xbe, 0xde, 0xbb, 0x61, 0x5a, 0xb7, 0x05, 0x67, 0x41, + 0xc4, 0x7f, 0x78, 0xbe, 0x47, 0x41, 0x27, 0x0b, 0xb3, 0x7f, 0xe6, 0x11, + 0x43, 0x56, 0x43, 0x89, 0xd7, 0x42, 0x00, 0x2e, 0x27, 0x41, 0x05, 0x41, + 0xf8, 0xbf, 0x7d, 0x0b, 0x6e, 0x11, 0x03, 0x8f, 0xd5, 0x42, 0x14, 0x30, + 0xe5, 0x41, 0xc7, 0x41, 0xd8, 0xbe, 0x6f, 0x0b, 0x6e, 0x11, 0xc5, 0x42, + 0x29, 0x2e, 0x55, 0x00, 0x03, 0x31, 0x27, 0x2e, 0xb8, 0xf0, 0xf6, 0x6f, + 0xe5, 0x6f, 0xd7, 0x6f, 0xc4, 0x6f, 0xb3, 0x6f, 0xb0, 0x5f, 0xc8, 0x2e, + 0x40, 0x50, 0xf6, 0x7f, 0x1a, 0x18, 0x63, 0x56, 0x33, 0x00, 0x06, 0x30, + 0xfe, 0x03, 0x0e, 0xb8, 0xf2, 0xbf, 0x07, 0x0a, 0x2a, 0x18, 0x63, 0x5a, + 0xb5, 0x01, 0x03, 0x30, 0xfb, 0x03, 0x6e, 0xbb, 0xf2, 0xbf, 0xe1, 0x7f, + 0xf7, 0x0b, 0x56, 0x40, 0x36, 0x25, 0x46, 0x40, 0x06, 0x28, 0xc7, 0x7f, + 0x22, 0x18, 0xd1, 0x7f, 0xb5, 0x00, 0x01, 0x30, 0x39, 0x03, 0x2e, 0xb9, + 0x42, 0xbe, 0x14, 0x0b, 0xf2, 0x6f, 0x10, 0x18, 0xb5, 0x00, 0xb9, 0x03, + 0x2e, 0xb9, 0x62, 0xbf, 0x96, 0x0a, 0xb6, 0x6f, 0x30, 0x18, 0x75, 0x01, + 0xb9, 0x03, 0x5c, 0x28, 0xe2, 0xbf, 0xde, 0xb9, 0xd6, 0x6f, 0xdf, 0x0a, + 0x8a, 0x28, 0xc4, 0x6f, 0x82, 0x43, 0x23, 0x29, 0xe5, 0x6f, 0xc0, 0x2e, + 0x44, 0x43, 0xc0, 0x5f, 0x40, 0x50, 0xd0, 0x7f, 0x4a, 0x17, 0x00, 0x40, + 0x01, 0x18, 0x46, 0x25, 0x07, 0x25, 0x65, 0x56, 0xd9, 0x04, 0x53, 0x18, + 0xeb, 0x18, 0x05, 0x30, 0x49, 0x16, 0x69, 0x06, 0xca, 0x18, 0xa6, 0x00, + 0xc7, 0x02, 0x65, 0x58, 0xcb, 0x7f, 0x98, 0x2e, 0x7f, 0xb6, 0xcb, 0x6f, + 0xd2, 0x6f, 0xc0, 0x2e, 0x80, 0x42, 0xc0, 0x5f, 0x09, 0x2e, 0x1b, 0x01, + 0x05, 0x2e, 0x1b, 0x01, 0xa3, 0xbc, 0x44, 0xbe, 0x90, 0x50, 0x4f, 0xb9, + 0x07, 0x2e, 0x1b, 0x01, 0x4a, 0x25, 0x9f, 0xb8, 0x39, 0x8f, 0xb2, 0xbd, + 0xf2, 0x7f, 0xbf, 0xb9, 0xeb, 0x7f, 0x8a, 0x0a, 0x37, 0x89, 0x0b, 0x30, + 0x93, 0x0a, 0x8b, 0x7f, 0xcb, 0x43, 0x0b, 0x43, 0x80, 0xb2, 0xd3, 0x7f, + 0xc1, 0x7f, 0x90, 0x2e, 0x87, 0xb2, 0x20, 0x25, 0x01, 0x2e, 0x64, 0x00, + 0x01, 0x90, 0x0e, 0x2f, 0x67, 0x52, 0x01, 0x2e, 0x61, 0x00, 0xb4, 0x7f, + 0xa2, 0x7f, 0x98, 0x2e, 0x8d, 0xb2, 0x00, 0x30, 0x21, 0x2e, 0x64, 0x00, + 0xc1, 0x6f, 0xd3, 0x6f, 0xa2, 0x6f, 0xb4, 0x6f, 0x0b, 0x30, 0x01, 0x2e, + 0x1b, 0x01, 0x06, 0xbc, 0x06, 0xbb, 0x57, 0x25, 0x01, 0x2e, 0x1b, 0x01, + 0x94, 0xb1, 0x05, 0xbc, 0xb6, 0x7f, 0x0f, 0xbb, 0x6b, 0x50, 0x80, 0xb3, + 0x0f, 0x2f, 0x0d, 0x2e, 0x1b, 0x01, 0x6f, 0x5e, 0xb7, 0x09, 0x2d, 0x2e, + 0x1b, 0x01, 0x71, 0x5c, 0x69, 0x5e, 0x9b, 0x43, 0x9b, 0x43, 0xdb, 0x43, + 0x9b, 0x43, 0x1b, 0x42, 0xcb, 0x43, 0x0b, 0x42, 0x8b, 0x43, 0x40, 0xb2, + 0x05, 0x2f, 0x69, 0x50, 0x00, 0x2e, 0x16, 0x40, 0x0b, 0x40, 0x76, 0x7f, + 0x8b, 0x7f, 0xcb, 0x0a, 0x01, 0x2e, 0x61, 0x00, 0x67, 0x52, 0x6d, 0x5c, + 0x98, 0x2e, 0xd3, 0xb2, 0x90, 0x6f, 0x00, 0xb2, 0x0b, 0x2f, 0xf0, 0x6f, + 0x00, 0xb2, 0x08, 0x2f, 0x69, 0x58, 0x6b, 0x50, 0x12, 0x41, 0x12, 0x42, + 0x21, 0x30, 0x04, 0x41, 0x04, 0x42, 0x23, 0x2e, 0x5e, 0xf0, 0xc0, 0x6f, + 0x00, 0xb2, 0x26, 0x2f, 0x74, 0x6f, 0x80, 0x6f, 0x71, 0x54, 0x88, 0xbd, + 0xc8, 0xb8, 0x4b, 0x0a, 0x94, 0x42, 0x91, 0x42, 0x90, 0x42, 0x88, 0xba, + 0x69, 0x52, 0xf3, 0x6f, 0x54, 0x42, 0x85, 0x42, 0xc0, 0x90, 0x40, 0x42, + 0x15, 0x2f, 0x6b, 0x52, 0x00, 0x2e, 0x52, 0x40, 0x41, 0x40, 0xa2, 0x04, + 0x41, 0x06, 0x40, 0xaa, 0x04, 0x2f, 0x40, 0x90, 0x0b, 0x2f, 0xb1, 0x6f, + 0x4a, 0x0f, 0x08, 0x2f, 0xb2, 0x6f, 0x80, 0xb2, 0x05, 0x2f, 0x6b, 0x54, + 0x21, 0x30, 0x94, 0x42, 0x80, 0x42, 0x23, 0x2e, 0x5e, 0xf0, 0xd0, 0x6f, + 0x00, 0xb2, 0x13, 0x2f, 0x01, 0x2e, 0x60, 0x00, 0x09, 0x2e, 0x7c, 0x00, + 0x04, 0x1a, 0x0d, 0x2f, 0x73, 0x50, 0x29, 0x2e, 0x60, 0x00, 0x24, 0x42, + 0x44, 0x30, 0x02, 0x40, 0x02, 0x42, 0x09, 0x80, 0x00, 0x2e, 0x04, 0x42, + 0x03, 0x2d, 0x10, 0x30, 0x21, 0x2e, 0x64, 0x00, 0xeb, 0x6f, 0x70, 0x5f, + 0xb8, 0x2e, 0x09, 0x86, 0x49, 0x54, 0xe4, 0x40, 0xc3, 0x80, 0x94, 0x04, + 0xc3, 0x40, 0x13, 0x05, 0x05, 0x40, 0x25, 0x05, 0x8a, 0x17, 0x73, 0x30, + 0x73, 0x09, 0x8c, 0x17, 0xf3, 0x08, 0xe3, 0x00, 0x4c, 0x82, 0x95, 0x00, + 0xb3, 0xb5, 0x23, 0xb5, 0x53, 0x42, 0x52, 0x42, 0x53, 0x42, 0x42, 0x42, + 0x71, 0x82, 0x75, 0x54, 0x52, 0x42, 0x10, 0x50, 0x77, 0x54, 0x52, 0x42, + 0xfb, 0x7f, 0x22, 0x30, 0x79, 0x56, 0x43, 0x42, 0x44, 0x82, 0x0b, 0x30, + 0x52, 0x42, 0x5b, 0x42, 0x7c, 0x84, 0x4b, 0x42, 0x35, 0x82, 0x8c, 0x80, + 0x8b, 0x42, 0x0b, 0x42, 0x39, 0x80, 0x04, 0x30, 0x0b, 0x42, 0x37, 0x80, + 0x15, 0x30, 0x60, 0x25, 0x98, 0x2e, 0xc6, 0xb2, 0x8b, 0x83, 0xfb, 0x6f, + 0x65, 0x42, 0xc0, 0x2e, 0x44, 0x42, 0xf0, 0x5f, 0x05, 0x80, 0x02, 0x30, + 0x51, 0x82, 0x02, 0x42, 0x13, 0x30, 0x41, 0x40, 0x4b, 0x08, 0x7b, 0x54, + 0x3e, 0x80, 0x51, 0x14, 0xc0, 0x2e, 0x01, 0x42, 0x00, 0x2e, 0x40, 0x51, + 0xd1, 0x7f, 0x12, 0x25, 0x02, 0x30, 0x42, 0x43, 0x32, 0x30, 0x82, 0x43, + 0xc6, 0x7f, 0xe5, 0x7f, 0xb4, 0x7f, 0xa3, 0x7f, 0x90, 0x7f, 0x8b, 0x7f, + 0x98, 0x2e, 0x54, 0x01, 0xc0, 0x7e, 0x00, 0xac, 0x01, 0x2f, 0x65, 0x50, + 0xc0, 0x7e, 0x00, 0x2e, 0x90, 0x6f, 0x09, 0x8a, 0xd1, 0x6f, 0x75, 0x7f, + 0x4c, 0x82, 0x63, 0x41, 0x65, 0x7f, 0x11, 0x7f, 0x00, 0x2e, 0x64, 0x41, + 0x44, 0x85, 0x52, 0x7f, 0x45, 0x7f, 0x00, 0x2e, 0xa6, 0x40, 0x80, 0x40, + 0x32, 0x7f, 0x82, 0x8e, 0xc2, 0x6e, 0x45, 0x41, 0xf0, 0x7f, 0x27, 0x7f, + 0x02, 0x7f, 0x98, 0x2e, 0x8a, 0xb1, 0x23, 0x6f, 0xd1, 0x6f, 0xc2, 0x40, + 0xf9, 0x86, 0x23, 0x7f, 0x80, 0xb2, 0xe0, 0x7e, 0x0f, 0x2f, 0x32, 0x6f, + 0x64, 0x6f, 0x82, 0x40, 0xf2, 0x7f, 0x4e, 0x82, 0x42, 0x6f, 0x50, 0x6f, + 0x73, 0x6f, 0x85, 0x40, 0xc3, 0x40, 0x04, 0x41, 0x06, 0x40, 0xe2, 0x6e, + 0x98, 0x2e, 0x8a, 0xb1, 0xe0, 0x7e, 0xf3, 0x31, 0x10, 0x6f, 0x36, 0x80, + 0xe1, 0x6e, 0x02, 0x40, 0x71, 0x7f, 0x51, 0x04, 0x02, 0x30, 0x40, 0xa8, + 0x91, 0x04, 0x4a, 0x22, 0x89, 0x16, 0x93, 0x08, 0x4a, 0x00, 0x95, 0xb4, + 0x09, 0x18, 0x8e, 0x16, 0x13, 0x30, 0x93, 0x08, 0x21, 0x6f, 0x60, 0x7f, + 0x4d, 0x86, 0x02, 0x80, 0xb2, 0x00, 0x41, 0x40, 0x21, 0xb5, 0x50, 0x7f, + 0x43, 0x7f, 0x98, 0x2e, 0xc2, 0xb1, 0x40, 0x6f, 0x62, 0x6f, 0x55, 0x6f, + 0x13, 0x40, 0x84, 0x40, 0x01, 0x40, 0x45, 0x41, 0x42, 0xbe, 0x1d, 0x18, + 0x4c, 0x04, 0x31, 0x0f, 0x04, 0x8a, 0xc0, 0x6f, 0x11, 0x30, 0x02, 0x2f, + 0x00, 0x2e, 0x03, 0x2c, 0x01, 0x42, 0x23, 0x30, 0x03, 0x42, 0x00, 0x2e, + 0xd6, 0x6f, 0x44, 0x41, 0x8a, 0x87, 0x76, 0x8b, 0x00, 0xb3, 0x53, 0x7f, + 0x15, 0x2f, 0x04, 0x6f, 0x7d, 0x5e, 0x8b, 0x8d, 0xe7, 0x01, 0xc0, 0xa5, + 0x84, 0x41, 0x01, 0x2f, 0x00, 0xa1, 0x03, 0x2f, 0xc0, 0xad, 0x08, 0x2f, + 0x00, 0xa5, 0x06, 0x2f, 0xc6, 0x40, 0x81, 0x8d, 0x07, 0x30, 0x3c, 0x05, + 0xd6, 0x42, 0x04, 0x2c, 0xc4, 0x42, 0x02, 0x2c, 0x07, 0x30, 0x07, 0x30, + 0x86, 0x86, 0x94, 0x6f, 0xd7, 0x7e, 0x0e, 0x8d, 0x00, 0x40, 0x74, 0x89, + 0xc7, 0x40, 0x02, 0xb2, 0xf9, 0x29, 0x45, 0x41, 0x86, 0x41, 0xbe, 0x80, + 0x21, 0x41, 0x75, 0x23, 0x82, 0x40, 0xc7, 0x42, 0x45, 0x7f, 0x34, 0x7f, + 0x20, 0x7f, 0x98, 0x2e, 0xc2, 0xb1, 0x31, 0x6f, 0x60, 0x6f, 0x24, 0x6f, + 0x22, 0x40, 0x05, 0x41, 0x43, 0x40, 0x13, 0x01, 0x43, 0x86, 0xac, 0x0f, + 0xd1, 0x6f, 0x30, 0x7f, 0x00, 0x2f, 0x44, 0x42, 0x48, 0x8a, 0x41, 0x88, + 0xe1, 0x40, 0x13, 0x7f, 0x04, 0x7f, 0xf5, 0x7e, 0x98, 0x2e, 0xc2, 0xb1, + 0x11, 0x6f, 0x60, 0x6f, 0x34, 0x6f, 0x42, 0x40, 0x03, 0x40, 0x9a, 0x04, + 0x04, 0x41, 0x43, 0x82, 0xa2, 0x0e, 0x03, 0x6f, 0x00, 0x2f, 0xc2, 0x42, + 0x00, 0x2e, 0x41, 0x40, 0x72, 0x6f, 0x98, 0x2e, 0xc2, 0xb1, 0x25, 0x6f, + 0x72, 0x6f, 0x53, 0x41, 0x93, 0x0e, 0xd1, 0x6f, 0x46, 0x80, 0x1b, 0x30, + 0x03, 0x30, 0x0c, 0x2f, 0x04, 0x40, 0x00, 0x91, 0x42, 0x42, 0x08, 0x2f, + 0xf6, 0x6e, 0x44, 0x6f, 0x86, 0x41, 0xb4, 0x0e, 0x03, 0x2f, 0x02, 0x88, + 0xdb, 0x7e, 0x03, 0x43, 0x0b, 0x42, 0x46, 0x8d, 0x44, 0x41, 0x47, 0x80, + 0x05, 0x6f, 0x94, 0x0f, 0x76, 0x7f, 0x60, 0x7f, 0x02, 0x2f, 0x45, 0x89, + 0x42, 0x43, 0x03, 0x43, 0x49, 0x88, 0xa5, 0x6f, 0x40, 0x91, 0xa4, 0x7f, + 0x15, 0x30, 0xe2, 0x6f, 0xd3, 0x6e, 0x03, 0x2f, 0x04, 0x30, 0x83, 0x42, + 0x80, 0x2e, 0x77, 0xb4, 0x04, 0x40, 0x25, 0x29, 0x04, 0x42, 0x83, 0x42, + 0x45, 0x82, 0x94, 0x6f, 0x04, 0x85, 0xc0, 0xb2, 0x90, 0x2e, 0x63, 0xb4, + 0x15, 0x87, 0x3c, 0x8c, 0xc4, 0x40, 0x46, 0x7f, 0xc2, 0x86, 0x07, 0x40, + 0x86, 0x41, 0xf4, 0xbf, 0x00, 0xb3, 0x0c, 0x2f, 0x90, 0x6f, 0x16, 0x80, + 0x46, 0x25, 0x00, 0x40, 0x57, 0x25, 0x04, 0x18, 0xae, 0x0e, 0x10, 0x30, + 0x06, 0x30, 0x75, 0x25, 0x46, 0x23, 0x60, 0x6f, 0x64, 0x25, 0xc4, 0x40, + 0xfa, 0x86, 0x00, 0xb3, 0x33, 0x7f, 0x09, 0x2f, 0x93, 0x6f, 0xd8, 0x88, + 0x53, 0x6f, 0x04, 0x41, 0xc3, 0x40, 0xdc, 0x0e, 0x13, 0x30, 0x04, 0x30, + 0xdc, 0x22, 0xb3, 0x25, 0x40, 0xb3, 0x02, 0x2f, 0x3b, 0x25, 0xc0, 0x90, + 0x05, 0x2f, 0x91, 0x6f, 0xd0, 0x6f, 0x98, 0x2e, 0xc6, 0xb2, 0x4d, 0x2c, + 0x04, 0x30, 0x8d, 0x88, 0x43, 0x40, 0x82, 0x40, 0x54, 0x7f, 0xda, 0x0f, + 0x04, 0x30, 0x08, 0x2f, 0xc1, 0x80, 0x40, 0x42, 0xc2, 0x0f, 0x02, 0x2f, + 0x00, 0x30, 0xc0, 0x7e, 0x1b, 0x2d, 0xc0, 0x7e, 0x19, 0x2d, 0xe1, 0xbc, + 0x92, 0x6f, 0x4f, 0x04, 0x90, 0x84, 0x40, 0xa8, 0x21, 0x05, 0x83, 0x40, + 0x4c, 0x22, 0x4b, 0x0e, 0xb6, 0x84, 0x21, 0x30, 0x02, 0x2f, 0x11, 0x30, + 0x04, 0x2c, 0xc1, 0x7e, 0xe3, 0x6f, 0xc1, 0x7e, 0xc1, 0x42, 0x00, 0x2e, + 0x00, 0x40, 0x81, 0x40, 0x04, 0xbd, 0x40, 0x6f, 0x98, 0x2e, 0xc2, 0xb1, + 0x50, 0x6f, 0x11, 0x30, 0x02, 0x40, 0x51, 0x08, 0xc3, 0x6e, 0x03, 0x80, + 0x99, 0x15, 0x0b, 0x40, 0xb1, 0x6f, 0xd0, 0x6f, 0xb6, 0x7f, 0x5b, 0x7f, + 0x04, 0x30, 0x4d, 0x54, 0x03, 0x30, 0x11, 0x2c, 0x10, 0x80, 0x55, 0x6f, + 0x06, 0x40, 0x75, 0x01, 0x58, 0xbb, 0x6a, 0x09, 0x05, 0x42, 0xc1, 0x86, + 0x47, 0x40, 0x51, 0x25, 0xbe, 0x01, 0x56, 0x43, 0x00, 0x2e, 0x46, 0x41, + 0xf4, 0x03, 0xb6, 0x6f, 0x47, 0x43, 0x5e, 0x0e, 0xed, 0x2f, 0x31, 0x6f, + 0x60, 0x6f, 0x42, 0x40, 0x15, 0x30, 0x02, 0x82, 0x95, 0x08, 0x04, 0x42, + 0x52, 0x42, 0x02, 0x2c, 0x44, 0x42, 0x04, 0x30, 0x3e, 0x8e, 0x91, 0x6f, + 0x4f, 0x8c, 0x02, 0x40, 0x83, 0x41, 0xb5, 0x8d, 0x93, 0x0e, 0xd0, 0x6f, + 0x01, 0x2f, 0x98, 0x2e, 0xc6, 0xb2, 0x00, 0x2e, 0xc0, 0x41, 0x81, 0x41, + 0xc1, 0x0f, 0xc0, 0x6f, 0x01, 0x2f, 0x04, 0x42, 0x00, 0x2e, 0x70, 0x6f, + 0x3c, 0x82, 0x00, 0x40, 0x41, 0x40, 0x89, 0x16, 0x95, 0x08, 0x4a, 0x00, + 0x04, 0xbc, 0x91, 0xb4, 0x01, 0x0e, 0xe0, 0x6f, 0x07, 0x2f, 0xa1, 0x6f, + 0x00, 0x2e, 0x41, 0x40, 0x40, 0xb2, 0x02, 0x2f, 0xa1, 0x6f, 0x05, 0x42, + 0x44, 0x42, 0x00, 0x2e, 0x8b, 0x6f, 0xc0, 0x5e, 0xb8, 0x2e, 0x03, 0x2e, + 0x1c, 0x01, 0x9c, 0xbc, 0x1d, 0xb9, 0x02, 0x82, 0x25, 0x2e, 0x8e, 0x00, + 0x83, 0x56, 0x13, 0x18, 0x01, 0x2e, 0x66, 0x00, 0x43, 0x40, 0xd8, 0x04, + 0x05, 0x2e, 0x65, 0x00, 0x40, 0x50, 0x27, 0x2e, 0x65, 0x00, 0xfb, 0x7f, + 0xda, 0x05, 0x8b, 0x50, 0x4b, 0x40, 0x02, 0x40, 0x81, 0x82, 0x01, 0x42, + 0x03, 0x80, 0x81, 0x52, 0xb1, 0x00, 0x03, 0x40, 0x3b, 0x82, 0x85, 0x58, + 0x14, 0x01, 0xc0, 0xb2, 0x37, 0x2e, 0x66, 0x00, 0xd1, 0x7f, 0xe2, 0x7f, + 0x04, 0x2f, 0x05, 0x2e, 0x6b, 0x00, 0x81, 0x84, 0x25, 0x2e, 0x6b, 0x00, + 0x62, 0x40, 0x3a, 0x0f, 0x45, 0x40, 0xc1, 0x7f, 0x21, 0x30, 0x12, 0x30, + 0x42, 0x2f, 0x0d, 0x2e, 0x69, 0x00, 0x3e, 0x0e, 0x33, 0x2f, 0x05, 0x2e, + 0x6a, 0x00, 0x01, 0x35, 0x91, 0x0e, 0x01, 0x30, 0x03, 0x2f, 0x09, 0x2e, + 0x6e, 0x00, 0x00, 0xb3, 0x24, 0x2f, 0xc0, 0x35, 0x90, 0x0e, 0x39, 0x2f, + 0x8f, 0x50, 0x02, 0x30, 0x01, 0x40, 0x7f, 0x82, 0x43, 0xa2, 0x02, 0x2f, + 0x00, 0x2e, 0x0c, 0x2c, 0x01, 0x30, 0xc0, 0xb2, 0x11, 0x30, 0x02, 0x2f, + 0x25, 0x2e, 0x6d, 0x00, 0x03, 0x2d, 0x23, 0x2e, 0x6d, 0x00, 0x21, 0x30, + 0x25, 0x2e, 0x6b, 0x00, 0x42, 0xb2, 0x04, 0x2f, 0x41, 0xb2, 0x02, 0x2f, + 0x25, 0x2e, 0x6d, 0x00, 0x31, 0x30, 0x3e, 0x80, 0x04, 0x86, 0x25, 0x2e, + 0x6c, 0x00, 0x02, 0x42, 0xc2, 0x42, 0x18, 0x2d, 0x02, 0x35, 0x01, 0x42, + 0x25, 0x2e, 0x6a, 0x00, 0x13, 0x2d, 0x2c, 0x04, 0x38, 0x1e, 0x21, 0x2e, + 0x69, 0x00, 0x7f, 0x50, 0x11, 0x30, 0x22, 0x30, 0x98, 0x2e, 0x66, 0xb5, + 0x09, 0x2c, 0x01, 0x30, 0x2c, 0x00, 0x38, 0x1c, 0x21, 0x2e, 0x68, 0x00, + 0x7f, 0x50, 0x98, 0x2e, 0x66, 0xb5, 0x01, 0x30, 0xc0, 0x6f, 0xd4, 0xb1, + 0xf5, 0xbd, 0x6b, 0xba, 0x91, 0x5a, 0x02, 0x40, 0x15, 0x18, 0xf5, 0xbe, + 0xeb, 0xbb, 0xe3, 0x0a, 0x3d, 0x0b, 0xd2, 0x6f, 0xe3, 0x00, 0x84, 0x40, + 0x63, 0x05, 0x93, 0x58, 0x2c, 0x18, 0xf5, 0xbe, 0x03, 0x42, 0xeb, 0xbb, + 0xfd, 0x0b, 0xe0, 0x6f, 0x58, 0x01, 0xdf, 0x01, 0x7d, 0x1f, 0x95, 0x42, + 0x18, 0x04, 0x85, 0x40, 0x5d, 0x05, 0x2c, 0x18, 0x75, 0xbe, 0xeb, 0xba, + 0x2c, 0x0b, 0xdc, 0x04, 0x18, 0x1c, 0x80, 0x42, 0x84, 0x80, 0x02, 0x30, + 0x00, 0x40, 0x00, 0xb2, 0x0c, 0x2f, 0x01, 0x2e, 0x6b, 0x00, 0x03, 0x35, + 0x83, 0x0e, 0x07, 0x2f, 0x8d, 0x50, 0x3e, 0x80, 0x25, 0x2e, 0x6d, 0x00, + 0x02, 0x42, 0x03, 0x80, 0x00, 0x2e, 0x02, 0x42, 0x40, 0xb2, 0x04, 0x2f, + 0x8b, 0x50, 0x04, 0x80, 0x25, 0x2e, 0x6a, 0x00, 0x02, 0x42, 0x42, 0xb2, + 0x89, 0x56, 0x9a, 0x22, 0x41, 0xb2, 0x01, 0x2e, 0x1c, 0x01, 0x87, 0x52, + 0x0b, 0xbc, 0x8a, 0x22, 0x0f, 0xb8, 0x00, 0x90, 0x01, 0x32, 0x06, 0x2f, + 0x10, 0x30, 0x90, 0x08, 0x80, 0xb2, 0x08, 0x2f, 0x23, 0x2e, 0x5e, 0xf0, + 0x06, 0x2d, 0x20, 0x30, 0x90, 0x08, 0x80, 0xb2, 0x01, 0x2f, 0x23, 0x2e, + 0x5e, 0xf0, 0xfb, 0x6f, 0xc0, 0x5f, 0xb8, 0x2e, 0x07, 0x86, 0xfc, 0x88, + 0xc6, 0x40, 0x05, 0x41, 0x31, 0x1a, 0x12, 0x2f, 0x80, 0x91, 0x22, 0x2f, + 0x01, 0x35, 0x29, 0x0f, 0x0a, 0x2f, 0x06, 0x80, 0x00, 0x2e, 0x00, 0x40, + 0x00, 0xb2, 0x01, 0x2f, 0x44, 0xa9, 0x03, 0x2f, 0x00, 0x30, 0xc0, 0x42, + 0x00, 0x43, 0xb8, 0x2e, 0xc2, 0x42, 0x01, 0x43, 0xb8, 0x2e, 0x01, 0x35, + 0xa9, 0x0e, 0x0e, 0x2f, 0x03, 0x3b, 0xeb, 0x00, 0xcc, 0xa8, 0x0a, 0x2f, + 0x05, 0x86, 0xc2, 0x80, 0xc3, 0x40, 0x02, 0x42, 0x3c, 0x84, 0xc1, 0x80, + 0x81, 0x42, 0x82, 0x84, 0xc0, 0x2e, 0x80, 0x42, 0x00, 0x2e, 0xb8, 0x2e, + 0x03, 0x2e, 0x1d, 0x01, 0x9f, 0xbc, 0x9f, 0xb8, 0x90, 0x50, 0x40, 0xb2, + 0x90, 0x2e, 0x71, 0xb6, 0x12, 0x40, 0x03, 0x30, 0x11, 0x40, 0x80, 0xa8, + 0x5a, 0x05, 0x9f, 0x58, 0x55, 0x23, 0x00, 0x40, 0x75, 0x7f, 0x40, 0xa8, + 0x16, 0x41, 0xd9, 0x05, 0xcf, 0x23, 0x56, 0x05, 0x40, 0xa9, 0x9d, 0x05, + 0x87, 0x7f, 0x6e, 0x23, 0x17, 0x41, 0xa5, 0x7f, 0x3e, 0x8b, 0x04, 0x41, + 0x52, 0x43, 0x00, 0xa8, 0x98, 0x05, 0xf2, 0x7f, 0x86, 0x22, 0xcf, 0x05, + 0xc0, 0xa9, 0x9f, 0x05, 0xbe, 0x23, 0x04, 0x05, 0x92, 0x7f, 0x00, 0xa9, + 0xdc, 0x05, 0x51, 0x43, 0xb6, 0x7f, 0x27, 0x23, 0xa7, 0x54, 0xe1, 0x7f, + 0x02, 0x18, 0x7d, 0x83, 0x40, 0x43, 0xeb, 0xba, 0x75, 0xbd, 0xaa, 0x0a, + 0x0b, 0x2e, 0x71, 0x00, 0x77, 0x5c, 0x2e, 0x18, 0xf5, 0xbe, 0x6b, 0xbb, + 0x75, 0x0b, 0xaa, 0x00, 0xc4, 0x7f, 0x25, 0x2e, 0x71, 0x00, 0xb2, 0x6f, + 0xa5, 0x6f, 0xaa, 0x00, 0x54, 0x01, 0x84, 0x6f, 0x72, 0x6f, 0x94, 0x05, + 0x80, 0xa9, 0xde, 0x05, 0xb7, 0x23, 0x99, 0x5e, 0x77, 0x0e, 0x41, 0x40, + 0x97, 0x5c, 0xb1, 0x01, 0xd5, 0x7f, 0x00, 0x2e, 0x85, 0x41, 0x0e, 0x2f, + 0x00, 0xa0, 0x0c, 0x2f, 0x14, 0x0f, 0x04, 0x2f, 0xe0, 0x6f, 0x00, 0xac, + 0x10, 0x30, 0x08, 0x2c, 0x18, 0x22, 0xf0, 0x6f, 0x00, 0xac, 0x30, 0x30, + 0x24, 0x30, 0x02, 0x2c, 0x20, 0x22, 0x40, 0x30, 0x0d, 0x2e, 0x71, 0x00, + 0x80, 0xa1, 0x1e, 0x23, 0x79, 0x5e, 0x37, 0x0f, 0xbc, 0x23, 0x00, 0x90, + 0x14, 0x30, 0x10, 0x30, 0x18, 0x2f, 0x9d, 0x50, 0x30, 0x00, 0x9b, 0x56, + 0x43, 0x0e, 0x02, 0x2f, 0x10, 0x30, 0x0a, 0x2c, 0x03, 0x30, 0x99, 0x50, + 0x10, 0x0e, 0x13, 0x30, 0x00, 0x2f, 0x03, 0x30, 0x90, 0x0f, 0x10, 0x30, + 0x00, 0x2f, 0x00, 0x30, 0x00, 0x90, 0x10, 0x30, 0x00, 0x2f, 0x00, 0x30, + 0xc0, 0x90, 0x13, 0x30, 0x00, 0x2f, 0x03, 0x30, 0x40, 0xb2, 0x87, 0x5c, + 0x22, 0x2f, 0x41, 0x90, 0x4a, 0x2f, 0xa5, 0x50, 0x00, 0x2e, 0x01, 0x40, + 0x41, 0x82, 0x01, 0x42, 0x02, 0x80, 0x4a, 0xa8, 0x01, 0x40, 0x06, 0x2f, + 0xd0, 0x6f, 0x85, 0x0e, 0x3e, 0x2f, 0x41, 0x80, 0x21, 0x2e, 0x78, 0x00, + 0x3b, 0x2d, 0x95, 0x50, 0xfb, 0x7f, 0x4a, 0xa8, 0x06, 0x2f, 0x98, 0x2e, + 0x73, 0xb6, 0xc0, 0x90, 0xfb, 0x6f, 0x32, 0x2f, 0x00, 0x2e, 0x30, 0x2d, + 0x98, 0x2e, 0x73, 0xb6, 0x29, 0x2e, 0x7a, 0x00, 0x2b, 0x2c, 0xfb, 0x6f, + 0xa1, 0x52, 0xd2, 0x6f, 0x95, 0x0e, 0x41, 0x40, 0x05, 0x2f, 0x00, 0x90, + 0x17, 0x2f, 0x05, 0x2e, 0x7a, 0x00, 0x80, 0x90, 0x13, 0x2f, 0x7f, 0x82, + 0x40, 0xac, 0x23, 0x2e, 0x77, 0x00, 0x01, 0x30, 0x18, 0x2f, 0xa1, 0x54, + 0x82, 0x84, 0x23, 0x2e, 0x77, 0x00, 0x82, 0x40, 0x80, 0xb2, 0x11, 0x2f, + 0x00, 0x90, 0x23, 0x2e, 0x79, 0x00, 0x0d, 0x2f, 0x29, 0x2e, 0x72, 0x00, + 0x0b, 0x2d, 0x41, 0x80, 0x21, 0x2e, 0x77, 0x00, 0x0f, 0xa4, 0x05, 0x2f, + 0xa3, 0x50, 0x3e, 0x80, 0xf1, 0x30, 0x29, 0x2e, 0x79, 0x00, 0x01, 0x42, + 0x06, 0x30, 0x34, 0x08, 0x00, 0xb2, 0x02, 0x2f, 0x80, 0x30, 0x21, 0x2e, + 0x5e, 0xf0, 0x70, 0x5f, 0xb8, 0x2e, 0x04, 0x84, 0x01, 0x30, 0x81, 0x42, + 0x82, 0x84, 0x01, 0x42, 0xa1, 0x42, 0x81, 0x42, 0x82, 0x84, 0x00, 0x2e, + 0x91, 0x42, 0x81, 0x42, 0xb8, 0x2e, 0x30, 0x50, 0xf3, 0x7f, 0xc0, 0xac, + 0xe4, 0x7f, 0xd5, 0x7f, 0x03, 0x2f, 0x00, 0x30, 0x82, 0x04, 0xf3, 0x6f, + 0xc3, 0x06, 0x40, 0xad, 0x05, 0x2f, 0xe0, 0x6f, 0x05, 0x30, 0x28, 0x04, + 0xd1, 0x6f, 0x69, 0x07, 0xe0, 0x7f, 0x40, 0xa1, 0x01, 0x30, 0x20, 0x2f, + 0x13, 0x25, 0x02, 0x25, 0x04, 0x32, 0x06, 0x30, 0x02, 0x30, 0x03, 0x30, + 0xaf, 0xbb, 0xb1, 0xbd, 0xdf, 0x0a, 0x9f, 0xbb, 0x21, 0xbd, 0x97, 0x0a, + 0x8f, 0xbb, 0x91, 0xbc, 0x01, 0xbc, 0x4f, 0x0a, 0x6b, 0x0e, 0x04, 0x2f, + 0x6b, 0x1a, 0x07, 0x2f, 0xe7, 0x6f, 0x7a, 0x0f, 0x04, 0x2f, 0xe7, 0x6f, + 0x97, 0x04, 0x17, 0x30, 0x07, 0x0a, 0xdd, 0x06, 0x81, 0x8d, 0x34, 0x0e, + 0xe6, 0x2f, 0x00, 0x2e, 0x0d, 0x2d, 0x6b, 0x0e, 0x00, 0x30, 0x05, 0x2f, + 0x6b, 0x1a, 0x07, 0x2f, 0xe0, 0x6f, 0x42, 0x0f, 0x00, 0x30, 0x03, 0x2f, + 0xe0, 0x6f, 0x90, 0x04, 0xdd, 0x06, 0x10, 0x30, 0xf5, 0x6f, 0xc3, 0x7f, + 0xb2, 0x7f, 0x40, 0xad, 0x06, 0x2f, 0x03, 0x30, 0xb2, 0x6f, 0x9a, 0x04, + 0xc4, 0x6f, 0xdc, 0x06, 0xb2, 0x7f, 0xc3, 0x7f, 0x00, 0x2e, 0xd2, 0x6f, + 0xaa, 0x0c, 0x80, 0xac, 0x02, 0x30, 0x01, 0x2f, 0x10, 0x04, 0x51, 0x06, + 0xd0, 0x5f, 0xb8, 0x2e, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, + 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00 +}; + +#define BMA4_ACCEL_CONFIG_ADDR (0X40) +#define BMA4_TEMPERATURE_ADDR (0X22) + + +/**************************************************************/ +/**\name Step Counter & Detector */ +/**************************************************************/ +/**\name Step counter enable macros */ +#define BMA423_STEP_CNTR_EN_POS (4) +#define BMA423_STEP_CNTR_EN_MSK (0x10) +#define BMA423_ACTIVITY_EN_MSK (0x20) + +/**\name Step counter watermark macros */ +#define BMA423_STEP_CNTR_WM_MSK (0x03FF) + +/**\name Step counter reset macros */ +#define BMA423_STEP_CNTR_RST_POS (2) +#define BMA423_STEP_CNTR_RST_MSK (0x04) + +/**\name Step detector enable macros */ +#define BMA423_STEP_DETECTOR_EN_POS (3) +#define BMA423_STEP_DETECTOR_EN_MSK (0x08) + +/**\name Tilt enable macros */ +#define BMA423_TILT_EN_MSK (0x01) + +/**\name Step count output length*/ +#define BMA423_STEP_CNTR_DATA_SIZE (4) + +/**\name Wakeup enable macros */ +#define BMA423_WAKEUP_EN_MSK (0x01) + +/**\name Wake up sensitivity macros */ +#define BMA423_WAKEUP_SENS_POS (1) +#define BMA423_WAKEUP_SENS_MSK (0x0E) + +/**\name Tap selection macro */ +#define BMA423_TAP_SEL_POS (4) +#define BMA423_TAP_SEL_MSK (0x10) + +/**************************************************************/ +/**\name Any Motion */ +/**************************************************************/ +/**\name Any motion threshold macros */ +#define BMA423_ANY_NO_MOTION_THRES_POS (0) +#define BMA423_ANY_NO_MOTION_THRES_MSK (0x07FF) + +/**\name Any motion selection macros */ +#define BMA423_ANY_NO_MOTION_SEL_POS (3) +#define BMA423_ANY_NO_MOTION_SEL_MSK (0x08) + +/**\name Any motion enable macros */ +#define BMA423_ANY_NO_MOTION_AXIS_EN_POS (5) +#define BMA423_ANY_NO_MOTION_AXIS_EN_MSK (0xE0) + +/**\name Any motion duration macros */ +#define BMA423_ANY_NO_MOTION_DUR_MSK (0x1FFF) + +/**\name INTERRUPT MAPS */ +#define BMA4_INTR1_MAP (0) +#define BMA4_INTR2_MAP (1) + +/**\name INTERRUPT ENABLE REGISTERS*/ +#define BMA4_INT1_IO_CTRL_ADDR (0X53) +#define BMA4_INT2_IO_CTRL_ADDR (0X54) + +/**\name LATCH DURATION REGISTERS*/ +#define BMA4_INTR_LATCH_ADDR (0X55) + +/**\name CONSTANTS */ +#define BMA4_FIFO_CONFIG_LENGTH (2) +#define BMA4_ACCEL_CONFIG_LENGTH (2) +#define BMA4_FIFO_WM_LENGTH (2) +#define BMA4_CONFIG_STREAM_SIZE (6144) +#define BMA4_NON_LATCH_MODE (0) +#define BMA4_LATCH_MODE (1) +#define BMA4_OPEN_DRAIN (1) +#define BMA4_PUSH_PULL (0) +#define BMA4_ACTIVE_HIGH (1) +#define BMA4_ACTIVE_LOW (0) +#define BMA4_EDGE_TRIGGER (1) +#define BMA4_LEVEL_TRIGGER (0) +#define BMA4_OUTPUT_ENABLE (1) +#define BMA4_OUTPUT_DISABLE (0) +#define BMA4_INPUT_ENABLE (1) +#define BMA4_INPUT_DISABLE (0) + + +/**\name OUTPUT TYPE ENABLE POSITION AND MASK*/ +#define BMA4_INT_EDGE_CTRL_MASK (0x01) +#define BMA4_INT_EDGE_CTRL_POS (0x00) +#define BMA4_INT_LEVEL_MASK (0x02) +#define BMA4_INT_LEVEL_POS (0x01) +#define BMA4_INT_OPEN_DRAIN_MASK (0x04) +#define BMA4_INT_OPEN_DRAIN_POS (0x02) +#define BMA4_INT_OUTPUT_EN_MASK (0x08) +#define BMA4_INT_OUTPUT_EN_POS (0x03) +#define BMA4_INT_INPUT_EN_MASK (0x10) +#define BMA4_INT_INPUT_EN_POS (0x04) + + +/**\name Interrupt status macros */ +#define BMA423_STEP_CNTR_INT (0x02) +#define BMA423_ACTIVITY_INT (0x04) +#define BMA423_TILT_INT (0x08) +#define BMA423_WAKEUP_INT (0x20) +#define BMA423_ANY_NO_MOTION_INT (0x40) +#define BMA423_ERROR_INT (0x80) diff --git a/components/SensorLib/src/REG/CHSC5816Constants.h b/components/SensorLib/src/REG/CHSC5816Constants.h new file mode 100644 index 0000000..f12832d --- /dev/null +++ b/components/SensorLib/src/REG/CHSC5816Constants.h @@ -0,0 +1,66 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file CHSC5816Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-17 + * + */ + +#pragma once + +#define CHSC5816_SLAVE_ADDRESS (0x2E) + +#define CHSC5816_REG_CMD_BUFF (0x20000000U) +#define CHSC5816_REG_RSP_BUFF (0x20000000U) +#define CHSC5816_REG_IMG_HEAD (0x20000014U) +#define CHSC5816_REG_POINT (0x2000002CU) +#define CHSC5816_REG_WR_BUFF (0x20002000U) +#define CHSC5816_REG_RD_BUFF (0x20002400U) +#define CHSC5816_REG_HOLD_MCU (0x40007000U) +#define CHSC5816_REG_AUTO_FEED (0x40007010U) +#define CHSC5816_REG_REMAP_MCU (0x40007000U) +#define CHSC5816_REG_RELEASE_MCU (0x40007000U) +#define CHSC5816_REG_BOOT_STATE (0x20000018U) + + + +#define CHSC5816_HOLD_MCU_VAL (0x12044000U) +#define CHSC5816_AUTO_FEED_VAL (0x0000925aU) +#define CHSC5816_REMAP_MCU_VAL (0x12044002U) +#define CHSC5816_RELEASE_MCU_VAL (0x12044003U) + +#define CHSC5816_REG_VID_PID_BACKUP (40 * 1024 + 0x10U) + +#define CHSC5816_SIG_VALUE (0x43534843U) +/*ctp work staus*/ +#define CHSC5816_POINTING_WORK (0x00000000U) +#define CHSC5816_READY_UPGRADE (1 << 1) +#define CHSC5816_UPGRAD_RUNING (1 << 2) +#define CHSC5816_SLFTEST_RUNING (1 << 3) +#define CHSC5816_SUSPEND_GATE (1 << 16) +#define CHSC5816_GUESTURE_GATE (1 << 17) +#define CHSC5816_PROXIMITY_GATE (1 << 18) +#define CHSC5816_GLOVE_GATE (1 << 19) +#define CHSC5816_ORIENTATION_GATE (1 << 20) diff --git a/components/SensorLib/src/REG/CM32181Constants.h b/components/SensorLib/src/REG/CM32181Constants.h new file mode 100644 index 0000000..aba30fd --- /dev/null +++ b/components/SensorLib/src/REG/CM32181Constants.h @@ -0,0 +1,62 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file CM32181Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-14 + * + */ + +#pragma once + +#define CM32181_SLAVE_ADDRESS (0x10) + + + +// CM32181 slave address can be 0x10 or 0x48, determined by pin ADDR configuration +#define CM32181_ADDR_ALS (0x10) // 7-bit +#define CM32181_ADDR_ALS1 (0x48) // 7-bit + +// CM32181 registers +#define CM32181_REG_ALS_CONF (uint8_t)(0x00) +#define CM32181_REG_ALS_THDH (uint8_t)(0x01) +#define CM32181_REG_ALS_THDL (uint8_t)(0x02) +#define CM32181_REG_ALS_PSM (uint8_t)(0x03) +#define CM32181_REG_ALS_DATA (uint8_t)(0x04) +#define CM32181_REG_ALS_STATUS (uint8_t)(0x06) +#define CM32181_REG_ID (uint8_t)(0x07) + +#define CM32181_CHIP_ID (0x81) + + + + + + + + + + + + diff --git a/components/SensorLib/src/REG/CST9xxConstants.h b/components/SensorLib/src/REG/CST9xxConstants.h new file mode 100644 index 0000000..40a016a --- /dev/null +++ b/components/SensorLib/src/REG/CST9xxConstants.h @@ -0,0 +1,2781 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2024 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file CST9xxConstants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2024-07-07 + * + */ +#pragma once + +#define CST92XX_SLAVE_ADDRESS (0x5A) +#define CST92XX_BOOT_ADDRESS (0x5A) //Fixed, immutable + +#define CST9220_CHIP_ID (0x9220) +#define CST9217_CHIP_ID (0x9217) + + +#define CST92XX_MEM_SIZE (0x007F80) // 31KB +#define CST92XX_PROGRAM_PAGE_SIZE (128) +#define CST92XX_ACK (0xAB) +#define CST92XX_MAX_FINGER_NUM (2) + + +#define CST92XX_READ_COMMAND (0xD000) +#define CST92XX_REG_DEBUG_MODE (0xD101) +#define CST92XX_REG_SLEEP_MODE (0xD105) +#define CST92XX_REG_DIS_LOW_POWER_SCAN_MODE (0xD106) +#define CST92XX_REG_NORMAL_MODE (0xD109) +#define CST92XX_REG_RAW_MODE (0xD10A) +#define CST92XX_REG_DIFF_MODE (0xD10D) +#define CST92XX_REG_BASE_LINE_MODE (0xD10E) +#define CST92XX_REG_LOWPOWER_MODE (0xD10F) +#define CST92XX_REG_FACTORY_MODE (0xD114) + +#define CST92XX_GET_FINGER_NUM(X) (X & 0X7F) +#define CST92XX_GET_GESTURE(X) (X & 0xF0) + +const unsigned char cst92xx_firmware[] = { + 0xFC, 0x0F, 0x00, 0x20, 0xAD, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF5, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x35, 0x2E, 0x00, 0x00, 0x65, 0x1E, 0x00, 0x00, + 0xE1, 0x65, 0x00, 0x00, 0xD1, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x70, 0xB5, 0x05, 0x46, 0x0C, 0x46, 0x16, 0x46, + 0x02, 0xE0, 0x0F, 0xCC, 0x0F, 0xC5, 0x10, 0x3E, 0x10, 0x2E, 0xFA, 0xD2, + 0x08, 0x2E, 0x02, 0xD3, 0x03, 0xCC, 0x03, 0xC5, 0x08, 0x3E, 0x04, 0x2E, + 0x07, 0xD3, 0x01, 0xCC, 0x01, 0xC5, 0x36, 0x1F, 0x03, 0xE0, 0x21, 0x78, + 0x29, 0x70, 0x64, 0x1C, 0x6D, 0x1C, 0x76, 0x1E, 0xF9, 0xD2, 0x70, 0xBD, + 0xF8, 0xB5, 0x04, 0x2A, 0x2C, 0xD3, 0x83, 0x07, 0x12, 0xD0, 0x0B, 0x78, + 0x49, 0x1C, 0x03, 0x70, 0x40, 0x1C, 0x52, 0x1E, 0x83, 0x07, 0x0B, 0xD0, + 0x0B, 0x78, 0x49, 0x1C, 0x03, 0x70, 0x40, 0x1C, 0x52, 0x1E, 0x83, 0x07, + 0x04, 0xD0, 0x0B, 0x78, 0x49, 0x1C, 0x03, 0x70, 0x40, 0x1C, 0x52, 0x1E, + 0x8B, 0x07, 0x9B, 0x0F, 0x05, 0xD0, 0xC9, 0x1A, 0xDF, 0x00, 0x20, 0x23, + 0xDE, 0x1B, 0x08, 0xC9, 0x0A, 0xE0, 0xFF, 0xF7, 0xC1, 0xFF, 0xF8, 0xBD, + 0x1D, 0x46, 0x08, 0xC9, 0xFD, 0x40, 0x1C, 0x46, 0xB4, 0x40, 0x2C, 0x43, + 0x10, 0xC0, 0x12, 0x1F, 0x04, 0x2A, 0xF5, 0xD2, 0xF3, 0x08, 0xC9, 0x1A, + 0x52, 0x1E, 0xF0, 0xD4, 0x0B, 0x78, 0x49, 0x1C, 0x03, 0x70, 0x40, 0x1C, + 0x52, 0x1E, 0xEA, 0xD4, 0x0B, 0x78, 0x49, 0x1C, 0x03, 0x70, 0x40, 0x1C, + 0x01, 0x2A, 0xE4, 0xD4, 0x09, 0x78, 0x01, 0x70, 0xF8, 0xBD, 0x00, 0x22, + 0x03, 0x09, 0x8B, 0x42, 0x2C, 0xD3, 0x03, 0x0A, 0x8B, 0x42, 0x11, 0xD3, + 0x00, 0x23, 0x9C, 0x46, 0x4E, 0xE0, 0x03, 0x46, 0x0B, 0x43, 0x3C, 0xD4, + 0x00, 0x22, 0x43, 0x08, 0x8B, 0x42, 0x31, 0xD3, 0x03, 0x09, 0x8B, 0x42, + 0x1C, 0xD3, 0x03, 0x0A, 0x8B, 0x42, 0x01, 0xD3, 0x94, 0x46, 0x3F, 0xE0, + 0xC3, 0x09, 0x8B, 0x42, 0x01, 0xD3, 0xCB, 0x01, 0xC0, 0x1A, 0x52, 0x41, + 0x83, 0x09, 0x8B, 0x42, 0x01, 0xD3, 0x8B, 0x01, 0xC0, 0x1A, 0x52, 0x41, + 0x43, 0x09, 0x8B, 0x42, 0x01, 0xD3, 0x4B, 0x01, 0xC0, 0x1A, 0x52, 0x41, + 0x03, 0x09, 0x8B, 0x42, 0x01, 0xD3, 0x0B, 0x01, 0xC0, 0x1A, 0x52, 0x41, + 0xC3, 0x08, 0x8B, 0x42, 0x01, 0xD3, 0xCB, 0x00, 0xC0, 0x1A, 0x52, 0x41, + 0x83, 0x08, 0x8B, 0x42, 0x01, 0xD3, 0x8B, 0x00, 0xC0, 0x1A, 0x52, 0x41, + 0x43, 0x08, 0x8B, 0x42, 0x01, 0xD3, 0x4B, 0x00, 0xC0, 0x1A, 0x52, 0x41, + 0x41, 0x1A, 0x00, 0xD2, 0x01, 0x46, 0x52, 0x41, 0x10, 0x46, 0x70, 0x47, + 0x5D, 0xE0, 0xCA, 0x0F, 0x00, 0xD0, 0x49, 0x42, 0x03, 0x10, 0x00, 0xD3, + 0x40, 0x42, 0x53, 0x40, 0x00, 0x22, 0x9C, 0x46, 0x03, 0x09, 0x8B, 0x42, + 0x2D, 0xD3, 0x03, 0x0A, 0x8B, 0x42, 0x12, 0xD3, 0xFC, 0x22, 0x89, 0x01, + 0x12, 0xBA, 0x03, 0x0A, 0x8B, 0x42, 0x0C, 0xD3, 0x89, 0x01, 0x92, 0x11, + 0x8B, 0x42, 0x08, 0xD3, 0x89, 0x01, 0x92, 0x11, 0x8B, 0x42, 0x04, 0xD3, + 0x89, 0x01, 0x3A, 0xD0, 0x92, 0x11, 0x00, 0xE0, 0x89, 0x09, 0xC3, 0x09, + 0x8B, 0x42, 0x01, 0xD3, 0xCB, 0x01, 0xC0, 0x1A, 0x52, 0x41, 0x83, 0x09, + 0x8B, 0x42, 0x01, 0xD3, 0x8B, 0x01, 0xC0, 0x1A, 0x52, 0x41, 0x43, 0x09, + 0x8B, 0x42, 0x01, 0xD3, 0x4B, 0x01, 0xC0, 0x1A, 0x52, 0x41, 0x03, 0x09, + 0x8B, 0x42, 0x01, 0xD3, 0x0B, 0x01, 0xC0, 0x1A, 0x52, 0x41, 0xC3, 0x08, + 0x8B, 0x42, 0x01, 0xD3, 0xCB, 0x00, 0xC0, 0x1A, 0x52, 0x41, 0x83, 0x08, + 0x8B, 0x42, 0x01, 0xD3, 0x8B, 0x00, 0xC0, 0x1A, 0x52, 0x41, 0xD9, 0xD2, + 0x43, 0x08, 0x8B, 0x42, 0x01, 0xD3, 0x4B, 0x00, 0xC0, 0x1A, 0x52, 0x41, + 0x41, 0x1A, 0x00, 0xD2, 0x01, 0x46, 0x63, 0x46, 0x52, 0x41, 0x5B, 0x10, + 0x10, 0x46, 0x01, 0xD3, 0x40, 0x42, 0x00, 0x2B, 0x00, 0xD5, 0x49, 0x42, + 0x70, 0x47, 0x63, 0x46, 0x5B, 0x10, 0x00, 0xD3, 0x40, 0x42, 0x01, 0xB5, + 0x00, 0x20, 0xC0, 0x46, 0xC0, 0x46, 0x02, 0xBD, 0xFF, 0xB5, 0x84, 0xB0, + 0x00, 0x20, 0x0D, 0x9F, 0x15, 0x46, 0x1E, 0x46, 0x0E, 0x9C, 0x03, 0x90, + 0x52, 0xE0, 0x00, 0x20, 0x03, 0xE0, 0x43, 0x00, 0x2A, 0x4A, 0xE2, 0x52, + 0x40, 0x1C, 0x0A, 0x78, 0x90, 0x42, 0xF8, 0xDB, 0x0A, 0x22, 0x00, 0x21, + 0x05, 0x98, 0x02, 0xF0, 0x9D, 0xFE, 0x0A, 0x22, 0x00, 0x21, 0x28, 0x46, + 0x02, 0xF0, 0x98, 0xFE, 0x01, 0x97, 0x00, 0x96, 0x02, 0x94, 0x03, 0xA8, + 0x07, 0xC8, 0x2B, 0x46, 0x02, 0xF0, 0x60, 0xF9, 0x00, 0x28, 0x32, 0xD1, + 0x1E, 0x4A, 0x1D, 0x48, 0x00, 0x21, 0x13, 0x78, 0x08, 0xE0, 0x6A, 0x5C, + 0x00, 0x2A, 0x04, 0xD1, 0x4A, 0x00, 0xA2, 0x5E, 0x82, 0x42, 0x00, 0xDA, + 0x10, 0x46, 0x49, 0x1C, 0x99, 0x42, 0xF4, 0xDB, 0x00, 0x21, 0x08, 0xE0, + 0x05, 0x9A, 0x52, 0x5C, 0x00, 0x2A, 0x03, 0xD0, 0x4A, 0x00, 0xB3, 0x5A, + 0x1B, 0x1A, 0xB3, 0x52, 0x49, 0x1C, 0x11, 0x4A, 0x13, 0x78, 0x99, 0x42, + 0xF2, 0xDB, 0x00, 0x21, 0x0C, 0xE0, 0x6A, 0x5C, 0x00, 0x2A, 0x04, 0xD0, + 0x4A, 0x00, 0xBB, 0x5A, 0x1B, 0x18, 0xBB, 0x52, 0x03, 0xE0, 0x4A, 0x00, + 0xA3, 0x5A, 0x1B, 0x1A, 0xA3, 0x52, 0x49, 0x1C, 0x07, 0x4A, 0x12, 0x78, + 0x91, 0x42, 0xEE, 0xDB, 0xB8, 0xE7, 0x03, 0x98, 0x40, 0x1C, 0x03, 0x90, + 0x03, 0x49, 0x0A, 0x78, 0x90, 0x42, 0xA8, 0xDB, 0x08, 0xB0, 0xF0, 0xBD, + 0xFF, 0x7F, 0x00, 0x00, 0x38, 0x00, 0x00, 0x20, 0xC2, 0x06, 0xD2, 0x0E, + 0x01, 0x21, 0x91, 0x40, 0x40, 0x09, 0x02, 0x4A, 0x80, 0x00, 0x80, 0x18, + 0x01, 0x60, 0x70, 0x47, 0x00, 0xE1, 0x00, 0xE0, 0x83, 0x07, 0xFF, 0x22, + 0xDB, 0x0E, 0x9A, 0x40, 0x89, 0x07, 0x09, 0x0E, 0x99, 0x40, 0x00, 0x28, + 0x0B, 0xDA, 0x00, 0x07, 0x00, 0x0F, 0x08, 0x38, 0x83, 0x08, 0x08, 0x48, + 0x9B, 0x00, 0x18, 0x18, 0xC3, 0x69, 0x93, 0x43, 0x0B, 0x43, 0xC3, 0x61, + 0x70, 0x47, 0x83, 0x08, 0x04, 0x48, 0x9B, 0x00, 0x18, 0x18, 0x03, 0x68, + 0x93, 0x43, 0x0B, 0x43, 0x03, 0x60, 0x70, 0x47, 0x00, 0xED, 0x00, 0xE0, + 0x00, 0xE4, 0x00, 0xE0, 0x10, 0xB5, 0x03, 0xF0, 0x9D, 0xFF, 0x10, 0xBD, + 0x30, 0xB4, 0x74, 0x46, 0x64, 0x1E, 0x25, 0x78, 0x64, 0x1C, 0xAB, 0x42, + 0x00, 0xD2, 0x1D, 0x46, 0x63, 0x5D, 0x5B, 0x00, 0xE3, 0x18, 0x30, 0xBC, + 0x18, 0x47, 0x00, 0x00, 0x70, 0xB5, 0x14, 0x25, 0x68, 0x43, 0x28, 0x4D, + 0x04, 0x9C, 0x40, 0x19, 0x02, 0x2C, 0x27, 0xD0, 0x45, 0x7C, 0x14, 0x07, + 0x2E, 0x07, 0x36, 0x0F, 0x24, 0x0F, 0x96, 0x42, 0x03, 0xD9, 0x2D, 0x09, + 0x2D, 0x01, 0x25, 0x43, 0x45, 0x74, 0x45, 0x7C, 0x2E, 0x09, 0x96, 0x42, + 0x04, 0xD2, 0x2D, 0x07, 0x2D, 0x0F, 0x24, 0x01, 0x25, 0x43, 0x45, 0x74, + 0x85, 0x7C, 0x1C, 0x07, 0x2E, 0x07, 0x36, 0x0F, 0x24, 0x0F, 0x9E, 0x42, + 0x03, 0xD9, 0x2D, 0x09, 0x2D, 0x01, 0x25, 0x43, 0x85, 0x74, 0x85, 0x7C, + 0x2E, 0x09, 0x9E, 0x42, 0x04, 0xD2, 0x2D, 0x07, 0x2D, 0x0F, 0x24, 0x01, + 0x25, 0x43, 0x85, 0x74, 0x04, 0x68, 0x64, 0x18, 0x04, 0x60, 0x11, 0x4C, + 0x64, 0x68, 0x65, 0x69, 0x00, 0x2D, 0x07, 0xD0, 0xDE, 0x01, 0xEB, 0x56, + 0x45, 0x68, 0xF3, 0x18, 0x4B, 0x43, 0xDB, 0x11, 0x5B, 0x19, 0x02, 0xE0, + 0x45, 0x68, 0x4B, 0x43, 0xEB, 0x18, 0x43, 0x60, 0x23, 0x69, 0x00, 0x2B, + 0x07, 0xD0, 0xD4, 0x01, 0x9A, 0x56, 0xA2, 0x18, 0x4A, 0x43, 0xD1, 0x11, + 0x82, 0x68, 0x89, 0x18, 0x02, 0xE0, 0x83, 0x68, 0x51, 0x43, 0x59, 0x18, + 0x81, 0x60, 0x70, 0xBD, 0xC4, 0x08, 0x00, 0x20, 0x2C, 0x00, 0x00, 0x20, + 0xFF, 0xB5, 0x82, 0xB0, 0x00, 0x21, 0x0B, 0x98, 0x3E, 0x4A, 0x01, 0x91, + 0x51, 0x68, 0x03, 0x9C, 0xC9, 0x7E, 0x61, 0x43, 0x04, 0x9C, 0x09, 0x19, + 0x89, 0xB2, 0x4C, 0x00, 0x00, 0x91, 0x02, 0x99, 0x56, 0x78, 0x0C, 0x5F, + 0x14, 0x2E, 0x03, 0xD3, 0x00, 0x20, 0xC0, 0x43, 0x06, 0xB0, 0xF0, 0xBD, + 0x00, 0x21, 0x38, 0xE0, 0x0E, 0x22, 0x4A, 0x43, 0x33, 0x4D, 0x96, 0x46, + 0x52, 0x19, 0x95, 0x7A, 0x2F, 0x07, 0xAC, 0x46, 0x3F, 0x0F, 0x1D, 0x46, + 0x83, 0x42, 0x00, 0xD3, 0x05, 0x46, 0xAF, 0x42, 0x27, 0xD1, 0x65, 0x46, + 0x2F, 0x09, 0x1D, 0x46, 0x83, 0x42, 0x00, 0xD8, 0x05, 0x46, 0xAF, 0x42, + 0x1F, 0xD1, 0x0E, 0x20, 0x41, 0x43, 0x28, 0x48, 0x08, 0x18, 0x40, 0x88, + 0x02, 0x99, 0x40, 0x00, 0x08, 0x5E, 0xA0, 0x42, 0x01, 0xDA, 0x00, 0x98, + 0x50, 0x80, 0x23, 0x4B, 0x70, 0x46, 0x18, 0x5A, 0x71, 0x46, 0x40, 0x1C, + 0x58, 0x52, 0x04, 0x98, 0x91, 0x88, 0x60, 0x43, 0x08, 0x18, 0x90, 0x80, + 0x03, 0x98, 0xD1, 0x88, 0x60, 0x43, 0x08, 0x18, 0xD0, 0x80, 0x10, 0x89, + 0x00, 0x19, 0x10, 0x81, 0x2D, 0xE0, 0x49, 0x1C, 0xC9, 0xB2, 0xB1, 0x42, + 0xC4, 0xD3, 0x01, 0x99, 0x00, 0x29, 0x26, 0xD1, 0x31, 0x46, 0x0E, 0x22, + 0x51, 0x43, 0x14, 0x4A, 0x01, 0x25, 0x55, 0x52, 0x89, 0x18, 0x8A, 0x7A, + 0x10, 0x4F, 0x15, 0x09, 0x2D, 0x01, 0x1A, 0x46, 0x83, 0x42, 0x00, 0xD3, + 0x02, 0x46, 0x12, 0x07, 0x12, 0x0F, 0x15, 0x43, 0xEA, 0xB2, 0x12, 0x07, + 0x12, 0x0F, 0x8D, 0x72, 0x83, 0x42, 0x00, 0xD8, 0x03, 0x46, 0x18, 0x01, + 0x02, 0x43, 0x8A, 0x72, 0x00, 0x98, 0x48, 0x80, 0x04, 0x98, 0x60, 0x43, + 0x88, 0x80, 0x03, 0x98, 0x60, 0x43, 0xC8, 0x80, 0x0C, 0x81, 0x76, 0x1C, + 0x7E, 0x70, 0x00, 0x20, 0x94, 0xE7, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, + 0x8C, 0x09, 0x00, 0x20, 0xF0, 0xB5, 0x20, 0x4C, 0xE0, 0x6B, 0x25, 0x46, + 0x01, 0x78, 0x00, 0x20, 0x80, 0x3D, 0x23, 0x46, 0x28, 0x74, 0x40, 0x33, + 0x29, 0x70, 0xD8, 0x8E, 0x1A, 0x46, 0x20, 0x32, 0x28, 0x28, 0x02, 0xD8, + 0x16, 0x79, 0x00, 0x2E, 0x07, 0xD0, 0xC8, 0x28, 0x00, 0xD9, 0xC8, 0x20, + 0x01, 0x26, 0xC0, 0x08, 0x2E, 0x74, 0x40, 0x18, 0x28, 0x70, 0x28, 0x7C, + 0x40, 0x1C, 0x68, 0x74, 0xA9, 0x6B, 0x10, 0x7A, 0x08, 0x70, 0xA9, 0x6B, + 0x50, 0x7A, 0x48, 0x70, 0x00, 0x20, 0x51, 0x7A, 0xD6, 0x79, 0x71, 0x43, + 0x49, 0x00, 0x46, 0x00, 0x89, 0x19, 0xA6, 0x6F, 0x71, 0x5A, 0x49, 0x08, + 0xFF, 0x29, 0x00, 0xDD, 0xFF, 0x21, 0x87, 0x1C, 0xAE, 0x6B, 0x40, 0x1C, + 0x40, 0xB2, 0xF1, 0x55, 0x02, 0x28, 0xEC, 0xDB, 0xE9, 0x6B, 0x58, 0x7E, + 0x08, 0x70, 0xE9, 0x6B, 0x18, 0x7E, 0x48, 0x70, 0xE9, 0x6B, 0x10, 0x79, + 0x88, 0x70, 0xF0, 0xBD, 0xC0, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x04, 0x46, + 0x08, 0x46, 0x48, 0x43, 0x85, 0xB2, 0x64, 0x20, 0x40, 0x1A, 0x41, 0x43, + 0x49, 0x04, 0x0E, 0x0C, 0x40, 0x43, 0x85, 0xB0, 0x80, 0xB2, 0x00, 0x90, + 0x00, 0x20, 0x09, 0xE0, 0x81, 0x00, 0x01, 0xAB, 0xCB, 0x18, 0x09, 0x19, + 0x0F, 0x88, 0x1F, 0x80, 0x49, 0x88, 0x40, 0x1C, 0x59, 0x80, 0xC0, 0xB2, + 0x90, 0x42, 0xF3, 0xD3, 0x52, 0x1C, 0xD3, 0xB2, 0x04, 0x2B, 0x00, 0xD9, + 0x04, 0x23, 0x58, 0x1E, 0x09, 0xE0, 0x81, 0x00, 0x01, 0xAA, 0x89, 0x18, + 0x0A, 0x46, 0x40, 0x3A, 0x97, 0x8F, 0x0F, 0x80, 0xD2, 0x8F, 0x4A, 0x80, + 0x40, 0x1E, 0x00, 0x06, 0x00, 0x0E, 0xF2, 0xD1, 0x03, 0x2B, 0x1C, 0xD9, + 0x21, 0x88, 0xA0, 0x88, 0x69, 0x43, 0x70, 0x43, 0x0A, 0x18, 0x20, 0x89, + 0x00, 0x99, 0x0C, 0x4F, 0x48, 0x43, 0x10, 0x18, 0x39, 0x46, 0xFF, 0xF7, + 0x56, 0xFD, 0x6B, 0x46, 0x98, 0x80, 0x60, 0x88, 0xE1, 0x88, 0x68, 0x43, + 0x71, 0x43, 0x42, 0x18, 0x60, 0x89, 0x00, 0x99, 0x48, 0x43, 0x10, 0x18, + 0x39, 0x46, 0xFF, 0xF7, 0x48, 0xFD, 0x6B, 0x46, 0xD8, 0x80, 0x01, 0x98, + 0x05, 0xB0, 0xF0, 0xBD, 0x10, 0x27, 0x00, 0x00, 0xFF, 0xB5, 0x83, 0xB0, + 0x00, 0x26, 0x30, 0x46, 0x0D, 0x9A, 0x0C, 0xE0, 0x28, 0x21, 0x04, 0x9B, + 0x41, 0x43, 0xC9, 0x18, 0x89, 0x78, 0x00, 0x29, 0x03, 0xD0, 0x0C, 0x99, + 0x88, 0x55, 0x76, 0x1C, 0xF6, 0xB2, 0x40, 0x1C, 0xC0, 0xB2, 0x90, 0x42, + 0xF0, 0xD3, 0x0E, 0x98, 0x00, 0x2E, 0x06, 0x70, 0x02, 0xD0, 0x06, 0x98, + 0x00, 0x28, 0x02, 0xD1, 0x00, 0x20, 0x07, 0xB0, 0xF0, 0xBD, 0x07, 0x46, + 0xB0, 0x42, 0x00, 0xD8, 0x37, 0x46, 0x00, 0x25, 0x4F, 0xE0, 0x00, 0x24, + 0x49, 0xE0, 0xB5, 0x42, 0x27, 0xD2, 0x06, 0x98, 0x84, 0x42, 0x24, 0xD2, + 0x0C, 0x98, 0x28, 0x21, 0x40, 0x5D, 0x48, 0x43, 0x04, 0x99, 0x40, 0x18, + 0x81, 0x78, 0x02, 0x29, 0x23, 0xD3, 0x23, 0x49, 0x09, 0x68, 0x49, 0x69, + 0x8C, 0x46, 0x00, 0x29, 0x1D, 0xD0, 0x05, 0x9A, 0xE1, 0x00, 0x89, 0x18, + 0x0A, 0x88, 0x6B, 0x46, 0x1A, 0x81, 0x49, 0x88, 0x59, 0x81, 0x01, 0x8A, + 0x99, 0x80, 0x41, 0x8A, 0xD9, 0x80, 0x81, 0x89, 0x19, 0x80, 0xC0, 0x89, + 0x58, 0x80, 0x68, 0x46, 0x07, 0xC8, 0x63, 0x46, 0x98, 0x47, 0x00, 0x28, + 0x07, 0xD1, 0x28, 0x46, 0x78, 0x43, 0x00, 0x19, 0x03, 0x9A, 0x14, 0x49, + 0x40, 0x00, 0x11, 0x52, 0x15, 0xE0, 0x05, 0x99, 0xE0, 0x00, 0x41, 0x18, + 0x4B, 0x88, 0x05, 0x99, 0x0A, 0x5A, 0x0C, 0x98, 0x28, 0x21, 0x40, 0x5D, + 0x48, 0x43, 0x04, 0x99, 0x40, 0x18, 0x41, 0x8C, 0x00, 0x8C, 0x01, 0xF0, + 0xAD, 0xFC, 0x29, 0x46, 0x79, 0x43, 0x09, 0x19, 0x03, 0x9A, 0x49, 0x00, + 0x50, 0x52, 0x64, 0x1C, 0xE4, 0xB2, 0xBC, 0x42, 0xB3, 0xD3, 0x6D, 0x1C, + 0xED, 0xB2, 0xBD, 0x42, 0xAD, 0xD3, 0x0E, 0x98, 0x06, 0x70, 0x38, 0x46, + 0xA1, 0xE7, 0x00, 0x00, 0x34, 0x00, 0x00, 0x20, 0xFF, 0x7F, 0x00, 0x00, + 0xF8, 0xB5, 0x36, 0x22, 0x00, 0x21, 0x2E, 0x48, 0x02, 0xF0, 0x30, 0xFB, + 0x00, 0x25, 0x06, 0x20, 0x2B, 0x4A, 0x00, 0x21, 0x68, 0x43, 0x84, 0x18, + 0x00, 0x20, 0x4B, 0x00, 0x29, 0x4A, 0x12, 0x5C, 0x16, 0x09, 0x8E, 0x42, + 0x06, 0xD1, 0x17, 0x07, 0xE6, 0x5C, 0x3F, 0x0F, 0x01, 0x22, 0xBA, 0x40, + 0x16, 0x43, 0xE6, 0x54, 0x40, 0x1C, 0x07, 0x28, 0xF0, 0xD3, 0x49, 0x1C, + 0x03, 0x29, 0xEB, 0xD3, 0x6D, 0x1C, 0x07, 0x2D, 0xE3, 0xD3, 0x00, 0x21, + 0x1E, 0x4A, 0x00, 0x20, 0x52, 0x5C, 0x94, 0x46, 0x16, 0x09, 0x86, 0x42, + 0x11, 0xD1, 0x06, 0x22, 0x0B, 0x46, 0x53, 0x43, 0x18, 0x4A, 0x64, 0x46, + 0x9B, 0x18, 0x42, 0x00, 0x27, 0x07, 0x9D, 0x5C, 0x3F, 0x0F, 0x01, 0x24, + 0xBC, 0x40, 0xA5, 0x43, 0x9D, 0x54, 0x9A, 0x18, 0x53, 0x78, 0x23, 0x43, + 0x53, 0x70, 0x40, 0x1C, 0x03, 0x28, 0xE8, 0xD3, 0x49, 0x1C, 0x07, 0x29, + 0xE0, 0xD3, 0x0F, 0x4E, 0x00, 0x21, 0x00, 0x20, 0x32, 0x5C, 0x13, 0x09, + 0x8B, 0x42, 0x0D, 0xD1, 0x14, 0x07, 0x0A, 0x4A, 0x4B, 0x00, 0x9A, 0x18, + 0x24, 0x0F, 0x20, 0x32, 0x95, 0x7A, 0x01, 0x23, 0xA3, 0x40, 0x1D, 0x43, + 0x95, 0x72, 0x14, 0x7C, 0x9C, 0x43, 0x14, 0x74, 0x40, 0x1C, 0x07, 0x28, + 0xEA, 0xD3, 0x49, 0x1C, 0x03, 0x29, 0xE6, 0xD3, 0xF8, 0xBD, 0x00, 0x00, + 0xC0, 0x07, 0x00, 0x20, 0x4C, 0x73, 0x00, 0x00, 0x70, 0xB5, 0x04, 0x46, + 0x00, 0x20, 0x10, 0x21, 0x20, 0x5E, 0x61, 0x5E, 0x42, 0x18, 0x04, 0x20, + 0x0C, 0x21, 0x20, 0x5E, 0x61, 0x5E, 0x40, 0x18, 0x82, 0x42, 0x01, 0xDA, + 0x11, 0x46, 0x00, 0xE0, 0x01, 0x46, 0x01, 0x29, 0x01, 0xDA, 0x01, 0x21, + 0x04, 0xE0, 0x82, 0x42, 0x01, 0xDA, 0x11, 0x46, 0x00, 0xE0, 0x01, 0x46, + 0x82, 0x42, 0x00, 0xDD, 0x10, 0x46, 0x64, 0x22, 0x50, 0x43, 0xFF, 0xF7, + 0x3C, 0xFC, 0x05, 0x46, 0x02, 0x20, 0x0E, 0x21, 0x20, 0x5E, 0x61, 0x5E, + 0x0A, 0x22, 0x40, 0x18, 0x06, 0x21, 0x61, 0x5E, 0xA2, 0x5E, 0x8A, 0x18, + 0x90, 0x42, 0x01, 0xDA, 0x01, 0x46, 0x00, 0xE0, 0x11, 0x46, 0x01, 0x29, + 0x01, 0xDA, 0x01, 0x21, 0x04, 0xE0, 0x90, 0x42, 0x01, 0xDA, 0x01, 0x46, + 0x00, 0xE0, 0x11, 0x46, 0x90, 0x42, 0x00, 0xDC, 0x10, 0x46, 0x8D, 0x22, + 0x50, 0x43, 0xFF, 0xF7, 0x1C, 0xFC, 0x28, 0x18, 0x00, 0xB2, 0xFA, 0x38, + 0xC1, 0x0F, 0x08, 0x18, 0x41, 0x10, 0x3C, 0x20, 0x40, 0x1A, 0x05, 0x28, + 0x03, 0xDB, 0x3C, 0x28, 0x01, 0xDD, 0x3C, 0x20, 0x02, 0xE0, 0x05, 0x28, + 0x00, 0xDA, 0x05, 0x20, 0xC0, 0xB2, 0x70, 0xBD, 0xF1, 0xB5, 0x8C, 0xB0, + 0x00, 0x20, 0x06, 0x90, 0x50, 0x48, 0x41, 0x68, 0x49, 0x6A, 0x00, 0x29, + 0x7E, 0xD0, 0x00, 0x21, 0x08, 0x46, 0x07, 0x91, 0x87, 0xE0, 0x0E, 0x21, + 0x48, 0x43, 0x4C, 0x49, 0x08, 0x26, 0x45, 0x18, 0x0B, 0x95, 0xAE, 0x5F, + 0x06, 0x20, 0x28, 0x5E, 0x77, 0x10, 0xC0, 0x19, 0x31, 0x46, 0xFF, 0xF7, + 0xEE, 0xFB, 0xC4, 0xB2, 0x04, 0x20, 0x28, 0x5E, 0x31, 0x46, 0xC0, 0x19, + 0xFF, 0xF7, 0xE7, 0xFB, 0xC0, 0xB2, 0x05, 0x90, 0x01, 0x20, 0x84, 0x46, + 0x60, 0x1E, 0x41, 0xB2, 0x00, 0x25, 0x60, 0x46, 0x20, 0x18, 0x08, 0x90, + 0x52, 0xE0, 0x05, 0x9A, 0x60, 0x46, 0x10, 0x1A, 0x05, 0x9B, 0x62, 0x46, + 0x9A, 0x18, 0x40, 0xB2, 0x09, 0x92, 0x44, 0xE0, 0x00, 0x23, 0x1C, 0x46, + 0x00, 0x29, 0x00, 0xDB, 0x0C, 0x46, 0x35, 0x4A, 0x52, 0x68, 0x96, 0x46, + 0x92, 0x7E, 0x16, 0x46, 0x52, 0x1E, 0x0A, 0x92, 0x94, 0x42, 0x04, 0xDA, + 0x1A, 0x46, 0x00, 0x29, 0x02, 0xDB, 0x0A, 0x46, 0x00, 0xE0, 0x72, 0x1E, + 0x00, 0x27, 0xD2, 0xB2, 0x00, 0x28, 0x00, 0xDB, 0x07, 0x46, 0x73, 0x46, + 0xDB, 0x7E, 0x1C, 0x46, 0x5B, 0x1E, 0x9E, 0x46, 0x9F, 0x42, 0x04, 0xDA, + 0x00, 0x23, 0x00, 0x28, 0x02, 0xDB, 0x03, 0x46, 0x00, 0xE0, 0x63, 0x1E, + 0xDB, 0xB2, 0x00, 0x29, 0x01, 0xDA, 0x01, 0x22, 0x04, 0xE0, 0x0A, 0x9F, + 0x8F, 0x42, 0x01, 0xDA, 0xB6, 0x1E, 0xF2, 0xB2, 0x00, 0x28, 0x01, 0xDA, + 0x01, 0x23, 0x03, 0xE0, 0x86, 0x45, 0x01, 0xDA, 0xA3, 0x1E, 0xDB, 0xB2, + 0x54, 0x43, 0xE2, 0x18, 0x0C, 0x9B, 0x52, 0x00, 0x9A, 0x5A, 0x6B, 0x00, + 0x6C, 0x46, 0x6D, 0x1C, 0xE2, 0x52, 0x40, 0x1C, 0x09, 0x9A, 0x6D, 0xB2, + 0x40, 0xB2, 0x82, 0x42, 0xB8, 0xDA, 0x49, 0x1C, 0x08, 0x98, 0x49, 0xB2, + 0x88, 0x42, 0xAA, 0xDA, 0x11, 0x48, 0x40, 0x68, 0x41, 0x6A, 0x68, 0x46, + 0x88, 0x47, 0x00, 0xE0, 0x19, 0xE0, 0x0B, 0x99, 0xC8, 0x72, 0x0B, 0x98, + 0x06, 0x99, 0xC0, 0x7A, 0x88, 0x42, 0x00, 0xD9, 0x06, 0x90, 0x07, 0x98, + 0x40, 0x1C, 0xC0, 0xB2, 0x07, 0x90, 0x08, 0x49, 0x49, 0x78, 0x88, 0x42, + 0x00, 0xD2, 0x72, 0xE7, 0x05, 0x48, 0x40, 0x68, 0x01, 0x7B, 0x4A, 0x00, + 0x8A, 0x18, 0x06, 0x99, 0x51, 0x18, 0x89, 0x08, 0x01, 0x73, 0x0D, 0xB0, + 0xF0, 0xBD, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, 0x8C, 0x09, 0x00, 0x20, + 0xF8, 0xB5, 0x48, 0x22, 0x00, 0x21, 0x2E, 0x48, 0x02, 0xF0, 0xCE, 0xF9, + 0x2C, 0x4C, 0x2D, 0x4E, 0x00, 0x21, 0x00, 0x20, 0x2C, 0x4A, 0x12, 0x5C, + 0x12, 0x09, 0x8A, 0x42, 0x24, 0xD1, 0x32, 0x18, 0x8B, 0x00, 0x40, 0x32, + 0xE5, 0x5C, 0x12, 0x78, 0x15, 0x43, 0xE5, 0x54, 0x1B, 0x19, 0x9D, 0x7B, + 0x15, 0x43, 0x9D, 0x73, 0xDD, 0x7E, 0x15, 0x43, 0xDD, 0x76, 0xC5, 0x07, + 0x08, 0xD0, 0x1D, 0x46, 0x20, 0x35, 0xAF, 0x79, 0x17, 0x43, 0xAF, 0x71, + 0xEF, 0x7C, 0x17, 0x43, 0xEF, 0x74, 0x07, 0xE0, 0x1D, 0x46, 0x20, 0x35, + 0xAF, 0x7C, 0x17, 0x43, 0xAF, 0x74, 0xEF, 0x79, 0x17, 0x43, 0xEF, 0x71, + 0x20, 0x33, 0xDD, 0x7F, 0x15, 0x43, 0xDD, 0x77, 0x40, 0x1C, 0xC0, 0xB2, + 0x07, 0x28, 0xD1, 0xD3, 0x16, 0x4F, 0x00, 0x22, 0xB8, 0x5C, 0x00, 0x09, + 0x88, 0x42, 0x17, 0xD1, 0xB0, 0x18, 0x8B, 0x00, 0x40, 0x30, 0xE5, 0x5C, + 0xC0, 0x79, 0x05, 0x43, 0xE5, 0x54, 0x1B, 0x19, 0xDD, 0x7B, 0x05, 0x43, + 0xDD, 0x73, 0x9D, 0x7E, 0x05, 0x43, 0x9D, 0x76, 0x20, 0x33, 0xDD, 0x79, + 0x05, 0x43, 0xDD, 0x71, 0xDD, 0x7C, 0x05, 0x43, 0xDD, 0x74, 0xDD, 0x7F, + 0x05, 0x43, 0xDD, 0x77, 0x52, 0x1C, 0xD2, 0xB2, 0x09, 0x2A, 0xDF, 0xD3, + 0x49, 0x1C, 0xC9, 0xB2, 0x03, 0x29, 0xAA, 0xD3, 0xF8, 0xBD, 0x00, 0x00, + 0x78, 0x07, 0x00, 0x20, 0x68, 0x73, 0x00, 0x00, 0x4C, 0x73, 0x00, 0x00, + 0x53, 0x73, 0x00, 0x00, 0x38, 0xB5, 0x6B, 0x46, 0x00, 0x90, 0x1C, 0x88, + 0x0A, 0x46, 0x0A, 0x34, 0x1C, 0x80, 0x00, 0x99, 0x01, 0xF0, 0x74, 0xFC, + 0x38, 0xBD, 0x40, 0x1A, 0x00, 0xB2, 0x00, 0x28, 0x02, 0xDA, 0xFF, 0x30, + 0x69, 0x30, 0x00, 0xB2, 0x80, 0xB2, 0x70, 0x47, 0xF0, 0xB5, 0x6E, 0x4E, + 0x8B, 0xB0, 0xF2, 0x6B, 0x33, 0x46, 0x10, 0x79, 0x05, 0x90, 0xD0, 0x78, + 0x04, 0x90, 0x80, 0x3B, 0x14, 0x78, 0x59, 0x6D, 0x64, 0x00, 0x58, 0x6C, + 0x00, 0x94, 0xD4, 0x7D, 0x09, 0x94, 0x1B, 0x24, 0x14, 0x57, 0x08, 0x94, + 0x00, 0x24, 0x1C, 0x62, 0x07, 0x94, 0xDC, 0x61, 0x06, 0x94, 0x55, 0x78, + 0x6D, 0x08, 0x03, 0x95, 0x52, 0x25, 0x55, 0x5F, 0x6A, 0x10, 0x02, 0x92, + 0xDA, 0x1D, 0xF9, 0x32, 0x0A, 0x92, 0x14, 0x77, 0x5A, 0x78, 0x05, 0x2A, + 0x21, 0xD8, 0x04, 0x9C, 0x05, 0x9A, 0x54, 0x43, 0x00, 0x22, 0x20, 0x33, + 0x19, 0xE0, 0x58, 0x4D, 0x80, 0x3D, 0x6D, 0x78, 0x02, 0x2D, 0x01, 0xD8, + 0x0D, 0x88, 0x05, 0xE0, 0x00, 0x27, 0x05, 0x88, 0xCF, 0x5F, 0xED, 0x19, + 0xED, 0x03, 0x2D, 0x0C, 0x05, 0x80, 0x00, 0x25, 0x4D, 0x5F, 0x00, 0x2D, + 0x03, 0xDA, 0xDD, 0x7C, 0x01, 0x27, 0x3D, 0x43, 0xDD, 0x74, 0x80, 0x1C, + 0x89, 0x1C, 0x52, 0x1C, 0x92, 0xB2, 0xA2, 0x42, 0xE3, 0xD3, 0x4A, 0x49, + 0x80, 0x39, 0x48, 0x6C, 0x01, 0x90, 0x00, 0x25, 0x4C, 0x6D, 0x81, 0xE0, + 0x00, 0x20, 0x0A, 0x9A, 0x84, 0x46, 0x92, 0x6B, 0x01, 0x46, 0x50, 0x55, + 0x03, 0x46, 0x45, 0xE0, 0x01, 0x98, 0x22, 0x88, 0x00, 0x88, 0x80, 0x1A, + 0x02, 0xB2, 0x22, 0x80, 0x00, 0x98, 0x82, 0x42, 0x05, 0xDA, 0x49, 0x1C, + 0x60, 0x46, 0x80, 0x18, 0x00, 0xB2, 0xC9, 0xB2, 0x84, 0x46, 0x03, 0x98, + 0x82, 0x42, 0x1A, 0xDD, 0x09, 0x98, 0x82, 0x42, 0x2A, 0xDD, 0xF0, 0x6B, + 0xC0, 0x79, 0x00, 0x28, 0x03, 0xD0, 0x04, 0x9F, 0x7F, 0x1E, 0xBD, 0x42, + 0x04, 0xD0, 0x01, 0x27, 0x07, 0x98, 0x9F, 0x40, 0x07, 0x43, 0x07, 0x97, + 0x0A, 0x98, 0x01, 0x27, 0x80, 0x6B, 0x47, 0x55, 0xF0, 0x6B, 0x00, 0x78, + 0x90, 0x42, 0x15, 0xDA, 0x0A, 0x98, 0x07, 0x77, 0x12, 0xE0, 0x02, 0x98, + 0x82, 0x42, 0x0F, 0xDA, 0x08, 0x98, 0x82, 0x42, 0x0C, 0xDA, 0xF0, 0x6B, + 0xC0, 0x79, 0x00, 0x28, 0x03, 0xD0, 0x04, 0x98, 0x40, 0x1E, 0x85, 0x42, + 0x04, 0xD0, 0x01, 0x20, 0x06, 0x9A, 0x98, 0x40, 0x10, 0x43, 0x06, 0x90, + 0x01, 0x98, 0xA4, 0x1C, 0x80, 0x1C, 0x5B, 0x1C, 0x5B, 0xB2, 0x01, 0x90, + 0x05, 0x98, 0x83, 0x42, 0xB6, 0xDB, 0xF0, 0x6B, 0x20, 0x30, 0x80, 0x7C, + 0x00, 0x28, 0x29, 0xD0, 0x05, 0x98, 0x40, 0x00, 0x24, 0x1A, 0x02, 0x29, + 0x04, 0xD9, 0x60, 0x46, 0xFF, 0xF7, 0x35, 0xFA, 0x00, 0xB2, 0x00, 0xE0, + 0x00, 0x20, 0x00, 0x22, 0x19, 0xE0, 0x16, 0x49, 0x00, 0x28, 0x61, 0x5E, + 0x0B, 0xDD, 0x00, 0x9B, 0x99, 0x42, 0x0F, 0xDA, 0x43, 0x1C, 0x99, 0x42, + 0x01, 0xDD, 0x09, 0x1A, 0x09, 0xE0, 0x00, 0x29, 0x08, 0xDD, 0x01, 0x21, + 0x05, 0xE0, 0x81, 0x42, 0xF7, 0xDB, 0x00, 0x29, 0x02, 0xDA, 0x00, 0x21, + 0xC9, 0x43, 0x21, 0x80, 0xA4, 0x1C, 0x52, 0x1C, 0x52, 0xB2, 0x05, 0x99, + 0x8A, 0x42, 0xE2, 0xDB, 0x6D, 0x1C, 0x6D, 0xB2, 0x04, 0x98, 0x85, 0x42, + 0x00, 0xDA, 0x79, 0xE7, 0x03, 0x48, 0x07, 0x99, 0x80, 0x38, 0x01, 0x62, + 0x06, 0x99, 0xC1, 0x61, 0x0B, 0xB0, 0xF0, 0xBD, 0xC0, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0xF1, 0xB5, 0x00, 0x25, 0x86, 0xB0, 0x2E, 0x46, + 0x7A, 0xE0, 0x28, 0x46, 0x14, 0x22, 0x50, 0x43, 0x3F, 0x4A, 0x07, 0x46, + 0x84, 0x18, 0xE0, 0x7C, 0x00, 0x09, 0x6F, 0xD0, 0x3D, 0x48, 0x40, 0x68, + 0x02, 0x6A, 0x00, 0x2A, 0x0B, 0xD0, 0x20, 0x7C, 0x01, 0x09, 0x00, 0x07, + 0x00, 0x0F, 0x90, 0x47, 0x00, 0x28, 0x04, 0xD1, 0xE0, 0x7C, 0x00, 0x07, + 0x00, 0x0F, 0xE0, 0x74, 0x5E, 0xE0, 0x60, 0x68, 0x33, 0x4A, 0xA1, 0x68, + 0x02, 0x91, 0xD1, 0x59, 0x00, 0x02, 0x01, 0x91, 0xFF, 0xF7, 0xD9, 0xF9, + 0x30, 0x49, 0x80, 0x30, 0x4F, 0x68, 0xB9, 0x8B, 0x05, 0x91, 0x48, 0x43, + 0xF9, 0x7E, 0xFF, 0xF7, 0xD0, 0xF9, 0x02, 0x99, 0x03, 0x90, 0x08, 0x02, + 0x01, 0x99, 0xFF, 0xF7, 0xCA, 0xF9, 0xF9, 0x8B, 0x80, 0x30, 0x48, 0x43, + 0x04, 0x91, 0xB9, 0x7E, 0xFF, 0xF7, 0xC3, 0xF9, 0x03, 0x99, 0x02, 0x12, + 0x09, 0x12, 0x00, 0x29, 0x01, 0xDA, 0x00, 0x21, 0x03, 0xE0, 0x05, 0x98, + 0x88, 0x42, 0x00, 0xDA, 0x01, 0x46, 0x00, 0x2A, 0x01, 0xDA, 0x00, 0x22, + 0x03, 0xE0, 0x04, 0x98, 0x90, 0x42, 0x00, 0xDA, 0x02, 0x46, 0x06, 0x9B, + 0xF0, 0x00, 0x19, 0x52, 0x06, 0x99, 0x76, 0x1C, 0x40, 0x18, 0x42, 0x80, + 0x41, 0x79, 0x62, 0x7C, 0x09, 0x09, 0x12, 0x07, 0x09, 0x01, 0x12, 0x0F, + 0x11, 0x43, 0x41, 0x71, 0x62, 0x7C, 0xC9, 0xB2, 0x09, 0x07, 0x12, 0x09, + 0x09, 0x0F, 0x12, 0x01, 0x11, 0x43, 0x41, 0x71, 0x81, 0x79, 0xA2, 0x7C, + 0x09, 0x09, 0x12, 0x07, 0x09, 0x01, 0x12, 0x0F, 0x11, 0x43, 0x81, 0x71, + 0xA2, 0x7C, 0xC9, 0xB2, 0x09, 0x07, 0x12, 0x09, 0x09, 0x0F, 0x12, 0x01, + 0x11, 0x43, 0x81, 0x71, 0x01, 0x99, 0xF6, 0xB2, 0x49, 0x10, 0x01, 0x71, + 0x08, 0x2E, 0x05, 0xD2, 0x6D, 0x1C, 0xED, 0xB2, 0x04, 0x49, 0x08, 0x78, + 0x85, 0x42, 0x80, 0xD3, 0x30, 0x46, 0x07, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xC4, 0x08, 0x00, 0x20, 0x2C, 0x00, 0x00, 0x20, 0xF3, 0xB5, 0x85, 0xB0, + 0x05, 0x20, 0x00, 0x90, 0x31, 0x48, 0x04, 0x90, 0xC0, 0x6B, 0x40, 0x30, + 0x00, 0x78, 0x80, 0x1E, 0xC7, 0xB2, 0x3F, 0x2F, 0x00, 0xD9, 0x3F, 0x27, + 0x00, 0x20, 0x80, 0x25, 0x2C, 0x46, 0x02, 0x90, 0x20, 0x46, 0x01, 0x26, + 0x03, 0xE0, 0xC0, 0x1B, 0x76, 0x1C, 0xC0, 0xB2, 0xF6, 0xB2, 0xB8, 0x42, + 0xF9, 0xD8, 0x32, 0x46, 0x39, 0x46, 0x01, 0x90, 0x05, 0xF0, 0x36, 0xFA, + 0x06, 0x98, 0x80, 0x47, 0x03, 0x90, 0x06, 0x98, 0x80, 0x47, 0x01, 0x46, + 0x03, 0x98, 0x08, 0x18, 0x04, 0x99, 0x00, 0x04, 0xC9, 0x6B, 0x40, 0x0C, + 0x40, 0x31, 0xC9, 0x88, 0x81, 0x42, 0x01, 0xD9, 0xAC, 0x43, 0x08, 0xE0, + 0x01, 0x2D, 0x06, 0xD1, 0x0A, 0x46, 0x14, 0x32, 0x82, 0x42, 0x06, 0xD2, + 0x64, 0x1C, 0xE4, 0xB2, 0x03, 0xE0, 0x00, 0x2D, 0x01, 0xD1, 0x01, 0x22, + 0x02, 0x92, 0x6D, 0x08, 0x02, 0x9A, 0x2C, 0x43, 0x00, 0x2A, 0xCD, 0xD0, + 0x04, 0x9A, 0xD2, 0x6B, 0x40, 0x32, 0xD2, 0x88, 0x52, 0x08, 0x82, 0x42, + 0x02, 0xD2, 0x49, 0x00, 0x81, 0x42, 0x05, 0xD8, 0x00, 0x99, 0x49, 0x1E, + 0x09, 0x06, 0x09, 0x0E, 0x00, 0x91, 0xB9, 0xD1, 0x00, 0x99, 0x05, 0x22, + 0x51, 0x1A, 0x05, 0x9A, 0x11, 0x70, 0x05, 0x99, 0x4E, 0x70, 0x05, 0x99, + 0x8F, 0x70, 0x05, 0x9A, 0x01, 0x99, 0xD1, 0x70, 0x05, 0x99, 0x08, 0x71, + 0x01, 0x0A, 0x05, 0x98, 0x41, 0x71, 0x07, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0x70, 0xB5, 0x15, 0x4C, 0xE0, 0x7C, 0xC0, 0x07, + 0x24, 0xD0, 0x3C, 0x20, 0x05, 0xF0, 0x20, 0xFA, 0x00, 0x25, 0xE5, 0x75, + 0x02, 0xF0, 0x78, 0xF8, 0x20, 0x46, 0x20, 0x38, 0x05, 0x72, 0x01, 0x20, + 0x04, 0xF0, 0x20, 0xFF, 0x02, 0x20, 0x05, 0xF0, 0x3F, 0xF9, 0x02, 0xF0, + 0xA1, 0xFE, 0x0B, 0x48, 0x81, 0x7C, 0x80, 0x22, 0x11, 0x43, 0x81, 0x74, + 0x00, 0xF0, 0x12, 0xF8, 0x00, 0x20, 0x05, 0xF0, 0x33, 0xF9, 0x02, 0x20, + 0x05, 0xF0, 0x30, 0xF9, 0x00, 0x21, 0x02, 0x20, 0x05, 0xF0, 0x08, 0xF8, + 0x02, 0xF0, 0x12, 0xF9, 0x70, 0xBD, 0x00, 0x00, 0x60, 0x00, 0x00, 0x20, + 0xE0, 0x12, 0x00, 0x40, 0xF8, 0xB5, 0x19, 0x48, 0x18, 0x4F, 0xC0, 0x6B, + 0x80, 0x3F, 0x85, 0x79, 0x39, 0x7A, 0x2C, 0x46, 0x01, 0x29, 0x0E, 0xD0, + 0x00, 0x24, 0x15, 0x4E, 0x31, 0x7A, 0x02, 0x22, 0x11, 0x43, 0x31, 0x72, + 0x13, 0x49, 0x08, 0x22, 0xCA, 0x80, 0x20, 0x30, 0xC0, 0x78, 0x40, 0x1E, + 0xC0, 0xB2, 0x00, 0x90, 0x12, 0xE0, 0x6D, 0x1C, 0xED, 0xB2, 0xEE, 0xE7, + 0x0E, 0x49, 0xAA, 0x20, 0x88, 0x80, 0xFF, 0x20, 0x0B, 0x49, 0x02, 0x30, + 0xC8, 0x81, 0xF9, 0x6D, 0x01, 0x20, 0x08, 0x55, 0x21, 0x46, 0x00, 0x98, + 0x00, 0xF0, 0x12, 0xF8, 0x64, 0x1C, 0xE4, 0xB2, 0xAC, 0x42, 0xED, 0xD3, + 0x30, 0x7A, 0xFD, 0x21, 0x08, 0x40, 0x30, 0x72, 0xF8, 0xBD, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x40, 0x00, 0x10, 0x00, 0x40, + 0x00, 0x02, 0x00, 0x40, 0xF3, 0xB5, 0x4A, 0x48, 0x49, 0x49, 0xC0, 0x6B, + 0x8F, 0xB0, 0x06, 0x79, 0x80, 0x39, 0x10, 0x9A, 0x8B, 0x6D, 0x72, 0x43, + 0x09, 0x7A, 0x9D, 0x18, 0x01, 0x29, 0x00, 0xD1, 0xC6, 0x79, 0x40, 0x30, + 0x80, 0x89, 0x0D, 0x90, 0x02, 0x20, 0x0B, 0x90, 0x00, 0x20, 0x0A, 0x90, + 0x3F, 0x48, 0x60, 0x30, 0x0C, 0x90, 0x00, 0x20, 0x3E, 0x49, 0x06, 0xE0, + 0x43, 0x00, 0x6A, 0x46, 0xD1, 0x52, 0x00, 0x22, 0x2A, 0x54, 0x40, 0x1C, + 0xC0, 0xB2, 0xB0, 0x42, 0xF6, 0xD3, 0x00, 0x24, 0x27, 0x46, 0x5C, 0xE0, + 0x02, 0x20, 0x10, 0x99, 0x04, 0xF0, 0x98, 0xFF, 0x00, 0x21, 0x01, 0x20, + 0x10, 0x9A, 0x05, 0xF0, 0xDB, 0xF9, 0x0C, 0x99, 0x00, 0x20, 0x08, 0x70, + 0x32, 0x48, 0x11, 0x21, 0x81, 0x80, 0x43, 0x21, 0x01, 0x80, 0x00, 0xE0, + 0x30, 0xBF, 0x0C, 0x98, 0x00, 0x78, 0x00, 0x28, 0xFA, 0xD0, 0x00, 0x21, + 0x05, 0xA8, 0x03, 0xF0, 0x09, 0xFC, 0x01, 0x21, 0x08, 0x46, 0x10, 0x9A, + 0x05, 0xF0, 0xC4, 0xF9, 0x00, 0x20, 0x1A, 0xE0, 0x01, 0x21, 0x81, 0x40, + 0x8C, 0x46, 0x21, 0x42, 0x13, 0xD1, 0x41, 0x00, 0x05, 0xAA, 0x53, 0x5E, + 0x0D, 0x9A, 0x9A, 0x1A, 0x00, 0xD5, 0x52, 0x42, 0x6B, 0x46, 0x5B, 0x5A, + 0x92, 0xB2, 0x93, 0x42, 0x02, 0xD3, 0x6B, 0x46, 0x5A, 0x52, 0x04, 0xE0, + 0x29, 0x5C, 0x49, 0x1E, 0x29, 0x54, 0x61, 0x46, 0x0C, 0x43, 0x40, 0x1C, + 0xC0, 0xB2, 0xB0, 0x42, 0xE2, 0xD3, 0x01, 0x21, 0x0B, 0x46, 0xB3, 0x40, + 0x5B, 0x1E, 0xA3, 0x42, 0x02, 0xD1, 0x01, 0x20, 0x0A, 0x90, 0x17, 0xE0, + 0x0F, 0x98, 0x7F, 0x1C, 0x87, 0x42, 0x13, 0xD2, 0x00, 0x20, 0x0B, 0x46, + 0x0B, 0xE0, 0x29, 0x5C, 0x0F, 0x9A, 0x91, 0x42, 0x05, 0xD2, 0x1A, 0x46, + 0x82, 0x40, 0x22, 0x42, 0x01, 0xD1, 0x49, 0x1C, 0x29, 0x54, 0x40, 0x1C, + 0xC0, 0xB2, 0xB0, 0x42, 0xF1, 0xD3, 0x0A, 0x98, 0x00, 0x28, 0x9F, 0xD0, + 0x0B, 0x98, 0x40, 0x1E, 0x00, 0x06, 0x00, 0x0E, 0x0B, 0x90, 0x02, 0xD0, + 0x0A, 0x98, 0x00, 0x28, 0x87, 0xD0, 0x0A, 0x98, 0x11, 0xB0, 0xC0, 0xB2, + 0xF0, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x40, 0xF0, 0xB5, 0x46, 0x4F, 0x00, 0x23, 0x91, 0xB0, + 0x3C, 0x46, 0xFB, 0x71, 0x20, 0x34, 0x20, 0x7D, 0x21, 0x7D, 0x80, 0x07, + 0xC0, 0x0F, 0x49, 0x08, 0x49, 0x00, 0x01, 0x43, 0x21, 0x75, 0x20, 0x7D, + 0xFD, 0x25, 0x28, 0x40, 0x20, 0x75, 0x19, 0x20, 0x6E, 0x46, 0xB0, 0x74, + 0x03, 0x21, 0x31, 0x75, 0x28, 0x20, 0xF0, 0x74, 0x0A, 0x20, 0xB0, 0x75, + 0xF0, 0x7E, 0x14, 0x22, 0xC0, 0x06, 0xF2, 0x75, 0xC0, 0x0E, 0x18, 0x26, + 0x30, 0x43, 0x6E, 0x46, 0xB1, 0x76, 0x04, 0x21, 0x08, 0x43, 0x28, 0x40, + 0x31, 0x76, 0x3C, 0x21, 0x71, 0x76, 0x40, 0x08, 0x32, 0x82, 0x40, 0x00, + 0xF0, 0x76, 0x01, 0x20, 0x70, 0x75, 0x2F, 0x48, 0x08, 0x90, 0x0A, 0x30, + 0x09, 0x90, 0x38, 0x78, 0x25, 0x46, 0x30, 0x85, 0xE0, 0x35, 0xE8, 0x7F, + 0xFF, 0x28, 0x01, 0xD1, 0x14, 0x20, 0xE8, 0x77, 0x30, 0x77, 0x29, 0x48, + 0x0C, 0x90, 0x26, 0x4E, 0x28, 0x48, 0x80, 0x36, 0x0E, 0x93, 0x0D, 0x90, + 0xF0, 0x6B, 0x08, 0xAA, 0x81, 0x79, 0x91, 0x72, 0x41, 0x79, 0xD1, 0x72, + 0x01, 0x46, 0x40, 0x31, 0x0B, 0x89, 0x6A, 0x46, 0x93, 0x85, 0x49, 0x89, + 0xD1, 0x85, 0x31, 0x46, 0x40, 0x31, 0x03, 0x91, 0x49, 0x7E, 0xBB, 0x6F, + 0x3A, 0x6E, 0x01, 0x93, 0x00, 0x92, 0x02, 0x91, 0x42, 0x79, 0x81, 0x79, + 0x7B, 0x6D, 0xF8, 0x6C, 0x00, 0xF0, 0x58, 0xFD, 0x03, 0x99, 0x48, 0x7E, + 0x32, 0x28, 0x09, 0xD9, 0x69, 0x46, 0xC8, 0x7E, 0xC0, 0x06, 0xC0, 0x0E, + 0x20, 0x30, 0xC8, 0x76, 0x02, 0x20, 0x48, 0x75, 0x1E, 0x20, 0xC8, 0x74, + 0xF1, 0x6B, 0x32, 0x69, 0xC9, 0x7A, 0x70, 0x69, 0x00, 0x90, 0x0F, 0xAB, + 0x01, 0xA8, 0x0E, 0xC0, 0xAA, 0x6B, 0x04, 0xAB, 0x79, 0x6D, 0xF8, 0x6C, + 0x00, 0xF0, 0x56, 0xFC, 0xF8, 0x71, 0x69, 0x46, 0x09, 0x7F, 0xE9, 0x77, + 0x00, 0x28, 0x05, 0xD0, 0x20, 0x7D, 0x02, 0x21, 0x08, 0x43, 0x20, 0x75, + 0x11, 0xB0, 0xF0, 0xBD, 0x14, 0x20, 0xE8, 0x77, 0xFA, 0xE7, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x20, 0xFC, 0x73, 0x00, 0x00, 0x2D, 0x14, 0x00, 0x00, + 0x85, 0x08, 0x00, 0x00, 0xF0, 0xB5, 0x70, 0x48, 0x89, 0xB0, 0xC0, 0x6B, + 0xC1, 0x78, 0x04, 0x91, 0x01, 0x79, 0x03, 0x91, 0x3A, 0x21, 0x09, 0x5C, + 0x8E, 0x46, 0x3E, 0x21, 0x41, 0x5E, 0x01, 0x91, 0x69, 0x49, 0x82, 0x7B, + 0x80, 0x39, 0x09, 0x6A, 0x08, 0x91, 0x67, 0x49, 0x80, 0x39, 0x89, 0x69, + 0x07, 0x91, 0x65, 0x49, 0x60, 0x39, 0x0C, 0x46, 0xA0, 0x34, 0x06, 0x91, + 0x00, 0x2A, 0x65, 0xD0, 0x07, 0x9A, 0x08, 0x99, 0x11, 0x42, 0x61, 0xD1, + 0x25, 0x46, 0x00, 0x23, 0xC0, 0x3D, 0x2D, 0x6E, 0x76, 0x46, 0xAC, 0x46, + 0x76, 0x42, 0x19, 0x46, 0x1A, 0x46, 0x1D, 0x46, 0x05, 0x96, 0x13, 0xE0, + 0x67, 0x46, 0x00, 0x26, 0xBE, 0x5F, 0x76, 0x45, 0x01, 0xDD, 0x49, 0x1C, + 0x08, 0xE0, 0x05, 0x9F, 0xBE, 0x42, 0x05, 0xDA, 0x01, 0x9F, 0x52, 0x1C, + 0xBE, 0x42, 0x01, 0xDA, 0x5B, 0x1C, 0xDB, 0xB2, 0x66, 0x46, 0xB6, 0x1C, + 0xB4, 0x46, 0x6D, 0x1C, 0x03, 0x9E, 0xB5, 0x42, 0xE8, 0xD3, 0x4E, 0x4D, + 0x80, 0x3D, 0xAD, 0x6F, 0xAC, 0x46, 0x00, 0x25, 0x13, 0xE0, 0x67, 0x46, + 0x00, 0x26, 0xBE, 0x5F, 0x76, 0x45, 0x01, 0xDD, 0x49, 0x1C, 0x08, 0xE0, + 0x05, 0x9F, 0xBE, 0x42, 0x05, 0xDA, 0x01, 0x9F, 0x52, 0x1C, 0xBE, 0x42, + 0x01, 0xDA, 0x5B, 0x1C, 0xDB, 0xB2, 0x66, 0x46, 0xB6, 0x1C, 0xB4, 0x46, + 0x6D, 0x1C, 0x04, 0x9E, 0xB5, 0x42, 0xE8, 0xD3, 0x3F, 0x4D, 0x40, 0x35, + 0xAD, 0x7E, 0x04, 0x29, 0x01, 0xD8, 0x00, 0x2A, 0x07, 0xD0, 0x6D, 0x1C, + 0xE9, 0xB2, 0xA1, 0x76, 0x00, 0x2B, 0x06, 0xD0, 0x09, 0x1D, 0xA1, 0x76, + 0x03, 0xE0, 0x00, 0x2D, 0x12, 0xD0, 0x6D, 0x1E, 0xA5, 0x76, 0xA1, 0x7E, + 0x32, 0x29, 0x0D, 0xD9, 0x00, 0x21, 0xA1, 0x76, 0x33, 0x4A, 0x01, 0x21, + 0x80, 0x3A, 0x51, 0x70, 0x06, 0x9A, 0xD2, 0x7C, 0x0A, 0x43, 0x06, 0x99, + 0xCA, 0x74, 0x01, 0xE0, 0x00, 0x21, 0xA1, 0x76, 0x2D, 0x49, 0x03, 0x9B, + 0x80, 0x39, 0x04, 0x9A, 0x49, 0x6D, 0x5A, 0x43, 0x00, 0x26, 0x94, 0x46, + 0x35, 0x46, 0x32, 0x46, 0x10, 0xE0, 0x00, 0x23, 0xCB, 0x5E, 0xC7, 0x7D, + 0xBB, 0x42, 0x04, 0xDD, 0x07, 0x78, 0xBB, 0x42, 0x01, 0xDA, 0x76, 0x1C, + 0x04, 0xE0, 0x1B, 0x27, 0xC7, 0x57, 0xBB, 0x42, 0x00, 0xDA, 0x6D, 0x1C, + 0x89, 0x1C, 0x52, 0x1C, 0x62, 0x45, 0xEC, 0xD3, 0x00, 0x21, 0x02, 0x91, + 0x80, 0x7B, 0x14, 0x27, 0x00, 0x28, 0x0E, 0xD0, 0x05, 0x2D, 0x03, 0xD9, + 0x07, 0x98, 0x00, 0x28, 0x06, 0xD0, 0x01, 0xE0, 0x00, 0x2D, 0x06, 0xD0, + 0x08, 0x99, 0x07, 0x98, 0x08, 0x42, 0x02, 0xD1, 0x01, 0x20, 0x28, 0x27, + 0x02, 0x90, 0x60, 0x46, 0x80, 0x00, 0x05, 0x21, 0xFE, 0xF7, 0xA5, 0xFE, + 0x11, 0x49, 0x40, 0x31, 0xC9, 0x7E, 0x86, 0x42, 0x04, 0xD2, 0x85, 0x42, + 0x02, 0xD2, 0x02, 0x9A, 0x01, 0x2A, 0x0E, 0xD1, 0x49, 0x1C, 0xC8, 0xB2, + 0xE0, 0x76, 0xB8, 0x42, 0x07, 0xD3, 0x06, 0x98, 0xC0, 0x7C, 0x01, 0x21, + 0x08, 0x43, 0x06, 0x99, 0xC8, 0x74, 0x00, 0x20, 0xE0, 0x76, 0x09, 0xB0, + 0xF0, 0xBD, 0x40, 0x08, 0xB0, 0x42, 0xFA, 0xD9, 0xA8, 0x42, 0xF8, 0xD9, + 0x00, 0x29, 0xF6, 0xD0, 0x49, 0x1E, 0xE1, 0x76, 0xF3, 0xE7, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x8C, 0x46, 0x4D, 0x49, 0x88, 0xB0, + 0xC9, 0x6B, 0x07, 0x91, 0x8D, 0x79, 0x4C, 0x79, 0x01, 0x46, 0x61, 0x43, + 0x4A, 0x00, 0x61, 0x46, 0x4B, 0x00, 0x48, 0x49, 0xD2, 0x18, 0x80, 0x39, + 0x49, 0x6D, 0x52, 0x18, 0x61, 0x00, 0x8E, 0x46, 0x56, 0x1A, 0x31, 0x46, + 0x40, 0x39, 0xCF, 0x8F, 0x69, 0x46, 0x0F, 0x80, 0x37, 0x88, 0x4F, 0x80, + 0x76, 0x88, 0x8E, 0x80, 0x11, 0x46, 0x40, 0x39, 0xCE, 0x8F, 0x69, 0x46, + 0xCE, 0x80, 0x16, 0x88, 0x0E, 0x81, 0x56, 0x88, 0x4E, 0x81, 0x71, 0x46, + 0x8F, 0x18, 0x05, 0x97, 0x40, 0x3F, 0xFE, 0x8F, 0x69, 0x46, 0x8E, 0x81, + 0x71, 0x46, 0x52, 0x5A, 0x69, 0x46, 0xCA, 0x81, 0x05, 0x9F, 0x7A, 0x88, + 0x0A, 0x82, 0x34, 0x49, 0x80, 0x39, 0x0A, 0x6E, 0x99, 0x1E, 0x56, 0x5A, + 0x69, 0x46, 0x8E, 0x82, 0xD6, 0x5E, 0xCE, 0x82, 0x9B, 0x1C, 0xD2, 0x5A, + 0x0A, 0x83, 0x62, 0x46, 0x00, 0x21, 0x6B, 0x46, 0x00, 0x2A, 0x2F, 0xD0, + 0x64, 0x1E, 0xA4, 0x45, 0x03, 0xD1, 0x99, 0x80, 0x59, 0x81, 0x19, 0x82, + 0x19, 0x83, 0x00, 0x28, 0x2B, 0xD0, 0x6A, 0x1E, 0x90, 0x42, 0x02, 0xD1, + 0x99, 0x81, 0xD9, 0x81, 0x19, 0x82, 0x24, 0x49, 0x80, 0x39, 0x09, 0x78, + 0x4C, 0x08, 0x00, 0x22, 0x11, 0x46, 0x4F, 0x00, 0xDF, 0x5B, 0x49, 0x1C, + 0xBA, 0x18, 0xC9, 0xB2, 0x12, 0xB2, 0x09, 0x29, 0xF7, 0xD3, 0xA2, 0x42, + 0x0D, 0xDB, 0x07, 0x99, 0x89, 0x7B, 0x00, 0x29, 0x2E, 0xD0, 0x1A, 0x49, + 0x0A, 0x22, 0x40, 0x31, 0x4B, 0x7E, 0x80, 0x31, 0x00, 0x2B, 0x00, 0xD0, + 0x0A, 0x79, 0x96, 0x42, 0x0B, 0xDA, 0x00, 0x20, 0x08, 0xB0, 0xF0, 0xBD, + 0x19, 0x80, 0xD9, 0x80, 0x99, 0x81, 0x99, 0x82, 0xD1, 0xE7, 0x19, 0x80, + 0x59, 0x80, 0x99, 0x80, 0xD5, 0xE7, 0x49, 0x79, 0x00, 0x29, 0x15, 0xD0, + 0x0D, 0x49, 0x00, 0x28, 0x49, 0x6D, 0x07, 0xD0, 0x42, 0x1E, 0x6D, 0x1E, + 0xA8, 0x42, 0x0A, 0xD1, 0x8A, 0x5C, 0x00, 0x2A, 0x0E, 0xD0, 0x09, 0xE0, + 0x08, 0x78, 0x00, 0x28, 0x06, 0xD1, 0x48, 0x78, 0x00, 0x28, 0xDF, 0xD0, + 0x02, 0xE0, 0x8A, 0x5C, 0x00, 0x2A, 0x01, 0xD0, 0x01, 0x20, 0xD9, 0xE7, + 0x42, 0x1C, 0xED, 0xE7, 0x08, 0x5C, 0xF3, 0xE7, 0xC0, 0x00, 0x00, 0x20, + 0x1C, 0xB5, 0x05, 0xA0, 0x03, 0xC8, 0x01, 0x91, 0x00, 0x90, 0x05, 0x4B, + 0x14, 0x22, 0x05, 0x21, 0x68, 0x46, 0x02, 0xF0, 0x43, 0xFF, 0x1C, 0xBD, + 0x08, 0x13, 0x21, 0x28, 0x38, 0x00, 0x00, 0x00, 0x0A, 0x08, 0x00, 0x20, + 0x03, 0x48, 0x01, 0x21, 0x01, 0x70, 0x00, 0x21, 0x41, 0x70, 0x81, 0x70, + 0x70, 0x47, 0x00, 0x00, 0xA4, 0x0A, 0x00, 0x20, 0xF7, 0xB5, 0xA0, 0xB0, + 0x00, 0x20, 0x1B, 0x90, 0xFF, 0x48, 0x14, 0x46, 0x40, 0x68, 0xC1, 0x7E, + 0x12, 0x91, 0x80, 0x7E, 0x11, 0x90, 0x11, 0x46, 0x20, 0x98, 0x02, 0xF0, + 0x1B, 0xF8, 0x00, 0x28, 0x01, 0xD0, 0x01, 0x20, 0x1B, 0x90, 0x60, 0xB2, + 0x6B, 0xE2, 0xF8, 0x49, 0x40, 0x00, 0x08, 0x5A, 0x60, 0xE2, 0x00, 0x21, + 0x0B, 0x91, 0x0A, 0x91, 0xF5, 0xA1, 0x06, 0xC9, 0x06, 0x91, 0x07, 0x92, + 0xF5, 0xA1, 0x06, 0xC9, 0x04, 0x91, 0x81, 0x04, 0x46, 0x06, 0x4D, 0x0E, + 0x12, 0x98, 0x76, 0x0E, 0x68, 0x43, 0x80, 0x19, 0x20, 0x99, 0x40, 0x00, + 0x44, 0x18, 0x21, 0x99, 0x05, 0x92, 0x40, 0x18, 0x00, 0x21, 0x0D, 0x90, + 0x41, 0x5E, 0x0E, 0x91, 0x20, 0x88, 0x12, 0x99, 0x80, 0x04, 0x80, 0x0C, + 0x49, 0xB2, 0x0F, 0x90, 0x08, 0xAB, 0x1F, 0x91, 0x19, 0x70, 0x12, 0x99, + 0x01, 0x22, 0x49, 0x42, 0x49, 0xB2, 0x1E, 0x91, 0x59, 0x70, 0x9A, 0x70, + 0xFF, 0x21, 0xD9, 0x70, 0x12, 0x99, 0x49, 0x1E, 0x19, 0x71, 0x12, 0x9B, + 0xDF, 0x43, 0x08, 0xAB, 0x5F, 0x71, 0x12, 0x9F, 0x7F, 0x1C, 0x9F, 0x71, + 0x12, 0x9B, 0xD2, 0x1A, 0x08, 0xAB, 0xDA, 0x71, 0x00, 0x2D, 0x04, 0xD1, + 0x7F, 0x22, 0x5A, 0x70, 0x5A, 0x71, 0xDA, 0x71, 0x08, 0xE0, 0x11, 0x9A, + 0x52, 0x1E, 0x95, 0x42, 0x04, 0xD1, 0x7F, 0x22, 0x08, 0xAB, 0x1A, 0x70, + 0x1A, 0x71, 0x9A, 0x71, 0x00, 0x2E, 0x05, 0xD1, 0x7F, 0x21, 0x08, 0xAB, + 0xD9, 0x70, 0x19, 0x71, 0x59, 0x71, 0x06, 0xE0, 0x8E, 0x42, 0x04, 0xD1, + 0x7F, 0x21, 0x08, 0xAB, 0x99, 0x70, 0x99, 0x71, 0xD9, 0x71, 0x1B, 0x99, + 0x00, 0x29, 0x3D, 0xD0, 0xC6, 0x49, 0x00, 0x27, 0x09, 0x78, 0x00, 0x29, + 0x06, 0xD0, 0x01, 0x21, 0x89, 0x03, 0x40, 0x18, 0x80, 0xB2, 0x80, 0x0B, + 0x80, 0x03, 0x20, 0x80, 0x00, 0x20, 0x08, 0xA9, 0x09, 0x56, 0x7F, 0x29, + 0x27, 0xD0, 0x49, 0x00, 0x0A, 0x19, 0x94, 0x46, 0x12, 0x88, 0x92, 0x0B, + 0x02, 0x2A, 0x20, 0xD0, 0x0D, 0x9A, 0x51, 0x5E, 0xB9, 0x4A, 0x52, 0x68, + 0xD2, 0x78, 0x8A, 0x42, 0x19, 0xDD, 0x04, 0x29, 0x0E, 0xDD, 0x06, 0xAA, + 0x12, 0x5C, 0x15, 0xAB, 0x52, 0x19, 0xDA, 0x55, 0x04, 0xAA, 0x12, 0x5C, + 0x13, 0xAB, 0x92, 0x19, 0xDA, 0x55, 0x7A, 0x00, 0x17, 0xAB, 0x7F, 0x1C, + 0x99, 0x52, 0xFF, 0xB2, 0x61, 0x46, 0x09, 0x88, 0x01, 0x22, 0x89, 0x04, + 0x89, 0x0C, 0xD2, 0x03, 0x89, 0x18, 0x62, 0x46, 0x11, 0x80, 0x40, 0x1C, + 0xC0, 0xB2, 0x08, 0x28, 0xCF, 0xD3, 0xFA, 0xE0, 0x00, 0x27, 0x0C, 0x97, + 0x0C, 0x99, 0x08, 0xA8, 0x40, 0x56, 0x7F, 0x28, 0x4E, 0xD0, 0x40, 0x00, + 0x01, 0x19, 0x10, 0x91, 0x0D, 0x99, 0x0A, 0x5E, 0x20, 0x88, 0x1D, 0x90, + 0x81, 0x0B, 0x03, 0x29, 0x7A, 0xD0, 0x10, 0x98, 0x00, 0x88, 0x83, 0x0B, + 0x01, 0x2B, 0x75, 0xD1, 0x1D, 0x9B, 0x9B, 0x0B, 0x3D, 0xD1, 0x9B, 0x49, + 0x4B, 0x68, 0xD9, 0x7A, 0x49, 0x09, 0x28, 0xD1, 0x0C, 0x99, 0x04, 0x29, + 0x25, 0xD3, 0x0E, 0x99, 0x91, 0x42, 0x00, 0xDB, 0x11, 0x46, 0x1A, 0x79, + 0x04, 0x23, 0x93, 0x40, 0x1A, 0xB2, 0x03, 0x92, 0x0C, 0x9A, 0xD2, 0x07, + 0x01, 0xD0, 0x1E, 0x9A, 0x00, 0xE0, 0x1F, 0x9A, 0x0C, 0x9B, 0x06, 0x2B, + 0x02, 0xD2, 0x00, 0x23, 0xDB, 0x43, 0x00, 0xE0, 0x01, 0x23, 0x9C, 0x46, + 0x0D, 0x9B, 0x52, 0x00, 0x9A, 0x5E, 0x03, 0x9B, 0x8A, 0x1A, 0x9A, 0x42, + 0x07, 0xDB, 0x62, 0x46, 0x0D, 0x9B, 0x52, 0x00, 0x9A, 0x5E, 0x89, 0x1A, + 0x03, 0x9A, 0x91, 0x42, 0x0E, 0xDA, 0xC0, 0xB2, 0x0B, 0x90, 0x1D, 0x98, + 0x01, 0x21, 0x80, 0x04, 0x80, 0x0C, 0x89, 0x03, 0x40, 0x18, 0x20, 0x80, + 0x80, 0xB2, 0x81, 0x0B, 0x0B, 0x98, 0x89, 0x03, 0x01, 0x43, 0x21, 0x80, + 0x9C, 0xE0, 0x01, 0x29, 0xFC, 0xD1, 0x1D, 0x99, 0x82, 0x04, 0x89, 0x04, + 0x89, 0x0C, 0x92, 0x0C, 0x91, 0x42, 0xF5, 0xD0, 0x0C, 0x99, 0x04, 0x29, + 0xF2, 0xD2, 0xC1, 0xB2, 0x0A, 0x91, 0x0B, 0x98, 0x75, 0x4A, 0x14, 0x21, + 0x48, 0x43, 0x3C, 0x32, 0x80, 0x18, 0x00, 0x7C, 0x14, 0x23, 0x01, 0x09, + 0x00, 0x07, 0x00, 0x0F, 0x71, 0x1A, 0x28, 0x1A, 0x49, 0x43, 0x40, 0x43, + 0x08, 0x18, 0x0A, 0x99, 0x00, 0xB2, 0x59, 0x43, 0x89, 0x18, 0x0A, 0x7C, + 0x11, 0x09, 0x12, 0x07, 0x12, 0x0F, 0x71, 0x1A, 0xAA, 0x1A, 0x49, 0x43, + 0x52, 0x43, 0x89, 0x18, 0x09, 0xB2, 0x88, 0x42, 0x07, 0xDA, 0x03, 0x22, + 0x00, 0x92, 0xF3, 0xB2, 0xEA, 0xB2, 0x0E, 0x99, 0x0B, 0x98, 0x18, 0xE0, + 0x40, 0xE0, 0x88, 0x42, 0x05, 0xDD, 0x03, 0x22, 0x00, 0x92, 0xF3, 0xB2, + 0xEA, 0xB2, 0x0E, 0x99, 0x0E, 0xE0, 0x0E, 0x98, 0x03, 0x22, 0x00, 0x92, + 0x41, 0x10, 0xF3, 0xB2, 0xEA, 0xB2, 0x0B, 0x98, 0xFE, 0xF7, 0xC4, 0xFD, + 0x03, 0x22, 0x0E, 0x98, 0x00, 0x92, 0xF3, 0xB2, 0xEA, 0xB2, 0x41, 0x10, + 0x0A, 0x98, 0xFE, 0xF7, 0xBB, 0xFD, 0x10, 0x98, 0xE9, 0xB2, 0x00, 0x88, + 0xC2, 0xB2, 0x00, 0x92, 0x20, 0x88, 0xF2, 0xB2, 0xC3, 0xB2, 0x21, 0x98, + 0xFE, 0xF7, 0x08, 0xFE, 0x00, 0x28, 0x53, 0xDB, 0x20, 0x88, 0x03, 0x21, + 0x89, 0x03, 0x08, 0x43, 0x20, 0x80, 0x0A, 0x99, 0x0B, 0x98, 0x88, 0x42, + 0x20, 0x88, 0x05, 0xD2, 0x80, 0x0B, 0x0B, 0x99, 0x80, 0x03, 0xC9, 0x01, + 0x0A, 0x9A, 0x03, 0xE0, 0x80, 0x0B, 0x80, 0x03, 0x0B, 0x9A, 0xC9, 0x01, + 0x11, 0x43, 0x89, 0x04, 0x89, 0x0C, 0x08, 0x43, 0x20, 0x80, 0x25, 0xE0, + 0x10, 0x98, 0x00, 0x88, 0x80, 0x0B, 0x02, 0x28, 0x20, 0xD0, 0x3E, 0x48, + 0x40, 0x68, 0xC0, 0x78, 0x90, 0x42, 0x1B, 0xDD, 0x04, 0x2A, 0x10, 0xDD, + 0x0C, 0x99, 0x06, 0xA8, 0x40, 0x5C, 0x15, 0xA9, 0x40, 0x19, 0xC8, 0x55, + 0x0C, 0x99, 0x04, 0xA8, 0x40, 0x5C, 0x13, 0xA9, 0x80, 0x19, 0xC8, 0x55, + 0x78, 0x00, 0x17, 0xA9, 0x7F, 0x1C, 0x0A, 0x52, 0xFF, 0xB2, 0x10, 0x98, + 0x01, 0x21, 0x00, 0x88, 0xC9, 0x03, 0x80, 0x04, 0x80, 0x0C, 0x40, 0x18, + 0x10, 0x99, 0x08, 0x80, 0x0C, 0x98, 0x40, 0x1C, 0xC0, 0xB2, 0x0C, 0x90, + 0x08, 0x28, 0x00, 0xD2, 0x06, 0xE7, 0x20, 0x88, 0x81, 0x0B, 0x68, 0xD1, + 0x28, 0x4A, 0x0A, 0x20, 0x51, 0x68, 0x89, 0x79, 0x0A, 0x29, 0x00, 0xD2, + 0x08, 0x46, 0x11, 0x78, 0x88, 0x42, 0x03, 0xD8, 0x00, 0x20, 0xC0, 0x43, + 0x23, 0xB0, 0xF0, 0xBD, 0x14, 0x20, 0x0B, 0x91, 0x41, 0x43, 0x21, 0x48, + 0x2A, 0x07, 0x3C, 0x30, 0x08, 0x18, 0x41, 0x7C, 0x12, 0x0E, 0x09, 0x07, + 0x09, 0x0F, 0x11, 0x43, 0x0A, 0x09, 0xC9, 0xB2, 0x09, 0x09, 0x09, 0x01, + 0x11, 0x43, 0x41, 0x74, 0x02, 0x7C, 0x09, 0x07, 0x12, 0x09, 0x09, 0x0F, + 0x12, 0x01, 0x0A, 0x43, 0x02, 0x74, 0x81, 0x7C, 0x32, 0x07, 0x09, 0x07, + 0x09, 0x0F, 0x12, 0x0E, 0x11, 0x43, 0x0A, 0x09, 0xC9, 0xB2, 0x09, 0x09, + 0x09, 0x01, 0x11, 0x43, 0x81, 0x74, 0x02, 0x7C, 0x09, 0x01, 0x12, 0x07, + 0x12, 0x0F, 0x0A, 0x43, 0x02, 0x74, 0x00, 0x21, 0x01, 0x60, 0x41, 0x60, + 0x81, 0x60, 0x01, 0x21, 0xC1, 0x81, 0x0E, 0x99, 0x81, 0x81, 0x20, 0x88, + 0x01, 0x21, 0x80, 0x04, 0x80, 0x0C, 0x89, 0x03, 0x40, 0x18, 0x20, 0x80, + 0x80, 0xB2, 0x80, 0x0B, 0x0B, 0x99, 0x80, 0x03, 0x08, 0x43, 0x20, 0x80, + 0x01, 0x22, 0xF3, 0xB2, 0x00, 0x92, 0x0B, 0xE0, 0x2C, 0x00, 0x00, 0x20, + 0x88, 0x08, 0x00, 0x20, 0x01, 0xFF, 0x00, 0x00, 0x01, 0xFF, 0x01, 0xFF, + 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0xEA, 0xB2, 0x0E, 0x99, + 0x0B, 0x98, 0xFE, 0xF7, 0x01, 0xFD, 0x39, 0x48, 0x38, 0x49, 0x00, 0x78, + 0x40, 0x1C, 0x08, 0x70, 0x2E, 0xE0, 0x80, 0x0B, 0x01, 0x28, 0x2B, 0xD1, + 0x0B, 0x98, 0x14, 0x21, 0x48, 0x43, 0x34, 0x49, 0x40, 0x18, 0x0C, 0x21, + 0x03, 0x90, 0x41, 0x5E, 0x0E, 0x98, 0x81, 0x42, 0x13, 0xDA, 0x03, 0x98, + 0x29, 0x07, 0x00, 0x7C, 0x09, 0x0F, 0x00, 0x09, 0x00, 0x01, 0x08, 0x43, + 0x03, 0x99, 0x08, 0x74, 0x03, 0x98, 0x00, 0x7C, 0x01, 0x07, 0x09, 0x0F, + 0x30, 0x01, 0x01, 0x43, 0x03, 0x98, 0x01, 0x74, 0x03, 0x99, 0x0E, 0x98, + 0x88, 0x81, 0x01, 0x22, 0x00, 0x92, 0xF3, 0xB2, 0xEA, 0xB2, 0x0E, 0x99, + 0x0B, 0x98, 0xFE, 0xF7, 0xD1, 0xFC, 0x03, 0x98, 0x03, 0x99, 0xC0, 0x89, + 0x40, 0x1C, 0xC8, 0x81, 0x00, 0x25, 0x2A, 0xE0, 0x15, 0xA8, 0x40, 0x57, + 0x03, 0x90, 0x13, 0xA8, 0x46, 0x57, 0x68, 0x00, 0x17, 0xA9, 0x09, 0x5E, + 0x20, 0x88, 0x80, 0x0B, 0x03, 0x28, 0x12, 0xD1, 0x48, 0x10, 0x02, 0x90, + 0x02, 0x22, 0x03, 0x98, 0x00, 0x92, 0xC2, 0xB2, 0xF3, 0xB2, 0x02, 0x99, + 0x0B, 0x98, 0xFE, 0xF7, 0xB3, 0xFC, 0x02, 0x22, 0x03, 0x98, 0x00, 0x92, + 0xC2, 0xB2, 0xF3, 0xB2, 0x02, 0x99, 0x0A, 0x98, 0x07, 0xE0, 0x01, 0x28, + 0x07, 0xD1, 0x02, 0x22, 0x03, 0x98, 0x00, 0x92, 0xC2, 0xB2, 0xF3, 0xB2, + 0x0B, 0x98, 0xFE, 0xF7, 0xA1, 0xFC, 0x6D, 0x1C, 0xED, 0xB2, 0xBD, 0x42, + 0xD2, 0xD3, 0x0F, 0x98, 0x08, 0x49, 0x88, 0x42, 0x00, 0xD0, 0x9A, 0xE5, + 0x1C, 0x98, 0x40, 0x1E, 0x40, 0xB2, 0x1C, 0x90, 0x00, 0x28, 0x00, 0xDB, + 0x8F, 0xE5, 0x00, 0x20, 0x36, 0xE7, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, + 0xC4, 0x08, 0x00, 0x20, 0xFF, 0x3F, 0x00, 0x00, 0x06, 0x4A, 0x10, 0xB5, + 0x80, 0x32, 0xD3, 0x6B, 0x04, 0x49, 0xDA, 0x78, 0x1B, 0x79, 0x48, 0x6D, + 0x09, 0x6D, 0x5A, 0x43, 0x01, 0xF0, 0xA0, 0xF9, 0x10, 0xBD, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x20, 0xFF, 0xB5, 0x81, 0xB0, 0x20, 0x4D, 0x00, 0x90, + 0x0B, 0x9E, 0x0D, 0x9C, 0x00, 0x20, 0x6B, 0x60, 0x17, 0x46, 0x20, 0x70, + 0x01, 0xF0, 0x52, 0xFA, 0x3A, 0x46, 0x02, 0x99, 0x00, 0x98, 0x02, 0xF0, + 0x05, 0xFC, 0x02, 0x46, 0x02, 0x99, 0x00, 0x98, 0xFF, 0xF7, 0x4C, 0xFD, + 0x00, 0x28, 0x01, 0xDA, 0x01, 0x20, 0x18, 0xE0, 0x28, 0x78, 0x00, 0x28, + 0x01, 0xD1, 0x02, 0x20, 0x13, 0xE0, 0x68, 0x68, 0xC0, 0x7A, 0x41, 0x09, + 0x04, 0xD1, 0x80, 0x07, 0x02, 0xD5, 0x02, 0x98, 0xFE, 0xF7, 0xFE, 0xFE, + 0x68, 0x68, 0xC0, 0x7A, 0xC0, 0x07, 0x0A, 0xD0, 0x02, 0x99, 0x00, 0x98, + 0x01, 0xF0, 0x7A, 0xFC, 0x00, 0x28, 0x04, 0xD0, 0x03, 0x20, 0x20, 0x70, + 0x00, 0x20, 0x05, 0xB0, 0xF0, 0xBD, 0x33, 0x46, 0x0A, 0x9A, 0x02, 0x99, + 0x00, 0x98, 0x01, 0xF0, 0x91, 0xFD, 0x02, 0x98, 0x01, 0xF0, 0xF6, 0xFF, + 0x0C, 0x98, 0xFF, 0xF7, 0xEB, 0xF8, 0xF0, 0xE7, 0x2C, 0x00, 0x00, 0x20, + 0xFF, 0xB5, 0x07, 0x46, 0xD3, 0xB0, 0x00, 0x26, 0x2A, 0x48, 0x52, 0x96, + 0x02, 0x60, 0x10, 0x78, 0x0A, 0x25, 0x0C, 0x46, 0x0A, 0x28, 0x00, 0xD2, + 0x05, 0x46, 0x00, 0x20, 0xFF, 0x21, 0x4F, 0xAA, 0x02, 0xE0, 0x11, 0x54, + 0x40, 0x1C, 0xC0, 0xB2, 0xA0, 0x42, 0xFA, 0xD3, 0x00, 0x20, 0x4C, 0xAA, + 0x02, 0xE0, 0x11, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0xA8, 0x42, 0xFA, 0xD3, + 0x52, 0xAA, 0x4C, 0xA8, 0x01, 0x95, 0x02, 0x92, 0x00, 0x90, 0x23, 0x46, + 0x3A, 0x46, 0x04, 0xA8, 0x56, 0x99, 0xFE, 0xF7, 0x7F, 0xFD, 0x50, 0xAB, + 0x1B, 0x7A, 0x00, 0x2B, 0x16, 0xD0, 0x00, 0x2C, 0x14, 0xD0, 0x01, 0x2B, + 0x09, 0xD1, 0x01, 0x2C, 0x07, 0xD1, 0x6B, 0x46, 0x18, 0x8A, 0x13, 0x49, + 0x88, 0x42, 0x0B, 0xD0, 0x48, 0xAB, 0x1E, 0x77, 0x08, 0xE0, 0x00, 0x22, + 0xD2, 0x43, 0x01, 0x92, 0xC2, 0xB2, 0x00, 0x94, 0x4F, 0xA9, 0x04, 0xA8, + 0x00, 0xF0, 0x1A, 0xF8, 0x4F, 0xA9, 0x01, 0x95, 0x00, 0x91, 0x22, 0x46, + 0x39, 0x46, 0x4C, 0xAB, 0x56, 0x98, 0x05, 0xF0, 0xA1, 0xF8, 0x56, 0x98, + 0x00, 0xF0, 0x08, 0xFB, 0x29, 0x46, 0x56, 0x98, 0x04, 0xF0, 0x2C, 0xFA, + 0x29, 0x46, 0x56, 0x98, 0x02, 0xF0, 0x7E, 0xFD, 0x57, 0xB0, 0xF0, 0xBD, + 0x34, 0x00, 0x00, 0x20, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xB5, 0x04, 0x46, + 0x0E, 0x46, 0x00, 0x20, 0x11, 0x46, 0x9A, 0xB0, 0x51, 0x43, 0x15, 0x46, + 0x1A, 0x4B, 0x8C, 0x46, 0x23, 0x9F, 0x04, 0xE0, 0x41, 0x00, 0x62, 0x5A, + 0x9A, 0x1A, 0x62, 0x52, 0x40, 0x1C, 0x84, 0x45, 0xF8, 0xDC, 0x16, 0x48, + 0x02, 0xAA, 0x05, 0x70, 0x44, 0x60, 0x07, 0xA9, 0x01, 0x92, 0x00, 0x91, + 0x11, 0xAA, 0x14, 0xA9, 0x17, 0xA8, 0x0C, 0xAB, 0x04, 0xF0, 0xDE, 0xFC, + 0x00, 0x20, 0xFF, 0x21, 0x01, 0xE0, 0x31, 0x54, 0x40, 0x1C, 0xB8, 0x42, + 0xFB, 0xDB, 0x00, 0x20, 0x17, 0xAB, 0x0E, 0xE0, 0x19, 0x56, 0x00, 0x29, + 0x0A, 0xDB, 0x1D, 0x9A, 0x91, 0x42, 0x07, 0xDA, 0x69, 0x43, 0x09, 0x18, + 0x49, 0x00, 0x61, 0x5A, 0x00, 0x29, 0x01, 0xD0, 0x19, 0x5C, 0x31, 0x54, + 0x40, 0x1C, 0xB8, 0x42, 0xEE, 0xDB, 0x1E, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xFF, 0x7F, 0x00, 0x00, 0x38, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x91, 0xB0, + 0x0A, 0x91, 0x6B, 0x49, 0x17, 0x9D, 0xC9, 0x6B, 0x16, 0x9C, 0x89, 0x7B, + 0x17, 0x46, 0x00, 0x29, 0x7E, 0xD0, 0x0A, 0x9A, 0x1E, 0x46, 0x7A, 0x43, + 0x0B, 0x90, 0x19, 0x46, 0x0F, 0x92, 0x01, 0xF0, 0xA3, 0xF8, 0x00, 0x20, + 0x0A, 0xE0, 0x41, 0x00, 0x6A, 0x5E, 0x02, 0x2A, 0x01, 0xDA, 0x02, 0x22, + 0x00, 0xE0, 0x6A, 0x5A, 0x05, 0xAB, 0x40, 0x1C, 0x5A, 0x52, 0xC0, 0xB2, + 0x0A, 0x99, 0x88, 0x42, 0xF1, 0xD3, 0x00, 0x20, 0x02, 0x22, 0x0B, 0xE0, + 0x41, 0x00, 0x63, 0x5E, 0x02, 0x2B, 0x02, 0xDA, 0x6B, 0x46, 0x5A, 0x52, + 0x02, 0xE0, 0x63, 0x5A, 0x6D, 0x46, 0x6B, 0x52, 0x40, 0x1C, 0xC0, 0xB2, + 0xB8, 0x42, 0xF1, 0xD3, 0x00, 0x25, 0x97, 0xE0, 0x18, 0x98, 0x32, 0x28, + 0x04, 0xD2, 0x69, 0x00, 0x05, 0xA8, 0x40, 0x5A, 0x14, 0x28, 0x7D, 0xD9, + 0x28, 0x46, 0x78, 0x43, 0x00, 0xB2, 0x00, 0x24, 0x09, 0x90, 0x84, 0xE0, + 0x00, 0x20, 0x18, 0x9A, 0x01, 0x46, 0x84, 0x46, 0x0D, 0x90, 0x32, 0x2A, + 0x0A, 0xD2, 0x63, 0x00, 0x6A, 0x46, 0xD2, 0x5A, 0x14, 0x2A, 0x76, 0xD9, + 0x09, 0x9A, 0x12, 0x19, 0x52, 0x00, 0xB2, 0x5E, 0x1E, 0x2A, 0x70, 0xDB, + 0x01, 0x2D, 0x09, 0xD4, 0x09, 0x98, 0x6A, 0x00, 0xC0, 0x1B, 0x00, 0x19, + 0x40, 0x00, 0x05, 0xA9, 0x51, 0x18, 0x40, 0x39, 0x30, 0x5E, 0xC9, 0x8F, + 0x09, 0x9A, 0x6B, 0x00, 0x12, 0x19, 0x52, 0x00, 0x0C, 0x92, 0xB2, 0x5E, + 0x10, 0x92, 0x10, 0x18, 0x05, 0xAA, 0xD2, 0x5A, 0x0E, 0x92, 0x51, 0x18, + 0x8E, 0x46, 0x0A, 0x9A, 0x69, 0x1C, 0x91, 0x42, 0x0B, 0xD2, 0x09, 0x99, + 0xC9, 0x19, 0x09, 0x19, 0x49, 0x00, 0x71, 0x5E, 0x08, 0x18, 0x05, 0xA9, + 0x59, 0x18, 0x4A, 0x88, 0x71, 0x46, 0x51, 0x18, 0x8E, 0x46, 0x01, 0x2C, + 0x0D, 0xD4, 0x0C, 0x99, 0x8A, 0x19, 0x40, 0x3A, 0x3E, 0x21, 0x51, 0x5E, + 0x0D, 0x91, 0x62, 0x00, 0x69, 0x46, 0x00, 0xE0, 0x4B, 0xE0, 0x51, 0x18, + 0x40, 0x39, 0xC9, 0x8F, 0x8C, 0x46, 0x0D, 0x9A, 0x10, 0x99, 0x6B, 0x46, + 0x89, 0x18, 0x62, 0x00, 0x0D, 0x92, 0x9A, 0x5A, 0x10, 0x92, 0x94, 0x44, + 0x62, 0x1C, 0xBA, 0x42, 0x09, 0xD2, 0x0C, 0x9A, 0x02, 0x23, 0x92, 0x19, + 0xD3, 0x5E, 0x0D, 0x9A, 0x59, 0x18, 0x6B, 0x46, 0xD2, 0x18, 0x52, 0x88, + 0x94, 0x44, 0x00, 0x28, 0x00, 0xDA, 0x00, 0x20, 0x00, 0x29, 0x00, 0xDA, + 0x00, 0x21, 0x62, 0x46, 0x93, 0x08, 0x72, 0x46, 0x92, 0x08, 0x94, 0x46, + 0x0D, 0x93, 0x0D, 0x9A, 0x0E, 0x9B, 0x50, 0x43, 0x43, 0x43, 0x62, 0x46, + 0x10, 0x98, 0x51, 0x43, 0x48, 0x43, 0x18, 0x18, 0x40, 0x08, 0x01, 0xE0, + 0x0E, 0xE0, 0x08, 0xE0, 0x0D, 0x9B, 0x5A, 0x43, 0x91, 0x00, 0xFE, 0xF7, + 0x7C, 0xF9, 0x0C, 0x9A, 0x0B, 0x99, 0x40, 0x1C, 0x88, 0x52, 0x64, 0x1C, + 0xE4, 0xB2, 0xBC, 0x42, 0x00, 0xD2, 0x77, 0xE7, 0x6D, 0x1C, 0xED, 0xB2, + 0x0A, 0x98, 0x85, 0x42, 0x00, 0xD2, 0x63, 0xE7, 0x30, 0x46, 0x0F, 0x9A, + 0x0B, 0x99, 0x00, 0xF0, 0xDF, 0xFF, 0x11, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0x10, 0xB5, 0x0A, 0x48, 0x81, 0x78, 0x0A, 0x48, + 0x00, 0x29, 0x81, 0x88, 0x08, 0xD0, 0xFF, 0x22, 0x12, 0x01, 0x11, 0x43, + 0x81, 0x80, 0x05, 0x48, 0x01, 0x21, 0x40, 0x38, 0x01, 0x70, 0x10, 0xBD, + 0x11, 0x22, 0x11, 0x43, 0x81, 0x80, 0x02, 0xF0, 0x6D, 0xFE, 0x10, 0xBD, + 0x60, 0x01, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, 0xF7, 0xB5, 0x06, 0x46, + 0x1A, 0x48, 0x82, 0xB0, 0xC1, 0x8A, 0x00, 0x91, 0xFF, 0x21, 0xC1, 0x82, + 0x18, 0x48, 0x01, 0x90, 0x1D, 0xE0, 0x04, 0x98, 0x80, 0x47, 0x30, 0x70, + 0x00, 0x0A, 0x16, 0x4D, 0x70, 0x70, 0x28, 0x7C, 0x13, 0x4C, 0x01, 0x27, + 0x60, 0x34, 0xE1, 0x6B, 0x4A, 0x7C, 0x39, 0x46, 0x91, 0x40, 0x88, 0x43, + 0x28, 0x74, 0x28, 0x21, 0x03, 0x98, 0x00, 0xF0, 0x2D, 0xF8, 0x28, 0x7C, + 0xE1, 0x6B, 0x49, 0x7C, 0x8F, 0x40, 0x38, 0x43, 0x28, 0x74, 0x0C, 0x49, + 0xA0, 0x20, 0x88, 0x80, 0x01, 0x98, 0x40, 0x7D, 0x0A, 0x28, 0x05, 0xD1, + 0x06, 0x48, 0xA0, 0x30, 0x40, 0x68, 0x80, 0x78, 0x0A, 0x28, 0xD8, 0xD0, + 0x02, 0x49, 0x00, 0x98, 0xC8, 0x82, 0x05, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x40, 0x60, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x40, + 0x00, 0x02, 0x00, 0x40, 0x04, 0x48, 0x02, 0x69, 0x04, 0x21, 0x0A, 0x43, + 0x02, 0x61, 0x30, 0xBF, 0x02, 0x69, 0x8A, 0x43, 0x02, 0x61, 0x70, 0x47, + 0x00, 0xED, 0x00, 0xE0, 0x1C, 0xB5, 0x00, 0x23, 0x6A, 0x46, 0x13, 0x80, + 0x0D, 0xE0, 0x6A, 0x46, 0x93, 0x80, 0x02, 0xE0, 0xA2, 0x88, 0x52, 0x1C, + 0xA2, 0x80, 0x6A, 0x46, 0x92, 0x88, 0x6C, 0x46, 0x8A, 0x42, 0xF7, 0xD3, + 0x22, 0x88, 0x52, 0x1C, 0x22, 0x80, 0x6A, 0x46, 0x12, 0x88, 0x82, 0x42, + 0xED, 0xD3, 0x1C, 0xBD, 0xF0, 0xB5, 0x2E, 0x4D, 0xFF, 0x27, 0x68, 0x7A, + 0x2D, 0x4C, 0x85, 0xB0, 0x01, 0x28, 0x0E, 0xD0, 0xFF, 0xF7, 0x0E, 0xFB, + 0xE0, 0x79, 0xFF, 0x28, 0x05, 0xD0, 0x00, 0x28, 0x49, 0xD0, 0x40, 0x1E, + 0x38, 0x40, 0xE0, 0x71, 0x45, 0xD0, 0x68, 0x7A, 0x00, 0x28, 0x45, 0xD0, + 0x3D, 0xE0, 0x23, 0x4B, 0x01, 0x22, 0x00, 0x20, 0x80, 0x33, 0xDD, 0x6B, + 0x59, 0x69, 0xEE, 0x7A, 0x0A, 0xE0, 0x28, 0x23, 0x43, 0x43, 0xCB, 0x5C, + 0x00, 0x2B, 0x03, 0xD0, 0x28, 0x22, 0x42, 0x43, 0x8A, 0x5C, 0x03, 0xE0, + 0x40, 0x1C, 0xC0, 0xB2, 0x86, 0x42, 0xF2, 0xD8, 0x01, 0x2A, 0x06, 0xD0, + 0x02, 0x2A, 0x04, 0xD0, 0x00, 0xF0, 0xA8, 0xFC, 0xF1, 0x28, 0x15, 0xD0, + 0x21, 0xE0, 0x00, 0x22, 0x00, 0x92, 0x01, 0x92, 0x02, 0x92, 0x28, 0x22, + 0x50, 0x43, 0x1C, 0x30, 0x08, 0x18, 0x01, 0x88, 0x6A, 0x46, 0x91, 0x81, + 0x40, 0x88, 0xD0, 0x81, 0x40, 0x35, 0x6B, 0x89, 0x2A, 0x89, 0x14, 0x21, + 0x03, 0x98, 0x04, 0xF0, 0xB7, 0xFD, 0x0A, 0xE0, 0xE1, 0x79, 0xFF, 0x29, + 0x05, 0xD0, 0x00, 0x29, 0x07, 0xD0, 0xE7, 0x71, 0xF1, 0x20, 0x05, 0xB0, + 0xF0, 0xBD, 0x0A, 0x20, 0xE0, 0x71, 0x00, 0x20, 0xF9, 0xE7, 0xE7, 0x71, + 0xF7, 0xE7, 0xE7, 0x71, 0xF0, 0x20, 0xF4, 0xE7, 0xFF, 0x20, 0xF2, 0xE7, + 0x40, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00, 0x20, 0xF0, 0xB5, 0x29, 0x4E, + 0x30, 0x46, 0x80, 0x30, 0xC0, 0x6B, 0xB5, 0x69, 0x84, 0x46, 0x81, 0x7B, + 0x30, 0x46, 0xF4, 0x69, 0x33, 0x6A, 0x72, 0x69, 0x20, 0x30, 0x00, 0x29, + 0x02, 0xD0, 0x11, 0x46, 0x29, 0x43, 0x03, 0xD1, 0x00, 0x2C, 0x01, 0xD1, + 0x00, 0x2B, 0x02, 0xD0, 0x03, 0x21, 0x01, 0x71, 0x02, 0xE0, 0x01, 0x79, + 0x00, 0x29, 0x02, 0xD0, 0x01, 0x79, 0x49, 0x1E, 0x01, 0x71, 0x61, 0x46, + 0x89, 0x7B, 0x00, 0x29, 0x2F, 0xD0, 0x00, 0x21, 0x2F, 0x46, 0x1F, 0x42, + 0x15, 0xD1, 0x1A, 0x42, 0x01, 0xD0, 0x01, 0x21, 0x0B, 0xE0, 0x13, 0x46, + 0x23, 0x42, 0x01, 0xD0, 0x02, 0x21, 0x06, 0xE0, 0x00, 0x2A, 0x01, 0xD0, + 0x0F, 0x21, 0x02, 0xE0, 0x25, 0x42, 0x06, 0xD0, 0x04, 0x21, 0x82, 0x7D, + 0x01, 0x23, 0x8A, 0x42, 0x04, 0xD0, 0xF3, 0x84, 0x07, 0xE0, 0x00, 0x22, + 0xF2, 0x84, 0x11, 0xE0, 0xF2, 0x8C, 0x19, 0x24, 0x64, 0x01, 0xA2, 0x42, + 0x0C, 0xD2, 0xF2, 0x8C, 0x64, 0x46, 0x52, 0x1C, 0x92, 0xB2, 0xF2, 0x84, + 0x24, 0x7E, 0xA2, 0x42, 0x04, 0xD9, 0xC2, 0x7C, 0x1A, 0x43, 0xC2, 0x74, + 0x73, 0x70, 0xEA, 0xE7, 0x81, 0x75, 0xF0, 0xBD, 0x40, 0x00, 0x00, 0x20, + 0x10, 0xB5, 0x04, 0x48, 0xC0, 0x6B, 0x20, 0x30, 0x40, 0x7E, 0x00, 0x28, + 0x01, 0xD0, 0x02, 0xF0, 0x89, 0xF9, 0x10, 0xBD, 0xC0, 0x00, 0x00, 0x20, + 0x70, 0xB5, 0x85, 0x1A, 0x00, 0x2D, 0x00, 0xDC, 0x15, 0x1A, 0xC8, 0x1A, + 0x00, 0x28, 0x00, 0xDC, 0x58, 0x1A, 0x85, 0x42, 0x02, 0xDA, 0x45, 0x40, + 0x68, 0x40, 0x45, 0x40, 0x00, 0x2D, 0x1C, 0xD0, 0x01, 0x2D, 0x1C, 0xD0, + 0x06, 0x46, 0x46, 0x43, 0x29, 0x46, 0x30, 0x46, 0xFE, 0xF7, 0x13, 0xF8, + 0x40, 0x10, 0x44, 0x19, 0x6D, 0x43, 0xAE, 0x19, 0x25, 0x46, 0x29, 0x46, + 0x30, 0x46, 0xFE, 0xF7, 0x0A, 0xF8, 0x01, 0x19, 0x48, 0x10, 0xC9, 0x07, + 0xC9, 0x0F, 0x44, 0x18, 0x20, 0x46, 0x68, 0x40, 0xC0, 0x43, 0x01, 0x28, + 0xF0, 0xDC, 0xA0, 0xB2, 0x70, 0xBD, 0x00, 0x20, 0x70, 0xBD, 0x01, 0x20, + 0x70, 0xBD, 0x00, 0x00, 0x06, 0x4B, 0xD8, 0x80, 0x59, 0x81, 0x98, 0x88, + 0x10, 0x21, 0x08, 0x43, 0x98, 0x80, 0x5A, 0x80, 0x21, 0x20, 0x18, 0x80, + 0x98, 0x88, 0xC0, 0x06, 0xFC, 0xD5, 0x70, 0x47, 0x00, 0x11, 0x00, 0x40, + 0x10, 0xB5, 0x16, 0x48, 0x16, 0x4C, 0xC1, 0x6B, 0x11, 0x23, 0x88, 0x7A, + 0x63, 0x74, 0x20, 0x31, 0x4A, 0x7A, 0x12, 0x01, 0xD2, 0x1C, 0x22, 0x74, + 0x12, 0x4A, 0x02, 0x28, 0x04, 0xD9, 0x04, 0x01, 0x80, 0x1E, 0x04, 0x43, + 0x54, 0x72, 0x01, 0xE0, 0x20, 0x20, 0x50, 0x72, 0xC8, 0x7D, 0x89, 0x7D, + 0x80, 0x00, 0x09, 0x01, 0x08, 0x43, 0x41, 0x21, 0x08, 0x43, 0x10, 0x72, + 0x0A, 0x48, 0x83, 0x80, 0x01, 0x80, 0x00, 0x21, 0x01, 0x20, 0x03, 0xF0, + 0xE9, 0xFE, 0x02, 0x20, 0x04, 0xF0, 0x0A, 0xF8, 0x02, 0x48, 0x00, 0x21, + 0x60, 0x38, 0xC1, 0x75, 0x10, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, + 0xE0, 0x12, 0x00, 0x40, 0x00, 0x03, 0x00, 0x40, 0x00, 0x10, 0x00, 0x40, + 0x0D, 0x48, 0x01, 0x68, 0x0D, 0x48, 0x0A, 0x0E, 0x02, 0x70, 0x0A, 0x0C, + 0x42, 0x70, 0x0A, 0x0A, 0x82, 0x70, 0xC1, 0x70, 0x01, 0x78, 0x42, 0x78, + 0x89, 0x18, 0x82, 0x78, 0xC3, 0x78, 0xD2, 0x18, 0x89, 0x18, 0xA5, 0x31, + 0x0A, 0x0A, 0x02, 0x71, 0x41, 0x71, 0x05, 0x48, 0x81, 0x79, 0x02, 0x29, + 0x01, 0xD2, 0x02, 0x21, 0x81, 0x71, 0x70, 0x47, 0x28, 0x00, 0x00, 0x20, + 0x51, 0x07, 0x00, 0x20, 0x80, 0x01, 0x00, 0x20, 0xF1, 0xB5, 0x85, 0xB0, + 0x00, 0x27, 0x78, 0x1C, 0xC6, 0xB2, 0x04, 0x90, 0x32, 0xE0, 0x28, 0x20, + 0x05, 0x99, 0x78, 0x43, 0x44, 0x18, 0x60, 0x79, 0x01, 0x28, 0x29, 0xD9, + 0x28, 0x20, 0x70, 0x43, 0x45, 0x18, 0x68, 0x79, 0x01, 0x28, 0x23, 0xD9, + 0xA8, 0x89, 0x6B, 0x46, 0x98, 0x81, 0xE8, 0x89, 0xD8, 0x81, 0xA8, 0x8B, + 0x18, 0x81, 0xE8, 0x8B, 0x58, 0x81, 0xA0, 0x89, 0x98, 0x80, 0xE0, 0x89, + 0xD8, 0x80, 0xA0, 0x8B, 0x18, 0x80, 0xE0, 0x8B, 0x58, 0x80, 0x68, 0x46, + 0x0F, 0xC8, 0x01, 0xF0, 0x89, 0xFB, 0x00, 0x28, 0x0C, 0xD0, 0xA0, 0x89, + 0x6B, 0x46, 0x98, 0x81, 0xE0, 0x89, 0xD8, 0x81, 0xA8, 0x89, 0xA0, 0x81, + 0xE8, 0x89, 0xE0, 0x81, 0x98, 0x89, 0xA8, 0x81, 0xD8, 0x89, 0xE8, 0x81, + 0x76, 0x1C, 0xF6, 0xB2, 0x06, 0x2E, 0xCA, 0xD3, 0x04, 0x98, 0xC7, 0xB2, + 0x05, 0x2F, 0xC2, 0xD3, 0x06, 0xB0, 0xF0, 0xBD, 0xFF, 0xB5, 0x07, 0x46, + 0x3D, 0x48, 0x85, 0xB0, 0x81, 0x6A, 0x00, 0x91, 0x01, 0x46, 0x80, 0x39, + 0x09, 0x7A, 0x01, 0x29, 0x01, 0xD1, 0x40, 0x6B, 0x00, 0x90, 0x39, 0x49, + 0x00, 0x20, 0xC8, 0x81, 0x65, 0xE0, 0x00, 0x20, 0x01, 0x90, 0x03, 0x98, + 0x04, 0x25, 0x80, 0x00, 0x04, 0x90, 0x03, 0x98, 0x01, 0x24, 0x46, 0x00, + 0x00, 0x9A, 0x04, 0x99, 0x02, 0x94, 0x80, 0x20, 0x51, 0x58, 0x20, 0x43, + 0x20, 0x39, 0xC8, 0x77, 0x01, 0x22, 0x80, 0x21, 0x38, 0x46, 0x02, 0xF0, + 0xB9, 0xFD, 0xB8, 0x5F, 0x19, 0x21, 0x49, 0x01, 0x88, 0x42, 0x09, 0xDA, + 0xAC, 0x42, 0x13, 0xDD, 0x00, 0x2D, 0x00, 0xDD, 0x6D, 0x10, 0x00, 0x2D, + 0x0E, 0xD0, 0x60, 0x1B, 0xC4, 0xB2, 0xE3, 0xE7, 0x60, 0x19, 0xC4, 0xB2, + 0x0E, 0x98, 0x84, 0x42, 0xDE, 0xD3, 0x01, 0x98, 0x00, 0x28, 0x03, 0xD1, + 0x01, 0x20, 0x0E, 0x9C, 0x01, 0x90, 0xD7, 0xE7, 0x02, 0x99, 0x80, 0x20, + 0x01, 0x43, 0x00, 0x9A, 0x04, 0x98, 0x10, 0x58, 0x20, 0x38, 0xC1, 0x77, + 0x01, 0x22, 0x80, 0x21, 0x38, 0x46, 0x02, 0xF0, 0x91, 0xFD, 0xBC, 0x5F, + 0x01, 0x22, 0x80, 0x21, 0x38, 0x46, 0x02, 0xF0, 0x8B, 0xFD, 0xBD, 0x5F, + 0x01, 0x22, 0x80, 0x21, 0x38, 0x46, 0x02, 0xF0, 0x85, 0xFD, 0xA5, 0x42, + 0x02, 0xDD, 0x20, 0x46, 0x2C, 0x46, 0x05, 0x46, 0xB8, 0x5F, 0xA8, 0x42, + 0x01, 0xDC, 0xBD, 0x53, 0x02, 0xE0, 0xA0, 0x42, 0x00, 0xDB, 0xBC, 0x53, + 0x02, 0x98, 0x28, 0x21, 0x80, 0x06, 0x80, 0x0E, 0x48, 0x43, 0xB9, 0x5B, + 0x40, 0x18, 0x06, 0x99, 0x08, 0x80, 0x06, 0x98, 0x80, 0x1C, 0x06, 0x90, + 0x03, 0x98, 0x40, 0x1C, 0xC0, 0xB2, 0x07, 0x99, 0x03, 0x90, 0x88, 0x42, + 0x95, 0xD3, 0x09, 0xB0, 0xF0, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, + 0x00, 0x10, 0x00, 0x40, 0x14, 0x49, 0xCA, 0x6B, 0x40, 0x32, 0x12, 0x7B, + 0x02, 0x70, 0xCA, 0x6B, 0x20, 0x32, 0x52, 0x7A, 0x42, 0x70, 0xC9, 0x6B, + 0x89, 0x7A, 0x81, 0x70, 0x0F, 0x49, 0x8A, 0x7C, 0x92, 0x06, 0x92, 0x0E, + 0xC2, 0x70, 0x89, 0x7C, 0x00, 0x21, 0x01, 0x71, 0x0C, 0x49, 0xCA, 0x88, + 0x52, 0x05, 0x52, 0x0E, 0x42, 0x71, 0xCA, 0x88, 0x12, 0x07, 0x12, 0x0F, + 0x82, 0x71, 0xCA, 0x89, 0xC2, 0x71, 0x4A, 0x89, 0x52, 0x06, 0x52, 0x0E, + 0x02, 0x72, 0x0A, 0x89, 0x12, 0x0A, 0x42, 0x72, 0x09, 0x89, 0x81, 0x72, + 0x70, 0x47, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0xE0, 0x12, 0x00, 0x40, + 0x00, 0x10, 0x00, 0x40, 0x07, 0x49, 0x09, 0x7A, 0x01, 0x70, 0x06, 0x49, + 0x80, 0x39, 0x49, 0x7E, 0x41, 0x70, 0x04, 0x49, 0x60, 0x39, 0x09, 0x79, + 0x81, 0x70, 0x03, 0x49, 0x09, 0x78, 0xC1, 0x70, 0x70, 0x47, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x20, 0x40, 0x00, 0x00, 0x20, 0x10, 0xB5, 0x06, 0x48, + 0x05, 0x4B, 0xC0, 0x6B, 0x80, 0x3B, 0x82, 0x79, 0x40, 0x79, 0x59, 0x6D, + 0x42, 0x43, 0x98, 0x6C, 0x00, 0xF0, 0xEA, 0xFC, 0x10, 0xBD, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0xF8, 0xB5, 0x0E, 0x46, 0x07, 0x46, 0x00, 0x92, + 0x00, 0xF0, 0x58, 0xF9, 0x05, 0x1E, 0x00, 0xDC, 0x68, 0x42, 0x80, 0xB2, + 0x01, 0xF0, 0xAA, 0xFF, 0x04, 0x46, 0x00, 0x2D, 0x02, 0xDA, 0xB4, 0x20, + 0x00, 0x1B, 0x84, 0xB2, 0x31, 0x46, 0x38, 0x46, 0x00, 0x9A, 0x01, 0xF0, + 0xA7, 0xF8, 0x00, 0x28, 0x05, 0xD0, 0x00, 0x2C, 0x03, 0xD0, 0xFF, 0x20, + 0x69, 0x30, 0x00, 0x1B, 0x84, 0xB2, 0x20, 0x46, 0xF8, 0xBD, 0x00, 0x00, + 0xFF, 0xB5, 0x9E, 0x46, 0x8F, 0xB0, 0x6B, 0x46, 0x19, 0x70, 0x00, 0x23, + 0x70, 0x46, 0x03, 0x70, 0x14, 0x20, 0x41, 0x43, 0x37, 0x48, 0x01, 0x22, + 0x09, 0x18, 0x52, 0x1E, 0xD2, 0xB2, 0x68, 0x46, 0x80, 0x5C, 0x14, 0x23, + 0x84, 0x46, 0x58, 0x43, 0x32, 0x4B, 0xC3, 0x18, 0xD8, 0x7C, 0x04, 0x07, + 0x24, 0x0F, 0x02, 0x2C, 0x0D, 0xD0, 0x00, 0x09, 0x00, 0x01, 0x80, 0x1C, + 0xD8, 0x74, 0x73, 0x46, 0x1B, 0x78, 0x11, 0x9C, 0x60, 0x46, 0xE0, 0x54, + 0x70, 0x46, 0x00, 0x78, 0x73, 0x46, 0x40, 0x1C, 0x18, 0x70, 0x29, 0x48, + 0x00, 0x24, 0x40, 0x78, 0x0E, 0x90, 0x45, 0xE0, 0x0E, 0x20, 0x25, 0x46, + 0x45, 0x43, 0x24, 0x48, 0xC8, 0x30, 0x2F, 0x18, 0xB8, 0x7A, 0x03, 0x07, + 0x1B, 0x0F, 0x63, 0x45, 0x01, 0xD1, 0x03, 0x09, 0x02, 0xE0, 0x00, 0x09, + 0x60, 0x45, 0x32, 0xD1, 0x00, 0x2B, 0x30, 0xDB, 0x38, 0x7B, 0x01, 0x28, + 0x2D, 0xD1, 0x18, 0x46, 0x14, 0x26, 0x70, 0x43, 0x19, 0x4E, 0x80, 0x19, + 0xC6, 0x7C, 0x36, 0x07, 0x25, 0xD1, 0x17, 0x4F, 0xC6, 0x89, 0xC8, 0x37, + 0x7D, 0x5B, 0x75, 0x19, 0xC5, 0x81, 0x0C, 0x26, 0x0C, 0x25, 0x8E, 0x5F, + 0x45, 0x5F, 0xAE, 0x42, 0x10, 0xDA, 0x8D, 0x81, 0x0D, 0x7C, 0x06, 0x7C, + 0x2D, 0x07, 0x36, 0x09, 0x2D, 0x0F, 0x36, 0x01, 0x35, 0x43, 0x0D, 0x74, + 0xED, 0xB2, 0x06, 0x7C, 0x2D, 0x09, 0x2D, 0x01, 0x36, 0x07, 0x36, 0x0F, + 0x35, 0x43, 0x0D, 0x74, 0x6D, 0x46, 0xAB, 0x54, 0xC3, 0x7C, 0x52, 0x1C, + 0x1B, 0x09, 0x1B, 0x01, 0x5B, 0x1C, 0xD2, 0xB2, 0xC3, 0x74, 0x64, 0x1C, + 0x0E, 0x98, 0xE4, 0xB2, 0x84, 0x42, 0xB7, 0xD3, 0x00, 0x2A, 0x94, 0xD1, + 0x13, 0xB0, 0xF0, 0xBD, 0xC4, 0x08, 0x00, 0x20, 0x2C, 0x00, 0x00, 0x20, + 0xFF, 0xB5, 0x83, 0xB0, 0x06, 0x46, 0x01, 0x20, 0x05, 0x99, 0x0E, 0x9F, + 0x1D, 0x46, 0x88, 0x55, 0x00, 0x24, 0x2D, 0xE0, 0x28, 0x5D, 0x00, 0x28, + 0x29, 0xD1, 0x0C, 0x9A, 0x70, 0x00, 0x12, 0x5E, 0x0D, 0x9B, 0x60, 0x00, + 0x1B, 0x5E, 0x71, 0x43, 0xD2, 0x18, 0x14, 0x4B, 0x09, 0x19, 0x5B, 0x68, + 0x49, 0x00, 0x59, 0x5A, 0x51, 0x1A, 0x16, 0xD1, 0x01, 0x20, 0x28, 0x55, + 0x04, 0x98, 0x03, 0x57, 0x58, 0x1C, 0x0B, 0xD0, 0x0C, 0x98, 0x0D, 0x99, + 0x6A, 0x46, 0x83, 0xC2, 0x18, 0x46, 0x2B, 0x46, 0x05, 0x9A, 0x04, 0x99, + 0xFF, 0xF7, 0xD4, 0xFF, 0x00, 0x28, 0x08, 0xD0, 0x04, 0x98, 0x06, 0x55, + 0x01, 0x20, 0x07, 0xB0, 0xF0, 0xBD, 0x3A, 0x5E, 0x8A, 0x42, 0x00, 0xDD, + 0x39, 0x52, 0x64, 0x1C, 0x02, 0x48, 0x01, 0x78, 0x8C, 0x42, 0xCD, 0xDB, + 0x00, 0x20, 0xF2, 0xE7, 0x38, 0x00, 0x00, 0x20, 0xFF, 0xB5, 0xA3, 0xB0, + 0x2D, 0x99, 0x2C, 0x9E, 0x9B, 0x00, 0x90, 0x00, 0xB2, 0x00, 0x00, 0x93, + 0x89, 0x00, 0x01, 0xAB, 0x07, 0xC3, 0x2B, 0x4E, 0x00, 0x25, 0x70, 0x68, + 0x2C, 0x46, 0xC3, 0x7E, 0x1E, 0x22, 0x05, 0xA9, 0x14, 0xA8, 0x00, 0xF0, + 0x8F, 0xFB, 0x04, 0x90, 0x70, 0x68, 0x01, 0x7A, 0x04, 0x98, 0x81, 0x42, + 0x44, 0xD8, 0x6B, 0x46, 0x9A, 0x8A, 0x00, 0x92, 0x10, 0xAB, 0x1B, 0x8A, + 0x08, 0x22, 0x21, 0x49, 0x24, 0x98, 0x00, 0xF0, 0xC7, 0xF8, 0x07, 0x46, + 0x01, 0x26, 0x34, 0xE0, 0x70, 0x00, 0x05, 0xA9, 0x0A, 0x5A, 0x00, 0x92, + 0x14, 0xA9, 0x0B, 0x5A, 0x08, 0x22, 0x1A, 0x49, 0x24, 0x98, 0x00, 0xF0, + 0xB9, 0xF8, 0x00, 0x2C, 0x0B, 0xD0, 0x7D, 0x23, 0x2E, 0x9A, 0x7D, 0x21, + 0xDB, 0x00, 0xC9, 0x00, 0xD2, 0x18, 0x41, 0x43, 0x7A, 0x43, 0x91, 0x42, + 0x01, 0xD9, 0x6D, 0x1C, 0xED, 0xB2, 0x7D, 0x23, 0x2E, 0x9A, 0x7D, 0x21, + 0xDB, 0x00, 0xC9, 0x00, 0x9A, 0x1A, 0x41, 0x43, 0x7A, 0x43, 0x91, 0x42, + 0x01, 0xD2, 0x64, 0x1C, 0xE4, 0xB2, 0x0A, 0x49, 0x07, 0x46, 0x49, 0x68, + 0x28, 0x19, 0x09, 0x7A, 0x88, 0x42, 0x06, 0xD3, 0x01, 0x2D, 0x04, 0xD9, + 0x01, 0x2C, 0x02, 0xD9, 0x00, 0x20, 0x27, 0xB0, 0xF0, 0xBD, 0x76, 0x1C, + 0xF6, 0xB2, 0x04, 0x98, 0x86, 0x42, 0xC7, 0xD3, 0x01, 0x20, 0xF6, 0xE7, + 0x2C, 0x00, 0x00, 0x20, 0x10, 0x74, 0x00, 0x00, 0x10, 0xB5, 0x09, 0x49, + 0x00, 0x20, 0x49, 0x7C, 0x00, 0x29, 0x01, 0xD0, 0xFF, 0xF7, 0x3C, 0xFC, + 0x06, 0x49, 0x0A, 0x46, 0x08, 0x72, 0x40, 0x3A, 0x92, 0x7F, 0x05, 0x2A, + 0x02, 0xD9, 0x80, 0x22, 0x10, 0x43, 0x08, 0x72, 0x10, 0xBD, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00, 0x20, 0xF7, 0xB5, 0x84, 0xB0, + 0x6B, 0x46, 0x18, 0x8B, 0x5D, 0x8B, 0x03, 0x90, 0xDC, 0x8A, 0x9F, 0x8A, + 0x02, 0x46, 0x2B, 0x46, 0x21, 0x46, 0x38, 0x46, 0xFF, 0xF7, 0xE2, 0xFC, + 0x6B, 0x46, 0x01, 0x90, 0x5E, 0x8A, 0x18, 0x8A, 0x23, 0x46, 0x3A, 0x46, + 0x31, 0x46, 0x02, 0x90, 0xFF, 0xF7, 0xD8, 0xFC, 0x04, 0x46, 0x2B, 0x46, + 0x31, 0x46, 0x03, 0x9A, 0x02, 0x98, 0xFF, 0xF7, 0xD1, 0xFC, 0x00, 0x2C, + 0x01, 0xD0, 0x00, 0x28, 0x03, 0xD1, 0x00, 0x20, 0xC0, 0x43, 0x07, 0xB0, + 0xF0, 0xBD, 0x21, 0x46, 0x02, 0x46, 0x61, 0x43, 0x42, 0x43, 0x8A, 0x18, + 0x01, 0x99, 0x49, 0x43, 0x51, 0x1A, 0x8A, 0x02, 0x21, 0x46, 0x41, 0x43, + 0x10, 0x46, 0xFD, 0xF7, 0xE6, 0xFC, 0x00, 0xB2, 0xED, 0xE7, 0x01, 0x46, + 0xFF, 0x22, 0x0A, 0x39, 0x56, 0x32, 0x91, 0x42, 0x01, 0xD3, 0x01, 0x20, + 0x70, 0x47, 0x50, 0x28, 0x01, 0xD8, 0x02, 0x20, 0x70, 0x47, 0x64, 0x28, + 0x01, 0xD2, 0x03, 0x20, 0x70, 0x47, 0xAA, 0x28, 0x01, 0xD8, 0x04, 0x20, + 0x70, 0x47, 0xBE, 0x28, 0x01, 0xD2, 0x05, 0x20, 0x70, 0x47, 0xFF, 0x21, + 0x05, 0x31, 0x88, 0x42, 0x01, 0xD8, 0x06, 0x20, 0x70, 0x47, 0xFF, 0x21, + 0x19, 0x31, 0x88, 0x42, 0x01, 0xD2, 0x07, 0x20, 0x70, 0x47, 0x08, 0x20, + 0x70, 0x47, 0x00, 0x00, 0x06, 0x49, 0x49, 0x68, 0xCA, 0x78, 0x80, 0x1A, + 0x0A, 0x79, 0x89, 0x78, 0x10, 0x41, 0x00, 0xB2, 0x4A, 0x1E, 0x82, 0x42, + 0x00, 0xDA, 0x48, 0x1E, 0x40, 0xB2, 0x70, 0x47, 0x2C, 0x00, 0x00, 0x20, + 0xFF, 0xB5, 0x4A, 0x48, 0x1C, 0x46, 0x40, 0x68, 0x8D, 0xB0, 0xC3, 0x7E, + 0x0C, 0x93, 0x9B, 0x00, 0x08, 0x93, 0x80, 0x7E, 0x05, 0x91, 0x80, 0x00, + 0x07, 0x90, 0x00, 0x20, 0x84, 0x46, 0x06, 0x90, 0x50, 0x42, 0x42, 0xB2, + 0x20, 0xB2, 0x0A, 0x90, 0x16, 0x98, 0x0B, 0x92, 0x00, 0xB2, 0x09, 0x90, + 0x6E, 0xE0, 0x0B, 0x99, 0x68, 0xE0, 0x04, 0x25, 0x10, 0x46, 0x08, 0x43, + 0x06, 0xD1, 0x6B, 0x46, 0x09, 0x98, 0x98, 0x81, 0x0A, 0x98, 0x98, 0x80, + 0x01, 0x25, 0x28, 0xE0, 0x00, 0x2A, 0x08, 0xD1, 0x6B, 0x46, 0x09, 0x98, + 0x98, 0x81, 0x60, 0x18, 0x98, 0x80, 0x09, 0x98, 0xD8, 0x81, 0x60, 0x1A, + 0x0B, 0xE0, 0x16, 0x98, 0x00, 0x29, 0x0C, 0xD1, 0x80, 0x18, 0x6B, 0x46, + 0x98, 0x81, 0x0A, 0x98, 0x98, 0x80, 0x16, 0x98, 0x80, 0x1A, 0xD8, 0x81, + 0x0A, 0x98, 0x6B, 0x46, 0xD8, 0x80, 0x02, 0x25, 0x0D, 0xE0, 0x80, 0x18, + 0x6B, 0x46, 0x98, 0x81, 0x67, 0x18, 0x9F, 0x80, 0xD8, 0x81, 0x66, 0x1A, + 0xDE, 0x80, 0x16, 0x98, 0x80, 0x1A, 0x18, 0x82, 0x1F, 0x81, 0x58, 0x82, + 0x5E, 0x81, 0x00, 0x23, 0x2B, 0xE0, 0x5F, 0x00, 0x01, 0xA8, 0xC6, 0x5F, + 0x00, 0x2E, 0x24, 0xDB, 0x08, 0x98, 0x86, 0x42, 0x21, 0xDA, 0x03, 0xA8, + 0xC7, 0x5F, 0x00, 0x2F, 0x1D, 0xDB, 0x07, 0x98, 0x87, 0x42, 0x1A, 0xDA, + 0xB0, 0x07, 0x18, 0xD1, 0xB8, 0x07, 0x16, 0xD1, 0x0C, 0x98, 0x47, 0x43, + 0xB8, 0x19, 0x80, 0x10, 0x00, 0xB2, 0x05, 0x9E, 0x47, 0x00, 0x36, 0x88, + 0x0D, 0x98, 0xB6, 0x46, 0xC0, 0x5F, 0x00, 0x26, 0x00, 0x28, 0x00, 0xDB, + 0x06, 0x46, 0x70, 0x46, 0x46, 0x43, 0x60, 0x46, 0x30, 0x18, 0x84, 0x46, + 0x06, 0x98, 0x70, 0x44, 0x06, 0x90, 0x5B, 0x1C, 0x1B, 0xB2, 0xAB, 0x42, + 0xD1, 0xDB, 0x05, 0x98, 0x80, 0x1C, 0x49, 0x1C, 0x49, 0xB2, 0x05, 0x90, + 0x00, 0x29, 0x94, 0xDD, 0x52, 0x1C, 0x52, 0xB2, 0x00, 0x2A, 0x8E, 0xDD, + 0x06, 0x98, 0x00, 0x28, 0x04, 0xD0, 0x01, 0x46, 0x60, 0x46, 0xFD, 0xF7, + 0x12, 0xFC, 0x84, 0x46, 0x60, 0x46, 0x00, 0xB2, 0x11, 0xB0, 0xF0, 0xBD, + 0x2C, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0xFF, 0x49, 0xE5, 0xB0, 0x88, 0x88, + 0x6B, 0x46, 0x18, 0x83, 0xC8, 0x88, 0x58, 0x83, 0x08, 0x46, 0x40, 0x30, + 0x64, 0x90, 0x82, 0x8F, 0x9A, 0x82, 0xC0, 0x8F, 0xD8, 0x82, 0x00, 0x24, + 0x48, 0x78, 0x25, 0x46, 0x03, 0x28, 0x30, 0xD3, 0x00, 0x26, 0x29, 0xE0, + 0xB0, 0x00, 0x47, 0x18, 0xB8, 0x89, 0x6B, 0x46, 0x18, 0x82, 0xF8, 0x89, + 0x58, 0x82, 0x38, 0x89, 0x98, 0x81, 0x78, 0x89, 0xD8, 0x81, 0x04, 0x99, + 0x03, 0x98, 0xFE, 0xF7, 0xF9, 0xF8, 0x00, 0x90, 0x38, 0x89, 0x6B, 0x46, + 0x18, 0x81, 0x78, 0x89, 0x58, 0x81, 0xB8, 0x88, 0x98, 0x80, 0xF8, 0x88, + 0xD8, 0x80, 0x02, 0x99, 0x01, 0x98, 0xFE, 0xF7, 0xEB, 0xF8, 0x00, 0x99, + 0xFE, 0xF7, 0xF3, 0xF8, 0x73, 0x00, 0x54, 0xA9, 0xC8, 0x52, 0xC8, 0x5A, + 0xFF, 0xF7, 0xF5, 0xFE, 0x45, 0xA9, 0x76, 0x1C, 0xC8, 0x52, 0xB6, 0xB2, + 0xDF, 0x49, 0x48, 0x78, 0x80, 0x1E, 0xB0, 0x42, 0xD0, 0xDC, 0xDD, 0x4A, + 0x00, 0x20, 0x52, 0x78, 0x63, 0x92, 0x26, 0xA9, 0x06, 0x46, 0x92, 0x1E, + 0x11, 0xE0, 0xFF, 0x23, 0x0B, 0x54, 0x43, 0x00, 0x36, 0xAF, 0xFE, 0x52, + 0x2E, 0xAF, 0x9C, 0x46, 0x3E, 0x54, 0xFF, 0x27, 0x07, 0xAB, 0x1F, 0x54, + 0x63, 0x46, 0x17, 0xAF, 0xFE, 0x52, 0x0F, 0xAB, 0x1E, 0x54, 0x40, 0x1C, + 0x80, 0xB2, 0x82, 0x42, 0xEB, 0xDC, 0x00, 0x20, 0x60, 0xE0, 0x43, 0x00, + 0x45, 0xAE, 0xF6, 0x5A, 0xB4, 0x46, 0x05, 0x2E, 0x7E, 0xD0, 0x54, 0xAF, + 0xFE, 0x5A, 0xB4, 0x2E, 0x25, 0xD2, 0x63, 0x46, 0x9B, 0x1E, 0x02, 0x2B, + 0x18, 0xD8, 0x00, 0x2C, 0x04, 0xD0, 0x0B, 0x19, 0x20, 0x3B, 0xDB, 0x7F, + 0x01, 0x2B, 0x0B, 0xD1, 0x64, 0x1C, 0xE4, 0xB2, 0x0F, 0x19, 0x02, 0x23, + 0x20, 0x3F, 0xFB, 0x77, 0x2E, 0xAB, 0x1B, 0x19, 0x20, 0x3B, 0xDF, 0x7F, + 0x7F, 0x1C, 0xDF, 0x77, 0x2E, 0xAB, 0x1B, 0x19, 0x20, 0x3B, 0xDF, 0x7F, + 0x7F, 0x1C, 0xDF, 0x77, 0x0B, 0x19, 0x20, 0x3B, 0xDB, 0x7F, 0x02, 0x2B, + 0x32, 0xD1, 0x67, 0x00, 0x36, 0xAB, 0xFB, 0x18, 0x2A, 0xE0, 0xFF, 0x27, + 0x69, 0x37, 0xBE, 0x1B, 0xB6, 0xB2, 0x54, 0xAF, 0xFE, 0x52, 0x63, 0x46, + 0x9B, 0x1F, 0x02, 0x2B, 0x18, 0xD8, 0x00, 0x2C, 0x04, 0xD0, 0x0B, 0x19, + 0x20, 0x3B, 0xDB, 0x7F, 0x02, 0x2B, 0x0B, 0xD1, 0x64, 0x1C, 0xE4, 0xB2, + 0x0F, 0x19, 0x01, 0x23, 0x20, 0x3F, 0xFB, 0x77, 0x2E, 0xAB, 0x1B, 0x19, + 0x20, 0x3B, 0xDF, 0x7F, 0x7F, 0x1C, 0xDF, 0x77, 0x2E, 0xAB, 0x1B, 0x19, + 0x20, 0x3B, 0xDF, 0x7F, 0x7F, 0x1C, 0xDF, 0x77, 0x0B, 0x19, 0x20, 0x3B, + 0xDB, 0x7F, 0x01, 0x2B, 0x06, 0xD1, 0x63, 0x00, 0x36, 0xAF, 0xDB, 0x19, + 0x20, 0x3B, 0xDF, 0x8B, 0xBE, 0x19, 0xDE, 0x83, 0x40, 0x1C, 0x80, 0xB2, + 0x82, 0x42, 0x9C, 0xDC, 0x00, 0x20, 0x19, 0xE0, 0x2E, 0xA9, 0x0B, 0x5C, + 0x04, 0x2B, 0x04, 0xD8, 0x43, 0x00, 0x36, 0xAE, 0xF3, 0x5A, 0x3C, 0x2B, + 0x0E, 0xD3, 0x09, 0x5C, 0x0F, 0xAB, 0x59, 0x55, 0x41, 0x00, 0x36, 0xAB, + 0x59, 0x5A, 0x6B, 0x00, 0x17, 0xAE, 0xF1, 0x52, 0x26, 0xA9, 0x09, 0x5C, + 0x07, 0xAB, 0x59, 0x55, 0x6D, 0x1C, 0xED, 0xB2, 0x40, 0x1C, 0x80, 0xB2, + 0xA0, 0x42, 0xE3, 0xD3, 0x00, 0x23, 0x18, 0x46, 0x19, 0x46, 0x2C, 0xE0, + 0xA5, 0xE0, 0x07, 0xAE, 0x74, 0x56, 0xA4, 0x46, 0x9C, 0x42, 0x10, 0xD0, + 0x73, 0x5C, 0x0F, 0xAC, 0x64, 0x5C, 0x2E, 0xAE, 0x34, 0x54, 0x4C, 0x00, + 0x17, 0xAE, 0x34, 0x5B, 0x46, 0x00, 0x36, 0xAF, 0xBC, 0x53, 0x64, 0x46, + 0x26, 0xAE, 0x34, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0x13, 0xE0, 0x2E, 0xAC, + 0x24, 0x18, 0x20, 0x3C, 0x0F, 0xAF, 0xE6, 0x7F, 0x7F, 0x5C, 0xF6, 0x19, + 0xE6, 0x77, 0x46, 0x00, 0x36, 0xAC, 0x34, 0x19, 0x20, 0x3C, 0xA4, 0x46, + 0x4E, 0x00, 0x17, 0xAF, 0xE4, 0x8B, 0xBE, 0x5B, 0xA6, 0x19, 0x64, 0x46, + 0xE6, 0x83, 0x49, 0x1C, 0x89, 0xB2, 0xA9, 0x42, 0xD1, 0xD3, 0x63, 0x99, + 0x73, 0x4D, 0x02, 0x29, 0x06, 0xD8, 0xA8, 0x78, 0x00, 0x1F, 0x4C, 0x28, + 0x6F, 0xD2, 0xF1, 0x20, 0x65, 0xB0, 0xF0, 0xBD, 0x00, 0x28, 0x26, 0xD1, + 0x64, 0x98, 0x6B, 0x46, 0x81, 0x8F, 0x19, 0x82, 0xC0, 0x8F, 0x58, 0x82, + 0xA8, 0x88, 0x98, 0x81, 0xE8, 0x88, 0xD8, 0x81, 0x04, 0x99, 0x03, 0x98, + 0xFD, 0xF7, 0xEC, 0xFF, 0x01, 0x46, 0xFF, 0x22, 0x2D, 0x39, 0x10, 0x32, + 0x91, 0x42, 0x01, 0xD3, 0xA0, 0x20, 0xE5, 0xE7, 0x01, 0x46, 0x2E, 0x39, + 0x59, 0x29, 0x01, 0xD2, 0xA1, 0x20, 0xDF, 0xE7, 0x01, 0x46, 0x88, 0x39, + 0x59, 0x29, 0x01, 0xD2, 0xA2, 0x20, 0xD9, 0xE7, 0xE2, 0x38, 0x59, 0x28, + 0xD4, 0xD2, 0xA3, 0x20, 0xD4, 0xE7, 0xFF, 0x21, 0x0F, 0x31, 0x01, 0x28, + 0x70, 0xD1, 0x58, 0x4C, 0x80, 0x34, 0xA0, 0x88, 0xE3, 0x88, 0xC0, 0x18, + 0x40, 0x08, 0x6B, 0x46, 0x18, 0x82, 0x20, 0x88, 0x63, 0x88, 0xC0, 0x18, + 0x40, 0x08, 0x6B, 0x46, 0x58, 0x82, 0x30, 0xAB, 0x18, 0x8B, 0xFF, 0x23, + 0xC3, 0x33, 0x98, 0x42, 0x2B, 0xD8, 0x88, 0x42, 0x2C, 0xD9, 0x05, 0x9A, + 0x06, 0x99, 0x04, 0x98, 0xFF, 0xF7, 0x32, 0xFC, 0x6B, 0x46, 0x03, 0x90, + 0xDF, 0x8A, 0x59, 0x8B, 0x18, 0x8B, 0x9A, 0x8A, 0x0D, 0x46, 0x06, 0x46, + 0x3B, 0x46, 0xFF, 0xF7, 0x75, 0xFA, 0x1E, 0x28, 0x18, 0xD3, 0x03, 0x98, + 0xFF, 0x21, 0x1E, 0x38, 0x2E, 0x31, 0x88, 0x42, 0x12, 0xD2, 0x03, 0x98, + 0xB4, 0x28, 0x2A, 0xD8, 0xE1, 0x88, 0xA0, 0x88, 0x09, 0x1A, 0x89, 0x10, + 0x08, 0x18, 0xB0, 0x42, 0x08, 0xDD, 0x20, 0x88, 0x85, 0x42, 0x05, 0xD9, + 0x60, 0x88, 0x85, 0x42, 0x02, 0xD2, 0x65, 0x20, 0x90, 0xE7, 0x71, 0xE0, + 0x6F, 0x20, 0x8D, 0xE7, 0x3C, 0x28, 0x6D, 0xD9, 0x00, 0x21, 0xFF, 0x27, + 0x0C, 0x46, 0x08, 0x46, 0x54, 0xAE, 0x69, 0x37, 0x0B, 0xE0, 0x43, 0x00, + 0xF3, 0x5A, 0xB4, 0x2B, 0x00, 0xD9, 0xFB, 0x1A, 0x9B, 0xB2, 0x8B, 0x42, + 0x01, 0xD9, 0x04, 0x46, 0x19, 0x46, 0x40, 0x1C, 0x80, 0xB2, 0x82, 0x42, + 0xF1, 0xDC, 0x5A, 0x29, 0x01, 0xD2, 0x63, 0x20, 0x72, 0xE7, 0xA0, 0x00, + 0x40, 0x19, 0x01, 0x89, 0x6B, 0x46, 0x19, 0x81, 0x40, 0x89, 0x58, 0x81, + 0x04, 0x99, 0x02, 0x98, 0xFD, 0xF7, 0x66, 0xFF, 0x01, 0x46, 0xFF, 0x22, + 0x2D, 0x39, 0x10, 0x32, 0x91, 0x42, 0x02, 0xD3, 0x3C, 0x20, 0x5F, 0xE7, + 0x10, 0xE0, 0x01, 0x46, 0x2E, 0x39, 0x59, 0x29, 0x01, 0xD2, 0x76, 0x20, + 0x58, 0xE7, 0x01, 0x46, 0x88, 0x39, 0x59, 0x29, 0x01, 0xD2, 0x3E, 0x20, + 0x52, 0xE7, 0xE2, 0x38, 0x59, 0x28, 0x4D, 0xD2, 0x5E, 0x20, 0x4D, 0xE7, + 0x02, 0x28, 0x18, 0xD1, 0x20, 0xAB, 0x18, 0x20, 0x18, 0x56, 0x01, 0x28, + 0x08, 0xD1, 0x30, 0xAB, 0x1A, 0x8B, 0x8A, 0x42, 0x04, 0xD2, 0x5A, 0x8B, + 0x8A, 0x42, 0x01, 0xD2, 0x73, 0x20, 0x3D, 0xE7, 0x02, 0x28, 0x39, 0xD1, + 0x30, 0xAB, 0x18, 0x8B, 0x88, 0x42, 0x35, 0xD2, 0x58, 0x8B, 0x88, 0x42, + 0x32, 0xD2, 0x7A, 0x20, 0x32, 0xE7, 0x03, 0x28, 0x1E, 0xD1, 0x20, 0xAB, + 0x18, 0x20, 0x18, 0x56, 0x01, 0x28, 0x0E, 0xD1, 0x30, 0xAB, 0x19, 0x8B, + 0xDC, 0x29, 0x0A, 0xD2, 0x59, 0x8B, 0xDC, 0x29, 0x07, 0xD2, 0x99, 0x8B, + 0xDC, 0x29, 0x04, 0xD2, 0x77, 0x20, 0x1F, 0xE7, 0xA4, 0x0A, 0x00, 0x20, + 0x1A, 0xE0, 0x02, 0x28, 0x18, 0xD1, 0x30, 0xAB, 0x18, 0x8B, 0x0F, 0xE0, + 0x30, 0xAB, 0x98, 0x8B, 0xDC, 0x28, 0x11, 0xD2, 0x6D, 0x20, 0x11, 0xE7, + 0x04, 0x28, 0x0D, 0xD1, 0x20, 0xAB, 0x18, 0x7E, 0x01, 0x28, 0x09, 0xD1, + 0x30, 0xAB, 0x18, 0x8B, 0x5A, 0x28, 0x05, 0xD9, 0xDC, 0x28, 0x03, 0xD2, + 0x30, 0xAB, 0x58, 0x8B, 0xDC, 0x28, 0xE9, 0xD3, 0x00, 0x20, 0xFF, 0xE6, + 0xFF, 0xB5, 0x83, 0xB0, 0x0C, 0xA8, 0x0F, 0xC8, 0x00, 0x25, 0xFF, 0xF7, + 0xC3, 0xF9, 0x00, 0x27, 0x3C, 0x46, 0x01, 0x97, 0x02, 0x90, 0x00, 0x28, + 0x2E, 0xD0, 0x26, 0xE0, 0x0E, 0x99, 0x0C, 0x98, 0x08, 0x1A, 0x68, 0x43, + 0x02, 0x99, 0xFD, 0xF7, 0xE0, 0xF9, 0x0C, 0x99, 0x40, 0x18, 0x06, 0xB2, + 0x0D, 0x99, 0x0F, 0x98, 0x40, 0x1A, 0x68, 0x43, 0x02, 0x99, 0xFD, 0xF7, + 0xD6, 0xF9, 0x0D, 0x99, 0x40, 0x18, 0x00, 0xB2, 0x00, 0x2C, 0x04, 0xD0, + 0xB7, 0x42, 0x02, 0xD1, 0x01, 0x99, 0x81, 0x42, 0x09, 0xD0, 0x61, 0x00, + 0x03, 0x9A, 0x64, 0x1C, 0x56, 0x52, 0x04, 0x9A, 0xB7, 0xB2, 0x50, 0x52, + 0x80, 0xB2, 0xA4, 0xB2, 0x01, 0x90, 0x6D, 0x1C, 0xAD, 0xB2, 0x02, 0x98, + 0x85, 0x42, 0x02, 0xD8, 0x05, 0x98, 0x84, 0x42, 0xD2, 0xD3, 0xE0, 0xB2, + 0x07, 0xB0, 0xF0, 0xBD, 0x06, 0x49, 0x8A, 0x7D, 0x06, 0x48, 0xC0, 0x6B, + 0x43, 0x7A, 0x9A, 0x43, 0x8A, 0x75, 0x40, 0x7A, 0x48, 0x76, 0x03, 0x48, + 0x01, 0x21, 0x60, 0x38, 0x81, 0x74, 0x70, 0x47, 0x00, 0x03, 0x00, 0x40, + 0xC0, 0x00, 0x00, 0x20, 0x03, 0x49, 0x02, 0x48, 0xC8, 0x60, 0xBF, 0xF3, + 0x4F, 0x8F, 0xFE, 0xE7, 0x04, 0x00, 0xFA, 0x05, 0x00, 0xED, 0x00, 0xE0, + 0x03, 0xE0, 0x0B, 0x78, 0x03, 0x70, 0x40, 0x1C, 0x49, 0x1C, 0x52, 0x1E, + 0xF9, 0xD2, 0x70, 0x47, 0x03, 0xE0, 0x0B, 0x88, 0x03, 0x80, 0x80, 0x1C, + 0x89, 0x1C, 0x52, 0x1E, 0xF9, 0xD2, 0x70, 0x47, 0x01, 0xE0, 0x01, 0x70, + 0x40, 0x1C, 0x52, 0x1E, 0xFB, 0xD2, 0x70, 0x47, 0xF8, 0xB5, 0x52, 0x4E, + 0xF0, 0x79, 0x52, 0x4F, 0xC0, 0x07, 0x3D, 0x46, 0x80, 0x35, 0x00, 0x28, + 0x2F, 0xD0, 0x01, 0x20, 0x3C, 0x46, 0xE0, 0x34, 0xA0, 0x70, 0xF0, 0x79, + 0x00, 0x06, 0x24, 0xD5, 0x70, 0x88, 0xD1, 0x21, 0x09, 0x02, 0x41, 0x1A, + 0x20, 0x29, 0x04, 0xD8, 0xC0, 0xB2, 0x03, 0xF0, 0x23, 0xFB, 0x02, 0x20, + 0x06, 0xE0, 0x47, 0x49, 0x88, 0x42, 0x05, 0xD1, 0x46, 0x49, 0x02, 0xF0, + 0xE7, 0xFF, 0x03, 0x20, 0xA0, 0x70, 0x0E, 0xE0, 0x0D, 0x21, 0x09, 0x03, + 0x41, 0x1A, 0x50, 0x29, 0x09, 0xD8, 0xF9, 0x60, 0x03, 0x21, 0xA1, 0x70, + 0x3F, 0x49, 0x29, 0x64, 0x3F, 0x49, 0x88, 0x42, 0x01, 0xD1, 0xFF, 0xF7, + 0x9F, 0xF9, 0x10, 0x20, 0xF0, 0x71, 0x3D, 0x49, 0xA0, 0x20, 0x88, 0x80, + 0xF8, 0xBD, 0xB3, 0x79, 0xCF, 0x20, 0x03, 0x40, 0x35, 0x48, 0xC0, 0x22, + 0x01, 0x46, 0x12, 0x58, 0x20, 0x31, 0xC0, 0x68, 0x01, 0x2B, 0x1C, 0xD0, + 0x05, 0x2B, 0x08, 0xD0, 0x00, 0x24, 0x09, 0x2B, 0x01, 0xD0, 0xB4, 0x71, + 0xF8, 0xBD, 0xBC, 0x72, 0x73, 0x88, 0xDB, 0x07, 0x05, 0xD0, 0x31, 0x4B, + 0x98, 0x42, 0x04, 0xD1, 0xA5, 0x20, 0x70, 0x80, 0x08, 0xE0, 0x10, 0x20, + 0x07, 0xE0, 0x4B, 0x7D, 0x27, 0x49, 0x10, 0x5C, 0xC9, 0x68, 0x49, 0x1C, + 0x70, 0x80, 0xF9, 0x60, 0x14, 0x20, 0xB0, 0x71, 0xF8, 0xBD, 0xBB, 0x7A, + 0x02, 0x2B, 0x35, 0xD2, 0x00, 0x2B, 0x0C, 0xD0, 0x72, 0x88, 0x00, 0x02, + 0x80, 0x18, 0x84, 0xB2, 0xD1, 0x20, 0x00, 0x02, 0x20, 0x1A, 0x20, 0x28, + 0x05, 0xD8, 0xE0, 0xB2, 0x03, 0xF0, 0xCA, 0xFA, 0x2E, 0xE0, 0x70, 0x88, + 0x2B, 0xE0, 0x48, 0x7D, 0x00, 0x28, 0x0C, 0xD0, 0x19, 0x49, 0x20, 0x46, + 0x02, 0xF0, 0x8C, 0xFF, 0x41, 0x20, 0x40, 0x02, 0x20, 0x1A, 0xFF, 0x28, + 0x20, 0xD8, 0x69, 0x6C, 0x0A, 0x31, 0x29, 0x64, 0x1B, 0xE0, 0x13, 0x48, + 0x28, 0x64, 0x0D, 0x20, 0x00, 0x03, 0x20, 0x1A, 0x50, 0x28, 0x00, 0xD8, + 0xF8, 0x60, 0x10, 0x48, 0x84, 0x42, 0x01, 0xD1, 0xFF, 0xF7, 0x40, 0xF9, + 0x01, 0x20, 0x00, 0x03, 0x84, 0x42, 0x0B, 0xD2, 0x68, 0x6C, 0x28, 0x64, + 0xFC, 0x60, 0x07, 0xE0, 0x0B, 0x49, 0x88, 0x42, 0x04, 0xD0, 0x71, 0x88, + 0x11, 0x54, 0xF8, 0x68, 0x40, 0x1C, 0xF8, 0x60, 0xB8, 0x7A, 0x40, 0x1C, + 0xB8, 0x72, 0xAE, 0xE7, 0x00, 0x20, 0x00, 0x40, 0x40, 0x00, 0x00, 0x20, + 0xF4, 0xD1, 0x00, 0x00, 0x11, 0x07, 0x00, 0x20, 0x40, 0xD0, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x40, 0xFF, 0xFF, 0x00, 0x00, 0x30, 0xB5, 0x10, 0x49, + 0x10, 0x4A, 0x00, 0x20, 0x43, 0x00, 0x40, 0x1C, 0x80, 0xB2, 0xD1, 0x52, + 0x1E, 0x28, 0xF9, 0xD3, 0x00, 0x22, 0x0D, 0x4B, 0x0B, 0x4C, 0x1A, 0x70, + 0x11, 0x46, 0x3C, 0x34, 0x14, 0x20, 0x48, 0x43, 0x00, 0x19, 0x82, 0x81, + 0xC5, 0x7C, 0x49, 0x1C, 0x2D, 0x09, 0x2D, 0x01, 0xED, 0xB2, 0x2D, 0x07, + 0x2D, 0x0F, 0x89, 0xB2, 0xC5, 0x74, 0x0A, 0x29, 0xF0, 0xD3, 0x5A, 0x70, + 0x30, 0xBD, 0x00, 0x00, 0xFF, 0x3F, 0x00, 0x00, 0x88, 0x08, 0x00, 0x20, + 0x2C, 0x00, 0x00, 0x20, 0x00, 0x23, 0x02, 0xE0, 0xC1, 0x54, 0x5B, 0x1C, + 0x9B, 0xB2, 0x93, 0x42, 0xFA, 0xD3, 0x70, 0x47, 0x01, 0x20, 0x80, 0x07, + 0x01, 0x89, 0x04, 0x22, 0x11, 0x43, 0x01, 0x81, 0x02, 0x89, 0x08, 0x21, + 0x0A, 0x43, 0x02, 0x81, 0x42, 0x89, 0x80, 0x23, 0x1A, 0x43, 0x42, 0x81, + 0x42, 0x89, 0x8A, 0x43, 0x42, 0x81, 0x41, 0x89, 0x71, 0x22, 0x11, 0x43, + 0x41, 0x81, 0x81, 0x89, 0x09, 0x09, 0x09, 0x01, 0x81, 0x81, 0x70, 0x47, + 0x10, 0xB5, 0x12, 0x4A, 0x10, 0x48, 0x50, 0x80, 0x11, 0x48, 0x00, 0x78, + 0x03, 0x02, 0x11, 0x48, 0xC1, 0x6B, 0x08, 0x46, 0x20, 0x30, 0x84, 0x78, + 0x23, 0x43, 0x13, 0x81, 0x40, 0x31, 0x89, 0x8A, 0xD1, 0x80, 0xC1, 0x78, + 0xFF, 0x31, 0xFF, 0x31, 0x02, 0x31, 0x51, 0x81, 0x42, 0x79, 0x01, 0x79, + 0x12, 0x01, 0x80, 0x79, 0x11, 0x43, 0xC0, 0x00, 0x80, 0x22, 0x10, 0x43, + 0x01, 0x43, 0x06, 0x48, 0x81, 0x74, 0x02, 0xF0, 0xC3, 0xFE, 0x10, 0xBD, + 0x82, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0xF8, 0x73, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0xE0, 0x12, 0x00, 0x40, 0x70, 0xB5, 0x01, 0x21, + 0x89, 0x07, 0x88, 0x89, 0x00, 0x07, 0x00, 0x0F, 0x88, 0x81, 0x20, 0x48, + 0xC2, 0x6B, 0x90, 0x7F, 0x00, 0x28, 0x34, 0xD0, 0x02, 0x28, 0x88, 0x89, + 0x34, 0xD0, 0x30, 0x23, 0x18, 0x43, 0x88, 0x81, 0x1B, 0x4D, 0xC1, 0x20, + 0x68, 0x70, 0x13, 0x46, 0x20, 0x33, 0x1C, 0x78, 0xD2, 0x7F, 0x20, 0x01, + 0x18, 0x4E, 0x10, 0x43, 0x30, 0x83, 0x01, 0x26, 0x30, 0x46, 0xA0, 0x40, + 0x96, 0x40, 0x16, 0x4A, 0x30, 0x43, 0x94, 0x7C, 0x04, 0x43, 0x94, 0x74, + 0x54, 0x7C, 0x04, 0x43, 0x54, 0x74, 0x5C, 0x78, 0x01, 0x2C, 0x54, 0x7D, + 0x18, 0xD0, 0x84, 0x43, 0x54, 0x75, 0x14, 0x7D, 0x04, 0x43, 0x14, 0x75, + 0xD4, 0x7C, 0x20, 0x43, 0xD0, 0x74, 0x48, 0x89, 0x40, 0x22, 0x10, 0x43, + 0x48, 0x81, 0x00, 0x20, 0x68, 0x71, 0x59, 0x7C, 0x80, 0x22, 0x11, 0x43, + 0x29, 0x70, 0xE8, 0x71, 0x70, 0xBD, 0x88, 0x89, 0xE0, 0x23, 0xCB, 0xE7, + 0x10, 0x23, 0xC9, 0xE7, 0x04, 0x43, 0xE5, 0xE7, 0xC0, 0x00, 0x00, 0x20, + 0x00, 0x20, 0x00, 0x40, 0x20, 0x11, 0x00, 0x40, 0x00, 0x03, 0x00, 0x40, + 0x10, 0xB5, 0x01, 0x21, 0x03, 0x20, 0xFD, 0xF7, 0x19, 0xF9, 0x02, 0x21, + 0x05, 0x20, 0xFD, 0xF7, 0x15, 0xF9, 0x03, 0x21, 0x04, 0x20, 0xFD, 0xF7, + 0x11, 0xF9, 0x05, 0x20, 0xFD, 0xF7, 0x02, 0xF9, 0x03, 0x20, 0xFD, 0xF7, + 0xFF, 0xF8, 0x04, 0x20, 0xFD, 0xF7, 0xFC, 0xF8, 0x62, 0xB6, 0x10, 0xBD, + 0x30, 0xB5, 0x0E, 0x48, 0x03, 0x7C, 0x0E, 0x49, 0x01, 0x22, 0xC9, 0x6B, + 0x14, 0x46, 0x4D, 0x7C, 0xAC, 0x40, 0x23, 0x43, 0x03, 0x74, 0x43, 0x7D, + 0x4D, 0x7C, 0x14, 0x46, 0xAC, 0x40, 0xA3, 0x43, 0x43, 0x75, 0x03, 0x7D, + 0x4D, 0x7C, 0x14, 0x46, 0xAC, 0x40, 0x23, 0x43, 0x03, 0x75, 0xC3, 0x7C, + 0x49, 0x7C, 0x8A, 0x40, 0x13, 0x43, 0xC3, 0x74, 0x30, 0xBD, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x40, 0xC0, 0x00, 0x00, 0x20, 0x10, 0xB5, 0x16, 0x48, + 0xC1, 0x7C, 0x49, 0x08, 0x49, 0x00, 0xC1, 0x74, 0x01, 0x7D, 0x49, 0x08, + 0x49, 0x00, 0x01, 0x75, 0x01, 0x7D, 0xFD, 0x22, 0x11, 0x40, 0x01, 0x75, + 0x01, 0x7D, 0xFB, 0x22, 0x11, 0x40, 0x01, 0x75, 0x02, 0x46, 0x00, 0x21, + 0x20, 0x3A, 0x11, 0x72, 0xD1, 0x71, 0x51, 0x72, 0x01, 0x71, 0xD1, 0x84, + 0x81, 0x75, 0x41, 0x71, 0x01, 0x23, 0x83, 0x74, 0xD1, 0x70, 0x60, 0x30, + 0xC0, 0x6B, 0x28, 0x24, 0x24, 0x5C, 0x94, 0x71, 0x53, 0x70, 0x00, 0x78, + 0x10, 0x70, 0xD0, 0x1D, 0xF9, 0x30, 0x81, 0x77, 0xFF, 0x21, 0xC1, 0x77, + 0x10, 0xBD, 0x00, 0x00, 0x60, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x7F, 0x4C, + 0x85, 0xB0, 0x7D, 0x48, 0xE0, 0x63, 0x7E, 0x48, 0x20, 0x64, 0x20, 0x46, + 0x80, 0x38, 0x7D, 0x49, 0x81, 0x63, 0x09, 0x31, 0xC1, 0x63, 0x09, 0x31, + 0x8C, 0x46, 0x01, 0x64, 0x48, 0x31, 0x41, 0x64, 0x90, 0x31, 0x81, 0x64, + 0x90, 0x31, 0xC1, 0x64, 0x90, 0x31, 0x04, 0x91, 0x01, 0x65, 0x90, 0x31, + 0x41, 0x65, 0x90, 0x31, 0x81, 0x65, 0x6C, 0x31, 0xC1, 0x65, 0x0C, 0x31, + 0x03, 0x91, 0x01, 0x66, 0x12, 0x31, 0x41, 0x66, 0x12, 0x31, 0x02, 0x91, + 0x81, 0x66, 0x12, 0x31, 0xC1, 0x66, 0x12, 0x31, 0x01, 0x67, 0x09, 0x31, + 0x05, 0x46, 0x41, 0x67, 0x00, 0x26, 0xC0, 0x35, 0x2E, 0x77, 0x09, 0x31, + 0x01, 0x91, 0x81, 0x67, 0x10, 0x31, 0xC1, 0x67, 0x08, 0x46, 0x10, 0x30, + 0x00, 0x90, 0x20, 0x60, 0x10, 0x30, 0x60, 0x60, 0x10, 0x30, 0xA0, 0x60, + 0x08, 0x30, 0xE0, 0x60, 0x08, 0x30, 0x20, 0x61, 0x40, 0x30, 0x60, 0x61, + 0x60, 0x48, 0x60, 0x62, 0xC0, 0x1F, 0x20, 0x62, 0x10, 0x30, 0xA0, 0x62, + 0x24, 0x30, 0xE0, 0x62, 0x58, 0x38, 0xE0, 0x61, 0x1C, 0x38, 0xA0, 0x61, + 0x5B, 0x48, 0xA0, 0x63, 0x00, 0x1F, 0x60, 0x63, 0x00, 0x1F, 0x00, 0x21, + 0x20, 0x63, 0x0F, 0xE0, 0x28, 0x23, 0x0A, 0x46, 0x5A, 0x43, 0x67, 0x69, + 0x93, 0x1C, 0xFE, 0x54, 0x60, 0x69, 0x53, 0x1C, 0x86, 0x54, 0x67, 0x69, + 0x52, 0x1D, 0xFE, 0x54, 0x60, 0x69, 0x49, 0x1C, 0x86, 0x54, 0xC9, 0xB2, + 0xE0, 0x6B, 0xC0, 0x7A, 0x88, 0x42, 0xEB, 0xD8, 0x48, 0x22, 0x00, 0x21, + 0x60, 0x46, 0xFF, 0xF7, 0xA3, 0xFD, 0x90, 0x22, 0x00, 0x21, 0x04, 0x98, + 0xFF, 0xF7, 0x9E, 0xFD, 0x12, 0x22, 0x00, 0x21, 0x02, 0x98, 0xFF, 0xF7, + 0x99, 0xFD, 0x12, 0x22, 0x00, 0x21, 0x03, 0x98, 0xFF, 0xF7, 0x94, 0xFD, + 0x10, 0x22, 0x00, 0x21, 0x00, 0x98, 0xFF, 0xF7, 0x8F, 0xFD, 0x10, 0x22, + 0x00, 0x21, 0x01, 0x98, 0xFF, 0xF7, 0x8A, 0xFD, 0x3A, 0x4F, 0x07, 0x22, + 0x80, 0x3F, 0x00, 0x21, 0xF8, 0x6D, 0xFF, 0xF7, 0x83, 0xFD, 0x3F, 0x22, + 0x00, 0x21, 0xB8, 0x6D, 0xFF, 0xF7, 0x7E, 0xFD, 0x09, 0x22, 0x00, 0x21, + 0xF8, 0x6B, 0xFF, 0xF7, 0x79, 0xFD, 0x09, 0x22, 0x00, 0x21, 0xB8, 0x6B, + 0xFF, 0xF7, 0x74, 0xFD, 0x38, 0x46, 0x20, 0x30, 0x46, 0x75, 0x86, 0x73, + 0x06, 0x72, 0x46, 0x74, 0x3E, 0x74, 0x01, 0x20, 0x78, 0x74, 0xFF, 0x37, + 0x2F, 0x48, 0x01, 0x37, 0xF8, 0x60, 0x2F, 0x48, 0x38, 0x61, 0x2F, 0x48, + 0x78, 0x61, 0x2F, 0x48, 0xB8, 0x61, 0x38, 0x46, 0x20, 0x30, 0x00, 0x90, + 0x86, 0x70, 0x7E, 0x62, 0x46, 0x70, 0x7E, 0x77, 0x3E, 0x77, 0x02, 0x20, + 0x68, 0x77, 0xAE, 0x77, 0xEE, 0x77, 0x3D, 0x46, 0x20, 0x3D, 0x2E, 0x70, + 0x6E, 0x70, 0xAE, 0x70, 0x1E, 0x48, 0x28, 0x49, 0x09, 0x38, 0xA0, 0x64, + 0x24, 0x48, 0xE0, 0x64, 0x24, 0x48, 0x20, 0x65, 0x22, 0x48, 0xC0, 0x1D, + 0x60, 0x65, 0xC0, 0x1D, 0xB8, 0x63, 0xE0, 0x6B, 0xC2, 0x78, 0x1F, 0x48, + 0xFF, 0xF7, 0x2E, 0xFD, 0xE0, 0x6B, 0x20, 0x49, 0x02, 0x79, 0x14, 0x48, + 0x09, 0x38, 0xFF, 0xF7, 0x27, 0xFD, 0xFF, 0x21, 0x28, 0x46, 0x60, 0x30, + 0xC1, 0x71, 0xEE, 0x70, 0x0F, 0x21, 0x81, 0x71, 0x19, 0x21, 0x01, 0x71, + 0x01, 0x21, 0x41, 0x71, 0x0C, 0x48, 0x16, 0x22, 0x00, 0x21, 0x51, 0x30, + 0xFF, 0xF7, 0x26, 0xFD, 0x01, 0xF0, 0x4A, 0xF8, 0x08, 0x48, 0x51, 0x30, + 0x38, 0x64, 0x00, 0x98, 0x06, 0x74, 0xFD, 0xF7, 0xE7, 0xF9, 0xFD, 0xF7, + 0x47, 0xFB, 0x02, 0xF0, 0xF7, 0xFC, 0x05, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xE4, 0x72, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0x11, 0x07, 0x00, 0x20, + 0x8C, 0x01, 0x00, 0x20, 0xAF, 0x73, 0x00, 0x00, 0x64, 0x73, 0x00, 0x00, + 0xFD, 0x5D, 0x00, 0x00, 0x75, 0x44, 0x00, 0x00, 0xDD, 0x6E, 0x00, 0x00, + 0x79, 0x4E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, + 0x45, 0x73, 0x00, 0x00, 0x3C, 0x73, 0x00, 0x00, 0xF0, 0xB5, 0x97, 0xB0, + 0x00, 0x20, 0x12, 0x90, 0x60, 0x48, 0x41, 0x78, 0x16, 0x91, 0x01, 0x78, + 0x15, 0x91, 0x49, 0x1E, 0x13, 0x91, 0x12, 0x98, 0xA1, 0xE0, 0x00, 0x24, + 0xFF, 0x25, 0xA4, 0x46, 0xAE, 0x46, 0x20, 0x46, 0x23, 0x46, 0x00, 0x94, + 0x03, 0xE0, 0x0F, 0xAA, 0x13, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0x15, 0x9A, + 0x90, 0x42, 0xF8, 0xD3, 0x6B, 0x46, 0x12, 0x98, 0x18, 0x71, 0x12, 0x9A, + 0x14, 0x23, 0x5A, 0x43, 0x52, 0x4B, 0x01, 0x20, 0xD2, 0x18, 0xD2, 0x7C, + 0x12, 0x07, 0x7E, 0xD1, 0x40, 0x1E, 0xC0, 0xB2, 0x01, 0xA9, 0x0B, 0x5C, + 0x14, 0x21, 0x4D, 0x4A, 0x59, 0x43, 0x89, 0x18, 0xCF, 0x7C, 0x3A, 0x07, + 0x12, 0x0F, 0x02, 0x2A, 0x23, 0xD0, 0xCA, 0x89, 0x0F, 0xAE, 0x12, 0x19, + 0x94, 0xB2, 0x01, 0x22, 0xF2, 0x54, 0x3A, 0x09, 0x12, 0x01, 0x92, 0x1C, + 0xCA, 0x74, 0x8A, 0x7C, 0x16, 0x07, 0x36, 0x0F, 0xAE, 0x42, 0x00, 0xD8, + 0x35, 0x46, 0x12, 0x09, 0x66, 0x46, 0x62, 0x45, 0x00, 0xD3, 0x16, 0x46, + 0xB4, 0x46, 0x4E, 0x7C, 0x72, 0x46, 0x31, 0x07, 0x09, 0x0F, 0x71, 0x45, + 0x00, 0xD8, 0x0A, 0x46, 0x96, 0x46, 0x00, 0x99, 0x32, 0x09, 0x8A, 0x42, + 0x00, 0xD3, 0x11, 0x46, 0x00, 0x91, 0x00, 0x22, 0x25, 0xE0, 0x11, 0x46, + 0x0E, 0x26, 0x71, 0x43, 0x34, 0x4E, 0xC8, 0x36, 0x89, 0x19, 0x8E, 0x7A, + 0x31, 0x07, 0x09, 0x0F, 0x99, 0x42, 0x01, 0xD1, 0x31, 0x09, 0x02, 0xE0, + 0x36, 0x09, 0x9E, 0x42, 0x13, 0xD1, 0x00, 0x29, 0x11, 0xDB, 0x14, 0x27, + 0x0E, 0x46, 0x7E, 0x43, 0x2B, 0x4F, 0xF6, 0x19, 0x14, 0x96, 0xF6, 0x7C, + 0x37, 0x07, 0x08, 0xD1, 0x01, 0xAF, 0x39, 0x54, 0x31, 0x09, 0x40, 0x1C, + 0x09, 0x01, 0x14, 0x9E, 0x49, 0x1C, 0xC0, 0xB2, 0xF1, 0x74, 0x52, 0x1C, + 0xD2, 0xB2, 0x16, 0x99, 0x8A, 0x42, 0xD6, 0xD3, 0x37, 0x28, 0x1F, 0xD2, + 0x00, 0x28, 0x9F, 0xD1, 0x1F, 0x4D, 0x0F, 0xAE, 0xC8, 0x35, 0x1D, 0x4F, + 0x11, 0xE0, 0x0E, 0x21, 0x41, 0x43, 0x4A, 0x19, 0x92, 0x7A, 0x13, 0x07, + 0x1B, 0x0F, 0xF3, 0x5C, 0x01, 0x2B, 0x06, 0xD1, 0x12, 0x09, 0xB2, 0x5C, + 0x01, 0x2A, 0x02, 0xD1, 0x69, 0x5A, 0x09, 0x19, 0x8C, 0xB2, 0x40, 0x1C, + 0xC0, 0xB2, 0x16, 0x99, 0x88, 0x42, 0xEA, 0xD3, 0x78, 0x68, 0x00, 0x88, + 0xA0, 0x42, 0x04, 0xD8, 0x00, 0xE0, 0x02, 0xE0, 0x01, 0x20, 0x17, 0xB0, + 0xF0, 0xBD, 0x12, 0x98, 0x40, 0x1C, 0xC0, 0xB2, 0x12, 0x90, 0x13, 0x9A, + 0x0A, 0x49, 0x90, 0x42, 0x00, 0xDA, 0x58, 0xE7, 0x00, 0x20, 0x09, 0x4A, + 0x08, 0xE0, 0x14, 0x21, 0x41, 0x43, 0x89, 0x18, 0xCB, 0x7C, 0x1B, 0x09, + 0x1B, 0x01, 0x40, 0x1C, 0xCB, 0x74, 0xC0, 0xB2, 0x15, 0x99, 0x88, 0x42, + 0xF3, 0xD3, 0x00, 0x20, 0xE3, 0xE7, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, + 0xC4, 0x08, 0x00, 0x20, 0x17, 0xB5, 0x6B, 0x46, 0x99, 0x88, 0x18, 0x88, + 0x5C, 0x89, 0x0A, 0x1A, 0x59, 0x88, 0x63, 0x1A, 0x5A, 0x43, 0x6B, 0x46, + 0xDB, 0x88, 0x59, 0x1A, 0x6B, 0x46, 0x1B, 0x89, 0x18, 0x1A, 0x41, 0x43, + 0x50, 0x1A, 0x00, 0x28, 0x01, 0xDD, 0x01, 0x20, 0x1E, 0xBD, 0x00, 0x20, + 0x1E, 0xBD, 0x00, 0x00, 0xF0, 0xB5, 0x1D, 0x4D, 0x07, 0x46, 0x68, 0x68, + 0x85, 0xB0, 0x84, 0x6A, 0x0E, 0x46, 0x00, 0x2C, 0x26, 0xD0, 0x01, 0xAA, + 0x02, 0xA9, 0x03, 0xA8, 0x6B, 0x46, 0xA0, 0x47, 0x00, 0x28, 0x1F, 0xD0, + 0x6B, 0x46, 0x70, 0x00, 0x15, 0x49, 0x6C, 0x68, 0x09, 0x5A, 0x18, 0x7B, + 0x1D, 0x79, 0x1E, 0x78, 0x40, 0x1E, 0x1B, 0x7A, 0x6D, 0x1E, 0x76, 0x1C, + 0x84, 0x46, 0x5B, 0x1C, 0x16, 0xE0, 0x88, 0x04, 0xE2, 0x7E, 0x40, 0x0E, + 0x49, 0x06, 0x49, 0x0E, 0x42, 0x43, 0x52, 0x18, 0x52, 0x00, 0xD2, 0x19, + 0xA8, 0x42, 0x05, 0xDB, 0xB0, 0x42, 0x03, 0xDC, 0x61, 0x45, 0x01, 0xDB, + 0x99, 0x42, 0x02, 0xDD, 0x00, 0x20, 0x05, 0xB0, 0xF0, 0xBD, 0x10, 0x88, + 0x81, 0x04, 0x89, 0x0C, 0x04, 0x48, 0x81, 0x42, 0xE5, 0xD1, 0x01, 0x20, + 0xF5, 0xE7, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x20, 0x88, 0x08, 0x00, 0x20, + 0xFF, 0x3F, 0x00, 0x00, 0xFF, 0xB5, 0x93, 0xB0, 0x00, 0x20, 0x09, 0x90, + 0x44, 0xE1, 0x0E, 0x21, 0x48, 0x43, 0xBB, 0x4A, 0x12, 0x90, 0x80, 0x18, + 0x11, 0x90, 0x80, 0x7A, 0x14, 0x23, 0x01, 0x07, 0x09, 0x0F, 0x10, 0x91, + 0x59, 0x43, 0x13, 0x46, 0xC8, 0x3B, 0xC9, 0x18, 0x0F, 0x91, 0x89, 0x89, + 0x00, 0x09, 0x08, 0x91, 0x0E, 0x90, 0x14, 0x21, 0x48, 0x43, 0xC5, 0x18, + 0x0C, 0x20, 0x28, 0x5E, 0x08, 0x99, 0x88, 0x42, 0x01, 0xDA, 0xA8, 0x89, + 0x08, 0x90, 0x64, 0x68, 0xE0, 0x7A, 0x40, 0x09, 0x7E, 0xD1, 0x11, 0x99, + 0x08, 0x73, 0x0D, 0x90, 0xE0, 0x7A, 0x0C, 0x90, 0x00, 0x07, 0x51, 0xD5, + 0x15, 0x98, 0x00, 0x28, 0x4E, 0xD0, 0x00, 0x27, 0x07, 0x97, 0x3E, 0x46, + 0x06, 0x97, 0x43, 0xE0, 0x28, 0x20, 0x15, 0x99, 0x70, 0x43, 0x40, 0x18, + 0x0B, 0x90, 0x40, 0x78, 0x00, 0x28, 0x39, 0xD0, 0x0B, 0x98, 0xE1, 0x7E, + 0x00, 0x8C, 0x48, 0x43, 0xA1, 0x8B, 0xFC, 0xF7, 0x12, 0xFD, 0xC0, 0xB2, + 0x05, 0x90, 0x0B, 0x98, 0xA1, 0x7E, 0x40, 0x8C, 0x48, 0x43, 0xE1, 0x8B, + 0xFC, 0xF7, 0x09, 0xFD, 0xC0, 0xB2, 0x00, 0x2F, 0x0F, 0xD1, 0x0F, 0x99, + 0x05, 0x9B, 0x09, 0x7C, 0x0A, 0x09, 0x9A, 0x1A, 0x52, 0x1C, 0x02, 0x2A, + 0x07, 0xD8, 0x09, 0x07, 0x09, 0x0F, 0x41, 0x1A, 0x49, 0x1C, 0x02, 0x29, + 0x01, 0xD8, 0x01, 0x27, 0x13, 0xE0, 0x07, 0x99, 0x00, 0x29, 0x0E, 0xD1, + 0x29, 0x7C, 0x05, 0x9B, 0x0A, 0x09, 0x9A, 0x1A, 0x52, 0x1C, 0x02, 0x2A, + 0x07, 0xD8, 0x09, 0x07, 0x09, 0x0F, 0x40, 0x1A, 0x40, 0x1C, 0x02, 0x28, + 0x01, 0xD8, 0x01, 0x20, 0x07, 0x90, 0x00, 0x2F, 0x02, 0xD0, 0x07, 0x98, + 0x00, 0x28, 0x7E, 0xD1, 0x76, 0x1C, 0xF6, 0xB2, 0x16, 0x98, 0x86, 0x42, + 0xB8, 0xD3, 0x06, 0x98, 0x00, 0x28, 0xF6, 0xD1, 0x0C, 0x98, 0xC0, 0x06, + 0x74, 0xD5, 0x15, 0x98, 0x00, 0x28, 0x71, 0xD0, 0x0F, 0x98, 0x69, 0x7C, + 0x43, 0x7C, 0x0E, 0x07, 0x18, 0x07, 0x00, 0x0F, 0x36, 0x0F, 0xB0, 0x42, + 0x00, 0xD3, 0x30, 0x46, 0x07, 0x90, 0x18, 0x09, 0x09, 0x09, 0x88, 0x42, + 0x00, 0xD8, 0x08, 0x46, 0x06, 0x90, 0x0F, 0x98, 0xA9, 0x7C, 0x83, 0x7C, + 0x0E, 0x07, 0x18, 0x07, 0x00, 0x0F, 0x36, 0x0F, 0xB0, 0x42, 0x00, 0xD3, + 0x30, 0x46, 0x05, 0x90, 0x18, 0x09, 0x09, 0x09, 0x88, 0x42, 0x00, 0xE0, + 0x9B, 0xE0, 0x00, 0xD8, 0x08, 0x46, 0x04, 0x90, 0x00, 0x20, 0x6B, 0xE0, + 0x60, 0x46, 0x28, 0x21, 0x48, 0x43, 0x15, 0x99, 0x00, 0x22, 0x41, 0x18, + 0x48, 0x78, 0x00, 0x28, 0x5F, 0xD0, 0x20, 0x31, 0x48, 0x79, 0x89, 0x79, + 0x07, 0x09, 0x0B, 0x09, 0x00, 0x07, 0x09, 0x07, 0x00, 0x0F, 0x09, 0x0F, + 0x0A, 0x93, 0x3E, 0x1A, 0x5B, 0x1A, 0x76, 0x1C, 0x5B, 0x1C, 0x5E, 0x43, + 0xE3, 0x79, 0xB6, 0xB2, 0xB3, 0x42, 0x4C, 0xD8, 0x07, 0x9B, 0x98, 0x42, + 0x00, 0xD3, 0x03, 0x46, 0x06, 0x98, 0x87, 0x42, 0x00, 0xD8, 0x38, 0x46, + 0x02, 0x90, 0x05, 0x98, 0x81, 0x42, 0x00, 0xD3, 0x08, 0x46, 0x03, 0x90, + 0x0A, 0x99, 0x04, 0x98, 0x81, 0x42, 0x00, 0xD8, 0x08, 0x46, 0x19, 0x46, + 0x01, 0x90, 0x1F, 0xE0, 0x03, 0x98, 0x15, 0xE0, 0xE3, 0x7E, 0x13, 0x9E, + 0x4B, 0x43, 0x1B, 0x18, 0x5B, 0x00, 0xF3, 0x5A, 0x9E, 0x0B, 0x0B, 0xD0, + 0x9E, 0x04, 0x10, 0x9F, 0x76, 0x0E, 0xBE, 0x42, 0x04, 0xD0, 0x5B, 0x06, + 0x0E, 0x9E, 0x5B, 0x0E, 0xB3, 0x42, 0x01, 0xD1, 0x52, 0x1C, 0x92, 0xB2, + 0x40, 0x1C, 0xC0, 0xB2, 0x01, 0xE0, 0x4D, 0xE0, 0x25, 0xE0, 0x01, 0x9B, + 0x98, 0x42, 0xE3, 0xD9, 0x49, 0x1C, 0xC9, 0xB2, 0x02, 0x98, 0x81, 0x42, + 0xDC, 0xD9, 0x00, 0x2A, 0x11, 0xD0, 0x0F, 0x99, 0xEB, 0x89, 0xC9, 0x89, + 0x3B, 0x48, 0xC9, 0x18, 0x12, 0x9B, 0xC0, 0x5A, 0x08, 0x18, 0x80, 0xB2, + 0x41, 0x00, 0x40, 0x18, 0x80, 0x08, 0x90, 0x42, 0x03, 0xD2, 0x11, 0x99, + 0x01, 0x20, 0x08, 0x73, 0x30, 0xE0, 0x60, 0x46, 0x40, 0x1C, 0xC0, 0xB2, + 0x16, 0x99, 0x84, 0x46, 0x88, 0x42, 0x8F, 0xD3, 0x0D, 0x98, 0x01, 0x28, + 0x26, 0xD0, 0x0C, 0x98, 0x40, 0x07, 0x0B, 0xD5, 0xA0, 0x7A, 0x21, 0x79, + 0x14, 0x9A, 0x88, 0x40, 0x11, 0x99, 0x49, 0x88, 0x49, 0x00, 0x51, 0x5E, + 0x08, 0x9A, 0x51, 0x1A, 0x88, 0x42, 0xE2, 0xDC, 0x0C, 0x98, 0x80, 0x07, + 0x14, 0xD5, 0x28, 0x7C, 0x22, 0x7B, 0x01, 0x09, 0x00, 0x07, 0x00, 0x0F, + 0x6B, 0x46, 0x07, 0xC3, 0x0F, 0x98, 0x14, 0x99, 0x00, 0x7C, 0x02, 0x07, + 0x03, 0x09, 0x12, 0x0F, 0x13, 0x98, 0xFE, 0xF7, 0x87, 0xFE, 0x00, 0x28, + 0x02, 0xD0, 0x11, 0x98, 0x01, 0x21, 0x01, 0x73, 0x09, 0x98, 0x40, 0x1C, + 0xC0, 0xB2, 0x09, 0x90, 0x1A, 0x4C, 0x63, 0x78, 0x98, 0x42, 0x00, 0xD2, + 0xB5, 0xE6, 0x00, 0x20, 0x28, 0xE0, 0x0E, 0x21, 0x15, 0x4A, 0x41, 0x43, + 0x89, 0x18, 0x0A, 0x7B, 0x00, 0x2A, 0x1F, 0xD0, 0x8D, 0x7A, 0x12, 0x4F, + 0x2A, 0x07, 0xC8, 0x3F, 0x12, 0x0F, 0x14, 0x24, 0x2D, 0x09, 0x14, 0x26, + 0x62, 0x43, 0x75, 0x43, 0xD4, 0x19, 0x0C, 0x22, 0xED, 0x19, 0x0C, 0x26, + 0xA2, 0x5E, 0xAE, 0x5F, 0x49, 0x88, 0xB2, 0x42, 0x06, 0xDD, 0x14, 0x9A, + 0x49, 0x00, 0x51, 0x5E, 0xB1, 0x42, 0x07, 0xDD, 0xA9, 0x81, 0x05, 0xE0, + 0x4D, 0x00, 0x14, 0x99, 0x49, 0x5F, 0x91, 0x42, 0x00, 0xDD, 0xA1, 0x81, + 0x40, 0x1C, 0xC0, 0xB2, 0x98, 0x42, 0xD4, 0xD3, 0x17, 0xB0, 0xF0, 0xBD, + 0x8C, 0x09, 0x00, 0x20, 0x2C, 0x00, 0x00, 0x20, 0xFF, 0xB5, 0x82, 0xB0, + 0x6B, 0x46, 0x18, 0x89, 0x99, 0x89, 0x04, 0x46, 0x01, 0x91, 0x88, 0x42, + 0x00, 0xD8, 0x0C, 0x46, 0x6B, 0x46, 0x19, 0x8A, 0x9B, 0x8A, 0x0A, 0x46, + 0x00, 0x93, 0x99, 0x42, 0x00, 0xD3, 0x1A, 0x46, 0x94, 0x42, 0x4C, 0xD3, + 0x6B, 0x46, 0x5A, 0x89, 0xDB, 0x89, 0x15, 0x46, 0x9E, 0x46, 0x9A, 0x42, + 0x00, 0xD8, 0x75, 0x46, 0x6B, 0x46, 0x5C, 0x8A, 0xDB, 0x8A, 0x26, 0x46, + 0x9C, 0x46, 0x9C, 0x42, 0x00, 0xD3, 0x66, 0x46, 0xB5, 0x42, 0x3A, 0xD3, + 0x01, 0x9D, 0x03, 0x46, 0xA8, 0x42, 0x00, 0xD3, 0x2B, 0x46, 0x00, 0x9F, + 0x0E, 0x46, 0xB9, 0x42, 0x00, 0xD8, 0x3E, 0x46, 0xB3, 0x42, 0x2E, 0xD8, + 0x13, 0x46, 0x72, 0x45, 0x00, 0xD3, 0x73, 0x46, 0x25, 0x46, 0x64, 0x45, + 0x00, 0xD8, 0x65, 0x46, 0xAB, 0x42, 0x24, 0xD8, 0x65, 0x46, 0x2E, 0x1B, + 0x43, 0x1A, 0x15, 0x1B, 0x7F, 0x1A, 0x73, 0x43, 0x7D, 0x43, 0x5B, 0x1B, + 0x01, 0x9D, 0x6D, 0x1A, 0x75, 0x43, 0x76, 0x46, 0x36, 0x1B, 0x77, 0x43, + 0xED, 0x1B, 0x6B, 0x43, 0x00, 0x2B, 0x12, 0xDC, 0x0D, 0x1A, 0x01, 0x9B, + 0x71, 0x46, 0x89, 0x1A, 0xA4, 0x1A, 0x1B, 0x1A, 0x4D, 0x43, 0x5C, 0x43, + 0x2C, 0x1B, 0x00, 0x9D, 0x28, 0x1A, 0x48, 0x43, 0x61, 0x46, 0x89, 0x1A, + 0x59, 0x43, 0x40, 0x1A, 0x44, 0x43, 0x00, 0x2C, 0x02, 0xDD, 0x00, 0x20, + 0x06, 0xB0, 0xF0, 0xBD, 0x01, 0x20, 0xFB, 0xE7, 0xF7, 0xB5, 0x84, 0xB0, + 0x68, 0x46, 0x40, 0x8B, 0x00, 0x90, 0x68, 0x46, 0x00, 0x8B, 0x01, 0x90, + 0x68, 0x46, 0xC5, 0x8A, 0x84, 0x8A, 0x29, 0x46, 0x20, 0x46, 0x00, 0x9B, + 0x01, 0x9A, 0xFE, 0xF7, 0x3D, 0xFB, 0x02, 0x90, 0x68, 0x46, 0x47, 0x8A, + 0x06, 0x8A, 0x2B, 0x46, 0x22, 0x46, 0x39, 0x46, 0x30, 0x46, 0xFE, 0xF7, + 0x33, 0xFB, 0x05, 0x46, 0x39, 0x46, 0x30, 0x46, 0x00, 0x9B, 0x01, 0x9A, + 0xFE, 0xF7, 0x2C, 0xFB, 0x04, 0x46, 0x00, 0x2D, 0x1F, 0xD0, 0x00, 0x2C, + 0x1F, 0xD0, 0x02, 0x98, 0x29, 0x46, 0x40, 0x43, 0x69, 0x43, 0x41, 0x1A, + 0x20, 0x46, 0x60, 0x43, 0x08, 0x1A, 0x29, 0x46, 0xC0, 0x01, 0x61, 0x43, + 0xFC, 0xF7, 0x45, 0xFB, 0xFF, 0x21, 0xC9, 0x43, 0x88, 0x42, 0x02, 0xDB, + 0x49, 0x42, 0x88, 0x42, 0x00, 0xDD, 0x08, 0x46, 0xFF, 0x30, 0x01, 0x30, + 0x50, 0x35, 0x45, 0x43, 0x68, 0x12, 0x50, 0x30, 0x84, 0x42, 0x05, 0xDC, + 0x01, 0xE0, 0x50, 0x28, 0x02, 0xDA, 0x01, 0x20, 0x07, 0xB0, 0xF0, 0xBD, + 0x00, 0x20, 0xFB, 0xE7, 0xF0, 0xB5, 0x18, 0x4A, 0xBC, 0x23, 0x9D, 0x58, + 0x20, 0x32, 0x94, 0x7B, 0x00, 0x29, 0x12, 0xD0, 0x14, 0x4E, 0x00, 0x23, + 0xB6, 0x8D, 0x0B, 0xE0, 0xC7, 0x5C, 0xB7, 0x42, 0x06, 0xD1, 0x28, 0x7D, + 0x50, 0x72, 0x7F, 0x2C, 0x01, 0xD2, 0x64, 0x1C, 0x94, 0x73, 0xF0, 0xBD, + 0x5B, 0x1C, 0xDB, 0xB2, 0x8B, 0x42, 0xF1, 0xD3, 0xF0, 0xBD, 0xE8, 0x7C, + 0x00, 0x21, 0x84, 0x42, 0x01, 0xD2, 0x11, 0x72, 0xF0, 0xBD, 0x50, 0x7A, + 0x01, 0x28, 0xFA, 0xD9, 0x80, 0x21, 0x0C, 0x43, 0x40, 0x1E, 0xC0, 0xB2, + 0x94, 0x73, 0x50, 0x72, 0x01, 0x28, 0xF3, 0xD1, 0x10, 0x7A, 0x80, 0x08, + 0x80, 0x00, 0x10, 0x72, 0xF0, 0xBD, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, + 0xF1, 0xB5, 0x86, 0xB0, 0x00, 0x25, 0x96, 0xE0, 0x00, 0x20, 0x01, 0x90, + 0x28, 0x46, 0x14, 0x21, 0x48, 0x43, 0x4C, 0x4E, 0x05, 0x90, 0x84, 0x19, + 0xE0, 0x7C, 0x01, 0x07, 0x7E, 0xD1, 0x00, 0x07, 0x00, 0x0F, 0x10, 0x30, + 0xE0, 0x74, 0x02, 0xAA, 0x29, 0x46, 0x01, 0xAB, 0x06, 0x98, 0xFE, 0xF7, + 0x89, 0xFC, 0x6B, 0x46, 0x18, 0x79, 0x01, 0x21, 0x84, 0x46, 0x66, 0xE0, + 0x02, 0xA8, 0x47, 0x5C, 0x40, 0x4A, 0x14, 0x20, 0x47, 0x43, 0xB8, 0x18, + 0xE3, 0x89, 0xC6, 0x89, 0x9B, 0x19, 0xE3, 0x81, 0x63, 0x68, 0x46, 0x68, + 0x9B, 0x19, 0x63, 0x60, 0xA3, 0x68, 0x86, 0x68, 0x9B, 0x19, 0xA3, 0x60, + 0x05, 0x9B, 0xD7, 0x59, 0xD3, 0x58, 0x05, 0x9E, 0xDB, 0x19, 0x93, 0x51, + 0x66, 0x7C, 0x43, 0x7C, 0x32, 0x07, 0x1B, 0x07, 0x12, 0x0F, 0x1B, 0x0F, + 0x9A, 0x42, 0x00, 0xD3, 0x1A, 0x46, 0x33, 0x09, 0x1B, 0x01, 0x1A, 0x43, + 0x62, 0x74, 0x43, 0x7C, 0xD6, 0xB2, 0x32, 0x09, 0x1B, 0x09, 0x9A, 0x42, + 0x00, 0xD8, 0x1A, 0x46, 0x33, 0x07, 0x12, 0x01, 0x1B, 0x0F, 0x1A, 0x43, + 0x62, 0x74, 0xA6, 0x7C, 0x83, 0x7C, 0x32, 0x07, 0x1B, 0x07, 0x12, 0x0F, + 0x1B, 0x0F, 0x9A, 0x42, 0x00, 0xD3, 0x1A, 0x46, 0x33, 0x09, 0x1B, 0x01, + 0x1A, 0x43, 0xA2, 0x74, 0x83, 0x7C, 0xD6, 0xB2, 0x32, 0x09, 0x1B, 0x09, + 0x9A, 0x42, 0x00, 0xD8, 0x1A, 0x46, 0x33, 0x07, 0x12, 0x01, 0x1B, 0x0F, + 0x1A, 0x43, 0xA2, 0x74, 0x0C, 0x23, 0x0C, 0x22, 0xE3, 0x5E, 0x82, 0x5E, + 0x93, 0x42, 0x10, 0xDA, 0xA2, 0x81, 0x22, 0x7C, 0x03, 0x7C, 0x12, 0x07, + 0x1B, 0x09, 0x12, 0x0F, 0x1B, 0x01, 0x1A, 0x43, 0x22, 0x74, 0xD2, 0xB2, + 0x03, 0x7C, 0x12, 0x09, 0x12, 0x01, 0x1B, 0x07, 0x1B, 0x0F, 0x1A, 0x43, + 0x22, 0x74, 0xC2, 0x7C, 0x12, 0x07, 0x12, 0x0F, 0x49, 0x1C, 0xC2, 0x74, + 0xC9, 0xB2, 0x61, 0x45, 0x96, 0xD3, 0x0E, 0x48, 0x0C, 0x21, 0x40, 0x68, + 0x61, 0x5E, 0x02, 0x8B, 0x91, 0x42, 0x00, 0xE0, 0x09, 0xE0, 0x04, 0xDB, + 0x0E, 0x21, 0x61, 0x5E, 0x40, 0x79, 0x81, 0x42, 0x03, 0xDA, 0xE0, 0x7C, + 0x00, 0x07, 0x00, 0x0F, 0xE0, 0x74, 0x6D, 0x1C, 0xED, 0xB2, 0x04, 0x48, + 0x00, 0x78, 0x85, 0x42, 0x00, 0xD2, 0x63, 0xE7, 0x07, 0xB0, 0xF0, 0xBD, + 0xC4, 0x08, 0x00, 0x20, 0x2C, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x9D, 0xB0, + 0xFC, 0x48, 0x1C, 0x90, 0xC0, 0x6B, 0xFB, 0x4C, 0x05, 0x79, 0xC1, 0x78, + 0x80, 0x3C, 0x09, 0x94, 0x16, 0x91, 0xE0, 0x34, 0xE1, 0x79, 0x08, 0x91, + 0x40, 0x7B, 0x00, 0x26, 0x00, 0x28, 0x0D, 0xD1, 0x16, 0x98, 0x00, 0x21, + 0x45, 0x43, 0x20, 0x46, 0xE0, 0x38, 0x6A, 0x00, 0x40, 0x6D, 0xFF, 0xF7, + 0xAD, 0xF8, 0x26, 0x71, 0x26, 0x72, 0x66, 0x72, 0x1D, 0xB0, 0xF0, 0xBD, + 0xED, 0x48, 0xA0, 0x30, 0x1B, 0x90, 0x00, 0x7C, 0x00, 0x28, 0x02, 0xD1, + 0x16, 0x98, 0x40, 0x1C, 0x02, 0xE0, 0x1B, 0x98, 0x00, 0x7D, 0x80, 0x1C, + 0xC0, 0xB2, 0x02, 0xF0, 0x5F, 0xF8, 0x01, 0x21, 0x00, 0x20, 0x02, 0xF0, + 0xBD, 0xFA, 0xE5, 0x48, 0x81, 0x8A, 0x6B, 0x46, 0x99, 0x87, 0xE4, 0x49, + 0x8A, 0x7C, 0xDA, 0x87, 0xC2, 0x88, 0x10, 0xAB, 0x1A, 0x80, 0xC2, 0x89, + 0x5A, 0x80, 0x4A, 0x7C, 0xDA, 0x80, 0x0A, 0x7C, 0x1A, 0x81, 0x11, 0x22, + 0x4A, 0x74, 0x13, 0x22, 0x0A, 0x74, 0xDD, 0x4A, 0x42, 0x80, 0x08, 0x22, + 0xC2, 0x80, 0x00, 0x22, 0xC2, 0x81, 0xA3, 0x20, 0x88, 0x74, 0xD6, 0x49, + 0x22, 0x79, 0x80, 0x39, 0xC8, 0x1D, 0xF9, 0x30, 0xC0, 0x31, 0x19, 0x91, + 0x1A, 0x90, 0x00, 0x2A, 0x22, 0xD1, 0x08, 0x6B, 0x1A, 0x9A, 0x06, 0x78, + 0x08, 0x46, 0xC0, 0x38, 0x41, 0x6D, 0xA8, 0x00, 0x0B, 0x18, 0x68, 0x00, + 0xD2, 0x68, 0x08, 0x18, 0x00, 0x92, 0x02, 0x46, 0x30, 0x46, 0x01, 0xF0, + 0x11, 0xF8, 0x19, 0x99, 0x1E, 0x28, 0x89, 0x6B, 0x08, 0x80, 0x0D, 0xD2, + 0x00, 0x20, 0x20, 0x72, 0x60, 0x72, 0x1A, 0x99, 0x48, 0x60, 0x1C, 0x98, + 0x31, 0x02, 0xC0, 0x6B, 0x20, 0x30, 0x80, 0x78, 0x01, 0x43, 0xC2, 0x48, + 0x01, 0x81, 0x5D, 0xE1, 0x00, 0x20, 0x0B, 0x90, 0x0A, 0x90, 0x02, 0x90, + 0xBD, 0x48, 0xA9, 0x00, 0x80, 0x38, 0x40, 0x6D, 0x13, 0x90, 0x41, 0x18, + 0x15, 0x91, 0x69, 0x00, 0x41, 0x18, 0x00, 0x20, 0x14, 0x91, 0x0C, 0x90, + 0x60, 0x79, 0xBB, 0x4F, 0x00, 0x28, 0x08, 0xD0, 0xA1, 0x79, 0x00, 0x29, + 0x05, 0xD0, 0x1A, 0x98, 0x40, 0x68, 0xFC, 0xF7, 0xB2, 0xF9, 0xC8, 0xB2, + 0x0C, 0x90, 0x08, 0x99, 0x0C, 0x98, 0x19, 0x9E, 0x48, 0x43, 0x0E, 0x90, + 0x31, 0x6B, 0x08, 0x18, 0x00, 0x25, 0x0D, 0x90, 0x74, 0xE0, 0x09, 0x99, + 0x0D, 0x98, 0xFF, 0x31, 0x01, 0x31, 0xCA, 0x68, 0x40, 0x5D, 0x00, 0x92, + 0x13, 0xA9, 0x0E, 0xC9, 0x00, 0xF0, 0xCC, 0xFF, 0x6B, 0x00, 0x03, 0xA9, + 0xC8, 0x52, 0x0E, 0x98, 0xF1, 0x6B, 0x40, 0x00, 0xC2, 0x18, 0x88, 0x5E, + 0x9C, 0x46, 0x86, 0x46, 0x03, 0xA8, 0xC0, 0x5A, 0x88, 0x52, 0x03, 0xA8, + 0xC0, 0x5E, 0x71, 0x46, 0x41, 0x1A, 0x00, 0xD5, 0x49, 0x42, 0x40, 0x18, + 0x00, 0xB2, 0x63, 0x46, 0x03, 0xA9, 0xC8, 0x52, 0xB1, 0x6B, 0x89, 0x5A, + 0x43, 0x1A, 0x19, 0x2B, 0x07, 0xDD, 0x43, 0x00, 0xC0, 0x18, 0x08, 0x18, + 0x80, 0x10, 0x63, 0x46, 0x03, 0xA9, 0xC8, 0x52, 0x06, 0xE0, 0x4B, 0x00, + 0xC9, 0x18, 0x08, 0x18, 0x03, 0xAB, 0x80, 0x10, 0x61, 0x46, 0x58, 0x52, + 0x60, 0x46, 0x03, 0xAB, 0xB1, 0x6B, 0x18, 0x5A, 0x88, 0x52, 0x60, 0x46, + 0x18, 0x5E, 0xB8, 0x42, 0x01, 0xDA, 0x07, 0x46, 0x0B, 0x95, 0x02, 0x99, + 0x88, 0x42, 0x01, 0xDD, 0x0A, 0x95, 0x02, 0x90, 0x28, 0x2F, 0x1D, 0xDA, + 0x20, 0x79, 0x00, 0x28, 0x1A, 0xD1, 0x20, 0x7A, 0xA8, 0x42, 0x17, 0xD1, + 0x60, 0x7A, 0x0C, 0x99, 0x88, 0x42, 0x13, 0xD1, 0x09, 0x98, 0x6B, 0x46, + 0xFF, 0x30, 0x01, 0x30, 0x41, 0x68, 0x49, 0x1E, 0x41, 0x60, 0x25, 0x72, + 0x0C, 0x99, 0x61, 0x72, 0x0C, 0x20, 0x18, 0x5E, 0x1E, 0x28, 0x04, 0xDA, + 0x20, 0x79, 0x00, 0x28, 0x01, 0xD1, 0x00, 0x21, 0x21, 0x72, 0x98, 0xE0, + 0x19, 0x98, 0x40, 0x68, 0x80, 0x7A, 0xCA, 0x28, 0xF9, 0xD0, 0x60, 0x79, + 0x00, 0x28, 0x03, 0xD1, 0x25, 0x72, 0x00, 0x21, 0x61, 0x72, 0x8C, 0xE0, + 0x6D, 0x1C, 0xED, 0xB2, 0x08, 0x98, 0x85, 0x42, 0x87, 0xD3, 0x04, 0x28, + 0x1A, 0xD1, 0x0A, 0x98, 0x03, 0x28, 0x0A, 0xD1, 0x6B, 0x46, 0x0E, 0x20, + 0x0C, 0x21, 0x18, 0x5E, 0x59, 0x5E, 0x88, 0x42, 0x01, 0xDA, 0x01, 0x20, + 0x0D, 0xE0, 0x00, 0x20, 0x0B, 0xE0, 0x00, 0x28, 0x0A, 0xD1, 0x6B, 0x46, + 0x10, 0x20, 0x12, 0x21, 0x18, 0x5E, 0x59, 0x5E, 0x88, 0x42, 0x01, 0xDA, + 0x02, 0x20, 0x00, 0xE0, 0x03, 0x20, 0x0B, 0x90, 0xF1, 0x6A, 0x0C, 0x9A, + 0x0B, 0x98, 0x88, 0x54, 0x60, 0x7A, 0x07, 0x90, 0x18, 0x90, 0x20, 0x7A, + 0x17, 0x90, 0x06, 0x90, 0xA2, 0x79, 0x60, 0x4F, 0x00, 0x20, 0x94, 0x46, + 0x0C, 0x99, 0x10, 0xE0, 0xF2, 0x6A, 0x12, 0x5C, 0xFF, 0x2A, 0x0A, 0xD0, + 0x08, 0x9B, 0x52, 0x00, 0x43, 0x43, 0x5B, 0x00, 0x9A, 0x18, 0xB3, 0x6B, + 0x9D, 0x5A, 0xBD, 0x42, 0x01, 0xDA, 0x9F, 0x5E, 0x01, 0x46, 0x40, 0x1C, + 0xC0, 0xB2, 0x84, 0x45, 0xEC, 0xD8, 0x54, 0x48, 0x87, 0x42, 0x03, 0xD0, + 0x07, 0x91, 0xF0, 0x6A, 0x40, 0x5C, 0x06, 0x90, 0x09, 0x98, 0xFF, 0x30, + 0x01, 0x30, 0x82, 0x68, 0x94, 0x46, 0x00, 0x2A, 0x09, 0xD1, 0xA1, 0x72, + 0xF2, 0x6A, 0x53, 0x5C, 0xE3, 0x72, 0x61, 0x72, 0x52, 0x5C, 0x22, 0x72, + 0x01, 0x21, 0x81, 0x60, 0x2F, 0xE0, 0x17, 0x9A, 0x06, 0x99, 0x8A, 0x42, + 0x03, 0xD1, 0x18, 0x9A, 0x07, 0x99, 0x8A, 0x42, 0x1C, 0xD0, 0x08, 0x9A, + 0x18, 0x99, 0x08, 0x9B, 0x51, 0x43, 0x4A, 0x00, 0x17, 0x99, 0xB5, 0x6B, + 0x49, 0x00, 0x51, 0x18, 0x07, 0x9A, 0x69, 0x5A, 0x5A, 0x43, 0x06, 0x9B, + 0x52, 0x00, 0x5B, 0x00, 0xD2, 0x18, 0xAA, 0x5A, 0x1E, 0x32, 0x91, 0x42, + 0x61, 0x46, 0x09, 0xD9, 0x49, 0x1C, 0x81, 0x60, 0x06, 0x29, 0x0A, 0xD3, + 0x06, 0x9A, 0x22, 0x72, 0x07, 0x9A, 0x62, 0x72, 0x01, 0x21, 0x03, 0xE0, + 0x01, 0x29, 0x02, 0xD9, 0x61, 0x46, 0x49, 0x1E, 0x81, 0x60, 0x06, 0x99, + 0xE1, 0x72, 0x07, 0x99, 0xA1, 0x72, 0x02, 0x98, 0x50, 0x28, 0x0C, 0xDD, + 0x1E, 0x20, 0x20, 0x71, 0x02, 0x99, 0xFF, 0x22, 0xC9, 0x19, 0x5F, 0x32, + 0x91, 0x42, 0x19, 0xDD, 0x09, 0x99, 0xFF, 0x31, 0x01, 0x31, 0x48, 0x80, + 0x14, 0xE0, 0x09, 0x98, 0xFF, 0x30, 0x01, 0x30, 0x41, 0x88, 0x00, 0x29, + 0x01, 0xD0, 0x49, 0x1E, 0x41, 0x80, 0x02, 0x99, 0x1E, 0x29, 0x09, 0xDA, + 0x21, 0x79, 0x00, 0x29, 0x06, 0xD0, 0x49, 0x1E, 0x09, 0x06, 0x09, 0x0E, + 0x21, 0x71, 0x01, 0xD1, 0x00, 0x69, 0x80, 0x47, 0xA7, 0x82, 0x02, 0x98, + 0xE0, 0x82, 0x60, 0x7A, 0x08, 0x99, 0x32, 0x6B, 0x48, 0x43, 0x21, 0x7A, + 0x10, 0x18, 0x40, 0x5C, 0x1C, 0x99, 0x00, 0x02, 0xC9, 0x6B, 0x20, 0x31, + 0x89, 0x78, 0x08, 0x43, 0x12, 0x49, 0x08, 0x81, 0x6B, 0x46, 0x11, 0x49, + 0x98, 0x8F, 0x88, 0x82, 0x10, 0x48, 0xDA, 0x8F, 0x82, 0x74, 0x10, 0xAB, + 0x1A, 0x88, 0xCA, 0x80, 0x5A, 0x88, 0xCA, 0x81, 0xDA, 0x88, 0x42, 0x74, + 0x1A, 0x89, 0x02, 0x74, 0x0D, 0x4A, 0x4A, 0x80, 0x81, 0x7C, 0x49, 0x06, + 0x49, 0x0E, 0x81, 0x74, 0x09, 0x9C, 0xFF, 0x34, 0x01, 0x34, 0xE0, 0x68, + 0x80, 0x47, 0x1B, 0x98, 0x00, 0x7C, 0x00, 0x28, 0x0E, 0xD1, 0x16, 0x98, + 0x10, 0xE0, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, + 0xE0, 0x12, 0x00, 0x40, 0x82, 0x11, 0x00, 0x00, 0xFF, 0x7F, 0x00, 0x00, + 0x82, 0x10, 0x00, 0x00, 0x1B, 0x98, 0x00, 0x7D, 0x40, 0x1C, 0xC0, 0xB2, + 0x01, 0xF0, 0x80, 0xFE, 0x60, 0x68, 0x40, 0x1C, 0x60, 0x60, 0x0B, 0xE6, + 0xFE, 0xB5, 0x07, 0x46, 0x01, 0xF0, 0x90, 0xFE, 0x00, 0x20, 0x02, 0xF0, + 0x83, 0xF8, 0x02, 0xF0, 0xE3, 0xFA, 0x43, 0x49, 0x38, 0x46, 0xFC, 0xF7, + 0xBF, 0xFE, 0x0A, 0x20, 0x02, 0xF0, 0x4E, 0xF9, 0x00, 0x25, 0x2C, 0x46, + 0x00, 0xF0, 0x88, 0xF8, 0x40, 0x19, 0x64, 0x1C, 0xA4, 0xB2, 0x85, 0xB2, + 0x08, 0x2C, 0xF7, 0xD3, 0xED, 0x08, 0xBD, 0x71, 0x28, 0x0A, 0xF8, 0x71, + 0x28, 0x46, 0x23, 0x30, 0xC0, 0x08, 0x38, 0x72, 0x28, 0x46, 0x23, 0x38, + 0xC0, 0x10, 0x78, 0x72, 0x7D, 0x21, 0x34, 0x4A, 0xC9, 0x00, 0x38, 0x1D, + 0xFD, 0xF7, 0xC2, 0xFE, 0x14, 0x20, 0x02, 0xF0, 0x2F, 0xF9, 0x31, 0x48, + 0x00, 0x24, 0x01, 0x46, 0xE0, 0x31, 0xFF, 0x30, 0x21, 0x30, 0x26, 0x46, + 0x01, 0x91, 0x00, 0x90, 0x01, 0x99, 0x00, 0x20, 0x88, 0x70, 0x2C, 0x49, + 0x01, 0x20, 0xC8, 0x71, 0xFD, 0xF7, 0xEE, 0xFE, 0x2A, 0x49, 0x45, 0x20, + 0x08, 0x80, 0x28, 0x49, 0x10, 0x20, 0xC8, 0x71, 0x00, 0xF0, 0x54, 0xF8, + 0x01, 0x46, 0x40, 0x1B, 0x00, 0xB2, 0x76, 0x1C, 0x02, 0x46, 0x18, 0x32, + 0xB6, 0xB2, 0x30, 0x2A, 0x10, 0xD8, 0x22, 0x18, 0x14, 0xB2, 0xB2, 0x07, + 0x0C, 0xD1, 0x78, 0x2C, 0x03, 0xDD, 0x6D, 0x1C, 0xAD, 0xB2, 0x78, 0x3C, + 0x05, 0xE0, 0x96, 0x22, 0xD4, 0x42, 0x03, 0xDA, 0x6D, 0x1E, 0xAD, 0xB2, + 0x96, 0x34, 0x24, 0xB2, 0x23, 0x30, 0x46, 0x28, 0x09, 0xD8, 0x19, 0x48, + 0x86, 0x42, 0x0A, 0xD3, 0x00, 0x98, 0x02, 0x22, 0x42, 0x70, 0x17, 0x4A, + 0x01, 0x20, 0x50, 0x77, 0x0D, 0xE0, 0x00, 0x9A, 0x01, 0x20, 0x50, 0x70, + 0x09, 0xE0, 0x01, 0x98, 0x80, 0x78, 0x00, 0x28, 0xC0, 0xD0, 0x00, 0x98, + 0x03, 0x22, 0x42, 0x70, 0x01, 0x9A, 0x00, 0x20, 0x90, 0x70, 0xB9, 0x72, + 0x08, 0x0A, 0xF8, 0x72, 0x00, 0x98, 0x40, 0x78, 0x38, 0x73, 0x00, 0x99, + 0x00, 0x20, 0x88, 0x70, 0x0A, 0x20, 0x02, 0xF0, 0xD5, 0xF8, 0xFE, 0xF7, + 0x2F, 0xFF, 0x01, 0x20, 0x01, 0xF0, 0xDA, 0xFD, 0xFE, 0xBD, 0x00, 0x00, + 0xF5, 0x41, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, 0x40, + 0x00, 0x10, 0x00, 0x40, 0xC4, 0x09, 0x00, 0x00, 0x40, 0x01, 0x00, 0x20, + 0x30, 0xB5, 0x0C, 0x48, 0x0C, 0x4B, 0x82, 0x6A, 0x01, 0x20, 0x98, 0x72, + 0x09, 0x48, 0x00, 0x24, 0x60, 0x30, 0x04, 0x70, 0x09, 0x49, 0x11, 0x25, + 0x8D, 0x80, 0x43, 0x25, 0x0D, 0x80, 0x00, 0xE0, 0x30, 0xBF, 0x01, 0x78, + 0x00, 0x29, 0xFB, 0xD0, 0x10, 0x68, 0x40, 0x1C, 0x00, 0x88, 0x9C, 0x72, + 0x30, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x40, + 0x00, 0x10, 0x00, 0x40, 0x70, 0xB5, 0x28, 0x48, 0x80, 0x24, 0x04, 0x72, + 0xE1, 0x05, 0x48, 0x88, 0x04, 0x22, 0x90, 0x43, 0x48, 0x80, 0x26, 0x49, + 0x24, 0x48, 0x48, 0x80, 0x25, 0x4A, 0xD0, 0x6B, 0x03, 0x46, 0x41, 0x33, + 0x5D, 0x78, 0x1E, 0x78, 0x2B, 0x02, 0x33, 0x43, 0x5B, 0xBA, 0x0B, 0x81, + 0x40, 0x30, 0x03, 0x78, 0xFF, 0x33, 0xFF, 0x33, 0x02, 0x33, 0x4B, 0x81, + 0xC3, 0x78, 0x05, 0x79, 0x1B, 0x01, 0x23, 0x43, 0x1D, 0x43, 0x1C, 0x4B, + 0x9D, 0x74, 0x23, 0x24, 0x1C, 0x74, 0x18, 0x24, 0x5C, 0x74, 0xFF, 0x23, + 0x02, 0x33, 0xCB, 0x81, 0x40, 0x79, 0xC8, 0x80, 0x10, 0x46, 0x00, 0x21, + 0x60, 0x38, 0x15, 0x4B, 0xC1, 0x75, 0x08, 0x46, 0xE0, 0x3B, 0x84, 0x00, + 0xE4, 0x18, 0x21, 0x70, 0x40, 0x1C, 0xC0, 0xB2, 0x0A, 0x28, 0xF8, 0xD3, + 0x00, 0x21, 0x20, 0x23, 0x90, 0x6A, 0x03, 0xE0, 0x10, 0xC8, 0x23, 0x70, + 0x49, 0x1C, 0xC9, 0xB2, 0xD4, 0x6B, 0x24, 0x79, 0x8C, 0x42, 0xF7, 0xD8, + 0x02, 0x20, 0x01, 0xF0, 0x85, 0xFF, 0x02, 0x20, 0x01, 0xF0, 0x60, 0xFD, + 0x05, 0x48, 0x01, 0x21, 0xA0, 0x30, 0x81, 0x70, 0x70, 0xBD, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x40, 0x83, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, + 0xC0, 0x00, 0x00, 0x20, 0xE0, 0x12, 0x00, 0x40, 0x02, 0xF0, 0xDE, 0xF9, + 0x05, 0x4C, 0x60, 0x7D, 0x00, 0x28, 0x04, 0xD0, 0x06, 0x28, 0xFA, 0xD1, + 0x02, 0xF0, 0xF8, 0xFE, 0xF7, 0xE7, 0x02, 0xF0, 0x9D, 0xFF, 0xF4, 0xE7, + 0x60, 0x00, 0x00, 0x20, 0xF7, 0xB5, 0x0C, 0x46, 0x27, 0x49, 0x00, 0x27, + 0x49, 0x68, 0x03, 0x46, 0x8A, 0x7E, 0xC9, 0x7E, 0x23, 0x4D, 0x4A, 0x43, + 0x39, 0x46, 0x03, 0xE0, 0x05, 0x80, 0x80, 0x1C, 0x49, 0x1C, 0x89, 0xB2, + 0x91, 0x42, 0xF9, 0xD3, 0x00, 0x26, 0x33, 0xE0, 0x02, 0x9A, 0x00, 0x2A, + 0x07, 0xD0, 0x92, 0x5D, 0x00, 0x2A, 0x04, 0xD1, 0xC0, 0x7E, 0x40, 0x00, + 0xC3, 0x18, 0x04, 0x19, 0x26, 0xE0, 0x00, 0x25, 0x1F, 0xE0, 0x00, 0x20, + 0x20, 0x5E, 0xC9, 0x78, 0x88, 0x42, 0x16, 0xDB, 0xFE, 0xF7, 0x34, 0xFA, + 0xC0, 0xB2, 0xB8, 0x42, 0x00, 0xD9, 0x07, 0x46, 0x13, 0x49, 0x40, 0x00, + 0x09, 0x5A, 0x10, 0x4A, 0x91, 0x42, 0x06, 0xD0, 0x1A, 0x88, 0x89, 0x04, + 0x92, 0x0B, 0x92, 0x03, 0x89, 0x0C, 0x0A, 0x43, 0x1A, 0x80, 0xF1, 0x01, + 0x0C, 0x4A, 0x29, 0x43, 0x11, 0x52, 0x9B, 0x1C, 0xA4, 0x1C, 0x6D, 0x1C, + 0xED, 0xB2, 0x08, 0x48, 0x41, 0x68, 0xC8, 0x7E, 0xA8, 0x42, 0xDA, 0xD8, + 0x76, 0x1C, 0xF6, 0xB2, 0x04, 0x49, 0x48, 0x68, 0x82, 0x7E, 0xB2, 0x42, + 0xC6, 0xD8, 0x38, 0x46, 0xFE, 0xBD, 0x00, 0x00, 0xFF, 0x3F, 0x00, 0x00, + 0x2C, 0x00, 0x00, 0x20, 0x88, 0x08, 0x00, 0x20, 0x01, 0x22, 0x70, 0xB5, + 0xD2, 0x02, 0x81, 0x1A, 0x12, 0x1A, 0x00, 0x2A, 0x00, 0xDD, 0x11, 0x46, + 0x8D, 0xB2, 0x09, 0x4E, 0x01, 0x21, 0x4A, 0x00, 0xB4, 0x5A, 0x23, 0x1A, + 0x00, 0x2B, 0x00, 0xDC, 0x03, 0x1B, 0x9A, 0xB2, 0xAA, 0x42, 0x04, 0xD2, + 0x49, 0x1C, 0xC9, 0xB2, 0x15, 0x46, 0x5A, 0x29, 0xF1, 0xD9, 0x49, 0x1E, + 0xC8, 0xB2, 0x70, 0xBD, 0xB2, 0x74, 0x00, 0x00, 0x10, 0xB5, 0x03, 0x48, + 0x40, 0x88, 0x00, 0x28, 0x01, 0xD0, 0x00, 0xF0, 0xED, 0xFD, 0x10, 0xBD, + 0x40, 0x01, 0x00, 0x20, 0x70, 0x47, 0x00, 0x00, 0x70, 0xB5, 0x17, 0x49, + 0x08, 0x7D, 0x0C, 0x46, 0x83, 0x07, 0x20, 0x3C, 0xBC, 0x20, 0x00, 0x59, + 0x00, 0x25, 0xA2, 0x79, 0x20, 0x30, 0x00, 0x2B, 0x02, 0xDB, 0x0B, 0x7A, + 0xDB, 0x09, 0x0B, 0xD0, 0xA5, 0x80, 0xE5, 0x70, 0xC3, 0x79, 0x9A, 0x42, + 0x05, 0xD1, 0x00, 0x7A, 0x98, 0x42, 0x02, 0xD0, 0xA0, 0x71, 0x01, 0x20, + 0x88, 0x74, 0x70, 0xBD, 0xE1, 0x78, 0x0A, 0x4E, 0x49, 0x1C, 0xCB, 0xB2, + 0xE3, 0x70, 0xA1, 0x88, 0xB1, 0x42, 0x01, 0xD2, 0x49, 0x1C, 0xA1, 0x80, + 0x01, 0x7B, 0x8B, 0x42, 0xF1, 0xD1, 0x01, 0x7A, 0x8A, 0x42, 0xEE, 0xD1, + 0xC0, 0x79, 0xA0, 0x71, 0xE5, 0x70, 0x70, 0xBD, 0x60, 0x00, 0x00, 0x20, + 0x60, 0xEA, 0x00, 0x00, 0x10, 0xB5, 0x19, 0x4C, 0x00, 0x20, 0x20, 0x71, + 0x01, 0x21, 0x61, 0x71, 0x21, 0x46, 0x20, 0x39, 0x88, 0x86, 0xC8, 0x86, + 0x40, 0x31, 0x48, 0x80, 0x48, 0x60, 0x88, 0x60, 0xA0, 0x72, 0xE0, 0x72, + 0x20, 0x72, 0x60, 0x72, 0x02, 0x22, 0xFF, 0x21, 0x10, 0x48, 0xFE, 0xF7, + 0xC3, 0xFC, 0x08, 0x22, 0x00, 0x21, 0x0F, 0x48, 0xFE, 0xF7, 0xBE, 0xFC, + 0x08, 0x22, 0x00, 0x21, 0x0D, 0x48, 0xFE, 0xF7, 0xB9, 0xFC, 0x07, 0x22, + 0x01, 0x21, 0x0C, 0x48, 0xFE, 0xF7, 0xB4, 0xFC, 0x20, 0x46, 0x07, 0x49, + 0x60, 0x38, 0xC1, 0x66, 0x06, 0x49, 0x81, 0x67, 0x06, 0x49, 0xC1, 0x67, + 0x07, 0x49, 0x01, 0x67, 0x02, 0x20, 0xA0, 0x71, 0xE0, 0x71, 0x10, 0xBD, + 0x20, 0x01, 0x00, 0x20, 0x16, 0x00, 0x00, 0x20, 0x18, 0x00, 0x00, 0x20, + 0x20, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x20, 0xF8, 0x73, 0x00, 0x00, + 0xFE, 0xB5, 0x70, 0x4C, 0x6F, 0x48, 0x27, 0x46, 0x25, 0x46, 0x40, 0x78, + 0xFF, 0x37, 0x41, 0x37, 0xE0, 0x35, 0x20, 0x34, 0x05, 0x28, 0x16, 0xD9, + 0xB8, 0x79, 0x00, 0x28, 0x13, 0xD1, 0xA8, 0x70, 0x69, 0x4E, 0x08, 0xE0, + 0x01, 0x20, 0xF0, 0x71, 0xFD, 0xF7, 0xFC, 0xFC, 0x10, 0x20, 0xF0, 0x71, + 0xA8, 0x78, 0x00, 0x28, 0x02, 0xD1, 0xA0, 0x7C, 0x00, 0x28, 0xF3, 0xD0, + 0x63, 0x49, 0x45, 0x20, 0x08, 0x80, 0x00, 0xE0, 0x30, 0xBF, 0xA0, 0x7C, + 0x00, 0x28, 0xFB, 0xD0, 0x5D, 0x48, 0xC0, 0x30, 0x02, 0x90, 0x40, 0x7F, + 0x01, 0x28, 0x0E, 0xD0, 0x5D, 0x4E, 0x00, 0x20, 0x70, 0x77, 0x02, 0x98, + 0x41, 0x7F, 0x30, 0x46, 0x80, 0x38, 0x01, 0x90, 0x40, 0x6C, 0x81, 0x74, + 0x02, 0x98, 0x40, 0x7F, 0x02, 0x28, 0x11, 0xD0, 0x3F, 0xE0, 0x57, 0x48, + 0x01, 0x78, 0x10, 0x22, 0x11, 0x43, 0x01, 0x70, 0x00, 0x21, 0xC1, 0x71, + 0xFF, 0x22, 0x42, 0x75, 0x02, 0x75, 0xC1, 0x74, 0x01, 0x74, 0x81, 0x74, + 0x41, 0x74, 0xFD, 0xF7, 0xC7, 0xFC, 0xFC, 0xE7, 0x4A, 0x4B, 0x4D, 0x49, + 0x9A, 0x88, 0x20, 0x31, 0x64, 0x20, 0x00, 0x91, 0x00, 0x2A, 0x02, 0xD0, + 0xD9, 0x8C, 0x00, 0x29, 0x03, 0xD0, 0x00, 0x9A, 0x00, 0x21, 0x51, 0x70, + 0x10, 0xE0, 0x00, 0x99, 0x49, 0x78, 0x02, 0x29, 0x00, 0xD1, 0x02, 0x20, + 0x71, 0x6A, 0x05, 0x29, 0x01, 0xD8, 0x02, 0x28, 0x04, 0xD1, 0x01, 0x99, + 0xC9, 0x6B, 0x20, 0x31, 0xC9, 0x79, 0x99, 0x71, 0x71, 0x6A, 0x49, 0x1C, + 0x71, 0x62, 0x71, 0x6A, 0x81, 0x42, 0x02, 0xD2, 0x60, 0x7D, 0x0A, 0x28, + 0x07, 0xD1, 0xB8, 0x79, 0x00, 0x28, 0x16, 0xD0, 0x00, 0x99, 0x00, 0x20, + 0x48, 0x70, 0x00, 0x20, 0x70, 0x62, 0x02, 0x98, 0x40, 0x7F, 0xFB, 0x21, + 0x00, 0x28, 0x31, 0xD0, 0xE8, 0x78, 0x01, 0x28, 0x18, 0xD0, 0xE8, 0x78, + 0x02, 0x28, 0x24, 0xD0, 0xE8, 0x78, 0x08, 0x28, 0x28, 0xD2, 0xE8, 0x78, + 0x40, 0x1C, 0xE8, 0x70, 0x21, 0xE0, 0x2A, 0x48, 0x40, 0x6D, 0xFF, 0xF7, + 0x53, 0xFD, 0x00, 0x98, 0x40, 0x78, 0x01, 0x28, 0xE3, 0xD1, 0x01, 0x98, + 0xC0, 0x6B, 0x20, 0x30, 0x01, 0x7A, 0x24, 0x48, 0x81, 0x71, 0xDC, 0xE7, + 0x22, 0x48, 0x42, 0x7A, 0x00, 0x2A, 0x02, 0xD1, 0x80, 0x88, 0x04, 0x28, + 0x04, 0xD2, 0x20, 0x7D, 0x08, 0x40, 0x20, 0x75, 0x02, 0x20, 0x00, 0xE0, + 0x08, 0x20, 0xE8, 0x70, 0x06, 0xE0, 0x1B, 0x48, 0x40, 0x7A, 0x00, 0x28, + 0x08, 0xD0, 0x20, 0x7D, 0x08, 0x40, 0x20, 0x75, 0x01, 0x98, 0x40, 0x6C, + 0x82, 0x7A, 0xCA, 0x2A, 0x02, 0xD0, 0x0A, 0xE0, 0x03, 0x20, 0xD0, 0xE7, + 0x02, 0x7C, 0x01, 0x2A, 0x05, 0xD1, 0x00, 0x22, 0x02, 0x74, 0xE0, 0x7C, + 0x01, 0x22, 0x10, 0x43, 0xE0, 0x74, 0xB8, 0x79, 0x00, 0x28, 0x01, 0xD0, + 0x40, 0x1E, 0xB8, 0x71, 0x20, 0x7D, 0x40, 0x07, 0x08, 0xD5, 0x0F, 0x48, + 0x03, 0x7C, 0x01, 0x9A, 0xD2, 0x6B, 0x55, 0x7C, 0x01, 0x22, 0xAA, 0x40, + 0x93, 0x43, 0x03, 0x74, 0x20, 0x7D, 0x22, 0x7D, 0x40, 0x07, 0xC0, 0x0F, + 0xC0, 0x00, 0xF7, 0x23, 0x1A, 0x40, 0x02, 0x43, 0x22, 0x75, 0x20, 0x7D, + 0x08, 0x40, 0x20, 0x75, 0xFE, 0xBD, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, + 0x00, 0x20, 0x00, 0x40, 0x00, 0x10, 0x00, 0x40, 0x40, 0x01, 0x00, 0x20, + 0x00, 0x03, 0x00, 0x40, 0x00, 0xB5, 0x01, 0x22, 0x92, 0x07, 0x50, 0x88, + 0x04, 0x21, 0x88, 0x43, 0x50, 0x80, 0x0C, 0x48, 0x02, 0x88, 0x0A, 0x43, + 0x02, 0x80, 0x0B, 0x48, 0x01, 0x7A, 0xC9, 0x08, 0xC9, 0x00, 0x01, 0x72, + 0x00, 0x21, 0x81, 0x72, 0x08, 0x48, 0x01, 0x74, 0x81, 0x7C, 0x49, 0x06, + 0x49, 0x0E, 0x81, 0x74, 0x01, 0x20, 0x01, 0xF0, 0x45, 0xFB, 0x00, 0x21, + 0x08, 0x46, 0x01, 0xF0, 0x3F, 0xFC, 0x00, 0xBD, 0x00, 0x10, 0x00, 0x40, + 0x00, 0x03, 0x00, 0x40, 0xE0, 0x12, 0x00, 0x40, 0xF3, 0xB5, 0x85, 0xB0, + 0x00, 0x27, 0xA8, 0xE0, 0x28, 0x20, 0x05, 0x99, 0x78, 0x43, 0x44, 0x18, + 0xA0, 0x78, 0x00, 0x28, 0x7E, 0xD0, 0x01, 0x28, 0x04, 0xD1, 0x0C, 0x25, + 0x0E, 0x20, 0x65, 0x5F, 0x20, 0x5E, 0x28, 0xE0, 0x03, 0x28, 0x04, 0xD3, + 0x4F, 0x48, 0x00, 0x68, 0xC0, 0x79, 0x00, 0x28, 0x0B, 0xD0, 0xA0, 0x89, + 0x21, 0x8A, 0x40, 0x18, 0xA1, 0x8A, 0x40, 0x1A, 0x05, 0xB2, 0xE0, 0x89, + 0x61, 0x8A, 0x40, 0x18, 0xE1, 0x8A, 0x40, 0x1A, 0x14, 0xE0, 0x21, 0x8A, + 0xA0, 0x89, 0x49, 0x00, 0x41, 0x18, 0xA0, 0x8A, 0x42, 0x00, 0x80, 0x18, + 0x08, 0x1A, 0x21, 0x8B, 0x40, 0x18, 0x05, 0xB2, 0x61, 0x8A, 0xE0, 0x89, + 0x49, 0x00, 0x41, 0x18, 0xE0, 0x8A, 0x42, 0x00, 0x80, 0x18, 0x08, 0x1A, + 0x61, 0x8B, 0x40, 0x18, 0x00, 0xB2, 0x00, 0x2D, 0x01, 0xDA, 0x00, 0x25, + 0x06, 0xE0, 0x3A, 0x49, 0x09, 0x68, 0xC9, 0x89, 0x49, 0x1E, 0xA9, 0x42, + 0x00, 0xDA, 0x0D, 0xB2, 0x00, 0x28, 0x01, 0xDA, 0x00, 0x20, 0x06, 0xE0, + 0x34, 0x49, 0x09, 0x68, 0x09, 0x8A, 0x49, 0x1E, 0x81, 0x42, 0x00, 0xDA, + 0x08, 0xB2, 0x25, 0x84, 0x60, 0x84, 0xE1, 0x89, 0x40, 0x1A, 0x2F, 0x49, + 0x09, 0x68, 0x04, 0x91, 0x49, 0x78, 0x03, 0x91, 0x48, 0x43, 0x04, 0x99, + 0x09, 0x8A, 0xFB, 0xF7, 0xB4, 0xFC, 0x26, 0x46, 0x20, 0x36, 0x71, 0x79, + 0x02, 0x91, 0x0A, 0x07, 0x12, 0x0F, 0x82, 0x18, 0x09, 0x09, 0x40, 0x18, + 0x52, 0xB2, 0x40, 0xB2, 0x01, 0x92, 0x00, 0x90, 0xA0, 0x89, 0x04, 0x99, + 0x28, 0x1A, 0x8D, 0x78, 0xC9, 0x89, 0x68, 0x43, 0xFB, 0xF7, 0x9F, 0xFC, + 0xB3, 0x79, 0x19, 0x07, 0x09, 0x0F, 0x41, 0x18, 0x1A, 0x09, 0x80, 0x18, + 0x01, 0x9A, 0x49, 0xB2, 0x40, 0xB2, 0x00, 0x2A, 0x01, 0xDA, 0x00, 0x22, + 0x01, 0x92, 0x03, 0x9A, 0x00, 0x9C, 0x52, 0x1E, 0xA2, 0x42, 0x01, 0xDA, + 0x52, 0xB2, 0x00, 0x92, 0x00, 0x29, 0x00, 0xE0, 0x1F, 0xE0, 0x00, 0xDA, + 0x00, 0x21, 0x6D, 0x1E, 0x85, 0x42, 0x00, 0xDA, 0x68, 0xB2, 0x02, 0x9A, + 0x01, 0x9C, 0x12, 0x09, 0x24, 0x07, 0x12, 0x01, 0x24, 0x0F, 0x22, 0x43, + 0x72, 0x71, 0xD2, 0xB2, 0x14, 0x07, 0x00, 0x9A, 0x24, 0x0F, 0x12, 0x01, + 0x14, 0x43, 0x1A, 0x09, 0x09, 0x07, 0x12, 0x01, 0x09, 0x0F, 0x0A, 0x43, + 0xD1, 0xB2, 0x09, 0x07, 0x09, 0x0F, 0x00, 0x01, 0x74, 0x71, 0x01, 0x43, + 0xB1, 0x71, 0x7F, 0x1C, 0xFF, 0xB2, 0x06, 0x98, 0x87, 0x42, 0x00, 0xD2, + 0x52, 0xE7, 0x07, 0xB0, 0xF0, 0xBD, 0x00, 0x00, 0x34, 0x00, 0x00, 0x20, + 0x03, 0x48, 0x02, 0x49, 0x81, 0x60, 0xC0, 0x68, 0x70, 0x47, 0x00, 0x00, + 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x00, 0x40, 0x30, 0xB5, 0x01, 0x46, + 0x08, 0x48, 0x04, 0x46, 0x40, 0x34, 0x25, 0x46, 0xC3, 0x6B, 0xC0, 0x3D, + 0xA0, 0x68, 0x2D, 0x7A, 0x1A, 0x79, 0x80, 0xB2, 0x01, 0x2D, 0x02, 0xD1, + 0x20, 0x69, 0xDA, 0x79, 0x80, 0xB2, 0xFD, 0xF7, 0x47, 0xFC, 0x30, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0xFE, 0xB5, 0x36, 0x48, 0x35, 0x4A, 0x40, 0x7A, + 0x80, 0x32, 0x00, 0x21, 0x00, 0x92, 0x00, 0x28, 0x12, 0xD0, 0xD2, 0x6B, + 0x00, 0x9B, 0x00, 0x20, 0xD2, 0x7A, 0x5B, 0x69, 0x0A, 0xE0, 0x28, 0x24, + 0x44, 0x43, 0x1C, 0x5D, 0x00, 0x2C, 0x03, 0xD0, 0x49, 0x1C, 0xC9, 0xB2, + 0x8A, 0x42, 0x03, 0xD0, 0x40, 0x1C, 0xC0, 0xB2, 0x82, 0x42, 0xF2, 0xD8, + 0x00, 0x26, 0x28, 0x4F, 0x28, 0x4C, 0x35, 0x46, 0x20, 0x37, 0x01, 0x91, + 0x1B, 0xE0, 0x00, 0x98, 0x41, 0x69, 0x28, 0x20, 0x68, 0x43, 0x08, 0x5C, + 0x00, 0x28, 0x12, 0xD0, 0x02, 0xAA, 0x21, 0x46, 0x28, 0x46, 0x01, 0xF0, + 0x43, 0xFD, 0x64, 0x1D, 0x00, 0x2E, 0x08, 0xD1, 0x38, 0x7A, 0x01, 0x99, + 0xC0, 0x09, 0xC0, 0x01, 0x08, 0x43, 0x20, 0x70, 0xAB, 0x20, 0x60, 0x70, + 0xA4, 0x1C, 0x76, 0x1C, 0xF6, 0xB2, 0x6D, 0x1C, 0xED, 0xB2, 0x00, 0x98, + 0xC0, 0x6B, 0xC0, 0x7A, 0xA8, 0x42, 0xDE, 0xD8, 0x38, 0x7A, 0xC1, 0x09, + 0x10, 0xD0, 0x01, 0x99, 0x20, 0x70, 0xB8, 0x7A, 0x00, 0x29, 0x60, 0x70, + 0x03, 0xD0, 0xAB, 0x20, 0xA0, 0x70, 0xA4, 0x1C, 0x04, 0xE0, 0x80, 0x20, + 0x60, 0x71, 0xAB, 0x20, 0xA0, 0x71, 0xA4, 0x1D, 0x64, 0x1C, 0x05, 0xE0, + 0x01, 0x98, 0x01, 0x28, 0x02, 0xD9, 0xAB, 0x20, 0x20, 0x70, 0xF7, 0xE7, + 0x20, 0x46, 0xFD, 0xF7, 0x3F, 0xFD, 0x07, 0x48, 0x01, 0x79, 0x49, 0x06, + 0x49, 0x0E, 0x01, 0x71, 0x01, 0x79, 0x05, 0x4A, 0x12, 0x7A, 0xD2, 0x09, + 0xD2, 0x01, 0x11, 0x43, 0x01, 0x71, 0xFE, 0xBD, 0x40, 0x00, 0x00, 0x20, + 0x11, 0x07, 0x00, 0x20, 0x80, 0x01, 0x00, 0x20, 0x0A, 0x46, 0x10, 0xB5, + 0x0F, 0x49, 0x03, 0x46, 0x4C, 0x7D, 0x00, 0x20, 0x01, 0x2C, 0x10, 0xD0, + 0x4C, 0x7D, 0x05, 0x2C, 0x0D, 0xD0, 0x4C, 0x7D, 0x08, 0x2C, 0x0A, 0xD0, + 0x4C, 0x7D, 0x04, 0x2C, 0x0A, 0xD0, 0x4A, 0x7D, 0x03, 0x2A, 0x02, 0xD0, + 0x49, 0x7D, 0x06, 0x29, 0x00, 0xD1, 0x01, 0x20, 0x10, 0xBD, 0x48, 0x7D, + 0x19, 0x46, 0x01, 0xE0, 0x19, 0x46, 0x04, 0x20, 0x00, 0xF0, 0x04, 0xF8, + 0xF5, 0xE7, 0x00, 0x00, 0x60, 0x00, 0x00, 0x20, 0xF7, 0xB5, 0x24, 0x4D, + 0x86, 0xB0, 0xE9, 0x6B, 0x04, 0x91, 0xA9, 0x6B, 0x13, 0x46, 0x03, 0x91, + 0x04, 0x28, 0x0C, 0xD0, 0x68, 0x46, 0xFD, 0xF7, 0xFB, 0xFC, 0x0B, 0x22, + 0x69, 0x46, 0x18, 0x46, 0xFE, 0xF7, 0xF8, 0xF9, 0x07, 0x98, 0x01, 0xF0, + 0x09, 0xFB, 0x09, 0xB0, 0xF0, 0xBD, 0x19, 0x4C, 0x6F, 0x6D, 0x80, 0x34, + 0xE0, 0x6B, 0xAB, 0x6D, 0xC6, 0x78, 0x00, 0x79, 0x46, 0x43, 0x68, 0x46, + 0xFD, 0xF7, 0xB6, 0xFC, 0x32, 0x46, 0x19, 0x46, 0x38, 0x46, 0xFE, 0xF7, + 0xE3, 0xF9, 0xBE, 0x19, 0x0B, 0x22, 0x69, 0x46, 0x30, 0x46, 0xFE, 0xF7, + 0xDD, 0xF9, 0xE0, 0x6B, 0x0B, 0x36, 0x02, 0x79, 0x30, 0x46, 0x69, 0x6F, + 0xFE, 0xF7, 0xD6, 0xF9, 0xE0, 0x6B, 0x01, 0x79, 0xC2, 0x78, 0x8E, 0x19, + 0x30, 0x46, 0xE9, 0x6D, 0xFE, 0xF7, 0xCE, 0xF9, 0xE0, 0x6B, 0xC1, 0x78, + 0x02, 0x79, 0x8D, 0x19, 0x28, 0x46, 0x04, 0x99, 0xFE, 0xF7, 0xC6, 0xF9, + 0xE0, 0x6B, 0x03, 0x99, 0x02, 0x79, 0x50, 0x19, 0xC6, 0xE7, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x20, 0x10, 0xB5, 0x0C, 0x46, 0x01, 0x46, 0x0B, 0x48, + 0xC0, 0x6B, 0xC2, 0x78, 0x03, 0x79, 0xC0, 0x79, 0xD2, 0x18, 0x05, 0x28, + 0x01, 0xD2, 0x04, 0x20, 0x00, 0xE0, 0x08, 0x20, 0x10, 0x18, 0x42, 0x00, + 0x04, 0x48, 0x80, 0x38, 0x80, 0x6D, 0xFE, 0xF7, 0xA9, 0xF9, 0x20, 0x46, + 0x01, 0xF0, 0xBA, 0xFA, 0x10, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, + 0xF8, 0xB5, 0x1D, 0x4E, 0x30, 0x7C, 0x1D, 0x4D, 0x01, 0x27, 0xE9, 0x6B, + 0x4A, 0x7C, 0x39, 0x46, 0x91, 0x40, 0x08, 0x43, 0x30, 0x74, 0x2C, 0x46, + 0x60, 0x3C, 0x60, 0x7D, 0x00, 0x28, 0x05, 0xD0, 0x17, 0x49, 0x14, 0x20, + 0xFF, 0xF7, 0x60, 0xFF, 0x00, 0x28, 0x23, 0xD1, 0x20, 0x7D, 0x00, 0x07, + 0x02, 0xD5, 0x01, 0x20, 0x02, 0xF0, 0xFC, 0xF9, 0x10, 0x48, 0x80, 0x38, + 0x40, 0x7A, 0x00, 0x28, 0x07, 0xD1, 0xE9, 0x6B, 0xA0, 0x7B, 0xC9, 0x7C, + 0x88, 0x42, 0x13, 0xD3, 0x20, 0x7A, 0x00, 0x06, 0x10, 0xD5, 0x60, 0x7C, + 0x00, 0x28, 0x0D, 0xD1, 0x30, 0x7C, 0xE9, 0x6B, 0x49, 0x7C, 0x8F, 0x40, + 0x38, 0x43, 0x30, 0x74, 0x06, 0x48, 0x28, 0x64, 0xFF, 0xF7, 0xCA, 0xFE, + 0x20, 0x7D, 0x04, 0x21, 0x08, 0x43, 0x20, 0x75, 0xF8, 0xBD, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x40, 0xC0, 0x00, 0x00, 0x20, 0x11, 0x07, 0x00, 0x20, + 0x00, 0xB5, 0x05, 0x49, 0xAA, 0x20, 0x88, 0x80, 0x04, 0x48, 0x00, 0x21, + 0x81, 0x74, 0x20, 0x38, 0x80, 0x79, 0x01, 0xF0, 0x0D, 0xFC, 0x00, 0xBD, + 0x00, 0x02, 0x00, 0x40, 0x60, 0x00, 0x00, 0x20, 0xFE, 0xB5, 0x31, 0x49, + 0x30, 0x4D, 0x08, 0x46, 0x8C, 0x78, 0x80, 0x30, 0x01, 0x90, 0xC0, 0x6B, + 0x09, 0x6D, 0x86, 0x79, 0x00, 0x79, 0x01, 0x27, 0x60, 0x43, 0x40, 0x00, + 0x08, 0x18, 0xE0, 0x35, 0x2F, 0x70, 0x29, 0x46, 0xC0, 0x39, 0x00, 0x91, + 0xC9, 0x7D, 0x00, 0x29, 0x1A, 0xD0, 0x00, 0x21, 0xFF, 0xF7, 0x7E, 0xFE, + 0xB4, 0x42, 0x16, 0xD1, 0x01, 0x21, 0x22, 0x46, 0x08, 0x46, 0x01, 0xF0, + 0x37, 0xFC, 0x00, 0x20, 0x01, 0xF0, 0x10, 0xFB, 0x00, 0x21, 0x08, 0x46, + 0x01, 0xF0, 0xE8, 0xF9, 0x1D, 0x48, 0x00, 0x21, 0x01, 0x72, 0x01, 0x98, + 0xC0, 0x6B, 0x40, 0x30, 0x81, 0x8A, 0x1B, 0x48, 0xC1, 0x80, 0x6F, 0x70, + 0xFE, 0xBD, 0x64, 0x1C, 0x17, 0x4A, 0xE4, 0xB2, 0x94, 0x70, 0x00, 0x98, + 0x40, 0x7D, 0x06, 0x28, 0x24, 0xD0, 0xB4, 0x42, 0x22, 0xD0, 0x01, 0x25, + 0xAD, 0x07, 0x08, 0x21, 0x02, 0x23, 0x76, 0x1E, 0x68, 0x88, 0xB4, 0x42, + 0x13, 0xDA, 0x08, 0x43, 0x68, 0x80, 0x0F, 0x49, 0x08, 0x88, 0x18, 0x43, + 0x08, 0x80, 0xD0, 0x6D, 0x64, 0x1C, 0x00, 0x5D, 0x02, 0x02, 0x02, 0x43, + 0xCA, 0x81, 0xE0, 0xB2, 0x00, 0x21, 0x01, 0xF0, 0x33, 0xFB, 0xE0, 0xB2, + 0x01, 0xF0, 0xCE, 0xF8, 0xFE, 0xBD, 0x08, 0x43, 0x68, 0x80, 0x05, 0x48, + 0x01, 0x88, 0x19, 0x43, 0x01, 0x80, 0xFE, 0xBD, 0x6F, 0x70, 0xFF, 0xF7, + 0x4F, 0xFD, 0xFE, 0xBD, 0x40, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, + 0xFF, 0xB5, 0x01, 0x20, 0x81, 0xB0, 0x00, 0x90, 0x01, 0x2A, 0x01, 0xD1, + 0x00, 0x20, 0x00, 0x90, 0x3A, 0x49, 0x39, 0x48, 0x48, 0x82, 0x00, 0x27, + 0x62, 0xE0, 0x04, 0x99, 0xB8, 0x00, 0x46, 0x18, 0x31, 0x68, 0x0F, 0x20, + 0x08, 0x70, 0x30, 0x68, 0xBF, 0x21, 0x20, 0x38, 0xC1, 0x77, 0x33, 0x4C, + 0x33, 0x48, 0x20, 0x81, 0x33, 0x48, 0x60, 0x81, 0x3A, 0x46, 0x03, 0x21, + 0x00, 0x98, 0x01, 0xF0, 0xCF, 0xFB, 0xA5, 0x04, 0x68, 0x89, 0x80, 0x21, + 0x08, 0x43, 0x68, 0x81, 0x2E, 0x48, 0x20, 0x80, 0x2D, 0x48, 0x42, 0x38, + 0x20, 0x80, 0x01, 0x21, 0x08, 0x20, 0xFD, 0xF7, 0x4D, 0xF9, 0x69, 0x89, + 0x80, 0x20, 0x81, 0x43, 0x69, 0x81, 0x00, 0x24, 0x20, 0x25, 0x2C, 0x43, + 0xE0, 0xB2, 0x01, 0xF0, 0x5F, 0xF8, 0x21, 0x48, 0x21, 0x49, 0x40, 0x38, + 0x48, 0x82, 0x01, 0x21, 0x64, 0x20, 0xFD, 0xF7, 0x3B, 0xF9, 0x1E, 0x49, + 0x21, 0x48, 0x48, 0x82, 0x01, 0x21, 0x64, 0x20, 0xFD, 0xF7, 0x34, 0xF9, + 0x30, 0x68, 0x00, 0x78, 0x00, 0x06, 0x00, 0xD4, 0xAC, 0x43, 0x6D, 0x08, + 0xE5, 0xD1, 0x17, 0x48, 0x15, 0x49, 0x41, 0x82, 0x81, 0x04, 0x48, 0x89, + 0x80, 0x22, 0x10, 0x43, 0x48, 0x81, 0x3A, 0x46, 0x01, 0x21, 0x00, 0x98, + 0x01, 0xF0, 0x94, 0xFB, 0x31, 0x68, 0x30, 0x20, 0x08, 0x70, 0x30, 0x68, + 0x00, 0x21, 0x20, 0x38, 0xC1, 0x77, 0x00, 0x2C, 0x00, 0xD1, 0x01, 0x24, + 0x02, 0x98, 0x10, 0x49, 0x04, 0x80, 0x02, 0x98, 0x80, 0x1C, 0x02, 0x90, + 0xAA, 0x20, 0x88, 0x80, 0x7F, 0x1C, 0xFF, 0xB2, 0x01, 0x98, 0x87, 0x42, + 0x99, 0xD3, 0x01, 0x21, 0x89, 0x07, 0x48, 0x89, 0x80, 0x22, 0x10, 0x43, + 0x48, 0x81, 0x05, 0xB0, 0xF0, 0xBD, 0x00, 0x00, 0xD0, 0x82, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x40, 0xE0, 0xE8, 0x00, 0x00, 0xFF, 0x02, 0x00, 0x00, + 0x45, 0x08, 0x00, 0x00, 0x90, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x40, + 0x70, 0xB5, 0x0E, 0x4A, 0x0D, 0x4E, 0xD2, 0x6B, 0x80, 0x3E, 0x95, 0x78, + 0x13, 0x79, 0xD4, 0x79, 0x92, 0x79, 0x76, 0x6D, 0x5A, 0x43, 0x52, 0x00, + 0xB3, 0x18, 0x00, 0x22, 0x0B, 0xE0, 0x00, 0x26, 0x9E, 0x5F, 0xAE, 0x42, + 0x04, 0xDB, 0x0E, 0x78, 0x82, 0x55, 0x0E, 0x78, 0x76, 0x1C, 0x0E, 0x70, + 0x9B, 0x1C, 0x52, 0x1C, 0xD2, 0xB2, 0xA2, 0x42, 0xF1, 0xD3, 0x70, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0xFF, 0xB5, 0x30, 0x49, 0x1D, 0x46, 0xC9, 0x6B, + 0x83, 0xB0, 0x0E, 0x79, 0x0B, 0x7B, 0x00, 0x02, 0x20, 0x31, 0x01, 0x93, + 0x89, 0x78, 0x14, 0x46, 0x08, 0x43, 0x2B, 0x49, 0x0C, 0x9A, 0x08, 0x81, + 0x00, 0x2A, 0x00, 0xD0, 0x90, 0x47, 0x00, 0x20, 0x28, 0x4A, 0x05, 0xE0, + 0x41, 0x00, 0x00, 0x23, 0x62, 0x52, 0x40, 0x1C, 0x6B, 0x52, 0xC0, 0xB2, + 0xB0, 0x42, 0xF7, 0xD3, 0x21, 0x48, 0x00, 0x27, 0x60, 0x30, 0x02, 0x90, + 0x2B, 0xE0, 0x22, 0x49, 0xA3, 0x20, 0x88, 0x74, 0x02, 0x98, 0x00, 0x22, + 0x02, 0x70, 0x1D, 0x48, 0x11, 0x22, 0x82, 0x80, 0x45, 0x22, 0x02, 0x80, + 0x43, 0x22, 0x02, 0x80, 0x00, 0xE0, 0x30, 0xBF, 0x02, 0x98, 0x00, 0x78, + 0x00, 0x28, 0xFA, 0xD0, 0x23, 0x20, 0x88, 0x74, 0x00, 0x21, 0x04, 0x98, + 0xFF, 0xF7, 0x4A, 0xFD, 0x00, 0x21, 0x0C, 0xE0, 0x4A, 0x00, 0x04, 0x98, + 0xA3, 0x5E, 0x80, 0x5A, 0x83, 0x42, 0x00, 0xDD, 0xA0, 0x52, 0xAB, 0x5E, + 0x83, 0x42, 0x00, 0xDA, 0xA8, 0x52, 0x49, 0x1C, 0xC9, 0xB2, 0xB1, 0x42, + 0xF0, 0xD3, 0x7F, 0x1C, 0xFF, 0xB2, 0x01, 0x98, 0x87, 0x42, 0xD0, 0xD3, + 0x00, 0x21, 0x08, 0x46, 0x07, 0xE0, 0x42, 0x00, 0xAB, 0x5A, 0xA2, 0x5A, + 0x9A, 0x1A, 0x51, 0x18, 0x40, 0x1C, 0x89, 0xB2, 0xC0, 0xB2, 0xB0, 0x42, + 0xF5, 0xD3, 0x88, 0x08, 0x07, 0xB0, 0xF0, 0xBD, 0xC0, 0x00, 0x00, 0x20, + 0x00, 0x10, 0x00, 0x40, 0xFF, 0x7F, 0x00, 0x00, 0xE0, 0x12, 0x00, 0x40, + 0x30, 0xB5, 0x04, 0x46, 0x0D, 0x46, 0x10, 0x46, 0x01, 0xF0, 0xF0, 0xFD, + 0x29, 0x46, 0x20, 0x46, 0xFF, 0xF7, 0x12, 0xFD, 0x30, 0xBD, 0x00, 0x00, + 0xF8, 0xB5, 0x23, 0x48, 0x54, 0x21, 0xC0, 0x6B, 0x22, 0x4C, 0x09, 0x5A, + 0xE1, 0x80, 0x20, 0x49, 0x00, 0x26, 0x60, 0x31, 0x00, 0x91, 0x4E, 0x70, + 0x1F, 0x49, 0x8A, 0x7C, 0x80, 0x23, 0x1A, 0x43, 0x8A, 0x74, 0xDD, 0x05, + 0x6A, 0x88, 0x04, 0x21, 0x8A, 0x43, 0x6A, 0x80, 0x20, 0x30, 0xC1, 0x7D, + 0x80, 0x7D, 0x89, 0x00, 0x00, 0x01, 0x01, 0x43, 0x43, 0x20, 0x01, 0x43, + 0x17, 0x48, 0x01, 0x72, 0x13, 0x4F, 0x80, 0x3F, 0xBE, 0x70, 0xF8, 0x6D, + 0x00, 0x78, 0x01, 0x02, 0x01, 0x43, 0xE1, 0x81, 0x00, 0x21, 0x02, 0x20, + 0x01, 0xF0, 0x5C, 0xF8, 0x00, 0x20, 0x00, 0xF0, 0x6F, 0xFF, 0x00, 0x99, + 0x0E, 0x70, 0x11, 0x20, 0xA0, 0x80, 0x45, 0x20, 0x20, 0x80, 0x43, 0x20, + 0x20, 0x80, 0x68, 0x88, 0x04, 0x21, 0x08, 0x43, 0x68, 0x80, 0xF8, 0x6D, + 0x40, 0x78, 0x01, 0x02, 0x01, 0x43, 0xE1, 0x81, 0x00, 0x21, 0x01, 0x20, + 0x01, 0xF0, 0xBC, 0xF9, 0x01, 0x20, 0x00, 0xF0, 0x57, 0xFF, 0xF8, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, 0xE0, 0x12, 0x00, 0x40, + 0x00, 0x03, 0x00, 0x40, 0x10, 0xB5, 0xFB, 0xF7, 0x37, 0xFB, 0xFC, 0xF7, + 0xCF, 0xFD, 0x11, 0x4C, 0x00, 0x20, 0x20, 0x72, 0x20, 0x46, 0x02, 0x21, + 0x20, 0x30, 0xC1, 0x75, 0xFF, 0xF7, 0xA2, 0xFF, 0x60, 0x78, 0x05, 0x28, + 0x04, 0xD9, 0xE0, 0x1D, 0xF9, 0x30, 0x40, 0x7F, 0x00, 0x28, 0x06, 0xD0, + 0x08, 0x48, 0xE0, 0x30, 0x41, 0x78, 0x00, 0x29, 0x09, 0xD0, 0xFC, 0xF7, + 0xB7, 0xFD, 0xFD, 0xF7, 0x6B, 0xFA, 0x60, 0x78, 0xC8, 0x28, 0x01, 0xD2, + 0x40, 0x1C, 0x60, 0x70, 0x10, 0xBD, 0x30, 0xBF, 0xF0, 0xE7, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x20, 0x30, 0xB5, 0x19, 0x4B, 0x3C, 0x24, 0x00, 0x21, + 0x1A, 0x6E, 0x08, 0x46, 0x00, 0x25, 0x55, 0x5F, 0xA5, 0x42, 0x00, 0xDD, + 0x49, 0x1C, 0x40, 0x1C, 0x92, 0x1C, 0x09, 0x28, 0xF6, 0xD3, 0x9B, 0x6F, + 0x00, 0x20, 0x02, 0x46, 0x00, 0x25, 0x5D, 0x5F, 0xA5, 0x42, 0x00, 0xDD, + 0x40, 0x1C, 0x52, 0x1C, 0x9B, 0x1C, 0x07, 0x2A, 0xF6, 0xD3, 0x0D, 0x4B, + 0x06, 0x29, 0x9A, 0x7F, 0x01, 0xD9, 0x04, 0x28, 0x02, 0xD8, 0x08, 0x18, + 0x0A, 0x28, 0x03, 0xD9, 0x0A, 0x2A, 0x05, 0xD2, 0x52, 0x1C, 0x02, 0xE0, + 0x00, 0x2A, 0x01, 0xD0, 0x52, 0x1E, 0x9A, 0x77, 0x04, 0x48, 0x40, 0x38, + 0x40, 0x7E, 0x00, 0x28, 0x01, 0xD0, 0x00, 0x20, 0x98, 0x77, 0x30, 0xBD, + 0x40, 0x00, 0x00, 0x20, 0x40, 0x01, 0x00, 0x20, 0xF0, 0xB5, 0x60, 0x49, + 0x5F, 0x48, 0x80, 0x31, 0xC9, 0x6B, 0x8B, 0xB0, 0xCF, 0x78, 0x80, 0x6F, + 0x09, 0x79, 0x0A, 0x91, 0x5B, 0x49, 0x06, 0x46, 0xE0, 0x31, 0xC9, 0x8A, + 0x64, 0x29, 0x01, 0xD2, 0x00, 0x21, 0x06, 0xE0, 0x64, 0x39, 0xFF, 0x22, + 0x89, 0xB2, 0x91, 0x32, 0x91, 0x42, 0x00, 0xD9, 0x11, 0x46, 0x89, 0x08, + 0xFA, 0x31, 0x06, 0x91, 0x00, 0x21, 0x0D, 0x46, 0x0C, 0x46, 0x09, 0x91, + 0x0B, 0xE0, 0x00, 0x22, 0x82, 0x5E, 0x3C, 0x2A, 0x01, 0xDD, 0x6D, 0x1C, + 0xED, 0xB2, 0xA2, 0x42, 0x00, 0xDD, 0x14, 0x46, 0x80, 0x1C, 0x49, 0x1C, + 0x89, 0xB2, 0xB9, 0x42, 0xF1, 0xD3, 0xB8, 0x00, 0x05, 0x21, 0xFB, 0xF7, + 0x74, 0xF8, 0xA8, 0x42, 0x07, 0xD2, 0xFF, 0x20, 0x2D, 0x30, 0x84, 0x42, + 0x03, 0xDD, 0xA0, 0xB2, 0x06, 0x90, 0x01, 0x20, 0x09, 0x90, 0x06, 0x98, + 0x84, 0x42, 0x00, 0xDD, 0x04, 0xB2, 0x00, 0x25, 0x58, 0xE0, 0x00, 0x20, + 0x31, 0x46, 0x20, 0x39, 0x30, 0x5E, 0xC9, 0x8B, 0x6B, 0x46, 0x99, 0x83, + 0xD8, 0x83, 0x71, 0x88, 0x02, 0x46, 0x19, 0x84, 0x00, 0x2D, 0x02, 0xD1, + 0x00, 0x21, 0x99, 0x83, 0x05, 0xE0, 0x79, 0x1E, 0x8D, 0x42, 0x02, 0xD1, + 0x00, 0x21, 0x6B, 0x46, 0x19, 0x84, 0x00, 0x28, 0x01, 0xDC, 0x01, 0x20, + 0x03, 0xE0, 0x06, 0x9B, 0x98, 0x42, 0x00, 0xDD, 0x18, 0x46, 0x6B, 0x46, + 0x1C, 0x21, 0x59, 0x5E, 0x8C, 0x46, 0x8A, 0x42, 0x13, 0xDA, 0x20, 0x21, + 0x59, 0x5E, 0x8A, 0x42, 0x0F, 0xDA, 0x1E, 0x29, 0x02, 0xDC, 0x62, 0x46, + 0x1E, 0x2A, 0x0A, 0xDD, 0x60, 0x46, 0x40, 0x18, 0x40, 0x10, 0x02, 0xB2, + 0x32, 0x80, 0x00, 0x2A, 0x03, 0xDC, 0x61, 0x45, 0x00, 0xDC, 0x61, 0x46, + 0x48, 0x10, 0x09, 0x99, 0x00, 0x29, 0x06, 0xD0, 0x3C, 0x28, 0x01, 0xD9, + 0x3C, 0x38, 0x00, 0xE0, 0x01, 0x20, 0x3C, 0x3C, 0x24, 0xB2, 0x1E, 0x2C, + 0x0C, 0xDD, 0x00, 0x02, 0x21, 0x46, 0xFB, 0xF7, 0x1C, 0xF8, 0x80, 0xB2, + 0x69, 0x00, 0x01, 0xAA, 0x50, 0x52, 0x00, 0x28, 0x07, 0xD1, 0x01, 0x20, + 0x50, 0x52, 0x04, 0xE0, 0xFF, 0x20, 0x01, 0x30, 0x69, 0x00, 0x01, 0xAA, + 0xF8, 0xE7, 0xB6, 0x1C, 0x6D, 0x1C, 0xAD, 0xB2, 0xBD, 0x42, 0xA4, 0xD3, + 0x00, 0x23, 0x1C, 0xE0, 0x10, 0x48, 0x59, 0x00, 0x40, 0x6D, 0x0A, 0x9A, + 0x40, 0x18, 0x00, 0x21, 0x55, 0x00, 0x10, 0xE0, 0x00, 0x22, 0x82, 0x5E, + 0x0F, 0x2A, 0x09, 0xDB, 0x4C, 0x00, 0x01, 0xAE, 0x34, 0x5B, 0x54, 0x43, + 0x24, 0x0A, 0xE6, 0x00, 0x34, 0x1B, 0xA2, 0x18, 0xD2, 0x10, 0x02, 0x80, + 0x28, 0x18, 0x49, 0x1C, 0xC9, 0xB2, 0xB9, 0x42, 0xEC, 0xD3, 0x5B, 0x1C, + 0xDB, 0xB2, 0x0A, 0x98, 0x83, 0x42, 0xDF, 0xD3, 0x0B, 0xB0, 0xF0, 0xBD, + 0x40, 0x00, 0x00, 0x20, 0xF7, 0xB5, 0x4D, 0x48, 0x88, 0xB0, 0x80, 0x6F, + 0x01, 0x90, 0x4B, 0x48, 0x80, 0x30, 0x47, 0x68, 0xC0, 0x6B, 0x00, 0x21, + 0x80, 0x79, 0x07, 0x90, 0x08, 0x98, 0x0B, 0x46, 0x01, 0x80, 0x47, 0x48, + 0x0C, 0x46, 0x0D, 0x46, 0x0E, 0x46, 0x06, 0x91, 0x0A, 0x46, 0x05, 0x91, + 0x04, 0x90, 0x20, 0xE0, 0x01, 0x99, 0x50, 0x00, 0x09, 0x5A, 0x38, 0x5A, + 0x08, 0x1A, 0x00, 0xB2, 0x14, 0x28, 0x01, 0xDB, 0x36, 0x18, 0x04, 0xE0, + 0x09, 0x21, 0xC9, 0x43, 0x88, 0x42, 0x00, 0xDA, 0x2D, 0x18, 0x19, 0x18, + 0x0B, 0xB2, 0x06, 0x99, 0x81, 0x42, 0x00, 0xDA, 0x06, 0x90, 0x01, 0x1B, + 0x04, 0x46, 0x05, 0x98, 0x09, 0xB2, 0x88, 0x42, 0x00, 0xDA, 0x05, 0x91, + 0x04, 0x98, 0x88, 0x42, 0x00, 0xDD, 0x04, 0x91, 0x52, 0x1C, 0x07, 0x98, + 0x82, 0x42, 0xDB, 0xD3, 0x01, 0x46, 0x18, 0x46, 0xFA, 0xF7, 0xAD, 0xFF, + 0x00, 0x24, 0x00, 0xB2, 0x86, 0x46, 0x21, 0x46, 0xA4, 0x46, 0x20, 0x46, + 0x02, 0x94, 0x17, 0xE0, 0x01, 0x9A, 0x43, 0x00, 0xD2, 0x5A, 0xFB, 0x5A, + 0xD2, 0x1A, 0x12, 0xB2, 0x72, 0x45, 0x06, 0xDB, 0x0A, 0x9B, 0x9A, 0x42, + 0x03, 0xDD, 0x49, 0x1C, 0x94, 0x44, 0xC9, 0xB2, 0x07, 0xE0, 0x00, 0x2A, + 0x00, 0xDA, 0x52, 0x42, 0x02, 0x9B, 0xD2, 0x18, 0x64, 0x1C, 0xE4, 0xB2, + 0x02, 0x92, 0x40, 0x1C, 0x07, 0x9A, 0x90, 0x42, 0xE4, 0xD3, 0x00, 0x20, + 0x08, 0x9A, 0x07, 0x46, 0x10, 0x80, 0x00, 0x29, 0x14, 0xD0, 0x00, 0x2C, + 0x15, 0xD0, 0x60, 0x46, 0xFA, 0xF7, 0x7F, 0xFF, 0x03, 0x90, 0x21, 0x46, + 0x02, 0x98, 0xFA, 0xF7, 0x7A, 0xFF, 0x41, 0x1C, 0x03, 0x98, 0xFA, 0xF7, + 0x76, 0xFF, 0x08, 0x99, 0x80, 0xB2, 0x08, 0x80, 0x09, 0x99, 0x88, 0x42, + 0x03, 0xD2, 0x01, 0xE0, 0x02, 0x2C, 0x00, 0xD3, 0x01, 0x27, 0x64, 0x2E, + 0x03, 0xD8, 0x63, 0x20, 0xC0, 0x43, 0x85, 0x42, 0x11, 0xDA, 0x05, 0x98, + 0x32, 0x28, 0x0D, 0xDD, 0x31, 0x21, 0x04, 0x98, 0xC9, 0x43, 0x88, 0x42, + 0x08, 0xDA, 0x96, 0x2E, 0x06, 0xD9, 0x06, 0x98, 0x3C, 0x28, 0x03, 0xDD, + 0x77, 0x20, 0xC0, 0x43, 0x85, 0x42, 0x00, 0xDC, 0x01, 0x27, 0x38, 0x46, + 0x0B, 0xB0, 0xF0, 0xBD, 0x40, 0x00, 0x00, 0x20, 0xFF, 0x7F, 0x00, 0x00, + 0xF1, 0xB5, 0x55, 0x48, 0x82, 0xB0, 0xC1, 0x6B, 0x02, 0x46, 0x86, 0x46, + 0x80, 0x3A, 0x90, 0x6E, 0x0D, 0x79, 0x84, 0x46, 0x13, 0x6F, 0xD0, 0x6E, + 0x00, 0x93, 0x14, 0x6E, 0x02, 0x9A, 0x00, 0x2A, 0x0C, 0xD1, 0x70, 0x46, + 0x00, 0x68, 0xCD, 0x78, 0x84, 0x46, 0x70, 0x46, 0x71, 0x46, 0x40, 0x68, + 0x89, 0x68, 0x00, 0x91, 0x48, 0x49, 0x80, 0x39, 0x8C, 0x6F, 0x04, 0xE0, + 0x46, 0x4A, 0x00, 0x21, 0x80, 0x3A, 0x51, 0x61, 0x91, 0x61, 0x00, 0x21, + 0x0A, 0x46, 0x01, 0x91, 0x40, 0xE0, 0x56, 0x00, 0x61, 0x46, 0x89, 0x5B, + 0x83, 0x5B, 0xC9, 0x1A, 0x0B, 0xB2, 0xA3, 0x53, 0x71, 0x46, 0xCF, 0x6B, + 0x1A, 0x21, 0x79, 0x56, 0x99, 0x42, 0x0A, 0xDD, 0x02, 0x99, 0x01, 0x29, + 0x2E, 0xD1, 0x3A, 0x4E, 0x01, 0x23, 0x80, 0x3E, 0x71, 0x69, 0x93, 0x40, + 0x19, 0x43, 0x71, 0x61, 0x26, 0xE0, 0xB9, 0x7D, 0x99, 0x42, 0x0F, 0xDA, + 0x14, 0x31, 0x99, 0x42, 0x01, 0xDA, 0x01, 0x21, 0x01, 0x91, 0x02, 0x99, + 0x01, 0x29, 0x1B, 0xD1, 0x30, 0x4E, 0x01, 0x23, 0x80, 0x3E, 0xB1, 0x69, + 0x93, 0x40, 0x19, 0x43, 0xB1, 0x61, 0x13, 0xE0, 0x2C, 0x49, 0x60, 0x39, + 0x09, 0x79, 0x00, 0x29, 0x0E, 0xD1, 0x00, 0x99, 0x87, 0x5F, 0x89, 0x5C, + 0x3B, 0x02, 0xCB, 0x18, 0x61, 0x46, 0x89, 0x5F, 0x89, 0x00, 0xCB, 0x18, + 0xB9, 0x00, 0x59, 0x1A, 0x0B, 0x12, 0x83, 0x53, 0x00, 0x9B, 0x99, 0x54, + 0x52, 0x1C, 0xD2, 0xB2, 0xAA, 0x42, 0xBC, 0xD3, 0x20, 0x49, 0x80, 0x31, + 0x49, 0x7F, 0x00, 0x29, 0x0B, 0xD0, 0x01, 0x99, 0x00, 0x29, 0x08, 0xD1, + 0x6A, 0x00, 0x61, 0x46, 0xFD, 0xF7, 0x3C, 0xFD, 0x2A, 0x46, 0x00, 0x21, + 0x00, 0x98, 0xFD, 0xF7, 0x47, 0xFD, 0x00, 0x20, 0x13, 0x23, 0xDB, 0x43, + 0x06, 0x46, 0x02, 0x46, 0x47, 0x1F, 0x10, 0xE0, 0x51, 0x00, 0x61, 0x5E, + 0xB9, 0x42, 0x03, 0xDA, 0x99, 0x42, 0x07, 0xDA, 0x19, 0x46, 0x05, 0xE0, + 0x05, 0x29, 0x03, 0xDD, 0x14, 0x29, 0x00, 0xDD, 0x14, 0x21, 0x76, 0x1C, + 0x40, 0x18, 0x52, 0x1C, 0xD2, 0xB2, 0xAA, 0x42, 0xEC, 0xD3, 0x29, 0x46, + 0xFA, 0xF7, 0xB5, 0xFE, 0x03, 0x2E, 0x10, 0xD9, 0x00, 0x22, 0x0C, 0xE0, + 0x53, 0x00, 0xE1, 0x5E, 0x00, 0x28, 0x05, 0xDD, 0x81, 0x42, 0x02, 0xDD, + 0x09, 0x1A, 0x09, 0xB2, 0x00, 0xE0, 0x01, 0x21, 0x52, 0x1C, 0xE1, 0x52, + 0xD2, 0xB2, 0xAA, 0x42, 0xF0, 0xD3, 0xFE, 0xBD, 0xC0, 0x00, 0x00, 0x20, + 0x10, 0xB5, 0x01, 0x46, 0x08, 0x4A, 0x10, 0x20, 0xD0, 0x80, 0x08, 0x48, + 0x07, 0x4B, 0xC0, 0x6B, 0x01, 0x22, 0x20, 0x30, 0xC0, 0x7B, 0x60, 0x3B, + 0xDA, 0x73, 0x40, 0x1E, 0xA0, 0x33, 0xC0, 0xB2, 0x1A, 0x77, 0x00, 0xF0, + 0x05, 0xF8, 0x10, 0xBD, 0x00, 0x10, 0x00, 0x40, 0xC0, 0x00, 0x00, 0x20, + 0xF3, 0xB5, 0x3C, 0x4A, 0x8F, 0xB0, 0x10, 0x6E, 0x11, 0x46, 0x80, 0x31, + 0x0C, 0x90, 0xC8, 0x6B, 0x10, 0x9B, 0x06, 0x79, 0x01, 0x2B, 0x0E, 0xD0, + 0xCD, 0x68, 0x91, 0x6F, 0x0C, 0x91, 0xC6, 0x78, 0x40, 0x30, 0xC0, 0x89, + 0x0D, 0x90, 0x02, 0x20, 0x0B, 0x90, 0x00, 0x20, 0x0A, 0x90, 0x00, 0x20, + 0x01, 0x46, 0x31, 0x4B, 0x07, 0xE0, 0x55, 0x6F, 0xF2, 0xE7, 0x44, 0x00, + 0x6A, 0x46, 0x13, 0x53, 0x29, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0xB0, 0x42, + 0xF7, 0xD3, 0x00, 0x24, 0x27, 0x46, 0x40, 0xE0, 0x01, 0x21, 0x10, 0x98, + 0x00, 0xF0, 0xEC, 0xFA, 0x00, 0x20, 0x1A, 0xE0, 0x01, 0x21, 0x81, 0x40, + 0x8C, 0x46, 0x21, 0x42, 0x13, 0xD1, 0x0C, 0x9A, 0x41, 0x00, 0x53, 0x5E, + 0x0D, 0x9A, 0x9A, 0x1A, 0x00, 0xD5, 0x52, 0x42, 0x6B, 0x46, 0x5B, 0x5A, + 0x92, 0xB2, 0x93, 0x42, 0x02, 0xD3, 0x6B, 0x46, 0x5A, 0x52, 0x04, 0xE0, + 0x29, 0x5C, 0x49, 0x1E, 0x29, 0x54, 0x61, 0x46, 0x0C, 0x43, 0x40, 0x1C, + 0xC0, 0xB2, 0xB0, 0x42, 0xE2, 0xD3, 0x01, 0x21, 0x08, 0x46, 0xB0, 0x40, + 0x40, 0x1E, 0xA0, 0x42, 0x02, 0xD1, 0x01, 0x20, 0x0A, 0x90, 0x17, 0xE0, + 0x0F, 0x98, 0x7F, 0x1C, 0x87, 0x42, 0x13, 0xD2, 0x00, 0x20, 0x0B, 0x46, + 0x0B, 0xE0, 0x29, 0x5C, 0x0F, 0x9A, 0x91, 0x42, 0x05, 0xD2, 0x1A, 0x46, + 0x82, 0x40, 0x22, 0x42, 0x01, 0xD1, 0x49, 0x1C, 0x29, 0x54, 0x40, 0x1C, + 0xC0, 0xB2, 0xB0, 0x42, 0xF1, 0xD3, 0x0A, 0x98, 0x00, 0x28, 0xBB, 0xD0, + 0x0B, 0x98, 0x40, 0x1E, 0x00, 0x06, 0x00, 0x0E, 0x0B, 0x90, 0x02, 0xD0, + 0x0A, 0x98, 0x00, 0x28, 0xA1, 0xD0, 0x0A, 0x98, 0x11, 0xB0, 0xC0, 0xB2, + 0xF0, 0xBD, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0xFF, 0xFF, 0x00, 0x00, + 0xF0, 0xB5, 0x8C, 0x46, 0x3D, 0x49, 0x00, 0x28, 0xCE, 0x6B, 0xCC, 0x69, + 0x35, 0x79, 0x4B, 0x6A, 0x02, 0xD1, 0xF5, 0x78, 0x8C, 0x69, 0x0B, 0x6A, + 0x05, 0x2A, 0x23, 0xD1, 0x00, 0x20, 0x1E, 0xE0, 0xC2, 0x07, 0xD2, 0x0F, + 0x62, 0x45, 0x16, 0xD1, 0x22, 0x68, 0x91, 0x1C, 0x56, 0x1C, 0x1F, 0x3A, + 0x97, 0x7F, 0x8E, 0x46, 0x19, 0x78, 0x0F, 0x43, 0x97, 0x77, 0xD7, 0x7F, + 0x19, 0x78, 0x8F, 0x43, 0xD7, 0x77, 0x31, 0x78, 0x1A, 0x78, 0x91, 0x43, + 0x31, 0x70, 0x71, 0x46, 0x0A, 0x78, 0x19, 0x78, 0x8A, 0x43, 0x71, 0x46, + 0x0A, 0x70, 0x24, 0x1D, 0x5B, 0x1C, 0x40, 0x1C, 0xC0, 0xB2, 0xA8, 0x42, + 0xDE, 0xD3, 0xF0, 0xBD, 0x01, 0x2A, 0x23, 0xD1, 0x00, 0x20, 0x1E, 0xE0, + 0xC2, 0x07, 0xD2, 0x0F, 0x62, 0x45, 0x16, 0xD1, 0x22, 0x68, 0x91, 0x1C, + 0x56, 0x1C, 0x1F, 0x3A, 0x97, 0x7F, 0x8E, 0x46, 0x19, 0x78, 0x8F, 0x43, + 0x97, 0x77, 0xD7, 0x7F, 0x19, 0x78, 0x8F, 0x43, 0xD7, 0x77, 0x31, 0x78, + 0x1A, 0x78, 0x11, 0x43, 0x31, 0x70, 0x71, 0x46, 0x0A, 0x78, 0x19, 0x78, + 0x8A, 0x43, 0x71, 0x46, 0x0A, 0x70, 0x24, 0x1D, 0x5B, 0x1C, 0x40, 0x1C, + 0xC0, 0xB2, 0xA8, 0x42, 0xDE, 0xD3, 0xF0, 0xBD, 0x03, 0x2A, 0xFC, 0xD1, + 0x00, 0x20, 0x1E, 0xE0, 0xC2, 0x07, 0xD2, 0x0F, 0x62, 0x45, 0x16, 0xD1, + 0x22, 0x68, 0x91, 0x1C, 0x56, 0x1C, 0x1F, 0x3A, 0x97, 0x7F, 0x8E, 0x46, + 0x19, 0x78, 0x8F, 0x43, 0x97, 0x77, 0xD7, 0x7F, 0x19, 0x78, 0x8F, 0x43, + 0xD7, 0x77, 0x31, 0x78, 0x1A, 0x78, 0x91, 0x43, 0x31, 0x70, 0x71, 0x46, + 0x0A, 0x78, 0x19, 0x78, 0x0A, 0x43, 0x71, 0x46, 0x0A, 0x70, 0x24, 0x1D, + 0x5B, 0x1C, 0x40, 0x1C, 0xC0, 0xB2, 0xA8, 0x42, 0xDE, 0xD3, 0xF0, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x38, 0x4D, 0x00, 0x28, 0xEE, 0x6B, + 0xEB, 0x69, 0x34, 0x79, 0x6A, 0x6A, 0x02, 0xD1, 0xF4, 0x78, 0xAB, 0x69, + 0x2A, 0x6A, 0x05, 0x29, 0x1F, 0xD1, 0x00, 0x25, 0x1A, 0xE0, 0x18, 0x68, + 0x81, 0x1C, 0x8C, 0x46, 0x41, 0x1C, 0x1F, 0x38, 0x86, 0x7F, 0x17, 0x78, + 0x3E, 0x43, 0x86, 0x77, 0xC6, 0x7F, 0x17, 0x78, 0xBE, 0x43, 0xC6, 0x77, + 0x0E, 0x78, 0x10, 0x78, 0x86, 0x43, 0x0E, 0x70, 0x61, 0x46, 0x08, 0x78, + 0x11, 0x78, 0x88, 0x43, 0x61, 0x46, 0x08, 0x70, 0x1B, 0x1D, 0x52, 0x1C, + 0x6D, 0x1C, 0xED, 0xB2, 0xA5, 0x42, 0xE2, 0xD3, 0xF0, 0xBD, 0x01, 0x29, + 0x1F, 0xD1, 0x00, 0x25, 0x1A, 0xE0, 0x18, 0x68, 0x81, 0x1C, 0x8C, 0x46, + 0x41, 0x1C, 0x1F, 0x38, 0x86, 0x7F, 0x17, 0x78, 0xBE, 0x43, 0x86, 0x77, + 0xC6, 0x7F, 0x17, 0x78, 0xBE, 0x43, 0xC6, 0x77, 0x0E, 0x78, 0x10, 0x78, + 0x06, 0x43, 0x0E, 0x70, 0x61, 0x46, 0x08, 0x78, 0x11, 0x78, 0x88, 0x43, + 0x61, 0x46, 0x08, 0x70, 0x1B, 0x1D, 0x52, 0x1C, 0x6D, 0x1C, 0xED, 0xB2, + 0xA5, 0x42, 0xE2, 0xD3, 0xF0, 0xBD, 0x03, 0x29, 0xFC, 0xD1, 0x00, 0x25, + 0x1A, 0xE0, 0x18, 0x68, 0x81, 0x1C, 0x8C, 0x46, 0x41, 0x1C, 0x1F, 0x38, + 0x86, 0x7F, 0x17, 0x78, 0xBE, 0x43, 0x86, 0x77, 0xC6, 0x7F, 0x17, 0x78, + 0xBE, 0x43, 0xC6, 0x77, 0x0E, 0x78, 0x10, 0x78, 0x86, 0x43, 0x0E, 0x70, + 0x61, 0x46, 0x08, 0x78, 0x11, 0x78, 0x08, 0x43, 0x61, 0x46, 0x08, 0x70, + 0x1B, 0x1D, 0x52, 0x1C, 0x6D, 0x1C, 0xED, 0xB2, 0xA5, 0x42, 0xE2, 0xD3, + 0xF0, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0xF8, 0xB5, 0x25, 0x4A, + 0xD1, 0x6B, 0x00, 0x91, 0x16, 0x46, 0x0B, 0x79, 0x80, 0x3E, 0x31, 0x46, + 0x60, 0x31, 0xB2, 0xC9, 0x00, 0x28, 0xBE, 0x46, 0x37, 0x6F, 0xBC, 0x46, + 0x08, 0xD1, 0x00, 0x98, 0xB1, 0x6F, 0xC3, 0x78, 0x50, 0x68, 0x15, 0x68, + 0x86, 0x46, 0x90, 0x68, 0xF4, 0x6F, 0x84, 0x46, 0x19, 0x48, 0x80, 0x38, + 0x40, 0x78, 0x02, 0x28, 0x0A, 0xD8, 0x00, 0x20, 0x06, 0xE0, 0x42, 0x00, + 0x8E, 0x5A, 0xA6, 0x52, 0x8E, 0x5A, 0x40, 0x1C, 0xAE, 0x52, 0xC0, 0xB2, + 0x98, 0x42, 0xF6, 0xD3, 0x00, 0x22, 0x0B, 0xE0, 0x50, 0x00, 0x0E, 0x5E, + 0x77, 0x00, 0xF6, 0x19, 0x27, 0x5E, 0xF6, 0x19, 0xB6, 0x10, 0x2E, 0x52, + 0x0E, 0x5A, 0x52, 0x1C, 0x26, 0x52, 0xD2, 0xB2, 0x9A, 0x42, 0xF1, 0xD3, + 0x09, 0x48, 0x80, 0x38, 0x40, 0x78, 0x05, 0x28, 0x0C, 0xD8, 0x00, 0x20, + 0x04, 0x46, 0x07, 0xE0, 0x41, 0x00, 0x6A, 0x5A, 0x76, 0x46, 0x72, 0x52, + 0x61, 0x46, 0x0C, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0x98, 0x42, 0xF5, 0xD3, + 0xF8, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x6D, 0x48, + 0x89, 0xB0, 0x01, 0x88, 0x08, 0x91, 0x41, 0x88, 0x07, 0x91, 0xC1, 0x88, + 0x06, 0x91, 0xC1, 0x89, 0x05, 0x91, 0x01, 0x89, 0x04, 0x91, 0x40, 0x89, + 0x03, 0x90, 0x67, 0x48, 0x01, 0x7C, 0x02, 0x91, 0x81, 0x7C, 0x01, 0x91, + 0x40, 0x7C, 0x65, 0x4C, 0x00, 0x90, 0xE2, 0x6B, 0x0E, 0x25, 0x90, 0x7B, + 0x00, 0x28, 0x7D, 0xD0, 0x10, 0x46, 0x20, 0x30, 0x81, 0x7B, 0xC3, 0x7B, + 0xC6, 0x78, 0xC9, 0x18, 0x83, 0x78, 0x5F, 0x4F, 0x9B, 0x19, 0x9B, 0x1C, + 0x26, 0x46, 0x9C, 0x46, 0x60, 0x36, 0x33, 0x7A, 0x76, 0x7A, 0x76, 0x00, + 0xF6, 0x19, 0x9E, 0x5D, 0x63, 0x46, 0xF3, 0x18, 0x0E, 0x46, 0x10, 0x36, + 0x89, 0x1C, 0xB3, 0x42, 0x02, 0xD2, 0x5B, 0x00, 0xB3, 0x42, 0x01, 0xD3, + 0x59, 0x1A, 0xCD, 0xB2, 0x81, 0x7A, 0x51, 0x4F, 0x09, 0x01, 0x49, 0x1C, + 0x39, 0x74, 0x10, 0x21, 0x79, 0x74, 0x83, 0x7B, 0x29, 0x02, 0x4C, 0x4E, + 0x19, 0x43, 0x31, 0x81, 0x50, 0x21, 0x89, 0x5A, 0xF1, 0x80, 0x11, 0x7C, + 0xD2, 0x7B, 0x80, 0x23, 0x12, 0x01, 0x1A, 0x43, 0x11, 0x43, 0xB9, 0x74, + 0x49, 0x49, 0x71, 0x80, 0x41, 0x21, 0x31, 0x80, 0xC0, 0x7B, 0xFF, 0x30, + 0xFF, 0x30, 0x02, 0x30, 0x70, 0x81, 0x00, 0xF0, 0xCB, 0xFA, 0xE0, 0x6B, + 0x80, 0x22, 0x01, 0x7C, 0xC0, 0x7B, 0x00, 0x01, 0x10, 0x43, 0x01, 0x43, + 0xB9, 0x74, 0x3E, 0x48, 0x3D, 0x4F, 0x80, 0x38, 0x40, 0x78, 0xA0, 0x37, + 0x01, 0x28, 0x12, 0xD8, 0x02, 0x20, 0x00, 0xF0, 0x81, 0xFA, 0x01, 0x20, + 0xFF, 0xF7, 0xB8, 0xFD, 0xE0, 0x6B, 0x20, 0x30, 0x40, 0x7E, 0x00, 0x28, + 0x02, 0xD0, 0x00, 0x20, 0xFF, 0xF7, 0xB0, 0xFD, 0x3D, 0x70, 0xE0, 0x6B, + 0x40, 0x30, 0x00, 0x8A, 0xF0, 0x80, 0xE0, 0x6B, 0x20, 0x30, 0x40, 0x7E, + 0x00, 0x28, 0x1D, 0xD0, 0x01, 0x21, 0x08, 0x46, 0xFF, 0xF7, 0xB8, 0xFE, + 0x38, 0x78, 0xFF, 0x28, 0x07, 0xD0, 0xE1, 0x6B, 0x00, 0x02, 0x20, 0x31, + 0x89, 0x7B, 0x08, 0x43, 0x30, 0x81, 0xFF, 0x20, 0x38, 0x70, 0x00, 0x21, + 0x08, 0x46, 0x00, 0xF0, 0xC3, 0xF8, 0x08, 0x21, 0x28, 0x46, 0x00, 0xF0, + 0x4D, 0xF8, 0x00, 0xE0, 0x3D, 0xE0, 0xE0, 0x6B, 0x20, 0x30, 0x40, 0x7E, + 0x00, 0x28, 0x02, 0xD1, 0x02, 0x20, 0x00, 0xF0, 0x4B, 0xFA, 0x00, 0x21, + 0x01, 0x20, 0x00, 0xF0, 0xB1, 0xF8, 0x1B, 0x4D, 0xA8, 0x7C, 0x40, 0x06, + 0x40, 0x0E, 0xA8, 0x74, 0x01, 0x20, 0x00, 0xF0, 0x3F, 0xFA, 0xE0, 0x6B, + 0x20, 0x30, 0x40, 0x7E, 0x00, 0x28, 0x07, 0xD0, 0x00, 0x20, 0xFF, 0xF7, + 0xFB, 0xFE, 0x00, 0x20, 0xFF, 0xF7, 0xC0, 0xFC, 0x00, 0xF0, 0xB6, 0xF9, + 0x01, 0x20, 0xFF, 0xF7, 0xF3, 0xFE, 0x01, 0x20, 0xFF, 0xF7, 0xB8, 0xFC, + 0xFF, 0xF7, 0x1A, 0xFB, 0x08, 0x98, 0x30, 0x80, 0x07, 0x98, 0x70, 0x80, + 0x06, 0x98, 0xF0, 0x80, 0x05, 0x98, 0xF0, 0x81, 0x04, 0x98, 0x30, 0x81, + 0x03, 0x98, 0x70, 0x81, 0x02, 0x98, 0x28, 0x74, 0x01, 0x98, 0xA8, 0x74, + 0x00, 0x98, 0x68, 0x74, 0x02, 0x20, 0x00, 0xF0, 0x37, 0xFC, 0x09, 0xB0, + 0xF0, 0xBD, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0xE0, 0x12, 0x00, 0x40, + 0xC0, 0x00, 0x00, 0x20, 0xF8, 0x73, 0x00, 0x00, 0x83, 0x10, 0x00, 0x00, + 0xF3, 0xB5, 0x05, 0x46, 0x34, 0xA0, 0x8B, 0xB0, 0x00, 0x68, 0x34, 0x49, + 0x08, 0x90, 0x88, 0x6F, 0x05, 0x90, 0x08, 0x46, 0x80, 0x30, 0x09, 0x90, + 0x43, 0x68, 0xA0, 0x30, 0xFF, 0x22, 0x07, 0x90, 0x02, 0x70, 0x48, 0x78, + 0x02, 0x28, 0x04, 0xD8, 0x07, 0x22, 0x18, 0x46, 0x05, 0x99, 0xFD, 0xF7, + 0x35, 0xFA, 0x2A, 0x48, 0xE0, 0x30, 0x00, 0x79, 0x00, 0x28, 0x4A, 0xD0, + 0x00, 0x27, 0x68, 0x46, 0x06, 0x95, 0x07, 0x80, 0x3C, 0x46, 0x3E, 0x46, + 0x00, 0x21, 0x08, 0x46, 0x00, 0xF0, 0x4A, 0xF8, 0x32, 0x22, 0x08, 0x21, + 0x68, 0x46, 0xFF, 0xF7, 0xC7, 0xFB, 0x0A, 0x90, 0x68, 0x46, 0x00, 0x88, + 0xB8, 0x42, 0x0A, 0xD9, 0x07, 0x22, 0x01, 0xA8, 0x05, 0x99, 0xFD, 0xF7, + 0x17, 0xFA, 0x68, 0x46, 0x07, 0x88, 0x1B, 0x48, 0x00, 0x89, 0x00, 0x0A, + 0x06, 0x90, 0x0A, 0x98, 0x00, 0x28, 0x1C, 0xD0, 0x68, 0x46, 0x00, 0x88, + 0x0A, 0x28, 0x18, 0xD2, 0x04, 0x2C, 0x06, 0xD2, 0x08, 0xA8, 0x00, 0x5D, + 0x40, 0x19, 0x64, 0x1C, 0xC0, 0xB2, 0xE4, 0xB2, 0x03, 0xE0, 0x00, 0x24, + 0x2D, 0x1D, 0xED, 0xB2, 0x28, 0x46, 0x09, 0x99, 0x00, 0x02, 0xC9, 0x6B, + 0x20, 0x31, 0x89, 0x7B, 0x08, 0x43, 0x0C, 0x49, 0x08, 0x81, 0x0C, 0x98, + 0x76, 0x1C, 0x86, 0x42, 0xC6, 0xD3, 0x68, 0x46, 0x00, 0x88, 0x00, 0x28, + 0x07, 0xD0, 0x07, 0x22, 0x01, 0xA9, 0x05, 0x98, 0xFD, 0xF7, 0xE8, 0xF9, + 0x07, 0x99, 0x06, 0x98, 0x08, 0x70, 0x0D, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xFF, 0x01, 0xFE, 0x02, 0x40, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, + 0xF3, 0xB5, 0x47, 0x4D, 0x85, 0xB0, 0x29, 0x46, 0x80, 0x31, 0xCA, 0x6B, + 0x05, 0x9C, 0x10, 0x46, 0x44, 0x4B, 0x20, 0x30, 0x01, 0x2C, 0x24, 0xD0, + 0xCE, 0x6C, 0x41, 0x49, 0xD4, 0x78, 0xC0, 0x31, 0x09, 0x7F, 0xAD, 0x6F, + 0x0A, 0x02, 0x0A, 0x43, 0xDA, 0x81, 0x00, 0x7E, 0x01, 0x28, 0x5E, 0xD0, + 0x03, 0x22, 0x00, 0x21, 0x05, 0x98, 0xFF, 0xF7, 0x49, 0xFD, 0x01, 0x22, + 0x11, 0x46, 0x05, 0x98, 0xFF, 0xF7, 0x44, 0xFD, 0x00, 0x22, 0x02, 0x21, + 0x05, 0x98, 0x00, 0xF0, 0x6D, 0xF8, 0x00, 0xF0, 0xD7, 0xF8, 0xB0, 0xB2, + 0x22, 0x46, 0x69, 0x46, 0xFC, 0xF7, 0x48, 0xFB, 0x00, 0x20, 0x6F, 0x46, + 0x0F, 0xE0, 0x8E, 0x6C, 0x2E, 0x49, 0x14, 0x79, 0x20, 0x31, 0xC9, 0x7B, + 0x2D, 0x6E, 0x0A, 0x02, 0x0A, 0x43, 0xDA, 0x81, 0xC0, 0x7A, 0xD9, 0xE7, + 0x41, 0x00, 0x7A, 0x5A, 0x80, 0x1C, 0x6A, 0x52, 0xC0, 0xB2, 0xA0, 0x42, + 0xF8, 0xD3, 0x00, 0x22, 0x03, 0x21, 0x05, 0x98, 0x00, 0xF0, 0x4C, 0xF8, + 0x01, 0x22, 0x00, 0x21, 0x05, 0x98, 0xFF, 0xF7, 0x19, 0xFD, 0x03, 0x22, + 0x01, 0x21, 0x05, 0x98, 0xFF, 0xF7, 0x14, 0xFD, 0x01, 0x22, 0x02, 0x21, + 0x05, 0x98, 0x00, 0xF0, 0x3D, 0xF8, 0x1C, 0x48, 0x00, 0x21, 0xE0, 0x30, + 0x01, 0x70, 0x00, 0xF0, 0xA3, 0xF8, 0xB0, 0xB2, 0x22, 0x46, 0x69, 0x46, + 0xFC, 0xF7, 0x14, 0xFB, 0x01, 0x20, 0x04, 0xE0, 0x41, 0x00, 0x7A, 0x5A, + 0x80, 0x1C, 0x6A, 0x52, 0xC0, 0xB2, 0xA0, 0x42, 0xF8, 0xD3, 0x01, 0x22, + 0x03, 0x21, 0x05, 0x98, 0x00, 0xF0, 0x24, 0xF8, 0x01, 0x22, 0x11, 0x46, + 0x05, 0x98, 0xFF, 0xF7, 0xF1, 0xFC, 0x07, 0xB0, 0xF0, 0xBD, 0x03, 0x21, + 0x05, 0x98, 0xFF, 0xF7, 0x6B, 0xFD, 0x02, 0x21, 0x05, 0x98, 0x00, 0xF0, + 0x4F, 0xF8, 0x00, 0xF0, 0x7F, 0xF8, 0xB0, 0xB2, 0x22, 0x46, 0x29, 0x46, + 0xFC, 0xF7, 0xF0, 0xFA, 0x03, 0x21, 0x05, 0x98, 0x00, 0xF0, 0x44, 0xF8, + 0x01, 0x21, 0x05, 0x98, 0xFF, 0xF7, 0x58, 0xFD, 0xE5, 0xE7, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, 0xF0, 0xB5, 0x1B, 0x4E, + 0x94, 0x00, 0xB3, 0x6A, 0xA4, 0x46, 0x1B, 0x19, 0x34, 0x46, 0x80, 0x3C, + 0xF7, 0x6B, 0x64, 0x6F, 0x3D, 0x79, 0xA4, 0x18, 0x00, 0x28, 0x04, 0xD1, + 0xF3, 0x6A, 0xF0, 0x68, 0xFD, 0x78, 0x63, 0x44, 0x84, 0x18, 0x02, 0x29, + 0x13, 0xD1, 0x0F, 0x21, 0x09, 0x02, 0x80, 0x26, 0x0C, 0xE0, 0x20, 0x78, + 0x1F, 0x68, 0x30, 0x43, 0x08, 0x43, 0x20, 0x3F, 0xF8, 0x77, 0x1F, 0x68, + 0x0F, 0x20, 0x38, 0x70, 0x08, 0x33, 0xA4, 0x1C, 0x92, 0x1C, 0xD2, 0xB2, + 0xAA, 0x42, 0xF0, 0xD3, 0xF0, 0xBD, 0x03, 0x29, 0xFC, 0xD1, 0x00, 0x20, + 0x07, 0xE0, 0x19, 0x68, 0x20, 0x39, 0xC8, 0x77, 0x19, 0x68, 0x08, 0x70, + 0x08, 0x33, 0x92, 0x1C, 0xD2, 0xB2, 0xAA, 0x42, 0xF5, 0xD3, 0xF0, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0x70, 0xB5, 0x17, 0x4D, 0xEE, 0x6B, 0x2B, 0x46, + 0x80, 0x3B, 0x34, 0x79, 0xAA, 0x6A, 0x5B, 0x6F, 0x00, 0x28, 0x02, 0xD1, + 0xF4, 0x78, 0xEB, 0x68, 0xEA, 0x6A, 0x02, 0x29, 0x11, 0xD1, 0x00, 0x20, + 0x0F, 0x21, 0x0B, 0xE0, 0x1D, 0x78, 0xAE, 0x06, 0xB6, 0x0E, 0x15, 0x68, + 0x80, 0x36, 0x20, 0x3D, 0xEE, 0x77, 0x20, 0xCA, 0x29, 0x70, 0x5B, 0x1C, + 0x40, 0x1C, 0xC0, 0xB2, 0xA0, 0x42, 0xF1, 0xD3, 0x70, 0xBD, 0x03, 0x29, + 0xFC, 0xD1, 0x00, 0x20, 0x01, 0x46, 0x06, 0xE0, 0x13, 0x68, 0x20, 0x3B, + 0xD9, 0x77, 0x08, 0xCA, 0x19, 0x70, 0x40, 0x1C, 0xC0, 0xB2, 0xA0, 0x42, + 0xF6, 0xD3, 0x70, 0xBD, 0xC0, 0x00, 0x00, 0x20, 0x10, 0xB5, 0x09, 0x4B, + 0x01, 0x20, 0x98, 0x72, 0x08, 0x48, 0x00, 0x22, 0x02, 0x70, 0x08, 0x49, + 0x11, 0x24, 0x8C, 0x80, 0x43, 0x24, 0x0C, 0x80, 0x00, 0xE0, 0x30, 0xBF, + 0x01, 0x78, 0x00, 0x29, 0xFB, 0xD0, 0x9A, 0x72, 0x10, 0xBD, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x40, 0x20, 0x01, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, + 0xF0, 0xB5, 0x33, 0x48, 0x85, 0xB0, 0x80, 0x6F, 0x84, 0x46, 0x31, 0x48, + 0x80, 0x30, 0xC0, 0x6B, 0x85, 0x79, 0x20, 0x30, 0x81, 0x7E, 0xC0, 0x7E, + 0x00, 0x90, 0x8E, 0x46, 0x00, 0x20, 0x01, 0x46, 0x09, 0xE0, 0x4B, 0x00, + 0x62, 0x46, 0xD2, 0x5E, 0x72, 0x45, 0x02, 0xDD, 0x90, 0x42, 0x00, 0xD2, + 0x10, 0x46, 0x49, 0x1C, 0x09, 0xB2, 0xA9, 0x42, 0xF3, 0xDB, 0x25, 0x4C, + 0x00, 0x21, 0xC0, 0x34, 0x41, 0xE0, 0x63, 0x69, 0x00, 0x22, 0x5A, 0x54, + 0x4A, 0x00, 0x04, 0x92, 0x63, 0x46, 0x9A, 0x5E, 0x67, 0x7E, 0x00, 0x9B, + 0x76, 0x46, 0x00, 0x2F, 0x05, 0xD0, 0x73, 0x46, 0x14, 0x33, 0x9E, 0xB2, + 0x00, 0x9B, 0x0A, 0x33, 0x9B, 0xB2, 0xB2, 0x42, 0x2B, 0xDD, 0x04, 0x9E, + 0x1E, 0x27, 0x66, 0x44, 0x03, 0x96, 0x20, 0x3E, 0xF7, 0x5F, 0x02, 0x97, + 0x02, 0x27, 0x03, 0x9E, 0x00, 0x29, 0xF7, 0x5F, 0x01, 0x97, 0x02, 0xD1, + 0x00, 0x27, 0x02, 0x97, 0x04, 0xE0, 0x6E, 0x1E, 0xB1, 0x42, 0x01, 0xD1, + 0x00, 0x27, 0x01, 0x97, 0x02, 0x9E, 0xB2, 0x42, 0x02, 0xDB, 0x01, 0x9E, + 0xB2, 0x42, 0x05, 0xDA, 0x98, 0x42, 0x0E, 0xD9, 0x1E, 0x46, 0x0A, 0x3E, + 0xB2, 0x42, 0x0A, 0xDD, 0x01, 0x26, 0x67, 0x69, 0x98, 0x42, 0x7E, 0x54, + 0x05, 0xD9, 0x0A, 0x3B, 0x9A, 0x42, 0x02, 0xDC, 0x63, 0x69, 0x00, 0x22, + 0x5A, 0x54, 0x49, 0x1C, 0x09, 0xB2, 0xA9, 0x42, 0xBB, 0xDB, 0x05, 0xB0, + 0xF0, 0xBD, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x3F, 0x28, 0x01, 0xD9, + 0x01, 0x20, 0x70, 0x47, 0xC1, 0x08, 0x40, 0x07, 0x40, 0x0F, 0x09, 0x01, + 0x01, 0x43, 0x88, 0x20, 0x01, 0x43, 0x02, 0x48, 0x81, 0x74, 0x00, 0x20, + 0x70, 0x47, 0x00, 0x00, 0xE0, 0x12, 0x00, 0x40, 0x70, 0xB5, 0x06, 0x46, + 0x07, 0x48, 0x00, 0x24, 0xC0, 0x6B, 0xC5, 0x78, 0x06, 0xE0, 0x22, 0x46, + 0x31, 0x46, 0x01, 0x20, 0x00, 0xF0, 0x3A, 0xFB, 0x64, 0x1C, 0xE4, 0xB2, + 0xAC, 0x42, 0xF6, 0xD3, 0x70, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, + 0x06, 0x21, 0x09, 0x4B, 0x10, 0xB5, 0x48, 0x43, 0xC1, 0x18, 0x08, 0x4A, + 0x4C, 0x78, 0x54, 0x70, 0x18, 0x5C, 0x10, 0x70, 0xC8, 0x78, 0x50, 0x72, + 0x88, 0x78, 0x10, 0x72, 0x48, 0x79, 0x50, 0x74, 0x08, 0x79, 0x10, 0x74, + 0x10, 0xBD, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x20, 0x40, 0x03, 0x00, 0x40, + 0x04, 0x48, 0xFF, 0x22, 0x02, 0x70, 0x00, 0x21, 0x41, 0x70, 0x02, 0x72, + 0x41, 0x72, 0x02, 0x74, 0x41, 0x74, 0x70, 0x47, 0x40, 0x03, 0x00, 0x40, + 0x0E, 0x49, 0x48, 0x6C, 0x82, 0x7A, 0xCA, 0x2A, 0x17, 0xD1, 0xC2, 0x7A, + 0x13, 0x02, 0x02, 0x7B, 0x13, 0x43, 0x0B, 0x4A, 0x13, 0x81, 0x43, 0x7B, + 0xFF, 0x33, 0xFF, 0x33, 0x02, 0x33, 0x53, 0x81, 0xC2, 0x7B, 0x80, 0x7B, + 0x00, 0x01, 0x02, 0x43, 0xC8, 0x6B, 0x80, 0x21, 0x20, 0x30, 0x80, 0x79, + 0xC0, 0x00, 0x08, 0x43, 0x02, 0x43, 0x03, 0x48, 0x82, 0x74, 0x70, 0x47, + 0xC0, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, 0xE0, 0x12, 0x00, 0x40, + 0xF0, 0xB5, 0x8C, 0x46, 0x46, 0x4B, 0x45, 0x49, 0x1A, 0x46, 0x41, 0x18, + 0x80, 0x32, 0x34, 0x29, 0x03, 0xD8, 0x44, 0x48, 0xD9, 0x60, 0x10, 0x64, + 0xF0, 0xBD, 0x0D, 0x21, 0x09, 0x03, 0x41, 0x1A, 0x36, 0x29, 0x01, 0xD8, + 0xD9, 0x60, 0xF0, 0xBD, 0x3D, 0x4C, 0x01, 0x21, 0x80, 0x34, 0x09, 0x03, + 0x65, 0x6C, 0x88, 0x42, 0x01, 0xD2, 0x15, 0x64, 0x5C, 0xE0, 0x39, 0x4C, + 0x01, 0x27, 0x46, 0x1A, 0x7F, 0x03, 0x20, 0x34, 0xBE, 0x42, 0x0F, 0xD2, + 0x60, 0x7D, 0x04, 0x28, 0x0A, 0xD0, 0x60, 0x7D, 0x05, 0x28, 0x07, 0xD0, + 0x60, 0x7D, 0x06, 0x28, 0x04, 0xD0, 0x60, 0x7D, 0x0A, 0x28, 0x01, 0xD0, + 0x98, 0x6C, 0x1F, 0xE0, 0x58, 0x6D, 0x1D, 0xE0, 0x03, 0x26, 0x36, 0x03, + 0x86, 0x1B, 0xBE, 0x42, 0x01, 0xD2, 0x58, 0x6C, 0x16, 0xE0, 0x05, 0x26, + 0x36, 0x03, 0x86, 0x1B, 0xBE, 0x42, 0x01, 0xD2, 0x98, 0x6D, 0x0F, 0xE0, + 0x07, 0x26, 0x36, 0x03, 0x86, 0x1B, 0x8E, 0x42, 0x34, 0xD2, 0x39, 0x25, + 0x6D, 0x02, 0xA8, 0x42, 0x0D, 0xD2, 0x60, 0x7D, 0x05, 0x28, 0x06, 0xD0, + 0x60, 0x7D, 0x01, 0x28, 0x05, 0xD0, 0xD8, 0x6E, 0x10, 0x64, 0xDE, 0x60, + 0xF0, 0xBD, 0x18, 0x6E, 0xFA, 0xE7, 0x98, 0x6E, 0xF8, 0xE7, 0x1D, 0x21, + 0x89, 0x02, 0x88, 0x42, 0x0D, 0xD2, 0x61, 0x7D, 0x05, 0x29, 0x06, 0xD0, + 0x61, 0x7D, 0x01, 0x29, 0x05, 0xD0, 0x51, 0x68, 0x40, 0x1B, 0x11, 0x64, + 0x12, 0xE0, 0x99, 0x6F, 0xFA, 0xE7, 0x11, 0x68, 0xF8, 0xE7, 0x3B, 0x24, + 0x64, 0x02, 0xA0, 0x42, 0x03, 0xD2, 0xDC, 0x6B, 0x40, 0x1A, 0x14, 0x64, + 0x06, 0xE0, 0x0F, 0x21, 0xC9, 0x02, 0x88, 0x42, 0xDC, 0xD2, 0x99, 0x6B, + 0x00, 0x1B, 0x11, 0x64, 0xD8, 0x60, 0xF0, 0xBD, 0x01, 0x21, 0xC9, 0x03, + 0x41, 0x1A, 0xFF, 0x29, 0x02, 0xD8, 0x60, 0x46, 0x10, 0x64, 0x8D, 0xE7, + 0x41, 0x21, 0x49, 0x02, 0x40, 0x1A, 0xFF, 0x28, 0x01, 0xD8, 0x0A, 0x35, + 0x8F, 0xE7, 0x04, 0x48, 0xEC, 0xE7, 0x00, 0x00, 0x10, 0x2E, 0xFF, 0xFF, + 0x40, 0x00, 0x00, 0x20, 0x50, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, + 0x04, 0x48, 0xFF, 0x21, 0x41, 0x75, 0x01, 0x75, 0x00, 0x22, 0xC2, 0x74, + 0x01, 0x74, 0x82, 0x74, 0x42, 0x74, 0x70, 0x47, 0x00, 0x03, 0x00, 0x40, + 0x10, 0xB5, 0x0C, 0x46, 0x02, 0x28, 0x07, 0xD1, 0x01, 0x20, 0x00, 0xF0, + 0x0D, 0xF8, 0x00, 0x21, 0x20, 0x46, 0x00, 0xF0, 0x6D, 0xF9, 0x10, 0xBD, + 0x00, 0x28, 0x01, 0xD0, 0x01, 0x28, 0xFA, 0xD1, 0x00, 0xF0, 0x02, 0xF8, + 0x10, 0xBD, 0x00, 0x00, 0x70, 0xB5, 0x0D, 0x4B, 0x00, 0x24, 0x1E, 0x46, + 0xDD, 0x6B, 0x80, 0x3E, 0x36, 0x7A, 0x2A, 0x79, 0x99, 0x6A, 0x01, 0x2E, + 0x01, 0xD1, 0xEA, 0x79, 0x59, 0x6B, 0x00, 0x28, 0x02, 0xD0, 0x01, 0x28, + 0x00, 0xD1, 0x0F, 0x24, 0x00, 0x20, 0xE3, 0xB2, 0x03, 0xE0, 0x10, 0xC9, + 0x23, 0x70, 0x40, 0x1C, 0xC0, 0xB2, 0x90, 0x42, 0xF9, 0xD3, 0x70, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0x10, 0xB5, 0x0F, 0x49, 0xCB, 0x6B, 0x00, 0x21, + 0xDA, 0x79, 0x15, 0xE0, 0x04, 0x78, 0x8C, 0x42, 0x10, 0xD1, 0x0B, 0x48, + 0x83, 0x24, 0x60, 0x38, 0x02, 0x7A, 0x22, 0x43, 0x02, 0x72, 0x1A, 0x7D, + 0x42, 0x72, 0x0A, 0x01, 0x17, 0x32, 0x82, 0x72, 0x02, 0x46, 0x20, 0x3A, + 0x91, 0x85, 0x01, 0x21, 0x81, 0x73, 0x10, 0xBD, 0x49, 0x1C, 0xC9, 0xB2, + 0x91, 0x42, 0xE7, 0xD3, 0x10, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, + 0x70, 0xB5, 0x0C, 0x4C, 0x01, 0x26, 0x61, 0x6C, 0x4E, 0x71, 0x0B, 0x4D, + 0x29, 0x7C, 0xE2, 0x6B, 0x53, 0x7C, 0x32, 0x46, 0x9A, 0x40, 0x91, 0x43, + 0x29, 0x74, 0x00, 0xF0, 0x83, 0xFF, 0x28, 0x7C, 0xE1, 0x6B, 0x49, 0x7C, + 0x8E, 0x40, 0x30, 0x43, 0x28, 0x74, 0x61, 0x6C, 0x00, 0x20, 0x48, 0x71, + 0x70, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x40, + 0xF3, 0xB5, 0x83, 0xB0, 0x00, 0x27, 0x9F, 0xE0, 0x28, 0x20, 0x03, 0x99, + 0x78, 0x43, 0x44, 0x18, 0xA0, 0x78, 0x00, 0x28, 0x7D, 0xD0, 0x52, 0x4D, + 0x28, 0x68, 0xC0, 0x79, 0x00, 0x28, 0x04, 0xD0, 0x20, 0x8C, 0x6B, 0x46, + 0x18, 0x80, 0x60, 0x8C, 0x03, 0xE0, 0xA0, 0x89, 0x6B, 0x46, 0x18, 0x80, + 0xE0, 0x89, 0x6B, 0x46, 0x58, 0x80, 0x00, 0x22, 0x20, 0x46, 0x00, 0x99, + 0x00, 0xF0, 0xE2, 0xFD, 0x20, 0x46, 0x62, 0x79, 0xA1, 0x79, 0x10, 0x30, + 0xFA, 0xF7, 0xAE, 0xFA, 0x01, 0x90, 0x44, 0x48, 0x00, 0x68, 0x00, 0x7B, + 0x00, 0x28, 0x1F, 0xD1, 0x60, 0x79, 0x02, 0x28, 0x1C, 0xD3, 0x6B, 0x46, + 0xDD, 0x88, 0x9A, 0x88, 0xE1, 0x89, 0xA0, 0x89, 0x2B, 0x46, 0xFC, 0xF7, + 0x07, 0xF8, 0xC1, 0xB2, 0x3B, 0x48, 0x00, 0x68, 0x42, 0x7A, 0x8A, 0x42, + 0x05, 0xD2, 0xA1, 0x79, 0xC0, 0x7A, 0x81, 0x42, 0x0A, 0xD2, 0x49, 0x1C, + 0x07, 0xE0, 0x02, 0x7A, 0x8A, 0x42, 0x05, 0xD9, 0xA1, 0x79, 0x80, 0x7A, + 0x81, 0x42, 0x01, 0xD9, 0x49, 0x1E, 0xA1, 0x71, 0xE0, 0x79, 0x00, 0x28, + 0x0D, 0xD0, 0xE3, 0x8B, 0xA2, 0x8B, 0xE1, 0x89, 0xA0, 0x89, 0xFB, 0xF7, + 0xE9, 0xFF, 0x2D, 0x49, 0x09, 0x68, 0x89, 0x79, 0x49, 0x08, 0x88, 0x42, + 0x01, 0xD2, 0x00, 0x20, 0xE0, 0x71, 0x60, 0x79, 0x01, 0x28, 0x49, 0xD9, + 0xE0, 0x79, 0x00, 0x28, 0x46, 0xD1, 0x00, 0x25, 0x2E, 0x46, 0x10, 0xE0, + 0xB0, 0x00, 0x20, 0x18, 0x41, 0x8A, 0x00, 0x8A, 0xE3, 0x8B, 0xA2, 0x8B, + 0xFB, 0xF7, 0xD0, 0xFF, 0x20, 0x49, 0x09, 0x68, 0x89, 0x79, 0x88, 0x42, + 0x01, 0xD2, 0x6D, 0x1C, 0xED, 0xB2, 0x76, 0x1C, 0xF6, 0xB2, 0x60, 0x79, + 0xB0, 0x42, 0xEB, 0xD8, 0x66, 0x79, 0xAE, 0x42, 0x01, 0xD1, 0x01, 0x20, + 0xE0, 0x71, 0x6B, 0x46, 0x99, 0x88, 0x70, 0x1B, 0x41, 0x43, 0x02, 0x90, + 0xA0, 0x8B, 0x68, 0x43, 0x08, 0x18, 0x31, 0x46, 0x00, 0xE0, 0x17, 0xE0, + 0xF9, 0xF7, 0xDD, 0xFF, 0xA0, 0x83, 0x6B, 0x46, 0xD9, 0x88, 0x02, 0x98, + 0x41, 0x43, 0xE0, 0x8B, 0x68, 0x43, 0x08, 0x18, 0x31, 0x46, 0xF9, 0xF7, + 0xD2, 0xFF, 0xE0, 0x83, 0xA0, 0x8B, 0x6B, 0x46, 0x18, 0x80, 0xE0, 0x8B, + 0x58, 0x80, 0x01, 0x22, 0x20, 0x46, 0x00, 0x99, 0x00, 0xF0, 0x60, 0xFD, + 0x7F, 0x1C, 0xFF, 0xB2, 0x04, 0x98, 0x87, 0x42, 0x00, 0xD2, 0x5B, 0xE7, + 0x05, 0xB0, 0xF0, 0xBD, 0x6B, 0x46, 0x98, 0x88, 0xA0, 0x83, 0xD8, 0x88, + 0xE7, 0xE7, 0x00, 0x00, 0x34, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x28, 0x4B, + 0x1E, 0x46, 0xDC, 0x6B, 0x80, 0x3E, 0x36, 0x7A, 0x25, 0x79, 0xDA, 0x69, + 0x59, 0x6A, 0x01, 0x2E, 0x02, 0xD1, 0xE5, 0x79, 0x1A, 0x6B, 0x99, 0x6B, + 0x00, 0x28, 0x1F, 0xD1, 0x00, 0x24, 0x1A, 0xE0, 0x10, 0x68, 0x83, 0x1C, + 0x9C, 0x46, 0x43, 0x1C, 0x1F, 0x38, 0x86, 0x7F, 0x0F, 0x78, 0x3E, 0x43, + 0x86, 0x77, 0xC6, 0x7F, 0x0F, 0x78, 0xBE, 0x43, 0xC6, 0x77, 0x1E, 0x78, + 0x08, 0x78, 0x86, 0x43, 0x1E, 0x70, 0x63, 0x46, 0x18, 0x78, 0x0B, 0x78, + 0x98, 0x43, 0x63, 0x46, 0x18, 0x70, 0x12, 0x1D, 0x49, 0x1C, 0x64, 0x1C, + 0xE4, 0xB2, 0xAC, 0x42, 0xE2, 0xD3, 0xF0, 0xBD, 0x02, 0x28, 0xFC, 0xD1, + 0x00, 0x24, 0x1A, 0xE0, 0x10, 0x68, 0x83, 0x1C, 0x9C, 0x46, 0x43, 0x1C, + 0x1F, 0x38, 0x86, 0x7F, 0x0F, 0x78, 0xBE, 0x43, 0x86, 0x77, 0xC6, 0x7F, + 0x0F, 0x78, 0xBE, 0x43, 0xC6, 0x77, 0x1E, 0x78, 0x08, 0x78, 0x86, 0x43, + 0x1E, 0x70, 0x63, 0x46, 0x18, 0x78, 0x0B, 0x78, 0x18, 0x43, 0x63, 0x46, + 0x18, 0x70, 0x12, 0x1D, 0x49, 0x1C, 0x64, 0x1C, 0xE4, 0xB2, 0xAC, 0x42, + 0xE2, 0xD3, 0xF0, 0xBD, 0xC0, 0x00, 0x00, 0x20, 0xFE, 0xB5, 0x1E, 0x4A, + 0x43, 0x00, 0x12, 0x68, 0x1D, 0x4C, 0xD2, 0x5A, 0x1B, 0x4B, 0xA4, 0x6D, + 0xC0, 0x3B, 0xDB, 0x6B, 0x6D, 0x46, 0x9C, 0x46, 0x1B, 0x79, 0x58, 0x43, + 0x26, 0x18, 0x00, 0x20, 0x0F, 0xE0, 0x00, 0x29, 0x09, 0xD1, 0x34, 0x5C, + 0xD7, 0x07, 0xA4, 0x06, 0xA4, 0x0E, 0x80, 0x34, 0x7F, 0x0E, 0x3C, 0x43, + 0x2C, 0x54, 0x52, 0x08, 0x01, 0xE0, 0x82, 0x24, 0x2C, 0x54, 0x40, 0x1C, + 0xC0, 0xB2, 0x98, 0x42, 0xED, 0xD3, 0x0D, 0x49, 0x0E, 0x48, 0x80, 0x39, + 0x8A, 0x68, 0xC2, 0x80, 0x0B, 0x4A, 0x12, 0x7A, 0x01, 0x2A, 0x03, 0xD1, + 0x62, 0x46, 0xD3, 0x79, 0x09, 0x69, 0xC1, 0x80, 0x81, 0x88, 0x10, 0x22, + 0x11, 0x43, 0x81, 0x80, 0x69, 0x46, 0x01, 0x81, 0x43, 0x80, 0x31, 0x21, + 0x01, 0x80, 0x81, 0x88, 0xC9, 0x06, 0xFC, 0xD5, 0xFE, 0xBD, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x20, 0x40, 0x00, 0x00, 0x20, 0x00, 0x11, 0x00, 0x40, + 0xF7, 0xB5, 0x1B, 0x48, 0x84, 0xB0, 0xC0, 0x6B, 0x0F, 0x46, 0x05, 0x79, + 0x00, 0x20, 0x14, 0x46, 0x01, 0xAE, 0x01, 0x46, 0x02, 0x46, 0x07, 0xC6, + 0x0C, 0x3E, 0x2A, 0x46, 0x01, 0xA8, 0xFC, 0xF7, 0x83, 0xFD, 0xAC, 0x42, + 0x00, 0xD9, 0x2C, 0x46, 0x80, 0x23, 0x04, 0x9A, 0x00, 0x20, 0x61, 0x1E, + 0x1F, 0x43, 0x1A, 0x43, 0x06, 0xE0, 0x88, 0x42, 0x01, 0xDA, 0x37, 0x54, + 0x00, 0xE0, 0x32, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0xA0, 0x42, 0xF6, 0xD3, + 0x09, 0x48, 0x40, 0x30, 0x81, 0x68, 0x09, 0x48, 0xC1, 0x80, 0x81, 0x88, + 0x10, 0x22, 0x11, 0x43, 0x81, 0x80, 0x01, 0xA9, 0x01, 0x81, 0x45, 0x80, + 0x31, 0x21, 0x01, 0x80, 0x81, 0x88, 0xC9, 0x06, 0xFC, 0xD5, 0x07, 0xB0, + 0xF0, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0x00, 0x11, 0x00, 0x40, + 0x41, 0x01, 0x0A, 0x48, 0x02, 0x88, 0x20, 0x23, 0x1A, 0x40, 0x88, 0x32, + 0x02, 0x80, 0xC2, 0x13, 0x11, 0x43, 0x01, 0x81, 0x41, 0x88, 0x01, 0x88, + 0x08, 0x22, 0x91, 0x43, 0x01, 0x80, 0xAA, 0x21, 0x81, 0x80, 0x01, 0x88, + 0x19, 0x43, 0x01, 0x80, 0x70, 0x47, 0x00, 0x00, 0x00, 0x02, 0x00, 0x40, + 0xF0, 0xB5, 0x1A, 0x4B, 0xDB, 0x6B, 0xDC, 0x7A, 0x84, 0x42, 0x28, 0xD9, + 0x9D, 0x7C, 0x28, 0x23, 0x04, 0x46, 0x5C, 0x43, 0x27, 0x46, 0x15, 0x4B, + 0x1E, 0x37, 0xBE, 0x1E, 0x5B, 0x69, 0x01, 0x2D, 0x1E, 0xD0, 0x9D, 0x5B, + 0xDE, 0x5B, 0x1F, 0x5D, 0x00, 0x01, 0x01, 0x2F, 0x1B, 0xD0, 0x02, 0x2F, + 0x19, 0xD0, 0x00, 0x27, 0x1F, 0x55, 0x2B, 0x09, 0x08, 0x70, 0x2C, 0x01, + 0x35, 0x07, 0x4B, 0x70, 0x30, 0x09, 0x2D, 0x0F, 0x88, 0x70, 0x2C, 0x43, + 0xCC, 0x70, 0x0D, 0x78, 0x5B, 0x19, 0xC0, 0x18, 0x20, 0x18, 0x00, 0x07, + 0x00, 0x0F, 0x08, 0x71, 0x10, 0x78, 0x40, 0x1D, 0x10, 0x70, 0xF0, 0xBD, + 0xDD, 0x5B, 0x9E, 0x5B, 0xDF, 0xE7, 0x80, 0x1D, 0xE5, 0xE7, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x23, 0x4B, 0x96, 0x00, 0xDC, 0x69, + 0x5D, 0x6A, 0xA4, 0x19, 0xAD, 0x18, 0x01, 0x28, 0x03, 0xD1, 0x9C, 0x69, + 0x1B, 0x6A, 0xA4, 0x19, 0x07, 0xE0, 0x1D, 0x4F, 0x80, 0x3F, 0x3F, 0x7A, + 0x01, 0x2F, 0x03, 0xD1, 0x1C, 0x6B, 0x9B, 0x6B, 0xA4, 0x19, 0x9D, 0x18, + 0x22, 0x68, 0x2B, 0x78, 0x54, 0x1E, 0x25, 0x78, 0x9D, 0x43, 0x25, 0x70, + 0x15, 0x78, 0x9D, 0x43, 0x15, 0x70, 0x55, 0x78, 0x9D, 0x43, 0x55, 0x70, + 0x95, 0x78, 0x9D, 0x43, 0x95, 0x70, 0x01, 0x28, 0x0D, 0xD1, 0x00, 0x29, + 0x08, 0xD0, 0x04, 0x29, 0x09, 0xD1, 0x20, 0x78, 0x18, 0x43, 0x20, 0x70, + 0x10, 0x78, 0x18, 0x43, 0x10, 0x70, 0xF0, 0xBD, 0x20, 0x78, 0x98, 0x43, + 0xF7, 0xE7, 0x01, 0x29, 0x03, 0xD1, 0x20, 0x78, 0x18, 0x43, 0x20, 0x70, + 0xF0, 0xBD, 0x02, 0x29, 0x03, 0xD1, 0x50, 0x78, 0x18, 0x43, 0x50, 0x70, + 0xF0, 0xBD, 0x03, 0x29, 0xFC, 0xD1, 0x90, 0x78, 0x18, 0x43, 0x90, 0x70, + 0xF0, 0xBD, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0xF8, 0xB5, 0x47, 0x4C, + 0x22, 0x46, 0xFF, 0x32, 0x41, 0x32, 0x20, 0x34, 0x01, 0x28, 0x2E, 0xD0, + 0x02, 0x28, 0x2E, 0xD0, 0x03, 0x28, 0x32, 0xD0, 0x21, 0x46, 0x01, 0x23, + 0xA0, 0x31, 0x04, 0x28, 0x33, 0xD0, 0x05, 0x28, 0x33, 0xD0, 0x3E, 0x4E, + 0xF7, 0x1D, 0xF9, 0x37, 0x3D, 0x46, 0xE0, 0x36, 0x20, 0x35, 0xB4, 0x46, + 0x06, 0x28, 0x2C, 0xD0, 0x07, 0x28, 0x33, 0xD0, 0x08, 0x28, 0x3F, 0xD0, + 0x38, 0x4D, 0x09, 0x28, 0x3E, 0xD0, 0x0A, 0x28, 0x43, 0xD0, 0x0B, 0x28, + 0x43, 0xD0, 0x0C, 0x28, 0x43, 0xD0, 0x0D, 0x28, 0x43, 0xD0, 0x0E, 0x28, + 0x43, 0xD0, 0x0F, 0x28, 0x43, 0xD0, 0x01, 0x46, 0x10, 0x39, 0x0B, 0x29, + 0x46, 0xD8, 0x06, 0x21, 0x61, 0x75, 0x20, 0x74, 0x44, 0xE0, 0x07, 0x21, + 0x22, 0xE0, 0x2E, 0x49, 0x2C, 0x48, 0xC8, 0x60, 0xBF, 0xF3, 0x4F, 0x8F, + 0xFE, 0xE7, 0x01, 0x20, 0xFF, 0xF7, 0x24, 0xFF, 0xFA, 0x20, 0xA0, 0x74, + 0xFE, 0xE7, 0xCB, 0x77, 0x34, 0xE0, 0x4B, 0x77, 0x32, 0xE0, 0x8B, 0x77, + 0x00, 0x23, 0x4B, 0x77, 0x7B, 0x62, 0x6B, 0x70, 0x61, 0x46, 0xCB, 0x70, + 0x63, 0x75, 0x0A, 0xE0, 0x00, 0x26, 0x8E, 0x77, 0x02, 0x26, 0x4E, 0x77, + 0x00, 0x21, 0x79, 0x62, 0x69, 0x70, 0x61, 0x46, 0xCB, 0x70, 0x00, 0x21, + 0x61, 0x75, 0x0F, 0x21, 0x91, 0x71, 0x1B, 0xE0, 0x02, 0x21, 0x15, 0xE0, + 0x00, 0x21, 0x61, 0x75, 0x29, 0x88, 0x20, 0x22, 0x11, 0x43, 0x29, 0x80, + 0x12, 0xE0, 0x63, 0x75, 0x10, 0xE0, 0x03, 0x21, 0x0A, 0xE0, 0x04, 0x21, + 0x08, 0xE0, 0x05, 0x21, 0x06, 0xE0, 0x08, 0x21, 0x04, 0xE0, 0x00, 0x22, + 0x8A, 0x77, 0x02, 0x22, 0x4A, 0x77, 0x0A, 0x21, 0x61, 0x75, 0x01, 0xE0, + 0x1C, 0x28, 0x07, 0xD0, 0x62, 0x7D, 0x09, 0x49, 0x80, 0x31, 0x4B, 0x6C, + 0x9A, 0x70, 0x49, 0x6C, 0xC8, 0x70, 0xF8, 0xBD, 0x09, 0x49, 0x10, 0x20, + 0x88, 0x71, 0x64, 0x21, 0x03, 0x20, 0xFB, 0xF7, 0xB7, 0xFC, 0xFF, 0xF7, + 0xD5, 0xFC, 0xAA, 0x20, 0xA8, 0x80, 0xFD, 0xE7, 0x40, 0x00, 0x00, 0x20, + 0x00, 0x02, 0x00, 0x40, 0x04, 0x00, 0xFA, 0x05, 0x00, 0xED, 0x00, 0xE0, + 0x00, 0x20, 0x00, 0x40, 0x10, 0xB5, 0x0E, 0x48, 0x82, 0x78, 0xFF, 0x38, + 0xAA, 0x23, 0x0D, 0x49, 0x01, 0x38, 0x00, 0x2A, 0x4A, 0x88, 0x06, 0xD0, + 0x80, 0x24, 0x22, 0x43, 0x4A, 0x80, 0x8B, 0x80, 0x00, 0x21, 0x81, 0x74, + 0x10, 0xBD, 0x4A, 0x80, 0x82, 0x7C, 0xFF, 0x2A, 0x02, 0xD2, 0x82, 0x7C, + 0x52, 0x1C, 0x82, 0x74, 0x80, 0x7C, 0x30, 0x28, 0xF4, 0xD2, 0x8B, 0x80, + 0x10, 0xBD, 0x00, 0x00, 0x60, 0x01, 0x00, 0x20, 0x00, 0x02, 0x00, 0x40, + 0xFF, 0xB5, 0x82, 0xB0, 0x1C, 0x46, 0x0A, 0x22, 0xFF, 0x21, 0x02, 0x98, + 0xFC, 0xF7, 0xDC, 0xFC, 0x14, 0x22, 0x00, 0x21, 0x0B, 0x98, 0xFC, 0xF7, + 0xD7, 0xFC, 0x00, 0x21, 0x14, 0xE0, 0x12, 0x48, 0x4D, 0x00, 0x60, 0x53, + 0x00, 0x20, 0x0A, 0xE0, 0x4A, 0x43, 0x12, 0x18, 0x5B, 0x68, 0x52, 0x00, + 0x66, 0x5F, 0x9F, 0x5A, 0xBE, 0x42, 0x01, 0xDA, 0x9A, 0x5A, 0x62, 0x53, + 0x40, 0x1C, 0x0B, 0x4B, 0x1A, 0x78, 0x90, 0x42, 0xF0, 0xDB, 0x49, 0x1C, + 0x08, 0x4A, 0x10, 0x78, 0x81, 0x42, 0xE6, 0xDB, 0x0B, 0x99, 0x0C, 0x9A, + 0x01, 0x92, 0x00, 0x91, 0x02, 0xA8, 0x07, 0xC8, 0x23, 0x46, 0xF9, 0xF7, + 0xFF, 0xFD, 0x06, 0xB0, 0xF0, 0xBD, 0x00, 0x00, 0x01, 0x80, 0xFF, 0xFF, + 0x38, 0x00, 0x00, 0x20, 0x00, 0xB5, 0xFD, 0xF7, 0xCD, 0xFD, 0x03, 0x48, + 0x2F, 0x21, 0x80, 0x6A, 0x00, 0x68, 0x01, 0x70, 0x00, 0xBD, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0x70, 0xB5, 0x29, 0x48, 0x04, 0x21, 0x01, 0x81, + 0xAA, 0x21, 0x81, 0x80, 0x28, 0x21, 0x01, 0x80, 0x26, 0x48, 0xCA, 0x26, + 0x06, 0x70, 0x46, 0x70, 0x25, 0x49, 0x70, 0x20, 0x08, 0x60, 0x23, 0x48, + 0x00, 0x25, 0x20, 0x38, 0xC5, 0x71, 0x24, 0x4C, 0x22, 0x48, 0x14, 0x22, + 0x29, 0x46, 0x60, 0x64, 0xFC, 0xF7, 0xA4, 0xFB, 0x60, 0x6C, 0x06, 0x70, + 0x61, 0x6C, 0x01, 0x20, 0x48, 0x70, 0x60, 0x6C, 0x85, 0x70, 0x60, 0x6C, + 0xC5, 0x70, 0x61, 0x6C, 0x02, 0x20, 0x08, 0x71, 0xFE, 0xF7, 0xC4, 0xF8, + 0x61, 0x6C, 0x88, 0x71, 0x61, 0x6C, 0x00, 0x0A, 0xC8, 0x71, 0x60, 0x6C, + 0x05, 0x72, 0x60, 0x6C, 0x85, 0x72, 0x16, 0x48, 0x61, 0x6C, 0x00, 0x78, + 0xC8, 0x72, 0x61, 0x6C, 0x0A, 0x20, 0x08, 0x73, 0x61, 0x6C, 0x18, 0x20, + 0x48, 0x73, 0x61, 0x6C, 0x03, 0x20, 0x88, 0x73, 0x61, 0x6C, 0xC8, 0x73, + 0x60, 0x6C, 0x05, 0x74, 0xFC, 0xF7, 0x66, 0xFD, 0xFC, 0xF7, 0x34, 0xFD, + 0x3C, 0x20, 0xFF, 0xF7, 0x1D, 0xFE, 0xFC, 0xF7, 0xA5, 0xFC, 0xFC, 0xF7, + 0x5B, 0xFC, 0xFC, 0xF7, 0x09, 0xFD, 0xFC, 0xF7, 0xEF, 0xFC, 0x00, 0xF0, + 0xC5, 0xFC, 0x70, 0xBD, 0x00, 0x02, 0x00, 0x40, 0x20, 0x03, 0x00, 0x40, + 0x00, 0x01, 0x00, 0x40, 0xF6, 0x07, 0x00, 0x20, 0xC0, 0x00, 0x00, 0x20, + 0xF8, 0x73, 0x00, 0x00, 0xF0, 0xB5, 0x34, 0x49, 0x89, 0xB0, 0xC9, 0x6B, + 0x32, 0x4E, 0x8A, 0x79, 0x07, 0x92, 0x09, 0x79, 0x80, 0x3E, 0x31, 0x4F, + 0x06, 0x91, 0x00, 0x28, 0x07, 0xD0, 0x43, 0x20, 0x38, 0x72, 0x28, 0x21, + 0x78, 0x20, 0xFB, 0xF7, 0xCF, 0xFB, 0x75, 0x6C, 0x1F, 0xE0, 0x38, 0x7A, + 0xBF, 0x21, 0x08, 0x40, 0x38, 0x72, 0x38, 0x7A, 0x02, 0x21, 0x08, 0x43, + 0x38, 0x72, 0x28, 0x21, 0x78, 0x20, 0x75, 0x6D, 0xFB, 0xF7, 0xC0, 0xFB, + 0x00, 0x22, 0x11, 0x46, 0x01, 0x20, 0xFF, 0xF7, 0x2F, 0xFE, 0x00, 0x24, + 0x01, 0x22, 0x80, 0x21, 0x01, 0xA8, 0xFE, 0xF7, 0x4D, 0xFB, 0x64, 0x1C, + 0xE4, 0xB2, 0x32, 0x2C, 0xF6, 0xD3, 0x38, 0x7A, 0x81, 0x21, 0x08, 0x43, + 0x38, 0x72, 0x00, 0x27, 0x37, 0x72, 0x02, 0x20, 0xFF, 0xF7, 0xF8, 0xFC, + 0x00, 0x21, 0x02, 0x20, 0xFF, 0xF7, 0xD0, 0xFB, 0x06, 0x98, 0x15, 0x4E, + 0x00, 0x24, 0x47, 0x00, 0x60, 0x3E, 0x19, 0xE0, 0x22, 0x46, 0x00, 0x21, + 0x01, 0x20, 0xFF, 0xF7, 0x0D, 0xFE, 0x20, 0x20, 0x00, 0x90, 0x23, 0x46, + 0x29, 0x46, 0x01, 0xA8, 0x06, 0x9A, 0xFB, 0xF7, 0x49, 0xFD, 0x01, 0x21, + 0x7D, 0x19, 0x22, 0x46, 0x08, 0x46, 0xFF, 0xF7, 0xFF, 0xFD, 0x0B, 0x49, + 0xAA, 0x20, 0x88, 0x80, 0x00, 0x20, 0xB0, 0x74, 0x64, 0x1C, 0xE4, 0xB2, + 0x07, 0x98, 0x84, 0x42, 0xE2, 0xD3, 0x00, 0x21, 0x08, 0x46, 0xFF, 0xF7, + 0xA9, 0xFB, 0x00, 0x20, 0xFF, 0xF7, 0xCA, 0xFC, 0x09, 0xB0, 0xF0, 0xBD, + 0xC0, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x40, 0x00, 0x02, 0x00, 0x40, + 0x70, 0xB5, 0x28, 0x48, 0x54, 0x21, 0x41, 0x72, 0x43, 0x21, 0x01, 0x72, + 0x27, 0x4C, 0x26, 0x48, 0x60, 0x80, 0x27, 0x48, 0x21, 0x21, 0x01, 0x74, + 0x10, 0x25, 0x45, 0x74, 0xF1, 0x21, 0x09, 0x01, 0x21, 0x81, 0x11, 0x21, + 0x49, 0x01, 0x61, 0x81, 0xC3, 0x21, 0x81, 0x74, 0xE5, 0x80, 0x41, 0x20, + 0x20, 0x80, 0x02, 0x20, 0xFF, 0xF7, 0x84, 0xFA, 0x01, 0x20, 0xFE, 0xF7, + 0xBB, 0xFD, 0x00, 0x20, 0xFE, 0xF7, 0xB8, 0xFD, 0xE5, 0x80, 0x00, 0x21, + 0x01, 0x20, 0xFF, 0xF7, 0xE3, 0xF8, 0x00, 0x21, 0x08, 0x46, 0xFF, 0xF7, + 0xDF, 0xF8, 0x01, 0x20, 0xFF, 0xF7, 0x72, 0xFA, 0x15, 0x4A, 0x00, 0x20, + 0x51, 0x6D, 0x13, 0x6E, 0x44, 0x00, 0x1C, 0x5B, 0x53, 0x6F, 0xAA, 0x25, + 0x1B, 0x5C, 0x40, 0x1C, 0x6B, 0x43, 0xE3, 0x18, 0x0B, 0x80, 0x89, 0x1C, + 0x09, 0x28, 0xF2, 0xD3, 0x13, 0x46, 0x51, 0x6D, 0x00, 0x20, 0x80, 0x33, + 0x12, 0x31, 0x94, 0x6F, 0x45, 0x00, 0x65, 0x5B, 0xDC, 0x68, 0xAA, 0x26, + 0x24, 0x5C, 0x40, 0x1C, 0x74, 0x43, 0x2C, 0x19, 0x0C, 0x80, 0x89, 0x1C, + 0x07, 0x28, 0xF2, 0xD3, 0x70, 0xBD, 0x00, 0x00, 0x00, 0x03, 0x00, 0x40, + 0x83, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0xE0, 0x12, 0x00, 0x40, + 0x40, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x01, 0x46, 0x20, 0x48, 0x85, 0xB0, + 0x42, 0x8A, 0x01, 0x92, 0x02, 0x8A, 0x00, 0x92, 0x1E, 0x4A, 0x42, 0x80, + 0x1E, 0x4A, 0x02, 0x80, 0x1E, 0x4A, 0x11, 0x23, 0x53, 0x74, 0x35, 0x23, + 0x13, 0x74, 0x00, 0x22, 0xC2, 0x81, 0x1C, 0x4E, 0x14, 0x46, 0xF0, 0x6B, + 0x05, 0x79, 0xC7, 0x78, 0x68, 0x00, 0x40, 0x18, 0x02, 0x91, 0x03, 0x90, + 0x06, 0xE0, 0x22, 0x46, 0x01, 0x21, 0x00, 0x20, 0xFF, 0xF7, 0x68, 0xFD, + 0x64, 0x1C, 0xE4, 0xB2, 0xAC, 0x42, 0xF6, 0xD3, 0x00, 0x24, 0x06, 0xE0, + 0x01, 0x21, 0x22, 0x46, 0x08, 0x46, 0xFF, 0xF7, 0x5D, 0xFD, 0x64, 0x1C, + 0xE4, 0xB2, 0xBC, 0x42, 0xF6, 0xD3, 0x01, 0x22, 0xB3, 0x6A, 0x28, 0x46, + 0x02, 0x99, 0xFE, 0xF7, 0x63, 0xF9, 0x00, 0x22, 0xF3, 0x6A, 0x38, 0x46, + 0x03, 0x99, 0xFE, 0xF7, 0x5D, 0xF9, 0x03, 0x48, 0x01, 0x99, 0x41, 0x82, + 0x00, 0x99, 0x01, 0x82, 0x05, 0xB0, 0xF0, 0xBD, 0x00, 0x10, 0x00, 0x40, + 0x82, 0x10, 0x00, 0x00, 0x45, 0x08, 0x00, 0x00, 0xE0, 0x12, 0x00, 0x40, + 0xC0, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x28, 0x4C, 0x00, 0x20, 0x87, 0xB0, + 0x07, 0x46, 0x65, 0x69, 0x07, 0xE0, 0x28, 0x21, 0x41, 0x43, 0x6A, 0x5C, + 0x03, 0x2A, 0x00, 0xD1, 0x6F, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0xE1, 0x6B, + 0xC9, 0x7A, 0x81, 0x42, 0xF3, 0xD8, 0xE0, 0x6B, 0x69, 0x46, 0x02, 0x79, + 0x8A, 0x70, 0xC2, 0x78, 0x4A, 0x70, 0x01, 0x46, 0x40, 0x31, 0x0A, 0x46, + 0x0B, 0x89, 0x69, 0x46, 0xCB, 0x81, 0x52, 0x89, 0x0A, 0x82, 0x18, 0x4E, + 0xC0, 0x7A, 0x08, 0x70, 0x80, 0x3E, 0x70, 0x7C, 0x0A, 0x22, 0x40, 0x1C, + 0xC8, 0x70, 0x01, 0x20, 0x08, 0x71, 0x14, 0x20, 0x48, 0x71, 0x8A, 0x71, + 0xCF, 0x71, 0x08, 0x72, 0x28, 0x20, 0x48, 0x72, 0x88, 0x72, 0x46, 0x20, + 0xC8, 0x72, 0x0F, 0x73, 0x0E, 0x48, 0x05, 0x90, 0xF1, 0x79, 0x6A, 0x46, + 0x63, 0x69, 0x20, 0x69, 0xFB, 0xF7, 0xA8, 0xF8, 0x77, 0x72, 0x00, 0x20, + 0xE2, 0x6B, 0x09, 0xE0, 0x28, 0x21, 0x41, 0x43, 0x69, 0x5C, 0x00, 0x29, + 0x02, 0xD0, 0x71, 0x7A, 0x49, 0x1C, 0x71, 0x72, 0x40, 0x1C, 0xC0, 0xB2, + 0xD1, 0x7A, 0x81, 0x42, 0xF2, 0xD8, 0x07, 0xB0, 0xF0, 0xBD, 0x00, 0x00, + 0xC0, 0x00, 0x00, 0x20, 0x4D, 0x3A, 0x00, 0x00, 0x07, 0x49, 0x00, 0x22, + 0x0A, 0x70, 0x07, 0x4A, 0x11, 0x23, 0x93, 0x80, 0x43, 0x23, 0x13, 0x80, + 0x02, 0xE0, 0x00, 0x28, 0x00, 0xD1, 0x30, 0xBF, 0x0A, 0x78, 0x00, 0x2A, + 0xF9, 0xD0, 0x70, 0x47, 0x20, 0x01, 0x00, 0x20, 0x00, 0x10, 0x00, 0x40, + 0xFC, 0xB5, 0x39, 0x49, 0x0B, 0x46, 0xDC, 0x1D, 0xF9, 0x34, 0xC8, 0x78, + 0x62, 0x7F, 0x20, 0x33, 0x94, 0x46, 0x14, 0x28, 0x02, 0xD3, 0xA0, 0x7F, + 0x00, 0x28, 0x02, 0xD0, 0x60, 0x46, 0x00, 0x28, 0x5F, 0xD0, 0x31, 0x48, + 0x30, 0x49, 0x80, 0x30, 0xC2, 0x6B, 0xD0, 0x78, 0x15, 0x79, 0x68, 0x43, + 0x01, 0x90, 0x4F, 0x6D, 0x8D, 0x6C, 0x48, 0x6C, 0x00, 0x21, 0x00, 0x91, + 0x2A, 0x49, 0x1E, 0x79, 0x20, 0x31, 0x49, 0x79, 0x00, 0x2E, 0x08, 0xD0, + 0x49, 0x1C, 0xC9, 0xB2, 0x59, 0x71, 0x64, 0x29, 0x07, 0xD9, 0x01, 0x21, + 0x00, 0x91, 0x00, 0x21, 0x02, 0xE0, 0x00, 0x29, 0x01, 0xD0, 0x49, 0x1E, + 0x59, 0x71, 0x61, 0x46, 0x00, 0x29, 0x04, 0xD0, 0x21, 0x7F, 0x00, 0x29, + 0x01, 0xD1, 0x01, 0x21, 0x00, 0x91, 0x20, 0x32, 0x11, 0x7D, 0x8C, 0x46, + 0x51, 0x7D, 0x8E, 0x46, 0x61, 0x46, 0x7F, 0x29, 0x01, 0xD9, 0x7F, 0x21, + 0x8C, 0x46, 0x71, 0x46, 0x7F, 0x29, 0x01, 0xD9, 0x7F, 0x21, 0x8E, 0x46, + 0x15, 0x49, 0x00, 0x24, 0x0A, 0x6C, 0x20, 0xE0, 0x00, 0x99, 0x00, 0x29, + 0x02, 0xD0, 0x29, 0x88, 0x01, 0x80, 0x14, 0xE0, 0x19, 0x79, 0x00, 0x29, + 0x11, 0xD1, 0x51, 0x56, 0x3E, 0x88, 0x89, 0x19, 0x09, 0xB2, 0x61, 0x45, + 0x02, 0xDD, 0x01, 0x88, 0x49, 0x1E, 0x05, 0xE0, 0x76, 0x46, 0x76, 0x42, + 0xB1, 0x42, 0x03, 0xDA, 0x01, 0x88, 0x49, 0x1C, 0x01, 0x80, 0x00, 0x21, + 0x11, 0x70, 0x52, 0x1C, 0xAD, 0x1C, 0xBF, 0x1C, 0x80, 0x1C, 0x64, 0x1C, + 0xE4, 0xB2, 0x01, 0x99, 0x8C, 0x42, 0xDB, 0xD3, 0xFC, 0xBD, 0x00, 0x20, + 0x58, 0x71, 0xFC, 0xBD, 0x40, 0x00, 0x00, 0x20, 0xFF, 0xB5, 0x42, 0x4D, + 0x81, 0xB0, 0x18, 0x46, 0xAB, 0x78, 0x0A, 0x9F, 0x5B, 0x1C, 0x0B, 0x9E, + 0x0C, 0x99, 0xAB, 0x70, 0x6B, 0x46, 0x9C, 0x88, 0x00, 0x2F, 0x00, 0xD0, + 0x14, 0x1B, 0x6B, 0x46, 0x1C, 0x80, 0xDC, 0x88, 0x00, 0x2E, 0x00, 0xD0, + 0x04, 0x1B, 0x6B, 0x46, 0x5C, 0x80, 0x00, 0x29, 0x12, 0xD0, 0x13, 0x18, + 0x5C, 0x08, 0x01, 0x29, 0x26, 0xD0, 0x02, 0x29, 0x2D, 0xD0, 0x03, 0x29, + 0x0A, 0xD1, 0x6B, 0x46, 0x19, 0x88, 0x5B, 0x88, 0x80, 0x1A, 0xE4, 0x1A, + 0x6B, 0x46, 0x40, 0x10, 0x1C, 0x80, 0x40, 0x18, 0x6B, 0x46, 0x58, 0x80, + 0x2C, 0x4C, 0x28, 0x78, 0x62, 0x78, 0xC3, 0x07, 0x91, 0x00, 0x08, 0x19, + 0x80, 0x34, 0x00, 0x2B, 0x1F, 0xD0, 0x00, 0x21, 0x29, 0x70, 0x52, 0x1C, + 0x6A, 0x70, 0x6B, 0x46, 0x19, 0x88, 0x81, 0x80, 0x5A, 0x88, 0xC2, 0x80, + 0x62, 0x80, 0x22, 0x80, 0xE1, 0x80, 0xA1, 0x80, 0x05, 0xB0, 0xF0, 0xBD, + 0x6B, 0x46, 0x10, 0x1A, 0x5A, 0x88, 0x40, 0x10, 0x19, 0x88, 0x80, 0x18, + 0x18, 0x80, 0x60, 0x1A, 0xDC, 0xE7, 0x6B, 0x46, 0x59, 0x88, 0x40, 0x1A, + 0x58, 0x80, 0x18, 0x88, 0x10, 0x1A, 0x18, 0x80, 0xD6, 0xE7, 0x18, 0x4A, + 0x6B, 0x46, 0x47, 0x88, 0x52, 0x5A, 0x59, 0x88, 0x18, 0x88, 0x0D, 0x46, + 0x06, 0x46, 0x3B, 0x46, 0xFB, 0xF7, 0x64, 0xFA, 0x02, 0x99, 0x88, 0x42, + 0x1D, 0xD3, 0x11, 0x4A, 0x50, 0x78, 0x1E, 0x28, 0x19, 0xD2, 0x81, 0x00, + 0x40, 0x1C, 0x89, 0x18, 0x50, 0x70, 0x8E, 0x80, 0xCD, 0x80, 0x20, 0x88, + 0xA8, 0x42, 0x00, 0xD3, 0x28, 0x46, 0x20, 0x80, 0x60, 0x88, 0xA8, 0x42, + 0x00, 0xD8, 0x28, 0x46, 0x60, 0x80, 0xA0, 0x88, 0xB0, 0x42, 0x00, 0xD3, + 0x30, 0x46, 0xA0, 0x80, 0xE0, 0x88, 0xB0, 0x42, 0x00, 0xD8, 0x30, 0x46, + 0xE0, 0x80, 0x02, 0x48, 0x40, 0x30, 0x86, 0x87, 0xC5, 0x87, 0xBB, 0xE7, + 0xA4, 0x0A, 0x00, 0x20, 0x07, 0xB5, 0x00, 0x2A, 0x0A, 0xD1, 0x02, 0x21, + 0x8A, 0x00, 0x12, 0x18, 0x93, 0x89, 0x13, 0x82, 0x49, 0x1E, 0xD3, 0x89, + 0x09, 0x06, 0x53, 0x82, 0x09, 0x0E, 0xF5, 0xD1, 0x6B, 0x46, 0x99, 0x88, + 0x01, 0x82, 0xD9, 0x88, 0x41, 0x82, 0x0E, 0xBD, 0x81, 0x78, 0x49, 0x1E, + 0x81, 0x70, 0x01, 0x79, 0x00, 0x29, 0x03, 0xD0, 0x01, 0x89, 0x81, 0x81, + 0x41, 0x89, 0x02, 0xE0, 0x01, 0x8C, 0x81, 0x81, 0x41, 0x8C, 0xC1, 0x81, + 0x70, 0x47, 0x00, 0x00, 0xF3, 0xB5, 0x04, 0x46, 0x80, 0x78, 0x81, 0xB0, + 0x05, 0x28, 0x01, 0xD2, 0x40, 0x1C, 0xA0, 0x70, 0x1E, 0x4F, 0xA0, 0x78, + 0x39, 0x68, 0xC9, 0x78, 0x88, 0x42, 0x01, 0xD9, 0x01, 0x20, 0x00, 0xE0, + 0x00, 0x20, 0x60, 0x70, 0x6B, 0x46, 0x20, 0x79, 0x1E, 0x89, 0x5D, 0x89, + 0x00, 0x28, 0x1B, 0xD0, 0x60, 0x78, 0x00, 0x28, 0x01, 0xD1, 0x26, 0x81, + 0x65, 0x81, 0x61, 0x89, 0x20, 0x89, 0x2B, 0x46, 0x32, 0x46, 0xFB, 0xF7, + 0xF5, 0xF9, 0x39, 0x68, 0x49, 0x79, 0x88, 0x42, 0x02, 0xD9, 0x00, 0x20, + 0x20, 0x71, 0x09, 0xE0, 0x20, 0x79, 0x00, 0x28, 0x06, 0xD0, 0x20, 0x89, + 0x20, 0x84, 0x61, 0x89, 0x61, 0x84, 0xA0, 0x81, 0xE1, 0x81, 0x01, 0xE0, + 0xA6, 0x81, 0xE5, 0x81, 0x60, 0x79, 0x03, 0x28, 0x01, 0xD2, 0x40, 0x1C, + 0x60, 0x71, 0x60, 0x78, 0x00, 0x28, 0x06, 0xD0, 0x20, 0x78, 0x00, 0x28, + 0x01, 0xD1, 0x01, 0x20, 0x00, 0xE0, 0x02, 0x20, 0x20, 0x70, 0xFE, 0xBD, + 0x34, 0x00, 0x00, 0x20, 0xFF, 0xB5, 0x87, 0xB0, 0x04, 0x46, 0x00, 0x20, + 0x11, 0x9E, 0x0C, 0xE0, 0x28, 0x21, 0x41, 0x43, 0x09, 0x19, 0x89, 0x78, + 0x00, 0x29, 0x01, 0xD0, 0x01, 0x22, 0x00, 0xE0, 0xFF, 0x22, 0x01, 0xA9, + 0x0A, 0x54, 0x40, 0x1C, 0xC0, 0xB2, 0xB0, 0x42, 0xF0, 0xD3, 0x00, 0x25, + 0x67, 0xE0, 0x10, 0x98, 0x40, 0x5D, 0xFF, 0x28, 0x41, 0xD1, 0x00, 0x20, + 0x07, 0xE0, 0x28, 0x21, 0x41, 0x43, 0x09, 0x19, 0x89, 0x78, 0x00, 0x29, + 0x03, 0xD0, 0x40, 0x1C, 0xC0, 0xB2, 0xB0, 0x42, 0xF5, 0xD3, 0xFF, 0x21, + 0xB0, 0x42, 0x00, 0xD2, 0x01, 0x46, 0x04, 0x91, 0xFF, 0x29, 0x4E, 0xD0, + 0x04, 0x98, 0x28, 0x22, 0x50, 0x43, 0x07, 0x19, 0x01, 0x21, 0x3A, 0x48, + 0x39, 0x71, 0x00, 0x68, 0x08, 0x22, 0x81, 0x7A, 0xC0, 0x7A, 0x08, 0x18, + 0x40, 0x08, 0xB8, 0x71, 0x00, 0x20, 0xF8, 0x71, 0x08, 0x99, 0xE8, 0x00, + 0x40, 0x18, 0x06, 0x90, 0x01, 0x88, 0x39, 0x81, 0x40, 0x88, 0x78, 0x81, + 0x38, 0x46, 0x20, 0x30, 0x06, 0x99, 0xF9, 0xF7, 0x65, 0xF9, 0x06, 0x98, + 0x6B, 0x46, 0x01, 0x88, 0x19, 0x80, 0x40, 0x88, 0x58, 0x80, 0x38, 0x46, + 0x00, 0x99, 0xFF, 0xF7, 0x63, 0xFF, 0x06, 0x98, 0xFF, 0x21, 0x00, 0x79, + 0xF8, 0x70, 0x04, 0x98, 0x01, 0xAA, 0x11, 0x54, 0x1F, 0xE0, 0x0A, 0x99, + 0x08, 0x22, 0x08, 0x5C, 0x04, 0x90, 0x08, 0x98, 0xE9, 0x00, 0x0F, 0x18, + 0x04, 0x98, 0x28, 0x21, 0x48, 0x43, 0x00, 0x19, 0x05, 0x90, 0x20, 0x30, + 0x39, 0x46, 0xF9, 0xF7, 0x43, 0xF9, 0x38, 0x88, 0x6B, 0x46, 0x18, 0x80, + 0x78, 0x88, 0x58, 0x80, 0x00, 0x99, 0x05, 0x98, 0xFF, 0xF7, 0x42, 0xFF, + 0x05, 0x98, 0x39, 0x79, 0xC1, 0x70, 0x04, 0x98, 0xFF, 0x22, 0x01, 0xA9, + 0x0A, 0x54, 0x6D, 0x1C, 0xED, 0xB2, 0x09, 0x98, 0x85, 0x42, 0x94, 0xD3, + 0x00, 0x22, 0x1E, 0xE0, 0x01, 0xA8, 0x80, 0x5C, 0xFF, 0x28, 0x18, 0xD0, + 0x10, 0x46, 0x28, 0x21, 0x48, 0x43, 0x21, 0x5C, 0x00, 0x29, 0x0F, 0xD0, + 0x0C, 0x4B, 0x01, 0x19, 0x1B, 0x68, 0x8D, 0x78, 0x1B, 0x79, 0x05, 0x27, + 0xFB, 0x1A, 0x9D, 0x42, 0x06, 0xDC, 0x03, 0x23, 0x23, 0x54, 0x00, 0x20, + 0x48, 0x71, 0x88, 0x70, 0x48, 0x70, 0x02, 0xE0, 0x00, 0x19, 0xFF, 0xF7, + 0x07, 0xFF, 0x52, 0x1C, 0xD2, 0xB2, 0xB2, 0x42, 0xDE, 0xD3, 0x0B, 0xB0, + 0xF0, 0xBD, 0x00, 0x00, 0x34, 0x00, 0x00, 0x20, 0x0E, 0xB5, 0x0E, 0x48, + 0xC0, 0x6B, 0xC0, 0x79, 0x00, 0x28, 0x0F, 0xD0, 0x00, 0x20, 0x02, 0x90, + 0x02, 0xA9, 0x68, 0x46, 0xFD, 0xF7, 0x4C, 0xFF, 0x08, 0x48, 0x6B, 0x46, + 0x60, 0x38, 0x00, 0x7A, 0x00, 0x06, 0x04, 0xD5, 0x19, 0x7A, 0x68, 0x46, + 0xFC, 0xF7, 0x0E, 0xFE, 0x0E, 0xBD, 0x18, 0x7A, 0x00, 0x28, 0xFB, 0xD0, + 0x68, 0x46, 0xFF, 0xF7, 0x8B, 0xF8, 0x0E, 0xBD, 0xC0, 0x00, 0x00, 0x20, + 0x10, 0xB5, 0x00, 0xF0, 0x2F, 0xF8, 0xFA, 0xF7, 0xED, 0xFD, 0xFB, 0xF7, + 0xA1, 0xFA, 0xF9, 0xF7, 0x45, 0xFE, 0xFB, 0xF7, 0xEF, 0xF8, 0x10, 0xBD, + 0xF0, 0xB5, 0x0F, 0x4C, 0x21, 0x78, 0x00, 0x26, 0xAB, 0x29, 0x08, 0xD0, + 0x01, 0x25, 0xAD, 0x07, 0x29, 0x89, 0x08, 0x27, 0xB9, 0x43, 0x29, 0x81, + 0xA0, 0x21, 0x0A, 0x4B, 0x07, 0xE0, 0x26, 0x70, 0xF0, 0xBD, 0x22, 0x78, + 0xAB, 0x2A, 0x05, 0xD0, 0x30, 0xBF, 0x07, 0x4A, 0x91, 0x80, 0x9A, 0x7C, + 0x82, 0x42, 0xF6, 0xD3, 0x26, 0x70, 0x28, 0x89, 0x38, 0x43, 0x28, 0x81, + 0xF0, 0xBD, 0x00, 0x00, 0x11, 0x07, 0x00, 0x20, 0x60, 0x00, 0x00, 0x20, + 0x00, 0x02, 0x00, 0x40, 0x03, 0x48, 0x00, 0xE0, 0x00, 0xBF, 0x41, 0x78, + 0x00, 0x29, 0xFB, 0xD0, 0x70, 0x47, 0x00, 0x00, 0x20, 0x01, 0x00, 0x20, + 0x70, 0xB5, 0x06, 0x46, 0x0D, 0x4C, 0xAA, 0x20, 0xA0, 0x80, 0x0D, 0x4D, + 0x00, 0x20, 0xA8, 0x74, 0x32, 0x20, 0xFF, 0xF7, 0x07, 0xFA, 0x22, 0x88, + 0x28, 0x46, 0x60, 0x30, 0x40, 0x6C, 0xA0, 0x21, 0x03, 0xE0, 0x43, 0x79, + 0x00, 0x2B, 0x03, 0xD0, 0xA1, 0x80, 0xAB, 0x7C, 0xB3, 0x42, 0xF8, 0xD3, + 0x22, 0x80, 0x05, 0x20, 0xFF, 0xF7, 0xF6, 0xF9, 0x70, 0xBD, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x40, 0x60, 0x00, 0x00, 0x20, 0xF0, 0xB5, 0x4F, 0x48, + 0x3A, 0x21, 0xC0, 0x6B, 0x89, 0xB0, 0x0E, 0x5C, 0x41, 0x7D, 0x02, 0x91, + 0x01, 0x78, 0x01, 0x91, 0x4A, 0x49, 0x4A, 0x4C, 0x80, 0x31, 0x08, 0x91, + 0x49, 0x88, 0x40, 0x34, 0x0A, 0x29, 0x03, 0xD9, 0x00, 0x20, 0x20, 0x76, + 0x09, 0xB0, 0xF0, 0xBD, 0xC1, 0x78, 0x03, 0x91, 0x05, 0x79, 0x43, 0x48, + 0x80, 0x38, 0x01, 0x6E, 0x02, 0x6A, 0x8C, 0x46, 0x00, 0x21, 0x08, 0x46, + 0x07, 0x92, 0x2D, 0xE0, 0x43, 0x00, 0x9E, 0x46, 0x63, 0x44, 0x1F, 0x46, + 0x20, 0x3F, 0x06, 0x93, 0xFF, 0x8B, 0x6B, 0x46, 0x1F, 0x82, 0x73, 0x46, + 0x67, 0x46, 0xFF, 0x5E, 0x6B, 0x46, 0x5F, 0x82, 0x06, 0x9B, 0xBE, 0x46, + 0x5F, 0x88, 0x6B, 0x46, 0x9F, 0x82, 0x00, 0x28, 0x02, 0xD1, 0x00, 0x27, + 0x1F, 0x82, 0x05, 0xE0, 0x6B, 0x1E, 0x98, 0x42, 0x02, 0xD1, 0x00, 0x27, + 0x6B, 0x46, 0x9F, 0x82, 0xD3, 0x07, 0x0B, 0xD0, 0x6B, 0x46, 0x10, 0x27, + 0xDF, 0x5F, 0xB7, 0x42, 0x06, 0xDA, 0xB6, 0x45, 0x04, 0xDA, 0x14, 0x27, + 0xDF, 0x5F, 0xB7, 0x42, 0x00, 0xDA, 0x49, 0x1C, 0x52, 0x08, 0x40, 0x1C, + 0xA8, 0x42, 0xCF, 0xD3, 0x26, 0x48, 0x40, 0x30, 0x00, 0x7E, 0x00, 0x29, + 0x25, 0xD0, 0x02, 0x9A, 0x12, 0xB2, 0x90, 0x42, 0x03, 0xDA, 0x49, 0x1C, + 0x49, 0x08, 0x40, 0x18, 0x20, 0x76, 0x20, 0x7E, 0x90, 0x42, 0x26, 0xDB, + 0x1E, 0x4A, 0x80, 0x3A, 0x90, 0x69, 0x00, 0x28, 0x02, 0xD0, 0x07, 0x99, + 0x01, 0x42, 0x0F, 0xD1, 0x56, 0x6D, 0x91, 0x6C, 0x50, 0x6C, 0x03, 0x9A, + 0x6A, 0x43, 0x55, 0x00, 0x2A, 0x46, 0xFB, 0xF7, 0xC5, 0xFE, 0x2A, 0x46, + 0x00, 0x21, 0x30, 0x46, 0xFB, 0xF7, 0xD0, 0xFE, 0x00, 0x20, 0x20, 0x76, + 0xC8, 0x20, 0x60, 0x76, 0x0B, 0xE0, 0x61, 0x7E, 0x00, 0x29, 0x04, 0xD0, + 0x07, 0x9A, 0x00, 0x2A, 0x01, 0xD1, 0x49, 0x1E, 0x61, 0x76, 0x00, 0x28, + 0x01, 0xD0, 0x40, 0x1E, 0x20, 0x76, 0x08, 0x98, 0x40, 0x7F, 0x00, 0x28, + 0x02, 0xD0, 0x00, 0x20, 0x60, 0x76, 0x83, 0xE7, 0x60, 0x7E, 0x32, 0x28, + 0x80, 0xD9, 0x81, 0x08, 0x01, 0x98, 0x08, 0x18, 0x04, 0x49, 0xC0, 0xB2, + 0x80, 0x39, 0x08, 0x70, 0x64, 0x28, 0xF2, 0xD9, 0x64, 0x20, 0x08, 0x70, + 0x74, 0xE7, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x20, 0x03, 0x48, 0x00, 0x21, + 0x01, 0x76, 0x41, 0x76, 0x81, 0x76, 0xC1, 0x76, 0x70, 0x47, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x20, 0xF0, 0xB5, 0x4C, 0x4F, 0xB3, 0xB0, 0x38, 0x7C, + 0x4B, 0x4D, 0xE9, 0x6B, 0x4A, 0x7C, 0x01, 0x21, 0x91, 0x40, 0x08, 0x43, + 0x38, 0x74, 0xFE, 0xF7, 0x6D, 0xFE, 0x00, 0x26, 0x2C, 0x46, 0x60, 0x3C, + 0xA6, 0x74, 0x32, 0x20, 0xFF, 0xF7, 0x30, 0xF9, 0x00, 0x20, 0xFB, 0xF7, + 0x27, 0xF8, 0xE6, 0x75, 0x7B, 0xE0, 0x21, 0x7C, 0x00, 0x20, 0x10, 0x39, + 0x0B, 0x00, 0xF9, 0xF7, 0x43, 0xF9, 0x09, 0x06, 0x06, 0x27, 0x2C, 0x31, + 0x42, 0x52, 0x5C, 0x68, 0x6C, 0x00, 0x3D, 0x48, 0x3B, 0x49, 0x41, 0x80, + 0x10, 0x21, 0xC1, 0x80, 0x11, 0x21, 0x49, 0x01, 0x41, 0x81, 0x38, 0x49, + 0x72, 0x39, 0x01, 0x81, 0x38, 0x48, 0x93, 0x21, 0x81, 0x74, 0x11, 0x21, + 0x41, 0x74, 0x13, 0x21, 0x01, 0x74, 0x54, 0x20, 0x78, 0x72, 0x20, 0x7C, + 0x10, 0x28, 0x07, 0xD0, 0x00, 0x20, 0xFF, 0xF7, 0xFF, 0xFA, 0x20, 0x7C, + 0x69, 0x6C, 0x48, 0x72, 0x26, 0x74, 0x48, 0xE0, 0x01, 0x20, 0xF6, 0xE7, + 0x68, 0x46, 0xFF, 0xF7, 0xC1, 0xFB, 0x12, 0x20, 0xF4, 0xE7, 0x68, 0x46, + 0xFC, 0xF7, 0x98, 0xFF, 0x13, 0x20, 0xEF, 0xE7, 0x29, 0x49, 0x20, 0x20, + 0x08, 0x60, 0xFD, 0xF7, 0x99, 0xFA, 0x30, 0xBF, 0x69, 0x6C, 0x14, 0x20, + 0x48, 0x72, 0x26, 0x49, 0xA0, 0x20, 0x08, 0x80, 0x23, 0x49, 0x20, 0x20, + 0x80, 0x39, 0x08, 0x60, 0x2F, 0xE0, 0x69, 0x6C, 0x15, 0x20, 0x48, 0x72, + 0xFE, 0xF7, 0xDA, 0xFE, 0x38, 0x78, 0x10, 0x21, 0x08, 0x43, 0x38, 0x70, + 0x80, 0x20, 0xF8, 0x71, 0xFD, 0xF7, 0x80, 0xFA, 0xFA, 0xF7, 0xA4, 0xFE, + 0xFC, 0xE7, 0x69, 0x6C, 0x16, 0x20, 0x48, 0x72, 0x39, 0x7C, 0xE8, 0x6B, + 0x42, 0x7C, 0x01, 0x20, 0x90, 0x40, 0x01, 0x43, 0x08, 0xE0, 0x69, 0x6C, + 0x17, 0x20, 0x48, 0x72, 0x39, 0x7C, 0xE8, 0x6B, 0x42, 0x7C, 0x01, 0x20, + 0x90, 0x40, 0x81, 0x43, 0x39, 0x74, 0x26, 0x74, 0x09, 0xE0, 0xFF, 0xF7, + 0x25, 0xFB, 0x18, 0x20, 0xB4, 0xE7, 0x00, 0x28, 0x03, 0xD0, 0x32, 0x21, + 0x68, 0x46, 0xFD, 0xF7, 0x3D, 0xFC, 0x0A, 0x49, 0xA0, 0x20, 0x88, 0x80, + 0xA6, 0x74, 0x60, 0x7D, 0x06, 0x28, 0x80, 0xD0, 0x33, 0xB0, 0xF0, 0xBD, + 0x00, 0x03, 0x00, 0x40, 0xC0, 0x00, 0x00, 0x20, 0x82, 0x10, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x40, 0xE0, 0x12, 0x00, 0x40, 0x80, 0xE1, 0x00, 0xE0, + 0x00, 0x02, 0x00, 0x40, 0x70, 0xB5, 0x25, 0x49, 0x01, 0x20, 0x48, 0x70, + 0x0C, 0x46, 0xC0, 0x3C, 0xE1, 0x7C, 0x01, 0x43, 0xE1, 0x74, 0x20, 0x7D, + 0xFD, 0x21, 0x08, 0x40, 0x20, 0x75, 0x20, 0x7D, 0xFB, 0x21, 0x08, 0x40, + 0x20, 0x75, 0x20, 0x7D, 0xF7, 0x21, 0x08, 0x40, 0x20, 0x75, 0x1C, 0x4D, + 0x00, 0x20, 0x28, 0x60, 0x2E, 0xE0, 0xFD, 0xF7, 0x69, 0xFC, 0x28, 0x68, + 0x40, 0x1C, 0x28, 0x60, 0x01, 0x20, 0xFA, 0xF7, 0x75, 0xFF, 0xF9, 0xF7, + 0x51, 0xFE, 0xFC, 0xF7, 0x07, 0xFD, 0xFE, 0xF7, 0x91, 0xFA, 0xFD, 0xF7, + 0x43, 0xFE, 0xF9, 0xF7, 0x71, 0xFC, 0xFF, 0xF7, 0x7F, 0xFE, 0xF9, 0xF7, + 0xE3, 0xFF, 0xFF, 0xF7, 0xE9, 0xFB, 0xFA, 0xF7, 0x15, 0xFF, 0xFA, 0xF7, + 0x61, 0xF9, 0xFA, 0xF7, 0xBB, 0xFE, 0xFF, 0xF7, 0xF5, 0xFD, 0x0B, 0x48, + 0xF9, 0xF7, 0x40, 0xFF, 0xFD, 0xF7, 0xA8, 0xF8, 0xFF, 0xF7, 0x70, 0xFB, + 0xFB, 0xF7, 0x0A, 0xFA, 0xFF, 0xF7, 0x3C, 0xFE, 0xFD, 0xF7, 0xFC, 0xFB, + 0xFD, 0xF7, 0x12, 0xF9, 0x60, 0x7D, 0x06, 0x28, 0xCD, 0xD1, 0x70, 0xBD, + 0x20, 0x01, 0x00, 0x20, 0x28, 0x00, 0x00, 0x20, 0xD1, 0x20, 0x00, 0x00, + 0x3C, 0x14, 0x32, 0x07, 0x09, 0x09, 0x07, 0x00, 0x00, 0x08, 0x06, 0x02, + 0x08, 0x01, 0x01, 0x05, 0x03, 0x00, 0x00, 0x06, 0x04, 0x28, 0x28, 0x1E, + 0x32, 0x00, 0xD8, 0xE2, 0x00, 0x00, 0x01, 0x02, 0x03, 0x02, 0x0A, 0x18, + 0x03, 0x03, 0x00, 0x14, 0x10, 0x01, 0x02, 0x01, 0xC8, 0x03, 0x0A, 0x18, + 0x5A, 0x5A, 0x00, 0x00, 0x78, 0x78, 0x00, 0x00, 0x01, 0x01, 0x19, 0x41, + 0x00, 0x00, 0x9C, 0xFF, 0x20, 0x0F, 0x10, 0x03, 0x03, 0x08, 0x90, 0x01, + 0x2C, 0x01, 0x2C, 0x01, 0x90, 0x01, 0x80, 0x02, 0x20, 0x00, 0xEC, 0xFF, + 0x1A, 0x00, 0x1A, 0x00, 0x04, 0x03, 0x05, 0x02, 0x01, 0x00, 0x08, 0x09, + 0x06, 0x05, 0x03, 0x01, 0x02, 0x09, 0x07, 0x00, 0x17, 0x03, 0x13, 0x02, + 0x11, 0x07, 0x00, 0x04, 0x15, 0x05, 0x14, 0x01, 0x12, 0x10, 0x23, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x03, 0x00, 0x40, 0x41, 0x03, 0x00, 0x40, 0x49, 0x03, 0x00, 0x40, + 0x41, 0x03, 0x00, 0x40, 0x49, 0x03, 0x00, 0x40, 0x41, 0x03, 0x00, 0x40, + 0x41, 0x03, 0x00, 0x40, 0x41, 0x03, 0x00, 0x40, 0x49, 0x03, 0x00, 0x40, + 0x41, 0x03, 0x00, 0x40, 0x49, 0x03, 0x00, 0x40, 0x41, 0x03, 0x00, 0x40, + 0x49, 0x03, 0x00, 0x40, 0x49, 0x03, 0x00, 0x40, 0x51, 0x03, 0x00, 0x40, + 0x41, 0x03, 0x00, 0x40, 0x80, 0x08, 0x08, 0x04, 0x02, 0x80, 0x01, 0x10, + 0x20, 0x20, 0x10, 0x02, 0x04, 0x01, 0x08, 0x40, 0x11, 0x12, 0x00, 0x40, + 0x0D, 0x12, 0x00, 0x40, 0x15, 0x12, 0x00, 0x40, 0x09, 0x12, 0x00, 0x40, + 0x05, 0x12, 0x00, 0x40, 0x01, 0x12, 0x00, 0x40, 0x21, 0x12, 0x00, 0x40, + 0x25, 0x12, 0x00, 0x40, 0x19, 0x12, 0x00, 0x40, 0x15, 0x12, 0x00, 0x40, + 0x0D, 0x12, 0x00, 0x40, 0x05, 0x12, 0x00, 0x40, 0x09, 0x12, 0x00, 0x40, + 0x25, 0x12, 0x00, 0x40, 0x1D, 0x12, 0x00, 0x40, 0x01, 0x12, 0x00, 0x40, + 0x0E, 0x17, 0x11, 0x1B, 0xA6, 0xCE, 0xEC, 0x00, 0x00, 0x14, 0x32, 0x5A, + 0x00, 0x00, 0xA6, 0xCE, 0xEC, 0x00, 0x14, 0x32, 0x5A, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x02, 0x00, 0x05, 0x00, 0x08, 0x00, 0x0A, 0x00, 0x0B, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x09, 0x00, 0x11, 0x00, + 0x1A, 0x00, 0x23, 0x00, 0x26, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, + 0x0A, 0x00, 0x18, 0x00, 0x2E, 0x00, 0x49, 0x00, 0x60, 0x00, 0x69, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x09, 0x00, 0x18, 0x00, 0x37, 0x00, 0x69, 0x00, + 0xA6, 0x00, 0xDA, 0x00, 0xEF, 0x00, 0x01, 0x00, 0x05, 0x00, 0x11, 0x00, + 0x2E, 0x00, 0x69, 0x00, 0xC7, 0x00, 0x3A, 0x01, 0x9C, 0x01, 0xC3, 0x01, + 0x02, 0x00, 0x08, 0x00, 0x1A, 0x00, 0x49, 0x00, 0xA6, 0x00, 0x3A, 0x01, + 0xEE, 0x01, 0x89, 0x02, 0xC7, 0x02, 0x02, 0x00, 0x0A, 0x00, 0x23, 0x00, + 0x60, 0x00, 0xDA, 0x00, 0x9C, 0x01, 0x89, 0x02, 0x55, 0x03, 0xA7, 0x03, + 0x02, 0x00, 0x0B, 0x00, 0x26, 0x00, 0x69, 0x00, 0xEF, 0x00, 0xC3, 0x01, + 0xC7, 0x02, 0xA7, 0x03, 0x00, 0x04, 0x00, 0x08, 0xFF, 0x07, 0xFE, 0x07, + 0xFD, 0x07, 0xFB, 0x07, 0xF8, 0x07, 0xF4, 0x07, 0xF0, 0x07, 0xEC, 0x07, + 0xE6, 0x07, 0xE0, 0x07, 0xDA, 0x07, 0xD3, 0x07, 0xCB, 0x07, 0xC3, 0x07, + 0xBA, 0x07, 0xB0, 0x07, 0xA6, 0x07, 0x9B, 0x07, 0x90, 0x07, 0x84, 0x07, + 0x77, 0x07, 0x6A, 0x07, 0x5D, 0x07, 0x4E, 0x07, 0x40, 0x07, 0x30, 0x07, + 0x20, 0x07, 0x10, 0x07, 0xFF, 0x06, 0xED, 0x06, 0xDB, 0x06, 0xC8, 0x06, + 0xB5, 0x06, 0xA1, 0x06, 0x8D, 0x06, 0x78, 0x06, 0x63, 0x06, 0x4D, 0x06, + 0x37, 0x06, 0x20, 0x06, 0x09, 0x06, 0xF1, 0x05, 0xD9, 0x05, 0xC1, 0x05, + 0xA8, 0x05, 0x8E, 0x05, 0x74, 0x05, 0x5A, 0x05, 0x3F, 0x05, 0x24, 0x05, + 0x08, 0x05, 0xEC, 0x04, 0xD0, 0x04, 0xB3, 0x04, 0x96, 0x04, 0x79, 0x04, + 0x5B, 0x04, 0x3D, 0x04, 0x1E, 0x04, 0x00, 0x04, 0xE0, 0x03, 0xC1, 0x03, + 0xA1, 0x03, 0x81, 0x03, 0x61, 0x03, 0x40, 0x03, 0x20, 0x03, 0xFF, 0x02, + 0xDD, 0x02, 0xBC, 0x02, 0x9A, 0x02, 0x78, 0x02, 0x56, 0x02, 0x34, 0x02, + 0x12, 0x02, 0xEF, 0x01, 0xCC, 0x01, 0xA9, 0x01, 0x86, 0x01, 0x63, 0x01, + 0x40, 0x01, 0x1D, 0x01, 0xF9, 0x00, 0xD6, 0x00, 0xB2, 0x00, 0x8E, 0x00, + 0x6B, 0x00, 0x47, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x09, 0x00, 0x2C, 0x01, 0x2C, 0x01, + 0x20, 0x4E, 0xCA, 0xCA, 0xAA, 0x55, 0xAA, 0x55, 0x62, 0x47, 0x17, 0x92, + 0x06, 0x00, 0x00, 0x01, 0x2D, 0x11, 0x65, 0x57, 0xFF, 0xFF, 0xFF, 0xFF, + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x32, 0xEB, 0x8B, 0xB3, +}; + diff --git a/components/SensorLib/src/REG/CSTxxxConstants.h b/components/SensorLib/src/REG/CSTxxxConstants.h new file mode 100644 index 0000000..18ccd9b --- /dev/null +++ b/components/SensorLib/src/REG/CSTxxxConstants.h @@ -0,0 +1,46 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file CSTxxxConstants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-24 + * + */ + +#pragma once + +#define CSTXXX_SLAVE_ADDRESS (0x15) +#define CST816_SLAVE_ADDRESS (0x15) +#define CST328_SLAVE_ADDRESS (0x1A) +#define CST226SE_SLAVE_ADDRESS (0x5A) + +#define CST816S_CHIP_ID (0xB4) +#define CST816T_CHIP_ID (0xB5) +#define CST716_CHIP_ID (0x20) +#define CST226SE_CHIP_ID (0xA8) + + + + + diff --git a/components/SensorLib/src/REG/DRV2605Constants.h b/components/SensorLib/src/REG/DRV2605Constants.h new file mode 100644 index 0000000..9371a0c --- /dev/null +++ b/components/SensorLib/src/REG/DRV2605Constants.h @@ -0,0 +1,80 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file DRV2605Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-03 + * + */ + +#pragma once + +#define DRV2605_SLAVE_ADDRESS (0x5A) + +#define DRV2604_CHIP_ID (0x04) //* DRV2604 (contains RAM, does not contain licensed ROM library) +#define DRV2605_CHIP_ID (0x03) //* DRV2605 (contains licensed ROM library, does not contain RAM) +#define DRV2604L_CHIP_ID (0x06) //* DRV2604L (low-voltage version of the DRV2604 device) +#define DRV2605L_CHIP_ID (0x07) //* DRV2605L (low-voltage version of the DRV2605 device) + +#define DRV2605_REG_STATUS (0x00) //* Status register +#define DRV2605_REG_MODE (0x01) //* Mode register +#define DRV2605_MODE_INTTRIG (0x00) //* Internal trigger mode +#define DRV2605_MODE_EXTTRIGEDGE (0x01) //* External edge trigger mode +#define DRV2605_MODE_EXTTRIGLVL (0x02) //* External level trigger mode +#define DRV2605_MODE_PWMANALOG (0x03) //* PWM/Analog input mode +#define DRV2605_MODE_AUDIOVIBE (0x04) //* Audio-to-vibe mode +#define DRV2605_MODE_REALTIME (0x05) //* Real-time playback (RTP) mode +#define DRV2605_MODE_DIAGNOS (0x06) //* Diagnostics mode +#define DRV2605_MODE_AUTOCAL (0x07) //* Auto calibration mode +#define DRV2605_REG_RTPIN (0x02) //* Real-time playback input register +#define DRV2605_REG_LIBRARY (0x03) //* Waveform library selection register +#define DRV2605_REG_WAVESEQ1 (0x04) //* Waveform sequence register 1 +#define DRV2605_REG_WAVESEQ2 (0x05) //* Waveform sequence register 2 +#define DRV2605_REG_WAVESEQ3 (0x06) //* Waveform sequence register 3 +#define DRV2605_REG_WAVESEQ4 (0x07) //* Waveform sequence register 4 +#define DRV2605_REG_WAVESEQ5 (0x08) //* Waveform sequence register 5 +#define DRV2605_REG_WAVESEQ6 (0x09) //* Waveform sequence register 6 +#define DRV2605_REG_WAVESEQ7 (0x0A) //* Waveform sequence register 7 +#define DRV2605_REG_WAVESEQ8 (0x0B) //* Waveform sequence register 8 +#define DRV2605_REG_GO (0x0C) //* Go register +#define DRV2605_REG_OVERDRIVE (0x0D) //* Overdrive time offset register +#define DRV2605_REG_SUSTAINPOS (0x0E) //* Sustain time offset, positive register +#define DRV2605_REG_SUSTAINNEG (0x0F) //* Sustain time offset, negative register +#define DRV2605_REG_BREAK (0x10) //* Brake time offset register +#define DRV2605_REG_AUDIOCTRL (0x11) //* Audio-to-vibe control register +#define DRV2605_REG_AUDIOLVL (0x12) //* Audio-to-vibe minimum input level register +#define DRV2605_REG_AUDIOMAX (0x13) //* Audio-to-vibe maximum input level register +#define DRV2605_REG_AUDIOOUTMIN (0x14) //* Audio-to-vibe minimum output drive register +#define DRV2605_REG_AUDIOOUTMAX (0x15) //* Audio-to-vibe maximum output drive register +#define DRV2605_REG_RATEDV (0x16) //* Rated voltage register +#define DRV2605_REG_CLAMPV (0x17) //* Overdrive clamp voltage register +#define DRV2605_REG_AUTOCALCOMP (0x18) //* Auto-calibration compensation result register +#define DRV2605_REG_AUTOCALEMP (0x19) //* Auto-calibration back-EMF result register +#define DRV2605_REG_FEEDBACK (0x1A) //* Feedback control register +#define DRV2605_REG_CONTROL1 (0x1B) //* Control1 Register +#define DRV2605_REG_CONTROL2 (0x1C) //* Control2 Register +#define DRV2605_REG_CONTROL3 (0x1D) //* Control3 Register +#define DRV2605_REG_CONTROL4 (0x1E) //* Control4 Register +#define DRV2605_REG_VBAT (0x21) //* Vbat voltage-monitor register +#define DRV2605_REG_LRARESON (0x22) //* LRA resonance-period register \ No newline at end of file diff --git a/components/SensorLib/src/REG/FT6X36Constants.h b/components/SensorLib/src/REG/FT6X36Constants.h new file mode 100644 index 0000000..6b2362e --- /dev/null +++ b/components/SensorLib/src/REG/FT6X36Constants.h @@ -0,0 +1,65 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file FT6X36Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-01 + * + */ + +#pragma once + +#define FT3267_SLAVE_ADDRESS (0x38) +#define FT5206_SLAVE_ADDRESS (0x38) +#define FT6X36_SLAVE_ADDRESS (0x38) + +#define FT6X36_VEND_ID (0x11) +#define FT3267_CHIP_ID (0x33) +#define FT6206_CHIP_ID (0x06) +#define FT6236_CHIP_ID (0x36) +#define FT6236U_CHIP_ID (0x64) +#define FT5206U_CHIP_ID (0x64) + +#define FT6X36_REG_MODE (0x00) +#define FT6X36_REG_GEST (0x01) +#define FT6X36_REG_STATUS (0x02) +#define FT6X36_REG_TOUCH1_XH (0x03) +#define FT6X36_REG_TOUCH1_XL (0x04) +#define FT6X36_REG_TOUCH1_YH (0x05) +#define FT6X36_REG_TOUCH1_YL (0x06) +#define FT6X36_REG_THRESHOLD (0x80) +#define FT6X36_REG_MONITOR_TIME (0x87) +#define FT6X36_REG_PERIOD_ACTIVE (0x88) +#define FT6X36_REG_PERIOD_MONITOR (0x89) + + +#define FT6X36_REG_AUTO_CLB_MODE (0xA0) +#define FT6X36_REG_LIB_VERSION_H (0xA1) +#define FT6X36_REG_LIB_VERSION_L (0xA2) +#define FT6X36_REG_INT_STATUS (0xA4) +#define FT6X36_REG_POWER_MODE (0xA5) +#define FT6X36_REG_FIRM_VERS (0xA6) +#define FT6X36_REG_CHIP_ID (0xA3) +#define FT6X36_REG_VENDOR1_ID (0xA8) +#define FT6X36_REG_ERROR_STATUS (0xA9) \ No newline at end of file diff --git a/components/SensorLib/src/REG/GT911Constants.h b/components/SensorLib/src/REG/GT911Constants.h new file mode 100644 index 0000000..d8d5271 --- /dev/null +++ b/components/SensorLib/src/REG/GT911Constants.h @@ -0,0 +1,166 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file GT911Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-12 + * + */ + +#pragma once + +#define GT911_SLAVE_ADDRESS_H (0x14) +#define GT911_SLAVE_ADDRESS_L (0x5D) +#define GT911_DEV_ID (911) +#define GT911_BASE_REF_RATE (5) +#define GT911_REG_LENGTH (186) + +// Real-time command (Write only) +#define GT911_COMMAND (0x8040) +#define GT911_ESD_CHECK (0x8041) +#define GT911_COMMAND_CHECK (0x8046) + +// Configuration information (R/W) +#define GT911_CONFIG_START (0x8047) +#define GT911_CONFIG_VERSION (0x8047) +#define GT911_X_OUTPUT_MAX_LOW (0x8048) +#define GT911_X_OUTPUT_MAX_HIGH (0x8049) +#define GT911_Y_OUTPUT_MAX_LOW (0x804A) +#define GT911_Y_OUTPUT_MAX_HIGH (0x804B) +#define GT911_TOUCH_NUMBER (0x804C) +#define GT911_MODULE_SWITCH_1 (0x804D) +#define GT911_MODULE_SWITCH_2 (0x804E) +#define GT911_SHAKE_COUNT (0x804F) +#define GT911_FILTER (0x8050) +#define GT911_LARGE_TOUCH (0x8051) +#define GT911_NOISE_REDUCTION (0x8052) +#define GT911_SCREEN_TOUCH_LEVEL (0x8053) +#define GT911_SCREEN_RELEASE_LEVEL (0x8054) +#define GT911_LOW_POWER_CONTROL (0x8055) +#define GT911_REFRESH_RATE (0x8056) +#define GT911_X_THRESHOLD (0x8057) +#define GT911_Y_THRESHOLD (0x8058) +#define GT911_X_SPEED_LIMIT (0x8059) // Reserve +#define GT911_Y_SPEED_LIMIT (0x805A) // Reserve +#define GT911_SPACE_TOP_BOTTOM (0x805B) +#define GT911_SPACE_LEFT_RIGHT (0x805C) +#define GT911_MINI_FILTER (0x805D) +#define GT911_STRETCH_R0 (0x805E) +#define GT911_STRETCH_R1 (0x805F) +#define GT911_STRETCH_R2 (0x8060) +#define GT911_STRETCH_RM (0x8061) +#define GT911_DRV_GROUPA_NUM (0x8062) +#define GT911_DRV_GROUPB_NUM (0x8063) +#define GT911_SENSOR_NUM (0x8064) +#define GT911_FREQ_A_FACTOR (0x8065) +#define GT911_FREQ_B_FACTOR (0x8066) +#define GT911_PANEL_BIT_FREQ_L (0x8067) +#define GT911_PANEL_BIT_FREQ_H (0x8068) +#define GT911_PANEL_SENSOR_TIME_L (0x8069) // Reserve +#define GT911_PANEL_SENSOR_TIME_H (0x806A) +#define GT911_PANEL_TX_GAIN (0x806B) +#define GT911_PANEL_RX_GAIN (0x806C) +#define GT911_PANEL_DUMP_SHIFT (0x806D) +#define GT911_DRV_FRAME_CONTROL (0x806E) +#define GT911_CHARGING_LEVEL_UP (0x806F) +#define GT911_MODULE_SWITCH3 (0x8070) +#define GT911_GESTURE_DIS (0X8071) +#define GT911_GESTURE_LONG_PRESS_TIME (0x8072) +#define GT911_X_Y_SLOPE_ADJUST (0X8073) +#define GT911_GESTURE_CONTROL (0X8074) +#define GT911_GESTURE_SWITCH1 (0X8075) +#define GT911_GESTURE_SWITCH2 (0X8076) +#define GT911_GESTURE_REFRESH_RATE (0x8077) +#define GT911_GESTURE_TOUCH_LEVEL (0x8078) +#define GT911_NEWGREENWAKEUPLEVEL (0x8079) +#define GT911_FREQ_HOPPING_START (0x807A) +#define GT911_FREQ_HOPPING_END (0X807B) +#define GT911_NOISE_DETECT_TIMES (0x807C) +#define GT911_HOPPING_FLAG (0X807D) +#define GT911_HOPPING_THRESHOLD (0X807E) +#define GT911_NOISE_THRESHOLD (0X807F) // Reserve +#define GT911_NOISE_MIN_THRESHOLD (0X8080) +#define GT911_HOPPING_SENSOR_GROUP (0X8082) +#define GT911_HOPPING_SEG1_NORMALIZE (0X8083) +#define GT911_HOPPING_SEG1_FACTOR (0X8084) +#define GT911_MAIN_CLOCK_AJDUST (0X8085) +#define GT911_HOPPING_SEG2_NORMALIZE (0X8086) +#define GT911_HOPPING_SEG2_FACTOR (0X8087) +#define GT911_HOPPING_SEG3_NORMALIZE (0X8089) +#define GT911_HOPPING_SEG3_FACTOR (0X808A) +#define GT911_HOPPING_SEG4_NORMALIZE (0X808C) +#define GT911_HOPPING_SEG4_FACTOR (0X808D) +#define GT911_HOPPING_SEG5_NORMALIZE (0X808F) +#define GT911_HOPPING_SEG5_FACTOR (0X8090) +#define GT911_HOPPING_SEG6_NORMALIZE (0X8092) +#define GT911_KEY_1 (0X8093) +#define GT911_KEY_2 (0X8094) +#define GT911_KEY_3 (0X8095) +#define GT911_KEY_4 (0X8096) +#define GT911_KEY_AREA (0X8097) +#define GT911_KEY_TOUCH_LEVEL (0X8098) +#define GT911_KEY_LEAVE_LEVEL (0X8099) +#define GT911_KEY_SENS_1_2 (0X809A) +#define GT911_KEY_SENS_3_4 (0X809B) +#define GT911_KEY_RESTRAIN (0X809C) +#define GT911_KEY_RESTRAIN_TIME (0X809D) +#define GT911_GESTURE_LARGE_TOUCH (0X809E) +#define GT911_HOTKNOT_NOISE_MAP (0X80A1) +#define GT911_LINK_THRESHOLD (0X80A2) +#define GT911_PXY_THRESHOLD (0X80A3) +#define GT911_GHOT_DUMP_SHIFT (0X80A4) +#define GT911_GHOT_RX_GAIN (0X80A5) +#define GT911_FREQ_GAIN0 (0X80A6) +#define GT911_FREQ_GAIN1 (0X80A7) +#define GT911_FREQ_GAIN2 (0X80A8) +#define GT911_FREQ_GAIN3 (0X80A9) +#define GT911_COMBINE_DIS (0X80B3) +#define GT911_SPLIT_SET (0X80B4) +#define GT911_SENSOR_CH0 (0X80B7) +#define GT911_DRIVER_CH0 (0X80D5) +#define GT911_CONFIG_CHKSUM (0X80FF) +#define GT911_CONFIG_FRESH (0X8100) +#define GT911_CONFIG_SIZE (0xFF - 0x46) + +// Coordinate information +#define GT911_PRODUCT_ID (0x8140) +#define GT911_FIRMWARE_VERSION (0x8144) +#define GT911_X_RESOLUTION (0x8146) +#define GT911_Y_RESOLUTION (0x8148) + +#define GT911_VENDOR_ID (0X8140) +#define GT911_IMFORMATION (0X8140) +#define GT911_POINT_INFO (0X814E) +#define GT911_POINT_1 (0X814F) +#define GT911_POINT_2 (0X8157) +#define GT911_POINT_3 (0X815F) +#define GT911_POINT_4 (0X8167) +#define GT911_POINT_5 (0X816F) + + +#define GT911_GET_POINT(x) (x & 0x0F) +#define GT911_GET_BUFFER_STATUS(x) (x & 0x80) +#define GT911_GET_HAVE_KEY(x) (x & 0x10) + + diff --git a/components/SensorLib/src/REG/LTR533Constants.h b/components/SensorLib/src/REG/LTR533Constants.h new file mode 100644 index 0000000..9df1278 --- /dev/null +++ b/components/SensorLib/src/REG/LTR533Constants.h @@ -0,0 +1,63 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file LTR533Constants.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-09 + */ +#pragma once + +#define LTR553_SLAVE_ADDRESS (0x23) + +#define LTR553_REG_ALS_CONTR (0x80) +#define LTR553_REG_PS_CONTR (0x81) +#define LTR553_REG_PS_LED (0x82) +#define LTR553_REG_PS_N_PULSES (0x83) +#define LTR553_REG_PS_MEAS_RATE (0x84) +#define LTR553_REG_ALS_MEAS_RATE (0x85) +#define LTR553_REG_PART_ID (0x86) +#define LTR553_REG_MANUFAC_ID (0x87) +#define LTR553_REG_ALS_DATA_CH1_0 (0x88) +#define LTR553_REG_ALS_DATA_CH1_1 (0x89) +#define LTR553_REG_ALS_DATA_CH0_0 (0x8A) +#define LTR553_REG_ALS_DATA_CH0_1 (0x8B) +#define LTR553_REG_ALS_PS_STATUS (0x8C) +#define LTR553_REG_PS_DATA_0 (0x8D) +#define LTR553_REG_PS_DATA_1 (0x8E) +#define LTR553_REG_INTERRUPT (0x8F) +#define LTR553_REG_PS_THRES_UP_0 (0x90) +#define LTR553_REG_PS_THRES_UP_1 (0x91) +#define LTR553_REG_PS_THRES_LOW_0 (0x92) +#define LTR553_REG_PS_THRES_LOW_1 (0x93) +#define LTR553_REG_PS_OFFSET_1 (0x94) +#define LTR553_REG_PS_OFFSET_0 (0x95) +#define LTR553_REG_ALS_THRES_UP_0 (0x97) +#define LTR553_REG_ALS_THRES_UP_1 (0x98) +#define LTR553_REG_ALS_THRES_LOW_0 (0x99) +#define LTR553_REG_ALS_THRES_LOW_1 (0x9A) +#define LTR553_REG_INTERRUPT_PERSIST (0x9E) + + + +#define LTR553_DEFAULT_MAN_ID (0x05) \ No newline at end of file diff --git a/components/SensorLib/src/REG/MPU6886Constants.h b/components/SensorLib/src/REG/MPU6886Constants.h new file mode 100644 index 0000000..459bad2 --- /dev/null +++ b/components/SensorLib/src/REG/MPU6886Constants.h @@ -0,0 +1,115 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file MPU6886Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2022-10-16 + * + */ + +#pragma once + + +#define MPU6886_SLAVE_ADDRESS (0x68) + +#define MPU6886_REG_XG_OFFS_TC_H (0x04) +#define MPU6886_REG_XG_OFFS_TC_L (0x05) +#define MPU6886_REG_YG_OFFS_TC_H (0x07) +#define MPU6886_REG_YG_OFFS_TC_L (0x08) +#define MPU6886_REG_ZG_OFFS_TC_H (0x0A) +#define MPU6886_REG_ZG_OFFS_TC_L (0x0B) +#define MPU6886_REG_SELF_TEST_X_ACCEL (0x0D) +#define MPU6886_REG_SELF_TEST_Y_ACCEL (0x0E) +#define MPU6886_REG_SELF_TEST_Z_ACCEL (0x0F) +#define MPU6886_REG_XG_OFFS_USRH (0x13) +#define MPU6886_REG_XG_OFFS_USRL (0x14) +#define MPU6886_REG_YG_OFFS_USRH (0x15) +#define MPU6886_REG_YG_OFFS_USRL (0x16) +#define MPU6886_REG_ZG_OFFS_USRH (0x17) +#define MPU6886_REG_ZG_OFFS_USRL (0x18) +#define MPU6886_REG_SMPLRT_DIV (0x19) +#define MPU6886_REG_CONFIG (0x1A) +#define MPU6886_REG_GYRO_CONFIG (0x1B) +#define MPU6886_REG_ACCEL_CONFIG (0x1C) +#define MPU6886_REG_ACCEL_CONFIG_2 (0x1D) +#define MPU6886_REG_LP_MODE_CFG (0x1E) +#define MPU6886_REG_ACCEL_WOM_X_THR (0x20) +#define MPU6886_REG_ACCEL_WOM_Y_THR (0x21) +#define MPU6886_REG_ACCEL_WOM_Z_THR (0x22) +#define MPU6886_REG_FIFO_EN (0x23) +#define MPU6886_REG_FSYNC_INT (0x36) +#define MPU6886_REG_INT_PIN_CFG (0x37) +#define MPU6886_REG_INT_ENABLE (0x38) +#define MPU6886_REG_FIFO_WM_INT_STATUS (0x39) +#define MPU6886_REG_INT_STATUS (0x3A) +#define MPU6886_REG_ACCEL_XOUT_H (0x3B) +#define MPU6886_REG_ACCEL_XOUT_L (0x3C) +#define MPU6886_REG_ACCEL_YOUT_H (0x3D) +#define MPU6886_REG_ACCEL_YOUT_L (0x3E) +#define MPU6886_REG_ACCEL_ZOUT_H (0x3F) +#define MPU6886_REG_ACCEL_ZOUT_L (0x40) +#define MPU6886_REG_TEMP_OUT_H (0x41) +#define MPU6886_REG_TEMP_OUT_L (0x42) +#define MPU6886_REG_GYRO_XOUT_H (0x43) +#define MPU6886_REG_GYRO_XOUT_L (0x44) +#define MPU6886_REG_GYRO_YOUT_H (0x45) +#define MPU6886_REG_GYRO_YOUT_L (0x46) +#define MPU6886_REG_GYRO_ZOUT_H (0x47) +#define MPU6886_REG_GYRO_ZOUT_L (0x48) +#define MPU6886_REG_SELF_TEST_X_GYRO (0x50) +#define MPU6886_REG_SELF_TEST_Y_GYRO (0x51) +#define MPU6886_REG_SELF_TEST_Z_GYRO (0x52) +#define MPU6886_REG_E_ID0 (0x53) +#define MPU6886_REG_E_ID1 (0x54) +#define MPU6886_REG_E_ID2 (0x55) +#define MPU6886_REG_E_ID3 (0x56) +#define MPU6886_REG_E_ID4 (0x57) +#define MPU6886_REG_E_ID5 (0x58) +#define MPU6886_REG_E_ID6 (0x59) +#define MPU6886_REG_FIFO_WM_TH1 (0x60) +#define MPU6886_REG_FIFO_WM_TH2 (0x61) +#define MPU6886_REG_SIGNAL_PATH_RESET (0x68) +#define MPU6886_REG_ACCEL_INTEL_CTRL (0x69) +#define MPU6886_REG_USER_CTRL (0x6A) +#define MPU6886_REG_PWR_MGMT_1 (0x6B) +#define MPU6886_REG_PWR_MGMT_2 (0x6C) +#define MPU6886_REG_I2C_IF (0x70) +#define MPU6886_REG_FIFO_COUNTH (0x72) +#define MPU6886_REG_FIFO_COUNTL (0x73) +#define MPU6886_REG_FIFO_R_W (0x74) +#define MPU6886_REG_WHO_AM_I (0x75) +#define MPU6886_REG_XA_OFFSET_H (0x77) +#define MPU6886_REG_XA_OFFSET_L (0x78) +#define MPU6886_REG_YA_OFFSET_H (0x7A) +#define MPU6886_REG_YA_OFFSET_L (0x7B) +#define MPU6886_REG_ZA_OFFSET_H (0x7D) +#define MPU6886_REG_ZA_OFFSET_L (0x7E) + + +#define MPU6886_WHO_AM_I_RES (0x19) + + + + + diff --git a/components/SensorLib/src/REG/PCF85063Constants.h b/components/SensorLib/src/REG/PCF85063Constants.h new file mode 100644 index 0000000..17f89bc --- /dev/null +++ b/components/SensorLib/src/REG/PCF85063Constants.h @@ -0,0 +1,63 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file PCF85063Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-07 + * + */ + +#pragma once + + +#define PCF85063_SLAVE_ADDRESS (0x51) + +#define PCF85063_CTRL1_REG (0x00) +#define PCF85063_CTRL2_REG (0x01) +#define PCF85063_OFFSET_REG (0x02) +#define PCF85063_RAM_REG (0x03) +#define PCF85063_SEC_REG (0x04) +#define PCF85063_MIN_REG (0x05) +#define PCF85063_HR_REG (0x06) +#define PCF85063_DAY_REG (0x07) +#define PCF85063_WEEKDAY_REG (0x08) +#define PCF85063_MONTH_REG (0x09) +#define PCF85063_YEAR_REG (0x0A) +#define PCF85063_ALRM_SEC_REG (0x0B) +#define PCF85063_ALRM_MIN_REG (0x0C) +#define PCF85063_ALRM_HR_REG (0x0D) +#define PCF85063_ALRM_DAY_REG (0x0E) +#define PCF85063_ALRM_WEEK_REG (0x0F) +#define PCF85063_TIMER_VAL_REG (0x10) +#define PCF85063_TIMER_MD_REG (0x11) + +#define PCF85063_CTRL1_TEST_EN_MASK (1<<7u) +#define PCF85063_CTRL1_CLOCK_EN_MASK (1<<5u) +#define PCF85063_CTRL1_SOFTRST_EN_MASK (1<<4u) +#define PCF85063_CTRL1_CIE_EN_MASK (1<<2u) +#define PCF85063_CTRL1_HOUR_FORMAT_12H_MASK (1<<1u) + + +#define PCF85063_NO_ALARM (0xFF) +#define PCF85063_ALARM_ENABLE (0x80) \ No newline at end of file diff --git a/components/SensorLib/src/REG/PCF8563Constants.h b/components/SensorLib/src/REG/PCF8563Constants.h new file mode 100644 index 0000000..685fc05 --- /dev/null +++ b/components/SensorLib/src/REG/PCF8563Constants.h @@ -0,0 +1,70 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file PCF8563Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2022-12-09 + * + */ + +#pragma once + + +#define PCF8563_SLAVE_ADDRESS (0x51) + +#define PCF8563_STAT1_REG (0x00) +#define PCF8563_STAT2_REG (0x01) +#define PCF8563_SEC_REG (0x02) +#define PCF8563_MIN_REG (0x03) +#define PCF8563_HR_REG (0x04) +#define PCF8563_DAY_REG (0x05) +#define PCF8563_WEEKDAY_REG (0x06) +#define PCF8563_MONTH_REG (0x07) +#define PCF8563_YEAR_REG (0x08) +#define PCF8563_ALRM_MIN_REG (0x09) +#define PCF8563_SQW_REG (0x0D) +#define PCF8563_TIMER1_REG (0x0E) +#define PCF8563_TIMER2_REG (0x0F) + +#define PCF8563_VOL_LOW_MASK (0x80) +#define PCF8563_MINUTES_MASK (0x7F) +#define PCF8563_HOUR_MASK (0x3F) +#define PCF8563_WEEKDAY_MASK (0x07) +#define PCF8563_CENTURY_MASK (0x80) +#define PCF8563_DAY_MASK (0x3F) +#define PCF8563_MONTH_MASK (0x1F) +#define PCF8563_TIMER_CTL_MASK (0x03) + + +#define PCF8563_ALARM_AF (0x08) +#define PCF8563_TIMER_TF (0x04) +#define PCF8563_ALARM_AIE (0x02) +#define PCF8563_TIMER_TIE (0x01) +#define PCF8563_TIMER_TE (0x80) +#define PCF8563_TIMER_TD10 (0x03) + +#define PCF8563_NO_ALARM (0xFF) +#define PCF8563_ALARM_ENABLE (0x80) +#define PCF8563_CLK_ENABLE (0x80) + diff --git a/components/SensorLib/src/REG/QMC6310Constants.h b/components/SensorLib/src/REG/QMC6310Constants.h new file mode 100644 index 0000000..4f0fcd0 --- /dev/null +++ b/components/SensorLib/src/REG/QMC6310Constants.h @@ -0,0 +1,53 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file QMC6310Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2022-10-16 + * + */ + +#pragma once + +// @brief device address +#define QMC6310_SLAVE_ADDRESS (0x1C) +#define QMC6310_DEFAULT_ID (0x80) + + +#define QMC6310_REG_CHIP_ID (0x00) +#define QMC6310_REG_LSB_DX (0X01) +#define QMC6310_REG_MSB_DX (0X02) +#define QMC6310_REG_LSB_DY (0X03) +#define QMC6310_REG_MSB_DY (0X04) +#define QMC6310_REG_LSB_DZ (0X05) +#define QMC6310_REG_MSB_DZ (0X06) +#define QMC6310_REG_STAT (0X09) +#define QMC6310_REG_CMD1 (0x0A) +#define QMC6310_REG_CMD2 (0x0B) + + +#define QMC6310_REG_SIGN (0x29) + + + diff --git a/components/SensorLib/src/REG/QMI8658Constants.h b/components/SensorLib/src/REG/QMI8658Constants.h new file mode 100644 index 0000000..ec55bcc --- /dev/null +++ b/components/SensorLib/src/REG/QMI8658Constants.h @@ -0,0 +1,133 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file QMI8658Constants.h + * @author Lewis He (lewishe@outlook.com) + * @date 2022-10-16 + * + */ +#pragma once + +// @brief device address +#define QMI8658_L_SLAVE_ADDRESS (0x6B) +#define QMI8658_H_SLAVE_ADDRESS (0x6A) + + +// @brief registers default value +#define QMI8658_REG_WHOAMI_DEFAULT (0x05) +#define QMI8658_REG_STATUS_DEFAULT (0x03) +#define QMI8658_REG_RESET_DEFAULT (0xB0) + + +// @brief registers list +#define QMI8658_REG_WHOAMI (0x00) +#define QMI8658_REG_REVISION (0x01) +#define QMI8658_REG_CTRL1 (0x02) +#define QMI8658_REG_CTRL2 (0x03) +#define QMI8658_REG_CTRL3 (0x04) +// #define QMI8658_REG_CTRL4 (0x05) +#define QMI8658_REG_CTRL5 (0x06) +// #define QMI8658_REG_CTRL6 (0x07) +#define QMI8658_REG_CTRL7 (0x08) +#define QMI8658_REG_CTRL8 (0x09) +#define QMI8658_REG_CTRL9 (0x0A) + +#define QMI8658_REG_CAL1_L (0x0B) +#define QMI8658_REG_CAL1_H (0x0C) +#define QMI8658_REG_CAL2_L (0x0D) +#define QMI8658_REG_CAL2_H (0x0E) +#define QMI8658_REG_CAL3_L (0x0F) +#define QMI8658_REG_CAL3_H (0x10) +#define QMI8658_REG_CAL4_L (0x11) +#define QMI8658_REG_CAL4_H (0x12) + +#define QMI8658_REG_FIFOWMKTH (0x13) +#define QMI8658_REG_FIFOCTRL (0x14) +#define QMI8658_REG_FIFOCOUNT (0x15) +#define QMI8658_REG_FIFOSTATUS (0x16) +#define QMI8658_REG_FIFODATA (0x17) +// #define QMI8658_REG_STATUSI2CM (0x2C) +#define QMI8658_REG_STATUSINT (0x2D) +#define QMI8658_REG_STATUS0 (0x2E) +#define QMI8658_REG_STATUS1 (0x2F) +#define QMI8658_REG_TIMESTAMP_L (0x30) +#define QMI8658_REG_TIMESTAMP_M (0x31) +#define QMI8658_REG_TIMESTAMP_H (0x32) +#define QMI8658_REG_TEMPEARTURE_L (0x33) +#define QMI8658_REG_TEMPEARTURE_H (0x34) +#define QMI8658_REG_AX_L (0x35) +#define QMI8658_REG_AX_H (0x36) +#define QMI8658_REG_AY_L (0x37) +#define QMI8658_REG_AY_H (0x38) +#define QMI8658_REG_AZ_L (0x39) +#define QMI8658_REG_AZ_H (0x3A) +#define QMI8658_REG_GX_L (0x3B) +#define QMI8658_REG_GX_H (0x3C) +#define QMI8658_REG_GY_L (0x3D) +#define QMI8658_REG_GY_H (0x3E) +#define QMI8658_REG_GZ_L (0x3F) +#define QMI8658_REG_GZ_H (0x40) + +#define QMI8658_REG_COD_STATUS (0x46) + +#define QMI8658_REG_DQW_L (0x49) +#define QMI8658_REG_DQW_H (0x4A) +#define QMI8658_REG_DQX_L (0x4B) +#define QMI8658_REG_DQX_H (0x4C) +#define QMI8658_REG_DQY_L (0x4D) +#define QMI8658_REG_DQY_H (0x4E) +#define QMI8658_REG_DQZ_L (0x4F) +#define QMI8658_REG_DQZ_H (0x50) + +#define QMI8658_REG_DVX_L (0x51) +#define QMI8658_REG_DVX_H (0x52) +#define QMI8658_REG_DVY_L (0x53) +#define QMI8658_REG_DVY_H (0x54) +#define QMI8658_REG_DVZ_L (0x55) +#define QMI8658_REG_DVZ_H (0x56) + +#define QMI8658_REG_TAP_STATUS (0x59) +#define QMI8658_REG_PEDO_L (0x5A) +#define QMI8658_REG_PEDO_M (0x5B) +#define QMI8658_REG_PEDO_H (0x5C) +#define QMI8658_REG_RESET (0x60) + +#define QMI8658_REG_RST_RESULT (0x4D) +#define QMI8658_REG_RST_RESULT_VAL (0x80) + +#define STATUS0_ACCE_AVAIL (0x01) +#define STATUS0_GYRO_AVAIL (0x02) +#define QMI8658_ACCEL_LPF_MASK (0xF9) +#define QMI8658_GYRO_LPF_MASK (0x9F) + + + + + +#define QMI8658_ACCEL_EN_MASK (0x01) +#define QMI8658_GYRO_EN_MASK (0x02) +#define QMI8658_ACCEL_GYRO_EN_MASK (0x03) + + +#define QMI8658_FIFO_MAP_INT1 0x04 // ctrl1 diff --git a/components/SensorLib/src/REG/XL9555Constants.h b/components/SensorLib/src/REG/XL9555Constants.h new file mode 100644 index 0000000..7061e41 --- /dev/null +++ b/components/SensorLib/src/REG/XL9555Constants.h @@ -0,0 +1,33 @@ +#pragma once + +// A0, A1, A2 connect to GND +#define XL9555_UNKOWN_ADDRESS (0xFF) +#define XL9555_SLAVE_ADDRESS0 (0x20) +#define XL9555_SLAVE_ADDRESS1 (0x21) +#define XL9555_SLAVE_ADDRESS2 (0x22) +#define XL9555_SLAVE_ADDRESS3 (0x23) +#define XL9555_SLAVE_ADDRESS4 (0x24) +#define XL9555_SLAVE_ADDRESS5 (0x25) +#define XL9555_SLAVE_ADDRESS6 (0x26) +#define XL9555_SLAVE_ADDRESS7 (0x27) + +// Input Port 0 /R +#define XL9555_CTRL_INP0 (0x00) +// Input Port 1 /R +#define XL9555_CTRL_INP1 (0x01) +// Output Port 0 /RW +#define XL9555_CTRL_OUTP0 (0x02) +// Output Port 1 /RW +#define XL9555_CTRL_OUTP1 (0x03) +// Polarity Inversion Port 0 /RW +#define XL9555_CTRL_PIP0 (0x04) +// Polarity Inversion Port 1 /RW +#define XL9555_CTRL_PIP1 (0x05) +// Configuration Port 0 /RW +#define XL9555_CTRL_CFG0 (0x06) +// Configuration Port 1 /RW +#define XL9555_CTRL_CFG1 (0x07) + +#define XL9555_MAX_PIN (15) + + diff --git a/components/SensorLib/src/SensorBHI260AP.cpp b/components/SensorLib/src/SensorBHI260AP.cpp new file mode 100644 index 0000000..2017065 --- /dev/null +++ b/components/SensorLib/src/SensorBHI260AP.cpp @@ -0,0 +1,36 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2024 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBHI260AP.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2024-05-27 + * + */ +#include "SensorBHI260AP.hpp" + +#if defined(ARDUINO) +volatile bool SensorBHI260AP::__data_available; +#endif + + diff --git a/components/SensorLib/src/SensorBHI260AP.hpp b/components/SensorLib/src/SensorBHI260AP.hpp new file mode 100644 index 0000000..e655d68 --- /dev/null +++ b/components/SensorLib/src/SensorBHI260AP.hpp @@ -0,0 +1,802 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBHI260AP.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-06 + * @note Most source code references come from the https://github.com/boschsensortec/BHY2-Sensor-API + * Simplification for Arduino + */ +#pragma once + +#if defined(ARDUINO) + +#include "bosch/BoschParse.h" +#include "bosch/SensorBhy2Define.h" +#include "bosch/firmware/BHI260AP.fw.h" + + + + +class SensorBHI260AP +{ + friend class BoschParse; +public: + SensorBHI260AP(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BHI260AP_SLAVE_ADDRESS_L) + { + __handler.u.i2c_dev.scl = scl; + __handler.u.i2c_dev.sda = sda; + __handler.u.i2c_dev.addr = addr; + __handler.u.i2c_dev.wire = &w; + __handler.intf = SENSORLIB_I2C_INTERFACE; + } + + SensorBHI260AP(int cs, int mosi = -1, int miso = -1, int sck = -1, + PLATFORM_SPI_TYPE &spi = SPI + ) + { + __handler.u.spi_dev.cs = cs; + __handler.u.spi_dev.miso = miso; + __handler.u.spi_dev.mosi = mosi; + __handler.u.spi_dev.sck = sck; + __handler.u.spi_dev.spi = &spi; + __handler.intf = SENSORLIB_SPI_INTERFACE; + } + + ~SensorBHI260AP() + { + deinit(); + } + + SensorBHI260AP() + { + memset(&__handler, 0, sizeof(__handler)); + } + + void setPins(int rst, int irq) + { + __handler.irq = irq; + __handler.rst = rst; + + } + + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BHI260AP_SLAVE_ADDRESS_L) + { + __handler.u.i2c_dev.scl = scl; + __handler.u.i2c_dev.sda = sda; + __handler.u.i2c_dev.addr = addr; + __handler.u.i2c_dev.wire = &w; + __handler.intf = SENSORLIB_I2C_INTERFACE; + return initImpl(); + } + + bool init( + PLATFORM_SPI_TYPE &spi, + int cs, int mosi = MOSI, int miso = MISO, int sck = SCK) + { + __handler.u.spi_dev.cs = cs; + __handler.u.spi_dev.miso = miso; + __handler.u.spi_dev.mosi = mosi; + __handler.u.spi_dev.sck = sck; + __handler.u.spi_dev.spi = &spi; + __handler.intf = SENSORLIB_SPI_INTERFACE; + return initImpl(); + } + + bool init() + { + return initImpl(); + } + + void deinit() + { + if (__pro_buf) { + free(__pro_buf); + } + __pro_buf = NULL; + + if (bhy2) { + free(bhy2); + bhy2 = NULL; + } + + if (__handler.irq != SENSOR_PIN_NONE) { + detachInterrupt(__handler.irq); + } + // end(); + } + + void reset() + { + if (__handler.rst != SENSOR_PIN_NONE) { + digitalWrite(__handler.rst, HIGH); + delay(5); + digitalWrite(__handler.rst, LOW); + delay(10); + digitalWrite(__handler.rst, HIGH); + delay(5); + } + } + + void update() + { + if (!__pro_buf) { + return; + } + if (__handler.irq != SENSOR_PIN_NONE) { + if (__data_available) { + bhy2_get_and_process_fifo(__pro_buf, __pro_buf_size, bhy2); + } + } else { + bhy2_get_and_process_fifo(__pro_buf, __pro_buf_size, bhy2); + } + } + + void setBootFormFlash(bool boot_from_flash) + { + __boot_from_flash = boot_from_flash; + } + + + bhy2_dev *getHandler() + { + return bhy2; + } + + void printSensors(Stream &port) + { + uint8_t cnt = 0; + bool presentBuff[256]; + + for (uint16_t i = 0; i < sizeof(bhy2->present_buff); i++) { + for (uint8_t j = 0; j < 8; j++) { + presentBuff[i * 8 + j] = ((bhy2->present_buff[i] >> j) & 0x01); + } + } + + port.println("Present sensors: "); + for (int i = 0; i < (int)sizeof(presentBuff); i++) { + if (presentBuff[i]) { + cnt++; + port.print(i); + port.print(" - "); + port.print(get_sensor_name(i)); + port.println(); + } + } + port.printf("Total %u Sensor online .\n", cnt); + } + + + bool printInfo(Stream &stream) + { + uint16_t kernel_version = 0, user_version = 0; + uint16_t rom_version = 0; + uint8_t product_id = 0; + uint8_t host_status = 0, feat_status = 0; + uint8_t boot_status = 0; + uint8_t sensor_error; + struct bhy2_sensor_info info; + + /* Get product_id */ + __error_code = (bhy2_get_product_id(&product_id, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_product_id failed!", false); + + /* Get Kernel version */ + __error_code = (bhy2_get_kernel_version(&kernel_version, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_kernel_version failed!", false); + + /* Get User version */ + __error_code = (bhy2_get_user_version(&user_version, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_user_version failed!", false); + + /* Get ROM version */ + __error_code = (bhy2_get_rom_version(&rom_version, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_rom_version failed!", false); + + __error_code = (bhy2_get_host_status(&host_status, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_host_status failed!", false); + + __error_code = (bhy2_get_feature_status(&feat_status, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_feature_status failed!", false); + + stream.printf("Product ID : %02x\n", product_id); + stream.printf("Kernel version : %04u\n", kernel_version); + stream.printf("User version : %04u\n", user_version); + stream.printf("ROM version : %04u\n", rom_version); + stream.printf("Power state : %s\n", (host_status & BHY2_HST_POWER_STATE) ? "sleeping" : "active"); + stream.printf("Host interface : %s\n", (host_status & BHY2_HST_HOST_PROTOCOL) ? "SPI" : "I2C"); + stream.printf("Feature status : 0x%02x\n", feat_status); + + /* Read boot status */ + __error_code = (bhy2_get_boot_status(&boot_status, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false); + + stream.printf("Boot Status : 0x%02x: ", boot_status); + + if (boot_status & BHY2_BST_FLASH_DETECTED) { + stream.println("\tFlash detected. "); + } + + if (boot_status & BHY2_BST_FLASH_VERIFY_DONE) { + stream.println("\tFlash verify done. "); + } + + if (boot_status & BHY2_BST_FLASH_VERIFY_ERROR) { + stream.println("Flash verification failed. "); + } + + if (boot_status & BHY2_BST_NO_FLASH) { + stream.println("\tNo flash installed. "); + } + + if (boot_status & BHY2_BST_HOST_INTERFACE_READY) { + stream.println("\tHost interface ready. "); + } + + if (boot_status & BHY2_BST_HOST_FW_VERIFY_DONE) { + stream.println("\tFirmware verification done. "); + } + + if (boot_status & BHY2_BST_HOST_FW_VERIFY_ERROR) { + stream.println("\tFirmware verification error. "); + } + + if (boot_status & BHY2_BST_HOST_FW_IDLE) { + stream.println("\tFirmware halted. "); + } + + /* Read error value */ + __error_code = (bhy2_get_error_value(&sensor_error, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_error_value failed!", false); + if (sensor_error) { + log_e("%s", get_sensor_error_text(sensor_error)); + } + + + if (feat_status & BHY2_FEAT_STATUS_OPEN_RTOS_MSK) { + + bhy2_update_virtual_sensor_list(bhy2); + + /* Get present virtual sensor */ + bhy2_get_virt_sensor_list(bhy2); + + stream.printf("Virtual sensor list.\r\n"); + stream.printf("Sensor ID | Sensor Name | ID | Ver | Min rate | Max rate |\r\n"); + stream.printf("----------+--------------------------------------+-----+-----+-----------+-----------|\r\n"); + for (uint8_t i = 0; i < BHY2_SENSOR_ID_MAX; i++) { + if (bhy2_is_sensor_available(i, bhy2)) { + if (i < BHY2_SENSOR_ID_CUSTOM_START) { + stream.printf(" %8u | %36s ", i, get_sensor_name(i)); + } + __error_code = (bhy2_get_sensor_info(i, &info, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_sensor_info failed!", false); + stream.printf("| %3u | %3u | %9.4f | %9.4f |\r\n", + info.driver_id, + info.driver_version, + info.min_rate.f_val, + info.max_rate.f_val); + } + } + } + return true; + } + + bool setInterruptCtrl(uint8_t data) + { + __error_code = bhy2_set_host_interrupt_ctrl(data, bhy2); + if (__error_code != BHY2_OK) { + return false; + } + } + + uint8_t getInterruptCtrl() + { + uint8_t data; + __error_code = bhy2_get_host_interrupt_ctrl(&data, bhy2); + if (__error_code != BHY2_OK) { + return 0; + } + return data; + } + + void printInterruptCtrl(Stream &stream) + { + uint8_t data; + __error_code = bhy2_get_host_interrupt_ctrl(&data, bhy2); + if (__error_code != BHY2_OK) { + return ; + } + stream.printf("Host interrupt control\r\n"); + stream.printf("-- Wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_W) ? "disabled" : "enabled"); + stream.printf("-- Non wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_NW) ? "disabled" : "enabled"); + stream.printf("-- Status FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_STATUS_FIFO) ? "disabled" : "enabled"); + stream.printf("-- Debugging %s.\r\n", (data & BHY2_ICTL_DISABLE_DEBUG) ? "disabled" : "enabled"); + stream.printf("-- Fault %s.\r\n", (data & BHY2_ICTL_DISABLE_FAULT) ? "disabled" : "enabled"); + stream.printf("-- Interrupt is %s.\r\n", (data & BHY2_ICTL_ACTIVE_LOW) ? "active low" : "active high"); + stream.printf("-- Interrupt is %s triggered.\r\n", (data & BHY2_ICTL_EDGE) ? "pulse" : "level"); + stream.printf("-- Interrupt pin drive is %s.\r\n", (data & BHY2_ICTL_OPEN_DRAIN) ? "open drain" : "push-pull"); + } + + bool isReady() + { + uint8_t boot_status = 0; + __error_code = bhy2_get_boot_status(&boot_status, bhy2); + log_i("boot_status:0x%x", boot_status); + if (__error_code != BHY2_OK) { + return false; + } + return (boot_status & BHY2_BST_HOST_INTERFACE_READY); + } + + uint16_t getKernelVersion() + { + uint16_t version = 0; + __error_code = bhy2_get_kernel_version(&version, bhy2); + if ((__error_code != BHY2_OK) && (version == 0)) { + return 0; + } + log_d("Boot successful. Kernel version %u.", version); + return version; + } + + + + void onEvent(BhySensorEvent event_id, BhyEventCb callback) + { + SensorEventCbList_t newEventHandler; + newEventHandler.cb = callback; + newEventHandler.event = event_id; + BoschParse::bhyEventVector.push_back(newEventHandler); + } + + void removeEvent(BhySensorEvent event_id, BhyEventCb callback) + { + if (!callback) { + return; + } + for (uint32_t i = 0; i < BoschParse::bhyEventVector.size(); i++) { + SensorEventCbList_t entry = BoschParse::bhyEventVector[i]; + if (entry.cb == callback && entry.event == event_id) { + BoschParse::bhyEventVector.erase(BoschParse::bhyEventVector.begin() + i); + } + } + } + + + void onResultEvent(BhySensorID sensor_id, BhyParseDataCallback callback) + { + ParseCallBackList_t newEventHandler; + newEventHandler.cb = callback; + newEventHandler.id = sensor_id; + BoschParse::bhyParseEventVector.push_back(newEventHandler); + } + + void removeResultEvent(BhySensorID sensor_id, BhyParseDataCallback callback) + { + if (!callback) { + return; + } + for (uint32_t i = 0; i < BoschParse::bhyParseEventVector.size(); i++) { + ParseCallBackList_t entry = BoschParse::bhyParseEventVector[i]; + if (entry.cb == callback && entry.id == sensor_id) { + BoschParse::bhyParseEventVector.erase(BoschParse::bhyParseEventVector.begin() + i); + } + } + } + + void setProcessBufferSize(uint32_t size) + { + __pro_buf_size = size; + } + + + bool uploadFirmware(const uint8_t *firmware, uint32_t length, bool write2Flash = false) + { + uint8_t sensor_error; + uint8_t boot_status; + + log_i("Upload Firmware ..."); + + __error_code = bhy2_get_boot_status(&boot_status, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false); + + if (write2Flash) { + if (boot_status & BHY2_BST_FLASH_DETECTED) { + uint32_t start_addr = BHY2_FLASH_SECTOR_START_ADDR; + uint32_t end_addr = start_addr + length; + log_i("Flash detected. Erasing flash to upload firmware"); + __error_code = bhy2_erase_flash(start_addr, end_addr, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_erase_flash failed!", false); + } else { + log_e("Flash not detected"); + return false; + } + printf("Loading firmware into FLASH."); + __error_code = bhy2_upload_firmware_to_flash(firmware, length, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_upload_firmware_to_flash failed!", false); + } else { + log_i("Loading firmware into RAM."); + log_i("upload size = %lu", length); + __error_code = bhy2_upload_firmware_to_ram(firmware, length, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_upload_firmware_to_ram failed!", false); + } + + log_i("Loading firmware into RAM Done"); + __error_code = bhy2_get_error_value(&sensor_error, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_error_value failed!", false); + if (sensor_error != BHY2_OK) { + __error_code = bhy2_get_error_value(&sensor_error, bhy2); + log_e("%s", get_sensor_error_text(sensor_error)); + return false; + } + + + if (write2Flash) { + log_i("Booting from FLASH."); + __error_code = bhy2_boot_from_flash(bhy2); + } else { + log_i("Booting from RAM."); + __error_code = bhy2_boot_from_ram(bhy2); + } + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2 boot failed!", false); + + __error_code = bhy2_get_error_value(&sensor_error, bhy2); + if (sensor_error) { + log_e("%s", get_sensor_error_text(sensor_error)); + return false; + } + return sensor_error == BHY2_OK; + } + + String getError() + { + String err = get_api_error(__error_code); + err += " Code:" + String(__error_code); + return err; + } + + bool configure(uint8_t sensor_id, float sample_rate, uint32_t report_latency_ms) + { + if (!bhy2_is_sensor_available(sensor_id, bhy2)) { + log_e("Sensor not present"); return false; + } + __error_code = bhy2_set_virt_sensor_cfg(sensor_id, sample_rate, report_latency_ms, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_virt_sensor_cfg failed!", false); + log_i("Enable %s at %.2fHz.", get_sensor_name(sensor_id), sample_rate); + return true; + } + + struct bhy2_virt_sensor_conf getConfigure(uint8_t sensor_id) + { + bhy2_virt_sensor_conf conf; + bhy2_get_virt_sensor_cfg(sensor_id, &conf, bhy2); + log_i("range:%u sample_rate:%f latency:%lu sensitivity:%u\n", conf.range, conf.sample_rate, conf.latency, conf.sensitivity); + return conf; + } + + float getScaling(uint8_t sensor_id) + { + return get_sensor_default_scaling(sensor_id); + } + + void setFirmware(const uint8_t *image, size_t image_len, bool write_flash) + { + __firmware = image; + __firmware_size = image_len; + __write_flash = write_flash; + } + + static const char *getSensorName(uint8_t sensor_id) + { + return get_sensor_name(sensor_id); + } + + // Get an accuracy report + uint8_t getAccuracy() + { + return __accuracy; + } + +private: + + bool bootFromFlash() + { + int8_t rslt; + uint8_t boot_status, feat_status; + uint8_t error_val = 0; + uint16_t tries = 300; /* Wait for up to little over 3s */ + + log_d("Waiting for firmware verification to complete"); + do { + __error_code = bhy2_get_boot_status(&boot_status, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false); + if (boot_status & BHY2_BST_FLASH_VERIFY_DONE) { + break; + } + delay(10); + } while (tries--); + + __error_code = bhy2_get_boot_status(&boot_status, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false); + print_boot_status(boot_status); + + if (boot_status & BHY2_BST_HOST_INTERFACE_READY) { + + if (boot_status & BHY2_BST_FLASH_DETECTED) { + + /* If no firmware is running, boot from Flash */ + log_d("Booting from flash"); + rslt = bhy2_boot_from_flash(bhy2); + if (rslt != BHY2_OK) { + log_e("%s. Booting from flash failed.\r\n", get_api_error(rslt)); + __error_code = bhy2_get_regs(BHY2_REG_ERROR_VALUE, &error_val, 1, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_regs failed!", false); + if (error_val) { + log_e("%s\r\n", get_sensor_error_text(error_val)); + } + return false; + } + + __error_code = bhy2_get_boot_status(&boot_status, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false); + print_boot_status(boot_status); + + if (!(boot_status & BHY2_BST_HOST_INTERFACE_READY)) { + /* hub is not ready, need reset hub */ + log_d("Host interface is not ready, triggering a reset"); + __error_code = bhy2_soft_reset(bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_soft_reset failed!", false); + } + + __error_code = (bhy2_get_feature_status(&feat_status, bhy2)); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "Reading Feature status failed, booting from flash failed!", false); + + } else { + log_e("Can't detect external flash"); + return false; + } + } else { + log_e("Host interface is not ready"); + return false; + } + + log_d("Booting from flash successful"); + return true; + } + + + + void print_boot_status(uint8_t boot_status) + { + log_d("Boot Status : 0x%02x: ", boot_status); + if (boot_status & BHY2_BST_FLASH_DETECTED) { + log_d("Flash detected. "); + } + + if (boot_status & BHY2_BST_FLASH_VERIFY_DONE) { + log_d("Flash verify done. "); + } + + if (boot_status & BHY2_BST_FLASH_VERIFY_ERROR) { + log_d("Flash verification failed. "); + } + + if (boot_status & BHY2_BST_NO_FLASH) { + log_d("No flash installed. "); + } + + if (boot_status & BHY2_BST_HOST_INTERFACE_READY) { + log_d("Host interface ready. "); + } + + if (boot_status & BHY2_BST_HOST_FW_VERIFY_DONE) { + log_d("Firmware verification done. "); + } + + if (boot_status & BHY2_BST_HOST_FW_VERIFY_ERROR) { + log_d("Firmware verification error. "); + } + + if (boot_status & BHY2_BST_HOST_FW_IDLE) { + log_d("Firmware halted. "); + } + } + + static void handleISR() + { + __data_available = true; + } + + + bool initImpl() + { + uint8_t product_id = 0; + + if (__handler.rst != SENSOR_PIN_NONE) { + pinMode(__handler.rst, OUTPUT); + } + + reset(); + + bhy2 = (struct bhy2_dev *)malloc(sizeof(struct bhy2_dev )); + BHY2_RLST_CHECK(!bhy2, " Device handler malloc failed!", false); + + switch (__handler.intf) { + case BHY2_I2C_INTERFACE: + // esp32s3 test I2C maximum read and write is 64 bytes + __max_rw_length = 64; + BHY2_RLST_CHECK(!__handler.u.i2c_dev.wire, "Wire ptr NULL", false); + if (!SensorInterfaces::setup_interfaces(__handler)) { + log_e("setup_interfaces failed"); + return false; + } + __error_code = bhy2_init(BHY2_I2C_INTERFACE, + SensorInterfaces::bhy2_i2c_read, + SensorInterfaces::bhy2_i2c_write, + SensorInterfaces::bhy2_delay_us, + __max_rw_length, &__handler, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_init failed!", false); + // __error_code = bhy2_set_host_intf_ctrl(BHY2_I2C_INTERFACE, bhy2); + // BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_host_intf_ctrl failed!", false); + break; + + case BHY2_SPI_INTERFACE: + // esp32s3 test SPI maximum read and write is 256 bytes + __max_rw_length = 256; + BHY2_RLST_CHECK(!__handler.u.spi_dev.spi, "SPI ptr NULL", false); + if (!SensorInterfaces::setup_interfaces(__handler)) { + log_e("setup_interfaces failed"); + return false; + } + __error_code = bhy2_init(BHY2_SPI_INTERFACE, + SensorInterfaces::bhy2_spi_read, + SensorInterfaces::bhy2_spi_write, + SensorInterfaces::bhy2_delay_us, + __max_rw_length, + &__handler, + bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_init failed!", false); + // __error_code = bhy2_set_host_intf_ctrl(BHY2_SPI_INTERFACE, bhy2); + // BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_host_intf_ctrl failed!", false); + break; + default: + return false; + } + + __error_code = bhy2_soft_reset(bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "reset bhy2 failed!", false); + + __error_code = bhy2_get_product_id(&product_id, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_product_id failed!", false); + + + /* Check for a valid product ID */ + if (product_id != BHY2_PRODUCT_ID) { + log_e("Product ID read %X. Expected %X", product_id, BHY2_PRODUCT_ID); + return false; + } else { + log_i("BHI260/BHA260 found. Product ID read %X", product_id); + } + + if (!__firmware) { + // Default write to ram + setFirmware(bhy2_firmware_image, sizeof(bhy2_firmware_image), false); + } + + if (__boot_from_flash) { + if (!bootFromFlash()) { + //** If the boot from flash fails, re-upload the firmware to flash + __error_code = bhy2_soft_reset(bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "reset bhy2 failed!", false); + + if (!uploadFirmware(__firmware, __firmware_size, __write_flash)) { + log_e("uploadFirmware failed!"); + return false; + } + } + } else { + // ** Upload firmware to RAM + if (!uploadFirmware(__firmware, __firmware_size, __write_flash)) { + log_e("uploadFirmware failed!"); + return false; + } + } + + uint16_t version = getKernelVersion(); + BHY2_RLST_CHECK(!version, "getKernelVersion failed!", false); + log_i("Boot successful. Kernel version %u.", version); + + //Set event callback + __error_code = bhy2_register_fifo_parse_callback(BHY2_SYS_ID_META_EVENT, BoschParse::parseMetaEvent, (void *)&__accuracy, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_register_fifo_parse_callback failed!", false); + + __error_code = bhy2_register_fifo_parse_callback(BHY2_SYS_ID_META_EVENT_WU, BoschParse::parseMetaEvent, (void *)&__accuracy, bhy2); + BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_register_fifo_parse_callback failed!", false); + + // __error_code = bhy2_register_fifo_parse_callback(BHY2_SYS_ID_DEBUG_MSG, BoschParse::parseDebugMessage, NULL, bhy2); + // BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_register_fifo_parse_callback parseDebugMessage failed!", false); + + //Set process buffer +#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32)) && defined(BOARD_HAS_PSRAM) + __pro_buf = (uint8_t *)ps_malloc(__pro_buf_size); +#else + __pro_buf = (uint8_t *)malloc(__pro_buf_size); +#endif + BHY2_RLST_CHECK(!__pro_buf, "process buffer malloc failed!", false); + + __error_code = bhy2_get_and_process_fifo(__pro_buf, __pro_buf_size, bhy2); + if (__error_code != BHY2_OK) { + log_e("bhy2_get_and_process_fifo failed"); + free(__pro_buf); + return false; + } + + /* Update the callback table to enable parsing of sensor hintr_ctrl */ + bhy2_update_virtual_sensor_list(bhy2); + + /* Get present virtual sensor */ + bhy2_get_virt_sensor_list(bhy2); + + // Only register valid sensor IDs + for (uint8_t i = 0; i < BHY2_SENSOR_ID_MAX; i++) { + if (bhy2_is_sensor_available(i, bhy2)) { + bhy2_register_fifo_parse_callback(i, BoschParse::parseData, NULL, bhy2); + } + } + + if (__handler.irq != SENSOR_PIN_NONE) { +#if defined(ARDUINO_ARCH_RP2040) + attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING); +#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) + attachInterrupt(__handler.irq, handleISR, RISING); +#else +#error "Interrupt registration not implemented" +#endif + } + + return __error_code == BHY2_OK; + } + +protected: + struct bhy2_dev *bhy2 = NULL; + SensorLibConfigure __handler; + int8_t __error_code; + static volatile bool __data_available; + uint8_t *__pro_buf = NULL; + size_t __pro_buf_size = BHY_PROCESS_BUFFER_SIZE; + const uint8_t *__firmware; + size_t __firmware_size; + bool __write_flash; + bool __boot_from_flash; + uint16_t __max_rw_length; + uint8_t __accuracy; /* Accuracy is reported as a meta event. */ +}; + + +#endif /*defined(ARDUINO)*/ + + + + diff --git a/components/SensorLib/src/SensorBMA423.hpp b/components/SensorLib/src/SensorBMA423.hpp new file mode 100644 index 0000000..41ecabc --- /dev/null +++ b/components/SensorLib/src/SensorBMA423.hpp @@ -0,0 +1,846 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBMA423.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2022-03-31 + * @note Most source code references come from the https://github.com/boschsensortec/BMA423-Sensor-API + * Simplification for Arduino + */ +#pragma once + +#include "REG/BMA423Constants.h" +#include "SensorCommon.tpp" + +class SensorBMA423 : + public SensorCommon +{ + friend class SensorCommon; +public: + + enum AccelRange { + RANGE_2G, + RANGE_4G, + RANGE_8G, + RANGE_16G + }; + + /*! Output data rate in Hz */ + enum AccelODR { + ODR_0_78HZ = 1, + ODR_1_56HZ, + ODR_3_12HZ, + ODR_6_25HZ, + ODR_12_5HZ, + ODR_25HZ, + ODR_50HZ, + ODR_100HZ, + ODR_200HZ, + ODR_400HZ, + ODR_800HZ, + ODR_1600HZ, + }; + + /*! Bandwidth parameter, determines filter configuration */ + enum BandWidth { + BW_OSR4_AVG1, + BW_OSR2_AVG2, + BW_NORMAL_AVG4, + BW_CIC_AVG8, + BW_RES_AVG16, + BW_RES_AVG32, + BW_RES_AVG64, + BW_RES_AVG128, + }; + + enum PerformanceMode { + PERF_CIC_AVG_MODE, + PERF_CONTINUOUS_MODE, + }; + + enum TemperatureUnit { + TEMP_DEG, + TEMP_FAHREN, + TEMP_KELVIN, + }; + + // Calculate direction facing the front of the chip + enum SensorDir { + DIRECTION_BOTTOM_LEFT, + DIRECTION_TOP_RIGHT, + DIRECTION_TOP_LEFT, + DIRECTION_BOTTOM_RIGHT, + DIRECTION_BOTTOM, + DIRECTION_TOP + }; + + // Chip orientation and orientation + enum SensorRemap { + // Top right corner + REMAP_TOP_LAYER_RIGHT_CORNER, + // Front bottom left corner + REMAP_TOP_LAYER_BOTTOM_LEFT_CORNER, + // Top left corner + REMAP_TOP_LAYER_LEFT_CORNER, + // Top bottom right corner + REMAP_TOP_LAYER_BOTTOM_RIGHT_CORNER, + // Bottom top right corner + REMAP_BOTTOM_LAYER_TOP_RIGHT_CORNER, + // Bottom bottom left corner + REMAP_BOTTOM_LAYER_BOTTOM_LEFT_CORNER, + // Bottom bottom right corner + REMAP_BOTTOM_LAYER_BOTTOM_RIGHT_CORNER, + // Bottom top left corner + REMAP_BOTTOM_LAYER_TOP_LEFT_CORNER, + }; + + enum Feature { + /**\name Feature enable macros for the sensor */ + FEATURE_STEP_CNTR = 0x01, + /**\name Below macros are mutually exclusive */ + FEATURE_ANY_MOTION = 0x02, + FEATURE_NO_MOTION = 0x04, + FEATURE_ACTIVITY = 0x08, + FEATURE_TILT = 0x10, + FEATURE_WAKEUP = 0x20, + }; + + /**\name Interrupt status macros */ + enum FeatureInterrupt { + INT_STEP_CNTR = 0x02, + INT_ACTIVITY = 0x04, + INT_TILT = 0x05, + INT_WAKEUP = 0x20, + INT_ANY_NO_MOTION = 0x40, + }; + +#if defined(ARDUINO) + SensorBMA423(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMA423_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorBMA423() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = BMA423_SLAVE_ADDRESS; + } + + ~SensorBMA423() + { + deinit(); + } + + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMA423_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + void reset() + { + writeRegister(BMA423_RESET_REG, 0xB6); + delay(20); + } + + bool enablePowerSave() + { + uint8_t val; + + val = readRegister(BMA4_POWER_CONF_ADDR); + val |= BMA4_ADVANCE_POWER_SAVE_MSK; + writeRegister(BMA4_POWER_CONF_ADDR, val); + return true; + } + + bool disablePowerSave() + { + uint8_t val; + val = readRegister(BMA4_POWER_CONF_ADDR); + val &= ~(BMA4_ADVANCE_POWER_SAVE_MSK); + writeRegister(BMA4_POWER_CONF_ADDR, val); + return true; + } + + void disableInterruptCtrl() + { + writeRegister(BMA4_INIT_CTRL_ADDR, 0x00); + } + + void enableInterruptCtrl() + { + writeRegister(BMA4_INIT_CTRL_ADDR, 0x01); + } + + + bool enableAccelerometer() + { + uint8_t val; + val = readRegister(BMA4_POWER_CTRL_ADDR); + val |= BMA4_ACCEL_ENABLE_MSK; + writeRegister(BMA4_POWER_CTRL_ADDR, val); + return true; + } + + bool disableAccelerometer() + { + uint8_t val; + val = readRegister( BMA4_POWER_CTRL_ADDR); + val &= (~BMA4_ACCEL_ENABLE_MSK); + writeRegister(BMA4_POWER_CTRL_ADDR, val); + return true; + } + + bool configAccelerometer(AccelRange range = RANGE_4G, AccelODR odr = ODR_200HZ, + BandWidth bw = BW_NORMAL_AVG4, + PerformanceMode perfMode = PERF_CONTINUOUS_MODE) + + { + uint8_t buffer[2] = {0, 0}; + if (perfMode == PERF_CONTINUOUS_MODE) { + if (bw > BW_NORMAL_AVG4) { + return false; + } + } else if (perfMode == PERF_CIC_AVG_MODE) { + if (bw > BW_RES_AVG128) { + return false; + } + } else { + return false; + } + if ((odr < ODR_0_78HZ) || (odr > ODR_1600HZ)) { + return false; + } + + buffer[0] = odr & 0x0F; + buffer[0] |= (uint8_t)(bw << 4); + buffer[0] |= (uint8_t)(perfMode << 7); + buffer[1] = range & 0x03; + + /* Burst write is not possible in + suspend mode hence individual write is + used with delay of 1 ms */ + writeRegister(BMA4_ACCEL_CONFIG_ADDR, buffer[0]); + delay(2); + writeRegister(BMA4_ACCEL_CONFIG_ADDR + 1, buffer[1]); + return true; + } + + + bool getAccelRaw(int16_t *rawBuffer) + { + uint8_t buffer[6] = {0}; + if (readRegister(BMA4_DATA_8_ADDR, buffer, 6) != DEV_WIRE_ERR) { + /* Accel data x axis */ + rawBuffer[0] = (int16_t)(buffer[1] << 8) | (buffer[0]); + /* Accel data y axis */ + rawBuffer[1] = (int16_t)(buffer[3] << 8) | (buffer[2]); + /* Accel data z axis */ + rawBuffer[2] = (int16_t)(buffer[5] << 8) | (buffer[4]); + } else { + return false; + } + return true; + } + + bool getAccelerometer(int16_t &x, int16_t &y, int16_t &z) + { + int16_t raw[3]; + if (getAccelRaw(raw)) { + x = raw[0] / 16; + y = raw[1] / 16; + z = raw[2] / 16; + return true; + } + return false; + } + + float getTemperature(TemperatureUnit unit) + { + int32_t raw = readRegister(BMA4_TEMPERATURE_ADDR); + /* '0' value read from the register corresponds to 23 degree C */ + raw = (raw * 1000) + (23 * 1000); + switch (unit) { + case TEMP_FAHREN: + /* Temperature in degree Fahrenheit */ + /* 1800 = 1.8 * 1000 */ + raw = ((raw / 1000) * 1800) + (32 * 1000); + break; + case TEMP_KELVIN: + /* Temperature in degree Kelvin */ + /* 273150 = 273.15 * 1000 */ + raw = raw + 273150; + break; + default: + break; + } + float res = (float)raw / (float)1000.0; + /* 0x80 - raw read from the register and 23 is the ambient raw added. + * If the raw read from register is 0x80, it means no valid + * information is available */ + if (((raw - 23) / 1000) == 0x80) { + return 0; + } + return res; + } + + + uint8_t direction() + { + int16_t x = 0, y = 0, z = 0; + getAccelerometer(x, y, z); + uint16_t absX = abs(x); + uint16_t absY = abs(y); + uint16_t absZ = abs(z); + if ((absZ > absX) && (absZ > absY)) { + if (z > 0) { + return DIRECTION_TOP; + } else { + return DIRECTION_BOTTOM; + } + } else if ((absY > absX) && (absY > absZ)) { + if (y > 0) { + return DIRECTION_TOP_RIGHT; + } else { + return DIRECTION_BOTTOM_LEFT; + } + } else { + if (x < 0) { + return DIRECTION_BOTTOM_RIGHT; + } else { + return DIRECTION_TOP_LEFT; + } + } + return 0; + } + + bool setRemapAxes(SensorRemap remap) + { + //Top + // No.1 REG: 0x3e -> 0x88 REG: 0x3f -> 0x0 + // No.2 REG: 0x3e -> 0xac REG: 0x3f -> 0x0 + // No.3 REG: 0x3e -> 0x85 REG: 0x3f -> 0x0 + // No.4 REG: 0x3e -> 0xa1 REG: 0x3f -> 0x0 + + // Bottom + // No.5 REG: 0x3e -> 0x81 REG: 0x3f -> 0x1 + // No.6 REG: 0x3e -> 0xa5 REG: 0x3f -> 0x1 + // No.7 REG: 0x3e -> 0x8c REG: 0x3f -> 0x1 + // No.8 REG: 0x3e -> 0xa8 REG: 0x3f -> 0x1 + + uint8_t configReg0[] = {0x88, 0xAC, 0x85, 0xA1, 0x81, 0xA5, 0x8C, 0xA8}; + if (remap > sizeof(configReg0) / sizeof(configReg0[0])) { + return false; + } + uint8_t buffer[BMA423_FEATURE_SIZE] = {0}; + uint8_t index = BMA423_AXES_REMAP_OFFSET; + if (readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE) == DEV_WIRE_ERR) { + return false; + } + buffer[index] = configReg0[remap]; + buffer[index + 1] = remap >= 4 ? 0x00 : 0x01; + return writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE) != DEV_WIRE_ERR; + } + + + + + bool setStepCounterWatermark(uint16_t watermark) + { + uint8_t buffer[BMA423_FEATURE_SIZE] = {0}; + uint8_t index = BMA423_STEP_CNTR_OFFSET; + uint16_t wm_lsb = 0; + uint16_t wm_msb = 0; + int rslt; + uint16_t data = 0; + + rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE); + if (rslt != DEV_WIRE_ERR) { + wm_lsb = buffer[index]; + wm_msb = buffer[index + 1] << 8; + data = wm_lsb | wm_msb; + /* Sets only watermark bits in the complete 16 bits of data */ + data = ((data & ~(0x03FFU)) | (watermark & 0x03FFU)); + /* Splits 16 bits of data to individual 8 bits data */ + buffer[index] = (uint8_t)(data & 0x00FFU); + buffer[index + 1] = (uint8_t)((data & 0xFF00U) >> 8); + /* Writes stepcounter watermark settings in the sensor */ + rslt = writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE); + } + return rslt != DEV_WIRE_ERR; + } + + bool disablePedometer() + { + return enablePedometer(false); + } + + bool enablePedometer(bool enable = true) + { + int rslt; + uint8_t buffer[BMA423_FEATURE_SIZE] = {0}; + /* Step detector enable bit pos. is 1 byte ahead of the base address */ + uint8_t index = BMA423_STEP_CNTR_OFFSET + 1; + rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE); + if (rslt != DEV_WIRE_ERR) { + buffer[index] = ((buffer[index] & ~0x08) | ((enable << 3) & 0x08)); + rslt = writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE); + } + return rslt != DEV_WIRE_ERR; + } + + uint32_t getPedometerCounter() + { + uint8_t buffer[4] = {0}; + /* Reads the step counter output data from the gpio register */ + int rslt = readRegister(BMA4_STEP_CNT_OUT_0_ADDR, buffer, 4); + if (rslt != DEV_WIRE_ERR) { + return ((uint32_t)buffer[0]) | ((uint32_t)buffer[1] << 8) | ((uint32_t)buffer[2] << 16) | ((uint32_t)buffer[3] << 24); + } + return DEV_WIRE_NONE; + } + + void resetPedometer() + { + uint8_t buffer[BMA423_FEATURE_SIZE] = {0}; + /* Reset bit is 1 byte ahead of base address */ + uint8_t index = BMA423_STEP_CNTR_OFFSET + 1; + int rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE); + if (rslt != DEV_WIRE_ERR) { + buffer[index] = ((buffer[index] & ~0x04U) | ((1 << 2U) & 0x04U)); + writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE); + } + } + + bool enableFeature(uint8_t feature, uint8_t enable) + { + uint8_t buffer[BMA423_FEATURE_SIZE] = {0}; + int rslt; + uint8_t len; + /* Update the length for read and write */ + update_len(&len, feature, enable); + rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, len); + if (rslt != DEV_WIRE_ERR) { + if (enable) { + /* Enables the feature */ + rslt = feature_enable(feature, len, buffer); + } else { + /* Disables the feature */ + rslt = feature_disable(feature, len, buffer); + } + } + return rslt != DEV_WIRE_ERR; + } + + uint16_t readIrqStatus() + { + uint8_t data[2] = {0}; + if (readRegister(BMA4_INT_STAT_0_ADDR, data, 2) != DEV_WIRE_ERR) { + int_status = data[0] | (data[1] << 8); + return int_status; + } + return DEV_WIRE_NONE; + } + + uint16_t getIrqStatus() + { + return int_status; + } + + bool configInterrupt( + /*! Trigger condition of interrupt pin */ + uint8_t edge_ctrl = BMA4_LEVEL_TRIGGER, + /*! Level of interrupt pin */ + uint8_t level = BMA4_ACTIVE_HIGH, + /*! Behaviour of interrupt pin to open drain */ + uint8_t od = BMA4_PUSH_PULL, + /*! Output enable for interrupt pin */ + uint8_t output_en = BMA4_OUTPUT_ENABLE, + /*! Input enable for interrupt pin */ + uint8_t input_en = BMA4_INPUT_DISABLE, + /*! Variable used to select the interrupt pin1 or pin2 for interrupt configuration. */ + uint8_t int_line = BMA4_INTR1_MAP + ) + { + uint8_t interrupt_address_array[2] = {BMA4_INT1_IO_CTRL_ADDR, BMA4_INT2_IO_CTRL_ADDR}; + uint8_t data = 0; + if (int_line > 1) { + return false; + } + data = ((uint8_t)((edge_ctrl & BMA4_INT_EDGE_CTRL_MASK) | + ((level << 1) & BMA4_INT_LEVEL_MASK) | + ((od << 2) & BMA4_INT_OPEN_DRAIN_MASK) | + ((output_en << 3) & BMA4_INT_OUTPUT_EN_MASK) | + ((input_en << 4) & BMA4_INT_INPUT_EN_MASK))); + + this->int_line = int_line; + + return writeRegister(interrupt_address_array[int_line], &data, 1) != DEV_WIRE_ERR; + } + + bool configFeatureInterrupt(uint16_t feature_interrupt_mask, bool enable) + { + return interruptMap(int_line, feature_interrupt_mask, enable); + } + + + bool enablePedometerIRQ() + { + return (interruptMap(int_line, INT_STEP_CNTR, true)); + } + + bool enableTiltIRQ() + { + return (interruptMap(int_line, INT_TILT, true)); + } + + bool enableWakeupIRQ() + { + return (interruptMap(int_line, INT_WAKEUP, true)); + } + + bool enableAnyNoMotionIRQ() + { + return (interruptMap(int_line, INT_ANY_NO_MOTION, true)); + } + + bool enableActivityIRQ() + { + return (interruptMap(int_line, INT_ACTIVITY, true)); + } + + bool disablePedometerIRQ() + { + return (interruptMap(int_line, INT_STEP_CNTR, false)); + } + + bool disableTiltIRQ() + { + return (interruptMap(int_line, INT_TILT, false)); + } + + bool disableWakeupIRQ() + { + return (interruptMap(int_line, INT_WAKEUP, false)); + } + + bool disableAnyNoMotionIRQ() + { + return (interruptMap(int_line, INT_ANY_NO_MOTION, false)); + } + + bool disableActivityIRQ() + { + return (interruptMap(int_line, INT_ACTIVITY, false)); + } + + + inline bool isActivity() + { + return (int_status & BMA423_ACTIVITY_INT); + } + + inline bool isTilt() + { + return (int_status & BMA423_TILT_INT); + } + + inline bool isDoubleTap() + { + return (int_status & BMA423_WAKEUP_INT); + } + + inline bool isAnyNoMotion() + { + return (int_status & BMA423_ACTIVITY_INT); + } + + inline bool isPedometer() + { + return (int_status & BMA423_STEP_CNTR_INT); + } + +private: + + bool interruptMap(uint8_t int_line, uint16_t int_map, uint8_t enable) + { + int rslt; + uint8_t data[3] = {0, 0, 0}; + uint8_t index[2] = {BMA4_INT_MAP_1_ADDR, BMA4_INT_MAP_2_ADDR}; + rslt = readRegister(BMA4_INT_MAP_1_ADDR, data, 3); + if (enable) { + /* Feature interrupt mapping */ + data[int_line] |= (uint8_t)(int_map & (0x00FF)); + /* Hardware interrupt mapping */ + if (int_line == BMA4_INTR2_MAP) + data[2] |= (uint8_t)((int_map & (0xFF00)) >> 4); + else + data[2] |= (uint8_t)((int_map & (0xFF00)) >> 8); + + rslt = writeRegister(index[int_line], &data[int_line], 1); + rslt = writeRegister(BMA4_INT_MAP_DATA_ADDR, &data[2], 1); + + } else { + /* Feature interrupt un-mapping */ + data[int_line] &= (~(uint8_t)(int_map & (0x00FF))); + /* Hardware interrupt un-mapping */ + if (int_line == BMA4_INTR2_MAP) + data[2] &= (~(uint8_t)((int_map & (0xFF00)) >> 4)); + else + data[2] &= (~(uint8_t)((int_map & (0xFF00)) >> 8)); + + rslt = writeRegister(index[int_line], &data[int_line], 1); + rslt = writeRegister(BMA4_INT_MAP_DATA_ADDR, &data[2], 1); + + } + return rslt != DEV_WIRE_ERR; + } + + /*! + * @brief This API sets the interrupt mode in the sensor. + */ + bool setInterruptMode(uint8_t mode) + { + if (mode == BMA4_NON_LATCH_MODE || mode == BMA4_LATCH_MODE) + return writeRegister(BMA4_INTR_LATCH_ADDR, &mode, 1) != DEV_WIRE_ERR; + return false; + } + + + bool feature_disable(uint8_t feature, uint8_t len, uint8_t *buffer) + { + uint8_t index = 0; + + /* Disable step counter */ + if ((feature & FEATURE_STEP_CNTR) > 0) { + /* Step counter enable bit pos. is 1 byte ahead of the + base address */ + index = BMA423_STEP_CNTR_OFFSET + 1; + buffer[index] = buffer[index] & (~BMA423_STEP_CNTR_EN_MSK); + } + + /* Disable activity */ + if ((feature & FEATURE_ACTIVITY) > 0) { + /* Activity enable bit pos. is 1 byte ahead of the + base address */ + index = BMA423_STEP_CNTR_OFFSET + 1; + buffer[index] = buffer[index] & (~BMA423_ACTIVITY_EN_MSK); + } + /* Disable tilt */ + if ((feature & FEATURE_TILT) > 0) { + /* Tilt enable bit pos. is the base address(0x3A) of tilt */ + index = BMA423_TILT_OFFSET; + buffer[index] = buffer[index] & (~BMA423_TILT_EN_MSK); + } + + /* Disable wakeup */ + if ((feature & FEATURE_WAKEUP) > 0) { + /* Tilt enable bit pos. is the base address(0x38) of wakeup */ + index = BMA423_WAKEUP_OFFSET; + buffer[index] = buffer[index] & (~BMA423_WAKEUP_EN_MSK); + } + + /* Disable anymotion/nomotion */ + if ((feature & FEATURE_ANY_MOTION) > 0 || (feature & FEATURE_NO_MOTION) > 0) { + /* Any/Nomotion enable bit pos. is 1 bytes ahead of the + any/nomotion base address(0x00) */ + index = 1; + + if ((feature & FEATURE_ANY_MOTION) > 0) { + /* Disable anymotion */ + buffer[index] = buffer[index] | BMA423_ANY_NO_MOTION_SEL_MSK; + } else { + /* Disable nomotion */ + buffer[index] = buffer[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK); + } + /* Any/Nomotion axis enable bit pos. is 3 byte ahead of the + any/nomotion base address(0x00) */ + index = 3; + buffer[index] = buffer[index] & (~BMA423_ANY_NO_MOTION_AXIS_EN_MSK); + } + /* Write the configured settings in the sensor */ + return writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, len) != DEV_WIRE_ERR; + } + + int feature_enable(uint8_t feature, uint8_t len, uint8_t *buffer) + { + uint8_t index = 0; + + /* Enable step counter */ + if ((feature & FEATURE_STEP_CNTR) > 0) { + /* Step counter enable bit pos. is 1 byte ahead of the + base address */ + index = BMA423_STEP_CNTR_OFFSET + 1; + buffer[index] = buffer[index] | BMA423_STEP_CNTR_EN_MSK; + } + + /* Enable activity */ + if ((feature & FEATURE_ACTIVITY) > 0) { + /* Activity enable bit pos. is 1 byte ahead of the + base address */ + index = BMA423_STEP_CNTR_OFFSET + 1; + buffer[index] = buffer[index] | BMA423_ACTIVITY_EN_MSK; + } + /* Enable tilt */ + if ((feature & FEATURE_TILT) > 0) { + /* Tilt enable bit pos. is the base address(0x3A) of tilt */ + index = BMA423_TILT_OFFSET; + buffer[index] = buffer[index] | BMA423_TILT_EN_MSK; + } + + /* Enable wakeup */ + if ((feature & FEATURE_WAKEUP) > 0) { + /* Wakeup enable bit pos. is the base address(0x38) of wakeup */ + index = BMA423_WAKEUP_OFFSET; + buffer[index] = buffer[index] | BMA423_WAKEUP_EN_MSK; + } + + /* Enable anymotion/nomotion */ + if ((feature & FEATURE_ANY_MOTION) > 0 || (feature & FEATURE_NO_MOTION) > 0) { + /* Any/Nomotion enable bit pos. is 1 bytes ahead of the + any/nomotion base address(0x00) */ + index = 1; + + if ((feature & FEATURE_ANY_MOTION) > 0) { + /* Enable anymotion */ + buffer[index] = buffer[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK); + } else { + /* Enable nomotion */ + buffer[index] = buffer[index] | BMA423_ANY_NO_MOTION_SEL_MSK; + } + } + + /* Write the feature enable settings in the sensor */ + return writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, len) != DEV_WIRE_ERR; + } + + void update_len(uint8_t *len, uint8_t feature, uint8_t enable) + { + uint8_t length = BMA423_FEATURE_SIZE; + + if ((feature == FEATURE_ANY_MOTION) || (feature == FEATURE_NO_MOTION)) { + /* Change the feature length to 2 for reading and writing of 2 bytes for + any/no-motion enable */ + length = BMA423_ANYMOTION_EN_LEN; + + /* Read and write 4 byte to disable the any/no motion completely along with + all axis */ + if (!enable) { + /*Change the feature length to 4 for reading and writing + of 4 bytes for any/no-motion enable */ + length = length + 2; + } + } + *len = length; + } + + bool configure() + { + uint8_t val; + val = readRegister(BMA4_INTERNAL_STAT); + if (val == BMA4_ASIC_INITIALIZED) { + log_d("No need configure!"); + readIrqStatus(); //clear irq status + return true; + } + + disablePowerSave(); + delay(1); + disableInterruptCtrl(); + + const uint8_t *stream_data = bma423_config_file; + const uint8_t maxReadWriteLenght = 32; + + for (size_t index = 0; index < BMA4_CONFIG_STREAM_SIZE; index += maxReadWriteLenght) { + uint8_t asic_msb = (uint8_t)((index / 2) >> 4); + uint8_t asic_lsb = ((index / 2) & 0x0F); + writeRegister(BMA4_RESERVED_REG_5B_ADDR, asic_lsb); + writeRegister(BMA4_RESERVED_REG_5C_ADDR, asic_msb); + writeRegister(BMA4_FEATURE_CONFIG_ADDR, (uint8_t *)(stream_data + index), maxReadWriteLenght); + } + + enableInterruptCtrl(); + delay(150); + val = readRegister(BMA4_INTERNAL_STAT); + if (val == BMA4_ASIC_INITIALIZED) { + log_d("BMA configure SUCCESS!"); + } else { + log_d("BMA configure FAILED!"); + } + return val == BMA4_ASIC_INITIALIZED; + } + + bool initImpl() + { + uint8_t id; + int retry = 2; + + while (retry--) { + id = readRegister(BMA4_CHIP_ID_ADDR); + if (id != BMA423_CHIP_ID) { + reset(); + } + } + + if (id == BMA423_CHIP_ID) { + return configure(); + } + + log_d("ChipID:0x%x should be 0x%x", id, BMA423_CHIP_ID); + return false; + + } + + + int getReadMaskImpl() + { + return DEV_WIRE_ERR; + } + + uint16_t int_status; + uint8_t int_line; + +protected: + + +}; + + + diff --git a/components/SensorLib/src/SensorBMM150.cpp b/components/SensorLib/src/SensorBMM150.cpp new file mode 100644 index 0000000..f6c28fa --- /dev/null +++ b/components/SensorLib/src/SensorBMM150.cpp @@ -0,0 +1,36 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2024 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBMM150.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2024-07-24 + * + */ +#include "SensorBMM150.hpp" + +#if defined(ARDUINO) +volatile bool SensorBMM150::__data_available; +#endif + + diff --git a/components/SensorLib/src/SensorBMM150.hpp b/components/SensorLib/src/SensorBMM150.hpp new file mode 100644 index 0000000..93e848c --- /dev/null +++ b/components/SensorLib/src/SensorBMM150.hpp @@ -0,0 +1,342 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBMM150.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-09 + * @note Most source code references come from the https://github.com/boschsensortec/BMM150-Sensor-API + * Simplification for Arduino + */ +#pragma once + +#include "bosch/common/bosch_interfaces.h" +#include "bosch/BMM150/bmm150.h" +#include "bosch/SensorBhy2Define.h" + +#if defined(ARDUINO) + +/*! @name I2C ADDRESS */ +#define BMM150_DEFAULT_I2C_ADDRESS UINT8_C(0x10) +#define BMM150_I2C_ADDRESS_CSB_LOW_SDO_HIGH UINT8_C(0x11) +#define BMM150_I2C_ADDRESS_CSB_HIGH_SDO_LOW UINT8_C(0x12) +#define BMM150_I2C_ADDRESS_CSB_HIGH_SDO_HIGH UINT8_C(0x13) + + +class SensorBMM150 +{ +public: + + enum PowerMode { + POWERMODE_NORMAL, + POWERMODE_FORCED, + POWERMODE_SLEEP, + POWERMODE_SUSPEND, + }; + + enum InterruptLevel { + INTERRUPT_HIGH_ACTIVE, + INTERRUPT_LOW_ACTIVE, + }; + + SensorBMM150(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMM150_DEFAULT_I2C_ADDRESS) + { + __handler.u.i2c_dev.scl = scl; + __handler.u.i2c_dev.sda = sda; + __handler.u.i2c_dev.addr = addr; + __handler.u.i2c_dev.wire = &w; + __handler.intf = SENSORLIB_I2C_INTERFACE; + } + + SensorBMM150(int cs, int mosi = -1, int miso = -1, int sck = -1, PLATFORM_SPI_TYPE &spi = SPI ) + { + __handler.u.spi_dev.cs = cs; + __handler.u.spi_dev.miso = miso; + __handler.u.spi_dev.mosi = mosi; + __handler.u.spi_dev.sck = sck; + __handler.u.spi_dev.spi = &spi; + __handler.intf = SENSORLIB_SPI_INTERFACE; + } + + ~SensorBMM150() + { + deinit(); + } + + SensorBMM150() + { + memset(&__handler, 0, sizeof(__handler)); + } + + void setPins(int rst, int irq) + { + __handler.irq = irq; + __handler.rst = rst; + + } + + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMM150_DEFAULT_I2C_ADDRESS) + { + __handler.u.i2c_dev.scl = scl; + __handler.u.i2c_dev.sda = sda; + __handler.u.i2c_dev.addr = addr; + __handler.u.i2c_dev.wire = &w; + __handler.intf = SENSORLIB_I2C_INTERFACE; + return initImpl(); + } + + bool init( PLATFORM_SPI_TYPE &spi, int cs, int mosi = -1, int miso = -1, int sck = -1) + { + __handler.u.spi_dev.cs = cs; + __handler.u.spi_dev.miso = miso; + __handler.u.spi_dev.mosi = mosi; + __handler.u.spi_dev.sck = sck; + __handler.u.spi_dev.spi = &spi; + __handler.intf = SENSORLIB_SPI_INTERFACE; + return initImpl(); + } + + bool init() + { + return initImpl(); + } + + void deinit() + { + if (dev) { + free(dev); + dev = NULL; + } + if (__handler.irq != SENSOR_PIN_NONE) { + detachInterrupt(__handler.irq); + } + } + + void reset() + { + if (__handler.rst != SENSOR_PIN_NONE) { + digitalWrite(__handler.rst, HIGH); + delay(5); + digitalWrite(__handler.rst, LOW); + delay(10); + digitalWrite(__handler.rst, HIGH); + delay(5); + } + } + + void sleep() + { + setMode(POWERMODE_SLEEP); + } + + bool setMode(PowerMode mode) + { + settings.pwr_mode = mode; + return bmm150_set_op_mode(&settings, dev) == BMM150_OK; + } + + bool setThreshold(uint8_t high_th, uint8_t low_th) + { + settings.int_settings.high_threshold = high_th; + settings.int_settings.low_threshold = low_th; + return bmm150_set_sensor_settings(BMM150_SEL_HIGH_THRESHOLD_SETTING, &settings, dev) == BMM150_OK; + } + + bool setInterruptLevel(InterruptLevel level) + { + settings.int_settings.high_int_en = level; + return bmm150_set_sensor_settings(BMM150_SEL_HIGH_THRESHOLD_INT, &settings, dev) == BMM150_OK; + } + + bool enableINT() + { + settings.int_settings.int_pin_en = BMM150_INT_ENABLE; + return bmm150_set_sensor_settings(BMM150_SEL_INT_PIN_EN, &settings, dev) == BMM150_OK; + } + + bool disableINT() + { + settings.int_settings.int_pin_en = BMM150_INT_DISABLE; + return bmm150_set_sensor_settings(BMM150_SEL_INT_PIN_EN, &settings, dev) == BMM150_OK; + } + + bool enabledDataReady() + { + settings.int_settings.drdy_pin_en = BMM150_INT_ENABLE; + return bmm150_set_sensor_settings(BMM150_SEL_DRDY_PIN_EN, &settings, dev) == BMM150_OK; + } + + bool disabledDataReady() + { + settings.int_settings.drdy_pin_en = BMM150_INT_DISABLE; + return bmm150_set_sensor_settings(BMM150_SEL_DRDY_PIN_EN, &settings, dev) == BMM150_OK; + } + + uint8_t getChipID() + { + return dev->chip_id; + } + + uint8_t getIrqStatus() + { + bmm150_get_interrupt_status(dev); + return dev->int_status; + } + + bool isDataReady() + { + return dev->int_status & BMM150_INT_ASSERTED_DRDY; + } + + bool isLowThreshold() + { + return dev->int_status & BMM150_INT_ASSERTED_LOW_THRES; + } + + bool isHighThreshold() + { + return dev->int_status & BMM150_INT_ASSERTED_HIGH_THRES; + } + + struct bmm150_mag_data getMag() + { + struct bmm150_mag_data data = {0, 0, 0}; + bmm150_read_mag_data(&data, dev); + return data; + } + + bool getMag(int16_t &x, int16_t &y, int16_t &z) + { + struct bmm150_mag_data data; + if (bmm150_read_mag_data(&data, dev) != BMM150_OK) { + return false; + } + x = data.x; + y = data.y; + z = data.z; + return true; + } + +private: + + static void handleISR(/*void *available*/) + { + // *(bool *)(available) = true; + __data_available = true; + } + + bool initImpl() + { + memset(&settings, 0, sizeof(settings)); + + if (__handler.rst != SENSOR_PIN_NONE) { + pinMode(__handler.rst, OUTPUT); + } + + reset(); + + dev = (struct bmm150_dev *)malloc(sizeof(struct bmm150_dev)); + BHY2_RLST_CHECK(!dev, " Device handler malloc failed!", false); + + switch (__handler.intf) { + case SENSORLIB_I2C_INTERFACE: + BHY2_RLST_CHECK(!__handler.u.i2c_dev.wire, "Wire ptr NULL", false); + if (!SensorInterfaces::setup_interfaces(__handler)) { + log_e("setup_interfaces failed"); + free(dev); + return false; + } + dev->intf = BMM150_I2C_INTF; + dev->read = SensorInterfaces::bhy2_i2c_read; + dev->write = SensorInterfaces::bhy2_i2c_write; + dev->intf_ptr = &__handler; + break; + + case SENSORLIB_SPI_INTERFACE: + BHY2_RLST_CHECK(!__handler.u.spi_dev.spi, "SPI ptr NULL", false); + if (!SensorInterfaces::setup_interfaces(__handler)) { + log_e("setup_interfaces failed"); + free(dev); + return false; + } + dev->intf = BMM150_I2C_INTF; + dev->read = SensorInterfaces::bhy2_spi_read; + dev->write = SensorInterfaces::bhy2_spi_write; + dev->intf_ptr = &__handler; + break; + default: + free(dev); + return false; + } + + dev->delay_us = SensorInterfaces::bhy2_delay_us; + __error_code = bmm150_init(dev); + if (__error_code != BMM150_OK) { + log_e("bmm150 init failed!"); + free(dev); + return false; + } + + __error_code = bmm150_soft_reset(dev); + if (__error_code != BMM150_OK) { + log_e("reset failed!"); + free(dev); + return false; + } + + bmm150_get_sensor_settings(&settings, dev); + + if (__handler.irq != SENSOR_PIN_NONE) { + /* + #if defined(ARDUINO_ARCH_RP2040) + attachInterruptParam((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING, (void *)&__data_available); + #else + attachInterruptArg(__handler.irq, handleISR, (void *)&__data_available, RISING); + #endif + */ +#if defined(ARDUINO_ARCH_RP2040) + attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING); +#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) + attachInterrupt(__handler.irq, handleISR, RISING); +#else +#error "Interrupt registration not implemented" +#endif + } + + return __error_code == BMM150_OK; + } + +protected: + struct bmm150_settings settings; + struct bmm150_dev *dev = NULL; + SensorLibConfigure __handler; + int8_t __error_code; + static volatile bool __data_available; +}; + + +#endif /*defined(ARDUINO)*/ + + + + diff --git a/components/SensorLib/src/SensorCM32181.hpp b/components/SensorLib/src/SensorCM32181.hpp new file mode 100644 index 0000000..63bc874 --- /dev/null +++ b/components/SensorLib/src/SensorCM32181.hpp @@ -0,0 +1,234 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorCM32181.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-14 + * + */ +#pragma once + +#include "REG/CM32181Constants.h" +#include "SensorCommon.tpp" + +class SensorCM32181 : + public SensorCommon +{ + friend class SensorCommon; +public: + + + enum Sampling { + SAMPLING_X1, //ALS Sensitivity x 1 + SAMPLING_X2, //ALS Sensitivity x 2 + SAMPLING_X1_8, //ALS Sensitivity x (1/8) + SAMPLING_X1_4, //ALS Sensitivity x (1/4) + }; + + enum IntegrationTime { + INTEGRATION_TIME_25MS = 0x0C, + INTEGRATION_TIME_50MS = 0x08, + INTEGRATION_TIME_100MS = 0x00, //0000 = 100ms + INTEGRATION_TIME_200MS, //0001 = 200ms + INTEGRATION_TIME_400MS, //0010 = 400ms + INTEGRATION_TIME_800MS, //0011 = 800ms + }; + + enum PowerSaveMode { + PowerSaveMode1 = 0x00, + PowerSaveMode2, + PowerSaveMode3, + PowerSaveMode4 + }; + + enum InterruptEvent { + ALS_EVENT_LOW_TRIGGER = 0x00, + ALS_EVENT_HIGH_TRIGGER, + ALS_EVENT_NULL, + }; + +#if defined(ARDUINO) + SensorCM32181(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = CM32181_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorCM32181() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = CM32181_SLAVE_ADDRESS; + } + + ~SensorCM32181() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = CM32181_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + void setSampling(Sampling tempSampling = SAMPLING_X1, + IntegrationTime int_time = INTEGRATION_TIME_200MS + ) + { + uint16_t data; + readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + data &= ~(0x03 << 11); + data |= tempSampling << 11; + data &= ~(0xF << 6); + data |= int_time << 6; + readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + } + + void setIntThreshold(uint16_t low_threshold, uint16_t high_threshold) + { + + uint8_t buffer[2] = {0}; + buffer[1] = highByte(high_threshold); + buffer[0] = lowByte(high_threshold);; + writeRegister(CM32181_REG_ALS_THDH, buffer, 2); + buffer[1] = highByte(low_threshold); + buffer[0] = lowByte(low_threshold); + writeRegister(CM32181_REG_ALS_THDL, buffer, 2); + } + + + void powerSave(PowerSaveMode mode, bool enable) + { + uint16_t data = 0x00; + readRegister(CM32181_REG_ALS_PSM, (uint8_t *)&data, 2); + data |= mode << 1; + enable ? data |= 0x01 : data |= 0x00; + writeRegister(CM32181_REG_ALS_PSM, (uint8_t *)&data, 2); + } + + // Read CM32181_REG_ALS_STATUS register to clear interrupt + InterruptEvent getIrqStatus() + { + uint16_t data; + readRegister(CM32181_REG_ALS_STATUS, (uint8_t *)&data, 2); + return bitRead(data, 15) ? ALS_EVENT_LOW_TRIGGER : bitRead(data, 14) ? ALS_EVENT_HIGH_TRIGGER : ALS_EVENT_NULL; + } + + void enableINT() + { + uint16_t data; + readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + bitWrite(data, 1, 1); + writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + } + + void disableINT() + { + uint16_t data; + readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + bitWrite(data, 1, 0); + writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + } + + void powerOn() + { + uint16_t data; + readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + bitClear(data, 0); + writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + } + + void powerDown() + { + uint16_t data; + readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + bitSet(data, 0); + writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2); + } + + uint16_t getRaw() + { + uint8_t buffer[2] = {0}; + readRegister(CM32181_REG_ALS_DATA, buffer, 2); + return (uint16_t) buffer[0] | (uint16_t)(buffer[1] << 8); + } + + float getLux() + { + return getRaw() * calibration_factor; + } + + int getChipID() + { + uint8_t buffer[2] = {0}; + readRegister(CM32181_REG_ID, buffer, 2); + return lowByte(buffer[0]); + } + +private: + + bool initImpl() + { + setReadRegisterSendStop(false); + + int chipID = getChipID(); + log_i("chipID:%d\n", chipID); + + if (chipID == DEV_WIRE_ERR ) { + return false; + } + if (chipID != CM32181_CHIP_ID) { + return false; + } + return true; + } + + int getReadMaskImpl() + { + return -1; + } + + +protected: + // The default calibration value, learned from the manual, + // is now unable to obtain the calibration value from the specified register + const float calibration_factor = 0.286; +}; + + + diff --git a/components/SensorLib/src/SensorCommon.tpp b/components/SensorLib/src/SensorCommon.tpp new file mode 100644 index 0000000..d1e0000 --- /dev/null +++ b/components/SensorLib/src/SensorCommon.tpp @@ -0,0 +1,711 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorCommon.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2022-10-16 + * + */ + + +#pragma once + +#include "SensorLib.h" + +typedef int (*iic_fptr_t)(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len); +typedef void (*gpio_write_fptr_t)(uint32_t gpio, uint8_t value); +typedef int (*gpio_read_fptr_t)(uint32_t gpio); +typedef void (*gpio_mode_fptr_t)(uint32_t gpio, uint8_t mode); +typedef void (*delay_ms_fptr_t)(uint32_t ms); + +template +class SensorCommon +{ +public: + ~SensorCommon() + { +#if defined(ARDUINO) + if (__spiSetting) { + delete __spiSetting; + } +#endif + } + +#if defined(ARDUINO) + void setSpiSetting(uint32_t freq, uint8_t dataOrder = SPI_DATA_ORDER, uint8_t dataMode = SPI_MODE0) + { + __freq = freq; + __dataOrder = dataOrder; + __dataMode = dataMode; + } + + bool begin(PLATFORM_WIRE_TYPE &w, uint8_t addr, int sda, int scl) + { + log_i("Using Arduino Wire interface."); + if (__has_init)return thisChip().initImpl(); + __wire = &w; + __sda = sda; + __scl = scl; +#if defined(ARDUINO_ARCH_NRF52) + if (__sda != 0xFF && __scl != 0xFF) { + __wire->setPins(__sda, __scl); + } + __wire->begin(); +#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) + if (__sda != 0xFF && __scl != 0xFF) { + __wire->end(); + __wire->setSDA(__sda); + __wire->setSCL(__scl); + } + __wire->begin(); +#elif defined(ARDUINO_ARCH_ESP32) + __wire->begin(__sda, __scl); +#else + __wire->begin(); +#endif + __addr = addr; + __spi = NULL; + __i2c_master_read = NULL; + __i2c_master_write = NULL; + __has_init = thisChip().initImpl(); + return __has_init; + } + + bool begin(int cs, int mosi = -1, int miso = -1, int sck = -1, + PLATFORM_SPI_TYPE &spi = SPI + ) + { + log_i("Using Arduino SPI interface."); + if (__has_init)return thisChip().initImpl(); + __cs = cs; + __spi = &spi; + pinMode(__cs, OUTPUT); + digitalWrite(__cs, HIGH); + __spiSetting = new DEFAULT_SPISETTING; + if (!__spiSetting) { + return false; + } + if (mosi != -1 && miso != -1 && sck != -1) { +#if defined(ARDUINO_ARCH_NRF52) + __spi->begin(); +#elif defined(ARDUINO_ARCH_RP2040) + __spi->setSCK(sck); + __spi->setRX(miso); + __spi->setTX(mosi); + __spi->begin(); +#elif defined(ARDUINO_ARCH_STM32) + __spi->setSCLK(sck); + __spi->setMISO(miso); + __spi->setMOSI(mosi); + __spi->begin(); +#else + __spi->begin(sck, miso, mosi); +#endif + } else { + __spi->begin(); + } + __wire = NULL; + __readMask = thisChip().getReadMaskImpl(); + __has_init = thisChip().initImpl(); + return __has_init; + } + +#elif defined(ESP_PLATFORM) && !defined(ARDUINO) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + // * Using the new API of esp-idf 5.x, you need to pass the I2C BUS handle, + // * which is useful when the bus shares multiple devices. + + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) + { + log_i("Using ESP-IDF Driver interface."); + if (i2c_dev_bus_handle == NULL) return false; + if (__has_init)return thisChip().initImpl(); + + __i2c_master_read = NULL; + __i2c_master_write = NULL; + __addr = addr; + + /* + i2c_master_bus_config_t i2c_bus_config; + memset(&i2c_bus_config, 0, sizeof(i2c_bus_config)); + i2c_bus_config.clk_source = I2C_CLK_SRC_DEFAULT; + i2c_bus_config.i2c_port = port_num; + i2c_bus_config.scl_io_num = (gpio_num_t)__scl; + i2c_bus_config.sda_io_num = (gpio_num_t)__sda; + i2c_bus_config.glitch_ignore_cnt = 7; + + i2c_new_master_bus(&i2c_bus_config, &bus_handle); + */ + bus_handle = i2c_dev_bus_handle; + + __i2c_dev_conf.dev_addr_length = I2C_ADDR_BIT_LEN_7; + __i2c_dev_conf.device_address = __addr; + __i2c_dev_conf.scl_speed_hz = SENSORLIB_I2C_MASTER_SEEED; +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,3,0)) +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,4,0)) + // New fields since esp-idf-v5.3-beta1 + __i2c_dev_conf.scl_wait_us = 0; +#endif + __i2c_dev_conf.flags.disable_ack_check = 0; +#endif + if (ESP_OK != i2c_master_bus_add_device(bus_handle, + &__i2c_dev_conf, + &__i2c_device)) { + log_i("i2c_master_bus_add_device failed !"); + return false; + } + log_i("Added Device Address : 0x%X New Dev Address: %p Speed :%lu ", __addr, __i2c_device, __i2c_dev_conf.scl_speed_hz); + __has_init = thisChip().initImpl(); + + if (!__has_init) { + // Initialization failed, delete device + log_i("i2c_master_bus_rm_device !"); + i2c_master_bus_rm_device(__i2c_device); + } + + return __has_init; + } + +#else //ESP 4.X + + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) + { + __i2c_num = port_num; + log_i("Using ESP-IDF Driver interface."); + if (__has_init)return thisChip().initImpl(); + __sda = sda; + __scl = scl; + __addr = addr; + __i2c_master_read = NULL; + __i2c_master_write = NULL; + + i2c_config_t i2c_conf; + memset(&i2c_conf, 0, sizeof(i2c_conf)); + i2c_conf.mode = I2C_MODE_MASTER; + i2c_conf.sda_io_num = sda; + i2c_conf.scl_io_num = scl; + i2c_conf.sda_pullup_en = GPIO_PULLUP_ENABLE; + i2c_conf.scl_pullup_en = GPIO_PULLUP_ENABLE; + i2c_conf.master.clk_speed = SENSORLIB_I2C_MASTER_SEEED; + + /** + * @brief Without checking whether the initialization is successful, + * I2C may be initialized externally, + * so just make sure there is an initialization here. + */ + i2c_param_config(__i2c_num, &i2c_conf); + i2c_driver_install(__i2c_num, + i2c_conf.mode, + SENSORLIB_I2C_MASTER_RX_BUF_DISABLE, + SENSORLIB_I2C_MASTER_TX_BUF_DISABLE, 0); + __has_init = thisChip().initImpl(); + return __has_init; + } +#endif //ESP 5.X + +#endif + + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) + { + log_i("Using Custom interface."); + if (__has_init)return thisChip().initImpl(); + __i2c_master_read = readRegCallback; + __i2c_master_write = writeRegCallback; + __addr = addr; +#if defined(ARDUINO) + __spi = NULL; +#endif + __has_init = thisChip().initImpl(); + return __has_init; + } + + void setGpioWriteCallback(gpio_write_fptr_t cb) + { + __set_gpio_level = cb; + } + + void setGpioReadCallback(gpio_read_fptr_t cb) + { + __get_gpio_level = cb; + } + + void setGpioModeCallback(gpio_mode_fptr_t cb) + { + __set_gpio_mode = cb; + } + + void setDelayCallback(delay_ms_fptr_t cb) + { + __delay_ms = cb; + } + +protected: + + inline void setGpioMode(uint32_t gpio, uint8_t mode) + { + if (__set_gpio_mode) { + return __set_gpio_mode(gpio, mode); + } +#if defined(ARDUINO) || defined(ESP_PLATFORM) + return pinMode(gpio, mode); +#endif + } + + inline void setGpioLevel(uint32_t gpio, uint8_t level) + { + if (__set_gpio_level) { + return __set_gpio_level(gpio, level); + } +#if defined(ARDUINO) || defined(ESP_PLATFORM) + return digitalWrite(gpio, level); +#endif + } + + inline int getGpioLevel(uint32_t gpio) + { + if (__get_gpio_level) { + return __get_gpio_level(gpio); + } +#if defined(ARDUINO) || defined(ESP_PLATFORM) + return digitalRead(gpio); +#endif + } + + bool probe(uint8_t address) + { +#if defined(ARDUINO) + if (__wire) { + __wire->beginTransmission(address); + return __wire->endTransmission() == 0; + } + return false; +#elif defined(ESP_PLATFORM) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + return i2c_master_probe(bus_handle, address, 1000); +#else + return true; +#endif +#else + return true; +#endif + } + + bool probe() + { +#if defined(ARDUINO) + if (__wire) { + __wire->beginTransmission(__addr); + return __wire->endTransmission() == 0; + } + return false; +#elif defined(ESP_PLATFORM) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + return i2c_master_probe(bus_handle, __addr, 1000); +#else + return true; +#endif +#else + return true; +#endif + } + + //! Write method + int writeRegister(uint8_t reg, uint8_t norVal, uint8_t orVal) + { + int val = readRegister(reg); + if (val == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + val &= norVal; + val |= orVal; + return writeRegister(reg, val); + } + + int writeRegister(int reg, uint8_t val) + { + return writeRegister(reg, &val, 1); + } + + int writeThenRead(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len) + { +#if defined(ARDUINO) + if (__wire) { + __wire->beginTransmission(__addr); + __wire->write(write_buffer, write_len); + if (__wire->endTransmission(__sendStop) != 0) { + return DEV_WIRE_ERR; + } + __wire->requestFrom(__addr, read_len); + return __wire->readBytes(read_buffer, read_len) == read_len ? DEV_WIRE_NONE : DEV_WIRE_ERR; + } +#elif defined(ESP_PLATFORM) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + if (ESP_OK == i2c_master_transmit_receive( + __i2c_device, + write_buffer, + write_len, + read_buffer, + read_len, + -1)) { + return DEV_WIRE_NONE; + } +#else //ESP_IDF_VERSION + if (ESP_OK == i2c_master_write_read_device( + __i2c_num, + __addr, + write_buffer, + write_len, + read_buffer, + read_len, + SENSORLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) { + return DEV_WIRE_NONE; + } +#endif //ESP_IDF_VERSION + +#endif //ESP_PLATFORM + return DEV_WIRE_ERR; + } + + int writeBuffer(uint8_t *buf, size_t length) + { +#if defined(ARDUINO) + if (__wire) { + __wire->beginTransmission(__addr); + __wire->write(buf, length); + uint8_t ret = (__wire->endTransmission()); + return ret == 0 ? DEV_WIRE_NONE : DEV_WIRE_ERR; + } +#elif defined(ESP_PLATFORM) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + if (ESP_OK == i2c_master_transmit( + __i2c_device, + buf, + length, + -1)) { + return DEV_WIRE_NONE; + } +#else //ESP_IDF_VERSION + if (ESP_OK == i2c_master_write_to_device(__i2c_num, + __addr, + buf, + length, + SENSORLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) { + return DEV_WIRE_NONE; + } +#endif //ESP_IDF_VERSION + +#endif //ESP_PLATFORM + return DEV_WIRE_ERR; + } + + int writeRegister(int reg, uint8_t *buf, size_t length) + { + if (__i2c_master_write) { + return __i2c_master_write(__addr, reg, buf, length); + } +#if defined(ARDUINO) + if (__wire) { + __wire->beginTransmission(__addr); + if (__reg_addr_len == 1) { + __wire->write(reg); + } else { + for (int i = 0; i < __reg_addr_len; ++i) { + __wire->write(reg >> (8 * ((__reg_addr_len - 1) - i))); + } + } + __wire->write(buf, length); + return (__wire->endTransmission() == 0) ? DEV_WIRE_NONE : DEV_WIRE_ERR; + } + if (__spi) { + __spi->beginTransaction(*__spiSetting); + digitalWrite(__cs, LOW); + if (__reg_addr_len == 1) { + __spi->transfer(reg); + } else { + for (int i = 0; i < __reg_addr_len; ++i) { + __spi->transfer(reg >> (8 * ((__reg_addr_len - 1) - i))); + } + } + __spi->transfer(buf, length); + digitalWrite(__cs, HIGH); + __spi->endTransaction(); + return DEV_WIRE_NONE; + } + return DEV_WIRE_ERR; + +#elif defined(ESP_PLATFORM) + uint8_t *write_buffer = (uint8_t *)malloc(sizeof(uint8_t) * (length + __reg_addr_len)); + if (!write_buffer) { + return DEV_WIRE_ERR; + } + write_buffer[0] = reg; + memcpy(write_buffer, ®, __reg_addr_len); + memcpy(write_buffer + __reg_addr_len, buf, length); + int ret = writeBuffer(write_buffer, __reg_addr_len + length); + free(write_buffer); + return ret; +#endif //ESP_PLATFORM + } + + //! Read method + int readRegister(int reg) + { + uint8_t val = 0; + return readRegister(reg, &val, 1) == -1 ? -1 : val; + } + + int readRegister(int reg, uint8_t *buf, uint8_t length) + { + if (__i2c_master_read) { + return __i2c_master_read(__addr, reg, buf, length); + } +#if defined(ARDUINO) + if (__wire) { + __wire->beginTransmission(__addr); + if (__reg_addr_len == 1) { + __wire->write(reg); + } else { + for (int i = 0; i < __reg_addr_len; ++i) { + __wire->write(reg >> (8 * ((__reg_addr_len - 1) - i))); + } + } + if (__wire->endTransmission(__sendStop) != 0) { + return DEV_WIRE_ERR; + } + __wire->requestFrom(__addr, length); + return __wire->readBytes(buf, length) == length ? DEV_WIRE_NONE : DEV_WIRE_ERR; + } + if (__spi) { + __spi->beginTransaction(*__spiSetting); + digitalWrite(__cs, LOW); + if (__reg_addr_len == 1) { + __spi->transfer(__readMask != -1 ? (reg | __readMask) : reg); + } else { + uint8_t firstBytes = reg >> (8 * ((__reg_addr_len - 1))); + __spi->transfer(__readMask != -1 ? (firstBytes | __readMask) : firstBytes); + for (int i = 1; i < __reg_addr_len; ++i) { + __spi->transfer(reg >> (8 * ((__reg_addr_len - 1) - i))); + } + } + for (size_t i = 0; i < length; i++) { + buf[i] = __spi->transfer(0x00); + } + digitalWrite(__cs, HIGH); + __spi->endTransaction(); + return DEV_WIRE_NONE; + } +#elif defined(ESP_PLATFORM) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + if (ESP_OK == i2c_master_transmit_receive( + __i2c_device, + (const uint8_t *)®, + __reg_addr_len, + buf, + length, + -1)) { + return DEV_WIRE_NONE; + } +#else //ESP_IDF_VERSION + if (ESP_OK == i2c_master_write_read_device(__i2c_num, + __addr, + (uint8_t *)®, + __reg_addr_len, + buf, + length, + SENSORLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) { + return DEV_WIRE_NONE; + } +#endif //ESP_IDF_VERSION + +#endif //ESP_PLATFORM + return DEV_WIRE_ERR; + } + + bool inline clrRegisterBit(int registers, uint8_t bit) + { + int val = readRegister(registers); + if (val == DEV_WIRE_ERR) { + return false; + } + return writeRegister(registers, (val & (~_BV(bit)))) == 0; + } + + bool inline setRegisterBit(int registers, uint8_t bit) + { + int val = readRegister(registers); + if (val == DEV_WIRE_ERR) { + return false; + } + return writeRegister(registers, (val | (_BV(bit)))) == 0; + } + + bool inline getRegisterBit(int registers, uint8_t bit) + { + int val = readRegister(registers); + if (val == DEV_WIRE_ERR) { + return false; + } + return val & _BV(bit); + } + + uint16_t inline readRegisterH8L4(uint8_t highReg, uint8_t lowReg) + { + int h8 = readRegister(highReg); + int l4 = readRegister(lowReg); + if (h8 == DEV_WIRE_ERR || l4 == DEV_WIRE_ERR)return 0; + return (h8 << 4) | (l4 & 0x0F); + } + + uint16_t inline readRegisterH8L5(uint8_t highReg, uint8_t lowReg) + { + int h8 = readRegister(highReg); + int l5 = readRegister(lowReg); + if (h8 == DEV_WIRE_ERR || l5 == DEV_WIRE_ERR)return 0; + return (h8 << 5) | (l5 & 0x1F); + } + + uint16_t inline readRegisterH6L8(uint8_t highReg, uint8_t lowReg) + { + int h6 = readRegister(highReg); + int l8 = readRegister(lowReg); + if (h6 == DEV_WIRE_ERR || l8 == DEV_WIRE_ERR)return 0; + return ((h6 & 0x3F) << 8) | l8; + } + + uint16_t inline readRegisterH5L8(uint8_t highReg, uint8_t lowReg) + { + int h5 = readRegister(highReg); + int l8 = readRegister(lowReg); + if (h5 == DEV_WIRE_ERR || l8 == DEV_WIRE_ERR)return 0; + return ((h5 & 0x1F) << 8) | l8; + } + + void setRegAddressLength(uint8_t len) + { + __reg_addr_len = len; + } + + + void setReadRegisterSendStop(bool sendStop) + { + __sendStop = sendStop; + } + + + bool reallocBuffer(size_t realloc_size) + { +#if defined(ARDUINO) + +#ifdef ARDUINO_ARCH_ESP32 + // ESP32 I2C BUFFER : 128 Bytes + if (__wire) { + if (__wire->setBufferSize(realloc_size) != realloc_size) { + log_e("realloc I2C buffer failed!"); + return false; + } + } +#elif defined(ARDUINO_ARCH_RP2040) + // RP2040 I2C BUFFER : 256 Bytes + +#elif defined(ARDUINO_ARCH_NRF52) + // NRF52840 I2C BUFFER : 64 Bytes +// #warning "NRF Platform I2C Buffer expansion is not implemented" + //TODO:"NRF Platform I2C Buffer expansion is not implemented" +#endif +#endif + return true; + } + + /* + * CRTP Helper + */ +protected: + + void end() + { +#if defined(ARDUINO) + if (__wire) { +#if defined(ESP_IDF_VERSION) +#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4,4,0) + __wire->end(); +#endif /*ESP_IDF_VERSION*/ +#endif /*ESP_IDF_VERSION*/ + } +#endif /*ARDUINO*/ + } + + + inline const chipType &thisChip() const + { + return static_cast(*this); + } + + inline chipType &thisChip() + { + return static_cast(*this); + } + +protected: + bool __has_init = false; +#if defined(ARDUINO) + PLATFORM_WIRE_TYPE *__wire = NULL; + PLATFORM_SPI_TYPE *__spi = NULL; + SPISettings *__spiSetting = NULL; + uint8_t __dataOrder = SPI_DATA_ORDER; + uint8_t __dataMode = SPI_MODE0; + uint32_t __freq = 400000; + +#elif defined(ESP_PLATFORM) + i2c_port_t __i2c_num; +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + i2c_master_bus_handle_t bus_handle; + i2c_master_dev_handle_t __i2c_device; + i2c_device_config_t __i2c_dev_conf; +#endif //ESP_IDF_VERSION + +#endif //ESP_PLATFORM + + int __readMask = -1; + int __sda = -1; + int __scl = -1; + int __cs = -1; + int __miso = -1; + int __mosi = -1; + int __sck = -1; + bool __sendStop = true; + uint8_t __addr = 0xFF; + uint8_t __reg_addr_len = 1; + iic_fptr_t __i2c_master_read = NULL; + iic_fptr_t __i2c_master_write = NULL; + gpio_write_fptr_t __set_gpio_level = NULL; + gpio_read_fptr_t __get_gpio_level = NULL; + gpio_mode_fptr_t __set_gpio_mode = NULL; + delay_ms_fptr_t __delay_ms = NULL; + +}; diff --git a/components/SensorLib/src/SensorDRV2605.hpp b/components/SensorLib/src/SensorDRV2605.hpp new file mode 100644 index 0000000..87eef56 --- /dev/null +++ b/components/SensorLib/src/SensorDRV2605.hpp @@ -0,0 +1,235 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorDRV2605.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-03 + * @note Source code from https://github.com/adafruit/Adafruit_DRV2605_Library + */ +#pragma once + +#include "REG/DRV2605Constants.h" +#include "SensorCommon.tpp" + +class SensorDRV2605 : + public SensorCommon +{ + friend class SensorCommon; +public: + +#if defined(ARDUINO) + SensorDRV2605(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = DRV2605_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorDRV2605() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = DRV2605_SLAVE_ADDRESS; + } + + ~SensorDRV2605() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = DRV2605_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + /**************************************************************************/ + /*! + @brief Select the haptic waveform to use. + @param slot The waveform slot to set, from 0 to 7 + @param w The waveform sequence value, refers to an index in the ROM library. + + Playback starts at slot 0 and continues through to slot 7, stopping if it + encounters a value of 0. A list of available waveforms can be found in + section 11.2 of the datasheet: http://www.adafruit.com/datasheets/DRV2605.pdf + */ + /**************************************************************************/ + void setWaveform(uint8_t slot, uint8_t w) + { + writeRegister(DRV2605_REG_WAVESEQ1 + slot, w); + } + + /**************************************************************************/ + /*! + @brief Select the waveform library to use. + @param lib Library to use, 0 = Empty, 1-5 are ERM, 6 is LRA. + + See section 7.6.4 in the datasheet for more details: + http://www.adafruit.com/datasheets/DRV2605.pdf + */ + /**************************************************************************/ + void selectLibrary(uint8_t lib) + { + writeRegister(DRV2605_REG_LIBRARY, lib); + } + + /**************************************************************************/ + /*! + @brief Start playback of the waveforms (start moving!). + */ + /**************************************************************************/ + void run() + { + writeRegister(DRV2605_REG_GO, 1); + } + + /**************************************************************************/ + /*! + @brief Stop playback. + */ + /**************************************************************************/ + void stop() + { + writeRegister(DRV2605_REG_GO, 0); + } + + /**************************************************************************/ + /*! + @brief Set the device mode. + @param mode Mode value, see datasheet section 7.6.2: + http://www.adafruit.com/datasheets/DRV2605.pdf + + 0: Internal trigger, call run() to start playback\n + 1: External trigger, rising edge on IN pin starts playback\n + 2: External trigger, playback follows the state of IN pin\n + 3: PWM/analog input\n + 4: Audio\n + 5: Real-time playback\n + 6: Diagnostics\n + 7: Auto calibration + */ + /**************************************************************************/ + void setMode(uint8_t mode) + { + writeRegister(DRV2605_REG_MODE, mode); + } + + /**************************************************************************/ + /*! + @brief Set the realtime value when in RTP mode, used to directly drive the + haptic motor. + @param rtp 8-bit drive value. + */ + /**************************************************************************/ + void setRealtimeValue(uint8_t rtp) + { + writeRegister(DRV2605_REG_RTPIN, rtp); + } + + /**************************************************************************/ + /*! + @brief Use ERM (Eccentric Rotating Mass) mode. + */ + /**************************************************************************/ + void useERM() + { + writeRegister(DRV2605_REG_FEEDBACK, readRegister(DRV2605_REG_FEEDBACK) & 0x7F); + } + + /**************************************************************************/ + /*! + @brief Use LRA (Linear Resonance Actuator) mode. + */ + /**************************************************************************/ + void useLRA() + { + writeRegister(DRV2605_REG_FEEDBACK, readRegister(DRV2605_REG_FEEDBACK) | 0x80); + } + +private: + bool initImpl() + { + int chipID = readRegister(DRV2605_REG_STATUS); + if (chipID == -1) { + return false; + } + chipID >>= 5; + + if (chipID != DRV2604_CHIP_ID && + chipID != DRV2605_CHIP_ID && + chipID != DRV2604L_CHIP_ID && + chipID != DRV2605L_CHIP_ID ) { + LOG("ChipID:0x%x should be 0x03 or 0x04 or 0x06 or 0x07\n", chipID); + return false; + } + + writeRegister(DRV2605_REG_MODE, 0x00); // out of standby + + writeRegister(DRV2605_REG_RTPIN, 0x00); // no real-time-playback + + writeRegister(DRV2605_REG_WAVESEQ1, 1); // strong click + writeRegister(DRV2605_REG_WAVESEQ2, 0); // end sequence + + writeRegister(DRV2605_REG_OVERDRIVE, 0); // no overdrive + + writeRegister(DRV2605_REG_SUSTAINPOS, 0); + writeRegister(DRV2605_REG_SUSTAINNEG, 0); + writeRegister(DRV2605_REG_BREAK, 0); + writeRegister(DRV2605_REG_AUDIOMAX, 0x64); + + // ERM open loop + + // turn off N_ERM_LRA + writeRegister(DRV2605_REG_FEEDBACK, + readRegister(DRV2605_REG_FEEDBACK) & 0x7F); + // turn on ERM_OPEN_LOOP + writeRegister(DRV2605_REG_CONTROL3, + readRegister(DRV2605_REG_CONTROL3) | 0x20); + + return true; + } + + int getReadMaskImpl() + { + return -1; + } + +protected: + +}; + + + diff --git a/components/SensorLib/src/SensorLTR553.hpp b/components/SensorLib/src/SensorLTR553.hpp new file mode 100644 index 0000000..58c465a --- /dev/null +++ b/components/SensorLib/src/SensorLTR553.hpp @@ -0,0 +1,349 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorLTR553ALS.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-09 + * + */ +#pragma once + +#include "REG/LTR533Constants.h" +#include "SensorCommon.tpp" + + +class SensorLTR553 : + public SensorCommon +{ + friend class SensorCommon; +public: + + enum IrqLevel { + ALS_IRQ_ACTIVE_LOW, // INT pin is considered active when it is a logic 0 (default) + ALS_IRQ_ACTIVE_HIGH // INT pin is considered active when it is a logic 1 + }; + enum IrqMode { + ALS_IRQ_ONLY_PS = 1, // Only PS measurement can trigger interrupt + ALS_IRQ_ONLY_ALS, // Only ALS measurement can trigger interrupt + ALS_IRQ_BOTH, // Both ALS and PS measurement can trigger interrupt + }; + + enum LightSensorGain { + ALS_GAIN_1X = 0x00, // 1 lux to 64k lux (default) + ALS_GAIN_2X = 0x01, // 0.5 lux to 32k lux + ALS_GAIN_4X = 0x02, // 0.25 lux to 16k lux + ALS_GAIN_8X = 0x03, // 0.125 lux to 8k lux + ALS_GAIN_48X = 0x06, // 0.02 lux to 1.3k lux + ALS_GAIN_96X = 0x07, // 0.01 lux to 600 lux + }; + + enum PsLedPeriod { + PS_LED_PLUSE_30KHZ = 0x00, + PS_LED_PLUSE_40KHZ, + PS_LED_PLUSE_50KHZ, + PS_LED_PLUSE_60KHZ, + PS_LED_PLUSE_70KHZ, + PS_LED_PLUSE_80KHZ, + PS_LED_PLUSE_90KHZ, + PS_LED_PLUSE_100KHZ, + }; + enum PsLedDuty { + PS_LED_DUTY_25 = 0x00, + PS_LED_DUTY_50, + PS_LED_DUTY_75, + PS_LED_DUTY_100, + }; + enum PsLedCurrent { + PS_LED_CUR_5MA = 0x00, + PS_LED_CUR_10MA, + PS_LED_CUR_20MA, + PS_LED_CUR_50MA, + PS_LED_CUR_100MA, + }; + enum PsRate { + PS_MEAS_RATE_50MS, + PS_MEAS_RATE_70MS, + PS_MEAS_RATE_100MS, + PS_MEAS_RATE_200MS, + PS_MEAS_RATE_500MS, + PS_MEAS_RATE_1000MS, + PS_MEAS_RATE_2000MS, + PS_MEAS_RATE_10MS = 8, + }; + + enum IntegrationTime { + ALS_INTEGRATION_TIME_100MS = 0x00, + ALS_INTEGRATION_TIME_50MS, + ALS_INTEGRATION_TIME_200MS, + ALS_INTEGRATION_TIME_400MS, + ALS_INTEGRATION_TIME_150MS, + ALS_INTEGRATION_TIME_250MS, + ALS_INTEGRATION_TIME_300MS, + ALS_INTEGRATION_TIME_350MS, + }; + + enum MeasurementRate { + ALS_MEASUREMENT_TIME_50MS, + ALS_MEASUREMENT_TIME_100MS, + ALS_MEASUREMENT_TIME_200MS, + ALS_MEASUREMENT_TIME_500MS, + ALS_MEASUREMENT_TIME_1000MS, + ALS_MEASUREMENT_TIME_2000MS, + }; + +#if defined(ARDUINO) + SensorLTR553(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = LTR553_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorLTR553() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = LTR553_SLAVE_ADDRESS; + } + + ~SensorLTR553() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = LTR553_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + void setIRQLevel(IrqLevel level) + { + level ? setRegisterBit(LTR553_REG_INTERRUPT, 2) : clrRegisterBit(LTR553_REG_INTERRUPT, 2); + } + + void enableIRQ(IrqMode mode) + { + writeRegister(LTR553_REG_INTERRUPT, 0xFC, mode); + } + + void disableIRQ() + { + writeRegister(LTR553_REG_INTERRUPT, 0xFC, 0x00); + } + + + //! Light Sensor ! + bool psAvailable() + { + return getRegisterBit(LTR553_REG_ALS_PS_STATUS, 0); + } + + void setLightSensorThreshold(uint16_t low, uint16_t high) + { + uint8_t buffer[4] = { + (uint8_t)(high & 0xFF), + (uint8_t)((high >> 8) & 0xFF), + (uint8_t)(low & 0xFF), + (uint8_t)((low >> 8) & 0xFF), + }; + writeRegister(LTR553_REG_ALS_THRES_UP_0, buffer, 4); + } + + // Controls the N number of times the measurement data is outside the range + // defined by the upper and lower threshold limits before asserting the interrupt. + void setLightSensorPersists(uint8_t count) + { + writeRegister(LTR553_REG_INTERRUPT_PERSIST, 0xF0, count - 1); + } + + void setLightSensorRate(IntegrationTime integrationTime, MeasurementRate measurementRate) + { + writeRegister(LTR553_REG_ALS_MEAS_RATE, 0x00, (integrationTime & 0xF) << 8 | (measurementRate & 0xF)); + } + + void enableLightSensor() + { + setRegisterBit(LTR553_REG_ALS_CONTR, 0); + } + + void disableLightSensor() + { + clrRegisterBit(LTR553_REG_ALS_CONTR, 0); + } + + void setLightSensorGain(LightSensorGain gain) + { + writeRegister(LTR553_REG_ALS_CONTR, 0xE3, gain); + } + + int getLightSensor(uint8_t ch) + { + uint8_t buffer[2] = {0}; + // Check ALS Data is Valid + if (getRegisterBit(LTR553_REG_ALS_PS_STATUS, 7) != false) { + return 0; + } + int val = readRegister(ch == 1 ? LTR553_REG_ALS_DATA_CH1_0 : LTR553_REG_ALS_DATA_CH0_0, buffer, 2); + if (val == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + return buffer[0] | (buffer[1] << 8); + } + + //! Proximity sensor ! + // Controls the N number of times the measurement data is outside the range + // defined by the upper and lower threshold limits before asserting the interrupt. + void setProximityPersists(uint8_t count) + { + writeRegister(LTR553_REG_INTERRUPT_PERSIST, 0x0F, count == 0 ? 0 : count - 1); + } + + void setProximityThreshold(uint16_t low, uint16_t high) + { + writeRegister(LTR553_REG_PS_THRES_UP_0, lowByte(high)); + writeRegister(LTR553_REG_PS_THRES_UP_1, lowByte(high >> 8) & 0x0F); + writeRegister(LTR553_REG_PS_THRES_LOW_0, lowByte(low)); + writeRegister(LTR553_REG_PS_THRES_LOW_1, lowByte(low >> 8) & 0x0F); + } + + void setProximityRate(PsRate rate) + { + writeRegister(LTR553_REG_PS_MEAS_RATE, 0xF0, rate & 0x0F); + } + + void enableProximity() + { + writeRegister(LTR553_REG_PS_CONTR, 0xF3u, 0x03u); + } + + void disableProximity() + { + writeRegister(LTR553_REG_PS_CONTR, 0xF3u, 0x00u); + } + + void enablePsIndicator() + { + setRegisterBit(LTR553_REG_PS_CONTR, 5); + } + + void disablePsIndicator() + { + clrRegisterBit(LTR553_REG_PS_CONTR, 5); + } + + int getProximity(bool *saturated = NULL ) + { + uint8_t buffer[2] = {0}; + int val = readRegister(LTR553_REG_PS_DATA_0, buffer, 2); + if (val == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + if (saturated) { + *saturated = buffer[1] & 0x80; + } + return buffer[0] | (buffer[1] & 0x03); + } + + void setPsLedPulsePeriod(PsLedPeriod period) + { + writeRegister(LTR553_REG_PS_LED, 0x1F, period); + } + + void setPsLedDutyCycle(PsLedDuty duty) + { + writeRegister(LTR553_REG_PS_LED, 0xE7, duty); + } + + void setPsLedCurrent(PsLedCurrent cur) + { + writeRegister(LTR553_REG_PS_LED, 0xF8, cur); + } + + void setPsLedPulses(uint8_t pulesNum) + { + writeRegister(LTR553_REG_PS_N_PULSES, 0xF0, pulesNum & 0x0F); + } + + int getPartID() + { + int val = readRegister(LTR553_REG_PART_ID); + if (val == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + return (val >> 4) & 0x0F; + } + + int getRevisionID() + { + int val = readRegister(LTR553_REG_PART_ID); + if (val == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + return (val) & 0x0F; + } + + int getManufacturerID() + { + // Manufacturer ID (0x05H) + return readRegister(LTR553_REG_MANUFAC_ID); + } + + void reset() + { + setRegisterBit(LTR553_REG_ALS_CONTR, 1); + } + +private: + + bool initImpl() + { + setReadRegisterSendStop(false); + reset(); + return getManufacturerID() == LTR553_DEFAULT_MAN_ID; + } + + int getReadMaskImpl() + { + return -1; + } + +protected: + +}; + + + diff --git a/components/SensorLib/src/SensorLib.h b/components/SensorLib/src/SensorLib.h new file mode 100644 index 0000000..c3bb954 --- /dev/null +++ b/components/SensorLib/src/SensorLib.h @@ -0,0 +1,248 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorLib.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-05 + */ + +#pragma once + +#if defined(ARDUINO) +#include +#include +#include +#elif defined(ESP_PLATFORM) +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "esp_log.h" +#include "esp_err.h" +#include +#include "esp_idf_version.h" +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) +#include "driver/i2c_master.h" +#else +#include "driver/i2c.h" +#endif //ESP_IDF_VERSION +#else +#include +#include +#include +#endif + +#ifdef ARDUINO_ARCH_MBED +// Not supported at the moment +#error The Arduino RP2040 MBED board package is not supported when PIO is used. Use the community package by Earle Philhower. +#endif + +#if defined(ARDUINO) +#if defined(ARDUINO_ARCH_RP2040) +#define PLATFORM_SPI_TYPE SPIClassRP2040 +#define PLATFORM_WIRE_TYPE TwoWire +#define SPI_DATA_ORDER SPI_MSB_FIRST +#define DEFAULT_SDA (0xFF) +#define DEFAULT_SCL (0xFF) +#define DEFAULT_SPISETTING SPISettings() +#elif defined(ARDUINO_ARCH_STM32) +#define PLATFORM_SPI_TYPE SPIClass +#define PLATFORM_WIRE_TYPE TwoWire +#define SPI_DATA_ORDER MSBFIRST +#define DEFAULT_SDA (0xFF) +#define DEFAULT_SCL (0xFF) +#define DEFAULT_SPISETTING SPISettings() +#elif defined(ARDUINO_ARCH_NRF52) +#define PLATFORM_SPI_TYPE SPIClass +#define PLATFORM_WIRE_TYPE TwoWire +#define SPI_DATA_ORDER MSBFIRST +#define DEFAULT_SDA (0xFF) +#define DEFAULT_SCL (0xFF) +#define DEFAULT_SPISETTING SPISettings() +#else +#define PLATFORM_SPI_TYPE SPIClass +#define PLATFORM_WIRE_TYPE TwoWire +#define SPI_DATA_ORDER SPI_MSBFIRST +#define DEFAULT_SDA (SDA) +#define DEFAULT_SCL (SCL) +#define DEFAULT_SPISETTING SPISettings(__freq, __dataOrder, __dataMode); +#endif + +#elif defined(ESP_PLATFORM) + +#define SENSORLIB_I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ +#define SENSORLIB_I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ +#define SENSORLIB_I2C_MASTER_TIMEOUT_MS 1000 +#define SENSORLIB_I2C_MASTER_SEEED 400000 + +#endif + +#ifndef I2C_BUFFER_LENGTH +#define I2C_BUFFER_LENGTH (32) +#endif + +enum SensorLibInterface { + SENSORLIB_SPI_INTERFACE = 1, + SENSORLIB_I2C_INTERFACE +}; + +typedef struct __SensorLibPins { + int irq; + int rst; + union __ { + struct { + int sda; + int scl; + int addr; +#ifdef ARDUINO + PLATFORM_WIRE_TYPE *wire; +#endif + } i2c_dev; + struct { + int cs; + int miso; + int mosi; + int sck; +#ifdef ARDUINO + PLATFORM_SPI_TYPE *spi; +#endif + } spi_dev; + } u ; + SensorLibInterface intf; +} SensorLibConfigure; + + + + +#define SENSOR_PIN_NONE (-1) +#define DEV_WIRE_NONE (0) +#define DEV_WIRE_ERR (-1) +#define DEV_WIRE_TIMEOUT (-2) + + + + +#ifndef IRAM_ATTR +#define IRAM_ATTR +#endif + +#ifdef _BV +#undef _BV +#endif +#define _BV(b) (1UL << (uint32_t)(b)) + +// #define LOG_PORT Serial +#ifdef LOG_PORT +#define LOG(fmt, ...) LOG_PORT.printf("[%s] " fmt "\n", __func__, ##__VA_ARGS__) +#define LOG_BIN(x) LOG_PORT.println(x,BIN); +#else +#define LOG(fmt, ...) printf("[%s] " fmt "\n", __func__, ##__VA_ARGS__) +#define LOG_BIN(x) printf("[%s] 0x%X\n", __func__, x) +#endif + +#ifndef lowByte +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#endif + +#ifndef highByte +#define highByte(w) ((uint8_t) ((w) >> 8)) +#endif + +#ifndef bitRead +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#endif + +#ifndef bitSet +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#endif + +#ifndef bitClear +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#endif + +#ifndef bitToggle +#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) +#endif + +#ifndef bitWrite +#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) +#endif + +#define SENSORLIB_ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented"))) + +#define SENSORLIB_COUNT(x) (sizeof(x)/sizeof(*x)) + +#ifdef ARDUINO +#if !defined(ESP32) || !defined(ARDUINO_ARCH_ESP32) +#define LOG_FILE_LINE_INFO __FILE__, __LINE__ +#ifndef log_e +#define log_e(fmt, ...) Serial.printf("[E][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__) +#endif +#ifndef log_i +#define log_i(fmt, ...) Serial.printf("[I][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__) +#endif +#ifndef log_d +#define log_d(fmt, ...) Serial.printf("[D][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__) +#endif +#endif +#elif defined(ESP_PLATFORM) +#define log_e(...) printf(__VA_ARGS__) +#define log_i(...) printf(__VA_ARGS__) +#define log_d(...) printf(__VA_ARGS__) +#else +#define log_e(...) +#define log_i(...) +#define log_d(...) +#endif + +#if !defined(ARDUINO) && defined(ESP_PLATFORM) + +#ifndef INPUT +#define INPUT (0x0) +#endif + +#ifndef OUTPUT +#define OUTPUT (0x1) +#endif + +#ifndef RISING +#define RISING (0x01) +#endif + +#ifndef FALLING +#define FALLING (0x02) +#endif + +#ifndef LOW +#define LOW 0 +#endif + +#ifndef HIGH +#define HIGH 1 +#endif + +#include "platform/esp_arduino.h" + +#endif + + +#include "DevicesPins.h" \ No newline at end of file diff --git a/components/SensorLib/src/SensorPCF85063.hpp b/components/SensorLib/src/SensorPCF85063.hpp new file mode 100644 index 0000000..2b8cf45 --- /dev/null +++ b/components/SensorLib/src/SensorPCF85063.hpp @@ -0,0 +1,392 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorPCF85063.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-07 + * + */ +#pragma once +#include "REG/PCF85063Constants.h" +#include "SensorCommon.tpp" +#include "SensorRTC.h" + + +class SensorPCF85063 : + public SensorCommon, + public RTCCommon +{ + friend class SensorCommon; + friend class RTCCommon; +public: + + enum ClockHz { + CLK_32768HZ = 0, + CLK_16384HZ, + CLK_8192HZ, + CLK_4096HZ, + CLK_2048HZ, + CLK_1024HZ, + CLK_1HZ, + CLK_LOW, + }; + + +#if defined(ARDUINO) + SensorPCF85063(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF85063_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorPCF85063() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = PCF85063_SLAVE_ADDRESS; + } + + ~SensorPCF85063() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF85063_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + void setDateTime(RTC_DateTime datetime) + { + setDateTime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second); + } + + void setDateTime(uint16_t year, + uint8_t month, + uint8_t day, + uint8_t hour, + uint8_t minute, + uint8_t second) + { + uint8_t buffer[7]; + buffer[0] = DEC2BCD(second) & 0x7F; + buffer[1] = DEC2BCD(minute); + buffer[2] = DEC2BCD(hour); + buffer[3] = DEC2BCD(day); + buffer[4] = getDayOfWeek(day, month, year); + buffer[5] = DEC2BCD(month); + buffer[6] = DEC2BCD(year % 100); + + writeRegister(PCF85063_SEC_REG, buffer, 7); + } + + + RTC_DateTime getDateTime() + { + RTC_DateTime datetime; + uint8_t buffer[7]; + readRegister(PCF85063_SEC_REG, buffer, 7); + datetime.available = ((buffer[0] & 0x80) == 0x80) ? false : true; + datetime.second = BCD2DEC(buffer[0] & 0x7F); + datetime.minute = BCD2DEC(buffer[1] & 0x7F); + if (is24Hour) { + datetime.hour = BCD2DEC(buffer[2] & 0x3F); // 24-hour mode + } else { + datetime.AMPM = (buffer[2] & 0x20) == 0x20 ? 'A' : 'P'; + datetime.hour = BCD2DEC(buffer[2] & 0x1F); // 12-hour mode + } + datetime.day = BCD2DEC(buffer[3] & 0x3F); + datetime.week = BCD2DEC(buffer[4] & 0x07); + datetime.month = BCD2DEC(buffer[5] & 0x1F); + datetime.year = BCD2DEC(buffer[6]) + 2000; + return datetime; + } + + void getDateTime(struct tm *timeinfo) + { + if (!timeinfo)return; + *timeinfo = conversionUnixTime(getDateTime()); + } + + /* + Defalut use 24H mode + bool is24HourMode() + { + return is24Hour; + } + + bool is12HourMode() + { + return !is24Hour; + } + + void set24Hour() + { + is24Hour = true; + clrRegisterBit(PCF85063_CTRL1_REG, 1); + } + + void set12Hour() + { + is24Hour = false; + setRegisterBit(PCF85063_CTRL1_REG, 1); + } + */ + + void stop() + { + setRegisterBit(PCF85063_CTRL1_REG, 5); + } + + void start() + { + clrRegisterBit(PCF85063_CTRL1_REG, 5); + } + + bool isRunning() + { + return !getRegisterBit(PCF85063_CTRL1_REG, 5); + } + + void enableAlarm() + { + setRegisterBit(PCF85063_CTRL2_REG, 7); + } + + void disableAlarm() + { + clrRegisterBit(PCF85063_CTRL2_REG, 7); + } + + void resetAlarm() + { + clrRegisterBit(PCF85063_CTRL2_REG, 6); + } + + bool isAlarmActive() + { + return getRegisterBit(PCF85063_CTRL2_REG, 6); + } + + RTC_Alarm getAlarm() + { + uint8_t buffer[5]; + readRegister(PCF85063_ALRM_MIN_REG, buffer, 5); + buffer[0] = BCD2DEC(buffer[0] & 0x80); //second + buffer[1] = BCD2DEC(buffer[1] & 0x40); //minute + buffer[2] = BCD2DEC(buffer[2] & 0x40); //hour + buffer[3] = BCD2DEC(buffer[3] & 0x08); //day + buffer[4] = BCD2DEC(buffer[4] & 0x08); //weekday + // RTC_Alarm(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t week) + return RTC_Alarm(buffer[2], buffer[1], buffer[0], buffer[3], buffer[4]); + } + + void setAlarm(RTC_Alarm alarm) + { + setAlarm(alarm.hour, + alarm.minute, + alarm.second, + alarm.day, + alarm.week); + } + + void setAlarm(uint8_t hour, + uint8_t minute, + uint8_t second, + uint8_t day, + uint8_t week) + { + uint8_t buffer[5] = {0}; + + RTC_DateTime datetime = getDateTime(); + + uint8_t daysInMonth = getDaysInMonth(datetime.month, datetime.year); + + if (second != PCF85063_NO_ALARM) { + if (second > 59) { + second = 59; + } + buffer[0] = DEC2BCD(second); + buffer[0] &= ~PCF85063_ALARM_ENABLE; + } else { + buffer[0] = PCF85063_ALARM_ENABLE; + } + + if (minute != PCF85063_NO_ALARM) { + if (minute > 59) { + minute = 59; + } + buffer[1] = DEC2BCD(minute); + buffer[1] &= ~PCF85063_ALARM_ENABLE; + } else { + buffer[1] = PCF85063_ALARM_ENABLE; + } + if (hour != PCF85063_NO_ALARM) { + if (is24Hour) { + if (hour > 23) { + hour = 23; + } + buffer[2] = DEC2BCD(hour); + buffer[2] &= ~PCF85063_ALARM_ENABLE; + } else { + /* + if (hour > 12) { + hour = 12; + } + buffer[2] = DEC2BCD(hour); + buffer[2] |= isAM ? 0 : _BV(5); + buffer[2] &= ~PCF85063_ALARM_ENABLE; + */ + } + } else { + buffer[2] = PCF85063_ALARM_ENABLE; + } + if (day != PCF85063_NO_ALARM) { + //TODO:Check day in Month + buffer[3] = DEC2BCD(((day) < (1) ? (1) : ((day) > (daysInMonth) ? (daysInMonth) : (day)))); + buffer[3] &= ~PCF85063_ALARM_ENABLE; + } else { + buffer[3] = PCF85063_ALARM_ENABLE; + } + if (week != PCF85063_NO_ALARM) { + if (week > 6) { + week = 6; + } + buffer[4] = DEC2BCD(week); + buffer[4] &= ~PCF85063_ALARM_ENABLE; + } else { + buffer[4] = PCF85063_ALARM_ENABLE; + } + writeRegister(PCF85063_ALRM_SEC_REG, buffer, 4); + } + + void setAlarmByHours(uint8_t hour) + { + setAlarm(hour, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM); + } + + void setAlarmBySecond(uint8_t second) + { + setAlarm(PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + second, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM); + } + + void setAlarmByMinutes(uint8_t minute) + { + setAlarm(PCF85063_NO_ALARM, + minute, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM); + } + + void setAlarmByDays(uint8_t day) + { + setAlarm(PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + day, + PCF85063_NO_ALARM); + } + + void setAlarmByWeekDay(uint8_t week) + { + setAlarm(PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + PCF85063_NO_ALARM, + week); + } + + void setClockOutput(ClockHz hz) + { + int val = readRegister(PCF85063_CTRL2_REG); + if (val == DEV_WIRE_ERR)return; + val &= 0xF8; + val |= hz; + writeRegister(PCF85063_CTRL2_REG, val); + } + +private: + + bool initImpl() + { + // 230704:Does not use power-off judgment, if the RTC backup battery is not installed, + // it will return failure. Here only to judge whether the device communication is normal + + //Check device is online + int ret = readRegister(PCF85063_SEC_REG); + if (ret == DEV_WIRE_ERR) { + return false; + } + if (BCD2DEC(ret & 0x7F) > 59) { + return false; + } + + //Default use 24-hour mode + is24Hour = !getRegisterBit(PCF85063_CTRL1_REG, 1); + if (!is24Hour) { + // Set 24H Mode + clrRegisterBit(PCF85063_CTRL1_REG, 1); + } + + //Turn on RTC + start(); + + return isRunning(); + } + + int getReadMaskImpl() + { + return -1; + } + +protected: + + bool is24Hour = true; +}; + + + diff --git a/components/SensorLib/src/SensorPCF8563.hpp b/components/SensorLib/src/SensorPCF8563.hpp new file mode 100644 index 0000000..f48835e --- /dev/null +++ b/components/SensorLib/src/SensorPCF8563.hpp @@ -0,0 +1,359 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorPCF8563.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2022-12-09 + * + */ +#pragma once + +#include "REG/PCF8563Constants.h" +#include "SensorCommon.tpp" +#include "SensorRTC.h" + +class SensorPCF8563 : + public SensorCommon, + public RTCCommon +{ + friend class SensorCommon; + friend class RTCCommon; +public: + + enum { + CLK_32_768KHZ, + CLK_1024KHZ, + CLK_32HZ, + CLK_1HZ, + }; + + +#if defined(ARDUINO) + SensorPCF8563(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF8563_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorPCF8563() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = PCF8563_SLAVE_ADDRESS; + } + + ~SensorPCF8563() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF8563_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + void setDateTime(RTC_DateTime datetime) + { + setDateTime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second); + } + + + void setDateTime(uint16_t year, + uint8_t month, + uint8_t day, + uint8_t hour, + uint8_t minute, + uint8_t second) + { + uint8_t buffer[7]; + buffer[0] = DEC2BCD(second) & 0x7F; + buffer[1] = DEC2BCD(minute); + buffer[2] = DEC2BCD(hour); + buffer[3] = DEC2BCD(day); + buffer[4] = getDayOfWeek(day, month, year); + buffer[5] = DEC2BCD(month); + buffer[6] = DEC2BCD(year % 100); + + if ((2000 % year) == 2000) { + buffer[5] &= 0x7F; + } else { + buffer[5] |= 0x80; + } + writeRegister(PCF8563_SEC_REG, buffer, 7); + } + + + RTC_DateTime getDateTime() + { + RTC_DateTime datetime; + uint8_t buffer[7]; + readRegister(PCF8563_SEC_REG, buffer, 7); + datetime.available = ((buffer[0] & 0x80) == 0x80) ? false : true; + datetime.second = BCD2DEC(buffer[0] & 0x7F); + datetime.minute = BCD2DEC(buffer[1] & 0x7F); + datetime.hour = BCD2DEC(buffer[2] & 0x3F); + datetime.day = BCD2DEC(buffer[3] & 0x3F); + datetime.week = BCD2DEC(buffer[4] & 0x07); + datetime.month = BCD2DEC(buffer[5] & 0x1F); + datetime.year = BCD2DEC(buffer[6]); + //cetury : 0 = 1900 , 1 = 2000 + datetime.year += (buffer[5] & PCF8563_CENTURY_MASK) ? 1900 : 2000; + return datetime; + } + + void getDateTime(struct tm *timeinfo) + { + if (!timeinfo)return; + *timeinfo = conversionUnixTime(getDateTime()); + } + + RTC_Alarm getAlarm() + { + uint8_t buffer[4]; + readRegister(PCF8563_ALRM_MIN_REG, buffer, 4); + buffer[0] = BCD2DEC(buffer[0] & 0x80); //minute + buffer[1] = BCD2DEC(buffer[1] & 0x40); //hour + buffer[2] = BCD2DEC(buffer[2] & 0x40); //day + buffer[3] = BCD2DEC(buffer[3] & 0x08); //weekday + // RTC_Alarm(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t week) + return RTC_Alarm(buffer[1], buffer[0], 0, buffer[2], buffer[3]); + } + + void enableAlarm() + { + setRegisterBit(PCF8563_STAT2_REG, 1); + } + + void disableAlarm() + { + clrRegisterBit(PCF8563_STAT2_REG, 1); + } + + void resetAlarm() + { + clrRegisterBit(PCF8563_STAT2_REG, 3); + } + + bool isAlarmActive() + { + return getRegisterBit(PCF8563_STAT2_REG, 3); + } + + void setAlarm(RTC_Alarm alarm) + { + setAlarm( alarm.hour, alarm.minute, alarm.day, alarm.week); + } + + void setAlarm(uint8_t hour, uint8_t minute, uint8_t day, uint8_t week) + { + uint8_t buffer[4] = {0}; + + RTC_DateTime datetime = getDateTime(); + + uint8_t daysInMonth = getDaysInMonth(datetime.month, datetime.year); + + if (minute != PCF8563_NO_ALARM) { + if (minute > 59) { + minute = 59; + } + buffer[0] = DEC2BCD(minute); + buffer[0] &= ~PCF8563_ALARM_ENABLE; + } else { + buffer[0] = PCF8563_ALARM_ENABLE; + } + + if (hour != PCF8563_NO_ALARM) { + if (hour > 23) { + hour = 23; + } + buffer[1] = DEC2BCD(hour); + buffer[1] &= ~PCF8563_ALARM_ENABLE; + } else { + buffer[1] = PCF8563_ALARM_ENABLE; + } + if (day != PCF8563_NO_ALARM) { + //TODO:Check day in Month + buffer[2] = DEC2BCD(((day) < (1) ? (1) : ((day) > (daysInMonth) ? (daysInMonth) : (day)))); + buffer[2] &= ~PCF8563_ALARM_ENABLE; + } else { + buffer[2] = PCF8563_ALARM_ENABLE; + } + if (week != PCF8563_NO_ALARM) { + if (week > 6) { + week = 6; + } + buffer[3] = DEC2BCD(week); + buffer[3] &= ~PCF8563_ALARM_ENABLE; + } else { + buffer[3] = PCF8563_ALARM_ENABLE; + } + writeRegister(PCF8563_ALRM_MIN_REG, buffer, 4); + } + + void setAlarmByMinutes(uint8_t minute) + { + setAlarm(PCF8563_NO_ALARM, minute, PCF8563_NO_ALARM, PCF8563_NO_ALARM); + } + void setAlarmByDays(uint8_t day) + { + setAlarm(PCF8563_NO_ALARM, PCF8563_NO_ALARM, day, PCF8563_NO_ALARM); + } + void setAlarmByHours(uint8_t hour) + { + setAlarm(hour, PCF8563_NO_ALARM, PCF8563_NO_ALARM, PCF8563_NO_ALARM); + } + void setAlarmByWeekDay(uint8_t week) + { + setAlarm(PCF8563_NO_ALARM, PCF8563_NO_ALARM, PCF8563_NO_ALARM, week); + } + + bool isCountdownTimerEnable() + { + uint8_t buffer[2]; + buffer[0] = readRegister(PCF8563_STAT2_REG); + buffer[1] = readRegister(PCF8563_TIMER1_REG); + if (buffer[0] & PCF8563_TIMER_TIE) { + return buffer[1] & PCF8563_TIMER_TE ? true : false; + } + return false; + } + + bool isCountdownTimerActive() + { + return getRegisterBit(PCF8563_STAT2_REG, 2); + } + + void enableCountdownTimer() + { + setRegisterBit(PCF8563_STAT2_REG, 0); + } + + void disableCountdownTimer() + { + clrRegisterBit(PCF8563_STAT2_REG, 0); + } + + void setCountdownTimer(uint8_t val, uint8_t freq) + { + uint8_t buffer[3]; + buffer[1] = readRegister(PCF8563_TIMER1_REG); + buffer[1] |= (freq & PCF8563_TIMER_TD10); + buffer[2] = val; + writeRegister(PCF8563_TIMER1_REG, buffer[1]); + writeRegister(PCF8563_TIMER2_REG, buffer[2]); + } + + void clearCountdownTimer() + { + uint8_t val; + val = readRegister(PCF8563_STAT2_REG); + val &= ~(PCF8563_TIMER_TF | PCF8563_TIMER_TIE); + val |= PCF8563_ALARM_AF; + writeRegister(PCF8563_STAT2_REG, val); + writeRegister(PCF8563_TIMER1_REG, 0x00); + } + + void enableCLK(uint8_t freq) + { + if (freq > CLK_1HZ) return; + writeRegister(PCF8563_SQW_REG, freq | PCF8563_CLK_ENABLE); + } + + void disableCLK() + { + clrRegisterBit(PCF8563_SQW_REG, 7); + } + + + +private: + + bool initImpl() + { + // Check whether RTC time is valid? If it is invalid, it can be judged + // that there is a problem with the hardware, or the RTC power supply voltage is too low + /* + int count = 0; + for (int i = 0; i < 3; ++i) { + if (!getRegisterBit(PCF8563_SEC_REG, 7)) { + count++; + } + } + if (count != 3 ) { + return false; + } + */ + + // 230704:Does not use power-off judgment, if the RTC backup battery is not installed, + // it will return failure. Here only to judge whether the device communication is normal + + //Check device is online + int ret = readRegister(PCF8563_SEC_REG); + if (ret == DEV_WIRE_ERR) { + return false; + } + if (BCD2DEC(ret & 0x7F) > 59) { + return false; + } + + // Determine whether the hardware clock year, month, and day match the internal time of the RTC. + // If they do not match, it will be updated to the compilation date + // RTC_DateTime compileDatetime = RTC_DateTime(__DATE__, __TIME__); + // RTC_DateTime hwDatetime = getDateTime(); + // if (compileDatetime.year != hwDatetime.year || + // compileDatetime.month != hwDatetime.month || + // compileDatetime.day != hwDatetime.month + // ) { + // LOG("No match yy:mm:dd . set datetime to compilation date time"); + // setDateTime(compileDatetime); + // } + return true; + } + + int getReadMaskImpl() + { + return -1; + } + +protected: + + +}; + + + diff --git a/components/SensorLib/src/SensorQMC6310.hpp b/components/SensorLib/src/SensorQMC6310.hpp new file mode 100644 index 0000000..1c75e9a --- /dev/null +++ b/components/SensorLib/src/SensorQMC6310.hpp @@ -0,0 +1,402 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorQMC6310.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2022-10-16 + * + */ +#pragma once + +#include "REG/QMC6310Constants.h" +#include "SensorCommon.tpp" + +class Polar +{ +public: + Polar(): polar(0), Gauss(0), uT(0) {} + Polar(float polar, float Gauss, float uT): polar(polar), Gauss(Gauss), uT(uT) {} + float polar; + float Gauss; + float uT; +}; + + +class SensorQMC6310 : + public SensorCommon +{ + friend class SensorCommon; +public: + + + enum SensorMode { + MODE_SUSPEND, + MODE_NORMAL, + MODE_SINGLE, + MODE_CONTINUOUS, + }; + + // Unit:Guass + enum MagRange { + RANGE_30G, + RANGE_12G, + RANGE_8G, + RANGE_2G, + }; + + enum OutputRate { + DATARATE_10HZ, + DATARATE_50HZ, + DATARATE_100HZ, + DATARATE_200HZ, + }; + + enum CtrlReg { + SET_RESET_ON, + SET_ONLY_ON, + SET_RESET_OFF, + }; + + enum OverSampleRatio { + OSR_8, + OSR_4, + OSR_2, + OSR_1, + }; + + enum DownSampleRatio { + DSR_1, + DSR_2, + DSR_4, + DSR_8, + }; + +#if defined(ARDUINO) + SensorQMC6310(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = QMC6310_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + SensorQMC6310() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = QMC6310_SLAVE_ADDRESS; + } + + ~SensorQMC6310() + { + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = QMC6310_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + + void deinit() + { + // end(); + } + + void reset() + { + writeRegister(QMC6310_REG_CMD2, 0x80); + delay(10); + writeRegister(QMC6310_REG_CMD2, 0x00); + } + + uint8_t getChipID() + { + return readRegister(QMC6310_REG_CHIP_ID); + } + + + int getStatus() + { + return readRegister(QMC6310_REG_STAT); + } + + bool isDataReady() + { + if (readRegister(QMC6310_REG_STAT) & 0x01) { + return true; + } + LOG("No ready!\n"); + return false; + } + + bool isDataOverflow() + { + if (readRegister(QMC6310_REG_STAT) & 0x02) { + return true; + } + return false; + } + + int setSelfTest(bool en) + { + return en ? setRegisterBit(QMC6310_REG_CMD2, 1) + : clrRegisterBit(QMC6310_REG_CMD2, 1); + } + + int setMode(SensorMode m) + { + return writeRegister(QMC6310_REG_CMD1, 0xFC, m); + } + + int setCtrlRegister(CtrlReg c) + { + return writeRegister(QMC6310_REG_CMD2, 0xFC, c); + } + + int setDataOutputRate(OutputRate odr) + { + return writeRegister(QMC6310_REG_CMD1, 0xF3, (odr << 2)); + } + + int setOverSampleRate(OverSampleRatio osr) + { + return writeRegister(QMC6310_REG_CMD1, 0xCF, (osr << 4)); + } + + int setDownSampleRate(DownSampleRatio dsr) + { + return writeRegister(QMC6310_REG_CMD1, 0x3F, (dsr << 6)); + } + + // Define the sign for X Y and Z axis + int setSign(uint8_t x, uint8_t y, uint8_t z) + { + int sign = x + y * 2 + z * 4; + return writeRegister(QMC6310_REG_SIGN, sign); + } + + int configMagnetometer(SensorMode mode, MagRange range, OutputRate odr, + OverSampleRatio osr, DownSampleRatio dsr) + { + if (setMagRange(range) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + if (writeRegister(QMC6310_REG_CMD1, 0xFC, mode) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + if (writeRegister(QMC6310_REG_CMD1, 0xF3, (odr << 2)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + if (writeRegister(QMC6310_REG_CMD1, 0xCF, (osr << 4)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + if (writeRegister(QMC6310_REG_CMD1, 0x3F, (dsr << 6)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + return DEV_WIRE_NONE; + } + + int setMagRange(MagRange range) + { + switch (range) { + case RANGE_30G: + sensitivity = 0.1; + break; + case RANGE_12G: + sensitivity = 0.04; + break; + case RANGE_8G: + sensitivity = 0.026; + break; + case RANGE_2G: + sensitivity = 0.0066; + break; + default: + break; + } + return writeRegister(QMC6310_REG_CMD2, 0xF3, (range << 2)); + } + + void setOffset(int x, int y, int z) + { + x_offset = x; y_offset = y; z_offset = z; + } + + int readData() + { + uint8_t buffer[6]; + int16_t x, y, z; + if (readRegister(QMC6310_REG_LSB_DX, buffer, + 6) != DEV_WIRE_ERR) { + x = (int16_t)(buffer[1] << 8) | (buffer[0]); + y = (int16_t)(buffer[3] << 8) | (buffer[2]); + z = (int16_t)(buffer[5] << 8) | (buffer[4]); + + if (x == 32767) { + x = -((65535 - x) + 1); + } + x = (x - x_offset); + if (y == 32767) { + y = -((65535 - y) + 1); + } + y = (y - y_offset); + if (z == 32767) { + z = -((65535 - z) + 1); + } + z = (z - z_offset); + + raw[0] = x; + raw[1] = y; + raw[2] = z; + + mag[0] = (float)x * sensitivity; + mag[1] = (float)y * sensitivity; + mag[2] = (float)z * sensitivity; + return DEV_WIRE_NONE; + } + return DEV_WIRE_ERR; + } + + void setDeclination(float dec) + { + _declination = dec; + } + + bool readPolar(Polar &p) + { + if (isDataReady()) { + readData(); + float x = getX(); + float y = getY(); + float z = getZ(); + float angle = (atan2(x, -y) / PI) * 180.0 + _declination; + angle = _convertAngleToPositive(angle); + float magnitude = sqrt(x * x + y * y + z * z); + p = Polar(angle, magnitude * 100, magnitude); + return true; + } + return false; + } + + int16_t getRawX() + { + return raw[0]; + } + + int16_t getRawY() + { + return raw[1]; + } + + int16_t getRawZ() + { + return raw[2]; + } + + float getX() + { + return mag[0]; + } + + float getY() + { + return mag[1]; + } + + float getZ() + { + return mag[2]; + } + + void getMag(float &x, float &y, float &z) + { + x = mag[0]; + y = mag[1]; + z = mag[2]; + } + + void dumpCtrlRegister() + { + uint8_t buffer[2]; + readRegister(QMC6310_REG_CMD1, buffer, 2); + for (int i = 0; i < 2; ++i) { +#if defined(ARDUINO) + Serial.printf("CMD%d: 0x%02x", i + 1, buffer[i]); +#else + printf("CTRL%d: 0x%02x", i + 1, buffer[i]); +#endif +#if defined(ARDUINO) + Serial.print("\t\t BIN:"); + Serial.println(buffer[i], BIN); +#else + LOG("\n"); +#endif + } +#if defined(ARDUINO) + Serial.println(); +#else + printf("\n"); +#endif + } + +private: + + float _convertAngleToPositive(float angle) + { + if (angle >= 360.0) { + angle = angle - 360.0; + } + if (angle < 0) { + angle = angle + 360.0; + } + return angle; + } + + + bool initImpl() + { + reset(); + return getChipID() == QMC6310_DEFAULT_ID; + } + + int getReadMaskImpl() + { + return -1; + } + +protected: + int16_t raw[3]; + float mag[3]; + float _declination; + float sensitivity; + int16_t x_offset = 0, y_offset = 0, z_offset = 0; +}; + diff --git a/components/SensorLib/src/SensorQMI8658.hpp b/components/SensorLib/src/SensorQMI8658.hpp new file mode 100644 index 0000000..d4e15f3 --- /dev/null +++ b/components/SensorLib/src/SensorQMI8658.hpp @@ -0,0 +1,1510 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorQMI8658.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2022-10-16 + * + */ +#pragma once + +#include "REG/QMI8658Constants.h" +#include "SensorCommon.tpp" +#ifndef ARDUINO +#include +#include +#endif +typedef struct __IMUdata { + float x; + float y; + float z; +} IMUdata; + +class SensorQMI8658 : + public SensorCommon +{ + friend class SensorCommon; +public: + + typedef void (*EventCallBack_t)(void); + + enum AccelRange { + ACC_RANGE_2G, + ACC_RANGE_4G, + ACC_RANGE_8G, + ACC_RANGE_16G + }; + + enum GyroRange { + GYR_RANGE_16DPS, + GYR_RANGE_32DPS, + GYR_RANGE_64DPS, + GYR_RANGE_128DPS, + GYR_RANGE_256DPS, + GYR_RANGE_512DPS, + GYR_RANGE_1024DPS, + }; + + // In 6DOF mode (accelerometer and gyroscope are both enabled), + // the output data rate is derived from the nature frequency of gyroscope + enum AccelODR { + ACC_ODR_1000Hz = 3, + ACC_ODR_500Hz, + ACC_ODR_250Hz, + ACC_ODR_125Hz, + ACC_ODR_62_5Hz, + ACC_ODR_31_25Hz, + ACC_ODR_LOWPOWER_128Hz = 12, + ACC_ODR_LOWPOWER_21Hz, + ACC_ODR_LOWPOWER_11Hz, + ACC_ODR_LOWPOWER_3Hz + }; + + enum GyroODR { + GYR_ODR_7174_4Hz, + GYR_ODR_3587_2Hz, + GYR_ODR_1793_6Hz, + GYR_ODR_896_8Hz, + GYR_ODR_448_4Hz, + GYR_ODR_224_2Hz, + GYR_ODR_112_1Hz, + GYR_ODR_56_05Hz, + GYR_ODR_28_025Hz + }; + + //Low-Pass Filter. + enum LpfMode { + LPF_MODE_0, //2.66% of ODR + LPF_MODE_1, //3.63% of ODR + LPF_MODE_2, //5.39% of ODR + LPF_MODE_3, //13.37% of ODR + }; + + enum MotionEvent { + MOTION_TAP, + MOTION_ANT_MOTION, + MOTION_NO_MOTION, + MOTION_SIGNIFICANT, + MOTION_PEDOMETER, + }; + + enum IntPin { + IntPin1, + IntPin2, + }; + + enum Fifo_Samples { + FIFO_SAMPLES_16, + FIFO_SAMPLES_32, + FIFO_SAMPLES_64, + FIFO_SAMPLES_128, + FIFO_SAMPLES_MAX, + } ; + + enum FIFO_Mode { + FIFO_MODE_BYPASS, + FIFO_MODE_FIFO, + FIFO_MODE_STREAM, + FIFO_MODE_MAX, + }; + + enum SampleMode { + SYNC_MODE, //Synchronous sampling + ASYNC_MODE, //Asynchronous sampling + }; + + enum CommandTable { + CTRL_CMD_ACK = 0x00, + CTRL_CMD_RST_FIFO = 0x04, + CTRL_CMD_REQ_FIFO = 0x05, + CTRL_CMD_WRITE_WOM_SETTING = 0x08, + CTRL_CMD_ACCEL_HOST_DELTA_OFFSET = 0x09, + CTRL_CMD_GYRO_HOST_DELTA_OFFSET = 0x0A, + CTRL_CMD_CONFIGURE_TAP = 0x0C, + CTRL_CMD_CONFIGURE_PEDOMETER = 0x0D, + CTRL_CMD_CONFIGURE_MOTION = 0x0E, + CTRL_CMD_RESET_PEDOMETER = 0x0F, + CTRL_CMD_COPY_USID = 0x10, + CTRL_CMD_SET_RPU = 0x11, + CTRL_CMD_AHB_CLOCK_GATING = 0x12, + CTRL_CMD_ON_DEMAND_CALIBRATION = 0xA2, + CTRL_CMD_APPLY_GYRO_GAINS = 0xAA, + }; + + enum StatusReg { + EVENT_SIGNIFICANT_MOTION = 128, + EVENT_NO_MOTION = 64, + EVENT_ANY_MOTION = 32, + EVENT_PEDOMETER_MOTION = 16, + EVENT_WOM_MOTION = 4, + EVENT_TAP_MOTION = 2, + }; + +#if defined(ARDUINO) + SensorQMI8658(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = QMI8658_L_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } + + SensorQMI8658(int cs, int mosi = -1, int miso = -1, int sck = -1, PLATFORM_SPI_TYPE &spi = SPI) + { + __spi = &spi; + __cs = cs; + __miso = miso; + __mosi = mosi; + __sck = sck; + } + +#endif + + SensorQMI8658() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = QMI8658_L_SLAVE_ADDRESS; + } + + ~SensorQMI8658() + { + log_i("~SensorQMI8658"); + deinit(); + } + +#if defined(ARDUINO) + bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = QMI8658_L_SLAVE_ADDRESS) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + + void deinit() + { + // end(); + } + + bool reset(bool waitResult = true, uint32_t timeout = 500) + { + int val = 0; // initialize with some value to avoid compilation errors + writeRegister(QMI8658_REG_RESET, QMI8658_REG_RESET_DEFAULT); + // Maximum 15ms for the Reset process to be finished + if (waitResult) { + uint32_t start = millis(); + while (millis() - start < timeout) { + val = readRegister(QMI8658_REG_RST_RESULT); + if (val != DEV_WIRE_ERR && val == QMI8658_REG_RST_RESULT_VAL) { + + //EN.ADDR_AI + setRegisterBit(QMI8658_REG_CTRL1, 6); + + return true; + } + delay(10); + } + LOG("Reset chip failed, respone val = %d - 0x%X\n", val, val); + return false; + } + + //EN.ADDR_AI + setRegisterBit(QMI8658_REG_CTRL1, 6); + + return true; + } + + uint8_t getChipID() + { + return readRegister(QMI8658_REG_REVISION); + } + + int whoAmI() + { + return readRegister(QMI8658_REG_WHOAMI); + } + + uint32_t getTimestamp() + { + uint8_t buffer[3]; + uint32_t timestamp; + if (readRegister(QMI8658_REG_TIMESTAMP_L, buffer, 3) != DEV_WIRE_ERR) { + timestamp = (uint32_t)(((uint32_t)buffer[2] << 16) | + ((uint32_t)buffer[1] << 8) | buffer[0]); + if (timestamp > lastTimestamp) { + lastTimestamp = timestamp; + } else { + lastTimestamp = (timestamp + 0x1000000 - lastTimestamp); + } + } + return lastTimestamp; + } + + + float getTemperature_C() + { + uint8_t buffer[2]; + if (readRegister(QMI8658_REG_TEMPEARTURE_L, buffer, 2) != DEV_WIRE_ERR) { + return (float)buffer[1] + ((float)buffer[0] / 256.0); + } + return NAN; + } + + void enableINT(IntPin pin, bool enable = true) + { + switch (pin) { + case IntPin1: + enable ? setRegisterBit(QMI8658_REG_CTRL1, 3) : clrRegisterBit(QMI8658_REG_CTRL1, 3); + break; + case IntPin2: + enable ? setRegisterBit(QMI8658_REG_CTRL1, 4) : clrRegisterBit(QMI8658_REG_CTRL1, 4); + break; + default: + break; + } + } + + uint8_t getIrqStatus() + { + return readRegister(QMI8658_REG_STATUSINT); + } + + + void enableDataReadyINT(bool enable = true) + { + enable ? clrRegisterBit(QMI8658_REG_CTRL7, 5) : + setRegisterBit(QMI8658_REG_CTRL7, 5); + } + + /** + * @brief + * @note + * @param range: + * @param odr: + * @param lpfOdr: + * @param lpf: + * @param selfTest: + * @retval + */ + int configAccelerometer(AccelRange range, AccelODR odr, LpfMode lpfOdr = LPF_MODE_0, + bool lpf = true, bool selfTest = true) + { + bool en = isEnableAccelerometer(); + + if (en) { + disableAccelerometer(); + } + + //setAccelRange + if (writeRegister(QMI8658_REG_CTRL2, 0x8F, (range << 4)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + switch (range) { + // Possible accelerometer scales (and their register bit settings) are: + // 2 Gs (00), 4 Gs (01), 8 Gs (10), and 16 Gs (11). + // Here's a bit of an algorith to calculate DPS/(ADC tick) based on that + // 2-bit value: + case ACC_RANGE_2G: accelScales = 2.0 / 32768.0; break; + case ACC_RANGE_4G: accelScales = 4.0 / 32768.0; break; + case ACC_RANGE_8G: accelScales = 8.0 / 32768.0; break; + case ACC_RANGE_16G: accelScales = 16.0 / 32768.0; break; + } + + // setAccelOutputDataRate + if (writeRegister(QMI8658_REG_CTRL2, 0xF0, odr) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + // setAccelLowPassFitter + lpf ? setRegisterBit(QMI8658_REG_CTRL5, 0) : clrRegisterBit(QMI8658_REG_CTRL5, 0); + + // setAccelLowPassFitterOdr + if (writeRegister(QMI8658_REG_CTRL5, QMI8658_ACCEL_LPF_MASK, (lpfOdr << 1)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + // setAccelSelfTest + selfTest ? setRegisterBit(QMI8658_REG_CTRL2, 7) : clrRegisterBit(QMI8658_REG_CTRL2, 7); + + if (en) { + enableAccelerometer(); + } + + return DEV_WIRE_NONE; + } + + /** + * @brief + * @note + * @param range: + * @param odr: + * @param lpfOdr: + * @param lpf: + * @param selfTest: + * @retval + */ + int configGyroscope(GyroRange range, GyroODR odr, LpfMode lpfOdr = LPF_MODE_0, + bool lpf = true, bool selfTest = true) + { + bool en = isEnableGyroscope(); + + if (en) { + disableGyroscope(); + } + + // setGyroRange + if (writeRegister(QMI8658_REG_CTRL3, 0x8F, (range << 4)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + switch (range) { + // Possible gyro scales (and their register bit settings) are: + // 250 DPS (00), 500 DPS (01), 1000 DPS (10), and 2000 DPS (11). + // Here's a bit of an algorith to calculate DPS/(ADC tick) based on that + // 2-bit value: + case GYR_RANGE_16DPS: gyroScales = 16.0 / 32768.0; break; + case GYR_RANGE_32DPS: gyroScales = 32.0 / 32768.0; break; + case GYR_RANGE_64DPS: gyroScales = 64.0 / 32768.0; break; + case GYR_RANGE_128DPS: gyroScales = 128.0 / 32768.0; break; + case GYR_RANGE_256DPS: gyroScales = 256.0 / 32768.0; break; + case GYR_RANGE_512DPS: gyroScales = 512.0 / 32768.0; break; + case GYR_RANGE_1024DPS: gyroScales = 1024.0 / 32768.0; break; + } + + // setGyroOutputDataRate + if (writeRegister(QMI8658_REG_CTRL3, 0xF0, odr) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + // setGyroLowPassFitter + lpf ? setRegisterBit(QMI8658_REG_CTRL5, 4) : clrRegisterBit(QMI8658_REG_CTRL5, 4); + + + // setGyroLowPassFitterOdr + if (writeRegister(QMI8658_REG_CTRL5, QMI8658_GYRO_LPF_MASK, (lpfOdr << 5)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + // setGyroSelfTest + selfTest ? setRegisterBit(QMI8658_REG_CTRL3, 7) : clrRegisterBit(QMI8658_REG_CTRL3, 7); + + + if (en) { + enableGyroscope(); + } + + return DEV_WIRE_NONE; + } + + /** + * @brief + * @note + * @param mode: + * @param samples: + * @param pin: + * @param watermark: + * @retval + */ + int configFIFO(FIFO_Mode mode, + Fifo_Samples samples = FIFO_SAMPLES_16, IntPin pin = IntPin2, + uint8_t watermark = 8) + { + bool enGyro = isEnableGyroscope(); + bool enAccel = isEnableAccelerometer(); + + if (enGyro) { + disableGyroscope(); + } + + if (enAccel) { + disableAccelerometer(); + } + + ///////////////// + pin == IntPin2 ? clrRegisterBit(QMI8658_REG_CTRL1, 2) : setRegisterBit(QMI8658_REG_CTRL1, 2); + + // set fifo mode and samples len + fifoMode = (samples << 2) | mode; + if (writeRegister(QMI8658_REG_FIFOCTRL, fifoMode) == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + + // set watermark + if (writeRegister(QMI8658_REG_FIFOWMKTH, watermark) == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + + //reset fifo + writeCommand(CTRL_CMD_RST_FIFO); + ///////////////// + + if (enGyro) { + enableGyroscope(); + } + + if (enAccel) { + enableAccelerometer(); + } + + return DEV_WIRE_NONE; + } + + uint16_t getFifoNeedBytes() + { + uint8_t sam[] = {16, 32, 64, 128}; + uint8_t sensors = 0; + if (gyroEn && accelEn) { + sensors = 2; + } else if (gyroEn || accelEn) { + sensors = 1; + } + uint8_t samples = ((fifoMode >> 2) & 0x03) ; + return sam[samples] * 6 * sensors; + } + + bool readFromFifo(IMUdata *acc, uint16_t accLenght, IMUdata *gyr, uint16_t gyrLenght) + { + uint16_t bytes = getFifoNeedBytes(); + uint8_t *buffer = new uint8_t [bytes]; + if (!buffer) { + LOG("No memory!"); + return false; + } + if (!readFromFifo(buffer, bytes)) { + delete buffer; + return false; + } + + int counter = 0; + for (int i = 0; i < bytes; ) { + if (accelEn) { + if (counter < accLenght) { + acc[counter].x = (float)((int16_t)buffer[i] | (buffer[i + 1] << 8)) * accelScales; + acc[counter].y = (float)((int16_t)buffer[i + 2] | (buffer[i + 3] << 8)) * accelScales; + acc[counter].z = (float)((int16_t)buffer[i + 4] | (buffer[i + 5] << 8)) * accelScales; + } + i += 6; + } + + if (gyroEn) { + if (counter < gyrLenght) { + gyr[counter].x = (float)((int16_t)buffer[i] | (buffer[i + 1] << 8)) * gyroScales; + gyr[counter].y = (float)((int16_t)buffer[i + 2] | (buffer[i + 3] << 8)) * gyroScales; + gyr[counter].z = (float)((int16_t)buffer[i + 4] | (buffer[i + 5] << 8)) * gyroScales; + } + i += 6; + } + counter++; + } + delete buffer; + return true; + } + + bool readFromFifo(uint8_t *data, size_t lenght) + { + uint8_t status[2]; + uint8_t fifo_sensors = 1; + uint16_t fifo_bytes = 0; + uint16_t fifo_level = 0; + + // get fifo status + int val = readRegister(QMI8658_REG_FIFOSTATUS); + if (val == DEV_WIRE_ERR) { + return false; + } + LOG("fifo status:0x%x ", val); + + if (val & (1 << 5)) { + LOG("\t\tFIFO Overflow condition has happened (data dropping happened)\n"); + } + if (val & (1 << 6)) { + LOG("\t\tFIFO Water Mark Level Hit\n"); + } + if (val & (1 << 7)) { + LOG("\t\tFIFO is Full\n"); + } + + val = readRegister(QMI8658_REG_FIFOCOUNT, status, 2); + if (val == DEV_WIRE_ERR) { + return false; + } + + fifo_bytes = ((status[1] & 0x03)) << 8 | status[0]; + + if (accelEn && gyroEn) { + fifo_sensors = 2; + } else if (accelEn || gyroEn) { + fifo_sensors = 1; + } + + fifo_level = fifo_bytes / (3 * fifo_sensors); + fifo_bytes = fifo_level * (6 * fifo_sensors); + + LOG("fifo-level : %d fifo_bytes : %d fifo_sensors : %d\n", fifo_level, fifo_bytes, fifo_sensors); + if (lenght < fifo_bytes) { + writeCommand(CTRL_CMD_RST_FIFO); + return false; + } + + if (fifo_level) { + writeCommand(CTRL_CMD_REQ_FIFO); + + if (readRegister(QMI8658_REG_FIFODATA, data, fifo_bytes) == + DEV_WIRE_ERR) { + LOG("get fifo error !"); + return false; + } + + val = writeRegister(QMI8658_REG_FIFOCTRL, fifoMode); + if (val == DEV_WIRE_ERR) { + return false; + } + } + + writeCommand(CTRL_CMD_RST_FIFO); + + return fifo_level; + } + + bool enableAccelerometer() + { + accelEn = true; + return setRegisterBit(QMI8658_REG_CTRL7, 0) == DEV_WIRE_NONE; + } + + bool disableAccelerometer() + { + accelEn = false; + return clrRegisterBit(QMI8658_REG_CTRL7, 0) == DEV_WIRE_NONE; + } + + bool isEnableAccelerometer() + { + accelEn = getRegisterBit(QMI8658_REG_CTRL7, 0); + return accelEn; + } + + bool isEnableGyroscope() + { + gyroEn = getRegisterBit(QMI8658_REG_CTRL7, 1); + return gyroEn; + } + + bool enableGyroscope() + { + gyroEn = true; + return setRegisterBit(QMI8658_REG_CTRL7, 1) == DEV_WIRE_NONE; + } + + bool disableGyroscope() + { + gyroEn = false; + return clrRegisterBit(QMI8658_REG_CTRL7, 1) == DEV_WIRE_NONE; + } + + bool getAccelRaw(int16_t *rawBuffer) + { + uint8_t buffer[6] = {0}; + if (readRegister(QMI8658_REG_AX_L, buffer, 6) != DEV_WIRE_ERR) { + rawBuffer[0] = (int16_t)(buffer[1] << 8) | (buffer[0]); + rawBuffer[1] = (int16_t)(buffer[3] << 8) | (buffer[2]); + rawBuffer[2] = (int16_t)(buffer[5] << 8) | (buffer[4]); + } else { + return false; + } + return true; + } + + bool getAccelerometer(float &x, float &y, float &z) + { + int16_t raw[3]; + if (getAccelRaw(raw)) { + x = raw[0] * accelScales; + y = raw[1] * accelScales; + z = raw[2] * accelScales; + return true; + } + return false; + } + + float getAccelerometerScales() + { + return accelScales; + } + + float getGyroscopeScales() + { + return gyroScales; + } + + bool getGyroRaw(int16_t *rawBuffer) + { + uint8_t buffer[6] = {0}; + if (readRegister(QMI8658_REG_GX_L, buffer, 6) != DEV_WIRE_ERR) { + rawBuffer[0] = (int16_t)(buffer[1] << 8) | (buffer[0]); + rawBuffer[1] = (int16_t)(buffer[3] << 8) | (buffer[2]); + rawBuffer[2] = (int16_t)(buffer[5] << 8) | (buffer[4]); + } else { + return false; + } + return true; + } + + int getGyroscope(float &x, float &y, float &z) + { + int16_t raw[3]; + if (getGyroRaw(raw)) { + x = raw[0] * gyroScales; + y = raw[1] * gyroScales; + z = raw[2] * gyroScales; + return true; + } + return false; + } + + bool getDataReady() + { + switch (sampleMode) { + case SYNC_MODE: + return getRegisterBit(QMI8658_REG_STATUSINT, 1); + case ASYNC_MODE: + //TODO: When Accel and Gyro are configured with different rates, this will always be false + if (gyroEn && accelEn) { + return readRegister(QMI8658_REG_STATUS0) & 0x03; + } else if (gyroEn) { + return readRegister(QMI8658_REG_STATUS0) & 0x02; + } else if (accelEn) { + return readRegister(QMI8658_REG_STATUS0) & 0x01; + } + break; + default: + break; + } + return false; + } + + int enableSyncSampleMode() + { + sampleMode = SYNC_MODE; + return setRegisterBit(QMI8658_REG_CTRL7, 7); + } + + int disableSyncSampleMode() + { + sampleMode = ASYNC_MODE; + return clrRegisterBit(QMI8658_REG_CTRL7, 7); + } + + int enableLockingMechanism() + { + enableSyncSampleMode(); + if (writeRegister(QMI8658_REG_CAL1_L, 0x01) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + return writeCommand(CTRL_CMD_AHB_CLOCK_GATING); + + } + + int disableLockingMechanism() + { + disableSyncSampleMode(); + if (writeRegister(QMI8658_REG_CAL1_L, 0x00) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + return writeCommand(CTRL_CMD_AHB_CLOCK_GATING); + } + + + void dumpCtrlRegister() + { + uint8_t buffer[9]; + readRegister(QMI8658_REG_CTRL1, buffer, 9); + for (int i = 0; i < 9; ++i) { +#if defined(ARDUINO) + Serial.printf("CTRL%d: REG:0x%02X HEX:0x%02X ", i + 1, QMI8658_REG_CTRL1 + i, buffer[i]); +#else + printf("CTRL%d: 0x%02x", i + 1, buffer[i]); +#endif +#if defined(ARDUINO) + Serial.print(" BIN:0b"); + Serial.println(buffer[i], BIN); +#else + LOG("\n"); +#endif + } +#if defined(ARDUINO) + Serial.println(); +#else + printf("\n"); +#endif + + buffer[0] = readRegister(QMI8658_REG_FIFOCTRL); +#if defined(ARDUINO) + Serial.printf("FIFOCTRL: REG:0x%02X HEX:0x%02X ", QMI8658_REG_FIFOCTRL, buffer[0]); + Serial.print(" BIN:0b"); + Serial.println(buffer[0], BIN); +#else + printf("FIFOCTRL: REG:0x%02X HEX:0x%02X \n", QMI8658_REG_FIFOCTRL, buffer[0]); +#endif + + } + + void powerDown() + { + disableAccelerometer(); + disableGyroscope(); + setRegisterBit(QMI8658_REG_CTRL1, 1); + } + + void powerOn() + { + clrRegisterBit(QMI8658_REG_CTRL1, 1); + } + + int getStatusRegister() + { + return readRegister(QMI8658_REG_STATUS1); + } + + int configActivityInterruptMap(IntPin pin) + { + return pin == IntPin1 ? setRegisterBit(QMI8658_REG_CTRL8, 6) + : clrRegisterBit(QMI8658_REG_CTRL8, 6); + } + + /** + * @brief configPedometer + * @note The calculation of the Pedometer Detection is based on the accelerometer ODR defined by CTRL2.aODR, + * refer to Table 22 for details. + * @param ped_sample_cnt: Indicates the count of sample batch/window for calculation + * @param ped_fix_peak2peak:Indicates the threshold of the valid peak-to-peak detection + * E.g., 0x00CC means 200mg + * @param ped_fix_peak:Indicates the threshold of the peak detection comparing to average + * E.g., 0x0066 means 100mg + * @param ped_time_up:Indicates the maximum duration (timeout window) for a step. + * Reset counting calculation if no peaks detected within this duration. + * E.g., 80 means 1.6s @ ODR = 50Hz + * @param ped_time_low:Indicates the minimum duration for a step. + * The peaks detected within this duration (quiet time) is ignored. + * E.g., 12 means 0.25s @ ODR = 50Hz + * @param ped_time_cnt_entry:Indicates the minimum continuous steps to start the valid step counting. + * If the continuously detected steps is lower than this count and timeout, + * the steps will not be take into account; + * if yes, the detected steps will all be taken into account and + * counting is started to count every following step before timeout. + * This is useful to screen out the fake steps detected by non-step vibrations + * The timeout duration is defined by ped_time_up. + * E.g., 10 means 10 steps entry count + * @param ped_fix_precision:0 is recommended + * @param ped_sig_count: The amount of steps when to update the pedometer output registers. + * E.g., ped_sig_count = 4, every 4 valid steps is detected, update the registers once (added by 4). + * @retval + */ + int configPedometer(uint16_t ped_sample_cnt, uint16_t ped_fix_peak2peak, uint16_t ped_fix_peak, + uint16_t ped_time_up, uint8_t ped_time_low = 0x14, uint8_t ped_time_cnt_entry = 0x0A, uint8_t ped_fix_precision = 0x00, + uint8_t ped_sig_count = 0x04) + { + // The Pedometer can only work in Non-SyncSample mode + disableSyncSampleMode(); + + bool enGyro = isEnableGyroscope(); + bool enAccel = isEnableAccelerometer(); + + if (enGyro) { + disableGyroscope(); + } + + if (enAccel) { + disableAccelerometer(); + } + + writeRegister(QMI8658_REG_CAL1_L, ped_sample_cnt & 0xFF); + writeRegister(QMI8658_REG_CAL1_H, (ped_sample_cnt >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL2_L, ped_fix_peak2peak & 0xFF); + writeRegister(QMI8658_REG_CAL2_H, (ped_fix_peak2peak >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL3_L, ped_fix_peak & 0xFF); + writeRegister(QMI8658_REG_CAL3_H, (ped_fix_peak >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL4_H, 0x01); + writeRegister(QMI8658_REG_CAL4_L, 0x02); + + writeCommand(CTRL_CMD_CONFIGURE_PEDOMETER); + + writeRegister(QMI8658_REG_CAL1_L, ped_time_up & 0xFF); + writeRegister(QMI8658_REG_CAL1_H, (ped_time_up >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL2_L, ped_time_low); + writeRegister(QMI8658_REG_CAL2_H, ped_time_cnt_entry); + writeRegister(QMI8658_REG_CAL3_L, ped_fix_precision); + writeRegister(QMI8658_REG_CAL3_H, ped_sig_count); + writeRegister(QMI8658_REG_CAL4_H, 0x02); + writeRegister(QMI8658_REG_CAL4_L, 0x02); + + writeCommand(CTRL_CMD_CONFIGURE_PEDOMETER); + + if (enGyro) { + enableGyroscope(); + } + + if (enAccel) { + enableAccelerometer(); + } + return 0; + } + + uint32_t getPedometerCounter() + { + uint8_t buffer[3]; + if (readRegister(QMI8658_REG_PEDO_L, buffer, 3) != DEV_WIRE_ERR) { + return (uint32_t)(((uint32_t)buffer[2] << 16) | ((uint32_t)buffer[1] << 8) | buffer[0]); + } + return 0; + } + + int clearPedometerCounter() + { + return writeCommand(CTRL_CMD_RESET_PEDOMETER); + } + + // The Pedometer can only work in Non-SyncSample mode + int enablePedometer() + { + return setRegisterBit(QMI8658_REG_CTRL8, 4); + } + + int disablePedometer() + { + return clrRegisterBit(QMI8658_REG_CTRL8, 4); + } + + enum TagPriority { + PRIORITY0, // (X > Y> Z) + PRIORITY1, // (X > Z > Y) + PRIORITY2, // (Y > X > Z) + PRIORITY3, // (Y > Z > X) + PRIORITY4, // (Z > X > Y) + PRIORITY5, // (Z > Y > X) + }; + + /** + * @brief configTap + * @note The calculation of the Tap Detection is based on the accelerometer ODR defined by CTRL2.aODR, refer to Table 22 for details. + * @param priority: Priority definition between the x, y, z axes of acceleration. Only + Priority[2:0] bits are used. + The axis that output the first peak of Linear Acceleration in a valid + Tap detection, will be consider as the Tap axis. However, there is + possibility that two or three of the axes shows same Linear + Acceleration at exactly same time when reach (or be higher than) + the PeakMagThr. In this case, the defined priority is used to judge + and select the axis as Tap axis. + * @param peakWindow:Defines the maximum duration (in sample) for a valid peak. In a + valid peak, the linear acceleration should reach or be higher than + the PeakMagThr and should return to quiet (no significant + movement) within UDMThr, at the end of PeakWindow. + E.g., 20 @500Hz ODR + * @param tapWindow:Defines the minimum quiet time before the second Tap happen. + After the first Tap is detected, there should be no significant + movement (defined by UDMThr) during the TapWindow. The valid + second tap should be detected after TapWindow and before + DTapWindow. + E.g., 50 @500Hz ODR + * @param dTapWindow:Defines the maximum time for a valid second Tap for Double Tap, + count start from the first peak of the valid first Tap. + E.g., 250 @500Hz ODR + * @param alpha:Defines the ratio for calculation the average of the acceleration. + The bigger of Alpha, the bigger weight of the latest data. + E.g., 0.0625 + * @param gamma:Defines the ratio for calculating the average of the movement + magnitude. The bigger of Gamma, the bigger weight of the latest + data. + E.g., 0.25 + * @param peakMagThr:Threshold for peak detection. + E.g, 0.8g2 (0x0320) + * @param UDMThr:Undefined Motion threshold. This defines the threshold of the + Linear Acceleration for quiet status. + E.g., 0.4g2 (0x0190) + * @retval + */ + int configTap(uint8_t priority, uint8_t peakWindow, uint16_t tapWindow, uint16_t dTapWindow, + uint8_t alpha, uint8_t gamma, uint16_t peakMagThr, uint16_t UDMThr) + { + bool enGyro = isEnableGyroscope(); + bool enAccel = isEnableAccelerometer(); + + if (enGyro) { + disableGyroscope(); + } + + if (enAccel) { + disableAccelerometer(); + } + writeRegister(QMI8658_REG_CAL1_L, peakWindow); + writeRegister(QMI8658_REG_CAL1_H, priority); + writeRegister(QMI8658_REG_CAL2_L, tapWindow & 0xFF); + writeRegister(QMI8658_REG_CAL2_H, (tapWindow >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL3_L, dTapWindow & 0xFF); + writeRegister(QMI8658_REG_CAL3_H, (dTapWindow >> 8) & 0xFF); + // writeRegister(QMI8658_REG_CAL4_L, 0x02); + writeRegister(QMI8658_REG_CAL4_H, 0x01); + + writeCommand(CTRL_CMD_CONFIGURE_TAP); + + writeRegister(QMI8658_REG_CAL1_L, alpha); + writeRegister(QMI8658_REG_CAL1_H, gamma); + writeRegister(QMI8658_REG_CAL2_L, peakMagThr & 0xFF); + writeRegister(QMI8658_REG_CAL2_H, (peakMagThr >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL3_L, UDMThr & 0xFF); + writeRegister(QMI8658_REG_CAL3_H, (UDMThr >> 8) & 0xFF); + // writeRegister(QMI8658_REG_CAL4_L, 0x02); + writeRegister(QMI8658_REG_CAL4_H, 0x02); + + writeCommand(CTRL_CMD_CONFIGURE_TAP); + + if (enGyro) { + enableGyroscope(); + } + + if (enAccel) { + enableAccelerometer(); + } + + return 0; + } + + int enableTap() + { + return setRegisterBit(QMI8658_REG_CTRL8, 0); + } + + int disableTap() + { + return clrRegisterBit(QMI8658_REG_CTRL8, 0); + } + + void getTapStatus() + { + int val = readRegister(QMI8658_REG_TAP_STATUS); + if (val & _BV(7)) { + LOG("Tap was detected on the negative direction of the Tap axis\n"); + } else { + LOG("Tap was detected on the positive direction of the Tap axis\n"); + } + uint8_t t = (val >> 4) & 0x03; + switch (t) { + case 0: + LOG("No Tap was detected\n"); + break; + case 1: + LOG("Tap was detected on X axis\n"); + break; + case 2: + LOG("Tap was detected on Y axis\n"); + break; + case 3: + LOG("Tap was detected on Z axis\n"); + break; + + default: + break; + } + t = val & 0x03; + switch (t) { + case 0: + LOG("No Tap was detected\n"); + break; + case 1: + LOG("Single-Tap was detected\n"); + break; + case 2: + LOG("Double-Tap was detected\n"); + break; + default: + break; + } + LOG("\n\n\n"); + } + + + /** + * @brief + * @note + * @param AnyMotionXThr: + * @param AnyMotionYThr: + * @param AnyMotionZThr: + * @param NoMotionXThr: + * @param NoMotionYThr: + * @param NoMotionZThr: + * @param modeCtrl: + * @param AnyMotionWindow: + * @param NoMotionWindow: + * @param SigMotionWaitWindow: + * @param SigMotionConfirmWindow: + * @retval + */ + int configMotion(uint8_t AnyMotionXThr, uint8_t AnyMotionYThr, uint8_t AnyMotionZThr, + uint8_t NoMotionXThr, uint8_t NoMotionYThr, uint8_t NoMotionZThr, uint8_t modeCtrl, + uint8_t AnyMotionWindow, uint8_t NoMotionWindow, + uint16_t SigMotionWaitWindow, uint16_t SigMotionConfirmWindow) + { + bool enGyro = isEnableGyroscope(); + bool enAccel = isEnableAccelerometer(); + + if (enGyro) { + disableGyroscope(); + } + + if (enAccel) { + disableAccelerometer(); + } + writeRegister(QMI8658_REG_CAL1_L, AnyMotionXThr); + writeRegister(QMI8658_REG_CAL1_H, AnyMotionYThr); + writeRegister(QMI8658_REG_CAL2_L, AnyMotionZThr); + writeRegister(QMI8658_REG_CAL2_H, NoMotionXThr); + writeRegister(QMI8658_REG_CAL3_L, NoMotionYThr); + writeRegister(QMI8658_REG_CAL3_H, NoMotionZThr); + writeRegister(QMI8658_REG_CAL4_L, modeCtrl); + writeRegister(QMI8658_REG_CAL4_H, 0x01); + + writeCommand(CTRL_CMD_CONFIGURE_MOTION); + + writeRegister(QMI8658_REG_CAL1_L, AnyMotionWindow); + writeRegister(QMI8658_REG_CAL1_H, NoMotionWindow); + writeRegister(QMI8658_REG_CAL2_L, SigMotionWaitWindow & 0xFF); + writeRegister(QMI8658_REG_CAL2_H, (SigMotionWaitWindow >> 8) & 0xFF); + writeRegister(QMI8658_REG_CAL3_L, SigMotionConfirmWindow & 0xFF); + writeRegister(QMI8658_REG_CAL3_H, (SigMotionConfirmWindow >> 8) & 0xFF); + // writeRegister(QMI8658_REG_CAL4_L, 0x02); + writeRegister(QMI8658_REG_CAL4_H, 0x02); + + writeCommand(CTRL_CMD_CONFIGURE_MOTION); + + if (enGyro) { + enableGyroscope(); + } + + if (enAccel) { + enableAccelerometer(); + } + return 0; + } + + int enableMotionDetect() + { + setRegisterBit(QMI8658_REG_CTRL8, 1); + setRegisterBit(QMI8658_REG_CTRL8, 3); + return setRegisterBit(QMI8658_REG_CTRL8, 2); + } + + int disableMotionDetect() + { + return clrRegisterBit(QMI8658_REG_CTRL8, 2); + } + + + /** + * @brief configWakeOnMotion + * @note Configuring Wom will reset the sensor, set the function to Wom, and there will be no data output + * @param WoMThreshold: Resolution = 1mg ,default 200g + * @param odr: Accelerometer output data rate ,defalut low power 128Hz + * @param pin: Interrupt Pin( 1 or 2 ) ,defalut use pin2 + * @param defaultPinValue: WoM Interrupt Initial Value select: ,default pin high + * 01 – INT2 (with initial value 0) + * 11 – INT2 (with initial value 1) + * 00 – INT1 (with initial value 0) + * 10 – INT1 (with initial value 1) + * @param blankingTime: Interrupt Blanking Time + * (in number of accelerometer samples), the + * number of consecutive samples that will be ignored after + * enabling the WoM, to screen out unwanted fake detection + * @retval + */ + int configWakeOnMotion(uint8_t WoMThreshold = 200, + AccelODR odr = ACC_ODR_LOWPOWER_128Hz, + IntPin pin = IntPin2, + uint8_t defaultPinValue = 1, + uint8_t blankingTime = 0x20 + ) + { + + uint8_t val = 0; + + //Reset default value + if (!reset()) { + return DEV_WIRE_ERR; + } + + // Disable sensors + clrRegisterBit(QMI8658_REG_CTRL7, 0); + + //setAccelRange + if (writeRegister(QMI8658_REG_CTRL2, 0x8F, (ACC_RANGE_8G << 4)) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + // setAccelOutputDataRate + if (writeRegister(QMI8658_REG_CTRL2, 0xF0, odr) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + //set wom + if (writeRegister(QMI8658_REG_CAL1_L, WoMThreshold) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + if ( pin == IntPin1) { + val = defaultPinValue ? 0x02 : 0x00; + } else if (pin == IntPin2) { + val = defaultPinValue ? 0x03 : 0x01; + } + + val <<= 6; + val |= (blankingTime & 0x3F); + if (writeRegister(QMI8658_REG_CAL1_H, val) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + if (writeCommand(CTRL_CMD_WRITE_WOM_SETTING) != DEV_WIRE_NONE) { + return DEV_WIRE_ERR; + } + + enableAccelerometer(); + + enableINT(pin); + + return DEV_WIRE_NONE; + } + + + + void getChipUsid(uint8_t *buffer, uint8_t lenght) + { + if (lenght > 6) { + lenght = 6; + } + memcpy(buffer, usid, lenght); + } + + + uint32_t getChipFirmwareVersion() + { + return revisionID; + } + + enum SensorStatus { + STATUS_INT_CTRL9_CMD_DONE = _BV(0), + STATUS_INT_LOCKED = _BV(1), + STATUS_INT_AVAIL = _BV(2), + STATUS0_GDATA_REDAY = _BV(3), + STATUS0_ADATA_REDAY = _BV(4), + STATUS1_SIGNI_MOTION = _BV(5), + STATUS1_NO_MOTION = _BV(6), + STATUS1_ANY_MOTION = _BV(7), + STATUS1_PEDOME_MOTION = _BV(8), + STATUS1_WOM_MOTION = _BV(9), + STATUS1_TAP_MOTION = _BV(10), + }; + + /** + * @brief readSensorStatus + * @note Get the interrupt status and status 0, status 1 of the sensor + * @retval Return SensorStatus + */ + uint16_t readSensorStatus() + { + uint16_t result = 0; + // STATUSINT 0x2D + // STATUS0 0x2E + // STATUS1 0x2F + uint8_t status[3]; + if (readRegister(QMI8658_REG_STATUSINT, status, 3) != DEV_WIRE_NONE) { + return 0; + } + + // LOG("STATUSINT:0x%X BIN:", status[0]); + // LOG_BIN(status[0]); + // LOG("STATUS0:0x%X BIN:", status[1]); + // LOG_BIN(status[1]); + // LOG("STATUS1:0x%X BIN:", status[2]); + // LOG_BIN(status[2]); + // LOG("------------------\n"); + + // Ctrl9 CmdDone + // Indicates CTRL9 Command was done, as part of CTRL9 protocol + // 0: Not Completed + // 1: Done + if (status[0] & 0x80) { + result |= STATUS_INT_CTRL9_CMD_DONE; + } + // If syncSmpl (CTRL7.bit7) = 1: + // 0: Sensor Data is not locked. + // 1: Sensor Data is locked. + // If syncSmpl = 0, this bit shows the same value of INT1 level + if (status[0] & 0x02) { + result |= STATUS_INT_LOCKED; + } + // If syncSmpl (CTRL7.bit7) = 1: + // 0: Sensor Data is not available + // 1: Sensor Data is available for reading + // If syncSmpl = 0, this bit shows the same value of INT2 level + if (status[0] & 0x01) { + result |= STATUS_INT_AVAIL; + // if (eventGyroDataReady)eventGyroDataReady(); + // if (eventAccelDataReady)eventAccelDataReady(); + } + + //Locking Mechanism Can reading.. + if ((status[0] & 0x03) == 0x03) { + if (eventDataLocking)eventDataLocking(); + } + + //======================================= + // Valid only in asynchronous mode + if (sampleMode == ASYNC_MODE) { + // Gyroscope new data available + // 0: No updates since last read. + // 1: New data available + if (status[1] & 0x02) { + result |= STATUS0_GDATA_REDAY; + if (eventGyroDataReady)eventGyroDataReady(); + __gDataReady = true; + } + // Accelerometer new data available + // 0: No updates since last read. + // 1: New data available. + if (status[1] & 0x01) { + result |= STATUS0_ADATA_REDAY; + if (eventAccelDataReady)eventAccelDataReady(); + __aDataReady = true; + } + } + + //======================================= + // Significant Motion + // 0: No Significant-Motion was detected + // 1: Significant-Motion was detected + if (status[2] & 0x80) { + result |= STATUS1_SIGNI_MOTION; + if (eventSignificantMotion)eventSignificantMotion(); + } + // No Motion + // 0: No No-Motion was detected + // 1: No-Motion was detected + if (status[2] & 0x40) { + result |= STATUS1_NO_MOTION; + if (eventNoMotionEvent)eventNoMotionEvent(); + } + // Any Motion + // 0: No Any-Motion was detected + // 1: Any-Motion was detected + if (status[2] & 0x20) { + result |= STATUS1_ANY_MOTION; + if (eventAnyMotionEvent)eventAnyMotionEvent(); + } + // Pedometer + // 0: No step was detected + // 1: step was detected + if (status[2] & 0x10) { + result |= STATUS1_PEDOME_MOTION; + if (eventPedometerEvent)eventPedometerEvent(); + } + // WoM + // 0: No WoM was detected + // 1: WoM was detected + if (status[2] & 0x04) { + result |= STATUS1_WOM_MOTION; + if (eventWomEvent)eventWomEvent(); + } + // TAP + // 0: No Tap was detected + // 1: Tap was detected + if (status[2] & 0x02) { + result |= STATUS1_TAP_MOTION; + if (eventTagEvent)eventTagEvent(); + } + return result; + } + + void setWakeupMotionEventCallBack(EventCallBack_t cb) + { + eventWomEvent = cb; + } + + void setTapEventCallBack(EventCallBack_t cb) + { + eventTagEvent = cb; + } + + void setPedometerEventCallBack(EventCallBack_t cb) + { + eventPedometerEvent = cb; + } + + void setNoMotionEventCallBack(EventCallBack_t cb) + { + eventNoMotionEvent = cb; + } + + void setAnyMotionEventCallBack(EventCallBack_t cb) + { + eventAnyMotionEvent = cb; + } + + void setSignificantMotionEventCallBack(EventCallBack_t cb) + { + eventSignificantMotion = cb; + } + + void setGyroDataReadyCallBack(EventCallBack_t cb) + { + eventGyroDataReady = cb; + } + + void setAccelDataReadyEventCallBack(EventCallBack_t cb) + { + eventAccelDataReady = cb; + } + + void setDataLockingEvevntCallBack(EventCallBack_t cb) + { + eventDataLocking = cb; + } + +private: + float accelScales, gyroScales; + uint32_t lastTimestamp = 0; + uint8_t sampleMode = ASYNC_MODE; + bool accelEn, gyroEn; + uint8_t fifoMode; + uint32_t revisionID; + uint8_t usid[6]; + bool __gDataReady = false; + bool __aDataReady = false; + + EventCallBack_t eventWomEvent = NULL; + EventCallBack_t eventTagEvent = NULL; + EventCallBack_t eventPedometerEvent = NULL; + EventCallBack_t eventNoMotionEvent = NULL; + EventCallBack_t eventAnyMotionEvent = NULL; + EventCallBack_t eventSignificantMotion = NULL; + EventCallBack_t eventGyroDataReady = NULL; + EventCallBack_t eventAccelDataReady = NULL; + EventCallBack_t eventDataLocking = NULL; + + + int writeCommand(CommandTable cmd) + { + int val; + uint32_t startMillis; + if (writeRegister(QMI8658_REG_CTRL9, cmd) == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + startMillis = millis(); + do { + val = readRegister(QMI8658_REG_STATUSINT); + delay(1); + if (millis() - startMillis > 1000) { + LOG("wait for ctrl9 command done time out : %d val:%d \n", cmd, val); + return DEV_WIRE_TIMEOUT; + } + } while (val != DEV_WIRE_ERR && !(val & 0x80)); + + if (writeRegister(QMI8658_REG_CTRL9, CTRL_CMD_ACK) == DEV_WIRE_ERR) { + return DEV_WIRE_ERR; + } + + startMillis = millis(); + do { + val = readRegister(QMI8658_REG_STATUSINT); + delay(1); + if (millis() - startMillis > 1000) { + LOG("Clear ctrl9 command done flag timeout : %d val:%d \n", cmd, val); + return DEV_WIRE_TIMEOUT; + } + } while (val != DEV_WIRE_ERR && (val & 0x80)); + + return DEV_WIRE_NONE; + } + +protected: + + bool initImpl() + { + uint8_t buffer[6] = {0}; + + if (!reset()) { + return false; + } + + uint8_t id = whoAmI(); + if (id != QMI8658_REG_WHOAMI_DEFAULT) { + LOG("ERROR! ID NOT MATCH QMI8658 , Respone id is 0x%x\n", id); + return false; + } + // Eanble address auto increment, Big-Endian format + // writeRegister(QMI8658_REG_CTRL1, 0x60); + + // Little-Endian / address auto increment + // writeRegister(QMI8658_REG_CTRL1, 0x40); + + // no need . reset function has set + //EN.ADDR_AI + // setRegisterBit(QMI8658_REG_CTRL1, 6); + + + // Use STATUSINT.bit7 as CTRL9 handshake + writeRegister(QMI8658_REG_CTRL8, 0x80); + + // Get firmware version and usid + writeCommand(CTRL_CMD_COPY_USID); + + if (readRegister(QMI8658_REG_DQW_L, buffer, 3) != DEV_WIRE_ERR) { + revisionID = buffer[0] | (uint32_t)(buffer[1] << 8) | + (uint32_t)(buffer[2] << 16); + LOG("FW Version :0x%02X%02X%02X\n", buffer[0], buffer[1], buffer[2]); + } + + if (readRegister(QMI8658_REG_DVX_L, usid, 6) != DEV_WIRE_ERR) { + LOG("USID :%02X%02X%02X%02X%02X%02X\n", + usid[0], usid[1], usid[2], + usid[3], usid[4], usid[5]); + } + + return true; + } + + int getReadMaskImpl() + { + return 0x80; + } + +}; + + + + + + + + diff --git a/components/SensorLib/src/SensorRTC.h b/components/SensorLib/src/SensorRTC.h new file mode 100644 index 0000000..915748e --- /dev/null +++ b/components/SensorLib/src/SensorRTC.h @@ -0,0 +1,344 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorRTC.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-07 + * + */ +#pragma once + +#ifdef ARDUINO +#include +#else +#include +#endif /*defined(ARDUINO)*/ + +#include + +#define RTC_DAYS_IN_JANUARY (31u) +#define RTC_DAYS_IN_FEBRUARY (28u) +#define RTC_DAYS_IN_MARCH (31u) +#define RTC_DAYS_IN_APRIL (30u) +#define RTC_DAYS_IN_MAY (31u) +#define RTC_DAYS_IN_JUNE (30u) +#define RTC_DAYS_IN_JULY (31u) +#define RTC_DAYS_IN_AUGUST (31u) +#define RTC_DAYS_IN_SEPTEMBER (30u) +#define RTC_DAYS_IN_OCTOBER (31u) +#define RTC_DAYS_IN_NOVEMBER (30u) +#define RTC_DAYS_IN_DECEMBER (31u) + +enum { + DATETIME_FORMAT_HM, + DATETIME_FORMAT_HMS, + DATETIME_FORMAT_YYYY_MM_DD, + DATETIME_FORMAT_MM_DD_YYYY, + DATETIME_FORMAT_DD_MM_YYYY, + DATETIME_FORMAT_YYYY_MM_DD_H_M_S, + DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK, +}; + + + +class RTC_DateTime +{ +public: + RTC_DateTime() : year(0), month(0), day(0), hour(0), minute(0), second(0), week(0), available(false) {} + RTC_DateTime(const char *date, const char *time) + { + // sample input: date = "Dec 26 2009", time = "12:34:56" + year = 2000 + StringToUint8(date + 9); + // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec + switch (date[0]) { + case 'J': + if ( date[1] == 'a' ) + month = 1; + else if ( date[2] == 'n' ) + month = 6; + else + month = 7; + break; + case 'F': + month = 2; + break; + case 'A': + month = date[1] == 'p' ? 4 : 8; + break; + case 'M': + month = date[2] == 'r' ? 3 : 5; + break; + case 'S': + month = 9; + break; + case 'O': + month = 10; + break; + case 'N': + month = 11; + break; + case 'D': + month = 12; + break; + } + day = StringToUint8(date + 4); + hour = StringToUint8(time); + minute = StringToUint8(time + 3); + second = StringToUint8(time + 6); + } + RTC_DateTime(uint16_t year, + uint8_t month, + uint8_t day, + uint8_t hour, + uint8_t minute, + uint8_t second + ) + { + this->year = year; + this->month = month; + this->day = day; + this->hour = hour; + this->minute = minute; + this->second = second; + this->week = week; + }; + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t minute; + uint8_t second; + uint8_t week; + char AMPM; + bool available; + bool operator==(RTC_DateTime d) + { + return ((d.year == year) && + (d.month == month) && + (d.day == day) && + (d.hour == hour) && + (d.minute == minute)); + } +private: + uint8_t StringToUint8(const char *pString) + { + uint8_t value = 0; + + // skip leading 0 and spaces + while ('0' == *pString || *pString == ' ') { + pString++; + } + + // calculate number until we hit non-numeral char + while ('0' <= *pString && *pString <= '9') { + value *= 10; + value += *pString - '0'; + pString++; + } + return value; + } +}; + +class RTC_Alarm +{ +public: + RTC_Alarm(void): second(0), minute(0), hour(0), day(0), week(0) {} + RTC_Alarm( + uint8_t hour, + uint8_t minute, + uint8_t second, + uint8_t day, + uint8_t week + ): second(second), minute(minute), hour(hour), day(day), week(week) + { + } + uint8_t second; + uint8_t minute; + uint8_t hour; + uint8_t day; + uint8_t week; +}; + +template +class RTCCommon +{ +public: + const char *strftime(uint8_t sytle = DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK) + { + const char *weekString[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"}; + static char format[64]; + RTC_DateTime t = thisChip().getDateTime(); + switch (sytle) { + case DATETIME_FORMAT_HM: + snprintf(format, sizeof(format), "%02d:%02d", t.hour, t.minute); + break; + case DATETIME_FORMAT_HMS: + snprintf(format, sizeof(format), "%02d:%02d:%02d", t.hour, t.minute, t.second); + break; + case DATETIME_FORMAT_YYYY_MM_DD: + snprintf(format, sizeof(format), "%d-%02d-%02d", t.year, t.month, t.day); + break; + case DATETIME_FORMAT_MM_DD_YYYY: + snprintf(format, sizeof(format), "%02d-%02d-%d", t.month, t.day, t.year); + break; + case DATETIME_FORMAT_DD_MM_YYYY: + snprintf(format, sizeof(format), "%02d-%02d-%d", t.day, t.month, t.year); + break; + case DATETIME_FORMAT_YYYY_MM_DD_H_M_S: + snprintf(format, sizeof(format), "%d-%02d-%02d/%02d:%02d:%02d", t.year, t.month, t.day, t.hour, t.minute, t.second); + break; + case DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK: + snprintf(format, sizeof(format), "%d-%02d-%02d/%02d:%02d:%02d - %s", t.year, t.month, t.day, t.hour, t.minute, t.second, weekString[t.week > 6 ? 0 : t.week]); + break; + default: + snprintf(format, sizeof(format), "%02d:%02d", t.hour, t.minute); + break; + } + return format; + } + + struct tm conversionUnixTime(RTC_DateTime datetime) + { + struct tm t_tm; + t_tm.tm_hour = datetime.hour; + t_tm.tm_min = datetime.minute; + t_tm.tm_sec = datetime.second; + t_tm.tm_year = datetime.year - 1900; //Year, whose value starts from 1900 + t_tm.tm_mon = datetime.month - 1; //Month (starting from January, 0 for January) - Value range is [0,11] + t_tm.tm_mday = datetime.day; + t_tm.tm_wday = datetime.week; + return t_tm; + } + + time_t hwClockRead() + { + struct tm t_tm = conversionUnixTime(thisChip().getDateTime()); + struct timeval val; + val.tv_sec = mktime(&t_tm); + val.tv_usec = 0; +#if __BSD_VISIBLE + settimeofday(&val, NULL); +#endif /*__BSD_VISIBLE*/ + return val.tv_sec; + } + + void hwClockWrite() + { + time_t now; + struct tm info; + time(&now); + localtime_r(&now, &info); + thisChip().setDateTime(info.tm_year + 1900, + info.tm_mon + 1, + info.tm_mday, + info.tm_hour, + info.tm_min, + info.tm_sec); + } + + uint32_t getDayOfWeek(uint32_t day, uint32_t month, uint32_t year) + { + uint32_t val; + if (month < 3) { + month = 12u + month; + year--; + } + val = (day + (((month + 1u) * 26u) / 10u) + year + (year / 4u) + (6u * (year / 100u)) + (year / 400u)) % 7u; + if (0u == val) { + val = 7; + } + return (val - 1); + } + + uint8_t getNextMonth(uint8_t curMonth) + { + return ((curMonth < 12u) ? (curMonth + 1u) : 1u); + } + + uint16_t getNextYear(uint16_t curYear) + { + return (curYear + 1u); + } + + uint32_t getLeapYear(uint32_t year) + { + uint32_t val; + if (((0u == (year % 4Lu)) && (0u != (year % 100Lu))) || (0u == (year % 400Lu))) { + val = 1uL; + } else { + val = 0uL; + } + return val; + } + + uint8_t getDaysInMonth(uint8_t month, uint16_t year) + { + const uint8_t daysInMonthTable[12] = {RTC_DAYS_IN_JANUARY, + RTC_DAYS_IN_FEBRUARY, + RTC_DAYS_IN_MARCH, + RTC_DAYS_IN_APRIL, + RTC_DAYS_IN_MAY, + RTC_DAYS_IN_JUNE, + RTC_DAYS_IN_JULY, + RTC_DAYS_IN_AUGUST, + RTC_DAYS_IN_SEPTEMBER, + RTC_DAYS_IN_OCTOBER, + RTC_DAYS_IN_NOVEMBER, + RTC_DAYS_IN_DECEMBER + }; + + uint8_t val; + val = daysInMonthTable[month - 1u]; + if (2 == month) { + if (0u != getLeapYear(year)) { + val++; + } + } + return val; + } + + uint8_t BCD2DEC(uint8_t val) + { + return ((val / 16 * 10) + (val % 16)); + } + uint8_t DEC2BCD(uint8_t val) + { + return ((val / 10 * 16) + (val % 10)); + } + + /* + * CRTP Helper + */ +protected: + inline const chipType &thisChip() const + { + return static_cast(*this); + } + + inline chipType &thisChip() + { + return static_cast(*this); + } + +}; \ No newline at end of file diff --git a/components/SensorLib/src/SensorWireHelper.cpp b/components/SensorLib/src/SensorWireHelper.cpp new file mode 100644 index 0000000..5983ac1 --- /dev/null +++ b/components/SensorLib/src/SensorWireHelper.cpp @@ -0,0 +1,123 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorWireHelper.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-05 + * + */ +#include "SensorWireHelper.h" + +#if defined(ARDUINO) + + + +int SensorWireHelper::regdump(TwoWire &w, Stream &serial, uint8_t devAddr, uint8_t start, uint8_t length) +{ + uint8_t *buffer = (uint8_t *)malloc(length); + if (!buffer) return -1; + w.begin(); + w.beginTransmission(devAddr); + w.write(start); + if (w.endTransmission() != 0) { + free(buffer); + return -1; + } + size_t len = w.requestFrom(devAddr, length); + if (length != len) { + free(buffer); + return -1; + } + w.readBytes(buffer, length); + hexdump(buffer, length, serial); + free(buffer); + return 0; +} + + + +void SensorWireHelper::dumpDevices(TwoWire &w, Stream &serial, int first, int last) +{ + int i, j; + int ret; + serial.printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); + for (i = 0; i < 128; i += 16) { + serial.printf("%02x: ", i); + + for (j = 0; j < 16; j++) { + /* Skip unwanted addresses */ + if (i + j < first || i + j > last) { + serial.printf(" "); + continue; + } + + w.beginTransmission(i + j); + ret = w.endTransmission(); + + if (ret != 0) + serial.printf("-- "); + else + serial.printf("%02x ", i + j); + } + serial.printf("\n"); + } +} + + +void SensorWireHelper::hexdump(uint8_t *data, size_t len, Stream &serial) +{ + size_t rem_len = len; + for (size_t i = 0; i < len; i += 16) { + char str[80]; + snprintf(str, 80, "%07x ", i); + size_t line_len = 16; + if (rem_len < line_len) { + line_len = rem_len; + } + for (size_t j = 0; j < line_len; j++) { + snprintf(&str[8 + j * 3], 80, "%02x ", data[i + j]); + } + for (size_t j = line_len; j < 16; j++) { + snprintf(&str[8 + j * 3], 80, " "); + } + str[56] = '|'; + str[57] = ' '; + for (size_t j = 0; j < line_len; j++) { + char c = data[i + j]; + if ((c < ' ') || (c > '~')) { + c = '.'; + } + snprintf(&str[58 + j], 80, "%c", c); + } + for (size_t j = line_len; j < 16; j++) { + snprintf(&str[58 + j], 80, " "); + } + serial.println(str); + rem_len -= 16; + } +} + + + +#endif //ARDUINO diff --git a/components/SensorLib/src/SensorWireHelper.h b/components/SensorLib/src/SensorWireHelper.h new file mode 100644 index 0000000..bfd1131 --- /dev/null +++ b/components/SensorLib/src/SensorWireHelper.h @@ -0,0 +1,46 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorWireHelper.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-10 + * + */ +#pragma once + +#if defined(ARDUINO) +#include +#include + +class SensorWireHelper +{ +public: + static int regdump(TwoWire &w, Stream &serial, uint8_t devAddr, uint8_t start, uint8_t len); + static void dumpDevices(TwoWire &w, Stream &serial = Serial, int first = 0, int last = 127); + static void hexdump(uint8_t *data, size_t len, Stream &serial = Serial); +}; + +#endif /*ARDUINO*/ + + diff --git a/components/SensorLib/src/TouchDrvCHSC5816.hpp b/components/SensorLib/src/TouchDrvCHSC5816.hpp new file mode 100644 index 0000000..31efa43 --- /dev/null +++ b/components/SensorLib/src/TouchDrvCHSC5816.hpp @@ -0,0 +1,312 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvCHSC5816.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-12 + * + */ +#pragma once + +#include "REG/CHSC5816Constants.h" +#include "TouchDrvInterface.hpp" +#include "SensorCommon.tpp" + +typedef struct __CHSC5816_Header { + uint16_t fw_ver; + uint16_t checksum; + uint32_t sig; + uint32_t vid_pid; + uint16_t raw_offet; + uint16_t dif_offet; +} CHSC5816_Header_t; + +union __CHSC5816_PointReg { + struct { + uint8_t status; + uint8_t fingerNumber; + uint8_t x_l8; + uint8_t y_l8; + uint8_t z; + uint8_t x_h4: 4; + uint8_t y_h4: 4; + uint8_t id: 4; + uint8_t event: 4; + uint8_t p2; + } rp; + unsigned char data[8]; +}; + +class TouchDrvCHSC5816 : + public TouchDrvInterface, + public SensorCommon +{ + friend class SensorCommon; +public: + + +#if defined(ARDUINO) + TouchDrvCHSC5816(PLATFORM_WIRE_TYPE &w, + int sda = DEFAULT_SDA, + int scl = DEFAULT_SCL, + uint8_t addr = CHSC5816_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __rst = SENSOR_PIN_NONE; + __irq = SENSOR_PIN_NONE; + __addr = addr; + } +#endif + + TouchDrvCHSC5816() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __rst = SENSOR_PIN_NONE; + __irq = SENSOR_PIN_NONE; + __addr = CHSC5816_SLAVE_ADDRESS; + } + + ~TouchDrvCHSC5816() + { + // deinit(); + } + +#if defined(ARDUINO) + bool begin(PLATFORM_WIRE_TYPE &w, + uint8_t addr = CHSC5816_SLAVE_ADDRESS, + int sda = DEFAULT_SDA, + int scl = DEFAULT_SCL) + { + return SensorCommon::begin(w, addr, sda, scl); + } +#endif + +#if defined(ESP_PLATFORM) && !defined(ARDUINO) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) + { + return SensorCommon::begin(i2c_dev_bus_handle, addr); + } +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) + { + return SensorCommon::begin(port_num, addr, sda, scl); + } +#endif //ESP_IDF_VERSION +#endif + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) + { + return SensorCommon::begin(addr, readRegCallback, writeRegCallback); + } + + void reset() + { + if (__rst != SENSOR_PIN_NONE) { + this->setGpioLevel(__rst, LOW); + delay(3); + this->setGpioLevel(__rst, HIGH); + delay(5); + } + } + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point = 1) + { + __CHSC5816_PointReg touch; + + // CHSC5816_REG_POINT + uint8_t write_buffer[] = {0x20, 0x00, 0x00, 0x2c}; + writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), touch.data, 8); + if (touch.rp.status == 0xFF && touch.rp.fingerNumber == 0) { + return 0; + } + if (x_array) { + *x_array = (unsigned int)(touch.rp.x_h4 << 8) | touch.rp.x_l8; + } + if (y_array) { + *y_array = (unsigned int)(touch.rp.y_h4 << 8) | touch.rp.y_l8; + } + + updateXY(1, x_array, y_array); + + return 1; + } + + bool isPressed() + { + if (__irq != SENSOR_PIN_NONE) { + return this->getGpioLevel(__irq) == LOW; + } + return getPoint(NULL, NULL); + } + + const char *getModelName() + { + return "CHSC5816"; + } + + //2uA + void sleep() + { + uint8_t write_buffer[] = { + 0x20, 0x00, 0x00, 0x00, // CHSC5816_REG_CMD_BUFF + 0xF8, 0x16, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE9 + }; + writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer)); + } + + void wakeup() + { + reset(); + } + + void idle() + { + uint8_t write_buffer[] = { + 0x20, 0x00, 0x00, 0x00, // CHSC5816_REG_CMD_BUFF + 0x20, 0x16, 0x02, 0x00, 0xDB, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE9 + }; + writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer)); + } + + uint8_t getSupportTouchPoint() + { + return 1; + } + + bool getResolution(int16_t *x, int16_t *y) + { + /* + uint8_t buffer[16] = { + 0xFC, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xe9 + }; + writeRegister(CHSC5816_REG_CMD_BUFF, buffer, 16); + memset(buffer, 0, 16); + readRegister(CHSC5816_REG_CMD_BUFF, buffer, 16); + for (int i = 0; i < 16; ++i) { + Serial.print(buffer[i], HEX); + Serial.print(","); + } + Serial.println(); + return true; + */ + return false; + } + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) + { + SensorCommon::setGpioModeCallback(mode_cb); + SensorCommon::setGpioWriteCallback(write_cb); + SensorCommon::setGpioReadCallback(read_cb); + } + +private: + bool checkOnline() + { + CHSC5816_Header_t tmp; + memset(&tmp, 0, sizeof(CHSC5816_Header_t)); + memset(&__header, 0, sizeof(CHSC5816_Header_t)); + + // CHSC5816_REG_BOOT_STATE 0x20000018 + uint8_t write_buffer[] = {0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00}; + + if (writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer)) == DEV_WIRE_ERR) { + log_e("writeBuffer clean boot state failed!\n"); + return false; + } + + reset(); + + for (int i = 0; i < 10; ++i) { + delay(10); + // CHSC5816_REG_IMG_HEAD 0x20000014 + uint8_t write_buffer[] = {0x20, 0x00, 0x00, 0x14}; + if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), + (uint8_t *)&__header, + sizeof(CHSC5816_Header_t)) == DEV_WIRE_ERR) { + printf("readRegister 1 failed!\n"); + return false; + } + + if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), + (uint8_t *)&tmp, + sizeof(CHSC5816_Header_t)) == DEV_WIRE_ERR) { + printf("readRegister 2 failed!\n"); + return false; + } + + if (memcmp(&tmp, &__header, sizeof(CHSC5816_Header_t)) != 0 ) { + continue; + } + if (__header.sig == CHSC5816_SIG_VALUE) { + return true; + } + } + return false; + } + + bool initImpl() + { + + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, INPUT); + } + + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + } + + reset(); + + if (checkOnline()) { + reset(); + return true; + } + + return false; + } + + int getReadMaskImpl() + { + return -1; + } + + +protected: + CHSC5816_Header_t __header; +}; + + + diff --git a/components/SensorLib/src/TouchDrvCST92xx.cpp b/components/SensorLib/src/TouchDrvCST92xx.cpp new file mode 100644 index 0000000..72eb5b8 --- /dev/null +++ b/components/SensorLib/src/TouchDrvCST92xx.cpp @@ -0,0 +1,1185 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2024 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvCST92xx.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2024-07-07 + */ +#include "TouchDrvCST92xx.h" + +#if defined(ARDUINO) +TouchDrvCST92xx::TouchDrvCST92xx(): + __center_btn_x(0), + __center_btn_y(0), + __jump_check(false) +{ +} + +bool TouchDrvCST92xx::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl) +{ + return SensorCommon::begin(wire, address, sda, scl); +} + +#elif defined(ESP_PLATFORM) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) +bool TouchDrvCST92xx::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) +{ + return SensorCommon::begin(i2c_dev_bus_handle, addr); +} +#else +bool TouchDrvCST92xx::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) +{ + return SensorCommon::begin(port_num, addr, sda, scl); +} + +#endif //ESP_IDF_VERSION +#endif //ARDUINO + +bool TouchDrvCST92xx::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) +{ + return SensorCommon::begin(addr, readRegCallback, writeRegCallback); +} + +void TouchDrvCST92xx::reset() +{ + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + this->setGpioLevel(__rst, LOW); + delay(10); + this->setGpioLevel(__rst, HIGH); + } +} + +void TouchDrvCST92xx::parseFingerData(uint8_t *data, cst9xx_point_t *point) +{ + const uint8_t id = (data[0] >> 4); + const uint8_t pressed = (data[0] & 0x0F); + const uint16_t x = ((data[1] << 4) | (data[3] >> 4)); + const uint16_t y = ((data[2] << 4) | (data[3] & 0x0F)); + + if (pressed == 0x06 && id < CST92XX_MAX_FINGER_NUM) { + point->finger_id = id; + point->evt = pressed; + point->x = x; + point->y = y; + } +} + +uint8_t TouchDrvCST92xx::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point) +{ + int16_t res = 0; + uint8_t point = 0; + uint8_t read_buffer[CST92XX_MAX_FINGER_NUM * 5 + 5] = {0}; + uint8_t write_buffer[4] = {0}; + cst9xx_point_t point_info[CST92XX_MAX_FINGER_NUM]; + + if (!x_array || !y_array || !get_point) { + return 0; + } + memset(&point_info, 0, sizeof(point_info)); + + //Write read command + write_buffer[0] = highByte(CST92XX_READ_COMMAND); + write_buffer[1] = lowByte(CST92XX_READ_COMMAND); + res = writeThenRead(write_buffer, 2, read_buffer, sizeof(read_buffer)); + if (res != DEV_WIRE_NONE) { + log_e("Write read command error"); + return 0; + } + // Write read ack + write_buffer[0] = highByte(CST92XX_READ_COMMAND); + write_buffer[1] = lowByte(CST92XX_READ_COMMAND); + write_buffer[2] = CST92XX_ACK; + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + log_e("Write read ack error"); + return 0; + } + + // check device ack + if (read_buffer[6] != CST92XX_ACK) { + // log_e("Check device ack error , response code is 0x%x", read_buffer[6]); + return 0; + } + + // palm + gesture + if (CST92XX_GET_GESTURE(read_buffer[4])) { + log_d("read point read_buffer[4]=0x%x.\n", read_buffer[4]); + if ((read_buffer[4] >> 7) == 0x01) { + if (__homeButtonCb) { + __homeButtonCb(__userData); + } + // bool palm = true; + } else if (read_buffer[4] >> 4) { + //uint8_t gesture = read_buffer[4] >> 4; + } + } + + point = CST92XX_GET_FINGER_NUM(read_buffer[5]); + if (point > CST92XX_MAX_FINGER_NUM || point == 0) { + return 0; + } + + /* + // button + if ((read_buffer[5] & 0x80) == 0x80) { + uint8_t *data = read_buffer + point * 5; + if (point > 0) { + data += 2; + } + uint8_t key_id = data[0]; + uint8_t key_status = data[1]; + } + */ + + for (uint8_t i = 0; i < point; ++i) { + uint8_t *data = read_buffer + (i * 5) + (i == 0 ? 0 : 2); + parseFingerData(data, &point_info[i]); + x_array[i] = point_info[i].x; + y_array[i] = point_info[i].y; + log_d("Finger %d: x %d, y %d, id %d, event 0x%x.", i, point_info[i].x, point_info[i].y, point_info[i].finger_id, point_info[i].evt); + } + + if (point_info[0].evt == 0x00) { + log_d("Release finger ...."); + return 0; + } + + updateXY(point, x_array, y_array); + + return point; +} + +// CST9217/CST9217 touch level is once per second, not continuous low level +bool TouchDrvCST92xx::isPressed() +{ + if (__irq != SENSOR_PIN_NONE) { + return this->getGpioLevel(__irq) == LOW; + } + return getPoint(NULL, NULL, 1); +} + + +const char *TouchDrvCST92xx::getModelName() +{ + switch (__chipID) { + case CST9220_CHIP_ID: + return "CST9220"; + case CST9217_CHIP_ID: + return "CST9217"; + default: + break; + } + return "UNKNOW"; +} + +void TouchDrvCST92xx::sleep() +{ + + uint8_t write_buffer[2] = {0}; + // Enter command mode + setMode(CST92_MODE_DEBUG_INFO); + //Send sleep command + write_buffer[0] = highByte(CST92XX_REG_SLEEP_MODE); + write_buffer[1] = lowByte(CST92XX_REG_SLEEP_MODE); + writeBuffer(write_buffer, 2); +#ifdef ESP32 + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, OPEN_DRAIN); + } + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OPEN_DRAIN); + } +#endif +} + +void TouchDrvCST92xx::wakeup() +{ + reset(); +} + +void TouchDrvCST92xx::idle() +{ +} + +uint8_t TouchDrvCST92xx::getSupportTouchPoint() +{ + return CST92XX_MAX_FINGER_NUM; +} + +bool TouchDrvCST92xx::getResolution(int16_t *x, int16_t *y) +{ + return false; +} + +void TouchDrvCST92xx::setCoverScreenCallback(home_button_callback_t cb, void *user_data) +{ + __homeButtonCb = cb; + __userData = user_data; +} + +/** + * @note Only when the device address is equal to 0X5A can it be accessed. If the device address is not equal to 0X5A, it can only be accessed after reset. + */ +uint32_t TouchDrvCST92xx::readWordFromMem(uint8_t type, uint16_t mem_addr) +{ + int res = 0; + uint8_t write_buffer[4] = {0}; + uint8_t read_buffer[4] = {0}; + + uint8_t slave_address = __addr; + + __addr = CST92XX_BOOT_ADDRESS; + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x10; + write_buffer[2] = type; + + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + log_e("Write 0A010 failed"); + goto ERROR; + } + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x0C; + write_buffer[2] = mem_addr; + write_buffer[3] = mem_addr >> 8; + + res = writeBuffer(write_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("Write 0A00C failed"); + goto ERROR; + } + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x04; + write_buffer[2] = 0xE4; + + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + log_e("Write 0A004E4 failed"); + goto ERROR; + } + + for (uint8_t t = 0;; t++) { + if (t >= 100) { + goto ERROR; + } + write_buffer[0] = 0xA0; + write_buffer[1] = 0x04; + res = writeThenRead(write_buffer, 2, read_buffer, 1); + if (res != DEV_WIRE_NONE) { + log_e("Write 0A004 failed"); + goto ERROR; + } + + if (read_buffer[0] == 0x00) { + break; + } + } + write_buffer[0] = 0xA0; + write_buffer[1] = 0x18; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + + __addr = slave_address; + + return ((uint32_t)(read_buffer[0])) | + (((uint32_t)(read_buffer[1])) << 8) | + (((uint32_t)(read_buffer[2])) << 16) | + (((uint32_t)(read_buffer[3])) << 24); +ERROR: + __addr = slave_address; + return 0; +} + +uint32_t TouchDrvCST92xx::getChipType() +{ + // uint32_t chip_id = 0; + uint32_t chip_type = 0; + for (uint8_t retry = 3; retry > 0; retry--) { + chip_type = readWordFromMem(1, 0x077C); + // chip_id = readWordFromMem(0, 0x7FC0); + if ((chip_type >> 16) == 0xCACA) { + chip_type &= 0xffff; + break; + } + delay(10); + } + log_d("Chip Type: 0x%04lx", chip_type); + // log_d("Module_id: 0x%04x", chip_id); + if ((chip_type != CST9220_CHIP_ID) && (chip_type != CST9217_CHIP_ID)) { + log_e("Chip type error 0x%04lx", chip_type); + return 0; + } + return chip_type; +} + +uint32_t TouchDrvCST92xx::get_u32_from_ptr(const void *ptr) +{ + return *reinterpret_cast(ptr); +} + + +/** + * @note Only when the device address is equal to 0X5A can it be accessed. If the device address is not equal to 0X5A, it can only be accessed after reset. + */ +bool TouchDrvCST92xx::enterBootloader(void) +{ + int16_t res = 0; + uint8_t check_cnt = 0; + uint8_t write_buffer[4] = {0}; + uint8_t read_buffer[4] = {0}; + + uint8_t slave_address = __addr; + + __addr = CST92XX_BOOT_ADDRESS; + + for (uint8_t i = 10;; i += 2) { + + if (i > 20) { + log_e("Enter boot:try timeout"); + goto ERROR; + } + + reset(); + + delay(i); + + for (check_cnt = 0; check_cnt < 5; check_cnt++) { + write_buffer[0] = 0xA0; + write_buffer[1] = 0x01; + write_buffer[2] = 0xAA; + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + delay(2); + continue; + } + delay(2); + write_buffer[0] = 0xA0; + write_buffer[1] = 0x02; + res = writeThenRead(write_buffer, 2, read_buffer, 2); + if (res != DEV_WIRE_NONE) { + delay(2); + continue; + } + if ((read_buffer[0] == 0x55) && (read_buffer[1] == 0xB0)) { + break; + } + } + if ((read_buffer[0] == 0x55) && (read_buffer[1] == 0xB0)) { + break; + } + } + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x01; + write_buffer[2] = 0x00; + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + log_e("Enter boot exit error"); + goto ERROR; + } + __addr = slave_address; + log_d("Enter boot mode success!"); + return true; + +ERROR: + __addr = slave_address; + return false; + +} + + +bool TouchDrvCST92xx::setMode(uint8_t mode) +{ + uint8_t read_buffer[4] = {0}; + uint8_t write_buffer[4] = {0}; + uint8_t i = 0; + int16_t res = -1; + uint8_t mode_cmd = 0; + + for (i = 0; i < 3; i++) { + write_buffer[0] = 0xD1; + write_buffer[1] = 0x1E; + res = writeBuffer(write_buffer, 2); + if (res != DEV_WIRE_NONE) { + delay(200); + continue; + } + write_buffer[0] = 0xD1; + write_buffer[1] = 0x1E; + res = writeBuffer(write_buffer, 2); + if (res != DEV_WIRE_NONE) { + delay(200); + continue; + } + write_buffer[0] = 0x00; + write_buffer[1] = 0x02; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + delay(200); + continue; + } + if (read_buffer[1] == 0x1E) + break; + } + + switch (mode) { + case CST92_MODE_NORMAL: { + log_d("set_work_mode: ENUM_MODE_NORMAL"); + write_buffer[0] = highByte(CST92XX_REG_NORMAL_MODE); + write_buffer[1] = lowByte(CST92XX_REG_NORMAL_MODE); + break; + } + case CST92_MODE_DEBUG_DIFF: { + log_d("set_work_mode: ENUM_MODE_DEBUG_DIFF"); + write_buffer[0] = highByte(CST92XX_REG_DIFF_MODE); + write_buffer[1] = lowByte(CST92XX_REG_DIFF_MODE); + break; + } + case CST92_MODE_DEBUG_RAWDATA: { + log_d("set_work_mode: ENUM_MODE_DEBUG_RAWDATA"); + write_buffer[0] = highByte(CST92XX_REG_RAW_MODE); + write_buffer[1] = lowByte(CST92XX_REG_RAW_MODE); + break; + } + case CST92_MODE_DEBUG_INFO: { + log_d("set_work_mode: ENUM_MODE_DEBUG_INFO"); + write_buffer[0] = highByte(CST92XX_REG_DEBUG_MODE); + write_buffer[1] = lowByte(CST92XX_REG_DEBUG_MODE); + break; + } + case CST92_MODE_FACTORY: { + log_d("set_work_mode: ENUM_MODE_FACTORY"); + for (i = 0; i < 10; i++) { + write_buffer[0] = highByte(CST92XX_REG_FACTORY_MODE); + write_buffer[1] = lowByte(CST92XX_REG_FACTORY_MODE); + res = writeBuffer(write_buffer, 2); + if (res != DEV_WIRE_NONE) { + delay(1); + continue; + } + delay(10); + write_buffer[0] = 0x00; + write_buffer[1] = 0x09; + res = writeThenRead(write_buffer, 2, read_buffer, 1); + if (res != DEV_WIRE_NONE) { + delay(1); + continue; + } + if (read_buffer[0] == 0x14) + break; + } + write_buffer[0] = 0xD1; + write_buffer[1] = 0x19; + res = writeBuffer(write_buffer, 2); + if (res != DEV_WIRE_NONE) { + log_e("set_work_mode 0xD119 error"); + return false; + } + break; + } + case CST92_MODE_FACTORY_LOWDRV: { + log_d("set_work_mode: ENUM_MODE_FACTORY_LOWDRV"); + write_buffer[0] = 0xD1; + write_buffer[1] = 0x11; + break; + } + case CST92_MODE_FACTORY_HIGHDRV: { + log_d("set_work_mode: ENUM_MODE_FACTORY_HIGHDRV"); + write_buffer[0] = 0xD1; + write_buffer[1] = 0x10; + break; + } + case CST92_MODE_FACTORY_SHORT: { + log_d("set_work_mode: ENUM_MODE_FACTORY_SHORT"); + write_buffer[0] = 0xD1; + write_buffer[1] = 0x12; + break; + } + case 0XFE: { + log_d("set_work_mode: 0xFE"); + write_buffer[0] = 0xD1; + write_buffer[1] = 0x1F; + break; + } + default: { + log_d("set_work_mode: NA return"); + return 0; + } + } + mode_cmd = write_buffer[1]; + res = writeBuffer(write_buffer, 2); + if (res != DEV_WIRE_NONE) { + log_e("set_work_mode 0x%x 0x%x error", write_buffer[0], write_buffer[1]); + return false; + } + write_buffer[0] = 0x00; + write_buffer[1] = 0x02; + res = writeThenRead(write_buffer, 2, read_buffer, 2); + if (res != DEV_WIRE_NONE) { + log_e("set_work_mode read 0x0002 failed : 0x%X 0x%X", read_buffer[0], read_buffer[1]); + } + if (mode_cmd != read_buffer[1]) { + log_e("set work mode read 0x0002=0x%x failed", read_buffer[1]); + return false; + } + delay(10); + return true; +} + +#if 0 /*DISABLE UPDATE FIRMWARE*/ + + + +bool TouchDrvCST92xx::getFirmwareInfo(void) +{ + uint8_t read_buffer[4] = {0}; + uint8_t write_buffer[6] = {0}; + uint32_t version = 0; + int16_t res = -1; + int32_t info_checksum = 0; + + setMode(CST92_MODE_DEBUG_INFO); + + delay(1); + write_buffer[0] = 0xD1; + write_buffer[1] = 0x01; + res = writeBuffer(write_buffer, 2); + res |= writeBuffer(write_buffer, 2); + if (res != DEV_WIRE_NONE) { + log_e("write 0xD101 error"); + return false; + } + + // BOOT TIME + CBCB + write_buffer[0] = 0xD1; + write_buffer[1] = 0xFC; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("read 0xD1FC error"); + return false; + } + info_checksum += get_u32_from_ptr(read_buffer); + // d200: 0x55AA55AA + info_checksum += 0x55AA55AA; + // firmware_project_id firmware_ic_type + write_buffer[0] = 0xD2; + write_buffer[1] = 0x04; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("read 0xD204 error"); + return false; + } + info_checksum += get_u32_from_ptr(read_buffer); + uint16_t firmware_project_id = ((uint16_t)write_buffer[1] << 8) + write_buffer[0]; + uint16_t firmware_ic_type = ((uint16_t)write_buffer[3] << 8) + write_buffer[2]; + // firmware_version + write_buffer[0] = 0xD2; + write_buffer[1] = 0x08; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("read 0xD208 error"); + return false; + } + version = get_u32_from_ptr(read_buffer); + info_checksum += version; + uint32_t firmware_version = version; + // firmware_info_checksum + write_buffer[0] = 0xD2; + write_buffer[1] = 0x1c; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("read 0xD21c error"); + return false; + } + if (get_u32_from_ptr(read_buffer) != info_checksum) { + log_e("info_checksum error"); + return false; + } + // firmware_checksum + write_buffer[0] = 0xD2; + write_buffer[1] = 0x0C; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("read 0xD20c error"); + return false; + } + uint32_t firmware_checksum = ((uint32_t)write_buffer[3] << 24) + ((uint32_t)write_buffer[2] << 16) + ((uint32_t)write_buffer[1] << 8) + write_buffer[0]; + // tx_num rx_num key_num + write_buffer[0] = 0xD1; + write_buffer[1] = 0xF4; + res = writeThenRead(write_buffer, 2, read_buffer, 4); + if (res != DEV_WIRE_NONE) { + log_e("read 0xD1F4 error"); + return false; + } + uint32_t tx_num = ((uint16_t)write_buffer[1] << 8) + write_buffer[0]; + uint32_t rx_num = write_buffer[2]; + uint32_t key_num = write_buffer[3]; + // Go back normal mode + setMode(CST92_MODE_NORMAL); + log_d("Chip firmware ic type: 0x%04lx", firmware_ic_type); + log_d("Chip firmware version: 0x%04lx", firmware_version); + log_d("Chip firmware project id: 0x%04lx", firmware_project_id); + log_d("Chip checksum: 0x%04lx", firmware_checksum); + log_d("Chip tx_num: %ld", tx_num); + log_d("Chip rx_num: %ld", rx_num); + log_d("Chip key_num: %ld", key_num); + return 0; +} + +/** + * @note Only when the device address is equal to 0X5A can it be accessed. If the device address is not equal to 0X5A, it can only be accessed after reset. + */ +int16_t TouchDrvCST92xx::eraseMem(void) +{ + int16_t res = 0; + uint8_t write_buffer[4] = {0}; + + uint8_t slave_address = __addr; + + __addr = CST92XX_BOOT_ADDRESS; + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x14; + write_buffer[2] = 0x00; + write_buffer[3] = 0x00; + res = writeBuffer(write_buffer, 4); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + write_buffer[0] = 0xA0; + write_buffer[1] = 0x0C; + write_buffer[2] = 0x80; + write_buffer[3] = 0x7F; + res = writeBuffer(write_buffer, 4); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + write_buffer[0] = 0xA0; + write_buffer[1] = 0x04; + write_buffer[2] = 0xEC; + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + delay(300); + for (uint16_t i = 0;; i += 10) { + if (i >= 1000) { + goto ERROR; + } + delay(10); + write_buffer[0] = 0xA0; + write_buffer[1] = 0x05; + res = writeThenRead(write_buffer, 2, write_buffer, 2); + if (res != DEV_WIRE_NONE) { + delay(10); + continue; + } + if (write_buffer[0] == 0x88) { + break; + } + } + __addr = slave_address; + return 0; +ERROR: + __addr = slave_address; + return -1; +} + +int16_t TouchDrvCST92xx::writeSRAM(uint8_t *buf, uint16_t len) +{ + + uint8_t write_buffer[CST92XX_PROGRAM_PAGE_SIZE + 2] = {0}; + int16_t res = 0; + uint16_t reg = 0xA018; + uint16_t per_len = sizeof(write_buffer) - 2; + + + uint8_t slave_address = __addr; + + __addr = CST92XX_BOOT_ADDRESS; + + while (len > 0) { + uint16_t cur_len = len; + if (cur_len > per_len) { + cur_len = per_len; + } + write_buffer[0] = reg >> 8; + write_buffer[1] = reg; + memcpy(write_buffer + 2, buf, cur_len); + res = writeBuffer(write_buffer, cur_len + 2); + if (res != DEV_WIRE_NONE) { + __addr = slave_address; + return -1; + } + reg += cur_len; + buf += cur_len; + len -= cur_len; + } + __addr = slave_address; + return 0; +} + +int16_t TouchDrvCST92xx::writeMemPage(uint16_t addr, uint8_t *buf, uint16_t len) +{ + int16_t res = 0; + uint8_t write_buffer[4] = {0}; + + + uint8_t slave_address = __addr; + + __addr = CST92XX_BOOT_ADDRESS; + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x0C; + write_buffer[2] = len; + write_buffer[3] = len >> 8; + res = writeBuffer(write_buffer, 4); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + write_buffer[0] = 0xA0; + write_buffer[1] = 0x14; + write_buffer[2] = addr; + write_buffer[3] = addr >> 8; + res = writeBuffer(write_buffer, 4); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + res = writeSRAM(buf, len); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + write_buffer[0] = 0xA0; + write_buffer[1] = 0x04; + write_buffer[2] = 0xEE; + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + for (uint16_t t = 0;; t += 10) { + if (t >= 1000) { + goto ERROR; + } + delay(10); + write_buffer[0] = 0xA0; + write_buffer[1] = 0x05; + res = writeThenRead(write_buffer, 2, write_buffer, 1); + if (res != DEV_WIRE_NONE) { + delay(10); + continue; + } + if (write_buffer[0] == 0x55) { + break; + } + } + __addr = slave_address; + return 0; +ERROR: + __addr = slave_address; + return -1; + +} + + +int16_t TouchDrvCST92xx::getFirmwareAddress(uint8_t data_seq, uint16_t data_len) +{ + if (bin_data.head_data == NULL) { + // GET firmware bin data point + log_e("getFirmwareAddress data NULL or len error return"); + return -1; + } + bin_data.data = (uint8_t *)bin_data.head_data + (data_seq * data_len); + // log_d("getFirmwareAddress data_seq:0x%04x,data_len:0x%04x.data_point:0x%04x",data_seq,data_len,(data_seq*data_len)); + if ((bin_data.data == NULL) || ((data_seq * data_len) > CST92XX_MEM_SIZE)) { + log_e("getFirmwareAddress data NULL or len error return"); + return -1; + } + return 0; +} + +int16_t TouchDrvCST92xx::writeMemAll(void) +{ + uint8_t *data; + uint16_t addr = 0; + uint16_t remain_len = CST92XX_MEM_SIZE; + + while (remain_len > 0) { + uint16_t cur_len = remain_len; + if (cur_len > CST92XX_PROGRAM_PAGE_SIZE) { + cur_len = CST92XX_PROGRAM_PAGE_SIZE; + } + // if write fw 128 bytes every time,need update point + if (getFirmwareAddress(((CST92XX_MEM_SIZE - remain_len) / CST92XX_PROGRAM_PAGE_SIZE), CST92XX_PROGRAM_PAGE_SIZE) < 0) { + log_e("getFirmwareAddress fail"); + return -1; + } + data = bin_data.data; + if (writeMemPage(addr, data, cur_len) < 0) { + return -1; + } + data += cur_len; // update bin point every 128 bytes + addr += cur_len; // update bin point every 128 bytes + remain_len -= cur_len; + } + return 0; +} + +int16_t TouchDrvCST92xx::calculateVerifyChecksum(void) +{ + int16_t res = 0; + uint8_t write_buffer[4] = {0}; + uint32_t checksum = 0; + + uint8_t slave_address = __addr; + + __addr = CST92XX_BOOT_ADDRESS; + + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x03; + write_buffer[2] = 0x00; + res = writeBuffer(write_buffer, 3); + if (res != DEV_WIRE_NONE) { + return -1; + } + for (uint16_t t = 0;; t += 10) { + if (t >= 1000) { + goto ERROR; + } + delay(10); + write_buffer[0] = 0xA0; + write_buffer[1] = 0x00; + res = writeThenRead(write_buffer, 2, write_buffer, 1); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + if (write_buffer[0] == 0x01) { + break; + } + if (write_buffer[0] == 0x02) { + goto ERROR; + } + } + + write_buffer[0] = 0xA0; + write_buffer[1] = 0x08; + res = writeThenRead(write_buffer, 2, write_buffer, 4); + if (res != DEV_WIRE_NONE) { + goto ERROR; + } + + checksum = ((uint32_t)(write_buffer[0])) | + (((uint32_t)(write_buffer[1])) << 8) | + (((uint32_t)(write_buffer[2])) << 16) | + (((uint32_t)(write_buffer[3])) << 24); + + if (checksum != bin_data.checksum) { + goto ERROR; + } + __addr = slave_address; + return 0; +ERROR: + __addr = slave_address; + return -1; + +} + +int16_t TouchDrvCST92xx::upgradeFirmware(void) +{ + int16_t res = 0; + uint8_t retry = 3; + + while (retry--) { + + res = enterBootloader(); + + if (res != DEV_WIRE_NONE) { + log_e("enterBootloader fail.%d", retry); + continue; + } + res = eraseMem(); + if (res != DEV_WIRE_NONE) { + log_e("eraseMem fail.%d", retry); + continue; + } + res = writeMemAll(); + if (res != DEV_WIRE_NONE) { + log_e("writeMemAll fail.%d", retry); + continue; + } + res = calculateVerifyChecksum(); + if (res != DEV_WIRE_NONE) { + log_e("calculateVerifyChecksum fail.%d", retry); + continue; + } else { + break; + } + } + + reset(); + + delay(40); + + if ((retry == 0) && (res)) { + log_e("upgradeFirmware fail exit.%d", retry); + return -1; + } else { + log_d("upgradeFirmware success exit"); + } + + return 0; +} + +uint32_t TouchDrvCST92xx::verifyFirmware(uint8_t *pdat, uint16_t order) +{ + uint32_t sum = 0; + uint16_t data_len = 0; + uint16_t i; + + if (!pdat) { + log_e("pdata error return"); + return 0; + } + data_len = 128; + if (order == 254) + data_len = (128 - 20); + for (i = 0; i < data_len; i += 4) { + sum += get_u32_from_ptr(pdat + i); + } + return sum; +} + +int16_t TouchDrvCST92xx::parseFirmware(void) +{ + uint16_t i; + // int16_t res; + uint32_t sum; + uint8_t *pdat; + + bin_data.checksum = 0; + // 0x7F6C-32620=32k-128-20=checksum + // 0x7F80-32640=32k-128 + sum = 0x55; + for (i = 0; i < 255; i++) { + if (getFirmwareAddress(i, 128) < 0) { + log_e("getFirmwareAddress fail."); + return -1; + } + pdat = bin_data.data; + sum += verifyFirmware(pdat, i); + // log_d("sum checksum data=0x%04x 0x%04x 0x%04x", sum, i,*pdat); + pdat += 128; // update bin point every 128 bytes + if (i == 254) { + pdat -= 20; // 0x7F6C + if (sum != get_u32_from_ptr(pdat)) { + log_e("main checksum data error 0x%04x 0x%04x", sum, get_u32_from_ptr(pdat)); + return -1; + } + sum = 0; + sum += get_u32_from_ptr(pdat - 4); // 0x7F68 + sum += get_u32_from_ptr(pdat - 8); // 0x7F64 + sum += get_u32_from_ptr(pdat - 12); // 0x7F60 + sum += get_u32_from_ptr(pdat - 16); // 0x7F5C + if (sum != get_u32_from_ptr(pdat + 16)) { // 0x7F7C + log_e("info checksum data error 0x%04x 0x%04x", sum, get_u32_from_ptr(pdat + 16)); + return -1; + } + bin_data.ok = true; + bin_data.checksum = get_u32_from_ptr(pdat + 0x7F6C - 0x7F6C); + bin_data.chip_type = (get_u32_from_ptr(pdat + 0x7F64 - 0x7F6C) >> 16); + bin_data.version = get_u32_from_ptr(pdat + 0x7F68 - 0x7F6C); + bin_data.project_id = (get_u32_from_ptr(pdat + 0x7F64 - 0x7F6C) & 0x0000FFFF); + } + } + log_d("bin_data.ok: 0x%x", bin_data.ok); + log_d("bin_data.checksum: 0x%04x", bin_data.checksum); + log_d("bin_data.version: 0x%04x", bin_data.version); + log_d("bin_data.project_id: 0x%04x", bin_data.project_id); + log_d("bin_data.chip_type: 0x%04x", bin_data.chip_type); + + return 0; +} + +int16_t TouchDrvCST92xx::upgradeFirmwareJudge(void) +{ + + if (!bin_data.ok) { + log_e("bin_data.ok %d is not ok.", bin_data.ok); + return -1; + } + if (chipType != bin_data.chip_type) { + log_e("chip type != bin data chip type"); + return -1; + } + if (IC_firmware.firmware_info_ok == 0) { + log_d("IC_firmware.firmware_info_ok error,need force update."); + return 0; + } else { + if (IC_firmware.firmware_project_id != bin_data.project_id) { + log_e("firmware_project_id != bin_data.firmware_project_id,no need update"); + return -1; + } + if (IC_firmware.firmware_checksum == bin_data.checksum) { + log_e("firmware_checksum == bin_data.checksum,no need update."); + return -1; + } else { + if (IC_firmware.firmware_version <= bin_data.version) { + log_d("firmware_version is lower than bin_data.version,need update"); + return 0; + } else { + log_e("firmware_version is higher,no need update"); + } + } + } + return -1; +} + + +int16_t TouchDrvCST92xx::updateFirmware(void) +{ + uint8_t need_upgrade = 0; + int16_t res = -1; + bin_data.head_data = (uint8_t *)cst92xx_firmware; + + res = parseFirmware(); + if (res < 0) { + log_e("parseFirmware fail."); + goto END_UPGRADE; + } + res = upgradeFirmwareJudge(); + if (res != DEV_WIRE_NONE) { + log_d("upgradeFirmwareJudge return,no need update fw."); + goto END_UPGRADE; + } else { + need_upgrade = 1; + } + log_d("need_upgrade=%d, firmware_version=0x%04X.", need_upgrade, bin_data.version); + if (need_upgrade) { + res = upgradeFirmware(); + if (res != DEV_WIRE_NONE) { + log_e("upgradeFirmware failed"); + goto END_UPGRADE; + } + log_d("upgradeFirmware OK done."); + reset(); + delay(40); + if (!getFirmwareInfo()) { + log_e("get_firmware_info failed"); + reset(); + } + } + return 0; + +END_UPGRADE: + reset(); + return -1; +} + +#endif /*DISABLE UPDATE FIRMWARE*/ + +void TouchDrvCST92xx::jumpCheck() +{ + __jump_check = true; +} + +void TouchDrvCST92xx::setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) +{ + SensorCommon::setGpioModeCallback(mode_cb); + SensorCommon::setGpioWriteCallback(write_cb); + SensorCommon::setGpioReadCallback(read_cb); +} + +bool TouchDrvCST92xx::initImpl() +{ + int retry = 5; + + if (!__jump_check) { + while (retry > 0) { + if (enterBootloader()) { + break; + } + retry--; + delay(1000); + } + if (0 == retry) { + log_e("Enter boot loader mode failed!"); + return false; + } + + chipType = getChipType(); + + log_d("Chip ID:0x%x", chipType); + + } else { + + log_d("Jump check setting default IC type : CST9217"); + // Jump check setting default IC type + chipType = CST9217_CHIP_ID; + + } + + reset(); + + if(__jump_check && __addr != CST92XX_BOOT_ADDRESS){ + delay(55); + } + + if (!this->probe()) { + log_e("device is not online"); + return false; + } + + if (chipType != CST9220_CHIP_ID && chipType != CST9217_CHIP_ID) { + return false; + } + + __chipID = chipType; + + log_d("Touch type:%s", getModelName()); + + return true; +} + +int TouchDrvCST92xx::getReadMaskImpl() +{ + return -1; +} + + + + + + + + diff --git a/components/SensorLib/src/TouchDrvCST92xx.h b/components/SensorLib/src/TouchDrvCST92xx.h new file mode 100644 index 0000000..00d2100 --- /dev/null +++ b/components/SensorLib/src/TouchDrvCST92xx.h @@ -0,0 +1,181 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvCST92xx.h + * @author Lewis He (lewishe@outlook.com) + * @date 2024-07-07 + */ +#pragma once + +#include "TouchDrvInterface.hpp" +#include "SensorCommon.tpp" +#include "SensorLib.h" +#include "REG/CST9xxConstants.h" + + +enum CST92_RunMode { + CST92_MODE_NORMAL = (0x00), + CST92_MODE_LOW_POWER = (0X01), + CST92_MODE_DEEP_SLEEP = (0X02), + CST92_MODE_WAKEUP = (0x03), + CST92_MODE_DEBUG_DIFF = (0x04), + CST92_MODE_DEBUG_RAWDATA = (0X05), + CST92_MODE_FACTORY = (0x06), + CST92_MODE_DEBUG_INFO = (0x07), + CST92_MODE_UPDATE_FW = (0x08), + CST92_MODE_FACTORY_HIGHDRV = (0x10), + CST92_MODE_FACTORY_LOWDRV = (0x11), + CST92_MODE_FACTORY_SHORT = (0x12), + CST92_MODE_LPSCAN = (0x13), +}; + + +class TouchDrvCST92xx : public TouchDrvInterface, + public SensorCommon +{ + friend class SensorCommon; + +public: + +#if defined(ARDUINO) + TouchDrvCST92xx(); + + bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl); + +#elif defined(ESP_PLATFORM) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr); +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl); +#endif //ESP_IDF_VERSION +#endif + + void jumpCheck(); + + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback); + + + void reset(); + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point); + + bool isPressed(); + + const char *getModelName(); + + void sleep(); + + void wakeup(); + + void idle(); + + + uint8_t getSupportTouchPoint(); + + bool getResolution(int16_t *x, int16_t *y); + + void setCoverScreenCallback(home_button_callback_t cb, void *user_data = NULL); + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb); + + + + + +private: + + typedef struct { + uint8_t finger_id; + uint8_t evt; + uint16_t x; + uint16_t y; + } cst9xx_point_t; + + bool setMode(uint8_t mode); + bool enterBootloader(); + + uint32_t readWordFromMem(uint8_t type, uint16_t mem_addr); + void parseFingerData(uint8_t *data, cst9xx_point_t *point); + uint32_t get_u32_from_ptr(const void *ptr); + + +#if 0 /*DISABLE UPDATE FIRMWARE*/ + + struct { + bool firmware_info_ok; + uint32_t firmware_ic_type; + uint32_t firmware_version; + uint32_t firmware_checksum; + uint32_t firmware_project_id; + uint8_t tx_num; + uint8_t rx_num; + uint8_t key_num; + } IC_firmware; + + struct { + bool ok; + uint8_t *head_data; + uint8_t *data; + uint32_t checksum; + uint32_t version; + uint32_t project_id; + uint32_t chip_type; + } bin_data; + + bool getFirmwareInfo(void); + int16_t eraseMem(void); + int16_t writeSRAM(uint8_t *buf, uint16_t len); + int16_t writeMemPage(uint16_t addr, uint8_t *buf, uint16_t len) ; + int16_t writeMemAll(void) ; + int16_t calculateVerifyChecksum(void) ; + int16_t upgradeFirmware(void); + uint32_t verifyFirmware(uint8_t *pdata, uint16_t order); + int16_t parseFirmware(void); + int16_t upgradeFirmwareJudge(void); + int16_t getFirmwareAddress(uint8_t data_seq, uint16_t data_len) ; + int16_t updateFirmware(void); +#endif + + + uint32_t getChipType(); + bool initImpl(); + int getReadMaskImpl(); + + uint16_t chipType; + +protected: + int16_t __center_btn_x; + int16_t __center_btn_y; + bool __jump_check; +}; + + + + + + + diff --git a/components/SensorLib/src/TouchDrvCSTXXX.hpp b/components/SensorLib/src/TouchDrvCSTXXX.hpp new file mode 100644 index 0000000..bb54164 --- /dev/null +++ b/components/SensorLib/src/TouchDrvCSTXXX.hpp @@ -0,0 +1,295 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvCSTXXX.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-24 + * @date last 2023-10-05 + * + */ +#pragma once + +#include "REG/CSTxxxConstants.h" +#include "touch/TouchClassCST226.h" +#include "touch/TouchClassCST816.h" +#include "SensorCommon.tpp" + +class TouchDrvCSTXXX : public TouchDrvInterface +{ +public: + TouchDrvCSTXXX(): drv(NULL) + { + } + + ~TouchDrvCSTXXX() + { + if (drv) { + delete drv; + drv = NULL; + } + } + +#if defined(ARDUINO) + bool begin(PLATFORM_WIRE_TYPE &wire, + uint8_t address, + int sda, + int scl + ) + { + if (!drv) { + drv = new TouchClassCST816(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(wire, address, sda, scl)) { + delete drv; + drv = NULL; + } + } + + if (!drv) { + drv = new TouchClassCST226(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(wire, address, sda, scl)) { + delete drv; + drv = NULL; + } + } + + return drv != NULL; + } +#elif defined(ESP_PLATFORM) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) + { + if (!drv) { + drv = new TouchClassCST816(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(i2c_dev_bus_handle, addr)) { + delete drv; + drv = NULL; + } + } + + if (!drv) { + drv = new TouchClassCST226(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(i2c_dev_bus_handle, addr)) { + delete drv; + drv = NULL; + } + } + return drv != NULL; + } +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) + { + if (!drv) { + drv = new TouchClassCST816(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(port_num, addr, sda, scl)) { + delete drv; + drv = NULL; + } + } + + if (!drv) { + drv = new TouchClassCST226(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(port_num, addr, sda, scl)) { + delete drv; + drv = NULL; + } + } + return drv != NULL; + } +#endif //ESP_IDF_VERSION +#endif//ARDUINO + + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) + { + __set_gpio_level = write_cb; + __get_gpio_level = read_cb; + __set_gpio_mode = mode_cb; + } + + bool begin(uint8_t address, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) + { + if (!drv) { + drv = new TouchClassCST816(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(address, readRegCallback, writeRegCallback)) { + delete drv; + drv = NULL; + } + } + + if (!drv) { + drv = new TouchClassCST226(); + drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level); + drv->setPins(__rst, __irq); + if (!drv->begin(address, readRegCallback, writeRegCallback)) { + delete drv; + drv = NULL; + } + } + + return drv != NULL; + } + + + void reset() + { + if (!drv)return; + drv->reset(); + } + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point = 1) + { + if (!drv)return 0; + return drv->getPoint(x_array, y_array, get_point); + } + + bool isPressed() + { + if (!drv)return false; + return drv->isPressed(); + } + + const char *getModelName() + { + if (!drv)return "NULL"; + return drv->getModelName(); + } + + void sleep() + { + if (!drv)return; + drv->sleep(); + } + + void wakeup() + { + if (!drv)return; + drv->reset(); + } + + void idle() + { + if (!drv)return; + drv->idle(); + } + + uint8_t getSupportTouchPoint() + { + if (!drv)return 0; + return drv->getSupportTouchPoint(); + } + + bool getResolution(int16_t *x, int16_t *y) + { + if (!drv)return false; + return drv->getResolution(x, y); + } + + void setCenterButtonCoordinate(uint16_t x, uint16_t y) + { + if (!drv)return ; + const char *model = drv->getModelName(); + if (strncmp(model, "CST8", 3) == 0) { + TouchClassCST816 *pT = static_cast(drv); + pT->setCenterButtonCoordinate(x, y); + } + } + + void setHomeButtonCallback(home_button_callback_t callback, void *user_data = NULL) + { + if (!drv)return ; + const char *model = drv->getModelName(); + if (strncmp(model, "CST8", 3) == 0) { + TouchClassCST816 *pT = static_cast(drv); + pT->setHomeButtonCallback(callback, user_data); + // pT->setCenterButtonCoordinate(600, 120); // Only suitable for AMOLED 1.91 inch + + } if (strncmp(model, "CST2", 3) == 0) { + TouchClassCST226 *pT = static_cast(drv); + pT->setHomeButtonCallback(callback, user_data); + } + } + + void disableAutoSleep() + { + if (!drv)return ; + const char *model = drv->getModelName(); + if (strncmp(model, "CST8", 3) == 0) { + TouchClassCST816 *pT = static_cast(drv); + pT->disableAutoSleep(); + } + } + + void enableAutoSleep() + { + if (!drv)return ; + const char *model = drv->getModelName(); + if (strncmp(model, "CST8", 3) == 0) { + TouchClassCST816 *pT = static_cast(drv); + pT->enableAutoSleep(); + } + } + + void setSwapXY(bool swap) + { + if (!drv)return ; + drv->setSwapXY(swap); + } + + void setMirrorXY(bool mirrorX, bool mirrorY) + { + if (!drv)return ; + drv->setMirrorXY(mirrorX, mirrorY); + } + + void setMaxCoordinates(uint16_t x, uint16_t y) + { + if (!drv)return ; + drv->setMaxCoordinates(x, y); + } + +private: + gpio_write_fptr_t __set_gpio_level = NULL; + gpio_read_fptr_t __get_gpio_level = NULL; + gpio_mode_fptr_t __set_gpio_mode = NULL; + TouchDrvInterface *drv = NULL; +}; + + + diff --git a/components/SensorLib/src/TouchDrvFT6X36.hpp b/components/SensorLib/src/TouchDrvFT6X36.hpp new file mode 100644 index 0000000..866bd44 --- /dev/null +++ b/components/SensorLib/src/TouchDrvFT6X36.hpp @@ -0,0 +1,426 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvFT6X36.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-01 + * + */ +#pragma once + +#include "REG/FT6X36Constants.h" +#include "TouchDrvInterface.hpp" +#include "SensorCommon.tpp" + +class TouchDrvFT6X36 : + public TouchDrvInterface, + public SensorCommon +{ + friend class SensorCommon; +public: + + + enum GesTrue { + NO_GESTURE, + MOVE_UP, + MOVE_LEFT, + MOVE_DOWN, + MOVE_RIGHT, + ZOOM_IN, + ZOOM_OUT, + } ; + + enum EventFlag { + EVENT_PUT_DOWN, + EVENT_PUT_UP, + EVENT_CONTACT, + EVENT_NONE, + } ; + + enum PowerMode { + PMODE_ACTIVE = 0, // ~4mA + PMODE_MONITOR = 1, // ~3mA + PMODE_DEEPSLEEP = 3, // ~100uA The reset pin must be pulled down to wake up + } ; + + EventFlag event; + +#if defined(ARDUINO) + TouchDrvFT6X36(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = FT6X36_SLAVE_ADDRESS) + { + __wire = &w; + __sda = sda; + __scl = scl; + __addr = addr; + } +#endif + + TouchDrvFT6X36() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __addr = FT6X36_SLAVE_ADDRESS; + } + + ~TouchDrvFT6X36() + { + deinit(); + } + +#if defined(ARDUINO) + + bool begin(PLATFORM_WIRE_TYPE &w, + uint8_t addr = FT6X36_SLAVE_ADDRESS, + int sda = DEFAULT_SDA, + int scl = DEFAULT_SCL) + { + return SensorCommon::begin(w, addr, sda, scl); + } + +#elif defined(ESP_PLATFORM) && !defined(ARDUINO) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) + { + return SensorCommon::begin(i2c_dev_bus_handle, addr); + } +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) + { + return SensorCommon::begin(port_num, addr, sda, scl); + } +#endif //ESP_IDF_VERSION + +#endif + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) + { + return SensorCommon::begin(addr, readRegCallback, writeRegCallback); + } + + + void deinit() + { + // end(); + } + + uint8_t getDeviceMode(void) + { + return readRegister(FT6X36_REG_MODE) & 0x03; + } + + // Obtaining gestures depends on whether the built-in firmware of the chip has this function + uint8_t getGesture() + { + int val = readRegister(FT6X36_REG_GEST); + switch (val) { + case 0x10: + return MOVE_UP; + case 0x14: + return MOVE_RIGHT; + case 0x18: + return MOVE_DOWN; + case 0x1C: + return MOVE_LEFT; + case 0x48: + return ZOOM_IN; + case 0x49: + return ZOOM_OUT; + default: + break; + } + return NO_GESTURE; + } + + void setThreshold(uint8_t value) + { + writeRegister(FT6X36_REG_THRESHOLD, value); + } + + uint8_t getThreshold(void) + { + return readRegister(FT6X36_REG_THRESHOLD); + } + + uint8_t getMonitorTime(void) + { + return readRegister(FT6X36_REG_MONITOR_TIME); + } + + void setMonitorTime(uint8_t sec) + { + writeRegister(FT6X36_REG_MONITOR_TIME, sec); + } + + // Calibration useless actually, + // any value set will not be valid, + // depending on the internal firmware of the chip. + /* + void enableAutoCalibration(void) + { + writeRegister(FT6X36_REG_AUTO_CLB_MODE, 0x00); + } + + void disableAutoCalibration(void) + { + writeRegister(FT6X36_REG_AUTO_CLB_MODE, 0xFF); + } + */ + + uint16_t getLibraryVersion() + { + uint8_t buffer[2]; + readRegister(FT6X36_REG_LIB_VERSION_H, buffer, 2); + return (buffer[0] << 8) | buffer[1]; + } + + // The interrupt is triggered only if a touch is detected during the scan cycle + void interruptPolling(void) + { + //datasheet this bit is 0,Actually, it's wrong + writeRegister(FT6X36_REG_INT_STATUS, 1); + } + + // Triggers an interrupt whenever a touch is detected + void interruptTrigger(void) + { + //datasheet this bit is 1,Actually, it's wrong + writeRegister(FT6X36_REG_INT_STATUS, 0); + } + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t size = 1) + { + uint8_t buffer[16]; + + if (!x_array || !y_array || !size) + return 0; + + if (readRegister(FT6X36_REG_MODE, buffer, 16) == DEV_WIRE_ERR) { + return 0; + } + + // uint8_t mode = buffer[0]; + //REG 0x01 + // uint8_t gesture = buffer[1]; + //REG 0x02 + uint8_t point = buffer[2] & 0x0F; + if (point == 0 || point == 0x0F) { + return 0; + } + + //REG 0x03 ~ 0x04 + // uint8_t eventFlag = (buffer[3] & 0xC0) >> 6; + uint16_t posX = ((buffer[3] & 0x0F) << 8) | buffer[4]; + //REG 0x05 ~ 0x06 + uint16_t posY = ((buffer[5] & 0x0F) << 8) | buffer[6] ; + + + x_array[0] = posX; + y_array[0] = posY; + +#ifdef LOG_PORT + LOG_PORT.println("----------------------------------------------------------------------------"); + LOG_PORT.println("Touched Gesture EvenFlag [0]PosX [0]PosY [1]PosX [1]PosY"); + LOG_PORT.print(point); LOG_PORT.print("\t"); + // LOG_PORT.print(gesture); LOG_PORT.print("\t"); + // LOG_PORT.print(eventFlag); LOG_PORT.print("\t"); + LOG_PORT.print(posX); LOG_PORT.print("\t"); + LOG_PORT.print(posY); LOG_PORT.print("\t"); +#endif + + if (point == 2) { + //REG 0x09 ~ 0x0A + posX = ((buffer[9] & 0x0F) << 8) | buffer[10]; + //REG 0x0B ~ 0x0C + posY = ((buffer[11] & 0x0F) << 8) | buffer[12] ; + +#ifdef LOG_PORT + LOG_PORT.print(posX); LOG_PORT.print("\t"); + LOG_PORT.print(posY); LOG_PORT.print("\t"); +#endif + + if (size == 2) { + x_array[1] = posX; + y_array[1] = posY; + } + } +#ifdef LOG_PORT + LOG_PORT.println(); +#endif + updateXY(point, x_array, y_array); + + return point; + } + + bool isPressed() + { + if (__irq != SENSOR_PIN_NONE) { + return this->getGpioLevel(__irq) == LOW; + } + return readRegister(FT6X36_REG_STATUS) & 0x0F; + } + + void setPowerMode(PowerMode mode) + { + writeRegister(FT6X36_REG_POWER_MODE, mode); + } + + void sleep() + { + writeRegister(FT6X36_REG_POWER_MODE, PMODE_DEEPSLEEP); + } + + void wakeup() + { + reset(); + } + + void idle() + { + + } + + uint8_t getSupportTouchPoint() + { + return 1; + } + + uint32_t getChipID(void) + { + return readRegister(FT6X36_REG_CHIP_ID); + } + + uint8_t getVendorID(void) + { + return readRegister(FT6X36_REG_VENDOR1_ID); + } + + uint8_t getErrorCode(void) + { + return readRegister(FT6X36_REG_ERROR_STATUS); + } + + const char *getModelName() + { + switch (__chipID) { + case FT6206_CHIP_ID: return "FT6206"; + case FT6236_CHIP_ID: return "FT6236"; + case FT6236U_CHIP_ID: return "FT6236U"; + case FT3267_CHIP_ID: return "FT3267"; + default: return "UNKNOWN"; + } + } + + + bool getResolution(int16_t *x, int16_t *y) + { + return false; + } + + void reset() + { + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + this->setGpioLevel(__rst, HIGH); + delay(10); + this->setGpioLevel(__rst, LOW); + delay(30); + this->setGpioLevel(__rst, HIGH); + // For the variant of GPIO extended RST, + // communication and delay are carried out simultaneously, and 160ms is measured in T-RGB esp-idf new api + delay(160); + } + } + + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) + { + SensorCommon::setGpioModeCallback(mode_cb); + SensorCommon::setGpioWriteCallback(write_cb); + SensorCommon::setGpioReadCallback(read_cb); + } + +private: + bool initImpl() + { + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, INPUT); + } + + reset(); + + uint8_t vendId = readRegister(FT6X36_REG_VENDOR1_ID); + + + if (vendId != FT6X36_VEND_ID) { + log_e("Vendor id is 0x%X not match!", vendId); + return false; + } + + __chipID = readRegister(FT6X36_REG_CHIP_ID); + + if ((__chipID != FT6206_CHIP_ID) && + (__chipID != FT6236_CHIP_ID) && + (__chipID != FT6236U_CHIP_ID) && + (__chipID != FT3267_CHIP_ID) + ) { + log_e("Vendor id is not match!"); + log_e("ChipID:0x%lx should be 0x06 or 0x36 or 0x64", __chipID); + return false; + } + + log_i("Vend ID: 0x%X", vendId); + log_i("Chip ID: 0x%lx", __chipID); + log_i("Firm Version: 0x%X", readRegister(FT6X36_REG_FIRM_VERS)); + log_i("Point Rate Hz: %u", readRegister(FT6X36_REG_PERIOD_ACTIVE)); + log_i("Thresh : %u", readRegister(FT6X36_REG_THRESHOLD)); + + // change threshold to be higher/lower + writeRegister(FT6X36_REG_THRESHOLD, 60); + + log_i("Chip library version : 0x%x", getLibraryVersion()); + + // This register describes period of monitor status, it should not less than 30. + log_i("Chip period of monitor status : 0x%x", readRegister(FT6X36_REG_PERIOD_MONITOR)); + + // This register describes the period of active status, it should not less than 12 + + + return true; + } + + int getReadMaskImpl() + { + return -1; + } + +}; + + + diff --git a/components/SensorLib/src/TouchDrvGT911.hpp b/components/SensorLib/src/TouchDrvGT911.hpp new file mode 100644 index 0000000..3dafad5 --- /dev/null +++ b/components/SensorLib/src/TouchDrvGT911.hpp @@ -0,0 +1,653 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvGT911.tpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-12 + * + */ +#pragma once + +#include "REG/GT911Constants.h" +#include "TouchDrvInterface.hpp" +#include "SensorCommon.tpp" + + +#if defined(ARDUINO_ARCH_NRF52) +// NRF52840 I2C BUFFER : 64 Bytes , +#warning "NRF Platform I2C Buffer expansion is not implemented , GT911 requires at least 188 bytes to read all configurations" +#endif + +typedef struct GT911_Struct { + uint8_t trackID; + int16_t x; + int16_t y; + int16_t size; +} GT911Point_t; + + +#define LOW_LEVEL_QUERY 0x03 +#define HIGH_LEVEL_QUERY 0x04 + +class TouchDrvGT911 : + public TouchDrvInterface, + public SensorCommon +{ + friend class SensorCommon; +public: + + +#if defined(ARDUINO) + TouchDrvGT911(PLATFORM_WIRE_TYPE &w, + int sda = DEFAULT_SDA, + int scl = DEFAULT_SCL, + uint8_t addr = GT911_SLAVE_ADDRESS_H) + { + __wire = &w; + __sda = sda; + __scl = scl; + __rst = SENSOR_PIN_NONE; + __irq = SENSOR_PIN_NONE; + __addr = addr; + } +#endif + + TouchDrvGT911() + { +#if defined(ARDUINO) + __wire = &Wire; + __sda = DEFAULT_SDA; + __scl = DEFAULT_SCL; +#endif + __rst = SENSOR_PIN_NONE; + __irq = SENSOR_PIN_NONE; + __addr = GT911_SLAVE_ADDRESS_H; + } + + ~TouchDrvGT911() + { + deinit(); + } + +#if defined(ARDUINO) + bool begin(PLATFORM_WIRE_TYPE &w, + uint8_t addr = GT911_SLAVE_ADDRESS_H, + int sda = DEFAULT_SDA, + int scl = DEFAULT_SCL + ) + { + return SensorCommon::begin(w, addr, sda, scl); + } + +#elif defined(ESP_PLATFORM) && !defined(ARDUINO) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) + { + return SensorCommon::begin(i2c_dev_bus_handle, addr); + } +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) + { + return SensorCommon::begin(port_num, addr, sda, scl); + } +#endif //ESP_IDF_VERSION + +#endif + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) + { + return SensorCommon::begin(addr, readRegCallback, writeRegCallback); + } + + + void deinit() + { + // end(); + } + + + void reset() + { + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + this->setGpioLevel(__rst, HIGH); + delay(10); + } + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, INPUT); + } + /* + * If you perform a software reset on a board without a reset pin connected, + * subsequent interrupt settings or re-writing of configurations will be invalid. + * For example, when debugging a LilyGo T-Deck, resetting the interrupt mode will + * be invalid after a software reset. + * */ + // writeRegister(GT911_COMMAND, 0x02); + // writeCommand(0x02); + } + + void sleep() + { + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, OUTPUT); + this->setGpioLevel(__irq, LOW); + } + // writeRegister(GT911_COMMAND, 0x05); + writeCommand(0x05); + + /* + * Depending on the chip and platform, setting it to input after removing sleep will affect power consumption. + * The chip platform determines whether + * + * * */ + // if (__irq != SENSOR_PIN_NONE) { + // this->setGpioLevel(__irq, INPUT); + // } + } + + + + void wakeup() + { + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, OUTPUT); + this->setGpioLevel(__irq, HIGH); + delay(8); + this->setGpioMode(__irq, INPUT); + } else { + reset(); + } + } + + void idle() + { + + } + + uint8_t getSupportTouchPoint() + { + return 5; + } + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t size = 1) + { + uint8_t buffer[39]; + uint8_t touchPoint = 0; + GT911Point_t p[5]; + + if (!x_array || !y_array || size == 0) + return 0; + + uint8_t val = readGT911(GT911_POINT_INFO); + + bool haveKey = GT911_GET_HAVE_KEY(val); + // bool bufferStatus = GT911_GET_BUFFER_STATUS(val); + // log_i("REG:0x%X S:0X%d K:%d\n", val,bufferStatus,haveKey); + + if (__homeButtonCb && haveKey) { + __homeButtonCb(__userData); + } + + clearBuffer(); + + touchPoint = GT911_GET_POINT(val); + if (touchPoint == 0) { + return 0; + } + + // GT911_POINT_1 0X814F + uint8_t write_buffer[2] = {0x81, 0x4F}; + if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), + buffer, 39) == DEV_WIRE_ERR) { + return 0; + } + + for (uint8_t i = 0; i < size; i++) { + p[i].trackID = buffer[i * 8]; + p[i].x = buffer[0x01 + i * 8] ; + p[i].x |= (buffer[0x02 + i * 8] << 8 ); + p[i].y = buffer[0x03 + i * 8] ; + p[i].y |= (buffer[0x04 + i * 8] << 8); + p[i].size = buffer[0x05 + i * 8] ; + p[i].size |= (buffer[0x06 + i * 8] << 8) ; + + x_array[i] = p[i].x; + y_array[i] = p[i].y; + } + +#ifdef LOG_PORT + LOG_PORT.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); + LOG_PORT.println("Touched [0]ID [0]Size [0]X [0]Y [1]ID [1]Size [1]X [1]Y [2]ID [2]Size [2]X [2]Y [3]ID [3]Size [3]X [3]Y [4]ID [4]Size [4]X [4]Y "); + LOG_PORT.print(touchPoint); LOG_PORT.print("\t"); + for (int i = 0; i < size; ++i) { + LOG_PORT.print(p[i].trackID); LOG_PORT.print("\t"); + LOG_PORT.print(p[i].size); LOG_PORT.print("\t"); + LOG_PORT.print( p[i].x); LOG_PORT.print("\t"); + LOG_PORT.print( p[i].y); LOG_PORT.print("\t"); + } + LOG_PORT.println(); +#endif + + updateXY(touchPoint, x_array, y_array); + + return touchPoint; + } + + + bool isPressed() + { + if (__irq != SENSOR_PIN_NONE) { + if (__irq_mode == FALLING) { + return this->getGpioLevel(__irq) == LOW; + } else if (__irq_mode == RISING ) { + return this->getGpioLevel(__irq) == HIGH; + } else if (__irq_mode == LOW_LEVEL_QUERY) { + return this->getGpioLevel(__irq) == LOW; + } else if (__irq_mode == HIGH_LEVEL_QUERY) { + return this->getGpioLevel(__irq) == HIGH; + } + } + return getPoint(); + } + + bool setInterruptMode(uint8_t mode) + { + // GT911_MODULE_SWITCH_1 0x804D + uint8_t val = readGT911(GT911_MODULE_SWITCH_1); + val &= 0XFC; + if (mode == FALLING) { + val |= 0x01; + } else if (mode == RISING ) { + val |= 0x00; + } else if (mode == LOW_LEVEL_QUERY ) { + val |= 0x02; + } else if (mode == HIGH_LEVEL_QUERY ) { + val |= 0x03; + } + __irq_mode = mode; + writeGT911(GT911_MODULE_SWITCH_1, val); + return reloadConfig(); + } + + /** + * @retval + * * 0x0: Rising edge trigger + * * 0x1: Falling edge trigger + * * 0x2: Low level query + * * 0x3: High level query + */ + uint8_t getInterruptMode() + { + uint8_t val = readGT911(GT911_MODULE_SWITCH_1); + // return val & 0x03; + val &= 0x03; + if (val == 0x00) { + __irq_mode = RISING; + } else if (val == 0x01) { + __irq_mode = FALLING; + } else if (val == 0x02) { + __irq_mode = LOW_LEVEL_QUERY; + } else if (val == 0x03) { + __irq_mode = HIGH_LEVEL_QUERY; + } + return val; + } + + + uint8_t getPoint() + { + // GT911_POINT_INFO 0X814E + uint8_t val = readGT911(GT911_POINT_INFO); + clearBuffer(); + return GT911_GET_POINT(val); + } + + + uint32_t getChipID() + { + char product_id[4] = {0}; + // GT911_PRODUCT_ID 0x8140 + for (int i = 0; i < 4; ++i) { + product_id[i] = readGT911(GT911_PRODUCT_ID + i); + } + return atoi(product_id); + } + + uint16_t getFwVersion() + { + uint8_t fw_ver[2] = {0}; + // GT911_FIRMWARE_VERSION 0x8144 + for (int i = 0; i < 2; ++i) { + fw_ver[i] = readGT911(GT911_FIRMWARE_VERSION + i); + } + return fw_ver[0] | (fw_ver[1] << 8); + } + + uint8_t getConfigVersion() + { + return readGT911(GT911_CONFIG_VERSION); + } + + + bool getResolution(int16_t *x, int16_t *y) + { + uint8_t x_resolution[2] = {0}, y_resolution[2] = {0}; + + for (int i = 0; i < 2; ++i) { + x_resolution[i] = readGT911(GT911_X_RESOLUTION + i); + } + for (int i = 0; i < 2; ++i) { + y_resolution[i] = readGT911(GT911_Y_RESOLUTION + i); + } + + *x = x_resolution[0] | (x_resolution[1] << 8); + *y = y_resolution[0] | (y_resolution[1] << 8); + return true; + } + + //Range : 5 ~ 15 ms + void updateRefreshRate(uint8_t rate_ms) + { + if ((rate_ms - 5) < 5) { + rate_ms = 5; + } + if (rate_ms > 15) { + rate_ms = 15; + } + rate_ms -= 5; + writeGT911(GT911_REFRESH_RATE, rate_ms); + reloadConfig(); + } + + uint8_t getRefreshRate() + { + uint8_t rate_ms = readGT911(GT911_REFRESH_RATE); + return rate_ms + GT911_BASE_REF_RATE ; + } + + + int getVendorID() + { + return readGT911(GT911_VENDOR_ID); + } + + + const char *getModelName() + { + return "GT911"; + } + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) + { + SensorCommon::setGpioModeCallback(mode_cb); + SensorCommon::setGpioWriteCallback(write_cb); + SensorCommon::setGpioReadCallback(read_cb); + } + + void setHomeButtonCallback(home_button_callback_t cb, void *user_data) + { + __homeButtonCb = cb; + __userData = user_data; + } + + bool writeConfig(const uint8_t *config_buffer, size_t buffer_size) + { + setRegAddressLength(2); + int err = writeRegister(GT911_CONFIG_VERSION, (uint8_t *)config_buffer, buffer_size); + setRegAddressLength(1); + return err == DEV_WIRE_NONE; + } + + uint8_t *loadConfig(size_t *output_size, bool print_out = false) + { + *output_size = 0; + uint8_t *buffer = (uint8_t * )malloc(GT911_REG_LENGTH * sizeof(uint8_t)); + if (!buffer)return NULL; + uint8_t write_buffer[2] = {highByte(GT911_CONFIG_VERSION), lowByte(GT911_CONFIG_VERSION)}; + if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), buffer, GT911_REG_LENGTH) == DEV_WIRE_ERR) { + free(buffer); + return NULL; + } + if (print_out) { + printf("const unsigned char config[186] = {"); + for (int i = 0; i < GT911_REG_LENGTH; ++i) { + if ( (i % 8) == 0) { + printf("\n"); + } + printf("0x%02X", buffer[i]); + if ((i + 1) < GT911_REG_LENGTH) { + printf(","); + } + } + printf("};\n"); + } + *output_size = GT911_REG_LENGTH; + return buffer; + } + + bool reloadConfig() + { + uint8_t buffer[GT911_REG_LENGTH] = {highByte(GT911_CONFIG_VERSION), lowByte(GT911_CONFIG_VERSION)}; + if (writeThenRead(buffer, 2, buffer, GT911_REG_LENGTH - 2) == DEV_WIRE_ERR) { + return false; + } + + uint8_t check_sum = 0; + for (int i = 0; i < (GT911_REG_LENGTH - 2 ); i++) { + check_sum += buffer[i]; + } + check_sum = (~check_sum) + 1; + log_d("reloadConfig check_sum : 0x%X\n", check_sum); + writeGT911(GT911_CONFIG_CHKSUM, check_sum); + writeGT911(GT911_CONFIG_FRESH, 0x01); + return true; + } + + void dumpRegister() + { + size_t output_size = 0; + uint8_t *buffer = loadConfig(&output_size, true); + if (output_size == 0) { + return; + } + + if (buffer == NULL)return; + printf("----------Dump register------------\n"); + for (size_t i = 0; i < output_size; ++i) { + printf("[%d] REG: 0x%X : 0x%02X\n", i, GT911_CONFIG_VERSION + i, buffer[i]); + } + free(buffer); + } + + // Range : 1~5 + void setMaxTouchPoint(uint8_t num) + { + if (num < 1)num = 1; + if (num > 5) num = 5; + writeGT911(GT911_TOUCH_NUMBER, num); + reloadConfig(); + } + + uint8_t getMaxTouchPoint() + { + uint8_t num = readGT911(GT911_TOUCH_NUMBER); + return num & 0x0F; + } + +private: + + uint8_t readGT911(uint16_t cmd) + { + uint8_t value = 0x00; + uint8_t write_buffer[2] = {highByte(cmd), lowByte(cmd)}; + writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), + &value, 1); + return value; + } + + int writeGT911(uint16_t cmd, uint8_t value) + { + uint8_t write_buffer[3] = {highByte(cmd), lowByte(cmd), value}; + return writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer)); + } + + + void writeCommand(uint8_t command) + { + // GT911_COMMAND 0x8040 + uint8_t write_buffer[3] = {0x80, 0x40, command}; + writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer)); + } + + void inline clearBuffer() + { + writeGT911(GT911_POINT_INFO, 0x00); + } + + bool probeAddress() + { + const uint8_t device_address[2] = {GT911_SLAVE_ADDRESS_L, GT911_SLAVE_ADDRESS_H}; + for (size_t i = 0; i < SENSORLIB_COUNT(device_address); ++i) { + __addr = device_address[i]; + for (int retry = 0; retry < 3; ++retry) { + if (getChipID() == GT911_DEV_ID) { + return true; + } + } + } + return false; + } + + + bool initImpl() + { + int16_t x = 0, y = 0; + + if (__rst == SENSOR_PIN_NONE) { + // Automatically determine the current device + // address when using the reset pin without connection + if (!probeAddress()) { + return false; + } + log_i("Probe address is : 0x%X", __addr); + + // Reset Config + reset(); + + this->setGpioMode(__irq, INPUT); + + } else if (__addr == GT911_SLAVE_ADDRESS_H && + __rst != SENSOR_PIN_NONE && + __irq != SENSOR_PIN_NONE) { + + log_i("GT911 using 0x28 address!"); + + this->setGpioMode(__rst, OUTPUT); + this->setGpioMode(__irq, OUTPUT); + + this->setGpioLevel(__rst, LOW); + this->setGpioLevel(__irq, HIGH); + delayMicroseconds(120); + this->setGpioLevel(__rst, HIGH); + delay(18); + this->setGpioMode(__irq, INPUT); + + } else if (__addr == GT911_SLAVE_ADDRESS_L && + __rst != SENSOR_PIN_NONE && + __irq != SENSOR_PIN_NONE) { + + log_i("GT911 using 0xBA address!"); + + this->setGpioMode(__rst, OUTPUT); + this->setGpioMode(__irq, OUTPUT); + + this->setGpioLevel(__rst, LOW); + this->setGpioLevel(__irq, LOW); + delayMicroseconds(120); + this->setGpioLevel(__rst, HIGH); + delay(18); + this->setGpioMode(__irq, INPUT); + + } + + // For variants where the GPIO is controlled by I2C, a delay is required here + delay(20); + + __chipID = getChipID(); + log_i("Product id:%ld", __chipID); + + if (__chipID != GT911_DEV_ID) { + log_i("Not find device GT911"); + return false; + } + log_i("Firmware version: 0x%x", getFwVersion()); + getResolution(&x, &y); + log_i("Resolution : X = %d Y = %d", x, y); + log_i("Vendor id:%d", getVendorID()); + log_i("Refresh Rate:%d ms", getRefreshRate()); + log_i("MaxTouchPoint:%d", getMaxTouchPoint()); + + /* + * For the ESP32 platform, the default buffer is 128. + * Need to re-apply for a larger buffer to fully read the configuration table. + * */ + if (!this->reallocBuffer(GT911_REG_LENGTH + 2 )) { + log_e("realloc i2c buffer failed !"); + return false; + } + + // Get the default interrupt trigger mode of the current screen + getInterruptMode(); + + if ( __irq_mode == RISING) { + log_i("Interrupt Mode: RISING"); + } else if (__irq_mode == FALLING) { + log_i("Interrupt Mode: FALLING"); + } else if (__irq_mode == LOW_LEVEL_QUERY) { + log_i("Interrupt Mode: LOW_LEVEL_QUERY"); + } else if (__irq_mode == HIGH_LEVEL_QUERY) { + log_i("Interrupt Mode: HIGH_LEVEL_QUERY"); + } else { + log_e("UNKOWN"); + } + + + return true; + } + + int getReadMaskImpl() + { + return -1; + } + + +protected: + int __irq_mode; +}; + + + diff --git a/components/SensorLib/src/TouchDrvInterface.cpp b/components/SensorLib/src/TouchDrvInterface.cpp new file mode 100644 index 0000000..5e43a30 --- /dev/null +++ b/components/SensorLib/src/TouchDrvInterface.cpp @@ -0,0 +1,100 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted,free of charge,to any person obtaining a copy + * of this software and associated documentation files (the "Software"),to deal + * in the Software without restriction,including without limitation the rights + * to use,copy,modify,merge,publish,distribute,sublicense,and/or sell + * copies of the Software,and to permit persons to whom the Software is + * furnished to do so,subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR + * IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER + * LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvInterface.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-21 + * + */ +#include "TouchDrvInterface.hpp" + +TouchDrvInterface::TouchDrvInterface() : + __resX(0), + __resY(0), + __xMax(0), + __yMax(0), + __swapXY(false), + __mirrorX(false), + __mirrorY(false), + __rst(-1), + __irq(-1), + __chipID(0x00), + __homeButtonCb(NULL), + __userData(NULL) +{ + +} + +TouchDrvInterface::~TouchDrvInterface() +{ + +} + +uint32_t TouchDrvInterface::getChipID() +{ + return __chipID; +} + + +void TouchDrvInterface::setPins(int rst, int irq) +{ + __irq = irq; + __rst = rst; +} + +void TouchDrvInterface::setSwapXY(bool swap) +{ + __swapXY = swap; +} + +void TouchDrvInterface::setMirrorXY(bool mirrorX, bool mirrorY) +{ + __mirrorX = mirrorX; + __mirrorY = mirrorY; +} + +void TouchDrvInterface::setMaxCoordinates(uint16_t x, uint16_t y) +{ + __xMax = x; + __yMax = y; +} + +void TouchDrvInterface::updateXY(uint8_t pointNum, int16_t *xBuffer, int16_t *yBuffer) +{ + if (!pointNum) + return; + for (int i = 0; i < pointNum; ++i) { + if (__swapXY) { + uint16_t tmp = xBuffer[i]; + xBuffer[i] = yBuffer[i]; + yBuffer[i] = tmp; + } + if (__mirrorX && __xMax ) { + xBuffer[i] = __xMax - xBuffer[i]; + } + if (__mirrorY && __yMax) { + yBuffer[i] = __yMax - yBuffer[i]; + } + } +} diff --git a/components/SensorLib/src/TouchDrvInterface.hpp b/components/SensorLib/src/TouchDrvInterface.hpp new file mode 100644 index 0000000..b41ea4d --- /dev/null +++ b/components/SensorLib/src/TouchDrvInterface.hpp @@ -0,0 +1,145 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted,free of charge,to any person obtaining a copy + * of this software and associated documentation files (the "Software"),to deal + * in the Software without restriction,including without limitation the rights + * to use,copy,modify,merge,publish,distribute,sublicense,and/or sell + * copies of the Software,and to permit persons to whom the Software is + * furnished to do so,subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR + * IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER + * LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchDrvInterface.hpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-04-17 + * + */ +#pragma once + +#include +#include +#include "SensorLib.h" +#include "SensorCommon.tpp" + +typedef void (*home_button_callback_t)(void *user_data); + + +class TouchData +{ +public: + TouchData() {} + ~TouchData() {}; + uint8_t available; + uint8_t id[5]; + int16_t x[5]; + int16_t y[5]; + uint8_t status[5]; + uint8_t pressure[5]; + + uint16_t getX(uint8_t index = 0) + { + return x[index]; + } + uint16_t getY(uint8_t index = 0) + { + return y[index]; + } + uint16_t getPressure(uint8_t index = 0) + { + return pressure[index]; + } + uint16_t getStatus(uint8_t index = 0) + { + return status[index]; + } +}; + + + +class TouchDrvInterface +{ +public: + TouchDrvInterface(); + + virtual ~TouchDrvInterface(); + +#if defined(ARDUINO) + + virtual bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl) = 0; + +#elif defined(ESP_PLATFORM) && !defined(ARDUINO) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + virtual bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) = 0; +#else + virtual bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) = 0; +#endif //ESP_IDF_VERSION + +#endif //defined(ESP_PLATFORM) && !defined(ARDUINO) + + virtual bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) = 0; + + virtual void reset() = 0; + + virtual uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point) = 0; + + virtual bool isPressed() = 0; + + virtual const char *getModelName() = 0; + + virtual void sleep() = 0; + + virtual void wakeup() = 0; + + virtual void idle() = 0; + + virtual uint8_t getSupportTouchPoint() = 0; + + virtual bool getResolution(int16_t *x, int16_t *y) = 0; + + virtual void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) = 0; + + uint32_t getChipID(); + + void setPins(int rst, int irq); + + void setSwapXY(bool swap); + + void setMirrorXY(bool mirrorX, bool mirrorY); + + void setMaxCoordinates(uint16_t x, uint16_t y); + + void updateXY(uint8_t pointNum, int16_t *xBuffer, int16_t *yBuffer); + +protected: + uint16_t __resX, __resY, __xMax, __yMax; + bool __swapXY, __mirrorX, __mirrorY; + int __rst; + int __irq; + uint32_t __chipID; + home_button_callback_t __homeButtonCb; + void *__userData; + +}; + + + + + + + diff --git a/components/SensorLib/src/bosch/BMM150/bmm150.c b/components/SensorLib/src/bosch/BMM150/bmm150.c new file mode 100644 index 0000000..1f401f0 --- /dev/null +++ b/components/SensorLib/src/bosch/BMM150/bmm150.c @@ -0,0 +1,2187 @@ +/** + * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bmm150.c + * @date 2020-06-03 + * @version v2.0.0 + * + */ + +/*! @file bmm150.c + * @brief Sensor driver for BMM150 sensor */ +#include "bmm150.h" + +/************************** Internal macros *******************************/ +/* Sensor ODR, Repetition and axes enable/disable settings */ +#define MODE_SETTING_SEL UINT16_C(0x000F) + +/* Interrupt pin settings like polarity,latch and int_pin enable */ +#define INTERRUPT_PIN_SETTING_SEL UINT16_C(0x01F0) + +/* Settings to enable/disable interrupts */ +#define INTERRUPT_CONFIG_SEL UINT16_C(0x1E00) + +/* Interrupt settings for configuring threshold values */ +#define INTERRUPT_THRESHOLD_CONFIG_SEL UINT16_C(0x6000) + +/********************** Static function declarations ************************/ + +/*! + * @brief This internal API is used to validate the device pointer for + * null conditions. + * + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t null_ptr_check(const struct bmm150_dev *dev); + +/*! + * @brief This internal API sets/resets the power control bit of 0x4B register. + * + * @param[in] pwrcntrl_bit : Variable used to select/deselect the suspend mode. + * @param[in,out] dev : Structure instance of bmm150_dev + * + * pwrcntrl_bit | power mode + * -----------------|------------------------- + * 0x00 | Suspend mode + * 0x01 | Sleep/Active modes + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_power_control_bit(uint8_t pwrcntrl_bit, struct bmm150_dev *dev); + +/*! + * @brief This internal API reads the trim registers of the sensor and stores + * the trim values in the "trim_data" of device structure. + * + * @param[in,out] dev : Structure instance of bmm150_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t read_trim_registers(struct bmm150_dev *dev); + +/*! + * @brief This internal API writes the op_mode value in the Opmode bits + * (bits 1 and 2) of 0x4C register. + * + * op_mode | Power mode + * ------------|----------------------- + * 0x00 | BMM150_POWERMODE_NORMAL + * 0x01 | BMM150_POWERMODE_FORCED + * 0x03 | BMM150_POWERMODE_SLEEP + * + * @param[in,out] dev : Structure instance of bmm150_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t write_op_mode(uint8_t op_mode, struct bmm150_dev *dev); + +/*! + * @brief This internal API sets the device from suspend to sleep mode + * by setting the power control bit to '1' of 0x4B register + * + * @param[in,out] dev : Structure instance of bmm150_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t suspend_to_sleep_mode(struct bmm150_dev *dev); + +/*! + * @brief This internal API sets the xy repetition value in the 0x51 register. + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in,out] dev : Structure instance of bmm150_dev + * + * settings->xy_rep | nXY(XY Repetitions) + * -------------------------|----------------------- + * 0x00 | 1 + * 0x01 | 3 + * 0x02 | 5 + * . | . + * . | . + * 0xFF | 511 + * + * @note number of XY Repetitions nXY = 1+2(settings->xy_rep) + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_xy_rep(const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * @brief This internal API sets the z repetition value in the 0x52 register. + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in,out] dev : Structure instance of bmm150_dev + * + * settings->z_rep | nZ(Z Repetitions) + * -------------------------|----------------------- + * 0x00 | 1 + * 0x01 | 2 + * 0x02 | 3 + * . | . + * . | . + * 0xFF | 256 + * + * @note number of Z Repetitions nZ = 1+(settings->z_rep) + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_z_rep(const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to set the output data rate of the sensor + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * settings->data_rate | Data rate (ODR) + * -------------------------|----------------------- + * 0x00 | BMM150_DATA_RATE_10HZ + * 0x01 | BMM150_DATA_RATE_02HZ + * 0x02 | BMM150_DATA_RATE_06HZ + * 0x03 | BMM150_DATA_RATE_08HZ + * 0x04 | BMM150_DATA_RATE_15HZ + * 0x05 | BMM150_DATA_RATE_20HZ + * 0x06 | BMM150_DATA_RATE_25HZ + * 0x07 | BMM150_DATA_RATE_30HZ + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_odr(const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * @brief This internal API sets the preset mode ODR and repetition settings. + * @param[in] settings : Structure instance of bmm150_settings + * @param[in] dev : Structure instance of bmm150_dev + * + * API settings | Representation + * ---------------------|------------------------------ + * settings->data_rate | Output Data Rate (ODR) + * settings->xy_rep | XY repetition value + * settings->z_rep | Z-repetition value + * + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_odr_xyz_rep(const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to enable or disable the magnetic + * measurement of x,y,z axes based on the value of xyz_axes_control. + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * settings->xyz_axes_control | Measurement axes/channel + * ---------------------------|-------------------------- + * Bit 0 | X - Channel + * Bit 1 | Y - Channel + * Bit 2 | Z - Channel + * + * @note Setting 1 - Disables Channel measurement + * @note Setting 0 - Enables Channel measurement + * + * settings->xyz_axes_control | Measurement axes Enabled/disabled + * -------------------------------|------------------------------------ + * 0x01 | Disables X axis (Y,Z axes enabled) + * 0x02 | Disables Y axis (X,Z axes enabled) + * 0x04 | Disables Z axis (X,Y axes enabled) + * 0x07 | Disables all X,Y,Z axes measurement + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_control_measurement_xyz(const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to identify the settings which the user + * wants to modify in the sensor. + * + * @param[in] sub_settings : Contains the settings subset to identify particular + * group of settings which the user is interested to change. + * @param[in] settings : Contains the user specified settings. + * + * @return Indicates whether user is interested to modify the settings which + * are related to sub_settings. + * @retval True -> User wants to modify this group of settings + * @retval False -> User does not want to modify this group of settings + */ +static uint8_t are_settings_changed(uint16_t sub_settings, uint16_t settings); + +/*! + * @brief This API sets the ODR , measurement axes control , + * repetition values of xy,z. + * + * @param[in] desired_settings : Contains the settings which user wants to + * change. + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t mode_settings(uint16_t desired_settings, const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to parse and store the sensor + * settings in the device structure + * + * @param[in] reg_data : Pointer of an array consisting all sensor + * setting data from 0x4B to 0x52 registers. + * @param[in] settings : Structure instance of bmm150_settings. + * + */ +static void parse_setting(const uint8_t *reg_data, struct bmm150_settings *settings); + +/*! + * @brief This API is used to enable the interrupts and map them to the + * corresponding interrupt pins and specify the pin characteristics like the + * polarity , latch settings for the interrupt pins. + * + * @note The other interrupts can be latched or non-latched but, + * Data ready interrupt is always cleared after reading out the data + * + * @param[in] desired_settings : Contains the settings which user wants to + * change. + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t interrupt_pin_settings(uint16_t desired_settings, + const struct bmm150_settings *settings, + struct bmm150_dev *dev); + +/*! + * @brief This API is used to enable data overrun , overflow interrupts and + * enable/disable high/low threshold interrupts for x,y,z axis based on the + * threshold values set by the user in the High threshold (0x50) and + * Low threshold (0x4F) registers. + * + * @param[in] desired_settings : Contains the settings which user wants to + * change. + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t interrupt_config(uint16_t desired_settings, const struct bmm150_settings *settings, + struct bmm150_dev *dev); + +/*! + * @brief This API is used to write the user specified High/Low threshold value + * as a reference to generate the high/low threshold interrupt. + * + * @param[in] desired_settings : Contains the settings which user wants to + * change. + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t interrupt_threshold_settings(uint16_t desired_settings, + const struct bmm150_settings *settings, + struct bmm150_dev *dev); + +#ifdef BMM150_USE_FLOATING_POINT + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer X axis data in float. + * + * @param[in] mag_data_x : The value of raw X data + * @param[in] data_rhall : The value of raw RHALL data + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of compensated X data value in float + */ +static float compensate_x(int16_t mag_data_x, uint16_t data_rhall, const struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer Y axis data in float. + * + * @param[in] mag_data_y : The value of raw Y data + * @param[in] data_rhall : The value of raw RHALL data + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of compensated Y data value in float + */ +static float compensate_y(int16_t mag_data_y, uint16_t data_rhall, const struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer Z axis data in float. + * + * @param[in] mag_data_z : The value of raw Z data + * @param[in] data_rhall : The value of raw RHALL data + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of compensated Z data value in float + */ +static float compensate_z(int16_t mag_data_z, uint16_t data_rhall, const struct bmm150_dev *dev); + +#else + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer X axis data in int16_t. + * + * @param[in] mag_data_x : The value of raw X data + * @param[in] data_rhall : The value of raw RHALL data + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of compensated X data value in int16_t format + */ +static int16_t compensate_x(int16_t mag_data_x, uint16_t data_rhall, const struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer Y axis data in int16_t. + * + * @param[in] mag_data_y : The value of raw Y data + * @param[in] data_rhall : The value of raw RHALL data + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of compensated Y data value in int16_t format + */ +static int16_t compensate_y(int16_t mag_data_y, uint16_t data_rhall, const struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer Z axis data in int16_t. + * + * @param[in] mag_data_z : The value of raw Z data + * @param[in] data_rhall : The value of raw RHALL data + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of compensated Z data value in int16_t format + */ +static int16_t compensate_z(int16_t mag_data_z, uint16_t data_rhall, const struct bmm150_dev *dev); + +#endif + +/*! + * @brief This internal API is used to perform the normal self test + * of the sensor and return the self test result as return value + * + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t perform_normal_self_test(struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to enable the normal self test by setting + * the Self Test bit (bit0) of the 0x4C register, + * which triggers the start of self test + * + * @param[out] self_test_enable : The value of self test bit0 in 0x4C register + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t enable_normal_self_test(uint8_t *self_test_enable, struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to validate the results of normal self test + * by using the self test status available in the bit0 of registers 0x42,0x44 + * and 0x46. + * + * @param[in] dev : Structure instance of bmm150_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t validate_normal_self_test(struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to perform advanced self test for Z axis + * + * @param[in] dev : Structure instance of bmm150_dev + * + * @return Result of API execution status + * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * + * Return value | Status of self-test + *----------------------|--------------------------- + * 0 | BMM150_OK + * 8 | BMM150_W_ADV_SELF_TEST_FAIL + */ +static int8_t perform_adv_self_test(struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to set the desired power mode , + * axes control and repetition settings for advanced self test + * + * @param[in] dev : Structure instance of bmm150_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t adv_self_test_settings(struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to set the positive or negative value of + * self-test current and obtain the corresponding magnetometer z axis data + * + * @param[in] self_test_current : Self test current either positive/negative + * @param[out] data_z : Z-axis Magnetometer data + * @param[in] dev : Structure instance of bmm150_dev + * + * self_test_current | Self-test current Direction + *-------------------------|------------------------------ + * 0x03 | BMM150_ENABLE_POSITIVE_CURRENT + * 0x02 | BMM150_ENABLE_NEGATIVE_CURRENT + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t adv_self_test_measurement(uint8_t self_test_current, int16_t *data_z, struct bmm150_dev *dev); + +/*! + * @brief This internal API is used to get the difference between the + * Z axis mag data obtained by positive and negative self-test current + * and validate whether the advanced self test is done successfully or not. + * + * @param[in] positive_data_z : Z-axis Mag data by positive self-test current + * @param[in] negative_data_z : Z-axis Mag data by negative self-test current + * + * + * @return Result of API execution status + * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * + * Return value | Status of self-test + *----------------------|--------------------------- + * 0 | BMM150_OK + * 8 | BMM150_W_ADV_SELF_TEST_FAIL + */ +static int8_t validate_adv_self_test(int16_t positive_data_z, int16_t negative_data_z); + +/*! + * @brief This internal API is used to set the self test current value in + * the Adv. ST bits (bit6 and bit7) of 0x4C register + * + * @param[in] self_test_current : Self test current value (+ve/-ve) + * @param[in] dev : Structure instance of bmm150_dev + * + * self_test_current | Self-test current Direction + *-------------------------|------------------------------ + * 0x00 | BMM150_DISABLE_SELF_TEST_CURRENT + * 0x02 | BMM150_ENABLE_NEGATIVE_CURRENT + * 0x03 | BMM150_ENABLE_POSITIVE_CURRENT + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +static int8_t set_adv_self_test_current(uint8_t self_test_current, struct bmm150_dev *dev); + +/********************** Global function definitions ************************/ + +/*! + * @brief This API is the entry point, Call this API before using other APIs. + * This API reads the chip-id of the sensor which is the first step to + * verify the sensor and updates the trim parameters of the sensor. + */ +int8_t bmm150_init(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t chip_id = 0; + + /* Power up the sensor from suspend to sleep mode */ + rslt = set_power_control_bit(BMM150_POWER_CNTRL_ENABLE, dev); + + if (rslt == BMM150_OK) + { + /* Start-up time delay of 3ms */ + dev->delay_us(BMM150_START_UP_TIME, dev->intf_ptr); + + /* Chip ID of the sensor is read */ + rslt = bmm150_get_regs(BMM150_REG_CHIP_ID, &chip_id, 1, dev); + + /* Proceed if everything is fine until now */ + if (rslt == BMM150_OK) + { + /* Check for chip id validity */ + if (chip_id == BMM150_CHIP_ID) + { + dev->chip_id = chip_id; + + /* Function to update trim values */ + rslt = read_trim_registers(dev); + } + } + } + + return rslt; +} + +/*! + * @brief This API writes the given data to the register address + * of the sensor. + */ +int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev) +{ + int8_t rslt; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if ((rslt == BMM150_OK) && (reg_data != NULL) && (len != 0)) + { + /* Write the data to the reg_addr */ + + /* SPI write requires to set The MSB of reg_addr as 0 + * but in default the MSB is always 0 + */ + dev->intf_rslt = dev->write(reg_addr, reg_data, len, dev->intf_ptr); + } + else + { + rslt = BMM150_E_NULL_PTR; + } + + return rslt; +} + +/*! + * @brief This API reads the data from the given register address of the sensor. + */ +int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev) +{ + int8_t rslt; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if ((rslt == BMM150_OK) && (reg_data != NULL)) + { + if (dev->intf != BMM150_I2C_INTF) + { + /* If interface selected is SPI */ + reg_addr = reg_addr | 0x80; + } + + /* Read the data from the reg_addr */ + dev->intf_rslt = dev->read(reg_addr, reg_data, len, dev->intf_ptr); + } + else + { + rslt = BMM150_E_NULL_PTR; + } + + return rslt; +} + +/*! + * @brief This API is used to perform soft-reset of the sensor + * where all the registers are reset to their default values except 0x4B. + */ +int8_t bmm150_soft_reset(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + + rslt = bmm150_get_regs(BMM150_REG_POWER_CONTROL, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + reg_data = reg_data | BMM150_SET_SOFT_RESET; + rslt = bmm150_set_regs(BMM150_REG_POWER_CONTROL, ®_data, 1, dev); + dev->delay_us(BMM150_DELAY_SOFT_RESET, dev->intf_ptr); + } + + return rslt; +} + +/*! + * @brief This API is used to set the power mode of the sensor. + */ +int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t pwr_mode; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if (rslt == BMM150_OK) + { + pwr_mode = settings->pwr_mode; + + /* Select the power mode to set */ + switch (pwr_mode) + { + case BMM150_POWERMODE_NORMAL: + + /* If the sensor is in suspend mode + * put the device to sleep mode + */ + rslt = suspend_to_sleep_mode(dev); + if (rslt == BMM150_OK) + { + /* write the op mode */ + rslt = write_op_mode(pwr_mode, dev); + } + + break; + case BMM150_POWERMODE_FORCED: + + /* If the sensor is in suspend mode + * put the device to sleep mode + */ + rslt = suspend_to_sleep_mode(dev); + if (rslt == BMM150_OK) + { + /* write the op mode */ + rslt = write_op_mode(pwr_mode, dev); + } + + break; + case BMM150_POWERMODE_SLEEP: + + /* If the sensor is in suspend mode + * put the device to sleep mode + */ + rslt = suspend_to_sleep_mode(dev); + if (rslt == BMM150_OK) + { + /* write the op mode */ + rslt = write_op_mode(pwr_mode, dev); + } + + break; + case BMM150_POWERMODE_SUSPEND: + + /* Set the power control bit to zero */ + rslt = set_power_control_bit(BMM150_POWER_CNTRL_DISABLE, dev); + break; + default: + rslt = BMM150_E_INVALID_CONFIG; + break; + } + } + + return rslt; +} + +/*! + * @brief This API is used to get the power mode of the sensor. + */ +int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if (rslt == BMM150_OK) + { + if (dev->pwr_cntrl_bit == BMM150_POWER_CNTRL_DISABLE) + { + /* Power mode set is suspend mode */ + *op_mode = BMM150_POWERMODE_SUSPEND; + } + else + { + /* Power mode set is stored in the op_mode */ + rslt = bmm150_get_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + *op_mode = BMM150_GET_BITS(reg_data, BMM150_OP_MODE); + } + } + + return rslt; +} + +/*! + * @brief This API is used to set the preset mode of the sensor. + */ +int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t preset_mode; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if (rslt == BMM150_OK) + { + preset_mode = settings->preset_mode; + + switch (preset_mode) + { + case BMM150_PRESETMODE_LOWPOWER: + + /* Set the data rate x,y,z repetition + * for Low Power mode + */ + settings->data_rate = BMM150_DATA_RATE_10HZ; + settings->xy_rep = BMM150_REPXY_LOWPOWER; + settings->z_rep = BMM150_REPZ_LOWPOWER; + rslt = set_odr_xyz_rep(settings, dev); + break; + case BMM150_PRESETMODE_REGULAR: + + /* Set the data rate x,y,z repetition + * for Regular mode + */ + settings->data_rate = BMM150_DATA_RATE_10HZ; + settings->xy_rep = BMM150_REPXY_REGULAR; + settings->z_rep = BMM150_REPZ_REGULAR; + rslt = set_odr_xyz_rep(settings, dev); + break; + case BMM150_PRESETMODE_HIGHACCURACY: + + /* Set the data rate x,y,z repetition + * for High Accuracy mode * + */ + settings->data_rate = BMM150_DATA_RATE_20HZ; + settings->xy_rep = BMM150_REPXY_HIGHACCURACY; + settings->z_rep = BMM150_REPZ_HIGHACCURACY; + rslt = set_odr_xyz_rep(settings, dev); + break; + case BMM150_PRESETMODE_ENHANCED: + + /* Set the data rate x,y,z repetition + * for Enhanced Accuracy mode + */ + settings->data_rate = BMM150_DATA_RATE_10HZ; + settings->xy_rep = BMM150_REPXY_ENHANCED; + settings->z_rep = BMM150_REPZ_ENHANCED; + rslt = set_odr_xyz_rep(settings, dev); + break; + default: + rslt = BMM150_E_INVALID_CONFIG; + break; + } + } + + return rslt; +} + +/*! + * @brief This API sets the sensor settings based on the desired_settings + * and the dev structure configuration + */ +int8_t bmm150_set_sensor_settings(uint16_t desired_settings, + const struct bmm150_settings *settings, + struct bmm150_dev *dev) +{ + int8_t rslt; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if (rslt == BMM150_OK) + { + if (are_settings_changed(MODE_SETTING_SEL, desired_settings)) + { + /* ODR, Control measurement, XY,Z repetition values */ + rslt = mode_settings(desired_settings, settings, dev); + } + + if ((!rslt) && are_settings_changed(INTERRUPT_PIN_SETTING_SEL, desired_settings)) + { + /* Interrupt pin settings */ + rslt = interrupt_pin_settings(desired_settings, settings, dev); + } + + if ((!rslt) && are_settings_changed(INTERRUPT_CONFIG_SEL, desired_settings)) + { + /* Interrupt configuration settings */ + rslt = interrupt_config(desired_settings, settings, dev); + } + + if ((!rslt) && are_settings_changed(INTERRUPT_THRESHOLD_CONFIG_SEL, desired_settings)) + { + /* Interrupt threshold settings */ + rslt = interrupt_threshold_settings(desired_settings, settings, dev); + } + } + + return rslt; +} + +/*! + * @brief This API gets the sensor settings and updates the dev structure + */ +int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t setting[BMM150_LEN_SETTING_DATA] = {0}; + + /* Read the entire sensor settings */ + rslt = bmm150_get_regs(BMM150_REG_POWER_CONTROL, setting, BMM150_LEN_SETTING_DATA, dev); + + if (rslt == BMM150_OK) + { + /* Parse and store the settings */ + parse_setting(setting, settings); + } + + return rslt; +} + +/*! + * @brief This API is used to read the magnetometer data from registers + * 0x42 to 0x49 and update the dev structure with the + * compensated mag data in micro-tesla. + */ +int8_t bmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev) +{ + int8_t rslt; + int16_t msb_data; + uint8_t reg_data[BMM150_LEN_XYZR_DATA] = {0}; + struct bmm150_raw_mag_data raw_mag_data; + + /* Read the mag data registers */ + rslt = bmm150_get_regs(BMM150_REG_DATA_X_LSB, reg_data, BMM150_LEN_XYZR_DATA, dev); + + if (rslt == BMM150_OK) + { + /* Mag X axis data */ + reg_data[0] = BMM150_GET_BITS(reg_data[0], BMM150_DATA_X); + + /* Shift the MSB data to left by 5 bits */ + /* Multiply by 32 to get the shift left by 5 value */ + msb_data = ((int16_t)((int8_t)reg_data[1])) * 32; + + /* Raw mag X axis data */ + raw_mag_data.raw_datax = (int16_t)(msb_data | reg_data[0]); + + /* Mag Y axis data */ + reg_data[2] = BMM150_GET_BITS(reg_data[2], BMM150_DATA_Y); + + /* Shift the MSB data to left by 5 bits */ + /* Multiply by 32 to get the shift left by 5 value */ + msb_data = ((int16_t)((int8_t)reg_data[3])) * 32; + + /* Raw mag Y axis data */ + raw_mag_data.raw_datay = (int16_t)(msb_data | reg_data[2]); + + /* Mag Z axis data */ + reg_data[4] = BMM150_GET_BITS(reg_data[4], BMM150_DATA_Z); + + /* Shift the MSB data to left by 7 bits */ + /* Multiply by 128 to get the shift left by 7 value */ + msb_data = ((int16_t)((int8_t)reg_data[5])) * 128; + + /* Raw mag Z axis data */ + raw_mag_data.raw_dataz = (int16_t)(msb_data | reg_data[4]); + + /* Mag R-HALL data */ + reg_data[6] = BMM150_GET_BITS(reg_data[6], BMM150_DATA_RHALL); + raw_mag_data.raw_data_r = (uint16_t)(((uint16_t)reg_data[7] << 6) | reg_data[6]); + + /* Compensated Mag X data in int16_t format */ + mag_data->x = compensate_x(raw_mag_data.raw_datax, raw_mag_data.raw_data_r, dev); + + /* Compensated Mag Y data in int16_t format */ + mag_data->y = compensate_y(raw_mag_data.raw_datay, raw_mag_data.raw_data_r, dev); + + /* Compensated Mag Z data in int16_t format */ + mag_data->z = compensate_z(raw_mag_data.raw_dataz, raw_mag_data.raw_data_r, dev); + } + + return rslt; +} + +/*! + * @brief This API is used to perform the complete self test + * (both normal and advanced) for the BMM150 sensor + */ +int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev) +{ + int8_t rslt; + int8_t self_test_rslt = 0; + struct bmm150_settings settings; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if (rslt == BMM150_OK) + { + switch (self_test_mode) + { + case BMM150_SELF_TEST_NORMAL: + + /* Set the sensor in sleep mode */ + settings.pwr_mode = BMM150_POWERMODE_SLEEP; + rslt = bmm150_set_op_mode(&settings, dev); + + if (rslt == BMM150_OK) + { + /* Perform the normal self test */ + rslt = perform_normal_self_test(dev); + } + + break; + case BMM150_SELF_TEST_ADVANCED: + + /* Perform the advanced self test */ + rslt = perform_adv_self_test(dev); + + /* Check to ensure bus error does not occur */ + if (rslt >= BMM150_OK) + { + /* Store the status of self test result */ + self_test_rslt = rslt; + + /* Perform soft reset */ + rslt = bmm150_soft_reset(dev); + } + + /* Check to ensure bus operations are success */ + if (rslt == BMM150_OK) + { + /* Restore self_test_rslt as return value */ + rslt = self_test_rslt; + } + + break; + default: + rslt = BMM150_E_INVALID_CONFIG; + break; + } + } + + return rslt; +} + +/*! + * @brief This API is used to get the status flags of all interrupt + * which is used to check for the assertion of interrupts + */ +int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t interrupt_status; + uint8_t data_ready_status; + + /* Read the data ready status from the register 0x48 */ + rslt = bmm150_get_regs(BMM150_REG_DATA_READY_STATUS, &data_ready_status, 1, dev); + + if (rslt == BMM150_OK) + { + /* Read the interrupt status from the register 0x50 */ + rslt = bmm150_get_regs(BMM150_REG_INTERRUPT_STATUS, &interrupt_status, 1, dev); + + if (rslt == BMM150_OK) + { + /* Mask and store the data ready status bit */ + data_ready_status = BMM150_GET_BITS_POS_0(data_ready_status, BMM150_DRDY_STATUS); + + /* Store the entire interrupt status in dev */ + dev->int_status = (data_ready_status << 8) | interrupt_status; + } + } + + return rslt; +} + +/****************************************************************************/ +/**\name BMM150 as Auxiliary Mag */ + +/*! + * @brief This API is used to compensate the raw mag data + */ +int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev) +{ + int8_t rslt; + int16_t msb_data; + struct bmm150_raw_mag_data raw_mag_data; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if ((rslt == BMM150_OK) && (aux_data != NULL)) + { + /* Mag X axis data */ + aux_data[0] = BMM150_GET_BITS(aux_data[0], BMM150_DATA_X); + + /* Shift the MSB data to left by 5 bits */ + /* Multiply by 32 to get the shift left by 5 value */ + msb_data = ((int16_t)((int8_t)aux_data[1])) * 32; + + /* Raw mag X axis data */ + raw_mag_data.raw_datax = (int16_t)(msb_data | aux_data[0]); + + /* Mag Y axis data */ + aux_data[2] = BMM150_GET_BITS(aux_data[2], BMM150_DATA_Y); + + /* Shift the MSB data to left by 5 bits */ + /* Multiply by 32 to get the shift left by 5 value */ + msb_data = ((int16_t)((int8_t)aux_data[3])) * 32; + + /* Raw mag Y axis data */ + raw_mag_data.raw_datay = (int16_t)(msb_data | aux_data[2]); + + /* Mag Z axis data */ + aux_data[4] = BMM150_GET_BITS(aux_data[4], BMM150_DATA_Z); + + /* Shift the MSB data to left by 7 bits */ + /* Multiply by 128 to get the shift left by 7 value */ + msb_data = ((int16_t)((int8_t)aux_data[5])) * 128; + + /* Raw mag Z axis data */ + raw_mag_data.raw_dataz = (int16_t)(msb_data | aux_data[4]); + + /* Mag R-HALL data */ + aux_data[6] = BMM150_GET_BITS(aux_data[6], BMM150_DATA_RHALL); + raw_mag_data.raw_data_r = (uint16_t)(((uint16_t)aux_data[7] << 6) | aux_data[6]); + + /* Compensated Mag X data in int16_t format */ + mag_data->x = compensate_x(raw_mag_data.raw_datax, raw_mag_data.raw_data_r, dev); + + /* Compensated Mag Y data in int16_t format */ + mag_data->y = compensate_y(raw_mag_data.raw_datay, raw_mag_data.raw_data_r, dev); + + /* Compensated Mag Z data in int16_t format */ + mag_data->z = compensate_z(raw_mag_data.raw_dataz, raw_mag_data.raw_data_r, dev); + } + + return rslt; +} + +/****************************************************************************/ +/**\name INTERNAL APIs */ + +/*! + * @brief This internal API is used to validate the device structure pointer for + * null conditions. + */ +static int8_t null_ptr_check(const struct bmm150_dev *dev) +{ + int8_t rslt; + + if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL) || + (dev->intf_ptr == NULL)) + { + /* Device structure pointer is not valid */ + rslt = BMM150_E_NULL_PTR; + } + else + { + /* Device structure is fine */ + rslt = BMM150_OK; + } + + return rslt; +} + +/*! + * @brief This internal API sets/resets the power control bit of 0x4B register. + */ +static int8_t set_power_control_bit(uint8_t pwrcntrl_bit, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data = 0; + + /* Power control register 0x4B is read */ + rslt = bmm150_get_regs(BMM150_REG_POWER_CONTROL, ®_data, 1, dev); + + /* Proceed if everything is fine until now */ + if (rslt == BMM150_OK) + { + /* Sets the value of power control bit */ + reg_data = BMM150_SET_BITS_POS_0(reg_data, BMM150_PWR_CNTRL, pwrcntrl_bit); + rslt = bmm150_set_regs(BMM150_REG_POWER_CONTROL, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + /* Store the power control bit + * value in dev structure + */ + dev->pwr_cntrl_bit = pwrcntrl_bit; + } + } + + return rslt; +} + +/*! + * @brief This internal API reads the trim registers of the sensor and stores + * the trim values in the "trim_data" of device structure. + */ +static int8_t read_trim_registers(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t trim_x1y1[2] = {0}; + uint8_t trim_xyz_data[4] = {0}; + uint8_t trim_xy1xy2[10] = {0}; + uint16_t temp_msb = 0; + + /* Trim register value is read */ + rslt = bmm150_get_regs(BMM150_DIG_X1, trim_x1y1, 2, dev); + + if (rslt == BMM150_OK) + { + rslt = bmm150_get_regs(BMM150_DIG_Z4_LSB, trim_xyz_data, 4, dev); + + if (rslt == BMM150_OK) + { + rslt = bmm150_get_regs(BMM150_DIG_Z2_LSB, trim_xy1xy2, 10, dev); + + if (rslt == BMM150_OK) + { + /* Trim data which is read is updated + * in the device structure + */ + dev->trim_data.dig_x1 = (int8_t)trim_x1y1[0]; + dev->trim_data.dig_y1 = (int8_t)trim_x1y1[1]; + dev->trim_data.dig_x2 = (int8_t)trim_xyz_data[2]; + dev->trim_data.dig_y2 = (int8_t)trim_xyz_data[3]; + temp_msb = ((uint16_t)trim_xy1xy2[3]) << 8; + dev->trim_data.dig_z1 = (uint16_t)(temp_msb | trim_xy1xy2[2]); + temp_msb = ((uint16_t)trim_xy1xy2[1]) << 8; + dev->trim_data.dig_z2 = (int16_t)(temp_msb | trim_xy1xy2[0]); + temp_msb = ((uint16_t)trim_xy1xy2[7]) << 8; + dev->trim_data.dig_z3 = (int16_t)(temp_msb | trim_xy1xy2[6]); + temp_msb = ((uint16_t)trim_xyz_data[1]) << 8; + dev->trim_data.dig_z4 = (int16_t)(temp_msb | trim_xyz_data[0]); + dev->trim_data.dig_xy1 = trim_xy1xy2[9]; + dev->trim_data.dig_xy2 = (int8_t)trim_xy1xy2[8]; + temp_msb = ((uint16_t)(trim_xy1xy2[5] & 0x7F)) << 8; + dev->trim_data.dig_xyz1 = (uint16_t)(temp_msb | trim_xy1xy2[4]); + } + } + } + + return rslt; +} + +/*! + * @brief This internal API writes the op_mode value in the Opmode bits + * (bits 1 and 2) of 0x4C register. + */ +static int8_t write_op_mode(uint8_t op_mode, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + + /* Read the 0x4C register */ + rslt = bmm150_get_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + /* Set the op_mode value in Opmode bits of 0x4C */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_OP_MODE, op_mode); + rslt = bmm150_set_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + } + + return rslt; +} + +/*! + * @brief This internal API sets the device from suspend to sleep mode + * by setting the power control bit to '1' of 0x4B register + */ +static int8_t suspend_to_sleep_mode(struct bmm150_dev *dev) +{ + int8_t rslt; + + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); + + /* Proceed if null check is fine */ + if (rslt == BMM150_OK) + { + if (dev->pwr_cntrl_bit == BMM150_POWER_CNTRL_DISABLE) + { + rslt = set_power_control_bit(BMM150_POWER_CNTRL_ENABLE, dev); + + /* Start-up time delay of 3ms */ + dev->delay_us(BMM150_START_UP_TIME, dev->intf_ptr); + } + } + + return rslt; +} + +/*! + * @brief This internal API sets the xy repetition value in the 0x51 register. + */ +static int8_t set_xy_rep(const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t rep_xy; + + /* Set the xy repetition */ + rep_xy = settings->xy_rep; + rslt = bmm150_set_regs(BMM150_REG_REP_XY, &rep_xy, 1, dev); + + return rslt; +} + +/*! + * @brief This internal API sets the z repetition value in the 0x52 register. + */ +static int8_t set_z_rep(const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t rep_z; + + /* Set the z repetition */ + rep_z = settings->z_rep; + rslt = bmm150_set_regs(BMM150_REG_REP_Z, &rep_z, 1, dev); + + return rslt; +} + +/*! + * @brief This internal API is used to set the output data rate of the sensor. + */ +static int8_t set_odr(const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + + /* Read the 0x4C register */ + rslt = bmm150_get_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + /* Set the ODR value */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_ODR, settings->data_rate); + rslt = bmm150_set_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + } + + return rslt; +} + +/*! + * @brief This internal API sets the preset mode ODR and repetition settings. + */ +static int8_t set_odr_xyz_rep(const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + + /* Set the ODR */ + rslt = set_odr(settings, dev); + + if (rslt == BMM150_OK) + { + /* Set the XY-repetitions number */ + rslt = set_xy_rep(settings, dev); + + if (rslt == BMM150_OK) + { + /* Set the Z-repetitions number */ + rslt = set_z_rep(settings, dev); + } + } + + return rslt; +} + +/*! + * @brief This internal API is used to enable or disable the magnetic + * measurement of x,y,z axes based on the value of xyz_axes_control. + */ +static int8_t set_control_measurement_xyz(const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + + rslt = bmm150_get_regs(BMM150_REG_AXES_ENABLE, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + /* Set the axes to be enabled/disabled */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_CONTROL_MEASURE, settings->xyz_axes_control); + rslt = bmm150_set_regs(BMM150_REG_AXES_ENABLE, ®_data, 1, dev); + } + + return rslt; +} + +/*! + * @brief This internal API is used to identify the settings which the user + * wants to modify in the sensor. + */ +static uint8_t are_settings_changed(uint16_t sub_settings, uint16_t desired_settings) +{ + uint8_t settings_changed; + + if (sub_settings & desired_settings) + { + /* User wants to modify this particular settings */ + settings_changed = BMM150_TRUE; + } + else + { + /* User don't want to modify this particular settings */ + settings_changed = BMM150_FALSE; + } + + return settings_changed; +} + +/*! + * @brief This API sets the ODR , measurement axes control , + * repetition values of xy,z. + */ +static int8_t mode_settings(uint16_t desired_settings, const struct bmm150_settings *settings, struct bmm150_dev *dev) +{ + int8_t rslt = BMM150_E_INVALID_CONFIG; + + if (desired_settings & BMM150_SEL_DATA_RATE) + { + /* Sets the ODR */ + rslt = set_odr(settings, dev); + } + + if (desired_settings & BMM150_SEL_CONTROL_MEASURE) + { + /* Enables/Disables the control measurement axes */ + rslt = set_control_measurement_xyz(settings, dev); + } + + if (desired_settings & BMM150_SEL_XY_REP) + { + /* Sets the XY repetition */ + rslt = set_xy_rep(settings, dev); + } + + if (desired_settings & BMM150_SEL_Z_REP) + { + /* Sets the Z repetition */ + rslt = set_z_rep(settings, dev); + } + + return rslt; +} + +/*! + * @brief This internal API is used to parse and store the sensor + * settings in the device structure + */ +static void parse_setting(const uint8_t *reg_data, struct bmm150_settings *settings) +{ + /* Parse all the w/r registers and update the + * current sensor settings in the dev structure + */ + settings->z_rep = reg_data[7]; + settings->xy_rep = reg_data[6]; + settings->int_settings.high_threshold = reg_data[5]; + settings->int_settings.low_threshold = reg_data[4]; + settings->xyz_axes_control = BMM150_GET_BITS(reg_data[3], BMM150_CONTROL_MEASURE); + settings->int_settings.drdy_pin_en = BMM150_GET_BITS(reg_data[3], BMM150_DRDY_EN); + settings->int_settings.int_pin_en = BMM150_GET_BITS(reg_data[3], BMM150_INT_PIN_EN); + settings->int_settings.drdy_polarity = BMM150_GET_BITS(reg_data[3], BMM150_DRDY_POLARITY); + settings->int_settings.int_latch = BMM150_GET_BITS(reg_data[3], BMM150_INT_LATCH); + settings->int_settings.int_polarity = BMM150_GET_BITS_POS_0(reg_data[3], BMM150_INT_POLARITY); + settings->int_settings.data_overrun_en = BMM150_GET_BITS(reg_data[2], BMM150_DATA_OVERRUN_INT); + settings->int_settings.overflow_int_en = BMM150_GET_BITS(reg_data[2], BMM150_OVERFLOW_INT); + settings->int_settings.high_int_en = BMM150_GET_BITS(reg_data[2], BMM150_HIGH_THRESHOLD_INT); + settings->int_settings.low_int_en = BMM150_GET_BITS_POS_0(reg_data[2], BMM150_LOW_THRESHOLD_INT); + settings->data_rate = BMM150_GET_BITS(reg_data[1], BMM150_ODR); +} + +/*! + * @brief This API is used to enable the interrupts and map them to the + * corresponding interrupt pins and specify the pin characteristics like the + * polarity , latch settings for the interrupt pins. + */ +static int8_t interrupt_pin_settings(uint16_t desired_settings, + const struct bmm150_settings *settings, + struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + struct bmm150_int_ctrl_settings int_settings; + + rslt = bmm150_get_regs(BMM150_REG_AXES_ENABLE, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + int_settings = settings->int_settings; + if (desired_settings & BMM150_SEL_DRDY_PIN_EN) + { + /* Enables the Data ready interrupt and + * maps it to the DRDY pin of the sensor + */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_DRDY_EN, int_settings.drdy_pin_en); + } + + if (desired_settings & BMM150_SEL_INT_PIN_EN) + { + /* Sets interrupt pin enable */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_INT_PIN_EN, int_settings.int_pin_en); + } + + if (desired_settings & BMM150_SEL_DRDY_POLARITY) + { + /* Sets Data ready pin's polarity */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_DRDY_POLARITY, int_settings.drdy_polarity); + } + + if (desired_settings & BMM150_SEL_INT_LATCH) + { + /* Sets Interrupt in latched or non-latched mode */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_INT_LATCH, int_settings.int_latch); + } + + if (desired_settings & BMM150_SEL_INT_POLARITY) + { + /* Sets Interrupt pin's polarity */ + reg_data = BMM150_SET_BITS_POS_0(reg_data, BMM150_INT_POLARITY, int_settings.int_polarity); + } + + /* Set the interrupt configurations in the 0x4E register */ + rslt = bmm150_set_regs(BMM150_REG_AXES_ENABLE, ®_data, 1, dev); + } + + return rslt; +} + +/*! + * @brief This API is used to enable data overrun , overflow interrupts and + * enable/disable high/low threshold interrupts for x,y,z axis based on the + * threshold values set by the user in the High threshold (0x50) and + * Low threshold (0x4F) registers. + */ +static int8_t interrupt_config(uint16_t desired_settings, const struct bmm150_settings *settings, + struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + struct bmm150_int_ctrl_settings int_settings; + + rslt = bmm150_get_regs(BMM150_REG_INT_CONFIG, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + int_settings = settings->int_settings; + if (desired_settings & BMM150_SEL_DATA_OVERRUN_INT) + { + /* Sets Data overrun interrupt */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_DATA_OVERRUN_INT, int_settings.data_overrun_en); + } + + if (desired_settings & BMM150_SEL_OVERFLOW_INT) + { + /* Sets Data overflow interrupt */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_OVERFLOW_INT, int_settings.overflow_int_en); + } + + if (desired_settings & BMM150_SEL_HIGH_THRESHOLD_INT) + { + /* Sets high threshold interrupt */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_HIGH_THRESHOLD_INT, int_settings.high_int_en); + } + + if (desired_settings & BMM150_SEL_LOW_THRESHOLD_INT) + { + /* Sets low threshold interrupt */ + reg_data = BMM150_SET_BITS_POS_0(reg_data, BMM150_LOW_THRESHOLD_INT, int_settings.low_int_en); + } + + /* Set the interrupt configurations in the 0x4D register */ + rslt = bmm150_set_regs(BMM150_REG_INT_CONFIG, ®_data, 1, dev); + } + + return rslt; +} + +/*! + * @brief This API is used to write the user specified High/Low threshold value + * as a reference to generate the high/low threshold interrupt. + */ +static int8_t interrupt_threshold_settings(uint16_t desired_settings, + const struct bmm150_settings *settings, + struct bmm150_dev *dev) +{ + int8_t rslt = BMM150_E_INVALID_CONFIG; + uint8_t reg_data; + + if (desired_settings & BMM150_SEL_LOW_THRESHOLD_SETTING) + { + /* Sets the Low threshold value to trigger interrupt */ + reg_data = settings->int_settings.low_threshold; + rslt = bmm150_set_regs(BMM150_REG_LOW_THRESHOLD, ®_data, 1, dev); + } + + if (desired_settings & BMM150_SEL_HIGH_THRESHOLD_SETTING) + { + /* Sets the High threshold value to trigger interrupt */ + reg_data = settings->int_settings.high_threshold; + rslt = bmm150_set_regs(BMM150_REG_HIGH_THRESHOLD, ®_data, 1, dev); + } + + return rslt; +} + +#ifdef BMM150_USE_FLOATING_POINT + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer x axis data(micro-tesla) in float. + */ +static float compensate_x(int16_t mag_data_x, uint16_t data_rhall, const struct bmm150_dev *dev) +{ + float retval = 0; + float process_comp_x0; + float process_comp_x1; + float process_comp_x2; + float process_comp_x3; + float process_comp_x4; + + /* Overflow condition check */ + if ((mag_data_x != BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP) && (data_rhall != 0) && (dev->trim_data.dig_xyz1 != 0)) + { + /* Processing compensation equations */ + process_comp_x0 = (((float)dev->trim_data.dig_xyz1) * 16384.0f / data_rhall); + retval = (process_comp_x0 - 16384.0f); + process_comp_x1 = ((float)dev->trim_data.dig_xy2) * (retval * retval / 268435456.0f); + process_comp_x2 = process_comp_x1 + retval * ((float)dev->trim_data.dig_xy1) / 16384.0f; + process_comp_x3 = ((float)dev->trim_data.dig_x2) + 160.0f; + process_comp_x4 = mag_data_x * ((process_comp_x2 + 256.0f) * process_comp_x3); + retval = ((process_comp_x4 / 8192.0f) + (((float)dev->trim_data.dig_x1) * 8.0f)) / 16.0f; + } + else + { + /* Overflow, set output to 0.0f */ + retval = BMM150_OVERFLOW_OUTPUT_FLOAT; + } + + return retval; +} + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer y axis data(micro-tesla) in float. + */ +static float compensate_y(int16_t mag_data_y, uint16_t data_rhall, const struct bmm150_dev *dev) +{ + float retval = 0; + float process_comp_y0; + float process_comp_y1; + float process_comp_y2; + float process_comp_y3; + float process_comp_y4; + + /* Overflow condition check */ + if ((mag_data_y != BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP) && (data_rhall != 0) && (dev->trim_data.dig_xyz1 != 0)) + { + /* Processing compensation equations */ + process_comp_y0 = ((float)dev->trim_data.dig_xyz1) * 16384.0f / data_rhall; + retval = process_comp_y0 - 16384.0f; + process_comp_y1 = ((float)dev->trim_data.dig_xy2) * (retval * retval / 268435456.0f); + process_comp_y2 = process_comp_y1 + retval * ((float)dev->trim_data.dig_xy1) / 16384.0f; + process_comp_y3 = ((float)dev->trim_data.dig_y2) + 160.0f; + process_comp_y4 = mag_data_y * (((process_comp_y2) + 256.0f) * process_comp_y3); + retval = ((process_comp_y4 / 8192.0f) + (((float)dev->trim_data.dig_y1) * 8.0f)) / 16.0f; + } + else + { + /* Overflow, set output to 0.0f */ + retval = BMM150_OVERFLOW_OUTPUT_FLOAT; + } + + return retval; +} + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer z axis data(micro-tesla) in float. + */ +static float compensate_z(int16_t mag_data_z, uint16_t data_rhall, const struct bmm150_dev *dev) +{ + float retval = 0; + float process_comp_z0; + float process_comp_z1; + float process_comp_z2; + float process_comp_z3; + float process_comp_z4; + float process_comp_z5; + + /* Overflow condition check */ + if ((mag_data_z != BMM150_OVERFLOW_ADCVAL_ZAXIS_HALL) && (dev->trim_data.dig_z2 != 0) && + (dev->trim_data.dig_z1 != 0) && (dev->trim_data.dig_xyz1 != 0) && (data_rhall != 0)) + { + /* Processing compensation equations */ + process_comp_z0 = ((float)mag_data_z) - ((float)dev->trim_data.dig_z4); + process_comp_z1 = ((float)data_rhall) - ((float)dev->trim_data.dig_xyz1); + process_comp_z2 = (((float)dev->trim_data.dig_z3) * process_comp_z1); + process_comp_z3 = ((float)dev->trim_data.dig_z1) * ((float)data_rhall) / 32768.0f; + process_comp_z4 = ((float)dev->trim_data.dig_z2) + process_comp_z3; + process_comp_z5 = (process_comp_z0 * 131072.0f) - process_comp_z2; + retval = (process_comp_z5 / ((process_comp_z4)*4.0f)) / 16.0f; + } + else + { + /* Overflow, set output to 0.0f */ + retval = BMM150_OVERFLOW_OUTPUT_FLOAT; + } + + return retval; +} + +#else + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer X axis data(micro-tesla) in int16_t. + */ +static int16_t compensate_x(int16_t mag_data_x, uint16_t data_rhall, const struct bmm150_dev *dev) +{ + int16_t retval; + uint16_t process_comp_x0 = 0; + int32_t process_comp_x1; + uint16_t process_comp_x2; + int32_t process_comp_x3; + int32_t process_comp_x4; + int32_t process_comp_x5; + int32_t process_comp_x6; + int32_t process_comp_x7; + int32_t process_comp_x8; + int32_t process_comp_x9; + int32_t process_comp_x10; + + /* Overflow condition check */ + if (mag_data_x != BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP) + { + if (data_rhall != 0) + { + /* Availability of valid data */ + process_comp_x0 = data_rhall; + } + else if (dev->trim_data.dig_xyz1 != 0) + { + process_comp_x0 = dev->trim_data.dig_xyz1; + } + else + { + process_comp_x0 = 0; + } + + if (process_comp_x0 != 0) + { + /* Processing compensation equations */ + process_comp_x1 = ((int32_t)dev->trim_data.dig_xyz1) * 16384; + process_comp_x2 = ((uint16_t)(process_comp_x1 / process_comp_x0)) - ((uint16_t)0x4000); + retval = ((int16_t)process_comp_x2); + process_comp_x3 = (((int32_t)retval) * ((int32_t)retval)); + process_comp_x4 = (((int32_t)dev->trim_data.dig_xy2) * (process_comp_x3 / 128)); + process_comp_x5 = (int32_t)(((int16_t)dev->trim_data.dig_xy1) * 128); + process_comp_x6 = ((int32_t)retval) * process_comp_x5; + process_comp_x7 = (((process_comp_x4 + process_comp_x6) / 512) + ((int32_t)0x100000)); + process_comp_x8 = ((int32_t)(((int16_t)dev->trim_data.dig_x2) + ((int16_t)0xA0))); + process_comp_x9 = ((process_comp_x7 * process_comp_x8) / 4096); + process_comp_x10 = ((int32_t)mag_data_x) * process_comp_x9; + retval = ((int16_t)(process_comp_x10 / 8192)); + retval = (retval + (((int16_t)dev->trim_data.dig_x1) * 8)) / 16; + } + else + { + retval = BMM150_OVERFLOW_OUTPUT; + } + } + else + { + /* Overflow condition */ + retval = BMM150_OVERFLOW_OUTPUT; + } + + return retval; +} + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer Y axis data(micro-tesla) in int16_t. + */ +static int16_t compensate_y(int16_t mag_data_y, uint16_t data_rhall, const struct bmm150_dev *dev) +{ + int16_t retval; + uint16_t process_comp_y0 = 0; + int32_t process_comp_y1; + uint16_t process_comp_y2; + int32_t process_comp_y3; + int32_t process_comp_y4; + int32_t process_comp_y5; + int32_t process_comp_y6; + int32_t process_comp_y7; + int32_t process_comp_y8; + int32_t process_comp_y9; + + /* Overflow condition check */ + if (mag_data_y != BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP) + { + if (data_rhall != 0) + { + /* Availability of valid data */ + process_comp_y0 = data_rhall; + } + else if (dev->trim_data.dig_xyz1 != 0) + { + process_comp_y0 = dev->trim_data.dig_xyz1; + } + else + { + process_comp_y0 = 0; + } + + if (process_comp_y0 != 0) + { + /* Processing compensation equations */ + process_comp_y1 = (((int32_t)dev->trim_data.dig_xyz1) * 16384) / process_comp_y0; + process_comp_y2 = ((uint16_t)process_comp_y1) - ((uint16_t)0x4000); + retval = ((int16_t)process_comp_y2); + process_comp_y3 = ((int32_t)retval) * ((int32_t)retval); + process_comp_y4 = ((int32_t)dev->trim_data.dig_xy2) * (process_comp_y3 / 128); + process_comp_y5 = ((int32_t)(((int16_t)dev->trim_data.dig_xy1) * 128)); + process_comp_y6 = ((process_comp_y4 + (((int32_t)retval) * process_comp_y5)) / 512); + process_comp_y7 = ((int32_t)(((int16_t)dev->trim_data.dig_y2) + ((int16_t)0xA0))); + process_comp_y8 = (((process_comp_y6 + ((int32_t)0x100000)) * process_comp_y7) / 4096); + process_comp_y9 = (((int32_t)mag_data_y) * process_comp_y8); + retval = (int16_t)(process_comp_y9 / 8192); + retval = (retval + (((int16_t)dev->trim_data.dig_y1) * 8)) / 16; + } + else + { + retval = BMM150_OVERFLOW_OUTPUT; + } + } + else + { + /* Overflow condition */ + retval = BMM150_OVERFLOW_OUTPUT; + } + + return retval; +} + +/*! + * @brief This internal API is used to obtain the compensated + * magnetometer Z axis data(micro-tesla) in int16_t. + */ +static int16_t compensate_z(int16_t mag_data_z, uint16_t data_rhall, const struct bmm150_dev *dev) +{ + int32_t retval; + int16_t process_comp_z0; + int32_t process_comp_z1; + int32_t process_comp_z2; + int32_t process_comp_z3; + int16_t process_comp_z4; + + if (mag_data_z != BMM150_OVERFLOW_ADCVAL_ZAXIS_HALL) + { + if ((dev->trim_data.dig_z2 != 0) && (dev->trim_data.dig_z1 != 0) && (data_rhall != 0) && + (dev->trim_data.dig_xyz1 != 0)) + { + /*Processing compensation equations */ + process_comp_z0 = ((int16_t)data_rhall) - ((int16_t)dev->trim_data.dig_xyz1); + process_comp_z1 = (((int32_t)dev->trim_data.dig_z3) * ((int32_t)(process_comp_z0))) / 4; + process_comp_z2 = (((int32_t)(mag_data_z - dev->trim_data.dig_z4)) * 32768); + process_comp_z3 = ((int32_t)dev->trim_data.dig_z1) * (((int16_t)data_rhall) * 2); + process_comp_z4 = (int16_t)((process_comp_z3 + (32768)) / 65536); + retval = ((process_comp_z2 - process_comp_z1) / (dev->trim_data.dig_z2 + process_comp_z4)); + + /* Saturate result to +/- 2 micro-tesla */ + if (retval > BMM150_POSITIVE_SATURATION_Z) + { + retval = BMM150_POSITIVE_SATURATION_Z; + } + else if (retval < BMM150_NEGATIVE_SATURATION_Z) + { + retval = BMM150_NEGATIVE_SATURATION_Z; + } + + /* Conversion of LSB to micro-tesla */ + retval = retval / 16; + } + else + { + retval = BMM150_OVERFLOW_OUTPUT; + } + } + else + { + /* Overflow condition */ + retval = BMM150_OVERFLOW_OUTPUT; + } + + return (int16_t)retval; +} + +#endif + +/*! + * @brief This internal API is used to perform the normal self test + * of the sensor and return the self test result as return value + */ +static int8_t perform_normal_self_test(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t self_test_bit; + + /* Triggers the start of normal self test */ + rslt = enable_normal_self_test(&self_test_bit, dev); + + /* Check for self test completion status */ + if ((rslt == BMM150_OK) && (self_test_bit == 0)) + { + /* Validates the self test results for all 3 axes */ + rslt = validate_normal_self_test(dev); + } + + return rslt; +} + +/*! + * @brief This internal API is used to enable the normal self test by setting + * the Self Test bit (bit0) of the 0x4C register, + * which triggers the start of self test + */ +static int8_t enable_normal_self_test(uint8_t *self_test_enable, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + uint8_t self_test_val; + + /* Read the data from register 0x4C */ + rslt = bmm150_get_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + /* Set the Self Test bit(bit0) of the 0x4C register */ + self_test_val = 1; + reg_data = BMM150_SET_BITS_POS_0(reg_data, BMM150_SELF_TEST, self_test_val); + + /* Write the data to 0x4C register to trigger self test */ + rslt = bmm150_set_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + dev->delay_us(BMM150_DELAY_NORMAL_SELF_TEST, dev->intf_ptr); + + if (rslt == BMM150_OK) + { + /* Read the data from register 0x4C */ + rslt = bmm150_get_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + + /* Self Test bit(bit0) is stored in self_test_enable, + * It will be reset to zero after the self test is over + */ + *self_test_enable = BMM150_GET_BITS_POS_0(reg_data, BMM150_SELF_TEST); + } + } + + return rslt; +} + +/*! + * @brief This internal API is used to validate the results of normal self test + * by using the self test status available in the bit0 of registers 0x42,0x44 + * and 0x46. + */ +static int8_t validate_normal_self_test(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t status; + uint8_t self_test_rslt[5]; + + /* Read the data from register 0x42 to 0x46 */ + rslt = bmm150_get_regs(BMM150_REG_DATA_X_LSB, self_test_rslt, BMM150_LEN_SELF_TEST, dev); + + if (rslt == BMM150_OK) + { + /* Parse and get the self test status bits */ + /* X-Self-Test (bit0) of 0x42 register is stored */ + self_test_rslt[0] = BMM150_GET_BITS_POS_0(self_test_rslt[0], BMM150_SELF_TEST); + + /* Y-Self-Test (bit0) of 0x44 register is stored */ + self_test_rslt[2] = BMM150_GET_BITS_POS_0(self_test_rslt[2], BMM150_SELF_TEST); + + /* Z-Self-Test (bit0) of 0x46 register is stored */ + self_test_rslt[4] = BMM150_GET_BITS_POS_0(self_test_rslt[4], BMM150_SELF_TEST); + + /* Combine the self test status and store it in the first + * 3 bits of the status variable for processing + */ + status = (uint8_t)((self_test_rslt[4] << 2) | (self_test_rslt[2] << 1) | self_test_rslt[0]); + + /* Validate status and store Self test result in "rslt" */ + if (status == BMM150_SELF_TEST_STATUS_SUCCESS) + { + /* Self test is success when all status bits are set */ + rslt = BMM150_OK; + } + else + { + if (status == BMM150_SELF_TEST_STATUS_XYZ_FAIL) + { + /* Self test - all axis fail condition */ + rslt = BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL; + } + else + { + /* Self test - some axis fail condition */ + rslt = (int8_t)status; + } + } + } + + return rslt; +} + +/*! + * @brief This internal API is used to perform advanced self test for Z axis + */ +static int8_t perform_adv_self_test(struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t self_test_current; + int16_t positive_data_z; + int16_t negative_data_z; + + /* Set the desired power mode ,axes control and repetition settings */ + rslt = adv_self_test_settings(dev); + + if (rslt == BMM150_OK) + { + /* Measure the Z axes data with positive self-test current */ + self_test_current = BMM150_ENABLE_POSITIVE_CURRENT; + rslt = adv_self_test_measurement(self_test_current, &positive_data_z, dev); + + if (rslt == BMM150_OK) + { + /* Measure the Z axes data with + * negative self-test current + */ + self_test_current = BMM150_ENABLE_NEGATIVE_CURRENT; + rslt = adv_self_test_measurement(self_test_current, &negative_data_z, dev); + + if (rslt == BMM150_OK) + { + /* Disable self-test current */ + self_test_current = BMM150_DISABLE_SELF_TEST_CURRENT; + rslt = set_adv_self_test_current(self_test_current, dev); + + if (rslt == BMM150_OK) + { + /* Validate the advanced self test */ + rslt = validate_adv_self_test(positive_data_z, negative_data_z); + } + } + } + } + + return rslt; +} + +/*! + * @brief This internal API is used to set the desired power mode , + * axes control and repetition settings for advanced self test + */ +static int8_t adv_self_test_settings(struct bmm150_dev *dev) +{ + int8_t rslt; + struct bmm150_settings settings; + + /* Set the power mode as sleep mode */ + settings.pwr_mode = BMM150_POWERMODE_SLEEP; + rslt = bmm150_set_op_mode(&settings, dev); + + if (rslt == BMM150_OK) + { + /* Disable XY-axis measurement */ + settings.xyz_axes_control = BMM150_DISABLE_XY_AXIS; + rslt = set_control_measurement_xyz(&settings, dev); + + if (rslt == BMM150_OK) + { + /* Repetition value is set as 0x04 */ + settings.z_rep = BMM150_SELF_TEST_REP_Z; + rslt = set_z_rep(&settings, dev); + } + } + + return rslt; +} + +/*! + * @brief This internal API is used to set the positive or negative value of + * self-test current and obtain the corresponding magnetometer z axis data + */ +static int8_t adv_self_test_measurement(uint8_t self_test_current, int16_t *data_z, struct bmm150_dev *dev) +{ + int8_t rslt; + struct bmm150_settings settings; + struct bmm150_mag_data mag_data; + + /* Set the advanced self test current as positive or + * negative based on the value of parameter "self_test_current" + */ + rslt = set_adv_self_test_current(self_test_current, dev); + + if (rslt == BMM150_OK) + { + /* Set the device in forced mode */ + settings.pwr_mode = BMM150_POWERMODE_FORCED; + rslt = bmm150_set_op_mode(&settings, dev); + + /* Delay to ensure measurement is complete */ + dev->delay_us(BMM150_DELAY_ADV_SELF_TEST, dev->intf_ptr); + + if (rslt == BMM150_OK) + { + /* Read Mag data and store the value of Z axis data */ + rslt = bmm150_read_mag_data(&mag_data, dev); + + if (rslt == BMM150_OK) + { + /* Mag Z axis data is stored */ + *data_z = mag_data.z; + } + } + } + + return rslt; +} + +/*! + * @brief This internal API is used to get the difference between the + * Z axis mag data obtained by positive and negative self-test current + * and validate whether the advanced self test is done successfully or not. + */ +static int8_t validate_adv_self_test(int16_t positive_data_z, int16_t negative_data_z) +{ + int32_t adv_self_test_rslt; + int8_t rslt; + + /* Advanced self test difference between the Z axis mag data + * obtained by the positive and negative self-test current + */ + adv_self_test_rslt = positive_data_z - negative_data_z; + + /* Advanced self test validation */ + /*Value of adv_self_test_rslt should be in between 180-240 micro-tesla */ + if ((adv_self_test_rslt > 180) && (adv_self_test_rslt < 240)) + { + /* Advanced self test success */ + rslt = BMM150_OK; + } + else + { + /* Advanced self test fail */ + rslt = BMM150_W_ADV_SELF_TEST_FAIL; + } + + return rslt; +} + +/*! + * @brief This internal API is used to set the self test current value in + * the Adv. ST bits (bit6 and bit7) of 0x4C register + */ +static int8_t set_adv_self_test_current(uint8_t self_test_current, struct bmm150_dev *dev) +{ + int8_t rslt; + uint8_t reg_data; + + /* Read the 0x4C register */ + rslt = bmm150_get_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + + if (rslt == BMM150_OK) + { + /* Set the self test current value in the Adv. ST bits + * (bit6 and bit7) of 0x4c register + */ + reg_data = BMM150_SET_BITS(reg_data, BMM150_ADV_SELF_TEST, self_test_current); + rslt = bmm150_set_regs(BMM150_REG_OP_MODE, ®_data, 1, dev); + } + + return rslt; +} diff --git a/components/SensorLib/src/bosch/BMM150/bmm150.h b/components/SensorLib/src/bosch/BMM150/bmm150.h new file mode 100644 index 0000000..01f3aab --- /dev/null +++ b/components/SensorLib/src/bosch/BMM150/bmm150.h @@ -0,0 +1,479 @@ +/** +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bmm150.h +* @date 2020-06-03 +* @version v2.0.0 +* +*/ + +/*! + * @defgroup bmm150 BMM150 + */ + +#ifndef _BMM150_H +#define _BMM150_H + +/*! CPP guard */ +#ifdef __cplusplus +extern "C" { +#endif + +/********************************************************************/ +/* header files */ + +#include "bmm150_defs.h" + +/********************************************************************/ +/* (extern) variable declarations */ +/********************************************************************/ +/* function prototype declarations */ + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiInit Initialization + * @brief Initialize the sensor and device structure + */ + +/*! + * \ingroup bmm150ApiInit + * \page bmm150_api_bmm150_init bmm150_init + * \code + * int8_t bmm150_init(struct bmm150_dev *dev); + * \endcode + * @details This API is the entry point, Call this API before using other APIs. + * This API reads the chip-id of the sensor which is the first step to + * verify the sensor and also it configures the read mechanism of SPI and + * I2C interface. + * + * @param[in,out] dev : Structure instance of bmm150_dev + * @note : Refer user guide for detailed info. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_init(struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiRegs Registers + * @brief Read / Write data to the given register address of the sensor + */ + +/*! + * \ingroup bmm150ApiRegs + * \page bmm150_api_bmm150_set_regs bmm150_set_regs + * \code + * int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev); + * \endcode + * @details This API writes the given data to the register address + * of the sensor. + * + * @param[in] reg_addr : Register address from where the data to be written. + * @param[in] reg_data : Pointer to data buffer which is to be written + * in the reg_addr of sensor. + * @param[in] len : No of bytes of data to write.. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev); + +/*! + * \ingroup bmm150ApiRegs + * \page bmm150_api_bmm150_get_regs bmm150_get_regs + * \code + * int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev) + * \endcode + * @details This API reads the data from the given register address of sensor. + * + * @param[in] reg_addr : Register address from where the data to be read + * @param[out] reg_data : Pointer to data buffer to store the read data. + * @param[in] len : No of bytes of data to be read. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiSoftreset Soft reset + * @brief Perform soft reset of the sensor + */ + +/*! + * \ingroup bmm150ApiSoftreset + * \page bmm150_api_bmm150_soft_reset bmm150_soft_reset + * \code + * int8_t bmm150_soft_reset(struct bmm150_dev *dev); + * \endcode + * @details This API is used to perform soft-reset of the sensor + * where all the registers are reset to their default values except 0x4B. + * + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_soft_reset(struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiPowermode Power mode + * @brief Set / Get power mode of the sensor + */ + +/*! + * \ingroup bmm150ApiPowermode + * \page bmm150_api_bmm150_set_op_mode bmm150_set_op_mode + * \code + * int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev); + * \endcode + * @details This API is used to set the power mode of the sensor. + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + *@verbatim + * settings->pwr_mode | Power mode + * ------------------------|----------------------- + * 0x00 | BMM150_POWERMODE_NORMAL + * 0x01 | BMM150_POWERMODE_FORCED + * 0x03 | BMM150_POWERMODE_SLEEP + * 0x04 | BMM150_POWERMODE_SUSPEND + *@endverbatim + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev); + +/*! + * \ingroup bmm150ApiPowermode + * \page bmm150_api_bmm150_get_op_mode bmm150_get_op_mode + * \code + * int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev); + * \endcode + * @details This API is used to get the power mode of the sensor. + * + * @param[out] op_mode : power mode of the sensor. + * @param[in] dev : Structure instance of bmm150_dev. + * + *@verbatim + * op_mode | Power mode + * -------------|----------------------- + * 0x00 | BMM150_POWERMODE_NORMAL + * 0x01 | BMM150_POWERMODE_FORCED + * 0x03 | BMM150_POWERMODE_SLEEP + * 0x04 | BMM150_POWERMODE_SUSPEND + *@endverbatim + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiPresetmode Preset mode + * @brief Set preset mode of the sensor + */ + +/*! + * \ingroup bmm150ApiPresetmode + * \page bmm150_api_bmm150_set_presetmode bmm150_set_presetmode + * \code + * int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev); + * \endcode + * @details This API is used to set the preset mode of the sensor. + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + *@verbatim + * settings->preset_mode | Preset mode + * ---------------------------|---------------------------------- + * 0x01 | BMM150_PRESETMODE_LOWPOWER + * 0x02 | BMM150_PRESETMODE_REGULAR + * 0x03 | BMM150_PRESETMODE_HIGHACCURACY + * 0x04 | BMM150_PRESETMODE_ENHANCED + *@endverbatim + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiSensorSettings Sensor Settings + * @brief Set / Get sensor settings of the sensor + */ + +/*! + * \ingroup bmm150ApiSensorSettings + * \page bmm150_api_bmm150_set_sensor_settings bmm150_set_sensor_settings + * \code + * int8_t bmm150_set_sensor_settings(uint16_t desired_settings, const struct bmm150_settings *settings, struct bmm150_dev *dev); + * \endcode + * @details This API sets the sensor settings based on the desired_settings + * and the dev structure configuration + * + * @param[in] desired_settings : Selection macro for selecting the setting. + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @note Assign the sensor setting macros (multiple macros can be + * set by doing a bitwise-OR operation) to the desired_settings parameter + * of this API to perform the corresponding setting. + * + * @note threshold interrupt for each axes are set by using bitwise AND + * operation of the following macros + * - BMM150_THRESHOLD_X + * - BMM150_THRESHOLD_Y + * - BMM150_THRESHOLD_Z + * + *@verbatim + * desired_settings | Selected sensor setting macros + * -------------------|-------------------------------- + * 0x0001 | BMM150_SEL_DATA_RATE + * 0x0002 | BMM150_SEL_CONTROL_MEASURE + * 0x0004 | BMM150_SEL_XY_REP + * 0x0008 | BMM150_SEL_Z_REP + * 0x0010 | BMM150_SEL_DRDY_PIN_EN + * 0x0020 | BMM150_SEL_INT_PIN_EN + * 0x0040 | BMM150_SEL_DRDY_POLARITY + * 0x0080 | BMM150_SEL_INT_LATCH + * 0x0100 | BMM150_SEL_INT_POLARITY + * 0x0200 | BMM150_SEL_DATA_OVERRUN_INT + * 0x0400 | BMM150_SEL_OVERFLOW_INT + * 0x0800 | BMM150_SEL_HIGH_THRESHOLD_INT + * 0x1000 | BMM150_SEL_LOW_THRESHOLD_INT + * 0x2000 | BMM150_SEL_LOW_THRESHOLD_SETTING + * 0x4000 | BMM150_SEL_HIGH_THRESHOLD_SETTING + *@endverbatim + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_set_sensor_settings(uint16_t desired_settings, + const struct bmm150_settings *settings, + struct bmm150_dev *dev); + +/*! + * \ingroup bmm150ApiSensorSettings + * \page bmm150_api_bmm150_get_sensor_settings bmm150_get_sensor_settings + * \code + * int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev); + * \endcode + * @details This API gets all the sensor settings and updates the dev structure + * + * @param[in] settings : Structure instance of bmm150_settings. + * @param[in] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiMagData Read magnetometer data + * @brief Read magnetometer data + */ + +/*! + * \ingroup bmm150ApiMagData + * \page bmm150_api_bmm150_read_mag_data bmm150_read_mag_data + * \code + * int8_t bbmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev); + * \endcode + * @details This API reads the magnetometer data from registers 0x42 to 0x49 + * and updates the dev structure with compensated mag data in micro-tesla + * + * @param[in] mag_data : Structure instance of bmm150_mag_data. + * @param[in,out] dev : Structure instance of bmm150_dev. + * + * @note The output mag data can be obtained either in int16_t or float format + * using this API. + * @note Enable the macro "BMM150_USE_FLOATING_POINT" in the bmm150_defs.h + * file and call this API to get the mag data in float, + * disable this macro to get the mag data in int16_t format + * + *@verbatim + * Mag data output(micro-tesla) | Mag data in dev structure(int16_t/float) + * --------------------------------|------------------------------------------ + * X-axis data | mag_data->x + * Y-axis data | mag_data->y + * Z-axis data | mag_data->z + *@endverbatim + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiSelftest Self test + * @brief Perform self test + */ + +/*! + * \ingroup bmm150ApiSelftest + * \page bmm150_api_bmm150_perform_self_test bmm150_perform_self_test + * \code + * int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev); + * \endcode + * @details This API is used to perform the complete self test + * (both normal and advanced) for the BMM150 sensor + * + * @param[in] self_test_mode : The type of self test to be performed + * @param[in] dev : Structure instance of bmm150_dev. + * + *@verbatim + * self_test_mode | Self test enabled + * --------------------|-------------------------- + * 0 | BMM150_SELF_TEST_NORMAL + * 1 | BMM150_SELF_TEST_ADVANCED + *@endverbatim + * + * @note The return value of this API gives us the result of self test. + * + * @note Performing advanced self test does soft reset of the sensor, User can + * set the desired settings after performing the advanced self test. + * + * @return Result of API execution status and self test result. + * @retval 0 BMM150_OK + * @retval 1 BMM150_W_NORMAL_SELF_TEST_YZ_FAIL + * @retval 2 BMM150_W_NORMAL_SELF_TEST_XZ_FAIL + * @retval 3 BMM150_W_NORMAL_SELF_TEST_Z_FAIL + * @retval 4 BMM150_W_NORMAL_SELF_TEST_XY_FAIL + * @retval 5 BMM150_W_NORMAL_SELF_TEST_Y_FAIL + * @retval 6 BMM150_W_NORMAL_SELF_TEST_X_FAIL + * @retval 7 BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL + * @retval 8 BMM150_W_ADV_SELF_TEST_FAIL + */ +int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiInt Interrupt status + * @brief Obtain interrupt staus flags + */ + +/*! + * \ingroup bmm150ApiInt + * \page bmm150_api_bmm150_get_interrupt_status bmm150_get_interrupt_status + * \code + * int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev); + * \endcode + * @details This API obtains the status flags of all interrupt + * which is used to check for the assertion of interrupts + * + * @param[in,out] dev : Structure instance of bmm150_dev. + * + * @note The status flags of all the interrupts are stored in the + * dev->int_status. + * + * @note The value of dev->int_status is performed a bitwise AND operation + * with predefined interrupt status macros to find the interrupt status + * which is either set or reset. + * + * Ex. + * if (dev->int_status & BMM150_INT_ASSERTED_DRDY) + * { + * Occurrence of data ready interrupt + * } else { + * No interrupt occurred + * } + * + * @return Result of API execution status and self test result. + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev); + +/** + * \ingroup bmm150 + * \defgroup bmm150ApiAux Compensate magnetometer data + * @brief Compensation of magnetometer data + */ + +/*! + * \ingroup bmm150ApiAux + * \page bmm150_api_bmm150_aux_mag_data bmm150_aux_mag_data + * \code + * int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev); + * \endcode + * @details This API is used to compensate the raw mag data + * + * @param[in] aux_data : Raw mag data obtained from BMI160 registers + * @param[in] mag_data : Structure instance of bmm150_mag_data. + * @param[in,out] dev : Structure instance of bmm150_dev. + * + * @return Result of API execution status and self test result. + * @retval 0 -> Success + * @retval >0 -> Warning + * @retval <0 -> Fail + */ +int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev); + +#ifdef __cplusplus +} +#endif /* End of CPP guard */ + +#endif /* _BMM150_H */ diff --git a/components/SensorLib/src/bosch/BMM150/bmm150_defs.h b/components/SensorLib/src/bosch/BMM150/bmm150_defs.h new file mode 100644 index 0000000..897edb9 --- /dev/null +++ b/components/SensorLib/src/bosch/BMM150/bmm150_defs.h @@ -0,0 +1,643 @@ +/** +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bmm150_defs.h +* @date 2020-06-03 +* @version v2.0.0 +* +*/ + +/*! \file bmm150_defs.h */ + +#ifndef _BMM150_DEFS_H +#define _BMM150_DEFS_H + +/******************************************************************************/ +/*! @name Header includes */ +/******************************************************************************/ +#ifdef __KERNEL__ +#include +#else +#include +#include +#endif + +/******************************************************************************/ +/*! @name Common macros */ +/******************************************************************************/ +#ifdef __KERNEL__ +#if (LONG_MAX) > 0x7fffffff +#define __have_long64 1 +#elif (LONG_MAX) == 0x7fffffff +#define __have_long32 1 +#endif +#endif + +#if !defined(UINT8_C) +#define INT8_C(x) x +#if (INT_MAX) > 0x7f +#define UINT8_C(x) x +#else +#define UINT8_C(x) x##U +#endif +#endif + +#if !defined(UINT16_C) +#define INT16_C(x) x +#if (INT_MAX) > 0x7fff +#define UINT16_C(x) x +#else +#define UINT16_C(x) x##U +#endif +#endif + +#if !defined(INT32_C) && !defined(UINT32_C) +#if __have_long32 +#define INT32_C(x) x##L +#define UINT32_C(x) x##UL +#else +#define INT32_C(x) x +#define UINT32_C(x) x##U +#endif +#endif + +#if !defined(INT64_C) && !defined(UINT64_C) +#if __have_long64 +#define INT64_C(x) x##L +#define UINT64_C(x) x##UL +#else +#define INT64_C(x) x##LL +#define UINT64_C(x) x##ULL +#endif +#endif + +/*! @name C standard macros */ +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *) 0) +#endif +#endif + +/******************************************************************************/ +/*! @name Compiler switch macros Definitions */ +/******************************************************************************/ +#ifndef BMM150_USE_FLOATING_POINT /*< Check if floating point (using BMM150_USE_FLOATING_POINT) is enabled */ +#ifndef BMM150_USE_FIXED_POINT /*< If floating point is not enabled then enable BMM150_USE_FIXED_POINT */ +#define BMM150_USE_FIXED_POINT +#endif +#endif + +/******************************************************************************/ +/*! @name General Macro Definitions */ +/******************************************************************************/ +/*! @name API success code */ +#define BMM150_OK INT8_C(0) + +/*! @name To define TRUE or FALSE */ +#define BMM150_TRUE UINT8_C(1) +#define BMM150_FALSE UINT8_C(0) + +/*! @name API error codes */ +#define BMM150_E_NULL_PTR INT8_C(-1) +#define BMM150_E_DEV_NOT_FOUND INT8_C(-2) +#define BMM150_E_INVALID_CONFIG INT8_C(-3) +#define BMM150_E_COM_FAIL INT8_C(-4) + +/*! @name API warning codes */ +#define BMM150_W_NORMAL_SELF_TEST_YZ_FAIL INT8_C(1) +#define BMM150_W_NORMAL_SELF_TEST_XZ_FAIL INT8_C(2) +#define BMM150_W_NORMAL_SELF_TEST_Z_FAIL INT8_C(3) +#define BMM150_W_NORMAL_SELF_TEST_XY_FAIL INT8_C(4) +#define BMM150_W_NORMAL_SELF_TEST_Y_FAIL INT8_C(5) +#define BMM150_W_NORMAL_SELF_TEST_X_FAIL INT8_C(6) +#define BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL INT8_C(7) +#define BMM150_W_ADV_SELF_TEST_FAIL INT8_C(8) + +/*! @name CHIP ID & SOFT RESET VALUES */ +#define BMM150_CHIP_ID UINT8_C(0x32) +#define BMM150_SET_SOFT_RESET UINT8_C(0x82) + +/*! @name POWER MODE DEFINTIONS */ +#define BMM150_POWERMODE_NORMAL UINT8_C(0x00) +#define BMM150_POWERMODE_FORCED UINT8_C(0x01) +#define BMM150_POWERMODE_SLEEP UINT8_C(0x03) +#define BMM150_POWERMODE_SUSPEND UINT8_C(0x04) + +/*! @name Power mode settings */ +#define BMM150_POWER_CNTRL_DISABLE UINT8_C(0x00) +#define BMM150_POWER_CNTRL_ENABLE UINT8_C(0x01) + +/*! @name Sensor delay time settings */ +#define BMM150_DELAY_SOFT_RESET UINT8_C(1000) +#define BMM150_DELAY_NORMAL_SELF_TEST UINT8_C(2000) +#define BMM150_START_UP_TIME UINT8_C(3000) +#define BMM150_DELAY_ADV_SELF_TEST UINT8_C(4000) + +/*! @name ENABLE/DISABLE DEFINITIONS */ +#define BMM150_XYZ_CHANNEL_ENABLE UINT8_C(0x00) +#define BMM150_XYZ_CHANNEL_DISABLE UINT8_C(0x07) + +/*! @name Register Address */ +#define BMM150_REG_CHIP_ID UINT8_C(0x40) +#define BMM150_REG_DATA_X_LSB UINT8_C(0x42) +#define BMM150_REG_DATA_READY_STATUS UINT8_C(0x48) +#define BMM150_REG_INTERRUPT_STATUS UINT8_C(0x4A) +#define BMM150_REG_POWER_CONTROL UINT8_C(0x4B) +#define BMM150_REG_OP_MODE UINT8_C(0x4C) +#define BMM150_REG_INT_CONFIG UINT8_C(0x4D) +#define BMM150_REG_AXES_ENABLE UINT8_C(0x4E) +#define BMM150_REG_LOW_THRESHOLD UINT8_C(0x4F) +#define BMM150_REG_HIGH_THRESHOLD UINT8_C(0x50) +#define BMM150_REG_REP_XY UINT8_C(0x51) +#define BMM150_REG_REP_Z UINT8_C(0x52) + +/*! @name Macros to select the sensor settings to be set by the user + * These values are internal for API implementation. Don't relate this to + * data sheet. + */ +#define BMM150_SEL_DATA_RATE UINT16_C(1) +#define BMM150_SEL_CONTROL_MEASURE UINT16_C(1 << 1) +#define BMM150_SEL_XY_REP UINT16_C(1 << 2) +#define BMM150_SEL_Z_REP UINT16_C(1 << 3) +#define BMM150_SEL_DRDY_PIN_EN UINT16_C(1 << 4) +#define BMM150_SEL_INT_PIN_EN UINT16_C(1 << 5) +#define BMM150_SEL_DRDY_POLARITY UINT16_C(1 << 6) +#define BMM150_SEL_INT_LATCH UINT16_C(1 << 7) +#define BMM150_SEL_INT_POLARITY UINT16_C(1 << 8) +#define BMM150_SEL_DATA_OVERRUN_INT UINT16_C(1 << 9) +#define BMM150_SEL_OVERFLOW_INT UINT16_C(1 << 10) +#define BMM150_SEL_HIGH_THRESHOLD_INT UINT16_C(1 << 11) +#define BMM150_SEL_LOW_THRESHOLD_INT UINT16_C(1 << 12) +#define BMM150_SEL_LOW_THRESHOLD_SETTING UINT16_C(1 << 13) +#define BMM150_SEL_HIGH_THRESHOLD_SETTING UINT16_C(1 << 14) + +/*! @name DATA RATE DEFINITIONS */ +#define BMM150_DATA_RATE_10HZ UINT8_C(0x00) +#define BMM150_DATA_RATE_02HZ UINT8_C(0x01) +#define BMM150_DATA_RATE_06HZ UINT8_C(0x02) +#define BMM150_DATA_RATE_08HZ UINT8_C(0x03) +#define BMM150_DATA_RATE_15HZ UINT8_C(0x04) +#define BMM150_DATA_RATE_20HZ UINT8_C(0x05) +#define BMM150_DATA_RATE_25HZ UINT8_C(0x06) +#define BMM150_DATA_RATE_30HZ UINT8_C(0x07) +#define BMM150_ODR_MAX UINT8_C(0x07) +#define BMM150_ODR_MSK UINT8_C(0x38) +#define BMM150_ODR_POS UINT8_C(0x03) + +/*! @name TRIM REGISTERS */ +/* Trim Extended Registers */ +#define BMM150_DIG_X1 UINT8_C(0x5D) +#define BMM150_DIG_Y1 UINT8_C(0x5E) +#define BMM150_DIG_Z4_LSB UINT8_C(0x62) +#define BMM150_DIG_Z4_MSB UINT8_C(0x63) +#define BMM150_DIG_X2 UINT8_C(0x64) +#define BMM150_DIG_Y2 UINT8_C(0x65) +#define BMM150_DIG_Z2_LSB UINT8_C(0x68) +#define BMM150_DIG_Z2_MSB UINT8_C(0x69) +#define BMM150_DIG_Z1_LSB UINT8_C(0x6A) +#define BMM150_DIG_Z1_MSB UINT8_C(0x6B) +#define BMM150_DIG_XYZ1_LSB UINT8_C(0x6C) +#define BMM150_DIG_XYZ1_MSB UINT8_C(0x6D) +#define BMM150_DIG_Z3_LSB UINT8_C(0x6E) +#define BMM150_DIG_Z3_MSB UINT8_C(0x6F) +#define BMM150_DIG_XY2 UINT8_C(0x70) +#define BMM150_DIG_XY1 UINT8_C(0x71) + +/*! @name Threshold interrupt setting macros for x,y,z axes selection */ +#define BMM150_THRESHOLD_X UINT8_C(0x06) +#define BMM150_THRESHOLD_Y UINT8_C(0x05) +#define BMM150_THRESHOLD_Z UINT8_C(0x03) + +#define BMM150_HIGH_THRESHOLD_INT_MSK UINT8_C(0x38) +#define BMM150_HIGH_THRESHOLD_INT_POS UINT8_C(0x03) +#define BMM150_LOW_THRESHOLD_INT_MSK UINT8_C(0x07) + +/*! @name User configurable interrupt setting macros */ +#define BMM150_INT_ENABLE UINT8_C(0x01) +#define BMM150_INT_DISABLE UINT8_C(0x00) +#define BMM150_ACTIVE_HIGH_POLARITY UINT8_C(0x01) +#define BMM150_ACTIVE_LOW_POLARITY UINT8_C(0x00) +#define BMM150_LATCHED UINT8_C(0x01) +#define BMM150_NON_LATCHED UINT8_C(0x00) + +/*! @name Interrupt status */ +#define BMM150_INT_THRESHOLD_X_LOW UINT16_C(0x0001) +#define BMM150_INT_THRESHOLD_Y_LOW UINT16_C(0x0002) +#define BMM150_INT_THRESHOLD_Z_LOW UINT16_C(0x0004) +#define BMM150_INT_THRESHOLD_X_HIGH UINT16_C(0x0008) +#define BMM150_INT_THRESHOLD_Y_HIGH UINT16_C(0x0010) +#define BMM150_INT_THRESHOLD_Z_HIGH UINT16_C(0x0020) +#define BMM150_INT_DATA_OVERFLOW UINT16_C(0x0040) +#define BMM150_INT_DATA_OVERRUN UINT16_C(0x0080) +#define BMM150_INT_DATA_READY UINT16_C(0x0100) + +#define BMM150_DRDY_EN_MSK UINT8_C(0x80) +#define BMM150_DRDY_EN_POS UINT8_C(0x07) +#define BMM150_DRDY_POLARITY_MSK UINT8_C(0x04) +#define BMM150_DRDY_POLARITY_POS UINT8_C(0x02) +#define BMM150_INT_PIN_EN_MSK UINT8_C(0x40) +#define BMM150_INT_PIN_EN_POS UINT8_C(0x06) +#define BMM150_INT_LATCH_MSK UINT8_C(0x02) +#define BMM150_INT_LATCH_POS UINT8_C(0x01) +#define BMM150_INT_POLARITY_MSK UINT8_C(0x01) +#define BMM150_DRDY_STATUS_MSK UINT8_C(0x01) + +/*! @name Interrupt status macros */ +#define BMM150_INT_ASSERTED_DRDY UINT16_C(0x0100) +#define BMM150_INT_ASSERTED_LOW_THRES UINT16_C(0x0007) +#define BMM150_INT_ASSERTED_HIGH_THRES UINT16_C(0x0380) + +/*! @name Power control bit macros */ +#define BMM150_PWR_CNTRL_MSK UINT8_C(0x01) +#define BMM150_CONTROL_MEASURE_MSK UINT8_C(0x38) +#define BMM150_CONTROL_MEASURE_POS UINT8_C(0x03) +#define BMM150_POWER_CONTROL_BIT_MSK UINT8_C(0x01) +#define BMM150_POWER_CONTROL_BIT_POS UINT8_C(0x00) + +/*! @name Data macros */ +#define BMM150_DATA_X_MSK UINT8_C(0xF8) +#define BMM150_DATA_X_POS UINT8_C(0x03) + +#define BMM150_DATA_Y_MSK UINT8_C(0xF8) +#define BMM150_DATA_Y_POS UINT8_C(0x03) + +#define BMM150_DATA_Z_MSK UINT8_C(0xFE) +#define BMM150_DATA_Z_POS UINT8_C(0x01) + +#define BMM150_DATA_RHALL_MSK UINT8_C(0xFC) +#define BMM150_DATA_RHALL_POS UINT8_C(0x02) + +#define BMM150_DATA_OVERRUN_INT_MSK UINT8_C(0x80) +#define BMM150_DATA_OVERRUN_INT_POS UINT8_C(0x07) + +#define BMM150_OVERFLOW_INT_MSK UINT8_C(0x40) +#define BMM150_OVERFLOW_INT_POS UINT8_C(0x06) + +/*! @name OVERFLOW DEFINITIONS */ +#define BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP INT16_C(-4096) +#define BMM150_OVERFLOW_ADCVAL_ZAXIS_HALL INT16_C(-16384) +#define BMM150_OVERFLOW_OUTPUT INT16_C(-32768) +#define BMM150_NEGATIVE_SATURATION_Z INT16_C(-32767) +#define BMM150_POSITIVE_SATURATION_Z INT16_C(32767) +#ifdef BMM150_USE_FLOATING_POINT +#define BMM150_OVERFLOW_OUTPUT_FLOAT 0.0f +#endif + +/*! @name PRESET MODE DEFINITIONS */ +#define BMM150_PRESETMODE_LOWPOWER UINT8_C(0x01) +#define BMM150_PRESETMODE_REGULAR UINT8_C(0x02) +#define BMM150_PRESETMODE_HIGHACCURACY UINT8_C(0x03) +#define BMM150_PRESETMODE_ENHANCED UINT8_C(0x04) + +#define BMM150_OP_MODE_MSK UINT8_C(0x06) +#define BMM150_OP_MODE_POS UINT8_C(0x01) + +/*! @name PRESET MODES - REPETITIONS-XY RATES */ +#define BMM150_REPXY_LOWPOWER UINT8_C(0x01) +#define BMM150_REPXY_REGULAR UINT8_C(0x04) +#define BMM150_REPXY_ENHANCED UINT8_C(0x07) +#define BMM150_REPXY_HIGHACCURACY UINT8_C(0x17) + +/*! @name PRESET MODES - REPETITIONS-Z RATES */ +#define BMM150_REPZ_LOWPOWER UINT8_C(0x01) +#define BMM150_REPZ_REGULAR UINT8_C(0x07) +#define BMM150_REPZ_ENHANCED UINT8_C(0x0D) +#define BMM150_REPZ_HIGHACCURACY UINT8_C(0x29) + +/*! @name Self test settings */ +#define BMM150_DISABLE_XY_AXIS UINT8_C(0x03) +#define BMM150_SELF_TEST_REP_Z UINT8_C(0x04) + +/*! @name Self test selection macros */ +#define BMM150_SELF_TEST_NORMAL UINT8_C(0) +#define BMM150_SELF_TEST_ADVANCED UINT8_C(1) + +/*! @name Advanced self-test current settings */ +#define BMM150_DISABLE_SELF_TEST_CURRENT UINT8_C(0x00) +#define BMM150_ENABLE_NEGATIVE_CURRENT UINT8_C(0x02) +#define BMM150_ENABLE_POSITIVE_CURRENT UINT8_C(0x03) + +/*! @name Normal self-test status */ +#define BMM150_SELF_TEST_STATUS_XYZ_FAIL UINT8_C(0x00) +#define BMM150_SELF_TEST_STATUS_SUCCESS UINT8_C(0x07) + +#define BMM150_SELF_TEST_MSK UINT8_C(0x01) +#define BMM150_ADV_SELF_TEST_MSK UINT8_C(0xC0) +#define BMM150_ADV_SELF_TEST_POS UINT8_C(0x06) + +/*! @name Register read lengths */ +#define BMM150_LEN_SELF_TEST UINT8_C(5) +#define BMM150_LEN_SETTING_DATA UINT8_C(8) +#define BMM150_LEN_XYZR_DATA UINT8_C(8) + +/*! @name Boundary check macros */ +#define BMM150_BOUNDARY_MAXIMUM UINT8_C(0) +#define BMM150_BOUNDARY_MINIMUM UINT8_C(1) + +/*! @name Macro to SET and GET BITS of a register*/ +#define BMM150_SET_BITS(reg_data, bitname, data) \ + ((reg_data & ~(bitname##_MSK)) | \ + ((data << bitname##_POS) & bitname##_MSK)) + +#define BMM150_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \ + (bitname##_POS)) + +#define BMM150_SET_BITS_POS_0(reg_data, bitname, data) \ + ((reg_data & ~(bitname##_MSK)) | \ + (data & bitname##_MSK)) + +#define BMM150_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) + +/********************************************************/ + +/*! + * @brief Interface selection Enums + */ +enum bmm150_intf { + /*! SPI interface */ + BMM150_SPI_INTF, + /*! I2C interface */ + BMM150_I2C_INTF +}; + +/******************************************************************************/ +/*! @name Function Pointers */ +/******************************************************************************/ +#ifndef BMM150_INTF_RET_TYPE +#define BMM150_INTF_RET_TYPE int8_t +#endif + +#ifndef BMM150_INTF_RET_SUCCESS +#define BMM150_INTF_RET_SUCCESS INT8_C(0) +#endif + +/*! + * @brief Bus communication function pointer which should be mapped to + * the platform specific read functions of the user + * + * @param[in] reg_addr : 8bit register address of the sensor + * @param[out] reg_data : Data from the specified address + * @param[in] length : Length of the reg_data array + * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors + * for interface related callbacks + * @retval 0 for Success + * @retval Non-zero for Failure + */ +typedef BMM150_INTF_RET_TYPE (*bmm150_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, + void *intf_ptr); + +/*! + * @brief Bus communication function pointer which should be mapped to + * the platform specific write functions of the user + * + * @param[in] reg_addr : 8bit register address of the sensor + * @param[out] reg_data : Data to the specified address + * @param[in] length : Length of the reg_data array + * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors + * for interface related callbacks + * @retval 0 for Success + * @retval Non-zero for Failure + * + */ +typedef BMM150_INTF_RET_TYPE (*bmm150_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, + void *intf_ptr); + +/*! + * @brief Delay function pointer which should be mapped to + * delay function of the user + * + * @param period : The time period in microseconds + * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors + * for interface related callbacks + */ +typedef void (*bmm150_delay_us_fptr_t)(uint32_t period, void *intf_ptr); + +/******************************************************************************/ +/*! @name Structure Declarations */ +/******************************************************************************/ + +/*! + * @brief bmm150 trim data structure + */ +struct bmm150_trim_registers { + /*! trim x1 data */ + int8_t dig_x1; + + /*! trim y1 data */ + int8_t dig_y1; + + /*! trim x2 data */ + int8_t dig_x2; + + /*! trim y2 data */ + int8_t dig_y2; + + /*! trim z1 data */ + uint16_t dig_z1; + + /*! trim z2 data */ + int16_t dig_z2; + + /*! trim z3 data */ + int16_t dig_z3; + + /*! trim z4 data */ + int16_t dig_z4; + + /*! trim xy1 data */ + uint8_t dig_xy1; + + /*! trim xy2 data */ + int8_t dig_xy2; + + /*! trim xyz1 data */ + uint16_t dig_xyz1; +}; + +/*! + * @brief bmm150 interrupt pin settings + */ +struct bmm150_int_ctrl_settings { + /*! Data ready interrupt enable */ + uint8_t drdy_pin_en; + + /*! Threshold and overflow interrupts enable */ + uint8_t int_pin_en; + + /*! Data ready interrupt polarity Active high/low */ + uint8_t drdy_polarity; + + /*! Interrupt pin - Latched or Non-latched */ + uint8_t int_latch; + + /*! Interrupt polarity Active high/low */ + uint8_t int_polarity; + + /*! Data overrun interrupt enable */ + uint8_t data_overrun_en; + + /*! Overflow interrupt enable */ + uint8_t overflow_int_en; + + /*! high interrupt enable/disable axis selection */ + uint8_t high_int_en; + + /*! low interrupt enable/disable axis selection */ + uint8_t low_int_en; + + /*! low threshold limit */ + uint8_t low_threshold; + + /*! high threshold limit */ + uint8_t high_threshold; +}; + +/*! + * @brief bmm150 sensor settings + */ +struct bmm150_settings { + /*! Control measurement of XYZ axes */ + uint8_t xyz_axes_control; + + /*! Power mode of sensor */ + uint8_t pwr_mode; + + /*! Data rate value (ODR) */ + uint8_t data_rate; + + /*! XY Repetitions */ + uint8_t xy_rep; + + /*! Z Repetitions */ + uint8_t z_rep; + + /*! Preset mode of sensor */ + uint8_t preset_mode; + + /*! Interrupt configuration settings */ + struct bmm150_int_ctrl_settings int_settings; +}; + +/*! + * @brief bmm150 un-compensated (raw) magnetometer data + */ +struct bmm150_raw_mag_data { + /*! Raw mag X data */ + int16_t raw_datax; + + /*! Raw mag Y data */ + int16_t raw_datay; + + /*! Raw mag Z data */ + int16_t raw_dataz; + + /*! Raw mag resistance value */ + uint16_t raw_data_r; +}; + +#ifdef BMM150_USE_FLOATING_POINT + +/*! + * @brief bmm150 compensated magnetometer data in float + */ +struct bmm150_mag_data { + /*! compensated mag X data */ + float x; + + /*! compensated mag Y data */ + float y; + + /*! compensated mag Z data */ + float z; +}; + +#else + +/*! + * @brief bmm150 compensated magnetometer data in int16_t format + */ +struct bmm150_mag_data { + /*! compensated mag X data */ + int16_t x; + + /*! compensated mag Y data */ + int16_t y; + + /*! compensated mag Z data */ + int16_t z; +}; + +#endif + +/*! + * @brief bmm150 device structure + */ +struct bmm150_dev { + /*! Chip Id */ + uint8_t chip_id; + + /*! SPI/I2C Interface */ + enum bmm150_intf intf; + + /*! + * The interface pointer is used to enable the user + * to link their interface descriptors for reference during the + * implementation of the read and write interfaces to the + * hardware. + */ + void *intf_ptr; + + /*! Variable that holds result of read/write function */ + BMM150_INTF_RET_TYPE intf_rslt; + + /*! Bus read function pointer */ + bmm150_read_fptr_t read; + + /*! Bus write function pointer */ + bmm150_write_fptr_t write; + + /*! delay(in us) function pointer */ + bmm150_delay_us_fptr_t delay_us; + + /*! Trim registers */ + struct bmm150_trim_registers trim_data; + + /*! Interrupt status */ + uint16_t int_status; + + /*! Power control bit value */ + uint8_t pwr_cntrl_bit; +}; + +#endif /* BMM150_DEFS_H_ */ diff --git a/components/SensorLib/src/bosch/BoschParse.cpp b/components/SensorLib/src/bosch/BoschParse.cpp new file mode 100644 index 0000000..1b42c97 --- /dev/null +++ b/components/SensorLib/src/bosch/BoschParse.cpp @@ -0,0 +1,181 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file BoschParse.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-30 + * + */ +#include "BoschParse.h" + +std::vector BoschParse::bhyEventVector; +std::vector BoschParse::bhyParseEventVector; +uint8_t SensorEventCbList::current_id = 1; +uint8_t ParseCallBackList::current_id = 1; + +void BoschParse::parseData(const struct bhy2_fifo_parse_data_info *fifo, void *user_data) +{ + int8_t size = fifo->data_size - 1; + +#ifdef LOG_PORT + LOG_PORT.print("Sensor: "); + LOG_PORT.print(fifo->sensor_id); + LOG_PORT.print(" size: "); + LOG_PORT.print(fifo->data_size); + LOG_PORT.print(" value:"); + for (uint8_t i = 0; i < size; i++) { + LOG_PORT.printf("%04x", fifo->data_ptr[i]); + LOG_PORT.print(" "); + } + LOG_PORT.println(); +#endif + + for (uint32_t i = 0; i < bhyParseEventVector.size(); i++) { + ParseCallBackList_t entry = bhyParseEventVector[i]; + if (entry.cb ) { + if (entry.id == fifo->sensor_id) { + if (entry.cb) { + entry.cb(fifo->sensor_id, fifo->data_ptr, size, fifo->time_stamp); + } + } + } + } +} + +void BoschParse::parseMetaEvent(const struct bhy2_fifo_parse_data_info *callback_info, void *user_data) +{ + (void)user_data; + + uint8_t meta_event_type = callback_info->data_ptr[0]; + uint8_t byte1 = callback_info->data_ptr[1]; + uint8_t byte2 = callback_info->data_ptr[2]; + const char *event_text; + // Remove warning + (void)byte1; + (void)byte2; + (void)event_text; + uint8_t *accuracy = (uint8_t *)user_data; + + if (callback_info->sensor_id == BHY2_SYS_ID_META_EVENT) { + event_text = "[META EVENT]"; + } else if (callback_info->sensor_id == BHY2_SYS_ID_META_EVENT_WU) { + event_text = "[META EVENT WAKE UP]"; + } else { + return; + } + + switch (meta_event_type) { + case BHY2_META_EVENT_FLUSH_COMPLETE: + log_i("%s Flush complete for sensor id %u", event_text, byte1); + break; + case BHY2_META_EVENT_SAMPLE_RATE_CHANGED: + log_i("%s Sample rate changed for sensor id %u", event_text, byte1); + break; + case BHY2_META_EVENT_POWER_MODE_CHANGED: + log_i("%s Power mode changed for sensor id %u", event_text, byte1); + break; + case BHY2_META_EVENT_ALGORITHM_EVENTS: + log_i("%s Algorithm event", event_text); + break; + case BHY2_META_EVENT_SENSOR_STATUS: + log_i("%s Accuracy for sensor id %u changed to %u", event_text, byte1, byte2); + if (accuracy) { + *accuracy = byte2; + } + break; + case BHY2_META_EVENT_BSX_DO_STEPS_MAIN: + log_i("%s BSX event (do steps main)", event_text); + break; + case BHY2_META_EVENT_BSX_DO_STEPS_CALIB: + log_i("%s BSX event (do steps calib)", event_text); + break; + case BHY2_META_EVENT_BSX_GET_OUTPUT_SIGNAL: + log_i("%s BSX event (get output signal)", event_text); + break; + case BHY2_META_EVENT_SENSOR_ERROR: + log_i("%s Sensor id %u reported error 0x%02X", event_text, byte1, byte2); + break; + case BHY2_META_EVENT_FIFO_OVERFLOW: + log_i("%s FIFO overflow", event_text); + break; + case BHY2_META_EVENT_DYNAMIC_RANGE_CHANGED: + log_i("%s Dynamic range changed for sensor id %u", event_text, byte1); + break; + case BHY2_META_EVENT_FIFO_WATERMARK: + log_i("%s FIFO watermark reached", event_text); + break; + case BHY2_META_EVENT_INITIALIZED: + log_i("%s Firmware initialized. Firmware version %u", event_text, ((uint16_t)byte2 << 8) | byte1); + break; + case BHY2_META_TRANSFER_CAUSE: + log_i("%s Transfer cause for sensor id %u", event_text, byte1); + break; + case BHY2_META_EVENT_SENSOR_FRAMEWORK: + log_i("%s Sensor framework event for sensor id %u", event_text, byte1); + break; + case BHY2_META_EVENT_RESET: + log_i("%s Reset event", event_text); + break; + case BHY2_META_EVENT_SPACER: + return; + default: + log_i("%s Unknown meta event with id: %u", event_text, meta_event_type); + break; + } + + for (uint32_t i = 0; i < bhyEventVector.size(); i++) { + SensorEventCbList_t entry = bhyEventVector[i]; + if (entry.cb ) { + if (entry.event == meta_event_type) { + if (entry.cb) { + entry.cb(meta_event_type, callback_info->data_ptr, callback_info->data_size); + } + } + } + } +} + + +void BoschParse::parseDebugMessage(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref) +{ + uint32_t s, ns; + uint64_t tns; + uint8_t msg_length = 0; + uint8_t debug_msg[17] = { 0 }; /* Max payload size is 16 bytes, adds a trailing zero if the payload is full */ + + if (!callback_info) { + log_i("Null reference"); + + return; + } + + time_to_s_ns(*callback_info->time_stamp, &s, &ns, &tns); + + msg_length = callback_info->data_ptr[0]; + + memcpy(debug_msg, &callback_info->data_ptr[1], msg_length); + debug_msg[msg_length] = '\0'; /* Terminate the string */ + + log_i("[DEBUG MSG]; T: %lu.%09lu; %s", s, ns, debug_msg); +} \ No newline at end of file diff --git a/components/SensorLib/src/bosch/BoschParse.h b/components/SensorLib/src/bosch/BoschParse.h new file mode 100644 index 0000000..6b5f107 --- /dev/null +++ b/components/SensorLib/src/bosch/BoschParse.h @@ -0,0 +1,58 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file BoschParse.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-30 + * + */ +#pragma once + +#include "SensorCommon.tpp" +#include "SensorBhy2Define.h" +#include "bosch/bhy2_parse.h" +#include "bosch/common/common.h" +#include +#include + + +enum BoschOrientation { + BHY2_DIRECTION_TOP_RIGHT, + BHY2_DIRECTION_TOP_LEFT, + BHY2_DIRECTION_BOTTOM_LEFT, + BHY2_DIRECTION_BOTTOM_RIGHT, +}; + +class BoschParse +{ +public: + static std::vector bhyEventVector; + static std::vector bhyParseEventVector; + + static void parseData(const struct bhy2_fifo_parse_data_info *fifo, void *user_data); + + static void parseMetaEvent(const struct bhy2_fifo_parse_data_info *callback_info, void *user_data); + + static void parseDebugMessage(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); +}; diff --git a/components/SensorLib/src/bosch/SensorBhy2Define.h b/components/SensorLib/src/bosch/SensorBhy2Define.h new file mode 100644 index 0000000..45b689f --- /dev/null +++ b/components/SensorLib/src/bosch/SensorBhy2Define.h @@ -0,0 +1,203 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBhy2Define.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-09-30 + * + */ +#pragma once + +#include +#include + +#define BHI260AP_SLAVE_ADDRESS_L 0x28 +#define BHI260AP_SLAVE_ADDRESS_H 0x29 +#define BHY_PROCESS_BUFFER_SIZE 512 + +#define BHY2_RLST_CHECK(ret, str, val) \ + do \ + { \ + if (ret) \ + { \ + log_e(str); \ + return val; \ + } \ + } while (0) + +typedef void (*BhyEventCb)(uint8_t event, uint8_t *data, uint32_t size); +typedef void (*BhyParseDataCallback)(uint8_t sensor_id, uint8_t *data, uint32_t size,uint64_t *timestamp); + + + +typedef struct SensorEventCbList { + static uint8_t current_id; + uint8_t id; + BhyEventCb cb; + uint8_t event; + uint8_t *data; + SensorEventCbList() : id(current_id++), cb(NULL), event(0), data(NULL) + { + } +} SensorEventCbList_t; + + +typedef struct ParseCallBackList { + static uint8_t current_id; + uint8_t id; + BhyParseDataCallback cb; + uint32_t data_length; + uint8_t *data; + ParseCallBackList() : id(current_id++), cb(NULL), data_length(0), data(NULL) + { + } +} ParseCallBackList_t; + +enum BhySensorEvent { + BHY2_EVENT_FLUSH_COMPLETE = 1, + BHY2_EVENT_SAMPLE_RATE_CHANGED, + BHY2_EVENT_POWER_MODE_CHANGED, + BHY2_EVENT_ALGORITHM_EVENTS = 5, + BHY2_EVENT_SENSOR_STATUS, + BHY2_EVENT_BSX_DO_STEPS_MAIN, + BHY2_EVENT_BSX_DO_STEPS_CALIB, + BHY2_EVENT_BSX_GET_OUTPUT_SIGNAL, + BHY2_EVENT_SENSOR_ERROR = 11, + BHY2_EVENT_FIFO_OVERFLOW, + BHY2_EVENT_DYNAMIC_RANGE_CHANGED, + BHY2_EVENT_FIFO_WATERMARK, + BHY2_EVENT_INITIALIZED = 16, + BHY2_EVENT_TRANSFER_CAUSE, + BHY2_EVENT_SENSOR_FRAMEWORK, + BHY2_EVENT_RESET, +}; + + +enum BhySensorID { + SENSOR_ID_ACC_PASS = 1, /* Accelerometer passthrough */ + SENSOR_ID_ACC_RAW = 3, /* Accelerometer uncalibrated */ + SENSOR_ID_ACC = 4, /* Accelerometer corrected */ + SENSOR_ID_ACC_BIAS = 5, /* Accelerometer offset */ + SENSOR_ID_ACC_WU = 6, /* Accelerometer corrected wake up */ + SENSOR_ID_ACC_RAW_WU = 7, /* Accelerometer uncalibrated wake up */ + SENSOR_ID_GYRO_PASS = 10, /* Gyroscope passthrough */ + SENSOR_ID_GYRO_RAW = 12, /* Gyroscope uncalibrated */ + SENSOR_ID_GYRO = 13, /* Gyroscope corrected */ + SENSOR_ID_GYRO_BIAS = 14, /* Gyroscope offset */ + SENSOR_ID_GYRO_WU = 15, /* Gyroscope wake up */ + SENSOR_ID_GYRO_RAW_WU = 16, /* Gyroscope uncalibrated wake up */ + SENSOR_ID_MAG_PASS = 19, /* Magnetometer passthrough */ + SENSOR_ID_MAG_RAW = 21, /* Magnetometer uncalibrated */ + SENSOR_ID_MAG = 22, /* Magnetometer corrected */ + SENSOR_ID_MAG_BIAS = 23, /* Magnetometer offset */ + SENSOR_ID_MAG_WU = 24, /* Magnetometer wake up */ + SENSOR_ID_MAG_RAW_WU = 25, /* Magnetometer uncalibrated wake up */ + SENSOR_ID_GRA = 28, /* Gravity vector */ + SENSOR_ID_GRA_WU = 29, /* Gravity vector wake up */ + SENSOR_ID_LACC = 31, /* Linear acceleration */ + SENSOR_ID_LACC_WU = 32, /* Linear acceleration wake up */ + SENSOR_ID_RV = 34, /* Rotation vector */ + SENSOR_ID_RV_WU = 35, /* Rotation vector wake up */ + SENSOR_ID_GAMERV = 37, /* Game rotation vector */ + SENSOR_ID_GAMERV_WU = 38, /* Game rotation vector wake up */ + SENSOR_ID_GEORV = 40, /* Geo-magnetic rotation vector */ + SENSOR_ID_GEORV_WU = 41, /* Geo-magnetic rotation vector wake up */ + SENSOR_ID_ORI = 43, /* Orientation */ + SENSOR_ID_ORI_WU = 44, /* Orientation wake up */ + SENSOR_ID_TILT_DETECTOR = 48, /* Tilt detector */ + SENSOR_ID_STD = 50, /* Step detector */ + SENSOR_ID_STC = 52, /* Step counter */ + SENSOR_ID_STC_WU = 53, /* Step counter wake up */ + SENSOR_ID_SIG = 55, /* Significant motion */ + SENSOR_ID_WAKE_GESTURE = 57, /* Wake gesture */ + SENSOR_ID_GLANCE_GESTURE = 59, /* Glance gesture */ + SENSOR_ID_PICKUP_GESTURE = 61, /* Pickup gesture */ + SENSOR_ID_AR = 63, /* Activity recognition */ + SENSOR_ID_WRIST_TILT_GESTURE = 67, /* Wrist tilt gesture */ + SENSOR_ID_DEVICE_ORI = 69, /* Device orientation */ + SENSOR_ID_DEVICE_ORI_WU = 70, /* Device orientation wake up */ + SENSOR_ID_STATIONARY_DET = 75, /* Stationary detect */ + SENSOR_ID_MOTION_DET = 77, /* Motion detect */ + SENSOR_ID_ACC_BIAS_WU = 91, /* Accelerometer offset wake up */ + SENSOR_ID_GYRO_BIAS_WU = 92, /* Gyroscope offset wake up */ + SENSOR_ID_MAG_BIAS_WU = 93, /* Magnetometer offset wake up */ + SENSOR_ID_STD_WU = 94, /* Step detector wake up */ + SENSOR_ID_BSEC = 115, /* BSEC 1.x output */ + SENSOR_ID_TEMP = 128, /* Temperature */ + SENSOR_ID_BARO = 129, /* Barometer */ + SENSOR_ID_HUM = 130, /* Humidity */ + SENSOR_ID_GAS = 131, /* Gas */ + SENSOR_ID_TEMP_WU = 132, /* Temperature wake up */ + SENSOR_ID_BARO_WU = 133, /* Barometer wake up */ + SENSOR_ID_HUM_WU = 134, /* Humidity wake up */ + SENSOR_ID_GAS_WU = 135, /* Gas wake up */ + SENSOR_ID_STC_HW = 136, /* Hardware Step counter */ + SENSOR_ID_STD_HW = 137, /* Hardware Step detector */ + SENSOR_ID_SIG_HW = 138, /* Hardware Significant motion */ + SENSOR_ID_STC_HW_WU = 139, /* Hardware Step counter wake up */ + SENSOR_ID_STD_HW_WU = 140, /* Hardware Step detector wake up */ + SENSOR_ID_SIG_HW_WU = 141, /* Hardware Significant motion wake up */ + SENSOR_ID_ANY_MOTION = 142, /* Any motion */ + SENSOR_ID_ANY_MOTION_WU = 143, /* Any motion wake up */ + SENSOR_ID_EXCAMERA = 144, /* External camera trigger */ + SENSOR_ID_GPS = 145, /* GPS */ + SENSOR_ID_LIGHT = 146, /* Light */ + SENSOR_ID_PROX = 147, /* Proximity */ + SENSOR_ID_LIGHT_WU = 148, /* Light wake up */ + SENSOR_ID_PROX_WU = 149, /* Proximity wake up */ + SENSOR_ID_BSEC_LEGACY = 171, /* BSEC 1.x output (legacy, deprecated) */ + SENSOR_DEBUG_DATA_EVENT = 250, /* Binary or string debug data */ + SENSOR_TIMESTAMP_SMALL_DELTA = 251, /* Incremental time change from previous read */ + SENSOR_TIMESTAMP_SMALL_DELTA_WU = 245, /* Incremental time change from previous read wake up */ + SENSOR_TIMESTAMP_LARGE_DELTA = 252, /* Incremental time change from previous read */ + SENSOR_TIMESTAMP_LARGE_DELTA_WU = 246, /* Incremental time change from previous read wake up */ + SENSOR_TIMESTAMP_FULL = 253, /* Incremental time change from previous read */ + SENSOR_TIMESTAMP_FULL_WU = 247, /* Incremental time change from previous read wake up */ + SENSOR_ALL_ID = 255 /* All Sensor parse event*/ +}; + + +#define SENSOR_EULER_ID SENSOR_ID_ORI_WU +#define QUAT_SENSOR_ID SENSOR_ID_RV + + + + + + + + + + + + + + + + + + + + + diff --git a/components/SensorLib/src/bosch/bhi3.c b/components/SensorLib/src/bosch/bhi3.c new file mode 100644 index 0000000..2670151 --- /dev/null +++ b/components/SensorLib/src/bosch/bhi3.c @@ -0,0 +1,730 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bhi3.c + * @date 2023-03-24 + * @version v1.6.0 + * + */ + +/*********************************************************************/ +/* system header files */ +#include +#include +#include + +/*********************************************************************/ +/* BHI3 SensorAPI header files */ +#include "bhi3.h" + +/*************************Private Functions***************************/ + +/*! + * @brief To set the Physical Sensor Control Parameters + */ +int8_t bhi3_physical_sensor_control_set_config(uint8_t sensor_id, + const uint8_t *payload, + uint16_t len, + uint8_t control_code, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + uint16_t cmnd_len = BHY2_LE24MUL(len + 1); /*1 byte added for control code */ + uint8_t cmnd[cmnd_len]; + + memset(cmnd, 0, cmnd_len); + cmnd[0] = BHI3_PHY_SENSOR_CTRL_CODE(BHI3_PHY_SENSOR_CTRL_WRITE, control_code); + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + if (payload == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + for (int i = 0; i < len; i++) + { + cmnd[i + 1] = *(payload + i); + } + + rslt = bhy2_set_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), cmnd, cmnd_len, dev); + } + } + + return rslt; +} + +/*! + * @brief To get the Physical Sensor Control Parameters + */ +int8_t bhi3_physical_sensor_control_get_config(uint8_t sensor_id, + uint8_t *payload, + uint32_t len, + uint8_t control_code, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t ret_len = 0; + + uint8_t cmnd[BHY2_COMMAND_HEADER_LEN] = {0}; + uint8_t rdbck[BHY2_LE24MUL(len)]; + + cmnd[0] = BHI3_PHY_SENSOR_CTRL_CODE(BHI3_PHY_SENSOR_CTRL_READ, control_code); + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_set_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), cmnd, BHY2_COMMAND_HEADER_LEN, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + rslt = bhy2_get_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), rdbck, BHY2_LE24MUL(len), &ret_len, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + memcpy(payload, &rdbck[1], len); /*0th element holds control code */ + } + + return rslt; +} + +/**************************Public Functions***************************/ + +/*! + * @brief To parse Wrist Gesture Detection Data + */ +int8_t bhi3_wrist_gesture_detect_parse_data(const uint8_t *data, bhi3_wrist_gesture_detect_t *output) +{ + int8_t rslt = BHY2_OK; + + if ((data == NULL) || (output == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + output->wrist_gesture = (enum bhi3_wrist_gesture_activity) * (data); + } + + return rslt; +} + +/*! + * @brief To set the Accelerometer Fast Offset Calibration + */ +int8_t bhi3_set_acc_foc(const struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER, + (uint8_t *)acc_foc, + BHI3_PHY_ACC_FOC_CTRL_LEN, + BHI3_PHY_ACC_FOC_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Accelerometer Fast Offset Calibration + */ +int8_t bhi3_get_acc_foc(struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER, + (uint8_t *)acc_foc, + BHI3_PHY_ACC_FOC_CTRL_LEN, + BHI3_PHY_ACC_FOC_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Accelerometer Power Mode + */ +int8_t bhi3_set_acc_power_mode(const uint8_t *acc_pwm, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER, + acc_pwm, + BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN, + BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Accelerometer Power Mode + */ +int8_t bhi3_get_acc_power_mode(uint8_t *acc_pwm, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER, + acc_pwm, + BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN, + BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Gyroscope Fast Offset Calibration + */ +int8_t bhi3_set_gyro_foc(const struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + (uint8_t *)gyro_foc, + BHI3_PHY_GYRO_FOC_CTRL_LEN, + BHI3_PHY_GYRO_FOC_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Gyroscope Fast Offset Calibration + */ +int8_t bhi3_get_gyro_foc(struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + (uint8_t *)gyro_foc, + BHI3_PHY_GYRO_FOC_CTRL_LEN, + BHI3_PHY_GYRO_FOC_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Gyroscope OIS + */ +int8_t bhi3_set_gyro_ois(const uint8_t *gyro_ois, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_ois, + BHI3_PHY_GYRO_OIS_CTRL_LEN, + BHI3_PHY_GYRO_OIS_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Gyroscope OIS + */ +int8_t bhi3_get_gyro_ois(uint8_t *gyro_ois, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_ois, + BHI3_PHY_GYRO_OIS_CTRL_LEN, + BHI3_PHY_GYRO_OIS_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Gyroscope Fast Startup + */ +int8_t bhi3_set_gyro_fast_startup(const uint8_t *gyro_fs, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_fs, + BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN, + BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Gyroscope Fast Startup + */ +int8_t bhi3_get_gyro_fast_startup(uint8_t *gyro_fs, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_fs, + BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN, + BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Gyroscope CRT + */ +int8_t bhi3_set_gyro_crt(const uint8_t *gyro_crt, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_crt, + BHI3_PHY_GYRO_CRT_CTRL_LEN, + BHI3_PHY_GYRO_CRT_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Gyroscope CRT + */ + +/*lint -e506, -e778 */ +int8_t bhi3_get_gyro_crt(uint8_t *gyro_crt, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = + bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_crt, + BHY2_LE24MUL(BHI3_PHY_GYRO_CRT_CTRL_LEN), + BHI3_PHY_GYRO_CRT_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Gyroscope Power Mode + */ +int8_t bhi3_set_gyro_power_mode(const uint8_t *gyro_pwm, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_pwm, + BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN, + BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Gyroscope Power Mode + */ +int8_t bhi3_get_gyro_power_mode(uint8_t *gyro_pwm, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_pwm, + BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN, + BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Gyroscope Timer Auto Trim state + */ +int8_t bhi3_set_gyro_timer_auto_trim(const uint8_t *gyro_tat, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_tat, + BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN, + BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Gyroscope Timer Auto Trim Status + */ +int8_t bhi3_get_gyro_timer_auto_trim(uint8_t *gyro_tat, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE, + gyro_tat, + BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN, + BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Wrist Wear Wakeup Configuration + */ +int8_t bhi3_set_wrist_wear_wakeup_config(const uint8_t *www_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP, + www_cnfg, + BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN, + BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Wrist Wear Wakeup Configuration + */ +int8_t bhi3_get_wrist_wear_wakeup_config(uint8_t *www_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP, + www_cnfg, + BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN, + BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Any Motion Configuration + */ +int8_t bhi3_set_anymotion_config(const uint8_t *any_motion_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION, + any_motion_cnfg, + BHI3_PHY_ANY_MOTION_CTRL_LEN, + BHI3_PHY_ANY_MOTION_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Any Motion Configuration + */ +int8_t bhi3_get_anymotion_config(uint8_t *any_motion_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION, + any_motion_cnfg, + BHI3_PHY_ANY_MOTION_CTRL_LEN, + BHI3_PHY_ANY_MOTION_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the No Motion Configuration + */ +int8_t bhi3_set_nomotion_config(const uint8_t *no_motion_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION, + no_motion_cnfg, + BHI3_PHY_NO_MOTION_CTRL_LEN, + BHI3_PHY_NO_MOTION_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the No Motion Configuration + */ +int8_t bhi3_get_nomotion_config(uint8_t *no_motion_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the configuration parameter */ + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION, + no_motion_cnfg, + BHI3_PHY_NO_MOTION_CTRL_LEN, + BHI3_PHY_NO_MOTION_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To set the Wrist Gesture Detect Configuration + */ +int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the configuration parameter */ + rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT, + wgd_cnfg, + BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN, + BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE, + dev); + } + + return rslt; +} + +/*! + * @brief To get the Wrist Gesture Detect Configuration + */ +int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT, + wgd_cnfg, + BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN, + BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE, + dev); + } + + return rslt; +} diff --git a/components/SensorLib/src/bosch/bhi3.h b/components/SensorLib/src/bosch/bhi3.h new file mode 100644 index 0000000..e1879a9 --- /dev/null +++ b/components/SensorLib/src/bosch/bhi3.h @@ -0,0 +1,330 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhi3.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHI3_H__ +#define __BHI3_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include "bhy2.h" +#include "bhi3_defs.h" + +/*! + * @brief To parse Wrist Gesture Detection Data + * + * @param[in] Wrist Gesture Detection Data + * @param[in] Wrist Gesture Detection Output Structure + * + * @return API error codes + * + */ +int8_t bhi3_wrist_gesture_detect_parse_data(const uint8_t *data, bhi3_wrist_gesture_detect_t *output); + +/*! + * @brief To set the Accelerometer Fast Offset Calibration + * + * @param[in] Physical Accelerometer FOC data + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_set_acc_foc(const struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev); + +/*! + * @brief To get the Accelerometer Fast Offset Calibration + * + * @param[out] Physical Accelerometer FOC data + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_get_acc_foc(struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev); + +/*! + * @brief To set the Accelerometer Power Mode + * + * @param[in] Physical Accelerometer Power Mode data + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_set_acc_power_mode(const uint8_t *acc_pwm, struct bhy2_dev *dev); + +/*! + * @brief To get the Accelerometer Power Mode + * + * @param[out] Physical Accelerometer Power Mode data + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_get_acc_power_mode(uint8_t *acc_pwm, struct bhy2_dev *dev); + +/*! +* @brief To set the Gyroscope Fast Offset Calibration +* +* @param[in] Physical Gyroscope FOC data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_set_gyro_foc(const struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev); + +/*! +* @brief To get the Gyroscope Fast Offset Calibration +* +* @param[out] Physical Gyroscope FOC data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_get_gyro_foc(struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev); + +/*! +* @brief To set the Gyroscope OIS +* +* @param[in] Physical Gyroscope OIS data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_set_gyro_ois(const uint8_t *gyro_ois, struct bhy2_dev *dev); + +/*! +* @brief To get the Gyroscope OIS +* +* @param[out] Physical Gyroscope OIS data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_get_gyro_ois(uint8_t *gyro_ois, struct bhy2_dev *dev); + +/*! +* @brief To set the Gyroscope Fast Startup +* +* @param[in] Physical Gyroscope Fast Startup data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_set_gyro_fast_startup(const uint8_t *gyro_fs, struct bhy2_dev *dev); + +/*! +* @brief To get the Gyroscope Fast Startup +* +* @param[out] Physical Gyroscope Fast Startup data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_get_gyro_fast_startup(uint8_t *gyro_fs, struct bhy2_dev *dev); + +/*! +* @brief To set the Gyroscope CRT +* +* @param[in] Physical Gyroscope CRT data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_set_gyro_crt(const uint8_t *gyro_crt, struct bhy2_dev *dev); + +/*! +* @brief To get the Gyroscope CRT +* +* @param[out] Physical Gyroscope CRT data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_get_gyro_crt(uint8_t *gyro_crt, struct bhy2_dev *dev); + +/*! +* @brief To set the Gyroscope Power Mode +* +* @param[in] Physical Gyroscope Power Mode data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_set_gyro_power_mode(const uint8_t *gyro_pwm, struct bhy2_dev *dev); + +/*! +* @brief To get the Gyroscope Power Mode +* +* @param[out] Physical Gyroscope Power Mode data +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_get_gyro_power_mode(uint8_t *gyro_pwm, struct bhy2_dev *dev); + +/*! +* @brief To set the Gyroscope Timer Auto Trim state +* +* @param[in] Physical Gyroscope Timer Auto Trim state +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_set_gyro_timer_auto_trim(const uint8_t *gyro_tat, struct bhy2_dev *dev); + +/*! +* @brief To get the Gyroscope Timer Auto Trim status +* +* @param[out] Physical Gyroscope Timer Auto Trim state +* @param[in] dev hub handle +* +* @return API error codes +* +*/ +int8_t bhi3_get_gyro_timer_auto_trim(uint8_t *gyro_tat, struct bhy2_dev *dev); + +/*! + * @brief To set the Wrist Wear Wakeup Configuration + * + * @param[in] Wrist Wear Wakeup Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_set_wrist_wear_wakeup_config(const uint8_t *www_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To get the Wrist Wear Wakeup Configuration + * + * @param[out] Wrist Wear Wakeup Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_get_wrist_wear_wakeup_config(uint8_t *www_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To set the Any Motion Configuration + * + * @param[in] Any Motion Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_set_anymotion_config(const uint8_t *any_motion_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To get the Any Motion Configuration + * + * @param[out] Any Motion Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_get_anymotion_config(uint8_t *any_motion_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To set the No Motion Configuration + * + * @param[in] No Motion Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_set_nomotion_config(const uint8_t *no_motion_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To get the No Motion Configuration + * + * @param[out] No Motion Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_get_nomotion_config(uint8_t *no_motion_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To set the Wrist Gesture Detection Configuration + * + * @param[in] Wrist Gesture Detection Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2_dev *dev); + +/*! + * @brief To get the Wrist Gesture Detection Configuration + * + * @param[out] Wrist Gesture Detection Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHI3_H__ */ diff --git a/components/SensorLib/src/bosch/bhi3_defs.h b/components/SensorLib/src/bosch/bhi3_defs.h new file mode 100644 index 0000000..a88ce30 --- /dev/null +++ b/components/SensorLib/src/bosch/bhi3_defs.h @@ -0,0 +1,204 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhi3_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHI3_DEFS_H__ +#define __BHI3_DEFS_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include "bhy2_defs.h" + +/*! The Product ID needs to be replaced with Chip ID for explicit HW specific Identification*/ +#define BHI3_PRODUCT_ID BHY2_PRODUCT_ID + +/*! Firmware header identifier */ +/*#define BHY2_FW_MAGIC UINT16_C(0x662B) */ + +/*! BHI3 Variant IDs */ +#define BHI3_VARIANT_ID_BHI360 UINT32_C(0x18BC5434) +#define BHI3_VARIANT_ID_BHI380 UINT32_C(0x6E6D6CA6) + +/*! BHI3 Specifc Sensor IDs */ +#define BHI3_SENSOR_ID_AR_WEAR_WU UINT8_C(154) /* Activity Recognition (wear/hear) */ +#define BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU UINT8_C(156) /* Wrist Gesture Detector Low Power Wakeup*/ +#define BHI3_SENSOR_ID_WRIST_WEAR_LP_WU UINT8_C(158) /* Wrist Wear Low Power Wakeup */ +#define BHI3_SENSOR_ID_NO_MOTION_LP_WU UINT8_C(159) /* No motion Low Power */ + +/*! Physical Sensor Control Parameter Page Base Address*/ +#define BHI3_PHY_SENSOR_CTRL_PAGE UINT16_C(0x0E) + +/*! Physical Sensor Control pages + * Here the 'id' refers to the Sensor ID of requisite Physical Sensors (Acc/Gyro) + * */ +#define BHI3_PHY_SENSOR_CTRL_PARAM(id) (((BHI3_PHY_SENSOR_CTRL_PAGE) << 8) | (id)) +#define BHI3_PHY_SENSOR_CTRL_CODE(dir, code) ((dir << 7) | (code)) + +#define BHI3_PHY_SENSOR_CTRL_WRITE UINT8_C(0x00) +#define BHI3_PHY_SENSOR_CTRL_READ UINT8_C(0x01) + +#define BHI3_PHY_ACC_FOC_CTRL_CODE UINT8_C(0x01) +#define BHI3_PHY_ACC_FOC_CTRL_LEN 6 + +#define BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE UINT8_C(0x05) +#define BHI3_PHY_ACC_NORMAL_POWER_MODE UINT8_C(0x00) +#define BHI3_PHY_ACC_LOW_POWER_MODE UINT8_C(0x02) +#define BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN 1 + +#define BHI3_PHY_GYRO_FOC_CTRL_CODE UINT8_C(0x01) +#define BHI3_PHY_GYRO_FOC_CTRL_LEN 6 + +#define BHI3_PHY_GYRO_OIS_CTRL_CODE UINT8_C(0x02) +#define BHI3_PHY_GYRO_DISABLE_OIS UINT8_C(0x00) +#define BHI3_PHY_GYRO_ENABLE_OIS UINT8_C(0x01) +#define BHI3_PHY_GYRO_OIS_CTRL_LEN 1 + +#define BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE UINT8_C(0x03) +#define BHI3_PHY_GYRO_DISABLE_FAST_STARTUP UINT8_C(0x00) +#define BHI3_PHY_GYRO_ENABLE_FAST_STARTUP UINT8_C(0x01) +#define BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN 1 + +#define BHI3_PHY_GYRO_CRT_CTRL_CODE UINT8_C(0x04) +#define BHI3_PHY_GYRO_CRT_STATUS_SUCCESS UINT8_C(0x00) +#define BHI3_PHY_GYRO_ENABLE_CRT UINT8_C(0x01) +#define BHI3_PHY_GYRO_CRT_CTRL_LEN 1 + +#define BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE UINT8_C(0x05) +#define BHI3_PHY_GYRO_NORMAL_POWER_MODE UINT8_C(0x00) +#define BHI3_PHY_GYRO_PERFORMANCE_POWER_MODE UINT8_C(0x01) +#define BHI3_PHY_GYRO_LOW_POWER_MODE UINT8_C(0x02) +#define BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN 1 + +#define BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE UINT8_C(0x06) +#define BHI3_PHY_GYRO_DISABLE_TIMER_AUTO_TRIM UINT8_C(0x00) +#define BHI3_PHY_GYRO_ENABLE_TIMER_AUTO_TRIM UINT8_C(0x01) +#define BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN 1 + +#define BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE UINT8_C(0x01) +#define BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN 10 + +#define BHI3_PHY_ANY_MOTION_CTRL_CODE UINT8_C(0x01) +#define BHI3_PHY_ANY_MOTION_CTRL_LEN 4 + +#define BHI3_PHY_NO_MOTION_CTRL_CODE UINT8_C(0x01) +#define BHI3_PHY_NO_MOTION_CTRL_LEN 4 + +#define BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE UINT8_C(0x07) +#define BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN 19 + +typedef struct bhi3_wrist_wear_wakeup_config_param { + uint16_t min_angle_focus; + uint16_t min_angle_nonfocus; + uint8_t angle_landscape_right; + uint8_t angle_landscape_left; + uint8_t angle_portrait_down; + uint8_t angle_portrait_up; + uint8_t min_dur_moved; + uint8_t min_dur_quite; +} __attribute__ ((packed)) bhi3_wrist_wear_wakeup_config_param_t; + +typedef struct bhi3_any_no_motion_config_param { + uint16_t duration; + uint8_t axis; + uint16_t threshold; +} __attribute__ ((packed)) bhi3_any_no_motion_config_param_t; + +typedef struct bhi3_wrist_gesture_detect_config_param { + uint16_t min_flick_peak_y_threshold; + uint16_t min_flick_peak_z_threshold; + uint16_t gravity_bounds_x_pos; + uint16_t gravity_bounds_x_neg; + uint16_t gravity_bounds_y_neg; + uint16_t gravity_bounds_z_neg; + uint16_t flick_peak_decay_coeff; + uint16_t lp_mean_filter_coeff; + uint16_t max_duration_jiggle_peaks; + uint8_t device_position; +} __attribute__ ((packed)) bhi3_wrist_gesture_detect_config_param_t; + +enum bhi3_wrist_gesture_activity { + NO_GESTURE, + WRIST_SHAKE_JIGGLE = 0x03, + FLICK_IN, + FLICK_OUT +}; + +typedef struct bhi3_wrist_gesture_detect { + enum bhi3_wrist_gesture_activity wrist_gesture; +} __attribute__ ((packed)) bhi3_wrist_gesture_detect_t; + +static const char *const bhi3_wrist_gesture_detect_output[] = { + [NO_GESTURE] = "NO_GESTURE", + [1] = "", + [2] = "", + [WRIST_SHAKE_JIGGLE] = "WRIST_SHAKE_JIGGLE", + [FLICK_IN] = "FLICK_IN", + [FLICK_OUT] = "FLICK_OUT" +}; /*lint -e528 */ + +enum bhi3_phy_sensor_acc_power_mode { + ACC_NORMAL, + ACC_LOW_POWER = 0x02 +}; + +enum bhi3_phy_sensor_gyro_power_mode { + GYRO_NORMAL, + GYRO_PERFORMANCE, + GYRO_LOW_POWER +}; + +static const char *const bhi3_phy_sensor_acc_pwm_output[] = { + [ACC_NORMAL] = "NORMAL", + [1] = "", + [ACC_LOW_POWER] = "LOW POWER" +}; /*lint -e528 */ + +static const char *const bhi3_phy_sensor_gyro_pwm_output[] = { + [GYRO_NORMAL] = "NORMAL", + [GYRO_PERFORMANCE] = "PERFORMANCE", + [GYRO_LOW_POWER] = "LOW POWER" +}; /*lint -e528 */ + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHI3_DEFS_H__ */ diff --git a/components/SensorLib/src/bosch/bhi3_multi_tap.c b/components/SensorLib/src/bosch/bhi3_multi_tap.c new file mode 100644 index 0000000..2f17ca9 --- /dev/null +++ b/components/SensorLib/src/bosch/bhi3_multi_tap.c @@ -0,0 +1,211 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhi3_multi_tap.c +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include + +/*********************************************************************/ +/* BHI3 SensorAPI header files */ +/*********************************************************************/ +#include "bhi3.h" + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "bhi3_multi_tap.h" + +/*lint -e506, -e778*/ + +/*! + * @brief This API writes to the configuration parameter + * + * @param[in] buffer to store Multi Tap configuration + * @param[out] dev hub handle. + * + * @return rslt execution result. + */ +int8_t bhi3_multi_tap_set_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the Multi Tap configuration parameter */ + rslt = bhy2_set_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_ENABLE_PARAM), + (uint8_t*)buffer, + BHI3_MULTI_TAP_ENABLE_LENGTH, + dev); + } + + return rslt; +} + +/*! + * @brief To get the MULTI-TAP configuration parameters + * + * @param[out] buffer to store Multi Tap configuration + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhi3_multi_tap_get_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t ret_length; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the Multi Tap configuration from the parameter page*/ + rslt = + bhy2_get_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_ENABLE_PARAM), + (uint8_t *)buffer, + BHY2_LE24MUL(BHI3_MULTI_TAP_ENABLE_LENGTH), + &ret_length, + dev); + + if (rslt != BHY2_OK) + { + /*! Invalid number of parameters readout */ + rslt = BHY2_E_INVALID_EVENT_SIZE; + } + } + + return rslt; +} + +/*! + * @brief This API writes to the tap detector configuration parameter + * + * @param[in] buffer to store Multi Tap Detector configuration + * @param[out] dev hub handle. + * + * @return rslt execution result. + */ +int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the Multi Tap configuration parameter */ + rslt = bhy2_set_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM), + (uint8_t*)buffer, + BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH, + dev); + } + + return rslt; +} + +/*! + * @brief To get the MULTI-TAP Detector configuration parameters + * + * @param[out] buffer to store Multi Tap Detector configuration + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t ret_length; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the Multi Tap configuration from the parameter page*/ + rslt = bhy2_get_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM), + (uint8_t *)buffer, + BHY2_LE24MUL(BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH), + &ret_length, + dev); + + if (rslt != BHY2_OK) + { + /*! Invalid number of parameters readout */ + rslt = BHY2_E_INVALID_EVENT_SIZE; + } + } + + return rslt; +} + +/*! + * @brief Parsing the fifo data to Multi Tap output format + * + * @param[in] Multi Tap data + * @param[out] buffer to store parameter data + * + * @return API error codes + * + */ +int8_t bhi3_multi_tap_parse_data(const uint8_t *data, uint8_t* output) +{ + int8_t rslt = BHY2_OK; + + if ((data == NULL) || (output == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + *output = *data; + } + + return rslt; +} diff --git a/components/SensorLib/src/bosch/bhi3_multi_tap.h b/components/SensorLib/src/bosch/bhi3_multi_tap.h new file mode 100644 index 0000000..d8df9bb --- /dev/null +++ b/components/SensorLib/src/bosch/bhi3_multi_tap.h @@ -0,0 +1,111 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhi3_multi_tap.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_MULTI_TAP_H_ +#define _BHY2_MULTI_TAP_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include + +#include "bhi3.h" +#include "bhi3_multi_tap_defs.h" + +/*! + * @brief Parsing the fifo data to MULTI_TAP output structure format + * + * @param[in] Multi Tap data + * @param[out] buffer to store parameter data + * + * @return API error codes + * + */ +int8_t bhi3_multi_tap_parse_data(const uint8_t *data, uint8_t *output); + +/*! + * @brief To set the MULTI_TAP configuration parameters + * @param[out] buffer to store parameter data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhi3_multi_tap_set_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the MULTI_TAP configuration parameters + * + * @param[out] buffer to store parameter data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhi3_multi_tap_get_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the MULTI_TAP Detector configuration parameters + * @param[out] buffer to store parameter data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the MULTI_TAP Detector configuration parameters + * + * @param[out] buffer to store parameter data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_MULTI_TAP_H_ */ diff --git a/components/SensorLib/src/bosch/bhi3_multi_tap_defs.h b/components/SensorLib/src/bosch/bhi3_multi_tap_defs.h new file mode 100644 index 0000000..e6f9137 --- /dev/null +++ b/components/SensorLib/src/bosch/bhi3_multi_tap_defs.h @@ -0,0 +1,189 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhi3_multi_tap_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHI3_MULTI_TAP_DEFS_H_ +#define _BHI3_MULTI_TAP_DEFS_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include + +/*! Sensor ID for Multi-Tap */ +#define BHI3_SENSOR_ID_MULTI_TAP UINT8_C(153) + +/*! Multi-Tap Parameter Page Base Address*/ +#define BHI3_MULTI_TAP_PAGE UINT16_C(0x0D) + +/*! Multi-Tap Configuration pages */ +#define BHI3_MULTI_TAP_ENABLE_PARAM 0x01 +#define BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM 0x02 +#define BHI3_MULTI_TAP_PARAM(id) (((BHI3_MULTI_TAP_PAGE) << 8) | (id)) + +#define BHI3_MULTI_TAP_ENABLE_LENGTH UINT8_C(4) +#define BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH UINT8_C(6) + +#define BHI3_MULTI_TAP_AXIS_SEL_X UINT8_C(0) +#define BHI3_MULTI_TAP_AXIS_SEL_Y UINT8_C(1) +#define BHI3_MULTI_TAP_AXIS_SEL_Z UINT8_C(2) + +#define BHI3_MULTI_TAP_WAIT_TIMEOUT_DISABLE UINT8_C(0) +#define BHI3_MULTI_TAP_WAIT_TIMEOUT_ENABLE UINT8_C(1) + +#define BHI3_MULTI_TAP_FILTER_MODE_SENSITIVE UINT8_C(0) +#define BHI3_MULTI_TAP_FILTER_MODE_NORMAL UINT8_C(1) +#define BHI3_MULTI_TAP_FILTER_MODE_ROBUST UINT8_C(2) + +#define BHI3_SINGLE_TAP_AXIS_SEL_MASK 0x03 +#define BHI3_SINGLE_TAP_WAIT_TIMEOUT_MASK 0x04 +#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_MASK 0x38 +#define BHI3_SINGLE_TAP_FILTER_MODE_MASK 0xC0 + +#define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_MASK 0x03FF +#define BHI3_DOUBLE_TAP_MAX_GES_DUR_MASK 0xFC00 + +#define BHI3_TRIPLE_TAP_MAX_DUR_BW_PEAKS_MASK 0x0F +#define BHI3_TRIPLE_TAP_TAP_SHOCK_SETL_DUR_MASK 0xF0 +#define BHI3_TRIPLE_TAP_MIN_QT_DUR_BW_PEAKS_MASK 0x0F +#define BHI3_TRIPLE_TAP_QT_TM_AFTER_GESTURE_MASK 0xF0 + +#define BHI3_SINGLE_TAP_AXIS_SEL_SHIFT UINT8_C(0) +#define BHI3_SINGLE_TAP_WAIT_TIMEOUT_SHIFT UINT8_C(2) +#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_SHIFT UINT8_C(3) +#define BHI3_SINGLE_TAP_FILTER_MODE_SHIFT UINT8_C(6) + +#define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_SHIFT UINT8_C(0) +#define BHI3_DOUBLE_TAP_MAX_GES_DUR_SHIFT UINT8_C(10) + +#define BHI3_TRIPLE_TAP_MAX_DUR_BW_PEAKS_SHIFT UINT8_C(0) +#define BHI3_TRIPLE_TAP_TAP_SHOCK_SETL_DUR_SHIFT UINT8_C(4) +#define BHI3_TRIPLE_TAP_MIN_QT_DUR_BW_PEAKS_SHIFT UINT8_C(0) +#define BHI3_TRIPLE_TAP_QT_TM_AFTER_GESTURE_SHIFT UINT8_C(4) + +/*! + * Single Tap Configuration. + */ +typedef union bhi3_singletap_detector_settings +{ + uint16_t as_uint16; + struct + { + uint16_t axis_sel : 2; /* Tap axis selection */ + uint16_t wait_for_timeout : 1; /* Wait for gesture confirmation */ + uint16_t max_peaks_for_tap : 3; /* Maximum number of peaks that can occur when a tap is done + * */ + uint16_t mode : 2; /* Filter configuration for various detection mode: SENSITIVE, NORMAL and + * ROBUST */ + uint16_t reserved8 : 8; + } as_s; +} __attribute__ ((packed)) bhi3_singletap_detector_settings_t; + +/*! + * Double Tap Configuration. + */ +typedef union bhi3_doubletap_detector_settings +{ + uint16_t as_uint16; + struct + { + uint16_t tap_peak_thres : 10; /* Minimum threshold for peak detection */ + uint16_t max_gesture_dur : 6; /* Maximum time duration from first tap within which matching + * tap/s should happen to be detected as double/triple tap */ + } as_s; +} __attribute__ ((packed)) bhi3_doubletap_detector_settings_t; + +/*! + * Triple Tap Configuration. + */ +typedef union bhi3_tripletap_detector_settings +{ + uint16_t as_uint16; + struct + { + uint16_t max_dur_between_peaks : 4; /* Maximum time duration within which matching peaks of tap + * should occur */ + uint16_t tap_shock_settling_dur : 4; /* Maximum duration to wait for tap shock settling */ + uint16_t min_quite_dur_between_taps : 4; /* Minimum quite time between detection of consecutive taps + * of double/triple taps*/ + uint16_t quite_time_after_gesture : 4; /* Minimum quite time between detection of 2 consecutive + * selected gesture */ + } as_s; +} __attribute__ ((packed)) bhi3_tripletap_detector_settings_t; + +/*! + * Multi Tap Configuration. + */ +typedef struct bhi3_multi_tap_detector +{ + bhi3_singletap_detector_settings_t stap_setting; + bhi3_doubletap_detector_settings_t dtap_setting; + bhi3_tripletap_detector_settings_t ttap_setting; +} __attribute__ ((packed)) bhi3_multi_tap_detector_t; + +/*! + * Multi Tap Setting. + */ +enum bhi3_multi_tap_val { + NO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + DOUBLE_SINGLE_TAP, + TRIPLE_TAP, + TRIPLE_SINGLE_TAP, + TRIPLE_DOUBLE_TAP, + TRIPLE_DOUBLE_SINGLE_TAP +}; + +/*! + * Multi Tap Output. + */ +static const char * const bhi3_multi_tap_string_out[] = { + [NO_TAP] = "NO_TAP", [SINGLE_TAP] = "SINGLE_TAP", [DOUBLE_TAP] = "DOUBLE_TAP", + [DOUBLE_SINGLE_TAP] = "DOUBLE_SINGLE_TAP", [TRIPLE_TAP] = "TRIPLE_TAP", [TRIPLE_SINGLE_TAP] = "TRIPLE_SINGLE_TAP", + [TRIPLE_DOUBLE_TAP] = "TRIPLE_DOUBLE_TAP", [TRIPLE_DOUBLE_SINGLE_TAP] = "TRIPLE_DOUBLE_SINGLE_TAP" +}; /*lint -e528 */ + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHI3_MULTI_TAP_DEFS_H_ */ diff --git a/components/SensorLib/src/bosch/bhy2.c b/components/SensorLib/src/bosch/bhy2.c new file mode 100644 index 0000000..bbd4d97 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2.c @@ -0,0 +1,1785 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2.c +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#include "bhy2.h" +#include "bhy2_hif.h" +#include "bhy2_defs.h" + +typedef enum +{ + BHY2_BUFFER_STATUS_OK, + BHY2_BUFFER_STATUS_RELOAD +} buffer_status_t; + +union bhy2_float_u32 +{ + bhy2_float as_float; + uint32_t reg; +}; + +/* + * Array base address "0" corresponds to virtual sensor id 245 + * Debug Data: 250 : event size : 18 + * 245 & 251 : Timestamp small Delta : event size : 2 + * 252 & 246 : Timestamp Large Delta : event size : 3 + * 253 & 247 : Full timestamp: event size: 6 + * 254 & 248 : Meta event: event size: 4 + * Filler: 255 : event size : 1 + */ +static const uint8_t bhy2_sysid_event_size[11] = { 2, 3, 6, 4, 0, 18, 2, 3, 6, 4, 1 }; + +static int8_t parse_fifo(enum bhy2_fifo_type source, struct bhy2_fifo_buffer *fifo_p, struct bhy2_dev *dev); +static int8_t get_buffer_status(const struct bhy2_fifo_buffer *fifo_p, uint8_t event_size, buffer_status_t *status); +static int8_t get_time_stamp(enum bhy2_fifo_type source, uint64_t **time_stamp, struct bhy2_dev *dev); +static int8_t get_callback_info(uint8_t sensor_id, struct bhy2_fifo_parse_callback_table *info, struct bhy2_dev *dev); + +/*function to check the return values in parse_fifo function*/ +static inline int8_t check_return_value(int8_t result) +{ + + if (result != BHY2_OK) + { + return result; + } + + return BHY2_OK; +} + +int8_t bhy2_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_regs(reg_addr, reg_data, length, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_set_regs(reg_addr, reg_data, length, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +static int8_t bhy2_get_and_process_fifo_support(uint8_t *int_status, + int8_t *rslt, + struct bhy2_fifo_buffer *fifo_temp, + struct bhy2_dev *dev) +{ + uint32_t bytes_read = 0; + int8_t temp_rslt = BHY2_OK; + + while ((*int_status || fifo_temp->remain_length) && (*rslt == BHY2_OK)) + { + if (((BHY2_IS_INT_FIFO_W(*int_status)) == BHY2_IST_FIFO_W_DRDY) || + ((BHY2_IS_INT_FIFO_W(*int_status)) == BHY2_IST_FIFO_W_LTCY) || + ((BHY2_IS_INT_FIFO_W(*int_status)) == BHY2_IST_FIFO_W_WM) || (fifo_temp->remain_length)) + { + + /* Reset read_pos to the start of the buffer */ + fifo_temp->read_pos = 0; + + /* Append data into the work_buffer linked through fifos */ + *rslt = + bhy2_hif_get_wakeup_fifo(&fifo_temp->buffer[fifo_temp->read_length], + (fifo_temp->buffer_size - fifo_temp->read_length), + &bytes_read, + &fifo_temp->remain_length, + &dev->hif); + if (*rslt != BHY2_OK) + { + return *rslt; + } + + fifo_temp->read_length += bytes_read; + } + + *rslt = parse_fifo(BHY2_FIFO_TYPE_WAKEUP, fifo_temp, dev); + *int_status = 0; + } + + return temp_rslt; + +} + +int8_t bhy2_get_and_process_fifo(uint8_t *work_buffer, uint32_t buffer_size, struct bhy2_dev *dev) +{ + uint8_t int_status, int_status_bak; + uint32_t bytes_read = 0; + int8_t rslt; + struct bhy2_fifo_buffer fifos; + + if ((dev == NULL) || (work_buffer == NULL)) + { + return BHY2_E_NULL_PTR; + } + + if (buffer_size == 0) + { + return BHY2_E_BUFFER; + } + + memset(work_buffer, 0, buffer_size); + memset(&fifos, 0, sizeof(struct bhy2_fifo_buffer)); + + fifos.buffer = work_buffer; + fifos.buffer_size = buffer_size; + + rslt = bhy2_hif_get_interrupt_status(&int_status_bak, &dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + /* Get and process the Wake up FIFO */ + fifos.read_length = 0; + int_status = int_status_bak; + + rslt = bhy2_get_and_process_fifo_support(&int_status, &rslt, &fifos, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + /* Get and process the Non Wake-up FIFO */ + fifos.read_length = 0; + int_status = int_status_bak; + while ((int_status || fifos.remain_length) && (rslt == BHY2_OK)) + { + if (((BHY2_IS_INT_FIFO_NW(int_status)) == BHY2_IST_FIFO_NW_DRDY) || + ((BHY2_IS_INT_FIFO_NW(int_status)) == BHY2_IST_FIFO_NW_LTCY) || + ((BHY2_IS_INT_FIFO_NW(int_status)) == BHY2_IST_FIFO_NW_WM) || (fifos.remain_length)) + { + /* Reset read_pos to the start of the buffer */ + fifos.read_pos = 0; + + /* Append data into the work_buffer linked through fifos */ + rslt = bhy2_hif_get_nonwakeup_fifo(&fifos.buffer[fifos.read_length], + (fifos.buffer_size - fifos.read_length), + &bytes_read, + &fifos.remain_length, + &dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + fifos.read_length += bytes_read; + } + + rslt = parse_fifo(BHY2_FIFO_TYPE_NON_WAKEUP, &fifos, dev); + int_status = 0; + } + + /* Get and process the Status fifo */ + fifos.read_length = 0; + int_status = int_status_bak; + while ((int_status || fifos.remain_length) && (rslt == BHY2_OK)) + { + if ((((BHY2_IS_INT_ASYNC_STATUS(int_status)) == BHY2_IST_MASK_DEBUG) || (fifos.remain_length))) + { + fifos.read_pos = 0; + rslt = + bhy2_hif_get_status_fifo_async(&fifos.buffer[fifos.read_length], + (fifos.buffer_size - fifos.read_length), + &bytes_read, + &fifos.remain_length, + &dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + fifos.read_length += bytes_read; + } + + rslt = parse_fifo(BHY2_FIFO_TYPE_STATUS, &fifos, dev); + int_status = 0; + } + + return rslt; +} + +int8_t bhy2_get_virt_sensor_cfg(uint8_t sensor_id, struct bhy2_virt_sensor_conf *virt_sensor_conf, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t bytes_read = 0; + union bhy2_float_u32 sample_rate; + uint8_t buffer[12]; /* Size of parameter to get sensor config */ + + if ((dev != NULL) && (virt_sensor_conf != NULL)) + { + rslt = bhy2_hif_get_parameter((uint16_t)(BHY2_PARAM_SENSOR_CONF_0 + sensor_id), + buffer, + 12, + &bytes_read, + &dev->hif); + sample_rate.reg = BHY2_LE2U32(buffer); + virt_sensor_conf->sample_rate = sample_rate.as_float; + virt_sensor_conf->latency = BHY2_LE2U32(&buffer[4]); + virt_sensor_conf->sensitivity = BHY2_LE2U16(&buffer[8]); + virt_sensor_conf->range = BHY2_LE2U16(&buffer[10]); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_set_virt_sensor_cfg(uint8_t sensor_id, bhy2_float sample_rate, uint32_t latency, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_exec_sensor_conf_cmd(sensor_id, sample_rate, latency, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_set_virt_sensor_range(uint8_t sensor_id, uint16_t range, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t buffer[4] = { 0 }; + + if (dev != NULL) + { + buffer[0] = sensor_id; + buffer[1] = (uint8_t)(range & 0xFF); + buffer[2] = (uint8_t)((range >> 8) & 0xFF); + buffer[3] = 0x00; /* Reserved */ + rslt = bhy2_hif_exec_cmd(BHY2_CMD_CHANGE_RANGE, buffer, 4, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_fifo_ctrl(uint32_t *fifo_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t bytes_read = 0; + uint8_t buffer[16] = { 0 }; + + if ((dev == NULL) || (fifo_ctrl == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, 16, &bytes_read, &dev->hif); + + fifo_ctrl[0] = BHY2_LE2U32(buffer); /* Wake up FIFO watermark */ + fifo_ctrl[1] = BHY2_LE2U32(&buffer[4]); /* Wake up FIFO size */ + fifo_ctrl[2] = BHY2_LE2U32(&buffer[8]); /* Non wake up FIFO watermark */ + fifo_ctrl[3] = BHY2_LE2U32(&buffer[12]); /* Non wake up FIFO size */ + } + + return rslt; +} + +int8_t bhy2_set_fifo_wmark_wkup(uint32_t watermark, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t bytes_read = 0; + uint8_t buffer[20] = { 0 }; + uint32_t read_watermark = 0; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &bytes_read, &dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + buffer[0] = (uint8_t)((watermark & 0xFF)); + buffer[1] = (uint8_t)(((watermark >> 8) & 0xFF)); + buffer[2] = (uint8_t)(((watermark >> 16) & 0xFF)); + buffer[3] = (uint8_t)(((watermark >> 24) & 0xFF)); + rslt = bhy2_hif_set_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &bytes_read, &dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + read_watermark = BHY2_LE2U32(buffer); + if (read_watermark != watermark) + { + rslt = BHY2_E_PARAM_NOT_SET; + } + } + + return rslt; +} + +int8_t bhy2_get_fifo_wmark_wkup(uint32_t *watermark, struct bhy2_dev *dev) +{ + int8_t rslt = 0; + uint32_t bytes_read = 0; + uint8_t buffer[20] = { 0 }; + + if ((dev == NULL) || (watermark == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &bytes_read, &dev->hif); + *watermark = BHY2_LE2U32(buffer); + } + + return rslt; +} + +int8_t bhy2_set_fifo_wmark_nonwkup(uint32_t watermark, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t bytes_read = 0; + uint8_t buffer[20] = { 0 }; + uint32_t read_watermark = 0; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &bytes_read, &dev->hif); + if (rslt < 0) + { + return rslt; + } + + buffer[8] = (uint8_t)((watermark & 0xFF)); + buffer[9] = (uint8_t)(((watermark >> 8) & 0xFF)); + buffer[10] = (uint8_t)(((watermark >> 16) & 0xFF)); + buffer[11] = (uint8_t)(((watermark >> 24) & 0xFF)); + rslt = bhy2_hif_set_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &dev->hif); + if (rslt < 0) + { + return rslt; + } + + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &bytes_read, &dev->hif); + if (rslt < 0) + { + return rslt; + } + + read_watermark = BHY2_LE2U32(&buffer[8]); + if (read_watermark != watermark) + { + rslt = BHY2_E_PARAM_NOT_SET; + } + } + + return rslt; +} + +int8_t bhy2_get_fifo_wmark_nonwkup(uint32_t *watermark, struct bhy2_dev *dev) +{ + int8_t rslt = 0; + uint32_t bytes_read = 0; + uint8_t buffer[20] = { 0 }; + + if ((dev == NULL) || (watermark == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_parameter(BHY2_PARAM_FIFO_CTRL, buffer, sizeof(buffer), &bytes_read, &dev->hif); + *watermark = BHY2_LE2U32(&buffer[8]); + } + + return rslt; +} + +int8_t bhy2_get_product_id(uint8_t *product_id, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_product_id(product_id, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_chip_id(uint8_t *chip_id, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_chip_id(chip_id, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_revision_id(uint8_t *revision_id, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev != NULL) && (revision_id != NULL)) + { + rslt = bhy2_hif_get_regs(BHY2_REG_REVISION_ID, revision_id, 1, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_rom_version(uint16_t *rom_version, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev != NULL) && (rom_version != NULL)) + { + rslt = bhy2_hif_get_rom_version(rom_version, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_kernel_version(uint16_t *kernel_version, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_kernel_version(kernel_version, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_user_version(uint16_t *user_version, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_user_version(user_version, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_boot_status(uint8_t *boot_status, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_boot_status(boot_status, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_host_status(uint8_t *host_status, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_host_status(host_status, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_feature_status(uint8_t *feat_status, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_get_feature_status(feat_status, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_get_virt_sensor_list(struct bhy2_dev *dev) +{ + uint32_t bytes_read = 0; + int8_t rslt = 0; + + if (dev != NULL) + { + rslt = + bhy2_hif_get_parameter(BHY2_PARAM_SYS_VIRT_SENSOR_PRESENT, dev->present_buff, 32, &bytes_read, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (firmware == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_upload_firmware_to_ram(firmware, length, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_upload_firmware_to_ram_partly(const uint8_t *firmware, + uint32_t total_size, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (firmware == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_upload_firmware_to_ram_partly(firmware, total_size, cur_pos, packet_len, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_boot_from_ram(struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_boot_program_ram(&dev->hif); + } + + return rslt; +} + +int8_t bhy2_erase_flash(uint32_t start_address, uint32_t end_addr, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_erase_flash(start_address, end_addr, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_upload_firmware_to_flash(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t buffer[20] = { 0 }; + uint32_t bytes_read = 0; + + if ((dev == NULL) || (firmware == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_upload_to_flash(firmware, length, buffer, sizeof(buffer), &bytes_read, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_upload_firmware_to_flash_partly(const uint8_t *firmware, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (firmware == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_upload_to_flash_partly(firmware, cur_pos, packet_len, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_boot_from_flash(struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_boot_from_flash(&dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_host_interrupt_ctrl(uint8_t hintr_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERRUPT_CTRL, &hintr_ctrl, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_host_interrupt_ctrl(uint8_t *hintr_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERRUPT_CTRL, hintr_ctrl, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_interrupt_status(uint8_t *int_status, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_interrupt_status(int_status, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_host_intf_ctrl(uint8_t hintf_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &hintf_ctrl, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_host_intf_ctrl(uint8_t *hintf_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, hintf_ctrl, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_fifo_format_ctrl(uint8_t param, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t buffer[4] = { 0 }; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + buffer[0] = param & BHY2_FIFO_FORMAT_CTRL_MASK; + rslt = bhy2_hif_exec_cmd(BHY2_CMD_FIFO_FORMAT_CTRL, buffer, 4, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_timestamp_event_req(uint8_t ts_ev_req, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t buffer; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + if (ts_ev_req) + { + buffer = 0x01; + } + else + { + buffer = 0x00; + } + + rslt = bhy2_hif_set_regs(BHY2_REG_TIME_EV_REQ, &buffer, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_hw_timestamp_ns(uint64_t *timestamp_ns, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (timestamp_ns == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_hw_timestamp(timestamp_ns, &dev->hif); + *timestamp_ns *= UINT64_C(15625); + } + + return rslt; +} + +int8_t bhy2_set_host_ctrl(uint8_t host_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_CTRL, &host_ctrl, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_host_ctrl(uint8_t *host_ctrl, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (host_ctrl == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_CTRL, host_ctrl, 1, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_soft_passthrough_transfer(union bhy2_soft_passthrough_conf *conf, + uint8_t reg_addr, + uint8_t length, + uint8_t *reg_data, + struct bhy2_dev *dev) +{ + uint32_t bytes_read = 0; + int8_t rslt = BHY2_OK; + uint8_t cmd[BHY2_COMMAND_PACKET_LEN] = { 0 }; + uint8_t tmp_rd_buf[BHY2_SPASS_WRITE_RESP_PACKET_LEN] = { 0 }; + uint16_t buffer_size = 0; + + if ((dev == NULL) || (conf == NULL) || (reg_data == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + conf->conf.trans_count = length; + conf->conf.reg = reg_addr; + if (conf->conf.direction == BHY2_SPASS_READ) + { + if ((BHY2_SPASS_READ_PACKET_LEN + length) % 4) + { + buffer_size = (uint16_t)(((BHY2_SPASS_READ_PACKET_LEN + length) / 4 + 1) * 4); + } + else + { + buffer_size = (uint16_t)(BHY2_SPASS_READ_PACKET_LEN + length); + } + + if (buffer_size <= BHY2_COMMAND_PACKET_LEN) + { + rslt = bhy2_hif_exec_soft_passthrough(conf->data, 8, cmd, buffer_size, &bytes_read, &dev->hif); + memcpy(reg_data, &cmd[9], length); + } + else + { + rslt = BHY2_E_BUFFER; + } + } + else + { + if ((8 + length) % 4) + { + buffer_size = (uint16_t)(((8 + length) / 4 + 1) * 4); + } + else + { + buffer_size = (uint16_t)(8 + length); + } + + if (buffer_size <= BHY2_COMMAND_PACKET_LEN) + { + memcpy(&cmd[0], conf->data, 8); + memcpy(&cmd[8], reg_data, length); + rslt = bhy2_hif_exec_soft_passthrough(&cmd[0], + buffer_size, + tmp_rd_buf, + sizeof(tmp_rd_buf), + &bytes_read, + &dev->hif); + } + else + { + rslt = BHY2_E_BUFFER; + } + } + } + + return rslt; +} + +int8_t bhy2_flush_fifo(uint8_t sensor_id, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_fifo_flush(sensor_id, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_soft_reset(struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_reset(&dev->hif); + } + + return rslt; +} + +int8_t bhy2_perform_self_test(uint8_t phys_sensor_id, struct bhy2_self_test_resp *self_test_resp, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (self_test_resp == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_do_self_test(phys_sensor_id, self_test_resp, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_perform_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_status, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (foc_status == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_do_foc(phys_sensor_id, foc_status, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_orientation_matrix(uint8_t phys_sensor_id, struct bhy2_orient_matrix orient_matrix, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_orientation_matrix(phys_sensor_id, orient_matrix, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_phys_sensor_info(uint8_t phys_sensor_id, + struct bhy2_phys_sensor_info *phy_sen_info, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (phy_sen_info == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_phys_sensor_info(phys_sensor_id, phy_sen_info, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_orientation_matrix(uint8_t phys_sensor_id, + struct bhy2_orient_matrix *orient_matrix, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + struct bhy2_phys_sensor_info phy_sen_info; + + if ((dev == NULL) || (orient_matrix == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_phys_sensor_info(phys_sensor_id, &phy_sen_info, &dev->hif); + + /*lint -e702 Info 702: Shift right of signed quantity (int) */ + orient_matrix->c[0] = (int8_t)((phy_sen_info.orientation_matrix[0] & 0x0F) << 4) >> 4; + orient_matrix->c[1] = (int8_t)(phy_sen_info.orientation_matrix[0] & 0xF0) >> 4; + orient_matrix->c[2] = (int8_t)((phy_sen_info.orientation_matrix[1] & 0x0F) << 4) >> 4; + orient_matrix->c[3] = (int8_t)(phy_sen_info.orientation_matrix[1] & 0xF0) >> 4; + orient_matrix->c[4] = (int8_t)((phy_sen_info.orientation_matrix[2] & 0x0F) << 4) >> 4; + orient_matrix->c[5] = (int8_t)(phy_sen_info.orientation_matrix[2] & 0xF0) >> 4; + orient_matrix->c[6] = (int8_t)((phy_sen_info.orientation_matrix[3] & 0x0F) << 4) >> 4; + orient_matrix->c[7] = (int8_t)(phy_sen_info.orientation_matrix[3] & 0xF0) >> 4; + orient_matrix->c[8] = (int8_t)((phy_sen_info.orientation_matrix[4] & 0x0F) << 4) >> 4; + + /*lint +e702 */ + } + + return rslt; +} + +int8_t bhy2_get_sic_matrix(uint8_t *sic_matrix, uint16_t matrix_len, uint32_t *actual_len, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (sic_matrix == NULL) || (actual_len == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_bsx_state(BHY2_PARAM_BSX_SIC, sic_matrix, matrix_len, actual_len, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_sic_matrix(const uint8_t *sic_matrix, uint16_t matrix_len, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (sic_matrix == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_bsx_state(BHY2_PARAM_BSX_SIC, sic_matrix, matrix_len, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_calibration_profile(uint8_t phy_sensor_id, + uint8_t *calib_prof, + uint16_t prof_len, + uint32_t *actual_len, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (calib_prof == NULL) || (actual_len == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_bsx_state((uint16_t)(BHY2_PARAM_BSX_CALIB_STATE_BASE | phy_sensor_id), + calib_prof, + prof_len, + actual_len, + &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_calibration_profile(uint8_t phy_sensor_id, + const uint8_t *calib_prof, + uint16_t prof_len, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (calib_prof == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_set_bsx_state((uint16_t)(BHY2_PARAM_BSX_CALIB_STATE_BASE | phy_sensor_id), + calib_prof, + prof_len, + &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_post_mortem_data(uint8_t *post_mortem, uint32_t buffer_len, uint32_t *actual_len, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint16_t crash_dump_status_code = 0; + + if ((dev == NULL) || (post_mortem == NULL) || (actual_len == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_post_mortem(&crash_dump_status_code, actual_len, post_mortem, buffer_len, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_init(enum bhy2_intf intf, + bhy2_read_fptr_t read, + bhy2_write_fptr_t write, + bhy2_delay_us_fptr_t delay_us, + uint32_t read_write_len, + void *intf_ptr, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + memset(dev, 0, sizeof(struct bhy2_dev)); + + rslt = bhy2_hif_init(intf, read, write, delay_us, read_write_len, intf_ptr, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_register_fifo_parse_callback(uint8_t sensor_id, + bhy2_fifo_parse_callback_t callback, + void *callback_ref, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t i = 0; + + if ((dev == NULL) || (callback == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + for (i = 0; i < BHY2_MAX_SIMUL_SENSORS; i++) + { + if (dev->table[i].sensor_id == 0) + { + dev->table[i].sensor_id = sensor_id; + dev->table[i].callback = callback; + dev->table[i].callback_ref = callback_ref; + break; + } + } + + if (i == BHY2_MAX_SIMUL_SENSORS) + { + rslt = BHy2_E_INSUFFICIENT_MAX_SIMUL_SENSORS; + } + } + + return rslt; +} + +int8_t bhy2_deregister_fifo_parse_callback(uint8_t sensor_id, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t i = 0; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + for (i = 0; i < BHY2_MAX_SIMUL_SENSORS; i++) + { + if (dev->table[i].sensor_id == sensor_id) + { + dev->table[i].sensor_id = 0; + dev->table[i].callback = NULL; + dev->table[i].callback_ref = NULL; + break; + } + } + } + + return rslt; +} + +int8_t bhy2_update_virtual_sensor_list(struct bhy2_dev *dev) +{ + int8_t rslt; + uint8_t sensor_id; + struct bhy2_sensor_info info; + uint8_t sensor_index; + uint8_t bit_mask; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /* Each bit corresponds to presence of Virtual sensor */ + rslt = bhy2_get_virt_sensor_list(dev); + if (rslt == BHY2_OK) + { + /* Padding: Sensor id*/ + dev->event_size[0] = 1; + + for (sensor_id = 1; (sensor_id < BHY2_SPECIAL_SENSOR_ID_OFFSET) && (rslt == BHY2_OK); sensor_id++) + { + sensor_index = (uint8_t)(sensor_id / 8); + bit_mask = (uint8_t)(0x01 << (sensor_id % 8)); + + if (dev->present_buff[sensor_index] & bit_mask) + { + rslt = bhy2_hif_get_sensor_info(sensor_id, &info, &dev->hif); + if (rslt == BHY2_OK) + { + if (info.event_size == 0) + { + rslt = BHY2_E_INVALID_EVENT_SIZE; + break; + } + else + { + dev->event_size[sensor_id] = info.event_size; + } + } + } + } + + for (sensor_id = BHY2_N_VIRTUAL_SENSOR_MAX - 1; sensor_id >= BHY2_SPECIAL_SENSOR_ID_OFFSET; sensor_id--) + { + dev->event_size[sensor_id] = bhy2_sysid_event_size[sensor_id - BHY2_SPECIAL_SENSOR_ID_OFFSET]; + } + } + } + + return rslt; +} + +int8_t bhy2_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_dev *dev) +{ + int8_t rslt; + + if ((dev == NULL) || (info == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_sensor_info(sensor_id, info, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_set_parameter(uint16_t param, const uint8_t *buffer, uint32_t length, struct bhy2_dev *dev) +{ + int8_t rslt; + + if ((dev == NULL) || (buffer == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_exec_cmd(param, buffer, length, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_parameter(uint16_t param, uint8_t *buffer, uint32_t length, uint32_t *actual_len, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (buffer == NULL) || (actual_len == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_hif_get_parameter(param, buffer, length, actual_len, &dev->hif); + } + + return rslt; +} + +int8_t bhy2_get_error_value(uint8_t *error_value, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if ((dev == NULL) || (error_value == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + rslt = bhy2_get_regs(BHY2_REG_ERROR_VALUE, error_value, 1, dev); + } + + return rslt; +} + +int8_t bhy2_set_data_injection_mode(enum bhy2_data_inj_mode mode, struct bhy2_dev *dev) +{ + uint8_t data_inj_payload[8] = { 0 }; + int8_t rslt = BHY2_OK; + uint8_t work_buffer[256] = { 0 }; + uint32_t actual_len = 0; + uint16_t cmd = BHY2_CMD_SET_INJECT_MODE; + + data_inj_payload[0] = (uint8_t)(cmd & 0xFF); + data_inj_payload[1] = (uint8_t)((cmd >> 8) & 0xFF); + data_inj_payload[2] = BHY2_DATA_INJECT_MODE_PAYLOAD_LEN; + + if (dev != NULL) + { + + switch (mode) + { + case BHY2_NORMAL_MODE: + data_inj_payload[4] = 0; + break; + case BHY2_REAL_TIME_INJECTION: + data_inj_payload[4] = 1; + break; + case BHY2_STEP_BY_STEP_INJECTION: + data_inj_payload[4] = 2; + break; + default: + rslt = BHY2_E_INVALID_PARAM; + } + + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_set_inject_data_mode(data_inj_payload, + sizeof (data_inj_payload), + work_buffer, + 256, + &actual_len, + &dev->hif); + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_dev *dev) +{ + return bhy2_hif_inject_data(payload, payload_len, &dev->hif); +} + +uint8_t bhy2_is_sensor_available(uint8_t sensor_id, const struct bhy2_dev *dev) +{ + uint8_t offset = sensor_id / 8; + uint8_t mask = 1U << (sensor_id & 0x7); + uint8_t sensor_present = 0; + + if (dev != NULL) + { + sensor_present = (dev->present_buff[offset] & mask); + } + + return sensor_present; +} + +/** + * @brief Function to get the BHy260 variant ID + */ +int8_t bhy2_get_variant_id(uint32_t *variant_id, struct bhy2_dev *dev) +{ + int8_t rslt; + uint8_t cfg_read_command[] = { 0x16, 0x00, 0x00, 0x00 }; + uint8_t buffer[118] = { 0 }; + + rslt = bhy2_soft_reset(dev); + if (rslt == BHY2_OK) + { + rslt = bhy2_set_regs(BHY2_REG_CHAN_CMD, cfg_read_command, sizeof(cfg_read_command), dev); + + /* Give the device some time to prepare data */ + dev->hif.delay_us(10000, NULL); + } + + if (rslt == BHY2_OK) + { + /* Read status FIFO. First check if response is correct */ + rslt = bhy2_get_regs(BHY2_REG_CHAN_STATUS, buffer, 4, dev); + } + + if (rslt == BHY2_OK) + { + if (!((buffer[0] == 0x10) && (buffer[1] == 0x00) && (buffer[2] == sizeof(buffer)) && (buffer[3] == 0))) + { + rslt = BHY2_E_INVALID_PARAM; + } + } + + if (rslt == BHY2_OK) + { + /* Read out the configuration */ + rslt = bhy2_get_regs(BHY2_REG_CHAN_STATUS, buffer, sizeof(buffer), dev); + if (rslt == BHY2_OK) + { + *variant_id = ((uint32_t)buffer[40] << 24) | ((uint32_t)buffer[41] << 16) | ((uint32_t)buffer[42] << 8) | + buffer[43]; + } + } + + return rslt; +} + +static int8_t get_callback_info(uint8_t sensor_id, struct bhy2_fifo_parse_callback_table *info, struct bhy2_dev *dev) +{ + + int8_t rslt = BHY2_OK; + uint8_t i = 0, j; + + if ((dev != NULL) && (info != NULL)) + { + for (j = 0; j < BHY2_MAX_SIMUL_SENSORS; j++) + { + if (sensor_id == dev->table[j].sensor_id) + { + *info = dev->table[j]; + i = j; + break; + } + } + + if (i == BHY2_MAX_SIMUL_SENSORS) + { + rslt = BHy2_E_INSUFFICIENT_MAX_SIMUL_SENSORS; + } + else + { + if ((sensor_id >= BHY2_SPECIAL_SENSOR_ID_OFFSET) && (dev->event_size[sensor_id] == 0)) + { + dev->event_size[sensor_id] = bhy2_sysid_event_size[sensor_id - BHY2_SPECIAL_SENSOR_ID_OFFSET]; + } + + if ((sensor_id == 0) && (dev->event_size[sensor_id] == 0)) + { + dev->event_size[sensor_id] = 1; + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +static int8_t get_buffer_status(const struct bhy2_fifo_buffer *fifo_p, uint8_t event_size, buffer_status_t *status) +{ + if ((fifo_p->read_pos + event_size) <= fifo_p->read_length) + { + *status = BHY2_BUFFER_STATUS_OK; + } + else + { + *status = BHY2_BUFFER_STATUS_RELOAD; + } + + return BHY2_OK; +} + +static int8_t get_time_stamp(enum bhy2_fifo_type source, uint64_t **time_stamp, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (source < BHY2_FIFO_TYPE_MAX) + { + *time_stamp = &dev->last_time_stamp[source]; + } + else + { + rslt = BHY2_E_INVALID_FIFO_TYPE; + } + + return rslt; +} + +static int8_t parse_fifo_support(struct bhy2_fifo_buffer *fifo_buf) +{ + uint8_t i; + + if (fifo_buf->read_length) + { + if (fifo_buf->read_length < fifo_buf->read_pos) + { + return BHY2_E_INVALID_PARAM; + } + + fifo_buf->read_length -= fifo_buf->read_pos; + if (fifo_buf->read_length) + { + for (i = 0; i < fifo_buf->read_length; i++) + { + fifo_buf->buffer[i] = fifo_buf->buffer[fifo_buf->read_pos + i]; + } + } + } + + return BHY2_OK; +} + +static int8_t parse_fifo(enum bhy2_fifo_type source, struct bhy2_fifo_buffer *fifo_p, struct bhy2_dev *dev) +{ + uint8_t tmp_sensor_id = 0; + int8_t rslt = BHY2_OK; + uint32_t tmp_read_pos; + struct bhy2_fifo_parse_data_info data_info; + uint64_t *time_stamp; + struct bhy2_fifo_parse_callback_table info = { 0 }; + buffer_status_t status = BHY2_BUFFER_STATUS_OK; + + for (; (fifo_p->read_pos < fifo_p->read_length) && (status == BHY2_BUFFER_STATUS_OK);) + { + tmp_read_pos = fifo_p->read_pos; + tmp_sensor_id = fifo_p->buffer[tmp_read_pos]; + + rslt = get_time_stamp(source, &time_stamp, dev); + rslt = check_return_value(rslt); + switch (tmp_sensor_id) + { + case BHY2_SYS_ID_FILLER: + case BHY2_SYS_ID_PADDING: + fifo_p->read_pos += 1; + break; + case BHY2_SYS_ID_TS_SMALL_DELTA_WU: + case BHY2_SYS_ID_TS_SMALL_DELTA: + rslt = get_buffer_status(fifo_p, 2, &status); + rslt = check_return_value(rslt); + if (status != BHY2_BUFFER_STATUS_OK) + { + break; + } + + *time_stamp += fifo_p->buffer[tmp_read_pos + 1]; + fifo_p->read_pos += 2; + break; + case BHY2_SYS_ID_TS_LARGE_DELTA: + case BHY2_SYS_ID_TS_LARGE_DELTA_WU: + rslt = get_buffer_status(fifo_p, 3, &status); + rslt = check_return_value(rslt); + + if (status != BHY2_BUFFER_STATUS_OK) + { + break; + } + + *time_stamp += BHY2_LE2U16(fifo_p->buffer + tmp_read_pos + 1); + fifo_p->read_pos += 3; + break; + case BHY2_SYS_ID_BHY2_LOG_DOSTEP: + rslt = get_buffer_status(fifo_p, 23, &status); + rslt = check_return_value(rslt); + + if (status != BHY2_BUFFER_STATUS_OK) + { + break; + } + + fifo_p->read_pos += 23; + + break; + case BHY2_SYS_ID_TS_FULL: + case BHY2_SYS_ID_TS_FULL_WU: + rslt = get_buffer_status(fifo_p, 6, &status); + rslt = check_return_value(rslt); + + if (status != BHY2_BUFFER_STATUS_OK) + { + break; + } + + *time_stamp = BHY2_LE2U40(fifo_p->buffer + tmp_read_pos + UINT8_C(1)); + fifo_p->read_pos += 6; + break; + default: + rslt = get_callback_info(tmp_sensor_id, &info, dev); + rslt = check_return_value(rslt); + rslt = get_buffer_status(fifo_p, dev->event_size[tmp_sensor_id], &status); /*lint !e838 suppressing + * previously assigned value + * not used info */ + rslt = check_return_value(rslt); + if (status != BHY2_BUFFER_STATUS_OK) + { + break; + } + + if (info.callback != NULL) + { + /* Read position is incremented by 1 to exclude sensor id */ + data_info.data_ptr = &fifo_p->buffer[tmp_read_pos + 1]; + data_info.fifo_type = source; + data_info.time_stamp = time_stamp; + data_info.sensor_id = tmp_sensor_id; + data_info.data_size = dev->event_size[tmp_sensor_id]; + info.callback(&data_info, info.callback_ref); + } + + fifo_p->read_pos += dev->event_size[tmp_sensor_id]; + break; + } + } + + rslt = parse_fifo_support(fifo_p); + + return rslt; +} + +int8_t bhy2_clear_fifo(uint8_t flush_cfg, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t buffer[4] = { 0 }; + + if (dev != NULL) + { + buffer[0] = flush_cfg; + rslt = bhy2_hif_exec_cmd(BHY2_CMD_FIFO_FLUSH, buffer, 4, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_read_status(uint16_t *status_code, + uint8_t *status_buff, + uint32_t status_len, + uint32_t *actual_len, + struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev != NULL) + { + rslt = bhy2_hif_wait_status_ready(&dev->hif); + if (rslt != BHY2_OK) + { + return rslt; + } + + rslt = bhy2_hif_get_status_fifo(status_code, status_buff, status_len, actual_len, &dev->hif); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} diff --git a/components/SensorLib/src/bosch/bhy2.h b/components/SensorLib/src/bosch/bhy2.h new file mode 100644 index 0000000..c86bcec --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2.h @@ -0,0 +1,664 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHY2_H__ +#define __BHY2_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include "bhy2_defs.h" + +/** + * @brief Function to link the callback interfaces + * @param[in] intf : Physical communication interface + * @param[in] read : Read function pointer + * @param[in] write : Write function pointer + * @param[in] delay_us : Microsecond delay function pointer + * @param[in] read_write_len : Maximum read/write lengths supported + * @param[in] intf_ptr : Reference to the interface. Can be NULL + * @param[out] dev : Device reference + * @return API error codes + */ +int8_t bhy2_init(enum bhy2_intf intf, + bhy2_read_fptr_t read, + bhy2_write_fptr_t write, + bhy2_delay_us_fptr_t delay_us, + uint32_t read_write_len, + void *intf_ptr, + struct bhy2_dev *dev); + +/** + * @brief Function to get data from registers + * @param[in] reg_addr : Register address to be read from + * @param[out] reg_data : Reference to the data buffer + * @param[in] length : Length of the data buffer + * @param[in] dev : Device reference + * @return API Error codes + */ +int8_t bhy2_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev); + +/** + * @brief Function to set data to registers + * @param[in] reg_addr : Register address to write to + * @param[in] reg_data : Reference to the data buffer + * @param[in] length : Length of the data buffer + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev); + +/** + * @brief Function to get the product ID + * @param[out] product_id : Reference to data buffer to store the product ID + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_product_id(uint8_t *product_id, struct bhy2_dev *dev); + +/** + * @brief Function to get the chip ID + * @param[out] chip_id : Reference to data buffer to store the chip ID + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_chip_id(uint8_t *chip_id, struct bhy2_dev *dev); + +/** + * @brief Function to get the revision ID + * @param[out] revision_id : Reference to data buffer to store the revision ID + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_revision_id(uint8_t *revision_id, struct bhy2_dev *dev); + +/** + * @brief Function to get the ROM version + * @param[out] rom_version : Reference to the data buffer to store the ROM version + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_rom_version(uint16_t *rom_version, struct bhy2_dev *dev); + +/** + * @brief Function to get the kernel version + * @param[out] kernel_version : Reference to the data buffer to store the kernel version + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_kernel_version(uint16_t *kernel_version, struct bhy2_dev *dev); + +/** + * @brief Function to get the user version + * @param[out] user_version : Reference to the data buffer to store the user version + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_user_version(uint16_t *user_version, struct bhy2_dev *dev); + +/** + * @brief Function to get the boot status + * @param[out] boot_status : Reference to the data buffer to store the boot status + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_boot_status(uint8_t *boot_status, struct bhy2_dev *dev); + +/** + * @brief Function to get the host status + * @param[out] host_status : Reference to the data buffer to store the host status + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_host_status(uint8_t *host_status, struct bhy2_dev *dev); + +/** + * @brief Function to get the feature status + * @param[out] feat_status : Reference to the data buffer to store the feature status + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_feature_status(uint8_t *feat_status, struct bhy2_dev *dev); + +/** + * @brief Function to get the virtual sensor list and store in the device structure + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_virt_sensor_list(struct bhy2_dev *dev); + +/** + * @brief Function to get the virtual sensor configuration + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[out] virt_sensor_conf : Reference to the data buffer to store the virtual sensor configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_virt_sensor_cfg(uint8_t sensor_id, struct bhy2_virt_sensor_conf *virt_sensor_conf, + struct bhy2_dev *dev); + +/** + * @brief Function to set the sample rate and latency of the virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] sample_rate : Sample rate in Hz + * @param[in] latency : Report latency in milliseconds + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_virt_sensor_cfg(uint8_t sensor_id, bhy2_float sample_rate, uint32_t latency, struct bhy2_dev *dev); + +/** + * @brief Function set the range of the virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] range : Range of the virtual sensor + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_virt_sensor_range(uint8_t sensor_id, uint16_t range, struct bhy2_dev *dev); + +/** + * @brief Function to get and process the FIFOs + * @param[in] work_buffer : Reference to the data buffer where the FIFO data is copied to before parsing + * @param[in] buffer_size : Size of the data buffer + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_and_process_fifo(uint8_t *work_buffer, uint32_t buffer_size, struct bhy2_dev *dev); + +/** + * @brief Function get the FIFO control register + * @param[out] fifo_ctrl : Reference to the data buffer to store the FIFO control + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_fifo_ctrl(uint32_t *fifo_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to set the Wake up FIFO watermark + * @param[in] watermark : Size of the watermark + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_fifo_wmark_wkup(uint32_t watermark, struct bhy2_dev *dev); + +/** + * @brief Function to get the Wake up FIFO watermark + * @param[out] watermark : Reference to the data buffer to store the FIFO watermark size + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_fifo_wmark_wkup(uint32_t *watermark, struct bhy2_dev *dev); + +/** + * @brief Function to set the Non wake up FIFO watermark + * @param[in] watermark : Size of the watermark + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_fifo_wmark_nonwkup(uint32_t watermark, struct bhy2_dev *dev); + +/** + * @brief Function to get the Non wake up FIFO watermark + * @param[out] watermark : Reference to the data buffer to store the FIFO watermark size + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_fifo_wmark_nonwkup(uint32_t *watermark, struct bhy2_dev *dev); + +/** + * @brief Function to flush data of a virtual sensor from the FIFOs + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_flush_fifo(uint8_t sensor_id, struct bhy2_dev *dev); + +/** + * @brief Function to set the FIFO format + * @param[in] param : FIFO format settings + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_fifo_format_ctrl(uint8_t param, struct bhy2_dev *dev); + +/** + * @brief Function to upload firmware to RAM + * @param[in] firmware : Reference to the data buffer containing the firmware + * @param[in] length : Size of the firmware + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev); + +/** + * @brief Function to upload part of the firmware to RAM + * @param[in] firmware : Reference to the data buffer containing the current firmware section + * @param[in] total_size : Total size of the firmware + * @param[in] cur_pos : Current position of the part being loaded + * @param[in] packet_len : Size of the part being loaded + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_upload_firmware_to_ram_partly(const uint8_t *firmware, + uint32_t total_size, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_dev *dev); + +/** + * @brief Function to boot firmware from RAM + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_boot_from_ram(struct bhy2_dev *dev); + +/** + * @brief Function to erase the flash + * @param[in] start_addr : Start address + * @param[in] end_addr : End address + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_erase_flash(uint32_t start_address, uint32_t end_addr, struct bhy2_dev *dev); + +/** + * @brief Function to upload firmware to Flash + * @param[in] firmware : Reference to the data buffer containing the firmware + * @param[in] length : Size of the firwmare + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_upload_firmware_to_flash(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev); + +/** + * @brief Function to upload part of the firmware to Flash + * @param[in] firmware : Reference to the data buffer containing the current firmware section + * @param[in] cur_pos : Current position of the part being loaded + * @param[in] packet_len : Size of the part being loaded + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_upload_firmware_to_flash_partly(const uint8_t *firmware, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_dev *dev); + +/** + * @brief Function to boot from Flash + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_boot_from_flash(struct bhy2_dev *dev); + +/** + * @brief Function to set the host interrupt control register + * @param[in] hintr_ctrl : Host interrupt control configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_host_interrupt_ctrl(uint8_t hintr_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to get the host interrupt control register + * @param[out] hintr_ctrl : Reference to the data buffer to store the configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_host_interrupt_ctrl(uint8_t *hintr_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to get the interrupt status register + * @param[out] int_status : Reference to the data buffer to store the interrupt status + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_interrupt_status(uint8_t *int_status, struct bhy2_dev *dev); + +/** + * @brief Function to set the host interface control register + * @param[in] hintf_ctrl : Host interface control configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_host_intf_ctrl(uint8_t hintf_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to get the host interface control register + * @param[out] hintf_ctrl : Reference to the data buffer to store the configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_host_intf_ctrl(uint8_t *hintf_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to trigger a timestamp event + * @param[in] ts_ev_req : Pass a non-zero value to trigger a timestamp event + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_timestamp_event_req(uint8_t ts_ev_req, struct bhy2_dev *dev); + +/** + * @brief Function to get the timestamp of the sensor in nanoseconds + * @param[out] timestamp_ns : Reference to the data buffer to store the timestamp in nanoseconds + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_hw_timestamp_ns(uint64_t *timestamp_ns, struct bhy2_dev *dev); + +/** + * @brief Function to get the host control register + * @param[in] host_ctrl : Host control configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_host_ctrl(uint8_t host_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to get the host control register + * @param[out] host_ctrl : Reference to the data buffer to store the host control configuration + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_host_ctrl(uint8_t *host_ctrl, struct bhy2_dev *dev); + +/** + * @brief Function to trigger a soft reset + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_soft_reset(struct bhy2_dev *dev); + +/** + * @brief Function to perform a self test of a virtual sensor + * @param[in] phys_sensor_id : Physical sensor ID of the virtual sensor + * @param[out] self_test_resp : Reference to the data buffer to store the self test response from the virtual sensor + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_perform_self_test(uint8_t phys_sensor_id, struct bhy2_self_test_resp *self_test_resp, struct bhy2_dev *dev); + +/** + * @brief Function to perform a fast offset compensation of a virtual sensor + * @param[in] phys_sensor_id : Physical Sensor ID of the virtual sensor + * @param[out] self_test_resp : Reference to the data buffer to store the FOC response from the virtual sensor + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_perform_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_dev *dev); + +/** + * @brief Function to set the orientation matrix of a physical sensor + * @param[in] phys_sensor_id : Sensor ID of the virtual sensor + * @param[in] orient_matrix : Orientation matrix + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_orientation_matrix(uint8_t phys_sensor_id, struct bhy2_orient_matrix orient_matrix, + struct bhy2_dev *dev); + +/** + * @brief Function to get the physical sensor information + * @param[in] phys_sensor_id : Sensor ID of the physical sensor + * @param[out] phy_sen_info : Reference to the data buffer to the store the physical sensor information + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_phys_sensor_info(uint8_t phys_sensor_id, + struct bhy2_phys_sensor_info *phy_sen_info, + struct bhy2_dev *dev); + +/** + * @brief Function to get the orientation matrix of a physical sensor + * @param[in] phys_sensor_id : Sensor ID of the virtual sensor + * @param[out] orient_matrix : Reference to the data buffer to the store the orientation matrix + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_orientation_matrix(uint8_t phys_sensor_id, + struct bhy2_orient_matrix *orient_matrix, + struct bhy2_dev *dev); + +/** + * @brief Function to set the Soft Iron Correction matrix + * @param[in] sic_matrix : Reference to the data buffer storing the Soft Iron Correction matrix + * @param[in] matrix_len : Length of the matrix + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_sic_matrix(const uint8_t *sic_matrix, uint16_t matrix_len, struct bhy2_dev *dev); + +/** + * @brief Function to get the Soft Iron Correction matrix + * @param[out] sic_matrix : Reference to the data buffer to store the Soft Iron Correction matrix + * @param[in] matrix_len : Length of data buffer + * @param[out] actual_len : Actual length of the Soft Iron Correction matrix + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_sic_matrix(uint8_t *sic_matrix, uint16_t matrix_len, uint32_t *actual_len, struct bhy2_dev *dev); + +/** + * @brief Function to get the calibration profile of a BSX virtual sensor + * @param[in] phys_sensor_id: Physical Sensor ID of the virtual sensor + * @param[out] calib_prof : Reference to the data buffer to store the calibration profile + * @param[in] prof_len : Length of the data buffer + * @param[out] actual_len : Actual length of the calibration profile + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_calibration_profile(uint8_t phys_sensor_id, + uint8_t *calib_prof, + uint16_t prof_len, + uint32_t *actual_len, + struct bhy2_dev *dev); + +/** + * @brief Function to set the calibration profile of a BSX virtual sensor + * @param[in] phys_sensor_id: Physical Sensor ID of the virtual sensor + * @param[in] calib_prof : Reference to the data buffer storing the calibration profile + * @param[in] prof_len : Length of the profil + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_calibration_profile(uint8_t phys_sensor_idv, + const uint8_t *calib_prof, + uint16_t prof_len, + struct bhy2_dev *dev); + +/** + * @brief Function to get the post mortem data + * @param[out] post_mortem : Reference to the data buffer to store the post mortem data + * @param[in] buffer_len : Length of the data buffer + * @param[out] actual_len : Actual length of the post mortem data + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_post_mortem_data(uint8_t *post_mortem, uint32_t buffer_len, uint32_t *actual_len, struct bhy2_dev *dev); + +/** + * @brief Function to link a callback and relevant reference when the sensor event is available in the FIFO + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] callback : Reference of the callback function + * @param[in] callback_ref : Reference needed inside the callback function. Can be NULL + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_register_fifo_parse_callback(uint8_t sensor_id, + bhy2_fifo_parse_callback_t callback, + void *callback_ref, + struct bhy2_dev *dev); + +/** + * @brief Function to unlink a callback and relevant reference + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_deregister_fifo_parse_callback(uint8_t sensor_id, struct bhy2_dev *dev); + +/** + * @brief Function to update the callback table's information + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_update_virtual_sensor_list(struct bhy2_dev *dev); + +/** + * @brief Function to get information of a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[out] info : Reference to the data buffer to store the virtual sensor information + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_dev *dev); + +/** + * @brief Function to set a parameter + * @param[in] param : Parameter ID + * @param[in] payload : Reference to the data buffer storing the parameter's payload + * @param[in] length : Length of the payload + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_dev *dev); + +/** + * @brief Function to get a parameter + * @param[in] param : Parameter ID + * @param[out] payload : Reference to the data buffer to store the parameter's payload + * @param[in] payload_len : Length of the data buffer + * @param[out] actual_len : Actual length of the payload + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_parameter(uint16_t param, + uint8_t *payload, + uint32_t payload_len, + uint32_t *actual_len, + struct bhy2_dev *dev); + +/** + * @brief Function to get the error value register + * @param[out] error_value : Reference to the data buffer to store the error value + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_get_error_value(uint8_t *error_value, struct bhy2_dev *dev); + +/** + * @brief Function to directly communicate with the sensor + * @param[in] conf : The configuration of the transfer + * @param[in] reg_addr : Register address to write to + * @param[in] length : Length of the data buffer to be transferred + * @param[in/out] reg_data : Reference to the data buffer + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_soft_passthrough_transfer(union bhy2_soft_passthrough_conf *conf, + uint8_t reg_addr, + uint8_t length, + uint8_t *reg_data, + struct bhy2_dev *dev); + +/** + * @brief Function to check if a virtual sensor is available + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] dev : Device reference + * @return 1 if the sensor is available. 0 otherwise + */ +uint8_t bhy2_is_sensor_available(uint8_t sensor_id, const struct bhy2_dev *dev); + +/** + * @brief Function to get the BHy260 variant ID + * + * @param[in] variant_id : Reference to store the variant ID + * @param[in] dev : Device reference + * @return int8_t API error codes + */ +int8_t bhy2_get_variant_id(uint32_t *variant_id, struct bhy2_dev *dev); + +/** + * @brief Function to inject data + * @param[in] payload : Reference to the data buffer + * @param[in] payload_len : Length of the data buffer + * @param[in] dev : Device reference + * @return API error codes + */ + +int8_t bhy2_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_dev *dev); + +/** + * @brief Function to set inject mode + * @param[in] mode : Type of data inject mode + * @param[in] dev : Device reference + * @return API error codes + */ +int8_t bhy2_set_data_injection_mode(enum bhy2_data_inj_mode mode, struct bhy2_dev *dev); + +/** +* @brief Function to clear the FIFO +* @param[in] flush_cfg : Type of FIFO Flush +* @param[in] dev : Device reference +* @return API error codes +*/ +int8_t bhy2_clear_fifo(uint8_t flush_cfg, struct bhy2_dev *dev); + +/** +* @brief Function to read the status FIFO +* @param[out] status_code : Status Code +* @param[in] status_buff : Buffer for reading Status Response +* @param[in] status_len : Length of the Response +* @param[out] actual_len : Length of Data read +* @param[in] dev : Device reference +* @return API error codes +*/ +int8_t bhy2_read_status(uint16_t *status_code, + uint8_t *status_buff, + uint32_t status_len, + uint32_t *actual_len, + struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHY2_H__ */ diff --git a/components/SensorLib/src/bosch/bhy2_bsec.c b/components/SensorLib/src/bosch/bhy2_bsec.c new file mode 100644 index 0000000..e32f708 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_bsec.c @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bhy2_bsec.c + * @date 2023-03-24 + * @version v1.6.0 + * + */ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include + +/*********************************************************************/ +/* BHY2 SensorAPI header files */ +/*********************************************************************/ +#include "bhy2.h" + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "bhy2_bsec.h" + +void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data) +{ + uint8_t i = 0; + + if ((payload != NULL) && (data != NULL)) + { + data->comp_temp = BHY2_LE2U32(payload + i); + i += 4; + data->comp_hum = BHY2_LE2U32(payload + i); + i += 4; + data->comp_gas = BHY2_LE2U32(payload + i); + i += 4; + data->iaq = BHY2_LE2U32(payload + i); + i += 4; + data->static_iaq = BHY2_LE2U32(payload + i); + i += 4; + data->e_co2 = BHY2_LE2U32(payload + i); + i += 4; + data->voc = BHY2_LE2U32(payload + i); + i += 4; + data->iaq_accuracy = payload[i]; + } +} diff --git a/components/SensorLib/src/bosch/bhy2_bsec.h b/components/SensorLib/src/bosch/bhy2_bsec.h new file mode 100644 index 0000000..2d018fe --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_bsec.h @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bhy2_bsec.h + * @date 2023-03-24 + * @version v1.6.0 + * + */ + +#ifndef _BHY2_BSEC_H_ +#define _BHY2_BSEC_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include +#include + +#include "bhy2.h" + +#define BHY2_SENSOR_ID_AIR_QUALITY UINT8_C(115) + +struct bhy2_bsec_air_quality +{ + float comp_temp; /* Sensor heat compensated temperature (deg C) */ + float comp_hum; /* Sensor heat compensated humidity (%rH) */ + float comp_gas; /* Compensated gas resistance (ohms) */ + float iaq; /* Indoor Air Quality index */ + float static_iaq; /* Static IAQ index */ + float e_co2; /* Equivalent CO2 (ppm) */ + float voc; /* Volatile organic compounds (ppb) */ + uint8_t iaq_accuracy; /* IAQ index accuracy (0-3) */ +}; + +void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_BSEC_H_ */ diff --git a/components/SensorLib/src/bosch/bhy2_defs.h b/components/SensorLib/src/bosch/bhy2_defs.h new file mode 100644 index 0000000..4d76c41 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_defs.h @@ -0,0 +1,789 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHY2_DEFS_H__ +#define __BHY2_DEFS_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#ifdef __KERNEL__ +#include +#include +#include +#else +#include +#include +#endif /*~ __KERNEL__ */ + +#ifndef UNUSED +#define UNUSED(__x__) ((void)(__x__)) +#endif /*~ UNUSED */ + +#ifdef __KERNEL__ +#define bhy2_float u32 +#else +#define bhy2_float float +#endif /*~ __KERNEL__ */ + +#ifdef __KERNEL__ + +#if !defined(UINT8_C) && !defined(INT8_C) +#define INT8_C(x) S8_C(x) +#define UINT8_C(x) U8_C(x) +#endif + +#if !defined(UINT16_C) && !defined(INT16_C) +#define INT16_C(x) S16_C(x) +#define UINT16_C(x) U16_C(x) +#endif + +#if !defined(INT32_C) && !defined(UINT32_C) +#define INT32_C(x) S32_C(x) +#define UINT32_C(x) U32_C(x) +#endif + +#if !defined(INT64_C) && !defined(UINT64_C) +#define INT64_C(x) S64_C(x) +#define UINT64_C(x) U64_C(x) +#endif + +#else /* __KERNEL__ */ + +#if !defined(UINT8_C) && !defined(INT8_C) +#define INT8_C(x) (x) +#define UINT8_C(x) (x##U) +#endif + +#if !defined(UINT16_C) && !defined(INT16_C) +#define INT16_C(x) (x) +#define UINT16_C(x) (x##U) +#endif + +#if !defined(INT32_C) && !defined(UINT32_C) +#define INT32_C(x) (x) +#define UINT32_C(x) (x##U) +#endif + +#if !defined(INT64_C) && !defined(UINT64_C) +#define INT64_C(x) (x##LL) +#define UINT64_C(x) (x##ULL) +#endif + +#endif /* __KERNEL__ */ + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *) 0) +#endif +#endif + +#ifndef BHY2_PACKED +#define BHY2_PACKED __attribute__ ((__packed__)) +#endif + +/** API error codes */ +#define BHY2_OK INT8_C(0) +#define BHY2_E_NULL_PTR INT8_C(-1) +#define BHY2_E_INVALID_PARAM INT8_C(-2) +#define BHY2_E_IO INT8_C(-3) +#define BHY2_E_MAGIC INT8_C(-4) +#define BHY2_E_TIMEOUT INT8_C(-5) +#define BHY2_E_BUFFER INT8_C(-6) +#define BHY2_E_INVALID_FIFO_TYPE INT8_C(-7) +#define BHY2_E_INVALID_EVENT_SIZE INT8_C(-8) +#define BHY2_E_PARAM_NOT_SET INT8_C(-9) +#define BHy2_E_INSUFFICIENT_MAX_SIMUL_SENSORS INT8_C(-10) + +#ifndef BHY2_COMMAND_PACKET_LEN +#define BHY2_COMMAND_PACKET_LEN UINT16_C(256) +#endif + +#ifndef BHY2_COMMAND_HEADER_LEN +#define BHY2_COMMAND_HEADER_LEN UINT16_C(4) +#endif + +#if (BHY2_COMMAND_PACKET_LEN < BHY2_COMMAND_HEADER_LEN) +#error "BHY2_COMMAND_PACKET_LEN should be at least 4 bytes" +#endif + +#define BHY2_PRODUCT_ID UINT8_C(0x89) + +/*! Register map */ +#define BHY2_REG_CHAN_CMD UINT8_C(0x00) +#define BHY2_REG_CHAN_FIFO_W UINT8_C(0x01) +#define BHY2_REG_CHAN_FIFO_NW UINT8_C(0x02) +#define BHY2_REG_CHAN_STATUS UINT8_C(0x03) +#define BHY2_REG_CHIP_CTRL UINT8_C(0x05) +#define BHY2_REG_HOST_INTERFACE_CTRL UINT8_C(0x06) +#define BHY2_REG_HOST_INTERRUPT_CTRL UINT8_C(0x07) +#define BHY2_REG_RESET_REQ UINT8_C(0x14) +#define BHY2_REG_TIME_EV_REQ UINT8_C(0x15) +#define BHY2_REG_HOST_CTRL UINT8_C(0x16) +#define BHY2_REG_HOST_STATUS UINT8_C(0x17) +#define BHY2_REG_CRC_0 UINT8_C(0x18) /* Totally 4 */ +#define BHY2_REG_PRODUCT_ID UINT8_C(0x1C) +#define BHY2_REG_REVISION_ID UINT8_C(0x1D) +#define BHY2_REG_ROM_VERSION_0 UINT8_C(0x1E) /* Totally 2 */ +#define BHY2_REG_KERNEL_VERSION_0 UINT8_C(0x20) /* Totally 2 */ +#define BHY2_REG_USER_VERSION_0 UINT8_C(0x22) /* Totally 2 */ +#define BHY2_REG_FEATURE_STATUS UINT8_C(0x24) +#define BHY2_REG_BOOT_STATUS UINT8_C(0x25) +#define BHY2_REG_HOST_INTR_TIME_0 UINT8_C(0x26) /* Totally 5 */ +#define BHY2_REG_CHIP_ID UINT8_C(0x2B) +#define BHY2_REG_INT_STATUS UINT8_C(0x2D) +#define BHY2_REG_ERROR_VALUE UINT8_C(0x2E) +#define BHY2_REG_ERROR_AUX UINT8_C(0x2F) +#define BHY2_REG_DEBUG_VALUE UINT8_C(0x30) +#define BHY2_REG_DEBUG_STATE UINT8_C(0x31) +#define BHY2_REG_GP_5 UINT8_C(0x32) +#define BHY2_REG_GP_6 UINT8_C(0x36) +#define BHY2_REG_GP_7 UINT8_C(0x3A) + +/*! Command packets */ +#define BHY2_CMD_REQ_POST_MORTEM_DATA UINT16_C(0x0001) +#define BHY2_CMD_UPLOAD_TO_PROGRAM_RAM UINT16_C(0x0002) +#define BHY2_CMD_BOOT_PROGRAM_RAM UINT16_C(0x0003) +#define BHY2_CMD_ERASE_FLASH UINT16_C(0x0004) +#define BHY2_CMD_WRITE_FLASH UINT16_C(0x0005) +#define BHY2_CMD_BOOT_FLASH UINT16_C(0x0006) +#define BHY2_CMD_SET_INJECT_MODE UINT16_C(0x0007) +#define BHY2_CMD_INJECT_DATA UINT16_C(0x0008) +#define BHY2_CMD_FIFO_FLUSH UINT16_C(0x0009) +#define BHY2_CMD_SW_PASSTHROUGH UINT16_C(0x000A) +#define BHY2_CMD_REQ_SELF_TEST UINT16_C(0x000B) +#define BHY2_CMD_REQ_FOC UINT16_C(0x000C) +#define BHY2_CMD_CONFIG_SENSOR UINT16_C(0x000D) +#define BHY2_CMD_CHANGE_RANGE UINT16_C(0x000E) +#define BHY2_CMD_FIFO_FORMAT_CTRL UINT16_C(0x0015) + +/*! Soft passthrough feature */ +#define BHY2_SPASS_READ UINT8_C(0) +#define BHY2_SPASS_WRITE UINT8_C(1) +#define BHY2_SPASS_SINGLE_TRANS UINT8_C(0) +#define BHY2_SPASS_MULTI_TRANS UINT8_C(1) +#define BHY2_SPASS_DELAY_DIS UINT8_C(0) +#define BHY2_SPASS_DELAY_EN UINT8_C(1) +#define BHY2_SPASS_SIF1 UINT8_C(1) +#define BHY2_SPASS_SIF2 UINT8_C(2) +#define BHY2_SPASS_SIF3 UINT8_C(3) +#define BHY2_SPASS_SPI_4_WIRE UINT8_C(0) +#define BHY2_SPASS_SPI_3_WIRE UINT8_C(1) +#define BHY2_SPASS_SPI_CPOL_0 UINT8_C(0) +#define BHY2_SPASS_SPI_CPOL_1 UINT8_C(1) +#define BHY2_SPASS_SPI_CPHA_0 UINT8_C(0) +#define BHY2_SPASS_SPI_CPHA_1 UINT8_C(1) +#define BHY2_SPASS_SPI_CS_LOW UINT8_C(0) +#define BHY2_SPASS_SPI_CS_HIGH UINT8_C(1) +#define BHY2_SPASS_SPI_LSB_FIRST_DIS UINT8_C(0) +#define BHY2_SPASS_SPI_LSB_FIRST_EN UINT8_C(1) +#define BHY2_SPASS_SPI_READ_BIT_POL_LOW UINT8_C(0) +#define BHY2_SPASS_SPI_READ_BIT_POL_HIGH UINT8_C(1) +#define BHY2_SPASS_SPI_READ_BIT_POS_0 UINT8_C(0) +#define BHY2_SPASS_SPI_READ_BIT_POS_1 UINT8_C(1) +#define BHY2_SPASS_SPI_READ_BIT_POS_2 UINT8_C(2) +#define BHY2_SPASS_SPI_READ_BIT_POS_3 UINT8_C(3) +#define BHY2_SPASS_SPI_READ_BIT_POS_4 UINT8_C(4) +#define BHY2_SPASS_SPI_READ_BIT_POS_5 UINT8_C(5) +#define BHY2_SPASS_SPI_READ_BIT_POS_6 UINT8_C(6) +#define BHY2_SPASS_SPI_READ_BIT_POS_7 UINT8_C(7) +#define BHY2_SPASS_READ_PACKET_LEN UINT8_C(0x13) +#define BHY2_SPASS_WRITE_RESP_PACKET_LEN UINT8_C(16) + +/*! Helper macros */ +#define BHY2_CHK_BIT(data, bit) (((uint32_t)data >> bit) & 0x01) +#define BHY2_ROUND_WORD_LOWER(x) ((x >> 2) << 2) +#define BHY2_ROUND_WORD_HIGHER(x) (((x >> 2) + 1) << 2) + +#define BHY2_COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__))) +#define BHY2_DATA_INJECT_MODE_PAYLOAD_LEN UINT8_C(0x04) + +/*! Firmware header identifier */ +#define BHY2_FW_MAGIC UINT16_C(0x662B) + +/*! BHy260 Variant IDs */ +#define BHY2_VARIANT_ID_BHA260AB UINT32_C(0x2838C2C2) +#define BHY2_VARIANT_ID_BHI260AB UINT32_C(0x266EB6E7) +#define BHY2_VARIANT_ID_BHI260AP UINT32_C(0x98D7A5D1) + +/*! Boot status */ +#define BHY2_BST_FLASH_DETECTED UINT8_C(0x01) +#define BHY2_BST_FLASH_VERIFY_DONE UINT8_C(0x02) +#define BHY2_BST_FLASH_VERIFY_ERROR UINT8_C(0x04) +#define BHY2_BST_NO_FLASH UINT8_C(0x08) +#define BHY2_BST_HOST_INTERFACE_READY UINT8_C(0x10) +#define BHY2_BST_HOST_FW_VERIFY_DONE UINT8_C(0x20) +#define BHY2_BST_HOST_FW_VERIFY_ERROR UINT8_C(0x40) +#define BHY2_BST_HOST_FW_IDLE UINT8_C(0x80) +#define BHY2_BST_CHECK_RETRY UINT8_C(100) + +/*! Host status */ +#define BHY2_HST_POWER_STATE UINT8_C(0x01) +#define BHY2_HST_HOST_PROTOCOL UINT8_C(0x02) +#define BHY2_HST_HOST_CHANNEL_0 UINT8_C(0x10) +#define BHY2_HST_HOST_CHANNEL_1 UINT8_C(0x20) +#define BHY2_HST_HOST_CHANNEL_2 UINT8_C(0x40) +#define BHY2_HST_HOST_CHANNEL_3 UINT8_C(0x80) + +/*! Interrupt status masks */ +#define BHY2_IST_MASK_ASSERTED (0x1) +#define BHY2_IST_MASK_FIFO_W (0x6) +#define BHY2_IST_MASK_FIFO_NW (0x18) +#define BHY2_IST_MASK_STATUS (0x20) +#define BHY2_IST_MASK_DEBUG (0x40) +#define BHY2_IST_MASK_RESET_FAULT (0x80) +#define BHY2_IST_FIFO_W_DRDY UINT8_C(0x2) +#define BHY2_IST_FIFO_W_LTCY UINT8_C(0x4) +#define BHY2_IST_FIFO_W_WM UINT8_C(0x6) +#define BHY2_IST_FIFO_NW_DRDY UINT8_C(0x8) +#define BHY2_IST_FIFO_NW_LTCY UINT8_C(0x10) +#define BHY2_IST_FIFO_NW_WM UINT8_C(0x18) +#define BHY2_IS_INT_FIFO_W(status) (status & BHY2_IST_MASK_FIFO_W) +#define BHY2_IS_INT_FIFO_NW(status) (status & BHY2_IST_MASK_FIFO_NW) +#define BHY2_IS_INT_STATUS(status) (status & BHY2_IST_MASK_STATUS) +#define BHY2_IS_INT_ASYNC_STATUS(status) (status & BHY2_IST_MASK_DEBUG) +#define BHY2_IS_INT_RESET(status) (status & BHY2_IST_MASK_RESET_FAULT) +#define BHY2_IST_MASK_FIFO (BHY2_IST_MASK_FIFO_W | BHY2_IST_MASK_FIFO_NW) +#define BHY2_IS_INT_FIFO(status) (status & BHY2_IST_MASK_FIFO) + +/*! Chip control bits */ +#define BHY2_CHIP_CTRL_DISABLE UINT8_C(0x00) +#define BHY2_CHIP_CTRL_TURBO_ENABLE UINT8_C(0x01) +#define BHY2_CHIP_CTRL_CLR_ERR_REG UINT8_C(0x02) + +/*! Host interface control bits */ +#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_0 UINT8_C(0x01) +#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_1 UINT8_C(0x02) +#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_2 UINT8_C(0x04) +#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_3 UINT8_C(0x08) +#define BHY2_HIF_CTRL_AP_SUSPENDED UINT8_C(0x10) +#define BHY2_HIF_CTRL_TIMESTAMP_EV_CTRL UINT8_C(0x40) +#define BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL UINT8_C(0x80) + +/*! Interrupt control bits */ +#define BHY2_ICTL_DISABLE_FIFO_W UINT8_C(0x01) +#define BHY2_ICTL_DISABLE_FIFO_NW UINT8_C(0x02) +#define BHY2_ICTL_DISABLE_STATUS_FIFO UINT8_C(0x04) +#define BHY2_ICTL_DISABLE_DEBUG UINT8_C(0x08) +#define BHY2_ICTL_DISABLE_FAULT UINT8_C(0x10) +#define BHY2_ICTL_ACTIVE_LOW UINT8_C(0x20) +#define BHY2_ICTL_EDGE UINT8_C(0x40) +#define BHY2_ICTL_OPEN_DRAIN UINT8_C(0x80) + +/*! Reset command */ +#define BHY2_REQUEST_RESET UINT8_C(0x01) + +/*! FIFO Format bit */ +#define BHY2_FIFO_FORMAT_CTRL_MASK UINT8_C(0x03) +#define BHY2_FIFO_FORMAT_CTRL_DIS_DELTA_TS UINT8_C(0x01) +#define BHY2_FIFO_FORMAT_CTRL_DIS_FULL_TS UINT8_C(0x02) +#define BHY2_FIFO_FORMAT_CTRL_DIS_ALL_TS UINT8_C(0x03) + +/*! System parameters */ +#define BHY2_PARAM_READ_MASK UINT16_C(0x1000) +#define BHY2_PARAM_FIFO_CTRL UINT16_C(0x103) +#define BHY2_PARAM_SYS_VIRT_SENSOR_PRESENT UINT16_C(0x11F) +#define BHY2_PARAM_SYS_PHYS_SENSOR_PRESENT UINT16_C(0x120) +#define BHY2_PARAM_PHYSICAL_SENSOR_BASE UINT16_C(0x120) +#define BHY2_PARAM_BSX_CALIB_STATE_BASE UINT16_C(0x200) +#define BHY2_PARAM_BSX_CALIB_STATE_ACCEL UINT16_C(0x201) +#define BHY2_PARAM_BSX_CALIB_STATE_GYRO UINT16_C(0x203) +#define BHY2_PARAM_BSX_CALIB_STATE_MAG UINT16_C(0x205) +#define BHY2_PARAM_BSX_SIC UINT16_C(0x27D) +#define BHY2_PARAM_BSX_VERSION UINT16_C(0x27E) +#define BHY2_PARAM_SET_SENSOR_CTRL UINT16_C(0x0E00) +#define BHY2_PARAM_GET_SENSOR_CTRL UINT16_C(0x1E00) +#define BHY2_PARAM_SENSOR_CTRL_FOC UINT8_C(0x1) +#define BHY2_PARAM_SENSOR_CTRL_OIS UINT8_C(0x2) +#define BHY2_PARAM_SENSOR_CTRL_FST UINT8_C(0x3) +#define BHY2_PARAM_SENSOR_CTRL_READ UINT8_C(0x80) +#define BHY2_PARAM_SENSOR_INFO_0 UINT16_C(0x300) +#define BHY2_PARAM_SENSOR_CONF_0 UINT16_C(0x500) + +#define BHY2_BSX_STATE_TRANSFER_COMPLETE UINT8_C(0x80) +#define BHY2_BSX_STATE_BLOCK_NUM_MSK UINT8_C(0x7F) +#define BHY2_BSX_STATE_BLOCK_LEN UINT8_C(64) +#define BHY2_BSX_STATE_STRUCT_LEN UINT8_C(68) + +#define BHY2_QUERY_PARAM_STATUS_READY_MAX_RETRY UINT16_C(1000) +#define BHY2_QUERY_FLASH_MAX_RETRY UINT16_C(1200) + +/*! Meta event definitions */ +#define BHY2_META_EVENT_FLUSH_COMPLETE (1) +#define BHY2_META_EVENT_SAMPLE_RATE_CHANGED (2) +#define BHY2_META_EVENT_POWER_MODE_CHANGED (3) +#define BHY2_META_EVENT_ALGORITHM_EVENTS (5) +#define BHY2_META_EVENT_SENSOR_STATUS (6) +#define BHY2_META_EVENT_BSX_DO_STEPS_MAIN (7) +#define BHY2_META_EVENT_BSX_DO_STEPS_CALIB (8) +#define BHY2_META_EVENT_BSX_GET_OUTPUT_SIGNAL (9) +#define BHY2_META_EVENT_RESERVED1 (10) +#define BHY2_META_EVENT_SENSOR_ERROR (11) +#define BHY2_META_EVENT_FIFO_OVERFLOW (12) +#define BHY2_META_EVENT_DYNAMIC_RANGE_CHANGED (13) +#define BHY2_META_EVENT_FIFO_WATERMARK (14) +#define BHY2_META_EVENT_RESERVED2 (15) +#define BHY2_META_EVENT_INITIALIZED (16) +#define BHY2_META_TRANSFER_CAUSE (17) +#define BHY2_META_EVENT_SENSOR_FRAMEWORK (18) +#define BHY2_META_EVENT_RESET (19) +#define BHY2_META_EVENT_SPACER (20) + +/* Flash start address in memory */ +#define BHY2_FLASH_SECTOR_START_ADDR UINT32_C(0x1F84) +#define BHY2_FLASH_BULK_ERASE UINT32_C(0xFFFFFFFF) + +/* End address for common flash sizes */ +#define BHY2_FLASH_SIZE_0_5MB UINT32_C(0x7FFFF) +#define BHY2_FLASH_SIZE_1MB UINT32_C(0xFFFFF) +#define BHY2_FLASH_SIZE_2MB UINT32_C(0x1FFFFF) +#define BHY2_FLASH_SIZE_4MB UINT32_C(0x3FFFFF) +#define BHY2_FLASH_SIZE_8MB UINT32_C(0x7FFFFF) + +/* Sensor IDs */ +#define BHY2_SENSOR_ID_CUSTOM_START UINT8_C(160) +#define BHY2_SENSOR_ID_CUSTOM_END UINT8_C(191) + +#define BHY2_SENSOR_ID_MAX UINT8_C(200) +#define BHY2_SENSOR_ID_TBD UINT8_C(BHY2_SENSOR_ID_MAX - 1) + +/* Virtual Sensor IDs */ +#define BHY2_SENSOR_ID_ACC_PASS UINT8_C(1) /* Accelerometer passthrough */ +#define BHY2_SENSOR_ID_ACC_RAW UINT8_C(3) /* Accelerometer uncalibrated */ +#define BHY2_SENSOR_ID_ACC UINT8_C(4) /* Accelerometer corrected */ +#define BHY2_SENSOR_ID_ACC_BIAS UINT8_C(5) /* Accelerometer offset */ +#define BHY2_SENSOR_ID_ACC_WU UINT8_C(6) /* Accelerometer corrected wake up */ +#define BHY2_SENSOR_ID_ACC_RAW_WU UINT8_C(7) /* Accelerometer uncalibrated wake up */ +#define BHY2_SENSOR_ID_SI_ACCEL UINT8_C(8) /* Virtual Sensor ID for Accelerometer */ +#define BHY2_SENSOR_ID_GYRO_PASS UINT8_C(10) /* Gyroscope passthrough */ +#define BHY2_SENSOR_ID_GYRO_RAW UINT8_C(12) /* Gyroscope uncalibrated */ +#define BHY2_SENSOR_ID_GYRO UINT8_C(13) /* Gyroscope corrected */ +#define BHY2_SENSOR_ID_GYRO_BIAS UINT8_C(14) /* Gyroscope offset */ +#define BHY2_SENSOR_ID_GYRO_WU UINT8_C(15) /* Gyroscope wake up */ +#define BHY2_SENSOR_ID_GYRO_RAW_WU UINT8_C(16) /* Gyroscope uncalibrated wake up */ +#define BHY2_SENSOR_ID_SI_GYROS UINT8_C(17) /* Virtual Sensor ID for Gyroscope */ +#define BHY2_SENSOR_ID_MAG_PASS UINT8_C(19) /* Magnetometer passthrough */ +#define BHY2_SENSOR_ID_MAG_RAW UINT8_C(21) /* Magnetometer uncalibrated */ +#define BHY2_SENSOR_ID_MAG UINT8_C(22) /* Magnetometer corrected */ +#define BHY2_SENSOR_ID_MAG_BIAS UINT8_C(23) /* Magnetometer offset */ +#define BHY2_SENSOR_ID_MAG_WU UINT8_C(24) /* Magnetometer wake up */ +#define BHY2_SENSOR_ID_MAG_RAW_WU UINT8_C(25) /* Magnetometer uncalibrated wake up */ +#define BHY2_SENSOR_ID_GRA UINT8_C(28) /* Gravity vector */ +#define BHY2_SENSOR_ID_GRA_WU UINT8_C(29) /* Gravity vector wake up */ +#define BHY2_SENSOR_ID_LACC UINT8_C(31) /* Linear acceleration */ +#define BHY2_SENSOR_ID_LACC_WU UINT8_C(32) /* Linear acceleration wake up */ +#define BHY2_SENSOR_ID_RV UINT8_C(34) /* Rotation vector */ +#define BHY2_SENSOR_ID_RV_WU UINT8_C(35) /* Rotation vector wake up */ +#define BHY2_SENSOR_ID_GAMERV UINT8_C(37) /* Game rotation vector */ +#define BHY2_SENSOR_ID_GAMERV_WU UINT8_C(38) /* Game rotation vector wake up */ +#define BHY2_SENSOR_ID_GEORV UINT8_C(40) /* Geo-magnetic rotation vector */ +#define BHY2_SENSOR_ID_GEORV_WU UINT8_C(41) /* Geo-magnetic rotation vector wake up */ +#define BHY2_SENSOR_ID_ORI UINT8_C(43) /* Orientation */ +#define BHY2_SENSOR_ID_ORI_WU UINT8_C(44) /* Orientation wake up */ +#define BHY2_SENSOR_ID_TILT_DETECTOR UINT8_C(48) /* Tilt detector */ +#define BHY2_SENSOR_ID_STD UINT8_C(50) /* Step detector */ +#define BHY2_SENSOR_ID_STC UINT8_C(52) /* Step counter */ +#define BHY2_SENSOR_ID_STC_WU UINT8_C(53) /* Step counter wake up */ +#define BHY2_SENSOR_ID_SIG UINT8_C(55) /* Significant motion */ +#define BHY2_SENSOR_ID_WAKE_GESTURE UINT8_C(57) /* Wake gesture */ +#define BHY2_SENSOR_ID_GLANCE_GESTURE UINT8_C(59) /* Glance gesture */ +#define BHY2_SENSOR_ID_PICKUP_GESTURE UINT8_C(61) /* Pickup gesture */ +#define BHY2_SENSOR_ID_AR UINT8_C(63) /* Activity recognition */ +#define BHY2_SENSOR_ID_WRIST_TILT_GESTURE UINT8_C(67) /* Wrist tilt gesture */ +#define BHY2_SENSOR_ID_DEVICE_ORI UINT8_C(69) /* Device orientation */ +#define BHY2_SENSOR_ID_DEVICE_ORI_WU UINT8_C(70) /* Device orientation wake up */ +#define BHY2_SENSOR_ID_STATIONARY_DET UINT8_C(75) /* Stationary detect */ +#define BHY2_SENSOR_ID_MOTION_DET UINT8_C(77) /* Motion detect */ +#define BHY2_SENSOR_ID_ACC_BIAS_WU UINT8_C(91) /* Accelerometer offset wake up */ +#define BHY2_SENSOR_ID_GYRO_BIAS_WU UINT8_C(92) /* Gyroscope offset wake up */ +#define BHY2_SENSOR_ID_MAG_BIAS_WU UINT8_C(93) /* Magnetometer offset wake up */ +#define BHY2_SENSOR_ID_STD_WU UINT8_C(94) /* Step detector wake up */ +#define BHY2_SENSOR_ID_TEMP UINT8_C(128) /* Temperature */ +#define BHY2_SENSOR_ID_BARO UINT8_C(129) /* Barometer */ +#define BHY2_SENSOR_ID_HUM UINT8_C(130) /* Humidity */ +#define BHY2_SENSOR_ID_GAS UINT8_C(131) /* Gas */ +#define BHY2_SENSOR_ID_TEMP_WU UINT8_C(132) /* Temperature wake up */ +#define BHY2_SENSOR_ID_BARO_WU UINT8_C(133) /* Barometer wake up */ +#define BHY2_SENSOR_ID_HUM_WU UINT8_C(134) /* Humidity wake up */ +#define BHY2_SENSOR_ID_GAS_WU UINT8_C(135) /* Gas wake up */ +#define BHY2_SENSOR_ID_STC_LP UINT8_C(136) /* Step counter Low Power */ +#define BHY2_SENSOR_ID_STD_LP UINT8_C(137) /* Step detector Low Power */ +#define BHY2_SENSOR_ID_SIG_LP UINT8_C(138) /* Significant motion Low Power */ +#define BHY2_SENSOR_ID_STC_LP_WU UINT8_C(139) /* Step counter Low Power wake up */ +#define BHY2_SENSOR_ID_STD_LP_WU UINT8_C(140) /* Step detector Low Power wake up */ +#define BHY2_SENSOR_ID_SIG_LP_WU UINT8_C(141) /* Significant motion Low Power wake up */ +#define BHY2_SENSOR_ID_ANY_MOTION_LP UINT8_C(142) /* Any motion Low Power */ +#define BHY2_SENSOR_ID_ANY_MOTION_LP_WU UINT8_C(143) /* Any motion Low Power wake up */ +#define BHY2_SENSOR_ID_EXCAMERA UINT8_C(144) /* External camera trigger */ +#define BHY2_SENSOR_ID_GPS UINT8_C(145) /* GPS */ +#define BHY2_SENSOR_ID_LIGHT UINT8_C(146) /* Light */ +#define BHY2_SENSOR_ID_PROX UINT8_C(147) /* Proximity */ +#define BHY2_SENSOR_ID_LIGHT_WU UINT8_C(148) /* Light wake up */ +#define BHY2_SENSOR_ID_PROX_WU UINT8_C(149) /* Proximity wake up */ + +/*! Physical sensor IDs*/ +#define BHY2_PHYS_SENSOR_ID_ACCELEROMETER UINT8_C(1) +#define BHY2_PHYS_SENSOR_ID_GYROSCOPE UINT8_C(3) +#define BHY2_PHYS_SENSOR_ID_MAGNETOMETER UINT8_C(5) +#define BHY2_PHYS_SENSOR_ID_TEMP_GYRO UINT8_C(7) +#define BHY2_PHYS_SENSOR_ID_ANY_MOTION UINT8_C(9) +#define BHY2_PHYS_SENSOR_ID_PRESSURE UINT8_C(11) +#define BHY2_PHYS_SENSOR_ID_POSITION UINT8_C(13) +#define BHY2_PHYS_SENSOR_ID_HUMIDITY UINT8_C(15) +#define BHY2_PHYS_SENSOR_ID_TEMPERATURE UINT8_C(17) +#define BHY2_PHYS_SENSOR_ID_GAS_RESISTOR UINT8_C(19) +#define BHY2_PHYS_SENSOR_ID_PHYS_STEP_COUNTER UINT8_C(32) +#define BHY2_PHYS_SENSOR_ID_PHYS_STEP_DETECTOR UINT8_C(33) +#define BHY2_PHYS_SENSOR_ID_PHYS_SIGN_MOTION UINT8_C(34) +#define BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION UINT8_C(35) +#define BHY2_PHYS_SENSOR_ID_EX_CAMERA_INPUT UINT8_C(36) +#define BHY2_PHYS_SENSOR_ID_GPS UINT8_C(48) +#define BHY2_PHYS_SENSOR_ID_LIGHT UINT8_C(49) +#define BHY2_PHYS_SENSOR_ID_PROXIMITY UINT8_C(50) +#define BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION UINT8_C(55) +#define BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT UINT8_C(56) +#define BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP UINT8_C(57) + +/*! System data IDs */ +#define BHY2_IS_SYS_ID(sid) ((sid) >= 224) + +#define BHY2_SYS_ID_PADDING UINT8_C(0) +#define BHY2_SYS_ID_TS_SMALL_DELTA UINT8_C(251) +#define BHY2_SYS_ID_TS_LARGE_DELTA UINT8_C(252) +#define BHY2_SYS_ID_TS_FULL UINT8_C(253) +#define BHY2_SYS_ID_META_EVENT UINT8_C(254) +#define BHY2_SYS_ID_TS_SMALL_DELTA_WU UINT8_C(245) +#define BHY2_SYS_ID_TS_LARGE_DELTA_WU UINT8_C(246) +#define BHY2_SYS_ID_TS_FULL_WU UINT8_C(247) +#define BHY2_SYS_ID_META_EVENT_WU UINT8_C(248) +#define BHY2_SYS_ID_FILLER UINT8_C(255) +#define BHY2_SYS_ID_DEBUG_MSG UINT8_C(250) +#define BHY2_SYS_ID_BHY2_LOG_UPDATE_SUB UINT8_C(243) +#define BHY2_SYS_ID_BHY2_LOG_DOSTEP UINT8_C(244) + +/*! Status code definitions */ +#define BHY2_STATUS_INITIALIZED UINT8_C(0x1) +#define BHY2_STATUS_DEBUG_OUTPUT UINT8_C(0x2) +#define BHY2_STATUS_CRASH_DUMP UINT8_C(0x3) +#define BHY2_STATUS_INJECT_SENSOR_CONF_REQ UINT8_C(0x4) +#define BHY2_STATUS_SW_PASS_THRU_RES UINT8_C(0x5) +#define BHY2_STATUS_SELF_TEST_RES UINT8_C(0x6) +#define BHY2_STATUS_FOC_RES UINT8_C(0x7) +#define BHY2_STATUS_SYSTEM_ERROR UINT8_C(0x8) +#define BHY2_STATUS_SENSOR_ERROR UINT8_C(0x9) +#define BHY2_STATUS_FLASH_ERASE_COMPLETE UINT8_C(0xA) +#define BHY2_STATUS_FLASH_WRITE_COMPLETE UINT8_C(0xB) +#define BHY2_STATUS_FLASH_CONTINUE_UPLOAD UINT8_C(0xC) +#define BHY2_STATUS_HOST_EV_TIMESTAMP UINT8_C(0xD) +#define BHY2_STATUS_DUT_TEST_RES UINT8_C(0xE) +#define BHY2_STATUS_CMD_ERR UINT8_C(0xF) + +#define BHY2_IS_STATUS_GET_PARAM_OUTPUT(status) ((status) >= 0x100 && (status) <= 0xFFF) + +/*! Activity bits */ +#define BHY2_STILL_ACTIVITY_ENDED (0x0001) +#define BHY2_WALKING_ACTIVITY_ENDED (0x0002) +#define BHY2_RUNNING_ACTIVITY_ENDED (0x0004) +#define BHY2_ON_BICYCLE_ACTIVITY_ENDED (0x0008) +#define BHY2_IN_VEHICLE_ACTIVITY_ENDED (0x0010) +#define BHY2_TILTING_ACTIVITY_ENDED (0x0020) + +#define BHY2_STILL_ACTIVITY_STARTED (0x0100) +#define BHY2_WALKING_ACTIVITY_STARTED (0x0200) +#define BHY2_RUNNING_ACTIVITY_STARTED (0x0400) +#define BHY2_ON_BICYCLE_ACTIVITY_STARTED (0x0800) +#define BHY2_IN_VEHICLE_ACTIVITY_STARTED (0x1000) +#define BHY2_TILTING_ACTIVITY_STARTED (0x2000) + +/*! Feature status */ +#define BHY2_FEAT_STATUS_FLASH_DESC_MSK UINT8_C(0x01) +#define BHY2_FEAT_STATUS_OPEN_RTOS_MSK UINT8_C(0x02) +#define BHY2_FEAT_STATUS_OPEN_RTOS_POS (1) +#define BHY2_FEAT_STATUS_HOST_ID_MSK UINT8_C(0x1C) +#define BHY2_FEAT_STATUS_HOST_ID_POS (2) +#define BHY2_FEAT_STATUS_ALGO_ID_MSK UINT8_C(0xE0) +#define BHY2_FEAT_STATUS_ALGO_ID_POS (5) + +/*! Fast offset compensation status codes */ +#define BHY2_FOC_PASS UINT8_C(0x00) +#define BHY2_FOC_FAILED UINT8_C(0x65) +#define BHY2_FOC_UNKNOWN_FAILURE UINT8_C(0x23) + +/*! Self test status codes */ +#define BHY2_ST_PASSED UINT8_C(0x00) +#define BHY2_ST_X_AXIS_FAILED UINT8_C(0x01) +#define BHY2_ST_Y_AXIS_FAILED UINT8_C(0x02) +#define BHY2_ST_Z_AXIS_FAILED UINT8_C(0x04) +#define BHY2_ST_MULTI_AXIS_FAILURE UINT8_C(0x07) +#define BHY2_ST_NOT_SUPPORTED UINT8_C(0x08) +#define BHY2_ST_INVALID_PHYS_ID UINT8_C(0x09) + +#define BHY2_LE2U16(x) ((uint16_t)((x)[0] | (x)[1] << 8)) +#define BHY2_LE2S16(x) ((int16_t)BHY2_LE2U16(x)) +#define BHY2_LE2U24(x) ((uint32_t)((x)[0] | (uint32_t)(x)[1] << 8 | (uint32_t)(x)[2] << 16)) +#define BHY2_LE2S24(x) ((int32_t)(BHY2_LE2U24(x) << 8) >> 8) +#define BHY2_LE2U32(x) ((uint32_t)((x)[0] | (uint32_t)(x)[1] << 8 | (uint32_t)(x)[2] << 16 | \ + (uint32_t)(x)[3] << 24)) +#define BHY2_LE2S32(x) ((int32_t)BHY2_LE2U32(x)) +#define BHY2_LE2U40(x) (BHY2_LE2U32(x) | (uint64_t)(x)[4] << 32) +#define BHY2_LE2U64(x) (BHY2_LE2U32(x) | (uint64_t)BHY2_LE2U32(&(x)[4]) << 32) + +#define BHY2_LE24MUL(x) (((x) % 4) ? (uint16_t)((((x) / 4) + 1) * 4) : (uint16_t)((x) + 4)) + +/*! Maximum no of available virtual sensor */ +#define BHY2_N_VIRTUAL_SENSOR_MAX UINT8_C(256) + +#ifndef BHY2_MAX_SIMUL_SENSORS +#define BHY2_MAX_SIMUL_SENSORS 48 +#endif + +/* Special & debug virtual sensor id starts at 245 */ +#define BHY2_SPECIAL_SENSOR_ID_OFFSET UINT8_C(245) + +#ifndef BHY2_INTF_RET_TYPE +#define BHY2_INTF_RET_TYPE int8_t +#endif + +#ifndef BHY2_INTF_RET_SUCCESS +#define BHY2_INTF_RET_SUCCESS 0 +#endif + +/* Type definitions for the function pointers */ +typedef BHY2_INTF_RET_TYPE (*bhy2_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr); +typedef BHY2_INTF_RET_TYPE (*bhy2_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, + void *intf_ptr); +typedef void (*bhy2_delay_us_fptr_t)(uint32_t period_us, void *intf_ptr); + +enum bhy2_intf { + BHY2_SPI_INTERFACE = 1, + BHY2_I2C_INTERFACE +}; + +/* HIF device structure */ +struct bhy2_hif_dev { + bhy2_read_fptr_t read; + bhy2_write_fptr_t write; + bhy2_delay_us_fptr_t delay_us; + enum bhy2_intf intf; + void *intf_ptr; + BHY2_INTF_RET_TYPE intf_rslt; + uint32_t read_write_len; +}; + +enum bhy2_fifo_type { + BHY2_FIFO_TYPE_WAKEUP, + BHY2_FIFO_TYPE_NON_WAKEUP, + BHY2_FIFO_TYPE_STATUS, + BHY2_FIFO_TYPE_MAX +}; + +struct BHY2_PACKED bhy2_fifo_parse_data_info { + uint8_t sensor_id; + enum bhy2_fifo_type fifo_type; + uint8_t data_size; + uint8_t *data_ptr; + uint64_t *time_stamp; +}; + +typedef void (*bhy2_fifo_parse_callback_t)(const struct bhy2_fifo_parse_data_info *callback_info, void *private_data); + +struct BHY2_PACKED bhy2_fifo_parse_callback_table { + uint8_t sensor_id; + bhy2_fifo_parse_callback_t callback; + void *callback_ref; +}; + +/* Device structure */ +struct bhy2_dev { + struct bhy2_hif_dev hif; + struct bhy2_fifo_parse_callback_table table[BHY2_MAX_SIMUL_SENSORS]; + uint8_t event_size[BHY2_N_VIRTUAL_SENSOR_MAX]; + uint64_t last_time_stamp[BHY2_FIFO_TYPE_MAX]; + uint8_t present_buff[32]; +}; + +struct bhy2_fifo_buffer { + uint32_t read_pos; + uint32_t read_length; + uint32_t remain_length; + uint32_t buffer_size; + uint8_t *buffer; +}; + +typedef int16_t (*bhy2_frame_parse_func_t)(struct bhy2_fifo_buffer *p_fifo_buffer, struct bhy2_dev *bhy2_p); + +struct bhy2_virt_sensor_conf { + uint16_t sensitivity; + uint16_t range; + uint32_t latency; + bhy2_float sample_rate; +}; + +struct bhy2_data_xyz { + int16_t x; + int16_t y; + int16_t z; +}; + +struct bhy2_data_quaternion { + int16_t x; + int16_t y; + int16_t z; + int16_t w; + uint16_t accuracy; +}; + +struct bhy2_data_orientation { + int16_t heading; + int16_t pitch; + int16_t roll; +}; + +union BHY2_PACKED bhy2_spt_dev_id { + uint8_t slave_address; + uint8_t cs_pin; +}; + +struct BHY2_PACKED bhy2_spt_bits { + /*! byte 1 */ + uint8_t direction : 1; /**< 0: read; 1: write. */ + uint8_t trans_type : 1; /**< 0: single burst; 1:multi single transfers. */ + uint8_t delay_ctrl : 1; /**< 0: none; 1: delay between bytes. */ + uint8_t master_bus : 2; /**< 1: SIF1; 2: SIF2; 3:SIF3. */ + uint8_t spi_mode : 1; /**< 0: 4 wire; 1: 3 wire. */ + uint8_t cpol : 1; /**< spi clock polarity. */ + uint8_t cpha : 1; /**< spi clock phase. */ + /*! byte 2 */ + uint8_t delay_val : 6; /**< multiples of 50us. min is 200us (4LSB) */ + uint8_t cs_level : 1; /**< chip select level. */ + uint8_t lsb_first : 1; /**< least significant byte first. */ + /*! byte 3~4 */ + uint16_t trans_rate; /**< spi clock rate. */ + /*! byte 5 */ + uint8_t address_shift : 4; /**< number of bits to shift register address. */ + uint8_t read_bit_pol : 1; /**< 0: active low; 1: active high. */ + uint8_t read_bit_pos : 3; /**< bit number of read bit in command byte. */ + /*! byte 6 */ + union bhy2_spt_dev_id func_set; + + /*! byte 7 */ + uint8_t trans_count; + + /*! byte 8 */ + uint8_t reg; +}; + +union bhy2_soft_passthrough_conf { + struct bhy2_spt_bits conf; + uint8_t data[8]; +}; + +union bhy2_u16_conv { + uint16_t u16_val; + uint8_t bytes[2]; +}; +union bhy2_u32_conv { + uint32_t u32_val; + uint8_t bytes[4]; +}; +union bhy2_float_conv { + bhy2_float f_val; + uint32_t u32_val; + uint8_t bytes[4]; +}; +struct bhy2_sensor_info { + uint8_t sensor_type; + uint8_t driver_id; + uint8_t driver_version; + uint8_t power; + union bhy2_u16_conv max_range; + union bhy2_u16_conv resolution; + union bhy2_float_conv max_rate; + union bhy2_u32_conv fifo_reserved; + union bhy2_u32_conv fifo_max; + uint8_t event_size; + union bhy2_float_conv min_rate; +}; + +struct bhy2_phys_sensor_info { + uint8_t sensor_type; + uint8_t driver_id; + uint8_t driver_version; + uint8_t power_current; + union bhy2_u16_conv curr_range; + uint8_t flags; + uint8_t slave_address; + uint8_t gpio_assignment; + union bhy2_float_conv curr_rate; + uint8_t num_axis; + uint8_t orientation_matrix[5]; + uint8_t reserved; +}; + +struct bhy2_self_test_resp { + uint8_t test_status; + int16_t x_offset, y_offset, z_offset; +}; + +struct bhy2_foc_resp { + uint8_t foc_status; + int16_t x_offset, y_offset, z_offset; +}; + +struct bhy2_orient_matrix { + int8_t c[9]; +}; + +enum bhy2_data_inj_mode { + BHY2_NORMAL_MODE = 0, + BHY2_REAL_TIME_INJECTION = 1, + BHY2_STEP_BY_STEP_INJECTION = 2 +}; + +#define BHY2_BYTE_TO_NIBBLE(X) (((uint8_t)(X)[0] & 0x0F) | (((uint8_t)(X)[1] << 4) & 0xF0)) + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHY2_DEFS_H__ */ diff --git a/components/SensorLib/src/bosch/bhy2_head_tracker.c b/components/SensorLib/src/bosch/bhy2_head_tracker.c new file mode 100644 index 0000000..263cd19 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_head_tracker.c @@ -0,0 +1,353 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_head_tracker.c +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include + +/*********************************************************************/ +/* BHY2 SensorAPI header files */ +/*********************************************************************/ +#include "bhy2.h" + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "bhy2_head_tracker.h" + +/*Parsing callback for Head Orientation Quaternion*/ +void bhy2_head_tracker_quat_parsing(const uint8_t *payload, struct bhy2_head_tracker_quat_data *data) +{ + uint8_t i = 0; + + if ((payload != NULL) && (data != NULL)) + { + data->x = BHY2_LE2S16(&payload[i]); + i += 2; + data->y = BHY2_LE2S16(&payload[i]); + i += 2; + data->z = BHY2_LE2S16(&payload[i]); + i += 2; + data->w = BHY2_LE2S16(&payload[i]); + i += 2; + data->accuracy = payload[i]; + } +} + +/*Parsing callback for Head Orientation Euler*/ +void bhy2_head_tracker_eul_parsing(const uint8_t *payload, struct bhy2_head_tracker_eul_data *data) +{ + uint8_t i = 0; + + if ((payload != NULL) && (data != NULL)) + { + data->heading = BHY2_LE2S16(&payload[i]); + i += 2; + data->pitch = BHY2_LE2S16(&payload[i]); + i += 2; + data->roll = BHY2_LE2S16(&payload[i]); + i += 2; + data->accuracy = payload[i]; + } +} + +/*Callback for triggering Head Misalignment Calibration*/ +int8_t bhy2_head_tracker_trigger_hmc_calibration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Trigger Head Misalignment Calibration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_TRIGGER_CALIB), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for setting Head Misalignment Calibration Configuration*/ +int8_t bhy2_head_tracker_set_hmc_configuration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Misalignment Configuration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_CONFIG), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_CONFIG_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Misalignment Calibration Configuration*/ +int8_t bhy2_head_tracker_get_hmc_configuration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Misalignment Configuration */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_CONFIG), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_CONFIG_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting default Head Misalignment Calibration Configuration*/ +int8_t bhy2_head_tracker_set_default_hmc_configuration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set default Head Misalignment Configuration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Misalignment Calibrator Version*/ +int8_t bhy2_head_tracker_get_hmc_version(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Misalignment Calibrator Version */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_VERSION), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_VERSION_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting Head Misalignment Calibration Correction Quaternion Configuration*/ +int8_t bhy2_head_tracker_set_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Misalignment Calibration Correction Quaternion Configuration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_WLENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Misalignment Calibration Correction Quaternion Configuration*/ +int8_t bhy2_head_tracker_get_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Misalignment Calibration Correction Quaternion Configuration */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_RLENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting Head Orientation Initial Head Correction for Quaternion*/ +int8_t bhy2_head_tracker_set_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Orientation Initial Head Correction for Quaternion */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Orientation Initial Head Correction for Quaternion*/ +int8_t bhy2_head_tracker_get_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Orientation Initial Head Correction for Quaternion */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for getting Head Orientation Version*/ +int8_t bhy2_head_tracker_get_ho_version(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get IMU/NDOF Head Orientation Version */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_VERSION), + (uint8_t*)buffer, + BHY2_HEAD_ORI_VERSION_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting Head Orientation Initial Head Correction for Euler*/ +int8_t bhy2_head_tracker_set_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Orientation Initial Head Correction for Euler */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Orientation Initial Head Correction for Euler*/ +int8_t bhy2_head_tracker_get_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Orientation Initial Head Correction for Euler */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH, + &act_len, + dev); + } + + return rslt; +} diff --git a/components/SensorLib/src/bosch/bhy2_head_tracker.h b/components/SensorLib/src/bosch/bhy2_head_tracker.h new file mode 100644 index 0000000..94a5f31 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_head_tracker.h @@ -0,0 +1,213 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_head_tracker.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_HEAD_TRACKER_H_ +#define _BHY2_HEAD_TRACKER_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include +#include + +#include "bhy2.h" +#include "bhy2_head_tracker_defs.h" + +/*! + * @brief Parsing callback for Head Orientation Quaternion + * + * @param[in] payload + * @param[out] bhy2_head_tracker_quat_data to store Head Orientation [Quaternion] data + * + * @return API error codes + * + */ +void bhy2_head_tracker_quat_parsing(const uint8_t *payload, struct bhy2_head_tracker_quat_data *data); + +/*! + * @brief Parsing callback for Head Orientation Euler + * + * @param[in] payload + * @param[out] bhy2_head_tracker_eul_data to store Head Orientation [Euler] data + * + * @return API error codes + * + */ +void bhy2_head_tracker_eul_parsing(const uint8_t *payload, struct bhy2_head_tracker_eul_data *data); + +/*! + * @brief To trigger the Head Misalignment Calibration + * + * @param[in] buffer + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_trigger_hmc_calibration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Calibration Configuration + * + * @param[in] buffer to hold the Head Misalignment Calibration Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_hmc_configuration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Calibration Configuration + * + * @param[out] buffer to hold the Head Misalignment Calibration Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_hmc_configuration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the default Head Misalignment Calibration Configuration + * + * @param[in] command buffer + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_default_hmc_configuration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Calibrator Version + * + * @param[out] buffer to hold the Head Misalignment Calibrator Version + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_hmc_version(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Quaternion Calibration Correction Configuration + * + * @param[in] buffer to hold the Head Misalignment Quaternion Calibration Correction Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Quaternion Calibration Correction Configuration + * + * @param[out] buffer to hold the Head Misalignment Quaternion Calibration Correction Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Quaternion Initial Head Correction + * + * @param[in] buffer to hold the Head Misalignment Quaternion Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Quaternion Initial Head Correction + * + * @param[out] buffer to hold the Head Misalignment Quaternion Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the IMU/NDOF Head Orientation Version + * + * @param[out] buffer to hold the IMU/NDOF Head Orientation Version + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_ho_version(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Euler Initial Head Correction + * + * @param[in] buffer to hold the Head Misalignment Euler Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Euler Initial Head Correction + * + * @param[out] buffer to hold the Head Misalignment Euler Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_HEAD_TRACKER_H_ */ diff --git a/components/SensorLib/src/bosch/bhy2_head_tracker_defs.h b/components/SensorLib/src/bosch/bhy2_head_tracker_defs.h new file mode 100644 index 0000000..3c2c03a --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_head_tracker_defs.h @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_head_tracker_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_HEAD_TRACKER_DEFS_H_ +#define _BHY2_HEAD_TRACKER_DEFS_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include +#include + +#include "bhy2.h" + +/*! Virtual Sensor Macros */ +#define BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG UINT8_C(120) /*Head Orientation Misalignment*/ +#define BHY2_SENSOR_ID_IMU_HEAD_ORI_Q UINT8_C(121) /*IMU Head Orientation Quaternion*/ +#define BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q UINT8_C(122) /*NDOF Head Orientation Quaternion*/ +#define BHY2_SENSOR_ID_IMU_HEAD_ORI_E UINT8_C(123) /*IMU Head Orientation Euler*/ +#define BHY2_SENSOR_ID_NDOF_HEAD_ORI_E UINT8_C(124) /*NDOF Head Orientation Euler*/ + +#define BHY2_HEAD_ORI_PAGE UINT16_C(12) +#define BHY2_HEAD_ORI_PARAM(id) (((BHY2_HEAD_ORI_PAGE) << 8) | (id)) + +#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB UINT8_C(1) +#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_SET UINT8_C(1) + +#define BHY2_HEAD_ORI_HMC_CONFIG UINT8_C(2) +#define BHY2_HEAD_ORI_HMC_CONFIG_LENGTH UINT8_C(8) + +#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG UINT8_C(3) +#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_SET UINT8_C(1) + +#define BHY2_HEAD_ORI_HMC_VERSION UINT8_C(4) +#define BHY2_HEAD_ORI_HMC_VERSION_LENGTH UINT8_C(4) + +#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR UINT8_C(5) +#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_WLENGTH UINT8_C(16) +#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_RLENGTH UINT8_C(20) + +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR UINT8_C(10) +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_DISABLE UINT8_C(0) +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_ENABLE UINT8_C(1) + +#define BHY2_HEAD_ORI_VERSION UINT8_C(11) +#define BHY2_HEAD_ORI_VERSION_LENGTH UINT8_C(4) + +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR UINT8_C(12) +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_DISABLE UINT8_C(0) +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_ENABLE UINT8_C(1) + +/*! Sensor Structure for Head Orientation Quaternion */ +struct bhy2_head_tracker_quat_data +{ + int16_t x, y, z, w; + uint8_t accuracy; +}; + +/*! Sensor Structure for Head Orientation Euler */ +struct bhy2_head_tracker_eul_data +{ + int16_t heading, pitch, roll; + uint8_t accuracy; +}; + +/*! Structure for Head Misalignment Configuration */ +struct bhy2_head_tracker_misalignment_config +{ + uint8_t still_phase_max_dur; + uint8_t still_phase_min_dur; + uint8_t still_phase_max_samples; + int32_t acc_diff_threshold; +}; + +/*! Structure for Head Orientation /Head Misalignment version */ +struct bhy2_head_tracker_ver +{ + uint8_t major, minor, patch, reserved; +}; + +/*! Structure for Head Misalignment Quaternion Correction */ +struct bhy2_head_tracker_misalignment_quat_corr +{ + int32_t quaternion_x; + int32_t quaternion_y; + int32_t quaternion_z; + int32_t quaternion_w; + int32_t accuracy; +}; + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_HEAD_TRACKER_DEFS_H_ */ diff --git a/components/SensorLib/src/bosch/bhy2_hif.c b/components/SensorLib/src/bosch/bhy2_hif.c new file mode 100644 index 0000000..c243936 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_hif.c @@ -0,0 +1,1757 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bhy2_hif.c + * @date 2023-03-24 + * @version v1.6.0 + * + */ + +#include "bhy2_hif.h" + +/*! Mask definitions for SPI read/write address */ +#define BHY2_SPI_RD_MASK UINT8_C(0x80) +#define BHY2_SPI_WR_MASK UINT8_C(0x7F) + +union bhy2_hif_float_u32 +{ + bhy2_float as_float; + uint32_t reg; +}; + +static void bhy2_hif_exec_cmd_generic_support(const uint16_t *cmd, + uint8_t *cmd_buf, + uint32_t *temp_length, + uint32_t *total_length, + const uint32_t *len, + const uint32_t *pre_len, + const uint32_t *cmd_len) +{ + *total_length = *pre_len + *len; + + if (*cmd_len) + { + *temp_length = *pre_len + *cmd_len; + } + else + { + *temp_length = *total_length; + } + + /* Align 4 bytes */ + if (*temp_length % 4) + { + + *temp_length = BHY2_ROUND_WORD_HIGHER(*temp_length); + } + + cmd_buf[0] = (uint8_t)(*cmd & 0xFF); + cmd_buf[1] = (uint8_t)((*cmd >> 8) & 0xFF); + + /* Length in word */ + if (*cmd == BHY2_CMD_UPLOAD_TO_PROGRAM_RAM) + { + cmd_buf[2] = (*temp_length / 4) & 0xFF; + cmd_buf[3] = ((*temp_length / 4) >> 8) & 0xFF; + } + /* Length in byte */ + else + { + cmd_buf[2] = *temp_length & 0xFF; + cmd_buf[3] = (*temp_length >> 8) & 0xFF; + } +} + +/* + * If a command need several frames to upload to sensor, + * this command only be used in the first frame. + * + * |------------------------------------------------|---------------| + * |<-- frame one -->|<--frame two-->| + * |------------------------------------------------|---------------| + * | |<--pre_length-->|<--length-->| | + * |------------------|----------------|------------|---------------| + * | cmd | cmd_length | pre_payload | data 1 | data 2 | + * |-----------------------------------|------------|---------------| + * | payload | + * |------------|---------------| + * |<-- cmd_length -->| + * |----------------------------| + */ +static int8_t bhy2_hif_exec_cmd_generic(uint16_t cmd, + const uint8_t *payload, + uint32_t length, + const uint8_t *pre_payload, + uint32_t pre_length, + uint32_t cmd_length, + struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint32_t remain, trans_len, copy_len, pos, total_len, temp_total_len, loop_remain_len, max_len; + uint8_t command_buf[BHY2_COMMAND_PACKET_LEN]; + + if ((hif != NULL) && !((length != 0) && (payload == NULL)) && !((pre_length != 0) && (pre_payload == NULL))) + { + if (hif->read_write_len != 0) + { + bhy2_hif_exec_cmd_generic_support(&cmd, + command_buf, + &temp_total_len, + &total_len, + &length, + &pre_length, + &cmd_length); + pos = BHY2_COMMAND_HEADER_LEN; + remain = total_len; + loop_remain_len = remain + pos; + max_len = BHY2_COMMAND_PACKET_LEN - BHY2_COMMAND_HEADER_LEN; + + if (hif->read_write_len < max_len) + { + max_len = hif->read_write_len; + } + + while ((loop_remain_len > 0) && (rslt == BHY2_OK)) + { + if ((remain + pos) > max_len) + { + trans_len = max_len; + copy_len = max_len - pos; + } + else + { + trans_len = remain + pos; + copy_len = remain; + + /* Align to 4 bytes */ + if (trans_len % 4) + { + + trans_len = BHY2_ROUND_WORD_HIGHER(trans_len); + } + + if (trans_len > (BHY2_COMMAND_PACKET_LEN - BHY2_COMMAND_HEADER_LEN)) + { + trans_len = BHY2_COMMAND_PACKET_LEN - BHY2_COMMAND_HEADER_LEN; + } + } + + if (copy_len > 0) + { + if (remain >= (length + copy_len)) + { + memcpy(&command_buf[pos], &pre_payload[total_len - remain], copy_len); + } + else if (remain > length) + { + memcpy(&command_buf[pos], &pre_payload[total_len - remain], remain - length); + memcpy(&command_buf[pos + remain - length], payload, copy_len - (remain - length)); + } + else + { + memcpy(&command_buf[pos], &payload[length - remain], copy_len); + } + } + + if ((trans_len - (pos + copy_len)) > 0) + { + memset(&command_buf[pos + copy_len], 0, BHY2_COMMAND_PACKET_LEN - (pos + copy_len)); + } + + rslt = bhy2_hif_set_regs(BHY2_REG_CHAN_CMD, command_buf, trans_len, hif); + if (rslt != BHY2_OK) + { + break; + } + + pos = 0; + remain -= copy_len; + loop_remain_len = remain; + } + } + else + { + rslt = BHY2_E_INVALID_PARAM; + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_wait_status_ready(struct bhy2_hif_dev *hif) +{ + uint16_t retry; + uint8_t int_status; + int8_t rslt; + + /* Wait status ready */ + for (retry = 0; retry < BHY2_QUERY_PARAM_STATUS_READY_MAX_RETRY; ++retry) + { + rslt = bhy2_hif_get_interrupt_status(&int_status, hif); + if (rslt == BHY2_OK) + { + if (int_status & BHY2_IST_MASK_STATUS) + { + rslt = BHY2_OK; + break; + } + + /* 10ms */ + rslt = bhy2_hif_delay_us(10000, hif); + if (rslt != BHY2_OK) + { + return rslt; + } + } + else + { + return rslt; /*break; */ + } + } + + return rslt; +} + +static int8_t bhy2_hif_check_boot_status_ram(struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint16_t i; + uint8_t boot_status; + + /* total 5s */ + for (i = 0; i < BHY2_BST_CHECK_RETRY; ++i) + { + /* 50ms */ + rslt = bhy2_hif_delay_us(50000, hif); + if (rslt < 0) + { + return rslt; + } + + rslt = bhy2_hif_get_regs(BHY2_REG_BOOT_STATUS, &boot_status, sizeof(boot_status), hif); + if (rslt < 0) + { + return rslt; + } + + if ((boot_status & BHY2_BST_HOST_INTERFACE_READY) && (boot_status & BHY2_BST_HOST_FW_VERIFY_DONE) && + (!(boot_status & BHY2_BST_HOST_FW_VERIFY_ERROR))) + { + break; + } + } + + if (i == BHY2_BST_CHECK_RETRY) + { + return BHY2_E_TIMEOUT; + } + + return BHY2_OK; +} + +static int8_t bhy2_hif_check_boot_status_flash(struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint16_t i; + uint8_t boot_status; + + /* total 5s */ + for (i = 0; i < BHY2_BST_CHECK_RETRY; ++i) + { + /* 50ms */ + rslt = bhy2_hif_delay_us(50000, hif); + if (rslt < 0) + { + return rslt; + } + + rslt = bhy2_hif_get_regs(BHY2_REG_BOOT_STATUS, &boot_status, sizeof(boot_status), hif); + if (rslt < 0) + { + return rslt; + } + + if ((boot_status & BHY2_BST_HOST_INTERFACE_READY) && (boot_status & BHY2_BST_FLASH_VERIFY_DONE) && + (!(boot_status & BHY2_BST_FLASH_VERIFY_ERROR))) + { + break; + } + } + + if (i == BHY2_BST_CHECK_RETRY) + { + return BHY2_E_TIMEOUT; + } + + return BHY2_OK; +} + +static int8_t bhy2_hif_get_fifo(uint8_t reg, + uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint8_t n_bytes[2]; + uint32_t read_len; + uint32_t read_write_len; + uint32_t offset; + + if ((hif != NULL) && (fifo != NULL) && (bytes_read != NULL) && (bytes_remain != NULL)) + { + read_write_len = hif->read_write_len; + + if (*bytes_remain == 0) + { + rslt = bhy2_hif_get_regs(reg, n_bytes, 2, hif); /* Read the the available size */ + *bytes_remain = BHY2_LE2U16(n_bytes); + } + + if ((*bytes_remain != 0) && (rslt == BHY2_OK)) + { + if (fifo_len < *bytes_remain) + { + *bytes_read = fifo_len; + } + else + { + *bytes_read = *bytes_remain; + } + + read_len = *bytes_read; + offset = 0; + while (read_len > read_write_len) + { + rslt = bhy2_hif_get_regs(reg, &fifo[offset], read_write_len, hif); + if (rslt != BHY2_OK) + { + break; + } + + read_len -= read_write_len; + offset += read_write_len; + } + + if (read_len != 0) + { + rslt = bhy2_hif_get_regs(reg, &fifo[offset], read_len, hif); + } + + *bytes_remain -= *bytes_read; + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_init(enum bhy2_intf intf, + bhy2_read_fptr_t read, + bhy2_write_fptr_t write, + bhy2_delay_us_fptr_t delay_us, + uint32_t read_write_len, + void *intf_ptr, + struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + + if ((hif != NULL) && (read != NULL) && (write != NULL) && (delay_us != NULL)) + { + hif->read = read; + hif->write = write; + hif->delay_us = delay_us; + hif->intf_ptr = intf_ptr; + hif->intf = intf; + if (read_write_len % 4) + { + + hif->read_write_len = BHY2_ROUND_WORD_LOWER(read_write_len); + } + else + { + hif->read_write_len = read_write_len; + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + + if ((hif != NULL) && (hif->read != NULL) && (reg_data != NULL)) + { + if (hif->intf == BHY2_SPI_INTERFACE) + { + reg_addr |= BHY2_SPI_RD_MASK; + } + + hif->intf_rslt = hif->read(reg_addr, reg_data, length, hif->intf_ptr); + if (hif->intf_rslt != BHY2_INTF_RET_SUCCESS) + { + rslt = BHY2_E_IO; + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + + if ((hif != NULL) && (hif->write != NULL) && (reg_data != NULL)) + { + if (hif->intf == BHY2_SPI_INTERFACE) + { + reg_addr &= BHY2_SPI_WR_MASK; + } + + hif->intf_rslt = hif->write(reg_addr, reg_data, length, hif->intf_ptr); + if (hif->intf_rslt != BHY2_INTF_RET_SUCCESS) + { + rslt = BHY2_E_IO; + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_delay_us(uint32_t period_us, const struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + + if ((hif != NULL) && (hif->delay_us != NULL)) + { + hif->delay_us(period_us, hif->intf_ptr); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_exec_cmd(uint16_t cmd, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_exec_cmd_generic(cmd, payload, length, NULL, 0, 0, hif); +} + +int8_t bhy2_hif_get_parameter(uint16_t param, + uint8_t *payload, + uint32_t payload_len, + uint32_t *actual_len, + struct bhy2_hif_dev *hif) +{ + uint16_t code = 0; + uint8_t prev_hif_ctrl, hif_ctrl; + int8_t rslt = BHY2_OK; + + if ((hif != NULL) && (payload != NULL) && (actual_len != NULL)) + { + *actual_len = 0; + + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &hif_ctrl, 1, hif); + if (rslt == BHY2_OK) + { + prev_hif_ctrl = hif_ctrl; + hif_ctrl &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); /* Change the Status FIFO to synchronous mode + * */ + if (hif_ctrl != prev_hif_ctrl) + { + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &hif_ctrl, 1, hif); + } + + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_exec_cmd(param | BHY2_PARAM_READ_MASK, NULL, 0, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_status_fifo(&code, payload, payload_len, actual_len, hif); + + if (rslt == BHY2_OK) + { + + if (hif_ctrl != prev_hif_ctrl) + { + hif_ctrl = prev_hif_ctrl; + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &hif_ctrl, 1, hif); + } + + if (rslt == BHY2_OK) + { + if (code != param) + { + rslt = BHY2_E_TIMEOUT; + } + } + } + } + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_exec_cmd(param, payload, length, hif); +} + +int8_t bhy2_hif_get_product_id(uint8_t *product_id, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_PRODUCT_ID, product_id, 1, hif); +} + +int8_t bhy2_hif_get_chip_id(uint8_t *chip_id, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_CHIP_ID, chip_id, 1, hif); +} + +int8_t bhy2_hif_get_rom_version(uint16_t *rom_version, struct bhy2_hif_dev *hif) +{ + uint8_t buffer[2]; + int8_t rslt; + + if (rom_version != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_ROM_VERSION_0, buffer, 2, hif); + *rom_version = BHY2_LE2U16(buffer); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_kernel_version(uint16_t *kernel_version, struct bhy2_hif_dev *hif) +{ + uint8_t buffer[2]; + int8_t rslt; + + if (kernel_version != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_KERNEL_VERSION_0, buffer, 2, hif); + *kernel_version = BHY2_LE2U16(buffer); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_user_version(uint16_t *user_version, struct bhy2_hif_dev *hif) +{ + uint8_t buffer[2]; + int8_t rslt; + + if (user_version != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_USER_VERSION_0, buffer, 2, hif); + *user_version = BHY2_LE2U16(buffer); + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_boot_status(uint8_t *boot_status, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_BOOT_STATUS, boot_status, 1, hif); +} + +int8_t bhy2_hif_get_host_status(uint8_t *host_status, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_HOST_STATUS, host_status, 1, hif); +} + +int8_t bhy2_hif_get_feature_status(uint8_t *feat_status, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_FEATURE_STATUS, feat_status, 1, hif); +} + +int8_t bhy2_hif_get_interrupt_status(uint8_t *int_status, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_INT_STATUS, int_status, 1, hif); +} + +int8_t bhy2_hif_get_fw_error(uint8_t *fw_error, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_regs(BHY2_REG_ERROR_VALUE, fw_error, 1, hif); +} + +int8_t bhy2_hif_reset(struct bhy2_hif_dev *hif) +{ + uint8_t reset_req = BHY2_REQUEST_RESET; + uint8_t boot_status = 0; + int8_t rslt; + + /* Timeout at 150ms (15 * 10000 microseconds) */ + uint16_t count = 15; + + rslt = bhy2_hif_set_regs(BHY2_REG_RESET_REQ, &reset_req, 1, hif); + if (rslt == BHY2_OK) + { + while (count--) + { + rslt = bhy2_hif_delay_us(10000, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_regs(BHY2_REG_BOOT_STATUS, &boot_status, 1, hif); + if (rslt == BHY2_OK) + { + if (boot_status & BHY2_BST_HOST_INTERFACE_READY) + { + break; + } + } + } + } + + if (!(boot_status & BHY2_BST_HOST_INTERFACE_READY)) + { + rslt = BHY2_E_TIMEOUT; + } + } + + return rslt; +} + +int8_t bhy2_hif_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint16_t magic; + + if ((hif != NULL) && (firmware != NULL)) + { + magic = BHY2_LE2U16(firmware); + if (magic != BHY2_FW_MAGIC) + { + rslt = BHY2_E_MAGIC; + } + else + { + rslt = bhy2_hif_exec_cmd(BHY2_CMD_UPLOAD_TO_PROGRAM_RAM, firmware, length, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_check_boot_status_ram(hif); + + } + + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_upload_firmware_to_ram_partly(const uint8_t *firmware, + uint32_t total_size, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint16_t magic; + + if ((hif != NULL) && (firmware != NULL)) + { + if (cur_pos == 0) + { + magic = BHY2_LE2U16(firmware); + if (magic != BHY2_FW_MAGIC) + { + rslt = BHY2_E_MAGIC; + } + + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_exec_cmd_generic(BHY2_CMD_UPLOAD_TO_PROGRAM_RAM, + firmware, + packet_len, + NULL, + 0, + total_size, + hif); + } + } + else + { + rslt = bhy2_hif_set_regs(BHY2_REG_CHAN_CMD, firmware, packet_len, hif); + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_boot_program_ram(struct bhy2_hif_dev *hif) +{ + int8_t rslt; + + rslt = bhy2_hif_exec_cmd(BHY2_CMD_BOOT_PROGRAM_RAM, NULL, 0, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_check_boot_status_ram(hif); + } + + return rslt; +} + +int8_t bhy2_hif_get_wakeup_fifo(uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_fifo(BHY2_REG_CHAN_FIFO_W, fifo, fifo_len, bytes_read, bytes_remain, hif); +} + +int8_t bhy2_hif_get_nonwakeup_fifo(uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_fifo(BHY2_REG_CHAN_FIFO_NW, fifo, fifo_len, bytes_read, bytes_remain, hif); +} + +int8_t bhy2_hif_get_status_fifo(uint16_t *status_code, + uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint8_t tmp_fifo[4]; + + rslt = bhy2_hif_get_regs(BHY2_REG_CHAN_STATUS, tmp_fifo, 4, hif); + if (rslt == BHY2_OK) + { + *status_code = BHY2_LE2U16(&tmp_fifo[0]); + *bytes_remain = BHY2_LE2U16(&tmp_fifo[2]); + + if (*bytes_remain != 0) + { + if (fifo_len < *bytes_remain) + { + rslt = BHY2_E_BUFFER; + } + else + { + rslt = bhy2_hif_get_regs(BHY2_REG_CHAN_STATUS, fifo, *bytes_remain, hif); + } + } + } + + return rslt; +} + +int8_t bhy2_hif_get_status_fifo_async(uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif) +{ + return bhy2_hif_get_fifo(BHY2_REG_CHAN_STATUS, fifo, fifo_len, bytes_read, bytes_remain, hif); +} + +int8_t bhy2_hif_exec_sensor_conf_cmd(uint8_t sensor_id, + bhy2_float sample_rate, + uint32_t latency, + struct bhy2_hif_dev *hif) +{ + uint8_t tmp_buf[8]; + union bhy2_hif_float_u32 sample_rate_u; + + sample_rate_u.as_float = sample_rate; + + /* Sample rate is 32bits, latency is 24bits */ + tmp_buf[0] = sensor_id; + tmp_buf[1] = (uint8_t)(sample_rate_u.reg & 0xFF); + tmp_buf[2] = (uint8_t)((sample_rate_u.reg >> 8) & 0xFF); + tmp_buf[3] = (uint8_t)((sample_rate_u.reg >> 16) & 0xFF); + tmp_buf[4] = (uint8_t)((sample_rate_u.reg >> 24) & 0xFF); + tmp_buf[5] = (uint8_t)(latency & 0xFF); + tmp_buf[6] = (uint8_t)((latency >> 8) & 0xFF); + tmp_buf[7] = (uint8_t)((latency >> 16) & 0xFF); + + return bhy2_hif_exec_cmd(BHY2_CMD_CONFIG_SENSOR, tmp_buf, 8, hif); +} + +int8_t bhy2_hif_set_fifo_flush(uint8_t sensor_id, struct bhy2_hif_dev *hif) +{ + uint8_t tmp_buf[4] = {sensor_id, 0, 0, 0}; + + return bhy2_hif_exec_cmd(BHY2_CMD_FIFO_FLUSH, tmp_buf, 4, hif); +} + +int8_t bhy2_hif_exec_soft_passthrough(const uint8_t *payload, + uint32_t payload_len, + uint8_t *reg_data, + uint32_t length, + uint32_t *actual_len, + struct bhy2_hif_dev *hif) +{ + uint16_t code = 0; + uint8_t old_status, tmp_buf; + int8_t rslt; + + /* Enter synchronous mode */ + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + old_status = tmp_buf; + tmp_buf &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + /* Execute the Software passthrough */ + rslt = bhy2_hif_exec_cmd(BHY2_CMD_SW_PASSTHROUGH, payload, payload_len, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + /* Read back the response */ + rslt = bhy2_hif_get_status_fifo(&code, reg_data, length, actual_len, hif); + if (rslt == BHY2_OK) + { + /* Set back to previous mode */ + tmp_buf = old_status; + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + if (code != BHY2_STATUS_SW_PASS_THRU_RES) + { + rslt = BHY2_E_TIMEOUT; + } + } + } + } + } + } + } + + return rslt; +} + +int8_t bhy2_hif_get_post_mortem(uint16_t *code, + uint32_t *actual_len, + uint8_t *post_mortem, + uint32_t buffer_len, + struct bhy2_hif_dev *hif) +{ + uint8_t old_status, tmp_buf; + int8_t rslt; + + if (code != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + old_status = tmp_buf; + tmp_buf &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_exec_cmd(BHY2_CMD_REQ_POST_MORTEM_DATA, NULL, 0, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_status_fifo(code, post_mortem, buffer_len, actual_len, hif); + if (rslt == BHY2_OK) + { + tmp_buf = old_status; + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + if (*code != BHY2_STATUS_CRASH_DUMP) + { + rslt = BHY2_E_TIMEOUT; + } + } + } + } + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_do_self_test(uint8_t phys_sensor_id, + struct bhy2_self_test_resp *self_test_resp, + struct bhy2_hif_dev *hif) +{ + uint16_t code = 0; + uint8_t old_status, tmp_buf, req[4], ret_data[16]; + uint32_t ret_len = 0; + int8_t rslt; + + if (self_test_resp != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + old_status = tmp_buf; + tmp_buf &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + req[0] = phys_sensor_id; + req[1] = req[2] = req[3] = 0; + rslt = bhy2_hif_exec_cmd(BHY2_CMD_REQ_SELF_TEST, req, 4, hif); + if (rslt == BHY2_OK) + { + /* wait status ready */ + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_status_fifo(&code, ret_data, 16, &ret_len, hif); + if (rslt == BHY2_OK) + { + tmp_buf = old_status; + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + if (code != BHY2_STATUS_SELF_TEST_RES) + { + rslt = BHY2_E_TIMEOUT; + } + else + { + if (ret_data[0] != phys_sensor_id) + { + rslt = BHY2_E_INVALID_PARAM; + } + else + { + self_test_resp->test_status = ret_data[1]; + self_test_resp->x_offset = BHY2_LE2S16(&ret_data[2]); + self_test_resp->y_offset = BHY2_LE2S16(&ret_data[4]); + self_test_resp->z_offset = BHY2_LE2S16(&ret_data[6]); + } + } + } + } + } + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_do_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_hif_dev *hif) +{ + uint16_t code = 0; + uint8_t old_status, tmp_buf, req[4], ret_data[16]; + uint32_t ret_len = 0; + int8_t rslt; + + if (foc_resp != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + old_status = tmp_buf; + tmp_buf &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + req[0] = phys_sensor_id; + req[1] = req[2] = req[3] = 0; + rslt = bhy2_hif_exec_cmd(BHY2_CMD_REQ_FOC, req, 4, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_status_fifo(&code, ret_data, 16, &ret_len, hif); + if (rslt == BHY2_OK) + { + tmp_buf = old_status; + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + if (code != BHY2_STATUS_FOC_RES) + { + rslt = BHY2_E_TIMEOUT; + } + else + { + if (ret_data[0] != phys_sensor_id) + { + rslt = BHY2_E_INVALID_PARAM; + } + else + { + foc_resp->foc_status = ret_data[1]; + foc_resp->x_offset = BHY2_LE2S16(&ret_data[2]); + foc_resp->y_offset = BHY2_LE2S16(&ret_data[4]); + foc_resp->z_offset = BHY2_LE2S16(&ret_data[6]); + } + } + } + } + } + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_sensor_ctrl(uint8_t sensor_id, + uint8_t ctrl_code, + uint8_t *payload, + uint32_t payload_len, + uint32_t *actual_len, + struct bhy2_hif_dev *hif) +{ + uint16_t code = 0; + uint8_t old_status; + uint8_t tmp_buf[4] = {0}; + uint8_t buf = 0; + uint32_t length; + uint16_t param_num; + int8_t rslt; + + if ((payload != NULL) && (actual_len != NULL)) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &buf, 1, hif); + if (rslt == BHY2_OK) + { + old_status = buf; + buf &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &buf, 1, hif); + if (rslt == BHY2_OK) + { + /* Set the parameter to request data */ + param_num = (uint16_t)(BHY2_PARAM_SET_SENSOR_CTRL | sensor_id); + tmp_buf[0] = ctrl_code | BHY2_PARAM_SENSOR_CTRL_READ; + length = 4; + rslt = bhy2_hif_set_parameter(param_num, tmp_buf, length, hif); + if (rslt == BHY2_OK) + { + /* Get parameter to read data */ + param_num = (uint16_t)(BHY2_PARAM_GET_SENSOR_CTRL | sensor_id); + length = 0; + rslt = bhy2_hif_set_parameter(param_num, NULL, length, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_status_fifo(&code, payload, payload_len, actual_len, hif); + if (rslt == BHY2_OK) + { + buf = old_status; + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &buf, 1, hif); + if (rslt == BHY2_OK) + { + if (code != (BHY2_PARAM_SET_SENSOR_CTRL | sensor_id)) + { + rslt = BHY2_E_INVALID_PARAM; + } + else if (payload[0] != ctrl_code) + { + rslt = BHY2_E_INVALID_PARAM; + } + } + } + } + } + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_set_sensor_ctrl(uint8_t sensor_id, + uint8_t ctrl_code, + const uint8_t *payload, + uint32_t payload_len, + struct bhy2_hif_dev *hif) +{ + uint16_t param_num; + uint8_t command; + + /* Set parameter to send data */ + param_num = (uint16_t)(BHY2_PARAM_SET_SENSOR_CTRL | sensor_id); + command = (uint8_t)(ctrl_code & (~BHY2_PARAM_SENSOR_CTRL_READ)); + + return bhy2_hif_exec_cmd_generic(param_num, payload, payload_len, &command, 1, 0, hif); +} + +int8_t bhy2_hif_get_bsx_state(uint16_t param_id, + uint8_t *bsx_state, + uint32_t state_len, + uint32_t *actual_len, + struct bhy2_hif_dev *hif) +{ + uint8_t complete_flag = 0; + uint16_t tmp_state_len = 0; + uint8_t block_len = 0; + uint32_t read_len; + int8_t rslt; + uint8_t tmp_bsx_state_buf[BHY2_BSX_STATE_STRUCT_LEN]; + uint16_t state_index = 0; + + while (complete_flag == 0) + { + rslt = bhy2_hif_get_parameter(param_id, tmp_bsx_state_buf, BHY2_BSX_STATE_STRUCT_LEN, &read_len, hif); + if (rslt != BHY2_OK) + { + break; + } + + if (read_len > BHY2_BSX_STATE_STRUCT_LEN) + { + rslt = BHY2_E_INVALID_PARAM - 50; + break; + } + + complete_flag = tmp_bsx_state_buf[0] & BHY2_BSX_STATE_TRANSFER_COMPLETE; + block_len = tmp_bsx_state_buf[1]; + tmp_state_len = BHY2_LE2U16(&tmp_bsx_state_buf[2]); + if (tmp_state_len == 0) + { + rslt = BHY2_E_INVALID_PARAM - 70; + break; + } + + *actual_len = tmp_state_len; /* Report actual length, in case of invalid buffer */ + + if (state_len < tmp_state_len) + { + rslt = BHY2_E_BUFFER; + break; + } + + memcpy(&bsx_state[state_index], &tmp_bsx_state_buf[4], tmp_bsx_state_buf[1]); + state_index += block_len; + } + + return rslt; +} + +int8_t bhy2_hif_set_bsx_state(uint16_t param_id, const uint8_t *bsx_state, uint32_t state_len, struct bhy2_hif_dev *hif) +{ + uint32_t pos; + uint16_t num = 0; + int8_t rslt = BHY2_OK; + uint8_t tmp_bsx_state_buf[BHY2_BSX_STATE_STRUCT_LEN]; + uint32_t state_buf_size; + + for (pos = 0; pos < state_len; pos += BHY2_BSX_STATE_BLOCK_LEN, num++) + { + tmp_bsx_state_buf[0] = num & 0x7F; + state_buf_size = state_len - pos; + if (state_buf_size <= BHY2_BSX_STATE_BLOCK_LEN) + { + tmp_bsx_state_buf[0] |= 0x80; + tmp_bsx_state_buf[1] = (uint8_t)state_buf_size; + } + else + { + tmp_bsx_state_buf[1] = BHY2_BSX_STATE_BLOCK_LEN; + } + + tmp_bsx_state_buf[2] = state_len & 0xFF; + tmp_bsx_state_buf[3] = (state_len >> 8) & 0xFF; + memcpy(&tmp_bsx_state_buf[4], &bsx_state[pos], tmp_bsx_state_buf[1]); + rslt = bhy2_hif_set_parameter(param_id, tmp_bsx_state_buf, BHY2_BSX_STATE_STRUCT_LEN, hif); + if (rslt != BHY2_OK) + { + break; + } + } + + return rslt; +} + +int8_t bhy2_hif_erase_flash(uint32_t start_addr, uint32_t end_addr, struct bhy2_hif_dev *hif) +{ + uint8_t buf[8]; + uint8_t int_status = 0; + uint16_t retry; + + /* Variable to get the response code */ + uint16_t code = 0; + int8_t rslt = BHY2_OK; + uint32_t ret_len; + + /* Check for invalid end address */ + if ((end_addr < start_addr) && (start_addr != BHY2_FLASH_BULK_ERASE)) + { + rslt = BHY2_E_INVALID_PARAM; + } + else + { + /* Set start address */ + buf[0] = (uint8_t)(start_addr & 0xFF); + buf[1] = (uint8_t)((start_addr >> 8) & 0xFF); + buf[2] = (uint8_t)((start_addr >> 16) & 0xFF); + buf[3] = (uint8_t)((start_addr >> 24) & 0xFF); + + /* Set the end address */ + buf[4] = (uint8_t)(end_addr & 0xFF); + buf[5] = (uint8_t)((end_addr >> 8) & 0xFF); + buf[6] = (uint8_t)((end_addr >> 16) & 0xFF); + buf[7] = (uint8_t)((end_addr >> 24) & 0xFF); + + /* Erase flash */ + rslt = bhy2_hif_exec_cmd(BHY2_CMD_ERASE_FLASH, buf, 8, hif); + if (rslt == BHY2_OK) + { + /* Check status and wait for at least 0.5 seconds for the erase to complete + * and time out provided for 10 Mins (1200 * 0.5 Seconds = 10 Min) */ + for (retry = 0; retry < BHY2_QUERY_FLASH_MAX_RETRY; retry++) + { + rslt = bhy2_hif_get_interrupt_status(&int_status, hif); + if (rslt != BHY2_OK) + { + break; + } + + if (int_status & BHY2_IST_MASK_STATUS) + { + break; + } + + rslt = bhy2_hif_delay_us(500000, hif); + if (rslt != BHY2_OK) + { + break; + } + } + + if (rslt == BHY2_OK) + { + /* Read status */ + rslt = bhy2_hif_get_status_fifo(&code, NULL, 0, &ret_len, hif); + if (rslt == BHY2_OK) + { + /* Status code */ + if (code != BHY2_STATUS_FLASH_ERASE_COMPLETE) + { + rslt = BHY2_E_TIMEOUT; + } + } + } + } + } + + return rslt; +} + +int8_t bhy2_hif_upload_to_flash(const uint8_t *firmware, + uint32_t length, + uint8_t *work_buffer, + uint32_t work_buf_len, + uint32_t *exp_size, + struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint16_t magic; + uint32_t sector_addr = BHY2_FLASH_SECTOR_START_ADDR; + uint8_t addr_buf[4]; + uint32_t remain, trans_len, pos; + uint16_t code; + + if ((hif != NULL) && (firmware != NULL) && (work_buffer != NULL)) + { + magic = BHY2_LE2U16(firmware); + if (magic != BHY2_FW_MAGIC) + { + rslt = BHY2_E_MAGIC; + } + else + { + pos = 0; + remain = length; + if (hif->read_write_len % 4) + { + + hif->read_write_len = BHY2_ROUND_WORD_LOWER(hif->read_write_len); + } + + while (remain > 0) + { + if (remain > hif->read_write_len) + { + trans_len = hif->read_write_len; + } + else + { + trans_len = remain; + } + + /* Set the sector address */ + addr_buf[0] = (uint8_t)(sector_addr & 0xFF); + addr_buf[1] = (uint8_t)((sector_addr >> 8) & 0xFF); + addr_buf[2] = (uint8_t)((sector_addr >> 16) & 0xFF); + addr_buf[3] = (uint8_t)((sector_addr >> 24) & 0xFF); + + /* Transfer firmware to the flash */ + rslt = bhy2_hif_exec_cmd_generic(BHY2_CMD_WRITE_FLASH, &firmware[pos], trans_len, addr_buf, 4, 0, hif); + if (rslt != BHY2_OK) + { + break; + } + + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt != BHY2_OK) + { + break; + } + + rslt = bhy2_hif_get_status_fifo(&code, work_buffer, work_buf_len, exp_size, hif); + if (rslt != BHY2_OK) + { + break; + } + + /* Status code */ + if (code != BHY2_STATUS_FLASH_WRITE_COMPLETE) + { + rslt = BHY2_E_TIMEOUT; + break; + } + + pos += trans_len; + remain -= trans_len; + sector_addr += hif->read_write_len; + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_upload_to_flash_partly(const uint8_t *firmware, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint16_t magic; + uint32_t sector_addr = BHY2_FLASH_SECTOR_START_ADDR + cur_pos; + uint8_t addr_buf[4]; + uint16_t code; + uint8_t work_buffer[32]; + uint32_t exp_size, work_buf_len = 32; + + if ((hif != NULL) && (firmware != NULL)) + { + if (cur_pos == 0) + { + magic = BHY2_LE2U16(firmware); + if (magic != BHY2_FW_MAGIC) + { + rslt = BHY2_E_MAGIC; + } + } + + if (rslt == BHY2_OK) + { + /* Set the sector address */ + addr_buf[0] = (uint8_t)(sector_addr & 0xFF); + addr_buf[1] = (uint8_t)((sector_addr >> 8) & 0xFF); + addr_buf[2] = (uint8_t)((sector_addr >> 16) & 0xFF); + addr_buf[3] = (uint8_t)((sector_addr >> 24) & 0xFF); + + /* Transfer firmware to the flash */ + rslt = bhy2_hif_exec_cmd_generic(BHY2_CMD_WRITE_FLASH, firmware, packet_len, addr_buf, 4, 0, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_wait_status_ready(hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_get_status_fifo(&code, work_buffer, work_buf_len, &exp_size, hif); + if (rslt == BHY2_OK) + { + if (code != BHY2_STATUS_FLASH_WRITE_COMPLETE) + { + rslt = BHY2_E_TIMEOUT; + } + } + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_boot_from_flash(struct bhy2_hif_dev *hif) +{ + int8_t rslt; + + rslt = bhy2_hif_exec_cmd(BHY2_CMD_BOOT_FLASH, NULL, 0, hif); + if (rslt == BHY2_OK) + { + rslt = bhy2_hif_check_boot_status_flash(hif); + } + + return rslt; +} + +int8_t bhy2_hif_request_hw_timestamp(struct bhy2_hif_dev *hif) +{ + uint8_t time_ev_req = 1; + + return bhy2_hif_set_regs(BHY2_REG_TIME_EV_REQ, &time_ev_req, 1, hif); +} + +int8_t bhy2_hif_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif) +{ + int8_t rslt = BHY2_OK; + uint8_t ts_regs[5]; + + if (ts_ticks != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTR_TIME_0, ts_regs, 5, hif); + if (rslt == BHY2_OK) + { + *ts_ticks = BHY2_LE2U40(ts_regs); + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_req_and_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint8_t retry; + uint8_t tmp_buf[5]; + uint64_t ts_old; + + if (ts_ticks != NULL) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTR_TIME_0, tmp_buf, 5, hif); + if (rslt == BHY2_OK) + { + ts_old = BHY2_LE2U40(tmp_buf); + tmp_buf[0] = 1; + rslt = bhy2_hif_set_regs(BHY2_REG_TIME_EV_REQ, tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + for (retry = 0; retry < 5; retry++) + { + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTR_TIME_0, tmp_buf, 5, hif); + if (rslt == BHY2_OK) + { + *ts_ticks = BHY2_LE2U40(tmp_buf); + if (*ts_ticks != ts_old) + { + break; + } + + rslt = bhy2_hif_delay_us(10, hif); + if (rslt != BHY2_OK) + { + break; + } + } + } + + if ((retry >= 5) && (*ts_ticks == ts_old)) + { + rslt = BHY2_E_TIMEOUT; + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint32_t length; + uint8_t bytes[28]; + + if (info != NULL) + { + /* Checking for a valid sensor ID */ + if (sensor_id > BHY2_SPECIAL_SENSOR_ID_OFFSET) + { + rslt = BHY2_E_INVALID_PARAM; + } + else + { + rslt = bhy2_hif_get_parameter((uint16_t)(BHY2_PARAM_SENSOR_INFO_0 + sensor_id), bytes, 28, &length, hif); + if (rslt == BHY2_OK) + { + if (length != 28) + { + rslt = BHY2_E_INVALID_PARAM; + } + else + { + info->sensor_type = bytes[0]; + info->driver_id = bytes[1]; + info->driver_version = bytes[2]; + info->power = bytes[3]; + info->max_range.bytes[0] = bytes[4]; + info->max_range.bytes[1] = bytes[5]; + info->resolution.bytes[0] = bytes[6]; + info->resolution.bytes[1] = bytes[7]; + info->max_rate.bytes[0] = bytes[8]; + info->max_rate.bytes[1] = bytes[9]; + info->max_rate.bytes[2] = bytes[10]; + info->max_rate.bytes[3] = bytes[11]; + info->fifo_reserved.bytes[0] = bytes[12]; + info->fifo_reserved.bytes[1] = bytes[13]; + info->fifo_reserved.bytes[2] = bytes[14]; + info->fifo_reserved.bytes[3] = bytes[15]; + info->fifo_max.bytes[0] = bytes[16]; + info->fifo_max.bytes[1] = bytes[17]; + info->fifo_max.bytes[2] = bytes[18]; + info->fifo_max.bytes[3] = bytes[19]; + info->event_size = bytes[20]; + info->min_rate.bytes[0] = bytes[21]; + info->min_rate.bytes[1] = bytes[22]; + info->min_rate.bytes[2] = bytes[23]; + info->min_rate.bytes[3] = bytes[24]; + info->max_range.u16_val = BHY2_LE2U16(info->max_range.bytes); + info->resolution.u16_val = BHY2_LE2U16(info->resolution.bytes); + info->max_rate.u32_val = BHY2_LE2U32(info->max_rate.bytes); + info->fifo_reserved.u32_val = BHY2_LE2U32(info->fifo_reserved.bytes); + info->fifo_max.u32_val = BHY2_LE2U32(info->fifo_max.bytes); + info->min_rate.u32_val = BHY2_LE2U32(info->min_rate.bytes); + } + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_get_phys_sensor_info(uint8_t sensor_id, struct bhy2_phys_sensor_info *info, struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint32_t length; + uint8_t bytes[20]; + + if (info != NULL) + { + rslt = bhy2_hif_get_parameter((uint16_t)(BHY2_PARAM_PHYSICAL_SENSOR_BASE + sensor_id), bytes, 20, &length, hif); + if (rslt == BHY2_OK) + { + if (length != 20) + { + rslt = BHY2_E_INVALID_PARAM; + } + else + { + info->sensor_type = bytes[0]; + info->driver_id = bytes[1]; + info->driver_version = bytes[2]; + info->power_current = bytes[3]; + info->curr_range.bytes[0] = bytes[4]; + info->curr_range.bytes[1] = bytes[5]; + info->flags = bytes[6]; + info->slave_address = bytes[7]; + info->gpio_assignment = bytes[8]; + info->curr_rate.bytes[0] = bytes[9]; + info->curr_rate.bytes[1] = bytes[10]; + info->curr_rate.bytes[2] = bytes[11]; + info->curr_rate.bytes[3] = bytes[12]; + info->num_axis = bytes[13]; + info->orientation_matrix[0] = bytes[14]; + info->orientation_matrix[1] = bytes[15]; + info->orientation_matrix[2] = bytes[16]; + info->orientation_matrix[3] = bytes[17]; + info->orientation_matrix[4] = bytes[18]; + + info->curr_range.u16_val = BHY2_LE2U16(info->curr_range.bytes); + info->curr_rate.u32_val = BHY2_LE2U32(info->curr_rate.bytes); + } + } + } + else + { + rslt = BHY2_E_NULL_PTR; + } + + return rslt; +} + +int8_t bhy2_hif_set_orientation_matrix(uint8_t sensor_id, + struct bhy2_orient_matrix orient_matrix, + struct bhy2_hif_dev *hif) +{ + int8_t rslt; + uint8_t tmp_matrix_buf[8]; /* Includes 2 reserved bytes */ + + memset(tmp_matrix_buf, 0, sizeof(tmp_matrix_buf)); + + tmp_matrix_buf[0] = BHY2_BYTE_TO_NIBBLE(&orient_matrix.c[0]); + tmp_matrix_buf[1] = BHY2_BYTE_TO_NIBBLE(&orient_matrix.c[2]); + tmp_matrix_buf[2] = BHY2_BYTE_TO_NIBBLE(&orient_matrix.c[4]); + tmp_matrix_buf[3] = BHY2_BYTE_TO_NIBBLE(&orient_matrix.c[6]); + tmp_matrix_buf[4] = orient_matrix.c[8] & 0x0F; + + rslt = bhy2_hif_set_parameter((uint16_t)(BHY2_PARAM_PHYSICAL_SENSOR_BASE + sensor_id), tmp_matrix_buf, 8, hif); + + return rslt; +} + +/*lint -e{715} suppressed parameters not referenced info as all the calling functions are parsing the valid values to + * all parameters*/ +int8_t bhy2_hif_set_inject_data_mode(const uint8_t *payload, + uint8_t payload_len, + const uint8_t *work_buf, + uint32_t work_buf_len, + const uint32_t *actual_len, + struct bhy2_hif_dev *hif) +{ + uint8_t tmp_buf; + int8_t rslt; + + rslt = bhy2_hif_get_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + tmp_buf &= (uint8_t)(~(BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL)); + rslt = bhy2_hif_set_regs(BHY2_REG_HOST_INTERFACE_CTRL, &tmp_buf, 1, hif); + if (rslt == BHY2_OK) + { + /* Set injection mode */ + rslt = bhy2_hif_set_regs(BHY2_REG_CHAN_CMD, payload, payload_len, hif); + if (rslt != BHY2_OK) + { + rslt = BHY2_E_NULL_PTR; + } + } + } + + return rslt; +} + +int8_t bhy2_hif_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_hif_dev *hif) +{ + return bhy2_hif_exec_cmd(BHY2_CMD_INJECT_DATA, payload, payload_len, hif); +} diff --git a/components/SensorLib/src/bosch/bhy2_hif.h b/components/SensorLib/src/bosch/bhy2_hif.h new file mode 100644 index 0000000..a8ac9d4 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_hif.h @@ -0,0 +1,576 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_hif.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHY2_HIF_H__ +#define __BHY2_HIF_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include "bhy2_defs.h" + +/** + * @brief Function to link the callback interfaces + * @param[in] intf : Physical communication interface + * @param[in] read : Read function pointer + * @param[in] write : Write function pointer + * @param[in] delay_us : Microsecond delay function pointer + * @param[in] read_write_len : Maximum read/write lengths supported + * @param[in] intf_ptr : Reference to the interface. Can be NULL + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_init(enum bhy2_intf intf, + bhy2_read_fptr_t read, + bhy2_write_fptr_t write, + bhy2_delay_us_fptr_t delay_us, + uint32_t read_write_len, + void *intf_ptr, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to get data from registers + * @param[in] reg_addr : Register address to be read from + * @param[out] reg_data : Reference to the data buffer + * @param[in] length : Length of the data buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif); + +/** + * @brief Function to set data to registers + * @param[in] reg_addr : Register address to write to + * @param[in] reg_data : Reference to the data buffer + * @param[in] length : Length of the data buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif); + +/** + * @brief Function to delay in microseconds + * @param[in] period_us : Period to delay in microseconds + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_delay_us(uint32_t period_us, const struct bhy2_hif_dev *hif); + +/** + * Function to execute a command + * @param[in] cmd : Command code + * @param[in] payload : Reference to the data buffer containing the command's payload + * @param[in] length : Length of the data buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_exec_cmd(uint16_t cmd, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get a parameter + * @param[in] param : Parameter ID + * @param[out] payload : Reference to the data buffer to store the parameter's payload + * @param[in] payload_len : Length of the data buffer + * @param[out] actual_len : Actual length of the payload + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_parameter(uint16_t param, + uint8_t *payload, + uint32_t payload_len, + uint32_t *actual_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to set a parameter + * @param[in] param : Parameter ID + * @param[in] payload : Reference to the data buffer storing the parameter's payload + * @param[in] length : Length of the data buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif); + +/** + * @brief Function to erase the flash + * @param[in] start_addr : Start address + * @param[in] end_addr : End address + * @param[in] hif : HIF device address + * @return API error codes + */ +int8_t bhy2_hif_erase_flash(uint32_t start_addr, uint32_t end_addr, struct bhy2_hif_dev *hif); + +/** + * @brief Function to upload data to flash + * @param[in] firmware : Reference to the data buffer storing the firmware + * @param[in] length : Length of the data buffer + * @param[in/out] work_buffer : Reference to the work buffer + * @param[in] work_buf_len : Length of the work buffer + * @param[out] exp_size : Expected size of the work buffer if insufficient size + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_upload_to_flash(const uint8_t *firmware, + uint32_t length, + uint8_t *work_buffer, + uint32_t work_buf_len, + uint32_t *exp_size, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to upload data to flash partly + * @param[in] firmware : Reference cur_pos of the data buffer storing the firmware + * @param[in] cur_pos : Current position of the firmware + * @param[in] packet_len : Length of the firmware packet to be transferred + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_upload_to_flash_partly(const uint8_t *firmware, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to boot from flash + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_boot_from_flash(struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the product ID + * @param[out] product_id : Reference to the data buffer to store the product ID + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_product_id(uint8_t *product_id, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the chip ID + * @param[out] chip_id : Reference to the data buffer to store the chip ID + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_chip_id(uint8_t *chip_id, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the ROM version + * @param[out] rom_version : Reference to the data buffer to store the ROM version + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_rom_version(uint16_t *rom_version, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the kernel version + * @param[out] kernel_version : Reference to the data buffer to store the kernel version + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_kernel_version(uint16_t *kernel_version, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the user version + * @param[out] user_version : Reference to the data buffer to store the user version + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_user_version(uint16_t *user_version, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the boot status + * @param[out] boot_status : Reference to the data buffer to store the boot status + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_boot_status(uint8_t *boot_status, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the host status + * @param[out] host_status : Reference to the data buffer to store the host status + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_host_status(uint8_t *host_status, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the feature status + * @param[out] feat_status : Reference to the data buffer to store the feature status + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_feature_status(uint8_t *feat_status, struct bhy2_hif_dev *hif); + +/** + * @brief Function get the interrupt status + * @param[out] int_status : Reference to the data buffer to store the interrupt status + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_interrupt_status(uint8_t *int_status, struct bhy2_hif_dev *hif); + +/** + * @brief Function get the firmware error code + * @param[out] fw_error : Reference to the data buffer to store the firmware error code + * @param[in] hif : HIF device reference + * @return API error code + */ +int8_t bhy2_hif_get_fw_error(uint8_t *fw_error, struct bhy2_hif_dev *hif); + +/** + * @brief Function to trigger a soft reset + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_reset(struct bhy2_hif_dev *hif); + +/** + * @brief Function to upload a firmware to RAM + * @param[in] firmware : Reference to the data buffer storing the firmware + * @param[in] length : Length of the firmware + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_hif_dev *hif); + +/** + * @brief Function to upload a part of the firmware to RAM + * @param[in] firmware : Reference to the data buffer storing the current part of firmware + * @param[in] total_size : Total size of the firmware + * @param[in] cur_pos : Current position of the firmware + * @param[in] packet_len : Size of firmware part to be uploaded + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_upload_firmware_to_ram_partly(const uint8_t *firmware, + uint32_t total_size, + uint32_t cur_pos, + uint32_t packet_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to boot from RAM + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_boot_program_ram(struct bhy2_hif_dev *hif); + +/** + * @brief Function to get data from the Wake-up FIFO + * @param[out] fifo : Reference to the data buffer to store data from the FIFO + * @param[in] fifo_len : Length of the data buffer + * @param[out] bytes_read : Number of bytes read into the data buffer + * @param[out] bytes_remain : Bytes remaining in the sensor FIFO + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_wakeup_fifo(uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to get data from the Non-wake-up FIFO + * @param[out] fifo : Reference to the data buffer to store data from the FIFO + * @param[in] fifo_len : Length of the data buffer + * @param[out] bytes_read : Number of bytes read into the data buffer + * @param[out] bytes_remain : Bytes remaining in the sensor FIFO + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_nonwakeup_fifo(uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to get synchronous data from the Status FIFO + * @param[out] status_code : Status code received + * @param[out] fifo : Reference to the data buffer to store the payload of the status code + * @param[in] fifo_len : Length of the data buffer + * @param[out] bytes_remain : Number of bytes in the payload + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_status_fifo(uint16_t *status_code, + uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to get asynchronous data from the Status FIFO + * @param[out] fifo : Reference to the data buffer to store data from the FIFO + * @param[in] fifo_len : Length of the data buffer + * @param[out] bytes_read : Number of bytes read into the data buffer + * @param[out] bytes_remain : Bytes remaining in the sensor FIFO + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_status_fifo_async(uint8_t *fifo, + uint32_t fifo_len, + uint32_t *bytes_read, + uint32_t *bytes_remain, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to configure a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] sample_rate : Sample rate in Hz + * @param[in] latency : Report latency in milliseconds + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_exec_sensor_conf_cmd(uint8_t sensor_id, + bhy2_float sample_rate, + uint32_t latency, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to flush data of a virtual sensor from the FIFOs + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_fifo_flush(uint8_t sensor_id, struct bhy2_hif_dev *hif); + +/** + * @brief Function to perform a self-test for a particular virtual sensor + * @param[in] phys_sensor_id : Physical sensor ID of the virtual sensor + * @param[out] self_test_resp : Reference to the data buffer to store the self-test response + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_do_self_test(uint8_t phys_sensor_id, + struct bhy2_self_test_resp *self_test_resp, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to perform a fast offset compensation for a particular virtual sensor + * @param[in] phys_sensor_id : Physical Sensor ID of the virtual sensor + * @param[out] foc_resp : Reference to the data buffer to store the FOC response + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_do_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the sensor control configuration of a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] ctrl_code : Sensor control code + * @param[out] payload : Reference to the data buffer to store the sensor control + * @param[in] payload_len : Length of the data buffer + * @param[out] actual_len : Actual length of the sensor control configuration + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_sensor_ctrl(uint8_t sensor_id, + uint8_t ctrl_code, + uint8_t *payload, + uint32_t payload_len, + uint32_t *actual_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to set the sensor control configuration of a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[in] ctrl_code : Sensor control code + * @param[in] payload : Reference to the data buffer storing the sensor control + * @param[in] payload_len : Length of the sensor control configuration + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_sensor_ctrl(uint8_t sensor_id, + uint8_t ctrl_code, + const uint8_t *payload, + uint32_t payload_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the BSX state of a BSX parameter + * @param[in] param_id : Parameter ID of the BSX parameter + * @param[out] bsx_state : Reference to teh data buffer to store the BSX state + * @param[in] state_len : Length of the buffer + * @param[out] actual_len : Actual length of the BSX state + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_bsx_state(uint16_t param_id, + uint8_t *bsx_state, + uint32_t state_len, + uint32_t *actual_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to the BSX state of a BSX parameter + * @param[in] param_id : Parameter ID of the BSX parameter + * @param[in] bsx_state : Reference to the data buffer storing the BSX state + * @param[in] state_len : Length of the BSX state + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_bsx_state(uint16_t param_id, const uint8_t *bsx_state, uint32_t state_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to request a timestamp event + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_request_hw_timestamp(struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the hardware timestamp + * @param[out] ts_ticks : Reference to the data buffer to store the timestamp in ticks + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif); + +/** + * @brief Function to request and get the hardware timestamp + * @param[out] ts_ticks : Reference to the data buffer to store the timestamp in ticks + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_req_and_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif); + +/** + * @brief Function to communicate with connected sensors + * @param[in] payload : Command payload + * @param[in] payload_len : Payload length + * @param[in/out] reg_data : Reference to the data buffer storing the register data + * @param[in] length : Length of the data buffer + * @param[out] actual_len : Registers actually read + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_exec_soft_passthrough(const uint8_t *payload, + uint32_t payload_len, + uint8_t *reg_data, + uint32_t length, + uint32_t *actual_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the post-mortem data dump + * @param[out] code : Post-mortem status code + * @param[out] actual_len : Actual length of the post-mortem data dump + * @param[out] post_mortem : Reference to the data buffer to store the data dump + * @param[in] buffer_len : Length of the data buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_post_mortem(uint16_t *code, + uint32_t *actual_len, + uint8_t *post_mortem, + uint32_t buffer_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function get information of a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[out] info : Reference to the data buffer to store the sensor info + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the physical sensor information of a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[out] info : Reference to the data buffer to store the physical sensor info + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_get_phys_sensor_info(uint8_t sensor_id, struct bhy2_phys_sensor_info *info, struct bhy2_hif_dev *hif); + +/** + * @brief Function to get the orientation matrix of a virtual sensor + * @param[in] sensor_id : Sensor ID of the virtual sensor + * @param[out] orient_matrix : Reference to the data buffer to store the orientation matrix + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_orientation_matrix(uint8_t sensor_id, + struct bhy2_orient_matrix orient_matrix, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to set the data injection mode + * @param[in] payload : Reference to the data buffer containing the host injection mode + * @param[in] payload_len : Length of the data buffer + * @param[in/out] work_buf : Reference to the work buffer + * @param[in] work_buf_len : Length of the work buffer + * @param[out] actual_len : Expected length of the work buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_set_inject_data_mode(const uint8_t *payload, + uint8_t payload_len, + const uint8_t *work_buf, + uint32_t work_buf_len, + const uint32_t *actual_len, + struct bhy2_hif_dev *hif); + +/** + * @brief Function to inject data + * @param[in] payload : Reference to the data buffer + * @param[in] payload_len : Length of the data buffer + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_hif_dev *hif); + +/** + * @brief Function to wait till status is ready + * @param[in] hif : HIF device reference + * @return API error codes + */ +int8_t bhy2_hif_wait_status_ready(struct bhy2_hif_dev *hif); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHY2_HIF_H__ */ diff --git a/components/SensorLib/src/bosch/bhy2_klio.c b/components/SensorLib/src/bosch/bhy2_klio.c new file mode 100644 index 0000000..3f3a3a9 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_klio.c @@ -0,0 +1,373 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_klio.c +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +/*********************************************************************/ +/* system header files */ +#include +#include + +/*********************************************************************/ +/* BHY2 SensorAPI header files */ +#include "bhy2.h" + +/*********************************************************************/ +/* own header files */ +#include "bhy2_klio.h" + +int8_t bhy2_klio_read_pattern(const uint8_t id, uint8_t *buffer, uint16_t *length, struct bhy2_dev *dev) +{ + int8_t rslt; + uint32_t ret_len; + bhy2_klio_pattern_transfer_t pattern = { 0 }; + + if (!buffer || !length || !dev) + { + return BHY2_E_NULL_PTR; + } + + if (id != 0 || *length < sizeof(pattern.pattern_data)) + { + return BHY2_E_INVALID_PARAM; + } + + rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN), (uint8_t*)&pattern, sizeof(pattern), &ret_len, dev); + + if (rslt != BHY2_OK) + { + return rslt; + } + + if (ret_len != sizeof(pattern)) + { + return BHY2_E_INVALID_PARAM; + } + + memcpy(buffer, pattern.pattern_data, pattern.full_size); + *length = pattern.full_size; + + return rslt; +} + +int8_t bhy2_klio_read_reset_driver_status(uint32_t *klio_driver_status, struct bhy2_dev *dev) +{ + uint32_t ret_len = 0; + int8_t rslt; + + if (!klio_driver_status || !dev) + { + return BHY2_E_NULL_PTR; + } + + do + { + rslt = + bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_DRIVER_STATUS), + (uint8_t*)klio_driver_status, + sizeof(*klio_driver_status), + &ret_len, + dev); + + if (rslt != BHY2_OK) + { + return rslt; + } + } while (*klio_driver_status == KLIO_DRIVER_ERROR_OPERATION_PENDING); + + return rslt; +} + +int8_t bhy2_klio_write_pattern(const uint8_t idx, const uint8_t *pattern_data, const uint16_t size, + struct bhy2_dev *dev) +{ + bhy2_klio_pattern_transfer_t pattern = { + .block_id = 0, .block_size = (uint8_t)size, .full_size = size, .pattern_id = idx, .pattern_data = { 0 } + }; + + if (!dev || size > sizeof(pattern.pattern_data)) + { + return BHY2_E_INVALID_PARAM; + } + + memcpy(pattern.pattern_data, pattern_data, size); + + return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN), (const uint8_t*)&pattern, sizeof(pattern), dev); +} + +int8_t bhy2_klio_set_pattern_states(const bhy2_klio_pattern_state_t operation, + const uint8_t *pattern_ids, + const uint16_t count, + struct bhy2_dev *dev) +{ + uint32_t buffer_size = sizeof(bhy2_klio_pattern_state_op_t) + count; + uint8_t buffer[buffer_size]; + + if (!dev || count == 0) + { + return BHY2_E_INVALID_PARAM; + } + + buffer[1] = (uint8_t)count; + buffer[0] = operation; + + for (uint8_t i = 0; i < count; i++) + { + buffer[i + 2] = pattern_ids[i]; + } + + return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_STATE), buffer, buffer_size, dev); +} + +int8_t bhy2_klio_set_state(const bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint8_t buffer[4]; + + if (!dev || !state) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + buffer[0] = state->learning_enabled; + buffer[1] = state->learning_reset; + buffer[2] = state->recognition_enabled; + buffer[3] = state->recognition_reset; + + rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGORITHM_STATE), buffer, sizeof(buffer), dev); + } + + return rslt; +} + +int8_t bhy2_klio_get_state(bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (!dev || !state) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + uint8_t buffer[4]; + uint32_t ret_len; + + rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGORITHM_STATE), buffer, sizeof(buffer), &ret_len, dev); + if (rslt == BHY2_OK && ret_len == sizeof(buffer)) + { + state->learning_enabled = buffer[0]; + state->learning_reset = buffer[1]; + state->recognition_enabled = buffer[2]; + state->recognition_reset = buffer[3]; + } + } + + return rslt; +} + +int8_t bhy2_klio_similarity_score(const uint8_t *first_pattern, + const uint8_t *second_pattern, + const uint16_t size, + float *similarity, + struct bhy2_dev *dev) +{ + uint32_t klio_driver_status = 0; + int8_t rslt; + uint32_t ret_len; + bhy2_klio_pattern_transfer_t pattern1 = { 0 }, pattern2 = { 0 }; + uint8_t buffer[4]; + + if (!dev || size > sizeof(pattern1.pattern_data)) + { + return BHY2_E_INVALID_PARAM; + } + + pattern1.block_size = pattern2.block_size = (uint8_t)size; + pattern1.full_size = pattern2.full_size = size; + memcpy(pattern1.pattern_data, first_pattern, size); + memcpy(pattern2.pattern_data, second_pattern, size); + + rslt = + bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)&pattern1, sizeof(pattern1), dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + rslt = + bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)&pattern2, sizeof(pattern2), dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + /* Wait for similarity calculation to complete. */ + rslt = bhy2_klio_read_reset_driver_status(&klio_driver_status, dev); + if (rslt != BHY2_OK || klio_driver_status != KLIO_DRIVER_ERROR_NONE) + { + return BHY2_E_INVALID_PARAM; + } + + rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), buffer, sizeof(buffer), &ret_len, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + if (ret_len != sizeof(buffer)) + { + return BHY2_E_INVALID_PARAM; + } + + memcpy(similarity, buffer, sizeof(*similarity)); + + return BHY2_OK; +} + +int8_t bhy2_klio_similarity_score_multiple(const uint8_t idx, + const uint8_t *indexes, + const uint8_t count, + float *similarity, + struct bhy2_dev *dev) +{ + uint32_t klio_driver_status; + int8_t rslt; + uint32_t ret_len; + uint32_t buffer_size = sizeof(bhy2_klio_similarity_calculation_t) + count; + + buffer_size = BHY2_ROUND_WORD_HIGHER(buffer_size); + uint8_t buffer[256] = { 0 }; + + if (!indexes || !similarity || !dev) + { + return BHY2_E_NULL_PTR; + } + + /* buffer[0-3] values are initialized to zero's to distinguish from regular pattern comparison*/ + buffer[4] = idx; + buffer[5] = count; + for (uint8_t i = 0; i < count; i++) + { + buffer[i + 6] = indexes[i]; + } + + /* Start similarity calculations. */ + rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)buffer, buffer_size, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + /* Wait for similarity calculation to complete. */ + rslt = bhy2_klio_read_reset_driver_status(&klio_driver_status, dev); + if (rslt != BHY2_OK || klio_driver_status != KLIO_DRIVER_ERROR_NONE) + { + return BHY2_E_INVALID_PARAM; + } + + /* Read similarity results. */ + rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), + (uint8_t *)similarity, + sizeof(float) * count, + &ret_len, + dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + return BHY2_OK; +} + +int8_t bhy2_klio_set_parameter(const bhy2_klio_parameter_t id, + const void *parameter_data, + const uint16_t size, + struct bhy2_dev *dev) +{ + bhy2_klio_parameter_wrapper_t buffer; + + buffer.id = id; + buffer.flags = 0; + buffer.size = (uint8_t)size; + memcpy(buffer.payload.data, parameter_data, size); + + /* Size is 3 bytes header and buffer.size then rounded up to a four byte multiple. */ + return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), + (uint8_t*)&buffer, + (3 + buffer.size + 3) & ~3, + dev); +} + +int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id, + uint8_t *parameter_data, + uint16_t *size, + struct bhy2_dev *dev) +{ + uint32_t ret_len; + uint8_t buffer[260] = { 0 }; + + buffer[0] = id; + int8_t rslt; + + /* Size is 3 bytes header and buffer.size then rounded up to a four byte multiple. */ + rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), buffer, (3 + buffer[2] + 3) & ~3, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), buffer, sizeof(buffer), &ret_len, dev); + if (rslt != BHY2_OK) + { + return rslt; + } + + if (ret_len < 3 || buffer[2] > *size) + { + return BHY2_E_INVALID_PARAM; + } + + for (uint16_t i = 3, j = 0; i < buffer[2] + 3; i++, j++) + { + parameter_data[j] = buffer[i]; + } + + *size = buffer[2]; + + return BHY2_OK; +} diff --git a/components/SensorLib/src/bosch/bhy2_klio.h b/components/SensorLib/src/bosch/bhy2_klio.h new file mode 100644 index 0000000..db66a62 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_klio.h @@ -0,0 +1,227 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_klio.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHY2_KLIO_H__ +#define __BHY2_KLIO_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include + +#include "bhy2.h" +#include "bhy2_klio_defs.h" + +/*! + * @brief Reads and resets current driver status. + * + * The driver_status will be set to one of the values in + * @ref bhy2_klio_driver_error_state_t. This function will not return a driver + * status of + * @ref bhy2_klio_driver_error_state_t::KLIO_DRIVER_ERROR_OPERATION_PENDING. + * but will retry until the pending operation is finished. + * + * @param[out] driver_status Pointer to uint32_t + * @param[in] dev Device reference. + * + * @return BHY2 API error codes. + */ +int8_t bhy2_klio_read_reset_driver_status(uint32_t *driver_status, struct bhy2_dev *dev); + +/*! + * @brief Read learnt pattern. + * + * @param[in] id pattern id (only 0 supported now) + * @param[out] buffer buffer big enough to fit complete pattern fingerprint data + * @param[in,out] length size of buffer, return size of actual pattern data + * @param[in] dev Device reference + * + * @return BHY2 API error codes. + * + * After learning of a new pattern has been signaled by a sensor data event, + * call this function to retrieve the learnt pattern. + */ +int8_t bhy2_klio_read_pattern(const uint8_t id, uint8_t *buffer, uint16_t *length, struct bhy2_dev *dev); + +/*! + * @brief Set KLIO algorithm learning and recognition state. + * + * @param[in] state new state for algorithm + * @param[in] dev Device reference + * + * @return BHY2 API error codes. + * + * Writing 1 to the reset fields resets all internal algorithm state and + * removes any patterns loaded for recognition. + */ +int8_t bhy2_klio_set_state(const bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev); + +/*! + * @brief Get KLIO algorithm learning and recognition state. + * + * @param[out] state current state for algorithm + * @param[in] dev Device reference + * + * @return BHY2 API error codes. + * + * The resets are always read as 0. + */ +int8_t bhy2_klio_get_state(bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev); + +/*! + * @brief Write pattern to recognition algorithm. + * + * @param[in] idx pattern index + * @param[in] pattern_data containing pattern + * @param[in] size pattern size + * @param[in] dev Device reference + * + * @return BHY2 API error codes. + * + * Write a pattern to the specified recognition index. The allowed number of + * recognition patterns may be retrieved using the + * @ref bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_MAX_PATTERNS parameter. + * + * After a pattern is written, it is in disabled state and not used. It must + * be enabled using @ref bhy2_klio_set_pattern_states() before it will be used + * by the recognition algorithm. + */ +int8_t bhy2_klio_write_pattern(const uint8_t idx, const uint8_t *pattern_data, const uint16_t size, + struct bhy2_dev *dev); + +/*! + * @brief Sets the specified state for the specified pattern ids. + * + * @param[in] operation operation to perform + * @param[in] pattern_ids ids of pattern(s) to perform operation on + * @param[in] size size of pattern_ids array + * @param[in] dev Device reference + * + * @return BHY2 API error codes. + */ +int8_t bhy2_klio_set_pattern_states(const bhy2_klio_pattern_state_t operation, + const uint8_t *pattern_ids, + const uint16_t size, + struct bhy2_dev *dev); + +/*! + * @brief Calculates similarity score between two patterns. + * + * The similariy between patterns is a meassure of the similarity between the + * performed activities or exercises. If the two patterns represent the same + * excercise the similarity will be close to 1.0, and if they are for very + * different excercises, the similarity will be negative. + * + * @param[in] first_pattern Buffer containing first pattern. + * @param[in] second_pattern Buffer containing second pattern. + * @param[in] size Pattern size. + * @param[out] similarity Similarity score. + * @param[in] dev Device reference. + * + * @return BHY2 API error codes. + */ +int8_t bhy2_klio_similarity_score(const uint8_t *first_pattern, + const uint8_t *second_pattern, + const uint16_t size, + float *similarity, + struct bhy2_dev *dev); + +/*! + * @brief Calculates similarity score between multiple patterns. + * + * This is more efficient than bhy2_klio_similarity_score() since if the patterns + * are already available on the bhy2, they need not be uploaded again to + * perform the comparison. And several comparisons may be performed with one + * API call. + * + * @param[in] idx Reference pattern. + * @param[in] indexes Buffer containing indexes of patterns to compare reference pattern with. + * @param[in] count Number of patterns in indexes buffer. + * @param[out] similarity Similarity scores (one score for each pattern in indexes buffer). + * @param[in] dev Device reference. + * + * @return BHY2 API error codes. + */ +int8_t bhy2_klio_similarity_score_multiple(const uint8_t idx, + const uint8_t *indexes, + const uint8_t count, + float *similarity, + struct bhy2_dev *dev); + +/*! + * @brief Set KLIO algorithm parameter + * + * @param[in] id Parameter to set. + * @param[in] parameter_data Buffer containing new parameter value. + * @param[in] size Parameter size. + * @param[in] dev Device reference. + * + * @return BHY2 API error codes. + */ +int8_t bhy2_klio_set_parameter(const bhy2_klio_parameter_t id, + const void *parameter_data, + const uint16_t size, + struct bhy2_dev *dev); + +/*! + * @brief Get KLIO algorithm parameter + * + * @param[in] id Parameter id. + * @param[out] parameter_data Buffer to store parameter data. + * @param[in,out] size Parameter data size. + * @param[in] dev Device reference. + * + * @return BHY2 API error codes. + * + * The expected type or buffer size of parameter_data for respective parameter + * id is specified in the @ref bhy2_klio_parameter_t enum. + */ +int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id, + uint8_t *parameter_data, + uint16_t *size, + struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif diff --git a/components/SensorLib/src/bosch/bhy2_klio_defs.h b/components/SensorLib/src/bosch/bhy2_klio_defs.h new file mode 100644 index 0000000..2d4b05e --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_klio_defs.h @@ -0,0 +1,349 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_klio_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef __BHY2_KLIO_DEFS_H__ +#define __BHY2_KLIO_DEFS_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include + +#define BHY2_SENSOR_ID_KLIO UINT8_C(112) +#define BHY2_SENSOR_ID_KLIO_LOG UINT8_C(127) + +#ifndef BHY2_KLIO_PAGE +#define BHY2_KLIO_PAGE UINT16_C(9) +#endif +#define KLIO_PARAM(id) (((BHY2_KLIO_PAGE) << 8) | (id)) + +/*! + * @enum bhy2_klio_parameter + * + * KLIO algorithm parameters + * + * @var bhy2_klio_parameter::KLIO_PARAM_ALGORITHM_VERSION + * Algorithm version. (read) + * @code{.c} char version[244]; @endcode + * + * @var bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_RESPONSIVNESS + * The approximate number of cycles / repetitions for recognition to recognize + * an activity. (read / write) + * @code{.c} float cycle_fraction; @endcode + * + * @var bhy2_klio_parameter::KLIO_PARAM_PATTERN_BLOB_SIZE + * Pattern blob size in bytes. (read) + * @code{.c} uint16_t pattern_blob_size; @endcode + * + * @var bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_MAX_PATTERNS + * Read Maximum number of patterns. (read) + * @code{.c} uint16_t recognition_max_patterns; @endcode + * + * @var bhy2_klio_parameter::KLIO_PARAM_LEARNING_IGNORE_INSIG_MOVEMENT + * Flag if insignificant movements should be ignored in learning. Value 0 or 1. (read / write) + * @code{.c} uint8_t ignore_insig_movement; @endcode + */ +typedef enum +{ + KLIO_PARAM_ALGORITHM_VERSION = 0, + KLIO_PARAM_RECOGNITION_SENSITIVITY = 1, + KLIO_PARAM_RECOGNITION_RESPONSIVNESS = 2, + KLIO_PARAM_LEARNING_SPEED = 3, + KLIO_PARAM_LEARNING_SIMILARITY_THRESHOLD = 4, + KLIO_PARAM_LEARNING_FREQUENCIES = 5, + KLIO_PARAM_LEARNING_PROGRESS = 6, + KLIO_PARAM_PATTERN_BLOB_SIZE = 7, + KLIO_PARAM_RECOGNITION_MAX_PATTERNS = 8, + KLIO_PARAM_INPUT_SENSORS = 9, + KLIO_PARAM_LEARNING_IGNORE_INSIG_MOVEMENT = 10 +} bhy2_klio_parameter_t; + +/*! + * + * @brief Convenience wrapper used in bhy2_klio.c algo parameter wrapper. + * + */ +typedef struct +{ + uint8_t id; + uint8_t flags; + uint8_t size; + union + { + uint8_t data[244]; + char version[244]; + float cycle_fraction; + uint16_t pattern_blob_size; + uint16_t recognition_max_patterns; + uint8_t ignore_insig_movement; + } BHY2_PACKED payload; +} BHY2_PACKED bhy2_klio_parameter_wrapper_t; + +/*! + * + * @brief bhy2 klio state structure + * + */ +typedef struct +{ + uint8_t learning_enabled; /*!< 0 - disable learning, 1 - enable learning. */ + uint8_t learning_reset; /*!< 0 - nop, 1 - reset learning. Always read as 0. */ + uint8_t recognition_enabled; /*!< 0 - disable recognition, 1 - enable recognition. */ + uint8_t recognition_reset; /*!< 0 - nop, 1 - reset learning. Always read as 0. */ +} BHY2_PACKED bhy2_klio_sensor_state_t; + +typedef struct +{ + uint8_t instance; + + /*! + * A value of -1 means no new learning has occurred. If the value is >= 0, + * then a new pattern has been learnt, and reading of this pattern may be + * performed. + */ + int8_t index; + + /*! + * While learning a new pattern, this field counts from 0 to 100. When 100 is + * reached a new pattern will be learnt. If learning is interrupted, this + * progress will return to 0, and change reason will be set to indicate + * why learning was interrupted. + */ + uint8_t progress; + + /*! + * | Value | Description | + * |:-----:|:-----------------------------------------------------------------------| + * | 0 | Learning is progressing. | + * | 1 | Learning was interrupted by a non-repetitive activity. | + * | 2 | Learning was interrupted because no significant movement was detected. | + */ + uint8_t change_reason; +} BHY2_PACKED bhy2_klio_sensor_frame_learning_t; + +typedef struct +{ + uint8_t instance; + + /*! The index of the recognized activity. 255 means no activity was + * recognized. */ + uint8_t index; + + /*! The current repetition count of the recognized activity. */ + float count; +} BHY2_PACKED bhy2_klio_sensor_frame_recognition_t; + +/*! + * + * @brief bhy2 klio combined data structure + * + * When the algorithm generates a new data frame, it is sent in this structure. + * + */ +typedef struct +{ + bhy2_klio_sensor_frame_learning_t learn; + bhy2_klio_sensor_frame_recognition_t recognize; +} BHY2_PACKED bhy2_klio_sensor_frame_t; + +/*! + * + * @brief bhy2 klio sensor log frame + * + * When the algorithm consumes a new set of samples, it is sent in this structure. + * + */ +typedef struct +{ + float timestamp; + float accel[3]; + float gyro[3]; +} BHY2_PACKED bhy2_klio_log_frame_t; + +/*! + * + * @brief bhy2 klio pattern transfer format + * + */ +typedef struct +{ + uint8_t block_id; /*!< Write as 0. */ + uint8_t block_size; /*!< Write as 0. */ + + /*! Size of pattern_data in bytes. The size of patterns may be obtained + using the @ref bhy2_klio_parameter::KLIO_PARAM_PATTERN_BLOB_SIZE + parameter. */ + uint16_t full_size; + + /*! Id of pattern to write. */ + uint8_t pattern_id; + + /*! Actual pattern data describing the exercise. */ + uint8_t pattern_data[244]; +} BHY2_PACKED bhy2_klio_pattern_transfer_t; + +/*! + * + * @brief Convenience wrapper used by @ref bhy2_klio_similarity_score_multiple(). + * + */ +typedef struct +{ + uint32_t zero; + uint8_t index; + uint8_t count; + uint8_t *indexes; +} BHY2_PACKED bhy2_klio_similarity_calculation_t; + +/*! + * + * @brief Convenience wrapper used by @ref bhy2_klio_set_pattern_states(). + * + */ +typedef struct +{ + uint8_t operation; + uint8_t count; + uint8_t *indexes; +} BHY2_PACKED bhy2_klio_pattern_state_op_t; + +/*! + * KLIO pattern state + */ +typedef enum +{ + /*!< disable pattern */ + KLIO_PATTERN_STATE_DISABLE = 0, + + /*!< enable pattern */ + KLIO_PATTERN_STATE_ENABLE = 1, + + /*!< switch hand */ + KLIO_PATTERN_STATE_SWITCH_HAND = 2, + + /*!< disable adaptive pattern */ + KLIO_PATTERN_STATE_AP_DISABLE = 3 +} bhy2_klio_pattern_state_t; + +/*! + * @brief KLIO host interface parameter identifiers. + * + * The parameter id used when calling the BHY2 functions directly. E.g. to read the driver status this may be used. + * + * ~~~{.c} + * uint32_t klio_driver_status = 0; + * uint32_t ret_len = 0; + * int8_t rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_DRIVER_STATUS), + * (uint8_t*)&klio_driver_status, + * sizeof(klio_driver_status), + * &ret_len, + * dev); + * if (rslt != BHY2_OK) + * { + * return rslt; + * } + * ~~~ + */ +typedef enum +{ + /*!< Read and write algorighm state. */ + KLIO_HIF_PARAM_ALGORITHM_STATE = 0, + + /*!< Read and write patterns. */ + KLIO_HIF_PARAM_PATTERN = 1, + + /*!< Read and write algorithm parameters. */ + KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER = 2, + KLIO_HIF_PARAM_STATISTIC = 3, + KLIO_HIF_PARAM_PATTERN_STATE = 4, + + /*!< Perform pattern similarity. */ + KLIO_HIF_PARAM_PATTERN_SIMILARITY = 5, + KLIO_HIF_PARAM_PATTERN_COMBINING = 6, + + /*!< Read driver status. */ + KLIO_HIF_PARAM_DRIVER_STATUS = 7 +} bhy2_klio_hif_parameter_t; + +/*! + * KLIO driver error codes + */ +typedef enum +{ + /*!< No error. */ + KLIO_DRIVER_ERROR_NONE = 0, + + /*!< Invalid parameter. */ + KLIO_DRIVER_ERROR_INVALID_PARAMETER = 1, + + /*!< Parameter out of range. */ + KLIO_DRIVER_ERROR_PARAMETER_OUT_OF_RANGE = 2, + + /*! + * Invalid pattern operation. E.g. trying to read a learnt pattern when no + * pattern has been learnt, or trying to write an invalid pattern. + */ + KLIO_DRIVER_ERROR_INVALID_PATTERN_OPERATION = 3, + + /*!< Not implemented. */ + KLIO_DRIVER_ERROR_NOT_IMPLEMENTED = 4, + + /*!< Insufficient buffer size */ + KLIO_DRIVER_ERROR_BUFSIZE = 5, + + /*!< Internal error. */ + KLIO_DRIVER_ERROR_INTERNAL = 6, + + /*!< Undefined error */ + KLIO_DRIVER_ERROR_UNDEFINED = 7, + + /*! + * Previous operation is still progressing. Read driver status again until + * operation is finished. + */ + KLIO_DRIVER_ERROR_OPERATION_PENDING = 8 +} bhy2_klio_driver_error_state_t; + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHY2_KLIO_DEFS_H__ */ diff --git a/components/SensorLib/src/bosch/bhy2_parse.c b/components/SensorLib/src/bosch/bhy2_parse.c new file mode 100644 index 0000000..8d22313 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_parse.c @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bhy2_parse.c + * @date 2023-03-24 + * @version v1.6.0 + * + */ + +#include "bhy2.h" +#include "bhy2_parse.h" + +void bhy2_parse_temperature_celsius(const uint8_t *data, bhy2_float *temperature) +{ + /* 1 LSB = 1/100 degC */ + float scale_factor = (float)1 / 100; + + *temperature = BHY2_LE2S16(data) * scale_factor; +} + +void bhy2_parse_humidity(const uint8_t *data, bhy2_float *humidity) +{ + float scale_factor = (float)1; + + *humidity = data[0] * scale_factor; +} + +void bhy2_parse_pressure(const uint8_t *data, bhy2_float *pressure) +{ + /* 1 LSB = 1/128 Pa */ + float scale_factor = (float)1 / 128; + + *pressure = (float)BHY2_LE2U24(data) * scale_factor; +} + +void bhy2_parse_altitude(const uint8_t *data, bhy2_float *altitude) +{ + *altitude = (float)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24)); +} + +void bhy2_parse_quaternion(const uint8_t *data, struct bhy2_data_quaternion *quaternion) +{ + quaternion->x = BHY2_LE2S16(data); + quaternion->y = BHY2_LE2S16(data + 2); + quaternion->z = BHY2_LE2S16(data + 4); + quaternion->w = BHY2_LE2S16(data + 6); + quaternion->accuracy = BHY2_LE2U16(data + 8); +} + +void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector) +{ + vector->x = BHY2_LE2S16(data); + vector->y = BHY2_LE2S16(data + 2); + vector->z = BHY2_LE2S16(data + 4); +} + +void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *orientation) +{ + orientation->heading = BHY2_LE2S16(data); + orientation->pitch = BHY2_LE2S16(data + 2); + orientation->roll = BHY2_LE2S16(data + 4); +} + +uint32_t bhy2_parse_step_counter(const uint8_t *data) +{ + return (uint32_t)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24)); +} diff --git a/components/SensorLib/src/bosch/bhy2_parse.h b/components/SensorLib/src/bosch/bhy2_parse.h new file mode 100644 index 0000000..445ff15 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_parse.h @@ -0,0 +1,109 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_parse.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ +#ifndef __BHY2_PARSE_H__ +#define __BHY2_PARSE_H__ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include "bhy2.h" + +/** + * @brief Function to parse FIFO frame data into temperature + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] temperature : Reference to the data buffer to store temperature in degree C + */ +void bhy2_parse_temperature_celsius(const uint8_t *data, bhy2_float *temperature); + +/** + * @brief Function to parse FIFO frame data into humidity + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] humidity : Reference to the data buffer to store humidity in % + */ +void bhy2_parse_humidity(const uint8_t *data, bhy2_float *humidity); + +/** + * @brief Function to parse FIFO frame data into barometric pressure + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] pressure : Reference to the data buffer to store pressure in Pascals + */ +void bhy2_parse_pressure(const uint8_t *data, bhy2_float *pressure); + +/** + * @brief Function to parse FIFO frame data into altitude + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] altitude : Reference to the data buffer to store altitude + */ +void bhy2_parse_altitude(const uint8_t *data, bhy2_float *altitude); + +/** + * @brief Function to parse FIFO frame data into quaternion + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] quaternion : Reference to the data buffer to store quaternion + */ +void bhy2_parse_quaternion(const uint8_t *data, struct bhy2_data_quaternion *quaternion); + +/** + * @brief Function to parse FIFO frame data into orientation + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] orientation : Reference to the data buffer to store orientation + */ +void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *orientation); + +/** + * @brief Function to parse FIFO frame data into 3 axes vector + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @param[out] vector : Reference to the data buffer to store vector + */ +void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector); + +/** + * @brief Function to parse FIFO frame data into step counter + * @param[in] data : Reference to the data buffer storing data from the FIFO + * @return[out] : Reference to the data buffer to step counter + */ +uint32_t bhy2_parse_step_counter(const uint8_t *data); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __BHY2_PARSE_H__ */ diff --git a/components/SensorLib/src/bosch/bhy2_swim.c b/components/SensorLib/src/bosch/bhy2_swim.c new file mode 100644 index 0000000..4b2aa2c --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_swim.c @@ -0,0 +1,203 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_swim.c +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include + +/*********************************************************************/ +/* BHY2 SensorAPI header files */ +/*********************************************************************/ +#include "bhy2.h" + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "bhy2_swim.h" + +/*! + * @brief This API writes to the configuration parameter + * Config parameters are pool length and handedness + * + * @param[in] buffer to store swim configuration + * @param[out] dev hub handle. + * + * @return rslt execution result. + */ +int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + /*! Length of the configuration is 4 bytes */ + uint32_t length = BHY2_SWIM_DATA_LENGTH; + + /*! Swim Parameter page with offset 0 used for swim configuration*/ + uint16_t param = BHY2_SWIM_CONFIG_PARAM; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set the swim configuration parameter */ + rslt = bhy2_set_parameter(param, (uint8_t *)buffer, length, dev); + } + + return rslt; +} + +/*! + * @brief To get the SWIM configuration parameters like swim length and handedness + * + * @param[out] buffer to store swim configuration + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhy2_swim_get_config(void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + /*! Length of the configuration is 4 bytes */ + uint32_t length = BHY2_SWIM_DATA_LENGTH; + uint32_t ret_length; + + /*! Swim Parameter page with offset 0 used to store swim configuration*/ + uint16_t param = BHY2_SWIM_CONFIG_PARAM; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the swim configuration from the parameter page*/ + rslt = bhy2_get_parameter(param, buffer, length, &ret_length, dev); + + if ((rslt == BHY2_OK) && (ret_length != BHY2_SWIM_DATA_LENGTH)) + { + /*! Invalid number of parameters readout */ + rslt = BHY2_E_INVALID_EVENT_SIZE; + } + } + + return rslt; +} + +/*! + * @brief To get the SWIM Algorithm version + * + * @param[out] buffer to store version data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhy2_swim_get_version(bhy2_swim_version_t *version, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + /*! Buffer to store the swim version */ + uint8_t buffer[4]; + + /*! Length of the configuration is 4 */ + uint32_t length = BHY2_SWIM_DATA_LENGTH; + uint32_t ret_length; + + /*! Swim Parameter page with offset 1 used to store swim algorithm version*/ + uint16_t param = BHY2_SWIM_VERSION; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get the swim version from the parameter page */ + rslt = bhy2_get_parameter(param, buffer, length, &ret_length, dev); + + if ((rslt == BHY2_OK) && (ret_length != BHY2_SWIM_DATA_LENGTH)) + { + /*! Invalid number of parameters readout */ + rslt = BHY2_E_INVALID_EVENT_SIZE; + } + else + { + version->improvement = buffer[0]; + version->platform = buffer[1]; + version->bugfix = buffer[2]; + } + } + + return rslt; +} + +/*! + * @brief Parsing the fifo data to SWIM output structure format + * + * @param[in] Swim data + * @param[out] bhy2_swim_aglo_output to store parameter data + * + * @return API error codes + * + */ +int8_t bhy2_swim_parse_data(const uint8_t *data, struct bhy2_swim_algo_output* output) +{ + int8_t rslt = BHY2_OK; + + if ((data == NULL) || (output == NULL)) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + output->total_distance = BHY2_LE2U16(data); + output->length_count = BHY2_LE2U16(data + 2); + output->lengths_freestyle = BHY2_LE2U16(data + 4); + output->lengths_breaststroke = BHY2_LE2U16(data + 6); + output->lengths_butterfly = BHY2_LE2U16(data + 8); + output->lengths_backstroke = BHY2_LE2U16(data + 10); + output->stroke_count = BHY2_LE2U16(data + 12); + } + + return rslt; +} diff --git a/components/SensorLib/src/bosch/bhy2_swim.h b/components/SensorLib/src/bosch/bhy2_swim.h new file mode 100644 index 0000000..ab5b197 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_swim.h @@ -0,0 +1,101 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_swim.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_SWIM_H_ +#define _BHY2_SWIM_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include + +#include "bhy2.h" +#include "bhy2_swim_defs.h" + +/*! + * @brief Parsing the fifo data to SWIM output structure format + * + * @param[in] data parameter + * @param[out] bhy2_swim_aglo_output to store parameter data + * + * @return API error codes + * + */ +int8_t bhy2_swim_parse_data(const uint8_t *data, struct bhy2_swim_algo_output *output); + +/*! + * @brief To get the SWIM configuration parameters like swim length and handedness + * + * @param[out] buffer to store parameter data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhy2_swim_get_config(void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the SWIM Algorithm version + * + * @param[out] buffer to store version data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhy2_swim_get_version(bhy2_swim_version_t *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the SWIM configuration parameters like swim length and handedness + * @param[out] buffer to store parameter data + * @param[in] dev hub handle + * + * @return status code, BHY_HIF_E_SUCCESS in case of success + * + */ +int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_SWIM_H_ */ diff --git a/components/SensorLib/src/bosch/bhy2_swim_defs.h b/components/SensorLib/src/bosch/bhy2_swim_defs.h new file mode 100644 index 0000000..6811ee8 --- /dev/null +++ b/components/SensorLib/src/bosch/bhy2_swim_defs.h @@ -0,0 +1,126 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_swim_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_SWIM_DEFS_H_ +#define _BHY2_SWIM_DEFS_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include + +/*! Sensor ID for Swim */ +#define BHY2_SENSOR_ID_SWIM UINT8_C(114) + +/*! Swim Parameter Page Base Address*/ +#define BHY2_SWIM_PAGE UINT16_C(0x0B) + +/*! Swim Configuration pages */ +#define BHY2_SWIM_CONFIG_PARAM (BHY2_SWIM_PAGE << 8) +#define BHY2_SWIM_VERSION ((BHY2_SWIM_PAGE << 8) | 1) + +/*! Swim configurations enable/ disable from parameter page */ +#define BHY2_SWIM_ENABLE_CONFIG UINT8_C(1) +#define BHY2_SWIM_DISABLE_CONFIG UINT8_C(0) + +/*! Device in left/right hand */ +#define BHY2_SWIM_DEVICE_ON_LEFT_HAND UINT8_C(1) +#define BHY2_SWIM_DEVICE_ON_RIGHT_HAND UINT8_C(0) + +/*! Pool length */ +#define BHY2_SWIM_POOL_LENGTH_25M UINT8_C(25) +#define BHY2_SWIM_POOL_LENGTH_50M UINT8_C(50) + +#define BHY2_SWIM_DATA_LENGTH UINT8_C(4) + +/*! + * bhy2 swim algo parameter. + */ +typedef struct bhy2_swim_config_param +{ + uint8_t update_swim_config; + uint8_t dev_on_left_hand; + uint8_t pool_length_integral; + uint8_t pool_length_floating; +} __attribute__ ((packed)) bhy2_swim_config_param_t; + +/*! + * swim output structure + */ +typedef struct bhy2_swim_algo_output +{ + uint16_t total_distance; + uint16_t length_count; + uint16_t lengths_freestyle; + uint16_t lengths_breaststroke; + uint16_t lengths_butterfly; + uint16_t lengths_backstroke; + uint16_t stroke_count; +} __attribute__ ((packed)) bhy2_swim_algo_output_t; + +/*! + * callback data capturing structure + */ +typedef struct bhy2_swim_data_parse +{ + uint8_t sensor_id; + uint8_t data_size; + uint8_t *data_ptr; + uint64_t *time_stamp; +} bhy2_swim_data_parse_t; + +/*! @brief structure definition to hold the version information of the software */ +typedef struct bhy2_swim_version +{ + uint8_t improvement; + uint8_t platform; + uint8_t bugfix; + uint8_t optional; +} bhy2_swim_version_t; + +typedef void (*bhy2_swim_algo_callback)(uint32_t seconds, uint32_t nanoseconds, + const struct bhy2_swim_data_parse *callback_info); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_SWIM_DEFS_H_ */ diff --git a/components/SensorLib/src/bosch/common/bosch_interfaces.cpp b/components/SensorLib/src/bosch/common/bosch_interfaces.cpp new file mode 100644 index 0000000..1dab7bc --- /dev/null +++ b/components/SensorLib/src/bosch/common/bosch_interfaces.cpp @@ -0,0 +1,166 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file bosch_interfaces.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-09 + * + */ +#include "bosch_interfaces.h" + +#if defined(ARDUINO) + +#if defined(ARDUINO_ARCH_RP2040) +SPISettings SensorInterfaces::__spiSetting = SPISettings(); +#else +SPISettings SensorInterfaces::__spiSetting = SPISettings(4000000, SPI_DATA_ORDER, SPI_MODE0); +#endif + +void SensorInterfaces::close_interfaces(SensorLibConfigure config) +{ + +} + +bool SensorInterfaces::setup_interfaces(SensorLibConfigure config) +{ + if (config.irq != SENSOR_PIN_NONE) { + pinMode(config.irq, INPUT_PULLDOWN); + } + switch (config.intf) { + case SENSORLIB_I2C_INTERFACE: +#if defined(ARDUINO_ARCH_RP2040) + config.u.i2c_dev.wire->end(); + config.u.i2c_dev.wire->setSDA(config.u.i2c_dev.sda); + config.u.i2c_dev.wire->setSCL(config.u.i2c_dev.scl); + config.u.i2c_dev.wire->begin(); +#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA) + config.u.i2c_dev.wire->end(); + config.u.i2c_dev.wire->setPins(config.u.i2c_dev.sda, config.u.i2c_dev.scl); + config.u.i2c_dev.wire->begin(); +#else + config.u.i2c_dev.wire->begin(config.u.i2c_dev.sda, config.u.i2c_dev.scl); +#endif + config.u.i2c_dev.wire->beginTransmission(config.u.i2c_dev.addr); + if (config.u.i2c_dev.wire->endTransmission() != 0) { + return false; + } + break; + case SENSORLIB_SPI_INTERFACE: + pinMode(config.u.spi_dev.cs, OUTPUT); + digitalWrite(config.u.spi_dev.cs, HIGH); +#if defined(ARDUINO_ARCH_RP2040) + config.u.spi_dev.spi->setSCK(config.u.spi_dev.sck); + config.u.spi_dev.spi->setRX(config.u.spi_dev.miso); + config.u.spi_dev.spi->setTX(config.u.spi_dev.mosi); + config.u.spi_dev.spi->begin(); +#elif defined(ARDUINO_ARCH_NRF52) + config.u.spi_dev.spi->setPins(config.u.spi_dev.miso, config.u.spi_dev.sck, config.u.spi_dev.mosi); + config.u.spi_dev.spi->begin(); +#elif defined(ARDUINO_ARCH_STM32) + config.u.spi_dev.spi->setSCLK(config.u.spi_dev.sck); + config.u.spi_dev.spi->setMISO(config.u.spi_dev.miso); + config.u.spi_dev.spi->setMOSI(config.u.spi_dev.mosi); + config.u.spi_dev.spi->begin(); +#else +config.u.spi_dev.spi->begin(config.u.spi_dev.sck, config.u.spi_dev.miso, config.u.spi_dev.mosi); +#endif + break; + default: + break; + } + return true; +} + + + + +int8_t SensorInterfaces::bhy2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr) +{ + SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr; + if (!pConfig) { + return DEV_WIRE_ERR; + } + digitalWrite(pConfig->u.spi_dev.cs, LOW); + pConfig->u.spi_dev.spi->beginTransaction(__spiSetting); + pConfig->u.spi_dev.spi->transfer((reg_addr)); + for (size_t i = 0; i < length; i++) { + reg_data[i] = pConfig->u.spi_dev.spi->transfer(0x00); + } + pConfig->u.spi_dev.spi->endTransaction(); + digitalWrite(pConfig->u.spi_dev.cs, HIGH); + + return DEV_WIRE_NONE; +} + +int8_t SensorInterfaces::bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr) +{ + SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr; + if (!pConfig) { + return DEV_WIRE_ERR; + } + digitalWrite(pConfig->u.spi_dev.cs, LOW); + pConfig->u.spi_dev.spi->beginTransaction(__spiSetting); + pConfig->u.spi_dev.spi->transfer(reg_addr); + pConfig->u.spi_dev.spi->transfer((uint8_t *)reg_data, length); + pConfig->u.spi_dev.spi->endTransaction(); + digitalWrite(pConfig->u.spi_dev.cs, HIGH); + return DEV_WIRE_NONE; +} + +int8_t SensorInterfaces::bhy2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr) +{ + SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr; + if (!pConfig) { + return DEV_WIRE_ERR; + } + pConfig->u.i2c_dev.wire->beginTransmission(pConfig->u.i2c_dev.addr); + pConfig->u.i2c_dev.wire->write(reg_addr); + if (pConfig->u.i2c_dev.wire->endTransmission() != 0) { + return DEV_WIRE_ERR; + } + pConfig->u.i2c_dev.wire->requestFrom(pConfig->u.i2c_dev.addr, length); + return pConfig->u.i2c_dev.wire->readBytes(reg_data, length) == length ? DEV_WIRE_NONE : DEV_WIRE_ERR; +} + +int8_t SensorInterfaces::bhy2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr) +{ + SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr; + if (!pConfig) { + return DEV_WIRE_ERR; + } + pConfig->u.i2c_dev.wire->beginTransmission(pConfig->u.i2c_dev.addr); + pConfig->u.i2c_dev.wire->write(reg_addr); + pConfig->u.i2c_dev.wire->write(reg_data, length); + return (pConfig->u.i2c_dev.wire->endTransmission() == 0) ? 0 : DEV_WIRE_ERR; + +} + + +void SensorInterfaces::bhy2_delay_us(uint32_t us, void *private_data) +{ + (void)private_data; + delayMicroseconds(us); +} + +#endif /*Arduino */ \ No newline at end of file diff --git a/components/SensorLib/src/bosch/common/bosch_interfaces.h b/components/SensorLib/src/bosch/common/bosch_interfaces.h new file mode 100644 index 0000000..cf69ae2 --- /dev/null +++ b/components/SensorLib/src/bosch/common/bosch_interfaces.h @@ -0,0 +1,61 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2022 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file bosch_interfaces.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-09 + * + */ +#pragma once + +#include "SensorLib.h" + +#if defined(ARDUINO) +class SensorInterfaces +{ +public: + static bool setup_interfaces(SensorLibConfigure config); + static void close_interfaces(SensorLibConfigure config); + static int8_t bhy2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr); + static int8_t bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr); + static int8_t bhy2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr); + static int8_t bhy2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr); + static void bhy2_delay_us(uint32_t us, void *private_data); + +private: + static SPISettings __spiSetting; +}; + +#endif + + + + + + + + + + + diff --git a/components/SensorLib/src/bosch/common/common.cpp b/components/SensorLib/src/bosch/common/common.cpp new file mode 100644 index 0000000..bb0a9f5 --- /dev/null +++ b/components/SensorLib/src/bosch/common/common.cpp @@ -0,0 +1,987 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file common.c + * @brief Common source file for the BHy260 examples + * @note Adapting Arduino based on BHY2-Sensor-API by lewis + */ + +#include "common.h" +#include "bosch/bhy2_parse.h" +#include "bosch/bhy2.h" + + +void time_to_s_ns(uint64_t time_ticks, uint32_t *s, uint32_t *ns, uint64_t *tns) +{ + *tns = time_ticks * 15625; /* timestamp is now in nanoseconds */ + *s = (uint32_t)(*tns / UINT64_C(1000000000)); + *ns = (uint32_t)(*tns - ((*s) * UINT64_C(1000000000))); +} + +const char *get_api_error(int8_t error_code) +{ + const char *ret; + + switch (error_code) { + case BHY2_OK: + ret = "[API Success]"; + break; + case BHY2_E_NULL_PTR: + ret = "[API Error] Null pointer"; + break; + case BHY2_E_INVALID_PARAM: + ret = "[API Error] Invalid parameter"; + break; + case BHY2_E_IO: + ret = "[API Error] IO error"; + break; + case BHY2_E_MAGIC: + ret = "[API Error] Invalid firmware"; + break; + case BHY2_E_TIMEOUT: + ret = "[API Error] Timed out"; + break; + case BHY2_E_BUFFER: + ret = "[API Error] Invalid buffer"; + break; + case BHY2_E_INVALID_FIFO_TYPE: + ret = "[API Error] Invalid FIFO type"; + break; + case BHY2_E_INVALID_EVENT_SIZE: + ret = "[API Error] Invalid Event size"; + break; + case BHY2_E_PARAM_NOT_SET: + ret = "[API Error] Parameter not set"; + break; + default: + ret = "[API Error] Unknown API error code"; + } + + return ret; +} + +const char *get_sensor_error_text(uint8_t sensor_error) +{ + const char *ret; + + switch (sensor_error) { + case 0x00: + break; + case 0x10: + ret = "[Sensor error] Bootloader reports: Firmware Expected Version Mismatch"; + break; + case 0x11: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Header CRC"; + break; + case 0x12: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: SHA Hash Mismatch"; + break; + case 0x13: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Image CRC"; + break; + case 0x14: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: ECDSA Signature Verification Failed"; + break; + case 0x15: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Public Key CRC"; + break; + case 0x16: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Signed Firmware Required"; + break; + case 0x17: + ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: FW Header Missing"; + break; + case 0x19: + ret = "[Sensor error] Bootloader reports: Unexpected Watchdog Reset"; + break; + case 0x1A: + ret = "[Sensor error] ROM Version Mismatch"; + break; + case 0x1B: + ret = "[Sensor error] Bootloader reports: Fatal Firmware Error"; + break; + case 0x1C: + ret = "[Sensor error] Chained Firmware Error: Next Payload Not Found"; + break; + case 0x1D: + ret = "[Sensor error] Chained Firmware Error: Payload Not Valid"; + break; + case 0x1E: + ret = "[Sensor error] Chained Firmware Error: Payload Entries Invalid"; + break; + case 0x1F: + ret = "[Sensor error] Bootloader reports: Bootloader Error: OTP CRC Invalid"; + break; + case 0x20: + ret = "[Sensor error] Firmware Init Failed"; + break; + case 0x21: + ret = "[Sensor error] Sensor Init Failed: Unexpected Device ID"; + break; + case 0x22: + ret = "[Sensor error] Sensor Init Failed: No Response from Device"; + break; + case 0x23: + ret = "[Sensor error] Sensor Init Failed: Unknown"; + break; + case 0x24: + ret = "[Sensor error] Sensor Error: No Valid Data"; + break; + case 0x25: + ret = "[Sensor error] Slow Sample Rate"; + break; + case 0x26: + ret = "[Sensor error] Data Overflow (saturated sensor data)"; + break; + case 0x27: + ret = "[Sensor error] Stack Overflow"; + break; + case 0x28: + ret = "[Sensor error] Insufficient Free RAM"; + break; + case 0x29: + ret = "[Sensor error] Sensor Init Failed: Driver Parsing Error"; + break; + case 0x2A: + ret = "[Sensor error] Too Many RAM Banks Required"; + break; + case 0x2B: + ret = "[Sensor error] Invalid Event Specified"; + break; + case 0x2C: + ret = "[Sensor error] More than 32 On Change"; + break; + case 0x2D: + ret = "[Sensor error] Firmware Too Large"; + break; + case 0x2F: + ret = "[Sensor error] Invalid RAM Banks"; + break; + case 0x30: + ret = "[Sensor error] Math Error"; + break; + case 0x40: + ret = "[Sensor error] Memory Error"; + break; + case 0x41: + ret = "[Sensor error] SWI3 Error"; + break; + case 0x42: + ret = "[Sensor error] SWI4 Error"; + break; + case 0x43: + ret = "[Sensor error] Illegal Instruction Error"; + break; + case 0x44: + ret = "[Sensor error] Bootloader reports: Unhandled Interrupt Error / Exception / Postmortem Available"; + break; + case 0x45: + ret = "[Sensor error] Invalid Memory Access"; + break; + case 0x50: + ret = "[Sensor error] Algorithm Error: BSX Init"; + break; + case 0x51: + ret = "[Sensor error] Algorithm Error: BSX Do Step"; + break; + case 0x52: + ret = "[Sensor error] Algorithm Error: Update Sub"; + break; + case 0x53: + ret = "[Sensor error] Algorithm Error: Get Sub"; + break; + case 0x54: + ret = "[Sensor error] Algorithm Error: Get Phys"; + break; + case 0x55: + ret = "[Sensor error] Algorithm Error: Unsupported Phys Rate"; + break; + case 0x56: + ret = "[Sensor error] Algorithm Error: Cannot find BSX Driver"; + break; + case 0x60: + ret = "[Sensor error] Sensor Self-Test Failure"; + break; + case 0x61: + ret = "[Sensor error] Sensor Self-Test X Axis Failure"; + break; + case 0x62: + ret = "[Sensor error] Sensor Self-Test Y Axis Failure"; + break; + case 0x64: + ret = "[Sensor error] Sensor Self-Test Z Axis Failure"; + break; + case 0x65: + ret = "[Sensor error] FOC Failure"; + break; + case 0x66: + ret = "[Sensor error] Sensor Busy"; + break; + case 0x6F: + ret = "[Sensor error] Self-Test or FOC Test Unsupported"; + break; + case 0x72: + ret = "[Sensor error] No Host Interrupt Set"; + break; + case 0x73: + ret = "[Sensor error] Event ID Passed to Host Interface Has No Known Size"; + break; + case 0x75: + ret = "[Sensor error] Host Download Channel Underflow (Host Read Too Fast)"; + break; + case 0x76: + ret = "[Sensor error] Host Upload Channel Overflow (Host Wrote Too Fast)"; + break; + case 0x77: + ret = "[Sensor error] Host Download Channel Empty"; + break; + case 0x78: + ret = "[Sensor error] DMA Error"; + break; + case 0x79: + ret = "[Sensor error] Corrupted Input Block Chain"; + break; + case 0x7A: + ret = "[Sensor error] Corrupted Output Block Chain"; + break; + case 0x7B: + ret = "[Sensor error] Buffer Block Manager Error"; + break; + case 0x7C: + ret = "[Sensor error] Input Channel Not Word Aligned"; + break; + case 0x7D: + ret = "[Sensor error] Too Many Flush Events"; + break; + case 0x7E: + ret = "[Sensor error] Unknown Host Channel Error"; + break; + case 0x81: + ret = "[Sensor error] Decimation Too Large"; + break; + case 0x90: + ret = "[Sensor error] Master SPI/I2C Queue Overflow"; + break; + case 0x91: + ret = "[Sensor error] SPI/I2C Callback Error"; + break; + case 0xA0: + ret = "[Sensor error] Timer Scheduling Error"; + break; + case 0xB0: + ret = "[Sensor error] Invalid GPIO for Host IRQ"; + break; + case 0xB1: + ret = "[Sensor error] Error Sending Initialized Meta Events"; + break; + case 0xC0: + ret = "[Sensor error] Bootloader reports: Command Error"; + break; + case 0xC1: + ret = "[Sensor error] Bootloader reports: Command Too Long"; + break; + case 0xC2: + ret = "[Sensor error] Bootloader reports: Command Buffer Overflow"; + break; + case 0xD0: + ret = "[Sensor error] User Mode Error: Sys Call Invalid"; + break; + case 0xD1: + ret = "[Sensor error] User Mode Error: Trap Invalid"; + break; + case 0xE1: + ret = "[Sensor error] Firmware Upload Failed: Firmware header corrupt"; + break; + case 0xE2: + ret = "[Sensor error] Sensor Data Injection: Invalid input stream"; + break; + default: + ret = "[Sensor error] Unknown error code"; + } + + return ret; +} + +const char *get_sensor_name(uint8_t sensor_id) +{ + const char *ret; + + switch (sensor_id) { + case BHY2_SENSOR_ID_ACC_PASS: + ret = "Accelerometer passthrough"; + break; + case BHY2_SENSOR_ID_ACC_RAW: + ret = "Accelerometer uncalibrated"; + break; + case BHY2_SENSOR_ID_ACC: + ret = "Accelerometer corrected"; + break; + case BHY2_SENSOR_ID_ACC_BIAS: + ret = "Accelerometer offset"; + break; + case BHY2_SENSOR_ID_ACC_WU: + ret = "Accelerometer corrected wake up"; + break; + case BHY2_SENSOR_ID_ACC_RAW_WU: + ret = "Accelerometer uncalibrated wake up"; + break; + case BHY2_SENSOR_ID_GYRO_PASS: + ret = "Gyroscope passthrough"; + break; + case BHY2_SENSOR_ID_GYRO_RAW: + ret = "Gyroscope uncalibrated"; + break; + case BHY2_SENSOR_ID_GYRO: + ret = "Gyroscope corrected"; + break; + case BHY2_SENSOR_ID_GYRO_BIAS: + ret = "Gyroscope offset"; + break; + case BHY2_SENSOR_ID_GYRO_WU: + ret = "Gyroscope wake up"; + break; + case BHY2_SENSOR_ID_GYRO_RAW_WU: + ret = "Gyroscope uncalibrated wake up"; + break; + case BHY2_SENSOR_ID_MAG_PASS: + ret = "Magnetometer passthrough"; + break; + case BHY2_SENSOR_ID_MAG_RAW: + ret = "Magnetometer uncalibrated"; + break; + case BHY2_SENSOR_ID_MAG: + ret = "Magnetometer corrected"; + break; + case BHY2_SENSOR_ID_MAG_BIAS: + ret = "Magnetometer offset"; + break; + case BHY2_SENSOR_ID_MAG_WU: + ret = "Magnetometer wake up"; + break; + case BHY2_SENSOR_ID_MAG_RAW_WU: + ret = "Magnetometer uncalibrated wake up"; + break; + case BHY2_SENSOR_ID_GRA: + ret = "Gravity vector"; + break; + case BHY2_SENSOR_ID_GRA_WU: + ret = "Gravity vector wake up"; + break; + case BHY2_SENSOR_ID_LACC: + ret = "Linear acceleration"; + break; + case BHY2_SENSOR_ID_LACC_WU: + ret = "Linear acceleration wake up"; + break; + case BHY2_SENSOR_ID_RV: + ret = "Rotation vector"; + break; + case BHY2_SENSOR_ID_RV_WU: + ret = "Rotation vector wake up"; + break; + case BHY2_SENSOR_ID_GAMERV: + ret = "Game rotation vector"; + break; + case BHY2_SENSOR_ID_GAMERV_WU: + ret = "Game rotation vector wake up"; + break; + case BHY2_SENSOR_ID_GEORV: + ret = "Geo-magnetic rotation vector"; + break; + case BHY2_SENSOR_ID_GEORV_WU: + ret = "Geo-magnetic rotation vector wake up"; + break; + case BHY2_SENSOR_ID_ORI: + ret = "Orientation"; + break; + case BHY2_SENSOR_ID_ORI_WU: + ret = "Orientation wake up"; + break; + case BHY2_SENSOR_ID_ACC_BIAS_WU: + ret = "Accelerometer offset wake up"; + break; + case BHY2_SENSOR_ID_GYRO_BIAS_WU: + ret = "Gyroscope offset wake up"; + break; + case BHY2_SENSOR_ID_MAG_BIAS_WU: + ret = "Magnetometer offset wake up"; + break; + case BHY2_SENSOR_ID_TEMP: + ret = "Temperature"; + break; + case BHY2_SENSOR_ID_BARO: + ret = "Barometer"; + break; + case BHY2_SENSOR_ID_HUM: + ret = "Humidity"; + break; + case BHY2_SENSOR_ID_GAS: + ret = "Gas"; + break; + case BHY2_SENSOR_ID_TEMP_WU: + ret = "Temperature wake up"; + break; + case BHY2_SENSOR_ID_BARO_WU: + ret = "Barometer wake up"; + break; + case BHY2_SENSOR_ID_HUM_WU: + ret = "Humidity wake up"; + break; + case BHY2_SENSOR_ID_GAS_WU: + ret = "Gas wake up"; + break; + case BHY2_SENSOR_ID_KLIO: + ret = "Klio"; + break; + case BHY2_SENSOR_ID_KLIO_LOG: + ret = "Klio log"; + break; + case BHY2_SENSOR_ID_SWIM: + ret = "Swim recognition"; + break; + case BHY2_SENSOR_ID_SI_ACCEL: + ret = "SI Accel"; + break; + case BHY2_SENSOR_ID_SI_GYROS: + ret = "SI Gyro"; + break; + case BHY2_SENSOR_ID_LIGHT: + ret = "Light"; + break; + case BHY2_SENSOR_ID_LIGHT_WU: + ret = "Light wake up"; + break; + case BHY2_SENSOR_ID_PROX: + ret = "Proximity"; + break; + case BHY2_SENSOR_ID_PROX_WU: + ret = "Proximity wake up"; + break; + case BHY2_SENSOR_ID_STC: + ret = "Step counter"; + break; + case BHY2_SENSOR_ID_STC_WU: + ret = "Step counter wake up"; + break; + case BHY2_SENSOR_ID_STC_LP: + ret = "Low Power Step counter"; + break; + case BHY2_SENSOR_ID_STC_LP_WU: + ret = "Low Power Step counter wake up"; + break; + case BHY2_SENSOR_ID_SIG: + ret = "Significant motion"; + break; + case BHY2_SENSOR_ID_STD: + ret = "Step detector"; + break; + case BHY2_SENSOR_ID_STD_WU: + ret = "Step detector wake up"; + break; + case BHY2_SENSOR_ID_TILT_DETECTOR: + ret = "Tilt detector"; + break; + case BHY2_SENSOR_ID_WAKE_GESTURE: + ret = "Wake gesture"; + break; + case BHY2_SENSOR_ID_GLANCE_GESTURE: + ret = "Glance gesture"; + break; + case BHY2_SENSOR_ID_PICKUP_GESTURE: + ret = "Pickup gesture"; + break; + case BHY2_SENSOR_ID_SIG_LP: + ret = "Low Power Significant motion"; + break; + case BHY2_SENSOR_ID_SIG_LP_WU: + ret = "Low Power Significant motion wake up"; + break; + case BHY2_SENSOR_ID_STD_LP: + ret = "Low Power Step detector"; + break; + case BHY2_SENSOR_ID_STD_LP_WU: + ret = "Low Power Step detector wake up"; + break; + case BHY2_SENSOR_ID_AR: + ret = "Activity recognition"; + break; + case BHY2_SENSOR_ID_EXCAMERA: + ret = "External camera trigger"; + break; + case BHY2_SENSOR_ID_GPS: + ret = "GPS"; + break; + case BHY2_SENSOR_ID_WRIST_TILT_GESTURE: + ret = "Wrist tilt gesture"; + break; + case BHY2_SENSOR_ID_DEVICE_ORI: + ret = "Device orientation"; + break; + case BHY2_SENSOR_ID_DEVICE_ORI_WU: + ret = "Device orientation wake up"; + break; + case BHY2_SENSOR_ID_STATIONARY_DET: + ret = "Stationary detect"; + break; + case BHY2_SENSOR_ID_ANY_MOTION_LP: + ret = "Low Power Any motion"; + break; + case BHY2_SENSOR_ID_ANY_MOTION_LP_WU: + ret = "Low Power Any motion wake up"; + break; + case BHI3_SENSOR_ID_NO_MOTION_LP_WU: + ret = "Low Power No Motion wake up"; + break; + case BHY2_SENSOR_ID_MOTION_DET: + ret = "Motion detect"; + break; + case BHI3_SENSOR_ID_AR_WEAR_WU: + ret = "Activity recognition for Wearables"; + break; + case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU: + ret = "Low Power Wrist Wear wake up"; + break; + case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU: + ret = "Low Power Wrist Gesture wake up"; + break; + case BHI3_SENSOR_ID_MULTI_TAP: + ret = "Multi Tap Detector"; + break; + case BHY2_SENSOR_ID_AIR_QUALITY: + ret = "Air Quality"; + break; + case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG: + ret = "Head Misalignment Calibrator"; + break; + case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q: + ret = "IMU Head Orientation Quaternion"; + break; + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q: + ret = "NDOF Head Orientation Quaternion"; + break; + case BHY2_SENSOR_ID_IMU_HEAD_ORI_E: + ret = "IMU Head Orientation Euler"; + break; + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E: + ret = "NDOF Head Orientation Euler"; + break; + default: + if ((sensor_id >= BHY2_SENSOR_ID_CUSTOM_START) && (sensor_id <= BHY2_SENSOR_ID_CUSTOM_END)) { + ret = "Custom sensor ID "; + } else { + ret = "Undefined sensor ID "; + } + } + + return ret; +} + +float get_sensor_default_scaling(uint8_t sensor_id) +{ + float scaling = -1.0f; + + switch (sensor_id) { + case BHY2_SENSOR_ID_ACC_PASS: + case BHY2_SENSOR_ID_ACC_RAW: + case BHY2_SENSOR_ID_ACC: + case BHY2_SENSOR_ID_ACC_BIAS: + case BHY2_SENSOR_ID_ACC_WU: + case BHY2_SENSOR_ID_ACC_RAW_WU: + case BHY2_SENSOR_ID_GRA: + case BHY2_SENSOR_ID_GRA_WU: + case BHY2_SENSOR_ID_LACC: + case BHY2_SENSOR_ID_LACC_WU: + case BHY2_SENSOR_ID_ACC_BIAS_WU: + scaling = 1.0f / 4096.0f; + break; + case BHY2_SENSOR_ID_GYRO_PASS: + case BHY2_SENSOR_ID_GYRO_RAW: + case BHY2_SENSOR_ID_GYRO: + case BHY2_SENSOR_ID_GYRO_BIAS: + case BHY2_SENSOR_ID_GYRO_WU: + case BHY2_SENSOR_ID_GYRO_RAW_WU: + case BHY2_SENSOR_ID_GYRO_BIAS_WU: + scaling = 2000.0f / 32768.0f; + break; + case BHY2_SENSOR_ID_MAG_PASS: + case BHY2_SENSOR_ID_MAG_RAW: + case BHY2_SENSOR_ID_MAG: + case BHY2_SENSOR_ID_MAG_BIAS: + case BHY2_SENSOR_ID_MAG_WU: + case BHY2_SENSOR_ID_MAG_RAW_WU: + case BHY2_SENSOR_ID_MAG_BIAS_WU: + scaling = 2500.0f / 32768.0f; + break; + case BHY2_SENSOR_ID_RV: + case BHY2_SENSOR_ID_RV_WU: + case BHY2_SENSOR_ID_GAMERV: + case BHY2_SENSOR_ID_GAMERV_WU: + case BHY2_SENSOR_ID_GEORV: + case BHY2_SENSOR_ID_GEORV_WU: + scaling = 1.0f / 16384.0f; + break; + case BHY2_SENSOR_ID_ORI: + case BHY2_SENSOR_ID_ORI_WU: + scaling = 360.0f / 32768.0f; + break; + case BHY2_SENSOR_ID_TEMP: + case BHY2_SENSOR_ID_TEMP_WU: + scaling = 1.0f / 100.0f; + break; + case BHY2_SENSOR_ID_BARO: + case BHY2_SENSOR_ID_BARO_WU: + scaling = 100.0f / 128.0f; + break; + case BHY2_SENSOR_ID_HUM: + case BHY2_SENSOR_ID_HUM_WU: + scaling = 1.0f; + break; + case BHY2_SENSOR_ID_GAS: + case BHY2_SENSOR_ID_GAS_WU: + scaling = 1.0f; + break; + case BHY2_SENSOR_ID_LIGHT: + case BHY2_SENSOR_ID_LIGHT_WU: + scaling = 10000.0f / 216.0f; + break; + case BHY2_SENSOR_ID_PROX: + case BHY2_SENSOR_ID_PROX_WU: + scaling = 1.0f; + break; + case BHY2_SENSOR_ID_SI_ACCEL: + case BHY2_SENSOR_ID_SI_GYROS: + + /* Scaling factor already applied in firmware*/ + break; + case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG: + case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q: + scaling = 1.0f / 16384.0f; /*2^14 -> 16384*/ + break; + case BHY2_SENSOR_ID_IMU_HEAD_ORI_E: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E: + scaling = 360.0f / 32768.0f; /*2^15 -> 32768*/ + break; + default: + scaling = -1.0f; /* Do not apply the scaling factor */ + } + + return scaling; +} + +const char *get_sensor_parse_format(uint8_t sensor_id) +{ + const char *ret; + + switch (sensor_id) { + case BHY2_SENSOR_ID_ACC_PASS: + case BHY2_SENSOR_ID_ACC_RAW: + case BHY2_SENSOR_ID_ACC: + case BHY2_SENSOR_ID_ACC_BIAS: + case BHY2_SENSOR_ID_ACC_BIAS_WU: + case BHY2_SENSOR_ID_ACC_WU: + case BHY2_SENSOR_ID_ACC_RAW_WU: + case BHY2_SENSOR_ID_GYRO_PASS: + case BHY2_SENSOR_ID_GYRO_RAW: + case BHY2_SENSOR_ID_GYRO: + case BHY2_SENSOR_ID_GYRO_BIAS: + case BHY2_SENSOR_ID_GYRO_BIAS_WU: + case BHY2_SENSOR_ID_GYRO_WU: + case BHY2_SENSOR_ID_GYRO_RAW_WU: + case BHY2_SENSOR_ID_MAG_PASS: + case BHY2_SENSOR_ID_MAG_RAW: + case BHY2_SENSOR_ID_MAG: + case BHY2_SENSOR_ID_MAG_BIAS: + case BHY2_SENSOR_ID_MAG_BIAS_WU: + case BHY2_SENSOR_ID_MAG_WU: + case BHY2_SENSOR_ID_MAG_RAW_WU: + case BHY2_SENSOR_ID_GRA: + case BHY2_SENSOR_ID_GRA_WU: + case BHY2_SENSOR_ID_LACC: + case BHY2_SENSOR_ID_LACC_WU: + ret = "s16,s16,s16"; + break; + case BHY2_SENSOR_ID_RV: + case BHY2_SENSOR_ID_RV_WU: + case BHY2_SENSOR_ID_GAMERV: + case BHY2_SENSOR_ID_GAMERV_WU: + case BHY2_SENSOR_ID_GEORV: + case BHY2_SENSOR_ID_GEORV_WU: + ret = "s16,s16,s16,s16,u16"; + break; + case BHY2_SENSOR_ID_ORI: + case BHY2_SENSOR_ID_ORI_WU: + ret = "s16,s16,s16"; + break; + case BHY2_SENSOR_ID_DEVICE_ORI: + case BHY2_SENSOR_ID_DEVICE_ORI_WU: + case BHY2_SENSOR_ID_HUM: + case BHY2_SENSOR_ID_HUM_WU: + case BHY2_SENSOR_ID_PROX: + case BHY2_SENSOR_ID_PROX_WU: + case BHY2_SENSOR_ID_EXCAMERA: + case BHI3_SENSOR_ID_MULTI_TAP: + ret = "u8"; + break; + case BHY2_SENSOR_ID_TEMP: + case BHY2_SENSOR_ID_TEMP_WU: + ret = "s16"; + break; + case BHY2_SENSOR_ID_BARO: + case BHY2_SENSOR_ID_BARO_WU: + ret = "u24"; + break; + case BHY2_SENSOR_ID_GAS: + case BHY2_SENSOR_ID_GAS_WU: + case BHY2_SENSOR_ID_STC: + case BHY2_SENSOR_ID_STC_WU: + case BHY2_SENSOR_ID_STC_LP: + case BHY2_SENSOR_ID_STC_LP_WU: + ret = "u32"; + break; + case BHY2_SENSOR_ID_KLIO: + ret = "u8,u8,u8,u8,u8,u8,f"; + break; + case BHY2_SENSOR_ID_SWIM: + ret = "u16,u16,u16,u16,u16,u16,u16"; + break; + case BHY2_SENSOR_ID_SI_ACCEL: + case BHY2_SENSOR_ID_SI_GYROS: + ret = "f,f,f"; + break; + case BHY2_SENSOR_ID_LIGHT: + case BHY2_SENSOR_ID_LIGHT_WU: + ret = "s16"; + break; + case BHY2_SENSOR_ID_SIG: + case BHY2_SENSOR_ID_STD: + case BHY2_SENSOR_ID_STD_WU: + case BHY2_SENSOR_ID_TILT_DETECTOR: + case BHY2_SENSOR_ID_WAKE_GESTURE: + case BHY2_SENSOR_ID_GLANCE_GESTURE: + case BHY2_SENSOR_ID_PICKUP_GESTURE: + case BHY2_SENSOR_ID_SIG_LP: + case BHY2_SENSOR_ID_SIG_LP_WU: + case BHY2_SENSOR_ID_STD_LP: + case BHY2_SENSOR_ID_STD_LP_WU: + case BHY2_SENSOR_ID_WRIST_TILT_GESTURE: + case BHY2_SENSOR_ID_STATIONARY_DET: + case BHY2_SENSOR_ID_ANY_MOTION_LP: + case BHY2_SENSOR_ID_ANY_MOTION_LP_WU: + case BHI3_SENSOR_ID_NO_MOTION_LP_WU: + case BHY2_SENSOR_ID_MOTION_DET: + case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU: + ret = ""; + break; + case BHY2_SENSOR_ID_AR: + case BHI3_SENSOR_ID_AR_WEAR_WU: + ret = "u16"; + break; + case BHY2_SENSOR_ID_GPS: + ret = "st"; + break; + case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU: + ret = "u8"; + break; + case BHY2_SENSOR_ID_AIR_QUALITY: + ret = "f32,f32,f32,f32,f32,f32,f32,u8"; + break; + case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG: + case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q: + ret = "s16,s16,s16,s16,u8"; + break; + + case BHY2_SENSOR_ID_IMU_HEAD_ORI_E: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E: + ret = "s16,s16,s16,u8"; + break; + default: + ret = ""; + } + + return ret; +} + +const char *get_sensor_axis_names(uint8_t sensor_id) +{ + const char *ret; + + switch (sensor_id) { + case BHY2_SENSOR_ID_ACC_PASS: + case BHY2_SENSOR_ID_ACC_RAW: + case BHY2_SENSOR_ID_ACC: + case BHY2_SENSOR_ID_ACC_BIAS: + case BHY2_SENSOR_ID_ACC_BIAS_WU: + case BHY2_SENSOR_ID_ACC_WU: + case BHY2_SENSOR_ID_ACC_RAW_WU: + case BHY2_SENSOR_ID_GYRO_PASS: + case BHY2_SENSOR_ID_GYRO_RAW: + case BHY2_SENSOR_ID_GYRO: + case BHY2_SENSOR_ID_GYRO_BIAS: + case BHY2_SENSOR_ID_GYRO_BIAS_WU: + case BHY2_SENSOR_ID_GYRO_WU: + case BHY2_SENSOR_ID_GYRO_RAW_WU: + case BHY2_SENSOR_ID_MAG_PASS: + case BHY2_SENSOR_ID_MAG_RAW: + case BHY2_SENSOR_ID_MAG: + case BHY2_SENSOR_ID_MAG_BIAS: + case BHY2_SENSOR_ID_MAG_BIAS_WU: + case BHY2_SENSOR_ID_MAG_WU: + case BHY2_SENSOR_ID_MAG_RAW_WU: + case BHY2_SENSOR_ID_GRA: + case BHY2_SENSOR_ID_GRA_WU: + case BHY2_SENSOR_ID_LACC: + case BHY2_SENSOR_ID_LACC_WU: + case BHY2_SENSOR_ID_SI_ACCEL: + case BHY2_SENSOR_ID_SI_GYROS: + ret = "x,y,z"; + break; + case BHY2_SENSOR_ID_RV: + case BHY2_SENSOR_ID_RV_WU: + case BHY2_SENSOR_ID_GAMERV: + case BHY2_SENSOR_ID_GAMERV_WU: + case BHY2_SENSOR_ID_GEORV: + case BHY2_SENSOR_ID_GEORV_WU: + ret = "x,y,z,w,ar"; + break; + case BHY2_SENSOR_ID_ORI: + case BHY2_SENSOR_ID_ORI_WU: + ret = "h,p,r"; + break; + case BHY2_SENSOR_ID_DEVICE_ORI: + case BHY2_SENSOR_ID_DEVICE_ORI_WU: + ret = "o"; + break; + case BHY2_SENSOR_ID_TEMP: + case BHY2_SENSOR_ID_TEMP_WU: + ret = "t"; + break; + case BHY2_SENSOR_ID_BARO: + case BHY2_SENSOR_ID_BARO_WU: + ret = "p"; + break; + case BHY2_SENSOR_ID_HUM: + case BHY2_SENSOR_ID_HUM_WU: + ret = "h"; + break; + case BHY2_SENSOR_ID_GAS: + case BHY2_SENSOR_ID_GAS_WU: + ret = "g"; + break; + case BHY2_SENSOR_ID_KLIO: + ret = "lin,lid,lpr,lcr,rin,rid,rc"; + break; + case BHY2_SENSOR_ID_SWIM: + ret = "d,lc,f,br,bu,ba,sc"; + break; + case BHY2_SENSOR_ID_LIGHT: + case BHY2_SENSOR_ID_LIGHT_WU: + ret = "l"; + break; + case BHY2_SENSOR_ID_PROX: + case BHY2_SENSOR_ID_PROX_WU: + ret = "p"; + break; + case BHY2_SENSOR_ID_STC: + case BHY2_SENSOR_ID_STC_WU: + case BHY2_SENSOR_ID_STC_LP: + case BHY2_SENSOR_ID_STC_LP_WU: + case BHY2_SENSOR_ID_EXCAMERA: + ret = "c"; + break; + case BHY2_SENSOR_ID_SIG: + case BHY2_SENSOR_ID_STD: + case BHY2_SENSOR_ID_STD_WU: + case BHY2_SENSOR_ID_TILT_DETECTOR: + case BHY2_SENSOR_ID_WAKE_GESTURE: + case BHY2_SENSOR_ID_GLANCE_GESTURE: + case BHY2_SENSOR_ID_PICKUP_GESTURE: + case BHY2_SENSOR_ID_SIG_LP: + case BHY2_SENSOR_ID_SIG_LP_WU: + case BHY2_SENSOR_ID_STD_LP: + case BHY2_SENSOR_ID_STD_LP_WU: + case BHY2_SENSOR_ID_WRIST_TILT_GESTURE: + case BHY2_SENSOR_ID_STATIONARY_DET: + case BHY2_SENSOR_ID_ANY_MOTION_LP: + case BHY2_SENSOR_ID_ANY_MOTION_LP_WU: + case BHI3_SENSOR_ID_NO_MOTION_LP_WU: + case BHY2_SENSOR_ID_MOTION_DET: + case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU: + ret = "e"; + break; + case BHY2_SENSOR_ID_AR: + case BHI3_SENSOR_ID_AR_WEAR_WU: + ret = "a"; + break; + case BHY2_SENSOR_ID_GPS: + ret = "g"; + break; + case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU: + ret = "wrist_gesture"; + break; + case BHI3_SENSOR_ID_MULTI_TAP: + ret = "taps"; + break; + case BHY2_SENSOR_ID_AIR_QUALITY: + ret = "t,h,g,i,si,c,v,a"; + break; + case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG: + case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q: + ret = "x,y,z,w,a"; + break; + case BHY2_SENSOR_ID_IMU_HEAD_ORI_E: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E: + ret = "h,p,r,a"; + break; + default: + ret = ""; + } + + return ret; +} + +void check_bhy2_api(unsigned int line, const char *func, int8_t val) +{ + int i = 3; + while (i--) { + + Serial.printf("BHI260 API failed at line %u. The function %s returned error code %d. %s\r\n", + line, + func, + val, + get_api_error(val)); + delay(1000); + } +} + diff --git a/components/SensorLib/src/bosch/common/common.h b/components/SensorLib/src/bosch/common/common.h new file mode 100644 index 0000000..ed25075 --- /dev/null +++ b/components/SensorLib/src/bosch/common/common.h @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file common.h + * @brief Common header file for the BHI260/BHA260 examples + * @note Adapting Arduino based on BHY2-Sensor-API by lewis + */ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include "bosch_interfaces.h" +#include "bosch/bhy2.h" +#include "bosch/bhi3.h" +#include "bosch/bhi3_multi_tap.h" +#include "bosch/bhy2_klio.h" +#include "bosch/bhy2_swim.h" +#include "bosch/bhy2_bsec.h" +#include "bosch/bhy2_head_tracker.h" + + +#define BHY2_ASSERT(x) if (x) check_bhy2_api(__LINE__, __FUNCTION__, x) + + + +void check_bhy2_api(unsigned int line, const char *func, int8_t val); +void time_to_s_ns(uint64_t time_ticks, uint32_t *s, uint32_t *ns, uint64_t *tns); +const char *get_api_error(int8_t error_code); +const char *get_sensor_error_text(uint8_t sensor_error); +const char *get_sensor_name(uint8_t sensor_id); +float get_sensor_default_scaling(uint8_t sensor_id); +const char *get_sensor_parse_format(uint8_t sensor_id); +const char *get_sensor_axis_names(uint8_t sensor_id); + + +#endif /* _COMMON_H_ */ diff --git a/components/SensorLib/src/bosch/firmware/BHI260AP.fw.h b/components/SensorLib/src/bosch/firmware/BHI260AP.fw.h new file mode 100644 index 0000000..3d90b0c --- /dev/null +++ b/components/SensorLib/src/bosch/firmware/BHI260AP.fw.h @@ -0,0 +1,8642 @@ +const unsigned char bhy2_firmware_image[] = { + 0x2b, 0x66, 0x00, 0x00, 0x00, 0x00, 0x67, 0x17, 0x8f, 0xfa, 0x20, 0xa5, + 0x64, 0xd4, 0xa3, 0x15, 0x17, 0x8c, 0x09, 0xcb, 0xfa, 0xed, 0xef, 0x7d, + 0x6c, 0x1c, 0xa8, 0xc2, 0x91, 0x52, 0xb0, 0xcb, 0x1d, 0x00, 0xef, 0xe6, + 0x22, 0x62, 0xfc, 0x48, 0x00, 0x00, 0x00, 0x00, 0x53, 0x0d, 0x30, 0xdd, + 0x75, 0x1b, 0x11, 0xbe, 0x74, 0xdd, 0x97, 0xe9, 0x40, 0x5a, 0x28, 0xb7, + 0x8e, 0x5f, 0xc1, 0x62, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x05, 0xd9, 0x7a, + 0xc0, 0x7a, 0x98, 0x9f, 0x98, 0x26, 0x49, 0xcc, 0xf2, 0x24, 0x67, 0x01, + 0x26, 0x6c, 0xd9, 0x4d, 0x90, 0x69, 0x01, 0x00, 0x8e, 0x8d, 0xfb, 0x79, + 0x78, 0x51, 0x01, 0x00, 0x2e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0xd1, 0xb9, 0xa4, 0x54, 0x92, 0x13, 0x00, 0xd0, 0x29, 0x10, 0x00, + 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, + 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, + 0xd0, 0x29, 0x10, 0x00, 0xdc, 0x9a, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, + 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, + 0x70, 0x5d, 0x01, 0x00, 0xd0, 0x29, 0x10, 0x00, 0x6c, 0x5f, 0x12, 0x00, + 0x0c, 0xb1, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, 0x68, 0xb3, 0x10, 0x00, + 0x68, 0xb3, 0x10, 0x00, 0x68, 0xb3, 0x10, 0x00, 0x80, 0x4d, 0x12, 0x00, + 0xa4, 0x6d, 0x12, 0x00, 0xa4, 0x6d, 0x12, 0x00, 0x64, 0xb6, 0x10, 0x00, + 0xec, 0xb6, 0x10, 0x00, 0x34, 0xb8, 0x10, 0x00, 0x68, 0x6a, 0x12, 0x00, + 0xd0, 0x29, 0x10, 0x00, 0x2c, 0x1a, 0x10, 0x00, 0xc8, 0xb5, 0x10, 0x00, + 0x10, 0x15, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, 0xd0, 0x29, 0x10, 0x00, + 0xb8, 0x18, 0x10, 0x00, 0x6c, 0x19, 0x10, 0x00, 0x4c, 0x6e, 0x12, 0x00, + 0x4c, 0x6e, 0x12, 0x00, 0x4c, 0x6e, 0x12, 0x00, 0x34, 0xcd, 0x12, 0x00, + 0xc1, 0x02, 0xcf, 0xf2, 0x5d, 0x07, 0x4f, 0xf6, 0x1d, 0x05, 0x00, 0x01, + 0x81, 0x06, 0x00, 0x01, 0x4d, 0x06, 0xcf, 0xf7, 0x69, 0x06, 0xcf, 0xf7, + 0x85, 0x06, 0xcf, 0xf7, 0xd9, 0x07, 0xcf, 0xf7, 0xe5, 0x05, 0xcf, 0xf9, + 0x35, 0x06, 0xcf, 0xf9, 0x11, 0x07, 0xcf, 0xf9, 0xa1, 0x01, 0x0f, 0xfa, + 0xa9, 0x01, 0x0f, 0xfa, 0x95, 0x02, 0x0f, 0xfa, 0x09, 0x06, 0x0f, 0xfa, + 0x51, 0x06, 0x00, 0x08, 0x19, 0x01, 0x4f, 0xfa, 0xb5, 0x04, 0x4f, 0xfa, + 0xf5, 0x04, 0x4f, 0xfa, 0x5d, 0x05, 0x4f, 0xfa, 0x01, 0x04, 0xc0, 0x00, + 0x59, 0x06, 0x4f, 0xfa, 0x71, 0x06, 0x4f, 0xfa, 0x35, 0x06, 0x00, 0x08, + 0xb5, 0x01, 0x8f, 0xfa, 0xd9, 0x01, 0x8f, 0xfa, 0x89, 0x07, 0x00, 0x08, + 0x41, 0x02, 0x8f, 0xfa, 0x65, 0x03, 0x8f, 0xfa, 0xbd, 0x03, 0x8f, 0xfa, + 0x15, 0x04, 0x8f, 0xfa, 0x61, 0x04, 0x8f, 0xfa, 0x79, 0x04, 0x8f, 0xfa, + 0xa5, 0x07, 0x00, 0x08, 0xf9, 0x04, 0x8f, 0xfa, 0x01, 0x06, 0x40, 0x01, + 0x4d, 0x06, 0x8f, 0xfa, 0x81, 0x07, 0x8f, 0xfa, 0xa5, 0x01, 0xcf, 0xfa, + 0xa5, 0x02, 0xcf, 0xfa, 0x6d, 0x03, 0xcf, 0xfa, 0x79, 0x06, 0xcf, 0xfa, + 0xdd, 0x02, 0x40, 0x01, 0x35, 0x00, 0x0f, 0xfb, 0x75, 0x00, 0x0f, 0xfb, + 0xa9, 0x00, 0x0f, 0xfb, 0xd9, 0x00, 0x0f, 0xfb, 0xe1, 0x00, 0x0f, 0xfb, + 0xed, 0x00, 0x0f, 0xfb, 0xf5, 0x00, 0x0f, 0xfb, 0x05, 0x01, 0x0f, 0xfb, + 0x49, 0x02, 0x0f, 0xfb, 0x4d, 0x02, 0x0f, 0xfb, 0x55, 0x02, 0x0f, 0xfb, + 0x65, 0x02, 0x0f, 0xfb, 0x75, 0x02, 0x0f, 0xfb, 0x81, 0x02, 0x0f, 0xfb, + 0x75, 0x03, 0x0f, 0xfb, 0xad, 0x04, 0x0f, 0xfb, 0xd5, 0x04, 0x0f, 0xfb, + 0xed, 0x04, 0x0f, 0xfb, 0xf5, 0x04, 0x0f, 0xfb, 0x19, 0x05, 0x0f, 0xfb, + 0xf1, 0x03, 0x40, 0x01, 0x21, 0x06, 0x0f, 0xfb, 0x29, 0x02, 0x40, 0x08, + 0xd9, 0x06, 0x0f, 0xfb, 0x29, 0x01, 0x4f, 0xfb, 0x05, 0x05, 0xc0, 0x00, + 0x15, 0x02, 0x4f, 0xfb, 0xf1, 0x02, 0x4f, 0xfb, 0xad, 0x00, 0x80, 0x00, + 0x65, 0x00, 0x80, 0x00, 0xf5, 0x07, 0x40, 0x00, 0x39, 0x00, 0x80, 0x00, + 0x11, 0x00, 0x80, 0x00, 0x79, 0x00, 0x80, 0x00, 0xd9, 0x00, 0x80, 0x00, + 0xb5, 0x00, 0x80, 0x00, 0xf5, 0x05, 0x4f, 0xfb, 0xb9, 0x06, 0x4f, 0xfb, + 0xfd, 0x06, 0x4f, 0xfb, 0x91, 0x03, 0x40, 0x01, 0x51, 0x06, 0x8f, 0xfb, + 0x29, 0x02, 0xcf, 0xfb, 0xb5, 0x02, 0x0f, 0xfc, 0x35, 0x04, 0x0f, 0xfc, + 0x81, 0x04, 0x0f, 0xfc, 0x8d, 0x04, 0x0f, 0xfc, 0x61, 0x05, 0x0f, 0xfc, + 0x0d, 0x01, 0x8f, 0xfd, 0xa1, 0x01, 0x8f, 0xfd, 0xb1, 0x01, 0x8f, 0xfd, + 0xc1, 0x01, 0x8f, 0xfd, 0x51, 0x02, 0x40, 0x01, 0x91, 0x03, 0x8f, 0xfd, + 0x09, 0x05, 0x8f, 0xfd, 0x45, 0x04, 0xc0, 0x00, 0x99, 0x00, 0xcf, 0xfd, + 0xd9, 0x03, 0xc0, 0x00, 0x51, 0x02, 0x0f, 0xef, 0xbd, 0x04, 0xcf, 0xfd, + 0x25, 0x05, 0xcf, 0xfd, 0x6d, 0x06, 0xcf, 0xfd, 0xa5, 0x06, 0xcf, 0xfd, + 0x5d, 0x07, 0xcf, 0xfd, 0xf5, 0x07, 0xcf, 0xfd, 0x29, 0x00, 0x0f, 0xfe, + 0xe1, 0x01, 0x40, 0x01, 0x11, 0x02, 0x0f, 0xfe, 0xa1, 0x02, 0x0f, 0xfe, + 0x39, 0x03, 0x0f, 0xfe, 0xc9, 0x03, 0x0f, 0xfe, 0xb1, 0x04, 0x0f, 0xfe, + 0x71, 0x07, 0x0f, 0xfe, 0xb1, 0x02, 0x00, 0x09, 0xfd, 0x07, 0x0f, 0xfe, + 0x0d, 0x00, 0x4f, 0xfe, 0x61, 0x00, 0x4f, 0xfe, 0xb5, 0x00, 0x4f, 0xfe, + 0xb9, 0x00, 0x4f, 0xfe, 0xcd, 0x00, 0x4f, 0xfe, 0xf5, 0x00, 0x4f, 0xfe, + 0x05, 0x02, 0x4f, 0xfe, 0xd9, 0x05, 0x8f, 0xfe, 0x65, 0x06, 0x8f, 0xfe, + 0x7d, 0x06, 0x8f, 0xfe, 0x9d, 0x00, 0x40, 0x01, 0x35, 0x07, 0x8f, 0xfe, + 0x49, 0x07, 0x8f, 0xfe, 0x6d, 0x07, 0x8f, 0xfe, 0xe5, 0x07, 0x8f, 0xfe, + 0x15, 0x00, 0xcf, 0xfe, 0x9d, 0x00, 0xcf, 0xfe, 0xb5, 0x00, 0xcf, 0xfe, + 0xe5, 0x00, 0xcf, 0xfe, 0x59, 0x01, 0xcf, 0xfe, 0x05, 0x02, 0xcf, 0xfe, + 0x1d, 0x02, 0xcf, 0xfe, 0x6d, 0x02, 0x00, 0x09, 0x79, 0x02, 0x00, 0x09, + 0x85, 0x02, 0x00, 0x09, 0x51, 0x03, 0x00, 0x09, 0x4d, 0x02, 0xcf, 0xfe, + 0x9d, 0x02, 0xcf, 0xfe, 0xa5, 0x02, 0xcf, 0xfe, 0x99, 0x03, 0x00, 0x09, + 0x4d, 0x03, 0xcf, 0xfe, 0xb5, 0x03, 0xcf, 0xfe, 0x19, 0x04, 0xcf, 0xfe, + 0x81, 0x04, 0xcf, 0xfe, 0xa9, 0x04, 0xcf, 0xfe, 0xe5, 0x03, 0x00, 0x09, + 0x0d, 0x04, 0x00, 0x09, 0xd9, 0x06, 0x00, 0x01, 0xd9, 0x06, 0xcf, 0xfe, + 0x99, 0x07, 0xcf, 0xfe, 0xb1, 0x04, 0x00, 0x09, 0xe5, 0x04, 0x00, 0x09, + 0x0d, 0x05, 0x00, 0x09, 0x7d, 0x00, 0x0f, 0xff, 0xbd, 0x00, 0x0f, 0xff, + 0xb1, 0x05, 0x00, 0x01, 0x51, 0x06, 0x00, 0x09, 0x81, 0x02, 0x0f, 0xff, + 0x85, 0x02, 0x0f, 0xff, 0xa9, 0x02, 0xc0, 0x00, 0xcd, 0x02, 0x0f, 0xff, + 0x19, 0x03, 0x0f, 0xff, 0x19, 0x03, 0x0f, 0xff, 0x85, 0x05, 0x40, 0x00, + 0x6d, 0x06, 0x4f, 0xff, 0x35, 0x00, 0x8f, 0xff, 0x59, 0x02, 0xcf, 0xef, + 0x0d, 0x03, 0xcf, 0xef, 0xad, 0x03, 0xcf, 0xef, 0x01, 0x04, 0xcf, 0xef, + 0x8d, 0x04, 0xcf, 0xef, 0x9d, 0x04, 0xcf, 0xef, 0x11, 0x05, 0xcf, 0xef, + 0x59, 0x05, 0xcf, 0xef, 0x69, 0x05, 0xcf, 0xef, 0x39, 0x00, 0x00, 0x02, + 0xc5, 0x00, 0x00, 0x02, 0xdd, 0x01, 0x00, 0x02, 0xe1, 0x02, 0x00, 0x02, + 0xa5, 0x03, 0x00, 0x02, 0xf5, 0x03, 0x00, 0x02, 0xf1, 0x04, 0x00, 0x02, + 0x71, 0x05, 0x00, 0x02, 0x7d, 0x03, 0x0f, 0xf0, 0x71, 0x06, 0x00, 0x02, + 0x89, 0x07, 0x00, 0x02, 0xbd, 0x07, 0x00, 0x02, 0x91, 0x00, 0x40, 0x02, + 0x6d, 0x02, 0x40, 0x02, 0x31, 0x00, 0x4f, 0xf0, 0x5d, 0x01, 0x4f, 0xf0, + 0xf1, 0x02, 0x40, 0x02, 0x51, 0x07, 0x8f, 0xf0, 0x21, 0x00, 0xcf, 0xf0, + 0x45, 0x00, 0xcf, 0xf0, 0xb1, 0x01, 0xcf, 0xf0, 0xfd, 0x06, 0xcf, 0xf0, + 0x05, 0x07, 0xcf, 0xf0, 0xdd, 0x00, 0x0f, 0xf1, 0xe9, 0x00, 0x0f, 0xf1, + 0x51, 0x00, 0x80, 0x02, 0x79, 0x05, 0x0f, 0xf1, 0x31, 0x06, 0x0f, 0xf1, + 0x39, 0x06, 0x0f, 0xf1, 0x49, 0x06, 0x0f, 0xf1, 0x2d, 0x00, 0x4f, 0xf1, + 0x81, 0x00, 0x4f, 0xf1, 0x71, 0x01, 0xc0, 0x02, 0xe1, 0x02, 0xc0, 0x02, + 0x65, 0x03, 0xc0, 0x02, 0xed, 0x03, 0xc0, 0x02, 0x0d, 0x04, 0xc0, 0x02, + 0x0d, 0x04, 0xc0, 0x02, 0xdd, 0x02, 0x4f, 0xf1, 0x91, 0x04, 0xc0, 0x02, + 0x85, 0x04, 0x4f, 0xf1, 0x6d, 0x07, 0x4f, 0xf1, 0x71, 0x07, 0x4f, 0xf1, + 0x79, 0x07, 0x4f, 0xf1, 0x7d, 0x07, 0x4f, 0xf1, 0x81, 0x07, 0x4f, 0xf1, + 0x9d, 0x07, 0x4f, 0xf1, 0xad, 0x07, 0x4f, 0xf1, 0xb1, 0x07, 0x4f, 0xf1, + 0xb1, 0x07, 0x4f, 0xf1, 0x49, 0x01, 0x8f, 0xf1, 0xa1, 0x01, 0x8f, 0xf1, + 0xdd, 0x01, 0x8f, 0xf1, 0x7d, 0x02, 0x8f, 0xf1, 0x79, 0x03, 0x8f, 0xf1, + 0x05, 0x04, 0x8f, 0xf1, 0xc9, 0x03, 0x00, 0x03, 0xc9, 0x06, 0x8f, 0xf1, + 0x61, 0x07, 0x8f, 0xf1, 0xf9, 0x07, 0x8f, 0xf1, 0xd5, 0x00, 0xcf, 0xf1, + 0x99, 0x02, 0xcf, 0xf1, 0xa1, 0x02, 0xcf, 0xf1, 0xbd, 0x03, 0xcf, 0xf1, + 0x29, 0x04, 0xcf, 0xf1, 0x89, 0x04, 0xcf, 0xf1, 0xa9, 0x05, 0x00, 0x03, + 0xcd, 0x05, 0xcf, 0xf1, 0x6d, 0x06, 0xcf, 0xf1, 0x15, 0x07, 0xcf, 0xf1, + 0xb1, 0x07, 0xcf, 0xf1, 0x01, 0x02, 0x0f, 0xf2, 0x05, 0x02, 0x0f, 0xf2, + 0x4d, 0x02, 0x0f, 0xf2, 0xd9, 0x02, 0x0f, 0xf2, 0x3d, 0x03, 0x0f, 0xf2, + 0x89, 0x03, 0x0f, 0xf2, 0xf9, 0x03, 0x0f, 0xf2, 0x19, 0x04, 0x0f, 0xf2, + 0x85, 0x06, 0x00, 0x03, 0xc5, 0x07, 0x00, 0x03, 0x39, 0x00, 0x40, 0x03, + 0x91, 0x01, 0x40, 0x03, 0xb5, 0x02, 0x40, 0x03, 0xa9, 0x03, 0x40, 0x03, + 0x85, 0x04, 0x40, 0x03, 0x41, 0x02, 0x80, 0x03, 0x41, 0x02, 0x80, 0x03, + 0x71, 0x02, 0x80, 0x03, 0x39, 0x03, 0x80, 0x03, 0xad, 0x03, 0x80, 0x03, + 0xfd, 0x03, 0x80, 0x03, 0x09, 0x06, 0x8f, 0xf2, 0x21, 0x06, 0x8f, 0xf2, + 0xfd, 0x07, 0xcf, 0xf2, 0xd1, 0x06, 0x80, 0x03, 0x4d, 0x01, 0x0f, 0xf3, + 0x71, 0x01, 0x0f, 0xf3, 0x81, 0x01, 0x0f, 0xf3, 0xb5, 0x01, 0x0f, 0xf3, + 0xb9, 0x01, 0x0f, 0xf3, 0xc5, 0x01, 0x0f, 0xf3, 0x11, 0x02, 0x0f, 0xf3, + 0xbd, 0x07, 0x80, 0x03, 0xe9, 0x07, 0x80, 0x03, 0x9d, 0x00, 0xc0, 0x03, + 0xd5, 0x01, 0xc0, 0x03, 0x55, 0x02, 0xc0, 0x03, 0xc5, 0x02, 0xc0, 0x03, + 0xe5, 0x02, 0xc0, 0x03, 0x09, 0x03, 0xc0, 0x03, 0x31, 0x03, 0xc0, 0x03, + 0x51, 0x05, 0xc0, 0x03, 0x85, 0x06, 0xc0, 0x03, 0x39, 0x01, 0x00, 0x04, + 0x01, 0x02, 0x00, 0x04, 0x79, 0x02, 0x00, 0x04, 0x79, 0x03, 0x00, 0x04, + 0x79, 0x03, 0x00, 0x04, 0x15, 0x06, 0x00, 0x04, 0xdd, 0x04, 0x8f, 0xf3, + 0x59, 0x05, 0x8f, 0xf3, 0x09, 0x06, 0x8f, 0xf3, 0x6d, 0x06, 0x8f, 0xf3, + 0x7d, 0x06, 0x8f, 0xf3, 0xfd, 0x06, 0x8f, 0xf3, 0x11, 0x07, 0x8f, 0xf3, + 0x85, 0x07, 0x8f, 0xf3, 0x55, 0x04, 0x40, 0x04, 0x31, 0x05, 0x40, 0x04, + 0x7d, 0x07, 0x40, 0x04, 0x41, 0x01, 0x80, 0x04, 0xdd, 0x01, 0x80, 0x04, + 0x2d, 0x03, 0x80, 0x04, 0x91, 0x03, 0x80, 0x04, 0xf1, 0x06, 0x80, 0x04, + 0xb1, 0x03, 0xc0, 0x04, 0x5d, 0x04, 0xc0, 0x04, 0x99, 0x05, 0xc0, 0x04, + 0x31, 0x01, 0x4f, 0xf4, 0x69, 0x01, 0x4f, 0xf4, 0x15, 0x03, 0x4f, 0xf4, + 0xe9, 0x04, 0x4f, 0xf4, 0x49, 0x05, 0x4f, 0xf4, 0x85, 0x06, 0x4f, 0xf4, + 0x49, 0x07, 0x4f, 0xf4, 0x81, 0x00, 0x8f, 0xf4, 0x85, 0x00, 0x8f, 0xf4, + 0x1d, 0x01, 0x8f, 0xf4, 0x39, 0x01, 0x8f, 0xf4, 0x31, 0x02, 0x8f, 0xf4, + 0xcd, 0x04, 0x8f, 0xf4, 0x65, 0x05, 0x8f, 0xf4, 0x19, 0x07, 0x8f, 0xf4, + 0x01, 0x01, 0x0f, 0xf5, 0x05, 0x00, 0x00, 0x05, 0xe5, 0x02, 0x0f, 0xf5, + 0x09, 0x03, 0x0f, 0xf5, 0x19, 0x03, 0x0f, 0xf5, 0xcd, 0x03, 0x0f, 0xf5, + 0xd1, 0x03, 0x0f, 0xf5, 0xdd, 0x03, 0x0f, 0xf5, 0xb1, 0x04, 0x0f, 0xf5, + 0xd5, 0x01, 0x00, 0x05, 0x59, 0x02, 0x00, 0x05, 0xf5, 0x02, 0x00, 0x05, + 0x55, 0x03, 0x00, 0x05, 0xb1, 0x04, 0x00, 0x05, 0x1d, 0x05, 0x00, 0x05, + 0x1d, 0x05, 0x00, 0x05, 0x2d, 0x05, 0x00, 0x05, 0xa9, 0x05, 0x00, 0x05, + 0x01, 0x07, 0x00, 0x05, 0xcd, 0x00, 0xcf, 0xf5, 0xe1, 0x00, 0xcf, 0xf5, + 0x31, 0x01, 0xcf, 0xf5, 0xfd, 0x01, 0xcf, 0xf5, 0xed, 0x02, 0xcf, 0xf5, + 0x81, 0x03, 0xcf, 0xf5, 0xe9, 0x03, 0xcf, 0xf5, 0x45, 0x04, 0xcf, 0xf5, + 0x25, 0x05, 0xcf, 0xf5, 0xed, 0x01, 0x0f, 0xf6, 0x09, 0x02, 0x0f, 0xf6, + 0x85, 0x02, 0x0f, 0xf6, 0xc1, 0x02, 0x0f, 0xf6, 0xf9, 0x02, 0x0f, 0xf6, + 0x25, 0x07, 0x4f, 0xf6, 0x7d, 0x07, 0x4f, 0xf6, 0xc1, 0x07, 0x4f, 0xf6, + 0x55, 0x00, 0x8f, 0xf6, 0xc5, 0x01, 0x8f, 0xf6, 0x39, 0x02, 0x8f, 0xf6, + 0x49, 0x02, 0x8f, 0xf6, 0xe9, 0x02, 0x8f, 0xf6, 0xf1, 0x02, 0x8f, 0xf6, + 0xbd, 0x03, 0x8f, 0xf6, 0xc5, 0x05, 0x40, 0x05, 0xc9, 0x06, 0x40, 0x05, + 0xb5, 0x02, 0x80, 0x05, 0x0d, 0x03, 0x80, 0x05, 0x31, 0x03, 0x80, 0x05, + 0x11, 0x05, 0x80, 0x05, 0x5d, 0x06, 0x80, 0x05, 0x41, 0x00, 0xc0, 0x05, + 0xd9, 0x02, 0xcf, 0xf6, 0xa5, 0x03, 0xcf, 0xf6, 0xcd, 0x05, 0xcf, 0xf6, + 0x61, 0x06, 0xcf, 0xf6, 0x71, 0x06, 0xcf, 0xf6, 0x29, 0x07, 0xcf, 0xf6, + 0x31, 0x07, 0xcf, 0xf6, 0x21, 0x00, 0x0f, 0xf7, 0xe1, 0x00, 0x0f, 0xf7, + 0x65, 0x01, 0x0f, 0xf7, 0x21, 0x03, 0x0f, 0xf7, 0x4d, 0x03, 0x0f, 0xf7, + 0xb1, 0x03, 0x0f, 0xf7, 0xc1, 0x03, 0x0f, 0xf7, 0x91, 0x04, 0x0f, 0xf7, + 0xad, 0x04, 0x0f, 0xf7, 0xb1, 0x05, 0x0f, 0xf7, 0x21, 0x06, 0x0f, 0xf7, + 0xfd, 0x07, 0x80, 0x05, 0x91, 0x07, 0x0f, 0xf7, 0xe5, 0x07, 0x0f, 0xf7, + 0x05, 0x00, 0x4f, 0xf7, 0xa1, 0x00, 0x4f, 0xf7, 0xb1, 0x00, 0x4f, 0xf7, + 0x61, 0x01, 0x4f, 0xf7, 0x75, 0x01, 0x4f, 0xf7, 0xa1, 0x01, 0x4f, 0xf7, + 0xc5, 0x01, 0x4f, 0xf7, 0x19, 0x02, 0x4f, 0xf7, 0x89, 0x02, 0x4f, 0xf7, + 0xc1, 0x02, 0x4f, 0xf7, 0xed, 0x00, 0xc0, 0x05, 0xc1, 0x01, 0xc0, 0x05, + 0x7d, 0x04, 0xc0, 0x05, 0x09, 0x05, 0xc0, 0x05, 0x19, 0x05, 0xc0, 0x05, + 0x05, 0x06, 0xc0, 0x05, 0x05, 0x06, 0xc0, 0x05, 0x65, 0x07, 0xc0, 0x05, + 0x65, 0x07, 0xc0, 0x05, 0x7d, 0x07, 0xc0, 0x05, 0x1d, 0x07, 0x8f, 0xf7, + 0x5d, 0x07, 0x8f, 0xf7, 0xdd, 0x00, 0xcf, 0xf7, 0x7d, 0x01, 0xcf, 0xf7, + 0xf1, 0x01, 0x00, 0x06, 0xa5, 0x02, 0x00, 0x06, 0x1d, 0x05, 0xcf, 0xf7, + 0xdd, 0x05, 0xcf, 0xf7, 0x7d, 0x04, 0x00, 0x06, 0x45, 0x07, 0x00, 0x06, + 0x51, 0x00, 0x0f, 0xf8, 0xa1, 0x00, 0x0f, 0xf8, 0x39, 0x01, 0x0f, 0xf8, + 0x11, 0x02, 0x0f, 0xf8, 0x79, 0x02, 0x0f, 0xf8, 0x45, 0x03, 0x0f, 0xf8, + 0x8d, 0x05, 0x0f, 0xf8, 0xe5, 0x05, 0x0f, 0xf8, 0x6d, 0x06, 0x0f, 0xf8, + 0xdd, 0x06, 0x0f, 0xf8, 0xfd, 0x07, 0x00, 0x06, 0x3d, 0x00, 0x4f, 0xf8, + 0x45, 0x00, 0x4f, 0xf8, 0x59, 0x00, 0x4f, 0xf8, 0x41, 0x01, 0x40, 0x06, + 0x51, 0x01, 0x4f, 0xf8, 0x59, 0x03, 0x40, 0x06, 0x55, 0x05, 0x40, 0x06, + 0x01, 0x05, 0x4f, 0xf8, 0x89, 0x00, 0x8f, 0xf8, 0x05, 0x00, 0x80, 0x06, + 0x01, 0x01, 0x8f, 0xf8, 0x61, 0x00, 0x80, 0x06, 0xad, 0x01, 0x8f, 0xf8, + 0x21, 0x02, 0x8f, 0xf8, 0x71, 0x02, 0x8f, 0xf8, 0xc1, 0x02, 0x8f, 0xf8, + 0xdd, 0x02, 0x8f, 0xf8, 0xed, 0x02, 0x8f, 0xf8, 0x35, 0x03, 0x8f, 0xf8, + 0xe1, 0x03, 0x8f, 0xf8, 0xf1, 0x03, 0x8f, 0xf8, 0xf5, 0x03, 0x8f, 0xf8, + 0x21, 0x04, 0x8f, 0xf8, 0x3d, 0x04, 0x8f, 0xf8, 0x05, 0x02, 0x80, 0x06, + 0x79, 0x04, 0x8f, 0xf8, 0xf9, 0x07, 0x00, 0x07, 0xb5, 0x00, 0x40, 0x07, + 0xfd, 0x00, 0x0f, 0xf9, 0xb5, 0x01, 0x0f, 0xf9, 0xd9, 0x00, 0x40, 0x07, + 0x35, 0x06, 0x40, 0x07, 0x71, 0x05, 0x0f, 0xf9, 0x31, 0x06, 0x40, 0x07, + 0xad, 0x07, 0x40, 0x07, 0x19, 0x04, 0x8f, 0xf9, 0xb9, 0x04, 0x8f, 0xf9, + 0xc9, 0x04, 0x8f, 0xf9, 0x81, 0x03, 0xc0, 0x07, 0x09, 0x05, 0x8f, 0xf9, + 0x09, 0x05, 0x8f, 0xf9, 0xad, 0x05, 0x8f, 0xf9, 0xd1, 0x05, 0x8f, 0xf9, + 0xed, 0x06, 0x8f, 0xf9, 0xd5, 0x03, 0xc0, 0x07, 0x55, 0x03, 0xcf, 0xf9, + 0x05, 0x04, 0xc0, 0x07, 0x81, 0x03, 0xcf, 0xf9, 0xed, 0x03, 0xcf, 0xf9, + 0x29, 0x04, 0xcf, 0xf9, 0x39, 0x04, 0xcf, 0xf9, 0xa5, 0x04, 0xc0, 0x07, + 0x69, 0x04, 0xcf, 0xf9, 0xbd, 0x04, 0xc0, 0x07, 0xe9, 0x04, 0xc0, 0x07, + 0xfd, 0x04, 0xcf, 0xf9, 0x19, 0x05, 0xcf, 0xf9, 0x15, 0x05, 0xc0, 0x07, + 0x41, 0x05, 0xcf, 0xf9, 0x29, 0x05, 0xc0, 0x07, 0x65, 0x05, 0xcf, 0xf9, + 0x69, 0x05, 0xc0, 0x07, 0x89, 0x05, 0xcf, 0xf9, 0x9d, 0x05, 0xcf, 0xf9, + 0xc1, 0x05, 0xcf, 0xf9, 0x75, 0x05, 0xc0, 0x07, 0xb9, 0x06, 0xcf, 0xf9, + 0x01, 0x07, 0xcf, 0xf9, 0x19, 0x07, 0xcf, 0xf9, 0x4d, 0x07, 0xcf, 0xf9, + 0x95, 0x07, 0xcf, 0xf9, 0xa9, 0x07, 0xcf, 0xf9, 0x31, 0x06, 0xc0, 0x07, + 0x3d, 0x06, 0x0f, 0xfa, 0x89, 0x07, 0x0f, 0xfa, 0xe1, 0x07, 0x0f, 0xfa, + 0xf9, 0x07, 0x0f, 0xfa, 0x2d, 0x00, 0x4f, 0xfa, 0x2d, 0x00, 0x4f, 0xfa, + 0x55, 0x07, 0xc0, 0x07, 0x6d, 0x07, 0xc0, 0x07, 0xfd, 0x04, 0x8f, 0xfa, + 0x15, 0x05, 0x8f, 0xfa, 0x41, 0x05, 0x8f, 0xfa, 0x35, 0x00, 0x00, 0x08, + 0x4d, 0x00, 0x00, 0x08, 0xd5, 0x05, 0x8f, 0xfa, 0x51, 0x07, 0x8f, 0xfa, + 0x69, 0x07, 0x8f, 0xfa, 0x9d, 0x07, 0x8f, 0xfa, 0x39, 0x02, 0x00, 0x08, + 0x0d, 0x06, 0xcf, 0xfa, 0x25, 0x06, 0xcf, 0xfa, 0x8d, 0x02, 0x00, 0x08, + 0x4d, 0x01, 0x8f, 0xfb, 0x65, 0x01, 0x8f, 0xfb, 0x89, 0x03, 0xcf, 0xfb, + 0x91, 0x03, 0xcf, 0xfb, 0xc5, 0x03, 0xcf, 0xfb, 0x59, 0x06, 0xcf, 0xfb, + 0x71, 0x06, 0xcf, 0xfb, 0xa9, 0x06, 0xcf, 0xfb, 0xc1, 0x06, 0xcf, 0xfb, + 0xfd, 0x06, 0xcf, 0xfb, 0x15, 0x07, 0xcf, 0xfb, 0x49, 0x07, 0xcf, 0xfb, + 0x65, 0x07, 0xcf, 0xfb, 0x05, 0x00, 0x0f, 0xfc, 0x6d, 0x00, 0x0f, 0xfc, + 0x9d, 0x00, 0x0f, 0xfc, 0xed, 0x00, 0x0f, 0xfc, 0xf9, 0x00, 0x0f, 0xfc, + 0x4d, 0x01, 0x0f, 0xfc, 0xb1, 0x01, 0x0f, 0xfc, 0x25, 0x00, 0x40, 0x08, + 0x41, 0x03, 0x0f, 0xfc, 0x45, 0x03, 0x0f, 0xfc, 0x81, 0x03, 0x0f, 0xfc, + 0xcd, 0x03, 0x0f, 0xfc, 0xb5, 0x01, 0x40, 0x08, 0xe9, 0x01, 0x40, 0x08, + 0xc1, 0x03, 0x40, 0x08, 0xb9, 0x06, 0x0f, 0xfc, 0xc9, 0x06, 0x0f, 0xfc, + 0xc1, 0x03, 0x40, 0x08, 0x21, 0x04, 0x40, 0x08, 0x49, 0x07, 0x0f, 0xfc, + 0x59, 0x07, 0x0f, 0xfc, 0x69, 0x01, 0x4f, 0xfc, 0x71, 0x01, 0x4f, 0xfc, + 0x81, 0x01, 0x4f, 0xfc, 0x9d, 0x01, 0x4f, 0xfc, 0x35, 0x04, 0x40, 0x08, + 0xd5, 0x01, 0x4f, 0xfc, 0xd9, 0x01, 0x4f, 0xfc, 0xe9, 0x01, 0x4f, 0xfc, + 0x75, 0x02, 0x4f, 0xfc, 0xf1, 0x02, 0x4f, 0xfc, 0xc9, 0x04, 0x4f, 0xfc, + 0xe1, 0x04, 0x4f, 0xfc, 0x7d, 0x05, 0x4f, 0xfc, 0x25, 0x06, 0x4f, 0xfc, + 0x19, 0x07, 0x4f, 0xfc, 0xdd, 0x00, 0x8f, 0xfc, 0xe5, 0x00, 0x8f, 0xfc, + 0xed, 0x00, 0x8f, 0xfc, 0xf5, 0x00, 0x8f, 0xfc, 0x71, 0x04, 0x40, 0x08, + 0xf5, 0x01, 0x8f, 0xfc, 0x1d, 0x05, 0x40, 0x08, 0xf1, 0x03, 0x8f, 0xfc, + 0x91, 0x04, 0x8f, 0xfc, 0x15, 0x05, 0x8f, 0xfc, 0xb5, 0x07, 0x40, 0x08, + 0x01, 0x07, 0x8f, 0xfc, 0x11, 0x07, 0x8f, 0xfc, 0x21, 0x07, 0x8f, 0xfc, + 0xdd, 0x07, 0x8f, 0xfc, 0xed, 0x02, 0xcf, 0xfc, 0x61, 0x04, 0xcf, 0xfc, + 0x65, 0x04, 0xcf, 0xfc, 0xb5, 0x04, 0xcf, 0xfc, 0xbd, 0x04, 0xcf, 0xfc, + 0xd9, 0x04, 0xcf, 0xfc, 0x15, 0x05, 0xcf, 0xfc, 0x1d, 0x05, 0xcf, 0xfc, + 0x85, 0x06, 0xcf, 0xfc, 0x19, 0x06, 0x80, 0x08, 0x6d, 0x00, 0x0f, 0xfd, + 0x81, 0x00, 0x0f, 0xfd, 0x19, 0x02, 0x0f, 0xfd, 0x31, 0x02, 0x0f, 0xfd, + 0x75, 0x02, 0x0f, 0xfd, 0x8d, 0x02, 0x0f, 0xfd, 0xed, 0x03, 0x0f, 0xfd, + 0x05, 0x04, 0x0f, 0xfd, 0x31, 0x04, 0x0f, 0xfd, 0xa9, 0x05, 0x0f, 0xfd, + 0x55, 0x00, 0x4f, 0xfd, 0x6d, 0x00, 0x4f, 0xfd, 0xe5, 0x00, 0x4f, 0xfd, + 0x95, 0x01, 0x4f, 0xfd, 0x9d, 0x01, 0x4f, 0xfd, 0xb1, 0x01, 0x4f, 0xfd, + 0xc9, 0x01, 0x4f, 0xfd, 0xad, 0x03, 0x4f, 0xfd, 0x49, 0x02, 0x8f, 0xfd, + 0x61, 0x02, 0x8f, 0xfd, 0xed, 0x06, 0x80, 0x08, 0x01, 0x04, 0x8f, 0xfd, + 0x19, 0x04, 0x8f, 0xfd, 0xc9, 0x05, 0x8f, 0xfd, 0xd5, 0x04, 0xcf, 0xfd, + 0xed, 0x04, 0xcf, 0xfd, 0xb5, 0x02, 0x0f, 0xfe, 0x9d, 0x03, 0x8f, 0xfe, + 0xb5, 0x03, 0x8f, 0xfe, 0xd5, 0x06, 0xc0, 0x08, 0xed, 0x06, 0xc0, 0x08, + 0x59, 0x02, 0x0f, 0xff, 0x71, 0x02, 0x0f, 0xff, 0x59, 0x02, 0x8f, 0xff, + 0xb5, 0x02, 0x8f, 0xff, 0x81, 0x03, 0x00, 0x04, 0xf1, 0x06, 0x0f, 0xf6, + 0xf5, 0x01, 0x00, 0x01, 0xfd, 0x00, 0x4f, 0xf6, 0x59, 0x02, 0x00, 0x01, + 0x1d, 0x06, 0xc0, 0x05, 0xdd, 0x05, 0xcf, 0xf8, 0xed, 0x06, 0xcf, 0xf8, + 0x41, 0x02, 0x4f, 0xf9, 0x4d, 0x02, 0x4f, 0xf9, 0xa1, 0x02, 0x80, 0x07, + 0xc1, 0x07, 0x80, 0x00, 0xb5, 0x06, 0x8f, 0xf9, 0xfd, 0x06, 0x8f, 0xf9, + 0x4d, 0x07, 0xcf, 0xfa, 0xf9, 0x04, 0x00, 0x00, 0x39, 0x02, 0x00, 0x01, + 0xc1, 0x02, 0x00, 0x08, 0xa1, 0x01, 0x00, 0x01, 0xed, 0x01, 0x00, 0x01, + 0xb9, 0x01, 0x00, 0x01, 0xdd, 0x02, 0x00, 0x08, 0x79, 0x03, 0x00, 0x08, + 0xa1, 0x00, 0x8f, 0xfb, 0xc9, 0x04, 0x00, 0x08, 0xad, 0x02, 0x8f, 0xfb, + 0xe9, 0x02, 0x0f, 0xfd, 0xf9, 0x02, 0x0f, 0xfd, 0x85, 0x00, 0x80, 0x0a, + 0x05, 0x03, 0x4f, 0xfd, 0x35, 0x01, 0x00, 0x00, 0x71, 0x01, 0x00, 0x00, + 0xfd, 0x03, 0x8f, 0xfd, 0x2d, 0x02, 0xcf, 0xee, 0x65, 0x04, 0x8f, 0xfd, + 0xf5, 0x04, 0x8f, 0xfd, 0xf9, 0x06, 0xcf, 0xfd, 0x99, 0x05, 0x0f, 0xfe, + 0x45, 0x07, 0x4f, 0xfe, 0xfd, 0x01, 0xc0, 0x08, 0x1d, 0x02, 0xc0, 0x08, + 0x09, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0xe2, 0xc2, 0x08, 0x45, + 0x01, 0x80, 0x68, 0x40, 0x84, 0x20, 0x03, 0x0c, 0x19, 0x08, 0x31, 0x04, + 0x48, 0x41, 0x0e, 0x8d, 0x00, 0x15, 0x06, 0x10, 0x21, 0x42, 0x1d, 0x78, + 0x4a, 0x0e, 0x6f, 0xfb, 0x01, 0x43, 0xc2, 0xc6, 0x28, 0x4d, 0x4c, 0x70, + 0x2a, 0x08, 0xe0, 0x00, 0x08, 0x43, 0x00, 0x15, 0x06, 0x10, 0x00, 0x41, + 0x61, 0x40, 0x21, 0x42, 0xfa, 0x0a, 0x2f, 0xf6, 0x01, 0x43, 0xc2, 0xc6, + 0xe2, 0xc2, 0x08, 0x45, 0x01, 0x80, 0x68, 0x40, 0x84, 0x20, 0x03, 0x0c, + 0x19, 0x08, 0x31, 0x04, 0x48, 0x41, 0x0e, 0x8d, 0x00, 0x15, 0x06, 0x10, + 0x21, 0x42, 0x1d, 0x78, 0xee, 0x0d, 0x6f, 0xfb, 0x01, 0x43, 0xc2, 0xc6, + 0x28, 0x4d, 0x4c, 0x70, 0xea, 0x0f, 0xa0, 0x00, 0x08, 0x43, 0x00, 0x15, + 0x06, 0x10, 0x00, 0x41, 0x61, 0x40, 0x21, 0x42, 0xce, 0x0a, 0x2f, 0xf6, + 0x01, 0x43, 0xc2, 0xc6, 0xe2, 0xc2, 0x08, 0x45, 0x01, 0x80, 0x68, 0x40, + 0x84, 0x20, 0x03, 0x0c, 0x19, 0x08, 0x31, 0x04, 0x48, 0x41, 0x0e, 0x8d, + 0x00, 0x15, 0x07, 0x10, 0x21, 0x42, 0x1d, 0x78, 0x1e, 0x0e, 0x6f, 0xfb, + 0x01, 0x43, 0xc2, 0xc6, 0x28, 0x4d, 0x4c, 0x70, 0xaa, 0x0f, 0xa0, 0x00, + 0x08, 0x43, 0x00, 0x15, 0x07, 0x10, 0x00, 0x41, 0x61, 0x40, 0x21, 0x42, + 0xb2, 0x0a, 0xe0, 0x00, 0x01, 0x43, 0xc2, 0xc6, 0xe2, 0xc2, 0x08, 0x45, + 0x01, 0x80, 0x68, 0x40, 0x84, 0x20, 0x03, 0x0c, 0x19, 0x08, 0x31, 0x04, + 0x48, 0x41, 0x0e, 0x8d, 0x00, 0x15, 0x07, 0x10, 0x21, 0x42, 0x1d, 0x78, + 0xa6, 0x0d, 0x6f, 0xfb, 0x01, 0x43, 0xc2, 0xc6, 0x28, 0x4d, 0x4c, 0x70, + 0x6a, 0x0f, 0xa0, 0x00, 0x08, 0x43, 0x00, 0x15, 0x07, 0x10, 0x00, 0x41, + 0x61, 0x40, 0x21, 0x42, 0x8a, 0x0a, 0xe0, 0x00, 0x01, 0x43, 0xc2, 0xc6, + 0xe2, 0xc2, 0x08, 0x45, 0x01, 0x80, 0x68, 0x40, 0x84, 0x20, 0x03, 0x0c, + 0x19, 0x08, 0x31, 0x04, 0x48, 0x41, 0x0e, 0x8d, 0x00, 0x15, 0x06, 0x10, + 0x21, 0x42, 0x1d, 0x78, 0xe2, 0x0a, 0x6f, 0xfb, 0x01, 0x43, 0xc2, 0xc6, + 0x28, 0x4d, 0x4c, 0x71, 0x2a, 0x0f, 0xa0, 0x00, 0x08, 0x43, 0x00, 0x15, + 0x06, 0x10, 0x00, 0x41, 0x61, 0x40, 0x21, 0x42, 0xce, 0x09, 0x2f, 0xf6, + 0x01, 0x43, 0xc2, 0xc6, 0xe2, 0xc2, 0x08, 0x45, 0x01, 0x80, 0x68, 0x40, + 0x84, 0x20, 0x03, 0x0c, 0x19, 0x08, 0x31, 0x04, 0x48, 0x41, 0x0e, 0x8d, + 0x00, 0x15, 0x07, 0x10, 0x21, 0x42, 0x1d, 0x78, 0xbe, 0x0a, 0x6f, 0xfb, + 0x01, 0x43, 0xc2, 0xc6, 0x28, 0x4d, 0x4c, 0x71, 0xea, 0x0e, 0xa0, 0x00, + 0x08, 0x43, 0x00, 0x15, 0x07, 0x10, 0x00, 0x41, 0x61, 0x40, 0x21, 0x42, + 0x22, 0x0a, 0xe0, 0x00, 0x01, 0x43, 0xc2, 0xc6, 0xf1, 0xc0, 0x81, 0x80, + 0x84, 0x24, 0x03, 0x1c, 0x11, 0x0c, 0x31, 0x14, 0x00, 0x10, 0x05, 0x00, + 0x0e, 0x88, 0x1d, 0x78, 0x9e, 0x5a, 0x04, 0xf0, 0x10, 0xe0, 0x8e, 0x5a, + 0xd1, 0xc0, 0xe0, 0x7e, 0xf1, 0xc0, 0x81, 0x80, 0x84, 0x24, 0x03, 0x1c, + 0x11, 0x0c, 0x31, 0x14, 0x00, 0x10, 0x06, 0x00, 0x0e, 0x88, 0x1d, 0x78, + 0xa0, 0x5a, 0x04, 0xf0, 0x10, 0xe0, 0x8f, 0x5a, 0xd1, 0xc0, 0xe0, 0x7e, + 0xf1, 0xc0, 0x81, 0x80, 0x84, 0x24, 0x03, 0x1c, 0x11, 0x0c, 0x31, 0x14, + 0x00, 0x10, 0x06, 0x00, 0x0e, 0x88, 0x1d, 0x78, 0x9f, 0x5a, 0x04, 0xf0, + 0x10, 0xe0, 0x90, 0x5a, 0xd1, 0xc0, 0xe0, 0x7e, 0xf1, 0xc0, 0x81, 0x80, + 0x84, 0x24, 0x03, 0x1c, 0x11, 0x0c, 0x31, 0x14, 0x00, 0x10, 0x06, 0x00, + 0x0e, 0x88, 0x1d, 0x78, 0x9c, 0x5a, 0x04, 0xf0, 0x10, 0xe0, 0x8d, 0x5a, + 0xd1, 0xc0, 0xe0, 0x7e, 0xfc, 0x1c, 0x88, 0xb7, 0xe1, 0xc0, 0xe1, 0xc1, + 0xe1, 0xc2, 0xe1, 0xc3, 0xfc, 0x1c, 0x08, 0xb1, 0xfc, 0x1c, 0x48, 0xb1, + 0xfc, 0x1c, 0x88, 0xb1, 0xfc, 0x1c, 0xc8, 0xb1, 0xfc, 0x1c, 0x08, 0xb2, + 0xfc, 0x1c, 0x48, 0xb2, 0xfc, 0x1c, 0x88, 0xb2, 0xfc, 0x1c, 0xc8, 0xb2, + 0xe1, 0xc4, 0xf1, 0xc0, 0xfc, 0x1c, 0x08, 0xbf, 0x6a, 0x20, 0x80, 0x00, + 0xe1, 0xc0, 0x6a, 0x20, 0xc0, 0x00, 0xe1, 0xc0, 0xc3, 0x40, 0xf0, 0x00, + 0x2d, 0x00, 0x00, 0x88, 0xc1, 0xb8, 0xf0, 0x26, 0x01, 0x70, 0xa0, 0x00, + 0x08, 0x87, 0x03, 0xe9, 0x40, 0x79, 0xc1, 0xc0, 0x6b, 0x20, 0xc0, 0x00, + 0xc1, 0xc0, 0x6b, 0x20, 0x80, 0x00, 0xc1, 0xc0, 0x0a, 0x24, 0x00, 0x70, + 0xd1, 0xc0, 0xc1, 0xc4, 0x04, 0x14, 0x0b, 0x34, 0x04, 0x14, 0x0a, 0x34, + 0x04, 0x14, 0x09, 0x34, 0x04, 0x14, 0x08, 0x34, 0x04, 0x14, 0x07, 0x34, + 0x04, 0x14, 0x06, 0x34, 0x04, 0x14, 0x05, 0x34, 0x04, 0x14, 0x04, 0x34, + 0xc1, 0xc3, 0xc1, 0xc2, 0xc1, 0xc1, 0xc1, 0xc0, 0x04, 0x14, 0x1e, 0x34, + 0x6f, 0x24, 0x3f, 0x00, 0xe4, 0xc2, 0x2f, 0x27, 0xbf, 0x03, 0x6f, 0x23, + 0x3f, 0x00, 0xcb, 0x45, 0xa0, 0x00, 0xa2, 0x42, 0x20, 0x8d, 0x06, 0x21, + 0x00, 0x00, 0x82, 0x0b, 0xaf, 0xee, 0x00, 0xad, 0x20, 0x8d, 0x14, 0x70, + 0xc3, 0x40, 0xf0, 0x00, 0x34, 0x00, 0x05, 0xf2, 0x7b, 0x00, 0x20, 0x00, + 0x33, 0xa8, 0xa0, 0xb9, 0x33, 0xa8, 0x20, 0xad, 0x00, 0x16, 0x80, 0x70, + 0xa0, 0x00, 0xa1, 0x42, 0x14, 0x70, 0x33, 0xf2, 0x00, 0x16, 0xc0, 0x70, + 0xa0, 0x00, 0xb0, 0x42, 0xcb, 0x44, 0xa0, 0x00, 0xa0, 0x42, 0x14, 0x70, + 0xc3, 0x43, 0xf0, 0x00, 0x40, 0x02, 0x26, 0x00, 0x2b, 0x00, 0x40, 0x8c, + 0x6d, 0x71, 0xe5, 0xb8, 0x00, 0x2b, 0x80, 0x10, 0x2f, 0x27, 0xbf, 0x00, + 0x6f, 0x23, 0x3f, 0x00, 0x12, 0xf4, 0x25, 0x83, 0x06, 0x79, 0x25, 0xa3, + 0x2f, 0x26, 0xbf, 0x00, 0x11, 0xf0, 0x2f, 0x27, 0x7f, 0x00, 0x6f, 0x23, + 0x3f, 0x00, 0x07, 0x83, 0x0f, 0x20, 0x80, 0x00, 0x07, 0xa3, 0x2f, 0x26, + 0x7f, 0x00, 0x0b, 0xf0, 0x25, 0x83, 0x25, 0x78, 0x05, 0xa3, 0x2f, 0x26, + 0xbf, 0x00, 0x00, 0x8c, 0x00, 0x2b, 0x00, 0x10, 0x06, 0xa3, 0x2f, 0x26, + 0xbf, 0x03, 0xc4, 0xc6, 0xe6, 0xc1, 0xa3, 0xc1, 0x2f, 0x27, 0x3f, 0x02, + 0x6f, 0x23, 0x3f, 0x00, 0x6f, 0x26, 0x3f, 0x04, 0x37, 0x88, 0x6d, 0x70, + 0x34, 0x70, 0x0c, 0xf2, 0x35, 0x88, 0x83, 0xe9, 0x36, 0x88, 0x44, 0x80, + 0x05, 0xb9, 0x42, 0x21, 0x01, 0x08, 0x3a, 0x62, 0x68, 0x8a, 0x74, 0x70, + 0x8e, 0x00, 0x21, 0x00, 0x80, 0xc4, 0xe7, 0x82, 0xc6, 0x82, 0xff, 0xd9, + 0x5a, 0xdd, 0x18, 0x1a, 0x80, 0x0f, 0x12, 0x00, 0x24, 0xf1, 0x87, 0xa2, + 0x40, 0xc6, 0x41, 0xc7, 0x4f, 0x00, 0x20, 0x00, 0x42, 0xc1, 0xab, 0x25, + 0x08, 0x1e, 0x00, 0x16, 0x81, 0x70, 0xf0, 0x00, 0x35, 0x00, 0xc5, 0xb9, + 0x34, 0x72, 0x10, 0xf4, 0x6f, 0x27, 0x3f, 0x00, 0x6f, 0x23, 0x3f, 0x00, + 0xaa, 0x21, 0x5a, 0x00, 0x4b, 0x21, 0x80, 0x83, 0x0b, 0xf2, 0x2f, 0x21, + 0xbf, 0x0f, 0x00, 0x00, 0x77, 0x00, 0x0b, 0xf0, 0x2f, 0x21, 0xbf, 0x0f, + 0x00, 0x00, 0xb7, 0x00, 0x05, 0xf0, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, + 0xb7, 0x00, 0x6f, 0x26, 0x3f, 0x04, 0x68, 0x8a, 0x02, 0xc1, 0x08, 0xeb, + 0x8c, 0x21, 0xc3, 0x8f, 0x04, 0xf4, 0x77, 0x88, 0x74, 0x70, 0xd7, 0xf5, + 0x8c, 0x21, 0xc3, 0x8f, 0x6d, 0x71, 0x09, 0xf4, 0x27, 0x82, 0x0f, 0x09, + 0x01, 0x03, 0x01, 0xc1, 0x27, 0xa2, 0x00, 0xc1, 0x26, 0xa2, 0x2f, 0x26, + 0x3f, 0x02, 0x61, 0x40, 0xc6, 0xc5, 0xe0, 0x78, 0x14, 0x70, 0x7c, 0x00, + 0x21, 0x00, 0x00, 0x43, 0x2f, 0x27, 0x3f, 0x03, 0x6f, 0x23, 0x3f, 0x00, + 0x6f, 0x26, 0x3f, 0x04, 0x22, 0xf0, 0x29, 0xf4, 0x00, 0x16, 0x80, 0x70, + 0xf0, 0x00, 0x35, 0x00, 0xc5, 0xb8, 0x14, 0x72, 0x0f, 0xf4, 0x6f, 0x27, + 0x3f, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xaa, 0x20, 0x5a, 0x00, 0x4b, 0x20, + 0x80, 0x83, 0x0c, 0xf2, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, 0x77, 0x00, + 0x0a, 0xf0, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, 0xb7, 0x00, 0x06, 0xf0, + 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, 0xb7, 0x00, 0x6f, 0x26, 0x3f, 0x04, + 0x4c, 0x8b, 0x00, 0x81, 0x54, 0x70, 0xba, 0x07, 0xe2, 0xff, 0x8c, 0x20, + 0xc3, 0x8f, 0x2f, 0x26, 0x3f, 0x03, 0x8c, 0x20, 0xc3, 0x8f, 0x00, 0x41, + 0xca, 0x21, 0xe1, 0x08, 0x54, 0x70, 0xe0, 0x7f, 0xca, 0x20, 0x41, 0x00, + 0xe0, 0x7f, 0x23, 0xd8, 0xe8, 0xc3, 0xa3, 0xc1, 0x2f, 0x27, 0x3f, 0x04, + 0x6f, 0x23, 0x3f, 0x00, 0x6f, 0x26, 0x3f, 0x04, 0x2d, 0x90, 0xad, 0x70, + 0x34, 0x70, 0x0c, 0xf2, 0x2b, 0x90, 0x83, 0xe9, 0x2c, 0x90, 0x24, 0x77, + 0x42, 0x80, 0x5a, 0x21, 0x01, 0x05, 0x3a, 0x62, 0x2c, 0x8a, 0x34, 0x70, + 0x94, 0x00, 0x21, 0x00, 0x80, 0xc3, 0xc4, 0x82, 0xa2, 0x82, 0xff, 0xdc, + 0x08, 0x1a, 0x80, 0x0f, 0x13, 0x00, 0xcc, 0x4d, 0x64, 0xa2, 0x40, 0xc5, + 0x41, 0xc6, 0x51, 0x00, 0x20, 0x00, 0x42, 0xc4, 0xab, 0x21, 0x08, 0x0e, + 0x00, 0x16, 0x81, 0x70, 0xf0, 0x00, 0x35, 0x00, 0xc5, 0xb9, 0x34, 0x72, + 0x0f, 0xf4, 0x6f, 0x27, 0x3f, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xaa, 0x21, + 0x5a, 0x00, 0x4b, 0x21, 0x80, 0x83, 0x0c, 0xf2, 0x2f, 0x21, 0xbf, 0x0f, + 0x00, 0x00, 0x77, 0x00, 0x0a, 0xf0, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, + 0xb7, 0x00, 0x06, 0xf0, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, 0xb7, 0x00, + 0x6f, 0x26, 0x3f, 0x04, 0x2c, 0x8a, 0x02, 0xc4, 0x09, 0xe9, 0x8c, 0x24, + 0xc3, 0x9f, 0x07, 0xf4, 0x2d, 0x90, 0x34, 0x70, 0xac, 0x07, 0xe2, 0xff, + 0x5a, 0xd9, 0x8c, 0x24, 0xc3, 0x9f, 0xad, 0x71, 0x0a, 0xf4, 0x04, 0x82, + 0x11, 0x08, 0xc1, 0x00, 0x01, 0xc0, 0x04, 0xa2, 0x00, 0xc0, 0x02, 0xa2, + 0x91, 0xd8, 0x67, 0x58, 0x2f, 0x26, 0x3f, 0x04, 0xa1, 0x40, 0xc8, 0xc7, + 0x00, 0x16, 0x80, 0x70, 0xf0, 0x00, 0x35, 0x00, 0xc5, 0xb8, 0x14, 0x72, + 0x0f, 0xf4, 0x6f, 0x27, 0x3f, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xaa, 0x20, + 0x5a, 0x00, 0x4b, 0x20, 0x80, 0x83, 0x0c, 0xf2, 0x2f, 0x21, 0xbf, 0x0f, + 0x00, 0x00, 0x77, 0x00, 0xe0, 0x7e, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, + 0xb7, 0x00, 0xe0, 0x7e, 0x2f, 0x21, 0xbf, 0x0f, 0x00, 0x00, 0xb7, 0x00, + 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0x02, 0x88, 0x15, 0x08, 0xbf, 0x01, + 0xf6, 0xd8, 0x02, 0x89, 0x0b, 0x08, 0xff, 0x01, 0x0c, 0x70, 0xd1, 0xc0, + 0xe0, 0x7e, 0xf0, 0xd8, 0x92, 0x09, 0xaf, 0xf4, 0x2c, 0x71, 0xe0, 0x78, + 0xe4, 0xc2, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, + 0x00, 0x00, 0x28, 0x45, 0xae, 0x0d, 0x6f, 0xf9, 0x08, 0x46, 0x4c, 0x70, + 0x6c, 0x70, 0xc1, 0x40, 0x4e, 0x0f, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, + 0xe4, 0xc2, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, + 0x00, 0x00, 0x28, 0x45, 0x8a, 0x0d, 0x6f, 0xf9, 0x08, 0x46, 0x4c, 0x71, + 0x6c, 0x70, 0xc1, 0x40, 0x2a, 0x0f, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, + 0xe4, 0xc2, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, + 0x00, 0x00, 0x28, 0x45, 0x66, 0x0d, 0x6f, 0xf9, 0x08, 0x46, 0x4c, 0x72, + 0x6c, 0x70, 0xc1, 0x40, 0x06, 0x0f, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, + 0xe2, 0xc2, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, + 0x00, 0x00, 0x3e, 0x0d, 0x6f, 0xf9, 0x08, 0x45, 0x4c, 0x73, 0x6c, 0x76, + 0xe6, 0x0e, 0xa0, 0x08, 0xa1, 0x40, 0xc2, 0xc6, 0xe4, 0xc2, 0xc3, 0x42, + 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x28, 0x45, + 0x22, 0x0d, 0x6f, 0xf9, 0x08, 0x46, 0x4c, 0x74, 0x6c, 0x70, 0xc1, 0x40, + 0xc2, 0x0e, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, 0xe4, 0xc2, 0xc3, 0x42, + 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x28, 0x45, + 0xfe, 0x0c, 0x6f, 0xf9, 0x08, 0x46, 0x4c, 0x75, 0x6c, 0x70, 0xc1, 0x40, + 0x9e, 0x0e, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, 0xe4, 0xc2, 0xc3, 0x42, + 0x13, 0x00, 0x70, 0x91, 0xc3, 0x43, 0x13, 0x00, 0x74, 0x91, 0x28, 0x45, + 0xda, 0x0c, 0x6f, 0xf9, 0x08, 0x46, 0x4c, 0x76, 0x6c, 0x70, 0xc1, 0x40, + 0x7a, 0x0e, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, 0xe4, 0xc2, 0xc3, 0x42, + 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x28, 0x45, + 0xb6, 0x0c, 0x6f, 0xf9, 0x08, 0x46, 0x07, 0xda, 0x6c, 0x70, 0xc1, 0x40, + 0x56, 0x0e, 0xa0, 0x08, 0xa1, 0x41, 0xc4, 0xc6, 0xf1, 0xc0, 0xc3, 0x42, + 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x86, 0x0c, + 0x4f, 0xf9, 0x08, 0xda, 0x3a, 0x0e, 0xa0, 0x08, 0x6c, 0x74, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xe4, 0xc2, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, + 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x28, 0x45, 0x72, 0x0c, 0x6f, 0xf9, + 0x08, 0x46, 0x09, 0xda, 0x6c, 0x70, 0xc1, 0x40, 0x12, 0x0e, 0xa0, 0x08, + 0xa1, 0x41, 0xc4, 0xc6, 0xe2, 0xc2, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, + 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x0c, 0x6f, 0xf9, 0x08, 0x45, + 0x0a, 0xda, 0x6c, 0x76, 0xf2, 0x0d, 0xa0, 0x08, 0xa1, 0x40, 0xc2, 0xc6, + 0xe2, 0xc3, 0xa1, 0xc1, 0x3a, 0x0c, 0xef, 0xfa, 0x08, 0x45, 0x40, 0xc0, + 0x40, 0x24, 0x05, 0x30, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x76, 0x72, 0x0b, 0xef, 0xfa, 0xa1, 0x40, + 0x40, 0x24, 0x04, 0x30, 0x0b, 0xda, 0x6c, 0x76, 0xae, 0x0d, 0xa0, 0x08, + 0xa1, 0x40, 0x00, 0xc0, 0xc2, 0xc7, 0xe0, 0x78, 0xe4, 0xc2, 0xad, 0x70, + 0xcb, 0x46, 0x13, 0x00, 0xd4, 0x91, 0x00, 0x86, 0x21, 0x86, 0x02, 0x79, + 0x0b, 0x09, 0x72, 0x01, 0x22, 0xb9, 0x9a, 0x0b, 0xcf, 0xfa, 0xa5, 0x71, + 0xef, 0x0d, 0x34, 0x94, 0x08, 0xe6, 0xc3, 0x42, 0x13, 0x00, 0x74, 0x91, + 0xc3, 0x43, 0x13, 0x00, 0x78, 0x91, 0xca, 0x0b, 0x4f, 0xf9, 0x0c, 0xda, + 0x7e, 0x0d, 0xa0, 0x08, 0x6c, 0x74, 0xc4, 0xc6, 0xf1, 0xc0, 0xc3, 0x42, + 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0xae, 0x0b, + 0x4f, 0xf9, 0x0d, 0xda, 0x62, 0x0d, 0xa0, 0x08, 0x6c, 0x74, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, + 0xc3, 0x43, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x0b, 0x4f, 0xf9, 0x0e, 0xda, + 0x42, 0x0d, 0xa0, 0x08, 0x6c, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0xf1, 0xc0, 0xc3, 0x42, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x43, 0x00, 0x00, + 0x00, 0x00, 0x6e, 0x0b, 0x4f, 0xf9, 0x0f, 0xda, 0x22, 0x0d, 0xa0, 0x08, + 0x6c, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xe0, 0x7f, 0x0c, 0x70, + 0xe8, 0xc2, 0x08, 0x45, 0x94, 0xe1, 0x42, 0x01, 0x25, 0x00, 0xed, 0x70, + 0x0e, 0x71, 0xcd, 0x70, 0xe1, 0xad, 0xe0, 0xad, 0xae, 0x09, 0xaf, 0xf5, + 0xcf, 0x78, 0x61, 0x8d, 0x40, 0x8d, 0x2f, 0x21, 0x08, 0x04, 0x08, 0xbb, + 0x14, 0x70, 0xc5, 0x71, 0x65, 0x7a, 0xcf, 0x78, 0xc5, 0x22, 0x42, 0x00, + 0x2f, 0x20, 0x40, 0x20, 0x40, 0xad, 0x28, 0xba, 0xdd, 0x08, 0x74, 0x82, + 0x41, 0xad, 0x09, 0xde, 0x0e, 0x71, 0xe3, 0xad, 0x02, 0x1d, 0xc2, 0x13, + 0x7a, 0x09, 0xaf, 0xf5, 0xcf, 0x78, 0x63, 0x8d, 0x42, 0x8d, 0x2f, 0x21, + 0x08, 0x04, 0x08, 0xbb, 0x14, 0x70, 0xc5, 0x71, 0x65, 0x7a, 0xcf, 0x78, + 0xc5, 0x22, 0x42, 0x00, 0x2f, 0x20, 0x40, 0x20, 0x42, 0xad, 0x28, 0xba, + 0xdd, 0x08, 0xb4, 0x84, 0x43, 0xad, 0xcd, 0x70, 0x0e, 0x71, 0xe5, 0xad, + 0x04, 0x1d, 0xc2, 0x13, 0x6e, 0x08, 0xaf, 0xf5, 0xcf, 0x78, 0x65, 0x8d, + 0x44, 0x8d, 0x2f, 0x21, 0x08, 0x04, 0x08, 0xbb, 0x14, 0x70, 0xc5, 0x71, + 0x65, 0x7a, 0xcf, 0x78, 0xc5, 0x22, 0x42, 0x00, 0x2f, 0x20, 0x40, 0x20, + 0x44, 0xad, 0x28, 0xba, 0xdd, 0x08, 0x74, 0x82, 0x45, 0xad, 0xe7, 0xad, + 0xe6, 0xad, 0x09, 0xdf, 0x4a, 0x26, 0x40, 0x10, 0x3a, 0x08, 0xaf, 0xf5, + 0xef, 0x78, 0x87, 0x8d, 0x46, 0x8d, 0x14, 0x70, 0x40, 0x2c, 0x00, 0x12, + 0xd0, 0x79, 0xe5, 0x71, 0x45, 0x78, 0xef, 0x7b, 0xc5, 0x20, 0x42, 0x00, + 0x3b, 0x7e, 0x06, 0xad, 0x28, 0xb8, 0xe1, 0x0b, 0xb4, 0x84, 0x07, 0xad, + 0xe6, 0x0e, 0x40, 0x00, 0xde, 0x0e, 0x60, 0x00, 0x08, 0xad, 0xb6, 0x0e, + 0x60, 0x00, 0x09, 0xad, 0x92, 0x0e, 0x60, 0x00, 0x0a, 0xad, 0x5e, 0x09, + 0xaf, 0xf5, 0x0b, 0xad, 0xda, 0x09, 0xaf, 0xf5, 0x0c, 0xad, 0x8a, 0x09, + 0xaf, 0xf5, 0x0d, 0xad, 0x0e, 0xad, 0xc3, 0x41, 0xf0, 0x00, 0x00, 0x01, + 0x0d, 0x89, 0x14, 0xdf, 0xc2, 0xb8, 0x0f, 0xad, 0x09, 0x89, 0xc6, 0xb8, + 0x10, 0xad, 0x05, 0x91, 0xc6, 0xb8, 0x11, 0xad, 0x0c, 0x89, 0xc1, 0xb8, + 0x12, 0xad, 0x13, 0x8d, 0x2c, 0x89, 0x00, 0x16, 0x02, 0x70, 0xf0, 0x00, + 0x90, 0x01, 0x6c, 0x20, 0x43, 0x00, 0x24, 0xb9, 0x5b, 0x78, 0x44, 0x21, + 0x42, 0x00, 0x44, 0x20, 0x81, 0x00, 0x05, 0x23, 0x80, 0x00, 0x25, 0x78, + 0x13, 0xad, 0xe1, 0x40, 0xc8, 0xc6, 0xe0, 0x78, 0xe8, 0xc2, 0xf0, 0x26, + 0x4d, 0x70, 0xa0, 0x00, 0xf4, 0x4d, 0x48, 0x47, 0x08, 0x46, 0xb5, 0x70, + 0x66, 0xf2, 0x2f, 0x27, 0x3f, 0x04, 0x6f, 0x23, 0x3f, 0x00, 0x01, 0x85, + 0x00, 0xae, 0x60, 0x85, 0x42, 0x85, 0x28, 0xb8, 0x01, 0xae, 0x20, 0x40, + 0x62, 0xae, 0x6a, 0x08, 0x6f, 0xf8, 0x43, 0xae, 0x82, 0x8e, 0x04, 0xae, + 0x55, 0x27, 0x80, 0x1f, 0x22, 0xb8, 0xc5, 0xb8, 0x40, 0x25, 0x03, 0x15, + 0x98, 0x4e, 0x4c, 0x70, 0x09, 0x24, 0x0b, 0x10, 0x1f, 0xf0, 0x60, 0x83, + 0x20, 0xeb, 0xd4, 0x8b, 0x80, 0x89, 0x44, 0x71, 0xc3, 0xbe, 0x6c, 0x24, + 0xc0, 0x10, 0xc5, 0x78, 0x00, 0xa9, 0x88, 0x8b, 0x84, 0x20, 0xc2, 0x03, + 0x04, 0xbc, 0x84, 0x24, 0x01, 0x1c, 0x85, 0x78, 0x00, 0xa9, 0x15, 0x8b, + 0xc5, 0x7c, 0x07, 0xb8, 0x85, 0x78, 0x00, 0xa9, 0x0c, 0x93, 0x96, 0x8b, + 0x02, 0xa9, 0x28, 0xb8, 0x81, 0xa9, 0x03, 0xa9, 0x24, 0x74, 0x4f, 0x78, + 0xc3, 0x08, 0xc4, 0x82, 0x0c, 0xe5, 0x20, 0xf0, 0xa0, 0x85, 0x21, 0xed, + 0x94, 0x8d, 0x60, 0x89, 0x44, 0x71, 0xc3, 0xbc, 0x6c, 0x23, 0xc0, 0x00, + 0x85, 0x78, 0x00, 0xa9, 0x68, 0x8d, 0x84, 0x20, 0xc2, 0x03, 0x04, 0xbb, + 0x84, 0x23, 0x01, 0x0c, 0x65, 0x78, 0x00, 0xa9, 0x15, 0x8d, 0x85, 0x7b, + 0x07, 0xb8, 0x65, 0x78, 0x00, 0xa9, 0x0c, 0x95, 0x76, 0x8d, 0x02, 0xa9, + 0x28, 0xb8, 0x61, 0xa9, 0x03, 0xa9, 0x24, 0x74, 0x4f, 0x78, 0xc5, 0x08, + 0xc4, 0x82, 0x2f, 0x26, 0x3f, 0x04, 0x08, 0xd9, 0x15, 0x79, 0x03, 0xf0, + 0x2c, 0x70, 0x30, 0x78, 0xc8, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0xcb, 0x44, + 0xa0, 0x00, 0x24, 0x87, 0x80, 0x84, 0x60, 0x7c, 0x48, 0x45, 0xcd, 0x70, + 0x09, 0xe8, 0x00, 0x8d, 0xcd, 0x71, 0x07, 0xe8, 0x3d, 0x58, 0x24, 0x88, + 0x05, 0x88, 0x21, 0xad, 0x02, 0xad, 0xc1, 0x40, 0xc4, 0xc6, 0xe0, 0x78, + 0xea, 0xc2, 0x08, 0x45, 0x7c, 0xb8, 0x70, 0x41, 0x48, 0x46, 0x1d, 0x08, + 0xf5, 0x00, 0x30, 0x40, 0x55, 0x25, 0x40, 0x1e, 0x0f, 0x79, 0xc1, 0x40, + 0x02, 0x42, 0xb7, 0xff, 0x00, 0x19, 0x04, 0x20, 0x0c, 0x71, 0xca, 0xc6, + 0x0f, 0x0d, 0x74, 0x18, 0x1e, 0x4e, 0x2c, 0x70, 0x9a, 0x09, 0xef, 0xfc, + 0x4c, 0x75, 0xcb, 0x47, 0xa0, 0x00, 0x18, 0x87, 0x82, 0x87, 0xa1, 0x40, + 0x02, 0x41, 0xc1, 0x42, 0x60, 0x7c, 0x22, 0x43, 0x07, 0xe8, 0x71, 0x0d, + 0xf0, 0x10, 0x0c, 0x71, 0x31, 0x0d, 0x10, 0x11, 0xe9, 0xf1, 0x25, 0x0d, + 0x32, 0x14, 0x0c, 0x70, 0x87, 0x0d, 0x30, 0x14, 0x02, 0x41, 0xf9, 0xe5, + 0x44, 0xf2, 0xfe, 0xe5, 0xdf, 0xf5, 0x20, 0x8f, 0x03, 0xae, 0x02, 0xae, + 0x01, 0xae, 0x0c, 0x74, 0x20, 0xae, 0x3f, 0xf0, 0x41, 0x0d, 0xd0, 0x10, + 0xab, 0x0d, 0x11, 0x91, 0x46, 0x0d, 0x80, 0x07, 0x08, 0x45, 0x02, 0x6e, + 0xc3, 0x41, 0x13, 0x00, 0x61, 0x90, 0xfa, 0x0a, 0xef, 0xee, 0x4c, 0x76, + 0x18, 0x4e, 0xc3, 0x41, 0xa0, 0x00, 0x4c, 0x88, 0xea, 0x0a, 0xef, 0xee, + 0x4c, 0x76, 0x09, 0xed, 0x80, 0x25, 0x04, 0x1f, 0x1e, 0x4e, 0x4c, 0x76, + 0xda, 0x0a, 0xef, 0xee, 0xa1, 0x41, 0x00, 0x11, 0x00, 0x21, 0xb6, 0xf1, + 0x0d, 0x08, 0x35, 0x25, 0x0c, 0x70, 0x00, 0x19, 0x05, 0x20, 0xca, 0xc6, + 0x0e, 0x0f, 0xef, 0xf9, 0x0c, 0x72, 0x41, 0x28, 0x03, 0x06, 0x41, 0x28, + 0x02, 0x04, 0x41, 0x28, 0x01, 0x02, 0x10, 0xae, 0x14, 0xd8, 0x73, 0xae, + 0x52, 0xae, 0x31, 0xae, 0x09, 0xf0, 0x10, 0xd8, 0x96, 0x0a, 0xa0, 0x00, + 0xc1, 0x42, 0x05, 0xf0, 0xc1, 0x40, 0x02, 0x41, 0x2f, 0xff, 0x31, 0x09, + 0x11, 0xa0, 0x98, 0xf1, 0xe8, 0xc2, 0xcb, 0x46, 0xa0, 0x00, 0x18, 0x87, + 0x64, 0x86, 0x48, 0x45, 0x30, 0x40, 0x60, 0x7b, 0x08, 0x47, 0xb6, 0xe8, + 0xfe, 0xe7, 0x0c, 0x70, 0x33, 0xf4, 0x0d, 0x08, 0x10, 0x20, 0x40, 0x8d, + 0x40, 0xae, 0x03, 0xf0, 0x40, 0x8e, 0xcb, 0x45, 0x13, 0x00, 0x67, 0x90, + 0x05, 0xea, 0x8c, 0x22, 0xc3, 0x8f, 0x23, 0xf2, 0x06, 0xf0, 0xf6, 0x0c, + 0x6f, 0xee, 0xa1, 0x40, 0x40, 0x8e, 0x1a, 0xea, 0x21, 0x86, 0x01, 0x69, + 0x01, 0xa6, 0x3e, 0x0b, 0x6f, 0xee, 0x5a, 0x4d, 0x00, 0x8e, 0x25, 0x08, + 0x94, 0x00, 0x3b, 0x58, 0x00, 0x43, 0x20, 0x44, 0x1d, 0x4d, 0xe1, 0x41, + 0x26, 0x0b, 0x6f, 0xee, 0x02, 0x42, 0x00, 0x8e, 0x0d, 0x08, 0xf4, 0x00, + 0x54, 0x25, 0x40, 0x1a, 0x16, 0x0b, 0x4f, 0xee, 0x04, 0x8e, 0x0d, 0x08, + 0x1e, 0x00, 0x86, 0x0c, 0x6f, 0xee, 0x0a, 0xd8, 0x0c, 0x71, 0xc8, 0xc6, + 0xe2, 0xc2, 0x33, 0x0b, 0xb0, 0x00, 0x28, 0x43, 0x45, 0x0b, 0x50, 0x00, + 0x9b, 0x0b, 0x11, 0x00, 0x80, 0x90, 0x59, 0x0c, 0x13, 0x16, 0x61, 0x0c, + 0xd0, 0x11, 0x9f, 0x0c, 0x10, 0x12, 0x8b, 0x0c, 0x91, 0x12, 0x21, 0x90, + 0x04, 0x69, 0xb1, 0x09, 0x34, 0x02, 0x00, 0xa2, 0x53, 0x21, 0x7e, 0x80, + 0x4b, 0xf0, 0x80, 0x90, 0xc3, 0x41, 0xa0, 0x00, 0x5c, 0xe9, 0x4b, 0x0c, + 0xd0, 0x11, 0x4d, 0x0c, 0x10, 0x12, 0x67, 0x0c, 0x91, 0x12, 0xb6, 0x08, + 0x00, 0x00, 0x4b, 0xf0, 0x80, 0x90, 0xcb, 0x45, 0xa0, 0x00, 0x2c, 0x87, + 0x3b, 0x0c, 0x90, 0x16, 0x45, 0x0c, 0x50, 0x16, 0x4b, 0x0c, 0x11, 0x16, + 0x82, 0x85, 0x23, 0xec, 0x40, 0x7c, 0x3d, 0xf0, 0x65, 0x0c, 0x10, 0x16, + 0x09, 0x0c, 0x50, 0x16, 0x37, 0x0c, 0x91, 0x16, 0x21, 0x90, 0x0c, 0x71, + 0x64, 0x69, 0x5d, 0x09, 0x31, 0x01, 0x60, 0xa2, 0xc2, 0xc6, 0xbe, 0x0b, + 0x00, 0x00, 0x2d, 0xf0, 0xfe, 0x0b, 0x00, 0x00, 0x29, 0xf0, 0x20, 0x85, + 0x0b, 0xe9, 0x43, 0x85, 0x25, 0x88, 0x60, 0x7a, 0x04, 0x88, 0x23, 0xf0, + 0x80, 0x85, 0x05, 0xec, 0x60, 0x7c, 0x04, 0x88, 0x1d, 0xf0, 0xcb, 0x44, + 0xa0, 0x00, 0x30, 0x87, 0xa0, 0x84, 0x17, 0xed, 0x60, 0x7d, 0x61, 0x41, + 0xc2, 0xc6, 0x01, 0x90, 0x2c, 0x68, 0x64, 0x68, 0xf8, 0xe1, 0x60, 0xa2, + 0x0a, 0xf7, 0x53, 0x20, 0x7e, 0x80, 0x0c, 0x71, 0xdc, 0xf3, 0x06, 0xf0, + 0x21, 0x90, 0x04, 0x69, 0x00, 0xa2, 0x07, 0xe9, 0x2c, 0x71, 0x81, 0x40, + 0x70, 0x58, 0x0c, 0x70, 0xc2, 0xc6, 0x0c, 0x71, 0xc2, 0xc6, 0xe0, 0x78, + 0xf1, 0xc0, 0x79, 0x20, 0x00, 0x00, 0x04, 0x71, 0x04, 0xa9, 0x0c, 0x71, + 0x64, 0x58, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xf8, 0xc2, 0x08, 0x46, + 0x04, 0x88, 0x0d, 0x08, 0x1f, 0x00, 0x01, 0x96, 0xa1, 0x08, 0x11, 0x02, + 0x0b, 0x16, 0x94, 0x10, 0xfa, 0x08, 0x6f, 0xfa, 0x0a, 0x16, 0x93, 0x10, + 0x04, 0xe8, 0x2d, 0x10, 0x92, 0x00, 0x03, 0xf0, 0x4e, 0x71, 0xcb, 0x47, + 0xa0, 0x00, 0x80, 0xea, 0xcb, 0x45, 0xa0, 0x00, 0x60, 0xea, 0x0c, 0x70, + 0x03, 0x1f, 0xc2, 0x14, 0x04, 0x1f, 0x02, 0x15, 0x1c, 0xad, 0x18, 0x1d, + 0x45, 0x11, 0x22, 0x96, 0x08, 0x16, 0x90, 0x10, 0x4b, 0x21, 0x00, 0x86, + 0x30, 0x41, 0x13, 0xf2, 0x41, 0x29, 0xcc, 0x20, 0x53, 0x24, 0x41, 0x10, + 0x5d, 0x09, 0xd0, 0x00, 0x6b, 0x09, 0x90, 0x00, 0x7d, 0x09, 0x51, 0x00, + 0x67, 0x0a, 0x5f, 0x20, 0xc3, 0x41, 0xa0, 0x00, 0xec, 0x40, 0x21, 0xd8, + 0x4d, 0xf0, 0x2e, 0x58, 0x10, 0x45, 0x34, 0x58, 0x00, 0x41, 0x02, 0x40, + 0xa2, 0x42, 0x33, 0x58, 0x16, 0xe8, 0xbc, 0x48, 0x18, 0xda, 0x92, 0x08, + 0xef, 0xee, 0xa1, 0x40, 0x01, 0x85, 0xf0, 0xd9, 0x04, 0x79, 0x63, 0x09, + 0x30, 0x04, 0x91, 0xe0, 0xe5, 0x09, 0x31, 0x08, 0xa2, 0xe0, 0xf7, 0xf2, + 0xa1, 0xe0, 0xc6, 0x21, 0x21, 0x26, 0xcf, 0x21, 0xe1, 0x20, 0xf5, 0xf0, + 0x00, 0x96, 0x2c, 0x76, 0x70, 0x58, 0xd8, 0xc6, 0x08, 0x1d, 0x81, 0x14, + 0x04, 0x1d, 0x81, 0x14, 0x00, 0x1d, 0x80, 0x1f, 0xa0, 0x00, 0x74, 0x40, + 0x0d, 0xf0, 0x3f, 0x0a, 0x51, 0x20, 0x08, 0x1d, 0x41, 0x14, 0x04, 0x1d, + 0x41, 0x14, 0x00, 0x1d, 0x80, 0x1f, 0xa0, 0x00, 0x54, 0x40, 0x03, 0xf0, + 0x01, 0xa5, 0x49, 0x8e, 0x2e, 0x8d, 0x00, 0xaf, 0x5b, 0x7a, 0xc0, 0xb9, + 0x1f, 0xad, 0x19, 0x4e, 0x45, 0x79, 0x2e, 0xad, 0x44, 0xf0, 0x0a, 0x02, + 0x21, 0x00, 0x56, 0x71, 0x92, 0xe0, 0x0f, 0x02, 0x20, 0x00, 0xc5, 0x21, + 0x21, 0x26, 0xc3, 0x41, 0xa0, 0x00, 0x08, 0x41, 0x22, 0xd8, 0x55, 0x8d, + 0xc0, 0xdb, 0x2f, 0x24, 0x02, 0x04, 0x09, 0x16, 0x88, 0x10, 0x06, 0x16, + 0x0b, 0x11, 0x44, 0x24, 0x07, 0x11, 0x41, 0x29, 0x0c, 0x23, 0x53, 0x20, + 0x86, 0x20, 0x02, 0xa5, 0x01, 0xa5, 0x20, 0xa5, 0x04, 0x21, 0xc1, 0x20, + 0x44, 0x24, 0x00, 0x02, 0x44, 0x24, 0x09, 0x12, 0x6c, 0x24, 0xcc, 0x00, + 0x26, 0xb9, 0x05, 0x20, 0x80, 0x01, 0x41, 0x29, 0x85, 0x23, 0x05, 0x21, + 0xc1, 0x01, 0x85, 0x78, 0x84, 0x22, 0x02, 0x00, 0x44, 0x25, 0x43, 0x00, + 0x05, 0x21, 0x41, 0x02, 0x45, 0x78, 0x73, 0xad, 0x34, 0xad, 0x15, 0xad, + 0x03, 0x96, 0x10, 0x1d, 0xc4, 0x12, 0x12, 0x1d, 0x02, 0x12, 0x1f, 0xad, + 0x28, 0xb8, 0x00, 0xaf, 0xfa, 0x09, 0x60, 0x00, 0xa1, 0x40, 0x19, 0x4e, + 0x00, 0x88, 0x02, 0xaf, 0x41, 0x29, 0x00, 0x22, 0x44, 0x21, 0x17, 0xa1, + 0xd3, 0x42, 0xa0, 0x00, 0x44, 0x87, 0x1d, 0x1d, 0x42, 0x14, 0x01, 0x1f, + 0x02, 0x14, 0x1e, 0xad, 0x12, 0xf2, 0xc5, 0xb8, 0xd3, 0x46, 0x4c, 0x3d, + 0xcd, 0xcc, 0x11, 0x08, 0x74, 0x01, 0x63, 0xb8, 0x48, 0x30, 0x80, 0x00, + 0x00, 0x30, 0x96, 0x05, 0x27, 0x09, 0x1f, 0x20, 0xd3, 0x40, 0x12, 0x00, + 0x50, 0x4b, 0x08, 0xf0, 0x23, 0x09, 0x3f, 0x20, 0xce, 0x70, 0xd3, 0x40, + 0x12, 0x00, 0x4c, 0x4b, 0x40, 0x23, 0xc0, 0x24, 0x6c, 0x20, 0x40, 0x00, + 0x00, 0x1a, 0x00, 0x24, 0x10, 0xf0, 0xd3, 0x40, 0x12, 0x00, 0x7c, 0x4b, + 0x04, 0xf0, 0xd3, 0x40, 0x12, 0x00, 0x78, 0x4b, 0x9c, 0x4e, 0x05, 0x6f, + 0x62, 0x42, 0x32, 0x0f, 0xaf, 0xee, 0x00, 0x1a, 0x00, 0x24, 0x10, 0xd8, + 0x40, 0x27, 0x55, 0x11, 0xf6, 0x70, 0xd3, 0x47, 0x12, 0x00, 0x38, 0x58, + 0x0d, 0xb5, 0x0f, 0xf2, 0x40, 0x25, 0x05, 0x16, 0xa1, 0x40, 0x82, 0x41, + 0xa2, 0x42, 0x62, 0x43, 0x0a, 0x24, 0xc0, 0x05, 0x23, 0x20, 0x00, 0x04, + 0x0a, 0x26, 0x80, 0x05, 0xd8, 0xc6, 0x15, 0x09, 0x7f, 0x20, 0x40, 0x25, + 0x05, 0x16, 0xa1, 0x40, 0x82, 0x41, 0xa2, 0x42, 0x62, 0x43, 0x2c, 0xf0, + 0x42, 0x23, 0x51, 0x20, 0x2f, 0x26, 0x47, 0xf4, 0x1f, 0xf2, 0x40, 0x25, + 0x18, 0x16, 0x0a, 0x26, 0x40, 0x24, 0x8a, 0x46, 0xcf, 0x79, 0x6c, 0x71, + 0x8c, 0x70, 0xa1, 0x40, 0xa2, 0x42, 0x23, 0x20, 0x00, 0x04, 0x0a, 0x25, + 0x00, 0x06, 0x00, 0x12, 0x10, 0x20, 0xc6, 0x77, 0xa6, 0x71, 0x2f, 0x26, + 0x87, 0xf5, 0xc5, 0x71, 0xf0, 0xf5, 0x42, 0x23, 0x81, 0x20, 0x06, 0x6f, + 0x2f, 0x7a, 0x00, 0x24, 0x54, 0x24, 0x00, 0x22, 0x15, 0x00, 0x2f, 0x21, + 0x07, 0x05, 0x40, 0x25, 0x05, 0x16, 0x6c, 0x71, 0xa1, 0x40, 0xa2, 0x42, + 0x23, 0x20, 0x00, 0x04, 0x0a, 0x24, 0xc0, 0x05, 0xd8, 0xc6, 0x46, 0x21, + 0x11, 0x26, 0x4f, 0x21, 0x11, 0x21, 0x08, 0x95, 0x52, 0x8d, 0x95, 0x8d, + 0x74, 0x8d, 0x13, 0x15, 0x89, 0x10, 0x8a, 0x23, 0x01, 0x10, 0x1f, 0xad, + 0x42, 0xaf, 0x41, 0x28, 0x02, 0x02, 0x9b, 0x78, 0x36, 0x6b, 0x40, 0x2b, + 0xc8, 0x00, 0x04, 0x21, 0x86, 0x2f, 0x00, 0x00, 0x1f, 0x3f, 0xc2, 0xbc, + 0x44, 0x21, 0x51, 0x10, 0x40, 0xaf, 0x6c, 0x20, 0x09, 0x01, 0x44, 0x20, + 0x02, 0x04, 0x04, 0x21, 0xc0, 0x02, 0x44, 0x20, 0x0b, 0x18, 0x45, 0x7c, + 0x05, 0x26, 0xc2, 0x02, 0x0c, 0xbb, 0x84, 0x21, 0x02, 0x00, 0x45, 0x78, + 0x04, 0x23, 0x83, 0x0f, 0x0f, 0x00, 0x00, 0x80, 0x25, 0x78, 0x40, 0x29, + 0x91, 0x23, 0x65, 0x78, 0x05, 0x24, 0x50, 0x12, 0x05, 0x21, 0x11, 0x20, + 0x42, 0xf1, 0x46, 0x21, 0x11, 0x26, 0xcf, 0x21, 0x21, 0x21, 0xcf, 0x21, + 0xe2, 0x20, 0x0e, 0x8d, 0x0e, 0x70, 0x00, 0x1f, 0x02, 0x14, 0x1f, 0x1d, + 0x02, 0x14, 0x1d, 0x78, 0x33, 0xf1, 0xe0, 0x78, 0xc3, 0x41, 0xa0, 0x00, + 0x54, 0x87, 0x40, 0x81, 0x00, 0x43, 0x07, 0xea, 0x40, 0x40, 0x43, 0x82, + 0xfe, 0xea, 0x63, 0xa0, 0x02, 0xf0, 0x60, 0xa1, 0x0c, 0x70, 0xe0, 0x7f, + 0x0c, 0x1b, 0x01, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0x48, 0x87, 0x21, 0x80, + 0xe0, 0x7f, 0x00, 0x80, 0xe4, 0xc2, 0xcb, 0x45, 0xa0, 0x00, 0x48, 0x87, + 0xc4, 0x88, 0x08, 0x8d, 0x39, 0x0e, 0x00, 0x10, 0x17, 0x0e, 0x91, 0x10, + 0xc2, 0x0a, 0x4f, 0xfa, 0x21, 0xa5, 0x00, 0xa5, 0x3b, 0xd8, 0xc3, 0x41, + 0x12, 0x00, 0x84, 0x5b, 0x07, 0xf0, 0x1f, 0x08, 0xb1, 0x00, 0x3b, 0xd8, + 0xc3, 0x41, 0x11, 0x00, 0x64, 0xa6, 0x9a, 0x0e, 0x00, 0x00, 0x0c, 0x71, + 0x6b, 0x20, 0x00, 0x04, 0xe0, 0x78, 0xe0, 0x78, 0xe0, 0x78, 0xc8, 0xad, + 0xc4, 0xc6, 0xe0, 0x78, 0xea, 0xc2, 0x21, 0x90, 0xa4, 0x68, 0xcb, 0x47, + 0xa0, 0x00, 0x48, 0x87, 0x38, 0x60, 0x8a, 0x20, 0x83, 0x28, 0x40, 0x20, + 0x11, 0x01, 0x00, 0x8d, 0x8c, 0x20, 0x03, 0x8c, 0x48, 0x00, 0x25, 0x00, + 0xc1, 0x6d, 0x28, 0x8f, 0xb5, 0x09, 0xb1, 0x00, 0x00, 0x41, 0x80, 0x21, + 0xfc, 0x02, 0xa5, 0x09, 0x75, 0x02, 0x41, 0xda, 0x77, 0x0a, 0x6f, 0x00, + 0x82, 0xda, 0x7f, 0x0a, 0x6f, 0x00, 0x8a, 0x22, 0x04, 0x01, 0x91, 0x0a, + 0x4e, 0x00, 0x24, 0x8e, 0x21, 0xa7, 0x41, 0x8e, 0x63, 0x8e, 0x20, 0x8e, + 0x82, 0x8e, 0x08, 0xba, 0x08, 0xbb, 0x25, 0x7a, 0x05, 0x23, 0x01, 0x03, + 0x10, 0xb9, 0x45, 0x79, 0x20, 0xa7, 0x3c, 0xf0, 0x7d, 0x08, 0x30, 0x00, + 0xa5, 0x72, 0xa3, 0x87, 0x07, 0x00, 0x00, 0x00, 0xa3, 0x85, 0x77, 0x0d, + 0x10, 0x10, 0x20, 0x85, 0x24, 0x89, 0xf9, 0x09, 0x01, 0x80, 0x08, 0x8f, + 0x0b, 0x08, 0x51, 0x00, 0x3b, 0x58, 0x21, 0xa7, 0x00, 0xa7, 0x48, 0x8d, + 0x01, 0x85, 0xfe, 0x0c, 0xaf, 0xee, 0xc1, 0x41, 0x40, 0x85, 0xa8, 0x8d, + 0xb9, 0x12, 0xc0, 0x00, 0x45, 0x08, 0x33, 0x00, 0xdd, 0x65, 0x21, 0x87, + 0x00, 0x87, 0x72, 0x58, 0x1c, 0xf0, 0x40, 0x8e, 0x20, 0x87, 0x61, 0x87, + 0x00, 0x22, 0x42, 0x80, 0x09, 0xf0, 0x21, 0x8e, 0x40, 0x8e, 0x80, 0x87, + 0x08, 0xb9, 0x61, 0x87, 0x45, 0x79, 0x00, 0x24, 0x42, 0x90, 0x41, 0x23, + 0x01, 0x80, 0x21, 0xa7, 0x40, 0xa7, 0x06, 0xf0, 0x00, 0x1e, 0x02, 0x74, + 0xf0, 0x00, 0x48, 0x00, 0x26, 0x0d, 0x2f, 0xfa, 0x2c, 0x70, 0x1d, 0x65, + 0x37, 0x0d, 0x44, 0x94, 0xca, 0xc6, 0xe2, 0xd8, 0x00, 0x1e, 0x02, 0x70, + 0xf0, 0x00, 0x48, 0x00, 0xca, 0xc6, 0xe0, 0x78, 0xf1, 0xc0, 0xa3, 0xc1, + 0xc3, 0x42, 0xa0, 0x00, 0x50, 0x87, 0x40, 0x8a, 0x0a, 0xea, 0x04, 0x88, + 0x41, 0xc1, 0x2c, 0x74, 0x93, 0xb9, 0x40, 0xc1, 0x62, 0xc0, 0x0c, 0x71, + 0x80, 0xc1, 0x64, 0x58, 0xa3, 0xc0, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0xe6, 0xc2, 0x42, 0x23, 0x3c, 0x80, 0x15, 0xf2, 0xcd, 0x70, 0xad, 0x70, + 0xa8, 0x20, 0x40, 0x04, 0x97, 0x6d, 0x5c, 0x64, 0x2f, 0x27, 0xff, 0x02, + 0x6f, 0x23, 0x3f, 0x00, 0xf3, 0x8c, 0x06, 0xef, 0xd3, 0xac, 0x0e, 0x1c, + 0x43, 0x10, 0xd0, 0xa4, 0x2f, 0x26, 0xff, 0x02, 0xa5, 0x71, 0x8a, 0x09, + 0x8f, 0xf9, 0xc6, 0xc6, 0x00, 0x16, 0x1d, 0x70, 0xa0, 0x00, 0x04, 0x47, + 0x09, 0x24, 0x4c, 0x17, 0xf0, 0x26, 0x1d, 0x73, 0xa0, 0x00, 0x20, 0x6c, + 0xab, 0x25, 0x10, 0x30, 0xaa, 0x25, 0x90, 0x30, 0x35, 0x0d, 0xfe, 0x31, + 0x50, 0x25, 0xdd, 0x31, 0xab, 0x25, 0x90, 0x30, 0x67, 0x24, 0x40, 0x33, + 0xfc, 0x1c, 0xc8, 0xb7, 0xaa, 0x25, 0x09, 0x38, 0xa7, 0x25, 0x09, 0x39, + 0xfc, 0x1c, 0x48, 0xb7, 0xaa, 0x25, 0x49, 0x38, 0xa7, 0x25, 0x49, 0x39, + 0xfc, 0x1c, 0x48, 0xb7, 0x0a, 0x27, 0x80, 0x3f, 0x11, 0x00, 0x3c, 0xc8, + 0x6f, 0x24, 0x3f, 0x00, 0xaa, 0x27, 0x90, 0x30, 0x4f, 0x27, 0xdf, 0x31, + 0xab, 0x27, 0x90, 0x30, 0x04, 0x14, 0x1d, 0x34, 0xab, 0x25, 0x49, 0x39, + 0x04, 0x14, 0x1d, 0x34, 0xab, 0x25, 0x09, 0x39, 0x04, 0x14, 0x1f, 0x34, + 0x67, 0x24, 0x40, 0x33, 0xab, 0x27, 0x10, 0x30, 0x6f, 0x24, 0x3f, 0x00, + 0xc3, 0x42, 0xa0, 0x00, 0x60, 0x87, 0x39, 0xa2, 0xe0, 0x7f, 0x18, 0xa2, + 0xf1, 0xc0, 0x26, 0x0a, 0x0f, 0xfd, 0xc3, 0x40, 0xa0, 0x00, 0x08, 0x47, + 0x40, 0x20, 0x02, 0x0a, 0xcc, 0x48, 0x20, 0xe0, 0x00, 0x1a, 0x80, 0x0f, + 0x12, 0x00, 0x7c, 0x5d, 0x00, 0x19, 0x80, 0x0f, 0x12, 0x00, 0x28, 0x5d, + 0x00, 0x18, 0x80, 0x0f, 0x12, 0x00, 0x62, 0x61, 0xd1, 0xc0, 0xe0, 0x7e, + 0x05, 0xeb, 0x15, 0x22, 0xcc, 0x00, 0xfc, 0x1c, 0xc0, 0x90, 0xf9, 0x07, + 0x0f, 0xfe, 0xe0, 0x78, 0x00, 0x42, 0x06, 0xe8, 0x10, 0x8a, 0xe7, 0xb8, + 0x0c, 0x77, 0xe0, 0x7d, 0x05, 0x02, 0xef, 0xfe, 0x40, 0x40, 0xe0, 0x78, + 0xea, 0xc2, 0x00, 0x10, 0x10, 0x00, 0x08, 0x45, 0x58, 0x20, 0x4e, 0x01, + 0x70, 0xb8, 0x70, 0x41, 0xaa, 0x0d, 0xef, 0xfc, 0x28, 0x47, 0xc3, 0x41, + 0x00, 0x80, 0x1e, 0x40, 0x36, 0x71, 0xd5, 0x21, 0x22, 0x08, 0xe4, 0xa6, + 0x04, 0x1d, 0x50, 0x10, 0x18, 0x25, 0x02, 0x14, 0x07, 0xf4, 0x2c, 0x70, + 0x04, 0x1e, 0x01, 0x10, 0xa3, 0xa6, 0x42, 0xa6, 0x0a, 0xf0, 0xc3, 0x41, + 0xa0, 0x00, 0x60, 0x87, 0x98, 0x81, 0x79, 0x81, 0x40, 0x41, 0xa1, 0xa6, + 0x83, 0xa6, 0x62, 0xa6, 0x20, 0xa6, 0xca, 0xc6, 0x0c, 0x70, 0x54, 0x70, + 0xab, 0x20, 0x50, 0x02, 0xe0, 0x7c, 0xc3, 0x40, 0xa0, 0x00, 0xb8, 0x87, + 0xe0, 0x7f, 0x40, 0xa0, 0xee, 0xc2, 0x4e, 0x70, 0xcb, 0x46, 0xa0, 0x00, + 0x60, 0x87, 0x8a, 0x21, 0x90, 0x28, 0x52, 0x40, 0xa4, 0x6e, 0xab, 0x22, + 0x50, 0x22, 0x00, 0x85, 0x40, 0x21, 0x53, 0x20, 0x0c, 0xe8, 0x20, 0x86, + 0xe1, 0x85, 0x80, 0xb9, 0x2b, 0x21, 0x40, 0x04, 0x2a, 0x0f, 0x0f, 0xfe, + 0xe5, 0x78, 0x2b, 0x20, 0xc0, 0x04, 0x06, 0xf0, 0x2b, 0x22, 0x40, 0x24, + 0x2b, 0x22, 0xc0, 0x24, 0x06, 0x71, 0x0c, 0xe6, 0x26, 0x72, 0xd7, 0x08, + 0x34, 0xa2, 0x0c, 0xe5, 0xce, 0xc6, 0xe0, 0x78, 0xee, 0xc2, 0xd9, 0x88, + 0x08, 0x45, 0x30, 0x43, 0xc1, 0xbe, 0xa2, 0x08, 0x6f, 0xfb, 0xa1, 0x40, + 0x4e, 0x70, 0x0e, 0x71, 0x0a, 0xe8, 0x1f, 0x0e, 0xb5, 0x10, 0xa1, 0x40, + 0x35, 0x58, 0x13, 0x0b, 0x25, 0x20, 0x0c, 0x71, 0x2e, 0x70, 0x40, 0xf0, + 0x0c, 0x71, 0x10, 0x41, 0x3c, 0xf0, 0x0d, 0x8d, 0x03, 0xe8, 0xe0, 0x85, + 0x05, 0xf0, 0x0d, 0x1d, 0x43, 0x10, 0xa9, 0x47, 0x02, 0xf0, 0x1c, 0xef, + 0x6a, 0x08, 0x6f, 0xfb, 0xe1, 0x40, 0x11, 0xe8, 0xe1, 0x40, 0x35, 0x58, + 0x1b, 0x08, 0xc1, 0x04, 0x55, 0x87, 0x05, 0xea, 0x39, 0x87, 0x60, 0x7a, + 0xe1, 0x40, 0x19, 0x0f, 0x60, 0x13, 0xe1, 0x40, 0x5e, 0x0b, 0x0f, 0xf9, + 0x06, 0xf0, 0x46, 0x08, 0x6f, 0xfb, 0xe1, 0x40, 0x02, 0xe8, 0x0e, 0x70, + 0xe0, 0x87, 0xe7, 0xf1, 0x16, 0x70, 0x15, 0xf2, 0x46, 0x0b, 0x2f, 0xf9, + 0xa1, 0x40, 0x0b, 0x0e, 0x90, 0x10, 0x0d, 0x1d, 0x03, 0x10, 0x10, 0x8d, + 0x14, 0x70, 0x0b, 0xf2, 0x10, 0x1d, 0x03, 0x10, 0x9e, 0x78, 0x2c, 0x70, + 0x4c, 0x71, 0xa1, 0x40, 0x91, 0x58, 0xbe, 0x78, 0x4e, 0x71, 0x79, 0x20, + 0x10, 0x20, 0x0c, 0x70, 0x83, 0xe8, 0x56, 0x70, 0xb1, 0xf5, 0x14, 0x70, + 0xca, 0x20, 0x42, 0x24, 0x02, 0x40, 0xce, 0xc6, 0x00, 0x1e, 0x00, 0x70, + 0xa0, 0x00, 0xe0, 0x47, 0x6a, 0x20, 0x80, 0x02, 0xae, 0xb8, 0xbf, 0xb8, + 0x29, 0x20, 0x00, 0x80, 0xaa, 0x20, 0xc1, 0x00, 0x51, 0x20, 0xc0, 0x87, + 0xbf, 0xb8, 0xab, 0x20, 0xc1, 0x00, 0xe7, 0x24, 0x62, 0x33, 0xc7, 0x40, + 0xa0, 0x00, 0xe0, 0x47, 0x64, 0x1c, 0x08, 0xb0, 0xaa, 0x20, 0x49, 0x09, + 0x98, 0x1c, 0x00, 0x30, 0xaa, 0x20, 0x09, 0x09, 0x94, 0x1c, 0x00, 0x30, + 0xaa, 0x20, 0x49, 0x08, 0x90, 0x1c, 0x00, 0x30, 0xaa, 0x20, 0x09, 0x08, + 0x8c, 0x1c, 0x00, 0x30, 0x0a, 0x20, 0x00, 0x0f, 0x88, 0x1c, 0x00, 0x30, + 0x6a, 0x20, 0x80, 0x00, 0x84, 0x1c, 0x00, 0x30, 0x6a, 0x20, 0xc0, 0x00, + 0x80, 0x1c, 0x00, 0x30, 0x7c, 0x1c, 0xc0, 0x37, 0x78, 0x1c, 0x80, 0x37, + 0x74, 0x1c, 0x40, 0x37, 0xaa, 0x20, 0x50, 0x00, 0x5c, 0xc0, 0x6c, 0x1c, + 0xc0, 0x36, 0x68, 0x1c, 0x80, 0x36, 0x64, 0x1c, 0x40, 0x36, 0x60, 0x1c, + 0x00, 0x36, 0x5c, 0x1c, 0xc0, 0x35, 0x58, 0x1c, 0x80, 0x35, 0x54, 0x1c, + 0x40, 0x35, 0x50, 0x1c, 0x00, 0x35, 0x4c, 0x1c, 0xc0, 0x34, 0x48, 0x1c, + 0x80, 0x34, 0x44, 0x1c, 0x40, 0x34, 0x40, 0x1c, 0x00, 0x34, 0x4f, 0xc7, + 0x4e, 0xc6, 0x4d, 0xc5, 0x4c, 0xc4, 0x2c, 0x1c, 0xc0, 0x32, 0x28, 0x1c, + 0x80, 0x32, 0x24, 0x1c, 0x40, 0x32, 0x20, 0x1c, 0x00, 0x32, 0x1c, 0x1c, + 0xc0, 0x31, 0x18, 0x1c, 0x80, 0x31, 0x14, 0x1c, 0x40, 0x31, 0x10, 0x1c, + 0x00, 0x31, 0x43, 0xc3, 0x42, 0xc2, 0x41, 0xc1, 0xaa, 0x20, 0x48, 0x00, + 0x42, 0x20, 0x00, 0x84, 0x1e, 0x00, 0x01, 0x00, 0x6a, 0x21, 0x80, 0x08, + 0x44, 0x21, 0xc1, 0x00, 0x6b, 0x21, 0x80, 0x08, 0x22, 0x20, 0x80, 0x0f, + 0x12, 0x00, 0xd0, 0x39, 0x14, 0x70, 0x2a, 0x00, 0x01, 0x00, 0xab, 0x20, + 0x48, 0x00, 0x00, 0x16, 0x0a, 0x70, 0xa0, 0x00, 0xac, 0x46, 0x00, 0x1a, + 0x00, 0x17, 0x22, 0x20, 0x80, 0x0f, 0x12, 0x00, 0xec, 0x2a, 0x00, 0x16, + 0x0a, 0x70, 0xa0, 0x00, 0xac, 0x46, 0x00, 0x12, 0x1c, 0x10, 0x98, 0x14, + 0x1e, 0x30, 0xab, 0x26, 0x49, 0x39, 0x94, 0x14, 0x1e, 0x30, 0xab, 0x26, + 0x09, 0x39, 0x90, 0x14, 0x1e, 0x30, 0xab, 0x26, 0x49, 0x38, 0x8c, 0x14, + 0x1e, 0x30, 0xab, 0x26, 0x09, 0x38, 0x88, 0x14, 0x1e, 0x30, 0x0a, 0x24, + 0x80, 0x77, 0x84, 0x14, 0x1e, 0x30, 0x6b, 0x26, 0x80, 0x30, 0x80, 0x14, + 0x1e, 0x30, 0x6b, 0x26, 0xc0, 0x30, 0x7c, 0x14, 0x1f, 0x30, 0x78, 0x14, + 0x1e, 0x30, 0x74, 0x14, 0x1d, 0x30, 0x6c, 0x14, 0x1b, 0x30, 0x68, 0x14, + 0x1a, 0x30, 0x64, 0x14, 0x19, 0x30, 0x60, 0x14, 0x18, 0x30, 0x5c, 0x14, + 0x17, 0x30, 0x58, 0x14, 0x16, 0x30, 0x54, 0x14, 0x15, 0x30, 0x50, 0x14, + 0x14, 0x30, 0x4c, 0x14, 0x13, 0x30, 0x48, 0x14, 0x12, 0x30, 0x44, 0x14, + 0x11, 0x30, 0x40, 0x14, 0x10, 0x30, 0x0f, 0xc7, 0x0e, 0xc6, 0x0d, 0xc5, + 0x0c, 0xc4, 0x2c, 0x14, 0x0b, 0x30, 0x28, 0x14, 0x0a, 0x30, 0x24, 0x14, + 0x09, 0x30, 0x20, 0x14, 0x08, 0x30, 0x1c, 0x14, 0x07, 0x30, 0x18, 0x14, + 0x06, 0x30, 0x14, 0x14, 0x05, 0x30, 0x10, 0x14, 0x04, 0x30, 0x03, 0xc3, + 0x02, 0xc2, 0x01, 0xc1, 0x1c, 0xc0, 0xab, 0x20, 0x50, 0x00, 0x9c, 0x14, + 0x00, 0x34, 0x6f, 0x23, 0x3f, 0x00, 0x6f, 0x24, 0x3f, 0x00, 0xe0, 0x78, + 0xfc, 0x1c, 0x08, 0xb0, 0xaa, 0x20, 0x48, 0x00, 0x0b, 0x08, 0x10, 0x00, + 0x0c, 0x70, 0xab, 0x20, 0x48, 0x00, 0x10, 0xd8, 0xab, 0x20, 0x48, 0x00, + 0x04, 0x14, 0x00, 0x34, 0xe0, 0x7e, 0xe2, 0x08, 0x00, 0x00, 0x98, 0x14, + 0x1e, 0x30, 0x6b, 0x26, 0x40, 0x33, 0x98, 0x14, 0x1e, 0x30, 0xab, 0x26, + 0x49, 0x39, 0x94, 0x14, 0x1e, 0x30, 0xab, 0x26, 0x09, 0x39, 0x90, 0x14, + 0x1e, 0x30, 0xab, 0x26, 0x49, 0x38, 0x8c, 0x14, 0x1e, 0x30, 0xab, 0x26, + 0x09, 0x38, 0x88, 0x14, 0x1e, 0x30, 0x0a, 0x24, 0x80, 0x77, 0x84, 0x14, + 0x1e, 0x30, 0x6b, 0x26, 0x80, 0x30, 0x80, 0x14, 0x1e, 0x30, 0x6b, 0x26, + 0xc0, 0x30, 0x7c, 0x14, 0x1f, 0x30, 0x78, 0x14, 0x1e, 0x30, 0x74, 0x14, + 0x1d, 0x30, 0x6c, 0x14, 0x1b, 0x30, 0x68, 0x14, 0x1a, 0x30, 0x64, 0x14, + 0x19, 0x30, 0x60, 0x14, 0x18, 0x30, 0x5c, 0x14, 0x17, 0x30, 0x58, 0x14, + 0x16, 0x30, 0x54, 0x14, 0x15, 0x30, 0x50, 0x14, 0x14, 0x30, 0x4c, 0x14, + 0x13, 0x30, 0x48, 0x14, 0x12, 0x30, 0x44, 0x14, 0x11, 0x30, 0x40, 0x14, + 0x10, 0x30, 0x0f, 0xc7, 0x0e, 0xc6, 0x0d, 0xc5, 0x0c, 0xc4, 0x2c, 0x14, + 0x0b, 0x30, 0x28, 0x14, 0x0a, 0x30, 0x24, 0x14, 0x09, 0x30, 0x20, 0x14, + 0x08, 0x30, 0x1c, 0x14, 0x07, 0x30, 0x18, 0x14, 0x06, 0x30, 0x14, 0x14, + 0x05, 0x30, 0x10, 0x14, 0x04, 0x30, 0x03, 0xc3, 0x02, 0xc2, 0x01, 0xc1, + 0x1c, 0xc0, 0xab, 0x20, 0x50, 0x00, 0x9c, 0x14, 0x00, 0x30, 0xab, 0x20, + 0x10, 0x00, 0xa0, 0x14, 0x00, 0x30, 0xab, 0x20, 0x90, 0x00, 0x51, 0x20, + 0xc0, 0x87, 0xa4, 0x14, 0x00, 0x34, 0x6f, 0x23, 0x3f, 0x00, 0x0a, 0x00, + 0x01, 0x00, 0x67, 0x24, 0x40, 0x33, 0x6f, 0x24, 0x3f, 0x00, 0xe0, 0x78, + 0x00, 0x16, 0x0a, 0x70, 0xa0, 0x00, 0xac, 0x46, 0x00, 0x12, 0x1c, 0x10, + 0xc3, 0x40, 0x00, 0x40, 0x00, 0x00, 0xab, 0x20, 0x50, 0x02, 0xe0, 0x7e, + 0xe2, 0xc0, 0xaa, 0x24, 0x0a, 0x14, 0x15, 0x7c, 0x92, 0x49, 0x8a, 0x20, + 0x9f, 0x0f, 0x44, 0x78, 0x41, 0x2a, 0x43, 0x01, 0x35, 0xba, 0x4f, 0x20, + 0x0d, 0x00, 0x04, 0x23, 0x81, 0x0f, 0x00, 0x00, 0xc0, 0xff, 0x53, 0x22, + 0xc0, 0x00, 0x25, 0x78, 0xa0, 0xb4, 0x01, 0xb4, 0xc2, 0xc4, 0xe0, 0x78, + 0xe8, 0xc2, 0xcb, 0x45, 0xa0, 0x00, 0xec, 0x87, 0x48, 0x46, 0x28, 0x47, + 0x10, 0x40, 0xc3, 0x40, 0xa0, 0x00, 0x94, 0x40, 0x2a, 0xda, 0xc6, 0x0e, + 0x6f, 0xee, 0xa1, 0x41, 0xdc, 0x4d, 0xc3, 0x40, 0xa0, 0x00, 0xc0, 0x40, + 0xb6, 0x0e, 0x6f, 0xee, 0x2a, 0xda, 0x02, 0x40, 0xe1, 0x41, 0x1a, 0x0b, + 0xaf, 0xfa, 0xc1, 0x42, 0xc8, 0xc6, 0xe0, 0x78, 0xcb, 0x44, 0xf0, 0x00, + 0x00, 0x01, 0x14, 0x8c, 0x17, 0x08, 0x9f, 0x01, 0x14, 0x8c, 0x13, 0x08, + 0x5f, 0x01, 0x0b, 0x94, 0x0b, 0x08, 0x1f, 0x00, 0x14, 0x8c, 0xe4, 0xb8, + 0xe0, 0x7c, 0x14, 0x8c, 0xc3, 0x41, 0xf0, 0x00, 0x34, 0x00, 0x45, 0xda, + 0x15, 0xa9, 0x76, 0x8c, 0x70, 0xd8, 0x90, 0xb8, 0x76, 0xa9, 0x54, 0xa9, + 0x05, 0xa4, 0x45, 0xd8, 0xc1, 0x07, 0xef, 0xf3, 0x2c, 0x70, 0xe0, 0x78, + 0xc3, 0x40, 0xf0, 0x00, 0x00, 0x01, 0x2d, 0x88, 0x0c, 0x88, 0xc2, 0xb9, + 0x24, 0xb8, 0xc0, 0xb8, 0x47, 0x20, 0xc0, 0x01, 0x09, 0x20, 0x40, 0x00, + 0xe0, 0x7f, 0x04, 0x71, 0xc3, 0x40, 0xf0, 0x00, 0x00, 0x01, 0x2d, 0x88, + 0x0c, 0x88, 0xc2, 0xb9, 0x24, 0xb8, 0xc0, 0xb8, 0x47, 0x20, 0xc0, 0x01, + 0x09, 0x20, 0x41, 0x00, 0x22, 0x78, 0x04, 0x71, 0xe0, 0x7f, 0x0f, 0x78, + 0x6d, 0x02, 0x0f, 0xf5, 0x55, 0x02, 0x0f, 0xf5, 0x79, 0x02, 0x0f, 0xf5, + 0xf1, 0xc0, 0x8a, 0x09, 0x0f, 0xf5, 0x11, 0x08, 0x74, 0x02, 0x42, 0x20, + 0x41, 0x02, 0x09, 0x09, 0x54, 0x02, 0xff, 0xd8, 0xd1, 0xc0, 0xe0, 0x7e, + 0xf1, 0xc0, 0x52, 0x0f, 0xcf, 0xf1, 0x14, 0x70, 0x0c, 0x70, 0x23, 0xf2, + 0xc3, 0x41, 0xa0, 0x00, 0xe8, 0x42, 0x24, 0x89, 0x2b, 0x09, 0xd0, 0x00, + 0x2d, 0x09, 0x50, 0x00, 0x2f, 0x09, 0x90, 0x00, 0x97, 0xe9, 0xc3, 0x40, + 0xa0, 0x00, 0xc4, 0x45, 0x00, 0x88, 0x44, 0x20, 0x00, 0x02, 0x10, 0xb8, + 0x52, 0x20, 0xc0, 0x04, 0x00, 0x20, 0x80, 0x0f, 0x08, 0x00, 0x00, 0x00, + 0x09, 0xf0, 0x0c, 0x70, 0x97, 0xb8, 0x07, 0xf0, 0x0c, 0x70, 0x95, 0xb8, + 0x03, 0xf0, 0x0c, 0x70, 0x96, 0xb8, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0x55, 0x88, 0x74, 0x88, 0x78, 0xd9, 0x44, 0x79, 0x04, 0xba, 0xc3, 0xbb, + 0x84, 0x22, 0x01, 0x0c, 0x87, 0xb9, 0x65, 0x7a, 0x35, 0xa8, 0xe0, 0x7f, + 0x54, 0xa8, 0xe0, 0x78, 0xe2, 0xc0, 0x64, 0x88, 0x05, 0x88, 0x24, 0xbb, + 0x00, 0x29, 0xcc, 0x00, 0x6c, 0x71, 0x41, 0x28, 0xcd, 0x00, 0x41, 0x28, + 0x01, 0x01, 0x06, 0x23, 0x40, 0x03, 0xc2, 0xb9, 0x47, 0x78, 0x38, 0x78, + 0x05, 0x7c, 0x8f, 0x78, 0xc2, 0xc4, 0xe0, 0x78, 0xee, 0xc3, 0xa1, 0xc1, + 0x08, 0x46, 0x14, 0x88, 0x24, 0x86, 0xf5, 0x68, 0x3f, 0x67, 0x28, 0x8f, + 0x03, 0x86, 0x00, 0x1e, 0x00, 0x70, 0xf0, 0x00, 0x2c, 0x01, 0x1c, 0xe9, + 0x40, 0x87, 0x69, 0x8f, 0x01, 0x86, 0x40, 0x27, 0x11, 0x14, 0x03, 0x12, + 0x8b, 0x00, 0x82, 0x8a, 0x44, 0x23, 0x12, 0x82, 0x0a, 0x20, 0x40, 0x24, + 0x03, 0xf4, 0x00, 0x11, 0x10, 0x20, 0x0d, 0x71, 0x29, 0x0b, 0x3f, 0x00, + 0xad, 0x71, 0x1d, 0x0a, 0x30, 0x20, 0x28, 0x45, 0x1d, 0x09, 0x54, 0x01, + 0xad, 0x74, 0x0c, 0xf0, 0x22, 0x86, 0x00, 0x1c, 0x01, 0x30, 0x00, 0xc0, + 0x00, 0xa1, 0xce, 0xc7, 0x09, 0x09, 0x34, 0x04, 0x28, 0x45, 0x10, 0xdd, + 0x21, 0x87, 0x42, 0x86, 0x40, 0xc1, 0x00, 0xc1, 0x11, 0x08, 0x31, 0x20, + 0x20, 0xa2, 0x2c, 0x70, 0x23, 0xa0, 0x22, 0xa0, 0x21, 0xa0, 0x20, 0xa0, + 0x44, 0x23, 0x13, 0x81, 0x04, 0xf2, 0x4a, 0x8f, 0x22, 0x86, 0x4c, 0xa9, + 0x00, 0x28, 0x02, 0x13, 0x2f, 0x27, 0x3f, 0x03, 0x6f, 0x23, 0x3f, 0x00, + 0xc3, 0x41, 0xf0, 0x00, 0x40, 0x02, 0x13, 0x0b, 0x51, 0x10, 0x65, 0x81, + 0x65, 0x7a, 0x45, 0xa1, 0x2f, 0x26, 0x3f, 0x03, 0x06, 0xf0, 0x65, 0x81, + 0x46, 0x7b, 0x65, 0xa1, 0x2f, 0x26, 0x3f, 0x03, 0x0d, 0x08, 0x30, 0x20, + 0x02, 0x41, 0xb2, 0x0c, 0x6f, 0xee, 0xa1, 0x42, 0x11, 0x0b, 0x31, 0x20, + 0x53, 0x25, 0x01, 0x11, 0x42, 0x86, 0x0c, 0x70, 0x90, 0xb8, 0x06, 0xf0, + 0x42, 0x86, 0xc3, 0x40, 0x01, 0x00, 0x00, 0x01, 0x40, 0xc0, 0x60, 0xc1, + 0x00, 0xc0, 0x2b, 0x08, 0x30, 0x20, 0x01, 0xa2, 0x08, 0x8f, 0x23, 0x0d, + 0x05, 0x10, 0x21, 0x0a, 0x10, 0x20, 0x1b, 0x0d, 0x35, 0x11, 0x4e, 0x25, + 0x3c, 0x11, 0xb2, 0x4f, 0xa8, 0x20, 0xc0, 0x01, 0xb8, 0x67, 0x30, 0x88, + 0xb8, 0x62, 0xa5, 0x71, 0x30, 0xa8, 0xce, 0xc7, 0x02, 0x75, 0x00, 0x19, + 0x40, 0x23, 0xce, 0xc7, 0xee, 0xc3, 0xa3, 0xc1, 0x08, 0x46, 0x14, 0x88, + 0x24, 0x86, 0xf5, 0x68, 0x3f, 0x67, 0x28, 0x8f, 0x03, 0x86, 0x00, 0x1e, + 0x00, 0x70, 0xf0, 0x00, 0x2c, 0x01, 0x18, 0xe9, 0x49, 0x8f, 0x01, 0x86, + 0x40, 0x27, 0x11, 0x14, 0x44, 0x22, 0x13, 0x82, 0x50, 0x42, 0x0a, 0x20, + 0x40, 0x24, 0x04, 0xf4, 0x00, 0x11, 0x10, 0x20, 0x29, 0x0a, 0x3f, 0x20, + 0xad, 0x71, 0x1d, 0x0b, 0x30, 0x20, 0x28, 0x45, 0x1d, 0x09, 0x54, 0x01, + 0xad, 0x74, 0x0c, 0xf0, 0x22, 0x86, 0x08, 0x1c, 0x01, 0x30, 0x02, 0xc0, + 0x00, 0xa1, 0xce, 0xc7, 0x09, 0x09, 0x34, 0x04, 0x28, 0x45, 0x10, 0xdd, + 0x0d, 0x08, 0x30, 0x20, 0x02, 0x41, 0xfa, 0x0b, 0x6f, 0xee, 0xa1, 0x42, + 0x17, 0x0a, 0xbf, 0x20, 0x53, 0x25, 0x01, 0x11, 0x0c, 0x70, 0x90, 0xb8, + 0x42, 0x86, 0x41, 0xc0, 0x61, 0xc1, 0x01, 0xc0, 0x08, 0xf0, 0xc3, 0x40, + 0x01, 0x00, 0x00, 0x01, 0x42, 0x86, 0x40, 0xc0, 0x60, 0xc1, 0x00, 0xc0, + 0x2b, 0x08, 0x30, 0x20, 0x01, 0xa2, 0x08, 0x8f, 0x23, 0x0d, 0x05, 0x10, + 0x21, 0x0b, 0x10, 0x20, 0x1b, 0x0d, 0x35, 0x11, 0x4e, 0x25, 0x3c, 0x11, + 0x02, 0x27, 0x42, 0x13, 0xa8, 0x20, 0xc0, 0x01, 0xb8, 0x67, 0x30, 0x88, + 0xb8, 0x62, 0xa5, 0x71, 0x30, 0xa8, 0xce, 0xc7, 0x02, 0x75, 0x00, 0x19, + 0x40, 0x23, 0xce, 0xc7, 0xf0, 0xc2, 0x08, 0x45, 0x14, 0x88, 0x24, 0x85, + 0x10, 0xdf, 0xd5, 0x68, 0x3e, 0x66, 0x09, 0x8e, 0x20, 0x85, 0x0c, 0x16, + 0x11, 0x10, 0x08, 0x16, 0x90, 0x10, 0x44, 0x20, 0x54, 0x80, 0xca, 0x27, + 0x62, 0x10, 0x0f, 0x08, 0xbe, 0x00, 0x10, 0x42, 0x50, 0x22, 0x80, 0x20, + 0x09, 0xae, 0x13, 0x09, 0x30, 0x20, 0x09, 0x27, 0x13, 0x14, 0x22, 0x40, + 0x62, 0x0b, 0x6f, 0xee, 0x62, 0x42, 0x15, 0x0f, 0x25, 0x14, 0x02, 0x20, + 0xc0, 0x24, 0xc3, 0x41, 0x12, 0x00, 0xd0, 0x66, 0x08, 0xae, 0x27, 0xf0, + 0x14, 0x8d, 0x40, 0x86, 0x76, 0x8d, 0x04, 0x71, 0x0f, 0x79, 0x70, 0x71, + 0x22, 0x8a, 0x8d, 0x71, 0x63, 0x8a, 0xca, 0x20, 0x26, 0x00, 0x00, 0x2c, + 0x42, 0x10, 0x14, 0xad, 0x2f, 0x27, 0x3f, 0x03, 0x6f, 0x23, 0x3f, 0x00, + 0xc3, 0x40, 0xf0, 0x00, 0x40, 0x02, 0xc3, 0x41, 0x12, 0x00, 0xd8, 0x66, + 0x11, 0x0b, 0x51, 0x00, 0x65, 0x80, 0x46, 0x7b, 0x65, 0xa0, 0x2f, 0x26, + 0x3f, 0x03, 0x07, 0xf0, 0x65, 0x80, 0x65, 0x7a, 0x45, 0xa0, 0x2f, 0x26, + 0x3f, 0x03, 0x0d, 0x09, 0x30, 0x20, 0x00, 0x21, 0xc0, 0x24, 0x03, 0xa6, + 0x51, 0x22, 0x40, 0xa0, 0x2e, 0x70, 0x1f, 0xf2, 0x3d, 0x27, 0x02, 0x14, + 0x79, 0x24, 0x00, 0x20, 0x05, 0x20, 0xbe, 0x80, 0x17, 0xf2, 0x05, 0x86, + 0x04, 0x30, 0x40, 0x84, 0x26, 0x00, 0x2c, 0x00, 0xa1, 0x42, 0x0a, 0x0c, + 0x8f, 0xfd, 0x14, 0x70, 0x1a, 0x00, 0x2b, 0x00, 0x4a, 0x21, 0xc0, 0x28, + 0x03, 0x85, 0x00, 0x1e, 0x00, 0x70, 0xf0, 0x00, 0x2c, 0x01, 0x1f, 0x0f, + 0x25, 0x14, 0x2e, 0x70, 0x10, 0xf0, 0x0d, 0x0f, 0x25, 0x14, 0xa1, 0x40, + 0x95, 0xff, 0xd0, 0xc6, 0xa1, 0x40, 0x50, 0xff, 0x17, 0x8d, 0x04, 0x77, + 0x17, 0xad, 0x46, 0x86, 0x04, 0xea, 0x27, 0x86, 0x60, 0x7a, 0x22, 0x40, + 0xd0, 0xc6, 0xe0, 0x78, 0x39, 0x06, 0xef, 0xff, 0x20, 0x40, 0xe0, 0x78, + 0xe2, 0xc2, 0x20, 0x40, 0x28, 0x45, 0x47, 0xff, 0x17, 0x8d, 0x04, 0x77, + 0x17, 0xad, 0xc2, 0xc6, 0xf1, 0xc0, 0xc8, 0x44, 0x4a, 0x26, 0xc0, 0x01, + 0xf8, 0x1c, 0xc8, 0xb1, 0xe2, 0x0b, 0x6f, 0xf5, 0x81, 0x47, 0xa2, 0xc0, + 0xd1, 0xc0, 0xe0, 0x7e, 0xf1, 0xc0, 0xc8, 0x44, 0x4a, 0x26, 0xc0, 0x03, + 0xf8, 0x1c, 0xc8, 0xb1, 0xca, 0x0b, 0x6f, 0xf5, 0x81, 0x47, 0xa2, 0xc0, + 0xd1, 0xc0, 0xe0, 0x7e, 0xf1, 0xc0, 0xc8, 0x44, 0x4a, 0x26, 0xc0, 0x01, + 0xf8, 0x1c, 0xc8, 0xb1, 0xe2, 0x0a, 0x6f, 0xf5, 0x81, 0x47, 0xa2, 0xc0, + 0xd1, 0xc0, 0xe0, 0x7e, 0xf2, 0xc3, 0xa1, 0xc1, 0x00, 0x10, 0x15, 0x01, + 0x08, 0x47, 0x0a, 0x21, 0xc0, 0x21, 0x0a, 0x22, 0x80, 0x21, 0x0a, 0x23, + 0x40, 0x21, 0x0a, 0x20, 0x00, 0x21, 0x70, 0x44, 0x2f, 0x27, 0x3f, 0x00, + 0x6f, 0x23, 0x3f, 0x00, 0x0d, 0xc6, 0x16, 0x8e, 0x77, 0x8e, 0x04, 0x77, + 0x1d, 0x0b, 0x03, 0x00, 0x75, 0x8e, 0x04, 0x86, 0xb5, 0x6b, 0x1d, 0x65, + 0x2a, 0xad, 0x19, 0x09, 0xff, 0x20, 0xe0, 0xa5, 0x78, 0x22, 0x03, 0x00, + 0x44, 0xa5, 0x0f, 0xf0, 0x6f, 0x26, 0x3f, 0x00, 0x0c, 0x70, 0xd2, 0xc7, + 0x20, 0xea, 0x49, 0x20, 0x10, 0x21, 0x28, 0x4d, 0x40, 0x41, 0xda, 0x09, + 0x6f, 0xee, 0x02, 0x42, 0x6c, 0x70, 0x0c, 0xc0, 0x08, 0x1d, 0x02, 0x14, + 0x0c, 0x1d, 0x00, 0x15, 0x18, 0x1d, 0xc0, 0x14, 0x1c, 0x1d, 0x80, 0x14, + 0x09, 0x1d, 0x42, 0x14, 0x05, 0xa5, 0x80, 0xc0, 0xe1, 0x41, 0x22, 0x08, + 0x6f, 0xf5, 0xa2, 0x42, 0x00, 0xc0, 0x01, 0xa5, 0xc1, 0x40, 0x04, 0xf8, + 0x0c, 0x71, 0xd2, 0xc7, 0x6f, 0x26, 0x3f, 0x00, 0xdc, 0xf1, 0xe0, 0x78, + 0xe2, 0xc2, 0x08, 0x45, 0x17, 0x88, 0x84, 0xe8, 0xa1, 0x40, 0x0a, 0xff, + 0x7e, 0x09, 0x6f, 0xf5, 0xa1, 0x40, 0x6f, 0x26, 0x3f, 0x00, 0xc2, 0xc6, + 0xf6, 0xc2, 0x30, 0x45, 0x08, 0x45, 0x77, 0x58, 0x78, 0x20, 0x13, 0x00, + 0x8c, 0xd8, 0x1f, 0x23, 0x0f, 0x20, 0xcb, 0x46, 0xa0, 0x00, 0xcc, 0x49, + 0xa1, 0x40, 0x2e, 0x0e, 0xef, 0xf9, 0xdf, 0x67, 0x2f, 0x87, 0x10, 0x47, + 0x30, 0x41, 0x05, 0xe9, 0x62, 0x40, 0x20, 0x58, 0x10, 0x42, 0xeb, 0x85, + 0x2a, 0x85, 0x2f, 0x27, 0xbf, 0x05, 0x6f, 0x23, 0x3f, 0x00, 0x6f, 0x26, + 0x3f, 0x04, 0x62, 0x40, 0xe1, 0x42, 0xde, 0x0c, 0xef, 0xfc, 0x30, 0x40, + 0x8e, 0x71, 0x0d, 0xe8, 0x38, 0x8d, 0x6c, 0x70, 0xa2, 0x42, 0x62, 0x40, + 0x0a, 0x24, 0x00, 0x04, 0xe1, 0x45, 0xa1, 0x46, 0x26, 0x58, 0x83, 0xe8, + 0x8e, 0x70, 0x4c, 0x71, 0xe2, 0x41, 0x62, 0x40, 0x99, 0x58, 0x2f, 0x26, + 0xbf, 0x05, 0x41, 0x09, 0x30, 0x20, 0x62, 0x40, 0x20, 0x58, 0x39, 0x08, + 0x64, 0x04, 0x62, 0x40, 0x9f, 0x20, 0x02, 0x03, 0xc8, 0x4e, 0x1e, 0x66, + 0x1d, 0x0a, 0x64, 0x24, 0x3a, 0x60, 0x21, 0x82, 0x08, 0x86, 0x05, 0x20, + 0x7e, 0x80, 0x0e, 0xf2, 0x07, 0x20, 0x00, 0x04, 0xe7, 0x79, 0x05, 0x20, + 0x7e, 0x80, 0x08, 0xf2, 0x40, 0x23, 0x40, 0x22, 0x20, 0x1e, 0x00, 0x14, + 0xe1, 0xa2, 0x8d, 0x58, 0x82, 0x40, 0xd6, 0xc6, 0xea, 0xc2, 0xf2, 0x69, + 0x50, 0x41, 0x30, 0x40, 0x5c, 0xd9, 0xe1, 0x42, 0x68, 0x46, 0x0a, 0x0f, + 0x2f, 0xfc, 0x08, 0x45, 0x4a, 0x24, 0x00, 0x72, 0xa2, 0xa6, 0xfd, 0x65, + 0x0c, 0x6d, 0x2c, 0x70, 0xc1, 0x42, 0x03, 0xa6, 0xa8, 0x20, 0xc0, 0x02, + 0x01, 0x11, 0x80, 0x24, 0x14, 0x70, 0xca, 0x21, 0x61, 0x00, 0x34, 0x70, + 0xc0, 0x78, 0x01, 0x1a, 0x12, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0x44, 0x88, + 0x20, 0x80, 0x10, 0x1e, 0x00, 0x14, 0xc0, 0xa0, 0x25, 0xa6, 0xca, 0xc6, + 0xea, 0xc2, 0x00, 0x16, 0x03, 0x70, 0xa0, 0x00, 0xcc, 0x87, 0x48, 0x47, + 0x30, 0x40, 0xce, 0x6b, 0xc3, 0x43, 0xa1, 0x00, 0x7c, 0x09, 0x40, 0x23, + 0x0d, 0x06, 0x10, 0x41, 0xc3, 0x42, 0x13, 0x00, 0x44, 0x91, 0xc1, 0x41, + 0xa1, 0x40, 0xe4, 0xff, 0x00, 0x19, 0x80, 0x2f, 0xa0, 0x00, 0x64, 0x88, + 0xc0, 0xa7, 0x00, 0x18, 0x40, 0x23, 0xca, 0xc6, 0xee, 0xc2, 0xc8, 0x47, + 0x0a, 0x21, 0x00, 0x21, 0x70, 0x42, 0x48, 0x45, 0x30, 0x40, 0x1d, 0x0d, + 0x30, 0x00, 0x10, 0x43, 0x0a, 0xef, 0x40, 0x25, 0x0e, 0x06, 0x66, 0xbd, + 0x02, 0x42, 0xa0, 0x43, 0xc1, 0x40, 0xa1, 0x41, 0xd6, 0xff, 0x03, 0xf0, + 0xa8, 0x46, 0x62, 0x40, 0x02, 0x41, 0xa1, 0x42, 0x42, 0x43, 0x0a, 0x24, + 0x40, 0x04, 0xc1, 0x45, 0xee, 0x0e, 0x6f, 0xfe, 0xe1, 0x46, 0xce, 0xc6, + 0xee, 0xc2, 0xc3, 0x40, 0xa0, 0x00, 0x44, 0x88, 0xe0, 0x80, 0x50, 0x42, + 0x30, 0x43, 0x6a, 0x20, 0x80, 0x02, 0xae, 0xb8, 0x29, 0x20, 0x00, 0x80, + 0x2e, 0x70, 0x32, 0xf0, 0x40, 0x20, 0x11, 0x04, 0x63, 0x0b, 0x44, 0x24, + 0x62, 0x87, 0x43, 0x87, 0x60, 0x41, 0x70, 0x40, 0x13, 0x09, 0xa5, 0x00, + 0x28, 0x46, 0x20, 0x86, 0xd3, 0x71, 0x5c, 0x5c, 0x5c, 0x5c, 0x24, 0x6e, + 0xf8, 0xf3, 0x00, 0x22, 0x0d, 0x20, 0x08, 0xda, 0xa1, 0x40, 0xe1, 0x41, + 0xc6, 0x0f, 0x2f, 0xee, 0xc3, 0xa7, 0x02, 0x26, 0x00, 0x14, 0x41, 0x28, + 0x02, 0x04, 0x41, 0x28, 0x01, 0x02, 0x0c, 0xad, 0x4e, 0xad, 0x2d, 0xad, + 0x24, 0x87, 0x38, 0xb8, 0x0f, 0xad, 0x41, 0x29, 0x83, 0x03, 0x41, 0x29, + 0x82, 0x01, 0x12, 0x69, 0x6a, 0xad, 0x49, 0xad, 0x08, 0xad, 0xe5, 0x87, + 0x36, 0xb9, 0x2b, 0xad, 0x2f, 0x20, 0x48, 0x04, 0xce, 0xef, 0x6a, 0x21, + 0x80, 0x02, 0x8e, 0xb9, 0x29, 0x20, 0x40, 0x80, 0xce, 0xc6, 0xe0, 0x78, + 0xea, 0xc2, 0x08, 0x47, 0xcd, 0x70, 0xad, 0x70, 0x37, 0xf0, 0x00, 0x16, + 0x01, 0x70, 0xa0, 0x00, 0x4c, 0x40, 0x5a, 0x25, 0x00, 0x16, 0x1a, 0x61, + 0x00, 0x12, 0x0b, 0x01, 0x59, 0x0b, 0x7e, 0x10, 0x50, 0x40, 0x16, 0x40, + 0x02, 0x20, 0xd1, 0x83, 0x43, 0x26, 0x01, 0x90, 0x07, 0xd8, 0x3c, 0x20, + 0x42, 0x04, 0x7f, 0x21, 0x00, 0x00, 0x34, 0x70, 0xca, 0x20, 0x81, 0x00, + 0x9a, 0xe8, 0x0e, 0x40, 0x40, 0x20, 0x4c, 0x80, 0x41, 0x26, 0x03, 0x90, + 0x00, 0x21, 0x11, 0xa3, 0x01, 0x21, 0xc1, 0x80, 0x7c, 0x21, 0x02, 0x22, + 0x7a, 0x21, 0x00, 0x00, 0x34, 0x70, 0xca, 0x20, 0x81, 0x00, 0xf6, 0xe8, + 0x4f, 0x23, 0x80, 0x10, 0x0d, 0x0b, 0xfe, 0x10, 0x00, 0x18, 0x04, 0x20, + 0x02, 0x40, 0x7e, 0x58, 0x08, 0x18, 0x40, 0x24, 0xa5, 0x71, 0x00, 0x16, + 0xc0, 0x70, 0xa0, 0x00, 0x50, 0x40, 0x8f, 0x0d, 0x02, 0x90, 0xca, 0xc6, + 0xe4, 0xc2, 0xe1, 0xc4, 0xfc, 0x1c, 0xc8, 0xb2, 0xfc, 0x1c, 0x88, 0xb2, + 0xfc, 0x1c, 0x48, 0xb2, 0xfc, 0x1c, 0x08, 0xb2, 0xfc, 0x1c, 0xc8, 0xb1, + 0xfc, 0x1c, 0x88, 0xb1, 0xfc, 0x1c, 0x48, 0xb1, 0xfc, 0x1c, 0x08, 0xb1, + 0xe1, 0xc3, 0xe1, 0xc2, 0xe1, 0xc1, 0xe1, 0xc0, 0xfc, 0x1c, 0x88, 0xb7, + 0x6a, 0x25, 0xc0, 0x10, 0xe1, 0xc5, 0x6a, 0x25, 0x80, 0x10, 0xe1, 0xc5, + 0xfc, 0x1c, 0x08, 0xbf, 0xcb, 0x45, 0xf0, 0x00, 0xa0, 0x01, 0x00, 0x85, + 0xa0, 0xb8, 0x00, 0xa5, 0x04, 0x15, 0x02, 0x10, 0x22, 0x85, 0x02, 0x85, + 0xe0, 0x78, 0xfd, 0x09, 0x01, 0x80, 0xcb, 0x46, 0xa0, 0x00, 0x48, 0x88, + 0x00, 0x8e, 0x59, 0x61, 0x38, 0x60, 0x9a, 0x58, 0x00, 0x1e, 0xc3, 0x11, + 0x00, 0x85, 0x81, 0xb8, 0x00, 0xa5, 0xa1, 0x58, 0x40, 0xd9, 0xc3, 0x40, + 0xf0, 0x00, 0x2c, 0x01, 0x20, 0xa0, 0x02, 0x09, 0x4f, 0xfc, 0x05, 0xe8, + 0x00, 0x85, 0x80, 0xb8, 0x00, 0xa5, 0x09, 0x58, 0xc1, 0xc5, 0x0a, 0x24, + 0x40, 0x73, 0xc1, 0xc5, 0x6b, 0x25, 0x80, 0x10, 0xc1, 0xc5, 0x6b, 0x25, + 0xc0, 0x10, 0x04, 0x14, 0x1e, 0x34, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc2, + 0xc1, 0xc3, 0x04, 0x14, 0x04, 0x34, 0x04, 0x14, 0x05, 0x34, 0x04, 0x14, + 0x06, 0x34, 0x04, 0x14, 0x07, 0x34, 0x04, 0x14, 0x08, 0x34, 0x04, 0x14, + 0x09, 0x34, 0x04, 0x14, 0x0a, 0x34, 0x04, 0x14, 0x0b, 0x34, 0xc1, 0xc4, + 0xc4, 0xc2, 0x6f, 0x24, 0x3f, 0x00, 0xe0, 0x78, 0xee, 0xc2, 0x81, 0x58, + 0x14, 0x70, 0xa0, 0x00, 0x21, 0x00, 0x08, 0x45, 0x2f, 0x27, 0xff, 0x04, + 0x6f, 0x23, 0x3f, 0x00, 0x6f, 0x26, 0x3f, 0x04, 0x00, 0x8d, 0xe1, 0xb8, + 0x42, 0xf4, 0xcb, 0x46, 0xf0, 0x00, 0xa0, 0x01, 0x00, 0x86, 0xa0, 0xb8, + 0x00, 0x1e, 0x00, 0x10, 0x22, 0x86, 0x02, 0x86, 0xe0, 0x78, 0xfd, 0x09, + 0x21, 0x80, 0x30, 0x41, 0x72, 0x08, 0x6f, 0xfc, 0x04, 0x16, 0x12, 0x10, + 0xd3, 0x40, 0xa0, 0x00, 0x48, 0x88, 0xcb, 0x47, 0xf0, 0x00, 0x20, 0x01, + 0x14, 0xe8, 0x02, 0x85, 0x42, 0x20, 0xc0, 0x81, 0xca, 0x20, 0x6e, 0x00, + 0x02, 0xa5, 0x24, 0x87, 0x1f, 0x09, 0xbf, 0x01, 0x42, 0x70, 0x40, 0x21, + 0x80, 0x21, 0x9a, 0x58, 0x00, 0x10, 0x80, 0x20, 0x04, 0x71, 0x00, 0x18, + 0x02, 0x20, 0x06, 0xf0, 0x00, 0x18, 0xc3, 0x21, 0x04, 0xf0, 0x02, 0xa5, + 0xa1, 0x40, 0x7c, 0x58, 0x00, 0x95, 0x81, 0xb8, 0x00, 0xb5, 0x40, 0xd8, + 0x00, 0xa7, 0x06, 0xa7, 0x00, 0x86, 0x81, 0xb8, 0x00, 0xa6, 0x04, 0x87, + 0x0d, 0x08, 0x9f, 0x01, 0xa1, 0x58, 0x00, 0x86, 0x80, 0xb8, 0x00, 0xa6, + 0x2f, 0x26, 0xff, 0x04, 0xce, 0xc6, 0xe0, 0x78, 0x05, 0xe8, 0x00, 0x18, + 0x84, 0x0f, 0x00, 0x00, 0xe6, 0x07, 0x06, 0xe9, 0x00, 0x19, 0x82, 0x0f, + 0x00, 0x00, 0x08, 0x00, 0x05, 0xea, 0x00, 0x1a, 0x82, 0x0f, 0x00, 0x00, + 0x09, 0x00, 0x06, 0xeb, 0x00, 0x1b, 0x82, 0x0f, 0x00, 0x00, 0x0a, 0x00, + 0x0d, 0x0c, 0x10, 0x00, 0x00, 0x1c, 0x82, 0x0f, 0x00, 0x00, 0x30, 0x00, + 0xb4, 0x70, 0xe0, 0x7c, 0x00, 0x1d, 0x82, 0x0f, 0x00, 0x00, 0x26, 0x00, + 0xe0, 0x7e, 0xe0, 0x78, 0xa8, 0x10, 0x00, 0x01, 0x14, 0x70, 0xe0, 0x7f, + 0xca, 0x20, 0x61, 0x00, 0xe2, 0xc2, 0xe6, 0xe1, 0x17, 0xf4, 0x8d, 0x76, + 0x66, 0xdd, 0x93, 0xbc, 0xc3, 0x41, 0xa1, 0x00, 0x7c, 0x27, 0x00, 0x1e, + 0x42, 0x73, 0xf0, 0x00, 0x48, 0x00, 0x80, 0xa1, 0x05, 0x19, 0x83, 0x02, + 0x43, 0xb1, 0x18, 0x88, 0x64, 0xb1, 0x0a, 0x19, 0x04, 0x01, 0x04, 0xa9, + 0x0c, 0x71, 0x64, 0x58, 0xc2, 0xc6, 0xde, 0x0e, 0x8f, 0xfc, 0xc2, 0xc6, + 0xe4, 0xc3, 0xa7, 0xc1, 0x08, 0x46, 0x34, 0x58, 0x08, 0x45, 0x2e, 0x58, + 0x00, 0x42, 0xc1, 0x40, 0xa1, 0x41, 0x33, 0x58, 0x08, 0x45, 0x0f, 0xe8, + 0x2f, 0x85, 0x60, 0x79, 0xa1, 0x40, 0x25, 0x08, 0xb5, 0x00, 0x10, 0xd8, + 0x4e, 0x85, 0x60, 0x7a, 0xa1, 0x41, 0x25, 0x08, 0x30, 0x04, 0x6f, 0xd9, + 0x09, 0xf0, 0x4c, 0x70, 0x80, 0xc0, 0x22, 0xd9, 0x6c, 0x70, 0x40, 0x44, + 0x66, 0xc6, 0x07, 0xf0, 0x66, 0xd9, 0x4c, 0x70, 0x6c, 0x70, 0x40, 0x44, + 0xa1, 0x40, 0x6c, 0x58, 0xc4, 0xc7, 0xe0, 0x78, 0xf1, 0xc0, 0x08, 0xb8, + 0x0a, 0x27, 0x40, 0x01, 0x98, 0xb8, 0x4a, 0x25, 0x00, 0x02, 0x53, 0x58, + 0xd1, 0xc0, 0xe0, 0x7e, 0x0a, 0x27, 0x40, 0x01, 0x8d, 0x06, 0x2f, 0xf5, + 0x4a, 0x25, 0x00, 0x02, 0xf1, 0xc0, 0x00, 0x35, 0x8c, 0x0f, 0x80, 0x42, + 0x00, 0x00, 0x0a, 0x27, 0x80, 0x01, 0x48, 0x34, 0x46, 0x12, 0x08, 0xb8, + 0x2f, 0x24, 0x88, 0x11, 0x0f, 0x0c, 0x34, 0x11, 0x98, 0xb8, 0x00, 0x24, + 0x86, 0x1f, 0x00, 0x00, 0xfc, 0xff, 0xac, 0x72, 0x53, 0x58, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0x00, 0x35, 0x8c, 0x0f, 0x80, 0x42, + 0x00, 0x00, 0x0a, 0x27, 0x80, 0x01, 0x48, 0x34, 0x46, 0x12, 0x08, 0xb8, + 0x2f, 0x24, 0x88, 0x11, 0x0f, 0x0c, 0x34, 0x11, 0x98, 0xb8, 0x00, 0x24, + 0x86, 0x1f, 0x00, 0x00, 0xfc, 0xff, 0x4a, 0x25, 0x80, 0x02, 0x53, 0x58, + 0xd1, 0xc0, 0xe0, 0x7e, 0x0a, 0x27, 0x80, 0x01, 0x0a, 0x26, 0x40, 0x01, + 0x1d, 0x06, 0x2f, 0xf5, 0x4a, 0x25, 0xc0, 0x02, 0xf1, 0xc0, 0x00, 0x35, + 0x8c, 0x0f, 0x80, 0x42, 0x00, 0x00, 0x0a, 0x27, 0x80, 0x01, 0x48, 0x34, + 0x46, 0x12, 0x08, 0xb8, 0x2f, 0x24, 0x88, 0x11, 0x8f, 0xb8, 0x11, 0x0c, + 0x34, 0x11, 0x98, 0xb8, 0x00, 0x24, 0x86, 0x1f, 0x00, 0x00, 0xfc, 0xff, + 0xac, 0x72, 0x53, 0x58, 0xd1, 0xc0, 0xe0, 0x7e, 0xf1, 0xc0, 0xfc, 0x1c, + 0x88, 0xb7, 0x82, 0x08, 0x4f, 0xfa, 0x04, 0x14, 0x1e, 0x34, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0xfc, 0x1c, 0x88, 0xb7, 0x3a, 0x0a, + 0x8f, 0xed, 0x04, 0x14, 0x1e, 0x34, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0xfc, 0x1c, 0x88, 0xb7, 0xe1, 0xc0, 0xe1, 0xc1, 0xe1, 0xc2, 0xe1, 0xc3, + 0xfc, 0x1c, 0x08, 0xb1, 0xfc, 0x1c, 0x48, 0xb1, 0xfc, 0x1c, 0x88, 0xb1, + 0xfc, 0x1c, 0xc8, 0xb1, 0xfc, 0x1c, 0x08, 0xb2, 0xfc, 0x1c, 0x48, 0xb2, + 0xfc, 0x1c, 0x88, 0xb2, 0xfc, 0x1c, 0xc8, 0xb2, 0xe1, 0xc4, 0xf1, 0xc0, + 0xfc, 0x1c, 0x08, 0xbf, 0x6a, 0x20, 0x80, 0x00, 0xe1, 0xc0, 0x6a, 0x20, + 0xc0, 0x00, 0xe1, 0xc0, 0xaa, 0x20, 0x90, 0x02, 0x77, 0xb8, 0x0f, 0x78, + 0x0f, 0x08, 0x50, 0x00, 0x8a, 0xe8, 0xc3, 0x40, 0xa0, 0x00, 0xec, 0x40, + 0x04, 0xf0, 0xc3, 0x40, 0xa0, 0x00, 0x08, 0x41, 0xca, 0x0f, 0x8f, 0xff, + 0xc1, 0xc0, 0x6b, 0x20, 0xc0, 0x00, 0xc1, 0xc0, 0x6b, 0x20, 0x80, 0x00, + 0xc1, 0xc0, 0x0a, 0x24, 0x00, 0x70, 0xd1, 0xc0, 0xc1, 0xc4, 0x04, 0x14, + 0x0b, 0x34, 0x04, 0x14, 0x0a, 0x34, 0x04, 0x14, 0x09, 0x34, 0x04, 0x14, + 0x08, 0x34, 0x04, 0x14, 0x07, 0x34, 0x04, 0x14, 0x06, 0x34, 0x04, 0x14, + 0x05, 0x34, 0x04, 0x14, 0x04, 0x34, 0xc1, 0xc3, 0xc1, 0xc2, 0xc1, 0xc1, + 0xc1, 0xc0, 0x04, 0x14, 0x1e, 0x34, 0x6f, 0x24, 0x3f, 0x00, 0xe0, 0x78, + 0xe8, 0xc2, 0xe1, 0xc4, 0xfc, 0x1c, 0xc8, 0xb2, 0xfc, 0x1c, 0x88, 0xb2, + 0xfc, 0x1c, 0x48, 0xb2, 0xfc, 0x1c, 0x08, 0xb2, 0xfc, 0x1c, 0xc8, 0xb1, + 0xfc, 0x1c, 0x88, 0xb1, 0xfc, 0x1c, 0x48, 0xb1, 0xfc, 0x1c, 0x08, 0xb1, + 0xe1, 0xc3, 0xe1, 0xc2, 0xe1, 0xc1, 0xe1, 0xc0, 0xfc, 0x1c, 0x88, 0xb7, + 0x6a, 0x25, 0xc0, 0x10, 0xe1, 0xc5, 0x6a, 0x25, 0x80, 0x10, 0xe1, 0xc5, + 0xfc, 0x1c, 0x08, 0xbf, 0xaa, 0x20, 0x90, 0x02, 0x42, 0x20, 0xc1, 0x08, + 0x42, 0x20, 0x40, 0x09, 0x2f, 0x7c, 0x4c, 0x73, 0x91, 0x40, 0x11, 0x0c, + 0xb5, 0x11, 0x0f, 0x7b, 0x48, 0x20, 0x82, 0x20, 0x80, 0x22, 0x83, 0x0f, + 0xb3, 0x6a, 0xcd, 0x71, 0xc3, 0x40, 0xa0, 0x00, 0x74, 0x49, 0x84, 0x25, + 0x1f, 0x1e, 0xcb, 0x47, 0xf0, 0x00, 0x20, 0x01, 0x78, 0x7e, 0x1d, 0x65, + 0x2f, 0x27, 0x3f, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xc9, 0xa7, 0x41, 0x85, + 0x20, 0x85, 0x04, 0x1d, 0x01, 0x10, 0x00, 0x1d, 0x01, 0x10, 0x2f, 0x26, + 0x3f, 0x00, 0x02, 0x40, 0x45, 0x58, 0x0a, 0x87, 0xc4, 0x78, 0xd1, 0x70, + 0xee, 0xf3, 0xc1, 0xc5, 0x0a, 0x24, 0x40, 0x73, 0xc1, 0xc5, 0x6b, 0x25, + 0x80, 0x10, 0xc1, 0xc5, 0x6b, 0x25, 0xc0, 0x10, 0x04, 0x14, 0x1e, 0x34, + 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc2, 0xc1, 0xc3, 0x04, 0x14, 0x04, 0x34, + 0x04, 0x14, 0x05, 0x34, 0x04, 0x14, 0x06, 0x34, 0x04, 0x14, 0x07, 0x34, + 0x04, 0x14, 0x08, 0x34, 0x04, 0x14, 0x09, 0x34, 0x04, 0x14, 0x0a, 0x34, + 0x04, 0x14, 0x0b, 0x34, 0xc1, 0xc4, 0xc8, 0xc2, 0x6f, 0x24, 0x3f, 0x00, + 0xf0, 0xc2, 0x08, 0x45, 0xc3, 0x43, 0xa0, 0x00, 0xd3, 0x4d, 0xd3, 0x40, + 0xa0, 0x00, 0xa0, 0x4d, 0xc3, 0x40, 0xa0, 0x00, 0xe0, 0x4d, 0x8a, 0x21, + 0x87, 0x0d, 0x76, 0xda, 0x8e, 0x70, 0x00, 0x1b, 0x43, 0x00, 0x17, 0x18, + 0x03, 0x20, 0x0f, 0x18, 0x83, 0x00, 0x08, 0x18, 0x40, 0x20, 0x24, 0x18, + 0x40, 0x20, 0x40, 0xa0, 0x5d, 0x58, 0x1d, 0x08, 0x85, 0x0f, 0x00, 0x00, + 0xf8, 0x13, 0xc3, 0x40, 0xf0, 0x00, 0x34, 0x00, 0x28, 0xd9, 0x4c, 0x70, + 0x34, 0xa8, 0x15, 0x18, 0x03, 0x00, 0x6d, 0xf0, 0x89, 0x25, 0x01, 0x19, + 0x64, 0xd8, 0x88, 0x25, 0x3e, 0x17, 0xa2, 0x78, 0xc8, 0xd9, 0x0f, 0x7e, + 0xd7, 0x49, 0xd1, 0x41, 0xd1, 0x77, 0x0c, 0x72, 0x8a, 0x21, 0x0a, 0x0c, + 0x8a, 0x0f, 0x2f, 0xf9, 0xca, 0x21, 0xc5, 0x23, 0x10, 0x43, 0x5d, 0x58, + 0x08, 0x45, 0x5b, 0x58, 0x10, 0x42, 0x6e, 0x08, 0xaf, 0xf7, 0x16, 0x40, + 0x0c, 0x22, 0x00, 0xa0, 0xc2, 0x25, 0x85, 0x14, 0x1a, 0x25, 0x51, 0x14, + 0x3d, 0x27, 0x8d, 0x13, 0x5f, 0x25, 0x00, 0x17, 0x85, 0x29, 0x03, 0x22, + 0x02, 0x70, 0x02, 0x80, 0x04, 0x21, 0x91, 0x2f, 0xff, 0x01, 0xfc, 0xff, + 0x42, 0x08, 0xaf, 0xf7, 0x20, 0xe0, 0x14, 0x78, 0x20, 0xe0, 0x32, 0x70, + 0xca, 0x21, 0x0d, 0x20, 0xa1, 0x40, 0x3e, 0x0f, 0x2f, 0xf9, 0x22, 0x41, + 0x10, 0x41, 0x3c, 0x27, 0x8f, 0x13, 0x5b, 0x58, 0x08, 0x45, 0x5c, 0x58, + 0x17, 0x08, 0x35, 0x08, 0x08, 0x46, 0x1f, 0xd8, 0xa0, 0xe5, 0x3c, 0x20, + 0x54, 0x03, 0xca, 0x26, 0x25, 0x10, 0xca, 0x25, 0x25, 0x10, 0x5f, 0x27, + 0x00, 0x17, 0x04, 0x21, 0xd1, 0x24, 0x00, 0x20, 0x10, 0x20, 0xfe, 0x0f, + 0x6f, 0xf7, 0x16, 0x40, 0x15, 0x0c, 0x30, 0x20, 0x42, 0x25, 0x01, 0x18, + 0x09, 0x29, 0x01, 0x00, 0x09, 0x2e, 0x02, 0x10, 0x48, 0x49, 0x09, 0xf0, + 0x42, 0x26, 0x01, 0x18, 0x09, 0x29, 0x02, 0x00, 0x09, 0x2d, 0x00, 0x10, + 0x20, 0xe2, 0xdd, 0x65, 0x10, 0x4d, 0x51, 0x48, 0xda, 0x0e, 0x2f, 0xf9, + 0xe1, 0x40, 0x04, 0x21, 0x02, 0x20, 0x40, 0x40, 0xd0, 0xc6, 0xe0, 0x78, + 0x50, 0x20, 0xc1, 0x07, 0x00, 0x42, 0x3f, 0xb8, 0x21, 0x09, 0x84, 0x0f, + 0xb1, 0x42, 0x18, 0x72, 0xcb, 0x44, 0x13, 0x00, 0x4c, 0x91, 0x41, 0x09, + 0x84, 0x0f, 0x80, 0x7f, 0x01, 0x00, 0x81, 0x40, 0x2c, 0x71, 0xd1, 0x04, + 0x20, 0x00, 0x6c, 0x70, 0x41, 0x09, 0x84, 0x0f, 0xb1, 0x3e, 0x19, 0x72, + 0x97, 0x09, 0x85, 0x0f, 0x85, 0x3f, 0x92, 0x15, 0xc3, 0x41, 0x13, 0x00, + 0x5c, 0x91, 0x15, 0x21, 0x03, 0x00, 0x08, 0x13, 0x0b, 0x00, 0x03, 0x49, + 0x52, 0x20, 0x01, 0x00, 0xa7, 0x00, 0x20, 0x00, 0x02, 0x21, 0x0c, 0x00, + 0x41, 0x09, 0x81, 0x0f, 0x80, 0x7f, 0x00, 0x00, 0x14, 0x70, 0xe1, 0x20, + 0xc2, 0x07, 0x0c, 0x70, 0x3d, 0x00, 0x00, 0x00, 0x01, 0x32, 0x80, 0x0f, + 0x49, 0x71, 0xca, 0xf2, 0x7f, 0xdb, 0x17, 0xbb, 0x04, 0x30, 0xc0, 0x80, + 0x14, 0x00, 0x2c, 0x00, 0x8d, 0x70, 0x11, 0x09, 0x85, 0x0f, 0x80, 0x31, + 0x00, 0x00, 0xe0, 0x7f, 0x01, 0x32, 0xc0, 0x00, 0x6d, 0x70, 0x6f, 0x00, + 0x20, 0x00, 0x6c, 0x70, 0x04, 0x32, 0x80, 0x8f, 0xb1, 0x42, 0x80, 0x71, + 0x10, 0x00, 0x0c, 0x00, 0x2c, 0x71, 0x6c, 0x70, 0x91, 0x03, 0x20, 0x00, + 0x0a, 0x20, 0x00, 0x03, 0x04, 0x32, 0x80, 0x8f, 0xcf, 0xc2, 0xb5, 0xf1, + 0x12, 0x00, 0x26, 0x00, 0x2c, 0x71, 0x4a, 0x23, 0x00, 0x00, 0xd9, 0x03, + 0x20, 0x00, 0x0a, 0x20, 0x00, 0x03, 0xf0, 0x26, 0x01, 0x70, 0x13, 0x00, + 0x54, 0x91, 0x00, 0x32, 0x80, 0x0f, 0xb8, 0x3f, 0x3b, 0xaa, 0x01, 0x30, + 0x40, 0x00, 0x48, 0x30, 0xcc, 0x02, 0x48, 0x34, 0x80, 0x10, 0x00, 0x30, + 0x8b, 0x0f, 0x17, 0x37, 0xd1, 0xf7, 0x00, 0x30, 0x83, 0x0f, 0x31, 0x3f, + 0x80, 0x71, 0x02, 0x32, 0xc3, 0x00, 0x02, 0x33, 0xc2, 0x02, 0x00, 0x32, + 0x80, 0x00, 0x00, 0x30, 0x81, 0x0f, 0x31, 0x33, 0x4c, 0xbb, 0x01, 0x31, + 0x81, 0x0f, 0xdd, 0xb5, 0x0e, 0xea, 0x00, 0x30, 0x41, 0x00, 0x01, 0x31, + 0x81, 0x0f, 0x8a, 0x38, 0x55, 0xb3, 0x00, 0x30, 0x41, 0x00, 0x01, 0x31, + 0x81, 0x0f, 0x36, 0xbb, 0x61, 0x0b, 0x00, 0x30, 0x41, 0x00, 0x01, 0x31, + 0x81, 0x0f, 0x2a, 0x3e, 0xab, 0xaa, 0x00, 0x30, 0x40, 0x00, 0x02, 0x32, + 0x00, 0x00, 0x49, 0x0c, 0x30, 0x10, 0x00, 0x32, 0x01, 0x00, 0x02, 0x36, + 0x00, 0x70, 0x00, 0x40, 0x00, 0x00, 0x40, 0x2c, 0xc2, 0x15, 0x07, 0x31, + 0x00, 0x00, 0x8c, 0x24, 0xfe, 0x90, 0x02, 0x33, 0x00, 0x10, 0x02, 0x33, + 0x00, 0x00, 0x01, 0x30, 0x80, 0x0f, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x20, + 0x80, 0x00, 0xe0, 0x20, 0xca, 0x07, 0x00, 0x20, 0x80, 0x0f, 0x00, 0x32, + 0x00, 0x00, 0x00, 0x30, 0x80, 0x0f, 0x80, 0x0d, 0x00, 0x00, 0xe0, 0x7e, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xc0, 0x00, 0x00, 0x07, 0x31, 0x00, 0x00, + 0x02, 0x32, 0x00, 0x00, 0x01, 0x30, 0x80, 0x0f, 0x80, 0x3f, 0x00, 0x00, + 0xe0, 0x7e, 0xe0, 0x78, 0xe4, 0x1c, 0x48, 0xb3, 0x41, 0xc6, 0x42, 0xc7, + 0x0c, 0x1c, 0x00, 0x34, 0x10, 0x1c, 0x40, 0x34, 0x08, 0x45, 0x1b, 0x78, + 0xd3, 0x70, 0x00, 0xff, 0x00, 0x00, 0x10, 0x01, 0x26, 0x00, 0x14, 0x1c, + 0xc0, 0x37, 0x44, 0x35, 0x00, 0x90, 0x40, 0x00, 0x2e, 0x00, 0x86, 0xc1, + 0x4a, 0x0c, 0x20, 0x00, 0xa1, 0x40, 0x00, 0x16, 0x03, 0x70, 0x10, 0x00, + 0x64, 0x0b, 0xbf, 0xda, 0x40, 0x2a, 0x02, 0x06, 0x18, 0x14, 0x11, 0x30, + 0x01, 0x30, 0x81, 0x00, 0x04, 0x30, 0xc0, 0x80, 0x38, 0x00, 0x2c, 0x00, + 0x50, 0x22, 0xc3, 0x07, 0x01, 0x31, 0x81, 0x00, 0x00, 0x30, 0xc0, 0x00, + 0x39, 0x00, 0x20, 0x00, 0x01, 0x30, 0xc0, 0x00, 0x50, 0x25, 0xfe, 0x97, + 0xc3, 0x40, 0x13, 0x00, 0x6c, 0x91, 0x2c, 0x71, 0x6c, 0x70, 0x88, 0x00, + 0x22, 0x00, 0xa1, 0x42, 0x22, 0x0a, 0x00, 0x00, 0x95, 0x00, 0x20, 0x00, + 0x52, 0x20, 0xcd, 0x07, 0x00, 0x31, 0xc0, 0x00, 0x42, 0x21, 0x51, 0x20, + 0x01, 0x30, 0xc0, 0x00, 0x18, 0x1c, 0x40, 0x34, 0x07, 0x31, 0x0f, 0x00, + 0xd3, 0x40, 0xa0, 0x00, 0x54, 0x88, 0x00, 0x37, 0xcd, 0x13, 0x4c, 0x71, + 0x0a, 0x20, 0x40, 0x03, 0x76, 0x0b, 0x20, 0x00, 0x02, 0x41, 0x08, 0x46, + 0x40, 0x20, 0x01, 0x21, 0x4a, 0x22, 0x80, 0x00, 0x66, 0x0b, 0x20, 0x00, + 0x0a, 0x20, 0x40, 0x03, 0x07, 0x36, 0x00, 0x10, 0x00, 0x35, 0x00, 0x10, + 0x00, 0x37, 0x00, 0x10, 0x45, 0x09, 0x30, 0x20, 0x01, 0x37, 0x0d, 0x10, + 0x48, 0x31, 0x81, 0x20, 0x00, 0x16, 0x00, 0x70, 0x10, 0x00, 0x78, 0x0b, + 0x00, 0x31, 0x82, 0x0f, 0x5e, 0xb9, 0x83, 0x80, 0x01, 0x35, 0x82, 0x10, + 0x00, 0x30, 0x40, 0x00, 0x21, 0x00, 0x20, 0x00, 0x01, 0x32, 0x0d, 0x00, + 0x5e, 0x0a, 0x00, 0x00, 0x4e, 0x0b, 0x2f, 0xf6, 0x08, 0x45, 0x00, 0x80, + 0xc3, 0x41, 0x80, 0xff, 0x00, 0x00, 0xa1, 0xe0, 0xca, 0x25, 0x41, 0x10, + 0xa1, 0x40, 0x14, 0x14, 0x1f, 0x30, 0x10, 0x14, 0x11, 0x30, 0x0c, 0x14, + 0x10, 0x30, 0x02, 0xc7, 0x01, 0xc6, 0xe0, 0x7f, 0x1c, 0x14, 0x0d, 0x34, + 0x76, 0x0b, 0x20, 0x00, 0xa1, 0x40, 0xe5, 0x08, 0x30, 0x80, 0x2c, 0x71, + 0xc3, 0x40, 0x13, 0x00, 0x6c, 0x91, 0x6c, 0x70, 0x5e, 0x09, 0x20, 0x00, + 0xa1, 0x42, 0xd1, 0x07, 0xef, 0xff, 0x08, 0x45, 0xd0, 0x1c, 0x48, 0xb3, + 0x41, 0xc6, 0x42, 0xc7, 0x0c, 0x1c, 0xc0, 0x37, 0xe8, 0x46, 0xc8, 0x45, + 0x44, 0xc0, 0x84, 0xc0, 0x4b, 0xc6, 0x4a, 0xc5, 0x24, 0x1c, 0x40, 0x31, + 0x20, 0x1c, 0x00, 0x31, 0x47, 0xc3, 0x46, 0xc2, 0x5a, 0x0b, 0x20, 0x00, + 0x45, 0xc1, 0x06, 0xe8, 0x0b, 0xc6, 0x11, 0x00, 0x20, 0x00, 0x0a, 0xc5, + 0xce, 0x0a, 0x2f, 0xf6, 0x0d, 0xc7, 0xe0, 0xa0, 0xa1, 0x40, 0xc1, 0x41, + 0x0c, 0x14, 0x1f, 0x30, 0x02, 0xc7, 0x01, 0xc6, 0xe0, 0x7f, 0x30, 0x14, + 0x0d, 0x34, 0xe0, 0x78, 0xd4, 0x1c, 0x48, 0xb3, 0x41, 0xc6, 0x08, 0x1c, + 0xc0, 0x37, 0xcb, 0x46, 0xf0, 0x7f, 0x00, 0x00, 0x44, 0xc0, 0x83, 0xc0, + 0x20, 0x1c, 0x40, 0x31, 0x1c, 0x1c, 0x00, 0x31, 0x46, 0xc3, 0x45, 0xc2, + 0x28, 0x1c, 0x80, 0x33, 0x24, 0x1c, 0x01, 0x30, 0x06, 0x0b, 0x20, 0x00, + 0x0c, 0x1c, 0xc1, 0x30, 0x11, 0x08, 0x30, 0x00, 0xad, 0x70, 0x0a, 0xc6, + 0x11, 0x00, 0x20, 0x00, 0x24, 0x14, 0x0d, 0x30, 0x72, 0x0a, 0x0f, 0xf6, + 0x22, 0xd9, 0x20, 0xa0, 0xa1, 0x40, 0xc1, 0x41, 0x08, 0x14, 0x1f, 0x30, + 0x01, 0xc6, 0xe0, 0x7f, 0x2c, 0x14, 0x0d, 0x34, 0xd8, 0x1c, 0x48, 0xb3, + 0x04, 0x1c, 0xc0, 0x37, 0x43, 0xc0, 0x82, 0xc0, 0x1c, 0x1c, 0x40, 0x31, + 0x18, 0x1c, 0x00, 0x31, 0x45, 0xc3, 0x44, 0xc2, 0x24, 0x1c, 0x01, 0x30, + 0x20, 0x1c, 0x01, 0x30, 0xb6, 0x0a, 0x20, 0x00, 0x08, 0x1c, 0x01, 0x31, + 0x11, 0x08, 0x30, 0x00, 0xad, 0x70, 0x09, 0xc1, 0x15, 0x00, 0x20, 0x00, + 0x20, 0x14, 0x0d, 0x30, 0x22, 0x0a, 0x0f, 0xf6, 0x22, 0xd9, 0x20, 0xa0, + 0x4a, 0x21, 0x00, 0x00, 0xa1, 0x40, 0x04, 0x14, 0x1f, 0x30, 0xe0, 0x7f, + 0x28, 0x14, 0x0d, 0x34, 0xd4, 0x1c, 0x48, 0xb3, 0x41, 0xc6, 0x08, 0x1c, + 0xc0, 0x37, 0xcb, 0x46, 0xf8, 0x7f, 0x00, 0x00, 0x44, 0xc0, 0x83, 0xc0, + 0x20, 0x1c, 0x40, 0x31, 0x1c, 0x1c, 0x00, 0x31, 0x46, 0xc3, 0x45, 0xc2, + 0x28, 0x1c, 0x80, 0x33, 0x24, 0x1c, 0x01, 0x30, 0x5e, 0x0a, 0x20, 0x00, + 0x0c, 0x1c, 0x41, 0x30, 0x11, 0x08, 0x30, 0x00, 0xad, 0x70, 0x0a, 0xc6, + 0x11, 0x00, 0x20, 0x00, 0x24, 0x14, 0x0d, 0x30, 0xca, 0x09, 0x0f, 0xf6, + 0x21, 0xd9, 0x20, 0xa0, 0xa1, 0x40, 0xc1, 0x41, 0x08, 0x14, 0x1f, 0x30, + 0x01, 0xc6, 0xe0, 0x7f, 0x2c, 0x14, 0x0d, 0x34, 0xd8, 0x1c, 0x48, 0xb3, + 0x04, 0x1c, 0xc0, 0x37, 0x24, 0x1c, 0x80, 0x3f, 0xf0, 0x7f, 0x00, 0x00, + 0x43, 0xc0, 0x60, 0x40, 0x0a, 0x25, 0x80, 0x10, 0x20, 0x1c, 0x01, 0x30, + 0x26, 0x0a, 0x20, 0x00, 0x08, 0x1c, 0xc1, 0x30, 0x46, 0xc0, 0xa1, 0x40, + 0x1a, 0x0a, 0x20, 0x00, 0x47, 0xc1, 0x10, 0x1c, 0x00, 0x30, 0x82, 0xc0, + 0xfa, 0x09, 0x20, 0x00, 0x45, 0xc1, 0x08, 0xe8, 0x20, 0x14, 0x00, 0x30, + 0x72, 0x0a, 0x20, 0x00, 0x09, 0xc1, 0x08, 0xf0, 0x6a, 0x09, 0x0f, 0xf6, + 0x22, 0xd9, 0x20, 0xa0, 0xff, 0xd8, 0x17, 0xb8, 0x04, 0x14, 0x1f, 0x30, + 0xe0, 0x7f, 0x28, 0x14, 0x0d, 0x34, 0xe0, 0x78, 0xd8, 0x1c, 0x48, 0xb3, + 0x04, 0x1c, 0xc0, 0x37, 0x43, 0xc0, 0x60, 0x40, 0x0a, 0x25, 0x80, 0x10, + 0x24, 0x1c, 0x01, 0x30, 0x20, 0x1c, 0x01, 0x30, 0xca, 0x09, 0x20, 0x00, + 0x08, 0x1c, 0x01, 0x31, 0x46, 0xc0, 0xa1, 0x40, 0xbe, 0x09, 0x20, 0x00, + 0x47, 0xc1, 0x10, 0x1c, 0x00, 0x30, 0x82, 0xc0, 0x9e, 0x09, 0x20, 0x00, + 0x45, 0xc1, 0x08, 0xe8, 0x20, 0x14, 0x00, 0x30, 0x16, 0x0a, 0x20, 0x00, + 0x09, 0xc1, 0x08, 0xf0, 0x0e, 0x09, 0x0f, 0xf6, 0x22, 0xd9, 0x20, 0xa0, + 0x4a, 0x20, 0x00, 0x00, 0x04, 0x14, 0x1f, 0x30, 0xe0, 0x7f, 0x28, 0x14, + 0x0d, 0x34, 0xe0, 0x78, 0xd8, 0x1c, 0x48, 0xb3, 0x04, 0x1c, 0xc0, 0x37, + 0x24, 0x1c, 0x80, 0x3f, 0xf8, 0x7f, 0x00, 0x00, 0x43, 0xc0, 0x60, 0x40, + 0x0a, 0x25, 0x80, 0x10, 0x20, 0x1c, 0x01, 0x30, 0x6a, 0x09, 0x20, 0x00, + 0x08, 0x1c, 0x41, 0x30, 0x46, 0xc0, 0xa1, 0x40, 0x5e, 0x09, 0x20, 0x00, + 0x47, 0xc1, 0x10, 0x1c, 0x00, 0x30, 0x82, 0xc0, 0x3e, 0x09, 0x20, 0x00, + 0x45, 0xc1, 0x08, 0xe8, 0x20, 0x14, 0x00, 0x30, 0xb6, 0x09, 0x20, 0x00, + 0x09, 0xc1, 0x0a, 0xf0, 0xae, 0x08, 0x0f, 0xf6, 0x21, 0xd9, 0x20, 0xa0, + 0x0a, 0x20, 0x80, 0x0f, 0xc0, 0x7f, 0x00, 0x00, 0x04, 0x14, 0x1f, 0x30, + 0xe0, 0x7f, 0x28, 0x14, 0x0d, 0x34, 0xe0, 0x78, 0xe8, 0x1c, 0x48, 0xb3, + 0x41, 0xc6, 0x42, 0xc7, 0x0c, 0x1c, 0x00, 0x34, 0x10, 0x1c, 0x40, 0x34, + 0x14, 0x1c, 0xc0, 0x37, 0x68, 0x46, 0x48, 0x47, 0x61, 0x82, 0x31, 0x0e, + 0xb2, 0x10, 0x40, 0x82, 0x30, 0x40, 0x10, 0x41, 0x4a, 0x25, 0x40, 0x10, + 0x0a, 0x20, 0x40, 0x04, 0x0e, 0x0a, 0x20, 0x00, 0x0a, 0x21, 0x00, 0x04, + 0x08, 0x17, 0x02, 0x12, 0x96, 0x0e, 0x20, 0x00, 0x61, 0x87, 0xa5, 0x71, + 0x00, 0x42, 0xe9, 0x0d, 0xa2, 0x93, 0x20, 0x43, 0x40, 0x40, 0x60, 0x41, + 0x14, 0x14, 0x1f, 0x30, 0x10, 0x14, 0x11, 0x30, 0x0c, 0x14, 0x10, 0x30, + 0x02, 0xc7, 0x01, 0xc6, 0xe0, 0x7f, 0x18, 0x14, 0x0d, 0x34, 0xe0, 0x78, + 0x48, 0x43, 0x20, 0x42, 0x35, 0x0b, 0x70, 0x10, 0x20, 0x81, 0x31, 0x09, + 0x81, 0x0f, 0x80, 0x3f, 0x00, 0x00, 0x21, 0x82, 0x41, 0x0b, 0xf2, 0x10, + 0x01, 0x31, 0x01, 0x00, 0x40, 0x22, 0x0c, 0x02, 0x4a, 0x23, 0x80, 0x00, + 0x04, 0x14, 0x02, 0x14, 0x64, 0x71, 0x00, 0x31, 0x01, 0x00, 0xf9, 0x0b, + 0xe2, 0x82, 0x01, 0x31, 0x81, 0x00, 0x10, 0xf0, 0x1d, 0x0b, 0xb2, 0x10, + 0x4a, 0x23, 0x40, 0x00, 0x04, 0x12, 0x0c, 0x02, 0x40, 0x23, 0x43, 0x00, + 0x00, 0x31, 0x01, 0x00, 0xf5, 0x0b, 0xe2, 0x82, 0x01, 0x31, 0x01, 0x03, + 0xe0, 0x7f, 0x20, 0x40, 0x50, 0x20, 0xfe, 0x87, 0x00, 0x19, 0x01, 0x00, + 0xe0, 0x7c, 0x41, 0x28, 0xc2, 0x05, 0x04, 0x20, 0x80, 0x0f, 0x7f, 0x80, + 0xff, 0xff, 0x4f, 0x7a, 0x05, 0x20, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x80, 0x22, 0xbe, 0x00, 0xe0, 0x7f, 0x40, 0xa1, 0xff, 0xd9, 0x17, 0xb9, + 0x04, 0x20, 0x42, 0x00, 0x30, 0x72, 0x2c, 0x70, 0x04, 0xf4, 0xd6, 0xb8, + 0x78, 0x20, 0x01, 0x00, 0xe0, 0x7f, 0x20, 0x40, 0xc3, 0x41, 0xa0, 0x00, + 0x60, 0x88, 0x40, 0x81, 0x00, 0xa1, 0xe0, 0x7f, 0x40, 0x40, 0xe0, 0x78, + 0xc3, 0x41, 0xa0, 0x00, 0x60, 0x88, 0x20, 0x81, 0x02, 0xe9, 0x00, 0x79, + 0xe0, 0x7f, 0x0c, 0x70, 0xe0, 0x7f, 0x0c, 0x70, 0x2f, 0x23, 0x00, 0x80, + 0xca, 0x21, 0x01, 0x00, 0xe1, 0x20, 0xc1, 0x07, 0xc2, 0x20, 0x01, 0x00, + 0x41, 0x2b, 0xc2, 0x00, 0xc3, 0x72, 0x00, 0x70, 0x00, 0x00, 0x2f, 0x21, + 0x84, 0x00, 0x41, 0x2b, 0x0c, 0x06, 0x61, 0xbc, 0x8c, 0x24, 0x83, 0x9f, + 0xe1, 0x20, 0xc5, 0x07, 0x40, 0x2b, 0x00, 0x07, 0xc5, 0x21, 0x81, 0x0f, + 0x00, 0x7f, 0x00, 0x00, 0xe1, 0x20, 0xc1, 0x07, 0x41, 0x2a, 0x42, 0x05, + 0x2f, 0x2c, 0xc1, 0x90, 0xc2, 0x24, 0x04, 0x13, 0xc0, 0x24, 0x63, 0x10, + 0x85, 0x71, 0x00, 0x2b, 0x03, 0x03, 0x69, 0xbc, 0x82, 0x7a, 0x40, 0x2a, + 0x42, 0x05, 0x2f, 0x21, 0x40, 0x80, 0x2f, 0x21, 0x84, 0x00, 0x41, 0x2b, + 0x0c, 0x03, 0x85, 0x79, 0xe0, 0x7f, 0x40, 0x2b, 0x00, 0x05, 0xe0, 0x78, + 0x2f, 0x24, 0x40, 0x90, 0x02, 0x24, 0x83, 0x1f, 0x00, 0x70, 0x00, 0x00, + 0x40, 0x2b, 0xc2, 0x00, 0x2f, 0x22, 0x84, 0x00, 0x02, 0x23, 0x83, 0x0f, + 0x20, 0x00, 0x00, 0x00, 0xd3, 0x73, 0xc0, 0x1f, 0x00, 0x00, 0x40, 0x28, + 0x03, 0x01, 0x20, 0x00, 0x26, 0x00, 0x41, 0x28, 0x40, 0x87, 0x45, 0x78, + 0x44, 0x20, 0x41, 0x00, 0x05, 0x21, 0xc1, 0x80, 0xe0, 0x7f, 0xc1, 0x20, + 0x22, 0x00, 0xe0, 0x7f, 0x6c, 0x21, 0x80, 0x07, 0x2f, 0x23, 0xc4, 0x00, + 0x45, 0x78, 0x41, 0x2c, 0x4c, 0x15, 0x82, 0x24, 0x0d, 0x9a, 0xb7, 0xf6, + 0x42, 0x24, 0x0c, 0x96, 0x53, 0x20, 0x81, 0x05, 0x22, 0x00, 0x2c, 0x00, + 0x2f, 0x20, 0x00, 0x80, 0x05, 0x21, 0xc1, 0x80, 0x2f, 0x20, 0x84, 0x0f, + 0x80, 0xff, 0x00, 0x00, 0xd0, 0x20, 0xa1, 0x05, 0x8c, 0x24, 0xd1, 0x9f, + 0xe0, 0x7f, 0xd0, 0x20, 0xa2, 0x05, 0x4e, 0x24, 0x02, 0x10, 0x97, 0xb9, + 0x01, 0x29, 0x80, 0x00, 0x2f, 0x20, 0x04, 0x80, 0xe1, 0x20, 0xc6, 0x07, + 0x4e, 0x22, 0xcc, 0x07, 0x13, 0x21, 0x01, 0x03, 0x05, 0x21, 0xc1, 0x80, + 0xd1, 0x20, 0x21, 0x80, 0xe0, 0x7f, 0xc0, 0x20, 0x62, 0x00, 0xe0, 0x78, + 0xcb, 0x44, 0xe0, 0xff, 0x00, 0x00, 0x14, 0x24, 0x44, 0x10, 0x14, 0x24, + 0xc5, 0x10, 0xb5, 0xbc, 0x0c, 0x24, 0x00, 0x83, 0xe0, 0x00, 0x06, 0x00, + 0x0c, 0x25, 0x00, 0x83, 0xd8, 0x00, 0x06, 0x00, 0x41, 0x2c, 0x44, 0x05, + 0x41, 0x2d, 0x45, 0x05, 0x00, 0x25, 0x05, 0x01, 0x82, 0x25, 0x8f, 0x0f, + 0x8c, 0x25, 0xdf, 0x8e, 0xc0, 0x00, 0x26, 0x00, 0x07, 0x21, 0xcc, 0x80, + 0x40, 0x25, 0x47, 0x00, 0x94, 0xb9, 0xd4, 0xb9, 0x94, 0xbb, 0xcf, 0x27, + 0xe4, 0x02, 0x40, 0x2b, 0xc3, 0x02, 0x41, 0x2a, 0x45, 0x05, 0x40, 0x2a, + 0xc2, 0x82, 0x05, 0x23, 0x43, 0x01, 0x1d, 0x20, 0x84, 0x00, 0x1c, 0x20, + 0x8c, 0x00, 0x94, 0x70, 0xcf, 0x27, 0xe2, 0x07, 0x1d, 0x20, 0xc4, 0x00, + 0x1c, 0x20, 0xc5, 0x00, 0x00, 0x24, 0x0c, 0x91, 0x41, 0x25, 0x00, 0x00, + 0x1d, 0x21, 0x84, 0x00, 0x1c, 0x21, 0x85, 0x00, 0x00, 0x24, 0x0c, 0x91, + 0x01, 0x20, 0x40, 0x81, 0x1d, 0x21, 0xc4, 0x00, 0x1c, 0x21, 0xc5, 0x00, + 0x41, 0x26, 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x81, + 0x01, 0x21, 0x41, 0x01, 0x19, 0x09, 0x3f, 0x05, 0x00, 0x24, 0x0c, 0x93, + 0x42, 0x27, 0x47, 0x00, 0x01, 0x20, 0x00, 0x80, 0x01, 0x21, 0x41, 0x00, + 0x00, 0x24, 0x0c, 0x93, 0x40, 0x2f, 0x04, 0x05, 0x41, 0x2f, 0xc7, 0x07, + 0x08, 0x00, 0x05, 0x00, 0xe0, 0x7f, 0x80, 0x71, 0xc5, 0x24, 0xc1, 0x91, + 0x44, 0x20, 0x45, 0x00, 0xc5, 0x25, 0x62, 0x00, 0x00, 0x20, 0x40, 0x81, + 0x41, 0x21, 0x01, 0x00, 0x15, 0x09, 0x5e, 0x05, 0x00, 0x24, 0x84, 0x0f, + 0x10, 0x00, 0x00, 0x00, 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, + 0xe0, 0x7f, 0x80, 0x71, 0x2f, 0x25, 0xc0, 0x80, 0x41, 0x26, 0x04, 0x70, + 0x00, 0x00, 0x00, 0x00, 0xcc, 0x22, 0x21, 0x80, 0x60, 0x03, 0x21, 0x00, + 0x2f, 0x21, 0x40, 0x90, 0xc7, 0x24, 0x65, 0x00, 0xcc, 0x20, 0x21, 0x80, + 0x2c, 0x03, 0x01, 0x00, 0x41, 0x29, 0x46, 0x95, 0x06, 0x21, 0x81, 0x0f, + 0xf0, 0xff, 0x00, 0x00, 0xc5, 0x21, 0x82, 0x0f, 0x10, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x22, 0x00, 0x00, 0x40, 0x34, 0x70, 0x0c, 0x00, 0x01, 0x00, + 0x1b, 0x00, 0x20, 0x00, 0x2f, 0x2a, 0x41, 0x10, 0x14, 0x70, 0x4a, 0x22, + 0xc0, 0x17, 0x0e, 0x00, 0x04, 0x00, 0x2f, 0x2a, 0x01, 0x10, 0x40, 0x22, + 0x0a, 0x18, 0x42, 0x22, 0x8a, 0x12, 0x02, 0x26, 0x86, 0x02, 0xc4, 0x71, + 0x02, 0x26, 0x8b, 0xf2, 0x00, 0x00, 0x20, 0x00, 0x01, 0x28, 0xcb, 0x02, + 0x12, 0x00, 0x09, 0x00, 0x42, 0x22, 0x0b, 0x18, 0x00, 0x28, 0xc1, 0x02, + 0x13, 0x00, 0x20, 0x00, 0x0c, 0x70, 0x00, 0x28, 0x80, 0x02, 0x00, 0x29, + 0x8a, 0x02, 0x05, 0x23, 0x81, 0x12, 0x41, 0x2d, 0x47, 0x85, 0x06, 0x23, + 0x88, 0x0f, 0xf0, 0xff, 0x00, 0x00, 0xc5, 0x20, 0x82, 0x1f, 0x10, 0x00, + 0x00, 0x00, 0x5c, 0x00, 0x22, 0x00, 0x40, 0x42, 0x15, 0x70, 0x0e, 0x00, + 0x01, 0x00, 0x1d, 0x00, 0x20, 0x00, 0x2f, 0x2a, 0x01, 0x12, 0x54, 0x70, + 0x4a, 0x22, 0xc0, 0x17, 0x0c, 0x00, 0x04, 0x00, 0x2f, 0x2a, 0x81, 0x10, + 0x40, 0x22, 0x0a, 0x18, 0x42, 0x22, 0x8a, 0x12, 0x02, 0x27, 0x87, 0x02, + 0xe4, 0x71, 0x02, 0x26, 0x8b, 0xf2, 0x00, 0x00, 0x20, 0x00, 0x01, 0x2a, + 0xcb, 0x02, 0x14, 0x00, 0x09, 0x00, 0x42, 0x22, 0x0b, 0x18, 0x00, 0x2a, + 0xc8, 0x02, 0x15, 0x00, 0x20, 0x00, 0x4c, 0x70, 0x00, 0x2a, 0x82, 0x02, + 0x00, 0x28, 0x8a, 0x12, 0x05, 0x23, 0x88, 0x12, 0x8c, 0x26, 0xdf, 0x8f, + 0xf2, 0x01, 0x01, 0x00, 0x8c, 0x27, 0xdf, 0x8f, 0x1c, 0x02, 0x21, 0x00, + 0x00, 0x26, 0xc6, 0x01, 0x1d, 0x20, 0x8a, 0x00, 0x1c, 0x20, 0x8b, 0x00, + 0x82, 0x26, 0xcf, 0x0f, 0x1d, 0x21, 0x87, 0x00, 0x1c, 0x21, 0x8c, 0x00, + 0x00, 0x23, 0xcb, 0x91, 0x41, 0x24, 0x02, 0x10, 0x1d, 0x20, 0x07, 0x02, + 0x1c, 0x20, 0x0c, 0x02, 0x00, 0x23, 0xcb, 0x91, 0x01, 0x22, 0x02, 0x03, + 0x1d, 0x21, 0x07, 0x02, 0x1c, 0x21, 0x0c, 0x02, 0x00, 0x22, 0xc2, 0x81, + 0x41, 0x24, 0x09, 0x10, 0x40, 0x29, 0x01, 0x13, 0x41, 0x2a, 0x03, 0x05, + 0x65, 0x79, 0x40, 0x2a, 0x07, 0x03, 0x40, 0x2a, 0x00, 0x03, 0x41, 0x2b, + 0x03, 0x15, 0x65, 0x78, 0x40, 0x2b, 0x0c, 0x13, 0x55, 0x70, 0xc5, 0x24, + 0xa2, 0x10, 0xd4, 0x70, 0x1e, 0x00, 0x0c, 0x00, 0x04, 0x21, 0xbe, 0x8f, + 0x20, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x00, 0xc4, 0x71, 0x2f, 0x21, + 0x42, 0x80, 0x2f, 0x20, 0x04, 0x80, 0x2f, 0x24, 0x04, 0x13, 0x95, 0x70, + 0x36, 0x00, 0x0a, 0x00, 0x04, 0x24, 0xbe, 0x9f, 0xff, 0x7f, 0xff, 0xff, + 0x0c, 0x00, 0x02, 0x00, 0x44, 0x20, 0x7e, 0x80, 0x22, 0x00, 0x01, 0x00, + 0x40, 0x20, 0x40, 0x80, 0x41, 0x21, 0x01, 0x00, 0x04, 0x21, 0xbe, 0x8f, + 0x20, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x01, 0x00, 0xc4, 0x71, 0x2f, 0x21, + 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0x8c, 0x26, 0xdf, 0x8f, 0x0e, 0x01, + 0x0a, 0x00, 0xd4, 0x70, 0x1a, 0x00, 0x0c, 0x00, 0x06, 0x21, 0x81, 0x0f, + 0x10, 0x00, 0x00, 0x00, 0x40, 0x2e, 0x02, 0x05, 0x45, 0x79, 0x2f, 0x22, + 0x03, 0x01, 0x45, 0x79, 0xe0, 0x7e, 0x8c, 0x26, 0xff, 0x82, 0xfa, 0x00, + 0x0b, 0x00, 0x02, 0x26, 0x8a, 0x71, 0x00, 0x00, 0x00, 0x00, 0x42, 0x22, + 0x4a, 0x90, 0x4a, 0x26, 0x00, 0x70, 0x88, 0x00, 0x0b, 0x00, 0x8c, 0x00, + 0x01, 0x00, 0x4c, 0x22, 0x00, 0x98, 0x4a, 0x26, 0x00, 0x70, 0x2a, 0x00, + 0x0b, 0x00, 0x42, 0x22, 0x0a, 0x18, 0x05, 0x24, 0x0c, 0x90, 0x6d, 0x77, + 0x10, 0x00, 0x02, 0x00, 0x00, 0x2b, 0x8b, 0x12, 0x87, 0x23, 0xff, 0x1f, + 0x04, 0x21, 0xcc, 0x02, 0x01, 0x29, 0x80, 0x02, 0x5d, 0x00, 0x20, 0x00, + 0x2c, 0x70, 0x95, 0x70, 0x6d, 0x77, 0x1e, 0x00, 0x02, 0x00, 0x4c, 0x22, + 0x00, 0x98, 0xc2, 0x23, 0xca, 0x12, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x2b, + 0x8b, 0x12, 0x87, 0x23, 0xff, 0x1f, 0x04, 0x20, 0xcc, 0x02, 0x02, 0x26, + 0x8b, 0xf2, 0x00, 0x00, 0x20, 0x00, 0x00, 0x29, 0xcb, 0x02, 0x14, 0x00, + 0x09, 0x00, 0x40, 0x22, 0x0b, 0x18, 0x01, 0x29, 0xc0, 0x02, 0x15, 0x00, + 0x20, 0x00, 0x2c, 0x70, 0x01, 0x28, 0x80, 0x02, 0x01, 0x29, 0x81, 0x02, + 0x05, 0x20, 0xc0, 0x02, 0x0d, 0x00, 0x00, 0x00, 0x2f, 0x20, 0x00, 0x80, + 0x2f, 0x21, 0x4b, 0x00, 0x44, 0x20, 0xbe, 0x80, 0x4a, 0x26, 0x00, 0x70, + 0x1c, 0x00, 0x01, 0x00, 0x44, 0x20, 0x4a, 0x01, 0x05, 0x22, 0x3e, 0x93, + 0x4a, 0x26, 0x00, 0x70, 0x0c, 0x00, 0x01, 0x00, 0x40, 0x20, 0x80, 0x80, + 0x41, 0x21, 0x01, 0x00, 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, + 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0x02, 0x26, 0x86, 0x01, + 0x04, 0x21, 0xbe, 0x8f, 0x10, 0x00, 0x00, 0x00, 0xc0, 0x26, 0x62, 0x00, + 0x80, 0xf1, 0x8a, 0x26, 0xdf, 0x0f, 0xc3, 0x41, 0x10, 0x00, 0x00, 0x00, + 0xf5, 0x06, 0xef, 0xff, 0x0c, 0x70, 0x02, 0x26, 0x86, 0x01, 0x2c, 0x70, + 0xe9, 0x06, 0xef, 0xff, 0x0c, 0x70, 0xd3, 0x71, 0x10, 0x00, 0x00, 0x00, + 0xcc, 0x20, 0x21, 0x80, 0x2f, 0x21, 0x03, 0x01, 0xc5, 0x21, 0x82, 0x0f, + 0xf8, 0x7f, 0x00, 0x00, 0xc0, 0x78, 0x70, 0xf5, 0x8c, 0x27, 0xdf, 0x8f, + 0x14, 0x00, 0x01, 0x00, 0x2f, 0x21, 0x03, 0x01, 0x05, 0x21, 0x81, 0x0f, + 0xf0, 0x7f, 0x00, 0x00, 0x0c, 0x70, 0x64, 0xf1, 0x0c, 0x20, 0x80, 0x9f, + 0x10, 0x00, 0x00, 0x00, 0xcc, 0x22, 0x21, 0x80, 0x2f, 0x21, 0x03, 0x01, + 0xc5, 0x21, 0x82, 0x0f, 0xf8, 0x7f, 0x00, 0x00, 0xc5, 0x21, 0x81, 0x0f, + 0xf0, 0x7f, 0x00, 0x00, 0x0c, 0x70, 0x52, 0xf1, 0x0c, 0x25, 0x80, 0x8f, + 0xe0, 0xff, 0x00, 0x00, 0x4a, 0x26, 0x00, 0x70, 0x2a, 0x00, 0x06, 0x00, + 0x4a, 0x26, 0x00, 0x70, 0x0c, 0x70, 0x2c, 0x70, 0x94, 0x70, 0xc5, 0x21, + 0x82, 0x0f, 0x00, 0x80, 0x00, 0x00, 0x40, 0xf1, 0xc7, 0x24, 0x65, 0x00, + 0x0c, 0x21, 0x80, 0x9f, 0xe0, 0xff, 0x00, 0x00, 0xb2, 0xf7, 0x4a, 0x26, + 0x00, 0x70, 0xc3, 0x41, 0xf8, 0x7f, 0x00, 0x00, 0x0c, 0x70, 0x32, 0xf1, + 0x07, 0x21, 0x81, 0x0f, 0x00, 0x80, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x07, 0x23, 0x83, 0x0f, 0x00, 0x80, 0x00, 0x00, 0x00, 0x21, 0x44, 0x00, + 0x00, 0x23, 0xc5, 0x00, 0x0c, 0x24, 0x40, 0x81, 0xcc, 0x20, 0x81, 0x80, + 0x10, 0x00, 0x06, 0x00, 0x08, 0x44, 0x40, 0x40, 0x81, 0x42, 0x28, 0x44, + 0x60, 0x41, 0x81, 0x43, 0x8a, 0x24, 0xdf, 0x1f, 0x40, 0x2c, 0x4c, 0x15, + 0x14, 0x24, 0x44, 0x10, 0x14, 0x24, 0xc5, 0x10, 0x40, 0x2c, 0x8c, 0x10, + 0x0c, 0x24, 0x00, 0x83, 0xcc, 0x25, 0x05, 0x83, 0xc6, 0x01, 0x06, 0x00, + 0x41, 0x29, 0x04, 0x05, 0x41, 0x2b, 0x05, 0x05, 0x02, 0x24, 0x46, 0x01, + 0x53, 0x26, 0x86, 0x02, 0x07, 0x21, 0xc7, 0x00, 0x40, 0x29, 0xc1, 0x02, + 0x41, 0x28, 0x4c, 0x05, 0x85, 0x79, 0x40, 0x28, 0xc0, 0x02, 0x40, 0x2b, + 0xc3, 0x02, 0x41, 0x2a, 0x4c, 0x05, 0x85, 0x7b, 0x40, 0x2a, 0xc2, 0x02, + 0x9f, 0xbb, 0x4e, 0x26, 0x0c, 0x88, 0x1c, 0x00, 0x2d, 0x00, 0x01, 0x2a, + 0x85, 0x01, 0x8c, 0x26, 0x01, 0x80, 0x01, 0x2b, 0x85, 0x01, 0xca, 0x25, + 0x26, 0x00, 0x17, 0x00, 0x20, 0x00, 0x8d, 0x70, 0xd4, 0x70, 0x00, 0x2b, + 0x0c, 0x03, 0xc5, 0x25, 0x02, 0x03, 0x01, 0x2b, 0x8c, 0x01, 0x41, 0x2f, + 0xc7, 0x87, 0x62, 0x00, 0x22, 0x00, 0x9f, 0xb9, 0x00, 0x25, 0x05, 0x80, + 0x01, 0x24, 0x4c, 0x90, 0x10, 0x00, 0x26, 0x00, 0xc2, 0x24, 0x66, 0x00, + 0x2f, 0x24, 0x04, 0x93, 0x2f, 0x25, 0x44, 0x01, 0x41, 0x2d, 0xc0, 0x82, + 0x40, 0x2c, 0x41, 0x15, 0x25, 0x78, 0x41, 0x2c, 0xc1, 0x12, 0x40, 0x2c, + 0x04, 0x05, 0xe1, 0x20, 0xc6, 0x07, 0x80, 0x71, 0x4c, 0x26, 0x00, 0x88, + 0xca, 0x23, 0x85, 0x00, 0xca, 0x22, 0x25, 0x00, 0x13, 0x23, 0x83, 0x01, + 0x05, 0x23, 0x83, 0x80, 0xd3, 0x25, 0x61, 0x82, 0xd1, 0x20, 0x21, 0x80, + 0xca, 0x27, 0x62, 0x00, 0x00, 0x20, 0xc0, 0x81, 0xe0, 0x7f, 0x41, 0x21, + 0x01, 0x00, 0x0e, 0x25, 0x05, 0x80, 0x03, 0x21, 0x0c, 0x83, 0x52, 0x00, + 0x23, 0x00, 0x0c, 0x70, 0x41, 0x2d, 0xc0, 0x82, 0x40, 0x2c, 0x41, 0x15, + 0x25, 0x78, 0x41, 0x2c, 0xc1, 0x12, 0x42, 0x24, 0x44, 0x00, 0x40, 0x2c, + 0x04, 0x05, 0xe1, 0x20, 0xc6, 0x07, 0x80, 0x71, 0x4c, 0x26, 0x00, 0x88, + 0xca, 0x23, 0x85, 0x00, 0xca, 0x22, 0x25, 0x00, 0x13, 0x23, 0x83, 0x01, + 0x05, 0x23, 0x83, 0x80, 0xca, 0x27, 0x22, 0x00, 0x04, 0x27, 0x07, 0x80, + 0xd3, 0x25, 0x61, 0x82, 0xca, 0x27, 0x62, 0x00, 0x00, 0x20, 0xc0, 0x81, + 0xe0, 0x7f, 0x41, 0x21, 0x01, 0x00, 0xcc, 0x25, 0x21, 0x80, 0xe1, 0x20, + 0xc1, 0x07, 0x2c, 0x70, 0x2f, 0x28, 0x01, 0x03, 0x9f, 0xe0, 0x14, 0x00, + 0x25, 0x00, 0x04, 0x71, 0x2f, 0x28, 0x41, 0x81, 0xca, 0x20, 0x24, 0x08, + 0xc0, 0x20, 0x63, 0x08, 0x4e, 0x20, 0x01, 0x88, 0x18, 0x00, 0x2d, 0x00, + 0x00, 0x2c, 0x0c, 0x10, 0xc0, 0xe0, 0x00, 0x2d, 0x0c, 0x00, 0xca, 0x24, + 0x26, 0x10, 0x17, 0x00, 0x20, 0x00, 0xac, 0x70, 0x14, 0x70, 0x01, 0x2d, + 0x41, 0x00, 0xc5, 0x24, 0x42, 0x10, 0x00, 0x2d, 0x05, 0x00, 0x53, 0x24, + 0x81, 0x02, 0x0e, 0x20, 0x40, 0x80, 0x04, 0x24, 0x84, 0x0f, 0x00, 0x00, + 0x00, 0x08, 0x12, 0x00, 0x22, 0x00, 0xc0, 0x20, 0x61, 0x00, 0x2f, 0x24, + 0x02, 0x93, 0x2f, 0x25, 0x44, 0x01, 0x4c, 0x07, 0xe6, 0xff, 0xc5, 0x24, + 0x06, 0x00, 0x4e, 0x20, 0x40, 0x00, 0x4e, 0x20, 0x01, 0x88, 0x1a, 0x00, + 0x2d, 0x00, 0x01, 0x2d, 0x05, 0x00, 0xc0, 0xe0, 0x01, 0x2c, 0x05, 0x10, + 0xca, 0x25, 0x26, 0x00, 0x15, 0x00, 0x20, 0x00, 0x8d, 0x70, 0x14, 0x70, + 0x00, 0x2c, 0x41, 0x10, 0xc5, 0x25, 0x42, 0x00, 0x01, 0x2c, 0x0c, 0x10, + 0x15, 0x07, 0xef, 0xff, 0x84, 0x71, 0x2f, 0x22, 0x40, 0x90, 0x41, 0x26, + 0x04, 0x70, 0x00, 0x00, 0x00, 0x00, 0x90, 0x02, 0x01, 0x00, 0x2f, 0x23, + 0xc0, 0x90, 0x41, 0x26, 0x05, 0x70, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x02, + 0x01, 0x00, 0x0c, 0x23, 0x80, 0x92, 0xcc, 0x22, 0x01, 0x80, 0xcc, 0x21, + 0xc1, 0x80, 0x08, 0x42, 0x14, 0x00, 0x0e, 0x00, 0x40, 0x40, 0x41, 0x42, + 0x28, 0x42, 0x60, 0x41, 0x41, 0x43, 0x88, 0x42, 0xa0, 0x44, 0x41, 0x45, + 0x2f, 0x26, 0x40, 0x00, 0x41, 0x2e, 0x46, 0x85, 0x06, 0x21, 0x81, 0x0f, + 0xf0, 0xff, 0x00, 0x00, 0xc5, 0x21, 0x82, 0x0f, 0x10, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x22, 0x00, 0x00, 0x40, 0x34, 0x70, 0x0c, 0x00, 0x01, 0x00, + 0x1b, 0x00, 0x20, 0x00, 0x2f, 0x2a, 0x41, 0x10, 0x14, 0x70, 0x4a, 0x22, + 0xc0, 0x17, 0x0e, 0x00, 0x04, 0x00, 0x2f, 0x2a, 0x01, 0x10, 0x40, 0x22, + 0x0a, 0x18, 0x42, 0x22, 0x8a, 0x12, 0x02, 0x26, 0x86, 0x02, 0xc4, 0x71, + 0x02, 0x26, 0x8b, 0xf2, 0x00, 0x00, 0x20, 0x00, 0x01, 0x28, 0xcb, 0x02, + 0x12, 0x00, 0x09, 0x00, 0x42, 0x22, 0x0b, 0x18, 0x00, 0x28, 0xc1, 0x02, + 0x13, 0x00, 0x20, 0x00, 0x0c, 0x70, 0x00, 0x28, 0x80, 0x02, 0x00, 0x29, + 0x8a, 0x02, 0x05, 0x23, 0x81, 0x12, 0x2f, 0x27, 0xc0, 0x00, 0x41, 0x2f, + 0x47, 0x85, 0x06, 0x23, 0x88, 0x0f, 0xf0, 0xff, 0x00, 0x00, 0xc5, 0x20, + 0x82, 0x1f, 0x10, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x22, 0x00, 0x40, 0x42, + 0x15, 0x70, 0x0e, 0x00, 0x01, 0x00, 0x1d, 0x00, 0x20, 0x00, 0x2f, 0x2a, + 0x01, 0x12, 0x54, 0x70, 0x4a, 0x22, 0xc0, 0x17, 0x0c, 0x00, 0x04, 0x00, + 0x2f, 0x2a, 0x81, 0x10, 0x40, 0x22, 0x0a, 0x18, 0x42, 0x22, 0x8a, 0x12, + 0x02, 0x27, 0x87, 0x02, 0xe4, 0x71, 0x02, 0x26, 0x8b, 0xf2, 0x00, 0x00, + 0x20, 0x00, 0x01, 0x2a, 0xcb, 0x02, 0x14, 0x00, 0x09, 0x00, 0x42, 0x22, + 0x0b, 0x18, 0x00, 0x2a, 0xc8, 0x02, 0x15, 0x00, 0x20, 0x00, 0x4c, 0x70, + 0x00, 0x2a, 0x82, 0x02, 0x00, 0x28, 0x8a, 0x12, 0x05, 0x23, 0x88, 0x12, + 0x8c, 0x26, 0xdf, 0x8f, 0x4a, 0x26, 0x00, 0x70, 0xa6, 0x03, 0x01, 0x00, + 0x8c, 0x27, 0xdf, 0x8f, 0x4a, 0x26, 0x00, 0x70, 0xf4, 0x03, 0x21, 0x00, + 0x02, 0x26, 0xcb, 0x01, 0x4c, 0x23, 0x80, 0x9d, 0x02, 0x21, 0x49, 0x12, + 0x3a, 0x01, 0x09, 0x00, 0x42, 0x23, 0x8a, 0x90, 0x4a, 0x26, 0x00, 0x70, + 0x8a, 0x00, 0x01, 0x00, 0x24, 0x00, 0x09, 0x00, 0x2f, 0x22, 0x80, 0x80, + 0x2f, 0x20, 0x0b, 0x12, 0x40, 0x22, 0x4a, 0x90, 0x4a, 0x26, 0x00, 0x70, + 0x72, 0x00, 0x01, 0x00, 0x2f, 0x22, 0x80, 0x80, 0x6b, 0x00, 0x20, 0x00, + 0x2f, 0x20, 0x0b, 0x12, 0x4c, 0x22, 0x00, 0x98, 0x6d, 0x70, 0x28, 0x00, + 0x2b, 0x00, 0x42, 0x22, 0x0a, 0x18, 0x0a, 0x21, 0x80, 0x90, 0x12, 0x00, + 0x02, 0x00, 0x02, 0x26, 0x8b, 0x72, 0x00, 0x00, 0x20, 0x00, 0x00, 0x28, + 0xc9, 0x12, 0x01, 0x28, 0x82, 0x12, 0x3f, 0x00, 0x20, 0x00, 0x0d, 0x70, + 0x02, 0x26, 0x8b, 0x72, 0x00, 0x00, 0x20, 0x00, 0x00, 0x2a, 0xc9, 0x02, + 0x02, 0x26, 0x8b, 0xf2, 0x00, 0x00, 0x20, 0x00, 0x00, 0x28, 0xcb, 0x12, + 0x12, 0x00, 0x09, 0x00, 0x40, 0x22, 0x0b, 0x18, 0x01, 0x28, 0xc2, 0x12, + 0x13, 0x00, 0x20, 0x00, 0x0d, 0x70, 0x01, 0x2a, 0x82, 0x02, 0x01, 0x28, + 0x88, 0x12, 0x05, 0x22, 0xc2, 0x02, 0x2f, 0x20, 0x00, 0x80, 0x2f, 0x21, + 0x4b, 0x00, 0x2f, 0x20, 0x00, 0x80, 0x2f, 0x21, 0x4b, 0x00, 0x0c, 0x24, + 0x40, 0x81, 0x4a, 0x26, 0x00, 0x70, 0xe0, 0x01, 0x02, 0x00, 0x00, 0x20, + 0x80, 0x80, 0x01, 0x21, 0x01, 0x02, 0x04, 0x21, 0xbe, 0x8f, 0x80, 0x00, + 0x00, 0x00, 0x4a, 0x26, 0x00, 0x70, 0x14, 0x00, 0x01, 0x00, 0xc4, 0x71, + 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x80, 0xc5, 0x21, 0x65, 0x10, + 0x44, 0x20, 0xbe, 0x80, 0x4a, 0x26, 0x00, 0x70, 0x34, 0x00, 0x21, 0x00, + 0x35, 0x70, 0xcb, 0x20, 0x61, 0x81, 0x4a, 0x26, 0x00, 0x70, 0x28, 0x00, + 0x01, 0x00, 0x40, 0x20, 0x80, 0x80, 0xc0, 0x21, 0x65, 0x00, 0x04, 0x21, + 0xbe, 0x8f, 0x80, 0x00, 0x00, 0x00, 0x4a, 0x26, 0x00, 0x70, 0x10, 0x00, + 0x01, 0x00, 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0xc4, 0x71, + 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0x2f, 0x21, 0x42, 0x80, + 0x2f, 0x20, 0x04, 0x00, 0xd4, 0x70, 0x4a, 0x26, 0x00, 0x70, 0x66, 0x00, + 0x0c, 0x00, 0x8c, 0x26, 0xdf, 0x8f, 0x4a, 0x26, 0x00, 0x70, 0x3e, 0x01, + 0x0a, 0x00, 0x06, 0x21, 0x81, 0x0f, 0x10, 0x00, 0x00, 0x00, 0x40, 0x2e, + 0x02, 0x05, 0x45, 0x79, 0x2f, 0x22, 0x03, 0x01, 0x45, 0x79, 0xe0, 0x7e, + 0x14, 0x70, 0x4a, 0x26, 0x00, 0x70, 0x72, 0x05, 0xc2, 0xff, 0xd3, 0x73, + 0x00, 0x80, 0x00, 0x00, 0x4a, 0x26, 0x00, 0x70, 0x7c, 0x71, 0x12, 0x00, + 0x02, 0x00, 0x54, 0x70, 0x4a, 0x26, 0x00, 0x70, 0x7c, 0x71, 0xca, 0x21, + 0x41, 0x00, 0x40, 0x40, 0xe0, 0x7e, 0x54, 0x70, 0x4a, 0x26, 0x00, 0x70, + 0x56, 0x05, 0xc2, 0xff, 0x4a, 0x26, 0x00, 0x70, 0xe0, 0x7e, 0x4a, 0x26, + 0x00, 0x70, 0x02, 0x26, 0x8a, 0x71, 0x00, 0x00, 0x00, 0x00, 0x42, 0x22, + 0x4a, 0x90, 0x4a, 0x26, 0x00, 0x70, 0x88, 0x00, 0x0b, 0x00, 0x8c, 0x00, + 0x01, 0x00, 0x4c, 0x22, 0x00, 0x98, 0x4a, 0x26, 0x00, 0x70, 0x2a, 0x00, + 0x0b, 0x00, 0x42, 0x22, 0x0a, 0x18, 0x05, 0x21, 0x09, 0x90, 0x6d, 0x77, + 0x10, 0x00, 0x02, 0x00, 0x00, 0x2b, 0x8b, 0x12, 0x87, 0x23, 0xff, 0x1f, + 0x04, 0x21, 0xc9, 0x02, 0x01, 0x29, 0x80, 0x02, 0x5d, 0x00, 0x20, 0x00, + 0x2c, 0x70, 0x35, 0x70, 0x6d, 0x77, 0x1e, 0x00, 0x02, 0x00, 0x4c, 0x22, + 0x00, 0x98, 0xc2, 0x23, 0xca, 0x12, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x2b, + 0x8b, 0x12, 0x87, 0x23, 0xff, 0x1f, 0x04, 0x20, 0xc9, 0x02, 0x02, 0x26, + 0x8b, 0xf2, 0x00, 0x00, 0x20, 0x00, 0x00, 0x29, 0xcb, 0x02, 0x14, 0x00, + 0x09, 0x00, 0x40, 0x22, 0x0b, 0x18, 0x01, 0x29, 0xc0, 0x02, 0x15, 0x00, + 0x20, 0x00, 0x2c, 0x70, 0x01, 0x28, 0x80, 0x02, 0x01, 0x29, 0x81, 0x02, + 0x05, 0x20, 0xc0, 0x02, 0x0d, 0x00, 0x00, 0x00, 0x2f, 0x20, 0x00, 0x80, + 0x2f, 0x21, 0x4b, 0x00, 0x44, 0x20, 0xbe, 0x80, 0x4a, 0x26, 0x00, 0x70, + 0x1c, 0x00, 0x01, 0x00, 0x44, 0x20, 0x4a, 0x01, 0x05, 0x22, 0x7e, 0x92, + 0x4a, 0x26, 0x00, 0x70, 0x0c, 0x00, 0x01, 0x00, 0x40, 0x20, 0x80, 0x80, + 0x41, 0x21, 0x01, 0x00, 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, + 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0x02, 0x26, 0x86, 0x01, + 0x04, 0x21, 0xbe, 0x8f, 0x10, 0x00, 0x00, 0x00, 0xc0, 0x26, 0x62, 0x00, + 0x65, 0xf1, 0x8a, 0x26, 0xdf, 0x0f, 0xc3, 0x41, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x70, 0x5f, 0xf1, 0x02, 0x26, 0x86, 0x01, 0x2c, 0x70, 0xb7, 0x06, + 0xef, 0xff, 0x0c, 0x70, 0x02, 0x20, 0x80, 0x80, 0x03, 0x21, 0x01, 0x02, + 0x04, 0x21, 0xbe, 0x8f, 0x40, 0x00, 0x00, 0x00, 0x4a, 0x26, 0x00, 0x70, + 0x20, 0x00, 0x02, 0x00, 0x2f, 0x20, 0x00, 0x80, 0x2f, 0x21, 0x4b, 0x00, + 0x42, 0x26, 0x46, 0x00, 0x04, 0x21, 0xbe, 0x8f, 0x40, 0x00, 0x00, 0x00, + 0x4a, 0x26, 0x00, 0x70, 0x52, 0x00, 0x01, 0x00, 0x44, 0x20, 0xbe, 0x80, + 0x4a, 0x26, 0x00, 0x70, 0x46, 0x00, 0x21, 0x00, 0x44, 0x20, 0x7e, 0x80, + 0x4a, 0x26, 0x00, 0x70, 0x1a, 0x00, 0x02, 0x00, 0x35, 0x70, 0x4a, 0x26, + 0x00, 0x70, 0x32, 0x00, 0x02, 0x00, 0x44, 0x20, 0x3e, 0x81, 0x4a, 0x26, + 0x00, 0x70, 0x26, 0x00, 0x01, 0x00, 0x40, 0x20, 0x80, 0x80, 0x41, 0x21, + 0x01, 0x00, 0x04, 0x21, 0xbe, 0x8f, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x26, + 0x62, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, + 0x04, 0x00, 0x2f, 0x21, 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0x2f, 0x21, + 0x42, 0x80, 0x2f, 0x20, 0x04, 0x00, 0xd3, 0x71, 0x10, 0x00, 0x00, 0x00, + 0x4a, 0x26, 0x00, 0x70, 0xfc, 0x05, 0xca, 0xff, 0x34, 0x70, 0x0e, 0x00, + 0x01, 0x00, 0x2f, 0x2a, 0x41, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x14, 0x70, + 0x08, 0x00, 0x0c, 0x00, 0x2f, 0x2a, 0x01, 0x00, 0xc0, 0x22, 0x29, 0x08, + 0x9c, 0xf3, 0xca, 0x22, 0xeb, 0x07, 0x6a, 0xba, 0x02, 0x26, 0x8b, 0xf0, + 0x00, 0x00, 0x20, 0x00, 0x01, 0x28, 0xcb, 0x02, 0x12, 0x00, 0x09, 0x00, + 0x42, 0x22, 0x0b, 0x08, 0x00, 0x28, 0xc1, 0x02, 0x13, 0x00, 0x20, 0x00, + 0x0c, 0x70, 0x00, 0x29, 0x81, 0x00, 0x05, 0x21, 0xc1, 0x02, 0x00, 0x28, + 0x80, 0x00, 0x02, 0x26, 0x86, 0x80, 0x4a, 0x26, 0x00, 0x70, 0x0e, 0x06, + 0xcc, 0xff, 0xb7, 0x05, 0xcf, 0xff, 0xd3, 0x71, 0x10, 0x00, 0x00, 0x00, + 0xcc, 0x20, 0x21, 0x80, 0x2f, 0x21, 0x03, 0x01, 0x02, 0x78, 0x10, 0x00, + 0x01, 0x00, 0x05, 0x21, 0x81, 0x0f, 0xf8, 0x7f, 0x00, 0x00, 0xe0, 0x7e, + 0x8c, 0x27, 0xdf, 0x8f, 0x4a, 0x26, 0x00, 0x70, 0x28, 0x00, 0x02, 0x00, + 0x0c, 0x20, 0x80, 0x9f, 0x10, 0x00, 0x00, 0x00, 0xcc, 0x22, 0x21, 0x80, + 0x4a, 0x26, 0x00, 0x70, 0x0a, 0x00, 0x01, 0x00, 0x2f, 0x21, 0x43, 0x01, + 0xe9, 0xf1, 0x0c, 0x24, 0x40, 0x81, 0x4a, 0x26, 0x00, 0x70, 0xe5, 0xf5, + 0x05, 0x21, 0x81, 0x0f, 0xf0, 0x7f, 0x00, 0x00, 0x0c, 0x70, 0xe0, 0x7e, + 0x60, 0x41, 0x40, 0x40, 0xe0, 0x7e, 0xe0, 0x78, 0xe2, 0xc2, 0x48, 0x31, + 0x01, 0x00, 0x08, 0x45, 0x07, 0x36, 0x4c, 0x70, 0x48, 0x47, 0x00, 0x00, + 0x09, 0x90, 0xc3, 0x43, 0x83, 0x3a, 0x6f, 0x12, 0x2c, 0x70, 0x48, 0x30, + 0x00, 0x00, 0x00, 0x34, 0x00, 0x10, 0x00, 0x30, 0xc0, 0x00, 0x04, 0x30, + 0x40, 0x80, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x30, 0x8d, 0x10, 0x7a, 0x8b, 0xe2, 0x48, 0x31, 0x01, 0x00, + 0xca, 0x20, 0xa6, 0x02, 0x10, 0x78, 0x00, 0x34, 0x41, 0x10, 0x48, 0x20, + 0xc0, 0x00, 0x0c, 0xb5, 0x86, 0x0b, 0xef, 0xf7, 0x00, 0x31, 0xc0, 0x00, + 0x2c, 0x70, 0x04, 0x30, 0x40, 0x80, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, 0x48, 0x30, 0x80, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x05, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0xea, 0xc3, 0x82, 0x24, + 0x0d, 0x34, 0x50, 0x41, 0x08, 0x45, 0x94, 0xc0, 0x8a, 0x22, 0x0c, 0x00, + 0x0e, 0x0d, 0x6f, 0xed, 0x28, 0x46, 0x00, 0x85, 0x40, 0x24, 0x83, 0x30, + 0x40, 0x24, 0x04, 0x32, 0x54, 0x24, 0x85, 0x39, 0x40, 0x24, 0x06, 0x31, + 0x40, 0x24, 0xc7, 0x30, 0xc1, 0x41, 0x22, 0x42, 0x1a, 0x09, 0xaf, 0xf4, + 0x02, 0x1c, 0x43, 0x32, 0x02, 0xc7, 0xe1, 0x0f, 0x31, 0x10, 0x56, 0x25, + 0x10, 0x1d, 0x03, 0x14, 0x8e, 0x30, 0x2c, 0x70, 0xed, 0x70, 0xd1, 0x09, + 0x31, 0x00, 0xcf, 0x78, 0x02, 0x14, 0x81, 0x30, 0xc5, 0x09, 0x24, 0x00, + 0x04, 0x77, 0xa9, 0x08, 0x55, 0x02, 0x25, 0x20, 0x00, 0x00, 0x0a, 0xf0, + 0x13, 0xf0, 0x1a, 0xf0, 0x1e, 0xf0, 0x26, 0xf0, 0x2e, 0xf0, 0x38, 0xf0, + 0x3c, 0xf0, 0x42, 0xf0, 0x94, 0xc0, 0x81, 0xc1, 0xfa, 0x0b, 0x6f, 0xf8, + 0x83, 0xc2, 0x83, 0xc1, 0x40, 0xda, 0x9e, 0x0c, 0x6f, 0xed, 0x02, 0x40, + 0x3c, 0xf0, 0x94, 0xc0, 0x1a, 0x09, 0xef, 0xf8, 0x81, 0xc1, 0x78, 0x1d, + 0x18, 0x10, 0x36, 0xf0, 0x94, 0xc0, 0x1a, 0x0e, 0xaf, 0xf0, 0x81, 0xc1, + 0x01, 0xa5, 0x30, 0xf0, 0x94, 0xc0, 0x02, 0x09, 0xef, 0xf8, 0x81, 0xc1, + 0x00, 0x30, 0x00, 0x00, 0x04, 0xa5, 0x28, 0xf0, 0x94, 0xc0, 0xf2, 0x08, + 0xef, 0xf8, 0x81, 0xc1, 0x00, 0x30, 0x01, 0x00, 0x89, 0x1d, 0x18, 0x10, + 0x25, 0xa5, 0x1e, 0xf0, 0x94, 0xc0, 0xde, 0x08, 0xef, 0xf8, 0x81, 0xc1, + 0x00, 0x30, 0x01, 0x00, 0x8a, 0x1d, 0x18, 0x10, 0x26, 0xa5, 0x14, 0xf0, + 0x94, 0xc0, 0xca, 0x08, 0xef, 0xf8, 0x81, 0xc1, 0x07, 0xa5, 0x0e, 0xf0, + 0x94, 0xc0, 0xc6, 0x0f, 0xaf, 0xf7, 0x81, 0xc1, 0x10, 0xb5, 0x08, 0xf0, + 0x94, 0xc0, 0xb2, 0x08, 0xef, 0xf8, 0x81, 0xc1, 0x8b, 0x1d, 0x18, 0x10, + 0x01, 0xc0, 0x8a, 0x21, 0x3e, 0x06, 0x32, 0x70, 0xca, 0x27, 0x4d, 0x10, + 0x3c, 0x21, 0x01, 0x20, 0x3d, 0x21, 0x00, 0x20, 0x1e, 0x66, 0x9b, 0xf1, + 0xe1, 0x40, 0xca, 0xc7, 0xec, 0xc3, 0xa7, 0xc1, 0x0a, 0x21, 0x00, 0x21, + 0x70, 0x40, 0x50, 0x42, 0x28, 0x46, 0x08, 0x45, 0x1a, 0x0b, 0x20, 0x00, + 0x55, 0x20, 0x8f, 0x09, 0x22, 0x85, 0xf6, 0x0a, 0xef, 0xfb, 0x03, 0x85, + 0x4a, 0x24, 0xc0, 0x70, 0x41, 0x68, 0x14, 0x20, 0x01, 0x00, 0x0c, 0x70, + 0x0c, 0x1d, 0x80, 0x10, 0xa8, 0x20, 0x00, 0x02, 0x02, 0x4e, 0x15, 0x25, + 0x43, 0x10, 0x04, 0x71, 0x24, 0x71, 0x4b, 0xa3, 0x72, 0x0c, 0x20, 0x00, + 0xa1, 0x40, 0x00, 0x19, 0x00, 0x20, 0xa1, 0x40, 0x82, 0x0d, 0x20, 0x00, + 0xc1, 0x41, 0x00, 0x41, 0xa1, 0x40, 0xb2, 0x0d, 0x20, 0x00, 0x30, 0x41, + 0x00, 0x41, 0xa1, 0x40, 0x36, 0x0c, 0x20, 0x00, 0x22, 0x42, 0xcd, 0x70, + 0x00, 0x18, 0x82, 0x23, 0x39, 0xe8, 0x21, 0x87, 0x02, 0x87, 0x40, 0x87, + 0x44, 0xc1, 0x45, 0xc0, 0x56, 0x25, 0x80, 0x1a, 0x83, 0xc1, 0x46, 0xc6, + 0x5a, 0x0c, 0x2f, 0xef, 0x43, 0xc2, 0x00, 0x18, 0x43, 0x20, 0xb8, 0x17, + 0x02, 0x10, 0xbc, 0x17, 0x01, 0x10, 0xc0, 0x17, 0x00, 0x10, 0x40, 0xc2, + 0x4a, 0x24, 0xc0, 0x70, 0x3f, 0xda, 0x40, 0x2a, 0x02, 0x06, 0x41, 0xc1, + 0x80, 0xc1, 0x4f, 0x22, 0xc3, 0x07, 0x42, 0xc0, 0xa8, 0x20, 0x40, 0x04, + 0x00, 0x81, 0x04, 0x30, 0x80, 0x83, 0xc5, 0xf6, 0x01, 0x30, 0x80, 0x00, + 0x03, 0xf0, 0x01, 0x30, 0xc0, 0x00, 0x48, 0x30, 0xc0, 0x02, 0x48, 0x30, + 0x80, 0x00, 0x04, 0x19, 0x10, 0x00, 0x02, 0xc2, 0x01, 0xc1, 0x00, 0xc0, + 0x45, 0xa7, 0x24, 0xa7, 0x03, 0xa7, 0x00, 0x10, 0x8e, 0x20, 0xa1, 0x40, + 0xc1, 0x41, 0xca, 0x0a, 0x20, 0x00, 0x22, 0x42, 0x4a, 0x24, 0xc0, 0x70, + 0x55, 0x25, 0x40, 0x1a, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x01, 0x04, + 0x04, 0x1a, 0x50, 0x20, 0x00, 0x88, 0x48, 0x30, 0x00, 0x00, 0x00, 0x1a, + 0x00, 0x20, 0xcc, 0xc7, 0xe8, 0xc3, 0xb2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, 0x6a, 0x0f, 0x6f, 0xf4, 0x03, 0x1c, + 0x43, 0x32, 0x02, 0x14, 0x80, 0x30, 0x56, 0x26, 0x10, 0x1d, 0x03, 0x14, + 0x81, 0x30, 0x0f, 0x78, 0x8d, 0x09, 0x24, 0x00, 0x04, 0x77, 0x7d, 0x08, + 0x55, 0x02, 0x25, 0x20, 0x00, 0x00, 0x0a, 0xf0, 0x14, 0xf0, 0x17, 0xf0, + 0x1c, 0xf0, 0x20, 0xf0, 0x21, 0xf0, 0x24, 0xf0, 0x24, 0xf0, 0x2b, 0xf0, + 0x82, 0xc0, 0x40, 0xda, 0xa6, 0x0a, 0x6f, 0xed, 0x02, 0x41, 0x82, 0xc0, + 0x81, 0xc3, 0xa1, 0x41, 0x0a, 0x0a, 0x6f, 0xf8, 0xe1, 0x42, 0x26, 0xf0, + 0x78, 0x16, 0x00, 0x16, 0x1d, 0xf0, 0x01, 0x86, 0x81, 0xc3, 0xa1, 0x41, + 0x36, 0x0c, 0xaf, 0xf0, 0xe1, 0x42, 0x1c, 0xf0, 0x04, 0x86, 0x2f, 0x30, + 0x00, 0x00, 0x13, 0xf0, 0x89, 0x16, 0x00, 0x16, 0x0f, 0xf0, 0x8a, 0x16, + 0x00, 0x16, 0x0d, 0xf0, 0x07, 0x86, 0x0b, 0xf0, 0x10, 0x96, 0x81, 0xc3, + 0xa1, 0x41, 0x06, 0x0e, 0xaf, 0xf7, 0xe1, 0x42, 0x08, 0xf0, 0x8b, 0x16, + 0x00, 0x16, 0x81, 0xc3, 0xa1, 0x41, 0xf6, 0x0e, 0xaf, 0xf8, 0xe1, 0x42, + 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xb9, 0xf1, + 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc8, 0xc7, + 0xe8, 0xc3, 0xa1, 0xc1, 0x50, 0x40, 0x28, 0x45, 0x2c, 0x70, 0x10, 0xda, + 0x60, 0x40, 0x88, 0x46, 0x66, 0x08, 0x6f, 0xfb, 0x68, 0x47, 0xb5, 0x70, + 0xad, 0x70, 0x1b, 0xf4, 0x4a, 0x24, 0x00, 0x71, 0xc3, 0x42, 0x13, 0x00, + 0x24, 0x6b, 0x0c, 0x70, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x03, 0x04, + 0x80, 0xc1, 0x1c, 0x61, 0x04, 0x71, 0x38, 0x23, 0x01, 0x04, 0x20, 0xac, + 0x6e, 0x0b, 0xaf, 0xf6, 0x80, 0xc0, 0x07, 0xe8, 0xad, 0x72, 0x01, 0x1f, + 0x03, 0x11, 0x00, 0x1f, 0x43, 0x10, 0xa0, 0xa6, 0xc8, 0xc7, 0xe0, 0x78, + 0xf2, 0xc3, 0xb2, 0xc1, 0x10, 0x45, 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, + 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x45, + 0x30, 0x44, 0x4e, 0x0e, 0x6f, 0xf4, 0x03, 0x1c, 0xc3, 0x32, 0x02, 0x14, + 0x80, 0x30, 0x56, 0x25, 0x0e, 0x2b, 0x55, 0x25, 0x4f, 0x2a, 0x55, 0x25, + 0xd0, 0x28, 0x55, 0x25, 0x91, 0x29, 0x55, 0x25, 0x13, 0x2d, 0x40, 0x25, + 0x12, 0x2b, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0xad, 0x09, 0x24, 0x00, + 0x04, 0x77, 0x9d, 0x08, 0xd5, 0x02, 0x25, 0x20, 0x00, 0x00, 0x0c, 0xf0, + 0x0d, 0xf0, 0x19, 0xf0, 0x19, 0xf0, 0x21, 0xf0, 0x22, 0xf0, 0x29, 0xf0, + 0x2a, 0xf0, 0x31, 0xf0, 0x36, 0xf0, 0x39, 0xf0, 0x81, 0xc3, 0xe1, 0x40, + 0x1c, 0xf0, 0x82, 0xc0, 0x40, 0xda, 0x6e, 0x09, 0x6f, 0xed, 0xc1, 0x41, + 0x82, 0xc0, 0x81, 0xc3, 0x82, 0x41, 0xd2, 0x08, 0x6f, 0xf8, 0xa1, 0x42, + 0x30, 0xf0, 0xbe, 0x40, 0x29, 0xf0, 0xb0, 0x15, 0x80, 0x20, 0x81, 0xc3, + 0x82, 0x41, 0xde, 0x0f, 0x2f, 0xf6, 0xa1, 0x42, 0x26, 0xf0, 0x81, 0xc3, + 0x02, 0x40, 0x04, 0xf0, 0x81, 0xc3, 0x22, 0x40, 0x82, 0x41, 0x4a, 0x08, + 0xef, 0xf8, 0xa1, 0x42, 0x1c, 0xf0, 0x28, 0x15, 0x00, 0x20, 0x15, 0xf0, + 0x81, 0xc3, 0x42, 0x40, 0x82, 0x41, 0x02, 0x0f, 0xef, 0xf8, 0xa1, 0x42, + 0x12, 0xf0, 0x81, 0xc3, 0x62, 0x40, 0x82, 0x41, 0x5e, 0x0f, 0xef, 0xf9, + 0xa1, 0x42, 0x0c, 0xf0, 0xcc, 0x15, 0x00, 0x20, 0x03, 0xf0, 0x53, 0x15, + 0x00, 0x26, 0x81, 0xc3, 0x82, 0x41, 0xb2, 0x0a, 0xaf, 0xf0, 0xa1, 0x42, + 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xa9, 0xf1, + 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0x1c, 0x02, 0x20, 0x01, 0x1c, + 0x42, 0x20, 0xd2, 0xc7, 0x89, 0x01, 0x00, 0x04, 0xe8, 0xc3, 0xb4, 0xc1, + 0x10, 0x40, 0xb1, 0x10, 0x80, 0x00, 0x3a, 0xe8, 0x55, 0x20, 0x4d, 0x2a, + 0x2c, 0x8d, 0x2f, 0x09, 0x70, 0x00, 0xb1, 0x18, 0x03, 0x20, 0xc3, 0x40, + 0x13, 0x00, 0xb8, 0x6b, 0x0b, 0x09, 0x90, 0x00, 0x09, 0x09, 0xd0, 0x00, + 0x14, 0xf0, 0x10, 0xe0, 0x56, 0x0e, 0x2f, 0xf8, 0x84, 0xc1, 0x56, 0x20, + 0x00, 0x2b, 0x84, 0xc1, 0xa2, 0x08, 0x6f, 0xed, 0x40, 0xda, 0x40, 0x85, + 0x21, 0x85, 0x02, 0x85, 0xac, 0x1d, 0x80, 0x10, 0xb0, 0x1d, 0x40, 0x10, + 0xb4, 0x1d, 0x00, 0x10, 0x56, 0x20, 0x01, 0x2b, 0x84, 0xc0, 0x40, 0xda, + 0x82, 0x08, 0x6f, 0xed, 0x84, 0xc5, 0x4a, 0x24, 0x00, 0x71, 0x80, 0xc0, + 0xa8, 0x20, 0x80, 0x01, 0x14, 0x15, 0x01, 0x14, 0x04, 0x18, 0x50, 0x00, + 0x55, 0x20, 0x40, 0x2b, 0x80, 0xc1, 0x66, 0x08, 0x6f, 0xed, 0x10, 0xda, + 0xc8, 0xc7, 0xe0, 0x78, 0xe4, 0xc3, 0xa7, 0xc1, 0x08, 0x45, 0x32, 0xe9, + 0xb0, 0xea, 0x4a, 0x24, 0xc0, 0x70, 0x2c, 0x70, 0xa8, 0x20, 0x80, 0x03, + 0x15, 0x25, 0x40, 0x10, 0xa4, 0x10, 0x0c, 0x00, 0x98, 0x10, 0x03, 0x00, + 0x84, 0xc2, 0x35, 0x7a, 0x02, 0x33, 0x00, 0x03, 0x24, 0x71, 0x00, 0xa2, + 0x2a, 0x0a, 0x6f, 0xfb, 0x84, 0xc0, 0xb0, 0x15, 0x81, 0x10, 0x37, 0x09, + 0x94, 0x00, 0x32, 0x21, 0x83, 0x0f, 0x13, 0x00, 0xb3, 0x6b, 0x01, 0x30, + 0x82, 0x0f, 0xfa, 0xc4, 0x00, 0x00, 0x6a, 0x7b, 0x00, 0x30, 0x80, 0x00, + 0x01, 0x30, 0x81, 0x0f, 0x74, 0x49, 0x00, 0x24, 0x48, 0x33, 0x80, 0x00, + 0x04, 0x31, 0x00, 0x80, 0xc5, 0xf6, 0xbe, 0x09, 0x20, 0x04, 0xa1, 0x40, + 0xc4, 0xc7, 0x56, 0x25, 0x00, 0x1b, 0x80, 0xc1, 0x6e, 0x08, 0xa0, 0x04, + 0x80, 0xc6, 0x4a, 0x24, 0x00, 0x71, 0x55, 0x25, 0x41, 0x1b, 0x20, 0x42, + 0xa8, 0x20, 0xc0, 0x02, 0x60, 0x82, 0x04, 0x16, 0x00, 0x14, 0x04, 0x33, + 0x00, 0x80, 0xca, 0x20, 0xc5, 0x00, 0x04, 0x1a, 0x10, 0x00, 0x80, 0xc0, + 0xc2, 0x0f, 0x2f, 0xed, 0x4a, 0x22, 0x00, 0x04, 0x00, 0xc0, 0x4a, 0x24, + 0xc0, 0x70, 0x81, 0xc1, 0xa8, 0x20, 0x00, 0x02, 0x04, 0x11, 0x02, 0x04, + 0x04, 0x32, 0x00, 0x80, 0xca, 0x20, 0x89, 0x00, 0x04, 0x30, 0x80, 0x8f, + 0xc9, 0x36, 0x9c, 0x53, 0x44, 0xf7, 0xb0, 0x1d, 0xc3, 0x10, 0xc4, 0xc7, + 0x04, 0x30, 0x80, 0x8f, 0x38, 0x37, 0xa4, 0x8c, 0x44, 0xf7, 0xb0, 0x1d, + 0x83, 0x10, 0xc4, 0xc7, 0x04, 0x30, 0x80, 0x8f, 0xd3, 0x38, 0xf6, 0xcf, + 0x6f, 0x20, 0x0b, 0x00, 0xb0, 0x1d, 0x02, 0x10, 0xc4, 0xc7, 0xe0, 0x78, + 0xf1, 0xc0, 0x00, 0x43, 0x0c, 0x70, 0x09, 0xe9, 0x87, 0xea, 0x55, 0x23, + 0x40, 0x0c, 0x5e, 0x0f, 0xef, 0xee, 0x55, 0x23, 0x81, 0x09, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xec, 0xc3, 0xac, 0xc1, 0x08, 0x47, 0x2b, 0x80, + 0x0c, 0x80, 0x42, 0x87, 0x43, 0xc1, 0x44, 0xc0, 0x09, 0x6a, 0x2d, 0x87, + 0x7f, 0xdc, 0x48, 0x32, 0x88, 0x00, 0x48, 0x30, 0x8b, 0x00, 0x17, 0xbc, + 0x50, 0x40, 0x2d, 0x0a, 0xb2, 0x00, 0x45, 0xc1, 0x40, 0x27, 0x02, 0x1e, + 0x2c, 0x72, 0x4a, 0x24, 0xc0, 0x70, 0x83, 0xc0, 0xa8, 0x20, 0x40, 0x02, + 0xa0, 0x80, 0x04, 0x12, 0x03, 0x04, 0x01, 0x33, 0x43, 0x03, 0x04, 0x18, + 0xd0, 0x00, 0x12, 0x71, 0x24, 0x71, 0xb3, 0xf6, 0x4a, 0x24, 0xc0, 0x70, + 0x07, 0x34, 0x08, 0x12, 0x07, 0x34, 0xd1, 0x12, 0x4a, 0x21, 0x00, 0x00, + 0xa8, 0x20, 0x40, 0x04, 0x83, 0xc3, 0x35, 0x7b, 0x00, 0x83, 0x15, 0x27, + 0x4c, 0x10, 0x4b, 0x84, 0x00, 0x30, 0x00, 0x10, 0x89, 0xc5, 0x02, 0x32, + 0x02, 0x00, 0x35, 0x7d, 0x24, 0x71, 0x00, 0xa3, 0x40, 0xa5, 0x89, 0xc0, + 0x80, 0xc1, 0xaa, 0x0b, 0x6f, 0xfb, 0x80, 0xc6, 0x5d, 0x08, 0xb2, 0x20, + 0xad, 0x72, 0x4a, 0x24, 0xc0, 0x70, 0x14, 0x25, 0x40, 0x13, 0x4b, 0x68, + 0x4a, 0x20, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x03, 0x83, 0xc1, 0x15, 0x27, + 0x83, 0x10, 0x01, 0x49, 0x8b, 0x83, 0x89, 0xc3, 0x15, 0x7b, 0x02, 0x34, + 0x41, 0x10, 0x04, 0x71, 0x44, 0x71, 0x20, 0xa3, 0x89, 0xc0, 0x86, 0xc1, + 0x6e, 0x0b, 0x6f, 0xfb, 0x40, 0x24, 0x12, 0x36, 0x4a, 0x24, 0xc0, 0x70, + 0x80, 0xc0, 0xa8, 0x20, 0x80, 0x02, 0x40, 0x80, 0x04, 0x12, 0x01, 0x24, + 0x01, 0x31, 0x81, 0x00, 0x04, 0x18, 0x50, 0x00, 0x12, 0x75, 0xb2, 0x07, + 0xeb, 0xff, 0xa5, 0x71, 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0xc0, 0x01, + 0x00, 0x86, 0x00, 0x31, 0x00, 0x20, 0x04, 0x1e, 0x10, 0x10, 0x00, 0xc4, + 0x01, 0xc3, 0x02, 0xc1, 0x00, 0xc0, 0x4c, 0x71, 0x8c, 0x1f, 0x00, 0x13, + 0x90, 0x1f, 0xc0, 0x10, 0x94, 0x1f, 0x40, 0x10, 0x80, 0xc1, 0x41, 0x49, + 0x54, 0x72, 0x4c, 0x72, 0x01, 0x30, 0x40, 0x00, 0xba, 0xf7, 0xcc, 0xc7, + 0xe4, 0xc3, 0xa3, 0xc1, 0x20, 0x42, 0x08, 0x45, 0x80, 0xc1, 0x40, 0x40, + 0x02, 0x0b, 0x6f, 0xfb, 0x80, 0xc6, 0x00, 0xc2, 0x0c, 0x71, 0x2c, 0x71, + 0x23, 0x4e, 0x34, 0x72, 0x2c, 0x72, 0x01, 0x32, 0xc2, 0x00, 0xbc, 0xf7, + 0x25, 0x85, 0x04, 0x32, 0x40, 0x80, 0x47, 0xf7, 0x26, 0x85, 0x04, 0x32, + 0x40, 0x80, 0xc3, 0xf6, 0x0c, 0x70, 0xc4, 0xc7, 0xe6, 0xc3, 0xaa, 0xc1, + 0x84, 0x80, 0x4a, 0x24, 0xc0, 0x70, 0x08, 0x45, 0x28, 0x47, 0x55, 0x20, + 0xce, 0x08, 0x0c, 0x70, 0xa8, 0x20, 0x40, 0x03, 0x04, 0x16, 0x03, 0x14, + 0x40, 0x24, 0x41, 0x39, 0x1a, 0x61, 0x04, 0x33, 0x00, 0x83, 0x04, 0x71, + 0x6f, 0x21, 0x0b, 0x00, 0x20, 0xaa, 0x26, 0x0b, 0xaf, 0xf5, 0x40, 0x24, + 0x40, 0x39, 0x9d, 0x0f, 0x11, 0x10, 0x99, 0x08, 0x30, 0x00, 0x0c, 0x70, + 0x49, 0x85, 0x2a, 0x85, 0x50, 0x71, 0x61, 0x69, 0x40, 0x41, 0xca, 0x21, + 0xcb, 0x00, 0x83, 0x09, 0xa2, 0x00, 0x2a, 0xa5, 0x5c, 0x4d, 0x83, 0xc1, + 0x86, 0x08, 0xaf, 0xf6, 0x83, 0xc7, 0x02, 0x85, 0x4a, 0x24, 0xc0, 0x70, + 0x48, 0x30, 0x81, 0x00, 0xa8, 0x20, 0xc0, 0x01, 0x00, 0x87, 0x07, 0x30, + 0x40, 0x00, 0x04, 0x1f, 0x10, 0x10, 0x4a, 0x24, 0xc0, 0x70, 0x2c, 0x70, + 0xa8, 0x20, 0x80, 0x03, 0x15, 0x25, 0x40, 0x10, 0x83, 0xc2, 0x98, 0x10, + 0x0c, 0x00, 0x23, 0x4a, 0x86, 0xc2, 0x35, 0x7a, 0x02, 0x33, 0x00, 0x03, + 0x24, 0x71, 0x00, 0xa2, 0x86, 0xc0, 0xca, 0x0e, 0x6f, 0xf6, 0x80, 0xc1, + 0x01, 0xc1, 0x00, 0xc0, 0x47, 0x85, 0x02, 0xc3, 0x01, 0x30, 0x40, 0x00, + 0x00, 0x32, 0x81, 0x0f, 0x40, 0x40, 0x00, 0x00, 0x01, 0x30, 0xc0, 0x00, + 0x04, 0x31, 0x00, 0x80, 0x0c, 0x70, 0x49, 0xf7, 0x03, 0xc3, 0x04, 0xc2, + 0x05, 0xc1, 0x0c, 0x71, 0x60, 0xa6, 0x41, 0xa6, 0x22, 0xa6, 0xc6, 0xc7, + 0x0c, 0x70, 0x28, 0x1d, 0x01, 0x10, 0xc6, 0xc7, 0xf6, 0xc3, 0x82, 0x24, + 0x11, 0x31, 0x50, 0x42, 0x10, 0x40, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, + 0x44, 0x01, 0x8a, 0x22, 0x0c, 0x00, 0x12, 0x0d, 0x2f, 0xed, 0x28, 0x45, + 0x06, 0x40, 0x40, 0x24, 0x83, 0x37, 0x40, 0x24, 0x04, 0x39, 0x56, 0x24, + 0x05, 0x3a, 0x40, 0x24, 0x06, 0x38, 0x40, 0x24, 0xc7, 0x37, 0xa1, 0x41, + 0x42, 0x42, 0x1e, 0x09, 0x6f, 0xf4, 0x1e, 0x1c, 0xc3, 0x32, 0x24, 0x14, + 0x11, 0x30, 0x36, 0x70, 0xcb, 0xf4, 0x1f, 0x14, 0x8d, 0x30, 0x56, 0x20, + 0x97, 0x2a, 0x55, 0x20, 0x53, 0x2a, 0x56, 0x20, 0x16, 0x2b, 0x55, 0x20, + 0xce, 0x28, 0x55, 0x20, 0x8f, 0x29, 0x55, 0x20, 0x15, 0x2d, 0x40, 0x20, + 0x14, 0x2b, 0x2e, 0x70, 0x2c, 0x70, 0x34, 0x70, 0xb7, 0xf4, 0x1e, 0x14, + 0x81, 0x30, 0xaf, 0x78, 0x30, 0x70, 0x66, 0x01, 0x2d, 0x00, 0x04, 0x77, + 0x8a, 0xe0, 0x1e, 0x01, 0x0d, 0x00, 0x25, 0x20, 0x00, 0x00, 0x0c, 0xf0, + 0x26, 0xf0, 0x32, 0xf0, 0x3a, 0xf0, 0x44, 0xf0, 0x51, 0xf0, 0x60, 0xf0, + 0x68, 0xf0, 0x76, 0xf0, 0x8d, 0xf0, 0x97, 0xf0, 0x00, 0x24, 0x80, 0x3f, + 0x00, 0x00, 0x44, 0x01, 0x88, 0xc1, 0x76, 0x0b, 0xaf, 0xf8, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0xc3, 0x43, 0x7a, 0x44, 0x00, 0x00, + 0x46, 0xc3, 0x00, 0x1b, 0x80, 0x20, 0x04, 0x1b, 0x40, 0x20, 0x08, 0x1b, + 0x00, 0x20, 0x43, 0xc2, 0x44, 0xc1, 0x45, 0xc0, 0x83, 0xc1, 0x10, 0xda, + 0xe2, 0x40, 0x63, 0xf0, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x44, 0x01, + 0x88, 0xc1, 0x9e, 0x0b, 0x2f, 0xf8, 0x8a, 0xc2, 0x8a, 0xc1, 0x40, 0xda, + 0xc2, 0x40, 0x57, 0xf0, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x44, 0x01, + 0xc6, 0x0d, 0x6f, 0xf0, 0x88, 0xc1, 0x0c, 0x18, 0x00, 0x20, 0x4f, 0xf0, + 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x44, 0x01, 0xa2, 0x0a, 0x2f, 0xf6, + 0x88, 0xc1, 0xb0, 0x18, 0x02, 0x20, 0x45, 0xf0, 0x00, 0x24, 0x80, 0x3f, + 0x00, 0x00, 0x44, 0x01, 0x88, 0xc1, 0xfe, 0x0a, 0xaf, 0xf8, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x40, 0xa6, 0x21, 0xa6, 0x02, 0xa6, + 0x35, 0xf0, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x44, 0x01, 0x88, 0xc1, + 0xde, 0x0a, 0xaf, 0xf8, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, + 0x40, 0xa7, 0x21, 0xa7, 0x02, 0xa7, 0x27, 0xf0, 0x00, 0x24, 0x80, 0x3f, + 0x00, 0x00, 0x44, 0x01, 0x62, 0x0d, 0x6f, 0xf0, 0x88, 0xc1, 0x28, 0x18, + 0x00, 0x20, 0x1d, 0xf0, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x44, 0x01, + 0x88, 0xc1, 0x7a, 0x09, 0xef, 0xf8, 0x55, 0x24, 0x02, 0x3e, 0x55, 0x24, + 0x01, 0x3e, 0x60, 0xda, 0x82, 0x40, 0x0d, 0xf0, 0x00, 0x24, 0x80, 0x3f, + 0x00, 0x00, 0x44, 0x01, 0x88, 0xc1, 0xca, 0x09, 0xef, 0xf9, 0x9a, 0xc2, + 0x9a, 0xc1, 0x78, 0xda, 0xa2, 0x40, 0x92, 0x0b, 0x0f, 0xed, 0x08, 0xc0, + 0x8a, 0x21, 0x3e, 0x06, 0x52, 0x70, 0xca, 0x21, 0x4d, 0x20, 0x3c, 0x22, + 0x01, 0x20, 0x3d, 0x22, 0x00, 0x20, 0x1d, 0x65, 0x5d, 0xf1, 0x00, 0x24, + 0x80, 0x3f, 0x00, 0x00, 0x44, 0x01, 0x02, 0x0d, 0x6f, 0xf0, 0x88, 0xc1, + 0xcc, 0x18, 0x00, 0x20, 0xeb, 0xf1, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, + 0x44, 0x01, 0xee, 0x0c, 0x6f, 0xf0, 0x88, 0xc1, 0x53, 0x18, 0x18, 0x20, + 0xe1, 0xf1, 0x22, 0x40, 0xd6, 0xc7, 0xe0, 0x78, 0x48, 0x31, 0x01, 0x00, + 0xcb, 0x44, 0x83, 0x3a, 0x6f, 0x12, 0x07, 0x36, 0x48, 0x70, 0x48, 0x47, + 0x00, 0x00, 0x21, 0x80, 0x6d, 0x70, 0x48, 0x31, 0x81, 0x00, 0x00, 0x30, + 0x41, 0x10, 0x00, 0x31, 0x01, 0x03, 0x04, 0x31, 0xc0, 0x82, 0xc7, 0xf6, + 0x01, 0x31, 0x81, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x31, + 0x81, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x50, 0x90, 0x48, 0x31, 0xc1, 0x02, + 0x48, 0x31, 0x83, 0x00, 0x48, 0x32, 0x01, 0x00, 0x00, 0x30, 0x41, 0x10, + 0x48, 0x33, 0xc2, 0x02, 0x00, 0x31, 0x01, 0x03, 0x49, 0x22, 0x02, 0x02, + 0x48, 0x22, 0x02, 0x01, 0x04, 0x31, 0xc0, 0x82, 0x42, 0xa0, 0xc7, 0xf6, + 0x01, 0x31, 0x81, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x31, + 0x81, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x31, 0xc1, 0x02, 0x48, 0x31, + 0x81, 0x00, 0x48, 0x31, 0xc1, 0x02, 0x49, 0x21, 0x41, 0x06, 0x48, 0x21, + 0x01, 0x01, 0xe0, 0x7f, 0x29, 0xa0, 0xe0, 0x78, 0xf4, 0xc3, 0x82, 0x24, + 0x02, 0x3a, 0x50, 0x46, 0x08, 0x45, 0x55, 0x20, 0x0e, 0x08, 0x55, 0x24, + 0x80, 0x39, 0x10, 0xda, 0x0a, 0x23, 0x80, 0x21, 0x0a, 0x25, 0x40, 0x21, + 0x0a, 0x22, 0x00, 0x21, 0x70, 0x41, 0x30, 0x40, 0x92, 0x0a, 0x2f, 0xed, + 0x55, 0x24, 0x8f, 0x39, 0x4a, 0x24, 0xc0, 0x70, 0x0a, 0x21, 0x80, 0x0f, + 0xfa, 0x44, 0x00, 0x00, 0x4f, 0x21, 0xc3, 0x07, 0xa8, 0x20, 0x00, 0x04, + 0x04, 0x10, 0x0c, 0x24, 0x20, 0x40, 0x60, 0x42, 0x04, 0x34, 0x40, 0x90, + 0xca, 0x20, 0x05, 0x03, 0x04, 0x30, 0xc0, 0x80, 0xca, 0x22, 0x09, 0x00, + 0x04, 0x1f, 0x90, 0x10, 0x2c, 0x70, 0x47, 0xc0, 0x94, 0xc0, 0x18, 0xda, + 0x28, 0x47, 0x00, 0x1b, 0x42, 0x20, 0x00, 0x1a, 0x40, 0x20, 0x8e, 0x08, + 0x2f, 0xfb, 0x00, 0x1d, 0x40, 0x20, 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x24, + 0x81, 0x39, 0x8e, 0xc0, 0x51, 0xc7, 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x11, + 0x02, 0x04, 0x00, 0x32, 0x94, 0x0f, 0x20, 0x3c, 0x12, 0xac, 0x04, 0x18, + 0x10, 0x05, 0x10, 0x86, 0x3c, 0x16, 0x81, 0x10, 0x38, 0x14, 0x10, 0x30, + 0x04, 0x71, 0x05, 0x21, 0x41, 0x04, 0x0f, 0xc7, 0x10, 0xa6, 0x79, 0x21, + 0x00, 0x00, 0x3c, 0x1e, 0x02, 0x10, 0x6a, 0x0d, 0xaf, 0xee, 0x8e, 0xc0, + 0x4a, 0x24, 0xc0, 0x70, 0x00, 0x34, 0x08, 0x25, 0x00, 0x37, 0xcc, 0x13, + 0x00, 0x30, 0x03, 0x24, 0x40, 0x24, 0x0b, 0x3e, 0x8e, 0xc1, 0x47, 0xc0, + 0xa8, 0x20, 0xc0, 0x01, 0x40, 0x81, 0x00, 0x30, 0x82, 0x00, 0x04, 0x19, + 0x90, 0x00, 0x01, 0x33, 0x00, 0x03, 0x8e, 0x86, 0x01, 0x30, 0x00, 0x02, + 0x46, 0x85, 0x2f, 0x31, 0x00, 0x20, 0x07, 0x85, 0x28, 0x85, 0x4a, 0x24, + 0xc0, 0x70, 0x02, 0x36, 0x03, 0x73, 0x80, 0x3f, 0x00, 0x00, 0x42, 0xc0, + 0x0d, 0x70, 0x4a, 0x20, 0x00, 0x00, 0x41, 0xc2, 0x43, 0xc1, 0x47, 0xc3, + 0xa8, 0x20, 0x00, 0x04, 0x81, 0xc7, 0x01, 0x4f, 0xf0, 0x23, 0x02, 0x10, + 0x00, 0x33, 0x49, 0x00, 0x00, 0x34, 0x81, 0x10, 0x15, 0x25, 0x02, 0x10, + 0x01, 0x31, 0x41, 0x02, 0x04, 0x71, 0x26, 0xa2, 0x46, 0x85, 0x27, 0x85, + 0x08, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x1c, 0x1c, 0x00, 0x32, 0x41, 0xc2, + 0x42, 0xc1, 0x43, 0xc0, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x17, 0x01, 0x14, + 0x04, 0x13, 0x00, 0x14, 0x00, 0x30, 0x40, 0x00, 0x01, 0x30, 0x08, 0x10, + 0x27, 0x85, 0x08, 0x85, 0x46, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x0e, 0x70, + 0x42, 0xc1, 0x43, 0xc0, 0x45, 0xc1, 0x46, 0xc0, 0x84, 0xc4, 0x8e, 0xc7, + 0x8e, 0xc1, 0x84, 0xc0, 0x0a, 0x23, 0x00, 0x14, 0x1c, 0x1c, 0x00, 0x32, + 0x41, 0xc2, 0x44, 0xc2, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x10, 0x03, 0x04, + 0x04, 0x11, 0x02, 0x04, 0x00, 0x32, 0xc2, 0x00, 0x01, 0x33, 0x8b, 0x10, + 0x08, 0x85, 0x46, 0x85, 0x27, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x46, 0xc0, + 0x4a, 0x20, 0x00, 0x00, 0x28, 0x1c, 0x00, 0x34, 0x44, 0xc2, 0x45, 0xc1, + 0xa8, 0x20, 0xc0, 0x04, 0x81, 0xc1, 0x03, 0x4c, 0x02, 0x49, 0x01, 0x4f, + 0x00, 0x33, 0xc3, 0x10, 0x04, 0x71, 0x00, 0x30, 0x82, 0x10, 0x02, 0x31, + 0xc3, 0x00, 0x02, 0x31, 0x81, 0x00, 0x00, 0x31, 0xc1, 0x00, 0x01, 0x30, + 0x50, 0x20, 0x5f, 0x85, 0x20, 0x86, 0x01, 0x86, 0x9e, 0x85, 0x61, 0x85, + 0x49, 0xc2, 0x4c, 0xc1, 0x4d, 0xc0, 0x88, 0xc0, 0x8c, 0xc1, 0x40, 0x24, + 0x04, 0x3b, 0x40, 0x24, 0x05, 0x3a, 0x22, 0x42, 0x48, 0xc4, 0x3e, 0x0e, + 0x6f, 0xf8, 0x28, 0x1c, 0x00, 0x34, 0x28, 0x14, 0x0b, 0x30, 0x64, 0x86, + 0x45, 0x86, 0x26, 0x86, 0x07, 0x86, 0xe2, 0x86, 0x83, 0x86, 0x04, 0x1d, + 0xc0, 0x12, 0x43, 0xc3, 0x44, 0xc2, 0x45, 0xc1, 0x46, 0xc0, 0x40, 0x25, + 0x03, 0x12, 0x81, 0xc0, 0x84, 0xc1, 0x54, 0x24, 0x84, 0x39, 0x40, 0x24, + 0x05, 0x38, 0x22, 0x42, 0x41, 0xc7, 0x56, 0x0a, 0x6f, 0xf6, 0x42, 0xc4, + 0x20, 0x14, 0x08, 0x30, 0x24, 0x14, 0x0b, 0x30, 0x6a, 0x86, 0x4b, 0x86, + 0x2c, 0x86, 0x0d, 0x86, 0xe8, 0x86, 0x89, 0x86, 0x08, 0x1d, 0x00, 0x12, + 0x0c, 0x1d, 0xc0, 0x12, 0x43, 0xc3, 0x44, 0xc2, 0x45, 0xc1, 0x46, 0xc0, + 0x40, 0x25, 0x03, 0x14, 0x81, 0xc0, 0x84, 0xc1, 0x54, 0x24, 0x04, 0x39, + 0x40, 0x24, 0x05, 0x38, 0x22, 0x42, 0x41, 0xc7, 0x16, 0x0a, 0x6f, 0xf6, + 0x42, 0xc4, 0x2f, 0x30, 0x00, 0x14, 0x08, 0xc2, 0x0b, 0x85, 0x09, 0xc1, + 0x8d, 0x70, 0x4a, 0x24, 0xc0, 0x70, 0x04, 0x30, 0x00, 0xa3, 0x01, 0x1c, + 0x43, 0x30, 0x44, 0xa5, 0x7d, 0x20, 0xc3, 0x00, 0x7d, 0x20, 0x82, 0x00, + 0x68, 0x4d, 0x25, 0xa5, 0x03, 0x1c, 0xc2, 0x30, 0xca, 0x20, 0x05, 0x14, + 0x02, 0x1c, 0x82, 0x30, 0xa8, 0x20, 0x40, 0x04, 0x40, 0x24, 0x49, 0x30, + 0x33, 0x21, 0x01, 0x13, 0x85, 0x71, 0x48, 0x31, 0x8b, 0x00, 0x00, 0x10, + 0x01, 0x00, 0x00, 0x30, 0xcb, 0x12, 0x01, 0x31, 0xc1, 0x02, 0x18, 0x18, + 0x50, 0x00, 0x13, 0xc0, 0x4a, 0x24, 0xc0, 0x70, 0x03, 0x1c, 0xc2, 0x30, + 0x00, 0x30, 0x0b, 0x00, 0x54, 0x25, 0x00, 0x18, 0x02, 0x1c, 0x82, 0x30, + 0x01, 0x1c, 0x43, 0x30, 0xa8, 0x20, 0x40, 0x03, 0x01, 0x11, 0xc1, 0x14, + 0x48, 0x31, 0x8c, 0x00, 0x20, 0x80, 0x00, 0x33, 0x0c, 0x13, 0x01, 0x31, + 0x01, 0x03, 0x18, 0x18, 0x50, 0x00, 0x12, 0xc0, 0x4a, 0x24, 0xc0, 0x70, + 0x8d, 0x70, 0x00, 0x30, 0x08, 0x00, 0x7c, 0x4d, 0x03, 0x1c, 0xc2, 0x30, + 0x02, 0x1c, 0x82, 0x30, 0x01, 0x1c, 0x43, 0x30, 0xa8, 0x20, 0x00, 0x04, + 0x40, 0x24, 0x49, 0x30, 0x33, 0x21, 0x01, 0x13, 0x85, 0x71, 0x48, 0x31, + 0x8b, 0x00, 0x20, 0x80, 0x00, 0x30, 0xcb, 0x12, 0x01, 0x31, 0xc1, 0x02, + 0x18, 0x18, 0x50, 0x00, 0x0b, 0xc4, 0x4a, 0x24, 0xc0, 0x70, 0x78, 0x4d, + 0x00, 0x34, 0x08, 0x13, 0x03, 0x1c, 0xc2, 0x30, 0x02, 0x1c, 0x82, 0x30, + 0x01, 0x1c, 0x43, 0x30, 0xa8, 0x20, 0x40, 0x03, 0x01, 0x11, 0xc1, 0x14, + 0x48, 0x31, 0x8b, 0x00, 0x20, 0x80, 0x00, 0x30, 0xcb, 0x12, 0x01, 0x31, + 0xc1, 0x02, 0x18, 0x18, 0x50, 0x00, 0x0a, 0x85, 0x30, 0x86, 0x02, 0x1c, + 0x82, 0x30, 0x02, 0x31, 0x02, 0x20, 0x4a, 0x24, 0xc0, 0x70, 0x7d, 0x21, + 0x80, 0x00, 0x00, 0x32, 0x8b, 0x00, 0x01, 0x1c, 0x02, 0x30, 0x54, 0x25, + 0x80, 0x18, 0x4c, 0x70, 0x03, 0x1c, 0xc2, 0x30, 0xa8, 0x20, 0x00, 0x04, + 0x40, 0x24, 0x41, 0x30, 0x33, 0x21, 0x81, 0x00, 0x44, 0x71, 0x48, 0x31, + 0x83, 0x00, 0x20, 0x80, 0x00, 0x33, 0xc3, 0x10, 0x01, 0x31, 0xc1, 0x00, + 0x18, 0x18, 0x50, 0x00, 0x8a, 0xc0, 0xd2, 0x09, 0x6f, 0xf6, 0x4a, 0xc4, + 0x09, 0x85, 0x47, 0xc0, 0xc6, 0x09, 0x6f, 0xf6, 0x87, 0xc0, 0x07, 0xc1, + 0x0a, 0xc0, 0x2c, 0x15, 0x10, 0x10, 0xf0, 0x86, 0x02, 0x30, 0x40, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x7d, 0x20, 0xc3, 0x20, 0x7d, 0x20, 0x82, 0x20, + 0x7d, 0x27, 0x8c, 0x10, 0x03, 0x1c, 0xc2, 0x30, 0x02, 0x1c, 0x82, 0x30, + 0x50, 0x20, 0xc2, 0x07, 0x6c, 0x4d, 0x6c, 0x70, 0x01, 0x1c, 0x02, 0x33, + 0xa8, 0x20, 0x00, 0x04, 0x40, 0x24, 0x41, 0x30, 0x33, 0x21, 0xc1, 0x00, + 0x64, 0x71, 0x48, 0x31, 0x8c, 0x00, 0x20, 0x80, 0x00, 0x32, 0x0c, 0x03, + 0x01, 0x31, 0x01, 0x03, 0x18, 0x18, 0x50, 0x00, 0x48, 0x37, 0x00, 0x10, + 0xc3, 0x41, 0x48, 0x42, 0x00, 0x00, 0xda, 0x0c, 0x6f, 0xf8, 0x47, 0xc0, + 0x50, 0x20, 0xfe, 0x87, 0x57, 0xf4, 0x40, 0x20, 0x40, 0x20, 0xa7, 0x08, + 0x34, 0x01, 0x0b, 0xa5, 0x16, 0x09, 0x4f, 0xf6, 0x19, 0x08, 0xf5, 0x00, + 0xed, 0x70, 0x03, 0xb8, 0x04, 0x20, 0x80, 0x0f, 0xff, 0x00, 0xf8, 0xff, + 0x01, 0x2e, 0x0f, 0x70, 0x0c, 0x00, 0x12, 0x06, 0x18, 0xda, 0x40, 0x40, + 0xf5, 0x78, 0x0f, 0x79, 0xb9, 0x61, 0x55, 0x24, 0x00, 0x38, 0x66, 0x0e, + 0xef, 0xec, 0x55, 0x24, 0x10, 0x38, 0x4a, 0x24, 0x80, 0x71, 0x2f, 0x27, + 0xc7, 0x13, 0x9a, 0xc0, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x10, 0x01, 0x24, + 0x00, 0x31, 0x81, 0x0f, 0xda, 0x3b, 0x0e, 0x74, 0x04, 0x18, 0x50, 0x00, + 0x9a, 0xc0, 0x94, 0xc1, 0xee, 0x09, 0xef, 0xed, 0x54, 0x24, 0x10, 0x3a, + 0x3c, 0x16, 0x80, 0x10, 0x10, 0xe8, 0x4a, 0x24, 0x80, 0x71, 0x0c, 0x70, + 0xa8, 0x20, 0xc0, 0x02, 0x33, 0x20, 0x81, 0x0f, 0x13, 0x00, 0xd8, 0x6b, + 0x04, 0x71, 0x48, 0x31, 0x81, 0x00, 0x04, 0x18, 0x50, 0x20, 0x04, 0xf0, + 0x64, 0x1c, 0x01, 0x30, 0x94, 0xc1, 0x91, 0xc3, 0x42, 0x42, 0x22, 0x0a, + 0x6f, 0xee, 0xa1, 0x40, 0x15, 0x25, 0xc0, 0x13, 0x18, 0xe0, 0x2c, 0x70, + 0x3a, 0x0c, 0xef, 0xfa, 0x18, 0xda, 0xbc, 0x1d, 0x03, 0x10, 0x0b, 0xc0, + 0x28, 0x1d, 0x40, 0x14, 0x09, 0xa5, 0xd2, 0x09, 0x6f, 0xf7, 0x46, 0x40, + 0x27, 0xe8, 0x80, 0xd8, 0x00, 0x1b, 0x02, 0x20, 0x11, 0xc0, 0xf0, 0x16, + 0x02, 0x10, 0x2c, 0x70, 0x48, 0x30, 0x80, 0x00, 0x47, 0xc2, 0x00, 0x30, + 0x80, 0x0f, 0x74, 0x49, 0x00, 0x24, 0x07, 0x30, 0x80, 0x00, 0x04, 0x30, + 0x40, 0x80, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x48, 0x30, 0x80, 0x00, 0x48, 0x30, 0xc0, 0x02, 0xc2, 0x70, + 0x00, 0x1d, 0x00, 0x20, 0xd4, 0xc7, 0x00, 0x13, 0xc0, 0x20, 0xb9, 0x08, + 0x12, 0x80, 0xd4, 0xc7, 0xe2, 0xc0, 0x47, 0xdd, 0x4a, 0x24, 0xc0, 0x70, + 0x18, 0xbd, 0xcb, 0x44, 0xa3, 0x42, 0x0b, 0xd7, 0xc3, 0x43, 0xd3, 0x3e, + 0x98, 0xdd, 0xc3, 0x42, 0x3b, 0x4a, 0xc1, 0xbf, 0xc3, 0x41, 0xdc, 0x44, + 0x30, 0x4e, 0x35, 0x18, 0x03, 0x02, 0xac, 0xa0, 0x8b, 0xa0, 0x6a, 0xa0, + 0x47, 0xa0, 0x26, 0xa0, 0x0a, 0x21, 0x00, 0x00, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x19, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x19, 0x11, 0x00, 0x34, 0x18, 0x03, 0x00, 0x20, 0x18, 0x03, 0x00, + 0xc2, 0xc4, 0xe0, 0x78, 0xea, 0xc3, 0xa7, 0xc1, 0x4a, 0x24, 0xc0, 0x70, + 0x68, 0x40, 0x48, 0x46, 0x28, 0x43, 0x08, 0x45, 0x0c, 0x70, 0x84, 0xc4, + 0xa8, 0x20, 0xc0, 0x02, 0x02, 0x4d, 0xf0, 0x23, 0x01, 0x10, 0x15, 0x24, + 0x03, 0x10, 0x04, 0x71, 0x02, 0x31, 0x81, 0x00, 0x20, 0xa3, 0x49, 0x85, + 0x4a, 0x24, 0xc0, 0x70, 0x81, 0xc3, 0x81, 0xc0, 0xa8, 0x20, 0x00, 0x02, + 0x04, 0x14, 0x01, 0x14, 0x00, 0x32, 0x41, 0x00, 0x04, 0x18, 0x50, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x0a, 0x20, 0x40, 0x03, 0xa8, 0x20, 0x40, 0x02, + 0x40, 0x80, 0x04, 0x13, 0x01, 0x04, 0x01, 0x31, 0x81, 0x00, 0x04, 0x18, + 0x50, 0x00, 0x09, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x2d, 0x70, 0x02, 0x36, + 0x06, 0x70, 0x80, 0x3f, 0x00, 0x00, 0x0c, 0x70, 0xa8, 0x20, 0x40, 0x04, + 0x84, 0xc1, 0x81, 0xc3, 0x15, 0x23, 0x02, 0x00, 0x07, 0x49, 0x15, 0x25, + 0x01, 0x10, 0x80, 0x82, 0x23, 0x81, 0x04, 0x71, 0x00, 0x34, 0xcc, 0x13, + 0x01, 0x31, 0x01, 0x03, 0x20, 0xa2, 0x4a, 0x24, 0xc0, 0x70, 0x0c, 0x70, + 0xa8, 0x20, 0x80, 0x02, 0x01, 0x4b, 0x15, 0x25, 0x02, 0x10, 0x04, 0x71, + 0x00, 0x36, 0x41, 0x00, 0x0c, 0x1a, 0x40, 0x00, 0x4a, 0x24, 0xc0, 0x70, + 0xa8, 0x20, 0x40, 0x02, 0x15, 0x25, 0x40, 0x12, 0x03, 0x80, 0x15, 0x20, + 0x41, 0x12, 0x25, 0x71, 0x00, 0xa1, 0x84, 0xc1, 0x61, 0x40, 0xd2, 0x0d, + 0x2f, 0xf6, 0x84, 0xc7, 0x8c, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x0c, 0x70, + 0xa8, 0x20, 0x80, 0x03, 0x04, 0x17, 0x03, 0x14, 0x2c, 0x70, 0x40, 0x24, + 0x42, 0x30, 0x04, 0x33, 0x00, 0x83, 0x1a, 0x62, 0x04, 0x71, 0xca, 0x21, + 0x69, 0x00, 0x20, 0xaa, 0x1a, 0x0b, 0x6f, 0xf5, 0x40, 0x24, 0x40, 0x30, + 0x67, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x10, 0x40, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0xc0, 0x03, 0x15, 0x25, 0x02, 0x10, 0xe3, 0x82, 0x2c, 0x70, + 0x40, 0x24, 0x4c, 0x30, 0x04, 0x37, 0xc0, 0x90, 0x1a, 0x64, 0x04, 0x71, + 0xca, 0x21, 0x6a, 0x00, 0x20, 0xaa, 0xea, 0x0a, 0x6f, 0xf5, 0x40, 0x24, + 0x40, 0x30, 0x66, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x08, 0x47, 0x0c, 0x70, + 0xa8, 0x20, 0x00, 0x04, 0x15, 0x25, 0x02, 0x10, 0x0c, 0x12, 0x0b, 0x00, + 0x2c, 0x70, 0x40, 0x24, 0x4c, 0x30, 0x04, 0x33, 0xc0, 0x90, 0x1a, 0x64, + 0x04, 0x71, 0xca, 0x21, 0x69, 0x00, 0x20, 0xaa, 0xb6, 0x0a, 0x6f, 0xf5, + 0x40, 0x24, 0x40, 0x30, 0x04, 0xe8, 0x34, 0x1d, 0x03, 0x10, 0x0f, 0xf0, + 0x34, 0x15, 0x80, 0x10, 0x35, 0x15, 0x81, 0x10, 0x04, 0x71, 0x0f, 0x7a, + 0x0b, 0x09, 0x85, 0x00, 0x34, 0x1d, 0x42, 0x10, 0x03, 0xf0, 0x34, 0x1d, + 0x02, 0x10, 0x84, 0xc1, 0xa1, 0x40, 0x79, 0x27, 0x0f, 0x10, 0x12, 0x0d, + 0x2f, 0xf6, 0x40, 0x24, 0x11, 0x34, 0x8b, 0x85, 0x4a, 0x24, 0xc0, 0x70, + 0x4a, 0x20, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x03, 0x04, 0x11, 0x03, 0x24, + 0x2c, 0x70, 0x40, 0x24, 0x42, 0x30, 0x04, 0x33, 0x00, 0x83, 0x1a, 0x62, + 0x04, 0x71, 0xca, 0x21, 0x69, 0x00, 0x20, 0xaa, 0x56, 0x0a, 0x6f, 0xf5, + 0x40, 0x24, 0x40, 0x30, 0x05, 0x20, 0x3e, 0x84, 0x07, 0xf4, 0x35, 0x15, + 0x81, 0x10, 0x34, 0x15, 0x80, 0x10, 0x09, 0x08, 0x45, 0x00, 0x82, 0xbf, + 0x50, 0x27, 0x40, 0x10, 0x16, 0x70, 0xcf, 0x20, 0x62, 0x00, 0x00, 0xae, + 0x20, 0x15, 0x81, 0x10, 0x0f, 0x09, 0x00, 0x00, 0x20, 0x1d, 0x02, 0x10, + 0x00, 0x8e, 0x87, 0xb8, 0x00, 0xae, 0xca, 0xc7, 0x4a, 0x24, 0xc0, 0x70, + 0x0a, 0x21, 0x00, 0x00, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x19, 0x11, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x19, 0x11, 0x00, + 0x34, 0x18, 0x03, 0x00, 0xe0, 0x7f, 0x20, 0x18, 0x03, 0x00, 0xe0, 0x78, + 0xc3, 0x40, 0xa0, 0x00, 0xe0, 0x86, 0x00, 0x80, 0x2c, 0x70, 0x4c, 0x70, + 0x05, 0x07, 0xef, 0xfc, 0x6c, 0x70, 0xe0, 0x78, 0xe2, 0xc2, 0xcb, 0x45, + 0xa0, 0x00, 0xbc, 0x86, 0x21, 0x85, 0xc3, 0x40, 0xa0, 0x00, 0x7c, 0x6e, + 0x00, 0x80, 0x24, 0x77, 0x1a, 0x0c, 0x2f, 0xfd, 0x21, 0xa5, 0x00, 0x1d, + 0x03, 0x10, 0xc2, 0xc6, 0xe4, 0xc2, 0xcb, 0x45, 0xa0, 0x00, 0xf4, 0xc7, + 0x08, 0x46, 0x58, 0x25, 0xc3, 0x19, 0x0c, 0xd8, 0x1c, 0xd9, 0x8c, 0x70, + 0x4a, 0x0d, 0xef, 0xfc, 0xa1, 0x42, 0xc3, 0x41, 0xa0, 0x00, 0xc4, 0x86, + 0x00, 0xa1, 0x56, 0x25, 0x85, 0x1a, 0x57, 0x25, 0x86, 0x1a, 0xc3, 0x40, + 0x12, 0x00, 0x3c, 0x97, 0xc3, 0x41, 0x13, 0x00, 0x28, 0x90, 0x8a, 0x22, + 0x18, 0x00, 0x8a, 0x24, 0x42, 0x00, 0x5e, 0x0a, 0xaf, 0xfe, 0xc1, 0x43, + 0xc3, 0x41, 0xa0, 0x00, 0x7c, 0x6e, 0x00, 0xa1, 0xc4, 0xc6, 0xe0, 0x78, + 0xe4, 0xc3, 0xa1, 0xc1, 0x2c, 0x77, 0x80, 0xc2, 0x0c, 0x70, 0xda, 0x0b, + 0x2f, 0xfd, 0x20, 0x43, 0x14, 0xe8, 0xcb, 0x45, 0xa0, 0x00, 0xe0, 0x86, + 0x00, 0x85, 0x2c, 0x70, 0x4c, 0x77, 0x16, 0x0d, 0xef, 0xfc, 0x6c, 0x70, + 0x7a, 0xe8, 0xc3, 0x41, 0xa0, 0x00, 0xbc, 0x86, 0x00, 0x89, 0x08, 0xe8, + 0x00, 0xc6, 0x00, 0x19, 0x03, 0x00, 0x0b, 0xf0, 0xcd, 0x70, 0x09, 0xf0, + 0x00, 0x85, 0x2c, 0x70, 0x4c, 0x70, 0x6c, 0x70, 0x4a, 0x0e, 0xef, 0xfc, + 0xcd, 0x70, 0xc1, 0x40, 0xc4, 0xc7, 0xe0, 0x78, 0x50, 0x21, 0xcc, 0x07, + 0x02, 0x21, 0x03, 0x83, 0x15, 0x0c, 0x23, 0x10, 0x43, 0x22, 0x01, 0x80, + 0x00, 0x23, 0x83, 0x8f, 0x00, 0x80, 0x00, 0x00, 0x81, 0x21, 0xff, 0x8f, + 0xe0, 0x7f, 0x65, 0x78, 0xe2, 0xc3, 0xa1, 0xc1, 0x8e, 0x0f, 0xcf, 0xff, + 0x7e, 0xe8, 0xb4, 0xd9, 0xc3, 0x40, 0xf0, 0x00, 0x4b, 0x00, 0xc3, 0x42, + 0xa0, 0x00, 0xd4, 0xc1, 0x20, 0xa8, 0x00, 0x8a, 0x05, 0xe8, 0x01, 0x82, + 0x04, 0x71, 0x01, 0xa2, 0xf0, 0xf1, 0xc3, 0x40, 0xa0, 0x00, 0x8c, 0x86, + 0x2c, 0x72, 0x4c, 0x70, 0x6c, 0x70, 0xdb, 0x59, 0xda, 0x0e, 0xef, 0xff, + 0x08, 0x45, 0x00, 0x16, 0x80, 0x70, 0xa0, 0x00, 0xb8, 0x86, 0xc5, 0x08, + 0x9e, 0x80, 0x03, 0x1c, 0x03, 0x30, 0x02, 0x1c, 0x42, 0x33, 0x01, 0x1c, + 0x03, 0x32, 0x3b, 0x58, 0x00, 0x42, 0x20, 0x43, 0x40, 0x24, 0x41, 0x30, + 0xfe, 0xd8, 0xe2, 0x0a, 0x6f, 0xfb, 0x8c, 0x70, 0xd0, 0xf1, 0xe0, 0x78, + 0xf1, 0xc0, 0xa1, 0xc1, 0x09, 0xe8, 0x22, 0x81, 0x20, 0x81, 0x60, 0xc1, + 0x3a, 0x09, 0x6f, 0xfb, 0x80, 0xc1, 0x0c, 0x70, 0x02, 0xf0, 0x23, 0xd8, + 0x87, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0xa1, 0xc1, + 0x08, 0xe8, 0x3a, 0x80, 0x60, 0xc1, 0x1e, 0x09, 0x6f, 0xfb, 0x80, 0xc1, + 0x0c, 0x70, 0x03, 0xf0, 0x23, 0xd8, 0x87, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, + 0xf1, 0xc0, 0x6e, 0x08, 0x00, 0x00, 0xd1, 0xc0, 0xe0, 0x7f, 0x0c, 0x70, + 0xe2, 0xc0, 0x4a, 0x24, 0x00, 0x77, 0x8d, 0x70, 0xcb, 0x45, 0xa0, 0x00, + 0x08, 0xc2, 0x89, 0x43, 0x0a, 0x23, 0x80, 0x0f, 0xa0, 0x00, 0xa0, 0xc4, + 0xa8, 0x20, 0x00, 0x04, 0x5a, 0x23, 0x01, 0x16, 0xc3, 0x42, 0x06, 0x01, + 0xff, 0x00, 0x65, 0x71, 0x38, 0x65, 0x42, 0xa0, 0x04, 0x18, 0xc1, 0x02, + 0x38, 0x4b, 0x1a, 0x61, 0xb8, 0x61, 0x40, 0xa0, 0x4a, 0x24, 0x80, 0x71, + 0xc3, 0x40, 0xa0, 0x00, 0xa8, 0x86, 0x82, 0xb0, 0x80, 0xa0, 0x60, 0x40, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0x0c, 0x1b, 0xc1, 0x00, + 0x14, 0x1b, 0x41, 0x00, 0x0c, 0x70, 0x04, 0x1b, 0x81, 0x00, 0xc2, 0xc4, + 0xc3, 0x43, 0xa0, 0x00, 0xd4, 0xc1, 0x00, 0x8b, 0x08, 0xe8, 0x02, 0x83, + 0x24, 0x83, 0x41, 0x68, 0x01, 0x69, 0x42, 0xa3, 0xe0, 0x7f, 0x04, 0xa3, + 0x24, 0x83, 0x08, 0xe9, 0x03, 0x83, 0x09, 0x08, 0x45, 0x00, 0x23, 0xa3, + 0x10, 0x1b, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0xfa, 0xc3, 0x82, 0x24, + 0x02, 0x39, 0xcb, 0x46, 0xa0, 0x00, 0x88, 0x86, 0x2a, 0x86, 0x02, 0x86, + 0x6b, 0x86, 0x43, 0x86, 0xed, 0x70, 0x00, 0x21, 0x01, 0x80, 0xf1, 0x44, + 0xf1, 0x40, 0xf1, 0x45, 0x01, 0x22, 0xc0, 0x80, 0xd3, 0x46, 0xa0, 0x00, + 0x68, 0xc1, 0x4c, 0xc7, 0x4b, 0xc7, 0x4a, 0xc7, 0x22, 0xa6, 0x03, 0xa6, + 0x5a, 0x24, 0x03, 0x27, 0x00, 0x26, 0xcd, 0x20, 0x05, 0x85, 0x14, 0x70, + 0x10, 0x42, 0x61, 0xf2, 0x03, 0x85, 0x22, 0x86, 0x84, 0x85, 0x43, 0x86, + 0x08, 0x15, 0x0b, 0x10, 0x04, 0x15, 0x08, 0x10, 0x02, 0x21, 0x09, 0x80, + 0x03, 0x22, 0x00, 0x83, 0x3c, 0x21, 0x08, 0x12, 0x3c, 0x20, 0xcc, 0x02, + 0x71, 0x70, 0xca, 0x24, 0x01, 0x12, 0x95, 0x70, 0x4b, 0xf4, 0x98, 0x8d, + 0x32, 0x23, 0x93, 0x05, 0x40, 0x26, 0x00, 0x23, 0x78, 0x60, 0x23, 0xa5, + 0x41, 0xa0, 0x88, 0xec, 0x1e, 0x0b, 0x60, 0x06, 0x42, 0x40, 0x14, 0x70, + 0x18, 0xad, 0x3d, 0xf2, 0x10, 0x8e, 0x09, 0xe8, 0x07, 0x86, 0x0f, 0x08, + 0xc1, 0x04, 0xbe, 0x0a, 0x00, 0x00, 0x10, 0x1e, 0x03, 0x10, 0x50, 0x12, + 0x01, 0x20, 0x42, 0x40, 0x60, 0x79, 0x1c, 0x1c, 0xc2, 0x34, 0x80, 0x12, + 0x11, 0x20, 0x78, 0x12, 0x01, 0x20, 0xef, 0x7a, 0x8a, 0xc3, 0x55, 0x7b, + 0x48, 0xc0, 0x00, 0x1b, 0x40, 0x04, 0x18, 0x1c, 0x40, 0x34, 0x2f, 0x27, + 0x3f, 0x03, 0x6f, 0x23, 0x3f, 0x00, 0x00, 0x81, 0x61, 0x81, 0x22, 0x81, + 0x2f, 0x26, 0x3f, 0x03, 0x44, 0xc1, 0x5f, 0x22, 0x01, 0x06, 0x5f, 0x22, + 0x02, 0x03, 0x43, 0xc3, 0x42, 0xc0, 0x97, 0xc0, 0x8e, 0xc3, 0x19, 0x61, + 0x7a, 0x62, 0x26, 0x0d, 0x6f, 0xee, 0x82, 0xc0, 0x0b, 0x0d, 0x10, 0x20, + 0x00, 0x86, 0x0d, 0x0b, 0x01, 0x20, 0x50, 0x21, 0xd0, 0x27, 0xae, 0x71, + 0xe5, 0x71, 0x86, 0x71, 0x96, 0x73, 0x30, 0x07, 0xc5, 0xff, 0x05, 0x86, + 0x13, 0x08, 0x22, 0x04, 0x02, 0x20, 0x00, 0x04, 0xd3, 0x70, 0x00, 0x00, + 0x00, 0x19, 0x24, 0x01, 0x0b, 0x00, 0x2f, 0x27, 0xc7, 0x93, 0x14, 0x1e, + 0x00, 0x14, 0x8c, 0xf2, 0xad, 0x70, 0xd3, 0x41, 0xa0, 0x00, 0xb8, 0x86, + 0x00, 0x11, 0x80, 0x20, 0x5a, 0x25, 0x02, 0x16, 0x97, 0xc1, 0x59, 0x61, + 0x2d, 0x08, 0x3e, 0x00, 0x04, 0x19, 0x00, 0x04, 0x10, 0x89, 0x22, 0x81, + 0x8a, 0xc2, 0x11, 0x16, 0x86, 0x10, 0xf0, 0x22, 0x47, 0x03, 0x62, 0x81, + 0x41, 0x81, 0x20, 0x81, 0x42, 0x28, 0xc5, 0x27, 0x0a, 0x24, 0x00, 0x04, + 0x72, 0x0b, 0xaf, 0xfa, 0x00, 0x1c, 0x01, 0x30, 0xa5, 0x71, 0xc9, 0x0d, + 0xc4, 0x93, 0x11, 0x8e, 0x97, 0xc2, 0x2c, 0x71, 0x04, 0x71, 0x11, 0xae, + 0xc5, 0x74, 0xe1, 0x43, 0xc1, 0x40, 0x34, 0x1c, 0x01, 0x37, 0xd9, 0x41, + 0xdb, 0x59, 0x14, 0x70, 0xb6, 0x00, 0x2b, 0x00, 0x08, 0x45, 0x58, 0xf4, + 0x55, 0x26, 0x8f, 0x29, 0x8d, 0xc2, 0x23, 0x40, 0xe1, 0x41, 0xdd, 0x59, + 0x21, 0x87, 0x10, 0x44, 0x42, 0x21, 0x55, 0x00, 0x3b, 0x58, 0x0e, 0x70, + 0x18, 0x40, 0x30, 0x47, 0x12, 0x43, 0x12, 0x42, 0x0d, 0xc0, 0x5f, 0x08, + 0x05, 0x20, 0x5a, 0x20, 0x0e, 0x26, 0xc3, 0x40, 0xa0, 0x00, 0x04, 0xc2, + 0xd9, 0x60, 0x02, 0x66, 0xa6, 0x91, 0x2f, 0x0a, 0x60, 0x05, 0x48, 0x43, + 0xfe, 0xe5, 0x0a, 0xf4, 0x7e, 0xdd, 0x0a, 0x25, 0xc0, 0x22, 0x0a, 0x23, + 0x00, 0x26, 0x0a, 0x22, 0xc0, 0x25, 0x0b, 0xf0, 0x61, 0x40, 0x03, 0x41, + 0xc2, 0x0c, 0xef, 0xff, 0xe2, 0x42, 0x10, 0x43, 0x30, 0x42, 0x0a, 0x25, + 0xc0, 0x22, 0x26, 0x0c, 0x6f, 0xf8, 0xbd, 0x78, 0x09, 0xe8, 0x55, 0x80, + 0x07, 0xea, 0xf9, 0x66, 0x28, 0x18, 0xc0, 0x04, 0x60, 0x7a, 0x2c, 0x18, + 0x80, 0x04, 0x06, 0x71, 0xd2, 0xf1, 0x2d, 0x0c, 0x50, 0x20, 0x00, 0x11, + 0x81, 0x20, 0x25, 0x09, 0x1e, 0x00, 0x27, 0x1c, 0x02, 0x30, 0x26, 0x1c, + 0x02, 0x35, 0x25, 0x1c, 0xc3, 0x31, 0x3b, 0x58, 0x00, 0x42, 0x20, 0x43, + 0x40, 0x24, 0x41, 0x39, 0xfe, 0xd8, 0xd2, 0x0f, 0x2f, 0xfb, 0x8c, 0x70, + 0x5d, 0x0c, 0xd0, 0xa0, 0xda, 0xc7, 0xfa, 0x0d, 0x2f, 0xfb, 0x51, 0xd8, + 0xb3, 0x79, 0xc3, 0x40, 0xf0, 0x00, 0x4c, 0x00, 0x20, 0xb0, 0xda, 0xc7, + 0xf8, 0xc3, 0xfa, 0x08, 0x6f, 0xf8, 0xa2, 0xc1, 0x66, 0x0f, 0x2f, 0xf8, + 0x10, 0x43, 0x2e, 0x70, 0xcd, 0x70, 0x10, 0x44, 0xcb, 0x47, 0xa0, 0x00, + 0xbc, 0xc1, 0x32, 0x42, 0x32, 0x40, 0x3a, 0x40, 0xd1, 0x47, 0xd1, 0x45, + 0x04, 0x1c, 0x44, 0x34, 0x00, 0x1c, 0x40, 0x34, 0x0a, 0x0b, 0x20, 0x04, + 0x01, 0x87, 0x04, 0x30, 0x40, 0x84, 0x72, 0x00, 0x2e, 0x00, 0x10, 0x46, + 0xa0, 0x87, 0x35, 0xed, 0xa1, 0x40, 0x62, 0x41, 0xae, 0x08, 0x6f, 0xf8, + 0x82, 0x42, 0x2c, 0xe8, 0x9e, 0x0f, 0x8f, 0xf7, 0x80, 0xc0, 0x4e, 0x71, + 0x04, 0x36, 0x00, 0xa6, 0xb8, 0x60, 0x00, 0x18, 0x82, 0x04, 0x0b, 0xf6, + 0x0c, 0xf4, 0xc3, 0x40, 0xa0, 0x00, 0xa0, 0xc4, 0xf0, 0x20, 0x01, 0x04, + 0xa0, 0x48, 0x0d, 0x09, 0x03, 0x00, 0x0a, 0x20, 0x80, 0x35, 0xb1, 0x40, + 0x32, 0x25, 0x80, 0x1f, 0xa0, 0x00, 0xa8, 0x86, 0x13, 0xe8, 0x04, 0x36, + 0x40, 0xa5, 0x0a, 0xf6, 0x0f, 0xf4, 0xc3, 0x40, 0xa0, 0x00, 0xa0, 0xc4, + 0xc1, 0x48, 0xa0, 0x48, 0x13, 0x09, 0x03, 0x00, 0x0a, 0x25, 0x80, 0x25, + 0xa9, 0x46, 0x05, 0xf0, 0x46, 0x0d, 0x2f, 0xfb, 0x54, 0xd8, 0xe6, 0x71, + 0x85, 0x0f, 0xf4, 0xa0, 0x08, 0xe7, 0xcb, 0x45, 0xa0, 0x00, 0x88, 0x86, + 0x33, 0x0a, 0x10, 0x20, 0x1a, 0x08, 0x80, 0x05, 0x1d, 0xe8, 0x2e, 0x0f, + 0x8f, 0xf7, 0x00, 0x85, 0x50, 0x25, 0xfe, 0xa7, 0xca, 0x26, 0x01, 0x14, + 0x0d, 0x08, 0xa0, 0x03, 0xc1, 0x40, 0x32, 0x08, 0x00, 0x00, 0xc0, 0x85, + 0x13, 0x0e, 0x00, 0x14, 0x1c, 0x1d, 0x00, 0x14, 0x10, 0x1d, 0x43, 0x10, + 0x03, 0xf0, 0x14, 0x1d, 0xc1, 0x1f, 0x00, 0xc1, 0x04, 0x14, 0x00, 0x31, + 0x28, 0xa5, 0x12, 0xb5, 0xd8, 0xc7, 0xf2, 0x0c, 0x2f, 0xfb, 0x56, 0xd8, + 0xd8, 0xc7, 0xe0, 0x78, 0xe4, 0xc2, 0xfa, 0x0f, 0x2f, 0xf8, 0x08, 0x45, + 0x66, 0x0e, 0x2f, 0xf8, 0x08, 0x46, 0x00, 0x42, 0xa1, 0x40, 0xe2, 0x0f, + 0x2f, 0xf8, 0xc1, 0x41, 0x08, 0x46, 0x10, 0xe8, 0xb6, 0x0f, 0x40, 0x05, + 0x0e, 0xe8, 0x27, 0x80, 0x03, 0xe9, 0x00, 0x19, 0x01, 0x00, 0xc3, 0x41, + 0xa0, 0x00, 0x88, 0x86, 0x00, 0xa6, 0xc7, 0xa0, 0xa0, 0xa1, 0xc4, 0xc6, + 0x54, 0xd8, 0x03, 0xf0, 0x56, 0xd8, 0xaa, 0x0c, 0x0f, 0xfb, 0xc4, 0xc6, + 0xea, 0xc2, 0xa0, 0x80, 0x08, 0x46, 0x30, 0x41, 0x08, 0x18, 0x43, 0x00, + 0x26, 0xed, 0x42, 0x0b, 0x6f, 0xf9, 0xa1, 0x40, 0x20, 0xe8, 0x1a, 0x0a, + 0x6f, 0xf8, 0xa1, 0x40, 0x3a, 0x0b, 0x4f, 0xf9, 0x1a, 0xe8, 0x1d, 0x95, + 0x3c, 0x95, 0xe1, 0x68, 0x2b, 0x0f, 0x44, 0x10, 0x15, 0x85, 0xed, 0x70, + 0x00, 0x1e, 0x41, 0x70, 0xa0, 0x00, 0x34, 0x41, 0x10, 0x40, 0x08, 0x1d, + 0x43, 0x10, 0x0b, 0xe8, 0x0b, 0x86, 0x2a, 0x86, 0x0b, 0xa5, 0x2a, 0xa5, + 0xa1, 0x40, 0x23, 0x20, 0x00, 0x04, 0x22, 0x41, 0xe8, 0xad, 0xfd, 0xb5, + 0xa0, 0x85, 0xdd, 0xed, 0x0c, 0x70, 0x08, 0x1e, 0x03, 0x10, 0xca, 0xc6, + 0xfa, 0xc2, 0xfc, 0x1c, 0xc8, 0xb6, 0x30, 0x45, 0x4e, 0x0f, 0x2f, 0xf8, + 0x18, 0x43, 0xbe, 0x0d, 0x2f, 0xf8, 0x18, 0x41, 0x18, 0x40, 0xcd, 0x70, + 0xc5, 0x0d, 0x30, 0x20, 0x8e, 0x77, 0x4e, 0x70, 0x2e, 0x77, 0x52, 0x46, + 0x52, 0x43, 0xd3, 0x40, 0xa0, 0x00, 0x68, 0xc1, 0x16, 0x23, 0x97, 0x34, + 0xee, 0x40, 0x5a, 0x22, 0x0f, 0x27, 0x00, 0x20, 0xcd, 0x23, 0x04, 0x30, + 0x80, 0x83, 0xc4, 0xa5, 0x68, 0x00, 0x2c, 0x00, 0xc3, 0xa5, 0x04, 0x30, + 0x80, 0x8f, 0x7f, 0x47, 0x00, 0xff, 0x5c, 0x00, 0x06, 0x00, 0x07, 0x36, + 0x00, 0x70, 0x6e, 0x4e, 0x28, 0x6b, 0xfe, 0x0b, 0x8f, 0xec, 0x00, 0x42, + 0x3c, 0x26, 0x88, 0x20, 0x3c, 0x23, 0x4c, 0x20, 0x0c, 0x23, 0x40, 0xa0, + 0xca, 0x24, 0x01, 0x12, 0x95, 0x70, 0x3c, 0x22, 0x0b, 0x05, 0x3c, 0x21, + 0x43, 0x04, 0xca, 0x23, 0x42, 0x20, 0xca, 0x26, 0x82, 0x20, 0x0c, 0x21, + 0x40, 0xa0, 0xe6, 0x40, 0xca, 0x23, 0xc1, 0x02, 0x74, 0x70, 0x22, 0xa5, + 0x41, 0xa5, 0x02, 0x77, 0xca, 0x21, 0x42, 0x20, 0xca, 0x24, 0x82, 0x20, + 0x23, 0x41, 0x03, 0x42, 0xae, 0x0e, 0x2f, 0xf8, 0x00, 0xa7, 0x04, 0xf0, + 0x0c, 0x70, 0xd8, 0xad, 0x46, 0x71, 0x81, 0x0a, 0x64, 0xa5, 0x05, 0xa5, + 0x0a, 0x24, 0x40, 0x75, 0xa8, 0x20, 0x00, 0x04, 0x5a, 0x26, 0x00, 0x17, + 0x02, 0x70, 0x25, 0x80, 0x09, 0xe9, 0x41, 0x80, 0x22, 0x80, 0x0e, 0x22, + 0x82, 0x85, 0x03, 0x23, 0x41, 0xa0, 0x43, 0xa0, 0x24, 0xa0, 0xc5, 0x71, + 0xca, 0x46, 0x04, 0xf0, 0x2e, 0x77, 0x6e, 0x70, 0x02, 0x26, 0x02, 0x95, + 0xc3, 0x41, 0xa0, 0x00, 0x88, 0x86, 0x03, 0x23, 0x40, 0xa4, 0x28, 0x19, + 0x00, 0x05, 0x2c, 0x19, 0x40, 0x04, 0x42, 0xa1, 0x03, 0xa1, 0x04, 0x14, + 0x1b, 0x34, 0xda, 0xc6, 0xf4, 0xc3, 0x82, 0x24, 0x0c, 0x3f, 0x68, 0x46, + 0x50, 0x43, 0x28, 0x45, 0x10, 0x40, 0x8a, 0x27, 0x8e, 0x10, 0x07, 0xea, + 0x2c, 0x70, 0xa1, 0x40, 0x22, 0x0a, 0xaf, 0xfa, 0x62, 0x42, 0x4a, 0x24, + 0xc0, 0x73, 0xfe, 0xd9, 0x02, 0x77, 0x0c, 0x74, 0x00, 0x1c, 0x01, 0x31, + 0x22, 0xad, 0x4a, 0x21, 0x00, 0x00, 0x81, 0xc2, 0xa8, 0x20, 0x40, 0x01, + 0x24, 0x71, 0x01, 0x1a, 0x52, 0x00, 0x09, 0xee, 0x8f, 0xe6, 0x32, 0x01, + 0x2d, 0x00, 0x61, 0xc6, 0xc3, 0xad, 0x4e, 0x71, 0x05, 0xf0, 0x4a, 0x22, + 0xc0, 0x23, 0x03, 0x1d, 0x03, 0x10, 0x8a, 0x26, 0x07, 0x1d, 0x54, 0x20, + 0x15, 0x29, 0x54, 0x20, 0x94, 0x2b, 0x2e, 0x70, 0x40, 0x24, 0x16, 0x31, + 0x02, 0x76, 0x01, 0x16, 0x80, 0x24, 0x04, 0x77, 0xf3, 0x08, 0xd5, 0x03, + 0x25, 0x20, 0x00, 0x00, 0x0f, 0xf0, 0x1d, 0xf0, 0x2d, 0xf0, 0x3a, 0xf0, + 0x4c, 0xf0, 0x4f, 0xf0, 0x50, 0xf0, 0x53, 0xf0, 0x54, 0xf0, 0x5c, 0xf0, + 0x5d, 0xf0, 0x5f, 0xf0, 0x5f, 0xf0, 0x61, 0xf0, 0x61, 0xf0, 0x56, 0x24, + 0x40, 0x3d, 0x14, 0xda, 0x5a, 0x0b, 0xaf, 0xec, 0xa2, 0x41, 0x56, 0x24, + 0x40, 0x3d, 0x80, 0xc3, 0xa1, 0x41, 0x1a, 0x0e, 0x20, 0x05, 0x62, 0x42, + 0x59, 0xf0, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x94, 0x01, 0x14, 0xda, + 0x3a, 0x0b, 0xaf, 0xec, 0x82, 0x41, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, + 0x94, 0x01, 0x80, 0xc3, 0xa1, 0x41, 0xc2, 0x08, 0x60, 0x05, 0x62, 0x42, + 0x47, 0xf0, 0x85, 0xc0, 0x8a, 0x22, 0x06, 0x00, 0x1a, 0x0b, 0xaf, 0xec, + 0xc1, 0x41, 0x85, 0xc0, 0x80, 0xc3, 0xa1, 0x41, 0x02, 0x0a, 0x60, 0x05, + 0x62, 0x42, 0x3b, 0xf0, 0x70, 0x10, 0x82, 0x20, 0x00, 0x24, 0x81, 0x3f, + 0x00, 0x00, 0xbc, 0x01, 0xf6, 0x0f, 0xa0, 0x04, 0xdf, 0x10, 0x00, 0x26, + 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0xbc, 0x01, 0x80, 0xc3, 0xa1, 0x41, + 0xce, 0x0a, 0x60, 0x05, 0x62, 0x42, 0x27, 0xf0, 0x28, 0x10, 0x00, 0x20, + 0x0c, 0xf0, 0x2c, 0x10, 0x00, 0x20, 0x0a, 0xf0, 0x30, 0x10, 0x00, 0x20, + 0x06, 0xf0, 0xdd, 0x10, 0x00, 0x26, 0x04, 0xf0, 0xde, 0x10, 0x00, 0x26, + 0x80, 0xc3, 0xa1, 0x41, 0xc6, 0x0c, 0x60, 0x05, 0x62, 0x42, 0x13, 0xf0, + 0xff, 0x17, 0x80, 0x90, 0x0a, 0xf0, 0x00, 0x8f, 0x08, 0xf0, 0x01, 0x8f, + 0x06, 0xf0, 0x02, 0x8f, 0x04, 0xf0, 0x03, 0x8f, 0x02, 0xf0, 0x04, 0x8f, + 0x80, 0xc3, 0xa1, 0x41, 0x66, 0x0d, 0x60, 0x05, 0x62, 0x42, 0x26, 0x71, + 0x07, 0x09, 0x84, 0xa4, 0x00, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, + 0x21, 0xad, 0xd4, 0xc7, 0xf0, 0xc3, 0xa2, 0xc1, 0x50, 0x42, 0x68, 0x45, + 0x28, 0x46, 0x10, 0x40, 0x06, 0xea, 0x2c, 0x70, 0xc1, 0x40, 0xb6, 0x08, + 0xaf, 0xfa, 0x42, 0x42, 0xfe, 0xd9, 0xed, 0x71, 0x04, 0x1c, 0x01, 0x31, + 0x03, 0x1c, 0x83, 0x30, 0x22, 0xae, 0x02, 0x1c, 0xc2, 0x33, 0x0a, 0xed, + 0x0c, 0x74, 0x5b, 0x0d, 0xf5, 0x10, 0x02, 0x1c, 0x42, 0x33, 0xa3, 0xae, + 0x8e, 0x71, 0x06, 0xf0, 0x8e, 0x72, 0xad, 0x71, 0x03, 0x1e, 0x03, 0x10, + 0x8a, 0x21, 0x0e, 0x20, 0x40, 0x24, 0xd3, 0x30, 0x19, 0x0d, 0xb0, 0x10, + 0x81, 0xc3, 0x21, 0x0d, 0x71, 0x10, 0x81, 0xc3, 0x42, 0x42, 0x02, 0x40, + 0x32, 0x0f, 0x60, 0x05, 0xc1, 0x41, 0x08, 0xf0, 0x32, 0x20, 0x40, 0x24, + 0xc1, 0x41, 0xe6, 0x0c, 0x60, 0x05, 0x42, 0x42, 0x0d, 0x0f, 0x05, 0x15, + 0x01, 0x13, 0x8d, 0x24, 0xe5, 0x71, 0xea, 0xf1, 0x01, 0xc0, 0x41, 0x28, + 0x01, 0x02, 0x00, 0xae, 0x21, 0xae, 0xd0, 0xc7, 0xe8, 0xc2, 0x48, 0x46, + 0x28, 0x47, 0x2c, 0x70, 0x10, 0xda, 0x60, 0x40, 0x0a, 0x20, 0x00, 0x21, + 0x2e, 0x08, 0xaf, 0xfa, 0x68, 0x45, 0x0c, 0x70, 0x36, 0xef, 0x29, 0x6e, + 0x21, 0x09, 0xf5, 0x00, 0x42, 0x26, 0x41, 0x1e, 0x04, 0x1d, 0x83, 0x12, + 0x03, 0x1d, 0x03, 0x11, 0x02, 0x1d, 0xc3, 0x10, 0x01, 0x1d, 0x83, 0x10, + 0x00, 0x1d, 0x43, 0x10, 0x0c, 0x75, 0x26, 0xf0, 0x49, 0x09, 0xd5, 0x02, + 0x25, 0x20, 0x40, 0x00, 0x0b, 0xf0, 0x0e, 0xf0, 0x0f, 0xf0, 0x12, 0xf0, + 0x1c, 0xf0, 0x1c, 0xf0, 0x1a, 0xf0, 0x17, 0xf0, 0x0f, 0xf0, 0x18, 0xf0, + 0x10, 0xf0, 0x00, 0x1d, 0xc3, 0x11, 0x13, 0xf0, 0x00, 0x1d, 0x83, 0x12, + 0x0f, 0xf0, 0x00, 0x1d, 0xc3, 0x12, 0x0d, 0xf0, 0x00, 0x1d, 0x03, 0x13, + 0x09, 0xf0, 0x00, 0x1d, 0x83, 0x13, 0x07, 0xf0, 0x00, 0x1d, 0xc3, 0x13, + 0x03, 0xf0, 0x00, 0x1d, 0x43, 0x13, 0x0c, 0x71, 0x00, 0x18, 0x00, 0x20, + 0xc8, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0xfe, 0x0b, 0x60, 0x03, 0x08, 0x45, + 0x4a, 0x24, 0x40, 0x71, 0x2c, 0x70, 0xa1, 0x40, 0xa8, 0x20, 0x40, 0x01, + 0x21, 0xa0, 0x08, 0x18, 0x11, 0x00, 0x80, 0x25, 0x0e, 0x10, 0x00, 0x1d, + 0x03, 0x10, 0xc2, 0xc6, 0xfd, 0x01, 0x00, 0x05, 0xea, 0xc3, 0x82, 0x24, + 0x0e, 0x34, 0x10, 0x41, 0x8c, 0xc0, 0x8a, 0x22, 0x0d, 0x08, 0x3a, 0x09, + 0xaf, 0xec, 0x28, 0x45, 0x02, 0x8d, 0x8c, 0x20, 0x83, 0x8f, 0x8a, 0x20, + 0x3e, 0x07, 0x36, 0xf4, 0x23, 0x8d, 0x0e, 0x72, 0xad, 0x71, 0x4c, 0x71, + 0x03, 0x1c, 0x83, 0x30, 0x02, 0x1c, 0x42, 0x33, 0x09, 0xe9, 0x8a, 0x20, + 0xfe, 0x06, 0x20, 0x42, 0x0e, 0x71, 0x51, 0x09, 0xf5, 0x00, 0x02, 0x1c, + 0x42, 0x30, 0x8a, 0x26, 0x0e, 0x10, 0x40, 0x24, 0xcf, 0x30, 0x22, 0x76, + 0x04, 0x1c, 0x01, 0x31, 0x23, 0x0a, 0xb0, 0x00, 0x8c, 0xc0, 0x4d, 0x78, + 0x23, 0x08, 0x71, 0x00, 0x8c, 0xc0, 0x81, 0xc1, 0xea, 0x08, 0xa0, 0x05, + 0x82, 0xc2, 0x82, 0xc1, 0x28, 0xda, 0xde, 0x08, 0xaf, 0xec, 0x22, 0x40, + 0x05, 0xf0, 0xfa, 0x0f, 0xe0, 0x05, 0x81, 0xc1, 0x00, 0xae, 0x0f, 0x0d, + 0x05, 0x14, 0x01, 0x17, 0x82, 0x14, 0xa5, 0x71, 0xe6, 0xf1, 0x0c, 0x70, + 0xca, 0xc7, 0xe0, 0x78, 0xe8, 0xc2, 0x00, 0x20, 0x8d, 0x0f, 0x00, 0x00, + 0x24, 0x02, 0x36, 0x0f, 0x2f, 0xef, 0x10, 0x40, 0x4a, 0x24, 0x00, 0x71, + 0xc3, 0x43, 0x13, 0x00, 0xe0, 0x6b, 0x55, 0x20, 0x80, 0x2a, 0x60, 0x41, + 0xa8, 0x20, 0x00, 0x02, 0x01, 0x11, 0xc2, 0x04, 0x48, 0x32, 0x82, 0x00, + 0x04, 0x18, 0x90, 0x00, 0x4a, 0x24, 0x00, 0x71, 0x55, 0x20, 0x80, 0x2b, + 0x0a, 0x21, 0xc0, 0x00, 0xa8, 0x20, 0x00, 0x02, 0x01, 0x11, 0xc2, 0x04, + 0x48, 0x32, 0x82, 0x00, 0x04, 0x18, 0x90, 0x00, 0x4a, 0x24, 0x00, 0x71, + 0x40, 0x20, 0x00, 0x2b, 0x0a, 0x21, 0xc0, 0x00, 0x28, 0x18, 0x01, 0x20, + 0xa8, 0x20, 0x00, 0x02, 0x01, 0x11, 0xc2, 0x04, 0x48, 0x32, 0x82, 0x00, + 0x04, 0x18, 0x90, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x20, 0x00, 0x2d, + 0x4a, 0x27, 0x00, 0x10, 0xcc, 0x18, 0x43, 0x20, 0xa0, 0x18, 0x43, 0x20, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0x4a, 0x24, 0x00, 0x71, + 0xc3, 0x40, 0xa3, 0x3b, 0x0a, 0xd7, 0xa0, 0x1d, 0xd8, 0x93, 0x78, 0x18, + 0x00, 0x20, 0x55, 0x20, 0x00, 0x29, 0x60, 0x41, 0xa8, 0x20, 0x00, 0x02, + 0x01, 0x11, 0xc2, 0x04, 0x48, 0x32, 0x82, 0x00, 0x04, 0x18, 0x90, 0x00, + 0xc2, 0x83, 0x81, 0x83, 0x63, 0x83, 0xc3, 0x40, 0x49, 0x40, 0xdb, 0x0f, + 0x8a, 0x21, 0x09, 0x0d, 0xfe, 0xa5, 0xfa, 0xa5, 0xc3, 0x42, 0xac, 0x3b, + 0x00, 0x5f, 0x8c, 0x18, 0x43, 0x20, 0x15, 0xa5, 0x18, 0xa5, 0x17, 0xa5, + 0x16, 0xa5, 0x02, 0x71, 0x02, 0x40, 0x5f, 0xa5, 0xf4, 0xa9, 0x00, 0x19, + 0x43, 0x00, 0x9b, 0xa5, 0x7d, 0xa5, 0x8e, 0x0d, 0xa0, 0x00, 0xdc, 0xa5, + 0xc8, 0xc6, 0xe0, 0x78, 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x34, 0x50, 0x40, + 0x08, 0x47, 0x84, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0xba, 0x0f, 0x6f, 0xec, + 0x28, 0x45, 0x00, 0x87, 0x40, 0x24, 0x83, 0x30, 0x40, 0x24, 0x04, 0x32, + 0x40, 0x24, 0x05, 0x33, 0x40, 0x24, 0x06, 0x31, 0x40, 0x24, 0xc7, 0x30, + 0xa1, 0x41, 0x02, 0x42, 0xc6, 0x0b, 0xaf, 0xf3, 0x02, 0x1c, 0x43, 0x31, + 0x02, 0xc5, 0x81, 0x0d, 0x31, 0x10, 0x2c, 0x70, 0x03, 0x14, 0x8e, 0x30, + 0xad, 0x70, 0xba, 0xe9, 0x02, 0x14, 0x81, 0x30, 0xcf, 0x78, 0x6d, 0x09, + 0x24, 0x00, 0x04, 0x77, 0x4d, 0x08, 0x55, 0x01, 0x25, 0x20, 0x00, 0x00, + 0x05, 0xf0, 0x0b, 0xf0, 0x0f, 0xf0, 0x15, 0xf0, 0x19, 0xf0, 0x84, 0xc0, + 0xe6, 0x0d, 0x6f, 0xf5, 0x81, 0xc1, 0x15, 0xaf, 0x18, 0xf0, 0x84, 0xc0, + 0xda, 0x0d, 0x6f, 0xf5, 0x81, 0xc1, 0x17, 0xaf, 0x12, 0xf0, 0x84, 0xc0, + 0xf6, 0x0f, 0xa0, 0x03, 0x81, 0xc1, 0x0c, 0xb7, 0x0c, 0xf0, 0x84, 0xc0, + 0xc2, 0x0d, 0x6f, 0xf5, 0x81, 0xc1, 0x1a, 0xaf, 0x06, 0xf0, 0x84, 0xc0, + 0xc2, 0x0a, 0xef, 0xf6, 0x81, 0xc1, 0x0e, 0xb7, 0x01, 0xc0, 0x8a, 0x21, + 0x3e, 0x06, 0x12, 0x70, 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, 0x01, 0x20, + 0x3d, 0x20, 0x00, 0x20, 0x1e, 0x66, 0xc9, 0xf1, 0xa1, 0x40, 0xc8, 0xc7, + 0xe8, 0xc3, 0xa3, 0xc1, 0x4a, 0x24, 0xc0, 0x70, 0x08, 0x45, 0x80, 0xc2, + 0x6c, 0x70, 0xa8, 0x20, 0x80, 0x06, 0x04, 0x11, 0x00, 0x04, 0x48, 0x47, + 0x00, 0x30, 0x80, 0x0f, 0x03, 0x40, 0x6f, 0x12, 0x04, 0x30, 0xc0, 0x80, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, + 0x42, 0x6f, 0x00, 0xb7, 0x80, 0xc0, 0xa6, 0x0b, 0x20, 0x05, 0x82, 0xc1, + 0x4c, 0x95, 0x08, 0x14, 0x01, 0x31, 0x15, 0x8d, 0x42, 0x79, 0x2e, 0x79, + 0x06, 0x0c, 0x20, 0x00, 0x4c, 0x77, 0x9a, 0x0e, 0x20, 0x03, 0x2c, 0x71, + 0x10, 0x40, 0x08, 0x14, 0x41, 0x31, 0x15, 0x8d, 0xf2, 0x0b, 0x20, 0x00, + 0x4c, 0x77, 0x86, 0x0e, 0x20, 0x03, 0x2c, 0x71, 0x0a, 0x14, 0x4e, 0x31, + 0x2f, 0x21, 0x06, 0x04, 0x15, 0x0e, 0x63, 0x10, 0x00, 0x42, 0x00, 0x14, + 0x40, 0x31, 0x39, 0x08, 0x12, 0x00, 0x08, 0x1d, 0x45, 0x10, 0x1d, 0xf0, + 0x2c, 0x9d, 0xc2, 0x0b, 0x20, 0x00, 0x4e, 0x78, 0x13, 0x08, 0x83, 0x03, + 0x02, 0x14, 0x40, 0x31, 0x23, 0x08, 0x12, 0x00, 0x08, 0x1d, 0x05, 0x10, + 0x0f, 0xf0, 0x04, 0x8d, 0x0d, 0xe8, 0x32, 0x0b, 0x60, 0x05, 0x80, 0xc0, + 0x09, 0xe8, 0x08, 0x1d, 0xc5, 0x1f, 0x07, 0xf0, 0x08, 0x1d, 0xc5, 0x10, + 0x03, 0xf0, 0x08, 0x1d, 0x85, 0x10, 0x17, 0x8d, 0x18, 0xe8, 0x20, 0x9f, + 0x09, 0x09, 0x33, 0x00, 0x20, 0x40, 0x33, 0x78, 0x10, 0x78, 0x8c, 0x20, + 0xc6, 0x86, 0x88, 0xf7, 0x04, 0x21, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x80, + 0x2f, 0xb8, 0x08, 0xf0, 0x03, 0x9d, 0x11, 0x08, 0x32, 0x00, 0x2c, 0x72, + 0x02, 0x0e, 0x00, 0x03, 0x05, 0xb5, 0x05, 0xf0, 0x0c, 0x70, 0x0a, 0x1d, + 0x05, 0x10, 0x24, 0x9d, 0x34, 0x77, 0x07, 0xf2, 0x0e, 0x78, 0xc2, 0xb9, + 0xd2, 0x68, 0x25, 0x7e, 0x04, 0xf0, 0xcb, 0x46, 0x00, 0x00, 0xff, 0xff, + 0x03, 0x95, 0xd0, 0x7a, 0xed, 0x70, 0x50, 0x70, 0x0c, 0x70, 0x23, 0xf2, + 0x7a, 0x8d, 0x0c, 0x70, 0x1f, 0xeb, 0x1b, 0x0b, 0xf1, 0x00, 0x0c, 0x71, + 0x36, 0x8d, 0x89, 0x95, 0x24, 0x71, 0x31, 0x0c, 0xa1, 0x10, 0x36, 0xad, + 0x2f, 0x79, 0x2b, 0x09, 0x94, 0x02, 0x40, 0x25, 0x02, 0x13, 0x80, 0xc1, + 0x6a, 0x0a, 0x20, 0x00, 0x60, 0x40, 0x8d, 0xe8, 0x74, 0x8d, 0x2e, 0x95, + 0x80, 0xc0, 0x86, 0x08, 0x20, 0x00, 0x4c, 0x70, 0x14, 0xad, 0x78, 0x20, + 0x40, 0x00, 0x03, 0xf0, 0xf6, 0xad, 0x24, 0x8d, 0x0f, 0x78, 0x0f, 0x08, + 0x71, 0x00, 0xc9, 0xb5, 0x83, 0xe9, 0xc3, 0x95, 0x2c, 0x70, 0x16, 0xe9, + 0x43, 0x9d, 0x83, 0x40, 0x60, 0x90, 0x21, 0x90, 0x02, 0x90, 0x66, 0xb5, + 0x27, 0xb5, 0x25, 0x0a, 0x32, 0x00, 0x08, 0xb5, 0xd0, 0x79, 0xc3, 0x40, + 0x00, 0x00, 0xff, 0xff, 0x11, 0x09, 0x00, 0x00, 0x48, 0x47, 0x85, 0x27, + 0x3e, 0x10, 0x06, 0xf0, 0x43, 0x95, 0x06, 0xf0, 0x00, 0x42, 0x03, 0xb5, + 0x04, 0x1d, 0x03, 0x10, 0x83, 0x40, 0x80, 0x90, 0x61, 0x90, 0x02, 0x90, + 0xd0, 0x79, 0x86, 0xb5, 0x67, 0xb5, 0x08, 0xb5, 0x17, 0x09, 0x80, 0x0f, + 0x00, 0x00, 0xff, 0xff, 0x50, 0x78, 0x0f, 0x08, 0x40, 0x00, 0xc3, 0xb5, + 0x85, 0x26, 0x3e, 0x10, 0xc9, 0x47, 0xef, 0x78, 0xc8, 0xc7, 0xe0, 0x78, + 0xe6, 0xc0, 0x80, 0x98, 0xcd, 0x70, 0x8c, 0xbe, 0x17, 0x0e, 0x22, 0x13, + 0xc9, 0x45, 0x89, 0x45, 0x0f, 0x0c, 0x83, 0x1f, 0xff, 0xff, 0xff, 0xef, + 0xcb, 0x45, 0x00, 0x00, 0xff, 0xef, 0x81, 0x98, 0x17, 0x0e, 0x22, 0x13, + 0xc9, 0x47, 0x89, 0x47, 0x0f, 0x0c, 0x83, 0x1f, 0xff, 0xff, 0xff, 0xef, + 0xcb, 0x47, 0x00, 0x00, 0xff, 0xef, 0x02, 0x98, 0x15, 0x0e, 0x02, 0x10, + 0x08, 0x46, 0x11, 0x08, 0x83, 0x0f, 0xff, 0xff, 0xff, 0xef, 0xcb, 0x46, + 0x00, 0x00, 0xff, 0xef, 0xce, 0x7c, 0xae, 0x7d, 0xee, 0x78, 0x1a, 0x24, + 0x4e, 0x10, 0x1e, 0x25, 0x41, 0x13, 0x09, 0x78, 0x8c, 0x7e, 0x40, 0x2a, + 0x0d, 0x05, 0x38, 0x60, 0x36, 0x68, 0xb8, 0x61, 0x10, 0x76, 0xc1, 0x42, + 0x0c, 0x71, 0x0d, 0xf7, 0xb8, 0x62, 0x30, 0x70, 0x60, 0x40, 0x49, 0xf7, + 0x0b, 0x0c, 0x33, 0x10, 0x81, 0x40, 0x93, 0x78, 0x0e, 0x78, 0xbf, 0x20, + 0x1f, 0x04, 0xc6, 0xc4, 0xe6, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, 0x22, 0x09, 0xaf, 0xf3, 0x03, 0x1c, + 0x43, 0x31, 0x02, 0x14, 0x80, 0x30, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, + 0x55, 0x09, 0x24, 0x00, 0x04, 0x77, 0x45, 0x08, 0x55, 0x01, 0x25, 0x20, + 0x00, 0x00, 0x06, 0xf0, 0x06, 0xf0, 0x08, 0xf0, 0x0d, 0xf0, 0x14, 0xf0, + 0x15, 0x8e, 0x0c, 0xf0, 0x17, 0x8e, 0x0a, 0xf0, 0x0c, 0x9e, 0x81, 0xc3, + 0xa1, 0x41, 0xce, 0x09, 0x20, 0x03, 0xe1, 0x42, 0x0e, 0xf0, 0x1a, 0x8e, + 0x81, 0xc3, 0xa1, 0x41, 0xe2, 0x0a, 0x6f, 0xf5, 0xe1, 0x42, 0x08, 0xf0, + 0x0e, 0x96, 0x81, 0xc3, 0xa1, 0x41, 0xea, 0x0f, 0xaf, 0xf6, 0xe1, 0x42, + 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xd5, 0xf1, + 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc6, 0xc7, + 0xe8, 0xc2, 0x50, 0x40, 0x28, 0x46, 0x2c, 0x70, 0x10, 0xda, 0x60, 0x40, + 0x88, 0x47, 0x5e, 0x0a, 0x6f, 0xfa, 0x68, 0x45, 0x0c, 0x70, 0x07, 0xee, + 0x0b, 0x08, 0x91, 0x2f, 0x0c, 0x71, 0x00, 0x1d, 0x83, 0x10, 0x00, 0xa7, + 0xc8, 0xc6, 0xe0, 0x78, 0xe8, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, 0x6e, 0x08, 0xaf, 0xf3, 0x03, 0x1c, + 0xc3, 0x31, 0x02, 0x14, 0x80, 0x30, 0x40, 0x26, 0x10, 0x13, 0x03, 0x14, + 0x81, 0x30, 0x0f, 0x78, 0x61, 0x09, 0x24, 0x00, 0x04, 0x77, 0x51, 0x08, + 0xd5, 0x01, 0x25, 0x20, 0x00, 0x00, 0x08, 0xf0, 0x0e, 0xf0, 0x08, 0xf0, + 0x08, 0xf0, 0x0a, 0xf0, 0x11, 0xf0, 0x18, 0xf0, 0x16, 0x8e, 0x10, 0xf0, + 0x04, 0x9e, 0x07, 0xf0, 0x05, 0x9e, 0x05, 0xf0, 0x09, 0x9e, 0x03, 0xf0, + 0x03, 0x9e, 0x81, 0xc3, 0xa1, 0x41, 0x0a, 0x09, 0x20, 0x03, 0xe1, 0x42, + 0x0e, 0xf0, 0x14, 0x8e, 0x81, 0xc3, 0xa1, 0x41, 0x1e, 0x0a, 0x6f, 0xf5, + 0xe1, 0x42, 0x08, 0xf0, 0x81, 0xc3, 0x02, 0x40, 0xa1, 0x41, 0x72, 0x0d, + 0xe0, 0x05, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, + 0x02, 0x30, 0xcf, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, + 0x21, 0xad, 0xc8, 0xc7, 0xe4, 0xc3, 0xa5, 0xc1, 0x28, 0x40, 0x2a, 0x68, + 0x34, 0x72, 0x60, 0x00, 0x26, 0x00, 0x2c, 0x70, 0x0d, 0x08, 0xf0, 0x00, + 0x4a, 0x25, 0x00, 0x10, 0x09, 0x08, 0x91, 0x00, 0x8a, 0x25, 0x86, 0x16, + 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x24, 0x0b, 0x30, 0xa8, 0x20, 0xc0, 0x02, + 0xf4, 0x22, 0x43, 0x00, 0xf4, 0x20, 0x40, 0x10, 0x14, 0x23, 0x4c, 0x10, + 0x24, 0x71, 0x62, 0x78, 0x00, 0xb4, 0x80, 0xc0, 0x83, 0xc1, 0x82, 0x0d, + 0xe0, 0x04, 0x83, 0xc6, 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0xc0, 0x02, 0x02, 0x16, 0x02, 0x15, 0x40, 0x24, 0x41, 0x32, + 0x1b, 0x61, 0x04, 0x71, 0x3c, 0x25, 0x81, 0x10, 0x20, 0xab, 0x17, 0xf0, + 0x35, 0x08, 0x71, 0x00, 0x01, 0x40, 0x83, 0xc1, 0x52, 0x0d, 0xe0, 0x04, + 0x83, 0xc5, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x24, 0x41, 0x32, 0xa8, 0x20, + 0xc0, 0x02, 0x02, 0x15, 0x00, 0x15, 0x3c, 0x26, 0x00, 0x70, 0x00, 0x00, + 0x00, 0x0c, 0x01, 0x19, 0x12, 0x00, 0xaa, 0x09, 0xef, 0xf4, 0x40, 0x24, + 0x40, 0x32, 0x00, 0x41, 0x20, 0x40, 0xc4, 0xc7, 0xcd, 0x00, 0x40, 0x03, + 0x38, 0x60, 0xe0, 0x7f, 0x0e, 0x78, 0xe0, 0x78, 0xe8, 0xc2, 0x48, 0x45, + 0x10, 0x40, 0x29, 0x78, 0x54, 0x77, 0xca, 0x25, 0x21, 0x10, 0x15, 0x0d, + 0x32, 0x10, 0x28, 0x47, 0x21, 0x0d, 0x33, 0x18, 0xcd, 0x70, 0x00, 0x28, + 0x4e, 0x03, 0x0c, 0xf0, 0x8c, 0x25, 0x7f, 0x98, 0x86, 0xf6, 0x76, 0x0a, + 0x20, 0x03, 0xb3, 0x79, 0x08, 0x46, 0x04, 0xf0, 0x42, 0x28, 0xce, 0x07, + 0x29, 0x6d, 0x0c, 0x71, 0x38, 0x78, 0x30, 0x79, 0xa0, 0xe1, 0xca, 0x20, + 0x26, 0x00, 0x0b, 0x7e, 0xc0, 0x26, 0x62, 0x10, 0x10, 0xd9, 0x52, 0x0a, + 0x20, 0x03, 0xc1, 0x40, 0x08, 0x45, 0xce, 0x78, 0x46, 0x0a, 0x20, 0x03, + 0x0f, 0xd9, 0x19, 0x0d, 0x20, 0x10, 0x07, 0x27, 0x00, 0x14, 0x3a, 0x0a, + 0x20, 0x03, 0x0f, 0xd9, 0x00, 0x20, 0x8e, 0x0f, 0x00, 0x00, 0xff, 0x7f, + 0xce, 0x78, 0xc8, 0xc6, 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x35, 0x50, 0x40, + 0x08, 0x47, 0x85, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0x32, 0x0a, 0x6f, 0xec, + 0x28, 0x45, 0x00, 0x87, 0x40, 0x24, 0x83, 0x31, 0x40, 0x24, 0x04, 0x33, + 0x40, 0x24, 0x05, 0x34, 0x40, 0x24, 0x06, 0x32, 0x40, 0x24, 0xc7, 0x31, + 0xa1, 0x41, 0x02, 0x42, 0x3e, 0x0e, 0x6f, 0xf3, 0x06, 0x1c, 0xc3, 0x31, + 0x03, 0xc5, 0xad, 0x0d, 0x31, 0x10, 0x2c, 0x70, 0x07, 0x14, 0x8e, 0x30, + 0xad, 0x70, 0xa1, 0x09, 0x31, 0x00, 0xcf, 0x78, 0x06, 0x14, 0x81, 0x30, + 0x95, 0x09, 0x24, 0x00, 0x04, 0x77, 0x79, 0x08, 0xd5, 0x01, 0x25, 0x20, + 0x00, 0x00, 0x08, 0xf0, 0x0c, 0xf0, 0x12, 0xf0, 0x16, 0xf0, 0x1c, 0xf0, + 0x20, 0xf0, 0x26, 0xf0, 0x85, 0xc0, 0x5a, 0x08, 0x6f, 0xf5, 0x82, 0xc1, + 0x16, 0xaf, 0x2c, 0xf0, 0x85, 0xc0, 0x76, 0x0a, 0xa0, 0x03, 0x82, 0xc1, + 0x03, 0xb7, 0x26, 0xf0, 0x85, 0xc0, 0x6a, 0x0a, 0xa0, 0x03, 0x82, 0xc1, + 0x04, 0xb7, 0x20, 0xf0, 0x85, 0xc0, 0x5e, 0x0a, 0xa0, 0x03, 0x82, 0xc1, + 0x05, 0xb7, 0x1a, 0xf0, 0x85, 0xc0, 0x52, 0x0a, 0xa0, 0x03, 0x82, 0xc1, + 0x09, 0xb7, 0x14, 0xf0, 0x85, 0xc0, 0x1e, 0x08, 0x6f, 0xf5, 0x82, 0xc1, + 0x14, 0xaf, 0x0e, 0xf0, 0x85, 0xc0, 0x82, 0xc1, 0x5e, 0x0b, 0xe0, 0x05, + 0x80, 0xc2, 0x83, 0x40, 0x40, 0x90, 0x21, 0x90, 0x02, 0x90, 0x46, 0xb7, + 0x27, 0xb7, 0x08, 0xb7, 0x02, 0xc0, 0x8a, 0x21, 0x3e, 0x06, 0x12, 0x70, + 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, + 0x1e, 0x66, 0xb3, 0xf1, 0xa1, 0x40, 0xc8, 0xc7, 0x48, 0x31, 0x01, 0x00, + 0x07, 0x36, 0x42, 0x70, 0x48, 0x47, 0x00, 0x00, 0x28, 0x80, 0x04, 0x31, + 0x80, 0x80, 0xe0, 0x7c, 0x04, 0x18, 0x43, 0x00, 0xe0, 0x7f, 0x48, 0xa0, + 0xfa, 0xc2, 0xfc, 0x1c, 0xc8, 0xb6, 0x82, 0x24, 0x03, 0x38, 0x04, 0x15, + 0x0c, 0x00, 0x6d, 0x70, 0x0a, 0x21, 0x40, 0x21, 0x04, 0x34, 0xc0, 0x92, + 0x0a, 0x20, 0xc0, 0x21, 0x0a, 0x25, 0x80, 0x21, 0x0a, 0x21, 0x00, 0x31, + 0x70, 0x42, 0x58, 0x43, 0x08, 0x46, 0xc8, 0xf6, 0x01, 0x34, 0x8d, 0x1f, + 0x00, 0x3f, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x01, 0x34, 0x8d, 0x1f, + 0x00, 0xbf, 0x00, 0x00, 0x47, 0x14, 0x0f, 0x36, 0x4a, 0x24, 0xc0, 0x70, + 0x55, 0x24, 0x40, 0x3d, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x11, 0x02, 0x04, + 0x00, 0x32, 0x82, 0x0f, 0x83, 0x3a, 0x6f, 0x12, 0x04, 0x18, 0x90, 0x00, + 0x55, 0x24, 0x41, 0x3d, 0x55, 0x24, 0x82, 0x3c, 0xc1, 0x40, 0x9e, 0x0d, + 0x6f, 0xee, 0x55, 0x24, 0x93, 0x3c, 0x48, 0x35, 0xc0, 0x12, 0x55, 0x24, + 0x44, 0x3d, 0x1d, 0x78, 0x55, 0x24, 0xc5, 0x3b, 0x44, 0x20, 0x43, 0x00, + 0xc1, 0x40, 0x42, 0x41, 0x23, 0x42, 0x55, 0x24, 0xcd, 0x3b, 0x92, 0x0c, + 0xaf, 0xee, 0x70, 0x44, 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0x80, 0x03, 0x01, 0x4d, 0xf0, 0x23, 0x03, 0x20, 0x55, 0x24, + 0x02, 0x3b, 0x00, 0x31, 0x41, 0x05, 0x15, 0x7a, 0x01, 0x33, 0x41, 0x00, + 0x04, 0x71, 0x20, 0xa2, 0x61, 0x86, 0x49, 0x86, 0x28, 0x4e, 0x55, 0x24, + 0x01, 0x3b, 0x55, 0x24, 0x04, 0x3a, 0x8e, 0x0a, 0xef, 0xf2, 0x10, 0x46, + 0x55, 0x24, 0x01, 0x3a, 0x10, 0xda, 0x6e, 0x08, 0x6f, 0xec, 0xc2, 0x40, + 0x55, 0x24, 0x01, 0x3a, 0x32, 0x09, 0xef, 0xf2, 0xc2, 0x40, 0x55, 0x24, + 0x01, 0x3a, 0x10, 0xda, 0x56, 0x08, 0x6f, 0xec, 0xc2, 0x40, 0x3c, 0x86, + 0xc1, 0x40, 0xba, 0x0e, 0x6f, 0xee, 0x82, 0x42, 0x8a, 0x23, 0x44, 0x2b, + 0x32, 0x26, 0xd4, 0x14, 0x5d, 0x0c, 0x30, 0x20, 0x10, 0x45, 0x55, 0x26, + 0x57, 0x18, 0x4a, 0x20, 0x00, 0x30, 0x80, 0xc5, 0x10, 0xda, 0xa1, 0x40, + 0x2a, 0x08, 0x6f, 0xec, 0xe2, 0x41, 0x07, 0x71, 0x10, 0xe5, 0xf5, 0x08, + 0x74, 0xb2, 0x40, 0x27, 0x17, 0x24, 0x10, 0xda, 0xa1, 0x40, 0x16, 0x08, + 0x6f, 0xec, 0xc2, 0x41, 0x54, 0x26, 0x8d, 0x1e, 0x4a, 0x20, 0x00, 0x30, + 0x40, 0x24, 0x17, 0x30, 0x10, 0xda, 0xa1, 0x40, 0xfe, 0x0f, 0x2f, 0xec, + 0xe2, 0x41, 0x07, 0x71, 0x10, 0xe5, 0xf5, 0x08, 0xb4, 0xb2, 0x40, 0x27, + 0x17, 0x24, 0x00, 0x8d, 0x09, 0x08, 0xb5, 0x02, 0x04, 0x71, 0x00, 0xad, + 0x41, 0x09, 0x11, 0x30, 0x3d, 0x0c, 0x30, 0x20, 0x55, 0x24, 0x43, 0x3d, + 0x36, 0x40, 0x2f, 0x31, 0xc0, 0x06, 0x2f, 0x32, 0x00, 0x00, 0xc1, 0x40, + 0x36, 0x0d, 0x6f, 0xee, 0x55, 0x24, 0x4d, 0x3d, 0x4a, 0x24, 0xc0, 0x70, + 0x56, 0x26, 0xc1, 0x18, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x15, 0x00, 0x14, + 0x00, 0x30, 0x80, 0x0f, 0x6a, 0x44, 0xfb, 0xae, 0x04, 0x19, 0x10, 0x00, + 0x5e, 0x40, 0x00, 0xa1, 0x4a, 0x24, 0x00, 0x71, 0x0a, 0x20, 0x00, 0x04, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x16, 0x01, 0x24, 0x04, 0x18, 0x50, 0x00, + 0x00, 0x18, 0x40, 0x05, 0x8a, 0x20, 0x04, 0x0b, 0x08, 0x66, 0x0f, 0xe8, + 0x0c, 0x70, 0x04, 0x31, 0x00, 0x80, 0x4b, 0xf7, 0x4a, 0x24, 0x00, 0x71, + 0xa8, 0x20, 0xc0, 0x01, 0x06, 0x40, 0x52, 0x20, 0xc0, 0x07, 0x04, 0x18, + 0x10, 0x20, 0x32, 0x26, 0xc0, 0x14, 0x0d, 0xe8, 0x4a, 0x24, 0x00, 0x71, + 0x56, 0x26, 0xc0, 0x18, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x01, 0x04, + 0x04, 0x1f, 0x50, 0x10, 0x06, 0xf0, 0x0c, 0x70, 0x03, 0xa7, 0x02, 0xa7, + 0x01, 0xa7, 0x00, 0xa7, 0x80, 0x24, 0x03, 0x38, 0x04, 0x14, 0x1b, 0x34, + 0xda, 0xc6, 0xe0, 0x78, 0xea, 0xc3, 0xb0, 0xc1, 0x4a, 0x24, 0xc0, 0x70, + 0xc8, 0x46, 0x0a, 0x21, 0x40, 0x21, 0x70, 0x40, 0x48, 0x40, 0x08, 0x45, + 0x4a, 0x20, 0x00, 0x00, 0x40, 0x24, 0x06, 0x3d, 0x40, 0x24, 0x09, 0x3a, + 0xa8, 0x20, 0x40, 0x05, 0x03, 0x49, 0xf0, 0x20, 0x0c, 0x10, 0x15, 0x26, + 0x02, 0x00, 0x00, 0x33, 0x8b, 0x0f, 0x83, 0x3a, 0x6f, 0x12, 0x15, 0x21, + 0x0f, 0x10, 0x00, 0x34, 0x83, 0x1f, 0x7a, 0x3d, 0x00, 0x00, 0x04, 0x71, + 0x00, 0x1a, 0xc0, 0x02, 0x60, 0xa7, 0x8d, 0xc1, 0x8a, 0xc2, 0x40, 0x24, + 0x05, 0x37, 0xa1, 0x40, 0x02, 0x43, 0xc6, 0x09, 0xef, 0xee, 0x87, 0xc7, + 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, 0xa8, 0x20, 0x40, 0x03, + 0x8a, 0xc1, 0x02, 0x4f, 0x04, 0x49, 0x80, 0xc3, 0x00, 0x32, 0x41, 0x04, + 0x15, 0x7b, 0x01, 0x34, 0x41, 0x10, 0x04, 0x71, 0x20, 0xa3, 0x80, 0xc1, + 0x83, 0xc2, 0xfe, 0x0d, 0xef, 0xee, 0xa1, 0x40, 0x40, 0x25, 0x0f, 0x1b, + 0x83, 0xc1, 0x10, 0xda, 0xa6, 0x0e, 0x2f, 0xec, 0xe1, 0x40, 0x1d, 0x08, + 0x31, 0x20, 0x8d, 0xc0, 0x80, 0xc2, 0xde, 0x0d, 0xaf, 0xee, 0xe1, 0x41, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x53, 0xa5, 0x34, 0xa5, 0x15, 0xa5, + 0x4a, 0x24, 0x00, 0x71, 0x0a, 0x21, 0x80, 0x03, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x17, 0x02, 0x14, 0x04, 0x19, 0x90, 0x00, 0x00, 0x8f, 0x48, 0x30, + 0x00, 0x00, 0x00, 0xa1, 0x0c, 0x8d, 0x0f, 0xe8, 0x0c, 0x70, 0x04, 0x32, + 0x00, 0x80, 0x4b, 0xf7, 0x4a, 0x24, 0x00, 0x71, 0xa8, 0x20, 0xc0, 0x01, + 0x00, 0x86, 0x52, 0x20, 0xc0, 0x07, 0x04, 0x1e, 0x10, 0x10, 0xca, 0xc7, + 0x08, 0x44, 0x6c, 0x70, 0x0c, 0x70, 0x62, 0x4c, 0x04, 0x32, 0x40, 0x80, + 0x4c, 0x70, 0xca, 0x22, 0x6c, 0x00, 0x5b, 0x63, 0xca, 0x20, 0x69, 0x00, + 0x74, 0x73, 0xe0, 0x20, 0xcd, 0x07, 0xf5, 0xea, 0xe0, 0x7e, 0xe0, 0x78, + 0xe6, 0xc0, 0x76, 0x10, 0x8b, 0x00, 0x7f, 0xdd, 0x28, 0x40, 0x48, 0x33, + 0x0b, 0x10, 0x8a, 0x27, 0x09, 0x1d, 0x50, 0x21, 0xfe, 0x87, 0x17, 0xbd, + 0x00, 0x20, 0x8c, 0x0f, 0x00, 0x00, 0x24, 0x02, 0xca, 0x20, 0x41, 0x13, + 0x04, 0x33, 0xc0, 0x90, 0x1f, 0x67, 0x0e, 0xf7, 0x32, 0x24, 0x8b, 0x1f, + 0xff, 0xff, 0xd4, 0xfe, 0x11, 0x0b, 0x31, 0x10, 0x8a, 0x26, 0x04, 0x15, + 0xce, 0x60, 0xdb, 0x0e, 0x30, 0x10, 0xcd, 0x70, 0x60, 0x8f, 0x06, 0xeb, + 0xc3, 0x42, 0x49, 0x40, 0xdb, 0x0f, 0x4d, 0xf0, 0x32, 0x24, 0x83, 0x1f, + 0xff, 0xff, 0xa8, 0xfe, 0x0f, 0xeb, 0x50, 0x22, 0xfe, 0x87, 0xca, 0x22, + 0x41, 0x03, 0x48, 0x32, 0xc2, 0x02, 0x3e, 0x84, 0x15, 0x20, 0x82, 0x00, + 0xa3, 0x12, 0x02, 0x06, 0x01, 0x32, 0x42, 0x00, 0x5e, 0xa4, 0x54, 0x8f, + 0x0e, 0xea, 0x32, 0x24, 0x82, 0x1f, 0xff, 0xff, 0xd4, 0xfe, 0x86, 0xea, + 0x80, 0x20, 0x04, 0x05, 0x00, 0x88, 0x06, 0xe8, 0xc3, 0x40, 0xb2, 0x3d, + 0xc2, 0xb8, 0x1a, 0xa4, 0x48, 0x30, 0xc0, 0x12, 0x35, 0x84, 0x04, 0x77, + 0x48, 0x30, 0x80, 0x00, 0xdf, 0x84, 0x00, 0x30, 0x80, 0x0f, 0x32, 0xbe, + 0xc2, 0xb8, 0x5a, 0x84, 0x01, 0x30, 0x80, 0x0f, 0xb2, 0x3e, 0xc2, 0xb8, + 0x77, 0x84, 0x01, 0x30, 0x40, 0x00, 0x02, 0x35, 0x81, 0x13, 0x01, 0x30, + 0x80, 0x00, 0xc3, 0x42, 0x49, 0x40, 0xdb, 0x0f, 0x00, 0x31, 0xc3, 0x00, + 0x04, 0x30, 0x80, 0x80, 0xca, 0x22, 0x05, 0x00, 0x3e, 0x84, 0x00, 0x36, + 0x80, 0x10, 0x56, 0xa4, 0x01, 0x33, 0x00, 0x00, 0x01, 0x30, 0x42, 0x00, + 0x17, 0xa4, 0xc3, 0x43, 0xb2, 0x3d, 0xc2, 0xb8, 0xc3, 0x41, 0x49, 0x40, + 0xdb, 0x0f, 0x04, 0x32, 0xc0, 0x80, 0x20, 0x40, 0xca, 0x20, 0xc5, 0x00, + 0x04, 0x32, 0x40, 0x80, 0xca, 0x21, 0x05, 0x00, 0x20, 0x40, 0xca, 0x20, + 0x85, 0x00, 0x04, 0x32, 0xc0, 0x80, 0xca, 0x20, 0x45, 0x00, 0x18, 0xa4, + 0xc6, 0xc4, 0x48, 0x33, 0xc2, 0x02, 0x20, 0x8f, 0x14, 0x1f, 0x43, 0x10, + 0xde, 0xa4, 0xf0, 0x26, 0x82, 0x70, 0x13, 0x00, 0xf8, 0x6b, 0xda, 0xa4, + 0x0f, 0x09, 0x71, 0x00, 0x55, 0xa4, 0x80, 0x20, 0x09, 0x0d, 0x2c, 0x70, + 0xc0, 0xa8, 0x18, 0x84, 0x0d, 0x09, 0x31, 0x80, 0x17, 0xa4, 0xaa, 0xf1, + 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x34, 0x50, 0x40, 0x08, 0x47, 0x84, 0xc0, + 0x8a, 0x22, 0x0c, 0x00, 0xd2, 0x0c, 0x2f, 0xec, 0x28, 0x45, 0x00, 0x87, + 0x40, 0x24, 0x83, 0x30, 0x40, 0x24, 0x04, 0x32, 0x40, 0x24, 0x05, 0x33, + 0x40, 0x24, 0x06, 0x31, 0x40, 0x24, 0xc7, 0x30, 0xa1, 0x41, 0x02, 0x42, + 0xde, 0x08, 0x6f, 0xf3, 0x02, 0x1c, 0x43, 0x35, 0x02, 0xc5, 0x9d, 0xed, + 0x03, 0x14, 0x8e, 0x30, 0xad, 0x70, 0x2c, 0x70, 0x97, 0xe9, 0x02, 0x14, + 0x80, 0x30, 0xcf, 0x79, 0x27, 0x08, 0x64, 0x00, 0x84, 0xc2, 0x81, 0xc3, + 0x7a, 0x0a, 0x60, 0x00, 0xe1, 0x40, 0x01, 0xc0, 0x8a, 0x21, 0x3e, 0x06, + 0x12, 0x70, 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, 0x01, 0x20, 0x3d, 0x20, + 0x00, 0x20, 0x1e, 0x66, 0xea, 0xf1, 0xa1, 0x40, 0xc8, 0xc7, 0xe0, 0x78, + 0xf2, 0xc3, 0xb3, 0xc1, 0x0a, 0x25, 0x80, 0x21, 0x0a, 0x26, 0x40, 0x01, + 0x0a, 0x22, 0x00, 0x21, 0x70, 0x41, 0x48, 0x47, 0x30, 0x40, 0x11, 0x0f, + 0xfe, 0x01, 0x08, 0x45, 0x44, 0x27, 0x40, 0x00, 0xcc, 0x1d, 0x02, 0x10, + 0x80, 0x14, 0x0e, 0x30, 0x78, 0x14, 0x13, 0x30, 0x4a, 0x24, 0xc0, 0x70, + 0x4a, 0x20, 0x00, 0x00, 0x54, 0x24, 0x09, 0x38, 0x40, 0x24, 0x08, 0x3d, + 0xa8, 0x20, 0x40, 0x05, 0xf0, 0x20, 0x01, 0x20, 0x02, 0x4f, 0x15, 0x21, + 0x0b, 0x10, 0x00, 0x31, 0x8c, 0x0f, 0x83, 0x3a, 0x6f, 0x12, 0x15, 0x20, + 0x03, 0x10, 0x00, 0x32, 0x81, 0x0f, 0x7a, 0x3d, 0x00, 0x00, 0x04, 0x71, + 0x00, 0x1b, 0x00, 0x13, 0x20, 0xa3, 0x90, 0xc1, 0x8d, 0xc2, 0x40, 0x24, + 0x05, 0x3a, 0x0a, 0x24, 0x80, 0x01, 0xa1, 0x40, 0x42, 0x43, 0x6a, 0x0d, + 0xef, 0xf4, 0x40, 0x24, 0x14, 0x3a, 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, + 0x00, 0x02, 0x86, 0x40, 0x00, 0x30, 0xc0, 0x04, 0x04, 0x1c, 0x10, 0x20, + 0x8d, 0xc1, 0x40, 0x24, 0x04, 0x37, 0xa2, 0x43, 0xa1, 0x40, 0x22, 0x42, + 0x40, 0x24, 0x13, 0x3d, 0xbe, 0x0b, 0x20, 0x00, 0x40, 0x24, 0x14, 0x37, + 0x1e, 0x85, 0x36, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x00, 0x30, 0x80, 0x0f, + 0x74, 0x49, 0x00, 0x24, 0x07, 0x30, 0x4b, 0x00, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0x80, 0x04, 0x8a, 0xc1, 0xf0, 0x23, 0x02, 0x20, 0x01, 0x49, + 0xf0, 0x24, 0x03, 0x20, 0x01, 0x32, 0x4c, 0x00, 0x80, 0xc2, 0x00, 0x33, + 0xc1, 0x10, 0x15, 0x7a, 0x01, 0x34, 0x41, 0x10, 0x04, 0x71, 0x20, 0xa2, + 0x80, 0xc1, 0x83, 0xc2, 0x9e, 0x08, 0x2f, 0xf5, 0xa1, 0x40, 0x5c, 0x4d, + 0x83, 0xc1, 0x10, 0xda, 0x76, 0x0b, 0x2f, 0xec, 0x10, 0x43, 0x1d, 0x0a, + 0x31, 0x20, 0x90, 0xc0, 0x80, 0xc2, 0xae, 0x0a, 0xaf, 0xee, 0x62, 0x41, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x53, 0xa5, 0x34, 0xa5, 0x15, 0xa5, + 0x3e, 0x43, 0x43, 0x87, 0x1e, 0x41, 0x2e, 0x0d, 0xef, 0xff, 0xa1, 0x40, + 0x4a, 0x24, 0x00, 0x71, 0x0a, 0x21, 0x80, 0x03, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x13, 0x02, 0x24, 0x04, 0x19, 0x90, 0x00, 0xa1, 0x15, 0x00, 0x16, + 0x00, 0xa1, 0x0c, 0x8d, 0x0f, 0xe8, 0x4a, 0x20, 0x00, 0x00, 0x04, 0x32, + 0x00, 0x80, 0x4b, 0xf7, 0x4a, 0x24, 0x00, 0x71, 0xa8, 0x20, 0xc0, 0x01, + 0x00, 0x86, 0x52, 0x20, 0xc0, 0x07, 0x04, 0x1e, 0x10, 0x10, 0xd2, 0xc7, + 0xe8, 0xc3, 0xa2, 0xc1, 0x08, 0x45, 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, + 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x50, 0x40, + 0x28, 0x46, 0x55, 0x25, 0x0f, 0x18, 0x7a, 0x0f, 0x2f, 0xf3, 0x03, 0x1c, + 0x43, 0x35, 0x02, 0x14, 0x80, 0x30, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, + 0xed, 0x09, 0x24, 0x00, 0x04, 0x77, 0x67, 0x08, 0x95, 0x02, 0x25, 0x20, + 0x00, 0x00, 0x0b, 0xf0, 0x0b, 0xf0, 0x0d, 0xf0, 0x0d, 0xf0, 0x0f, 0xf0, + 0x0f, 0xf0, 0x17, 0xf0, 0x1d, 0xf0, 0x1f, 0xf0, 0x1f, 0xf0, 0x0c, 0x8d, + 0x0b, 0xf0, 0x05, 0x85, 0x1c, 0xf0, 0x06, 0x85, 0x1a, 0xf0, 0x07, 0x85, + 0x18, 0xf0, 0x08, 0x85, 0x16, 0xf0, 0x24, 0x15, 0x80, 0x10, 0x81, 0xc3, + 0xc1, 0x41, 0x5e, 0x0d, 0x2f, 0xfa, 0x02, 0x42, 0x13, 0xf0, 0x25, 0x15, + 0x80, 0x10, 0x81, 0xc3, 0xc1, 0x41, 0x22, 0x09, 0x2f, 0xf5, 0x02, 0x42, + 0x0b, 0xf0, 0x18, 0x85, 0x04, 0xf0, 0x19, 0x85, 0x02, 0xf0, 0x04, 0x85, + 0x81, 0xc3, 0xc1, 0x41, 0x1e, 0x0f, 0x6f, 0xf7, 0x02, 0x42, 0x02, 0x14, + 0x80, 0x30, 0x6b, 0xb8, 0x71, 0x08, 0xd5, 0x02, 0x25, 0x20, 0x00, 0x00, + 0x0b, 0xf0, 0x0e, 0xf0, 0x0f, 0xf0, 0x12, 0xf0, 0x18, 0xf0, 0x20, 0xf0, + 0x20, 0xf0, 0x22, 0xf0, 0x22, 0xf0, 0x24, 0xf0, 0x24, 0xf0, 0x68, 0x15, + 0x80, 0x10, 0x12, 0xf0, 0x69, 0x15, 0x80, 0x10, 0x06, 0xf0, 0x74, 0x15, + 0x80, 0x10, 0x04, 0xf0, 0x75, 0x15, 0x80, 0x10, 0x81, 0xc3, 0xc1, 0x41, + 0xf2, 0x0c, 0x2f, 0xfa, 0x02, 0x42, 0x1a, 0xf0, 0x76, 0x15, 0x80, 0x10, + 0x81, 0xc3, 0xc1, 0x41, 0xb6, 0x08, 0x2f, 0xf5, 0x02, 0x42, 0x12, 0xf0, + 0x1b, 0x85, 0x0b, 0xf0, 0x01, 0x87, 0x09, 0xf0, 0x02, 0x87, 0x07, 0xf0, + 0x1c, 0x85, 0x05, 0xf0, 0x00, 0x87, 0x03, 0xf0, 0x12, 0x87, 0x81, 0xc3, + 0xc1, 0x41, 0xaa, 0x0e, 0x6f, 0xf7, 0x02, 0x42, 0x02, 0x14, 0x80, 0x30, + 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0x89, 0xf1, 0x01, 0xc0, 0x41, 0x28, + 0x01, 0x02, 0x00, 0xae, 0x21, 0xae, 0xc8, 0xc7, 0xe8, 0xc3, 0xa3, 0xc1, + 0x48, 0x47, 0x28, 0x45, 0x2c, 0x70, 0x10, 0xda, 0x60, 0x40, 0x0a, 0x20, + 0x00, 0x21, 0x1a, 0x08, 0x2f, 0xfa, 0x68, 0x46, 0x2c, 0x70, 0x0a, 0x22, + 0x80, 0x0f, 0x13, 0x00, 0x08, 0x6c, 0x33, 0xed, 0x4a, 0x24, 0x00, 0x71, + 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x03, 0x04, 0x80, 0xc0, 0x3c, 0x60, + 0x24, 0x71, 0x38, 0x23, 0xc0, 0x03, 0x00, 0xac, 0x22, 0x0b, 0x6f, 0xf5, + 0x80, 0xc0, 0x38, 0xe8, 0x0f, 0xdd, 0x0e, 0x1e, 0x43, 0x15, 0x0d, 0x1e, + 0x03, 0x15, 0x0c, 0x1e, 0xc3, 0x14, 0x0b, 0x1e, 0x83, 0x13, 0x0a, 0x1e, + 0x43, 0x13, 0x09, 0x1e, 0xc3, 0x12, 0x08, 0x1e, 0x43, 0x12, 0x07, 0x1e, + 0x03, 0x12, 0x06, 0x1e, 0xc3, 0x11, 0x05, 0x1e, 0x83, 0x11, 0x04, 0x1e, + 0x43, 0x11, 0x03, 0x1e, 0x03, 0x11, 0x02, 0x1e, 0xc3, 0x10, 0x01, 0x1e, + 0x83, 0x10, 0x00, 0x1e, 0x43, 0x10, 0x33, 0x00, 0x00, 0x00, 0x4a, 0x24, + 0x40, 0x71, 0x10, 0xe2, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x03, 0x04, + 0x81, 0xc0, 0x3c, 0x60, 0x24, 0x71, 0x38, 0x23, 0xc0, 0x03, 0x00, 0xac, + 0x1a, 0x0e, 0x6f, 0xf7, 0x81, 0xc0, 0x26, 0xe8, 0xad, 0x71, 0x00, 0x1e, + 0xc3, 0x11, 0x23, 0xf0, 0xad, 0x70, 0x1b, 0x0f, 0xb0, 0x19, 0xb8, 0x66, + 0x19, 0x0f, 0x71, 0x1c, 0xb8, 0x66, 0xa5, 0x72, 0x01, 0x18, 0x83, 0x03, + 0x00, 0x18, 0x43, 0x03, 0x04, 0xf0, 0xa5, 0x71, 0x00, 0x18, 0xc3, 0x02, + 0xbe, 0x08, 0x2f, 0xf7, 0x78, 0x27, 0x00, 0x1c, 0x05, 0xe8, 0xb8, 0x66, + 0xa5, 0x71, 0x00, 0x18, 0x83, 0x01, 0x13, 0x0f, 0x71, 0x1e, 0xbe, 0x66, + 0xa5, 0x71, 0x00, 0x1e, 0x83, 0x12, 0x03, 0xf0, 0xad, 0x70, 0x00, 0x18, + 0x40, 0x23, 0xc8, 0xc7, 0xf0, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x50, 0x44, 0x28, 0x45, 0x5e, 0x0d, 0x2f, 0xf3, 0x03, 0x1c, + 0x03, 0x32, 0x02, 0x14, 0x80, 0x30, 0x55, 0x26, 0x93, 0x1b, 0x55, 0x26, + 0x12, 0x19, 0x54, 0x26, 0x10, 0x18, 0x54, 0x26, 0x8f, 0x19, 0x40, 0x26, + 0x11, 0x1b, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x95, 0x09, 0x24, 0x00, + 0x04, 0x77, 0x53, 0x08, 0x55, 0x01, 0x25, 0x20, 0x00, 0x00, 0x06, 0xf0, + 0x0b, 0xf0, 0x12, 0xf0, 0x18, 0xf0, 0x1b, 0xf0, 0x81, 0xc3, 0x22, 0x40, + 0xa1, 0x41, 0x26, 0x0c, 0x6f, 0xfa, 0x82, 0x42, 0x19, 0xf0, 0x0a, 0x86, + 0x81, 0xc3, 0xa1, 0x41, 0x32, 0x0a, 0x6f, 0xef, 0x82, 0x42, 0x13, 0xf0, + 0x3c, 0x16, 0x80, 0x10, 0x81, 0xc3, 0xa1, 0x41, 0x2e, 0x0b, 0x2f, 0xfa, + 0x82, 0x42, 0x0b, 0xf0, 0x81, 0xc3, 0x02, 0x40, 0x03, 0xf0, 0x81, 0xc3, + 0xe1, 0x40, 0xa1, 0x41, 0x6e, 0x0f, 0x6f, 0xf7, 0x82, 0x42, 0x02, 0x14, + 0x80, 0x30, 0x27, 0x08, 0x30, 0x02, 0x81, 0xc3, 0x11, 0x08, 0xf0, 0x01, + 0x81, 0xc3, 0x25, 0x08, 0xb1, 0x01, 0x81, 0xc3, 0x62, 0x40, 0x0a, 0xf0, + 0x8c, 0x16, 0x80, 0x10, 0xa1, 0x41, 0xf6, 0x0a, 0x2f, 0xfa, 0x82, 0x42, + 0x06, 0xf0, 0x42, 0x40, 0xa1, 0x41, 0xc2, 0x0b, 0x6f, 0xfa, 0x82, 0x42, + 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xb5, 0xf1, + 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xd0, 0xc7, + 0xec, 0xc3, 0xb3, 0xc1, 0x88, 0x47, 0x48, 0x45, 0x30, 0x42, 0x10, 0x41, + 0x2c, 0x70, 0x74, 0x70, 0x22, 0xa7, 0x21, 0xa7, 0x20, 0xa7, 0x26, 0xf4, + 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x21, 0x4e, 0x28, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0xc0, 0x02, 0x02, 0x4d, 0x90, 0xc3, 0x15, 0x7b, 0x00, 0x32, + 0x82, 0x0f, 0xcc, 0x3d, 0xcd, 0xcc, 0x04, 0x71, 0x40, 0xa3, 0x69, 0x11, + 0x80, 0x20, 0x14, 0x70, 0x0c, 0x70, 0x0e, 0xf2, 0x48, 0x16, 0x82, 0x10, + 0x90, 0xc1, 0xc2, 0x0b, 0x20, 0x00, 0x22, 0x40, 0x8a, 0x21, 0x04, 0x05, + 0x74, 0x16, 0x80, 0x10, 0x32, 0x21, 0x41, 0x20, 0x05, 0x20, 0x7e, 0x80, + 0x6a, 0x03, 0x22, 0x00, 0x2c, 0x70, 0x03, 0x85, 0x04, 0x30, 0x40, 0x80, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x76, 0x11, 0x81, 0x20, + 0x48, 0x30, 0xc0, 0x02, 0x0f, 0x78, 0x30, 0x70, 0x3e, 0x03, 0x05, 0x00, + 0x08, 0x8e, 0x0f, 0xe8, 0x68, 0x11, 0x80, 0x20, 0x31, 0x08, 0xb1, 0x00, + 0x08, 0x1e, 0x03, 0x10, 0x40, 0x21, 0x00, 0x2b, 0x90, 0xc1, 0x9a, 0x08, + 0xaf, 0xf2, 0x80, 0xc2, 0x20, 0xf0, 0x75, 0x11, 0x80, 0x20, 0xed, 0x08, + 0x30, 0x00, 0x40, 0x21, 0x0d, 0x2b, 0x55, 0x21, 0x00, 0x29, 0x84, 0xc2, + 0x1a, 0x0f, 0x6f, 0xf2, 0xa1, 0x41, 0x71, 0xf0, 0x55, 0x21, 0x8d, 0x2b, + 0x90, 0xc1, 0x80, 0xc2, 0x6e, 0x08, 0xaf, 0xf2, 0x0a, 0x20, 0x40, 0x03, + 0x4a, 0x24, 0x00, 0x71, 0x40, 0x21, 0x00, 0x2b, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x10, 0x01, 0x04, 0x04, 0x1d, 0x50, 0x10, 0xad, 0x70, 0x80, 0xc0, + 0x6a, 0x0f, 0xef, 0xf3, 0x42, 0xc5, 0x01, 0xc1, 0x7f, 0xda, 0x17, 0xba, + 0x4f, 0x22, 0xcc, 0x07, 0x89, 0x43, 0x04, 0x31, 0x80, 0x80, 0x40, 0x43, + 0xca, 0x24, 0x89, 0x10, 0x04, 0x31, 0xc0, 0x82, 0x20, 0x40, 0xca, 0x23, + 0x05, 0x03, 0x04, 0x31, 0x80, 0x80, 0xca, 0x20, 0xc9, 0x00, 0x04, 0x31, + 0xc0, 0x82, 0x32, 0x0b, 0x6f, 0xf4, 0xca, 0x20, 0xc5, 0x00, 0x08, 0x46, + 0xc3, 0x40, 0x49, 0x40, 0xdb, 0x0f, 0x04, 0x36, 0x00, 0x90, 0x84, 0xf6, + 0x02, 0x30, 0x8e, 0x03, 0x00, 0xc0, 0x43, 0xc0, 0x8e, 0x09, 0x6f, 0xf5, + 0x83, 0xc0, 0x00, 0x36, 0x8e, 0x1f, 0x00, 0x3f, 0x00, 0x00, 0x45, 0xc5, + 0xc1, 0x40, 0x92, 0x0c, 0xaf, 0xf6, 0x44, 0xc5, 0x47, 0xc0, 0xda, 0x09, + 0xef, 0xfa, 0xc1, 0x40, 0x03, 0xc1, 0x75, 0x11, 0x82, 0x20, 0x00, 0x30, + 0x40, 0x00, 0x46, 0xc0, 0x06, 0xea, 0x55, 0x21, 0x00, 0x29, 0x84, 0xc1, + 0x10, 0xda, 0x10, 0xf0, 0x40, 0x21, 0x0d, 0x2b, 0x84, 0xc0, 0x88, 0xc2, + 0x5a, 0x0e, 0x6f, 0xf2, 0xa1, 0x41, 0x88, 0xc0, 0x56, 0x0f, 0x6f, 0xf2, + 0x8c, 0xc1, 0x8c, 0xc1, 0x10, 0xda, 0xa1, 0x40, 0x7a, 0x0e, 0xcf, 0xeb, + 0x29, 0x02, 0x00, 0x00, 0x84, 0xc0, 0x10, 0xda, 0x6e, 0x0e, 0xef, 0xeb, + 0xa1, 0x41, 0x68, 0x11, 0x90, 0x20, 0x84, 0xc0, 0x90, 0xc1, 0x92, 0x0f, + 0x6f, 0xf2, 0x80, 0xc2, 0x19, 0x08, 0xb0, 0x20, 0x4a, 0x24, 0x00, 0x71, + 0x55, 0x21, 0x80, 0x2b, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x15, 0x01, 0x14, + 0x04, 0x18, 0x50, 0x00, 0x80, 0xc0, 0xad, 0x70, 0x8a, 0x0e, 0xef, 0xf3, + 0x08, 0x1c, 0x01, 0x30, 0x01, 0xc0, 0x00, 0xc1, 0x04, 0x30, 0x40, 0x83, + 0x48, 0xc1, 0x45, 0xf7, 0xea, 0x08, 0x6f, 0xf5, 0x88, 0xc0, 0x40, 0x21, + 0x00, 0x2b, 0xbe, 0x0b, 0x6f, 0xf2, 0x84, 0xc1, 0x84, 0xc0, 0xce, 0x0b, + 0x6f, 0xf2, 0xe1, 0x41, 0x08, 0xc2, 0x4a, 0x24, 0xc0, 0x70, 0xe1, 0x40, + 0xa8, 0x20, 0xc0, 0x01, 0x20, 0x80, 0x00, 0x32, 0x41, 0x00, 0x04, 0x18, + 0x50, 0x00, 0x74, 0x11, 0x80, 0x20, 0x30, 0xe8, 0x4a, 0x24, 0xc0, 0x70, + 0x4c, 0x70, 0x42, 0x43, 0x0c, 0x70, 0x43, 0xc2, 0xa8, 0x20, 0x00, 0x02, + 0x04, 0x13, 0x01, 0x04, 0x00, 0x31, 0x41, 0x00, 0x01, 0x30, 0x40, 0x00, + 0x04, 0x30, 0x80, 0x8f, 0x61, 0x44, 0x00, 0x00, 0x43, 0xc0, 0xc6, 0xf6, + 0x00, 0x30, 0x82, 0x0f, 0xbc, 0x38, 0x62, 0xbe, 0x7f, 0xd8, 0x17, 0xb8, + 0x04, 0x32, 0x00, 0x80, 0x6c, 0x11, 0x03, 0x20, 0xca, 0x20, 0x85, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x00, 0x30, 0x01, 0x00, 0xa8, 0x20, 0x40, 0x02, + 0x00, 0x87, 0x00, 0x33, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x04, 0x1f, + 0x10, 0x10, 0xa8, 0xf0, 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x21, 0x0d, 0x2d, + 0xa1, 0x40, 0xe1, 0x42, 0xa8, 0x20, 0x40, 0x02, 0x60, 0x80, 0x04, 0x12, + 0x01, 0x04, 0x01, 0x31, 0xc1, 0x00, 0x04, 0x18, 0x50, 0x00, 0x7a, 0x0f, + 0xef, 0xf9, 0xa1, 0x40, 0xd3, 0x40, 0xc8, 0x42, 0x00, 0x00, 0x04, 0x30, + 0x00, 0x84, 0xda, 0xf6, 0x02, 0x85, 0x40, 0x85, 0x21, 0x85, 0x42, 0xc0, + 0xa1, 0x40, 0x40, 0xc2, 0x5a, 0x0f, 0xef, 0xf9, 0x41, 0xc1, 0x4a, 0x24, + 0xc0, 0x70, 0x80, 0xc1, 0xa1, 0x42, 0x43, 0xc0, 0xa8, 0x20, 0x80, 0x02, + 0x04, 0x11, 0x03, 0x04, 0x07, 0x33, 0x03, 0x00, 0x00, 0x33, 0x03, 0x04, + 0x04, 0x1a, 0xd0, 0x00, 0x7c, 0x11, 0x00, 0x20, 0x08, 0xc1, 0x48, 0x86, + 0x7c, 0x8e, 0x00, 0x30, 0x41, 0x00, 0x02, 0x36, 0x00, 0x70, 0x80, 0x3f, + 0x00, 0x00, 0x00, 0x30, 0x80, 0x00, 0x01, 0x30, 0x42, 0x00, 0x48, 0xa6, + 0x08, 0xeb, 0x00, 0x86, 0x50, 0x22, 0xc1, 0x07, 0x43, 0xc2, 0x04, 0x31, + 0x00, 0x80, 0x16, 0xf6, 0x4a, 0x24, 0xc0, 0x70, 0x0c, 0x70, 0x4a, 0x44, + 0x0c, 0x1c, 0x01, 0x30, 0xa8, 0x20, 0x00, 0x02, 0x04, 0x14, 0x01, 0x14, + 0x00, 0x31, 0x41, 0x00, 0x01, 0x30, 0x40, 0x00, 0x31, 0x86, 0x43, 0xc0, + 0x04, 0x30, 0x40, 0x80, 0x3e, 0x00, 0x0c, 0x00, 0x21, 0x85, 0x70, 0x11, + 0x0c, 0x20, 0x40, 0x85, 0x08, 0x15, 0x00, 0x10, 0x6c, 0x11, 0x0b, 0x20, + 0x4a, 0x24, 0xc0, 0x70, 0x41, 0xc1, 0x80, 0xc1, 0x43, 0xc4, 0x40, 0xc2, + 0x42, 0xc0, 0xa8, 0x20, 0x80, 0x03, 0x04, 0x11, 0x00, 0x04, 0x40, 0x87, + 0x00, 0x30, 0x03, 0x03, 0x00, 0x33, 0x80, 0x10, 0x01, 0x30, 0xc0, 0x00, + 0x04, 0x1f, 0x10, 0x10, 0x2e, 0xf0, 0xa9, 0xeb, 0x01, 0x86, 0x50, 0x22, + 0xc1, 0x07, 0x04, 0x31, 0x00, 0x80, 0x46, 0x00, 0x2c, 0x00, 0x43, 0xc2, + 0x21, 0x85, 0x70, 0x11, 0x0c, 0x20, 0x40, 0x85, 0x08, 0x15, 0x00, 0x10, + 0x6c, 0x11, 0x0b, 0x20, 0x4a, 0x24, 0xc0, 0x70, 0xa0, 0x19, 0x43, 0x20, + 0x41, 0xc1, 0x80, 0xc1, 0x43, 0xc4, 0x40, 0xc2, 0x42, 0xc0, 0xa8, 0x20, + 0x80, 0x03, 0x04, 0x11, 0x00, 0x04, 0x40, 0x87, 0x00, 0x30, 0x03, 0x03, + 0x00, 0x33, 0x80, 0x10, 0x01, 0x30, 0xc0, 0x00, 0x04, 0x1f, 0x10, 0x10, + 0x06, 0xf0, 0x0c, 0x70, 0x1c, 0xae, 0x02, 0xa7, 0x01, 0xa7, 0x00, 0xa7, + 0xf9, 0x11, 0x80, 0x20, 0x83, 0xe8, 0xf9, 0x19, 0x43, 0x20, 0x68, 0x11, + 0x80, 0x20, 0x39, 0x08, 0xb0, 0x00, 0x55, 0x21, 0x8d, 0x2a, 0x36, 0x43, + 0x58, 0x11, 0x02, 0x20, 0x40, 0x24, 0x04, 0x3c, 0x42, 0x41, 0x42, 0x0e, + 0x6f, 0xf2, 0xa1, 0x40, 0x8c, 0xc1, 0x10, 0xda, 0x22, 0x0c, 0xef, 0xeb, + 0xa1, 0x40, 0x8c, 0xc1, 0xea, 0x0c, 0x6f, 0xf2, 0xa1, 0x40, 0x8c, 0xc1, + 0x10, 0xda, 0x12, 0x0c, 0xef, 0xeb, 0xa1, 0x40, 0xcc, 0xc7, 0xe0, 0x78, + 0xf0, 0xc3, 0xa4, 0xc1, 0x55, 0x20, 0xce, 0x0d, 0x30, 0x40, 0x10, 0x41, + 0x32, 0x86, 0x65, 0x16, 0x00, 0x16, 0x50, 0x42, 0xad, 0x71, 0xfe, 0x0a, + 0x6f, 0xfa, 0x1c, 0x1e, 0x43, 0x10, 0x04, 0x71, 0x65, 0x1e, 0x18, 0x10, + 0x80, 0xc1, 0x02, 0x40, 0xb6, 0x08, 0x2f, 0xfa, 0x80, 0xc7, 0x00, 0xc1, + 0xa0, 0x4f, 0xb5, 0x72, 0xad, 0x72, 0x01, 0x31, 0x01, 0x00, 0xbc, 0xf7, + 0x65, 0x16, 0x0f, 0x16, 0x4a, 0x24, 0xc0, 0x70, 0x0c, 0x70, 0x52, 0x6f, + 0x42, 0x22, 0x03, 0x01, 0xa8, 0x20, 0x80, 0x02, 0xf0, 0x20, 0x0c, 0x20, + 0x15, 0x21, 0xcb, 0x20, 0x04, 0x71, 0x64, 0x71, 0x4a, 0x1b, 0x18, 0x13, + 0x2f, 0x34, 0x40, 0x10, 0x8a, 0x23, 0x09, 0x0b, 0x22, 0x73, 0x20, 0x8b, + 0x15, 0x21, 0x80, 0x20, 0x49, 0x18, 0x18, 0x03, 0x8e, 0xe9, 0x63, 0x16, + 0x00, 0x16, 0x32, 0x86, 0x0d, 0x09, 0x23, 0x00, 0x2c, 0x71, 0x00, 0x1b, + 0x43, 0x00, 0x06, 0xf0, 0x04, 0x71, 0x2c, 0x70, 0x63, 0x1e, 0x18, 0x10, + 0x34, 0x70, 0x92, 0xf2, 0xb2, 0x86, 0x10, 0x86, 0x09, 0x20, 0x50, 0x03, + 0x17, 0x0f, 0x23, 0x14, 0x42, 0x20, 0x54, 0x20, 0x29, 0x0f, 0x21, 0x15, + 0x2c, 0x71, 0xf1, 0x44, 0xb1, 0x43, 0xa1, 0x43, 0x18, 0xf0, 0xbf, 0x67, + 0x02, 0x27, 0x00, 0x14, 0x04, 0x71, 0xa1, 0x41, 0x56, 0x0a, 0x6f, 0xfa, + 0x6e, 0x71, 0x65, 0x16, 0x0f, 0x16, 0x00, 0x41, 0x6c, 0x72, 0x0c, 0xf0, + 0xb8, 0x67, 0x02, 0x20, 0x00, 0x04, 0x04, 0x71, 0x3e, 0x0a, 0x6f, 0xfa, + 0xa1, 0x41, 0x00, 0x43, 0x2c, 0x71, 0xb1, 0x43, 0x48, 0x30, 0x90, 0x20, + 0x48, 0x34, 0x82, 0x20, 0x7f, 0xd8, 0x17, 0xb8, 0x07, 0x30, 0x05, 0x04, + 0x07, 0x30, 0x86, 0x00, 0x56, 0x21, 0x40, 0x29, 0x40, 0x24, 0x07, 0x30, + 0x0a, 0x24, 0xc0, 0x04, 0x02, 0x0c, 0x20, 0x00, 0xe1, 0x42, 0x0b, 0x0a, + 0x10, 0x20, 0x20, 0x86, 0x02, 0xf0, 0x21, 0x86, 0xae, 0x0c, 0xaf, 0xff, + 0x80, 0xc0, 0x65, 0x16, 0x01, 0x16, 0x62, 0x86, 0x8d, 0x70, 0x04, 0xb9, + 0x22, 0x71, 0x49, 0x11, 0x02, 0x06, 0x89, 0x43, 0x04, 0x32, 0xc0, 0x80, + 0x87, 0xf7, 0x23, 0x86, 0x6d, 0x70, 0x04, 0x32, 0x40, 0x80, 0x03, 0xf6, + 0x6d, 0x71, 0x8b, 0xe8, 0x13, 0x0b, 0x10, 0x10, 0x06, 0x86, 0xe1, 0x68, + 0xe4, 0xe7, 0xc3, 0xf6, 0x64, 0xdf, 0xe6, 0xa6, 0x03, 0xf0, 0x86, 0xa6, + 0xed, 0x70, 0xf9, 0x11, 0x80, 0x20, 0x06, 0xe8, 0x13, 0x0a, 0x10, 0x20, + 0x28, 0x86, 0x08, 0xf0, 0x22, 0x40, 0x80, 0x20, 0x04, 0x05, 0x80, 0xa8, + 0x21, 0xf0, 0x29, 0x86, 0x52, 0x0c, 0xaf, 0xff, 0x80, 0xc0, 0x07, 0xe8, + 0x22, 0x40, 0x80, 0x20, 0x04, 0x05, 0x00, 0x18, 0x43, 0x00, 0x2d, 0x0b, + 0x30, 0x10, 0xad, 0x70, 0x2a, 0x86, 0x3a, 0x0c, 0xaf, 0xff, 0x80, 0xc0, + 0x14, 0x70, 0x0c, 0x70, 0x03, 0xf4, 0x0d, 0x86, 0x04, 0x71, 0x2c, 0x86, + 0x13, 0x08, 0x62, 0x00, 0x0d, 0xa6, 0x22, 0x40, 0x80, 0x20, 0x04, 0x05, + 0xa0, 0xa8, 0x03, 0xf0, 0xad, 0xa6, 0x05, 0x86, 0x09, 0x0f, 0x02, 0x10, + 0xf8, 0x19, 0x03, 0x20, 0xd0, 0xc7, 0xe0, 0x78, 0x8d, 0x00, 0xc0, 0x02, + 0x8a, 0x24, 0x01, 0x74, 0x8a, 0x23, 0x04, 0x05, 0x55, 0x20, 0x42, 0x0f, + 0x2c, 0x70, 0x56, 0x20, 0x4c, 0x09, 0x1b, 0x63, 0x20, 0xa2, 0x27, 0xa2, + 0x22, 0xb2, 0x20, 0xab, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1c, 0x11, 0x10, + 0x80, 0x20, 0x09, 0x0b, 0x5f, 0x1a, 0x58, 0x00, 0x20, 0xa4, 0xe0, 0x7f, + 0x20, 0xa8, 0xe0, 0x78, 0xe8, 0xc2, 0x68, 0x45, 0x48, 0x46, 0x30, 0x40, + 0x2a, 0x0e, 0xaf, 0xf4, 0x08, 0x47, 0x42, 0x20, 0xc0, 0x22, 0x31, 0x08, + 0xf5, 0x02, 0x55, 0x27, 0x10, 0x18, 0x25, 0x20, 0x00, 0x00, 0x0c, 0xf0, + 0x11, 0xf0, 0x18, 0xf0, 0x1d, 0xf0, 0x24, 0xf0, 0x29, 0xf0, 0x2f, 0xf0, + 0x34, 0xf0, 0x3b, 0xf0, 0x3f, 0xf0, 0x46, 0xf0, 0xc1, 0x40, 0x66, 0x08, + 0xef, 0xf4, 0xa1, 0x41, 0x68, 0x1f, 0x02, 0x10, 0xc8, 0xc6, 0xc1, 0x40, + 0x82, 0x0c, 0xef, 0xf9, 0xa1, 0x41, 0x69, 0x1f, 0x02, 0x10, 0xc8, 0xc6, + 0xc1, 0x40, 0x76, 0x0c, 0xef, 0xf9, 0xa1, 0x41, 0x74, 0x1f, 0x02, 0x10, + 0xc8, 0xc6, 0xc1, 0x40, 0x66, 0x0c, 0xef, 0xf9, 0xa1, 0x41, 0x75, 0x1f, + 0x02, 0x10, 0xc8, 0xc6, 0xc1, 0x40, 0x2e, 0x08, 0xef, 0xf4, 0xa1, 0x41, + 0x76, 0x1f, 0x02, 0x10, 0xc8, 0xc6, 0xc1, 0x40, 0x22, 0x0e, 0x2f, 0xf7, + 0xa1, 0x41, 0x1b, 0xa7, 0xc8, 0xc6, 0xc1, 0x40, 0x16, 0x0e, 0x2f, 0xf7, + 0xa1, 0x41, 0x04, 0x18, 0x00, 0x20, 0xc8, 0xc6, 0xc1, 0x40, 0x0a, 0x0e, + 0x2f, 0xf7, 0xa1, 0x41, 0x08, 0x18, 0x00, 0x20, 0xc8, 0xc6, 0xc1, 0x40, + 0xfa, 0x0d, 0x2f, 0xf7, 0xa1, 0x41, 0x1c, 0xa7, 0xc8, 0xc6, 0xc1, 0x40, + 0xee, 0x0d, 0x2f, 0xf7, 0xa1, 0x41, 0x00, 0x18, 0x00, 0x20, 0xc8, 0xc6, + 0xc1, 0x40, 0xe2, 0x0d, 0x2f, 0xf7, 0xa1, 0x41, 0x48, 0x18, 0x00, 0x20, + 0xc8, 0xc6, 0xe0, 0x78, 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x34, 0x50, 0x40, + 0x08, 0x47, 0x84, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0x3a, 0x09, 0xef, 0xeb, + 0x28, 0x45, 0x00, 0x87, 0x40, 0x24, 0x83, 0x30, 0x40, 0x24, 0x04, 0x32, + 0x40, 0x24, 0x05, 0x33, 0x40, 0x24, 0x06, 0x31, 0x40, 0x24, 0xc7, 0x30, + 0xa1, 0x41, 0x02, 0x42, 0x46, 0x0d, 0xef, 0xf2, 0x02, 0x1c, 0x03, 0x32, + 0x02, 0xc5, 0x9d, 0xed, 0x03, 0x14, 0x8e, 0x30, 0xad, 0x70, 0x2c, 0x70, + 0x97, 0xe9, 0x02, 0x14, 0x80, 0x30, 0xcf, 0x79, 0x27, 0x08, 0x64, 0x00, + 0x84, 0xc2, 0x81, 0xc3, 0x26, 0x08, 0x20, 0x00, 0xe1, 0x40, 0x01, 0xc0, + 0x8a, 0x21, 0x3e, 0x06, 0x12, 0x70, 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, + 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, 0x1e, 0x66, 0xea, 0xf1, 0xa1, 0x40, + 0xc8, 0xc7, 0xe0, 0x78, 0xe8, 0xc3, 0xa4, 0xc1, 0x68, 0x45, 0x48, 0x46, + 0x28, 0x47, 0x72, 0x0d, 0xaf, 0xf4, 0x10, 0x40, 0x21, 0x0f, 0x30, 0x12, + 0x80, 0xc2, 0x33, 0x0f, 0xf0, 0x11, 0xc1, 0x40, 0x29, 0x0f, 0xb1, 0x11, + 0x80, 0xc2, 0xc1, 0x40, 0x26, 0x0c, 0x2f, 0xfa, 0xa1, 0x41, 0x55, 0x20, + 0x80, 0x2b, 0x08, 0xf0, 0xc1, 0x40, 0x1a, 0x0c, 0x2f, 0xfa, 0xa1, 0x41, + 0x55, 0x20, 0x00, 0x29, 0x80, 0xc1, 0x96, 0x08, 0xef, 0xeb, 0x10, 0xda, + 0xc8, 0xc7, 0x3e, 0x0b, 0xef, 0xf9, 0xa1, 0x41, 0x8c, 0x18, 0x02, 0x20, + 0xc8, 0xc7, 0xe0, 0x78, 0xe6, 0xc2, 0x48, 0x31, 0x03, 0x00, 0x22, 0x92, + 0xc3, 0x42, 0x48, 0x47, 0x00, 0x00, 0x07, 0x32, 0xcb, 0x00, 0x55, 0x20, + 0x8d, 0x0a, 0x48, 0x31, 0x01, 0x00, 0x08, 0x46, 0x07, 0x32, 0x4c, 0x00, + 0xd8, 0x15, 0x00, 0x90, 0x7f, 0xdf, 0x17, 0xbf, 0x00, 0x30, 0x80, 0x0f, + 0xc8, 0x42, 0x00, 0x00, 0xc3, 0x43, 0x83, 0x3a, 0x6f, 0x12, 0x2d, 0x70, + 0x07, 0x36, 0xc8, 0x72, 0xf4, 0x49, 0x00, 0x24, 0x07, 0x37, 0x02, 0x13, + 0x07, 0x30, 0x01, 0x03, 0x11, 0x85, 0x3c, 0x1e, 0x43, 0x10, 0xe4, 0x1d, + 0x43, 0x90, 0x48, 0x30, 0x80, 0x00, 0x00, 0x34, 0x00, 0x10, 0x00, 0x30, + 0xc0, 0x00, 0x04, 0x1e, 0x00, 0x12, 0x04, 0x30, 0x40, 0x82, 0x5e, 0xa6, + 0x3f, 0xa6, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x38, 0x85, + 0x48, 0x30, 0xc2, 0x02, 0x48, 0x31, 0x81, 0x00, 0x00, 0x34, 0x40, 0x10, + 0x48, 0x32, 0x81, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x48, 0x31, 0xc1, 0x02, + 0x04, 0x30, 0x40, 0x82, 0x32, 0xa5, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0x3e, 0x85, 0x48, 0x30, 0xc2, 0x02, 0x0d, 0x70, 0x48, 0x31, + 0x81, 0x00, 0x00, 0x34, 0x40, 0x10, 0x48, 0x32, 0x81, 0x00, 0x00, 0x30, + 0xc0, 0x00, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, 0x00, 0x82, 0x39, 0xa5, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x3c, 0x85, 0x48, 0x30, + 0xc2, 0x02, 0x48, 0x31, 0x81, 0x00, 0x00, 0x34, 0x40, 0x10, 0x48, 0x32, + 0x81, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, + 0x00, 0x82, 0x3d, 0xa5, 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, + 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, + 0x48, 0x30, 0xc0, 0x02, 0x4a, 0x24, 0xc0, 0x70, 0x48, 0x30, 0x80, 0x00, + 0xc3, 0x41, 0x13, 0x00, 0x2c, 0x6c, 0x48, 0x30, 0xc0, 0x02, 0x49, 0x20, + 0x00, 0x05, 0x48, 0x20, 0x80, 0x00, 0x1f, 0xa5, 0x0a, 0x20, 0x80, 0x03, + 0x80, 0x20, 0x0a, 0x04, 0xa8, 0x20, 0x00, 0x02, 0x04, 0x11, 0x02, 0x04, + 0x07, 0x32, 0xc2, 0x02, 0x04, 0x18, 0x90, 0x00, 0x07, 0x36, 0xc0, 0x72, + 0x80, 0xbf, 0x00, 0x00, 0x07, 0x30, 0x80, 0x0f, 0x72, 0x3f, 0x22, 0xb0, + 0x16, 0x0e, 0x8f, 0xfd, 0x02, 0x37, 0x00, 0x10, 0x7e, 0x1d, 0x18, 0x10, + 0xc6, 0x0c, 0xef, 0xff, 0xc1, 0x40, 0xc6, 0xc6, 0xf4, 0xc3, 0xa4, 0xc1, + 0x40, 0x29, 0x96, 0x00, 0x42, 0x26, 0x13, 0x21, 0x50, 0x41, 0x28, 0x47, + 0x08, 0x45, 0x15, 0x20, 0xc1, 0x04, 0x80, 0xc0, 0x10, 0xda, 0x0a, 0x20, + 0xc0, 0x21, 0x0a, 0x25, 0x80, 0x21, 0x0a, 0x24, 0x40, 0x21, 0x0a, 0x22, + 0x00, 0x21, 0xde, 0x0e, 0xaf, 0xeb, 0x68, 0x46, 0x2f, 0x0f, 0x63, 0x14, + 0x15, 0x25, 0x82, 0x15, 0xe1, 0x41, 0x4a, 0x24, 0x00, 0x71, 0x0a, 0x24, + 0x80, 0x10, 0x80, 0xc0, 0xa8, 0x20, 0x40, 0x02, 0x60, 0x80, 0x04, 0x14, + 0x0b, 0x14, 0x01, 0x33, 0xc3, 0x10, 0x04, 0x18, 0xd0, 0x00, 0x24, 0x71, + 0xe3, 0x09, 0x62, 0x84, 0x10, 0xe2, 0x33, 0x0a, 0xa2, 0x23, 0x34, 0x6e, + 0xb9, 0x61, 0xc1, 0x42, 0x70, 0xb9, 0x4a, 0x24, 0x00, 0x71, 0x80, 0xc0, + 0x0a, 0x24, 0x40, 0x10, 0xa8, 0x20, 0x40, 0x02, 0x60, 0x80, 0x04, 0x14, + 0x0b, 0x14, 0x01, 0x33, 0xc3, 0x10, 0x04, 0x18, 0xd0, 0x00, 0x10, 0xe1, + 0x52, 0x72, 0x44, 0x71, 0xaf, 0xf6, 0x4a, 0x24, 0x00, 0x71, 0x8d, 0x70, + 0x40, 0x24, 0x0b, 0x30, 0xa8, 0x20, 0xc0, 0x04, 0x15, 0x23, 0x01, 0x13, + 0x00, 0x81, 0xf0, 0x25, 0xc2, 0x14, 0x15, 0x20, 0x03, 0x23, 0x00, 0x30, + 0x00, 0x05, 0x85, 0x71, 0x02, 0x32, 0x02, 0x00, 0x66, 0x71, 0x00, 0x32, + 0x82, 0x00, 0x00, 0xa1, 0x40, 0xa3, 0x37, 0x0f, 0x63, 0x14, 0x4a, 0x24, + 0x00, 0x71, 0x0c, 0x70, 0x15, 0x20, 0xc2, 0x03, 0xa8, 0x20, 0x40, 0x04, + 0x80, 0xc1, 0x43, 0x4d, 0x01, 0x49, 0x15, 0x20, 0x0c, 0x20, 0x04, 0x71, + 0x02, 0x33, 0x41, 0x00, 0x60, 0x84, 0x00, 0x31, 0x41, 0x00, 0x44, 0x71, + 0x01, 0x33, 0x41, 0x00, 0x20, 0xa4, 0xe5, 0x71, 0xe7, 0xf1, 0x39, 0x0a, + 0x82, 0x23, 0x4a, 0x24, 0x00, 0x71, 0x12, 0x6e, 0x6c, 0x68, 0x2c, 0x70, + 0xa8, 0x20, 0x40, 0x04, 0x80, 0xc0, 0x62, 0x4d, 0x20, 0x48, 0x15, 0x20, + 0x4c, 0x20, 0x24, 0x71, 0x02, 0x32, 0x00, 0x00, 0x40, 0x84, 0x00, 0x30, + 0x00, 0x00, 0x64, 0x71, 0x01, 0x32, 0x00, 0x00, 0x00, 0xa4, 0x52, 0x76, + 0xc5, 0x71, 0xa9, 0xf6, 0x4a, 0x24, 0x00, 0x71, 0xa8, 0x20, 0xc0, 0x01, + 0x06, 0x40, 0x00, 0x30, 0x40, 0x05, 0x04, 0x18, 0x10, 0x20, 0xd4, 0xc7, + 0xe4, 0xc2, 0x49, 0x68, 0x4f, 0x7d, 0x9f, 0x25, 0x02, 0x13, 0xcb, 0x44, + 0xa0, 0x00, 0xcc, 0x49, 0x20, 0x43, 0xba, 0x64, 0xd1, 0x82, 0x54, 0x24, + 0x82, 0x1a, 0x59, 0x65, 0x42, 0x6e, 0x40, 0xb1, 0x0f, 0x78, 0xc3, 0x44, + 0x13, 0x00, 0xfc, 0x4c, 0x6a, 0x0b, 0x2f, 0xf8, 0x4c, 0x74, 0xc4, 0xc6, + 0xe6, 0xc2, 0x42, 0x81, 0x08, 0x45, 0x04, 0x80, 0x00, 0x32, 0x82, 0x0f, + 0x4c, 0x3d, 0xd0, 0xcc, 0x00, 0x30, 0x80, 0x0f, 0x73, 0x3f, 0x33, 0x33, + 0x01, 0x30, 0x80, 0x00, 0x01, 0x30, 0x82, 0x0f, 0x7a, 0xc4, 0x00, 0x00, + 0x04, 0xa5, 0xbf, 0xba, 0x00, 0x81, 0x04, 0x32, 0x80, 0x8f, 0x37, 0x42, + 0x86, 0x8c, 0x43, 0x85, 0x61, 0x81, 0x82, 0x85, 0x02, 0xa5, 0x02, 0x33, + 0x8e, 0x00, 0x02, 0x30, 0x0f, 0x03, 0x01, 0x81, 0xbf, 0xbe, 0xbf, 0xbf, + 0x03, 0xa5, 0x85, 0xf7, 0xb2, 0x0a, 0x6f, 0xef, 0xa1, 0x40, 0x04, 0x8d, + 0x01, 0x37, 0x82, 0x13, 0x33, 0x08, 0xb0, 0x00, 0xcd, 0x70, 0x4b, 0x08, + 0x50, 0x00, 0xa7, 0x08, 0x11, 0x00, 0x14, 0x8d, 0x04, 0x32, 0x80, 0x8f, + 0xf4, 0x41, 0x5d, 0xbb, 0x04, 0x71, 0x0f, 0x78, 0x49, 0x20, 0x81, 0x0c, + 0x8e, 0x00, 0x2c, 0x00, 0x34, 0xad, 0x85, 0x08, 0x94, 0x0c, 0xd4, 0xad, + 0x04, 0x1d, 0x43, 0x10, 0x3f, 0xf0, 0x17, 0x8d, 0x04, 0x71, 0x0f, 0x79, + 0x31, 0x09, 0xf4, 0x02, 0x17, 0xad, 0x19, 0x8d, 0x69, 0x08, 0x95, 0x01, + 0xd9, 0xad, 0xd7, 0xad, 0xc4, 0xad, 0x81, 0xde, 0x31, 0xf0, 0x15, 0x8d, + 0x04, 0x32, 0x80, 0x8f, 0xf4, 0x41, 0x5d, 0xbb, 0x41, 0x68, 0x55, 0xad, + 0xd0, 0xf6, 0x18, 0x8d, 0xd6, 0xad, 0x04, 0x71, 0x18, 0xad, 0x1f, 0xf0, + 0x04, 0x32, 0x80, 0x8f, 0xf4, 0x41, 0x5d, 0xbb, 0x3e, 0x00, 0x0c, 0x00, + 0x19, 0x8d, 0x04, 0x71, 0x19, 0xad, 0x1b, 0xf0, 0x16, 0x8d, 0x04, 0x71, + 0x0f, 0x79, 0x23, 0x09, 0xb4, 0x01, 0x16, 0xad, 0x18, 0x8d, 0x15, 0x08, + 0xf4, 0x02, 0xa1, 0x40, 0xd8, 0xad, 0xd5, 0xad, 0x04, 0x1d, 0x83, 0x10, + 0xd6, 0xad, 0x0b, 0xf0, 0x0a, 0x0a, 0x4f, 0xef, 0x55, 0x8d, 0x4f, 0x78, + 0xe5, 0xe0, 0x85, 0xf7, 0xfe, 0x09, 0x6f, 0xef, 0xa1, 0x40, 0xc1, 0x40, + 0xc6, 0xc6, 0xe0, 0x78, 0x00, 0x42, 0x02, 0x80, 0x04, 0x30, 0x40, 0x80, + 0x0c, 0x70, 0xe0, 0x20, 0xce, 0x07, 0x03, 0x82, 0x04, 0x30, 0x40, 0x80, + 0xca, 0xf7, 0x44, 0x82, 0xc3, 0x40, 0x40, 0x40, 0x00, 0x00, 0x04, 0x32, + 0x40, 0x80, 0xe0, 0x7f, 0xd0, 0x20, 0xae, 0x05, 0x7f, 0xd8, 0xe0, 0x7f, + 0x17, 0xb8, 0xe0, 0x78, 0xea, 0xc3, 0x82, 0x24, 0x0c, 0x37, 0x50, 0x40, + 0x08, 0x47, 0x87, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0x4e, 0x0c, 0xaf, 0xeb, + 0x28, 0x45, 0x00, 0x87, 0x40, 0x24, 0x83, 0x33, 0x40, 0x24, 0x04, 0x35, + 0x40, 0x24, 0x05, 0x36, 0x40, 0x24, 0x06, 0x34, 0x40, 0x24, 0xc7, 0x33, + 0xa1, 0x41, 0x02, 0x42, 0x5a, 0x08, 0xef, 0xf2, 0x0e, 0x1c, 0x03, 0x31, + 0x05, 0xc5, 0xbd, 0xed, 0x0f, 0x14, 0x8e, 0x30, 0xad, 0x70, 0x8a, 0x21, + 0x3e, 0x26, 0x2c, 0x70, 0xb5, 0xe9, 0x0e, 0x14, 0x81, 0x30, 0xcf, 0x78, + 0x63, 0x09, 0x04, 0x00, 0x23, 0x08, 0x30, 0x01, 0x84, 0xc1, 0x29, 0x08, + 0xb0, 0x00, 0x84, 0xc1, 0x37, 0x08, 0xf0, 0x00, 0x84, 0xc1, 0x3b, 0x08, + 0x71, 0x00, 0x87, 0xc0, 0x76, 0x0a, 0xaf, 0xf4, 0x84, 0xc1, 0x04, 0xaf, + 0x15, 0xf0, 0x6e, 0x0a, 0xaf, 0xf4, 0x87, 0xc0, 0x15, 0xaf, 0x11, 0xf0, + 0x87, 0xc0, 0x62, 0x0a, 0x6f, 0xf8, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, + 0x02, 0xc0, 0x42, 0xa7, 0x23, 0xa7, 0x04, 0xa7, 0x05, 0xf0, 0x4e, 0x0a, + 0xaf, 0xf4, 0x87, 0xc0, 0x14, 0xaf, 0x04, 0xc0, 0x12, 0x70, 0x3c, 0x20, + 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, 0xca, 0x25, 0x4d, 0x14, 0x1e, 0x66, + 0xcc, 0xf1, 0xa1, 0x40, 0xca, 0xc7, 0xe0, 0x78, 0xf2, 0xc3, 0xac, 0xc1, + 0x17, 0xc7, 0x50, 0x45, 0x30, 0x42, 0x08, 0x46, 0x2c, 0x70, 0x24, 0xda, + 0xe1, 0x40, 0xe8, 0x45, 0x0a, 0x20, 0x80, 0x21, 0x0a, 0x21, 0x40, 0x21, + 0x0a, 0x23, 0x00, 0x21, 0xca, 0x09, 0xaf, 0xf9, 0x70, 0x44, 0x04, 0x8e, + 0x13, 0x08, 0x3f, 0x00, 0x14, 0xda, 0x15, 0x08, 0x7f, 0x00, 0x80, 0xc0, + 0x14, 0xda, 0x62, 0x41, 0x07, 0xf0, 0x80, 0xc0, 0xa2, 0x41, 0x05, 0xf0, + 0x80, 0xc0, 0x14, 0xda, 0x82, 0x41, 0x62, 0x0b, 0x8f, 0xeb, 0x04, 0xc1, + 0xce, 0x0e, 0xef, 0xff, 0xc1, 0x40, 0x44, 0xc0, 0x80, 0xc0, 0xee, 0x08, + 0x2f, 0xf2, 0x88, 0xc1, 0x88, 0xc0, 0xfe, 0x08, 0x2f, 0xf2, 0x85, 0xc1, + 0x04, 0x8e, 0x23, 0x08, 0x3f, 0x01, 0x4a, 0x24, 0x40, 0x71, 0x2b, 0x08, + 0x7f, 0x01, 0x4a, 0x24, 0x40, 0x71, 0x33, 0x08, 0xbf, 0x01, 0x80, 0xc1, + 0x14, 0xda, 0x2a, 0x0b, 0xaf, 0xeb, 0xa1, 0x40, 0x21, 0xf0, 0xa1, 0x40, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x15, 0x01, 0x24, 0x04, 0x18, 0x50, 0x00, + 0x14, 0xf0, 0xa1, 0x40, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x14, 0x01, 0x24, + 0x04, 0x18, 0x50, 0x00, 0x0c, 0xf0, 0x4a, 0x24, 0x40, 0x71, 0x62, 0x41, + 0x0a, 0x20, 0x40, 0x03, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x02, 0x04, + 0x04, 0x18, 0x90, 0x00, 0x24, 0x85, 0x5e, 0x0e, 0xef, 0xff, 0xc1, 0x40, + 0x04, 0xa5, 0x18, 0xc1, 0x4a, 0x24, 0x40, 0x71, 0x0a, 0x20, 0x40, 0x03, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x02, 0x04, 0x04, 0x1f, 0x90, 0x10, + 0x15, 0x8e, 0x4a, 0x24, 0x40, 0x71, 0x0a, 0xe8, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x13, 0x00, 0x24, 0x04, 0x19, 0x10, 0x00, 0x11, 0x00, 0x00, 0x00, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x15, 0x00, 0x14, 0x04, 0x19, 0x10, 0x00, + 0x04, 0xc2, 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, 0x85, 0xc3, + 0x0c, 0x19, 0x80, 0x20, 0xa8, 0x20, 0x80, 0x04, 0x01, 0x4b, 0x15, 0x21, + 0x0c, 0x20, 0x20, 0xa4, 0xf0, 0x22, 0x0c, 0x20, 0x00, 0x31, 0x8b, 0x0f, + 0x7a, 0xc4, 0x00, 0x00, 0x15, 0x20, 0x01, 0x20, 0x01, 0x34, 0xcc, 0x12, + 0x04, 0x71, 0x80, 0xa1, 0x0c, 0x18, 0x80, 0x20, 0xd2, 0xc7, 0xe0, 0x78, + 0xe8, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, + 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, + 0x28, 0x45, 0xda, 0x0e, 0xaf, 0xf2, 0x03, 0x1c, 0x03, 0x31, 0x02, 0x14, + 0x80, 0x30, 0x40, 0x26, 0x10, 0x12, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, + 0x49, 0x09, 0x04, 0x00, 0x1d, 0x08, 0x10, 0x01, 0x1d, 0x08, 0xb0, 0x00, + 0x81, 0xc3, 0x25, 0x08, 0xd0, 0x00, 0x2d, 0x08, 0x71, 0x00, 0x81, 0xc3, + 0x04, 0x8e, 0xe1, 0x42, 0xa1, 0x41, 0x0e, 0xf0, 0x15, 0x8e, 0x09, 0xf0, + 0x02, 0x40, 0xa1, 0x41, 0xb2, 0x08, 0x6f, 0xf8, 0xe1, 0x42, 0x08, 0xf0, + 0x14, 0x8e, 0x81, 0xc3, 0xa1, 0x41, 0xe1, 0x42, 0x92, 0x08, 0x8f, 0xf4, + 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xdb, 0xf1, + 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc8, 0xc7, + 0xe8, 0xc3, 0xa1, 0xc1, 0x60, 0x40, 0x48, 0x45, 0x28, 0x46, 0x2c, 0x70, + 0x10, 0xda, 0x88, 0x47, 0x1a, 0x08, 0xaf, 0xf9, 0x70, 0x40, 0xd5, 0x70, + 0xcd, 0x70, 0x2b, 0xf2, 0x4a, 0x24, 0xc0, 0x70, 0xc3, 0x42, 0x13, 0x00, + 0x44, 0x6c, 0x0c, 0x70, 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x12, 0x03, 0x04, + 0x40, 0x24, 0x41, 0x30, 0x1c, 0x61, 0x04, 0x71, 0x38, 0x23, 0x41, 0x03, + 0x20, 0xac, 0x52, 0x08, 0x6f, 0xf6, 0x40, 0x24, 0x40, 0x30, 0x06, 0xe8, + 0xcd, 0x71, 0x00, 0x18, 0x43, 0x20, 0x11, 0xf0, 0x13, 0x0d, 0x10, 0x1f, + 0x15, 0x0d, 0xd0, 0x1e, 0x17, 0x0d, 0x91, 0x1b, 0x00, 0x18, 0x83, 0x20, + 0x06, 0xf0, 0x00, 0x18, 0x03, 0x21, 0x04, 0xf0, 0x00, 0x18, 0xc3, 0x20, + 0xcd, 0x71, 0xc0, 0xa7, 0xc8, 0xc7, 0xe0, 0x78, 0xf1, 0xc0, 0xa3, 0xc1, + 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, + 0x40, 0x24, 0xc6, 0x32, 0xe6, 0x0d, 0xaf, 0xf2, 0x03, 0x1c, 0x03, 0x30, + 0x01, 0xc0, 0xa3, 0xc0, 0xd1, 0xc0, 0xe0, 0x7e, 0x4a, 0x24, 0xc0, 0x70, + 0x98, 0x48, 0xc3, 0x42, 0x13, 0x00, 0x38, 0x6c, 0x04, 0x18, 0x43, 0x00, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x12, 0x03, 0x04, 0x04, 0x19, 0xd0, 0x00, + 0x15, 0x18, 0x03, 0x00, 0xe0, 0x7f, 0x00, 0x19, 0x03, 0x00, 0xe0, 0x78, + 0xf1, 0xc0, 0xa4, 0xc1, 0x00, 0x80, 0x40, 0x24, 0x83, 0x31, 0x40, 0x24, + 0x04, 0x30, 0x40, 0x24, 0x05, 0x33, 0x40, 0x24, 0x06, 0x32, 0x40, 0x24, + 0xc7, 0x31, 0x3a, 0x0d, 0xaf, 0xf2, 0x06, 0x1c, 0x03, 0x30, 0x00, 0xc0, + 0xa4, 0xc0, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xe0, 0x7e, 0xe0, 0x78, + 0xe6, 0xc0, 0x34, 0x10, 0x8c, 0x00, 0x55, 0x20, 0x8d, 0x0e, 0x0c, 0xea, + 0x0d, 0x0c, 0xd1, 0x10, 0x40, 0x8d, 0x25, 0x0a, 0xb5, 0x00, 0xc9, 0x6a, + 0xcd, 0x70, 0x00, 0x1d, 0x03, 0x10, 0x0d, 0xf0, 0x40, 0x8d, 0xea, 0x10, + 0x8e, 0x00, 0x44, 0x71, 0x4f, 0x7f, 0x0d, 0x0f, 0x85, 0x13, 0x48, 0x46, + 0x40, 0xad, 0x03, 0xf0, 0xc0, 0xad, 0xe9, 0x10, 0x82, 0x00, 0x08, 0xe9, + 0x21, 0x0a, 0xb5, 0x00, 0xad, 0x70, 0xe9, 0x18, 0x03, 0x00, 0x0f, 0xf0, + 0xea, 0x10, 0x8d, 0x00, 0x21, 0x6a, 0x2f, 0x7a, 0x0f, 0x0a, 0x45, 0x03, + 0x28, 0x45, 0xe9, 0x18, 0x42, 0x00, 0x05, 0xf0, 0xa9, 0x6a, 0xe9, 0x18, + 0x42, 0x03, 0xea, 0x10, 0x8b, 0x00, 0xcf, 0x79, 0x31, 0x09, 0xc5, 0x02, + 0x0d, 0x0c, 0xd1, 0x10, 0xeb, 0x10, 0x82, 0x00, 0x25, 0x09, 0x85, 0x00, + 0xaf, 0x7a, 0x2f, 0x0a, 0xc5, 0x02, 0x0f, 0x0c, 0x94, 0x10, 0xeb, 0x10, + 0x81, 0x00, 0x23, 0x0a, 0x45, 0x00, 0x29, 0x6c, 0x15, 0x09, 0x53, 0x00, + 0x2c, 0x71, 0x34, 0x18, 0x43, 0x00, 0x12, 0xf0, 0x21, 0x6c, 0x2f, 0x7a, + 0x11, 0x0b, 0x84, 0x00, 0x34, 0x18, 0x42, 0x00, 0x0a, 0xf0, 0x11, 0x0b, + 0xf5, 0x00, 0x2c, 0x72, 0x34, 0x18, 0xc2, 0x00, 0x60, 0x41, 0x04, 0xf0, + 0x34, 0x18, 0x83, 0x00, 0x2f, 0x79, 0x13, 0x09, 0x05, 0x03, 0x11, 0x0c, + 0x90, 0x10, 0x0b, 0x0c, 0xd1, 0x10, 0xe8, 0x18, 0x03, 0x00, 0xc6, 0xc4, + 0xe8, 0x18, 0x05, 0x00, 0xc6, 0xc4, 0xe0, 0x78, 0xec, 0xc3, 0xa1, 0xc1, + 0x55, 0x20, 0x4e, 0x09, 0xfc, 0x80, 0x83, 0x86, 0x4a, 0x24, 0xc0, 0x70, + 0x08, 0x45, 0x20, 0x40, 0x70, 0x41, 0x50, 0x40, 0x40, 0x24, 0x41, 0x30, + 0x0a, 0x22, 0x00, 0x20, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x10, 0x02, 0x04, + 0x04, 0x32, 0x00, 0x83, 0x6f, 0x22, 0x0b, 0x00, 0x01, 0x19, 0x92, 0x00, + 0x42, 0x0d, 0xef, 0xf3, 0x40, 0x24, 0x40, 0x30, 0x33, 0xe8, 0x64, 0x86, + 0xfd, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x0c, 0x70, 0x0a, 0x21, 0x80, 0x04, + 0xa8, 0x20, 0x40, 0x03, 0x04, 0x11, 0x0b, 0x04, 0x40, 0x24, 0x42, 0x30, + 0x1c, 0x62, 0x04, 0x33, 0xc0, 0x90, 0x04, 0x71, 0x6f, 0x22, 0x0b, 0x00, + 0x40, 0xac, 0x12, 0x0d, 0xef, 0xf3, 0x40, 0x24, 0x40, 0x30, 0x1b, 0xe8, + 0x45, 0x86, 0xfe, 0x85, 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0x40, 0x03, 0x04, 0x12, 0x0c, 0x24, 0x40, 0x24, 0x41, 0x30, + 0x1b, 0x61, 0x04, 0x34, 0x80, 0x90, 0x04, 0x71, 0x6f, 0x21, 0x0b, 0x00, + 0x20, 0xab, 0xe2, 0x0c, 0xef, 0xf3, 0x40, 0x24, 0x40, 0x30, 0x03, 0xe8, + 0xff, 0x85, 0x41, 0x86, 0x16, 0x86, 0x7d, 0x85, 0x02, 0x37, 0x81, 0x10, + 0x00, 0x30, 0x41, 0x00, 0x17, 0x86, 0x01, 0x32, 0x41, 0x00, 0x5c, 0x85, + 0x00, 0x30, 0xcc, 0x00, 0x04, 0x37, 0x40, 0x90, 0x21, 0xa6, 0xca, 0x21, + 0xc5, 0x03, 0x04, 0x31, 0x00, 0x83, 0x48, 0x43, 0xd0, 0xf6, 0x9e, 0x85, + 0x00, 0x30, 0x0b, 0x03, 0x04, 0x31, 0xc0, 0x82, 0x68, 0x43, 0xca, 0xf6, + 0x7f, 0x85, 0x89, 0x43, 0x00, 0x30, 0xc0, 0x00, 0x04, 0x31, 0x00, 0x80, + 0xc2, 0xf6, 0x68, 0x43, 0x02, 0x86, 0x7f, 0xdb, 0x17, 0xbb, 0x07, 0x30, + 0x80, 0x00, 0x07, 0x33, 0x81, 0x00, 0x01, 0x30, 0xc0, 0x00, 0x04, 0x30, + 0x40, 0x80, 0xca, 0x21, 0x05, 0x00, 0x07, 0x33, 0x42, 0x00, 0x61, 0x40, + 0x20, 0xa6, 0x04, 0x32, 0xc0, 0x82, 0xca, 0x20, 0x89, 0x00, 0x00, 0x18, + 0x00, 0x20, 0x02, 0x86, 0x01, 0x33, 0x00, 0x10, 0x04, 0x30, 0xc0, 0x80, + 0xca, 0x20, 0xc9, 0x00, 0x04, 0x30, 0xc0, 0x80, 0x02, 0xa6, 0x05, 0xf4, + 0x00, 0x19, 0xc3, 0x20, 0xcc, 0xc7, 0x04, 0x30, 0x80, 0x8f, 0x00, 0x3f, + 0x00, 0x00, 0x45, 0xf6, 0x00, 0x19, 0x43, 0x20, 0xcc, 0xc7, 0x00, 0x19, + 0x83, 0x20, 0xcc, 0xc7, 0xea, 0xc3, 0x82, 0x24, 0x0c, 0x38, 0x50, 0x40, + 0x08, 0x45, 0x88, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0xc6, 0x0e, 0x6f, 0xeb, + 0x28, 0x46, 0x00, 0x85, 0x40, 0x24, 0x83, 0x30, 0x40, 0x24, 0x04, 0x32, + 0x40, 0x24, 0x05, 0x37, 0x40, 0x24, 0x06, 0x31, 0x40, 0x24, 0xc7, 0x30, + 0xc1, 0x41, 0x02, 0x42, 0xd2, 0x0a, 0xaf, 0xf2, 0x02, 0x1c, 0x03, 0x33, + 0x02, 0xc6, 0xd5, 0x70, 0x7b, 0xf4, 0x03, 0x14, 0x8f, 0x30, 0x55, 0x25, + 0x11, 0x18, 0xcd, 0x70, 0x2c, 0x70, 0xeb, 0x09, 0x31, 0x00, 0xef, 0x78, + 0x02, 0x14, 0x81, 0x30, 0xdf, 0x09, 0x24, 0x00, 0x04, 0x77, 0xc3, 0x08, + 0x15, 0x03, 0x25, 0x20, 0x00, 0x00, 0x0d, 0xf0, 0x12, 0xf0, 0x18, 0xf0, + 0x1c, 0xf0, 0x22, 0xf0, 0x26, 0xf0, 0x2c, 0xf0, 0x30, 0xf0, 0x3b, 0xf0, + 0x40, 0xf0, 0x47, 0xf0, 0x4c, 0xf0, 0x88, 0xc0, 0xea, 0x09, 0xef, 0xf5, + 0x81, 0xc1, 0x90, 0x1d, 0x04, 0x10, 0x4b, 0xf0, 0x88, 0xc0, 0xd6, 0x0a, + 0xef, 0xf6, 0x81, 0xc1, 0x0c, 0xa5, 0x45, 0xf0, 0x88, 0xc0, 0xca, 0x0a, + 0xef, 0xf6, 0x81, 0xc1, 0x14, 0xa5, 0x3f, 0xf0, 0x88, 0xc0, 0xbe, 0x0a, + 0xef, 0xf6, 0x81, 0xc1, 0x15, 0xa5, 0x39, 0xf0, 0x88, 0xc0, 0xb2, 0x0a, + 0xef, 0xf6, 0x81, 0xc1, 0x18, 0xa5, 0x33, 0xf0, 0x88, 0xc0, 0xa6, 0x0a, + 0xef, 0xf6, 0x81, 0xc1, 0x19, 0xa5, 0x2d, 0xf0, 0x88, 0xc0, 0x9a, 0x0a, + 0xef, 0xf6, 0x81, 0xc1, 0x1a, 0xa5, 0x27, 0xf0, 0x88, 0xc0, 0x81, 0xc1, + 0x32, 0x0e, 0x20, 0x05, 0x83, 0xc2, 0x83, 0xc1, 0x10, 0xda, 0xfa, 0x0d, + 0x6f, 0xeb, 0x22, 0x40, 0x1b, 0xf0, 0x88, 0xc0, 0x76, 0x0a, 0xef, 0xf6, + 0x81, 0xc1, 0xac, 0x1d, 0x00, 0x10, 0x15, 0xf0, 0x88, 0xc0, 0x66, 0x0c, + 0x6f, 0xf4, 0x81, 0xc1, 0x6d, 0x1d, 0x02, 0x10, 0x0d, 0xf0, 0x88, 0xc0, + 0x5a, 0x0a, 0xef, 0xf6, 0x81, 0xc1, 0xcc, 0x1d, 0x00, 0x10, 0x07, 0xf0, + 0x88, 0xc0, 0x4e, 0x0a, 0xef, 0xf6, 0x81, 0xc1, 0x0b, 0xa5, 0x01, 0xc0, + 0x8a, 0x21, 0x3e, 0x06, 0x12, 0x70, 0xca, 0x26, 0x4d, 0x10, 0x3c, 0x20, + 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, 0x1f, 0x67, 0x8d, 0xf1, 0xc1, 0x40, + 0xca, 0xc7, 0xe0, 0x78, 0xee, 0xc3, 0xad, 0xc1, 0xa8, 0x47, 0x0a, 0x20, + 0x00, 0x21, 0x30, 0x41, 0x08, 0x46, 0x13, 0x0a, 0xfe, 0x01, 0x00, 0x1d, + 0x03, 0x00, 0x0c, 0x71, 0x46, 0x78, 0x36, 0x1e, 0x02, 0x10, 0x0f, 0x0b, + 0xfe, 0x01, 0x0c, 0x71, 0x66, 0x78, 0x35, 0x1e, 0x02, 0x10, 0x78, 0x4e, + 0x40, 0x24, 0xc2, 0x32, 0x8a, 0xc3, 0x3e, 0x08, 0xaf, 0xfe, 0x22, 0x41, + 0x36, 0x16, 0x80, 0x10, 0x08, 0xe8, 0x35, 0x16, 0x80, 0x10, 0x06, 0xe8, + 0x0b, 0x14, 0x80, 0x30, 0x6e, 0x71, 0x03, 0xe8, 0x6e, 0x70, 0x40, 0x26, + 0x0d, 0x17, 0x87, 0xc1, 0xa1, 0x40, 0xae, 0x0e, 0xaf, 0xf4, 0x40, 0x24, + 0x12, 0x37, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x24, 0x41, 0x36, 0xa8, 0x20, + 0x80, 0x03, 0x04, 0x12, 0x02, 0x24, 0x0c, 0x70, 0x04, 0x32, 0x80, 0x8f, + 0x00, 0x47, 0x00, 0x00, 0xca, 0x20, 0x69, 0x00, 0x01, 0x19, 0x12, 0x00, + 0xf6, 0x0b, 0xef, 0xf3, 0x40, 0x24, 0x40, 0x36, 0x07, 0xe8, 0x0c, 0x70, + 0x02, 0xa5, 0x01, 0xa5, 0x00, 0xa5, 0x34, 0x1e, 0x02, 0x10, 0x76, 0x70, + 0x00, 0x02, 0x21, 0x00, 0x8a, 0xc1, 0x81, 0xc2, 0x40, 0x24, 0x83, 0x32, + 0xc1, 0x40, 0xda, 0x0c, 0xef, 0xff, 0x40, 0x24, 0x12, 0x3a, 0x4a, 0x24, + 0xc0, 0x70, 0x0c, 0x70, 0xa8, 0x20, 0x40, 0x03, 0x15, 0x26, 0x01, 0x10, + 0xf0, 0x21, 0x03, 0x20, 0x21, 0x81, 0x15, 0x22, 0x02, 0x20, 0x04, 0x71, + 0x02, 0x33, 0x41, 0x00, 0x20, 0xa2, 0x01, 0xc4, 0x4a, 0x24, 0xc0, 0x70, + 0x04, 0x6e, 0x8a, 0xc2, 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x12, 0x01, 0x04, + 0x60, 0x80, 0x00, 0x34, 0x41, 0x10, 0x01, 0x33, 0x41, 0x00, 0x04, 0x18, + 0x50, 0x00, 0x2a, 0x16, 0x80, 0x10, 0x54, 0x96, 0x04, 0x71, 0x0f, 0x79, + 0x50, 0x71, 0xa0, 0x01, 0x25, 0x00, 0x2a, 0x1e, 0x02, 0x10, 0x4a, 0x24, + 0xc0, 0x70, 0x2c, 0x70, 0x2a, 0x1e, 0x03, 0x10, 0xa8, 0x20, 0x00, 0x03, + 0x15, 0x26, 0x40, 0x10, 0x44, 0x80, 0x01, 0x80, 0x8a, 0xc3, 0x35, 0x7b, + 0x02, 0x30, 0x80, 0x00, 0x24, 0x71, 0x00, 0xa3, 0x8a, 0xc0, 0x87, 0xc1, + 0xda, 0x0d, 0xaf, 0xf4, 0x40, 0x24, 0x11, 0x37, 0x3f, 0x86, 0x01, 0xc0, + 0x4a, 0x24, 0xc0, 0x70, 0x4c, 0x70, 0x07, 0x30, 0x41, 0x00, 0x0c, 0x86, + 0x02, 0x1c, 0x82, 0x30, 0x03, 0x1c, 0x82, 0x30, 0x00, 0x31, 0x0c, 0x00, + 0xa8, 0x20, 0x80, 0x03, 0x04, 0x11, 0x03, 0x24, 0x0c, 0x70, 0x40, 0x24, + 0x41, 0x36, 0x04, 0x33, 0x00, 0x83, 0x59, 0x61, 0x44, 0x71, 0xca, 0x20, + 0x6a, 0x00, 0x00, 0xa9, 0x0e, 0x0b, 0xef, 0xf3, 0x40, 0x24, 0x40, 0x36, + 0xbb, 0x08, 0x30, 0x00, 0x4c, 0x70, 0xb0, 0x16, 0x00, 0x10, 0x7f, 0xdc, + 0x17, 0xbc, 0x01, 0x30, 0x01, 0x03, 0x2c, 0x16, 0x0b, 0x10, 0xc3, 0x40, + 0x20, 0x41, 0x00, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x04, 0x31, 0x00, 0x80, + 0xca, 0x20, 0x45, 0x00, 0x40, 0x24, 0x08, 0x37, 0xb0, 0x1e, 0x00, 0x10, + 0xa8, 0x20, 0x80, 0x03, 0x04, 0x10, 0x09, 0x14, 0x2c, 0x70, 0x40, 0x24, + 0x43, 0x36, 0x04, 0x31, 0xc0, 0x92, 0x5b, 0x63, 0x44, 0x71, 0xca, 0x21, + 0x69, 0x00, 0x20, 0xab, 0x07, 0x34, 0x11, 0x10, 0xc3, 0x40, 0xcc, 0x3e, + 0xcd, 0xcc, 0x04, 0x31, 0x00, 0xa0, 0xca, 0x21, 0x05, 0x20, 0xaa, 0x0a, + 0xef, 0xf3, 0x40, 0x24, 0x40, 0x36, 0x8a, 0xc2, 0x2b, 0xe8, 0x5e, 0x08, + 0xef, 0xf5, 0x8a, 0xc0, 0x6b, 0x86, 0x4a, 0x24, 0xc0, 0x70, 0x83, 0xc4, + 0x87, 0xc2, 0x83, 0xc1, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x00, 0x04, + 0x04, 0x33, 0x00, 0x80, 0xca, 0x20, 0xc5, 0x00, 0x04, 0x19, 0x10, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, 0xa8, 0x20, 0x00, 0x04, + 0x8a, 0xc1, 0x01, 0x49, 0x15, 0x26, 0x02, 0x10, 0x03, 0x4c, 0x00, 0x31, + 0x4b, 0x20, 0x24, 0x82, 0x00, 0x33, 0xc3, 0x10, 0x04, 0x71, 0x01, 0x31, + 0xc1, 0x00, 0x24, 0xa2, 0x11, 0xf0, 0x2c, 0x70, 0x25, 0xf0, 0x4a, 0x24, + 0xc0, 0x70, 0x28, 0x4e, 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x12, 0x01, 0x04, + 0x60, 0x80, 0x00, 0x31, 0x41, 0x20, 0x01, 0x33, 0x41, 0x00, 0x04, 0x18, + 0x50, 0x00, 0x40, 0x24, 0x81, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x92, 0x0c, + 0x20, 0x00, 0xc1, 0x40, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x26, 0x00, 0x14, + 0xa8, 0x20, 0x40, 0x01, 0x04, 0x10, 0x01, 0x04, 0x22, 0xa0, 0x03, 0x14, + 0x82, 0x30, 0x02, 0x14, 0x81, 0x30, 0x80, 0xd8, 0x00, 0xaf, 0x0a, 0x14, + 0x83, 0x30, 0x34, 0x16, 0x91, 0x10, 0x2e, 0x0a, 0xef, 0xff, 0xc1, 0x40, + 0x34, 0x16, 0x80, 0x10, 0x0d, 0x09, 0x00, 0x20, 0x00, 0x8f, 0x87, 0xb8, + 0x00, 0x1f, 0x02, 0x10, 0x2a, 0x1e, 0x03, 0x10, 0x4a, 0x24, 0xc0, 0x70, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x15, 0x00, 0x14, 0x04, 0x18, 0x10, 0x20, + 0x34, 0x16, 0x80, 0x10, 0x48, 0x30, 0x00, 0x00, 0x00, 0x18, 0x00, 0x20, + 0xce, 0xc7, 0xe0, 0x78, 0xe8, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, 0x56, 0x0f, 0x6f, 0xf2, 0x03, 0x1c, + 0x03, 0x33, 0x02, 0x14, 0x80, 0x30, 0x55, 0x26, 0x10, 0x18, 0x03, 0x14, + 0x81, 0x30, 0x0f, 0x78, 0x91, 0x09, 0x24, 0x00, 0x04, 0x77, 0x81, 0x08, + 0x15, 0x03, 0x25, 0x20, 0x00, 0x00, 0x0d, 0xf0, 0x13, 0xf0, 0x15, 0xf0, + 0x15, 0xf0, 0x17, 0xf0, 0x17, 0xf0, 0x19, 0xf0, 0x19, 0xf0, 0x20, 0xf0, + 0x21, 0xf0, 0x29, 0xf0, 0x2a, 0xf0, 0x90, 0x16, 0x00, 0x11, 0x81, 0xc3, + 0xa1, 0x41, 0x2e, 0x0e, 0xaf, 0xf5, 0xe1, 0x42, 0x28, 0xf0, 0x0c, 0x86, + 0x21, 0xf0, 0x14, 0x86, 0x1f, 0xf0, 0x15, 0x86, 0x1d, 0xf0, 0x18, 0x86, + 0x1b, 0xf0, 0x19, 0x86, 0x19, 0xf0, 0x1a, 0x86, 0x17, 0xf0, 0x81, 0xc3, + 0x02, 0x40, 0xa1, 0x41, 0xae, 0x0a, 0x20, 0x05, 0xe1, 0x42, 0x16, 0xf0, + 0xac, 0x16, 0x00, 0x10, 0x0d, 0xf0, 0x6d, 0x16, 0x80, 0x10, 0x81, 0xc3, + 0xa1, 0x41, 0xde, 0x08, 0x6f, 0xf4, 0xe1, 0x42, 0x0a, 0xf0, 0xcc, 0x16, + 0x00, 0x10, 0x03, 0xf0, 0x0b, 0x86, 0x81, 0xc3, 0xa1, 0x41, 0xde, 0x0e, + 0xaf, 0xf6, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, + 0x02, 0x30, 0xb7, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, + 0x21, 0xad, 0xc8, 0xc7, 0xe8, 0xc3, 0xa1, 0xc1, 0x50, 0x40, 0x28, 0x45, + 0x2c, 0x70, 0x10, 0xda, 0x60, 0x40, 0x88, 0x46, 0x4e, 0x08, 0x6f, 0xf9, + 0x68, 0x47, 0xb5, 0x70, 0xad, 0x70, 0x2f, 0xf4, 0x4a, 0x24, 0x00, 0x71, + 0xc3, 0x42, 0x13, 0x00, 0x50, 0x6c, 0x0c, 0x70, 0xa8, 0x20, 0x80, 0x02, + 0x04, 0x12, 0x03, 0x04, 0x80, 0xc1, 0x1c, 0x61, 0x04, 0x71, 0x38, 0x23, + 0x01, 0x04, 0x20, 0xac, 0x56, 0x0b, 0xaf, 0xf4, 0x80, 0xc0, 0x1b, 0xe8, + 0x0c, 0xdd, 0x0b, 0x1f, 0xc3, 0x13, 0x0a, 0x1f, 0x83, 0x13, 0x09, 0x1f, + 0x43, 0x13, 0x08, 0x1f, 0x03, 0x13, 0x07, 0x1f, 0xc3, 0x12, 0x06, 0x1f, + 0x83, 0x12, 0x05, 0x1f, 0x43, 0x12, 0x04, 0x1f, 0x03, 0x12, 0x03, 0x1f, + 0xc3, 0x11, 0x02, 0x1f, 0x03, 0x11, 0x01, 0x1f, 0x83, 0x10, 0x00, 0x1f, + 0x43, 0x10, 0xa0, 0xa6, 0xc8, 0xc7, 0xe0, 0x78, 0xf2, 0xc3, 0xa2, 0xc1, + 0x08, 0x45, 0x04, 0x15, 0x00, 0x14, 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, + 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x46, 0x30, 0x45, + 0x0a, 0x0e, 0x6f, 0xf2, 0x03, 0x1c, 0xc3, 0x33, 0x02, 0x14, 0x80, 0x30, + 0x40, 0x25, 0x10, 0x13, 0x55, 0x25, 0x11, 0x1b, 0x55, 0x25, 0xd2, 0x1b, + 0x55, 0x25, 0xd3, 0x1c, 0x55, 0x25, 0x94, 0x1d, 0x40, 0x25, 0x0f, 0x16, + 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0xaf, 0x09, 0x24, 0x00, 0x04, 0x77, + 0x9b, 0x08, 0xd5, 0x03, 0x25, 0x20, 0x00, 0x00, 0x0f, 0xf0, 0x12, 0xf0, + 0x13, 0xf0, 0x16, 0xf0, 0x17, 0xf0, 0x1a, 0xf0, 0x1b, 0xf0, 0x1e, 0xf0, + 0x1f, 0xf0, 0x22, 0xf0, 0x23, 0xf0, 0x26, 0xf0, 0x2b, 0xf0, 0x2e, 0xf0, + 0x34, 0xf0, 0x81, 0xc3, 0xe1, 0x40, 0x22, 0xf0, 0x30, 0x15, 0x80, 0x10, + 0x28, 0xf0, 0x26, 0x15, 0x80, 0x10, 0x26, 0xf0, 0x81, 0xc3, 0xa1, 0x40, + 0x18, 0xf0, 0x31, 0x15, 0x80, 0x10, 0x20, 0xf0, 0x32, 0x15, 0x80, 0x10, + 0x1c, 0xf0, 0x98, 0x15, 0x00, 0x10, 0x22, 0xf0, 0x81, 0xc3, 0x02, 0x40, + 0x0c, 0xf0, 0x81, 0xc3, 0x22, 0x40, 0x0a, 0xf0, 0x81, 0xc3, 0x42, 0x40, + 0x06, 0xf0, 0x81, 0xc3, 0x62, 0x40, 0x04, 0xf0, 0x81, 0xc3, 0x82, 0x40, + 0xa2, 0x41, 0xf6, 0x0f, 0xaf, 0xf6, 0xc1, 0x42, 0x13, 0xf0, 0xe4, 0x15, + 0x80, 0x10, 0x04, 0xf0, 0xe5, 0x15, 0x80, 0x10, 0x81, 0xc3, 0xa2, 0x41, + 0x5e, 0x0f, 0x2f, 0xf4, 0xc1, 0x42, 0x09, 0xf0, 0xac, 0x15, 0x00, 0x10, + 0x81, 0xc3, 0xa2, 0x41, 0x62, 0x0d, 0xaf, 0xf6, 0xc1, 0x42, 0x02, 0x14, + 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xa8, 0xf1, 0x01, 0xc0, + 0x41, 0x28, 0x01, 0x02, 0x00, 0x1d, 0x02, 0x20, 0x01, 0x1d, 0x42, 0x20, + 0xd2, 0xc7, 0xe0, 0x78, 0x2d, 0x00, 0x40, 0x02, 0xf0, 0xc3, 0x82, 0x24, + 0x0c, 0x37, 0x50, 0x42, 0x08, 0x45, 0x87, 0xc0, 0x8a, 0x22, 0x0c, 0x00, + 0x86, 0x08, 0x6f, 0xeb, 0x28, 0x46, 0x00, 0x85, 0x40, 0x24, 0x83, 0x33, + 0x40, 0x24, 0x04, 0x35, 0x40, 0x24, 0x05, 0x36, 0x40, 0x24, 0x06, 0x34, + 0x40, 0x24, 0xc7, 0x33, 0xc1, 0x41, 0x42, 0x42, 0x92, 0x0c, 0x6f, 0xf2, + 0x0e, 0x1c, 0xc3, 0x33, 0x14, 0x14, 0x11, 0x30, 0x36, 0x70, 0xcb, 0xf4, + 0x0f, 0x14, 0x8e, 0x30, 0x55, 0x25, 0x54, 0x1b, 0x55, 0x25, 0x13, 0x1c, + 0x55, 0x25, 0x10, 0x1d, 0x55, 0x25, 0xcf, 0x1d, 0x2e, 0x70, 0x2c, 0x70, + 0x34, 0x70, 0xbd, 0xf4, 0x0e, 0x14, 0x81, 0x30, 0xcf, 0x78, 0x30, 0x70, + 0x6e, 0x01, 0x2d, 0x00, 0x04, 0x77, 0x8e, 0xe0, 0x4e, 0x01, 0x0d, 0x00, + 0x25, 0x20, 0x00, 0x00, 0x0f, 0xf0, 0x1b, 0xf0, 0x20, 0xf0, 0x27, 0xf0, + 0x31, 0xf0, 0x38, 0xf0, 0x3d, 0xf0, 0x44, 0xf0, 0x4e, 0xf0, 0x5d, 0xf0, + 0x6a, 0xf0, 0x79, 0xf0, 0x83, 0xf0, 0x8a, 0xf0, 0x8f, 0xf0, 0x87, 0xc0, + 0x84, 0xc1, 0xf6, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, + 0x02, 0xc0, 0x47, 0xa5, 0x28, 0xa5, 0x09, 0xa5, 0x89, 0xf0, 0x87, 0xc0, + 0x6e, 0x0e, 0x2f, 0xf4, 0x84, 0xc1, 0x34, 0x1d, 0x02, 0x10, 0x83, 0xf0, + 0x87, 0xc0, 0x62, 0x0e, 0x2f, 0xf4, 0x84, 0xc1, 0x2a, 0x1d, 0x02, 0x10, + 0x7b, 0xf0, 0x87, 0xc0, 0x84, 0xc1, 0xc2, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x41, 0xa5, 0x22, 0xa5, 0x03, 0xa5, + 0x6f, 0xf0, 0x87, 0xc0, 0x3a, 0x0e, 0x2f, 0xf4, 0x84, 0xc1, 0x35, 0x1d, + 0x02, 0x10, 0x69, 0xf0, 0x87, 0xc0, 0x2e, 0x0e, 0x2f, 0xf4, 0x84, 0xc1, + 0x36, 0x1d, 0x02, 0x10, 0x61, 0xf0, 0x87, 0xc0, 0x22, 0x0c, 0xaf, 0xf6, + 0x84, 0xc1, 0x9c, 0x1d, 0x00, 0x10, 0x5b, 0xf0, 0x87, 0xc0, 0x84, 0xc1, + 0x7e, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, + 0x44, 0xa5, 0x25, 0xa5, 0x06, 0xa5, 0x4f, 0xf0, 0x87, 0xc0, 0x84, 0xc1, + 0x66, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, + 0x00, 0x1c, 0x80, 0x20, 0x04, 0x1c, 0x40, 0x20, 0x08, 0x1c, 0x00, 0x20, + 0x3f, 0xf0, 0x87, 0xc0, 0x84, 0xc1, 0x4a, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x00, 0x1b, 0x80, 0x20, 0x04, 0x1b, + 0x40, 0x20, 0x08, 0x1b, 0x00, 0x20, 0x31, 0xf0, 0x87, 0xc0, 0x84, 0xc1, + 0x2a, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, + 0x00, 0x18, 0x80, 0x20, 0x04, 0x18, 0x40, 0x20, 0x08, 0x18, 0x00, 0x20, + 0x21, 0xf0, 0x87, 0xc0, 0x84, 0xc1, 0x0e, 0x0e, 0xaf, 0xf6, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x40, 0xa7, 0x21, 0xa7, 0x02, 0xa7, + 0x15, 0xf0, 0x87, 0xc0, 0x86, 0x0d, 0x2f, 0xf4, 0x84, 0xc1, 0xe8, 0x1d, + 0x02, 0x10, 0x0f, 0xf0, 0x87, 0xc0, 0x7a, 0x0d, 0x2f, 0xf4, 0x84, 0xc1, + 0xe9, 0x1d, 0x02, 0x10, 0x07, 0xf0, 0x87, 0xc0, 0x6e, 0x0b, 0xaf, 0xf6, + 0x84, 0xc1, 0xb0, 0x1d, 0x00, 0x10, 0x04, 0xc0, 0x8a, 0x21, 0x3e, 0x06, + 0x52, 0x70, 0xca, 0x21, 0x4d, 0x20, 0x3c, 0x22, 0x01, 0x20, 0x3d, 0x22, + 0x00, 0x20, 0x1e, 0x66, 0x44, 0xf1, 0x22, 0x40, 0xd0, 0xc7, 0xe0, 0x78, + 0xe6, 0xc0, 0x48, 0x43, 0x08, 0x41, 0x55, 0x20, 0xc2, 0x0c, 0x0c, 0x70, + 0x00, 0x46, 0x00, 0x1b, 0x02, 0x10, 0x5f, 0x0e, 0xf5, 0x00, 0x15, 0x21, + 0x8d, 0x11, 0x55, 0x25, 0x4c, 0x1b, 0x64, 0x85, 0xc3, 0x84, 0x55, 0x25, + 0x0f, 0x1c, 0x04, 0x33, 0x80, 0x83, 0xca, 0xf6, 0x60, 0xa7, 0xa0, 0x82, + 0x01, 0x35, 0x48, 0x13, 0x02, 0x33, 0x03, 0x02, 0x60, 0xa4, 0x0d, 0xf0, + 0xa0, 0x84, 0x04, 0x33, 0x40, 0x83, 0x4c, 0xf7, 0x60, 0xa4, 0x80, 0x82, + 0x01, 0x34, 0x0c, 0x13, 0x01, 0x33, 0x03, 0x03, 0x60, 0xa7, 0x00, 0x1b, + 0x43, 0x10, 0x0b, 0xf0, 0x60, 0x82, 0x01, 0x33, 0xc3, 0x00, 0x01, 0x36, + 0xce, 0x10, 0x02, 0x35, 0xc3, 0x10, 0xca, 0xa4, 0x67, 0xa4, 0xc4, 0x71, + 0xd3, 0xf1, 0x00, 0xa9, 0x55, 0x08, 0xf5, 0x00, 0x15, 0x21, 0x03, 0x10, + 0x55, 0x23, 0x0e, 0x0d, 0xa4, 0x83, 0x83, 0x86, 0x04, 0x35, 0x00, 0x93, + 0x55, 0x23, 0xcc, 0x0d, 0xcd, 0xf6, 0xe0, 0x82, 0xa0, 0xa4, 0x00, 0x37, + 0x8b, 0x1f, 0x80, 0xc0, 0x00, 0x00, 0x01, 0x35, 0xcf, 0x12, 0xe0, 0xa6, + 0x00, 0x19, 0x43, 0x00, 0xa4, 0x83, 0x60, 0x86, 0x04, 0x35, 0xc0, 0x90, + 0x4c, 0xf7, 0x60, 0x82, 0xa0, 0xa6, 0x00, 0x33, 0x83, 0x0f, 0x80, 0x40, + 0x00, 0x00, 0x01, 0x35, 0xc3, 0x10, 0x60, 0xa4, 0x00, 0x19, 0x43, 0x00, + 0x04, 0x71, 0xd8, 0xf1, 0xc6, 0xc4, 0xe0, 0x78, 0xea, 0xc3, 0xa7, 0xc1, + 0x48, 0x31, 0x01, 0x00, 0x08, 0x45, 0x07, 0x36, 0x51, 0x70, 0x48, 0x47, + 0x00, 0x00, 0x18, 0x80, 0x7f, 0xde, 0x17, 0xbe, 0x02, 0x36, 0x00, 0x10, + 0xcb, 0x47, 0xc8, 0x41, 0x00, 0x00, 0x6e, 0x0e, 0x2f, 0xfd, 0x07, 0x37, + 0x50, 0x14, 0xca, 0x0c, 0x2f, 0xfd, 0x00, 0x30, 0x00, 0x20, 0x07, 0x31, + 0xc2, 0x23, 0x90, 0x15, 0x01, 0x11, 0x02, 0x36, 0x03, 0x10, 0x48, 0x31, + 0x01, 0x00, 0x77, 0xa5, 0x00, 0x32, 0x40, 0x00, 0x2c, 0x70, 0x04, 0x30, + 0x40, 0x80, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x14, 0xb5, 0x00, 0x30, 0x80, 0x2f, 0x24, 0xbd, 0xca, 0xa5, + 0x82, 0x0c, 0x0f, 0xfd, 0x4a, 0x24, 0x00, 0x71, 0x02, 0x36, 0x00, 0x10, + 0x4a, 0x21, 0x00, 0x00, 0xec, 0x1d, 0x00, 0x10, 0xa8, 0x20, 0x40, 0x03, + 0x15, 0x25, 0x40, 0x10, 0x80, 0x10, 0x00, 0x00, 0x83, 0xc7, 0x15, 0x27, + 0x42, 0x10, 0x02, 0x36, 0x00, 0x10, 0x24, 0x71, 0x00, 0xa2, 0xd2, 0x0f, + 0xa0, 0x03, 0x83, 0xc0, 0x4a, 0x21, 0x00, 0x20, 0x00, 0x87, 0x4a, 0x0c, + 0x2f, 0xfd, 0x00, 0x30, 0x00, 0x20, 0x26, 0x71, 0xf5, 0x09, 0x34, 0xa1, + 0x04, 0x1f, 0x10, 0x10, 0x4a, 0x24, 0x00, 0x71, 0x54, 0x25, 0x01, 0x1e, + 0x83, 0xc0, 0xa8, 0x20, 0x40, 0x02, 0x04, 0x10, 0x02, 0x04, 0x02, 0x36, + 0x82, 0x10, 0x04, 0x19, 0x90, 0x00, 0x1f, 0x85, 0x5d, 0x85, 0x3e, 0x85, + 0xac, 0x15, 0x0c, 0x10, 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x25, 0x03, 0x1a, + 0x42, 0xc0, 0x80, 0xc0, 0x40, 0xc2, 0x41, 0xc1, 0xa8, 0x20, 0x00, 0x02, + 0x04, 0x10, 0x01, 0x04, 0x07, 0x34, 0x41, 0x10, 0x04, 0x1b, 0x50, 0x00, + 0x36, 0x1d, 0x43, 0x10, 0x2a, 0x1d, 0x03, 0x10, 0x35, 0x1d, 0x43, 0x10, + 0xca, 0xc7, 0xe0, 0x78, 0xe4, 0xc2, 0x08, 0x45, 0x5f, 0x20, 0x02, 0x0f, + 0xc3, 0x40, 0xa0, 0x00, 0x70, 0x4c, 0xc3, 0x41, 0xf0, 0x00, 0x2c, 0x01, + 0x5e, 0x60, 0x00, 0x19, 0x41, 0x00, 0x67, 0x86, 0x1c, 0xeb, 0x00, 0x22, + 0x82, 0x0f, 0xa0, 0x00, 0xa9, 0x4c, 0xc3, 0x40, 0xf0, 0x00, 0x00, 0x00, + 0x00, 0x1a, 0x03, 0x00, 0xb5, 0x78, 0xcb, 0x44, 0xa0, 0x00, 0x14, 0x42, + 0x28, 0x90, 0x13, 0x88, 0x40, 0x84, 0xc5, 0xb8, 0x02, 0x79, 0x26, 0xa6, + 0x06, 0xea, 0x60, 0x7a, 0xa1, 0x40, 0x86, 0xe8, 0x67, 0x86, 0x26, 0x86, + 0x07, 0x09, 0xc5, 0x00, 0xc4, 0xc6, 0x00, 0x16, 0x02, 0x70, 0xa0, 0x00, + 0xe8, 0x41, 0x20, 0x1e, 0x01, 0x10, 0x05, 0xea, 0x60, 0x7a, 0xa1, 0x40, + 0xc4, 0xc6, 0x0f, 0x0d, 0xf1, 0x10, 0xa1, 0x40, 0xc2, 0x0e, 0x8f, 0xea, + 0xc4, 0xc6, 0xe6, 0x08, 0x8f, 0xea, 0xc4, 0xc6, 0xe6, 0xc2, 0x08, 0x47, + 0x5f, 0x27, 0x0e, 0x1f, 0xc3, 0x40, 0xf0, 0x00, 0x2c, 0x01, 0xcb, 0x45, + 0xa0, 0x00, 0xa0, 0x4c, 0x00, 0x18, 0x41, 0x00, 0xd8, 0x65, 0x5e, 0x0c, + 0x2f, 0xfb, 0x09, 0x18, 0x03, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0x14, 0x42, + 0x40, 0x80, 0x06, 0xea, 0xa1, 0x66, 0x60, 0x7a, 0xe1, 0x40, 0x84, 0xe8, + 0x0c, 0x70, 0x8b, 0x58, 0xc6, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0xe1, 0xc4, + 0xfc, 0x1c, 0xc8, 0xb2, 0xfc, 0x1c, 0x88, 0xb2, 0xfc, 0x1c, 0x48, 0xb2, + 0xfc, 0x1c, 0x08, 0xb2, 0xfc, 0x1c, 0xc8, 0xb1, 0xfc, 0x1c, 0x88, 0xb1, + 0xfc, 0x1c, 0x48, 0xb1, 0xfc, 0x1c, 0x08, 0xb1, 0xe1, 0xc3, 0xe1, 0xc2, + 0xe1, 0xc1, 0xe1, 0xc0, 0xfc, 0x1c, 0x88, 0xb7, 0x6a, 0x25, 0xc0, 0x10, + 0xe1, 0xc5, 0x6a, 0x25, 0x80, 0x10, 0xe1, 0xc5, 0xfc, 0x1c, 0x08, 0xbf, + 0xa1, 0xc1, 0xc3, 0x40, 0xf0, 0x00, 0x44, 0x01, 0x00, 0x18, 0x01, 0x02, + 0x22, 0x0c, 0x4f, 0xfb, 0x14, 0x71, 0x43, 0xf2, 0xcb, 0x45, 0xa0, 0x00, + 0x78, 0x6e, 0xcd, 0x70, 0xa1, 0x40, 0x00, 0x1c, 0x01, 0x30, 0x2f, 0x26, + 0x0c, 0x10, 0x2f, 0x21, 0x88, 0x83, 0x0c, 0xf2, 0xc3, 0x40, 0xa0, 0x00, + 0x00, 0x87, 0x00, 0x80, 0x4c, 0x71, 0x6c, 0x70, 0x42, 0x0b, 0x6f, 0xfb, + 0x40, 0x24, 0x04, 0x30, 0x04, 0x26, 0x81, 0x9f, 0xff, 0x00, 0x00, 0x00, + 0x0b, 0xf2, 0xc3, 0x40, 0xa0, 0x00, 0xe4, 0x86, 0x00, 0x80, 0x4c, 0x71, + 0x6c, 0x70, 0x26, 0x0b, 0x6f, 0xfb, 0x40, 0x24, 0x04, 0x30, 0x04, 0x26, + 0x81, 0x9f, 0x00, 0x0f, 0x00, 0x00, 0x0a, 0xf2, 0x02, 0x85, 0x08, 0xe8, + 0x4c, 0x71, 0x6c, 0x70, 0x0a, 0x0b, 0x6f, 0xfb, 0x40, 0x24, 0x04, 0x30, + 0x6c, 0x26, 0xc1, 0x96, 0x09, 0xf2, 0x01, 0x85, 0x07, 0xe8, 0x4c, 0x71, + 0x6c, 0x70, 0xf6, 0x0a, 0x6f, 0xfb, 0x40, 0x24, 0x04, 0x30, 0x00, 0xc0, + 0x03, 0xe8, 0x42, 0x0b, 0x8f, 0xfc, 0x87, 0x74, 0xc1, 0xc5, 0x0a, 0x24, + 0x40, 0x73, 0xc1, 0xc5, 0x6b, 0x25, 0x80, 0x10, 0xc1, 0xc5, 0x6b, 0x25, + 0xc0, 0x10, 0x04, 0x14, 0x1e, 0x34, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc2, + 0xc1, 0xc3, 0x04, 0x14, 0x04, 0x34, 0x04, 0x14, 0x05, 0x34, 0x04, 0x14, + 0x06, 0x34, 0x04, 0x14, 0x07, 0x34, 0x04, 0x14, 0x08, 0x34, 0x04, 0x14, + 0x09, 0x34, 0x04, 0x14, 0x0a, 0x34, 0x04, 0x14, 0x0b, 0x34, 0xc1, 0xc4, + 0xc4, 0xc2, 0x6f, 0x24, 0x3f, 0x00, 0xe0, 0x78, 0x41, 0x02, 0x8f, 0xea, + 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x34, 0x50, 0x40, 0x08, 0x47, 0x84, 0xc0, + 0x8a, 0x22, 0x0c, 0x00, 0xfa, 0x0a, 0x2f, 0xeb, 0x28, 0x45, 0x00, 0x87, + 0x40, 0x24, 0x83, 0x30, 0x40, 0x24, 0x04, 0x32, 0x40, 0x24, 0x05, 0x33, + 0x40, 0x24, 0x06, 0x31, 0x40, 0x24, 0xc7, 0x30, 0xa1, 0x41, 0x02, 0x42, + 0x06, 0x0f, 0x2f, 0xf2, 0x02, 0x1c, 0x43, 0x31, 0x02, 0xc5, 0x81, 0x0d, + 0x31, 0x10, 0x2c, 0x70, 0x03, 0x14, 0x8e, 0x30, 0xad, 0x70, 0xba, 0xe9, + 0x02, 0x14, 0x81, 0x30, 0xcf, 0x78, 0x6d, 0x09, 0x24, 0x00, 0x04, 0x77, + 0x4d, 0x08, 0x55, 0x01, 0x25, 0x20, 0x00, 0x00, 0x05, 0xf0, 0x0b, 0xf0, + 0x0f, 0xf0, 0x15, 0xf0, 0x19, 0xf0, 0x84, 0xc0, 0x8e, 0x0f, 0xef, 0xf8, + 0x81, 0xc1, 0x02, 0xa7, 0x18, 0xf0, 0x84, 0xc0, 0x1e, 0x0f, 0x6f, 0xf6, + 0x81, 0xc1, 0x04, 0xa7, 0x12, 0xf0, 0x84, 0xc0, 0x12, 0x0f, 0x6f, 0xf6, + 0x81, 0xc1, 0x05, 0xa7, 0x0c, 0xf0, 0x84, 0xc0, 0x06, 0x0f, 0x6f, 0xf6, + 0x81, 0xc1, 0x0a, 0xa7, 0x06, 0xf0, 0x84, 0xc0, 0x5e, 0x0f, 0xef, 0xf8, + 0x81, 0xc1, 0x03, 0xa7, 0x01, 0xc0, 0x8a, 0x21, 0x3e, 0x06, 0x12, 0x70, + 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, + 0x1e, 0x66, 0xc9, 0xf1, 0xa1, 0x40, 0xc8, 0xc7, 0xe6, 0xc3, 0xa7, 0xc1, + 0x08, 0x46, 0x04, 0x88, 0x28, 0x47, 0x14, 0xe8, 0x4a, 0x24, 0xc0, 0x70, + 0xb8, 0x4e, 0xe1, 0x40, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x02, 0x04, + 0x04, 0x19, 0x90, 0x00, 0xc3, 0x40, 0x8c, 0x42, 0x00, 0x00, 0x0a, 0xa6, + 0x00, 0x19, 0x01, 0x00, 0x04, 0x1e, 0x03, 0x10, 0x4a, 0x24, 0xc0, 0x70, + 0x0c, 0x70, 0x84, 0xc4, 0xa8, 0x20, 0x00, 0x03, 0x15, 0x26, 0x01, 0x10, + 0x03, 0x4f, 0x26, 0x81, 0x15, 0x24, 0x02, 0x10, 0x04, 0x71, 0x02, 0x33, + 0x41, 0x00, 0x20, 0xa2, 0x84, 0xc0, 0x62, 0x0b, 0x6f, 0xf4, 0x81, 0xc1, + 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x26, 0x0d, 0x16, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x17, 0x00, 0x14, 0x04, 0x1d, 0x10, 0x10, 0x8a, 0x86, 0x4a, 0x24, + 0xc0, 0x70, 0x81, 0xc1, 0x40, 0x24, 0x42, 0x30, 0xa8, 0x20, 0xc0, 0x02, + 0x04, 0x11, 0x03, 0x04, 0x0c, 0x70, 0x04, 0x33, 0x00, 0x83, 0xca, 0x20, + 0x69, 0x00, 0x01, 0x1a, 0x12, 0x00, 0x9a, 0x08, 0xaf, 0xf3, 0x40, 0x24, + 0x40, 0x30, 0x0d, 0xe8, 0x05, 0x86, 0x0a, 0xa6, 0x20, 0x85, 0xc3, 0x40, + 0x01, 0x00, 0x80, 0x51, 0x24, 0x71, 0x17, 0x08, 0x44, 0x00, 0x20, 0xa5, + 0x09, 0xf0, 0x00, 0x1d, 0x01, 0x10, 0x04, 0x86, 0x2c, 0x70, 0x0a, 0xa6, + 0x03, 0xf0, 0x00, 0xa5, 0x00, 0x41, 0x03, 0x86, 0x10, 0x71, 0x0c, 0x70, + 0xc4, 0xf7, 0x81, 0xd8, 0x00, 0x1d, 0x01, 0x10, 0xc6, 0xc7, 0xe0, 0x78, + 0xe6, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, + 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, + 0x28, 0x45, 0xee, 0x0d, 0x2f, 0xf2, 0x03, 0x1c, 0x43, 0x31, 0x02, 0x14, + 0x80, 0x30, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x4b, 0x09, 0x24, 0x00, + 0x04, 0x77, 0x3b, 0x08, 0x55, 0x01, 0x25, 0x20, 0x00, 0x00, 0x06, 0xf0, + 0x06, 0xf0, 0x08, 0xf0, 0x08, 0xf0, 0x0f, 0xf0, 0x02, 0x86, 0x0e, 0xf0, + 0x04, 0x86, 0x05, 0xf0, 0x05, 0x86, 0x03, 0xf0, 0x0a, 0x86, 0x81, 0xc3, + 0xa1, 0x41, 0xce, 0x0d, 0x6f, 0xf6, 0xe1, 0x42, 0x07, 0xf0, 0x03, 0x86, + 0x81, 0xc3, 0xa1, 0x41, 0x22, 0x0e, 0xef, 0xf8, 0xe1, 0x42, 0x02, 0x14, + 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xd9, 0xf1, 0x01, 0xc0, + 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc6, 0xc7, 0xe0, 0x78, + 0xe2, 0xc2, 0x60, 0x40, 0x2c, 0x70, 0x10, 0xda, 0x36, 0x0f, 0xef, 0xf8, + 0x88, 0x45, 0x00, 0x1d, 0x01, 0x10, 0xc2, 0xc6, 0xe6, 0xc3, 0xa2, 0xc1, + 0x08, 0x46, 0x18, 0x16, 0x00, 0x14, 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, + 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, + 0x52, 0x0d, 0x2f, 0xf2, 0x03, 0x1c, 0x83, 0x30, 0x02, 0x14, 0x80, 0x30, + 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x35, 0x09, 0x04, 0x00, 0x1b, 0x08, + 0xb0, 0x00, 0x81, 0xc3, 0x1d, 0x08, 0x71, 0x00, 0x81, 0xc3, 0xc1, 0x40, + 0xa1, 0x41, 0xb6, 0x0f, 0x6f, 0xf6, 0xe1, 0x42, 0x06, 0xf0, 0x03, 0x86, + 0xa1, 0x41, 0xa2, 0x0d, 0xef, 0xf8, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, + 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xe6, 0xf1, 0x01, 0xc0, 0x41, 0x28, + 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc6, 0xc7, 0xf5, 0x01, 0x00, 0x02, + 0xea, 0xc3, 0x82, 0x24, 0x0c, 0x39, 0x50, 0x41, 0x08, 0x46, 0x89, 0xc0, + 0x8a, 0x22, 0x0c, 0x00, 0x66, 0x08, 0x2f, 0xeb, 0x28, 0x45, 0x00, 0x86, + 0x40, 0x24, 0xc3, 0x34, 0x40, 0x24, 0x04, 0x37, 0x40, 0x24, 0x05, 0x38, + 0x40, 0x24, 0x06, 0x33, 0x40, 0x24, 0xc7, 0x36, 0xa1, 0x41, 0x22, 0x42, + 0x72, 0x0c, 0x2f, 0xf2, 0x13, 0x1c, 0x83, 0x30, 0x1c, 0x14, 0x10, 0x30, + 0x67, 0x08, 0x31, 0x20, 0x2c, 0x70, 0x1b, 0x14, 0x8f, 0x30, 0x0e, 0x70, + 0xad, 0xe9, 0x13, 0x14, 0x81, 0x30, 0xef, 0x78, 0x53, 0x09, 0x04, 0x00, + 0x23, 0x08, 0xb0, 0x00, 0x89, 0xc1, 0x33, 0x08, 0x71, 0x00, 0x89, 0xc0, + 0x83, 0xc1, 0x0a, 0x0f, 0x6f, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, + 0x02, 0xc0, 0x46, 0xa6, 0x27, 0xa6, 0x08, 0xa6, 0x0b, 0xf0, 0x03, 0xc5, + 0x85, 0xc0, 0xb9, 0x61, 0xfa, 0x0f, 0xef, 0xea, 0x4c, 0x74, 0x05, 0xc1, + 0x04, 0x6d, 0x43, 0xc0, 0x29, 0xa6, 0x03, 0xc0, 0x8a, 0x21, 0x3e, 0x06, + 0x32, 0x70, 0xca, 0x20, 0x4d, 0x20, 0x3c, 0x21, 0x01, 0x20, 0x3d, 0x21, + 0x00, 0x20, 0x1f, 0x67, 0xd4, 0xf1, 0x02, 0x40, 0xca, 0xc7, 0xe0, 0x78, + 0x48, 0x31, 0x01, 0x00, 0x07, 0x36, 0x42, 0x70, 0x48, 0x47, 0x00, 0x00, + 0x2c, 0x70, 0x04, 0x32, 0x40, 0x80, 0xc7, 0xf6, 0x01, 0x32, 0x81, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x32, 0x81, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x18, 0x43, 0x00, 0x48, 0x31, + 0x81, 0x00, 0x48, 0x31, 0x41, 0x02, 0x35, 0x79, 0xe0, 0x7f, 0x23, 0xa0, + 0xe4, 0xc3, 0xa3, 0xc1, 0x20, 0x42, 0x08, 0x45, 0x80, 0xc1, 0x40, 0x40, + 0xea, 0x08, 0x6f, 0xf4, 0x80, 0xc6, 0x00, 0xc3, 0x8d, 0x71, 0x0c, 0x71, + 0x01, 0x4e, 0x04, 0x31, 0xc0, 0x80, 0xca, 0x23, 0x49, 0x00, 0x14, 0x72, + 0x0c, 0x72, 0xba, 0xf7, 0x26, 0x85, 0x8a, 0x22, 0x4c, 0x07, 0xba, 0x62, + 0x04, 0x33, 0x40, 0x80, 0xce, 0xf7, 0x24, 0x85, 0x04, 0x33, 0x40, 0x80, + 0xdd, 0xf7, 0x05, 0x85, 0x04, 0x33, 0x00, 0x80, 0x56, 0x00, 0x2e, 0x00, + 0x8d, 0x74, 0x14, 0x12, 0xce, 0x00, 0x34, 0xf0, 0xa1, 0x41, 0x80, 0x21, + 0x0c, 0x07, 0x00, 0x89, 0x61, 0x89, 0x04, 0x77, 0xc9, 0x6b, 0x0d, 0x7b, + 0xcd, 0x78, 0x88, 0x23, 0x3e, 0x02, 0x8c, 0x20, 0x3e, 0x82, 0x4c, 0x00, + 0x2a, 0x00, 0x60, 0xa9, 0x88, 0xd9, 0x0c, 0x71, 0x30, 0xf0, 0xa9, 0x44, + 0x80, 0x24, 0x0c, 0x17, 0x20, 0x8c, 0x61, 0x8c, 0x24, 0x77, 0xc9, 0x6b, + 0x2d, 0x7b, 0xcd, 0x79, 0x88, 0x23, 0x3e, 0x02, 0x8c, 0x21, 0x3e, 0x82, + 0x60, 0xac, 0x9e, 0xf6, 0xc0, 0xaa, 0x8d, 0x72, 0x0f, 0xf0, 0xa1, 0x41, + 0x80, 0x21, 0x0c, 0x07, 0x01, 0x89, 0x14, 0x11, 0xc3, 0x00, 0xc9, 0x68, + 0xcd, 0x78, 0x8c, 0x20, 0x3e, 0x82, 0x60, 0xa9, 0x90, 0xf6, 0x8d, 0x73, + 0xc0, 0xaa, 0x2f, 0x26, 0x85, 0xf3, 0x24, 0x00, 0x23, 0x00, 0x0c, 0x74, + 0x80, 0x25, 0x0c, 0x17, 0x00, 0x15, 0xc3, 0x10, 0x81, 0x40, 0x07, 0xf0, + 0x88, 0xd9, 0x04, 0xf0, 0x88, 0xd9, 0x0c, 0x73, 0x20, 0xaa, 0x09, 0x0b, + 0x12, 0x00, 0x0c, 0x73, 0xc4, 0xc7, 0xe0, 0x78, 0xf2, 0xc3, 0x82, 0x24, + 0x0c, 0x3d, 0x50, 0x42, 0x10, 0x41, 0x8d, 0xc0, 0x8a, 0x22, 0x0c, 0x00, + 0xa2, 0x0e, 0xef, 0xea, 0x28, 0x45, 0x26, 0x40, 0x40, 0x24, 0x83, 0x33, + 0x40, 0x24, 0x04, 0x35, 0x40, 0x24, 0x05, 0x3c, 0x40, 0x24, 0x06, 0x34, + 0x40, 0x24, 0xc7, 0x33, 0xa1, 0x41, 0x42, 0x42, 0xae, 0x0a, 0x2f, 0xf2, + 0x0e, 0x1c, 0x43, 0x35, 0x05, 0xc0, 0x03, 0xe8, 0xd2, 0xc7, 0x0f, 0x14, + 0x8e, 0x30, 0x8a, 0x24, 0x04, 0x27, 0x8a, 0x23, 0x04, 0x2d, 0x8a, 0x20, + 0x05, 0x23, 0x8a, 0x27, 0x05, 0x1f, 0x55, 0x21, 0x8d, 0x2e, 0x56, 0x21, + 0x15, 0x28, 0x00, 0x24, 0x54, 0x24, 0x00, 0x23, 0x53, 0x24, 0x00, 0x20, + 0x50, 0x24, 0x22, 0x77, 0x0e, 0x14, 0x81, 0x30, 0xcf, 0x78, 0x30, 0x70, + 0xc8, 0x01, 0x2d, 0x00, 0x8a, 0x21, 0x08, 0x00, 0x04, 0x77, 0x94, 0xe0, + 0x1e, 0x01, 0x0d, 0x00, 0x25, 0x20, 0x00, 0x00, 0x15, 0xf0, 0x1b, 0xf0, + 0x1f, 0xf0, 0x25, 0xf0, 0x29, 0xf0, 0x2f, 0xf0, 0x33, 0xf0, 0x3c, 0xf0, + 0x40, 0xf0, 0x49, 0xf0, 0x50, 0xf0, 0x59, 0xf0, 0x66, 0xf0, 0x75, 0xf0, + 0x83, 0xf0, 0x8a, 0xf0, 0x97, 0xf0, 0x9e, 0xf0, 0xa3, 0xf0, 0xb2, 0xf0, + 0xbf, 0xf0, 0x8d, 0xc0, 0x96, 0x0f, 0x2f, 0xee, 0x84, 0xc1, 0x00, 0xa5, + 0x71, 0xf0, 0x8d, 0xc0, 0x8a, 0x0f, 0x2f, 0xee, 0x84, 0xc1, 0x01, 0xa5, + 0x6b, 0xf0, 0x8d, 0xc0, 0x72, 0x0a, 0x6f, 0xf6, 0x84, 0xc1, 0x02, 0xa5, + 0x65, 0xf0, 0x8d, 0xc0, 0x66, 0x0a, 0x6f, 0xf6, 0x84, 0xc1, 0x03, 0xa5, + 0x5f, 0xf0, 0x8d, 0xc0, 0x5a, 0x0a, 0x6f, 0xf6, 0x84, 0xc1, 0x04, 0xa5, + 0x59, 0xf0, 0x8d, 0xc0, 0x5a, 0x0f, 0x2f, 0xee, 0x84, 0xc1, 0x05, 0xa5, + 0x53, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0xd6, 0x0b, 0xaf, 0xf9, 0x86, 0xc2, + 0x86, 0xc1, 0x18, 0xda, 0xa2, 0x40, 0x49, 0xf0, 0x8d, 0xc0, 0x32, 0x0a, + 0x6f, 0xf6, 0x84, 0xc1, 0x0c, 0xa5, 0x45, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, + 0xb6, 0x0b, 0xaf, 0xf9, 0x86, 0xc2, 0x86, 0xc1, 0x18, 0xda, 0x82, 0x40, + 0x39, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0xa6, 0x0b, 0xaf, 0xf9, 0x86, 0xc2, + 0x86, 0xc1, 0x18, 0xda, 0x62, 0x40, 0x31, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, + 0x92, 0x0b, 0xaf, 0xf9, 0x86, 0xc2, 0x86, 0xc1, 0x18, 0xda, 0x02, 0x40, + 0x27, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0xea, 0x0b, 0xaf, 0xf7, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x59, 0x19, 0x98, 0x20, 0x5a, 0x19, + 0x58, 0x20, 0x5b, 0x19, 0x18, 0x20, 0x1b, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, + 0xca, 0x0b, 0xaf, 0xf7, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, + 0x5c, 0x19, 0x98, 0x20, 0x5d, 0x19, 0x58, 0x20, 0x5e, 0x19, 0x18, 0x20, + 0x0b, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0x46, 0x0b, 0xaf, 0xf9, 0x86, 0xc2, + 0x86, 0xc1, 0x18, 0xda, 0xe1, 0x40, 0x1e, 0x0d, 0xcf, 0xea, 0x04, 0xc0, + 0x52, 0x70, 0xcc, 0x06, 0xee, 0xff, 0xc5, 0x71, 0x52, 0xf0, 0x8d, 0xc0, + 0x92, 0x09, 0x6f, 0xf6, 0x84, 0xc1, 0xac, 0x1d, 0x00, 0x10, 0xf5, 0xf1, + 0x8d, 0xc0, 0x84, 0xc1, 0x7e, 0x0b, 0xaf, 0xf7, 0x80, 0xc2, 0x00, 0xc2, + 0x01, 0xc1, 0x02, 0xc0, 0x66, 0x19, 0x98, 0x20, 0x67, 0x19, 0x58, 0x20, + 0x68, 0x19, 0x18, 0x20, 0xe5, 0xf1, 0x8d, 0xc0, 0x72, 0x0e, 0x2f, 0xee, + 0x84, 0xc1, 0xbc, 0x1d, 0x00, 0x10, 0xdf, 0xf1, 0x8d, 0xc0, 0x66, 0x0e, + 0x2f, 0xee, 0x84, 0xc1, 0xc0, 0x1d, 0x00, 0x10, 0xd7, 0xf1, 0x8d, 0xc0, + 0x84, 0xc1, 0xb6, 0x0b, 0x6f, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, + 0x02, 0xc0, 0x6b, 0x19, 0x98, 0x20, 0x6c, 0x19, 0x58, 0x20, 0x6d, 0x19, + 0x18, 0x20, 0xc9, 0xf1, 0x8d, 0xc0, 0x84, 0xc1, 0x96, 0x0b, 0x6f, 0xf6, + 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x6e, 0x19, 0x98, 0x20, + 0x6f, 0x19, 0x58, 0x20, 0x70, 0x19, 0x18, 0x20, 0xb9, 0xf1, 0x8d, 0xc0, + 0x1a, 0x0e, 0x2f, 0xee, 0x84, 0xc1, 0xdc, 0x1d, 0x00, 0x10, 0xb3, 0xf1, + 0xc3, 0x42, 0x13, 0x00, 0xd8, 0x6c, 0x2a, 0x08, 0x20, 0x02, 0x22, 0x40, + 0x0c, 0x70, 0xd2, 0xc7, 0x8a, 0x20, 0x3e, 0x06, 0xd2, 0xc7, 0xe0, 0x78, + 0xee, 0xc3, 0xad, 0xc1, 0x08, 0x45, 0x04, 0x88, 0x0a, 0x21, 0x80, 0x21, + 0x0a, 0x20, 0x40, 0x21, 0x70, 0x43, 0x48, 0x47, 0x30, 0x42, 0x0a, 0xe8, + 0x8a, 0x20, 0x0c, 0x09, 0x08, 0x65, 0x06, 0xe8, 0xa1, 0x40, 0x32, 0x0c, + 0x60, 0x00, 0x42, 0x41, 0x8a, 0x20, 0x0c, 0x09, 0x4a, 0x24, 0xc0, 0x70, + 0x6d, 0x70, 0xb8, 0x60, 0x00, 0x25, 0x8e, 0x1f, 0x00, 0x00, 0xd4, 0x01, + 0x04, 0x1d, 0xc2, 0x12, 0x00, 0x18, 0x43, 0x00, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0x00, 0x07, 0x01, 0x4f, 0x00, 0x31, 0x81, 0x0f, 0x7a, 0x3d, + 0x00, 0x00, 0x04, 0x31, 0xc0, 0x82, 0xc7, 0xf6, 0x01, 0x31, 0x8c, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x31, 0x8c, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0x80, 0xc3, 0x8b, 0xc2, 0x48, 0x34, 0xcc, 0x12, 0x15, 0x7b, + 0x14, 0x7a, 0x04, 0x71, 0x20, 0xa3, 0x80, 0xb2, 0x8a, 0x27, 0x09, 0x1f, + 0xbf, 0x67, 0x8b, 0xc2, 0x2c, 0x71, 0xda, 0x0a, 0xaf, 0xf1, 0xe1, 0x40, + 0x76, 0x70, 0x6e, 0x70, 0x1c, 0xf4, 0x80, 0xc1, 0x3a, 0x0c, 0xef, 0xff, + 0xa1, 0x40, 0x4a, 0x24, 0xc0, 0x70, 0x0a, 0x23, 0x00, 0x00, 0x88, 0xc0, + 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x01, 0x24, 0x00, 0x31, 0x81, 0x0f, + 0xcc, 0x3d, 0xcd, 0xcc, 0x04, 0x18, 0x50, 0x00, 0xa1, 0x42, 0x88, 0xc1, + 0x80, 0x22, 0x0c, 0x01, 0xc6, 0x0e, 0x20, 0x00, 0xa1, 0x40, 0x10, 0x43, + 0x59, 0x16, 0x01, 0x16, 0x17, 0xe9, 0xa1, 0x40, 0x80, 0x20, 0x0b, 0x04, + 0x00, 0x88, 0x93, 0xe8, 0x8b, 0xc2, 0xe1, 0x40, 0x02, 0x0b, 0xaf, 0xf1, + 0x40, 0x24, 0x12, 0x3b, 0x4a, 0x24, 0xc0, 0x70, 0x80, 0xc0, 0xa8, 0x20, + 0x40, 0x02, 0x02, 0x12, 0x41, 0x25, 0x48, 0x31, 0x81, 0x00, 0x04, 0x18, + 0x50, 0x00, 0x58, 0x16, 0x00, 0x16, 0x8a, 0x27, 0x0c, 0x11, 0xbf, 0x67, + 0x00, 0x30, 0x82, 0x0f, 0x74, 0x49, 0x00, 0x24, 0x80, 0xc1, 0x40, 0x24, + 0x04, 0x34, 0xc3, 0x43, 0x2b, 0x32, 0x77, 0xcc, 0xe1, 0x40, 0x5a, 0x0d, + 0x6f, 0xf1, 0x40, 0x24, 0x12, 0x30, 0x84, 0xc1, 0x10, 0xda, 0x3a, 0x0b, + 0xef, 0xea, 0xe1, 0x40, 0x84, 0xc1, 0x02, 0x0c, 0x6f, 0xf1, 0xe1, 0x40, + 0x84, 0xc1, 0x10, 0xda, 0x26, 0x0b, 0xef, 0xea, 0xe1, 0x40, 0x40, 0x24, + 0xc1, 0x33, 0x40, 0x24, 0x82, 0x33, 0x82, 0x08, 0x20, 0x00, 0xa1, 0x40, + 0x0e, 0x14, 0x80, 0x30, 0x00, 0x19, 0x03, 0x20, 0x05, 0x20, 0xfe, 0x84, + 0x04, 0xf2, 0x80, 0xd8, 0x00, 0x19, 0x02, 0x20, 0x40, 0x86, 0x21, 0x86, + 0x02, 0x86, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0xc2, 0x41, 0xc1, 0x42, 0xc0, + 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x00, 0x24, 0x00, 0x30, 0x80, 0x0f, + 0x20, 0x41, 0x00, 0x00, 0x04, 0x18, 0x10, 0x20, 0x0f, 0x14, 0x80, 0x30, + 0x48, 0x30, 0x00, 0x00, 0x00, 0x18, 0x00, 0x20, 0xce, 0xc7, 0xe0, 0x78, + 0xa3, 0xc1, 0x4a, 0x24, 0xc0, 0x70, 0x80, 0xc3, 0x80, 0xc2, 0xa8, 0x20, + 0x00, 0x02, 0x04, 0x10, 0x01, 0x04, 0xbf, 0xb9, 0x04, 0x1a, 0x50, 0x00, + 0x00, 0xc0, 0x2c, 0x71, 0x22, 0x4b, 0x04, 0x32, 0x00, 0x80, 0xca, 0x20, + 0x89, 0x00, 0x34, 0x72, 0x2c, 0x72, 0xba, 0xf7, 0xe0, 0x7f, 0xa3, 0xc0, + 0xe8, 0xc3, 0x82, 0x24, 0x02, 0x3a, 0x48, 0x47, 0x28, 0x46, 0x08, 0x45, + 0x56, 0x20, 0x01, 0x0f, 0x86, 0xc0, 0x90, 0xda, 0x86, 0x0a, 0xef, 0xea, + 0x40, 0x24, 0x10, 0x36, 0x4a, 0x24, 0x80, 0x71, 0x80, 0xc3, 0x80, 0xc0, + 0xa8, 0x20, 0x80, 0x01, 0x1c, 0x10, 0x01, 0x24, 0x04, 0x18, 0x50, 0x00, + 0x03, 0xc2, 0x2c, 0x70, 0x15, 0x23, 0x40, 0x00, 0x04, 0x80, 0x04, 0x30, + 0x80, 0x80, 0xca, 0x22, 0x09, 0x00, 0x34, 0x71, 0x2c, 0x71, 0xf8, 0xf5, + 0xc0, 0x15, 0x00, 0x10, 0x04, 0x32, 0x00, 0x80, 0x44, 0xf7, 0x00, 0x1e, + 0xc3, 0x10, 0x11, 0xf0, 0xbc, 0x15, 0x00, 0x10, 0x04, 0x32, 0x00, 0x80, + 0x44, 0xf7, 0x00, 0x1e, 0x83, 0x10, 0x09, 0xf0, 0xb8, 0x15, 0x00, 0x10, + 0x04, 0x32, 0x00, 0x80, 0x6f, 0x20, 0x0b, 0x00, 0x00, 0xae, 0x8a, 0x20, + 0x4c, 0x05, 0x08, 0x65, 0x09, 0x08, 0x91, 0x01, 0x00, 0x1e, 0x03, 0x10, + 0x00, 0x1f, 0x03, 0x10, 0x80, 0x25, 0x0c, 0x15, 0x20, 0x8d, 0x00, 0x8e, + 0x0d, 0x08, 0x40, 0x00, 0x00, 0x1f, 0x43, 0x10, 0x00, 0x8e, 0x00, 0xad, + 0xc8, 0xc7, 0xe0, 0x78, 0xfa, 0xc3, 0xa2, 0xc1, 0x10, 0x40, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x50, 0x41, 0x28, 0x45, 0x55, 0x20, 0x8e, 0x2e, 0x66, 0x0e, + 0xef, 0xf1, 0x03, 0x1c, 0x43, 0x35, 0x02, 0x14, 0x81, 0x30, 0x8a, 0x20, + 0x06, 0x0b, 0x8a, 0x22, 0x04, 0x07, 0x8a, 0x23, 0x04, 0x0d, 0x8a, 0x27, + 0x05, 0x13, 0x8a, 0x24, 0x05, 0x19, 0x56, 0x20, 0x19, 0x28, 0x56, 0x20, + 0x98, 0x2b, 0x56, 0x20, 0xd7, 0x2c, 0x56, 0x20, 0xd2, 0x2d, 0x00, 0x20, + 0x16, 0x20, 0x00, 0x20, 0x94, 0x20, 0x00, 0x20, 0xd3, 0x20, 0x02, 0x77, + 0x00, 0x20, 0x15, 0x23, 0x80, 0x20, 0x05, 0x2f, 0x03, 0x14, 0x80, 0x30, + 0x2f, 0x79, 0xe1, 0x08, 0x64, 0x00, 0x09, 0x69, 0xcd, 0x08, 0x55, 0x05, + 0x25, 0x20, 0x00, 0x00, 0x15, 0xf0, 0x17, 0xf0, 0x17, 0xf0, 0x19, 0xf0, + 0x19, 0xf0, 0x1b, 0xf0, 0x1b, 0xf0, 0x1e, 0xf0, 0x1e, 0xf0, 0x21, 0xf0, + 0x22, 0xf0, 0x25, 0xf0, 0x26, 0xf0, 0x29, 0xf0, 0x2e, 0xf0, 0x36, 0xf0, + 0x3b, 0xf0, 0x3e, 0xf0, 0x3f, 0xf0, 0x42, 0xf0, 0x47, 0xf0, 0x00, 0x86, + 0x47, 0xf0, 0x01, 0x86, 0x45, 0xf0, 0x02, 0x86, 0x24, 0xf0, 0x03, 0x86, + 0x22, 0xf0, 0x04, 0x86, 0x20, 0xf0, 0x05, 0x86, 0x3d, 0xf0, 0x81, 0xc3, + 0x23, 0x40, 0x15, 0xf0, 0x0c, 0x86, 0x1a, 0xf0, 0x81, 0xc3, 0x82, 0x40, + 0x0f, 0xf0, 0x81, 0xc3, 0x62, 0x40, 0x0d, 0xf0, 0x81, 0xc3, 0xe1, 0x40, + 0x09, 0xf0, 0x81, 0xc3, 0xa2, 0x40, 0x16, 0xf0, 0x81, 0xc3, 0x03, 0x40, + 0x12, 0xf0, 0x81, 0xc3, 0x02, 0x40, 0xa1, 0x41, 0x4a, 0x0f, 0x6f, 0xf9, + 0x22, 0x42, 0x28, 0xf0, 0xac, 0x16, 0x00, 0x10, 0x81, 0xc3, 0xa1, 0x41, + 0xa6, 0x0d, 0x2f, 0xf6, 0x22, 0x42, 0x20, 0xf0, 0x81, 0xc3, 0xe2, 0x40, + 0xa1, 0x41, 0x96, 0x0f, 0x6f, 0xf7, 0x22, 0x42, 0x18, 0xf0, 0xbc, 0x16, + 0x00, 0x10, 0x11, 0xf0, 0xc0, 0x16, 0x00, 0x10, 0x0d, 0xf0, 0x81, 0xc3, + 0xc2, 0x40, 0x04, 0xf0, 0x81, 0xc3, 0x42, 0x40, 0xa1, 0x41, 0xe6, 0x0f, + 0x2f, 0xf6, 0x22, 0x42, 0x08, 0xf0, 0xdc, 0x16, 0x00, 0x10, 0x81, 0xc3, + 0xa1, 0x41, 0x76, 0x0a, 0x2f, 0xee, 0x22, 0x42, 0x02, 0x14, 0x80, 0x30, + 0x21, 0x68, 0x02, 0x1c, 0x42, 0x30, 0x90, 0xf1, 0x01, 0xc0, 0x41, 0x28, + 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xda, 0xc7, 0xe8, 0xc3, 0xa1, 0xc1, + 0x60, 0x40, 0x48, 0x45, 0x28, 0x46, 0x2c, 0x70, 0x10, 0xda, 0x88, 0x47, + 0xda, 0x0e, 0xaf, 0xf8, 0x70, 0x40, 0xd5, 0x70, 0xcd, 0x70, 0x08, 0xf2, + 0x47, 0x0d, 0x91, 0x19, 0x00, 0x18, 0x83, 0x21, 0xcd, 0x71, 0x1f, 0xf0, + 0x4a, 0x24, 0x00, 0x71, 0xc3, 0x42, 0x13, 0x00, 0xc8, 0x6c, 0x0c, 0x70, + 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x03, 0x04, 0x80, 0xc1, 0x1c, 0x61, + 0x04, 0x71, 0x38, 0x23, 0x41, 0x03, 0x20, 0xac, 0xd6, 0x09, 0x2f, 0xf4, + 0x80, 0xc0, 0x0b, 0xe8, 0xcd, 0x74, 0x03, 0x18, 0xc3, 0x21, 0x02, 0x18, + 0x43, 0x21, 0x01, 0x18, 0x83, 0x20, 0x00, 0x18, 0x43, 0x20, 0xc0, 0xa7, + 0xc8, 0xc7, 0xe0, 0x78, 0xf4, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x50, 0x43, 0x28, 0x45, 0xae, 0x0c, 0xef, 0xf1, 0x03, 0x1c, + 0xc3, 0x31, 0x02, 0x14, 0x80, 0x30, 0x8a, 0x20, 0x09, 0x2c, 0x8a, 0x27, + 0x0c, 0x11, 0x8a, 0x26, 0x4c, 0x25, 0x8a, 0x22, 0x8c, 0x25, 0x8a, 0x21, + 0x0c, 0x29, 0x56, 0x26, 0x54, 0x1e, 0x56, 0x26, 0x15, 0x1f, 0x00, 0x20, + 0x90, 0x23, 0xdf, 0x67, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x87, 0x09, + 0x24, 0x00, 0x04, 0x77, 0x73, 0x08, 0xd5, 0x01, 0x25, 0x20, 0x00, 0x00, + 0x07, 0xf0, 0x1f, 0xf0, 0x0c, 0xf0, 0x13, 0xf0, 0x18, 0xf0, 0x22, 0xf0, + 0x28, 0xf0, 0x81, 0xc3, 0x82, 0x40, 0xa1, 0x41, 0x36, 0x0f, 0xaf, 0xf9, + 0x62, 0x42, 0x29, 0xf0, 0x81, 0xc3, 0x02, 0x40, 0xa1, 0x41, 0xd2, 0x0e, + 0x2f, 0xf6, 0x62, 0x42, 0x21, 0xf0, 0x81, 0xc3, 0xe1, 0x40, 0xa1, 0x41, + 0x46, 0x0b, 0x2f, 0xf9, 0x62, 0x42, 0x1b, 0xf0, 0x32, 0x26, 0x80, 0x15, + 0x0a, 0xf0, 0x81, 0xc3, 0xa2, 0x40, 0xa1, 0x41, 0xaa, 0x0c, 0x2f, 0xfa, + 0x62, 0x42, 0x11, 0xf0, 0x32, 0x26, 0x80, 0x14, 0x81, 0xc3, 0xa1, 0x41, + 0x1e, 0x0e, 0xaf, 0xf3, 0x62, 0x42, 0x09, 0xf0, 0x32, 0x26, 0x40, 0x14, + 0x81, 0xc3, 0xa1, 0x41, 0x3a, 0x0a, 0xef, 0xf8, 0x62, 0x42, 0x02, 0x14, + 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xbc, 0xf1, 0x01, 0xc0, + 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xd4, 0xc7, 0xe0, 0x78, + 0xee, 0xc3, 0x82, 0x24, 0x07, 0x35, 0x50, 0x41, 0x28, 0x45, 0x10, 0x40, + 0x56, 0x24, 0x80, 0x3d, 0x2c, 0x70, 0x24, 0xda, 0xa8, 0x46, 0x0a, 0x23, + 0x00, 0x21, 0x70, 0x42, 0x86, 0x0d, 0xaf, 0xf8, 0x56, 0x24, 0x8f, 0x3d, + 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x16, 0x00, 0x14, + 0x10, 0x1f, 0x10, 0x10, 0x8d, 0x70, 0x0a, 0x21, 0x40, 0x14, 0x6c, 0x70, + 0x0a, 0x20, 0x80, 0x14, 0x4c, 0x70, 0x5a, 0x22, 0x80, 0x01, 0x4a, 0x24, + 0x80, 0x71, 0x56, 0x24, 0x4e, 0x3b, 0x79, 0x60, 0x35, 0x7e, 0x0a, 0x23, + 0x00, 0x12, 0x21, 0x41, 0x0c, 0x70, 0x80, 0xa6, 0xa8, 0x20, 0x80, 0x02, + 0x0c, 0x13, 0x07, 0x14, 0x18, 0x11, 0x06, 0x04, 0x00, 0x36, 0xc6, 0x01, + 0x01, 0x30, 0x80, 0x01, 0x44, 0x71, 0x05, 0x74, 0xcf, 0x0a, 0xf4, 0x80, + 0x00, 0xa6, 0x64, 0x71, 0xc1, 0x0b, 0xb4, 0x81, 0x25, 0x74, 0x55, 0x24, + 0xc8, 0x3f, 0x55, 0x24, 0xc9, 0x3f, 0x0a, 0x26, 0x80, 0x04, 0x15, 0x20, + 0x05, 0x13, 0x4c, 0x70, 0x0a, 0x23, 0x40, 0x14, 0x0c, 0x70, 0x4a, 0x24, + 0x80, 0x71, 0x14, 0x20, 0x01, 0x00, 0x15, 0x25, 0x4e, 0x00, 0xc0, 0x43, + 0x2c, 0x70, 0x40, 0xa6, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x13, 0x04, 0x14, + 0x0c, 0x13, 0x07, 0x04, 0x00, 0x37, 0x07, 0x01, 0x01, 0x31, 0xc1, 0x01, + 0x04, 0x71, 0xdb, 0x08, 0xb4, 0x81, 0x20, 0xa6, 0x0a, 0x24, 0x80, 0x04, + 0x4a, 0x24, 0x80, 0x71, 0x6d, 0x70, 0x21, 0x41, 0x0a, 0x20, 0x00, 0x01, + 0xa8, 0x20, 0x80, 0x02, 0x0c, 0x10, 0x07, 0x04, 0x0c, 0x11, 0x03, 0x04, + 0x00, 0x33, 0xc3, 0x01, 0x01, 0x33, 0xcb, 0x10, 0x14, 0x22, 0x80, 0x00, + 0x56, 0x24, 0x81, 0x3d, 0x98, 0x60, 0x01, 0x49, 0x00, 0x24, 0x83, 0x3f, + 0x00, 0x00, 0x44, 0x01, 0x44, 0x71, 0x01, 0x33, 0x41, 0x10, 0x84, 0x74, + 0x15, 0x7b, 0xc5, 0x0a, 0xf4, 0x80, 0x20, 0xa3, 0x85, 0x71, 0x25, 0x74, + 0x7b, 0x0c, 0xf4, 0x90, 0xc4, 0x74, 0x56, 0x24, 0x40, 0x3b, 0x00, 0x24, + 0x81, 0x3f, 0x00, 0x00, 0x44, 0x01, 0x55, 0x24, 0x42, 0x3b, 0xea, 0x0c, + 0xaf, 0xf8, 0x55, 0x24, 0x4e, 0x3b, 0x2c, 0x70, 0x4a, 0x24, 0xc0, 0x70, + 0xc1, 0x42, 0x62, 0x40, 0x4a, 0x23, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x02, + 0x04, 0x10, 0x0b, 0x04, 0x18, 0x12, 0x0c, 0x04, 0x00, 0x34, 0xcc, 0x12, + 0x01, 0x33, 0x03, 0x03, 0x20, 0x4d, 0x15, 0x20, 0x42, 0x20, 0x24, 0x71, + 0x01, 0x33, 0x00, 0x00, 0xc5, 0x74, 0xd5, 0x09, 0xb4, 0x81, 0x72, 0x1a, + 0x18, 0x00, 0x55, 0x24, 0x00, 0x39, 0x2c, 0x70, 0x24, 0xda, 0x32, 0x0c, + 0xaf, 0xf8, 0x55, 0x24, 0x0d, 0x39, 0x4a, 0x24, 0x80, 0x71, 0xa8, 0x20, + 0x40, 0x01, 0x07, 0x1d, 0x53, 0x10, 0xcc, 0x70, 0x55, 0x24, 0x48, 0x3b, + 0x8d, 0x70, 0x0a, 0x21, 0x80, 0x14, 0x6c, 0x70, 0x4a, 0x24, 0xc0, 0x70, + 0x01, 0x40, 0x6d, 0x70, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x11, 0x02, 0x14, + 0x18, 0x10, 0x01, 0x04, 0x00, 0x31, 0x81, 0x00, 0x01, 0x33, 0x4b, 0x10, + 0x5a, 0x23, 0x80, 0x01, 0x40, 0x24, 0x04, 0x30, 0x64, 0x71, 0x99, 0x60, + 0x55, 0x24, 0x00, 0x39, 0x33, 0x20, 0x40, 0x00, 0x15, 0x24, 0x41, 0x00, + 0x48, 0x30, 0x80, 0x00, 0x02, 0x30, 0xc0, 0x02, 0xc5, 0x0b, 0xb4, 0x81, + 0x00, 0xa1, 0x85, 0x71, 0xb7, 0x0c, 0xb4, 0x91, 0x05, 0x74, 0x4c, 0x70, + 0x15, 0x20, 0x87, 0x20, 0x0a, 0x20, 0x40, 0x14, 0x2c, 0x70, 0x5a, 0x21, + 0x80, 0x01, 0x4a, 0x24, 0x80, 0x71, 0x80, 0x43, 0x15, 0x27, 0x0c, 0x00, + 0x4a, 0x20, 0x00, 0x00, 0x78, 0x1c, 0x98, 0x11, 0xa8, 0x20, 0x00, 0x03, + 0x04, 0x10, 0x09, 0x14, 0x18, 0x13, 0x0b, 0x04, 0x00, 0x33, 0x4b, 0x12, + 0x01, 0x30, 0xc0, 0x02, 0x78, 0x1c, 0x18, 0x10, 0x24, 0x71, 0xd3, 0x09, + 0x94, 0x81, 0x44, 0x71, 0xc1, 0x0a, 0xb4, 0x81, 0x84, 0x74, 0xce, 0xc7, + 0xe8, 0xc3, 0x82, 0x24, 0x02, 0x34, 0x4a, 0x24, 0x80, 0x71, 0x50, 0x40, + 0x0a, 0x25, 0x00, 0x10, 0x56, 0x20, 0x4e, 0x0e, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x11, 0x00, 0x04, 0x04, 0x1e, 0x10, 0x10, 0x80, 0xc0, 0x2c, 0x70, + 0x90, 0xda, 0x56, 0x0b, 0xaf, 0xf8, 0x80, 0xc7, 0x4a, 0x24, 0x80, 0x71, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x00, 0x24, 0x1c, 0x1f, 0x10, 0x10, + 0x80, 0xc1, 0x90, 0xda, 0xf6, 0x0c, 0xaf, 0xea, 0x0a, 0x20, 0x80, 0x03, + 0x4a, 0x24, 0xc0, 0x70, 0x80, 0x25, 0x09, 0x1c, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x1d, 0x11, 0x10, 0xc8, 0xc7, 0xe0, 0x78, 0xf0, 0xc3, 0xb5, 0xc1, + 0x30, 0x40, 0x8a, 0x27, 0x4c, 0x15, 0x10, 0x42, 0x00, 0x20, 0x8d, 0x0f, + 0x00, 0x00, 0xbc, 0x02, 0xcd, 0x70, 0x1f, 0x67, 0x92, 0xc1, 0x02, 0x40, + 0x70, 0x43, 0x50, 0x44, 0x41, 0x1c, 0x82, 0x33, 0x1a, 0x0e, 0xef, 0xf3, + 0x54, 0x24, 0x11, 0x39, 0x4a, 0x24, 0xc0, 0x70, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0xc0, 0x04, 0x15, 0x22, 0x03, 0x20, 0xf0, 0x21, 0x01, 0x20, + 0xd8, 0x13, 0x03, 0x00, 0x00, 0x24, 0x82, 0x3f, 0x00, 0x00, 0x45, 0x00, + 0x1a, 0x62, 0x04, 0x31, 0xc0, 0x80, 0x04, 0x71, 0x6f, 0x21, 0x0b, 0x00, + 0x20, 0xaa, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, 0x45, 0x00, 0xce, 0x09, + 0x0f, 0xf3, 0x20, 0x8f, 0x2a, 0xe8, 0x34, 0x76, 0x90, 0x01, 0x0d, 0x00, + 0x25, 0x20, 0x40, 0x00, 0x07, 0xf0, 0xc4, 0xf0, 0x2c, 0xf0, 0xc2, 0xf0, + 0x4b, 0xf0, 0x61, 0xf0, 0x6d, 0xf0, 0x17, 0x85, 0x3f, 0x85, 0x41, 0x68, + 0x30, 0x70, 0x74, 0x01, 0x2b, 0x00, 0x57, 0xa5, 0x84, 0x15, 0x02, 0x96, + 0x85, 0x15, 0x01, 0x96, 0x86, 0x15, 0x00, 0x96, 0xd7, 0xa5, 0x00, 0x1f, + 0x83, 0x10, 0x43, 0xc2, 0x44, 0xc1, 0x45, 0xc0, 0x40, 0x22, 0x02, 0x28, + 0x80, 0xc1, 0x42, 0x40, 0x40, 0xc6, 0x41, 0xc6, 0xf2, 0x0e, 0xef, 0xff, + 0x42, 0xc6, 0xa2, 0xf0, 0x0d, 0x09, 0x70, 0x01, 0x80, 0x22, 0x8c, 0x25, + 0x00, 0x1a, 0x42, 0x20, 0x00, 0x1f, 0x43, 0x11, 0xd7, 0xa5, 0x98, 0xf0, + 0x17, 0x85, 0x54, 0x24, 0x84, 0x38, 0x00, 0x24, 0x85, 0x3f, 0x00, 0x00, + 0x41, 0x00, 0x04, 0x71, 0x17, 0xa5, 0x02, 0x41, 0x82, 0x42, 0x62, 0x43, + 0x56, 0x09, 0x20, 0x00, 0x42, 0x40, 0x54, 0x24, 0x41, 0x38, 0x91, 0xc2, + 0x4e, 0x09, 0xef, 0xff, 0x42, 0x40, 0x42, 0x14, 0x80, 0x30, 0x14, 0x73, + 0x7b, 0xf2, 0x3c, 0x85, 0x17, 0x85, 0x30, 0x70, 0xf4, 0x00, 0x0c, 0x00, + 0xd7, 0xa5, 0xc0, 0xaf, 0x76, 0xf0, 0x00, 0x24, 0x84, 0x3f, 0x00, 0x00, + 0x43, 0x00, 0x00, 0x24, 0x85, 0x3f, 0x00, 0x00, 0x41, 0x00, 0x42, 0x40, + 0x02, 0x41, 0x82, 0x42, 0x16, 0x09, 0x20, 0x00, 0x62, 0x43, 0x43, 0x14, + 0x80, 0x30, 0xcd, 0x08, 0x10, 0x00, 0xd1, 0xa5, 0x00, 0x1f, 0x83, 0x11, + 0x60, 0xf0, 0x17, 0x85, 0x39, 0x85, 0x04, 0x71, 0xb9, 0x08, 0x62, 0x00, + 0x17, 0xa5, 0x80, 0x22, 0x8c, 0x25, 0x00, 0x12, 0x80, 0x20, 0xd7, 0xa5, + 0xff, 0x1a, 0x02, 0xa0, 0x52, 0xf0, 0x37, 0x85, 0x4a, 0x24, 0xc0, 0x70, + 0x01, 0x69, 0x30, 0x43, 0x17, 0xa5, 0x0c, 0x70, 0xa8, 0x20, 0x80, 0x03, + 0x15, 0x22, 0x01, 0x20, 0xf0, 0x20, 0x03, 0x20, 0x9c, 0x11, 0x0c, 0x06, + 0x92, 0xc2, 0x15, 0x7a, 0x02, 0x33, 0x01, 0x03, 0x04, 0x71, 0x20, 0xa2, + 0x8e, 0x08, 0xef, 0xff, 0x92, 0xc0, 0x31, 0x85, 0xe7, 0x17, 0x90, 0x90, + 0x10, 0x44, 0x01, 0x30, 0x40, 0x00, 0x1d, 0x08, 0xb5, 0x22, 0x11, 0xa5, + 0x15, 0x22, 0x00, 0x24, 0xb5, 0x18, 0x18, 0x05, 0x44, 0x15, 0x11, 0x10, + 0x06, 0x71, 0xe7, 0x1f, 0x02, 0x94, 0x17, 0xf0, 0x46, 0x85, 0x8a, 0x21, + 0x0b, 0x06, 0x42, 0x71, 0x02, 0x30, 0x91, 0x00, 0x80, 0xc0, 0x24, 0xda, + 0x1a, 0x0b, 0xaf, 0xea, 0x44, 0x1d, 0x40, 0x14, 0x42, 0x40, 0x80, 0x20, + 0x0b, 0x05, 0x80, 0xc1, 0x28, 0xda, 0x0a, 0x0b, 0xaf, 0xea, 0x24, 0x1c, + 0x00, 0x35, 0x7e, 0x15, 0x01, 0x96, 0x2f, 0x20, 0x07, 0x04, 0x48, 0x30, + 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x04, 0x31, 0x00, 0xa0, 0x4b, 0xf7, + 0xe7, 0x1f, 0x82, 0x93, 0xd1, 0xa5, 0xd7, 0xa5, 0x00, 0x1f, 0x03, 0x11, + 0x41, 0x14, 0x80, 0x30, 0xd0, 0xc7, 0x1b, 0x85, 0xf9, 0x0b, 0x02, 0xa0, + 0x84, 0x15, 0x02, 0x96, 0x85, 0x15, 0x01, 0x96, 0x86, 0x15, 0x00, 0x96, + 0xe7, 0x1f, 0x82, 0x93, 0xd1, 0xa5, 0xd7, 0xa5, 0x4d, 0xc2, 0x4e, 0xc1, + 0x4f, 0xc0, 0x40, 0x22, 0x02, 0x28, 0x8a, 0xc1, 0x42, 0x40, 0x4a, 0xc6, + 0x4b, 0xc6, 0x7a, 0x0d, 0xef, 0xff, 0x4c, 0xc6, 0x00, 0x1f, 0x83, 0x10, + 0xe2, 0xf1, 0xe0, 0x78, 0xf2, 0xc3, 0x82, 0x24, 0x05, 0x3a, 0x8a, 0x27, + 0x4c, 0x15, 0x0a, 0x24, 0x40, 0x21, 0x0a, 0x21, 0x00, 0x21, 0x70, 0x43, + 0x48, 0x43, 0x30, 0x40, 0x10, 0x42, 0x55, 0x20, 0x4e, 0x08, 0xad, 0x70, + 0x1f, 0x67, 0x00, 0x1d, 0x42, 0x03, 0x59, 0x0b, 0x71, 0x00, 0x00, 0x1c, + 0x42, 0x03, 0x4a, 0x24, 0xc0, 0x70, 0x0c, 0x70, 0xa8, 0x20, 0x40, 0x04, + 0x15, 0x22, 0x02, 0x20, 0xf0, 0x20, 0x01, 0x20, 0x9c, 0x12, 0x03, 0x06, + 0x00, 0x24, 0x82, 0x3f, 0x00, 0x00, 0x5c, 0x01, 0x15, 0x7a, 0x02, 0x31, + 0xc1, 0x00, 0x04, 0x71, 0x20, 0xa2, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, + 0x5c, 0x01, 0x7a, 0x0f, 0x8f, 0xff, 0x2c, 0x86, 0x04, 0x30, 0x40, 0x80, + 0x66, 0x00, 0x0c, 0x00, 0x00, 0x19, 0x43, 0x20, 0x09, 0x8f, 0x14, 0x70, + 0x0c, 0x02, 0x02, 0x00, 0x0f, 0x02, 0x00, 0x00, 0x42, 0x40, 0x80, 0x20, + 0x8c, 0x07, 0x20, 0x88, 0x02, 0xe9, 0xa0, 0xa8, 0x56, 0x24, 0xc1, 0x39, + 0x61, 0x40, 0xea, 0x08, 0x2f, 0xf1, 0x56, 0x24, 0xd5, 0x39, 0x0c, 0x70, + 0x00, 0x24, 0x81, 0x3f, 0x00, 0x00, 0x14, 0x01, 0x4a, 0x24, 0xc0, 0x70, + 0x0a, 0x22, 0x40, 0x05, 0xa8, 0x20, 0x80, 0x01, 0x0c, 0x12, 0x03, 0x04, + 0x04, 0x19, 0xd0, 0x00, 0x04, 0x71, 0xed, 0x08, 0xf4, 0x80, 0xa6, 0x74, + 0x41, 0x0b, 0xf0, 0x20, 0x54, 0x22, 0x81, 0x2d, 0x35, 0x0b, 0x31, 0x21, + 0x54, 0x22, 0x81, 0x2a, 0x18, 0xf0, 0x27, 0x17, 0x81, 0x10, 0x49, 0x8f, + 0x30, 0x72, 0x68, 0x01, 0x06, 0x00, 0x04, 0x30, 0x80, 0x8f, 0x20, 0x41, + 0x00, 0x00, 0xa0, 0x01, 0x2c, 0x00, 0x44, 0x71, 0x9f, 0x16, 0x01, 0x16, + 0x49, 0xaf, 0x01, 0x30, 0x40, 0x00, 0x9f, 0x1e, 0x18, 0x10, 0xd2, 0xc7, + 0x40, 0x22, 0x01, 0x2f, 0x55, 0x24, 0xc0, 0x3f, 0x9e, 0x09, 0xaf, 0xea, + 0x18, 0xda, 0x95, 0xc0, 0x2c, 0x70, 0x90, 0xda, 0xd6, 0x0f, 0x6f, 0xf8, + 0x54, 0x24, 0x95, 0x3a, 0x4a, 0x24, 0x80, 0x71, 0x55, 0x24, 0xc0, 0x3f, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x01, 0x04, 0x1c, 0x1d, 0x50, 0x20, + 0x4a, 0x24, 0x00, 0x79, 0x56, 0x22, 0x01, 0x2f, 0x95, 0xc0, 0xa8, 0x20, + 0x80, 0x02, 0x04, 0x11, 0x03, 0x04, 0x40, 0x80, 0x01, 0x33, 0x82, 0x00, + 0x04, 0x18, 0x90, 0x00, 0x56, 0x22, 0x41, 0x2e, 0x55, 0x24, 0x40, 0x3e, + 0x52, 0x09, 0xaf, 0xea, 0x18, 0xda, 0x0d, 0x70, 0x4a, 0x24, 0x00, 0x10, + 0x4a, 0x24, 0xc0, 0x70, 0x14, 0x24, 0x00, 0x13, 0xa8, 0x20, 0x00, 0x05, + 0x33, 0x20, 0x82, 0x0f, 0x13, 0x00, 0x74, 0x6c, 0x00, 0x24, 0x81, 0x3f, + 0x00, 0x00, 0x14, 0x01, 0x03, 0x49, 0x40, 0x24, 0x09, 0x33, 0x48, 0x32, + 0x82, 0x00, 0x15, 0x21, 0x01, 0x10, 0x04, 0x71, 0x60, 0xa1, 0x49, 0xa1, + 0x85, 0x71, 0xd1, 0x0c, 0xd4, 0x90, 0x2c, 0x70, 0x4a, 0x24, 0x80, 0x71, + 0x15, 0x22, 0x0c, 0x22, 0x55, 0x24, 0x42, 0x3e, 0x21, 0x43, 0x0c, 0x70, + 0x9c, 0x1c, 0x58, 0x13, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x06, 0x04, + 0x0c, 0x13, 0x0b, 0x04, 0x00, 0x33, 0x8b, 0x11, 0x01, 0x30, 0xc0, 0x02, + 0x05, 0x71, 0x25, 0x74, 0xd5, 0x08, 0xf4, 0x90, 0x9c, 0x1c, 0x18, 0x10, + 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0x40, 0x04, 0x15, 0x22, 0x40, 0x20, + 0xf0, 0x20, 0x43, 0x20, 0x9c, 0x10, 0x00, 0x06, 0x00, 0x24, 0x82, 0x3f, + 0x00, 0x00, 0x5c, 0x01, 0x35, 0x7a, 0x02, 0x33, 0x00, 0x00, 0x24, 0x71, + 0x00, 0xa2, 0x23, 0x0b, 0x10, 0x21, 0x00, 0x24, 0x80, 0x3f, 0x00, 0x00, + 0x5c, 0x01, 0xe2, 0x0d, 0x8f, 0xff, 0x2c, 0x86, 0x04, 0x30, 0x40, 0x80, + 0xc5, 0xf6, 0x00, 0x8f, 0x65, 0x08, 0xb1, 0x00, 0x6c, 0x71, 0x40, 0x86, + 0x21, 0x86, 0x02, 0x86, 0x6c, 0x70, 0x40, 0xc2, 0x41, 0xc1, 0x42, 0xc0, + 0x00, 0x19, 0xc2, 0x20, 0x55, 0x24, 0x41, 0x3e, 0x95, 0xc2, 0x83, 0xc3, + 0x00, 0x24, 0x84, 0x3f, 0x00, 0x00, 0x5c, 0x01, 0x40, 0x24, 0x05, 0x30, + 0x12, 0x09, 0xef, 0xff, 0x42, 0x40, 0x00, 0x1c, 0x43, 0x20, 0xd2, 0xc7, + 0x1a, 0xf4, 0x48, 0x32, 0x01, 0x00, 0x00, 0x30, 0x43, 0x00, 0x01, 0x31, + 0x40, 0x00, 0x9f, 0x16, 0x01, 0x16, 0x02, 0x33, 0x0c, 0x00, 0x04, 0x31, + 0x00, 0x83, 0xd6, 0xf6, 0x01, 0x33, 0x00, 0x00, 0x04, 0x31, 0x00, 0x80, + 0x50, 0xf7, 0x01, 0x6a, 0x09, 0xaf, 0x12, 0xf1, 0x43, 0x86, 0x24, 0x86, + 0x05, 0x86, 0xd3, 0xf1, 0x17, 0x09, 0x85, 0x00, 0x04, 0x30, 0x80, 0x8f, + 0x80, 0x3f, 0x00, 0x00, 0x0c, 0x06, 0xc6, 0xff, 0x9f, 0x1e, 0x58, 0x13, + 0xa9, 0xaf, 0xd2, 0xc7, 0xc9, 0x01, 0x80, 0x01, 0xe8, 0xc3, 0xa6, 0xc1, + 0x10, 0x40, 0x8a, 0x20, 0x07, 0x05, 0x02, 0x70, 0x02, 0x0a, 0xaf, 0xf8, + 0x0a, 0x26, 0x40, 0x10, 0x04, 0x30, 0x80, 0x8f, 0x7a, 0x44, 0x00, 0x00, + 0x88, 0x00, 0x26, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x83, 0xc5, 0x83, 0xc0, + 0xa8, 0x20, 0x80, 0x02, 0x04, 0x16, 0x01, 0x14, 0x00, 0x31, 0x81, 0x0f, + 0xcc, 0x3d, 0xcd, 0xcc, 0x04, 0x18, 0x50, 0x00, 0x4a, 0x24, 0xc0, 0x70, + 0x6d, 0x70, 0x0c, 0x70, 0xa8, 0x20, 0x80, 0x03, 0x15, 0x20, 0x01, 0x20, + 0x04, 0x4d, 0x75, 0x11, 0x03, 0x06, 0x80, 0xc2, 0x15, 0x7a, 0x02, 0x34, + 0xc1, 0x10, 0x04, 0x71, 0x00, 0x1a, 0x40, 0x00, 0x00, 0xc5, 0x01, 0xc4, + 0x02, 0xc3, 0x03, 0xc2, 0x04, 0xc1, 0x05, 0xc0, 0x4a, 0x24, 0x00, 0x71, + 0x72, 0x18, 0x58, 0x23, 0x73, 0x18, 0x18, 0x23, 0x74, 0x18, 0xd8, 0x20, + 0x9c, 0x18, 0x98, 0x20, 0x9d, 0x18, 0x58, 0x20, 0x9e, 0x18, 0x18, 0x20, + 0x80, 0x20, 0x0c, 0x21, 0xa8, 0x20, 0xc0, 0x02, 0x33, 0x23, 0x80, 0x1f, + 0x13, 0x00, 0x60, 0x6c, 0x65, 0x71, 0x48, 0x30, 0x80, 0x00, 0x04, 0x18, + 0x10, 0x20, 0xc8, 0xc7, 0x8a, 0x0a, 0xa0, 0x01, 0x02, 0x40, 0xc8, 0xc7, + 0xf4, 0xc3, 0x82, 0x24, 0x0f, 0x35, 0x50, 0x43, 0x10, 0x42, 0x55, 0x24, + 0x40, 0x3d, 0x8a, 0x22, 0x0c, 0x00, 0x56, 0x0f, 0x6f, 0xea, 0x28, 0x45, + 0x46, 0x40, 0x40, 0x24, 0x83, 0x33, 0x40, 0x24, 0x04, 0x35, 0x55, 0x24, + 0x05, 0x3d, 0x40, 0x24, 0x06, 0x34, 0x40, 0x24, 0xc7, 0x33, 0xa1, 0x41, + 0x62, 0x42, 0x62, 0x0b, 0xaf, 0xf1, 0x0e, 0x1c, 0xc3, 0x31, 0x14, 0x14, + 0x11, 0x30, 0x36, 0x70, 0x7d, 0xf4, 0x0f, 0x14, 0x8d, 0x30, 0x8a, 0x24, + 0x0c, 0x21, 0x8a, 0x20, 0x4c, 0x25, 0x8a, 0x27, 0x8c, 0x15, 0x8a, 0x26, + 0x0c, 0x19, 0x56, 0x22, 0x56, 0x2e, 0x56, 0x22, 0x15, 0x2f, 0x2e, 0x70, + 0x2c, 0x70, 0x00, 0x24, 0x94, 0x24, 0x00, 0x20, 0x90, 0x24, 0x42, 0x77, + 0x42, 0x76, 0xcf, 0x09, 0x31, 0x00, 0xaf, 0x78, 0x0e, 0x14, 0x81, 0x30, + 0xc3, 0x09, 0x24, 0x00, 0x04, 0x77, 0xa7, 0x08, 0xd5, 0x01, 0x25, 0x20, + 0x00, 0x00, 0x08, 0xf0, 0x12, 0xf0, 0x1c, 0xf0, 0x2a, 0xf0, 0x36, 0xf0, + 0x3c, 0xf0, 0x43, 0xf0, 0x55, 0x24, 0x40, 0x3d, 0x84, 0xc1, 0x1a, 0x0e, + 0x6f, 0xf9, 0x55, 0x24, 0x82, 0x3b, 0x55, 0x24, 0x81, 0x3b, 0x18, 0xda, + 0xc2, 0x40, 0x25, 0xf0, 0x55, 0x24, 0x40, 0x3d, 0x84, 0xc1, 0xa6, 0x0b, + 0xef, 0xf9, 0x8a, 0xc2, 0x8a, 0xc1, 0x90, 0xda, 0xa2, 0x40, 0x1b, 0xf0, + 0x55, 0x24, 0x40, 0x3d, 0x84, 0xc1, 0x96, 0x0d, 0xef, 0xf5, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x9c, 0x1a, 0x98, 0x20, 0x9d, 0x1a, + 0x58, 0x20, 0x9e, 0x1a, 0x18, 0x20, 0x23, 0xf0, 0x55, 0x24, 0x40, 0x3d, + 0x84, 0xc1, 0xfa, 0x09, 0xef, 0xf8, 0x86, 0xc2, 0x86, 0xc1, 0x10, 0xda, + 0x82, 0x40, 0x76, 0x0e, 0x4f, 0xea, 0x17, 0xf0, 0x55, 0x24, 0x40, 0x3d, + 0xee, 0x0c, 0x6f, 0xf3, 0x84, 0xc1, 0x00, 0x18, 0x02, 0x20, 0x0f, 0xf0, + 0x55, 0x24, 0x40, 0x3d, 0xde, 0x0c, 0x6f, 0xf3, 0x84, 0xc1, 0x00, 0xaf, + 0x07, 0xf0, 0x55, 0x24, 0x40, 0x3d, 0xfe, 0x08, 0xaf, 0xf8, 0x84, 0xc1, + 0x00, 0xae, 0x04, 0xc0, 0x8a, 0x21, 0x3e, 0x06, 0x72, 0x70, 0xca, 0x21, + 0x4d, 0x20, 0x3c, 0x23, 0x01, 0x20, 0x3d, 0x23, 0x00, 0x20, 0x1d, 0x65, + 0x9b, 0xf1, 0x22, 0x40, 0xd4, 0xc7, 0xe0, 0x78, 0xf0, 0xc3, 0xa6, 0xc1, + 0x40, 0x92, 0xc3, 0x43, 0x48, 0x47, 0x00, 0x00, 0x00, 0x20, 0x8d, 0x0f, + 0x00, 0x00, 0xbc, 0x02, 0x48, 0x32, 0x02, 0x00, 0x10, 0x40, 0x07, 0x33, + 0x82, 0x00, 0xbb, 0x15, 0x00, 0x96, 0xcb, 0x46, 0xc8, 0x41, 0x00, 0x00, + 0xd1, 0x41, 0x48, 0x30, 0x80, 0x00, 0xcb, 0x47, 0x83, 0x3a, 0x6f, 0x12, + 0x48, 0x31, 0x0c, 0x00, 0x6d, 0x70, 0x04, 0x32, 0x80, 0x83, 0xca, 0x21, + 0x85, 0x20, 0x00, 0x31, 0x00, 0x20, 0x00, 0x30, 0xc0, 0x03, 0x04, 0x30, + 0xc0, 0x82, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0xba, 0x15, + 0x01, 0x96, 0x48, 0x30, 0xc2, 0x02, 0x07, 0x33, 0x12, 0x03, 0x8a, 0x24, + 0x0c, 0x17, 0x48, 0x31, 0x81, 0x00, 0x00, 0x31, 0x40, 0x20, 0x48, 0x32, + 0x81, 0x00, 0x00, 0x30, 0xc0, 0x03, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, + 0xc0, 0x82, 0x3c, 0xa5, 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, + 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, + 0x07, 0x36, 0x8b, 0x74, 0x80, 0x3f, 0x00, 0x00, 0x8b, 0x15, 0x01, 0x96, + 0x48, 0x30, 0xc2, 0x02, 0x6c, 0x70, 0x48, 0x31, 0x80, 0x00, 0x48, 0x32, + 0x82, 0x00, 0x02, 0x74, 0x00, 0x31, 0x00, 0x20, 0x48, 0x32, 0xc2, 0x02, + 0x5b, 0xa5, 0x00, 0x33, 0x00, 0x10, 0x78, 0x1d, 0xc0, 0x12, 0x00, 0x30, + 0xc0, 0x03, 0x04, 0x30, 0xc0, 0x80, 0xc7, 0xf6, 0x01, 0x30, 0x81, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x30, 0x81, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0x8c, 0x15, 0x00, 0x96, 0x48, 0x31, 0xc1, 0x02, 0x48, 0x30, + 0x80, 0x00, 0x34, 0xac, 0x00, 0x31, 0x00, 0x20, 0x00, 0x33, 0x00, 0x10, + 0x00, 0x30, 0xc0, 0x03, 0x04, 0x30, 0xc0, 0x80, 0xc6, 0xf6, 0x01, 0x30, + 0x81, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x81, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x90, 0x15, 0x00, 0x96, 0x48, 0x31, 0xc1, 0x02, + 0x4c, 0x70, 0x48, 0x30, 0x80, 0x00, 0x35, 0xac, 0x00, 0x32, 0x00, 0x20, + 0x00, 0x30, 0xc0, 0x03, 0x04, 0x30, 0x80, 0x80, 0xc6, 0xf6, 0x01, 0x30, + 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x08, 0x15, 0x01, 0x90, 0x48, 0x30, 0xc3, 0x02, + 0x57, 0xa5, 0x48, 0x31, 0x81, 0x00, 0x40, 0xb4, 0x00, 0x31, 0x40, 0x20, + 0x42, 0xac, 0x48, 0x33, 0x81, 0x00, 0x00, 0x30, 0xc0, 0x03, 0x48, 0x31, + 0xc1, 0x02, 0x04, 0x30, 0x80, 0x80, 0x3f, 0xa5, 0xc6, 0xf6, 0x01, 0x30, + 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc1, 0x02, 0x4c, 0x70, 0x48, 0x31, + 0x81, 0x00, 0x00, 0x31, 0x80, 0x2f, 0xcc, 0x3e, 0xcd, 0xcc, 0x55, 0x20, + 0x8f, 0x2e, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, 0x80, 0x80, 0x39, 0xa5, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc1, 0x02, + 0x8a, 0x20, 0x09, 0x0f, 0x02, 0x70, 0x22, 0x0c, 0x2f, 0xf1, 0x20, 0x1c, + 0x42, 0x10, 0x8a, 0x20, 0x0b, 0x05, 0x02, 0x70, 0x2c, 0x70, 0x29, 0xda, + 0x92, 0x0a, 0x6f, 0xf8, 0xc0, 0x18, 0x19, 0x20, 0x40, 0x20, 0x00, 0x22, + 0xe0, 0xda, 0x42, 0x0c, 0x6f, 0xea, 0xe1, 0x41, 0x8a, 0x21, 0x04, 0x07, + 0x02, 0x71, 0x80, 0xc0, 0x18, 0xda, 0x32, 0x0c, 0x6f, 0xea, 0x40, 0x24, + 0x14, 0x30, 0x4a, 0x24, 0x80, 0x71, 0x40, 0x20, 0x13, 0x2f, 0xcb, 0x47, + 0xc8, 0x42, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x03, 0x04, 0x14, 0x00, 0x24, + 0x00, 0x30, 0x80, 0x03, 0x07, 0x30, 0x40, 0x04, 0x00, 0x30, 0xc0, 0x03, + 0x07, 0x30, 0x80, 0x04, 0x04, 0x1b, 0x10, 0x20, 0x8a, 0x21, 0x04, 0x0d, + 0x02, 0x71, 0x80, 0xc0, 0x18, 0xda, 0xf6, 0x0b, 0x6f, 0xea, 0x40, 0x24, + 0x14, 0x30, 0x4a, 0x24, 0x80, 0x71, 0xa8, 0x20, 0xc0, 0x03, 0x04, 0x14, + 0x00, 0x24, 0x00, 0x30, 0x80, 0x03, 0x07, 0x30, 0x40, 0x04, 0x00, 0x30, + 0xc0, 0x03, 0x07, 0x30, 0x80, 0x04, 0x04, 0x1b, 0x10, 0x20, 0x8a, 0x21, + 0x05, 0x03, 0x02, 0x71, 0x80, 0xc0, 0x18, 0xda, 0xc2, 0x0b, 0x6f, 0xea, + 0x40, 0x24, 0x14, 0x30, 0x4a, 0x24, 0x80, 0x71, 0xa8, 0x20, 0x80, 0x03, + 0x04, 0x14, 0x00, 0x24, 0x00, 0x30, 0x80, 0x03, 0x07, 0x30, 0x40, 0x04, + 0x00, 0x30, 0xc0, 0x03, 0x07, 0x30, 0x80, 0x04, 0x04, 0x1b, 0x10, 0x20, + 0xb6, 0x15, 0x00, 0x96, 0xc3, 0x41, 0x48, 0x41, 0x00, 0x00, 0x04, 0x31, + 0x40, 0xa0, 0x00, 0x30, 0x80, 0x03, 0xca, 0x21, 0x45, 0x20, 0x07, 0x30, + 0x40, 0x04, 0x04, 0x18, 0x43, 0x20, 0x7e, 0x1d, 0x18, 0x90, 0xd0, 0xc7, + 0xe6, 0xc2, 0x42, 0x81, 0x08, 0x45, 0x05, 0x80, 0x00, 0x32, 0x82, 0x0f, + 0xcc, 0x3d, 0xd0, 0xcc, 0xcb, 0x47, 0x0e, 0x42, 0xa1, 0xc2, 0x00, 0x30, + 0x80, 0x0f, 0x66, 0x3f, 0x66, 0x66, 0x6d, 0x70, 0x01, 0x30, 0x88, 0x00, + 0x61, 0x46, 0x14, 0x1d, 0x00, 0x12, 0x03, 0x85, 0x41, 0x81, 0x64, 0x85, + 0x82, 0x81, 0x02, 0x32, 0x0e, 0x00, 0x42, 0x85, 0x00, 0x81, 0xbf, 0xbe, + 0x69, 0x41, 0x02, 0xa5, 0x02, 0x30, 0x80, 0x00, 0x02, 0x34, 0xc2, 0x10, + 0x50, 0x20, 0xc3, 0x07, 0x01, 0x81, 0x01, 0x33, 0x83, 0x03, 0xbf, 0xba, + 0x03, 0xa5, 0x02, 0x81, 0x01, 0x33, 0x82, 0x00, 0xcb, 0x46, 0x4b, 0x43, + 0x78, 0xf1, 0x04, 0xa5, 0x04, 0x32, 0xc0, 0x83, 0x4f, 0x27, 0x00, 0x16, + 0xe4, 0x8d, 0x61, 0x81, 0x80, 0x81, 0xca, 0x26, 0x69, 0x00, 0x04, 0x32, + 0x00, 0x80, 0xca, 0x21, 0x69, 0x10, 0xf5, 0x70, 0xca, 0x21, 0x81, 0x11, + 0x50, 0x23, 0xc6, 0x07, 0x50, 0x24, 0xc7, 0x17, 0x02, 0x37, 0x80, 0x01, + 0xbf, 0xb8, 0x04, 0x30, 0x80, 0x83, 0x0c, 0x74, 0x93, 0xf7, 0x42, 0x81, + 0x04, 0x32, 0xc0, 0x82, 0x8f, 0xf7, 0x04, 0x37, 0x80, 0x81, 0xc8, 0xf6, + 0x04, 0x34, 0xc0, 0x92, 0x0c, 0x72, 0xca, 0x20, 0xeb, 0x00, 0x07, 0xf0, + 0x04, 0x33, 0xc0, 0x82, 0x0c, 0x70, 0xca, 0x20, 0x6b, 0x00, 0x07, 0x30, + 0x83, 0x1f, 0x7a, 0x44, 0x00, 0x00, 0x7f, 0xda, 0x17, 0xba, 0x04, 0x33, + 0x80, 0x80, 0x07, 0xf6, 0x04, 0x33, 0xc0, 0x82, 0x60, 0x42, 0x43, 0xf7, + 0x4c, 0x70, 0xc2, 0xb8, 0x6a, 0x68, 0x2f, 0x0b, 0xb5, 0x00, 0x8d, 0x70, + 0x04, 0x32, 0x80, 0x8f, 0xa3, 0x3c, 0x0a, 0xd7, 0x0c, 0x70, 0xca, 0x20, + 0x69, 0x00, 0x04, 0x32, 0x80, 0x8f, 0x7a, 0x3f, 0x48, 0xe1, 0x6f, 0x23, + 0x0b, 0x10, 0x6c, 0x71, 0x04, 0x23, 0x0b, 0x10, 0x04, 0x36, 0x80, 0x83, + 0x17, 0xf0, 0x8d, 0x70, 0x6c, 0x70, 0x99, 0xe8, 0x04, 0x32, 0x80, 0x8f, + 0xa3, 0x3c, 0x0a, 0xd7, 0x0c, 0x70, 0xca, 0x20, 0x69, 0x00, 0x04, 0x32, + 0x80, 0x8f, 0x7a, 0x3f, 0x48, 0xe1, 0x6f, 0x23, 0x0b, 0x10, 0x6c, 0x70, + 0x8d, 0x71, 0x04, 0x23, 0x0b, 0x10, 0x04, 0x37, 0x80, 0x83, 0x6f, 0x20, + 0x0b, 0x00, 0x04, 0x23, 0x0b, 0x10, 0x2f, 0x0f, 0x70, 0x10, 0xcd, 0x70, + 0xa7, 0x0f, 0x11, 0x10, 0x41, 0x09, 0x10, 0x10, 0x09, 0x0b, 0x10, 0x10, + 0x1c, 0x8d, 0x1c, 0xe8, 0x19, 0x8d, 0x04, 0x71, 0x0d, 0x79, 0x93, 0x09, + 0x72, 0x02, 0x19, 0xad, 0x1b, 0x1d, 0x43, 0x10, 0x19, 0x1d, 0x03, 0x12, + 0x41, 0xf0, 0x18, 0x8d, 0x04, 0x71, 0x0f, 0x7a, 0x39, 0x0a, 0xf4, 0x02, + 0x18, 0xad, 0x1a, 0x8d, 0x3d, 0x08, 0xf4, 0x02, 0xa1, 0x40, 0x66, 0x0a, + 0x0f, 0xf0, 0x1c, 0x1d, 0x43, 0x10, 0x33, 0xf0, 0x19, 0x8d, 0x04, 0x77, + 0x2f, 0x26, 0x05, 0xf0, 0x5a, 0x00, 0x23, 0x00, 0x19, 0xad, 0x1b, 0x8d, + 0xd9, 0xad, 0x29, 0xe8, 0x4f, 0x0b, 0x30, 0x10, 0xdb, 0xad, 0x04, 0x1d, + 0x43, 0x10, 0x23, 0xf0, 0x43, 0x09, 0x10, 0x10, 0x1a, 0x8d, 0x04, 0x71, + 0x1a, 0xad, 0x1d, 0xf0, 0x31, 0x0b, 0x10, 0x10, 0x06, 0xec, 0x2a, 0x0a, + 0x2f, 0xf0, 0xa1, 0x40, 0x81, 0xde, 0x15, 0xf0, 0x10, 0xeb, 0xc2, 0x81, + 0x1a, 0x0a, 0x2f, 0xf0, 0xa1, 0x40, 0x50, 0x26, 0xc0, 0x17, 0x8a, 0x26, + 0x7e, 0x10, 0x04, 0x30, 0x80, 0x8f, 0x0c, 0x44, 0x02, 0x36, 0xca, 0x26, + 0x26, 0x10, 0x05, 0xf0, 0xfe, 0x09, 0x2f, 0xf0, 0xa1, 0x40, 0xcf, 0x78, + 0xc6, 0xc6, 0xe0, 0x78, 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x34, 0x50, 0x40, + 0x08, 0x45, 0x84, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0x28, 0x47, 0x76, 0x09, + 0x6f, 0xea, 0x84, 0xc6, 0x00, 0x85, 0x40, 0x24, 0x83, 0x31, 0x40, 0x24, + 0x04, 0x32, 0x40, 0x24, 0x05, 0x33, 0x40, 0x24, 0x06, 0x30, 0x40, 0x24, + 0xc7, 0x31, 0xe1, 0x41, 0x02, 0x42, 0x82, 0x0d, 0x6f, 0xf1, 0x06, 0x1c, + 0x83, 0x30, 0x02, 0xc0, 0xa2, 0xe8, 0x07, 0x14, 0x8f, 0x30, 0x0e, 0x71, + 0x06, 0x14, 0x81, 0x30, 0xef, 0x78, 0x35, 0x09, 0x24, 0x00, 0x2f, 0x26, + 0x07, 0xf4, 0x1f, 0x08, 0xb0, 0x00, 0x80, 0xc1, 0x21, 0x08, 0x51, 0x00, + 0x00, 0xc0, 0x09, 0x66, 0x04, 0x71, 0x40, 0xc0, 0xfe, 0x0a, 0x20, 0x00, + 0xa1, 0x40, 0x10, 0x40, 0x06, 0xf0, 0x9e, 0x0f, 0x2f, 0xf3, 0x84, 0xc0, + 0x39, 0x1d, 0x02, 0x10, 0xe5, 0x71, 0xe6, 0xf1, 0x0c, 0x70, 0x03, 0xf2, + 0xc8, 0xc7, 0x8a, 0x20, 0x7e, 0x06, 0xc8, 0xc7, 0xe2, 0xc2, 0x84, 0x88, + 0x06, 0xec, 0x00, 0x1f, 0x03, 0x00, 0x04, 0x18, 0x03, 0x00, 0x04, 0xf0, + 0x00, 0x1f, 0x43, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x20, 0x0c, 0x02, + 0x0a, 0x25, 0x80, 0x11, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x14, 0x0b, 0x14, + 0x04, 0x1d, 0xd0, 0x12, 0x3a, 0x10, 0x8c, 0x00, 0x6d, 0x70, 0x48, 0x34, + 0x0c, 0x10, 0x80, 0xa5, 0x83, 0x83, 0x04, 0x34, 0xc0, 0x92, 0xc7, 0xf6, + 0x01, 0x34, 0x8c, 0x1f, 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x34, + 0x8c, 0x1f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x34, 0xcd, 0x12, 0xaf, 0x7c, + 0x8c, 0x24, 0xc3, 0x9f, 0x1c, 0xf2, 0x39, 0x10, 0x8b, 0x00, 0x21, 0x0c, + 0xe4, 0x12, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x20, 0x0b, 0x02, 0x68, 0x44, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x14, 0x08, 0x14, 0x04, 0x1b, 0x10, 0x12, + 0x3a, 0x18, 0x42, 0x03, 0x4a, 0x24, 0x00, 0x71, 0x00, 0x1f, 0x03, 0x00, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x13, 0x0c, 0x04, 0x04, 0x1e, 0x10, 0x03, + 0x80, 0x43, 0xda, 0x0a, 0x20, 0x00, 0x0a, 0x24, 0x40, 0x01, 0xc2, 0xc6, + 0xe6, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, + 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, + 0x28, 0x45, 0xce, 0x0c, 0x6f, 0xf1, 0x03, 0x1c, 0x83, 0x30, 0x02, 0x14, + 0x80, 0x30, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x2d, 0x09, 0x04, 0x00, + 0x0f, 0x08, 0x90, 0x00, 0x19, 0x08, 0x51, 0x00, 0x38, 0x16, 0x80, 0x10, + 0x03, 0xf0, 0x39, 0x16, 0x80, 0x10, 0x81, 0xc3, 0xa1, 0x41, 0xaa, 0x0e, + 0x2f, 0xf3, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, + 0x02, 0x30, 0xe9, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, + 0x21, 0xad, 0xc6, 0xc7, 0xee, 0xc3, 0xa2, 0xc1, 0x50, 0x41, 0x28, 0x45, + 0x10, 0x40, 0x2c, 0x70, 0x10, 0xda, 0x60, 0x40, 0x0a, 0x23, 0x00, 0x21, + 0x2a, 0x0e, 0x2f, 0xf8, 0x68, 0x46, 0x4a, 0x27, 0x40, 0x10, 0x4a, 0x24, + 0xc0, 0x70, 0x02, 0x1c, 0x03, 0x35, 0x01, 0x1c, 0x83, 0x30, 0x60, 0xc7, + 0x15, 0xed, 0x40, 0x24, 0x40, 0x31, 0x80, 0xc1, 0xa8, 0x20, 0x00, 0x02, + 0x01, 0x11, 0x82, 0x04, 0x38, 0x22, 0x42, 0x04, 0x01, 0x18, 0x92, 0x00, + 0x5e, 0x0e, 0xef, 0xf4, 0x40, 0x24, 0x40, 0x31, 0xe1, 0x08, 0x30, 0x00, + 0xad, 0x70, 0xad, 0x72, 0x69, 0xf0, 0x0c, 0x70, 0xa8, 0x20, 0xc0, 0x02, + 0x80, 0xc1, 0x09, 0x61, 0x40, 0x24, 0x42, 0x31, 0x1a, 0x62, 0x04, 0x71, + 0x38, 0x21, 0x41, 0x04, 0x20, 0xaa, 0x36, 0x0e, 0xef, 0xf4, 0x40, 0x24, + 0x40, 0x31, 0x4e, 0x70, 0xad, 0x70, 0x06, 0xe8, 0xad, 0x72, 0x01, 0x1e, + 0x83, 0x10, 0xe0, 0xae, 0x06, 0x40, 0x39, 0x08, 0x91, 0x01, 0x0c, 0x70, + 0xf0, 0x26, 0x01, 0x70, 0x13, 0x00, 0xe4, 0x6c, 0x40, 0x24, 0xc2, 0x30, + 0x14, 0x71, 0x1a, 0x62, 0x0c, 0x71, 0x38, 0x21, 0x41, 0x04, 0x20, 0xaa, + 0xf4, 0xf5, 0x9e, 0x0e, 0xaf, 0xf5, 0x40, 0x24, 0xc0, 0x30, 0x07, 0xe8, + 0xb8, 0x66, 0xa5, 0x72, 0x01, 0x18, 0x83, 0x00, 0xe0, 0xa8, 0x06, 0x40, + 0x37, 0x08, 0xf1, 0x01, 0x4a, 0x20, 0x00, 0x00, 0xf0, 0x26, 0x01, 0x70, + 0x13, 0x00, 0xec, 0x6c, 0x40, 0x24, 0xc2, 0x30, 0x14, 0x71, 0x1a, 0x62, + 0x0c, 0x71, 0x38, 0x21, 0x41, 0x04, 0x20, 0xaa, 0xf4, 0xf5, 0x66, 0x0e, + 0xaf, 0xf5, 0x40, 0x24, 0xc0, 0x30, 0x07, 0xe8, 0xb8, 0x66, 0xa5, 0x72, + 0x01, 0x18, 0x83, 0x00, 0xe0, 0xa8, 0x06, 0x40, 0x50, 0x20, 0x00, 0x00, + 0x63, 0x08, 0x11, 0x02, 0xf0, 0x26, 0x81, 0x74, 0x13, 0x00, 0xf4, 0x6c, + 0x40, 0x24, 0xc0, 0x30, 0x56, 0x71, 0x00, 0x20, 0x82, 0x04, 0x4e, 0x71, + 0x38, 0x21, 0x40, 0x04, 0x00, 0xaa, 0xf4, 0xf5, 0x2a, 0x0e, 0xaf, 0xf5, + 0x40, 0x24, 0xc0, 0x30, 0x1d, 0xe8, 0xbe, 0x66, 0xa5, 0x72, 0x01, 0x1e, + 0x83, 0x10, 0x18, 0xf0, 0x11, 0x09, 0x71, 0x25, 0x06, 0x40, 0x0d, 0x08, + 0x91, 0x01, 0xe0, 0xae, 0x06, 0x40, 0xad, 0x71, 0x11, 0x09, 0xd1, 0x25, + 0x0d, 0x08, 0x51, 0x02, 0xb8, 0x66, 0xe0, 0xa8, 0xa5, 0x71, 0x06, 0x40, + 0x0f, 0x09, 0x91, 0x25, 0x0b, 0x08, 0xf1, 0x01, 0xbe, 0x66, 0xa5, 0x71, + 0xe0, 0xae, 0x00, 0x1b, 0x40, 0x23, 0xce, 0xc7, 0xe6, 0xc3, 0xa2, 0xc1, + 0x08, 0x46, 0x08, 0x16, 0x00, 0x14, 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, + 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, + 0x06, 0x0b, 0x6f, 0xf1, 0x03, 0x1c, 0x83, 0x30, 0x02, 0x14, 0x80, 0x30, + 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x37, 0x09, 0x04, 0x00, 0x1b, 0x08, + 0xb0, 0x00, 0x81, 0xc3, 0x1f, 0x08, 0x71, 0x00, 0x81, 0xc3, 0xc1, 0x40, + 0xa1, 0x41, 0x6a, 0x0d, 0xaf, 0xf5, 0xe1, 0x42, 0x07, 0xf0, 0x32, 0x16, + 0x80, 0x10, 0xa1, 0x41, 0xda, 0x0c, 0x2f, 0xf3, 0xe1, 0x42, 0x02, 0x14, + 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xe4, 0xf1, 0x01, 0xc0, + 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc6, 0xc7, 0xe0, 0x78, + 0x99, 0x04, 0x40, 0x01, 0x00, 0x42, 0x9f, 0xe1, 0x0c, 0x70, 0xe0, 0x20, + 0xcd, 0x07, 0x0c, 0x71, 0xe0, 0x7f, 0x38, 0x1a, 0x42, 0x00, 0xe0, 0x78, + 0xe6, 0xc3, 0x82, 0x24, 0x0c, 0x37, 0x48, 0x47, 0x08, 0x45, 0x87, 0xc0, + 0x8a, 0x22, 0x0c, 0x00, 0x02, 0x0e, 0x2f, 0xea, 0x28, 0x46, 0x00, 0x85, + 0x40, 0x24, 0x83, 0x34, 0x40, 0x24, 0x04, 0x33, 0x40, 0x24, 0x05, 0x36, + 0x40, 0x24, 0x06, 0x35, 0x40, 0x24, 0xc7, 0x34, 0xc1, 0x41, 0xe1, 0x42, + 0x0e, 0x0a, 0x6f, 0xf1, 0x12, 0x1c, 0x83, 0x30, 0x03, 0xc0, 0x03, 0xe8, + 0xc6, 0xc7, 0x13, 0x14, 0x8e, 0x30, 0x12, 0x14, 0x81, 0x30, 0xcf, 0x78, + 0x35, 0x09, 0x04, 0x00, 0x23, 0x08, 0xb0, 0x00, 0x85, 0xc1, 0x29, 0x08, + 0x71, 0x00, 0x87, 0xc0, 0x85, 0xc1, 0xae, 0x0c, 0xaf, 0xf5, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x42, 0xa5, 0x23, 0xa5, 0x04, 0xa5, + 0x06, 0xf0, 0x2a, 0x0c, 0x2f, 0xf3, 0x87, 0xc0, 0x3a, 0x1d, 0x02, 0x10, + 0xc5, 0x71, 0xe5, 0xf1, 0x03, 0xc0, 0xc6, 0xc7, 0xee, 0xc3, 0xaa, 0xc1, + 0x38, 0x10, 0x8c, 0x00, 0x08, 0x45, 0x88, 0x47, 0x68, 0x46, 0x50, 0x41, + 0x41, 0x0c, 0x3f, 0x10, 0x30, 0x40, 0x4a, 0x24, 0xc0, 0x70, 0x02, 0x40, + 0x0a, 0x21, 0xc0, 0x03, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x02, 0x04, + 0x04, 0x19, 0x90, 0x00, 0x3a, 0x15, 0x80, 0x10, 0x4a, 0x24, 0xc0, 0x70, + 0x48, 0x30, 0x02, 0x00, 0xc1, 0x40, 0x40, 0xa1, 0x0a, 0x21, 0x40, 0x04, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x03, 0x04, 0x04, 0x18, 0xd0, 0x00, + 0x40, 0xa0, 0x68, 0xf0, 0x42, 0x85, 0x23, 0x85, 0x04, 0x85, 0x3a, 0x15, + 0x92, 0x10, 0x43, 0xc2, 0x44, 0xc1, 0x1b, 0x0c, 0xff, 0x10, 0x45, 0xc0, + 0x03, 0xc2, 0x04, 0xc1, 0x05, 0xc0, 0x0a, 0x23, 0x80, 0x24, 0x40, 0xc2, + 0x41, 0xc1, 0x42, 0xc0, 0x13, 0xf0, 0x4f, 0x85, 0x30, 0x85, 0x11, 0x85, + 0x48, 0x15, 0x93, 0x10, 0x40, 0xc2, 0x41, 0xc1, 0x17, 0x0c, 0x3e, 0x11, + 0x42, 0xc0, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x0a, 0x22, 0xc0, 0x24, + 0x43, 0xc2, 0x44, 0xc1, 0x45, 0xc0, 0x4a, 0x24, 0x00, 0x71, 0x22, 0x41, + 0x0a, 0x20, 0x80, 0x03, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x02, 0x04, + 0x04, 0x18, 0x90, 0x00, 0x80, 0xc2, 0x2c, 0x73, 0x22, 0x40, 0x06, 0x0c, + 0x2f, 0xf2, 0xc1, 0x43, 0x60, 0x86, 0x41, 0x86, 0x48, 0x33, 0x00, 0x20, + 0x22, 0x86, 0x4a, 0x24, 0x00, 0x71, 0x49, 0xc0, 0x46, 0xc3, 0x4a, 0x20, + 0x00, 0x00, 0x86, 0xc3, 0x47, 0xc2, 0x48, 0xc1, 0xa8, 0x20, 0x00, 0x03, + 0x01, 0x4b, 0x15, 0x26, 0x02, 0x10, 0x20, 0xa2, 0xf0, 0x20, 0x01, 0x20, + 0x15, 0x27, 0x02, 0x10, 0x04, 0x71, 0x20, 0xa2, 0x83, 0xc2, 0x2c, 0x73, + 0x02, 0x40, 0xc6, 0x0b, 0x2f, 0xf2, 0xe1, 0x43, 0x41, 0x87, 0x22, 0x87, + 0x60, 0x87, 0x48, 0x32, 0x00, 0x20, 0x47, 0xc2, 0x49, 0xc0, 0x48, 0xc1, + 0x86, 0xc1, 0x10, 0xda, 0xe1, 0x40, 0x82, 0x0c, 0x2f, 0xea, 0x46, 0xc3, + 0x38, 0x15, 0x8c, 0x10, 0x27, 0x0c, 0x7f, 0x10, 0x2c, 0x74, 0x21, 0x0c, + 0xbe, 0x10, 0x14, 0xe5, 0x2c, 0x74, 0x02, 0x40, 0xe1, 0x43, 0x56, 0x0d, + 0x6f, 0xf3, 0xa1, 0x42, 0x2c, 0x74, 0x22, 0x40, 0xa1, 0x42, 0x4a, 0x0d, + 0x6f, 0xf3, 0xc1, 0x43, 0xce, 0xc7, 0x14, 0xe5, 0x02, 0x40, 0xe1, 0x43, + 0xa2, 0x0b, 0x2f, 0xf2, 0xa1, 0x42, 0x2c, 0x74, 0x22, 0x40, 0xa1, 0x42, + 0x96, 0x0b, 0x2f, 0xf2, 0xc1, 0x43, 0xce, 0xc7, 0x4a, 0x24, 0xc0, 0x70, + 0x40, 0x20, 0x01, 0x0f, 0x40, 0x20, 0x02, 0x02, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x12, 0x03, 0x04, 0x04, 0x19, 0xd0, 0x00, 0x3a, 0x10, 0x81, 0x00, + 0x04, 0x18, 0x43, 0x00, 0xe0, 0x7f, 0x48, 0x18, 0x42, 0x00, 0xe0, 0x78, + 0xec, 0xc3, 0xa9, 0xc1, 0x30, 0x40, 0x86, 0xc1, 0x48, 0x47, 0xde, 0x08, + 0x6f, 0xf8, 0x08, 0x45, 0x02, 0x08, 0x2f, 0xf9, 0x86, 0xc0, 0xd3, 0x41, + 0xdb, 0x2e, 0xff, 0xe6, 0x04, 0x30, 0x40, 0x84, 0xcd, 0x70, 0xd7, 0xf6, + 0x46, 0x0f, 0x8f, 0xf6, 0x35, 0x08, 0x13, 0x22, 0x53, 0x08, 0x50, 0x20, + 0x65, 0x08, 0x90, 0x20, 0xa5, 0x08, 0x11, 0x21, 0x20, 0x85, 0x62, 0x85, + 0x41, 0x85, 0x52, 0x21, 0xc1, 0x07, 0x41, 0xc6, 0x40, 0xc3, 0x00, 0x30, + 0x8e, 0x00, 0x42, 0xc1, 0x46, 0xf0, 0x40, 0x85, 0x21, 0x85, 0x02, 0x85, + 0x40, 0xc2, 0x41, 0xc1, 0x42, 0xc0, 0x40, 0xf0, 0x4f, 0x08, 0x10, 0x22, + 0x61, 0x08, 0x10, 0x28, 0x75, 0x08, 0x11, 0x24, 0x21, 0x85, 0x60, 0x85, + 0x42, 0x85, 0x52, 0x21, 0xc1, 0x07, 0x42, 0xc6, 0x41, 0xc3, 0x00, 0x30, + 0x8e, 0x00, 0x40, 0xc1, 0x2e, 0xf0, 0x22, 0x85, 0x61, 0x85, 0x40, 0x85, + 0x52, 0x21, 0xc1, 0x07, 0x40, 0xc6, 0x42, 0xc3, 0x00, 0x30, 0x8e, 0x00, + 0x41, 0xc1, 0x24, 0xf0, 0x40, 0x85, 0x21, 0x85, 0x62, 0x85, 0x00, 0x30, + 0x80, 0x00, 0x52, 0x21, 0xc1, 0x07, 0x40, 0xc6, 0x41, 0xc3, 0x42, 0xc1, + 0x16, 0xf0, 0x41, 0x85, 0x22, 0x85, 0x60, 0x85, 0x00, 0x30, 0x80, 0x00, + 0x52, 0x21, 0xc1, 0x07, 0x41, 0xc6, 0x42, 0xc3, 0x40, 0xc1, 0x0c, 0xf0, + 0x42, 0x85, 0x20, 0x85, 0x61, 0x85, 0x00, 0x30, 0x80, 0x00, 0x52, 0x21, + 0xc1, 0x07, 0x42, 0xc6, 0x40, 0xc3, 0x41, 0xc1, 0x52, 0x20, 0xce, 0x07, + 0x80, 0xc0, 0x83, 0xc1, 0x0a, 0x08, 0x6f, 0xf8, 0x40, 0x24, 0x12, 0x30, + 0xd3, 0x40, 0x80, 0x3f, 0x00, 0x00, 0x01, 0x36, 0x01, 0x14, 0x50, 0x20, + 0xc0, 0x25, 0x00, 0x31, 0x00, 0x00, 0x2f, 0x35, 0x00, 0x10, 0x1a, 0x0f, + 0xef, 0xf8, 0x83, 0xc0, 0x04, 0x30, 0x40, 0x84, 0xd9, 0xf6, 0x04, 0x36, + 0x00, 0x94, 0xca, 0x26, 0x09, 0x14, 0x01, 0x30, 0x01, 0x00, 0x4a, 0x24, + 0xc0, 0x70, 0x02, 0x30, 0x80, 0x23, 0x07, 0x30, 0x40, 0x00, 0x2f, 0x31, + 0x00, 0x00, 0xa8, 0x20, 0x40, 0x02, 0x04, 0x12, 0x00, 0x24, 0x00, 0x31, + 0x00, 0x00, 0x04, 0x1f, 0x10, 0x10, 0xa0, 0xa7, 0xcc, 0xc7, 0x0c, 0x70, + 0xa3, 0xa7, 0x02, 0xa7, 0x01, 0xa7, 0x00, 0xa7, 0xcc, 0xc7, 0xe0, 0x78, + 0xf4, 0xc3, 0xb5, 0xc1, 0x28, 0x46, 0x10, 0x45, 0x92, 0xc1, 0xc1, 0x40, + 0x0a, 0x24, 0x40, 0x21, 0x0a, 0x23, 0x00, 0x21, 0x68, 0x47, 0x8e, 0x0f, + 0x2f, 0xf8, 0x48, 0x45, 0x50, 0x14, 0x11, 0x30, 0x4c, 0x14, 0x12, 0x30, + 0x48, 0x14, 0x10, 0x30, 0x01, 0x86, 0x01, 0x32, 0x56, 0x24, 0x22, 0x86, + 0x00, 0x30, 0x82, 0x2f, 0x6b, 0x3c, 0xfa, 0xed, 0x52, 0x20, 0xc0, 0x07, + 0x04, 0x36, 0x80, 0xa0, 0x4c, 0xf7, 0x01, 0x31, 0x02, 0x24, 0x6c, 0x70, + 0x2f, 0x32, 0x80, 0x00, 0x04, 0x31, 0xc0, 0x80, 0x40, 0x41, 0x04, 0xf6, + 0x52, 0x22, 0xc1, 0x07, 0x7a, 0x0a, 0x8f, 0xf2, 0x00, 0xa5, 0x00, 0x86, + 0x72, 0x0a, 0xaf, 0xf2, 0x2f, 0x31, 0x80, 0x05, 0x00, 0xa7, 0x00, 0x85, + 0x8d, 0x70, 0x52, 0x20, 0xc0, 0x07, 0x00, 0xa5, 0x02, 0x86, 0x04, 0x30, + 0x00, 0x83, 0x87, 0xf7, 0x00, 0x87, 0x52, 0x20, 0xc0, 0x07, 0x00, 0xa7, + 0x02, 0x86, 0x01, 0x32, 0x01, 0x24, 0x3f, 0xda, 0x18, 0xba, 0x04, 0x31, + 0x80, 0x80, 0xc4, 0x30, 0x05, 0x83, 0x44, 0xf7, 0x61, 0x86, 0x0d, 0xf0, + 0x01, 0x31, 0x01, 0x24, 0x61, 0x86, 0x04, 0x31, 0x80, 0x80, 0xc4, 0x33, + 0x05, 0x83, 0xde, 0x00, 0x26, 0x00, 0x04, 0x33, 0x00, 0x83, 0x20, 0x86, + 0x4a, 0xc0, 0x88, 0xc0, 0x48, 0xc1, 0x84, 0xc2, 0x20, 0xd9, 0x02, 0x0e, + 0xef, 0xff, 0x49, 0xc3, 0x80, 0xc0, 0x84, 0xc1, 0x02, 0x0a, 0x2f, 0xea, + 0x10, 0xda, 0x00, 0xc1, 0x02, 0xc0, 0x01, 0xc3, 0x03, 0xc2, 0x46, 0xc1, + 0x52, 0x20, 0xc1, 0x07, 0x52, 0x23, 0xc0, 0x07, 0x45, 0xc2, 0x44, 0xc1, + 0x47, 0xc0, 0x84, 0xc1, 0x8b, 0xc2, 0xe6, 0x08, 0x20, 0x00, 0xa2, 0x40, + 0x0e, 0xc1, 0xe2, 0x09, 0xaf, 0xf2, 0x0d, 0xc0, 0x00, 0x30, 0x80, 0x0f, + 0x00, 0xc0, 0x00, 0x00, 0x4c, 0x70, 0x04, 0x30, 0x80, 0x80, 0x46, 0xf7, + 0x01, 0x30, 0x80, 0x0f, 0xc9, 0x40, 0xdb, 0x0f, 0x00, 0x1b, 0x00, 0x20, + 0x00, 0x86, 0x22, 0x86, 0x4f, 0xc0, 0x01, 0x86, 0x04, 0x31, 0x80, 0x80, + 0x84, 0xc2, 0x50, 0xc0, 0x8f, 0xc0, 0x51, 0xc1, 0x56, 0xf7, 0x96, 0x0d, + 0xef, 0xff, 0x20, 0xd9, 0x80, 0xc0, 0x84, 0xc1, 0x96, 0x09, 0x2f, 0xea, + 0x10, 0xda, 0x02, 0xc1, 0x01, 0xc0, 0x00, 0xc3, 0x03, 0xc2, 0x45, 0xc1, + 0x52, 0x20, 0xc1, 0x07, 0x52, 0x23, 0xc0, 0x07, 0x44, 0xc2, 0x46, 0xc1, + 0x47, 0xc0, 0x05, 0xf0, 0x6a, 0x0d, 0xef, 0xff, 0x10, 0xd9, 0x84, 0xc1, + 0x8b, 0xc2, 0x72, 0x08, 0x20, 0x00, 0xa2, 0x40, 0x0e, 0xc1, 0x6e, 0x09, + 0xaf, 0xf2, 0x0d, 0xc0, 0x01, 0x30, 0x01, 0x00, 0x0c, 0x70, 0x04, 0x31, + 0x00, 0x80, 0x46, 0xf7, 0x01, 0x31, 0x81, 0x0f, 0xc9, 0x40, 0xdb, 0x0f, + 0x00, 0x1c, 0x40, 0x20, 0xd4, 0xc7, 0x59, 0xf7, 0xc3, 0x42, 0x35, 0xbf, + 0xf3, 0x04, 0x04, 0x33, 0x80, 0x80, 0xd3, 0xf6, 0x20, 0x86, 0x04, 0x30, + 0x00, 0x83, 0x50, 0xf7, 0x04, 0x30, 0x80, 0x80, 0xcc, 0xf6, 0x04, 0x31, + 0x80, 0x8f, 0x35, 0x3f, 0xf3, 0x04, 0x48, 0xf7, 0x04, 0x31, 0x80, 0x80, + 0x02, 0x07, 0xc9, 0xff, 0x02, 0xf0, 0x20, 0x86, 0x4a, 0xc0, 0x48, 0xc1, + 0x88, 0xc0, 0x84, 0xc2, 0x10, 0xd9, 0xfe, 0x0c, 0xef, 0xff, 0x49, 0xc3, + 0x8f, 0xf1, 0xe0, 0x78, 0xe6, 0xc0, 0x80, 0x81, 0x63, 0x80, 0xc1, 0x81, + 0xa2, 0x80, 0x00, 0x33, 0x0b, 0x03, 0x83, 0x81, 0x60, 0x80, 0x00, 0x33, + 0x03, 0x03, 0x01, 0x33, 0xc3, 0x02, 0x00, 0x35, 0x8c, 0x13, 0xc2, 0x81, + 0xa1, 0x80, 0x02, 0x33, 0x0c, 0x03, 0x00, 0x35, 0x83, 0x13, 0x01, 0x34, + 0xc3, 0x10, 0x60, 0xa2, 0x80, 0x81, 0x62, 0x80, 0xc3, 0x81, 0xa1, 0x80, + 0x00, 0x33, 0x0c, 0x03, 0x00, 0x35, 0x83, 0x13, 0xc2, 0x81, 0x01, 0x33, + 0x0b, 0x03, 0x81, 0x81, 0x63, 0x80, 0xa0, 0x80, 0x00, 0x33, 0x03, 0x03, + 0x01, 0x33, 0xc3, 0x10, 0x00, 0x35, 0x8c, 0x13, 0x02, 0x33, 0x03, 0x03, + 0x61, 0xa2, 0x80, 0x81, 0x61, 0x80, 0xc3, 0x81, 0xa2, 0x80, 0x00, 0x33, + 0x0b, 0x03, 0x80, 0x80, 0x00, 0x35, 0x83, 0x13, 0xa1, 0x81, 0x02, 0x33, + 0xcb, 0x02, 0xc2, 0x81, 0x00, 0x34, 0x43, 0x13, 0xa3, 0x80, 0x01, 0x33, + 0xcc, 0x10, 0x00, 0x35, 0x83, 0x13, 0x01, 0x34, 0xc3, 0x10, 0x62, 0xa2, + 0x80, 0x81, 0x60, 0x80, 0xc3, 0x81, 0xa3, 0x80, 0x04, 0x11, 0x0b, 0x00, + 0xe1, 0x80, 0x00, 0x33, 0x09, 0x03, 0x00, 0x35, 0x88, 0x13, 0x62, 0x81, + 0x22, 0x80, 0x00, 0x37, 0xcc, 0x12, 0x02, 0x30, 0x40, 0x12, 0x00, 0x31, + 0xc1, 0x00, 0x02, 0x30, 0x00, 0x03, 0x02, 0x30, 0x40, 0x00, 0x03, 0xa2, + 0xc6, 0xc4, 0xe0, 0x78, 0x40, 0x81, 0x02, 0xa1, 0x54, 0x70, 0xe0, 0x7c, + 0x21, 0x81, 0x00, 0x7a, 0xee, 0xc3, 0xa5, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x40, 0x24, 0x83, 0x32, 0x40, 0x24, 0x04, 0x33, 0x40, 0x24, 0x05, 0x34, + 0x40, 0x24, 0x06, 0x30, 0x40, 0x24, 0xc7, 0x32, 0x50, 0x43, 0x30, 0x40, + 0x3e, 0x0c, 0x2f, 0xf1, 0x0a, 0x1c, 0x83, 0x30, 0x0c, 0x14, 0x11, 0x30, + 0x63, 0x09, 0x31, 0x20, 0x2c, 0x70, 0x0a, 0x14, 0x92, 0x30, 0x0b, 0x14, + 0x8f, 0x30, 0x2e, 0x70, 0xef, 0x78, 0x53, 0x0a, 0x04, 0x20, 0xa7, 0xe9, + 0x21, 0x08, 0x70, 0x00, 0x00, 0xc5, 0x31, 0x08, 0xb1, 0x00, 0x00, 0x20, + 0x41, 0x23, 0x81, 0xc0, 0xde, 0x0f, 0xef, 0xe9, 0x4c, 0x74, 0x01, 0xc0, + 0xa5, 0x74, 0x40, 0xc5, 0x07, 0xa6, 0x0c, 0xf0, 0x00, 0x20, 0x41, 0x23, + 0x81, 0xc0, 0xca, 0x0f, 0xef, 0xe9, 0x4c, 0x74, 0x01, 0xc0, 0xa5, 0x74, + 0x40, 0xc5, 0x02, 0xa6, 0x72, 0x75, 0x8a, 0x20, 0x3e, 0x06, 0xca, 0x21, + 0x0d, 0x20, 0x3d, 0x23, 0x40, 0x23, 0x3c, 0x23, 0x41, 0x23, 0x1f, 0x67, + 0xd8, 0xf1, 0x22, 0x40, 0xce, 0xc7, 0xe0, 0x78, 0xe4, 0xc3, 0xa7, 0xc1, + 0x4a, 0x24, 0xc0, 0x70, 0x28, 0x46, 0x08, 0x45, 0x0c, 0x70, 0x84, 0xc4, + 0xa8, 0x20, 0x00, 0x03, 0x15, 0x25, 0x01, 0x10, 0x03, 0x4e, 0x24, 0x81, + 0x15, 0x24, 0x02, 0x10, 0x04, 0x71, 0x02, 0x33, 0x41, 0x00, 0x20, 0xa2, + 0x84, 0xc0, 0xda, 0x08, 0x6f, 0xf3, 0x81, 0xc1, 0x04, 0x8d, 0x12, 0xe8, + 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x4d, 0xc1, 0x40, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x10, 0x02, 0x04, 0x04, 0x19, 0x90, 0x00, 0x46, 0xd8, 0x00, 0xa1, + 0x0c, 0x1d, 0x01, 0x10, 0x04, 0x1d, 0x03, 0x10, 0x4a, 0x24, 0xc0, 0x70, + 0x40, 0x25, 0x00, 0x14, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x16, 0x01, 0x14, + 0x04, 0x18, 0x50, 0x00, 0x00, 0x80, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x24, + 0x41, 0x30, 0x48, 0x30, 0x03, 0x00, 0x81, 0xc0, 0xa8, 0x20, 0x80, 0x02, + 0x04, 0x10, 0x02, 0x04, 0x04, 0x32, 0xc0, 0x80, 0x6f, 0x22, 0x0b, 0x00, + 0x01, 0x19, 0x92, 0x00, 0x66, 0x0c, 0x6f, 0xf2, 0x40, 0x24, 0x40, 0x30, + 0x14, 0x70, 0x0c, 0x70, 0x2c, 0x70, 0x04, 0xf2, 0x23, 0x85, 0x24, 0x71, + 0x42, 0x85, 0x0d, 0x0a, 0x65, 0x00, 0x23, 0xa5, 0x03, 0xa5, 0x81, 0xd8, + 0xc4, 0xc7, 0xe0, 0x78, 0xe6, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, 0x5e, 0x0b, 0x2f, 0xf1, 0x03, 0x1c, + 0x83, 0x30, 0x02, 0x14, 0x80, 0x30, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, + 0x29, 0x09, 0x04, 0x00, 0x0d, 0x08, 0x90, 0x00, 0x15, 0x08, 0x51, 0x00, + 0x02, 0x86, 0x03, 0xf0, 0x07, 0x86, 0x81, 0xc3, 0xa1, 0x41, 0xb6, 0x0b, + 0xef, 0xf7, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, + 0x02, 0x30, 0xeb, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, + 0x21, 0xad, 0xc6, 0xc7, 0xe2, 0xc2, 0x60, 0x40, 0x2c, 0x70, 0x10, 0xda, + 0xca, 0x0c, 0xef, 0xf7, 0x88, 0x45, 0x00, 0x1d, 0x01, 0x10, 0xc2, 0xc6, + 0xe8, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, 0x60, 0x44, 0x40, 0x24, + 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, + 0x28, 0x45, 0xea, 0x0a, 0x2f, 0xf1, 0x03, 0x1c, 0x83, 0x30, 0x02, 0x14, + 0x80, 0x30, 0x40, 0x26, 0x10, 0x14, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, + 0x33, 0x09, 0x04, 0x00, 0x19, 0x08, 0xb0, 0x00, 0x81, 0xc3, 0x1f, 0x08, + 0x71, 0x00, 0x81, 0xc3, 0x03, 0x86, 0xa1, 0x41, 0x3e, 0x0b, 0xef, 0xf7, + 0xe1, 0x42, 0x07, 0xf0, 0x02, 0x40, 0xa1, 0x41, 0x3a, 0x0d, 0x6f, 0xf5, + 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, + 0xe5, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, + 0xc8, 0xc7, 0xe0, 0x78, 0xfa, 0xdb, 0x46, 0xda, 0x2c, 0x70, 0x04, 0x18, + 0x43, 0x00, 0x62, 0xa0, 0x47, 0xa0, 0x23, 0xa0, 0x24, 0xa0, 0x25, 0xa0, + 0xe0, 0x7f, 0x26, 0xa0, 0xea, 0xc3, 0x82, 0x24, 0x0c, 0x39, 0x50, 0x41, + 0x08, 0x46, 0x89, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0xe2, 0x0d, 0xef, 0xe9, + 0x28, 0x45, 0x00, 0x86, 0x40, 0x24, 0xc3, 0x34, 0x40, 0x24, 0x04, 0x37, + 0x40, 0x24, 0x05, 0x38, 0x40, 0x24, 0x06, 0x33, 0x40, 0x24, 0xc7, 0x36, + 0xa1, 0x41, 0x22, 0x42, 0xee, 0x09, 0x2f, 0xf1, 0x13, 0x1c, 0x83, 0x30, + 0x1c, 0x14, 0x10, 0x30, 0x67, 0x08, 0x31, 0x20, 0x2c, 0x70, 0x1b, 0x14, + 0x8f, 0x30, 0x0e, 0x70, 0xad, 0xe9, 0x13, 0x14, 0x81, 0x30, 0xef, 0x78, + 0x53, 0x09, 0x04, 0x00, 0x23, 0x08, 0xb0, 0x00, 0x83, 0xc1, 0x33, 0x08, + 0x71, 0x00, 0x89, 0xc1, 0x03, 0xc5, 0x85, 0xc0, 0xb9, 0x61, 0x8e, 0x0d, + 0xef, 0xe9, 0x4c, 0x74, 0x05, 0xc1, 0x04, 0x6d, 0x43, 0xc0, 0x23, 0xa6, + 0x0b, 0xf0, 0x89, 0xc0, 0x6e, 0x0c, 0x6f, 0xf5, 0x80, 0xc2, 0x00, 0xc2, + 0x01, 0xc1, 0x02, 0xc0, 0x44, 0xa6, 0x25, 0xa6, 0x06, 0xa6, 0x03, 0xc0, + 0x8a, 0x21, 0x3e, 0x06, 0x32, 0x70, 0xca, 0x20, 0x4d, 0x20, 0x3c, 0x21, + 0x01, 0x20, 0x3d, 0x21, 0x00, 0x20, 0x1f, 0x67, 0xd4, 0xf1, 0x02, 0x40, + 0xca, 0xc7, 0xe0, 0x78, 0x48, 0x31, 0x01, 0x00, 0x07, 0x36, 0x42, 0x70, + 0x48, 0x47, 0x00, 0x00, 0x2c, 0x70, 0x04, 0x32, 0x40, 0x80, 0xc7, 0xf6, + 0x01, 0x32, 0x81, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x32, + 0x81, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x18, + 0x43, 0x00, 0x48, 0x31, 0x81, 0x00, 0x48, 0x31, 0x41, 0x02, 0x35, 0x79, + 0xe0, 0x7f, 0x22, 0xa0, 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x34, 0x48, 0x47, + 0x08, 0x45, 0x84, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0xfe, 0x0c, 0xef, 0xe9, + 0x28, 0x46, 0x00, 0x85, 0x40, 0x24, 0x83, 0x30, 0x40, 0x24, 0x04, 0x32, + 0x40, 0x24, 0x05, 0x33, 0x40, 0x24, 0x06, 0x31, 0x40, 0x24, 0xc7, 0x30, + 0xc1, 0x41, 0xe1, 0x42, 0x0a, 0x09, 0x2f, 0xf1, 0x02, 0x1c, 0x43, 0x30, + 0x02, 0xc6, 0xcb, 0x0e, 0x31, 0x10, 0x55, 0x25, 0x50, 0x18, 0x03, 0x14, + 0x8e, 0x30, 0x02, 0x14, 0x80, 0x30, 0x2b, 0x08, 0x84, 0x03, 0xcf, 0x78, + 0x11, 0x08, 0x71, 0x00, 0x84, 0xc0, 0x7e, 0x08, 0x6f, 0xfa, 0x81, 0xc1, + 0x20, 0x18, 0x02, 0x20, 0x01, 0xc0, 0x9f, 0x0f, 0x24, 0x10, 0xc5, 0x71, + 0x02, 0x14, 0x80, 0x30, 0xcf, 0x79, 0xe3, 0x08, 0x45, 0x80, 0x20, 0x10, + 0x80, 0x20, 0x8f, 0x08, 0x30, 0x00, 0xcd, 0x70, 0xcb, 0x41, 0x32, 0x01, + 0xe6, 0x78, 0xcb, 0x40, 0x00, 0x00, 0x9c, 0x6c, 0xcb, 0x43, 0xef, 0x41, + 0x96, 0xe8, 0xcb, 0x47, 0x5f, 0x05, 0xbe, 0x0a, 0xcb, 0x44, 0x64, 0x75, + 0x84, 0x00, 0xc3, 0x43, 0x5f, 0x05, 0x4a, 0x00, 0xc3, 0x42, 0x0c, 0x00, + 0x0c, 0x00, 0xc3, 0x41, 0xaa, 0x7e, 0xa0, 0x00, 0x8a, 0x26, 0x04, 0x00, + 0x7d, 0xd8, 0x1c, 0x18, 0x80, 0x23, 0x18, 0x18, 0x80, 0x23, 0x3e, 0x1d, + 0xc5, 0x11, 0x58, 0x1d, 0x45, 0x10, 0x44, 0x1d, 0x84, 0x13, 0xc5, 0xa5, + 0xd7, 0xb5, 0xd9, 0xb5, 0xdb, 0xb5, 0xdd, 0xb5, 0x20, 0x1d, 0x40, 0x12, + 0x26, 0x1d, 0x04, 0x12, 0x54, 0x1d, 0xc0, 0x12, 0xf4, 0xa5, 0x8a, 0xa5, + 0x73, 0xa5, 0x46, 0xa5, 0x30, 0xa5, 0x48, 0x1d, 0x84, 0x11, 0x1f, 0xa5, + 0x00, 0x18, 0x00, 0x20, 0x2e, 0x0b, 0x60, 0x03, 0x0c, 0x70, 0x9e, 0x20, + 0x06, 0x04, 0x1a, 0xb5, 0x03, 0xf0, 0x8a, 0x26, 0x3e, 0x16, 0xc1, 0x40, + 0xc8, 0xc7, 0xe0, 0x78, 0xfa, 0xc3, 0xa8, 0xc1, 0x4a, 0x24, 0x00, 0x71, + 0x0a, 0x27, 0x80, 0x21, 0x0a, 0x23, 0x40, 0x21, 0x0a, 0x20, 0x00, 0x31, + 0x78, 0x41, 0x50, 0x46, 0x08, 0x46, 0x55, 0x20, 0x0d, 0x08, 0x80, 0xc2, + 0xed, 0x70, 0xd3, 0x44, 0x00, 0x3f, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x06, + 0x04, 0x11, 0x00, 0x04, 0x00, 0x30, 0x80, 0x0f, 0x03, 0x40, 0x6f, 0x12, + 0x04, 0x30, 0xc0, 0x83, 0xc4, 0xf6, 0x01, 0x30, 0x00, 0x05, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, + 0x48, 0x30, 0x80, 0x00, 0x48, 0x30, 0xc0, 0x02, 0x04, 0x1a, 0x10, 0x00, + 0x42, 0x0c, 0x20, 0x01, 0x00, 0xc0, 0x10, 0x40, 0x3a, 0x0c, 0x20, 0x01, + 0x01, 0xc0, 0x00, 0x20, 0x10, 0x20, 0x32, 0x0c, 0x20, 0x01, 0x02, 0xc0, + 0xf6, 0x08, 0x60, 0x00, 0x02, 0x70, 0x0e, 0x79, 0xc1, 0x40, 0x1e, 0x0d, + 0x20, 0x00, 0x30, 0x42, 0x28, 0x96, 0x10, 0x40, 0x10, 0x49, 0x2f, 0x20, + 0x06, 0x80, 0x0a, 0x00, 0x03, 0x00, 0x13, 0x78, 0x0e, 0x78, 0x48, 0x30, + 0x80, 0x00, 0x00, 0x30, 0x80, 0x0f, 0x00, 0x3d, 0x00, 0x00, 0x82, 0x09, + 0x4f, 0xf5, 0x48, 0x30, 0xc0, 0x02, 0x2a, 0x16, 0x55, 0x11, 0x12, 0x16, + 0x51, 0x11, 0xea, 0x0d, 0x60, 0x02, 0x0e, 0x78, 0x48, 0x30, 0x80, 0x00, + 0x66, 0x09, 0x6f, 0xf5, 0x00, 0x30, 0x00, 0x05, 0x00, 0x42, 0x22, 0x40, + 0x9a, 0x0e, 0x20, 0x00, 0xa2, 0x41, 0x2a, 0x9e, 0x8b, 0x96, 0x68, 0x9e, + 0x5b, 0x96, 0x1e, 0x21, 0x14, 0x00, 0x18, 0x24, 0xd1, 0x10, 0x09, 0xb6, + 0x05, 0xea, 0xc1, 0x40, 0x1e, 0x0d, 0x20, 0x00, 0x42, 0x41, 0x2f, 0x21, + 0x46, 0x04, 0x2f, 0x22, 0x06, 0x05, 0x3f, 0x22, 0x41, 0x00, 0x3b, 0x79, + 0x0e, 0x9e, 0x18, 0xe1, 0x35, 0x26, 0x52, 0x10, 0x5e, 0x0d, 0x20, 0x00, + 0x2c, 0x71, 0x48, 0x9e, 0x30, 0x9e, 0x0e, 0xb6, 0xb6, 0x0a, 0x20, 0x01, + 0x0f, 0x9e, 0x48, 0x96, 0x31, 0x96, 0x59, 0x61, 0x2e, 0x7b, 0x0b, 0x08, + 0xe3, 0x00, 0x0f, 0xb6, 0x2f, 0xb6, 0x33, 0x9e, 0x12, 0x9e, 0x9e, 0x0a, + 0x20, 0x01, 0x4e, 0x7a, 0x34, 0x96, 0x48, 0x96, 0x31, 0x4a, 0x2e, 0x7b, + 0x09, 0x0b, 0x23, 0x00, 0x12, 0xb6, 0x32, 0xb6, 0x35, 0x9e, 0x4e, 0x78, + 0x82, 0x0a, 0x20, 0x01, 0x02, 0x42, 0x2f, 0x9e, 0x2e, 0x70, 0x21, 0x09, + 0x23, 0x04, 0x08, 0xb6, 0x2c, 0x16, 0x80, 0x10, 0x1e, 0x1e, 0x04, 0x14, + 0x88, 0xe8, 0x0e, 0x9e, 0x0d, 0x0a, 0x03, 0x20, 0x2e, 0x71, 0xee, 0xb6, + 0x2c, 0x1e, 0x43, 0x10, 0x12, 0x9e, 0x0f, 0x08, 0x03, 0x20, 0x2c, 0x1e, + 0xc2, 0x13, 0x24, 0x1e, 0x04, 0x14, 0x18, 0x9e, 0xe6, 0x0c, 0x20, 0x00, + 0x2c, 0x71, 0x18, 0xb6, 0x53, 0x09, 0x30, 0x20, 0x00, 0x1b, 0x42, 0x24, + 0x17, 0x96, 0x6c, 0x71, 0x14, 0x70, 0x0c, 0x71, 0x0a, 0xf2, 0x39, 0x96, + 0x1a, 0x96, 0x58, 0x96, 0x2a, 0x78, 0x34, 0x6a, 0x2e, 0x79, 0x0e, 0x78, + 0x3e, 0x21, 0x00, 0x00, 0x3b, 0x96, 0x06, 0xe9, 0x5c, 0x96, 0x3d, 0x96, + 0x3d, 0x21, 0x83, 0x00, 0x15, 0xe8, 0x15, 0xeb, 0x1f, 0x96, 0x3c, 0x16, + 0x81, 0x10, 0x3d, 0x09, 0x25, 0x00, 0x40, 0x21, 0x50, 0x00, 0x2f, 0x21, + 0x07, 0x04, 0x10, 0x71, 0x3c, 0x1e, 0x02, 0x14, 0xca, 0x20, 0x25, 0x20, + 0x2e, 0xf0, 0x18, 0x9e, 0x2e, 0x70, 0x32, 0x40, 0x5a, 0xf0, 0x44, 0x16, + 0x00, 0x11, 0x3c, 0x1e, 0xc2, 0x13, 0x36, 0x09, 0x60, 0x03, 0xc0, 0xb8, + 0x9e, 0x20, 0x06, 0x04, 0x0e, 0x70, 0x2e, 0x71, 0x1a, 0xb6, 0x46, 0xf0, + 0x38, 0x9e, 0x1a, 0x9e, 0x74, 0x69, 0x1b, 0x79, 0x62, 0x79, 0x2f, 0x21, + 0x46, 0x80, 0x0a, 0x00, 0x03, 0x00, 0x33, 0x79, 0x2e, 0x79, 0x40, 0x16, + 0x02, 0x11, 0x15, 0x09, 0xa3, 0x00, 0x0e, 0x71, 0x00, 0x1b, 0x83, 0x20, + 0x38, 0x9e, 0x1a, 0x9e, 0x0e, 0x72, 0x74, 0x69, 0x42, 0x16, 0x41, 0x11, + 0x9e, 0x09, 0x20, 0x01, 0x6e, 0x7a, 0x1a, 0xb6, 0x44, 0x16, 0x00, 0x11, + 0xe6, 0x08, 0x60, 0x03, 0xc0, 0xb8, 0x1e, 0x20, 0x00, 0x04, 0x2e, 0x70, + 0x2f, 0x23, 0x07, 0x90, 0x1d, 0xf2, 0x46, 0x16, 0x00, 0x11, 0x48, 0x16, + 0x0c, 0x11, 0x4c, 0x71, 0x4a, 0x20, 0x00, 0x20, 0x98, 0x60, 0x44, 0x71, + 0x10, 0x78, 0x4f, 0x79, 0x41, 0x28, 0xc8, 0x01, 0x41, 0x28, 0x03, 0x02, + 0x0c, 0x23, 0x40, 0x90, 0x44, 0x20, 0x41, 0x10, 0x79, 0x61, 0x79, 0x20, + 0x00, 0x00, 0x00, 0x20, 0x50, 0x20, 0x70, 0xf7, 0x46, 0x1e, 0x04, 0x10, + 0x02, 0xf0, 0x0e, 0x70, 0x44, 0x16, 0x81, 0x10, 0x0c, 0x70, 0xf8, 0xb6, + 0xc0, 0xb9, 0xfc, 0xb6, 0x4a, 0x1e, 0x42, 0x10, 0x4c, 0x16, 0x41, 0x11, + 0x1b, 0x09, 0x03, 0x00, 0x44, 0x16, 0x00, 0x11, 0x3c, 0x1e, 0xc2, 0x13, + 0x7a, 0x08, 0x60, 0x03, 0xc0, 0xb8, 0x9e, 0x20, 0x06, 0x04, 0x1a, 0xb6, + 0x02, 0xf0, 0x1a, 0x96, 0x2f, 0x23, 0x06, 0x80, 0x10, 0x00, 0x23, 0x00, + 0x10, 0x79, 0x0c, 0x70, 0x8f, 0xb8, 0x09, 0x09, 0x00, 0x00, 0x33, 0x78, + 0x04, 0x20, 0x82, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0x42, 0x78, 0x5d, 0x79, + 0x2f, 0x26, 0x08, 0xf0, 0x0d, 0x0b, 0x33, 0x00, 0xc0, 0x21, 0x62, 0x00, + 0x30, 0x78, 0x13, 0x79, 0x18, 0x96, 0x2e, 0x79, 0x04, 0xb8, 0x0e, 0x78, + 0x13, 0x08, 0x42, 0x00, 0x4a, 0x16, 0x80, 0x10, 0x05, 0xe8, 0x00, 0x1b, + 0x43, 0x20, 0x4a, 0x1e, 0xc2, 0x13, 0x08, 0x16, 0x0b, 0x10, 0x43, 0x86, + 0x25, 0x85, 0x04, 0x85, 0xf8, 0xad, 0x00, 0x13, 0x83, 0x20, 0x3d, 0x20, + 0xc8, 0x02, 0x36, 0x70, 0x79, 0x23, 0x00, 0x00, 0x07, 0xb8, 0x3d, 0x21, + 0x8c, 0x00, 0xcf, 0x20, 0xa2, 0x01, 0x30, 0x72, 0xca, 0x24, 0x01, 0x12, + 0x18, 0xad, 0x87, 0xec, 0x85, 0xb8, 0x10, 0x1d, 0xc0, 0x12, 0x45, 0xa5, + 0x18, 0xad, 0x7e, 0x86, 0x3f, 0x86, 0x29, 0x0b, 0x44, 0x00, 0x28, 0x85, + 0x87, 0x85, 0x30, 0x72, 0x3d, 0x24, 0xc8, 0x12, 0x3d, 0x21, 0x8c, 0x00, + 0xca, 0x24, 0x01, 0x12, 0x88, 0xec, 0x83, 0xb8, 0x1c, 0x1d, 0xc0, 0x12, + 0x48, 0xa5, 0x2c, 0x70, 0x18, 0xad, 0x03, 0xf0, 0x21, 0x6b, 0x60, 0x85, + 0x81, 0x85, 0x2b, 0x0b, 0x24, 0x03, 0x3e, 0xa6, 0x23, 0x85, 0x82, 0x85, + 0x30, 0x72, 0x3d, 0x24, 0xc8, 0x12, 0x3d, 0x21, 0x8c, 0x00, 0xca, 0x24, + 0x01, 0x12, 0x89, 0xec, 0x84, 0xb8, 0x08, 0x1d, 0xc0, 0x12, 0x43, 0xa5, + 0x2c, 0x70, 0x18, 0xad, 0x02, 0xf0, 0x21, 0x6b, 0x44, 0x8e, 0x20, 0xa5, + 0x05, 0xea, 0x45, 0x20, 0x00, 0x0e, 0xe4, 0xae, 0x18, 0xad, 0x00, 0x1f, + 0x02, 0x20, 0x04, 0x1e, 0xc0, 0x23, 0x02, 0x86, 0x23, 0x86, 0x4c, 0x70, + 0x00, 0x20, 0x00, 0x84, 0x41, 0x21, 0x01, 0x80, 0x02, 0xa6, 0x23, 0xa6, + 0x00, 0x1e, 0x00, 0x20, 0x02, 0x85, 0x23, 0x85, 0x00, 0x20, 0x00, 0x84, + 0x46, 0xc0, 0x41, 0x21, 0x03, 0x80, 0x24, 0x85, 0x05, 0x85, 0x47, 0xc3, + 0x00, 0x21, 0x01, 0x84, 0x41, 0x20, 0x00, 0x80, 0x44, 0xc1, 0x45, 0xc0, + 0x86, 0xc0, 0x84, 0xc1, 0x43, 0x48, 0x40, 0x49, 0x15, 0x21, 0x8d, 0x30, + 0x15, 0x20, 0x8c, 0x30, 0x54, 0x71, 0x4c, 0x71, 0x60, 0xa5, 0x00, 0xa4, + 0xf4, 0xf5, 0xda, 0xc7, 0xe6, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x31, 0x40, 0x24, 0x05, 0x30, 0x40, 0x24, + 0x86, 0x31, 0x48, 0x47, 0x28, 0x45, 0x86, 0x0c, 0xef, 0xf0, 0x07, 0x1c, + 0x43, 0x30, 0x07, 0x14, 0x83, 0x30, 0x06, 0x14, 0x81, 0x30, 0x2f, 0x78, + 0x23, 0x0b, 0x04, 0x00, 0x17, 0x08, 0x51, 0x00, 0x00, 0xc0, 0x41, 0x68, + 0x0f, 0x0f, 0xa4, 0x10, 0xb8, 0x60, 0xa4, 0x16, 0x8c, 0x10, 0x40, 0xc2, + 0x80, 0xa8, 0x24, 0x71, 0x06, 0x1c, 0x42, 0x30, 0xef, 0xf1, 0x00, 0xc0, + 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xc6, 0xc7, 0xe0, 0x78, + 0xe8, 0xc2, 0x50, 0x40, 0x28, 0x46, 0x2c, 0x70, 0x10, 0xda, 0x60, 0x40, + 0x88, 0x47, 0xf2, 0x0d, 0xaf, 0xf7, 0x68, 0x45, 0x0c, 0x70, 0x07, 0xee, + 0x0b, 0x08, 0xd1, 0x2f, 0x0c, 0x71, 0x00, 0x1d, 0x43, 0x10, 0x00, 0xa7, + 0xc8, 0xc6, 0xe0, 0x78, 0xe6, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x00, 0x80, + 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, + 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, 0x02, 0x0c, 0xef, 0xf0, 0x03, 0x1c, + 0x83, 0x35, 0x02, 0x14, 0x80, 0x30, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, + 0xeb, 0x09, 0x24, 0x00, 0x04, 0x77, 0xdb, 0x08, 0x95, 0x05, 0x25, 0x20, + 0x00, 0x00, 0x17, 0xf0, 0x17, 0xf0, 0x19, 0xf0, 0x19, 0xf0, 0x1b, 0xf0, + 0x1b, 0xf0, 0x22, 0xf0, 0x22, 0xf0, 0x24, 0xf0, 0x24, 0xf0, 0x27, 0xf0, + 0x27, 0xf0, 0x29, 0xf0, 0x29, 0xf0, 0x2c, 0xf0, 0x2d, 0xf0, 0x35, 0xf0, + 0x3a, 0xf0, 0x3d, 0xf0, 0x44, 0xf0, 0x46, 0xf0, 0x4c, 0xf0, 0x17, 0x86, + 0x0a, 0xf0, 0x18, 0x86, 0x08, 0xf0, 0x19, 0x86, 0x06, 0xf0, 0x1a, 0x86, + 0x04, 0xf0, 0x1b, 0x86, 0x02, 0xf0, 0x1c, 0x86, 0x81, 0xc3, 0xa1, 0x41, + 0xc2, 0x08, 0x2f, 0xed, 0xe1, 0x42, 0x43, 0xf0, 0x0f, 0x9e, 0x17, 0xf0, + 0x12, 0x9e, 0x15, 0xf0, 0x08, 0x9e, 0x13, 0xf0, 0x2c, 0x16, 0x80, 0x10, + 0x34, 0xf0, 0x18, 0x9e, 0x0d, 0xf0, 0x0e, 0x9e, 0x0b, 0xf0, 0x09, 0x9e, + 0x09, 0xf0, 0x46, 0x16, 0x00, 0x11, 0x0e, 0xf0, 0x4a, 0x16, 0x80, 0x10, + 0x28, 0xf0, 0x74, 0x16, 0x40, 0x11, 0x81, 0xc3, 0xa1, 0x41, 0x46, 0x0c, + 0x60, 0x00, 0xe1, 0x42, 0x25, 0xf0, 0x1c, 0x96, 0x81, 0xc3, 0xa1, 0x41, + 0x6e, 0x0a, 0x2f, 0xf4, 0xe1, 0x42, 0x1f, 0xf0, 0x3c, 0x16, 0x80, 0x10, + 0x16, 0xf0, 0x23, 0x86, 0x02, 0x86, 0x40, 0x24, 0x04, 0x31, 0xa1, 0x42, + 0xd6, 0x0a, 0x2f, 0xfa, 0xe1, 0x43, 0x13, 0xf0, 0x1e, 0x86, 0x04, 0xf0, + 0x80, 0x16, 0x00, 0x10, 0x81, 0xc3, 0xa1, 0x41, 0xa6, 0x0b, 0xaf, 0xf7, + 0xe1, 0x42, 0x09, 0xf0, 0x98, 0x16, 0x80, 0x10, 0x81, 0xc3, 0xa1, 0x41, + 0x1e, 0x0d, 0xaf, 0xf2, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, + 0x02, 0x1c, 0x02, 0x30, 0x89, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, + 0x00, 0xad, 0x21, 0xad, 0xc6, 0xc7, 0xe0, 0x78, 0xe2, 0xc3, 0xa2, 0xc1, + 0x08, 0x45, 0x97, 0x80, 0x18, 0x80, 0x54, 0x15, 0x46, 0x11, 0x56, 0x15, + 0x45, 0x11, 0x4e, 0x15, 0x44, 0x11, 0x50, 0x15, 0x43, 0x11, 0x52, 0x15, + 0x42, 0x11, 0x41, 0xc0, 0x80, 0xc0, 0x12, 0x09, 0x20, 0x00, 0x40, 0xc4, + 0x00, 0x41, 0x58, 0x15, 0x00, 0x11, 0x00, 0xc3, 0x01, 0xc2, 0x77, 0xa5, + 0x58, 0xa5, 0x18, 0xe8, 0x1a, 0x85, 0x99, 0x85, 0x54, 0x15, 0x46, 0x11, + 0x56, 0x15, 0x45, 0x11, 0x4e, 0x15, 0x44, 0x11, 0x50, 0x15, 0x43, 0x11, + 0x52, 0x15, 0x42, 0x11, 0x41, 0xc0, 0x80, 0xc0, 0xde, 0x08, 0x20, 0x00, + 0x40, 0xc4, 0x00, 0xc3, 0x01, 0xc2, 0x00, 0x41, 0x79, 0xa5, 0x5a, 0xa5, + 0x20, 0x40, 0xc2, 0xc7, 0xe2, 0xc3, 0xa2, 0xc1, 0x08, 0x45, 0x5b, 0x80, + 0x1c, 0x80, 0x8c, 0x70, 0x40, 0xc2, 0x41, 0xc0, 0x80, 0xc0, 0xc3, 0x42, + 0x00, 0x00, 0xc8, 0x3b, 0xc3, 0x43, 0xff, 0xff, 0x39, 0xc4, 0xc3, 0x45, + 0x00, 0x00, 0x91, 0x37, 0xa6, 0x08, 0x20, 0x00, 0x80, 0x46, 0x00, 0xc2, + 0x01, 0xc1, 0x14, 0x70, 0x5b, 0xa5, 0x3c, 0xa5, 0xc6, 0xf6, 0x74, 0x15, + 0x40, 0x11, 0x1f, 0x08, 0x13, 0x00, 0x07, 0xf0, 0x4b, 0xf6, 0x74, 0x15, + 0x40, 0x11, 0x13, 0x08, 0x52, 0x00, 0x3c, 0x95, 0x13, 0x78, 0x74, 0x1d, + 0x04, 0x10, 0x01, 0x69, 0x1c, 0xb5, 0xc2, 0xc7, 0x81, 0x04, 0xc0, 0x00, + 0x19, 0x61, 0xc3, 0x40, 0x00, 0x00, 0xff, 0x7f, 0x10, 0x71, 0xca, 0x21, + 0x09, 0x00, 0x07, 0xf6, 0x0b, 0x09, 0x83, 0x0f, 0xff, 0xff, 0x00, 0x80, + 0x21, 0x68, 0xe0, 0x7f, 0x2e, 0x78, 0xe0, 0x78, 0xe6, 0xc2, 0x28, 0x47, + 0x10, 0xd9, 0x6a, 0x0d, 0x60, 0x00, 0x08, 0x45, 0x08, 0x46, 0x10, 0xd9, + 0x5e, 0x0d, 0x60, 0x00, 0xe1, 0x40, 0xc7, 0x78, 0x0e, 0x78, 0x56, 0x0d, + 0x60, 0x00, 0x0f, 0xd9, 0xfd, 0x65, 0x94, 0xe8, 0x10, 0xd9, 0x4a, 0x0d, + 0x60, 0x00, 0xa1, 0x40, 0xc7, 0x78, 0x0e, 0x78, 0x3e, 0x0d, 0x60, 0x00, + 0x0f, 0xd9, 0x0a, 0xe8, 0xd5, 0x70, 0xc3, 0x40, 0xff, 0x07, 0xff, 0xff, + 0x6f, 0x25, 0x43, 0x10, 0xca, 0x25, 0x09, 0x10, 0xa1, 0x40, 0xc6, 0xc6, + 0xf0, 0xc2, 0x30, 0x43, 0x49, 0x79, 0xcd, 0x70, 0x8d, 0xbe, 0x08, 0x47, + 0xd8, 0x61, 0x0e, 0xd9, 0x0a, 0x22, 0x80, 0x21, 0x0a, 0x21, 0x40, 0x21, + 0x0a, 0x24, 0x00, 0x21, 0x06, 0x0d, 0x60, 0x00, 0x68, 0x45, 0x96, 0x0f, + 0xef, 0xff, 0x21, 0x87, 0x1e, 0x25, 0xc1, 0x14, 0x00, 0x17, 0x10, 0x10, + 0x08, 0x45, 0xd8, 0x61, 0xee, 0x0c, 0x60, 0x00, 0x0e, 0xd9, 0x00, 0x41, + 0x7a, 0x0f, 0xef, 0xff, 0x02, 0x40, 0x10, 0x40, 0x1a, 0x25, 0x40, 0x14, + 0x0e, 0xd9, 0xda, 0x0c, 0x60, 0x00, 0xd8, 0x60, 0x00, 0x41, 0x66, 0x0f, + 0xef, 0xff, 0x02, 0x40, 0x1e, 0x24, 0xc1, 0x24, 0x01, 0xa7, 0xd8, 0x61, + 0xc2, 0x0c, 0x60, 0x00, 0x0e, 0xd9, 0x10, 0x40, 0x1a, 0x25, 0x80, 0x14, + 0x0e, 0xd9, 0xb6, 0x0c, 0x60, 0x00, 0xd8, 0x60, 0x00, 0x41, 0x42, 0x0f, + 0xef, 0xff, 0x02, 0x40, 0xc3, 0x41, 0x00, 0x00, 0xff, 0x7f, 0x15, 0x09, + 0x62, 0x03, 0x00, 0xa7, 0xa1, 0x41, 0x0d, 0x0d, 0x83, 0x1f, 0xff, 0xff, + 0x00, 0x80, 0x32, 0x6e, 0x2e, 0x78, 0xd0, 0xc6, 0xf1, 0xc0, 0x1e, 0x21, + 0x0c, 0x00, 0x0c, 0x70, 0x04, 0x32, 0x00, 0x80, 0xc6, 0xf6, 0x01, 0x32, + 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x32, 0x80, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, 0x4c, 0x70, 0x48, 0x30, + 0x80, 0x00, 0x8f, 0xba, 0x33, 0x4a, 0x48, 0x30, 0xc1, 0x02, 0x5d, 0x7a, + 0x6c, 0x79, 0x99, 0x61, 0x58, 0x61, 0x52, 0x0c, 0x60, 0x00, 0x0f, 0xd9, + 0xd1, 0xc0, 0xe0, 0x7f, 0x0e, 0x78, 0xe0, 0x78, 0xe8, 0xc3, 0x82, 0x24, + 0x0c, 0x34, 0x50, 0x40, 0x08, 0x47, 0x84, 0xc0, 0x8a, 0x22, 0x0c, 0x00, + 0x4e, 0x0c, 0xaf, 0xe9, 0x28, 0x45, 0x00, 0x87, 0x40, 0x24, 0x83, 0x30, + 0x40, 0x24, 0x04, 0x32, 0x40, 0x24, 0x05, 0x33, 0x40, 0x24, 0x06, 0x31, + 0x40, 0x24, 0xc7, 0x30, 0xa1, 0x41, 0x02, 0x42, 0x5a, 0x08, 0xef, 0xf0, + 0x02, 0x1c, 0x83, 0x35, 0x02, 0xc5, 0xb5, 0x70, 0xc0, 0xf4, 0x03, 0x14, + 0x8e, 0x30, 0xad, 0x70, 0x2c, 0x70, 0x34, 0x70, 0xba, 0xf4, 0x02, 0x14, + 0x81, 0x30, 0xcf, 0x78, 0x30, 0x70, 0x6c, 0x01, 0x2d, 0x00, 0x04, 0x77, + 0x95, 0xe0, 0x4c, 0x01, 0x0d, 0x00, 0x25, 0x20, 0x00, 0x00, 0x17, 0xf0, + 0x1b, 0xf0, 0x21, 0xf0, 0x25, 0xf0, 0x2b, 0xf0, 0x2f, 0xf0, 0x35, 0xf0, + 0x39, 0xf0, 0x3f, 0xf0, 0x43, 0xf0, 0x4a, 0xf0, 0x4e, 0xf0, 0x54, 0xf0, + 0x58, 0xf0, 0x5f, 0xf0, 0x64, 0xf0, 0x6b, 0xf0, 0x6f, 0xf0, 0x76, 0xf0, + 0x7b, 0xf0, 0x81, 0xf0, 0x86, 0xf0, 0x84, 0xc0, 0x62, 0x0d, 0xef, 0xec, + 0x81, 0xc1, 0x17, 0xa7, 0x86, 0xf0, 0x84, 0xc0, 0x56, 0x0d, 0xef, 0xec, + 0x81, 0xc1, 0x18, 0xa7, 0x80, 0xf0, 0x84, 0xc0, 0x4a, 0x0d, 0xef, 0xec, + 0x81, 0xc1, 0x19, 0xa7, 0x7a, 0xf0, 0x84, 0xc0, 0x3e, 0x0d, 0xef, 0xec, + 0x81, 0xc1, 0x1a, 0xa7, 0x74, 0xf0, 0x84, 0xc0, 0x32, 0x0d, 0xef, 0xec, + 0x81, 0xc1, 0x1b, 0xa7, 0x6e, 0xf0, 0x84, 0xc0, 0x26, 0x0d, 0xef, 0xec, + 0x81, 0xc1, 0x1c, 0xa7, 0x68, 0xf0, 0x84, 0xc0, 0x32, 0x0c, 0xe0, 0x00, + 0x81, 0xc1, 0x0f, 0xb7, 0x62, 0xf0, 0x84, 0xc0, 0x26, 0x0c, 0xe0, 0x00, + 0x81, 0xc1, 0x12, 0xb7, 0x5c, 0xf0, 0x84, 0xc0, 0x1a, 0x0c, 0xe0, 0x00, + 0x81, 0xc1, 0x08, 0xb7, 0x56, 0xf0, 0x84, 0xc0, 0xe6, 0x09, 0xaf, 0xf2, + 0x81, 0xc1, 0x2c, 0x1f, 0x02, 0x10, 0x50, 0xf0, 0x84, 0xc0, 0x02, 0x0c, + 0xe0, 0x00, 0x81, 0xc1, 0x18, 0xb7, 0x4a, 0xf0, 0x84, 0xc0, 0xf6, 0x0b, + 0xe0, 0x00, 0x81, 0xc1, 0x0e, 0xb7, 0x44, 0xf0, 0x84, 0xc0, 0xea, 0x0b, + 0xe0, 0x00, 0x81, 0xc1, 0x09, 0xb7, 0x3e, 0xf0, 0x84, 0xc0, 0xc2, 0x0e, + 0xef, 0xf3, 0x81, 0xc1, 0x46, 0x1f, 0x04, 0x10, 0x36, 0xf0, 0x84, 0xc0, + 0xa6, 0x09, 0xaf, 0xf2, 0x81, 0xc1, 0x4a, 0x1f, 0x02, 0x10, 0x30, 0xf0, + 0x84, 0xc0, 0xc2, 0x0b, 0xe0, 0x00, 0x81, 0xc1, 0x74, 0x1f, 0x04, 0x10, + 0x28, 0xf0, 0x84, 0xc0, 0x96, 0x0e, 0xef, 0xf3, 0x81, 0xc1, 0x1c, 0xb7, + 0x22, 0xf0, 0x84, 0xc0, 0x7e, 0x09, 0xaf, 0xf2, 0x81, 0xc1, 0x3c, 0x1f, + 0x02, 0x10, 0x1c, 0xf0, 0x84, 0xc0, 0x3e, 0x08, 0x60, 0x00, 0x81, 0xc1, + 0x23, 0xa7, 0x02, 0xa7, 0x14, 0xf0, 0x84, 0xc0, 0xca, 0x0f, 0x6f, 0xf7, + 0x81, 0xc1, 0x1e, 0xa7, 0x0e, 0xf0, 0x84, 0xc0, 0xbe, 0x0f, 0x6f, 0xf7, + 0x81, 0xc1, 0x80, 0x1f, 0x00, 0x10, 0x08, 0xf0, 0x84, 0xc0, 0x4a, 0x09, + 0xaf, 0xf2, 0x81, 0xc1, 0x98, 0x1f, 0x02, 0x10, 0x01, 0xc0, 0x8a, 0x21, + 0x3e, 0x06, 0x12, 0x70, 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, 0x01, 0x20, + 0x3d, 0x20, 0x00, 0x20, 0x1e, 0x66, 0x47, 0xf1, 0xa1, 0x40, 0xc8, 0xc7, + 0x2c, 0x70, 0x9e, 0xb9, 0x20, 0x42, 0x10, 0x71, 0x22, 0xb9, 0x3e, 0xf7, + 0x2c, 0x70, 0x0b, 0xea, 0x5b, 0x61, 0x0b, 0x08, 0xc4, 0x00, 0x62, 0x78, + 0x54, 0x79, 0x41, 0x2a, 0x82, 0x80, 0x3d, 0x79, 0xf8, 0xf5, 0xe0, 0x7f, + 0x30, 0x78, 0xe0, 0x78, 0xe0, 0x7f, 0x04, 0x18, 0x43, 0x00, 0xe0, 0x78, + 0xe2, 0xc0, 0x00, 0x1e, 0x03, 0x00, 0x20, 0x10, 0x89, 0x00, 0x0b, 0x09, + 0x51, 0x10, 0x87, 0x80, 0x86, 0xa0, 0x84, 0xeb, 0x83, 0x81, 0x87, 0xa0, + 0x21, 0x10, 0x8c, 0x00, 0x4a, 0x24, 0x00, 0x71, 0x0c, 0xec, 0x48, 0x43, + 0x0a, 0x24, 0x40, 0x11, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x13, 0x08, 0x14, + 0x04, 0x1c, 0x10, 0x12, 0x88, 0x44, 0x0b, 0xf0, 0x28, 0x43, 0xa8, 0x44, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x13, 0x08, 0x14, 0x04, 0x1c, 0x10, 0x12, + 0x68, 0x44, 0x0f, 0xec, 0x4a, 0x24, 0x00, 0x71, 0x40, 0x20, 0x0b, 0x02, + 0x0a, 0x24, 0x40, 0x11, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x13, 0x08, 0x14, + 0x04, 0x1c, 0x10, 0x12, 0x3c, 0xf0, 0x61, 0x09, 0x30, 0x10, 0x4a, 0x24, + 0x00, 0x71, 0xa5, 0x80, 0x0c, 0x15, 0x0c, 0x00, 0x04, 0x34, 0x40, 0x93, + 0x55, 0xf6, 0x87, 0x80, 0x50, 0x24, 0xfe, 0x97, 0x11, 0xf2, 0xa6, 0x80, + 0x04, 0x34, 0x40, 0x93, 0x8d, 0xf7, 0x4a, 0x24, 0x00, 0x71, 0x40, 0x20, + 0x0b, 0x02, 0xa8, 0x44, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x13, 0x08, 0x14, + 0x04, 0x1c, 0x10, 0x12, 0x1e, 0xf0, 0x4a, 0x24, 0x00, 0x71, 0x40, 0x20, + 0x0b, 0x02, 0xa8, 0x44, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x14, 0x08, 0x14, + 0x04, 0x1b, 0x10, 0x12, 0x80, 0xdc, 0x20, 0x18, 0x03, 0x00, 0x00, 0x1e, + 0x02, 0x03, 0x0e, 0xf0, 0x80, 0xdc, 0x40, 0x20, 0x0b, 0x02, 0x00, 0x1e, + 0x02, 0x03, 0xa8, 0x44, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x14, 0x08, 0x14, + 0x04, 0x1b, 0x10, 0x12, 0x04, 0x88, 0x1f, 0x08, 0x90, 0x00, 0x43, 0x08, + 0x51, 0x00, 0x8f, 0xeb, 0x4a, 0x24, 0x00, 0x71, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x11, 0x00, 0x04, 0x04, 0x1d, 0x10, 0x00, 0x10, 0xf0, 0x15, 0x0c, + 0x30, 0x00, 0x4a, 0x24, 0x00, 0x71, 0x00, 0x16, 0x80, 0x00, 0xc6, 0xb8, + 0x17, 0x00, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x12, 0x00, 0x04, + 0x04, 0x1d, 0x10, 0x00, 0x00, 0x16, 0x80, 0x00, 0x87, 0xb8, 0x00, 0x1e, + 0x02, 0x00, 0xc2, 0xc4, 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x39, 0x50, 0x40, + 0x08, 0x47, 0x89, 0xc0, 0x8a, 0x22, 0x0c, 0x00, 0x3a, 0x09, 0xaf, 0xe9, + 0x28, 0x45, 0x00, 0x87, 0x40, 0x24, 0x83, 0x35, 0x40, 0x24, 0x04, 0x37, + 0x40, 0x24, 0x05, 0x38, 0x40, 0x24, 0x06, 0x36, 0x40, 0x24, 0xc7, 0x35, + 0xa1, 0x41, 0x02, 0x42, 0x46, 0x0d, 0xaf, 0xf0, 0x16, 0x1c, 0x03, 0x31, + 0x07, 0xc5, 0x9b, 0x0d, 0x31, 0x10, 0x2c, 0x70, 0x17, 0x14, 0x8e, 0x30, + 0xad, 0x70, 0x8f, 0x09, 0x31, 0x00, 0xcf, 0x78, 0x16, 0x14, 0x81, 0x30, + 0x83, 0x09, 0x04, 0x00, 0x2f, 0x08, 0x30, 0x01, 0x86, 0xc1, 0x3d, 0x08, + 0xb0, 0x00, 0x86, 0xc1, 0x4b, 0x08, 0xf0, 0x00, 0x86, 0xc1, 0x57, 0x08, + 0x71, 0x00, 0x89, 0xc0, 0x86, 0xc1, 0x62, 0x0f, 0x2f, 0xf6, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x41, 0xa7, 0x22, 0xa7, 0x03, 0xa7, + 0x1d, 0xf0, 0x89, 0xc0, 0x1a, 0x0f, 0x2f, 0xf4, 0x83, 0xc2, 0x03, 0xc1, + 0x04, 0xc0, 0x2f, 0xa7, 0x10, 0xa7, 0x15, 0xf0, 0x89, 0xc0, 0x3a, 0x0f, + 0x2f, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x44, 0xa7, + 0x25, 0xa7, 0x06, 0xa7, 0x09, 0xf0, 0x89, 0xc0, 0xf2, 0x0e, 0x2f, 0xf4, + 0x83, 0xc2, 0x03, 0xc1, 0x04, 0xc0, 0x2d, 0xa7, 0x0e, 0xa7, 0x06, 0xc0, + 0x8a, 0x21, 0x3e, 0x06, 0x12, 0x70, 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, + 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, 0x1e, 0x66, 0xbb, 0xf1, 0xa1, 0x40, + 0xc8, 0xc7, 0xe0, 0x78, 0xf2, 0xc3, 0xaf, 0xc1, 0x4a, 0x24, 0xc0, 0x70, + 0x54, 0x20, 0x02, 0x0a, 0x08, 0x46, 0x55, 0x20, 0x0f, 0x08, 0x50, 0x40, + 0xa8, 0x20, 0x40, 0x02, 0x60, 0x82, 0x04, 0x11, 0x00, 0x04, 0x01, 0x30, + 0xc0, 0x00, 0x04, 0x1a, 0x10, 0x00, 0x20, 0x82, 0x0c, 0x70, 0x61, 0x69, + 0x87, 0xe1, 0x7c, 0x02, 0x2b, 0x00, 0x60, 0xa2, 0x16, 0x41, 0x00, 0x10, + 0x0c, 0x20, 0x0e, 0x42, 0x4a, 0x24, 0xc0, 0x70, 0x48, 0x33, 0x86, 0x00, + 0x48, 0xc1, 0x40, 0x24, 0x08, 0x33, 0x40, 0x24, 0x0b, 0x36, 0xc3, 0x43, + 0xfa, 0x44, 0x00, 0x00, 0x4a, 0x21, 0x00, 0x00, 0x46, 0xc4, 0x47, 0xc2, + 0xa8, 0x20, 0x00, 0x04, 0xf0, 0x23, 0x42, 0x10, 0x15, 0x20, 0x4c, 0x10, + 0x24, 0x71, 0x07, 0x32, 0x89, 0x01, 0x60, 0x42, 0x04, 0x31, 0xc0, 0x90, + 0xca, 0x22, 0x45, 0x02, 0x00, 0x1c, 0x80, 0x10, 0x4a, 0x24, 0xc0, 0x70, + 0xa8, 0x20, 0xc0, 0x03, 0xf0, 0x20, 0x02, 0x10, 0xc3, 0x41, 0xfa, 0xc4, + 0x00, 0x00, 0x15, 0x23, 0x03, 0x10, 0x04, 0x32, 0x40, 0x80, 0x04, 0x71, + 0xca, 0x21, 0x89, 0x00, 0x20, 0xa3, 0x6c, 0x4e, 0xfc, 0x4e, 0x54, 0x26, + 0x83, 0x18, 0x86, 0xc2, 0x40, 0x24, 0x04, 0x33, 0x40, 0x24, 0x05, 0x30, + 0xb6, 0x0c, 0x20, 0x02, 0x80, 0xc5, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, + 0x51, 0xa6, 0x32, 0xa6, 0x13, 0xa6, 0x04, 0x6e, 0xa8, 0x4e, 0x40, 0x26, + 0x03, 0x17, 0x83, 0xc2, 0x40, 0x24, 0x04, 0x30, 0x40, 0x24, 0x05, 0x39, + 0x96, 0x0d, 0x20, 0x02, 0x70, 0x41, 0x89, 0xc1, 0x18, 0xda, 0x96, 0x0f, + 0x6f, 0xe9, 0x22, 0x40, 0x01, 0x87, 0x00, 0xc3, 0x01, 0xc2, 0x02, 0xc1, + 0x4a, 0x24, 0xc0, 0x70, 0x54, 0x26, 0x12, 0x1c, 0x04, 0x77, 0x78, 0xa6, + 0x59, 0xa6, 0x3a, 0xa6, 0x04, 0x1f, 0x00, 0x10, 0xa8, 0x20, 0x00, 0x02, + 0x04, 0x12, 0x00, 0x24, 0x00, 0x30, 0x00, 0x00, 0x04, 0x1d, 0x10, 0x10, + 0x80, 0xc0, 0x66, 0x0b, 0x6f, 0xf8, 0x80, 0xc5, 0x4a, 0x24, 0xc0, 0x70, + 0x2f, 0x34, 0x00, 0x20, 0x83, 0xc1, 0xa8, 0x20, 0x40, 0x02, 0x04, 0x11, + 0x00, 0x04, 0x00, 0x30, 0x00, 0x00, 0x04, 0x1d, 0x10, 0x10, 0x80, 0xc0, + 0x42, 0x0b, 0x6f, 0xf8, 0x40, 0x24, 0x15, 0x30, 0x4a, 0x24, 0xc0, 0x70, + 0x2f, 0x33, 0x00, 0x20, 0x4a, 0x20, 0x00, 0x00, 0xa8, 0x20, 0x00, 0x04, + 0x08, 0x45, 0x40, 0x24, 0x11, 0x33, 0x15, 0x26, 0x00, 0x10, 0xf0, 0x21, + 0x41, 0x23, 0x18, 0x80, 0x15, 0x25, 0x42, 0x23, 0x00, 0x30, 0x41, 0x00, + 0x01, 0x6d, 0x20, 0xa2, 0x80, 0xc0, 0x0e, 0x0b, 0x6f, 0xf8, 0x00, 0x34, + 0xd5, 0x24, 0x07, 0x30, 0x40, 0x05, 0x74, 0x16, 0x8b, 0x10, 0x00, 0x30, + 0x88, 0x0f, 0x7a, 0x44, 0x00, 0x00, 0x23, 0x0b, 0x11, 0x10, 0x04, 0x30, + 0x80, 0x9f, 0x6d, 0x44, 0x66, 0xc6, 0xcb, 0xf6, 0x04, 0xc0, 0xf0, 0x21, + 0x41, 0x23, 0x6d, 0x71, 0x74, 0x1e, 0x43, 0x10, 0x1e, 0xa6, 0x3f, 0xa6, + 0x02, 0xf0, 0x04, 0xc0, 0x03, 0xc4, 0x50, 0x20, 0xc2, 0x07, 0x50, 0x24, + 0xc1, 0x17, 0x02, 0x31, 0x82, 0x00, 0xc3, 0x41, 0xab, 0x43, 0x00, 0x00, + 0x04, 0x32, 0x40, 0x80, 0xb0, 0x00, 0x2d, 0x00, 0x04, 0x34, 0x40, 0x90, + 0x4f, 0xf7, 0x04, 0x34, 0x80, 0x9f, 0xfa, 0xc3, 0x00, 0x00, 0xd1, 0xf6, + 0x04, 0x30, 0x80, 0x8f, 0xae, 0xc2, 0x67, 0x66, 0xcb, 0xf6, 0x04, 0x30, + 0x80, 0x8f, 0x6a, 0x44, 0xcd, 0xec, 0x8c, 0x00, 0x06, 0x00, 0xf0, 0x21, + 0x42, 0x23, 0x04, 0x32, 0x40, 0x80, 0x80, 0x00, 0x2c, 0x00, 0x2c, 0x70, + 0x61, 0x87, 0x97, 0x0b, 0x73, 0x00, 0x20, 0xa7, 0x8f, 0x0b, 0x10, 0x10, + 0x04, 0x34, 0x80, 0xaf, 0x48, 0x44, 0x00, 0x00, 0xc5, 0xf6, 0x04, 0x33, + 0x80, 0xaf, 0x54, 0x44, 0x00, 0x80, 0x7a, 0x00, 0x0c, 0x00, 0x04, 0x33, + 0x80, 0xaf, 0x96, 0x44, 0x00, 0x00, 0x58, 0xf7, 0x46, 0x43, 0x04, 0x30, + 0xc0, 0x90, 0x54, 0xf7, 0x00, 0x30, 0x03, 0x00, 0x00, 0x34, 0x0c, 0x13, + 0x02, 0x36, 0xc3, 0x70, 0x74, 0x49, 0x00, 0x24, 0x02, 0x33, 0x03, 0x03, + 0x2f, 0x33, 0xc0, 0x00, 0x01, 0x33, 0x83, 0x0f, 0x96, 0x42, 0x00, 0x00, + 0x04, 0x32, 0xc0, 0x80, 0x3e, 0x00, 0x06, 0x00, 0x7c, 0x86, 0x2d, 0xeb, + 0x7e, 0x86, 0x04, 0x30, 0xc0, 0x80, 0xd9, 0xf6, 0x1f, 0x86, 0x04, 0x32, + 0x00, 0x80, 0x55, 0xf7, 0x74, 0x1e, 0x03, 0x10, 0x2c, 0x71, 0x11, 0xf0, + 0x1c, 0x86, 0x1f, 0x08, 0x71, 0x00, 0x2c, 0x70, 0x00, 0x87, 0x41, 0x68, + 0x13, 0x08, 0x72, 0x01, 0x40, 0xa7, 0xc3, 0x40, 0x58, 0x44, 0x00, 0x80, + 0x00, 0x1a, 0x00, 0x20, 0x3c, 0xa6, 0x48, 0x8f, 0x0c, 0x70, 0x0c, 0x18, + 0x00, 0x20, 0x08, 0x18, 0x00, 0x20, 0x04, 0x18, 0x00, 0x20, 0x11, 0x09, + 0xa0, 0x00, 0x00, 0x18, 0x00, 0x20, 0x28, 0xaf, 0x02, 0xe9, 0x81, 0xd8, + 0xd2, 0xc7, 0xc3, 0x40, 0x62, 0x44, 0x33, 0x93, 0x2c, 0x71, 0x00, 0x1a, + 0x00, 0x20, 0x70, 0x1e, 0x41, 0x10, 0x74, 0x1e, 0x03, 0x10, 0xe7, 0xf1, + 0xec, 0xc3, 0xa2, 0xc1, 0x08, 0x46, 0x04, 0x16, 0x00, 0x14, 0x60, 0x44, + 0x40, 0x24, 0xc3, 0x30, 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, + 0x48, 0x47, 0x28, 0x45, 0x1e, 0x0a, 0xaf, 0xf0, 0x03, 0x1c, 0x03, 0x31, + 0x02, 0x14, 0x80, 0x30, 0x40, 0x26, 0x10, 0x13, 0x40, 0x26, 0x11, 0x1c, + 0x40, 0x26, 0x12, 0x1e, 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0x4d, 0x09, + 0x04, 0x00, 0x23, 0x08, 0x30, 0x01, 0x81, 0xc3, 0x1f, 0x08, 0xb0, 0x00, + 0x81, 0xc3, 0x27, 0x08, 0xf0, 0x00, 0x81, 0xc3, 0x29, 0x08, 0x71, 0x00, + 0x81, 0xc3, 0xe1, 0x42, 0xc1, 0x40, 0xa1, 0x41, 0x06, 0xf0, 0x42, 0x40, + 0x08, 0xf0, 0x02, 0x40, 0xa1, 0x41, 0xe1, 0x42, 0xea, 0x0b, 0x0f, 0xf6, + 0x06, 0xf0, 0x22, 0x40, 0xa1, 0x41, 0xb2, 0x0b, 0x2f, 0xf4, 0xe1, 0x42, + 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, 0x02, 0x1c, 0x02, 0x30, 0xda, 0xf1, + 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, 0x00, 0xad, 0x21, 0xad, 0xcc, 0xc7, + 0xe2, 0xc2, 0x60, 0x40, 0x2c, 0x70, 0x10, 0xda, 0x5e, 0x0b, 0x6f, 0xf7, + 0x88, 0x45, 0x00, 0x1d, 0x01, 0x10, 0xc2, 0xc6, 0xec, 0xc3, 0xa2, 0xc1, + 0x08, 0x46, 0x50, 0x16, 0x00, 0x14, 0x60, 0x44, 0x40, 0x24, 0xc3, 0x30, + 0x40, 0x24, 0x05, 0x31, 0x40, 0x24, 0x86, 0x30, 0x48, 0x47, 0x28, 0x45, + 0x7a, 0x09, 0xaf, 0xf0, 0x03, 0x1c, 0x43, 0x33, 0x02, 0x14, 0x80, 0x30, + 0x40, 0x26, 0x11, 0x14, 0x42, 0x26, 0x12, 0x13, 0x42, 0x26, 0x10, 0x1d, + 0x03, 0x14, 0x81, 0x30, 0x0f, 0x78, 0xab, 0x09, 0x24, 0x00, 0x04, 0x77, + 0x97, 0x08, 0x55, 0x03, 0x25, 0x20, 0x00, 0x00, 0x0d, 0xf0, 0x14, 0xf0, + 0x15, 0xf0, 0x1c, 0xf0, 0x1c, 0xf0, 0x1e, 0xf0, 0x1e, 0xf0, 0x25, 0xf0, + 0x25, 0xf0, 0x27, 0xf0, 0x28, 0xf0, 0x2f, 0xf0, 0x35, 0xf0, 0x81, 0xc3, + 0x02, 0x40, 0xa1, 0x41, 0x06, 0x0e, 0x20, 0x03, 0xe1, 0x42, 0x35, 0xf0, + 0x81, 0xc3, 0xc1, 0x40, 0x03, 0xf0, 0x81, 0xc3, 0x22, 0x40, 0xa1, 0x41, + 0xa2, 0x0b, 0xef, 0xf4, 0xe1, 0x42, 0x2b, 0xf0, 0x03, 0x86, 0x15, 0xf0, + 0x07, 0x86, 0x05, 0xf0, 0x0a, 0x86, 0x03, 0xf0, 0x0b, 0x86, 0x81, 0xc3, + 0xa1, 0x41, 0x1e, 0x09, 0xef, 0xf4, 0xe1, 0x42, 0x1d, 0xf0, 0x08, 0x86, + 0x07, 0xf0, 0x0d, 0x86, 0x05, 0xf0, 0x24, 0x16, 0x80, 0x10, 0x0b, 0xf0, + 0x0c, 0x86, 0x81, 0xc3, 0xa1, 0x41, 0x0e, 0x0e, 0xaf, 0xec, 0xe1, 0x42, + 0x0f, 0xf0, 0x38, 0x16, 0x80, 0x10, 0x81, 0xc3, 0xa1, 0x41, 0xde, 0x0a, + 0x6f, 0xf2, 0xe1, 0x42, 0x07, 0xf0, 0x81, 0xc3, 0x42, 0x40, 0xa1, 0x41, + 0xde, 0x0a, 0x2f, 0xf6, 0xe1, 0x42, 0x02, 0x14, 0x80, 0x30, 0x04, 0x71, + 0x02, 0x1c, 0x02, 0x30, 0xaa, 0xf1, 0x01, 0xc0, 0x41, 0x28, 0x01, 0x02, + 0x00, 0xad, 0x21, 0xad, 0xcc, 0xc7, 0xe0, 0x78, 0xf9, 0x03, 0x80, 0x00, + 0xe8, 0xc3, 0x82, 0x24, 0x0c, 0x3d, 0x50, 0x40, 0x08, 0x47, 0x8d, 0xc0, + 0x8a, 0x22, 0x0c, 0x00, 0x0a, 0x0c, 0x6f, 0xe9, 0x28, 0x45, 0x1c, 0x17, + 0x00, 0x14, 0x40, 0x24, 0x83, 0x33, 0x40, 0x24, 0x04, 0x35, 0x40, 0x24, + 0x05, 0x3c, 0x40, 0x24, 0x06, 0x34, 0x40, 0x24, 0xc7, 0x33, 0xa1, 0x41, + 0x02, 0x42, 0x16, 0x08, 0xaf, 0xf0, 0x0e, 0x1c, 0x43, 0x33, 0x05, 0xc5, + 0xb5, 0x70, 0x92, 0xf4, 0x0f, 0x14, 0x8e, 0x30, 0xad, 0x70, 0x2c, 0x70, + 0x34, 0x70, 0x8c, 0xf4, 0x0e, 0x14, 0x81, 0x30, 0xcf, 0x78, 0x30, 0x70, + 0x0c, 0x01, 0x2d, 0x00, 0x04, 0x77, 0xf1, 0x08, 0x55, 0x03, 0x25, 0x20, + 0x00, 0x00, 0x0e, 0xf0, 0x17, 0xf0, 0x23, 0xf0, 0x2d, 0xf0, 0x33, 0xf0, + 0x37, 0xf0, 0x3d, 0xf0, 0x41, 0xf0, 0x47, 0xf0, 0x4b, 0xf0, 0x52, 0xf0, + 0x56, 0xf0, 0x5d, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0xde, 0x0c, 0x20, 0x03, + 0x86, 0xc2, 0x86, 0xc1, 0x18, 0xda, 0x92, 0x0b, 0x6f, 0xe9, 0xe1, 0x40, + 0x5c, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0x7a, 0x0a, 0xef, 0xf4, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x4d, 0xa7, 0x2e, 0xa7, 0x0f, 0xa7, + 0x50, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0x62, 0x0a, 0xef, 0xf4, 0x80, 0xc2, + 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x51, 0xa7, 0x32, 0xa7, 0x13, 0xa7, + 0x44, 0xf0, 0x8d, 0xc0, 0xea, 0x0c, 0xaf, 0xec, 0x84, 0xc1, 0x10, 0xa7, + 0x3e, 0xf0, 0x8d, 0xc0, 0xd2, 0x0f, 0xaf, 0xf4, 0x84, 0xc1, 0x14, 0xa7, + 0x38, 0xf0, 0x8d, 0xc0, 0xc6, 0x0f, 0xaf, 0xf4, 0x84, 0xc1, 0x17, 0xa7, + 0x32, 0xf0, 0x8d, 0xc0, 0xba, 0x0f, 0xaf, 0xf4, 0x84, 0xc1, 0x18, 0xa7, + 0x2c, 0xf0, 0x8d, 0xc0, 0xba, 0x0c, 0xaf, 0xec, 0x84, 0xc1, 0x15, 0xa7, + 0x26, 0xf0, 0x8d, 0xc0, 0xae, 0x0c, 0xaf, 0xec, 0x84, 0xc1, 0x1a, 0xa7, + 0x20, 0xf0, 0x8d, 0xc0, 0x92, 0x09, 0x6f, 0xf2, 0x84, 0xc1, 0x58, 0x1f, + 0x02, 0x10, 0x1a, 0xf0, 0x8d, 0xc0, 0x96, 0x0c, 0xaf, 0xec, 0x84, 0xc1, + 0x19, 0xa7, 0x14, 0xf0, 0x8d, 0xc0, 0x7a, 0x09, 0x6f, 0xf2, 0x84, 0xc1, + 0x6c, 0x1f, 0x02, 0x10, 0x0c, 0xf0, 0x8d, 0xc0, 0x84, 0xc1, 0x6a, 0x09, + 0x2f, 0xf6, 0x80, 0xc2, 0x00, 0xc2, 0x01, 0xc1, 0x02, 0xc0, 0x4a, 0xa7, + 0x2b, 0xa7, 0x0c, 0xa7, 0x04, 0xc0, 0x8a, 0x21, 0x3e, 0x06, 0x12, 0x70, + 0xca, 0x25, 0x4d, 0x10, 0x3c, 0x20, 0x01, 0x20, 0x3d, 0x20, 0x00, 0x20, + 0x1e, 0x66, 0x76, 0xf1, 0xa1, 0x40, 0xc8, 0xc7, 0xe0, 0x7e, 0xe0, 0x78, + 0xe4, 0xc3, 0xa2, 0xc1, 0xa0, 0x81, 0x28, 0x46, 0x08, 0xda, 0xb9, 0x60, + 0xa6, 0x0a, 0x6f, 0xe9, 0x80, 0xc0, 0x01, 0xc1, 0x00, 0xc0, 0x08, 0xe5, + 0xa0, 0xa6, 0xc4, 0xc7, 0x80, 0x83, 0x85, 0x72, 0x27, 0x0a, 0x24, 0x03, + 0xa1, 0xc1, 0x4c, 0x70, 0x02, 0x1c, 0x04, 0x30, 0x00, 0x83, 0x40, 0x24, + 0x8c, 0x30, 0x4c, 0x64, 0x58, 0x60, 0x54, 0x71, 0x4c, 0x71, 0x38, 0x60, + 0x80, 0xa8, 0xf8, 0xf5, 0x00, 0x83, 0x04, 0x72, 0x00, 0xa3, 0xe0, 0x7f, + 0x87, 0x74, 0xe0, 0x78, 0xee, 0xc2, 0x70, 0x43, 0x48, 0x47, 0x10, 0x40, + 0xc4, 0xe1, 0xd8, 0x00, 0x25, 0x00, 0xcd, 0x70, 0xcb, 0x45, 0xa0, 0x00, + 0xd0, 0x86, 0x00, 0x8d, 0x0b, 0x08, 0x71, 0x00, 0xff, 0xd8, 0x08, 0x8d, + 0x04, 0xf0, 0x00, 0x1d, 0x43, 0x10, 0x08, 0xad, 0xd3, 0x42, 0xa0, 0x00, + 0x64, 0xe1, 0x0f, 0x08, 0x21, 0x04, 0x4c, 0x20, 0x40, 0xa9, 0xc3, 0x85, + 0x20, 0xf0, 0xc3, 0x40, 0x12, 0x00, 0xec, 0x4a, 0xcb, 0x44, 0x12, 0x00, + 0xf0, 0x4a, 0xca, 0x24, 0x01, 0x10, 0x40, 0x25, 0x06, 0x11, 0xc3, 0x40, + 0xa0, 0x00, 0x8c, 0x86, 0x8a, 0x23, 0x10, 0x00, 0xc3, 0x44, 0xa0, 0x00, + 0x64, 0xe5, 0x8a, 0x25, 0x08, 0x00, 0x42, 0x42, 0x23, 0x20, 0x00, 0x03, + 0x02, 0x41, 0xcd, 0x70, 0x03, 0xe8, 0xc0, 0xad, 0x38, 0xf0, 0xc3, 0xa5, + 0x08, 0x1d, 0x02, 0x14, 0x7f, 0xd8, 0xc4, 0x78, 0x00, 0xaf, 0x01, 0x85, + 0x76, 0x6e, 0x54, 0x23, 0x01, 0x08, 0x40, 0xda, 0x70, 0x41, 0x10, 0x71, + 0x40, 0xd9, 0x8a, 0xf7, 0x4f, 0x26, 0xc0, 0x11, 0x00, 0xaf, 0x01, 0x85, + 0x00, 0x1d, 0x03, 0x10, 0x02, 0x20, 0x41, 0x04, 0x21, 0xaf, 0x01, 0x85, + 0x2f, 0x20, 0x47, 0x20, 0x02, 0x22, 0x02, 0x04, 0x02, 0xaf, 0x01, 0x85, + 0x4c, 0x20, 0xc0, 0xaf, 0x00, 0x27, 0x01, 0x14, 0x28, 0xb8, 0xca, 0x22, + 0x2d, 0x00, 0x03, 0xaf, 0x04, 0x69, 0xea, 0x0f, 0x2f, 0xf7, 0x2c, 0x70, + 0x00, 0x21, 0x81, 0x24, 0x04, 0x6f, 0x9a, 0x09, 0x6f, 0xe9, 0x02, 0x42, + 0x21, 0x6e, 0x44, 0xd8, 0xcd, 0x71, 0x23, 0xa5, 0x00, 0x1b, 0x04, 0x20, + 0xc1, 0x40, 0xce, 0xc6, 0xea, 0xc2, 0x48, 0x47, 0x10, 0x40, 0xc4, 0xe1, + 0xa0, 0x00, 0x25, 0x00, 0x2c, 0x70, 0xcb, 0x45, 0xa0, 0x00, 0xd0, 0x86, + 0x00, 0x8d, 0x0d, 0x08, 0xb1, 0x00, 0xff, 0xd8, 0x09, 0x8d, 0x05, 0xf0, + 0x00, 0x1d, 0x83, 0x10, 0x09, 0xad, 0x0b, 0x08, 0x01, 0x04, 0xc1, 0x85, + 0x08, 0xf0, 0xc3, 0x8f, 0x02, 0x8f, 0x09, 0x1d, 0x02, 0x14, 0x08, 0xbe, + 0x05, 0x7e, 0xc1, 0xa5, 0x8c, 0x26, 0x10, 0x90, 0x62, 0x00, 0x0d, 0x00, + 0x00, 0x8f, 0x41, 0x8f, 0xc6, 0xb8, 0x36, 0x68, 0x58, 0x61, 0x57, 0x0e, + 0x04, 0x10, 0xd3, 0x41, 0xa0, 0x00, 0x64, 0xe1, 0x00, 0x21, 0x40, 0x04, + 0x26, 0x09, 0x6f, 0xe9, 0x24, 0x6f, 0x00, 0x17, 0xc0, 0x10, 0x3b, 0x08, + 0x33, 0x00, 0x4c, 0x20, 0x40, 0xa9, 0xc3, 0x40, 0x12, 0x00, 0xf4, 0x4a, + 0xcb, 0x47, 0x12, 0x00, 0xf8, 0x4a, 0xca, 0x27, 0x01, 0x10, 0xc3, 0x40, + 0xa0, 0x00, 0x8c, 0x86, 0xc3, 0x43, 0xa0, 0x00, 0x64, 0xe5, 0x8a, 0x24, + 0x08, 0x00, 0x22, 0x41, 0x23, 0x20, 0xc0, 0x03, 0xc1, 0x42, 0x2c, 0x70, + 0x00, 0x1d, 0x03, 0x10, 0x86, 0xe8, 0x2c, 0x71, 0x04, 0xf0, 0x2c, 0x70, + 0x00, 0x1d, 0x03, 0x10, 0x20, 0x40, 0xca, 0xc6, 0xe2, 0xc2, 0x08, 0x44, + 0xfd, 0xe0, 0x68, 0x45, 0x09, 0xf2, 0xfe, 0xe4, 0x0c, 0xf4, 0x40, 0x40, + 0xdf, 0x59, 0x00, 0x1d, 0x05, 0x11, 0x0c, 0x71, 0x11, 0xf0, 0x25, 0xd8, + 0x56, 0x0e, 0xef, 0xff, 0xa1, 0x43, 0x0d, 0xf0, 0xbf, 0xe4, 0x0c, 0x70, + 0x09, 0xf7, 0x15, 0x0c, 0x50, 0x10, 0x15, 0x0c, 0x50, 0x11, 0x0b, 0x0c, + 0xd1, 0x10, 0x21, 0xd8, 0xf2, 0xf1, 0xc2, 0xc6, 0x20, 0xd8, 0xf0, 0xf1, + 0x22, 0xd8, 0xee, 0xf1, 0xf1, 0xc0, 0x00, 0x43, 0xfd, 0xe0, 0x06, 0xf4, + 0x25, 0xd8, 0x0a, 0x0f, 0xcf, 0xff, 0x0d, 0xf0, 0xbf, 0xe3, 0x0c, 0x70, + 0x09, 0xf7, 0x17, 0x0b, 0x50, 0x00, 0x17, 0x0b, 0x50, 0x01, 0x0b, 0x0b, + 0xd1, 0x00, 0x21, 0xd8, 0xf3, 0xf1, 0xd1, 0xc0, 0xe0, 0x7e, 0x20, 0xd8, + 0xef, 0xf1, 0x22, 0xd8, 0xed, 0xf1, 0xe0, 0x78, 0xe4, 0xc3, 0xa1, 0xc1, + 0x80, 0xc0, 0xc3, 0x41, 0x13, 0x00, 0x58, 0x90, 0x52, 0x08, 0x6f, 0xe9, + 0x4c, 0x74, 0x3b, 0x58, 0x08, 0x46, 0x28, 0x45, 0xfe, 0xd8, 0x80, 0xc1, + 0x8c, 0x70, 0xc1, 0x42, 0xa1, 0x43, 0x6b, 0x58, 0xf8, 0xd8, 0x80, 0xc1, + 0x8c, 0x70, 0xc1, 0x42, 0xa1, 0x43, 0x6b, 0x58, 0xc3, 0x40, 0xf0, 0x00, + 0x3f, 0x00, 0x20, 0x88, 0x84, 0xb9, 0x20, 0xa8, 0xc4, 0xc7, 0xe0, 0x78, + 0x09, 0x08, 0x12, 0x00, 0xe0, 0x7f, 0x39, 0x78, 0x12, 0x78, 0x39, 0x78, + 0xe0, 0x7f, 0x12, 0x78, 0xe6, 0xc2, 0x08, 0x45, 0x12, 0x18, 0x85, 0x07, + 0x28, 0xda, 0x0c, 0x18, 0x01, 0x05, 0x68, 0x18, 0x81, 0x02, 0xc3, 0x41, + 0xc0, 0x49, 0x00, 0x92, 0xc3, 0x40, 0x07, 0x49, 0x00, 0x24, 0x40, 0x25, + 0x0e, 0x17, 0x64, 0x1d, 0x81, 0x12, 0x58, 0x1d, 0xc3, 0x10, 0x50, 0xad, + 0x22, 0xa5, 0x01, 0xa5, 0x2c, 0x70, 0x3c, 0xda, 0x1e, 0x0e, 0x2f, 0xf7, + 0xc1, 0x40, 0x96, 0x0f, 0xef, 0xef, 0xc1, 0x40, 0x1a, 0x85, 0x19, 0x08, + 0x72, 0x02, 0xed, 0x70, 0x19, 0x85, 0x11, 0x08, 0x70, 0x02, 0xc1, 0x40, + 0x7e, 0x0f, 0xef, 0xef, 0x64, 0x1d, 0x41, 0x12, 0x09, 0x95, 0xc3, 0x43, + 0xc8, 0x42, 0x00, 0x00, 0xcb, 0x44, 0x83, 0x3a, 0x6f, 0x12, 0x48, 0x30, + 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x30, 0x00, 0x03, 0x04, 0x30, + 0xc0, 0x83, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x30, 0x8d, 0x10, 0x7a, 0x8b, 0xe2, 0x48, 0x31, 0x01, 0x00, + 0xca, 0x20, 0xa6, 0x02, 0x10, 0x78, 0x00, 0x31, 0xc1, 0x00, 0x48, 0x20, + 0xc0, 0x00, 0x0c, 0xb5, 0x9a, 0x0d, 0xaf, 0xf3, 0x00, 0x31, 0x00, 0x03, + 0x48, 0x30, 0xc0, 0x02, 0x05, 0xa5, 0xc6, 0xc6, 0xe6, 0xc2, 0x08, 0x45, + 0x8a, 0x20, 0x0a, 0x00, 0xcb, 0x46, 0x16, 0x43, 0x00, 0x00, 0xc3, 0x41, + 0xfd, 0x44, 0x00, 0x20, 0x10, 0xb5, 0xc7, 0xa5, 0x24, 0xa5, 0x01, 0xa5, + 0xfe, 0x0f, 0xef, 0xea, 0x55, 0x25, 0x40, 0x1c, 0xf2, 0x09, 0x2f, 0xeb, + 0x56, 0x25, 0x80, 0x1a, 0x4a, 0x24, 0x00, 0x74, 0x56, 0x25, 0x01, 0x1d, + 0x0a, 0x20, 0x80, 0x0f, 0x13, 0x00, 0x34, 0x6b, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x10, 0x02, 0x04, 0x04, 0x19, 0x90, 0x00, 0x67, 0x85, 0x21, 0x85, + 0xcb, 0x43, 0x10, 0x42, 0x00, 0x00, 0x07, 0x36, 0xc8, 0x70, 0x80, 0x3f, + 0x00, 0x00, 0x8b, 0x1d, 0x98, 0x13, 0x48, 0x31, 0x81, 0x00, 0xc3, 0x40, + 0x48, 0x44, 0x00, 0x00, 0xcb, 0x46, 0x48, 0x41, 0x00, 0x00, 0x78, 0x1d, + 0xd8, 0x12, 0x8a, 0x1d, 0x18, 0x10, 0x00, 0x31, 0x80, 0x03, 0xcb, 0x47, + 0x83, 0x3a, 0x6f, 0x12, 0x00, 0x30, 0xc0, 0x03, 0x2d, 0x70, 0xc3, 0x42, + 0x96, 0x44, 0x00, 0x00, 0xcb, 0x44, 0x1c, 0x49, 0x00, 0x40, 0xc3, 0x43, + 0xaf, 0x49, 0x00, 0xc8, 0x04, 0x30, 0x40, 0x82, 0x89, 0x1d, 0x98, 0x10, + 0x86, 0xa5, 0x65, 0xa5, 0xc4, 0x1d, 0x00, 0x12, 0xc6, 0xf6, 0x01, 0x30, + 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x30, 0x95, 0x48, 0x30, 0xc0, 0x02, 0x48, 0x30, + 0x82, 0x00, 0x48, 0x31, 0x00, 0x00, 0x00, 0x30, 0x80, 0x03, 0x48, 0x32, + 0xc1, 0x02, 0x00, 0x30, 0xc0, 0x03, 0x49, 0x21, 0x01, 0x02, 0x48, 0x21, + 0x01, 0x01, 0x04, 0x30, 0x40, 0x82, 0x22, 0xa5, 0xc6, 0xf6, 0x01, 0x30, + 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, 0x48, 0x30, 0x80, 0x00, + 0x48, 0x30, 0xc0, 0x02, 0x49, 0x20, 0x40, 0x06, 0x48, 0x20, 0x00, 0x01, + 0x09, 0xa5, 0x0e, 0x08, 0x20, 0x00, 0xa1, 0x40, 0xc6, 0xc6, 0xe0, 0x78, + 0xe8, 0xc3, 0xa4, 0xc1, 0x4a, 0x24, 0x00, 0x76, 0x08, 0x46, 0x40, 0x20, + 0x0d, 0x0b, 0x0c, 0x70, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1d, 0x11, 0x10, + 0x4a, 0x24, 0x80, 0x77, 0x53, 0x1e, 0x59, 0x10, 0xcc, 0x1e, 0x00, 0x10, + 0x0c, 0x1e, 0x00, 0x10, 0x55, 0x26, 0x00, 0x1d, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x18, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x26, 0x4f, 0x1a, + 0x0a, 0x20, 0xc0, 0x03, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, + 0x00, 0x18, 0x03, 0x00, 0x56, 0x26, 0x80, 0x1a, 0x06, 0x09, 0x2f, 0xeb, + 0x10, 0x40, 0x41, 0x87, 0x02, 0x87, 0x60, 0x87, 0xc3, 0x41, 0x7a, 0x44, + 0x00, 0x00, 0x43, 0xc1, 0x41, 0xc2, 0x42, 0xc0, 0x80, 0xc1, 0x10, 0xda, + 0x02, 0x40, 0xd2, 0x0d, 0x2f, 0xe9, 0x40, 0xc3, 0x4a, 0x24, 0x00, 0x74, + 0x56, 0x26, 0x00, 0x1b, 0xc3, 0x41, 0x13, 0x00, 0x74, 0x6b, 0x00, 0x42, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x03, 0x04, 0x04, 0x1a, 0xd0, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1d, 0x11, 0x10, + 0x4a, 0x24, 0xc0, 0x70, 0x0a, 0x21, 0x80, 0x0f, 0x7a, 0xc4, 0x00, 0x00, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1d, 0x50, 0x10, 0x80, 0xc1, 0xb1, 0x1e, + 0x43, 0x10, 0x0e, 0x0e, 0x60, 0x00, 0x28, 0x1e, 0x01, 0x10, 0x55, 0x26, + 0x40, 0x1b, 0x80, 0xc1, 0x7a, 0x0d, 0x2f, 0xe9, 0x10, 0xda, 0xc8, 0xc7, + 0xf0, 0xc3, 0x82, 0x24, 0x06, 0x3e, 0x08, 0x46, 0x54, 0x20, 0x00, 0x09, + 0x2c, 0x70, 0x14, 0xda, 0xa6, 0x0b, 0x2f, 0xf7, 0x8a, 0x21, 0x8e, 0x21, + 0x4a, 0x24, 0x40, 0x71, 0x54, 0x26, 0x92, 0x1b, 0x00, 0x21, 0x91, 0x23, + 0x4a, 0x20, 0x00, 0x20, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1a, 0x11, 0x20, + 0x2c, 0x70, 0x28, 0x47, 0x8f, 0xbf, 0x40, 0xdc, 0x00, 0x19, 0x02, 0x24, + 0xfe, 0x19, 0x04, 0xa4, 0xfc, 0x19, 0x04, 0xa4, 0x47, 0x09, 0x75, 0x01, + 0x15, 0x26, 0x43, 0x10, 0x4d, 0x83, 0x1d, 0x0a, 0x70, 0x01, 0x14, 0x26, + 0x40, 0x10, 0x23, 0x0a, 0x51, 0x02, 0x52, 0x18, 0x04, 0x04, 0x48, 0x18, + 0x04, 0x04, 0x7f, 0xd8, 0x17, 0xb8, 0x10, 0xf0, 0x52, 0x18, 0xc4, 0x03, + 0x48, 0x18, 0x04, 0x03, 0x4f, 0xd8, 0x18, 0xb8, 0x08, 0xf0, 0x52, 0x18, + 0xc4, 0x03, 0x48, 0x18, 0x04, 0x03, 0xc3, 0x40, 0x7f, 0x7f, 0xff, 0xff, + 0x17, 0xa3, 0x24, 0x71, 0xde, 0xf1, 0x8a, 0x20, 0x07, 0x0d, 0xd8, 0x60, + 0x2c, 0x70, 0x26, 0x0b, 0x2f, 0xf7, 0x8a, 0x22, 0x06, 0x00, 0x8c, 0x20, + 0xc1, 0xa7, 0x94, 0x00, 0x2d, 0x00, 0xad, 0x70, 0x15, 0x26, 0x14, 0x14, + 0x74, 0x14, 0x02, 0x20, 0x4a, 0x24, 0x80, 0x7b, 0x0a, 0x23, 0x80, 0x2f, + 0x13, 0x00, 0xfc, 0x6c, 0x40, 0x23, 0x03, 0x23, 0xa8, 0x20, 0x80, 0x02, + 0x04, 0x13, 0x00, 0x04, 0x82, 0xc1, 0xb9, 0x61, 0xa5, 0x71, 0x38, 0x20, + 0x80, 0x00, 0x00, 0xa9, 0xea, 0x0e, 0xe0, 0x01, 0x82, 0xc0, 0x14, 0x70, + 0x0c, 0x70, 0x0a, 0xf2, 0x14, 0x26, 0x01, 0x14, 0xfa, 0x19, 0x1c, 0x00, + 0x80, 0x21, 0x0a, 0x0d, 0x00, 0xb1, 0x22, 0xf0, 0x74, 0x14, 0x03, 0x20, + 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x13, 0x01, 0x24, + 0x40, 0x24, 0x42, 0x31, 0x1a, 0x62, 0x04, 0x71, 0x38, 0x21, 0xc1, 0x00, + 0x20, 0xaa, 0x40, 0x24, 0x40, 0x31, 0x0e, 0x0b, 0xef, 0xf3, 0x14, 0x26, + 0x0d, 0x14, 0xa1, 0x41, 0x80, 0x21, 0x0a, 0x0d, 0x04, 0xe8, 0x8a, 0x20, + 0x04, 0x00, 0x03, 0xf0, 0x40, 0xd8, 0xe0, 0xb1, 0xfa, 0x1d, 0x1c, 0x10, + 0x06, 0x71, 0xb7, 0xf1, 0x8e, 0xc0, 0x2c, 0x70, 0x8a, 0x22, 0x06, 0x00, + 0x7e, 0x0a, 0x2f, 0xf7, 0x40, 0x24, 0x10, 0x3e, 0x54, 0x26, 0x93, 0x1e, + 0x40, 0x24, 0x4f, 0x30, 0x04, 0x13, 0x00, 0x24, 0xd5, 0xe0, 0x9c, 0x00, + 0x29, 0x00, 0x4e, 0x68, 0xbc, 0xe2, 0x34, 0x01, 0x2d, 0x00, 0x2c, 0x71, + 0x0c, 0x70, 0x28, 0x43, 0x8d, 0x70, 0x25, 0x20, 0x80, 0x00, 0x69, 0xf0, + 0x90, 0xf0, 0x67, 0xf0, 0x8e, 0xf0, 0x65, 0xf0, 0x8c, 0xf0, 0x63, 0xf0, + 0x8a, 0xf0, 0x61, 0xf0, 0x88, 0xf0, 0x5f, 0xf0, 0x86, 0xf0, 0x5d, 0xf0, + 0x84, 0xf0, 0x84, 0xf0, 0x82, 0xf0, 0x82, 0xf0, 0x80, 0xf0, 0x2c, 0xf0, + 0x7e, 0xf0, 0x2a, 0xf0, 0x7c, 0xf0, 0x28, 0xf0, 0x7a, 0xf0, 0x26, 0xf0, + 0x78, 0xf0, 0x24, 0xf0, 0x76, 0xf0, 0x22, 0xf0, 0x74, 0xf0, 0x20, 0xf0, + 0x72, 0xf0, 0x72, 0xf0, 0x70, 0xf0, 0x70, 0xf0, 0x6e, 0xf0, 0x2f, 0xf0, + 0x6c, 0xf0, 0x2d, 0xf0, 0x6a, 0xf0, 0x2b, 0xf0, 0x68, 0xf0, 0x29, 0xf0, + 0x66, 0xf0, 0x27, 0xf0, 0x64, 0xf0, 0x25, 0xf0, 0x62, 0xf0, 0x23, 0xf0, + 0x60, 0xf0, 0x33, 0xf0, 0x5e, 0xf0, 0x31, 0xf0, 0x5c, 0xf0, 0x2f, 0xf0, + 0x5a, 0xf0, 0x31, 0xf0, 0x58, 0xf0, 0x2f, 0xf0, 0x56, 0xf0, 0x2d, 0xf0, + 0x0c, 0x70, 0x2c, 0x70, 0x6d, 0x71, 0x28, 0xf0, 0x8c, 0x20, 0x42, 0x8d, + 0xd1, 0xf6, 0x2c, 0x71, 0x8c, 0x20, 0x82, 0x8d, 0x44, 0xf2, 0x8c, 0x20, + 0x02, 0x8e, 0xf4, 0xf3, 0x8c, 0x20, 0x82, 0x8e, 0x42, 0xf2, 0x8c, 0x20, + 0x03, 0x80, 0x0c, 0xf2, 0x40, 0xf0, 0x0c, 0x71, 0x12, 0xf0, 0x80, 0x20, + 0xbe, 0x0a, 0x79, 0x08, 0x75, 0x01, 0x15, 0xd9, 0x71, 0x09, 0x0e, 0x00, + 0x2c, 0x71, 0x0c, 0x70, 0x28, 0x43, 0x8d, 0x71, 0x20, 0xaf, 0x01, 0xaf, + 0x02, 0xaf, 0x60, 0xc1, 0x05, 0xf0, 0x0c, 0x70, 0x2c, 0x71, 0x08, 0x43, + 0x8d, 0x71, 0x86, 0xe8, 0x04, 0xe9, 0x09, 0x0b, 0x10, 0x10, 0x95, 0xec, + 0x34, 0x70, 0xc3, 0x43, 0xcc, 0x3d, 0xcd, 0xcc, 0xc3, 0x42, 0x8b, 0x3a, + 0x58, 0xa0, 0xc3, 0x41, 0x1c, 0x41, 0x0a, 0xe8, 0x7c, 0x72, 0x75, 0x70, + 0xc3, 0x40, 0x20, 0x3c, 0x12, 0xac, 0x5c, 0x71, 0x95, 0x70, 0x3c, 0x70, + 0x40, 0xc0, 0x80, 0xc1, 0x4c, 0x74, 0x0a, 0x0b, 0x2f, 0xe9, 0x02, 0x40, + 0xa5, 0x71, 0xe0, 0xe5, 0xd4, 0x06, 0xe5, 0xff, 0x06, 0x74, 0x0e, 0xf0, + 0x0c, 0x70, 0x6d, 0x71, 0x8d, 0x70, 0xdb, 0xf1, 0x0c, 0x71, 0xd7, 0xf1, + 0x2c, 0x71, 0x0c, 0x70, 0x00, 0x1c, 0x01, 0x30, 0x28, 0x43, 0xd2, 0xf1, + 0x00, 0x12, 0x82, 0x20, 0xdf, 0x16, 0x00, 0x16, 0x0e, 0x0f, 0xef, 0xf2, + 0x8e, 0xc1, 0x7f, 0xda, 0xc3, 0x43, 0xc8, 0x42, 0x00, 0x00, 0x17, 0xba, + 0xc3, 0x41, 0x74, 0x49, 0x00, 0x24, 0xc3, 0x40, 0x7a, 0x44, 0x00, 0x00, + 0xfb, 0x19, 0x43, 0xa0, 0xde, 0x1e, 0x19, 0x10, 0xdd, 0x1e, 0xd8, 0x10, + 0x4c, 0xa6, 0x2b, 0xa6, 0x0a, 0xa6, 0xd0, 0xc7, 0xea, 0xc2, 0x10, 0x40, + 0xe2, 0x0f, 0xaf, 0xeb, 0x55, 0x20, 0x4d, 0x0a, 0x8a, 0x21, 0x44, 0x20, + 0xff, 0xdf, 0xcb, 0x41, 0x23, 0x3c, 0x0a, 0xd7, 0xc3, 0x40, 0x48, 0x43, + 0x00, 0x00, 0x83, 0xdc, 0x76, 0x18, 0x83, 0x20, 0x74, 0x18, 0x05, 0x20, + 0x8a, 0x26, 0x01, 0x09, 0xcb, 0x40, 0xa0, 0x42, 0x00, 0x00, 0xcb, 0x43, + 0x20, 0x41, 0x00, 0x00, 0x16, 0xbf, 0xcb, 0x46, 0xfa, 0x44, 0x00, 0x00, + 0xdb, 0x47, 0x0e, 0x3d, 0x4d, 0xf3, 0x0a, 0x26, 0x80, 0x3f, 0xd6, 0x3c, + 0x62, 0xa1, 0xc3, 0x45, 0x03, 0x3b, 0x6f, 0x12, 0x8a, 0x24, 0x07, 0x0d, + 0x8a, 0x27, 0x04, 0x0b, 0x17, 0xbc, 0xc3, 0x43, 0xc8, 0x41, 0x00, 0x00, + 0xc3, 0x42, 0x7a, 0x45, 0x00, 0x00, 0xc3, 0x41, 0x70, 0x41, 0x00, 0x00, + 0x68, 0x18, 0x44, 0x24, 0x70, 0x18, 0x40, 0x22, 0x6c, 0x18, 0x00, 0x20, + 0x8a, 0x20, 0x87, 0x00, 0x1f, 0xa5, 0x48, 0x1d, 0x80, 0x11, 0x44, 0x1d, + 0x00, 0x12, 0x40, 0x1d, 0xc0, 0x12, 0xef, 0xa5, 0xce, 0xa5, 0xe4, 0x1d, + 0xc0, 0x97, 0xe0, 0x1d, 0x80, 0x97, 0xdc, 0x1d, 0x40, 0x91, 0x74, 0x1d, + 0x00, 0x11, 0x64, 0x1d, 0xc0, 0x11, 0x98, 0xa5, 0x77, 0xa5, 0x56, 0xa5, + 0x29, 0xa5, 0xca, 0xc6, 0xe4, 0xc0, 0xcb, 0x46, 0x7f, 0x47, 0x00, 0xff, + 0x2d, 0xdd, 0x80, 0xdc, 0x8a, 0x23, 0x08, 0x00, 0xc3, 0x42, 0x00, 0x00, + 0xff, 0xff, 0x2c, 0x70, 0x1a, 0x18, 0xc3, 0x00, 0xc8, 0xa0, 0xae, 0xb0, + 0x8c, 0xb0, 0x65, 0xa0, 0x49, 0xb0, 0x42, 0xa0, 0x43, 0xb0, 0x26, 0xb0, + 0x27, 0xb0, 0x28, 0xb0, 0xc4, 0xc4, 0xe0, 0x78, 0xe6, 0xc2, 0x08, 0x45, + 0x1a, 0x0f, 0xef, 0xff, 0x55, 0x20, 0x8e, 0x0a, 0xfe, 0x08, 0xaf, 0xfc, + 0xa1, 0x40, 0x11, 0x86, 0xd8, 0x16, 0x01, 0x90, 0x11, 0xdb, 0x48, 0x30, + 0x80, 0x00, 0x1a, 0xbb, 0x00, 0x30, 0xc0, 0x00, 0x3b, 0xdf, 0xcb, 0x44, + 0x83, 0x3a, 0x6f, 0x12, 0x00, 0x31, 0x82, 0x0f, 0xc8, 0x42, 0x00, 0x00, + 0x18, 0xbf, 0x00, 0x30, 0x01, 0x03, 0x0d, 0x70, 0x00, 0x32, 0xc0, 0x03, + 0xcb, 0x43, 0x74, 0x45, 0x00, 0x24, 0x04, 0x31, 0x00, 0x82, 0x3c, 0x1d, + 0x43, 0x10, 0xe4, 0x1e, 0x43, 0x90, 0xfe, 0xa5, 0x04, 0x1d, 0xc0, 0x12, + 0x1f, 0xa5, 0xc7, 0xf6, 0x01, 0x31, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, + 0x05, 0xf0, 0x01, 0x31, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x38, 0x86, + 0x48, 0x30, 0xc2, 0x02, 0x48, 0x31, 0x81, 0x00, 0x00, 0x31, 0xc0, 0x00, + 0x48, 0x32, 0x81, 0x00, 0x00, 0x30, 0x00, 0x03, 0x48, 0x31, 0xc1, 0x02, + 0x04, 0x30, 0x00, 0x82, 0x32, 0xa6, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0x3e, 0x86, 0x48, 0x30, 0xc2, 0x02, 0x6d, 0x70, 0x48, 0x31, + 0x81, 0x00, 0x00, 0x31, 0xc0, 0x00, 0x48, 0x32, 0x81, 0x00, 0x00, 0x30, + 0x00, 0x03, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, 0xc0, 0x82, 0x39, 0xa6, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x3c, 0x86, 0x48, 0x30, + 0xc2, 0x02, 0x48, 0x31, 0x81, 0x00, 0x00, 0x31, 0xc0, 0x00, 0x48, 0x32, + 0x81, 0x00, 0x00, 0x30, 0x00, 0x03, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, + 0xc0, 0x82, 0x3d, 0xa6, 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, + 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, + 0x48, 0x30, 0xc0, 0x02, 0x4a, 0x24, 0xc0, 0x70, 0x48, 0x30, 0x80, 0x00, + 0xc3, 0x41, 0x13, 0x00, 0xf0, 0x6b, 0x48, 0x30, 0xc0, 0x02, 0x49, 0x20, + 0x00, 0x05, 0x48, 0x20, 0x80, 0x00, 0x1f, 0xa6, 0x0a, 0x20, 0x40, 0x03, + 0x80, 0x20, 0x0a, 0x04, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x02, 0x04, + 0x04, 0x18, 0x90, 0x00, 0xc3, 0x40, 0x06, 0x3b, 0x00, 0xe2, 0x7e, 0x1e, + 0x18, 0x10, 0x32, 0x0e, 0x2f, 0xfd, 0xa1, 0x40, 0xc6, 0xc6, 0xe0, 0x78, + 0xea, 0xc3, 0xa7, 0xc1, 0x47, 0xdc, 0x4a, 0x24, 0x00, 0x71, 0x08, 0x46, + 0x55, 0x20, 0x4f, 0x08, 0x6d, 0x18, 0x03, 0x02, 0x18, 0xbc, 0xc3, 0x43, + 0xa3, 0x42, 0x0b, 0xd7, 0xcb, 0x45, 0xd3, 0x3e, 0x98, 0xdd, 0xc3, 0x42, + 0x3b, 0x4a, 0xc1, 0xbf, 0xc3, 0x41, 0xdc, 0x44, 0x30, 0x4e, 0xc3, 0x40, + 0x7b, 0x3e, 0xd7, 0x5e, 0x90, 0x1e, 0x85, 0x11, 0x55, 0x26, 0x0b, 0x18, + 0x9a, 0xa6, 0x79, 0xa6, 0xb8, 0xa6, 0x55, 0xa6, 0x34, 0xa6, 0x0c, 0xa6, + 0x0a, 0x20, 0x80, 0x0f, 0x13, 0x00, 0xc4, 0x6d, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x10, 0x01, 0x04, 0x04, 0x1b, 0x50, 0x10, 0x4a, 0x24, 0x00, 0x71, + 0xcb, 0x43, 0x51, 0x3f, 0x18, 0xb7, 0xcb, 0x44, 0x98, 0x3d, 0xc2, 0xb5, + 0xc3, 0x43, 0x4c, 0x3f, 0xcd, 0xcc, 0x8a, 0x22, 0x10, 0x02, 0xc3, 0x41, + 0x83, 0x41, 0x3b, 0x6c, 0xc3, 0x40, 0x21, 0x3d, 0xe0, 0x61, 0x28, 0x1e, + 0x85, 0x11, 0xb7, 0xa6, 0x48, 0x1f, 0xc0, 0x12, 0x8a, 0xa7, 0x7b, 0xa7, + 0xea, 0x1e, 0x84, 0x10, 0x2b, 0xa6, 0x2c, 0x70, 0xd3, 0x40, 0x80, 0x3f, + 0x00, 0x00, 0x1a, 0xa7, 0xa8, 0x20, 0x40, 0x03, 0x15, 0x26, 0x40, 0x10, + 0x80, 0x10, 0x00, 0x00, 0x83, 0xc5, 0x15, 0x25, 0x42, 0x10, 0x02, 0x30, + 0x00, 0x20, 0x24, 0x71, 0x00, 0xa2, 0x2e, 0x0a, 0xa0, 0x01, 0x83, 0xc0, + 0x4a, 0x21, 0x00, 0x20, 0xa6, 0x0e, 0xef, 0xfa, 0x00, 0x15, 0x00, 0x10, + 0x26, 0x71, 0xf9, 0x09, 0x34, 0xa1, 0x04, 0x1d, 0x10, 0x10, 0x4a, 0x24, + 0x00, 0x71, 0x54, 0x26, 0x00, 0x1e, 0x83, 0xc1, 0xa8, 0x20, 0x00, 0x02, + 0x04, 0x11, 0x02, 0x04, 0x02, 0x30, 0x82, 0x20, 0x04, 0x18, 0x90, 0x00, + 0x3e, 0x86, 0x1f, 0x86, 0x5d, 0x86, 0x6a, 0x87, 0x4a, 0x24, 0xc0, 0x70, + 0x55, 0x26, 0x10, 0x1a, 0x41, 0xc1, 0x42, 0xc0, 0x80, 0xc1, 0x0a, 0x20, + 0x00, 0x04, 0x40, 0xc2, 0xa8, 0x20, 0x00, 0x02, 0x04, 0x11, 0x02, 0x04, + 0x07, 0x33, 0x82, 0x00, 0x04, 0x18, 0x90, 0x00, 0x4a, 0x24, 0xc0, 0x70, + 0x0c, 0x70, 0xbc, 0x4e, 0x36, 0x1e, 0x43, 0x10, 0x35, 0x1e, 0x43, 0x10, + 0x2a, 0x1e, 0x02, 0x10, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x19, 0x11, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x26, 0x00, 0x14, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x18, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x04, 0x6e, 0xad, 0x70, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0x78, 0x4e, 0x34, 0x1e, + 0x42, 0x13, 0xd2, 0x0b, 0x2f, 0xfc, 0x2a, 0x1e, 0x42, 0x13, 0x02, 0x87, + 0x40, 0x87, 0x21, 0x87, 0x8a, 0x87, 0x4a, 0x24, 0xc0, 0x70, 0xc3, 0x43, + 0x51, 0x39, 0x17, 0xb7, 0xa6, 0xa7, 0xa4, 0xa7, 0x36, 0x1e, 0x43, 0x10, + 0x35, 0x1e, 0x43, 0x10, 0x14, 0x1f, 0xc0, 0x10, 0x45, 0xc0, 0x83, 0xc0, + 0x43, 0xc2, 0x44, 0xc1, 0xa8, 0x20, 0x00, 0x02, 0x04, 0x10, 0x01, 0x04, + 0x07, 0x34, 0x41, 0x10, 0x04, 0x18, 0x50, 0x20, 0x4a, 0x24, 0xc0, 0x70, + 0x0c, 0x70, 0x55, 0x26, 0x41, 0x1b, 0x0b, 0xa7, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x19, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x19, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x55, 0x26, 0x00, 0x1d, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0xe9, 0x1e, 0x03, 0x10, + 0x00, 0x18, 0x03, 0x00, 0xca, 0xc7, 0xe0, 0x78, 0x4a, 0x24, 0xc0, 0x70, + 0xc3, 0x41, 0x8c, 0x42, 0x00, 0x00, 0xcb, 0x44, 0xa0, 0x40, 0x00, 0x00, + 0xfa, 0xdb, 0x40, 0x20, 0x02, 0x06, 0x08, 0x18, 0x41, 0x01, 0x04, 0x18, + 0x43, 0x00, 0x2a, 0xa0, 0x85, 0xa0, 0x24, 0xa0, 0x0c, 0x18, 0xc0, 0x00, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1a, 0x11, 0x00, 0xe0, 0x7f, 0x00, 0x1a, + 0x01, 0x00, 0xe0, 0x78, 0xe8, 0xc2, 0x4a, 0x24, 0x80, 0x71, 0x10, 0x40, + 0x55, 0x20, 0x8e, 0x0e, 0xc3, 0x43, 0xa0, 0x3f, 0x00, 0x00, 0xc3, 0x42, + 0x7a, 0x44, 0x00, 0x00, 0xc3, 0x41, 0xfa, 0x43, 0x00, 0x00, 0x8d, 0x70, + 0xc3, 0x40, 0x00, 0x00, 0x40, 0x9c, 0x14, 0x1e, 0x01, 0x10, 0x64, 0xa6, + 0x43, 0xa6, 0x22, 0xa6, 0x56, 0x20, 0x01, 0x28, 0xcb, 0x45, 0x13, 0x00, + 0x64, 0x6c, 0x01, 0xa6, 0x00, 0x1e, 0x00, 0x10, 0xa8, 0x20, 0x80, 0x02, + 0x98, 0x65, 0x08, 0x10, 0xc0, 0x00, 0x85, 0x71, 0x48, 0x30, 0x80, 0x00, + 0x04, 0x19, 0x10, 0x00, 0xc3, 0x41, 0x20, 0x42, 0x00, 0x00, 0x8a, 0x20, + 0x04, 0x07, 0x40, 0x25, 0x0f, 0x1d, 0x2c, 0xa6, 0x02, 0x70, 0x18, 0xda, + 0xe6, 0x0d, 0xef, 0xe8, 0xe1, 0x41, 0x8a, 0x20, 0x04, 0x0d, 0x02, 0x70, + 0x54, 0x25, 0x81, 0x19, 0xd6, 0x0d, 0xef, 0xe8, 0x18, 0xda, 0x8a, 0x20, + 0x05, 0x03, 0x02, 0x70, 0x18, 0xda, 0xca, 0x0d, 0xef, 0xe8, 0xe1, 0x41, + 0x4a, 0x24, 0xc0, 0x70, 0x8a, 0x20, 0x05, 0x09, 0x7d, 0xd9, 0x02, 0x70, + 0x40, 0x29, 0xc1, 0x05, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x50, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x0a, 0x21, 0x80, 0x0f, 0x74, 0x49, 0x00, 0x24, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x50, 0x00, 0x4a, 0x24, 0x80, 0x71, + 0x81, 0xd9, 0x17, 0xb9, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x50, 0x00, + 0x28, 0x15, 0x08, 0x10, 0x2c, 0x15, 0x0b, 0x10, 0xec, 0x85, 0x4a, 0x24, + 0xc0, 0x70, 0x7d, 0xda, 0x8a, 0x21, 0x06, 0x0b, 0xcb, 0x44, 0xc8, 0x41, + 0x00, 0x00, 0xc3, 0x43, 0x12, 0x00, 0x80, 0x4f, 0x05, 0xba, 0x02, 0x71, + 0x00, 0x18, 0x00, 0x03, 0xc0, 0x1e, 0xc0, 0x10, 0xbc, 0x1e, 0x80, 0x10, + 0xb4, 0x1e, 0xc0, 0x12, 0xb0, 0x1e, 0x00, 0x12, 0xb8, 0x1e, 0xc0, 0x13, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x19, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, + 0x56, 0x20, 0xc1, 0x2d, 0x0a, 0x20, 0x40, 0x03, 0xa8, 0x20, 0x00, 0x02, + 0x02, 0x10, 0x42, 0x05, 0x48, 0x32, 0x82, 0x00, 0x04, 0x19, 0x90, 0x00, + 0x8a, 0x21, 0x0f, 0x0a, 0x8a, 0x20, 0x09, 0x0f, 0xdc, 0x1e, 0x40, 0x10, + 0x00, 0x20, 0x0e, 0x20, 0xf6, 0x0b, 0xaf, 0xef, 0xc1, 0x40, 0x08, 0xd9, + 0x0a, 0x0d, 0xaf, 0xef, 0xc1, 0x40, 0x1c, 0xe5, 0x8a, 0x21, 0x08, 0x00, + 0x02, 0x40, 0xb6, 0x08, 0x20, 0x00, 0xa1, 0x42, 0x8a, 0x21, 0x08, 0x00, + 0x02, 0x40, 0xaa, 0x08, 0x20, 0x00, 0xa1, 0x42, 0x0a, 0x08, 0x20, 0x00, + 0x02, 0x40, 0xc8, 0xc6, 0xe6, 0xc3, 0xa6, 0xc1, 0x08, 0x46, 0x55, 0x20, + 0xcf, 0x0c, 0x8a, 0x20, 0x09, 0x0f, 0xd8, 0x60, 0x96, 0x0c, 0xaf, 0xef, + 0x8a, 0x25, 0x0c, 0x1f, 0x4a, 0x24, 0x00, 0x71, 0xc1, 0x42, 0xb8, 0x66, + 0xad, 0x70, 0x2c, 0x70, 0x80, 0x22, 0x0c, 0x01, 0xa8, 0x20, 0xc0, 0x02, + 0x33, 0x21, 0x83, 0x0f, 0x13, 0x00, 0x60, 0x6c, 0x24, 0x71, 0x48, 0x33, + 0x83, 0x00, 0x04, 0x1a, 0xd0, 0x00, 0x4a, 0x24, 0x80, 0x72, 0x93, 0x1f, + 0x58, 0x13, 0x00, 0x18, 0x83, 0x02, 0xe0, 0x18, 0x44, 0x83, 0xd8, 0x18, + 0x44, 0x83, 0xe2, 0x18, 0x42, 0x83, 0xda, 0x18, 0x42, 0x83, 0xc0, 0x18, + 0x42, 0x83, 0x8a, 0x20, 0x0b, 0x05, 0xd8, 0x60, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x18, 0x11, 0x00, 0x40, 0x87, 0x21, 0x87, 0x02, 0x87, 0x8d, 0x1f, + 0x58, 0x13, 0x43, 0xc2, 0x44, 0xc1, 0x45, 0xc0, 0x40, 0x26, 0x02, 0x18, + 0x80, 0xc1, 0xc1, 0x40, 0x40, 0xc5, 0x41, 0xc5, 0x2a, 0x0f, 0x2f, 0xfe, + 0x42, 0xc5, 0x80, 0x26, 0x0c, 0x19, 0xa0, 0xae, 0xc6, 0xc7, 0xe0, 0x78, + 0xf0, 0xc3, 0xa6, 0xc1, 0x40, 0x92, 0xc3, 0x43, 0x48, 0x47, 0x00, 0x00, + 0x00, 0x20, 0x8d, 0x0f, 0x00, 0x00, 0xbc, 0x02, 0x48, 0x32, 0x02, 0x00, + 0x10, 0x40, 0x07, 0x33, 0x82, 0x00, 0xbb, 0x15, 0x00, 0x96, 0xcb, 0x46, + 0xc8, 0x41, 0x00, 0x00, 0xd1, 0x41, 0x48, 0x30, 0x80, 0x00, 0xcb, 0x44, + 0x83, 0x3a, 0x6f, 0x12, 0x48, 0x31, 0x0b, 0x00, 0x0d, 0x70, 0x04, 0x32, + 0x80, 0x83, 0xca, 0x21, 0x85, 0x20, 0x00, 0x31, 0x00, 0x20, 0x00, 0x30, + 0x00, 0x03, 0x04, 0x30, 0x00, 0x82, 0xc7, 0xf6, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, + 0x00, 0x00, 0xba, 0x15, 0x01, 0x96, 0x48, 0x30, 0xc2, 0x02, 0x07, 0x33, + 0xd2, 0x02, 0x8a, 0x27, 0x0c, 0x17, 0x48, 0x31, 0x81, 0x00, 0x00, 0x31, + 0x40, 0x20, 0x48, 0x32, 0x81, 0x00, 0x00, 0x30, 0x00, 0x03, 0x48, 0x31, + 0xc1, 0x02, 0x04, 0x30, 0x00, 0x82, 0x3c, 0xa5, 0xc6, 0xf6, 0x01, 0x30, + 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, 0x01, 0x30, 0x80, 0x0f, + 0x00, 0xbf, 0x00, 0x00, 0x07, 0x36, 0x8b, 0x74, 0x80, 0x3f, 0x00, 0x00, + 0x8b, 0x15, 0x01, 0x96, 0x48, 0x30, 0xc2, 0x02, 0x6c, 0x70, 0x48, 0x31, + 0x80, 0x00, 0x48, 0x32, 0x82, 0x00, 0x02, 0x77, 0x00, 0x31, 0x00, 0x20, + 0x48, 0x32, 0xc2, 0x02, 0x5b, 0xa5, 0x00, 0x33, 0x00, 0x10, 0x78, 0x1d, + 0xc0, 0x12, 0x00, 0x30, 0x00, 0x03, 0x04, 0x30, 0xc0, 0x80, 0xc7, 0xf6, + 0x01, 0x30, 0x81, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x05, 0xf0, 0x01, 0x30, + 0x81, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x8c, 0x15, 0x00, 0x96, 0x48, 0x31, + 0xc1, 0x02, 0x48, 0x30, 0x80, 0x00, 0x34, 0xaf, 0x00, 0x31, 0x00, 0x20, + 0x00, 0x33, 0x00, 0x10, 0x00, 0x30, 0x00, 0x03, 0x04, 0x30, 0xc0, 0x80, + 0xc6, 0xf6, 0x01, 0x30, 0x81, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x81, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x90, 0x15, 0x00, 0x96, + 0x48, 0x31, 0xc1, 0x02, 0x4c, 0x70, 0x48, 0x30, 0x80, 0x00, 0x35, 0xaf, + 0x00, 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x03, 0x04, 0x30, 0x80, 0x80, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x08, 0x15, 0x01, 0x90, + 0x48, 0x30, 0xc3, 0x02, 0x57, 0xa5, 0x48, 0x31, 0x81, 0x00, 0x40, 0xb7, + 0x00, 0x31, 0x40, 0x20, 0x42, 0xaf, 0x48, 0x33, 0x81, 0x00, 0x00, 0x30, + 0x00, 0x03, 0x48, 0x31, 0xc1, 0x02, 0x04, 0x30, 0x80, 0x80, 0x3f, 0xa5, + 0xc6, 0xf6, 0x01, 0x30, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x30, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, + 0x00, 0x31, 0x81, 0x2f, 0xcc, 0x3e, 0xcd, 0xcc, 0x4c, 0x70, 0x48, 0x30, + 0x80, 0x00, 0x04, 0x31, 0x80, 0x80, 0x48, 0x30, 0xc0, 0x02, 0x19, 0xa5, + 0xc6, 0xf6, 0x01, 0x31, 0x80, 0x0f, 0x00, 0x3f, 0x00, 0x00, 0x06, 0xf0, + 0x01, 0x31, 0x80, 0x0f, 0x00, 0xbf, 0x00, 0x00, 0x48, 0x30, 0xc1, 0x02, + 0x8a, 0x20, 0x09, 0x0f, 0x02, 0x70, 0x55, 0x20, 0x93, 0x2e, 0x4a, 0x0a, + 0xaf, 0xef, 0x20, 0x1f, 0x42, 0x10, 0x4a, 0x24, 0x80, 0x72, 0x8a, 0x20, + 0x0b, 0x05, 0x2c, 0x70, 0x00, 0x20, 0x00, 0x04, 0xe0, 0x1f, 0x42, 0x90, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0x40, 0x20, 0x00, 0x22, + 0xe0, 0xda, 0x62, 0x41, 0x5e, 0x0a, 0xef, 0xe8, 0x44, 0x1d, 0x01, 0x10, + 0x8a, 0x21, 0x04, 0x07, 0x02, 0x71, 0x80, 0xc0, 0x18, 0xda, 0x4e, 0x0a, + 0xef, 0xe8, 0x40, 0x24, 0x14, 0x30, 0x4a, 0x24, 0x80, 0x71, 0x40, 0x20, + 0x13, 0x2f, 0xcb, 0x47, 0xc8, 0x42, 0x00, 0x00, 0xa8, 0x20, 0x80, 0x03, + 0x04, 0x14, 0x00, 0x24, 0x00, 0x30, 0x80, 0x03, 0x07, 0x30, 0x40, 0x04, + 0x00, 0x30, 0xc0, 0x03, 0x07, 0x30, 0x80, 0x04, 0x04, 0x1b, 0x10, 0x20, + 0x8a, 0x21, 0x04, 0x0d, 0x02, 0x71, 0x80, 0xc0, 0x18, 0xda, 0x12, 0x0a, + 0xef, 0xe8, 0x40, 0x24, 0x14, 0x30, 0x4a, 0x24, 0x80, 0x71, 0xa8, 0x20, + 0xc0, 0x03, 0x04, 0x14, 0x00, 0x24, 0x00, 0x30, 0x80, 0x03, 0x07, 0x30, + 0x40, 0x04, 0x00, 0x30, 0xc0, 0x03, 0x07, 0x30, 0x80, 0x04, 0x04, 0x1b, + 0x10, 0x20, 0x8a, 0x21, 0x05, 0x03, 0x02, 0x71, 0x80, 0xc0, 0x18, 0xda, + 0xde, 0x09, 0xef, 0xe8, 0x40, 0x24, 0x14, 0x30, 0x4a, 0x24, 0x80, 0x71, + 0xa8, 0x20, 0x80, 0x03, 0x04, 0x14, 0x00, 0x24, 0x00, 0x30, 0x80, 0x03, + 0x07, 0x30, 0x40, 0x04, 0x00, 0x30, 0xc0, 0x03, 0x07, 0x30, 0x80, 0x04, + 0x04, 0x1b, 0x10, 0x20, 0xb6, 0x15, 0x00, 0x96, 0xc3, 0x41, 0x48, 0x41, + 0x00, 0x00, 0x04, 0x31, 0x40, 0xa0, 0x00, 0x30, 0x80, 0x03, 0xca, 0x21, + 0x45, 0x20, 0x07, 0x30, 0x40, 0x04, 0x04, 0x18, 0x43, 0x20, 0x7e, 0x1d, + 0x18, 0x90, 0xd0, 0xc7, 0xa3, 0xc1, 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x20, + 0x02, 0x02, 0x2c, 0x70, 0x38, 0x18, 0x45, 0x00, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x1a, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0x3a, 0x18, 0x42, 0x00, + 0x40, 0xc1, 0x41, 0xc1, 0x62, 0xc1, 0x80, 0xc3, 0x80, 0xc1, 0xa8, 0x20, + 0x40, 0x01, 0x04, 0x19, 0x53, 0x00, 0x4a, 0x24, 0x40, 0x72, 0xa8, 0x20, + 0x40, 0x02, 0x01, 0x13, 0xc1, 0x04, 0x48, 0x31, 0x81, 0x00, 0x04, 0x1a, + 0x50, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0xfc, 0x48, 0x40, 0x20, 0x02, 0x02, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x12, 0x03, 0x04, 0x04, 0x19, 0xd0, 0x00, + 0x48, 0x18, 0x03, 0x00, 0xe0, 0x7f, 0xa3, 0xc0, 0xe8, 0xc2, 0x08, 0x45, + 0x55, 0x20, 0x10, 0x08, 0xcd, 0x70, 0xcb, 0x41, 0x32, 0x01, 0xe6, 0x78, + 0x3e, 0x18, 0xc5, 0x01, 0xcb, 0x40, 0x00, 0x00, 0x9c, 0x6c, 0x58, 0x18, + 0x45, 0x00, 0xcb, 0x43, 0xef, 0x41, 0x96, 0xe8, 0xcb, 0x47, 0x5f, 0x05, + 0xbe, 0x0a, 0xcb, 0x44, 0x64, 0x75, 0x84, 0x00, 0xc3, 0x43, 0x5f, 0x05, + 0x4a, 0x00, 0xc3, 0x42, 0x0c, 0x00, 0x0c, 0x00, 0xc3, 0x41, 0xaa, 0x7e, + 0xa0, 0x00, 0x8a, 0x26, 0x04, 0x00, 0x7d, 0xd8, 0x20, 0x18, 0x80, 0x23, + 0x1c, 0x18, 0x80, 0x23, 0x20, 0x1d, 0x40, 0x12, 0x26, 0x1d, 0x04, 0x12, + 0x54, 0x1d, 0xc0, 0x12, 0xf4, 0xa5, 0x8a, 0xa5, 0x73, 0xa5, 0x46, 0xa5, + 0x44, 0x1d, 0x84, 0x13, 0x30, 0xa5, 0x48, 0x1d, 0x84, 0x11, 0xc5, 0xa5, + 0xd7, 0xb5, 0xd9, 0xb5, 0xdb, 0xb5, 0xdd, 0xb5, 0x1f, 0xa5, 0x04, 0x18, + 0x00, 0x20, 0xc2, 0x0f, 0x20, 0x02, 0x0c, 0x70, 0x9e, 0x20, 0x06, 0x04, + 0x6c, 0x70, 0x8a, 0x22, 0xdd, 0x09, 0x8a, 0x21, 0xb5, 0x0d, 0x8a, 0x27, + 0xdc, 0x1c, 0xcb, 0x44, 0x33, 0x09, 0x00, 0x00, 0x8b, 0xbb, 0x24, 0x18, + 0x82, 0x23, 0xdc, 0xa5, 0xdb, 0xa5, 0xd8, 0xb5, 0x2c, 0x1d, 0x83, 0x10, + 0x74, 0x1d, 0x45, 0x10, 0x4a, 0x1d, 0x82, 0x13, 0x46, 0x1d, 0x84, 0x13, + 0xdc, 0xb5, 0x3c, 0x1d, 0x82, 0x13, 0xc3, 0xa5, 0xc2, 0xa5, 0x00, 0x18, + 0x80, 0x23, 0xde, 0xa5, 0x5a, 0xa5, 0x39, 0xa5, 0x58, 0xa5, 0x37, 0xa5, + 0xf2, 0xb5, 0x87, 0xa5, 0x64, 0xa5, 0x1a, 0xb5, 0x55, 0x25, 0x80, 0x18, + 0x2c, 0x70, 0x96, 0x0e, 0xaf, 0xf6, 0x11, 0xda, 0xc8, 0xc6, 0xe0, 0x78, + 0xf1, 0xc0, 0x1e, 0x21, 0x0c, 0x00, 0x0c, 0x70, 0x8f, 0xb8, 0x31, 0x48, + 0x4c, 0x79, 0x1d, 0x7b, 0x99, 0x61, 0x78, 0x61, 0x16, 0x08, 0xaf, 0xff, + 0x0f, 0xd9, 0xd1, 0xc0, 0xe0, 0x7f, 0x0e, 0x78, 0xe4, 0xc0, 0x7f, 0xda, + 0xc3, 0x43, 0x22, 0xbe, 0x88, 0x2f, 0x17, 0xba, 0xc3, 0x41, 0xd7, 0x3e, + 0x1e, 0x74, 0xcb, 0x44, 0x13, 0x00, 0xd4, 0x6d, 0x70, 0xa0, 0x4f, 0xa0, + 0x2e, 0xa0, 0x2d, 0xa0, 0x22, 0x84, 0x41, 0x84, 0x60, 0x84, 0x23, 0xa0, + 0x42, 0xa0, 0x61, 0xa0, 0x44, 0x84, 0x63, 0x84, 0x25, 0x84, 0x4a, 0x24, + 0x80, 0x71, 0x40, 0x20, 0x0b, 0x07, 0x45, 0xa0, 0x64, 0xa0, 0x26, 0xa0, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1b, 0x11, 0x10, 0x4a, 0x24, 0xc0, 0x70, + 0x54, 0x20, 0x03, 0x0a, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x1b, 0x11, 0x00, + 0x4a, 0x24, 0xc0, 0x70, 0x54, 0x20, 0x02, 0x0c, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x1a, 0x11, 0x00, 0x4a, 0x24, 0xc0, 0x70, 0xcb, 0x46, 0x30, 0x44, + 0x66, 0xc6, 0x2c, 0x70, 0xcb, 0x45, 0x7a, 0x44, 0x00, 0x00, 0x54, 0x20, + 0x8c, 0x08, 0x70, 0x18, 0x41, 0x00, 0x74, 0x18, 0x43, 0x00, 0xc0, 0xa2, + 0x20, 0xa3, 0xbf, 0xa0, 0x78, 0x18, 0x40, 0x00, 0x84, 0x18, 0x40, 0x00, + 0x88, 0x18, 0x42, 0x00, 0x80, 0x18, 0x40, 0x00, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x1c, 0x11, 0x10, 0xc4, 0xc4, 0xe0, 0x78, 0x4a, 0x24, 0x00, 0x71, + 0xa8, 0x20, 0x80, 0x01, 0x14, 0x10, 0x02, 0x04, 0x04, 0x19, 0x90, 0x00, + 0xe0, 0x7e, 0xe0, 0x78, 0x2c, 0x72, 0x4c, 0x71, 0x2f, 0x21, 0x42, 0x80, + 0x42, 0xf7, 0x0c, 0x7a, 0x0c, 0x78, 0xfc, 0xf5, 0xe0, 0x7f, 0x40, 0x40, + 0x40, 0x81, 0x58, 0x60, 0x01, 0x10, 0xcc, 0x00, 0x00, 0x88, 0x62, 0x6a, + 0x40, 0x2c, 0x02, 0x12, 0x45, 0x78, 0xe0, 0x7f, 0x60, 0xa1, 0xe0, 0x78, + 0xe0, 0x7f, 0x00, 0xa1, 0x31, 0x88, 0x0d, 0xe9, 0x18, 0x88, 0x1b, 0x08, + 0x51, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0xa0, 0x86, 0x00, 0x88, 0x14, 0x70, + 0x80, 0xd8, 0x05, 0xf2, 0xe0, 0x7e, 0xe0, 0x7f, 0x0c, 0x70, 0xe0, 0x7f, + 0xff, 0xd8, 0xe0, 0x78, 0xf1, 0xc0, 0x58, 0x88, 0x4a, 0x24, 0xc0, 0x70, + 0x20, 0x43, 0xc3, 0x41, 0xa0, 0x00, 0xbc, 0xc1, 0xa8, 0x20, 0x80, 0x01, + 0x00, 0x81, 0x0b, 0x08, 0x80, 0x00, 0x08, 0xe1, 0x05, 0xf0, 0x96, 0x0b, + 0x20, 0x00, 0x01, 0x81, 0x00, 0xa3, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0xe6, 0xc2, 0x4a, 0x24, 0xc0, 0x70, 0xc3, 0x43, 0xa0, 0x00, 0x7c, 0xc1, + 0x28, 0x47, 0x60, 0x41, 0xa8, 0x20, 0x40, 0x02, 0x1c, 0x11, 0x02, 0x04, + 0x09, 0x0a, 0x01, 0x00, 0xe8, 0x19, 0x03, 0x80, 0xe0, 0x78, 0x58, 0x88, + 0x4a, 0x24, 0xc0, 0x70, 0x54, 0x23, 0x00, 0x08, 0xa8, 0x20, 0x80, 0x01, + 0x20, 0x80, 0x0b, 0x09, 0x80, 0x00, 0x08, 0xe0, 0x14, 0xf0, 0xc1, 0x80, + 0x04, 0x36, 0xc0, 0x93, 0x10, 0xf2, 0xcb, 0x45, 0xf0, 0x00, 0x49, 0x00, + 0x55, 0xd8, 0xee, 0x0d, 0x2f, 0xf7, 0x40, 0xad, 0x48, 0x37, 0x41, 0x12, + 0x48, 0x36, 0x40, 0x12, 0x03, 0x1d, 0x44, 0x10, 0x05, 0x1d, 0x04, 0x10, + 0xc6, 0xc6, 0xe0, 0x78, 0xfa, 0xc2, 0xfc, 0x1c, 0xc8, 0xb6, 0xd6, 0x0b, + 0x6f, 0xf4, 0xaa, 0xc1, 0x5a, 0x0f, 0x2f, 0xf4, 0x18, 0x41, 0x47, 0xc0, + 0x3b, 0x58, 0x0e, 0x70, 0x38, 0x43, 0xcb, 0x47, 0xa0, 0x00, 0xbc, 0xc1, + 0x12, 0x47, 0x12, 0x43, 0x46, 0xc0, 0x34, 0x1f, 0x00, 0x14, 0x38, 0x1f, + 0x00, 0x14, 0x3c, 0x1f, 0x00, 0x14, 0x40, 0x1f, 0x00, 0x14, 0x07, 0xc0, + 0x0c, 0x27, 0x00, 0xa0, 0x5e, 0x02, 0x26, 0x00, 0x40, 0x2f, 0xce, 0x21, + 0x23, 0x76, 0x07, 0x86, 0x14, 0x70, 0x22, 0x02, 0x02, 0x00, 0x69, 0x8e, + 0x31, 0x8e, 0x8e, 0x8e, 0x18, 0x16, 0x91, 0x10, 0x78, 0x23, 0x00, 0x00, + 0x79, 0x21, 0x02, 0x00, 0x04, 0x7a, 0x05, 0xec, 0x0d, 0x87, 0x04, 0x71, + 0x0d, 0xa7, 0x05, 0xea, 0x0e, 0x87, 0x04, 0x71, 0x0e, 0xa7, 0x05, 0xe9, + 0x0f, 0x87, 0x04, 0x71, 0x0f, 0xa7, 0x05, 0xeb, 0x10, 0x87, 0x04, 0x71, + 0x10, 0xa7, 0x78, 0x24, 0x00, 0x10, 0x46, 0x78, 0xe0, 0xb8, 0xf1, 0xf4, + 0x2f, 0x26, 0x45, 0x24, 0xd6, 0x70, 0xda, 0x01, 0x2c, 0x00, 0xae, 0x71, + 0xc1, 0x40, 0x20, 0x1c, 0xc1, 0x30, 0xd6, 0x0a, 0xaf, 0xf3, 0x24, 0x1c, + 0x40, 0x35, 0xad, 0x86, 0x2c, 0x86, 0x10, 0x42, 0x8e, 0x70, 0x2f, 0x20, + 0x40, 0x04, 0x04, 0x32, 0x00, 0xa5, 0x44, 0xc0, 0xd4, 0xf7, 0x42, 0x26, + 0x00, 0x2d, 0x0f, 0x78, 0x27, 0x08, 0xd4, 0x00, 0x19, 0x8e, 0xe5, 0xb8, + 0xa9, 0xf4, 0x50, 0x21, 0xfe, 0x87, 0xc3, 0x40, 0x48, 0x44, 0x00, 0x00, + 0xce, 0xf2, 0x04, 0x31, 0x00, 0x80, 0xca, 0x21, 0x09, 0x00, 0xcb, 0xf0, + 0xd3, 0x42, 0x7f, 0x47, 0x00, 0xff, 0x0f, 0x70, 0x84, 0xc1, 0x89, 0xc2, + 0x40, 0x24, 0x04, 0x38, 0xc3, 0x40, 0xa0, 0x00, 0x8c, 0x86, 0xe1, 0x43, + 0x18, 0x1f, 0x43, 0x10, 0x14, 0x1c, 0x80, 0x34, 0x96, 0x5a, 0x82, 0x0a, + 0xef, 0xfb, 0x10, 0x41, 0x18, 0x1f, 0x03, 0x10, 0x00, 0x16, 0x80, 0x70, + 0xa0, 0x00, 0xb8, 0x86, 0x2b, 0x08, 0x5e, 0x00, 0x45, 0x87, 0x0c, 0x17, + 0x07, 0x10, 0x08, 0x17, 0x86, 0x10, 0x04, 0x17, 0x05, 0x10, 0x00, 0x17, + 0x84, 0x10, 0x90, 0x8f, 0x28, 0xc3, 0x05, 0xc1, 0x24, 0xc0, 0x41, 0xc2, + 0x2f, 0x22, 0x47, 0x04, 0x92, 0x09, 0xaf, 0xf6, 0x40, 0xc4, 0x8c, 0x21, + 0x3f, 0xad, 0x0d, 0xf4, 0x0b, 0x87, 0x00, 0x32, 0x92, 0x2f, 0x00, 0x3f, + 0x00, 0x00, 0x86, 0x71, 0x0b, 0x08, 0x25, 0x05, 0x0f, 0x71, 0x2c, 0x1f, + 0x00, 0x15, 0x8a, 0x20, 0x3f, 0x0d, 0x04, 0x32, 0x40, 0xa3, 0x39, 0x21, + 0x00, 0x20, 0xc5, 0x20, 0x6b, 0x00, 0x05, 0x20, 0x40, 0x05, 0x7d, 0x08, + 0x51, 0x80, 0xcb, 0x45, 0xf0, 0x00, 0x34, 0x00, 0x87, 0x09, 0x32, 0x20, + 0x52, 0xd8, 0x19, 0x08, 0x30, 0x30, 0x52, 0xd8, 0x4e, 0x0c, 0x0f, 0xf7, + 0x48, 0x32, 0x41, 0x22, 0x4e, 0x21, 0x00, 0x20, 0x0c, 0xb5, 0x2d, 0xb5, + 0x08, 0xc1, 0xfe, 0x0f, 0xef, 0xfb, 0xe1, 0x40, 0x42, 0x26, 0x01, 0x2d, + 0x2f, 0x79, 0x19, 0x09, 0xf5, 0x00, 0x05, 0xc0, 0x04, 0x30, 0x80, 0x8f, + 0x7f, 0x47, 0x00, 0xff, 0x44, 0xf7, 0x7f, 0xd8, 0x17, 0xb8, 0x45, 0xc0, + 0x6a, 0x09, 0x00, 0x00, 0x44, 0x16, 0x11, 0x10, 0x08, 0x45, 0x10, 0xa6, + 0xca, 0x0a, 0x6f, 0xf5, 0xc1, 0x40, 0x24, 0xe8, 0x04, 0x31, 0x40, 0xa3, + 0x4b, 0xf2, 0x0c, 0x70, 0x04, 0x35, 0x00, 0x90, 0x46, 0x00, 0x2c, 0x00, + 0x3c, 0x96, 0xa1, 0xe9, 0x4e, 0x16, 0x82, 0x10, 0x8a, 0x21, 0xbf, 0x0f, + 0x0c, 0x77, 0x8c, 0x22, 0xc3, 0x8f, 0xca, 0x20, 0x41, 0x00, 0x38, 0x1e, + 0x45, 0x10, 0x4e, 0x1e, 0x02, 0x10, 0xff, 0xd8, 0x17, 0xf0, 0xd6, 0x0b, + 0x0f, 0xf7, 0x48, 0x32, 0x41, 0x22, 0x4e, 0x21, 0x00, 0x20, 0x0c, 0xb5, + 0x2d, 0xb5, 0x2e, 0xf0, 0x2c, 0x71, 0x12, 0x0d, 0x6f, 0xf3, 0xc1, 0x40, + 0x27, 0xf0, 0x4e, 0x70, 0x65, 0xf1, 0x04, 0x35, 0x00, 0x90, 0x10, 0xf7, + 0x0e, 0xe9, 0x1c, 0xb6, 0x0c, 0x70, 0xbe, 0x0a, 0x0f, 0xf4, 0x06, 0xc3, + 0x00, 0x42, 0x2c, 0x73, 0xac, 0x70, 0xc1, 0x40, 0x86, 0x08, 0x6f, 0xf7, + 0x0a, 0x24, 0xc0, 0x06, 0xc3, 0x40, 0x7f, 0x43, 0x00, 0x00, 0x04, 0x35, + 0x00, 0x90, 0xca, 0x20, 0x45, 0x03, 0x48, 0x30, 0x40, 0x02, 0x06, 0xc3, + 0x0f, 0x7a, 0x78, 0x22, 0x05, 0x00, 0x2c, 0x72, 0xc1, 0x40, 0x62, 0x08, + 0x6f, 0xf7, 0x0a, 0x24, 0xc0, 0x06, 0xb1, 0xa6, 0x66, 0x71, 0xcf, 0x05, + 0xef, 0xff, 0xe6, 0x71, 0x00, 0x41, 0xc3, 0x40, 0xc8, 0x3f, 0x00, 0x00, + 0x04, 0x35, 0x00, 0x90, 0xca, 0x20, 0x49, 0x03, 0x04, 0x32, 0x40, 0xa0, + 0xae, 0x70, 0xc5, 0xf6, 0x30, 0x42, 0x08, 0x45, 0x2d, 0xf1, 0x04, 0x32, + 0x00, 0xa0, 0x08, 0x45, 0xca, 0x22, 0x05, 0x20, 0x27, 0xf1, 0x49, 0x0b, + 0x30, 0x20, 0x2e, 0x71, 0x07, 0xc0, 0x1b, 0xe8, 0x18, 0xde, 0x40, 0xdd, + 0x33, 0x21, 0x80, 0x33, 0x17, 0x08, 0x52, 0x00, 0x30, 0x21, 0x41, 0x33, + 0x50, 0x21, 0xfe, 0x87, 0x05, 0xf2, 0x32, 0x0f, 0xe0, 0x00, 0x0f, 0x78, + 0x0a, 0xe8, 0x07, 0xc0, 0x06, 0x71, 0x55, 0x25, 0x0d, 0x18, 0xe1, 0x08, + 0x24, 0xa0, 0x55, 0x26, 0x0e, 0x18, 0x03, 0xf0, 0x2e, 0x70, 0xc3, 0x40, + 0xa0, 0x00, 0xa0, 0x86, 0x00, 0x18, 0x42, 0x04, 0x0c, 0x87, 0x0b, 0x08, + 0xc5, 0x04, 0x30, 0x1f, 0xc0, 0x14, 0x06, 0x0d, 0xcf, 0xfb, 0xaa, 0xc0, + 0x04, 0x14, 0x1b, 0x34, 0xda, 0xc6, 0xe0, 0x78, 0xf1, 0xc0, 0x0e, 0x0d, + 0x6f, 0xe8, 0x0c, 0x71, 0xc3, 0x41, 0x13, 0x00, 0x8c, 0x08, 0xe2, 0x09, + 0x2f, 0xf7, 0x0c, 0x72, 0xc3, 0x41, 0x13, 0x00, 0xd0, 0x08, 0x6a, 0x0a, + 0x2f, 0xf7, 0x0c, 0x72, 0xf2, 0x0e, 0xc0, 0x00, 0xd1, 0xc0, 0xe0, 0x7e, + 0x00, 0x41, 0x04, 0x30, 0x80, 0x8f, 0x7f, 0x47, 0x00, 0xff, 0x0c, 0x70, + 0xe0, 0x20, 0xca, 0x07, 0x04, 0x31, 0x00, 0x80, 0x7f, 0xd8, 0x17, 0xb8, + 0xe0, 0x7f, 0xca, 0x20, 0x4d, 0x00, 0xe0, 0x78, 0xe8, 0xc3, 0xa3, 0xc1, + 0x08, 0x47, 0x03, 0x80, 0xa6, 0x0a, 0xa0, 0x00, 0xa0, 0x80, 0x07, 0x85, + 0x1d, 0x08, 0xd0, 0x00, 0x89, 0x08, 0x51, 0x01, 0x28, 0x85, 0x44, 0x81, + 0x61, 0x91, 0x0c, 0x11, 0x10, 0x00, 0x00, 0x82, 0x82, 0xbb, 0x61, 0xb1, + 0x40, 0xc0, 0x0c, 0xf0, 0x08, 0x85, 0x02, 0x88, 0x67, 0x08, 0x7f, 0x00, + 0x80, 0xc1, 0x44, 0x85, 0x60, 0x7a, 0xa1, 0x40, 0x10, 0x40, 0x30, 0xe8, + 0xfe, 0x0f, 0x80, 0x00, 0x04, 0x87, 0x40, 0x24, 0xc3, 0x32, 0x40, 0x24, + 0x04, 0x31, 0x02, 0x41, 0xa0, 0x80, 0x11, 0x87, 0xc4, 0x85, 0xf2, 0x0e, + 0x2f, 0xfb, 0x42, 0x86, 0x52, 0x0a, 0x80, 0x00, 0x0b, 0x14, 0x80, 0x30, + 0x0f, 0x08, 0x51, 0x00, 0x00, 0xc0, 0x23, 0x85, 0x01, 0xa6, 0x60, 0x79, + 0xa1, 0x40, 0x01, 0x87, 0x07, 0x80, 0x0b, 0x20, 0x80, 0x8f, 0x00, 0x08, + 0x18, 0x00, 0x10, 0xf2, 0x04, 0x87, 0x01, 0xc1, 0x01, 0x80, 0x64, 0x80, + 0x42, 0x83, 0x20, 0xa2, 0x00, 0xc1, 0x43, 0x80, 0x60, 0x7a, 0x21, 0xa3, + 0x04, 0xf0, 0x06, 0x0c, 0x6f, 0xf6, 0xa1, 0x40, 0xa2, 0x0f, 0x80, 0x00, + 0xc8, 0xc7, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, 0xa6, 0x0f, 0x2f, 0xfb, + 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0x61, 0x00, + 0x6f, 0xfb, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, 0xaa, 0x08, 0x6f, 0xfb, + 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0x9d, 0x01, 0x6f, 0xfb, + 0x11, 0x80, 0xe0, 0x78, 0x55, 0x05, 0x2f, 0xfb, 0x11, 0x80, 0xe0, 0x78, + 0x45, 0x05, 0x6f, 0xfb, 0x11, 0x80, 0xe0, 0x78, 0x1d, 0x07, 0x6f, 0xfb, + 0x11, 0x80, 0xe0, 0x78, 0xfa, 0xc2, 0xfc, 0x1c, 0xc8, 0xb6, 0xa1, 0xc1, + 0xcb, 0x45, 0xa0, 0x00, 0x84, 0x6e, 0x0a, 0x85, 0x0a, 0x80, 0x14, 0x70, + 0xfa, 0x05, 0x62, 0x00, 0x8a, 0x20, 0xfc, 0x00, 0x0b, 0x85, 0x80, 0x20, + 0x4e, 0x00, 0x20, 0x88, 0x6e, 0x0a, 0xe0, 0x01, 0xa1, 0x40, 0x2a, 0x85, + 0x0b, 0x85, 0x4a, 0x0d, 0x20, 0x01, 0x30, 0x19, 0x41, 0x00, 0x0b, 0x85, + 0x4b, 0xd9, 0xed, 0x70, 0xdf, 0x18, 0x58, 0x03, 0x70, 0x18, 0x42, 0x00, + 0x80, 0x20, 0x0e, 0x00, 0xe0, 0xa8, 0x76, 0x09, 0x6f, 0xf6, 0x54, 0x25, + 0x80, 0x19, 0x6e, 0x09, 0x6f, 0xf6, 0x54, 0x25, 0x00, 0x18, 0xdb, 0x41, + 0x13, 0x00, 0xec, 0x6d, 0xd3, 0x41, 0x00, 0x00, 0x00, 0x80, 0xcb, 0x46, + 0x7f, 0x7f, 0xff, 0xff, 0x40, 0x24, 0x07, 0x30, 0x56, 0x21, 0xc1, 0x3b, + 0x40, 0xdb, 0xcc, 0x75, 0xa1, 0x40, 0xc3, 0x42, 0x00, 0x00, 0xef, 0xff, + 0x0a, 0x24, 0x40, 0x04, 0x40, 0xc7, 0x00, 0x1e, 0xc0, 0x73, 0xa0, 0x00, + 0x88, 0x99, 0x22, 0x0c, 0xaf, 0xf5, 0xc1, 0x45, 0xdb, 0x43, 0x13, 0x00, + 0x78, 0x6f, 0x40, 0x24, 0x07, 0x30, 0x54, 0x23, 0x81, 0x3c, 0x40, 0xdb, + 0xcc, 0x75, 0xa1, 0x40, 0xc3, 0x42, 0x00, 0x00, 0xef, 0xff, 0x0a, 0x24, + 0x40, 0x04, 0xfe, 0x0b, 0xaf, 0xf5, 0xc1, 0x45, 0x40, 0x24, 0x07, 0x30, + 0x40, 0xdb, 0xcc, 0x75, 0xc1, 0x45, 0xa1, 0x40, 0x63, 0x41, 0xc3, 0x42, + 0x00, 0x00, 0xef, 0xff, 0xe2, 0x0b, 0xaf, 0xf5, 0x0a, 0x24, 0x40, 0x04, + 0xc3, 0x40, 0x13, 0x00, 0x2c, 0x87, 0x2e, 0x09, 0x6f, 0xf5, 0x40, 0xc7, + 0xc3, 0x41, 0xa0, 0x00, 0xbc, 0x9a, 0x6a, 0x0c, 0x2f, 0xf3, 0x0c, 0x71, + 0xd3, 0x44, 0x13, 0x00, 0x78, 0x72, 0x58, 0x24, 0x40, 0x2b, 0xee, 0x08, + 0xaf, 0xf5, 0x2c, 0x71, 0x40, 0x21, 0x00, 0x35, 0xe2, 0x08, 0xaf, 0xf5, + 0x2c, 0x71, 0xd3, 0x47, 0x13, 0x00, 0x90, 0x77, 0x58, 0x27, 0x40, 0x2b, + 0x2e, 0x08, 0x20, 0x02, 0x10, 0xd9, 0xd3, 0x43, 0x13, 0x00, 0x2c, 0x75, + 0x40, 0x24, 0x05, 0x30, 0x54, 0x23, 0x81, 0x2d, 0x40, 0xda, 0x8a, 0x24, + 0x01, 0x08, 0xa1, 0x40, 0xe6, 0x0d, 0xa0, 0x01, 0x22, 0x43, 0x42, 0x27, + 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, + 0xa1, 0x40, 0xd2, 0x0d, 0xa0, 0x01, 0x22, 0x43, 0x55, 0x23, 0x01, 0x29, + 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0xba, 0x0d, 0xa0, 0x01, 0x22, 0x43, 0xd3, 0x46, 0x13, 0x00, 0x84, 0x83, + 0x40, 0x24, 0x05, 0x30, 0x55, 0x26, 0x01, 0x29, 0x40, 0xda, 0x8a, 0x24, + 0x01, 0x08, 0xa1, 0x40, 0x9e, 0x0d, 0xa0, 0x01, 0x22, 0x43, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xe2, 0x41, + 0x8a, 0x0d, 0xa0, 0x01, 0x22, 0x43, 0xc3, 0x40, 0x13, 0x00, 0xbc, 0x87, + 0x72, 0x08, 0x4f, 0xf5, 0xc3, 0x41, 0xa0, 0x00, 0x64, 0x9b, 0xb2, 0x0b, + 0x2f, 0xf3, 0x0c, 0x73, 0x40, 0x21, 0x00, 0x3f, 0x3a, 0x08, 0xaf, 0xf5, + 0x2c, 0x71, 0x54, 0x21, 0x00, 0x3a, 0x32, 0x08, 0xaf, 0xf5, 0x2c, 0x71, + 0x57, 0x27, 0x80, 0x2d, 0x82, 0x0f, 0xe0, 0x01, 0x10, 0xd9, 0xd3, 0x45, + 0x13, 0x00, 0xbc, 0x7e, 0x40, 0x24, 0x05, 0x30, 0x55, 0x25, 0x81, 0x2d, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x3a, 0x0d, 0xa0, 0x01, + 0x22, 0x43, 0xd3, 0x42, 0x13, 0x00, 0xf4, 0x79, 0x40, 0x24, 0x05, 0x30, + 0x58, 0x22, 0x01, 0x29, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0x1e, 0x0d, 0xa0, 0x01, 0x22, 0x43, 0x55, 0x25, 0xc1, 0x2f, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x0a, 0x0d, + 0xa0, 0x01, 0x22, 0x43, 0xdb, 0x40, 0x13, 0x00, 0xe8, 0x85, 0x40, 0x24, + 0x05, 0x30, 0x57, 0x20, 0x01, 0x39, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, + 0xa1, 0x40, 0xee, 0x0c, 0xa0, 0x01, 0x22, 0x43, 0x57, 0x22, 0x81, 0x2d, + 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0xd6, 0x0c, 0xa0, 0x01, 0x22, 0x43, 0xc3, 0x40, 0x13, 0x00, 0x74, 0x87, + 0xbe, 0x0f, 0x0f, 0xf5, 0xc3, 0x41, 0xa0, 0x00, 0x10, 0x9b, 0xfe, 0x0a, + 0x2f, 0xf3, 0x0c, 0x72, 0x58, 0x24, 0x00, 0x2a, 0x86, 0x0f, 0x6f, 0xf5, + 0x2c, 0x71, 0x40, 0x21, 0x00, 0x3a, 0x7e, 0x0f, 0x6f, 0xf5, 0x2c, 0x71, + 0x58, 0x27, 0x00, 0x29, 0xce, 0x0e, 0xe0, 0x01, 0x10, 0xd9, 0x58, 0x27, + 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, + 0xa1, 0x40, 0x8e, 0x0c, 0xa0, 0x01, 0x22, 0x43, 0x54, 0x27, 0x81, 0x2d, + 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0x76, 0x0c, 0xa0, 0x01, 0x22, 0x43, 0x58, 0x27, 0x81, 0x2d, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x62, 0x0c, + 0xa0, 0x01, 0x22, 0x43, 0x55, 0x26, 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x4a, 0x0c, 0xa0, 0x01, + 0x22, 0x43, 0x55, 0x27, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, + 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x36, 0x0c, 0xa0, 0x01, 0x22, 0x43, + 0x22, 0x0f, 0x2f, 0xf5, 0x56, 0x23, 0xc0, 0x39, 0xc3, 0x41, 0xa0, 0x00, + 0xd8, 0x99, 0xc6, 0x0b, 0x20, 0x01, 0x0c, 0x76, 0x2c, 0x71, 0xea, 0x0e, + 0x6f, 0xf5, 0x23, 0x40, 0x54, 0x23, 0x00, 0x3f, 0xde, 0x0e, 0x6f, 0xf5, + 0x2c, 0x71, 0x57, 0x24, 0x00, 0x2a, 0xd6, 0x0e, 0x6f, 0xf5, 0x2c, 0x70, + 0xc3, 0x40, 0x13, 0x00, 0x20, 0x81, 0x10, 0xd9, 0x22, 0x0e, 0xe0, 0x01, + 0x10, 0x40, 0x42, 0x20, 0x00, 0x29, 0x1a, 0x0e, 0xe0, 0x01, 0x2c, 0x70, + 0x57, 0x20, 0x00, 0x29, 0x0e, 0x0e, 0xe0, 0x01, 0x2c, 0x70, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x62, 0x41, + 0xce, 0x0b, 0xa0, 0x01, 0x22, 0x43, 0x54, 0x26, 0x01, 0x29, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xba, 0x0b, + 0xa0, 0x01, 0x22, 0x43, 0x57, 0x27, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xa2, 0x0b, 0xa0, 0x01, + 0x22, 0x43, 0x92, 0x0e, 0x2f, 0xf5, 0x56, 0x23, 0x40, 0x3e, 0xc3, 0x41, + 0xa0, 0x00, 0x70, 0x9a, 0x32, 0x0b, 0x20, 0x01, 0x09, 0xd8, 0x42, 0x24, + 0x00, 0x2a, 0x56, 0x0e, 0x6f, 0xf5, 0x2c, 0x71, 0x55, 0x23, 0x40, 0x3b, + 0x4a, 0x0e, 0x6f, 0xf5, 0x2c, 0x71, 0x42, 0x24, 0x00, 0x25, 0x42, 0x0e, + 0x6f, 0xf5, 0x2c, 0x70, 0x55, 0x20, 0x80, 0x2d, 0x92, 0x0d, 0xe0, 0x01, + 0x10, 0xd9, 0x55, 0x20, 0x40, 0x2b, 0x8a, 0x0d, 0xe0, 0x01, 0x2c, 0x70, + 0x55, 0x20, 0x00, 0x29, 0x7e, 0x0d, 0xe0, 0x01, 0x2c, 0x70, 0x42, 0x0e, + 0x2f, 0xf5, 0x56, 0x23, 0x00, 0x3c, 0xc3, 0x41, 0xa0, 0x00, 0x24, 0x9a, + 0xe2, 0x0a, 0x20, 0x01, 0x07, 0xd8, 0x55, 0x23, 0xc0, 0x38, 0x06, 0x0e, + 0x6f, 0xf5, 0x2c, 0x71, 0x55, 0x23, 0x00, 0x3a, 0xfa, 0x0d, 0x6f, 0xf5, + 0x2c, 0x71, 0x42, 0x24, 0x00, 0x2f, 0xf2, 0x0d, 0x6f, 0xf5, 0x2c, 0x70, + 0x54, 0x20, 0x80, 0x2d, 0x42, 0x0d, 0xe0, 0x01, 0x10, 0xd9, 0x54, 0x20, + 0x00, 0x29, 0x3a, 0x0d, 0xe0, 0x01, 0x2c, 0x70, 0x40, 0x20, 0x00, 0x29, + 0x2e, 0x0d, 0xe0, 0x01, 0x2c, 0x70, 0x56, 0x23, 0x01, 0x29, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xee, 0x0a, + 0xa0, 0x01, 0x22, 0x43, 0x55, 0x26, 0x41, 0x2b, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xd6, 0x0a, 0xa0, 0x01, + 0x22, 0x43, 0x54, 0x27, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, + 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xc2, 0x0a, 0xa0, 0x01, 0x22, 0x43, + 0xae, 0x0d, 0x2f, 0xf5, 0x55, 0x20, 0x40, 0x3b, 0xc3, 0x41, 0xa0, 0x00, + 0x44, 0x9d, 0x46, 0x08, 0x2f, 0xf3, 0x10, 0xd8, 0x58, 0x24, 0xc0, 0x2d, + 0x72, 0x0d, 0x6f, 0xf5, 0x2c, 0x70, 0x40, 0x23, 0x00, 0x29, 0xc6, 0x0c, + 0xe0, 0x01, 0x10, 0xd9, 0x86, 0x0d, 0x2f, 0xf5, 0x55, 0x20, 0xc0, 0x3f, + 0xc3, 0x41, 0xa0, 0x00, 0x88, 0xa2, 0xd2, 0x08, 0x20, 0x01, 0x0b, 0xd8, + 0x58, 0x23, 0xc0, 0x2e, 0x4a, 0x0d, 0x6f, 0xf5, 0x2c, 0x70, 0x58, 0x24, + 0x00, 0x2f, 0x42, 0x0d, 0x6f, 0xf5, 0x2c, 0x70, 0x42, 0x23, 0x00, 0x29, + 0x92, 0x0c, 0xe0, 0x01, 0x10, 0xd9, 0x54, 0x23, 0x01, 0x29, 0x40, 0x24, + 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x52, 0x0a, + 0xa0, 0x01, 0xa1, 0x40, 0x54, 0x26, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, + 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x3a, 0x0a, 0xa0, 0x01, + 0xa1, 0x40, 0x2a, 0x0d, 0x2f, 0xf5, 0x55, 0x24, 0x00, 0x2e, 0xc3, 0x41, + 0xa0, 0x00, 0x5c, 0xa7, 0xae, 0x09, 0x2f, 0xf3, 0x0d, 0xd8, 0x57, 0x23, + 0x80, 0x2e, 0xee, 0x0c, 0x6f, 0xf5, 0x2c, 0x70, 0x58, 0x23, 0x00, 0x2b, + 0xe2, 0x0c, 0x6f, 0xf5, 0x2c, 0x70, 0x40, 0x25, 0x00, 0x29, 0x36, 0x0c, + 0xe0, 0x01, 0x10, 0xd9, 0x42, 0x25, 0x00, 0x29, 0x2a, 0x0c, 0xe0, 0x01, + 0x40, 0xd9, 0xee, 0x0c, 0x2f, 0xf5, 0x56, 0x24, 0x40, 0x29, 0xc3, 0x41, + 0xa0, 0x00, 0x1c, 0xaa, 0x72, 0x09, 0x20, 0x01, 0x0e, 0xd8, 0x58, 0x23, + 0xc0, 0x29, 0xb2, 0x0c, 0x6f, 0xf5, 0x2c, 0x70, 0x54, 0x25, 0x00, 0x29, + 0x02, 0x0c, 0xe0, 0x01, 0x2c, 0x70, 0x10, 0xd9, 0xfa, 0x0b, 0xe0, 0x01, + 0xa2, 0x40, 0xbe, 0x0c, 0x2f, 0xf5, 0x56, 0x24, 0x80, 0x2b, 0xc3, 0x41, + 0xa0, 0x00, 0x10, 0x99, 0x0a, 0x0a, 0x2f, 0xf3, 0x29, 0xd8, 0x57, 0x23, + 0x80, 0x29, 0x82, 0x0c, 0x6f, 0xf5, 0x2c, 0x70, 0x10, 0xd9, 0xd6, 0x0b, + 0xe0, 0x01, 0xc2, 0x40, 0xcb, 0x46, 0xa0, 0x00, 0x2e, 0x6f, 0x00, 0x96, + 0x50, 0xd9, 0x04, 0x20, 0x80, 0x0f, 0x00, 0x00, 0x7f, 0xff, 0x00, 0xb6, + 0xba, 0x0b, 0xe0, 0x01, 0x40, 0x26, 0x00, 0x29, 0x0a, 0x96, 0x55, 0x25, + 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x04, 0x20, 0x80, 0x0f, 0x00, 0x00, + 0x7f, 0xff, 0x0a, 0xb6, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0x6a, 0x09, 0xa0, 0x01, 0x22, 0x43, 0x57, 0x20, 0x81, 0x3d, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x56, 0x09, + 0xa0, 0x01, 0x22, 0x43, 0x58, 0x22, 0x41, 0x2b, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x3e, 0x09, 0xa0, 0x01, + 0x22, 0x43, 0x54, 0x25, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x2a, 0x09, 0xa0, 0x01, 0xa1, 0x40, + 0x58, 0x20, 0x01, 0x39, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0x12, 0x09, 0xa0, 0x01, 0xa1, 0x40, 0xc3, 0x40, + 0x13, 0x00, 0xdc, 0x88, 0xfa, 0x0b, 0x0f, 0xf5, 0xc3, 0x41, 0xa0, 0x00, + 0xd4, 0x9c, 0x66, 0x08, 0x2f, 0xf3, 0x12, 0xd8, 0x58, 0x23, 0x80, 0x28, + 0xc2, 0x0b, 0x6f, 0xf5, 0x2c, 0x70, 0x55, 0x25, 0x40, 0x2b, 0x16, 0x0b, + 0xe0, 0x01, 0x10, 0xd9, 0xd6, 0x0b, 0x2f, 0xf5, 0x55, 0x23, 0x00, 0x3f, + 0xc3, 0x41, 0xa0, 0x00, 0xf0, 0x9e, 0x26, 0x08, 0x20, 0x01, 0x0c, 0xd8, + 0x58, 0x23, 0x40, 0x2c, 0x9a, 0x0b, 0x6f, 0xf5, 0x2c, 0x70, 0x58, 0x25, + 0x00, 0x29, 0xee, 0x0a, 0xe0, 0x01, 0x10, 0xd9, 0x58, 0x25, 0x80, 0x2d, + 0xe2, 0x0a, 0xe0, 0x01, 0x40, 0xd9, 0x58, 0x25, 0x40, 0x2b, 0xda, 0x0a, + 0xe0, 0x01, 0x40, 0xd9, 0x59, 0x27, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, + 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x96, 0x08, 0xa0, 0x01, + 0xa1, 0x40, 0x55, 0x26, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x82, 0x08, 0xa0, 0x01, 0xa1, 0x40, + 0x6e, 0x0b, 0x2f, 0xf5, 0x55, 0x21, 0x00, 0x3a, 0xc3, 0x41, 0xa0, 0x00, + 0xe4, 0x9f, 0xea, 0x0e, 0xef, 0xf2, 0x15, 0xd8, 0xc3, 0x41, 0x00, 0x00, + 0xef, 0xff, 0x32, 0x0b, 0x6f, 0xf5, 0x54, 0x21, 0x80, 0x3c, 0xcb, 0x47, + 0x13, 0x00, 0x58, 0x7c, 0x58, 0x27, 0xc0, 0x1f, 0x7a, 0x0a, 0xe0, 0x01, + 0x10, 0xd9, 0x58, 0x27, 0x00, 0x19, 0x72, 0x0a, 0xe0, 0x01, 0x2c, 0x70, + 0x58, 0x27, 0x80, 0x1d, 0x66, 0x0a, 0xe0, 0x01, 0x2c, 0x70, 0x00, 0x16, + 0x00, 0x71, 0xa0, 0x00, 0xde, 0x6e, 0x2c, 0x70, 0xa2, 0xb8, 0x00, 0x1e, + 0x04, 0x70, 0xa0, 0x00, 0xde, 0x6e, 0x4e, 0x0a, 0xe0, 0x01, 0x58, 0x27, + 0x40, 0x1b, 0x00, 0x16, 0x00, 0x71, 0xa0, 0x00, 0xf2, 0x6e, 0x55, 0x27, + 0x01, 0x19, 0x40, 0x24, 0x05, 0x30, 0xa2, 0xb8, 0x00, 0x1e, 0x04, 0x70, + 0xa0, 0x00, 0xf2, 0x6e, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0xf6, 0x0f, 0x60, 0x01, 0x22, 0x43, 0x58, 0x20, 0xc1, 0x3f, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xe2, 0x0f, + 0x60, 0x01, 0x22, 0x43, 0x55, 0x27, 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xca, 0x0f, 0x60, 0x01, + 0x22, 0x43, 0xba, 0x0a, 0x2f, 0xf5, 0x55, 0x24, 0x80, 0x29, 0xc3, 0x41, + 0xa0, 0x00, 0x6c, 0x9c, 0x46, 0x0e, 0xef, 0xf2, 0x17, 0xd8, 0xc3, 0x41, + 0x00, 0x00, 0xef, 0xff, 0x7a, 0x0a, 0x6f, 0xf5, 0x54, 0x21, 0x00, 0x3f, + 0x57, 0x27, 0x00, 0x19, 0xca, 0x09, 0xe0, 0x01, 0x10, 0xd9, 0x57, 0x27, + 0x80, 0x1d, 0xc2, 0x09, 0xe0, 0x01, 0x2c, 0x70, 0x54, 0x27, 0x81, 0x1d, + 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0x7e, 0x0f, 0x60, 0x01, 0x22, 0x43, 0x59, 0x20, 0x01, 0x39, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x6a, 0x0f, + 0x60, 0x01, 0x22, 0x43, 0x55, 0x27, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x52, 0x0f, 0x60, 0x01, + 0x22, 0x43, 0x42, 0x0a, 0x2f, 0xf5, 0x55, 0x21, 0x80, 0x3e, 0xc3, 0x41, + 0xa0, 0x00, 0xb8, 0xa4, 0x3e, 0x0e, 0xe0, 0x00, 0x18, 0xd8, 0xc3, 0x41, + 0x00, 0x00, 0xef, 0xff, 0x02, 0x0a, 0x6f, 0xf5, 0x55, 0x21, 0xc0, 0x38, + 0x4c, 0x4f, 0x56, 0x09, 0xe0, 0x01, 0x10, 0xd9, 0x42, 0x27, 0x00, 0x19, + 0x4a, 0x09, 0xe0, 0x01, 0x2c, 0x70, 0x2c, 0x70, 0x42, 0x09, 0xe0, 0x01, + 0xe1, 0x40, 0x00, 0x16, 0x00, 0x71, 0xa0, 0x00, 0x06, 0x6f, 0x2c, 0x70, + 0xa2, 0xb8, 0x00, 0x1e, 0x04, 0x70, 0xa0, 0x00, 0x06, 0x6f, 0x2a, 0x09, + 0xe0, 0x01, 0x54, 0x27, 0x00, 0x19, 0x58, 0x20, 0x81, 0x2d, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xe6, 0x0e, + 0x60, 0x01, 0x22, 0x43, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, + 0x01, 0x08, 0xa1, 0x40, 0x03, 0x41, 0xd2, 0x0e, 0x60, 0x01, 0x22, 0x43, + 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0x42, 0x41, 0xbe, 0x0e, 0x60, 0x01, 0x22, 0x43, 0xaa, 0x09, 0x2f, 0xf5, + 0x56, 0x21, 0x80, 0x39, 0xc3, 0x41, 0xa0, 0x00, 0x78, 0x98, 0xca, 0x0d, + 0xe0, 0x00, 0x2a, 0xd8, 0xc3, 0x41, 0x00, 0x00, 0xef, 0xff, 0x6e, 0x09, + 0x6f, 0xf5, 0x40, 0x23, 0x00, 0x3a, 0xc3, 0x41, 0x00, 0x00, 0xef, 0xff, + 0x5e, 0x09, 0x6f, 0xf5, 0x40, 0x23, 0x00, 0x3f, 0xc3, 0x41, 0x00, 0x00, + 0xef, 0xff, 0x52, 0x09, 0x6f, 0xf5, 0x54, 0x23, 0x00, 0x3a, 0x55, 0x27, + 0xc0, 0x1f, 0xa2, 0x08, 0xe0, 0x01, 0x2c, 0x70, 0x00, 0x16, 0x00, 0x71, + 0xa0, 0x00, 0x1a, 0x6f, 0x10, 0xd9, 0x04, 0x20, 0x80, 0x0f, 0x00, 0x00, + 0x7f, 0xff, 0x00, 0x1e, 0x04, 0x70, 0xa0, 0x00, 0x1a, 0x6f, 0x82, 0x08, + 0xe0, 0x01, 0x56, 0x27, 0x00, 0x19, 0x59, 0x25, 0x00, 0x29, 0x76, 0x08, + 0xe0, 0x01, 0x10, 0xd9, 0x58, 0x25, 0xc0, 0x2f, 0x6a, 0x08, 0xe0, 0x01, + 0x4a, 0x21, 0x00, 0x04, 0x4a, 0x24, 0xc0, 0x70, 0x58, 0x23, 0x82, 0x2f, + 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x12, 0x00, 0x04, 0x08, 0x80, 0x21, 0x90, + 0x04, 0x21, 0x81, 0x0f, 0x00, 0x00, 0x7f, 0xff, 0x21, 0xb0, 0xcd, 0x70, + 0x8f, 0xbe, 0x56, 0x25, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, + 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x06, 0x0e, 0x60, 0x01, 0xc1, 0x43, + 0x58, 0x20, 0x81, 0x3d, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, + 0x01, 0x08, 0xa1, 0x40, 0xee, 0x0d, 0x60, 0x01, 0xc1, 0x43, 0x59, 0x22, + 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, + 0xa1, 0x40, 0xda, 0x0d, 0x60, 0x01, 0xc1, 0x43, 0x59, 0x20, 0x01, 0x29, + 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, + 0xc2, 0x0d, 0x60, 0x01, 0xc1, 0x43, 0x58, 0x20, 0x41, 0x3b, 0x40, 0x24, + 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0xae, 0x0d, + 0x60, 0x01, 0xc1, 0x43, 0x58, 0x22, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, + 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x96, 0x0d, 0x60, 0x01, + 0xc1, 0x43, 0x58, 0x20, 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, + 0x8a, 0x24, 0x01, 0x08, 0xa1, 0x40, 0x82, 0x0d, 0x60, 0x01, 0xc1, 0x43, + 0x42, 0x20, 0x01, 0x39, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, + 0x01, 0x08, 0xa1, 0x40, 0x6a, 0x0d, 0x60, 0x01, 0xc1, 0x43, 0x57, 0x22, + 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x40, 0xda, 0x8a, 0x24, 0x01, 0x08, + 0xa1, 0x40, 0x56, 0x0d, 0x60, 0x01, 0xc1, 0x43, 0xc3, 0x40, 0x13, 0x00, + 0xfc, 0x89, 0x3e, 0x08, 0x0f, 0xf5, 0xc3, 0x41, 0xa0, 0x00, 0x48, 0x9e, + 0x2a, 0x0d, 0xe0, 0x00, 0x1f, 0xd8, 0x55, 0x23, 0x80, 0x3c, 0x06, 0x08, + 0x6f, 0xf5, 0x2c, 0x70, 0x57, 0x23, 0x00, 0x2c, 0xfa, 0x0f, 0x2f, 0xf5, + 0x2c, 0x70, 0x42, 0x23, 0x00, 0x2e, 0xf2, 0x0f, 0x2f, 0xf5, 0x2c, 0x70, + 0x58, 0x23, 0x80, 0x2d, 0xe6, 0x0f, 0x2f, 0xf5, 0x2c, 0x70, 0x58, 0x26, + 0x80, 0x2d, 0x3a, 0x0f, 0xa0, 0x01, 0x10, 0xd9, 0x58, 0x26, 0x41, 0x2b, + 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, + 0xf6, 0x0c, 0x60, 0x01, 0xa1, 0x40, 0x54, 0x20, 0x01, 0x39, 0x40, 0x24, + 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0xe2, 0x0c, + 0x60, 0x01, 0xa1, 0x40, 0x55, 0x22, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, + 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0xca, 0x0c, 0x60, 0x01, + 0xa1, 0x40, 0x58, 0x20, 0x41, 0x2b, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0xb6, 0x0c, 0x60, 0x01, 0xa1, 0x40, + 0x40, 0x20, 0x01, 0x39, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0x9e, 0x0c, 0x60, 0x01, 0xa1, 0x40, 0x54, 0x22, + 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, + 0x01, 0x08, 0x8a, 0x0c, 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, 0x13, 0x00, + 0x6c, 0x89, 0x72, 0x0f, 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, 0x9c, 0x99, + 0x56, 0x0c, 0xef, 0xf2, 0x20, 0xd8, 0x2c, 0x70, 0x3a, 0x0f, 0x2f, 0xf5, + 0x82, 0x40, 0x55, 0x20, 0xc0, 0x2f, 0x8e, 0x0e, 0xa0, 0x01, 0x10, 0xd9, + 0x56, 0x20, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0x4a, 0x0c, 0x60, 0x01, 0xa1, 0x40, 0x40, 0x22, + 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, + 0x01, 0x08, 0x36, 0x0c, 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, 0x13, 0x00, + 0x8c, 0x8a, 0x1e, 0x0f, 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, 0xb8, 0x9b, + 0x46, 0x0c, 0xef, 0xf2, 0x21, 0xd8, 0x55, 0x23, 0xc0, 0x3d, 0xe6, 0x0e, + 0x2f, 0xf5, 0x2c, 0x70, 0x57, 0x26, 0x00, 0x29, 0x36, 0x0e, 0xa0, 0x01, + 0x10, 0xd9, 0x42, 0x26, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0xf6, 0x0b, 0x60, 0x01, 0xa1, 0x40, + 0x55, 0x22, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0xde, 0x0b, 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, + 0x13, 0x00, 0xd4, 0x8a, 0xc6, 0x0e, 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, + 0xbc, 0x9d, 0xd2, 0x0b, 0xe0, 0x00, 0x3c, 0xd8, 0x40, 0x24, 0x00, 0x2f, + 0x8e, 0x0e, 0x2f, 0xf5, 0x2c, 0x70, 0x54, 0x20, 0x80, 0x3d, 0xe2, 0x0d, + 0xa0, 0x01, 0x10, 0xd9, 0x55, 0x20, 0x01, 0x39, 0x40, 0x24, 0x05, 0x30, + 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x9e, 0x0b, 0x60, 0x01, + 0xa1, 0x40, 0x55, 0x22, 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x8a, 0x0b, 0x60, 0x01, 0xa1, 0x40, + 0x76, 0x0e, 0xef, 0xf4, 0x54, 0x24, 0x00, 0x2a, 0xc3, 0x41, 0xa0, 0x00, + 0x14, 0xa1, 0x42, 0x09, 0xef, 0xf2, 0x22, 0xd8, 0x58, 0x24, 0x80, 0x2c, + 0x3a, 0x0e, 0x2f, 0xf5, 0x2c, 0x70, 0x55, 0x23, 0x40, 0x2b, 0x8e, 0x0d, + 0xa0, 0x01, 0x10, 0xd9, 0x55, 0x23, 0xc0, 0x2f, 0x82, 0x0d, 0xa0, 0x01, + 0x2c, 0x70, 0x55, 0x23, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x42, 0x0b, 0x60, 0x01, 0xa1, 0x40, + 0x40, 0x27, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0x2a, 0x0b, 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, + 0x13, 0x00, 0x44, 0x8a, 0x12, 0x0e, 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, + 0x10, 0x9c, 0x26, 0x0b, 0xef, 0xf2, 0x2b, 0xd8, 0x40, 0x24, 0x00, 0x2a, + 0xda, 0x0d, 0x2f, 0xf5, 0x2c, 0x70, 0x58, 0x26, 0x00, 0x29, 0x2e, 0x0d, + 0xa0, 0x01, 0x10, 0xd9, 0x57, 0x26, 0x81, 0x2d, 0x40, 0x24, 0x05, 0x30, + 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0xea, 0x0a, 0x60, 0x01, + 0xa1, 0x40, 0x55, 0x22, 0x41, 0x2b, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0xd6, 0x0a, 0x60, 0x01, 0xa1, 0x40, + 0xc3, 0x40, 0x13, 0x00, 0x4c, 0x88, 0xbe, 0x0d, 0xcf, 0xf4, 0xc3, 0x41, + 0xa0, 0x00, 0x90, 0x98, 0x86, 0x09, 0xef, 0xf2, 0x2c, 0xd8, 0x58, 0x24, + 0xc0, 0x28, 0x86, 0x0d, 0x2f, 0xf5, 0x2c, 0x70, 0x55, 0x27, 0x40, 0x1b, + 0xd6, 0x0c, 0xa0, 0x01, 0x10, 0xd9, 0x55, 0x27, 0x81, 0x1d, 0x40, 0x24, + 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x96, 0x0a, + 0x60, 0x01, 0xa1, 0x40, 0x56, 0x27, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, + 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x7e, 0x0a, 0x60, 0x01, + 0xa1, 0x40, 0xc3, 0x40, 0x13, 0x00, 0x24, 0x89, 0x66, 0x0d, 0xcf, 0xf4, + 0xc3, 0x41, 0xa0, 0x00, 0xac, 0x98, 0x22, 0x0a, 0xef, 0xf2, 0x2d, 0xd8, + 0x57, 0x24, 0x80, 0x2c, 0x2e, 0x0d, 0x2f, 0xf5, 0x2c, 0x70, 0x58, 0x20, + 0x00, 0x29, 0x82, 0x0c, 0xa0, 0x01, 0x10, 0xd9, 0x57, 0x20, 0x81, 0x2d, + 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, + 0x3e, 0x0a, 0x60, 0x01, 0xa1, 0x40, 0x42, 0x22, 0x01, 0x29, 0x40, 0x24, + 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x2a, 0x0a, + 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, 0x13, 0x00, 0xb4, 0x89, 0x12, 0x0d, + 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, 0xcc, 0x98, 0xd2, 0x09, 0xe0, 0x00, + 0x3d, 0xd8, 0x40, 0x24, 0x00, 0x25, 0xda, 0x0c, 0x2f, 0xf5, 0x2c, 0x70, + 0x59, 0x26, 0x00, 0x29, 0x2a, 0x0c, 0xa0, 0x01, 0x10, 0xd9, 0x58, 0x26, + 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, + 0x01, 0x08, 0xea, 0x09, 0x60, 0x01, 0xa1, 0x40, 0x54, 0x22, 0x01, 0x29, + 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, + 0xd2, 0x09, 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, 0x13, 0x00, 0x94, 0x88, + 0xba, 0x0c, 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, 0x34, 0x99, 0x2a, 0x09, + 0xe0, 0x00, 0x40, 0xd8, 0x57, 0x24, 0x00, 0x2f, 0x82, 0x0c, 0x2f, 0xf5, + 0x2c, 0x70, 0x57, 0x25, 0x80, 0x2d, 0xd6, 0x0b, 0xa0, 0x01, 0x10, 0xd9, + 0x57, 0x25, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0x92, 0x09, 0x60, 0x01, 0xa1, 0x40, 0x58, 0x22, + 0xc1, 0x2f, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, + 0x01, 0x08, 0x7e, 0x09, 0x60, 0x01, 0xa1, 0x40, 0xc3, 0x40, 0x13, 0x00, + 0x04, 0x88, 0x66, 0x0c, 0xcf, 0xf4, 0xc3, 0x41, 0xa0, 0x00, 0xec, 0x98, + 0x4a, 0x08, 0xe0, 0x00, 0x41, 0xd8, 0x40, 0x23, 0x00, 0x35, 0x2e, 0x0c, + 0x2f, 0xf5, 0x2c, 0x70, 0x56, 0x22, 0x00, 0x29, 0x7e, 0x0b, 0xa0, 0x01, + 0x10, 0xd9, 0x59, 0x27, 0x01, 0x19, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, + 0x6c, 0x70, 0x8a, 0x24, 0x01, 0x08, 0x3e, 0x09, 0x60, 0x01, 0xa1, 0x40, + 0x56, 0x26, 0x01, 0x29, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, + 0x8a, 0x24, 0x01, 0x08, 0x26, 0x09, 0x60, 0x01, 0xa1, 0x40, 0x55, 0x27, + 0x41, 0x2b, 0x40, 0x24, 0x05, 0x30, 0x4c, 0x70, 0x6c, 0x70, 0x8a, 0x24, + 0x01, 0x08, 0x12, 0x09, 0x60, 0x01, 0xa1, 0x40, 0x86, 0x09, 0xaf, 0xf5, + 0xa1, 0x40, 0x87, 0x74, 0x04, 0x14, 0x1b, 0x34, 0xda, 0xc6, 0xe0, 0x78, + 0xe4, 0xc2, 0x08, 0x46, 0x03, 0x80, 0x00, 0x80, 0x48, 0x80, 0x04, 0x82, + 0x61, 0x92, 0x23, 0x82, 0xa0, 0x80, 0x11, 0x86, 0x82, 0xbb, 0x22, 0x0d, + 0xaf, 0xfb, 0x61, 0xb2, 0x19, 0x08, 0xfe, 0x01, 0x00, 0x42, 0x24, 0x86, + 0xc6, 0xba, 0x00, 0x81, 0x64, 0x80, 0x22, 0x83, 0x40, 0xa9, 0x23, 0x80, + 0x60, 0x79, 0xa1, 0xa3, 0xc4, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, + 0x56, 0x0f, 0xaf, 0xfb, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x11, 0x80, 0xd5, 0x07, 0xaf, 0xfb, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, + 0xf2, 0x0f, 0xaf, 0xfb, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x21, 0x01, 0xef, 0xfb, 0x11, 0x80, 0xe0, 0x78, 0x11, 0x04, 0xaf, 0xfb, + 0x11, 0x80, 0xe0, 0x78, 0x91, 0x01, 0xef, 0xfb, 0x11, 0x80, 0xe0, 0x78, + 0x71, 0x02, 0xef, 0xfb, 0x11, 0x80, 0xe0, 0x78, 0xec, 0xc3, 0x83, 0x80, + 0x08, 0x47, 0x00, 0x84, 0xa8, 0x80, 0x02, 0x15, 0x09, 0x11, 0x4f, 0x21, + 0x80, 0x10, 0x01, 0xb5, 0x01, 0x84, 0xc8, 0x80, 0x02, 0x16, 0x08, 0x11, + 0x4f, 0x20, 0x80, 0x10, 0x01, 0xb6, 0x02, 0x84, 0x44, 0x85, 0x63, 0x86, + 0x23, 0x85, 0x08, 0x80, 0x00, 0x12, 0x11, 0x00, 0x0c, 0x10, 0x0b, 0x00, + 0x0f, 0x0b, 0x30, 0x10, 0xa8, 0xc1, 0x41, 0x90, 0x82, 0xba, 0x41, 0xb0, + 0x05, 0xf0, 0x40, 0x24, 0x0b, 0x33, 0x0c, 0x1c, 0x01, 0x30, 0x03, 0x84, + 0x41, 0x28, 0x88, 0x10, 0x08, 0x80, 0x43, 0x80, 0x40, 0x45, 0x06, 0xea, + 0x41, 0x90, 0x82, 0xba, 0x41, 0xb0, 0x06, 0xf0, 0x40, 0x24, 0x05, 0x32, + 0x08, 0x1c, 0x01, 0x30, 0x50, 0x87, 0x80, 0x95, 0xa0, 0x96, 0x01, 0x92, + 0x17, 0x08, 0x3e, 0x00, 0x44, 0x20, 0x44, 0x10, 0x44, 0x21, 0x08, 0x11, + 0x05, 0x24, 0x3e, 0x82, 0x2a, 0xf4, 0xa0, 0xb8, 0x01, 0xb2, 0x48, 0x34, + 0x02, 0x10, 0x48, 0x35, 0x00, 0x10, 0x07, 0x30, 0x86, 0x00, 0x04, 0x87, + 0x49, 0x8f, 0x80, 0x80, 0x91, 0x40, 0x13, 0x0a, 0xb4, 0x00, 0x10, 0x14, + 0x12, 0x10, 0xa1, 0x80, 0xc4, 0x85, 0x82, 0x86, 0x02, 0xf0, 0x84, 0xc4, + 0x08, 0x12, 0x07, 0x20, 0x65, 0x42, 0x11, 0x87, 0xd2, 0x09, 0xef, 0xfb, + 0x40, 0xc4, 0x04, 0x1a, 0x40, 0x24, 0x1e, 0x41, 0x60, 0x79, 0x02, 0x40, + 0x09, 0x8f, 0x11, 0x08, 0xb4, 0x00, 0xa1, 0x40, 0x04, 0x1e, 0x40, 0x14, + 0x23, 0x85, 0x40, 0x79, 0xcc, 0xc7, 0xe0, 0x78, 0xe8, 0xc2, 0x63, 0x80, + 0x00, 0x41, 0x00, 0x83, 0x61, 0x83, 0x48, 0x80, 0x68, 0x83, 0x10, 0x81, + 0xe1, 0x92, 0x4f, 0x27, 0x8c, 0x10, 0x81, 0xb2, 0x84, 0x82, 0xa1, 0x93, + 0xc1, 0x90, 0x00, 0x12, 0x08, 0x01, 0x00, 0x13, 0x09, 0x01, 0x0c, 0x13, + 0x07, 0x00, 0x43, 0x82, 0x00, 0x14, 0x10, 0x10, 0x4f, 0x25, 0x8b, 0x10, + 0x22, 0xbd, 0x02, 0x1b, 0xc4, 0x02, 0x1b, 0x0e, 0x3e, 0x10, 0x44, 0x25, + 0x43, 0x10, 0x44, 0x27, 0x0c, 0x11, 0x05, 0x23, 0x3e, 0x83, 0x03, 0xf2, + 0xc8, 0xc6, 0xa0, 0xbe, 0xc1, 0xb0, 0x84, 0x81, 0x48, 0x30, 0x0b, 0x10, + 0x48, 0x31, 0x00, 0x10, 0x0a, 0x24, 0x00, 0x04, 0xa0, 0x84, 0x07, 0x30, + 0xc5, 0x02, 0x11, 0x81, 0xe0, 0x41, 0xc4, 0x85, 0x4a, 0x0b, 0xef, 0xfb, + 0x08, 0x16, 0x06, 0x10, 0x23, 0x85, 0xa1, 0x40, 0x60, 0x79, 0x04, 0x1e, + 0x00, 0x14, 0xc8, 0xc6, 0xe6, 0xc3, 0xa6, 0xc1, 0x83, 0x80, 0x00, 0x41, + 0xec, 0x70, 0x00, 0x84, 0x62, 0x84, 0xe8, 0x80, 0x01, 0x84, 0x02, 0x17, + 0x05, 0x11, 0x08, 0x80, 0x4f, 0x25, 0x82, 0x00, 0x41, 0xb7, 0xa1, 0x90, + 0x68, 0x83, 0x4f, 0x25, 0x82, 0x10, 0x41, 0xb0, 0x41, 0x93, 0x83, 0x84, + 0x41, 0x2d, 0x84, 0x10, 0x4f, 0x22, 0x8d, 0x00, 0xa1, 0xb3, 0x88, 0x84, + 0xc4, 0x87, 0x0c, 0x17, 0x08, 0x10, 0x0c, 0x10, 0x09, 0x00, 0xa1, 0x94, + 0x0c, 0x13, 0x0b, 0x00, 0xc0, 0x86, 0x19, 0x0d, 0xbf, 0x10, 0x41, 0x2a, + 0x86, 0x00, 0x43, 0x84, 0x82, 0xbd, 0xa1, 0xb4, 0x00, 0x12, 0x87, 0x00, + 0x85, 0x27, 0x3e, 0x00, 0x90, 0x81, 0x40, 0x93, 0xa0, 0x97, 0x00, 0x90, + 0x61, 0x94, 0x44, 0x24, 0x44, 0x00, 0x1f, 0x0b, 0x3e, 0x00, 0x44, 0x26, + 0x46, 0x00, 0x44, 0x25, 0x05, 0x01, 0x05, 0x25, 0x05, 0x01, 0x05, 0x25, + 0xbe, 0x81, 0x03, 0xf2, 0xc6, 0xc7, 0xa0, 0xbb, 0x61, 0xb4, 0x48, 0x35, + 0x0c, 0x10, 0x48, 0x32, 0x03, 0x00, 0x2f, 0x27, 0xc7, 0x01, 0x48, 0x30, + 0x02, 0x00, 0x04, 0x81, 0x07, 0x33, 0x03, 0x03, 0x07, 0x32, 0x02, 0x03, + 0xc1, 0x45, 0xa0, 0x80, 0x11, 0x81, 0xe4, 0x85, 0x22, 0x87, 0x42, 0xc1, + 0x41, 0xc3, 0x40, 0xc2, 0x21, 0x41, 0x01, 0x42, 0x4a, 0x0d, 0xef, 0xfb, + 0x61, 0x43, 0x23, 0x85, 0xa1, 0x40, 0x60, 0x79, 0xc1, 0xa7, 0xc6, 0xc7, + 0xe2, 0xc2, 0x11, 0x80, 0x92, 0x0e, 0xef, 0xfb, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0xad, 0x07, 0xef, 0xfb, 0x2f, 0x79, + 0xe2, 0xc2, 0x11, 0x80, 0x9a, 0x08, 0x2f, 0xfc, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x2d, 0x07, 0x2f, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0x91, 0x04, 0xef, 0xfb, 0x11, 0x80, 0xe0, 0x78, 0x21, 0x00, 0x6f, 0xfc, + 0x11, 0x80, 0xe0, 0x78, 0xe5, 0x00, 0x6f, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0xec, 0xc2, 0xa0, 0x80, 0x68, 0x46, 0x50, 0x41, 0x8a, 0x85, 0xeb, 0x85, + 0x0c, 0x84, 0x17, 0x08, 0x71, 0x00, 0x30, 0x40, 0xe1, 0x40, 0x80, 0x20, + 0x0e, 0x00, 0x30, 0x1c, 0x01, 0x10, 0x00, 0x18, 0x03, 0x00, 0x44, 0x20, + 0x52, 0xa0, 0x0b, 0xf2, 0x80, 0x27, 0x0e, 0x10, 0x00, 0x8f, 0x0f, 0x08, + 0xa5, 0x03, 0xa1, 0x40, 0xd2, 0x08, 0x40, 0x01, 0xc0, 0xaf, 0x78, 0x22, + 0x01, 0x20, 0x85, 0xee, 0x0c, 0x77, 0x83, 0xe9, 0xcc, 0xc6, 0x78, 0x26, + 0x00, 0x10, 0x05, 0x20, 0x7e, 0x80, 0x32, 0xf4, 0x0a, 0x24, 0x80, 0x73, + 0x40, 0x21, 0x0b, 0x24, 0xed, 0x70, 0x2c, 0x70, 0x4c, 0x70, 0x6c, 0x70, + 0x0a, 0x20, 0x40, 0x04, 0xa8, 0x20, 0x80, 0x04, 0x18, 0x13, 0x0c, 0x15, + 0x95, 0x71, 0xca, 0x23, 0x01, 0x00, 0x0b, 0xf2, 0x95, 0x75, 0xca, 0x21, + 0x01, 0x00, 0x07, 0xf2, 0x09, 0x0c, 0xd1, 0x10, 0x00, 0x42, 0x03, 0xf0, + 0xe1, 0x80, 0x18, 0xe0, 0x03, 0xea, 0xe1, 0x82, 0x06, 0xf0, 0x04, 0xeb, + 0xe1, 0x83, 0x04, 0xf0, 0x02, 0xe9, 0xe1, 0x81, 0xd5, 0x71, 0xc1, 0x40, + 0xca, 0x20, 0x6e, 0x00, 0x0a, 0x24, 0x00, 0x70, 0x40, 0x21, 0x01, 0x21, + 0xa8, 0x20, 0x00, 0x01, 0x18, 0x19, 0xd0, 0x03, 0xa1, 0x40, 0x02, 0x41, + 0x22, 0x42, 0x02, 0x0c, 0x2f, 0xf5, 0xc1, 0x43, 0xcc, 0xc6, 0xe0, 0x78, + 0x3e, 0x78, 0xe0, 0x7e, 0x48, 0x88, 0x00, 0x19, 0x05, 0x00, 0x42, 0x22, + 0x3c, 0x80, 0xe0, 0x7c, 0x83, 0x80, 0x6c, 0x70, 0xa8, 0x20, 0x00, 0x03, + 0x04, 0x14, 0x00, 0x14, 0x08, 0x80, 0x42, 0x88, 0x0b, 0x0a, 0x9f, 0x01, + 0x05, 0x90, 0x05, 0x7b, 0x60, 0xb1, 0xe0, 0x78, 0xe0, 0x7e, 0xe0, 0x78, + 0x52, 0xd9, 0x03, 0x18, 0x43, 0x00, 0x01, 0x18, 0x03, 0x00, 0x00, 0x18, + 0x03, 0x01, 0xe0, 0x7f, 0x22, 0xa8, 0xe0, 0x78, 0xfa, 0xc2, 0xfc, 0x1c, + 0xc8, 0xb6, 0xbb, 0xc1, 0xc3, 0x80, 0x08, 0x47, 0x44, 0x17, 0x19, 0x10, + 0xd1, 0x40, 0x00, 0x86, 0x88, 0xc5, 0x28, 0x80, 0x01, 0x91, 0x44, 0x81, + 0x82, 0xb8, 0x01, 0xb1, 0x00, 0x82, 0x0c, 0x11, 0x1b, 0x00, 0x2c, 0x70, + 0x47, 0xc0, 0x88, 0xc0, 0x6e, 0x0e, 0xef, 0xf5, 0x14, 0xda, 0x4a, 0x24, + 0xc0, 0x70, 0x84, 0xc0, 0xa8, 0x20, 0x40, 0x01, 0x08, 0x43, 0xa0, 0xa0, + 0x04, 0x74, 0x08, 0x17, 0x89, 0x10, 0x04, 0xc2, 0x05, 0xc3, 0xcc, 0x71, + 0xec, 0x70, 0x40, 0x24, 0x04, 0x38, 0xc8, 0x40, 0x4d, 0x08, 0x45, 0x12, + 0x04, 0x10, 0x0c, 0x22, 0x08, 0x84, 0x20, 0x90, 0x3d, 0x09, 0x85, 0x0f, + 0x00, 0x00, 0xf0, 0xff, 0x21, 0x90, 0x35, 0x09, 0x9f, 0x00, 0x8c, 0x94, + 0x8c, 0x24, 0x05, 0x95, 0x0a, 0xf2, 0x8c, 0x24, 0x85, 0x96, 0x0c, 0xf2, + 0x8c, 0x24, 0x05, 0x96, 0x0d, 0xf4, 0x84, 0x80, 0x43, 0x80, 0x08, 0xf0, + 0x84, 0x80, 0x0c, 0x10, 0x04, 0x00, 0x04, 0xf0, 0x84, 0x80, 0x63, 0x80, + 0x82, 0xb9, 0x21, 0xb0, 0xc0, 0x84, 0xe4, 0x71, 0x05, 0x71, 0xdc, 0xf1, + 0x30, 0x87, 0x81, 0x91, 0x00, 0x1b, 0x00, 0x11, 0x44, 0xc2, 0x29, 0x0c, + 0x3e, 0x10, 0x45, 0xc3, 0x04, 0x11, 0x80, 0x30, 0x11, 0x08, 0x34, 0x04, + 0x41, 0x28, 0x0b, 0x01, 0xc3, 0xb8, 0x09, 0x08, 0xc0, 0x02, 0xcc, 0x72, + 0x2f, 0x20, 0xc7, 0x01, 0x93, 0x08, 0xa4, 0x01, 0xa0, 0xbc, 0x81, 0xb1, + 0x04, 0x87, 0x29, 0x8f, 0x82, 0x80, 0x04, 0x10, 0x14, 0x00, 0x00, 0x10, + 0x16, 0x00, 0x91, 0x43, 0x10, 0x14, 0x18, 0x10, 0x10, 0x14, 0x15, 0x20, + 0x1d, 0x09, 0x34, 0x01, 0x10, 0x16, 0x17, 0x20, 0x84, 0x80, 0xa3, 0x80, + 0x91, 0x40, 0x10, 0x14, 0x12, 0x10, 0x10, 0x15, 0x11, 0x10, 0x56, 0x40, + 0x36, 0x41, 0x04, 0xf0, 0x8d, 0xc0, 0x92, 0xc1, 0x08, 0x10, 0x07, 0x30, + 0x08, 0x15, 0x06, 0x20, 0x08, 0x17, 0x05, 0x20, 0x41, 0xc0, 0x40, 0xc1, + 0x23, 0x40, 0x9a, 0x0b, 0x6f, 0xfc, 0x63, 0x41, 0x04, 0x1f, 0x80, 0x23, + 0xde, 0x41, 0x60, 0x79, 0xc2, 0x40, 0x07, 0xc0, 0x04, 0x1d, 0x00, 0x20, + 0x9e, 0x41, 0x60, 0x79, 0x82, 0x40, 0x04, 0x18, 0x80, 0x33, 0x7e, 0x41, + 0x60, 0x79, 0x62, 0x40, 0x09, 0x8f, 0x1b, 0x08, 0x34, 0x01, 0xa1, 0x40, + 0x04, 0x19, 0x80, 0x23, 0x23, 0x85, 0x40, 0x79, 0x04, 0x1a, 0x80, 0x23, + 0x1e, 0x41, 0x60, 0x79, 0x02, 0x40, 0xbb, 0xc0, 0x04, 0x14, 0x1b, 0x34, + 0xda, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, 0x86, 0x0c, 0x6f, 0xfc, + 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0xfd, 0x04, + 0x6f, 0xfc, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, 0x66, 0x0d, 0x6f, 0xfc, + 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0xe6, 0xc0, 0xc3, 0x80, + 0x71, 0x80, 0x08, 0x10, 0x8b, 0x00, 0xad, 0x71, 0x40, 0x86, 0xe4, 0x8b, + 0x48, 0x82, 0x41, 0x2f, 0x08, 0x11, 0x85, 0x92, 0x80, 0xb1, 0x3f, 0x0d, + 0xc5, 0x12, 0x04, 0x16, 0x03, 0x12, 0x4c, 0x93, 0x8c, 0x22, 0x05, 0x85, + 0x0a, 0xf2, 0x8c, 0x22, 0x05, 0x86, 0x0c, 0x71, 0x09, 0xf2, 0x8c, 0x22, + 0x85, 0x86, 0x06, 0xf4, 0x0c, 0x72, 0x05, 0xf0, 0x0c, 0x74, 0x03, 0xf0, + 0x0c, 0x70, 0xeb, 0x78, 0xcb, 0x20, 0x01, 0x82, 0x05, 0xf2, 0x08, 0x83, + 0x05, 0x90, 0x05, 0x7c, 0x80, 0xb1, 0xa5, 0x71, 0xe3, 0xf1, 0xc6, 0xc4, + 0x25, 0x05, 0x6f, 0xfc, 0x11, 0x80, 0xe0, 0x78, 0x0d, 0x02, 0x6f, 0xfc, + 0x11, 0x80, 0xe0, 0x78, 0x3d, 0x05, 0x6f, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0xee, 0xc2, 0x08, 0x45, 0x03, 0x80, 0x91, 0x85, 0x28, 0x47, 0x00, 0x80, + 0x54, 0x8c, 0x04, 0x14, 0x93, 0x10, 0x91, 0x41, 0x68, 0x80, 0x21, 0x93, + 0xa4, 0xb9, 0x83, 0x0a, 0x30, 0x00, 0x21, 0xb3, 0x09, 0x15, 0x89, 0x10, + 0x2c, 0x70, 0x8d, 0x70, 0x20, 0x46, 0x5f, 0x09, 0x65, 0x02, 0x6d, 0x70, + 0x44, 0x85, 0x26, 0x4a, 0x4c, 0x70, 0x02, 0x16, 0x88, 0x10, 0x11, 0x72, + 0x0a, 0x24, 0x80, 0x01, 0x81, 0x47, 0xc0, 0x21, 0x66, 0x00, 0xe8, 0x44, + 0x0a, 0x26, 0x00, 0x01, 0x6f, 0xf7, 0x82, 0x86, 0x0a, 0x26, 0x00, 0x01, + 0x30, 0x24, 0xcc, 0x12, 0x88, 0x84, 0x80, 0x94, 0xd3, 0x74, 0x00, 0x00, + 0xff, 0xff, 0xe8, 0x44, 0xca, 0x26, 0x22, 0x00, 0xca, 0x24, 0x62, 0x10, + 0x0a, 0xf2, 0x15, 0x09, 0x50, 0x00, 0xe8, 0x44, 0x0d, 0x0f, 0x31, 0x00, + 0x0a, 0x26, 0x00, 0x01, 0xcc, 0x71, 0x8d, 0x70, 0x65, 0x74, 0x44, 0x71, + 0xdb, 0xf1, 0x1b, 0x0e, 0x30, 0x00, 0x40, 0xda, 0xc4, 0x93, 0xc1, 0x41, + 0xd2, 0x08, 0xef, 0xf5, 0xc3, 0xb3, 0xc0, 0xb7, 0x0b, 0xf0, 0x30, 0x85, + 0x03, 0xf0, 0x30, 0x85, 0x43, 0xb3, 0xc2, 0x08, 0xef, 0xf5, 0x20, 0x91, + 0x10, 0x85, 0x00, 0x90, 0x00, 0xb7, 0x41, 0x2b, 0x10, 0x21, 0xcd, 0x71, + 0x08, 0x8d, 0x79, 0x0e, 0x05, 0x10, 0x03, 0x85, 0xc0, 0x48, 0x48, 0x80, + 0x8c, 0x90, 0x61, 0x92, 0x8c, 0x24, 0x05, 0x95, 0x50, 0x23, 0x01, 0x01, + 0x21, 0xb2, 0x0b, 0xf2, 0x8c, 0x24, 0x05, 0x96, 0x2c, 0x71, 0x0a, 0xf2, + 0x8c, 0x24, 0x85, 0x96, 0x05, 0xf4, 0x2c, 0x72, 0x04, 0xf0, 0x2c, 0x74, + 0x02, 0xf0, 0x2c, 0x70, 0x0b, 0x21, 0xc0, 0x84, 0x14, 0x27, 0x92, 0x13, + 0x06, 0xf2, 0x30, 0x85, 0x84, 0xbb, 0x20, 0x91, 0x61, 0xb2, 0x0a, 0xf0, + 0x0b, 0x21, 0x00, 0x84, 0x04, 0xf4, 0x15, 0x11, 0x81, 0x20, 0x0c, 0xe9, + 0x30, 0x85, 0x20, 0x91, 0x56, 0x08, 0xcf, 0xf5, 0x10, 0x85, 0x00, 0x90, + 0x00, 0x1a, 0x04, 0x20, 0xc5, 0x71, 0xce, 0xf1, 0xc3, 0x41, 0x00, 0x00, + 0xff, 0xff, 0x42, 0x08, 0xcf, 0xf5, 0x00, 0x1a, 0xc5, 0x2f, 0xf8, 0xf1, + 0xce, 0xc6, 0xe0, 0x78, 0x31, 0x04, 0x6f, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0xee, 0xc3, 0xa8, 0xc1, 0x08, 0x47, 0x01, 0x80, 0x23, 0x87, 0x0e, 0x70, + 0xcd, 0x70, 0x07, 0x80, 0xa0, 0x81, 0x0b, 0x20, 0x80, 0x8f, 0x20, 0x00, + 0x01, 0x00, 0x03, 0xf2, 0xc1, 0x81, 0x19, 0x08, 0x9e, 0x00, 0x04, 0x20, + 0x80, 0x0f, 0x22, 0x00, 0x00, 0x00, 0x52, 0x20, 0x7e, 0x84, 0x04, 0xf2, + 0x08, 0x11, 0x10, 0x00, 0x56, 0x0c, 0xcf, 0xff, 0x07, 0x85, 0x1f, 0x08, + 0xd0, 0x00, 0xa9, 0x08, 0x51, 0x01, 0x08, 0x85, 0x21, 0x90, 0x44, 0x80, + 0x82, 0xb9, 0x21, 0xb0, 0x20, 0x82, 0x0c, 0x10, 0x13, 0x00, 0x40, 0xc1, + 0x0c, 0xf0, 0x08, 0x85, 0x02, 0x88, 0x3d, 0x08, 0x7f, 0x00, 0x80, 0xc1, + 0x44, 0x85, 0x60, 0x7a, 0xa1, 0x40, 0x81, 0x08, 0x30, 0x00, 0x10, 0x43, + 0x4e, 0x70, 0x52, 0x41, 0x27, 0xee, 0x08, 0x86, 0x21, 0x90, 0x4b, 0x09, + 0xbf, 0x00, 0x2e, 0x70, 0x47, 0x86, 0x33, 0x0a, 0xd0, 0x00, 0x65, 0x0a, + 0x71, 0x01, 0x82, 0xb9, 0x44, 0x80, 0x21, 0xb0, 0x20, 0x82, 0x03, 0x80, + 0x43, 0xc1, 0x13, 0xf0, 0xe2, 0x0d, 0xaf, 0xf5, 0xa1, 0x40, 0x05, 0xee, + 0xda, 0x0d, 0xaf, 0xf5, 0xc1, 0x40, 0x45, 0x08, 0x30, 0x20, 0x02, 0x40, + 0xce, 0x0d, 0x8f, 0xf5, 0x1c, 0xf0, 0x44, 0x86, 0x83, 0xc1, 0x60, 0x7a, + 0xc1, 0x40, 0x00, 0x10, 0x91, 0x00, 0x85, 0x21, 0x3e, 0x20, 0x3f, 0x08, + 0x10, 0x20, 0x20, 0x10, 0x02, 0x20, 0x21, 0x92, 0x33, 0x09, 0x9f, 0x00, + 0x1e, 0x44, 0x1f, 0x08, 0xd0, 0x00, 0x15, 0x08, 0x71, 0x01, 0x82, 0xb9, + 0x64, 0x82, 0x21, 0xb2, 0x03, 0x82, 0x20, 0x83, 0x42, 0xc1, 0x09, 0xf0, + 0x36, 0x09, 0x00, 0x00, 0xce, 0xc7, 0x06, 0x46, 0x82, 0xc1, 0x60, 0x7a, + 0x02, 0x40, 0x00, 0x10, 0x92, 0x00, 0x85, 0x22, 0x3e, 0x20, 0x22, 0x09, + 0x00, 0x00, 0x01, 0x87, 0x1e, 0x88, 0x15, 0x08, 0x7f, 0x00, 0x40, 0x24, + 0x04, 0x34, 0x04, 0x87, 0xa0, 0x80, 0xc4, 0x85, 0x08, 0x16, 0x04, 0x10, + 0x11, 0x87, 0x2f, 0x22, 0x47, 0x04, 0x2f, 0x23, 0x87, 0x04, 0x40, 0x24, + 0xc5, 0x31, 0x66, 0x0e, 0x6f, 0xfc, 0x62, 0x41, 0x01, 0x87, 0x1e, 0x88, + 0x17, 0x08, 0x5f, 0x00, 0x07, 0x14, 0xc0, 0x30, 0x0f, 0x08, 0x13, 0x00, + 0x00, 0xc0, 0x01, 0xa6, 0x23, 0x85, 0x60, 0x79, 0xa1, 0x40, 0xce, 0xc7, + 0xe2, 0xc2, 0x11, 0x80, 0xf6, 0x08, 0xaf, 0xfc, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0xb5, 0x01, 0xaf, 0xfc, 0x2f, 0x79, + 0xe2, 0xc2, 0x11, 0x80, 0x26, 0x0a, 0xaf, 0xfc, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x1d, 0x03, 0xaf, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0xd9, 0x04, 0x6f, 0xfc, 0x11, 0x80, 0xe0, 0x78, 0x11, 0x03, 0xaf, 0xfc, + 0x11, 0x80, 0xe0, 0x78, 0xa9, 0x05, 0xaf, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0xe4, 0xc2, 0x08, 0x46, 0x03, 0x80, 0x00, 0x80, 0x48, 0x80, 0x04, 0x82, + 0x61, 0x92, 0x23, 0x82, 0xa0, 0x80, 0x11, 0x86, 0x82, 0xbb, 0x36, 0x09, + 0xef, 0xfc, 0x61, 0xb2, 0x19, 0x08, 0xfe, 0x01, 0x00, 0x42, 0x24, 0x86, + 0xc6, 0xba, 0x00, 0x81, 0x64, 0x80, 0x22, 0x83, 0x40, 0xa9, 0x23, 0x80, + 0x60, 0x79, 0xa1, 0xa3, 0xc4, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, + 0xde, 0x09, 0xef, 0xfc, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x11, 0x80, 0x55, 0x02, 0xef, 0xfc, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, + 0x5e, 0x0a, 0xef, 0xfc, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0xbd, 0x02, 0xef, 0xfc, 0x11, 0x80, 0xe0, 0x78, 0x25, 0x00, 0xef, 0xfc, + 0x11, 0x80, 0xe0, 0x78, 0xb1, 0x02, 0xef, 0xfc, 0x11, 0x80, 0xe0, 0x78, + 0x51, 0x03, 0xef, 0xfc, 0x11, 0x80, 0xe0, 0x78, 0xc3, 0x41, 0xa0, 0x00, + 0x84, 0x6e, 0x49, 0x81, 0x20, 0xa0, 0x00, 0x7a, 0x5e, 0x78, 0xe0, 0x7e, + 0xe8, 0xc2, 0x28, 0x47, 0x50, 0x40, 0x08, 0x45, 0x2c, 0x70, 0x8a, 0x22, + 0x06, 0x00, 0x3e, 0x09, 0xef, 0xf5, 0xe1, 0x40, 0x1f, 0x08, 0x30, 0x20, + 0x2c, 0x70, 0xcd, 0x70, 0x06, 0xed, 0x04, 0x85, 0x20, 0x48, 0x66, 0x08, + 0xaf, 0xf5, 0xe1, 0x41, 0xc5, 0x71, 0xcf, 0x79, 0xf1, 0x09, 0x24, 0x84, + 0xe5, 0x74, 0xc8, 0xc6, 0xee, 0xc3, 0xa4, 0xc1, 0x08, 0x47, 0x03, 0x80, + 0xc0, 0x80, 0xa1, 0x80, 0x08, 0x86, 0x28, 0x85, 0x02, 0x10, 0x10, 0x01, + 0x26, 0x0a, 0xef, 0xff, 0x02, 0x11, 0x12, 0x01, 0x07, 0x85, 0x23, 0x08, + 0xd0, 0x00, 0xdd, 0x08, 0x51, 0x01, 0xd9, 0x0a, 0x9f, 0x20, 0x08, 0x85, + 0x64, 0x80, 0x41, 0x90, 0x0c, 0x10, 0x13, 0x00, 0x20, 0x83, 0x82, 0xba, + 0x41, 0xb0, 0x40, 0xc1, 0x0c, 0xf0, 0x08, 0x85, 0x02, 0x88, 0x3d, 0x08, + 0x7f, 0x00, 0x80, 0xc1, 0x44, 0x85, 0x60, 0x7a, 0xa1, 0x40, 0xb1, 0x08, + 0x30, 0x00, 0x10, 0x43, 0x07, 0x86, 0x37, 0x08, 0xf0, 0x00, 0x81, 0xc1, + 0xa1, 0x08, 0x71, 0x01, 0x44, 0x20, 0x11, 0xa1, 0x1f, 0xf4, 0x08, 0x86, + 0x2e, 0x70, 0x64, 0x80, 0x41, 0x90, 0x0c, 0x10, 0x10, 0x00, 0x20, 0x83, + 0x82, 0xba, 0x41, 0xb0, 0x41, 0xc1, 0x1c, 0xf0, 0xaa, 0x0b, 0xaf, 0xf5, + 0xa1, 0x40, 0xa6, 0x0b, 0xaf, 0xf5, 0xc1, 0x40, 0x3a, 0xf0, 0x65, 0x86, + 0x00, 0xc2, 0x60, 0x7b, 0xc1, 0x40, 0x10, 0x40, 0x14, 0x70, 0x83, 0xc0, + 0x78, 0x20, 0x11, 0x20, 0xca, 0x20, 0x01, 0x20, 0x08, 0xf0, 0x41, 0x29, + 0x91, 0x20, 0x6f, 0x20, 0x43, 0x00, 0x40, 0x24, 0x10, 0x33, 0x41, 0xc0, + 0x1a, 0x0f, 0xcf, 0xff, 0x30, 0x87, 0x01, 0x91, 0x11, 0x08, 0x1e, 0x00, + 0x45, 0x0a, 0x9f, 0x20, 0x41, 0x09, 0x31, 0x20, 0xa0, 0xb8, 0x01, 0xb1, + 0x04, 0x87, 0x00, 0x14, 0x04, 0x30, 0x40, 0x24, 0xc6, 0x32, 0x02, 0x41, + 0xa0, 0x80, 0x11, 0x87, 0x62, 0x42, 0x22, 0x43, 0xc4, 0x85, 0x96, 0x0d, + 0xef, 0xfc, 0x08, 0x16, 0x05, 0x10, 0x56, 0x09, 0xcf, 0xff, 0x0b, 0x14, + 0xc0, 0x30, 0x11, 0x08, 0x13, 0x00, 0x00, 0xc0, 0x23, 0x85, 0x01, 0xa6, + 0x60, 0x79, 0xa1, 0x40, 0xce, 0x0e, 0xcf, 0xff, 0xce, 0xc7, 0xe0, 0x78, + 0xe2, 0xc2, 0x11, 0x80, 0xd2, 0x0f, 0xef, 0xfc, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0x19, 0x01, 0x2f, 0xfd, 0x2f, 0x79, + 0xe2, 0xc2, 0x11, 0x80, 0x76, 0x09, 0x2f, 0xfd, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x91, 0x01, 0x6f, 0xfd, 0x11, 0x80, 0xe0, 0x78, + 0xed, 0x02, 0xef, 0xfc, 0x11, 0x80, 0xe0, 0x78, 0x31, 0x02, 0x6f, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0x69, 0x03, 0x6f, 0xfd, 0x11, 0x80, 0xe0, 0x78, + 0xe2, 0xc2, 0x29, 0x08, 0xb1, 0x00, 0x4c, 0x73, 0xcb, 0x45, 0xa0, 0x00, + 0xbc, 0x86, 0x21, 0x85, 0xc3, 0x40, 0xa0, 0x00, 0x7c, 0x6e, 0x00, 0x80, + 0x24, 0x71, 0x21, 0xa5, 0x2c, 0x71, 0x72, 0x08, 0x2f, 0xf8, 0x6c, 0x70, + 0x00, 0x1d, 0x43, 0x10, 0xc2, 0xc6, 0xe0, 0x78, 0xf0, 0xc3, 0xa9, 0xc1, + 0x63, 0x80, 0x20, 0x83, 0x28, 0x81, 0x41, 0x91, 0x82, 0xba, 0x41, 0xb1, + 0x41, 0x83, 0xa8, 0x82, 0xe1, 0x95, 0x4f, 0x27, 0x82, 0x10, 0x41, 0xb5, + 0x81, 0x80, 0x43, 0x85, 0xc4, 0x85, 0xa4, 0x81, 0x9e, 0x8c, 0x23, 0x81, + 0x00, 0x16, 0x14, 0x10, 0x00, 0x15, 0x11, 0x10, 0x19, 0x0c, 0x3f, 0x10, + 0xf1, 0x43, 0x62, 0x83, 0x88, 0x83, 0xa1, 0x94, 0x0d, 0x0d, 0xbf, 0x10, + 0x82, 0xbd, 0x63, 0x84, 0xa1, 0xb4, 0x0b, 0xf0, 0x8d, 0x70, 0xcb, 0x45, + 0x7f, 0x43, 0x00, 0x00, 0x80, 0xc3, 0x42, 0xc4, 0x41, 0xc4, 0x40, 0xc4, + 0x43, 0xc5, 0x84, 0x80, 0x11, 0x80, 0x40, 0x24, 0x04, 0x35, 0x40, 0x24, + 0xc7, 0x34, 0xc2, 0x84, 0xa0, 0x84, 0x04, 0x14, 0x12, 0x10, 0x10, 0x16, + 0x10, 0x10, 0xe4, 0x85, 0x08, 0x10, 0x06, 0x20, 0xe6, 0x0f, 0x6f, 0xfd, + 0x08, 0x17, 0x05, 0x10, 0x04, 0x1f, 0x40, 0x14, 0x04, 0x18, 0x40, 0x24, + 0x23, 0x85, 0x60, 0x79, 0xa1, 0x40, 0x17, 0x0b, 0xbf, 0x20, 0x85, 0xc1, + 0x42, 0x40, 0x9e, 0x0a, 0xe0, 0x00, 0x82, 0x42, 0x5e, 0x41, 0x60, 0x79, + 0x42, 0x40, 0x13, 0x14, 0x80, 0x30, 0x03, 0xe8, 0xd0, 0xc7, 0x23, 0x86, + 0x60, 0x79, 0xc1, 0x40, 0xd0, 0xc7, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, + 0x46, 0x08, 0xaf, 0xfd, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x11, 0x80, 0x9d, 0x00, 0xaf, 0xfd, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, + 0xf2, 0x09, 0xaf, 0xfd, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0xe9, 0x07, 0x8f, 0xff, 0x51, 0x02, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, + 0xed, 0x06, 0x6f, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0x59, 0x02, 0xaf, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0x15, 0x02, 0x00, 0x00, 0x29, 0x04, 0xaf, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0xf0, 0xc3, 0xa9, 0xc1, 0x63, 0x80, 0x20, 0x83, + 0x88, 0x81, 0x21, 0x94, 0x82, 0xb9, 0x21, 0xb4, 0x21, 0x83, 0x48, 0x81, + 0xe1, 0x92, 0x4f, 0x27, 0x81, 0x10, 0x21, 0xb2, 0x21, 0x80, 0xc4, 0x82, + 0xa4, 0x84, 0x43, 0x82, 0x27, 0x81, 0x00, 0x16, 0x14, 0x10, 0x00, 0x15, + 0x11, 0x10, 0x04, 0x21, 0x8b, 0x0f, 0x22, 0x00, 0x00, 0x00, 0x23, 0x84, + 0xf1, 0x43, 0x52, 0x23, 0x7e, 0x94, 0x0b, 0xf2, 0x62, 0x83, 0x88, 0x83, + 0xa1, 0x94, 0x0f, 0x0d, 0xbf, 0x10, 0x82, 0xbd, 0x63, 0x84, 0xa1, 0xb4, + 0x0a, 0xf0, 0x8d, 0x70, 0xcb, 0x45, 0x7f, 0x43, 0x00, 0x00, 0x80, 0xc3, + 0x42, 0xc4, 0x41, 0xc4, 0x40, 0xc4, 0x43, 0xc5, 0x84, 0x80, 0x11, 0x80, + 0x40, 0x24, 0x04, 0x35, 0x40, 0x24, 0xc7, 0x34, 0xc2, 0x84, 0xa0, 0x84, + 0x04, 0x14, 0x12, 0x10, 0x10, 0x16, 0x10, 0x10, 0xe4, 0x85, 0x08, 0x10, + 0x06, 0x20, 0xda, 0x0e, 0x6f, 0xfd, 0x08, 0x17, 0x05, 0x10, 0x04, 0x1f, + 0x40, 0x14, 0x04, 0x18, 0x40, 0x24, 0x23, 0x85, 0x60, 0x79, 0xa1, 0x40, + 0x15, 0x0b, 0xbf, 0x20, 0x85, 0xc1, 0x42, 0x40, 0x8e, 0x09, 0xe0, 0x00, + 0x82, 0x42, 0x5e, 0x41, 0x60, 0x79, 0x42, 0x40, 0x13, 0x14, 0x80, 0x30, + 0x02, 0xe8, 0xd0, 0xc7, 0x23, 0x86, 0x60, 0x79, 0xc1, 0x40, 0xd0, 0xc7, + 0xe2, 0xc2, 0x11, 0x80, 0x3a, 0x0f, 0x6f, 0xfd, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0x91, 0x07, 0x6f, 0xfd, 0x2f, 0x79, + 0xe2, 0xc2, 0x11, 0x80, 0xe6, 0x08, 0xaf, 0xfd, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0xdd, 0x06, 0x8f, 0xff, 0x45, 0x01, 0xaf, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0xe1, 0x05, 0x6f, 0xfd, 0x11, 0x80, 0xe0, 0x78, + 0x4d, 0x01, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0x09, 0x01, 0x00, 0x00, + 0x1d, 0x03, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0xf0, 0xc3, 0xa9, 0xc1, + 0x43, 0x80, 0x20, 0x82, 0x88, 0x81, 0x21, 0x94, 0x82, 0xb9, 0x21, 0xb4, + 0x21, 0x82, 0x68, 0x81, 0xe1, 0x93, 0x4f, 0x27, 0x81, 0x10, 0x21, 0xb3, + 0x22, 0x82, 0x43, 0x83, 0xc4, 0x83, 0x64, 0x84, 0xa8, 0x81, 0x23, 0x84, + 0x00, 0x16, 0x14, 0x10, 0x00, 0x13, 0x11, 0x00, 0x81, 0x95, 0x11, 0x0c, + 0xbf, 0x10, 0xf1, 0x43, 0x63, 0x85, 0x82, 0xbc, 0x81, 0xb5, 0x0b, 0xf0, + 0x8d, 0x70, 0xcb, 0x45, 0x7f, 0x43, 0x00, 0x00, 0x80, 0xc3, 0x42, 0xc4, + 0x41, 0xc4, 0x40, 0xc4, 0x43, 0xc5, 0x84, 0x80, 0x11, 0x80, 0x40, 0x24, + 0x04, 0x35, 0x40, 0x24, 0xc7, 0x34, 0xc2, 0x84, 0xa0, 0x84, 0x04, 0x14, + 0x12, 0x10, 0x10, 0x16, 0x10, 0x10, 0xe4, 0x85, 0x08, 0x10, 0x06, 0x20, + 0xde, 0x0d, 0x6f, 0xfd, 0x08, 0x17, 0x05, 0x10, 0x04, 0x1f, 0x40, 0x14, + 0x04, 0x18, 0x40, 0x24, 0x23, 0x85, 0x60, 0x79, 0xa1, 0x40, 0x17, 0x0b, + 0xbf, 0x20, 0x85, 0xc1, 0x42, 0x40, 0x96, 0x08, 0xe0, 0x00, 0x82, 0x42, + 0x5e, 0x41, 0x60, 0x79, 0x42, 0x40, 0x13, 0x14, 0x80, 0x30, 0x03, 0xe8, + 0xd0, 0xc7, 0x23, 0x86, 0x60, 0x79, 0xc1, 0x40, 0xd0, 0xc7, 0xe0, 0x78, + 0xe2, 0xc2, 0x11, 0x80, 0x3e, 0x0e, 0x6f, 0xfd, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0x95, 0x06, 0x6f, 0xfd, 0x2f, 0x79, + 0xe2, 0xc2, 0x11, 0x80, 0xea, 0x0f, 0x6f, 0xfd, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0xe1, 0x05, 0x8f, 0xff, 0x49, 0x00, 0xaf, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0xe5, 0x04, 0x6f, 0xfd, 0x11, 0x80, 0xe0, 0x78, + 0x51, 0x00, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0x0d, 0x00, 0x00, 0x00, + 0x21, 0x02, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0xe6, 0xc2, 0x08, 0x47, + 0x50, 0x87, 0x03, 0x80, 0x28, 0x45, 0xc0, 0x92, 0x00, 0x80, 0x4a, 0x09, + 0xaf, 0xf5, 0xc1, 0x41, 0x03, 0x87, 0xc1, 0x41, 0x01, 0x80, 0x3e, 0x09, + 0xaf, 0xf5, 0xc0, 0xb5, 0xc1, 0xb5, 0xc6, 0xc6, 0xe4, 0xc2, 0x08, 0x46, + 0x03, 0x80, 0x00, 0x80, 0x48, 0x80, 0x04, 0x82, 0x61, 0x92, 0x23, 0x82, + 0xa0, 0x80, 0x11, 0x86, 0x82, 0xbb, 0x7a, 0x0e, 0xaf, 0xfd, 0x61, 0xb2, + 0x19, 0x08, 0xfe, 0x01, 0x00, 0x42, 0x24, 0x86, 0xc6, 0xba, 0x00, 0x81, + 0x64, 0x80, 0x22, 0x83, 0x40, 0xa9, 0x23, 0x80, 0x60, 0x79, 0xa1, 0xa3, + 0xc4, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, 0x02, 0x0f, 0xaf, 0xfd, + 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0x55, 0x07, + 0xaf, 0xfd, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, 0x5e, 0x0f, 0xaf, 0xfd, + 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0xc1, 0x07, 0xaf, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0x91, 0x05, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, + 0xc9, 0x07, 0xaf, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0x69, 0x00, 0xef, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0xf4, 0xc3, 0xa5, 0xc1, 0x08, 0x45, 0x03, 0x80, + 0x00, 0x80, 0x48, 0x80, 0x01, 0x92, 0x82, 0xb8, 0x01, 0xb2, 0x04, 0x85, + 0x61, 0x85, 0x23, 0x82, 0x44, 0x82, 0xc1, 0x80, 0x00, 0x10, 0x15, 0x00, + 0x87, 0x83, 0x00, 0x12, 0x12, 0x00, 0x10, 0x16, 0x11, 0x10, 0x10, 0x15, + 0x16, 0x20, 0x0f, 0x0c, 0x7f, 0x16, 0xd1, 0x40, 0x4c, 0x72, 0x83, 0xc3, + 0x06, 0xf0, 0xe2, 0x80, 0x4c, 0x73, 0xc4, 0x87, 0xd1, 0x44, 0x62, 0x86, + 0x0b, 0x0c, 0x7f, 0x17, 0x40, 0x24, 0x04, 0x31, 0x06, 0xf0, 0x46, 0x48, + 0x04, 0x86, 0x10, 0x43, 0x08, 0x10, 0x04, 0x00, 0x08, 0x16, 0x05, 0x20, + 0x36, 0x42, 0x11, 0x85, 0x46, 0x09, 0xef, 0xfd, 0x40, 0x24, 0xc6, 0x30, + 0x03, 0x14, 0xc0, 0x30, 0x13, 0x08, 0x13, 0x00, 0x04, 0x1e, 0x80, 0x24, + 0xbe, 0x41, 0x60, 0x79, 0xa2, 0x40, 0x03, 0x14, 0x80, 0x30, 0x11, 0x08, + 0xfe, 0x00, 0x02, 0x40, 0x04, 0x19, 0x80, 0x24, 0x1e, 0x41, 0x40, 0x79, + 0x01, 0x85, 0x07, 0x80, 0x1b, 0x08, 0x5e, 0x06, 0x03, 0x14, 0x81, 0x30, + 0x13, 0x09, 0x1e, 0x01, 0x04, 0x1c, 0x80, 0x24, 0x23, 0x87, 0x60, 0x79, + 0xe1, 0x40, 0x01, 0x85, 0x07, 0x80, 0x19, 0x08, 0x5e, 0x07, 0x03, 0x14, + 0x80, 0x30, 0x11, 0x08, 0x7e, 0x01, 0xc1, 0x40, 0x04, 0x1b, 0x80, 0x24, + 0x23, 0x86, 0x40, 0x79, 0xd4, 0xc7, 0xe0, 0x78, 0xe2, 0xc2, 0x11, 0x80, + 0xce, 0x0c, 0xef, 0xfd, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x11, 0x80, 0x1d, 0x05, 0xef, 0xfd, 0x2f, 0x79, 0xe2, 0xc2, 0x11, 0x80, + 0x3a, 0x0d, 0xef, 0xfd, 0x88, 0x45, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x11, 0x07, 0xef, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0xa9, 0x07, 0xaf, 0xfd, + 0x11, 0x80, 0xe0, 0x78, 0x51, 0x00, 0x2f, 0xfe, 0x11, 0x80, 0xe0, 0x78, + 0x31, 0x02, 0x2f, 0xfe, 0x11, 0x80, 0xe0, 0x78, 0x41, 0x28, 0xc1, 0x00, + 0x44, 0x21, 0x01, 0x07, 0x30, 0x21, 0x82, 0x0f, 0xa0, 0x00, 0x44, 0xe1, + 0x2c, 0x71, 0x00, 0x29, 0x00, 0x00, 0x04, 0x7a, 0xe0, 0x7f, 0x79, 0x22, + 0x00, 0x00, 0xe0, 0x78, 0xc3, 0x41, 0xa0, 0x00, 0x44, 0xe1, 0x01, 0x81, + 0x40, 0x81, 0x62, 0x81, 0x05, 0x20, 0x8c, 0x0f, 0xff, 0xf9, 0x00, 0x00, + 0x05, 0x22, 0x82, 0x0f, 0xff, 0x0f, 0x00, 0xfc, 0x05, 0x23, 0x80, 0x0f, + 0x00, 0x70, 0xf9, 0x78, 0x81, 0xa1, 0x40, 0xa1, 0xe0, 0x7f, 0x02, 0xa1, + 0x8c, 0x20, 0x02, 0x88, 0xe0, 0x20, 0xc5, 0x07, 0x41, 0x28, 0xc1, 0x00, + 0x44, 0x21, 0x02, 0x07, 0x00, 0x22, 0x82, 0x0f, 0xa0, 0x00, 0x44, 0xe1, + 0x20, 0x82, 0xc4, 0xb8, 0x0f, 0x21, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0xa2, + 0x99, 0x03, 0x8f, 0xff, 0xe6, 0xc2, 0xd1, 0x80, 0x08, 0x45, 0x10, 0x80, + 0x28, 0x47, 0x44, 0x8e, 0x2f, 0x0a, 0x71, 0x00, 0x00, 0x90, 0x95, 0xe8, + 0x03, 0x85, 0x2c, 0x70, 0x1a, 0x0f, 0x6f, 0xf5, 0x00, 0x80, 0x03, 0x85, + 0xc3, 0x41, 0x00, 0x00, 0xff, 0xff, 0x01, 0x80, 0x0a, 0x0f, 0x6f, 0xf5, + 0x00, 0x1f, 0x05, 0x10, 0x10, 0x85, 0x44, 0x8e, 0x02, 0x1f, 0xc5, 0x1f, + 0x00, 0x90, 0x94, 0xe8, 0x25, 0x0a, 0x91, 0x00, 0x03, 0x85, 0xc3, 0x41, + 0x00, 0x00, 0xff, 0xff, 0xea, 0x0e, 0x6f, 0xf5, 0x00, 0x80, 0x03, 0x85, + 0x2c, 0x70, 0x01, 0x80, 0xde, 0x0e, 0x6f, 0xf5, 0x00, 0x1f, 0xc5, 0x1f, + 0x02, 0x1f, 0x05, 0x10, 0xc6, 0xc6, 0xe0, 0x78, 0xfa, 0xc2, 0xfc, 0x1c, + 0xc8, 0xb6, 0xa6, 0xc1, 0x04, 0x1c, 0x00, 0x31, 0xa0, 0x80, 0x01, 0xc0, + 0x00, 0x12, 0x14, 0x00, 0xd3, 0x41, 0x7f, 0x47, 0x00, 0xff, 0x2c, 0x15, + 0x19, 0x10, 0x00, 0x80, 0x58, 0x43, 0x0f, 0x70, 0xd3, 0x43, 0x10, 0x3a, + 0xe0, 0x2d, 0xd3, 0x42, 0x48, 0x42, 0x00, 0x00, 0xed, 0x70, 0x45, 0xc0, + 0x0c, 0x70, 0x0a, 0x27, 0x40, 0x24, 0x0a, 0x25, 0x40, 0x24, 0x44, 0xc3, + 0x40, 0xc1, 0x42, 0xc0, 0x43, 0xc0, 0xdb, 0x0f, 0x25, 0x15, 0x8a, 0x23, + 0x0e, 0x01, 0x00, 0xc6, 0xf6, 0x7e, 0x00, 0x86, 0xc7, 0x08, 0x30, 0x00, + 0xea, 0xe0, 0x1a, 0xf2, 0xe8, 0xe0, 0x2f, 0xf4, 0x1d, 0x8d, 0xbb, 0x08, + 0x3e, 0x00, 0x68, 0xd8, 0x21, 0x86, 0x43, 0xc0, 0x04, 0x31, 0x40, 0x84, + 0x30, 0x45, 0xca, 0x25, 0x41, 0x24, 0x53, 0xf2, 0x04, 0x35, 0xc0, 0xa4, + 0x8a, 0x20, 0x3f, 0x2d, 0x94, 0xf7, 0x04, 0x35, 0x80, 0xa4, 0xd8, 0xf6, + 0x67, 0x03, 0x00, 0x00, 0x1d, 0x8d, 0x8f, 0x08, 0x3e, 0x00, 0x6a, 0xd8, + 0x21, 0x86, 0x42, 0xc0, 0x04, 0x31, 0x40, 0x84, 0x30, 0x47, 0x3d, 0xf2, + 0x04, 0x37, 0xc0, 0xa4, 0x8a, 0x20, 0x3f, 0x2d, 0x46, 0x03, 0x25, 0x00, + 0x04, 0x37, 0x80, 0xa4, 0x3e, 0x03, 0x09, 0x00, 0x04, 0x1e, 0x00, 0x16, + 0x31, 0xf0, 0x01, 0x86, 0x04, 0x30, 0x00, 0x86, 0x5a, 0x00, 0x0c, 0x00, + 0x04, 0x30, 0x80, 0x8f, 0x7f, 0x47, 0x00, 0xef, 0x4e, 0x00, 0x0d, 0x00, + 0xd3, 0x40, 0xc8, 0x3f, 0x00, 0x00, 0x07, 0x30, 0x00, 0x04, 0x22, 0x09, + 0x2f, 0xf2, 0x10, 0x46, 0x48, 0x30, 0x40, 0x02, 0x29, 0x68, 0x2b, 0x78, + 0x0e, 0xf2, 0x4a, 0x24, 0x00, 0x71, 0x0c, 0x72, 0xa8, 0x20, 0x80, 0x01, + 0x05, 0x29, 0x02, 0x00, 0x0c, 0x78, 0x45, 0x79, 0x01, 0x69, 0x48, 0x30, + 0x00, 0x00, 0x07, 0xf0, 0x48, 0x30, 0x00, 0x00, 0x04, 0x36, 0x00, 0xa0, + 0x07, 0xf2, 0x00, 0x30, 0x00, 0x04, 0x01, 0xa6, 0x03, 0xf0, 0x0a, 0x27, + 0x40, 0x24, 0xe5, 0x71, 0x95, 0xf1, 0x23, 0x73, 0x00, 0x8b, 0x35, 0xe8, + 0x02, 0x85, 0x20, 0x88, 0x28, 0x40, 0x2f, 0xe9, 0xe1, 0x80, 0x8d, 0x70, + 0xcb, 0x46, 0x00, 0x00, 0xff, 0xff, 0x81, 0x4f, 0x00, 0x91, 0x49, 0x08, + 0xd1, 0x02, 0x08, 0x89, 0x50, 0x81, 0x42, 0x20, 0x3c, 0x80, 0x00, 0x1a, + 0x84, 0x03, 0x10, 0xf2, 0x0c, 0x11, 0x0b, 0x00, 0xa8, 0x20, 0x00, 0x03, + 0x04, 0x13, 0x00, 0x14, 0x08, 0x80, 0x43, 0x90, 0x05, 0xea, 0x44, 0x90, + 0x03, 0xea, 0xc4, 0xb0, 0xc3, 0xb0, 0xe0, 0x78, 0x09, 0x89, 0x42, 0x20, + 0x3c, 0x80, 0x0a, 0xf2, 0x10, 0x11, 0x01, 0x00, 0xa8, 0x20, 0x80, 0x01, + 0x04, 0x11, 0x00, 0x04, 0x04, 0x80, 0xc0, 0xb0, 0x85, 0x71, 0xb7, 0x0c, + 0x04, 0x92, 0x00, 0x1b, 0x02, 0x06, 0x8a, 0x23, 0x4e, 0x11, 0x00, 0x23, + 0x4b, 0x16, 0x00, 0x13, 0x80, 0x10, 0xbf, 0x08, 0x10, 0x00, 0x02, 0x85, + 0x20, 0x88, 0xb3, 0x09, 0x30, 0x00, 0x28, 0x40, 0x61, 0x80, 0xcd, 0x70, + 0xcb, 0x47, 0x00, 0x00, 0xff, 0xff, 0xc1, 0x4b, 0x00, 0x91, 0x45, 0x08, + 0x91, 0x03, 0x08, 0x89, 0x50, 0x81, 0x42, 0x20, 0x3c, 0x80, 0xe0, 0xb2, + 0x0e, 0xf2, 0x43, 0x81, 0xa8, 0x20, 0x00, 0x03, 0x04, 0x12, 0x00, 0x04, + 0x08, 0x80, 0x83, 0x90, 0x05, 0xec, 0x84, 0x90, 0x03, 0xec, 0xe4, 0xb0, + 0xe3, 0xb0, 0xe0, 0x78, 0x09, 0x89, 0x42, 0x20, 0x3c, 0x80, 0x0a, 0xf2, + 0x10, 0x11, 0x01, 0x00, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x00, 0x04, + 0x04, 0x80, 0xe0, 0xb0, 0xc5, 0x71, 0xbb, 0x0e, 0x04, 0x92, 0xcd, 0x70, + 0xcb, 0x47, 0x00, 0x00, 0xff, 0xff, 0xc1, 0x4b, 0x00, 0x91, 0x45, 0x08, + 0x51, 0x03, 0x08, 0x89, 0x50, 0x81, 0x42, 0x20, 0x3c, 0x80, 0xe0, 0xb2, + 0x0e, 0xf2, 0x43, 0x81, 0xa8, 0x20, 0x00, 0x03, 0x04, 0x12, 0x00, 0x04, + 0x08, 0x80, 0x83, 0x90, 0x05, 0xec, 0x84, 0x90, 0x03, 0xec, 0xe4, 0xb0, + 0xe3, 0xb0, 0xe0, 0x78, 0x09, 0x89, 0x42, 0x20, 0x3c, 0x80, 0x0a, 0xf2, + 0x10, 0x11, 0x01, 0x00, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x00, 0x04, + 0x04, 0x80, 0xe0, 0xb0, 0xc5, 0x71, 0xbb, 0x0e, 0x04, 0x92, 0x00, 0x1b, + 0x02, 0x16, 0x80, 0x21, 0x8e, 0x31, 0x00, 0x11, 0x80, 0x30, 0x33, 0xe8, + 0x02, 0x85, 0x20, 0x88, 0x28, 0x43, 0x2d, 0xe9, 0xc1, 0x80, 0xed, 0x70, + 0xcb, 0x44, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x4e, 0x00, 0x91, 0x45, 0x08, + 0x11, 0x03, 0x08, 0x89, 0x50, 0x81, 0x42, 0x20, 0x3c, 0x80, 0x80, 0xb2, + 0x0e, 0xf2, 0x43, 0x81, 0xa8, 0x20, 0x00, 0x03, 0x04, 0x12, 0x00, 0x04, + 0x08, 0x80, 0x63, 0x90, 0x05, 0xeb, 0x64, 0x90, 0x03, 0xeb, 0x84, 0xb0, + 0x83, 0xb0, 0xe0, 0x78, 0x09, 0x89, 0x42, 0x20, 0x3c, 0x80, 0x0a, 0xf2, + 0x10, 0x11, 0x01, 0x00, 0xa8, 0x20, 0x80, 0x01, 0x04, 0x11, 0x00, 0x04, + 0x04, 0x80, 0x80, 0xb0, 0xe5, 0x71, 0xbb, 0x0f, 0xc4, 0x92, 0x00, 0x19, + 0x02, 0x36, 0x00, 0xc1, 0x04, 0xc3, 0x04, 0x14, 0x04, 0x30, 0xa1, 0x40, + 0x96, 0x09, 0x2f, 0xf5, 0x63, 0x42, 0xef, 0x08, 0x31, 0x00, 0x10, 0x40, + 0x07, 0x85, 0xe7, 0x08, 0x1e, 0x02, 0x03, 0xc0, 0x1a, 0xe8, 0x02, 0x85, + 0xde, 0x08, 0x6f, 0xf4, 0x1f, 0xd9, 0x04, 0x35, 0x80, 0xaf, 0x7f, 0x47, + 0x00, 0xef, 0x00, 0x42, 0x10, 0xf7, 0x10, 0xea, 0x10, 0x82, 0x00, 0x90, + 0x48, 0x30, 0x00, 0x00, 0x00, 0x35, 0x01, 0x20, 0x07, 0x36, 0x40, 0x70, + 0x48, 0x47, 0x00, 0x00, 0x31, 0x82, 0x48, 0x30, 0x40, 0x02, 0x1f, 0xa1, + 0x02, 0xc0, 0x1c, 0xe8, 0x02, 0x85, 0xaa, 0x08, 0x6f, 0xf4, 0x1f, 0xd9, + 0x04, 0x37, 0x80, 0xaf, 0x7f, 0x47, 0x00, 0xef, 0x00, 0x42, 0x12, 0xf7, + 0x10, 0xea, 0x10, 0x82, 0x00, 0x90, 0x48, 0x30, 0x00, 0x00, 0x00, 0x37, + 0x01, 0x20, 0x07, 0x36, 0x40, 0x70, 0x48, 0x47, 0x00, 0x00, 0x31, 0x82, + 0x48, 0x30, 0x40, 0x02, 0x84, 0x19, 0x00, 0x00, 0x00, 0xc0, 0xed, 0x70, + 0xc4, 0x68, 0x67, 0x40, 0x6b, 0x0f, 0x05, 0x10, 0x00, 0xc0, 0x08, 0x10, + 0x01, 0x04, 0x40, 0xc0, 0xea, 0xe1, 0x12, 0xf2, 0xe8, 0xe1, 0x2a, 0xf4, + 0x00, 0x86, 0x04, 0x30, 0x80, 0x8f, 0x7f, 0x47, 0x00, 0xff, 0x24, 0xf2, + 0x02, 0x85, 0x4e, 0x08, 0x6f, 0xf4, 0x1f, 0xd9, 0x31, 0x80, 0x10, 0x80, + 0x3f, 0x81, 0x10, 0xf0, 0x00, 0x86, 0x04, 0x30, 0x80, 0x8f, 0x7f, 0x47, + 0x00, 0xff, 0x16, 0xf2, 0x02, 0x85, 0x32, 0x08, 0x6f, 0xf4, 0x1f, 0xd9, + 0x31, 0x80, 0x10, 0x80, 0x84, 0x11, 0x01, 0x00, 0x00, 0x90, 0x48, 0x31, + 0x01, 0x00, 0x48, 0x30, 0x00, 0x00, 0x00, 0x30, 0x40, 0x00, 0x07, 0x36, + 0x00, 0x70, 0x48, 0x47, 0x00, 0x00, 0x00, 0xa6, 0x08, 0xe6, 0xe5, 0x71, + 0xcb, 0xf1, 0x4a, 0x85, 0x6c, 0x70, 0x8d, 0x70, 0x30, 0x1a, 0x41, 0x00, + 0x2c, 0x1a, 0x00, 0x06, 0x05, 0xc1, 0x8f, 0x78, 0x23, 0x08, 0x45, 0x00, + 0x04, 0xc1, 0x16, 0x21, 0x00, 0x00, 0x20, 0x80, 0x09, 0xe9, 0x01, 0x80, + 0x04, 0x30, 0x80, 0x8f, 0x7f, 0x47, 0x00, 0xef, 0x03, 0xf7, 0x64, 0x71, + 0x6b, 0xa2, 0x85, 0x71, 0xee, 0xf1, 0x02, 0x40, 0xa6, 0xc0, 0x04, 0x14, + 0x1b, 0x34, 0xda, 0xc6, 0xe4, 0xc2, 0x08, 0x46, 0x03, 0x80, 0x00, 0x80, + 0x48, 0x80, 0x04, 0x82, 0x61, 0x92, 0x23, 0x82, 0xa0, 0x80, 0x11, 0x86, + 0x82, 0xbb, 0x4a, 0x0f, 0xef, 0xfd, 0x61, 0xb2, 0x19, 0x08, 0xfe, 0x01, + 0x00, 0x42, 0x24, 0x86, 0xc6, 0xba, 0x00, 0x81, 0x64, 0x80, 0x22, 0x83, + 0x40, 0xa9, 0x23, 0x80, 0x60, 0x79, 0xa1, 0xa3, 0xc4, 0xc6, 0xe0, 0x78, + 0xe2, 0xc2, 0x11, 0x80, 0xe2, 0x09, 0x2f, 0xfe, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x11, 0x80, 0x65, 0x02, 0x2f, 0xfe, 0x2f, 0x79, + 0xe2, 0xc2, 0x11, 0x80, 0x6e, 0x0a, 0x2f, 0xfe, 0x88, 0x45, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x51, 0x03, 0x2f, 0xfe, 0x11, 0x80, 0xe0, 0x78, + 0x1d, 0x06, 0xef, 0xfd, 0x11, 0x80, 0xe0, 0x78, 0x45, 0x03, 0x2f, 0xfe, + 0x11, 0x80, 0xe0, 0x78, 0xa1, 0x04, 0x2f, 0xfe, 0x11, 0x80, 0xe0, 0x78, + 0xf2, 0xc3, 0x82, 0x24, 0x0c, 0x3f, 0x28, 0x45, 0x22, 0x89, 0x08, 0x46, + 0x8a, 0x25, 0x3e, 0x27, 0x8c, 0x21, 0x83, 0x8f, 0xc9, 0xf4, 0x4a, 0x24, + 0xc0, 0x73, 0x8a, 0x27, 0x8e, 0x10, 0xdf, 0x67, 0x4a, 0x20, 0x00, 0x00, + 0xa8, 0x20, 0x80, 0x01, 0x81, 0xc1, 0x19, 0x61, 0x04, 0x71, 0x00, 0xa9, + 0x03, 0x8d, 0x09, 0xe8, 0x2e, 0x71, 0x8a, 0x25, 0xfe, 0x26, 0x0f, 0x08, + 0x34, 0x04, 0x61, 0xc0, 0xb3, 0xf0, 0x4a, 0x21, 0xc0, 0x23, 0x8a, 0x22, + 0x07, 0x2d, 0x54, 0x26, 0x14, 0x19, 0x54, 0x26, 0x93, 0x1b, 0xae, 0x70, + 0x0e, 0x71, 0x0c, 0x70, 0x00, 0x22, 0x92, 0x23, 0x00, 0x1c, 0x01, 0x31, + 0x0c, 0x20, 0x40, 0xa4, 0x42, 0x01, 0x2d, 0x00, 0x14, 0x70, 0x9f, 0xf4, + 0x81, 0xc0, 0x04, 0x77, 0x32, 0x20, 0x00, 0x04, 0x04, 0x77, 0x8e, 0xe0, + 0x22, 0x01, 0x0d, 0x00, 0x25, 0x20, 0x00, 0x00, 0x0f, 0xf0, 0x1a, 0xf0, + 0x27, 0xf0, 0x33, 0xf0, 0x45, 0xf0, 0x4b, 0xf0, 0x4f, 0xf0, 0x55, 0xf0, + 0x5a, 0xf0, 0x61, 0xf0, 0x66, 0xf0, 0x6c, 0xf0, 0x70, 0xf0, 0x76, 0xf0, + 0x7a, 0xf0, 0x80, 0xc1, 0x56, 0x24, 0x42, 0x3d, 0x82, 0x0d, 0x20, 0x00, + 0xa1, 0x40, 0x56, 0x24, 0x41, 0x3d, 0x14, 0xda, 0x82, 0x40, 0x1a, 0xf0, + 0x80, 0xc1, 0x00, 0x24, 0x82, 0x3f, 0x00, 0x00, 0x94, 0x01, 0x5e, 0x0e, + 0x20, 0x00, 0xa1, 0x40, 0x00, 0x24, 0x81, 0x3f, 0x00, 0x00, 0x94, 0x01, + 0x14, 0xda, 0x62, 0x40, 0x0a, 0xf0, 0x80, 0xc1, 0x85, 0xc2, 0x62, 0x08, + 0x60, 0x00, 0xa1, 0x40, 0x85, 0xc1, 0x8a, 0x22, 0x06, 0x00, 0x42, 0x40, + 0x6a, 0x0e, 0x4f, 0xe7, 0x59, 0xf0, 0x80, 0xc1, 0x00, 0x24, 0x82, 0x3f, + 0x00, 0x00, 0xbc, 0x01, 0x06, 0x09, 0x60, 0x00, 0xa1, 0x40, 0x70, 0x16, + 0x82, 0x10, 0x00, 0x24, 0x81, 0x3f, 0x00, 0x00, 0xbc, 0x01, 0x82, 0x0a, + 0x6f, 0xf1, 0xdf, 0x16, 0x00, 0x16, 0x10, 0x45, 0x45, 0xf0, 0x80, 0xc1, + 0x2a, 0x0b, 0x60, 0x00, 0xa1, 0x40, 0x0a, 0xa6, 0x3f, 0xf0, 0x80, 0xc1, + 0x1e, 0x0b, 0x60, 0x00, 0xa1, 0x40, 0x0b, 0xa6, 0x39, 0xf0, 0x80, 0xc1, + 0x12, 0x0b, 0x60, 0x00, 0xa1, 0x40, 0x0c, 0xa6, 0x33, 0xf0, 0x80, 0xc1, + 0x06, 0x0b, 0x60, 0x00, 0xa1, 0x40, 0xdd, 0x1e, 0x18, 0x10, 0x2d, 0xf0, + 0x80, 0xc1, 0xfa, 0x0a, 0x60, 0x00, 0xa1, 0x40, 0xde, 0x1e, 0x18, 0x10, + 0x25, 0xf0, 0x80, 0xc1, 0x1e, 0x0d, 0xe0, 0x00, 0xa1, 0x40, 0xff, 0x1f, + 0x02, 0x90, 0x1f, 0xf0, 0x80, 0xc1, 0x12, 0x0d, 0xe0, 0x00, 0xa1, 0x40, + 0x00, 0xaf, 0x19, 0xf0, 0x80, 0xc1, 0x06, 0x0d, 0xe0, 0x00, 0xa1, 0x40, + 0x01, 0xaf, 0x13, 0xf0, 0x80, 0xc1, 0xfa, 0x0c, 0xe0, 0x00, 0xa1, 0x40, + 0x02, 0xaf, 0x0d, 0xf0, 0x80, 0xc1, 0xee, 0x0c, 0xe0, 0x00, 0xa1, 0x40, + 0x03, 0xaf, 0x07, 0xf0, 0x80, 0xc1, 0xe2, 0x0c, 0xe0, 0x00, 0xa1, 0x40, + 0x04, 0xaf, 0xb6, 0x70, 0x79, 0x25, 0x00, 0x20, 0xc0, 0x20, 0x61, 0x20, + 0x5e, 0xf1, 0xa2, 0x40, 0xd2, 0xc7, 0xe0, 0x78, 0x4a, 0x24, 0xc0, 0x70, + 0xa8, 0x20, 0x40, 0x02, 0x02, 0x10, 0x42, 0x05, 0x07, 0x0a, 0x13, 0x00, + 0x53, 0x7a, 0x02, 0x19, 0x94, 0x00, 0xe0, 0x7e, 0xe4, 0xc2, 0x08, 0x46, + 0x4a, 0x25, 0x00, 0x10, 0x1a, 0x0e, 0x6f, 0xf9, 0x00, 0x86, 0xa5, 0x71, + 0xf9, 0x0d, 0x34, 0x91, 0x04, 0x1e, 0x10, 0x10, 0xc4, 0xc6, 0xe0, 0x78, + 0x2c, 0x72, 0x4c, 0x71, 0x2f, 0x21, 0x42, 0x80, 0x42, 0xf7, 0x09, 0x7a, + 0x46, 0x21, 0x01, 0x80, 0x04, 0xf2, 0x0e, 0x78, 0x09, 0x78, 0xf8, 0xf1, + 0xe0, 0x7f, 0x4e, 0x78, 0xf1, 0xc0, 0x00, 0x41, 0x14, 0x73, 0x0c, 0x77, + 0x07, 0xf7, 0xf0, 0x26, 0x41, 0x70, 0x13, 0x00, 0xbc, 0xaa, 0x03, 0xe9, + 0x40, 0x79, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xe6, 0xc3, 0xa5, 0xc1, + 0x68, 0x45, 0x60, 0x83, 0x28, 0x46, 0x14, 0xe3, 0x2b, 0x0a, 0xe4, 0x00, + 0x00, 0x41, 0x80, 0xc0, 0x14, 0xda, 0x22, 0x0d, 0x6f, 0xe7, 0x80, 0xc7, + 0x4a, 0x24, 0x00, 0x75, 0xa8, 0x20, 0x00, 0x02, 0x00, 0x85, 0x01, 0x17, + 0x81, 0x14, 0xd8, 0x60, 0xc5, 0x71, 0x20, 0xa8, 0x00, 0x85, 0x14, 0xe0, + 0x00, 0xa5, 0xc6, 0xc7, 0xe4, 0xc2, 0x08, 0x46, 0x20, 0x40, 0x28, 0x45, + 0xa2, 0x0d, 0x2f, 0xfe, 0x00, 0x19, 0x01, 0x00, 0xc0, 0xa5, 0xa1, 0x40, + 0xc4, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0x08, 0x45, 0x70, 0x18, 0x03, 0x00, + 0x54, 0x20, 0x00, 0x09, 0x2c, 0x70, 0x1e, 0x0b, 0x6f, 0xf5, 0x14, 0xda, + 0x4a, 0x24, 0x40, 0x71, 0x54, 0x25, 0x80, 0x1b, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x18, 0x11, 0x00, 0x8a, 0x20, 0x07, 0x0d, 0xb8, 0x60, 0x2c, 0x70, + 0xfe, 0x0a, 0x6f, 0xf5, 0x8a, 0x22, 0x06, 0x00, 0x4a, 0x24, 0x40, 0x71, + 0x40, 0x25, 0x00, 0x1d, 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, + 0x8a, 0x24, 0x01, 0x78, 0x54, 0x25, 0x80, 0x1e, 0x4a, 0x26, 0x00, 0x10, + 0xa8, 0x20, 0x00, 0x01, 0x04, 0x18, 0x11, 0x00, 0xa1, 0x40, 0x1e, 0x0f, + 0x2f, 0xfe, 0xdf, 0x1d, 0x98, 0x13, 0x4a, 0x24, 0x40, 0x71, 0xa1, 0x40, + 0xa8, 0x20, 0x40, 0x01, 0xc1, 0xa0, 0x08, 0x18, 0x11, 0x00, 0x8a, 0x20, + 0x0e, 0x00, 0xb8, 0x60, 0x00, 0x18, 0x03, 0x00, 0xa1, 0x40, 0xc4, 0xc6, + 0xe4, 0xc2, 0x08, 0x46, 0x20, 0x40, 0x28, 0x45, 0x04, 0x19, 0x03, 0x00, + 0x66, 0x0a, 0x6f, 0xfe, 0x00, 0x19, 0x01, 0x00, 0xc0, 0xa5, 0xa1, 0x40, + 0xc4, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0x08, 0x46, 0x20, 0x40, 0x28, 0x45, + 0x82, 0x0a, 0x6f, 0xfe, 0x00, 0x19, 0x01, 0x00, 0xa1, 0x40, 0x7a, 0x0a, + 0x6f, 0xfe, 0x58, 0x1d, 0x01, 0x10, 0xc0, 0xa5, 0xa1, 0x40, 0xc4, 0xc6, + 0x4a, 0x24, 0xc0, 0x70, 0x40, 0x21, 0x03, 0x02, 0x0a, 0x22, 0x80, 0x0f, + 0x13, 0x00, 0x38, 0x6c, 0x04, 0x19, 0x43, 0x00, 0x00, 0x19, 0x01, 0x00, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x12, 0x0c, 0x04, 0x04, 0x1b, 0x10, 0x03, + 0x14, 0x19, 0x05, 0x00, 0x00, 0xa1, 0xe0, 0x7f, 0x20, 0x40, 0xe0, 0x78, + 0xe4, 0xc2, 0x08, 0x46, 0x78, 0x49, 0x28, 0x45, 0x6e, 0x0e, 0x6f, 0xfa, + 0x00, 0x19, 0x01, 0x00, 0x7e, 0x0b, 0x6f, 0xfe, 0xa1, 0x40, 0xc0, 0xa5, + 0xa1, 0x40, 0xc4, 0xc6, 0xe4, 0xc2, 0x08, 0x46, 0x20, 0x40, 0x28, 0x45, + 0x04, 0x19, 0x03, 0x00, 0x4e, 0x0d, 0x6f, 0xfe, 0x00, 0x19, 0x01, 0x00, + 0xc0, 0xa5, 0xa1, 0x40, 0xc4, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0x08, 0x46, + 0x20, 0x40, 0x28, 0x45, 0x04, 0x19, 0x03, 0x00, 0x6a, 0x0d, 0x6f, 0xfe, + 0x00, 0x19, 0x01, 0x00, 0xc0, 0xa5, 0xa1, 0x40, 0xc4, 0xc6, 0xe0, 0x78, + 0xe4, 0xc2, 0x08, 0x46, 0x0c, 0x70, 0x38, 0x19, 0x02, 0x00, 0x04, 0xa9, + 0x00, 0xa1, 0x20, 0x40, 0x06, 0x0a, 0xaf, 0xfe, 0x28, 0x45, 0xc0, 0xa5, + 0xa1, 0x40, 0xc4, 0xc6, 0xe2, 0xc0, 0x4a, 0x24, 0xc0, 0x70, 0x46, 0xdd, + 0x4c, 0x70, 0xfa, 0xdc, 0x40, 0x21, 0x03, 0x04, 0x04, 0x19, 0x43, 0x00, + 0xa7, 0xa1, 0x40, 0xa1, 0x82, 0xa1, 0x43, 0xa1, 0xa8, 0x20, 0x00, 0x01, + 0x04, 0x1b, 0x11, 0x00, 0x00, 0xa1, 0x20, 0x40, 0xc2, 0xc4, 0xe0, 0x78, + 0xe4, 0xc2, 0x08, 0x46, 0x20, 0x40, 0x28, 0x45, 0x04, 0x19, 0x03, 0x00, + 0x26, 0x0a, 0xaf, 0xfe, 0x00, 0x19, 0x01, 0x00, 0xc0, 0xa5, 0xa1, 0x40, + 0xc4, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0x08, 0x46, 0x20, 0x40, 0x28, 0x45, + 0x16, 0x0b, 0xaf, 0xfe, 0x00, 0x19, 0x01, 0x00, 0xc0, 0xa5, 0xa1, 0x40, + 0xc4, 0xc6, 0xe0, 0x78, 0x6c, 0x70, 0xf5, 0x20, 0xc2, 0x00, 0x09, 0x0a, + 0x13, 0x00, 0x53, 0x7a, 0x14, 0x21, 0xcc, 0x00, 0x74, 0x71, 0x6c, 0x71, + 0x40, 0xb4, 0xf7, 0xf5, 0xe0, 0x7e, 0xe0, 0x78, 0xe6, 0xc1, 0xa6, 0xc1, + 0x80, 0x80, 0x01, 0x80, 0x48, 0x41, 0x44, 0xc4, 0x45, 0xc0, 0x80, 0x81, + 0x40, 0x81, 0x01, 0x81, 0x50, 0x24, 0xfe, 0x97, 0x42, 0xc2, 0x43, 0xc0, + 0x18, 0xf2, 0x04, 0x34, 0x80, 0x9f, 0x80, 0x3f, 0x00, 0x00, 0x14, 0xf2, + 0x4a, 0x20, 0x00, 0x00, 0x40, 0x24, 0x0b, 0x34, 0x15, 0x23, 0x02, 0x10, + 0xa0, 0x82, 0x14, 0x71, 0x0c, 0x71, 0x07, 0x35, 0x0d, 0x13, 0xa0, 0xa2, + 0xf8, 0xf5, 0x01, 0x81, 0x07, 0x30, 0x0d, 0x03, 0x43, 0xc5, 0x03, 0xf0, + 0x03, 0xc5, 0x4a, 0x24, 0xc0, 0x70, 0xed, 0x70, 0x84, 0xc6, 0x40, 0x24, + 0x06, 0x30, 0xe9, 0x43, 0xa8, 0x20, 0xc0, 0x08, 0xf0, 0x23, 0xc1, 0x02, + 0xf0, 0x21, 0xc8, 0x12, 0x0c, 0x70, 0x41, 0xc7, 0x40, 0xc1, 0x15, 0x26, + 0x0c, 0x00, 0x01, 0x4e, 0x40, 0x84, 0x14, 0x71, 0x00, 0x30, 0x41, 0x10, + 0x0c, 0x71, 0x01, 0x32, 0x41, 0x00, 0x20, 0xa4, 0xf5, 0xf5, 0x00, 0xc1, + 0x01, 0xc0, 0x15, 0x25, 0xc2, 0x02, 0x00, 0x35, 0x48, 0x10, 0x15, 0x24, + 0xcc, 0x02, 0x02, 0x30, 0x00, 0x02, 0x65, 0x71, 0x00, 0xa2, 0x20, 0xa4, + 0x41, 0xc0, 0xc6, 0xc5, 0xe6, 0xc3, 0xa5, 0xc1, 0x68, 0x45, 0x60, 0x83, + 0x28, 0x46, 0x14, 0xe3, 0x2b, 0x0a, 0xe4, 0x00, 0x00, 0x41, 0x80, 0xc0, + 0x14, 0xda, 0x56, 0x0a, 0x6f, 0xe7, 0x80, 0xc7, 0x4a, 0x24, 0x00, 0x75, + 0xa8, 0x20, 0x00, 0x02, 0x00, 0x85, 0x01, 0x17, 0x81, 0x14, 0xd8, 0x60, + 0xc5, 0x71, 0x20, 0xa8, 0x00, 0x85, 0x14, 0xe0, 0x00, 0xa5, 0xc6, 0xc7, + 0xed, 0x06, 0x0f, 0xf8, 0xf1, 0xc0, 0x00, 0x41, 0x01, 0x80, 0x84, 0x20, + 0x03, 0x0c, 0x13, 0x08, 0x30, 0x08, 0x90, 0xe0, 0x0c, 0x70, 0x08, 0xf4, + 0x00, 0x81, 0x9b, 0x5a, 0x04, 0xf0, 0x7a, 0x0f, 0x2f, 0xf8, 0x00, 0x81, + 0xd1, 0xc0, 0xe0, 0x7e, 0xe6, 0xc1, 0xa9, 0xc1, 0x80, 0x80, 0x68, 0x41, + 0x48, 0x40, 0x43, 0xc4, 0x61, 0x80, 0x42, 0x80, 0x00, 0x81, 0x44, 0xc3, + 0x45, 0xc2, 0x40, 0xc0, 0x60, 0x81, 0x41, 0x81, 0x02, 0x81, 0x50, 0x23, + 0xfe, 0x87, 0x41, 0xc2, 0x42, 0xc0, 0x1c, 0xf2, 0x7f, 0xda, 0x17, 0xba, + 0x04, 0x33, 0x80, 0x80, 0x16, 0xf2, 0x4a, 0x24, 0xc0, 0x70, 0x83, 0xc0, + 0xa8, 0x20, 0xc0, 0x01, 0x20, 0x80, 0x07, 0x31, 0xc1, 0x00, 0x04, 0x18, + 0x50, 0x00, 0x2c, 0x71, 0x80, 0xc0, 0x35, 0x78, 0x80, 0x80, 0x34, 0x72, + 0x2c, 0x72, 0x07, 0x34, 0xcc, 0x10, 0x80, 0xa0, 0xb8, 0xf7, 0x40, 0xc2, + 0x6d, 0x70, 0x6c, 0x70, 0x0c, 0x70, 0x14, 0x20, 0xc1, 0x00, 0xf0, 0x21, + 0x41, 0x10, 0x41, 0x68, 0x86, 0xc4, 0x15, 0x24, 0x8d, 0x10, 0x15, 0x24, + 0x0e, 0x10, 0x0c, 0x71, 0x20, 0xa5, 0xeb, 0x0a, 0xb4, 0x80, 0x00, 0x1e, + 0x40, 0x10, 0xf0, 0x20, 0xc6, 0x10, 0x4a, 0x24, 0xc0, 0x70, 0x83, 0xc1, + 0x20, 0x1c, 0xc0, 0x32, 0xa8, 0x20, 0xc0, 0x02, 0x04, 0x11, 0x00, 0x04, + 0x40, 0x84, 0x00, 0x36, 0x00, 0x00, 0x01, 0x32, 0x00, 0x00, 0x04, 0x1c, + 0x10, 0x10, 0x06, 0xc7, 0x4a, 0x20, 0x00, 0x00, 0x21, 0x68, 0x80, 0xc5, + 0x86, 0xc4, 0x25, 0x4d, 0x35, 0x7c, 0xc0, 0x84, 0x00, 0x35, 0xc6, 0x13, + 0x14, 0x20, 0xc2, 0x00, 0x02, 0x36, 0x8d, 0x11, 0x0c, 0x71, 0x15, 0x25, + 0x82, 0x00, 0xa0, 0xa4, 0xe1, 0x09, 0xb4, 0x80, 0xa0, 0xa2, 0x15, 0x24, + 0xc0, 0x00, 0x64, 0x71, 0x89, 0x0b, 0xf4, 0x80, 0xe0, 0xa0, 0xc6, 0xc5, + 0xe2, 0xc2, 0x28, 0x45, 0x20, 0x81, 0x40, 0x43, 0x14, 0xda, 0x19, 0x61, + 0xd6, 0x0e, 0x2f, 0xf5, 0x60, 0x40, 0x00, 0x85, 0x14, 0xe0, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0xe6, 0xc3, 0x82, 0x24, 0x06, 0x30, 0x68, 0x45, + 0x60, 0x83, 0x28, 0x46, 0x56, 0x23, 0x03, 0x0c, 0x2f, 0x0a, 0xe4, 0x00, + 0x00, 0x41, 0x80, 0xc0, 0x8a, 0x22, 0x06, 0x00, 0xf2, 0x08, 0x6f, 0xe7, + 0x80, 0xc7, 0x8a, 0x24, 0x06, 0x70, 0xa8, 0x20, 0x40, 0x02, 0x00, 0x85, + 0x01, 0x17, 0x81, 0x14, 0xd8, 0x60, 0xc5, 0x71, 0x20, 0xa8, 0x00, 0x85, + 0x56, 0x20, 0x00, 0x0c, 0x00, 0xa5, 0xc6, 0xc7, 0xe2, 0xc2, 0x08, 0x45, + 0x04, 0x71, 0xf2, 0x0b, 0x2f, 0xf2, 0x0f, 0x78, 0x10, 0xd9, 0xa1, 0x40, + 0x0c, 0x58, 0xc3, 0x40, 0xa0, 0x00, 0xf0, 0x86, 0x20, 0x80, 0xc3, 0x40, + 0x12, 0x00, 0x98, 0xbb, 0x09, 0x09, 0x20, 0x00, 0xb5, 0x71, 0xc2, 0xc6, + 0x60, 0xd8, 0xca, 0x20, 0x21, 0x06, 0xb5, 0x70, 0xca, 0x20, 0xa1, 0x01, + 0x0f, 0x58, 0xc2, 0xc6, 0xe6, 0xc2, 0x48, 0x45, 0x28, 0x46, 0xfe, 0x0c, + 0x6f, 0xf2, 0x08, 0x47, 0x14, 0x70, 0x0c, 0x70, 0x26, 0xf2, 0x8c, 0xd8, + 0x5f, 0x27, 0x01, 0x17, 0xea, 0x78, 0x30, 0x21, 0x82, 0x0f, 0xa0, 0x00, + 0xa8, 0x4d, 0x30, 0x20, 0x80, 0x0f, 0xa0, 0x00, 0x10, 0x4a, 0x50, 0x70, + 0x0c, 0x71, 0xd8, 0xf7, 0x80, 0x85, 0x2d, 0x0c, 0x85, 0x10, 0x5f, 0x27, + 0x01, 0x1f, 0x30, 0x21, 0x83, 0x0f, 0xa0, 0x00, 0xcc, 0x4c, 0x99, 0x62, + 0x0a, 0xe1, 0x19, 0x09, 0xe5, 0x00, 0x6c, 0x24, 0x41, 0x10, 0x40, 0x86, + 0x59, 0x61, 0x00, 0x19, 0x01, 0x00, 0x20, 0x85, 0x24, 0x74, 0x20, 0xa5, + 0xc6, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0x28, 0x45, 0x20, 0x81, 0x40, 0x43, + 0x14, 0xda, 0x19, 0x61, 0xe2, 0x0d, 0x2f, 0xf5, 0x60, 0x40, 0x00, 0x85, + 0x14, 0xe0, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0xe6, 0xc3, 0x82, 0x24, + 0x06, 0x30, 0x68, 0x45, 0x60, 0x83, 0x28, 0x46, 0x56, 0x23, 0x03, 0x0c, + 0x2f, 0x0a, 0xe4, 0x00, 0x00, 0x41, 0x80, 0xc0, 0x8a, 0x22, 0x06, 0x00, + 0xfe, 0x0f, 0x2f, 0xe7, 0x80, 0xc7, 0x8a, 0x24, 0x06, 0x70, 0xa8, 0x20, + 0x40, 0x02, 0x00, 0x85, 0x01, 0x17, 0x81, 0x14, 0xd8, 0x60, 0xc5, 0x71, + 0x20, 0xa8, 0x00, 0x85, 0x56, 0x20, 0x00, 0x0c, 0x00, 0xa5, 0xc6, 0xc7, + 0xe2, 0xc0, 0x08, 0x44, 0x14, 0x70, 0x1c, 0xd8, 0x2a, 0xf2, 0x2a, 0xe9, + 0x60, 0x91, 0xe1, 0xd8, 0x4d, 0x0b, 0x81, 0x0f, 0x00, 0x00, 0x2b, 0x66, + 0x76, 0x81, 0xb6, 0x84, 0x41, 0x0b, 0x41, 0x03, 0xa1, 0x94, 0x0d, 0x0d, + 0xde, 0x11, 0x39, 0x0b, 0x34, 0x04, 0x70, 0xbb, 0x80, 0x23, 0x3e, 0x01, + 0x2d, 0x0b, 0x84, 0x00, 0x41, 0x91, 0x29, 0x0a, 0x41, 0x03, 0x62, 0x94, + 0x42, 0x91, 0x21, 0x0a, 0xc1, 0x00, 0x63, 0x94, 0x43, 0x91, 0x19, 0x0a, + 0xc1, 0x00, 0x78, 0x84, 0x58, 0x81, 0x11, 0x0a, 0xc1, 0x00, 0x59, 0x84, + 0x39, 0x81, 0x09, 0x09, 0x81, 0x00, 0x0c, 0x70, 0xc2, 0xc4, 0xe0, 0x78, + 0xe2, 0xc2, 0x08, 0x45, 0x14, 0x70, 0x1c, 0xd8, 0x1a, 0xf2, 0x20, 0x95, + 0x31, 0x09, 0x81, 0x0f, 0x00, 0x00, 0x2b, 0x66, 0x5e, 0x85, 0x78, 0xd9, + 0xda, 0x0d, 0xaf, 0xea, 0xa1, 0x40, 0x14, 0x70, 0x1d, 0xd8, 0x0e, 0xf2, + 0x1b, 0x85, 0x56, 0x85, 0x0a, 0xb8, 0x10, 0x72, 0xe1, 0xd8, 0x08, 0xf7, + 0x38, 0x85, 0x80, 0x22, 0x3e, 0x09, 0x09, 0x0a, 0x44, 0x00, 0x0c, 0x70, + 0xc2, 0xc6, 0xe0, 0x78, 0xe8, 0xc2, 0xcb, 0x45, 0x12, 0x00, 0x00, 0x40, + 0x2d, 0x0d, 0x81, 0x1f, 0x12, 0x00, 0x00, 0x40, 0x2c, 0x70, 0xed, 0x71, + 0x17, 0x69, 0x00, 0x20, 0x8e, 0x0f, 0xa0, 0x00, 0xe0, 0x5e, 0x00, 0x96, + 0x35, 0x08, 0x80, 0x0f, 0x00, 0x00, 0x2b, 0x66, 0x01, 0x69, 0xed, 0x08, + 0xb4, 0x80, 0x2c, 0x71, 0xcd, 0x70, 0x12, 0xf0, 0x38, 0x25, 0x81, 0x1f, + 0x20, 0x00, 0x00, 0x70, 0x38, 0x25, 0x80, 0x1f, 0x20, 0x00, 0x00, 0x20, + 0x25, 0x78, 0x0f, 0x08, 0x71, 0x00, 0xcd, 0x70, 0xcb, 0x46, 0x12, 0x00, + 0x84, 0x3f, 0xed, 0x70, 0x6e, 0x0f, 0xef, 0xff, 0xc1, 0x40, 0xc3, 0x08, + 0x11, 0x00, 0xc3, 0x41, 0x13, 0x00, 0x70, 0x9d, 0xb2, 0x49, 0xfe, 0x0e, + 0xef, 0xff, 0xc1, 0x40, 0xaf, 0x08, 0x11, 0x00, 0x0a, 0x09, 0x00, 0x00, + 0x4e, 0x0f, 0xef, 0xff, 0x08, 0x45, 0xa3, 0x08, 0x11, 0x00, 0x01, 0x96, + 0x2d, 0x08, 0x5e, 0x00, 0x97, 0x08, 0xbe, 0x00, 0x16, 0xd8, 0x16, 0x85, + 0x2c, 0x77, 0x41, 0x28, 0xbc, 0x80, 0x0a, 0xf2, 0x54, 0x25, 0x80, 0x1f, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x02, 0x04, 0x06, 0x39, 0x81, 0x00, + 0x17, 0x85, 0x77, 0x08, 0x61, 0x00, 0x13, 0xd8, 0x7c, 0x15, 0x0b, 0x10, + 0x00, 0x23, 0x40, 0x13, 0x54, 0x20, 0x81, 0x0f, 0xa1, 0x40, 0xaa, 0x0e, + 0xef, 0xff, 0x61, 0x42, 0xad, 0xe8, 0x54, 0x25, 0x82, 0x1f, 0x54, 0x23, + 0x83, 0x1f, 0xc1, 0x40, 0x1e, 0x0e, 0x2f, 0xf8, 0xa1, 0x41, 0x10, 0x40, + 0x00, 0x16, 0x00, 0x70, 0xa0, 0x00, 0xd8, 0x5e, 0x2c, 0x70, 0xa2, 0x0c, + 0x2f, 0xf5, 0x80, 0xda, 0xda, 0x0e, 0xe0, 0x00, 0xa1, 0x40, 0x99, 0xe8, + 0x16, 0xef, 0x36, 0x85, 0x16, 0x86, 0x16, 0x70, 0xc2, 0x21, 0x22, 0x04, + 0x38, 0x60, 0x00, 0x20, 0x8e, 0x0f, 0x12, 0x00, 0x7c, 0x40, 0x02, 0x26, + 0x0d, 0x70, 0xed, 0xff, 0x85, 0xbf, 0x2e, 0x09, 0xcf, 0xed, 0x1a, 0x65, + 0x2c, 0x70, 0x6e, 0x0c, 0x2f, 0xf5, 0xc1, 0x40, 0xc8, 0xc6, 0x7a, 0x0f, + 0xaf, 0xec, 0x2c, 0x71, 0xe2, 0xc2, 0x28, 0x45, 0x20, 0x81, 0x40, 0x43, + 0x8a, 0x22, 0x06, 0x00, 0x19, 0x61, 0xc6, 0x0b, 0x2f, 0xf5, 0x60, 0x40, + 0x00, 0x85, 0x56, 0x20, 0x00, 0x0c, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0xe2, 0xc1, 0x80, 0x83, 0x85, 0x74, 0x29, 0x0a, 0x24, 0x03, 0xa1, 0xc1, + 0x4a, 0x24, 0x00, 0x71, 0x40, 0xc0, 0x0c, 0x70, 0xa8, 0x20, 0x40, 0x02, + 0xa0, 0x83, 0x80, 0xc2, 0x0c, 0x62, 0x04, 0x71, 0xba, 0x61, 0x24, 0x71, + 0x80, 0xaa, 0x00, 0x83, 0x04, 0x74, 0x00, 0xa3, 0xc2, 0xc5, 0xe0, 0x78, + 0xf5, 0x02, 0xef, 0xf2, 0xc0, 0xd8, 0xe0, 0x78, 0xc3, 0x40, 0x13, 0x00, + 0x90, 0xa9, 0xe0, 0x7e, 0x4a, 0x21, 0x00, 0x00, 0x01, 0x10, 0x82, 0x04, + 0x81, 0x69, 0x20, 0x43, 0x54, 0x70, 0xca, 0x23, 0x01, 0x03, 0x0b, 0x0b, + 0xb3, 0x0b, 0x81, 0x41, 0x76, 0xea, 0x79, 0x22, 0x01, 0x00, 0x7a, 0x23, + 0x80, 0x0b, 0xe0, 0x7f, 0x25, 0x78, 0xe0, 0x78, 0xe2, 0xc2, 0x06, 0x0c, + 0xef, 0xf2, 0x08, 0x45, 0x8c, 0x25, 0x83, 0x9f, 0x0c, 0xf2, 0x8c, 0x25, + 0x83, 0x9e, 0x12, 0xf2, 0x8c, 0x25, 0xc3, 0x9e, 0x0c, 0xf2, 0x8c, 0x25, + 0x43, 0x9e, 0x0f, 0xf4, 0x0c, 0x73, 0x0b, 0xf0, 0x0a, 0x0c, 0x2f, 0xe9, + 0x0c, 0x73, 0x06, 0x0c, 0x2f, 0xe9, 0x0c, 0x72, 0x0c, 0x71, 0x03, 0xf0, + 0x0c, 0x72, 0xfa, 0x0b, 0x0f, 0xe9, 0xc2, 0xc6, 0xe2, 0xc2, 0x28, 0x45, + 0x20, 0x81, 0x40, 0x43, 0x8a, 0x22, 0x06, 0x00, 0x19, 0x61, 0x02, 0x0b, + 0x2f, 0xf5, 0x60, 0x40, 0x00, 0x85, 0x56, 0x20, 0x00, 0x0c, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0xe2, 0xc0, 0xa0, 0x83, 0x81, 0x6d, 0x11, 0x0a, + 0x24, 0x03, 0xb9, 0x61, 0x00, 0xa9, 0x00, 0x83, 0x04, 0x71, 0x00, 0xa3, + 0xc2, 0xc4, 0xe0, 0x78, 0x42, 0x22, 0x3c, 0x80, 0xe0, 0x7c, 0x40, 0x21, + 0x43, 0x06, 0xa8, 0x20, 0x00, 0x03, 0x07, 0x13, 0x01, 0x00, 0x0d, 0x09, + 0x01, 0x00, 0x20, 0x8b, 0x87, 0xb9, 0x20, 0xab, 0x55, 0x23, 0x03, 0x08, + 0xe0, 0x7e, 0xe0, 0x78, 0x14, 0x70, 0xe0, 0x7c, 0x39, 0x88, 0x87, 0xb9, + 0x39, 0xa8, 0x00, 0x80, 0xfc, 0xe8, 0xe0, 0x7e, 0xe8, 0xc3, 0xa1, 0xc1, + 0xc3, 0x41, 0xa0, 0x00, 0xfc, 0x86, 0x00, 0x89, 0x04, 0xe8, 0x00, 0x19, + 0x03, 0x00, 0x91, 0x5a, 0x8a, 0x20, 0x42, 0x2c, 0xcb, 0x47, 0xf0, 0x00, + 0x4b, 0x00, 0xcb, 0x46, 0x00, 0x00, 0xfc, 0x7f, 0x0c, 0x70, 0xc3, 0x41, + 0x00, 0x00, 0xff, 0xff, 0x80, 0xc2, 0x0a, 0x0e, 0x6f, 0xf7, 0x6c, 0x77, + 0x00, 0xc0, 0x78, 0xe8, 0xad, 0x70, 0x5a, 0xd9, 0x00, 0x1f, 0x02, 0x14, + 0xab, 0x21, 0x08, 0x0e, 0x0e, 0xf0, 0x0b, 0x09, 0x50, 0x00, 0x05, 0xe9, + 0x16, 0xf0, 0x60, 0x58, 0x06, 0xe8, 0xc3, 0x40, 0xa0, 0x00, 0xf4, 0x86, + 0x00, 0x80, 0x40, 0x78, 0x00, 0xc0, 0x0e, 0xf0, 0x19, 0x08, 0x6e, 0x03, + 0xaf, 0x79, 0x4a, 0x69, 0xdf, 0x0a, 0x55, 0x83, 0xc4, 0x78, 0x9a, 0x5a, + 0x00, 0xc1, 0xd2, 0x78, 0x24, 0x78, 0x40, 0xc0, 0xa5, 0x71, 0xad, 0x0d, + 0x15, 0x94, 0xf2, 0xe8, 0xd2, 0xf1, 0xe0, 0x78, 0xf1, 0xc0, 0x04, 0x77, + 0x0f, 0x78, 0x04, 0xe9, 0x21, 0x58, 0x03, 0xf0, 0x1d, 0x58, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0x2f, 0x7b, 0x8c, 0xd8, 0x6a, 0x78, + 0x00, 0x20, 0x80, 0x0f, 0xa0, 0x00, 0x25, 0x4a, 0x2f, 0x27, 0xbf, 0x00, + 0x6f, 0x23, 0x3f, 0x00, 0x6f, 0x26, 0x3f, 0x04, 0x20, 0x88, 0x00, 0x18, + 0xc3, 0x0f, 0x2f, 0x26, 0xbf, 0x00, 0x8c, 0x21, 0xc3, 0x8f, 0x07, 0xf2, + 0xf0, 0x26, 0xc0, 0x70, 0x13, 0x00, 0x4c, 0x90, 0x8c, 0x58, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xe2, 0xc2, 0x4d, 0x08, 0xd1, 0x01, 0xc3, 0x40, + 0xf0, 0x00, 0x5b, 0x00, 0xa0, 0x88, 0x20, 0x88, 0xe0, 0x78, 0xfd, 0x0d, + 0x41, 0x90, 0xc3, 0x40, 0xa0, 0x00, 0xb2, 0x41, 0x20, 0x88, 0x35, 0x0d, + 0x40, 0x10, 0xa0, 0xa8, 0xb2, 0x0a, 0xaf, 0xe6, 0xa1, 0x40, 0x12, 0x0f, + 0xaf, 0xec, 0xa1, 0x40, 0xcb, 0x45, 0xf0, 0x00, 0x47, 0x00, 0x32, 0x0c, + 0xaf, 0xe6, 0x00, 0x8d, 0x0b, 0xe8, 0x00, 0x8d, 0x00, 0x16, 0x01, 0x70, + 0xa0, 0x00, 0xf8, 0x86, 0x40, 0x79, 0x07, 0xf0, 0x22, 0x0d, 0x0f, 0xf3, + 0xc2, 0xc6, 0x0c, 0x70, 0x0f, 0x58, 0xc3, 0x40, 0xa0, 0x00, 0xa0, 0x42, + 0x20, 0x88, 0x2f, 0x27, 0xff, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xc3, 0x42, + 0xf0, 0x00, 0x50, 0x02, 0x00, 0x82, 0x10, 0x20, 0x40, 0x00, 0x00, 0xa2, + 0x2f, 0x26, 0xff, 0x00, 0xc2, 0xc6, 0xe0, 0x78, 0xe0, 0x7f, 0x00, 0xa1, + 0x40, 0x81, 0x02, 0xa1, 0x54, 0x70, 0xe0, 0x7c, 0x21, 0x81, 0x00, 0x7a, + 0xe2, 0xc3, 0xa3, 0xc1, 0x08, 0xb8, 0x8f, 0xb8, 0x97, 0xb8, 0x88, 0x45, + 0xff, 0xdc, 0xc3, 0x44, 0x13, 0x00, 0xc8, 0x4d, 0x40, 0x24, 0x05, 0x32, + 0xcc, 0x70, 0x98, 0xb8, 0x42, 0xc4, 0x22, 0x0a, 0x6f, 0xf3, 0x40, 0xc5, + 0x8e, 0x09, 0x2f, 0xf8, 0x82, 0xc1, 0xc2, 0xc7, 0xe2, 0xc3, 0xa3, 0xc1, + 0x08, 0xb8, 0x97, 0xb8, 0x88, 0x45, 0xff, 0xdc, 0xc3, 0x44, 0x13, 0x00, + 0xc8, 0x4d, 0x40, 0x24, 0x05, 0x32, 0xcc, 0x70, 0x98, 0xb8, 0x42, 0xc4, + 0xf6, 0x09, 0x6f, 0xf3, 0x40, 0xc5, 0x66, 0x09, 0x2f, 0xf8, 0x82, 0xc1, + 0xc2, 0xc7, 0xe0, 0x78, 0x4a, 0x22, 0x40, 0x00, 0x02, 0x10, 0x01, 0x05, + 0x79, 0x21, 0x03, 0x00, 0x71, 0x4a, 0x0b, 0x09, 0xf3, 0x00, 0x44, 0x71, + 0x78, 0xeb, 0x7a, 0x21, 0xc0, 0x00, 0xe0, 0x7f, 0x65, 0x78, 0xe0, 0x78, + 0xe4, 0xc3, 0xa1, 0xc1, 0xa0, 0x81, 0x28, 0x46, 0x4c, 0x74, 0xb9, 0x60, + 0x06, 0x0b, 0x2f, 0xe7, 0x80, 0xc0, 0x00, 0xc0, 0x24, 0x6d, 0x20, 0xa6, + 0xc4, 0xc7, 0xe0, 0x78, 0xe6, 0xc3, 0xaa, 0xc1, 0x68, 0x45, 0x60, 0x83, + 0x28, 0x46, 0x28, 0xe3, 0x2b, 0x0a, 0xe4, 0x00, 0x00, 0x41, 0x80, 0xc0, + 0x28, 0xda, 0xe2, 0x0a, 0x2f, 0xe7, 0x80, 0xc7, 0x4a, 0x24, 0x00, 0x7a, + 0xa8, 0x20, 0x00, 0x02, 0x00, 0x85, 0x01, 0x17, 0x81, 0x14, 0xd8, 0x60, + 0xc5, 0x71, 0x20, 0xa8, 0x00, 0x85, 0x28, 0xe0, 0x00, 0xa5, 0xc6, 0xc7, + 0xe2, 0xc2, 0xc3, 0x42, 0xa0, 0x00, 0xae, 0x4a, 0xff, 0xd8, 0xcb, 0x44, + 0xa0, 0x00, 0x22, 0x4a, 0xc3, 0x41, 0xa0, 0x00, 0x3a, 0x4b, 0xf5, 0xdd, + 0xfb, 0xdb, 0x03, 0xaa, 0x03, 0xac, 0x03, 0xa9, 0xa0, 0xac, 0x60, 0xaa, + 0xfa, 0x0b, 0x6f, 0xf3, 0x60, 0xa9, 0xc3, 0x41, 0xa0, 0x00, 0x04, 0x42, + 0x00, 0x19, 0x80, 0x0f, 0x13, 0x00, 0x4c, 0x4d, 0xc2, 0xc6, 0xe0, 0x78, + 0xf1, 0xc0, 0x00, 0x16, 0x02, 0x70, 0xa0, 0x00, 0xc8, 0x87, 0xc3, 0x40, + 0x13, 0x00, 0x78, 0x4c, 0xc3, 0x41, 0x13, 0x00, 0x5c, 0x90, 0x6c, 0x70, + 0xc3, 0x45, 0xa1, 0x00, 0x7c, 0x1b, 0xc3, 0x46, 0xa0, 0x00, 0x08, 0xe9, + 0x12, 0x0a, 0xef, 0xf8, 0x8a, 0x24, 0x82, 0x00, 0x00, 0x1e, 0x00, 0x70, + 0xa0, 0x00, 0x00, 0x87, 0xd1, 0xc0, 0xe0, 0x7e, 0xe4, 0xc2, 0xc3, 0x40, + 0xf0, 0x00, 0x3e, 0x00, 0x20, 0x88, 0x81, 0xb9, 0x20, 0xa8, 0x00, 0x16, + 0x80, 0x70, 0xf0, 0x00, 0x0c, 0x01, 0x1b, 0x08, 0x3e, 0x01, 0xad, 0x70, + 0x2e, 0x0c, 0x8f, 0xf8, 0x08, 0x45, 0x29, 0x68, 0x0c, 0x70, 0x97, 0xb8, + 0x10, 0x71, 0xca, 0x25, 0x06, 0x10, 0x1a, 0x0d, 0x8f, 0xed, 0x02, 0x0d, + 0xaf, 0xed, 0x08, 0x46, 0x00, 0x41, 0xa1, 0x42, 0x06, 0x0f, 0x6f, 0xf8, + 0xc1, 0x40, 0xa6, 0x0a, 0xcf, 0xf6, 0x0c, 0x70, 0xc4, 0xc6, 0xe0, 0x78, + 0xe4, 0xc3, 0xa2, 0xc1, 0xcb, 0x45, 0xa0, 0x00, 0x64, 0xe7, 0x0c, 0x71, + 0x3a, 0x0c, 0x2f, 0xf7, 0x9c, 0x4d, 0x00, 0x16, 0x02, 0x70, 0xa0, 0x00, + 0xd0, 0x87, 0xcb, 0x46, 0xa0, 0x00, 0xe0, 0x86, 0x00, 0xa6, 0x54, 0x25, + 0x86, 0x1a, 0xc3, 0x40, 0x13, 0x00, 0x34, 0x64, 0xc3, 0x41, 0x13, 0x00, + 0x37, 0x90, 0x6c, 0x70, 0xc3, 0x45, 0xa1, 0x00, 0x7c, 0x11, 0x7a, 0x09, + 0xef, 0xf8, 0x8a, 0x24, 0xc2, 0x00, 0x01, 0xa6, 0x4a, 0x26, 0x00, 0x10, + 0xc3, 0x40, 0x69, 0x72, 0x4e, 0x56, 0x40, 0xc0, 0x74, 0xd8, 0x04, 0x1c, + 0x04, 0x30, 0x6a, 0x4e, 0x60, 0xc0, 0x54, 0xd8, 0xcc, 0x78, 0xf0, 0x26, + 0x82, 0x73, 0xa0, 0x00, 0xd4, 0x87, 0xf0, 0x26, 0x85, 0x73, 0xa0, 0x00, + 0xe0, 0x87, 0x55, 0x25, 0x81, 0x1a, 0x00, 0x20, 0x46, 0x00, 0x62, 0x6e, + 0x4e, 0x26, 0xc4, 0x11, 0xc3, 0x40, 0x13, 0x00, 0x24, 0x6a, 0x32, 0x09, + 0xef, 0xf8, 0x80, 0xc1, 0x15, 0x25, 0x81, 0x13, 0xc5, 0x71, 0xbd, 0x0e, + 0xf4, 0x90, 0x00, 0xa1, 0xc4, 0xc7, 0xe0, 0x78, 0xf2, 0xc2, 0x70, 0x42, + 0x50, 0x45, 0x30, 0x43, 0x08, 0x46, 0xcb, 0x47, 0xf0, 0x00, 0x34, 0x00, + 0x97, 0xd8, 0x34, 0x70, 0x06, 0x01, 0x21, 0x00, 0x17, 0xaf, 0x2e, 0x70, + 0x8a, 0x24, 0x03, 0x20, 0x32, 0x40, 0x1a, 0x20, 0x0d, 0x25, 0xdd, 0x65, + 0x32, 0x15, 0xc1, 0x10, 0x29, 0x09, 0x32, 0x00, 0x53, 0x21, 0x00, 0x01, + 0x21, 0x08, 0x75, 0x06, 0x25, 0xb9, 0x53, 0x21, 0x42, 0x00, 0x36, 0x0c, + 0xaf, 0xf3, 0xa1, 0x41, 0x32, 0x15, 0x81, 0x10, 0x0c, 0x71, 0xc3, 0x42, + 0xf0, 0x00, 0x60, 0x02, 0x38, 0x78, 0x00, 0xa2, 0x08, 0x85, 0x84, 0x20, + 0x03, 0x0c, 0xa0, 0xe0, 0x56, 0x00, 0x22, 0x00, 0x8d, 0x71, 0x2e, 0x15, + 0x80, 0x10, 0x2f, 0x15, 0x82, 0x10, 0x00, 0x2c, 0x01, 0x10, 0x2f, 0x27, + 0xff, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xc3, 0x40, 0xf0, 0x00, 0x40, 0x02, + 0x11, 0x0a, 0x10, 0x00, 0x45, 0x80, 0x26, 0x7a, 0x45, 0xa0, 0x2f, 0x26, + 0xff, 0x00, 0x07, 0xf0, 0x45, 0x80, 0x45, 0x79, 0x25, 0xa0, 0x2f, 0x26, + 0xff, 0x00, 0x2e, 0x15, 0x82, 0x10, 0x58, 0x7c, 0x86, 0xa0, 0x2f, 0x27, + 0xff, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0x24, 0x80, 0x10, 0x21, 0x81, 0x00, + 0x24, 0xa0, 0x2f, 0x26, 0xff, 0x00, 0x06, 0x71, 0x0c, 0x20, 0xc0, 0xa4, + 0x6a, 0x07, 0xc5, 0xff, 0x6f, 0x26, 0xff, 0x05, 0x98, 0xd8, 0xad, 0x70, + 0x17, 0xaf, 0x5a, 0xd9, 0x0c, 0x70, 0xab, 0x21, 0x08, 0x0e, 0xaa, 0x1e, + 0x02, 0x10, 0xad, 0x1e, 0x02, 0x10, 0xaf, 0x1e, 0x02, 0x10, 0xb2, 0x0b, + 0x6f, 0xf3, 0xc1, 0x40, 0x25, 0x08, 0xb4, 0x00, 0x08, 0x43, 0x00, 0x86, + 0x86, 0x0b, 0xef, 0xff, 0x07, 0x1e, 0x43, 0x10, 0xc1, 0x40, 0xa2, 0x41, + 0x56, 0x0b, 0xef, 0xff, 0x42, 0x42, 0x18, 0x8e, 0x0a, 0x21, 0xc0, 0x22, + 0x16, 0xaf, 0x07, 0xf0, 0x32, 0x16, 0x80, 0x10, 0x8e, 0x09, 0x2f, 0xf2, + 0xc4, 0xb8, 0xa5, 0x71, 0xb7, 0x0d, 0xe4, 0x94, 0x55, 0x26, 0x0e, 0x1c, + 0x06, 0xf0, 0x6f, 0x26, 0xff, 0x05, 0x98, 0xd8, 0x2e, 0x70, 0x17, 0xaf, + 0x99, 0xd8, 0x35, 0x0a, 0x30, 0x20, 0x17, 0xaf, 0xcd, 0x70, 0xb7, 0x6e, + 0xa2, 0x75, 0xa1, 0x40, 0xd6, 0x0c, 0x6f, 0xf3, 0x3a, 0x1d, 0x05, 0x10, + 0x17, 0x08, 0xb4, 0x00, 0x00, 0x42, 0xa1, 0x40, 0x2a, 0x0b, 0xef, 0xff, + 0x07, 0x1d, 0x43, 0x10, 0x18, 0x8d, 0x50, 0x41, 0x16, 0xaf, 0xc5, 0x71, + 0xdb, 0x0e, 0x84, 0x94, 0x9a, 0xd8, 0x5a, 0xd9, 0x17, 0xaf, 0x2f, 0x20, + 0x47, 0x04, 0xab, 0x21, 0x08, 0x0e, 0xd2, 0xc6, 0xe2, 0xc2, 0x28, 0x45, + 0x20, 0x81, 0x40, 0x43, 0x28, 0xda, 0x19, 0x61, 0xaa, 0x0d, 0xef, 0xf4, + 0x60, 0x40, 0x00, 0x85, 0x28, 0xe0, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0x48, 0x81, 0x23, 0x92, 0x0b, 0x08, 0x44, 0x00, 0x24, 0x92, 0x09, 0x21, + 0x01, 0x00, 0xe0, 0x7f, 0x20, 0x40, 0xe0, 0x78, 0xf6, 0xc3, 0xa3, 0xc1, + 0x50, 0x47, 0x30, 0x44, 0x2a, 0x08, 0xef, 0xf3, 0x08, 0x45, 0xd3, 0x42, + 0x00, 0x00, 0xff, 0xff, 0x8f, 0x08, 0xa0, 0x04, 0x10, 0x41, 0x0e, 0x70, + 0xd3, 0x45, 0x00, 0x00, 0xef, 0xff, 0x40, 0x24, 0x16, 0x30, 0x4a, 0x47, + 0x08, 0x8d, 0x4d, 0x08, 0x25, 0x20, 0xf0, 0x7e, 0x03, 0x85, 0xf0, 0x20, + 0x0e, 0x04, 0x07, 0x86, 0x0b, 0x08, 0xf1, 0x00, 0xc1, 0x40, 0xe6, 0x08, + 0xcf, 0xf4, 0x17, 0x0d, 0x64, 0x24, 0x0a, 0x23, 0x80, 0x24, 0x22, 0x40, + 0xc1, 0x41, 0x23, 0x20, 0x00, 0x05, 0xe2, 0x42, 0x10, 0x43, 0xc1, 0x40, + 0x7e, 0x0a, 0xef, 0xf4, 0x62, 0x41, 0x14, 0x26, 0x00, 0x24, 0x00, 0x18, + 0xc4, 0x04, 0xf0, 0x78, 0x9a, 0x0e, 0xaf, 0xf3, 0x62, 0x41, 0x08, 0x47, + 0x06, 0x71, 0xdc, 0xf1, 0x10, 0x85, 0x85, 0x0d, 0xa4, 0x23, 0xe0, 0xb0, + 0x47, 0x85, 0x05, 0xea, 0x80, 0xc1, 0x60, 0x7a, 0xa1, 0x40, 0x69, 0x85, + 0x05, 0xeb, 0x80, 0xc2, 0xc1, 0x41, 0x60, 0x7b, 0xa1, 0x40, 0x92, 0x0e, + 0xaf, 0xf3, 0xa1, 0x40, 0x10, 0x85, 0x21, 0x90, 0x80, 0xb9, 0x21, 0xb0, + 0xd6, 0xc7, 0x08, 0x8d, 0x11, 0xe8, 0xed, 0x70, 0x40, 0x24, 0x10, 0x30, + 0x4a, 0x26, 0x00, 0x10, 0x03, 0x85, 0xe0, 0x60, 0x23, 0x80, 0x40, 0x79, + 0x08, 0x8d, 0xc5, 0x71, 0x02, 0x18, 0xd5, 0x2f, 0xf1, 0x0e, 0x24, 0x90, + 0xe5, 0x74, 0x69, 0x85, 0x10, 0x85, 0x00, 0x18, 0x84, 0x04, 0x06, 0xeb, + 0x80, 0xc2, 0x42, 0x41, 0x60, 0x7b, 0xa1, 0x40, 0x09, 0x8d, 0x10, 0xe8, + 0xcd, 0x70, 0xed, 0x70, 0x04, 0x85, 0xc3, 0x41, 0x00, 0x00, 0xff, 0xff, + 0x16, 0x09, 0x2f, 0xf4, 0xc0, 0x60, 0x09, 0x8d, 0xe5, 0x71, 0xf1, 0x0f, + 0x24, 0x90, 0xc5, 0x74, 0xd6, 0xc7, 0xe0, 0x78, 0xf1, 0xc0, 0x88, 0x81, + 0x62, 0x8c, 0x0f, 0x0b, 0x9e, 0x01, 0x65, 0x94, 0x64, 0x7a, 0x17, 0x0a, + 0xc1, 0x00, 0xc3, 0x42, 0x00, 0x00, 0xff, 0xff, 0x19, 0x08, 0x80, 0x00, + 0x87, 0xe8, 0x43, 0x94, 0x08, 0xf0, 0xc3, 0x42, 0x00, 0x00, 0xff, 0xff, + 0x04, 0xf0, 0xca, 0x0e, 0xcf, 0xff, 0x00, 0x42, 0xd1, 0xc0, 0xe0, 0x7f, + 0x50, 0x78, 0xe0, 0x78, 0xe2, 0xc2, 0x88, 0x81, 0xa1, 0x94, 0x0f, 0x0d, + 0x9e, 0x11, 0x65, 0x94, 0x64, 0x7a, 0x1b, 0x0a, 0xc1, 0x00, 0xc3, 0x42, + 0x00, 0x00, 0xff, 0xff, 0x1d, 0x08, 0x80, 0x00, 0x03, 0xe8, 0x13, 0x0d, + 0x1f, 0x11, 0x44, 0x94, 0x08, 0xf0, 0xc3, 0x42, 0x00, 0x00, 0xff, 0xff, + 0x04, 0xf0, 0x8e, 0x0e, 0xcf, 0xff, 0x00, 0x42, 0x50, 0x78, 0xc2, 0xc6, + 0xf1, 0xc0, 0x88, 0x81, 0x62, 0x8c, 0x0f, 0x0b, 0x9e, 0x01, 0x65, 0x94, + 0x64, 0x7a, 0x17, 0x0a, 0xc1, 0x00, 0xc3, 0x42, 0x00, 0x00, 0xff, 0xff, + 0x19, 0x08, 0x80, 0x00, 0x87, 0xe8, 0x44, 0x94, 0x08, 0xf0, 0xc3, 0x42, + 0x00, 0x00, 0xff, 0xff, 0x04, 0xf0, 0x5a, 0x0e, 0xcf, 0xff, 0x00, 0x42, + 0xd1, 0xc0, 0xe0, 0x7f, 0x50, 0x78, 0xe0, 0x78, 0xe6, 0xc0, 0x64, 0x80, + 0x8d, 0x70, 0x41, 0xa3, 0x08, 0x8b, 0x2d, 0x0c, 0x05, 0x10, 0x03, 0x8b, + 0x10, 0xe8, 0x1a, 0x24, 0x0d, 0x10, 0x4c, 0x70, 0xc6, 0x83, 0x47, 0x49, + 0x44, 0x71, 0xb5, 0x7e, 0x00, 0x86, 0x01, 0x37, 0x00, 0x10, 0x00, 0xa6, + 0x03, 0x8b, 0xf1, 0x0a, 0x24, 0x80, 0xa5, 0x71, 0x85, 0x71, 0xec, 0xf1, + 0xc6, 0xc4, 0xe0, 0x78, 0xe6, 0xc2, 0xa4, 0x80, 0x08, 0x46, 0x00, 0x95, + 0x9b, 0x08, 0x85, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0x9f, 0x08, 0x30, 0x00, + 0xc1, 0x40, 0xd6, 0x09, 0x00, 0x00, 0x23, 0x85, 0x1c, 0x15, 0x08, 0x10, + 0x6c, 0x70, 0x68, 0x43, 0x02, 0x8e, 0x85, 0x0b, 0x05, 0x00, 0x02, 0x86, + 0x64, 0x48, 0x08, 0x84, 0x40, 0x90, 0x6f, 0x0a, 0x80, 0x0f, 0x00, 0x00, + 0xff, 0xff, 0x04, 0x86, 0x2f, 0x21, 0xc7, 0x12, 0x0a, 0x27, 0x00, 0x02, + 0xcc, 0x70, 0x00, 0x90, 0x05, 0x2a, 0x02, 0x00, 0x0c, 0x70, 0x50, 0x7f, + 0x13, 0x08, 0x45, 0x02, 0x02, 0x17, 0x04, 0x05, 0x31, 0x0f, 0x00, 0x11, + 0xc4, 0x74, 0x04, 0x71, 0xf8, 0xf1, 0x78, 0x61, 0x00, 0x18, 0xc2, 0x02, + 0x14, 0x20, 0x4f, 0x12, 0x03, 0x8d, 0x40, 0xb7, 0x88, 0x84, 0x1f, 0x20, + 0x42, 0x02, 0xe4, 0x85, 0x05, 0x85, 0x65, 0x71, 0x15, 0x27, 0x4f, 0x12, + 0x55, 0x78, 0xe4, 0xa4, 0x03, 0xa4, 0x0d, 0xf0, 0x7a, 0x61, 0x00, 0xaa, + 0xe8, 0x84, 0x43, 0x8d, 0x85, 0x85, 0x0c, 0x7a, 0x04, 0x85, 0x55, 0x7c, + 0xc0, 0x70, 0x04, 0xa7, 0x83, 0xa7, 0x64, 0x71, 0xc2, 0xf1, 0x08, 0x1d, + 0x03, 0x10, 0x15, 0xf0, 0x08, 0x1d, 0xc2, 0x12, 0x11, 0xf0, 0x02, 0x8e, + 0x42, 0x20, 0x3c, 0x80, 0x0d, 0xf2, 0x44, 0x85, 0x65, 0x85, 0x22, 0x86, + 0x08, 0x1d, 0x03, 0x10, 0xa8, 0x20, 0xc0, 0x01, 0x04, 0x11, 0x00, 0x04, + 0x08, 0x80, 0x44, 0xa0, 0x63, 0xa0, 0x0c, 0x70, 0xc6, 0xc6, 0xe0, 0x78, + 0xea, 0xc2, 0x24, 0x80, 0x08, 0x45, 0x00, 0x91, 0xdb, 0x08, 0x30, 0x00, + 0xcd, 0x70, 0x0c, 0x11, 0x11, 0x00, 0xe8, 0x81, 0x1c, 0x11, 0x08, 0x00, + 0x4c, 0x70, 0x08, 0x89, 0x9b, 0x0a, 0x25, 0x00, 0x14, 0x27, 0x8b, 0x10, + 0xf4, 0x27, 0x80, 0x10, 0x04, 0x71, 0x00, 0x1b, 0x04, 0x10, 0xf4, 0x20, + 0x83, 0x10, 0x10, 0x78, 0x43, 0x08, 0xc1, 0x00, 0x63, 0x89, 0x1a, 0xeb, + 0x4a, 0x21, 0x00, 0x10, 0x06, 0x81, 0x4c, 0x7b, 0xf4, 0x20, 0x86, 0x10, + 0x00, 0x21, 0xcc, 0x10, 0x80, 0x48, 0x48, 0x36, 0x03, 0x00, 0x25, 0x71, + 0x07, 0x30, 0xc3, 0x00, 0x05, 0x81, 0x95, 0x78, 0x60, 0xa0, 0x06, 0x81, + 0x95, 0x78, 0x00, 0x18, 0x01, 0x00, 0x63, 0x89, 0xd9, 0x09, 0xc4, 0x90, + 0x04, 0x81, 0x61, 0x81, 0x00, 0x1b, 0x84, 0x13, 0x1d, 0xf0, 0x3f, 0x0b, + 0x94, 0x00, 0x24, 0x11, 0x80, 0x00, 0x37, 0x08, 0x51, 0x00, 0x03, 0x89, + 0x11, 0xe8, 0x2d, 0x70, 0x86, 0x81, 0x4c, 0x78, 0x65, 0x81, 0x21, 0x70, + 0x04, 0x4c, 0x15, 0x7b, 0x25, 0x71, 0x80, 0xa3, 0x66, 0x81, 0x15, 0x7b, + 0x00, 0x1b, 0x01, 0x00, 0x03, 0x89, 0xe9, 0x09, 0x04, 0x90, 0x04, 0x81, + 0x61, 0x81, 0x00, 0x1b, 0x05, 0x10, 0x55, 0x78, 0x60, 0xa0, 0x44, 0x71, + 0xb3, 0xf1, 0x0e, 0x70, 0x24, 0x19, 0x82, 0x03, 0x02, 0x8d, 0x49, 0x08, + 0x05, 0x20, 0x01, 0x11, 0x80, 0x24, 0xf4, 0x27, 0x00, 0x10, 0x8a, 0xe8, + 0x02, 0x85, 0xc0, 0x60, 0x28, 0x80, 0x22, 0x89, 0x09, 0x09, 0x1e, 0x00, + 0x42, 0x0b, 0xcf, 0xf3, 0xc5, 0x74, 0x06, 0x71, 0xee, 0xf1, 0x22, 0x8d, + 0x10, 0xe9, 0xcd, 0x70, 0xed, 0x70, 0x02, 0x85, 0xc0, 0x60, 0x48, 0x80, + 0x42, 0x8a, 0x0d, 0x0a, 0x1e, 0x00, 0x26, 0x0b, 0xcf, 0xf3, 0x22, 0x8d, + 0xe5, 0x71, 0xef, 0x0f, 0x64, 0x90, 0xc5, 0x74, 0xca, 0xc6, 0xe0, 0x78, + 0x04, 0x80, 0x65, 0x80, 0x60, 0xa1, 0x04, 0x80, 0xe0, 0x7f, 0x00, 0xa2, + 0xe4, 0xc2, 0xc4, 0x80, 0x08, 0x45, 0x2c, 0x70, 0x24, 0x1e, 0x43, 0x10, + 0x42, 0x88, 0x03, 0x86, 0x08, 0x1e, 0x03, 0x10, 0x3a, 0x0a, 0xef, 0xf4, + 0x04, 0x1e, 0x01, 0x10, 0x22, 0x8d, 0x04, 0x86, 0x52, 0x69, 0x2e, 0x0a, + 0xef, 0xf4, 0x2c, 0x70, 0x22, 0x8d, 0x03, 0x8e, 0x0a, 0x79, 0x05, 0x86, + 0x52, 0x69, 0x1e, 0x0a, 0xef, 0xf4, 0x2c, 0x70, 0x22, 0x8d, 0x03, 0x8e, + 0x0a, 0x79, 0x06, 0x86, 0x52, 0x69, 0x0e, 0x0a, 0xef, 0xf4, 0x2c, 0x70, + 0x22, 0x8d, 0x07, 0x86, 0x3b, 0x7a, 0x02, 0x0a, 0xef, 0xf4, 0x2c, 0x70, + 0x22, 0x8d, 0x08, 0x86, 0x3b, 0x7a, 0xf6, 0x09, 0xef, 0xf4, 0x2c, 0x70, + 0xc4, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0xa4, 0x80, 0x22, 0x88, 0x08, 0x46, + 0x04, 0x85, 0x52, 0x69, 0xde, 0x09, 0xef, 0xf4, 0x2c, 0x70, 0x22, 0x8e, + 0x08, 0x85, 0x3b, 0x7a, 0xd2, 0x09, 0xef, 0xf4, 0x2c, 0x70, 0x22, 0x8e, + 0x03, 0x8d, 0x0a, 0x79, 0x06, 0x85, 0x52, 0x69, 0xc2, 0x09, 0xef, 0xf4, + 0x2c, 0x70, 0xc4, 0xc6, 0x44, 0x80, 0x22, 0x88, 0x05, 0x82, 0x04, 0x1a, + 0x01, 0x00, 0x3b, 0x7a, 0xad, 0x01, 0xef, 0xf4, 0x2c, 0x70, 0xe0, 0x78, + 0xf1, 0xc0, 0x21, 0x80, 0x0d, 0x09, 0x50, 0x00, 0x86, 0xe9, 0xe6, 0x0f, + 0xcf, 0xff, 0x04, 0xf0, 0xae, 0x0f, 0xcf, 0xff, 0xd1, 0xc0, 0xe0, 0x7e, + 0xea, 0xc2, 0xa8, 0x46, 0xe0, 0x86, 0x8b, 0x80, 0x28, 0x45, 0x00, 0x27, + 0x01, 0x11, 0x70, 0x40, 0x50, 0x41, 0x14, 0x24, 0xcb, 0x13, 0x15, 0x24, + 0xc3, 0x13, 0x34, 0x7c, 0x4c, 0x95, 0xfa, 0x1b, 0x5c, 0x14, 0xfa, 0x1c, + 0x1c, 0x14, 0x2c, 0x95, 0x05, 0x80, 0x5d, 0xa3, 0xa0, 0xb9, 0x38, 0x60, + 0xe0, 0xb0, 0x2c, 0x70, 0xa2, 0x08, 0xaf, 0xf4, 0xa1, 0x40, 0x28, 0x85, + 0x01, 0x6f, 0x00, 0xa6, 0x08, 0x19, 0x04, 0x04, 0x06, 0x19, 0x44, 0x04, + 0xca, 0xc6, 0xe0, 0x78, 0xe6, 0xc0, 0x00, 0x43, 0x99, 0x88, 0x00, 0x82, + 0x20, 0x46, 0x91, 0x70, 0xa6, 0x00, 0x25, 0x00, 0x8a, 0x20, 0x7f, 0x0c, + 0x42, 0x24, 0x3c, 0x90, 0x4b, 0xf2, 0xa4, 0x83, 0xec, 0x70, 0xcb, 0x41, + 0x00, 0x00, 0xee, 0xff, 0xcb, 0x40, 0x48, 0x47, 0x00, 0x00, 0xe8, 0x43, + 0xa8, 0x20, 0x41, 0x00, 0xf0, 0x25, 0xc3, 0x12, 0x5a, 0x23, 0x0f, 0x15, + 0xc8, 0x83, 0x6c, 0x93, 0xc0, 0x77, 0x00, 0x96, 0x60, 0xa7, 0x29, 0x68, + 0x30, 0x79, 0x13, 0x09, 0x64, 0x10, 0x14, 0x70, 0x48, 0x30, 0x00, 0x00, + 0x07, 0x30, 0x00, 0x10, 0x06, 0xf0, 0xc3, 0x40, 0x7f, 0x47, 0x00, 0xff, + 0xca, 0x20, 0xc1, 0x01, 0x63, 0x96, 0x01, 0xa7, 0x29, 0x6b, 0x30, 0x79, + 0x0f, 0x09, 0x64, 0x10, 0x48, 0x33, 0x00, 0x00, 0x07, 0x30, 0x00, 0x10, + 0x07, 0xf0, 0x74, 0x70, 0xc3, 0x40, 0x7f, 0x47, 0x00, 0xff, 0xca, 0x20, + 0xc1, 0x01, 0x64, 0x96, 0x02, 0xa7, 0x29, 0x6b, 0x30, 0x79, 0x11, 0x09, + 0x64, 0x10, 0x48, 0x33, 0x00, 0x00, 0x07, 0x30, 0x00, 0x10, 0x09, 0xf0, + 0x74, 0x70, 0x2c, 0x70, 0xc3, 0x40, 0x7f, 0x47, 0x00, 0xff, 0xca, 0x20, + 0x41, 0x00, 0x25, 0x96, 0x65, 0x71, 0x03, 0xa7, 0x28, 0xb7, 0x0c, 0x70, + 0x80, 0xa2, 0xc6, 0xc4, 0xfa, 0xc2, 0xfc, 0x1c, 0xc8, 0xb6, 0xad, 0xc1, + 0x0a, 0x23, 0xc0, 0x31, 0x0a, 0x23, 0x80, 0x21, 0x0a, 0x21, 0x40, 0x31, + 0x0a, 0x25, 0x00, 0x21, 0x70, 0x42, 0x50, 0x47, 0x30, 0x46, 0x08, 0x47, + 0xad, 0x70, 0x04, 0x1c, 0x01, 0x34, 0x42, 0xc5, 0xa1, 0x0a, 0x30, 0x00, + 0x40, 0xc5, 0x9d, 0x0d, 0x10, 0x20, 0x99, 0x09, 0x14, 0x32, 0x0a, 0x87, + 0x0a, 0x80, 0x4c, 0x20, 0x00, 0x80, 0xae, 0x01, 0x21, 0x00, 0x8a, 0x21, + 0xfc, 0x20, 0x4c, 0x22, 0x00, 0xa8, 0xa2, 0x01, 0x25, 0x00, 0x8a, 0x21, + 0xff, 0x26, 0xd1, 0x0e, 0x30, 0x20, 0x8a, 0x20, 0xbc, 0x20, 0x8e, 0x70, + 0x92, 0x40, 0x02, 0x87, 0xcd, 0x70, 0x20, 0x88, 0x6b, 0x08, 0x65, 0x20, + 0x40, 0x24, 0x18, 0x33, 0x01, 0x80, 0x83, 0xc3, 0x40, 0x24, 0x04, 0x3c, + 0x2c, 0x70, 0xf0, 0x20, 0x11, 0x04, 0xc2, 0x42, 0x38, 0x11, 0x0c, 0x20, + 0x23, 0x20, 0x00, 0x03, 0x22, 0x40, 0x0c, 0xc0, 0x3d, 0x0e, 0x25, 0x10, + 0x40, 0x24, 0x04, 0x30, 0x01, 0x10, 0x83, 0x34, 0x34, 0x11, 0x0c, 0x20, + 0x22, 0x40, 0xa2, 0x41, 0x23, 0x20, 0x00, 0x03, 0x23, 0x42, 0x00, 0xc3, + 0x0e, 0xeb, 0x81, 0xc2, 0xe2, 0x40, 0x42, 0x41, 0x0a, 0x24, 0x40, 0x05, + 0x76, 0x0c, 0xef, 0xf3, 0x0a, 0x25, 0x40, 0x06, 0x08, 0x45, 0x86, 0xe8, + 0x86, 0x71, 0xad, 0x70, 0xc5, 0x71, 0xe3, 0xf1, 0x06, 0x71, 0xcd, 0xf1, + 0x8a, 0x21, 0xbc, 0x20, 0x8f, 0xf0, 0x83, 0xc3, 0x40, 0x24, 0x04, 0x3b, + 0x2c, 0x70, 0xe1, 0x40, 0xde, 0x0a, 0x2f, 0xf4, 0xc2, 0x42, 0x0b, 0xc0, + 0x3d, 0x0e, 0x25, 0x10, 0x40, 0x24, 0x04, 0x32, 0x01, 0x10, 0x83, 0x34, + 0xe1, 0x40, 0xa2, 0x41, 0xd2, 0x0a, 0x2f, 0xf4, 0x23, 0x42, 0x02, 0xc0, + 0x10, 0xe8, 0x00, 0xc3, 0x81, 0xc2, 0xe2, 0x40, 0x42, 0x41, 0x0a, 0x24, + 0x40, 0x05, 0x22, 0x0c, 0xef, 0xf3, 0x0a, 0x25, 0x40, 0x06, 0x89, 0x08, + 0x31, 0x00, 0x10, 0x41, 0x86, 0x71, 0xad, 0x70, 0xc5, 0x71, 0xe3, 0xf1, + 0xb1, 0x41, 0x3c, 0xf0, 0x8e, 0x70, 0xcd, 0x70, 0x63, 0xc5, 0x02, 0x87, + 0x20, 0x88, 0x3f, 0x0e, 0x65, 0x10, 0x40, 0x24, 0x04, 0x30, 0x01, 0x80, + 0x23, 0xc3, 0xa0, 0x60, 0x23, 0x42, 0x8d, 0x80, 0x23, 0x20, 0x00, 0x03, + 0xa2, 0x41, 0x00, 0xc3, 0x0e, 0xeb, 0x81, 0xc2, 0xe2, 0x40, 0x42, 0x41, + 0x0a, 0x24, 0x40, 0x05, 0xd6, 0x0b, 0xef, 0xf3, 0x0a, 0x25, 0x40, 0x06, + 0x10, 0x40, 0x87, 0xe8, 0x86, 0x71, 0x0e, 0x70, 0xa5, 0x74, 0xc5, 0x71, + 0xe1, 0xf1, 0x40, 0x24, 0x04, 0x32, 0x6c, 0x70, 0xe1, 0x40, 0xa2, 0x41, + 0x52, 0x0a, 0x2f, 0xf4, 0x23, 0x42, 0x02, 0xc3, 0x0a, 0x21, 0x00, 0x24, + 0x0c, 0xeb, 0x81, 0xc2, 0xe2, 0x40, 0x42, 0x41, 0x0a, 0x24, 0x40, 0x05, + 0x9e, 0x0b, 0xef, 0xf3, 0x0a, 0x25, 0x40, 0x06, 0x10, 0x41, 0x86, 0x71, + 0x33, 0x09, 0x31, 0x20, 0x2f, 0x25, 0x07, 0x85, 0x15, 0xf2, 0x01, 0xc0, + 0x81, 0xc2, 0xe2, 0x41, 0x70, 0xb8, 0x41, 0xc0, 0xe1, 0x40, 0xa2, 0x43, + 0x0a, 0x24, 0x40, 0x06, 0x0a, 0x26, 0x80, 0x05, 0x36, 0x0f, 0xef, 0xf3, + 0x0a, 0x27, 0xc0, 0x06, 0x01, 0xc0, 0x2e, 0x70, 0x00, 0x1b, 0x00, 0x20, + 0x0e, 0xf0, 0x2c, 0x70, 0xe2, 0x40, 0x42, 0x42, 0xc2, 0x0e, 0xaf, 0xf4, + 0x00, 0x1b, 0x01, 0x20, 0x2f, 0x26, 0x07, 0xf5, 0x8a, 0x20, 0xff, 0x06, + 0xca, 0x21, 0x01, 0x20, 0x2c, 0x70, 0xa2, 0x40, 0xaa, 0x0e, 0xaf, 0xf4, + 0x23, 0x42, 0x22, 0x40, 0xad, 0xc0, 0x04, 0x14, 0x1b, 0x34, 0xda, 0xc6, + 0xec, 0xc2, 0xbe, 0x0f, 0xaf, 0xfe, 0x08, 0x47, 0x01, 0x87, 0x04, 0xe8, + 0x36, 0x09, 0x8f, 0xf3, 0x4e, 0x70, 0xcd, 0x70, 0x02, 0x87, 0x20, 0x88, + 0x55, 0x0e, 0x65, 0x10, 0x2e, 0x70, 0x01, 0x80, 0x32, 0x40, 0xc5, 0x48, + 0x08, 0x8d, 0x29, 0x08, 0x05, 0x20, 0x03, 0x85, 0x30, 0x20, 0x40, 0x04, + 0x28, 0x80, 0x47, 0x80, 0x61, 0x91, 0x54, 0x73, 0x46, 0x23, 0x82, 0x01, + 0x82, 0xba, 0x41, 0xb1, 0x03, 0xf4, 0x6a, 0x09, 0x8f, 0xf4, 0x26, 0x74, + 0x06, 0x71, 0xee, 0xf1, 0x09, 0x8d, 0x0e, 0xe8, 0x2e, 0x70, 0x32, 0x40, + 0x04, 0x85, 0xa2, 0x0c, 0xef, 0xff, 0x30, 0x20, 0x40, 0x04, 0x09, 0x8d, + 0x06, 0x71, 0xf5, 0x08, 0x24, 0xa0, 0x26, 0x74, 0xc5, 0x71, 0xd6, 0xf1, + 0xad, 0x70, 0x18, 0x8f, 0x17, 0x0d, 0x05, 0x10, 0x03, 0x87, 0x30, 0x20, + 0x80, 0x04, 0x04, 0xe8, 0x7a, 0x0c, 0xcf, 0xff, 0x46, 0x74, 0xa5, 0x71, + 0xf5, 0xf1, 0xca, 0x0c, 0xcf, 0xfe, 0xcc, 0xc6, 0x15, 0x09, 0xf0, 0x00, + 0x0a, 0x80, 0x1b, 0x09, 0x91, 0x00, 0x24, 0x18, 0x80, 0x0f, 0x13, 0x00, + 0xc8, 0x52, 0xe0, 0x7e, 0x24, 0x18, 0x80, 0x0f, 0x13, 0x00, 0x90, 0x52, + 0xe0, 0x7e, 0x24, 0x18, 0x80, 0x0f, 0x13, 0x00, 0x00, 0x53, 0xe0, 0x7e, + 0xf2, 0xc3, 0xa6, 0xc1, 0x0a, 0x20, 0x00, 0x21, 0x70, 0x45, 0x50, 0x44, + 0x30, 0x43, 0x08, 0x46, 0x2e, 0x70, 0x54, 0x70, 0x04, 0x1c, 0x01, 0x30, + 0x06, 0xf2, 0x76, 0x70, 0x8a, 0x21, 0xbc, 0x20, 0x02, 0xf2, 0xb6, 0x70, + 0x80, 0x02, 0x21, 0x00, 0x4c, 0x20, 0x00, 0xa2, 0x78, 0x02, 0x05, 0x00, + 0x0a, 0x86, 0x8a, 0x21, 0xfc, 0x20, 0x0a, 0x80, 0x04, 0x77, 0x14, 0x71, + 0x68, 0x02, 0x2d, 0x00, 0x2c, 0x70, 0xeb, 0x86, 0xa2, 0x40, 0xa2, 0x0d, + 0xaf, 0xf4, 0x02, 0x42, 0x40, 0x24, 0x05, 0x32, 0x40, 0x24, 0x06, 0x34, + 0x40, 0x24, 0x87, 0x33, 0xc1, 0x40, 0x62, 0x41, 0x82, 0x42, 0xa2, 0x43, + 0xee, 0x0a, 0x6f, 0xf4, 0x0a, 0x24, 0x00, 0x04, 0x14, 0x70, 0x3c, 0x02, + 0x22, 0x00, 0x10, 0x41, 0x02, 0xc5, 0x4e, 0x70, 0x52, 0x41, 0x38, 0xed, + 0x6d, 0x09, 0x11, 0x20, 0x04, 0xc0, 0x67, 0x08, 0x25, 0x05, 0x84, 0xc2, + 0x40, 0x24, 0xc5, 0x33, 0x40, 0x24, 0xc6, 0x35, 0x40, 0x24, 0x07, 0x31, + 0x62, 0x40, 0x82, 0x41, 0xa2, 0x43, 0x9e, 0x0b, 0x2f, 0xf4, 0x0a, 0x24, + 0x00, 0x04, 0x10, 0x41, 0xa2, 0xe8, 0x0f, 0x14, 0x81, 0x30, 0x8c, 0x21, + 0x83, 0x8f, 0x08, 0xf4, 0x01, 0xc2, 0xc1, 0x40, 0xa2, 0x0e, 0x2f, 0xf4, + 0xa2, 0x41, 0x0a, 0xf0, 0xe2, 0x0e, 0x6f, 0xf3, 0x02, 0x86, 0x10, 0xe8, + 0x6a, 0x80, 0x01, 0xc2, 0x60, 0x7b, 0xa2, 0x41, 0x2e, 0x70, 0x02, 0xc0, + 0x2c, 0x70, 0x02, 0x42, 0xa9, 0x68, 0xa2, 0x40, 0x12, 0x0d, 0xaf, 0xf4, + 0x42, 0xc5, 0xcf, 0xf1, 0x8a, 0x21, 0xbc, 0x20, 0xf5, 0xf1, 0x2e, 0x70, + 0x4c, 0x87, 0x0a, 0x87, 0x2a, 0x86, 0x00, 0x30, 0x80, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x0d, 0xa1, 0x0b, 0x87, 0x00, 0x32, 0x00, 0x00, 0x48, 0x30, + 0xc0, 0x02, 0x15, 0x09, 0x31, 0x20, 0x0e, 0xa1, 0x0e, 0x14, 0x80, 0x30, + 0x09, 0x08, 0x15, 0x01, 0x28, 0x19, 0x81, 0x00, 0x70, 0x17, 0x80, 0x10, + 0x42, 0x20, 0x3c, 0x80, 0x11, 0xf2, 0x44, 0x86, 0xa8, 0x20, 0xc0, 0x03, + 0xf0, 0x22, 0x81, 0x04, 0x14, 0x27, 0x80, 0x14, 0xfa, 0x10, 0x03, 0x07, + 0x80, 0x20, 0x0a, 0x0d, 0x28, 0x81, 0x46, 0x71, 0x63, 0xb1, 0x00, 0x90, + 0x04, 0xb1, 0x58, 0x8e, 0x19, 0xea, 0x63, 0x86, 0x2c, 0x70, 0x20, 0x4b, + 0x8d, 0x71, 0x00, 0x10, 0x0b, 0x01, 0xa2, 0x88, 0x00, 0x2c, 0xcc, 0x12, + 0x42, 0x25, 0x3c, 0x90, 0x00, 0x1c, 0x04, 0x33, 0x08, 0xf2, 0x02, 0x80, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x0d, 0x04, 0xa8, 0x85, 0x85, 0xb5, + 0x24, 0x71, 0xdb, 0x09, 0x84, 0x80, 0x4e, 0x70, 0x52, 0x40, 0x02, 0x86, + 0x20, 0x88, 0x77, 0x08, 0x45, 0x20, 0x01, 0x80, 0xf0, 0x20, 0x0d, 0x04, + 0x48, 0x85, 0x08, 0xea, 0x80, 0xc1, 0x60, 0x7a, 0xa1, 0x40, 0x00, 0x14, + 0x03, 0x31, 0x19, 0xf0, 0x08, 0x8d, 0x6c, 0x70, 0x00, 0x1c, 0x84, 0x34, + 0x42, 0x20, 0x3c, 0x80, 0x11, 0xf2, 0x43, 0x85, 0x4a, 0x23, 0x00, 0x00, + 0xa8, 0x20, 0x40, 0x03, 0x04, 0x12, 0x00, 0x04, 0x08, 0x80, 0x22, 0x88, + 0x0d, 0x09, 0x9f, 0x01, 0x05, 0x90, 0x05, 0x7b, 0x00, 0x1c, 0xc4, 0x30, + 0xe0, 0x78, 0x09, 0x8d, 0x08, 0x43, 0x13, 0xe8, 0x84, 0x85, 0x2c, 0x70, + 0x20, 0x4c, 0x42, 0x88, 0x42, 0x22, 0x3c, 0x80, 0x08, 0xf2, 0x02, 0x80, + 0xa8, 0x20, 0x80, 0x01, 0x04, 0x10, 0x02, 0x04, 0x48, 0x82, 0x65, 0xb2, + 0x24, 0x71, 0xe9, 0x09, 0xc4, 0x82, 0x06, 0x71, 0xc5, 0xf1, 0x8a, 0x20, + 0x4e, 0x00, 0x1d, 0x67, 0x7a, 0x0b, 0x20, 0x00, 0xc1, 0x40, 0x20, 0x8d, + 0x10, 0x42, 0xe2, 0x0d, 0xef, 0xff, 0xc1, 0x40, 0x01, 0x8d, 0x05, 0xe8, + 0xa6, 0x08, 0x20, 0x00, 0xc1, 0x40, 0x80, 0x27, 0xce, 0x10, 0x00, 0x8f, + 0x8f, 0x08, 0x30, 0x00, 0x0e, 0x70, 0xed, 0x70, 0x19, 0x8e, 0x87, 0x0f, + 0x05, 0x10, 0x04, 0x86, 0x30, 0x20, 0x0d, 0x04, 0x8a, 0x20, 0xbe, 0x0a, + 0x2c, 0x95, 0x38, 0x60, 0x1b, 0x08, 0x74, 0x01, 0x15, 0xda, 0x20, 0x40, + 0x80, 0x20, 0x3d, 0x00, 0x23, 0x08, 0x75, 0x02, 0x8a, 0x22, 0x45, 0x00, + 0x0b, 0x0a, 0x0f, 0x00, 0x0b, 0xf0, 0xef, 0x0a, 0x0e, 0x80, 0x8a, 0x20, + 0x84, 0x00, 0x40, 0xc0, 0x80, 0xc1, 0x3e, 0x0b, 0x6f, 0xf4, 0xa1, 0x40, + 0x2c, 0x95, 0x23, 0x09, 0xd5, 0x04, 0xc3, 0x40, 0x05, 0x00, 0x40, 0x51, + 0x17, 0x08, 0x4e, 0x00, 0xc3, 0x40, 0x20, 0xbc, 0x12, 0xac, 0x40, 0xc0, + 0x80, 0xc1, 0x1e, 0x0b, 0x6f, 0xf4, 0xa1, 0x40, 0x2c, 0x95, 0x42, 0x21, + 0x00, 0x0e, 0x1d, 0x08, 0x75, 0x01, 0x15, 0xd9, 0x15, 0x09, 0x2e, 0x00, + 0x80, 0xc1, 0xc3, 0x40, 0x1c, 0xc1, 0x0a, 0xe8, 0x40, 0xc0, 0xfe, 0x0a, + 0x6f, 0xf4, 0xa1, 0x40, 0x06, 0x74, 0xe5, 0x71, 0xbe, 0xf1, 0x36, 0x70, + 0xca, 0x21, 0x81, 0x24, 0x22, 0x40, 0xd2, 0xc7, 0xe6, 0xc2, 0x18, 0x10, + 0x84, 0x00, 0xeb, 0x80, 0xac, 0x70, 0x6c, 0x70, 0x4b, 0x0b, 0x25, 0x01, + 0x6d, 0x70, 0x23, 0x80, 0x8d, 0x70, 0x65, 0x49, 0x14, 0x27, 0xc1, 0x10, + 0x52, 0x11, 0x09, 0x01, 0x48, 0x11, 0x0e, 0x01, 0x02, 0x15, 0x88, 0x10, + 0x11, 0x74, 0xc0, 0x23, 0x66, 0x00, 0x70, 0xf7, 0x22, 0x85, 0x30, 0x21, + 0xc1, 0x02, 0x28, 0x81, 0x43, 0x91, 0x05, 0xea, 0x08, 0x19, 0x44, 0x02, + 0xc3, 0xb1, 0xc3, 0x42, 0x00, 0x00, 0xff, 0xff, 0x09, 0x0e, 0x81, 0x10, + 0x44, 0xb1, 0x43, 0xb1, 0x65, 0x74, 0x85, 0x71, 0xea, 0xf1, 0x22, 0x80, + 0x0a, 0x26, 0x40, 0x30, 0x00, 0x11, 0x9f, 0x00, 0x0c, 0x25, 0xc0, 0x87, + 0x5a, 0x02, 0x26, 0x00, 0xec, 0x70, 0x04, 0x16, 0x00, 0x30, 0xf0, 0x20, + 0x4c, 0x01, 0x08, 0x8c, 0x00, 0x46, 0x10, 0xe8, 0x23, 0x84, 0x0a, 0x24, + 0x80, 0x71, 0xec, 0x70, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x11, 0x00, 0x04, + 0x08, 0x80, 0x02, 0x88, 0x24, 0xb8, 0xc0, 0xb8, 0x00, 0x27, 0x07, 0x00, + 0xa9, 0x8c, 0xcd, 0x70, 0xc9, 0x43, 0x6c, 0x70, 0x0c, 0x70, 0x31, 0x0b, + 0x65, 0x03, 0x0d, 0x71, 0x24, 0x84, 0x61, 0x49, 0x42, 0x89, 0x42, 0x22, + 0x3c, 0x80, 0x0e, 0xf2, 0x22, 0x81, 0x00, 0x42, 0xa8, 0x20, 0x80, 0x02, + 0x04, 0x11, 0x00, 0x04, 0x08, 0x80, 0x05, 0x90, 0x10, 0x72, 0xc5, 0x23, + 0x02, 0x10, 0x00, 0x42, 0x64, 0x71, 0xeb, 0xf1, 0x4e, 0x87, 0x0d, 0x87, + 0x2f, 0x87, 0x2f, 0x23, 0xc8, 0x02, 0x00, 0x28, 0x8b, 0x10, 0x0f, 0x23, + 0x02, 0x10, 0x0f, 0x22, 0x4d, 0x00, 0x7d, 0x0d, 0xe1, 0x10, 0x00, 0x28, + 0x09, 0x10, 0x42, 0x26, 0x3c, 0x80, 0xe6, 0xf2, 0x0c, 0x14, 0x0d, 0x10, + 0xa8, 0x20, 0xc0, 0x0c, 0xc0, 0x4d, 0x2f, 0x21, 0xc7, 0x01, 0x4f, 0x09, + 0xb5, 0x00, 0x08, 0x80, 0x0a, 0x10, 0x08, 0x01, 0x40, 0x27, 0x06, 0x1d, + 0x8d, 0x70, 0x52, 0xdb, 0x49, 0x0c, 0x25, 0x11, 0x2c, 0x71, 0x04, 0x16, + 0x02, 0x04, 0x58, 0x79, 0x04, 0x21, 0x02, 0x82, 0x12, 0xf2, 0x23, 0x90, + 0x31, 0x72, 0xcc, 0x22, 0xc2, 0x82, 0x09, 0xf4, 0x0c, 0xe9, 0x24, 0x90, + 0x0a, 0xe9, 0x71, 0x67, 0x24, 0xb0, 0x23, 0xb0, 0x06, 0xf0, 0x06, 0xe9, + 0x24, 0x90, 0x04, 0xe9, 0x71, 0x67, 0x24, 0xb0, 0x64, 0x72, 0x85, 0x71, + 0xe4, 0xf1, 0x23, 0x90, 0x06, 0xe9, 0x24, 0x90, 0x04, 0xe9, 0x52, 0x17, + 0x01, 0x11, 0x24, 0xb0, 0xc5, 0x71, 0xb0, 0xf0, 0x00, 0x28, 0x48, 0x10, + 0x05, 0x20, 0x40, 0x12, 0x63, 0x08, 0xe1, 0x00, 0x42, 0x26, 0x3c, 0x80, + 0xa6, 0xf2, 0xa3, 0x84, 0xa8, 0x20, 0x80, 0x0a, 0x2f, 0x20, 0xc7, 0x01, + 0x4b, 0x08, 0xb5, 0x00, 0x40, 0x27, 0x08, 0x1d, 0xc0, 0x4d, 0x8d, 0x70, + 0x52, 0xda, 0x08, 0x80, 0x0a, 0x10, 0x0b, 0x01, 0x37, 0x0c, 0x25, 0x11, + 0x2c, 0x71, 0x04, 0x10, 0x03, 0x14, 0x78, 0x79, 0x04, 0x21, 0xc3, 0x82, + 0x10, 0xf2, 0x17, 0x0b, 0x61, 0x02, 0x23, 0x90, 0x0c, 0xe9, 0x24, 0x90, + 0x0a, 0xe9, 0x51, 0x67, 0x24, 0xb0, 0x23, 0xb0, 0x06, 0xf0, 0x06, 0xe9, + 0x24, 0x90, 0x04, 0xe9, 0x51, 0x67, 0x24, 0xb0, 0x44, 0x72, 0x85, 0x71, + 0xe6, 0xf1, 0xc5, 0x71, 0x7a, 0xf0, 0x5d, 0x0a, 0xe1, 0x00, 0x42, 0x26, + 0x3c, 0x80, 0x76, 0xf2, 0x0c, 0x14, 0x0d, 0x10, 0xa8, 0x20, 0x40, 0x09, + 0x2f, 0x20, 0xc7, 0x01, 0x41, 0x08, 0xb5, 0x00, 0x40, 0x27, 0x09, 0x1d, + 0xc0, 0x4d, 0x8d, 0x70, 0x52, 0xda, 0x28, 0x80, 0x65, 0x91, 0x31, 0x0c, + 0x25, 0x11, 0x0c, 0x71, 0x04, 0x11, 0x08, 0x14, 0x00, 0x28, 0x00, 0x02, + 0x04, 0x20, 0xc0, 0x80, 0x0b, 0xf2, 0x17, 0x08, 0xc1, 0x02, 0x03, 0x91, + 0x07, 0xe8, 0x04, 0x91, 0x05, 0xe8, 0x50, 0x67, 0x22, 0xb8, 0x04, 0xb1, + 0x03, 0xb1, 0x44, 0x72, 0x85, 0x71, 0xeb, 0xf1, 0xc5, 0x71, 0x4e, 0xf0, + 0x05, 0x20, 0xc0, 0x12, 0x67, 0x08, 0xe1, 0x00, 0x42, 0x26, 0x3c, 0x80, + 0x46, 0xf2, 0xc3, 0x84, 0x4a, 0x25, 0x00, 0x10, 0xa8, 0x20, 0x80, 0x0a, + 0x2f, 0x20, 0xc7, 0x01, 0x4b, 0x08, 0xb5, 0x00, 0x40, 0x27, 0x09, 0x1d, + 0xa0, 0x4e, 0x52, 0xda, 0x8d, 0x70, 0x08, 0x80, 0x0a, 0x10, 0x0b, 0x01, + 0x37, 0x0c, 0x25, 0x11, 0x2c, 0x71, 0x04, 0x11, 0x03, 0x14, 0x78, 0x79, + 0x04, 0x21, 0xc3, 0x82, 0x10, 0xf2, 0x15, 0x0b, 0x21, 0x02, 0x23, 0x90, + 0x0c, 0xe9, 0x24, 0x90, 0x0a, 0xe9, 0x51, 0x67, 0x24, 0xb0, 0x08, 0xf0, + 0x06, 0xe9, 0x24, 0x90, 0x04, 0xe9, 0x51, 0x67, 0x24, 0xb0, 0x23, 0xb0, + 0x44, 0x72, 0x85, 0x71, 0xe6, 0xf1, 0xa5, 0x71, 0x18, 0xf0, 0x31, 0x0e, + 0x10, 0x00, 0x2d, 0x08, 0xe1, 0x10, 0x0a, 0x24, 0x80, 0x71, 0x23, 0x84, + 0xa8, 0x20, 0x00, 0x04, 0x04, 0x11, 0x00, 0x04, 0x08, 0x80, 0x45, 0x90, + 0x13, 0x0b, 0x81, 0x00, 0x43, 0x90, 0x07, 0xea, 0x44, 0x90, 0x05, 0xea, + 0x56, 0x17, 0x02, 0x11, 0x44, 0xb0, 0xe0, 0x78, 0xa9, 0x05, 0xef, 0xff, + 0xa4, 0x71, 0xc6, 0xc6, 0xec, 0xc2, 0x18, 0x10, 0x89, 0x00, 0x2c, 0x10, + 0x06, 0x00, 0xed, 0x70, 0x08, 0x46, 0xe9, 0x43, 0xf1, 0x40, 0x2f, 0x20, + 0xc8, 0x02, 0x47, 0x08, 0x65, 0x02, 0x8d, 0x70, 0x23, 0x86, 0x02, 0x49, + 0x14, 0x26, 0x00, 0x00, 0x48, 0x10, 0x03, 0x01, 0x02, 0x12, 0x88, 0x00, + 0x90, 0x78, 0x2b, 0x08, 0x05, 0x02, 0x22, 0x82, 0x00, 0x49, 0x08, 0x80, + 0x23, 0x90, 0x0d, 0x09, 0xc5, 0x00, 0x4a, 0x20, 0xc0, 0x23, 0x63, 0xb0, + 0xc3, 0x41, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x0b, 0x41, 0x00, 0x24, 0xb0, + 0x23, 0xb0, 0x85, 0x71, 0xec, 0xf1, 0x65, 0x71, 0xdd, 0xf1, 0xd3, 0x42, + 0x00, 0x00, 0xff, 0xff, 0x02, 0x86, 0x20, 0x88, 0xb5, 0x0f, 0x65, 0x10, + 0x2e, 0x70, 0x01, 0x80, 0x42, 0x42, 0xe5, 0x48, 0x28, 0x8d, 0x2f, 0x20, + 0x48, 0x04, 0x1b, 0x08, 0x45, 0x00, 0x23, 0x85, 0x00, 0x49, 0x08, 0x80, + 0x23, 0x90, 0xee, 0x08, 0x6f, 0xf3, 0x50, 0x78, 0x00, 0x42, 0x26, 0x71, + 0xf2, 0xf1, 0x09, 0x6a, 0x10, 0x78, 0x4f, 0x08, 0x85, 0x0f, 0x00, 0x00, + 0xef, 0xff, 0x09, 0x15, 0x86, 0x10, 0x6c, 0x70, 0x2f, 0x23, 0x88, 0x10, + 0x71, 0x0b, 0xa5, 0x01, 0x0d, 0x70, 0x04, 0x85, 0x61, 0x48, 0x02, 0x11, + 0x89, 0x00, 0x2f, 0x20, 0x08, 0x02, 0x31, 0x70, 0xc0, 0x23, 0x66, 0x00, + 0x74, 0xf7, 0x82, 0x81, 0x00, 0x4c, 0x08, 0x80, 0x83, 0x90, 0x0b, 0xec, + 0x13, 0x0c, 0xc5, 0x12, 0x84, 0x90, 0x4a, 0x20, 0xc0, 0x23, 0x0b, 0x0c, + 0xe5, 0x12, 0x43, 0xb0, 0x44, 0xb0, 0x05, 0x71, 0xeb, 0xf1, 0x50, 0x78, + 0x35, 0x08, 0xa1, 0x04, 0x2c, 0x70, 0x09, 0x15, 0x88, 0x10, 0x2d, 0x09, + 0x25, 0x02, 0x8d, 0x70, 0x04, 0x85, 0x22, 0x48, 0x02, 0x12, 0x8b, 0x00, + 0x90, 0x78, 0x71, 0x70, 0xc0, 0x21, 0x66, 0x00, 0x75, 0xf7, 0x62, 0x82, + 0x85, 0x71, 0x00, 0x4b, 0x08, 0x80, 0x08, 0x18, 0xc5, 0x0f, 0x06, 0x18, + 0xc5, 0x0f, 0xf4, 0xf1, 0xe5, 0x71, 0xa6, 0xf1, 0x02, 0x40, 0xcc, 0xc6, + 0x08, 0x80, 0x84, 0x21, 0x41, 0x0e, 0x85, 0x21, 0x02, 0x01, 0x0a, 0x18, + 0x05, 0x00, 0x00, 0x18, 0xc5, 0x0f, 0xe0, 0x7f, 0x21, 0xb0, 0xe0, 0x78, + 0x08, 0x80, 0x21, 0x90, 0x00, 0x18, 0xc5, 0x0f, 0x6c, 0x21, 0x81, 0x00, + 0x82, 0xb9, 0xe0, 0x7f, 0x21, 0xb0, 0xe0, 0x78, 0x0f, 0x08, 0x34, 0x04, + 0x2c, 0x71, 0xc3, 0x41, 0x00, 0x00, 0xff, 0xff, 0x02, 0xf0, 0x18, 0x79, + 0xe0, 0x7f, 0x30, 0x78, 0x40, 0x81, 0x48, 0x60, 0x44, 0x71, 0xe0, 0x7f, + 0x40, 0xa1, 0xe0, 0x78, 0xec, 0xc2, 0xcb, 0x45, 0xf0, 0x00, 0x34, 0x00, + 0x93, 0xda, 0x2c, 0x70, 0x94, 0xd8, 0x57, 0xad, 0x00, 0x1e, 0x42, 0x70, + 0xa0, 0x00, 0xb4, 0x41, 0x17, 0xad, 0xa2, 0x5a, 0x34, 0xe8, 0xa3, 0x5a, + 0x95, 0xd8, 0x96, 0x0a, 0xaf, 0xf7, 0x17, 0xad, 0x96, 0xd8, 0x17, 0xad, + 0x34, 0x58, 0x10, 0x42, 0x3e, 0x58, 0x10, 0x41, 0x2e, 0x58, 0x10, 0x40, + 0x2f, 0x58, 0x08, 0x47, 0x02, 0x41, 0x22, 0x42, 0x00, 0x43, 0x42, 0x40, + 0xa4, 0x5a, 0x08, 0x46, 0x03, 0xe8, 0xc1, 0x40, 0x67, 0x58, 0x9b, 0xd9, + 0x9c, 0xd8, 0x37, 0xad, 0x42, 0x0a, 0xaf, 0xf7, 0x17, 0xad, 0x9d, 0xd8, + 0xf6, 0x0d, 0x6f, 0xff, 0x17, 0xad, 0x9e, 0xd8, 0x72, 0x0e, 0x6f, 0xff, + 0x17, 0xad, 0x9f, 0xd8, 0x1e, 0x0e, 0x6f, 0xff, 0x17, 0xad, 0xa0, 0xd8, + 0xd4, 0xad, 0x17, 0xad, 0x42, 0x40, 0x02, 0x41, 0x22, 0x42, 0xe1, 0x43, + 0xb1, 0x5a, 0x06, 0xf0, 0x14, 0x8d, 0x84, 0xe8, 0x20, 0xd8, 0x14, 0xad, + 0xa2, 0xd8, 0x4a, 0x0a, 0xaf, 0xf7, 0x17, 0xad, 0xa3, 0xd8, 0x17, 0xad, + 0x40, 0x58, 0xe0, 0x78, 0xc3, 0x40, 0xa0, 0x00, 0x04, 0x87, 0x01, 0x18, + 0x43, 0x00, 0x00, 0x16, 0x81, 0x70, 0xf0, 0x00, 0x06, 0x01, 0xe0, 0x7f, + 0x20, 0xa8, 0xe0, 0x78, 0xc3, 0x42, 0xa0, 0x00, 0x04, 0x87, 0x21, 0x8a, + 0x00, 0x43, 0x0c, 0x70, 0x34, 0x70, 0xe0, 0x7c, 0x40, 0x8a, 0x7f, 0xd9, + 0x44, 0x79, 0x00, 0x21, 0xc1, 0x80, 0x10, 0x00, 0x24, 0x00, 0x8c, 0x21, + 0x02, 0x80, 0x20, 0x40, 0x82, 0xf6, 0x7f, 0xd8, 0x84, 0x22, 0x02, 0x00, + 0x05, 0x7a, 0x00, 0x1e, 0x82, 0x70, 0xf0, 0x00, 0x06, 0x01, 0xe0, 0x7f, + 0x0c, 0x71, 0xe0, 0x78, 0xe0, 0x7e, 0xe0, 0x78, 0xea, 0xc3, 0xa7, 0xc1, + 0x08, 0x45, 0x01, 0x80, 0x82, 0x85, 0xe3, 0x85, 0xc0, 0x85, 0x00, 0x34, + 0x08, 0x10, 0x00, 0x30, 0x06, 0x00, 0x00, 0x34, 0x09, 0x13, 0x30, 0x40, + 0x00, 0x36, 0xcb, 0x13, 0x00, 0x37, 0x04, 0x10, 0x00, 0x36, 0x87, 0x13, + 0x00, 0x36, 0x00, 0x13, 0x68, 0x46, 0x01, 0x33, 0x0c, 0x12, 0x02, 0x30, + 0x00, 0x01, 0x02, 0x31, 0x8b, 0x11, 0x01, 0x34, 0x0c, 0x13, 0x01, 0x30, + 0x03, 0x00, 0x41, 0xc4, 0x02, 0x33, 0xc1, 0x11, 0x40, 0xc3, 0x00, 0x37, + 0xc0, 0x13, 0x01, 0x30, 0x40, 0x00, 0xa7, 0x0a, 0x70, 0x00, 0x42, 0xc0, + 0x21, 0x0a, 0x30, 0x01, 0x83, 0xc1, 0x1b, 0x0a, 0xb1, 0x00, 0x44, 0x6e, + 0x40, 0x26, 0x03, 0x12, 0x80, 0xc1, 0x40, 0x26, 0x05, 0x13, 0xa1, 0x40, + 0xa6, 0x0c, 0x6f, 0xfc, 0xc1, 0x44, 0xca, 0xc7, 0xda, 0x09, 0xef, 0xef, + 0xa1, 0x40, 0x43, 0x85, 0x22, 0x85, 0xe1, 0x85, 0x00, 0x85, 0x05, 0xc4, + 0x03, 0xc3, 0x00, 0x31, 0x82, 0x00, 0x7f, 0xdd, 0x00, 0x30, 0xc1, 0x03, + 0x17, 0xbd, 0x02, 0x33, 0x00, 0x03, 0x02, 0x31, 0x81, 0x00, 0x01, 0x30, + 0x02, 0x00, 0x01, 0x31, 0x40, 0x00, 0x02, 0x35, 0x81, 0x10, 0xb2, 0x0e, + 0xef, 0xee, 0x02, 0x42, 0x01, 0xc2, 0x08, 0x47, 0x00, 0xa6, 0x00, 0x32, + 0x81, 0x00, 0x52, 0x22, 0xc0, 0x07, 0x02, 0x35, 0x41, 0x10, 0x02, 0x42, + 0x2f, 0x31, 0x40, 0x00, 0x92, 0x0e, 0xef, 0xee, 0x01, 0x31, 0x41, 0x03, + 0x04, 0xc2, 0x03, 0xc1, 0x01, 0x30, 0x03, 0x00, 0x00, 0xc4, 0x02, 0x31, + 0x80, 0x00, 0x02, 0x42, 0x01, 0x30, 0x01, 0x00, 0x52, 0x24, 0xc0, 0x17, + 0x02, 0x35, 0x41, 0x10, 0x6e, 0x0e, 0xef, 0xee, 0x61, 0xa6, 0xe3, 0xa6, + 0x5c, 0xf0, 0x80, 0xc0, 0xbe, 0x0b, 0xaf, 0xf4, 0x83, 0xc1, 0x03, 0xc0, + 0x04, 0x30, 0x80, 0x8f, 0x7c, 0x3f, 0xae, 0x5d, 0xd3, 0xf6, 0x05, 0xc1, + 0x2e, 0x0a, 0x2f, 0xf3, 0x01, 0x30, 0x40, 0x00, 0x01, 0xc1, 0x02, 0xc2, + 0x6c, 0x70, 0x00, 0x30, 0x40, 0x00, 0x04, 0x32, 0xc0, 0x80, 0x52, 0x20, + 0xc0, 0x07, 0xca, 0xf6, 0x7f, 0xd9, 0x17, 0xb9, 0x09, 0xf0, 0x01, 0xc0, + 0x02, 0xc1, 0x52, 0x20, 0xc0, 0x07, 0x05, 0xf0, 0xc3, 0x41, 0x80, 0xbf, + 0x00, 0x00, 0x1e, 0x0e, 0xef, 0xee, 0x02, 0x42, 0x08, 0x47, 0x05, 0xc1, + 0x04, 0xc0, 0xf2, 0x09, 0x2f, 0xf3, 0x01, 0x30, 0x40, 0x00, 0x02, 0xc1, + 0x10, 0x41, 0x04, 0x31, 0x80, 0x8f, 0x80, 0xbf, 0x00, 0x00, 0xcc, 0xf6, + 0x04, 0x31, 0x80, 0x8f, 0x35, 0xbf, 0xf3, 0x04, 0x46, 0xf7, 0x21, 0x85, + 0x00, 0x85, 0x52, 0x21, 0xc1, 0x07, 0x04, 0xf0, 0x23, 0x85, 0x02, 0x85, + 0xe2, 0x0d, 0xef, 0xee, 0x02, 0x42, 0x00, 0x30, 0x8d, 0x0f, 0x00, 0xc0, + 0x00, 0x00, 0x0c, 0x70, 0x04, 0x35, 0x00, 0x90, 0x45, 0xf7, 0x01, 0x35, + 0x8d, 0x1f, 0xc9, 0x40, 0xdb, 0x0f, 0x00, 0xc0, 0x7f, 0xd9, 0x17, 0xb9, + 0x00, 0x31, 0x00, 0x20, 0x02, 0x42, 0xe1, 0xa6, 0xb6, 0x0d, 0xef, 0xee, + 0xa0, 0xa6, 0xa3, 0xa6, 0x02, 0xa6, 0xca, 0xc7, 0xe2, 0xc2, 0x28, 0x45, + 0x20, 0x81, 0x40, 0x43, 0x4c, 0x76, 0x19, 0x61, 0xda, 0x0b, 0x6f, 0xf4, + 0x60, 0x40, 0x00, 0x85, 0x04, 0x76, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, + 0xe6, 0xc3, 0xa2, 0xc1, 0x68, 0x45, 0x60, 0x83, 0x28, 0x46, 0x64, 0x76, + 0x2b, 0x0a, 0xe4, 0x00, 0x00, 0x41, 0x80, 0xc0, 0x4c, 0x76, 0xfe, 0x0d, + 0x6f, 0xe6, 0x80, 0xc7, 0x4a, 0x24, 0x80, 0x71, 0xa8, 0x20, 0x00, 0x02, + 0x00, 0x85, 0x01, 0x17, 0x81, 0x14, 0xd8, 0x60, 0xc5, 0x71, 0x20, 0xa8, + 0x00, 0x85, 0x04, 0x76, 0x00, 0xa5, 0xc6, 0xc7, 0xe2, 0xc3, 0x08, 0x45, + 0x01, 0x80, 0x84, 0x20, 0x03, 0x0c, 0x15, 0x08, 0x31, 0x04, 0xa1, 0xc1, + 0x0e, 0x8d, 0x00, 0x15, 0x04, 0x10, 0x1d, 0x78, 0x9d, 0x5a, 0xc2, 0xc7, + 0xff, 0xd8, 0x40, 0xc0, 0xc3, 0x44, 0x13, 0x00, 0x24, 0x1a, 0x40, 0x24, + 0x05, 0x30, 0xa1, 0x40, 0xaa, 0x5a, 0xa1, 0x40, 0x17, 0x58, 0x00, 0xc0, + 0xc2, 0xc7, 0xe0, 0x78, 0xea, 0xc2, 0x08, 0x46, 0x48, 0x30, 0x00, 0x00, + 0x48, 0x47, 0x30, 0x40, 0xc3, 0x41, 0x13, 0x00, 0x10, 0x4d, 0x60, 0x42, + 0x0a, 0x21, 0x00, 0x21, 0x68, 0x45, 0x83, 0x58, 0x14, 0x77, 0x12, 0xf2, + 0x9f, 0x25, 0x02, 0x13, 0xc3, 0x41, 0xa0, 0x00, 0xcc, 0x49, 0xb9, 0x61, + 0x00, 0x25, 0x8d, 0x1f, 0xa0, 0x00, 0x25, 0x4a, 0xe5, 0xa1, 0x10, 0x19, + 0x00, 0x04, 0xca, 0xa1, 0x00, 0xad, 0xca, 0xc6, 0xf0, 0x26, 0x40, 0x73, + 0x13, 0x00, 0x40, 0x90, 0x09, 0x09, 0x10, 0x20, 0x8d, 0x58, 0xca, 0xc6, + 0x8b, 0x58, 0xca, 0xc6, 0x00, 0x41, 0x14, 0x70, 0x0c, 0x70, 0xe0, 0x7c, + 0xab, 0x11, 0x80, 0x00, 0x14, 0x70, 0x0c, 0x71, 0xe0, 0x7d, 0xac, 0x11, + 0x81, 0x00, 0x34, 0x70, 0xe0, 0x7d, 0xe0, 0x7f, 0x0c, 0x70, 0xe0, 0x78, + 0xec, 0xc3, 0xa1, 0xc1, 0x34, 0x58, 0x10, 0x40, 0x3e, 0x58, 0x08, 0x47, + 0x2e, 0x58, 0x08, 0x46, 0x2f, 0x58, 0x08, 0x45, 0x10, 0xd8, 0x8d, 0x58, + 0x8a, 0x21, 0x82, 0x2c, 0xff, 0xd9, 0x0c, 0x70, 0x10, 0xb9, 0x80, 0xc2, + 0x56, 0x0e, 0xaf, 0xf6, 0x6c, 0x77, 0x00, 0xc0, 0x78, 0xe8, 0x4a, 0x22, + 0x00, 0x24, 0x00, 0x1e, 0x42, 0x74, 0xf0, 0x00, 0x4b, 0x00, 0x03, 0xf0, + 0x00, 0xc0, 0x11, 0x20, 0x80, 0x84, 0x3c, 0xf2, 0x2f, 0x20, 0x87, 0x04, + 0x1d, 0x08, 0x10, 0x04, 0x4b, 0x08, 0xb0, 0x04, 0x91, 0xe0, 0x34, 0xf4, + 0x02, 0x40, 0xc1, 0x41, 0xe1, 0x42, 0xa1, 0x43, 0x99, 0x5a, 0x4c, 0x20, + 0xc0, 0x88, 0x2c, 0xf4, 0x00, 0x16, 0x00, 0x70, 0xa0, 0x00, 0xe0, 0x86, + 0x2c, 0x70, 0x4c, 0x77, 0x5a, 0x0f, 0x6f, 0xf6, 0x6c, 0x70, 0x78, 0xe8, + 0x02, 0x40, 0xc1, 0x41, 0xe1, 0x42, 0xa1, 0x43, 0x98, 0x5a, 0x00, 0x16, + 0x00, 0x70, 0xa0, 0x00, 0xe0, 0x86, 0x2c, 0x70, 0x4c, 0x70, 0x9a, 0x08, + 0xaf, 0xf6, 0x6c, 0x70, 0x12, 0xf0, 0x2f, 0x27, 0xff, 0x00, 0x6f, 0x23, + 0x3f, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0x74, 0x49, 0x26, 0x80, 0x47, 0x80, + 0x18, 0x18, 0x01, 0x00, 0x1c, 0x18, 0x01, 0x00, 0x2f, 0x26, 0xff, 0x00, + 0xff, 0xd8, 0x45, 0x58, 0x46, 0x71, 0x4c, 0x22, 0xc0, 0xa4, 0x80, 0x07, + 0xce, 0xff, 0xae, 0xf1, 0x7f, 0xdc, 0x17, 0xbc, 0xc3, 0x43, 0x80, 0x3f, + 0x50, 0xb5, 0xc3, 0x42, 0x85, 0x3f, 0xc2, 0x03, 0xc3, 0x41, 0x73, 0x3f, + 0x31, 0x86, 0x83, 0xa0, 0x62, 0xa0, 0x41, 0xa0, 0x10, 0x18, 0x50, 0x00, + 0x2c, 0x70, 0x8d, 0x02, 0x6f, 0xf4, 0x1a, 0xda, 0x00, 0x1e, 0x02, 0x70, + 0xa0, 0x00, 0xb8, 0x86, 0xe0, 0x7e, 0xe0, 0x78, 0xc3, 0x43, 0x13, 0x00, + 0xf8, 0x6a, 0x42, 0xa3, 0x21, 0xa3, 0xe0, 0x7f, 0x00, 0xa3, 0xe0, 0x78, + 0xf1, 0xc0, 0x2c, 0x71, 0x00, 0x29, 0x00, 0x00, 0xb3, 0x5a, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0x2c, 0x71, 0x00, 0x29, 0x00, 0x00, + 0xb4, 0x5a, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xf1, 0xc0, 0x2c, 0x71, + 0x00, 0x29, 0x00, 0x00, 0x8e, 0x58, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0x2f, 0x27, 0xff, 0x00, 0x6f, 0x23, 0x3f, 0x00, 0xc3, 0x42, 0xa0, 0x00, + 0x78, 0x6e, 0x20, 0x82, 0x25, 0x78, 0x00, 0xa2, 0x2f, 0x26, 0xff, 0x00, + 0xc3, 0x40, 0xf0, 0x00, 0x40, 0x01, 0x00, 0x18, 0x01, 0x02, 0xe0, 0x7e, + 0xe4, 0xc3, 0xa1, 0xc1, 0x08, 0x45, 0x2f, 0x27, 0x7f, 0x00, 0x6f, 0x23, + 0x3f, 0x00, 0xaa, 0x20, 0x90, 0x02, 0xab, 0x20, 0xd0, 0x02, 0xcb, 0x46, + 0xa0, 0x00, 0x78, 0x6e, 0xaa, 0x20, 0x88, 0x01, 0x0f, 0x78, 0x14, 0x73, + 0x0c, 0xf7, 0x00, 0x86, 0xa5, 0x78, 0x00, 0xa6, 0x2f, 0x26, 0x7f, 0x00, + 0xc3, 0x40, 0xf0, 0x00, 0x40, 0x01, 0x00, 0x18, 0x01, 0x02, 0xc4, 0xc7, + 0x2f, 0x26, 0x7f, 0x00, 0xd2, 0x0b, 0x8f, 0xf6, 0x3d, 0x08, 0x70, 0x00, + 0x2f, 0x21, 0x48, 0x83, 0x00, 0x1c, 0x01, 0x30, 0x05, 0xf2, 0xc3, 0x40, + 0xa0, 0x00, 0x00, 0x87, 0x09, 0xf0, 0x04, 0x25, 0x81, 0x9f, 0xff, 0x00, + 0x00, 0x00, 0x11, 0xf2, 0xc3, 0x40, 0xa0, 0x00, 0xe4, 0x86, 0x00, 0x80, + 0x4c, 0x71, 0x6c, 0x70, 0xee, 0x0a, 0xaf, 0xf6, 0x40, 0x24, 0x04, 0x30, + 0x00, 0xc0, 0x04, 0xe8, 0x3a, 0x0b, 0xcf, 0xf7, 0xc4, 0xc7, 0x04, 0x25, + 0x81, 0x9f, 0x00, 0x0f, 0x00, 0x00, 0x04, 0xf2, 0x02, 0x86, 0xf0, 0xe8, + 0x6c, 0x25, 0xc1, 0x96, 0xf2, 0xf3, 0x01, 0x86, 0xea, 0xe8, 0xf0, 0xf1, + 0xe2, 0xc2, 0x76, 0x0b, 0xaf, 0xf6, 0x08, 0x45, 0x2d, 0x08, 0x70, 0x00, + 0x2f, 0x21, 0x48, 0x83, 0x05, 0xf2, 0xc3, 0x40, 0xa0, 0x00, 0x00, 0x87, + 0x09, 0xf0, 0x04, 0x25, 0x81, 0x9f, 0xff, 0x00, 0x00, 0x00, 0x0b, 0xf2, + 0xc3, 0x40, 0xa0, 0x00, 0xe4, 0x86, 0x00, 0x80, 0x4c, 0x71, 0x12, 0x0a, + 0xaf, 0xf6, 0x6c, 0x70, 0xc2, 0xc6, 0x04, 0x25, 0x81, 0x9f, 0x00, 0x0f, + 0x00, 0x00, 0xc3, 0x42, 0xa0, 0x00, 0x78, 0x6e, 0x03, 0xf2, 0x02, 0x82, + 0xf2, 0xe8, 0x6c, 0x25, 0xc1, 0x96, 0xf4, 0xf3, 0x01, 0x82, 0xee, 0xe8, + 0xf0, 0xf1, 0xe0, 0x78, 0xf1, 0xc0, 0x62, 0xb8, 0x39, 0x08, 0xf5, 0x00, + 0xa1, 0xc1, 0x0f, 0x78, 0xf0, 0x26, 0x00, 0x70, 0xa0, 0x00, 0x64, 0xe7, + 0x07, 0xe9, 0x2c, 0x71, 0x4c, 0x73, 0xce, 0x09, 0xaf, 0xf6, 0x6c, 0x70, + 0x0e, 0xf0, 0x2c, 0x71, 0x4c, 0x73, 0x6c, 0x70, 0x40, 0x24, 0x04, 0x30, + 0x3e, 0x0a, 0xaf, 0xf6, 0x00, 0x1c, 0x01, 0x30, 0x00, 0xc0, 0x04, 0xe8, + 0x8a, 0x0a, 0xcf, 0xf7, 0x87, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, + 0xf1, 0xc0, 0x9f, 0x20, 0x02, 0x03, 0x00, 0x20, 0x81, 0x0f, 0xa0, 0x00, + 0x25, 0x4a, 0x00, 0x89, 0x05, 0xe8, 0x0d, 0x78, 0x00, 0x19, 0xc3, 0x0f, + 0x85, 0x58, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0xe4, 0xc2, 0x08, 0x46, + 0x12, 0x58, 0x08, 0x45, 0xa4, 0x16, 0x00, 0x11, 0xb5, 0x70, 0xca, 0x25, + 0x61, 0x10, 0xb1, 0x70, 0x0c, 0x70, 0x0a, 0xf2, 0x56, 0x86, 0x05, 0xea, + 0xb0, 0x78, 0x60, 0x7a, 0xc1, 0x41, 0x0c, 0x71, 0xa4, 0x1e, 0x44, 0x13, + 0xc4, 0xc6, 0xe0, 0x78, 0xea, 0xc2, 0x8c, 0xdb, 0x0a, 0x7b, 0x08, 0x45, + 0xc3, 0x40, 0xa0, 0x00, 0x24, 0x4a, 0x1f, 0x63, 0x00, 0x8f, 0x28, 0x46, + 0x50, 0x40, 0x35, 0xe9, 0xb2, 0xe8, 0xc3, 0x40, 0xa0, 0x00, 0x64, 0x41, + 0x21, 0x8f, 0xb6, 0x78, 0x41, 0x80, 0xe0, 0x80, 0x8c, 0x21, 0xc3, 0x8f, + 0xcb, 0x44, 0xa0, 0x00, 0xcc, 0x49, 0x06, 0xf2, 0x78, 0x64, 0x0a, 0x80, + 0x45, 0x0e, 0x05, 0x10, 0x16, 0x6e, 0x41, 0x2e, 0x8b, 0x16, 0x00, 0x27, + 0x11, 0x90, 0x01, 0x22, 0xcf, 0x82, 0x8c, 0x21, 0xc3, 0x8f, 0x10, 0xf2, + 0x78, 0x64, 0x25, 0x80, 0x44, 0x80, 0x3b, 0x27, 0x40, 0x10, 0x3d, 0x21, + 0x82, 0x20, 0x30, 0x77, 0xca, 0x20, 0x81, 0x00, 0x8c, 0xe8, 0x52, 0x0f, + 0xef, 0xff, 0xa1, 0x40, 0xc1, 0x40, 0x22, 0x41, 0xe1, 0x42, 0xa1, 0x43, + 0x3a, 0x0c, 0xef, 0xff, 0x0a, 0x24, 0x00, 0x04, 0xca, 0xc6, 0x92, 0xe8, + 0x36, 0x0f, 0xef, 0xff, 0xa1, 0x40, 0xa1, 0x40, 0x9f, 0x20, 0x02, 0x03, + 0xc3, 0x42, 0xa0, 0x00, 0xcc, 0x49, 0x2c, 0x70, 0x58, 0x60, 0x00, 0x1f, + 0x43, 0x10, 0x25, 0xa0, 0x24, 0xa0, 0x2a, 0xa0, 0xf0, 0x26, 0x40, 0x73, + 0x13, 0x00, 0x40, 0x90, 0x09, 0x08, 0x10, 0x20, 0x8d, 0x58, 0xca, 0xc6, + 0x8b, 0x58, 0xca, 0xc6, 0xe2, 0xc2, 0x59, 0x88, 0xc1, 0xba, 0x54, 0x72, + 0x17, 0xf2, 0x2f, 0x27, 0x7f, 0x03, 0x6f, 0x23, 0x3f, 0x00, 0x50, 0x80, + 0x04, 0x32, 0x40, 0x80, 0x0d, 0xf2, 0x4c, 0x70, 0x04, 0x31, 0x80, 0x80, + 0xc5, 0xf7, 0x30, 0xa0, 0x0e, 0x18, 0x43, 0x00, 0x03, 0xf0, 0x13, 0x18, + 0x43, 0x00, 0x10, 0xd8, 0x8d, 0x58, 0x2f, 0x26, 0x7f, 0x03, 0xc2, 0xc6, + 0xe2, 0xc2, 0x59, 0x88, 0xc1, 0xba, 0x54, 0x72, 0x11, 0xf2, 0x2f, 0x27, + 0x7f, 0x03, 0x6f, 0x23, 0x3f, 0x00, 0x4c, 0x10, 0x02, 0x01, 0x13, 0x0a, + 0x40, 0x00, 0x4c, 0x18, 0x44, 0x00, 0x0f, 0x18, 0x43, 0x00, 0x10, 0xd8, + 0x8d, 0x58, 0x2f, 0x26, 0x7f, 0x03, 0xc2, 0xc6, 0xe6, 0xc3, 0xa4, 0xc1, + 0x08, 0x45, 0x19, 0x88, 0x28, 0x46, 0xc1, 0xb8, 0x14, 0x72, 0x27, 0xf2, + 0x40, 0x24, 0xc1, 0x33, 0x83, 0xc2, 0x40, 0x24, 0x83, 0x32, 0x40, 0x24, + 0x04, 0x30, 0x40, 0x24, 0x05, 0x31, 0xa1, 0x40, 0x39, 0x58, 0x00, 0xc1, + 0xc1, 0x40, 0x4c, 0x70, 0x04, 0x31, 0x80, 0x83, 0xca, 0x20, 0x45, 0x00, + 0x04, 0x31, 0x80, 0x80, 0xca, 0x26, 0x09, 0x10, 0x2f, 0x27, 0xff, 0x03, + 0x6f, 0x23, 0x3f, 0x00, 0x10, 0x85, 0x04, 0x30, 0x80, 0x83, 0x07, 0xf2, + 0x10, 0xd8, 0xd0, 0xa5, 0x0e, 0x1d, 0x43, 0x10, 0x8d, 0x58, 0x2f, 0x26, + 0xff, 0x03, 0xc6, 0xc7, 0xcb, 0x44, 0x13, 0x00, 0xc8, 0xaa, 0x80, 0x84, + 0x95, 0x70, 0xe0, 0x20, 0x02, 0x03, 0xe0, 0x7e, 0xcb, 0x44, 0x13, 0x00, + 0xc4, 0xaa, 0x80, 0x84, 0x95, 0x70, 0xe0, 0x7c, 0x00, 0x7c, 0xe0, 0x78, + 0xe8, 0xc2, 0x96, 0x0a, 0xcf, 0xf7, 0xcb, 0x45, 0x13, 0x00, 0x90, 0xaa, + 0x2a, 0x85, 0x10, 0x40, 0x92, 0x0a, 0xef, 0xf7, 0x09, 0x69, 0x4d, 0x08, + 0x74, 0x02, 0x08, 0x46, 0x08, 0x85, 0x86, 0x0a, 0xef, 0xf7, 0x04, 0x77, + 0x8a, 0x0d, 0xef, 0xec, 0x08, 0x47, 0x39, 0x0f, 0x75, 0x12, 0x21, 0x6f, + 0x55, 0x26, 0x83, 0x1f, 0x2f, 0x79, 0x40, 0x20, 0xc2, 0x20, 0x6f, 0x7e, + 0x08, 0x20, 0x40, 0x00, 0x4f, 0x7a, 0xd9, 0x60, 0x25, 0x0a, 0x64, 0x00, + 0x2c, 0x71, 0x0f, 0x78, 0x86, 0x0d, 0xef, 0xec, 0xc1, 0x41, 0x3a, 0x0e, + 0xef, 0xec, 0xc1, 0x40, 0x0a, 0x0c, 0x60, 0x01, 0x00, 0x85, 0xc8, 0xc6, + 0x2f, 0xd8, 0xb2, 0x09, 0xef, 0xeb, 0x2c, 0x71, 0xaa, 0x09, 0xef, 0xeb, + 0x2d, 0xd8, 0xe0, 0x78, 0xc3, 0x40, 0x13, 0x00, 0x8c, 0xaa, 0xfd, 0x05, + 0xaf, 0xf4, 0x00, 0x80, 0xea, 0xc2, 0xcb, 0x45, 0x13, 0x00, 0x94, 0xaa, + 0x00, 0x85, 0x21, 0x85, 0xe4, 0x85, 0xc5, 0x85, 0x02, 0x79, 0x26, 0xb9, + 0x1e, 0x21, 0x81, 0x0f, 0xaa, 0xaa, 0xab, 0xaa, 0x08, 0x15, 0x11, 0x10, + 0x0c, 0x15, 0x10, 0x10, 0x4a, 0x0e, 0xaf, 0xf4, 0x2f, 0x79, 0x02, 0x85, + 0xf2, 0x4e, 0x02, 0x20, 0x41, 0x24, 0x27, 0xb9, 0x27, 0xba, 0x2f, 0x79, + 0x96, 0x0e, 0xaf, 0xf4, 0x4f, 0x7a, 0xca, 0xc6, 0xe4, 0xc2, 0xcb, 0x45, + 0x13, 0x00, 0xac, 0xaa, 0xf2, 0x0a, 0xef, 0xec, 0xc0, 0x85, 0x63, 0x85, + 0x42, 0x85, 0x00, 0x41, 0x64, 0x77, 0xc1, 0x40, 0xa5, 0x5a, 0xc4, 0xc6, + 0xf1, 0xc0, 0x5a, 0xd8, 0xab, 0x20, 0x08, 0x0e, 0x97, 0x5a, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xe2, 0xc2, 0x28, 0x45, 0x20, 0x81, 0x40, 0x43, + 0x10, 0xda, 0x19, 0x61, 0x7e, 0x0d, 0x2f, 0xf4, 0x60, 0x40, 0x00, 0x85, + 0x10, 0xe0, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0xe6, 0xc3, 0xa4, 0xc1, + 0x68, 0x45, 0x60, 0x83, 0x28, 0x46, 0x10, 0xe3, 0x2b, 0x0a, 0xe4, 0x00, + 0x00, 0x41, 0x80, 0xc0, 0x10, 0xda, 0xa2, 0x0f, 0x2f, 0xe6, 0x80, 0xc7, + 0x4a, 0x24, 0x00, 0x74, 0xa8, 0x20, 0x00, 0x02, 0x00, 0x85, 0x01, 0x17, + 0x81, 0x14, 0xd8, 0x60, 0xc5, 0x71, 0x20, 0xa8, 0x00, 0x85, 0x10, 0xe0, + 0x00, 0xa5, 0xc6, 0xc7, 0xe2, 0xc2, 0x08, 0x45, 0x00, 0x90, 0xd3, 0x70, + 0x00, 0x00, 0x2b, 0x66, 0x1c, 0xd8, 0x17, 0xf4, 0x5e, 0x85, 0x78, 0xd9, + 0xe2, 0x0d, 0xaf, 0xe9, 0xa1, 0x40, 0x14, 0x70, 0x1d, 0xd8, 0x0f, 0xf2, + 0x4a, 0x24, 0x00, 0x71, 0x0c, 0x70, 0x4c, 0x70, 0xa8, 0x20, 0x40, 0x02, + 0x4f, 0x79, 0x15, 0x25, 0x41, 0x10, 0x4b, 0x11, 0x01, 0x06, 0x04, 0xe9, + 0x44, 0x71, 0xc2, 0xc6, 0x1e, 0xd8, 0xc2, 0xc6, 0xe4, 0xc3, 0xa1, 0xc1, + 0x0f, 0x7d, 0x11, 0x0d, 0xb5, 0x11, 0x0c, 0x73, 0x48, 0x25, 0x80, 0x10, + 0x80, 0x20, 0x83, 0x0f, 0xd3, 0x68, 0xc3, 0x40, 0xa0, 0x00, 0x74, 0x49, + 0x84, 0x26, 0x1f, 0x1e, 0x1e, 0x66, 0x2c, 0x77, 0x0c, 0x70, 0x80, 0xc2, + 0x62, 0x08, 0xaf, 0xf6, 0x20, 0x43, 0x00, 0xc0, 0x79, 0xe8, 0x9e, 0x78, + 0x41, 0x86, 0x20, 0x86, 0x04, 0x1e, 0x01, 0x10, 0x00, 0x1e, 0x01, 0x10, + 0xbe, 0x78, 0xa1, 0x40, 0x45, 0x58, 0xef, 0xf1, 0xe2, 0xc3, 0x08, 0x45, + 0x01, 0x80, 0x84, 0x20, 0x03, 0x0c, 0x15, 0x08, 0x31, 0x04, 0xa1, 0xc1, + 0x0e, 0x8d, 0x00, 0x15, 0x04, 0x10, 0x1d, 0x78, 0xa1, 0x5a, 0xc2, 0xc7, + 0xff, 0xd8, 0x40, 0xc0, 0xc3, 0x44, 0x13, 0x00, 0x24, 0x1a, 0x40, 0x24, + 0x05, 0x30, 0xa1, 0x40, 0xb5, 0x5a, 0xa1, 0x40, 0x17, 0x58, 0x00, 0xc0, + 0xc2, 0xc7, 0xe0, 0x78, 0xe2, 0xc2, 0x28, 0x45, 0x20, 0x81, 0x40, 0x43, + 0x18, 0xda, 0x19, 0x61, 0x6a, 0x0c, 0x2f, 0xf4, 0x60, 0x40, 0x00, 0x85, + 0x18, 0xe0, 0x00, 0xa5, 0xc2, 0xc6, 0xe0, 0x78, 0xe6, 0xc3, 0xa6, 0xc1, + 0x68, 0x45, 0x60, 0x83, 0x28, 0x46, 0x18, 0xe3, 0x2b, 0x0a, 0xe4, 0x00, + 0x00, 0x41, 0x80, 0xc0, 0x18, 0xda, 0x8e, 0x0e, 0x2f, 0xe6, 0x80, 0xc7, + 0x4a, 0x24, 0x00, 0x76, 0xa8, 0x20, 0x00, 0x02, 0x00, 0x85, 0x01, 0x17, + 0x81, 0x14, 0xd8, 0x60, 0xc5, 0x71, 0x20, 0xa8, 0x00, 0x85, 0x18, 0xe0, + 0x00, 0xa5, 0xc6, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0xbd, 0x37, 0x86, 0x35, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xbd, 0x37, 0x86, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x37, 0x86, 0x35, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xb7, 0xd1, 0x38, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x17, 0xb7, 0xd1, 0x38, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x17, 0xb7, 0xd1, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0x41, 0x32, 0x00, 0xac, 0xc5, 0xa7, 0x36, 0xac, 0xc5, 0xa7, 0x36, + 0xac, 0xc5, 0xa7, 0x36, 0x00, 0x00, 0x00, 0x00, 0xac, 0xc5, 0x27, 0x37, + 0xac, 0xc5, 0x27, 0x37, 0xac, 0xc5, 0x27, 0x37, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0xd3, 0x02, 0x37, 0x38, 0xa9, 0x68, 0x12, 0x37, 0xa9, 0x68, 0x92, 0x36, + 0x35, 0xfa, 0x8e, 0x37, 0x88, 0xc3, 0x64, 0x36, 0x88, 0xc3, 0xe4, 0x35, + 0xdb, 0x0f, 0x49, 0x40, 0xf3, 0x66, 0xdf, 0x3e, 0xc2, 0xb8, 0xb2, 0x3d, + 0x02, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, + 0x2d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x29, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, + 0x35, 0xfa, 0x0e, 0x3c, 0x88, 0xc3, 0xe4, 0x3a, 0x88, 0xc3, 0x64, 0x3a, + 0xf3, 0x66, 0x5f, 0x3f, 0xf3, 0x66, 0xdf, 0x3e, 0x50, 0x77, 0x56, 0x3e, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x14, 0x05, 0x14, 0x05, + 0xc4, 0x09, 0x00, 0x00, 0x06, 0x06, 0x06, 0x04, 0x04, 0x04, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3f, 0x9a, 0x99, 0x19, 0x3e, 0x9a, 0x99, 0x99, 0x3d, + 0x0a, 0xd7, 0xa3, 0x3c, 0x0a, 0xd7, 0xa3, 0x3c, 0x0a, 0xd7, 0xa3, 0x3c, + 0xbd, 0x37, 0x86, 0x35, 0xbd, 0x37, 0x86, 0x35, 0xbd, 0x37, 0x86, 0x35, + 0x00, 0x24, 0xf4, 0x49, 0x00, 0x24, 0xf4, 0x49, 0x00, 0x24, 0xf4, 0x49, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, + 0xba, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, + 0x88, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x00, + 0x66, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, + 0x6c, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, + 0x72, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0xe6, 0x00, 0x00, 0x00, + 0xf6, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, 0x00, + 0x9c, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, + 0x8e, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, + 0x84, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, + 0xa4, 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x17, 0xb7, 0x51, 0x39, 0x6f, 0x12, 0x03, 0x3b, 0x53, 0x05, 0xa3, 0x3c, + 0xb6, 0xf3, 0x3d, 0x3e, 0x8c, 0xe0, 0x5a, 0x3c, 0x8c, 0xe0, 0xda, 0x3c, + 0x8c, 0xe0, 0x5a, 0x3c, 0x00, 0x00, 0x80, 0x3f, 0xf8, 0xdf, 0xd2, 0xbf, + 0xf9, 0x6d, 0x33, 0x3f, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4c, 0x8e, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0xd4, 0x78, 0xa0, 0x00, + 0x77, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0xac, 0x8d, 0x13, 0x00, + 0x44, 0x54, 0x13, 0x00, 0xd8, 0x83, 0xa0, 0x00, 0x79, 0x00, 0x04, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xbc, 0x8d, 0x13, 0x00, 0x44, 0x54, 0x13, 0x00, + 0x00, 0x84, 0xa0, 0x00, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xcc, 0x8d, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0xdc, 0x76, 0xa0, 0x00, + 0x75, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0xdc, 0x8d, 0x13, 0x00, + 0x44, 0x54, 0x13, 0x00, 0x28, 0x84, 0xa0, 0x00, 0xbd, 0x02, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xec, 0x8d, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x30, 0x77, 0xa0, 0x00, 0xc1, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x8e, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x4c, 0x77, 0xa0, 0x00, + 0xc3, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x8e, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x68, 0x77, 0xa0, 0x00, 0x15, 0x00, 0x00, 0x00, + 0x84, 0x6e, 0xa0, 0x00, 0x04, 0x01, 0x00, 0x00, 0xfc, 0x8d, 0x13, 0x00, + 0x48, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, 0xa0, 0x2d, 0x13, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x66, 0x11, 0x00, + 0x34, 0x66, 0x11, 0x00, 0x04, 0x66, 0x11, 0x00, 0x40, 0x66, 0x11, 0x00, + 0x1c, 0x66, 0x11, 0x00, 0x10, 0x66, 0x11, 0x00, 0x28, 0x66, 0x11, 0x00, + 0x48, 0x70, 0xa0, 0x00, 0xe4, 0x9f, 0xa0, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x84, 0x6e, 0xa0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x2c, 0x8e, 0x13, 0x00, + 0x50, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, 0xf8, 0x2e, 0x13, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x13, 0x00, + 0xf0, 0x2f, 0x13, 0x00, 0xc0, 0x2f, 0x13, 0x00, 0xf8, 0x2f, 0x13, 0x00, + 0xd8, 0x2f, 0x13, 0x00, 0xd0, 0x2f, 0x13, 0x00, 0xe8, 0x2f, 0x13, 0x00, + 0x58, 0x70, 0xa0, 0x00, 0xb8, 0xa4, 0xa0, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x84, 0x6e, 0xa0, 0x00, 0x04, 0x03, 0x00, 0x00, 0x30, 0x74, 0x13, 0x00, + 0xc8, 0x8c, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, 0x0c, 0x31, 0x13, 0x00, + 0x08, 0x33, 0x13, 0x00, 0x98, 0x32, 0x13, 0x00, 0x38, 0x34, 0x13, 0x00, + 0xf8, 0x32, 0x13, 0x00, 0x70, 0x32, 0x13, 0x00, 0x00, 0x33, 0x13, 0x00, + 0x88, 0x32, 0x13, 0x00, 0x80, 0x32, 0x13, 0x00, 0xf0, 0x32, 0x13, 0x00, + 0x70, 0x70, 0xa0, 0x00, 0x78, 0x98, 0xa0, 0x00, 0x01, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa4, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x18, 0x76, 0xa0, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb0, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x88, 0x76, 0xa0, 0x00, + 0x65, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x8c, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x14, 0x77, 0xa0, 0x00, 0x23, 0x03, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xd4, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0xa0, 0x77, 0xa0, 0x00, 0x25, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0xbc, 0x77, 0xa0, 0x00, + 0x29, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x8c, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0xd8, 0x77, 0xa0, 0x00, 0x05, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x8d, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x64, 0x78, 0xa0, 0x00, 0x7b, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x28, 0x8d, 0x13, 0x00, 0x44, 0x54, 0x13, 0x00, 0x50, 0x84, 0xa0, 0x00, + 0x6d, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x8d, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x0c, 0x79, 0xa0, 0x00, 0x7d, 0x00, 0x03, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x58, 0x8d, 0x13, 0x00, 0x44, 0x54, 0x13, 0x00, + 0x78, 0x84, 0xa0, 0x00, 0x81, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x7c, 0x8d, 0x13, 0x00, 0x44, 0x54, 0x13, 0x00, 0xa0, 0x84, 0xa0, 0x00, + 0x41, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x8d, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0xd0, 0x79, 0xa0, 0x00, 0x39, 0x01, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa0, 0x8d, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x08, 0x7a, 0xa0, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, + 0x03, 0x01, 0x00, 0x00, 0xf8, 0x8c, 0x13, 0x00, 0x60, 0x8b, 0x13, 0x00, + 0xbc, 0x6e, 0xa0, 0x00, 0x40, 0x34, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc4, 0x35, 0x13, 0x00, 0xb4, 0x35, 0x13, 0x00, + 0x84, 0x35, 0x13, 0x00, 0xbc, 0x35, 0x13, 0x00, 0x9c, 0x35, 0x13, 0x00, + 0x94, 0x35, 0x13, 0x00, 0xac, 0x35, 0x13, 0x00, 0x78, 0x70, 0xa0, 0x00, + 0xf0, 0x9e, 0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, + 0x03, 0x03, 0x00, 0x00, 0x34, 0x8d, 0x13, 0x00, 0x1c, 0x8d, 0x13, 0x00, + 0xb4, 0x6e, 0xa0, 0x00, 0x08, 0x38, 0x13, 0x00, 0x00, 0x39, 0x13, 0x00, + 0xe4, 0x38, 0x13, 0x00, 0x04, 0x39, 0x13, 0x00, 0xf0, 0x38, 0x13, 0x00, + 0xbc, 0x38, 0x13, 0x00, 0xf8, 0x38, 0x13, 0x00, 0xd4, 0x38, 0x13, 0x00, + 0xcc, 0x38, 0x13, 0x00, 0xe8, 0x38, 0x13, 0x00, 0xc8, 0x70, 0xa0, 0x00, + 0xd8, 0x99, 0xa0, 0x00, 0x07, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, + 0x03, 0x03, 0x00, 0x00, 0x64, 0x8d, 0x13, 0x00, 0x4c, 0x8d, 0x13, 0x00, + 0xb4, 0x6e, 0xa0, 0x00, 0x0c, 0x39, 0x13, 0x00, 0x0c, 0x3a, 0x13, 0x00, + 0xf0, 0x39, 0x13, 0x00, 0x10, 0x3a, 0x13, 0x00, 0xfc, 0x39, 0x13, 0x00, + 0xc8, 0x39, 0x13, 0x00, 0x04, 0x3a, 0x13, 0x00, 0xe0, 0x39, 0x13, 0x00, + 0xd8, 0x39, 0x13, 0x00, 0xf4, 0x39, 0x13, 0x00, 0xd4, 0x70, 0xa0, 0x00, + 0x24, 0x9a, 0xa0, 0x00, 0x09, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, + 0x03, 0x03, 0x00, 0x00, 0x88, 0x8d, 0x13, 0x00, 0x70, 0x8d, 0x13, 0x00, + 0xb4, 0x6e, 0xa0, 0x00, 0x18, 0x3a, 0x13, 0x00, 0x08, 0x3b, 0x13, 0x00, + 0xec, 0x3a, 0x13, 0x00, 0x0c, 0x3b, 0x13, 0x00, 0xf8, 0x3a, 0x13, 0x00, + 0xc4, 0x3a, 0x13, 0x00, 0x00, 0x3b, 0x13, 0x00, 0xdc, 0x3a, 0x13, 0x00, + 0xd4, 0x3a, 0x13, 0x00, 0xf0, 0x3a, 0x13, 0x00, 0xe0, 0x70, 0xa0, 0x00, + 0x70, 0x9a, 0xa0, 0x00, 0xcb, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xcc, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0xfc, 0x75, 0xa0, 0x00, + 0x2d, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x8b, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x34, 0x76, 0xa0, 0x00, 0x55, 0x01, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xe4, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x6c, 0x76, 0xa0, 0x00, 0x65, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0xa4, 0x76, 0xa0, 0x00, + 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x8c, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0xc0, 0x76, 0xa0, 0x00, 0x4f, 0x01, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2c, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x84, 0x77, 0xa0, 0x00, 0x63, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x10, 0x78, 0xa0, 0x00, + 0x51, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x8c, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0xb8, 0x78, 0xa0, 0x00, 0x89, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x5c, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0xf0, 0x78, 0xa0, 0x00, 0x87, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x64, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x28, 0x79, 0xa0, 0x00, + 0x71, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x8c, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x44, 0x79, 0xa0, 0x00, 0x85, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x74, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x60, 0x79, 0xa0, 0x00, 0x4b, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7c, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x7c, 0x79, 0xa0, 0x00, + 0x5d, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x8c, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x98, 0x79, 0xa0, 0x00, 0x4d, 0x01, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0xec, 0x79, 0xa0, 0x00, 0x5b, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9c, 0x8c, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x5c, 0x7a, 0xa0, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x02, 0x01, 0x00, 0x00, + 0xec, 0x8b, 0x13, 0x00, 0x2c, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xf4, 0x62, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x98, 0x63, 0x11, 0x00, 0x80, 0x63, 0x11, 0x00, 0x50, 0x63, 0x11, 0x00, + 0x8c, 0x63, 0x11, 0x00, 0x68, 0x63, 0x11, 0x00, 0x5c, 0x63, 0x11, 0x00, + 0x74, 0x63, 0x11, 0x00, 0x00, 0x70, 0xa0, 0x00, 0x14, 0xa1, 0xa0, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x02, 0x01, 0x00, 0x00, + 0x24, 0x8c, 0x13, 0x00, 0x4c, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x78, 0x2e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x66, 0x11, 0x00, 0xc8, 0x66, 0x11, 0x00, 0x98, 0x66, 0x11, 0x00, + 0xd4, 0x66, 0x11, 0x00, 0xb0, 0x66, 0x11, 0x00, 0xa4, 0x66, 0x11, 0x00, + 0xbc, 0x66, 0x11, 0x00, 0x50, 0x70, 0xa0, 0x00, 0x6c, 0x9c, 0xa0, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x02, 0x02, 0x00, 0x00, + 0x44, 0x8c, 0x13, 0x00, 0x3c, 0x8c, 0x13, 0x00, 0xbc, 0x6e, 0xa0, 0x00, + 0xf0, 0x6d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x38, 0x6f, 0x11, 0x00, 0x20, 0x6f, 0x11, 0x00, 0xf0, 0x6e, 0x11, 0x00, + 0x2c, 0x6f, 0x11, 0x00, 0x08, 0x6f, 0x11, 0x00, 0xfc, 0x6e, 0x11, 0x00, + 0x14, 0x6f, 0x11, 0x00, 0x9c, 0x70, 0xa0, 0x00, 0x5c, 0xa7, 0xa0, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x02, 0x01, 0x00, 0x00, + 0x4c, 0x8c, 0x13, 0x00, 0x74, 0x8b, 0x13, 0x00, 0xbc, 0x6e, 0xa0, 0x00, + 0x90, 0x36, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd4, 0x37, 0x13, 0x00, 0xc4, 0x37, 0x13, 0x00, 0x94, 0x37, 0x13, 0x00, + 0xcc, 0x37, 0x13, 0x00, 0xac, 0x37, 0x13, 0x00, 0xa4, 0x37, 0x13, 0x00, + 0xbc, 0x37, 0x13, 0x00, 0xa0, 0x70, 0xa0, 0x00, 0x1c, 0xaa, 0xa0, 0x00, + 0x29, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x02, 0x01, 0x00, 0x00, + 0x94, 0x8c, 0x13, 0x00, 0xbc, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xfc, 0x77, 0x11, 0x00, 0x38, 0x3d, 0x13, 0x00, 0x34, 0x3d, 0x13, 0x00, + 0x78, 0x79, 0x11, 0x00, 0xec, 0x78, 0x11, 0x00, 0x94, 0x78, 0x11, 0x00, + 0xf8, 0x78, 0x11, 0x00, 0xac, 0x78, 0x11, 0x00, 0xa0, 0x78, 0x11, 0x00, + 0xe0, 0x78, 0x11, 0x00, 0x38, 0x71, 0xa0, 0x00, 0x10, 0x99, 0xa0, 0x00, + 0x54, 0x7d, 0x13, 0x00, 0xc0, 0x7d, 0x13, 0x00, 0x9c, 0x7d, 0x13, 0x00, + 0x78, 0x7d, 0x13, 0x00, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x24, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x50, 0x76, 0xa0, 0x00, + 0x47, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x8b, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0xf8, 0x76, 0xa0, 0x00, 0xd3, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x5c, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0xf4, 0x77, 0xa0, 0x00, 0xdf, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6c, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x2c, 0x78, 0xa0, 0x00, + 0xe7, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x8b, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0x48, 0x78, 0xa0, 0x00, 0x31, 0x01, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x80, 0x78, 0xa0, 0x00, 0xdd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x84, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x9c, 0x78, 0xa0, 0x00, + 0x43, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x8b, 0x13, 0x00, + 0x7c, 0xd2, 0x11, 0x00, 0xb4, 0x79, 0xa0, 0x00, 0x27, 0x03, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb8, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, + 0x24, 0x7a, 0xa0, 0x00, 0x45, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x8b, 0x13, 0x00, 0x7c, 0xd2, 0x11, 0x00, 0x40, 0x7a, 0xa0, 0x00, + 0xe4, 0x86, 0x13, 0x00, 0xc4, 0x71, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0xcc, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xc8, 0x84, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x7a, 0xa0, 0x00, + 0x9c, 0x86, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xe8, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2c, 0x73, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x28, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x7a, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x7a, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x7a, 0xa0, 0x00, + 0xc8, 0x72, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x02, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x40, 0x73, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb0, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x7a, 0xa0, 0x00, + 0xc8, 0x72, 0x13, 0x00, 0x54, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xce, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x54, 0x73, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3c, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x7b, 0xa0, 0x00, + 0x2c, 0x87, 0x13, 0x00, 0x64, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xac, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x68, 0x73, 0xa0, 0x00, + 0x74, 0x87, 0x13, 0x00, 0x78, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xae, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x7c, 0x73, 0xa0, 0x00, + 0xbc, 0x87, 0x13, 0x00, 0xdc, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xb0, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x90, 0x73, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb0, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x7b, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x8e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x50, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xec, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa0, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x7c, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb4, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x42, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2c, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xdc, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc8, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x7d, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x7e, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x7e, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x54, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x7e, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x7e, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa0, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x74, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x7e, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x54, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x62, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x7e, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb4, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x88, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x7e, 0xa0, 0x00, + 0x04, 0x88, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x16, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xa4, 0x73, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x8a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x7e, 0xa0, 0x00, + 0x8c, 0x6e, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xee, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xb8, 0x73, 0xa0, 0x00, + 0x8c, 0x6e, 0x13, 0x00, 0x88, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xbc, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xdc, 0x6e, 0xa0, 0x00, + 0x8c, 0x6e, 0x13, 0x00, 0x7c, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xc2, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf0, 0x6e, 0xa0, 0x00, + 0x8c, 0x6e, 0x13, 0x00, 0x50, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x34, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xcc, 0x73, 0xa0, 0x00, + 0x10, 0x73, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xf0, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xe0, 0x73, 0xa0, 0x00, + 0x10, 0x73, 0x13, 0x00, 0x04, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x1a, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x73, 0xa0, 0x00, + 0xd4, 0x6e, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xf2, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x74, 0xa0, 0x00, + 0xd4, 0x6e, 0x13, 0x00, 0x9c, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x9a, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x6f, 0xa0, 0x00, + 0xd4, 0x6e, 0x13, 0x00, 0x04, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x1c, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x1c, 0x74, 0xa0, 0x00, + 0xd4, 0x6e, 0x13, 0x00, 0x50, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x32, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x30, 0x74, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x7f, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x50, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x7f, 0xa0, 0x00, + 0x4c, 0x88, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x06, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x44, 0x74, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xec, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x76, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x7f, 0xa0, 0x00, + 0x1c, 0x6f, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xf4, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x18, 0x6f, 0xa0, 0x00, + 0x1c, 0x6f, 0x13, 0x00, 0x50, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x54, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x58, 0x74, 0xa0, 0x00, + 0x1c, 0x6f, 0x13, 0x00, 0x64, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x5a, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x6c, 0x74, 0xa0, 0x00, + 0x1c, 0x6f, 0x13, 0x00, 0x78, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x58, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x80, 0x74, 0xa0, 0x00, + 0x68, 0x70, 0x13, 0x00, 0x9c, 0x71, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0x96, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x85, 0xa0, 0x00, + 0x68, 0x70, 0x13, 0x00, 0xa4, 0x74, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0xb0, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x38, 0x85, 0xa0, 0x00, + 0x68, 0x70, 0x13, 0x00, 0xd8, 0x71, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0xd0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x70, 0x85, 0xa0, 0x00, + 0x94, 0x88, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x14, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x94, 0x74, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x7f, 0xa0, 0x00, + 0x58, 0x73, 0x13, 0x00, 0x88, 0x71, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0xba, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xa8, 0x85, 0xa0, 0x00, + 0xa0, 0x73, 0x13, 0x00, 0x04, 0x70, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0x1e, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xe0, 0x85, 0xa0, 0x00, + 0x58, 0x73, 0x13, 0x00, 0x28, 0x6e, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0xd6, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x18, 0x86, 0xa0, 0x00, + 0xa0, 0x73, 0x13, 0x00, 0x28, 0x6e, 0x13, 0x00, 0x3c, 0xec, 0x11, 0x00, + 0x54, 0xec, 0x11, 0x00, 0x50, 0xeb, 0x11, 0x00, 0xbc, 0xeb, 0x11, 0x00, + 0xd8, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x50, 0x86, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x7f, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2c, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x7f, 0xa0, 0x00, + 0xdc, 0x88, 0x13, 0x00, 0x28, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xda, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xa8, 0x74, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xdc, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x26, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x7f, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x7f, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa0, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x80, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb4, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x80, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc8, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x56, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x80, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x80, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xcc, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x80, 0xa0, 0x00, + 0x24, 0x89, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x08, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xbc, 0x74, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x80, 0xa0, 0x00, + 0xb0, 0x70, 0x13, 0x00, 0x40, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x38, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xd0, 0x74, 0xa0, 0x00, + 0xb0, 0x70, 0x13, 0x00, 0x00, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xdc, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xe4, 0x74, 0xa0, 0x00, + 0xb0, 0x70, 0x13, 0x00, 0xc4, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xca, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf8, 0x74, 0xa0, 0x00, + 0xf8, 0x70, 0x13, 0x00, 0x68, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x3a, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x75, 0xa0, 0x00, + 0xf8, 0x70, 0x13, 0x00, 0x14, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xde, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x20, 0x75, 0xa0, 0x00, + 0xf8, 0x70, 0x13, 0x00, 0xd8, 0x71, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xce, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x75, 0xa0, 0x00, + 0x40, 0x71, 0x13, 0x00, 0xe0, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x3e, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x48, 0x75, 0xa0, 0x00, + 0x40, 0x71, 0x13, 0x00, 0x3c, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xe2, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x5c, 0x75, 0xa0, 0x00, + 0x40, 0x71, 0x13, 0x00, 0x28, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xd4, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x70, 0x75, 0xa0, 0x00, + 0x6c, 0x89, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xfc, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x84, 0x75, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x80, 0xa0, 0x00, + 0xb4, 0x89, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x0e, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x98, 0x75, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x96, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x80, 0xa0, 0x00, + 0xfc, 0x89, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0xfe, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xac, 0x75, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x64, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x81, 0xa0, 0x00, + 0x44, 0x8a, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x04, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xc0, 0x75, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa0, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x72, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x81, 0xa0, 0x00, + 0x8c, 0x8a, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xd4, 0x75, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x54, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x81, 0xa0, 0x00, + 0xe8, 0x73, 0x13, 0x00, 0xb8, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x40, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2c, 0x6f, 0xa0, 0x00, + 0xe8, 0x73, 0x13, 0x00, 0x90, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x42, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x40, 0x6f, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x81, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x28, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb6, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x81, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x81, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x81, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3c, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb8, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x81, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8c, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x8c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x50, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x52, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa0, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb4, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xba, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xd8, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2c, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf8, 0x82, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x32, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x83, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc8, 0x6f, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x58, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x83, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x6e, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x58, 0x83, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf4, 0x74, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x83, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x70, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xbc, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x98, 0x83, 0xa0, 0x00, + 0xd4, 0x8a, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0xa0, 0xec, 0x11, 0x00, 0xb4, 0xec, 0x11, 0x00, + 0x0c, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xe8, 0x75, 0xa0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb4, 0x72, 0x13, 0x00, 0xb8, 0xec, 0x11, 0x00, + 0xc4, 0xec, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x86, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb8, 0x83, 0xa0, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x20, 0x8b, 0x13, 0x00, 0x1c, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x80, 0x61, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0x61, 0x11, 0x00, 0xe4, 0x61, 0x11, 0x00, 0xb4, 0x61, 0x11, 0x00, + 0xf0, 0x61, 0x11, 0x00, 0xcc, 0x61, 0x11, 0x00, 0xc0, 0x61, 0x11, 0x00, + 0xd8, 0x61, 0x11, 0x00, 0xe8, 0x6f, 0xa0, 0x00, 0x44, 0x9d, 0xa0, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x02, 0x00, 0x00, + 0x28, 0x8b, 0x13, 0x00, 0xdc, 0x8b, 0x13, 0x00, 0xbc, 0x6e, 0xa0, 0x00, + 0x1c, 0x1e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1f, 0x13, 0x00, 0xf0, 0x1e, 0x13, 0x00, 0xc0, 0x1e, 0x13, 0x00, + 0xf8, 0x1e, 0x13, 0x00, 0xd8, 0x1e, 0x13, 0x00, 0xd0, 0x1e, 0x13, 0x00, + 0xe8, 0x1e, 0x13, 0x00, 0xf8, 0x6f, 0xa0, 0x00, 0x88, 0xa2, 0xa0, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x02, 0x00, 0x00, + 0x30, 0x8b, 0x13, 0x00, 0x04, 0x8c, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xbc, 0x63, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x44, 0x64, 0x11, 0x00, 0x2c, 0x64, 0x11, 0x00, 0xfc, 0x63, 0x11, 0x00, + 0x38, 0x64, 0x11, 0x00, 0x14, 0x64, 0x11, 0x00, 0x08, 0x64, 0x11, 0x00, + 0x20, 0x64, 0x11, 0x00, 0x10, 0x70, 0xa0, 0x00, 0xbc, 0x9a, 0xa0, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x02, 0x00, 0x00, + 0x34, 0x8b, 0x13, 0x00, 0x14, 0x8c, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x50, 0x64, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd8, 0x64, 0x11, 0x00, 0xc0, 0x64, 0x11, 0x00, 0x90, 0x64, 0x11, 0x00, + 0xcc, 0x64, 0x11, 0x00, 0xa8, 0x64, 0x11, 0x00, 0x9c, 0x64, 0x11, 0x00, + 0xb4, 0x64, 0x11, 0x00, 0x20, 0x70, 0xa0, 0x00, 0x10, 0x9b, 0xa0, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x02, 0x00, 0x00, + 0x38, 0x8b, 0x13, 0x00, 0x1c, 0x8c, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xe4, 0x64, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6c, 0x65, 0x11, 0x00, 0x54, 0x65, 0x11, 0x00, 0x24, 0x65, 0x11, 0x00, + 0x60, 0x65, 0x11, 0x00, 0x3c, 0x65, 0x11, 0x00, 0x30, 0x65, 0x11, 0x00, + 0x48, 0x65, 0x11, 0x00, 0x30, 0x70, 0xa0, 0x00, 0x64, 0x9b, 0xa0, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x44, 0x8b, 0x13, 0x00, 0x40, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x20, 0x2d, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x98, 0x2d, 0x13, 0x00, 0x88, 0x2d, 0x13, 0x00, 0x58, 0x2d, 0x13, 0x00, + 0x90, 0x2d, 0x13, 0x00, 0x70, 0x2d, 0x13, 0x00, 0x68, 0x2d, 0x13, 0x00, + 0x80, 0x2d, 0x13, 0x00, 0x40, 0x70, 0xa0, 0x00, 0xec, 0x98, 0xa0, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x58, 0x8b, 0x13, 0x00, 0x54, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x20, 0x6a, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9c, 0x6a, 0x11, 0x00, 0x84, 0x6a, 0x11, 0x00, 0x54, 0x6a, 0x11, 0x00, + 0x90, 0x6a, 0x11, 0x00, 0x6c, 0x6a, 0x11, 0x00, 0x60, 0x6a, 0x11, 0x00, + 0x78, 0x6a, 0x11, 0x00, 0x60, 0x70, 0xa0, 0x00, 0x90, 0x98, 0xa0, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x68, 0x8b, 0x13, 0x00, 0x64, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xcc, 0x35, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x44, 0x36, 0x13, 0x00, 0x34, 0x36, 0x13, 0x00, 0x04, 0x36, 0x13, 0x00, + 0x3c, 0x36, 0x13, 0x00, 0x1c, 0x36, 0x13, 0x00, 0x14, 0x36, 0x13, 0x00, + 0x2c, 0x36, 0x13, 0x00, 0x84, 0x70, 0xa0, 0x00, 0x34, 0x99, 0xa0, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x80, 0x8b, 0x13, 0x00, 0x7c, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x64, 0x70, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x70, 0x11, 0x00, 0xc8, 0x70, 0x11, 0x00, 0x98, 0x70, 0x11, 0x00, + 0xd4, 0x70, 0x11, 0x00, 0xb0, 0x70, 0x11, 0x00, 0xa4, 0x70, 0x11, 0x00, + 0xbc, 0x70, 0x11, 0x00, 0xa8, 0x70, 0xa0, 0x00, 0xd4, 0x9c, 0xa0, 0x00, + 0x2d, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x8c, 0x8b, 0x13, 0x00, 0x88, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xf0, 0x70, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6c, 0x71, 0x11, 0x00, 0x54, 0x71, 0x11, 0x00, 0x24, 0x71, 0x11, 0x00, + 0x60, 0x71, 0x11, 0x00, 0x3c, 0x71, 0x11, 0x00, 0x30, 0x71, 0x11, 0x00, + 0x48, 0x71, 0x11, 0x00, 0xb8, 0x70, 0xa0, 0x00, 0xac, 0x98, 0xa0, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x94, 0x8b, 0x13, 0x00, 0x90, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x50, 0x75, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xcc, 0x75, 0x11, 0x00, 0xb4, 0x75, 0x11, 0x00, 0x84, 0x75, 0x11, 0x00, + 0xc0, 0x75, 0x11, 0x00, 0x9c, 0x75, 0x11, 0x00, 0x90, 0x75, 0x11, 0x00, + 0xa8, 0x75, 0x11, 0x00, 0xf4, 0x70, 0xa0, 0x00, 0x9c, 0x99, 0xa0, 0x00, + 0x3d, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x9c, 0x8b, 0x13, 0x00, 0x98, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x38, 0x3b, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb0, 0x3b, 0x13, 0x00, 0xa0, 0x3b, 0x13, 0x00, 0x70, 0x3b, 0x13, 0x00, + 0xa8, 0x3b, 0x13, 0x00, 0x88, 0x3b, 0x13, 0x00, 0x80, 0x3b, 0x13, 0x00, + 0x98, 0x3b, 0x13, 0x00, 0x04, 0x71, 0xa0, 0x00, 0xcc, 0x98, 0xa0, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x04, 0x00, 0x00, + 0xa4, 0x8b, 0x13, 0x00, 0x3c, 0x8e, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xb8, 0x3b, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xbc, 0x3c, 0x13, 0x00, 0xac, 0x3c, 0x13, 0x00, 0x7c, 0x3c, 0x13, 0x00, + 0xb4, 0x3c, 0x13, 0x00, 0x94, 0x3c, 0x13, 0x00, 0x8c, 0x3c, 0x13, 0x00, + 0xa4, 0x3c, 0x13, 0x00, 0x18, 0x71, 0xa0, 0x00, 0x48, 0x9e, 0xa0, 0x00, + 0x2b, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0xac, 0x8b, 0x13, 0x00, 0xa8, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0xec, 0x76, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0x77, 0x11, 0x00, 0x50, 0x77, 0x11, 0x00, 0x20, 0x77, 0x11, 0x00, + 0x5c, 0x77, 0x11, 0x00, 0x38, 0x77, 0x11, 0x00, 0x2c, 0x77, 0x11, 0x00, + 0x44, 0x77, 0x11, 0x00, 0x20, 0x71, 0xa0, 0x00, 0x10, 0x9c, 0xa0, 0x00, + 0x21, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0xb4, 0x8b, 0x13, 0x00, 0xb0, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x74, 0x77, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0x77, 0x11, 0x00, 0xd8, 0x77, 0x11, 0x00, 0xa8, 0x77, 0x11, 0x00, + 0xe4, 0x77, 0x11, 0x00, 0xc0, 0x77, 0x11, 0x00, 0xb4, 0x77, 0x11, 0x00, + 0xcc, 0x77, 0x11, 0x00, 0x30, 0x71, 0xa0, 0x00, 0xb8, 0x9b, 0xa0, 0x00, + 0x3c, 0x00, 0x00, 0x00, 0x84, 0x6e, 0xa0, 0x00, 0x01, 0x01, 0x00, 0x00, + 0xc8, 0x8b, 0x13, 0x00, 0xc4, 0x8b, 0x13, 0x00, 0xb4, 0x6e, 0xa0, 0x00, + 0x94, 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x42, 0x13, 0x00, 0xfc, 0x41, 0x13, 0x00, 0xcc, 0x41, 0x13, 0x00, + 0x04, 0x42, 0x13, 0x00, 0xe4, 0x41, 0x13, 0x00, 0xdc, 0x41, 0x13, 0x00, + 0xf4, 0x41, 0x13, 0x00, 0x44, 0x71, 0xa0, 0x00, 0xbc, 0x9d, 0xa0, 0x00, + 0x9c, 0x71, 0x13, 0x00, 0x50, 0x75, 0x13, 0x00, 0xd8, 0x80, 0x13, 0x00, + 0x08, 0x75, 0x13, 0x00, 0xb0, 0x71, 0x13, 0x00, 0xdc, 0x76, 0x13, 0x00, + 0x00, 0x77, 0x13, 0x00, 0x24, 0x77, 0x13, 0x00, 0x60, 0x7a, 0x13, 0x00, + 0x8c, 0x6f, 0x13, 0x00, 0x14, 0x7b, 0x13, 0x00, 0x50, 0x6e, 0x13, 0x00, + 0x64, 0x6e, 0x13, 0x00, 0x78, 0x6e, 0x13, 0x00, 0xec, 0x71, 0x13, 0x00, + 0x0c, 0x7d, 0x13, 0x00, 0x44, 0x81, 0x13, 0x00, 0x68, 0x74, 0x13, 0x00, + 0x00, 0x72, 0x13, 0x00, 0x50, 0x7e, 0x13, 0x00, 0xa4, 0x7b, 0x13, 0x00, + 0xa8, 0x83, 0x13, 0x00, 0x90, 0x74, 0x13, 0x00, 0x08, 0x7e, 0x13, 0x00, + 0xa4, 0x74, 0x13, 0x00, 0x70, 0x7f, 0x13, 0x00, 0x84, 0x83, 0x13, 0x00, + 0x14, 0x72, 0x13, 0x00, 0x90, 0x80, 0x13, 0x00, 0x78, 0x72, 0x13, 0x00, + 0x1c, 0x82, 0x13, 0x00, 0x8c, 0x72, 0x13, 0x00, 0x64, 0x82, 0x13, 0x00, + 0x6c, 0x80, 0x13, 0x00, 0xac, 0x82, 0x13, 0x00, 0xa0, 0x72, 0x13, 0x00, + 0xf4, 0x82, 0x13, 0x00, 0x54, 0x70, 0x13, 0x00, 0x3c, 0x83, 0x13, 0x00, + 0xb0, 0x81, 0x13, 0x00, 0xe0, 0x74, 0x13, 0x00, 0x0c, 0x86, 0x13, 0x00, + 0xb4, 0x72, 0x13, 0x00, 0x54, 0x86, 0x13, 0x00, 0x98, 0x7e, 0x13, 0x00, + 0x80, 0x7b, 0x13, 0x00, 0xe4, 0x7d, 0x13, 0x00, 0x58, 0x7c, 0x13, 0x00, + 0x40, 0x74, 0x13, 0x00, 0x88, 0x71, 0x13, 0x00, 0x04, 0x76, 0x13, 0x00, + 0xb4, 0x77, 0x13, 0x00, 0xe0, 0x75, 0x13, 0x00, 0x28, 0x76, 0x13, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x8c, 0x8e, 0x13, 0x00, 0x08, 0x75, 0x13, 0x00, + 0x20, 0x81, 0x13, 0x00, 0xc4, 0x71, 0x13, 0x00, 0x00, 0x6e, 0x13, 0x00, + 0x2c, 0x7e, 0x13, 0x00, 0x8c, 0x81, 0x13, 0x00, 0xd8, 0x71, 0x13, 0x00, + 0x14, 0x6e, 0x13, 0x00, 0x28, 0x6e, 0x13, 0x00, 0x3c, 0x6e, 0x13, 0x00, + 0x10, 0x7c, 0x13, 0x00, 0xec, 0x7b, 0x13, 0x00, 0x30, 0x7d, 0x13, 0x00, + 0xb0, 0x78, 0x13, 0x00, 0x74, 0x7e, 0x13, 0x00, 0xf8, 0x78, 0x13, 0x00, + 0xb8, 0x74, 0x13, 0x00, 0x7c, 0x74, 0x13, 0x00, 0xe0, 0x7e, 0x13, 0x00, + 0x98, 0x7e, 0x13, 0x00, 0x04, 0x7f, 0x13, 0x00, 0xbc, 0x7e, 0x13, 0x00, + 0xb4, 0x80, 0x13, 0x00, 0xd0, 0x79, 0x13, 0x00, 0x74, 0x75, 0x13, 0x00, + 0xf0, 0x83, 0x13, 0x00, 0x70, 0x76, 0x13, 0x00, 0x5c, 0x84, 0x13, 0x00, + 0xc8, 0x7b, 0x13, 0x00, 0xa0, 0x7c, 0x13, 0x00, 0x28, 0x7f, 0x13, 0x00, + 0x58, 0x85, 0x13, 0x00, 0x40, 0x82, 0x13, 0x00, 0x18, 0x7a, 0x13, 0x00, + 0x88, 0x82, 0x13, 0x00, 0x3c, 0x7a, 0x13, 0x00, 0x18, 0x83, 0x13, 0x00, + 0xa8, 0x7a, 0x13, 0x00, 0x84, 0x83, 0x13, 0x00, 0xa8, 0x83, 0x13, 0x00, + 0x78, 0x86, 0x13, 0x00, 0xf0, 0x7a, 0x13, 0x00, 0xdc, 0x76, 0x13, 0x00, + 0x98, 0x75, 0x13, 0x00, 0x6c, 0x77, 0x13, 0x00, 0x00, 0x77, 0x13, 0x00, + 0x94, 0x76, 0x13, 0x00, 0xfc, 0x77, 0x13, 0x00, 0x38, 0x7b, 0x13, 0x00, + 0xa4, 0x84, 0x13, 0x00, 0x44, 0x78, 0x13, 0x00, 0xa0, 0x6f, 0x13, 0x00, + 0xb4, 0x6f, 0x13, 0x00, 0xc8, 0x6f, 0x13, 0x00, 0xdc, 0x7f, 0x13, 0x00, + 0x10, 0x85, 0x13, 0x00, 0xd4, 0x78, 0x13, 0x00, 0x00, 0x80, 0x13, 0x00, + 0x34, 0x85, 0x13, 0x00, 0x1c, 0x79, 0x13, 0x00, 0x24, 0x80, 0x13, 0x00, + 0xc4, 0x85, 0x13, 0x00, 0xac, 0x79, 0x13, 0x00, 0x2c, 0x7e, 0x13, 0x00, + 0xe4, 0x7d, 0x13, 0x00, 0x08, 0x7e, 0x13, 0x00, 0x64, 0x6f, 0x13, 0x00, + 0xdc, 0x6f, 0x13, 0x00, 0x78, 0x6f, 0x13, 0x00, 0x24, 0x77, 0x13, 0x00, + 0x94, 0x7f, 0x13, 0x00, 0x64, 0x79, 0x13, 0x00, 0xec, 0x6d, 0x13, 0x00, + 0xf0, 0x6f, 0x13, 0x00, 0x28, 0x72, 0x13, 0x00, 0x2c, 0x75, 0x13, 0x00, + 0xcc, 0x83, 0x13, 0x00, 0x48, 0x77, 0x13, 0x00, 0x20, 0x81, 0x13, 0x00, + 0xfc, 0x80, 0x13, 0x00, 0xd8, 0x80, 0x13, 0x00, 0xbc, 0x7e, 0x13, 0x00, + 0x10, 0x7c, 0x13, 0x00, 0x7c, 0x7c, 0x13, 0x00, 0x04, 0x70, 0x13, 0x00, + 0x18, 0x70, 0x13, 0x00, 0x3c, 0x72, 0x13, 0x00, 0x4c, 0x76, 0x13, 0x00, + 0x38, 0x84, 0x13, 0x00, 0xd8, 0x77, 0x13, 0x00, 0x8c, 0x81, 0x13, 0x00, + 0x68, 0x81, 0x13, 0x00, 0x44, 0x81, 0x13, 0x00, 0x50, 0x72, 0x13, 0x00, + 0x2c, 0x70, 0x13, 0x00, 0x64, 0x72, 0x13, 0x00, 0x4c, 0x7f, 0x13, 0x00, + 0x7c, 0x85, 0x13, 0x00, 0x40, 0x79, 0x13, 0x00, 0xf8, 0x81, 0x13, 0x00, + 0xd4, 0x81, 0x13, 0x00, 0xb0, 0x81, 0x13, 0x00, 0xd0, 0x82, 0x13, 0x00, + 0x30, 0x86, 0x13, 0x00, 0x84, 0x7a, 0x13, 0x00, 0x28, 0x76, 0x13, 0x00, + 0x60, 0x83, 0x13, 0x00, 0xcc, 0x7a, 0x13, 0x00, 0xfc, 0x80, 0x13, 0x00, + 0xbc, 0x75, 0x13, 0x00, 0x14, 0x84, 0x13, 0x00, 0x90, 0x77, 0x13, 0x00, + 0x68, 0x81, 0x13, 0x00, 0xb8, 0x76, 0x13, 0x00, 0x80, 0x84, 0x13, 0x00, + 0x20, 0x78, 0x13, 0x00, 0x70, 0x7f, 0x13, 0x00, 0xe0, 0x7e, 0x13, 0x00, + 0x04, 0x7f, 0x13, 0x00, 0xf8, 0x81, 0x13, 0x00, 0xd4, 0x81, 0x13, 0x00, + 0xb8, 0x7f, 0x13, 0x00, 0xa0, 0x85, 0x13, 0x00, 0x88, 0x79, 0x13, 0x00, + 0x78, 0x7d, 0x13, 0x00, 0xe8, 0x7c, 0x13, 0x00, 0xec, 0x84, 0x13, 0x00, + 0x8c, 0x78, 0x13, 0x00, 0x5c, 0x7b, 0x13, 0x00, 0xc8, 0x7b, 0x13, 0x00, + 0x80, 0x7b, 0x13, 0x00, 0xa4, 0x7b, 0x13, 0x00, 0x9c, 0x7d, 0x13, 0x00, + 0xc4, 0x7c, 0x13, 0x00, 0xc8, 0x84, 0x13, 0x00, 0x68, 0x78, 0x13, 0x00, + 0xc0, 0x7d, 0x13, 0x00, 0x48, 0x80, 0x13, 0x00, 0xe8, 0x85, 0x13, 0x00, + 0xf4, 0x79, 0x13, 0x00, 0x7c, 0x7c, 0x13, 0x00, 0x34, 0x7c, 0x13, 0x00, + 0xa0, 0x7c, 0x13, 0x00, 0x58, 0x7c, 0x13, 0x00, 0x40, 0x70, 0x13, 0x00, + 0xcc, 0x74, 0x13, 0x00, 0xf4, 0x74, 0x13, 0x00, 0x54, 0x74, 0x13, 0x00, + 0xac, 0x82, 0x13, 0x00, 0x1c, 0x82, 0x13, 0x00, 0x3c, 0x83, 0x13, 0x00, + 0x54, 0x86, 0x13, 0x00, 0xe0, 0x75, 0x13, 0x00, 0xf4, 0x82, 0x13, 0x00, + 0x0c, 0x7d, 0x13, 0x00, 0x90, 0x80, 0x13, 0x00, 0x64, 0x82, 0x13, 0x00, + 0x50, 0x7e, 0x13, 0x00, 0x14, 0x7b, 0x13, 0x00, 0x50, 0x75, 0x13, 0x00, + 0x5c, 0x7b, 0x13, 0x00, 0xec, 0x7b, 0x13, 0x00, 0x34, 0x7c, 0x13, 0x00, + 0x54, 0x7d, 0x13, 0x00, 0x2c, 0x87, 0x13, 0x00, 0xbc, 0x87, 0x13, 0x00, + 0x74, 0x87, 0x13, 0x00, 0xdc, 0x88, 0x13, 0x00, 0xe4, 0x86, 0x13, 0x00, + 0x58, 0x73, 0x13, 0x00, 0xb0, 0x70, 0x13, 0x00, 0xfc, 0x89, 0x13, 0x00, + 0x6c, 0x89, 0x13, 0x00, 0x8c, 0x8a, 0x13, 0x00, 0xd4, 0x8a, 0x13, 0x00, + 0xc8, 0x72, 0x13, 0x00, 0x44, 0x8a, 0x13, 0x00, 0x4c, 0x88, 0x13, 0x00, + 0x24, 0x89, 0x13, 0x00, 0xb4, 0x89, 0x13, 0x00, 0x94, 0x88, 0x13, 0x00, + 0x04, 0x88, 0x13, 0x00, 0x9c, 0x86, 0x13, 0x00, 0x68, 0x70, 0x13, 0x00, + 0xf8, 0x70, 0x13, 0x00, 0xa0, 0x73, 0x13, 0x00, 0xe8, 0x73, 0x13, 0x00, + 0x40, 0x71, 0x13, 0x00, 0x8c, 0x6e, 0x13, 0x00, 0x10, 0x73, 0x13, 0x00, + 0xd4, 0x6e, 0x13, 0x00, 0x1c, 0x6f, 0x13, 0x00, 0x98, 0x75, 0x13, 0x00, + 0x6c, 0x77, 0x13, 0x00, 0xbc, 0x75, 0x13, 0x00, 0x14, 0x84, 0x13, 0x00, + 0x90, 0x77, 0x13, 0x00, 0x94, 0x7f, 0x13, 0x00, 0x64, 0x79, 0x13, 0x00, + 0xb8, 0x7f, 0x13, 0x00, 0xa0, 0x85, 0x13, 0x00, 0x88, 0x79, 0x13, 0x00, + 0x94, 0x76, 0x13, 0x00, 0xfc, 0x77, 0x13, 0x00, 0xb8, 0x76, 0x13, 0x00, + 0x80, 0x84, 0x13, 0x00, 0x20, 0x78, 0x13, 0x00, 0x2c, 0x75, 0x13, 0x00, + 0xcc, 0x83, 0x13, 0x00, 0x48, 0x77, 0x13, 0x00, 0x4c, 0x76, 0x13, 0x00, + 0x38, 0x84, 0x13, 0x00, 0xd8, 0x77, 0x13, 0x00, 0x74, 0x75, 0x13, 0x00, + 0xf0, 0x83, 0x13, 0x00, 0x4c, 0x7f, 0x13, 0x00, 0x7c, 0x85, 0x13, 0x00, + 0x40, 0x79, 0x13, 0x00, 0x28, 0x7f, 0x13, 0x00, 0x58, 0x85, 0x13, 0x00, + 0x70, 0x76, 0x13, 0x00, 0x5c, 0x84, 0x13, 0x00, 0xe8, 0x7c, 0x13, 0x00, + 0xec, 0x84, 0x13, 0x00, 0x8c, 0x78, 0x13, 0x00, 0xc4, 0x7c, 0x13, 0x00, + 0xc8, 0x84, 0x13, 0x00, 0x68, 0x78, 0x13, 0x00, 0x48, 0x80, 0x13, 0x00, + 0xe8, 0x85, 0x13, 0x00, 0xf4, 0x79, 0x13, 0x00, 0xdc, 0x7f, 0x13, 0x00, + 0x10, 0x85, 0x13, 0x00, 0xd4, 0x78, 0x13, 0x00, 0x00, 0x80, 0x13, 0x00, + 0x34, 0x85, 0x13, 0x00, 0x1c, 0x79, 0x13, 0x00, 0x24, 0x80, 0x13, 0x00, + 0xc4, 0x85, 0x13, 0x00, 0xac, 0x79, 0x13, 0x00, 0xd0, 0x82, 0x13, 0x00, + 0x30, 0x86, 0x13, 0x00, 0x84, 0x7a, 0x13, 0x00, 0x6c, 0x80, 0x13, 0x00, + 0x0c, 0x86, 0x13, 0x00, 0x60, 0x7a, 0x13, 0x00, 0x40, 0x82, 0x13, 0x00, + 0x18, 0x7a, 0x13, 0x00, 0x60, 0x83, 0x13, 0x00, 0xcc, 0x7a, 0x13, 0x00, + 0x78, 0x86, 0x13, 0x00, 0xf0, 0x7a, 0x13, 0x00, 0x04, 0x76, 0x13, 0x00, + 0xb4, 0x77, 0x13, 0x00, 0x18, 0x83, 0x13, 0x00, 0xa8, 0x7a, 0x13, 0x00, + 0x30, 0x7d, 0x13, 0x00, 0xb0, 0x78, 0x13, 0x00, 0xb4, 0x80, 0x13, 0x00, + 0xd0, 0x79, 0x13, 0x00, 0x88, 0x82, 0x13, 0x00, 0x3c, 0x7a, 0x13, 0x00, + 0x74, 0x7e, 0x13, 0x00, 0xf8, 0x78, 0x13, 0x00, 0x38, 0x7b, 0x13, 0x00, + 0xa4, 0x84, 0x13, 0x00, 0x44, 0x78, 0x13, 0x00, 0x43, 0x61, 0x6c, 0x69, + 0x62, 0x42, 0x53, 0x58, 0x00, 0x4e, 0x56, 0x69, 0x72, 0x74, 0x00, 0x53, + 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x67, 0x17, 0x00, + 0x48, 0x6f, 0x73, 0x74, 0x00, 0xa9, 0x1a, 0xa1, 0xab, 0x55, 0x17, 0x48, + 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00, + 0x50, 0x61, 0x72, 0x61, 0x6d, 0x20, 0x25, 0x75, 0x20, 0x6c, 0x65, 0x6e, + 0x20, 0x25, 0x75, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x25, 0x6c, 0x6c, + 0x75, 0x2e, 0x20, 0x20, 0x00, 0x25, 0x64, 0x2e, 0x20, 0x54, 0x65, 0x73, + 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, + 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x65, + 0x73, 0x74, 0x20, 0x25, 0x75, 0x2e, 0x20, 0x20, 0x00, 0x54, 0x68, 0x65, + 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, + 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x64, 0x20, + 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, + 0x79, 0x20, 0x64, 0x6f, 0x67, 0x2e, 0x20, 0x20, 0x54, 0x68, 0x69, 0x73, + 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2c, 0x20, + 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6f, 0x6e, 0x6c, 0x79, + 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x20, 0x20, 0x45, 0x20, + 0x70, 0x6c, 0x75, 0x72, 0x69, 0x62, 0x75, 0x73, 0x20, 0x75, 0x6e, 0x75, + 0x6d, 0x2e, 0x20, 0x20, 0x43, 0x6f, 0x67, 0x69, 0x74, 0x6f, 0x20, 0x65, + 0x72, 0x67, 0x6f, 0x20, 0x73, 0x75, 0x6d, 0x2e, 0x20, 0x20, 0x56, 0x69, + 0x6e, 0x69, 0x2c, 0x20, 0x76, 0x69, 0x64, 0x69, 0x2c, 0x20, 0x76, 0x69, + 0x63, 0x69, 0x2e, 0x00, 0x49, 0x64, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, + 0x65, 0x78, 0x70, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, + 0x00, 0x00, 0x00, 0xbf, 0x80, 0x71, 0x31, 0x3f, 0x80, 0x71, 0x31, 0xbf, + 0xd1, 0xf7, 0x17, 0x37, 0xd1, 0xf7, 0x17, 0xb7, 0x6c, 0x6f, 0x67, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0xce, 0x02, 0x00, + 0xeb, 0x3c, 0xeb, 0xae, 0x1f, 0xa4, 0xe4, 0xa1, 0xaf, 0x7b, 0x98, 0x7f, + 0x6b, 0xc8, 0x8e, 0x6d, 0x7b, 0x9d, 0xc1, 0x98, 0x02, 0x32, 0x96, 0x89, + 0x48, 0xa4, 0x10, 0xcd, 0x17, 0xce, 0xb8, 0x3c, 0x4d, 0x12, 0x4f, 0x2b, + 0x32, 0x11, 0xc0, 0x3a, 0x42, 0x15, 0x29, 0xea, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x70, 0x91, 0x13, 0x00, 0x74, 0x91, 0x13, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x74, 0x91, 0x13, 0x00, 0x78, 0x91, 0x13, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc3, 0x40, 0x12, 0x00, 0x00, 0x40, 0x6b, 0x20, 0x40, 0x09, 0x0a, 0x22, + 0x80, 0x8f, 0x10, 0x00, 0x84, 0x2b, 0xe2, 0x20, 0x82, 0x00, 0x0a, 0x22, + 0x80, 0x8f, 0x13, 0x00, 0xb4, 0x92, 0xe2, 0x20, 0x82, 0x00, 0x9a, 0x08, + 0x00, 0x00, 0xdb, 0x44, 0xa0, 0x00, 0x20, 0x5c, 0xab, 0x24, 0x09, 0x39, + 0xdb, 0x44, 0xa0, 0x00, 0x20, 0x6c, 0xab, 0x24, 0x49, 0x39, 0x9e, 0x0f, + 0x8f, 0xfd, 0x6a, 0x20, 0x80, 0x02, 0x8e, 0xb8, 0x29, 0x20, 0x00, 0x80, + 0xdb, 0x42, 0xa0, 0x00, 0x1c, 0x5c, 0x6f, 0x70, 0x22, 0x20, 0x80, 0x0f, + 0x13, 0x00, 0xac, 0x94, 0x41, 0x02, 0xcf, 0xe4, 0x88, 0x9b, 0x13, 0x00, + 0xc3, 0x40, 0x12, 0x00, 0x80, 0x4b, 0xd3, 0x70, 0x12, 0x00, 0x80, 0x4b, + 0xe0, 0x7c, 0xab, 0x20, 0x8a, 0x04, 0xe0, 0x7e, 0x41, 0x88, 0x00, 0x43, + 0x00, 0x88, 0x1c, 0xba, 0x5c, 0xba, 0x08, 0xba, 0x05, 0x7a, 0x40, 0xb1, + 0x01, 0x8b, 0x02, 0x13, 0xc2, 0x00, 0x24, 0xb8, 0x04, 0xba, 0x05, 0x7a, + 0x41, 0xb1, 0x04, 0x8b, 0x43, 0x8b, 0x1c, 0xb8, 0x5c, 0xb8, 0x08, 0xb8, + 0x45, 0x78, 0xe0, 0x7f, 0x02, 0xb1, 0xe0, 0x78, 0x00, 0x10, 0xc2, 0x00, + 0x40, 0xb1, 0x01, 0x10, 0xc2, 0x00, 0x41, 0xb1, 0x02, 0x10, 0xc0, 0x00, + 0xe0, 0x7f, 0x02, 0xb1, 0xe8, 0xc3, 0xab, 0xc1, 0xcb, 0x46, 0xf0, 0x00, + 0x34, 0x00, 0x0c, 0x70, 0x14, 0xae, 0x16, 0xae, 0x15, 0xae, 0x00, 0x16, + 0x0d, 0x70, 0xa0, 0x00, 0xd8, 0x5e, 0x0a, 0xd8, 0x4c, 0x74, 0x9a, 0x4d, + 0x9e, 0x0c, 0x6f, 0xea, 0x30, 0x40, 0x08, 0x8d, 0x46, 0x8d, 0x67, 0x8d, + 0x25, 0x8d, 0x08, 0xb8, 0x08, 0xba, 0x65, 0x78, 0x45, 0x79, 0x10, 0xb8, + 0x25, 0x78, 0x35, 0xb8, 0x8c, 0x20, 0x8f, 0x83, 0xcc, 0x20, 0x82, 0x8f, + 0x00, 0x00, 0xea, 0x05, 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, 0xd5, 0x07, + 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, 0xdd, 0x07, 0x07, 0xf2, 0x01, 0x8e, + 0x6c, 0x20, 0x40, 0x01, 0x45, 0x20, 0xc0, 0x00, 0x01, 0xae, 0x66, 0x15, + 0x80, 0x10, 0x06, 0xe8, 0x00, 0x1e, 0x02, 0x70, 0xf0, 0x00, 0x06, 0x01, + 0x80, 0xc0, 0x7a, 0x09, 0xaf, 0xfe, 0x54, 0x25, 0xce, 0x1c, 0x00, 0x10, + 0xc0, 0x20, 0x79, 0x08, 0x32, 0x00, 0x1a, 0xd9, 0x19, 0xd9, 0xfe, 0x0b, + 0x6f, 0xea, 0xc1, 0x40, 0x7f, 0x15, 0x81, 0x10, 0x38, 0x20, 0x42, 0x00, + 0x6a, 0xc1, 0xb5, 0x08, 0x61, 0x00, 0x29, 0x1c, 0x82, 0x30, 0x67, 0xd8, + 0xb8, 0x60, 0x84, 0xc1, 0xc5, 0xff, 0x54, 0x25, 0x80, 0x1d, 0x40, 0x24, + 0x81, 0x35, 0xc3, 0xff, 0x71, 0xd8, 0xb8, 0x60, 0x40, 0x24, 0x81, 0x38, + 0xc0, 0xff, 0x75, 0x15, 0xc1, 0x10, 0x70, 0x15, 0x80, 0x10, 0x6b, 0x15, + 0x82, 0x10, 0x04, 0xb9, 0x6c, 0x20, 0xc3, 0x00, 0x41, 0x2a, 0x00, 0x01, + 0x84, 0x21, 0x3c, 0x00, 0x25, 0x78, 0x65, 0x78, 0x48, 0x30, 0x81, 0x00, + 0x7f, 0xd8, 0x17, 0xb8, 0x00, 0x31, 0x81, 0x0f, 0x75, 0x37, 0x8f, 0xc2, + 0x01, 0x31, 0x01, 0x00, 0x07, 0x30, 0x40, 0x00, 0x43, 0xc0, 0x2c, 0xf0, + 0x8e, 0x0b, 0x6f, 0xea, 0xc1, 0x40, 0x2d, 0x8d, 0x38, 0x20, 0x42, 0x00, + 0x6a, 0xc1, 0x49, 0x08, 0x61, 0x00, 0x29, 0x1c, 0x82, 0x30, 0x67, 0x15, + 0xcb, 0x10, 0x68, 0x15, 0xc1, 0x10, 0x69, 0x15, 0xc2, 0x10, 0x6a, 0x15, + 0xc3, 0x10, 0x6b, 0x15, 0xcc, 0x10, 0x6c, 0x15, 0xce, 0x10, 0x6d, 0x15, + 0xcf, 0x10, 0x6e, 0x15, 0xc0, 0x10, 0x6f, 0x15, 0xcd, 0x10, 0x10, 0x1c, + 0xc4, 0x32, 0x12, 0x1c, 0x44, 0x30, 0x14, 0x1c, 0x84, 0x30, 0x83, 0x41, + 0x6b, 0xb1, 0x8c, 0xb1, 0xcd, 0xb1, 0xf1, 0xb1, 0x12, 0xb1, 0xb3, 0xb1, + 0xc3, 0x40, 0xa1, 0x00, 0xff, 0x7f, 0xee, 0x0e, 0x4f, 0xf6, 0x43, 0x08, + 0x74, 0x02, 0x08, 0x45, 0xd6, 0x0e, 0x4f, 0xf6, 0x68, 0xbd, 0x08, 0x46, + 0xe6, 0x09, 0xaf, 0xeb, 0xaf, 0x7d, 0x23, 0x6e, 0xb8, 0x60, 0x2f, 0x79, + 0x29, 0x09, 0x24, 0x00, 0x2d, 0xd8, 0xd6, 0x09, 0x8f, 0xeb, 0xf6, 0x09, + 0xaf, 0xeb, 0xa1, 0x41, 0xa6, 0x0a, 0xaf, 0xeb, 0xa1, 0x40, 0x80, 0xc1, + 0xc3, 0x40, 0x13, 0x00, 0xf8, 0x6a, 0xca, 0x0c, 0xef, 0xe4, 0x2c, 0xda, + 0xc8, 0xc7, 0x2f, 0xd8, 0x16, 0x0e, 0x6f, 0xea, 0x2c, 0x71, 0xe0, 0x78, + 0xf1, 0xc0, 0xcb, 0x44, 0xf0, 0x00, 0x34, 0x00, 0x22, 0x94, 0xc3, 0x40, + 0x00, 0x00, 0x2e, 0x14, 0x10, 0x78, 0x47, 0x09, 0x21, 0x00, 0x1a, 0xd8, + 0xc3, 0x40, 0xa0, 0x00, 0x64, 0x88, 0xc3, 0x41, 0xa1, 0x00, 0x88, 0x27, + 0x12, 0x49, 0xc3, 0x43, 0x00, 0x00, 0x67, 0x17, 0x0d, 0x0a, 0x72, 0x00, + 0x63, 0xb4, 0xca, 0x0a, 0xef, 0xf2, 0x2c, 0x70, 0xc3, 0x40, 0x13, 0x00, + 0xf0, 0x9d, 0x22, 0x08, 0x00, 0x00, 0xc3, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xe8, 0xfa, 0x0f, 0x8f, 0xe4, 0x92, 0x0e, 0x00, 0x00, 0xd1, 0xc0, + 0xe0, 0x7e, 0xba, 0x0d, 0x6f, 0xea, 0x2c, 0x70, 0xea, 0xc3, 0xa1, 0xc1, + 0x08, 0x46, 0x07, 0xe8, 0x9a, 0x0d, 0xaf, 0xe4, 0xc1, 0x40, 0x05, 0xe8, + 0xca, 0xc7, 0x0c, 0x70, 0xca, 0xc7, 0x03, 0x8e, 0x0d, 0x08, 0xf4, 0x00, + 0x40, 0x26, 0x0d, 0x12, 0xe1, 0x86, 0x10, 0xf0, 0xa4, 0x6e, 0xcb, 0x47, + 0x10, 0x00, 0xcc, 0x2a, 0x0a, 0xf0, 0x04, 0x6d, 0xa4, 0x68, 0x08, 0xf0, + 0x4e, 0x20, 0x02, 0x20, 0x66, 0x0a, 0xef, 0xf2, 0x2c, 0x70, 0x2a, 0x45, + 0x21, 0x85, 0x00, 0x85, 0x34, 0x70, 0x30, 0x40, 0x10, 0xf2, 0x40, 0x25, + 0x11, 0x12, 0xf4, 0xf6, 0x80, 0xc3, 0x00, 0x42, 0x22, 0x40, 0x60, 0x7f, + 0x02, 0x41, 0x40, 0x20, 0xc0, 0x20, 0x6c, 0x20, 0x40, 0x00, 0x1d, 0x65, + 0x08, 0xe5, 0xee, 0xf1, 0xe3, 0xe8, 0xc3, 0x43, 0xd0, 0xba, 0xad, 0x0b, + 0xc3, 0x42, 0xad, 0x0b, 0xd0, 0xba, 0xc3, 0x41, 0x00, 0x00, 0x0b, 0x0a, + 0x0c, 0x70, 0x60, 0xa5, 0x41, 0xa5, 0x02, 0x1e, 0x43, 0x13, 0x20, 0xb6, + 0xca, 0xc7, 0xe0, 0x78, 0xe6, 0xc2, 0x0c, 0x71, 0xa6, 0x5a, 0xcb, 0x45, + 0xa0, 0x00, 0x18, 0x87, 0x02, 0xa5, 0x0c, 0x71, 0xa7, 0x5a, 0x04, 0xa5, + 0x0c, 0x71, 0xc3, 0x41, 0x12, 0x00, 0xe0, 0x55, 0xae, 0x5a, 0x08, 0x46, + 0x0c, 0x71, 0xc3, 0x41, 0x12, 0x00, 0xd4, 0x56, 0xaf, 0x5a, 0x08, 0x47, + 0x0c, 0x73, 0xa6, 0x5a, 0x03, 0xa5, 0x0c, 0x73, 0xc3, 0x41, 0x12, 0x00, + 0xb8, 0x55, 0xae, 0x5a, 0x00, 0x41, 0x0c, 0x70, 0x04, 0xee, 0x04, 0xef, + 0x79, 0x21, 0x00, 0x00, 0xc6, 0xc6, 0xe0, 0x78, 0xf1, 0xc0, 0xc3, 0x40, + 0x12, 0x00, 0x54, 0x57, 0xac, 0x5a, 0xc3, 0x41, 0xa0, 0x00, 0x30, 0x87, + 0xd1, 0xc0, 0xe0, 0x7f, 0x00, 0xa1, 0xe0, 0x78, 0xe2, 0xc2, 0x42, 0x21, + 0x3c, 0x80, 0xc3, 0x43, 0x00, 0x00, 0xff, 0xff, 0xad, 0x70, 0x15, 0xf2, + 0x40, 0x20, 0x0c, 0x07, 0xa8, 0x20, 0x40, 0x04, 0x00, 0x84, 0x1b, 0x08, + 0x81, 0x00, 0x2e, 0x8c, 0x06, 0x94, 0xc0, 0xb9, 0x84, 0x20, 0xcf, 0x8f, + 0x25, 0x7d, 0x05, 0xf2, 0x70, 0x70, 0xca, 0x23, 0x05, 0x00, 0x55, 0x24, + 0x0c, 0x1c, 0x83, 0x82, 0xbb, 0x78, 0x2c, 0x8c, 0xa1, 0xb9, 0x05, 0x79, + 0x2c, 0xac, 0x23, 0x82, 0xe2, 0x0a, 0x2f, 0xf1, 0x60, 0x40, 0xc2, 0xc6, + 0x08, 0x44, 0x42, 0x22, 0x3c, 0x80, 0x4a, 0x20, 0x00, 0x00, 0xe0, 0x7c, + 0x40, 0x21, 0x03, 0x07, 0xa8, 0x20, 0xc0, 0x01, 0xc0, 0x13, 0x01, 0x04, + 0x38, 0x21, 0x01, 0x03, 0x25, 0x78, 0xe0, 0x7e, 0xee, 0xc2, 0xcb, 0x47, + 0xf0, 0x00, 0x00, 0x01, 0x13, 0x8f, 0xcb, 0x45, 0xf0, 0x00, 0x40, 0x02, + 0x80, 0xb8, 0x13, 0xaf, 0x12, 0x8f, 0x80, 0xb8, 0x12, 0xaf, 0x11, 0x8f, + 0xa0, 0xb8, 0x11, 0xaf, 0x01, 0x85, 0x21, 0x85, 0x44, 0x20, 0x42, 0x00, + 0x50, 0x21, 0x00, 0x00, 0x45, 0x78, 0x01, 0xa5, 0x00, 0x16, 0x01, 0x70, + 0xa0, 0x00, 0x74, 0x6e, 0xc3, 0x40, 0xa0, 0x00, 0x20, 0x6c, 0x16, 0x0f, + 0x0f, 0xf6, 0xaa, 0x20, 0x49, 0x09, 0x02, 0x0f, 0x2f, 0xf6, 0xaa, 0x21, + 0x09, 0x09, 0xfa, 0x09, 0x8f, 0xfe, 0x5e, 0x0d, 0x6f, 0xfd, 0x0c, 0x70, + 0x5e, 0x0a, 0x8f, 0xfe, 0x66, 0x0a, 0x8f, 0xfe, 0xa2, 0x0a, 0x8f, 0xfe, + 0x92, 0x0a, 0x4f, 0xf0, 0x10, 0x40, 0x14, 0x70, 0xd8, 0xf2, 0xd2, 0x0c, + 0x8f, 0xfd, 0x03, 0x90, 0xcb, 0x46, 0xf0, 0x00, 0x34, 0x00, 0x04, 0xb6, + 0x0e, 0x10, 0x80, 0x20, 0x22, 0x85, 0x22, 0xb8, 0xa0, 0xb9, 0xc0, 0xb8, + 0x25, 0x78, 0x02, 0xa5, 0x02, 0x10, 0x81, 0x20, 0x08, 0x8f, 0x0f, 0x09, + 0x7f, 0x00, 0x6c, 0x20, 0x40, 0x00, 0x80, 0xb8, 0x02, 0xf0, 0x81, 0xb8, + 0x08, 0xaf, 0x56, 0x0a, 0x6f, 0xf0, 0x17, 0x1e, 0x83, 0x14, 0x2f, 0x10, + 0x81, 0x00, 0x2e, 0x10, 0x82, 0x00, 0x40, 0x29, 0x00, 0x02, 0x45, 0x78, + 0x11, 0x08, 0x80, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x8c, 0x20, 0x53, 0x8f, + 0xc6, 0xf7, 0x08, 0xf0, 0x00, 0x1e, 0x43, 0x70, 0xa0, 0x00, 0x9c, 0x42, + 0x8a, 0x20, 0x93, 0x0f, 0xa9, 0x5a, 0x14, 0x70, 0x92, 0xf2, 0xc3, 0x40, + 0xa0, 0x00, 0x20, 0x5c, 0xc3, 0x41, 0xa0, 0x00, 0x20, 0x6c, 0x56, 0x0d, + 0x6f, 0xea, 0x17, 0x1e, 0xc3, 0x14, 0xcb, 0x45, 0xa0, 0x00, 0xb8, 0x88, + 0x28, 0xd9, 0xc3, 0x42, 0xa0, 0x00, 0x54, 0x40, 0x56, 0x25, 0x00, 0x1c, + 0x17, 0x1e, 0x43, 0x15, 0x22, 0x0b, 0x6f, 0xf6, 0x17, 0x1e, 0x83, 0x15, + 0xc3, 0x40, 0xa0, 0x00, 0x58, 0x8d, 0xc3, 0x42, 0xa0, 0x00, 0x74, 0x40, + 0x0e, 0x0b, 0x6f, 0xf6, 0x28, 0xd9, 0xc3, 0x40, 0xa0, 0x00, 0x78, 0x90, + 0xc3, 0x42, 0xa0, 0x00, 0xec, 0x40, 0xf6, 0x09, 0xef, 0xeb, 0x20, 0xd9, + 0xc3, 0x40, 0xa0, 0x00, 0x78, 0x94, 0xc3, 0x42, 0xa0, 0x00, 0x08, 0x41, + 0xe2, 0x09, 0xef, 0xeb, 0x20, 0xd9, 0x10, 0x8f, 0x10, 0xd9, 0x80, 0xb8, + 0x10, 0xaf, 0xa1, 0x40, 0x7e, 0x0a, 0x2f, 0xf4, 0x17, 0x1e, 0xc3, 0x15, + 0xd2, 0x08, 0x20, 0x00, 0x02, 0x40, 0xab, 0x08, 0x30, 0x00, 0xad, 0x70, + 0x34, 0x58, 0x10, 0x43, 0x2e, 0x58, 0x10, 0x42, 0x3e, 0x58, 0x10, 0x41, + 0x2f, 0x58, 0x00, 0x44, 0x02, 0x40, 0x62, 0x41, 0x42, 0x42, 0xda, 0x0a, + 0x20, 0x00, 0x22, 0x43, 0x87, 0x08, 0x10, 0x00, 0x36, 0x0a, 0x0f, 0xeb, + 0x0e, 0xe8, 0x0b, 0x8e, 0x19, 0x08, 0x5f, 0x00, 0x34, 0x58, 0x10, 0x40, + 0x2e, 0x58, 0x00, 0x42, 0x30, 0xd8, 0x02, 0x41, 0x33, 0x58, 0x04, 0xe8, + 0xaa, 0x09, 0x0f, 0xeb, 0x3e, 0x0d, 0x00, 0x00, 0x2f, 0xe8, 0x91, 0xd8, + 0xde, 0x0a, 0xef, 0xf5, 0x17, 0xae, 0x14, 0x8e, 0xa9, 0xe8, 0x82, 0x0d, + 0xcf, 0xff, 0x8a, 0x20, 0x08, 0x0e, 0xaa, 0xda, 0x2c, 0x70, 0xc1, 0x68, + 0xab, 0x22, 0x08, 0x0e, 0x2b, 0x21, 0x80, 0x03, 0x08, 0x8f, 0xc3, 0x43, + 0xfa, 0x02, 0x80, 0xf0, 0xc3, 0x41, 0x31, 0x01, 0x00, 0x2d, 0xc1, 0xb8, + 0x14, 0x72, 0x55, 0xdc, 0xca, 0x21, 0xc1, 0x00, 0x01, 0x6e, 0xc9, 0x43, + 0xab, 0x24, 0x08, 0x1e, 0x2b, 0x21, 0x00, 0x00, 0xc3, 0x40, 0xa0, 0x00, + 0xe0, 0x42, 0x00, 0x88, 0xad, 0x71, 0x09, 0xe8, 0x0c, 0x75, 0x0d, 0xf0, + 0x2a, 0xd8, 0xad, 0x70, 0x14, 0xae, 0xa1, 0x40, 0xce, 0xc6, 0xc3, 0x40, + 0xa0, 0x00, 0xe1, 0x42, 0x00, 0x88, 0x7b, 0xe8, 0x0c, 0x73, 0xab, 0x22, + 0x08, 0x0e, 0x2b, 0x20, 0xc0, 0x02, 0xf5, 0xf1, 0x2e, 0xd8, 0x3a, 0x0a, + 0x6f, 0xea, 0x2c, 0x70, 0xe6, 0xc2, 0xcb, 0x45, 0xf0, 0x00, 0x34, 0x00, + 0x17, 0x1d, 0x03, 0x16, 0x2f, 0x88, 0x4d, 0x88, 0xce, 0x88, 0x8c, 0x88, + 0x08, 0xb9, 0x08, 0xba, 0x25, 0x7e, 0x85, 0x7a, 0x10, 0xbe, 0xc3, 0x43, + 0xf0, 0x00, 0x40, 0x02, 0x53, 0x22, 0xc1, 0x02, 0x45, 0x7e, 0x3a, 0xb3, + 0x2c, 0xbe, 0x95, 0x88, 0x53, 0x26, 0x4b, 0x11, 0xd7, 0x88, 0x34, 0x88, + 0x56, 0x88, 0x08, 0xbc, 0x08, 0xbe, 0x25, 0x7c, 0x05, 0x26, 0x81, 0x10, + 0x4a, 0x24, 0x40, 0x76, 0x10, 0xb9, 0x85, 0x79, 0x2d, 0x70, 0x0d, 0x71, + 0xcd, 0x70, 0x24, 0xa3, 0xa8, 0x20, 0x41, 0x02, 0x71, 0x76, 0x45, 0xf2, + 0x0f, 0x0e, 0x14, 0x14, 0x5c, 0x88, 0x3d, 0x88, 0xff, 0x88, 0x9e, 0x88, + 0x05, 0xf0, 0x58, 0x88, 0x39, 0x88, 0xfb, 0x88, 0x9a, 0x88, 0x08, 0xb9, + 0x08, 0xbf, 0x45, 0x79, 0x05, 0x27, 0x02, 0x13, 0x10, 0xba, 0x45, 0x79, + 0x01, 0x29, 0x41, 0x02, 0xc1, 0xb9, 0x34, 0x71, 0x3e, 0x00, 0x21, 0x00, + 0x34, 0x72, 0x0f, 0xf2, 0x34, 0x73, 0x1f, 0xf4, 0x2f, 0x27, 0xbf, 0x00, + 0x6f, 0x23, 0x3f, 0x00, 0x25, 0x83, 0x0f, 0x21, 0x81, 0x03, 0x25, 0xa3, + 0x2f, 0x26, 0xbf, 0x00, 0x0b, 0xf0, 0x2f, 0x27, 0xbf, 0x00, 0x6f, 0x23, + 0x3f, 0x00, 0x25, 0x83, 0x10, 0x21, 0x81, 0x03, 0x25, 0xa3, 0x2f, 0x26, + 0xbf, 0x00, 0x2c, 0x71, 0xd8, 0x79, 0x26, 0xa3, 0x0f, 0xf0, 0x00, 0x28, + 0x81, 0x13, 0x28, 0xa3, 0x0b, 0xf0, 0x2f, 0x27, 0xbf, 0x00, 0x6f, 0x23, + 0x3f, 0x00, 0x27, 0x83, 0x0f, 0x21, 0x81, 0x03, 0x27, 0xa3, 0x2f, 0x26, + 0xbf, 0x00, 0x25, 0x72, 0xc5, 0x71, 0x61, 0x40, 0xad, 0x5a, 0xa7, 0x08, + 0x30, 0x00, 0x4a, 0x24, 0x40, 0x71, 0x11, 0xd8, 0x4a, 0x21, 0x00, 0x00, + 0xa8, 0x20, 0xc0, 0x01, 0xab, 0x20, 0xd0, 0x02, 0x04, 0x71, 0xab, 0x21, + 0x88, 0x01, 0x4a, 0x24, 0x80, 0x71, 0x16, 0xdc, 0x6c, 0x71, 0x23, 0xda, + 0x0c, 0x72, 0x24, 0xd9, 0xab, 0x24, 0xd0, 0x12, 0xab, 0x23, 0x88, 0x01, + 0xab, 0x22, 0xd0, 0x02, 0xab, 0x20, 0x88, 0x01, 0xab, 0x21, 0xd0, 0x02, + 0xab, 0x20, 0x88, 0x01, 0x17, 0xd8, 0x2c, 0x74, 0xa8, 0x20, 0xc0, 0x01, + 0xab, 0x20, 0xd0, 0x02, 0x04, 0x71, 0xab, 0x21, 0x88, 0x01, 0x4a, 0x24, + 0xc0, 0x70, 0x1d, 0xdc, 0x1e, 0xdb, 0x4c, 0x73, 0x1f, 0xd8, 0xab, 0x24, + 0xd0, 0x12, 0xab, 0x21, 0x88, 0x01, 0xab, 0x23, 0xd0, 0x02, 0xab, 0x22, + 0x88, 0x01, 0xab, 0x20, 0xd0, 0x02, 0x15, 0xd8, 0xab, 0x21, 0x88, 0x01, + 0xa8, 0x20, 0xc0, 0x02, 0x40, 0x20, 0x02, 0x04, 0x42, 0x20, 0x01, 0x04, + 0x04, 0x71, 0xab, 0x22, 0xd0, 0x02, 0xab, 0x21, 0x88, 0x01, 0x28, 0xda, + 0x07, 0xd9, 0x0c, 0x71, 0xab, 0x22, 0xd0, 0x02, 0xab, 0x21, 0x88, 0x01, + 0x17, 0x1d, 0x43, 0x16, 0xc6, 0xc6, 0xb0, 0xd9, 0x0c, 0x70, 0x34, 0xad, + 0xc6, 0xc6, 0xe0, 0x78, 0xea, 0xc2, 0x30, 0x41, 0x0e, 0x71, 0x36, 0xe9, + 0x40, 0x20, 0x0f, 0x07, 0xad, 0x70, 0x45, 0xde, 0x01, 0x87, 0x1d, 0x08, + 0x92, 0x04, 0x29, 0x08, 0x90, 0x04, 0x2f, 0x08, 0x50, 0x08, 0x3b, 0x08, + 0x91, 0x08, 0x00, 0x1f, 0x80, 0x1f, 0xa0, 0x00, 0x08, 0x41, 0x1c, 0xf0, + 0x12, 0xe8, 0x2b, 0x08, 0x51, 0x04, 0x00, 0x1f, 0x80, 0x1f, 0xa0, 0x00, + 0x54, 0x40, 0x14, 0xf0, 0x00, 0x1f, 0x80, 0x1f, 0xa0, 0x00, 0x74, 0x40, + 0x0e, 0xf0, 0x00, 0x1f, 0x80, 0x1f, 0xa0, 0x00, 0xec, 0x40, 0x0a, 0xf0, + 0x00, 0x1f, 0x01, 0x10, 0x06, 0xf0, 0x0e, 0x70, 0x00, 0x1e, 0x82, 0x73, + 0xf0, 0x00, 0x49, 0x00, 0x36, 0x09, 0x6f, 0xf6, 0xe1, 0x40, 0xa5, 0x71, + 0xa9, 0x0d, 0x64, 0x94, 0x55, 0x27, 0x0f, 0x1c, 0x02, 0x40, 0xca, 0xc6, + 0xf1, 0xc0, 0xa8, 0x5a, 0x14, 0x70, 0x0c, 0x71, 0x07, 0xf4, 0x29, 0xda, + 0xc3, 0x41, 0xf0, 0x00, 0x48, 0x00, 0x0c, 0x70, 0x40, 0xa9, 0xd1, 0xc0, + 0xe0, 0x7e, 0xe0, 0x78, 0xec, 0xc2, 0x50, 0x42, 0x30, 0x41, 0x10, 0x40, + 0xcb, 0x45, 0xf0, 0x00, 0x4b, 0x00, 0x20, 0x40, 0x40, 0x41, 0x60, 0x42, + 0x80, 0x43, 0xd2, 0x0f, 0xef, 0xff, 0x00, 0x1d, 0x83, 0x16, 0x14, 0x70, + 0x0c, 0x70, 0x4f, 0xf2, 0xc3, 0x42, 0xa0, 0x00, 0x54, 0x40, 0x22, 0x40, + 0x42, 0x41, 0x1e, 0x0b, 0xef, 0xff, 0x00, 0x1d, 0xc3, 0x16, 0xc3, 0x42, + 0xa0, 0x00, 0x74, 0x40, 0x22, 0x40, 0x0e, 0x0b, 0xef, 0xff, 0x42, 0x41, + 0xcb, 0x46, 0xf0, 0x00, 0x40, 0x02, 0xc3, 0x41, 0xf0, 0x00, 0x77, 0x02, + 0xe0, 0x86, 0x2d, 0x10, 0x83, 0x20, 0x00, 0x89, 0x6c, 0x20, 0x42, 0x00, + 0x53, 0x23, 0x40, 0x00, 0x45, 0x78, 0x00, 0xa9, 0x02, 0x40, 0x22, 0x41, + 0x42, 0x42, 0x02, 0x0a, 0x20, 0x00, 0x00, 0x1d, 0x03, 0x17, 0x28, 0xbf, + 0xca, 0xbf, 0x0d, 0xe8, 0x02, 0x40, 0x22, 0x41, 0xba, 0x09, 0x20, 0x00, + 0x42, 0x42, 0x05, 0xe8, 0x85, 0x27, 0x07, 0x10, 0x03, 0xf0, 0x85, 0x27, + 0x03, 0x10, 0x22, 0x41, 0x42, 0x42, 0xf6, 0x09, 0x20, 0x00, 0x00, 0x1d, + 0x43, 0x17, 0x60, 0x86, 0x8a, 0x21, 0x18, 0x00, 0x14, 0x70, 0xc5, 0x27, + 0x42, 0x10, 0x46, 0x27, 0x02, 0x10, 0x08, 0xba, 0x04, 0x23, 0x81, 0x0f, + 0xf8, 0xff, 0xff, 0x00, 0x0c, 0x71, 0x45, 0x79, 0x20, 0xa6, 0x00, 0x1d, + 0x83, 0x17, 0xcc, 0xc6, 0xf1, 0xc0, 0xc3, 0x40, 0x13, 0x00, 0x90, 0xa9, + 0x6e, 0x0e, 0x4f, 0xfe, 0x83, 0xe8, 0xd1, 0xc0, 0xe0, 0x7e, 0x3a, 0x0f, + 0x2f, 0xea, 0x2c, 0x71, 0xe2, 0xc2, 0xc3, 0x41, 0xa0, 0x00, 0xe0, 0x42, + 0xcb, 0x45, 0xf0, 0x00, 0x34, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0xe1, 0x42, + 0x00, 0x19, 0x03, 0x00, 0x17, 0x1d, 0x43, 0x14, 0xce, 0x0f, 0xef, 0xff, + 0x00, 0x18, 0x43, 0x00, 0xba, 0x0a, 0xcf, 0xff, 0x05, 0xe8, 0x92, 0xd8, + 0xde, 0x0c, 0x2f, 0xfe, 0x17, 0xad, 0x14, 0x8d, 0x83, 0xe8, 0x20, 0xd8, + 0x14, 0xad, 0xaf, 0xd8, 0x17, 0xad, 0x40, 0x58, 0xee, 0xc2, 0x70, 0x43, + 0x50, 0x41, 0x30, 0x42, 0x83, 0x0b, 0x30, 0x00, 0x10, 0x40, 0xad, 0x70, + 0xd7, 0x6d, 0x22, 0x76, 0xc1, 0x40, 0x35, 0x58, 0x0b, 0x08, 0x95, 0x00, + 0x3e, 0x1e, 0x83, 0x10, 0x05, 0xf0, 0x0b, 0x08, 0x54, 0x01, 0x3e, 0x1e, + 0xc3, 0x1f, 0x19, 0x8e, 0x40, 0x26, 0x0f, 0x17, 0xc1, 0xb8, 0x23, 0x08, + 0x71, 0x00, 0xe1, 0x40, 0x01, 0x97, 0x17, 0xe8, 0x48, 0x30, 0x00, 0x00, + 0xc3, 0x41, 0x12, 0x00, 0x64, 0x4b, 0xc1, 0x42, 0xb2, 0x5a, 0x23, 0x08, + 0x33, 0x00, 0x01, 0xaf, 0x1a, 0xf0, 0x02, 0x41, 0x9e, 0x08, 0x20, 0x00, + 0x42, 0x42, 0x09, 0xe8, 0x00, 0x41, 0x00, 0x80, 0xfe, 0xe8, 0xc0, 0xa1, + 0x03, 0xf0, 0x01, 0x1f, 0xc3, 0x1f, 0x28, 0x86, 0x0c, 0xe9, 0x21, 0x16, + 0x80, 0x10, 0xc1, 0xb8, 0x14, 0x72, 0x0c, 0x70, 0x05, 0xf4, 0x2f, 0x78, + 0x02, 0x41, 0x42, 0x42, 0x33, 0x58, 0x08, 0xa6, 0xa5, 0x71, 0x8d, 0x0d, + 0xc4, 0x94, 0x02, 0x40, 0xce, 0x0d, 0xef, 0xff, 0x42, 0x41, 0x5b, 0x0b, + 0x30, 0x20, 0x10, 0x42, 0xed, 0x70, 0xcd, 0x70, 0x11, 0xf0, 0x35, 0x58, + 0x10, 0x40, 0xa1, 0x40, 0x3a, 0x58, 0x35, 0x58, 0x0c, 0x20, 0x00, 0xa0, + 0xe1, 0x40, 0x56, 0xf7, 0xa1, 0x40, 0x3a, 0x58, 0x35, 0x58, 0x3e, 0x1d, + 0x02, 0x10, 0x0c, 0x71, 0x0e, 0xf0, 0x17, 0x6e, 0x00, 0x21, 0x0d, 0xa0, + 0x09, 0xf2, 0xa1, 0x40, 0x3a, 0x58, 0x07, 0xe8, 0x19, 0x8d, 0xc1, 0xb8, + 0xcf, 0x08, 0x71, 0x80, 0xa1, 0x40, 0xe1, 0x40, 0xc5, 0x71, 0x72, 0x76, + 0x3c, 0x26, 0xcf, 0x14, 0xca, 0x26, 0x26, 0x10, 0x04, 0x7f, 0xad, 0xf7, + 0xeb, 0xe8, 0x42, 0x40, 0xce, 0xc6, 0xe0, 0x78, 0xe2, 0xc2, 0x61, 0x88, + 0x08, 0x45, 0x40, 0x2b, 0x80, 0x07, 0x42, 0x28, 0xbe, 0x87, 0x0e, 0x00, + 0x24, 0x00, 0x80, 0x8d, 0x81, 0x40, 0x3d, 0x58, 0x07, 0xf0, 0xc1, 0xbb, + 0x0b, 0x0b, 0xb1, 0x00, 0x0c, 0x70, 0x81, 0x40, 0x33, 0x58, 0x00, 0xa5, + 0xc2, 0xc6, 0xe0, 0x78, 0x8d, 0x70, 0x17, 0xea, 0x2d, 0x10, 0x83, 0x00, + 0x27, 0x0b, 0x70, 0x00, 0x0a, 0x24, 0x80, 0x70, 0x3c, 0x49, 0xc3, 0x42, + 0xa0, 0x00, 0x08, 0x41, 0xa8, 0x20, 0xc0, 0x02, 0x20, 0x80, 0x0f, 0x09, + 0x81, 0x00, 0x34, 0x88, 0x07, 0x09, 0x9f, 0x00, 0x8d, 0x71, 0x55, 0x20, + 0x00, 0x0c, 0xe0, 0x7f, 0x81, 0x40, 0xe0, 0x78, 0x2d, 0x10, 0x80, 0x00, + 0x0f, 0x08, 0x51, 0x00, 0xc3, 0x40, 0xa0, 0x00, 0x54, 0x40, 0x21, 0x01, + 0xcf, 0xff, 0xc3, 0x40, 0xa0, 0x00, 0x08, 0x41, 0x15, 0x01, 0xcf, 0xff, + 0xc3, 0x40, 0xa0, 0x00, 0x74, 0x40, 0x0d, 0x01, 0xcf, 0xff, 0xe0, 0x78, + 0xc3, 0x42, 0xf0, 0x00, 0x4b, 0x00, 0x1b, 0xd9, 0x0c, 0x70, 0x00, 0x1a, + 0xc3, 0x07, 0xab, 0x21, 0xd0, 0x02, 0xab, 0x20, 0x88, 0x01, 0xc3, 0x40, + 0xf0, 0x00, 0x20, 0x01, 0x20, 0xd9, 0x26, 0xa0, 0x20, 0xa0, 0x6f, 0x26, + 0xff, 0x05, 0x90, 0xd9, 0x0c, 0x71, 0xe0, 0x7f, 0x20, 0xaa, 0x00, 0x00, + 0x2b, 0x66, 0x00, 0x00, 0x00, 0x00, 0x67, 0x17, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x90, 0x69, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x78, 0x51, 0x01, 0x00, 0x2e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x4e, 0x49, 0x03, + 0x54, 0x3b, 0x11, 0x00, 0x70, 0x91, 0x13, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x01, 0x58, 0x87, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x74, 0x91, 0x13, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x01, 0x3c, 0x87, 0xa0, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x6c, 0xa0, 0x00, 0x63, 0x0b, 0x00, 0x00, 0x00, 0x20, 0x00, 0xfc, + 0x23, 0x10, 0x00, 0xcc, 0x02, 0x04, 0x54, 0x22, 0x10, 0x00, 0xb4, 0xff, + 0x11, 0x00, 0xb8, 0xe2, 0x00, 0x00, 0x10, 0x00, 0xac, 0x00, 0x12, 0x00, + 0x40, 0x36, 0x11, 0x00, 0x18, 0xa0, 0x11, 0x00, 0x50, 0x39, 0x00, 0x00, + 0x11, 0x00, 0x04, 0x3a, 0x11, 0x00, 0x84, 0xa1, 0x11, 0x00, 0xf4, 0xa3, + 0x11, 0x00, 0xc8, 0x67, 0x00, 0x00, 0x13, 0x00, 0x04, 0xa4, 0x11, 0x00, + 0x00, 0xa2, 0x11, 0x00, 0x80, 0x1d, 0x12, 0x00, 0x28, 0x1e, 0x00, 0x08, + 0x12, 0x00, 0x58, 0x1f, 0x12, 0x00, 0x2c, 0x0a, 0x12, 0x00, 0x04, 0x02, + 0x04, 0xf4, 0x09, 0x12, 0x00, 0x02, 0x00, 0xdc, 0x02, 0x04, 0x34, 0x6c, + 0x12, 0x00, 0xa4, 0x01, 0x12, 0x00, 0xe8, 0x00, 0x12, 0x00, 0xe0, 0x67, + 0x00, 0x00, 0x12, 0x00, 0x68, 0x04, 0x12, 0x00, 0xb4, 0x9f, 0x11, 0x00, + 0x10, 0x80, 0x11, 0x00, 0x6c, 0x6a, 0x80, 0x0c, 0x13, 0x00, 0x80, 0x4b, + 0x12, 0x00, 0xc0, 0x02, 0x04, 0x00, 0x4c, 0x02, 0x6c, 0x02, 0x04, 0x34, + 0x27, 0x10, 0x00, 0xa0, 0x2c, 0x00, 0x4d, 0x12, 0x00, 0x20, 0x02, 0x04, + 0x40, 0x02, 0x04, 0x88, 0x63, 0x02, 0x24, 0x02, 0x18, 0xc0, 0x02, 0x04, + 0x9c, 0x24, 0x08, 0xa0, 0x10, 0x00, 0x60, 0x02, 0x14, 0x34, 0x47, 0x13, + 0x00, 0x8c, 0x13, 0x11, 0x00, 0xa0, 0x02, 0x04, 0xb8, 0x02, 0x04, 0x20, + 0x80, 0x94, 0xae, 0x11, 0x00, 0x3c, 0x02, 0x04, 0xf4, 0x7e, 0x11, 0x00, + 0x2c, 0x1a, 0x12, 0x00, 0xb0, 0x02, 0x04, 0xb2, 0x00, 0xbc, 0x02, 0x04, + 0x54, 0x1b, 0x02, 0x7c, 0x02, 0x04, 0x18, 0x02, 0x0c, 0x3c, 0x6b, 0x12, + 0x00, 0xfc, 0x18, 0x12, 0x00, 0xa0, 0x0c, 0xd8, 0x19, 0x12, 0x00, 0x94, + 0x02, 0x10, 0x14, 0x02, 0x0c, 0xf0, 0x17, 0x02, 0x74, 0x02, 0xec, 0x04, + 0x09, 0x13, 0x00, 0x02, 0xa8, 0x84, 0x02, 0x5c, 0xd4, 0x1d, 0x13, 0x00, + 0x4c, 0x1a, 0x13, 0x00, 0xdc, 0x02, 0x04, 0x28, 0x02, 0x04, 0x78, 0x02, + 0x04, 0x0c, 0x12, 0xec, 0x97, 0x02, 0xb8, 0x02, 0x04, 0x4c, 0x36, 0x13, + 0x00, 0xfc, 0x02, 0x20, 0x34, 0x75, 0x02, 0x64, 0x69, 0x11, 0x00, 0x00, + 0x08, 0x7c, 0x96, 0x12, 0x00, 0x54, 0x67, 0x10, 0x00, 0xc0, 0x66, 0x10, + 0x02, 0xd8, 0x10, 0x00, 0xfc, 0x68, 0x28, 0xa8, 0x10, 0x00, 0x0c, 0x02, + 0x10, 0x4c, 0x02, 0x08, 0x20, 0x69, 0x10, 0x00, 0x68, 0x02, 0x08, 0xd8, + 0x02, 0x04, 0x2c, 0x02, 0x04, 0x2a, 0x21, 0x14, 0x02, 0x04, 0xa4, 0x02, + 0x44, 0xc4, 0x02, 0x04, 0x0c, 0x9c, 0x12, 0x24, 0x61, 0x13, 0x00, 0x44, + 0x02, 0x04, 0x48, 0xf5, 0x08, 0x0a, 0x11, 0x00, 0xc0, 0x12, 0x38, 0x40, + 0x24, 0x12, 0x00, 0x4c, 0x02, 0x04, 0x60, 0x02, 0x04, 0xcc, 0x26, 0x12, + 0x00, 0x82, 0x82, 0xf0, 0x02, 0x04, 0x30, 0x27, 0x12, 0x00, 0xa8, 0x02, + 0x04, 0xc8, 0x02, 0x04, 0x00, 0x29, 0x12, 0x00, 0x98, 0x02, 0x04, 0x0a, + 0x0a, 0xec, 0x02, 0x04, 0xfc, 0x02, 0x04, 0x50, 0x2a, 0x12, 0x00, 0x60, + 0x02, 0x04, 0xdc, 0x02, 0x04, 0xc4, 0x37, 0x12, 0x00, 0x40, 0x08, 0xf4, + 0x5d, 0x12, 0x00, 0x14, 0x69, 0x12, 0x5c, 0x38, 0x12, 0x00, 0xec, 0x02, + 0x04, 0x94, 0x39, 0x12, 0x00, 0x2a, 0x08, 0xa0, 0x02, 0x04, 0xb8, 0x02, + 0x04, 0xc4, 0x02, 0x04, 0x88, 0x3a, 0x12, 0x00, 0xac, 0x02, 0x04, 0x24, + 0x3c, 0x12, 0x00, 0xca, 0x2c, 0xbc, 0x02, 0x04, 0xa4, 0x02, 0x68, 0xe0, + 0x31, 0x02, 0x68, 0x02, 0x04, 0x04, 0x32, 0x02, 0x3c, 0x02, 0x04, 0x80, + 0x02, 0x04, 0x00, 0x33, 0xab, 0x2a, 0x12, 0xc8, 0x02, 0x1c, 0x30, 0x02, + 0x04, 0x34, 0x02, 0x04, 0x58, 0x02, 0x88, 0xa8, 0x02, 0x14, 0xd8, 0x02, + 0x04, 0xfc, 0x02, 0x04, 0x00, 0x35, 0x83, 0xaa, 0x12, 0xe4, 0x02, 0x04, + 0x30, 0x36, 0x12, 0x00, 0x84, 0x02, 0x04, 0x94, 0x02, 0x04, 0xdc, 0x02, + 0x04, 0x08, 0x02, 0x84, 0x10, 0x02, 0x04, 0x2a, 0x10, 0x1c, 0x02, 0x04, + 0x40, 0x02, 0x04, 0x90, 0x02, 0x04, 0xa0, 0xf3, 0x11, 0x00, 0x95, 0x00, + 0x0d, 0x01, 0xb4, 0x6e, 0xa0, 0xa4, 0x00, 0x00, 0xbc, 0x02, 0x04, 0xf4, + 0x8b, 0x22, 0x3c, 0x8d, 0x12, 0x50, 0x8e, 0x13, 0x00, 0xe0, 0xb5, 0xa0, + 0x00, 0x03, 0x00, 0x01, 0x4b, 0x00, 0x00, 0x6f, 0x7f, 0x40, 0xff, 0x01, + 0x02, 0x2f, 0x08, 0x1f, 0x13, 0x00, 0x60, 0x99, 0xa0, 0xc0, 0x84, 0x00, + 0xe0, 0xbd, 0xa0, 0x00, 0xd0, 0x02, 0x2c, 0x02, 0x13, 0x00, 0xc4, 0x06, + 0x08, 0xe0, 0xb6, 0xa0, 0x00, 0x02, 0x24, 0x12, 0xdc, 0x50, 0x03, 0x14, + 0x20, 0xb8, 0x09, 0x0c, 0xff, 0xff, 0x00, 0x00, 0x04, 0x03, 0x15, 0x0a, + 0x04, 0x03, 0x14, 0x03, 0x0a, 0x10, 0x03, 0x0b, 0x1f, 0xe8, 0x03, 0x14, + 0x02, 0x40, 0x03, 0x0b, 0x08, 0x04, 0x03, 0x14, 0x04, 0x00, 0x40, 0x00, + 0x00, 0x80, 0x08, 0x13, 0x00, 0x05, 0x14, 0x09, 0x10, 0x03, 0x0a, 0xff, + 0xff, 0x0f, 0x14, 0x03, 0x14, 0x0f, 0x04, 0x0f, 0x10, 0x0f, 0x10, 0x0f, + 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x03, + 0x10, 0x03, 0xa8, 0x03, 0x08, 0x07, 0x04, 0x07, 0x10, 0xff, 0xff, 0x07, + 0x08, 0x0f, 0x18, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x07, 0x48, 0x0f, + 0x08, 0x07, 0x10, 0x0f, 0x30, 0x0b, 0x18, 0x0b, 0x0c, 0x07, 0x28, 0x03, + 0x08, 0x03, 0x18, 0x03, 0x04, 0x07, 0x0c, 0xff, 0xff, 0x03, 0x08, 0x07, + 0x04, 0x07, 0x18, 0x0f, 0x10, 0x03, 0x10, 0x0b, 0x1c, 0x0b, 0x0c, 0x03, + 0x1c, 0x03, 0x04, 0x0f, 0x14, 0x0f, 0x10, 0x0b, 0x24, 0x0f, 0x1c, 0x07, + 0x10, 0x07, 0x08, 0x0b, 0x2c, 0xff, 0xff, 0x03, 0x0c, 0x0f, 0x04, 0x0f, + 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, + 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, + 0x10, 0x0f, 0x10, 0xff, 0xff, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, + 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, + 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0f, 0x10, 0x0b, 0x10, 0x13, + 0xf4, 0x70, 0xfb, 0x04, 0x00, 0x00, 0x10, 0x02, 0x02, 0x08, 0x17, 0x06, + 0x14, 0x04, 0x4b, 0x69, 0x03, 0x14, 0x01, 0x08, 0x22, 0x05, 0x09, 0x03, + 0x14, 0x4f, 0x50, 0x0f, 0x14, 0xff, 0xf8, 0x03, 0x2a, 0x0f, 0x14, 0x09, + 0x14, 0x02, 0x62, 0x02, 0x7d, 0x03, 0x10, 0x03, 0x04, 0x05, 0x28, 0x00, + 0x01, 0x00, 0x72, 0x17, 0x03, 0x10, 0x03, 0x04, 0x0f, 0x14, 0x09, 0x14, + 0xfd, 0xc5, 0x42, 0xc8, 0x02, 0x03, 0x0e, 0x05, 0x04, 0x05, 0x28, 0x0f, + 0x14, 0x53, 0x2c, 0x0f, 0x14, 0x0f, 0x14, 0x00, 0x57, 0x04, 0x01, 0x00, + 0x20, 0x05, 0x4c, 0x03, 0x06, 0xc3, 0xfc, 0x05, 0x50, 0x0f, 0xa0, 0x00, + 0x00, 0x05, 0x00, 0x02, 0xa0, 0x5e, 0x40, 0x05, 0x00, 0x02, 0x64, 0x0f, + 0x14, 0x0f, 0x14, 0x55, 0xb8, 0x1f, 0x54, 0x02, 0x61, 0xf4, 0xff, 0x00, + 0x08, 0x0f, 0x78, 0x04, 0x03, 0xa3, 0x02, 0x05, 0x03, 0x88, 0x03, 0x04, + 0x06, 0x8c, 0x03, 0x0b, 0x08, 0x04, 0x05, 0x14, 0x0f, 0x78, 0x03, 0x39, + 0x0f, 0x14, 0x03, 0x14, 0xff, 0xff, 0x08, 0x37, 0x04, 0x09, 0x0f, 0x3c, + 0x03, 0x15, 0x0f, 0x14, 0x09, 0x14, 0x03, 0x0a, 0x09, 0x04, 0x0f, 0x28, + 0x03, 0x1a, 0x0f, 0x14, 0x09, 0x14, 0x12, 0xca, 0x1f, 0xcc, 0x03, 0x8f, + 0x0f, 0xdc, 0xfb, 0x17, 0x0f, 0x14, 0x15, 0x2c, 0x01, 0x12, 0x6a, 0x03, + 0x4b, 0x04, 0x04, 0x05, 0x64, 0x12, 0x2a, 0x1f, 0xa4, 0x0e, 0x3c, 0x02, + 0x2d, 0x01, 0x02, 0x04, 0x00, 0xdc, 0x6f, 0x80, 0x3a, 0xa0, 0x00, 0x24, + 0x72, 0xa0, 0x00, 0xe4, 0x02, 0x08, 0xe0, 0x02, 0x04, 0x5e, 0x02, 0x04, + 0x02, 0x18, 0x04, 0x7a, 0x38, 0xae, 0x00, 0x68, 0xa0, 0x00, 0x68, 0xad, + 0xa0, 0x00, 0x5c, 0x71, 0xa0, 0x00, 0x54, 0x02, 0x04, 0xa8, 0x05, 0x1c, + 0x04, 0x38, 0xec, 0x55, 0xab, 0x02, 0x0c, 0x2c, 0x02, 0x38, 0xf4, 0x02, + 0x08, 0xf0, 0x02, 0x04, 0x60, 0x02, 0x04, 0x07, 0x38, 0x48, 0x02, 0x38, + 0xfc, 0x02, 0x10, 0x64, 0x02, 0x04, 0x3a, 0xa8, 0x62, 0x02, 0x04, 0x54, + 0x02, 0x04, 0x02, 0x1c, 0x04, 0x38, 0x04, 0x70, 0xa0, 0x00, 0x34, 0x02, + 0x38, 0x0c, 0x02, 0x08, 0x08, 0x02, 0x04, 0x56, 0x55, 0x66, 0x05, 0x1c, + 0x04, 0x70, 0x58, 0x02, 0x38, 0x74, 0x02, 0x70, 0x6c, 0x02, 0x6c, 0x64, + 0x02, 0x04, 0xac, 0x0a, 0x1c, 0x68, 0x02, 0x1c, 0x3c, 0x55, 0x55, 0x02, + 0x38, 0x18, 0x02, 0x34, 0x14, 0x02, 0x04, 0x68, 0x0a, 0x1c, 0x88, 0x02, + 0x1c, 0x54, 0x02, 0x1c, 0x28, 0x02, 0x18, 0x24, 0x02, 0x04, 0x6a, 0x55, + 0x2d, 0x0a, 0x1c, 0xa8, 0x02, 0x1c, 0xb8, 0x02, 0x04, 0x74, 0x02, 0x20, + 0x6c, 0x02, 0x04, 0x34, 0x02, 0x20, 0x02, 0x8c, 0x02, 0x02, 0x04, 0x00, + 0x8c, 0x55, 0x57, 0x02, 0x10, 0x3c, 0x02, 0x10, 0x6e, 0x02, 0x30, 0x6c, + 0x02, 0x04, 0x55, 0x02, 0x04, 0x02, 0x18, 0x04, 0xa8, 0x44, 0x02, 0x18, + 0x80, 0x02, 0x8c, 0x7c, 0x35, 0xa0, 0x02, 0x88, 0x74, 0x02, 0x04, 0xb0, + 0x05, 0x1c, 0x22, 0xd7, 0x00, 0x00, 0x28, 0xb0, 0xa0, 0x00, 0xd8, 0x02, + 0x54, 0x9c, 0x02, 0x40, 0xba, 0xaa, 0x94, 0x02, 0x04, 0x4c, 0x02, 0x2c, + 0x02, 0x38, 0x04, 0x1c, 0x3c, 0x02, 0x1c, 0xe8, 0x02, 0x1c, 0xac, 0x02, + 0x18, 0xa4, 0x02, 0x04, 0x54, 0x0a, 0x1c, 0xaa, 0x56, 0x50, 0x02, 0x1c, + 0xf8, 0x02, 0x1c, 0xbc, 0x02, 0x18, 0xb4, 0x02, 0x04, 0x5c, 0x05, 0x1c, + 0x04, 0x70, 0x64, 0x02, 0x0c, 0xc4, 0x02, 0x14, 0x6c, 0x35, 0xa8, 0x02, + 0x08, 0x68, 0x02, 0x04, 0x70, 0x05, 0x70, 0x14, 0x18, 0x08, 0xaf, 0xa0, + 0x00, 0x8c, 0x02, 0x8c, 0x8c, 0x02, 0x88, 0x84, 0x02, 0x04, 0xaa, 0x5a, + 0xb4, 0x0a, 0x1c, 0x18, 0x02, 0x1c, 0x98, 0x02, 0x1c, 0x9c, 0x02, 0x18, + 0x94, 0x02, 0x04, 0xb8, 0x05, 0x1c, 0x04, 0x8c, 0x64, 0x02, 0x70, 0xa4, + 0xd5, 0xaa, 0x02, 0x1c, 0xac, 0x02, 0x18, 0xa4, 0x02, 0x04, 0xbc, 0x05, + 0x1c, 0x04, 0x54, 0x28, 0x02, 0x38, 0x7c, 0x02, 0x68, 0x74, 0x02, 0x14, + 0x72, 0x02, 0x04, 0xae, 0x6a, 0x56, 0x02, 0x04, 0x02, 0xc4, 0x04, 0x8c, + 0x88, 0x02, 0x18, 0xcc, 0x02, 0x8c, 0x90, 0x02, 0x08, 0x8c, 0x02, 0x04, + 0x76, 0x05, 0x1c, 0x94, 0x3b, 0xc8, 0x55, 0x57, 0x02, 0x50, 0x98, 0x02, + 0x14, 0x7a, 0x02, 0x14, 0x78, 0x02, 0x04, 0x57, 0x02, 0x04, 0x02, 0x38, + 0x04, 0x54, 0x68, 0x02, 0x54, 0xa4, 0x02, 0x1c, 0x7e, 0xb5, 0xaa, 0x02, + 0x14, 0x7c, 0x02, 0x04, 0x58, 0x02, 0x04, 0x07, 0x1c, 0x88, 0x02, 0x1c, + 0xd4, 0x02, 0x3c, 0xbc, 0x02, 0x88, 0xb4, 0x02, 0x04, 0xc0, 0x05, 0x1c, + 0x55, 0xad, 0x04, 0x70, 0xac, 0x02, 0x34, 0xb0, 0x02, 0x04, 0x82, 0x02, + 0x14, 0x80, 0x02, 0x04, 0x59, 0x02, 0x04, 0x07, 0x38, 0x98, 0x02, 0x38, + 0xb4, 0x02, 0x1c, 0xea, 0xaa, 0x86, 0x02, 0x14, 0x84, 0x02, 0x04, 0x5a, + 0x02, 0x04, 0x02, 0x1c, 0x04, 0x38, 0xbc, 0x02, 0x18, 0xd4, 0x02, 0xa8, + 0xc4, 0x02, 0x08, 0xc0, 0x02, 0x04, 0x16, 0x40, 0x88, 0x05, 0x1c, 0x04, + 0x8c, 0xa8, 0x02, 0x38, 0x20, 0xb4, 0xa0, 0x00, 0x30, 0xb1, 0xa0, 0x00, + 0x10, 0x02, 0x04, 0xb8, 0x57, 0x55, 0x02, 0x10, 0x02, 0x38, 0x04, 0x1c, + 0xc8, 0x02, 0x0c, 0xdc, 0x02, 0x38, 0xd0, 0x02, 0x34, 0xcc, 0x02, 0x04, + 0x8a, 0x0a, 0x38, 0xd8, 0x02, 0x1c, 0xec, 0x55, 0x55, 0x02, 0xa8, 0xdc, + 0x02, 0xa4, 0xd4, 0x02, 0x04, 0xc8, 0x0a, 0x1c, 0xe8, 0x02, 0x1c, 0xe4, + 0x02, 0x38, 0xdc, 0x02, 0x34, 0xd8, 0x02, 0x04, 0x8c, 0x55, 0x55, 0x0a, + 0x1c, 0xf8, 0x02, 0x1c, 0xec, 0x02, 0x1c, 0xe8, 0x02, 0x18, 0xe4, 0x02, + 0x04, 0x8e, 0x0a, 0x1c, 0x08, 0x12, 0x88, 0xf4, 0x02, 0x1c, 0xf0, 0xb5, + 0xaa, 0x02, 0x18, 0xec, 0x02, 0x04, 0x90, 0x05, 0x1c, 0x04, 0xc4, 0xf8, + 0x02, 0x10, 0xfc, 0x02, 0x1c, 0x00, 0x02, 0x6c, 0xfc, 0x02, 0x0c, 0x92, + 0x0a, 0x1c, 0xb2, 0x56, 0x08, 0x02, 0x14, 0x04, 0x73, 0x02, 0xc0, 0x02, + 0x08, 0x0c, 0x02, 0x04, 0x94, 0x05, 0x1c, 0x24, 0xbc, 0x0c, 0x02, 0x18, + 0x14, 0x02, 0x14, 0x98, 0x75, 0x55, 0x02, 0x14, 0x96, 0x02, 0x04, 0x5b, + 0x02, 0x04, 0x02, 0xe0, 0x04, 0x54, 0x1c, 0x02, 0x18, 0x10, 0x22, 0x68, + 0x0c, 0x02, 0x58, 0x04, 0x02, 0x04, 0xd4, 0x55, 0x55, 0x0a, 0x1c, 0x24, + 0x02, 0x1c, 0x14, 0x02, 0x3c, 0x2c, 0x02, 0x08, 0x28, 0x02, 0x04, 0x9a, + 0x0a, 0x1c, 0x34, 0x02, 0x10, 0x1c, 0x02, 0x38, 0x1c, 0xb5, 0xaa, 0x02, + 0x34, 0x14, 0x02, 0x04, 0xd8, 0x05, 0x1c, 0x14, 0x34, 0x18, 0x02, 0xc4, + 0x3c, 0x02, 0x20, 0x9e, 0x02, 0x14, 0x9c, 0x02, 0x04, 0x5c, 0x02, 0x04, + 0xab, 0xba, 0x02, 0x70, 0x04, 0x8c, 0x1c, 0x02, 0x50, 0x40, 0x02, 0x1c, + 0xa2, 0x02, 0x14, 0xa0, 0x02, 0x04, 0x5d, 0x02, 0x04, 0x02, 0x1c, 0x04, + 0x8c, 0x48, 0x02, 0x18, 0xaa, 0xf1, 0x24, 0x02, 0x20, 0x50, 0x02, 0x08, + 0x4c, 0x02, 0x04, 0xa4, 0x02, 0x1c, 0x45, 0xa4, 0x01, 0x00, 0xef, 0x42, + 0xc0, 0x02, 0x28, 0x04, 0x03, 0x04, 0x65, 0xf1, 0xff, 0x02, 0x0a, 0x3c, + 0xe7, 0x11, 0x66, 0x68, 0x0f, 0x20, 0x02, 0x1d, 0x02, 0x03, 0x0f, 0x20, + 0x02, 0x13, 0x04, 0x03, 0x07, 0x40, 0x03, 0x0d, 0x0f, 0x60, 0x03, 0x14, + 0x07, 0x20, 0xf7, 0xfd, 0x07, 0x40, 0x53, 0x35, 0x0b, 0x80, 0x06, 0x03, + 0x25, 0x06, 0x04, 0x0f, 0x40, 0x03, 0x17, 0x0f, 0x40, 0x04, 0x52, 0x75, + 0x0b, 0x40, 0x0f, 0x20, 0x0f, 0x20, 0x07, 0x20, 0x03, 0x4c, 0xff, 0xff, + 0x0f, 0x60, 0x03, 0x14, 0x07, 0x20, 0x07, 0xa0, 0x0f, 0x40, 0x0f, 0x20, + 0x0f, 0x20, 0x07, 0x20, 0x03, 0x4c, 0x0f, 0x60, 0x03, 0x14, 0x07, 0x20, + 0x07, 0x60, 0x1f, 0x00, 0x1f, 0x00, 0x0f, 0x60, 0xff, 0xbb, 0x0f, 0x40, + 0x0f, 0x20, 0x07, 0x20, 0x03, 0x6c, 0x0f, 0x80, 0x03, 0x14, 0x07, 0x20, + 0x0f, 0x80, 0x03, 0x1c, 0x03, 0x04, 0x0a, 0x03, 0x05, 0x06, 0x04, 0x03, + 0x40, 0x05, 0x1f, 0x60, 0xff, 0xff, 0x06, 0x1c, 0x03, 0x07, 0x0f, 0x20, + 0x03, 0x14, 0x07, 0x60, 0x03, 0x0c, 0x03, 0x20, 0x0f, 0xe0, 0x0f, 0x60, + 0x0f, 0xc0, 0x07, 0x40, 0x0f, 0xa0, 0x03, 0x50, 0x03, 0x04, 0x0f, 0x40, + 0x0f, 0x40, 0xff, 0xcf, 0x0f, 0x40, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, + 0x07, 0x20, 0x03, 0x6c, 0x03, 0xc0, 0x0f, 0x20, 0x07, 0x20, 0x07, 0xa0, + 0x1f, 0x20, 0x07, 0x20, 0x10, 0x75, 0x35, 0x40, 0x1f, 0x00, 0xff, 0xfe, + 0x0f, 0xc0, 0x0f, 0x40, 0x07, 0x40, 0x07, 0x80, 0x0f, 0x40, 0x0f, 0x40, + 0x0f, 0x20, 0x0f, 0x20, 0x02, 0x1e, 0xc0, 0x2f, 0x60, 0x0f, 0x40, 0x0f, + 0x40, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0xff, 0xff, 0x0f, 0x20, 0x0f, + 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x1f, 0x20, 0x1f, 0x20, 0x0f, + 0x20, 0x0f, 0x20, 0x0f, 0x60, 0x0f, 0x60, 0x0f, 0x20, 0x0f, 0x20, 0x2f, + 0x00, 0x07, 0x60, 0x27, 0x00, 0xff, 0xff, 0x0f, 0x20, 0x0f, 0x20, 0x0f, + 0x20, 0x07, 0x20, 0x17, 0xe0, 0x0f, 0x20, 0x07, 0x20, 0x0f, 0x60, 0x03, + 0x30, 0x03, 0x04, 0x0f, 0x20, 0x0f, 0x40, 0x0f, 0x20, 0x1f, 0x20, 0x07, + 0x20, 0x27, 0xa0, 0xff, 0xff, 0x0f, 0x20, 0x07, 0x20, 0x03, 0x6c, 0x33, + 0x00, 0x2f, 0x40, 0x2f, 0x40, 0x1f, 0x40, 0x1f, 0x40, 0x0f, 0x20, 0x0f, + 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, + 0x20, 0xff, 0xff, 0x0f, 0x20, 0x0f, 0x20, 0x1f, 0x40, 0x17, 0x00, 0x1f, + 0x80, 0x13, 0x10, 0x03, 0x04, 0x0f, 0x20, 0x0f, 0x40, 0x0f, 0x20, 0x0f, + 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0xff, + 0xff, 0x0f, 0xe0, 0x0f, 0xe0, 0x1f, 0xe0, 0x07, 0x40, 0x03, 0xcc, 0x13, + 0xe0, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x80, 0x07, 0x20, 0x1f, 0x20, 0x03, + 0x50, 0x03, 0x04, 0x0f, 0x20, 0x0f, 0x40, 0x0f, 0x20, 0xff, 0xff, 0x0f, + 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0x20, 0x0f, 0xc0, 0x07, 0x20, 0x2f, + 0xe0, 0x03, 0x9c, 0x03, 0x04, 0x07, 0x20, 0x03, 0x0c, 0x13, 0x00, 0x2f, + 0xe0, 0x2f, 0xe0, 0x1f, 0x60, 0x1f, 0x60, 0xaf, 0xa0, 0x0f, 0x20, 0x0b, + 0x20, 0x02, 0x64, 0x08, 0x6f, 0x1c, 0xa2, 0x54, 0x78, 0x92, 0xd4, 0xe0, + 0xb2, 0xa0, 0x00, 0xa0, 0x02, 0x04, 0x4c, 0x92, 0xd8, 0x5e, 0x41, 0x44, + 0x02, 0x04, 0x02, 0x24, 0x03, 0x03, 0x08, 0x28, 0x2c, 0x02, 0x28, 0x98, + 0x02, 0x28, 0x60, 0xb3, 0xa0, 0x00, 0x20, 0x02, 0x04, 0x64, 0xbd, 0xaa, + 0x02, 0x24, 0x5c, 0x02, 0x04, 0x03, 0x25, 0x02, 0x04, 0x08, 0x28, 0x38, + 0x02, 0x28, 0xc8, 0x02, 0x28, 0xe0, 0x02, 0x24, 0xa0, 0x02, 0x04, 0x84, + 0x02, 0x24, 0x5e, 0x55, 0x7c, 0x02, 0x04, 0x02, 0x24, 0x03, 0x03, 0x08, + 0x28, 0xc4, 0x92, 0xe8, 0xe0, 0xb2, 0x48, 0xb0, 0xb2, 0x7c, 0x80, 0x02, + 0x04, 0xcc, 0x92, 0xfc, 0xc4, 0xaf, 0xaa, 0x02, 0x04, 0x03, 0x25, 0x02, + 0x04, 0x08, 0x28, 0xcc, 0x02, 0x28, 0xf8, 0x02, 0x28, 0x10, 0x02, 0x9c, + 0xe0, 0x02, 0x28, 0xec, 0x02, 0x24, 0xe4, 0x02, 0x04, 0x57, 0xd5, 0x02, + 0x24, 0x03, 0x03, 0x08, 0x28, 0xd0, 0x02, 0x28, 0x04, 0x02, 0x78, 0x70, + 0x02, 0x28, 0x40, 0x02, 0x04, 0xfc, 0x02, 0x24, 0xf4, 0x02, 0x04, 0x03, + 0x25, 0x53, 0xbb, 0x13, 0x50, 0x02, 0x29, 0x10, 0x00, 0xfa, 0x44, 0x50, + 0x02, 0x4c, 0x5c, 0x02, 0x58, 0x03, 0x20, 0x28, 0x02, 0x38, 0x03, 0x08, + 0x07, 0x04, 0x04, 0xc4, 0xca, 0x5a, 0x3b, 0x00, 0xa4, 0x68, 0x01, 0x07, + 0x15, 0x06, 0x08, 0x90, 0xa2, 0xe8, 0xb0, 0x02, 0x04, 0x03, 0x0f, 0x74, + 0x02, 0xec, 0x03, 0x08, 0x07, 0x04, 0x01, 0x08, 0xd7, 0xce, 0x05, 0x0a, + 0x03, 0x70, 0x0f, 0x38, 0xd0, 0x02, 0x34, 0xf0, 0x02, 0x04, 0x03, 0x22, + 0x80, 0x0f, 0x38, 0x0a, 0x38, 0x02, 0xa8, 0x02, 0x00, 0x06, 0x10, 0x03, + 0x2c, 0x60, 0xe7, 0x60, 0xb9, 0xa0, 0x00, 0x60, 0xc2, 0xa8, 0x03, 0x0c, + 0x38, 0xc2, 0x44, 0x03, 0x08, 0x07, 0x04, 0x04, 0x18, 0x05, 0x0a, 0x0f, + 0x70, 0x03, 0x16, 0xda, 0x07, 0xb0, 0x02, 0xdc, 0xbc, 0x02, 0x04, 0x03, + 0x0c, 0x94, 0x0f, 0x70, 0x0a, 0xe0, 0x04, 0x70, 0xb4, 0xa6, 0x03, 0x2a, + 0x00, 0x00, 0xe0, 0xba, 0xa0, 0x74, 0x41, 0x00, 0xc0, 0x06, 0x70, 0x48, + 0x0f, 0x70, 0x0a, 0x70, 0x02, 0x38, 0x08, 0x0b, 0xa8, 0x20, 0xb5, 0xa0, + 0x00, 0x78, 0x06, 0xe0, 0x58, 0x6f, 0xb0, 0x0f, 0x38, 0x26, 0xbd, 0x03, + 0xa8, 0x04, 0x38, 0x20, 0x05, 0x6c, 0x03, 0x06, 0x60, 0xbc, 0xa0, 0x00, + 0x80, 0x02, 0x3c, 0x03, 0x0c, 0x78, 0x0f, 0x38, 0xf7, 0x0f, 0x06, 0x70, + 0x03, 0x1c, 0x0f, 0x04, 0xff, 0x02, 0x01, 0x0f, 0x14, 0x0f, 0x10, 0x0f, + 0x10, 0x07, 0x10, 0x03, 0x88, 0x07, 0x0c, 0x0b, 0x08, 0x98, 0xbb, 0x12, + 0x00, 0x80, 0xc1, 0x9c, 0x82, 0x11, 0x00, 0xd4, 0x4a, 0x12, 0x82, 0x9e, + 0x09, 0x1a, 0xf8, 0xcc, 0x12, 0x00, 0x7c, 0x0a, 0x04, 0x03, 0x1a, 0x8f, + 0x03, 0x1f, 0xe0, 0x03, 0x14, 0x0b, 0x04, 0xf3, 0x61, 0xe0, 0x95, 0x13, + 0x0b, 0x13, 0x08, 0x0c, 0x13, 0xdf, 0xcc, 0x5c, 0x12, 0x00, 0x00, 0x02, + 0x34, 0xb4, 0xf0, 0x00, 0x03, 0x69, 0xb0, 0x04, 0x4d, 0x09, 0x0c, 0xa0, + 0x01, 0xf0, 0x00, 0x13, 0x23, 0xa0, 0x07, 0x18, 0x02, 0x31, 0x80, 0x03, + 0x0c, 0x96, 0x7c, 0x08, 0x22, 0xc1, 0x12, 0x41, 0xe8, 0x03, 0x0c, 0x00, + 0xa0, 0x02, 0x50, 0x04, 0x00, 0x05, 0x3c, 0x02, 0x18, 0x12, 0x8d, 0x05, + 0x18, 0x03, 0x3a, 0x80, 0x3c, 0x04, 0x00, 0x48, 0x04, 0x24, 0x02, 0x23, + 0x03, 0x03, 0x13, 0xf0, 0x02, 0x00, 0x00, 0x80, 0x0e, 0x04, 0x7c, 0xeb, + 0xa0, 0x00, 0x7c, 0x02, 0x00, 0xf5, 0x02, 0x04, 0xff, 0xa0, 0x00, 0x0b, + 0x0b, 0x07, 0x0b, 0x02, 0x06, 0x03, 0x0d, 0x0d, 0x09, 0x0d, 0x00, 0x00, + 0x02, 0x08, 0x05, 0x1f, 0x1f, 0x13, 0x1d, 0x06, 0x10, 0x07, 0x25, 0x25, + 0x15, 0x25, 0x06, 0x14, 0x00, 0x00, 0x09, 0x79, 0x65, 0x69, 0x5d, 0x14, + 0x62, 0x0b, 0x79, 0x77, 0x77, 0x77, 0x14, 0x76, 0x0d, 0x00, 0x00, 0x00, + 0x00, 0x0e, 0x0e, 0x09, 0x0e, 0x03, 0x08, 0x04, 0x11, 0x11, 0x0b, 0x11, + 0x03, 0x0a, 0x07, 0x27, 0x00, 0x00, 0x27, 0x19, 0x24, 0x09, 0x08, 0x09, + 0x2f, 0x2f, 0x1a, 0x2f, 0x08, 0x19, 0x0c, 0x98, 0x7f, 0x84, 0x00, 0x18, + 0x74, 0x1a, 0x7b, 0x0e, 0x98, 0x95, 0x95, 0x95, 0x1a, 0x94, 0x11, 0x03, + 0x7d, 0x05, 0x04, 0xa9, 0x1a, 0xa1, 0x00, 0x00, 0xab, 0x55, 0x17, 0x00, + 0x00, 0x3d, 0x7e, 0x0d, 0xbf, 0x00, 0x00, 0x80, 0x3f, 0x3a, 0x3f, 0xd4, + 0x00, 0x00, 0xc0, 0xcc, 0x76, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x66, 0x02, 0x00, + 0x02, 0x00, 0x67, 0x17, 0xd4, 0x05, 0x22, 0x83, 0x2f, 0xc0, 0x87, 0x79, + 0x26, 0xf6, 0x0d, 0x4a, 0x03, 0x5b, 0x45, 0x99, 0x55, 0x60, 0x2b, 0xa2, + 0xb0, 0x19, 0x37, 0x52, 0x50, 0xbb, 0x2a, 0x49, 0xd7, 0xae, 0xa4, 0xc1, + 0x00, 0x00, 0x00, 0x00, 0x4f, 0x12, 0x94, 0x5e, 0x09, 0x4b, 0xc3, 0x52, + 0xf8, 0x61, 0x61, 0xb6, 0x31, 0x9a, 0xb6, 0x59, 0x78, 0x8c, 0x28, 0x8e, + 0x00, 0x00, 0x00, 0x00, 0x61, 0x7c, 0x36, 0x9d, 0xf6, 0x71, 0xa1, 0x8a, + 0x2c, 0x59, 0xa1, 0x5a, 0xd5, 0xd7, 0x21, 0x5e, 0xaa, 0xce, 0x32, 0xd5, + 0x74, 0x2a, 0x00, 0x00, 0xbc, 0xdc, 0x70, 0xc2, 0x00, 0x00, 0x00, 0x00, + 0x67, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x7e, 0x06, 0xe3, + 0x04, 0x00, 0x00, 0x00, 0x2b, 0x66, 0x02, 0x00, 0x02, 0x00, 0x67, 0x17, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x2a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x17, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xc9, 0x13, 0x00, + 0x1c, 0xcd, 0x13, 0x00, 0x48, 0x2b, 0xa1, 0x00, 0xc8, 0x2c, 0xa1, 0x00, + 0xc8, 0x2c, 0xa1, 0x00, 0xc8, 0x3d, 0xa1, 0x00, 0xc8, 0x3d, 0xa1, 0x00, + 0x48, 0x3e, 0xa1, 0x00, 0x38, 0xc9, 0x13, 0x00, 0x00, 0x00, 0x14, 0x00, + 0x6c, 0x3e, 0xa1, 0x00, 0x00, 0x80, 0xa1, 0x00, 0xec, 0xcc, 0x13, 0x00, + 0xd4, 0xaa, 0x13, 0x00, 0xfc, 0xaa, 0x13, 0x00, 0xe4, 0xaa, 0x13, 0x00, + 0xa9, 0x1a, 0xa1, 0xab, 0x55, 0x17, 0x00, 0x00, 0xc3, 0x42, 0xf0, 0x00, + 0x4c, 0x00, 0x00, 0x82, 0x21, 0x68, 0x0c, 0x70, 0xe0, 0x7f, 0x20, 0xa2, + 0x68, 0x44, 0xc3, 0x43, 0xa1, 0x00, 0xac, 0x29, 0x56, 0x7b, 0x40, 0x83, + 0x61, 0x83, 0x0a, 0x25, 0x00, 0x01, 0x65, 0x04, 0xe0, 0x00, 0x81, 0x44, + 0x60, 0x44, 0xc3, 0x43, 0xa1, 0x00, 0xac, 0x29, 0x56, 0x7b, 0x40, 0x83, + 0x4d, 0x03, 0xe0, 0x00, 0x61, 0x83, 0xe0, 0x78, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0x7c, 0x96, + 0xcb, 0x44, 0x00, 0x00, 0x4c, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0xc0, 0x66, + 0xcb, 0x44, 0x00, 0x00, 0x4e, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0x0c, 0x67, + 0xcb, 0x44, 0x00, 0x00, 0x51, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0x54, 0x67, + 0xcb, 0x44, 0x00, 0x00, 0x4d, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0xe0, 0x67, + 0xcb, 0x44, 0x00, 0x00, 0x4f, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0xa4, 0x97, + 0xcb, 0x44, 0x00, 0x00, 0x58, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0x14, 0x68, + 0xcb, 0x44, 0x00, 0x00, 0x57, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0xc4, 0x97, + 0xcb, 0x44, 0x00, 0x00, 0x59, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0x2c, 0x68, + 0xcb, 0x44, 0x00, 0x00, 0x56, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0x4c, 0x68, + 0xcb, 0x44, 0x00, 0x00, 0x52, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0xe0, 0x97, + 0xcb, 0x44, 0x00, 0x00, 0x47, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0xd8, 0x68, + 0xcb, 0x44, 0x00, 0x00, 0x55, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0xec, 0x97, + 0xcb, 0x44, 0x00, 0x00, 0x46, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0xfc, 0x68, + 0xcb, 0x44, 0x00, 0x00, 0x50, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x10, 0x00, 0x20, 0x69, + 0xcb, 0x44, 0x00, 0x00, 0x53, 0x00, 0x3e, 0x79, 0xe4, 0xc2, 0x08, 0x45, + 0x1f, 0x80, 0xb9, 0x15, 0x81, 0x10, 0x41, 0x80, 0xc2, 0x80, 0xc6, 0xb9, + 0xb9, 0x1d, 0x42, 0x10, 0x05, 0xea, 0xb9, 0x12, 0xc0, 0x00, 0x25, 0x08, + 0x12, 0x00, 0x5a, 0x0f, 0x20, 0x00, 0xa1, 0x40, 0x07, 0xee, 0x0f, 0x08, + 0x91, 0x00, 0xb9, 0x16, 0xc0, 0x10, 0x11, 0x08, 0x12, 0x00, 0x2c, 0x74, + 0x4c, 0x70, 0x7a, 0x0e, 0xa0, 0x00, 0xa1, 0x40, 0x0c, 0x70, 0xc4, 0xc6, + 0xe4, 0xc2, 0x08, 0x45, 0xb9, 0x10, 0xc0, 0x00, 0x33, 0x08, 0x12, 0x00, + 0x1f, 0x85, 0x21, 0x80, 0xc2, 0x80, 0x06, 0xe9, 0xb9, 0x11, 0xc0, 0x00, + 0x23, 0x08, 0x12, 0x00, 0x1a, 0x0f, 0x20, 0x00, 0xa1, 0x40, 0x08, 0xee, + 0x0d, 0x08, 0x91, 0x00, 0xb9, 0x16, 0xc0, 0x10, 0x0f, 0x08, 0x12, 0x00, + 0x2c, 0x74, 0x4c, 0x71, 0x3a, 0x0e, 0xa0, 0x00, 0xa1, 0x40, 0xb9, 0x15, + 0x81, 0x10, 0x0c, 0x70, 0x87, 0xb9, 0xb9, 0x1d, 0x42, 0x10, 0xc4, 0xc6, + 0xee, 0xc3, 0xa1, 0xc1, 0x50, 0x41, 0x30, 0x42, 0x2c, 0x70, 0x4c, 0x73, + 0x70, 0x40, 0x08, 0x45, 0xd2, 0x09, 0x20, 0x00, 0x03, 0x1c, 0x03, 0x30, + 0x2c, 0x71, 0x4c, 0x73, 0xc6, 0x09, 0x20, 0x00, 0xa1, 0x40, 0xb8, 0x15, + 0xc0, 0x10, 0x14, 0x77, 0x07, 0xf2, 0x14, 0x71, 0x65, 0xd8, 0x59, 0xf4, + 0x2c, 0x72, 0x4c, 0x71, 0x03, 0xf0, 0x2c, 0x72, 0x4c, 0x72, 0xaa, 0x09, + 0x20, 0x00, 0xa1, 0x40, 0x1f, 0x85, 0x08, 0xd9, 0xf4, 0x10, 0x93, 0x00, + 0x96, 0x0d, 0xa0, 0x00, 0xa1, 0x40, 0x8a, 0x08, 0x2f, 0xef, 0x0a, 0xd8, + 0xa1, 0x40, 0x8e, 0x08, 0x20, 0x00, 0x40, 0x25, 0x0e, 0x17, 0x7a, 0x08, + 0x2f, 0xef, 0x64, 0xd8, 0x40, 0x24, 0xc2, 0x30, 0x1b, 0xd9, 0x6c, 0x71, + 0x72, 0x0a, 0xe0, 0x00, 0xc1, 0x40, 0x03, 0x14, 0x80, 0x30, 0x23, 0xb8, + 0x44, 0x20, 0x40, 0x80, 0x03, 0x1c, 0x02, 0x30, 0xef, 0xf3, 0xdf, 0x85, + 0x2c, 0x70, 0x82, 0x08, 0x20, 0x00, 0xa1, 0x40, 0x56, 0x26, 0x0f, 0x18, + 0x00, 0xaf, 0x2c, 0x71, 0x72, 0x08, 0x20, 0x00, 0xa1, 0x40, 0x80, 0x26, + 0x84, 0x10, 0x00, 0xae, 0x2c, 0x72, 0x66, 0x08, 0x20, 0x00, 0xa1, 0x40, + 0x02, 0xae, 0x22, 0x0d, 0xa0, 0x00, 0x00, 0x8f, 0x00, 0x1a, 0x04, 0x20, + 0x16, 0x0d, 0xa0, 0x00, 0x00, 0x8e, 0x00, 0x19, 0x04, 0x20, 0x0e, 0x0d, + 0xa0, 0x00, 0x02, 0x8e, 0x00, 0x18, 0x04, 0x20, 0x16, 0x0f, 0x20, 0x00, + 0xa1, 0x40, 0xa1, 0x40, 0x0e, 0x0d, 0xa0, 0x00, 0x62, 0x41, 0x02, 0x08, + 0x2f, 0xef, 0x0a, 0xd8, 0x0c, 0x70, 0xce, 0xc7, 0xf1, 0xc0, 0xa1, 0xc1, + 0x1c, 0xe0, 0x40, 0x24, 0xc2, 0x30, 0x7e, 0xd9, 0x6c, 0x71, 0xe2, 0x0a, + 0xe0, 0x00, 0x03, 0x1c, 0xc3, 0x30, 0x87, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, + 0x1f, 0x80, 0xe0, 0x7f, 0xf4, 0x10, 0x80, 0x00, 0xf1, 0xc0, 0xa1, 0xc1, + 0x1c, 0xe0, 0x1f, 0x09, 0xb0, 0x00, 0x03, 0x1c, 0x03, 0x30, 0x1f, 0x09, + 0x70, 0x00, 0x40, 0x24, 0xc2, 0x30, 0x4c, 0x70, 0x8f, 0xe9, 0x40, 0x24, + 0xc2, 0x30, 0x71, 0xd9, 0x06, 0xf0, 0x40, 0x24, 0xc2, 0x30, 0x73, 0xd9, + 0x02, 0xf0, 0x72, 0xd9, 0xae, 0x09, 0xe0, 0x00, 0x6c, 0x71, 0x03, 0x14, + 0x82, 0x30, 0x87, 0x74, 0xd1, 0xc0, 0xe0, 0x7f, 0x40, 0x40, 0xe0, 0x78, + 0x1f, 0x80, 0xe0, 0x7f, 0xfc, 0x10, 0x00, 0x00, 0x1f, 0x80, 0xe0, 0x7f, + 0xec, 0x10, 0x00, 0x00, 0x1f, 0x80, 0xe0, 0x7f, 0xe8, 0x10, 0x00, 0x00, + 0xe4, 0xc2, 0xdf, 0x80, 0x08, 0x45, 0xa9, 0xd8, 0xd8, 0x60, 0x2c, 0x70, + 0x3e, 0x09, 0x2f, 0xf2, 0x14, 0xda, 0x7f, 0xd9, 0x23, 0xda, 0x0c, 0x70, + 0x17, 0xb9, 0xa0, 0xa6, 0xd4, 0x1e, 0x01, 0x14, 0x48, 0xa6, 0xd8, 0x1e, + 0x02, 0x10, 0x29, 0xa6, 0x1c, 0xae, 0xfc, 0x1e, 0x00, 0x10, 0x3e, 0x0a, + 0xa0, 0x00, 0xa1, 0x40, 0xc4, 0xc6, 0xe0, 0x78, 0xe4, 0xc2, 0x7f, 0x81, + 0x4a, 0x24, 0xc0, 0x70, 0x08, 0x44, 0xc3, 0x40, 0xa1, 0x00, 0x2c, 0x2a, + 0x28, 0x45, 0x2c, 0x70, 0x0a, 0x22, 0x00, 0x00, 0xa8, 0x20, 0xc0, 0x01, + 0x08, 0x12, 0x8e, 0x04, 0x0b, 0x0e, 0x05, 0x13, 0x24, 0x71, 0x2c, 0x73, + 0x10, 0xde, 0x36, 0x78, 0x41, 0x80, 0x21, 0x88, 0xa1, 0x40, 0xe8, 0x1b, + 0x80, 0x00, 0x16, 0x0c, 0xa0, 0x00, 0xf4, 0x1b, 0x82, 0x03, 0x0c, 0x70, + 0xca, 0x09, 0xe0, 0x00, 0xa1, 0x41, 0xc1, 0x40, 0xc4, 0xc6, 0xe0, 0x78, + 0xe6, 0xc3, 0xa1, 0xc1, 0x03, 0x1c, 0x03, 0x30, 0xbf, 0x80, 0x48, 0x47, + 0x54, 0x73, 0x8c, 0x00, 0x2d, 0x00, 0x21, 0xda, 0x33, 0x09, 0xb0, 0x00, + 0x40, 0x20, 0x0e, 0x07, 0x47, 0x09, 0x70, 0x00, 0x40, 0x24, 0xc2, 0x30, + 0x22, 0xda, 0xba, 0xe9, 0x40, 0x24, 0xc2, 0x30, 0x69, 0xd9, 0x6c, 0x71, + 0xce, 0x08, 0xe0, 0x00, 0xc1, 0x40, 0x03, 0x14, 0x82, 0x30, 0x14, 0x6f, + 0x44, 0x20, 0x01, 0x0c, 0x46, 0x22, 0x00, 0x0c, 0x1b, 0xf0, 0x40, 0x24, + 0xc2, 0x30, 0x69, 0xd9, 0x6c, 0x71, 0xb2, 0x08, 0xe0, 0x00, 0xc1, 0x40, + 0x03, 0x14, 0x80, 0x30, 0xc1, 0xbf, 0x6c, 0x20, 0x40, 0x00, 0xe5, 0x78, + 0x0e, 0xf0, 0x69, 0xd9, 0x6c, 0x71, 0x9a, 0x08, 0xe0, 0x00, 0xc1, 0x40, + 0x03, 0x14, 0x82, 0x30, 0x12, 0x6f, 0x44, 0x20, 0x01, 0x03, 0x46, 0x22, + 0x00, 0x03, 0x25, 0x78, 0x03, 0x1c, 0x02, 0x30, 0x40, 0x24, 0xc2, 0x30, + 0x69, 0xd9, 0x6c, 0x71, 0x66, 0x09, 0xe0, 0x00, 0xc1, 0x40, 0x03, 0x14, + 0x81, 0x30, 0x4c, 0x70, 0x91, 0x1d, 0x42, 0x10, 0x40, 0x40, 0xc6, 0xc7, + 0xf6, 0xc3, 0xa4, 0xc1, 0x7c, 0x11, 0x12, 0x00, 0x30, 0x43, 0x08, 0x47, + 0xcd, 0x70, 0x55, 0x22, 0x0d, 0x2f, 0x0c, 0x1c, 0x84, 0x33, 0x4f, 0x08, + 0x73, 0x04, 0x42, 0xc6, 0x7d, 0x0f, 0xb5, 0x10, 0x90, 0xe7, 0x56, 0x44, + 0x14, 0x12, 0x0e, 0x20, 0x0c, 0x12, 0x10, 0x20, 0x22, 0x0c, 0x20, 0x00, + 0x10, 0x12, 0x11, 0x20, 0x27, 0xe8, 0x1a, 0x0c, 0x20, 0x00, 0x22, 0x40, + 0x23, 0xe8, 0x12, 0x0c, 0x20, 0x00, 0x02, 0x40, 0x1f, 0xe8, 0x0a, 0x0c, + 0x20, 0x00, 0xc1, 0x40, 0x1b, 0xe8, 0x2c, 0x70, 0x2e, 0x0c, 0x20, 0x00, + 0x62, 0x40, 0x2c, 0x70, 0x4c, 0x70, 0x52, 0x0b, 0xa0, 0x00, 0x62, 0x40, + 0x15, 0xf0, 0xd1, 0x0f, 0x70, 0x14, 0x8c, 0x27, 0x02, 0x90, 0x7a, 0xf2, + 0x8c, 0x27, 0xc3, 0x9f, 0x92, 0xf4, 0xc3, 0x85, 0xff, 0xd9, 0x0a, 0x0c, + 0x20, 0x00, 0x62, 0x40, 0xb8, 0x26, 0x02, 0x10, 0x75, 0xf0, 0x80, 0xd9, + 0xfa, 0x0b, 0x20, 0x00, 0x62, 0x40, 0xb9, 0x13, 0x80, 0x20, 0xcd, 0x70, + 0xc6, 0xb8, 0xb9, 0x1b, 0x02, 0x20, 0x6b, 0xf0, 0x7e, 0xf4, 0x03, 0x85, + 0x60, 0xdf, 0x0f, 0x1c, 0x82, 0x33, 0x8c, 0x20, 0x02, 0x80, 0x04, 0x1c, + 0x84, 0x33, 0x40, 0xc6, 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, 0xff, 0x00, + 0x09, 0xf2, 0x06, 0x85, 0x8c, 0x20, 0x02, 0x80, 0xcc, 0x20, 0x82, 0x8f, + 0x00, 0x00, 0xff, 0x00, 0x84, 0xf4, 0x0e, 0x70, 0x12, 0x41, 0x2f, 0x22, + 0x46, 0x04, 0x2f, 0x23, 0x06, 0x04, 0x2f, 0x24, 0x86, 0x03, 0x62, 0x40, + 0x02, 0x08, 0xe0, 0x00, 0xe1, 0x41, 0x34, 0x13, 0x01, 0x20, 0x23, 0xd8, + 0x20, 0x1a, 0x00, 0x20, 0x60, 0x79, 0x62, 0x40, 0x58, 0x13, 0x02, 0x20, + 0xa4, 0x13, 0x00, 0x21, 0x60, 0x7a, 0x62, 0x41, 0x4e, 0x41, 0x06, 0xe9, + 0xa4, 0x11, 0x00, 0x01, 0x56, 0x81, 0x40, 0x7a, 0x6e, 0x0b, 0x20, 0x00, + 0x62, 0x40, 0x8f, 0x08, 0xb1, 0x00, 0x10, 0xdd, 0x08, 0x12, 0x0e, 0x20, + 0x83, 0x0e, 0x30, 0x10, 0xc1, 0x40, 0x2f, 0x86, 0x40, 0x79, 0x2d, 0x86, + 0x08, 0x47, 0x60, 0x79, 0xc1, 0x40, 0x4e, 0x86, 0xc1, 0x41, 0x60, 0x7a, + 0xe1, 0x40, 0x35, 0xf0, 0xa3, 0x85, 0x8c, 0x25, 0xc3, 0x9f, 0x33, 0xf4, + 0x82, 0xc1, 0x40, 0x24, 0x82, 0x32, 0x83, 0xc3, 0x46, 0x0c, 0xef, 0xff, + 0x62, 0x40, 0x0c, 0x14, 0x44, 0x31, 0x0a, 0x14, 0x43, 0x31, 0x08, 0x14, + 0x42, 0x31, 0x00, 0x41, 0x6e, 0x0f, 0xa0, 0x00, 0x62, 0x40, 0x38, 0xf0, + 0xc3, 0x85, 0x80, 0xd9, 0x1e, 0x0b, 0x20, 0x00, 0x62, 0x40, 0xb8, 0x26, + 0xc3, 0x1f, 0x0c, 0x70, 0x62, 0x41, 0x9e, 0x0f, 0xa0, 0x00, 0xe3, 0xa5, + 0x10, 0xee, 0x7c, 0x13, 0x01, 0x20, 0x00, 0x85, 0xec, 0x11, 0x0e, 0x00, + 0x26, 0x0a, 0x20, 0x00, 0x62, 0x41, 0x04, 0x36, 0x00, 0x90, 0x06, 0xf2, + 0x0c, 0x70, 0xae, 0x0f, 0xa0, 0x00, 0x62, 0x41, 0xa3, 0x85, 0xa1, 0x40, + 0xd6, 0xc7, 0xff, 0xd8, 0x62, 0x41, 0x99, 0xff, 0x82, 0xc1, 0x40, 0x24, + 0x82, 0x32, 0x83, 0xc3, 0xde, 0x0b, 0xef, 0xff, 0x62, 0x40, 0x0c, 0x14, + 0x44, 0x31, 0x0a, 0x14, 0x43, 0x31, 0x08, 0x14, 0x42, 0x31, 0x00, 0x41, + 0x06, 0x0f, 0xa0, 0x00, 0x62, 0x40, 0xa1, 0x40, 0x62, 0x41, 0x8f, 0xff, + 0x11, 0xdd, 0xe7, 0xf1, 0xa6, 0x0a, 0x20, 0x00, 0x62, 0x40, 0x2d, 0x08, + 0x91, 0x00, 0x72, 0x0a, 0x8f, 0xef, 0xe2, 0x08, 0xaf, 0xef, 0x08, 0x45, + 0x00, 0x42, 0x0c, 0x75, 0x5a, 0x0a, 0xaf, 0xef, 0xa1, 0x41, 0x2f, 0x80, + 0x40, 0x79, 0x8c, 0x20, 0x02, 0x80, 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, + 0xff, 0x00, 0x67, 0xf3, 0x7e, 0xd9, 0xb6, 0xda, 0x6c, 0x71, 0x1e, 0x0a, + 0xa0, 0x00, 0x62, 0x40, 0x22, 0x09, 0xa0, 0x00, 0x62, 0x40, 0x7e, 0xd9, + 0x11, 0xda, 0x0a, 0xdb, 0x0a, 0x0a, 0xa0, 0x00, 0x62, 0x40, 0x08, 0xd9, + 0x46, 0x09, 0xa0, 0x00, 0x62, 0x40, 0x3a, 0x0c, 0xef, 0xee, 0x0a, 0xd8, + 0x40, 0xd9, 0x2c, 0xda, 0x6c, 0x70, 0x62, 0x40, 0xee, 0x09, 0xa0, 0x00, + 0x40, 0x23, 0x17, 0x27, 0x22, 0x0c, 0xef, 0xee, 0x0a, 0xd8, 0x5a, 0xd8, + 0xd3, 0x46, 0x48, 0x42, 0x00, 0x00, 0x8c, 0x70, 0xab, 0x20, 0x08, 0x0e, + 0x40, 0x24, 0xc2, 0x33, 0x6d, 0xd9, 0x6c, 0x71, 0x80, 0x45, 0xe2, 0x40, + 0x0a, 0x26, 0x80, 0x05, 0x1e, 0x0f, 0xa0, 0x00, 0x0f, 0x1c, 0x43, 0x32, + 0x80, 0xc2, 0x12, 0xd9, 0x6c, 0x76, 0xfa, 0x0d, 0xa0, 0x00, 0xe2, 0x40, + 0x00, 0x14, 0x94, 0x30, 0x02, 0x14, 0x90, 0x30, 0x03, 0x14, 0x8e, 0x30, + 0x04, 0x14, 0x91, 0x30, 0x05, 0x14, 0x95, 0x30, 0x01, 0x14, 0x8d, 0x30, + 0x8c, 0x70, 0x40, 0x24, 0xc2, 0x33, 0x6d, 0xd9, 0x6c, 0x71, 0x80, 0x45, + 0xe2, 0x40, 0x0a, 0x26, 0x80, 0x05, 0xe2, 0x0e, 0xa0, 0x00, 0x0f, 0x1c, + 0x43, 0x33, 0x80, 0xc2, 0x12, 0xd9, 0x6c, 0x76, 0xba, 0x0d, 0xa0, 0x00, + 0xe2, 0x40, 0x01, 0x14, 0x80, 0x30, 0x05, 0x14, 0x89, 0x30, 0x04, 0x14, + 0x84, 0x30, 0x03, 0x14, 0x86, 0x30, 0x40, 0x2d, 0x01, 0x22, 0x00, 0x14, + 0x85, 0x30, 0x02, 0x14, 0x87, 0x30, 0x08, 0xbd, 0x05, 0x21, 0x41, 0x04, + 0x05, 0x25, 0x02, 0x15, 0x2e, 0x7b, 0x40, 0x28, 0x01, 0x02, 0x40, 0x29, + 0x00, 0x12, 0x08, 0xbe, 0x4e, 0x7c, 0x40, 0x2e, 0x02, 0x02, 0x05, 0x20, + 0x00, 0x01, 0x05, 0x20, 0x90, 0x23, 0x05, 0x21, 0x41, 0x01, 0x05, 0x22, + 0xc2, 0x01, 0x0e, 0x78, 0x2f, 0x23, 0x06, 0x14, 0x2e, 0x79, 0x76, 0x48, + 0x4e, 0x78, 0x02, 0x21, 0x11, 0x03, 0x02, 0x20, 0xd0, 0x02, 0x9a, 0x21, + 0x0f, 0x2a, 0x9a, 0x20, 0x0f, 0x2a, 0xcb, 0x40, 0x00, 0x00, 0x00, 0x10, + 0x04, 0x29, 0x11, 0x22, 0x9a, 0x26, 0x0f, 0x1a, 0x82, 0xc0, 0x8a, 0x22, + 0x0f, 0x0a, 0x04, 0x28, 0x10, 0x22, 0x04, 0x2e, 0x0e, 0x12, 0x00, 0x18, + 0x44, 0x04, 0x2f, 0x20, 0x46, 0x04, 0x11, 0x78, 0x2f, 0x21, 0x06, 0x04, + 0x31, 0x79, 0x8c, 0x21, 0xcf, 0x89, 0x3a, 0x20, 0x8d, 0x00, 0x0c, 0x1c, + 0x84, 0x33, 0x0a, 0x1c, 0x04, 0x34, 0x09, 0xf6, 0x8e, 0x71, 0x8c, 0x20, + 0x0f, 0x8a, 0x81, 0xbd, 0xca, 0x24, 0xab, 0x20, 0x02, 0xf0, 0xb1, 0x44, + 0xce, 0x78, 0x11, 0x78, 0x8c, 0x20, 0xc7, 0x8c, 0x03, 0xf6, 0x86, 0x71, + 0x82, 0xbd, 0x7e, 0xd9, 0xb6, 0xda, 0x6c, 0x73, 0xaa, 0x08, 0xa0, 0x00, + 0x62, 0x40, 0xb2, 0x0f, 0x60, 0x00, 0x62, 0x40, 0x2f, 0x20, 0x07, 0x05, + 0x14, 0x71, 0x0d, 0xf7, 0x17, 0x0d, 0x3f, 0x10, 0x61, 0xdf, 0x11, 0x0d, + 0x7f, 0x10, 0xe2, 0xbd, 0x64, 0xdf, 0xca, 0x27, 0xa1, 0x10, 0x03, 0xf0, + 0x62, 0xdf, 0x2f, 0x05, 0xcf, 0xff, 0xe0, 0x78, 0xe6, 0xc3, 0xa1, 0xc1, + 0xbf, 0x81, 0x4a, 0x24, 0x80, 0x71, 0xcb, 0x47, 0xa1, 0x00, 0x4c, 0x2a, + 0x00, 0x42, 0x3c, 0x49, 0x6c, 0x70, 0xcd, 0x70, 0x0a, 0x21, 0xc0, 0x03, + 0xf0, 0x1d, 0x80, 0x10, 0xa8, 0x20, 0x00, 0x02, 0x08, 0x11, 0x0c, 0x04, + 0x04, 0x34, 0x80, 0x90, 0x43, 0xf6, 0xc5, 0x71, 0xcd, 0x76, 0xfc, 0x15, + 0x01, 0x10, 0x8c, 0x21, 0xc3, 0x8f, 0x09, 0xf2, 0x8c, 0x21, 0x02, 0x80, + 0x23, 0xf4, 0x0b, 0x0e, 0xf4, 0x10, 0x6c, 0x71, 0xcd, 0x73, 0x16, 0x27, + 0x81, 0x13, 0x68, 0x15, 0x82, 0x10, 0x24, 0x89, 0x97, 0x6b, 0x74, 0x70, + 0xc3, 0xb9, 0x84, 0x22, 0x01, 0x0c, 0x24, 0x15, 0x06, 0x10, 0x85, 0x79, + 0xca, 0x22, 0x21, 0x08, 0x45, 0x79, 0x8c, 0x70, 0x03, 0x1c, 0x42, 0x30, + 0x40, 0x24, 0xc2, 0x30, 0x40, 0xd9, 0x6c, 0x71, 0x5e, 0x0d, 0xa0, 0x00, + 0x80, 0x45, 0x03, 0x14, 0x80, 0x30, 0x68, 0x1d, 0x02, 0x10, 0xd6, 0x7f, + 0x00, 0x87, 0xec, 0x1d, 0x00, 0x10, 0xc6, 0xc7, 0xe4, 0xc2, 0x72, 0x0f, + 0xef, 0xff, 0x28, 0x45, 0x08, 0x46, 0x0c, 0x70, 0xfa, 0x0c, 0xa0, 0x00, + 0xa1, 0x41, 0xc1, 0x40, 0xc4, 0xc6, 0xe0, 0x78, 0xf1, 0xc0, 0x00, 0x42, + 0x0d, 0xe8, 0x2f, 0x82, 0x60, 0x79, 0x40, 0x40, 0x00, 0x41, 0x8c, 0x20, + 0x02, 0x80, 0x0c, 0x70, 0xcc, 0x21, 0x82, 0x8f, 0x00, 0x00, 0xff, 0x00, + 0x02, 0xf2, 0x0c, 0x71, 0xd1, 0xc0, 0xe0, 0x7e, 0x1f, 0x80, 0x56, 0x20, + 0x00, 0x0a, 0xe0, 0x7f, 0x00, 0x88, 0xe0, 0x78, 0xe8, 0xc3, 0xa1, 0xc1, + 0xbf, 0x80, 0x30, 0x40, 0xd4, 0x15, 0x02, 0x10, 0xd1, 0x0a, 0x60, 0x00, + 0x03, 0x1c, 0x03, 0x30, 0x8c, 0x20, 0x02, 0xa0, 0x40, 0x20, 0x0e, 0x07, + 0x09, 0xf2, 0x8c, 0x20, 0xc3, 0xaf, 0x0c, 0xf4, 0x24, 0x1d, 0x01, 0x10, + 0x03, 0x1c, 0x43, 0x34, 0x0b, 0xf0, 0x7f, 0xd8, 0x17, 0xb8, 0x03, 0x1c, + 0x83, 0x34, 0x06, 0xf0, 0x7f, 0xd8, 0x17, 0xb8, 0x03, 0x1c, 0x03, 0x34, + 0x09, 0xa5, 0xcb, 0x47, 0xa0, 0x40, 0x00, 0x00, 0x8c, 0x70, 0x40, 0x24, + 0xc2, 0x30, 0x7e, 0xd9, 0x6c, 0x71, 0x80, 0x45, 0xc1, 0x40, 0xaa, 0x0c, + 0xa0, 0x00, 0xe1, 0x46, 0x03, 0x14, 0x80, 0x30, 0x8c, 0x20, 0x02, 0xa0, + 0xa6, 0x1d, 0x02, 0x10, 0x0d, 0xf4, 0xb7, 0xd8, 0x8c, 0x70, 0x03, 0x1c, + 0x02, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x40, 0xd9, 0x6c, 0x71, 0x80, 0x45, + 0xc1, 0x40, 0xe1, 0x46, 0x11, 0xf0, 0x68, 0x15, 0x80, 0x10, 0x8c, 0x70, + 0x40, 0x24, 0xc2, 0x30, 0xc3, 0xb8, 0x85, 0xb8, 0x03, 0x1c, 0x02, 0x30, + 0x40, 0xd9, 0x6c, 0x71, 0x80, 0x45, 0xc3, 0x46, 0x80, 0x3f, 0x00, 0x00, + 0xc1, 0x40, 0x5e, 0x0c, 0x80, 0x00, 0x03, 0x14, 0x80, 0x30, 0x8c, 0x70, + 0x8c, 0x20, 0x02, 0xa0, 0x40, 0x24, 0xc2, 0x30, 0x6c, 0xd9, 0x6c, 0x71, + 0x80, 0x45, 0x03, 0x1c, 0x03, 0x30, 0x68, 0x1d, 0x02, 0x10, 0x06, 0xf4, + 0xc3, 0x46, 0x80, 0x3f, 0x00, 0x00, 0x03, 0xf0, 0x80, 0x46, 0x32, 0x0c, + 0xa0, 0x00, 0xc1, 0x40, 0x03, 0x14, 0x80, 0x30, 0x94, 0x1d, 0x02, 0x10, + 0xd4, 0x1d, 0x00, 0x14, 0xc8, 0xc7, 0xe0, 0x78, 0xe4, 0xc3, 0xa1, 0xc1, + 0xbf, 0x80, 0x40, 0x20, 0x0e, 0x07, 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, + 0x6c, 0x71, 0xc1, 0x40, 0xee, 0x0a, 0xa0, 0x00, 0x03, 0x1c, 0x03, 0x30, + 0x03, 0x14, 0x80, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, 0x86, 0xb8, + 0x03, 0x1c, 0x02, 0x30, 0x6c, 0x71, 0xc6, 0x0b, 0xa0, 0x00, 0xc1, 0x40, + 0xc6, 0x08, 0xef, 0xee, 0x0c, 0x71, 0x03, 0x14, 0x80, 0x30, 0x9f, 0x1d, + 0x02, 0x10, 0xc4, 0xc7, 0xe4, 0xc2, 0x08, 0x45, 0x1f, 0x80, 0xb9, 0x15, + 0x81, 0x10, 0x40, 0x80, 0xc2, 0x80, 0xc6, 0xb9, 0xb9, 0x1d, 0x42, 0x10, + 0x05, 0xea, 0xb9, 0x12, 0xc0, 0x00, 0x25, 0x08, 0x12, 0x00, 0xb2, 0x0e, + 0xef, 0xff, 0xa1, 0x40, 0x07, 0xee, 0x0f, 0x08, 0x91, 0x00, 0xb9, 0x16, + 0xc0, 0x10, 0x11, 0x08, 0x12, 0x00, 0x2c, 0x74, 0x4c, 0x70, 0xd2, 0x0d, + 0x60, 0x00, 0xa1, 0x40, 0x0c, 0x70, 0xc4, 0xc6, 0xe4, 0xc2, 0x08, 0x45, + 0xb9, 0x10, 0xc0, 0x00, 0x33, 0x08, 0x12, 0x00, 0x1f, 0x85, 0x20, 0x80, + 0xc2, 0x80, 0x06, 0xe9, 0xb9, 0x11, 0xc0, 0x00, 0x23, 0x08, 0x12, 0x00, + 0x72, 0x0e, 0xef, 0xff, 0xa1, 0x40, 0x08, 0xee, 0x0d, 0x08, 0x91, 0x00, + 0xb9, 0x16, 0xc0, 0x10, 0x0f, 0x08, 0x12, 0x00, 0x2c, 0x74, 0x4c, 0x71, + 0x92, 0x0d, 0x60, 0x00, 0xa1, 0x40, 0xb9, 0x15, 0x81, 0x10, 0x0c, 0x70, + 0x87, 0xb9, 0xb9, 0x1d, 0x42, 0x10, 0xc4, 0xc6, 0xea, 0xc3, 0xa3, 0xc1, + 0xad, 0x70, 0x08, 0x46, 0x08, 0x1c, 0x44, 0x33, 0x41, 0xc5, 0x03, 0x1c, + 0x42, 0x33, 0xff, 0x86, 0x1c, 0xe0, 0x8a, 0x20, 0x81, 0x26, 0x40, 0x24, + 0xc2, 0x30, 0x2c, 0x73, 0x6c, 0x71, 0x02, 0x1c, 0x42, 0x33, 0xab, 0x20, + 0x08, 0x2e, 0x0e, 0x0a, 0xa0, 0x00, 0x10, 0x41, 0x03, 0x14, 0x80, 0x30, + 0x40, 0x24, 0x42, 0x30, 0x7e, 0xd9, 0x22, 0xb8, 0xc1, 0xb8, 0x03, 0x1c, + 0x02, 0x30, 0x6c, 0x71, 0x22, 0x40, 0xe2, 0x0a, 0xa0, 0x00, 0x01, 0x1c, + 0x43, 0x35, 0xe2, 0x0f, 0xaf, 0xee, 0x32, 0xd8, 0x01, 0x14, 0x80, 0x30, + 0xa6, 0x1f, 0x02, 0x10, 0x0c, 0x75, 0xd2, 0x0f, 0xaf, 0xee, 0xab, 0x20, + 0x08, 0x2e, 0x40, 0x24, 0x82, 0x30, 0x2c, 0x73, 0x6c, 0x71, 0xca, 0x09, + 0xa0, 0x00, 0x22, 0x40, 0x02, 0x14, 0x80, 0x30, 0x22, 0xb8, 0xc1, 0xb8, + 0x15, 0x08, 0x70, 0x00, 0x02, 0x1c, 0x02, 0x30, 0xa5, 0x71, 0xb0, 0x78, + 0xd5, 0x08, 0x94, 0x82, 0x23, 0xd8, 0xca, 0xc7, 0x40, 0x24, 0x82, 0x30, + 0x69, 0xd9, 0x6c, 0x71, 0x9e, 0x09, 0xa0, 0x00, 0x22, 0x40, 0x02, 0x14, + 0x80, 0x30, 0x40, 0x24, 0x42, 0x30, 0x69, 0xd9, 0x86, 0xb8, 0x01, 0x1c, + 0x02, 0x30, 0x6c, 0x71, 0x76, 0x0a, 0xa0, 0x00, 0x22, 0x40, 0x01, 0x14, + 0x80, 0x30, 0x01, 0x1c, 0xc3, 0x30, 0x40, 0x24, 0x42, 0x30, 0x91, 0x1f, + 0x02, 0x10, 0x7e, 0xd9, 0x6c, 0x71, 0x5e, 0x0a, 0xa0, 0x00, 0x22, 0x40, + 0x5e, 0x0f, 0xaf, 0xee, 0x32, 0xd8, 0x01, 0x14, 0x80, 0x30, 0xad, 0x70, + 0xa6, 0x1f, 0x02, 0x10, 0x5a, 0xd8, 0xab, 0x20, 0x08, 0x0e, 0x4a, 0x0f, + 0xaf, 0xee, 0x32, 0xd8, 0x40, 0x24, 0x82, 0x30, 0x1b, 0xd9, 0x6c, 0x71, + 0x42, 0x09, 0xa0, 0x00, 0x22, 0x40, 0x02, 0x14, 0x80, 0x30, 0x23, 0xb8, + 0x44, 0x20, 0x40, 0x80, 0x02, 0x1c, 0x02, 0x30, 0x05, 0xf4, 0xa5, 0x71, + 0xb0, 0x78, 0xd5, 0x08, 0x94, 0x82, 0x2c, 0x70, 0xc6, 0x08, 0x20, 0x00, + 0xc1, 0x40, 0x97, 0x1f, 0x1c, 0x10, 0x2c, 0x71, 0xba, 0x08, 0x20, 0x00, + 0xc1, 0x40, 0x98, 0x1f, 0x1c, 0x10, 0x2c, 0x72, 0xae, 0x08, 0x20, 0x00, + 0xc1, 0x40, 0x99, 0x1f, 0x1c, 0x10, 0x2c, 0x71, 0xaa, 0x0c, 0x20, 0x00, + 0xc1, 0x40, 0x81, 0xc2, 0x0c, 0xd9, 0x6c, 0x76, 0xf2, 0x08, 0xa0, 0x00, + 0x22, 0x40, 0x03, 0x14, 0x80, 0x30, 0x17, 0x08, 0xd0, 0x00, 0x19, 0x08, + 0x70, 0x00, 0x14, 0x70, 0x23, 0xd8, 0x3b, 0xf4, 0x01, 0x1c, 0x03, 0x35, + 0x06, 0xf0, 0x01, 0x1c, 0xc3, 0x35, 0x04, 0xf0, 0x01, 0x1c, 0x43, 0x35, + 0x40, 0x24, 0x42, 0x30, 0x7e, 0xd9, 0x6c, 0x71, 0xb2, 0x09, 0xa0, 0x00, + 0x22, 0x40, 0xb6, 0x0e, 0xaf, 0xee, 0x32, 0xd8, 0x01, 0x14, 0x80, 0x30, + 0x5a, 0xde, 0xad, 0x70, 0xa6, 0x1f, 0x02, 0x10, 0xab, 0x26, 0x08, 0x1e, + 0x0c, 0x75, 0x9e, 0x0e, 0xaf, 0xee, 0xab, 0x26, 0x08, 0x1e, 0x40, 0x24, + 0x82, 0x30, 0x2c, 0x73, 0x6c, 0x71, 0x96, 0x08, 0xa0, 0x00, 0x22, 0x40, + 0x02, 0x14, 0x81, 0x30, 0xa5, 0x71, 0x03, 0x14, 0x82, 0x30, 0xb0, 0x78, + 0x89, 0xe0, 0x41, 0x29, 0x80, 0x00, 0xc1, 0xb8, 0x02, 0x1c, 0x02, 0x30, + 0x03, 0xf7, 0xd1, 0x08, 0x81, 0x80, 0x50, 0x70, 0x65, 0xd8, 0xca, 0x20, + 0xe1, 0x00, 0xca, 0xc7, 0x1f, 0x80, 0xe0, 0x7f, 0x8c, 0x10, 0x00, 0x07, + 0xe4, 0xc3, 0xa1, 0xc1, 0x3f, 0x09, 0xb0, 0x00, 0x40, 0x20, 0x0d, 0x07, + 0x5f, 0x09, 0x70, 0x00, 0x40, 0x24, 0xc2, 0x30, 0x87, 0x09, 0x31, 0x00, + 0x0c, 0x70, 0x40, 0x24, 0xc2, 0x30, 0x74, 0xd9, 0x6c, 0x71, 0x3e, 0x08, + 0xa0, 0x00, 0xa1, 0x40, 0x03, 0x14, 0x8e, 0x30, 0x40, 0x24, 0xc2, 0x30, + 0x77, 0xd9, 0x6c, 0x71, 0x2a, 0x08, 0xa0, 0x00, 0xa1, 0x40, 0x03, 0x14, + 0x80, 0x30, 0x0e, 0xb8, 0x2a, 0xf0, 0x40, 0x24, 0xc2, 0x30, 0x76, 0xd9, + 0x6c, 0x71, 0x16, 0x08, 0xa0, 0x00, 0xa1, 0x40, 0x03, 0x14, 0x8e, 0x30, + 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, 0x6c, 0x71, 0x02, 0x08, 0xa0, 0x00, + 0xa1, 0x40, 0x03, 0x14, 0x80, 0x30, 0x0a, 0xb8, 0x12, 0xf0, 0x75, 0xd9, + 0x6c, 0x71, 0xf2, 0x0f, 0x60, 0x00, 0xa1, 0x40, 0x03, 0x14, 0x8e, 0x30, + 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, 0x6c, 0x71, 0xde, 0x0f, 0x60, 0x00, + 0xa1, 0x40, 0x03, 0x14, 0x80, 0x30, 0x0c, 0xb8, 0x04, 0x20, 0x80, 0x0f, + 0x00, 0x00, 0x00, 0xc0, 0x0e, 0x78, 0x46, 0xb8, 0xc5, 0x78, 0xc4, 0xc7, + 0x1f, 0x80, 0xe0, 0x7f, 0x42, 0x10, 0x00, 0x06, 0xea, 0xc2, 0x30, 0x41, + 0xb9, 0x11, 0xc1, 0x00, 0x09, 0x09, 0x32, 0x00, 0x08, 0x40, 0xca, 0xc6, + 0x7c, 0x11, 0x10, 0x20, 0xcb, 0x46, 0x13, 0x00, 0xf8, 0x6a, 0xc3, 0x40, + 0x00, 0x00, 0xff, 0x7f, 0x55, 0x20, 0x0d, 0x2c, 0xf4, 0x15, 0xcc, 0x90, + 0xb2, 0x10, 0xc3, 0x20, 0xb3, 0x10, 0x82, 0x20, 0xb1, 0x10, 0x8b, 0x20, + 0xb6, 0x10, 0xcf, 0x20, 0x08, 0xbc, 0x08, 0xbb, 0xb5, 0x10, 0x81, 0x20, + 0x85, 0x7a, 0x05, 0x23, 0xc3, 0x02, 0x48, 0x32, 0x8b, 0x00, 0x48, 0x33, + 0x8c, 0x00, 0x41, 0x86, 0x60, 0x86, 0x08, 0xbf, 0xe5, 0x79, 0x48, 0x31, + 0x89, 0x00, 0x00, 0x32, 0xcb, 0x02, 0x22, 0x86, 0x00, 0x33, 0x02, 0x03, + 0x00, 0x43, 0x48, 0x32, 0xc2, 0x02, 0x00, 0x31, 0x4c, 0x02, 0x48, 0x33, + 0xc1, 0x12, 0x13, 0x08, 0xa2, 0x00, 0x4c, 0x1d, 0x00, 0x12, 0x08, 0x22, + 0x83, 0x0f, 0xff, 0xff, 0x00, 0x80, 0x48, 0x34, 0xc2, 0x12, 0x77, 0xa5, + 0x0f, 0x08, 0x62, 0x00, 0x00, 0x43, 0x08, 0x21, 0x83, 0x0f, 0xff, 0xff, + 0x00, 0x80, 0x11, 0x08, 0xa2, 0x00, 0x78, 0xa5, 0x08, 0x22, 0x80, 0x0f, + 0xff, 0xff, 0x00, 0x80, 0xc3, 0x41, 0xa1, 0x00, 0x52, 0x29, 0x20, 0x89, + 0x93, 0x09, 0x30, 0x00, 0x19, 0xa5, 0x7d, 0x85, 0x88, 0x11, 0x00, 0x20, + 0x8c, 0x11, 0x01, 0x20, 0x5e, 0x85, 0x1d, 0xa5, 0x02, 0x20, 0xc0, 0x80, + 0x3e, 0xa5, 0x32, 0x0f, 0xaf, 0xe3, 0x03, 0x21, 0x81, 0x80, 0x08, 0x47, + 0xb6, 0x0d, 0x60, 0x00, 0x22, 0x40, 0x23, 0x86, 0x00, 0x30, 0x40, 0x00, + 0x07, 0x36, 0x01, 0x70, 0x7a, 0x47, 0x00, 0x00, 0x02, 0x31, 0xc0, 0x03, + 0x07, 0x30, 0x40, 0x00, 0x50, 0x20, 0xc1, 0x07, 0x04, 0x31, 0x80, 0x8f, + 0x4c, 0x3e, 0xcd, 0xcc, 0x46, 0x00, 0x06, 0x00, 0xc3, 0x42, 0x8f, 0x3d, + 0x29, 0x5c, 0x04, 0x30, 0x80, 0x80, 0x0a, 0xf6, 0xc3, 0x41, 0x8f, 0xbd, + 0x29, 0x5c, 0x04, 0x30, 0x40, 0x80, 0x00, 0x42, 0xca, 0x22, 0x45, 0x00, + 0x3f, 0x85, 0xc3, 0x40, 0xc8, 0x42, 0x00, 0x00, 0x00, 0x32, 0x03, 0x00, + 0xb7, 0xb8, 0x01, 0x32, 0x41, 0x00, 0x00, 0x31, 0x00, 0x00, 0x3f, 0xa5, + 0x01, 0x33, 0x00, 0x00, 0x48, 0x30, 0xc0, 0x02, 0x6a, 0x0e, 0x60, 0x00, + 0x0d, 0x78, 0x43, 0x10, 0x01, 0x26, 0x60, 0x79, 0x22, 0x40, 0xca, 0xc6, + 0x1f, 0x80, 0xe0, 0x7f, 0x45, 0x10, 0x00, 0x06, 0x1f, 0x80, 0xe0, 0x7f, + 0x44, 0x10, 0x00, 0x06, 0xe4, 0xc0, 0x39, 0x08, 0xf0, 0x00, 0x7f, 0x83, + 0x37, 0x08, 0xb0, 0x00, 0x14, 0x71, 0x24, 0xd8, 0x13, 0xf4, 0x97, 0x13, + 0x0d, 0x07, 0x99, 0x13, 0x0e, 0x07, 0x98, 0x13, 0x0c, 0x07, 0x0c, 0x70, + 0xc4, 0xa9, 0x82, 0xa9, 0xa0, 0xa9, 0x28, 0xbe, 0x28, 0xbc, 0x28, 0xbd, + 0xc5, 0xa9, 0x83, 0xa9, 0xa1, 0xa9, 0x00, 0x1a, 0x85, 0x01, 0xc4, 0xc4, + 0xbd, 0x13, 0x83, 0x00, 0x04, 0xf0, 0x80, 0x23, 0x04, 0x0b, 0x60, 0x8b, + 0x0c, 0x70, 0xc0, 0xbb, 0x60, 0xa9, 0x00, 0x1a, 0x45, 0x00, 0xc4, 0xc4, + 0xe2, 0xc2, 0x08, 0x45, 0x1f, 0x80, 0x2c, 0x70, 0x4e, 0x18, 0x58, 0x00, + 0x4d, 0x18, 0x58, 0x00, 0x4f, 0x18, 0x58, 0x00, 0x42, 0x18, 0x58, 0x00, + 0xca, 0x0d, 0x60, 0x00, 0xa1, 0xa0, 0xde, 0x0e, 0x20, 0x00, 0xa1, 0x40, + 0xc2, 0xc6, 0xe0, 0x78, 0xe6, 0xc3, 0xa1, 0xc1, 0xbf, 0x81, 0x4a, 0x24, + 0x00, 0x71, 0xc3, 0x43, 0xa1, 0x00, 0x04, 0x2b, 0x28, 0x46, 0x2c, 0x70, + 0x0a, 0x22, 0xc0, 0x00, 0xa8, 0x20, 0xc0, 0x01, 0x08, 0x12, 0x0f, 0x05, + 0x0d, 0x0f, 0x05, 0x10, 0x24, 0x71, 0x2c, 0x74, 0x8a, 0x27, 0x1f, 0x14, + 0x6b, 0x15, 0x8c, 0x10, 0x24, 0x15, 0x06, 0x10, 0x8c, 0x1d, 0xdc, 0x13, + 0x36, 0x7b, 0x02, 0x8b, 0x41, 0x83, 0x6c, 0x24, 0x81, 0x10, 0xc2, 0xb8, + 0x25, 0x78, 0x8c, 0x70, 0x44, 0x1d, 0x98, 0x10, 0x03, 0x1c, 0x02, 0x30, + 0x3c, 0x4e, 0x40, 0x24, 0xc2, 0x30, 0x43, 0xd9, 0x6c, 0x71, 0xaa, 0x0e, + 0x60, 0x00, 0x80, 0x45, 0x03, 0x14, 0x80, 0x30, 0xc1, 0x41, 0x6b, 0x1d, + 0x02, 0x10, 0x42, 0x0e, 0x60, 0x00, 0x0c, 0x70, 0xe1, 0x40, 0xc6, 0xc7, + 0xe6, 0xc3, 0xa1, 0xc1, 0xdf, 0x80, 0x48, 0x47, 0x61, 0x09, 0xb0, 0x00, + 0x40, 0x20, 0x0d, 0x07, 0xa5, 0x09, 0x70, 0x00, 0x40, 0x24, 0xc2, 0x30, + 0x34, 0x70, 0x82, 0xf4, 0x40, 0x24, 0xc2, 0x30, 0x74, 0xd9, 0x6c, 0x71, + 0x52, 0x0d, 0x60, 0x00, 0xa1, 0x40, 0x40, 0x24, 0x82, 0x30, 0x74, 0xd9, + 0x6c, 0x71, 0xa1, 0x40, 0x32, 0x0e, 0x60, 0x00, 0x02, 0x1c, 0xc2, 0x33, + 0x32, 0x0b, 0xaf, 0xee, 0x0c, 0x71, 0x02, 0x14, 0x80, 0x30, 0x40, 0x24, + 0xc2, 0x30, 0x77, 0xd9, 0x9c, 0x1e, 0x02, 0x10, 0x6c, 0x71, 0x26, 0x0d, + 0x60, 0x00, 0xa1, 0x40, 0x03, 0x14, 0x80, 0x30, 0x28, 0xbf, 0xc1, 0xbf, + 0x6c, 0x20, 0x40, 0x00, 0xe5, 0x78, 0x4c, 0xf0, 0x40, 0x24, 0xc2, 0x30, + 0x76, 0xd9, 0x6c, 0x71, 0x06, 0x0d, 0x60, 0x00, 0xa1, 0x40, 0x40, 0x24, + 0x82, 0x30, 0x76, 0xd9, 0x6c, 0x71, 0xa1, 0x40, 0xe6, 0x0d, 0x60, 0x00, + 0x02, 0x1c, 0xc2, 0x33, 0xe6, 0x0a, 0xaf, 0xee, 0x0c, 0x71, 0x02, 0x14, + 0x80, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, 0x9e, 0x1e, 0x02, 0x10, + 0x6c, 0x71, 0xda, 0x0c, 0x60, 0x00, 0xa1, 0x40, 0x03, 0x14, 0x80, 0x30, + 0x24, 0xbf, 0x44, 0x27, 0x01, 0x1c, 0x46, 0x20, 0x00, 0x0c, 0x25, 0xf0, + 0x75, 0xd9, 0x6c, 0x71, 0xbe, 0x0c, 0x60, 0x00, 0xa1, 0x40, 0x40, 0x24, + 0x82, 0x30, 0x75, 0xd9, 0x6c, 0x71, 0xa1, 0x40, 0x9e, 0x0d, 0x60, 0x00, + 0x02, 0x1c, 0xc2, 0x33, 0x9e, 0x0a, 0xaf, 0xee, 0x0c, 0x71, 0x02, 0x14, + 0x80, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, 0x9d, 0x1e, 0x02, 0x10, + 0x6c, 0x71, 0x92, 0x0c, 0x60, 0x00, 0xa1, 0x40, 0x03, 0x14, 0x80, 0x30, + 0x26, 0xbf, 0x44, 0x27, 0x01, 0x13, 0x46, 0x20, 0x00, 0x03, 0x25, 0x78, + 0x02, 0x1c, 0x02, 0x30, 0x40, 0x24, 0x82, 0x30, 0x77, 0xd9, 0x6c, 0x71, + 0x5e, 0x0d, 0x60, 0x00, 0xa1, 0x40, 0x62, 0x0a, 0xaf, 0xee, 0x0c, 0x71, + 0x02, 0x14, 0x80, 0x30, 0x9f, 0x1e, 0x02, 0x10, 0xc6, 0xc7, 0xe0, 0x78, + 0xe6, 0xc3, 0xa1, 0xc1, 0xbf, 0x80, 0x40, 0x20, 0x0e, 0x07, 0x28, 0x47, + 0x40, 0x24, 0xc2, 0x30, 0x77, 0xd9, 0x6c, 0x71, 0xc1, 0x40, 0x42, 0x0c, + 0x60, 0x00, 0x03, 0x1c, 0x03, 0x30, 0x03, 0x14, 0x80, 0x30, 0x37, 0x6f, + 0x40, 0x24, 0x82, 0x30, 0xc6, 0xb8, 0x25, 0x78, 0x02, 0x1c, 0x02, 0x30, + 0x77, 0xd9, 0x6c, 0x71, 0x12, 0x0d, 0x60, 0x00, 0xc1, 0x40, 0x09, 0x85, + 0x12, 0x0a, 0xaf, 0xee, 0x48, 0x30, 0xc0, 0x02, 0x02, 0x14, 0x80, 0x30, + 0x9f, 0x1d, 0x02, 0x10, 0xc6, 0xc7, 0xe0, 0x78, 0xe2, 0xc3, 0xa1, 0xc1, + 0xbf, 0x80, 0x8a, 0x23, 0x44, 0x0b, 0x79, 0x21, 0x0c, 0x00, 0x34, 0x70, + 0x93, 0x15, 0x82, 0x10, 0x79, 0x65, 0x80, 0xa9, 0x46, 0x22, 0x01, 0x0c, + 0x24, 0x15, 0x06, 0x10, 0xcf, 0x21, 0x22, 0x01, 0x8c, 0x70, 0x03, 0x1c, + 0x42, 0x30, 0x1c, 0xe0, 0x40, 0x24, 0xc2, 0x30, 0x6b, 0xd9, 0x6c, 0x71, + 0xea, 0x0c, 0x60, 0x00, 0x80, 0x45, 0x03, 0x14, 0x80, 0x30, 0x93, 0x1d, + 0x02, 0x10, 0xc2, 0xc7, 0xe2, 0xc3, 0xa1, 0xc1, 0x03, 0x1c, 0x03, 0x30, + 0xbf, 0x80, 0x15, 0x09, 0xb5, 0x00, 0x1c, 0xe0, 0xbd, 0x15, 0x81, 0x10, + 0x07, 0xe9, 0x03, 0x1c, 0xc3, 0x35, 0x07, 0xf0, 0x03, 0x1c, 0x43, 0x35, + 0x03, 0xf0, 0x03, 0x1c, 0x03, 0x35, 0x8c, 0x70, 0x40, 0x24, 0xc2, 0x30, + 0x7e, 0xd9, 0x6c, 0x71, 0xc3, 0x46, 0x80, 0x3f, 0x00, 0x00, 0xa6, 0x0c, + 0x60, 0x00, 0x80, 0x45, 0x7e, 0x09, 0xaf, 0xee, 0x50, 0xd8, 0x03, 0x14, + 0x80, 0x30, 0xa6, 0x1d, 0x02, 0x10, 0xc2, 0xc7, 0xee, 0xc3, 0xa1, 0xc1, + 0xff, 0x81, 0x28, 0x45, 0x2b, 0x08, 0x73, 0x04, 0x08, 0x46, 0x5f, 0x0e, + 0xb5, 0x10, 0x8a, 0x20, 0x44, 0x0b, 0x08, 0x67, 0x85, 0xe8, 0xa1, 0x40, + 0x9a, 0x0f, 0xef, 0xff, 0xc1, 0x41, 0xb9, 0x15, 0x80, 0x10, 0xc6, 0xb8, + 0xb9, 0x1d, 0x02, 0x10, 0x42, 0x1f, 0x98, 0x13, 0x15, 0xf0, 0x91, 0xe6, + 0xad, 0xf2, 0x8c, 0x26, 0x02, 0x90, 0xcc, 0x26, 0x82, 0x9f, 0x00, 0x00, + 0xff, 0x00, 0x11, 0xf4, 0x8a, 0x20, 0x44, 0x0b, 0x08, 0x67, 0x86, 0xe8, + 0xff, 0xd9, 0x6a, 0x0f, 0xef, 0xff, 0xa1, 0x40, 0xff, 0xd8, 0x42, 0x1f, + 0x18, 0x10, 0x0c, 0x70, 0xc2, 0x0b, 0x60, 0x00, 0xa1, 0x41, 0x42, 0x17, + 0x0e, 0x16, 0xc1, 0x40, 0xce, 0xc7, 0xfb, 0x0e, 0x31, 0x94, 0xe9, 0x46, + 0x42, 0x17, 0x12, 0x16, 0x8c, 0x22, 0xc3, 0xaf, 0x06, 0xf2, 0xff, 0xd9, + 0x3a, 0x0f, 0xef, 0xff, 0xa1, 0x40, 0xdf, 0x85, 0xfc, 0x16, 0x00, 0x10, + 0x8a, 0x21, 0x01, 0x28, 0x02, 0x1c, 0x03, 0x30, 0x8c, 0x20, 0x02, 0x80, + 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, 0xff, 0x00, 0xa2, 0xf2, 0x42, 0x16, + 0x00, 0x16, 0x8c, 0x20, 0x02, 0x80, 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, + 0xff, 0x00, 0x9a, 0xf2, 0xd6, 0x0e, 0xaf, 0xff, 0xa1, 0x40, 0x1b, 0x08, + 0x91, 0x00, 0x02, 0x86, 0x2f, 0x80, 0x40, 0x79, 0x8c, 0x20, 0x02, 0x80, + 0xcc, 0x20, 0x82, 0x8f, 0x00, 0x00, 0xff, 0x00, 0x8a, 0xf2, 0x8a, 0x20, + 0x81, 0x26, 0x7e, 0xd9, 0x15, 0xda, 0x32, 0xdb, 0xa1, 0x40, 0xab, 0x20, + 0x08, 0x2e, 0x56, 0x0e, 0x20, 0x00, 0x40, 0x25, 0x13, 0x17, 0xcd, 0x70, + 0x0c, 0x75, 0x86, 0x08, 0xaf, 0xee, 0xab, 0x20, 0x08, 0x2e, 0x40, 0x24, + 0x82, 0x30, 0x2c, 0x73, 0x6c, 0x71, 0x7e, 0x0a, 0x60, 0x00, 0x62, 0x40, + 0x02, 0x14, 0x80, 0x30, 0x44, 0x20, 0x00, 0x03, 0x0f, 0x08, 0x10, 0x01, + 0xc5, 0x71, 0xcf, 0x78, 0xd9, 0x08, 0x54, 0x81, 0xcd, 0x75, 0x7c, 0x15, + 0x10, 0x10, 0x40, 0x24, 0x42, 0x30, 0x6d, 0xd9, 0x6c, 0x71, 0x62, 0x40, + 0x52, 0x0a, 0x60, 0x00, 0x01, 0x1c, 0x03, 0x30, 0x01, 0x14, 0x80, 0x30, + 0x8c, 0x70, 0x40, 0x24, 0x42, 0x30, 0x84, 0xb8, 0x01, 0x1c, 0x02, 0x30, + 0x6d, 0xd9, 0x6c, 0x71, 0x80, 0x45, 0x3a, 0x0b, 0x60, 0x00, 0x62, 0x40, + 0x01, 0x14, 0x80, 0x30, 0x95, 0x18, 0x02, 0x20, 0x1e, 0x08, 0xaf, 0xee, + 0x32, 0xd8, 0x5a, 0xd8, 0xab, 0x20, 0x08, 0x0e, 0x12, 0x08, 0xaf, 0xee, + 0x0c, 0x75, 0x40, 0x24, 0xc2, 0x30, 0x1b, 0xd9, 0x6c, 0x71, 0x62, 0x40, + 0x0a, 0x0a, 0x60, 0x00, 0x03, 0x1c, 0x03, 0x30, 0x03, 0x14, 0x80, 0x30, + 0x1d, 0x78, 0x44, 0x20, 0x40, 0x80, 0x02, 0x1c, 0x02, 0x30, 0x2f, 0xf4, + 0xc5, 0x71, 0xcf, 0x78, 0xcf, 0x08, 0x54, 0x81, 0x2a, 0xf0, 0x42, 0x17, + 0x10, 0x16, 0x11, 0xde, 0x8c, 0x20, 0xc3, 0xaf, 0x0f, 0xf4, 0xaa, 0x0f, + 0xaf, 0xff, 0xa1, 0x40, 0x99, 0x17, 0x44, 0x17, 0x98, 0x17, 0x43, 0x17, + 0x97, 0x17, 0x42, 0x17, 0x00, 0x41, 0x2a, 0x0a, 0x60, 0x00, 0xa1, 0x40, + 0x59, 0xf1, 0xff, 0xd9, 0xfe, 0x0d, 0xef, 0xff, 0xa1, 0x40, 0x86, 0x0f, + 0xaf, 0xff, 0xa1, 0x40, 0x99, 0x17, 0x44, 0x17, 0x98, 0x17, 0x43, 0x17, + 0x97, 0x17, 0x42, 0x17, 0x00, 0x41, 0x06, 0x0a, 0x60, 0x00, 0xa1, 0x40, + 0xa1, 0x40, 0x02, 0x41, 0x31, 0xf0, 0x2e, 0x72, 0x4c, 0x70, 0x6c, 0x70, + 0x40, 0x44, 0x22, 0x41, 0x06, 0x0a, 0x60, 0x00, 0xa1, 0x40, 0x2d, 0x85, + 0x23, 0xd8, 0x08, 0xa7, 0x60, 0x79, 0xa1, 0x40, 0x56, 0x85, 0xa4, 0x15, + 0x00, 0x11, 0x60, 0x7a, 0xa1, 0x41, 0x20, 0x87, 0x05, 0xe9, 0xa4, 0x11, + 0x00, 0x01, 0x56, 0x81, 0x40, 0x7a, 0x7a, 0x0d, 0xaf, 0xff, 0xa1, 0x40, + 0x1f, 0x08, 0x91, 0x00, 0xc2, 0x87, 0x0d, 0xee, 0x2f, 0x86, 0x60, 0x79, + 0xc1, 0x40, 0x2d, 0x86, 0x08, 0x47, 0x60, 0x79, 0xc1, 0x40, 0x4e, 0x86, + 0xc1, 0x41, 0x60, 0x7a, 0xe1, 0x40, 0x8c, 0x22, 0xc3, 0xaf, 0x10, 0xde, + 0x17, 0xf3, 0xa1, 0x40, 0x42, 0x41, 0x7a, 0x0d, 0xcf, 0xff, 0x13, 0xf1, + 0xe2, 0xc3, 0xa1, 0xc1, 0xbf, 0x81, 0x4a, 0x24, 0x40, 0x71, 0xcb, 0x44, + 0xa1, 0x00, 0x2c, 0x2b, 0x20, 0x45, 0x40, 0x21, 0x0b, 0x07, 0x2c, 0x70, + 0x0a, 0x22, 0x00, 0x03, 0xa8, 0x20, 0x80, 0x02, 0x04, 0x12, 0x03, 0x05, + 0x48, 0x33, 0x03, 0x00, 0x04, 0x33, 0x00, 0x80, 0x46, 0xf6, 0x24, 0x71, + 0x2c, 0x75, 0xc3, 0x43, 0x48, 0x44, 0x00, 0x00, 0x35, 0x7c, 0x6a, 0x15, + 0x82, 0x10, 0x22, 0x8c, 0x45, 0x1d, 0xd8, 0x10, 0x6c, 0x22, 0xc2, 0x00, + 0xc3, 0xb9, 0x45, 0x79, 0x03, 0x1c, 0x42, 0x30, 0x40, 0x24, 0xc2, 0x30, + 0x42, 0xd9, 0x6c, 0x71, 0xc3, 0x44, 0x13, 0x00, 0xb4, 0xc8, 0xc3, 0x46, + 0x80, 0x3f, 0x00, 0x00, 0xe6, 0x09, 0x60, 0x00, 0x61, 0x40, 0x03, 0x14, + 0x81, 0x30, 0x45, 0x15, 0x00, 0x16, 0x6a, 0x1d, 0x42, 0x10, 0xc2, 0xc7, + 0xe6, 0xc2, 0xbf, 0x83, 0x65, 0x08, 0xf0, 0x00, 0x68, 0x46, 0x7b, 0x08, + 0xb0, 0x00, 0xed, 0x70, 0xb9, 0x08, 0x71, 0x00, 0x24, 0xdf, 0x01, 0x89, + 0x40, 0x89, 0x08, 0xb8, 0x05, 0x7a, 0x97, 0x1d, 0x9c, 0x10, 0x03, 0x89, + 0x62, 0x89, 0x4e, 0x7a, 0x08, 0xb8, 0x65, 0x78, 0x98, 0x1d, 0x1c, 0x10, + 0x05, 0x89, 0x24, 0x89, 0x08, 0xb8, 0x25, 0x78, 0x99, 0x1d, 0x1c, 0x10, + 0x2c, 0x70, 0x0a, 0x0b, 0xef, 0xff, 0xc1, 0x40, 0x98, 0x15, 0x42, 0x17, + 0x2c, 0x71, 0xfe, 0x0a, 0xef, 0xff, 0xc1, 0x40, 0x99, 0x15, 0x42, 0x17, + 0x2c, 0x72, 0xf2, 0x0a, 0xef, 0xff, 0xc1, 0x40, 0x2c, 0x71, 0x0a, 0x0c, + 0xef, 0xff, 0xc1, 0x40, 0xed, 0x70, 0x32, 0xf0, 0x20, 0x89, 0x42, 0x15, + 0x00, 0x16, 0xed, 0x70, 0xc0, 0xb9, 0x59, 0x08, 0xb5, 0x00, 0xbd, 0x1d, + 0x42, 0x10, 0xce, 0x0c, 0xef, 0xff, 0xc1, 0x41, 0x24, 0xf0, 0x8a, 0x20, + 0x04, 0x0b, 0x40, 0x89, 0xb8, 0x60, 0x21, 0x88, 0x44, 0x22, 0x42, 0x80, + 0x40, 0xa8, 0x0e, 0xf4, 0x35, 0x09, 0x71, 0x00, 0x2c, 0x70, 0x1e, 0x0c, + 0xef, 0xff, 0xc1, 0x40, 0x42, 0x15, 0x00, 0x16, 0x25, 0x08, 0xb5, 0x00, + 0x0c, 0x71, 0xe9, 0xf1, 0x8e, 0xe9, 0x42, 0x15, 0x00, 0x16, 0x8c, 0x20, + 0xc3, 0x8f, 0x06, 0xf2, 0xff, 0xd9, 0x42, 0x0c, 0xef, 0xff, 0xc1, 0x40, + 0x2c, 0x71, 0xf6, 0x0b, 0xef, 0xff, 0xc1, 0x40, 0xe1, 0x40, 0xc6, 0xc6, + 0x5f, 0x81, 0x20, 0x45, 0x6c, 0x75, 0xf8, 0x1a, 0x00, 0x00, 0x80, 0x22, + 0x83, 0x03, 0x3c, 0x49, 0xc3, 0x44, 0x13, 0x00, 0x0c, 0xc0, 0xf1, 0x07, + 0x20, 0x00, 0x1b, 0xd9, 0x14, 0x70, 0x20, 0x45, 0xe0, 0x7d, 0x7c, 0x15, + 0x02, 0x00, 0x40, 0x25, 0x00, 0x07, 0x2c, 0x74, 0x80, 0x22, 0x42, 0x0a, + 0xc3, 0x44, 0x13, 0x00, 0x2c, 0xc0, 0xd1, 0x07, 0x20, 0x00, 0x14, 0xdb, + 0xe8, 0xc2, 0x28, 0x47, 0x02, 0xe8, 0xc8, 0xc6, 0xbf, 0x87, 0xb9, 0x17, + 0xc0, 0x10, 0x08, 0x15, 0x10, 0x10, 0x49, 0x08, 0x33, 0x00, 0xc1, 0x85, + 0xce, 0x15, 0xc0, 0x10, 0x3d, 0x08, 0x33, 0x00, 0x55, 0x25, 0x80, 0x1b, + 0xba, 0x15, 0xc1, 0x10, 0xb9, 0x15, 0x8c, 0x10, 0x04, 0x10, 0xc2, 0x00, + 0x08, 0xb9, 0x00, 0x10, 0xc3, 0x00, 0xbb, 0x15, 0x8b, 0x10, 0xb7, 0x15, + 0x88, 0x10, 0x85, 0x79, 0x2a, 0xa0, 0x08, 0xba, 0x08, 0xbb, 0x30, 0x80, + 0x05, 0x22, 0xc2, 0x02, 0x05, 0x23, 0x03, 0x02, 0x4b, 0xa0, 0x69, 0xa0, + 0x60, 0x79, 0xe1, 0x40, 0x55, 0x27, 0x8f, 0x18, 0x0e, 0xee, 0xb9, 0x16, + 0xc0, 0x10, 0x19, 0x08, 0x13, 0x00, 0xce, 0x15, 0x80, 0x10, 0x11, 0x08, + 0xbe, 0x01, 0xc1, 0x42, 0x21, 0x87, 0xd2, 0x0f, 0x20, 0x00, 0x00, 0x87, + 0x8f, 0x08, 0x10, 0xa0, 0xb9, 0x10, 0xc0, 0x20, 0x87, 0x08, 0x13, 0x80, + 0xce, 0x15, 0x80, 0x10, 0x7f, 0x08, 0x7e, 0x81, 0x02, 0x42, 0x21, 0x87, + 0xb2, 0x0f, 0x20, 0x00, 0x00, 0x87, 0xc8, 0xc6, 0xec, 0xc3, 0xa8, 0xc1, + 0x3f, 0x80, 0x08, 0x47, 0x30, 0x40, 0xd8, 0x11, 0x80, 0x00, 0x1f, 0x1c, + 0x03, 0x30, 0x8a, 0xe8, 0xd8, 0x18, 0x43, 0x20, 0xc3, 0x41, 0xf0, 0x00, + 0xfc, 0x02, 0x00, 0x89, 0xa1, 0xb8, 0x00, 0xa9, 0x1c, 0x10, 0x80, 0x20, + 0x40, 0x27, 0x12, 0x17, 0x85, 0x08, 0x31, 0x00, 0x03, 0x1c, 0x03, 0x30, + 0x1c, 0x18, 0x43, 0x20, 0x08, 0x87, 0x79, 0x08, 0x51, 0x04, 0xcb, 0x45, + 0xf0, 0x00, 0x77, 0x02, 0x00, 0x8d, 0xc1, 0xb8, 0x69, 0x08, 0xb1, 0x00, + 0x18, 0xda, 0x00, 0x8d, 0x42, 0x41, 0x6c, 0x20, 0x40, 0x00, 0x00, 0xad, + 0x46, 0x08, 0xaf, 0xe3, 0x81, 0xc0, 0x21, 0xd8, 0x8c, 0x70, 0x16, 0x1c, + 0x43, 0x36, 0x04, 0x1c, 0x80, 0x3f, 0xa0, 0x00, 0xec, 0x40, 0x42, 0xc0, + 0x81, 0xc0, 0x7f, 0xd9, 0xc3, 0x42, 0xa1, 0x00, 0x51, 0x29, 0x6c, 0x71, + 0xc3, 0x46, 0x80, 0x3f, 0x00, 0x00, 0xca, 0x0e, 0x20, 0x00, 0x80, 0x45, + 0xb6, 0xde, 0x81, 0xc0, 0x40, 0x24, 0xc2, 0x30, 0x7e, 0xd9, 0x6c, 0x71, + 0x76, 0x0f, 0x20, 0x00, 0x03, 0x1c, 0x82, 0x33, 0x76, 0x0c, 0x6f, 0xee, + 0x32, 0xd8, 0xa6, 0x18, 0x82, 0x23, 0x00, 0x8d, 0x6c, 0x20, 0x40, 0x00, + 0x81, 0xb8, 0x00, 0xad, 0x32, 0x09, 0x20, 0x00, 0xe1, 0x40, 0x40, 0x24, + 0xc2, 0x37, 0x2c, 0x70, 0x6c, 0x71, 0x5e, 0x0e, 0x20, 0x00, 0x42, 0x40, + 0x14, 0x70, 0x4a, 0x20, 0x80, 0x28, 0x8a, 0xf4, 0x1f, 0x14, 0x80, 0x30, + 0x4a, 0x20, 0x40, 0x28, 0x6c, 0x20, 0xc0, 0x00, 0x8c, 0x20, 0x03, 0x84, + 0x80, 0xf4, 0xdf, 0x87, 0x0e, 0x70, 0x08, 0x86, 0xf1, 0x08, 0x30, 0x00, + 0x03, 0x1c, 0x03, 0x30, 0xf6, 0x08, 0x20, 0x00, 0xe1, 0x40, 0xb6, 0xd8, + 0x03, 0x1c, 0x02, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x7e, 0xd9, 0x6c, 0x71, + 0x0a, 0x0f, 0x20, 0x00, 0x42, 0x40, 0x0e, 0x0c, 0x6f, 0xee, 0x0c, 0x71, + 0xd6, 0x08, 0x20, 0x00, 0xe1, 0x40, 0x1f, 0x87, 0x8a, 0x24, 0x02, 0x70, + 0xc3, 0x41, 0xa1, 0x00, 0x84, 0x2a, 0x28, 0xe0, 0xa8, 0x20, 0x80, 0x01, + 0x01, 0x11, 0x82, 0x04, 0x01, 0x18, 0x92, 0x00, 0xad, 0x70, 0x40, 0x24, + 0xc2, 0x30, 0x7f, 0xd9, 0x6c, 0x71, 0x42, 0x40, 0xd2, 0x0e, 0x20, 0x00, + 0x03, 0x1c, 0x42, 0x33, 0xd2, 0x0b, 0x6f, 0xee, 0x0c, 0x71, 0x03, 0x14, + 0x80, 0x30, 0x03, 0x1c, 0x42, 0x33, 0x40, 0x24, 0xc2, 0x30, 0xa7, 0x1e, + 0x02, 0x10, 0x54, 0xd9, 0x6c, 0x71, 0xb2, 0x0e, 0x20, 0x00, 0x42, 0x40, + 0xb2, 0x0b, 0x6f, 0xee, 0x0c, 0x71, 0x03, 0x14, 0x81, 0x30, 0xbb, 0xd8, + 0xd3, 0x41, 0x80, 0x3f, 0x00, 0x00, 0x61, 0xc0, 0x7c, 0x1e, 0x42, 0x10, + 0x81, 0xc2, 0x53, 0xd9, 0x6c, 0x71, 0xa1, 0x44, 0xa1, 0x45, 0x42, 0x40, + 0xae, 0x0e, 0x20, 0x00, 0x0a, 0x26, 0x40, 0x04, 0x81, 0xc2, 0x55, 0xd9, + 0x6c, 0x71, 0xa1, 0x44, 0xa1, 0x45, 0x42, 0x40, 0x0a, 0x26, 0x40, 0x04, + 0x96, 0x0e, 0x20, 0x00, 0x61, 0xc5, 0x90, 0xd8, 0x61, 0xc0, 0x81, 0xc2, + 0x56, 0xd9, 0x6c, 0x71, 0xa1, 0x44, 0xa1, 0x45, 0x42, 0x40, 0x82, 0x0e, + 0x20, 0x00, 0x0a, 0x26, 0x40, 0x04, 0x81, 0xc2, 0x57, 0xd9, 0x6c, 0x71, + 0xa1, 0x44, 0xa1, 0x45, 0x42, 0x40, 0x0a, 0x26, 0x40, 0x04, 0x6a, 0x0e, + 0x20, 0x00, 0x04, 0x1c, 0xc3, 0x3f, 0xa8, 0xa6, 0x4e, 0x87, 0x0c, 0x70, + 0x60, 0x7a, 0xe1, 0x41, 0x02, 0x40, 0xcc, 0xc7, 0xf1, 0xc0, 0xa1, 0xc1, + 0x1c, 0xe0, 0x40, 0x24, 0xc2, 0x30, 0x7f, 0xd9, 0x6c, 0x71, 0x2e, 0x0d, + 0x20, 0x00, 0x03, 0x1c, 0x03, 0x30, 0x1e, 0x0b, 0x6f, 0xee, 0x0c, 0x71, + 0x87, 0x74, 0xd1, 0xc0, 0xe0, 0x7e, 0xe0, 0x78, 0x00, 0x41, 0x2f, 0x26, + 0x05, 0xf0, 0xc5, 0x21, 0x84, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xe0, 0x7f, + 0x2e, 0x78, 0xe0, 0x78, 0xe2, 0xc3, 0x45, 0x09, 0x75, 0x03, 0xa1, 0xc1, + 0xc3, 0x42, 0x00, 0x00, 0x28, 0x11, 0x39, 0x0a, 0x6e, 0x00, 0x53, 0x21, + 0xc3, 0x00, 0xbf, 0x80, 0x8c, 0x70, 0x1c, 0xe0, 0x69, 0x15, 0x82, 0x10, + 0x24, 0x15, 0x06, 0x10, 0x80, 0x45, 0x6c, 0x22, 0xc1, 0x00, 0x65, 0x79, + 0x03, 0x1c, 0x42, 0x30, 0x40, 0x24, 0xc2, 0x30, 0x41, 0xd9, 0xe6, 0x0d, + 0x20, 0x00, 0x6c, 0x71, 0x03, 0x14, 0x80, 0x30, 0x69, 0x1d, 0x02, 0x10, + 0xc2, 0xc7, 0xe0, 0x78, 0xe2, 0xc3, 0xa1, 0xc1, 0x03, 0x1c, 0x03, 0x30, + 0xbf, 0x80, 0x1c, 0xe0, 0x1d, 0xe9, 0x39, 0x09, 0x31, 0x01, 0x34, 0x6a, + 0x79, 0x15, 0x83, 0x10, 0x44, 0x21, 0x02, 0x04, 0x50, 0x23, 0x01, 0x01, + 0x45, 0x79, 0x8c, 0x70, 0x03, 0x1c, 0x42, 0x30, 0x40, 0x24, 0xc2, 0x30, + 0x51, 0xd9, 0x6c, 0x71, 0xc3, 0x46, 0x80, 0x3f, 0x00, 0x00, 0x9e, 0x0d, + 0x20, 0x00, 0x80, 0x45, 0x03, 0x14, 0x80, 0x30, 0x79, 0x1d, 0x02, 0x10, + 0xc2, 0xc7, 0x78, 0x15, 0x81, 0x10, 0x8c, 0x70, 0x6c, 0x71, 0x6c, 0x21, + 0x81, 0x00, 0x45, 0x79, 0x03, 0x1c, 0x42, 0x30, 0x40, 0x24, 0xc2, 0x30, + 0x50, 0xd9, 0xc3, 0x46, 0x80, 0x3f, 0x00, 0x00, 0x6e, 0x0d, 0x20, 0x00, + 0x80, 0x45, 0x03, 0x14, 0x80, 0x30, 0x78, 0x1d, 0x02, 0x10, 0xc2, 0xc7, + 0xe6, 0xc3, 0xa1, 0xc1, 0xdf, 0x80, 0x68, 0x47, 0x03, 0x1c, 0x82, 0x30, + 0x1c, 0xe0, 0x40, 0x24, 0xc2, 0x30, 0x6c, 0x71, 0x22, 0x0d, 0x20, 0x00, + 0x28, 0x45, 0x26, 0x0a, 0x6f, 0xee, 0x01, 0x6f, 0x03, 0x14, 0x80, 0x30, + 0xdd, 0x65, 0x28, 0x1d, 0x02, 0x10, 0xc6, 0xc7, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x13, 0x00, 0x28, 0x1a, + 0xcb, 0x44, 0x00, 0x00, 0x44, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x13, 0x00, 0x78, 0x1a, + 0xcb, 0x44, 0x00, 0x00, 0x45, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x13, 0x00, 0x4c, 0x1a, + 0xcb, 0x44, 0x00, 0x00, 0x42, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x13, 0x00, 0xdc, 0x1a, + 0xcb, 0x44, 0x00, 0x00, 0x43, 0x00, 0x3e, 0x79, 0xf2, 0xc3, 0x94, 0x24, + 0x2f, 0x3a, 0xc3, 0x40, 0xa0, 0x00, 0x8c, 0x86, 0xd6, 0x09, 0x20, 0x00, + 0x10, 0x42, 0xcb, 0x47, 0xf0, 0x00, 0x34, 0x00, 0x03, 0xe8, 0x50, 0xd9, + 0x2d, 0xf0, 0xcb, 0x46, 0x13, 0x00, 0xd8, 0xcc, 0x00, 0x8e, 0x1e, 0xe8, + 0xad, 0x70, 0xd3, 0x41, 0x13, 0x00, 0xdc, 0xcc, 0x0a, 0x20, 0x80, 0x2f, + 0x13, 0x00, 0xe4, 0xcc, 0x04, 0x11, 0x02, 0x24, 0x04, 0x10, 0x01, 0x24, + 0x00, 0x24, 0x83, 0x3f, 0x00, 0x00, 0x30, 0x06, 0x8a, 0x24, 0x08, 0x00, + 0xae, 0x09, 0x20, 0x00, 0x42, 0x40, 0x27, 0x08, 0x32, 0x00, 0x58, 0xd9, + 0x00, 0x8e, 0xa5, 0x71, 0xdd, 0x0d, 0x04, 0x90, 0x4f, 0xd8, 0x40, 0xc0, + 0x81, 0xc1, 0x80, 0xc2, 0x42, 0x40, 0x62, 0x09, 0x20, 0x00, 0x40, 0x24, + 0x14, 0x31, 0x06, 0xe8, 0x57, 0xd9, 0x34, 0xaf, 0x15, 0xaf, 0xd2, 0xc7, + 0x4e, 0x70, 0x00, 0xc0, 0x8b, 0x0a, 0x05, 0x20, 0x5a, 0x22, 0x0e, 0x25, + 0x30, 0x24, 0x80, 0x23, 0x1d, 0x78, 0xde, 0x09, 0x2f, 0xef, 0x10, 0x43, + 0x08, 0x45, 0x39, 0xe8, 0x07, 0x85, 0xb7, 0xe8, 0x81, 0xc0, 0x1e, 0x66, + 0x02, 0x86, 0x34, 0x15, 0x11, 0x10, 0x0e, 0x09, 0x20, 0x00, 0x30, 0x15, + 0x10, 0x10, 0x10, 0x45, 0x02, 0x09, 0x20, 0x00, 0x03, 0x86, 0x4c, 0x70, + 0x04, 0x30, 0x80, 0xa0, 0xa2, 0x41, 0xc7, 0xf7, 0x04, 0x30, 0x40, 0xa5, + 0x02, 0x41, 0xca, 0x21, 0x49, 0x05, 0x04, 0x31, 0x00, 0xa0, 0xca, 0x20, + 0x49, 0x04, 0x04, 0x35, 0x80, 0xa0, 0xd1, 0xf7, 0x04, 0x30, 0x40, 0xa0, + 0x05, 0xf2, 0x50, 0x21, 0xfe, 0x87, 0x03, 0xf2, 0x2c, 0xa5, 0x04, 0x31, + 0x00, 0xa0, 0x0f, 0xf2, 0x50, 0x20, 0xfe, 0x87, 0x0b, 0xf2, 0x0d, 0xa5, + 0x09, 0xf0, 0x59, 0xd8, 0x14, 0xaf, 0x16, 0x1f, 0xc2, 0x14, 0x55, 0xaf, + 0x19, 0x8d, 0x87, 0xb8, 0x19, 0xad, 0x46, 0x71, 0xbb, 0xf1, 0xc3, 0x40, + 0xa1, 0x00, 0xc8, 0x2c, 0xde, 0x0d, 0x0f, 0xff, 0xd2, 0xc7, 0xe0, 0x78, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x13, 0x00, 0xd4, 0x1d, 0xcb, 0x44, 0x00, 0x00, 0x41, 0x00, 0x3e, 0x79, + 0xee, 0xc3, 0x82, 0x24, 0x18, 0x3c, 0x4f, 0xd8, 0x40, 0xc0, 0x81, 0xc1, + 0xc3, 0x40, 0xa0, 0x00, 0x8c, 0x86, 0x8a, 0x08, 0x20, 0x00, 0x80, 0xc2, + 0xb2, 0xe8, 0x56, 0x0e, 0xcf, 0xee, 0xc6, 0x0c, 0xef, 0xee, 0x10, 0x43, + 0x10, 0x42, 0x0e, 0x70, 0x00, 0xc0, 0x55, 0x08, 0x25, 0x20, 0x81, 0xc0, + 0x5a, 0x20, 0x0d, 0x25, 0xa0, 0x60, 0x06, 0x09, 0x2f, 0xef, 0x1d, 0x78, + 0x08, 0x47, 0x1e, 0xe8, 0x07, 0x87, 0x9c, 0xe8, 0x81, 0xc0, 0xb8, 0x60, + 0x10, 0x10, 0x11, 0x01, 0xad, 0x70, 0xcd, 0x71, 0x1b, 0x09, 0x6e, 0x23, + 0xa1, 0x40, 0x62, 0x41, 0x0e, 0x0e, 0xef, 0xee, 0x42, 0x42, 0x0b, 0xe8, + 0x07, 0x88, 0x89, 0xe8, 0x78, 0x20, 0x00, 0x00, 0x04, 0x7e, 0xa5, 0x71, + 0xe5, 0x0d, 0x14, 0x98, 0x84, 0xee, 0x19, 0x8f, 0x87, 0xb8, 0x19, 0xaf, + 0x06, 0x71, 0xd8, 0xf1, 0xce, 0xc7, 0xe0, 0x78, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x13, 0x00, 0xfc, 0x1d, + 0xcb, 0x44, 0x00, 0x00, 0x49, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x11, 0x00, 0x2c, 0x69, + 0xcb, 0x44, 0x00, 0x00, 0x4b, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x13, 0x00, 0x4c, 0x36, + 0xcb, 0x44, 0x00, 0x00, 0x48, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x11, 0x00, 0x34, 0x75, + 0xcb, 0x44, 0x00, 0x00, 0x4a, 0x00, 0x3e, 0x79, 0x58, 0x88, 0x68, 0xba, + 0x9f, 0xe2, 0xe1, 0x20, 0xcd, 0x07, 0x40, 0x43, 0xc3, 0x42, 0x04, 0x90, + 0x01, 0x02, 0x11, 0x22, 0xc0, 0x80, 0xe0, 0x7c, 0x10, 0x80, 0xe0, 0x7f, + 0x00, 0xa1, 0xe0, 0x78, 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, + 0xe0, 0x20, 0x82, 0x0f, 0x11, 0x00, 0xf4, 0x7e, 0xcb, 0x44, 0x00, 0x00, + 0x31, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, + 0xe0, 0x20, 0x82, 0x0f, 0x11, 0x00, 0x10, 0x80, 0xcb, 0x44, 0x00, 0x00, + 0x1c, 0x00, 0x3e, 0x79, 0xc3, 0x40, 0xa1, 0x00, 0x8c, 0x29, 0xe0, 0x7f, + 0x00, 0x18, 0x43, 0x00, 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, + 0xe0, 0x20, 0x82, 0x0f, 0x11, 0x00, 0x84, 0xa1, 0xcb, 0x44, 0x00, 0x00, + 0x0a, 0x00, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, + 0xe0, 0x20, 0x82, 0x0f, 0x11, 0x00, 0x04, 0xa4, 0xcb, 0x44, 0x00, 0x00, + 0x0d, 0x00, 0x3e, 0x79, 0xe8, 0xc3, 0xa2, 0xc1, 0x28, 0x46, 0x08, 0x45, + 0x14, 0x70, 0x23, 0xd8, 0x45, 0xf2, 0x8b, 0x0e, 0x10, 0x10, 0x1a, 0x85, + 0xcb, 0x47, 0xff, 0x46, 0x00, 0xfe, 0x00, 0x30, 0xd0, 0x03, 0xb6, 0x0f, + 0xef, 0xff, 0xa1, 0x40, 0x48, 0x30, 0x00, 0x00, 0x42, 0x86, 0x4a, 0x24, + 0xc0, 0x70, 0x07, 0x30, 0x0b, 0x20, 0xc7, 0xde, 0x80, 0xc4, 0x18, 0xbe, + 0xa8, 0x20, 0xc0, 0x04, 0x04, 0x12, 0x00, 0x04, 0x00, 0x33, 0x01, 0x10, + 0xe1, 0x40, 0x04, 0x31, 0xc0, 0x83, 0x07, 0xf6, 0x04, 0x31, 0x80, 0x83, + 0xc1, 0x40, 0xca, 0x20, 0x46, 0x00, 0x48, 0x30, 0xc3, 0x02, 0x02, 0x1c, + 0xd4, 0x10, 0xc3, 0x40, 0xa1, 0x00, 0x8c, 0x29, 0x20, 0x88, 0x83, 0x42, + 0x81, 0x92, 0x40, 0x92, 0x8b, 0xe9, 0x22, 0x90, 0x13, 0x0a, 0x41, 0x00, + 0x24, 0x90, 0x0f, 0x0c, 0x61, 0x10, 0x70, 0x79, 0xc6, 0x90, 0x19, 0x0e, + 0x40, 0x10, 0x42, 0xb0, 0x00, 0x18, 0x03, 0x00, 0x84, 0xb0, 0x66, 0xb0, + 0x80, 0xc1, 0xda, 0x08, 0x20, 0x00, 0xa1, 0x40, 0x0c, 0x70, 0xc8, 0xc7, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x11, 0x00, 0x3c, 0xae, 0xcb, 0x44, 0x00, 0x00, 0x30, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x11, 0x00, 0x94, 0xae, 0xcb, 0x44, 0x00, 0x00, 0x2f, 0x00, 0x3e, 0x79, + 0xc3, 0x41, 0xf0, 0x00, 0x40, 0x02, 0x80, 0xd8, 0x08, 0xa1, 0x0c, 0x81, + 0xe7, 0xb8, 0xe0, 0x7d, 0x2f, 0x27, 0x3f, 0x00, 0x6f, 0x23, 0x3f, 0x00, + 0x44, 0x81, 0xa7, 0xba, 0x44, 0xa1, 0x2f, 0x26, 0x3f, 0x00, 0xe0, 0x7e, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x13, 0x00, 0x2c, 0x61, 0xcb, 0x44, 0x00, 0x00, 0x5b, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x13, 0x00, 0x44, 0x61, 0xcb, 0x44, 0x00, 0x00, 0x5c, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x13, 0x00, 0x88, 0x63, 0xcb, 0x44, 0x00, 0x00, 0x26, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0x80, 0x4c, 0xcb, 0x44, 0x00, 0x00, 0x27, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0xc0, 0x4c, 0xcb, 0x44, 0x00, 0x00, 0x28, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0xe8, 0x00, 0xcb, 0x44, 0x00, 0x00, 0x18, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0xa4, 0x01, 0xcb, 0x44, 0x00, 0x00, 0x17, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0x34, 0x6c, 0xcb, 0x44, 0x00, 0x00, 0x16, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0xdc, 0x09, 0xcb, 0x44, 0x00, 0x00, 0x15, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0xf4, 0x09, 0xcb, 0x44, 0x00, 0x00, 0x14, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0x04, 0x0a, 0xcb, 0x44, 0x00, 0x00, 0x13, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x12, 0x00, 0x2c, 0x0a, 0xcb, 0x44, 0x00, 0x00, 0x12, 0x00, 0x3e, 0x79, + 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, + 0x13, 0x00, 0x6c, 0x6a, 0x1d, 0xdc, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, + 0x51, 0x24, 0x80, 0x93, 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0xc0, 0x4b, + 0x1f, 0xdc, 0x3e, 0x79, 0x6a, 0x24, 0x80, 0x12, 0x51, 0x24, 0x80, 0x93, + 0xe0, 0x20, 0x82, 0x0f, 0x12, 0x00, 0x40, 0x4c, 0x21, 0xdc, 0x3e, 0x79, + 0x9b, 0xc9, 0x00, 0x00, 0x02, 0x23, 0x00, 0x00, 0x67, 0x17, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x5e, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x01, 0x52, 0x00, 0x04, 0x7f, 0x20, 0x01, 0x40, 0x04, 0x00, 0x6f, 0x00, + 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x22, 0x7a, 0x08, 0x41, 0x00, 0x05, + 0x00, 0x00, 0x17, 0x7a, 0x08, 0x41, 0x00, 0x0a, 0x00, 0x00, 0x18, 0x7a, + 0x08, 0x41, 0x00, 0x0a, 0x00, 0x00, 0xfe, 0x7a, 0x08, 0x41, 0x00, 0x07, + 0x00, 0x28, 0x00, 0x00, 0x39, 0x00, 0xc3, 0x00, 0x01, 0x52, 0x00, 0x04, + 0x7f, 0x50, 0x01, 0x40, 0x06, 0x00, 0x6f, 0x03, 0x00, 0x00, 0xff, 0x00, + 0x00, 0x02, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x40, 0xfe, 0xff, + 0x18, 0xff, 0x00, 0x01, 0x00, 0x40, 0x40, 0x00, 0x40, 0x10, 0x00, 0x00, + 0xff, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0x08, 0x00, 0xff, 0xfe, 0x7f, + 0x18, 0x7f, 0xff, 0x02, 0x00, 0xff, 0x00, 0x7f, 0x00, 0x7f, 0xff, 0x4f, + 0xff, 0xff, 0x7f, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x01, 0x40, 0xfe, 0x40, + 0x88, 0x00, 0x00, 0x03, 0x00, 0x40, 0x40, 0xff, 0x40, 0xff, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0x40, 0xff, 0xff, 0xff, 0x00, 0x40, 0x40, 0x40, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0x40, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x40, 0xff, + 0x40, 0xff, 0xff, 0x00, 0xff, 0x40, 0x40, 0x40, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x40, 0xff, 0x40, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x40, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0xff, 0x00, 0xff, 0x80, 0x80, + 0x80, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0xff, 0xff, 0xff, + 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0x00, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff, 0x00, 0xff, + 0x00, 0xff, 0xff, 0x80, 0xff, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0x80, + 0x80, 0x00, 0x00, 0xff, 0x00, 0xff, 0x80, 0x80, 0xff, 0x00, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0xfe, 0x00, 0x88, 0x00, 0x00, 0x04, + 0x00, 0x12, 0x00, 0x20, 0x00, 0x3c, 0xac, 0x00, 0xac, 0x12, 0x20, 0x20, + 0x12, 0x3c, 0xac, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xcc, 0xcd, 0xcc, 0xcc, 0xcd, 0x3d, 0xcc, 0x3d, 0xcc, 0x00, 0xcc, 0x00, + 0xcd, 0x00, 0x00, 0x3d, 0x00, 0x58, 0x00, 0x8b, 0x00, 0x3a, 0xa0, 0x00, + 0xa0, 0x58, 0x8b, 0x8b, 0x58, 0x3a, 0xa0, 0x3a, 0xac, 0x12, 0x20, 0x20, + 0x12, 0x3c, 0xac, 0x3c, 0xac, 0x58, 0x20, 0x8b, 0x12, 0x3a, 0xa0, 0x3c, + 0xa0, 0x58, 0x8b, 0x8b, 0x58, 0x3a, 0xa0, 0x3a, 0xac, 0x12, 0x20, 0x20, + 0x12, 0x3c, 0xac, 0x3c, 0xcc, 0xcd, 0xcc, 0xcc, 0xcd, 0x3d, 0xcc, 0x3d, + 0xcc, 0xcd, 0xcc, 0xcc, 0xcd, 0x3d, 0xcc, 0x3d, 0xcc, 0x58, 0xcc, 0x8b, + 0xcd, 0x3a, 0xa0, 0x3d, 0xa0, 0x00, 0x8b, 0x00, 0x58, 0x00, 0x00, 0x3a, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x0a, 0x1c, 0x1c, + 0x0a, 0x41, 0xe8, 0x41, 0xe8, 0x12, 0x1c, 0x20, 0x0a, 0x3c, 0xac, 0x41, + 0xac, 0x12, 0x20, 0x20, 0x12, 0x3c, 0xac, 0x3c, 0x01, 0x01, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0xfe, 0x00, 0x08, 0x00, 0x00, 0x0a, 0x00, 0x87, 0x00, 0x00, + 0x03, 0x00, 0x6e, 0x00, 0x02, 0x00, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x70, 0xc9, 0x13, 0x00, 0x38, 0xc9, 0x13, 0x00, + 0xf1, 0xc0, 0x0e, 0x08, 0x00, 0x00, 0xd1, 0xc0, 0xe0, 0x7f, 0x0c, 0x70, + 0xe4, 0xc2, 0xad, 0x70, 0xcb, 0x46, 0xa1, 0x00, 0xac, 0x29, 0x00, 0x86, + 0x21, 0x86, 0x02, 0x79, 0x0b, 0x09, 0x72, 0x01, 0x22, 0xb9, 0x66, 0x0a, + 0xcf, 0xff, 0xa5, 0x71, 0xef, 0x0d, 0x34, 0x94, 0x08, 0xe6, 0xc4, 0xc6, + 0x49, 0x4e, 0x49, 0x03, 0x54, 0x3b, 0x11, 0x00, 0x50, 0x29, 0xa1, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x15, 0x00, 0x02, 0x01, 0x05, 0x02, + 0x04, 0xc4, 0xc3, 0x13, 0x00, 0x03, 0x08, 0xf4, 0x06, 0x08, 0xdc, 0x06, + 0x08, 0x0c, 0xc4, 0x13, 0x34, 0xe8, 0x00, 0x06, 0x02, 0x20, 0x24, 0x02, + 0x08, 0x03, 0x20, 0x3c, 0xc5, 0x13, 0x00, 0x01, 0x02, 0x10, 0x54, 0x02, + 0x08, 0x02, 0x07, 0x0c, 0x03, 0x01, 0x00, 0x03, 0x20, 0x88, 0xc7, 0x13, + 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0xc6, 0x13, 0x00, 0x00, 0x00, 0x00, + 0xac, 0x29, 0xa1, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xb0, 0xda, 0x6c, + 0x3e, 0xa1, 0x00, 0x0f, 0x04, 0x0b, 0x10, 0x48, 0x02, 0x20, 0x4c, 0x06, + 0x04, 0x50, 0x02, 0x08, 0x03, 0x04, 0x54, 0x02, 0x08, 0x0b, 0x04, 0x6e, + 0x0f, 0x58, 0x02, 0x10, 0x0f, 0x04, 0x03, 0x10, 0x5c, 0x02, 0x18, 0x03, + 0x04, 0x68, 0x02, 0x08, 0x03, 0x04, 0x0b, 0x58, 0x07, 0x0c, 0x02, 0x03, + 0x00, 0x00, 0x00, 0x40, 0x14, 0x05, 0x7a, 0x3d, 0x04, 0x05, 0x00, 0x00, + 0xd6, 0xff, 0xf9, 0x3d, 0x08, 0x08, 0x03, 0x08, 0x79, 0x08, 0x04, 0x3e, + 0x10, 0x0c, 0x03, 0x08, 0xf9, 0x3e, 0x00, 0x00, 0x48, 0x41, 0x02, 0x1b, + 0x00, 0x00, 0x00, 0xc8, 0x41, 0x26, 0x63, 0x06, 0x02, 0x06, 0x02, 0x10, + 0x42, 0x07, 0x04, 0x08, 0xc8, 0x42, 0x02, 0x2b, 0x02, 0x0a, 0x48, 0x43, + 0x09, 0x02, 0x06, 0x02, 0x20, 0x43, 0xa2, 0xeb, 0x0a, 0x04, 0x08, 0x48, + 0x44, 0x0b, 0x02, 0x08, 0xd1, 0x02, 0x04, 0x0f, 0x03, 0x06, 0x10, 0x01, + 0x04, 0x08, 0x80, 0x04, 0x06, 0x0f, 0x05, 0x08, 0x10, 0x00, 0x61, 0x28, + 0x03, 0x28, 0x00, 0x0b, 0x88, 0x80, 0x10, 0x02, 0x11, 0x20, 0x80, 0x42, + 0x4c, 0x02, 0x07, 0x07, 0x03, 0x07, 0x00, 0xc0, 0x30, 0x81, 0x0b, 0xc0, + 0x00, 0x14, 0x14, 0x24, 0x04, 0x0a, 0x18, 0x48, 0x08, 0x11, 0x07, 0x17, + 0x08, 0x08, 0x44, 0x08, 0x15, 0x03, 0x03, 0x0b, 0x7d, 0x00, 0x04, 0x02, + 0x07, 0x80, 0x3d, 0xfa, 0x00, 0x04, 0x0f, 0x3e, 0xf4, 0x01, 0x02, 0x11, + 0x01, 0x03, 0x10, 0x3e, 0xe8, 0x03, 0x04, 0x7f, 0x3f, 0xd0, 0x07, 0x02, + 0x0f, 0x00, 0x80, 0x3f, 0x19, 0x00, 0x06, 0x00, 0x00, 0x00, 0x32, 0x00, + 0x07, 0x00, 0x64, 0x00, 0x08, 0x00, 0xc8, 0x00, 0x09, 0x00, 0x90, 0x01, + 0x0a, 0x00, 0x00, 0x00, 0x20, 0x03, 0x0b, 0x00, 0x48, 0x2b, 0xa1, 0x00, + 0xef, 0x00, 0x00, 0x00, 0x00, 0x42, 0x2a, 0x00, 0x02, 0x01, 0x20, 0x01, + 0x10, 0x00, 0x0f, 0x01, 0x01, 0x0a, 0x05, 0x12, 0x21, 0x02, 0x07, 0xf0, + 0x02, 0x04, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x19, 0x00, + 0x03, 0x78, 0x22, 0x00, 0x5c, 0xae, 0x13, 0x00, 0x7c, 0xaf, 0x08, 0x82, + 0x13, 0x00, 0x44, 0x02, 0x08, 0xb0, 0xb3, 0x13, 0x00, 0x4c, 0x02, 0x08, + 0xb8, 0xac, 0x13, 0x00, 0x78, 0x02, 0x04, 0x82, 0x38, 0x54, 0x02, 0x0c, + 0xf0, 0xbf, 0x13, 0x00, 0x94, 0x02, 0x08, 0xfc, 0xad, 0x13, 0x02, 0x3a, + 0x0f, 0x03, 0x05, 0x10, 0x64, 0x28, 0x60, 0x08, 0xa1, 0x00, 0x88, 0x27, + 0xa1, 0x05, 0x0d, 0x0a, 0x06, 0xb8, 0x1e, 0x05, 0x3e, 0x09, 0x0f, 0x48, + 0x44, 0x00, 0x00, 0xa4, 0x4f, 0x80, 0x3f, 0x02, 0x7a, 0x00, 0x08, 0x06, + 0x15, 0x01, 0x02, 0x08, 0x04, 0x04, 0x02, 0x90, 0x02, 0x0b, 0x04, 0x03, + 0x21, 0x01, 0x0f, 0xc0, 0x00, 0x1c, 0x00, 0x00, 0x03, 0x0f, 0xc0, 0x02, + 0x30, 0x05, 0xc0, 0xa0, 0x00, 0xcc, 0xb9, 0x13, 0x00, 0x68, 0xbc, 0x13, + 0x00, 0x1c, 0x00, 0x41, 0xb8, 0x13, 0x00, 0xac, 0xbe, 0x13, 0x00, 0x6c, + 0x02, 0x10, 0x60, 0xb5, 0x13, 0x00, 0x20, 0x02, 0x04, 0x74, 0x15, 0x54, + 0x02, 0x0c, 0x24, 0x02, 0x18, 0xf4, 0x02, 0x08, 0x78, 0xb7, 0x13, 0x00, + 0x24, 0x02, 0xcc, 0x7c, 0x02, 0x0c, 0x00, 0x0e, 0x01, 0xa4, 0x63, 0x01, + 0x0f, 0xc0, 0x06, 0x20, 0xcd, 0xcc, 0x4c, 0x02, 0xb0, 0x06, 0x0d, 0x00, + 0x03, 0xc0, 0xc8, 0x41, 0x00, 0x00, 0xd0, 0x07, 0xd0, 0x06, 0x00, 0x07, + 0x05, 0x14, 0x04, 0xbc, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc8, 0x2c, 0xa1, 0x00, 0x0e, 0x04, 0x00, 0x00, + 0x00, 0xb2, 0x69, 0x00, 0x02, 0x01, 0xf0, 0x01, 0x02, 0x05, 0x0e, 0x03, + 0xc0, 0x0e, 0x10, 0x09, 0x0f, 0x48, 0x44, 0x09, 0x0c, 0x03, 0x09, 0x0b, + 0x06, 0x0a, 0x30, 0xf0, 0x6d, 0xac, 0x13, 0x00, 0x00, 0x03, 0x04, 0x06, + 0x10, 0x0f, 0x07, 0x0f, 0x10, 0x03, 0x10, 0xf1, 0x0f, 0x80, 0x02, 0x15, + 0x04, 0x02, 0x04, 0x03, 0x03, 0x01, 0x06, 0x32, 0x02, 0x03, 0x06, 0x0b, + 0x04, 0xc8, 0x43, 0x00, 0x00, 0xc8, 0x3f, 0x05, 0x12, 0x02, 0x06, 0x05, + 0x08, 0x0d, 0x06, 0x58, 0xab, 0x83, 0xcd, 0x02, 0x84, 0x0d, 0x13, 0x00, + 0x7f, 0xd6, 0xd0, 0x3d, 0x0e, 0x13, 0x08, 0x0f, 0xd1, 0x0f, 0x80, 0x02, + 0x1a, 0x05, 0x20, 0x02, 0x05, 0x02, 0x03, 0x7f, 0xdf, 0x0f, 0x80, 0x02, + 0x7c, 0x02, 0x80, 0x02, 0x19, 0x04, 0x03, 0x0f, 0x80, 0x04, 0x15, 0x00, + 0x0f, 0x80, 0x03, 0x16, 0x0f, 0x80, 0x03, 0x14, 0x07, 0x04, 0xcd, 0x0f, + 0x80, 0x02, 0x19, 0xbf, 0xf7, 0x07, 0x13, 0x0f, 0x80, 0x05, 0x80, 0x1f, + 0x00, 0x02, 0x31, 0x0a, 0x03, 0x28, 0x1f, 0x00, 0x0a, 0x1c, 0x0f, 0x0b, + 0x03, 0x10, 0xcb, 0x07, 0x6d, 0x03, 0x0d, 0x06, 0x04, 0x17, 0xda, 0xff, + 0xcd, 0x0f, 0x80, 0x0f, 0x80, 0x06, 0x2f, 0x0c, 0x07, 0x1f, 0x00, 0x03, + 0x1d, 0x1f, 0x00, 0x03, 0x14, 0x07, 0x04, 0xeb, 0x0f, 0x80, 0x02, 0x19, + 0x3f, 0x34, 0x02, 0x05, 0x0f, 0x03, 0x59, 0x6f, 0x0f, 0x10, 0x00, 0x02, + 0x2f, 0x1e, 0x04, 0x22, 0x70, 0x12, 0x00, 0x48, 0x2f, 0x84, 0x04, 0x1a, + 0x0f, 0x05, 0x05, 0x10, 0xa3, 0x0f, 0x80, 0x02, 0x17, 0x45, 0x6f, 0x7d, + 0x26, 0x00, 0x02, 0x0b, 0x0f, 0x03, 0x0a, 0x10, 0x02, 0x0f, 0x3a, 0x04, + 0x1c, 0x88, 0x02, 0x80, 0xb8, 0x02, 0x04, 0x04, 0x0d, 0x0f, 0x05, 0x0f, + 0x10, 0x02, 0x10, 0xfc, 0x7b, 0x3b, 0x0f, 0x46, 0x02, 0x14, 0x25, 0x02, + 0x04, 0x0f, 0x03, 0x05, 0x10, 0x3c, 0x00, 0x0a, 0x05, 0x14, 0x0d, 0x06, + 0x40, 0x0f, 0x7c, 0x0d, 0x1f, 0x0f, 0x0e, 0x00, 0xea, 0x3b, 0xeb, 0x0f, + 0x80, 0x02, 0x22, 0x3b, 0x1f, 0x80, 0x02, 0x14, 0x0f, 0x03, 0x00, 0x00, + 0x1f, 0x7f, 0x05, 0x22, 0xe8, 0x02, 0x80, 0x60, 0x1f, 0x80, 0x05, 0x1b, + 0x0f, 0x06, 0xed, 0xff, 0x04, 0x10, 0xf7, 0x0f, 0x80, 0x02, 0x16, 0x1c, + 0x02, 0x04, 0x03, 0x03, 0x2f, 0x80, 0x2f, 0x80, 0x03, 0x24, 0x0f, 0x04, + 0x2f, 0x80, 0x03, 0x20, 0x2f, 0x80, 0x03, 0x14, 0x07, 0x04, 0xb6, 0x3e, + 0xf3, 0x0f, 0x80, 0x02, 0x19, 0x0d, 0x02, 0x04, 0x03, 0x03, 0x03, 0x0f, + 0xe3, 0x00, 0x1c, 0x80, 0x4f, 0x80, 0x03, 0x33, 0x4f, 0x00, 0x04, 0x14, + 0xe1, 0x2e, 0xdc, 0xfe, 0x65, 0x42, 0x04, 0x09, 0x0f, 0x05, 0x02, 0x10, + 0xd0, 0x0f, 0x80, 0x02, 0x14, 0x0e, 0x26, 0x80, 0x0f, 0x80, 0x15, 0x00, + 0x02, 0x21, 0x04, 0x03, 0x4f, 0x80, 0x04, 0x15, 0xe8, 0xfb, 0x00, 0xc0, + 0xc6, 0x55, 0x00, 0x84, 0x06, 0x08, 0x03, 0x16, 0x0f, 0x80, 0x03, 0x14, + 0x07, 0x04, 0xcf, 0x0f, 0x80, 0x02, 0x19, 0x27, 0x59, 0x0f, 0x80, 0x05, + 0x80, 0x7f, 0xfb, 0x4f, 0x80, 0x02, 0x31, 0x0a, 0x03, 0x4f, 0x80, 0x0a, + 0x1b, 0x0f, 0x0b, 0x04, 0x10, 0xf4, 0x0f, 0x80, 0x02, 0x16, 0x0c, 0x02, + 0x04, 0x03, 0x03, 0x0f, 0x80, 0x0f, 0x80, 0x03, 0x24, 0xbf, 0xfd, 0x0f, + 0x04, 0x2f, 0x00, 0x03, 0x20, 0x1f, 0x00, 0x03, 0x14, 0x07, 0x04, 0xf6, + 0x0f, 0x80, 0x02, 0x19, 0x1f, 0x02, 0x04, 0x03, 0x03, 0x2f, 0x80, 0x0f, + 0x80, 0x03, 0x24, 0x0f, 0x04, 0xdf, 0xfe, 0x0f, 0x80, 0x03, 0x20, 0x2f, + 0x80, 0x03, 0x14, 0x07, 0x04, 0xe9, 0x0f, 0x80, 0x02, 0x19, 0x3d, 0x3f, + 0x80, 0x02, 0x14, 0x0f, 0x03, 0x3f, 0x80, 0x07, 0x20, 0x3f, 0x80, 0x07, + 0x18, 0xdb, 0x7f, 0x0f, 0x08, 0x07, 0x10, 0xfa, 0x0f, 0x80, 0x02, 0x19, + 0x37, 0x0f, 0x80, 0x02, 0x14, 0x0f, 0x03, 0x0f, 0x80, 0x07, 0x20, 0x0f, + 0x80, 0x07, 0x18, 0x0f, 0x08, 0x07, 0x10, 0xf9, 0x7b, 0xa3, 0x0f, 0x80, + 0x02, 0x19, 0x34, 0x36, 0x00, 0x02, 0x0b, 0x0f, 0x03, 0x0a, 0x10, 0x02, + 0x87, 0x27, 0x0a, 0x14, 0x00, 0x00, 0x18, 0x42, 0x7c, 0xd0, 0x42, 0x84, + 0x37, 0xdf, 0x0c, 0x15, 0x0f, 0x0d, 0x0a, 0x10, 0xf8, 0x0f, 0x80, 0x02, + 0x1c, 0x32, 0x30, 0x02, 0x05, 0x0f, 0x03, 0x0f, 0x10, 0x5f, 0x00, 0x06, + 0x20, 0xa0, 0x02, 0x7c, 0x5f, 0x00, 0xb7, 0xff, 0x06, 0x1b, 0x0f, 0x07, + 0x04, 0x10, 0xec, 0x0f, 0x80, 0x02, 0x16, 0x30, 0x1f, 0x80, 0x02, 0x14, + 0x0f, 0x03, 0x1f, 0x80, 0x07, 0x20, 0x0f, 0x80, 0x07, 0x18, 0x0f, 0x08, + 0x07, 0x10, 0xf6, 0xbf, 0xc0, 0x0f, 0x80, 0x02, 0x19, 0x06, 0x16, 0x5a, + 0x3f, 0x00, 0x3f, 0x00, 0x02, 0x2b, 0x0f, 0x03, 0x5f, 0x00, 0x04, 0x20, + 0x3f, 0x00, 0x04, 0x15, 0x06, 0x05, 0xcc, 0x0f, 0x80, 0xfd, 0xdf, 0x02, + 0x18, 0x07, 0x0f, 0x80, 0x02, 0x14, 0x05, 0x03, 0x5f, 0x80, 0x05, 0x16, + 0x0b, 0x06, 0x3f, 0x80, 0x03, 0x1c, 0x0f, 0x80, 0x03, 0x14, 0x07, 0x04, + 0xa4, 0x0f, 0x80, 0x02, 0x19, 0xdc, 0x6f, 0x46, 0x24, 0x02, 0x05, 0x0f, + 0x03, 0x0f, 0x10, 0x00, 0x8f, 0x00, 0x05, 0x21, 0x8f, 0x00, 0x05, 0x16, + 0x0f, 0x06, 0x09, 0x10, 0xc8, 0x0f, 0x80, 0x02, 0x1b, 0x26, 0xff, 0xdb, + 0x16, 0x00, 0x02, 0x0b, 0x0e, 0x03, 0x1c, 0x00, 0x57, 0xa7, 0x0c, 0x24, + 0x8f, 0x00, 0x0c, 0x1d, 0x0f, 0x0d, 0x02, 0x10, 0xe8, 0x0f, 0x80, 0x02, + 0x14, 0x39, 0x2f, 0x80, 0x02, 0x14, 0x7f, 0xfb, 0x0f, 0x03, 0x2f, 0x80, + 0x07, 0x20, 0x4f, 0x00, 0x07, 0x18, 0x0f, 0x08, 0x07, 0x10, 0xc6, 0x0f, + 0x80, 0x02, 0x19, 0x1d, 0x16, 0x00, 0x2f, 0x80, 0x2f, 0x80, 0x02, 0x2b, + 0x0f, 0x03, 0xdf, 0xfe, 0x2f, 0x80, 0x04, 0x20, 0x2f, 0x00, 0x04, 0x15, + 0x06, 0x05, 0xc2, 0x0f, 0x80, 0x02, 0x18, 0x0f, 0x06, 0x80, 0x6f, 0x80, + 0x0f, 0x80, 0x02, 0x2b, 0x0f, 0x03, 0x0f, 0x80, 0x04, 0x20, 0xb7, 0xff, + 0x6f, 0x80, 0x04, 0x15, 0x06, 0x05, 0xc3, 0x0f, 0x80, 0x02, 0x18, 0x10, + 0x0f, 0x80, 0x02, 0x14, 0x05, 0x03, 0x2c, 0x00, 0x8f, 0x80, 0x04, 0x23, + 0x3f, 0x00, 0x03, 0x15, 0x0f, 0x80, 0xdb, 0xff, 0x03, 0x14, 0x07, 0x04, + 0xc5, 0x0f, 0x80, 0x02, 0x19, 0x20, 0x06, 0x80, 0x1f, 0x80, 0x1f, 0x00, + 0x02, 0x2b, 0x0f, 0x03, 0x1f, 0x00, 0x04, 0x20, 0x1f, 0x80, 0x04, 0x15, + 0x06, 0x05, 0xf6, 0xdf, 0xa0, 0x0f, 0x80, 0x02, 0x18, 0x4d, 0x2f, 0x80, + 0x02, 0x14, 0x0f, 0x03, 0x2f, 0x80, 0x07, 0x20, 0x2f, 0x80, 0x07, 0x18, + 0x0f, 0x08, 0x07, 0x10, 0xa1, 0x0f, 0x80, 0x02, 0x19, 0xfe, 0xdb, 0x4b, + 0x0f, 0x80, 0x02, 0x14, 0x0f, 0x03, 0x0f, 0x80, 0x07, 0x20, 0x0f, 0x80, + 0x07, 0x18, 0x0f, 0x08, 0x07, 0x10, 0xe7, 0x0f, 0x80, 0x02, 0x19, 0x35, + 0x4f, 0x80, 0x02, 0x14, 0x7f, 0xec, 0x0f, 0x03, 0x02, 0x80, 0x16, 0xa6, + 0x0d, 0x1a, 0x7f, 0x00, 0x0d, 0x1e, 0x0f, 0x0e, 0x00, 0x00, 0xe6, 0x0f, + 0x80, 0x02, 0x23, 0x5e, 0x1f, 0x00, 0x02, 0x14, 0x0f, 0x03, 0x7f, 0xfb, + 0x02, 0x80, 0x0f, 0x13, 0x04, 0x10, 0x6f, 0x80, 0x04, 0x15, 0x0f, 0x05, + 0x0a, 0x10, 0xa2, 0x0f, 0x80, 0x02, 0x1c, 0x43, 0x0f, 0x80, 0x02, 0x14, + 0x0f, 0x03, 0x0f, 0x80, 0x07, 0x20, 0x07, 0x00, 0x0f, 0x80, 0x07, 0x18, + 0x0f, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x3d, 0xa1, 0x00, + 0x36, 0x00, 0x00, 0x00, 0x00, 0x32, 0xdd, 0x00, 0x02, 0x01, 0xe0, 0x01, + 0x02, 0x05, 0x0e, 0x03, 0xd0, 0x41, 0x03, 0x11, 0x19, 0x03, 0x05, 0x0f, + 0x04, 0x0a, 0x10, 0x03, 0x0a, 0x0c, 0x09, 0x0b, 0x18, 0x00, 0x6c, 0xc6, + 0x13, 0x09, 0x0d, 0x0f, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x48, 0x3e, 0xa1, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x5c, 0x29, 0xa1, + 0x00, 0x00, 0x00, 0x00, 0x4c, 0x3e, 0xa1, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x01, 0xa4, 0x29, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x50, 0x3e, 0xa1, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x01, 0x64, 0x29, 0xa1, 0x00, 0x00, 0x00, 0x00, + 0x54, 0x3e, 0xa1, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x6c, 0x29, 0xa1, + 0x00, 0x00, 0x00, 0x00, 0x58, 0x3e, 0xa1, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x01, 0x54, 0x29, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x3e, 0xa1, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x01, 0x74, 0x29, 0xa1, 0x00, 0x7c, 0x29, 0xa1, + 0x00, 0x9c, 0x29, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x68, 0x3e, 0xa1, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x01, 0x84, 0x29, 0xa1, 0x00, 0x00, 0x00, 0x00, + 0x88, 0x27, 0xa1, 0x00, 0x38, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/components/SensorLib/src/platform/esp_arduino.cpp b/components/SensorLib/src/platform/esp_arduino.cpp new file mode 100644 index 0000000..169265a --- /dev/null +++ b/components/SensorLib/src/platform/esp_arduino.cpp @@ -0,0 +1,66 @@ +/** + * @file esp_arduino.cpp + * @author Lewis He (lewishe@outlook.com) + * @license MIT + * @copyright Copyright (c) 2024 Shenzhen Xinyuan Electronic Technology Co., Ltd + * @date 2024-01-08 + * + */ +#if !defined(ARDUINO) && defined(ESP_PLATFORM) +#include "SensorLib.h" +#include "driver/gpio.h" +#include "esp_timer.h" +#include "freertos/FreeRTOS.h" +#include + + +void pinMode(uint32_t gpio, uint8_t mode) +{ + gpio_config_t config; + memset(&config, 0, sizeof(config)); + config.pin_bit_mask = 1ULL << gpio; + switch (mode) { + case INPUT: + config.mode = GPIO_MODE_INPUT; + break; + case OUTPUT: + config.mode = GPIO_MODE_OUTPUT; + break; + } + config.pull_up_en = GPIO_PULLUP_DISABLE; + config.pull_down_en = GPIO_PULLDOWN_DISABLE; + config.intr_type = GPIO_INTR_DISABLE; + ESP_ERROR_CHECK(gpio_config(&config)); +} + +void digitalWrite(uint32_t gpio, uint8_t level) +{ + gpio_set_level((gpio_num_t )gpio, level); +} + +int digitalRead(uint32_t gpio) +{ + return gpio_get_level((gpio_num_t)gpio); +} + +void delay(uint32_t ms) +{ + vTaskDelay(pdMS_TO_TICKS(ms)); + ets_delay_us((ms % portTICK_PERIOD_MS) * 1000UL); +} + +uint32_t millis() +{ + return (uint32_t) (esp_timer_get_time() / 1000LL); +} + +uint32_t micros() +{ + return (uint32_t) esp_timer_get_time(); +} + +void delayMicroseconds(uint32_t us) +{ + ets_delay_us(us); +} +#endif diff --git a/components/SensorLib/src/platform/esp_arduino.h b/components/SensorLib/src/platform/esp_arduino.h new file mode 100644 index 0000000..876de66 --- /dev/null +++ b/components/SensorLib/src/platform/esp_arduino.h @@ -0,0 +1,22 @@ +/** + * @file esp_arduino.h + * @author Lewis He (lewishe@outlook.com) + * @license MIT + * @copyright Copyright (c) 2024 Shenzhen Xinyuan Electronic Technology Co., Ltd + * @date 2024-01-08 + * + */ +#pragma once + +#if !defined(ARDUINO) && defined(ESP_PLATFORM) + +void pinMode(uint32_t gpio, uint8_t mode); +void digitalWrite(uint32_t gpio, uint8_t level); +int digitalRead(uint32_t gpio); +void delay(uint32_t ms); +uint32_t millis(); +uint32_t micros(); +void delayMicroseconds(uint32_t us); + +#endif + diff --git a/components/SensorLib/src/touch/TouchClassCST226.cpp b/components/SensorLib/src/touch/TouchClassCST226.cpp new file mode 100644 index 0000000..8d292cb --- /dev/null +++ b/components/SensorLib/src/touch/TouchClassCST226.cpp @@ -0,0 +1,323 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchClassCST226.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-06 + */ +#include "TouchClassCST226.h" + +#define CST2xx_REG_STATUS (0x00) +#define CST226SE_BUFFER_NUM (28) + +#if defined(ARDUINO) +TouchClassCST226::TouchClassCST226() +{ + +} + +bool TouchClassCST226::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl) +{ + return SensorCommon::begin(wire, address, sda, scl); +} + +#elif defined(ESP_PLATFORM) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) +bool TouchClassCST226::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) +{ + return SensorCommon::begin(i2c_dev_bus_handle, addr); +} +#else +bool TouchClassCST226::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) +{ + return SensorCommon::begin(port_num, addr, sda, scl); +} +#endif //ESP_IDF_VERSION + +#endif //ARDUINO + + +bool TouchClassCST226::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) +{ + return SensorCommon::begin(addr, readRegCallback, writeRegCallback); +} + +void TouchClassCST226::reset() +{ + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + this->setGpioLevel(__rst, LOW); + delay(100); + this->setGpioLevel(__rst, HIGH); + delay(100); + } else { + writeRegister(0xD1, 0x0E); + delay(20); + } +} + +uint8_t TouchClassCST226::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point) +{ + uint8_t buffer[CST226SE_BUFFER_NUM]; + uint8_t index = 0; + + if (readRegister(CST2xx_REG_STATUS, buffer, CST226SE_BUFFER_NUM) == DEV_WIRE_ERR) { + return 0; + } + +#ifdef LOG_PORT + LOG_PORT.print("RAW:"); + for (int i = 0; i < CST226SE_BUFFER_NUM; ++i) { + LOG_PORT.printf("%02X,", buffer[i]); + } + LOG_PORT.println(); +#endif + + if (buffer[0] == 0x83 && buffer[1] == 0x17 && buffer[5] == 0x80) { + if (__homeButtonCb) { + __homeButtonCb(__userData); + } + return 0; + } + + if (buffer[6] != 0xAB)return 0; + if (buffer[0] == 0xAB)return 0; + if (buffer[5] == 0x80)return 0; + + uint8_t point = buffer[5] & 0x7F; + if (point > 5 || !point) { + writeRegister(0x00, 0xAB); + return 0; + } + + for (int i = 0; i < point; i++) { + report.id[i] = buffer[index] >> 4; + report.status[i] = buffer[index] & 0x0F; + report.x[i] = (uint16_t)((buffer[index + 1] << 4) | ((buffer[index + 3] >> 4) & 0x0F)); + report.y[i] = (uint16_t)((buffer[index + 2] << 4) | (buffer[index + 3] & 0x0F)); + report.pressure[i] = buffer[index + 4]; + index = (i == 0) ? (index + 7) : (index + 5); + } + + updateXY(point, report.x, report.y); + +#ifdef LOG_PORT + for (int i = 0; i < point; i++) { + LOG_PORT.printf("[%d]-X:%u Y:%u P:%u sta:%u ", report.id[i], report.x[i], report.y[i], report.pressure[i], report.status[i]); + } + LOG_PORT.println(); +#endif + + if (point) { + for (int i = 0; i < get_point; i++) { + x_array[i] = report.x[i]; + y_array[i] = report.y[i]; + } + } + + return point; +} + +bool TouchClassCST226::isPressed() +{ + static uint32_t lastPulse = 0; + if (__irq != SENSOR_PIN_NONE) { + int val = this->getGpioLevel(__irq) == LOW; + if (val) { + //Filter low levels with intervals greater than 1000ms + val = (millis() - lastPulse > 1000) ? false : true; + lastPulse = millis(); + return val; + } + return false; + } + return getPoint(NULL, NULL, 1); +} + + +const char *TouchClassCST226::getModelName() +{ + return "CST226SE"; +} + +void TouchClassCST226::sleep() +{ + writeRegister(0xD1, 0x05); +#ifdef ESP32 + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, OPEN_DRAIN); + } + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OPEN_DRAIN); + } +#endif +} + +void TouchClassCST226::wakeup() +{ + reset(); +} + +void TouchClassCST226::idle() +{ + +} + +uint8_t TouchClassCST226::getSupportTouchPoint() +{ + return 5; +} + +bool TouchClassCST226::getResolution(int16_t *x, int16_t *y) +{ + return false; +} + +void TouchClassCST226::setHomeButtonCallback(home_button_callback_t cb, void *user_data) +{ + __homeButtonCb = cb; + __userData = user_data; +} + +void TouchClassCST226::setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) +{ + SensorCommon::setGpioModeCallback(mode_cb); + SensorCommon::setGpioWriteCallback(write_cb); + SensorCommon::setGpioReadCallback(read_cb); +} + +bool TouchClassCST226::initImpl() +{ + + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + } + + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, INPUT); + } + + reset(); + + uint8_t buffer[8]; + // Enter Command mode + writeRegister(0xD1, 0x01); + delay(10); + uint8_t write_buffer[2] = {0xD1, 0xFC}; + writeThenRead(write_buffer, 2, buffer, 4); + uint32_t checkcode = 0; + checkcode = buffer[3]; + checkcode <<= 8; + checkcode |= buffer[2]; + checkcode <<= 8; + checkcode |= buffer[1]; + checkcode <<= 8; + checkcode |= buffer[0]; + + log_i("Chip checkcode:0x%lx.\r\n", checkcode); + + write_buffer[0] = {0xD1}; + write_buffer[1] = {0xF8}; + writeThenRead(write_buffer, 2, buffer, 4); + __resX = ( buffer[1] << 8) | buffer[0]; + __resY = ( buffer[3] << 8) | buffer[2]; + log_i("Chip resolution X:%u Y:%u\r\n", __resX, __resY); + + write_buffer[0] = {0xD2}; + write_buffer[1] = {0x04}; + writeThenRead(write_buffer, 2, buffer, 4); + uint32_t chipType = buffer[3]; + chipType <<= 8; + chipType |= buffer[2]; + + + uint32_t ProjectID = buffer[1]; + ProjectID <<= 8; + ProjectID |= buffer[0]; + log_i("Chip type :0x%lx, ProjectID:0X%lx\r\n", + chipType, ProjectID); + + + + write_buffer[0] = {0xD2}; + write_buffer[1] = {0x08}; + writeThenRead(write_buffer, 2, buffer, 8); + + uint32_t fwVersion = buffer[3]; + fwVersion <<= 8; + fwVersion |= buffer[2]; + fwVersion <<= 8; + fwVersion |= buffer[1]; + fwVersion <<= 8; + fwVersion |= buffer[0]; + + uint32_t checksum = buffer[7]; + checksum <<= 8; + checksum |= buffer[6]; + checksum <<= 8; + checksum |= buffer[5]; + checksum <<= 8; + checksum |= buffer[4]; + + log_i("Chip ic version:0x%lx, checksum:0x%lx\n", + fwVersion, checksum); + + if (fwVersion == 0xA5A5A5A5) { + log_i("Chip ic don't have firmware. \n"); + return false; + } + if ((checkcode & 0xffff0000) != 0xCACA0000) { + log_i("Firmware info read error .\n"); + return false; + } + + __chipID = chipType; + + // Exit Command mode + writeRegister(0xD1, 0x09); + return true; +} + +int TouchClassCST226::getReadMaskImpl() +{ + return -1; +} + + + + + + + + + + + + + + + diff --git a/components/SensorLib/src/touch/TouchClassCST226.h b/components/SensorLib/src/touch/TouchClassCST226.h new file mode 100644 index 0000000..7d1ceaa --- /dev/null +++ b/components/SensorLib/src/touch/TouchClassCST226.h @@ -0,0 +1,97 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchClassCST226.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-06 + */ +#pragma once + +#include "../TouchDrvInterface.hpp" +#include "../SensorCommon.tpp" + +class TouchClassCST226 : public TouchDrvInterface, + public SensorCommon +{ + friend class SensorCommon; + +public: + +#if defined(ARDUINO) + TouchClassCST226(); + + bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl); + +#elif defined(ESP_PLATFORM) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr); +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl); +#endif //ESP_IDF_VERSION + +#endif + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback); + + void reset(); + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point); + + bool isPressed(); + + const char *getModelName(); + + void sleep(); + + void wakeup(); + + void idle(); + + uint8_t getSupportTouchPoint(); + + bool getResolution(int16_t *x, int16_t *y); + + void setHomeButtonCallback(home_button_callback_t cb, void *user_data); + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb); + +private: + bool initImpl(); + int getReadMaskImpl(); +protected: + TouchData report; + +}; + + + + + + + + + + diff --git a/components/SensorLib/src/touch/TouchClassCST816.cpp b/components/SensorLib/src/touch/TouchClassCST816.cpp new file mode 100644 index 0000000..2d7708f --- /dev/null +++ b/components/SensorLib/src/touch/TouchClassCST816.cpp @@ -0,0 +1,328 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchClassCST816.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-06 + */ +#include "TouchClassCST816.h" + +#define CST8xx_REG_STATUS (0x00) +#define CST8xx_REG_XPOS_HIGH (0x03) +#define CST8xx_REG_XPOS_LOW (0x04) +#define CST8xx_REG_YPOS_HIGH (0x05) +#define CST8xx_REG_YPOS_LOW (0x06) +#define CST8xx_REG_DIS_AUTOSLEEP (0xFE) +#define CST8xx_REG_CHIP_ID (0xA7) +#define CST8xx_REG_FW_VERSION (0xA9) +#define CST8xx_REG_SLEEP (0xE5) + +#define CST816S_CHIP_ID (0xB4) +#define CST816T_CHIP_ID (0xB5) +#define CST716_CHIP_ID (0x20) +#define CST820_CHIP_ID (0xB7) +#define CST816D_CHIP_ID (0xB6) + +#if defined(ARDUINO) +TouchClassCST816::TouchClassCST816(): + __center_btn_x(0), + __center_btn_y(0) +{ +} + +bool TouchClassCST816::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl) +{ + return SensorCommon::begin(wire, address, sda, scl); +} + +#elif defined(ESP_PLATFORM) + +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) +bool TouchClassCST816::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) +{ + return SensorCommon::begin(i2c_dev_bus_handle, addr); +} +#else +bool TouchClassCST816::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) +{ + return SensorCommon::begin(port_num, addr, sda, scl); +} + +#endif //ESP_IDF_VERSION +#endif //ARDUINO + +bool TouchClassCST816::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) +{ + return SensorCommon::begin(addr, readRegCallback, writeRegCallback); +} + +void TouchClassCST816::reset() +{ + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + this->setGpioLevel(__rst, LOW); + delay(30); + this->setGpioLevel(__rst, HIGH); + delay(50); + } +} + +uint8_t TouchClassCST816::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point) +{ + uint8_t buffer[13]; + if (readRegister(CST8xx_REG_STATUS, buffer, 13) == DEV_WIRE_ERR) { + return 0; + } + + if (!buffer[2] || !x_array || !y_array || !get_point) { + return 0; + } + + // Some CST816T will return all 0xFF after turning off automatic sleep. + if (buffer[2] == 0xFF) { + return 0; + } + + // Only suitable for AMOLED 1.91 inch + // RAW:00,00,01,80,78,02,58,00,00,FF,FF,FF,FF, + // if (buffer[2] == 0x01 && buffer[3] == 0x80 && buffer[4] == 0x78 && buffer[5] == 0x02 && buffer[6] == 0x58) { + // if (__homeButtonCb) { + // __homeButtonCb(__userData); + // } + // return 0; + // } + + uint8_t point = buffer[2] & 0x0F; + + // CST816 only supports single touch + if (point > 1) { + return 0; + } + +#ifdef LOG_PORT + LOG_PORT.print("RAW:"); + for (int i = 0; i < 13; ++i) { + LOG_PORT.printf("%02X,", buffer[i]); + } + LOG_PORT.println(); +#endif + + int16_t tmp_x, tmp_y; + + tmp_x = ((buffer[CST8xx_REG_XPOS_HIGH] & 0x0F) << 8 | buffer[CST8xx_REG_XPOS_LOW]); + tmp_y = ((buffer[CST8xx_REG_YPOS_HIGH] & 0x0F) << 8 | buffer[CST8xx_REG_YPOS_LOW]); + + // Depends on touch screen firmware + if (tmp_x == __center_btn_x && tmp_y == __center_btn_y && __homeButtonCb) { + __homeButtonCb(__userData); + return 0; + } + + // if (get_point == 2) { + // x_array[1] = ((buffer[((uint8_t)0x09)] & 0x0F) << 8 | buffer[((uint8_t)0x10)]); + // y_array[1] = ((buffer[((uint8_t)0x11)] & 0x0F) << 8 | buffer[((uint8_t)0x12)]); + // } + + x_array[0] = tmp_x; + y_array[0] = tmp_y; + +#ifdef LOG_PORT + for (int i = 0; i < point; i++) { + LOG_PORT.printf("[%d] --> X:%d Y:%d \n", i, x_array[i], y_array[i]); + } +#endif + updateXY(point, x_array, y_array); + + return point; +} + +bool TouchClassCST816::isPressed() +{ + static uint32_t lastPulse = 0; + if (__irq != SENSOR_PIN_NONE) { + int val = this->getGpioLevel(__irq) == LOW; + if (val) { + //Filter low levels with intervals greater than 1000ms + val = (millis() - lastPulse > 1000) ? false : true; + lastPulse = millis(); + return val; + } + return false; + } + return getPoint(NULL, NULL, 1); +} + + +const char *TouchClassCST816::getModelName() +{ + switch (__chipID) { + case CST816S_CHIP_ID: + return "CST816S"; + case CST816T_CHIP_ID: + return "CST816T"; + case CST716_CHIP_ID: + return "CST716"; + case CST820_CHIP_ID: + return "CST820"; + case CST816D_CHIP_ID: + return "CST816D"; + default: + break; + } + return "UNKONW"; +} + +void TouchClassCST816::sleep() +{ + writeRegister(CST8xx_REG_SLEEP, 0x03); +#ifdef ESP32 + if (__irq != SENSOR_PIN_NONE) { + this->setGpioMode(__irq, OPEN_DRAIN); + } + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OPEN_DRAIN); + } +#endif +} + +void TouchClassCST816::wakeup() +{ + reset(); +} + +void TouchClassCST816::idle() +{ + +} + +uint8_t TouchClassCST816::getSupportTouchPoint() +{ + return 1; +} + +bool TouchClassCST816::getResolution(int16_t *x, int16_t *y) +{ + return false; +} + +void TouchClassCST816::setHomeButtonCallback(home_button_callback_t cb, void *user_data) +{ + __homeButtonCb = cb; + __userData = user_data; +} + +void TouchClassCST816::setCenterButtonCoordinate(int16_t x, int16_t y) +{ + __center_btn_x = x; + __center_btn_y = y; +} + + +void TouchClassCST816::disableAutoSleep() +{ + switch (__chipID) { + case CST816S_CHIP_ID: + case CST816T_CHIP_ID: + case CST820_CHIP_ID: + case CST816D_CHIP_ID: + reset(); + delay(50); + writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x01); + break; + case CST716_CHIP_ID: + default: + break; + } +} + +void TouchClassCST816::enableAutoSleep() +{ + switch (__chipID) { + case CST816S_CHIP_ID: + case CST816T_CHIP_ID: + case CST820_CHIP_ID: + case CST816D_CHIP_ID: + reset(); + delay(50); + writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x00); + break; + case CST716_CHIP_ID: + default: + break; + } +} + +void TouchClassCST816::setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb) +{ + SensorCommon::setGpioModeCallback(mode_cb); + SensorCommon::setGpioWriteCallback(write_cb); + SensorCommon::setGpioReadCallback(read_cb); +} + +bool TouchClassCST816::initImpl() +{ + + if (__rst != SENSOR_PIN_NONE) { + this->setGpioMode(__rst, OUTPUT); + } + + reset(); + + int chip_id = readRegister(CST8xx_REG_CHIP_ID); + log_i("Chip ID:0x%x\n", chip_id); + + int version = readRegister(CST8xx_REG_FW_VERSION); + log_i("Version :0x%x\n", version); + + // CST716 : 0x20 + // CST816S : 0xB4 + // CST816T : 0xB5 + // CST816D : 0xB6 + // CST226SE : A7 = 0X20 + if (chip_id != CST816S_CHIP_ID && + chip_id != CST816T_CHIP_ID && + chip_id != CST820_CHIP_ID && + chip_id != CST816D_CHIP_ID && + (chip_id != CST716_CHIP_ID || version == 0)) { + return false; + } + + __chipID = chip_id; + + log_i("Touch type:%s\n", getModelName()); + + return true; +} + +int TouchClassCST816::getReadMaskImpl() +{ + return -1; +} + + + + + diff --git a/components/SensorLib/src/touch/TouchClassCST816.h b/components/SensorLib/src/touch/TouchClassCST816.h new file mode 100644 index 0000000..e261a1a --- /dev/null +++ b/components/SensorLib/src/touch/TouchClassCST816.h @@ -0,0 +1,102 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2023 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file TouchClassCST816.h + * @author Lewis He (lewishe@outlook.com) + * @date 2023-10-06 + */ +#pragma once + +#include "../TouchDrvInterface.hpp" +#include "../SensorCommon.tpp" +#include "../SensorLib.h" + +class TouchClassCST816 : public TouchDrvInterface, + public SensorCommon +{ + friend class SensorCommon; + +public: + +#if defined(ARDUINO) + TouchClassCST816(); + + bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl); + +#elif defined(ESP_PLATFORM) +#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)) + bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr); +#else + bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl); +#endif //ESP_IDF_VERSION +#endif + + bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback); + + + void reset(); + + uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point); + + bool isPressed(); + + const char *getModelName(); + + void sleep(); + + void wakeup(); + + void idle(); + + uint8_t getSupportTouchPoint(); + + bool getResolution(int16_t *x, int16_t *y); + + void setCenterButtonCoordinate(int16_t x, int16_t y); + + void setHomeButtonCallback(home_button_callback_t cb, void *user_data); + + void disableAutoSleep(); + + void enableAutoSleep(); + + void setGpioCallback(gpio_mode_fptr_t mode_cb, + gpio_write_fptr_t write_cb, + gpio_read_fptr_t read_cb); + +private: + bool initImpl(); + int getReadMaskImpl(); + +protected: + int16_t __center_btn_x; + int16_t __center_btn_y; +}; + + + + + + + diff --git a/components/thorvg-main/.gitattributes b/components/thorvg-main/.gitattributes new file mode 100644 index 0000000..b791d92 --- /dev/null +++ b/components/thorvg-main/.gitattributes @@ -0,0 +1,8 @@ +# Normalize EOL for all files that Git considers text files +* text=auto eol=lf + +# Except for bat files, which are Windows only files +*.bat eol=crlf + +# And some test files where the EOL matters +*.json -text diff --git a/components/thorvg-main/.github/FUNDING.yml b/components/thorvg-main/.github/FUNDING.yml new file mode 100644 index 0000000..6b1adb8 --- /dev/null +++ b/components/thorvg-main/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: thorvg +open_collective: thorvg \ No newline at end of file diff --git a/components/thorvg-main/.github/labeler.yml b/components/thorvg-main/.github/labeler.yml new file mode 100644 index 0000000..b615a1c --- /dev/null +++ b/components/thorvg-main/.github/labeler.yml @@ -0,0 +1,55 @@ +"APIs": + - inc/**/* + +"binding": + - src/bindings/**/* + +"documentation": + - README.md + +"font": + - src/loaders/ttf/**/* + +"image": + - src/loaders/jpg/**/* + - src/loaders/external_jpg/**/* + - src/loaders/png/**/* + - src/loaders/external_png/**/* + - src/loaders/webp/**/* + - src/loaders/external_webp/**/* + - src/loaders/raw/**/* + - src/savers/gif/**/* + +"svg": + - src/loaders/svg/**/* + +"tvg": + - src/loaders/tvg/**/* + +"test": + - test/**/* + +"tools": + - tools/**/* + +"infrastructure": + - .github/**/* + - meson.build + - meson_option.txt + +"lottie": + - src/loaders/lottie/**/* + +"cpu": + - src/renderer/sw_engine/**/* + +"webgpu": + - src/renderer/wg_engine/**/* + +"gl": + - src/renderer/gl_engine/**/* + +"renderer": + - src/renderer/* + - src/common/**/* + diff --git a/components/thorvg-main/.github/workflows/build_android.yml b/components/thorvg-main/.github/workflows/build_android.yml new file mode 100644 index 0000000..b1b17c6 --- /dev/null +++ b/components/thorvg-main/.github/workflows/build_android.yml @@ -0,0 +1,73 @@ +name: Android + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + build_x86_64: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: nttld/setup-ndk@v1.3.1 + id: setup-ndk + with: + submodules: true + ndk-version: r21e + local-cache: true + + - name: Install Packages + run: | + sudo apt-get update + sudo apt-get install meson ninja-build libgles-dev + + - name: Build + env: + NDK: ${{ steps.setup-ndk.outputs.ndk-path }} + API: 21 + run: | + sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_x86_64.txt > /tmp/android_cross.txt + meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false -Dextra="lottie_exp" --cross-file /tmp/android_cross.txt + sudo ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_x86_64 + path: build/src/libthorvg* + + build_aarch64: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: nttld/setup-ndk@v1.3.1 + id: setup-ndk + with: + submodules: true + ndk-version: r21e + local-cache: true + + - name: Install Packages + run: | + sudo apt-get update + sudo apt-get install meson ninja-build libgles-dev + + - name: Build + env: + NDK: ${{ steps.setup-ndk.outputs.ndk-path }} + API: 21 + run: | + sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_aarch64.txt > /tmp/android_cross.txt + meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false -Dextra="lottie_exp" --cross-file /tmp/android_cross.txt + sudo ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_aarch64 + path: build/src/libthorvg* diff --git a/components/thorvg-main/.github/workflows/build_ios.yml b/components/thorvg-main/.github/workflows/build_ios.yml new file mode 100644 index 0000000..83d6146 --- /dev/null +++ b/components/thorvg-main/.github/workflows/build_ios.yml @@ -0,0 +1,100 @@ +name: iOS + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + build_simulator_x86_64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Unbreak Python in GitHub Actions + run: | + find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete + sudo rm -rf /Library/Frameworks/Python.framework/ + brew install --force python3 && brew unlink python3 && brew link --overwrite python3 + + - name: Install Packages + run: | + export HOMEBREW_NO_INSTALL_FROM_API=1 + brew update + brew install meson + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_simulator_x86_64.txt + ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_simulator_x86_64 + path: build/src/libthorvg* + + build_simulator_arm64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Unbreak Python in GitHub Actions + run: | + find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete + sudo rm -rf /Library/Frameworks/Python.framework/ + brew install --force python3 && brew unlink python3 && brew link --overwrite python3 + + - name: Install Packages + run: | + export HOMEBREW_NO_INSTALL_FROM_API=1 + brew update + brew install meson + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_simulator_arm64.txt + ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_simulator_arm64 + path: build/src/libthorvg* + + build_arm64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Unbreak Python in GitHub Actions + run: | + find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete + sudo rm -rf /Library/Frameworks/Python.framework/ + brew install --force python3 && brew unlink python3 && brew link --overwrite python3 + + - name: Install Packages + run: | + export HOMEBREW_NO_INSTALL_FROM_API=1 + brew update + brew install meson + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_arm64.txt + ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_arm64 + path: build/src/libthorvg* \ No newline at end of file diff --git a/components/thorvg-main/.github/workflows/build_macos.yml b/components/thorvg-main/.github/workflows/build_macos.yml new file mode 100644 index 0000000..648cb2a --- /dev/null +++ b/components/thorvg-main/.github/workflows/build_macos.yml @@ -0,0 +1,88 @@ +name: macOS + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Unbreak Python in GitHub Actions + run: | + find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete + sudo rm -rf /Library/Frameworks/Python.framework/ + brew install --force python3 && brew unlink python3 && brew link --overwrite python3 + + - name: Install Packages + run: | + export HOMEBREW_NO_INSTALL_FROM_API=1 + brew update + brew install meson sdl2 + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all -Dextra="lottie_exp" + ninja -C build install + + compact_test: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Unbreak Python in GitHub Actions + run: | + find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete + sudo rm -rf /Library/Frameworks/Python.framework/ + brew install --force python3 && brew unlink python3 && brew link --overwrite python3 + + - name: Install Packages + run: | + brew update + brew install meson + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false -Dextra="lottie_exp" + ninja -C build install + + unit_test: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Unbreak Python in GitHub Actions + run: | + find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete + sudo rm -rf /Library/Frameworks/Python.framework/ + brew install --force python3 && brew unlink python3 && brew link --overwrite python3 + + - name: Install Packages + run: | + brew update + brew install meson + + - name: Build + run: | + meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true -Dextra="lottie_exp" --errorlogs + ninja -C build install test + + - uses: actions/upload-artifact@v4 + with: + name: UnitTestReport + path: build/meson-logs/testlog.txt diff --git a/components/thorvg-main/.github/workflows/build_ubuntu.yml b/components/thorvg-main/.github/workflows/build_ubuntu.yml new file mode 100644 index 0000000..1a76fcb --- /dev/null +++ b/components/thorvg-main/.github/workflows/build_ubuntu.yml @@ -0,0 +1,92 @@ +name: Ubuntu + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install Packages + run: | + sudo apt-get update + sudo apt-get install meson ninja-build libturbojpeg0-dev libpng-dev libwebp-dev libgles-dev libsdl2-dev + + - name: Build + run: | + meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all + sudo ninja -C build install + + compact_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install Packages + run: | + sudo apt-get update + sudo apt-get install meson ninja-build libgles-dev + + - name: Build + run: | + meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false + sudo ninja -C build install + + unit_test: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install Packages + run: | + sudo apt-get update + sudo apt-get install meson ninja-build libgtest-dev libasan5 valgrind curl jq software-properties-common libturbojpeg0-dev libpng-dev libwebp-dev libgles-dev + + - name: Build + run: | + meson setup build -Dloaders="all" -Dengines="sw, gl" -Dsavers="all" -Dbindings="capi" -Dtests=true --errorlogs + sudo ninja -C build install test + + - uses: actions/upload-artifact@v4 + with: + name: UnitTestReport + path: build/meson-logs/testlog.txt + + - name: Run memcheck Script(valgrind) + run: | + export PATH=$PATH:~/.local/bin/ + chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh" + "${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build & Run memcheck Script(ASAN) + run: | + sudo rm -rf ./build + meson setup build -Db_sanitize="address,undefined" -Dloaders="all" -Dsavers="all" -Dtests="true" -Dbindings="capi" + sudo ninja -C build install + export PATH=$PATH:~/.local/bin/ + chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_asan.sh" + "${GITHUB_WORKSPACE}/.github/workflows/memcheck_asan.sh" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/components/thorvg-main/.github/workflows/build_windows.yml b/components/thorvg-main/.github/workflows/build_windows.yml new file mode 100644 index 0000000..12ba683 --- /dev/null +++ b/components/thorvg-main/.github/workflows/build_windows.yml @@ -0,0 +1,77 @@ +name: Windows + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Install Packages + run: | + pip install meson ninja + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all + where link + ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_windows + path: build/src/thorvg* + + compact_test: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Install Packages + run: | + pip install meson ninja + + - name: Build + run: | + meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false + where link + ninja -C build install + + - uses: actions/upload-artifact@v4 + with: + name: result_windows_static + path: build/src/thorvg* + + unit_test: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Install Packages + run: | + pip install meson ninja + + - name: Build + run: | + meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true --errorlogs + where link + ninja -C build install test + + - uses: actions/upload-artifact@v4 + with: + name: UnitTestReport + path: build/meson-logs/testlog.txt + diff --git a/components/thorvg-main/.github/workflows/memcheck_asan.sh b/components/thorvg-main/.github/workflows/memcheck_asan.sh new file mode 100644 index 0000000..6999669 --- /dev/null +++ b/components/thorvg-main/.github/workflows/memcheck_asan.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +if [[ -z "$GITHUB_TOKEN" ]]; then + echo "The GITHUB_TOKEN is required." + exit 1 +fi + +if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then + echo "Run Address Sanitizer" + echo "meson -Db_sanitize=\"address,undefined\" -Dloaders=\"all\" -Dsavers=\"all\" -Dtests=\"true\" -Dbindings=\"capi\" . build" + pwd + cd ${GITHUB_WORKSPACE}/build/test + ./tvgUnitTests > memcheck_asan.txt 2>&1 + + + PAYLOAD_MEMCHECK=`cat memcheck_asan.txt` + COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url) + + echo $COMMENTS_URL + echo "MEMCHECK errors:" + echo $PAYLOAD_MEMCHECK + + if [[ $PAYLOAD_MEMCHECK == *"runtime error:"* || $PAYLOAD_MEMCHECK == *"ERROR: AddressSanitizer:"* ]]; then + OUTPUT+=$'\n**MEMCHECK(ASAN) RESULT**:\n' + + OUTPUT+=$'\n`meson -Db_sanitize="address,undefined" -Dloaders="all" -Dsavers="all" -Dtests="true" -Dbindings="capi" . build`\n' + OUTPUT+=$'\n```\n' + OUTPUT+="$PAYLOAD_MEMCHECK" + OUTPUT+=$'\n```\n' + + ( + echo '
ASAN output' + echo + echo "$OUTPUT" + echo + echo '
' + ) >> "$GITHUB_STEP_SUMMARY" + + PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body') + + curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL" + fi +fi + diff --git a/components/thorvg-main/.github/workflows/memcheck_valgrind.sh b/components/thorvg-main/.github/workflows/memcheck_valgrind.sh new file mode 100644 index 0000000..716abd5 --- /dev/null +++ b/components/thorvg-main/.github/workflows/memcheck_valgrind.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +if [[ -z "$GITHUB_TOKEN" ]]; then + echo "The GITHUB_TOKEN is required." + exit 1 +fi + +if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then + echo "Run Valgrind" + echo "valgrind --leak-check=yes ./tvgUnitTests" + cd ./build/test + + valgrind --leak-check=yes ./tvgUnitTests > memcheck_valgrind.txt 2>&1 + + + PAYLOAD_MEMCHECK=`cat memcheck_valgrind.txt` + COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url) + + echo $COMMENTS_URL + echo "MEMCHECK errors:" + echo $PAYLOAD_MEMCHECK + + DEFINITELY_LOST_NUMBER=$(echo "$PAYLOAD_MEMCHECK" | grep -oP 'definitely lost:\s*\K[0-9]+(?=\s*bytes in)') + ERROR_NUMBER=$(echo "$PAYLOAD_MEMCHECK" | grep -oP 'ERROR SUMMARY:\s*\K[0-9]+(?=\s*errors)') + if [[ $ERROR_NUMBER != 0 || $DEFINITELY_LOST_NUMBER != 0 || $PAYLOAD_MEMCHECK == *"Invalid read "* || $PAYLOAD_MEMCHECK == *"Invalid write "* ]]; then + OUTPUT+=$'\n**MEMCHECK(VALGRIND) RESULT**:\n' + OUTPUT+=$'\n`valgrind --leak-check=yes ./tvgUnitTests`\n' + OUTPUT+=$'\n```\n' + OUTPUT+="$PAYLOAD_MEMCHECK" + OUTPUT+=$'\n```\n' + + ( + echo '
Valgrind output' + echo + echo "$OUTPUT" + echo + echo '
' + ) >> "$GITHUB_STEP_SUMMARY" + + PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body') + + curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL" + fi +fi + diff --git a/components/thorvg-main/.github/workflows/pull_request_label.yml b/components/thorvg-main/.github/workflows/pull_request_label.yml new file mode 100644 index 0000000..af0a025 --- /dev/null +++ b/components/thorvg-main/.github/workflows/pull_request_label.yml @@ -0,0 +1,13 @@ +name: Pull Request Labeler + +on: [pull_request_target] + +jobs: + triage: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v4 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + sync-labels: true + diff --git a/components/thorvg-main/.github/workflows/regression.yml b/components/thorvg-main/.github/workflows/regression.yml new file mode 100644 index 0000000..57ea0f1 --- /dev/null +++ b/components/thorvg-main/.github/workflows/regression.yml @@ -0,0 +1,192 @@ +name: Regression + +# on: [push, pull_request] - enable when testing +on: + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install things + run: | + sudo apt-get update + sudo apt-get install -y meson wget2 librsvg2-dev librsvg2-bin ninja-build git gcc-multilib g++-multilib earlyoom + + - name: Compile Thorvg PR + run: | + meson . build -Dtools=svg2png,lottie2gif -Dsavers=gif -Db_sanitize=address,undefined + sudo ninja -C build install + + - name: Compile Thorvg Develop + run: | + git clone https://github.com/thorvg/thorvg.git thorvg_develop + cd thorvg_develop + meson . build -Dtools=svg2png + sudo ninja -C build install + cd .. + + - name: Download SVG Regression finder and setup settings + run: | + wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.4.0/svg_tester + chmod +x ./svg_tester + + - name: Prepare valid files to test + run: | + wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgValidFiles.zip -O files.zip + unzip -q files.zip + rm files.zip + wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgNotValidFiles.zip -O files.zip + unzip -q files.zip + rm files.zip + mv ThorvgValidFiles FilesToTest + find ThorvgNotValidFiles -type f -exec mv {} FilesToTest \; + rmdir ThorvgNotValidFiles + + - name: Setup settings for crash/leak/timeout tests + run: | + mv test/regression/settings_crash_leak.toml settings.toml + + - name: Run regression finder tests + run: | + ./svg_tester 2>&1 | tee result_crashes.txt + + - name: Setup settings for comparison tests + run: | + mv test/regression/settings_comparison.toml settings.toml + + - name: Store Crashing/Leaking/Timing out Images + uses: actions/upload-artifact@v4 + with: + name: crashing-leaking-timeouting-images + path: BrokenFILES + if-no-files-found: ignore + + - name: Clean Data + run: | + rm -rf BrokenSVG || true + rm -rf FilesToTest || true + rm -rf ProblematicSVG || true + rm -rf IgnoredSVG || true + rm -rf BrokenFILES || true + + # Test valid files + - name: Prepare valid files to test + run: | + wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgValidFiles.zip -O files.zip + unzip -q files.zip + rm files.zip + mv ThorvgValidFiles FilesToTest + + - name: Run regression finder tests + run: | + ./svg_tester 2>&1 | tee result_valid_files.txt + + - name: Store Broken Images for valid inputs + uses: actions/upload-artifact@v4 + with: + name: differences-in-valid-files + path: BrokenSVG + if-no-files-found: ignore + + - name: Store Problematic Images for valid inputs + uses: actions/upload-artifact@v4 + with: + name: problematic-images-in-valid-files + path: ProblematicSVG + if-no-files-found: ignore + + - name: Clean Data + run: | + rm -rf BrokenSVG || true + rm -rf FilesToTest || true + rm -rf ProblematicSVG || true + rm -rf IgnoredSVG || true + rm -rf BrokenFILES || true + + # Test files that may not work currently good with Thorvg, errors from this are not critical + # it is possible that this will find also some improvements + - name: Prepare not valid to test + run: | + wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgNotValidFiles.zip -O files.zip + unzip -q files.zip + rm files.zip + mv ThorvgNotValidFiles FilesToTest + + - name: Run invalid files tests + run: | + ./svg_tester 2>&1 | tee result_not_valid_files.txt + + - name: Store Broken Images for not valid inputs + uses: actions/upload-artifact@v4 + with: + name: differences-in-not-valid-files + path: BrokenSVG + if-no-files-found: ignore + + - name: Store Problematic Images for not valid inputs + uses: actions/upload-artifact@v4 + with: + name: problematic-images-in-not-valid-files + path: ProblematicSVG + if-no-files-found: ignore + + - name: Clean Data + run: | + rm -rf BrokenSVG || true + rm -rf FilesToTest || true + rm -rf ProblematicSVG || true + rm -rf IgnoredSVG || true + rm -rf BrokenFILES || true + + - name: Test png reproducibility + run: | + wget -q https://github.com/thorvg/thorvg/files/11356766/AA_5.svg.zip -O files.zip + unzip -q files.zip + rm files.zip + cp test/regression/check_same_image_size.py check_same_image_size.py + # Forces to run tasks on different threads if possible, which should help find problem with data races + taskset -c 0-15 python3 check_same_image_size.py AA_5.svg ./build/src/tools/svg2png/tvg-svg2png 100 500 2>&1 | tee result_image_size.txt + + - name: Check results + run: | + export PATH=$PATH:~/.local/bin/ + python3 "${GITHUB_WORKSPACE}/.github/workflows/regression_check.py" + + if [[ -f "fail_ci.txt" ]]; then + ( + echo '```' + cat "fail_ci.txt" + echo '```' + ) >> "$GITHUB_STEP_SUMMARY" + fi + + - name: Find Comment + uses: peter-evans/find-comment@v3 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Regression report + +# TODO - not works +# - name: Create or update comment +# uses: peter-evans/create-or-update-comment@v4 +# with: +# comment-id: ${{ steps.fc.outputs.comment-id }} +# issue-number: ${{ github.event.pull_request.number }} +# body-path: 'comment.txt' +# edit-mode: replace + + - name: Fail CI if regression found + run: | + if [[ -f "fail_ci.txt" ]]; then + echo "Check Check results section for more details which tests failed" + exit 1 + fi diff --git a/components/thorvg-main/.github/workflows/regression_check.py b/components/thorvg-main/.github/workflows/regression_check.py new file mode 100644 index 0000000..1e12a06 --- /dev/null +++ b/components/thorvg-main/.github/workflows/regression_check.py @@ -0,0 +1,67 @@ +from typing import Optional + +POSSIBLE_PROBLEM = "POSSIBLE_PROBLEM - " + + +def check_file(file_name: str) -> Optional[str]: + with open(file_name, "r") as file: + print(f"Checking file {file_name}") + for line in file: + line = line.strip() + if line.startswith(POSSIBLE_PROBLEM): + return line[len(POSSIBLE_PROBLEM) :] + return None + + +if __name__ == "__main__": + data_to_check = [ + ( + "result_valid_files.txt", + True, + "Found difference in converting images that properly converted in develop branch.", + ), + ( + "result_not_valid_files.txt", + False, + "Found differences in converting images that were not properly converted in develop branch(this may be improvement).", + ), + ( + "result_image_size.txt", + True, + "Generated png have different size in each run.", + ), + ( + "result_crashes.txt", + True, + "Found crashes in crashes during when converting svg to png.", + ), + ] + + fail_ci = False + comment = "" + for file_name, fail_ci_when_triggered, new_comment in data_to_check: + possible_problem = check_file(file_name) + if possible_problem is not None: + print(f">>>>> Found changes in {file_name} (look at CI steps from above)") + print(f"Comment: {new_comment}") + + if fail_ci_when_triggered: + fail_ci = True + comment += new_comment + "\n" + + to_write = "Regression report:\n" + + if len(comment) > 0: + to_write += comment + to_write += "\nCheck CI for artifacts/logs for more details." + else: + to_write += "Not found any changes(both improvements and regressions) in this PR with test data." + + print("\n\n" + to_write + "\n\n") + + with open("comment.txt", "w") as file: + file.write(to_write) + + if fail_ci: + with open("fail_ci.txt", "w") as file: + file.write("Fail") diff --git a/components/thorvg-main/.github/workflows/release.yml b/components/thorvg-main/.github/workflows/release.yml new file mode 100644 index 0000000..860ddad --- /dev/null +++ b/components/thorvg-main/.github/workflows/release.yml @@ -0,0 +1,20 @@ +name: Release +on: + release: + types: [published] +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: "thorvg" + - name: Create source archive + run: | + rm -rf ./thorvg/.git* + tar -I "gzip -9" -cf thorvg.tar.gz thorvg + - name: Upload to release + uses: softprops/action-gh-release@v2 + with: + files: thorvg.tar.gz diff --git a/components/thorvg-main/.gitignore b/components/thorvg-main/.gitignore new file mode 100644 index 0000000..d297d9f --- /dev/null +++ b/components/thorvg-main/.gitignore @@ -0,0 +1,10 @@ +build +builddir +doc +.vscode +.idea +*.swp +*.tvg +*.tmp +*.code-workspace +.DS_Store diff --git a/components/thorvg-main/CODEOWNERS b/components/thorvg-main/CODEOWNERS new file mode 100644 index 0000000..1676374 --- /dev/null +++ b/components/thorvg-main/CODEOWNERS @@ -0,0 +1,7 @@ +# ThorVG uses the CODEOWNERS file to automatically assign designated reviewers within the GitHub system. +# Being listed as a code owner does not necessarily indicate copyright ownership of the code. + +* @hermet +/src/renderer/gl_engine @wenjieshen @SergeyLebedkin +/src/renderer/wg_engine @SergeyLebedkin +/src/loaders/svg @JSUYA \ No newline at end of file diff --git a/components/thorvg-main/CODE_OF_CONDUCT.md b/components/thorvg-main/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..b0cc41b --- /dev/null +++ b/components/thorvg-main/CODE_OF_CONDUCT.md @@ -0,0 +1,89 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We pledge to make our community welcoming, safe, and equitable for all. + +We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant. + + +## Encouraged Behaviors + +While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language. + +With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including: + +1. Respecting the **purpose of our community**, our activities, and our ways of gathering. +2. Engaging **kindly and honestly** with others. +3. Respecting **different viewpoints** and experiences. +4. **Taking responsibility** for our actions and contributions. +5. Gracefully giving and accepting **constructive feedback**. +6. Committing to **repairing harm** when it occurs. +7. Behaving in other ways that promote and sustain the **well-being of our community**. + + +## Restricted Behaviors + +We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct. + +1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop. +2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people. +3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits. +4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community. +5. **Violating confidentiality.** Sharing or acting on someone's personal or private information without their permission. +6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group. +7. Behaving in other ways that **threaten the well-being** of our community. + +### Other Restrictions + +1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions. +2. **Failing to credit sources.** Not properly crediting the sources of content you contribute. +3. **Promotional materials.** Sharing unsolicited commercial or marketing content unrelated to ThorVG or the topic of discussion. +4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors. + + +## Reporting an Issue + +Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm. + +When an incident does occur, it is important to report it promptly. To report a violation, please contact **thorvg@thorvg.org**. + +ThorVG Maintainers take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. ThorVG Maintainers will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution. + + +## Addressing and Repairing Harm + +The following enforcement guidelines outline how ThorVG Maintainers may respond to reported violations of this Code of Conduct. The response may vary depending on the severity and impact of the situation. + +If an investigation by the ThorVG Maintainers finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped. + +1) Warning + 1) Event: A violation involving a single incident or series of incidents. + 2) Consequence: A private, written warning from the ThorVG Maintainers. + 3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations. +2) Temporarily Limited Activities + 1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation. + 2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members. + 3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over. +3) Temporary Suspension + 1) Event: A pattern of repeated violation which the ThorVG Maintainers have tried to address with warnings, or a single serious violation. + 2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions. + 3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted. +4) Permanent Ban + 1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the ThorVG Maintainers determine there is no way to keep the community safe with this person as a member. + 2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior. + 3) Repair: There is no possible repair in cases of this severity. + +This enforcement ladder is intended as a guideline. It does not limit the ability of ThorVG Maintainers to use their discretion and judgment, in keeping with the best interests of our community. + + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/). + +This Code of Conduct is distributed under the Creative Commons Attribution 4.0 International (CC-BY-4.0) license. diff --git a/components/thorvg-main/CONTRIBUTING.md b/components/thorvg-main/CONTRIBUTING.md new file mode 100644 index 0000000..81faed7 --- /dev/null +++ b/components/thorvg-main/CONTRIBUTING.md @@ -0,0 +1,97 @@ +We always appreciate your contribution. ThorVG doesn't expect patches to be perfect; instead, we value contributions that make ThorVG better than before. This page outlines the ThorVG contribution format.
+
+ +## Coding Convention +Please read the [ThorVG Coding Convention Guidance](https://github.com/thorvg/thorvg/wiki/Coding-Convention) before writing your code. + +## Reviewers +ThorVG uses GitHub infrastructure to automatically assign code reviewers for your changes. To see the full list of reviewers, please refer to the [CODEOWNERS](https://github.com/thorvg/thorvg/blob/main/CODEOWNERS) file. +
+ +## Self Test & Verification +After updating the ThorVG code, please ensure your changes don't break the library. We recommend conducting unit tests. You can easily run them using the following build commands: +
+` +$meson setup build -Dtests=true -Dloaders="all" -Dsavers="all" -Dbindings="capi" -Dtools="all" -Dlog=true +` +
+` +$ninja -C build test +` +
+
+Please make it sure running all tests and no any fail case.
+
+Expected Fail: 0
+Fail: 0
+Unexpected Pass: 0
+Skipped: 0
+Timeout: 0
+ +## Commit Message +[Module][Feature]: [Title] + +[Description] + +- [Module] refers to the sub-module primarily affected by your change. Most of the time, this indicates the name of a sub-folder. +This also suggests who might need to review your patch. +If your change doesn't belong to any sub-modules, you can either replace this with a suitable name or skip it. +The name should be written entirely in lowercase letters. + - e.g., build, doc, infra, common, sw_engine, gl_engine, svg_loader, wasm, svg2png... + +- [Feature] indicates the primary function or feature you modified. Typically, this represents a class or file name. +This is an optional. + - e.g., canvas, shape, paint, scene, picture, task-scheduler, loader, builder, ... + +- [Title] provides a brief description of your change and should be encapsulated in a single sentence. + - e.g., "Fixed a typo." + - e.g., "Addressed compile warnings." + - e.g., "Refactored code." + - e.g., "Resolved a rendering bug causing overlapped shapes to display improperly." + +- [Description] doesn't have a strict format. However, it should detail what you accomplished in this patch as comprehensively as possible. + + If you've resolved bugs, include the following details: + - The type of bug. + - Steps to reproduce it. + - The root cause. + - The solution applied. + + For new features or functions, cover: + - The nature of the feature. + - Full API specifications (if there are any API additions). + - Its necessity or rationale. + - Any conditions or restrictions. + - Relevant examples or references. + + Finally, include any related issue ticket numbers in this section, if applicable. + + +Here's a sample commit message for clarity: + +- renderer/paint: Introduced path clipping feature + + We've added a new method, Paint::composite(), to support various composite behaviors. This allows paints to interact with other paint instances based on the chosen composite method. Initially, we're introducing the "ClipPath" method for path-based clipping. + + targetPaint->composite(srcPaint, CompositeMethod::ClipPath); + + Note: If the source paint lacks path information, clipping may not produce the desired effect. + + API Additions: + enum CompositeMethod {None = 0, ClipPath}; + Result Paint::composite(std::unique_ptr target, CompositeMethod method) const noexcept; + + Examples: Introduced ClipPath + + References: [Provide any relevant links, such as screenshots.] + + Issues: [Link to the issue] + +## Pull Request + +Once you've submitted a pull request (PR), please ensure the following checklist is completed: +- Reviewers: Check the Reviewers List. +- Assignees: You should be assigned. +- Labels: Mark the appropriate Patch Purpose. +- Automated Integration Test: All must pass. +

diff --git a/components/thorvg-main/CONTRIBUTORS.md b/components/thorvg-main/CONTRIBUTORS.md new file mode 100644 index 0000000..851ff86 --- /dev/null +++ b/components/thorvg-main/CONTRIBUTORS.md @@ -0,0 +1,59 @@ +## Project Lead +- Hermet Park + +## Core Contributors +- Pranay Samanta +- Junsu Choi +- Mira Grudzinska +- Ruiwen Tang +- Sergii Liebodkin +- Jinny You +- Jay WenJie + +## Contributors +- Prudhvi Raj Vasireddi +- Mateusz Palkowski +- Subhransu Mohanty +- Michal Szczecinski +- Shinwoo Kim +- Piotr Kalota +- Vincent Torri +- Pankaj Kumar +- Patryk Kaczmarek +- Michal Maciola +- Peter Vullings +- K. S. Ernest (iFire) Lee +- Rémi Verschelde +- Martin Liska +- Vincenzo Pupillo +- EunSik Jeong +- Rafał Mikrut +- Martin Capitanio +- YouJin Lee +- Nattu Adnan +- Gabor Kiss-Vamosi +- Lorcán Mc Donagh +- Lucas Niu +- Francisco Ramírez +- Abdelrahman Ashraf +- Neo Xu +- Thaddeus Crews +- Josh Soref +- Elliott Sales de Andrade +- �ukasz Pomietło +- Kelly Loh +- Dragoș Tiselice +- Marcin Baszczewski +- Fabian Blatz +- Jakub Marcowski +- Benjamin Halko +- Benson Muite +- kkocdko +- SoonGeon Noh +- Giseong Ji +- KunYoung Park +- Wang SiMiao 王�淼 +- Jackson Hu +- Andy French +- Andreas Deininger +- Jonathan Liu diff --git a/components/thorvg-main/LICENSE b/components/thorvg-main/LICENSE new file mode 100644 index 0000000..bf114cc --- /dev/null +++ b/components/thorvg-main/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2026 ThorVG Project + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/components/thorvg-main/README.md b/components/thorvg-main/README.md new file mode 100644 index 0000000..90b578b --- /dev/null +++ b/components/thorvg-main/README.md @@ -0,0 +1,675 @@ +[![LFX Health Score](https://insights.linuxfoundation.org/api/badge/health-score?project=thorvg)](https://insights.linuxfoundation.org/project/thorvg) +[![CodeFactor](https://www.codefactor.io/repository/github/hermet/thorvg/badge)](https://www.codefactor.io/repository/github/hermet/thorvg) +![BinarySize](https://img.shields.io/badge/Size->150kb-black) +[![License](https://img.shields.io/badge/licence-MIT-green.svg?style=flat)](LICENSE) +[![Wikipedia](https://img.shields.io/badge/Wikipedia-000000?style=flat&logo=wikipedia&logoColor=white)](https://en.wikipedia.org/wiki/Thor_Vector_Graphics) +[![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/thorvg/thorvg) +[![Discord](https://img.shields.io/badge/Community-5865f2?style=flat&logo=discord&logoColor=white)](https://discord.gg/n25xj6J6HM) +[![OpenCollective](https://img.shields.io/badge/OpenCollective-84B5FC?style=flat&logo=opencollective&logoColor=white)](https://opencollective.com/thorvg) +
+[![Build Ubuntu](https://github.com/thorvg/thorvg/actions/workflows/build_ubuntu.yml/badge.svg?branch=main&event=push)](https://github.com/thorvg/thorvg/actions/workflows/build_ubuntu.yml) +[![Build Windows](https://github.com/thorvg/thorvg/actions/workflows/build_windows.yml/badge.svg?branch=main&event=push)](https://github.com/thorvg/thorvg/actions/workflows/build_windows.yml) +[![Build macOS](https://github.com/thorvg/thorvg/actions/workflows/build_macos.yml/badge.svg?branch=main&event=push)](https://github.com/thorvg/thorvg/actions/workflows/build_macos.yml) +[![Build iOS](https://github.com/thorvg/thorvg/actions/workflows/build_ios.yml/badge.svg?branch=main&event=push)](https://github.com/thorvg/thorvg/actions/workflows/build_ios.yml) +[![Build Android](https://github.com/thorvg/thorvg/actions/workflows/build_android.yml/badge.svg?branch=main&event=push)](https://github.com/thorvg/thorvg/actions/workflows/build_android.yml) +
+[![Latest](https://img.shields.io/github/v/release/thorvg/thorvg)](https://github.com/thorvg/thorvg/releases/latest) +[![vcpkg](https://img.shields.io/vcpkg/v/thorvg)](https://vcpkg.link/ports/thorvg) +[![ArchLinux](https://img.shields.io/aur/version/thorvg?color=orange)](https://aur.archlinux.org/packages/thorvg) +[![Conan](https://img.shields.io/conan/v/thorvg)](https://conan.io/center/recipes/thorvg) +[![Fedora](https://img.shields.io/fedora/v/thorvg?color=orange)](https://src.fedoraproject.org/rpms/thorvg) +[![MSYS2](https://img.shields.io/badge/msys2-Latest-orange)](https://packages.msys2.org/packages/mingw-w64-x86_64-thorvg?repo=mingw64) +[![npm](https://img.shields.io/npm/v/@thorvg/lottie-player)](https://www.npmjs.com/package/@thorvg/lottie-player) +[![pub](https://img.shields.io/pub/v/thorvg.svg)](https://pub.dev/packages/thorvg) +[![Nimble](https://img.shields.io/badge/nimble-Latest-FFE953?color=orange)](https://nimble.directory/pkg/thorvg) +[![DUB](https://img.shields.io/badge/dub-latest-orange)](https://code.dlang.org/packages/bindbc-thorvg) +[![Homebrew](https://img.shields.io/badge/homebrew-latest-orange)](https://formulae.brew.sh/formula/thorvg) +
+ +# ThorVG +

+ +

+ +**Thor Vector Graphics** is an **open-source** graphics library designed for creating **vector-based scenes and animations**. It combines **high performance** with **lightweight efficiency**, as Thor embodies a dual meaning—_symbolizing both immense strength and lightning-fast agility_. Embracing the philosophy of _simplicity leads to reliability_, the ThorVG project provides **intuitive, user-friendly interfaces** while maintaining a **compact footprint** and **minimal overhead**.
+
+The following primitives are supported by ThorVG:
+ +- **Lines & Shapes**: rectangles, circles, and paths with coordinate control +- **Filling**: solid colors, linear & radial gradients, and path clipping +- **Stroking**: stroke width, joins, caps, dash patterns, and trimming +- **Scene Management**: retainable scene graph and object transformations +- **Composition**: various blending and masking +- **Text**: unicode characters with horizontal multi-line text layout using scalable fonts (TTF) +- **Images**: SVG, JPG, PNG, WebP, and raw bitmaps +- **Effects**: blur, drop shadow, fill, tint, tritone and color replacement +- **Animations**: Lottie + +

+ +

+ +### Lightweight Design +​ThorVG is designed for a wide range of programs, offering adaptability for integration and use in various applications and systems. It achieves this through a single binary with selectively buildable, modular components in a building block style. This ensures both optimal size and easy maintenance.
+ +

+ +

+ +The core library of ThorVG maintains a binary size of approximately **150KB**. This is significantly smaller compared to graphics engines designed primarily for desktop environments and offers the following advantages.
+ +- **Memory Efficiency**: Thanks to its low runtime memory usage, ThorVG operates stably even on low-spec systems. +- **Fast Boot**: The library loads and initializes quickly, improving the overall startup speed of applications. +- **Low Size Deployment:** With its small code and resource footprint, ThorVG is well-suited for embedded systems, IoT devices, and network-constrained environments. + +### Broad Portability +ThorVG is based on the **C++** standard and provides consistent functionality across various platforms through an abstraction layer that minimizes dependence on specific operating systems or hardware.
+ +- **Extensive Platform Support**: ThorVG supports web platforms, desktop operating systems such as Windows, macOS, and Linux, mobile platforms including Android and iOS, as well as embedded systems like Tizen and RTOS-based environments. +- **Microcontroller Support**: ThorVG has been shown to run on microcontrollers like the ESP32, demonstrating its efficiency even within environments with highly limited memory and storage. +- **Headless Rendering Support**: ThorVG can perform rendering without a display server, enabling use cases such as server-side graphics processing or offline rendering tools. + +If your program includes the main renderer, you can seamlessly utilize ThorVG APIs by transitioning drawing contexts between the main renderer and ThorVG. Throughout these API calls, ThorVG effectively serializes drawing commands among volatile paint nodes. Subsequently, it undertakes synchronous or asynchronous rendering via its render-backend engines. Additionally, ThorVG is adept at handling vector images, including formats like SVG and Lottie, and it remains adaptable for accommodating additional popular formats as needed. In the rendering process, the library may generate intermediate frame buffers for scene compositing, though only when essential. The accompanying diagram provides a concise overview of how to effectively incorporate ThorVG within your system.
+ +

+ +

+ +### CPU Rasterization +ThorVG is optimized for CPU-based rasterization, with a strong focus on vector rendering in environments where GPU resources are limited, unavailable, or intentionally avoided. In representative CPU benchmarks, ThorVG demonstrates **an average of ~1.8× faster performance** to a widely-used vector graphics engine across common vector rendering workloads. The advantage is particularly clear in geometry-heavy scenarios such as rectangles, strokes, rotations, and circle rendering. + +#### Performance Overview +

+ image +

+ +#### Test Conditions +- Tested with 5k semi-transparent primitives, including shapes, strokes, and images, using alpha blending. +- Image filtering was performed using bilinear interpolation. +- Test Platform: Apple M1 (macOS 15) +- Render size: 2560 × 1440 (2K) for each test case +- Versions: ThorVG v1.0.0, Skia v144 + +

+ +

+ +### Threading +ThorVG incorporates a threading mechanism designed to seamlessly retrieve upcoming scenes without unnecessary delays. It utilizes a finely-tuned task scheduler based on thread pools to handle a variety of tasks, including encoding, decoding, updating, and rendering. This architecture ensures efficient use of multi-core processing.
+
+The task scheduler is carefully designed to abstract complexity, simplify integration, and enhance user convenience. Its use is optional, allowing users to adopt it based on their specific needs.
+ +

+ +

+ +### Smart Rendering +ThorVG supports smart partial rendering, which enables more efficient rendering workflows by updating only the portions of a vector scene that have changed. By internally tracking modified regions, it minimizes unnecessary redraws and optimizes overall performance. This feature provides significant benefits in scenarios such as UI rendering, design tools, or applications where large parts of the scene remain static and only small elements update between frames. In such cases, avoiding full-scene rendering can greatly reduce computational workload and improve energy efficiency—making it particularly valuable on mobile and embedded systems.
+
+The following figure illustrates the geometry changes and highlights the minimal redraw region (outlined in red) that needs to be updated. Only the modified area between the previous and current frames is selectively redrawn, significantly improving performance.
+ +

+ +

+ +Please note that in highly dynamic content—such as fast-paced games or full-screen animations where nearly all objects change every frame—partial rendering provides little to no benefit and may even introduce minor overhead. In these scenarios, full-scene rendering is typically the better choice. For a practical showcase, visit [this page](https://hermet.github.io/partial-test/) demonstrating a performance comparison of partial rendering using ThorVG's software renderer.
+ +### Render Backends +Today, ThorVG provides its own implementation of multiple render-backend engines, allowing you to choose the one that best suits your app and system preferences. +
+ +- CPU/SIMD (Software) +- OpenGL/ES +- WebGL +- WebGPU + +ThorVG is particularly ahead of the curve in the web ecosystem. WebGPU introduces next-generation graphics APIs comparable to Vulkan, offering access to compute shaders and low-overhead GPU control. This enables more aggressive optimization strategies and broader application potential. On top of this, ThorVG fully supports all of its vector rendering features within the WebGPU backend, ensuring a complete and consistent experience across platforms. + +Furthermore, by abstracting underlying hardware graphics APIs such as Metal, Vulkan, and DirectX, ThorVG guarantees seamless integration across a wide range of systems, regardless of the specific hardware accelerations available. + +

+ + +### Supported Platforms +ThorVG is designed to be portable across a wide range of devices, including small IoT devices, embedded systems, mobile platforms, game consoles, desktop environments, and the web. It is actively under development, with continuous efforts to expand support for essential platforms as needed. Currently, the major supported platforms include:
+ +

+ +

+ +## Contents +- [ThorVG](#thorvg) + - [Installation](#installation) + - [Build and Install](#build-and-install) + - [Build with Visual Studio](#build-with-visual-studio) + - [Build with Xcode](#build-with-xcode) + - [Quick Start](#quick-start) + - [SVG](#svg) + - [Lottie](#lottie) + - [In Practice](#in-practice) + - [Canva iOS](#canva-ios) + - [dotLottie](#dotlottie) + - [Espressif](#espressif) + - [Flux Audio](#flux-audio) + - [Godot](#godot) + - [Lottie Creator](#lottie-creator) + - [LVGL](#lvgl) + - [Segger](#segger) + - [TinyPiXOS](#tinypixos) + - [Tizen](#tizen) + - [Interactive App](#interactive-app) + - [Examples](#examples) + - [Tools](#tools) + - [ThorVG Viewer](#thorvg-viewer) + - [Lottie to GIF](#lottie-to-gif) + - [SVG to PNG](#svg-to-png) + - [Related Projects](#related-projects) + - [API Bindings](#api-bindings) + - [Documentation](#documentation) + - [References](#references) + - [Dependencies](#dependencies) + - [Contributors](#contributors) + - [Partners](#partners) + - [Sponsors](#sponsors) + - [Communication](#communication) + +[](#contents) +
+## Installation +This section details the steps required to configure the environment for installing ThorVG.
+
+### Build and Install +ThorVG supports [meson](https://mesonbuild.com/) build system. Install [meson](http://mesonbuild.com/Getting-meson.html) and [ninja](https://ninja-build.org/) if you don't have them already. + +Run meson to configure ThorVG in the thorvg root folder. +``` +meson setup builddir +``` +Run ninja to build & install ThorVG: +``` +ninja -C builddir install +``` + +Regardless of the installation, all build results (symbols, executable) are generated in the builddir folder in thorvg. Some results such as examples won't be installed, you can check More examples section to see how to change it.
+​
+Note that some systems might include ThorVG package as a default component. In that case, you can skip this manual installation.
+ +### Build with Visual Studio +If you want to create Visual Studio project files, use the command `--backend=vs`. The resulting solution file `thorvg.sln` will be located in the build folder. +``` +meson setup builddir --backend=vs +``` + +### Build with Xcode +If you want to create Xcode project files, use the command `--backend=xcode`. The resulting solution file `thorvg.xcodeproj` will be located in the build folder. +``` +meson setup builddir --backend=xcode +``` + +[Back to contents](#contents) +
+
+## Quick Start +ThorVG renders vector shapes to a given canvas buffer. The following is a quick start to show you how to use the essential APIs. + +First, you should initialize the ThorVG engine: + +```cpp +tvg::Initializer::init(4); //4 threads +``` + +Then it would be best if you prepared an empty canvas for drawing on it: + +```cpp +static uint32_t buffer[WIDTH * HEIGHT]; //canvas target buffer + +auto canvas = tvg::SwCanvas::gen(); //generate a canvas +canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::ColorSpace::ARGB8888); //buffer, stride, w, h, Colorspace +``` + +Next you can draw multiple shapes on the canvas: + +```cpp +auto rect = tvg::Shape::gen(); //generate a shape +rect->appendRect(50, 50, 200, 200, 20, 20); //define it as a rounded rectangle (x, y, w, h, rx, ry) +rect->fill(100, 100, 100); //set its color (r, g, b) +canvas->add(rect); //add the rectangle to the canvas + +auto circle = tvg::Shape::gen(); //generate a shape +circle->appendCircle(400, 400, 100, 100); //define it as a circle (cx, cy, rx, ry) + +auto fill = tvg::RadialGradient::gen(); //generate a radial gradient +fill->radial(400, 400, 150); //set the radial gradient geometry info (cx, cy, radius) + +tvg::Fill::ColorStop colorStops[2]; //gradient colors +colorStops[0] = {0.0, 255, 255, 255, 255}; //1st color values (offset, r, g, b, a) +colorStops[1] = {1.0, 0, 0, 0, 255}; //2nd color values (offset, r, g, b, a) +fill->colorStops(colorStops, 2); //set the gradient colors info + +circle->fill(fill); //set the circle fill +canvas->add(circle); //add the circle to the canvas + +``` + +This code generates the following result: + +

+ +

+ +You can also draw you own shapes and use dashed stroking: + +```cpp +auto path = tvg::Shape::gen(); //generate a path +path->moveTo(199, 34); //set sequential path coordinates +path->lineTo(253, 143); +path->lineTo(374, 160); +path->lineTo(287, 244); +path->lineTo(307, 365); +path->lineTo(199, 309); +path->lineTo(97, 365); +path->lineTo(112, 245); +path->lineTo(26, 161); +path->lineTo(146, 143); +path->close(); + +path->fill(150, 150, 255); //path color + +path->strokeWidth(3); //stroke width +path->strokeFill(0, 0, 255); //stroke color +path->strokeJoin(tvg::StrokeJoin::Round); //stroke join style +path->strokeCap(tvg::StrokeCap::Round); //stroke cap style + +float pattern[2] = {10, 10}; //stroke dash pattern (line, gap) +path->strokeDash(pattern, 2); //set the stroke pattern + +canvas->add(path); //add the path to the canvas + +``` + +The code generates the following result: + +

+ +

+ +Now begin rendering & finish it at a particular time: + +```cpp +canvas->draw(); +canvas->sync(); +``` + +Then you can acquire the rendered image from the buffer memory. + +Lastly, terminate the engine after its usage: + +```cpp +tvg::Initializer::term(); +``` +[Back to contents](#contents) +
+
+## SVG + +ThorVG facilitates [SVG Tiny Specification](https://www.w3.org/TR/SVGTiny12/) rendering via its dedicated SVG interpreter. Adhering to the SVG Tiny Specification, the implementation maintains a lightweight profile, rendering it particularly advantageous for embedded systems. While ThorVG comprehensively adheres to [most of the SVG Tiny specs](https://github.com/thorvg/thorvg/wiki/SVG-Support), certain features remain unsupported within the current framework. These include:
+ + - Animation + - Interactivity + - Multimedia + +The figure below highlights ThorVG's SVG rendering capabilities: + +

+ +

+ +The following code snippet shows how to draw SVG image using ThorVG: + +```cpp +auto picture = tvg::Picture::gen(); //generate a picture +picture->load("tiger.svg"); //load a SVG file +canvas->add(picture); //add the picture to the canvas +``` + +The result is: + +

+ +

+ +[Back to contents](#contents) +
+
+## Lottie + +ThorVG supports the most powerful [Lottie Animation features](https://github.com/thorvg/thorvg/wiki/Lottie-Support). Lottie is an industry standard, JSON-based vector animation file format that enables seamless distribution of animations on any platform, akin to shipping static assets. These files are compact and compatible with various devices, scaling up or down without pixelation. With Lottie, you can easily create, edit, test, collaborate, and distribute animations in a user-friendly manner. For more information, please visit [Lottie Animation Community](https://lottie.github.io/)' website.
+
+ThorVG offers great flexibility in building its binary. Besides serving as a general graphics engine, it can be configured as a compact Lottie animation playback library with specific build options: + +``` +$meson setup builddir -Dloaders="lottie" +``` + +Alternatively, to support additional bitmap image formats: + +``` +$meson setup builddir -Dloaders="lottie, png, jpg, webp" +``` + +Please note that ThorVG supports Lottie Expressions by default. Lottie Expressions are small JavaScript code snippets that can be applied to animated properties in your Lottie animations, evaluating to a single value. This is an advanced feature in the Lottie specification and may impact binary size and performance, especially when targeting small devices such as MCUs. If this feature is not essential for your requirements, you can disable it using the `extra` build option in ThorVG: + +``` +$meson setup builddir -Dloaders="lottie" -Dextra="" +``` + +The following code snippet demonstrates how to use ThorVG to play a Lottie animation. + +```cpp +auto animation = tvg::Animation::gen(); //generate an animation +auto picture = animation->picture() //acquire a picture which associated with the animation. +picture->load("lottie.json"); //load a Lottie file +auto duration = animation->duration(); //figure out the animation duration time in seconds. +canvas->add(picture); //add the picture to the canvas +``` +First, an animation and a picture are generated. The Lottie file (lottie.json) is loaded into the picture, and then the picture is added to the canvas. The animation frames are controlled using the animation object to play the Lottie animation. Also you might want to know the animation duration time to run your animation loop. +```cpp +animation->frame(animation->totalFrame() * progress); //Set a current animation frame to display +canvas->update(animation->picture()); //Update the picture to be redrawn. +``` +Let's suppose the progress variable determines the position of the animation, ranging from 0 to 1 based on the total duration time of the animation. Adjusting the progress value allows you to control the animation at the desired position. Afterwards, the canvas is updated to redraw the picture with the updated animation frame.
+
+

+ +

+ +Please check out the [ThorVG Test App](https://thorvg-perf-test.vercel.app/) to see the performance of various Lottie animations powered by ThorVG. If you're working on the frontend, you can also download the ThorVG npm package [here](https://www.npmjs.com/package/@thorvg/lottie-player).
+ +[Back to contents](#contents) +
+
+## In Practice +### Canva iOS +[Canva](https://www.canva.com), is a popular visual communication platform used by millions worldwide. Known for its intuitive interface and rich design resources, Canva empowers users to create high-quality visual content easily. The iOS app switched from its previous Lottie engine to ThorVG, achieving around 80% faster rendering and 70% lower peak memory usage. + +

+ +

+ +### dotLottie +[dotLottie](https://dotlottie.io/) is an open-source format that combines multiple Lottie animations, assets like images and fonts, and supports features such as state machines and interactivity. It uses ZIP compression (.lottie extension) for easy and efficient distribution. As a superset of Lottie, the [dotLottie player](https://github.com/LottieFiles/dotlottie-rs) now runs on ThorVG for rendering. + +

+ +

+ +### Espressif +[Espressif Systems](https://www.espressif.com/en) provides [ThorVG as an official component](https://docs.espressif.com/projects/esp-iot-solution/en/latest/display/lcd/gui_solution.html#thorvg-component) within its ESP-IDF (IoT Development Framework), simplifying integration into ESP-IDF projects. This allows developers to easily incorporate ThorVG's rendering capabilities into their applications, particularly on IoT devices powered by Espressif’s ESP32 and ESP32-P4 microcontrollers. + +

+ +

+ +### Flux Audio +[Flux Audio](https://www.flux.audio/) is a high-performance audio company focused on premium sound and immersive experiences. They use advanced software for consistent audio processing across devices. ThorVG powers their UI with fast, scalable vector rendering, highlighting its flexibility in modern audio platforms. + +

+ +

+ +### Godot +ThorVG is integrated into the Godot game engine to support sleek, high-quality vector-based user interfaces and assets. [Godot](https://www.godotengine.org) is a modern, open-source game engine with a full suite of tools, allowing developers to focus on creating games without reinventing core functionality. + +

+ +

+ +### Lottie Creator + +[Lottie Creator](https://creator.lottiefiles.com/) is designed to create ultra-lightweight, highly customizable and interactive animations for web, apps and social. Supercharged with AI-based Motion Copilot. ThorVG is powering the Canvas engine behind Lottie Creator — enabling fast and scalable vector graphics rendering across platforms. + +

+ +

+ +### LVGL +[LVGL](https://lvgl.io/) is an open-source graphics library specifically designed for embedded systems with limited resources. It is lightweight and highly customizable, providing support for graphical user interfaces (GUIs) on microcontrollers, IoT devices, and other embedded platforms. ThorVG serves as the vector drawing primitives library in the LVGL framework. + +

+ +

+ +### Segger +[SEGGER](https://www.segger.com/) Microcontroller provides products for developing and manufacturing embedded systems, including real-time operating systems (RTOS), middleware libraries, debugging and trace probes, and programming tools. [It has adopted ThorVG](https://doc.segger.com/UM03001_emWin.html#GUI_GPU_ThorVG_ThorVG_driver) as a GPU driver to enable high-performance vector rendering for its GUI apps. + +

+ +

+ +### TinyPiXOS +[TinyPiXOS](https://www.tinypixos.com/en/) is a lightweight, open-source Linux OS that replaces X11/Wayland with a custom C/C++ graphics stack. It includes minimal window management and GUI tools, all optimized for low resource use. ThorVG handles core GUI rendering, delivering efficient performance and high visual quality in constrained environments. + +

+ +

+ +### Tizen +ThorVG has been integrated into the [Tizen](https://www.tizen.org) platform as the vector graphics engine. [NUI](https://docs.tizen.org/application/dotnet/guides/user-interface/nui/overview/) is the name of Tizen UI framework which is written in C#. ThorVG is the backend engine of the [NUI Vector Graphics](https://docs.tizen.org/application/dotnet/guides/user-interface/nui/vectorgraphics/Overview/) which is used for vector primitive drawings and scalable image contents such as SVG and Lottie Animation among the Tizen applications. + +

+ +

+
+ +Would you like us to showcase your project with ThorVG? Feel free to [open an issue](https://github.com/thorvg/thorvg/issues) or submit a pull request! + +[Back to contents](#contents) +
+
+## Interactive App +Check out [Thor Janitor](https://github.com/thorvg/thorvg.janitor), an interactive demo game fully rendered using ThorVG. It renders tens of thousands of objects in real-time with effects like DropShadow and Blur, running stably at 120+ FPS! + +

+ +

+ +

+ Watch the full video! +

+ +[Back to contents](#contents) +
+
+## Examples +There are plenty of sample code in [thorvg.example](https://github.com/thorvg/thorvg.example) to help you in understanding the ThorVG APIs. + +[Back to contents](#contents) +
+
+## Tools +### ThorVG Viewer +ThorVG provides a resource verification tool for the ThorVG engine. The [ThorVG viewer](https://thorvg.github.io/thorvg.viewer/) enables instant rendering directly in the web browser using the ThorVG WebAssembly binary, allowing real-time editing of vector elements. It does not upload your resources to any external server and supports exporting to formats such as GIF, ensuring that designer copyrights remain protected.
+
+ +

+ +

+ +### Lottie to GIF +ThorVG provides an executable `tvg-lottie2gif` converter that generates a GIF file from a Lottie file. + +To use the `tvg-lottie2gif`, you must turn on this feature in the build option: +``` +meson setup builddir -Dtools=lottie2gif -Dsavers=gif +``` +To use the 'tvg-lottie2gif' converter, you need to provide the 'Lottie files' parameter. This parameter can be a file name with the '.json' extension or a directory name. It also accepts multiple files or directories separated by spaces. If a directory is specified, the converter will search for files with the '.json' extension within that directory and all its subdirectories.
+
+Optionally, you can specify the image resolution in the 'WxH' format, with two numbers separated by an 'x' sign, following the '-r' flag.
+
+Both flags, if provided, are applied to all of the `.json` files. + +The usage examples of the `tvg-lottie2gif`: +``` +Usage: + tvg-lottie2gif [Lottie file] or [Lottie folder] [-r resolution] [-f fps] [-b background color] + +Flags: + -r set the output image resolution. + -f specifies the frames per second (fps) for the generated animation. + -b specifies the base background color (RGB in hex). If not specified, the background color will follow the original content. + +Examples: + $ tvg-lottie2gif input.json + $ tvg-lottie2gif input.json -f 30 + $ tvg-lottie2gif input.json -r 600x600 -f 30 + $ tvg-lottie2gif lottiefolder + $ tvg-lottie2gif lottiefolder -r 600x600 + $ tvg-lottie2gif lottiefolder -r 600x600 -f 30 -b fa7410 +``` + +### SVG to PNG +ThorVG provides an executable `tvg-svg2png` converter that generates a PNG file from an SVG file. + +To use the `tvg-svg2png`, you must turn on this feature in the build option: +``` +meson setup builddir -Dtools=svg2png +``` +To use the 'tvg-svg2png' converter, you need to provide the 'SVG files' parameter. This parameter can be a file name with the '.svg' extension or a directory name. It also accepts multiple files or directories separated by spaces. If a directory is specified, the converter will search for files with the '.svg' extension within that directory and all its subdirectories.
+
+Optionally, you can specify the image resolution in the 'WxH' format, with two numbers separated by an 'x' sign, following the '-r' flag.
+
+The background color can be set with the `-b` flag. The `bgColor` parameter should be passed as a three-bytes hexadecimal value in the `ffffff` format. The default background is transparent.
+
+Both flags, if provided, are applied to all of the `.svg` files. + +The usage examples of the `tvg-svg2png`: +``` +Usage: + tvg-svg2png [SVG files] [-r resolution] [-b bgColor] + +Flags: + -r set the output image resolution. + -b set the output image background color. + +Examples: + $ tvg-svg2png input.svg + $ tvg-svg2png input.svg -r 200x200 + $ tvg-svg2png input.svg -r 200x200 -b ff00ff + $ tvg-svg2png input1.svg input2.svg -r 200x200 -b ff00ff + $ tvg-svg2png . -r 200x200 +``` + +[Back to contents](#contents) +
+
+## Related Projects +ThorVG is designed to be portable and extensible across various platforms. The following projects integrate ThorVG into specific environments or tools:
+ +* [ThorVG Android](https://github.com/thorvg/thorvg.android) – Kotlin-based ThorVG support for Android. +* [ThorVG Example](https://github.com/thorvg/thorvg.example) – An example set demonstrates how to use ThorVG's APIs. +* [ThorVG Flutter](https://github.com/thorvg/thorvg.flutter) - A Flutter plugin for using ThorVG on Android and iOS. +* [ThorVG Janitor](https://github.com/thorvg/thorvg.janitor) - A demo game showcasing ThorVG’s real-time rendering features. +* [ThorVG Swift](https://github.com/thorvg/thorvg.swift) - Swift bindings for rendering vector graphics with ThorVG. +* [ThorVG Unity](https://github.com/thorvg/thorvg.unity) – ThorVG integration for Unity using C#. +* [ThorVG Viewer](https://github.com/thorvg/thorvg.viewer) - A browser-based viewer for ThorVG using WebAssembly. +* [ThorVG Web](https://github.com/thorvg/thorvg.web) - WebAssembly-based integration of ThorVG for web apps. + +[Back to contents](#contents) +
+
+ +## API Bindings +Our main development APIs are written in C++, but ThorVG also provides API bindings for C. + +To enable CAPI binding, you need to activate this feature in the build options: +``` +meson setup builddir -Dbindings="capi" +``` +[Back to contents](#contents) +
+
+## Documentation +The ThorVG API documentation is available at [thorvg.org/apis](https://www.thorvg.org/apis), and can also be found directly in this repository via the [C++ API](https://github.com/thorvg/thorvg/blob/main/inc/thorvg.h) and [C API](https://github.com/thorvg/thorvg/blob/main/src/bindings/capi/thorvg_capi.h). + +For comprehensive and well-structured technical information, please visit the [DeepWiki](https://deepwiki.com/thorvg/thorvg), which offers in-depth guidance on ThorVG's architecture, features, and usage. + +[Back to contents](#contents) +
+
+## References +- [Universal Motion Graphics across All Platforms: Unleashing Creativity with ThorVG](https://youtu.be/qhHMycRPQ9M?si=RXAag3Fxm8R7W_I0) +- [Canva Enhances iOS Lottie Rendering: 80% Faster and 70% More Efficient with ThorVG](https://lottiefiles.com/blog/working-with-lottie-animations/canva-enhances-ios-rendering-faster-and-efficient-with-thorvg) + +[Back to contents](#contents) +
+
+## Dependencies +ThorVG provides flexible image loading capabilities, supporting both static and external loaders. This design ensures that even in environments lacking external libraries, users can rely on built-in static loaders for core functionality. At its core, the ThorVG library is fully self-contained and operates without mandatory external dependencies. However, several optional feature extensions are available, each with its own set of dependencies. + +The following outlines the dependencies for these optional features: + +* **GL Engine**: [OpenGL 3.3](https://www.khronos.org/opengl/), [OpenGL ES 3.0](https://www.khronos.org/opengles/), or a browser with [WebGL2](https://www.khronos.org/webgl/) support. +* **WG Engine**: [webgpu-native v0.25](https://github.com/gfx-rs/wgpu-native) or a browser with [WebGPU](https://www.w3.org/TR/webgpu/) support. +* **PNG Loader** (external): [libpng](https://github.com/pnggroup/libpng) +* **JPEG Loader** (external): [libjpeg-turbo](https://github.com/libjpeg-turbo/libjpeg-turbo) +* **WebP Loader** (external): [libwebp](https://developers.google.com/speed/webp/download) + +[Back to contents](#contents) +
+
+## Contributors +ThorVG stands as a purely open-source initiative. We are grateful to the individuals, organizations, and companies that have contributed to the development of the ThorVG project. The dedicated efforts of the individuals and entities listed below have enabled ThorVG to reach its current state. + +* [Individuals](https://github.com/thorvg/thorvg/blob/main/CONTRIBUTORS.md) +* [Godot](https://godotengine.org/) +* [LVGL](https://lvgl.io/) +* [Canva Pty Ltd](https://www.canva.com/) + +[Back to contents](#contents) +
+
+## Partners +Partners engage in strategic collaboration with ThorVG, working together to shape the future of scalable, high-performance vector graphics. We acknowledge organizations that have supported ThorVG’s journey through development, integration, collaboration, and community involvement. + +

+ + LottieFiles + +

+ +

+ + Samsung + +

+ +
+ +If you’re interested in partnering with ThorVG, we’d love to hear from you. Please reach out at thorvg@thorvg.org + +[Back to contents](#contents) +
+
+## Sponsors +We sincerely thank our financial sponsors for their generous support, which drives the growth and innovation of the ThorVG project. Your contributions help us make ThorVG more powerful, efficient, and accessible for everyone. +
+
+

+ + LottieFiles + +

+
+We are also seeking your support to ensure the continued development of the ThorVG project. Your generous donations will help cover operational costs and contribute to the growth of this open-source project. Even a small contribution can make a big difference in securing the future of ThorVG! +
+
+ +* [Open Collective](https://opencollective.com/thorvg) + +[Back to contents](#contents) +
+
+## Communication +For real-time conversations and discussions, please join us on [Discord](https://discord.gg/n25xj6J6HM) + +[Back to contents](#contents) diff --git a/components/thorvg-main/cross/android_aarch64.txt b/components/thorvg-main/cross/android_aarch64.txt new file mode 100644 index 0000000..d348656 --- /dev/null +++ b/components/thorvg-main/cross/android_aarch64.txt @@ -0,0 +1,19 @@ +# Android developer (Use the NDK with other build systems) +# https://developer.android.com/ndk/guides/other_build_systems + +[binaries] +cpp = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/aarch64-linux-androidAPI-clang++' +ar = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ar' +as = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-as' +ranlib = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ranlib' +ld = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/ld' +strip = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-strip' + +[properties] +sys_root = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/sysroot' + +[host_machine] +system = 'android' +cpu_family = 'arm' +cpu = 'aarch64' +endian = 'little' \ No newline at end of file diff --git a/components/thorvg-main/cross/android_x86_64.txt b/components/thorvg-main/cross/android_x86_64.txt new file mode 100644 index 0000000..41e9e0b --- /dev/null +++ b/components/thorvg-main/cross/android_x86_64.txt @@ -0,0 +1,19 @@ +# Android developer (Use the NDK with other build systems) +# https://developer.android.com/ndk/guides/other_build_systems + +[binaries] +cpp = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/x86_64-linux-androidAPI-clang++' +ar = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ar' +as = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-as' +ranlib = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-ranlib' +ld = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/ld' +strip = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/bin/llvm-strip' + +[properties] +sys_root = 'NDK/toolchains/llvm/prebuilt/HOST_TAG/sysroot' + +[host_machine] +system = 'android' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' \ No newline at end of file diff --git a/components/thorvg-main/cross/ios_arm64.txt b/components/thorvg-main/cross/ios_arm64.txt new file mode 100644 index 0000000..418588b --- /dev/null +++ b/components/thorvg-main/cross/ios_arm64.txt @@ -0,0 +1,22 @@ +# build for the ios devices (Apple Silicon) + +[binaries] +cpp = ['clang++', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk'] +ar = 'ar' +strip = 'strip' + +[properties] +root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer' +has_function_printf = true + +[built-in options] +cpp_args = ['-miphoneos-version-min=11.0'] +cpp_link_args = ['-miphoneos-version-min=11.0'] + +[host_machine] +system = 'darwin' +subsystem = 'ios' +kernel = 'xnu' +cpu_family = 'aarch64' +cpu = 'aarch64' +endian = 'little' diff --git a/components/thorvg-main/cross/ios_simulator_arm64.txt b/components/thorvg-main/cross/ios_simulator_arm64.txt new file mode 100644 index 0000000..b9149ad --- /dev/null +++ b/components/thorvg-main/cross/ios_simulator_arm64.txt @@ -0,0 +1,23 @@ +# build for the ios simulator (Apple Silicon) + +[binaries] +cpp = ['clang++', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'] +ar = 'ar' +strip = 'strip' + +[properties] +root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer' +has_function_printf = true + +[built-in options] +cpp_args = ['-mios-simulator-version-min=11.0'] +cpp_link_args = ['-mios-simulator-version-min=11.0'] + +[host_machine] +system = 'darwin' +subsystem = 'ios' +kernel = 'xnu' +cpu_family = 'aarch64' +cpu = 'aarch64' +endian = 'little' + diff --git a/components/thorvg-main/cross/ios_simulator_x86_64.txt b/components/thorvg-main/cross/ios_simulator_x86_64.txt new file mode 100644 index 0000000..120f3e7 --- /dev/null +++ b/components/thorvg-main/cross/ios_simulator_x86_64.txt @@ -0,0 +1,22 @@ +# build for the ios simulator (Intel) + +[binaries] +cpp = ['clang++', '-arch', 'x86_64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'] +ar = 'ar' +strip = 'strip' + +[properties] +root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer' +has_function_printf = true + +[built-in options] +cpp_args = ['-mios-simulator-version-min=11.0'] +cpp_link_args = ['-mios-simulator-version-min=11.0'] + +[host_machine] +system = 'darwin' +subsystem = 'ios' +kernel = 'xnu' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/components/thorvg-main/inc/meson.build b/components/thorvg-main/inc/meson.build new file mode 100644 index 0000000..3e8e9b4 --- /dev/null +++ b/components/thorvg-main/inc/meson.build @@ -0,0 +1,5 @@ +header_files = ['thorvg.h'] + +thorvg_inc = include_directories('.') + +install_headers(header_files, subdir: 'thorvg-' + vmaj) diff --git a/components/thorvg-main/inc/thorvg.h b/components/thorvg-main/inc/thorvg.h new file mode 100644 index 0000000..ddbe6d4 --- /dev/null +++ b/components/thorvg-main/inc/thorvg.h @@ -0,0 +1,2631 @@ +#ifndef _THORVG_H_ +#define _THORVG_H_ + +#include +#include +#include +#include + +#define TVG_VERSION_MAJOR 1 // for compile-time checks +#define TVG_VERSION_MINOR 0 // for compile-time checks +#define TVG_VERSION_MICRO 0 // for compile-time checks + +#ifdef TVG_API + #undef TVG_API +#endif + +#ifndef TVG_STATIC + #ifdef _WIN32 + #if TVG_BUILD + #define TVG_API __declspec(dllexport) + #else + #define TVG_API __declspec(dllimport) + #endif + #elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) + #define TVG_API __global + #else + #if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__INTEL_COMPILER) + #define TVG_API __attribute__ ((visibility("default"))) + #else + #define TVG_API + #endif + #endif +#else + #define TVG_API +#endif + +#ifdef TVG_DEPRECATED + #undef TVG_DEPRECATED +#endif + +#ifdef _WIN32 + #define TVG_DEPRECATED __declspec(deprecated) +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) + #define TVG_DEPRECATED __attribute__ ((__deprecated__)) +#else + #define TVG_DEPRECATED +#endif + +#define _TVG_DECLARE_PRIVATE(A) \ +protected: \ + A(const A&) = delete; \ + const A& operator=(const A&) = delete; \ + A() + +#define _TVG_DECLARE_PRIVATE_BASE(A) \ + _TVG_DECLARE_PRIVATE(A); \ +public: \ + struct Impl; \ + Impl* pImpl + +#define _TVG_DECLARE_PRIVATE_DERIVE(A) \ + _TVG_DECLARE_PRIVATE(A); \ +protected: \ + ~A() {} + +#define _TVG_DISABLE_CTOR(A) \ + A() = delete; \ + ~A() = delete + +#define _TVG_DECLARE_ACCESSOR(A) \ + friend A + +namespace tvg +{ + +struct RenderMethod; +struct Animation; +struct Shape; + +/** + * @defgroup ThorVG ThorVG + * @brief ThorVG classes and enumerations providing C++ APIs. + */ + +/**@{*/ + +/** + * @brief Enumeration specifying the result from the APIs. + * + * All ThorVG APIs could potentially return one of the values in the list. + * Please note that some APIs may additionally specify the reasons that trigger their return values. + * + */ +enum struct Result +{ + Success = 0, ///< The value returned in case of a correct request execution. + InvalidArguments, ///< The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers. + InsufficientCondition, ///< The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist. + FailedAllocation, ///< The value returned in case of unsuccessful memory allocation. + MemoryCorruption, ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting + NonSupport, ///< The value returned in case of choosing unsupported engine features(options). + Unknown = 255 ///< The value returned in all other cases. +}; + + +/** + * @brief Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color. + */ +enum struct ColorSpace : uint8_t +{ + ABGR8888 = 0, ///< The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. + ARGB8888, ///< The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. + ABGR8888S, ///< The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied. @since 0.12 + ARGB8888S, ///< The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied. @since 0.12 + Grayscale8, ///< One single channel data. + Unknown = 255 ///< Unknown channel data. This is reserved for an initial ColorSpace value. @since 1.0 +}; + + +/** + * @brief Enumeration to specify rendering engine behavior. + * + * @note The availability or behavior of @c SmartRender may vary depending on platform or backend support. + * It attempts to optimize rendering performance by updating only the regions of the canvas that have + * changed between frames (partial redraw). This can be highly effective in scenarios where most of the + * canvas remains static and only small portions are updated—such as simple animations or GUI interactions. + * However, in complex scenes where a large portion of the canvas changes frequently (e.g., full-screen animations + * or heavy object movements), the overhead of tracking changes and managing update regions may outweigh the benefits, + * resulting in decreased performance compared to the default rendering mode. Thus, it is recommended to benchmark + * both modes in your specific use case to determine the optimal setting. + * + * @since 1.0 + */ +enum struct EngineOption : uint8_t +{ + None = 0, /**< No engine options are enabled. This may be used to explicitly disable all optional behaviors. */ + Default = 1 << 0, /**< Uses the default rendering mode. */ + SmartRender = 1 << 1 /**< Enables automatic partial (smart) rendering optimizations. */ +}; + + +/** + * @brief Enumeration specifying the values of the path commands accepted by ThorVG. + */ +enum struct PathCommand : uint8_t +{ + Close = 0, ///< Ends the current sub-path and connects it with its initial point. This command doesn't expect any points. + MoveTo, ///< Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position. + LineTo, ///< Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line. + CubicTo ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve. +}; + + +/** + * @brief Enumeration determining the ending type of a stroke in the open sub-paths. + */ +enum struct StrokeCap : uint8_t +{ + Butt = 0, ///< The stroke ends exactly at each of the two end-points of a sub-path. For zero length sub-paths no stroke is rendered. + Round, ///< The stroke is extended in both end-points of a sub-path by a half circle, with a radius equal to the half of a stroke width. For zero length sub-paths a full circle is rendered. + Square ///< The stroke is extended in both end-points of a sub-path by a rectangle, with the width equal to the stroke width and the length equal to the half of the stroke width. For zero length sub-paths the square is rendered with the size of the stroke width. +}; + + +/** + * @brief Enumeration determining the style used at the corners of joined stroked path segments. + */ +enum struct StrokeJoin : uint8_t +{ + Miter = 0, ///< The outer corner of the joined path segments is spiked. The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect. In case the extension goes beyond the limit, the join style is converted to the Bevel style. + Round, ///< The outer corner of the joined path segments is rounded. The circular region is centered at the join point. + Bevel ///< The outer corner of the joined path segments is bevelled at the join point. The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke. +}; + + +/** + * @brief Enumeration specifying how to fill the area outside the gradient bounds. + */ +enum struct FillSpread : uint8_t +{ + Pad = 0, ///< The remaining area is filled with the closest stop color. + Reflect, ///< The gradient pattern is reflected outside the gradient area until the expected region is filled. + Repeat ///< The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled. +}; + + +/** + * @brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape. + */ +enum struct FillRule : uint8_t +{ + NonZero = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape. + EvenOdd ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape. +}; + + +/** + * @brief Enumeration indicating the method used in the mask of two objects - the target and the source. + * + * Notation: S(Source), T(Target), SA(Source Alpha), TA(Target Alpha) + * + * @see Paint::mask() + */ +enum struct MaskMethod : uint8_t +{ + None = 0, ///< No Masking is applied. + Alpha, ///< Alpha Masking using the masking target's pixels as an alpha value. + InvAlpha, ///< Alpha Masking using the complement to the masking target's pixels as an alpha value. + Luma, ///< Alpha Masking using the grayscale (0.2126R + 0.7152G + 0.0722*B) of the masking target's pixels. @since 0.9 + InvLuma, ///< Alpha Masking using the grayscale (0.2126R + 0.7152G + 0.0722*B) of the complement to the masking target's pixels. @since 0.11 + Add, ///< Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) @since 1.0 + Subtract, ///< Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) @since 1.0 + Intersect, ///< Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) @since 1.0 + Difference, ///< Calculates the absolute difference between the target color and the source color multiplied by the complement of the target alpha. abs(T - S * (255 - TA)) @since 1.0 + Lighten, ///< Where multiple masks intersect, the highest transparency value is used. @since 1.0 + Darken ///< Where multiple masks intersect, the lowest transparency value is used. @since 1.0 +}; + + +/** + * @brief Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method. + * + * Notation: S(source paint as the top layer), D(destination as the bottom layer), Sa(source paint alpha), Da(destination alpha) + * + * @see Paint::blend() + * + * @since 0.15 + */ +enum struct BlendMethod : uint8_t +{ + Normal = 0, ///< Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D + Multiply, ///< Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D) + Screen, ///< The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D) + Overlay, ///< Combines Multiply and Screen blend modes. (2 * S * D) if (D < 128), otherwise 255 - 2 * (255 - S) * (255 - D) + Darken, ///< Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D) + Lighten, ///< Only has the opposite action of Darken Only. max(S, D) + ColorDodge, ///< Divides the bottom layer by the inverted top layer. D / (255 - S) + ColorBurn, ///< Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S + HardLight, ///< The same as Overlay but with the color roles reversed. (2 * S * D) if (S < 128), otherwise 255 - 2 * (255 - S) * (255 - D) + SoftLight, ///< The same as Overlay but with applying pure black or white does not result in pure black or white. (255 - 2 * S) * (D * D) + (2 * S * D) + Difference, ///< Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S) + Exclusion, ///< The result is twice the product of the top and bottom layers, subtracted from their sum. S + D - (2 * S * D) + Hue, ///< Combine with HSL(Sh + Ds + Dl) then convert it to RGB. @since 1.0 + Saturation, ///< Combine with HSL(Dh + Ss + Dl) then convert it to RGB. @since 1.0 + Color, ///< Combine with HSL(Sh + Ss + Dl) then convert it to RGB. @since 1.0 + Luminosity, ///< Combine with HSL(Dh + Ds + Sl) then convert it to RGB. @since 1.0 + Add, ///< Simply adds pixel values of one layer with the other. (S + D) + Composition = 255 ///< For intermediate composition layers; suitable for use with Scene or Picture. @since 1.0 +}; + + +/** + * @brief Enumeration that defines methods used for Scene Effects. + * + * This enum provides options to apply various post-processing effects to a scene. + * Scene effects are typically applied to modify the final appearance of a rendered scene, such as blurring. + * + * @see Scene::add(SceneEffect effect, ...) + * + * @since 1.0 + */ +enum struct SceneEffect : uint8_t +{ + Clear = 0, ///< Clear all previously applied scene effects, restoring the scene to its original state. + GaussianBlur, ///< Apply a blur effect with a Gaussian filter. Param(4) = {sigma(double)[> 0], direction(int)[both: 0 / horizontal: 1 / vertical: 2], border(int)[duplicate: 0 / wrap: 1], quality(int)[0 - 100]} + DropShadow, ///< Apply a drop shadow effect with a Gaussian Blur filter. Param(8) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255], angle(double)[0 - 360], distance(double), blur_sigma(double)[> 0], quality(int)[0 - 100]} + Fill, ///< Override the scene content color with a given fill information. Param(4) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255]} + Tint, ///< Tinting the current scene color with a given black, white color parameters. Param(7) = {black_R(int)[0 - 255], black_G(int)[0 - 255], black_B(int)[0 - 255], white_R(int)[0 - 255], white_G(int)[0 - 255], white_B(int)[0 - 255], intensity(double)[0 - 100]} + Tritone ///< Apply a tritone color effect to the scene using three color parameters for shadows, midtones, and highlights. A blending factor determines the mix between the original color and the tritone colors. Param(9) = {Shadow_R(int)[0 - 255], Shadow_G(int)[0 - 255], Shadow_B(int)[0 - 255], Midtone_R(int)[0 - 255], Midtone_G(int)[0 - 255], Midtone_B(int)[0 - 255], Highlight_R(int)[0 - 255], Highlight_G(int)[0 - 255], Highlight_B(int)[0 - 255], Blend(int)[0 - 255]} +}; + + +/** + * @brief Enumeration that defines methods used for wrapping text. + * + * This enum provides options to control how text is wrapped when it exceeds the available space. + * Wrapping affects the layout and flow of text in the rendering area. + * + * @see Text::wrap(TextWrap mode) + * + * @since 1.0 + */ +enum struct TextWrap : uint8_t +{ + None = 0, ///< Do not wrap text. Text is rendered on a single line and may overflow the bounding area. + Character, ///< Wrap at the character level. If a word cannot fit, it is broken into individual characters to fit the line. + Word, ///< Wrap at the word level. Words that do not fit are moved to the next line. + Smart, ///< Smart choose wrapping method: word wrap first, falling back to character wrap if a word does not fit. + Ellipsis ///< Truncate overflowing text and append an ellipsis ("...") at the end. Typically used for single-line labels. +}; + + +/** + * @brief Enumeration specifying the ThorVG class type value. + * + * ThorVG's drawing objects can return class type values, allowing you to identify the specific class of each object. + * + * @see Paint::type() + * @see Fill::type() + * + * @since 1.0 + */ +enum struct Type : uint8_t +{ + Undefined = 0, ///< Unknown class + Shape, ///< Shape class + Scene, ///< Scene class + Picture, ///< Picture class + Text, ///< Text class + LinearGradient = 10, ///< LinearGradient class + RadialGradient ///< RadialGradient class +}; + + +/** + * @brief A data structure representing a point in two-dimensional space. + * + * This structure defines a single point using Cartesian coordinates. + * It is typically used for specifying positions or coordinates in 2D graphics. + */ +struct Point +{ + float x; ///< The x-coordinate of the point. + float y; ///< The y-coordinate of the point. +}; + + +/** + * @brief A data structure representing a three-dimensional matrix. + * + * The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. + * The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. + * The elements e31 and e32 are set to 0, e33 is set to 1. + */ +struct Matrix +{ + float e11, e12, e13; + float e21, e22, e23; + float e31, e32, e33; +}; + + +/** + * @class Paint + * + * @brief An abstract class for managing graphical elements. + * + * A graphical element in TVG is any object composed into a Canvas. + * Paint represents such a graphical object and its behaviors such as duplication, transformation and composition. + * TVG recommends the user to regard a paint as a set of volatile commands. They can prepare a Paint and then request a Canvas to run them. + */ +struct TVG_API Paint +{ + /** + * @brief Retrieves the parent paint object. + * + * This function returns a pointer to the parent object if the current paint + * belongs to one. Otherwise, it returns @c nullptr. + * + * @return A pointer to the parent object if available, otherwise @c nullptr. + * + * @see Scene::add() + * @see Canvas::add() + * + * @since 1.0 + */ + const Paint* parent() const noexcept; + + /** + * @brief Sets the visibility of the Paint object. + * + * This is useful for selectively excluding paint objects during rendering. + * + * @param[in] on A boolean flag indicating visibility. The default is @c true. + * @c true, the object will be rendered by the engine. + * @c false, the object will be excluded from the drawing process. + * + * @note An invisible object is not considered inactive—it may still participate + * in internal update processing if its properties are updated, but it will not + * be taken into account for the final drawing output. To completely deactivate + * a paint object, remove it from the canvas. + * + * @see Paint::visible() const + * @see Result Canvas::remove(Paint* paint) + * + * @since 1.0 + */ + Result visible(bool on) noexcept; + + /** + * @brief Sets the angle by which the object is rotated. + * + * The angle in measured clockwise from the horizontal axis. + * The rotational axis passes through the point on the object with zero coordinates. + * + * @param[in] degree The value of the angle in degrees. + * + * @retval Result::InsufficientCondition in case a custom transform is applied. + * @see Paint::transform() + */ + Result rotate(float degree) noexcept; + + /** + * @brief Sets the scale value of the object. + * + * @param[in] factor The value of the scaling factor. The default value is 1. + * + * @retval Result::InsufficientCondition in case a custom transform is applied. + * @see Paint::transform() + */ + Result scale(float factor) noexcept; + + /** + * @brief Sets the values by which the object is moved in a two-dimensional space. + * + * The origin of the coordinate system is in the upper-left corner of the canvas. + * The horizontal and vertical axes point to the right and down, respectively. + * + * @param[in] x The value of the horizontal shift. + * @param[in] y The value of the vertical shift. + * + * @retval Result::InsufficientCondition in case a custom transform is applied. + * @see Paint::transform() + */ + Result translate(float x, float y) noexcept; + + /** + * @brief Sets the matrix of the affine transformation for the object. + * + * The augmented matrix of the transformation is expected to be given. + * + * @param[in] m The 3x3 augmented matrix. + */ + Result transform(const Matrix& m) noexcept; + + /** + * @brief Gets the matrix of the affine transformation of the object. + * + * The values of the matrix can be set by the transform() API, as well by the translate(), + * scale() and rotate(). In case no transformation was applied, the identity matrix is returned. + * + * @return The augmented transformation matrix. + * + * @since 0.4 + */ + Matrix& transform() noexcept; + + /** + * @brief Sets the opacity of the object. + * + * @param[in] o The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + * @note Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible. + */ + Result opacity(uint8_t o) noexcept; + + /** + * @brief Sets the masking target object and the masking method. + * + * @param[in] target The paint of the target object. + * @param[in] method The method used to mask the source object with the target. + * + * @retval Result::InsufficientCondition if the target has already belonged to another paint. + * @retval Result::InvalidArguments @p method equals @c MaskMethod::None and @p target is not @c nullptr. + */ + Result mask(Paint* target, MaskMethod method) noexcept; + + /** + * @brief Clip the drawing region of the paint object. + * + * This function restricts the drawing area of the paint object to the specified shape's paths. + * + * @param[in] clipper The shape object as the clipper. + * + * @retval Result::InsufficientCondition if the @p clipper has already belonged to another paint. + * + * @see Paint::clip() + * + * @since 1.0 + */ + Result clip(Shape* clipper) noexcept; + + /** + * @brief Sets the blending method for the paint object. + * + * The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. + * its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. + * The blending operation is determined by the chosen @p BlendMethod, which specifies how the colors or images are combined. + * + * @param[in] method The blending method to be set. + * + * @since 1.0 + */ + Result blend(BlendMethod method) noexcept; + + /** + * @brief Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space. + * + * This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. + * The returned values @p pt4 may have invalid if the operation fails. Thus, please check the retval. + * + * This bounding box can be used to obtain the transformed bounding region in canvas space + * by taking the geometry's axis-aligned bounding box (AABB) in the object's local coordinate space + * and applying the object's transformations. + * + * @param[out] pt4 An array of four points representing the bounding box. The array size must be 4. + * + * @retval Result::InsufficientCondition If the paint has not been updated by the canvas. + * + * @see Paint::bounds(float* x, float* y, float* w, float* h) + * @see Canvas::update() + * + * @since 1.0 + */ + Result bounds(Point* pt4) noexcept; + + /** + * @brief Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space. + * + * Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. + * The returned values @p x, @p y, @p w, @p h, may have invalid if the operation fails. Thus, please check the retval. + * + * This bounding box can be used to determine the actual rendered area of the object on the canvas, + * for purposes such as hit-testing, culling, or layout calculations. + * + * @param[out] x The x-coordinate of the upper-left corner of the bounding box. + * @param[out] y The y-coordinate of the upper-left corner of the bounding box. + * @param[out] w The width of the bounding box. + * @param[out] h The height of the bounding box. + * + * @retval Result::InsufficientCondition If the paint has not been updated by the canvas. + * + * @see Paint::bounds(Point* pt4) + * @see Canvas::update() + */ + Result bounds(float* x, float* y, float* w, float* h) noexcept; + + /** + * @brief Checks whether a given region intersects the filled area of the paint. + * + * This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— + * intersects the geometric fill region of the paint object. + * + * This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) + * occurs within a painted region. + * + * The paint must be updated in a Canvas beforehand—typically after the Canvas has been + * drawn and synchronized. + * + * @param[in] x The x-coordinate of the top-left corner of the test region. + * @param[in] y The y-coordinate of the top-left corner of the test region. + * @param[in] w The width of the region to test. Must be greater than 0; defaults to 1. + * @param[in] h The height of the region to test. Must be greater than 0; defaults to 1. + * + * @return @c true if any part of the region intersects the filled area; otherwise, @c false. + * + * @note To test a single point, set the region size to w = 1, h = 1. + * @note For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection. + * @note This test does not take into account the results of blending or masking. + * @note This test does take into account the the hidden paints as well. @see Paint::visible() + * @since 1.0 + */ + bool intersects(int32_t x, int32_t y, int32_t w = 1, int32_t h = 1) noexcept; + + /** + * @brief Duplicates the object. + * + * Creates a new object and sets its all properties as in the original object. + * + * @return The created object when succeed, @c nullptr otherwise. + */ + Paint* duplicate() const noexcept; + + /** + * @brief Gets the opacity value of the object. + * + * @return The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + */ + uint8_t opacity() const noexcept; + + /** + * @brief Gets the masking target object and the masking method. + * + * @param[out] target The paint of the target object. + * + * @return The method used to mask the source object with the target. + * + * @since 0.5 + */ + MaskMethod mask(const Paint** target) const noexcept; + + /** + * @brief Get the clipper shape of the paint object. + * + * This function returns the clipper that has been previously set to this paint object. + * + * @return The shape object used as the clipper, or @c nullptr if no clipper is set. + * + * @see Paint::clip(Shape* clipper) + * + * @since 1.0 + */ + Shape* clip() const noexcept; + + /** + * @brief Gets the current visibility status of the Paint object. + * + * @return true if the object is visible and will be rendered. + * false if the object is hidden and will not be rendered. + * + * @see Paint::visible(bool on) + * + * @since 1.0 + */ + bool visible() const noexcept; + + /** + * @brief Increment the reference count for the Paint instance. + * + * This method increases the reference count of the Paint object, allowing shared ownership and control over its lifetime. + * + * @return The updated reference count after the increment by 1. + * + * @warning Please ensure that each call to ref() is paired with a corresponding call to unref() to prevent a dangling instance. + * + * @see Paint::unref() + * @see Paint::refCnt() + * + * @since 1.0 + */ + uint16_t ref() noexcept; + + /** + * @brief Decrement the reference count for the Paint instance. + * + * This method decreases the reference count of the Paint object by 1. + * If the reference count reaches zero and the @p free flag is set to true, the Paint instance is automatically deleted. + * + * @param[in] free Flag indicating whether to delete the Paint instance when the reference count reaches zero. + * + * @return The updated reference count after the decrement. + * + * @see Paint::ref() + * @see Paint::refCnt() + * + * @since 1.0 + */ + uint16_t unref(bool free = true) noexcept; + + /** + * @brief Retrieve the current reference count of the Paint instance. + * + * This method provides the current reference count, allowing the user to check the shared ownership state of the Paint object. + * + * @return The current reference count of the Paint instance. + * + * @see Paint::ref() + * @see Paint::unref() + * + * @since 1.0 + */ + uint16_t refCnt() const noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the Paint instance. + * + * @since 1.0 + */ + virtual Type type() const noexcept = 0; + + /** + * @brief Unique ID of this instance. + * + * This is reserved to specify an paint instance in a scene. + * + * @since 1.0 + */ + uint32_t id = 0; + + /** + * @brief Safely releases a Paint object. + * + * This is the counterpart to the `gen()` API, and releases the given Paint object safely, + * handling @c nullptr and managing ownership properly. + * + * @param[in] paint A Paint object to release. + * + * @since 1.0 + */ + static void rel(Paint* paint) noexcept; + +protected: + virtual ~Paint(); + + _TVG_DECLARE_PRIVATE_BASE(Paint); +}; + + +/** + * @class Fill + * + * @brief An abstract class representing the gradient fill of the Shape object. + * + * It contains the information about the gradient colors and their arrangement + * inside the gradient bounds. The gradients bounds are defined in the LinearGradient + * or RadialGradient class, depending on the type of the gradient to be used. + * It specifies the gradient behavior in case the area defined by the gradient bounds + * is smaller than the area to be filled. + */ +struct TVG_API Fill +{ + /** + * @brief A data structure storing the information about the color and its relative position inside the gradient bounds. + */ + struct ColorStop + { + float offset; /**< The relative position of the color. */ + uint8_t r; /**< The red color channel value in the range [0 ~ 255]. */ + uint8_t g; /**< The green color channel value in the range [0 ~ 255]. */ + uint8_t b; /**< The blue color channel value in the range [0 ~ 255]. */ + uint8_t a; /**< The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. */ + }; + + virtual ~Fill(); + + /** + * @brief Sets the parameters of the colors of the gradient and their position. + * + * @param[in] colorStops An array of ColorStop data structure. + * @param[in] cnt The count of the @p colorStops array equal to the colors number used in the gradient. + */ + Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept; + + /** + * @brief Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds. + * + * @param[in] s The FillSpread value. + */ + Result spread(FillSpread s) noexcept; + + /** + * @brief Sets the matrix of the affine transformation for the gradient fill. + * + * The augmented matrix of the transformation is expected to be given. + * + * @param[in] m The 3x3 augmented matrix. + */ + Result transform(const Matrix& m) noexcept; + + /** + * @brief Gets the parameters of the colors of the gradient, their position and number. + * + * @param[out] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored. + * + * @return The number of colors used in the gradient. This value corresponds to the length of the @p colorStops array. + */ + uint32_t colorStops(const ColorStop** colorStops) const noexcept; + + /** + * @brief Gets the FillSpread value of the fill. + * + * @return The FillSpread value of this Fill. + */ + FillSpread spread() const noexcept; + + /** + * @brief Gets the matrix of the affine transformation of the gradient fill. + * + * In case no transformation was applied, the identity matrix is returned. + * + * @return The augmented transformation matrix. + */ + Matrix& transform() const noexcept; + + /** + * @brief Creates a copy of the Fill object. + * + * Return a newly created Fill object with the properties copied from the original. + * + * @return A copied Fill object when succeed, @c nullptr otherwise. + */ + Fill* duplicate() const noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the Fill instance. + * + * @since 1.0 + */ + virtual Type type() const noexcept = 0; + + _TVG_DECLARE_PRIVATE_BASE(Fill); +}; + + +/** + * @class Canvas + * + * @brief An abstract class for drawing graphical elements. + * + * A canvas is an entity responsible for drawing the target. It sets up the drawing engine and the buffer, which can be drawn on the screen. It also manages given Paint objects. + * + * @note A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical. + * @warning The Paint objects belonging to one Canvas can't be shared among multiple Canvases. + */ +struct TVG_API Canvas +{ + virtual ~Canvas(); + + /** + * @brief Returns the list of paints currently held by the Canvas. + * + * This function provides a list of paint nodes, allowing users to access scene-graph information. + * + * @warning Please avoid accessing the paints during Canvas update/draw. You can access them after calling sync(). + * @see Canvas::add() + * @see Canvas::remove() + * + * @warning This is read-only. Do not modify the list. + * @note 1.0 + */ + const std::list& paints() const noexcept; + + /** + * @brief Adds a paint object to the canvas root scene. + * + * Appends a paint object to the root scene of the canvas. If the optional @p at + * parameter is provided, the paint object is inserted immediately before the + * specified paint in the root scene. If @p at is @c nullptr, the paint object + * is appended to the end of the root scene. + * + * @param[in] target A pointer to the Paint object to be added to the root scene. + * This parameter must not be @c nullptr. + * @param[in] at A pointer to an existing Paint object in the root scene + * before which @p target will be inserted. If @c nullptr, + * @p target is appended to the end of the root scene. + * The default value is @c nullptr. + * + * @note Ownership of the @p target object is transferred to the canvas upon + * successful addition. To retain ownership, call @ref Paint::ref() + * before adding it to the canvas. + * @note The rendering order of paint objects follows their order in the root + * scene. If layering is required, ensure the paints are added in the + * desired order. + * + * @see Canvas::paints() + * @see Canvas::remove() + * @see Paint::ref() + * + * @since 1.0 + */ + Result add(Paint* target, Paint* at = nullptr) noexcept; + + /** + * @brief Removes a paint object or all paint objects from the root scene. + * + * This function removes a specified paint object from the root scene. If no paint + * object is specified (i.e., the default @c nullptr is used), the function + * performs to clear all paints from the root scene. + * + * @param[in] paint A pointer to the Paint object to be removed from the root scene. + * If @c nullptr, remove all the paints from the root scene. + * + * @see Canvas::add() + * @see Canvas::paints() + * + * @since 1.0 + */ + Result remove(Paint* paint = nullptr) noexcept; + + /** + * @brief Requests the canvas to update modified paint objects in preparation for rendering. + * + * This function triggers an internal update for all paint instances that have been modified + * since the last update. It ensures that the canvas state is ready for accurate rendering. + * + * @retval Result::InsufficientCondition The canvas is not properly prepared. + * This may occur if the canvas target has not been set or if the update is called during drawing. + * Call Canvas::sync() before trying. + * + * @note Only paint objects that have been changed will be processed. + * @note If the canvas is configured with multiple threads, the update may be performed asynchronously. + * + * @see Canvas::sync() + */ + Result update() noexcept; + + /** + * @brief Requests the canvas to render the Paint objects. + * + * @param[in] clear If @c true, clears the target buffer to zero before drawing. + * + * @retval Result::InsufficientCondition The canvas is not properly prepared. + * This may occur if Canvas::target() has not been set or if draw() is called multiple times + * without calling Canvas::sync() in between. + * + * @note Clearing the buffer is unnecessary if the canvas will be fully covered + * with opaque content. Skipping the clear can improve performance. + * @note Drawing may be performed asynchronously if the thread count is greater than zero. + * To ensure the drawing process is complete, call sync() afterwards. + * @note If the canvas has not been updated prior to Canvas::draw(), it may implicitly perform Canvas::update(). + * + * @see Canvas::sync() + * @see Canvas::update() + */ + Result draw(bool clear = false) noexcept; + + /** + * @brief Sets the drawing region of the canvas. + * + * This function defines a rectangular area of the canvas to be used for drawing operations. + * The specified viewport clips rendering output to the boundaries of that rectangle. + * + * Please note that changing the viewport is only allowed at the beginning of the rendering sequence—that is, after calling Canvas::sync(). + * + * @param[in] x The x-coordinate of the upper-left corner of the rectangle. + * @param[in] y The y-coordinate of the upper-left corner of the rectangle. + * @param[in] w The width of the rectangle. + * @param[in] h The height of the rectangle. + * + * @retval Result::InsufficientCondition If the canvas is not in a synced state. + * + * @see Canvas::sync() + * @see SwCanvas::target() + * @see GlCanvas::target() + * @see WgCanvas::target() + * + * @warning Changing the viewport is not allowed after calling Canvas::add(), + * Canvas::remove(), Canvas::update(), or Canvas::draw(). + * + * @note When the target is reset, the viewport will also be reset to match the target size. + * @since 0.15 + */ + Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept; + + /** + * @brief Guarantees that drawing task is finished. + * + * The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, + * the sync() must be called after the draw() regardless of threading. + * + * @see Canvas::draw() + */ + Result sync() noexcept; + + _TVG_DECLARE_PRIVATE_BASE(Canvas); +}; + + +/** + * @class LinearGradient + * + * @brief A class representing the linear gradient fill of the Shape object. + * + * Besides the APIs inherited from the Fill class, it enables setting and getting the linear gradient bounds. + * The behavior outside the gradient bounds depends on the value specified in the spread API. + * + * @warning This class is not designed for inheritance. + */ +struct TVG_API LinearGradient : Fill +{ + /** + * @brief Sets the linear gradient bounds. + * + * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing + * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking + * (@p x1, @p y1) and (@p x2, @p y2). + * + * @param[in] x1 The horizontal coordinate of the first point used to determine the gradient bounds. + * @param[in] y1 The vertical coordinate of the first point used to determine the gradient bounds. + * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds. + * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds. + * + * @note In case the first and the second points are equal, an object is filled with a single color using the last color specified in the colorStops(). + * @see Fill::colorStops() + */ + Result linear(float x1, float y1, float x2, float y2) noexcept; + + /** + * @brief Gets the linear gradient bounds. + * + * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing + * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking + * (@p x1, @p y1) and (@p x2, @p y2). + * + * @param[out] x1 The horizontal coordinate of the first point used to determine the gradient bounds. + * @param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds. + * @param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds. + * @param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds. + */ + Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept; + + /** + * @brief Creates a new LinearGradient object. + * + * @return A new LinearGradient object. + */ + static LinearGradient* gen() noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the LinearGradient instance. + * + * @since 1.0 + */ + Type type() const noexcept override; + + _TVG_DECLARE_PRIVATE(LinearGradient); +}; + + +/** + * @class RadialGradient + * + * @brief A class representing the radial gradient fill of the Shape object. + * + * @warning This class is not designed for inheritance. + */ +struct TVG_API RadialGradient : Fill +{ + /** + * @brief Sets the radial gradient attributes. + * + * The radial gradient is defined by the end circle with a center (@p cx, @p cy) and a radius @p r and + * the start circle with a center/focal point (@p fx, @p fy) and a radius @p fr. + * The gradient will be rendered such that the gradient stop at an offset of 100% aligns with the edge of the end circle + * and the stop at an offset of 0% aligns with the edge of the start circle. + * + * @param[in] cx The horizontal coordinate of the center of the end circle. + * @param[in] cy The vertical coordinate of the center of the end circle. + * @param[in] r The radius of the end circle. + * @param[in] fx The horizontal coordinate of the center of the start circle. + * @param[in] fy The vertical coordinate of the center of the start circle. + * @param[in] fr The radius of the start circle. + * + * @retval Result::InvalidArguments in case the radius @p r or @p fr value is negative. + * + * @note In case the radius @p r is zero, an object is filled with a single color using the last color specified in the colorStops(). + * @note In case the focal point (@p fx and @p fy) lies outside the end circle, it is projected onto the edge of the end circle. + * @note If the start circle doesn't fully fit inside the end circle (after possible repositioning), the @p fr is reduced accordingly. + * @note By manipulating the position and size of the focal point, a wide range of visual effects can be achieved, such as directing + * the gradient focus towards a specific edge or enhancing the depth and complexity of shading patterns. + * If a focal effect is not desired, simply align the focal point (@p fx and @p fy) with the center of the end circle (@p cx and @p cy) + * and set the radius (@p fr) to zero. This will result in a uniform gradient without any focal variations. + */ + Result radial(float cx, float cy, float r, float fx, float fy, float fr) noexcept; + + /** + * @brief Gets the radial gradient attributes. + * + * @param[out] cx The horizontal coordinate of the center of the end circle. + * @param[out] cy The vertical coordinate of the center of the end circle. + * @param[out] r The radius of the end circle. + * @param[out] fx The horizontal coordinate of the center of the start circle. + * @param[out] fy The vertical coordinate of the center of the start circle. + * @param[out] fr The radius of the start circle. + * + * @see RadialGradient::radial() + */ + Result radial(float* cx, float* cy, float* r, float* fx = nullptr, float* fy = nullptr, float* fr = nullptr) const noexcept; + + /** + * @brief Creates a new RadialGradient object. + * + * @return A new RadialGradient object. + */ + static RadialGradient* gen() noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the LinearGradient instance. + * + * @since 1.0 + */ + Type type() const noexcept override; + + _TVG_DECLARE_PRIVATE(RadialGradient); +}; + + +/** + * @class Shape + * + * @brief A class representing two-dimensional figures and their properties. + * + * A shape has three major properties: shape outline, stroking, filling. The outline in the Shape is retained as the path. + * Path can be composed by accumulating primitive commands such as moveTo(), lineTo(), cubicTo(), or complete shape interfaces such as appendRect(), appendCircle(), etc. + * Path can consists of sub-paths. One sub-path is determined by a close command. + * + * The stroke of Shape is an optional property in case the Shape needs to be represented with/without the outline borders. + * It's efficient since the shape path and the stroking path can be shared with each other. It's also convenient when controlling both in one context. + * + * @warning This class is not designed for inheritance. + */ +struct TVG_API Shape : Paint +{ + /** + * @brief Resets the shape path. + * + * The transformation matrix, color, fill, and stroke properties are retained. + * + * @note The memory where the path data is stored is not deallocated at this stage to allow for caching. + */ + Result reset() noexcept; + + /** + * @brief Sets the initial point of the sub-path. + * + * The value of the current point is set to the given point. + * + * @param[in] x The horizontal coordinate of the initial point of the sub-path. + * @param[in] y The vertical coordinate of the initial point of the sub-path. + */ + Result moveTo(float x, float y) noexcept; + + /** + * @brief Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point. + * + * The value of the current point is set to the given end-point. + * + * @param[in] x The horizontal coordinate of the end-point of the line. + * @param[in] y The vertical coordinate of the end-point of the line. + * + * @note In case this is the first command in the path, it corresponds to the moveTo() call. + */ + Result lineTo(float x, float y) noexcept; + + /** + * @brief Adds new points to the sub-path, which results in drawing a cubic Bezier curve starting + * at the current point and ending at the given end-point (@p x, @p y) using the control points (@p cx1, @p cy1) and (@p cx2, @p cy2). + * + * The value of the current point is set to the given end-point. + * + * @param[in] cx1 The horizontal coordinate of the 1st control point. + * @param[in] cy1 The vertical coordinate of the 1st control point. + * @param[in] cx2 The horizontal coordinate of the 2nd control point. + * @param[in] cy2 The vertical coordinate of the 2nd control point. + * @param[in] x The horizontal coordinate of the end-point of the curve. + * @param[in] y The vertical coordinate of the end-point of the curve. + * + * @note In case this is the first command in the path, no data from the path are rendered. + */ + Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept; + + /** + * @brief Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path. + * + * The value of the current point is set to the initial point of the closed sub-path. + * + * @note In case the sub-path does not contain any points, this function has no effect. + */ + Result close() noexcept; + + /** + * @brief Appends a rectangle to the path. + * + * The rectangle with rounded corners can be achieved by setting non-zero values to @p rx and @p ry arguments. + * The @p rx and @p ry values specify the radii of the ellipse defining the rounding of the corners. + * + * The position of the rectangle is specified by the coordinates of its upper-left corner - @p x and @p y arguments. + * + * The rectangle is treated as a new sub-path - it is not connected with the previous sub-path. + * + * The value of the current point is set to (@p x + @p rx, @p y) - in case @p rx is greater + * than @p w/2 the current point is set to (@p x + @p w/2, @p y) + * + * @param[in] x The horizontal coordinate of the upper-left corner of the rectangle. + * @param[in] y The vertical coordinate of the upper-left corner of the rectangle. + * @param[in] w The width of the rectangle. + * @param[in] h The height of the rectangle. + * @param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle. + * @param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle. + * @param[in] cw Specifies the path direction: @c true for clockwise, @c false for counterclockwise. + * + * @note For @p rx and @p ry greater than or equal to the half of @p w and the half of @p h, respectively, the shape become an ellipse. + */ + Result appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0, bool cw = true) noexcept; + + /** + * @brief Appends an ellipse to the path. + * + * The position of the ellipse is specified by the coordinates of its center - @p cx and @p cy arguments. + * + * The ellipse is treated as a new sub-path - it is not connected with the previous sub-path. + * + * The value of the current point is set to (@p cx, @p cy - @p ry). + * + * @param[in] cx The horizontal coordinate of the center of the ellipse. + * @param[in] cy The vertical coordinate of the center of the ellipse. + * @param[in] rx The x-axis radius of the ellipse. + * @param[in] ry The y-axis radius of the ellipse. + * @param[in] cw Specifies the path direction: @c true for clockwise, @c false for counterclockwise. + * + */ + Result appendCircle(float cx, float cy, float rx, float ry, bool cw = true) noexcept; + + /** + * @brief Appends a given sub-path to the path. + * + * The current point value is set to the last point from the sub-path. + * For each command from the @p cmds array, an appropriate number of points in @p pts array should be specified. + * If the number of points in the @p pts array is different than the number required by the @p cmds array, the shape with this sub-path will not be displayed on the screen. + * + * @param[in] cmds The array of the commands in the sub-path. + * @param[in] cmdCnt The number of the sub-path's commands. + * @param[in] pts The array of the two-dimensional points. + * @param[in] ptsCnt The number of the points in the @p pts array. + * + * @note The interface is designed for optimal path setting if the caller has a completed path commands already. + */ + Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept; + + /** + * @brief Sets the stroke width for the path. + * + * This function defines the thickness of the stroke applied to all figures + * in the path object. A stroke is the outline drawn along the edges of the + * path's geometry. + * + * @param[in] width The width of the stroke in pixels. Must be positive value. (The default is 0) + * + * @note A value of @p width 0 disables the stroke. + * + * @see strokeFill() + */ + Result strokeWidth(float width) noexcept; + + /** + * @brief Sets the stroke color for the path. + * + * This function defines the RGBA color of the stroke applied to all figures + * in the path object. The stroke color is used when rendering the outline + * of the path geometry. + * + * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. + * + * @note If the stroke width is 0 (default), the stroke will not be visible regardless of the color. + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * + * @see strokeWidth() + * @see strokeFill(Fill* f) + */ + Result strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept; + + /** + * @brief Sets the gradient fill of the stroke for all of the figures from the path. + * + * @param[in] f The gradient fill. + * + * @retval Result::InvalidArgument In case a @c nullptr is passed as the argument. + * + * @note If the stroke width is 0 (default), the stroke will not be visible regardless of the color. + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * + * @see strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + */ + Result strokeFill(Fill* f) noexcept; + + /** + * @brief Sets the dash pattern of the stroke. + * + * @param[in] dashPattern An array of alternating dash and gap lengths. + * @param[in] cnt The length of the @p dashPattern array. + * @param[in] offset The shift of the starting point within the repeating dash pattern, from which the pattern begins to be applied. + * + * @retval Result::InvalidArguments In case @p dashPattern is @c nullptr and @p cnt > 0 or @p dashPattern is not @c nullptr and @p cnt is zero. + * + * @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt. + * @note Values of @p dashPattern less than zero are treated as zero. + * @note If all values in the @p dashPattern are equal to or less than 0, the dash is ignored. + * @note If the @p dashPattern contains an odd number of elements, the sequence is repeated in the same + * order to form an even-length pattern, preserving the alternation of dashes and gaps. + * + * @since 1.0 + */ + Result strokeDash(const float* dashPattern, uint32_t cnt, float offset = 0.0f) noexcept; + + /** + * @brief Sets the cap style of the stroke in the open sub-paths. + * + * @param[in] cap The cap style value. The default value is @c StrokeCap::Square. + * + */ + Result strokeCap(StrokeCap cap) noexcept; + + /** + * @brief Sets the join style for stroked path segments. + * + * The join style is used for joining the two line segment while stroking the path. + * + * @param[in] join The join style value. The default value is @c StrokeJoin::Bevel. + * + */ + Result strokeJoin(StrokeJoin join) noexcept; + + /** + * @brief Sets the stroke miterlimit. + * + * @param[in] miterlimit The miterlimit imposes a limit on the extent of the stroke join, when the @c StrokeJoin::Miter join style is set. The default value is 4. + * + * @retval Result::InvalidArgument for @p miterlimit values less than zero. + * + * @since 0.11 + */ + Result strokeMiterlimit(float miterlimit) noexcept; + + /** + * @brief Sets the trim of the shape along the defined path segment, allowing control over which part of the shape is visible. + * + * If the values of the arguments @p begin and @p end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular. + * + * @param[in] begin Specifies the start of the segment to display along the path. + * @param[in] end Specifies the end of the segment to display along the path. + * @param[in] simultaneous Determines how to trim multiple paths within a single shape. If set to @c true (default), trimming is applied simultaneously to all paths; + * Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such. + * + * @since 1.0 + */ + Result trimpath(float begin, float end, bool simultaneous = true) noexcept; + + /** + * @brief Sets the solid color for all of the figures from the path. + * + * The parts of the shape defined as inner are colored. + * + * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + */ + Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept; + + /** + * @brief Sets the gradient fill for all of the figures from the path. + * + * The parts of the shape defined as inner are filled. + * + * @param[in] f The unique pointer to the gradient fill. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + */ + Result fill(Fill* f) noexcept; + + /** + * @brief Sets the fill rule for the shape. + * + * Specifies how the interior of the shape is determined when its path intersects itself. + * The default fill rule is @c FillRule::NonZero. + * + * @param[in] r The fill rule to apply to the shape. + */ + Result fillRule(FillRule r) noexcept; + + /** + * @brief Sets the rendering order of the stroke and the fill. + * + * @param[in] strokeFirst If @c true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option). + * + * @since 0.10 + */ + Result order(bool strokeFirst) noexcept; + + /** + * @brief Retrieves the current path data of the shape. + * + * This function provides access to the shape's path data, including the commands + * and points that define the path. + * + * @param[out] cmds Pointer to the array of commands representing the path. + * Can be @c nullptr if this information is not needed. + * @param[out] cmdsCnt Pointer to the variable that receives the number of commands in the @p cmds array. + * Can be @c nullptr if this information is not needed. + * @param[out] pts Pointer to the array of two-dimensional points that define the path. + * Can be @c nullptr if this information is not needed. + * @param[out] ptsCnt Pointer to the variable that receives the number of points in the @p pts array. + * Can be @c nullptr if this information is not needed. + */ + Result path(const PathCommand** cmds, uint32_t* cmdsCnt, const Point** pts, uint32_t* ptsCnt) const noexcept; + + /** + * @brief Gets the pointer to the gradient fill of the shape. + * + * @return The pointer to the gradient fill of the stroke when succeed, @c nullptr in case no fill was set. + */ + const Fill* fill() const noexcept; + + /** + * @brief Gets the solid color of the shape. + * + * @param[out] r The red color channel value in the range [0 ~ 255]. + * @param[out] g The green color channel value in the range [0 ~ 255]. + * @param[out] b The blue color channel value in the range [0 ~ 255]. + * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + */ + Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept; + + /** + * @brief Retrieves the current fill rule used by the shape. + * + * This function returns the fill rule, which determines how the interior + * regions of the shape are calculated when it overlaps itself. + * + * @see Shape::fillRule(FillRule r) + * @return The current FillRule value of the shape. + */ + FillRule fillRule() const noexcept; + + /** + * @brief Gets the stroke width. + * + * @return The stroke width value when succeed, zero if no stroke was set. + */ + float strokeWidth() const noexcept; + + /** + * @brief Gets the color of the shape's stroke. + * + * @param[out] r The red color channel value in the range [0 ~ 255]. + * @param[out] g The green color channel value in the range [0 ~ 255]. + * @param[out] b The blue color channel value in the range [0 ~ 255]. + * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + */ + Result strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept; + + /** + * @brief Gets the pointer to the gradient fill of the stroke. + * + * @return The pointer to the gradient fill of the stroke when succeed, @c nullptr otherwise. + */ + const Fill* strokeFill() const noexcept; + + /** + * @brief Gets the dash pattern of the stroke. + * + * @param[out] dashPattern The pointer to the memory, where the dash pattern array is stored. + * @param[out] offset The shift of the starting point within the repeating dash pattern. + * + * @return The length of the @p dashPattern array. + * + * @since 1.0 + */ + uint32_t strokeDash(const float** dashPattern, float* offset = nullptr) const noexcept; + + /** + * @brief Gets the cap style used for stroking the path. + * + * @return The cap style value of the stroke. + */ + StrokeCap strokeCap() const noexcept; + + /** + * @brief Gets the join style value used for stroking the path. + * + * @return The join style value of the stroke. + */ + StrokeJoin strokeJoin() const noexcept; + + /** + * @brief Gets the stroke miterlimit. + * + * @return The stroke miterlimit value when succeed, 4 if no stroke was set. + * + * @since 0.11 + */ + float strokeMiterlimit() const noexcept; + + /** + * @brief Creates a new Shape object. + * + * This function allocates and returns a new Shape instance. + * To properly destroy the Shape object, use @ref Paint::rel(). + * + * @return A pointer to the newly created Shape object. + * + * @see Paint::rel() + */ + static Shape* gen() noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the Shape instance. + * + * @since 1.0 + */ + Type type() const noexcept override; + + _TVG_DECLARE_PRIVATE_DERIVE(Shape); +}; + + +/** + * @class Picture + * + * @brief A class representing an image read in one of the supported formats: raw, svg, png, jpg, lot and etc. + * Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas. + * + * @note Supported formats are depended on the available TVG loaders. + * @note See Animation class if the picture data is animatable. + * + * @warning This class is not designed for inheritance. + */ +struct TVG_API Picture : Paint +{ + /** + * @brief Loads a picture data directly from a file. + * + * ThorVG efficiently caches the loaded data using the specified @p path as a key. + * This means that loading the same file again will not result in duplicate operations; + * instead, ThorVG will reuse the previously loaded picture data. + * + * @param[in] filename A file name, including the path, for the picture file. + * + * @retval Result::InvalidArguments In case the @p path is invalid. + * @retval Result::NonSupport When trying to load a file with an unknown extension. + * + * @note The Load behavior can be asynchronous if the assigned thread number is greater than zero. + * @see Initializer::init() + */ + Result load(const char* filename) noexcept; + + /** + * @brief Loads a picture data from a memory block of a given size. + * + * ThorVG efficiently caches the loaded data using the specified @p data address as a key + * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations + * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. + * + * @param[in] data A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if @p copy is @c false. + * @param[in] size The size in bytes of the memory occupied by the @p data. + * @param[in] mimeType Mimetype or extension of data such as "jpg", "jpeg", "lot", "lottie+json", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. + * @param[in] rpath A resource directory path, if the @p data needs to access any external resources. + * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. + * + * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less. + * @retval Result::NonSupport When trying to load a file with an unknown extension. + * + * @warning It's the user responsibility to release the @p data memory. + * + * @note If you are unsure about the MIME type, you can provide an empty value like @c nullptr, and thorvg will attempt to figure it out. + * @since 0.5 + */ + Result load(const char* data, uint32_t size, const char* mimeType, const char* rpath = nullptr, bool copy = false) noexcept; + + /** + * @brief Resizes the picture content to the given width and height. + * + * The picture content is resized while keeping the default size aspect ratio. + * The scaling factor is established for each of dimensions and the smaller value is applied to both of them. + * + * @param[in] w A new width of the image in pixels. + * @param[in] h A new height of the image in pixels. + * + */ + Result size(float w, float h) noexcept; + + /** + * @brief Gets the size of the image. + * + * @param[out] w The width of the image in pixels. + * @param[out] h The height of the image in pixels. + * + */ + Result size(float* w, float* h) const noexcept; + + /** + * @brief Sets the normalized origin point of the Picture object. + * + * This method defines the origin point of the Picture using normalized coordinates. + * Unlike a typical pivot point used only for transformations, this origin affects both + * the transformation behavior and the actual rendering position of the Picture. + * + * The specified origin becomes the reference point for positioning the Picture on the canvas. + * For example, setting the origin to (0.5f, 0.5f) moves the visual center of the picture + * to the position specified by Paint::translate(). + * + * The coordinates are given in a normalized range relative to the picture's bounds: + * - (0.0f, 0.0f): top-left corner + * - (0.5f, 0.5f): center + * - (1.0f, 1.0f): bottom-right corner + * + * @param[in] x The normalized x-coordinate of the origin point (range: 0.0f to 1.0f). + * @param[in] y The normalized y-coordinate of the origin point (range: 0.0f to 1.0f). + * + * @note This origin directly affects how the Picture is placed on the canvas when using + * transformations such as translate(), rotate(), or scale(). + * + * @see Paint::translate() + * @see Paint::rotate() + * @see Paint::scale() + * + * @since 1.0 + */ + Result origin(float x, float y) noexcept; + + /** + * @brief Gets the normalized origin point of the Picture object. + * + * This method retrieves the current origin point of the Picture, expressed + * in normalized coordinates relative to the picture’s bounds. + * + * @param[out] x The normalized x-coordinate of the origin (range: 0.0f to 1.0f). + * @param[out] y The normalized y-coordinate of the origin (range: 0.0f to 1.0f). + * + * @see origin() + * @since 1.0 + */ + Result origin(float* x, float* y) const noexcept; + + /** + * @brief Loads raw image data in a specific format from a memory block of the given size. + * + * ThorVG efficiently caches the loaded data, using the provided @p data address as a key + * when @p copy is set to @c false. This allows ThorVG to avoid redundant operations + * by reusing the previously loaded picture data for the same sharable @p data, + * rather than duplicating the load process. + * + * @param[in] data A pointer to the memory block where the raw image data is stored. + * @param[in] w The width of the image in pixels. + * @param[in] h The height of the image in pixels. + * @param[in] cs Specifies how the 32-bit color values should be interpreted. + * @param[in] copy If @c true, the data is copied into the engine's local buffer. If @c false, the data is not copied. + * + * @since 0.9 + */ + Result load(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy = false) noexcept; + + /** + * @brief Sets the asset resolver callback for handling external resources (e.g., images and fonts). + * + * This callback is invoked when an external asset reference (such as an image source or file path) + * is encountered in a Picture object. It allows the user to provide a custom mechanism for loading + * or substituting assets, such as loading from an external source or a virtual filesystem. + * + * @param[in] func A user-defined function that handles the resolution of asset paths. + * @p resolver can return @c true if the asset was successfully resolved by the user, or @c false if it was not. + * @param[in] data A pointer to user-defined data that will be passed to the callback each time it is invoked. + * This can be used to maintain context or access external resources. + * + * @retval Result::InsufficientCondition If the picture is already loaded. + * + * @note This function must be called before @ref Picture::load() + * Setting the resolver after loading will have no effect on asset resolution for that asset. + * @note If @c false is returned by @p func, ThorVG will attempt to resolve the resource using its internal resolution mechanism as a fallback. + * @note To unset the resolver, pass @c nullptr as the @p func parameter. + * @note Experimental API + */ + Result resolver(std::function func, void* data) noexcept; + + /** + * @brief Retrieve a paint object from the Picture scene by its Unique ID. + * + * This function searches for a paint object within the Picture scene that matches the provided @p id. + * + * @param[in] id The Unique ID of the paint object. + * + * @return A pointer to the paint object that matches the given identifier, or @c nullptr if no matching paint object is found. + * + * @see Accessor::id() + * + * @since 1.0 + */ + const Paint* paint(uint32_t id) noexcept; + + /** + * @brief Creates a new Picture object. + * + * This function allocates and returns a new Picture instance. + * To properly destroy the Picture object, use @ref Paint::rel(). + * + * @return A pointer to the newly created Picture object. + * + * @see Paint::rel() + */ + static Picture* gen() noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the Picture instance. + * + * @since 1.0 + */ + Type type() const noexcept override; + + _TVG_DECLARE_ACCESSOR(Animation); + _TVG_DECLARE_PRIVATE_DERIVE(Picture); +}; + + +/** + * @class Scene + * + * @brief A class to composite children paints. + * + * As the traditional graphics rendering method, TVG also enables scene-graph mechanism. + * This feature supports an array function for managing the multiple paints as one group paint. + * + * As a group, the scene can be transformed, made translucent and composited with other target paints, + * its children will be affected by the scene world. + * + * @warning This class is not designed for inheritance. + */ +struct TVG_API Scene : Paint +{ + /** + * @brief Adds a paint object to the scene. + * + * Appends a paint object to the scene. If the optional @p at parameter is provided, + * the paint object is inserted immediately before the specified paint in the scene. + * If @p at is @c nullptr, the paint object is appended to the end of the scene. + * + * @param[in] target A pointer to the Paint object to be added to the scene. + * This parameter must not be @c nullptr. + * @param[in] at A pointer to an existing Paint object in the scene before + * which @p target will be inserted. If @c nullptr, + * @p target is appended to the end of the scene. + * The default value is @c nullptr. + * + * @note Ownership of the @p target object is transferred to the scene upon + * successful addition. To retain ownership, call @ref Paint::ref() + * before adding it to the scene. + * @note The rendering order of paint objects follows their order in the scene. + * If layering is required, ensure the paints are added in the desired order. + * + * @see Scene::paints() + * @see Scene::remove() + * @see Paint::ref() + * + * @since 1.0 + */ + Result add(Paint* target, Paint* at = nullptr) noexcept; + + /** + * @brief Returns the list of paints currently held by the Scene. + * + * This function provides a list of paint nodes, allowing users to access scene-graph information. + * + * @see Scene::add() + * @see Scene::remove() + * + * @warning This is read-only. Do not modify the list. + * @since 1.0 + */ + const std::list& paints() const noexcept; + + /** + * @brief Removes a paint object or all paint objects from the scene. + * + * This function removes a specified paint object from the scene. If no paint + * object is specified (i.e., the default @c nullptr is used), the function + * performs to clear all paints from the scene. + * + * @param[in] paint A pointer to the Paint object to be removed from the scene. + * If @c nullptr, remove all the paints from the scene. + * + * @see Scene::add() + * @see Scene::paints() + * + * @since 1.0 + */ + Result remove(Paint* paint = nullptr) noexcept; + + /** + * @brief Add a post-processing effect to the scene. + * + * Adds a post-processing effect to the scene's effect pipeline, which is applied + * after the scene has been rendered. Effects are applied cumulatively and in the + * order they are added. Calling this function multiple times will chain multiple + * effects sequentially. + * + * Certain effects may be used to modify the pipeline behavior itself. For example, + * @c SceneEffect::Clear removes all previously added effects. + * + * @param[in] effect The scene effect to add. Available effects are defined in the @ref SceneEffect enum. + * @param[in] ... Additional variadic parameters required for certain effects (e.g., sigma and direction for GaussianBlur). + * + * @note The caller must provide the correct parameters for the selected effect. + * Supplying incorrect or insufficient arguments results in undefined behavior. + * + * @since 1.0 + */ + Result add(SceneEffect effect, ...) noexcept; + + /** + * @brief Creates a new Scene object. + * + * This function allocates and returns a new Scene instance. + * To properly destroy the Scene object, use @ref Paint::rel(). + * + * @return A pointer to the newly created Scene object. + * + * @see Paint::rel() + */ + static Scene* gen() noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the Scene instance. + * + * @since 1.0 + */ + Type type() const noexcept override; + + _TVG_DECLARE_PRIVATE_DERIVE(Scene); +}; + + +/** + * @class Text + * + * @brief A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text. + * + * @warning This class is not designed for inheritance. + * + * @since 0.15 + */ +struct TVG_API Text : Paint +{ + /** + * @brief Sets the font family for the text. + * + * This function specifies the name of the font to be used when rendering text. + * + * @param[in] name The name of the font. This should match a font available through the canvas backend. + * If set to @c nullptr, ThorVG will attempt to select a fallback font available on the engine. + * + * @retval Result::InsufficientCondition when the specified @p name cannot be found. + * + * @note This function only sets the font family name. Use @ref size() to define the font size. + * @note If the @p name is not specified, ThorVG will select an available fallback font. + * + * @see Text::size() + * @see Text::load() + * + * @since 1.0 + */ + Result font(const char* name) noexcept; + + /** + * @brief Sets the font size for the text. + * + * This function sets the font size used during text rendering. + * The size is specified in point units, and supports floating-point precision + * for smooth scaling and animation effects. + * + * @param[in] size The font size in points. Must be greater than 0.0. + * + * @retval Result::InvalidArguments if the @p size is less than or equal to 0. + * + * @note Use this function in combination with @ref font() to fully define text appearance. + * @note Fractional sizes (e.g., 12.5) are supported for sub-pixel rendering and animations. + * + * @see Text::font() + * + * @since 1.0 + */ + Result size(float size) noexcept; + + /** + * @brief Assigns the given unicode text to be rendered. + * + * This function sets the unicode string that will be displayed by the rendering system. + * The text is set according to the specified UTF encoding method, which defaults to UTF-8. + * + * @param[in] text The multi-byte text encoded with utf8 string to be rendered. + * + * @since 1.0 + */ + Result text(const char* text) noexcept; + + /** + * @brief Sets text alignment or anchor per axis. + * + * If layout width/height is set on an axis, align within the layout box. + * Otherwise, treat it as an anchor within the text bounds which point of + * the text box is pinned to the paint position. + * + * @param[in] x Horizontal alignment/anchor in [0..1]: 0=left/start, 0.5=center, 1=right/end. (Default is 0) + * @param[in] y Vertical alignment/anchor in [0..1]: 0=top, 0.5=middle, 1=bottom. (Default is 0) + * + * @since 1.0 + * + * @see layout() + */ + Result align(float x, float y) noexcept; + + /** + * @brief Sets the virtual layout box (constraints) for the text. + * + * If width/height is set on an axis, that axis is constrained by a virtual layout box and + * the text may wrap/align inside it. If width/height == 0, the axis is + * unconstrained and @ref align() acts as an anchor on that axis. + * + * @param[in] w Layout width in user space. Use 0 for no horizontal constraint. (Default is 0) + * @param[in] h Layout height in user space. Use 0 for no vertical constraint. (Default is 0) + * + * @note This defines constraints only; alignment/anchoring is controlled by @ref align(). + * @since 1.0 + * + * @see align() + * @see spacing() + */ + Result layout(float w, float h) noexcept; + + /** + * @brief Sets the text wrapping mode for this text object. + * + * This method controls how the text is laid out when it exceeds the available space. + * The wrapping mode determines whether text is truncated, wrapped by character or word, + * or adjusted automatically. An ellipsis mode is also available for truncation with "...". + * + * @param[in] mode The wrapping strategy to apply. Default is @c TextWrap::None + * + * @see TextWrap + * @since 1.0 + */ + Result wrap(TextWrap mode) noexcept; + + /** + * @brief Apply an italic (slant) transformation to the text. + * + * This function applies a shear transformation to simulate an italic (oblique) style + * for the current text object. The shear factor determines the degree of slant + * applied along the X-axis. + * + * @param[in] shear The shear factor to apply. A value of 0.0 applies no slant, while values around 0.5 result in a strong slant. + * Must be in the range [0.0, 0.5]. Default value is 0.18. + * + * @note The @p shear factor will be clamped to the valid range if it exceeds the limits. + * @note This does not require the font itself to be italic. + * It visually simulates the effect by applying a transformation matrix. + * + * @warning Excessive slanting may cause visual distortion depending on the font and size. + * + * @see Text::font() + * + * @since 1.0 + */ + Result italic(float shear = 0.18f) noexcept; + + /** + * @brief Sets an outline (stroke) around the text object. + * + * This function adds an outline to the text with the specified width and RGB color. + * The outline enhances the visibility of the text by rendering a stroke around its glyphs. + * + * @param width The width of the outline. Must be positive value. (The default is 0) + * @param r Red component of the outline color (0–255). + * @param g Green component of the outline color (0–255). + * @param b Blue component of the outline color (0–255). + * + * @note To disable the outline, set @p width to 0. + * @see Text::fill() to set the main text fill color. + * + * @since 1.0 + */ + Result outline(float width, uint8_t r, uint8_t g, uint8_t b) noexcept; + + /** + * @brief Sets the text color. + * + * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * + * @see Text::font() + * @see Text::outline() + * + * @since 0.15 + */ + Result fill(uint8_t r, uint8_t g, uint8_t b) noexcept; + + /** + * @brief Sets the gradient fill for all of the figures from the text. + * + * The parts of the text defined as inner are filled. + * + * @param[in] f The unique pointer to the gradient fill. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * @see Text::font() + * + * @since 0.15 + */ + Result fill(Fill* f) noexcept; + + /** + * @brief Set the spacing scale factors for text layout. + * + * This function adjusts the letter spacing (horizontal space between glyphs) and + * line spacing (vertical space between lines of text) using scale factors. + * + * Both values are relative to the font's default metrics: + * - The letter spacing is applied as a scale factor to the glyph's advance width. + * - The line spacing is applied as a scale factor to the glyph's advance height. + * + * @param[in] letter The scale factor for letter spacing. + * Values > 1.0 increase spacing, values < 1.0 decrease it. + * Must be greater than or equal to 0.0. (default: 1.0) + * + * @param[in] line The scale factor for line spacing. + * Values > 1.0 increase line spacing, values < 1.0 decrease it. + * Must be greater than or equal to 0.0. (default: 1.0) + * + * @since 1.0 + */ + Result spacing(float letter, float line) noexcept; + + /** + * @brief Loads a scalable font data (ttf) from a file. + * + * ThorVG efficiently caches the loaded data using the specified @p path as a key. + * This means that loading the same file again will not result in duplicate operations; + * instead, ThorVG will reuse the previously loaded font data. + * + * @param[in] filename A file name, including the path, for the font file. + * + * @retval Result::InvalidArguments In case the @p path is invalid. + * @retval Result::NonSupport When trying to load a file with an unknown extension. + * + * @see Text::unload(const char* filename) + * + * @since 0.15 + */ + static Result load(const char* filename) noexcept; + + /** + * @brief Loads a scalable font data (ttf) from a memory block of a given size. + * + * ThorVG efficiently caches the loaded font data using the specified @p name as a key. + * This means that loading the same fonts again will not result in duplicate operations. + * Instead, ThorVG will reuse the previously loaded font data. + * + * @param[in] name The name under which the font will be stored and accessible (e.x. in a @p font() API). + * @param[in] data A pointer to a memory location where the content of the font data is stored. + * @param[in] size The size in bytes of the memory occupied by the @p data. + * @param[in] mimeType Mimetype or extension of font data. In case an empty string is provided the loader will be determined automatically. + * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not (default). + * + * @retval Result::InvalidArguments If no name is provided or if @p size is zero while @p data points to a valid memory location. + * @retval Result::NonSupport When trying to load a file with an unsupported extension. + * @retval Result::InsufficientCondition If attempting to unload the font data that has not been previously loaded. + * + * @warning It's the user responsibility to release the @p data memory. + * + * @note To unload the font data loaded using this API, pass the proper @p name and @c nullptr as @p data. + * @note If you are unsure about the MIME type, you can provide an empty value like @c nullptr, and thorvg will attempt to figure it out. + * @see Text::font(const char* name, float size, const char* style) + * + * @since 0.15 + */ + static Result load(const char* name, const char* data, uint32_t size, const char* mimeType = "ttf", bool copy = false) noexcept; + + /** + * @brief Unloads the specified scalable font data (TTF) that was previously loaded. + * + * This function is used to release resources associated with a font file that has been loaded into memory. + * + * @param[in] filename The file name of the loaded font, including the path. + * + * @retval Result::InsufficientCondition Fails if the loader is not initialized. + * + * @note If the font data is currently in use, it will not be immediately unloaded. + * @see Text::load(const char* filename) + * + * @since 0.15 + */ + static Result unload(const char* filename) noexcept; + + /** + * @brief Creates a new Text object. + * + * This function allocates and returns a new Text instance. + * To properly destroy the Text object, use @ref Paint::rel(). + * + * @return A pointer to the newly created Text object. + * + * @see Paint::rel() + * + * @since 0.15 + */ + static Text* gen() noexcept; + + /** + * @brief Returns the ID value of this class. + * + * This method can be used to check the current concrete instance type. + * + * @return The class type ID of the Text instance. + * + * @since 1.0 + */ + Type type() const noexcept override; + + _TVG_DECLARE_PRIVATE_DERIVE(Text); +}; + + +/** + * @class SwCanvas + * + * @brief A class for the rendering graphical elements with a software raster engine. + */ +struct TVG_API SwCanvas final : Canvas +{ + ~SwCanvas() override; + + /** + * @brief Sets the drawing target for the rasterization. + * + * The buffer of a desirable size should be allocated and owned by the caller. + * + * @param[in] buffer A pointer to a memory block of the size @p stride x @p h, where the raster data are stored. + * @param[in] stride The stride of the raster image - greater than or equal to @p w. + * @param[in] w The width of the raster image. + * @param[in] h The height of the raster image. + * @param[in] cs The value specifying the way the 32-bits colors should be read/written. + * + * @retval Result::InvalidArguments In case no valid pointer is provided or the width, or the height or the stride is zero. + * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. + * @retval Result::NonSupport In case the software engine is not supported. + * + * @warning Do not access @p buffer during Canvas::add() - Canvas::sync(). It should not be accessed while the engine is writing on it. + * + * @see Canvas::viewport() + * @see Canvas::sync() + */ + Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, ColorSpace cs) noexcept; + + /** + * @brief Creates a new SwCanvas object with optional rendering engine settings. + * + * This method generates a software canvas instance that can be used for drawing vector graphics. + * It accepts an optional parameter @p op to choose between different rendering engine behaviors. + * + * @param[in] op The rendering engine option. Default is @c EngineOption::Default. + * + * @return A new SwCanvas object. + * + * @see enum EngineOption + */ + static SwCanvas* gen(EngineOption op = EngineOption::Default) noexcept; + + _TVG_DECLARE_PRIVATE(SwCanvas); +}; + + +/** + * @class GlCanvas + * + * @brief A class for the rendering graphic elements with a GL raster engine. + * + * @since 0.14 + */ +struct TVG_API GlCanvas final : Canvas +{ + ~GlCanvas() override; + + /** + * @brief Sets the drawing target for rasterization. + * + * This function specifies the drawing target where the rasterization will occur. It can target + * a specific framebuffer object (FBO) or the main surface. + * + * @param[in] display The platform-specific display handle (EGLDisplay for EGL). Set @c nullptr for other systems. + * @param[in] surface The platform-specific surface handle (EGLSurface for EGL, HDC for WGL). Set @c nullptr for other systems. + * @param[in] context The OpenGL context to be used for rendering on this canvas. + * @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface. + * @param[in] w The width (in pixels) of the raster image. + * @param[in] h The height (in pixels) of the raster image. + * @param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c ColorSpace::ABGR8888S as @c GL_RGBA8. + * + * @retval Result::InsufficientCondition If the canvas is currently rendering. + * Ensure that @ref Canvas::sync() has been called before setting a new target. + * @retval Result::NonSupport In case the gl engine is not supported. + * + * @note If @p display and @p surface are not provided, the ThorVG GL engine assumes that + * the appropriate OpenGL context is already current and will not attempt to bind a new one. + * + * @see Canvas::sync() + * + * @since 1.0 + */ + Result target(void* display, void* surface, void* context, int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept; + + /** + * @brief Creates a new OpenGL/ES Canvas object with optional rendering engine settings. + * + * This method generates a OpenGL canvas instance that can be used for drawing vector graphics. + * It accepts an optional parameter @p op to choose between different rendering engine behaviors. + * + * @param[in] op The rendering engine option. Default is @c EngineOption::Default. + * + * @return A new GlCanvas object. + * + * @note Currently, it does not support @c EngineOption::SmartRender. The request will be ignored. + * + * @see enum EngineOption + * + * @since 1.0 + */ + static GlCanvas* gen(EngineOption op = EngineOption::Default) noexcept; + + _TVG_DECLARE_PRIVATE(GlCanvas); +}; + + +/** + * @class WgCanvas + * + * @brief A class for the rendering graphic elements with a WebGPU raster engine. + * + * @warning Please do not use it. This class is not fully supported yet. + * + * @since 0.15 + */ +struct TVG_API WgCanvas final : Canvas +{ + ~WgCanvas() override; + + /** + * @brief Sets the drawing target for the rasterization. + * + * @param[in] device WGPUDevice, a desired handle for the wgpu device. If it is @c nullptr, ThorVG will assign an appropriate device internally. + * @param[in] instance WGPUInstance, context for all other wgpu objects. + * @param[in] target Either WGPUSurface or WGPUTexture, serving as handles to a presentable surface or texture. + * @param[in] w The width of the target. + * @param[in] h The height of the target. + * @param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c ColorSpace::ABGR8888S as @c WGPUTextureFormat_RGBA8Unorm. + * @param[in] type @c 0: surface, @c 1: texture are used as pesentable target. + * + * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. + * @retval Result::NonSupport In case the wg engine is not supported. + * + * @since 1.0 + * + * @see Canvas::viewport() + * @see Canvas::sync() + */ + Result target(void* device, void* instance, void* target, uint32_t w, uint32_t h, ColorSpace cs, int type = 0) noexcept; + + /** + * @brief Creates a new WebGPU Canvas object with optional rendering engine settings. + * + * This method generates a WebGPU canvas instance that can be used for drawing vector graphics. + * It accepts an optional parameter @p op to choose between different rendering engine behaviors. + * + * @param[in] op The rendering engine option. Default is @c EngineOption::Default. + * + * @return A new WgCanvas object. + * + * @note Currently, it does not support @c EngineOption::SmartRender. The request will be ignored. + * + * @see enum EngineOption + * + * @since 1.0 + */ + static WgCanvas* gen(EngineOption op = EngineOption::Default) noexcept; + + _TVG_DECLARE_PRIVATE(WgCanvas); +}; + + +/** + * @class Initializer + * + * @brief A class that enables initialization and termination of the TVG engines. + */ +struct TVG_API Initializer final +{ + /** + * @brief Initializes the ThorVG engine runtime. + * + * ThorVG requires an active runtime environment for rendering operations. + * This function sets up an internal task scheduler and creates a specified number + * of worker threads to enable parallel rendering. + * + * @param[in] threads The number of worker threads to launch. + * A value of 0 indicates that only the main thread will be used. + * + * @return Result indicating success or failure of initialization. + * + * @note This function uses internal reference counting to allow multiple init() calls. + * However, the number of threads is fixed during the first successful initialization + * and cannot be changed in subsequent calls. + * + * @see Initializer::term() + */ + static Result init(uint32_t threads = 0) noexcept; + + /** + * @brief Terminates the ThorVG engine. + * + * Cleans up resources and stops any internal threads initialized by init(). + * + * @retval Result::InsufficientCondition Returned if there is nothing to terminate (e.g., init() was not called). + * + * @note The initializer maintains a reference count for safe repeated use. + * Only the final call to term() will fully shut down the engine. + * @see Initializer::init() + */ + static Result term() noexcept; + + /** + * @brief Retrieves the version of the TVG engine. + * + * @param[out] major A major version number. + * @param[out] minor A minor version number. + * @param[out] micro A micro version number. + * + * @return The version of the engine in the format major.minor.micro, or a @p nullptr in case of an internal error. + * + * @since 0.15 + */ + static const char* version(uint32_t* major, uint32_t* minor, uint32_t* micro) noexcept; + + _TVG_DISABLE_CTOR(Initializer); +}; + + +/** + * @class Animation + * + * @brief The Animation class enables manipulation of animatable images. + * + * This class supports the display and control of animation frames. + * + * @since 0.13 + */ +struct TVG_API Animation +{ + virtual ~Animation(); + + /** + * @brief Specifies the current frame in the animation. + * + * @param[in] no The index of the animation frame to be displayed. The index should be less than the totalFrame(). + * + * @retval Result::InsufficientCondition if the given @p no is the same as the current frame value. + * @retval Result::NonSupport The current Picture data does not support animations. + * + * @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value + * is less than 0.001. In such cases, it returns @c Result::InsufficientCondition. + * Values less than 0.001 may be disregarded and may not be accurately retained by the Animation. + * + * @see totalFrame() + */ + Result frame(float no) noexcept; + + /** + * @brief Retrieves a picture instance associated with this animation instance. + * + * This function provides access to the picture instance that can be used to load animation formats, such as lot. + * After setting up the picture, it can be added to the designated canvas, enabling control over animation frames + * with this Animation instance. + * + * @return A picture instance that is tied to this animation. + * + * @warning The picture instance is owned by Animation. It should not be deleted manually. + */ + Picture* picture() const noexcept; + + /** + * @brief Retrieves the current frame number of the animation. + * + * @return The current frame number of the animation, between 0 and totalFrame() - 1. + * + * @note If the Picture is not properly configured, this function will return 0. + * + * @see Animation::frame() + * @see Animation::totalFrame() + */ + float curFrame() const noexcept; + + /** + * @brief Retrieves the total number of frames in the animation. + * + * @return The total number of frames in the animation. + * + * @note Frame numbering starts from 0. + * @note If the Picture is not properly configured, this function will return 0. + */ + float totalFrame() const noexcept; + + /** + * @brief Retrieves the duration of the animation in seconds. + * + * @return The duration of the animation in seconds. + * + * @note If the Picture is not properly configured, this function will return 0. + */ + float duration() const noexcept; + + /** + * @brief Specifies the playback segment of the animation. + * + * The set segment is designated as the play area of the animation. + * This is useful for playing a specific segment within the entire animation. + * After setting, the number of animation frames and the playback time are calculated + * by mapping the playback segment as the entire range. + * + * @param[in] begin segment begin frame. + * @param[in] end segment end frame. + * + * @retval Result::InsufficientCondition In case the animation is not loaded. + * @retval Result::InvalidArguments If the @p begin is higher than @p end. + * @retval Result::NonSupport When it's not animatable. + * + * @note Animation allows a range from 0.0 to the total frame. @p end should not be higher than @p begin. + * @note If a marker has been specified, its range will be disregarded. + * + * @see LottieAnimation::segment(const char* marker) + * @see Animation::totalFrame() + * + * @since 1.0 + */ + Result segment(float begin, float end) noexcept; + + /** + * @brief Gets the current segment range information. + * + * @param[out] begin segment begin frame. + * @param[out] end segment end frame. + * + * @retval Result::InsufficientCondition In case the animation is not loaded. + * @retval Result::NonSupport When it's not animatable. + * + * @since 1.0 + */ + Result segment(float* begin, float* end = nullptr) noexcept; + + /** + * @brief Creates a new Animation object. + * + * @return A new Animation object. + */ + static Animation* gen() noexcept; + + _TVG_DECLARE_PRIVATE_BASE(Animation); +}; + + +/** + * @class Saver + * + * @brief A class for exporting a paint object into a specified file, from which to recover the paint data later. + * + * ThorVG provides a feature for exporting & importing paint data. The Saver role is to export the paint data to a file. + * It's useful when you need to save the composed scene or image from a paint object and recreate it later. + * + * The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment. + * If it doesn't support the file format, the save() method returns the @c Result::NonSupport result. + * + * Once you export a paint to the file successfully, you can recreate it using the Picture class. + * + * @see Picture::load() + * + * @since 0.5 + */ +struct TVG_API Saver final +{ + ~Saver(); + + /** + * @brief Sets the base background content for the saved image. + * + * @param[in] paint The paint to be drawn as the background image for the saving paint. + * + * @since 1.0 + */ + Result background(Paint* paint) noexcept; + + /** + * @brief Exports the given @p paint data to the given @p path + * + * If the saver module supports any compression mechanism, it will optimize the data size. + * This might affect the encoding/decoding time in some cases. You can turn off the compression + * if you wish to optimize for speed. + * + * @param[in] paint The paint to be saved with all its associated properties. + * @param[in] filename A file name, including the path, where the paint data will be saved. + * @param[in] quality The encoded quality level. @c 0 is the minimum, @c 100 is the maximum value(recommended). + * + * @retval Result::InsufficientCondition If currently saving other resources. + * @retval Result::NonSupport When trying to save a file with an unknown extension or in an unsupported format. + * @retval Result::Unknown In case an empty paint is to be saved. + * + * @note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards. + * @see Saver::sync() + * + * @since 0.5 + */ + Result save(Paint* paint, const char* filename, uint32_t quality = 100) noexcept; + + /** + * @brief Export the provided animation data to the specified file path. + * + * This function exports the given animation data to the provided file path. You can also specify the desired frame rate in frames per second (FPS) by providing the fps parameter. + * + * @param[in] animation The animation to be saved, including all associated properties. + * @param[in] filename A file name, including the path, where the animation will be saved. + * @param[in] quality The encoded quality level. @c 0 is the minimum, @c 100 is the maximum value(recommended). + * @param[in] fps The desired frames per second (FPS). For example, to encode data at 60 FPS, pass 60. Pass 0 to keep the original frame data. + * + * @retval Result::InsufficientCondition if there are ongoing resource-saving operations. + * @retval Result::NonSupport if an attempt is made to save the file with an unknown extension or in an unsupported format. + * @retval Result::Unknown if attempting to save an empty paint. + * + * @note A higher frames per second (FPS) would result in a larger file size. It is recommended to use the default value. + * @note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards. + * + * @see Saver::sync() + * + * @since 1.0 + */ + Result save(Animation* animation, const char* filename, uint32_t quality = 100, uint32_t fps = 0) noexcept; + + /** + * @brief Guarantees that the saving task is finished. + * + * The behavior of the Saver works on a sync/async basis, depending on the threading setting of the Initializer. + * Thus, if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time. + * Otherwise, you can call sync() immediately. + * + * @note The asynchronous tasking is dependent on the Saver module implementation. + * @see Saver::save() + * + * @since 0.5 + */ + Result sync() noexcept; + + /** + * @brief Creates a new Saver object. + * + * @return A new Saver object. + * + * @since 0.5 + */ + static Saver* gen() noexcept; + + _TVG_DECLARE_PRIVATE_BASE(Saver); +}; + + +/** + * @class Accessor + * + * @brief The Accessor is a utility class to debug the Scene structure by traversing the scene-tree. + * + * The Accessor helps you search specific nodes to read the property information, figure out the structure of the scene tree and its size. + * + * @warning We strongly warn you not to change the paints of a scene unless you really know the design-structure. + * + * @since 0.10 + */ +struct TVG_API Accessor final +{ + ~Accessor(); + + /** + * @brief Set the access function for traversing the Picture scene tree nodes. + * + * @param[in] paint The paint node to traverse the internal scene-tree. + * @param[in] func The callback function calling for every paint nodes of the Picture. + * @param[in] data Data passed to the @p func as its argument. + * + * @note The bitmap based picture might not have the scene-tree. + * + * @since 1.0 + */ + Result set(Paint* paint, std::function func, void* data) noexcept; + + /** + * @brief Generate a unique ID (hash key) from a given name. + * + * This function computes a unique identifier value based on the provided string. + * You can use this to assign a unique ID to the Paint object. + * + * @param[in] name The input string to generate the unique identifier from. + * + * @return The generated unique identifier value. + * + * @see Paint::id + * + * @since 1.0 + */ + static uint32_t id(const char* name) noexcept; + + /** + * @brief Creates a new Accessor object. + * + * @return A new Accessor object. + */ + static Accessor* gen() noexcept; + + _TVG_DECLARE_PRIVATE_BASE(Accessor); +}; + +/** @}*/ + +} //namespace + +#endif //_THORVG_H_ diff --git a/components/thorvg-main/meson.build b/components/thorvg-main/meson.build new file mode 100644 index 0000000..00dd6b5 --- /dev/null +++ b/components/thorvg-main/meson.build @@ -0,0 +1,244 @@ +project('thorvg', + 'cpp', + default_options : ['buildtype=debugoptimized', 'b_sanitize=none', 'werror=false', 'optimization=3', 'cpp_std=c++14', 'strip=true'], + version : '1.0.0', + license : 'MIT') + +v_array = meson.project_version().split('.') +vmaj = v_array[0] + +config_h = configuration_data() + +src_dir = '/'.join(meson.current_source_dir().split('\\')) +add_project_arguments('-DTEST_DIR="@0@/test/resources"'.format(src_dir), + language : 'cpp') + +config_h.set_quoted('THORVG_VERSION_STRING', meson.project_version()) + +# Multi-Tasking +if get_option('threads') + config_h.set10('THORVG_THREAD_SUPPORT', true) +endif + +# Engines +all_engines = get_option('engines').contains('all') + +sw_engine = false +if all_engines or get_option('engines').contains('sw') + sw_engine = true + config_h.set10('THORVG_SW_RASTER_SUPPORT', true) +endif + +gl_engine = false +if all_engines or get_option('engines').contains('gl') + gl_engine = true + config_h.set10('THORVG_GL_RASTER_SUPPORT', true) +endif + +wg_engine = false +if all_engines or get_option('engines').contains('wg') + wg_engine = true + config_h.set10('THORVG_WG_RASTER_SUPPORT', true) +endif + +# Partial Rendering +if get_option('partial') + config_h.set10('THORVG_PARTIAL_RENDER_SUPPORT', true) +endif + +# Tools +all_tools = get_option('tools').contains('all') +lottie2gif = all_tools or get_option('tools').contains('lottie2gif') +svg2png = all_tools or get_option('tools').contains('svg2png') + +# Loaders +all_loaders = get_option('loaders').contains('all') +svg_loader = all_loaders or get_option('loaders').contains('svg') or svg2png +png_loader = all_loaders or get_option('loaders').contains('png') +jpg_loader = all_loaders or get_option('loaders').contains('jpg') +lottie_loader = all_loaders or get_option('loaders').contains('lottie') or lottie2gif +ttf_loader = all_loaders or get_option('loaders').contains('ttf') +webp_loader = all_loaders or get_option('loaders').contains('webp') + +# Savers +all_savers = get_option('savers').contains('all') +gif_saver = all_savers or get_option('savers').contains('gif') or lottie2gif + +# Logging +logging = get_option('log') + +# Loaders/savers/tools config +if svg_loader + config_h.set10('THORVG_SVG_LOADER_SUPPORT', true) +endif + +if png_loader + config_h.set10('THORVG_PNG_LOADER_SUPPORT', true) +endif + +if jpg_loader + config_h.set10('THORVG_JPG_LOADER_SUPPORT', true) +endif + +if lottie_loader + config_h.set10('THORVG_LOTTIE_LOADER_SUPPORT', true) +endif + +if ttf_loader + config_h.set10('THORVG_TTF_LOADER_SUPPORT', true) +endif + +if webp_loader + config_h.set10('THORVG_WEBP_LOADER_SUPPORT', true) +endif + +if gif_saver + config_h.set10('THORVG_GIF_SAVER_SUPPORT', true) +endif + +# Vectorization +simd_type = 'none' + +if get_option('simd') + if host_machine.cpu_family().startswith('x86') + config_h.set10('THORVG_AVX_VECTOR_SUPPORT', true) + simd_type = 'avx' + elif host_machine.cpu_family().startswith('arm') + config_h.set10('THORVG_NEON_VECTOR_SUPPORT', true) + simd_type = 'neon-arm' + elif host_machine.cpu().startswith('aarch') + config_h.set10('THORVG_NEON_VECTOR_SUPPORT', true) + simd_type = 'neon-aarch' + endif +endif + +# Bindings +if get_option('bindings').contains('capi') + config_h.set10('THORVG_CAPI_BINDING_SUPPORT', true) +endif + +# Log +if logging + config_h.set10('THORVG_LOG_ENABLED', true) +endif + +# File IO +if get_option('file') == true + config_h.set10('THORVG_FILE_IO_SUPPORT', true) +endif + + +# Extra +lottie_exp = lottie_loader and get_option('extra').contains('lottie_exp') + +if lottie_exp + config_h.set10('THORVG_LOTTIE_EXPRESSIONS_SUPPORT', true) +endif + +openmp = get_option('extra').contains('openmp') + +if openmp + config_h.set10('THORVG_OPENMP_SUPPORT', true) +endif + +gl_variant = '' + +if gl_engine + if get_option('extra').contains('opengl_es') + gl_variant = 'OpenGL ES' + else + gl_variant = 'OpenGL' + endif +else + gl_variant = 'None' +endif + +# Miscellaneous +config_h.set10('WIN32_LEAN_AND_MEAN', true) + +configure_file( + output: 'config.h', + configuration: config_h +) + +headers = [include_directories('inc'), include_directories('.')] + +subdir('inc') +subdir('src') +subdir('tools') + +if get_option('tests') + subdir('test') +endif + +summary( + { + 'Build Type': get_option('buildtype'), + 'Prefix': get_option('prefix'), + 'File I/O': get_option('file'), + 'Multi-Tasking': get_option('threads'), + 'Partial Rendering': get_option('partial'), + 'SIMD Instruction': simd_type, + 'Log Message': get_option('log'), + 'Tests': get_option('tests') + }, + bool_yn: true, +) + +summary( + { + 'SW': sw_engine, + 'GL': gl_engine, + 'WG': wg_engine, + }, + section: 'Raster Engine', + bool_yn: true, +) + +summary( + { + 'SVG': svg_loader, + 'TTF': ttf_loader, + 'LOTTIE': lottie_loader, + 'PNG': png_loader, + 'JPG': jpg_loader, + 'WEBP': webp_loader, + }, + section: 'Loader', + bool_yn: true, +) + +summary( + { + 'GIF': gif_saver, + }, + section: 'Saver', + bool_yn: true, +) + +summary( + { + 'CAPI': get_option('bindings').contains('capi'), + }, + section: 'Binding', + bool_yn: true, +) + +summary( + { + 'Svg2Png': svg2png, + 'Lottie2Gif': lottie2gif, + }, + section: 'Tool', + bool_yn: true, +) + +summary( + { + 'Lottie Expressions': lottie_exp, + 'OpenMP': openmp, + 'OpenGL Variant': gl_variant + }, + section: 'Extra', + bool_yn: true, +) diff --git a/components/thorvg-main/meson_options.txt b/components/thorvg-main/meson_options.txt new file mode 100644 index 0000000..55f076d --- /dev/null +++ b/components/thorvg-main/meson_options.txt @@ -0,0 +1,70 @@ +option('engines', + type: 'array', + choices: ['sw', 'gl', 'wg', 'all'], + value: ['sw'], + description: 'Enable Rasterizer Engine in thorvg') + +option('partial', + type: 'boolean', + value: true, + description: 'Enable Partial Rendering in thorvg') + +option('loaders', + type: 'array', + choices: ['', 'svg', 'png', 'jpg', 'lottie', 'ttf', 'webp', 'all'], + value: ['svg', 'lottie', 'ttf'], + description: 'Enable File Loaders in thorvg') + +option('savers', + type: 'array', + choices: ['', 'gif', 'all'], + value: [''], + description: 'Enable File Savers in thorvg') + +option('threads', + type: 'boolean', + value: true, + description: 'Enable the multi-threading task scheduler in thorvg') + +option('simd', + type: 'boolean', + value: false, + description: 'Enable CPU Vectorization(SIMD) in thorvg') + +option('bindings', + type: 'array', + choices: ['', 'capi'], + value: [''], + description: 'Enable API bindings') + +option('tools', + type: 'array', + choices: ['', 'svg2png', 'lottie2gif', 'all'], + value: [''], + description: 'Enable building thorvg tools') + +option('tests', + type: 'boolean', + value: false, + description: 'Enable building Unit Tests') + +option('log', + type: 'boolean', + value: false, + description: 'Enable log message') + +option('static', + type: 'boolean', + value: false, + description: 'Force to use static linking modules in thorvg') + +option('file', + type: 'boolean', + value: true, + description: 'Enable File IO calls in thorvg') + +option('extra', + type: 'array', + choices: ['', 'opengl_es', 'lottie_exp', 'openmp'], + value: ['lottie_exp', 'openmp'], + description: 'Enable support for extra options') diff --git a/components/thorvg-main/src/bindings/capi/meson.build b/components/thorvg-main/src/bindings/capi/meson.build new file mode 100644 index 0000000..bcea6a9 --- /dev/null +++ b/components/thorvg-main/src/bindings/capi/meson.build @@ -0,0 +1,11 @@ +source_file = [ + 'tvgCapi.cpp', +] + +thorvg_lib_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] + +install_headers('thorvg_capi.h', subdir: 'thorvg-' + vmaj) +headers += include_directories('.') diff --git a/components/thorvg-main/src/bindings/capi/thorvg_capi.h b/components/thorvg-main/src/bindings/capi/thorvg_capi.h new file mode 100644 index 0000000..c55820f --- /dev/null +++ b/components/thorvg-main/src/bindings/capi/thorvg_capi.h @@ -0,0 +1,3190 @@ +#ifndef __THORVG_CAPI_H__ +#define __THORVG_CAPI_H__ + +#include +#include + +#ifdef TVG_API + #undef TVG_API +#endif + +#define TVG_VERSION_MAJOR 1 // for compile-time checks +#define TVG_VERSION_MINOR 0 // for compile-time checks +#define TVG_VERSION_MICRO 0 // for compile-time checks + +#ifndef TVG_STATIC + #ifdef _WIN32 + #if TVG_BUILD + #define TVG_API __declspec(dllexport) + #else + #define TVG_API __declspec(dllimport) + #endif + #elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) + #define TVG_API __global + #else + #if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__INTEL_COMPILER) + #define TVG_API __attribute__ ((visibility("default"))) + #else + #define TVG_API + #endif + #endif +#else + #define TVG_API +#endif + +#ifdef TVG_DEPRECATED + #undef TVG_DEPRECATED +#endif + +#ifdef _WIN32 + #define TVG_DEPRECATED __declspec(deprecated) +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) + #define TVG_DEPRECATED __attribute__ ((__deprecated__)) +#else + #define TVG_DEPRECATED +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup ThorVG_CAPI ThorVG_CAPI + * @brief ThorVG C language binding APIs. + * + * \{ + */ + + +/** + * @brief A structure responsible for managing and drawing graphical elements. + * + * It sets up the target buffer, which can be drawn on the screen. It stores the Tvg_Paint objects (Shape, Scene, Picture). + */ +typedef struct _Tvg_Canvas* Tvg_Canvas; + + +/** + * @brief A structure representing a graphical element. + * + * @warning The TvgPaint objects cannot be shared between Canvases. + */ +typedef struct _Tvg_Paint* Tvg_Paint; + + +/** + * @brief A structure representing a gradient fill of a Tvg_Paint object. + */ +typedef struct _Tvg_Gradient* Tvg_Gradient; + + +/** + * @brief A structure representing an object that enables to save a Tvg_Paint object into a file. + */ +typedef struct _Tvg_Saver* Tvg_Saver; + +/** + * @brief A structure representing an animation controller object. + */ +typedef struct _Tvg_Animation* Tvg_Animation; + +/** + * @brief A structure representing an object that enables iterating through a scene's descendents. + */ +typedef struct _Tvg_Accessor* Tvg_Accessor; + + +/** + * @brief Enumeration specifying the result from the APIs. + * + * All ThorVG APIs could potentially return one of the values in the list. + * Please note that some APIs may additionally specify the reasons that trigger their return values. + * + */ +typedef enum { + TVG_RESULT_SUCCESS = 0, ///< The value returned in case of a correct request execution. + TVG_RESULT_INVALID_ARGUMENT, ///< The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers. + TVG_RESULT_INSUFFICIENT_CONDITION, ///< The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist. + TVG_RESULT_FAILED_ALLOCATION, ///< The value returned in case of unsuccessful memory allocation. + TVG_RESULT_MEMORY_CORRUPTION, ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting + TVG_RESULT_NOT_SUPPORTED, ///< The value returned in case of choosing unsupported engine features(options). + TVG_RESULT_UNKNOWN = 255 ///< The value returned in all other cases. +} Tvg_Result; + + +/** + * @brief Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color. + */ +typedef enum { + TVG_COLORSPACE_ABGR8888 = 0, ///< The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. + TVG_COLORSPACE_ARGB8888, ///< The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. + TVG_COLORSPACE_ABGR8888S, ///< The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied. (since 0.13) + TVG_COLORSPACE_ARGB8888S, ///< The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied. (since 0.13) + TVG_COLORSPACE_UNKNOWN = 255, ///< Unknown channel data. This is reserved for an initial ColorSpace value. (since 1.0) +} Tvg_Colorspace; + + +/** + * @brief Enumeration to specify rendering engine behavior. + * + * @note The availability or behavior of @c TVG_ENGINE_OPTION_SMART_RENDER may vary depending on platform or backend support. + * It attempts to optimize rendering performance by updating only the regions of the canvas that have + * changed between frames (partial redraw). This can be highly effective in scenarios where most of the + * canvas remains static and only small portions are updated—such as simple animations or GUI interactions. + * However, in complex scenes where a large portion of the canvas changes frequently (e.g., full-screen animations + * or heavy object movements), the overhead of tracking changes and managing update regions may outweigh the benefits, + * resulting in decreased performance compared to the default rendering mode. Thus, it is recommended to benchmark + * both modes in your specific use case to determine the optimal setting. + * + * @since 1.0 + */ +typedef enum { + TVG_ENGINE_OPTION_NONE = 0, /**< No engine options are enabled. This may be used to explicitly disable all optional behaviors. */ + TVG_ENGINE_OPTION_DEFAULT = 1 << 0, /**< Uses the default rendering mode. */ + TVG_ENGINE_OPTION_SMART_RENDER = 1 << 1 /**< Enables automatic partial (smart) rendering optimizations. */ +} Tvg_Engine_Option; + + +/** + * @brief Enumeration indicating the method used in the masking of two objects - the target and the source. + * + * @ingroup ThorVGCapi_Paint + */ +typedef enum { + TVG_MASK_METHOD_NONE = 0, ///< No Masking is applied. + TVG_MASK_METHOD_ALPHA, ///< Alpha Masking using the masking target's pixels as an alpha value. + TVG_MASK_METHOD_INVERSE_ALPHA, ///< Alpha Masking using the complement to the masking target's pixels as an alpha value. + TVG_MASK_METHOD_LUMA, ///< Alpha Masking using the grayscale (0.2126R + 0.7152G + 0.0722*B) of the masking target's pixels. @since 0.9 + TVG_MASK_METHOD_INVERSE_LUMA, ///< Alpha Masking using the grayscale (0.2126R + 0.7152G + 0.0722*B) of the complement to the masking target's pixels. @since 0.11 + TVG_MASK_METHOD_ADD, ///< Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) @since 1.0 + TVG_MASK_METHOD_SUBTRACT, ///< Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) @since 1.0 + TVG_MASK_METHOD_INTERSECT, ///< Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) @since 1.0 + TVG_MASK_METHOD_DIFFERENCE, ///< Calculates the absolute difference between the target color and the source color multiplied by the complement of the target alpha. abs(T - S * (255 - TA)) @since 1.0 + TVG_MASK_METHOD_LIGHTEN, ///< Where multiple masks intersect, the highest transparency value is used. @since 1.0 + TVG_MASK_METHOD_DARKEN ///< Where multiple masks intersect, the lowest transparency value is used. @since 1.0 +} Tvg_Mask_Method; + +/** + * @brief Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method. + * + * @ingroup ThorVGCapi_Paint + * + * @since 0.15 + */ +typedef enum { + TVG_BLEND_METHOD_NORMAL = 0, ///< Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D + TVG_BLEND_METHOD_MULTIPLY, ///< Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D) + TVG_BLEND_METHOD_SCREEN, ///< The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D) + TVG_BLEND_METHOD_OVERLAY, ///< Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D) + TVG_BLEND_METHOD_DARKEN, ///< Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D) + TVG_BLEND_METHOD_LIGHTEN, ///< Only has the opposite action of Darken Only. max(S, D) + TVG_BLEND_METHOD_COLORDODGE, ///< Divides the bottom layer by the inverted top layer. D / (255 - S) + TVG_BLEND_METHOD_COLORBURN, ///< Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S + TVG_BLEND_METHOD_HARDLIGHT, ///< The same as Overlay but with the color roles reversed. (2 * S * D) if (S < Sa), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D) + TVG_BLEND_METHOD_SOFTLIGHT, ///< The same as Overlay but with applying pure black or white does not result in pure black or white. (1 - 2 * S) * (D ^ 2) + (2 * S * D) + TVG_BLEND_METHOD_DIFFERENCE, ///< Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S) + TVG_BLEND_METHOD_EXCLUSION, ///< The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d) + TVG_BLEND_METHOD_HUE, ///< Combine with HSL(Sh + Ds + Dl) then convert it to RGB. + TVG_BLEND_METHOD_SATURATION, ///< Combine with HSL(Dh + Ss + Dl) then convert it to RGB. + TVG_BLEND_METHOD_COLOR, ///< Combine with HSL(Sh + Ss + Dl) then convert it to RGB. + TVG_BLEND_METHOD_LUMINOSITY, ///< Combine with HSL(Dh + Ds + Sl) then convert it to RGB. + TVG_BLEND_METHOD_ADD, ///< Simply adds pixel values of one layer with the other. (S + D) + TVG_BLEND_METHOD_COMPOSITION = 255 ///< Used for intermediate composition. @since 1.0 +} Tvg_Blend_Method; + + +/** + * @brief Enumeration indicating the ThorVG object type value. + * + * ThorVG's drawing objects can return object type values, allowing you to identify the specific type of each object. + * + * @ingroup ThorVGCapi_Paint + * + * @see tvg_paint_get_type() + * @see tvg_gradient_get_type() + * + * @since 1.0 + */ +typedef enum { + TVG_TYPE_UNDEF = 0, ///< Undefined type. + TVG_TYPE_SHAPE, ///< A shape type paint. + TVG_TYPE_SCENE, ///< A scene type paint. + TVG_TYPE_PICTURE, ///< A picture type paint. + TVG_TYPE_TEXT, ///< A text type paint. + TVG_TYPE_LINEAR_GRAD = 10, ///< A linear gradient type. + TVG_TYPE_RADIAL_GRAD ///< A radial gradient type. +} Tvg_Type; + + +/** + * @addtogroup ThorVGCapi_Shape + * \{ + */ + +/** + * @brief Enumeration specifying the values of the path commands accepted by ThorVG. + */ +typedef uint8_t Tvg_Path_Command; + +enum { + TVG_PATH_COMMAND_CLOSE = 0, ///< Ends the current sub-path and connects it with its initial point - corresponds to Z command in the svg path commands. + TVG_PATH_COMMAND_MOVE_TO, ///< Sets a new initial point of the sub-path and a new current point - corresponds to M command in the svg path commands. + TVG_PATH_COMMAND_LINE_TO, ///< Draws a line from the current point to the given point and sets a new value of the current point - corresponds to L command in the svg path commands. + TVG_PATH_COMMAND_CUBIC_TO ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point - corresponds to C command in the svg path commands. +}; + +/** + * @brief Enumeration determining the ending type of a stroke in the open sub-paths. + */ +typedef enum { + TVG_STROKE_CAP_BUTT = 0, ///< The stroke ends exactly at each of the two endpoints of a sub-path. For zero length sub-paths no stroke is rendered. + TVG_STROKE_CAP_ROUND, ///< The stroke is extended in both endpoints of a sub-path by a half circle, with a radius equal to the half of a stroke width. For zero length sub-paths a full circle is rendered. + TVG_STROKE_CAP_SQUARE ///< The stroke is extended in both endpoints of a sub-path by a rectangle, with the width equal to the stroke width and the length equal to the half of the stroke width. For zero length sub-paths the square is rendered with the size of the stroke width. +} Tvg_Stroke_Cap; + + +/** + * @brief Enumeration specifying how to fill the area outside the gradient bounds. + */ +typedef enum { + TVG_STROKE_JOIN_MITER = 0, ///< The outer corner of the joined path segments is spiked. The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect. In case the extension goes beyond the limit, the join style is converted to the Bevel style. + TVG_STROKE_JOIN_ROUND, ///< The outer corner of the joined path segments is rounded. The circular region is centered at the join point. + TVG_STROKE_JOIN_BEVEL ///< The outer corner of the joined path segments is bevelled at the join point. The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke. +} Tvg_Stroke_Join; + + +/** + * @brief Enumeration specifying how to fill the area outside the gradient bounds. + */ +typedef enum { + TVG_STROKE_FILL_PAD = 0, ///< The remaining area is filled with the closest stop color. + TVG_STROKE_FILL_REFLECT, ///< The gradient pattern is reflected outside the gradient area until the expected region is filled. + TVG_STROKE_FILL_REPEAT ///< The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled. +} Tvg_Stroke_Fill; + + +/** + * @brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape. + */ +typedef enum { + TVG_FILL_RULE_NON_ZERO = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape. + TVG_FILL_RULE_EVEN_ODD ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape. +} Tvg_Fill_Rule; + +/** \} */ // end addtogroup ThorVGCapi_Shape + + +/** + * @addtogroup ThorVGCapi_Gradient + * \{ + */ + +/** + * @brief A data structure storing the information about the color and its relative position inside the gradient bounds. + */ +typedef struct { + float offset; /**< The relative position of the color. */ + uint8_t r; /**< The red color channel value in the range [0 ~ 255]. */ + uint8_t g; /**< The green color channel value in the range [0 ~ 255]. */ + uint8_t b; /**< The blue color channel value in the range [0 ~ 255]. */ + uint8_t a; /**< The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. */ +} Tvg_Color_Stop; + +/** \} */ // end addtogroup ThorVGCapi_Gradient + + +/** + * @addtogroup ThorVGCapi_Text + * \{ + */ + +/** + * @brief A data structure storing the information about the color and its relative position inside the gradient bounds. + */ +typedef enum { + TVG_TEXT_WRAP_NONE = 0, ///< Do not wrap text. Text is rendered on a single line and may overflow the bounding area. + TVG_TEXT_WRAP_CHARACTER, ///< Wrap at the character level. If a word cannot fit, it is broken into individual characters to fit the line. + TVG_TEXT_WRAP_WORD, ///< Wrap at the word level. Words that do not fit are moved to the next line. + TVG_TEXT_WRAP_SMART, ///< Smart choose wrapping method: word wrap first, falling back to character wrap if a word does not fit. + TVG_TEXT_WRAP_ELLIPSIS, ///< Truncate overflowing text and append an ellipsis ("...") at the end. Typically used for single-line labels. + TVG_TEXT_WRAP_HYPHENATION ///< Reserved. No Support. +} Tvg_Text_Wrap; + +/** \} */ // end addtogroup ThorVGCapi_Text + +/** + * @brief A data structure representing a point in two-dimensional space. + */ +typedef struct { + float x, y; +} Tvg_Point; + + +/** + * @brief A data structure representing a three-dimensional matrix. + * + * The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. + * The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. + * The elements e31 and e32 are set to 0, e33 is set to 1. + */ +typedef struct { + float e11, e12, e13; + float e21, e22, e23; + float e31, e32, e33; +} Tvg_Matrix; + + +/** + * @brief Callback function type for resolving external assets. + * + * This callback is invoked when a Picture requires an external asset + * (such as an image or font resource). Implementations should load the asset + * into the given @p paint object. + * + * @param[in] paint The target paint object where the resolved asset will be loaded. + * @param[in] src The source path, identifier, or URI of the asset to be resolved. + * @param[in] data User-provided custom data passed to the callback for context. + * + * @return @c true if the asset was successfully resolved and loaded into @p paint, otherwise @c false. + * + * @see tvg_picture_set_asset_resolver() + * + * @since Experimental API + */ +typedef bool (*Tvg_Picture_Asset_Resolver)(Tvg_Paint paint, const char* src, void* data); + + +/** + * @defgroup ThorVGCapi_Initializer Initializer + * @brief A module enabling initialization and termination of the TVG engines. + * + * \{ + */ + +/************************************************************************/ +/* Engine API */ +/************************************************************************/ +/** + * @brief Initializes the ThorVG engine. + * + * ThorVG requires an active runtime environment to operate. + * Internally, it utilizes a task scheduler to efficiently parallelize rendering operations. + * You can specify the number of worker threads using the @p threads parameter. + * During initialization, ThorVG will spawn the specified number of threads. + * + * @param[in] threads The number of worker threads to create. A value of zero indicates that only the main thread will be used. + * + * @note The initializer uses internal reference counting to track multiple calls. + * The number of threads is fixed on the first call to tvg_engine_init() and cannot be changed in subsequent calls. + * @see tvg_engine_term() + */ +TVG_API Tvg_Result tvg_engine_init(unsigned threads); + + +/** + * @brief Terminates the ThorVG engine. + * + * Cleans up resources and stops any internal threads initialized by tvg_engine_init(). + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION Returned if there is nothing to terminate (e.g., tvg_engine_init() was not called). + * + * @note The initializer maintains a reference count for safe repeated use. Only the final call to tvg_engine_term() will fully shut down the engine. + * @see tvg_engine_init() + */ +TVG_API Tvg_Result tvg_engine_term(void); + + +/** + * @brief Retrieves the version of the TVG engine. + * + * @param[out] major A major version number. + * @param[out] minor A minor version number. + * @param[out] micro A micro version number. + * @param[out] version The version of the engine in the format major.minor.micro, or a @p nullptr in case of an internal error. + * + * @retval TVG_RESULT_SUCCESS. + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_engine_version(uint32_t* major, uint32_t* minor, uint32_t* micro, const char** version); + +/** \} */ // end defgroup ThorVGCapi_Initializer + + +/** + * @defgroup ThorVGCapi_Canvas Canvas + * @brief A module for managing and drawing graphical elements. + * + * A canvas is an entity responsible for drawing the target. It sets up the drawing engine and the buffer, which can be drawn on the screen. It also manages given Paint objects. + * + * @note A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical. + * @warning The Paint objects belonging to one Canvas can't be shared among multiple Canvases. + * \{ + */ + + +/** + * @defgroup ThorVGCapi_SwCanvas SwCanvas + * @ingroup ThorVGCapi_Canvas + * + * @brief A module for rendering the graphical elements using the software engine. + * + * \{ + */ + +/************************************************************************/ +/* SwCanvas API */ +/************************************************************************/ + +/** + * @brief Creates a new Software Canvas object with optional rendering engine settings. + * + * This method generates a software canvas instance that can be used for drawing vector graphics. + * It accepts an optional parameter @p op to choose between different rendering engine behaviors. + * + * @param[in] op The rendering engine option. + * + * @return A new Tvg_Canvas object. + * + * @see enum Tvg_Engine_Option + */ +TVG_API Tvg_Canvas tvg_swcanvas_create(Tvg_Engine_Option op); + + +/** + * @brief Sets the buffer used in the rasterization process and defines the used colorspace. + * + * For optimisation reasons TVG does not allocate memory for the output buffer on its own. + * The buffer of a desirable size should be allocated and owned by the caller. + * + * @param[in] canvas The Tvg_Canvas object managing the @p buffer. + * @param[in] buffer A pointer to the allocated memory block of the size @p stride x @p h. + * @param[in] stride The stride of the raster image - in most cases same value as @p w. + * @param[in] w The width of the raster image. + * @param[in] h The height of the raster image. + * @param[in] cs The colorspace value defining the way the 32-bits colors should be read/written. + * + * @retval TVG_RESULT_INVALID_ARGUMENTS An invalid canvas or buffer pointer passed or one of the @p stride, @p w or @p h being zero. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced. + * @retval TVG_RESULT_NOT_SUPPORTED The software engine is not supported. + * + * @warning Do not access @p buffer during tvg_canvas_draw() - tvg_canvas_sync(). It should not be accessed while the engine is writing on it. + * + * @see Tvg_Colorspace + */ +TVG_API Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Tvg_Colorspace cs); + + +/** \} */ // end defgroup ThorVGCapi_SwCanvas + + +/** + * @defgroup ThorVGCapi_GlCanvas SwCanvas + * @ingroup ThorVGCapi_Canvas + * + * @brief A module for rendering the graphical elements using the opengl engine. + * + * \{ + */ + +/************************************************************************/ +/* GlCanvas API */ +/************************************************************************/ + +/** + * @brief Creates a new OpenGL/ES Canvas object with optional rendering engine settings. + * + * This method generates a OpenGL/ES canvas instance that can be used for drawing vector graphics. + * It accepts an optional parameter @p op to choose between different rendering engine behaviors. + * + * @param[in] op The rendering engine option. + * + * @return A new Tvg_Canvas object. + * + * @note Currently, it does not support @c TVG_ENGINE_OPTION_SMART_RENDER. The request will be ignored. + * + * @see enum Tvg_Engine_Option + * + * @since 1.0 + */ +TVG_API Tvg_Canvas tvg_glcanvas_create(Tvg_Engine_Option op); + + +/** + * @brief Sets the drawing target for rasterization. + * + * This function specifies the drawing target where the rasterization will occur. It can target + * a specific framebuffer object (FBO) or the main surface. + * + * @param[in] display The platform-specific display handle (EGLDisplay for EGL). Set @c nullptr for other systems. + * @param[in] surface The platform-specific surface handle (EGLSurface for EGL, HDC for WGL). Set @c nullptr for other systems. + * @param[in] context The OpenGL context to be used for rendering on this canvas. + * @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface. + * @param[in] w The width (in pixels) of the raster image. + * @param[in] h The height (in pixels) of the raster image. + * @param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c TVG_COLORSPACE_ABGR8888S as @c GL_RGBA8. + * + * @note If @p display and @p surface are not provided, the ThorVG GL engine assumes that + * the appropriate OpenGL context is already current and will not attempt to bind a new one. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If the canvas is currently rendering. + * Ensure that @ref tvg_canvas_sync() has been called before setting a new target. + * @retval TVG_RESULT_NOT_SUPPORTED In case the gl engine is not supported. + * + * @see tvg_canvas_sync() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas canvas, void* display, void* surface, void* context, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs); + +/** \} */ // end defgroup ThorVGCapi_GlCanvas + + +/** + * @defgroup ThorVGCapi_WgCanvas WgCanvas + * @ingroup ThorVGCapi_Canvas + * + * @brief A module for rendering the graphical elements using the webgpu engine. + * + * \{ + */ + +/************************************************************************/ +/* WgCanvas API */ +/************************************************************************/ + +/** + * @brief Creates a new WebGPU Canvas object with optional rendering engine settings. + * + * This method generates a WebGPU canvas instance that can be used for drawing vector graphics. + * It accepts an optional parameter @p op to choose between different rendering engine behaviors. + * + * @param[in] op The rendering engine option. + * + * @return A new Tvg_Canvas object. + * + * @note Currently, it does not support @c TVG_ENGINE_OPTION_SMART_RENDER. The request will be ignored. + * + * @see enum Tvg_Engine_Option + * + * @since 1.0 + */ +TVG_API Tvg_Canvas tvg_wgcanvas_create(Tvg_Engine_Option op); + +/** + * @brief Sets the drawing target for the rasterization. + * + * @param[in] device WGPUDevice, a desired handle for the wgpu device. If it is @c nullptr, ThorVG will assign an appropriate device internally. + * @param[in] instance WGPUInstance, context for all other wgpu objects. + * @param[in] target Either WGPUSurface or WGPUTexture, serving as handles to a presentable surface or texture. + * @param[in] w The width of the target. + * @param[in] h The height of the target. + * @param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c TVG_COLORSPACE_ABGR8888S as @c WGPUTextureFormat_RGBA8Unorm. + * @param[in] type @c 0: surface, @c 1: texture are used as pesentable target. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced. + * @retval TVG_RESULT_NOT_SUPPORTED In case the wg engine is not supported. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_wgcanvas_set_target(Tvg_Canvas canvas, void* device, void* instance, void* target, uint32_t w, uint32_t h, Tvg_Colorspace cs, int type); + +/** \} */ // end defgroup ThorVGCapi_WgCanvas + + +/************************************************************************/ +/* Common Canvas API */ +/************************************************************************/ +/** + * @brief Clears the canvas internal data, releases all paints stored by the canvas and destroys the canvas object itself. + * + * @param[in] canvas The Tvg_Canvas object to be destroyed. + * + */ +TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas canvas); + + +/** + * @brief Adds a paint object to the canvas for rendering. + * + * Adds the specified paint into the canvas root scene. Only paints added to + * the canvas are considered rendering targets. The canvas retains the paint + * object until it is explicitly removed via tvg_canvas_remove(). + * + * @param[in] canvas A handle to the canvas that will manage the paint object. + * @param[in] paint A handle to the paint object to be rendered. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If the canvas is not in a valid state to accept new paints. + * + * @note Ownership of the @p paint object is transferred to the canvas upon + * successful addition. To retain ownership, call @ref tvg_paint_ref() + * before adding it to the canvas. + * @note The rendering order of paint objects follows the order in which they are + * added to the canvas. If layering is required, ensure paints are added in + * the desired order. + * + * @see tvg_canvas_insert() + * @see tvg_canvas_remove() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_canvas_add(Tvg_Canvas canvas, Tvg_Paint paint); + + +/** + * @brief Inserts a paint object into the canvas root scene. + * + * Inserts a paint object into the root scene of the specified canvas. If the + * @p at parameter is provided, the paint object is inserted immediately before + * the specified paint in the root scene. If @p at is @c nullptr, the paint object + * is appended to the end of the root scene. + * + * @param[in] canvas A handle to the canvas that will manage the paint object. + * This parameter must be a valid canvas handle. + * @param[in] target A handle to the paint object to be inserted into the root scene. + * This parameter must not be @c nullptr. + * @param[in] at A handle to an existing paint object in the root scene before + * which @p target will be inserted. If @c nullptr, @p target is + * appended to the end of the root scene. + * + * @note Ownership of the @p target object is transferred to the canvas upon + * successful addition. To retain ownership, call @ref tvg_paint_ref() + * before adding it to the canvas. + * @note The rendering order of paint objects follows their order in the root + * scene. If layering is required, ensure paints are inserted in the + * desired order. + * + * @see tvg_canvas_add() + * @see tvg_canvas_remove() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_canvas_insert(Tvg_Canvas canvas, Tvg_Paint target, Tvg_Paint at); + + +/** + * @brief Removes a paint object from the root scene. + * + * This function removes a specified paint object from the root scene. If no paint + * object is specified (i.e., the default @c nullptr is used), the function + * performs to clear all paints from the scene. + * + * @param[in] canvas A Tvg_Canvas object to remove the @p paint. + * @param[in] paint A pointer to the Paint object to be removed from the root scene. + * If @c nullptr, remove all the paints from the root scene. + * + * @see tvg_canvas_add() + * @see tvg_canvas_insert() + * @since 1.0 + */ +TVG_API Tvg_Result tvg_canvas_remove(Tvg_Canvas canvas, Tvg_Paint paint); + + +/** + * @brief Requests the canvas to update modified paint objects in preparation for rendering. + * + * This function triggers an internal update for all paint instances that have been modified + * since the last update. It ensures that the canvas state is ready for accurate rendering. + * + * @param[in] canvas The Tvg_Canvas object to be updated. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION The canvas is not properly prepared. + * This may occur if the canvas target has not been set or if the update is called during drawing. + * Call tvg_canvas_sync() before trying. + * + * @note Only paint objects that have been changed will be processed. + * @note If the canvas is configured with multiple threads, the update may be performed asynchronously. + * + * @see tvg_canvas_sync() + */ +TVG_API Tvg_Result tvg_canvas_update(Tvg_Canvas canvas); + + +/** + * @brief Requests the canvas to render the Paint objects. + * + * @param[in] canvas The Tvg_Canvas object containing elements to be drawn. + * @param[in] clear If @c true, clears the target buffer to zero before drawing. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION The canvas is not properly prepared. + * This may occur if the canvas target has not been set or if the update is called during drawing. + * without calling tvg_canvas_sync() in between. + * + * @note Clearing the buffer is unnecessary if the canvas will be fully covered + * with opaque content. Skipping the clear can improve performance. + * @note Drawing may be performed asynchronously if the thread count is greater than zero. + * To ensure the drawing process is complete, call sync() afterwards. + * @note If the canvas has not been updated prior to tvg_canvas_draw(), it may implicitly perform tvg_canvas_update() + * + * @see tvg_canvas_sync() + * @see tvg_canvas_update() + */ +TVG_API Tvg_Result tvg_canvas_draw(Tvg_Canvas canvas, bool clear); + + +/** + * @brief Guarantees that drawing task is finished. + * + * @param[in] canvas The Tvg_Canvas object containing elements which were drawn. + * + * The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, + * the tvg_canvas_sync() must be called after the tvg_canvas_draw() regardless of threading. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. + * + * @see tvg_canvas_draw() + */ +TVG_API Tvg_Result tvg_canvas_sync(Tvg_Canvas canvas); + + +/** + * @brief Sets the drawing region of the canvas. + * + * This function defines a rectangular area of the canvas to be used for drawing operations. + * The specified viewport clips rendering output to the boundaries of that rectangle. + * + * Please note that changing the viewport is only allowed at the beginning of the rendering sequence—that is, after calling tvg_canvas_sync(). + * + * @param[in] canvas The Tvg_Canvas object containing elements which were drawn. + * @param[in] x The x-coordinate of the upper-left corner of the rectangle. + * @param[in] y The y-coordinate of the upper-left corner of the rectangle. + * @param[in] w The width of the rectangle. + * @param[in] h The height of the rectangle. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If the canvas is not in a synced state. + * + * @see tvg_canvas_sync() + * @see tvg_swcanvas_set_target() + * @see tvg_glcanvas_set_target() + * @see tvg_wgcanvas_set_target() + * + * @warning Changing the viewport is not allowed after calling tvg_canvas_add(), + * tvg_canvas_remove(), tvg_canvas_update(), or tvg_canvas_draw(). + * + * @note When the target is reset, the viewport will also be reset to match the target size. + * @since 0.15 + */ +TVG_API Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas canvas, int32_t x, int32_t y, int32_t w, int32_t h); + +/** \} */ // end defgroup ThorVGCapi_Canvas + +/** + * @defgroup ThorVGCapi_Paint Paint + * @brief A module for managing graphical elements. It enables duplication, transformation and composition. + * + * \{ + */ + +/************************************************************************/ +/* Paint API */ +/************************************************************************/ + +/** + * @brief Safely releases a Tv_Paint object. + * + * This is the counterpart to the `new()` API, and releases the given Paint object safely, + * handling @c nullptr and managing ownership properly. + * + * @param[in] paint A Tvg_Paint object to release. + */ +TVG_API Tvg_Result tvg_paint_rel(Tvg_Paint paint); + + +/** + * @brief Increment the reference count for the Tvg_Paint object. + * + * This method increases the reference count of Tvg_Paint object, allowing shared ownership and control over its lifetime. + * + * @param[in] paint The Tvg_Paint object to increase the reference count. + * + * @return The updated reference count after the increment by 1. + * + * @warning Please ensure that each call to tvg_paint_ref() is paired with a corresponding call to tvg_paint_unref() to prevent a dangling instance. + * + * @see tvg_paint_unref() + * @see tvg_paint_get_ref() + * + * @since 1.0 + */ +TVG_API uint16_t tvg_paint_ref(Tvg_Paint paint); + + +/** + * @brief Decrement the reference count for the Tvg_Paint object. + * + * This method decreases the reference count of the Tvg_Paint object by 1. + * If the reference count reaches zero and the @p free flag is set to true, the instance is automatically deleted. + * + * @param[in] paint The Tvg_Paint object to decrease the reference count. + * @param[in] free Flag indicating whether to delete the Paint instance when the reference count reaches zero. + * + * @return The updated reference count after the decrement. + * + * @see tvg_paint_ref() + * @see tvg_paint_get_ref() + * + * @since 1.0 + */ +TVG_API uint16_t tvg_paint_unref(Tvg_Paint paint, bool free); + + +/** + * @brief Retrieve the current reference count of the Tvg_Paint object. + * + * This method provides the current reference count, allowing the user to check the shared ownership state of the Tvg_Paint object. + * + * @param[in] paint The Tvg_Paint object to return the reference count. + * + * @return The current reference count of the Tvg_Paint object. + * + * @see tvg_paint_ref() + * @see tvg_paint_unref() + * + * @since 1.0 + */ +TVG_API uint16_t tvg_paint_get_ref(const Tvg_Paint paint); + + +/** + * @brief Sets the visibility of the Paint object. + * + * This is useful for selectively excluding paint objects during rendering. + * + * @param[in] paint The Tvg_Paint object to set the visibility status. + * @param[in] on A boolean flag indicating visibility. The default is @c true. + * @c true, the object will be rendered by the engine. + * @c false, the object will be excluded from the drawing process. + * + * @note An invisible object is not considered inactive—it may still participate + * in internal update processing if its properties are updated, but it will not + * be taken into account for the final drawing output. To completely deactivate + * a paint object, remove it from the canvas. + * + * @see tvg_paint_get_visible() + * @see tvg_canvas_remove() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_paint_set_visible(Tvg_Paint paint, bool visible); + + +/** + * @brief Gets the current visibility status of the Paint object. + * + * @param[in] paint The Tvg_Paint object to return the visibility status. + * + * @return true if the object is visible and will be rendered. + * false if the object is hidden and will not be rendered. + * + * @see tvg_paint_set_visible() + * + * @since 1.0 + */ +TVG_API bool tvg_paint_get_visible(const Tvg_Paint paint); + + +/** + * @brief Scales the given Tvg_Paint object by the given factor. + * + * @param[in] paint The Tvg_Paint object to be scaled. + * @param[in] factor The value of the scaling factor. The default value is 1. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION in case a custom transform is applied. + * + * @see tvg_paint_set_transform() + */ +TVG_API Tvg_Result tvg_paint_scale(Tvg_Paint paint, float factor); + + +/** + * @brief Rotates the given Tvg_Paint by the given angle. + * + * The angle in measured clockwise from the horizontal axis. + * The rotational axis passes through the point on the object with zero coordinates. + * + * @param[in] paint The Tvg_Paint object to be rotated. + * @param[in] degree The value of the rotation angle in degrees. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION in case a custom transform is applied. + * + * @see tvg_paint_set_transform() + */ +TVG_API Tvg_Result tvg_paint_rotate(Tvg_Paint paint, float degree); + + +/** + * @brief Moves the given Tvg_Paint in a two-dimensional space. + * + * The origin of the coordinate system is in the upper-left corner of the canvas. + * The horizontal and vertical axes point to the right and down, respectively. + * + * @param[in] paint The Tvg_Paint object to be shifted. + * @param[in] x The value of the horizontal shift. + * @param[in] y The value of the vertical shift. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION in case a custom transform is applied. + * + * @see tvg_paint_set_transform() + */ +TVG_API Tvg_Result tvg_paint_translate(Tvg_Paint paint, float x, float y); + + +/** + * @brief Transforms the given Tvg_Paint using the augmented transformation matrix. + * + * The augmented matrix of the transformation is expected to be given. + * + * @param[in] paint The Tvg_Paint object to be transformed. + * @param[in] m The 3x3 augmented matrix. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. + */ +TVG_API Tvg_Result tvg_paint_set_transform(Tvg_Paint paint, const Tvg_Matrix* m); + + +/** + * @brief Gets the matrix of the affine transformation of the given Tvg_Paint object. + * + * In case no transformation was applied, the identity matrix is returned. + * + * @param[in] paint The Tvg_Paint object of which to get the transformation matrix. + * @param[out] m The 3x3 augmented matrix. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. + */ +TVG_API Tvg_Result tvg_paint_get_transform(Tvg_Paint paint, Tvg_Matrix* m); + + +/** + * @brief Sets the opacity of the given Tvg_Paint. + * + * @param[in] paint The Tvg_Paint object of which the opacity value is to be set. + * @param[in] opacity The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible. + */ +TVG_API Tvg_Result tvg_paint_set_opacity(Tvg_Paint paint, uint8_t opacity); + + +/** + * @brief Gets the opacity of the given Tvg_Paint. + * + * @param[in] paint The Tvg_Paint object of which to get the opacity value. + * @param[out] opacity The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. + */ +TVG_API Tvg_Result tvg_paint_get_opacity(const Tvg_Paint paint, uint8_t* opacity); + + +/** + * @brief Duplicates the given Tvg_Paint object. + * + * Creates a new object and sets its all properties as in the original object. + * + * @param[in] paint The Tvg_Paint object to be copied. + * + * @return A copied Tvg_Paint object if succeed, @c nullptr otherwise. + */ +TVG_API Tvg_Paint tvg_paint_duplicate(Tvg_Paint paint); + + +/** + * @brief Checks whether a given region intersects the filled area of the paint. + * + * This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— + * intersects the geometric fill region of the paint object. + * + * This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) + * occurs within a painted region. + * + * The paint must be updated in a Canvas beforehand—typically after the Canvas has been + * drawn and synchronized. + * + * @param[in] paint A Tvg_Paint pointer to the shape object to be tested. + * @param[in] x The x-coordinate of the top-left corner of the test region. + * @param[in] y The y-coordinate of the top-left corner of the test region. + * @param[in] w The width of the region to test. Must be greater than 0; defaults to 1. + * @param[in] h The height of the region to test. Must be greater than 0; defaults to 1. + * + * @return @c true if any part of the region intersects the filled area; otherwise, @c false. + * + * @note To test a single point, set the region size to w = 1, h = 1. + * @note For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection. + * @note This test does not take into account the results of blending or masking. + * @note This test does take into account the the hidden paints as well. @see tvg_paint_set_visible(). + * @since 1.0 + */ +TVG_API bool tvg_paint_intersects(Tvg_Paint paint, int32_t x, int32_t y, int32_t w, int32_t h); + + +/** + * @brief Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space. + * + * Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. + * The returned values @p x, @p y, @p w, @p h, may have invalid if the operation fails. Thus, please check the retval. + * + * This bounding box can be used to determine the actual rendered area of the object on the canvas, + * for purposes such as hit-testing, culling, or layout calculations. + * + * @param[in] paint The Tvg_Paint object of which to get the bounds. + * @param[out] x The x-coordinate of the upper-left corner of the bounding box. + * @param[out] y The y-coordinate of the upper-left corner of the bounding box. + * @param[out] w The width of the bounding box. + * @param[out] h The height of the bounding box. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid @p paint. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If it failed to compute the bounding box (mostly due to invalid path information). + * + * @see tvg_paint_get_obb() + * @see tvg_canvas_update() + */ +TVG_API Tvg_Result tvg_paint_get_aabb(Tvg_Paint paint, float* x, float* y, float* w, float* h); + + +/** + * @brief Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space. + * + * This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. + * The returned values @p pt4 may have invalid if the operation fails. Thus, please check the retval. + * + * This bounding box can be used to obtain the transformed bounding region in canvas space + * by taking the geometry's axis-aligned bounding box (AABB) in the object's local coordinate space + * and applying the object's transformations. + * + * @param[in] paint The Tvg_Paint object of which to get the bounds. + * @param[out] pt4 An array of four points representing the bounding box. The array size must be 4. + * + * @retval TVG_RESULT_INVALID_ARGUMENT @p paint or @p pt4 is invalid. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If it failed to compute the bounding box (mostly due to invalid path information). + * + * @see tvg_paint_get_aabb() + * @see tvg_canvas_update() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_paint_get_obb(Tvg_Paint paint, Tvg_Point* pt4); + + +/** + * @brief Sets the masking target object and the masking method. + * + * @param[in] paint The source object of the masking. + * @param[in] target The target object of the masking. + * @param[in] method The method used to mask the source object with the target. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION if the target has already belonged to another paint. + * + */ +TVG_API Tvg_Result tvg_paint_set_mask_method(Tvg_Paint paint, Tvg_Paint target, Tvg_Mask_Method method); + + +/** + * @brief Gets the masking target object and the masking method. + * + * @param[in] paint The source object of the masking. + * @param[out] target The target object of the masking. + * @param[out] method The method used to mask the source object with the target. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. + */ +TVG_API Tvg_Result tvg_paint_get_mask_method(const Tvg_Paint paint, const Tvg_Paint target, Tvg_Mask_Method* method); + + +/** + * @brief Clip the drawing region of the paint object. + * + * This function restricts the drawing area of the paint object to the specified shape's paths. + * + * @param[in] paint The target object of the clipping. + * @param[in] clipper The shape object as the clipper. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION if the target has already belonged to another paint. + * @retval TVG_RESULT_NOT_SUPPORTED If the @p clipper type is not Shape. + * + * @see tvg_paint_get_clip() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_paint_set_clip(Tvg_Paint paint, Tvg_Paint clipper); + +/** + * @brief Get the clipper shape of the paint object. + * + * This function returns the clipper that has been previously set to this paint object. + * + * @return The shape object used as the clipper, or @c nullptr if no clipper is set. + * + * @see tvg_paint_set_clip() + * + * @since 1.0 + */ +TVG_API Tvg_Paint tvg_paint_get_clip(const Tvg_Paint paint); + +/** + * @brief Retrieves the parent paint object. + * + * This function returns a pointer to the parent object if the current paint + * belongs to one. Otherwise, it returns @c nullptr. + * + * @param[in] paint The Tvg_Paint object of which to get the scene. + * + * @return A pointer to the parent object if available, otherwise @c nullptr. + * + * @see tvg_scene_add() + * @see tvg_canvas_add() + * + * @since 1.0 +*/ +TVG_API Tvg_Paint tvg_paint_get_parent(const Tvg_Paint paint); + + +/** + * @brief Gets the unique value of the paint instance indicating the instance type. + * + * @param[in] paint The Tvg_Paint object of which to get the type value. + * @param[out] type The unique type of the paint instance type. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_paint_get_type(const Tvg_Paint paint, Tvg_Type* type); + + +/** + * @brief Sets the blending method for the paint object. + * + * The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. + * its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. + * The blending operation is determined by the chosen @p BlendMethod, which specifies how the colors or images are combined. + * + * @param[in] paint The Tvg_Paint object of which to set the blend method. + * @param[in] method The blending method to be set. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_paint_set_blend_method(Tvg_Paint paint, Tvg_Blend_Method method); + + +/** \} */ // end defgroup ThorVGCapi_Paint + +/** + * @defgroup ThorVGCapi_Shape Shape + * + * @brief A module for managing two-dimensional figures and their properties. + * + * A shape has three major properties: shape outline, stroking, filling. The outline in the shape is retained as the path. + * Path can be composed by accumulating primitive commands such as tvg_shape_move_to(), tvg_shape_line_to(), tvg_shape_cubic_to() or complete shape interfaces such as tvg_shape_append_rect(), tvg_shape_append_circle(), etc. + * Path can consists of sub-paths. One sub-path is determined by a close command. + * + * The stroke of a shape is an optional property in case the shape needs to be represented with/without the outline borders. + * It's efficient since the shape path and the stroking path can be shared with each other. It's also convenient when controlling both in one context. + * + * \{ + */ + +/************************************************************************/ +/* Shape API */ +/************************************************************************/ + +/** + * @brief Creates a new Shape object. + * + * This function allocates and returns a new Shape instance. + * To properly destroy the Shape object, use @ref tvg_paint_rel(). + * + * @return A pointer to the newly created Shape object. + * + * @see tvg_paint_rel() + */ +TVG_API Tvg_Paint tvg_shape_new(void); + + +/** + * @brief Resets the shape path properties. + * + * The color, the fill and the stroke properties are retained. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note The memory, where the path data is stored, is not deallocated at this stage for caching effect. + */ +TVG_API Tvg_Result tvg_shape_reset(Tvg_Paint paint); + + +/** + * @brief Sets the initial point of the sub-path. + * + * The value of the current point is set to the given point. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] x The horizontal coordinate of the initial point of the sub-path. + * @param[in] y The vertical coordinate of the initial point of the sub-path. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_shape_move_to(Tvg_Paint paint, float x, float y); + + +/** + * @brief Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point. + * + * The value of the current point is set to the given end-point. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] x The horizontal coordinate of the end-point of the line. + * @param[in] y The vertical coordinate of the end-point of the line. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note In case this is the first command in the path, it corresponds to the tvg_shape_move_to() call. + */ +TVG_API Tvg_Result tvg_shape_line_to(Tvg_Paint paint, float x, float y); + + +/** + * @brief Adds new points to the sub-path, which results in drawing a cubic Bezier curve. + * + * The Bezier curve starts at the current point and ends at the given end-point (@p x, @p y). Two control points (@p cx1, @p cy1) and (@p cx2, @p cy2) are used to determine the shape of the curve. + * The value of the current point is set to the given end-point. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] cx1 The horizontal coordinate of the 1st control point. + * @param[in] cy1 The vertical coordinate of the 1st control point. + * @param[in] cx2 The horizontal coordinate of the 2nd control point. + * @param[in] cy2 The vertical coordinate of the 2nd control point. + * @param[in] x The horizontal coordinate of the endpoint of the curve. + * @param[in] y The vertical coordinate of the endpoint of the curve. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note In case this is the first command in the path, no data from the path are rendered. + */ +TVG_API Tvg_Result tvg_shape_cubic_to(Tvg_Paint paint, float cx1, float cy1, float cx2, float cy2, float x, float y); + + +/** + * @brief Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path. + * + * The value of the current point is set to the initial point of the closed sub-path. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note In case the sub-path does not contain any points, this function has no effect. + */ +TVG_API Tvg_Result tvg_shape_close(Tvg_Paint paint); + + +/** + * @brief Appends a rectangle to the path. + * + * The rectangle with rounded corners can be achieved by setting non-zero values to @p rx and @p ry arguments. + * The @p rx and @p ry values specify the radii of the ellipse defining the rounding of the corners. + * + * The position of the rectangle is specified by the coordinates of its upper-left corner - @p x and @p y arguments. + * + * The rectangle is treated as a new sub-path - it is not connected with the previous sub-path. + * + * The value of the current point is set to (@p x + @p rx, @p y) - in case @p rx is greater + * than @p w/2 the current point is set to (@p x + @p w/2, @p y) + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] x The horizontal coordinate of the upper-left corner of the rectangle. + * @param[in] y The vertical coordinate of the upper-left corner of the rectangle. + * @param[in] w The width of the rectangle. + * @param[in] h The height of the rectangle. + * @param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle. + * @param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle. + * @param[in] cw Specifies the path direction: @c true for clockwise, @c false for counterclockwise. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note For @p rx and @p ry greater than or equal to the half of @p w and the half of @p h, respectively, the shape become an ellipse. + */ +TVG_API Tvg_Result tvg_shape_append_rect(Tvg_Paint paint, float x, float y, float w, float h, float rx, float ry, bool cw); + + +/** + * @brief Appends an ellipse to the path. + * + * The position of the ellipse is specified by the coordinates of its center - @p cx and @p cy arguments. + * + * The ellipse is treated as a new sub-path - it is not connected with the previous sub-path. + * + * The value of the current point is set to (@p cx, @p cy - @p ry). + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] cx The horizontal coordinate of the center of the ellipse. + * @param[in] cy The vertical coordinate of the center of the ellipse. + * @param[in] rx The x-axis radius of the ellipse. + * @param[in] ry The y-axis radius of the ellipse. + * @param[in] cw Specifies the path direction: @c true for clockwise, @c false for counterclockwise. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint paint, float cx, float cy, float rx, float ry, bool cw); + + +/** + * @brief Appends a given sub-path to the path. + * + * The current point value is set to the last point from the sub-path. + * For each command from the @p cmds array, an appropriate number of points in @p pts array should be specified. + * If the number of points in the @p pts array is different than the number required by the @p cmds array, the shape with this sub-path will not be displayed on the screen. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] cmds The array of the commands in the sub-path. + * @param[in] cmdCnt The length of the @p cmds array. + * @param[in] pts The array of the two-dimensional points. + * @param[in] ptsCnt The length of the @p pts array. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument or @p cmdCnt or @p ptsCnt equal to zero. + */ +TVG_API Tvg_Result tvg_shape_append_path(Tvg_Paint paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt); + + +/** + * @brief Retrieves the current path data of the shape. + * + * This function provides access to the shape's path data, including the commands + * and points that define the path. + * + * @param[out] cmds Pointer to the array of commands representing the path. + * Can be @c nullptr if this information is not needed. + * @param[out] cmdsCnt Pointer to the variable that receives the number of commands in the @p cmds array. + * Can be @c nullptr if this information is not needed. + * @param[out] pts Pointer to the array of two-dimensional points that define the path. + * Can be @c nullptr if this information is not needed. + * @param[out] ptsCnt Pointer to the variable that receives the number of points in the @p pts array. + * Can be @c nullptr if this information is not needed. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note If any of the arguments are @c nullptr, that value will be ignored. + */ +TVG_API Tvg_Result tvg_shape_get_path(const Tvg_Paint paint, const Tvg_Path_Command** cmds, uint32_t* cmdsCnt, const Tvg_Point** pts, uint32_t* ptsCnt); + + +/** + * @brief Sets the stroke width for the path. + * + * This function defines the thickness of the stroke applied to all figures + * in the path object. A stroke is the outline drawn along the edges of the + * path's geometry. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] width The width of the stroke in pixels. Must be positive value. (The default is 0) + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note A value of @p width 0 disables the stroke. + * + * @see tvg_shape_set_stroke_color() + */ +TVG_API Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint paint, float width); + + +/** + * @brief Gets the shape's stroke width. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] width The stroke width. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + */ +TVG_API Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint paint, float* width); + + +/** + * @brief Sets the shape's stroke color. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note If the stroke width is 0 (default), the stroke will not be visible regardless of the color. + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * + * @see tvg_shape_set_stroke_width() + * @see tvg_shape_set_stroke_gradient() + */ +TVG_API Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a); + + +/** + * @brief Gets the shape's stroke color. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[out] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[out] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION No stroke was set. + */ +TVG_API Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); + + +/** + * @brief Sets the gradient fill of the stroke for all of the figures from the path. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] grad The gradient fill. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * @retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer or an error with accessing it. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * + * @see tvg_shape_set_stroke_color() + */ +TVG_API Tvg_Result tvg_shape_set_stroke_gradient(Tvg_Paint paint, Tvg_Gradient grad); + + +/** + * @brief Gets the gradient fill of the shape's stroke. + * + * The function does not allocate any memory. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] grad The gradient fill. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + */ +TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint paint, Tvg_Gradient* grad); + + +/** + * @brief Sets the shape's stroke dash pattern. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] dashPattern An array of alternating dash and gap lengths. + * @param[in] cnt The size of the @p dashPattern array. + * @param[in] offset The shift of the starting point within the repeating dash pattern, from which the pattern begins to be applied. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case @p dashPattern is @c nullptr and @p cnt > 0 or @p dashPattern is not @c nullptr and @p cnt is zero. + * + * @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt. + * @note Values of @p dashPattern less than zero are treated as zero. + * @note If all values in the @p dashPattern are equal to or less than 0, the dash is ignored. + * @note If the @p dashPattern contains an odd number of elements, the sequence is repeated in the same + * order to form an even-length pattern, preserving the alternation of dashes and gaps. + * @since 1.0 + */ +TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint paint, const float* dashPattern, uint32_t cnt, float offset); + + +/** + * @brief Gets the dash pattern of the stroke. + * + * The function does not allocate any memory. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] dashPattern The array of consecutive pair values of the dash length and the gap length. + * @param[out] cnt The size of the @p dashPattern array. + * @param[out] offset The shift of the starting point within the repeating dash pattern. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + * @since 1.0 + */ +TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint paint, const float** dashPattern, uint32_t* cnt, float* offset); + + +/** + * @brief Sets the cap style used for stroking the path. + * + * The cap style specifies the shape to be used at the end of the open stroked sub-paths. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] cap The cap style value. The default value is @c TVG_STROKE_CAP_SQUARE. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint paint, Tvg_Stroke_Cap cap); + + +/** + * @brief Gets the stroke cap style used for stroking the path. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] cap The cap style value. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + */ +TVG_API Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint paint, Tvg_Stroke_Cap* cap); + + +/** + * @brief Sets the join style for stroked path segments. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] join The join style value. The default value is @c TVG_STROKE_JOIN_BEVEL. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint paint, Tvg_Stroke_Join join); + + +/** + * @brief The function gets the stroke join method + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] join The join style value. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + */ +TVG_API Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint paint, Tvg_Stroke_Join* join); + + +/** + * @brief Sets the stroke miterlimit. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] miterlimit The miterlimit imposes a limit on the extent of the stroke join when the @c TVG_STROKE_JOIN_MITER join style is set. The default value is 4. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or Unsupported @p miterlimit values (less than zero). + * + * @since 0.11 + */ +TVG_API Tvg_Result tvg_shape_set_stroke_miterlimit(Tvg_Paint paint, float miterlimit); + + +/** + * @brief The function gets the stroke miterlimit. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] miterlimit The stroke miterlimit. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + * + * @since 0.11 + */ +TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint paint, float* miterlimit); + + +/** + * @brief Sets the trim of the shape along the defined path segment, allowing control over which part of the shape is visible. + * + * If the values of the arguments @p begin and @p end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] begin Specifies the start of the segment to display along the path. + * @param[in] end Specifies the end of the segment to display along the path. + * @param[in] simultaneous Determines how to trim multiple paths within a single shape. If set to @c true (default), trimming is applied simultaneously to all paths; + * Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_shape_set_trimpath(Tvg_Paint paint, float begin, float end, bool simultaneous); + + +/** + * @brief Sets the shape's solid color. + * + * The parts of the shape defined as inner are colored. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * @see tvg_shape_set_fill_rule() + */ +TVG_API Tvg_Result tvg_shape_set_fill_color(Tvg_Paint paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a); + + +/** + * @brief Gets the shape's solid color. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[out] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[out] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); + + +/** + * @brief Sets the fill rule for the shape. + * + * Specifies how the interior of the shape is determined when its path intersects itself. + * The default fill rule is @c TVG_FILL_RULE_NON_ZERO. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] rule The fill rule to apply to the shape. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint paint, Tvg_Fill_Rule rule); + + +/** + * @brief Retrieves the current fill rule used by the shape. + * + * This function returns the fill rule, which determines how the interior + * regions of the shape are calculated when it overlaps itself. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] rule The current Tvg_Fill_Rule value of the shape. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + */ +TVG_API Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint paint, Tvg_Fill_Rule* rule); + + +/** + * @brief Sets the rendering order of the stroke and the fill. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] strokeFirst If @c true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option). + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @since 0.10 + */ +TVG_API Tvg_Result tvg_shape_set_paint_order(Tvg_Paint paint, bool strokeFirst); + + +/** + * @brief Sets the gradient fill for all of the figures from the path. + * + * The parts of the shape defined as inner are filled. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[in] grad The gradient fill. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * @retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * @see tvg_shape_set_fill_rule() + */ +TVG_API Tvg_Result tvg_shape_set_gradient(Tvg_Paint paint, Tvg_Gradient grad); + + +/** + * @brief Gets the gradient fill of the shape. + * + * The function does not allocate any data. + * + * @param[in] paint A Tvg_Paint pointer to the shape object. + * @param[out] grad The gradient fill. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. + */ +TVG_API Tvg_Result tvg_shape_get_gradient(const Tvg_Paint paint, Tvg_Gradient* grad); + + +/** \} */ // end defgroup ThorVGCapi_Shape + + +/** + * @defgroup ThorVGCapi_Gradient Gradient + * @brief A module managing the gradient fill of objects. + * + * The module enables to set and to get the gradient colors and their arrangement inside the gradient bounds, + * to specify the gradient bounds and the gradient behavior in case the area defined by the gradient bounds + * is smaller than the area to be filled. + * + * \{ + */ + +/************************************************************************/ +/* Gradient API */ +/************************************************************************/ +/** + * @brief Creates a new linear gradient object. + * + * @return A new linear gradient object. + */ +TVG_API Tvg_Gradient tvg_linear_gradient_new(void); + + +/** + * @brief Creates a new radial gradient object. + * + * @return A new radial gradient object. + */ +TVG_API Tvg_Gradient tvg_radial_gradient_new(void); + + +/** + * @brief Sets the linear gradient bounds. + * + * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing + * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking + * (@p x1, @p y1) and (@p x2, @p y2). + * + * @param[in] grad The Tvg_Gradient object of which bounds are to be set. + * @param[in] x1 The horizontal coordinate of the first point used to determine the gradient bounds. + * @param[in] y1 The vertical coordinate of the first point used to determine the gradient bounds. + * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds. + * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. + * + * @note In case the first and the second points are equal, an object is filled with a single color using the last color specified in the tvg_gradient_set_color_stops(). + * @see tvg_gradient_set_color_stops() + */ +TVG_API Tvg_Result tvg_linear_gradient_set(Tvg_Gradient grad, float x1, float y1, float x2, float y2); + + +/** + * @brief Gets the linear gradient bounds. + * + * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing + * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking + * (@p x1, @p y1) and (@p x2, @p y2). + * + * @param[in] grad The Tvg_Gradient object of which to get the bounds. + * @param[out] x1 The horizontal coordinate of the first point used to determine the gradient bounds. + * @param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds. + * @param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds. + * @param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. + */ +TVG_API Tvg_Result tvg_linear_gradient_get(Tvg_Gradient grad, float* x1, float* y1, float* x2, float* y2); + + +/** + * @brief Sets the radial gradient attributes. + * + * The radial gradient is defined by the end circle with a center (@p cx, @p cy) and a radius @p r and + * the start circle with a center/focal point (@p fx, @p fy) and a radius @p fr. + * The gradient will be rendered such that the gradient stop at an offset of 100% aligns with the edge of the end circle + * and the stop at an offset of 0% aligns with the edge of the start circle. + * + * @param[in] grad The Tvg_Gradient object of which bounds are to be set. + * @param[in] cx The horizontal coordinate of the center of the end circle. + * @param[in] cy The vertical coordinate of the center of the end circle. + * @param[in] r The radius of the end circle. + * @param[in] fx The horizontal coordinate of the center of the start circle. + * @param[in] fy The vertical coordinate of the center of the start circle. + * @param[in] fr The radius of the start circle. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer or the radius @p r or @p fr value is negative. + * + * @note In case the radius @p r is zero, an object is filled with a single color using the last color specified in the specified in the tvg_gradient_set_color_stops(). + * @note In case the focal point (@p fx and @p fy) lies outside the end circle, it is projected onto the edge of the end circle. + * @note If the start circle doesn't fully fit inside the end circle (after possible repositioning), the @p fr is reduced accordingly. + * @note By manipulating the position and size of the focal point, a wide range of visual effects can be achieved, such as directing + * the gradient focus towards a specific edge or enhancing the depth and complexity of shading patterns. + * If a focal effect is not desired, simply align the focal point (@p fx and @p fy) with the center of the end circle (@p cx and @p cy) + * and set the radius (@p fr) to zero. This will result in a uniform gradient without any focal variations. + * + * @see tvg_gradient_set_color_stops() + */ +TVG_API Tvg_Result tvg_radial_gradient_set(Tvg_Gradient grad, float cx, float cy, float r, float fx, float fy, float fr); + + +/** + * @brief The function gets radial gradient attributes. + * + * @param[in] grad The Tvg_Gradient object of which to get the gradient attributes. + * @param[out] cx The horizontal coordinate of the center of the end circle. + * @param[out] cy The vertical coordinate of the center of the end circle. + * @param[out] r The radius of the end circle. + * @param[out] fx The horizontal coordinate of the center of the start circle. + * @param[out] fy The vertical coordinate of the center of the start circle. + * @param[out] fr The radius of the start circle. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. + * + * @see tvg_radial_gradient_set() + */ +TVG_API Tvg_Result tvg_radial_gradient_get(Tvg_Gradient grad, float* cx, float* cy, float* r, float* fx, float* fy, float* fr); + + +/** + * @brief Sets the parameters of the colors of the gradient and their position. + * + * @param[in] grad The Tvg_Gradient object of which the color information is to be set. + * @param[in] color_stop An array of Tvg_Color_Stop data structure. + * @param[in] cnt The size of the @p color_stop array equal to the colors number used in the gradient. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. + */ +TVG_API Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient grad, const Tvg_Color_Stop* color_stop, uint32_t cnt); + + +/** + * @brief Gets the parameters of the colors of the gradient, their position and number + * + * The function does not allocate any memory. + * + * @param[in] grad The Tvg_Gradient object of which to get the color information. + * @param[out] color_stop An array of Tvg_Color_Stop data structure. + * @param[out] cnt The size of the @p color_stop array equal to the colors number used in the gradient. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. + */ +TVG_API Tvg_Result tvg_gradient_get_color_stops(const Tvg_Gradient grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt); + + +/** + * @brief Sets the Tvg_Stroke_Fill value, which specifies how to fill the area outside the gradient bounds. + * + * @param[in] grad The Tvg_Gradient object. + * @param[in] spread The FillSpread value. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. + */ +TVG_API Tvg_Result tvg_gradient_set_spread(Tvg_Gradient grad, const Tvg_Stroke_Fill spread); + + +/** + * @brief Gets the FillSpread value of the gradient object. + * + * @param[in] grad The Tvg_Gradient object. + * @param[out] spread The FillSpread value. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. + */ +TVG_API Tvg_Result tvg_gradient_get_spread(const Tvg_Gradient grad, Tvg_Stroke_Fill* spread); + + +/** + * @brief Sets the matrix of the affine transformation for the gradient object. + * + * The augmented matrix of the transformation is expected to be given. + * + * @param[in] grad The Tvg_Gradient object to be transformed. + * @param[in] m The 3x3 augmented matrix. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. + */ +TVG_API Tvg_Result tvg_gradient_set_transform(Tvg_Gradient grad, const Tvg_Matrix* m); + + +/** + * @brief Gets the matrix of the affine transformation of the gradient object. + * + * In case no transformation was applied, the identity matrix is set. + * + * @param[in] grad The Tvg_Gradient object of which to get the transformation matrix. + * @param[out] m The 3x3 augmented matrix. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. + */ +TVG_API Tvg_Result tvg_gradient_get_transform(const Tvg_Gradient grad, Tvg_Matrix* m); + + +/** + * @brief Gets the unique value of the gradient instance indicating the instance type. + * + * @param[in] grad The Tvg_Gradient object of which to get the type value. + * @param[out] type The unique type of the gradient instance type. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_gradient_get_type(const Tvg_Gradient grad, Tvg_Type* type); + + +/** + * @brief Duplicates the given Tvg_Gradient object. + * + * Creates a new object and sets its all properties as in the original object. + * + * @param[in] grad The Tvg_Gradient object to be copied. + * + * @return A copied Tvg_Gradient object if succeed, @c nullptr otherwise. + */ +TVG_API Tvg_Gradient tvg_gradient_duplicate(Tvg_Gradient grad); + + +/** + * @brief Deletes the given gradient object. + * + * @param[in] grad The gradient object to be deleted. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. + */ +TVG_API Tvg_Result tvg_gradient_del(Tvg_Gradient grad); + + +/** \} */ // end defgroup ThorVGCapi_Gradient + + +/** + * @defgroup ThorVGCapi_Picture Picture + * + * @brief A module enabling to create and to load an image in one of the supported formats: svg, png, jpg, lottie and raw. + * + * + * \{ + */ + +/************************************************************************/ +/* Picture API */ +/************************************************************************/ + +/** + * @brief Creates a new Picture object. + * + * This function allocates and returns a new Picture instance. + * To properly destroy the Picture object, use @ref tvg_paint_rel(). + * + * @return A pointer to the newly created Picture object. + * + * @see tvg_paint_rel() + */ +TVG_API Tvg_Paint tvg_picture_new(void); + + +/** + * @brief Loads a picture data directly from a file. + * + * ThorVG efficiently caches the loaded data using the specified @p path as a key. + * This means that loading the same file again will not result in duplicate operations; + * instead, ThorVG will reuse the previously loaded picture data. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[in] path The absolute path to the image file. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or an empty @p path. + * @retval TVG_RESULT_NOT_SUPPORTED A file with an unknown extension. + */ +TVG_API Tvg_Result tvg_picture_load(Tvg_Paint picture, const char* path); + + +/** + * @brief Loads raw image data in a specific format from a memory block of the given size. + * + * ThorVG efficiently caches the loaded data, using the provided @p data address as a key + * when @p copy is set to @c false. This allows ThorVG to avoid redundant operations + * by reusing the previously loaded picture data for the same sharable @p data, + * rather than duplicating the load process. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[in] data A pointer to the memory block where the raw image data is stored. + * @param[in] w The width of the image in pixels. + * @param[in] h The height of the image in pixels. + * @param[in] cs Specifies how the 32-bit color values should be interpreted (read/write). + * @param[in] copy If @c true, the data is copied into the engine's local buffer. If @c false, the data is not copied. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or no data are provided or the @p w or @p h value is zero or less. + * + * @since 0.9 + */ +TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint picture, const uint32_t *data, uint32_t w, uint32_t h, Tvg_Colorspace cs, bool copy); + + +/** + * @brief Loads a picture data from a memory block of a given size. + * + * ThorVG efficiently caches the loaded data using the specified @p data address as a key + * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations + * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[in] data A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if @p copy is @c false + * @param[in] size The size in bytes of the memory occupied by the @p data. + * @param[in] mimetype Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lot", "lottie+json", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. + * @param[in] rpath A resource directory path, if the @p data needs to access any external resources. + * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument or the @p size is zero or less. + * @retval TVG_RESULT_NOT_SUPPORTED A file with an unknown extension. + * + * @warning: It's the user responsibility to release the @p data memory if the @p copy is @c true. + */ +TVG_API Tvg_Result tvg_picture_load_data(Tvg_Paint picture, const char *data, uint32_t size, const char *mimetype, const char* rpath, bool copy); + + +/** + * @brief Sets the asset resolver callback for handling external resources (e.g., images and fonts). + * + * This callback is invoked when an external asset reference (such as an image source or file path) + * is encountered in a Picture object. It allows the user to provide a custom mechanism for loading + * or substituting assets, such as loading from an external source or a virtual filesystem. + * + * @param[in] resolver A user-defined function that handles the resolution of asset paths. + * The function should return @c true if the asset was successfully resolved by the user, or @c false if it was not. + * @param[in] data A pointer to user-defined data that will be passed to the callback each time it is invoked. + * This can be used to maintain context or access external resources. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p picture argument. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If the @p picture is already loaded. + * + * @note This function must be called before @ref tvg_picture_load() + * Setting the resolver after loading will have no effect on asset resolution for that asset. + * @note If @c false is returned by @p resolver, ThorVG will attempt to resolve the resource using its internal resolution mechanism as a fallback. + * @note To unset the resolver, pass @c nullptr as the @p resolver parameter. + * @note Experimental API + * + * @see Tvg_Picture_Asset_Resolver + */ +TVG_API Tvg_Result tvg_picture_set_asset_resolver(Tvg_Paint picture, Tvg_Picture_Asset_Resolver resolver, void* data); + + +/** + * @brief Resizes the picture content to the given width and height. + * + * The picture content is resized while keeping the default size aspect ratio. + * The scaling factor is established for each of dimensions and the smaller value is applied to both of them. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[in] w A new width of the image in pixels. + * @param[in] h A new height of the image in pixels. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_picture_set_size(Tvg_Paint picture, float w, float h); + + +/** + * @brief Gets the size of the loaded picture. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[out] w A width of the image in pixels. + * @param[out] h A height of the image in pixels. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + */ +TVG_API Tvg_Result tvg_picture_get_size(const Tvg_Paint picture, float* w, float* h); + + +/** + * @brief Sets the normalized origin point of the Picture object. + * + * This method defines the origin point of the Picture using normalized coordinates. + * Unlike a typical pivot point used only for transformations, this origin affects both + * the transformation behavior and the actual rendering position of the Picture. + * + * The specified origin becomes the reference point for positioning the Picture on the canvas. + * For example, setting the origin to (0.5f, 0.5f) moves the visual center of the picture + * to the position specified by Paint::translate(). + * + * The coordinates are given in a normalized range relative to the picture's bounds: + * - (0.0f, 0.0f): top-left corner + * - (0.5f, 0.5f): center + * - (1.0f, 1.0f): bottom-right corner + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[in] x The normalized x-coordinate of the origin point (range: 0.0f to 1.0f). + * @param[in] y The normalized y-coordinate of the origin point (range: 0.0f to 1.0f). + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @note This origin directly affects how the Picture is placed on the canvas when using + * transformations such as translate(), rotate(), or scale(). + * + * @see tvg_paint_translate() + * @see tvg_paint_rotate() + * @see tvg_paint_scale() + * @see tvg_paint_set_transform() + * @see tvg_picture_get_origin() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_picture_set_origin(Tvg_Paint picture, float x, float y); + + +/** + * @brief Gets the normalized origin point of the Picture object. + * + * This method retrieves the current origin point of the Picture, expressed + * in normalized coordinates relative to the picture’s bounds. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[out] x The normalized x-coordinate of the origin (range: 0.0f to 1.0f). + * @param[out] y The normalized y-coordinate of the origin (range: 0.0f to 1.0f). + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. + * + * @see tvg_picture_set_origin() + * @since 1.0 + */ +TVG_API Tvg_Result tvg_picture_get_origin(const Tvg_Paint picture, float* x, float* y); + + +/** + * @brief Retrieve a paint object from the Picture scene by its Unique ID. + * + * This function searches for a paint object within the Picture scene that matches the provided @p id. + * + * @param[in] picture A Tvg_Paint pointer to the picture object. + * @param[in] id The Unique ID of the paint object. + * + * @return A pointer to the paint object that matches the given identifier, or @c nullptr if no matching paint object is found. + * + * @see tvg_accessor_generate_id() + * @since 1.0 + */ +TVG_API const Tvg_Paint tvg_picture_get_paint(Tvg_Paint picture, uint32_t id); + + +/** \} */ // end defgroup ThorVGCapi_Picture + + +/** + * @defgroup ThorVGCapi_Scene Scene + * @brief A module managing the multiple paints as one group paint. + * + * As a group, scene can be transformed, translucent, composited with other target paints, + * its children will be affected by the scene world. + * + * \{ + */ + +/************************************************************************/ +/* Scene API */ +/************************************************************************/ + +/** + * @brief Creates a new Scene object. + * + * This function allocates and returns a new Scene instance. + * To properly destroy the Scene object, use @ref tvg_paint_rel(). + * + * @return A pointer to the newly created Scene object. + * + * @see tvg_paint_rel() + */ +TVG_API Tvg_Paint tvg_scene_new(void); + + +/** + * @brief Adds a paint object to the scene. + * + * Appends the specified paint object to the given scene. Only paint objects + * added to the scene are considered rendering targets. + * + * @param[in] scene A handle to the scene object. + * This parameter must not be @c nullptr. + * @param[in] paint A handle to the paint object to be added to the scene. + * This parameter must not be @c nullptr. + * + * @note Ownership of the @p paint object is transferred to the canvas upon + * successful addition. To retain ownership, call @ref tvg_paint_ref() + * before adding it to the scene. +* @note The rendering order of paint objects follows their order in the root + * scene. If layering is required, ensure the paints are added in the + * desired order. + * + * @see tvg_scene_insert() + * @see tvg_scene_remove() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_add(Tvg_Paint scene, Tvg_Paint paint); + + +/** + * @brief Inserts a paint object into the scene. + * + * Inserts the specified paint object into the scene immediately before the + * given paint object @p at. The @p at parameter must reference an existing + * paint object already added to the scene. + * + * @param[in] scene A handle to the scene object. + * This parameter must not be @c nullptr. + * @param[in] target A handle to the paint object to be inserted into the scene. + * This parameter must not be @c nullptr. + * @param[in] at A handle to an existing paint object in the scene before + * which @p target will be inserted. + * This parameter must not be @c nullptr. + * + * @note Ownership of the @p target object is transferred to the scene upon + * successful addition. To retain ownership, call @ref tvg_paint_ref() + * before adding it to the scene. + * @note The rendering order of paint objects follows their order in the root + * scene. If layering is required, ensure the paints are added in the + * desired order. + * + * @see tvg_scene_add() + * @see tvg_scene_remove() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_insert(Tvg_Paint scene, Tvg_Paint target, Tvg_Paint at); + + +/** + * @brief Removes a paint object from the scene. + * + * This function removes a specified paint object from the scene. If no paint + * object is specified (i.e., the default @c nullptr is used), the function + * performs to clear all paints from the scene. + * + * @param[in] scene A Tvg_Paint pointer to the scene object. + * @param[in] paint A pointer to the Paint object to be removed from the scene. + * If @c nullptr, remove all the paints from the scene. + * + * @see tvg_scene_add() + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_remove(Tvg_Paint scene, Tvg_Paint paint); + + +/** + * @brief Clears all previously applied scene effects. + * + * This function clears all effects that have been applied to the scene, + * restoring it to its original state without any post-processing. + * + * @param[in] scene A pointer to the Tvg_Paint scene object. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_clear_effects(Tvg_Paint scene); + + +/** + * @brief Adds a Gaussian blur effect to the scene. + * + * This function adds a Gaussian blur filter to the scene as a post-processing effect. + * The blur can be applied in different directions with configurable border handling and quality settings. + * + * @param[in] scene A pointer to the Tvg_Paint scene object. + * @param[in] sigma The blur radius (sigma) value. Must be greater than 0. + * @param[in] direction Blur direction: 0 = both directions, 1 = horizontal only, 2 = vertical only. + * @param[in] border Border handling method: 0 = duplicate, 1 = wrap. + * @param[in] quality Blur quality level [0 - 100]. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_add_effect_gaussian_blur(Tvg_Paint scene, double sigma, int direction, int border, int quality); + + +/** + * @brief Adds a drop shadow effect to the scene. + * + * This function adds a drop shadow with a Gaussian blur to the scene. The shadow + * can be customized using color, opacity, angle, distance, blur radius (sigma), + * and quality parameters. + * + * @param[in] scene A pointer to the Tvg_Paint scene object. + * @param[in] r Red channel value of the shadow color [0 - 255]. + * @param[in] g Green channel value of the shadow color [0 - 255]. + * @param[in] b Blue channel value of the shadow color [0 - 255]. + * @param[in] a Alpha (opacity) channel value of the shadow [0 - 255]. + * @param[in] angle Shadow direction in degrees [0 - 360]. + * @param[in] distance Distance of the shadow from the original object. + * @param[in] sigma Gaussian blur sigma value for the shadow. Must be > 0. + * @param[in] quality Blur quality level [0 - 100]. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_add_effect_drop_shadow(Tvg_Paint scene, int r, int g, int b, int a, double angle, double distance, double sigma, int quality); + + +/** + * @brief Adds a fill color effect to the scene. + * + * This function overrides the scene's content colors with the specified fill color. + * + * @param[in] scene A pointer to the Tvg_Paint scene object. + * @param[in] r Red color channel value [0 - 255]. + * @param[in] g Green color channel value [0 - 255]. + * @param[in] b Blue color channel value [0 - 255]. + * @param[in] a Alpha (opacity) channel value [0 - 255]. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_add_effect_fill(Tvg_Paint scene, int r, int g, int b, int a); + + +/** + * @brief Adds a tint effect to the scene. + * + * This function tints the current scene using specified black and white color values, + * modulated by a given intensity. + * + * @param[in] scene A pointer to the Tvg_Paint scene object. + * @param[in] black_r Red component of the black color [0 - 255]. + * @param[in] black_g Green component of the black color [0 - 255]. + * @param[in] black_b Blue component of the black color [0 - 255]. + * @param[in] white_r Red component of the white color [0 - 255]. + * @param[in] white_g Green component of the white color [0 - 255]. + * @param[in] white_b Blue component of the white color [0 - 255]. + * @param[in] intensity Tint intensity value [0 - 100]. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_add_effect_tint(Tvg_Paint scene, int black_r, int black_g, int black_b, int white_r, int white_g, int white_b, double intensity); + + +/** + * @brief Adds a tritone color effect to the scene. + * + * This function adds a tritone color effect to the given scene using three sets of RGB values + * representing shadow, midtone, and highlight colors. + * + * @param[in] scene A pointer to the Tvg_Paint scene object. + * @param[in] shadow_r Red component of the shadow color [0 - 255]. + * @param[in] shadow_g Green component of the shadow color [0 - 255]. + * @param[in] shadow_b Blue component of the shadow color [0 - 255]. + * @param[in] midtone_r Red component of the midtone color [0 - 255]. + * @param[in] midtone_g Green component of the midtone color [0 - 255]. + * @param[in] midtone_b Blue component of the midtone color [0 - 255]. + * @param[in] highlight_r Red component of the highlight color [0 - 255]. + * @param[in] highlight_g Green component of the highlight color [0 - 255]. + * @param[in] highlight_b Blue component of the highlight color [0 - 255]. + * @param[in] blend A blending factor that determines the mix between the original color and the tritone colors [0 - 255]. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_scene_add_effect_tritone(Tvg_Paint scene, int shadow_r, int shadow_g, int shadow_b, int midtone_r, int midtone_g, int midtone_b, int highlight_r, int highlight_g, int highlight_b, int blend); + +/** \} */ // end defgroup ThorVGCapi_Scene + + +/** + * @defgroup ThorVGCapi_Text Text + * @brief A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text. + * + * @since 0.15 + * + * \{ + */ + +/************************************************************************/ +/* Text API */ +/************************************************************************/ + +/** + * @brief Creates a new Text object. + * + * This function allocates and returns a new Text instance. + * To properly destroy the Text object, use @ref tvg_paint_rel(). + * + * @return A pointer to the newly created Text object. + * + * @see tvg_paint_rel() + * + * @since 0.15 + */ +TVG_API Tvg_Paint tvg_text_new(void); + + +/** + * @brief Sets the font family for the text. + * + * This function specifies the name of the font to be used when rendering text. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] name The name of the font. This should match a font available through the canvas backend. + * If set to @c nullptr, ThorVG will attempt to select a fallback font available on the engine. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION The specified @p name cannot be found. + * + * @note This function only sets the font family name. Use @ref size() to define the font size. + * @note If the @p name is not specified, ThorVG will select an available fallback font. + * + * @see tvg_text_set_size() + * @see tvg_font_load() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_set_font(Tvg_Paint text, const char* name); + + +/** + * @brief Sets the font size for the text. + * + * This function sets the font size used during text rendering. + * The size is specified in point units, and supports floating-point precision + * for smooth scaling and animation effects. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] size The font size in points. Must be greater than 0.0. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument. + * @retval TVG_RESULT_INVALID_ARGUMENT if the @p size is less than or equal to 0. + * + * @note Use this function in combination with @ref font() to fully define text appearance. + * @note Fractional sizes (e.g., 12.5) are supported for sub-pixel rendering and animations. + * + * @see tvg_text_set_font() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_set_size(Tvg_Paint text, float size); + + +/** + * @brief Assigns the given unicode text to be rendered. + * + * This function sets the unicode text that will be displayed by the rendering system. + * The text is set according to the specified UTF encoding method, which defaults to UTF-8. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] utf8 The multi-byte text encoded with utf8 string to be rendered. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_set_text(Tvg_Paint text, const char* utf8); + + +/** + * @brief Sets text alignment or anchor per axis. + * + * If layout width/height is set on an axis, align within the layout box. + * Otherwise, treat it as an anchor within the text bounds which point of + * the text box is pinned to the paint position. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] x Horizontal alignment/anchor in [0..1]: 0=left/start, 0.5=center, 1=right/end. (Default is 0) + * @param[in] y Vertical alignment/anchor in [0..1]: 0=top, 0.5=middle, 1=bottom. (Default is 0) + * + * @since 1.0 + * + * @see tvg_text_layout() + */ +TVG_API Tvg_Result tvg_text_align(Tvg_Paint text, float x, float y); + + +/** + * @brief Sets the virtual layout box (constraints) for the text. + * + * If width/height is set on an axis, that axis is constrained by a virtual layout box and + * the text may wrap/align inside it. If width/height == 0, the axis is + * unconstrained and @ref tvg_text_align() acts as an anchor on that axis. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] w Layout width in user space. Use 0 for no horizontal constraint. (Default is 0) + * @param[in] h Layout height in user space. Use 0 for no vertical constraint. (Default is 0) + * + * @note This defines constraints only; alignment/anchoring is controlled by @ref align(). + * @since 1.0 + * + * @see tvg_text_align() + * @see tvg_text_spacing() + */ +TVG_API Tvg_Result tvg_text_layout(Tvg_Paint text, float w, float h); + +/** + * @brief Sets the text wrapping mode for this text object. + * + * This method controls how the text is laid out when it exceeds the available space. + * The wrapping mode determines whether text is truncated, wrapped by character or word, + * or adjusted automatically. An ellipsis mode is also available for truncation with "...". + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] mode The wrapping strategy to apply. Default is @c TVG_TEXT_WRAP_NONE. + * + * @see Tvg_Text_Wrap + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_wrap_mode(Tvg_Paint text, Tvg_Text_Wrap mode); + + +/** + * @brief Set the spacing scale factors for text layout. + * + * This function adjusts the letter spacing (horizontal space between glyphs) and + * line spacing (vertical space between lines of text) using scale factors. + * + * Both values are relative to the font's default metrics: + * - The letter spacing is applied as a scale factor to the glyph's advance width. + * - The line spacing is applied as a scale factor to the glyph's advance height. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] letter The scale factor for letter spacing. + * Values > 1.0 increase spacing, values < 1.0 decrease it. + * Must be greater than or equal to 0.0. (default: 1.0) + * + * @param[in] line The scale factor for line spacing. + * Values > 1.0 increase line spacing, values < 1.0 decrease it. + * Must be greater than or equal to 0.0. (default: 1.0) + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_spacing(Tvg_Paint text, float letter, float line); + + +/** + * @brief Apply an italic (slant) transformation to the text. + * + * This function applies a shear transformation to simulate an italic (oblique) style + * for the current text object. The shear factor determines the degree of slant + * applied along the X-axis. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] shear The shear factor to apply. A value of 0.0 applies no slant, while values around 0.5 result in a strong slant. + * Must be in the range [0.0, 0.5]. Recommended value is 0.18. + * + * @note The @p shear factor will be clamped to the valid range if it exceeds the limits. + * @note This does not require the font itself to be italic. + * It visually simulates the effect by applying a transformation matrix. + * + * @warning Excessive slanting may cause visual distortion depending on the font and size. + * + * @see tvg_text_set_font() + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_set_italic(Tvg_Paint text, float shear); + + +/** + * @brief Sets an outline (stroke) around the text object. + * + * This function adds an outline to the text with the specified width and RGB color. + * The outline enhances the visibility of the text by rendering a stroke around its glyphs. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param width The width of the outline. Must be positive value. (The default is 0) + * @param r Red component of the outline color (0–255). + * @param g Green component of the outline color (0–255). + * @param b Blue component of the outline color (0–255). + * + * @note To disable the outline, set @p width to 0. + * @see tvg_text_set_fill_color() to set the main text fill color. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_text_set_outline(Tvg_Paint text, float width, uint8_t r, uint8_t g, uint8_t b); + + +/** + * @brief Sets the text solid color. + * + * @param[in] paint A Tvg_Paint pointer to the text object. + * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. + * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * + * @see tvg_text_set_font() + * @see tvg_text_set_outline() + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_text_set_color(Tvg_Paint text, uint8_t r, uint8_t g, uint8_t b); + + +/** + * @brief Sets the gradient fill for the text. + * + * @param[in] text A Tvg_Paint pointer to the text object. + * @param[in] grad The linear or radial gradient fill + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument. + * @retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. + * + * @note Either a solid color or a gradient fill is applied, depending on what was set as last. + * @see tvg_text_set_font() + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_text_set_gradient(Tvg_Paint text, Tvg_Gradient gradient); + + +/** + * @brief Loads a scalable font data from a file. + * + * ThorVG efficiently caches the loaded data using the specified @p path as a key. + * This means that loading the same file again will not result in duplicate operations; + * instead, ThorVG will reuse the previously loaded font data. + * + * @param[in] path The path to the font file. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid @p path passed as an argument. + * @retval TVG_RESULT_NOT_SUPPORTED When trying to load a file with an unknown extension. + * + * @see tvg_font_unload() + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_font_load(const char* path); + + +/** + * @brief Loads a scalable font data from a memory block of a given size. + * + * ThorVG efficiently caches the loaded font data using the specified @p name as a key. + * This means that loading the same fonts again will not result in duplicate operations. + * Instead, ThorVG will reuse the previously loaded font data. + * + * @param[in] name The name under which the font will be stored and accessible (e.x. in a @p tvg_text_set_font API). + * @param[in] data A pointer to a memory location where the content of the font data is stored. + * @param[in] size The size in bytes of the memory occupied by the @p data. + * @param[in] mimetype Mimetype or extension of font data. In case a @c nullptr or an empty "" value is provided the loader will be determined automatically. + * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not (default). + * + * @retval TVG_RESULT_INVALID_ARGUMENT If no name is provided or if @p size is zero while @p data points to a valid memory location. + * @retval TVG_RESULT_NOT_SUPPORTED When trying to load a file with an unknown extension. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION When trying to unload the font data that has not been previously loaded. + * + * @warning: It's the user responsibility to release the @p data memory. + * + * @note To unload the font data loaded using this API, pass the proper @p name and @c nullptr as @p data. + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32_t size, const char *mimetype, bool copy); + + +/** + * @brief Unloads the specified scalable font data that was previously loaded. + * + * This function is used to release resources associated with a font file that has been loaded into memory. + * + * @param[in] path The path to the loaded font file. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION The loader is not initialized. + * + * @note If the font data is currently in use, it will not be immediately unloaded. + * @see tvg_font_load() + * + * @since 0.15 + */ +TVG_API Tvg_Result tvg_font_unload(const char* path); + + +/** \} */ // end defgroup ThorVGCapi_Text + + +/** + * @defgroup ThorVGCapi_Saver Saver + * @brief A module for exporting a paint object into a specified file. + * + * The module enables to save the composed scene and/or image from a paint object. + * Once it's successfully exported to a file, it can be recreated using the Picture module. + * + * \{ + */ + +/************************************************************************/ +/* Saver API */ +/************************************************************************/ +/** + * @brief Creates a new Tvg_Saver object. + * + * @return A new Tvg_Saver object. + */ +TVG_API Tvg_Saver tvg_saver_new(void); + + +/** + * @brief Exports the given @p paint data to the given @p path + * + * If the saver module supports any compression mechanism, it will optimize the data size. + * This might affect the encoding/decoding time in some cases. You can turn off the compression + * if you wish to optimize for speed. + * + * @param[in] saver The Tvg_Saver object connected with the saving task. + * @param[in] paint The paint to be saved with all its associated properties. + * @param[in] path A path to the file, in which the paint data is to be saved. + * @param[in] quality The encoded quality level. @c 0 is the minimum, @c 100 is the maximum value(recommended). + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION Currently saving other resources. + * @retval TVG_RESULT_NOT_SUPPORTED Trying to save a file with an unknown extension or in an unsupported format. + * @retval TVG_RESULT_UNKNOWN An empty paint is to be saved. + * + * @note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call tvg_saver_sync() afterwards. + * @see tvg_saver_sync() + */ +TVG_API Tvg_Result tvg_saver_save_paint(Tvg_Saver saver, Tvg_Paint paint, const char* path, uint32_t quality); + + +/** + * @brief Exports the given @p animation data to the given @p path + * + * If the saver module supports any compression mechanism, it will optimize the data size. + * This might affect the encoding/decoding time in some cases. You can turn off the compression + * if you wish to optimize for speed. + * + * @param[in] saver The Tvg_Saver object connected with the saving task. + * @param[in] animation The animation to be saved with all its associated properties. + * @param[in] path A path to the file, in which the animation data is to be saved. + * @param[in] quality The encoded quality level. @c 0 is the minimum, @c 100 is the maximum value(recommended). + * @param[in] fps The frames per second for the animation. If @c 0, the default fps is used. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION Currently saving other resources or animation has no frames. + * @retval TVG_RESULT_NOT_SUPPORTED Trying to save a file with an unknown extension or in an unsupported format. + * @retval TVG_RESULT_UNKNOWN Unknown if attempting to save an empty paint. + * + * @note A higher frames per second (FPS) would result in a larger file size. It is recommended to use the default value. + * @note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call tvg_saver_sync() afterwards. + * + * @see tvg_saver_sync() + * + * @since 1.0 +*/ +TVG_API Tvg_Result tvg_saver_save_animation(Tvg_Saver saver, Tvg_Animation animation, const char* path, uint32_t quality, uint32_t fps); + + +/** + * @brief Guarantees that the saving task is finished. + * + * The behavior of the Saver module works on a sync/async basis, depending on the threading setting of the Initializer. + * Thus, if you wish to have a benefit of it, you must call tvg_saver_sync() after the tvg_saver_save_paint() in the proper delayed time. + * Otherwise, you can call tvg_saver_sync() immediately. + * + * @param[in] saver The Tvg_Saver object connected with the saving task. + * + * @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION No saving task is running. + * + * @note The asynchronous tasking is dependent on the Saver module implementation. + * @see tvg_saver_save_paint() + */ +TVG_API Tvg_Result tvg_saver_sync(Tvg_Saver saver); + + +/** + * @brief Deletes the given Tvg_Saver object. + * + * @param[in] saver The Tvg_Saver object to be deleted. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Saver pointer. + */ +TVG_API Tvg_Result tvg_saver_del(Tvg_Saver saver); + + +/** \} */ // end defgroup ThorVGCapi_Saver + + +/** + * @defgroup ThorVGCapi_Animation Animation + * @brief A module for manipulation of animatable images. + * + * The module supports the display and control of animation frames. + * + * \{ + */ + +/************************************************************************/ +/* Animation API */ +/************************************************************************/ + +/** + * @brief Creates a new Animation object. + * + * @return Tvg_Animation A new Tvg_Animation object. + * + * @since 0.13 + */ +TVG_API Tvg_Animation tvg_animation_new(void); + + +/** + * @brief Specifies the current frame in the animation. + * + * @param[in] animation A Tvg_Animation pointer to the animation object. + * @param[in] no The index of the animation frame to be displayed. The index should be less than the tvg_animation_get_total_frame(). + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION if the given @p no is the same as the current frame value. + * @retval TVG_RESULT_NOT_SUPPORTED The picture data does not support animations. + * + * @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value + * is less than 0.001. In such cases, it returns @c Result::InsufficientCondition. + * Values less than 0.001 may be disregarded and may not be accurately retained by the Animation. + * @see tvg_animation_get_total_frame() + * + * @since 0.13 +*/ +TVG_API Tvg_Result tvg_animation_set_frame(Tvg_Animation animation, float no); + + +/** + * @brief Retrieves a picture instance associated with this animation instance. + * + * This function provides access to the picture instance that can be used to load animation formats, such as lot. + * After setting up the picture, it can be added to the designated canvas, enabling control over animation frames + * with this Animation instance. + * + * @param[in] animation A Tvg_Animation pointer to the animation object. + * + * @return A picture instance that is tied to this animation. + * + * @warning The picture instance is owned by Animation. It should not be deleted manually. + * + * @since 0.13 + */ +TVG_API Tvg_Paint tvg_animation_get_picture(Tvg_Animation animation); + + +/** + * @brief Retrieves the current frame number of the animation. + * + * @param[in] animation A Tvg_Animation pointer to the animation object. + * @param[in] no The current frame number of the animation, between 0 and totalFrame() - 1. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer or @p no + * + * @see tvg_animation_get_total_frame() + * @see tvg_animation_set_frame() + * + * @since 0.13 + */ +TVG_API Tvg_Result tvg_animation_get_frame(Tvg_Animation animation, float* no); + + +/** + * @brief Retrieves the total number of frames in the animation. + * + * @param[in] animation A Tvg_Animation pointer to the animation object. + * @param[in] cnt The total number of frames in the animation. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer or @p cnt. + * + * @note Frame numbering starts from 0. + * @note If the Picture is not properly configured, this function will return 0. + * + * @since 0.13 + */ +TVG_API Tvg_Result tvg_animation_get_total_frame(Tvg_Animation animation, float* cnt); + + +/** + * @brief Retrieves the duration of the animation in seconds. + * + * @param[in] animation A Tvg_Animation pointer to the animation object. + * @param[in] duration The duration of the animation in seconds. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer or @p duration. + * + * @note If the Picture is not properly configured, this function will return 0. + * + * @since 0.13 + */ +TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation animation, float* duration); + + +/** + * @brief Specifies the playback segment of the animation. + * + * The set segment is designated as the play area of the animation. + * This is useful for playing a specific segment within the entire animation. + * After setting, the number of animation frames and the playback time are calculated + * by mapping the playback segment as the entire range. + * + * @param[in] animation The Tvg_Animation pointer to the animation object. + * @param[in] begin segment begin frame. + * @param[in] end segment end frame. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. + * @retval TVG_RESULT_INVALID_ARGUMENT If the @p begin is higher than @p end. + * + * @note Animation allows a range from 0.0 to the total frame. @p end should not be higher than @p begin. + * @note If a marker has been specified, its range will be disregarded. + * + * @see tvg_lottie_animation_set_marker() + * @see tvg_animation_get_total_frame() + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation animation, float begin, float end); + + +/** + * @brief Gets the current segment range information. + * + * @param[in] animation The Tvg_Animation pointer to the animation object. + * @param[out] begin segment begin frame. + * @param[out] end segment end frame. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_animation_get_segment(Tvg_Animation animation, float* begin, float* end); + + +/** + * @brief Deletes the given Tvg_Animation object. + * + * @param[in] animation The Tvg_Animation object to be deleted. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer. + * + * @since 0.13 + */ +TVG_API Tvg_Result tvg_animation_del(Tvg_Animation animation); + + +/** \} */ // end defgroup ThorVGCapi_Animation + + +/** + * @defgroup ThorVGCapi_Accesssor Accessor + * @brief A module for manipulation of the scene tree + * + * This module helps to control the scene tree. + * \{ + */ + +/************************************************************************/ +/* Accessor API */ +/************************************************************************/ +/** + * @brief Creates a new accessor object. + * + * @return A new accessor object. + * + * @since 1.0 + */ +TVG_API Tvg_Accessor tvg_accessor_new(void); + + +/** + * @brief Deletes the given accessor object. + * + * @param[in] accessor The accessor object to be deleted. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Accessor pointer. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_accessor_del(Tvg_Accessor accessor); + + +/** + * @brief Sets the paint of the accessor then iterates through its descendents. + * + * Iterates through all descendents of the scene passed through the paint argument + * while calling func on each and passing the data pointer to this function. When + * func returns false iteration stops and the function returns. + * + * @param[in] accessor A Tvg_Accessor pointer to the accessor object. + * @param[in] paint A Tvg_Paint pointer to the scene object. + * @param[in] func A function pointer to the function that will be execute for each child. + * @param[in] data A void pointer to data that will be passed to the func. + * + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Accessor, Tvg_Paint, or function pointer. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_accessor_set(Tvg_Accessor accessor, Tvg_Paint paint, bool (*func)(Tvg_Paint paint, void* data), void* data); + + +/** + * @brief Generate a unique ID (hash key) from a given name. + * + * This function computes a unique identifier value based on the provided string. + * You can use this to assign a unique ID to the Paint object. + * + * @param[in] name The input string to generate the unique identifier from. + * + * @return The generated unique identifier value. + * + * @since 1.0 + */ +TVG_API uint32_t tvg_accessor_generate_id(const char* name); + + +/** \} */ // end defgroup ThorVGCapi_Accessor + + +/** + * @defgroup ThorVGCapi_LottieAnimation LottieAnimation + * @brief A module for manipulation of lottie extension features. + * + * The module enables control of advanced Lottie features. + * \{ + */ + +/************************************************************************/ +/* LottieAnimation Extension API */ +/************************************************************************/ + +/** + * @brief Creates a new LottieAnimation object. + * + * @return Tvg_Animation A new Tvg_LottieAnimation object. + * + * @since 0.15 + */ +TVG_API Tvg_Animation tvg_lottie_animation_new(void); + + +/** + * @brief Generates a new slot from the given slot data. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] slot The Lottie slot data in JSON format. + * + * @return The generated slot ID when successful, 0 otherwise. + * + * @since 1.0 + */ +TVG_API uint32_t tvg_lottie_animation_gen_slot(Tvg_Animation animation, const char* slot); + + +/** + * @brief Applies a previously generated slot to the animation. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] id The ID of the slot to apply, or 0 to reset all slots. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. + * @retval TVG_RESULT_INVALID_ARGUMENT When the given @p id is invalid + * @retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_apply_slot(Tvg_Animation animation, uint32_t id); + + +/** + * @brief Deletes a previously generated slot. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] id The ID of the slot to delete. + * + * @return Tvg_Result enumeration. + * @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded or the slot ID is invalid. + * @retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. + * + * @note This function should be paired with gen. + * @see tvg_lottie_animation_gen_slot() + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_del_slot(Tvg_Animation animation, uint32_t id); + + +/** + * @brief Specifies a segment by marker. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] marker The name of the segment marker. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. + * @retval TVG_RESULT_INVALID_ARGUMENT When the given @p marker is invalid. + * @retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_set_marker(Tvg_Animation animation, const char* marker); + + +/** + * @brief Gets the marker count of the animation. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[out] cnt The count value of the markers. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_get_markers_cnt(Tvg_Animation animation, uint32_t* cnt); + + +/** + * @brief Gets the marker name by a given index. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] idx The index of the animation marker, starts from 0. + * @param[out] name The name of marker when succeed. + * + * @retval TVG_RESULT_INVALID_ARGUMENT In case @c nullptr is passed as the argument or @c idx is out of range. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_get_marker(Tvg_Animation animation, uint32_t idx, const char** name); + + +/** + * @brief Interpolates between two frames over a specified duration. + * + * This method performs tweening, a process of generating intermediate frame + * between @p from and @p to based on the given @p progress. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] from The start frame number of the interpolation. + * @param[in] to The end frame number of the interpolation. + * @param[in] progress The current progress of the interpolation (range: 0.0 to 1.0). + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_tween(Tvg_Animation animation, float from, float to, float progress); + + +/** + * @brief Updates the value of an expression variable for a specific layer. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] layer The name of the layer containing the variable to be updated. + * @param[in] ix The property index of the variable within the layer. + * @param[in] var The name of the variable to be updated. + * @param[in] val The new value to assign to the variable. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If the animation is not loaded. + * @retval TVG_RESULT_INVALID_ARGUMENT When the given parameter is invalid. + * @retval TVG_RESULT_NOT_SUPPORTED When neither the layer nor the property is found in the current animation. + * + * @note Experimental API + */ +TVG_API Tvg_Result tvg_lottie_animation_assign(Tvg_Animation animation, const char* layer, uint32_t ix, const char* var, float val); + + +/** + * @brief Sets the quality level for Lottie effects. + * + * This function controls the rendering quality of effects like blur, shadows, etc. + * Lower values prioritize performance while higher values prioritize quality. + * + * @param[in] animation The Tvg_Animation pointer to the Lottie animation object. + * @param[in] value The quality level (0-100). 0 represents lowest quality/best performance, + * 100 represents highest quality/lowest performance, default is 50. + * + * @retval TVG_RESULT_INSUFFICIENT_CONDITION If the animation is not loaded. + * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer. + * + * @note This option is used as a hint; its behavior heavily depends on the render backend. + * + * @since 1.0 + */ +TVG_API Tvg_Result tvg_lottie_animation_set_quality(Tvg_Animation animation, uint8_t value); + +/** \} */ // end addtogroup ThorVGCapi_LottieAnimation + + +/** \} */ // end defgroup ThorVGCapi + + +#ifdef __cplusplus +} +#endif + +#endif //_THORVG_CAPI_H_ diff --git a/components/thorvg-main/src/bindings/capi/tvgCapi.cpp b/components/thorvg-main/src/bindings/capi/tvgCapi.cpp new file mode 100644 index 0000000..ce53ec4 --- /dev/null +++ b/components/thorvg-main/src/bindings/capi/tvgCapi.cpp @@ -0,0 +1,1235 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "config.h" +#include +#include +#include "thorvg_capi.h" +#ifdef THORVG_LOTTIE_LOADER_SUPPORT +#include +#endif + +using namespace std; +using namespace tvg; + +#ifdef __cplusplus +extern "C" { +#endif + + +/************************************************************************/ +/* Engine API */ +/************************************************************************/ + +TVG_API Tvg_Result tvg_engine_init(unsigned threads) +{ + return (Tvg_Result) Initializer::init(threads); +} + + +TVG_API Tvg_Result tvg_engine_term() +{ + return (Tvg_Result) Initializer::term(); +} + + +TVG_API Tvg_Result tvg_engine_version(uint32_t* major, uint32_t* minor, uint32_t* micro, const char** version) +{ + if (version) *version = Initializer::version(major, minor, micro); + return TVG_RESULT_SUCCESS; +} + +/************************************************************************/ +/* Canvas API */ +/************************************************************************/ + +TVG_API Tvg_Canvas tvg_swcanvas_create(Tvg_Engine_Option op) +{ + return (Tvg_Canvas) SwCanvas::gen(static_cast(op)); +} + + +TVG_API Tvg_Canvas tvg_glcanvas_create(Tvg_Engine_Option op) +{ + return (Tvg_Canvas) GlCanvas::gen(static_cast(op)); +} + + +TVG_API Tvg_Canvas tvg_wgcanvas_create(Tvg_Engine_Option op) +{ + return (Tvg_Canvas) WgCanvas::gen(static_cast(op)); +} + + +TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas canvas) +{ + if (canvas) { + delete(reinterpret_cast(canvas)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Tvg_Colorspace cs) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->target(buffer, stride, w, h, static_cast(cs)); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas canvas, void* display, void* surface, void* context, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->target(display, surface, context, id, w, h, static_cast(cs)); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_wgcanvas_set_target(Tvg_Canvas canvas, void* device, void* instance, void* target, uint32_t w, uint32_t h, Tvg_Colorspace cs, int type) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->target(device, instance, target, w, h, static_cast(cs), type); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_add(Tvg_Canvas canvas, Tvg_Paint paint) +{ + if (canvas && paint) return (Tvg_Result) reinterpret_cast(canvas)->add((Paint*)paint); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_insert(Tvg_Canvas canvas, Tvg_Paint target, Tvg_Paint at) +{ + if (canvas && target && at) return (Tvg_Result) reinterpret_cast(canvas)->add((Paint*)target, (Paint*) at); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_remove(Tvg_Canvas canvas, Tvg_Paint paint) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->remove((Paint*) paint); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_update(Tvg_Canvas canvas) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->update(); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_draw(Tvg_Canvas canvas, bool clear) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->draw(clear); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_sync(Tvg_Canvas canvas) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->sync(); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas canvas, int32_t x, int32_t y, int32_t w, int32_t h) +{ + if (canvas) return (Tvg_Result) reinterpret_cast(canvas)->viewport(x, y, w, h); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Paint API */ +/************************************************************************/ + +TVG_API Tvg_Paint tvg_paint_get_parent(const Tvg_Paint paint) +{ + return (Tvg_Paint) reinterpret_cast(paint)->parent(); +} + + +TVG_API Tvg_Result tvg_paint_rel(Tvg_Paint paint) +{ + Paint::rel(reinterpret_cast(paint)); + return TVG_RESULT_SUCCESS; +} + + +TVG_API Tvg_Result tvg_paint_set_visible(Tvg_Paint paint, bool visible) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->visible(visible); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API bool tvg_paint_get_visible(const Tvg_Paint paint) +{ + if (paint) return reinterpret_cast(paint)->visible(); + return false; +} + + +TVG_API uint16_t tvg_paint_ref(Tvg_Paint paint) +{ + if (paint) return reinterpret_cast(paint)->ref(); + return 0; +} + + +TVG_API uint16_t tvg_paint_unref(Tvg_Paint paint, bool free) +{ + if (paint) return reinterpret_cast(paint)->unref(free); + return 0; +} + + +TVG_API uint16_t tvg_paint_get_ref(const Tvg_Paint paint) +{ + if (paint) return reinterpret_cast(paint)->refCnt(); + return 0; +} + + +TVG_API Tvg_Result tvg_paint_scale(Tvg_Paint paint, float factor) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->scale(factor); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_rotate(Tvg_Paint paint, float degree) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->rotate(degree); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_translate(Tvg_Paint paint, float x, float y) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->translate(x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_set_transform(Tvg_Paint paint, const Tvg_Matrix* m) +{ + if (paint && m) return (Tvg_Result) reinterpret_cast(paint)->transform(*(reinterpret_cast(m))); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_get_transform(Tvg_Paint paint, Tvg_Matrix* m) +{ + if (paint && m) { + *reinterpret_cast(m) = reinterpret_cast(paint)->transform(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Paint tvg_paint_duplicate(Tvg_Paint paint) +{ + if (paint) return (Tvg_Paint) reinterpret_cast(paint)->duplicate(); + return nullptr; +} + + +TVG_API bool tvg_paint_intersects(Tvg_Paint paint, int32_t x, int32_t y, int32_t w, int32_t h) +{ + if (paint) return reinterpret_cast(paint)->intersects(x, y, w, h); + return false; +} + + +TVG_API Tvg_Result tvg_paint_set_opacity(Tvg_Paint paint, uint8_t opacity) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->opacity(opacity); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_get_opacity(const Tvg_Paint paint, uint8_t* opacity) +{ + if (paint && opacity) { + *opacity = reinterpret_cast(paint)->opacity(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_get_aabb(Tvg_Paint paint, float* x, float* y, float* w, float* h) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->bounds(x, y, w, h); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_get_obb(Tvg_Paint paint, Tvg_Point* pt4) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->bounds((Point*)pt4); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_set_mask_method(Tvg_Paint paint, Tvg_Paint target, Tvg_Mask_Method method) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->mask((Paint*)target, (MaskMethod)method); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_get_mask_method(const Tvg_Paint paint, const Tvg_Paint target, Tvg_Mask_Method* method) +{ + if (paint && target && method) { + *reinterpret_cast(method) = reinterpret_cast(paint)->mask(reinterpret_cast(target)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_set_blend_method(Tvg_Paint paint, Tvg_Blend_Method method) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->blend((BlendMethod)method); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_get_type(const Tvg_Paint paint, Tvg_Type* type) +{ + if (paint && type) { + *type = static_cast(reinterpret_cast(paint)->type()); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_paint_set_clip(Tvg_Paint paint, Tvg_Paint clipper) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->clip((Shape*)(clipper)); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Paint tvg_paint_get_clip(const Tvg_Paint paint) +{ + if (paint) return (Tvg_Paint) reinterpret_cast(paint)->clip(); + return nullptr; +} + + +/************************************************************************/ +/* Shape API */ +/************************************************************************/ + +TVG_API Tvg_Paint tvg_shape_new() +{ + return (Tvg_Paint) Shape::gen(); +} + + +TVG_API Tvg_Result tvg_shape_reset(Tvg_Paint paint) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->reset(); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_move_to(Tvg_Paint paint, float x, float y) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->moveTo(x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_line_to(Tvg_Paint paint, float x, float y) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->lineTo(x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_cubic_to(Tvg_Paint paint, float cx1, float cy1, float cx2, float cy2, float x, float y) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->cubicTo(cx1, cy1, cx2, cy2, x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_close(Tvg_Paint paint) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->close(); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_append_rect(Tvg_Paint paint, float x, float y, float w, float h, float rx, float ry, bool cw) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->appendRect(x, y, w, h, rx, ry, cw); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint paint, float cx, float cy, float rx, float ry, bool cw) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->appendCircle(cx, cy, rx, ry, cw); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_append_path(Tvg_Paint paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->appendPath((const PathCommand*)cmds, cmdCnt, (const Point*)pts, ptsCnt); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_path(const Tvg_Paint paint, const Tvg_Path_Command** cmds, uint32_t* cmdsCnt, const Tvg_Point** pts, uint32_t* ptsCnt) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->path((const PathCommand**)cmds, cmdsCnt, (const Point**)pts, ptsCnt); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint paint, float width) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeWidth(width); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint paint, float* width) +{ + if (paint && width) { + *width = reinterpret_cast(paint)->strokeWidth(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeFill(r, g, b, a); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeFill(r, g, b, a); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_gradient(Tvg_Paint paint, Tvg_Gradient gradient) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeFill((Fill*)(gradient)); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint paint, Tvg_Gradient* gradient) +{ + if (paint && gradient) { + *gradient = (Tvg_Gradient)(reinterpret_cast(paint)->strokeFill()); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint paint, const float* dashPattern, uint32_t cnt, float offset) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeDash(dashPattern, cnt, offset); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint paint, const float** dashPattern, uint32_t* cnt, float* offset) +{ + if (paint) { + *cnt = reinterpret_cast(paint)->strokeDash(dashPattern, offset); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint paint, Tvg_Stroke_Cap cap) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeCap((StrokeCap)cap); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint paint, Tvg_Stroke_Cap* cap) +{ + if (paint && cap) { + *cap = (Tvg_Stroke_Cap) reinterpret_cast(paint)->strokeCap(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint paint, Tvg_Stroke_Join join) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeJoin((StrokeJoin)join); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint paint, Tvg_Stroke_Join* join) +{ + if (paint && join) { + *join = (Tvg_Stroke_Join) reinterpret_cast(paint)->strokeJoin(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_stroke_miterlimit(Tvg_Paint paint, float ml) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->strokeMiterlimit(ml); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint paint, float* ml) +{ + if (paint && ml) { + *ml = reinterpret_cast(paint)->strokeMiterlimit(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_trimpath(Tvg_Paint paint, float begin, float end, bool simultaneous) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->trimpath(begin, end, simultaneous); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_fill_color(Tvg_Paint paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->fill(r, g, b, a); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->fill(r, g, b, a); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint paint, Tvg_Fill_Rule rule) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->fillRule((FillRule)rule); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint paint, Tvg_Fill_Rule* rule) +{ + if (paint && rule) { + *rule = (Tvg_Fill_Rule) reinterpret_cast(paint)->fillRule(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_paint_order(Tvg_Paint paint, bool strokeFirst) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->order(strokeFirst); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_set_gradient(Tvg_Paint paint, Tvg_Gradient gradient) +{ + if (paint) return (Tvg_Result) reinterpret_cast(paint)->fill((Fill*)gradient); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_shape_get_gradient(const Tvg_Paint paint, Tvg_Gradient* gradient) +{ + if (paint && gradient) { + *gradient = (Tvg_Gradient)(reinterpret_cast(paint)->fill()); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Picture API */ +/************************************************************************/ + +TVG_API Tvg_Paint tvg_picture_new() +{ + return (Tvg_Paint) Picture::gen(); +} + + +TVG_API Tvg_Result tvg_picture_load(Tvg_Paint picture, const char* path) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->load(path); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint picture, const uint32_t *data, uint32_t w, uint32_t h, Tvg_Colorspace cs, bool copy) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->load(data, w, h, static_cast(cs), copy); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_picture_load_data(Tvg_Paint picture, const char *data, uint32_t size, const char *mimetype, const char* rpath, bool copy) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->load(data, size, mimetype ? mimetype : "", rpath ? rpath : "", copy); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_picture_set_asset_resolver(Tvg_Paint picture, Tvg_Picture_Asset_Resolver resolver, void* data) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->resolver([resolver](Paint* paint, const char* src, void* data) -> bool { + return resolver(reinterpret_cast(paint), src, data); + }, data); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_picture_set_size(Tvg_Paint picture, float w, float h) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->size(w, h); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_picture_get_size(const Tvg_Paint picture, float* w, float* h) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->size(w, h); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API const Tvg_Paint tvg_picture_get_paint(Tvg_Paint picture, uint32_t id) +{ + if (picture) return (Tvg_Paint) reinterpret_cast(picture)->paint(id); + return nullptr; +} + + +TVG_API Tvg_Result tvg_picture_set_origin(Tvg_Paint picture, float x, float y) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->origin(x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_picture_get_origin(const Tvg_Paint picture, float* x, float* y) +{ + if (picture) return (Tvg_Result) reinterpret_cast(picture)->origin(x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Gradient API */ +/************************************************************************/ + +TVG_API Tvg_Gradient tvg_linear_gradient_new() +{ + return (Tvg_Gradient)LinearGradient::gen(); +} + + +TVG_API Tvg_Gradient tvg_radial_gradient_new() +{ + return (Tvg_Gradient)RadialGradient::gen(); +} + + +TVG_API Tvg_Gradient tvg_gradient_duplicate(Tvg_Gradient grad) +{ + if (grad) return (Tvg_Gradient) reinterpret_cast(grad)->duplicate(); + return nullptr; +} + + +TVG_API Tvg_Result tvg_gradient_del(Tvg_Gradient grad) +{ + if (grad) { + delete(reinterpret_cast(grad)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_linear_gradient_set(Tvg_Gradient grad, float x1, float y1, float x2, float y2) +{ + if (grad) return (Tvg_Result) reinterpret_cast(grad)->linear(x1, y1, x2, y2); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_linear_gradient_get(Tvg_Gradient grad, float* x1, float* y1, float* x2, float* y2) +{ + if (grad) return (Tvg_Result) reinterpret_cast(grad)->linear(x1, y1, x2, y2); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_radial_gradient_set(Tvg_Gradient grad, float cx, float cy, float r, float fx, float fy, float fr) +{ + if (grad) return (Tvg_Result) reinterpret_cast(grad)->radial(cx, cy, r, fx, fy, fr); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_radial_gradient_get(Tvg_Gradient grad, float* cx, float* cy, float* r, float* fx, float* fy, float* fr) +{ + if (grad) return (Tvg_Result) reinterpret_cast(grad)->radial(cx, cy, r, fx, fy, fr); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient grad, const Tvg_Color_Stop* color_stop, uint32_t cnt) +{ + if (grad) return (Tvg_Result) reinterpret_cast(grad)->colorStops(reinterpret_cast(color_stop), cnt); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_get_color_stops(const Tvg_Gradient grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt) +{ + if (grad && color_stop && cnt) { + *cnt = reinterpret_cast(grad)->colorStops(reinterpret_cast(color_stop)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_set_spread(Tvg_Gradient grad, const Tvg_Stroke_Fill spread) +{ + if (grad) return (Tvg_Result) reinterpret_cast(grad)->spread((FillSpread)spread); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_get_spread(const Tvg_Gradient grad, Tvg_Stroke_Fill* spread) +{ + if (grad && spread) { + *spread = (Tvg_Stroke_Fill) reinterpret_cast(grad)->spread(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_set_transform(Tvg_Gradient grad, const Tvg_Matrix* m) +{ + if (grad && m) return (Tvg_Result) reinterpret_cast(grad)->transform(*(reinterpret_cast(m))); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_get_transform(const Tvg_Gradient grad, Tvg_Matrix* m) +{ + if (grad && m) { + *reinterpret_cast(m) = reinterpret_cast(const_cast(grad))->transform(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_gradient_get_type(const Tvg_Gradient grad, Tvg_Type* type) +{ + if (grad && type) { + *type = static_cast(reinterpret_cast(grad)->type()); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Scene API */ +/************************************************************************/ + +TVG_API Tvg_Paint tvg_scene_new() +{ + return (Tvg_Paint) Scene::gen(); +} + + +TVG_API Tvg_Result tvg_scene_add(Tvg_Paint scene, Tvg_Paint paint) +{ + if (scene && paint) return (Tvg_Result) reinterpret_cast(scene)->add((Paint*)paint); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_insert(Tvg_Paint scene, Tvg_Paint paint, Tvg_Paint at) +{ + if (scene && paint && at) return (Tvg_Result) reinterpret_cast(scene)->add((Paint*)paint, (Paint*)at); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_remove(Tvg_Paint scene, Tvg_Paint paint) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->remove((Paint*)paint); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_clear_effects(Tvg_Paint scene) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->add(SceneEffect::Clear); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_add_effect_drop_shadow(Tvg_Paint scene, int r, int g, int b, int a, double angle, double distance, double sigma, int quality) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->add(SceneEffect::DropShadow, r, g, b, a, angle, distance, sigma, quality); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_add_effect_gaussian_blur(Tvg_Paint scene, double sigma, int direction, int border, int quality) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->add(SceneEffect::GaussianBlur, sigma, direction, border, quality); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_add_effect_fill(Tvg_Paint scene, int r, int g, int b, int a) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->add(SceneEffect::Fill, r, g, b, a); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_add_effect_tint(Tvg_Paint scene, int black_r, int black_g, int black_b, int white_r, int white_g, int white_b, double intensity) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->add(SceneEffect::Tint, black_r, black_g, black_b, white_r, white_g, white_b, intensity); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_scene_add_effect_tritone(Tvg_Paint scene, int shadow_r, int shadow_g, int shadow_b, int midtone_r, int midtone_g, int midtone_b, int highlight_r, int highlight_g, int highlight_b, int blend) +{ + if (scene) return (Tvg_Result) reinterpret_cast(scene)->add(SceneEffect::Tritone, shadow_r, shadow_g, shadow_b, midtone_r, midtone_g, midtone_b, highlight_r, highlight_g, highlight_b, blend); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Text API */ +/************************************************************************/ + +TVG_API Tvg_Paint tvg_text_new() +{ + return (Tvg_Paint)Text::gen(); +} + + +TVG_API Tvg_Result tvg_text_set_font(Tvg_Paint text, const char* name) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->font(name); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_set_size(Tvg_Paint text, float size) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->size(size); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_set_text(Tvg_Paint text, const char* utf8) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->text(utf8); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_align(Tvg_Paint text, float x, float y) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->align(x, y); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_layout(Tvg_Paint text, float w, float h) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->layout(w, h); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_set_outline(Tvg_Paint text, float width, uint8_t r, uint8_t g, uint8_t b) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->outline(width, r, g, b); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_set_color(Tvg_Paint text, uint8_t r, uint8_t g, uint8_t b) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->fill(r, g, b); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_set_italic(Tvg_Paint text, float shear) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->italic(shear); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_set_gradient(Tvg_Paint text, Tvg_Gradient gradient) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->fill((Fill*)(gradient)); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_wrap_mode(Tvg_Paint text, Tvg_Text_Wrap mode) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->wrap(TextWrap(mode)); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_text_spacing(Tvg_Paint text, float letter, float line) +{ + if (text) return (Tvg_Result) reinterpret_cast(text)->spacing(letter, line); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_font_load(const char* path) +{ + return (Tvg_Result) Text::load(path); +} + + +TVG_API Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32_t size, const char *mimetype, bool copy) +{ + return (Tvg_Result) Text::load(name, data, size, mimetype ? mimetype : "", copy); +} + + +TVG_API Tvg_Result tvg_font_unload(const char* path) +{ + return (Tvg_Result) Text::unload(path); +} + + +/************************************************************************/ +/* Saver API */ +/************************************************************************/ + +TVG_API Tvg_Saver tvg_saver_new() +{ + return (Tvg_Saver) Saver::gen(); +} + + +TVG_API Tvg_Result tvg_saver_save_paint(Tvg_Saver saver, Tvg_Paint paint, const char* path, uint32_t quality) +{ + if (saver) return (Tvg_Result) reinterpret_cast(saver)->save((Paint*)paint, path, quality); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_saver_save_animation(Tvg_Saver saver, Tvg_Animation animation, const char* path, uint32_t quality, uint32_t fps) +{ + if (saver) return (Tvg_Result) reinterpret_cast(saver)->save((Animation*)animation, path, quality, fps); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_saver_sync(Tvg_Saver saver) +{ + if (saver) return (Tvg_Result) reinterpret_cast(saver)->sync(); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_saver_del(Tvg_Saver saver) +{ + if (saver) { + delete(reinterpret_cast(saver)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Animation API */ +/************************************************************************/ + +TVG_API Tvg_Animation tvg_animation_new() +{ + return (Tvg_Animation) Animation::gen(); +} + + +TVG_API Tvg_Result tvg_animation_set_frame(Tvg_Animation animation, float no) +{ + if (animation) return (Tvg_Result) reinterpret_cast(animation)->frame(no); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_animation_get_frame(Tvg_Animation animation, float* no) +{ + if (animation && no) { + *no = reinterpret_cast(animation)->curFrame(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_animation_get_total_frame(Tvg_Animation animation, float* cnt) +{ + if (animation && cnt) { + *cnt = reinterpret_cast(animation)->totalFrame(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Paint tvg_animation_get_picture(Tvg_Animation animation) +{ + if (animation) return (Tvg_Paint) reinterpret_cast(animation)->picture(); + return nullptr; +} + + +TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation animation, float* duration) +{ + if (animation && duration) { + *duration = reinterpret_cast(animation)->duration(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation animation, float start, float end) +{ + if (animation) return (Tvg_Result) reinterpret_cast(animation)->segment(start, end); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_animation_get_segment(Tvg_Animation animation, float* start, float* end) +{ + if (animation) return (Tvg_Result) reinterpret_cast(animation)->segment(start, end); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_animation_del(Tvg_Animation animation) +{ + if (animation) { + delete(reinterpret_cast(animation)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +/************************************************************************/ +/* Accessor API */ +/************************************************************************/ + +TVG_API Tvg_Accessor tvg_accessor_new() +{ + return (Tvg_Accessor) Accessor::gen(); +} + + +TVG_API Tvg_Result tvg_accessor_del(Tvg_Accessor accessor) +{ + if (accessor) { + delete(reinterpret_cast(accessor)); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API Tvg_Result tvg_accessor_set(Tvg_Accessor accessor, Tvg_Paint paint, bool (*func)(Tvg_Paint paint, void* data), void* data) +{ + if (accessor) return (Tvg_Result) reinterpret_cast(accessor)->set(static_cast(reinterpret_cast(paint)), + [func](const Paint* paint, void* data) { return func((Tvg_Paint) paint, data); }, data); + return TVG_RESULT_INVALID_ARGUMENT; +} + + +TVG_API uint32_t tvg_accessor_generate_id(const char* name) +{ + return Accessor::id(name); +} + + +/************************************************************************/ +/* Lottie Animation API */ +/************************************************************************/ + +TVG_API Tvg_Animation tvg_lottie_animation_new() +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + return (Tvg_Animation) LottieAnimation::gen(); +#endif + return nullptr; +} + + +TVG_API uint32_t tvg_lottie_animation_gen_slot(Tvg_Animation animation, const char* slot) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return reinterpret_cast(animation)->gen(slot); +#endif + return 0; +} + + +TVG_API Tvg_Result tvg_lottie_animation_apply_slot(Tvg_Animation animation, uint32_t id) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->apply(id); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_del_slot(Tvg_Animation animation, uint32_t id) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->del(id); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_set_marker(Tvg_Animation animation, const char* marker) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->segment(marker); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_get_markers_cnt(Tvg_Animation animation, uint32_t* cnt) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation && cnt) { + *cnt = reinterpret_cast(animation)->markersCnt(); + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_get_marker(Tvg_Animation animation, uint32_t idx, const char** name) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation && name) { + *name = reinterpret_cast(animation)->marker(idx); + if (!(*name)) return TVG_RESULT_INVALID_ARGUMENT; + return TVG_RESULT_SUCCESS; + } + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_tween(Tvg_Animation animation, float from, float to, float progress) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->tween(from, to, progress); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_assign(Tvg_Animation animation, const char* layer, uint32_t ix, const char* var, float val) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->assign(layer, ix, var, val); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_set_quality(Tvg_Animation animation, uint8_t value) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->quality(value); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + +#ifdef __cplusplus +} +#endif diff --git a/components/thorvg-main/src/bindings/meson.build b/components/thorvg-main/src/bindings/meson.build new file mode 100644 index 0000000..c553a64 --- /dev/null +++ b/components/thorvg-main/src/bindings/meson.build @@ -0,0 +1,3 @@ +if get_option('bindings').contains('capi') + subdir('capi') +endif diff --git a/components/thorvg-main/src/common/meson.build b/components/thorvg-main/src/common/meson.build new file mode 100644 index 0000000..45f033f --- /dev/null +++ b/components/thorvg-main/src/common/meson.build @@ -0,0 +1,18 @@ +source_file = [ + 'tvgArray.h', + 'tvgCommon.h', + 'tvgColor.h', + 'tvgCompressor.h', + 'tvgInlist.h', + 'tvgLock.h', + 'tvgMath.h', + 'tvgStr.h', + 'tvgColor.cpp', + 'tvgCompressor.cpp', + 'tvgMath.cpp', + 'tvgStr.cpp' +] + +utils_dep = declare_dependency( + include_directories : include_directories('.'), + sources : source_file) diff --git a/components/thorvg-main/src/common/tvgAllocator.h b/components/thorvg-main/src/common/tvgAllocator.h new file mode 100644 index 0000000..c1d7a7e --- /dev/null +++ b/components/thorvg-main/src/common/tvgAllocator.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_ALLOCATOR_H_ +#define _TVG_ALLOCATOR_H_ + +#include +#include + +//separate memory alloators for clean customization +namespace tvg +{ + template + static inline T* malloc(size_t size) + { + return static_cast(std::malloc(size)); + } + + template + static inline T* calloc(size_t nmem, size_t size) + { + return static_cast(std::calloc(nmem, size)); + } + + template + static inline T* realloc(T* ptr, size_t size) + { + return static_cast(std::realloc(ptr, size)); + } + + template + static inline void free(T* ptr) + { + std::free(ptr); + } +} + +#endif //_TVG_ALLOCATOR_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/common/tvgArray.h b/components/thorvg-main/src/common/tvgArray.h new file mode 100644 index 0000000..c2b273d --- /dev/null +++ b/components/thorvg-main/src/common/tvgArray.h @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_ARRAY_H_ +#define _TVG_ARRAY_H_ + +#include "tvgCommon.h" + +#define ARRAY_FOREACH(A, B) \ + for (auto A = (B).begin(); A < (B).end(); ++A) + +#define ARRAY_REVERSE_FOREACH(A, B) \ + for (auto A = (B).end() - 1; A >= (B).begin(); --A) + +namespace tvg +{ + +template +struct Array +{ + T* data = nullptr; + uint32_t count = 0; + uint32_t reserved = 0; + + Array() = default; + + Array(int32_t size) + { + reserve(size); + } + + Array(const Array& rhs) + { + reset(); + *this = rhs; + } + + void push(T element) + { + if (count + 1 > reserved) { + reserved = count + (count + 2) / 2; + data = tvg::realloc(data, sizeof(T) * reserved); + } + data[count++] = element; + } + + void push(const Array& rhs) + { + if (rhs.count == 0) return; + grow(rhs.count); + memcpy(data + count, rhs.data, rhs.count * sizeof(T)); + count += rhs.count; + } + + bool reserve(uint32_t size) + { + if (size > reserved) { + reserved = size; + data = tvg::realloc(data, sizeof(T) * reserved); + } + return true; + } + + bool grow(uint32_t size) + { + return reserve(count + size); + } + + const T& operator[](size_t idx) const + { + return data[idx]; + } + + T& operator[](size_t idx) + { + return data[idx]; + } + + void operator=(const Array& rhs) + { + reserve(rhs.count); + if (rhs.count > 0) memcpy(data, rhs.data, sizeof(T) * rhs.count); + count = rhs.count; + } + + void move(Array& to) + { + to.reset(); + to.data = data; + to.count = count; + to.reserved = reserved; + + data = nullptr; + count = reserved = 0; + } + + const T* begin() const + { + return data; + } + + T* begin() + { + return data; + } + + T* end() + { + return data + count; + } + + const T* end() const + { + return data + count; + } + + const T& last() const + { + return data[count - 1]; + } + + const T& first() const + { + return data[0]; + } + + T& last() + { + return data[count - 1]; + } + + T& next() + { + if (full()) grow(count + 1); + return data[count++]; + } + + T& first() + { + return data[0]; + } + + void pop() + { + if (count > 0) --count; + } + + void reset() + { + tvg::free(data); + data = nullptr; + count = reserved = 0; + } + + void clear() + { + count = 0; + } + + bool empty() const + { + return count == 0; + } + + bool full() + { + return count == reserved; + } + + ~Array() + { + tvg::free(data); + } +}; + +} + +#endif //_TVG_ARRAY_H_ diff --git a/components/thorvg-main/src/common/tvgColor.cpp b/components/thorvg-main/src/common/tvgColor.cpp new file mode 100644 index 0000000..7181c3f --- /dev/null +++ b/components/thorvg-main/src/common/tvgColor.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgColor.h" +namespace tvg +{ + +void hsl2rgb(float h, float s, float l, uint8_t& r, uint8_t& g, uint8_t& b) +{ + if (tvg::zero(s)) { + r = g = b = (uint8_t)nearbyint(l * 255.0f); + return; + } + + if (tvg::equal(h, 360.0f)) { + h = 0.0f; + } else { + h = fmod(h, 360.0f); + if (h < 0.0f) h += 360.0f; + h /= 60.0f; + } + + auto v = (l <= 0.5f) ? (l * (1.0f + s)) : (l + s - (l * s)); + auto p = l + l - v; + auto sv = tvg::zero(v) ? 0.0f : (v - p) / v; + auto i = static_cast(h); + auto f = h - i; + auto vsf = v * sv * f; + auto t = p + vsf; + auto q = v - vsf; + float tr, tg, tb; + + switch (i) { + case 0: tr = v; tg = t; tb = p; break; + case 1: tr = q; tg = v; tb = p; break; + case 2: tr = p; tg = v; tb = t; break; + case 3: tr = p; tg = q; tb = v; break; + case 4: tr = t; tg = p; tb = v; break; + case 5: tr = v; tg = p; tb = q; break; + default: tr = tg = tb = 0.0f; break; + } + r = (uint8_t)nearbyint(tr * 255.0f); + g = (uint8_t)nearbyint(tg * 255.0f); + b = (uint8_t)nearbyint(tb * 255.0f); +} + +} \ No newline at end of file diff --git a/components/thorvg-main/src/common/tvgColor.h b/components/thorvg-main/src/common/tvgColor.h new file mode 100644 index 0000000..8a00707 --- /dev/null +++ b/components/thorvg-main/src/common/tvgColor.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_COLOR_H_ +#define _TVG_COLOR_H_ + + +#include "tvgCommon.h" + +namespace tvg +{ + struct RGB + { + uint8_t r, g, b; + }; + + struct RGBA + { + uint8_t r, g, b, a; + }; + + struct HSL + { + float h, s, l; + }; + + void hsl2rgb(float h, float s, float l, uint8_t& r, uint8_t& g, uint8_t& b); +} + +#endif //_TVG_COLOR_H_ diff --git a/components/thorvg-main/src/common/tvgCommon.h b/components/thorvg-main/src/common/tvgCommon.h new file mode 100644 index 0000000..a98d5eb --- /dev/null +++ b/components/thorvg-main/src/common/tvgCommon.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_COMMON_H_ +#define _TVG_COMMON_H_ + +#ifdef _WIN32 + #if defined(WINAPI_ENTRY) + #if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) + #include + #endif + #elif !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) + #include + #endif +#endif +#include +#include +#include +#include +#include "config.h" +#include "thorvg.h" + +using namespace std; +using namespace tvg; + +//for MSVC Compat +#ifdef _MSC_VER + #define TVG_UNUSED + #define strncasecmp _strnicmp + #define strcasecmp _stricmp + #define strtok_r strtok_s +#else + #define TVG_UNUSED __attribute__ ((__unused__)) +#endif + +// Portable 'fallthrough' attribute +#if __has_cpp_attribute(fallthrough) + #ifdef _MSC_VER + #define TVG_FALLTHROUGH [[fallthrough]]; + #else + #define TVG_FALLTHROUGH __attribute__ ((fallthrough)); + #endif +#else + #define TVG_FALLTHROUGH +#endif + +#if defined(_MSC_VER) && defined(__clang__) + #define strncpy strncpy_s +#endif + +void* operator new(std::size_t size); +void operator delete(void* ptr) noexcept; + +namespace tvg { + + enum class FileType { Png = 0, Jpg, Webp, Svg, Lot, Ttf, Raw, Gif, Unknown }; + + #ifdef THORVG_LOG_ENABLED + constexpr auto ErrorColor = "\033[31m"; //red + constexpr auto ErrorBgColor = "\033[41m";//bg red + constexpr auto LogColor = "\033[32m"; //green + constexpr auto LogBgColor = "\033[42m"; //bg green + constexpr auto GreyColor = "\033[90m"; //grey + constexpr auto ResetColors = "\033[0m"; //default + #define TVGERR(tag, fmt, ...) fprintf(stderr, "%s[E]%s %s" tag "%s (%s %d): %s" fmt "\n", ErrorBgColor, ResetColors, ErrorColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__) + #define TVGLOG(tag, fmt, ...) fprintf(stdout, "%s[L]%s %s" tag "%s (%s %d): %s" fmt "\n", LogBgColor, ResetColors, LogColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__) + #else + #define TVGERR(...) do {} while(0) + #define TVGLOG(...) do {} while(0) + #endif + + template + static inline T* to(const Paint* p) + { + return static_cast(const_cast(p)); + } + + uint16_t THORVG_VERSION_NUMBER(); + + extern int engineInit; +} + +#include "tvgAllocator.h" + +#endif //_TVG_COMMON_H_ diff --git a/components/thorvg-main/src/common/tvgCompressor.cpp b/components/thorvg-main/src/common/tvgCompressor.cpp new file mode 100644 index 0000000..fb6d183 --- /dev/null +++ b/components/thorvg-main/src/common/tvgCompressor.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "config.h" +#include "tvgCommon.h" +#include "tvgCompressor.h" + +namespace tvg { + + +/************************************************************************/ +/* B64 Implementation */ +/************************************************************************/ + +size_t b64Decode(const char* encoded, const size_t len, char** decoded) +{ + static constexpr const char B64_INDEX[256] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 + }; + + + if (!decoded || !encoded || len == 0) return 0; + + auto reserved = 3 * (1 + (len >> 2)) + 1; + auto output = tvg::malloc(reserved * sizeof(char)); + if (!output) return 0; + output[reserved - 1] = '\0'; + + size_t idx = 0; + + while (*encoded && *(encoded + 1)) { + if (*encoded <= 0x20) { + ++encoded; + continue; + } + + auto value1 = B64_INDEX[(size_t)encoded[0]]; + auto value2 = B64_INDEX[(size_t)encoded[1]]; + output[idx++] = (value1 << 2) + ((value2 & 0x30) >> 4); + + if (!encoded[2] || encoded[3] < 0 || encoded[2] == '=' || encoded[2] == '.') break; + auto value3 = B64_INDEX[(size_t)encoded[2]]; + output[idx++] = ((value2 & 0x0f) << 4) + ((value3 & 0x3c) >> 2); + + if (!encoded[3] || encoded[3] < 0 || encoded[3] == '=' || encoded[3] == '.') break; + auto value4 = B64_INDEX[(size_t)encoded[3]]; + output[idx++] = ((value3 & 0x03) << 6) + value4; + encoded += 4; + } + *decoded = output; + return idx; +} + + +/************************************************************************/ +/* DJB2 Implementation */ +/************************************************************************/ + +unsigned long djb2Encode(const char* str) +{ + if (!str) return 0; + + unsigned long hash = 5381; + int c; + + while ((c = *str++)) { + hash = ((hash << 5) + hash) + c; // hash * 33 + c + } + return hash; +} + +} \ No newline at end of file diff --git a/components/thorvg-main/src/common/tvgCompressor.h b/components/thorvg-main/src/common/tvgCompressor.h new file mode 100644 index 0000000..1584c9a --- /dev/null +++ b/components/thorvg-main/src/common/tvgCompressor.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_COMPRESSOR_H_ +#define _TVG_COMPRESSOR_H_ + +#include + +namespace tvg +{ + size_t b64Decode(const char* encoded, const size_t len, char** decoded); + unsigned long djb2Encode(const char* str); +} + +#endif //_TVG_COMPRESSOR_H_ diff --git a/components/thorvg-main/src/common/tvgInlist.h b/components/thorvg-main/src/common/tvgInlist.h new file mode 100644 index 0000000..3abe966 --- /dev/null +++ b/components/thorvg-main/src/common/tvgInlist.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_INLIST_H_ +#define _TVG_INLIST_H_ + +namespace tvg { + +//NOTE: declare this in your list item +#define INLIST_ITEM(T) \ + T* prev; \ + T* next + +template +struct Inlist +{ + T* head = nullptr; + T* tail = nullptr; + + ~Inlist() + { + free(); + } + + void free() + { + while (head) { + auto t = head; + head = t->next; + delete(t); + } + head = tail = nullptr; + } + + void back(T* element) + { + if (tail) { + tail->next = element; + element->prev = tail; + element->next = nullptr; + tail = element; + } else { + head = tail = element; + element->prev = nullptr; + element->next = nullptr; + } + } + + void front(T* element) + { + if (head) { + head->prev = element; + element->prev = nullptr; + element->next = head; + head = element; + } else { + head = tail = element; + element->prev = nullptr; + element->next = nullptr; + } + } + + T* back() + { + if (!tail) return nullptr; + auto t = tail; + tail = t->prev; + if (!tail) head = nullptr; + return t; + } + + T* front() + { + if (!head) return nullptr; + auto t = head; + head = t->next; + if (!head) tail = nullptr; + return t; + } + + void remove(T* element) + { + if (element->prev) element->prev->next = element->next; + if (element->next) element->next->prev = element->prev; + if (element == head) head = element->next; + if (element == tail) tail = element->prev; + } + + bool empty() const + { + return head ? false : true; + } +}; + +#define INLIST_FOREACH(inlist, cur) \ + for (auto cur = inlist.head; cur; cur = cur->next) + +#define INLIST_SAFE_FOREACH(inlist, cur) \ + auto cur = inlist.head; \ + auto next = cur ? cur->next : nullptr; \ + for (; cur; cur = next, next = (cur ? cur->next : nullptr)) + +} + +#endif // _TVG_INLIST_H_ diff --git a/components/thorvg-main/src/common/tvgLock.h b/components/thorvg-main/src/common/tvgLock.h new file mode 100644 index 0000000..d3a4e41 --- /dev/null +++ b/components/thorvg-main/src/common/tvgLock.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOCK_H_ +#define _TVG_LOCK_H_ + +#ifdef THORVG_THREAD_SUPPORT + +#include +#include "tvgTaskScheduler.h" + +namespace tvg { + + struct Key + { + std::mutex mtx; + }; + + struct ScopedLock + { + Key* key = nullptr; + + ScopedLock(Key& k) + { + if (TaskScheduler::threads() > 0) { + k.mtx.lock(); + key = &k; + } + } + + ~ScopedLock() + { + if (TaskScheduler::threads() > 0) { + key->mtx.unlock(); + } + } + }; + +} + +#else //THORVG_THREAD_SUPPORT + +namespace tvg { + + struct Key {}; + + struct ScopedLock + { + ScopedLock(Key& key) {} + }; + +} + +#endif //THORVG_THREAD_SUPPORT + +#endif //_TVG_LOCK_H_ + diff --git a/components/thorvg-main/src/common/tvgMath.cpp b/components/thorvg-main/src/common/tvgMath.cpp new file mode 100644 index 0000000..856377d --- /dev/null +++ b/components/thorvg-main/src/common/tvgMath.cpp @@ -0,0 +1,513 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgArray.h" + +#define BEZIER_EPSILON 1e-2f + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static float _lineLengthApprox(const Point& pt1, const Point& pt2) +{ + /* approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm. + With alpha = 1, beta = 3/8, giving results with the largest error less + than 7% compared to the exact value. */ + Point diff = {pt2.x - pt1.x, pt2.y - pt1.y}; + if (diff.x < 0) diff.x = -diff.x; + if (diff.y < 0) diff.y = -diff.y; + return (diff.x > diff.y) ? (diff.x + diff.y * 0.375f) : (diff.y + diff.x * 0.375f); +} + + +static float _lineLength(const Point& pt1, const Point& pt2) +{ + Point diff = {pt2.x - pt1.x, pt2.y - pt1.y}; + return sqrtf(diff.x * diff.x + diff.y * diff.y); +} + + +template +float _bezLength(const Bezier& cur, LengthFunc lineLengthFunc) +{ + Bezier left, right; + auto len = lineLengthFunc(cur.start, cur.ctrl1) + lineLengthFunc(cur.ctrl1, cur.ctrl2) + lineLengthFunc(cur.ctrl2, cur.end); + auto chord = lineLengthFunc(cur.start, cur.end); + + if (fabsf(len - chord) > BEZIER_EPSILON) { + cur.split(left, right); + return _bezLength(left, lineLengthFunc) + _bezLength(right, lineLengthFunc); + } + return len; +} + + +template +float _bezAt(const Bezier& bz, float at, float length, LengthFunc lineLengthFunc) +{ + auto biggest = 1.0f; + auto smallest = 0.0f; + auto t = 0.5f; + + //just in case to prevent an infinite loop + if (at <= 0) return 0.0f; + if (at >= length) return 1.0f; + + while (true) { + auto right = bz; + Bezier left; + right.split(t, left); + length = _bezLength(left, lineLengthFunc); + if (fabsf(length - at) < BEZIER_EPSILON || fabsf(smallest - biggest) < 1e-3f) { + break; + } + if (length < at) { + smallest = t; + t = (t + biggest) * 0.5f; + } else { + biggest = t; + t = (smallest + t) * 0.5f; + } + } + return t; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +namespace tvg { + + +uint8_t lerp(const uint8_t &start, const uint8_t &end, float t) +{ + return static_cast(tvg::clamp(static_cast(start + (end - start) * t), 0, 255)); +} + + +float length(const PathCommand* cmds, uint32_t cmdsCnt, const Point* pts, uint32_t ptsCnt) +{ + if (ptsCnt < 2) return 0.0f; + + auto start = pts; + auto length = 0.0f; + + while (cmdsCnt-- > 0) { + switch (*cmds) { + case PathCommand::Close: { + length += tvg::length(*(pts - 1), *start); + break; + } + case PathCommand::MoveTo: { + start = pts; + ++pts; + break; + } + case PathCommand::LineTo: { + length += tvg::length(*(pts - 1), *pts); + ++pts; + break; + } + case PathCommand::CubicTo: { + length += Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}.length(); + pts += 3; + break; + } + } + ++cmds; + } + + return length; +} + + +//https://en.wikipedia.org/wiki/Remez_algorithm +float atan2(float y, float x) +{ + if (y == 0.0f && x == 0.0f) return 0.0f; + auto a = std::min(fabsf(x), fabsf(y)) / std::max(fabsf(x), fabsf(y)); + auto s = a * a; + auto r = ((-0.0464964749f * s + 0.15931422f) * s - 0.327622764f) * s * a + a; + if (fabsf(y) > fabsf(x)) r = 1.57079637f - r; + if (x < 0) r = 3.14159274f - r; + if (y < 0) return -r; + return r; +} + + +bool inverse(const Matrix* m, Matrix* out) +{ + auto det = m->e11 * (m->e22 * m->e33 - m->e32 * m->e23) - + m->e12 * (m->e21 * m->e33 - m->e23 * m->e31) + + m->e13 * (m->e21 * m->e32 - m->e22 * m->e31); + + auto invDet = 1.0f / det; + if (std::isinf(invDet)) return false; + + out->e11 = (m->e22 * m->e33 - m->e32 * m->e23) * invDet; + out->e12 = (m->e13 * m->e32 - m->e12 * m->e33) * invDet; + out->e13 = (m->e12 * m->e23 - m->e13 * m->e22) * invDet; + out->e21 = (m->e23 * m->e31 - m->e21 * m->e33) * invDet; + out->e22 = (m->e11 * m->e33 - m->e13 * m->e31) * invDet; + out->e23 = (m->e21 * m->e13 - m->e11 * m->e23) * invDet; + out->e31 = (m->e21 * m->e32 - m->e31 * m->e22) * invDet; + out->e32 = (m->e31 * m->e12 - m->e11 * m->e32) * invDet; + out->e33 = (m->e11 * m->e22 - m->e21 * m->e12) * invDet; + + return true; +} + + +bool identity(const Matrix* m) +{ + if (m->e11 != 1.0f || m->e12 != 0.0f || m->e13 != 0.0f || + m->e21 != 0.0f || m->e22 != 1.0f || m->e23 != 0.0f || + m->e31 != 0.0f || m->e32 != 0.0f || m->e33 != 1.0f) { + return false; + } + return true; +} + + +void rotate(Matrix* m, float degree) +{ + if (degree == 0.0f) return; + + auto radian = degree / 180.0f * MATH_PI; + auto cosVal = cosf(radian); + auto sinVal = sinf(radian); + + m->e12 = m->e11 * -sinVal; + m->e11 *= cosVal; + m->e21 = m->e22 * sinVal; + m->e22 *= cosVal; +} + + +Matrix operator*(const Matrix& lhs, const Matrix& rhs) +{ + Matrix m; + + m.e11 = lhs.e11 * rhs.e11 + lhs.e12 * rhs.e21 + lhs.e13 * rhs.e31; + m.e12 = lhs.e11 * rhs.e12 + lhs.e12 * rhs.e22 + lhs.e13 * rhs.e32; + m.e13 = lhs.e11 * rhs.e13 + lhs.e12 * rhs.e23 + lhs.e13 * rhs.e33; + + m.e21 = lhs.e21 * rhs.e11 + lhs.e22 * rhs.e21 + lhs.e23 * rhs.e31; + m.e22 = lhs.e21 * rhs.e12 + lhs.e22 * rhs.e22 + lhs.e23 * rhs.e32; + m.e23 = lhs.e21 * rhs.e13 + lhs.e22 * rhs.e23 + lhs.e23 * rhs.e33; + + m.e31 = lhs.e31 * rhs.e11 + lhs.e32 * rhs.e21 + lhs.e33 * rhs.e31; + m.e32 = lhs.e31 * rhs.e12 + lhs.e32 * rhs.e22 + lhs.e33 * rhs.e32; + m.e33 = lhs.e31 * rhs.e13 + lhs.e32 * rhs.e23 + lhs.e33 * rhs.e33; + + return m; +} + + +bool operator==(const Matrix& lhs, const Matrix& rhs) +{ + if (!tvg::equal(lhs.e11, rhs.e11) || !tvg::equal(lhs.e12, rhs.e12) || !tvg::equal(lhs.e13, rhs.e13) || + !tvg::equal(lhs.e21, rhs.e21) || !tvg::equal(lhs.e22, rhs.e22) || !tvg::equal(lhs.e23, rhs.e23) || + !tvg::equal(lhs.e31, rhs.e31) || !tvg::equal(lhs.e32, rhs.e32) || !tvg::equal(lhs.e33, rhs.e33)) { + return false; + } + return true; +} + + +void operator*=(Point& pt, const Matrix& m) +{ + auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13; + auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23; + pt.x = tx; + pt.y = ty; +} + + +Point operator*(const Point& pt, const Matrix& m) +{ + auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13; + auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23; + return {tx, ty}; +} + + +Point normal(const Point& p1, const Point& p2) +{ + auto dir = p2 - p1; + auto len = length(dir); + if (tvg::zero(len)) return {}; + + auto unitDir = dir / len; + return {-unitDir.y, unitDir.x}; +} + + +void normalize(Point& pt) +{ + if (zero(pt)) return; //prevent zero division + auto ilength = 1.0f / sqrtf((pt.x * pt.x) + (pt.y * pt.y)); + pt.x *= ilength; + pt.y *= ilength; +} + + +float Line::length() const +{ + return _lineLength(pt1, pt2); +} + + +void Line::split(float at, Line& left, Line& right) const +{ + auto len = length(); + auto dx = ((pt2.x - pt1.x) / len) * at; + auto dy = ((pt2.y - pt1.y) / len) * at; + left.pt1 = pt1; + left.pt2.x = left.pt1.x + dx; + left.pt2.y = left.pt1.y + dy; + right.pt1 = left.pt2; + right.pt2 = pt2; +} + + +Bezier::Bezier(const Point& st, const Point& ed, float radius) +{ + // Calculate the angle between the start and end points + auto angle = tvg::atan2(ed.y - st.y, ed.x - st.x); + + // Calculate the control points of the cubic bezier curve + auto c = radius * PATH_KAPPA; // c = radius * (4/3) * tan(pi/8) + + start = {st.x, st.y}; + ctrl1 = {st.x + radius * cos(angle), st.y + radius * sin(angle)}; + ctrl2 = {ed.x - c * cos(angle), ed.y - c * sin(angle)}; + end = {ed.x, ed.y}; +} + + +void Bezier::split(Bezier& left, Bezier& right) const +{ + auto c = (ctrl1.x + ctrl2.x) * 0.5f; + left.ctrl1.x = (start.x + ctrl1.x) * 0.5f; + right.ctrl2.x = (ctrl2.x + end.x) * 0.5f; + left.start.x = start.x; + right.end.x = end.x; + left.ctrl2.x = (left.ctrl1.x + c) * 0.5f; + right.ctrl1.x = (right.ctrl2.x + c) * 0.5f; + left.end.x = right.start.x = (left.ctrl2.x + right.ctrl1.x) * 0.5f; + + c = (ctrl1.y + ctrl2.y) * 0.5f; + left.ctrl1.y = (start.y + ctrl1.y) * 0.5f; + right.ctrl2.y = (ctrl2.y + end.y) * 0.5f; + left.start.y = start.y; + right.end.y = end.y; + left.ctrl2.y = (left.ctrl1.y + c) * 0.5f; + right.ctrl1.y = (right.ctrl2.y + c) * 0.5f; + left.end.y = right.start.y = (left.ctrl2.y + right.ctrl1.y) * 0.5f; +} + + +void Bezier::split(float at, Bezier& left, Bezier& right) const +{ + right = *this; + auto t = right.at(at, right.length()); + right.split(t, left); +} + + +float Bezier::length() const +{ + return _bezLength(*this, _lineLength); +} + + +float Bezier::lengthApprox() const +{ + return _bezLength(*this, _lineLengthApprox); +} + + +void Bezier::split(float t, Bezier& left) +{ + left.start = start; + + left.ctrl1.x = start.x + t * (ctrl1.x - start.x); + left.ctrl1.y = start.y + t * (ctrl1.y - start.y); + + left.ctrl2.x = ctrl1.x + t * (ctrl2.x - ctrl1.x); //temporary holding spot + left.ctrl2.y = ctrl1.y + t * (ctrl2.y - ctrl1.y); //temporary holding spot + + ctrl2.x = ctrl2.x + t * (end.x - ctrl2.x); + ctrl2.y = ctrl2.y + t * (end.y - ctrl2.y); + + ctrl1.x = left.ctrl2.x + t * (ctrl2.x - left.ctrl2.x); + ctrl1.y = left.ctrl2.y + t * (ctrl2.y - left.ctrl2.y); + + left.ctrl2.x = left.ctrl1.x + t * (left.ctrl2.x - left.ctrl1.x); + left.ctrl2.y = left.ctrl1.y + t * (left.ctrl2.y - left.ctrl1.y); + + left.end.x = start.x = left.ctrl2.x + t * (ctrl1.x - left.ctrl2.x); + left.end.y = start.y = left.ctrl2.y + t * (ctrl1.y - left.ctrl2.y); +} + + +float Bezier::at(float at, float length) const +{ + return _bezAt(*this, at, length, _lineLength); +} + + +float Bezier::atApprox(float at, float length) const +{ + return _bezAt(*this, at, length, _lineLengthApprox); +} + + +Point Bezier::at(float t) const +{ + Point cur; + auto it = 1.0f - t; + + auto ax = start.x * it + ctrl1.x * t; + auto bx = ctrl1.x * it + ctrl2.x * t; + auto cx = ctrl2.x * it + end.x * t; + ax = ax * it + bx * t; + bx = bx * it + cx * t; + cur.x = ax * it + bx * t; + + float ay = start.y * it + ctrl1.y * t; + float by = ctrl1.y * it + ctrl2.y * t; + float cy = ctrl2.y * it + end.y * t; + ay = ay * it + by * t; + by = by * it + cy * t; + cur.y = ay * it + by * t; + + return cur; +} + + +float Bezier::angle(float t) const +{ + if (t < 0 || t > 1) return 0; + + //derivate + // p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 * + // t^2) * p2 + t^2 * p3) + float mt = 1.0f - t; + float d = t * t; + float a = -mt * mt; + float b = 1 - 4 * t + 3 * d; + float c = 2 * t - 3 * d; + + Point pt ={a * start.x + b * ctrl1.x + c * ctrl2.x + d * end.x, a * start.y + b * ctrl1.y + c * ctrl2.y + d * end.y}; + pt.x *= 3; + pt.y *= 3; + + return rad2deg(tvg::atan2(pt.y, pt.x)); +} + + +void Bezier::bounds(BBox& box, const Point& start, const Point& ctrl1, const Point& ctrl2, const Point& end) +{ + if (box.min.x > start.x) box.min.x = start.x; + if (box.min.y > start.y) box.min.y = start.y; + if (box.min.x > end.x) box.min.x = end.x; + if (box.min.y > end.y) box.min.y = end.y; + + if (box.max.x < start.x) box.max.x = start.x; + if (box.max.y < start.y) box.max.y = start.y; + if (box.max.x < end.x) box.max.x = end.x; + if (box.max.y < end.y) box.max.y = end.y; + + //find x/y-direction extrema (solving derivative of Bezier curve) + auto findMinMax = [&](float start, float ctrl1, float ctrl2, float end, float& min, float& max) -> void { + auto a = -1.0f * start + 3.0f * ctrl1 - 3.0f * ctrl2 + end; + auto b = start - 2.0f * ctrl1 + ctrl2; + auto c = -1.0f * start + ctrl1; + auto h = b * b - a * c; + if (h <= 0.0f) return; + h = sqrtf(h); + float t[2] = {(-b - h) / a, (-b + h) / a}; + for (int i = 0; i < 2; ++i) { + if (t[i] <= 0.0f || t[i] >= 1.0f) continue; + auto s = 1.0f - t[i]; + auto q = s * s * s * start + 3.0f * s * s * t[i] * ctrl1 + 3.0f * s * t[i] * t[i] * ctrl2 + t[i] * t[i] * t[i] * end; + if (q < min) min = q; + if (q > max) max = q; + } + }; + + findMinMax(start.x, ctrl1.x, ctrl2.x, end.x, box.min.x, box.max.x); + findMinMax(start.y, ctrl1.y, ctrl2.y, end.y, box.min.y, box.max.y); +} + + +bool Bezier::flatten() const +{ + float diff1_x = fabsf((ctrl1.x * 3.f) - (start.x * 2.f) - end.x); + float diff1_y = fabsf((ctrl1.y * 3.f) - (start.y * 2.f) - end.y); + float diff2_x = fabsf((ctrl2.x * 3.f) - (end.x * 2.f) - start.x); + float diff2_y = fabsf((ctrl2.y * 3.f) - (end.y * 2.f) - start.y); + if (diff1_x < diff2_x) diff1_x = diff2_x; + if (diff1_y < diff2_y) diff1_y = diff2_y; + return (diff1_x + diff1_y <= 0.5f); +} + + +uint32_t Bezier::segments() const +{ + static constexpr uint32_t MaxSegments = 1u << 10; // 2^10 segments cap keeps runtime bounded + uint32_t count = 0; + Array stack; + stack.push(*this); + Bezier left, right; + + while (!stack.empty()) { + auto current = stack.last(); + stack.pop(); + if (current.flatten()) { + ++count; + continue; + } + if (count + stack.count + 2 >= MaxSegments) { + TVGERR("Common", "Bezier segments count exceeded the maximum limit."); + return MaxSegments; + } + current.split(left, right); + stack.push(left); + stack.push(right); + } + return count; +} + + +Bezier Bezier::operator*(const Matrix& m) +{ + return Bezier{start * m, ctrl1* m, ctrl2 * m, end * m}; +} + +} \ No newline at end of file diff --git a/components/thorvg-main/src/common/tvgMath.h b/components/thorvg-main/src/common/tvgMath.h new file mode 100644 index 0000000..2590448 --- /dev/null +++ b/components/thorvg-main/src/common/tvgMath.h @@ -0,0 +1,486 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_MATH_H_ +#define _TVG_MATH_H_ + + #define _USE_MATH_DEFINES + +#include +#include +#include "tvgCommon.h" + +namespace tvg +{ + +#define MATH_PI 3.14159265358979323846f +#define MATH_PI2 1.57079632679489661923f +#define FLOAT_EPSILON 1.0e-06f //1.192092896e-07f +#define PATH_KAPPA 0.552284f + +/************************************************************************/ +/* General functions */ +/************************************************************************/ + +float atan2(float y, float x); +float length(const PathCommand* cmds, uint32_t cmdsCnt, const Point* pts, uint32_t ptsCnt); + + +static inline float deg2rad(float degree) +{ + return degree * (MATH_PI / 180.0f); +} + + +static inline float rad2deg(float radian) +{ + return radian * (180.0f / MATH_PI); +} + + +static inline bool zero(float a) +{ + return (fabsf(a) <= FLOAT_EPSILON) ? true : false; +} + + +static inline bool equal(float a, float b) +{ + return tvg::zero(a - b); +} + + +template +static inline constexpr const T& clamp(const T& v, const T& min, const T& max) +{ + if (v < min) return min; + else if (v > max) return max; + return v; +} + +/************************************************************************/ +/* Matrix functions */ +/************************************************************************/ + +void rotate(Matrix* m, float degree); +bool inverse(const Matrix* m, Matrix* out); +bool identity(const Matrix* m); +Matrix operator*(const Matrix& lhs, const Matrix& rhs); +bool operator==(const Matrix& lhs, const Matrix& rhs); + + +static inline float radian(const Matrix& m) +{ + return fabsf(tvg::atan2(m.e21, m.e11)); +} + + +static inline bool rightAngle(const Matrix& m) +{ + auto radian = tvg::radian(m); + if (tvg::zero(radian) || tvg::zero(radian - MATH_PI2) || tvg::zero(radian - MATH_PI)) return true; + return false; +} + + +static inline bool skewed(const Matrix& m) +{ + return !tvg::zero(m.e21 + m.e12); +} + + +static inline void identity(Matrix* m) +{ + m->e11 = 1.0f; + m->e12 = 0.0f; + m->e13 = 0.0f; + m->e21 = 0.0f; + m->e22 = 1.0f; + m->e23 = 0.0f; + m->e31 = 0.0f; + m->e32 = 0.0f; + m->e33 = 1.0f; +} + + +static inline constexpr const Matrix identity() +{ + return {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; +} + + +static inline float scaling(const Matrix& m) +{ + return sqrtf(m.e11 * m.e11 + m.e21 * m.e21); +} + + +static inline void scale(Matrix* m, const Point& p) +{ + m->e11 *= p.x; + m->e22 *= p.y; +} + + +static inline void scaleR(Matrix* m, const Point& p) +{ + if (p.x != 1.0f) { + m->e11 *= p.x; + m->e21 *= p.x; + } + if (p.y != 1.0f) { + m->e22 *= p.y; + m->e12 *= p.y; + } +} + + +static inline void translate(Matrix* m, const Point& p) +{ + m->e13 += p.x; + m->e23 += p.y; +} + + +static inline void translateR(Matrix* m, const Point& p) +{ + if (p.x == 0.0f && p.y == 0.0f) return; + m->e13 += (p.x * m->e11 + p.y * m->e12); + m->e23 += (p.x * m->e21 + p.y * m->e22); +} + + +static inline bool operator!=(const Matrix& lhs, const Matrix& rhs) +{ + return !(lhs == rhs); +} + + +static inline void operator*=(Matrix& lhs, const Matrix& rhs) +{ + lhs = lhs * rhs; +} + + +static inline Matrix operator*(const Matrix* lhs, const Matrix& rhs) +{ + if (lhs) return *lhs * rhs; + return rhs; +} + + +static inline void log(const Matrix& m) +{ + TVGLOG("COMMON", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m.e11, m.e12, m.e13, m.e21, m.e22, m.e23, m.e31, m.e32, m.e33); +} + + +/************************************************************************/ +/* Point functions */ +/************************************************************************/ + +void operator*=(Point& pt, const Matrix& m); +Point operator*(const Point& pt, const Matrix& m); +Point normal(const Point& p1, const Point& p2); +void normalize(Point& pt); + +static inline constexpr const Point operator*=(Point& pt, const Matrix* m) +{ + if (m) pt *= *m; + return pt; +} + + +static inline Point operator*(const Point& pt, const Matrix* m) +{ + if (m) return pt * *m; + return pt; +} + + +static inline Point min(const Point& lhs, const Point& rhs) +{ + return {std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y)}; +} + + +static inline Point max(const Point& lhs, const Point& rhs) +{ + return {std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y)}; +} + + +static inline float dot(const Point& lhs, const Point& rhs) +{ + return lhs.x * rhs.x + lhs.y * rhs.y; +} + + +static inline float cross(const Point& lhs, const Point& rhs) +{ + return lhs.x * rhs.y - rhs.x * lhs.y; +} + + +static inline bool zero(const Point& p) +{ + return tvg::zero(p.x) && tvg::zero(p.y); +} + + +static inline float length(const Point& a, const Point& b) +{ + auto x = b.x - a.x; + auto y = b.y - a.y; + + if (x < 0) x = -x; + if (y < 0) y = -y; + + return (x > y) ? (x + 0.375f * y) : (y + 0.375f * x); +} + + +static inline float length(const Point& a) +{ + return sqrtf(a.x * a.x + a.y * a.y); +} + + +static inline float length2(const Point& a) +{ + return a.x * a.x + a.y * a.y; +}; + + +static inline bool operator==(const Point& lhs, const Point& rhs) +{ + return tvg::equal(lhs.x, rhs.x) && tvg::equal(lhs.y, rhs.y); +} + + +static inline bool operator!=(const Point& lhs, const Point& rhs) +{ + return !(lhs == rhs); +} + + +static inline Point operator-(const Point& lhs, const Point& rhs) +{ + return {lhs.x - rhs.x, lhs.y - rhs.y}; +} + + +static inline Point operator-(const Point& lhs, const float rhs) +{ + return {lhs.x - rhs, lhs.y - rhs}; +} + + +static inline Point operator+(const Point& lhs, const Point& rhs) +{ + return {lhs.x + rhs.x, lhs.y + rhs.y}; +} + + +static inline Point operator+(const Point& lhs, const float rhs) +{ + return {lhs.x + rhs, lhs.y + rhs}; +} + + +static inline void operator+=(Point& lhs, const Point& rhs) +{ + lhs.x += rhs.x; + lhs.y += rhs.y; +} + + +static inline Point operator*(const Point& lhs, const Point& rhs) +{ + return {lhs.x * rhs.x, lhs.y * rhs.y}; +} + + +static inline void operator*=(Point& lhs, const Point& rhs) +{ + lhs.x *= rhs.x; + lhs.y *= rhs.y; +} + + +static inline Point operator*(const Point& lhs, const float rhs) +{ + return {lhs.x * rhs, lhs.y * rhs}; +} + + +static inline void operator*=(Point& lhs, const float rhs) +{ + lhs.x *= rhs; + lhs.y *= rhs; +} + + +static inline Point operator*(const float& lhs, const Point& rhs) +{ + return {lhs * rhs.x, lhs * rhs.y}; +} + + +static inline Point operator/(const Point& lhs, const Point& rhs) +{ + return {lhs.x / rhs.x, lhs.y / rhs.y}; +} + + +static inline Point operator/(const Point& lhs, const float rhs) +{ + return {lhs.x / rhs, lhs.y / rhs}; +} + + +static inline Point operator-(const Point& a) +{ + return {-a.x, -a.y}; +} + +enum class Orientation +{ + Linear = 0, + Clockwise, + CounterClockwise, +}; + + +static inline Orientation orientation(const Point& p1, const Point& p2, const Point& p3) +{ + auto val = cross(p2 - p1, p3 - p1); + if (zero(val)) return Orientation::Linear; + else return val > 0 ? Orientation::Clockwise : Orientation::CounterClockwise; +} + + +static inline void log(const Point& pt) +{ + TVGLOG("COMMON", "Point: [%f %f]", pt.x, pt.y); +} + + +static inline bool closed(const Point& lhs, const Point& rhs, float tolerance) +{ + float dx = lhs.x - rhs.x; + float dy = lhs.y - rhs.y; + return (dx * dx + dy * dy) < (tolerance * tolerance); +} + + +/************************************************************************/ +/* Line functions */ +/************************************************************************/ + +struct Line +{ + Point pt1; + Point pt2; + + void split(float at, Line& left, Line& right) const; + float length() const; +}; + + +/************************************************************************/ +/* Geometry functions */ +/************************************************************************/ + +struct BBox +{ + Point min, max; + + void init() + { + min = {FLT_MAX, FLT_MAX}; + max = {-FLT_MAX, -FLT_MAX}; + } +}; + + +static inline uint32_t arcSegmentsCnt(float arcAngle, float pixelRadius) +{ + if (pixelRadius < FLOAT_EPSILON) return 2; + static constexpr auto PX_TOLERANCE = 0.25f; + // Sagitta-based formula Approximation: 1 - cos(θ/2) ≈ (θ/2)²/2, so θ ≈ 2 * sqrt(2 * s/r) + auto segmentAngle = 2.0f * sqrtf(2.0f * PX_TOLERANCE / pixelRadius); + return static_cast(ceilf(fabsf(arcAngle) / segmentAngle)) + 1; +} + + +/************************************************************************/ +/* Bezier functions */ +/************************************************************************/ + +struct Bezier +{ + Point start; + Point ctrl1; + Point ctrl2; + Point end; + + Bezier() {} + Bezier(const Point& p0, const Point& p1, const Point& p2, const Point& p3): + start(p0), ctrl1(p1), ctrl2(p2), end(p3) {} + // Constructor that approximates a quarter-circle segment of arc between 'start' and 'end' points + // using a cubic Bezier curve with a given 'radius'. + Bezier(const Point& start, const Point& end, float radius); + + void split(float t, Bezier& left); + void split(Bezier& left, Bezier& right) const; + void split(float at, Bezier& left, Bezier& right) const; + float length() const; + float lengthApprox() const; + float at(float at, float length) const; + float atApprox(float at, float length) const; + Point at(float t) const; + float angle(float t) const; + bool flatten() const; + uint32_t segments() const; + + Bezier operator*(const Matrix& m); + + static void bounds(BBox& box, const Point& start, const Point& ctrl1, const Point& ctrl2, const Point& end); +}; + + +/************************************************************************/ +/* Interpolation functions */ +/************************************************************************/ + +template +static inline T lerp(const T &start, const T &end, float t) +{ + return static_cast(start + (end - start) * t); +} + +uint8_t lerp(const uint8_t &start, const uint8_t &end, float t); + +} + +#endif //_TVG_MATH_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/common/tvgStr.cpp b/components/thorvg-main/src/common/tvgStr.cpp new file mode 100644 index 0000000..df68794 --- /dev/null +++ b/components/thorvg-main/src/common/tvgStr.cpp @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "config.h" +#include +#include "tvgCommon.h" +#include "tvgMath.h" +#include "tvgStr.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static inline bool _floatExact(float a, float b) +{ + return memcmp(&a, &b, sizeof(float)) == 0; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +namespace tvg { + +/* + * https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strtof-strtof-l-wcstof-wcstof-l?view=msvc-160 + * + * src should be one of the following form : + * + * [whitespace] [sign] {digits [radix digits] | radix digits} [{e | E} [sign] digits] + * [whitespace] [sign] {INF | INFINITY} + * [whitespace] [sign] NAN [sequence] + * + * No hexadecimal form supported + * no sequence supported after NAN + */ +float toFloat(const char *str, char **end) +{ + if (end) *end = (char *) (str); + if (!str) return 0.0f; + + auto a = str; + auto iter = str; + auto val = 0.0f; + unsigned long long integerPart = 0; + int minus = 1; + + //ignore leading whitespaces + while (isspace(*iter)) iter++; + + //signed or not + if (*iter == '-') { + minus = -1; + iter++; + } else if (*iter == '+') { + iter++; + } + + if (tolower(*iter) == 'i') { + if ((tolower(*(iter + 1)) == 'n') && (tolower(*(iter + 2)) == 'f')) iter += 3; + else goto error; + + if (tolower(*(iter)) == 'i') { + if ((tolower(*(iter + 1)) == 'n') && (tolower(*(iter + 2)) == 'i') && (tolower(*(iter + 3)) == 't') && + (tolower(*(iter + 4)) == 'y')) + iter += 5; + else goto error; + } + if (end) *end = (char *) (iter); + return (minus == -1) ? -INFINITY : INFINITY; + } + + if (tolower(*iter) == 'n') { + if ((tolower(*(iter + 1)) == 'a') && (tolower(*(iter + 2)) == 'n')) iter += 3; + else goto error; + + if (end) *end = (char *) (iter); + return (minus == -1) ? -NAN : NAN; + } + + //Optional: integer part before dot + if (isdigit(*iter)) { + for (; isdigit(*iter); iter++) { + integerPart = integerPart * 10ULL + (unsigned long long) (*iter - '0'); + } + a = iter; + } else if (*iter != '.') { + goto success; + } + + val = static_cast(integerPart); + + //Optional: decimal part after dot + if (*iter == '.') { + unsigned long long decimalPart = 0; + unsigned long long pow10 = 1; + int count = 0; + + iter++; + + if (isdigit(*iter)) { + for (; isdigit(*iter); iter++, count++) { + if (count < 19) { + decimalPart = decimalPart * 10ULL + +static_cast(*iter - '0'); + pow10 *= 10ULL; + } + } + } else if (isspace(*iter)) { //skip if there is a space after the dot. + a = iter; + goto success; + } + + val += static_cast(decimalPart) / static_cast(pow10); + a = iter; + } + + //Optional: exponent + if (*iter == 'e' || *iter == 'E') { + ++iter; + + //Exception: svg may have 'em' unit for fonts. ex) 5em, 10.5em + if ((*iter == 'm') || (*iter == 'M')) { + //TODO: We don't support font em unit now, but has to multiply val * font size later... + a = iter + 1; + goto success; + } + + //signed or not + int minus_e = 1; + + if (*iter == '-') { + minus_e = -1; + ++iter; + } else if (*iter == '+') { + iter++; + } + + unsigned int exponentPart = 0; + + if (isdigit(*iter)) { + while (*iter == '0') iter++; + for (; isdigit(*iter); iter++) { + exponentPart = exponentPart * 10U + static_cast(*iter - '0'); + } + } else if (!isdigit(*(a - 1))) { + a = str; + goto success; + } else if (*iter == 0) { + goto success; + } + + //if ((_floatExact(val, 2.2250738585072011f)) && ((minus_e * static_cast(exponentPart)) <= -308)) { + if ((_floatExact(val, 1.175494351f)) && ((minus_e * static_cast(exponentPart)) <= -38)) { + //val *= 1.0e-308f; + val *= 1.0e-38f; + a = iter; + goto success; + } + + a = iter; + auto scale = 1.0f; + + while (exponentPart >= 8U) { + scale *= 1E8f; + exponentPart -= 8U; + } + while (exponentPart > 0U) { + scale *= 10.0f; + exponentPart--; + } + val = (minus_e == -1) ? (val / scale) : (val * scale); + } else if ((iter > str) && !isdigit(*(iter - 1))) { + a = str; + goto success; + } + +success: + if (end) *end = (char *)a; + if (!std::isfinite(val)) return 0.0f; + + return minus * val; + +error: + if (end) *end = (char *)str; + return 0.0f; +} + + +char* duplicate(const char *str, size_t n) +{ + auto len = strlen(str); + if (len < n) n = len; + + auto ret = tvg::malloc(n + 1); + ret[n] = '\0'; + + return (char*)memcpy(ret, str, n); +} + + +char* append(char* lhs, const char* rhs, size_t n) +{ + if (!rhs) return lhs; + if (!lhs) return duplicate(rhs, n); + lhs = tvg::realloc(lhs, strlen(lhs) + n + 1); + return strncat(lhs, rhs, n); +} + + +char* dirname(const char* path) +{ + auto ptr = strrchr(path, '/'); +#ifdef _WIN32 + auto ptr2 = strrchr(ptr ? ptr : path, '\\'); + if (ptr2) ptr = ptr2; +#endif + auto len = ptr ? size_t(ptr - path + 1) : SIZE_MAX; + return duplicate(path, len); +} + + +char* filename(const char* path) +{ + const char* ptr = strrchr(path, '/'); +#ifdef _WIN32 + auto ptr2 = strrchr(ptr ? ptr : path, '\\'); + if (ptr2) ptr = ptr2; +#endif + if (ptr) ++ptr; + else ptr = path; + auto dot = fileext(ptr); + auto len = (dot > ptr) ? (size_t)(dot - ptr - 1) : strlen(ptr); + return duplicate(ptr, len); +} + + +const char* fileext(const char* path) +{ + auto ext = path; + while (ext) { + auto p = strchr(ext, '.'); + if (!p) break; + ext = p + 1; + } + return ext; +} + + +char* concat(const char* a, const char* b) +{ + auto len = strlen(a) + strlen(b) + 1; + auto ret = tvg::malloc(len * sizeof(char)); + strcpy(ret, a); + strcat(ret, b); + return ret; +} + +} diff --git a/components/thorvg-main/src/common/tvgStr.h b/components/thorvg-main/src/common/tvgStr.h new file mode 100644 index 0000000..5d6c14d --- /dev/null +++ b/components/thorvg-main/src/common/tvgStr.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_STR_H_ +#define _TVG_STR_H_ + +#include "tvgCommon.h" + +namespace tvg +{ + +static inline bool equal(const char* a, const char* b) +{ + return !strcmp(a, b) && strlen(a) == strlen(b); +} + +char* concat(const char* a, const char* b); +float toFloat(const char *str, char **end); //convert to float +char* duplicate(const char *str, size_t n = SIZE_MAX); //copy the string +char* append(char* lhs, const char* rhs, size_t n); //append the rhs to the lhs +char* dirname(const char* path); //return the full directory name +char* filename(const char* path); //return the file name without extension +const char* fileext(const char* path); //return the file extension name + +} +#endif //_TVG_STR_H_ diff --git a/components/thorvg-main/src/loaders/external_jpg/meson.build b/components/thorvg-main/src/loaders/external_jpg/meson.build new file mode 100644 index 0000000..ce657ba --- /dev/null +++ b/components/thorvg-main/src/loaders/external_jpg/meson.build @@ -0,0 +1,18 @@ +source_file = [ + 'tvgJpgLoader.h', + 'tvgJpgLoader.cpp', +] + +jpg_dep = dependency('libturbojpeg', required: false) + +if not jpg_dep.found() + jpg_dep = cc.find_library('turbojpeg', required: false) +endif + +if jpg_dep.found() + subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + dependencies : jpg_dep, + sources : source_file + )] +endif diff --git a/components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.cpp b/components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.cpp new file mode 100644 index 0000000..75505b1 --- /dev/null +++ b/components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgJpgLoader.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void JpgLoader::clear() +{ + if (freeData) tvg::free(data); + data = nullptr; + size = 0; + freeData = false; +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +JpgLoader::JpgLoader() : ImageLoader(FileType::Jpg) +{ + jpegDecompressor = tjInitDecompress(); +} + + +JpgLoader::~JpgLoader() +{ + clear(); + tjDestroy(jpegDecompressor); + + //This image is shared with raster engine. + tjFree(surface.buf8); +} + + +bool JpgLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + if (!(data = (unsigned char*) LoadModule::open(path, size))) return false; + + int width, height, subSample, colorSpace; + if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &subSample, &colorSpace) < 0) return false; + w = static_cast(width); + h = static_cast(height); + freeData = true; + return true; +#else + return false; +#endif +} + + +bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + int width, height, subSample, colorSpace; + if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false; + + if (copy) { + this->data = tvg::malloc(size); + if (!this->data) return false; + memcpy((unsigned char *)this->data, data, size); + freeData = true; + } else { + this->data = (unsigned char *) data; + freeData = false; + } + + w = static_cast(width); + h = static_cast(height); + this->size = size; + + return true; +} + + +bool JpgLoader::read() +{ + if (!LoadModule::read()) return true; + + if (w == 0 || h == 0) return false; + + //determine the image format + TJPF format; + if (ImageLoader::cs == ColorSpace::ARGB8888 || ImageLoader::cs == ColorSpace::ARGB8888S) { + format = TJPF_BGRX; + surface.cs = ColorSpace::ARGB8888; + } else { + format = TJPF_RGBX; + surface.cs = ColorSpace::ABGR8888; + } + + auto image = (unsigned char *)tjAlloc(static_cast(w) * static_cast(h) * tjPixelSize[format]); + if (!image) return false; + + //decompress jpg image + if (tjDecompress2(jpegDecompressor, data, size, image, static_cast(w), 0, static_cast(h), format, 0) < 0) { + TVGERR("JPG LOADER", "%s", tjGetErrorStr()); + tjFree(image); + image = nullptr; + return false; + } + + //setup the surface + surface.buf8 = image; + surface.stride = w; + surface.w = w; + surface.h = h; + surface.channelSize = sizeof(uint32_t); + surface.premultiplied = true; + + clear(); + return true; +} diff --git a/components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.h b/components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.h new file mode 100644 index 0000000..c73a153 --- /dev/null +++ b/components/thorvg-main/src/loaders/external_jpg/tvgJpgLoader.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_JPG_LOADER_H_ +#define _TVG_JPG_LOADER_H_ + +#include "tvgLoader.h" + +using tjhandle = void*; + +//TODO: Use Task? +class JpgLoader : public ImageLoader +{ +public: + JpgLoader(); + ~JpgLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool read() override; + +private: + void clear(); + + tjhandle jpegDecompressor; + unsigned char* data = nullptr; + uint32_t size = 0; + bool freeData = false; +}; + +#endif //_TVG_JPG_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/external_png/meson.build b/components/thorvg-main/src/loaders/external_png/meson.build new file mode 100644 index 0000000..c188b9a --- /dev/null +++ b/components/thorvg-main/src/loaders/external_png/meson.build @@ -0,0 +1,14 @@ +source_file = [ + 'tvgPngLoader.h', + 'tvgPngLoader.cpp', +] + +png_dep = dependency('libpng', required: false) + +if png_dep.found() + subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + dependencies : png_dep, + sources : source_file + )] +endif diff --git a/components/thorvg-main/src/loaders/external_png/tvgPngLoader.cpp b/components/thorvg-main/src/loaders/external_png/tvgPngLoader.cpp new file mode 100644 index 0000000..c0eb493 --- /dev/null +++ b/components/thorvg-main/src/loaders/external_png/tvgPngLoader.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgPngLoader.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void PngLoader::clear() +{ + png_image_free(image); + tvg::free(image); + image = nullptr; +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +PngLoader::PngLoader() : ImageLoader(FileType::Png) +{ + image = tvg::calloc(1, sizeof(png_image)); + image->version = PNG_IMAGE_VERSION; + image->opaque = nullptr; +} + +PngLoader::~PngLoader() +{ + clear(); + tvg::free(surface.buf32); +} + + +bool PngLoader::open(const char* path) +{ + image->opaque = nullptr; + + if (!png_image_begin_read_from_file(image, path)) return false; + + w = (float)image->width; + h = (float)image->height; + + return true; +} + + +bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ +#ifdef THORVG_FILE_IO_SUPPORT + image->opaque = nullptr; + + if (!png_image_begin_read_from_memory(image, data, size)) return false; + + w = (float)image->width; + h = (float)image->height; + + return true; +#else + return false; +#endif +} + + +bool PngLoader::read() +{ + if (!LoadModule::read()) return true; + + if (w == 0 || h == 0) return false; + + if (ImageLoader::cs == ColorSpace::ARGB8888 || ImageLoader::cs == ColorSpace::ARGB8888S) { + image->format = PNG_FORMAT_BGRA; + surface.cs = ColorSpace::ARGB8888S; + } else { + image->format = PNG_FORMAT_RGBA; + surface.cs = ColorSpace::ABGR8888S; + } + + auto buffer = tvg::malloc(PNG_IMAGE_SIZE((*image))); + if (!png_image_finish_read(image, NULL, buffer, 0, NULL)) { + tvg::free(buffer); + return false; + } + + //setup the surface + surface.buf32 = reinterpret_cast(buffer); + surface.stride = (uint32_t)w; + surface.w = (uint32_t)w; + surface.h = (uint32_t)h; + surface.channelSize = sizeof(uint32_t); + //TODO: we can acquire a pre-multiplied image. See "png_structrp" + surface.premultiplied = false; + + clear(); + + return true; +} diff --git a/components/thorvg-main/src/loaders/external_png/tvgPngLoader.h b/components/thorvg-main/src/loaders/external_png/tvgPngLoader.h new file mode 100644 index 0000000..689ef2d --- /dev/null +++ b/components/thorvg-main/src/loaders/external_png/tvgPngLoader.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_PNG_LOADER_H_ +#define _TVG_PNG_LOADER_H_ + +#include +#include "tvgLoader.h" + +class PngLoader : public ImageLoader +{ +public: + PngLoader(); + ~PngLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool read() override; + +private: + void clear(); + + png_imagep image = nullptr; +}; + +#endif //_TVG_PNG_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/external_webp/meson.build b/components/thorvg-main/src/loaders/external_webp/meson.build new file mode 100644 index 0000000..69c3e33 --- /dev/null +++ b/components/thorvg-main/src/loaders/external_webp/meson.build @@ -0,0 +1,14 @@ +source_file = [ + 'tvgWebpLoader.h', + 'tvgWebpLoader.cpp', +] + +webp_dep = dependency('libwebp', required: false) + +if webp_dep.found() + subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + dependencies : webp_dep, + sources : source_file + )] +endif \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/external_webp/tvgWebpLoader.cpp b/components/thorvg-main/src/loaders/external_webp/tvgWebpLoader.cpp new file mode 100644 index 0000000..904f757 --- /dev/null +++ b/components/thorvg-main/src/loaders/external_webp/tvgWebpLoader.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +#include "tvgWebpLoader.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void WebpLoader::run(unsigned tid) +{ + //TODO: acquire the current colorspace format & pre-multiplied alpha image. + surface.buf8 = WebPDecodeBGRA(data, size, nullptr, nullptr); + surface.stride = (uint32_t)w; + surface.w = (uint32_t)w; + surface.h = (uint32_t)h; + surface.channelSize = sizeof(uint32_t); + surface.cs = ColorSpace::ARGB8888; + surface.premultiplied = false; + +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +WebpLoader::WebpLoader() : ImageLoader(FileType::Webp) +{ +} + + +WebpLoader::~WebpLoader() +{ + done(); + + if (freeData) tvg::free(data); + data = nullptr; + size = 0; + freeData = false; + WebPFree(surface.buf8); +} + + +bool WebpLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + if (!(data = (unsigned char*)LoadModule::open(path, size))) return false; + + int width, height; + if (!WebPGetInfo(data, size, &width, &height)) return false; + w = static_cast(width); + h = static_cast(height); + freeData = true; + return true; +#else + return false; +#endif +} + + +bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + if (copy) { + this->data = tvg::malloc(size); + if (!this->data) return false; + memcpy((unsigned char *)this->data, data, size); + freeData = true; + } else { + this->data = (unsigned char *) data; + freeData = false; + } + + int width, height; + if (!WebPGetInfo(this->data, size, &width, &height)) return false; + + w = static_cast(width); + h = static_cast(height); + surface.cs = ColorSpace::ARGB8888; + this->size = size; + return true; +} + + +bool WebpLoader::read() +{ + if (!LoadModule::read()) return true; + + if (!data || w == 0 || h == 0) return false; + + TaskScheduler::request(this); + + return true; +} + + +RenderSurface* WebpLoader::bitmap() +{ + this->done(); + + return ImageLoader::bitmap(); +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/external_webp/tvgWebpLoader.h b/components/thorvg-main/src/loaders/external_webp/tvgWebpLoader.h new file mode 100644 index 0000000..fc64738 --- /dev/null +++ b/components/thorvg-main/src/loaders/external_webp/tvgWebpLoader.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WEBP_LOADER_H_ +#define _TVG_WEBP_LOADER_H_ + +#include "tvgLoader.h" +#include "tvgTaskScheduler.h" + +class WebpLoader : public ImageLoader, public Task +{ +public: + WebpLoader(); + ~WebpLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool read() override; + + RenderSurface* bitmap() override; + +private: + void run(unsigned tid) override; + + unsigned char* data = nullptr; + uint32_t size = 0; + bool freeData = false; +}; + +#endif //_TVG_WEBP_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/jpg/meson.build b/components/thorvg-main/src/loaders/jpg/meson.build new file mode 100644 index 0000000..ff7e992 --- /dev/null +++ b/components/thorvg-main/src/loaders/jpg/meson.build @@ -0,0 +1,11 @@ +source_file = [ + 'tvgJpgd.h', + 'tvgJpgLoader.h', + 'tvgJpgd.cpp', + 'tvgJpgLoader.cpp', +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/jpg/tvgJpgLoader.cpp b/components/thorvg-main/src/loaders/jpg/tvgJpgLoader.cpp new file mode 100644 index 0000000..675568b --- /dev/null +++ b/components/thorvg-main/src/loaders/jpg/tvgJpgLoader.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgJpgLoader.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void JpgLoader::clear() +{ + jpgdDelete(decoder); + if (freeData) tvg::free(data); + decoder = nullptr; + data = nullptr; + freeData = false; +} + + +void JpgLoader::run(unsigned tid) +{ + surface.cs = ImageLoader::cs; + surface.buf8 = jpgdDecompress(decoder, surface.cs); + surface.stride = static_cast(w); + surface.w = static_cast(w); + surface.h = static_cast(h); + surface.channelSize = sizeof(uint32_t); + surface.premultiplied = true; + + clear(); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +JpgLoader::JpgLoader() : ImageLoader(FileType::Jpg) +{ + +} + + +JpgLoader::~JpgLoader() +{ + done(); + clear(); + tvg::free(surface.buf8); +} + + +bool JpgLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + int width, height; + if (!(decoder = jpgdHeader(path, &width, &height))) return false; + + w = static_cast(width); + h = static_cast(height); + + return true; +#else + return false; +#endif +} + + +bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + if (copy) { + this->data = tvg::malloc(size); + if (!this->data) return false; + memcpy((char *)this->data, data, size); + freeData = true; + } else { + this->data = (char *) data; + freeData = false; + } + + int width, height; + decoder = jpgdHeader(this->data, size, &width, &height); + if (!decoder) return false; + + w = static_cast(width); + h = static_cast(height); + + return true; +} + + + +bool JpgLoader::read() +{ + if (!LoadModule::read()) return true; + + if (!decoder || w == 0 || h == 0) return false; + + TaskScheduler::request(this); + + return true; +} + + +bool JpgLoader::close() +{ + if (!LoadModule::close()) return false; + this->done(); + return true; +} + + +RenderSurface* JpgLoader::bitmap() +{ + this->done(); + return ImageLoader::bitmap(); +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/jpg/tvgJpgLoader.h b/components/thorvg-main/src/loaders/jpg/tvgJpgLoader.h new file mode 100644 index 0000000..35798ab --- /dev/null +++ b/components/thorvg-main/src/loaders/jpg/tvgJpgLoader.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_JPG_LOADER_H_ +#define _TVG_JPG_LOADER_H_ + +#include "tvgLoader.h" +#include "tvgTaskScheduler.h" +#include "tvgJpgd.h" + +class JpgLoader : public ImageLoader, public Task +{ +private: + jpeg_decoder* decoder = nullptr; + char* data = nullptr; + bool freeData = false; + + void clear(); + void run(unsigned tid) override; + +public: + JpgLoader(); + ~JpgLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool read() override; + bool close() override; + + RenderSurface* bitmap() override; +}; + +#endif //_TVG_JPG_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/jpg/tvgJpgd.cpp b/components/thorvg-main/src/loaders/jpg/tvgJpgd.cpp new file mode 100644 index 0000000..9ebcc50 --- /dev/null +++ b/components/thorvg-main/src/loaders/jpg/tvgJpgd.cpp @@ -0,0 +1,2520 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include +#include +#include + +#include "tvgCommon.h" +#include "tvgJpgd.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define JPGD_MAX(a,b) (((a)>(b)) ? (a) : (b)) +#define JPGD_MIN(a,b) (((a)<(b)) ? (a) : (b)) + +typedef int16_t jpgd_quant_t; +typedef int16_t jpgd_block_t; + +// Success/failure error codes. +enum jpgd_status +{ + JPGD_SUCCESS = 0, JPGD_FAILED = -1, JPGD_DONE = 1, + JPGD_BAD_DHT_COUNTS = -256, JPGD_BAD_DHT_INDEX, JPGD_BAD_DHT_MARKER, JPGD_BAD_DQT_MARKER, JPGD_BAD_DQT_TABLE, + JPGD_BAD_PRECISION, JPGD_BAD_HEIGHT, JPGD_BAD_WIDTH, JPGD_TOO_MANY_COMPONENTS, + JPGD_BAD_SOF_LENGTH, JPGD_BAD_VARIABLE_MARKER, JPGD_BAD_DRI_LENGTH, JPGD_BAD_SOS_LENGTH, + JPGD_BAD_SOS_COMP_ID, JPGD_W_EXTRA_BYTES_BEFORE_MARKER, JPGD_NO_ARITHMETIC_SUPPORT, JPGD_UNEXPECTED_MARKER, + JPGD_NOT_JPEG, JPGD_UNSUPPORTED_MARKER, JPGD_BAD_DQT_LENGTH, JPGD_TOO_MANY_BLOCKS, + JPGD_UNDEFINED_QUANT_TABLE, JPGD_UNDEFINED_HUFF_TABLE, JPGD_NOT_SINGLE_SCAN, JPGD_UNSUPPORTED_COLORSPACE, + JPGD_UNSUPPORTED_SAMP_FACTORS, JPGD_DECODE_ERROR, JPGD_BAD_RESTART_MARKER, JPGD_ASSERTION_ERROR, + JPGD_BAD_SOS_SPECTRAL, JPGD_BAD_SOS_SUCCESSIVE, JPGD_STREAM_READ, JPGD_NOTENOUGHMEM +}; + +enum +{ + JPGD_IN_BUF_SIZE = 8192, JPGD_MAX_BLOCKS_PER_MCU = 10, JPGD_MAX_HUFF_TABLES = 8, JPGD_MAX_QUANT_TABLES = 4, + JPGD_MAX_COMPONENTS = 4, JPGD_MAX_COMPS_IN_SCAN = 4, JPGD_MAX_BLOCKS_PER_ROW = 8192, JPGD_MAX_HEIGHT = 16384, JPGD_MAX_WIDTH = 16384 +}; + +// Input stream interface. +// Derive from this class to read input data from sources other than files or memory. Set m_eof_flag to true when no more data is available. +// The decoder is rather greedy: it will keep on calling this method until its internal input buffer is full, or until the EOF flag is set. +// It the input stream contains data after the JPEG stream's EOI (end of image) marker it will probably be pulled into the internal buffer. +// Call the get_total_bytes_read() method to determine the actual size of the JPEG stream after successful decoding. +struct jpeg_decoder_stream +{ + jpeg_decoder_stream() { } + virtual ~jpeg_decoder_stream() { } + + // The read() method is called when the internal input buffer is empty. + // Parameters: + // pBuf - input buffer + // max_bytes_to_read - maximum bytes that can be written to pBuf + // pEOF_flag - set this to true if at end of stream (no more bytes remaining) + // Returns -1 on error, otherwise return the number of bytes actually written to the buffer (which may be 0). + // Notes: This method will be called in a loop until you set *pEOF_flag to true or the internal buffer is full. + virtual int read(uint8_t *pBuf, int max_bytes_to_read, bool *pEOF_flag) = 0; +}; + + +// stdio FILE stream class. +class jpeg_decoder_file_stream : public jpeg_decoder_stream +{ + jpeg_decoder_file_stream(const jpeg_decoder_file_stream &); + jpeg_decoder_file_stream &operator =(const jpeg_decoder_file_stream &); + + FILE *m_pFile = nullptr; + bool m_eof_flag = false; + bool m_error_flag = false; + +public: + jpeg_decoder_file_stream() {} + virtual ~jpeg_decoder_file_stream(); + bool open(const char *Pfilename); + void close(); + virtual int read(uint8_t *pBuf, int max_bytes_to_read, bool *pEOF_flag); + }; + + +// Memory stream class. +class jpeg_decoder_mem_stream : public jpeg_decoder_stream +{ + const uint8_t *m_pSrc_data; + uint32_t m_ofs, m_size; + +public: + jpeg_decoder_mem_stream() : m_pSrc_data(nullptr), m_ofs(0), m_size(0) {} + jpeg_decoder_mem_stream(const uint8_t *pSrc_data, uint32_t size) : m_pSrc_data(pSrc_data), m_ofs(0), m_size(size) {} + virtual ~jpeg_decoder_mem_stream() {} + bool open(const uint8_t *pSrc_data, uint32_t size); + void close() { m_pSrc_data = nullptr; m_ofs = 0; m_size = 0; } + virtual int read(uint8_t *pBuf, int max_bytes_to_read, bool *pEOF_flag); +}; + + +class jpeg_decoder +{ +public: + // Call get_error_code() after constructing to determine if the stream is valid or not. You may call the get_width(), get_height(), etc. + // methods after the constructor is called. You may then either destruct the object, or begin decoding the image by calling begin_decoding(), then decode() on each scanline. + jpeg_decoder(jpeg_decoder_stream *pStream); + ~jpeg_decoder(); + + // Call this method after constructing the object to begin decompression. + // If JPGD_SUCCESS is returned you may then call decode() on each scanline. + int begin_decoding(); + // Returns the next scan line. + // For grayscale images, pScan_line will point to a buffer containing 8-bit pixels (get_bytes_per_pixel() will return 1). + // Otherwise, it will always point to a buffer containing 32-bit RGBA pixels (A will always be 255, and get_bytes_per_pixel() will return 4). + // Returns JPGD_SUCCESS if a scan line has been returned. + // Returns JPGD_DONE if all scan lines have been returned. + // Returns JPGD_FAILED if an error occurred. Call get_error_code() for a more info. + int decode(const void** pScan_line); + inline jpgd_status get_error_code() const { return m_error_code; } + inline int get_width() const { return m_image_x_size; } + inline int get_height() const { return m_image_y_size; } + inline int get_num_components() const { return m_comps_in_frame; } + inline int get_bytes_per_pixel() const { return m_dest_bytes_per_pixel; } + inline int get_bytes_per_scan_line() const { return m_image_x_size * get_bytes_per_pixel(); } + // Returns the total number of bytes actually consumed by the decoder (which should equal the actual size of the JPEG file). + inline int get_total_bytes_read() const { return m_total_bytes_read; } + +private: + jpeg_decoder(const jpeg_decoder &); + jpeg_decoder &operator =(const jpeg_decoder &); + + typedef bool (*pDecode_block_func)(jpeg_decoder*, int, int, int); + + struct huff_tables + { + bool ac_table; + uint32_t look_up[256]; + uint32_t look_up2[256]; + uint8_t code_size[256]; + uint32_t tree[512]; + }; + + struct coeff_buf + { + uint8_t *pData; + int block_num_x, block_num_y; + int block_len_x, block_len_y; + int block_size; + }; + + struct mem_block + { + mem_block *m_pNext; + size_t m_used_count; + size_t m_size; + char m_data[1]; + }; + + mem_block *m_pMem_blocks; + int m_image_x_size; + int m_image_y_size; + jpeg_decoder_stream *m_pStream; + int m_progressive_flag; + uint8_t m_huff_ac[JPGD_MAX_HUFF_TABLES]; + uint8_t* m_huff_num[JPGD_MAX_HUFF_TABLES]; // pointer to number of Huffman codes per bit size + uint8_t* m_huff_val[JPGD_MAX_HUFF_TABLES]; // pointer to Huffman codes per bit size + jpgd_quant_t* m_quant[JPGD_MAX_QUANT_TABLES]; // pointer to quantization tables + int m_scan_type; // Gray, Yh1v1, Yh1v2, Yh2v1, Yh2v2 (CMYK111, CMYK4114 no longer supported) + int m_comps_in_frame; // # of components in frame + int m_comp_h_samp[JPGD_MAX_COMPONENTS]; // component's horizontal sampling factor + int m_comp_v_samp[JPGD_MAX_COMPONENTS]; // component's vertical sampling factor + int m_comp_quant[JPGD_MAX_COMPONENTS]; // component's quantization table selector + int m_comp_ident[JPGD_MAX_COMPONENTS]; // component's ID + int m_comp_h_blocks[JPGD_MAX_COMPONENTS]; + int m_comp_v_blocks[JPGD_MAX_COMPONENTS]; + int m_comps_in_scan; // # of components in scan + int m_comp_list[JPGD_MAX_COMPS_IN_SCAN]; // components in this scan + int m_comp_dc_tab[JPGD_MAX_COMPONENTS]; // component's DC Huffman coding table selector + int m_comp_ac_tab[JPGD_MAX_COMPONENTS]; // component's AC Huffman coding table selector + int m_spectral_start; // spectral selection start + int m_spectral_end; // spectral selection end + int m_successive_low; // successive approximation low + int m_successive_high; // successive approximation high + int m_max_mcu_x_size; // MCU's max. X size in pixels + int m_max_mcu_y_size; // MCU's max. Y size in pixels + int m_blocks_per_mcu; + int m_max_blocks_per_row; + int m_mcus_per_row, m_mcus_per_col; + int m_mcu_org[JPGD_MAX_BLOCKS_PER_MCU]; + int m_total_lines_left; // total # lines left in image + int m_mcu_lines_left; // total # lines left in this MCU + int m_real_dest_bytes_per_scan_line; + int m_dest_bytes_per_scan_line; // rounded up + int m_dest_bytes_per_pixel; // 4 (RGB) or 1 (Y) + huff_tables* m_pHuff_tabs[JPGD_MAX_HUFF_TABLES]; + coeff_buf* m_dc_coeffs[JPGD_MAX_COMPONENTS]; + coeff_buf* m_ac_coeffs[JPGD_MAX_COMPONENTS]; + int m_eob_run; + int m_block_y_mcu[JPGD_MAX_COMPONENTS]; + uint8_t* m_pIn_buf_ofs; + int m_in_buf_left; + int m_tem_flag; + bool m_eof_flag; + uint8_t m_in_buf_pad_start[128]; + uint8_t m_in_buf[JPGD_IN_BUF_SIZE + 128]; + uint8_t m_in_buf_pad_end[128]; + int m_bits_left; + uint32_t m_bit_buf; + int m_restart_interval; + int m_restarts_left; + int m_next_restart_num; + int m_max_mcus_per_row; + int m_max_blocks_per_mcu; + int m_expanded_blocks_per_mcu; + int m_expanded_blocks_per_row; + int m_expanded_blocks_per_component; + int m_max_mcus_per_col; + uint32_t m_last_dc_val[JPGD_MAX_COMPONENTS]; + jpgd_block_t* m_pMCU_coefficients; + int m_mcu_block_max_zag[JPGD_MAX_BLOCKS_PER_MCU]; + uint8_t* m_pSample_buf; + int m_crr[256]; + int m_cbb[256]; + int m_crg[256]; + int m_cbg[256]; + uint8_t* m_pScan_line_0; + uint8_t* m_pScan_line_1; + jpgd_status m_error_code; + bool m_ready_flag; + int m_total_bytes_read; + + void free_all_blocks(); + bool stop_decoding(jpgd_status status); + void *alloc(size_t n, bool zero = false); + void word_clear(void *p, uint16_t c, uint32_t n); + bool prep_in_buffer(); + bool read_dht_marker(); + bool read_dqt_marker(); + bool read_sof_marker(); + bool skip_variable_marker(); + bool read_dri_marker(); + bool read_sos_marker(); + int next_marker(); + int process_markers(); + bool locate_soi_marker(); + bool locate_sof_marker(); + bool locate_sos_marker(); + void init(jpeg_decoder_stream * pStream); + void create_look_ups(); + void fix_in_buffer(); + void transform_mcu(int mcu_row); + coeff_buf* coeff_buf_open(int block_num_x, int block_num_y, int block_len_x, int block_len_y); + inline jpgd_block_t *coeff_buf_getp(coeff_buf *cb, int block_x, int block_y); + void load_next_row(); + bool decode_next_row(); + void make_huff_table(int index, huff_tables *pH); + bool check_quant_tables(); + bool check_huff_tables(); + void calc_mcu_block_order(); + int init_scan(); + bool init_frame(); + bool process_restart(); + bool decode_scan(pDecode_block_func decode_block_func); + bool init_progressive(); + bool init_sequential(); + bool decode_start(); + void decode_init(jpeg_decoder_stream * pStream); + void H2V2Convert(); + void H2V1Convert(); + void H1V2Convert(); + void H1V1Convert(); + void gray_convert(); + void find_eoi(); + inline uint32_t get_char(); + inline uint32_t get_char(bool *pPadding_flag); + inline void stuff_char(uint8_t q); + inline uint8_t get_octet(); + inline uint32_t get_bits(int num_bits); + inline uint32_t get_bits_no_markers(int numbits); + inline int huff_decode(huff_tables *pH); + inline int huff_decode(huff_tables *pH, int& extrabits); + static inline uint8_t clamp(int i); + static bool decode_block_dc_first(jpeg_decoder *pD, int component_id, int block_x, int block_y); + static bool decode_block_dc_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y); + static bool decode_block_ac_first(jpeg_decoder *pD, int component_id, int block_x, int block_y); + static bool decode_block_ac_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y); +}; + + +// DCT coefficients are stored in this sequence. +static int g_ZAG[64] = { 0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63 }; + +enum JPEG_MARKER +{ + M_SOF0 = 0xC0, M_SOF1 = 0xC1, M_SOF2 = 0xC2, M_SOF3 = 0xC3, M_SOF5 = 0xC5, M_SOF6 = 0xC6, M_SOF7 = 0xC7, M_JPG = 0xC8, + M_SOF9 = 0xC9, M_SOF10 = 0xCA, M_SOF11 = 0xCB, M_SOF13 = 0xCD, M_SOF14 = 0xCE, M_SOF15 = 0xCF, M_DHT = 0xC4, M_DAC = 0xCC, + M_RST0 = 0xD0, M_RST1 = 0xD1, M_RST2 = 0xD2, M_RST3 = 0xD3, M_RST4 = 0xD4, M_RST5 = 0xD5, M_RST6 = 0xD6, M_RST7 = 0xD7, + M_SOI = 0xD8, M_EOI = 0xD9, M_SOS = 0xDA, M_DQT = 0xDB, M_DNL = 0xDC, M_DRI = 0xDD, M_DHP = 0xDE, M_EXP = 0xDF, + M_APP0 = 0xE0, M_APP15 = 0xEF, M_JPG0 = 0xF0, M_JPG13 = 0xFD, M_COM = 0xFE, M_TEM = 0x01, M_ERROR = 0x100, RST0 = 0xD0 +}; + +enum JPEG_SUBSAMPLING { JPGD_GRAYSCALE = 0, JPGD_YH1V1, JPGD_YH2V1, JPGD_YH1V2, JPGD_YH2V2 }; + +#define CONST_BITS 13 +#define PASS1_BITS 2 +#define SCALEDONE ((int32_t)1) +#define DESCALE(x,n) (((x) + (SCALEDONE << ((n)-1))) >> (n)) +#define DESCALE_ZEROSHIFT(x,n) (((x) + (128 << (n)) + (SCALEDONE << ((n)-1))) >> (n)) +#define MULTIPLY(var, cnst) ((var) * (cnst)) +#define CLAMP(i) ((static_cast(i) > 255) ? (((~i) >> 31) & 0xFF) : (i)) + +#define FIX_0_298631336 ((int32_t)2446) /* FIX(0.298631336) */ +#define FIX_0_390180644 ((int32_t)3196) /* FIX(0.390180644) */ +#define FIX_0_541196100 ((int32_t)4433) /* FIX(0.541196100) */ +#define FIX_0_765366865 ((int32_t)6270) /* FIX(0.765366865) */ +#define FIX_0_899976223 ((int32_t)7373) /* FIX(0.899976223) */ +#define FIX_1_175875602 ((int32_t)9633) /* FIX(1.175875602) */ +#define FIX_1_501321110 ((int32_t)12299) /* FIX(1.501321110) */ +#define FIX_1_847759065 ((int32_t)15137) /* FIX(1.847759065) */ +#define FIX_1_961570560 ((int32_t)16069) /* FIX(1.961570560) */ +#define FIX_2_053119869 ((int32_t)16819) /* FIX(2.053119869) */ +#define FIX_2_562915447 ((int32_t)20995) /* FIX(2.562915447) */ +#define FIX_3_072711026 ((int32_t)25172) /* FIX(3.072711026) */ + + +// Compiler creates a fast path 1D IDCT for X non-zero columns +template +struct Row +{ + static void idct(int* pTemp, const jpgd_block_t* pSrc) + { + // ACCESS_COL() will be optimized at compile time to either an array access, or 0. + #define ACCESS_COL(x) (((x) < NONZERO_COLS) ? (int)pSrc[x] : 0) + + const int z2 = ACCESS_COL(2), z3 = ACCESS_COL(6); + const int z1 = MULTIPLY(z2 + z3, FIX_0_541196100); + const int tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); + const int tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + + const int tmp0 = static_cast(ACCESS_COL(0) + ACCESS_COL(4)) << CONST_BITS; + const int tmp1 = static_cast(ACCESS_COL(0) - ACCESS_COL(4)) << CONST_BITS; + + const int tmp10 = tmp0 + tmp3, tmp13 = tmp0 - tmp3, tmp11 = tmp1 + tmp2, tmp12 = tmp1 - tmp2; + + const int atmp0 = ACCESS_COL(7), atmp1 = ACCESS_COL(5), atmp2 = ACCESS_COL(3), atmp3 = ACCESS_COL(1); + + const int bz1 = atmp0 + atmp3, bz2 = atmp1 + atmp2, bz3 = atmp0 + atmp2, bz4 = atmp1 + atmp3; + const int bz5 = MULTIPLY(bz3 + bz4, FIX_1_175875602); + + const int az1 = MULTIPLY(bz1, - FIX_0_899976223); + const int az2 = MULTIPLY(bz2, - FIX_2_562915447); + const int az3 = MULTIPLY(bz3, - FIX_1_961570560) + bz5; + const int az4 = MULTIPLY(bz4, - FIX_0_390180644) + bz5; + + const int btmp0 = MULTIPLY(atmp0, FIX_0_298631336) + az1 + az3; + const int btmp1 = MULTIPLY(atmp1, FIX_2_053119869) + az2 + az4; + const int btmp2 = MULTIPLY(atmp2, FIX_3_072711026) + az2 + az3; + const int btmp3 = MULTIPLY(atmp3, FIX_1_501321110) + az1 + az4; + + pTemp[0] = DESCALE(tmp10 + btmp3, CONST_BITS-PASS1_BITS); + pTemp[7] = DESCALE(tmp10 - btmp3, CONST_BITS-PASS1_BITS); + pTemp[1] = DESCALE(tmp11 + btmp2, CONST_BITS-PASS1_BITS); + pTemp[6] = DESCALE(tmp11 - btmp2, CONST_BITS-PASS1_BITS); + pTemp[2] = DESCALE(tmp12 + btmp1, CONST_BITS-PASS1_BITS); + pTemp[5] = DESCALE(tmp12 - btmp1, CONST_BITS-PASS1_BITS); + pTemp[3] = DESCALE(tmp13 + btmp0, CONST_BITS-PASS1_BITS); + pTemp[4] = DESCALE(tmp13 - btmp0, CONST_BITS-PASS1_BITS); + } +}; + + +template <> +struct Row<0> +{ + static void idct(int* pTemp, const jpgd_block_t* pSrc) + { +#ifdef _MSC_VER + pTemp; pSrc; +#endif + } +}; + + +template <> +struct Row<1> +{ + static void idct(int* pTemp, const jpgd_block_t* pSrc) + { + const int dcval = pSrc[0] * PASS1_BITS * 2; + + pTemp[0] = dcval; + pTemp[1] = dcval; + pTemp[2] = dcval; + pTemp[3] = dcval; + pTemp[4] = dcval; + pTemp[5] = dcval; + pTemp[6] = dcval; + pTemp[7] = dcval; + } +}; + + +// Compiler creates a fast path 1D IDCT for X non-zero rows +template +struct Col +{ + static void idct(uint8_t* pDst_ptr, const int* pTemp) + { + // ACCESS_ROW() will be optimized at compile time to either an array access, or 0. + #define ACCESS_ROW(x) (((x) < NONZERO_ROWS) ? pTemp[x * 8] : 0) + + const int z2 = ACCESS_ROW(2); + const int z3 = ACCESS_ROW(6); + + const int z1 = MULTIPLY(z2 + z3, FIX_0_541196100); + const int tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); + const int tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + + const int tmp0 = static_cast(ACCESS_ROW(0) + ACCESS_ROW(4)) << CONST_BITS; + const int tmp1 = static_cast(ACCESS_ROW(0) - ACCESS_ROW(4)) << CONST_BITS; + + const int tmp10 = tmp0 + tmp3, tmp13 = tmp0 - tmp3, tmp11 = tmp1 + tmp2, tmp12 = tmp1 - tmp2; + + const int atmp0 = ACCESS_ROW(7), atmp1 = ACCESS_ROW(5), atmp2 = ACCESS_ROW(3), atmp3 = ACCESS_ROW(1); + + const int bz1 = atmp0 + atmp3, bz2 = atmp1 + atmp2, bz3 = atmp0 + atmp2, bz4 = atmp1 + atmp3; + const int bz5 = MULTIPLY(bz3 + bz4, FIX_1_175875602); + + const int az1 = MULTIPLY(bz1, - FIX_0_899976223); + const int az2 = MULTIPLY(bz2, - FIX_2_562915447); + const int az3 = MULTIPLY(bz3, - FIX_1_961570560) + bz5; + const int az4 = MULTIPLY(bz4, - FIX_0_390180644) + bz5; + + const int btmp0 = MULTIPLY(atmp0, FIX_0_298631336) + az1 + az3; + const int btmp1 = MULTIPLY(atmp1, FIX_2_053119869) + az2 + az4; + const int btmp2 = MULTIPLY(atmp2, FIX_3_072711026) + az2 + az3; + const int btmp3 = MULTIPLY(atmp3, FIX_1_501321110) + az1 + az4; + + int i = DESCALE_ZEROSHIFT(tmp10 + btmp3, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*0] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp10 - btmp3, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*7] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp11 + btmp2, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*1] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp11 - btmp2, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*6] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp12 + btmp1, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*2] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp12 - btmp1, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*5] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp13 + btmp0, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*3] = (uint8_t)CLAMP(i); + + i = DESCALE_ZEROSHIFT(tmp13 - btmp0, CONST_BITS+PASS1_BITS+3); + pDst_ptr[8*4] = (uint8_t)CLAMP(i); + } +}; + + +template <> +struct Col<1> +{ + static void idct(uint8_t* pDst_ptr, const int* pTemp) + { + int dcval = DESCALE_ZEROSHIFT(pTemp[0], PASS1_BITS+3); + const uint8_t dcval_clamped = (uint8_t)CLAMP(dcval); + pDst_ptr[0*8] = dcval_clamped; + pDst_ptr[1*8] = dcval_clamped; + pDst_ptr[2*8] = dcval_clamped; + pDst_ptr[3*8] = dcval_clamped; + pDst_ptr[4*8] = dcval_clamped; + pDst_ptr[5*8] = dcval_clamped; + pDst_ptr[6*8] = dcval_clamped; + pDst_ptr[7*8] = dcval_clamped; + } +}; + + +static const uint8_t s_idct_row_table[] = { + 1,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0, 2,1,0,0,0,0,0,0, 2,1,1,0,0,0,0,0, 2,2,1,0,0,0,0,0, 3,2,1,0,0,0,0,0, 4,2,1,0,0,0,0,0, 4,3,1,0,0,0,0,0, + 4,3,2,0,0,0,0,0, 4,3,2,1,0,0,0,0, 4,3,2,1,1,0,0,0, 4,3,2,2,1,0,0,0, 4,3,3,2,1,0,0,0, 4,4,3,2,1,0,0,0, 5,4,3,2,1,0,0,0, 6,4,3,2,1,0,0,0, + 6,5,3,2,1,0,0,0, 6,5,4,2,1,0,0,0, 6,5,4,3,1,0,0,0, 6,5,4,3,2,0,0,0, 6,5,4,3,2,1,0,0, 6,5,4,3,2,1,1,0, 6,5,4,3,2,2,1,0, 6,5,4,3,3,2,1,0, + 6,5,4,4,3,2,1,0, 6,5,5,4,3,2,1,0, 6,6,5,4,3,2,1,0, 7,6,5,4,3,2,1,0, 8,6,5,4,3,2,1,0, 8,7,5,4,3,2,1,0, 8,7,6,4,3,2,1,0, 8,7,6,5,3,2,1,0, + 8,7,6,5,4,2,1,0, 8,7,6,5,4,3,1,0, 8,7,6,5,4,3,2,0, 8,7,6,5,4,3,2,1, 8,7,6,5,4,3,2,2, 8,7,6,5,4,3,3,2, 8,7,6,5,4,4,3,2, 8,7,6,5,5,4,3,2, + 8,7,6,6,5,4,3,2, 8,7,7,6,5,4,3,2, 8,8,7,6,5,4,3,2, 8,8,8,6,5,4,3,2, 8,8,8,7,5,4,3,2, 8,8,8,7,6,4,3,2, 8,8,8,7,6,5,3,2, 8,8,8,7,6,5,4,2, + 8,8,8,7,6,5,4,3, 8,8,8,7,6,5,4,4, 8,8,8,7,6,5,5,4, 8,8,8,7,6,6,5,4, 8,8,8,7,7,6,5,4, 8,8,8,8,7,6,5,4, 8,8,8,8,8,6,5,4, 8,8,8,8,8,7,5,4, + 8,8,8,8,8,7,6,4, 8,8,8,8,8,7,6,5, 8,8,8,8,8,7,6,6, 8,8,8,8,8,7,7,6, 8,8,8,8,8,8,7,6, 8,8,8,8,8,8,8,6, 8,8,8,8,8,8,8,7, 8,8,8,8,8,8,8,8, +}; + + +static const uint8_t s_idct_col_table[] = { 1, 1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; + + +void idct(const jpgd_block_t* pSrc_ptr, uint8_t* pDst_ptr, int block_max_zag) +{ + if (block_max_zag <= 1) { + int k = ((pSrc_ptr[0] + 4) >> 3) + 128; + k = CLAMP(k); + k = k | (k<<8); + k = k | (k<<16); + for (int i = 8; i > 0; i--) { + *(int*)&pDst_ptr[0] = k; + *(int*)&pDst_ptr[4] = k; + pDst_ptr += 8; + } + return; + } + + int temp[64]; + const jpgd_block_t* pSrc = pSrc_ptr; + int* pTemp = temp; + const uint8_t* pRow_tab = &s_idct_row_table[(block_max_zag - 1) * 8]; + int i; + for (i = 8; i > 0; i--, pRow_tab++) { + switch (*pRow_tab) { + case 0: Row<0>::idct(pTemp, pSrc); break; + case 1: Row<1>::idct(pTemp, pSrc); break; + case 2: Row<2>::idct(pTemp, pSrc); break; + case 3: Row<3>::idct(pTemp, pSrc); break; + case 4: Row<4>::idct(pTemp, pSrc); break; + case 5: Row<5>::idct(pTemp, pSrc); break; + case 6: Row<6>::idct(pTemp, pSrc); break; + case 7: Row<7>::idct(pTemp, pSrc); break; + case 8: Row<8>::idct(pTemp, pSrc); break; + } + pSrc += 8; + pTemp += 8; + } + + pTemp = temp; + + const int nonzero_rows = s_idct_col_table[block_max_zag - 1]; + for (i = 8; i > 0; i--) { + switch (nonzero_rows) { + case 1: Col<1>::idct(pDst_ptr, pTemp); break; + case 2: Col<2>::idct(pDst_ptr, pTemp); break; + case 3: Col<3>::idct(pDst_ptr, pTemp); break; + case 4: Col<4>::idct(pDst_ptr, pTemp); break; + case 5: Col<5>::idct(pDst_ptr, pTemp); break; + case 6: Col<6>::idct(pDst_ptr, pTemp); break; + case 7: Col<7>::idct(pDst_ptr, pTemp); break; + case 8: Col<8>::idct(pDst_ptr, pTemp); break; + } + pTemp++; + pDst_ptr++; + } +} + + +// Retrieve one character from the input stream. +inline uint32_t jpeg_decoder::get_char() +{ + // Any bytes remaining in buffer? + if (!m_in_buf_left) { + // Try to get more bytes. + if (!prep_in_buffer()) return 0xFF; + // Still nothing to get? + if (!m_in_buf_left) { + // Pad the end of the stream with 0xFF 0xD9 (EOI marker) + int t = m_tem_flag; + m_tem_flag ^= 1; + if (t) return 0xD9; + else return 0xFF; + } + } + uint32_t c = *m_pIn_buf_ofs++; + m_in_buf_left--; + return c; +} + + +// Same as previous method, except can indicate if the character is a pad character or not. +inline uint32_t jpeg_decoder::get_char(bool *pPadding_flag) +{ + if (!m_in_buf_left) { + if (!prep_in_buffer()) { + *pPadding_flag = false; + return 0xFF; + } + if (!m_in_buf_left) { + *pPadding_flag = true; + int t = m_tem_flag; + m_tem_flag ^= 1; + if (t) return 0xD9; + else return 0xFF; + } + } + *pPadding_flag = false; + uint32_t c = *m_pIn_buf_ofs++; + m_in_buf_left--; + + return c; +} + + +// Inserts a previously retrieved character back into the input buffer. +inline void jpeg_decoder::stuff_char(uint8_t q) +{ + *(--m_pIn_buf_ofs) = q; + m_in_buf_left++; +} + + +// Retrieves one character from the input stream, but does not read past markers. Will continue to return 0xFF when a marker is encountered. +inline uint8_t jpeg_decoder::get_octet() +{ + bool padding_flag; + int c = get_char(&padding_flag); + + if (c == 0xFF) { + if (padding_flag) return 0xFF; + + c = get_char(&padding_flag); + if (padding_flag) { + stuff_char(0xFF); + return 0xFF; + } + if (c == 0x00) return 0xFF; + else { + stuff_char(static_cast(c)); + stuff_char(0xFF); + return 0xFF; + } + } + return static_cast(c); +} + + +// Retrieves a variable number of bits from the input stream. Does not recognize markers. +inline uint32_t jpeg_decoder::get_bits(int num_bits) +{ + if (!num_bits) return 0; + + uint32_t i = m_bit_buf >> (32 - num_bits); + + if ((m_bits_left -= num_bits) <= 0) { + m_bit_buf <<= (num_bits += m_bits_left); + uint32_t c1 = get_char(); + uint32_t c2 = get_char(); + m_bit_buf = (m_bit_buf & 0xFFFF0000) | (c1 << 8) | c2; + m_bit_buf <<= -m_bits_left; + m_bits_left += 16; + } + else m_bit_buf <<= num_bits; + + return i; +} + + +// Retrieves a variable number of bits from the input stream. Markers will not be read into the input bit buffer. Instead, an infinite number of all 1's will be returned when a marker is encountered. +inline uint32_t jpeg_decoder::get_bits_no_markers(int num_bits) +{ + if (!num_bits)return 0; + + uint32_t i = m_bit_buf >> (32 - num_bits); + + if ((m_bits_left -= num_bits) <= 0) { + m_bit_buf <<= (num_bits += m_bits_left); + if ((m_in_buf_left < 2) || (m_pIn_buf_ofs[0] == 0xFF) || (m_pIn_buf_ofs[1] == 0xFF)) { + uint32_t c1 = get_octet(); + uint32_t c2 = get_octet(); + m_bit_buf |= (c1 << 8) | c2; + } else { + m_bit_buf |= ((uint32_t)m_pIn_buf_ofs[0] << 8) | m_pIn_buf_ofs[1]; + m_in_buf_left -= 2; + m_pIn_buf_ofs += 2; + } + m_bit_buf <<= -m_bits_left; + m_bits_left += 16; + } else m_bit_buf <<= num_bits; + + return i; +} + + +// Decodes a Huffman encoded symbol. +inline int jpeg_decoder::huff_decode(huff_tables *pH) +{ + int symbol; + + // Check first 8-bits: do we have a complete symbol? + if ((symbol = pH->look_up[m_bit_buf >> 24]) < 0) { + // Decode more bits, use a tree traversal to find symbol. + int ofs = 23; + do { + symbol = pH->tree[-(int)(symbol + ((m_bit_buf >> ofs) & 1))]; + ofs--; + } while (symbol < 0); + get_bits_no_markers(8 + (23 - ofs)); + } else get_bits_no_markers(pH->code_size[symbol]); + + return symbol; +} + + +// Decodes a Huffman encoded symbol. +inline int jpeg_decoder::huff_decode(huff_tables *pH, int& extra_bits) +{ + int symbol; + + // Check first 8-bits: do we have a complete symbol? + if ((symbol = pH->look_up2[m_bit_buf >> 24]) < 0) { + // Use a tree traversal to find symbol. + int ofs = 23; + do { + symbol = pH->tree[-(int)(symbol + ((m_bit_buf >> ofs) & 1))]; + ofs--; + } while (symbol < 0); + + get_bits_no_markers(8 + (23 - ofs)); + extra_bits = get_bits_no_markers(symbol & 0xF); + } else { + if (symbol & 0x8000) { + get_bits_no_markers((symbol >> 8) & 31); + extra_bits = symbol >> 16; + } else { + int code_size = (symbol >> 8) & 31; + int num_extra_bits = symbol & 0xF; + int bits = code_size + num_extra_bits; + if (bits <= (m_bits_left + 16)) extra_bits = get_bits_no_markers(bits) & ((1 << num_extra_bits) - 1); + else { + get_bits_no_markers(code_size); + extra_bits = get_bits_no_markers(num_extra_bits); + } + } + symbol &= 0xFF; + } + return symbol; +} + + +// Tables and macro used to fully decode the DPCM differences. +static const int s_extend_test[16] = { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; +static const unsigned int s_extend_offset[16] = { 0, ((~0u)<<1) + 1, ((~0u)<<2) + 1, ((~0u)<<3) + 1, ((~0u)<<4) + 1, ((~0u)<<5) + 1, ((~0u)<<6) + 1, ((~0u)<<7) + 1, ((~0u)<<8) + 1, ((~0u)<<9) + 1, ((~0u)<<10) + 1, ((~0u)<<11) + 1, ((~0u)<<12) + 1, ((~0u)<<13) + 1, ((~0u)<<14) + 1, ((~0u)<<15) + 1 }; + +// The logical AND's in this macro are to shut up static code analysis (aren't really necessary - couldn't find another way to do this) +#define JPGD_HUFF_EXTEND(x, s) (((x) < s_extend_test[s & 15]) ? ((x) + s_extend_offset[s & 15]) : (x)) + + +// Clamps a value between 0-255. +inline uint8_t jpeg_decoder::clamp(int i) +{ + if (static_cast(i) > 255) i = (((~i) >> 31) & 0xFF); + return static_cast(i); +} + + +// Unconditionally frees all allocated m_blocks. +void jpeg_decoder::free_all_blocks() +{ + delete(m_pStream); + m_pStream = nullptr; + + for (mem_block *b = m_pMem_blocks; b; ) { + mem_block *n = b->m_pNext; + tvg::free(b); + b = n; + } + m_pMem_blocks = nullptr; +} + + +bool jpeg_decoder::stop_decoding(jpgd_status status) +{ +#if 0 //for debugging + m_error_code = status; +#else + m_error_code = JPGD_FAILED; +#endif + free_all_blocks(); + return false; +} + + +void *jpeg_decoder::alloc(size_t nSize, bool zero) +{ + //align the coeff_buf with the current platform architecture + constexpr auto cbSize = alignof(coeff_buf); + nSize = (nSize + cbSize - 1) & ~(cbSize - 1); + + char *rv = nullptr; + for (mem_block *b = m_pMem_blocks; b; b = b->m_pNext) { + if ((b->m_used_count + nSize) <= b->m_size) { + rv = b->m_data + b->m_used_count; + b->m_used_count += nSize; + break; + } + } + if (!rv) { + int capacity = JPGD_MAX(32768 - 256, (nSize + 2047) & ~2047); + auto b = tvg::malloc(sizeof(mem_block) + capacity); + b->m_pNext = m_pMem_blocks; m_pMem_blocks = b; + b->m_used_count = nSize; + b->m_size = capacity; + rv = b->m_data; + } + if (zero) memset(rv, 0, nSize); + return rv; +} + + +void jpeg_decoder::word_clear(void *p, uint16_t c, uint32_t n) +{ + uint8_t *pD = (uint8_t*)p; + const uint8_t l = c & 0xFF, h = (c >> 8) & 0xFF; + while (n) { + pD[0] = l; pD[1] = h; pD += 2; + n--; + } +} + + +// Refill the input buffer. +// This method will sit in a loop until (A) the buffer is full or (B) +// the stream's read() method reports and end of file condition. +bool jpeg_decoder::prep_in_buffer() +{ + m_in_buf_left = 0; + m_pIn_buf_ofs = m_in_buf; + if (m_eof_flag) return true; + + do { + auto bytes_read = m_pStream->read(m_in_buf + m_in_buf_left, JPGD_IN_BUF_SIZE - m_in_buf_left, &m_eof_flag); + if (bytes_read == -1) return stop_decoding(JPGD_STREAM_READ); + m_in_buf_left += bytes_read; + } while ((m_in_buf_left < JPGD_IN_BUF_SIZE) && (!m_eof_flag)); + + m_total_bytes_read += m_in_buf_left; + + // Pad the end of the block with M_EOI (prevents the decompressor from going off the rails if the stream is invalid). + // (This dates way back to when this decompressor was written in C/asm, and the all-asm Huffman decoder did some fancy things to increase perf.) + word_clear(m_pIn_buf_ofs + m_in_buf_left, 0xD9FF, 64); + return true; +} + + +// Read a Huffman code table. +bool jpeg_decoder::read_dht_marker() +{ + int i, index, count; + uint8_t huff_num[17]; + uint8_t huff_val[256]; + uint32_t num_left = get_bits(16); + + if (num_left < 2) return stop_decoding(JPGD_BAD_DHT_MARKER); + num_left -= 2; + + while (num_left) { + index = get_bits(8); + huff_num[0] = 0; + count = 0; + + for (i = 1; i <= 16; i++) { + huff_num[i] = static_cast(get_bits(8)); + count += huff_num[i]; + } + + if (count > 255) return stop_decoding(JPGD_BAD_DHT_COUNTS); + + for (i = 0; i < count; i++) + huff_val[i] = static_cast(get_bits(8)); + + i = 1 + 16 + count; + + if (num_left < (uint32_t)i) return stop_decoding(JPGD_BAD_DHT_MARKER); + num_left -= i; + + if ((index & 0x10) > 0x10) return stop_decoding(JPGD_BAD_DHT_INDEX); + index = (index & 0x0F) + ((index & 0x10) >> 4) * (JPGD_MAX_HUFF_TABLES >> 1); + if (index >= JPGD_MAX_HUFF_TABLES) return stop_decoding(JPGD_BAD_DHT_INDEX); + + if (!m_huff_num[index]) m_huff_num[index] = (uint8_t *)alloc(17); + if (!m_huff_val[index]) m_huff_val[index] = (uint8_t *)alloc(256); + + m_huff_ac[index] = (index & 0x10) != 0; + memcpy(m_huff_num[index], huff_num, 17); + memcpy(m_huff_val[index], huff_val, 256); + } + return true; +} + + +// Read a quantization table. +bool jpeg_decoder::read_dqt_marker() +{ + int n, i, prec; + uint32_t temp; + uint32_t num_left = get_bits(16); + if (num_left < 2) return stop_decoding(JPGD_BAD_DQT_MARKER); + num_left -= 2; + + while (num_left) { + n = get_bits(8); + prec = n >> 4; + n &= 0x0F; + + if (n >= JPGD_MAX_QUANT_TABLES) return stop_decoding(JPGD_BAD_DQT_TABLE); + + if (!m_quant[n]) m_quant[n] = (jpgd_quant_t *)alloc(64 * sizeof(jpgd_quant_t)); + + // read quantization entries, in zag order + for (i = 0; i < 64; i++) { + temp = get_bits(8); + if (prec) temp = (temp << 8) + get_bits(8); + m_quant[n][i] = static_cast(temp); + } + i = 64 + 1; + if (prec) i += 64; + if (num_left < (uint32_t)i) return stop_decoding(JPGD_BAD_DQT_LENGTH); + num_left -= i; + } + return true; +} + + +// Read the start of frame (SOF) marker. +bool jpeg_decoder::read_sof_marker() +{ + int i; + uint32_t num_left = get_bits(16); + + if (get_bits(8) != 8) return stop_decoding(JPGD_BAD_PRECISION); /* precision: sorry, only 8-bit precision is supported right now */ + + m_image_y_size = get_bits(16); + if ((m_image_y_size < 1) || (m_image_y_size > JPGD_MAX_HEIGHT)) return stop_decoding(JPGD_BAD_HEIGHT); + + m_image_x_size = get_bits(16); + if ((m_image_x_size < 1) || (m_image_x_size > JPGD_MAX_WIDTH)) return stop_decoding(JPGD_BAD_WIDTH); + + m_comps_in_frame = get_bits(8); + if (m_comps_in_frame > JPGD_MAX_COMPONENTS) return stop_decoding(JPGD_TOO_MANY_COMPONENTS); + + if (num_left != (uint32_t)(m_comps_in_frame * 3 + 8)) return stop_decoding(JPGD_BAD_SOF_LENGTH); + + for (i = 0; i < m_comps_in_frame; i++) { + m_comp_ident[i] = get_bits(8); + m_comp_h_samp[i] = get_bits(4); + m_comp_v_samp[i] = get_bits(4); + m_comp_quant[i] = get_bits(8); + } + return true; +} + + +// Used to skip unrecognized markers. +bool jpeg_decoder::skip_variable_marker() +{ + uint32_t num_left = get_bits(16); + if (num_left < 2) return stop_decoding(JPGD_BAD_VARIABLE_MARKER); + num_left -= 2; + + while (num_left) { + get_bits(8); + num_left--; + } + return true; +} + + +// Read a define restart interval (DRI) marker. +bool jpeg_decoder::read_dri_marker() +{ + if (get_bits(16) != 4) return stop_decoding(JPGD_BAD_DRI_LENGTH); + m_restart_interval = get_bits(16); + return true; +} + + +// Read a start of scan (SOS) marker. +bool jpeg_decoder::read_sos_marker() +{ + int i, ci, c, cc; + uint32_t num_left = get_bits(16); + int n = get_bits(8); + + m_comps_in_scan = n; + num_left -= 3; + + if ( (num_left != (uint32_t)(n * 2 + 3)) || (n < 1) || (n > JPGD_MAX_COMPS_IN_SCAN) ) return stop_decoding(JPGD_BAD_SOS_LENGTH); + + for (i = 0; i < n; i++) { + cc = get_bits(8); + c = get_bits(8); + num_left -= 2; + + for (ci = 0; ci < m_comps_in_frame; ci++) + if (cc == m_comp_ident[ci]) break; + + if (ci >= m_comps_in_frame) return stop_decoding(JPGD_BAD_SOS_COMP_ID); + + m_comp_list[i] = ci; + m_comp_dc_tab[ci] = (c >> 4) & 15; + m_comp_ac_tab[ci] = (c & 15) + (JPGD_MAX_HUFF_TABLES >> 1); + } + m_spectral_start = get_bits(8); + m_spectral_end = get_bits(8); + m_successive_high = get_bits(4); + m_successive_low = get_bits(4); + + if (!m_progressive_flag) { + m_spectral_start = 0; + m_spectral_end = 63; + } + num_left -= 3; + + while (num_left) { /* read past whatever is num_left */ + get_bits(8); + num_left--; + } + return true; +} + + +// Finds the next marker. +int jpeg_decoder::next_marker() +{ + uint32_t c; + + do { + do { + c = get_bits(8); + } while (c != 0xFF); + + do { + c = get_bits(8); + } while (c == 0xFF); + } while (c == 0); + + return c; +} + + +// Process markers. Returns when an SOFx, SOI, EOI, or SOS marker is +// encountered. +int jpeg_decoder::process_markers() +{ + int c; + + for ( ; ; ) { + c = next_marker(); + switch (c) { + case M_SOF0: + case M_SOF1: + case M_SOF2: + case M_SOF3: + case M_SOF5: + case M_SOF6: + case M_SOF7: + // case M_JPG: + case M_SOF9: + case M_SOF10: + case M_SOF11: + case M_SOF13: + case M_SOF14: + case M_SOF15: + case M_SOI: + case M_EOI: + case M_SOS: return c; + case M_DHT: { + if (read_dht_marker()) break; + else return M_EOI; + } + // No arithmetic support - dumb patents! + case M_DAC: { + stop_decoding(JPGD_NO_ARITHMETIC_SUPPORT); + return M_EOI; + } + case M_DQT: { + if (read_dqt_marker()) break; + else return M_EOI; + } + case M_DRI: { + if (read_dri_marker()) break; + else return M_EOI; + } + //case M_APP0: /* no need to read the JFIF marker */ + case M_JPG: + case M_RST0: /* no parameters */ + case M_RST1: + case M_RST2: + case M_RST3: + case M_RST4: + case M_RST5: + case M_RST6: + case M_RST7: + case M_TEM: { + stop_decoding(JPGD_UNEXPECTED_MARKER); + return M_EOI; + } + default: { /* must be DNL, DHP, EXP, APPn, JPGn, COM, or RESn or APP0 */ + if (skip_variable_marker()) break; + else return M_EOI; + } + } + } +} + + +// Finds the start of image (SOI) marker. +// This code is rather defensive: it only checks the first 512 bytes to avoid +// false positives. +bool jpeg_decoder::locate_soi_marker() +{ + uint32_t lastchar = get_bits(8); + uint32_t thischar = get_bits(8); + + /* ok if it's a normal JPEG file without a special header */ + if ((lastchar == 0xFF) && (thischar == M_SOI)) return true; + + uint32_t bytesleft = 4096; //512; + + while (true) { + if (--bytesleft == 0) return stop_decoding(JPGD_NOT_JPEG); + + lastchar = thischar; + thischar = get_bits(8); + + if (lastchar == 0xFF) { + if (thischar == M_SOI) break; + else if (thischar == M_EOI) return stop_decoding(JPGD_NOT_JPEG); // get_bits will keep returning M_EOI if we read past the end + } + } + + // Check the next character after marker: if it's not 0xFF, it can't be the start of the next marker, so the file is bad. + thischar = (m_bit_buf >> 24) & 0xFF; + if (thischar != 0xFF) return stop_decoding(JPGD_NOT_JPEG); + return true; +} + + +// Find a start of frame (SOF) marker. +bool jpeg_decoder::locate_sof_marker() +{ + if (!locate_soi_marker()) return false; + switch (process_markers()) { + case M_SOF2: { + m_progressive_flag = true; + return read_sof_marker(); + } + case M_SOF0: /* baseline DCT */ + case M_SOF1: { /* extended sequential DCT */ + return read_sof_marker(); + } + case M_SOF9: return stop_decoding(JPGD_NO_ARITHMETIC_SUPPORT); + default: return stop_decoding(JPGD_UNSUPPORTED_MARKER); + } + return true; +} + + +// Find a start of scan (SOS) marker. +bool jpeg_decoder::locate_sos_marker() +{ + auto c = process_markers(); + if (c == M_EOI) return false; + else if (c != M_SOS) return stop_decoding(JPGD_UNEXPECTED_MARKER); + return read_sos_marker(); +} + + +// Reset everything to default/uninitialized state. +void jpeg_decoder::init(jpeg_decoder_stream *pStream) +{ + m_pMem_blocks = nullptr; + m_error_code = JPGD_SUCCESS; + m_ready_flag = false; + m_image_x_size = m_image_y_size = 0; + m_pStream = pStream; + m_progressive_flag = false; + + memset(m_huff_ac, 0, sizeof(m_huff_ac)); + memset(m_huff_num, 0, sizeof(m_huff_num)); + memset(m_huff_val, 0, sizeof(m_huff_val)); + memset(m_quant, 0, sizeof(m_quant)); + + m_scan_type = 0; + m_comps_in_frame = 0; + + memset(m_comp_h_samp, 0, sizeof(m_comp_h_samp)); + memset(m_comp_v_samp, 0, sizeof(m_comp_v_samp)); + memset(m_comp_quant, 0, sizeof(m_comp_quant)); + memset(m_comp_ident, 0, sizeof(m_comp_ident)); + memset(m_comp_h_blocks, 0, sizeof(m_comp_h_blocks)); + memset(m_comp_v_blocks, 0, sizeof(m_comp_v_blocks)); + + m_comps_in_scan = 0; + memset(m_comp_list, 0, sizeof(m_comp_list)); + memset(m_comp_dc_tab, 0, sizeof(m_comp_dc_tab)); + memset(m_comp_ac_tab, 0, sizeof(m_comp_ac_tab)); + + m_spectral_start = 0; + m_spectral_end = 0; + m_successive_low = 0; + m_successive_high = 0; + m_max_mcu_x_size = 0; + m_max_mcu_y_size = 0; + m_blocks_per_mcu = 0; + m_max_blocks_per_row = 0; + m_mcus_per_row = 0; + m_mcus_per_col = 0; + m_expanded_blocks_per_component = 0; + m_expanded_blocks_per_mcu = 0; + m_expanded_blocks_per_row = 0; + + memset(m_mcu_org, 0, sizeof(m_mcu_org)); + + m_total_lines_left = 0; + m_mcu_lines_left = 0; + m_real_dest_bytes_per_scan_line = 0; + m_dest_bytes_per_scan_line = 0; + m_dest_bytes_per_pixel = 0; + + memset(m_pHuff_tabs, 0, sizeof(m_pHuff_tabs)); + + memset(m_dc_coeffs, 0, sizeof(m_dc_coeffs)); + memset(m_ac_coeffs, 0, sizeof(m_ac_coeffs)); + memset(m_block_y_mcu, 0, sizeof(m_block_y_mcu)); + + m_eob_run = 0; + + memset(m_block_y_mcu, 0, sizeof(m_block_y_mcu)); + + m_pIn_buf_ofs = m_in_buf; + m_in_buf_left = 0; + m_eof_flag = false; + m_tem_flag = 0; + + memset(m_in_buf_pad_start, 0, sizeof(m_in_buf_pad_start)); + memset(m_in_buf, 0, sizeof(m_in_buf)); + memset(m_in_buf_pad_end, 0, sizeof(m_in_buf_pad_end)); + + m_restart_interval = 0; + m_restarts_left = 0; + m_next_restart_num = 0; + + m_max_mcus_per_row = 0; + m_max_blocks_per_mcu = 0; + m_max_mcus_per_col = 0; + + memset(m_last_dc_val, 0, sizeof(m_last_dc_val)); + m_pMCU_coefficients = nullptr; + m_pSample_buf = nullptr; + + m_total_bytes_read = 0; + + m_pScan_line_0 = nullptr; + m_pScan_line_1 = nullptr; + + // Ready the input buffer. + prep_in_buffer(); + + // Prime the bit buffer. + m_bits_left = 16; + m_bit_buf = 0; + + get_bits(16); + get_bits(16); + + for (int i = 0; i < JPGD_MAX_BLOCKS_PER_MCU; i++) { + m_mcu_block_max_zag[i] = 64; + } +} + +#define SCALEBITS 16 +#define ONE_HALF ((int) 1 << (SCALEBITS-1)) +#define FIX(x) ((int) ((x) * (1L<> SCALEBITS; + m_cbb[i] = ( FIX(1.77200f) * k + ONE_HALF) >> SCALEBITS; + m_crg[i] = (-FIX(0.71414f)) * k; + m_cbg[i] = (-FIX(0.34414f)) * k + ONE_HALF; + } +} + + +// This method throws back into the stream any bytes that where read +// into the bit buffer during initial marker scanning. +void jpeg_decoder::fix_in_buffer() +{ + if (m_bits_left == 16) stuff_char( (uint8_t)(m_bit_buf & 0xFF)); + if (m_bits_left >= 8) stuff_char( (uint8_t)((m_bit_buf >> 8) & 0xFF)); + + stuff_char((uint8_t)((m_bit_buf >> 16) & 0xFF)); + stuff_char((uint8_t)((m_bit_buf >> 24) & 0xFF)); + + m_bits_left = 16; + get_bits_no_markers(16); + get_bits_no_markers(16); +} + + +void jpeg_decoder::transform_mcu(int mcu_row) +{ + jpgd_block_t* pSrc_ptr = m_pMCU_coefficients; + uint8_t* pDst_ptr = m_pSample_buf + mcu_row * m_blocks_per_mcu * 64; + + for (int mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++) { + idct(pSrc_ptr, pDst_ptr, m_mcu_block_max_zag[mcu_block]); + pSrc_ptr += 64; + pDst_ptr += 64; + } +} + + +// Loads and dequantizes the next row of (already decoded) coefficients. +// Progressive images only. +void jpeg_decoder::load_next_row() +{ + int i; + jpgd_block_t *p; + jpgd_quant_t *q; + int mcu_row, mcu_block; + int component_num, component_id; + int block_x_mcu[JPGD_MAX_COMPONENTS]; + + memset(block_x_mcu, 0, JPGD_MAX_COMPONENTS * sizeof(int)); + + for (mcu_row = 0; mcu_row < m_mcus_per_row; mcu_row++) { + int block_x_mcu_ofs = 0, block_y_mcu_ofs = 0; + + for (mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++) { + component_id = m_mcu_org[mcu_block]; + q = m_quant[m_comp_quant[component_id]]; + p = m_pMCU_coefficients + 64 * mcu_block; + + jpgd_block_t* pAC = coeff_buf_getp(m_ac_coeffs[component_id], block_x_mcu[component_id] + block_x_mcu_ofs, m_block_y_mcu[component_id] + block_y_mcu_ofs); + jpgd_block_t* pDC = coeff_buf_getp(m_dc_coeffs[component_id], block_x_mcu[component_id] + block_x_mcu_ofs, m_block_y_mcu[component_id] + block_y_mcu_ofs); + p[0] = pDC[0]; + memcpy(&p[1], &pAC[1], 63 * sizeof(jpgd_block_t)); + + for (i = 63; i > 0; i--) { + if (p[g_ZAG[i]]) break; + } + + m_mcu_block_max_zag[mcu_block] = i + 1; + + for ( ; i >= 0; i--) { + if (p[g_ZAG[i]]) { + p[g_ZAG[i]] = static_cast(p[g_ZAG[i]] * q[i]); + } + } + + if (m_comps_in_scan == 1) block_x_mcu[component_id]++; + else { + if (++block_x_mcu_ofs == m_comp_h_samp[component_id]) { + block_x_mcu_ofs = 0; + if (++block_y_mcu_ofs == m_comp_v_samp[component_id]) { + block_y_mcu_ofs = 0; + block_x_mcu[component_id] += m_comp_h_samp[component_id]; + } + } + } + } + transform_mcu(mcu_row); + } + if (m_comps_in_scan == 1) m_block_y_mcu[m_comp_list[0]]++; + else { + for (component_num = 0; component_num < m_comps_in_scan; component_num++) { + component_id = m_comp_list[component_num]; + m_block_y_mcu[component_id] += m_comp_v_samp[component_id]; + } + } +} + + +// Restart interval processing. +bool jpeg_decoder::process_restart() +{ + int i; + int c = 0; + + // Align to a byte boundary + // FIXME: Is this really necessary? get_bits_no_markers() never reads in markers! + //get_bits_no_markers(m_bits_left & 7); + + // Let's scan a little bit to find the marker, but not _too_ far. + // 1536 is a "fudge factor" that determines how much to scan. + for (i = 1536; i > 0; i--) { + if (get_char() == 0xFF) break; + } + if (i == 0) return stop_decoding(JPGD_BAD_RESTART_MARKER); + + for ( ; i > 0; i--) { + if ((c = get_char()) != 0xFF) break; + } + if (i == 0) return stop_decoding(JPGD_BAD_RESTART_MARKER); + + // Is it the expected marker? If not, something bad happened. + if (c != (m_next_restart_num + M_RST0)) return stop_decoding(JPGD_BAD_RESTART_MARKER); + + // Reset each component's DC prediction values. + memset(&m_last_dc_val, 0, m_comps_in_frame * sizeof(uint32_t)); + + m_eob_run = 0; + m_restarts_left = m_restart_interval; + m_next_restart_num = (m_next_restart_num + 1) & 7; + + // Get the bit buffer going again... + m_bits_left = 16; + get_bits_no_markers(16); + get_bits_no_markers(16); + + return true; +} + + +static inline int dequantize_ac(int c, int q) +{ + c *= q; + return c; +} + +// Decodes and dequantizes the next row of coefficients. +bool jpeg_decoder::decode_next_row() +{ + for (int mcu_row = 0; mcu_row < m_mcus_per_row; mcu_row++) { + if ((m_restart_interval) && (m_restarts_left == 0)) { + if (!process_restart()) return false; + } + + jpgd_block_t* p = m_pMCU_coefficients; + + for (int mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++, p += 64) { + int component_id = m_mcu_org[mcu_block]; + jpgd_quant_t* q = m_quant[m_comp_quant[component_id]]; + + int r, s; + s = huff_decode(m_pHuff_tabs[m_comp_dc_tab[component_id]], r); + s = JPGD_HUFF_EXTEND(r, s); + + m_last_dc_val[component_id] = (s += m_last_dc_val[component_id]); + + p[0] = static_cast(s * q[0]); + + int prev_num_set = m_mcu_block_max_zag[mcu_block]; + huff_tables *pH = m_pHuff_tabs[m_comp_ac_tab[component_id]]; + int k; + for (k = 1; k < 64; k++) { + int extra_bits; + s = huff_decode(pH, extra_bits); + r = s >> 4; + s &= 15; + + if (s) { + if (r) { + if ((k + r) > 63) return stop_decoding(JPGD_DECODE_ERROR); + if (k < prev_num_set) { + int n = JPGD_MIN(r, prev_num_set - k); + int kt = k; + while (n--) p[g_ZAG[kt++]] = 0; + } + k += r; + } + s = JPGD_HUFF_EXTEND(extra_bits, s); + p[g_ZAG[k]] = static_cast(dequantize_ac(s, q[k])); //s * q[k]; + } else { + if (r == 15) { + if ((k + 16) > 64) return stop_decoding(JPGD_DECODE_ERROR); + if (k < prev_num_set) { + int n = JPGD_MIN(16, prev_num_set - k); + int kt = k; + while (n--) { + p[g_ZAG[kt++]] = 0; + } + } + k += 16 - 1; // - 1 because the loop counter is k + } else break; + } + } + + if (k < prev_num_set) { + int kt = k; + while (kt < prev_num_set) p[g_ZAG[kt++]] = 0; + } + + m_mcu_block_max_zag[mcu_block] = k; + } + transform_mcu(mcu_row); + m_restarts_left--; + } + return true; +} + + +// YCbCr H1V1 (1x1:1:1, 3 m_blocks per MCU) to RGB +void jpeg_decoder::H1V1Convert() +{ + int row = m_max_mcu_y_size - m_mcu_lines_left; + uint8_t *d = m_pScan_line_0; + uint8_t *s = m_pSample_buf + row * 8; + + for (int i = m_max_mcus_per_row; i > 0; i--) { + for (int j = 0; j < 8; j++) { + int y = s[j]; + int cb = s[64+j]; + int cr = s[128+j]; + + d[0] = clamp(y + m_crr[cr]); + d[1] = clamp(y + ((m_crg[cr] + m_cbg[cb]) >> 16)); + d[2] = clamp(y + m_cbb[cb]); + d[3] = 255; + d += 4; + } + s += 64*3; + } +} + + +// YCbCr H2V1 (2x1:1:1, 4 m_blocks per MCU) to RGB +void jpeg_decoder::H2V1Convert() +{ + int row = m_max_mcu_y_size - m_mcu_lines_left; + uint8_t *d0 = m_pScan_line_0; + uint8_t *y = m_pSample_buf + row * 8; + uint8_t *c = m_pSample_buf + 2*64 + row * 8; + + for (int i = m_max_mcus_per_row; i > 0; i--) { + for (int l = 0; l < 2; l++) { + for (int j = 0; j < 4; j++) { + int cb = c[0]; + int cr = c[64]; + + int rc = m_crr[cr]; + int gc = ((m_crg[cr] + m_cbg[cb]) >> 16); + int bc = m_cbb[cb]; + + int yy = y[j<<1]; + d0[0] = clamp(yy+rc); + d0[1] = clamp(yy+gc); + d0[2] = clamp(yy+bc); + d0[3] = 255; + + yy = y[(j<<1)+1]; + d0[4] = clamp(yy+rc); + d0[5] = clamp(yy+gc); + d0[6] = clamp(yy+bc); + d0[7] = 255; + d0 += 8; + c++; + } + y += 64; + } + y += 64*4 - 64*2; + c += 64*4 - 8; + } +} + + +// YCbCr H2V1 (1x2:1:1, 4 m_blocks per MCU) to RGB +void jpeg_decoder::H1V2Convert() +{ + int row = m_max_mcu_y_size - m_mcu_lines_left; + uint8_t *d0 = m_pScan_line_0; + uint8_t *d1 = m_pScan_line_1; + uint8_t *y; + uint8_t *c; + + if (row < 8) y = m_pSample_buf + row * 8; + else y = m_pSample_buf + 64*1 + (row & 7) * 8; + + c = m_pSample_buf + 64*2 + (row >> 1) * 8; + + for (int i = m_max_mcus_per_row; i > 0; i--) { + for (int j = 0; j < 8; j++) { + int cb = c[0+j]; + int cr = c[64+j]; + + int rc = m_crr[cr]; + int gc = ((m_crg[cr] + m_cbg[cb]) >> 16); + int bc = m_cbb[cb]; + + int yy = y[j]; + d0[0] = clamp(yy+rc); + d0[1] = clamp(yy+gc); + d0[2] = clamp(yy+bc); + d0[3] = 255; + + yy = y[8+j]; + d1[0] = clamp(yy+rc); + d1[1] = clamp(yy+gc); + d1[2] = clamp(yy+bc); + d1[3] = 255; + + d0 += 4; + d1 += 4; + } + y += 64*4; + c += 64*4; + } +} + + +// YCbCr H2V2 (2x2:1:1, 6 m_blocks per MCU) to RGB +void jpeg_decoder::H2V2Convert() +{ + int row = m_max_mcu_y_size - m_mcu_lines_left; + uint8_t *d0 = m_pScan_line_0; + uint8_t *d1 = m_pScan_line_1; + uint8_t *y; + uint8_t *c; + + if (row < 8) y = m_pSample_buf + row * 8; + else y = m_pSample_buf + 64*2 + (row & 7) * 8; + + c = m_pSample_buf + 64*4 + (row >> 1) * 8; + + for (int i = m_max_mcus_per_row; i > 0; i--) { + for (int l = 0; l < 2; l++) { + for (int j = 0; j < 8; j += 2) { + int cb = c[0]; + int cr = c[64]; + + int rc = m_crr[cr]; + int gc = ((m_crg[cr] + m_cbg[cb]) >> 16); + int bc = m_cbb[cb]; + + int yy = y[j]; + d0[0] = clamp(yy+rc); + d0[1] = clamp(yy+gc); + d0[2] = clamp(yy+bc); + d0[3] = 255; + + yy = y[j+1]; + d0[4] = clamp(yy+rc); + d0[5] = clamp(yy+gc); + d0[6] = clamp(yy+bc); + d0[7] = 255; + + yy = y[j+8]; + d1[0] = clamp(yy+rc); + d1[1] = clamp(yy+gc); + d1[2] = clamp(yy+bc); + d1[3] = 255; + + yy = y[j+8+1]; + d1[4] = clamp(yy+rc); + d1[5] = clamp(yy+gc); + d1[6] = clamp(yy+bc); + d1[7] = 255; + + d0 += 8; + d1 += 8; + + c++; + } + y += 64; + } + y += 64*6 - 64*2; + c += 64*6 - 8; + } +} + + +// Y (1 block per MCU) to 8-bit grayscale +void jpeg_decoder::gray_convert() +{ + int row = m_max_mcu_y_size - m_mcu_lines_left; + uint8_t *d = m_pScan_line_0; + uint8_t *s = m_pSample_buf + row * 8; + + for (int i = m_max_mcus_per_row; i > 0; i--) { + *(uint32_t *)d = *(uint32_t *)s; + *(uint32_t *)(&d[4]) = *(uint32_t *)(&s[4]); + s += 64; + d += 8; + } +} + + +// Find end of image (EOI) marker, so we can return to the user the exact size of the input stream. +void jpeg_decoder::find_eoi() +{ + if (!m_progressive_flag) { + // Attempt to read the EOI marker. + //get_bits_no_markers(m_bits_left & 7); + + // Prime the bit buffer + m_bits_left = 16; + get_bits(16); + get_bits(16); + + // The next marker _should_ be EOI + process_markers(); + } + m_total_bytes_read -= m_in_buf_left; +} + + +int jpeg_decoder::decode(const void** pScan_line) +{ + if ((m_error_code) || (!m_ready_flag)) return JPGD_FAILED; + if (m_total_lines_left == 0) return JPGD_DONE; + if (m_mcu_lines_left == 0) { + if (m_progressive_flag) load_next_row(); + else if (!decode_next_row()) return JPGD_FAILED; + // Find the EOI marker if that was the last row. + if (m_total_lines_left <= m_max_mcu_y_size) find_eoi(); + m_mcu_lines_left = m_max_mcu_y_size; + } + + switch (m_scan_type) { + case JPGD_YH2V2: { + if ((m_mcu_lines_left & 1) == 0) { + H2V2Convert(); + *pScan_line = m_pScan_line_0; + } + else *pScan_line = m_pScan_line_1; + break; + } + case JPGD_YH2V1: { + H2V1Convert(); + *pScan_line = m_pScan_line_0; + break; + } + case JPGD_YH1V2: { + if ((m_mcu_lines_left & 1) == 0) { + H1V2Convert(); + *pScan_line = m_pScan_line_0; + } else *pScan_line = m_pScan_line_1; + break; + } + case JPGD_YH1V1: { + H1V1Convert(); + *pScan_line = m_pScan_line_0; + break; + } + case JPGD_GRAYSCALE: { + gray_convert(); + *pScan_line = m_pScan_line_0; + break; + } + } + + m_mcu_lines_left--; + m_total_lines_left--; + + return JPGD_SUCCESS; +} + + +// Creates the tables needed for efficient Huffman decoding. +void jpeg_decoder::make_huff_table(int index, huff_tables *pH) +{ + int p, i, l, si; + uint8_t huffsize[257]; + uint32_t huffcode[257]; + uint32_t code; + uint32_t subtree; + int code_size; + int lastp; + int nextfreeentry; + int currententry; + + pH->ac_table = m_huff_ac[index] != 0; + p = 0; + + for (l = 1; l <= 16; l++) { + for (i = 1; i <= m_huff_num[index][l]; i++) { + huffsize[p++] = static_cast(l); + } + } + + huffsize[p] = 0; + lastp = p; + code = 0; + si = huffsize[0]; + p = 0; + + while (huffsize[p]) { + while (huffsize[p] == si) { + huffcode[p++] = code; + code++; + } + code <<= 1; + si++; + } + + memset(pH->look_up, 0, sizeof(pH->look_up)); + memset(pH->look_up2, 0, sizeof(pH->look_up2)); + memset(pH->tree, 0, sizeof(pH->tree)); + memset(pH->code_size, 0, sizeof(pH->code_size)); + + nextfreeentry = -1; + p = 0; + + while (p < lastp) { + i = m_huff_val[index][p]; + code = huffcode[p]; + code_size = huffsize[p]; + pH->code_size[i] = static_cast(code_size); + + if (code_size <= 8) { + code <<= (8 - code_size); + for (l = 1 << (8 - code_size); l > 0; l--) { + pH->look_up[code] = i; + bool has_extrabits = false; + int extra_bits = 0; + int num_extra_bits = i & 15; + int bits_to_fetch = code_size; + + if (num_extra_bits) { + int total_codesize = code_size + num_extra_bits; + if (total_codesize <= 8) { + has_extrabits = true; + extra_bits = ((1 << num_extra_bits) - 1) & (code >> (8 - total_codesize)); + bits_to_fetch += num_extra_bits; + } + } + if (!has_extrabits) pH->look_up2[code] = i | (bits_to_fetch << 8); + else pH->look_up2[code] = i | 0x8000 | (extra_bits << 16) | (bits_to_fetch << 8); + code++; + } + } else { + subtree = (code >> (code_size - 8)) & 0xFF; + currententry = pH->look_up[subtree]; + + if (currententry == 0) { + pH->look_up[subtree] = currententry = nextfreeentry; + pH->look_up2[subtree] = currententry = nextfreeentry; + nextfreeentry -= 2; + } + + code <<= (16 - (code_size - 8)); + + for (l = code_size; l > 9; l--) { + if ((code & 0x8000) == 0) currententry--; + if (pH->tree[-currententry - 1] == 0) { + pH->tree[-currententry - 1] = nextfreeentry; + currententry = nextfreeentry; + nextfreeentry -= 2; + } else currententry = pH->tree[-currententry - 1]; + code <<= 1; + } + if ((code & 0x8000) == 0) currententry--; + pH->tree[-currententry - 1] = i; + } + p++; + } +} + + +// Verifies the quantization tables needed for this scan are available. +bool jpeg_decoder::check_quant_tables() +{ + for (int i = 0; i < m_comps_in_scan; i++) { + if (!m_quant[m_comp_quant[m_comp_list[i]]]) return stop_decoding(JPGD_UNDEFINED_QUANT_TABLE); + } + return true; +} + + +// Verifies that all the Huffman tables needed for this scan are available. +bool jpeg_decoder::check_huff_tables() +{ + for (int i = 0; i < m_comps_in_scan; i++) { + if ((m_spectral_start == 0) && !m_huff_num[m_comp_dc_tab[m_comp_list[i]]]) return stop_decoding(JPGD_UNDEFINED_HUFF_TABLE); + if ((m_spectral_end > 0) && !m_huff_num[m_comp_ac_tab[m_comp_list[i]]]) return stop_decoding(JPGD_UNDEFINED_HUFF_TABLE); + } + + for (int i = 0; i < JPGD_MAX_HUFF_TABLES; i++) { + if (m_huff_num[i]) { + if (!m_pHuff_tabs[i]) m_pHuff_tabs[i] = (huff_tables *)alloc(sizeof(huff_tables)); + make_huff_table(i, m_pHuff_tabs[i]); + } + } + return true; +} + + +// Determines the component order inside each MCU. +// Also calcs how many MCU's are on each row, etc. +void jpeg_decoder::calc_mcu_block_order() +{ + int component_num, component_id; + int max_h_samp = 0, max_v_samp = 0; + + for (component_id = 0; component_id < m_comps_in_frame; component_id++) { + if (m_comp_h_samp[component_id] > max_h_samp) { + max_h_samp = m_comp_h_samp[component_id]; + } + if (m_comp_v_samp[component_id] > max_v_samp) { + max_v_samp = m_comp_v_samp[component_id]; + } + } + + for (component_id = 0; component_id < m_comps_in_frame; component_id++) { + m_comp_h_blocks[component_id] = ((((m_image_x_size * m_comp_h_samp[component_id]) + (max_h_samp - 1)) / max_h_samp) + 7) / 8; + m_comp_v_blocks[component_id] = ((((m_image_y_size * m_comp_v_samp[component_id]) + (max_v_samp - 1)) / max_v_samp) + 7) / 8; + } + + if (m_comps_in_scan == 1) { + m_mcus_per_row = m_comp_h_blocks[m_comp_list[0]]; + m_mcus_per_col = m_comp_v_blocks[m_comp_list[0]]; + } else { + m_mcus_per_row = (((m_image_x_size + 7) / 8) + (max_h_samp - 1)) / max_h_samp; + m_mcus_per_col = (((m_image_y_size + 7) / 8) + (max_v_samp - 1)) / max_v_samp; + } + + if (m_comps_in_scan == 1) { + m_mcu_org[0] = m_comp_list[0]; + m_blocks_per_mcu = 1; + } else { + m_blocks_per_mcu = 0; + + for (component_num = 0; component_num < m_comps_in_scan; component_num++) { + int num_blocks; + component_id = m_comp_list[component_num]; + num_blocks = m_comp_h_samp[component_id] * m_comp_v_samp[component_id]; + while (num_blocks--) m_mcu_org[m_blocks_per_mcu++] = component_id; + } + } +} + + +// Starts a new scan. +int jpeg_decoder::init_scan() +{ + if (!locate_sos_marker()) return false; + + calc_mcu_block_order(); + check_huff_tables(); + if (!check_quant_tables()) return false; + + memset(m_last_dc_val, 0, m_comps_in_frame * sizeof(uint32_t)); + + m_eob_run = 0; + + if (m_restart_interval) { + m_restarts_left = m_restart_interval; + m_next_restart_num = 0; + } + fix_in_buffer(); + return true; +} + + +// Starts a frame. Determines if the number of components or sampling factors +// are supported. +bool jpeg_decoder::init_frame() +{ + int i; + + if (m_comps_in_frame == 1) { + if ((m_comp_h_samp[0] != 1) || (m_comp_v_samp[0] != 1)) return stop_decoding(JPGD_UNSUPPORTED_SAMP_FACTORS); + m_scan_type = JPGD_GRAYSCALE; + m_max_blocks_per_mcu = 1; + m_max_mcu_x_size = 8; + m_max_mcu_y_size = 8; + } else if (m_comps_in_frame == 3) { + if (((m_comp_h_samp[1] != 1) || (m_comp_v_samp[1] != 1)) || ((m_comp_h_samp[2] != 1) || (m_comp_v_samp[2] != 1))) { + return stop_decoding(JPGD_UNSUPPORTED_SAMP_FACTORS); + } + + if ((m_comp_h_samp[0] == 1) && (m_comp_v_samp[0] == 1)) { + m_scan_type = JPGD_YH1V1; + m_max_blocks_per_mcu = 3; + m_max_mcu_x_size = 8; + m_max_mcu_y_size = 8; + } else if ((m_comp_h_samp[0] == 2) && (m_comp_v_samp[0] == 1)) { + m_scan_type = JPGD_YH2V1; + m_max_blocks_per_mcu = 4; + m_max_mcu_x_size = 16; + m_max_mcu_y_size = 8; + } else if ((m_comp_h_samp[0] == 1) && (m_comp_v_samp[0] == 2)) { + m_scan_type = JPGD_YH1V2; + m_max_blocks_per_mcu = 4; + m_max_mcu_x_size = 8; + m_max_mcu_y_size = 16; + } else if ((m_comp_h_samp[0] == 2) && (m_comp_v_samp[0] == 2)) { + m_scan_type = JPGD_YH2V2; + m_max_blocks_per_mcu = 6; + m_max_mcu_x_size = 16; + m_max_mcu_y_size = 16; + } else return stop_decoding(JPGD_UNSUPPORTED_SAMP_FACTORS); + } else return stop_decoding(JPGD_UNSUPPORTED_COLORSPACE); + + m_max_mcus_per_row = (m_image_x_size + (m_max_mcu_x_size - 1)) / m_max_mcu_x_size; + m_max_mcus_per_col = (m_image_y_size + (m_max_mcu_y_size - 1)) / m_max_mcu_y_size; + + // These values are for the *destination* pixels: after conversion. + if (m_scan_type == JPGD_GRAYSCALE) m_dest_bytes_per_pixel = 1; + else m_dest_bytes_per_pixel = 4; + + m_dest_bytes_per_scan_line = ((m_image_x_size + 15) & 0xFFF0) * m_dest_bytes_per_pixel; + m_real_dest_bytes_per_scan_line = (m_image_x_size * m_dest_bytes_per_pixel); + + // Initialize two scan line buffers. + m_pScan_line_0 = (uint8_t *)alloc(m_dest_bytes_per_scan_line, true); + if ((m_scan_type == JPGD_YH1V2) || (m_scan_type == JPGD_YH2V2)) { + m_pScan_line_1 = (uint8_t *)alloc(m_dest_bytes_per_scan_line, true); + } + + m_max_blocks_per_row = m_max_mcus_per_row * m_max_blocks_per_mcu; + + // Should never happen + if (m_max_blocks_per_row > JPGD_MAX_BLOCKS_PER_ROW) return stop_decoding(JPGD_ASSERTION_ERROR); + + // Allocate the coefficient buffer, enough for one MCU + m_pMCU_coefficients = (jpgd_block_t*)alloc(m_max_blocks_per_mcu * 64 * sizeof(jpgd_block_t)); + + for (i = 0; i < m_max_blocks_per_mcu; i++) { + m_mcu_block_max_zag[i] = 64; + } + + m_expanded_blocks_per_component = m_comp_h_samp[0] * m_comp_v_samp[0]; + m_expanded_blocks_per_mcu = m_expanded_blocks_per_component * m_comps_in_frame; + m_expanded_blocks_per_row = m_max_mcus_per_row * m_expanded_blocks_per_mcu; + + m_pSample_buf = (uint8_t *)alloc(m_max_blocks_per_row * 64); + + m_total_lines_left = m_image_y_size; + m_mcu_lines_left = 0; + create_look_ups(); + + return true; +} + + +// The coeff_buf series of methods originally stored the coefficients +// into a "virtual" file which was located in EMS, XMS, or a disk file. A cache +// was used to make this process more efficient. Now, we can store the entire +// thing in RAM. +jpeg_decoder::coeff_buf* jpeg_decoder::coeff_buf_open(int block_num_x, int block_num_y, int block_len_x, int block_len_y) +{ + coeff_buf* cb = (coeff_buf*)alloc(sizeof(coeff_buf)); + cb->block_num_x = block_num_x; + cb->block_num_y = block_num_y; + cb->block_len_x = block_len_x; + cb->block_len_y = block_len_y; + cb->block_size = (block_len_x * block_len_y) * sizeof(jpgd_block_t); + cb->pData = (uint8_t *)alloc(cb->block_size * block_num_x * block_num_y, true); + return cb; +} + + +inline jpgd_block_t *jpeg_decoder::coeff_buf_getp(coeff_buf *cb, int block_x, int block_y) +{ + return (jpgd_block_t *)(cb->pData + block_x * cb->block_size + block_y * (cb->block_size * cb->block_num_x)); +} + + +// The following methods decode the various types of m_blocks encountered +// in progressively encoded images. +bool jpeg_decoder::decode_block_dc_first(jpeg_decoder *pD, int component_id, int block_x, int block_y) +{ + int s, r; + jpgd_block_t *p = pD->coeff_buf_getp(pD->m_dc_coeffs[component_id], block_x, block_y); + + if ((s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_dc_tab[component_id]])) != 0) { + r = pD->get_bits_no_markers(s); + s = JPGD_HUFF_EXTEND(r, s); + } + pD->m_last_dc_val[component_id] = (s += pD->m_last_dc_val[component_id]); + p[0] = static_cast(static_cast(s) << pD->m_successive_low); + + return true; +} + + +bool jpeg_decoder::decode_block_dc_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y) +{ + if (pD->get_bits_no_markers(1)) { + jpgd_block_t *p = pD->coeff_buf_getp(pD->m_dc_coeffs[component_id], block_x, block_y); + p[0] |= (1 << pD->m_successive_low); + } + return true; +} + + +bool jpeg_decoder::decode_block_ac_first(jpeg_decoder *pD, int component_id, int block_x, int block_y) +{ + int k, s, r; + + if (pD->m_eob_run) { + pD->m_eob_run--; + return true; + } + jpgd_block_t *p = pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y); + + for (k = pD->m_spectral_start; k <= pD->m_spectral_end; k++) { + s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_ac_tab[component_id]]); + r = s >> 4; + s &= 15; + if (s) { + if ((k += r) > 63) return pD->stop_decoding(JPGD_DECODE_ERROR); + r = pD->get_bits_no_markers(s); + s = JPGD_HUFF_EXTEND(r, s); + p[g_ZAG[k]] = static_cast(static_cast(s) << pD->m_successive_low); + } else { + if (r == 15) { + if ((k += 15) > 63) return pD->stop_decoding(JPGD_DECODE_ERROR); + } else { + pD->m_eob_run = 1 << r; + if (r) pD->m_eob_run += pD->get_bits_no_markers(r); + pD->m_eob_run--; + break; + } + } + } + return true; +} + + +bool jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y) +{ + int s, k, r; + int p1 = 1 << pD->m_successive_low; + int m1 = static_cast(-1) << pD->m_successive_low; + jpgd_block_t *p = pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y); + + k = pD->m_spectral_start; + + if (pD->m_eob_run == 0) { + for ( ; k <= pD->m_spectral_end; k++) { + s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_ac_tab[component_id]]); + r = s >> 4; + s &= 15; + if (s) { + if (s != 1) return pD->stop_decoding(JPGD_DECODE_ERROR); + if (pD->get_bits_no_markers(1)) s = p1; + else s = m1; + } else { + if (r != 15) { + pD->m_eob_run = 1 << r; + if (r) pD->m_eob_run += pD->get_bits_no_markers(r); + break; + } + } + + do { + jpgd_block_t *this_coef = p + g_ZAG[k & 63]; + + if (*this_coef != 0) { + if (pD->get_bits_no_markers(1)) { + if ((*this_coef & p1) == 0) { + if (*this_coef >= 0) *this_coef = static_cast(*this_coef + p1); + else *this_coef = static_cast(*this_coef + m1); + } + } + } else { + if (--r < 0) break; + } + k++; + } while (k <= pD->m_spectral_end); + + if ((s) && (k < 64)) { + p[g_ZAG[k]] = static_cast(s); + } + } + } + + if (pD->m_eob_run > 0) { + for ( ; k <= pD->m_spectral_end; k++) { + jpgd_block_t *this_coef = p + g_ZAG[k & 63]; // logical AND to shut up static code analysis + + if (*this_coef != 0) { + if (pD->get_bits_no_markers(1)) { + if ((*this_coef & p1) == 0) { + if (*this_coef >= 0) *this_coef = static_cast(*this_coef + p1); + else *this_coef = static_cast(*this_coef + m1); + } + } + } + } + pD->m_eob_run--; + } + return true; +} + + +// Decode a scan in a progressively encoded image. +bool jpeg_decoder::decode_scan(pDecode_block_func decode_block_func) +{ + int mcu_row, mcu_col, mcu_block; + int block_x_mcu[JPGD_MAX_COMPONENTS], m_block_y_mcu[JPGD_MAX_COMPONENTS]; + + memset(m_block_y_mcu, 0, sizeof(m_block_y_mcu)); + + for (mcu_col = 0; mcu_col < m_mcus_per_col; mcu_col++) { + int component_num, component_id; + memset(block_x_mcu, 0, sizeof(block_x_mcu)); + + for (mcu_row = 0; mcu_row < m_mcus_per_row; mcu_row++) { + int block_x_mcu_ofs = 0, block_y_mcu_ofs = 0; + + if ((m_restart_interval) && (m_restarts_left == 0)) { + if (!process_restart()) return false; + } + + for (mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++) { + component_id = m_mcu_org[mcu_block]; + if (!decode_block_func(this, component_id, block_x_mcu[component_id] + block_x_mcu_ofs, m_block_y_mcu[component_id] + block_y_mcu_ofs)) return false; + + if (m_comps_in_scan == 1) block_x_mcu[component_id]++; + else { + if (++block_x_mcu_ofs == m_comp_h_samp[component_id]) { + block_x_mcu_ofs = 0; + + if (++block_y_mcu_ofs == m_comp_v_samp[component_id]) { + block_y_mcu_ofs = 0; + block_x_mcu[component_id] += m_comp_h_samp[component_id]; + } + } + } + } + m_restarts_left--; + } + + if (m_comps_in_scan == 1) m_block_y_mcu[m_comp_list[0]]++; + else { + for (component_num = 0; component_num < m_comps_in_scan; component_num++) { + component_id = m_comp_list[component_num]; + m_block_y_mcu[component_id] += m_comp_v_samp[component_id]; + } + } + } + return true; +} + + +// Decode a progressively encoded image. +bool jpeg_decoder::init_progressive() +{ + int i; + + if (m_comps_in_frame == 4) return stop_decoding(JPGD_UNSUPPORTED_COLORSPACE); + + // Allocate the coefficient buffers. + for (i = 0; i < m_comps_in_frame; i++) { + m_dc_coeffs[i] = coeff_buf_open(m_max_mcus_per_row * m_comp_h_samp[i], m_max_mcus_per_col * m_comp_v_samp[i], 1, 1); + m_ac_coeffs[i] = coeff_buf_open(m_max_mcus_per_row * m_comp_h_samp[i], m_max_mcus_per_col * m_comp_v_samp[i], 8, 8); + } + + while (true) { + int dc_only_scan, refinement_scan; + pDecode_block_func decode_block_func; + + if (!init_scan()) break; + + dc_only_scan = (m_spectral_start == 0); + refinement_scan = (m_successive_high != 0); + + if ((m_spectral_start > m_spectral_end) || (m_spectral_end > 63)) return stop_decoding(JPGD_BAD_SOS_SPECTRAL); + + if (dc_only_scan) { + if (m_spectral_end) return stop_decoding(JPGD_BAD_SOS_SPECTRAL); + } else if (m_comps_in_scan != 1) return stop_decoding(JPGD_BAD_SOS_SPECTRAL); // AC scans can only contain one component + + if ((refinement_scan) && (m_successive_low != m_successive_high - 1)) return stop_decoding(JPGD_BAD_SOS_SUCCESSIVE); + + if (dc_only_scan) { + if (refinement_scan) decode_block_func = decode_block_dc_refine; + else decode_block_func = decode_block_dc_first; + } else { + if (refinement_scan) decode_block_func = decode_block_ac_refine; + else decode_block_func = decode_block_ac_first; + } + if (!decode_scan(decode_block_func)) return false; + m_bits_left = 16; + get_bits(16); + get_bits(16); + } + + m_comps_in_scan = m_comps_in_frame; + + for (i = 0; i < m_comps_in_frame; i++) { + m_comp_list[i] = i; + } + + calc_mcu_block_order(); + + return true; +} + + +bool jpeg_decoder::init_sequential() +{ + if (!init_scan()) return stop_decoding(JPGD_UNEXPECTED_MARKER); + return true; +} + + +bool jpeg_decoder::decode_start() +{ + if (!init_frame()) return false; + if (m_progressive_flag) return init_progressive(); + return init_sequential(); +} + + +void jpeg_decoder::decode_init(jpeg_decoder_stream *pStream) +{ + init(pStream); + locate_sof_marker(); +} + + +jpeg_decoder::jpeg_decoder(jpeg_decoder_stream *pStream) +{ + decode_init(pStream); +} + + +int jpeg_decoder::begin_decoding() +{ + if (m_ready_flag) return JPGD_SUCCESS; + if (m_error_code) return JPGD_FAILED; + if (!decode_start()) return JPGD_FAILED; + m_ready_flag = true; + + return JPGD_SUCCESS; +} + + +jpeg_decoder::~jpeg_decoder() +{ + free_all_blocks(); +} + + +void jpeg_decoder_file_stream::close() +{ + if (m_pFile) { + fclose(m_pFile); + m_pFile = nullptr; + } + m_eof_flag = false; + m_error_flag = false; +} + + +jpeg_decoder_file_stream::~jpeg_decoder_file_stream() +{ + close(); +} + + +bool jpeg_decoder_file_stream::open(const char *Pfilename) +{ + close(); + + m_eof_flag = false; + m_error_flag = false; + +#if defined(_MSC_VER) + m_pFile = nullptr; + fopen_s(&m_pFile, Pfilename, "rb"); +#else + m_pFile = fopen(Pfilename, "rb"); +#endif + return m_pFile != nullptr; +} + + +int jpeg_decoder_file_stream::read(uint8_t *pBuf, int max_bytes_to_read, bool *pEOF_flag) +{ + if (!m_pFile) return -1; + + if (m_eof_flag) { + *pEOF_flag = true; + return 0; + } + + if (m_error_flag) return -1; + + int bytes_read = static_cast(fread(pBuf, 1, max_bytes_to_read, m_pFile)); + if (bytes_read < max_bytes_to_read) { + if (ferror(m_pFile)) { + m_error_flag = true; + return -1; + } + m_eof_flag = true; + *pEOF_flag = true; + } + return bytes_read; +} + + +bool jpeg_decoder_mem_stream::open(const uint8_t *pSrc_data, uint32_t size) +{ + close(); + m_pSrc_data = pSrc_data; + m_ofs = 0; + m_size = size; + return true; +} + + +int jpeg_decoder_mem_stream::read(uint8_t *pBuf, int max_bytes_to_read, bool *pEOF_flag) +{ + *pEOF_flag = false; + if (!m_pSrc_data) return -1; + + uint32_t bytes_remaining = m_size - m_ofs; + if ((uint32_t)max_bytes_to_read > bytes_remaining) { + max_bytes_to_read = bytes_remaining; + *pEOF_flag = true; + } + memcpy(pBuf, m_pSrc_data + m_ofs, max_bytes_to_read); + m_ofs += max_bytes_to_read; + + return max_bytes_to_read; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +jpeg_decoder* jpgdHeader(const char* data, int size, int* width, int* height) +{ + auto decoder = new jpeg_decoder(new jpeg_decoder_mem_stream((const uint8_t*)data, size)); + if (decoder->get_error_code() != JPGD_SUCCESS) { + delete(decoder); + return nullptr; + } + + if (width) *width = decoder->get_width(); + if (height) *height = decoder->get_height(); + + return decoder; +} + + +jpeg_decoder* jpgdHeader(const char* filename, int* width, int* height) +{ + auto fileStream = new jpeg_decoder_file_stream(); + if (!fileStream->open(filename)) { + delete(fileStream); + return nullptr; + } + + auto decoder = new jpeg_decoder(fileStream); + if (decoder->get_error_code() != JPGD_SUCCESS) { + delete(decoder); + return nullptr; + } + + if (width) *width = decoder->get_width(); + if (height) *height = decoder->get_height(); + + return decoder; +} + + +void jpgdDelete(jpeg_decoder* decoder) +{ + delete(decoder); +} + + +unsigned char* jpgdDecompress(jpeg_decoder* decoder, ColorSpace cs) +{ + if (!decoder || decoder->begin_decoding() != JPGD_SUCCESS) return nullptr; + + auto bgra = (cs == ColorSpace::ABGR8888S || cs == ColorSpace::ABGR8888); + auto channel = 4; //OPTIMIZE: jpg is 3 channel format, not really need 4 channel components. + auto width = decoder->get_width(); + auto height = decoder->get_height(); + //auto actual_comps = decoder->get_num_components(); + const auto stride = width * channel; + auto ret = tvg::malloc(stride * height); + auto dst = ret; + + for (int y = 0; y < height; y++) { + uint8_t* src = nullptr; + if (decoder->decode((const void**)&src) != JPGD_SUCCESS) { + tvg::free(ret); + return nullptr; + } + if (decoder->get_num_components() == 3) { + if (bgra) { + memcpy(dst, src, stride); + dst += stride; + } else { + for (int x = 0; x < width; x++, src += 4, dst += 4) { + dst[0] = src[2]; + dst[1] = src[1]; + dst[2] = src[0]; + dst[3] = 255; + } + } + } else if (decoder->get_num_components() == 1) { + for (int x = 0; x < width; x++, src++, dst += 4) { + dst[0] = *src; + dst[1] = *src; + dst[2] = *src; + dst[3] = 255; + } + } + } + return ret; +} diff --git a/components/thorvg-main/src/loaders/jpg/tvgJpgd.h b/components/thorvg-main/src/loaders/jpg/tvgJpgd.h new file mode 100644 index 0000000..1bff5d9 --- /dev/null +++ b/components/thorvg-main/src/loaders/jpg/tvgJpgd.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// jpgd.h - C++ class for JPEG decompression. +// Public domain, Rich Geldreich +#ifndef _TVG_JPGD_H_ +#define _TVG_JPGD_H_ + +class jpeg_decoder; + +jpeg_decoder* jpgdHeader(const char* data, int size, int* width, int* height); +jpeg_decoder* jpgdHeader(const char* filename, int* width, int* height); +unsigned char* jpgdDecompress(jpeg_decoder* decoder, ColorSpace cs); +void jpgdDelete(jpeg_decoder* decoder); + +#endif //_TVG_JPGD_H_ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp new file mode 100644 index 0000000..6127ae6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp @@ -0,0 +1,634 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jerryscript.h" + +#include + +#include "ecma-eval.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-init-finalize.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "jcontext.h" + +/** \addtogroup jerry Jerry engine interface + * @{ + */ + + +/** + * Turn on API availability + * + * @return void + */ +static inline void +jerry_api_enable (void) +{ +#ifndef JERRY_NDEBUG + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_ENABLED; +#endif /* JERRY_NDEBUG */ +} /* jerry_make_api_available */ + +/** + * Turn off API availability + * + * @return void + */ +static inline void +jerry_api_disable (void) +{ +#ifndef JERRY_NDEBUG + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_API_ENABLED; +#endif /* JERRY_NDEBUG */ +} /* jerry_make_api_unavailable */ + +/** + * Create an API compatible return value. + * + * @return return value for Jerry API functions + */ +static jerry_value_t +jerry_return (const jerry_value_t value) /**< return value */ +{ + if (ECMA_IS_VALUE_ERROR (value)) + { + return ecma_create_exception_from_context (); + } + + return value; +} /* jerry_return */ + +/** + * Jerry engine initialization + */ +void +jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ +{ +#if JERRY_EXTERNAL_CONTEXT + size_t total_size = jerry_port_context_alloc (sizeof (jerry_context_t)); + JERRY_UNUSED (total_size); +#endif /* JERRY_EXTERNAL_CONTEXT */ + + jerry_context_t *context_p = &JERRY_CONTEXT_STRUCT; + memset (context_p, 0, sizeof (jerry_context_t)); + +#if JERRY_EXTERNAL_CONTEXT && !JERRY_SYSTEM_ALLOCATOR + uint32_t heap_start_offset = JERRY_ALIGNUP (sizeof (jerry_context_t), JMEM_ALIGNMENT); + uint8_t *heap_p = ((uint8_t *) context_p) + heap_start_offset; + uint32_t heap_size = JERRY_ALIGNDOWN (total_size - heap_start_offset, JMEM_ALIGNMENT); + + JERRY_ASSERT (heap_p + heap_size <= ((uint8_t *) context_p) + total_size); + + context_p->heap_p = (jmem_heap_t *) heap_p; + context_p->heap_size = heap_size; +#endif /* JERRY_EXTERNAL_CONTEXT && !JERRY_SYSTEM_ALLOCATOR */ + + JERRY_CONTEXT (jerry_init_flags) = flags; + + jerry_api_enable (); + + jmem_init (); + ecma_init (); +} /* jerry_init */ + +/** + * Terminate Jerry engine + */ +void +jerry_cleanup (void) +{ + for (jerry_context_data_header_t *this_p = JERRY_CONTEXT (context_data_p); this_p != NULL; this_p = this_p->next_p) + { + if (this_p->manager_p->deinit_cb) + { + void *data = (this_p->manager_p->bytes_needed > 0) ? JERRY_CONTEXT_DATA_HEADER_USER_DATA (this_p) : NULL; + this_p->manager_p->deinit_cb (data); + } + } + + ecma_free_all_enqueued_jobs (); + ecma_finalize (); + jerry_api_disable (); + + for (jerry_context_data_header_t *this_p = JERRY_CONTEXT (context_data_p), *next_p = NULL; this_p != NULL; + this_p = next_p) + { + next_p = this_p->next_p; + + if (this_p->manager_p->finalize_cb) + { + void *data = (this_p->manager_p->bytes_needed > 0) ? JERRY_CONTEXT_DATA_HEADER_USER_DATA (this_p) : NULL; + this_p->manager_p->finalize_cb (data); + } + + jmem_heap_free_block (this_p, sizeof (jerry_context_data_header_t) + this_p->manager_p->bytes_needed); + } + + jmem_finalize (); +#if JERRY_EXTERNAL_CONTEXT + jerry_port_context_free (); +#endif /* JERRY_EXTERNAL_CONTEXT */ +} /* jerry_cleanup */ + +/** + * Perform eval + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return result of eval, may be error value. + */ +jerry_value_t +jerry_eval (const jerry_char_t *source_p, /**< source code */ + size_t source_size, /**< length of source code */ + uint32_t flags) /**< jerry_parse_opts_t flags */ +{ + parser_source_char_t source_char; + source_char.source_p = source_p; + source_char.source_size = source_size; + + return jerry_return (ecma_op_eval_chars_buffer ((void *) &source_char, flags)); +} /* jerry_eval */ + +/** + * Get global object + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return api value of global object + */ +jerry_value_t +jerry_current_realm (void) +{ + ecma_object_t *global_obj_p = ecma_builtin_get_global (); + ecma_ref_object (global_obj_p); + return ecma_make_object_value (global_obj_p); +} /* jerry_current_realm */ + +/** + * Check if the specified value is an error or abort value. + * + * @return true - if the specified value is an error value, + * false - otherwise + */ +bool +jerry_value_is_exception (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_exception (value); +} /* jerry_value_is_exception */ + +/** + * Check if the specified value is number. + * + * @return true - if the specified value is number, + * false - otherwise + */ +bool +jerry_value_is_number (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_number (value); +} /* jerry_value_is_number */ + +/** + * Check if the specified value is object. + * + * @return true - if the specified value is object, + * false - otherwise + */ +bool +jerry_value_is_object (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_object (value); +} /* jerry_value_is_object */ + +/** + * Check if the specified value is string. + * + * @return true - if the specified value is string, + * false - otherwise + */ +bool +jerry_value_is_string (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_string (value); +} /* jerry_value_is_string */ + +/** + * Check if the specified value is undefined. + * + * @return true - if the specified value is undefined, + * false - otherwise + */ +bool +jerry_value_is_undefined (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_undefined (value); +} /* jerry_value_is_undefined */ + +/** + * Get number from the specified value as a double. + * + * @return stored number as double + */ +float +jerry_value_as_number (const jerry_value_t value) /**< api value */ +{ + return (float) ecma_get_number_from_value (value); +} /* jerry_value_as_number */ + +/** + * Call ToObject operation on the api value. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return converted object value - if success + * thrown error - otherwise + */ +jerry_value_t +jerry_value_to_object (const jerry_value_t value) /**< input value */ +{ + return jerry_return (ecma_op_to_object (value)); +} /* jerry_value_to_object */ + +/** + * Call the ToString ecma builtin operation on the api value. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return converted string value - if success + * thrown error - otherwise + */ +jerry_value_t +jerry_value_to_string (const jerry_value_t value) /**< input value */ +{ + ecma_string_t *str_p = ecma_op_to_string (value); + return ecma_make_string_value (str_p); +} /* jerry_value_to_string */ + +/** + * Convert any number to int32 number. + * + * Note: + * For non-number values 0 is returned. + * + * @return int32 representation of the number. + */ +int32_t +jerry_value_as_int32 (const jerry_value_t value) /**< input value */ +{ + return ecma_number_to_int32 (ecma_get_number_from_value (value)); +} /* jerry_value_as_int32 */ + +/** + * Convert any number to uint32 number. + * + * Note: + * For non-number values 0 is returned. + * + * @return uint32 representation of the number. + */ +uint32_t +jerry_value_as_uint32 (const jerry_value_t value) /**< input value */ +{ + return ecma_number_to_uint32 (ecma_get_number_from_value (value)); +} /* jerry_value_as_uint32 */ + +/** + * Release ownership of the argument value + */ +void +jerry_value_free (jerry_value_t value) /**< value */ +{ + ecma_free_value (value); +} /* jerry_value_free */ + +/** + * Create a jerry_value_t representing a boolean value from the given boolean parameter. + * + * @return value of the created boolean + */ +jerry_value_t +jerry_boolean (bool value) /**< bool value from which a jerry_value_t will be created */ +{ + return ecma_make_boolean_value (value); +} /* jerry_boolean */ + +/** + * Create an external function object + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return value of the constructed function object + */ +jerry_value_t +jerry_function_external (jerry_external_handler_t handler) /**< native handler + * for the function */ +{ + ecma_object_t *func_obj_p = ecma_op_create_external_function_object (handler); + return ecma_make_object_value (func_obj_p); +} /* jerry_function_external */ + +/** + * Creates a jerry_value_t representing a number value. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return jerry_value_t created from the given double argument. + */ +jerry_value_t +jerry_number (float value) /**< double value from which a jerry_value_t will be created */ +{ + return ecma_make_number_value ((ecma_number_t) value); +} /* jerry_number */ + +/** + * Creates a jerry_value_t representing an undefined value. + * + * @return value of undefined + */ +jerry_value_t +jerry_undefined (void) +{ + return ECMA_VALUE_UNDEFINED; +} /* jerry_undefined */ + +/** + * Create new JavaScript object, like with new Object(). + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return value of the created object + */ +jerry_value_t +jerry_object (void) +{ + return ecma_make_object_value (ecma_op_create_object_object_noarg ()); +} /* jerry_object */ + +/** + * Create string value from the input zero-terminated ASCII string. + * + * @return created string + */ +jerry_value_t +jerry_string_sz (const char *str_p) /**< pointer to string */ +{ + const jerry_char_t *data_p = (const jerry_char_t *) str_p; + return jerry_string (data_p, lit_zt_utf8_string_size (data_p), JERRY_ENCODING_CESU8); +} /* jerry_string_sz */ + +/** + * Create a string value from the input buffer using the specified encoding. + * The content of the buffer is assumed to be valid in the specified encoding, it's the callers responsibility to + * validate the input. + * + * See also: jerry_validate_string + * + * @return created string + */ +jerry_value_t +jerry_string (const jerry_char_t *buffer_p, /**< pointer to buffer */ + jerry_size_t buffer_size, /**< buffer size */ + jerry_encoding_t encoding) /**< buffer encoding */ +{ + ecma_string_t *ecma_str_p = NULL; + //JERRY_ASSERT (jerry_validate_string (buffer_p, buffer_size, encoding)); + + switch (encoding) + { + case JERRY_ENCODING_CESU8: + { + ecma_str_p = ecma_new_ecma_string_from_utf8 (buffer_p, buffer_size); + break; + } + case JERRY_ENCODING_UTF8: + { + ecma_str_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (buffer_p, buffer_size); + break; + } + default: + { + return jerry_undefined(); + } + } + + return ecma_make_string_value (ecma_str_p); +} /* jerry_string */ + +/** + * Get length of a string value + * + * @return number of characters in the string + * 0 - if value is not a string + */ +jerry_length_t +jerry_string_length (const jerry_value_t value) /**< input string */ +{ + return ecma_string_get_length (ecma_get_string_from_value (value)); +} /* jerry_string_length */ + +/** + * Copy the characters of a string into the specified buffer using the specified encoding. The string is truncated to + * fit the buffer. If the value is not a string, nothing will be copied to the buffer. + * + * @return number of bytes copied to the buffer + */ +jerry_size_t +jerry_string_to_buffer (const jerry_value_t value, /**< input string value */ + jerry_encoding_t encoding, /**< output encoding */ + jerry_char_t *buffer_p, /**< [out] output characters buffer */ + jerry_size_t buffer_size) /**< size of output buffer */ +{ + ecma_string_t *str_p = ecma_get_string_from_value (value); + return ecma_string_copy_to_buffer (str_p, (lit_utf8_byte_t *) buffer_p, buffer_size, encoding); +} /* jerry_string_to_char_buffer */ + +/** + * Get value of a property to the specified object with the given name. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return value of the property - if success + * value marked with error flag - otherwise + */ +jerry_value_t +jerry_object_get (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name (string value) */ +{ + jerry_value_t ret_value = ecma_op_object_get (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key)); + return jerry_return (ret_value); +} /* jerry_object_get */ + +/** + * Get value of a property to the specified object with the given name. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return value of the property - if success + * value marked with error flag - otherwise + */ +jerry_value_t +jerry_object_get_sz (const jerry_value_t object, /**< object value */ + const char *key_p) /**< property key */ +{ + jerry_value_t key_str = jerry_string_sz (key_p); + jerry_value_t result = jerry_object_get (object, key_str); + ecma_free_value (key_str); + return result; +} /* jerry_object_get */ + +/** + * Get value by an index from the specified object. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return value of the property specified by the index - if success + * value marked with error flag - otherwise + */ +jerry_value_t +jerry_object_get_index (const jerry_value_t object, /**< object value */ + uint32_t index) /**< index to be written */ +{ + ecma_value_t ret_value = ecma_op_object_get_by_index (ecma_get_object_from_value (object), index); + return jerry_return (ret_value); +} /* jerry_object_get_index */ + +/** + * Set a property to the specified object with the given name. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return true value - if the operation was successful + * value marked with error flag - otherwise + */ +jerry_value_t +jerry_object_set (jerry_value_t object, /**< object value */ + const jerry_value_t key, /**< property name (string value) */ + const jerry_value_t value) /**< value to set */ +{ + return jerry_return (ecma_op_object_put (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key), value, true)); +} /* jerry_object_set */ + +/** + * Set a property to the specified object with the given name. + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return true value - if the operation was successful + * value marked with error flag - otherwise + */ +jerry_value_t +jerry_object_set_sz (jerry_value_t object, /**< object value */ + const char *key_p, /**< property key */ + const jerry_value_t value) /**< value to set */ +{ + jerry_value_t key_str = jerry_string_sz (key_p); + jerry_value_t result = jerry_object_set (object, key_str, value); + ecma_free_value (key_str); + return result; +} /* jerry_object_set */ + +/** + * Set indexed value in the specified object + * + * Note: + * returned value must be freed with jerry_value_free, when it is no longer needed. + * + * @return true value - if the operation was successful + * value marked with error flag - otherwise + */ +jerry_value_t +jerry_object_set_index (jerry_value_t object, /**< object value */ + uint32_t index, /**< index to be written */ + const jerry_value_t value) /**< value to set */ +{ + ecma_value_t ret_value = ecma_op_object_put_by_index (ecma_get_object_from_value (object), index, value, true); + return jerry_return (ret_value); +} /* jerry_object_set_index */ + +/** + * Get native pointer and its type information, associated with the given native type info. + * + * Note: + * If native pointer is present, its type information is returned in out_native_pointer_p + * + * @return found native pointer, + * or NULL + */ +void * +jerry_object_get_native_ptr (const jerry_value_t object, /**< object to get native pointer from */ + const jerry_object_native_info_t *native_info_p) /**< the type info + * of the native pointer */ +{ + if (!ecma_is_value_object (object)) + { + return NULL; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (object); + ecma_native_pointer_t *native_pointer_p = ecma_get_native_pointer_value (obj_p, (jerry_object_native_info_t *) native_info_p); + + if (native_pointer_p == NULL) + { + return NULL; + } + + return native_pointer_p->native_p; +} /* jerry_object_get_native_ptr */ + +/** + * Set native pointer and an optional type info for the specified object. + * + * + * Note: + * If native pointer was already set for the object, its value is updated. + * + * Note: + * If a non-NULL free callback is specified in the native type info, + * it will be called by the garbage collector when the object is freed. + * Referred values by this method must have at least 1 reference. (Correct API usage satisfies this condition) + * The type info always overwrites the previous value, so passing + * a NULL value deletes the current type info. + */ +void +jerry_object_set_native_ptr (jerry_value_t object, /**< object to set native pointer in */ + const jerry_object_native_info_t *native_info_p, /**< object's native type info */ + void *native_pointer_p) /**< native pointer */ +{ + if (ecma_is_value_object (object)) + { + ecma_object_t *object_p = ecma_get_object_from_value (object); + + ecma_create_native_pointer_property (object_p, native_pointer_p, native_info_p); + } +} /* jerry_object_set_native_ptr */ + + +/** + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/api/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/api/meson.build new file mode 100644 index 0000000..b20f50c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/api/meson.build @@ -0,0 +1,8 @@ +source_file = [ + 'jerryscript.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-alloc.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-alloc.cpp new file mode 100644 index 0000000..0a39565 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-alloc.cpp @@ -0,0 +1,232 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" + +#include "ecma-gc.h" +#include "ecma-globals.h" + +#include "jmem.h" +#include "jrt.h" + +JERRY_STATIC_ASSERT ((sizeof (ecma_property_value_t) == sizeof (ecma_value_t)), + size_of_ecma_property_value_t_must_be_equal_to_size_of_ecma_value_t); +JERRY_STATIC_ASSERT (((sizeof (ecma_property_value_t) - 1) & sizeof (ecma_property_value_t)) == 0, + size_of_ecma_property_value_t_must_be_power_of_2); + +JERRY_STATIC_ASSERT ((sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <= sizeof (uint64_t)), + size_of_ecma_extended_object_part_must_be_less_than_or_equal_to_8_bytes); + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types + * @{ + */ + +/** + * Implementation of routines for allocation/freeing memory for ECMA data types. + * + * All allocation routines from this module have the same structure: + * 1. Try to allocate memory. + * 2. If allocation was successful, return pointer to the allocated block. + * 3. Run garbage collection. + * 4. Try to allocate memory. + * 5. If allocation was successful, return pointer to the allocated block; + * else - shutdown engine. + */ + +/** + * Allocate memory for ecma-number + * + * @return pointer to allocated memory + */ +ecma_number_t * +ecma_alloc_number (void) +{ + return (ecma_number_t *) jmem_pools_alloc (sizeof (ecma_number_t)); +} /* ecma_alloc_number */ + +/** + * Dealloc memory from an ecma-number + * + * @return void + */ +void +ecma_dealloc_number (ecma_number_t *number_p) /**< number to be freed */ +{ + jmem_pools_free ((uint8_t *) number_p, sizeof (ecma_number_t)); +} /* ecma_dealloc_number */ + +/** + * Allocate memory for ecma-object + * + * @return pointer to allocated memory + */ +ecma_object_t * +ecma_alloc_object (void) +{ + return (ecma_object_t *) jmem_pools_alloc (sizeof (ecma_object_t)); +} /* ecma_alloc_object */ + +/** + * Dealloc memory from an ecma-object + * + * @return void + */ +void +ecma_dealloc_object (ecma_object_t *object_p) /**< object to be freed */ +{ + jmem_pools_free (object_p, sizeof (ecma_object_t)); +} /* ecma_dealloc_object */ + +/** + * Allocate memory for extended object + * + * @return pointer to allocated memory + */ +ecma_extended_object_t * +ecma_alloc_extended_object (size_t size) /**< size of object */ +{ + return (ecma_extended_object_t *) jmem_heap_alloc_block (size); +} /* ecma_alloc_extended_object */ + +/** + * Dealloc memory of an extended object + * + * @return void + */ +void +ecma_dealloc_extended_object (ecma_object_t *object_p, /**< extended object */ + size_t size) /**< size of object */ +{ + jmem_heap_free_block (object_p, size); +} /* ecma_dealloc_extended_object */ + +/** + * Allocate memory for ecma-string descriptor + * + * @return pointer to allocated memory + */ +ecma_string_t * +ecma_alloc_string (void) +{ + return (ecma_string_t *) jmem_pools_alloc (sizeof (ecma_string_t)); +} /* ecma_alloc_string */ + +/** + * Dealloc memory from ecma-string descriptor + * + * @return void + */ +void +ecma_dealloc_string (ecma_string_t *string_p) /**< string to be freed */ +{ + jmem_pools_free (string_p, sizeof (ecma_string_t)); +} /* ecma_dealloc_string */ + +/** + * Allocate memory for extended ecma-string descriptor + * + * @return pointer to allocated memory + */ +ecma_extended_string_t * +ecma_alloc_extended_string (void) +{ + return (ecma_extended_string_t *) jmem_heap_alloc_block (sizeof (ecma_extended_string_t)); +} /* ecma_alloc_extended_string */ + +/** + * Dealloc memory from extended ecma-string descriptor + * + * @return void + */ +void +ecma_dealloc_extended_string (ecma_extended_string_t *ext_string_p) /**< extended string to be freed */ +{ + jmem_heap_free_block (ext_string_p, sizeof (ecma_extended_string_t)); +} /* ecma_dealloc_extended_string */ + +/** + * Allocate memory for external ecma-string descriptor + * + * @return pointer to allocated memory + */ +ecma_external_string_t * +ecma_alloc_external_string (void) +{ + return (ecma_external_string_t *) jmem_heap_alloc_block (sizeof (ecma_external_string_t)); +} /* ecma_alloc_external_string */ + +/** + * Dealloc memory from external ecma-string descriptor + * + * @return void + */ +void +ecma_dealloc_external_string (ecma_external_string_t *ext_string_p) /**< external string to be freed */ +{ + jmem_heap_free_block (ext_string_p, sizeof (ecma_external_string_t)); +} /* ecma_dealloc_external_string */ + +/** + * Allocate memory for an string with character data + * + * @return pointer to allocated memory + */ +ecma_string_t * +ecma_alloc_string_buffer (size_t size) /**< size of string */ +{ + return (ecma_string_t *) jmem_heap_alloc_block (size); +} /* ecma_alloc_string_buffer */ + +/** + * Dealloc memory of a string with character data + * + * @return void + */ +void +ecma_dealloc_string_buffer (ecma_string_t *string_p, /**< string with data */ + size_t size) /**< size of string */ +{ + jmem_heap_free_block (string_p, size); +} /* ecma_dealloc_string_buffer */ + +/** + * Allocate memory for ecma-property pair + * + * @return pointer to allocated memory + */ +ecma_property_pair_t * +ecma_alloc_property_pair (void) +{ + return (ecma_property_pair_t *) jmem_heap_alloc_block (sizeof (ecma_property_pair_t)); +} /* ecma_alloc_property_pair */ + +/** + * Dealloc memory of an ecma-property + * + * @return void + */ +void +ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p) /**< property pair to be freed */ +{ + jmem_heap_free_block (property_pair_p, sizeof (ecma_property_pair_t)); +} /* ecma_dealloc_property_pair */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-alloc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-alloc.h new file mode 100644 index 0000000..a5af9d1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-alloc.h @@ -0,0 +1,129 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ALLOC_H +#define ECMA_ALLOC_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types + * @{ + */ + +/** + * Allocate memory for ecma-object + * + * @return pointer to allocated memory + */ +ecma_object_t *ecma_alloc_object (void); + +/** + * Dealloc memory from an ecma-object + */ +void ecma_dealloc_object (ecma_object_t *object_p); + +/** + * Allocate memory for extended object + * + * @return pointer to allocated memory + */ +ecma_extended_object_t *ecma_alloc_extended_object (size_t size); + +/** + * Dealloc memory of an extended object + */ +void ecma_dealloc_extended_object (ecma_object_t *object_p, size_t size); + +/** + * Allocate memory for ecma-number + * + * @return pointer to allocated memory + */ +ecma_number_t *ecma_alloc_number (void); + +/** + * Dealloc memory from an ecma-number + */ +void ecma_dealloc_number (ecma_number_t *number_p); + +/** + * Allocate memory for ecma-string descriptor + * + * @return pointer to allocated memory + */ +ecma_string_t *ecma_alloc_string (void); + +/** + * Dealloc memory from ecma-string descriptor + */ +void ecma_dealloc_string (ecma_string_t *string_p); + +/** + * Allocate memory for extended ecma-string descriptor + * + * @return pointer to allocated memory + */ +ecma_extended_string_t *ecma_alloc_extended_string (void); + +/** + * Dealloc memory from extended ecma-string descriptor + */ +void ecma_dealloc_extended_string (ecma_extended_string_t *string_p); + +/** + * Allocate memory for external ecma-string descriptor + * + * @return pointer to allocated memory + */ +ecma_external_string_t *ecma_alloc_external_string (void); + +/** + * Dealloc memory from external ecma-string descriptor + */ +void ecma_dealloc_external_string (ecma_external_string_t *string_p); + +/** + * Allocate memory for string with character data + * + * @return pointer to allocated memory + */ +ecma_string_t *ecma_alloc_string_buffer (size_t size); + +/** + * Dealloc memory of a string with character data + */ +void ecma_dealloc_string_buffer (ecma_string_t *string_p, size_t size); + +/** + * Allocate memory for ecma-property pair + * + * @return pointer to allocated memory + */ +ecma_property_pair_t *ecma_alloc_property_pair (void); + +/** + * Dealloc memory from an ecma-property pair + */ +void ecma_dealloc_property_pair (ecma_property_pair_t *property_pair_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_ALLOC_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-error-messages.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-error-messages.inc.h new file mode 100644 index 0000000..fe70fbc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-error-messages.inc.h @@ -0,0 +1,743 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-strings.py script + * from ecma-error-messages.ini. Do not edit! */ + +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_GROUP, "Invalid group") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ESCAPE, "Invalid escape") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_ATOMICS || JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INVALID_LENGTH, "Invalid length") +#endif /* JERRY_BUILTIN_ATOMICS \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INVALID_OFFSET, "Invalid offset") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_OBJECT_EXPECTED, "Object expected") +#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARGUMENT, "Invalid argument") +#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ENCODING, "Invalid encoding") +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_NOTHING_TO_REPEAT, "Nothing to repeat") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_AN_OBJECT, "Expected an object") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_CAPABILITY, "Invalid capability") +#if JERRY_BUILTIN_STRING +ECMA_ERROR_DEF (ECMA_ERR_INVALID_CODE_POINT, "Invalid code point") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_QUANTIFIER, "Invalid quantifier") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_NO_SOURCE_ARGUMENT, "No source argument") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_UNTERMINATED_GROUP, "Unterminated group") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_FUNCTION, "Expected a function") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_UTF8_STRING, "Invalid UTF8 string") +#if JERRY_BUILTIN_STRING +ECMA_ERROR_DEF (ECMA_ERR_INVALID_COUNT_VALUE, "Invalid count value") +#endif /* JERRY_BUILTIN_STRING */ +#if !(JERRY_BUILTIN_REALMS) +ECMA_ERROR_DEF (ECMA_ERR_REALMS_ARE_DISABLED, "Realms are disabled") +#endif /* !(JERRY_BUILTIN_REALMS) */ +ECMA_ERROR_DEF (ECMA_ERR_UNDEFINED_REFERENCE, "Undefined reference") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARRAY_LENGTH, "Invalid Array length") +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_REGEXP_FLAGS, "Invalid RegExp flags") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_STACK_LIMIT_EXCEEDED, "Stack limit exceeded") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_WEAKREF +ECMA_ERROR_DEF (ECMA_ERR_TARGET_IS_NOT_OBJECT, "Target is not Object") +#endif /* JERRY_BUILTIN_WEAKREF */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_BIGINT_VALUE_EXPECTED, "BigInt value expected") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_BINDING_CANNOT_SET, "Binding cannot be set") +#if JERRY_BUILTIN_STRING +ECMA_ERROR_DEF (ECMA_ERR_INVALID_STRING_, "Invalid string length") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_KEY_MUST_BE_AN_OBJECT, "Key must be an object") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_MISSING_ARRAY_ELEMENT, "Missing Array element") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_WEAKREF +ECMA_ERROR_DEF (ECMA_ERR_TARGET_IS_NOT_WEAKREF, "Target is not weakRef") +#endif /* JERRY_BUILTIN_WEAKREF */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TARGET_NOT_EXTENSIBLE, "Target not extensible") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_ANNEXB +ECMA_ERROR_DEF (ECMA_ERR_GETTER_IS_NOT_CALLABLE, "Getter is not callable") +#endif /* JERRY_BUILTIN_ANNEXB */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_HANDLER_CANNOT_BE_NULL, "Handler cannot be null") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_INVALID_UTF8_CHARACTER, "Invalid UTF8 character") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_UTF8_CODEPOINT, "Invalid UTF8 codepoint") +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_INVALID_CONTAINER_TYPE, "Invalid container type") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INVALID_RANGE_OF_INDEX, "Invalid range of index") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if !(JERRY_BUILTIN_PROXY) +ECMA_ERROR_DEF (ECMA_ERR_PROXY_IS_NOT_SUPPORTED, "Proxy is not supported") +#endif /* !(JERRY_BUILTIN_PROXY) */ +#if !(JERRY_BUILTIN_REALMS) +ECMA_ERROR_DEF (ECMA_ERR_REALM_IS_NOT_AVAILABLE, "Realm is not available") +#endif /* !(JERRY_BUILTIN_REALMS) */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_BIGINT_ZERO_DIVISION, "BigInt division by zero") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_AN_ARRAYBUFFER, "Expected an ArrayBuffer") +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_CHARACTER_CLASS, "Invalid character class") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ESCAPE_SEQUENCE, "Invalid escape sequence") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_SNAPSHOT_EXEC +ECMA_ERROR_DEF (ECMA_ERR_INVALID_SNAPSHOT_FORMAT, "Invalid snapshot format") +#endif /* JERRY_SNAPSHOT_EXEC */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_LONE_QUANTIFIER_BRACKET, "Lone quantifier bracket") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_OBJECT_CANNOT_BE_FROZEN, "Object cannot be frozen") +ECMA_ERROR_DEF (ECMA_ERR_OBJECT_CANNOT_BE_SEALED, "Object cannot be sealed") +#endif /* JERRY_BUILTIN_PROXY */ +#if !(JERRY_BUILTIN_REGEXP) +ECMA_ERROR_DEF (ECMA_ERR_REGEXP_IS_NOT_SUPPORTED, "RegExp is not supported") +#endif /* !(JERRY_BUILTIN_REGEXP) */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_UNMATCHED_CLOSE_BRACKET, "Unmatched close bracket") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_NOT_MODULE, "Argument is not a module") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_SET_PROTOTYPE, "Cannot set [[Prototype]]") +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_INVALID_NEW_ARRAY_LENGTH, "Invalid new Array length") +#endif /* JERRY_BUILTIN_ARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_IS_NOT_CALLABLE, "Iterator is not callable") +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_MODULE_IS_IN_ERROR_STATE, "Module is in error state") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_REJECT_MUST_BE_UNDEFINED, "Reject must be undefined") +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_REQUEST_IS_NOT_AVAILABLE, "Request is not available") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT, "Argument is not an object") +#if JERRY_BUILTIN_ATOMICS +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_NOT_SUPPORTED, "Argument is not supported") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_STRING +ECMA_ERROR_DEF (ECMA_ERR_INVALID_CODE_POINT_ERROR, "Error: Invalid code point") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INVALID_TYPEDARRAY_LENGTH, "Invalid TypedArray length") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_INVALID_HEXADECIMAL_VALUE, "Invalid hexadecimal value") +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_IS_NOT_AN_OBJECT, "Iterator is not an object") +ECMA_ERROR_DEF (ECMA_ERR_RESOLVE_MUST_BE_UNDEFINED, "Resolve must be undefined") +#if JERRY_SNAPSHOT_SAVE +ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_BUFFER_SMALL, "Snapshot buffer too small") +#endif /* JERRY_SNAPSHOT_SAVE */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_UNEXPECTED_END_OF_PATTERN, "Unexpected end of pattern") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_SNAPSHOT_SAVE +ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE, "Unsupported compiled code") +#endif /* JERRY_SNAPSHOT_SAVE */ +#if !(JERRY_BUILTIN_BIGINT) +ECMA_ERROR_DEF (ECMA_ERR_BIGINT_NOT_SUPPORTED, "BigInt support is disabled") +#endif /* !(JERRY_BUILTIN_BIGINT) */ +#if JERRY_BUILTIN_DATAVIEW +ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_DATAVIEW_OBJECT, "Expected a DataView object") +#endif /* JERRY_BUILTIN_DATAVIEW */ +ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_FUNCTION_OBJECT, "Expected a function object") +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARRAYBUFFER_LENGTH, "Invalid ArrayBuffer length") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if !(JERRY_MODULE_SYSTEM) +ECMA_ERROR_DEF (ECMA_ERR_MODULE_NOT_SUPPORTED, "Module support is disabled") +#endif /* !(JERRY_MODULE_SYSTEM) */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_OBJECT_IS_NOT_A_TYPEDARRAY, "Object is not a TypedArray") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_RECEIVER_MUST_BE_AN_OBJECT, "Receiver must be an object") +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_BIGINT_SERIALIZED, "BigInt cannot be serialized") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_IS_NOT_AN_OBJECT, "Container is not an object.") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_HEX_ESCAPE_SEQUENCE, "Invalid hex escape sequence") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_INVALID_SPECIES_CONSTRUCTOR, "Invalid species constructor") +ECMA_ERROR_DEF (ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH, "Proxy trap returned falsish") +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_MIN_GREATER_THAN_MAX, "Quantifier error: min > max") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_SYMBOL_IS_NOT_A_CONSTRUCTOR, "Symbol is not a constructor") +#if JERRY_BUILTIN_REFLECT +ECMA_ERROR_DEF (ECMA_ERR_TARGET_IS_NOT_A_CONSTRUCTOR, "Target is not a constructor") +#endif /* JERRY_BUILTIN_REFLECT */ +ECMA_ERROR_DEF (ECMA_ERR_ACCESSOR_WRITABLE, "Accessors cannot be writable") +#if !(JERRY_BUILTIN_DATAVIEW) +ECMA_ERROR_DEF (ECMA_ERR_DATA_VIEW_NOT_SUPPORTED, "DataView support is disabled") +#endif /* !(JERRY_BUILTIN_DATAVIEW) */ +#if JERRY_BUILTIN_DATE +ECMA_ERROR_DEF (ECMA_ERR_DATE_MUST_BE_A_FINITE_NUMBER, "Date must be a finite number") +#endif /* JERRY_BUILTIN_DATE */ +ECMA_ERROR_DEF (ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED, "Local variable is redeclared") +ECMA_ERROR_DEF (ECMA_ERR_UNSUPPORTED_BINARY_OPERATION, "Unsupported binary operation") +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_UNTERMINATED_CHARACTER_CLASS, "Unterminated character class") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_ARRAYBUFFER_IS_DETACHED, "ArrayBuffer has been detached") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_NOT_AN_OBJECT, "Constructor must be an object") +#if !(JERRY_BUILTIN_CONTAINER) +ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_NOT_SUPPORTED, "Container support is disabled") +#endif /* !(JERRY_BUILTIN_CONTAINER) */ +#if JERRY_BUILTIN_REALMS +ECMA_ERROR_DEF (ECMA_ERR_FIRST_ARGUMENT_IS_NOT_A_REALM, "First argument is not a realm") +#endif /* JERRY_BUILTIN_REALMS */ +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INCOMPATIBLE_TYPEDARRAY_TYPES, "Incompatible TypedArray types") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_TYPE_FOR_TYPEDARRAY, "Incorrect type for TypedArray") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_INVALID_OR_OUT_OF_RANGE_INDEX, "Invalid or out-of-range index") +#if JERRY_SNAPSHOT_SAVE +ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE, "Maximum snapshot size reached") +#endif /* JERRY_SNAPSHOT_SAVE */ +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_MODULE_CANNOT_BE_INSTANTIATED, "Module cannot be instantiated") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_SPECIES_MUST_BE_A_CONSTRUCTOR, "Species must be a constructor") +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_IS_NOT_A_PROXY, "Argument is not a Proxy object") +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_NOT_ARRAY_BUFFER, "Argument is not an ArrayBuffer") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_MAP_REQUIRES_NEW, "Constructor Map requires 'new'") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_SET_REQUIRES_NEW, "Constructor Set requires 'new'") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_MODULE_MUST_BE_IN_LINKED_STATE, "Module must be in linked state") +ECMA_ERROR_DEF (ECMA_ERR_UNKNOWN_EXPORT, "Native module export not found") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_PASSED_ARGUMENT_IS_NOT_A_REALM, "Passed argument is not a realm") +ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_METHOD_IS_NOT_WRITABLE, "Private method is not writable") +#if JERRY_BUILTIN_BIGINT || JERRY_BUILTIN_NUMBER +ECMA_ERROR_DEF (ECMA_ERR_RADIX_IS_OUT_OF_RANGE, "Radix must be between 2 and 36") +#endif /* JERRY_BUILTIN_BIGINT \ +|| JERRY_BUILTIN_NUMBER */ +#if !(JERRY_SNAPSHOT_EXEC) +ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_EXEC_DISABLED, "Snapshot execution is disabled") +#endif /* !(JERRY_SNAPSHOT_EXEC) */ +#if !(JERRY_BUILTIN_TYPEDARRAY) +ECMA_ERROR_DEF (ECMA_ERR_TYPED_ARRAY_NOT_SUPPORTED, "TypedArray support is disabled") +#endif /* !(JERRY_BUILTIN_TYPEDARRAY) */ +ECMA_ERROR_DEF (ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING, "Unicode surrogate pair missing") +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_INVALID_CONTROL_ESCAPE_SEQUENCE, "Invalid control escape sequence") +ECMA_ERROR_DEF (ECMA_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE, "Invalid unicode escape sequence") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_NEXT_IS_NOT_CALLABLE, "Iterator 'next' is not callable") +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT, "Iterator value is not an object") +ECMA_ERROR_DEF (ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE, "Resolve method must be callable") +#if !(JERRY_SNAPSHOT_SAVE) +ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_SAVE_DISABLED, "Snapshot generation is disabled") +#endif /* !(JERRY_SNAPSHOT_SAVE) */ +#if !(JERRY_PARSER) +ECMA_ERROR_DEF (ECMA_ERR_PARSER_NOT_SUPPORTED, "Source code parsing is disabled") +#endif /* !(JERRY_PARSER) */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_MUST_RETURN_WITH_AN_OBJECT, "Trap must return with an object") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_UNSUPPORTED_CONTAINER_OPERATION, "Unsupported container operation") +#endif /* JERRY_BUILTIN_CONTAINER */ +ECMA_ERROR_DEF (ECMA_ERR_METHOD_RETURN_IS_NOT_CALLABLE, "method 'return' is not callable") +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_PROMISE, "Argument 'this' is not a Promise") +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT, "Argument 'this' is not an object") +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_SYMBOL, "Argument 'this' must be a Symbol") +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_CALLBACK_RESULT_NOT_MODULE, "Callback result must be a module") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_CLASS_CONSTRUCTOR_REQUIRES_NEW, "Class constructor requires 'new'") +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_COMPARE_FUNC_NOT_CALLABLE, "Compare function is not callable") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_PROXY_REQUIRES_NEW, "Constructor Proxy requires 'new'") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_EXPECTED_A_CONFIGURABLE_PROPERTY, "Expected a configurable property") +ECMA_ERROR_DEF (ECMA_ERR_FIRST_PARAMETER_MUST_BE_CALLABLE, "First parameter must be callable") +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_FUNCTION_ADD_ORSET_IS_NOT_CALLABLE, "Function add/set is not callable") +#endif /* JERRY_BUILTIN_CONTAINER */ +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_RESULT_IS_NOT_AN_OBJECT, "Iterator result is not an object") +#if (JERRY_STACK_LIMIT != 0) +ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED, "Maximum call stack size exceeded") +#endif /* (JERRY_STACK_LIMIT != 0) */ +ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_STRING_LENGTH_IS_REACHED, "Maximum string length is reached") +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_MODULE_MUST_BE_IN_UNLINKED_STATE, "Module must be in unlinked state") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_SNAPSHOT_EXEC +ECMA_ERROR_DEF (ECMA_ERR_STATIC_SNAPSHOTS_ARE_NOT_ENABLED, "Static snapshots are not enabled") +#endif /* JERRY_SNAPSHOT_EXEC */ +#if JERRY_BUILTIN_WEAKREF +ECMA_ERROR_DEF (ECMA_ERR_WEAKREF_TARGET_MUST_BE_AN_OBJECT, "WeakRef target must be an object") +#endif /* JERRY_BUILTIN_WEAKREF */ +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_FUNCTION, "Argument 'this' is not a function") +#if JERRY_BUILTIN_ATOMICS +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_NOT_SHARED_ARRAY_BUFFER, "Argument is not SharedArrayBuffer") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_CONTAINER || JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE, "Callback function is not callable") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_CONTAINER \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED, "Initial value cannot be undefined") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER +ECMA_ERROR_DEF (ECMA_ERR_INVALID_SHARED_ARRAYBUFFER_LENGTH, "Invalid Shared ArrayBuffer length") +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +ECMA_ERROR_DEF (ECMA_ERR_INVALID_TYPE_FOR_CONSTRUCTOR_CALL, "Invalid type for constructor call") +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE, "Iterator 'throw' is not available") +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_NAMESPACE_OBJECT_IS_NOT_AVAILABLE, "Namespace object is not available") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_PROXY_TARGET_IS_NOT_A_CONSTRUCTOR, "Proxy target is not a constructor") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_REALMS +ECMA_ERROR_DEF (ECMA_ERR_SECOND_ARGUMENT_MUST_BE_AN_OBJECT, "Second argument must be an object") +#endif /* JERRY_BUILTIN_REALMS */ +#if JERRY_BUILTIN_DATAVIEW +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_BUFFER_NOT_OBJECT, "Argument 'buffer' is not an object") +#endif /* JERRY_BUILTIN_DATAVIEW */ +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR, "Argument 'this' is not an iterator") +ECMA_ERROR_DEF (ECMA_ERR_VALUE_MSG, "Argument cannot be marked as error") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_PROMISE_REQUIRES_NEW, "Constructor Promise requires 'new'") +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_WEAKMAP_REQUIRES_NEW, "Constructor WeakMap requires 'new'") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_WEAKSET_REQUIRES_NEW, "Constructor WeakSet requires 'new'") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_MAXIMUM_TYPEDARRAY_SIZE_IS_REACHED, "Maximum TypedArray size is reached") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_THE_GIVEN_ARGUMENT_IS_NOT_A_SYMBOL, "The given argument is not a Symbol") +ECMA_ERROR_DEF (ECMA_ERR_PARAMETER_REJECT_MUST_BE_CALLABLE, "'reject' parameter must be callable") +#if JERRY_BUILTIN_ATOMICS || JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY, "Argument 'this' is not a TypedArray") +#endif /* JERRY_BUILTIN_ATOMICS \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_SNAPSHOT_SAVE +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS, "Cannot allocate memory for literals") +#endif /* JERRY_SNAPSHOT_SAVE */ +ECMA_ERROR_DEF (ECMA_ERR_INVOKE_NULLABLE_SUPER_METHOD, "Cannot invoke nullable super method") +#if JERRY_BUILTIN_DATAVIEW +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_DATAVIEW_REQUIRES_NEW, "Constructor DataView requires 'new'") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_WEAKREF +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_WEAKREF_REQUIRES_NEW, "Constructor WeakRef requires 'new'.") +#endif /* JERRY_BUILTIN_WEAKREF */ +ECMA_ERROR_DEF (ECMA_ERR_SUPER_BINDING_MUST_BE_A_CONSTRUCTOR, "Super binding must be a constructor") +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_VALUE_CANNOT_BE_CONVERTED_TO_BIGINT, "Value cannot be converted to BigInt") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_PARAMETER_RESOLVE_MUST_BE_CALLABLE, "'resolve' parameter must be callable") +#if JERRY_BUILTIN_DATE +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_DATE_OBJECT, "Argument 'this' is not a Date object") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_CONSTRUCTOR, "Argument 'this' is not a constructor") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_BIGINT_FUNCTION_NOT_CONSTRUCTOR, "BigInt function is not a constructor") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTED_OBJECT_IS_NOT_TYPEDARRAY, "Constructed object is not TypedArray") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_INT8_ARRAY_REQUIRES_NEW, "Constructor Int8Array requires 'new'") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT, "Container is not a container object.") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_DATE +ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARGUMENT_TYPE_IN_TOPRIMITIVE, "Invalid argument type in toPrimitive") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_METHODS_INVOKE_WITH_NEW, "Methods cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_MODULE_EXPORTS_MUST_BE_STRING_VALUES, "Module exports must be string values") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_PROTOTYPE_IS_NEITHER_OBJECT_NOR_NULL, "Prototype is neither object nor null") +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_THE_MAPFN_ARGUMENT_IS_NOT_CALLABLE, "The 'mapfn' argument is not callable") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_THE_TWO_DESCRIPTORS_ARE_INCOMPATIBLE, "The two descriptors are incompatible") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_WRONG_ARGS_MSG, "This type of argument is not allowed") +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_CONTAINER_NEEDED, "Value is not a Container or Iterator") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP, "Argument 'this' is not a valid RegExp") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ARRAY_BUFFER_DETACHED, "ArrayBuffer has already been detached") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_BUILTIN_ROUTINES_HAVE_NO_CONSTRUCTOR, "Built-in routines have no constructor") +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_INT16_ARRAY_REQUIRES_NEW, "Constructor Int16Array requires 'new'") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_INT32_ARRAY_REQUIRES_NEW, "Constructor Int32Array requires 'new'") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT8_ARRAY_REQUIRES_NEW, "Constructor Uint8Array requires 'new'") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_SNAPSHOT_EXEC +ECMA_ERROR_DEF (ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM, "Function index is higher than maximum") +#endif /* JERRY_SNAPSHOT_EXEC */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_RANGE_OUT_OF_ORDER_IN_CHARACTER_CLASS, "Range out of order in character class") +#endif /* JERRY_BUILTIN_REGEXP */ +ECMA_ERROR_DEF (ECMA_ERR_RESULT_OF_DEFAULTVALUE_IS_INVALID, "Result of [[DefaultValue]] is invalid") +ECMA_ERROR_DEF (ECMA_ERR_RIGHT_VALUE_OF_IN_MUST_BE_AN_OBJECT, "Right value of 'in' must be an object") +#if !(JERRY_BUILTIN_SHAREDARRAYBUFFER) +ECMA_ERROR_DEF (ECMA_ERR_SHARED_ARRAYBUFFER_NOT_SUPPORTED, "SharedArrayBuffer support is disabled") +#endif /* !(JERRY_BUILTIN_SHAREDARRAYBUFFER) */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_RETURNED_NEITHER_OBJECT_NOR_NULL, "Trap returned neither object nor null") +ECMA_ERROR_DEF (ECMA_ERR_TRAP_WITH_DUPLICATED_ENTRIES, "Trap returned with duplicated entries") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_UNARY_PLUS_IS_NOT_ALLOWED_FOR_BIGINTS, "Unary plus is not allowed for BigInts") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_IS_NOT_AN_REGEXP, "Argument 'this' is not a RegExp object") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ALLOCATE_ARRAY_BUFFER, "Cannot allocate memory for ArrayBuffer") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_CONSTANT_BINDINGS_CANNOT_BE_REASSIGNED, "Constant bindings cannot be reassigned") +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_ARRAYBUFFER_REQUIRES_NEW, "Constructor ArrayBuffer requires 'new'") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT16_ARRAY_REQUIRES_NEW, "Constructor Uint16Array requires 'new'") +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT32_ARRAY_REQUIRES_NEW, "Constructor Uint32Array requires 'new'") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION, "Generator is currently under execution") +ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_RETURN_RESULT_IS_NOT_OBJECT, "Iterator 'return' result is not object") +ECMA_ERROR_DEF (ECMA_ERR_SEARCH_STRING_CANNOT_BE_OF_TYPE_REGEXP, "Search string can't be of type: RegExp") +ECMA_ERROR_DEF (ECMA_ERR_VALUE_RECEIVED_BY_YIELD_IS_NOT_OBJECT, "Value received by yield* is not object") +#if JERRY_BUILTIN_BOOLEAN +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_BOOLEAN_OBJECT, "Argument 'this' is not a Boolean object") +#endif /* JERRY_BUILTIN_BOOLEAN */ +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_DECLARE_SAME_PRIVATE_FIELD_TWICE, "Cannot declare same private field twice") +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_FLOAT32_ARRAY_REQUIRES_NEW, "Constructor Float32Array requires 'new'") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64 +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_FLOAT64_ARRAY_REQUIRES_NEW, "Constructor Float64Array requires 'new'") +#endif /* JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64 */ +ECMA_ERROR_DEF (ECMA_ERR_FUNCTION_PROTOTYPE_NOT_A_CONSTRUCTOR, "Function.prototype is not a constructor") +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE, "Imported binding shadows local variable") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_PROTOTYPE_FROM_REVOKED_PROXY_IS_INVALID, "Prototype from revoked Proxy is invalid") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_REGEXP && JERRY_BUILTIN_STRING +ECMA_ERROR_DEF (ECMA_ERR_REGEXP_ARGUMENT_SHOULD_HAVE_GLOBAL_FLAG, "RegExp argument should have global flag") +#endif /* JERRY_BUILTIN_REGEXP && JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_IS_NEITHER_AN_OBJECT_NOR_UNDEFINED, "Trap is neither an object nor undefined") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_PROMISE_RESOLVE_ITSELF, "A promise cannot be resolved with itself") +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_BIGINT64_ARRAY_REQUIRES_NEW, "Constructor BigInt64Array requires 'new'") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_MODULE_EXPORTS_MUST_BE_VALID_IDENTIFIERS, "Module exports must be valid identifiers") +#endif /* JERRY_MODULE_SYSTEM */ +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_GENERATOR_OBJECT, "Argument 'this' is not a generator object") +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_CANNOT_CONVERT_TO_OBJECT, "Argument cannot be converted to an object") +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_ALLOCATE_BIGINT_VALUE, "Cannot allocate memory for a BigInt value") +ECMA_ERROR_DEF (ECMA_ERR_CONVERT_BIGINT_TO_NUMBER, "Cannot convert a BigInt value to a number") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_CONVERT_SYMBOL_TO_NUMBER, "Cannot convert a Symbol value to a number") +ECMA_ERROR_DEF (ECMA_ERR_CONVERT_SYMBOL_TO_STRING, "Cannot convert a Symbol value to a string") +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_BIG_UINT64_ARRAY_REQUIRES_NEW, "Constructor BigUInt64Array requires 'new'") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_NUMBER +ECMA_ERROR_DEF (ECMA_ERR_FRACTION_DIGITS_OUT_OF_RANGE, "Fraction digits must be between 0 and 100") +#endif /* JERRY_BUILTIN_NUMBER */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_RETURN_VALUE_IS_NOT_AN_ARRAYBUFFER_OBJECT, "Return value is not an ArrayBuffer object") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_SUPER_CONSTRUCTOR_MAY_ONLY_BE_CALLED_ONCE, "Super constructor may only be called once") +ECMA_ERROR_DEF (ECMA_ERR_BINDING_NOT_EXIST_OR_UNINITIALIZED, "Binding does not exist or is uninitialised") +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_CONVERT_TO_OBJECT, "Cannot convert undefined or null to object") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_NUMBER +ECMA_ERROR_DEF (ECMA_ERR_PRECISION_DIGITS_MUST_BE_BETWEEN_IN_RANGE, "Precision digits must be between 1 and 100") +#endif /* JERRY_BUILTIN_NUMBER */ +ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_GETTER, "Private field was defined without a getter") +ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_SETTER, "Private field was defined without a setter") +ECMA_ERROR_DEF (ECMA_ERR_PROPERTY_NAME_IS_NEITHER_SYMBOL_NOR_STRING, "Property name is neither Symbol nor string") +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_STRING_CANNOT_BE_CONVERTED_TO_BIGINT_VALUE, "String cannot be converted to BigInt value") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_CONTAINER +ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_TYPE_CALL, "Operator called on incorrect container type") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE, "Reduce of empty Array with no initial value") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP_OBJECT, "Argument 'this' is not a valid RegExp object") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_ARRAY_BUFFER_OBJECT, "Argument 'this' is not an ArrayBuffer object") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_ARROW_FUNCTIONS_INVOKE_WITH_NEW, "Arrow functions cannot be invoked with 'new'") +ECMA_ERROR_DEF (ECMA_ERR_ASYNC_FUNCTIONS_INVOKE_WITH_NEW, "Async functions cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_SET_EXTENSIBLE_PROPERTY, "Cannot set [[Extensible]] property of object") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_SHAREDARRAYBUFFER_REQUIRES_NEW, "Constructor SharedArrayBuffer requires 'new'") +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONSTRUCTOR_UINT8_CLAMPED_ARRAY_REQUIRES_NEW, "Constructor Uint8ClampedArray requires 'new'") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_NEGATIVE_EXPONENT_IS_NOT_ALLOWED_FOR_BIGINTS, "Negative exponent is not allowed for BigInts") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_PROMISE_ALL_REMAINING_ELEMENTS_LIMIT_REACHED, "Promise.all remaining elements limit reached") +ECMA_ERROR_DEF (ECMA_ERR_VALUE_RECEIVED_BY_FOR_ASYNC_OF_IS_NOT_OBJECT, "Value received by for-async-of is not object") +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_INFINITY_OR_NAN_CANNOT_BE_CONVERTED_TO_BIGINT, "Infinity or NaN cannot be converted to BigInt") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_OPERATOR_DELETE_RETURNED_FALSE_IN_STRICT_MODE, "Operator delete returned false in strict mode") +ECMA_ERROR_DEF (ECMA_ERR_PROPERTY_PROTOTYPE_IS_NOT_AN_OBJECT, "Property 'prototype' is not an object or null") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_PROXY_HANDLER_IS_NULL_FOR_ISARRAY_OPERATION, "Proxy handler is null for 'isArray' operation") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_SNAPSHOT_SAVE +ECMA_ERROR_DEF (ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED, "Regular expression literals are not supported") +#endif /* JERRY_SNAPSHOT_SAVE */ +ECMA_ERROR_DEF (ECMA_ERR_RIGHT_VALUE_OF_INSTANCEOF_MUST_BE_AN_OBJECT, "Right value of 'instanceof' must be an object") +#if JERRY_SNAPSHOT_EXEC +ECMA_ERROR_DEF (ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY, "Static snapshots cannot be copied into memory") +#endif /* JERRY_SNAPSHOT_EXEC */ +#if JERRY_SNAPSHOT_SAVE +ECMA_ERROR_DEF (ECMA_ERR_TAGGED_TEMPLATE_LITERALS, "Unsupported feature: tagged template literals") +ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED, "Unsupported generate snapshot flags specified") +#endif /* JERRY_SNAPSHOT_SAVE */ +#if JERRY_SNAPSHOT_EXEC +ECMA_ERROR_DEF (ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED, "Unsupported snapshot exec flags are specified") +#endif /* JERRY_SNAPSHOT_EXEC */ +ECMA_ERROR_DEF (ECMA_ERR_VALUE_FOR_CLASS_HERITAGE_IS_NOT_A_CONSTRUCTOR, "Value for class heritage is not a constructor") +ECMA_ERROR_DEF (ECMA_ERR_TOO_MANY_ARGUMENTS_DECLARED_FOR_FUNCTION_APPLY, + "Too many arguments declared for Function.apply") +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_ACCESSOR_FUNCTIONS_INVOKE_WITH_NEW, "Accessor functions cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_MODULE_SYSTEM +ECMA_ERROR_DEF (ECMA_ERR_LINK_TO_MODULE_IN_ERROR_STATE, "Cannot link to a module which is in error state") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_ONLY_INTEGER_NUMBERS_CAN_BE_CONVERTED_TO_BIGINT, + "Only integer numbers can be converted to BigInt") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_TYPEDARRAY_INTRINSIC_DIRECTLY_CALLED, "TypedArray intrinsic cannot be directly called") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_UNSIGNED_RIGHT_SHIFT_IS_NOT_ALLOWED_FOR_BIGINTS, + "Unsigned right shift is not allowed for BigInts") +#endif /* JERRY_BUILTIN_BIGINT */ +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR, "Argument 'this' is not an async generator object") +ECMA_ERROR_DEF (ECMA_ERR_CLASS_EXTENDS_NOT_CONSTRUCTOR, "Class extends value is not a constructor or null") +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW, "Generator functions cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_BUILTIN_REGEXP +ECMA_ERROR_DEF (ECMA_ERR_RETURN_VALUE_OF_EXEC_MUST_BE_AN_OBJECT_OR_NULL, + "Return value of 'exec' must be an object or null") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_DATAVIEW +ECMA_ERROR_DEF (ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER, + "Start offset is outside the bounds of the buffer") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER, "Argument 'this' is not a SharedArrayBuffer object") +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +ECMA_ERROR_DEF (ECMA_ERR_CLASS_CONSTRUCTOR_NEW, "Class constructor cannot be invoked without 'new'") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_RETURN_PROXY_GET_TRAP, "Incorrect value is returned by a Proxy 'get' trap") +ECMA_ERROR_DEF (ECMA_ERR_INCORRECT_RETURN_PROXY_SET_TRAP, "Incorrect value is returned by a Proxy 'set' trap") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_CLASS_IS_NON_CONFIGURABLE, "Prototype property of a class is non-configurable") +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_PUSHING_TOO_HIGH_ELEMENT, "Pushing element over 2**53-1 length is disallowed") +#endif /* JERRY_BUILTIN_ARRAY */ +ECMA_ERROR_DEF (ECMA_ERR_THE_REQUESTED_PROPERTY_UPDATE_CANNOT_BE_PERFORMED, + "The requested property update cannot be performed") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_CONFIGURABLE_KEYS, + "Trap result did not include all configurable keys") +ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_TARGET_NOT_EXTENSIBLE, "Trap returned truish for target is not extensible") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_NUMBER +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_NUMBER, "Argument 'this' is not a number or a Number object") +#endif /* JERRY_BUILTIN_NUMBER */ +#if JERRY_BUILTIN_STRING +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_STRING_OBJECT, "Argument 'this' is not a string or a String object") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER_OBJECT, + "Argument 'this' is not an SharedArrayBuffer object") +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_ASYNC_ARROW_FUNCTIONS_INVOKE_WITH_NEW, "Async arrow functions cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_BUILTIN_ARRAY +ECMA_ERROR_DEF (ECMA_ERR_UNSHIFT_TOO_HIGH, "Unshift elements over 2**53-1 length is disallowed") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_NON_CONFIGURABLE_KEYS, + "Trap result did not include all non-configurable keys") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_ASYNC_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW, + "Async generator functions cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_BUILTIN_REFLECT +ECMA_ERROR_DEF (ECMA_ERR_REFLECT_EXPECTS_AN_OBJECT_AS_SECOND_ARGUMENT, + "Reflect.construct expects an object as second argument") +#endif /* JERRY_BUILTIN_REFLECT */ +#if JERRY_ERROR_MESSAGES +ECMA_ERROR_DEF (ECMA_ERR_SCRIPT_GLOBAL_FUNCTIONS_INVOKE_WITH_NEW, + "Script (global) functions cannot be invoked with 'new'") +#endif /* JERRY_ERROR_MESSAGES */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_CREATE_PROXY, "Cannot create Proxy with a non-object target or handler") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_DERIVED_CTOR_RETURN_NOR_OBJECT_OR_UNDEFINED, + "Derived constructors may only return object or undefined") +#if JERRY_SNAPSHOT_EXEC +ECMA_ERROR_DEF (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES, + "Invalid snapshot version or unsupported features present") +#endif /* JERRY_SNAPSHOT_EXEC */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_TYPEDARRAY_SMALLER_THAN_FILTER_CALL_RESULT, + "Constructed TypedArray is smaller than filter call result") +ECMA_ERROR_DEF (ECMA_ERR_DERIVED_ARRAY_BUFFER_CTOR_BUFFER_TOO_SMALL, + "Derived ArrayBuffer constructor created a too small buffer") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_EXTENSIBILITY, + "Trap result does not reflect extensibility of Proxy target") +ECMA_ERROR_DEF (ECMA_ERR_TRAP_EXTRA_KEYS_FOR_A_NON_EXTENSIBLE_TARGET, + "Trap returned extra keys for a non-extensible Proxy target") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_ARRAY_BUFFER_RETURNED_THIS_FROM_CONSTRUCTOR, + "ArrayBuffer subclass returned this from species constructor") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_DATAVIEW +ECMA_ERROR_DEF (ECMA_ERR_ARGUMENT_BUFFER_NOT_ARRAY_OR_SHARED_BUFFER, + "Argument 'buffer' is not an ArrayBuffer or SharedArrayBuffer") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_INEXTENSIBILITY, + "Trap result does not reflect inextensibility of Proxy target") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_TYPEDARRAY_INTRINSIC_CALLED_BY_NEW_EXPRESSION, + "TypedArray intrinsic cannot be called by a 'new' expression") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY +ECMA_ERROR_DEF (ECMA_ERR_CONTENTTYPE_RETURNED_TYPEDARRAY_NOT_MATCH_SOURCE, + "TypedArray returned by [[ContentType]] does not match source") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_BIGINT +ECMA_ERROR_DEF (ECMA_ERR_ALLOCATE_BIGINT_STRING, "Cannot allocate memory for a string representation of a BigInt value") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TARGET_NOT_EXTENSIBLE_DIFFERENT_PROTOTYPE_RETURNED, + "Target object is non-extensible and trap returned different prototype") +ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_ADDING_PROPERTY_NON_EXTENSIBLE_TARGET, + "Trap returned truish for adding property to the non-extensible target") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_READ_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT, + "Cannot read private member to an object whose class did not declare it") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_GIVEN_PROPERTY_IS_A_NON_CONFIGURABLE, + "Given property is a non-configurable data property on the proxy target") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_WRITE_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT, + "Cannot write private member to an object whose class did not declare it") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_FALSISH_PROPERTY_TARGET_NOT_EXTENSIBLE, + "Trap returned falsish for property but the proxy target is not extensible") +ECMA_ERROR_DEF (ECMA_ERR_PROXY_PROPERTY_NOT_CONFIGURABLE_NOT_HAVE_GETTER, + "Property of a Proxy is non-configurable and does not have a getter function") +ECMA_ERROR_DEF (ECMA_ERR_TARGET_PROPERTY_CONFIGURE_ACCESSOR_WITHOUT_SETTER, + "The property of a Proxy target is a non configurable accessor without a setter") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_LET_CONST_NOT_INITIALIZED, + "Variables declared by let/const must be initialized before reading their value") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_PROPERTY_NON_CONFIGURABLE, + "Trap returned truish for property which is non-configurable in the proxy target") +ECMA_ERROR_DEF (ECMA_ERR_TARGET_NOT_EXTENSIBLE_NOT_RETURNED_ITS_PROTOTYPE, + "Proxy target is non-extensible, but the trap did not return its actual prototype") +ECMA_ERROR_DEF (ECMA_ERR_TRAP_FALSISH_PROPERTY_NON_CONFIGURABLE, + "Trap returned falsish for property which exists in the proxy target as non-configurable") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_CALL_SUPER_CONSTRUCTOR_DERIVED_CLASS_BEFORE_THIS, + "Must call super constructor in derived class before accessing 'this' or returning from it") +#if JERRY_BUILTIN_PROXY +ECMA_ERROR_DEF (ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY, + "Trap returned truish for defining non-configurable property which is nonexistent in the target") +ECMA_ERROR_DEF ( + ECMA_ERR_TRAP_TRUISH_ADD_PROPERTY_INCOMPATIBLE_OTHER_PROP, + "Trap returned truish for adding property that is incompatible with the existing property in the target") +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_ERROR_DEF (ECMA_ERR_CANNOT_ACCESS_CALLER_CALLEE_ARGUMENTS, + "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the " + "arguments objects for calls to them") diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-error-messages.ini b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-error-messages.ini new file mode 100644 index 0000000..6c55bf0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-error-messages.ini @@ -0,0 +1,331 @@ +# Copyright JS Foundation and other contributors, http://js.foundation +# +# Licensed 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[ECMA_ERROR_MESSAGES] + +ECMA_ERR_CANNOT_ACCESS_CALLER_CALLEE_ARGUMENTS = "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them" +ECMA_ERR_PARAMETER_REJECT_MUST_BE_CALLABLE = "'reject' parameter must be callable" +ECMA_ERR_PARAMETER_RESOLVE_MUST_BE_CALLABLE = "'resolve' parameter must be callable" +ECMA_ERR_PROMISE_RESOLVE_ITSELF = "A promise cannot be resolved with itself" +ECMA_ERR_ACCESSOR_WRITABLE = "Accessors cannot be writable" +ECMA_ERR_ARGUMENT_BUFFER_NOT_ARRAY_OR_SHARED_BUFFER = "Argument 'buffer' is not an ArrayBuffer or SharedArrayBuffer" +ECMA_ERR_ARGUMENT_BUFFER_NOT_OBJECT = "Argument 'buffer' is not an object" +ECMA_ERR_ARGUMENT_THIS_NOT_ARRAY_BUFFER_OBJECT = "Argument 'this' is not an ArrayBuffer object" +ECMA_ERR_ARGUMENT_THIS_NOT_BOOLEAN_OBJECT = "Argument 'this' is not a Boolean object" +ECMA_ERR_ARGUMENT_THIS_NOT_DATE_OBJECT = "Argument 'this' is not a Date object" +ECMA_ERR_ARGUMENT_THIS_NOT_PROMISE = "Argument 'this' is not a Promise" +ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER = "Argument 'this' is not a SharedArrayBuffer object" +ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY = "Argument 'this' is not a TypedArray" +ECMA_ERR_ARGUMENT_THIS_NOT_CONSTRUCTOR = "Argument 'this' is not a constructor" +ECMA_ERR_ARGUMENT_THIS_NOT_FUNCTION = "Argument 'this' is not a function" +ECMA_ERR_ARGUMENT_THIS_NOT_GENERATOR_OBJECT = "Argument 'this' is not a generator object" +ECMA_ERR_ARGUMENT_THIS_NOT_NUMBER = "Argument 'this' is not a number or a Number object" +ECMA_ERR_ARGUMENT_THIS_NOT_STRING_OBJECT = "Argument 'this' is not a string or a String object" +ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP = "Argument 'this' is not a valid RegExp" +ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP_OBJECT = "Argument 'this' is not a valid RegExp object" +ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER_OBJECT = "Argument 'this' is not an SharedArrayBuffer object" +ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR = "Argument 'this' is not an async generator object" +ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR = "Argument 'this' is not an iterator" +ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT = "Argument 'this' is not an object" +ECMA_ERR_ARGUMENT_THIS_NOT_SYMBOL = "Argument 'this' must be a Symbol" +ECMA_ERR_ARGUMENT_CANNOT_CONVERT_TO_OBJECT = "Argument cannot be converted to an object" +ECMA_ERR_ARGUMENT_NOT_SHARED_ARRAY_BUFFER = "Argument is not SharedArrayBuffer" +ECMA_ERR_ARGUMENT_NOT_ARRAY_BUFFER = "Argument is not an ArrayBuffer" +ECMA_ERR_ARGUMENT_NOT_SUPPORTED = "Argument is not supported" +ECMA_ERR_ARRAY_BUFFER_DETACHED = "ArrayBuffer has already been detached" +ECMA_ERR_ARRAY_BUFFER_RETURNED_THIS_FROM_CONSTRUCTOR = "ArrayBuffer subclass returned this from species constructor" +ECMA_ERR_BIGINT_SERIALIZED = "BigInt cannot be serialized" +ECMA_ERR_BIGINT_ZERO_DIVISION = "BigInt division by zero" +ECMA_ERR_BIGINT_FUNCTION_NOT_CONSTRUCTOR = "BigInt function is not a constructor" +ECMA_ERR_BIGINT_VALUE_EXPECTED = "BigInt value expected" +ECMA_ERR_BINDING_CANNOT_SET = "Binding cannot be set" +ECMA_ERR_BINDING_NOT_EXIST_OR_UNINITIALIZED = "Binding does not exist or is uninitialised" +ECMA_ERR_BUILTIN_ROUTINES_HAVE_NO_CONSTRUCTOR = "Built-in routines have no constructor" +ECMA_ERR_CALLBACK_RESULT_NOT_MODULE = "Callback result must be a module" +ECMA_ERR_ALLOCATE_ARRAY_BUFFER = "Cannot allocate memory for ArrayBuffer" +ECMA_ERR_ALLOCATE_BIGINT_VALUE = "Cannot allocate memory for a BigInt value" +ECMA_ERR_ALLOCATE_BIGINT_STRING = "Cannot allocate memory for a string representation of a BigInt value" +ECMA_ERR_CONVERT_BIGINT_TO_NUMBER = "Cannot convert a BigInt value to a number" +ECMA_ERR_CONVERT_SYMBOL_TO_NUMBER = "Cannot convert a Symbol value to a number" +ECMA_ERR_CONVERT_SYMBOL_TO_STRING = "Cannot convert a Symbol value to a string" +ECMA_ERR_CANNOT_CREATE_PROXY = "Cannot create Proxy with a non-object target or handler" +ECMA_ERR_INVOKE_NULLABLE_SUPER_METHOD = "Cannot invoke nullable super method" +ECMA_ERR_LINK_TO_MODULE_IN_ERROR_STATE = "Cannot link to a module which is in error state" +ECMA_ERR_SET_EXTENSIBLE_PROPERTY = "Cannot set [[Extensible]] property of object" +ECMA_ERR_SET_PROTOTYPE = "Cannot set [[Prototype]]" +ECMA_ERR_CLASS_CONSTRUCTOR_REQUIRES_NEW = "Class constructor requires 'new'" +ECMA_ERR_CLASS_EXTENDS_NOT_CONSTRUCTOR = "Class extends value is not a constructor or null" +ECMA_ERR_COMPARE_FUNC_NOT_CALLABLE = "Compare function is not callable" +ECMA_ERR_CONSTANT_BINDINGS_CANNOT_BE_REASSIGNED = "Constant bindings cannot be reassigned" +ECMA_ERR_TYPEDARRAY_SMALLER_THAN_FILTER_CALL_RESULT = "Constructed TypedArray is smaller than filter call result" +ECMA_ERR_CONSTRUCTED_OBJECT_IS_NOT_TYPEDARRAY = "Constructed object is not TypedArray" +ECMA_ERR_CONSTRUCTOR_ARRAYBUFFER_REQUIRES_NEW = "Constructor ArrayBuffer requires 'new'" +ECMA_ERR_CONSTRUCTOR_BIGINT64_ARRAY_REQUIRES_NEW = "Constructor BigInt64Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_BIG_UINT64_ARRAY_REQUIRES_NEW = "Constructor BigUInt64Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_DATAVIEW_REQUIRES_NEW = "Constructor DataView requires 'new'" +ECMA_ERR_CONSTRUCTOR_FLOAT32_ARRAY_REQUIRES_NEW = "Constructor Float32Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_FLOAT64_ARRAY_REQUIRES_NEW = "Constructor Float64Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_INT16_ARRAY_REQUIRES_NEW = "Constructor Int16Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_INT32_ARRAY_REQUIRES_NEW = "Constructor Int32Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_INT8_ARRAY_REQUIRES_NEW = "Constructor Int8Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_MAP_REQUIRES_NEW = "Constructor Map requires 'new'" +ECMA_ERR_CONSTRUCTOR_PROMISE_REQUIRES_NEW = "Constructor Promise requires 'new'" +ECMA_ERR_CONSTRUCTOR_PROXY_REQUIRES_NEW = "Constructor Proxy requires 'new'" +ECMA_ERR_CONSTRUCTOR_SET_REQUIRES_NEW = "Constructor Set requires 'new'" +ECMA_ERR_CONSTRUCTOR_SHAREDARRAYBUFFER_REQUIRES_NEW = "Constructor SharedArrayBuffer requires 'new'" +ECMA_ERR_CONSTRUCTOR_UINT16_ARRAY_REQUIRES_NEW = "Constructor Uint16Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_UINT32_ARRAY_REQUIRES_NEW = "Constructor Uint32Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_UINT8_ARRAY_REQUIRES_NEW = "Constructor Uint8Array requires 'new'" +ECMA_ERR_CONSTRUCTOR_UINT8_CLAMPED_ARRAY_REQUIRES_NEW = "Constructor Uint8ClampedArray requires 'new'" +ECMA_ERR_CONSTRUCTOR_WEAKMAP_REQUIRES_NEW = "Constructor WeakMap requires 'new'" +ECMA_ERR_CONSTRUCTOR_WEAKREF_REQUIRES_NEW = "Constructor WeakRef requires 'new'." +ECMA_ERR_CONSTRUCTOR_WEAKSET_REQUIRES_NEW = "Constructor WeakSet requires 'new'" +ECMA_ERR_CONSTRUCTOR_NOT_AN_OBJECT = "Constructor must be an object" +ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT = "Container is not a container object." +ECMA_ERR_CONTAINER_IS_NOT_AN_OBJECT = "Container is not an object." +ECMA_ERR_DATE_MUST_BE_A_FINITE_NUMBER = "Date must be a finite number" +ECMA_ERR_DERIVED_ARRAY_BUFFER_CTOR_BUFFER_TOO_SMALL = "Derived ArrayBuffer constructor created a too small buffer" +ECMA_ERR_DERIVED_CTOR_RETURN_NOR_OBJECT_OR_UNDEFINED = "Derived constructors may only return object or undefined" +ECMA_ERR_INVALID_CODE_POINT_ERROR = "Error: Invalid code point" +ECMA_ERR_EXPECTED_A_DATAVIEW_OBJECT = "Expected a DataView object" +ECMA_ERR_EXPECTED_A_CONFIGURABLE_PROPERTY = "Expected a configurable property" +ECMA_ERR_EXPECTED_A_FUNCTION_OBJECT = "Expected a function object" +ECMA_ERR_EXPECTED_AN_ARRAYBUFFER = "Expected an ArrayBuffer" +ECMA_ERR_EXPECTED_AN_OBJECT = "Expected an object" +ECMA_ERR_FIRST_ARGUMENT_IS_NOT_A_REALM = "First argument is not a realm" +ECMA_ERR_FIRST_PARAMETER_MUST_BE_CALLABLE = "First parameter must be callable" +ECMA_ERR_FRACTION_DIGITS_OUT_OF_RANGE = "Fraction digits must be between 0 and 100" +ECMA_ERR_FUNCTION_ADD_ORSET_IS_NOT_CALLABLE = "Function add/set is not callable" +ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM = "Function index is higher than maximum" +ECMA_ERR_FUNCTION_PROTOTYPE_NOT_A_CONSTRUCTOR = "Function.prototype is not a constructor" +ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION = "Generator is currently under execution" +ECMA_ERR_GETTER_IS_NOT_CALLABLE = "Getter is not callable" +ECMA_ERR_GIVEN_PROPERTY_IS_A_NON_CONFIGURABLE = "Given property is a non-configurable data property on the proxy target" +ECMA_ERR_HANDLER_CANNOT_BE_NULL = "Handler cannot be null" +ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE = "Imported binding shadows local variable" +ECMA_ERR_INCOMPATIBLE_TYPEDARRAY_TYPES = "Incompatible TypedArray types" +ECMA_ERR_INCORRECT_TYPE_FOR_TYPEDARRAY = "Incorrect type for TypedArray" +ECMA_ERR_INCORRECT_RETURN_PROXY_GET_TRAP = "Incorrect value is returned by a Proxy 'get' trap" +ECMA_ERR_INCORRECT_RETURN_PROXY_SET_TRAP = "Incorrect value is returned by a Proxy 'set' trap" +ECMA_ERR_INFINITY_OR_NAN_CANNOT_BE_CONVERTED_TO_BIGINT = "Infinity or NaN cannot be converted to BigInt" +ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED = "Initial value cannot be undefined" +ECMA_ERR_INVALID_ARRAYBUFFER_LENGTH = "Invalid ArrayBuffer length" +ECMA_ERR_INVALID_JSON_FORMAT = "Invalid JSON format" +ECMA_ERR_INVALID_REGEXP_FLAGS = "Invalid RegExp flags" +ECMA_ERR_INVALID_SHARED_ARRAYBUFFER_LENGTH = "Invalid Shared ArrayBuffer length" +ECMA_ERR_INVALID_TYPEDARRAY_LENGTH = "Invalid TypedArray length" +ECMA_ERR_INVALID_UTF8_CHARACTER = "Invalid UTF8 character" +ECMA_ERR_INVALID_UTF8_CODEPOINT = "Invalid UTF8 codepoint" +ECMA_ERR_INVALID_UTF8_STRING = "Invalid UTF8 string" +ECMA_ERR_INVALID_ENCODING = "Invalid encoding" +ECMA_ERR_INVALID_ARGUMENT = "Invalid argument" +ECMA_ERR_INVALID_ARGUMENT_TYPE_IN_TOPRIMITIVE = "Invalid argument type in toPrimitive" +ECMA_ERR_INVALID_CAPABILITY = "Invalid capability" +ECMA_ERR_INVALID_CHARACTER_CLASS = "Invalid character class" +ECMA_ERR_INVALID_CODE_POINT = "Invalid code point" +ECMA_ERR_INVALID_CONTAINER_TYPE = "Invalid container type" +ECMA_ERR_INVALID_CONTROL_ESCAPE_SEQUENCE = "Invalid control escape sequence" +ECMA_ERR_INVALID_COUNT_VALUE = "Invalid count value" +ECMA_ERR_INVALID_ESCAPE = "Invalid escape" +ECMA_ERR_INVALID_ESCAPE_SEQUENCE = "Invalid escape sequence" +ECMA_ERR_INVALID_GROUP = "Invalid group" +ECMA_ERR_INVALID_HEX_ESCAPE_SEQUENCE = "Invalid hex escape sequence" +ECMA_ERR_INVALID_HEXADECIMAL_VALUE = "Invalid hexadecimal value" +ECMA_ERR_INVALID_LENGTH = "Invalid length" +ECMA_ERR_INVALID_NEW_ARRAY_LENGTH = "Invalid new Array length" +ECMA_ERR_INVALID_OFFSET = "Invalid offset" +ECMA_ERR_INVALID_OR_OUT_OF_RANGE_INDEX = "Invalid or out-of-range index" +ECMA_ERR_INVALID_QUANTIFIER = "Invalid quantifier" +ECMA_ERR_INVALID_RANGE_OF_INDEX = "Invalid range of index" +ECMA_ERR_INVALID_SCOPE_CHAIN_INDEX_FOR_EVAL = "Invalid scope chain index for eval" +ECMA_ERR_INVALID_SPECIES_CONSTRUCTOR = "Invalid species constructor" +ECMA_ERR_INVALID_STRING_ = "Invalid string length" +ECMA_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE = "Invalid unicode escape sequence" +ECMA_ERR_ITERATOR_NEXT_IS_NOT_CALLABLE = "Iterator 'next' is not callable" +ECMA_ERR_ITERATOR_RETURN_RESULT_IS_NOT_OBJECT = "Iterator 'return' result is not object" +ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE = "Iterator 'throw' is not available" +ECMA_ERR_ITERATOR_IS_NOT_AN_OBJECT = "Iterator is not an object" +ECMA_ERR_ITERATOR_IS_NOT_CALLABLE = "Iterator is not callable" +ECMA_ERR_ITERATOR_RESULT_IS_NOT_AN_OBJECT = "Iterator result is not an object" +ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT = "Iterator value is not an object" +ECMA_ERR_JSON_STRING_PARSE_ERROR = "JSON string parse error" +ECMA_ERR_JSON_STRINGIFY_ERROR = "JSON stringify error" +ECMA_ERR_KEY_MUST_BE_AN_OBJECT = "Key must be an object" +ECMA_ERR_LONE_QUANTIFIER_BRACKET = "Lone quantifier bracket" +ECMA_ERR_MAXIMUM_TYPEDARRAY_SIZE_IS_REACHED = "Maximum TypedArray size is reached" +ECMA_ERR_MAXIMUM_STRING_LENGTH_IS_REACHED = "Maximum string length is reached" +ECMA_ERR_MISSING_ARRAY_ELEMENT = "Missing Array element" +ECMA_ERR_MODULE_CANNOT_BE_INSTANTIATED = "Module cannot be instantiated" +ECMA_ERR_MODULE_EXPORTS_MUST_BE_STRING_VALUES = "Module exports must be string values" +ECMA_ERR_MODULE_EXPORTS_MUST_BE_VALID_IDENTIFIERS = "Module exports must be valid identifiers" +ECMA_ERR_MODULE_IS_IN_ERROR_STATE = "Module is in error state" +ECMA_ERR_MODULE_MUST_BE_IN_LINKED_STATE = "Module must be in linked state" +ECMA_ERR_MODULE_MUST_BE_IN_UNLINKED_STATE = "Module must be in unlinked state" +ECMA_ERR_CALL_SUPER_CONSTRUCTOR_DERIVED_CLASS_BEFORE_THIS = "Must call super constructor in derived class before accessing 'this' or returning from it" +ECMA_ERR_NAMESPACE_OBJECT_IS_NOT_AVAILABLE = "Namespace object is not available" +ECMA_ERR_NEGATIVE_EXPONENT_IS_NOT_ALLOWED_FOR_BIGINTS = "Negative exponent is not allowed for BigInts" +ECMA_ERR_NO_SOURCE_ARGUMENT = "No source argument" +ECMA_ERR_NOTHING_TO_REPEAT = "Nothing to repeat" +ECMA_ERR_OBJECT_CANNOT_BE_FROZEN = "Object cannot be frozen" +ECMA_ERR_OBJECT_CANNOT_BE_SEALED = "Object cannot be sealed" +ECMA_ERR_OBJECT_EXPECTED = "Object expected" +ECMA_ERR_OBJECT_IS_NOT_A_TYPEDARRAY = "Object is not a TypedArray" +ECMA_ERR_ONLY_INTEGER_NUMBERS_CAN_BE_CONVERTED_TO_BIGINT = "Only integer numbers can be converted to BigInt" +ECMA_ERR_OPERATOR_DELETE_RETURNED_FALSE_IN_STRICT_MODE = "Operator delete returned false in strict mode" +ECMA_ERR_PASSED_ARGUMENT_IS_NOT_A_REALM = "Passed argument is not a realm" +ECMA_ERR_PRECISION_DIGITS_MUST_BE_BETWEEN_IN_RANGE = "Precision digits must be between 1 and 100" +ECMA_ERR_PROMISE_ALL_REMAINING_ELEMENTS_LIMIT_REACHED = "Promise.all remaining elements limit reached" +ECMA_ERR_PROPERTY_PROTOTYPE_IS_NOT_AN_OBJECT = "Property 'prototype' is not an object or null" +ECMA_ERR_PROPERTY_NAME_IS_NEITHER_SYMBOL_NOR_STRING = "Property name is neither Symbol nor string" +ECMA_ERR_PROXY_PROPERTY_NOT_CONFIGURABLE_NOT_HAVE_GETTER = "Property of a Proxy is non-configurable and does not have a getter function" +ECMA_ERR_PROTOTYPE_FROM_REVOKED_PROXY_IS_INVALID = "Prototype from revoked Proxy is invalid" +ECMA_ERR_PROTOTYPE_IS_NEITHER_OBJECT_NOR_NULL = "Prototype is neither object nor null" +ECMA_ERR_PROXY_HANDLER_IS_NULL_FOR_ISARRAY_OPERATION = "Proxy handler is null for 'isArray' operation" +ECMA_ERR_PROXY_IS_NOT_SUPPORTED = "Proxy is not supported" +ECMA_ERR_TARGET_NOT_EXTENSIBLE_NOT_RETURNED_ITS_PROTOTYPE = "Proxy target is non-extensible, but the trap did not return its actual prototype" +ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH = "Proxy trap returned falsish" +ECMA_ERR_PUSHING_TOO_HIGH_ELEMENT = "Pushing element over 2**53-1 length is disallowed" +ECMA_ERR_MIN_GREATER_THAN_MAX = "Quantifier error: min > max" +ECMA_ERR_RADIX_IS_OUT_OF_RANGE = "Radix must be between 2 and 36" +ECMA_ERR_RANGE_OUT_OF_ORDER_IN_CHARACTER_CLASS = "Range out of order in character class" +ECMA_ERR_REALM_IS_NOT_AVAILABLE = "Realm is not available" +ECMA_ERR_REALMS_ARE_DISABLED = "Realms are disabled" +ECMA_ERR_REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE = "Reduce of empty Array with no initial value" +ECMA_ERR_REFLECT_EXPECTS_AN_OBJECT_AS_SECOND_ARGUMENT = "Reflect.construct expects an object as second argument" +ECMA_ERR_REGEXP_ARGUMENT_SHOULD_HAVE_GLOBAL_FLAG = "RegExp argument should have global flag" +ECMA_ERR_REGEXP_IS_NOT_SUPPORTED = "RegExp is not supported" +ECMA_ERR_REJECT_MUST_BE_UNDEFINED = "Reject must be undefined" +ECMA_ERR_REQUEST_IS_NOT_AVAILABLE = "Request is not available" +ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE = "Resolve method must be callable" +ECMA_ERR_RESOLVE_MUST_BE_UNDEFINED = "Resolve must be undefined" +ECMA_ERR_RESULT_OF_DEFAULTVALUE_IS_INVALID = "Result of [[DefaultValue]] is invalid" +ECMA_ERR_RETURN_VALUE_IS_NOT_AN_ARRAYBUFFER_OBJECT = "Return value is not an ArrayBuffer object" +ECMA_ERR_RETURN_VALUE_OF_EXEC_MUST_BE_AN_OBJECT_OR_NULL = "Return value of 'exec' must be an object or null" +ECMA_ERR_RIGHT_VALUE_OF_IN_MUST_BE_AN_OBJECT = "Right value of 'in' must be an object" +ECMA_ERR_RIGHT_VALUE_OF_INSTANCEOF_MUST_BE_AN_OBJECT = "Right value of 'instanceof' must be an object" +ECMA_ERR_SEARCH_STRING_CANNOT_BE_OF_TYPE_REGEXP = "Search string can't be of type: RegExp" +ECMA_ERR_SECOND_ARGUMENT_MUST_BE_AN_OBJECT = "Second argument must be an object" +ECMA_ERR_SPECIES_MUST_BE_A_CONSTRUCTOR = "Species must be a constructor" +ECMA_ERR_STACK_LIMIT_EXCEEDED = "Stack limit exceeded" +ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER = "Start offset is outside the bounds of the buffer" +ECMA_ERR_STATIC_SNAPSHOTS_ARE_NOT_ENABLED = "Static snapshots are not enabled" +ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY = "Static snapshots cannot be copied into memory" +ECMA_ERR_STRING_CANNOT_BE_CONVERTED_TO_BIGINT_VALUE = "String cannot be converted to BigInt value" +ECMA_ERR_SUPER_BINDING_MUST_BE_A_CONSTRUCTOR = "Super binding must be a constructor" +ECMA_ERR_SUPER_CONSTRUCTOR_MAY_ONLY_BE_CALLED_ONCE = "Super constructor may only be called once" +ECMA_ERR_SYMBOL_IS_NOT_A_CONSTRUCTOR = "Symbol is not a constructor" +ECMA_ERR_TARGET_IS_NOT_OBJECT = "Target is not Object" +ECMA_ERR_TARGET_IS_NOT_WEAKREF = "Target is not weakRef" +ECMA_ERR_TARGET_NOT_EXTENSIBLE = "Target not extensible" +ECMA_ERR_TARGET_NOT_EXTENSIBLE_DIFFERENT_PROTOTYPE_RETURNED = "Target object is non-extensible and trap returned different prototype" +ECMA_ERR_THE_MAPFN_ARGUMENT_IS_NOT_CALLABLE = "The 'mapfn' argument is not callable" +ECMA_ERR_THE_GIVEN_ARGUMENT_IS_NOT_A_SYMBOL = "The given argument is not a Symbol" +ECMA_ERR_TARGET_PROPERTY_CONFIGURE_ACCESSOR_WITHOUT_SETTER = "The property of a Proxy target is a non configurable accessor without a setter" +ECMA_ERR_THE_REQUESTED_PROPERTY_UPDATE_CANNOT_BE_PERFORMED = "The requested property update cannot be performed" +ECMA_ERR_THE_STRUCTURE_IS_CYCLICAL = "The structure is cyclical" +ECMA_ERR_THE_TWO_DESCRIPTORS_ARE_INCOMPATIBLE = "The two descriptors are incompatible" +ECMA_ERR_TOO_MANY_ARGUMENTS_DECLARED_FOR_FUNCTION_APPLY = "Too many arguments declared for Function.apply" +ECMA_ERR_TRAP_IS_NEITHER_AN_OBJECT_NOR_UNDEFINED = "Trap is neither an object nor undefined" +ECMA_ERR_TRAP_MUST_RETURN_WITH_AN_OBJECT = "Trap must return with an object" +ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_CONFIGURABLE_KEYS = "Trap result did not include all configurable keys" +ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_NON_CONFIGURABLE_KEYS = "Trap result did not include all non-configurable keys" +ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_EXTENSIBILITY = "Trap result does not reflect extensibility of Proxy target" +ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_INEXTENSIBILITY = "Trap result does not reflect inextensibility of Proxy target" +ECMA_ERR_TRAP_EXTRA_KEYS_FOR_A_NON_EXTENSIBLE_TARGET = "Trap returned extra keys for a non-extensible Proxy target" +ECMA_ERR_TRAP_FALSISH_PROPERTY_TARGET_NOT_EXTENSIBLE = "Trap returned falsish for property but the proxy target is not extensible" +ECMA_ERR_TRAP_FALSISH_PROPERTY_NON_CONFIGURABLE = "Trap returned falsish for property which exists in the proxy target as non-configurable" +ECMA_ERR_TRAP_RETURNED_NEITHER_OBJECT_NOR_NULL = "Trap returned neither object nor null" +ECMA_ERR_TRAP_TRUISH_ADDING_PROPERTY_NON_EXTENSIBLE_TARGET = "Trap returned truish for adding property to the non-extensible target" +ECMA_ERR_TRAP_TRUISH_ADD_PROPERTY_INCOMPATIBLE_OTHER_PROP = "Trap returned truish for adding property that is incompatible with the existing property in the target" +ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY = "Trap returned truish for defining non-configurable property which is nonexistent in the target" +ECMA_ERR_TRAP_TRUISH_PROPERTY_NON_CONFIGURABLE = "Trap returned truish for property which is non-configurable in the proxy target" +ECMA_ERR_TRAP_TRUISH_TARGET_NOT_EXTENSIBLE = "Trap returned truish for target is not extensible" +ECMA_ERR_TRAP_WITH_DUPLICATED_ENTRIES = "Trap returned with duplicated entries" +ECMA_ERR_TYPEDARRAY_INTRINSIC_CALLED_BY_NEW_EXPRESSION = "TypedArray intrinsic cannot be called by a 'new' expression" +ECMA_ERR_TYPEDARRAY_INTRINSIC_DIRECTLY_CALLED = "TypedArray intrinsic cannot be directly called" +ECMA_ERR_CONTENTTYPE_RETURNED_TYPEDARRAY_NOT_MATCH_SOURCE = "TypedArray returned by [[ContentType]] does not match source" +ECMA_ERR_UNARY_PLUS_IS_NOT_ALLOWED_FOR_BIGINTS = "Unary plus is not allowed for BigInts" +ECMA_ERR_UNDEFINED_REFERENCE = "Undefined reference" +ECMA_ERR_UNEXPECTED_END_OF_PATTERN = "Unexpected end of pattern" +ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING = "Unicode surrogate pair missing" +ECMA_ERR_UNMATCHED_CLOSE_BRACKET = "Unmatched close bracket" +ECMA_ERR_UNSHIFT_TOO_HIGH = "Unshift elements over 2**53-1 length is disallowed" +ECMA_ERR_UNSIGNED_RIGHT_SHIFT_IS_NOT_ALLOWED_FOR_BIGINTS = "Unsigned right shift is not allowed for BigInts" +ECMA_ERR_UNSUPPORTED_BINARY_OPERATION = "Unsupported binary operation" +ECMA_ERR_UNSUPPORTED_CONTAINER_OPERATION = "Unsupported container operation" +ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED = "Unsupported snapshot exec flags are specified" +ECMA_ERR_UNTERMINATED_CHARACTER_CLASS = "Unterminated character class" +ECMA_ERR_UNTERMINATED_GROUP = "Unterminated group" +ECMA_ERR_VALUE_CANNOT_BE_CONVERTED_TO_BIGINT = "Value cannot be converted to BigInt" +ECMA_ERR_VALUE_FOR_CLASS_HERITAGE_IS_NOT_A_CONSTRUCTOR = "Value for class heritage is not a constructor" +ECMA_ERR_VALUE_RECEIVED_BY_FOR_ASYNC_OF_IS_NOT_OBJECT = "Value received by for-async-of is not object" +ECMA_ERR_VALUE_RECEIVED_BY_YIELD_IS_NOT_OBJECT = "Value received by yield* is not object" +ECMA_ERR_WEAKREF_TARGET_MUST_BE_AN_OBJECT = "WeakRef target must be an object" +ECMA_ERR_METHOD_RETURN_IS_NOT_CALLABLE = "method 'return' is not callable" +ECMA_ERR_VALUE_MSG = "Argument cannot be marked as error" +ECMA_ERR_WRONG_ARGS_MSG = "This type of argument is not allowed" +ECMA_ERR_PARSER_NOT_SUPPORTED = "Source code parsing is disabled" +ECMA_ERR_JSON_NOT_SUPPORTED = "JSON support is disabled" +ECMA_ERR_TYPED_ARRAY_NOT_SUPPORTED = "TypedArray support is disabled" +ECMA_ERR_SHARED_ARRAYBUFFER_NOT_SUPPORTED = "SharedArrayBuffer support is disabled" +ECMA_ERR_DATA_VIEW_NOT_SUPPORTED = "DataView support is disabled" +ECMA_ERR_BIGINT_NOT_SUPPORTED = "BigInt support is disabled" +ECMA_ERR_CONTAINER_NOT_SUPPORTED = "Container support is disabled" +ECMA_ERR_NOT_MODULE = "Argument is not a module" +ECMA_ERR_UNKNOWN_EXPORT = "Native module export not found" +ECMA_ERR_MODULE_NOT_SUPPORTED = "Module support is disabled" +ECMA_ERR_CALLBACK_IS_NOT_CALLABLE = "Callback function is not callable" +ECMA_ERR_ARRAYBUFFER_IS_DETACHED = "ArrayBuffer has been detached" +ECMA_ERR_CANNOT_CONVERT_TO_OBJECT = "Cannot convert undefined or null to object" +ECMA_ERR_CLASS_IS_NON_CONFIGURABLE = "Prototype property of a class is non-configurable" +ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT = "Argument is not an object" +ECMA_ERR_ARGUMENT_IS_NOT_A_PROXY = "Argument is not a Proxy object" +ECMA_ERR_TARGET_IS_NOT_A_CONSTRUCTOR = "Target is not a constructor" +ECMA_ERR_ARGUMENT_IS_NOT_AN_REGEXP = "Argument 'this' is not a RegExp object" +ECMA_ERR_INVALID_ARRAY_LENGTH = "Invalid Array length" +ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED = "Local variable is redeclared" +ECMA_ERR_EXPECTED_A_FUNCTION = "Expected a function" +ECMA_ERR_CLASS_CONSTRUCTOR_NEW = "Class constructor cannot be invoked without 'new'" +ECMA_ERR_LET_CONST_NOT_INITIALIZED = "Variables declared by let/const must be initialized before reading their value" +ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE = "Maximum snapshot size reached" +ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED = "Regular expression literals are not supported" +ECMA_ERR_SNAPSHOT_BUFFER_SMALL = "Snapshot buffer too small" +ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE = "Unsupported compiled code" +ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED = "Unsupported generate snapshot flags specified" +ECMA_ERR_SNAPSHOT_SAVE_DISABLED = "Snapshot generation is disabled" +ECMA_ERR_SNAPSHOT_EXEC_DISABLED = "Snapshot execution is disabled" +ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS = "Cannot allocate memory for literals" +ECMA_ERR_TAGGED_TEMPLATE_LITERALS = "Unsupported feature: tagged template literals" +ECMA_ERR_CONTAINER_NEEDED = "Value is not a Container or Iterator" +ECMA_ERR_INCORRECT_TYPE_CALL = "Operator called on incorrect container type" +ECMA_ERR_INVALID_TYPE_FOR_CONSTRUCTOR_CALL = "Invalid type for constructor call" +ECMA_ERR_SCRIPT_GLOBAL_FUNCTIONS_INVOKE_WITH_NEW = "Script (global) functions cannot be invoked with 'new'" +ECMA_ERR_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW = "Generator functions cannot be invoked with 'new'" +ECMA_ERR_ASYNC_FUNCTIONS_INVOKE_WITH_NEW = "Async functions cannot be invoked with 'new'" +ECMA_ERR_ASYNC_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW = "Async generator functions cannot be invoked with 'new'" +ECMA_ERR_ACCESSOR_FUNCTIONS_INVOKE_WITH_NEW = "Accessor functions cannot be invoked with 'new'" +ECMA_ERR_METHODS_INVOKE_WITH_NEW = "Methods cannot be invoked with 'new'" +ECMA_ERR_ARROW_FUNCTIONS_INVOKE_WITH_NEW = "Arrow functions cannot be invoked with 'new'" +ECMA_ERR_ASYNC_ARROW_FUNCTIONS_INVOKE_WITH_NEW = "Async arrow functions cannot be invoked with 'new'" +ECMA_ERR_PROXY_TARGET_IS_NOT_A_CONSTRUCTOR = "Proxy target is not a constructor" +ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED = "Maximum call stack size exceeded" +ECMA_ERR_INVALID_SNAPSHOT_FORMAT = "Invalid snapshot format" +ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES = "Invalid snapshot version or unsupported features present" +ECMA_ERR_RECEIVER_MUST_BE_AN_OBJECT = "Receiver must be an object" +ECMA_ERR_CANNOT_DECLARE_SAME_PRIVATE_FIELD_TWICE = "Cannot declare same private field twice" +ECMA_ERR_CANNOT_WRITE_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT = "Cannot write private member to an object whose class did not declare it" +ECMA_ERR_PRIVATE_METHOD_IS_NOT_WRITABLE = "Private method is not writable" +ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_SETTER = "Private field was defined without a setter" +ECMA_ERR_CANNOT_READ_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT = "Cannot read private member to an object whose class did not declare it" +ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_GETTER = "Private field was defined without a getter" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-errors.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-errors.cpp new file mode 100644 index 0000000..7592fe8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-errors.cpp @@ -0,0 +1,71 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-errors.h" + +#if JERRY_ERROR_MESSAGES +/** + * Struct to store ecma error message with its size. + */ +typedef struct +{ + char *text; /* Text of ecma error message. */ + uint8_t size; /* Size of ecma error message. */ +} ecma_error_message_t; + +/* Error message texts with size. */ +static ecma_error_message_t ecma_error_messages[] JERRY_ATTR_CONST_DATA = { + { "", 0 }, /* ECMA_ERR_EMPTY */ +/** @cond doxygen_suppress */ +#define ECMA_ERROR_DEF(id, string) { string, sizeof (string) - 1 }, +#include "ecma-error-messages.inc.h" +#undef ECMA_ERROR_DEF + /** @endcond */ +}; +#endif /* JERRY_ERROR_MESSAGES */ + +/** + * Get specified ecma error as zero-terminated string + * + * @return pointer to zero-terminated ecma error + */ +const char * +ecma_get_error_msg (ecma_error_msg_t id) /**< ecma error id */ +{ + JERRY_ASSERT (id != ECMA_IS_VALID_CONSTRUCTOR); + +#if JERRY_ERROR_MESSAGES + return ecma_error_messages[id].text; +#else /* !JERRY_ERROR_MESSAGES */ + return NULL; +#endif /* JERRY_ERROR_MESSAGES */ +} /* ecma_get_error_msg */ + +/** + * Get size of specified ecma error + * + * @return size in bytes + */ +lit_utf8_size_t +ecma_get_error_size (ecma_error_msg_t id) /**< ecma error id */ +{ + JERRY_ASSERT (id != ECMA_IS_VALID_CONSTRUCTOR); + +#if JERRY_ERROR_MESSAGES + return ecma_error_messages[id].size; +#else /* !JERRY_ERROR_MESSAGES */ + return 0; +#endif /* JERRY_ERROR_MESSAGES */ +} /* ecma_get_error_size */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-errors.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-errors.h new file mode 100644 index 0000000..72947e6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-errors.h @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ERRORS_H +#define ECMA_ERRORS_H + +#include "lit-globals.h" + +typedef enum +{ + ECMA_ERR_EMPTY, +/** @cond doxygen_suppress */ +#if JERRY_ERROR_MESSAGES +#define ECMA_ERROR_DEF(id, ascii_zt_string) id, +#else /* !JERRY_ERROR_MESSAGES */ +#define ECMA_ERROR_DEF(id, ascii_zt_string) id = ECMA_ERR_EMPTY, +#endif /* JERRY_ERROR_MESSAGES */ +#include "ecma-error-messages.inc.h" +#undef ECMA_ERROR_DEF + /** @endcond */ + ECMA_IS_VALID_CONSTRUCTOR /* used as return value when checking constructor */ +} ecma_error_msg_t; + +const char* ecma_get_error_msg (ecma_error_msg_t id); +lit_utf8_size_t ecma_get_error_size (ecma_error_msg_t id); + +#endif /* !ECMA_ERRORS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-extended-info.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-extended-info.cpp new file mode 100644 index 0000000..6963065 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-extended-info.cpp @@ -0,0 +1,137 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-extended-info.h" + +#include "ecma-helpers.h" + +#include "byte-code.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaextendedinfo Extended info + * @{ + */ + +/** + * Decodes an uint32_t number, and updates the buffer position. + * + * @return the decoded value + */ +uint32_t +ecma_extended_info_decode_vlq (uint8_t **buffer_p) /**< [in/out] target buffer */ +{ + uint8_t *source_p = *buffer_p; + uint32_t value = 0; + + do + { + source_p--; + value = (value << ECMA_EXTENDED_INFO_VLQ_SHIFT) | (*source_p & ECMA_EXTENDED_INFO_VLQ_MASK); + } while (*source_p & ECMA_EXTENDED_INFO_VLQ_CONTINUE); + + *buffer_p = source_p; + return value; +} /* ecma_extended_info_decode_vlq */ + +/** + * Encodes an uint32_t number into a buffer. + */ +void +ecma_extended_info_encode_vlq (uint8_t **buffer_p, /**< target buffer */ + uint32_t value) /**< encoded value */ +{ + uint8_t *destination_p = *buffer_p - 1; + + if (value <= ECMA_EXTENDED_INFO_VLQ_MASK) + { + *destination_p = (uint8_t) value; + *buffer_p = destination_p; + return; + } + + uint32_t length = 0; + uint32_t current_value = value >> ECMA_EXTENDED_INFO_VLQ_SHIFT; + + do + { + current_value >>= ECMA_EXTENDED_INFO_VLQ_SHIFT; + length++; + } while (current_value > 0); + + destination_p -= length; + *buffer_p = destination_p; + + do + { + *destination_p++ = (uint8_t) (value | ECMA_EXTENDED_INFO_VLQ_CONTINUE); + value >>= ECMA_EXTENDED_INFO_VLQ_SHIFT; + } while (value > 0); + + **buffer_p &= ECMA_EXTENDED_INFO_VLQ_MASK; +} /* ecma_extended_info_encode_vlq */ + +/** + * Gets the encoded length of a number. + * + * @return encoded length + */ +uint32_t +ecma_extended_info_get_encoded_length (uint32_t value) /**< encoded value */ +{ + uint32_t length = 0; + + do + { + value >>= ECMA_EXTENDED_INFO_VLQ_SHIFT; + length++; + } while (value > 0); + + return length; +} /* ecma_extended_info_get_encoded_length */ + +/** + * Get the extended info from a byte code + * + * @return pointer to the extended info + */ +uint8_t * +ecma_compiled_code_resolve_extended_info (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */ +{ + JERRY_ASSERT (bytecode_header_p != NULL); + JERRY_ASSERT (bytecode_header_p->status_flags & CBC_CODE_FLAGS_HAS_EXTENDED_INFO); + + ecma_value_t *base_p = ecma_compiled_code_resolve_arguments_start (bytecode_header_p); + + if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR) + { + base_p--; + } + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS) + { + base_p--; + } + + JERRY_ASSERT (((uint8_t *) base_p)[-1] != 0); + + return ((uint8_t *) base_p) - 1; +} /* ecma_compiled_code_resolve_extended_info */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-extended-info.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-extended-info.h new file mode 100644 index 0000000..57046bd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-extended-info.h @@ -0,0 +1,54 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_EXTENDED_INFO_H +#define ECMA_EXTENDED_INFO_H + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaextendedinfo Extended info + * @{ + */ + +#include "ecma-globals.h" + +/** + * Vlq encoding: flag which is set for all bytes except the last one. + */ +#define ECMA_EXTENDED_INFO_VLQ_CONTINUE 0x80 + +/** + * Vlq encoding: mask to decode the number fragment. + */ +#define ECMA_EXTENDED_INFO_VLQ_MASK 0x7f + +/** + * Vlq encoding: number of bits stored in a byte. + */ +#define ECMA_EXTENDED_INFO_VLQ_SHIFT 7 + +uint32_t ecma_extended_info_decode_vlq (uint8_t **buffer_p); +void ecma_extended_info_encode_vlq (uint8_t **buffer_p, uint32_t value); +uint32_t ecma_extended_info_get_encoded_length (uint32_t value); + +uint8_t *ecma_compiled_code_resolve_extended_info (const ecma_compiled_code_t *bytecode_header_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_EXTENDED_INFO_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-gc.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-gc.cpp new file mode 100644 index 0000000..f23a2b4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-gc.cpp @@ -0,0 +1,2311 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Garbage collector implementation + */ + +#include "ecma-gc.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-arraybuffer-object.h" +#include "ecma-builtin-handlers.h" +#include "ecma-container-object.h" +#include "ecma-function-object.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lcache.h" +#include "ecma-objects.h" +#include "ecma-property-hashmap.h" +#include "ecma-proxy-object.h" + +#include "jcontext.h" +#include "jrt-bit-fields.h" +#include "jrt-libc-includes.h" +#include "jrt.h" +#include "re-compiler.h" +#include "vm-defines.h" +#include "vm-stack.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#include "ecma-typedarray-object.h" +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#include "ecma-promise-object.h" + +/* TODO: Extract GC to a separate component */ + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmagc Garbage collector + * @{ + */ + +/* + * The garbage collector uses the reference counter + * of object: it increases the counter by one when + * the object is marked at the first time. + */ + +/** + * Get visited flag of the object. + * + * @return true - if visited + * false - otherwise + */ +static inline bool +ecma_gc_is_object_visited (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + + return (object_p->type_flags_refs < ECMA_OBJECT_NON_VISITED); +} /* ecma_gc_is_object_visited */ + +/** + * Mark objects as visited starting from specified object as root + */ +static void ecma_gc_mark (ecma_object_t *object_p); + +/** + * Set visited flag of the object. + */ +static void +ecma_gc_set_object_visited (ecma_object_t *object_p) /**< object */ +{ + if (object_p->type_flags_refs >= ECMA_OBJECT_NON_VISITED) + { +#if (JERRY_GC_MARK_LIMIT != 0) + if (JERRY_CONTEXT (ecma_gc_mark_recursion_limit) != 0) + { + JERRY_CONTEXT (ecma_gc_mark_recursion_limit)--; + /* Set the reference count of gray object to 0 */ + object_p->type_flags_refs &= (ecma_object_descriptor_t) (ECMA_OBJECT_REF_ONE - 1); + ecma_gc_mark (object_p); + JERRY_CONTEXT (ecma_gc_mark_recursion_limit)++; + } + else + { + /* Set the reference count of the non-marked gray object to 1 */ + object_p->type_flags_refs &= (ecma_object_descriptor_t) ((ECMA_OBJECT_REF_ONE << 1) - 1); + JERRY_ASSERT (object_p->type_flags_refs >= ECMA_OBJECT_REF_ONE); + } +#else /* (JERRY_GC_MARK_LIMIT == 0) */ + /* Set the reference count of gray object to 0 */ + object_p->type_flags_refs &= (ecma_object_descriptor_t) (ECMA_OBJECT_REF_ONE - 1); +#endif /* (JERRY_GC_MARK_LIMIT != 0) */ + } +} /* ecma_gc_set_object_visited */ + +/** + * Initialize GC information for the object + */ +void +ecma_init_gc_info (ecma_object_t *object_p) /**< object */ +{ + JERRY_CONTEXT (ecma_gc_objects_number)++; + JERRY_CONTEXT (ecma_gc_new_objects)++; + + JERRY_ASSERT (object_p->type_flags_refs < ECMA_OBJECT_REF_ONE); + object_p->type_flags_refs |= ECMA_OBJECT_REF_ONE; + + object_p->gc_next_cp = JERRY_CONTEXT (ecma_gc_objects_cp); + ECMA_SET_NON_NULL_POINTER (JERRY_CONTEXT (ecma_gc_objects_cp), object_p); +} /* ecma_init_gc_info */ + +/** + * Increase reference counter of an object + * + * @return void + */ +void +ecma_ref_object_inline (ecma_object_t *object_p) /**< object */ +{ + if (JERRY_LIKELY (object_p->type_flags_refs < ECMA_OBJECT_MAX_REF)) + { + object_p->type_flags_refs = (ecma_object_descriptor_t) (object_p->type_flags_refs + ECMA_OBJECT_REF_ONE); + } + else + { + jerry_fatal (JERRY_FATAL_REF_COUNT_LIMIT); + } +} /* ecma_ref_object_inline */ + +/** + * Increase reference counter of an object + */ +void +ecma_ref_object (ecma_object_t *object_p) /**< object */ +{ + ecma_ref_object_inline (object_p); +} /* ecma_ref_object */ + +/** + * Decrease reference counter of an object + * + * @return void + */ +void +ecma_deref_object (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p->type_flags_refs >= ECMA_OBJECT_REF_ONE); + object_p->type_flags_refs = (ecma_object_descriptor_t) (object_p->type_flags_refs - ECMA_OBJECT_REF_ONE); +} /* ecma_deref_object */ + +/** + * Mark objects referenced by global object + */ +static void +ecma_gc_mark_global_object (ecma_global_object_t *global_object_p) /**< global object */ +{ + JERRY_ASSERT (global_object_p->extended_object.u.built_in.routine_id == 0); + + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, global_object_p->global_env_cp)); + +#if JERRY_BUILTIN_REALMS + ecma_gc_set_object_visited (ecma_get_object_from_value (global_object_p->this_binding)); +#endif /* JERRY_BUILTIN_REALMS */ + + if (global_object_p->global_scope_cp != global_object_p->global_env_cp) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, global_object_p->global_scope_cp)); + } + + jmem_cpointer_t *builtin_objects_p = global_object_p->builtin_objects; + + for (int i = 0; i < ECMA_BUILTIN_OBJECTS_COUNT; i++) + { + if (builtin_objects_p[i] != JMEM_CP_NULL) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, builtin_objects_p[i])); + } + } +} /* ecma_gc_mark_global_object */ + +/** + * Mark objects referenced by arguments object + */ +static void +ecma_gc_mark_arguments_object (ecma_extended_object_t *ext_object_p) /**< arguments object */ +{ + JERRY_ASSERT (ecma_get_object_type ((ecma_object_t *) ext_object_p) == ECMA_OBJECT_TYPE_CLASS); + + ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) ext_object_p; + ecma_gc_set_object_visited (ecma_get_object_from_value (arguments_p->callee)); + + ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1); + + if (ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p; + argv_p = (ecma_value_t *) (mapped_arguments_p + 1); + + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, mapped_arguments_p->lex_env)); + } + + uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number; + + for (uint32_t i = 0; i < arguments_number; i++) + { + if (ecma_is_value_object (argv_p[i])) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (argv_p[i])); + } + } +} /* ecma_gc_mark_arguments_object */ + +/** + * Mark referenced object from property + */ +static void +ecma_gc_mark_properties (ecma_object_t *object_p, /**< object */ + bool mark_references) /**< mark references */ +{ + JERRY_UNUSED (mark_references); + +#if !JERRY_MODULE_SYSTEM + JERRY_ASSERT (!mark_references); +#endif /* !JERRY_MODULE_SYSTEM */ + + jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp; + +#if JERRY_PROPERTY_HASHMAP + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prop_iter_cp = prop_iter_p->next_property_cp; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *property_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (uint32_t index = 0; index < ECMA_PROPERTY_PAIR_ITEM_COUNT; index++) + { + uint8_t property = property_pair_p->header.types[index]; + + if (JERRY_LIKELY (ECMA_PROPERTY_IS_RAW (property))) + { + if (property & ECMA_PROPERTY_FLAG_DATA) + { + ecma_value_t value = property_pair_p->values[index].value; + + if (ecma_is_value_object (value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (value)); + } + continue; + } + +#if JERRY_MODULE_SYSTEM + if (mark_references) + { + continue; + } +#endif /* JERRY_MODULE_SYSTEM */ + + ecma_property_value_t *accessor_objs_p = property_pair_p->values + index; + + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (accessor_objs_p); + + if (get_set_pair_p->getter_cp != JMEM_CP_NULL) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp)); + } + + if (get_set_pair_p->setter_cp != JMEM_CP_NULL) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->setter_cp)); + } + + continue; + } + + if (!ECMA_PROPERTY_IS_INTERNAL (property)) + { + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_DELETED || property == ECMA_PROPERTY_TYPE_HASHMAP); + continue; + } + + JERRY_ASSERT (property_pair_p->names_cp[index] >= LIT_INTERNAL_MAGIC_STRING_FIRST_DATA + && property_pair_p->names_cp[index] < LIT_MAGIC_STRING__COUNT); + + switch (property_pair_p->names_cp[index]) + { + case LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD: + { + ecma_environment_record_t *environment_record_p; + environment_record_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t, property_pair_p->values[index].value); + + if (environment_record_p->this_binding != ECMA_VALUE_UNINITIALIZED) + { + JERRY_ASSERT (ecma_is_value_object (environment_record_p->this_binding)); + ecma_gc_set_object_visited (ecma_get_object_from_value (environment_record_p->this_binding)); + } + + JERRY_ASSERT (ecma_is_value_object (environment_record_p->function_object)); + ecma_gc_set_object_visited (ecma_get_object_from_value (environment_record_p->function_object)); + break; + } + case LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS: + { + ecma_value_t *compact_collection_p; + compact_collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, property_pair_p->values[index].value); + + ecma_value_t *end_p = ecma_compact_collection_end (compact_collection_p); + ecma_value_t *current_p = compact_collection_p + 1; + + while (end_p - current_p >= ECMA_PRIVATE_ELEMENT_LIST_SIZE) + { + current_p++; /* skip the type */ + current_p++; /* skip the name */ + ecma_value_t value = *current_p++; + + if (!ecma_is_value_undefined (value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (value)); + } + } + break; + } +#if JERRY_BUILTIN_CONTAINER + case LIT_INTERNAL_MAGIC_STRING_WEAK_REFS: + { + ecma_value_t key_arg = ecma_make_object_value (object_p); + ecma_collection_t *refs_p; + + refs_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, property_pair_p->values[index].value); + + for (uint32_t j = 0; j < refs_p->item_count; j++) + { + const ecma_value_t reference_value = refs_p->buffer_p[j]; + + if (ecma_is_value_empty (reference_value)) + { + continue; + } + + ecma_object_t *reference_object_p = ecma_get_object_from_value (reference_value); + + JERRY_ASSERT (ecma_get_object_type (reference_object_p) == ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) reference_object_p; + + if (map_object_p->u.cls.type != ECMA_OBJECT_CLASS_CONTAINER + || map_object_p->u.cls.u2.container_id != LIT_MAGIC_STRING_WEAKMAP_UL + || !ecma_gc_is_object_visited (reference_object_p)) + { + continue; + } + + ecma_value_t value = ecma_op_container_find_weak_value (reference_object_p, key_arg); + + if (ecma_is_value_object (value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (value)); + } + } + break; + } +#endif /* JERRY_BUILTIN_CONTAINER */ + case LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES: + { + jerry_value_t value = property_pair_p->values[index].value; + + if (value == JMEM_CP_NULL) + { + JERRY_ASSERT (!(property & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL)); + break; + } + + ecma_native_pointer_t *item_p; + item_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value); + + do + { + jerry_object_native_info_t *native_info_p = item_p->native_info_p; + + JERRY_ASSERT (native_info_p != NULL && native_info_p->number_of_references > 0); + + uint8_t *start_p = ((uint8_t *) item_p->native_p) + native_info_p->offset_of_references; + ecma_value_t *value_p = (ecma_value_t *) start_p; + ecma_value_t *end_p = value_p + native_info_p->number_of_references; + + do + { + if (ecma_is_value_object (*value_p)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*value_p)); + } + } while (++value_p < end_p); + + if (property & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL) + { + break; + } + + item_p = &(((ecma_native_pointer_chain_t *) item_p)->next_p->data); + } while (item_p != NULL); + + break; + } + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } +} /* ecma_gc_mark_properties */ + +/** + * Mark compiled code. + */ +static void +ecma_gc_mark_compiled_code (ecma_value_t script_value) /**< script value */ +{ + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + + if (script_p->refs_and_type & CBC_SCRIPT_USER_VALUE_IS_OBJECT) + { + ecma_value_t user_value = CBC_SCRIPT_GET_USER_VALUE (script_p); + + JERRY_ASSERT (ecma_is_value_object (user_value)); + ecma_gc_set_object_visited (ecma_get_object_from_value (user_value)); + } + +#if JERRY_MODULE_SYSTEM + if (script_p->refs_and_type & CBC_SCRIPT_HAS_IMPORT_META) + { + ecma_value_t import_meta = CBC_SCRIPT_GET_IMPORT_META (script_p, script_p->refs_and_type); + + JERRY_ASSERT (ecma_is_value_object (import_meta)); + ecma_gc_set_object_visited (ecma_get_object_from_value (import_meta)); + } +#endif /* JERRY_MODULE_SYSTEM */ + +#if JERRY_BUILTIN_REALMS + ecma_gc_set_object_visited (script_p->realm_p); +#endif /* JERRY_BUILTIN_REALMS */ +} /* ecma_gc_mark_compiled_code */ + +/** + * Mark objects referenced by bound function object. + * + * @return void + */ +static void JERRY_ATTR_NOINLINE +ecma_gc_mark_bound_function_object (ecma_object_t *object_p) /**< bound function object */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p; + + ecma_object_t *target_func_p; + target_func_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, bound_func_p->header.u.bound_function.target_function); + + ecma_gc_set_object_visited (target_func_p); + + ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this; + + if (!ecma_is_value_integer_number (args_len_or_this)) + { + if (ecma_is_value_object (args_len_or_this)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (args_len_or_this)); + } + + return; + } + + ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this); + ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1); + + JERRY_ASSERT (args_length > 0); + + for (ecma_integer_value_t i = 0; i < args_length; i++) + { + if (ecma_is_value_object (args_p[i])) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (args_p[i])); + } + } +} /* ecma_gc_mark_bound_function_object */ + +/** + * Mark objects referenced by Promise built-in. + */ +static void +ecma_gc_mark_promise_object (ecma_extended_object_t *ext_object_p) /**< extended object */ +{ + /* Mark promise result. */ + ecma_value_t result = ext_object_p->u.cls.u3.value; + + if (ecma_is_value_object (result)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (result)); + } + + /* Mark all reactions. */ + ecma_promise_object_t *promise_object_p = (ecma_promise_object_t *) ext_object_p; + + ecma_collection_t *collection_p = promise_object_p->reactions; + + if (collection_p != NULL) + { + ecma_value_t *buffer_p = collection_p->buffer_p; + ecma_value_t *buffer_end_p = buffer_p + collection_p->item_count; + + while (buffer_p < buffer_end_p) + { + ecma_value_t value = *buffer_p++; + + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, value)); + + if (JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*buffer_p++)); + } + + if (JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*buffer_p++)); + } + } + } +} /* ecma_gc_mark_promise_object */ + +#if JERRY_BUILTIN_CONTAINER +/** + * Mark objects referenced by Map built-in. + */ +static void +ecma_gc_mark_map_object (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_PAIR_SIZE) + { + ecma_container_pair_t *entry_p = (ecma_container_pair_t *) (start_p + i); + + if (ecma_is_value_empty (entry_p->key)) + { + continue; + } + + if (ecma_is_value_object (entry_p->key)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (entry_p->key)); + } + + if (ecma_is_value_object (entry_p->value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (entry_p->value)); + } + } +} /* ecma_gc_mark_map_object */ + +/** + * Mark objects referenced by WeakMap built-in. + */ +static void +ecma_gc_mark_weakmap_object (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_PAIR_SIZE) + { + ecma_container_pair_t *entry_p = (ecma_container_pair_t *) (start_p + i); + + if (ecma_is_value_empty (entry_p->key)) + { + continue; + } + + JERRY_ASSERT (ecma_is_value_object (entry_p->key)); + + if (ecma_is_value_object (entry_p->value) && ecma_gc_is_object_visited (ecma_get_object_from_value (entry_p->key))) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (entry_p->value)); + } + } +} /* ecma_gc_mark_weakmap_object */ + +/** + * Mark objects referenced by Set built-in. + */ +static void +ecma_gc_mark_set_object (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_VALUE_SIZE) + { + ecma_value_t *entry_p = start_p + i; + + if (ecma_is_value_empty (*entry_p)) + { + continue; + } + + if (ecma_is_value_object (*entry_p)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*entry_p)); + } + } +} /* ecma_gc_mark_set_object */ +#endif /* JERRY_BUILTIN_CONTAINER */ + +/** + * Mark objects referenced by inactive generator functions, async functions, etc. + */ +static void +ecma_gc_mark_executable_object (ecma_object_t *object_p) /**< object */ +{ + vm_executable_object_t *executable_object_p = (vm_executable_object_t *) object_p; + + if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_ASYNC_GENERATOR_CALLED) + { + ecma_value_t task = executable_object_p->extended_object.u.cls.u3.head; + + while (!ECMA_IS_INTERNAL_VALUE_NULL (task)) + { + ecma_async_generator_task_t *task_p; + task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, task); + + JERRY_ASSERT (ecma_is_value_object (task_p->promise)); + ecma_gc_set_object_visited (ecma_get_object_from_value (task_p->promise)); + + if (ecma_is_value_object (task_p->operation_value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (task_p->operation_value)); + } + + task = task_p->next; + } + } + + ecma_gc_set_object_visited (executable_object_p->frame_ctx.lex_env_p); + ecma_gc_set_object_visited (executable_object_p->shared.function_object_p); + + if (!ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED (executable_object_p) + && !(executable_object_p->extended_object.u.cls.u2.executable_obj_flags + & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD)) + { + /* All objects referenced by running executable objects are strong roots, + * and a finished executable object cannot refer to other values. */ + return; + } + + if (ecma_is_value_object (executable_object_p->frame_ctx.this_binding)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (executable_object_p->frame_ctx.this_binding)); + } + + const ecma_compiled_code_t *bytecode_header_p = executable_object_p->shared.bytecode_header_p; + size_t register_end; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + register_end = args_p->register_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + register_end = args_p->register_end; + } + + ecma_value_t *register_p = VM_GET_REGISTERS (&executable_object_p->frame_ctx); + ecma_value_t *register_end_p = register_p + register_end; + + while (register_p < register_end_p) + { + if (ecma_is_value_object (*register_p)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*register_p)); + } + + register_p++; + } + + if (executable_object_p->frame_ctx.context_depth > 0) + { + ecma_value_t *context_end_p = register_p; + + register_p += executable_object_p->frame_ctx.context_depth; + + ecma_value_t *context_top_p = register_p; + + do + { + if (VM_CONTEXT_IS_VARIABLE_LENGTH (VM_GET_CONTEXT_TYPE (context_top_p[-1]))) + { + ecma_value_t *last_item_p = context_top_p - VM_GET_CONTEXT_END (context_top_p[-1]); + JERRY_ASSERT (last_item_p >= context_end_p); + context_top_p--; + + do + { + --context_top_p; + if (ecma_is_value_object (*context_top_p)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*context_top_p)); + } + } while (context_top_p > last_item_p); + + continue; + } + + uint32_t offsets = vm_get_context_value_offsets (context_top_p); + + while (VM_CONTEXT_HAS_NEXT_OFFSET (offsets)) + { + int32_t offset = VM_CONTEXT_GET_NEXT_OFFSET (offsets); + + if (ecma_is_value_object (context_top_p[offset])) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (context_top_p[offset])); + } + + offsets >>= VM_CONTEXT_OFFSET_SHIFT; + } + + JERRY_ASSERT (context_top_p >= context_end_p + offsets); + context_top_p -= offsets; + } while (context_top_p > context_end_p); + } + + register_end_p = executable_object_p->frame_ctx.stack_top_p; + + while (register_p < register_end_p) + { + if (ecma_is_value_object (*register_p)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (*register_p)); + } + + register_p++; + } + + if (ecma_is_value_object (executable_object_p->iterator)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (executable_object_p->iterator)); + } +} /* ecma_gc_mark_executable_object */ + +#if JERRY_BUILTIN_PROXY +/** + * Mark the objects referenced by a proxy object + */ +static void +ecma_gc_mark_proxy_object (ecma_object_t *object_p) /**< proxy object */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (object_p)); + + ecma_proxy_object_t *proxy_p = (ecma_proxy_object_t *) object_p; + + if (!ecma_is_value_null (proxy_p->target)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (proxy_p->target)); + } + + if (!ecma_is_value_null (proxy_p->handler)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (proxy_p->handler)); + } +} /* ecma_gc_mark_proxy_object */ +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * Mark objects as visited starting from specified object as root + */ +static void +ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (ecma_gc_is_object_visited (object_p)); + + if (ecma_is_lexical_environment (object_p)) + { + jmem_cpointer_t outer_lex_env_cp = object_p->u2.outer_reference_cp; + + if (outer_lex_env_cp != JMEM_CP_NULL) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, outer_lex_env_cp)); + } + + switch (ecma_get_lex_env_type (object_p)) + { + case ECMA_LEXICAL_ENVIRONMENT_CLASS: + { +#if JERRY_MODULE_SYSTEM + if (object_p->type_flags_refs & ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA) + { + if (ECMA_LEX_ENV_CLASS_IS_MODULE (object_p)) + { + ecma_gc_mark_properties (object_p, true); + } + + ecma_gc_set_object_visited (((ecma_lexical_environment_class_t *) object_p)->object_p); + return; + } +#endif /* JERRY_MODULE_SYSTEM */ + /* FALLTHRU */ + } + case ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND: + { + ecma_object_t *binding_object_p = ecma_get_lex_env_binding_object (object_p); + ecma_gc_set_object_visited (binding_object_p); + return; + } + default: + { + break; + } + } + } + else + { + /** + * Have the object's prototype here so the object could set it to JMEM_CP_NULL + * if the prototype should be ignored (like in case of PROXY). + */ + jmem_cpointer_t proto_cp = object_p->u2.prototype_cp; + + switch (ecma_get_object_type (object_p)) + { + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + { + ecma_extended_object_t *extended_object_p = (ecma_extended_object_t *) object_p; + + if (extended_object_p->u.built_in.id == ECMA_BUILTIN_ID_GLOBAL) + { + ecma_gc_mark_global_object ((ecma_global_object_t *) object_p); + } + +#if JERRY_BUILTIN_REALMS + ecma_value_t realm_value = extended_object_p->u.built_in.realm_value; + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, realm_value)); +#endif /* JERRY_BUILTIN_REALMS */ + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + { +#if JERRY_BUILTIN_REALMS + ecma_value_t realm_value = ((ecma_extended_built_in_object_t *) object_p)->built_in.realm_value; + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, realm_value)); +#endif /* JERRY_BUILTIN_REALMS */ + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + ecma_gc_mark_arguments_object (ext_object_p); + break; + } +#if JERRY_PARSER + case ECMA_OBJECT_CLASS_SCRIPT: + { + const ecma_compiled_code_t *compiled_code_p; + compiled_code_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value); + + JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)); + ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value); + break; + } +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_TYPEDARRAY + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + ecma_gc_set_object_visited (ecma_typedarray_get_arraybuffer (object_p)); + break; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE_NAMESPACE: + { + JERRY_ASSERT (proto_cp == JMEM_CP_NULL); + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, ext_object_p->u.cls.u3.value)); + ecma_gc_mark_properties (object_p, true); + return; + } +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE: + { + ecma_module_t *module_p = ((ecma_module_t *) ext_object_p); + + if (module_p->scope_p != NULL) + { + ecma_gc_set_object_visited (((ecma_module_t *) ext_object_p)->scope_p); + } + + if (module_p->namespace_object_p != NULL) + { + ecma_gc_set_object_visited (((ecma_module_t *) ext_object_p)->namespace_object_p); + } + + if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) + && module_p->u.compiled_code_p != NULL) + { + const ecma_compiled_code_t *compiled_code_p = module_p->u.compiled_code_p; + + JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)); + ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value); + } + + ecma_module_node_t *node_p = module_p->imports_p; + + while (node_p != NULL) + { + if (ecma_is_value_object (node_p->u.path_or_module)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (node_p->u.path_or_module)); + } + + node_p = node_p->next_p; + } + break; + } +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_BUILTIN_DATAVIEW + case ECMA_OBJECT_CLASS_DATAVIEW: + { + ecma_dataview_object_t *dataview_p = (ecma_dataview_object_t *) object_p; + ecma_gc_set_object_visited (dataview_p->buffer_p); + break; + } +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_CONTAINER + case ECMA_OBJECT_CLASS_CONTAINER: + { + if (ext_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_MAP_UL) + { + ecma_gc_mark_map_object (object_p); + break; + } + if (ext_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL) + { + ecma_gc_mark_weakmap_object (object_p); + break; + } + if (ext_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_SET_UL) + { + ecma_gc_mark_set_object (object_p); + break; + } + JERRY_ASSERT (ext_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKSET_UL); + break; + } +#endif /* JERRY_BUILTIN_CONTAINER */ + case ECMA_OBJECT_CLASS_GENERATOR: + case ECMA_OBJECT_CLASS_ASYNC_GENERATOR: + { + ecma_gc_mark_executable_object (object_p); + break; + } + case ECMA_OBJECT_CLASS_PROMISE: + { + ecma_gc_mark_promise_object (ext_object_p); + break; + } + case ECMA_OBJECT_CLASS_PROMISE_CAPABILITY: + { + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) object_p; + + if (ecma_is_value_object (capability_p->header.u.cls.u3.promise)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (capability_p->header.u.cls.u3.promise)); + } + if (ecma_is_value_object (capability_p->resolve)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (capability_p->resolve)); + } + if (ecma_is_value_object (capability_p->reject)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (capability_p->reject)); + } + break; + } + case ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR: + { + ecma_async_from_sync_iterator_object_t *iter_p = (ecma_async_from_sync_iterator_object_t *) ext_object_p; + + ecma_gc_set_object_visited (ecma_get_object_from_value (iter_p->header.u.cls.u3.sync_iterator)); + + if (!ecma_is_value_undefined (iter_p->sync_next_method)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (iter_p->sync_next_method)); + } + + break; + } + case ECMA_OBJECT_CLASS_ARRAY_ITERATOR: + case ECMA_OBJECT_CLASS_SET_ITERATOR: + case ECMA_OBJECT_CLASS_MAP_ITERATOR: + { + ecma_value_t iterated_value = ext_object_p->u.cls.u3.iterated_value; + if (!ecma_is_value_empty (iterated_value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (iterated_value)); + } + break; + } +#if JERRY_BUILTIN_REGEXP + case ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR: + { + ecma_regexp_string_iterator_t *regexp_string_iterator_obj = (ecma_regexp_string_iterator_t *) object_p; + ecma_value_t regexp = regexp_string_iterator_obj->iterating_regexp; + ecma_gc_set_object_visited (ecma_get_object_from_value (regexp)); + break; + } +#endif /* JERRY_BUILTIN_REGEXP */ + default: + { + /* The ECMA_OBJECT_CLASS__MAX type represents an uninitialized class. */ + JERRY_ASSERT (ext_object_p->u.cls.type <= ECMA_OBJECT_CLASS__MAX); + break; + } + } + + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { +#if JERRY_BUILTIN_REALMS + ecma_value_t realm_value = ((ecma_extended_built_in_object_t *) object_p)->built_in.realm_value; + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, realm_value)); +#endif /* JERRY_BUILTIN_REALMS */ + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_ARRAY: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (JERRY_UNLIKELY (ext_object_p->u.array.length_prop_and_hole_count & ECMA_ARRAY_TEMPLATE_LITERAL)) + { + /* Template objects are never marked. */ + JERRY_ASSERT (object_p->type_flags_refs >= ECMA_OBJECT_REF_ONE); + return; + } + + if (ecma_op_array_is_fast_array (ext_object_p)) + { + if (object_p->u1.property_list_cp != JMEM_CP_NULL) + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + for (uint32_t i = 0; i < ext_object_p->u.array.length; i++) + { + if (ecma_is_value_object (values_p[i])) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (values_p[i])); + } + } + } + + if (proto_cp != JMEM_CP_NULL) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp)); + } + return; + } + break; + } +#if JERRY_BUILTIN_PROXY + case ECMA_OBJECT_TYPE_PROXY: + { + ecma_gc_mark_proxy_object (object_p); + /* Prototype of proxy object is a bit set. */ + proto_cp = JMEM_CP_NULL; + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_OBJECT_TYPE_FUNCTION: + { + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + ecma_gc_set_object_visited ( + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, ext_func_p->u.function.scope_cp)); + + const ecma_compiled_code_t *compiled_code_p = ecma_op_function_get_compiled_code (ext_func_p); + + if (CBC_FUNCTION_IS_ARROW (compiled_code_p->status_flags)) + { + ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p; + + if (ecma_is_value_object (arrow_func_p->this_binding)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->this_binding)); + } + + if (ecma_is_value_object (arrow_func_p->new_target)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (arrow_func_p->new_target)); + } + } + +#if JERRY_SNAPSHOT_EXEC + if (JERRY_UNLIKELY (compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)) + { + /* Static snapshot functions have a global realm */ + break; + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)); + ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + ecma_gc_mark_bound_function_object (object_p); + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + +#if JERRY_BUILTIN_REALMS + ecma_value_t realm_value = ext_func_p->u.built_in.realm_value; + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, realm_value)); +#endif /* JERRY_BUILTIN_REALMS */ + + if (ext_func_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER) + { + switch (ext_func_p->u.built_in.routine_id) + { + case ECMA_NATIVE_HANDLER_PROMISE_RESOLVE: + case ECMA_NATIVE_HANDLER_PROMISE_REJECT: + { + ecma_promise_resolver_t *resolver_obj_p = (ecma_promise_resolver_t *) object_p; + ecma_gc_set_object_visited (ecma_get_object_from_value (resolver_obj_p->promise)); + break; + } + case ECMA_NATIVE_HANDLER_PROMISE_THEN_FINALLY: + case ECMA_NATIVE_HANDLER_PROMISE_CATCH_FINALLY: + { + ecma_promise_finally_function_t *finally_obj_p = (ecma_promise_finally_function_t *) object_p; + ecma_gc_set_object_visited (ecma_get_object_from_value (finally_obj_p->constructor)); + ecma_gc_set_object_visited (ecma_get_object_from_value (finally_obj_p->on_finally)); + break; + } + case ECMA_NATIVE_HANDLER_PROMISE_CAPABILITY_EXECUTOR: + { + ecma_promise_capability_executor_t *executor_p = (ecma_promise_capability_executor_t *) object_p; + ecma_gc_set_object_visited (ecma_get_object_from_value (executor_p->capability)); + break; + } + case ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER: + { + ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) object_p; + ecma_gc_set_object_visited (ecma_get_object_from_value (executor_p->capability)); + ecma_gc_set_object_visited (ecma_get_object_from_value (executor_p->values)); + ecma_gc_set_object_visited (ecma_get_object_from_value (executor_p->remaining_elements)); + break; + } +#if JERRY_BUILTIN_PROXY + case ECMA_NATIVE_HANDLER_PROXY_REVOKE: + { + ecma_revocable_proxy_object_t *rev_proxy_p = (ecma_revocable_proxy_object_t *) object_p; + + if (!ecma_is_value_null (rev_proxy_p->proxy)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (rev_proxy_p->proxy)); + } + + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_NATIVE_HANDLER_VALUE_THUNK: + case ECMA_NATIVE_HANDLER_VALUE_THROWER: + { + ecma_promise_value_thunk_t *thunk_obj_p = (ecma_promise_value_thunk_t *) object_p; + + if (ecma_is_value_object (thunk_obj_p->value)) + { + ecma_gc_set_object_visited (ecma_get_object_from_value (thunk_obj_p->value)); + } + break; + } + case ECMA_NATIVE_HANDLER_ASYNC_FROM_SYNC_ITERATOR_UNWRAP: + { + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + } + break; + } + case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION: + { + ecma_gc_mark_compiled_code (((ecma_extended_object_t *) object_p)->u.constructor_function.script_value); + break; + } +#if JERRY_BUILTIN_REALMS + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p; + ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, native_function_p->realm_value)); + break; + } +#endif /* JERRY_BUILTIN_REALMS */ + default: + { + break; + } + } + + if (proto_cp != JMEM_CP_NULL) + { + ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp)); + } + } + + ecma_gc_mark_properties (object_p, false); +} /* ecma_gc_mark */ + +/** + * Free the native handle/pointer by calling its free callback. + */ +static void +ecma_gc_free_native_pointer (ecma_property_t property, /**< property descriptor */ + ecma_value_t value) /**< property value */ +{ + if (JERRY_LIKELY (property & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL)) + { + JERRY_ASSERT (value != JMEM_CP_NULL); + + ecma_native_pointer_t *native_pointer_p; + native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value); + + if (native_pointer_p->native_info_p != NULL) + { + jerry_object_native_free_cb_t free_cb = native_pointer_p->native_info_p->free_cb; + + if (free_cb != NULL) + { + free_cb (native_pointer_p->native_p, native_pointer_p->native_info_p); + } + } + + jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t)); + return; + } + + if (value == JMEM_CP_NULL) + { + return; + } + + ecma_native_pointer_chain_t *item_p; + item_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value); + + do + { + if (item_p->data.native_info_p != NULL) + { + jerry_object_native_free_cb_t free_cb = item_p->data.native_info_p->free_cb; + + if (free_cb != NULL) + { + free_cb (item_p->data.native_p, item_p->data.native_info_p); + } + } + + ecma_native_pointer_chain_t *next_p = item_p->next_p; + + jmem_heap_free_block (item_p, sizeof (ecma_native_pointer_chain_t)); + + item_p = next_p; + } while (item_p != NULL); +} /* ecma_gc_free_native_pointer */ + +/** + * Free specified arguments object. + * + * @return allocated object's size + */ +static size_t +ecma_free_arguments_object (ecma_extended_object_t *ext_object_p) /**< arguments object */ +{ + JERRY_ASSERT (ecma_get_object_type ((ecma_object_t *) ext_object_p) == ECMA_OBJECT_TYPE_CLASS); + + size_t object_size = sizeof (ecma_unmapped_arguments_t); + + if (ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p; + object_size = sizeof (ecma_mapped_arguments_t); + +#if JERRY_SNAPSHOT_EXEC + if (!(mapped_arguments_p->unmapped.header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE)) +#endif /* JERRY_SNAPSHOT_EXEC */ + { + ecma_compiled_code_t *byte_code_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, mapped_arguments_p->u.byte_code); + + ecma_bytecode_deref (byte_code_p); + } + } + + ecma_value_t *argv_p = (ecma_value_t *) (((uint8_t *) ext_object_p) + object_size); + ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) ext_object_p; + uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number; + + for (uint32_t i = 0; i < arguments_number; i++) + { + ecma_free_value_if_not_object (argv_p[i]); + } + + uint32_t saved_argument_count = JERRY_MAX (arguments_number, arguments_p->header.u.cls.u2.formal_params_number); + + return object_size + (saved_argument_count * sizeof (ecma_value_t)); +} /* ecma_free_arguments_object */ + +/** + * Free specified fast access mode array object. + */ +static void +ecma_free_fast_access_array (ecma_object_t *object_p) /**< fast access mode array object to free */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (ext_object_p->u.array.length); + + if (object_p->u1.property_list_cp != JMEM_CP_NULL) + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + for (uint32_t i = 0; i < aligned_length; i++) + { + ecma_free_value_if_not_object (values_p[i]); + } + + jmem_heap_free_block (values_p, aligned_length * sizeof (ecma_value_t)); + } + + ecma_dealloc_extended_object (object_p, sizeof (ecma_extended_object_t)); +} /* ecma_free_fast_access_array */ + +/** + * Free non-objects referenced by inactive generator functions, async functions, etc. + * + * @return total object size + */ +static size_t +ecma_gc_free_executable_object (ecma_object_t *object_p) /**< object */ +{ + vm_executable_object_t *executable_object_p = (vm_executable_object_t *) object_p; + + const ecma_compiled_code_t *bytecode_header_p = executable_object_p->shared.bytecode_header_p; + size_t size, register_end; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + + register_end = args_p->register_end; + size = (register_end + (size_t) args_p->stack_limit) * sizeof (ecma_value_t); + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + + register_end = args_p->register_end; + size = (register_end + (size_t) args_p->stack_limit) * sizeof (ecma_value_t); + } + + size = JERRY_ALIGNUP (sizeof (vm_executable_object_t) + size, sizeof (uintptr_t)); + ecma_bytecode_deref ((ecma_compiled_code_t *) bytecode_header_p); + + uint16_t executable_obj_flags = executable_object_p->extended_object.u.cls.u2.executable_obj_flags; + + JERRY_ASSERT (!(executable_obj_flags & ECMA_EXECUTABLE_OBJECT_RUNNING)); + + if (executable_obj_flags & ECMA_ASYNC_GENERATOR_CALLED) + { + ecma_value_t task = executable_object_p->extended_object.u.cls.u3.head; + + while (!ECMA_IS_INTERNAL_VALUE_NULL (task)) + { + ecma_async_generator_task_t *task_p; + task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, task); + + JERRY_ASSERT (ecma_is_value_object (task_p->promise)); + ecma_free_value_if_not_object (task_p->operation_value); + + task = task_p->next; + jmem_heap_free_block (task_p, sizeof (ecma_async_generator_task_t)); + } + } + + if (executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED) + { + return size; + } + + ecma_free_value_if_not_object (executable_object_p->frame_ctx.this_binding); + + ecma_value_t *register_p = VM_GET_REGISTERS (&executable_object_p->frame_ctx); + ecma_value_t *register_end_p = register_p + register_end; + + while (register_p < register_end_p) + { + ecma_free_value_if_not_object (*register_p++); + } + + if (executable_object_p->frame_ctx.context_depth > 0) + { + ecma_value_t *context_end_p = register_p; + + register_p += executable_object_p->frame_ctx.context_depth; + + ecma_value_t *context_top_p = register_p; + + do + { + context_top_p[-1] &= (uint32_t) ~VM_CONTEXT_HAS_LEX_ENV; + + if (VM_CONTEXT_IS_VARIABLE_LENGTH (VM_GET_CONTEXT_TYPE (context_top_p[-1]))) + { + ecma_value_t *last_item_p = context_top_p - VM_GET_CONTEXT_END (context_top_p[-1]); + JERRY_ASSERT (last_item_p >= context_end_p); + context_top_p--; + + do + { + ecma_free_value_if_not_object (*(--context_top_p)); + } while (context_top_p > last_item_p); + + continue; + } + + uint32_t offsets = vm_get_context_value_offsets (context_top_p); + + while (VM_CONTEXT_HAS_NEXT_OFFSET (offsets)) + { + int32_t offset = VM_CONTEXT_GET_NEXT_OFFSET (offsets); + + if (ecma_is_value_object (context_top_p[offset])) + { + context_top_p[offset] = ECMA_VALUE_UNDEFINED; + } + + offsets >>= VM_CONTEXT_OFFSET_SHIFT; + } + + context_top_p = vm_stack_context_abort (&executable_object_p->frame_ctx, context_top_p); + } while (context_top_p > context_end_p); + } + + register_end_p = executable_object_p->frame_ctx.stack_top_p; + + while (register_p < register_end_p) + { + ecma_free_value_if_not_object (*register_p++); + } + + return size; +} /* ecma_gc_free_executable_object */ + +JERRY_STATIC_ASSERT (!ECMA_PROPERTY_IS_RAW (ECMA_PROPERTY_TYPE_DELETED), + ecma_property_type_deleted_must_not_be_raw_property); +JERRY_STATIC_ASSERT ((((int)ECMA_PROPERTY_TYPE_DELETED & (int)ECMA_PROPERTY_FLAG_LCACHED) == 0), + ecma_property_type_deleted_must_not_have_lcached_flag); +JERRY_STATIC_ASSERT ((((int)ECMA_GC_FREE_SECOND_PROPERTY) == 1), ecma_gc_free_second_must_be_one); + +/** + * Free property of an object + */ +void +ecma_gc_free_property (ecma_object_t *object_p, /**< object */ + ecma_property_pair_t *prop_pair_p, /**< property pair */ + uint32_t options) /**< option bits including property index */ +{ + /* Both cannot be deleted. */ + JERRY_ASSERT (prop_pair_p->header.types[0] != ECMA_PROPERTY_TYPE_DELETED + || prop_pair_p->header.types[1] != ECMA_PROPERTY_TYPE_DELETED); + JERRY_ASSERT (prop_pair_p->header.types[0] != ECMA_PROPERTY_TYPE_HASHMAP); + + uint32_t index = (options & ECMA_GC_FREE_SECOND_PROPERTY); + jmem_cpointer_t name_cp = prop_pair_p->names_cp[index]; + ecma_property_t *property_p = prop_pair_p->header.types + index; + ecma_property_t property = *property_p; + +#if JERRY_LCACHE + if ((property & ECMA_PROPERTY_FLAG_LCACHED) != 0) + { + ecma_lcache_invalidate (object_p, name_cp, property_p); + } +#endif /* JERRY_LCACHE */ + + if (ECMA_PROPERTY_IS_RAW (property)) + { + if (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_PTR) + { + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, name_cp); + ecma_deref_ecma_string (prop_name_p); + } + + if (property & ECMA_PROPERTY_FLAG_DATA) + { + ecma_free_value_if_not_object (prop_pair_p->values[index].value); + return; + } + + if (JERRY_UNLIKELY (options & ECMA_GC_FREE_REFERENCES)) + { + return; + } + return; + } + + if (property == ECMA_PROPERTY_TYPE_DELETED) + { + return; + } + + ecma_value_t value = prop_pair_p->values[index].value; + + switch (name_cp) + { + case LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD: + { + ecma_environment_record_t *environment_record_p; + environment_record_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t, value); + jmem_heap_free_block (environment_record_p, sizeof (ecma_environment_record_t)); + break; + } + case LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED: + { + ecma_value_t *compact_collection_p; + compact_collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, value); + ecma_compact_collection_free (compact_collection_p); + break; + } + case LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS: + { + ecma_value_t *compact_collection_p; + compact_collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, value); + + ecma_value_t *end_p = ecma_compact_collection_end (compact_collection_p); + ecma_value_t *current_p = compact_collection_p + 1; + + JERRY_ASSERT ((end_p - current_p) % ECMA_PRIVATE_ELEMENT_LIST_SIZE == 0); + + while (current_p < end_p) + { + current_p++; /* skip the type */ + ecma_deref_ecma_string (ecma_get_prop_name_from_value (*current_p++)); + current_p++; /* skip the value */ + } + + ecma_compact_collection_destroy (compact_collection_p); + break; + } + default: + { + JERRY_ASSERT (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER + || name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES); + ecma_gc_free_native_pointer (property, value); + break; + } + } +} /* ecma_gc_free_property */ + +/** + * Free properties of an object + */ +void +ecma_gc_free_properties (ecma_object_t *object_p, /**< object */ + uint32_t options) /**< option bits */ +{ + jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp; + +#if JERRY_PROPERTY_HASHMAP + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + ecma_property_hashmap_free (object_p); + prop_iter_cp = object_p->u1.property_list_cp; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (uint32_t i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + ecma_gc_free_property (object_p, prop_pair_p, i | options); + } + + prop_iter_cp = prop_iter_p->next_property_cp; + + ecma_dealloc_property_pair (prop_pair_p); + } +} /* ecma_gc_free_properties */ + +/** + * Free specified object. + */ +static void +ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */ +{ + JERRY_ASSERT (object_p != NULL && !ecma_gc_is_object_visited (object_p)); + + JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_objects_number) > 0); + JERRY_CONTEXT (ecma_gc_objects_number)--; + + if (ecma_is_lexical_environment (object_p)) + { +#if JERRY_MODULE_SYSTEM + if (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && (object_p->type_flags_refs & ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA)) + { + if (ECMA_LEX_ENV_CLASS_IS_MODULE (object_p)) + { + ecma_gc_free_properties (object_p, ECMA_GC_FREE_REFERENCES); + } + + ecma_dealloc_extended_object (object_p, sizeof (ecma_lexical_environment_class_t)); + return; + } +#endif /* JERRY_MODULE_SYSTEM */ + + if (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_gc_free_properties (object_p, ECMA_GC_FREE_NO_OPTIONS); + } + + ecma_dealloc_object (object_p); + return; + } + + ecma_object_type_t object_type = ecma_get_object_type (object_p); + + size_t ext_object_size = sizeof (ecma_extended_object_t); + + switch (object_type) + { + case ECMA_OBJECT_TYPE_GENERAL: + { + ecma_gc_free_properties (object_p, ECMA_GC_FREE_NO_OPTIONS); + ecma_dealloc_object (object_p); + return; + } + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + { + if (((ecma_extended_object_t *) object_p)->u.built_in.id == ECMA_BUILTIN_ID_GLOBAL) + { + ext_object_size = sizeof (ecma_global_object_t); + break; + } + + uint8_t bitset_size = ((ecma_extended_object_t *) object_p)->u.built_in.u.length_and_bitset_size; + ext_object_size += sizeof (uint64_t) * (bitset_size >> ECMA_BUILT_IN_BITSET_SHIFT); + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + { + ext_object_size = sizeof (ecma_extended_built_in_object_t); + uint8_t bitset_size = ((ecma_extended_built_in_object_t *) object_p)->built_in.u.length_and_bitset_size; + ext_object_size += sizeof (uint64_t) * (bitset_size >> ECMA_BUILT_IN_BITSET_SHIFT); + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_STRING: + case ECMA_OBJECT_CLASS_NUMBER: + case ECMA_OBJECT_CLASS_SYMBOL: +#if JERRY_BUILTIN_BIGINT + case ECMA_OBJECT_CLASS_BIGINT: +#endif /* JERRY_BUILTIN_BIGINT */ + { + ecma_free_value (ext_object_p->u.cls.u3.value); + break; + } + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + ext_object_size = ecma_free_arguments_object (ext_object_p); + break; + } +#if JERRY_BUILTIN_TYPEDARRAY + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + if (ext_object_p->u.cls.u2.typedarray_flags & ECMA_TYPEDARRAY_IS_EXTENDED) + { + ext_object_size = sizeof (ecma_extended_typedarray_object_t); + } + break; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE_NAMESPACE: + { + ecma_gc_free_properties (object_p, ECMA_GC_FREE_REFERENCES); + ecma_dealloc_extended_object (object_p, sizeof (ecma_extended_object_t)); + return; + } +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_PARSER + case ECMA_OBJECT_CLASS_SCRIPT: + { + ecma_compiled_code_t *compiled_code_p; + compiled_code_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value); + + ecma_bytecode_deref (compiled_code_p); + break; + } +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_DATE + case ECMA_OBJECT_CLASS_DATE: + { + ext_object_size = sizeof (ecma_date_object_t); + break; + } +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_REGEXP + case ECMA_OBJECT_CLASS_REGEXP: + { + ecma_compiled_code_t *bytecode_p = + ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value); + + ecma_bytecode_deref (bytecode_p); + + break; + } +#endif /* JERRY_BUILTIN_REGEXP */ + case ECMA_OBJECT_CLASS_STRING_ITERATOR: + { + ecma_value_t iterated_value = ext_object_p->u.cls.u3.iterated_value; + + if (!ecma_is_value_empty (iterated_value)) + { + ecma_deref_ecma_string (ecma_get_string_from_value (iterated_value)); + } + + break; + } +#if JERRY_BUILTIN_REGEXP + case ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR: + { + ecma_regexp_string_iterator_t *regexp_string_iterator_obj = (ecma_regexp_string_iterator_t *) object_p; + ecma_value_t iterated_string = regexp_string_iterator_obj->iterated_string; + + if (!ecma_is_value_empty (iterated_string)) + { + ecma_deref_ecma_string (ecma_get_string_from_value (iterated_string)); + } + + ext_object_size = sizeof (ecma_regexp_string_iterator_t); + break; + } +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_TYPEDARRAY + case ECMA_OBJECT_CLASS_ARRAY_BUFFER: +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + case ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER: +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + { + if (!(ECMA_ARRAYBUFFER_GET_FLAGS (ext_object_p) & ECMA_ARRAYBUFFER_HAS_POINTER)) + { + ext_object_size += ext_object_p->u.cls.u3.length; + break; + } + + ext_object_size = sizeof (ecma_arraybuffer_pointer_t); + + if (ECMA_ARRAYBUFFER_GET_FLAGS (ext_object_p) & ECMA_ARRAYBUFFER_ALLOCATED) + { + ecma_arraybuffer_release_buffer (object_p); + } + break; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_WEAKREF + case ECMA_OBJECT_CLASS_WEAKREF: + { + ecma_value_t target = ext_object_p->u.cls.u3.target; + + if (!ecma_is_value_undefined (target)) + { + ecma_op_object_unref_weak (ecma_get_object_from_value (target), ecma_make_object_value (object_p)); + } + break; + } +#endif /* JERRY_BUILTIN_WEAKREF */ +#if JERRY_BUILTIN_CONTAINER + case ECMA_OBJECT_CLASS_CONTAINER: + { + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + ecma_collection_t *container_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + ecma_op_container_free_entries (object_p); + ecma_collection_destroy (container_p); + break; + } +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_DATAVIEW + case ECMA_OBJECT_CLASS_DATAVIEW: + { + ext_object_size = sizeof (ecma_dataview_object_t); + break; + } +#endif /* JERRY_BUILTIN_DATAVIEW */ + case ECMA_OBJECT_CLASS_GENERATOR: + case ECMA_OBJECT_CLASS_ASYNC_GENERATOR: + { + ext_object_size = ecma_gc_free_executable_object (object_p); + break; + } + case ECMA_OBJECT_CLASS_PROMISE: + { + ecma_free_value_if_not_object (ext_object_p->u.cls.u3.value); + + /* Reactions only contains objects. */ + ecma_collection_destroy (((ecma_promise_object_t *) object_p)->reactions); + + ext_object_size = sizeof (ecma_promise_object_t); + break; + } + case ECMA_OBJECT_CLASS_PROMISE_CAPABILITY: + { + ext_object_size = sizeof (ecma_promise_capability_t); + break; + } + case ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR: + { + ext_object_size = sizeof (ecma_async_from_sync_iterator_object_t); + break; + } +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE: + { + ecma_module_release_module ((ecma_module_t *) ext_object_p); + ext_object_size = sizeof (ecma_module_t); + break; + } +#endif /* JERRY_MODULE_SYSTEM */ + default: + { + /* The ECMA_OBJECT_CLASS__MAX type represents an uninitialized class. */ + JERRY_ASSERT (ext_object_p->u.cls.type <= ECMA_OBJECT_CLASS__MAX); + break; + } + } + + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + ext_object_size = sizeof (ecma_extended_built_in_object_t); + uint8_t bitset_size = ((ecma_extended_built_in_object_t *) object_p)->built_in.u.length_and_bitset_size; + ext_object_size += sizeof (uint64_t) * (bitset_size >> ECMA_BUILT_IN_BITSET_SHIFT); + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_ARRAY: + { + if (ecma_op_array_is_fast_array ((ecma_extended_object_t *) object_p)) + { + ecma_free_fast_access_array (object_p); + return; + } + break; + } +#if JERRY_BUILTIN_PROXY + case ECMA_OBJECT_TYPE_PROXY: + { + ext_object_size = sizeof (ecma_proxy_object_t); + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_OBJECT_TYPE_FUNCTION: + { + /* Function with byte-code (not a built-in function). */ + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + +#if JERRY_SNAPSHOT_EXEC + if (ext_func_p->u.function.bytecode_cp != ECMA_NULL_POINTER) + { +#endif /* JERRY_SNAPSHOT_EXEC */ + ecma_compiled_code_t *byte_code_p = + (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_func_p->u.function.bytecode_cp)); + + if (CBC_FUNCTION_IS_ARROW (byte_code_p->status_flags)) + { + ecma_free_value_if_not_object (((ecma_arrow_function_t *) object_p)->this_binding); + ecma_free_value_if_not_object (((ecma_arrow_function_t *) object_p)->new_target); + ext_object_size = sizeof (ecma_arrow_function_t); + } + + ecma_bytecode_deref (byte_code_p); +#if JERRY_SNAPSHOT_EXEC + } + else + { + ext_object_size = sizeof (ecma_static_function_t); + } +#endif /* JERRY_SNAPSHOT_EXEC */ + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + ecma_extended_object_t *extended_func_p = (ecma_extended_object_t *) object_p; + + if (!ecma_builtin_function_is_routine (object_p)) + { + uint8_t bitset_size = extended_func_p->u.built_in.u.length_and_bitset_size; + ext_object_size += sizeof (uint64_t) * (bitset_size >> ECMA_BUILT_IN_BITSET_SHIFT); + break; + } + + if (extended_func_p->u.built_in.id != ECMA_BUILTIN_ID_HANDLER) + { + break; + } + + switch (extended_func_p->u.built_in.routine_id) + { + case ECMA_NATIVE_HANDLER_PROMISE_RESOLVE: + case ECMA_NATIVE_HANDLER_PROMISE_REJECT: + { + ext_object_size = sizeof (ecma_promise_resolver_t); + break; + } + case ECMA_NATIVE_HANDLER_PROMISE_THEN_FINALLY: + case ECMA_NATIVE_HANDLER_PROMISE_CATCH_FINALLY: + { + ext_object_size = sizeof (ecma_promise_finally_function_t); + break; + } + case ECMA_NATIVE_HANDLER_PROMISE_CAPABILITY_EXECUTOR: + { + ext_object_size = sizeof (ecma_promise_capability_executor_t); + break; + } + case ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER: + { + ext_object_size = sizeof (ecma_promise_all_executor_t); + break; + } +#if JERRY_BUILTIN_PROXY + case ECMA_NATIVE_HANDLER_PROXY_REVOKE: + { + ext_object_size = sizeof (ecma_revocable_proxy_object_t); + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_NATIVE_HANDLER_VALUE_THUNK: + case ECMA_NATIVE_HANDLER_VALUE_THROWER: + { + ecma_free_value_if_not_object (((ecma_promise_value_thunk_t *) object_p)->value); + ext_object_size = sizeof (ecma_promise_value_thunk_t); + break; + } + case ECMA_NATIVE_HANDLER_ASYNC_FROM_SYNC_ITERATOR_UNWRAP: + { + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + ext_object_size = sizeof (ecma_bound_function_t); + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p; + + ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this; + + ecma_free_value (bound_func_p->target_length); + + if (!ecma_is_value_integer_number (args_len_or_this)) + { + ecma_free_value_if_not_object (args_len_or_this); + break; + } + + ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this); + ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1); + + for (ecma_integer_value_t i = 0; i < args_length; i++) + { + ecma_free_value_if_not_object (args_p[i]); + } + + size_t args_size = ((size_t) args_length) * sizeof (ecma_value_t); + ext_object_size += args_size; + break; + } + case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION: + { + ecma_script_deref (((ecma_extended_object_t *) object_p)->u.constructor_function.script_value); + break; + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + ext_object_size = sizeof (ecma_native_function_t); + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + + ecma_gc_free_properties (object_p, ECMA_GC_FREE_NO_OPTIONS); + ecma_dealloc_extended_object (object_p, ext_object_size); +} /* ecma_gc_free_object */ + +/** + * Run garbage collection, freeing objects that are no longer referenced. + */ +void +ecma_gc_run (void) +{ +#if (JERRY_GC_MARK_LIMIT != 0) + JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_mark_recursion_limit) == JERRY_GC_MARK_LIMIT); +#endif /* (JERRY_GC_MARK_LIMIT != 0) */ + + JERRY_CONTEXT (ecma_gc_new_objects) = 0; + + ecma_object_t black_list_head; + black_list_head.gc_next_cp = JMEM_CP_NULL; + ecma_object_t *black_end_p = &black_list_head; + + ecma_object_t white_gray_list_head; + white_gray_list_head.gc_next_cp = JERRY_CONTEXT (ecma_gc_objects_cp); + + ecma_object_t *obj_prev_p = &white_gray_list_head; + jmem_cpointer_t obj_iter_cp = obj_prev_p->gc_next_cp; + ecma_object_t *obj_iter_p; + + /* Move root objects (i.e. they have global or stack references) to the black list. */ + while (obj_iter_cp != JMEM_CP_NULL) + { + obj_iter_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_object_t, obj_iter_cp); + const jmem_cpointer_t obj_next_cp = obj_iter_p->gc_next_cp; + + JERRY_ASSERT (obj_prev_p == NULL + || ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_prev_p->gc_next_cp) == obj_iter_p); + + if (obj_iter_p->type_flags_refs >= ECMA_OBJECT_REF_ONE) + { + /* Moving the object to list of marked objects. */ + obj_prev_p->gc_next_cp = obj_next_cp; + + black_end_p->gc_next_cp = obj_iter_cp; + black_end_p = obj_iter_p; + } + else + { + obj_iter_p->type_flags_refs |= ECMA_OBJECT_NON_VISITED; + obj_prev_p = obj_iter_p; + } + + obj_iter_cp = obj_next_cp; + } + + black_end_p->gc_next_cp = JMEM_CP_NULL; + + /* Mark root objects. */ + obj_iter_cp = black_list_head.gc_next_cp; + while (obj_iter_cp != JMEM_CP_NULL) + { + obj_iter_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_object_t, obj_iter_cp); + ecma_gc_mark (obj_iter_p); + obj_iter_cp = obj_iter_p->gc_next_cp; + } + + /* Mark non-root objects. */ + bool marked_anything_during_current_iteration; + + do + { +#if (JERRY_GC_MARK_LIMIT != 0) + JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_mark_recursion_limit) == JERRY_GC_MARK_LIMIT); +#endif /* (JERRY_GC_MARK_LIMIT != 0) */ + + marked_anything_during_current_iteration = false; + + obj_prev_p = &white_gray_list_head; + obj_iter_cp = obj_prev_p->gc_next_cp; + + while (obj_iter_cp != JMEM_CP_NULL) + { + obj_iter_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_object_t, obj_iter_cp); + const jmem_cpointer_t obj_next_cp = obj_iter_p->gc_next_cp; + + JERRY_ASSERT (obj_prev_p == NULL + || ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_prev_p->gc_next_cp) == obj_iter_p); + + if (ecma_gc_is_object_visited (obj_iter_p)) + { + /* Moving the object to list of marked objects */ + obj_prev_p->gc_next_cp = obj_next_cp; + + black_end_p->gc_next_cp = obj_iter_cp; + black_end_p = obj_iter_p; + +#if (JERRY_GC_MARK_LIMIT != 0) + if (obj_iter_p->type_flags_refs >= ECMA_OBJECT_REF_ONE) + { + /* Set the reference count of non-marked gray object to 0 */ + obj_iter_p->type_flags_refs &= (ecma_object_descriptor_t) (ECMA_OBJECT_REF_ONE - 1); + ecma_gc_mark (obj_iter_p); + marked_anything_during_current_iteration = true; + } +#else /* (JERRY_GC_MARK_LIMIT == 0) */ + marked_anything_during_current_iteration = true; +#endif /* (JERRY_GC_MARK_LIMIT != 0) */ + } + else + { + obj_prev_p = obj_iter_p; + } + + obj_iter_cp = obj_next_cp; + } + } while (marked_anything_during_current_iteration); + + black_end_p->gc_next_cp = JMEM_CP_NULL; + JERRY_CONTEXT (ecma_gc_objects_cp) = black_list_head.gc_next_cp; + + /* Sweep objects that are currently unmarked. */ + obj_iter_cp = white_gray_list_head.gc_next_cp; + + while (obj_iter_cp != JMEM_CP_NULL) + { + obj_iter_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_object_t, obj_iter_cp); + const jmem_cpointer_t obj_next_cp = obj_iter_p->gc_next_cp; + + JERRY_ASSERT (!ecma_gc_is_object_visited (obj_iter_p)); + + ecma_gc_free_object (obj_iter_p); + obj_iter_cp = obj_next_cp; + } + +#if JERRY_BUILTIN_REGEXP + /* Free RegExp bytecodes stored in cache */ + re_cache_gc (); +#endif /* JERRY_BUILTIN_REGEXP */ +} /* ecma_gc_run */ + +/** + * Try to free some memory (depending on memory pressure). + * + * When called with JMEM_PRESSURE_FULL, the engine will be terminated with JERRY_FATAL_OUT_OF_MEMORY. + */ +void +ecma_free_unused_memory (jmem_pressure_t pressure) /**< current pressure */ +{ + if (JERRY_LIKELY (pressure == JMEM_PRESSURE_LOW)) + { +#if JERRY_PROPERTY_HASHMAP + if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) > ECMA_PROP_HASHMAP_ALLOC_ON) + { + --JERRY_CONTEXT (ecma_prop_hashmap_alloc_state); + } + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_HIGH_PRESSURE_GC; +#endif /* JERRY_PROPERTY_HASHMAP */ + /* + * If there is enough newly allocated objects since last GC, probably it is worthwhile to start GC now. + * Otherwise, probability to free sufficient space is considered to be low. + */ + size_t new_objects_fraction = CONFIG_ECMA_GC_NEW_OBJECTS_FRACTION; + + if (JERRY_CONTEXT (ecma_gc_new_objects) * new_objects_fraction > JERRY_CONTEXT (ecma_gc_objects_number)) + { + ecma_gc_run (); + } + + return; + } + else if (pressure == JMEM_PRESSURE_HIGH) + { + /* Freeing as much memory as we currently can */ +#if JERRY_PROPERTY_HASHMAP + if (JERRY_CONTEXT (status_flags) & ECMA_STATUS_HIGH_PRESSURE_GC) + { + JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) = ECMA_PROP_HASHMAP_ALLOC_MAX; + } + else if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) < ECMA_PROP_HASHMAP_ALLOC_MAX) + { + ++JERRY_CONTEXT (ecma_prop_hashmap_alloc_state); + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_HIGH_PRESSURE_GC; + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + ecma_gc_run (); + +#if JERRY_PROPERTY_HASHMAP + /* Free hashmaps of remaining objects. */ + jmem_cpointer_t obj_iter_cp = JERRY_CONTEXT (ecma_gc_objects_cp); + + while (obj_iter_cp != JMEM_CP_NULL) + { + ecma_object_t *obj_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_iter_cp); + + if (!ecma_is_lexical_environment (obj_iter_p) + || ecma_get_lex_env_type (obj_iter_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + if (!ecma_is_lexical_environment (obj_iter_p) && ecma_op_object_is_fast_array (obj_iter_p)) + { + obj_iter_cp = obj_iter_p->gc_next_cp; + continue; + } + + jmem_cpointer_t prop_iter_cp = obj_iter_p->u1.property_list_cp; + + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + ecma_property_hashmap_free (obj_iter_p); + } + } + } + + obj_iter_cp = obj_iter_p->gc_next_cp; + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + jmem_pools_collect_empty (); + return; + } + else if (JERRY_UNLIKELY (pressure == JMEM_PRESSURE_FULL)) + { + jerry_fatal (JERRY_FATAL_OUT_OF_MEMORY); + } + else + { + JERRY_ASSERT (pressure == JMEM_PRESSURE_NONE); + JERRY_UNREACHABLE (); + } +} /* ecma_free_unused_memory */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-gc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-gc.h new file mode 100644 index 0000000..94a6d2a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-gc.h @@ -0,0 +1,54 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_GC_H +#define ECMA_GC_H + +#include "ecma-globals.h" + +#include "jmem.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmagc Garbage collector + * @{ + */ + +/** + * Free option flags + */ +typedef enum +{ + ECMA_GC_FREE_NO_OPTIONS = 0, /**< no options */ + ECMA_GC_FREE_SECOND_PROPERTY = (1 << 0), /**< free second property of a property pair */ + ECMA_GC_FREE_REFERENCES = (1 << 1), /**< free references */ +} ecma_gc_free_options_t; + +void ecma_init_gc_info (ecma_object_t *object_p); +void ecma_ref_object (ecma_object_t *object_p); +void ecma_ref_object_inline (ecma_object_t *object_p); +void ecma_deref_object (ecma_object_t *object_p); +void ecma_gc_free_property (ecma_object_t *object_p, ecma_property_pair_t *prop_pair_p, uint32_t options); +void ecma_gc_free_properties (ecma_object_t *object_p, uint32_t options); +void ecma_gc_run (void); +void ecma_free_unused_memory (jmem_pressure_t pressure); + +/** + * @} + * @} + */ + +#endif /* !ECMA_GC_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-globals.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-globals.h new file mode 100644 index 0000000..4e2ec32 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-globals.h @@ -0,0 +1,2238 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_GLOBALS_H +#define ECMA_GLOBALS_H + +#include "jerry-config.h" +#include "ecma-errors.h" +#include "jmem.h" +#include "jrt.h" +#include "lit-magic-strings.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmatypes ECMA types + * @{ + * + * \addtogroup compressedpointer Compressed pointer + * @{ + */ + +/** + * The NULL value for compressed pointers + */ +#define ECMA_NULL_POINTER JMEM_CP_NULL + +#if defined(JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY) + +/** + * JMEM_ALIGNMENT_LOG aligned pointers can be stored directly in ecma_value_t + */ +#define ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY + +#endif /* JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY */ + +/** + * @} + */ + +/** + * JerryScript status flags. + */ +typedef enum +{ + ECMA_STATUS_API_ENABLED = (1u << 0), /**< api available */ + ECMA_STATUS_DIRECT_EVAL = (1u << 1), /**< eval is called directly */ +#if JERRY_PROPERTY_HASHMAP + ECMA_STATUS_HIGH_PRESSURE_GC = (1u << 2), /**< last gc was under high pressure */ +#endif /* JERRY_PROPERTY_HASHMAP */ + ECMA_STATUS_EXCEPTION = (1u << 3), /**< last exception is a normal exception */ + ECMA_STATUS_ABORT = (1u << 4), /**< last exception is an abort */ + ECMA_STATUS_ERROR_UPDATE = (1u << 5), /**< the error_object_created_callback_p is called */ +#if JERRY_VM_THROW + ECMA_STATUS_ERROR_THROWN = (1u << 6), /**< the vm_throw_callback_p is called */ +#endif /* JERRY_VM_THROW */ +} ecma_status_flag_t; + +/** + * Type of ecma value + */ +typedef enum +{ + ECMA_TYPE_DIRECT = 0, /**< directly encoded value, a 28 bit signed integer or a simple value */ + ECMA_TYPE_STRING = 1, /**< pointer to description of a string */ + ECMA_TYPE_FLOAT = 2, /**< pointer to a 64 or 32 bit floating point number */ + ECMA_TYPE_OBJECT = 3, /**< pointer to description of an object */ + ECMA_TYPE_SYMBOL = 4, /**< pointer to description of a symbol */ + ECMA_TYPE_DIRECT_STRING = 5, /**< directly encoded string values */ + ECMA_TYPE_BIGINT = 6, /**< pointer to a bigint primitive */ + ECMA_TYPE_ERROR = 7, /**< pointer to description of an error reference (only supported by C API) */ + ECMA_TYPE_SNAPSHOT_OFFSET = ECMA_TYPE_ERROR, /**< offset to a snapshot number/string */ + ECMA_TYPE___MAX = ECMA_TYPE_ERROR /** highest value for ecma types */ +} ecma_type_t; + +/** + * Option flags for parser_parse_script and internal flags for global_status_flags in parser context. + */ +typedef enum +{ + ECMA_PARSE_NO_OPTS = 0, /**< no options passed */ + ECMA_PARSE_STRICT_MODE = (1u << 0), /**< enable strict mode, must be same as PARSER_IS_STRICT */ + ECMA_PARSE_MODULE = (1u << 1), /**< module is parsed */ + ECMA_PARSE_EVAL = (1u << 2), /**< eval is called */ + ECMA_PARSE_DIRECT_EVAL = (1u << 3), /**< eval is called directly (ECMA-262 v5, 15.1.2.1.1) */ + ECMA_PARSE_CLASS_CONSTRUCTOR = (1u << 4), /**< a class constructor is being parsed */ + + /* These five status flags must be in this order. The first four are also parser status flags. + * See PARSER_SAVE_STATUS_FLAGS / PARSER_RESTORE_STATUS_FLAGS. */ + ECMA_PARSE_ALLOW_SUPER = (1u << 5), /**< allow super property access */ + ECMA_PARSE_ALLOW_SUPER_CALL = (1u << 6), /**< allow super constructor call */ + ECMA_PARSE_FUNCTION_IS_PARSING_ARGS = (1u << 7), /**< set when parsing function arguments */ + ECMA_PARSE_INSIDE_CLASS_FIELD = (1u << 8), /**< a class field is being parsed */ + ECMA_PARSE_ALLOW_NEW_TARGET = (1u << 9), /**< allow new.target access */ + ECMA_PARSE_FUNCTION_CONTEXT = (1u << 10), /**< function context is present (ECMA_PARSE_DIRECT_EVAL must be set) */ + + ECMA_PARSE_HAS_SOURCE_VALUE = (1u << 11), /**< source_p points to a value list + * and the first value is the source code */ + ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE = (1u << 12), /**< source_p points to a value list + * and the second value is the argument list */ + ECMA_PARSE_GENERATOR_FUNCTION = (1u << 13), /**< generator function is parsed */ + ECMA_PARSE_ASYNC_FUNCTION = (1u << 14), /**< async function is parsed */ + + /* These flags are internally used by the parser. */ + ECMA_PARSE_INTERNAL_FREE_SOURCE = (1u << 15), /**< free source_p data */ + ECMA_PARSE_INTERNAL_FREE_ARG_LIST = (1u << 16), /**< free arg_list_p data */ + ECMA_PARSE_INTERNAL_PRE_SCANNING = (1u << 17), /**< the parser is in pre-scanning mode */ +#if JERRY_MODULE_SYSTEM + ECMA_PARSE_INTERNAL_HAS_IMPORT_META = (1u << 18), /**< module has import.meta expression */ +#endif /* JERRY_MODULE_SYSTEM */ +#ifndef JERRY_NDEBUG + /** + * This flag represents an error in for in/of statements, which cannot be set + * if the parsing is completed successfully. + */ + ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR = (1u << 30), +#endif /* !JERRY_NDEBUG */ +} ecma_parse_opts_t; + +/** + * Description of an ecma value + * + * Bit-field structure: type (3) | value (29) + */ +typedef uint32_t ecma_value_t; + +/** + * Type for directly encoded integer numbers in JerryScript. + */ +typedef int32_t ecma_integer_value_t; + +/** + * Mask for ecma types in ecma_value_t + */ +#define ECMA_VALUE_TYPE_MASK 0x7u + +/** + * Shift for value part in ecma_value_t + */ +#define ECMA_VALUE_SHIFT 3 + +/** + * Mask for directly encoded values + */ +#define ECMA_DIRECT_TYPE_MASK ((1u << ECMA_VALUE_SHIFT) | ECMA_VALUE_TYPE_MASK) + +/** + * Ecma integer value type + */ +#define ECMA_DIRECT_TYPE_INTEGER_VALUE ((0u << ECMA_VALUE_SHIFT) | ECMA_TYPE_DIRECT) + +/** + * Ecma simple value type + */ +#define ECMA_DIRECT_TYPE_SIMPLE_VALUE ((1u << ECMA_VALUE_SHIFT) | ECMA_TYPE_DIRECT) + +/** + * Shift for directly encoded values in ecma_value_t + */ +#define ECMA_DIRECT_SHIFT 4 + +/** + * ECMA make simple value + */ +#define ECMA_MAKE_VALUE(value) ((((ecma_value_t) (value)) << ECMA_DIRECT_SHIFT) | ECMA_DIRECT_TYPE_SIMPLE_VALUE) + +/** + * Simple ecma values + */ +enum +{ + /** + * Empty value is implementation defined value, used for representing: + * - empty (uninitialized) values + * - immutable binding values + * - special register or stack values for vm + */ + ECMA_VALUE_EMPTY = ECMA_MAKE_VALUE (0), /**< uninitialized value */ + ECMA_VALUE_ERROR = ECMA_MAKE_VALUE (1), /**< an error is currently thrown */ + ECMA_VALUE_FALSE = ECMA_MAKE_VALUE (2), /**< boolean false */ + ECMA_VALUE_TRUE = ECMA_MAKE_VALUE (3), /**< boolean true */ + ECMA_VALUE_UNDEFINED = ECMA_MAKE_VALUE (4), /**< undefined value */ + ECMA_VALUE_NULL = ECMA_MAKE_VALUE (5), /**< null value */ + ECMA_VALUE_UNINITIALIZED = ECMA_MAKE_VALUE (6), /**< a special value for uninitialized let/const declarations */ + ECMA_VALUE_NOT_FOUND = ECMA_MAKE_VALUE (7), /**< a special value returned by + * ecma_op_object_find */ + /* Values for controlling the VM */ + ECMA_VALUE_ARRAY_HOLE = ECMA_MAKE_VALUE (8), /**< array hole, used for + * initialization of an array literal */ + ECMA_VALUE_REGISTER_REF = ECMA_MAKE_VALUE (9), /**< register reference, + * a special "base" value for vm */ + ECMA_VALUE_RELEASE_LEX_ENV = ECMA_MAKE_VALUE (10), /**< if this error remains on the stack when an exception occurs + the top lexical environment of the VM frame should be popped */ + ECMA_VALUE_SPREAD_ELEMENT = ECMA_MAKE_VALUE (11), /**< a special value for spread elements in array initialization + * or function call argument list */ + /* Other values */ + ECMA_VALUE_ARGUMENT_NO_TRACK = ECMA_MAKE_VALUE (12), /**< represents not-tracked arguments formal parameter */ + ECMA_VALUE_SYNC_ITERATOR = ECMA_MAKE_VALUE (13), /**< option for ecma_op_get_iterator: sync iterator is requested */ + ECMA_VALUE_ASYNC_ITERATOR = ECMA_MAKE_VALUE (14), /**< option for ecma_op_get_iterator: async iterator is requested */ +#if JERRY_BUILTIN_GLOBAL_THIS + ECMA_VALUE_GLOBAL_THIS = ECMA_MAKE_VALUE (15), /**< globalThis built-in */ +#endif /* JERRY_BUILTIN_GLOBAL_THIS */ +}; + +#if !JERRY_NUMBER_TYPE_FLOAT64 +/** + * Maximum integer number for an ecma value + */ +#define ECMA_INTEGER_NUMBER_MAX 0x7fffff +/** + * Maximum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT) + */ +#define ECMA_INTEGER_NUMBER_MAX_SHIFTED 0x7fffff0 +#else /* JERRY_NUMBER_TYPE_FLOAT64 */ +/** + * Maximum integer number for an ecma value + */ +#define ECMA_INTEGER_NUMBER_MAX 0x7ffffff +/** + * Maximum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT) + */ +#define ECMA_INTEGER_NUMBER_MAX_SHIFTED 0x7ffffff0 +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +#if !JERRY_NUMBER_TYPE_FLOAT64 +/** + * Minimum integer number for an ecma value + */ +#define ECMA_INTEGER_NUMBER_MIN -0x7fffff +/** + * Minimum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT) + */ +#define ECMA_INTEGER_NUMBER_MIN_SHIFTED -0x7fffff0 +#else /* JERRY_NUMBER_TYPE_FLOAT64 */ +/** + * Minimum integer number for an ecma value + */ +#define ECMA_INTEGER_NUMBER_MIN -0x8000000 +/** + * Minimum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT) + */ +#define ECMA_INTEGER_NUMBER_MIN_SHIFTED (-0x7fffffff - 1) /* -0x80000000 */ +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +#if ECMA_DIRECT_SHIFT != 4 +#error "Please update ECMA_INTEGER_NUMBER_MIN/MAX_SHIFTED according to the new value of ECMA_DIRECT_SHIFT." +#endif /* ECMA_DIRECT_SHIFT != 4 */ + +/** + * Checks whether the integer number is in the integer number range. + */ +#define ECMA_IS_INTEGER_NUMBER(num) (ECMA_INTEGER_NUMBER_MIN <= (num) && (num) <= ECMA_INTEGER_NUMBER_MAX) + +/** + * Maximum integer number, which if squared, still fits in ecma_integer_value_t + */ +#if !JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_INTEGER_MULTIPLY_MAX 0xb50 +#else /* JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_INTEGER_MULTIPLY_MAX 0x2d41 +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Checks whether the error flag is set. + */ +#define ECMA_IS_VALUE_ERROR(value) (JERRY_UNLIKELY ((value) == ECMA_VALUE_ERROR)) + +/** + * Callback which tells whether the ECMAScript execution should be stopped. + */ +typedef ecma_value_t (*ecma_vm_exec_stop_callback_t) (void *user_p); + +/** + * Forward definition of jerry_call_info_t. + */ +struct jerry_call_info_t; + +/** + * Type of an external function handler. + */ +typedef ecma_value_t (*ecma_native_handler_t) (const struct jerry_call_info_t *call_info_p, + const ecma_value_t args_p[], + const uint32_t args_count); + +/** + * Representation of native pointer data. + */ +typedef struct +{ + void *native_p; /**< points to the data of the object */ + jerry_object_native_info_t *native_info_p; /**< native info */ +} ecma_native_pointer_t; + +/** + * Representation of native pointer data chain. + */ +typedef struct ecma_native_pointer_chain_t +{ + ecma_native_pointer_t data; /**< pointer data */ + struct ecma_native_pointer_chain_t *next_p; /**< next in the list */ +} ecma_native_pointer_chain_t; + +/** + * Representation for class constructor environment record. + */ +typedef struct +{ + ecma_value_t this_binding; /**< this binding */ + ecma_value_t function_object; /**< function object */ +} ecma_environment_record_t; + +/** + * Property list: + * The property list of an object is a chain list of various items. + * The type of each item is stored in the first byte of the item. + * + * The most common item is the property pair, which contains two + * ecmascript properties. It is also important, that after the + * first property pair, only property pair items are allowed. + * + * Example for other items is property name hash map, or array of items. + */ + +/** + * Property name listing options. + */ +typedef enum +{ + ECMA_LIST_NO_OPTS = (0), /**< no options are provided */ + ECMA_LIST_ARRAY_INDICES = (1 << 0), /**< exclude properties with names + * that are not indices */ + ECMA_LIST_ENUMERABLE = (1 << 1), /**< exclude non-enumerable properties */ + ECMA_LIST_PROTOTYPE = (1 << 2), /**< list properties from prototype chain */ + ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties */ + ECMA_LIST_SYMBOLS_ONLY = (1 << 4), /**< list symbol properties only */ + ECMA_LIST_CONVERT_FAST_ARRAYS = (1 << 5), /**< after listing the properties convert + * the fast access mode array back to normal array */ +} ecma_list_properties_options_t; + +/** + * Enumerable property name listing options. + */ +typedef enum +{ + ECMA_ENUMERABLE_PROPERTY_KEYS, /**< List only property names */ + ECMA_ENUMERABLE_PROPERTY_VALUES, /**< List only property values */ + ECMA_ENUMERABLE_PROPERTY_ENTRIES, /**< List both property names and values */ + + ECMA_ENUMERABLE_PROPERTY__COUNT /**< Number of enumerable property listing types */ +} ecma_enumerable_property_names_options_t; + +/** + * List enumerable properties and include the prototype chain. + */ +#define ECMA_LIST_ENUMERABLE_PROTOTYPE (ECMA_LIST_ENUMERABLE | ECMA_LIST_PROTOTYPE) + +/** + * Property flag list. Several flags are alias + */ +typedef enum +{ + ECMA_PROPERTY_FLAG_CONFIGURABLE = (1u << 0), /**< property is configurable */ + ECMA_PROPERTY_FLAG_ENUMERABLE = (1u << 1), /**< property is enumerable */ + ECMA_PROPERTY_FLAG_WRITABLE = (1u << 2), /**< property is writable */ + ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL = (1u << 2), /**< only one external pointer is assigned to this object */ + ECMA_PROPERTY_FLAG_DELETED = (1u << 3), /**< property is deleted */ + ECMA_PROPERTY_FLAG_BUILT_IN = (1u << 3), /**< property is defined by the ECMAScript standard */ + ECMA_FAST_ARRAY_FLAG = (1u << 3), /**< array is fast array */ + ECMA_PROPERTY_FLAG_LCACHED = (1u << 4), /**< property is lcached */ + ECMA_ARRAY_TEMPLATE_LITERAL = (1u << 4), /**< array is a template literal constructed by the parser */ + ECMA_PROPERTY_FLAG_DATA = (1u << 5), /**< property contains data */ + /* The last two bits contains an ECMA_DIRECT_STRING value. */ +} ecma_property_flags_t; + +/** + * Property flags configurable, enumerable, writable. + */ +#define ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE \ + (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE) + +/** + * Property flags configurable, enumerable. + */ +#define ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_ENUMERABLE) + +/** + * Property flags configurable, enumerable. + */ +#define ECMA_PROPERTY_CONFIGURABLE_WRITABLE (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_WRITABLE) + +/** + * Property flag built-in. + */ +#define ECMA_PROPERTY_BUILT_IN_FIXED (ECMA_PROPERTY_FLAG_BUILT_IN) + +/** + * Property flags enumerable, writable. + */ +#define ECMA_PROPERTY_ENUMERABLE_WRITABLE (ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE) + +/** + * Property flags built-in, configurable. + */ +#define ECMA_PROPERTY_BUILT_IN_CONFIGURABLE (ECMA_PROPERTY_FLAG_BUILT_IN | ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/** + * Property flags built-in, configurable, enumerable. + */ +#define ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_ENUMERABLE \ + (ECMA_PROPERTY_FLAG_BUILT_IN | ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE) + +/** + * Property flags built-in, configurable, writable. + */ +#define ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_WRITABLE (ECMA_PROPERTY_FLAG_BUILT_IN | ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/** + * Property flags built-in, writable. + */ +#define ECMA_PROPERTY_BUILT_IN_WRITABLE (ECMA_PROPERTY_FLAG_BUILT_IN | ECMA_PROPERTY_FLAG_WRITABLE) + +/** + * Property flags built-in, configurable, enumerable, writable. + */ +#define ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_ENUMERABLE_WRITABLE \ + (ECMA_PROPERTY_FLAG_BUILT_IN | ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +/** + * No attributes can be changed for this property. + */ +#define ECMA_PROPERTY_FIXED 0 + +/** + * Default flag of length property. + */ +#define ECMA_PROPERTY_FLAG_DEFAULT_LENGTH ECMA_PROPERTY_FLAG_CONFIGURABLE + +/** + * Shift for property name part. + */ +#define ECMA_PROPERTY_NAME_TYPE_SHIFT 6 + +/** + * Type of hash-map property. + */ +#define ECMA_PROPERTY_TYPE_HASHMAP (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT) + +/** + * Type of deleted property. + */ +#define ECMA_PROPERTY_TYPE_DELETED \ + (ECMA_PROPERTY_FLAG_DELETED | (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + +/** + * Type of property not found. + */ +#define ECMA_PROPERTY_TYPE_NOT_FOUND ECMA_PROPERTY_TYPE_HASHMAP + +/** + * Type of property not found and no more searching in the proto chain. + */ +#define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP ECMA_PROPERTY_TYPE_DELETED + +/** + * Type of property not found and an exception is thrown. + */ +#define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW \ + (ECMA_PROPERTY_FLAG_LCACHED | (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + +/** + * Checks whether a property is not found. + */ +#define ECMA_PROPERTY_IS_FOUND(property) \ + (((property) & (ECMA_PROPERTY_FLAG_DATA | (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT))) \ + != (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + +/** + * Abstract property representation. + * + * A property is a type_and_flags byte and an ecma_value_t value pair. + * This pair is represented by a single pointer in JerryScript. Although + * a packed struct would only consume sizeof(ecma_value_t)+1 memory + * bytes, accessing such structure is inefficient from the CPU viewpoint + * because the value is not naturally aligned. To improve performance, + * two type bytes and values are packed together. The memory layout is + * the following: + * + * [type 1, type 2, unused byte 1, unused byte 2][value 1][value 2] + * + * The unused two bytes are used to store a compressed pointer for the + * next property pair. + * + * The advantage of this layout is that the value reference can be computed + * from the property address. However, property pointers cannot be compressed + * anymore. + */ +typedef uint8_t ecma_property_t; /**< ecma_property_types_t (3 bit) and ecma_property_flags_t */ + +/** + * Number of items in a property pair. + */ +#define ECMA_PROPERTY_PAIR_ITEM_COUNT 2 + +/** + * Property header for all items in a property list. + */ +typedef struct +{ + ecma_property_t types[ECMA_PROPERTY_PAIR_ITEM_COUNT]; /**< two property type slot. The first represent + * the type of this property (e.g. property pair) */ + jmem_cpointer_t next_property_cp; /**< next cpointer */ +} ecma_property_header_t; + +/** + * Pair of pointers - to property's getter and setter + */ +typedef struct +{ + jmem_cpointer_t getter_cp; /**< compressed pointer to getter object */ + jmem_cpointer_t setter_cp; /**< compressed pointer to setter object */ +} ecma_getter_setter_pointers_t; + +/** + * Property data. + */ +typedef union +{ + ecma_value_t value; /**< value of a property */ + ecma_getter_setter_pointers_t getter_setter_pair; /**< getter setter pair */ +} ecma_property_value_t; + +/** + * Property pair. + */ +typedef struct +{ + ecma_property_header_t header; /**< header of the property */ + ecma_property_value_t values[ECMA_PROPERTY_PAIR_ITEM_COUNT]; /**< property value slots */ + jmem_cpointer_t names_cp[ECMA_PROPERTY_PAIR_ITEM_COUNT]; /**< property name slots */ +} ecma_property_pair_t; + +/** + * Get property name type. + */ +#define ECMA_PROPERTY_GET_NAME_TYPE(property) ((property) >> ECMA_PROPERTY_NAME_TYPE_SHIFT) + +/** + * Returns true if the property pointer is a property pair. + */ +#define ECMA_PROPERTY_IS_PROPERTY_PAIR(property_header_p) ((property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP) + +/** + * Property value of all internal properties + */ +#define ECMA_PROPERTY_INTERNAL (ECMA_PROPERTY_FLAG_DATA | (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + +/** + * Checks whether a property is internal property + */ +#define ECMA_PROPERTY_IS_INTERNAL(property) ((property) >= ECMA_PROPERTY_INTERNAL) + +/** + * Checks whether a property is raw data or accessor property + */ +#define ECMA_PROPERTY_IS_RAW(property) ((property) < (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + +/** + * Checks whether a property is raw data property (should only be used in assertions) + */ +#define ECMA_PROPERTY_IS_RAW_DATA(property) \ + (((property) &ECMA_PROPERTY_FLAG_DATA) && (property) < ECMA_PROPERTY_INTERNAL) + +/** + * Create internal property. + */ +#define ECMA_CREATE_INTERNAL_PROPERTY(object_p, name_p, property_p, property_value_p) \ + do \ + { \ + (property_value_p) = ecma_create_named_data_property ((object_p), (name_p), 0, &(property_p)); \ + JERRY_ASSERT (*(property_p) == ECMA_PROPERTY_INTERNAL); \ + } while (0) + +/** + * Property type of all virtual properties + */ +#define ECMA_PROPERTY_VIRTUAL ECMA_PROPERTY_INTERNAL + +/** + * Checks whether a property is virtual property + */ +#define ECMA_PROPERTY_IS_VIRTUAL(property) ECMA_PROPERTY_IS_INTERNAL (property) + +/** + * Returns true if the property is named property. + */ +#define ECMA_PROPERTY_IS_NAMED_PROPERTY(property) \ + ((property) < ECMA_PROPERTY_TYPE_HASHMAP || (property) >= ECMA_PROPERTY_INTERNAL) + +/** + * Add the offset part to a property for computing its property data pointer. + */ +#define ECMA_PROPERTY_VALUE_ADD_OFFSET(property_p) \ + ((uintptr_t) ((((uint8_t *) (property_p)) + (sizeof (ecma_property_value_t) * 2 - 1)))) + +/** + * Align the property for computing its property data pointer. + */ +#define ECMA_PROPERTY_VALUE_DATA_PTR(property_p) \ + (ECMA_PROPERTY_VALUE_ADD_OFFSET (property_p) & ~(sizeof (ecma_property_value_t) - 1)) + +/** + * Compute the property data pointer of a property. + * The property must be part of a property pair. + */ +#define ECMA_PROPERTY_VALUE_PTR(property_p) ((ecma_property_value_t *) ECMA_PROPERTY_VALUE_DATA_PTR (property_p)) + +/** + * Property reference. It contains the value pointer + * for real, and the value itself for virtual properties. + */ +typedef union +{ + ecma_property_value_t *value_p; /**< property value pointer for real properties */ + ecma_value_t virtual_value; /**< property value for virtual properties */ +} ecma_property_ref_t; + +/** + * Extended property reference, which also contains the + * property descriptor pointer for real properties. + */ +typedef struct +{ + ecma_property_ref_t property_ref; /**< property reference */ + ecma_property_t *property_p; /**< property descriptor pointer for real properties */ +} ecma_extended_property_ref_t; + +/** + * Option flags for ecma_op_object_get_property. + */ +typedef enum +{ + ECMA_PROPERTY_GET_NO_OPTIONS = 0, /**< no option flags for ecma_op_object_get_property */ + ECMA_PROPERTY_GET_VALUE = 1u << 0, /**< fill virtual_value field for virtual properties */ + ECMA_PROPERTY_GET_EXT_REFERENCE = 1u << 1, /**< get extended reference to the property */ +} ecma_property_get_option_bits_t; + +/** + * Internal object types. + */ +typedef enum +{ + ECMA_OBJECT_TYPE_GENERAL = 0, /**< all objects that are not belongs to the sub-types below */ + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL = 1, /**< built-in general object */ + ECMA_OBJECT_TYPE_CLASS = 2, /**< Objects with class property */ + ECMA_OBJECT_TYPE_BUILT_IN_CLASS = 3, /**< built-in object with class property */ + ECMA_OBJECT_TYPE_ARRAY = 4, /**< Array object (15.4) */ + ECMA_OBJECT_TYPE_BUILT_IN_ARRAY = 5, /**< Built-in array object */ + ECMA_OBJECT_TYPE_PROXY = 6, /**< Proxy object ECMAScript v6 26.2 */ + /* Note: these 4 types must be in this order. See IsCallable operation. */ + ECMA_OBJECT_TYPE_FUNCTION = 7, /**< Function objects (15.3), created through 13.2 routine */ + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION = 8, /**< Native built-in function object */ + ECMA_OBJECT_TYPE_BOUND_FUNCTION = 9, /**< Function objects (15.3), created through 15.3.4.5 routine */ + ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION = 10, /**< implicit class constructor function */ + ECMA_OBJECT_TYPE_NATIVE_FUNCTION = 11, /**< Native function object */ + + ECMA_OBJECT_TYPE__MAX /**< maximum value */ +} ecma_object_type_t; + +/** + * Base object types without built-in flag. + * + * Note: + * only these types can be checked with ecma_get_object_base_type. + */ +typedef enum +{ + ECMA_OBJECT_BASE_TYPE_GENERAL = ECMA_OBJECT_TYPE_GENERAL, /**< generic objects */ + ECMA_OBJECT_BASE_TYPE_CLASS = ECMA_OBJECT_TYPE_CLASS, /**< Objects with class property */ + ECMA_OBJECT_BASE_TYPE_ARRAY = ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */ +} ecma_object_base_type_t; + +/** + * Types of objects with class property. + * + * Note: + * when this type is changed, both ecma_class_object_magic_string_id + * and jerry_class_object_type must be updated as well + */ +typedef enum +{ + /* These objects require custom property resolving. */ + ECMA_OBJECT_CLASS_STRING, /**< String Object (ECMAScript v5.1, 4.3.18) */ + ECMA_OBJECT_CLASS_ARGUMENTS, /**< Arguments object (10.6) */ +#if JERRY_BUILTIN_TYPEDARRAY + ECMA_OBJECT_CLASS_TYPEDARRAY, /**< TypedArray which does NOT need extra space to store length and offset */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + ECMA_OBJECT_CLASS_MODULE_NAMESPACE, /**< Module Namespace (ECMAScript v11, 9.4.6) */ +#endif /* JERRY_MODULE_SYSTEM */ + + /* These objects are marked by Garbage Collector. */ + ECMA_OBJECT_CLASS_GENERATOR, /**< Generator object (ECMAScript v6, 25.2) */ + ECMA_OBJECT_CLASS_ASYNC_GENERATOR, /**< Async generator object (ECMAScript v11, 25.3) */ + ECMA_OBJECT_CLASS_ARRAY_ITERATOR, /**< Array iterator object (ECMAScript v6, 22.1.5.1) */ + ECMA_OBJECT_CLASS_SET_ITERATOR, /**< Set iterator object (ECMAScript v6, 23.2.5.1) */ + ECMA_OBJECT_CLASS_MAP_ITERATOR, /**< Map iterator object (ECMAScript v6, 23.1.5.1) */ +#if JERRY_BUILTIN_REGEXP + ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR, /** RegExp string iterator object (ECMAScript v11, 21.2.7) */ +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_MODULE_SYSTEM + ECMA_OBJECT_CLASS_MODULE, /**< Module (ECMAScript v6, 15.2) */ +#endif /* JERRY_MODULE_SYSTEM */ + ECMA_OBJECT_CLASS_PROMISE, /**< Promise (ECMAScript v6, 25.4) */ + ECMA_OBJECT_CLASS_PROMISE_CAPABILITY, /**< Promise capability (ECMAScript v6, 25.4.1.1) */ + ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR, /**< AsyncFromSyncIterator (ECMAScript v11, 25.1.4) */ +#if JERRY_BUILTIN_DATAVIEW + ECMA_OBJECT_CLASS_DATAVIEW, /**< DataView (ECMAScript v6, 24.2) */ +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_CONTAINER + ECMA_OBJECT_CLASS_CONTAINER, /**< Container (Map, WeakMap, Set, WeakSet) */ +#endif /* JERRY_BUILTIN_CONTAINER */ + + /* Normal objects. */ + ECMA_OBJECT_CLASS_BOOLEAN, /**< Boolean Object (ECMAScript v5.1, 4.3.15) */ + ECMA_OBJECT_CLASS_NUMBER, /**< Number Object (ECMAScript v5.1, 4.3.21) */ + ECMA_OBJECT_CLASS_ERROR, /**< Error Object (ECMAScript v5.1, 15.11) */ + ECMA_OBJECT_CLASS_INTERNAL_OBJECT, /**< object for internal properties */ +#if JERRY_PARSER + ECMA_OBJECT_CLASS_SCRIPT, /**< Compiled ECMAScript byte code */ +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_DATE + ECMA_OBJECT_CLASS_DATE, /**< Date Object (ECMAScript v5.1, 15.9) */ +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_REGEXP + ECMA_OBJECT_CLASS_REGEXP, /**< RegExp Object (ECMAScript v5.1, 15.10) */ +#endif /* JERRY_BUILTIN_REGEXP */ + ECMA_OBJECT_CLASS_SYMBOL, /**< Symbol object (ECMAScript v6, 4.3.27) */ + ECMA_OBJECT_CLASS_STRING_ITERATOR, /**< String iterator object (ECMAScript v6, 22.1.5.1) */ +#if JERRY_BUILTIN_TYPEDARRAY + ECMA_OBJECT_CLASS_ARRAY_BUFFER, /**< Array Buffer (ECMAScript v6, 24.1) */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER, /**< Shared Array Buffer (ECMAScript v11 24.2) */ +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +#if JERRY_BUILTIN_BIGINT + ECMA_OBJECT_CLASS_BIGINT, /**< Bigint (ECMAScript v11, 4.3.27) */ +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_WEAKREF + ECMA_OBJECT_CLASS_WEAKREF, /**< WeakRef (Not standardized yet) */ +#endif /* JERRY_BUILTIN_WEAKREF */ + + ECMA_OBJECT_CLASS__MAX /**< maximum value */ +} ecma_object_class_type_t; + +/** + * Types of lexical environments. + */ +typedef enum +{ + /* Types between 0 - 12 are ecma_object_type_t. */ + ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE = 13, /**< declarative lexical environment */ + ECMA_LEXICAL_ENVIRONMENT_CLASS = 14, /**< lexical environment with class */ + ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND = 15, /**< object-bound lexical environment */ + + ECMA_LEXICAL_ENVIRONMENT_TYPE_START = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< first lexical + * environment type */ + ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND /**< maximum value */ +} ecma_lexical_environment_type_t; + +/** + * Types of array iterators. + */ +typedef enum +{ + ECMA_ITERATOR_KEYS, /**< keys iterator */ + ECMA_ITERATOR_VALUES, /**< values iterator */ + ECMA_ITERATOR_ENTRIES, /**< entries iterator */ + ECMA_ITERATOR__COUNT, /**< number of iterator kinds */ +} ecma_iterator_kind_t; + +/** + * Offset for JERRY_CONTEXT (status_flags) top 8 bits. + */ +#define ECMA_LOCAL_PARSE_OPTS_OFFSET ((sizeof (uint32_t) - sizeof (uint8_t)) * JERRY_BITSINBYTE) + +/** + * Set JERRY_CONTEXT (status_flags) top 8 bits to the specified 'opts'. + */ +#define ECMA_SET_LOCAL_PARSE_OPTS(opts) \ + do \ + { \ + JERRY_CONTEXT (status_flags) |= ((uint32_t) opts << ECMA_LOCAL_PARSE_OPTS_OFFSET) | ECMA_STATUS_DIRECT_EVAL; \ + } while (0) + +/** + * Get JERRY_CONTEXT (status_flags) top 8 bits. + */ +#define ECMA_GET_LOCAL_PARSE_OPTS() \ + (JERRY_CONTEXT (status_flags) >> (ECMA_LOCAL_PARSE_OPTS_OFFSET - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER))) + +/** + * Clear JERRY_CONTEXT (status_flags) top 8 bits. + */ +#define ECMA_CLEAR_LOCAL_PARSE_OPTS() \ + do \ + { \ + JERRY_CONTEXT (status_flags) &= ((1 << ECMA_LOCAL_PARSE_OPTS_OFFSET) - 1); \ + } while (0) + +/** + * Ecma object type mask for getting the object type. + */ +#define ECMA_OBJECT_TYPE_MASK 0x00fu + +/** + * Extensible object. + */ +#define ECMA_OBJECT_FLAG_EXTENSIBLE 0x10 + +/** + * Declarative lexical environments created for non-closure code blocks + */ +#define ECMA_OBJECT_FLAG_BLOCK ECMA_OBJECT_FLAG_EXTENSIBLE + +/** + * Lexical environments with class has extra data + */ +#define ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA ECMA_OBJECT_FLAG_EXTENSIBLE + +/** + * Bitshift index for an ecma-object reference count field + */ +#define ECMA_OBJECT_REF_SHIFT 5 + +/** + * Value for increasing or decreasing the object reference counter. + */ +#define ECMA_OBJECT_REF_ONE (1u << ECMA_OBJECT_REF_SHIFT) + +/** + * Type of the descriptor field of an object + */ +typedef uint16_t ecma_object_descriptor_t; + +/** + * Bitmask for an ecma-object reference count field + */ +#define ECMA_OBJECT_REF_MASK ((ecma_object_descriptor_t) (~0u << ECMA_OBJECT_REF_SHIFT)) + +/** + * Represents non-visited white object + */ +#define ECMA_OBJECT_NON_VISITED ECMA_OBJECT_REF_MASK + +/** + * Maximum value of the object reference counter (1022 / 67108862). + */ +#define ECMA_OBJECT_MAX_REF (ECMA_OBJECT_NON_VISITED - ECMA_OBJECT_REF_ONE) + +/** + * Description of ECMA-object or lexical environment + * (depending on is_lexical_environment). + */ +typedef struct +{ + /** type : 4 bit : ecma_object_type_t or ecma_lexical_environment_type_t + depending on ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV + flags : 2 bit : ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV, + ECMA_OBJECT_FLAG_EXTENSIBLE or ECMA_OBJECT_FLAG_BLOCK + refs : 10 / 26 bit (max 1022 / 67108862) */ + ecma_object_descriptor_t type_flags_refs; + + /** next in the object chain maintained by the garbage collector */ + jmem_cpointer_t gc_next_cp; + + /** compressed pointer to property list or bound object */ + union + { + jmem_cpointer_t property_list_cp; /**< compressed pointer to object's + * or declarative lexical environments's property list */ + jmem_cpointer_t bound_object_cp; /**< compressed pointer to lexical environments's the bound object */ + jmem_cpointer_t home_object_cp; /**< compressed pointer to lexical environments's the home object */ + } u1; + + /** object prototype or outer reference */ + union + { + jmem_cpointer_t prototype_cp; /**< compressed pointer to the object's prototype */ + jmem_cpointer_t outer_reference_cp; /**< compressed pointer to the lexical environments's outer reference */ + } u2; +} ecma_object_t; + +/** + * Description of built-in properties of an object. + */ +typedef struct +{ + uint8_t id; /**< built-in id */ + uint8_t routine_id; /**< routine id for built-in functions */ + /** built-in specific field */ + union + { + uint8_t length_and_bitset_size; /**< length and bit set size for generic built-ins */ + uint8_t routine_index; /**< property descriptor index for built-in routines */ + } u; + /** extra built-in info */ + union + { + uint8_t instantiated_bitset[1]; /**< instantiated property bit set for generic built-ins */ + uint8_t routine_flags; /**< flags for built-in routines */ + } u2; + +#if JERRY_BUILTIN_REALMS + ecma_value_t realm_value; /**< realm value */ +#else /* !JERRY_BUILTIN_REALMS */ + uint32_t continue_instantiated_bitset[1]; /**< bit set for instantiated properties */ +#endif /* JERRY_BUILTIN_REALMS */ +} ecma_built_in_props_t; + +/** + * Type of a built-in function handler. + */ +typedef ecma_value_t (*ecma_builtin_handler_t) (ecma_object_t *function_obj_p, + const ecma_value_t args_p[], + const uint32_t args_count); + +#if JERRY_BUILTIN_REALMS + +/** + * Number of bits available in the instantiated bitset without allocation + */ +#define ECMA_BUILTIN_INSTANTIATED_BITSET_MIN_SIZE (8) + +#else /* !JERRY_BUILTIN_REALMS */ + +/** + * Number of bits available in the instantiated bitset without allocation + */ +#define ECMA_BUILTIN_INSTANTIATED_BITSET_MIN_SIZE (8 + 32) + +#endif /* JERRY_BUILTIN_REALMS */ + +/** + * Builtin routine function object status flags + */ +typedef enum +{ + ECMA_BUILTIN_ROUTINE_NO_OPTS = 0, /**< No options are provided */ + ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED = (1u << 0), /**< 'length' property has been initialized */ + ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED = (1u << 1), /**< 'name' property has been initialized */ + ECMA_BUILTIN_ROUTINE_GETTER = (1u << 2), /**< this routine is getter */ + ECMA_BUILTIN_ROUTINE_SETTER = (1u << 3), /**< this routine is setter */ +} ecma_builtin_routine_flags_t; + +/** + * Start position of bit set size in length_and_bitset_size field. + */ +#define ECMA_BUILT_IN_BITSET_SHIFT 5 + +/** + * Description of extended ECMA-object. + * + * The extended object is an object with extra fields. + */ +typedef struct +{ + ecma_object_t object; /**< object header */ + + /** + * Description of extra fields. These extra fields depend on the object type. + */ + union + { + ecma_built_in_props_t built_in; /**< built-in object part */ + + /** + * Description of objects with class. + * + * Note: + * class is a reserved word in c++, so cls is used instead + */ + struct + { + uint8_t type; /**< class type of the object */ + /** + * Description of 8 bit extra fields. These extra fields depend on the type. + */ + union + { + uint8_t arguments_flags; /**< arguments object flags */ + uint8_t error_type; /**< jerry_error_t type of native error objects */ +#if JERRY_BUILTIN_DATE + uint8_t date_flags; /**< flags for date objects */ +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_MODULE_SYSTEM + uint8_t module_state; /**< Module state */ +#endif /* JERRY_MODULE_SYSTEM */ + uint8_t iterator_kind; /**< type of iterator */ + uint8_t regexp_string_iterator_flags; /**< flags for RegExp string iterator */ + uint8_t promise_flags; /**< Promise object flags */ +#if JERRY_BUILTIN_CONTAINER + uint8_t container_flags; /**< container object flags */ +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_TYPEDARRAY + uint8_t array_buffer_flags; /**< ArrayBuffer flags */ + uint8_t typedarray_type; /**< type of typed array */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + } u1; + /** + * Description of 16 bit extra fields. These extra fields depend on the type. + */ + union + { + uint16_t formal_params_number; /**< for arguments: formal parameters number */ +#if JERRY_MODULE_SYSTEM + uint16_t module_flags; /**< Module flags */ +#endif /* JERRY_MODULE_SYSTEM */ + uint16_t iterator_index; /**< for %Iterator%: [[%Iterator%NextIndex]] property */ + uint16_t executable_obj_flags; /**< executable object flags */ +#if JERRY_BUILTIN_CONTAINER + uint16_t container_id; /**< magic string id of a container */ +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_TYPEDARRAY + uint16_t typedarray_flags; /**< typed array object flags */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + } u2; + /** + * Description of 32 bit / value. These extra fields depend on the type. + */ + union + { + ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */ + ecma_value_t target; /**< [[ProxyTarget]] or [[WeakRefTarget]] internal property */ +#if JERRY_BUILTIN_TYPEDARRAY + ecma_value_t arraybuffer; /**< for typedarray: ArrayBuffer reference */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + ecma_value_t head; /**< points to the async generator task queue head item */ + ecma_value_t iterated_value; /**< for %Iterator%: [[IteratedObject]] property */ + ecma_value_t promise; /**< PromiseCapability[[Promise]] internal slot */ + ecma_value_t sync_iterator; /**< IteratorRecord [[Iterator]] internal slot for AsyncFromSyncIterator */ + ecma_value_t spread_value; /**< for spread object: spread element */ + int32_t tza; /**< TimeZone adjustment for date objects */ + uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */ + uint32_t arguments_number; /**< for arguments: arguments number */ +#if JERRY_MODULE_SYSTEM + uint32_t dfs_ancestor_index; /**< module dfs ancestor index (ES2020 15.2.1.16) */ +#endif /* JERRY_MODULE_SYSTEM */ + } u3; + } cls; + + /** + * Description of function objects. + */ + struct + { + jmem_cpointer_tag_t scope_cp; /**< function scope */ + ecma_value_t bytecode_cp; /**< function byte code */ + } function; + + /** + * Description of array objects. + */ + struct + { + uint32_t length; /**< length property value */ + uint32_t length_prop_and_hole_count; /**< length property attributes and number of array holes in + * a fast access mode array multiplied ECMA_FAST_ACCESS_HOLE_ONE */ + } array; + + /** + * Description of bound function object. + */ + struct + { + jmem_cpointer_tag_t target_function; /**< target function */ + ecma_value_t args_len_or_this; /**< length of arguments or this value */ + } bound_function; + + /** + * Description of implicit class constructor function. + */ + struct + { + ecma_value_t script_value; /**< script value */ + uint8_t flags; /**< constructor flags */ + } constructor_function; + } u; +} ecma_extended_object_t; + +/** + * Description of built-in extended ECMA-object. + */ +typedef struct +{ + ecma_extended_object_t extended_object; /**< extended object part */ + ecma_built_in_props_t built_in; /**< built-in object part */ +} ecma_extended_built_in_object_t; + +/** + * Type of lexical environment with class + */ +typedef enum +{ + ECMA_LEX_ENV_CLASS_TYPE_MODULE, /**< module object reference */ + ECMA_LEX_ENV_CLASS_TYPE_CLASS_ENV, /**< class constructor object reference */ +} ecma_lexical_environment_class_type_t; + +/** + * Description of lexical environment with class + */ +typedef struct +{ + ecma_object_t lexical_env; /**< lexical environment header */ + uint32_t type; /**< element of ecma_lexical_environment_class_type_t */ + ecma_object_t *object_p; /**< object reference */ +} ecma_lexical_environment_class_t; + +/** + * Check whether the given lexical class environment is a module + */ +#define ECMA_LEX_ENV_CLASS_IS_MODULE(lex_env_p) \ + (((lex_env_p)->type_flags_refs & ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA) \ + && ((ecma_lexical_environment_class_t *) (lex_env_p))->type == ECMA_LEX_ENV_CLASS_TYPE_MODULE) + +/** + * Description of native functions + */ +typedef struct +{ + ecma_extended_object_t extended_object; /**< extended object part */ +#if JERRY_BUILTIN_REALMS + ecma_value_t realm_value; /**< realm value */ +#endif /* JERRY_BUILTIN_REALMS */ + ecma_native_handler_t native_handler_cb; /**< external function */ +} ecma_native_function_t; + +/** + * Alignment for the fast access mode array length. + * The real length is aligned up for allocating the underlying buffer. + */ +#define ECMA_FAST_ARRAY_ALIGNMENT (8) + +/** + * Align the length of the fast mode array to get the allocated size of the underlying buffer + */ +#define ECMA_FAST_ARRAY_ALIGN_LENGTH(length) \ + (uint32_t) ((((length)) + ECMA_FAST_ARRAY_ALIGNMENT - 1) / ECMA_FAST_ARRAY_ALIGNMENT * ECMA_FAST_ARRAY_ALIGNMENT) + +/** + * Compiled byte code data. + */ +typedef struct +{ + uint16_t size; /**< real size >> JMEM_ALIGNMENT_LOG */ + uint16_t refs; /**< reference counter for the byte code */ + uint16_t status_flags; /**< various status flags: + * CBC_IS_FUNCTION check tells whether the byte code + * is function or regular expression. + * If function, the other flags must be CBC_CODE_FLAGS... + * If regexp, the other flags must be RE_FLAG... */ +} ecma_compiled_code_t; + +/** + * Description of bound function objects. + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object header */ + ecma_value_t target_length; /**< length of target function */ +} ecma_bound_function_t; + +#if JERRY_SNAPSHOT_EXEC + +/** + * Description of static function objects. + */ +typedef struct +{ + ecma_extended_object_t header; /**< header part */ + const ecma_compiled_code_t *bytecode_p; /**< real byte code pointer */ +} ecma_static_function_t; + +#endif /* JERRY_SNAPSHOT_EXEC */ + +/** + * Description of arrow function objects. + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object header */ + ecma_value_t this_binding; /**< value of 'this' binding */ + ecma_value_t new_target; /**< value of new.target */ +} ecma_arrow_function_t; + +#if JERRY_SNAPSHOT_EXEC + +/** + * Description of static arrow function objects. + */ +typedef struct +{ + ecma_arrow_function_t header; + const ecma_compiled_code_t *bytecode_p; +} ecma_static_arrow_function_t; + +#endif /* JERRY_SNAPSHOT_EXEC */ + +#if JERRY_BUILTIN_CONTAINER +/** + * Flags for container objects + */ +typedef enum +{ + ECMA_CONTAINER_FLAGS_EMPTY = (0), /** empty flags */ + ECMA_CONTAINER_FLAGS_WEAK = (1 << 0) /** container object is weak */ +} ecma_container_flags_t; + +/** + * Description of map collection. + */ +typedef struct +{ + ecma_value_t key; /**< key value */ + ecma_value_t value; /**< value of the key */ +} ecma_container_pair_t; + +/** + * Size of a single element (in ecma_value_t unit). + */ +#define ECMA_CONTAINER_VALUE_SIZE 1 + +/** + * Size of a key - value pair (in ecma_value_t unit). + */ +#define ECMA_CONTAINER_PAIR_SIZE 2 + +/** + * Size of the internal buffer. + */ +#define ECMA_CONTAINER_GET_SIZE(container_p) (container_p->buffer_p[0]) + +/** + * Remove the size field of the internal buffer. + */ +#define ECMA_CONTAINER_SET_SIZE(container_p, size) (container_p->buffer_p[0] = (ecma_value_t) (size)) + +/** + * Number of entries of the internal buffer. + */ +#define ECMA_CONTAINER_ENTRY_COUNT(collection_p) (collection_p->item_count - 1) + +/** + * Pointer to the first entry of the internal buffer. + */ +#define ECMA_CONTAINER_START(collection_p) (collection_p->buffer_p + 1) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +/** + * Description of ECMA property descriptor + * + * See also: ECMA-262 v5, 8.10. + * + * Note: + * If a component of descriptor is undefined then corresponding + * field should contain it's default value. + */ +typedef struct +{ + uint16_t flags; /**< any combination of jerry_property_descriptor_flags_t bits */ + ecma_value_t value; /**< [[Value]] */ + ecma_object_t *get_p; /**< [[Get]] */ + ecma_object_t *set_p; /**< [[Set]] */ +} ecma_property_descriptor_t; + +/** + * Bitfield which represents a namedata property options in an ecma_property_descriptor_t + * Attributes: + * - is_get_defined, is_set_defined : false + * - is_configurable, is_writable, is_enumerable : undefined (false) + * - is_throw : undefined (false) + * - is_value_defined : true + * - is_configurable_defined, is_writable_defined, is_enumerable_defined : true + */ +#define ECMA_NAME_DATA_PROPERTY_DESCRIPTOR_BITS \ + ((uint16_t) (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE_DEFINED \ + | JERRY_PROP_IS_WRITABLE_DEFINED)) + +/** + * Bitmask to get a the physical property flags from an ecma_property_descriptor + */ +#define ECMA_PROPERTY_FLAGS_MASK \ + ((uint16_t) (JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_ENUMERABLE | JERRY_PROP_IS_WRITABLE)) + +/** + * Description of an ecma-number + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +typedef double ecma_number_t; +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +typedef float ecma_number_t; +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Convert double to an ecma-number. + */ +#define DOUBLE_TO_ECMA_NUMBER_T(value) ((ecma_number_t) (value)) + +/** + * Value '0' of ecma_number_t + */ +#define ECMA_NUMBER_ZERO ((ecma_number_t) 0.0f) + +/** + * Value '1' of ecma_number_t + */ +#define ECMA_NUMBER_ONE ((ecma_number_t) 1.0f) + +/** + * Value '2' of ecma_number_t + */ +#define ECMA_NUMBER_TWO ((ecma_number_t) 2.0f) + +/** + * Value '0.5' of ecma_number_t + */ +#define ECMA_NUMBER_HALF ((ecma_number_t) 0.5f) + +/** + * Value '-1' of ecma_number_t + */ +#define ECMA_NUMBER_MINUS_ONE ((ecma_number_t) -1.0f) + +/** + * Maximum number of characters in string representation of ecma-number + */ +#define ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER 64 + +/** + * Maximum number of characters in string representation of ecma-uint32 + */ +#define ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 10 + +/** + * String is not a valid array index. + */ +#define ECMA_STRING_NOT_ARRAY_INDEX UINT32_MAX + +/** + * Ecma-collection: a growable list of ecma-values. + */ +typedef struct +{ + uint32_t item_count; /**< number of items in the collection */ + uint32_t capacity; /**< number of items can be stored in the underlying buffer */ + ecma_value_t *buffer_p; /**< underlying data buffer */ +} ecma_collection_t; + +/** + * Initial capacity of an ecma-collection + */ +#define ECMA_COLLECTION_INITIAL_CAPACITY 4 + +/** + * Ecma-collection grow factor when the collection underlying buffer need to be reallocated + */ +#define ECMA_COLLECTION_GROW_FACTOR (ECMA_COLLECTION_INITIAL_CAPACITY * 2) + +/** + * Compute the total allocated size of the collection based on it's capacity + */ +#define ECMA_COLLECTION_ALLOCATED_SIZE(capacity) (uint32_t) (capacity * sizeof (ecma_value_t)) + +/** + * Initial allocated size of an ecma-collection + */ +#define ECMA_COLLECTION_INITIAL_SIZE ECMA_COLLECTION_ALLOCATED_SIZE (ECMA_COLLECTION_INITIAL_CAPACITY) + +/** + * Size shift of a compact collection + */ +#define ECMA_COMPACT_COLLECTION_SIZE_SHIFT 3 + +/** + * Get the size of the compact collection + */ +#define ECMA_COMPACT_COLLECTION_GET_SIZE(compact_collection_p) \ + ((compact_collection_p)[0] >> ECMA_COMPACT_COLLECTION_SIZE_SHIFT) + +/** + * Direct string types (2 bit). + */ +typedef enum +{ + ECMA_DIRECT_STRING_PTR = 0, /**< string is a string pointer, only used by property names */ + ECMA_DIRECT_STRING_MAGIC = 1, /**< string is a magic string */ + ECMA_DIRECT_STRING_UINT = 2, /**< string is an unsigned int */ + ECMA_DIRECT_STRING_SPECIAL = 3, /**< string is special */ +} ecma_direct_string_type_t; + +/** + * Maximum value of the immediate part of a direct magic string. + * Must be compatible with the immediate property name. + */ +#define ECMA_DIRECT_STRING_MAX_IMM 0x0000ffff + +/** + * Shift for direct string value part in ecma_value_t. + */ +#define ECMA_DIRECT_STRING_SHIFT (ECMA_VALUE_SHIFT + 2) + +/** + * Full mask for direct strings. + */ +#define ECMA_DIRECT_STRING_MASK ((uintptr_t) (ECMA_DIRECT_TYPE_MASK | (0x3u << ECMA_VALUE_SHIFT))) + +/** + * Create an ecma direct string. + */ +#define ECMA_CREATE_DIRECT_STRING(type, value) \ + ((uintptr_t) (ECMA_TYPE_DIRECT_STRING | ((type) << ECMA_VALUE_SHIFT) | (value) << ECMA_DIRECT_STRING_SHIFT)) + +/** + * Create an ecma direct string from the given number. + * + * Note: the given number must be less or equal than ECMA_DIRECT_STRING_MAX_IMM + */ +#define ECMA_CREATE_DIRECT_UINT32_STRING(uint32_number) \ + ((ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number)) + +/** + * Checks whether the string is direct. + */ +#define ECMA_IS_DIRECT_STRING(string_p) ((((uintptr_t) (string_p)) & 0x1) != 0) + +/** + * Checks whether the string is direct. + */ +#define ECMA_IS_DIRECT_STRING_WITH_TYPE(string_p, type) \ + ((((uintptr_t) (string_p)) & ECMA_DIRECT_STRING_MASK) == ECMA_CREATE_DIRECT_STRING (type, 0)) + +/** + * Returns the type of a direct string. + */ +#define ECMA_GET_DIRECT_STRING_TYPE(string_p) ((((uintptr_t) (string_p)) >> ECMA_VALUE_SHIFT) & 0x3) + +/** + * Shift applied to type conversions. + */ +#define ECMA_STRING_TYPE_CONVERSION_SHIFT (ECMA_PROPERTY_NAME_TYPE_SHIFT - ECMA_VALUE_SHIFT) + +/** + * Converts direct string type to property name type. + */ +#define ECMA_DIRECT_STRING_TYPE_TO_PROP_NAME_TYPE(string_p) \ + ((((uintptr_t) (string_p)) & (0x3 << ECMA_VALUE_SHIFT)) << ECMA_STRING_TYPE_CONVERSION_SHIFT) + +/** + * Returns the value of a direct string. + */ +#define ECMA_GET_DIRECT_STRING_VALUE(string_p) (((uintptr_t) (string_p)) >> ECMA_DIRECT_STRING_SHIFT) + +/** + * Maximum number of bytes that a long-utf8-string is able to store + */ +#define ECMA_STRING_SIZE_LIMIT UINT32_MAX + +typedef enum +{ + ECMA_STRING_CONTAINER_HEAP_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string + * maximum size is 2^16. */ + ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING, /**< the string is a long string or provided externally + * and only its attributes are stored. */ + ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< string representation of an uint32 number */ + ECMA_STRING_CONTAINER_HEAP_ASCII_STRING, /**< actual data is on the heap as an ASCII string + * maximum size is 2^16. */ + ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */ + ECMA_STRING_CONTAINER_SYMBOL, /**< the ecma-string is a symbol */ + + ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_SYMBOL /**< maximum value */ +} ecma_string_container_t; + +/** + * Mask for getting the container of a string. + */ +#define ECMA_STRING_CONTAINER_MASK 0x7u + +/** + * Value for increasing or decreasing the reference counter. + */ +#define ECMA_STRING_REF_ONE (1u << 4) + +/** + * Maximum value of the reference counter (4294967280). + */ +#define ECMA_STRING_MAX_REF (0xFFFFFFF0) + +/** + * Flag that identifies that the string is static which means it is stored in JERRY_CONTEXT (string_list_cp) + */ +#define ECMA_STATIC_STRING_FLAG (1 << 3) + +/** + * Set an ecma-string as static string + */ +#define ECMA_SET_STRING_AS_STATIC(string_p) (string_p)->refs_and_container |= ECMA_STATIC_STRING_FLAG + +/** + * Checks whether the ecma-string is static string + */ +#define ECMA_STRING_IS_STATIC(string_p) ((string_p)->refs_and_container & ECMA_STATIC_STRING_FLAG) + +/** + * Returns with the container type of a string. + */ +#define ECMA_STRING_GET_CONTAINER(string_desc_p) \ + ((ecma_string_container_t) ((string_desc_p)->refs_and_container & ECMA_STRING_CONTAINER_MASK)) + +/** + * Checks whether the reference counter is 1 of a string. + */ +#define ECMA_STRING_IS_REF_EQUALS_TO_ONE(string_desc_p) (((string_desc_p)->refs_and_container >> 4) == 1) + +/** + * Checks whether the reference counter is 1 of an extended primitive. + */ +#define ECMA_EXTENDED_PRIMITIVE_IS_REF_EQUALS_TO_ONE(extended_primitive_p) \ + (((extended_primitive_p)->refs_and_type >> 3) == 1) + +/** + * ECMA string-value descriptor + */ +typedef struct +{ + /** Reference counter for the string */ + uint32_t refs_and_container; + + /** + * Actual data or identifier of it's place in container (depending on 'container' field) + */ + union + { + lit_string_hash_t hash; /**< hash of the ASCII/UTF8 string */ + uint32_t magic_string_ex_id; /**< identifier of an external magic string (lit_magic_string_ex_id_t) */ + uint32_t uint32_number; /**< uint32-represented number placed locally in the descriptor */ + } u; +} ecma_string_t; + +/** + * ECMA UTF8 string-value descriptor + */ +typedef struct +{ + ecma_string_t header; /**< string header */ + uint16_t size; /**< size of this utf-8 string in bytes */ + uint16_t length; /**< length of this utf-8 string in characters */ +} ecma_short_string_t; + +/** + * Long or external CESU8 string-value descriptor + */ +typedef struct +{ + ecma_string_t header; /**< string header */ + const lit_utf8_byte_t *string_p; /**< string data */ + lit_utf8_size_t size; /**< size of this external string in bytes */ + lit_utf8_size_t length; /**< length of this external string in characters */ +} ecma_long_string_t; + +/** + * External UTF8 string-value descriptor + */ +typedef struct +{ + ecma_long_string_t header; /**< long string header */ + void *user_p; /**< user pointer passed to the callback when the string is freed */ +} ecma_external_string_t; + +/** + * Header size of an ecma ASCII string + */ +#define ECMA_ASCII_STRING_HEADER_SIZE ((lit_utf8_size_t) (sizeof (ecma_string_t) + sizeof (uint8_t))) + +/** + * Get the size of an ecma ASCII string + */ +#define ECMA_ASCII_STRING_GET_SIZE(string_p) \ + ((lit_utf8_size_t) * ((lit_utf8_byte_t *) (string_p) + sizeof (ecma_string_t)) + 1) + +/** + * Set the size of an ecma ASCII string + */ +#define ECMA_ASCII_STRING_SET_SIZE(string_p, size) \ + (*((lit_utf8_byte_t *) (string_p) + sizeof (ecma_string_t)) = (uint8_t) ((size) -1)) + +/** + * Get the start position of the string buffer of an ecma ASCII string + */ +#define ECMA_ASCII_STRING_GET_BUFFER(string_p) ((lit_utf8_byte_t *) (string_p) + ECMA_ASCII_STRING_HEADER_SIZE) + +/** + * Get the start position of the string buffer of an ecma UTF8 string + */ +#define ECMA_SHORT_STRING_GET_BUFFER(string_p) ((lit_utf8_byte_t *) (string_p) + sizeof (ecma_short_string_t)) + +/** + * Get the start position of the string buffer of an ecma long CESU8 string + */ +#define ECMA_LONG_STRING_BUFFER_START(string_p) ((lit_utf8_byte_t *) (string_p) + sizeof (ecma_long_string_t)) + +/** + * ECMA extended string-value descriptor + */ +typedef struct +{ + ecma_string_t header; /**< string header */ + + union + { + ecma_value_t symbol_descriptor; /**< symbol descriptor string-value */ + ecma_value_t value; /**< original key value corresponds to the map key string */ + } u; +} ecma_extended_string_t; + +/** + * Required number of ecma values in a compact collection to represent PrivateElement + */ +#define ECMA_PRIVATE_ELEMENT_LIST_SIZE 3 + +/** + * String builder header + */ +typedef struct +{ + lit_utf8_size_t current_size; /**< size of the data in the buffer */ +} ecma_stringbuilder_header_t; + +/** + * Get pointer to the beginning of the stored string in the string builder + */ +#define ECMA_STRINGBUILDER_STRING_PTR(header_p) \ + ((lit_utf8_byte_t *) (((lit_utf8_byte_t *) header_p) + ECMA_ASCII_STRING_HEADER_SIZE)) + +/** + * Get the size of the stored string in the string builder + */ +#define ECMA_STRINGBUILDER_STRING_SIZE(header_p) \ + ((lit_utf8_size_t) (header_p->current_size - ECMA_ASCII_STRING_HEADER_SIZE)) + +/** + * String builder handle + */ +typedef struct +{ + ecma_stringbuilder_header_t *header_p; /**< pointer to header */ +} ecma_stringbuilder_t; + +#ifndef JERRY_BUILTIN_BIGINT +/** + * BigInt type. + */ +#define ECMA_EXTENDED_PRIMITIVE_BIGINT 0 +#endif /* !defined (JERRY_BUILTIN_BIGINT) */ + +/** + * Flags for exception values. + */ +typedef enum +{ + ECMA_ERROR_API_FLAG_NONE = 0, + ECMA_ERROR_API_FLAG_ABORT = (1u << 0), /**< abort flag */ + ECMA_ERROR_API_FLAG_THROW_CAPTURED = (1u << 1), /**< throw captured flag */ +} ecma_error_api_flags_t; + +/** + * Representation of a thrown value on API level. + */ +typedef struct +{ + uint32_t refs_and_type; /**< reference counter and type */ + union + { + ecma_value_t value; /**< referenced value */ + uint32_t bigint_sign_and_size; /**< BigInt properties */ + } u; +} ecma_extended_primitive_t; + +/** + * Value for increasing or decreasing the reference counter. + */ +#define ECMA_EXTENDED_PRIMITIVE_REF_ONE (1u << 3) + +/** + * Maximum value of the reference counter. + */ +#define ECMA_EXTENDED_PRIMITIVE_MAX_REF (UINT32_MAX - (ECMA_EXTENDED_PRIMITIVE_REF_ONE - 1)) + +#if JERRY_PROPERTY_HASHMAP + +/** + * The lowest state of the ecma_prop_hashmap_alloc_state counter. + * If ecma_prop_hashmap_alloc_state other than this value, it is + * disabled. + */ +#define ECMA_PROP_HASHMAP_ALLOC_ON 0 + +/** + * The highest state of the ecma_prop_hashmap_alloc_state counter. + */ +#define ECMA_PROP_HASHMAP_ALLOC_MAX 4 + +#endif /* JERRY_PROPERTY_HASHMAP */ + +/** + * Number of values in a literal storage item + */ +#define ECMA_LIT_STORAGE_VALUE_COUNT 3 + +/** + * Literal storage item + */ +typedef struct +{ + jmem_cpointer_t next_cp; /**< cpointer ot next item */ + jmem_cpointer_t values[ECMA_LIT_STORAGE_VALUE_COUNT]; /**< list of values */ +} ecma_lit_storage_item_t; + +#if JERRY_LCACHE +/** + * Container of an LCache entry identifier + */ +typedef uint32_t ecma_lcache_hash_entry_id_t; + +/** + * Entry of LCache hash table + */ +typedef struct +{ + /** Pointer to a property of the object */ + ecma_property_t *prop_p; + + /** Entry identifier in LCache */ + ecma_lcache_hash_entry_id_t id; +} ecma_lcache_hash_entry_t; + +/** + * Number of rows in LCache's hash table + */ +#define ECMA_LCACHE_HASH_ROWS_COUNT 128 + +/** + * Number of entries in a row of LCache's hash table + */ +#define ECMA_LCACHE_HASH_ROW_LENGTH 2 + +#endif /* JERRY_LCACHE */ + +#if JERRY_BUILTIN_TYPEDARRAY + +/** + * Function callback descriptor of a %TypedArray% object getter + */ +typedef ecma_value_t (*ecma_typedarray_getter_fn_t) (lit_utf8_byte_t *src); + +/** + * Function callback descriptor of a %TypedArray% object setter + */ +typedef ecma_value_t (*ecma_typedarray_setter_fn_t) (lit_utf8_byte_t *src, ecma_value_t value); + +/** + * Builtin id for the different types of TypedArray's + */ +typedef enum +{ + ECMA_INT8_ARRAY, /**< Int8Array */ + ECMA_UINT8_ARRAY, /**< Uint8Array */ + ECMA_UINT8_CLAMPED_ARRAY, /**< Uint8ClampedArray */ + ECMA_INT16_ARRAY, /**< Int16Array */ + ECMA_UINT16_ARRAY, /**< Uint16Array */ + ECMA_INT32_ARRAY, /**< Int32Array */ + ECMA_UINT32_ARRAY, /**< Uint32Array */ + ECMA_FLOAT32_ARRAY, /**< Float32Array */ + ECMA_FLOAT64_ARRAY, /**< Float64Array */ + /* ECMA_TYPEDARRAY_IS_BIGINT_TYPE macro should be updated when new types are added */ + ECMA_BIGINT64_ARRAY, /**< BigInt64Array */ + ECMA_BIGUINT64_ARRAY, /**< BigUInt64Array */ +} ecma_typedarray_type_t; + +/** + * TypedArray flags. + */ +typedef enum +{ + ECMA_TYPEDARRAY_IS_EXTENDED = (1u << 0), /* an ecma_extended_typedarray_object_t is allocated for the TypedArray */ +} ecma_typedarray_flag_t; + +/** + * Array buffer flags. + */ +typedef enum +{ + ECMA_ARRAYBUFFER_HAS_POINTER = (1u << 0), /* ArrayBuffer has a buffer pointer. */ + ECMA_ARRAYBUFFER_ALLOCATED = (1u << 1), /* ArrayBuffer memory is allocated */ + ECMA_ARRAYBUFFER_DETACHED = (1u << 2), /* ArrayBuffer has been detached */ +} ecma_arraybuffer_flag_t; + +/** + * Structure for array buffers with a backing store pointer. + */ +typedef struct +{ + ecma_extended_object_t extended_object; /**< extended object part */ + void *buffer_p; /**< pointer to the backing store of the array buffer object */ + void *arraybuffer_user_p; /**< user pointer passed to the free callback */ +} ecma_arraybuffer_pointer_t; + +/** + * Some internal properties of TypedArray object. + * It is only used when the offset is not 0, and + * the array-length is not buffer-length / element_size. + */ +typedef struct +{ + ecma_extended_object_t extended_object; /**< extended object part */ + uint32_t byte_offset; /**< the byteoffset of the above arraybuffer */ + uint32_t array_length; /**< the array length */ +} ecma_extended_typedarray_object_t; + +/** + * General structure for query %TypedArray% object's properties. + **/ +typedef struct +{ + ecma_object_t *array_buffer_p; /**< pointer to the typedArray's [[ViewedArrayBuffer]] internal slot */ + ecma_typedarray_type_t id; /**< [[TypedArrayName]] internal slot */ + uint32_t length; /**< [[ByteLength]] internal slot */ + uint32_t offset; /**< [[ByteOffset]] internal slot. */ + uint8_t shift; /**< the element size shift in the typedArray */ + uint8_t element_size; /**< element size based on [[TypedArrayName]] in Table 49 */ +} ecma_typedarray_info_t; + +#if JERRY_BUILTIN_BIGINT +/** + * Checks whether a given typedarray is BigInt type or not. + **/ +#define ECMA_TYPEDARRAY_IS_BIGINT_TYPE(id) ((id) >= ECMA_BIGINT64_ARRAY) + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +/** + * Executable (e.g. generator, async) object flags. + */ +typedef enum +{ + ECMA_EXECUTABLE_OBJECT_COMPLETED = (1u << 0), /**< executable object is completed and cannot be resumed */ + ECMA_EXECUTABLE_OBJECT_RUNNING = (1u << 1), /**< executable object is currently running */ + /* Generator specific flags. */ + ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD = (1u << 2), /**< the executable object performs + * an await or a yield* operation */ + ECMA_ASYNC_GENERATOR_CALLED = (1u << 3), /**< the async generator was executed before */ + /* This must be the last generator specific flag. */ + ECMA_AWAIT_STATE_SHIFT = 4, /**< shift for await states */ +} ecma_executable_object_flags_t; + +/** + * Async function states after an await is completed. + */ +typedef enum +{ + ECMA_AWAIT_YIELD_NEXT, /**< wait for an iterator result object */ + ECMA_AWAIT_YIELD_NEXT_RETURN, /**< wait for an iterator result object after a return operation */ + ECMA_AWAIT_YIELD_RETURN, /**< wait for the argument passed to return operation */ + ECMA_AWAIT_YIELD_NEXT_VALUE, /**< wait for the value property of an iterator result object */ + ECMA_AWAIT_YIELD_OPERATION, /**< wait for the generator operation (next/throw/return) */ + ECMA_AWAIT_YIELD_CLOSE, /**< wait for the result of iterator close operation */ + /* After adding new ECMA_AWAIT_YIELD items, the ECMA_AWAIT_YIELD_END should be updated. */ + ECMA_AWAIT_FOR_CLOSE, /**< wait for a close iterator result object of for-await-of statement */ + ECMA_AWAIT_FOR_NEXT, /**< wait for an iterator result object of for-await-of statement */ +} ecma_await_states_t; + +/** + * Checks whether the executable object is waiting for resuming. + */ +#define ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED(executable_object_p) \ + (!((executable_object_p)->extended_object.u.cls.u2.executable_obj_flags \ + & (ECMA_EXECUTABLE_OBJECT_COMPLETED | ECMA_EXECUTABLE_OBJECT_RUNNING))) + +/** + * Last item of yield* related await states. + */ +#define ECMA_AWAIT_YIELD_END ECMA_AWAIT_YIELD_CLOSE + +/** + * Helper macro for ECMA_EXECUTABLE_OBJECT_RESUME_EXEC. + */ +#define ECMA_EXECUTABLE_OBJECT_RESUME_EXEC_MASK ((uint16_t) ~ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD) + +/** + * Resume execution of the byte code. + */ +#define ECMA_EXECUTABLE_OBJECT_RESUME_EXEC(executable_object_p) \ + ((executable_object_p)->extended_object.u.cls.u2.executable_obj_flags &= ECMA_EXECUTABLE_OBJECT_RESUME_EXEC_MASK) + +/** + * Enqueued task of an AsyncGenerator. + * + * An execution of a task has three steps: + * 1) Perform a next/throw/return operation + * 2) Resume the execution of the AsyncGenerator + * 3) Fulfill or reject a promise if the AsyncGenerator yielded a value + * (these Promises are created by the AsyncGenerator itself) + */ +typedef struct +{ + ecma_value_t next; /**< points to the next task which will be performed after this task is completed */ + ecma_value_t promise; /**< promise which will be fulfilled or rejected after this task is completed */ + ecma_value_t operation_value; /**< value argument of the operation */ + uint8_t operation_type; /**< type of operation (see ecma_async_generator_operation_type_t) */ +} ecma_async_generator_task_t; + +/** + * Definition of PromiseCapability Records + */ +typedef struct +{ + ecma_extended_object_t header; /**< object header, and [[Promise]] internal slot */ + ecma_value_t resolve; /**< [[Resolve]] internal slot */ + ecma_value_t reject; /**< [[Reject]] internal slot */ +} ecma_promise_capability_t; + +/** + * Definition of GetCapabilitiesExecutor Functions + */ +typedef struct +{ + ecma_extended_object_t header; /**< object header */ + ecma_value_t capability; /**< [[Capability]] internal slot */ +} ecma_promise_capability_executor_t; + +/** + * Definition of Promise.all Resolve Element Functions + */ +typedef struct +{ + ecma_extended_object_t header; /**< object header */ + ecma_value_t remaining_elements; /**< [[Remaining elements]] internal slot */ + ecma_value_t capability; /**< [[Capabilities]] internal slot */ + ecma_value_t values; /**< [[Values]] or [[Errors]] internal slot */ + uint32_t index; /**< [[Index]] and [[AlreadyCalled]] internal slot + * 0 - if the element has been resolved + * real index + 1 in the [[Values]] list - otherwise */ +} ecma_promise_all_executor_t; + +/** + * Promise prototype methods helper. + */ +typedef enum +{ + ECMA_PROMISE_ALL_RESOLVE, /**< promise.all resolve */ + ECMA_PROMISE_ALLSETTLED_RESOLVE, /**< promise.allSettled resolve */ + ECMA_PROMISE_ALLSETTLED_REJECT, /**< promise.allSettled reject */ + ECMA_PROMISE_ANY_REJECT, /**< promise.any reject */ +} ecma_promise_executor_type_t; + +#if JERRY_BUILTIN_DATAVIEW +/** + * Description of DataView objects. + */ +typedef struct +{ + ecma_extended_object_t header; /**< header part */ + ecma_object_t *buffer_p; /**< [[ViewedArrayBuffer]] internal slot */ + uint32_t byte_offset; /**< [[ByteOffset]] internal slot */ +} ecma_dataview_object_t; +#endif /* JERRY_BUILTIN_DATAVIEW */ + +typedef enum +{ + ECMA_SYMBOL_FLAG_NONE = 0, /**< no options */ + ECMA_SYMBOL_FLAG_GLOBAL = (1 << 0), /**< symbol is a well known symbol, See also: 6.1.5.1 */ + ECMA_SYMBOL_FLAG_PRIVATE_KEY = (1 << 1), /**< symbol is a private field */ + ECMA_SYMBOL_FLAG_PRIVATE_INSTANCE_METHOD = (1 << 2), /**< symbol is a private method or accessor */ +} ecma_symbol_flags_t; + +/** + * Bitshift index for the symbol hash property + */ +#define ECMA_SYMBOL_FLAGS_SHIFT 3 + +/** + * Bitmask for symbol hash flags + */ +#define ECMA_SYMBOL_FLAGS_MASK ((1 << ECMA_SYMBOL_FLAGS_SHIFT) - 1) + +#if (JERRY_STACK_LIMIT != 0) +/** + * Check the current stack usage. If the limit is reached a RangeError is raised. + * The macro argument specifies the return value which is usually ECMA_VALUE_ERROR or NULL. + */ +#define ECMA_CHECK_STACK_USAGE_RETURN(RETURN_VALUE) \ + do \ + { \ + if (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT) \ + { \ + ecma_raise_maximum_callstack_error (); \ + return RETURN_VALUE; \ + } \ + } while (0) + +/** + * Specialized version of ECMA_CHECK_STACK_USAGE_RETURN which returns ECMA_VALUE_ERROR. + * This version should be used in most cases. + */ +#define ECMA_CHECK_STACK_USAGE() ECMA_CHECK_STACK_USAGE_RETURN (ECMA_VALUE_ERROR) +#else /* JERRY_STACK_LIMIT == 0) */ +/** + * If the stack limit is unlimited, this check is an empty macro. + */ +#define ECMA_CHECK_STACK_USAGE_RETURN(RETURN_VALUE) + +/** + * If the stack limit is unlimited, this check is an empty macro. + */ +#define ECMA_CHECK_STACK_USAGE() +#endif /* (JERRY_STACK_LIMIT != 0) */ + +/** + * Invalid object pointer which represents abrupt completion + */ +#define ECMA_OBJECT_POINTER_ERROR ((ecma_object_t *) 0x01) + +/** + * Invalid property pointer which represents abrupt completion + */ +#define ECMA_PROPERTY_POINTER_ERROR ((ecma_property_t *) 0x01) + +#if JERRY_BUILTIN_PROXY + +/** + * Proxy object flags. + */ +typedef enum +{ + ECMA_PROXY_SKIP_RESULT_VALIDATION = (1u << 0), /**< skip result validation for [[GetPrototypeOf]], + * [[SetPrototypeOf]], [[IsExtensible]], + * [[PreventExtensions]], [[GetOwnProperty]], + * [[DefineOwnProperty]], [[HasProperty]], [[Get]], + * [[Set]], [[Delete]] and [[OwnPropertyKeys]] */ + ECMA_PROXY_IS_CALLABLE = (1u << 1), /**< proxy is callable */ + ECMA_PROXY_IS_CONSTRUCTABLE = (1u << 2), /**< proxy is constructable */ +} ecma_proxy_flag_types_t; + +/** + * Description of Proxy objects. + * + * A Proxy object's property list is used to store extra information: + * * The "header.u2.prototype_cp" 1st tag bit stores the IsCallable information. + * * The "header.u2.prototype_cp" 2nd tag bit stores the IsConstructor information. + */ +typedef struct +{ + ecma_object_t header; /**< header part */ + ecma_value_t target; /**< [[ProxyTarget]] internal slot */ + ecma_value_t handler; /**< [[ProxyHandler]] internal slot */ +} ecma_proxy_object_t; + +/** + * Description of Proxy objects. + */ +typedef struct +{ + ecma_extended_object_t header; /**< header part */ + ecma_value_t proxy; /**< [[RevocableProxy]] internal slot */ +} ecma_revocable_proxy_object_t; +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * Type to represent the maximum property index + * + * For ES6+ the maximum valid property index is 2**53 - 1 + */ +typedef uint64_t ecma_length_t; + +#if JERRY_BUILTIN_BIGINT + +/** + * BigUInt data is a sequence of uint32_t numbers. + */ +typedef uint32_t ecma_bigint_digit_t; + +/** + * Special BigInt value representing zero. + */ +#define ECMA_BIGINT_ZERO ((ecma_value_t) ECMA_TYPE_BIGINT) + +/** + * Special BigInt value representing zero when the result is pointer. + */ +#define ECMA_BIGINT_POINTER_TO_ZERO ((ecma_extended_primitive_t *) 0x1) + +/** + * Return the size of a BigInt value in ecma_bigint_data_t units. + */ +#define ECMA_BIGINT_GET_SIZE(value_p) \ + ((value_p)->u.bigint_sign_and_size & ~(uint32_t) (sizeof (ecma_bigint_digit_t) - 1)) + +/** + * Size of memory needs to be allocated for the digits of a BigInt. + * The value is rounded up for two digits. + */ +#define ECMA_BIGINT_GET_BYTE_SIZE(size) \ + (size_t) (((size) + sizeof (ecma_bigint_digit_t)) & ~(2 * sizeof (ecma_bigint_digit_t) - 1)) + +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Struct for counting the different types properties in objects + */ +typedef struct +{ + uint32_t array_index_named_props; /**< number of array index named properties */ + uint32_t string_named_props; /**< number of string named properties */ + uint32_t symbol_named_props; /**< number of symbol named properties */ +} ecma_property_counter_t; + +/** + * Arguments object related status flags + */ +typedef enum +{ + ECMA_ARGUMENTS_OBJECT_NO_FLAGS = 0, /* unmapped arguments object */ + ECMA_ARGUMENTS_OBJECT_MAPPED = (1 << 0), /* mapped arguments object */ + ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE = (1 << 1), /* static mapped arguments object */ + ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED = (1 << 2), /* 'callee' property has been lazy initialized */ + ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED = (1 << 3), /* 'length' property has been lazy initialized */ + ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED = (1 << 4), /* 'Symbol.iterator' property has been lazy initialized */ +} ecma_arguments_object_flags_t; + +/** + * Definition of unmapped arguments object + */ +typedef struct +{ + ecma_extended_object_t header; /**< object header */ + ecma_value_t callee; /**< 'callee' property */ +} ecma_unmapped_arguments_t; + +/** + * Definition of mapped arguments object + */ +typedef struct +{ + ecma_unmapped_arguments_t unmapped; /**< unmapped arguments object header */ + ecma_value_t lex_env; /**< environment reference */ + union + { + ecma_value_t byte_code; /**< callee's compiled code */ +#if JERRY_SNAPSHOT_EXEC + ecma_compiled_code_t *byte_code_p; /**< real byte code pointer */ +#endif /* JERRY_SNAPSHOT_EXEC */ + } u; +} ecma_mapped_arguments_t; + +/** + * Date object descriptor flags + */ +typedef enum +{ + ECMA_DATE_TZA_NONE = 0, /**< no time-zone adjustment is set */ + ECMA_DATE_TZA_SET = (1 << 0), /**< time-zone adjustment is set */ +} ecma_date_object_flags_t; + +/** + * Definition of date object + */ +typedef struct +{ + ecma_extended_object_t header; /**< object header */ + ecma_number_t date_value; /**< [[DateValue]] internal property */ +} ecma_date_object_t; + +/** + * Implicit class constructor flags + */ +typedef enum +{ + ECMA_CONSTRUCTOR_FUNCTION_HAS_HERITAGE = (1 << 0), /**< heritage object is present */ +} ecma_constructor_function_flags_t; + +/** + * Description of AsyncFromSyncIterator objects. + */ +typedef struct +{ + ecma_extended_object_t header; /**< header part */ + ecma_value_t sync_next_method; /**< IteratorRecord [[NextMethod]] internal slot */ +} ecma_async_from_sync_iterator_object_t; + +/** + * Private method kind + */ +typedef enum +{ + ECMA_PRIVATE_FIELD = 0, /**< private field */ + ECMA_PRIVATE_METHOD, /**< private method */ + ECMA_PRIVATE_GETTER, /**< private setter */ + ECMA_PRIVATE_SETTER, /**< private getter */ +} ecma_private_property_kind_t; + +/** + * Private static property flag + */ +#define ECMA_PRIVATE_PROPERTY_STATIC_FLAG (1 << 2) + +/* + * Get private property kind from a descriptor + */ +#define ECMA_PRIVATE_PROPERTY_KIND(prop) ((ecma_private_property_kind_t) ((int) (prop) & (ECMA_PRIVATE_PROPERTY_STATIC_FLAG - 1))) + +/** + * @} + * @} + */ + +#endif /* !ECMA_GLOBALS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-collection.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-collection.cpp new file mode 100644 index 0000000..fb0716c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-collection.cpp @@ -0,0 +1,446 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-conversion.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +/** + * Allocate a collection of ecma values. + * + * @return pointer to the collection + */ +ecma_collection_t * +ecma_new_collection (void) +{ + ecma_collection_t *collection_p; + collection_p = (ecma_collection_t *) jmem_heap_alloc_block (sizeof (ecma_collection_t)); + + collection_p->item_count = 0; + collection_p->capacity = ECMA_COLLECTION_INITIAL_CAPACITY; + const uint32_t size = ECMA_COLLECTION_ALLOCATED_SIZE (ECMA_COLLECTION_INITIAL_CAPACITY); + collection_p->buffer_p = (ecma_value_t *) jmem_heap_alloc_block (size); + + return collection_p; +} /* ecma_new_collection */ + +/** + * Deallocate a collection of ecma values without freeing it's values + * + * @return void + */ +void +ecma_collection_destroy (ecma_collection_t *collection_p) /**< value collection */ +{ + JERRY_ASSERT (collection_p != NULL); + + jmem_heap_free_block (collection_p->buffer_p, ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity)); + jmem_heap_free_block (collection_p, sizeof (ecma_collection_t)); +} /* ecma_collection_destroy */ + +/** + * Free the object collection elements and deallocate the collection + */ +void +ecma_collection_free_objects (ecma_collection_t *collection_p) /**< value collection */ +{ + JERRY_ASSERT (collection_p != NULL); + + ecma_value_t *buffer_p = collection_p->buffer_p; + + for (uint32_t i = 0; i < collection_p->item_count; i++) + { + if (ecma_is_value_object (buffer_p[i])) + { + ecma_deref_object (ecma_get_object_from_value (buffer_p[i])); + } + } + + ecma_collection_destroy (collection_p); +} /* ecma_collection_free_objects */ + +/** + * Free the template literal objects and deallocate the collection + */ +void +ecma_collection_free_template_literal (ecma_collection_t *collection_p) /**< value collection */ +{ + for (uint32_t i = 0; i < collection_p->item_count; i++) + { + ecma_object_t *object_p = ecma_get_object_from_value (collection_p->buffer_p[i]); + + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_ARRAY); + + ecma_extended_object_t *array_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (array_object_p->u.array.length_prop_and_hole_count & ECMA_ARRAY_TEMPLATE_LITERAL); + array_object_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_ARRAY_TEMPLATE_LITERAL; + + ecma_property_value_t *property_value_p; + + property_value_p = ecma_get_named_data_property (object_p, ecma_get_magic_string (LIT_MAGIC_STRING_RAW)); + ecma_object_t *raw_object_p = ecma_get_object_from_value (property_value_p->value); + + JERRY_ASSERT (ecma_get_object_type (raw_object_p) == ECMA_OBJECT_TYPE_ARRAY); + + array_object_p = (ecma_extended_object_t *) raw_object_p; + + JERRY_ASSERT (array_object_p->u.array.length_prop_and_hole_count & ECMA_ARRAY_TEMPLATE_LITERAL); + array_object_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_ARRAY_TEMPLATE_LITERAL; + + ecma_deref_object (raw_object_p); + ecma_deref_object (object_p); + } + + ecma_collection_destroy (collection_p); +} /* ecma_collection_free_template_literal */ + +/** + * Free the non-object collection elements and deallocate the collection + */ +void +ecma_collection_free_if_not_object (ecma_collection_t *collection_p) /**< value collection */ +{ + JERRY_ASSERT (collection_p != NULL); + + ecma_value_t *buffer_p = collection_p->buffer_p; + + for (uint32_t i = 0; i < collection_p->item_count; i++) + { + ecma_free_value_if_not_object (buffer_p[i]); + } + + ecma_collection_destroy (collection_p); +} /* ecma_collection_free_if_not_object */ + +/** + * Free the collection elements and deallocate the collection + */ +void +ecma_collection_free (ecma_collection_t *collection_p) /**< value collection */ +{ + JERRY_ASSERT (collection_p != NULL); + + ecma_value_t *buffer_p = collection_p->buffer_p; + + for (uint32_t i = 0; i < collection_p->item_count; i++) + { + ecma_free_value (buffer_p[i]); + } + + ecma_collection_destroy (collection_p); +} /* ecma_collection_free */ + +/** + * Append new value to ecma values collection + * + * Note: The reference count of the values are not increased + */ +void +ecma_collection_push_back (ecma_collection_t *collection_p, /**< value collection */ + ecma_value_t value) /**< ecma value to append */ +{ + JERRY_ASSERT (collection_p != NULL); + + ecma_value_t *buffer_p = collection_p->buffer_p; + + if (JERRY_LIKELY (collection_p->item_count < collection_p->capacity)) + { + buffer_p[collection_p->item_count++] = value; + return; + } + + const uint32_t new_capacity = collection_p->capacity + ECMA_COLLECTION_GROW_FACTOR; + const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity); + const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity); + + buffer_p = (ecma_value_t *) jmem_heap_realloc_block (buffer_p, old_size, new_size); + buffer_p[collection_p->item_count++] = value; + collection_p->capacity = new_capacity; + + collection_p->buffer_p = buffer_p; +} /* ecma_collection_push_back */ + +/** + * Reserve space for the given amount of ecma_values in the collection + */ +void +ecma_collection_reserve (ecma_collection_t *collection_p, /**< value collection */ + uint32_t count) /**< number of ecma values to reserve */ +{ + JERRY_ASSERT (collection_p != NULL); + JERRY_ASSERT (UINT32_MAX - count > collection_p->capacity); + + const uint32_t new_capacity = collection_p->capacity + count; + const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity); + const uint32_t new_size = ECMA_COLLECTION_ALLOCATED_SIZE (new_capacity); + + ecma_value_t *buffer_p = collection_p->buffer_p; + buffer_p = (ecma_value_t *) jmem_heap_realloc_block (buffer_p, old_size, new_size); + + collection_p->capacity = new_capacity; + collection_p->buffer_p = buffer_p; +} /* ecma_collection_reserve */ + +/** + * Append a list of values to the end of the collection + */ +void +ecma_collection_append (ecma_collection_t *collection_p, /**< value collection */ + const ecma_value_t *buffer_p, /**< values to append */ + uint32_t count) /**< number of ecma values to append */ +{ + JERRY_ASSERT (collection_p != NULL); + JERRY_ASSERT (collection_p->capacity >= collection_p->item_count); + + uint32_t free_count = collection_p->capacity - collection_p->item_count; + + if (free_count < count) + { + ecma_collection_reserve (collection_p, count - free_count); + } + + memcpy (collection_p->buffer_p + collection_p->item_count, buffer_p, count * sizeof (ecma_value_t)); + collection_p->item_count += count; +} /* ecma_collection_append */ + +/** + * Helper function to check if a given collection have duplicated properties or not + * + * @return true - if there are duplicated properties in the collection + * false - otherwise + */ +bool +ecma_collection_check_duplicated_entries (ecma_collection_t *collection_p) /**< prop name collection */ +{ + if (collection_p->item_count == 0) + { + return false; + } + + ecma_value_t *buffer_p = collection_p->buffer_p; + + for (uint32_t i = 0; i < collection_p->item_count - 1; i++) + { + ecma_string_t *current_name_p = ecma_get_prop_name_from_value (buffer_p[i]); + + for (uint32_t j = i + 1; j < collection_p->item_count; j++) + { + if (ecma_compare_ecma_strings (current_name_p, ecma_get_prop_name_from_value (buffer_p[j]))) + { + return true; + } + } + } + + return false; +} /* ecma_collection_check_duplicated_entries */ + +/** + * Check the string value existence in the collection. + * + * Used by: + * - ecma_builtin_json_stringify step 4.b.ii.5 + * - ecma_op_object_enumerate + * + * @return true, if the string is already in the collection. + */ +bool +ecma_collection_has_string_value (ecma_collection_t *collection_p, /**< collection */ + ecma_string_t *string_p) /**< string */ +{ + ecma_value_t *buffer_p = collection_p->buffer_p; + + for (uint32_t i = 0; i < collection_p->item_count; i++) + { + ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]); + + if (ecma_compare_ecma_strings (current_p, string_p)) + { + return true; + } + } + + return false; +} /* ecma_collection_has_string_value */ + +/** + * Initial capacity of an ecma-collection + */ +#define ECMA_COMPACT_COLLECTION_GROWTH 8 + +/** + * Set the size of the compact collection + */ +#define ECMA_COMPACT_COLLECTION_SET_SIZE(compact_collection_p, item_count, unused_items) \ + ((compact_collection_p)[0] = (((item_count) << ECMA_COMPACT_COLLECTION_SIZE_SHIFT) | (unused_items))) + +/** + * Set the size of the compact collection + */ +#define ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT(compact_collection_p) \ + ((compact_collection_p)[0] & ((1 << ECMA_COMPACT_COLLECTION_SIZE_SHIFT) - 1)) + +/** + * Allocate a compact collection of ecma values + * + * @return pointer to the compact collection + */ +ecma_value_t * +ecma_new_compact_collection (void) +{ + size_t size = (ECMA_COMPACT_COLLECTION_GROWTH / 2) * sizeof (ecma_value_t); + ecma_value_t *compact_collection_p = (ecma_value_t *) jmem_heap_alloc_block (size); + + ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p, + ECMA_COMPACT_COLLECTION_GROWTH / 2, + (ECMA_COMPACT_COLLECTION_GROWTH / 2) - 1); + return compact_collection_p; +} /* ecma_new_compact_collection */ + +/** + * Append a value to the compact collection + * + * @return updated pointer to the compact collection + */ +ecma_value_t * +ecma_compact_collection_push_back (ecma_value_t *compact_collection_p, /**< compact collection */ + ecma_value_t value) /**< ecma value to append */ +{ + ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p); + ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p); + + if (unused_items > 0) + { + compact_collection_p[size - unused_items] = value; + (*compact_collection_p)--; + return compact_collection_p; + } + + if (size == ECMA_COMPACT_COLLECTION_GROWTH / 2) + { + size_t old_size = (ECMA_COMPACT_COLLECTION_GROWTH / 2) * sizeof (ecma_value_t); + size_t new_size = ECMA_COMPACT_COLLECTION_GROWTH * sizeof (ecma_value_t); + compact_collection_p = (ecma_value_t *) jmem_heap_realloc_block (compact_collection_p, old_size, new_size); + + compact_collection_p[ECMA_COMPACT_COLLECTION_GROWTH / 2] = value; + + ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p, + ECMA_COMPACT_COLLECTION_GROWTH, + (ECMA_COMPACT_COLLECTION_GROWTH / 2) - 1); + return compact_collection_p; + } + + size_t old_size = size * sizeof (ecma_value_t); + size_t new_size = old_size + (ECMA_COMPACT_COLLECTION_GROWTH * sizeof (ecma_value_t)); + + compact_collection_p = (ecma_value_t *) jmem_heap_realloc_block (compact_collection_p, old_size, new_size); + compact_collection_p[size] = value; + + ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p, + size + ECMA_COMPACT_COLLECTION_GROWTH, + ECMA_COMPACT_COLLECTION_GROWTH - 1); + return compact_collection_p; +} /* ecma_compact_collection_push_back */ + +/** + * Discard the unused elements of a compact collection + * + * Note: + * further items should not be added after this call + * + * @return updated pointer to the compact collection + */ +ecma_value_t * +ecma_compact_collection_shrink (ecma_value_t *compact_collection_p) /**< compact collection */ +{ + ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p); + + if (unused_items == 0) + { + return compact_collection_p; + } + + ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p); + + size_t old_size = size * sizeof (ecma_value_t); + size_t new_size = (size - unused_items) * sizeof (ecma_value_t); + + compact_collection_p = (ecma_value_t *) jmem_heap_realloc_block (compact_collection_p, old_size, new_size); + + ECMA_COMPACT_COLLECTION_SET_SIZE (compact_collection_p, size - unused_items, 0); + return compact_collection_p; +} /* ecma_compact_collection_shrink */ + +/** + * Free a compact collection + */ +void +ecma_compact_collection_free (ecma_value_t *compact_collection_p) /**< compact collection */ +{ + ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p); + ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p); + + ecma_value_t *end_p = compact_collection_p + size - unused_items; + ecma_value_t *current_p = compact_collection_p + 1; + + while (current_p < end_p) + { + ecma_free_value (*current_p++); + } + + jmem_heap_free_block (compact_collection_p, size * sizeof (ecma_value_t)); +} /* ecma_compact_collection_free */ + +/** + * Get the end of a compact collection + * + * @return pointer to the compact collection end + */ +ecma_value_t * +ecma_compact_collection_end (ecma_value_t *compact_collection_p) /**< compact collection */ +{ + ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p); + ecma_value_t unused_items = ECMA_COMPACT_COLLECTION_GET_UNUSED_ITEM_COUNT (compact_collection_p); + + return compact_collection_p + size - unused_items; +} /* ecma_compact_collection_end */ + +/** + * Destroy a compact collection + */ +void +ecma_compact_collection_destroy (ecma_value_t *compact_collection_p) /**< compact collection */ +{ + ecma_value_t size = ECMA_COMPACT_COLLECTION_GET_SIZE (compact_collection_p); + + jmem_heap_free_block (compact_collection_p, size * sizeof (ecma_value_t)); +} /* ecma_compact_collection_destroy */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.cpp new file mode 100644 index 0000000..0a506a7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-conversion.cpp @@ -0,0 +1,943 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" + +#include "jrt-libc-includes.h" +#include "lit-char-helpers.h" +#include "lit-magic-strings.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +#if JERRY_NUMBER_TYPE_FLOAT64 + +/** + * \addtogroup ecmahelpersbigintegers Helpers for operations intermediate 128-bit integers + * @{ + */ + +/** + * 128-bit integer type + */ +typedef struct +{ + uint64_t hi; /**< high 64 bits */ + uint64_t lo; /**< low 64 bits */ +} ecma_uint128_t; + +/** + * Round high part of 128-bit integer to uint64_t + * + * @return rounded high to uint64_t + */ +static uint64_t +ecma_round_high_to_uint64 (ecma_uint128_t *num_p) +{ + uint64_t masked_lo = num_p->lo & ~(1ULL << 63u); + uint64_t masked_hi = num_p->hi & 0x1; + + if ((num_p->lo >> 63u != 0) && (masked_lo > 0 || masked_hi != 0)) + { + return (num_p->hi + 1); + } + + return num_p->hi; +} /* ecma_round_high_to_uint64 */ + +/** + * Left shift 128-bit integer by max 63 bits. + */ +static void +ecma_uint128_shift_left (ecma_uint128_t *num_p, int32_t shift) +{ + num_p->hi = (num_p->hi << shift) | (num_p->lo >> (64 - shift)); + num_p->lo <<= shift; +} /* ecma_uint128_shift_left */ + +/** + * Right shift 128-bit integer by max 63 bits. + */ +static void +ecma_uint128_shift_right (ecma_uint128_t *num_p, int32_t shift) +{ + num_p->lo = (num_p->lo >> shift) | (num_p->hi << (64 - shift)); + num_p->hi >>= shift; +} /* ecma_uint128_shift_right */ + +/** + * Add two 128-bit integer values and assign the result to the left one. + */ +static void +ecma_uint128_add (ecma_uint128_t *left_p, ecma_uint128_t *right_p) +{ + left_p->hi += right_p->hi; + left_p->lo += right_p->lo; + + if (left_p->lo < right_p->lo) + { + left_p->hi++; + } +} /* ecma_uint128_add */ + +/** + * Multiply 128-bit integer by 10 + */ +static void +ecma_uint128_mul10 (ecma_uint128_t *num_p) +{ + ecma_uint128_shift_left (num_p, 1u); + + ecma_uint128_t tmp = { num_p->hi, num_p->lo }; + ecma_uint128_shift_left (&tmp, 2u); + + ecma_uint128_add (num_p, &tmp); +} /* ecma_uint128_mul10 */ + +/** + * Divide 128-bit integer by 10 + * + * N = N3 *2^96 + N2 *2^64 + N1 *2^32 + N0 *2^0 // 128-bit dividend + * T = T3 *2^-32 + T2 *2^-64 + T1 *2^-96 + T0 *2^-128 // 128-bit divisor reciprocal, 1/10 * 2^-128 + * + * N * T = N3*T3 *2^64 + N2*T3 *2^32 + N1*T3 *2^0 + N0*T3 *2^-32 + * + N3*T2 *2^32 + N2*T2 *2^0 + N1*T2 *2^-32 + N0*T2 *2^-64 + * + N3*T1 *2^0 + N2*T1 *2^-32 + N1*T1 *2^-64 + N0*T1 *2^-96 + * + N3*T0 *2^-32 + N2*T0 *2^-64 + N1*T0 *2^-96 + N0*T0 *2^-128 + * + * Q3=carry Q2=^+carry Q1=^+carry Q0=^+carry fraction=^... + * + * Q = Q3 *2^96 + Q2 *2^64 + Q1 *2^32 + Q0 *2^0 // 128-bit quotient + */ +static void +ecma_uint128_div10 (ecma_uint128_t *num_p) +{ + /* estimation of reciprocal of 10, 128 bits right of the binary point (T1 == T2) */ + const uint64_t tenth_l = 0x9999999aul; + const uint64_t tenth_m = 0x99999999ul; + const uint64_t tenth_h = 0x19999999ul; + + const uint64_t l0 = ((uint32_t) num_p->lo) * tenth_l; + const uint64_t l1 = (num_p->lo >> 32u) * tenth_l; + const uint64_t l2 = ((uint32_t) num_p->hi) * tenth_l; + const uint64_t l3 = (num_p->hi >> 32u) * tenth_l; + const uint64_t m0 = ((uint32_t) num_p->lo) * tenth_m; + const uint64_t m1 = (num_p->lo >> 32u) * tenth_m; + const uint64_t m2 = ((uint32_t) num_p->hi) * tenth_m; + const uint64_t m3 = (num_p->hi >> 32u) * tenth_m; + const uint64_t h0 = ((uint32_t) num_p->lo) * tenth_h; + const uint64_t h1 = (num_p->lo >> 32u) * tenth_h; + const uint64_t h2 = ((uint32_t) num_p->hi) * tenth_h; + const uint64_t h3 = (num_p->hi >> 32u) * tenth_h; + + uint64_t q0 = l0 >> 32u; + q0 += (uint32_t) l1; + q0 += (uint32_t) m0; + + q0 >>= 32u; + q0 += l1 >> 32u; + q0 += m0 >> 32u; + q0 += (uint32_t) l2; + q0 += (uint32_t) m1; + q0 += (uint32_t) m0; + + q0 >>= 32u; + q0 += l2 >> 32u; + q0 += m1 >> 32u; + q0 += m0 >> 32u; + q0 += (uint32_t) l3; + q0 += (uint32_t) m2; + q0 += (uint32_t) m1; + q0 += (uint32_t) h0; + + q0 >>= 32u; + q0 += l3 >> 32u; + q0 += m2 >> 32u; + q0 += m1 >> 32u; + q0 += h0 >> 32u; + q0 += (uint32_t) m3; + q0 += (uint32_t) m2; + q0 += (uint32_t) h1; + + uint64_t q1 = q0 >> 32u; + q1 += m3 >> 32u; + q1 += m2 >> 32u; + q1 += h1 >> 32u; + q1 += (uint32_t) m3; + q1 += (uint32_t) h2; + + uint64_t q32 = q1 >> 32u; + q32 += m3 >> 32u; + q32 += h2 >> 32u; + q32 += h3; + + num_p->lo = (q1 << 32u) | ((uint32_t) q0); + num_p->hi = q32; +} /* ecma_uint128_div10 */ + +/** + * Count leading zeros in a 64-bit integer. The behaviour is undefined for 0. + * + * @return number of leading zeros. + */ +inline static int JERRY_ATTR_CONST +ecma_uint64_clz (uint64_t n) /**< integer to count leading zeros in */ +{ +#if defined(__GNUC__) || defined(__clang__) + return __builtin_clzll (n); +#else /* !defined (__GNUC__) && !defined (__clang__) */ + JERRY_ASSERT (n != 0); + + int cnt = 0; + uint64_t one = 0x8000000000000000ull; + + while ((n & one) == 0) + { + cnt++; + one >>= 1; + } + + return cnt; +#endif /* !defined (__GNUC__) && !defined (__clang__) */ +} /* ecma_uint64_clz */ + +/** + * Count leading zeros in the top 4 bits of a 64-bit integer. + * + * @return number of leading zeros in top 4 bits. + */ +inline static int JERRY_ATTR_CONST +ecma_uint64_clz_top4 (uint64_t n) /**< integer to count leading zeros in */ +{ + static const uint8_t ecma_uint4_clz[] = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; + return ecma_uint4_clz[n >> 60]; +} /* ecma_uint64_clz */ + +/** + * Shift required to clear 4 bits of a 64-bit integer. + * + * @return 0-4 + */ +inline static int JERRY_ATTR_CONST +ecma_uint64_normalize_shift (uint64_t n) /**< integer to count leading zeros in */ +{ + static const uint8_t ecma_uint4_shift[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; + + return ecma_uint4_shift[n >> 60]; +} /* ecma_uint64_normalize_shift */ + +/** + * @} + */ + +/** + * Number.MAX_VALUE exponent part when using 64 bit float representation. + */ +#define NUMBER_MAX_DECIMAL_EXPONENT 308 +/** + * Number.MIN_VALUE exponent part when using 64 bit float representation. + */ +#define NUMBER_MIN_DECIMAL_EXPONENT -324 + +#elif !JERRY_NUMBER_TYPE_FLOAT64 + +/** + * Number.MAX_VALUE exponent part when using 32 bit float representation. + */ +#define NUMBER_MAX_DECIMAL_EXPONENT 38 +/** + * Number.MIN_VALUE exponent part when using 32 bit float representation. + */ +#define NUMBER_MIN_DECIMAL_EXPONENT -45 + +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Value of epsilon + */ +#define EPSILON 0.0000001 + +/** + * ECMA-defined conversion from string to number for different radixes (2, 8, 16). + * + * See also: + * ECMA-262 v5 9.3.1 + * ECMA-262 v6 7.1.3.1 + * + * @return NaN - if the conversion fails + * converted number - otherwise + */ +ecma_number_t +ecma_utf8_string_to_number_by_radix (const lit_utf8_byte_t *str_p, /**< utf-8 string */ + const lit_utf8_size_t string_size, /**< end of utf-8 string */ + uint32_t radix, /**< radix */ + uint32_t options) /**< option flags */ +{ + JERRY_ASSERT (radix == 2 || radix == 8 || radix == 16); + JERRY_ASSERT (*str_p == LIT_CHAR_0); + + const lit_utf8_byte_t *end_p = str_p + string_size; + + /* Skip leading zero */ + str_p++; + + if (radix != 8 || LEXER_TO_ASCII_LOWERCASE (*str_p) == LIT_CHAR_LOWERCASE_O) + { + /* Skip radix specifier */ + str_p++; + } + + ecma_number_t num = ECMA_NUMBER_ZERO; + + while (str_p < end_p) + { + lit_utf8_byte_t digit = *str_p++; + + if (digit == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE)) + { + continue; + } + + if (!lit_char_is_hex_digit (digit)) + { + return ecma_number_make_nan (); + } + + uint32_t value = lit_char_hex_to_int (digit); + + if (value >= radix) + { + return ecma_number_make_nan (); + } + + num = num * radix + value; + } + + return num; +} /* ecma_utf8_string_to_number_by_radix */ + +/** + * ECMA-defined conversion of string to Number. + * + * See also: + * ECMA-262 v5, 9.3.1 + * + * @return NaN - if the conversion fails + * converted number - otherwise + */ +ecma_number_t +ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */ + lit_utf8_size_t str_size, /**< string size */ + uint32_t options) /**< allowing underscore option bit */ +{ + ecma_string_trim_helper (&str_p, &str_size); + const lit_utf8_byte_t *end_p = str_p + str_size; + + if (str_size == 0) + { + return ECMA_NUMBER_ZERO; + } + + bool sign = false; + + if (str_p + 2 < end_p && str_p[0] == LIT_CHAR_0) + { + uint8_t radix = lit_char_to_radix (str_p[1]); + + if (radix != 10) + { + return ecma_utf8_string_to_number_by_radix (str_p, str_size, radix, options); + } + } + + if (*str_p == LIT_CHAR_PLUS) + { + str_p++; + } + else if (*str_p == LIT_CHAR_MINUS) + { + sign = true; + str_p++; + } + + /* Check if string is equal to "Infinity". */ + const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL); + const lit_utf8_size_t infinity_length = lit_get_magic_string_size (LIT_MAGIC_STRING_INFINITY_UL); + + if ((lit_utf8_size_t) (end_p - str_p) == infinity_length && memcmp (infinity_str_p, str_p, infinity_length) == 0) + { + return ecma_number_make_infinity (sign); + } + + uint64_t significand = 0; + uint32_t digit_count = 0; + int32_t decimal_exponent = 0; + bool has_significand = false; + + /* Parsing integer part */ + while (str_p < end_p) + { + if (*str_p == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE)) + { + str_p++; + continue; + } + + if (!lit_char_is_decimal_digit (*str_p)) + { + break; + } + + has_significand = true; + uint32_t digit_value = (uint32_t) (*str_p++ - LIT_CHAR_0); + + if (digit_count == 0 && digit_value == 0) + { + /* Leading zeros are omitted. */ + continue; + } + + if (digit_count >= ECMA_NUMBER_MAX_DIGITS) + { + decimal_exponent++; + continue; + } + + significand = significand * 10 + digit_value; + digit_count++; + } + + /* Parse fraction part */ + if (str_p < end_p && *str_p == LIT_CHAR_DOT) + { + str_p++; + + while (str_p < end_p) + { + if (*str_p == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE)) + { + str_p++; + continue; + } + + if (!lit_char_is_decimal_digit (*str_p)) + { + break; + } + + has_significand = true; + uint32_t digit_value = (uint32_t) (*str_p++ - LIT_CHAR_0); + + if (digit_count == 0 && digit_value == 0) + { + /* Leading zeros are omitted. */ + decimal_exponent--; + continue; + } + + if (digit_count < ECMA_NUMBER_MAX_DIGITS) + { + significand = significand * 10 + digit_value; + digit_count++; + decimal_exponent--; + } + } + } + + /* Parsing exponent */ + if (str_p < end_p && LEXER_TO_ASCII_LOWERCASE (*str_p) == LIT_CHAR_LOWERCASE_E) + { + str_p++; + + int32_t exponent = 0; + int32_t exponent_sign = 1; + + if (str_p >= end_p) + { + return ecma_number_make_nan (); + } + + if (*str_p == LIT_CHAR_PLUS) + { + str_p++; + } + else if (*str_p == LIT_CHAR_MINUS) + { + exponent_sign = -1; + str_p++; + } + + if (str_p >= end_p || !lit_char_is_decimal_digit (*str_p)) + { + return ecma_number_make_nan (); + } + + while (str_p < end_p) + { + if (*str_p == LIT_CHAR_UNDERSCORE && (options & ECMA_CONVERSION_ALLOW_UNDERSCORE)) + { + str_p++; + continue; + } + + if (!lit_char_is_decimal_digit (*str_p)) + { + break; + } + + int32_t digit_value = (*str_p++ - LIT_CHAR_0); + exponent = exponent * 10 + digit_value; + + if (exponent_sign * exponent > NUMBER_MAX_DECIMAL_EXPONENT) + { + return ecma_number_make_infinity (sign); + } + + if (exponent_sign * exponent < NUMBER_MIN_DECIMAL_EXPONENT) + { + return sign ? -ECMA_NUMBER_ZERO : ECMA_NUMBER_ZERO; + } + } + + decimal_exponent += exponent_sign * exponent; + } + + if (!has_significand || str_p < end_p) + { + return ecma_number_make_nan (); + } + + if (significand == 0) + { + return sign ? -ECMA_NUMBER_ZERO : ECMA_NUMBER_ZERO; + } + +#if JERRY_NUMBER_TYPE_FLOAT64 + /* + * 128-bit mantissa storage + * + * Normalized: |4 bits zero|124-bit mantissa with highest bit set to 1| + */ + ecma_uint128_t significand_uint128 = { significand, 0 }; + + /* Normalizing mantissa */ + int shift = 4 - ecma_uint64_clz (significand_uint128.hi); + + if (shift < 0) + { + ecma_uint128_shift_left (&significand_uint128, -shift); + } + else + { + ecma_uint128_shift_right (&significand_uint128, shift); + } + + int32_t binary_exponent = ECMA_NUMBER_FRACTION_WIDTH + shift; + + while (decimal_exponent > 0) + { + JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) == 4); + + ecma_uint128_mul10 (&significand_uint128); + decimal_exponent--; + + /* Re-normalizing mantissa */ + shift = ecma_uint64_normalize_shift (significand_uint128.hi); + JERRY_ASSERT (shift >= 0 && shift <= 4); + + ecma_uint128_shift_right (&significand_uint128, shift); + binary_exponent += shift; + } + + while (decimal_exponent < 0) + { + /* Denormalizing mantissa, moving highest 1 to bit 127 */ + JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) <= 4); + shift = ecma_uint64_clz_top4 (significand_uint128.hi); + JERRY_ASSERT (shift >= 0 && shift <= 4); + + ecma_uint128_shift_left (&significand_uint128, shift); + binary_exponent -= shift; + + ecma_uint128_div10 (&significand_uint128); + decimal_exponent++; + } + + /* + * Preparing mantissa for conversion to 52-bit representation, converting it to: + * + * |11 zero bits|1|116 mantissa bits| + */ + JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) <= 4); + shift = 11 - ecma_uint64_clz_top4 (significand_uint128.hi); + ecma_uint128_shift_right (&significand_uint128, shift); + binary_exponent += shift; + + JERRY_ASSERT (ecma_uint64_clz (significand_uint128.hi) == 11); + + binary_exponent += ECMA_NUMBER_EXPONENT_BIAS; + + /* Handle denormal numbers */ + if (binary_exponent < 1) + { + ecma_uint128_shift_right (&significand_uint128, -binary_exponent + 1); + binary_exponent = 0; + } + + significand = ecma_round_high_to_uint64 (&significand_uint128); + + if (significand >= 1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1)) + { + /* Rounding carried over to the most significant bit, re-normalize. + * No need to shift mantissa right, as the low 52 bits will be 0 regardless. */ + binary_exponent++; + } + + if (binary_exponent >= ((1 << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) + { + return ecma_number_make_infinity (sign); + } + + /* Mask low 52 bits. */ + significand &= ((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1); + + JERRY_ASSERT (binary_exponent < (1 << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1); + JERRY_ASSERT (significand < (1ull << ECMA_NUMBER_FRACTION_WIDTH)); + + return ecma_number_create (sign, (uint32_t) binary_exponent, significand); +#elif !JERRY_NUMBER_TYPE_FLOAT64 + /* Less precise conversion */ + ecma_number_t num = (ecma_number_t) (uint32_t) fraction_uint64; + + ecma_number_t m = e_sign ? (ecma_number_t) 0.1 : (ecma_number_t) 10.0; + + while (e) + { + if (e % 2) + { + num *= m; + } + + m *= m; + e /= 2; + } + + return num; +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +} /* ecma_utf8_string_to_number */ + +/** + * ECMA-defined conversion of UInt32 to String (zero-terminated). + * + * See also: + * ECMA-262 v5, 9.8.1 + * + * @return number of bytes copied to buffer + */ +lit_utf8_size_t +ecma_uint32_to_utf8_string (uint32_t value, /**< value to convert */ + lit_utf8_byte_t *out_buffer_p, /**< buffer for string */ + lit_utf8_size_t buffer_size) /**< size of buffer */ +{ + lit_utf8_byte_t *buf_p = out_buffer_p + buffer_size; + + do + { + JERRY_ASSERT (buf_p >= out_buffer_p); + + buf_p--; + *buf_p = (lit_utf8_byte_t) ((value % 10) + LIT_CHAR_0); + value /= 10; + } while (value != 0); + + JERRY_ASSERT (buf_p >= out_buffer_p); + + lit_utf8_size_t bytes_copied = (lit_utf8_size_t) (out_buffer_p + buffer_size - buf_p); + + if (JERRY_LIKELY (buf_p != out_buffer_p)) + { + memmove (out_buffer_p, buf_p, bytes_copied); + } + + return bytes_copied; +} /* ecma_uint32_to_utf8_string */ + +/** + * ECMA-defined conversion of Number value to UInt32 value + * + * See also: + * ECMA-262 v5, 9.6 + * + * @return 32-bit unsigned integer - result of conversion. + */ +uint32_t +ecma_number_to_uint32 (ecma_number_t num) /**< ecma-number */ +{ + if (JERRY_UNLIKELY (ecma_number_is_zero (num) || !ecma_number_is_finite (num))) + { + return 0; + } + + const bool sign = ecma_number_is_negative (num); + const ecma_number_t abs_num = sign ? -num : num; + + /* 2 ^ 32 */ + const uint64_t uint64_2_pow_32 = (1ull << 32); + + const ecma_number_t num_2_pow_32 = uint64_2_pow_32; + + ecma_number_t num_in_uint32_range; + + if (abs_num >= num_2_pow_32) + { + num_in_uint32_range = ecma_number_remainder (abs_num, num_2_pow_32); + } + else + { + num_in_uint32_range = abs_num; + } + + /* Check that the floating point value can be represented with uint32_t. */ + JERRY_ASSERT (num_in_uint32_range < uint64_2_pow_32); + uint32_t uint32_num = (uint32_t) num_in_uint32_range; + + const uint32_t ret = sign ? (uint32_t)(-(int32_t)uint32_num) : uint32_num; + +#ifndef JERRY_NDEBUG + if (sign && uint32_num != 0) + { + JERRY_ASSERT (ret == uint64_2_pow_32 - uint32_num); + } + else + { + JERRY_ASSERT (ret == uint32_num); + } +#endif /* !JERRY_NDEBUG */ + + return ret; +} /* ecma_number_to_uint32 */ + +/** + * ECMA-defined conversion of Number value to Int32 value + * + * See also: + * ECMA-262 v5, 9.5 + * + * @return 32-bit signed integer - result of conversion. + */ +int32_t +ecma_number_to_int32 (ecma_number_t num) /**< ecma-number */ +{ + uint32_t uint32_num = ecma_number_to_uint32 (num); + + /* 2 ^ 32 */ + const int64_t int64_2_pow_32 = (1ll << 32); + + /* 2 ^ 31 */ + const uint32_t uint32_2_pow_31 = (1ull << 31); + + int32_t ret; + + if (uint32_num >= uint32_2_pow_31) + { + ret = (int32_t) (uint32_num - int64_2_pow_32); + } + else + { + ret = (int32_t) uint32_num; + } + +#ifndef JERRY_NDEBUG + int64_t int64_num = uint32_num; + + JERRY_ASSERT (int64_num >= 0); + + if (int64_num >= uint32_2_pow_31) + { + JERRY_ASSERT (ret == int64_num - int64_2_pow_32); + } + else + { + JERRY_ASSERT (ret == int64_num); + } +#endif /* !JERRY_NDEBUG */ + + return ret; +} /* ecma_number_to_int32 */ + +/** + * Perform conversion of ecma-number to decimal representation with decimal exponent. + * + * Note: + * The calculated values correspond to s, n, k parameters in ECMA-262 v5, 9.8.1, item 5: + * - parameter out_digits_p corresponds to s, the digits of the number; + * - parameter out_decimal_exp_p corresponds to n, the decimal exponent; + * - return value corresponds to k, the number of digits. + * + * @return the number of digits + */ +lit_utf8_size_t +ecma_number_to_decimal (ecma_number_t num, /**< ecma-number */ + lit_utf8_byte_t *out_digits_p, /**< [out] buffer to fill with digits */ + int32_t *out_decimal_exp_p) /**< [out] decimal exponent */ +{ + JERRY_ASSERT (!ecma_number_is_nan (num)); + JERRY_ASSERT (!ecma_number_is_zero (num)); + JERRY_ASSERT (!ecma_number_is_infinity (num)); + JERRY_ASSERT (!ecma_number_is_negative (num)); + + return ecma_errol0_dtoa ((double) num, out_digits_p, out_decimal_exp_p); +} /* ecma_number_to_decimal */ + +/** + * Convert ecma-number to zero-terminated string + * + * See also: + * ECMA-262 v5, 9.8.1 + * + * + * @return size of utf-8 string + */ +lit_utf8_size_t +ecma_number_to_utf8_string (ecma_number_t num, /**< ecma-number */ + lit_utf8_byte_t *buffer_p, /**< buffer for utf-8 string */ + lit_utf8_size_t buffer_size) /**< size of buffer */ +{ + lit_utf8_byte_t *dst_p; + + if (ecma_number_is_nan (num)) + { + /* 1. */ + dst_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_NAN, buffer_p, buffer_size); + return (lit_utf8_size_t) (dst_p - buffer_p); + } + + if (ecma_number_is_zero (num)) + { + /* 2. */ + *buffer_p = LIT_CHAR_0; + JERRY_ASSERT (1 <= buffer_size); + return 1; + } + + dst_p = buffer_p; + + if (ecma_number_is_negative (num)) + { + /* 3. */ + *dst_p++ = LIT_CHAR_MINUS; + num = -num; + } + + if (ecma_number_is_infinity (num)) + { + /* 4. */ + dst_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_INFINITY_UL, + dst_p, + (lit_utf8_size_t) (buffer_p + buffer_size - dst_p)); + JERRY_ASSERT (dst_p <= buffer_p + buffer_size); + return (lit_utf8_size_t) (dst_p - buffer_p); + } + + /* 5. */ + uint32_t num_uint32 = ecma_number_to_uint32 (num); + + if (((ecma_number_t) num_uint32) == num) + { + dst_p += ecma_uint32_to_utf8_string (num_uint32, dst_p, (lit_utf8_size_t) (buffer_p + buffer_size - dst_p)); + JERRY_ASSERT (dst_p <= buffer_p + buffer_size); + return (lit_utf8_size_t) (dst_p - buffer_p); + } + + /* decimal exponent */ + int32_t n; + /* number of digits in mantissa */ + int32_t k; + + k = (int32_t) ecma_number_to_decimal (num, dst_p, &n); + + if (k <= n && n <= 21) + { + /* 6. */ + dst_p += k; + + memset (dst_p, LIT_CHAR_0, (size_t) (n - k)); + dst_p += n - k; + + JERRY_ASSERT (dst_p <= buffer_p + buffer_size); + return (lit_utf8_size_t) (dst_p - buffer_p); + } + + if (0 < n && n <= 21) + { + /* 7. */ + memmove (dst_p + n + 1, dst_p + n, (size_t) (k - n)); + *(dst_p + n) = LIT_CHAR_DOT; + dst_p += k + 1; + + JERRY_ASSERT (dst_p <= buffer_p + buffer_size); + return (lit_utf8_size_t) (dst_p - buffer_p); + } + + if (-6 < n && n <= 0) + { + /* 8. */ + memmove (dst_p + 2 - n, dst_p, (size_t) k); + memset (dst_p + 2, LIT_CHAR_0, (size_t) -n); + *dst_p = LIT_CHAR_0; + *(dst_p + 1) = LIT_CHAR_DOT; + dst_p += k - n + 2; + + JERRY_ASSERT (dst_p <= buffer_p + buffer_size); + return (lit_utf8_size_t) (dst_p - buffer_p); + } + + if (k == 1) + { + /* 9. */ + dst_p++; + } + else + { + /* 10. */ + memmove (dst_p + 2, dst_p + 1, (size_t) (k - 1)); + *(dst_p + 1) = LIT_CHAR_DOT; + dst_p += k + 1; + } + + /* 9., 10. */ + *dst_p++ = LIT_CHAR_LOWERCASE_E; + *dst_p++ = (n >= 1) ? LIT_CHAR_PLUS : LIT_CHAR_MINUS; + uint32_t t = (uint32_t) (n >= 1 ? (n - 1) : -(n - 1)); + + dst_p += ecma_uint32_to_utf8_string (t, dst_p, (lit_utf8_size_t) (buffer_p + buffer_size - dst_p)); + + JERRY_ASSERT (dst_p <= buffer_p + buffer_size); + + return (lit_utf8_size_t) (dst_p - buffer_p); +} /* ecma_number_to_utf8_string */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-errol.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-errol.cpp new file mode 100644 index 0000000..67f7869 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-errol.cpp @@ -0,0 +1,245 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is based on work under the following copyright and permission + * notice: + * + * Copyright (c) 2016 Marc Andrysco + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include "ecma-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +/** + * Printing Floating-Point Numbers + * + * available at http://cseweb.ucsd.edu/~mandrysc/pub/dtoa.pdf + */ + +/** + * Floating point format definitions (next float value) + */ +#define ECMA_NEXT_FLOAT(value) (nextafter ((value), INFINITY)) +/** + * Floating point format definitions (previous float value) + */ +#define ECMA_PREV_FLOAT(value) (nextafter ((value), -INFINITY)) + +/** + * Value of epsilon + */ +#define ERROL0_EPSILON 0.0000001 + +/** + * High-precision data structure. + */ +typedef struct +{ + double value; /**< value */ + double offset; /**< offset */ +} ecma_high_prec_t; + +/** + * Normalize the number by factoring in the error. + * + * @return void + */ +static inline void +ecma_normalize_high_prec_data (ecma_high_prec_t *hp_data_p) /**< [in, out] float pair */ +{ + double val = hp_data_p->value; + + hp_data_p->value += hp_data_p->offset; + hp_data_p->offset += val - hp_data_p->value; +} /* ecma_normalize_high_prec_data */ + +/** + * Multiply the high-precision number by ten. + * + * @return void + */ +static inline void +ecma_multiply_high_prec_by_10 (ecma_high_prec_t *hp_data_p) /**< [in, out] high-precision number */ +{ + double value = hp_data_p->value; + + hp_data_p->value *= 10.0; + hp_data_p->offset *= 10.0; + + double offset = hp_data_p->value; + + offset -= value * 8.0; + offset -= value * 2.0; + + hp_data_p->offset -= offset; + + ecma_normalize_high_prec_data (hp_data_p); +} /* ecma_multiply_high_prec_by_10 */ + +/** + * Divide the high-precision number by ten. + */ +static void +ecma_divide_high_prec_by_10 (ecma_high_prec_t *hp_data_p) /**< [in, out] high-precision number */ +{ + double value = hp_data_p->value; + + hp_data_p->value /= 10.0; + hp_data_p->offset /= 10.0; + + value -= hp_data_p->value * 8.0; + value -= hp_data_p->value * 2.0; + + hp_data_p->offset += value / 10.0; + + ecma_normalize_high_prec_data (hp_data_p); +} /* ecma_divide_high_prec_by_10 */ + +/** + * Errol0 double to ASCII conversion, guaranteed correct but possibly not optimal. + * + * @return number of generated digits + */ +lit_utf8_size_t +ecma_errol0_dtoa (double val, /**< ecma number */ + lit_utf8_byte_t *buffer_p, /**< buffer to generate digits into */ + int32_t *exp_p) /**< [out] exponent */ +{ + double power_of_10 = 1.0; + int32_t exponent = 1; + + /* normalize the midpoint */ + ecma_high_prec_t mid; + + mid.value = val; + mid.offset = 0.0; + + while (((mid.value > 10.0) || ((mid.value == 10.0) && (mid.offset >= 0.0))) && (exponent < 308)) + { + exponent++; + ecma_divide_high_prec_by_10 (&mid); + power_of_10 /= 10.0; + } + + while (((mid.value < 1.0) || ((mid.value == 1.0) && (mid.offset < 0.0))) && (exponent > -307)) + { + exponent--; + ecma_multiply_high_prec_by_10 (&mid); + power_of_10 *= 10.0; + } + + ecma_high_prec_t high_bound, low_bound; + + high_bound.value = mid.value; + high_bound.offset = mid.offset; + + if ((float) ECMA_NEXT_FLOAT (val) != (float) INFINITY) + { + high_bound.offset += (ECMA_NEXT_FLOAT (val) - val) * power_of_10 / (2.0 + ERROL0_EPSILON); + } + + low_bound.value = mid.value; + low_bound.offset = mid.offset + (ECMA_PREV_FLOAT (val) - val) * power_of_10 / (2.0 + ERROL0_EPSILON); + + ecma_normalize_high_prec_data (&high_bound); + ecma_normalize_high_prec_data (&low_bound); + + /* normalized boundaries */ + + while (high_bound.value > 10.0 || (high_bound.value == 10.0 && (high_bound.offset >= 0.0))) + { + exponent++; + ecma_divide_high_prec_by_10 (&high_bound); + ecma_divide_high_prec_by_10 (&low_bound); + } + + while (high_bound.value < 1.0 || (high_bound.value == 1.0 && (high_bound.offset < 0.0))) + { + exponent--; + ecma_multiply_high_prec_by_10 (&high_bound); + ecma_multiply_high_prec_by_10 (&low_bound); + } + + /* digit generation */ + + lit_utf8_byte_t *dst_p = buffer_p; + + while (high_bound.value != 0.0 || high_bound.offset != 0.0) + { + uint8_t high_digit = (uint8_t) high_bound.value; + + if ((high_bound.value == high_digit) && (high_bound.offset < 0)) + { + high_digit = (uint8_t) (high_digit - 1u); + } + + uint8_t low_digit = (uint8_t) low_bound.value; + + if ((low_bound.value == low_digit) && (low_bound.offset < 0)) + { + low_digit = (uint8_t) (low_digit - 1u); + } + + if (low_digit != high_digit) + { + break; + } + + *dst_p++ = (lit_utf8_byte_t) ('0' + high_digit); + + high_bound.value -= high_digit; + ecma_multiply_high_prec_by_10 (&high_bound); + + low_bound.value -= low_digit; + ecma_multiply_high_prec_by_10 (&low_bound); + } + + double mdig = (high_bound.value + low_bound.value) / 2.0 + 0.5; + *dst_p++ = (lit_utf8_byte_t) ('0' + (uint8_t) mdig); + + *exp_p = exponent; + + return (lit_utf8_size_t) (dst_p - buffer_p); +} /* ecma_errol0_dtoa */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-external-pointers.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-external-pointers.cpp new file mode 100644 index 0000000..5ff76b0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-external-pointers.cpp @@ -0,0 +1,334 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +/** + * Create a native pointer property to store the native pointer and its type info. + * + * @return true - if property was just created with specified value, + * false - otherwise, if property existed before the call, it's value was updated + */ +bool +ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create property in */ + void *native_p, /**< native pointer */ + const jerry_object_native_info_t *native_info_p) /**< native type info */ +{ + ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER); + + if (native_info_p != NULL && native_info_p->number_of_references > 0) + { + name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES); + } + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_fast_array_convert_to_normal (obj_p); + } + + ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); + + bool is_new = (property_p == NULL); + + ecma_native_pointer_t *native_pointer_p; + + if (property_p == NULL) + { + native_pointer_p = (ecma_native_pointer_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_t)); + + ecma_property_value_t *value_p; + ECMA_CREATE_INTERNAL_PROPERTY (obj_p, name_p, property_p, value_p); + + ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p); + *property_p |= ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL; + } + else if (*property_p & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL) + { + ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value); + + if (native_pointer_p->native_info_p == native_info_p) + { + native_pointer_p->native_p = native_p; + return false; + } + + value_p->value = JMEM_CP_NULL; + (void) value_p->value; /* Make cppcheck happy. */ + *property_p &= (ecma_property_t) ~ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL; + + ecma_native_pointer_chain_t *item_p; + item_p = (ecma_native_pointer_chain_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_chain_t)); + item_p->data = *native_pointer_p; + + jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t)); + + item_p->next_p = (ecma_native_pointer_chain_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_chain_t)); + item_p->next_p->next_p = NULL; + + native_pointer_p = &item_p->next_p->data; + ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, item_p); + } + else + { + ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (value_p->value == JMEM_CP_NULL) + { + native_pointer_p = (ecma_native_pointer_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_t)); + ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p); + + *property_p |= ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL; + } + else + { + ecma_native_pointer_chain_t *item_p; + item_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value_p->value); + + /* There should be at least 2 native pointers in the chain */ + JERRY_ASSERT (item_p != NULL && item_p->next_p != NULL); + + while (true) + { + if (item_p->data.native_info_p == native_info_p) + { + /* The native info already exists -> update the corresponding data */ + item_p->data.native_p = native_p; + return false; + } + + if (item_p->next_p == NULL) + { + /* The native info does not exist -> append a new element to the chain */ + break; + } + + item_p = item_p->next_p; + } + + ecma_native_pointer_chain_t *new_item_p; + + new_item_p = (ecma_native_pointer_chain_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_chain_t)); + item_p->next_p = new_item_p; + new_item_p->next_p = NULL; + + native_pointer_p = &new_item_p->data; + } + } + + native_pointer_p->native_p = native_p; + native_pointer_p->native_info_p = (jerry_object_native_info_t *) native_info_p; + + return is_new; +} /* ecma_create_native_pointer_property */ + +/** + * Get value of native package stored in the object's property with specified identifier + * + * Note: + * property identifier should be one of the following: + * - LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER + * + * @return native pointer data if property exists + * NULL otherwise + */ +ecma_native_pointer_t * +ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */ + const jerry_object_native_info_t *native_info_p) /**< native type info */ +{ + if (ecma_op_object_is_fast_array (obj_p)) + { + /* Fast access mode array cannot have native pointer properties */ + return NULL; + } + + ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER); + + if (native_info_p != NULL && native_info_p->number_of_references > 0) + { + name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES); + } + + ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); + + if (property_p == NULL) + { + return NULL; + } + + ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (JERRY_LIKELY (*property_p & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL)) + { + ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value); + + if (native_pointer_p->native_info_p == native_info_p) + { + return native_pointer_p; + } + + return NULL; + } + + if (value_p->value == JMEM_CP_NULL) + { + return NULL; + } + + ecma_native_pointer_chain_t *item_p; + item_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value_p->value); + + /* There should be at least 2 native pointers in the chain */ + JERRY_ASSERT (item_p != NULL && item_p->next_p != NULL); + + do + { + if (item_p->data.native_info_p == native_info_p) + { + return &item_p->data; + } + + item_p = item_p->next_p; + } while (item_p != NULL); + + return NULL; +} /* ecma_get_native_pointer_value */ + +/** + * Delete the previously set native pointer by the native type info from the specified object. + * + * Note: + * If the specified object has no matching native pointer for the given native type info + * the function has no effect. + * + * @return true - if the native pointer has been deleted successfully + * false - otherwise + */ +bool +ecma_delete_native_pointer_property (ecma_object_t *obj_p, /**< object to delete property from */ + const jerry_object_native_info_t *native_info_p) /**< native type info */ +{ + if (ecma_op_object_is_fast_array (obj_p)) + { + /* Fast access mode array cannot have native pointer properties */ + return false; + } + + ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER); + + if (native_info_p != NULL && native_info_p->number_of_references > 0) + { + name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES); + } + + ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); + + if (property_p == NULL) + { + return false; + } + + ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (JERRY_LIKELY (*property_p & ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL)) + { + ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value); + + if (native_pointer_p->native_info_p != native_info_p) + { + return false; + } + + value_p->value = JMEM_CP_NULL; + *property_p &= (ecma_property_t) ~ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL; + jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t)); + return true; + } + + if (value_p->value == JMEM_CP_NULL) + { + return false; + } + + ecma_native_pointer_chain_t *first_p; + first_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_chain_t, value_p->value); + + /* There should be at least 2 native pointers in the chain */ + JERRY_ASSERT (first_p != NULL && first_p->next_p != NULL); + + ecma_native_pointer_chain_t *item_p = first_p; + ecma_native_pointer_chain_t *prev_p = NULL; + + do + { + if (item_p->data.native_info_p == native_info_p) + { + if (prev_p == NULL) + { + /* The first element is deleted from the chain: change the property value. */ + first_p = item_p->next_p; + ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, first_p); + } + else + { + /* A non-first element is deleted from the chain: update the previous pointer. */ + prev_p->next_p = item_p->next_p; + } + + jmem_heap_free_block (item_p, sizeof (ecma_native_pointer_chain_t)); + + if (first_p->next_p != NULL) + { + return true; + } + + /* Only one item remained. The ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL flag is + * set early to avoid using the chain if the allocation below triggers a GC. */ + *property_p |= ECMA_PROPERTY_FLAG_SINGLE_EXTERNAL; + + ecma_native_pointer_t *native_pointer_p; + native_pointer_p = (ecma_native_pointer_t *) jmem_heap_alloc_block (sizeof (ecma_native_pointer_t)); + *native_pointer_p = first_p->data; + + ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p); + + jmem_heap_free_block (first_p, sizeof (ecma_native_pointer_chain_t)); + return true; + } + + prev_p = item_p; + item_p = item_p->next_p; + } while (item_p != NULL); + + return false; +} /* ecma_delete_native_pointer_property */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-number.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-number.cpp new file mode 100644 index 0000000..56c867d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-number.cpp @@ -0,0 +1,677 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-helpers-number.h" + +#include + +#include "ecma-conversion.h" + +#include "lit-char-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +JERRY_STATIC_ASSERT ((sizeof (ecma_value_t) == sizeof (ecma_integer_value_t)), + size_of_ecma_value_t_must_be_equal_to_the_size_of_ecma_integer_value_t); + +JERRY_STATIC_ASSERT ((((int)ECMA_DIRECT_SHIFT) == (((int)ECMA_VALUE_SHIFT) + 1)), currently_directly_encoded_values_has_one_extra_flag); + +JERRY_STATIC_ASSERT ((((1 << (ECMA_DIRECT_SHIFT - 1)) | ECMA_TYPE_DIRECT) == ECMA_DIRECT_TYPE_SIMPLE_VALUE), + currently_directly_encoded_values_start_after_direct_type_simple_value); + +JERRY_STATIC_ASSERT ((sizeof (ecma_number_t) == sizeof (ecma_binary_num_t)), + size_of_ecma_number_t_must_be_equal_to_binary_representation); + +/** + * Convert an ecma-number to it's binary representation. + * + * @return binary representation + */ +ecma_binary_num_t JERRY_ATTR_CONST +ecma_number_to_binary (ecma_number_t number) /**< ecma number */ +{ + ecma_number_accessor_t f; + f.as_number = number; + + return f.as_binary; +} /* ecma_number_to_binary */ + +/** + * Convert a binary representation to the corresponding ecma-number. + * + * @return ecma-number + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_from_binary (ecma_binary_num_t binary) /**< binary representation */ +{ + ecma_number_accessor_t f; + f.as_binary = binary; + + return f.as_number; +} /* ecma_number_from_binary */ + +/** + * Check signedness of the binary number. + * + * @return true - if sign bit is set + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_number_sign (ecma_binary_num_t binary) /**< binary representation */ +{ + return (binary & ECMA_NUMBER_SIGN_BIT) != 0; +} /* ecma_number_sign */ + +/** + * Get biased exponent field of the binary number. + * + * @return unsigned integer value of the biased exponent field + */ +uint32_t JERRY_ATTR_CONST +ecma_number_biased_exp (ecma_binary_num_t binary) /**< binary representation */ +{ + return (uint32_t) ((binary & ~ECMA_NUMBER_SIGN_BIT) >> ECMA_NUMBER_FRACTION_WIDTH); +} /* ecma_number_biased_exp */ + +/** + * Get fraction field of the binary number. + * + * @return unsigned integer value of the fraction field + */ +uint64_t JERRY_ATTR_CONST +ecma_number_fraction (ecma_binary_num_t binary) /**< binary representation */ +{ + return binary & ((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1); +} /* ecma_number_fraction */ + +/** + * Packing sign, fraction and biased exponent to ecma-number + * + * @return ecma-number with specified sign, biased_exponent and fraction + */ +ecma_number_t +ecma_number_create (bool sign, /**< sign */ + uint32_t biased_exp, /**< biased exponent */ + uint64_t fraction) /**< fraction */ +{ + JERRY_ASSERT ((biased_exp & ~((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) == 0); + JERRY_ASSERT ((fraction & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0); + + ecma_binary_num_t binary = biased_exp; + binary <<= ECMA_NUMBER_FRACTION_WIDTH; + + binary |= fraction; + + if (sign) + { + binary |= ECMA_NUMBER_SIGN_BIT; + } + + return ecma_number_from_binary (binary); +} /* ecma_number_create */ + +/** + * Check if ecma-number is NaN + * + * @return true - if biased exponent is filled with 1 bits and + fraction is filled with anything but not all zero bits, + * false - otherwise + */ +bool +ecma_number_is_nan (ecma_number_t num) /**< ecma-number */ +{ + bool is_nan = (num != num); + +#ifndef JERRY_NDEBUG + /* IEEE-754 2008, 3.4, a */ + ecma_binary_num_t binary = ecma_number_to_binary (num); + bool is_nan_exponent = (ecma_number_biased_exp (binary) == (1 << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1); + bool is_nan_fraction = (ecma_number_fraction (binary) > 0); + + bool is_nan_ieee754 = is_nan_exponent && is_nan_fraction; + JERRY_ASSERT (is_nan == is_nan_ieee754); +#endif /* !JERRY_NDEBUG */ + + return is_nan; +} /* ecma_number_is_nan */ + +/** + * Make a NaN. + * + * @return NaN value + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_make_nan (void) +{ + ecma_number_accessor_t f; + f.as_binary = ECMA_NUMBER_BINARY_QNAN; + + return f.as_number; +} /* ecma_number_make_nan */ + +/** + * Make an Infinity. + * + * @return if !sign - +Infinity value, + * else - -Infinity value. + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_make_infinity (bool sign) /**< sign of the value */ +{ + ecma_number_accessor_t f; + f.as_binary = ECMA_NUMBER_BINARY_INF; + + if (sign) + { + f.as_binary |= ECMA_NUMBER_SIGN_BIT; + } + + return f.as_number; +} /* ecma_number_make_infinity */ + +/** + * Check if ecma-number is negative + * + * @return true - if sign bit of ecma-number is set + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_number_is_negative (ecma_number_t num) /**< ecma-number */ +{ + JERRY_ASSERT (!ecma_number_is_nan (num)); + + return (ecma_number_to_binary (num) & ECMA_NUMBER_SIGN_BIT) != 0; +} /* ecma_number_is_negative */ + +/** + * Check if ecma-number is zero + * + * @return true - if fraction is zero and biased exponent is zero, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_number_is_zero (ecma_number_t num) /**< ecma-number */ +{ + bool is_zero = (num == ECMA_NUMBER_ZERO); + +#ifndef JERRY_NDEBUG + bool is_zero_ieee754 = ((ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == 0); + JERRY_ASSERT (is_zero == is_zero_ieee754); +#endif /* !JERRY_NDEBUG */ + + return is_zero; +} /* ecma_number_is_zero */ + +/** + * Check if number is infinity + * + * @return true - if biased exponent is filled with 1 bits and + * fraction is filled with zero bits, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */ +{ + return (ecma_number_to_binary (num) & ~ECMA_NUMBER_SIGN_BIT) == ECMA_NUMBER_BINARY_INF; +} /* ecma_number_is_infinity */ + +/** + * Check if number is finite + * + * @return true - if number is finite + * false - if number is NaN or infinity + */ +bool JERRY_ATTR_CONST +ecma_number_is_finite (ecma_number_t num) /**< ecma-number */ +{ +#if defined(__GNUC__) || defined(__clang__) + return __builtin_isfinite (num); +#elif defined(_WIN32) + return isfinite (num); +#else /* !(defined(__GNUC__) || defined(__clang__) || defined(_WIN32)) */ + return !ecma_number_is_nan (num) && !ecma_number_is_infinity (num); +#endif /* defined (__GNUC__) || defined (__clang__) */ +} /* ecma_number_is_finite */ + +/** + * Get previous representable ecma-number + * + * @return maximum ecma-number that is less compared to passed argument + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_get_prev (ecma_number_t num) /**< ecma-number */ +{ +#if defined(__GNUC__) || defined(__clang__) + return __builtin_nextafter ((double)num, (double)-INFINITY); +#else /* !defined (__GNUC__) && !defined (__clang__) */ + JERRY_ASSERT (!ecma_number_is_nan (num)); + ecma_binary_num_t binary = ecma_number_to_binary (num); + + /* If -Infinity, return self */ + if (binary == (ECMA_NUMBER_SIGN_BIT | ECMA_NUMBER_BINARY_INF)) + { + return num; + } + + /* If +0.0, return -0.0 */ + if (binary == ECMA_NUMBER_BINARY_ZERO) + { + return -num; + } + + if (ecma_number_sign (binary)) + { + return ecma_number_from_binary (binary + 1); + } + + return ecma_number_from_binary (binary - 1); +#endif /* !defined (__GNUC__) && !defined (__clang__) */ +} /* ecma_number_get_prev */ + +/** + * Get next representable ecma-number + * + * @return minimum ecma-number that is greater compared to passed argument + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_get_next (ecma_number_t num) /**< ecma-number */ +{ +#if defined(__GNUC__) || defined(__clang__) + return __builtin_nextafter ((double)num, (double)INFINITY); +#else /* !defined (__GNUC__) && !defined (__clang__) */ + JERRY_ASSERT (!ecma_number_is_nan (num)); + ecma_binary_num_t binary = ecma_number_to_binary (num); + + /* If +Infinity, return self */ + if (binary == ECMA_NUMBER_BINARY_INF) + { + return num; + } + + /* If -0.0, return +0.0 */ + if (binary == (ECMA_NUMBER_SIGN_BIT | ECMA_NUMBER_BINARY_ZERO)) + { + return -num; + } + + if (ecma_number_sign (binary)) + { + return ecma_number_from_binary (binary - 1); + } + + return ecma_number_from_binary (binary + 1); +#endif /* !defined (__GNUC__) && !defined (__clang__) */ +} /* ecma_number_get_next */ + +/** + * Truncate fractional part of the number + * + * @return integer part of the number + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_trunc (ecma_number_t num) /**< ecma-number */ +{ + JERRY_ASSERT (!ecma_number_is_nan (num)); + + ecma_binary_num_t binary = ecma_number_to_binary (num); + uint32_t exponent = ecma_number_biased_exp (binary); + + if (exponent < ECMA_NUMBER_EXPONENT_BIAS) + { + return ECMA_NUMBER_ZERO; + } + + uint32_t unbiased_exp = exponent - ECMA_NUMBER_EXPONENT_BIAS; + + if (unbiased_exp >= ECMA_NUMBER_FRACTION_WIDTH) + { + return num; + } + + binary &= ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH - unbiased_exp)) - 1); + return ecma_number_from_binary (binary); +} /* ecma_number_trunc */ + +/** + * Calculate remainder of division of two numbers, + * as specified in ECMA-262 v5, 11.5.3, item 6. + * + * Note: + * operands shouldn't contain NaN, Infinity, or zero. + * + * @return number - calculated remainder. + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_remainder (ecma_number_t left_num, /**< left operand */ + ecma_number_t right_num) /**< right operand */ +{ + JERRY_ASSERT (ecma_number_is_finite (left_num) && !ecma_number_is_zero (left_num)); + JERRY_ASSERT (ecma_number_is_finite (right_num) && !ecma_number_is_zero (right_num)); + + const ecma_number_t q = ecma_number_trunc (left_num / right_num); + ecma_number_t r = left_num - right_num * q; + + if (ecma_number_is_zero (r) && ecma_number_is_negative (left_num)) + { + r = -r; + } + + return r; +} /* ecma_number_remainder */ + +/** + * Compute power operation according to the ES standard. + * + * @return x ** y + */ +ecma_number_t JERRY_ATTR_CONST +ecma_number_pow (ecma_number_t x, /**< left operand */ + ecma_number_t y) /**< right operand */ +{ + if (ecma_number_is_nan (y) || (ecma_number_is_infinity (y) && (x == ECMA_NUMBER_ONE || x == ECMA_NUMBER_MINUS_ONE))) + { + /* Handle differences between ES5.1 and ISO C standards for pow. */ + return ecma_number_make_nan (); + } + + if (ecma_number_is_zero (y)) + { + /* Handle differences between ES5.1 and ISO C standards for pow. */ + return ECMA_NUMBER_ONE; + } + + return DOUBLE_TO_ECMA_NUMBER_T (pow (x, y)); +} /* ecma_number_pow */ + +/** + * ECMA-integer number multiplication. + * + * @return number - result of multiplication. + */ +ecma_value_t JERRY_ATTR_CONST +ecma_integer_multiply (ecma_integer_value_t left_integer, /**< left operand */ + ecma_integer_value_t right_integer) /**< right operand */ +{ +#if defined(__GNUC__) || defined(__clang__) + /* Check if either integer is power of 2 */ + if (JERRY_UNLIKELY ((left_integer & (left_integer - 1)) == 0)) + { + /* Right shift right_integer with log2 (left_integer) */ + return ecma_make_integer_value ( + (int32_t) ((uint32_t) right_integer << (__builtin_ctz ((unsigned int) left_integer)))); + } + + if (JERRY_UNLIKELY ((right_integer & (right_integer - 1)) == 0)) + { + /* Right shift left_integer with log2 (right_integer) */ + return ecma_make_integer_value ( + (int32_t) ((uint32_t) left_integer << (__builtin_ctz ((unsigned int) right_integer)))); + } +#endif /* defined (__GNUC__) || defined (__clang__) */ + + return ecma_make_integer_value (left_integer * right_integer); +} /* ecma_integer_multiply */ + +/** + * The Number object's 'parseInt' routine + * + * See also: + * ECMA-262 v5, 15.1.2.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_number_parse_int (const lit_utf8_byte_t *str_p, /**< routine's first argument's + * string buffer */ + lit_utf8_size_t str_size, /**< routine's first argument's + * string buffer's size */ + ecma_value_t radix_value) /**< routine's second argument */ +{ + /* 2. Remove leading whitespace. */ + ecma_string_trim_helper (&str_p, &str_size); + + if (str_size == 0) + { + return ecma_make_nan_value (); + } + + const lit_utf8_byte_t *str_end_p = str_p + str_size; + + /* 3. */ + bool sign = false; + + /* 4. */ + if (*str_p == LIT_CHAR_MINUS) + { + sign = true; + str_p++; + } + /* 5. */ + else if (*str_p == LIT_CHAR_PLUS) + { + str_p++; + } + + /* 6. */ + ecma_number_t radix_num; + radix_value = ecma_op_to_number (radix_value, &radix_num); + + if (ECMA_IS_VALUE_ERROR (radix_value)) + { + return ECMA_VALUE_ERROR; + } + + int32_t radix = ecma_number_to_int32 (radix_num); + + /* 7.*/ + bool strip_prefix = true; + + /* 8. */ + if (radix != 0) + { + /* 8.a */ + if (radix < 2 || radix > 36) + { + return ecma_make_nan_value (); + } + /* 8.b */ + else if (radix != 16) + { + strip_prefix = false; + } + } + /* 9. */ + else + { + radix = 10; + } + + /* 10. */ + if (strip_prefix && ((str_end_p - str_p) >= 2) && (str_p[0] == LIT_CHAR_0) + && (LEXER_TO_ASCII_LOWERCASE (str_p[1]) == LIT_CHAR_LOWERCASE_X)) + { + str_p += 2; + radix = 16; + } + + ecma_number_t value = ECMA_NUMBER_ZERO; + const lit_utf8_byte_t *digit_start_p = str_p; + + /* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */ + while (str_p < str_end_p) + { + ecma_char_t ch = *str_p; + + int32_t digit = 0; + + if (lit_char_is_decimal_digit (ch)) + { + digit = ch - LIT_CHAR_0; + } + else if (LEXER_TO_ASCII_LOWERCASE (ch) >= LIT_CHAR_LOWERCASE_A + && LEXER_TO_ASCII_LOWERCASE (ch) <= LIT_CHAR_LOWERCASE_Z) + { + digit = LEXER_TO_ASCII_LOWERCASE (ch) - LIT_CHAR_LOWERCASE_A + 10; + } + else + { + /* Not a valid digit char, set to invalid value */ + digit = radix; + } + + if (digit >= radix) + { + break; + } + + value *= radix; + value += digit; + + str_p++; + } + + /* 12. */ + if (str_p == digit_start_p) + { + return ecma_make_nan_value (); + } + + /* 15. */ + if (sign) + { + value *= ECMA_NUMBER_MINUS_ONE; + } + + return ecma_make_number_value (value); +} /* ecma_number_parse_int */ + +/** + * The Number object's 'parseFloat' routine + * + * See also: + * ECMA-262 v5, 15.1.2.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_number_parse_float (const lit_utf8_byte_t *str_p, /**< routine's first argument's + * string buffer */ + lit_utf8_size_t str_size) /**< routine's first argument's + * string buffer's size */ +{ + /* 2. Remove leading whitespace. */ + ecma_string_trim_helper (&str_p, &str_size); + + const lit_utf8_byte_t *str_end_p = str_p + str_size; + bool sign = false; + + if (str_size == 0) + { + return ecma_make_nan_value (); + } + + if (*str_p == LIT_CHAR_PLUS) + { + str_p++; + } + else if (*str_p == LIT_CHAR_MINUS) + { + sign = true; + str_p++; + } + + /* Check if string is equal to "Infinity". */ + const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL); + const lit_utf8_size_t infinity_length = lit_get_magic_string_size (LIT_MAGIC_STRING_INFINITY_UL); + + /* The input string should be at least the length of "Infinity" to be correctly processed as + * the infinity value. + */ + if ((lit_utf8_size_t) (str_end_p - str_p) >= infinity_length && memcmp (infinity_str_p, str_p, infinity_length) == 0) + { + return ecma_make_number_value (ecma_number_make_infinity (sign)); + } + + const lit_utf8_byte_t *num_start_p = str_p; + const lit_utf8_byte_t *num_end_p = str_p; + + while (str_p < str_end_p && lit_char_is_decimal_digit (*str_p)) + { + str_p++; + } + + if (str_p < str_end_p && *str_p == LIT_CHAR_DOT) + { + str_p++; + + while (str_p < str_end_p && lit_char_is_decimal_digit (*str_p)) + { + str_p++; + } + } + + num_end_p = str_p; + + if (str_p < str_end_p && LEXER_TO_ASCII_LOWERCASE (*str_p) == LIT_CHAR_LOWERCASE_E) + { + str_p++; + + if (str_p < str_end_p && (*str_p == LIT_CHAR_PLUS || *str_p == LIT_CHAR_MINUS)) + { + str_p++; + } + + if (str_p < str_end_p && lit_char_is_decimal_digit (*str_p)) + { + str_p++; + + while (str_p < str_end_p && lit_char_is_decimal_digit (*str_p)) + { + str_p++; + } + + num_end_p = str_p; + } + } + + lit_utf8_size_t num_size = (lit_utf8_size_t) (num_end_p - num_start_p); + + if (num_size == 0) + { + return ecma_make_nan_value (); + } + + /* 5. */ + ecma_number_t ret_num = ecma_utf8_string_to_number (num_start_p, num_size, 0); + + if (sign) + { + ret_num *= ECMA_NUMBER_MINUS_ONE; + } + + return ecma_make_number_value (ret_num); +} /* ecma_number_parse_float */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h new file mode 100644 index 0000000..19ac8b5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-number.h @@ -0,0 +1,245 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_HELPERS_NUMBER_H +#define ECMA_HELPERS_NUMBER_H + +#include "ecma-globals.h" + +#include "jerry-config.h" + +/** + * Binary representation of an ecma-number + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +typedef uint64_t ecma_binary_num_t; +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +typedef uint32_t ecma_binary_num_t; +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Makes it possible to read/write the binary representation of an ecma_number_t + * without strict aliasing rule violation. + */ +typedef union +{ + ecma_number_t as_number; /**< ecma-number */ + ecma_binary_num_t as_binary; /**< binary representation */ +} ecma_number_accessor_t; + +ecma_binary_num_t ecma_number_to_binary (ecma_number_t number); +ecma_number_t ecma_number_from_binary (ecma_binary_num_t binary); + +bool ecma_number_sign (ecma_binary_num_t binary); +uint32_t ecma_number_biased_exp (ecma_binary_num_t binary); +uint64_t ecma_number_fraction (ecma_binary_num_t binary); +ecma_number_t ecma_number_create (bool sign, uint32_t biased_exp, uint64_t fraction); + +/** + * Maximum number of significant decimal digits that an ecma-number can store + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_MAX_DIGITS (19) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_MAX_DIGITS (9) +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Width of sign field + * + * See also: + * IEEE-754 2008, 3.6, Table 3.5 + */ +#define ECMA_NUMBER_SIGN_WIDTH (1) + +/** + * Width of biased exponent field + * + * See also: + * IEEE-754 2008, 3.6, Table 3.5 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_BIASED_EXP_WIDTH (11) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_BIASED_EXP_WIDTH (8) +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Exponent bias + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_EXPONENT_BIAS (1023) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_EXPONENT_BIAS (127) +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Width of fraction field + * + * See also: + * IEEE-754 2008, 3.6, Table 3.5 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_FRACTION_WIDTH (52) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_FRACTION_WIDTH (23) +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Sign bit in ecma-numbers + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_SIGN_BIT 0x8000000000000000ull +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_SIGN_BIT 0x7f800000u +#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Binary representation of an IEEE-754 QNaN value. + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_BINARY_QNAN 0x7ff8000000000000ull +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_BINARY_QNAN 0x7fc00000u +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Binary representation of an IEEE-754 Infinity value. + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_BINARY_INF 0x7ff0000000000000ull +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_BINARY_INF 0x7f800000u +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Binary representation of an IEEE-754 zero value. + */ +#define ECMA_NUMBER_BINARY_ZERO 0x0ull + +/** + * Number.MIN_VALUE (i.e., the smallest positive value of ecma-number) + * + * See also: ECMA_262 v5, 15.7.3.3 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_MIN_VALUE ((ecma_number_t) 5e-324) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_MIN_VALUE (FLT_MIN) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Number.MAX_VALUE (i.e., the maximum value of ecma-number) + * + * See also: ECMA_262 v5, 15.7.3.2 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_MAX_VALUE ((ecma_number_t) 1.7976931348623157e+308) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_MAX_VALUE (FLT_MAX) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Number.EPSILON + * + * See also: ECMA_262 v6, 20.1.2.1 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_EPSILON ((ecma_number_t) 2.2204460492503130808472633361816e-16) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_EPSILON ((ecma_number_t) 1.1920928955078125e-7) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Number.MAX_SAFE_INTEGER + * + * See also: ECMA_262 v6, 20.1.2.6 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0x1FFFFFFFFFFFFF) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0xFFFFFF) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Number.MIN_SAFE_INTEGER + * + * See also: ECMA_262 v6, 20.1.2.8 + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0x1FFFFFFFFFFFFF) +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0xFFFFFF) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Number.MAX_VALUE exponent part + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define NUMBER_MAX_DECIMAL_EXPONENT 308 +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define NUMBER_MAX_DECIMAL_EXPONENT 38 +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Number.MIN_VALUE exponent part + */ +#if JERRY_NUMBER_TYPE_FLOAT64 +#define NUMBER_MIN_DECIMAL_EXPONENT -324 +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +#define NUMBER_MIN_DECIMAL_EXPONENT -45 +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Euler number + */ +#define ECMA_NUMBER_E ((ecma_number_t) 2.7182818284590452354) + +/** + * Natural logarithm of 10 + */ +#define ECMA_NUMBER_LN10 ((ecma_number_t) 2.302585092994046) + +/** + * Natural logarithm of 2 + */ +#define ECMA_NUMBER_LN2 ((ecma_number_t) 0.6931471805599453) + +/** + * Logarithm base 2 of the Euler number + */ +#define ECMA_NUMBER_LOG2E ((ecma_number_t) 1.4426950408889634) + +/** + * Logarithm base 10 of the Euler number + */ +#define ECMA_NUMBER_LOG10E ((ecma_number_t) 0.4342944819032518) + +/** + * Pi number + */ +#define ECMA_NUMBER_PI ((ecma_number_t) 3.1415926535897932) + +/** + * Square root of 0.5 + */ +#define ECMA_NUMBER_SQRT_1_2 ((ecma_number_t) 0.7071067811865476) + +/** + * Square root of 2 + */ +#define ECMA_NUMBER_SQRT2 ((ecma_number_t) 1.4142135623730951) + +#endif /* !ECMA_HELPERS_NUMBER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-string.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-string.cpp new file mode 100644 index 0000000..8bfed7e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-string.cpp @@ -0,0 +1,2775 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" + +#include "jcontext.h" +#include "jrt-libc-includes.h" +#include "jrt.h" +#include "lit-char-helpers.h" +#include "lit-magic-strings.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +JERRY_STATIC_ASSERT ((((int)ECMA_STRING_CONTAINER_MASK) >= ((int)ECMA_STRING_CONTAINER__MAX)), + ecma_string_container_types_must_be_lower_than_the_container_mask); + +JERRY_STATIC_ASSERT (((ECMA_STRING_MAX_REF | ECMA_STRING_CONTAINER_MASK | ECMA_STATIC_STRING_FLAG) == UINT32_MAX), + ecma_string_ref_and_container_fields_should_fill_the_32_bit_field); + +JERRY_STATIC_ASSERT (((uint32_t)ECMA_STRING_NOT_ARRAY_INDEX == UINT32_MAX), + ecma_string_not_array_index_must_be_equal_to_uint32_max); + +JERRY_STATIC_ASSERT ((ECMA_TYPE_DIRECT_STRING & 0x1) != 0, ecma_type_direct_string_must_be_odd_number); + +JERRY_STATIC_ASSERT ((((int)LIT_MAGIC_STRING__COUNT) <= ((int)ECMA_DIRECT_STRING_MAX_IMM)), + all_magic_strings_must_be_encoded_as_direct_string); + +JERRY_STATIC_ASSERT (((int) ECMA_DIRECT_STRING_UINT == (int) ECMA_STRING_CONTAINER_UINT32_IN_DESC), + ecma_direct_and_container_types_must_match); + +JERRY_STATIC_ASSERT ((((int)ECMA_PROPERTY_NAME_TYPE_SHIFT) > ((int)ECMA_VALUE_SHIFT)), + ecma_property_name_type_shift_must_be_greater_than_ecma_value_shift); + +JERRY_STATIC_ASSERT ((sizeof (ecma_stringbuilder_header_t) <= ECMA_ASCII_STRING_HEADER_SIZE), + ecma_stringbuilder_header_must_not_be_larger_than_ecma_ascii_string); + +/** + * Convert a string to an unsigned 32 bit value if possible + * + * @return true if the conversion is successful + * false otherwise + */ +static bool +ecma_string_to_array_index (const lit_utf8_byte_t *string_p, /**< utf-8 string */ + lit_utf8_size_t string_size, /**< string size */ + uint32_t *result_p) /**< [out] converted value */ +{ + JERRY_ASSERT (string_size > 0 && *string_p >= LIT_CHAR_0 && *string_p <= LIT_CHAR_9); + + if (*string_p == LIT_CHAR_0) + { + *result_p = 0; + return (string_size == 1); + } + + if (string_size > ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32) + { + return false; + } + + uint32_t index = 0; + const lit_utf8_byte_t *string_end_p = string_p + string_size; + + if (string_size == ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32) + { + string_end_p--; + } + + do + { + if (*string_p > LIT_CHAR_9 || *string_p < LIT_CHAR_0) + { + return false; + } + + index = (index * 10) + (uint32_t) (*string_p++ - LIT_CHAR_0); + } while (string_p < string_end_p); + + if (string_size < ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32) + { + *result_p = index; + return true; + } + + /* Overflow must be checked as well when size is + * equal to ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32. */ + if (*string_p > LIT_CHAR_9 || *string_p < LIT_CHAR_0 || index > (UINT32_MAX / 10) + || (index == (UINT32_MAX / 10) && *string_p > LIT_CHAR_5)) + { + return false; + } + + *result_p = (index * 10) + (uint32_t) (*string_p - LIT_CHAR_0); + return true; +} /* ecma_string_to_array_index */ + +/** + * Returns the characters and size of a string. + * + * Note: + * UINT type is not supported + * + * @return byte array start - if the byte array of a string is available + * NULL - otherwise + */ +static const lit_utf8_byte_t * +ecma_string_get_chars_fast (const ecma_string_t *string_p, /**< ecma-string */ + lit_utf8_size_t *size_p) /**< [out] size of the ecma string */ +{ + if (ECMA_IS_DIRECT_STRING (string_p)) + { + if (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_MAGIC) + { + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + + if (id >= LIT_MAGIC_STRING__COUNT) + { + id -= LIT_MAGIC_STRING__COUNT; + + *size_p = lit_get_magic_string_ex_size (id); + return lit_get_magic_string_ex_utf8 (id); + } + + *size_p = lit_get_magic_string_size (id); + return lit_get_magic_string_utf8 (id); + } + } + + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + switch (ECMA_STRING_GET_CONTAINER (string_p)) + { + case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING: + { + *size_p = ((ecma_short_string_t *) string_p)->size; + return ECMA_SHORT_STRING_GET_BUFFER (string_p); + } + case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING: + { + ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p; + *size_p = long_string_p->size; + return long_string_p->string_p; + } + case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING: + { + *size_p = ECMA_ASCII_STRING_GET_SIZE (string_p); + return ECMA_ASCII_STRING_GET_BUFFER (string_p); + } + default: + { + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + lit_magic_string_ex_id_t id = LIT_MAGIC_STRING__COUNT - string_p->u.magic_string_ex_id; + *size_p = lit_get_magic_string_ex_size (id); + return lit_get_magic_string_ex_utf8 (id); + } + } +} /* ecma_string_get_chars_fast */ + +/** + * Allocate new ecma-string and fill it with reference to ECMA magic string + * + * @return pointer to ecma-string descriptor + */ +static ecma_string_t * +ecma_new_ecma_string_from_magic_string_ex_id (lit_magic_string_ex_id_t id) /**< identifier of external magic string */ +{ + JERRY_ASSERT (id < lit_get_magic_string_ex_count ()); + + uintptr_t string_id = (uintptr_t) (id + LIT_MAGIC_STRING__COUNT); + + if (JERRY_LIKELY (string_id <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_MAGIC, string_id); + } + + ecma_string_t *string_desc_p = ecma_alloc_string (); + + string_desc_p->refs_and_container = ECMA_STRING_CONTAINER_MAGIC_STRING_EX | ECMA_STRING_REF_ONE; + string_desc_p->u.magic_string_ex_id = id + LIT_MAGIC_STRING__COUNT; + + return string_desc_p; +} /* ecma_new_ecma_string_from_magic_string_ex_id */ + +/** + * Allocate new ecma-string and fill it with reference to the symbol descriptor + * + * Note: + * Takes the reference to the string_desc + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc) /**< ecma-string */ +{ + JERRY_ASSERT (!ecma_is_value_symbol (string_desc)); + + ecma_extended_string_t *symbol_p = ecma_alloc_extended_string (); + symbol_p->header.refs_and_container = ECMA_STRING_REF_ONE | ECMA_STRING_CONTAINER_SYMBOL; + symbol_p->u.symbol_descriptor = string_desc; + symbol_p->header.u.hash = (lit_string_hash_t) (((uintptr_t) symbol_p) & (uintptr_t) ~ECMA_SYMBOL_FLAGS_MASK); + + return (ecma_string_t *) symbol_p; +} /* ecma_new_symbol_from_descriptor_string */ + +/** + * Check whether an ecma-string contains an ecma-symbol + * + * @return true - if the ecma-string contains an ecma-symbol + * false - otherwise + */ +bool +ecma_prop_name_is_symbol (ecma_string_t *string_p) /**< ecma-string */ +{ + JERRY_ASSERT (string_p != NULL); + + return (!ECMA_IS_DIRECT_STRING (string_p) && ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_SYMBOL); +} /* ecma_prop_name_is_symbol */ + +/** + * Allocate new UTF8 ecma-string and fill it with characters from the given utf8 buffer + * + * @return pointer to ecma-string descriptor + */ +static inline ecma_string_t * +ecma_new_ecma_string_from_utf8_buffer (lit_utf8_size_t length, /**< length of the buffer */ + lit_utf8_size_t size, /**< size of the buffer */ + lit_utf8_byte_t **data_p) /**< [out] pointer to the start of the string buffer */ +{ + if (JERRY_LIKELY (size <= UINT16_MAX)) + { + if (JERRY_LIKELY (length == size) && size <= (UINT8_MAX + 1)) + { + ecma_string_t *string_desc_p; + string_desc_p = (ecma_string_t *) ecma_alloc_string_buffer (size + ECMA_ASCII_STRING_HEADER_SIZE); + string_desc_p->refs_and_container = ECMA_STRING_CONTAINER_HEAP_ASCII_STRING | ECMA_STRING_REF_ONE; + ECMA_ASCII_STRING_SET_SIZE (string_desc_p, size); + + *data_p = ECMA_ASCII_STRING_GET_BUFFER (string_desc_p); + return (ecma_string_t *) string_desc_p; + } + + ecma_short_string_t *string_desc_p; + string_desc_p = (ecma_short_string_t *) ecma_alloc_string_buffer (size + sizeof (ecma_short_string_t)); + string_desc_p->header.refs_and_container = ECMA_STRING_CONTAINER_HEAP_UTF8_STRING | ECMA_STRING_REF_ONE; + string_desc_p->size = (uint16_t) size; + string_desc_p->length = (uint16_t) length; + + *data_p = ECMA_SHORT_STRING_GET_BUFFER (string_desc_p); + return (ecma_string_t *) string_desc_p; + } + + ecma_long_string_t *long_string_p; + long_string_p = (ecma_long_string_t *) ecma_alloc_string_buffer (size + sizeof (ecma_long_string_t)); + long_string_p->header.refs_and_container = ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING | ECMA_STRING_REF_ONE; + long_string_p->string_p = ECMA_LONG_STRING_BUFFER_START (long_string_p); + long_string_p->size = size; + long_string_p->length = length; + + *data_p = ECMA_LONG_STRING_BUFFER_START (long_string_p); + return (ecma_string_t *) long_string_p; +} /* ecma_new_ecma_string_from_utf8_buffer */ + +/** + * Checks whether a string has a special representation, that is, the string is either a magic string, + * an external magic string, or an uint32 number, and creates an ecma string using the special representation, + * if available. + * + * @return pointer to ecma string with the special representation + * NULL, if there is no special representation for the string + */ +static ecma_string_t * +ecma_find_special_string (const lit_utf8_byte_t *string_p, /**< utf8 string */ + lit_utf8_size_t string_size) /**< string size */ +{ + JERRY_ASSERT (string_p != NULL || string_size == 0); + lit_magic_string_id_t magic_string_id = lit_is_utf8_string_magic (string_p, string_size); + + if (magic_string_id != LIT_MAGIC_STRING__COUNT) + { + return ecma_get_magic_string (magic_string_id); + } + + JERRY_ASSERT (string_size > 0); + + if (*string_p >= LIT_CHAR_0 && *string_p <= LIT_CHAR_9) + { + uint32_t array_index; + + if (ecma_string_to_array_index (string_p, string_size, &array_index)) + { + return ecma_new_ecma_string_from_uint32 (array_index); + } + } + + if (lit_get_magic_string_ex_count () > 0) + { + lit_magic_string_ex_id_t magic_string_ex_id = lit_is_ex_utf8_string_magic (string_p, string_size); + + if (magic_string_ex_id < lit_get_magic_string_ex_count ()) + { + return ecma_new_ecma_string_from_magic_string_ex_id (magic_string_ex_id); + } + } + + return NULL; +} /* ecma_find_special_string */ + +/** + * Allocate new ecma-string and fill it with characters from ascii characters + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_ascii (const lit_utf8_byte_t *string_p, /**< ascii string */ + lit_utf8_size_t string_size) /**< string size */ +{ + JERRY_ASSERT (string_p != NULL || string_size == 0); + + ecma_string_t *string_desc_p = ecma_find_special_string (string_p, string_size); + + if (string_desc_p != NULL) + { + return string_desc_p; + } + + lit_utf8_byte_t *data_p; + string_desc_p = ecma_new_ecma_string_from_utf8_buffer (string_size, string_size, &data_p); + + string_desc_p->u.hash = lit_utf8_string_calc_hash (string_p, string_size); + memcpy (data_p, string_p, string_size); + + return string_desc_p; +} /* ecma_new_ecma_string_from_ascii */ + +/** + * Allocate new ecma-string and fill it with characters from the utf8 string + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, /**< utf-8 string */ + lit_utf8_size_t string_size) /**< string size */ +{ + JERRY_ASSERT (string_p != NULL || string_size == 0); + JERRY_ASSERT (lit_is_valid_cesu8_string (string_p, string_size)); + + ecma_string_t *string_desc_p = ecma_find_special_string (string_p, string_size); + + if (string_desc_p != NULL) + { + return string_desc_p; + } + + lit_utf8_byte_t *data_p; + string_desc_p = + ecma_new_ecma_string_from_utf8_buffer (lit_utf8_string_length (string_p, string_size), string_size, &data_p); + + string_desc_p->u.hash = lit_utf8_string_calc_hash (string_p, string_size); + memcpy (data_p, string_p, string_size); + + return string_desc_p; +} /* ecma_new_ecma_string_from_utf8 */ + +/** + * Allocate a new ecma-string and initialize it from the utf8 string argument. + * All 4-bytes long unicode sequences are converted into two 3-bytes long sequences. + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p, /**< utf-8 string */ + lit_utf8_size_t string_size) /**< utf-8 string size */ +{ + JERRY_ASSERT (string_p != NULL || string_size == 0); + + lit_utf8_size_t converted_string_length = 0; + lit_utf8_size_t converted_string_size = 0; + lit_utf8_size_t pos = 0; + + /* Calculate the required length and size information of the converted cesu-8 encoded string */ + while (pos < string_size) + { + if ((string_p[pos] & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER) + { + pos++; + } + else if ((string_p[pos] & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER) + { + pos += 2; + } + else if ((string_p[pos] & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER) + { + pos += 3; + } + else + { + JERRY_ASSERT ((string_p[pos] & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER); + pos += 4; + converted_string_size += 2; + converted_string_length++; + } + + converted_string_length++; + } + + JERRY_ASSERT (pos == string_size); + + if (converted_string_size == 0) + { + return ecma_new_ecma_string_from_utf8 (string_p, string_size); + } + + converted_string_size += string_size; + + JERRY_ASSERT (lit_is_valid_utf8_string (string_p, string_size, false)); + + lit_utf8_byte_t *data_p; + ecma_string_t *string_desc_p = + ecma_new_ecma_string_from_utf8_buffer (converted_string_length, converted_string_size, &data_p); + + const lit_utf8_byte_t *const begin_data_p = data_p; + pos = 0; + + while (pos < string_size) + { + if ((string_p[pos] & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER) + { + /* Processing 4 byte unicode sequence. Always converted to two 3 byte long sequence. */ + lit_four_byte_utf8_char_to_cesu8 (data_p, string_p + pos); + data_p += 3 * 2; + pos += 4; + } + else + { + *data_p++ = string_p[pos++]; + } + } + + JERRY_ASSERT (pos == string_size); + + string_desc_p->u.hash = lit_utf8_string_calc_hash (begin_data_p, converted_string_size); + + return (ecma_string_t *) string_desc_p; +} /* ecma_new_ecma_string_from_utf8_converted_to_cesu8 */ + +/** + * Allocate new ecma-external-string and fill it with characters from the cesu8 string + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, /**< cesu-8 string */ + lit_utf8_size_t string_size, /**< string size */ + void *user_p) /**< user pointer passed to the callback + * when the string is freed */ +{ + JERRY_ASSERT (string_p != NULL || string_size == 0); + JERRY_ASSERT (lit_is_valid_cesu8_string (string_p, string_size)); + + if (string_size < (sizeof (ecma_external_string_t) - sizeof (ecma_short_string_t))) + { + /* Normal strings are created for short strings. */ + ecma_string_t *string_desc_p = ecma_new_ecma_string_from_utf8 (string_p, string_size); + + jerry_external_string_free_cb_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); + + if (free_cb != NULL) + { + free_cb ((lit_utf8_byte_t *) string_p, string_size, user_p); + } + return string_desc_p; + } + + ecma_string_t *string_desc_p = ecma_find_special_string (string_p, string_size); + + if (string_desc_p != NULL) + { + jerry_external_string_free_cb_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); + + if (free_cb != NULL) + { + free_cb ((lit_utf8_byte_t *) string_p, string_size, user_p); + } + return string_desc_p; + } + + ecma_external_string_t *external_string_p = ecma_alloc_external_string (); + ecma_long_string_t *long_string_p = (ecma_long_string_t *) external_string_p; + + long_string_p->header.refs_and_container = ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING | ECMA_STRING_REF_ONE; + long_string_p->header.u.hash = lit_utf8_string_calc_hash (string_p, string_size); + long_string_p->string_p = string_p; + long_string_p->size = string_size; + long_string_p->length = lit_utf8_string_length (string_p, string_size); + external_string_p->user_p = user_p; + + return (ecma_string_t *) external_string_p; +} /* ecma_new_ecma_external_string_from_cesu8 */ + +/** + * Allocate new ecma-string and fill it with cesu-8 character which represents specified code unit + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit) /**< code unit */ +{ + lit_utf8_byte_t lit_utf8_bytes[LIT_UTF8_MAX_BYTES_IN_CODE_UNIT]; + lit_utf8_size_t bytes_size = lit_code_unit_to_utf8 (code_unit, lit_utf8_bytes); + + return ecma_new_ecma_string_from_utf8 (lit_utf8_bytes, bytes_size); +} /* ecma_new_ecma_string_from_code_unit */ + +/** + * Allocate new ecma-string and fill it with cesu-8 character which represents specified code units + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, /**< code unit */ + ecma_char_t second_code_unit) /**< code unit */ +{ + lit_utf8_byte_t lit_utf8_bytes[2 * LIT_UTF8_MAX_BYTES_IN_CODE_UNIT]; + lit_utf8_size_t bytes_size = lit_code_unit_to_utf8 (first_code_unit, lit_utf8_bytes); + bytes_size += lit_code_unit_to_utf8 (second_code_unit, lit_utf8_bytes + bytes_size); + + return ecma_new_ecma_string_from_utf8 (lit_utf8_bytes, bytes_size); +} /* ecma_new_ecma_string_from_code_units */ + +/** + * Allocate new ecma-string and fill it with ecma-number + * + * Note: the number cannot be represented as direct string + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of the string */ +{ + JERRY_ASSERT (uint32_number > ECMA_DIRECT_STRING_MAX_IMM); + + ecma_string_t *string_p = ecma_alloc_string (); + + string_p->refs_and_container = ECMA_STRING_CONTAINER_UINT32_IN_DESC | ECMA_STRING_REF_ONE; + string_p->u.uint32_number = uint32_number; + + return string_p; +} /* ecma_new_non_direct_string_from_uint32 */ + +/** + * Allocate new ecma-string and fill it with property length number + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_length (ecma_length_t number) /**< property length */ +{ + if (JERRY_LIKELY (number <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) number); + } + + JERRY_ASSERT ((ecma_number_t) number <= ECMA_NUMBER_MAX_SAFE_INTEGER); + + if (JERRY_UNLIKELY (number > UINT32_MAX)) + { + return ecma_new_ecma_string_from_number ((ecma_number_t) number); + } + + return ecma_new_non_direct_string_from_uint32 ((uint32_t) number); +} /* ecma_new_ecma_string_from_length */ + +/** + * Allocate new ecma-string and fill it with uint32 number + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of the string */ +{ + if (JERRY_LIKELY (uint32_number <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number); + } + + return ecma_new_non_direct_string_from_uint32 (uint32_number); +} /* ecma_new_ecma_string_from_uint32 */ + +/** + * Returns the constant assigned to the uint32 number. + * + * Note: + * Calling ecma_deref_ecma_string on the returned pointer is optional. + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_get_ecma_string_from_uint32 (uint32_t uint32_number) /**< input number */ +{ + JERRY_ASSERT (uint32_number <= ECMA_DIRECT_STRING_MAX_IMM); + + return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number); +} /* ecma_get_ecma_string_from_uint32 */ + +/** + * Allocate new ecma-string and fill it with ecma-number + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */ +{ + uint32_t uint32_num = ecma_number_to_uint32 (num); + if (num == ((ecma_number_t) uint32_num)) + { + return ecma_new_ecma_string_from_uint32 (uint32_num); + } + + if (ecma_number_is_nan (num)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_NAN); + } + + if (ecma_number_is_infinity (num)) + { + lit_magic_string_id_t id = + (ecma_number_is_negative (num) ? LIT_MAGIC_STRING_NEGATIVE_INFINITY_UL : LIT_MAGIC_STRING_INFINITY_UL); + return ecma_get_magic_string (id); + } + + lit_utf8_byte_t str_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; + lit_utf8_size_t str_size = ecma_number_to_utf8_string (num, str_buf, sizeof (str_buf)); + + JERRY_ASSERT (str_size > 0); +#ifndef JERRY_NDEBUG + JERRY_ASSERT (lit_is_utf8_string_magic (str_buf, str_size) == LIT_MAGIC_STRING__COUNT + && lit_is_ex_utf8_string_magic (str_buf, str_size) == lit_get_magic_string_ex_count ()); +#endif /* !JERRY_NDEBUG */ + + lit_utf8_byte_t *data_p; + ecma_string_t *string_desc_p = + ecma_new_ecma_string_from_utf8_buffer (lit_utf8_string_length (str_buf, str_size), str_size, &data_p); + + string_desc_p->u.hash = lit_utf8_string_calc_hash (str_buf, str_size); + memcpy (data_p, str_buf, str_size); + + return string_desc_p; +} /* ecma_new_ecma_string_from_number */ + +/** + * Returns the constant assigned to the magic string id. + * + * Note: + * Calling ecma_deref_ecma_string on the returned pointer is optional. + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_get_magic_string (lit_magic_string_id_t id) /**< identifier of magic string */ +{ + JERRY_ASSERT (id < LIT_MAGIC_STRING__COUNT); + return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_MAGIC, (uintptr_t) id); +} /* ecma_get_magic_string */ + +/** + * Returns the constant assigned to the internal magic string id. + * + * Note: + * Calling ecma_deref_ecma_string on the returned pointer is optional. + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t * +ecma_get_internal_string (lit_magic_string_id_t id) /**< identifier of magic string */ +{ + JERRY_ASSERT (id >= LIT_NON_INTERNAL_MAGIC_STRING__COUNT && id < LIT_MAGIC_STRING__COUNT); + return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_SPECIAL, (uintptr_t) id); +} /* ecma_get_internal_string */ + +/** + * Append a cesu8 string after an ecma-string + * + * Note: + * The string1_p argument is freed. If it needs to be preserved, + * call ecma_ref_ecma_string with string1_p before the call. + * + * @return concatenation of an ecma-string and a cesu8 string + */ +ecma_string_t * +ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */ + const lit_utf8_byte_t *cesu8_string2_p, /**< characters to be appended */ + lit_utf8_size_t cesu8_string2_size, /**< byte size of cesu8_string2_p */ + lit_utf8_size_t cesu8_string2_length) /**< character length of cesu8_string2_p */ +{ + JERRY_ASSERT (string1_p != NULL && cesu8_string2_size > 0 && cesu8_string2_length > 0); + + if (JERRY_UNLIKELY (ecma_string_is_empty (string1_p))) + { + return ecma_new_ecma_string_from_utf8 (cesu8_string2_p, cesu8_string2_size); + } + + lit_utf8_size_t cesu8_string1_size; + lit_utf8_size_t cesu8_string1_length; + uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; + lit_utf8_byte_t uint32_to_string_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + + const lit_utf8_byte_t *cesu8_string1_p = + ecma_string_get_chars (string1_p, &cesu8_string1_size, &cesu8_string1_length, uint32_to_string_buffer, &flags); + + JERRY_ASSERT (!(flags & ECMA_STRING_FLAG_MUST_BE_FREED)); + JERRY_ASSERT (cesu8_string1_length > 0); + JERRY_ASSERT (cesu8_string1_length <= cesu8_string1_size); + + lit_utf8_size_t new_size = cesu8_string1_size + cesu8_string2_size; + + /* Poor man's carry flag check: it is impossible to allocate this large string. */ + if (new_size < (cesu8_string1_size | cesu8_string2_size)) + { + jerry_fatal (JERRY_FATAL_OUT_OF_MEMORY); + } + + lit_magic_string_id_t magic_string_id; + magic_string_id = + lit_is_utf8_string_pair_magic (cesu8_string1_p, cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + + if (magic_string_id != LIT_MAGIC_STRING__COUNT) + { + ecma_deref_ecma_string (string1_p); + return ecma_get_magic_string (magic_string_id); + } + + if ((flags & ECMA_STRING_FLAG_IS_UINT32) && new_size <= ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32) + { + memcpy (uint32_to_string_buffer + cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + + uint32_t array_index; + + if (ecma_string_to_array_index (uint32_to_string_buffer, new_size, &array_index)) + { + ecma_deref_ecma_string (string1_p); + return ecma_new_ecma_string_from_uint32 (array_index); + } + } + + if (lit_get_magic_string_ex_count () > 0) + { + lit_magic_string_ex_id_t magic_string_ex_id; + magic_string_ex_id = + lit_is_ex_utf8_string_pair_magic (cesu8_string1_p, cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + + if (magic_string_ex_id < lit_get_magic_string_ex_count ()) + { + ecma_deref_ecma_string (string1_p); + return ecma_new_ecma_string_from_magic_string_ex_id (magic_string_ex_id); + } + } + + lit_utf8_byte_t *data_p; + ecma_string_t *string_desc_p = + ecma_new_ecma_string_from_utf8_buffer (cesu8_string1_length + cesu8_string2_length, new_size, &data_p); + + lit_string_hash_t hash_start; + + if (JERRY_UNLIKELY (flags & ECMA_STRING_FLAG_REHASH_NEEDED)) + { + hash_start = lit_utf8_string_calc_hash (cesu8_string1_p, cesu8_string1_size); + } + else + { + JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string1_p)); + hash_start = string1_p->u.hash; + } + + string_desc_p->u.hash = lit_utf8_string_hash_combine (hash_start, cesu8_string2_p, cesu8_string2_size); + + memcpy (data_p, cesu8_string1_p, cesu8_string1_size); + memcpy (data_p + cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + + ecma_deref_ecma_string (string1_p); + return (ecma_string_t *) string_desc_p; +} /* ecma_append_chars_to_string */ + +/** + * Concatenate ecma-strings + * + * Note: + * The string1_p argument is freed. If it needs to be preserved, + * call ecma_ref_ecma_string with string1_p before the call. + * + * @return concatenation of two ecma-strings + */ +ecma_string_t * +ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */ + ecma_string_t *string2_p) /**< second ecma-string */ +{ + JERRY_ASSERT (string1_p != NULL && string2_p != NULL); + + if (JERRY_UNLIKELY (ecma_string_is_empty (string1_p))) + { + ecma_ref_ecma_string (string2_p); + return string2_p; + } + else if (JERRY_UNLIKELY (ecma_string_is_empty (string2_p))) + { + return string1_p; + } + + lit_utf8_size_t cesu8_string2_size; + lit_utf8_size_t cesu8_string2_length; + lit_utf8_byte_t uint32_to_string_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; + + const lit_utf8_byte_t *cesu8_string2_p = + ecma_string_get_chars (string2_p, &cesu8_string2_size, &cesu8_string2_length, uint32_to_string_buffer, &flags); + + JERRY_ASSERT (cesu8_string2_p != NULL); + + ecma_string_t *result_p = + ecma_append_chars_to_string (string1_p, cesu8_string2_p, cesu8_string2_size, cesu8_string2_length); + + JERRY_ASSERT (!(flags & ECMA_STRING_FLAG_MUST_BE_FREED)); + + return result_p; +} /* ecma_concat_ecma_strings */ + +/** + * Increase reference counter of non-direct ecma-string. + * + * @return void + */ +void +ecma_ref_ecma_string_non_direct (ecma_string_t *string_p) /**< string descriptor */ +{ + JERRY_ASSERT (string_p != NULL); + JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p)); + +#ifdef JERRY_NDEBUG + if (ECMA_STRING_IS_STATIC (string_p)) + { + return; + } +#endif /* JERRY_NDEBUG */ + + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + if (JERRY_LIKELY (string_p->refs_and_container < ECMA_STRING_MAX_REF)) + { + /* Increase reference counter. */ + string_p->refs_and_container += ECMA_STRING_REF_ONE; + } + else + { + jerry_fatal (JERRY_FATAL_REF_COUNT_LIMIT); + } +} /* ecma_ref_ecma_string_non_direct */ + +/** + * Increase reference counter of ecma-string. + */ +void +ecma_ref_ecma_string (ecma_string_t *string_p) /**< string descriptor */ +{ + JERRY_ASSERT (string_p != NULL); + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + return; + } + + ecma_ref_ecma_string_non_direct (string_p); +} /* ecma_ref_ecma_string */ + +/** + * Decrease reference counter and deallocate a non-direct ecma-string + * if the counter becomes zero. + * + * @return void + */ +void +ecma_deref_ecma_string_non_direct (ecma_string_t *string_p) /**< ecma-string */ +{ + JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p)); + +#ifdef JERRY_NDEBUG + if (ECMA_STRING_IS_STATIC (string_p)) + { + return; + } +#endif /* JERRY_NDEBUG */ + + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + /* Decrease reference counter. */ + string_p->refs_and_container -= ECMA_STRING_REF_ONE; + + if (string_p->refs_and_container >= ECMA_STRING_REF_ONE) + { + return; + } + + ecma_destroy_ecma_string (string_p); +} /* ecma_deref_ecma_string_non_direct */ + +/** + * Decrease reference counter and deallocate ecma-string + * if the counter becomes zero. + */ +void +ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */ +{ + JERRY_ASSERT (string_p != NULL); + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + return; + } + + ecma_deref_ecma_string_non_direct (string_p); +} /* ecma_deref_ecma_string */ + +/** + * Deallocate an ecma-string + */ +void +ecma_destroy_ecma_string (ecma_string_t *string_p) /**< ecma-string */ +{ + JERRY_ASSERT (string_p != NULL); + JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p)); + JERRY_ASSERT ((string_p->refs_and_container < ECMA_STRING_REF_ONE) || ECMA_STRING_IS_STATIC (string_p)); + + switch (ECMA_STRING_GET_CONTAINER (string_p)) + { + case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING: + { + ecma_dealloc_string_buffer (string_p, ((ecma_short_string_t *) string_p)->size + sizeof (ecma_short_string_t)); + return; + } + case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING: + { + ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p; + + if (long_string_p->string_p == ECMA_LONG_STRING_BUFFER_START (long_string_p)) + { + ecma_dealloc_string_buffer (string_p, long_string_p->size + sizeof (ecma_long_string_t)); + return; + } + + ecma_external_string_t *external_string_p = (ecma_external_string_t *) string_p; + jerry_external_string_free_cb_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); + + if (free_cb != NULL) + { + free_cb ((lit_utf8_byte_t *) external_string_p->header.string_p, + external_string_p->header.size, + external_string_p->user_p); + } + + ecma_dealloc_external_string (external_string_p); + return; + } + case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING: + { + ecma_dealloc_string_buffer (string_p, ECMA_ASCII_STRING_GET_SIZE (string_p) + ECMA_ASCII_STRING_HEADER_SIZE); + return; + } + case ECMA_STRING_CONTAINER_SYMBOL: + { + ecma_extended_string_t *symbol_p = (ecma_extended_string_t *) string_p; + ecma_free_value (symbol_p->u.symbol_descriptor); + ecma_dealloc_extended_string (symbol_p); + return; + } + default: + { + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC + || ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + /* only the string descriptor itself should be freed */ + ecma_dealloc_string (string_p); + } + } +} /* ecma_destroy_ecma_string */ + +/** + * Convert ecma-string to number + * + * @return converted ecma-number + */ +ecma_number_t +ecma_string_to_number (const ecma_string_t *string_p) /**< ecma-string */ +{ + JERRY_ASSERT (string_p != NULL); + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + if (ECMA_IS_DIRECT_STRING_WITH_TYPE (string_p, ECMA_DIRECT_STRING_UINT)) + { + return (ecma_number_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + } + } + else if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + return ((ecma_number_t) string_p->u.uint32_number); + } + + lit_utf8_size_t size; + const lit_utf8_byte_t *chars_p = ecma_string_get_chars_fast (string_p, &size); + + JERRY_ASSERT (chars_p != NULL); + + if (size == 0) + { + return ECMA_NUMBER_ZERO; + } + + return ecma_utf8_string_to_number (chars_p, size, 0); +} /* ecma_string_to_number */ + +/** + * Check if string is array index. + * + * @return ECMA_STRING_NOT_ARRAY_INDEX if string is not array index + * the array index otherwise + */ +uint32_t +ecma_string_get_array_index (const ecma_string_t *str_p) /**< ecma-string */ +{ + if (ECMA_IS_DIRECT_STRING (str_p)) + { + if (ECMA_IS_DIRECT_STRING_WITH_TYPE (str_p, ECMA_DIRECT_STRING_UINT)) + { + /* Value cannot be equal to the maximum value of a 32 bit unsigned number. */ + return (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (str_p); + } + + return ECMA_STRING_NOT_ARRAY_INDEX; + } + + if (ECMA_STRING_GET_CONTAINER (str_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + /* When the uint32_number is equal to the maximum value of 32 bit unsigned integer number, + * it is also an invalid array index. The comparison to ECMA_STRING_NOT_ARRAY_INDEX will + * be true in this case. */ + return str_p->u.uint32_number; + } + + return ECMA_STRING_NOT_ARRAY_INDEX; +} /* ecma_string_get_array_index */ + +/** + * Copy digits of uint32 number, truncating if buffer is not large enough. + * + * @return number of digits copied + */ +static lit_utf8_size_t +ecma_uint32_to_buffer (uint32_t num, /**< number */ + lit_utf8_byte_t *buffer_p /**< destination buffer */, + lit_utf8_size_t buffer_size /**< buffer size */) +{ + lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + lit_utf8_size_t digit_count = ecma_uint32_to_utf8_string (num, digits, ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + + digit_count = JERRY_MIN (buffer_size, digit_count); + memcpy (buffer_p, digits, digit_count); + return digit_count; +} /* ecma_uint32_to_buffer */ + +/** + * Convert ecma-string's contents to the specified encoding and copy it to the buffer. + * String data will be truncated to fit the buffer. + * + * @return number of bytes copied to the buffer. + */ +lit_utf8_size_t +ecma_string_copy_to_buffer (const ecma_string_t *string_p, /**< ecma-string descriptor */ + lit_utf8_byte_t *buffer_p, /**< destination buffer pointer + * (can be NULL if buffer_size == 0) */ + lit_utf8_size_t buffer_size, /**< size of buffer */ + jerry_encoding_t encoding) /**< encoding */ +{ + if (ECMA_IS_DIRECT_STRING (string_p)) + { + if (ECMA_IS_DIRECT_STRING_WITH_TYPE (string_p, ECMA_DIRECT_STRING_UINT)) + { + return ecma_uint32_to_buffer ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p), buffer_p, buffer_size); + } + } + else + { + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + return ecma_uint32_to_buffer (string_p->u.uint32_number, buffer_p, buffer_size); + } + } + + lit_utf8_size_t string_size; + const lit_utf8_byte_t *chars_p = ecma_string_get_chars_fast (string_p, &string_size); + lit_utf8_size_t copy_size = 0; + + JERRY_ASSERT (chars_p != NULL); + + switch (encoding) + { + case JERRY_ENCODING_CESU8: + { + copy_size = JERRY_MIN (string_size, buffer_size); + + if (copy_size < string_size) + { + /* Do not copy partial characters */ + while ((chars_p[copy_size] & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER) + { + copy_size--; + } + } + + memcpy (buffer_p, chars_p, copy_size); + break; + } + case JERRY_ENCODING_UTF8: + { + if (string_size == ecma_string_get_length (string_p)) + { + copy_size = JERRY_MIN (string_size, buffer_size); + + memcpy (buffer_p, chars_p, copy_size); + break; + } + + copy_size = lit_convert_cesu8_string_to_utf8_string (chars_p, string_size, buffer_p, buffer_size); + break; + } + default: + { + break; + } + } + + return copy_size; +} /* ecma_string_copy_to_buffer */ + +/** + * Convert ecma-string's contents to a cesu-8 string and put it to the buffer. + * It is the caller's responsibility to make sure that the string fits in the buffer. + * Check if the size of the string is equal with the size of the buffer. + * + * @return void + */ +void +ecma_string_to_cesu8_bytes (const ecma_string_t *string_desc_p, /**< ecma-string descriptor */ + lit_utf8_byte_t *buffer_p, /**< destination buffer pointer (can be NULL if buffer_size == 0) */ + lit_utf8_size_t buffer_size) /**< size of buffer */ +{ + ecma_string_copy_to_buffer (string_desc_p, buffer_p, buffer_size, JERRY_ENCODING_CESU8); +} + +/** + * Get size of the uint32 number stored locally in the string's descriptor + * + * Note: the represented number size and length are equal + * + * @return size in bytes + */ +static inline lit_utf8_size_t +ecma_string_get_uint32_size (const uint32_t uint32_number) /**< number in the string-descriptor */ +{ + uint32_t prev_number = 1; + uint32_t next_number = 100; + lit_utf8_size_t size = 1; + + const uint32_t max_size = 9; + + while (size < max_size && uint32_number >= next_number) + { + prev_number = next_number; + next_number *= 100; + size += 2; + } + + if (uint32_number >= prev_number * 10) + { + size++; + } + + return size; +} /* ecma_string_get_uint32_size */ + +/** + * Checks whether the given string is a sequence of ascii characters. + */ +#define ECMA_STRING_IS_ASCII(char_p, size) ((size) == lit_utf8_string_length ((char_p), (size))) + +/** + * Returns with the cesu8 character array of a string. + * + * Note: + * - This function returns with a newly allocated buffer for uint32 strings, + * which must be freed if the optional uint32_buff_p parameter is NULL. + * - The ASCII check only happens if the flags parameter gets + * 'ECMA_STRING_FLAG_IS_ASCII' as an input. + * + * @return start of cesu8 characters + */ +const lit_utf8_byte_t * +ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */ + lit_utf8_size_t *size_p, /**< [out] size of the ecma string */ + lit_utf8_size_t *length_p, /**< [out] optional argument. If the pointer is not NULL the pointed + * memory area is filled with the length of the ecma string */ + lit_utf8_byte_t *uint32_buff_p, /**< [out] optional argument. If the pointer is not NULL the + * pointed memory area is filled with the string converted + * uint32 string descriptor */ + uint8_t *flags_p) /**< [in,out] any combination of ecma_string_flag_t bits */ +{ + lit_utf8_size_t length; + lit_utf8_size_t size; + const lit_utf8_byte_t *result_p; + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + *flags_p |= ECMA_STRING_FLAG_REHASH_NEEDED; + + switch (ECMA_GET_DIRECT_STRING_TYPE (string_p)) + { + case ECMA_DIRECT_STRING_MAGIC: + { + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + + if (id >= LIT_MAGIC_STRING__COUNT) + { + id -= LIT_MAGIC_STRING__COUNT; + size = lit_get_magic_string_ex_size (id); + result_p = lit_get_magic_string_ex_utf8 (id); + length = 0; + + if (JERRY_UNLIKELY (*flags_p & ECMA_STRING_FLAG_IS_ASCII)) + { + length = lit_utf8_string_length (result_p, size); + } + } + else + { + size = lit_get_magic_string_size (id); + length = size; + + result_p = lit_get_magic_string_utf8 (id); + + /* All magic strings must be ascii strings. */ + JERRY_ASSERT (ECMA_STRING_IS_ASCII (result_p, size)); + } + break; + } + default: + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_UINT); + uint32_t uint32_number = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + size = (lit_utf8_size_t) ecma_string_get_uint32_size (uint32_number); + + if (uint32_buff_p != NULL) + { + result_p = uint32_buff_p; + } + else + { + result_p = (const lit_utf8_byte_t *) jmem_heap_alloc_block (size); + *flags_p |= ECMA_STRING_FLAG_MUST_BE_FREED; + } + + length = ecma_uint32_to_utf8_string (uint32_number, (lit_utf8_byte_t *) result_p, size); + + JERRY_ASSERT (length == size); + *flags_p |= ECMA_STRING_FLAG_IS_UINT32; + break; + } + } + } + else + { + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + switch (ECMA_STRING_GET_CONTAINER (string_p)) + { + case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING: + { + ecma_short_string_t *short_string_p = (ecma_short_string_t *) string_p; + size = short_string_p->size; + length = short_string_p->length; + result_p = ECMA_SHORT_STRING_GET_BUFFER (short_string_p); + break; + } + case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING: + { + ecma_long_string_t *long_string_desc_p = (ecma_long_string_t *) string_p; + size = long_string_desc_p->size; + length = long_string_desc_p->length; + result_p = long_string_desc_p->string_p; + break; + } + case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING: + { + size = ECMA_ASCII_STRING_GET_SIZE (string_p); + length = size; + result_p = ECMA_ASCII_STRING_GET_BUFFER (string_p); + break; + } + case ECMA_STRING_CONTAINER_UINT32_IN_DESC: + { + size = (lit_utf8_size_t) ecma_string_get_uint32_size (string_p->u.uint32_number); + + if (uint32_buff_p != NULL) + { + result_p = uint32_buff_p; + } + else + { + result_p = (const lit_utf8_byte_t *) jmem_heap_alloc_block (size); + *flags_p |= ECMA_STRING_FLAG_MUST_BE_FREED; + } + + length = ecma_uint32_to_utf8_string (string_p->u.uint32_number, (lit_utf8_byte_t *) result_p, size); + + JERRY_ASSERT (length == size); + *flags_p |= ECMA_STRING_FLAG_IS_UINT32 | ECMA_STRING_FLAG_REHASH_NEEDED; + break; + } + default: + { + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + lit_magic_string_ex_id_t id = LIT_MAGIC_STRING__COUNT - string_p->u.magic_string_ex_id; + size = lit_get_magic_string_ex_size (id); + length = 0; + + if (JERRY_UNLIKELY (*flags_p & ECMA_STRING_FLAG_IS_ASCII)) + { + length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (id), size); + } + + result_p = lit_get_magic_string_ex_utf8 (id); + *flags_p |= ECMA_STRING_FLAG_REHASH_NEEDED; + break; + } + } + } + + *size_p = size; + if (length_p != NULL) + { + *length_p = length; + } + + if ((*flags_p & ECMA_STRING_FLAG_IS_ASCII) && length != size) + { + *flags_p = (uint8_t) (*flags_p & (uint8_t) ~ECMA_STRING_FLAG_IS_ASCII); + } + + return result_p; +} /* ecma_string_get_chars */ + +/** + * Checks whether the string equals to the magic string id. + * + * @return true - if the string equals to the magic string id + * false - otherwise + */ +bool +ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, /**< property name */ + lit_magic_string_id_t id) /**< magic string id */ +{ + return (string_p == ecma_get_magic_string (id)); +} /* ecma_compare_ecma_string_to_magic_id */ + +/** + * Checks whether ecma string is empty or not + * + * @return true - if the string is an empty string + * false - otherwise + */ +bool +ecma_string_is_empty (const ecma_string_t *string_p) /**< ecma-string */ +{ + return ecma_compare_ecma_string_to_magic_id (string_p, LIT_MAGIC_STRING__EMPTY); +} /* ecma_string_is_empty */ + +/** + * Checks whether the string equals to "length". + * + * @return true - if the string equals to "length" + * false - otherwise + */ +bool +ecma_string_is_length (const ecma_string_t *string_p) /**< property name */ +{ + return ecma_compare_ecma_string_to_magic_id (string_p, LIT_MAGIC_STRING_LENGTH); +} /* ecma_string_is_length */ + +/** + * Converts a property name into a string + * + * @return pointer to the converted ecma string + */ +static inline ecma_string_t * +ecma_property_to_string (ecma_property_t property, /**< property name type */ + jmem_cpointer_t prop_name_cp) /**< property name compressed pointer */ +{ + uintptr_t property_string = ((uintptr_t) (property)) & (0x3 << ECMA_PROPERTY_NAME_TYPE_SHIFT); + property_string = (property_string >> ECMA_STRING_TYPE_CONVERSION_SHIFT) | ECMA_TYPE_DIRECT_STRING; + return (ecma_string_t *) (property_string | (((uintptr_t) prop_name_cp) << ECMA_DIRECT_STRING_SHIFT)); +} /* ecma_property_to_string */ + +/** + * Converts a string into a property name + * + * @return the compressed pointer part of the name + */ +jmem_cpointer_t +ecma_string_to_property_name (ecma_string_t *prop_name_p, /**< property name */ + ecma_property_t *name_type_p) /**< [out] property name type */ +{ + if (ECMA_IS_DIRECT_STRING (prop_name_p)) + { + *name_type_p = (ecma_property_t) ECMA_DIRECT_STRING_TYPE_TO_PROP_NAME_TYPE (prop_name_p); + return (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p); + } + + *name_type_p = ECMA_DIRECT_STRING_PTR << ECMA_PROPERTY_NAME_TYPE_SHIFT; + + ecma_ref_ecma_string (prop_name_p); + + jmem_cpointer_t prop_name_cp; + ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p); + return prop_name_cp; +} /* ecma_string_to_property_name */ + +/** + * Converts a property name into a string + * + * @return the string pointer + * string must be released with ecma_deref_ecma_string + */ +ecma_string_t * +ecma_string_from_property_name (ecma_property_t property, /**< property name type */ + jmem_cpointer_t prop_name_cp) /**< property name compressed pointer */ +{ + if (ECMA_PROPERTY_GET_NAME_TYPE (property) != ECMA_DIRECT_STRING_PTR) + { + return ecma_property_to_string (property, prop_name_cp); + } + + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, prop_name_cp); + ecma_ref_ecma_string (prop_name_p); + return prop_name_p; +} /* ecma_string_from_property_name */ + +/** + * Get hash code of property name + * + * @return hash code of property name + */ +lit_string_hash_t +ecma_string_get_property_name_hash (ecma_property_t property, /**< property name type */ + jmem_cpointer_t prop_name_cp) /**< property name compressed pointer */ +{ + if (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_PTR) + { + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, prop_name_cp); + return prop_name_p->u.hash; + } + + return (lit_string_hash_t) prop_name_cp; +} /* ecma_string_get_property_name_hash */ + +/** + * Check if property name is array index. + * + * @return ECMA_STRING_NOT_ARRAY_INDEX if string is not array index + * the array index otherwise + */ +uint32_t +ecma_string_get_property_index (ecma_property_t property, /**< property name type */ + jmem_cpointer_t prop_name_cp) /**< property name compressed pointer */ +{ + switch (ECMA_PROPERTY_GET_NAME_TYPE (property)) + { + case ECMA_DIRECT_STRING_UINT: + { + return (uint32_t) prop_name_cp; + } + case ECMA_DIRECT_STRING_PTR: + { + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, prop_name_cp); + return ecma_string_get_array_index (prop_name_p); + } + default: + { + return ECMA_STRING_NOT_ARRAY_INDEX; + } + } +} /* ecma_string_get_property_index */ + +/** + * Compare a property name to a string + * + * @return true if they are equals + * false otherwise + */ +bool +ecma_string_compare_to_property_name (ecma_property_t property, /**< property name type */ + jmem_cpointer_t prop_name_cp, /**< property name compressed pointer */ + const ecma_string_t *string_p) /**< other string */ +{ + if (ECMA_PROPERTY_GET_NAME_TYPE (property) != ECMA_DIRECT_STRING_PTR) + { + return ecma_property_to_string (property, prop_name_cp) == string_p; + } + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + return false; + } + + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, prop_name_cp); + return ecma_compare_ecma_non_direct_strings (prop_name_p, string_p); +} /* ecma_string_compare_to_property_name */ + +/** + * Helper for ecma_compare_ecma_strings_longpath to get string data + * + * @return string characters + */ +static const lit_utf8_byte_t * +ecma_compare_get_string_chars (const ecma_string_t *string_p, /**< ecma-string */ + lit_utf8_size_t *size_and_length_p) /**< [out] size and length */ +{ + switch (ECMA_STRING_GET_CONTAINER (string_p)) + { + case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING: + { + ecma_short_string_t *short_string_p = (ecma_short_string_t *) string_p; + size_and_length_p[0] = short_string_p->size; + size_and_length_p[1] = short_string_p->length; + return ECMA_SHORT_STRING_GET_BUFFER (string_p); + } + case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING: + { + ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p; + size_and_length_p[0] = long_string_p->size; + size_and_length_p[1] = long_string_p->length; + return long_string_p->string_p; + } + case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING: + { + size_and_length_p[0] = ECMA_ASCII_STRING_GET_SIZE (string_p); + size_and_length_p[1] = size_and_length_p[0]; + return ECMA_ASCII_STRING_GET_BUFFER (string_p); + } + default: + { + return NULL; + } + } +} /* ecma_compare_get_string_chars */ + +/** + * Long path part of ecma-string to ecma-string comparison routine + * + * See also: + * ecma_compare_ecma_strings + * + * @return true - if strings are equal; + * false - otherwise + */ +static bool JERRY_ATTR_NOINLINE +ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /**< ecma-string */ + const ecma_string_t *string2_p) /**< ecma-string */ +{ + const lit_utf8_byte_t *utf8_string1_p, *utf8_string2_p; + lit_utf8_size_t string1_size_and_length[2] = { 0, 0 }, string2_size_and_length[2] = { 0, 0 }; + + utf8_string1_p = ecma_compare_get_string_chars (string1_p, string1_size_and_length); + utf8_string2_p = ecma_compare_get_string_chars (string2_p, string2_size_and_length); + + if (utf8_string1_p == NULL || utf8_string2_p == NULL) + { + return false; + } + + if (string1_size_and_length[0] != string2_size_and_length[0] + || string1_size_and_length[1] != string2_size_and_length[1]) + { + return false; + } + + return !memcmp ((char *) utf8_string1_p, (char *) utf8_string2_p, string1_size_and_length[0]); +} /* ecma_compare_ecma_strings_longpath */ + +/** + * Compare two ecma-strings + * + * @return true - if strings are equal; + * false - otherwise + */ +bool +ecma_compare_ecma_strings (const ecma_string_t *string1_p, /**< ecma-string */ + const ecma_string_t *string2_p) /**< ecma-string */ +{ + JERRY_ASSERT (string1_p != NULL && string2_p != NULL); + + /* Fast paths first. */ + if (string1_p == string2_p) + { + return true; + } + + /* Either string is direct, return with false. */ + if (ECMA_IS_DIRECT_STRING (((uintptr_t) string1_p) | ((uintptr_t) string2_p))) + { + return false; + } + + /* Also compares uint32 values in descriptor. */ + if (string1_p->u.hash != string2_p->u.hash) + { + return false; + } + + if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + return ECMA_STRING_GET_CONTAINER (string2_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC; + } + + return ecma_compare_ecma_strings_longpath (string1_p, string2_p); +} /* ecma_compare_ecma_strings */ + +/** + * Compare two non-direct ecma-strings + * + * @return true - if strings are equal; + * false - otherwise + */ +bool +ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, /**< ecma-string */ + const ecma_string_t *string2_p) /**< ecma-string */ +{ + JERRY_ASSERT (string1_p != NULL && string2_p != NULL); + JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string1_p) && !ECMA_IS_DIRECT_STRING (string2_p)); + + /* Fast paths first. */ + if (string1_p == string2_p) + { + return true; + } + + if (string1_p->u.hash != string2_p->u.hash) + { + return false; + } + + if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + return ECMA_STRING_GET_CONTAINER (string2_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC; + } + + return ecma_compare_ecma_strings_longpath (string1_p, string2_p); +} /* ecma_compare_ecma_non_direct_strings */ + +/** + * Relational compare of ecma-strings. + * + * First string is less than second string if: + * - strings are not equal; + * - first string is prefix of second or is lexicographically less than second. + * + * @return true - if first string is less than second string, + * false - otherwise + */ +bool +ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-string */ + const ecma_string_t *string2_p) /**< ecma-string */ +{ + if (ecma_compare_ecma_strings (string1_p, string2_p)) + { + return false; + } + + const lit_utf8_byte_t *utf8_string1_p, *utf8_string2_p; + lit_utf8_size_t utf8_string1_size, utf8_string2_size; + + lit_utf8_byte_t uint32_to_string_buffer1[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + lit_utf8_byte_t uint32_to_string_buffer2[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + + if (ECMA_IS_DIRECT_STRING (string1_p)) + { + if (ECMA_GET_DIRECT_STRING_TYPE (string1_p) != ECMA_DIRECT_STRING_UINT) + { + utf8_string1_p = ecma_string_get_chars_fast (string1_p, &utf8_string1_size); + } + else + { + utf8_string1_size = ecma_uint32_to_utf8_string ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string1_p), + uint32_to_string_buffer1, + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + utf8_string1_p = uint32_to_string_buffer1; + } + } + else + { + JERRY_ASSERT (string1_p->refs_and_container >= ECMA_STRING_REF_ONE); + + if (ECMA_STRING_GET_CONTAINER (string1_p) != ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + utf8_string1_p = ecma_string_get_chars_fast (string1_p, &utf8_string1_size); + } + else + { + utf8_string1_size = ecma_uint32_to_utf8_string (string1_p->u.uint32_number, + uint32_to_string_buffer1, + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + utf8_string1_p = uint32_to_string_buffer1; + } + } + + if (ECMA_IS_DIRECT_STRING (string2_p)) + { + if (ECMA_GET_DIRECT_STRING_TYPE (string2_p) != ECMA_DIRECT_STRING_UINT) + { + utf8_string2_p = ecma_string_get_chars_fast (string2_p, &utf8_string2_size); + } + else + { + utf8_string2_size = ecma_uint32_to_utf8_string ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string2_p), + uint32_to_string_buffer2, + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + utf8_string2_p = uint32_to_string_buffer2; + } + } + else + { + JERRY_ASSERT (string2_p->refs_and_container >= ECMA_STRING_REF_ONE); + + if (ECMA_STRING_GET_CONTAINER (string2_p) != ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + utf8_string2_p = ecma_string_get_chars_fast (string2_p, &utf8_string2_size); + } + else + { + utf8_string2_size = ecma_uint32_to_utf8_string (string2_p->u.uint32_number, + uint32_to_string_buffer2, + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + utf8_string2_p = uint32_to_string_buffer2; + } + } + + return lit_compare_utf8_strings_relational (utf8_string1_p, utf8_string1_size, utf8_string2_p, utf8_string2_size); +} /* ecma_compare_ecma_strings_relational */ + +/** + * Special value to represent that no size is available. + */ +#define ECMA_STRING_NO_ASCII_SIZE 0xffffffff + +/** + * Return the size of uint32 and magic strings. + * The length of these strings are equal to their size. + * + * @return number of characters in the string + */ +static lit_utf8_size_t +ecma_string_get_ascii_size (const ecma_string_t *string_p) /**< ecma-string */ +{ + if (ECMA_IS_DIRECT_STRING (string_p)) + { + switch (ECMA_GET_DIRECT_STRING_TYPE (string_p)) + { + case ECMA_DIRECT_STRING_MAGIC: + { + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + + if (id >= LIT_MAGIC_STRING__COUNT) + { + return ECMA_STRING_NO_ASCII_SIZE; + } + + JERRY_ASSERT (ECMA_STRING_IS_ASCII (lit_get_magic_string_utf8 (id), lit_get_magic_string_size (id))); + + return lit_get_magic_string_size (id); + } + default: + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_UINT); + uint32_t uint32_number = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + return ecma_string_get_uint32_size (uint32_number); + } + } + } + + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) + { + return ecma_string_get_uint32_size (string_p->u.uint32_number); + } + else if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_HEAP_ASCII_STRING) + { + return ECMA_ASCII_STRING_GET_SIZE (string_p); + } + + return ECMA_STRING_NO_ASCII_SIZE; +} /* ecma_string_get_ascii_size */ + +/** + * Get length of ecma-string + * + * @return number of characters in the string + */ +lit_utf8_size_t +ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */ +{ + lit_utf8_size_t length = ecma_string_get_ascii_size (string_p); + + if (length != ECMA_STRING_NO_ASCII_SIZE) + { + return length; + } + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_MAGIC); + JERRY_ASSERT ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) >= LIT_MAGIC_STRING__COUNT); + + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) - LIT_MAGIC_STRING__COUNT; + return lit_utf8_string_length (lit_get_magic_string_ex_utf8 (id), lit_get_magic_string_ex_size (id)); + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_HEAP_UTF8_STRING) + { + return ((ecma_short_string_t *) string_p)->length; + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING) + { + return ((ecma_long_string_t *) string_p)->length; + } + + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + lit_magic_string_ex_id_t id = LIT_MAGIC_STRING__COUNT - string_p->u.magic_string_ex_id; + return lit_utf8_string_length (lit_get_magic_string_ex_utf8 (id), lit_get_magic_string_ex_size (id)); +} /* ecma_string_get_length */ + +/** + * Get length of UTF-8 encoded string length from ecma-string + * + * @return number of characters in the UTF-8 encoded string + */ +lit_utf8_size_t +ecma_string_get_utf8_length (const ecma_string_t *string_p) /**< ecma-string */ +{ + lit_utf8_size_t length = ecma_string_get_ascii_size (string_p); + + if (length != ECMA_STRING_NO_ASCII_SIZE) + { + return length; + } + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_MAGIC); + JERRY_ASSERT ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) >= LIT_MAGIC_STRING__COUNT); + + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) - LIT_MAGIC_STRING__COUNT; + return lit_get_utf8_length_of_cesu8_string (lit_get_magic_string_ex_utf8 (id), lit_get_magic_string_ex_size (id)); + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_HEAP_UTF8_STRING) + { + ecma_short_string_t *short_string_p = (ecma_short_string_t *) string_p; + lit_utf8_size_t size = short_string_p->size; + + if (size == short_string_p->length) + { + return size; + } + + return lit_get_utf8_length_of_cesu8_string (ECMA_SHORT_STRING_GET_BUFFER (string_p), size); + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING) + { + ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p; + lit_utf8_size_t size = long_string_p->size; + + if (size == long_string_p->length) + { + return size; + } + + return lit_get_utf8_length_of_cesu8_string (long_string_p->string_p, size); + } + + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + lit_magic_string_ex_id_t id = LIT_MAGIC_STRING__COUNT - string_p->u.magic_string_ex_id; + + return lit_get_utf8_length_of_cesu8_string (lit_get_magic_string_ex_utf8 (id), lit_get_magic_string_ex_size (id)); +} /* ecma_string_get_utf8_length */ + +/** + * Get size of ecma-string + * + * @return number of bytes in the buffer needed to represent the string + */ +lit_utf8_size_t +ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */ +{ + lit_utf8_size_t length = ecma_string_get_ascii_size (string_p); + + if (length != ECMA_STRING_NO_ASCII_SIZE) + { + return length; + } + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_MAGIC); + JERRY_ASSERT ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) >= LIT_MAGIC_STRING__COUNT); + + return lit_get_magic_string_ex_size ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) - LIT_MAGIC_STRING__COUNT); + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_HEAP_UTF8_STRING) + { + return ((ecma_short_string_t *) string_p)->size; + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING) + { + return ((ecma_long_string_t *) string_p)->size; + } + + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + return lit_get_magic_string_ex_size (LIT_MAGIC_STRING__COUNT - string_p->u.magic_string_ex_id); +} /* ecma_string_get_size */ + +/** + * Get the UTF-8 encoded string size from ecma-string + * + * @return number of bytes in the buffer needed to represent an UTF-8 encoded string + */ +lit_utf8_size_t +ecma_string_get_utf8_size (const ecma_string_t *string_p) /**< ecma-string */ +{ + lit_utf8_size_t length = ecma_string_get_ascii_size (string_p); + + if (length != ECMA_STRING_NO_ASCII_SIZE) + { + return length; + } + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_MAGIC); + JERRY_ASSERT ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) >= LIT_MAGIC_STRING__COUNT); + + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p) - LIT_MAGIC_STRING__COUNT; + return lit_get_utf8_size_of_cesu8_string (lit_get_magic_string_ex_utf8 (id), lit_get_magic_string_ex_size (id)); + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_HEAP_UTF8_STRING) + { + ecma_short_string_t *short_string_p = (ecma_short_string_t *) string_p; + lit_utf8_size_t size = short_string_p->size; + + if (size == short_string_p->length) + { + return size; + } + + return lit_get_utf8_size_of_cesu8_string (ECMA_SHORT_STRING_GET_BUFFER (string_p), size); + } + + if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING) + { + ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p; + + if (long_string_p->size == long_string_p->length) + { + return long_string_p->size; + } + + return lit_get_utf8_size_of_cesu8_string (long_string_p->string_p, long_string_p->size); + } + + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + + lit_magic_string_ex_id_t id = LIT_MAGIC_STRING__COUNT - string_p->u.magic_string_ex_id; + return lit_get_utf8_size_of_cesu8_string (lit_get_magic_string_ex_utf8 (id), lit_get_magic_string_ex_size (id)); +} /* ecma_string_get_utf8_size */ + +/** + * Get character from specified position in an external ecma-string. + * + * @return character value + */ +static ecma_char_t JERRY_ATTR_NOINLINE +ecma_external_string_get_char_at_pos (lit_utf8_size_t id, /**< id of the external magic string */ + lit_utf8_size_t index) /**< index of character */ +{ + id -= LIT_MAGIC_STRING__COUNT; + const lit_utf8_byte_t *data_p = lit_get_magic_string_ex_utf8 (id); + lit_utf8_size_t size = lit_get_magic_string_ex_size (id); + lit_utf8_size_t length = lit_utf8_string_length (data_p, size); + + if (JERRY_LIKELY (size == length)) + { + return (ecma_char_t) data_p[index]; + } + + return lit_utf8_string_code_unit_at (data_p, size, index); +} /* ecma_external_string_get_char_at_pos */ + +/** + * Get character from specified position in the ecma-string. + * + * @return character value + */ +ecma_char_t +ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */ + lit_utf8_size_t index) /**< index of character */ +{ + JERRY_ASSERT (index < ecma_string_get_length (string_p)); + + lit_utf8_byte_t uint32_to_string_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + switch (ECMA_GET_DIRECT_STRING_TYPE (string_p)) + { + case ECMA_DIRECT_STRING_MAGIC: + { + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + + if (JERRY_LIKELY (id < LIT_MAGIC_STRING__COUNT)) + { + /* All magic strings must be ascii strings. */ + const lit_utf8_byte_t *data_p = lit_get_magic_string_utf8 (id); + + return (ecma_char_t) data_p[index]; + } + + return ecma_external_string_get_char_at_pos (id, index); + } + default: + { + JERRY_ASSERT (ECMA_GET_DIRECT_STRING_TYPE (string_p) == ECMA_DIRECT_STRING_UINT); + uint32_t uint32_number = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + + ecma_uint32_to_utf8_string (uint32_number, uint32_to_string_buffer, ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + + return (ecma_char_t) uint32_to_string_buffer[index]; + } + } + } + + JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); + + switch (ECMA_STRING_GET_CONTAINER (string_p)) + { + case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING: + { + ecma_short_string_t *short_string_p = (ecma_short_string_t *) string_p; + lit_utf8_size_t size = short_string_p->size; + const lit_utf8_byte_t *data_p = ECMA_SHORT_STRING_GET_BUFFER (string_p); + + if (JERRY_LIKELY (size == short_string_p->length)) + { + return (ecma_char_t) data_p[index]; + } + + return lit_utf8_string_code_unit_at (data_p, size, index); + } + case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING: + { + ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p; + lit_utf8_size_t size = long_string_p->size; + const lit_utf8_byte_t *data_p = long_string_p->string_p; + + if (JERRY_LIKELY (size == long_string_p->length)) + { + return (ecma_char_t) data_p[index]; + } + + return lit_utf8_string_code_unit_at (data_p, size, index); + } + case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING: + { + const lit_utf8_byte_t *data_p = ECMA_ASCII_STRING_GET_BUFFER (string_p); + return (ecma_char_t) data_p[index]; + } + case ECMA_STRING_CONTAINER_UINT32_IN_DESC: + { + ecma_uint32_to_utf8_string (string_p->u.uint32_number, + uint32_to_string_buffer, + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); + + return (ecma_char_t) uint32_to_string_buffer[index]; + } + default: + { + JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX); + return ecma_external_string_get_char_at_pos (string_p->u.magic_string_ex_id, index); + } + } +} /* ecma_string_get_char_at_pos */ + +/** + * Check if passed string equals to one of magic strings + * and if equal magic string was found, return it's id in 'out_id_p' argument. + * + * @return id - if magic string equal to passed string was found, + * LIT_MAGIC_STRING__COUNT - otherwise. + */ +lit_magic_string_id_t +ecma_get_string_magic (const ecma_string_t *string_p) /**< ecma-string */ +{ + if (ECMA_IS_DIRECT_STRING_WITH_TYPE (string_p, ECMA_DIRECT_STRING_MAGIC)) + { + uint32_t id = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + + if (id < LIT_MAGIC_STRING__COUNT) + { + return (lit_magic_string_id_t) id; + } + } + + return LIT_MAGIC_STRING__COUNT; +} /* ecma_get_string_magic */ + +/** + * Try to calculate hash of the ecma-string + * + * @return calculated hash + */ +lit_string_hash_t +ecma_string_hash (const ecma_string_t *string_p) /**< ecma-string to calculate hash for */ +{ + if (ECMA_IS_DIRECT_STRING (string_p)) + { + return (lit_string_hash_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); + } + + return (lit_string_hash_t) string_p->u.hash; +} /* ecma_string_hash */ + +/** + * Create a substring from an ecma string + * + * @return a newly constructed ecma string with its value initialized to a copy of a substring of the first argument + */ +ecma_string_t * +ecma_string_substr (const ecma_string_t *string_p, /**< pointer to an ecma string */ + lit_utf8_size_t start_pos, /**< start position, should be less or equal than string length */ + lit_utf8_size_t end_pos) /**< end position, should be less or equal than string length */ +{ + const lit_utf8_size_t string_length = ecma_string_get_length (string_p); + JERRY_ASSERT (start_pos <= string_length); + JERRY_ASSERT (end_pos <= string_length); + + if (start_pos >= end_pos) + { + return ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_string_t *ecma_string_p = NULL; + end_pos -= start_pos; + + ECMA_STRING_TO_UTF8_STRING (string_p, start_p, buffer_size); + + if (string_length == buffer_size) + { + ecma_string_p = ecma_new_ecma_string_from_utf8 (start_p + start_pos, (lit_utf8_size_t) end_pos); + } + else + { + while (start_pos--) + { + start_p += lit_get_unicode_char_size_by_utf8_first_byte (*start_p); + } + + const lit_utf8_byte_t *end_p = start_p; + while (end_pos--) + { + end_p += lit_get_unicode_char_size_by_utf8_first_byte (*end_p); + } + + ecma_string_p = ecma_new_ecma_string_from_utf8 (start_p, (lit_utf8_size_t) (end_p - start_p)); + } + + ECMA_FINALIZE_UTF8_STRING (start_p, buffer_size); + + return ecma_string_p; +} /* ecma_string_substr */ + +/** + * Helper function for trimming. + * + * Used by: + * - ecma_string_trim_helper + * - ecma_builtin_global_object_parse_int + * - ecma_builtin_global_object_parse_float + * + * @return position of the first non whitespace character. + */ +const lit_utf8_byte_t * +ecma_string_trim_front (const lit_utf8_byte_t *start_p, /**< current string's start position */ + const lit_utf8_byte_t *end_p) /**< current string's end position */ +{ + ecma_char_t ch; + + while (start_p < end_p) + { + lit_utf8_size_t read_size = lit_read_code_unit_from_cesu8 (start_p, &ch); + + if (!lit_char_is_white_space (ch)) + { + break; + } + + start_p += read_size; + } + + return start_p; +} /* ecma_string_trim_front */ + +/** + * Helper function for trimming. + * + * Used by: + * - ecma_string_trim_helper + * + * @return position of the last non whitespace character. + */ +const lit_utf8_byte_t * +ecma_string_trim_back (const lit_utf8_byte_t *start_p, /**< current string's start position */ + const lit_utf8_byte_t *end_p) /**< current string's end position */ +{ + ecma_char_t ch; + + while (end_p > start_p) + { + lit_utf8_size_t read_size = lit_read_prev_code_unit_from_utf8 (end_p, &ch); + + if (!lit_char_is_white_space (ch)) + { + break; + } + + end_p -= read_size; + } + + return end_p; +} /* ecma_string_trim_back */ + +/** + * Helper function for trimming. + * + * Used by: + * - ecma_string_trim + * - ecma_utf8_string_to_number + * + * @return void + */ +void +ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, /**< [in, out] current string position */ + lit_utf8_size_t *utf8_str_size) /**< [in, out] size of the given string */ +{ + const lit_utf8_byte_t *end_p = *utf8_str_p + *utf8_str_size; + const lit_utf8_byte_t *start_p = *utf8_str_p; + + const lit_utf8_byte_t *new_start_p = ecma_string_trim_front (start_p, end_p); + const lit_utf8_byte_t *new_end_p = ecma_string_trim_back (new_start_p, end_p); + + *utf8_str_size = (lit_utf8_size_t) (new_end_p - new_start_p); + *utf8_str_p = new_start_p; +} /* ecma_string_trim_helper */ + +/** + * Trim leading and trailing whitespace characters from string. + * + * @return trimmed ecma string + */ +ecma_string_t * +ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string */ +{ + ecma_string_t *ret_string_p; + + lit_utf8_size_t utf8_str_size; + uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; + const lit_utf8_byte_t *utf8_str_p = ecma_string_get_chars (string_p, &utf8_str_size, NULL, NULL, &flags); + + if (utf8_str_size > 0) + { + ecma_string_trim_helper (&utf8_str_p, &utf8_str_size); + ret_string_p = ecma_new_ecma_string_from_utf8 (utf8_str_p, utf8_str_size); + } + else + { + ret_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) utf8_str_p, utf8_str_size); + } + + return ret_string_p; +} /* ecma_string_trim */ + +/** + * Pad the beginning or the end of string with parameter given in fill_string to the length of max_length. + * + * @return new string from original, padded with given parameters + */ +ecma_value_t +ecma_string_pad (ecma_value_t original_string_p, /**< Input ecma string */ + ecma_value_t max_length, /**< Length to pad to, including original length */ + ecma_value_t fill_string, /**< The string to pad with */ + bool pad_on_start) /**< true - if we are padding to the start, calling with padStart + false - if we are padding to the end, calling with padEnd */ +{ + /* 3 */ + ecma_length_t int_max_length; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_length (max_length, &int_max_length))) + { + return ECMA_VALUE_ERROR; + } + /* 4 */ + ecma_string_t *original_str_val_p = ecma_get_string_from_value (original_string_p); + const uint32_t string_length = ecma_string_get_length (original_str_val_p); + /* 5 */ + if (int_max_length <= string_length) + { + ecma_ref_ecma_string (original_str_val_p); + return original_string_p; + } + + ecma_string_t *filler_p = ecma_get_magic_string (LIT_MAGIC_STRING_SPACE_CHAR); + /* 6 - 7 */ + if (!ecma_is_value_undefined (fill_string)) + { + filler_p = ecma_op_to_string (fill_string); + if (filler_p == NULL) + { + return ECMA_VALUE_ERROR; + } + if (ecma_string_is_empty (filler_p)) + { + ecma_ref_ecma_string (original_str_val_p); + return original_string_p; + } + } + + if (int_max_length >= UINT32_MAX) + { + ecma_deref_ecma_string (filler_p); + return ecma_raise_range_error (ECMA_ERR_MAXIMUM_STRING_LENGTH_IS_REACHED); + } + + /* 9 */ + uint32_t fill_len = (uint32_t) int_max_length - string_length; + + /* 10 */ + uint32_t filler_length = ecma_string_get_length (filler_p); + uint32_t prepend_count = fill_len / filler_length; + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + if (!pad_on_start) + { + ecma_stringbuilder_append (&builder, original_str_val_p); + } + + for (uint32_t i = 0; i < prepend_count; i++) + { + ecma_stringbuilder_append (&builder, filler_p); + } + + uint32_t remaining = fill_len - (prepend_count * filler_length); + + ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, utf8_str_size); + const lit_utf8_byte_t *temp_start_p = start_p; + while (remaining > 0) + { + ecma_char_t ch; + lit_utf8_size_t read_size = lit_read_code_unit_from_cesu8 (temp_start_p, &ch); + ecma_stringbuilder_append_char (&builder, ch); + temp_start_p += read_size; + remaining--; + } + ECMA_FINALIZE_UTF8_STRING (start_p, utf8_str_size); + ecma_deref_ecma_string (filler_p); + + /* 11 - 12 */ + if (pad_on_start) + { + ecma_stringbuilder_append (&builder, original_str_val_p); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_string_pad */ + +/** + * Create an empty string builder + * + * @return new string builder + */ +ecma_stringbuilder_t +ecma_stringbuilder_create (void) +{ + const lit_utf8_size_t initial_size = ECMA_ASCII_STRING_HEADER_SIZE; + ecma_stringbuilder_header_t *header_p = (ecma_stringbuilder_header_t *) jmem_heap_alloc_block (initial_size); + header_p->current_size = initial_size; + + ecma_stringbuilder_t ret = { header_p }; + return ret; +} /* ecma_stringbuilder_create */ + +/** + * Create a string builder from an ecma string + * + * @return new string builder + */ +ecma_stringbuilder_t +ecma_stringbuilder_create_from (ecma_string_t *string_p) /**< ecma string */ +{ + const lit_utf8_size_t string_size = ecma_string_get_size (string_p); + const lit_utf8_size_t initial_size = string_size + ECMA_ASCII_STRING_HEADER_SIZE; + + ecma_stringbuilder_header_t *header_p = (ecma_stringbuilder_header_t *) jmem_heap_alloc_block (initial_size); + header_p->current_size = initial_size; + + ecma_string_to_cesu8_bytes (string_p, ECMA_STRINGBUILDER_STRING_PTR (header_p), string_size); + + ecma_stringbuilder_t ret = { header_p }; + return ret; +} /* ecma_stringbuilder_create_from */ + +/** + * Create a string builder from a raw string + * + * @return new string builder + */ +ecma_stringbuilder_t +ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p, /**< pointer to data */ + const lit_utf8_size_t data_size) /**< size of the data */ +{ + const lit_utf8_size_t initial_size = data_size + ECMA_ASCII_STRING_HEADER_SIZE; + + ecma_stringbuilder_header_t *header_p = (ecma_stringbuilder_header_t *) jmem_heap_alloc_block (initial_size); + header_p->current_size = initial_size; + + memcpy (ECMA_STRINGBUILDER_STRING_PTR (header_p), data_p, data_size); + + ecma_stringbuilder_t ret = { header_p }; + return ret; +} /* ecma_stringbuilder_create_raw */ + +/** + * Grow the underlying buffer of a string builder + * + * @return pointer to the end of the data in the underlying buffer + */ +static lit_utf8_byte_t * +ecma_stringbuilder_grow (ecma_stringbuilder_t *builder_p, /**< string builder */ + lit_utf8_size_t required_size) /**< required size */ +{ + ecma_stringbuilder_header_t *header_p = builder_p->header_p; + JERRY_ASSERT (header_p != NULL); + + const lit_utf8_size_t new_size = header_p->current_size + required_size; + header_p = (ecma_stringbuilder_header_t *) jmem_heap_realloc_block (header_p, header_p->current_size, new_size); + header_p->current_size = new_size; + builder_p->header_p = header_p; + + return ((lit_utf8_byte_t *) header_p) + header_p->current_size - required_size; +} /* ecma_stringbuilder_grow */ + +/** + * Get the current size of the string in a string builder + * + * @return the size of the string data + */ +lit_utf8_size_t +ecma_stringbuilder_get_size (ecma_stringbuilder_t *builder_p) /**< string builder */ +{ + ecma_stringbuilder_header_t *header_p = builder_p->header_p; + JERRY_ASSERT (header_p != NULL); + + return ECMA_STRINGBUILDER_STRING_SIZE (header_p); +} /* ecma_stringbuilder_get_size */ + +/** + * Get pointer to the raw string data in a string builder + * + * @return pointer to the string data + */ +lit_utf8_byte_t * +ecma_stringbuilder_get_data (ecma_stringbuilder_t *builder_p) /**< string builder */ +{ + ecma_stringbuilder_header_t *header_p = builder_p->header_p; + JERRY_ASSERT (header_p != NULL); + + return ECMA_STRINGBUILDER_STRING_PTR (header_p); +} /* ecma_stringbuilder_get_data */ + +/** + * Revert the string builder to a smaller size + */ +void +ecma_stringbuilder_revert (ecma_stringbuilder_t *builder_p, /**< string builder */ + const lit_utf8_size_t size) /**< new size */ +{ + ecma_stringbuilder_header_t *header_p = builder_p->header_p; + JERRY_ASSERT (header_p != NULL); + + const lit_utf8_size_t new_size = size + ECMA_ASCII_STRING_HEADER_SIZE; + JERRY_ASSERT (new_size <= header_p->current_size); + + header_p = (ecma_stringbuilder_header_t *) jmem_heap_realloc_block (header_p, header_p->current_size, new_size); + header_p->current_size = new_size; + builder_p->header_p = header_p; +} /* ecma_stringbuilder_revert */ + +/** + * Append an ecma_string_t to a string builder + */ +void +ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, /**< string builder */ + const ecma_string_t *string_p) /**< ecma string */ +{ + const lit_utf8_size_t string_size = ecma_string_get_size (string_p); + lit_utf8_byte_t *dest_p = ecma_stringbuilder_grow (builder_p, string_size); + + ecma_string_to_cesu8_bytes (string_p, dest_p, string_size); +} /* ecma_stringbuilder_append */ + +/** + * Append a magic string to a string builder + */ +void +ecma_stringbuilder_append_magic (ecma_stringbuilder_t *builder_p, /**< string builder */ + const lit_magic_string_id_t id) /**< magic string id */ +{ + const lit_utf8_size_t string_size = lit_get_magic_string_size (id); + lit_utf8_byte_t *dest_p = ecma_stringbuilder_grow (builder_p, string_size); + + const lit_utf8_byte_t *string_data_p = lit_get_magic_string_utf8 (id); + memcpy (dest_p, string_data_p, string_size); +} /* ecma_stringbuilder_append_magic */ + +/** + * Append raw string data to a string builder + */ +void +ecma_stringbuilder_append_raw (ecma_stringbuilder_t *builder_p, /**< string builder */ + const lit_utf8_byte_t *data_p, /**< pointer to data */ + const lit_utf8_size_t data_size) /**< size of the data */ +{ + lit_utf8_byte_t *dest_p = ecma_stringbuilder_grow (builder_p, data_size); + memcpy (dest_p, data_p, data_size); +} /* ecma_stringbuilder_append_raw */ + +/** + * Append a codepoint to a string builder + */ +void +ecma_stringbuilder_append_codepoint (ecma_stringbuilder_t *builder_p, /**< string builder */ + lit_code_point_t cp) /**< code point */ +{ + const lit_utf8_size_t size = (lit_utf8_size_t) lit_code_point_get_cesu8_length (cp); + lit_utf8_byte_t *dest_p = ecma_stringbuilder_grow (builder_p, size); + + lit_code_point_to_cesu8_bytes (dest_p, cp); +} /* ecma_stringbuilder_append_codepoint */ + +/** + * Append an ecma_char_t to a string builder + */ +void +ecma_stringbuilder_append_char (ecma_stringbuilder_t *builder_p, /**< string builder */ + const ecma_char_t c) /**< ecma char */ +{ + ecma_stringbuilder_append_codepoint (builder_p, c); +} /* ecma_stringbuilder_append_char */ + +/** + * Append a single byte to a string builder + */ +void +ecma_stringbuilder_append_byte (ecma_stringbuilder_t *builder_p, /**< string builder */ + const lit_utf8_byte_t byte) /**< byte */ +{ + lit_utf8_byte_t *dest_p = ecma_stringbuilder_grow (builder_p, 1); + *dest_p = byte; +} /* ecma_stringbuilder_append_byte */ + +/** + * Finalize a string builder, returning the created string, and releasing the underlying buffer. + * + * Note: + * The builder should no longer be used. + * + * @return the created string + */ +ecma_string_t * +ecma_stringbuilder_finalize (ecma_stringbuilder_t *builder_p) /**< string builder */ +{ + ecma_stringbuilder_header_t *header_p = builder_p->header_p; + JERRY_ASSERT (header_p != NULL); + + const lit_utf8_size_t string_size = ECMA_STRINGBUILDER_STRING_SIZE (header_p); + lit_utf8_byte_t *string_begin_p = ECMA_STRINGBUILDER_STRING_PTR (header_p); + + ecma_string_t *string_p = ecma_find_special_string (string_begin_p, string_size); + + if (JERRY_UNLIKELY (string_p != NULL)) + { + ecma_stringbuilder_destroy (builder_p); + return string_p; + } + +#ifndef JERRY_NDEBUG + builder_p->header_p = NULL; +#endif /* !defined (JERRY_NDEBUG) */ + + size_t container_size = sizeof (ecma_short_string_t); + const lit_string_hash_t hash = lit_utf8_string_calc_hash (string_begin_p, string_size); + const lit_utf8_size_t length = lit_utf8_string_length (string_begin_p, string_size); + + if (JERRY_LIKELY (string_size <= UINT16_MAX)) + { + if (JERRY_LIKELY (length == string_size) && string_size <= (UINT8_MAX + 1)) + { + string_p = (ecma_string_t *) header_p; + string_p->refs_and_container = ECMA_STRING_CONTAINER_HEAP_ASCII_STRING | ECMA_STRING_REF_ONE; + string_p->u.hash = hash; + ECMA_ASCII_STRING_SET_SIZE (string_p, string_size); + + return (ecma_string_t *) string_p; + } + } + else + { + container_size = sizeof (ecma_long_string_t); + } + + const size_t utf8_string_size = string_size + container_size; + header_p = (ecma_stringbuilder_header_t *) jmem_heap_realloc_block (header_p, header_p->current_size, utf8_string_size); + memmove (((lit_utf8_byte_t *) header_p + container_size), ECMA_STRINGBUILDER_STRING_PTR (header_p), string_size); + + if (JERRY_LIKELY (string_size <= UINT16_MAX)) + { + ecma_short_string_t *short_string_p = (ecma_short_string_t *) header_p; + + short_string_p->header.refs_and_container = ECMA_STRING_CONTAINER_HEAP_UTF8_STRING | ECMA_STRING_REF_ONE; + short_string_p->header.u.hash = hash; + short_string_p->size = (uint16_t) string_size; + short_string_p->length = (uint16_t) length; + + return (ecma_string_t *) short_string_p; + } + + ecma_long_string_t *long_string_p = (ecma_long_string_t *) header_p; + + long_string_p->header.refs_and_container = ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING | ECMA_STRING_REF_ONE; + long_string_p->header.u.hash = hash; + long_string_p->string_p = ECMA_LONG_STRING_BUFFER_START (long_string_p); + long_string_p->size = string_size; + long_string_p->length = length; + + return (ecma_string_t *) long_string_p; +} /* ecma_stringbuilder_finalize */ + +/** + * Destroy a string builder that is no longer needed without creating a string from the contents. + */ +void +ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p) /**< string builder */ +{ + JERRY_ASSERT (builder_p->header_p != NULL); + const lit_utf8_size_t size = builder_p->header_p->current_size; + jmem_heap_free_block (builder_p->header_p, size); + +#ifndef JERRY_NDEBUG + builder_p->header_p = NULL; +#endif /* !defined (JERRY_NDEBUG) */ + +} /* ecma_stringbuilder_destroy */ + +/** + * AdvanceStringIndex operation + * + * See also: + * ECMA-262 v6.0, 21.2.5.2.3 + * + * @return uint32_t - the proper character index based on the operation + */ +ecma_length_t +ecma_op_advance_string_index (ecma_string_t *str_p, /**< input string */ + ecma_length_t index, /**< given character index */ + bool is_unicode) /**< true - if regexp object's "unicode" flag is set + false - otherwise */ +{ + JERRY_ASSERT ((ecma_number_t) index <= ECMA_NUMBER_MAX_SAFE_INTEGER); + ecma_length_t next_index = index + 1; + + if (!is_unicode) + { + return next_index; + } + + lit_utf8_size_t str_len = ecma_string_get_length (str_p); + + if (next_index >= str_len) + { + return next_index; + } + + JERRY_ASSERT (index < UINT32_MAX); + ecma_char_t first = ecma_string_get_char_at_pos (str_p, (lit_utf8_size_t) index); + + if (!lit_is_code_point_utf16_high_surrogate (first)) + { + return next_index; + } + + ecma_char_t second = ecma_string_get_char_at_pos (str_p, (lit_utf8_size_t) next_index); + + if (!lit_is_code_point_utf16_low_surrogate (second)) + { + return next_index; + } + + return next_index + 1; +} /* ecma_op_advance_string_index */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-value.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-value.cpp new file mode 100644 index 0000000..c2a74d0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers-value.cpp @@ -0,0 +1,1257 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" + +#include "jrt-bit-fields.h" +#include "jrt.h" +#include "vm-defines.h" + +JERRY_STATIC_ASSERT (((int)ECMA_TYPE___MAX <= (int)ECMA_VALUE_TYPE_MASK), ecma_types_must_be_less_than_mask); + +JERRY_STATIC_ASSERT (((ECMA_VALUE_TYPE_MASK + 1) == (1 << ECMA_VALUE_SHIFT)), ecma_value_part_must_start_after_flags); + +JERRY_STATIC_ASSERT (((int)ECMA_VALUE_SHIFT <= (int)JMEM_ALIGNMENT_LOG), + ecma_value_shift_must_be_less_than_or_equal_than_mem_alignment_log); + +JERRY_STATIC_ASSERT ((sizeof (jmem_cpointer_t) <= sizeof (ecma_value_t)), + size_of_jmem_cpointer_t_must_be_less_or_equal_to_the_size_of_ecma_value_t); + +JERRY_STATIC_ASSERT ((sizeof (jmem_cpointer_t) <= sizeof (jmem_cpointer_tag_t)), + size_of_jmem_cpointer_t_must_be_less_or_equal_to_the_size_of_jmem_cpointer_tag_t); + +#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY + +/* cppcheck-suppress zerodiv */ +JERRY_STATIC_ASSERT (sizeof (uintptr_t) <= sizeof (ecma_value_t), uintptr_t_must_fit_in_ecma_value_t); + +#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ + +JERRY_STATIC_ASSERT ((sizeof (uintptr_t) > sizeof (ecma_value_t)), uintptr_t_must_not_fit_in_ecma_value_t); + +#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ + +JERRY_STATIC_ASSERT ((((int)ECMA_VALUE_FALSE | (1 << (int)ECMA_DIRECT_SHIFT)) == (int)ECMA_VALUE_TRUE) + && ECMA_VALUE_FALSE != ECMA_VALUE_TRUE, + only_the_lowest_bit_must_be_different_for_simple_value_true_and_false); + +#if JERRY_BUILTIN_BIGINT + +JERRY_STATIC_ASSERT (ECMA_NULL_POINTER == (ECMA_BIGINT_ZERO & ~(ecma_value_t) ECMA_VALUE_TYPE_MASK), + ecma_bigint_zero_must_be_encoded_as_null_pointer); + +#endif /* JERRY_BUILTIN_BIGINT */ + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +/** + * Get type field of ecma value + * + * @return type field + */ +ecma_type_t JERRY_ATTR_CONST +ecma_get_value_type_field (ecma_value_t value) /**< ecma value */ +{ + return (ecma_type_t)(((unsigned int) value) & ((unsigned int)ECMA_VALUE_TYPE_MASK)); +} /* ecma_get_value_type_field */ + +/** + * Convert a pointer into an ecma value. + * + * @return ecma value + */ +static inline ecma_value_t JERRY_ATTR_PURE +ecma_pointer_to_ecma_value (const void *ptr) /**< pointer */ +{ +#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY + + JERRY_ASSERT (ptr != NULL); + uintptr_t uint_ptr = (uintptr_t) ptr; + JERRY_ASSERT ((uint_ptr & ECMA_VALUE_TYPE_MASK) == 0); + return (ecma_value_t) uint_ptr; + +#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ + + jmem_cpointer_t ptr_cp; + ECMA_SET_NON_NULL_POINTER (ptr_cp, ptr); + return ((ecma_value_t) ptr_cp) << ECMA_VALUE_SHIFT; + +#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ +} /* ecma_pointer_to_ecma_value */ + +/** + * Get a pointer from an ecma value + * + * @return pointer + */ +static inline void *JERRY_ATTR_PURE +ecma_get_pointer_from_ecma_value (ecma_value_t value) /**< value */ +{ +#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY + void *ptr = (void *) (uintptr_t) ((value) & ~ECMA_VALUE_TYPE_MASK); + JERRY_ASSERT (ptr != NULL); + return ptr; +#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ + return ECMA_GET_NON_NULL_POINTER (void, value >> ECMA_VALUE_SHIFT); +#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ +} /* ecma_get_pointer_from_ecma_value */ + +/** + * Check if the value is direct ecma-value. + * + * @return true - if the value is a direct value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_direct (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT); +} /* ecma_is_value_direct */ + +/** + * Check if the value is simple ecma-value. + * + * @return true - if the value is a simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_simple (ecma_value_t value) /**< ecma value */ +{ + return (value & ECMA_DIRECT_TYPE_MASK) == ECMA_DIRECT_TYPE_SIMPLE_VALUE; +} /* ecma_is_value_simple */ + +/** + * Check whether the value is a given simple value. + * + * @return true - if the value is equal to the given simple value, + * false - otherwise + */ +static inline bool JERRY_ATTR_CONST +ecma_is_value_equal_to_simple_value (ecma_value_t value, /**< ecma value */ + ecma_value_t simple_value) /**< simple value */ +{ + return value == simple_value; +} /* ecma_is_value_equal_to_simple_value */ + +/** + * Check if the value is empty. + * + * @return true - if the value contains implementation-defined empty simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_empty (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_equal_to_simple_value (value, ECMA_VALUE_EMPTY); +} /* ecma_is_value_empty */ + +/** + * Check if the value is undefined. + * + * @return true - if the value contains ecma-undefined simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_undefined (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_equal_to_simple_value (value, ECMA_VALUE_UNDEFINED); +} /* ecma_is_value_undefined */ + +/** + * Check if the value is null. + * + * @return true - if the value contains ecma-null simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_null (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_equal_to_simple_value (value, ECMA_VALUE_NULL); +} /* ecma_is_value_null */ + +/** + * Check if the value is boolean. + * + * @return true - if the value contains ecma-true or ecma-false simple values, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_boolean (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_true (value | (1 << ECMA_DIRECT_SHIFT)); +} /* ecma_is_value_boolean */ + +/** + * Check if the value is true. + * + * @return true - if the value contains ecma-true simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_true (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_equal_to_simple_value (value, ECMA_VALUE_TRUE); +} /* ecma_is_value_true */ + +/** + * Check if the value is false. + * + * @return true - if the value contains ecma-false simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_false (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_equal_to_simple_value (value, ECMA_VALUE_FALSE); +} /* ecma_is_value_false */ + +/** + * Check if the value is not found. + * + * @return true - if the value contains ecma-not-found simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_found (ecma_value_t value) /**< ecma value */ +{ + return value != ECMA_VALUE_NOT_FOUND; +} /* ecma_is_value_found */ + +/** + * Check if the value is array hole. + * + * @return true - if the value contains ecma-array-hole simple value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_array_hole (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_equal_to_simple_value (value, ECMA_VALUE_ARRAY_HOLE); +} /* ecma_is_value_array_hole */ + +/** + * Check if the value is integer ecma-number. + * + * @return true - if the value contains an integer ecma-number value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_integer_number (ecma_value_t value) /**< ecma value */ +{ + return (value & ECMA_DIRECT_TYPE_MASK) == ECMA_DIRECT_TYPE_INTEGER_VALUE; +} /* ecma_is_value_integer_number */ + +/** + * Check if both values are integer ecma-numbers. + * + * @return true - if both values contain integer ecma-number values, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_are_values_integer_numbers (ecma_value_t first_value, /**< first ecma value */ + ecma_value_t second_value) /**< second ecma value */ +{ + JERRY_STATIC_ASSERT (ECMA_DIRECT_TYPE_INTEGER_VALUE == 0, ecma_direct_type_integer_value_must_be_zero); + + return ((first_value | second_value) & ECMA_DIRECT_TYPE_MASK) == ECMA_DIRECT_TYPE_INTEGER_VALUE; +} /* ecma_are_values_integer_numbers */ + +/** + * Check if the value is floating-point ecma-number. + * + * @return true - if the value contains a floating-point ecma-number value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_float_number (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_FLOAT); +} /* ecma_is_value_float_number */ + +/** + * Check if the value is ecma-number. + * + * @return true - if the value contains ecma-number value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_number (ecma_value_t value) /**< ecma value */ +{ + return (ecma_is_value_integer_number (value) || ecma_is_value_float_number (value)); +} /* ecma_is_value_number */ + +JERRY_STATIC_ASSERT (((ECMA_TYPE_STRING | 0x4) == ECMA_TYPE_DIRECT_STRING), + ecma_type_string_and_direct_string_must_have_one_bit_difference); + +/** + * Check if the value is ecma-string. + * + * @return true - if the value contains ecma-string value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_string (ecma_value_t value) /**< ecma value */ +{ + return ((value & (ECMA_VALUE_TYPE_MASK - 0x4)) == ECMA_TYPE_STRING); +} /* ecma_is_value_string */ + +/** + * Check if the value is symbol. + * + * @return true - if the value contains symbol value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_symbol (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_SYMBOL); +} /* ecma_is_value_symbol */ + +/** + * Check if the value is a specific magic string. + * + * @return true - if the value the magic string value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_magic_string (ecma_value_t value, /**< ecma value */ + lit_magic_string_id_t id) /**< magic string id */ +{ + return value == ecma_make_magic_string_value (id); +} /* ecma_is_value_magic_string */ + +/** + * Check if the value is bigint. + * + * @return true - if the value contains bigint value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_bigint (ecma_value_t value) /**< ecma value */ +{ +#if JERRY_BUILTIN_BIGINT + return (ecma_get_value_type_field (value) == ECMA_TYPE_BIGINT); +#else /* !JERRY_BUILTIN_BIGINT */ + JERRY_UNUSED (value); + return false; +#endif /* JERRY_BUILTIN_BIGINT */ +} /* ecma_is_value_bigint */ + +/** + * Check if the value can be property name. + * + * @return true - if the value can be property name value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_prop_name (ecma_value_t value) /**< ecma value */ +{ + return ecma_is_value_string (value) || ecma_is_value_symbol (value); +} /* ecma_is_value_prop_name */ + +/** + * Check if the value is direct ecma-string. + * + * @return true - if the value contains direct ecma-string value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_direct_string (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT_STRING); +} /* ecma_is_value_direct_string */ + +/** + * Check if the value is non-direct ecma-string. + * + * @return true - if the value contains non-direct ecma-string value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_non_direct_string (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_STRING); +} /* ecma_is_value_non_direct_string */ + +/** + * Check if the value is object. + * + * @return true - if the value contains object value, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_object (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_OBJECT); +} /* ecma_is_value_object */ + +/** + * Check if the value is error reference. + * + * @return true - if the value contains an error reference, + * false - otherwise + */ +bool JERRY_ATTR_CONST +ecma_is_value_exception (ecma_value_t value) /**< ecma value */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_ERROR); +} /* ecma_is_value_exception */ + +/** + * Debug assertion that specified value's type is one of ECMA-defined + * script-visible types, i.e.: undefined, null, boolean, number, string, object. + */ +void +ecma_check_value_type_is_spec_defined (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_undefined (value) || ecma_is_value_null (value) || ecma_is_value_boolean (value) + || ecma_is_value_number (value) || ecma_is_value_string (value) || ecma_is_value_bigint (value) + || ecma_is_value_symbol (value) || ecma_is_value_object (value)); +} /* ecma_check_value_type_is_spec_defined */ + +/** + * Checks if the given argument is an array or not. + * + * @return ECMA_VALUE_ERROR- if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether 'arg' is an array object + */ +ecma_value_t +ecma_is_value_array (ecma_value_t arg) /**< argument */ +{ + if (!ecma_is_value_object (arg)) + { + return ECMA_VALUE_FALSE; + } + + ecma_object_t *arg_obj_p = ecma_get_object_from_value (arg); + + if (ecma_get_object_base_type (arg_obj_p) == ECMA_OBJECT_BASE_TYPE_ARRAY) + { + return ECMA_VALUE_TRUE; + } + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (arg_obj_p)) + { + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) arg_obj_p; + + if (proxy_obj_p->handler == ECMA_VALUE_NULL) + { + return ecma_raise_type_error (ECMA_ERR_PROXY_HANDLER_IS_NULL_FOR_ISARRAY_OPERATION); + } + + return ecma_is_value_array (proxy_obj_p->target); + } +#endif /* JERRY_BUILTIN_PROXY */ + + return ECMA_VALUE_FALSE; +} /* ecma_is_value_array */ + +/** + * Creates an ecma value from the given raw boolean. + * + * @return boolean ecma_value + */ +ecma_value_t JERRY_ATTR_CONST +ecma_make_boolean_value (bool boolean_value) /**< raw bool value from which the ecma value will be created */ +{ + return boolean_value ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE; +} /* ecma_make_boolean_value */ + +/** + * Encode an integer number into an ecma-value without allocating memory + * + * Note: + * The value must fit into the range of allowed ecma integer values + * + * @return ecma-value + */ +ecma_value_t JERRY_ATTR_CONST +ecma_make_integer_value (ecma_integer_value_t integer_value) /**< integer number to be encoded */ +{ + JERRY_ASSERT (ECMA_IS_INTEGER_NUMBER (integer_value)); + + return (((ecma_value_t) integer_value) << ECMA_DIRECT_SHIFT) | ECMA_DIRECT_TYPE_INTEGER_VALUE; +} /* ecma_make_integer_value */ + +/** + * Allocate and initialize a new float number without checks. + * + * @return ecma-value + */ +static ecma_value_t +ecma_create_float_number (ecma_number_t ecma_number) /**< value of the float number */ +{ + ecma_number_t *ecma_num_p = ecma_alloc_number (); + + *ecma_num_p = ecma_number; + + return ecma_pointer_to_ecma_value (ecma_num_p) | ECMA_TYPE_FLOAT; +} /* ecma_create_float_number */ + +/** + * Encode float number without checks. + * + * @return ecma-value + */ +ecma_value_t +ecma_make_float_value (ecma_number_t *ecma_num_p) /**< pointer to the float number */ +{ + return ecma_pointer_to_ecma_value (ecma_num_p) | ECMA_TYPE_FLOAT; +} /* ecma_make_float_value */ + +/** + * Create a new NaN value. + * + * @return ecma-value + */ +ecma_value_t JERRY_ATTR_CONST +ecma_make_nan_value (void) +{ + return ecma_create_float_number (ecma_number_make_nan ()); +} /* ecma_make_nan_value */ + +/** + * Checks whether the passed number is +0.0 + * + * @return true, if it is +0.0, false otherwise + */ +static inline bool JERRY_ATTR_CONST +ecma_is_number_equal_to_positive_zero (ecma_number_t ecma_number) /**< number */ +{ + return ecma_number_to_binary (ecma_number) == ECMA_NUMBER_BINARY_ZERO; +} /* ecma_is_number_equal_to_positive_zero */ + +/** + * Encode a property length number into an ecma-value + * + * @return ecma-value + */ +ecma_value_t +ecma_make_length_value (ecma_length_t number) /**< number to be encoded */ +{ + if (number <= ECMA_INTEGER_NUMBER_MAX) + { + return ecma_make_integer_value ((ecma_integer_value_t) number); + } + + return ecma_create_float_number ((ecma_number_t) number); +} /* ecma_make_length_value */ + +/** + * Encode a number into an ecma-value + * + * @return ecma-value + */ +ecma_value_t +ecma_make_number_value (ecma_number_t ecma_number) /**< number to be encoded */ +{ + ecma_integer_value_t integer_value = (ecma_integer_value_t) ecma_number; + + if ((ecma_number_t) integer_value == ecma_number + && ((integer_value == 0) ? ecma_is_number_equal_to_positive_zero (ecma_number) + : ECMA_IS_INTEGER_NUMBER (integer_value))) + { + return ecma_make_integer_value (integer_value); + } + + return ecma_create_float_number (ecma_number); +} /* ecma_make_number_value */ + +/** + * Encode an int32 number into an ecma-value + * + * @return ecma-value + */ +ecma_value_t +ecma_make_int32_value (int32_t int32_number) /**< int32 number to be encoded */ +{ + if (ECMA_IS_INTEGER_NUMBER (int32_number)) + { + return ecma_make_integer_value ((ecma_integer_value_t) int32_number); + } + + return ecma_create_float_number ((ecma_number_t) int32_number); +} /* ecma_make_int32_value */ + +/** + * Encode an unsigned int32 number into an ecma-value + * + * @return ecma-value + */ +ecma_value_t +ecma_make_uint32_value (uint32_t uint32_number) /**< uint32 number to be encoded */ +{ + if (uint32_number <= ECMA_INTEGER_NUMBER_MAX) + { + return ecma_make_integer_value ((ecma_integer_value_t) uint32_number); + } + + return ecma_create_float_number ((ecma_number_t) uint32_number); +} /* ecma_make_uint32_value */ + +/** + * String value constructor + * + * @return ecma-value representation of the string argument + */ +ecma_value_t JERRY_ATTR_PURE +ecma_make_string_value (const ecma_string_t *ecma_string_p) /**< string to reference in value */ +{ + JERRY_ASSERT (ecma_string_p != NULL); + JERRY_ASSERT (!ecma_prop_name_is_symbol ((ecma_string_t *) ecma_string_p)); + + if ((((uintptr_t) ecma_string_p) & ECMA_VALUE_TYPE_MASK) != 0) + { + return (ecma_value_t) (uintptr_t) ecma_string_p; + } + + return ecma_pointer_to_ecma_value (ecma_string_p) | ECMA_TYPE_STRING; +} /* ecma_make_string_value */ + +/** + * Symbol value constructor + * + * @return ecma-value representation of the string argument + */ +ecma_value_t JERRY_ATTR_PURE +ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p) /**< symbol to reference in value */ +{ + JERRY_ASSERT (ecma_symbol_p != NULL); + JERRY_ASSERT (ecma_prop_name_is_symbol ((ecma_string_t *) ecma_symbol_p)); + + return ecma_pointer_to_ecma_value (ecma_symbol_p) | ECMA_TYPE_SYMBOL; +} /* ecma_make_symbol_value */ + +/** + * Property-name value constructor + * + * @return ecma-value representation of a property name argument + */ +ecma_value_t JERRY_ATTR_PURE +ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p) /**< property name to reference in value */ +{ + JERRY_ASSERT (ecma_prop_name_p != NULL); + + if (ecma_prop_name_is_symbol ((ecma_string_t *) ecma_prop_name_p)) + { + return ecma_make_symbol_value (ecma_prop_name_p); + } + + return ecma_make_string_value (ecma_prop_name_p); +} /* ecma_make_prop_name_value */ + +/** + * String value constructor + * + * @return ecma-value representation of the string argument + */ +ecma_value_t JERRY_ATTR_PURE +ecma_make_magic_string_value (lit_magic_string_id_t id) /**< magic string id */ +{ + return (ecma_value_t) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_MAGIC, (uintptr_t) id); +} /* ecma_make_magic_string_value */ + +/** + * Object value constructor + * + * @return ecma-value representation of the object argument + */ +ecma_value_t JERRY_ATTR_PURE +ecma_make_object_value (const ecma_object_t *object_p) /**< object to reference in value */ +{ + JERRY_ASSERT (object_p != NULL); + + return ecma_pointer_to_ecma_value (object_p) | ECMA_TYPE_OBJECT; +} /* ecma_make_object_value */ + +/** + * Error reference constructor + * + * @return ecma-value representation of the Error reference + */ +ecma_value_t JERRY_ATTR_PURE +ecma_make_extended_primitive_value (const ecma_extended_primitive_t *primitive_p, /**< extended primitive value */ + uint32_t type) /**< ecma type of extended primitive value */ +{ + JERRY_ASSERT (primitive_p != NULL); +#if JERRY_BUILTIN_BIGINT + JERRY_ASSERT (primitive_p != ECMA_BIGINT_POINTER_TO_ZERO); +#endif /* JERRY_BUILTIN_BIGINT */ + JERRY_ASSERT (type == ECMA_TYPE_BIGINT || type == ECMA_TYPE_ERROR); + + return ecma_pointer_to_ecma_value (primitive_p) | type; +} /* ecma_make_extended_primitive_value */ + +/** + * Get integer value from an integer ecma value + * + * @return integer value + */ +ecma_integer_value_t JERRY_ATTR_CONST +ecma_get_integer_from_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_integer_number (value)); + + return ((ecma_integer_value_t) value) >> ECMA_DIRECT_SHIFT; +} /* ecma_get_integer_from_value */ + +/** + * Get floating point value from an ecma value + * + * @return floating point value + */ +ecma_number_t JERRY_ATTR_PURE +ecma_get_float_from_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_FLOAT); + + return *(ecma_number_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_float_from_value */ + +/** + * Get floating point value pointer from an ecma value + * + * @return floating point value + */ +ecma_number_t *JERRY_ATTR_PURE +ecma_get_pointer_from_float_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_FLOAT); + + return (ecma_number_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_pointer_from_float_value */ + +/** + * Get floating point value from an ecma value + * + * @return floating point value + */ +ecma_number_t JERRY_ATTR_PURE +ecma_get_number_from_value (ecma_value_t value) /**< ecma value */ +{ + if (ecma_is_value_integer_number (value)) + { + return (ecma_number_t) ecma_get_integer_from_value (value); + } + + return ecma_get_float_from_value (value); +} /* ecma_get_number_from_value */ + +/** + * Get pointer to ecma-string from ecma value + * + * @return the string pointer + */ +ecma_string_t *JERRY_ATTR_PURE +ecma_get_string_from_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_string (value)); + + if ((value & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_DIRECT_STRING) + { + return (ecma_string_t *) (uintptr_t) value; + } + + return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_string_from_value */ + +/** + * Get pointer to ecma-string from ecma value + * + * @return the string pointer + */ +ecma_string_t *JERRY_ATTR_PURE +ecma_get_symbol_from_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_symbol (value)); + + return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_symbol_from_value */ + +/** + * Get pointer to a property name from ecma value + * + * @return the string pointer + */ +ecma_string_t *JERRY_ATTR_PURE +ecma_get_prop_name_from_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_prop_name (value)); + + if ((value & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_DIRECT_STRING) + { + return (ecma_string_t *) (uintptr_t) value; + } + + return (ecma_string_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_prop_name_from_value */ + +/** + * Get pointer to ecma-object from ecma value + * + * @return the pointer + */ +ecma_object_t *JERRY_ATTR_PURE +ecma_get_object_from_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_object (value)); + + return (ecma_object_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_object_from_value */ + +/** + * Get pointer to error reference from ecma value + * + * @return the pointer + */ +ecma_extended_primitive_t *JERRY_ATTR_PURE +ecma_get_extended_primitive_from_value (ecma_value_t value) /**< ecma value */ +{ +#if JERRY_BUILTIN_BIGINT + JERRY_ASSERT (value != ECMA_BIGINT_ZERO); +#endif /* JERRY_BUILTIN_BIGINT */ + JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_BIGINT + || ecma_get_value_type_field (value) == ECMA_TYPE_ERROR); + + return (ecma_extended_primitive_t *) ecma_get_pointer_from_ecma_value (value); +} /* ecma_get_extended_primitive_from_value */ + +/** + * Invert a boolean value + * + * @return ecma value + */ +ecma_value_t JERRY_ATTR_CONST +ecma_invert_boolean_value (ecma_value_t value) /**< ecma value */ +{ + JERRY_ASSERT (ecma_is_value_boolean (value)); + + return (value ^ (1 << ECMA_DIRECT_SHIFT)); +} /* ecma_invert_boolean_value */ + +/** + * Copy ecma value. + * + * @return copy of the given value + */ +ecma_value_t +ecma_copy_value (ecma_value_t value) /**< value description */ +{ + switch (ecma_get_value_type_field (value)) + { + case ECMA_TYPE_FLOAT: + { + ecma_number_t *num_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (value); + ecma_number_t *new_num_p = ecma_alloc_number (); + + *new_num_p = *num_p; + + return ecma_make_float_value (new_num_p); + } + case ECMA_TYPE_SYMBOL: + case ECMA_TYPE_STRING: + { + ecma_string_t *string_p = (ecma_string_t *) ecma_get_pointer_from_ecma_value (value); + ecma_ref_ecma_string_non_direct (string_p); + return value; + } +#if JERRY_BUILTIN_BIGINT + case ECMA_TYPE_BIGINT: + { + if (value != ECMA_BIGINT_ZERO) + { + ecma_ref_extended_primitive (ecma_get_extended_primitive_from_value (value)); + } + return value; + } +#endif /* JERRY_BUILTIN_BIGINT */ + case ECMA_TYPE_OBJECT: + { + ecma_ref_object_inline (ecma_get_object_from_value (value)); + return value; + } + default: + { + JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT + || ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT_STRING); + + return value; + } + } +} /* ecma_copy_value */ + +/** + * Copy ecma value. + * + * Note: + * this function is similar to ecma_copy_value, but it is + * faster for direct values since no function call is performed. + * It also increases the binary size so it is recommended for + * critical code paths only. + * + * @return copy of the given value + */ +ecma_value_t +ecma_fast_copy_value (ecma_value_t value) /**< value description */ +{ + return (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT) ? value : ecma_copy_value (value); +} /* ecma_fast_copy_value */ + +/** + * Copy the ecma value if not an object + * + * @return copy of the given value + */ +ecma_value_t +ecma_copy_value_if_not_object (ecma_value_t value) /**< value description */ +{ + if (!ecma_is_value_object (value)) + { + return ecma_copy_value (value); + } + + return value; +} /* ecma_copy_value_if_not_object */ + +/** + * Increase reference counter of a value if it is an object. + * + * @return void + */ +void +ecma_ref_if_object (ecma_value_t value) /**< value description */ +{ + if (ecma_is_value_object (value)) + { + ecma_ref_object (ecma_get_object_from_value (value)); + } +} /* ecma_ref_if_object */ + +/** + * Decrease reference counter of a value if it is an object. + * + * @return void + */ +void +ecma_deref_if_object (ecma_value_t value) /**< value description */ +{ + if (ecma_is_value_object (value)) + { + ecma_deref_object (ecma_get_object_from_value (value)); + } +} /* ecma_deref_if_object */ + +/** + * Assign a new value to an ecma-value + * + * Note: + * value previously stored in the property is freed + */ +void +ecma_value_assign_value (ecma_value_t *value_p, /**< [in, out] ecma value */ + ecma_value_t ecma_value) /**< value to assign */ +{ + JERRY_STATIC_ASSERT (ECMA_TYPE_DIRECT == 0, ecma_type_direct_must_be_zero_for_the_next_check); + + if (*value_p == ecma_value) + { + return; + } + + if (ecma_get_value_type_field (ecma_value || *value_p) == ECMA_TYPE_DIRECT) + { + *value_p = ecma_value; + } + else if (ecma_is_value_float_number (ecma_value) && ecma_is_value_float_number (*value_p)) + { + const ecma_number_t *num_src_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (ecma_value); + ecma_number_t *num_dst_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (*value_p); + + *num_dst_p = *num_src_p; + } + else + { + ecma_free_value_if_not_object (*value_p); + *value_p = ecma_copy_value_if_not_object (ecma_value); + } +} /* ecma_value_assign_value */ + +/** + * Update the value of a float number to a new value + * + * Note: + * The original value is destroyed. + * + * @return updated ecma value + */ +ecma_value_t +ecma_update_float_number (ecma_value_t float_value, /**< original float value */ + ecma_number_t new_number) /**< updated number value */ +{ + JERRY_ASSERT (ecma_is_value_float_number (float_value)); + + ecma_integer_value_t integer_number = (ecma_integer_value_t) new_number; + ecma_number_t *number_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (float_value); + + if ((ecma_number_t) integer_number == new_number + && ((integer_number == 0) ? ecma_is_number_equal_to_positive_zero (new_number) + : ECMA_IS_INTEGER_NUMBER (integer_number))) + { + ecma_dealloc_number (number_p); + return ecma_make_integer_value (integer_number); + } + + *number_p = new_number; + return float_value; +} /* ecma_update_float_number */ + +/** + * Assign a float number to an ecma-value + * + * Note: + * value previously stored in the property is freed + */ +static void +ecma_value_assign_float_number (ecma_value_t *value_p, /**< [in, out] ecma value */ + ecma_number_t ecma_number) /**< number to assign */ +{ + if (ecma_is_value_float_number (*value_p)) + { + ecma_number_t *num_dst_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (*value_p); + + *num_dst_p = ecma_number; + return; + } + + if (ecma_get_value_type_field (*value_p) != ECMA_TYPE_DIRECT + && ecma_get_value_type_field (*value_p) != ECMA_TYPE_OBJECT) + { + ecma_free_value (*value_p); + } + + *value_p = ecma_create_float_number (ecma_number); +} /* ecma_value_assign_float_number */ + +/** + * Assign a number to an ecma-value + * + * Note: + * value previously stored in the property is freed + */ +void +ecma_value_assign_number (ecma_value_t *value_p, /**< [in, out] ecma value */ + ecma_number_t ecma_number) /**< number to assign */ +{ + ecma_integer_value_t integer_value = (ecma_integer_value_t) ecma_number; + + if ((ecma_number_t) integer_value == ecma_number + && ((integer_value == 0) ? ecma_is_number_equal_to_positive_zero (ecma_number) + : ECMA_IS_INTEGER_NUMBER (integer_value))) + { + if (ecma_get_value_type_field (*value_p) != ECMA_TYPE_DIRECT + && ecma_get_value_type_field (*value_p) != ECMA_TYPE_OBJECT) + { + ecma_free_value (*value_p); + } + *value_p = ecma_make_integer_value (integer_value); + return; + } + + ecma_value_assign_float_number (value_p, ecma_number); +} /* ecma_value_assign_number */ + +/** + * Free the ecma value + */ +void +ecma_free_value (ecma_value_t value) /**< value description */ +{ + switch (ecma_get_value_type_field (value)) + { + case ECMA_TYPE_FLOAT: + { + ecma_number_t *number_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (value); + ecma_dealloc_number (number_p); + break; + } + case ECMA_TYPE_SYMBOL: + case ECMA_TYPE_STRING: + { + ecma_string_t *string_p = (ecma_string_t *) ecma_get_pointer_from_ecma_value (value); + ecma_deref_ecma_string_non_direct (string_p); + break; + } + case ECMA_TYPE_OBJECT: + { + ecma_deref_object (ecma_get_object_from_value (value)); + break; + } +#if JERRY_BUILTIN_BIGINT + case ECMA_TYPE_BIGINT: + { + if (value != ECMA_BIGINT_ZERO) + { + ecma_deref_bigint (ecma_get_extended_primitive_from_value (value)); + } + + break; + } +#endif /* JERRY_BUILTIN_BIGINT */ + default: + { + JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT + || ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT_STRING); + + /* no memory is allocated */ + break; + } + } +} /* ecma_free_value */ + +/** + * Free the ecma value + * + * Note: + * this function is similar to ecma_free_value, but it is + * faster for direct values since no function call is performed. + * It also increases the binary size so it is recommended for + * critical code paths only. + * + * @return void + */ +void +ecma_fast_free_value (ecma_value_t value) /**< value description */ +{ + if (ecma_get_value_type_field (value) != ECMA_TYPE_DIRECT) + { + ecma_free_value (value); + } +} /* ecma_fast_free_value */ + +/** + * Free the ecma value if not an object + */ +void +ecma_free_value_if_not_object (ecma_value_t value) /**< value description */ +{ + if (ecma_get_value_type_field (value) != ECMA_TYPE_OBJECT) + { + ecma_free_value (value); + } +} /* ecma_free_value_if_not_object */ + +/** + * Free an ecma-value object + * + * @return void + */ +void +ecma_free_object (ecma_value_t value) /**< value description */ +{ + ecma_deref_object (ecma_get_object_from_value (value)); +} /* ecma_free_object */ + +/** + * Free an ecma-value number + * + * @return void + */ +void +ecma_free_number (ecma_value_t value) /**< value description */ +{ + JERRY_ASSERT (ecma_is_value_number (value)); + + if (ecma_is_value_float_number (value)) + { + ecma_number_t *number_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (value); + ecma_dealloc_number (number_p); + } +} /* ecma_free_number */ + +/** + * Get the literal id associated with the given ecma_value type. + * This operation is equivalent to the JavaScript 'typeof' operator. + * + * @returns one of the following value: + * - LIT_MAGIC_STRING_UNDEFINED + * - LIT_MAGIC_STRING_OBJECT + * - LIT_MAGIC_STRING_BOOLEAN + * - LIT_MAGIC_STRING_NUMBER + * - LIT_MAGIC_STRING_STRING + * - LIT_MAGIC_STRING_FUNCTION + */ +lit_magic_string_id_t +ecma_get_typeof_lit_id (ecma_value_t value) /**< input ecma value */ +{ + lit_magic_string_id_t ret_value = LIT_MAGIC_STRING__EMPTY; + + if (ecma_is_value_undefined (value)) + { + ret_value = LIT_MAGIC_STRING_UNDEFINED; + } + else if (ecma_is_value_null (value)) + { + ret_value = LIT_MAGIC_STRING_OBJECT; + } + else if (ecma_is_value_boolean (value)) + { + ret_value = LIT_MAGIC_STRING_BOOLEAN; + } + else if (ecma_is_value_number (value)) + { + ret_value = LIT_MAGIC_STRING_NUMBER; + } + else if (ecma_is_value_string (value)) + { + ret_value = LIT_MAGIC_STRING_STRING; + } + else if (ecma_is_value_symbol (value)) + { + ret_value = LIT_MAGIC_STRING_SYMBOL; + } +#if JERRY_BUILTIN_BIGINT + else if (ecma_is_value_bigint (value)) + { + ret_value = LIT_MAGIC_STRING_BIGINT; + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + JERRY_ASSERT (ecma_is_value_object (value)); + + ret_value = ecma_op_is_callable (value) ? LIT_MAGIC_STRING_FUNCTION : LIT_MAGIC_STRING_OBJECT; + } + + JERRY_ASSERT (ret_value != LIT_MAGIC_STRING__EMPTY); + + return ret_value; +} /* ecma_get_typeof_lit_id */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers.cpp new file mode 100644 index 0000000..0604fee --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers.cpp @@ -0,0 +1,1676 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-helpers.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtins.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-lcache.h" +#include "ecma-property-hashmap.h" + +#include "byte-code.h" +#include "jcontext.h" +#include "jrt-bit-fields.h" +#include "re-compiler.h" + + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +JERRY_STATIC_ASSERT (((int)ECMA_OBJECT_TYPE_MASK >= ((int)ECMA_OBJECT_TYPE__MAX) - 1), + ecma_object_types_must_be_lower_than_the_container_mask); + +JERRY_STATIC_ASSERT (((int)ECMA_OBJECT_TYPE_MASK >= (int)ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX), + ecma_lexical_environment_types_must_be_lower_than_the_container_mask); + +JERRY_STATIC_ASSERT (((int)ECMA_OBJECT_FLAG_EXTENSIBLE == ((int)ECMA_OBJECT_TYPE_MASK) + 1), + ecma_extensible_flag_must_follow_the_object_type); + +JERRY_STATIC_ASSERT ((ECMA_OBJECT_REF_ONE == (ECMA_OBJECT_FLAG_EXTENSIBLE << 1)), + ecma_object_ref_one_must_follow_the_extensible_flag); + +JERRY_STATIC_ASSERT (((ECMA_OBJECT_MAX_REF + ECMA_OBJECT_REF_ONE) == ECMA_OBJECT_REF_MASK), + ecma_object_max_ref_does_not_fill_the_remaining_bits); + +JERRY_STATIC_ASSERT (((ECMA_OBJECT_REF_MASK & (ECMA_OBJECT_TYPE_MASK | ECMA_OBJECT_FLAG_EXTENSIBLE)) == 0), + ecma_object_ref_mask_overlaps_with_object_type_or_extensible); + +JERRY_STATIC_ASSERT ((ECMA_PROPERTY_FLAGS_MASK == ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE), + ecma_property_flags_mask_must_use_the_configurable_enumerable_writable_flags); + +/* These checks are needed by ecma_get_object_base_type. */ +JERRY_STATIC_ASSERT (((int) ECMA_OBJECT_TYPE_BUILT_IN_GENERAL == ((int) ECMA_OBJECT_TYPE_GENERAL | 0x1)) + && (((int) ECMA_OBJECT_TYPE_GENERAL & 0x1) == 0), + ecma_object_type_built_in_general_has_unexpected_value); +JERRY_STATIC_ASSERT (((int) ECMA_OBJECT_TYPE_BUILT_IN_CLASS == ((int) ECMA_OBJECT_TYPE_CLASS | 0x1)) + && (((int) ECMA_OBJECT_TYPE_CLASS & 0x1) == 0), + ecma_object_type_built_in_class_has_unexpected_value); +JERRY_STATIC_ASSERT (((int) ECMA_OBJECT_TYPE_BUILT_IN_ARRAY == ((int) ECMA_OBJECT_TYPE_ARRAY | 0x1)) + && (((int) ECMA_OBJECT_TYPE_ARRAY & 0x1) == 0), + ecma_object_type_built_in_array_has_unexpected_value); + +/** + * Create an object with specified prototype object + * (or NULL prototype if there is not prototype for the object) + * and value of 'Extensible' attribute. + * + * Reference counter's value will be set to one. + * + * @return pointer to the object's descriptor + */ +ecma_object_t * +ecma_create_object (ecma_object_t *prototype_object_p, /**< pointer to prototype of the object (or NULL) */ + size_t ext_object_size, /**< size of extended objects */ + ecma_object_type_t type) /**< object type */ +{ + ecma_object_t *new_object_p; + + if (ext_object_size > 0) + { + new_object_p = (ecma_object_t *) ecma_alloc_extended_object (ext_object_size); + } + else + { + new_object_p = ecma_alloc_object (); + } + + new_object_p->type_flags_refs = (ecma_object_descriptor_t) (type | ECMA_OBJECT_FLAG_EXTENSIBLE); + + ecma_init_gc_info (new_object_p); + + new_object_p->u1.property_list_cp = JMEM_CP_NULL; + + ECMA_SET_POINTER (new_object_p->u2.prototype_cp, prototype_object_p); + + return new_object_p; +} /* ecma_create_object */ + +/** + * Create a declarative lexical environment with specified outer lexical environment + * (or NULL if the environment is not nested). + * + * See also: ECMA-262 v5, 10.2.1.1 + * + * Reference counter's value will be set to one. + * + * @return pointer to the descriptor of lexical environment + */ +ecma_object_t * +ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p) /**< outer lexical environment */ +{ + ecma_object_t *new_lexical_environment_p = ecma_alloc_object (); + + new_lexical_environment_p->type_flags_refs = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE; + + ecma_init_gc_info (new_lexical_environment_p); + + new_lexical_environment_p->u1.property_list_cp = JMEM_CP_NULL; + + ECMA_SET_POINTER (new_lexical_environment_p->u2.outer_reference_cp, outer_lexical_environment_p); + + return new_lexical_environment_p; +} /* ecma_create_decl_lex_env */ + +/** + * Create a object lexical environment with specified outer lexical environment + * (or NULL if the environment is not nested), and binding object. + * + * See also: ECMA-262 v5, 10.2.1.2 + * + * Reference counter's value will be set to one. + * + * @return pointer to the descriptor of lexical environment + */ +ecma_object_t * +ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */ + ecma_object_t *binding_obj_p) /**< binding object */ +{ + JERRY_ASSERT (binding_obj_p != NULL && !ecma_is_lexical_environment (binding_obj_p)); + + ecma_object_t *new_lexical_environment_p = ecma_alloc_object (); + + new_lexical_environment_p->type_flags_refs = ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND; + + ecma_init_gc_info (new_lexical_environment_p); + + ECMA_SET_NON_NULL_POINTER (new_lexical_environment_p->u1.bound_object_cp, binding_obj_p); + + ECMA_SET_POINTER (new_lexical_environment_p->u2.outer_reference_cp, outer_lexical_environment_p); + + return new_lexical_environment_p; +} /* ecma_create_object_lex_env */ + +/** + * Create a lexical environment with a specified size. + * + * @return pointer to the descriptor of the lexical environment + */ +ecma_object_t * +ecma_create_lex_env_class (ecma_object_t *outer_lexical_environment_p, /**< outer lexical environment */ + size_t lexical_env_size) /**< size of the lexical environment */ +{ + ecma_object_t *new_lexical_environment_p; + + ecma_object_descriptor_t type_flags_refs = ECMA_LEXICAL_ENVIRONMENT_CLASS; + + if (lexical_env_size > 0) + { + new_lexical_environment_p = (ecma_object_t *) ecma_alloc_extended_object (lexical_env_size); + type_flags_refs |= ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA; + } + else + { + new_lexical_environment_p = ecma_alloc_object (); + } + + new_lexical_environment_p->type_flags_refs = type_flags_refs; + + ecma_init_gc_info (new_lexical_environment_p); + + new_lexical_environment_p->u1.property_list_cp = JMEM_CP_NULL; + + ECMA_SET_POINTER (new_lexical_environment_p->u2.outer_reference_cp, outer_lexical_environment_p); + + return new_lexical_environment_p; +} /* ecma_create_lex_env_class */ + +/** + * Check if the object is lexical environment. + * + * @return true - if object is a lexical environment + * false - otherwise + */ +bool JERRY_ATTR_PURE +ecma_is_lexical_environment (const ecma_object_t *object_p) /**< object or lexical environment */ +{ + JERRY_ASSERT (object_p != NULL); + + return (object_p->type_flags_refs & ECMA_OBJECT_TYPE_MASK) >= ECMA_LEXICAL_ENVIRONMENT_TYPE_START; +} /* ecma_is_lexical_environment */ + +/** + * Set value of [[Extensible]] object's internal property. + */ +void +ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (!ecma_is_lexical_environment (object_p)); + + object_p->type_flags_refs |= ECMA_OBJECT_FLAG_EXTENSIBLE; +} /* ecma_op_ordinary_object_set_extensible */ + +/** + * Get the internal type of an object. + * + * @return type of the object (ecma_object_type_t) + */ +ecma_object_type_t JERRY_ATTR_PURE +ecma_get_object_type (const ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (!ecma_is_lexical_environment (object_p)); + + return (ecma_object_type_t) (object_p->type_flags_refs & ECMA_OBJECT_TYPE_MASK); +} /* ecma_get_object_type */ + +/** + * Get the internal base type of an object. + * + * @return base type of the object (ecma_object_base_type_t) + */ +ecma_object_base_type_t JERRY_ATTR_PURE +ecma_get_object_base_type (const ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (!ecma_is_lexical_environment (object_p)); + + return (ecma_object_base_type_t) (object_p->type_flags_refs & (ECMA_OBJECT_TYPE_MASK - 0x1)); +} /* ecma_get_object_base_type */ + +/** + * Get value of an object if the class matches + * + * @return value of the object if the class matches + * ECMA_VALUE_NOT_FOUND otherwise + */ +bool +ecma_object_class_is (ecma_object_t *object_p, /**< object */ + ecma_object_class_type_t class_id) /**< class id */ +{ + if (ecma_get_object_base_type (object_p) == ECMA_OBJECT_BASE_TYPE_CLASS) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ext_object_p->u.cls.type == (uint8_t) class_id) + { + return true; + } + } + + return false; +} /* ecma_object_class_is */ + +/** + * Get type of lexical environment. + * + * @return type of the lexical environment (ecma_lexical_environment_type_t) + */ +ecma_lexical_environment_type_t JERRY_ATTR_PURE +ecma_get_lex_env_type (const ecma_object_t *object_p) /**< lexical environment */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (ecma_is_lexical_environment (object_p)); + + return (ecma_lexical_environment_type_t) (object_p->type_flags_refs & ECMA_OBJECT_TYPE_MASK); +} /* ecma_get_lex_env_type */ + +/** + * Get lexical environment's bound object. + * + * @return pointer to ecma object + */ +ecma_object_t *JERRY_ATTR_PURE +ecma_get_lex_env_binding_object (const ecma_object_t *object_p) /**< object-bound lexical environment */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (ecma_is_lexical_environment (object_p)); + JERRY_ASSERT (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND + || (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && !ECMA_LEX_ENV_CLASS_IS_MODULE (object_p))); + + return ECMA_GET_NON_NULL_POINTER (ecma_object_t, object_p->u1.bound_object_cp); +} /* ecma_get_lex_env_binding_object */ + +/** + * Create a new lexical environment with the same property list as the passed lexical environment + * + * @return pointer to the newly created lexical environment + */ +ecma_object_t * +ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, /**< declarative lexical environment */ + bool copy_values) /**< copy property values as well */ +{ + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + + ecma_object_t *outer_lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + ecma_object_t *new_lex_env_p = ecma_create_decl_lex_env (outer_lex_env_p); + + jmem_cpointer_t prop_iter_cp = lex_env_p->u1.property_list_cp; + ecma_property_header_t *prop_iter_p; + + JERRY_ASSERT (prop_iter_cp != JMEM_CP_NULL); + +#if JERRY_PROPERTY_HASHMAP + prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prop_iter_cp = prop_iter_p->next_property_cp; + } + + JERRY_ASSERT (prop_iter_cp != JMEM_CP_NULL); +#endif /* JERRY_PROPERTY_HASHMAP */ + + do + { + prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW_DATA (prop_iter_p->types[i])); + + uint8_t prop_attributes = (uint8_t) (prop_iter_p->types[i] & ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_string_t *name_p = ecma_string_from_property_name (prop_iter_p->types[i], prop_pair_p->names_cp[i]); + + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (new_lex_env_p, name_p, prop_attributes, NULL); + + ecma_deref_ecma_string (name_p); + + JERRY_ASSERT (property_value_p->value == ECMA_VALUE_UNDEFINED); + + if (copy_values) + { + property_value_p->value = ecma_copy_value_if_not_object (prop_pair_p->values[i].value); + } + else + { + property_value_p->value = ECMA_VALUE_UNINITIALIZED; + } + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } while (prop_iter_cp != JMEM_CP_NULL); + + ecma_deref_object (lex_env_p); + return new_lex_env_p; +} /* ecma_clone_decl_lexical_environment */ + +/** + * Create a property in an object and link it into + * the object's properties' linked-list (at start of the list). + * + * @return pointer to the newly created property value + */ +static ecma_property_value_t * +ecma_create_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *name_p, /**< property name */ + uint8_t type_and_flags, /**< type and flags, see ecma_property_info_t */ + ecma_property_value_t value, /**< property value */ + ecma_property_t **out_prop_p) /**< [out] the property is also returned + * if this field is non-NULL */ +{ + JERRY_ASSERT (ECMA_PROPERTY_PAIR_ITEM_COUNT == 2); + JERRY_ASSERT (name_p != NULL); + JERRY_ASSERT (object_p != NULL); + + jmem_cpointer_t *property_list_head_p = &object_p->u1.property_list_cp; + + if (*property_list_head_p != ECMA_NULL_POINTER) + { + /* If the first entry is free (deleted), it is reused. */ + ecma_property_header_t *first_property_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, *property_list_head_p); + +#if JERRY_PROPERTY_HASHMAP + bool has_hashmap = false; + + if (first_property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + property_list_head_p = &first_property_p->next_property_cp; + first_property_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, *property_list_head_p); + has_hashmap = true; + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (first_property_p)); + + if (first_property_p->types[0] == ECMA_PROPERTY_TYPE_DELETED) + { + ecma_property_pair_t *first_property_pair_p = (ecma_property_pair_t *) first_property_p; + + ecma_property_t name_type; + first_property_pair_p->names_cp[0] = ecma_string_to_property_name (name_p, &name_type); + first_property_p->types[0] = (ecma_property_t) (type_and_flags | name_type); + + ecma_property_t *property_p = first_property_p->types + 0; + + JERRY_ASSERT (ECMA_PROPERTY_VALUE_PTR (property_p) == first_property_pair_p->values + 0); + + if (out_prop_p != NULL) + { + *out_prop_p = property_p; + } + + first_property_pair_p->values[0] = value; + +#if JERRY_PROPERTY_HASHMAP + /* The property must be fully initialized before ecma_property_hashmap_insert + * is called, because the insert operation may reallocate the hashmap, and + * that triggers garbage collection which scans all properties of all objects. + * A not fully initialized but queued property may cause a crash. */ + + if (has_hashmap) + { + ecma_property_hashmap_insert (object_p, name_p, first_property_pair_p, 0); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + return first_property_pair_p->values + 0; + } + } + + /* Otherwise we create a new property pair and use its second value. */ + ecma_property_pair_t *first_property_pair_p = ecma_alloc_property_pair (); + + /* Need to query property_list_head_p again and recheck the existence + * of property hashmap, because ecma_alloc_property_pair may delete them. */ + property_list_head_p = &object_p->u1.property_list_cp; +#if JERRY_PROPERTY_HASHMAP + bool has_hashmap = false; + + if (*property_list_head_p != ECMA_NULL_POINTER) + { + ecma_property_header_t *first_property_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, *property_list_head_p); + + if (first_property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + property_list_head_p = &first_property_p->next_property_cp; + has_hashmap = true; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + /* Just copy the previous value (no need to decompress, compress). */ + first_property_pair_p->header.next_property_cp = *property_list_head_p; + first_property_pair_p->header.types[0] = ECMA_PROPERTY_TYPE_DELETED; + first_property_pair_p->names_cp[0] = LIT_INTERNAL_MAGIC_STRING_DELETED; + + ecma_property_t name_type; + first_property_pair_p->names_cp[1] = ecma_string_to_property_name (name_p, &name_type); + + first_property_pair_p->header.types[1] = (ecma_property_t) (type_and_flags | name_type); + + ECMA_SET_NON_NULL_POINTER (*property_list_head_p, &first_property_pair_p->header); + + ecma_property_t *property_p = first_property_pair_p->header.types + 1; + + JERRY_ASSERT (ECMA_PROPERTY_VALUE_PTR (property_p) == first_property_pair_p->values + 1); + + if (out_prop_p != NULL) + { + *out_prop_p = property_p; + } + + first_property_pair_p->values[1] = value; + +#if JERRY_PROPERTY_HASHMAP + /* See the comment before the other ecma_property_hashmap_insert above. */ + + if (has_hashmap) + { + ecma_property_hashmap_insert (object_p, name_p, first_property_pair_p, 1); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + return first_property_pair_p->values + 1; +} /* ecma_create_property */ + +/** + * Create named data property with given name, attributes and undefined value + * in the specified object. + * + * @return pointer to the newly created property value + */ +ecma_property_value_t * +ecma_create_named_data_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *name_p, /**< property name */ + uint8_t prop_attributes, /**< property attributes (See: ecma_property_flags_t) */ + ecma_property_t **out_prop_p) /**< [out] the property is also returned + * if this field is non-NULL */ +{ + JERRY_ASSERT (object_p != NULL && name_p != NULL); + JERRY_ASSERT (ecma_is_lexical_environment (object_p) || !ecma_op_object_is_fast_array (object_p)); + JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); + JERRY_ASSERT ((prop_attributes & ~ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_ENUMERABLE_WRITABLE) == 0); + + uint8_t type_and_flags = ECMA_PROPERTY_FLAG_DATA | prop_attributes; + + ecma_property_value_t value; + value.value = ECMA_VALUE_UNDEFINED; + + return ecma_create_property (object_p, name_p, type_and_flags, value, out_prop_p); +} /* ecma_create_named_data_property */ + +/** + * Create named accessor property with given name, attributes, getter and setter. + * + * @return pointer to the newly created property value + */ +ecma_property_value_t * +ecma_create_named_accessor_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *name_p, /**< property name */ + ecma_object_t *get_p, /**< getter */ + ecma_object_t *set_p, /**< setter */ + uint8_t prop_attributes, /**< property attributes */ + ecma_property_t **out_prop_p) /**< [out] the property is also returned + * if this field is non-NULL */ +{ + JERRY_ASSERT (object_p != NULL && name_p != NULL); + JERRY_ASSERT (ecma_is_lexical_environment (object_p) || !ecma_op_object_is_fast_array (object_p)); + JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); + JERRY_ASSERT ((prop_attributes & ~ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_ENUMERABLE) == 0); + + uint8_t type_and_flags = prop_attributes; + + ecma_property_value_t value; + ECMA_SET_POINTER (value.getter_setter_pair.getter_cp, get_p); + ECMA_SET_POINTER (value.getter_setter_pair.setter_cp, set_p); + + return ecma_create_property (object_p, name_p, type_and_flags, value, out_prop_p); +} /* ecma_create_named_accessor_property */ + +#if JERRY_MODULE_SYSTEM +/** + * Create property reference + */ +void +ecma_create_named_reference_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *name_p, /**< property name */ + ecma_value_t reference) /**< property reference */ +{ + JERRY_ASSERT (object_p != NULL && name_p != NULL); + JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); + JERRY_ASSERT ((ecma_is_lexical_environment (object_p) + && ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && ECMA_LEX_ENV_CLASS_IS_MODULE (object_p)) + || ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_MODULE_NAMESPACE)); + + uint8_t type_and_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE; + ecma_property_value_t value; + + value.value = reference; + + ecma_create_property (object_p, name_p, type_and_flags, value, NULL); +} /* ecma_create_named_reference_property */ + +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * Find named data property or named accessor property in a specified object. + * + * @return pointer to the property, if it is found, + * NULL - otherwise. + */ +ecma_property_t * +ecma_find_named_property (ecma_object_t *obj_p, /**< object to find property in */ + ecma_string_t *name_p) /**< property's name */ +{ + JERRY_ASSERT (obj_p != NULL); + JERRY_ASSERT (name_p != NULL); + JERRY_ASSERT (ecma_is_lexical_environment (obj_p) || !ecma_op_object_is_fast_array (obj_p)); + +#if JERRY_LCACHE + ecma_property_t *property_p = ecma_lcache_lookup (obj_p, name_p); + if (property_p != NULL) + { + return property_p; + } +#else /* !JERRY_LCACHE */ + ecma_property_t *property_p = NULL; +#endif /* JERRY_LCACHE */ + + jmem_cpointer_t prop_iter_cp = obj_p->u1.property_list_cp; + +#if JERRY_PROPERTY_HASHMAP + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + jmem_cpointer_t property_real_name_cp; + property_p = ecma_property_hashmap_find ((ecma_property_hashmap_t *) prop_iter_p, name_p, &property_real_name_cp); +#if JERRY_LCACHE + if (property_p != NULL && !ecma_is_property_lcached (property_p)) + { + ecma_lcache_insert (obj_p, property_real_name_cp, property_p); + } +#endif /* JERRY_LCACHE */ + return property_p; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + +#if JERRY_PROPERTY_HASHMAP + uint32_t steps = 0; +#endif /* JERRY_PROPERTY_HASHMAP */ + jmem_cpointer_t property_name_cp = ECMA_NULL_POINTER; + + if (ECMA_IS_DIRECT_STRING (name_p)) + { + ecma_property_t prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (name_p); + property_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (name_p); + + JERRY_ASSERT (prop_name_type > 0); + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + if (prop_pair_p->names_cp[0] == property_name_cp + && ECMA_PROPERTY_GET_NAME_TYPE (prop_iter_p->types[0]) == prop_name_type) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[0])); + + property_p = prop_iter_p->types + 0; + break; + } + + if (prop_pair_p->names_cp[1] == property_name_cp + && ECMA_PROPERTY_GET_NAME_TYPE (prop_iter_p->types[1]) == prop_name_type) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[1])); + + property_p = prop_iter_p->types + 1; + break; + } + +#if JERRY_PROPERTY_HASHMAP + steps++; +#endif /* JERRY_PROPERTY_HASHMAP */ + prop_iter_cp = prop_iter_p->next_property_cp; + } + } + else + { + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + if (ECMA_PROPERTY_GET_NAME_TYPE (prop_iter_p->types[0]) == ECMA_DIRECT_STRING_PTR) + { + property_name_cp = prop_pair_p->names_cp[0]; + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, property_name_cp); + + if (ecma_compare_ecma_non_direct_strings (name_p, prop_name_p)) + { + property_p = prop_iter_p->types + 0; + break; + } + } + + if (ECMA_PROPERTY_GET_NAME_TYPE (prop_iter_p->types[1]) == ECMA_DIRECT_STRING_PTR) + { + property_name_cp = prop_pair_p->names_cp[1]; + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, property_name_cp); + + if (ecma_compare_ecma_non_direct_strings (name_p, prop_name_p)) + { + property_p = prop_iter_p->types + 1; + break; + } + } + +#if JERRY_PROPERTY_HASHMAP + steps++; +#endif /* JERRY_PROPERTY_HASHMAP */ + prop_iter_cp = prop_iter_p->next_property_cp; + } + } + +#if JERRY_PROPERTY_HASHMAP + if (steps >= (ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE / 2)) + { + ecma_property_hashmap_create (obj_p); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + +#if JERRY_LCACHE + if (property_p != NULL && !ecma_is_property_lcached (property_p)) + { + ecma_lcache_insert (obj_p, property_name_cp, property_p); + } +#endif /* JERRY_LCACHE */ + + return property_p; +} /* ecma_find_named_property */ + +/** + * Get named data property or named access property in specified object. + * + * Warning: + * the property must exist + * + * @return pointer to the property, if it is found, + * NULL - otherwise. + */ +ecma_property_value_t * +ecma_get_named_data_property (ecma_object_t *obj_p, /**< object to find property in */ + ecma_string_t *name_p) /**< property's name */ +{ + JERRY_ASSERT (obj_p != NULL); + JERRY_ASSERT (name_p != NULL); + JERRY_ASSERT (ecma_is_lexical_environment (obj_p) || !ecma_op_object_is_fast_array (obj_p)); + + ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p); + + JERRY_ASSERT (property_p != NULL && ECMA_PROPERTY_IS_RAW_DATA (*property_p)); + + return ECMA_PROPERTY_VALUE_PTR (property_p); +} /* ecma_get_named_data_property */ + +/** + * Delete the object's property referenced by its value pointer. + * + * Note: specified property must be owned by specified object. + */ +void +ecma_delete_property (ecma_object_t *object_p, /**< object */ + ecma_property_value_t *prop_value_p) /**< property value reference */ +{ + jmem_cpointer_t cur_prop_cp = object_p->u1.property_list_cp; + + ecma_property_header_t *prev_prop_p = NULL; + +#if JERRY_PROPERTY_HASHMAP + ecma_property_hashmap_delete_status hashmap_status = ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP; + + if (cur_prop_cp != JMEM_CP_NULL) + { + ecma_property_header_t *cur_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, cur_prop_cp); + + if (cur_prop_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prev_prop_p = cur_prop_p; + cur_prop_cp = cur_prop_p->next_property_cp; + hashmap_status = ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (cur_prop_cp != JMEM_CP_NULL) + { + ecma_property_header_t *cur_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, cur_prop_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (cur_prop_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) cur_prop_p; + + for (uint32_t i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if ((prop_pair_p->values + i) == prop_value_p) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (cur_prop_p->types[i])); + +#if JERRY_PROPERTY_HASHMAP + if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP) + { + hashmap_status = ecma_property_hashmap_delete (object_p, prop_pair_p->names_cp[i], cur_prop_p->types + i); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + ecma_gc_free_property (object_p, prop_pair_p, i); + cur_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED; + prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED; + + JERRY_ASSERT (ECMA_PROPERTY_PAIR_ITEM_COUNT == 2); + + if (cur_prop_p->types[1 - i] != ECMA_PROPERTY_TYPE_DELETED) + { +#if JERRY_PROPERTY_HASHMAP + /* The other property is still valid. */ + if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP) + { + ecma_property_hashmap_free (object_p); + ecma_property_hashmap_create (object_p); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + return; + } + + JERRY_ASSERT (cur_prop_p->types[i] == ECMA_PROPERTY_TYPE_DELETED); + + if (prev_prop_p == NULL) + { + object_p->u1.property_list_cp = cur_prop_p->next_property_cp; + } + else + { + prev_prop_p->next_property_cp = cur_prop_p->next_property_cp; + } + + ecma_dealloc_property_pair ((ecma_property_pair_t *) cur_prop_p); + +#if JERRY_PROPERTY_HASHMAP + if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP) + { + ecma_property_hashmap_free (object_p); + ecma_property_hashmap_create (object_p); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + return; + } + } + + prev_prop_p = cur_prop_p; + cur_prop_cp = cur_prop_p->next_property_cp; + } +} /* ecma_delete_property */ + +/** + * Check whether the object contains a property + */ +static void +ecma_assert_object_contains_the_property (const ecma_object_t *object_p, /**< ecma-object */ + const ecma_property_value_t *prop_value_p, /**< property value */ + bool is_data) /**< property should be data property */ +{ +#ifndef JERRY_NDEBUG + jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp; + JERRY_ASSERT (prop_iter_cp != JMEM_CP_NULL); + + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prop_iter_cp = prop_iter_p->next_property_cp; + } + + while (prop_iter_cp != JMEM_CP_NULL) + { + prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if ((prop_pair_p->values + i) == prop_value_p) + { + JERRY_ASSERT (is_data == ((prop_pair_p->header.types[i] & ECMA_PROPERTY_FLAG_DATA) != 0)); + return; + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } +#else /* JERRY_NDEBUG */ + JERRY_UNUSED (object_p); + JERRY_UNUSED (prop_value_p); + JERRY_UNUSED (is_data); +#endif /* !JERRY_NDEBUG */ +} /* ecma_assert_object_contains_the_property */ + +/** + * Assign value to named data property + * + * Note: + * value previously stored in the property is freed + * + * @return void + */ +void +ecma_named_data_property_assign_value (ecma_object_t *obj_p, /**< object */ + ecma_property_value_t *prop_value_p, /**< property value reference */ + ecma_value_t value) /**< value to assign */ +{ + ecma_assert_object_contains_the_property (obj_p, prop_value_p, true); + + ecma_value_assign_value (&prop_value_p->value, value); +} /* ecma_named_data_property_assign_value */ + +/** + * Get named accessor property getter-setter-pair + * + * @return pointer to object's getter-setter pair + */ +ecma_getter_setter_pointers_t * +ecma_get_named_accessor_property (const ecma_property_value_t *prop_value_p) /**< property value reference */ +{ + return (ecma_getter_setter_pointers_t *) &prop_value_p->getter_setter_pair; +} /* ecma_get_named_accessor_property */ + +/** + * Set getter of named accessor property + */ +void +ecma_set_named_accessor_property_getter (ecma_object_t *object_p, /**< the property's container */ + ecma_property_value_t *prop_value_p, /**< property value reference */ + ecma_object_t *getter_p) /**< getter object */ +{ + ecma_assert_object_contains_the_property (object_p, prop_value_p, false); + + ECMA_SET_POINTER (prop_value_p->getter_setter_pair.getter_cp, getter_p); +} /* ecma_set_named_accessor_property_getter */ + +/** + * Set setter of named accessor property + */ +void +ecma_set_named_accessor_property_setter (ecma_object_t *object_p, /**< the property's container */ + ecma_property_value_t *prop_value_p, /**< property value reference */ + ecma_object_t *setter_p) /**< setter object */ +{ + ecma_assert_object_contains_the_property (object_p, prop_value_p, false); + + ECMA_SET_POINTER (prop_value_p->getter_setter_pair.setter_cp, setter_p); +} /* ecma_set_named_accessor_property_setter */ + +#if JERRY_MODULE_SYSTEM + +/** + * Construct a reference to a given property + * + * @return property reference + */ +ecma_value_t +ecma_property_to_reference (ecma_property_t *property_p) /**< data or reference property */ +{ + ecma_property_value_t *referenced_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (!(*property_p & ECMA_PROPERTY_FLAG_DATA)) + { + return referenced_value_p->value; + } + + jmem_cpointer_tag_t offset = (jmem_cpointer_tag_t) (((uintptr_t) property_p) & 0x1); + + if (offset == 0) + { + ++referenced_value_p; + } + + JERRY_ASSERT ((((uintptr_t) referenced_value_p) & (((uintptr_t) 1 << JMEM_ALIGNMENT_LOG) - 1)) == 0); + + ecma_value_t result; + ECMA_SET_NON_NULL_POINTER_TAG (result, referenced_value_p, offset); + return result; +} /* ecma_property_to_reference */ + +/** + * Gets the referenced property value + * + * @return pointer to the value + */ +ecma_property_value_t * +ecma_get_property_value_from_named_reference (ecma_property_value_t *reference_p) /**< data property reference */ +{ + ecma_value_t value = reference_p->value; + reference_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_property_value_t, value); + + if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (value)) + { + --reference_p; + } + + return reference_p; +} /* ecma_get_property_value_from_named_reference */ + +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * Get property's 'Writable' attribute value + * + * @return true - property is writable, + * false - otherwise + */ +bool +ecma_is_property_writable (ecma_property_t property) /**< property */ +{ + JERRY_ASSERT (property & ECMA_PROPERTY_FLAG_DATA); + + return (property & ECMA_PROPERTY_FLAG_WRITABLE) != 0; +} /* ecma_is_property_writable */ + +/** + * Set property's 'Writable' attribute value + */ +void +ecma_set_property_writable_attr (ecma_property_t *property_p, /**< [in,out] property */ + bool is_writable) /**< new value for writable flag */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW_DATA (*property_p)); + + if (is_writable) + { + *property_p = (uint8_t) (*property_p | ECMA_PROPERTY_FLAG_WRITABLE); + } + else + { + *property_p = (uint8_t) (*property_p & ~ECMA_PROPERTY_FLAG_WRITABLE); + } +} /* ecma_set_property_writable_attr */ + +/** + * Get property's 'Enumerable' attribute value + * + * @return true - property is enumerable, + * false - otherwise + */ +bool +ecma_is_property_enumerable (ecma_property_t property) /**< property */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (property)); + + return (property & ECMA_PROPERTY_FLAG_ENUMERABLE) != 0; +} /* ecma_is_property_enumerable */ + +/** + * Set property's 'Enumerable' attribute value + */ +void +ecma_set_property_enumerable_attr (ecma_property_t *property_p, /**< [in,out] property */ + bool is_enumerable) /**< new value for enumerable flag */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + if (is_enumerable) + { + *property_p = (uint8_t) (*property_p | ECMA_PROPERTY_FLAG_ENUMERABLE); + } + else + { + *property_p = (uint8_t) (*property_p & ~ECMA_PROPERTY_FLAG_ENUMERABLE); + } +} /* ecma_set_property_enumerable_attr */ + +/** + * Get property's 'Configurable' attribute value + * + * @return true - property is configurable, + * false - otherwise + */ +bool +ecma_is_property_configurable (ecma_property_t property) /**< property */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (property)); + + return (property & ECMA_PROPERTY_FLAG_CONFIGURABLE) != 0; +} /* ecma_is_property_configurable */ + +/** + * Set property's 'Configurable' attribute value + */ +void +ecma_set_property_configurable_attr (ecma_property_t *property_p, /**< [in,out] property */ + bool is_configurable) /**< new value for configurable flag */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + if (is_configurable) + { + *property_p = (uint8_t) (*property_p | ECMA_PROPERTY_FLAG_CONFIGURABLE); + } + else + { + *property_p = (uint8_t) (*property_p & ~ECMA_PROPERTY_FLAG_CONFIGURABLE); + } +} /* ecma_set_property_configurable_attr */ + +#if JERRY_LCACHE + +/** + * Check whether the property is registered in LCache + * + * @return true / false + */ +bool +ecma_is_property_lcached (ecma_property_t *property_p) /**< property */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p)); + + return (*property_p & ECMA_PROPERTY_FLAG_LCACHED) != 0; +} /* ecma_is_property_lcached */ + +/** + * Set value of flag indicating whether the property is registered in LCache + */ +void +ecma_set_property_lcached (ecma_property_t *property_p, /**< property */ + bool is_lcached) /**< new value for lcached flag */ +{ + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p)); + + if (is_lcached) + { + *property_p = (uint8_t) (*property_p | ECMA_PROPERTY_FLAG_LCACHED); + } + else + { + *property_p = (uint8_t) (*property_p & ~ECMA_PROPERTY_FLAG_LCACHED); + } +} /* ecma_set_property_lcached */ + +#endif /* JERRY_LCACHE */ + +/** + * Construct empty property descriptor, i.e.: + * property descriptor with all is_defined flags set to false and the rest - to default value. + * + * @return empty property descriptor + */ +ecma_property_descriptor_t +ecma_make_empty_property_descriptor (void) +{ + ecma_property_descriptor_t prop_desc; + + prop_desc.flags = 0; + prop_desc.value = ECMA_VALUE_UNDEFINED; + prop_desc.get_p = NULL; + prop_desc.set_p = NULL; + + return prop_desc; +} /* ecma_make_empty_property_descriptor */ + +/** + * Free values contained in the property descriptor + * and make it empty property descriptor + */ +void +ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */ +{ + if (prop_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + { + ecma_free_value (prop_desc_p->value); + } + + if ((prop_desc_p->flags & JERRY_PROP_IS_GET_DEFINED) && prop_desc_p->get_p != NULL) + { + ecma_deref_object (prop_desc_p->get_p); + } + + if ((prop_desc_p->flags & JERRY_PROP_IS_SET_DEFINED) && prop_desc_p->set_p != NULL) + { + ecma_deref_object (prop_desc_p->set_p); + } + + *prop_desc_p = ecma_make_empty_property_descriptor (); +} /* ecma_free_property_descriptor */ + +/** + * Increase ref count of an extended primitive value. + */ +void +ecma_ref_extended_primitive (ecma_extended_primitive_t *primitive_p) /**< extended primitive value */ +{ + if (JERRY_LIKELY (primitive_p->refs_and_type < ECMA_EXTENDED_PRIMITIVE_MAX_REF)) + { + primitive_p->refs_and_type += ECMA_EXTENDED_PRIMITIVE_REF_ONE; + } + else + { + jerry_fatal (JERRY_FATAL_REF_COUNT_LIMIT); + } +} /* ecma_ref_extended_primitive */ + +/** + * Decrease ref count of an error reference. + */ +void +ecma_deref_exception (ecma_extended_primitive_t *error_ref_p) /**< error reference */ +{ + JERRY_ASSERT (error_ref_p->refs_and_type >= ECMA_EXTENDED_PRIMITIVE_REF_ONE); + + error_ref_p->refs_and_type -= ECMA_EXTENDED_PRIMITIVE_REF_ONE; + + if (error_ref_p->refs_and_type < ECMA_EXTENDED_PRIMITIVE_REF_ONE) + { + ecma_free_value (error_ref_p->u.value); + jmem_pools_free (error_ref_p, sizeof (ecma_extended_primitive_t)); + } +} /* ecma_deref_exception */ + +#if JERRY_BUILTIN_BIGINT + +/** + * Decrease ref count of a bigint value. + */ +void +ecma_deref_bigint (ecma_extended_primitive_t *bigint_p) /**< bigint value */ +{ + JERRY_ASSERT (bigint_p->refs_and_type >= ECMA_EXTENDED_PRIMITIVE_REF_ONE); + + bigint_p->refs_and_type -= ECMA_EXTENDED_PRIMITIVE_REF_ONE; + + if (bigint_p->refs_and_type >= ECMA_EXTENDED_PRIMITIVE_REF_ONE) + { + return; + } + + uint32_t size = ECMA_BIGINT_GET_SIZE (bigint_p); + + JERRY_ASSERT (size > 0); + + size_t mem_size = ECMA_BIGINT_GET_BYTE_SIZE (size) + sizeof (ecma_extended_primitive_t); + jmem_heap_free_block (bigint_p, mem_size); +} /* ecma_deref_bigint */ + +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Create an error reference from a given value. + * + * Note: + * Reference of the value is taken. + * + * @return error reference value + */ +ecma_value_t +ecma_create_exception (ecma_value_t value, /**< referenced value */ + uint32_t options) /**< ECMA_ERROR_API_* options */ +{ + ecma_extended_primitive_t *error_ref_p; + error_ref_p = (ecma_extended_primitive_t *) jmem_pools_alloc (sizeof (ecma_extended_primitive_t)); + + error_ref_p->refs_and_type = ECMA_EXTENDED_PRIMITIVE_REF_ONE | options; + error_ref_p->u.value = value; + return ecma_make_extended_primitive_value (error_ref_p, ECMA_TYPE_ERROR); +} /* ecma_create_exception */ + +/** + * Create an error reference from the currently thrown error value. + * + * @return error reference value + */ +ecma_value_t +ecma_create_exception_from_context (void) +{ + uint32_t options = 0; + uint32_t status_flags = JERRY_CONTEXT (status_flags); + + if (status_flags & ECMA_STATUS_ABORT) + { + options |= ECMA_ERROR_API_FLAG_ABORT; + } + +#if JERRY_VM_THROW + if (status_flags & ECMA_STATUS_ERROR_THROWN) + { + options |= ECMA_ERROR_API_FLAG_THROW_CAPTURED; + } +#endif /* JERRY_VM_THROW */ + + return ecma_create_exception (jcontext_take_exception (), options); +} /* ecma_create_exception_from_context */ + +/** + * Create an exception from a given object. + * + * Note: + * Reference of the object is taken. + * + * @return exception value + */ +ecma_value_t +ecma_create_exception_from_object (ecma_object_t *object_p) /**< referenced object */ +{ + return ecma_create_exception (ecma_make_object_value (object_p), 0); +} /* ecma_create_exception_from_object */ + +/** + * Raise a new exception from the argument exception value. + * + * Note: the argument exceptions reference count is decreased + */ +void +ecma_throw_exception (ecma_value_t value) /**< error reference */ +{ + JERRY_ASSERT (!jcontext_has_pending_exception () && !jcontext_has_pending_abort ()); + ecma_extended_primitive_t *error_ref_p = ecma_get_extended_primitive_from_value (value); + + JERRY_ASSERT (error_ref_p->refs_and_type >= ECMA_EXTENDED_PRIMITIVE_REF_ONE); + + ecma_value_t referenced_value = error_ref_p->u.value; + uint32_t status_flags = JERRY_CONTEXT (status_flags); + + status_flags |= (ECMA_STATUS_EXCEPTION +#if JERRY_VM_THROW + | ECMA_STATUS_ERROR_THROWN +#endif /* JERRY_VM_THROW */ + | ECMA_STATUS_ABORT); + + if (!(error_ref_p->refs_and_type & ECMA_ERROR_API_FLAG_ABORT)) + { + status_flags &= ~(uint32_t) ECMA_STATUS_ABORT; + } + +#if JERRY_VM_THROW + if (!(error_ref_p->refs_and_type & ECMA_ERROR_API_FLAG_THROW_CAPTURED)) + { + status_flags &= ~(uint32_t) ECMA_STATUS_ERROR_THROWN; + } +#endif /* JERRY_VM_THROW */ + + JERRY_CONTEXT (status_flags) = status_flags; + + if (error_ref_p->refs_and_type >= 2 * ECMA_EXTENDED_PRIMITIVE_REF_ONE) + { + error_ref_p->refs_and_type -= ECMA_EXTENDED_PRIMITIVE_REF_ONE; + referenced_value = ecma_copy_value (referenced_value); + } + else + { + jmem_pools_free (error_ref_p, sizeof (ecma_extended_primitive_t)); + } + + JERRY_CONTEXT (error_value) = referenced_value; +} /* ecma_throw_exception */ + +/** + * Decrease the reference counter of a script value. + */ +void +ecma_script_deref (ecma_value_t script_value) /**< script value */ +{ + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + script_p->refs_and_type -= CBC_SCRIPT_REF_ONE; + + if (script_p->refs_and_type >= CBC_SCRIPT_REF_ONE) + { + return; + } + + size_t script_size = sizeof (cbc_script_t); + uint32_t type = script_p->refs_and_type; + + if (type & CBC_SCRIPT_HAS_USER_VALUE) + { + script_size += sizeof (ecma_value_t); + + if (!(type & CBC_SCRIPT_USER_VALUE_IS_OBJECT)) + { + ecma_value_t user_value = CBC_SCRIPT_GET_USER_VALUE (script_p); + + JERRY_ASSERT (!ecma_is_value_object (user_value)); + ecma_free_value (user_value); + } + } + +#if JERRY_SOURCE_NAME + ecma_deref_ecma_string (ecma_get_string_from_value (script_p->source_name)); +#endif /* JERRY_SOURCE_NAME */ + +#if JERRY_MODULE_SYSTEM + if (type & CBC_SCRIPT_HAS_IMPORT_META) + { + JERRY_ASSERT (!(type & CBC_SCRIPT_HAS_FUNCTION_ARGUMENTS)); + JERRY_ASSERT (ecma_is_value_object (CBC_SCRIPT_GET_IMPORT_META (script_p, type))); + + script_size += sizeof (ecma_value_t); + } +#endif /* JERRY_MODULE_SYSTEM */ + + jmem_heap_free_block (script_p, script_size); +} /* ecma_script_deref */ + +/** + * Increase reference counter of Compact + * Byte Code or regexp byte code. + */ +void +ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */ +{ + /* Abort program if maximum reference number is reached. */ + if (bytecode_p->refs >= UINT16_MAX) + { + jerry_fatal (JERRY_FATAL_REF_COUNT_LIMIT); + } + + bytecode_p->refs++; +} /* ecma_bytecode_ref */ + +/** + * Decrease reference counter of Compact + * Byte Code or regexp byte code. + */ +void +ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */ +{ + JERRY_ASSERT (bytecode_p->refs > 0); + JERRY_ASSERT (!CBC_IS_FUNCTION (bytecode_p->status_flags) + || !(bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)); + + bytecode_p->refs--; + + if (bytecode_p->refs > 0) + { + /* Non-zero reference counter. */ + return; + } + + if (CBC_IS_FUNCTION (bytecode_p->status_flags)) + { + ecma_value_t *literal_start_p = NULL; + uint32_t literal_end; + uint32_t const_literal_end; + + if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_p; + literal_end = args_p->literal_end; + const_literal_end = args_p->const_literal_end; + + literal_start_p = (ecma_value_t *) ((uint8_t *) bytecode_p + sizeof (cbc_uint16_arguments_t)); + literal_start_p -= args_p->register_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_p; + literal_end = args_p->literal_end; + const_literal_end = args_p->const_literal_end; + + literal_start_p = (ecma_value_t *) ((uint8_t *) bytecode_p + sizeof (cbc_uint8_arguments_t)); + literal_start_p -= args_p->register_end; + } + + for (uint32_t i = const_literal_end; i < literal_end; i++) + { + ecma_compiled_code_t *bytecode_literal_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, literal_start_p[i]); + + /* Self references are ignored. */ + if (bytecode_literal_p != bytecode_p) + { + ecma_bytecode_deref (bytecode_literal_p); + } + } + + ecma_script_deref (((cbc_uint8_arguments_t *) bytecode_p)->script_value); + + if (bytecode_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS) + { + ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (bytecode_p); + + /* Since the objects in the tagged template collection are not strong referenced anymore by the compiled code + we can treat them as 'new' objects. */ + JERRY_CONTEXT (ecma_gc_new_objects) += collection_p->item_count * 2; + ecma_collection_free_template_literal (collection_p); + } + + } + else + { +#if JERRY_BUILTIN_REGEXP + re_compiled_code_t *re_bytecode_p = (re_compiled_code_t *) bytecode_p; + + ecma_deref_ecma_string (ecma_get_string_from_value (re_bytecode_p->source)); +#endif /* JERRY_BUILTIN_REGEXP */ + } + + jmem_heap_free_block (bytecode_p, ((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG); +} /* ecma_bytecode_deref */ + +/** + * Gets the script data assigned to a script / module / function + * + * @return script data - if available, JMEM_CP_NULL - otherwise + */ +ecma_value_t +ecma_script_get_from_value (ecma_value_t value) /**< compiled code */ +{ + if (!ecma_is_value_object (value)) + { + return JMEM_CP_NULL; + } + + ecma_object_t *object_p = ecma_get_object_from_value (value); + const ecma_compiled_code_t *bytecode_p = NULL; + + while (true) + { + switch (ecma_get_object_type (object_p)) + { + case ECMA_OBJECT_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_SCRIPT) + { + bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value); + break; + } + +#if JERRY_MODULE_SYSTEM + if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_MODULE) + { + ecma_module_t *module_p = (ecma_module_t *) object_p; + + if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE)) + { + bytecode_p = module_p->u.compiled_code_p; + break; + } + } +#endif /* JERRY_MODULE_SYSTEM */ + return JMEM_CP_NULL; + } + case ECMA_OBJECT_TYPE_FUNCTION: + { + bytecode_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + object_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, ext_object_p->u.bound_function.target_function); + continue; + } + case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION: + { + return ((ecma_extended_object_t *) object_p)->u.constructor_function.script_value; + } + default: + { + return JMEM_CP_NULL; + } + } + + JERRY_ASSERT (bytecode_p != NULL); + return ((cbc_uint8_arguments_t *) bytecode_p)->script_value; + } +} /* ecma_script_get_from_value */ + +/** + * Resolve the position of the arguments list start of the compiled code + * + * @return start position of the arguments list start of the compiled code + */ +ecma_value_t * +ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */ +{ + JERRY_ASSERT (bytecode_header_p != NULL); + + uint8_t *byte_p = (uint8_t *) bytecode_header_p; + byte_p += ((size_t) bytecode_header_p->size) << JMEM_ALIGNMENT_LOG; + + if (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)) + { + return ((ecma_value_t *) byte_p); + } + + if (JERRY_LIKELY (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS))) + { + return ((ecma_value_t *) byte_p) - ((cbc_uint8_arguments_t *) bytecode_header_p)->argument_end; + } + + return ((ecma_value_t *) byte_p) - ((cbc_uint16_arguments_t *) bytecode_header_p)->argument_end; +} /* ecma_compiled_code_resolve_arguments_start */ + +/** + * Resolve the position of the function name of the compiled code + * + * @return position of the function name of the compiled code + */ +ecma_value_t * +ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */ +{ + JERRY_ASSERT (bytecode_header_p != NULL); + ecma_value_t *base_p = ecma_compiled_code_resolve_arguments_start (bytecode_header_p); + + if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR) + { + base_p--; + } + + return base_p; +} /* ecma_compiled_code_resolve_function_name */ + +/** + * Get the tagged template collection of the compiled code + * + * @return pointer to the tagged template collection + */ +ecma_collection_t * +ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */ +{ + JERRY_ASSERT (bytecode_header_p != NULL); + JERRY_ASSERT (bytecode_header_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS); + + ecma_value_t *base_p = ecma_compiled_code_resolve_function_name (bytecode_header_p); + return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, base_p[-1]); +} /* ecma_compiled_code_get_tagged_template_collection */ + +/** + * Get the source name of a compiled code. + * + * @return source name value + */ +ecma_value_t +ecma_get_source_name (const ecma_compiled_code_t *bytecode_p) /**< compiled code */ +{ +#if JERRY_SOURCE_NAME +#if JERRY_SNAPSHOT_EXEC + if (JERRY_UNLIKELY (bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON); + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value; + return ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value)->source_name; +#else /* !JERRY_SOURCE_NAME */ + JERRY_UNUSED (bytecode_p); + return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON); +#endif /* !JERRY_SOURCE_NAME */ +} /* ecma_get_source_name */ + +#if (JERRY_STACK_LIMIT != 0) +/** + * Check the current stack usage by calculating the difference from the initial stack base. + * + * @return current stack usage in bytes + */ +uintptr_t JERRY_ATTR_NOINLINE +ecma_get_current_stack_usage (void) +{ + volatile int __sp; + return (uintptr_t) (JERRY_CONTEXT (stack_base) - (uintptr_t) &__sp); +} /* ecma_get_current_stack_usage */ + +#endif /* (JERRY_STACK_LIMIT != 0) */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers.h new file mode 100644 index 0000000..1637265 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-helpers.h @@ -0,0 +1,520 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_HELPERS_H +#define ECMA_HELPERS_H + +#include "ecma-globals.h" + +#include "jmem.h" +#include "lit-strings.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmahelpers Helpers for operations with ECMA data types + * @{ + */ + +/** + * Get value of pointer from specified non-null compressed pointer. + */ +#define ECMA_GET_NON_NULL_POINTER(type, field) JMEM_CP_GET_NON_NULL_POINTER (type, field) + +/** + * Extract value of pointer from specified pointer-tag value + */ +#define ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, field) \ + JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG (type, field) + +/** + * Get value of pointer from specified compressed pointer. + */ +#define ECMA_GET_POINTER(type, field) JMEM_CP_GET_POINTER (type, field) + +/** + * Set value of non-null compressed pointer so that it will correspond + * to specified non_compressed_pointer. + */ +#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \ + JMEM_CP_SET_NON_NULL_POINTER (field, non_compressed_pointer) + +/** + * Set value of pointer-tag value so that it will correspond + * to specified non_compressed_pointer along with tag + */ +#define ECMA_SET_NON_NULL_POINTER_TAG(field, non_compressed_pointer, tag) \ + JMEM_CP_SET_NON_NULL_POINTER_TAG (field, non_compressed_pointer, tag) + +/** + * Set value of compressed pointer so that it will correspond + * to specified non_compressed_pointer. + */ +#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer) + +/** + * Get value of each tag bit from specified pointer-tag value + */ +#define ECMA_GET_FIRST_BIT_FROM_POINTER_TAG(field) \ + JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (field) /**< get first tag bit from jmem_cpointer_tag_t **/ +#define ECMA_GET_SECOND_BIT_FROM_POINTER_TAG(field) \ + JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (field) /**< get second tag bit from jmem_cpointer_tag_t **/ +#define ECMA_GET_THIRD_BIT_FROM_POINTER_TAG(field) \ + JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (field) /**< get third tag bit from jmem_cpointer_tag_t **/ + +/** + * Set value of each tag bit to specified pointer-tag value + */ +#define ECMA_SET_FIRST_BIT_TO_POINTER_TAG(field) \ + JMEM_CP_SET_FIRST_BIT_TO_POINTER_TAG (field) /**< set first tag bit to jmem_cpointer_tag_t **/ +#define ECMA_SET_SECOND_BIT_TO_POINTER_TAG(field) \ + JMEM_CP_SET_SECOND_BIT_TO_POINTER_TAG (field) /**< set second tag bit to jmem_cpointer_tag_t **/ +#define ECMA_SET_THIRD_BIT_TO_POINTER_TAG(field) \ + JMEM_CP_SET_THIRD_BIT_TO_POINTER_TAG (field) /**< set third tag bit to jmem_cpointer_tag_t **/ + +/** + * Status flags for ecma_string_get_chars function + */ +typedef enum +{ + ECMA_STRING_FLAG_EMPTY = 0, /**< No options are provided. */ + ECMA_STRING_FLAG_IS_ASCII = (1 << 0), /**< The string contains only ASCII characters. */ + ECMA_STRING_FLAG_REHASH_NEEDED = (1 << 1), /**< The hash of the string must be recalculated. + * For more details see ecma_append_chars_to_string */ + ECMA_STRING_FLAG_IS_UINT32 = (1 << 2), /**< The string represents an UINT32 number */ + ECMA_STRING_FLAG_MUST_BE_FREED = (1 << 3), /**< The returned buffer must be freed */ +} ecma_string_flag_t; + +/** + * Underscore is ignored when this option is passed. + */ +#define ECMA_CONVERSION_ALLOW_UNDERSCORE 0x1 + +/** + * Convert ecma-string's contents to a cesu-8 string and put it into a buffer. + */ +#define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \ + utf8_ptr, /**< [out] output buffer pointer */ \ + utf8_str_size) /**< [out] output buffer size */ \ + lit_utf8_size_t utf8_str_size; \ + uint8_t utf8_ptr##flags = ECMA_STRING_FLAG_EMPTY; \ + const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, NULL, NULL, &utf8_ptr##flags); + +/** + * Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING' + */ +#define ECMA_FINALIZE_UTF8_STRING(utf8_ptr, /**< pointer to character buffer */ \ + utf8_str_size) /**< buffer size */ \ + if (utf8_ptr##flags & ECMA_STRING_FLAG_MUST_BE_FREED) \ + { \ + JERRY_ASSERT (utf8_ptr != NULL); \ + jmem_heap_free_block ((void *) utf8_ptr, utf8_str_size); \ + } + +#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY + +/** + * Set an internal property value from pointer. + */ +#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) ((field) = ((ecma_value_t) pointer)) + +/** + * Set an internal property value from pointer. Pointer can be NULL. + */ +#define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) ((field) = ((ecma_value_t) pointer)) + +/** + * Convert an internal property value to pointer. + */ +#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) ((type *) field) + +/** + * Convert an internal property value to pointer. Result can be NULL. + */ +#define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) ((type *) field) + +/** + * Checks whether an internal property is NULL. + */ +#define ECMA_IS_INTERNAL_VALUE_NULL(field) ((field) == ((ecma_value_t) NULL)) + +#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ + +/** + * Set an internal property value from pointer. + */ +#define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) ECMA_SET_NON_NULL_POINTER (field, pointer) + +/** + * Set an internal property value from pointer. Pointer can be NULL. + */ +#define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) ECMA_SET_POINTER (field, pointer) + +/** + * Convert an internal property value to pointer. + */ +#define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) ECMA_GET_NON_NULL_POINTER (type, field) + +/** + * Convert an internal property value to pointer. Result can be NULL. + */ +#define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) ECMA_GET_POINTER (type, field) + +/** + * Checks whether an internal property is NULL. + */ +#define ECMA_IS_INTERNAL_VALUE_NULL(field) ((field) == ((ecma_value_t) JMEM_CP_NULL)) + +#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ + +/** + * Convert boolean to bitfield value. + */ +#define ECMA_BOOL_TO_BITFIELD(x) ((x) ? 1 : 0) + +/** + * Check whether the given type is ECMA_OBJECT_TYPE_PROXY + * + * @param type object type + */ +#define ECMA_OBJECT_TYPE_IS_PROXY(type) (JERRY_UNLIKELY ((type) == ECMA_OBJECT_TYPE_PROXY)) + +/** + * Check whether the given object has [[ProxyHandler]] and [[ProxyTarger]] internal slots + * + * @param obj_p ecma-object + */ +#if JERRY_BUILTIN_PROXY +#define ECMA_OBJECT_IS_PROXY(obj_p) (ECMA_OBJECT_TYPE_IS_PROXY (ecma_get_object_type ((obj_p)))) +#else /* !JERRY_BUILTIN_PROXY */ +#define ECMA_OBJECT_IS_PROXY(obj_p) (false) +#endif /* JERRY_BUILTIN_PROXY */ + +/* ecma-helpers-value.c */ +ecma_type_t JERRY_ATTR_CONST ecma_get_value_type_field (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_direct (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_simple (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_empty (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_undefined (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_null (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_boolean (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_true (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_false (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_found (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_array_hole (ecma_value_t value); + +bool JERRY_ATTR_CONST ecma_is_value_integer_number (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_are_values_integer_numbers (ecma_value_t first_value, ecma_value_t second_value); +bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_magic_string (ecma_value_t value, lit_magic_string_id_t id); +bool JERRY_ATTR_CONST ecma_is_value_bigint (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_non_direct_string (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_object (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_exception (ecma_value_t value); +ecma_value_t ecma_is_value_array (ecma_value_t arg); + +void ecma_check_value_type_is_spec_defined (ecma_value_t value); + +ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value); +ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value); +ecma_value_t ecma_make_nan_value (void); +ecma_value_t ecma_make_float_value (ecma_number_t *ecma_num_p); +ecma_value_t ecma_make_length_value (ecma_length_t length); +ecma_value_t ecma_make_number_value (ecma_number_t ecma_number); +ecma_value_t ecma_make_int32_value (int32_t int32_number); +ecma_value_t ecma_make_uint32_value (uint32_t uint32_number); +ecma_value_t JERRY_ATTR_PURE ecma_make_string_value (const ecma_string_t *ecma_string_p); +ecma_value_t JERRY_ATTR_PURE ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p); +ecma_value_t JERRY_ATTR_PURE ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p); +ecma_value_t JERRY_ATTR_PURE ecma_make_magic_string_value (lit_magic_string_id_t id); +ecma_value_t JERRY_ATTR_PURE ecma_make_object_value (const ecma_object_t *object_p); +ecma_value_t JERRY_ATTR_PURE ecma_make_extended_primitive_value (const ecma_extended_primitive_t *primitive_p, + uint32_t type); +ecma_integer_value_t JERRY_ATTR_CONST ecma_get_integer_from_value (ecma_value_t value); +ecma_number_t JERRY_ATTR_PURE ecma_get_float_from_value (ecma_value_t value); +ecma_number_t *ecma_get_pointer_from_float_value (ecma_value_t value); +ecma_number_t JERRY_ATTR_PURE ecma_get_number_from_value (ecma_value_t value); +ecma_string_t JERRY_ATTR_PURE *ecma_get_string_from_value (ecma_value_t value); +ecma_string_t JERRY_ATTR_PURE *ecma_get_symbol_from_value (ecma_value_t value); +ecma_string_t JERRY_ATTR_PURE *ecma_get_prop_name_from_value (ecma_value_t value); +ecma_object_t JERRY_ATTR_PURE *ecma_get_object_from_value (ecma_value_t value); +ecma_extended_primitive_t JERRY_ATTR_PURE *ecma_get_extended_primitive_from_value (ecma_value_t value); +ecma_value_t JERRY_ATTR_CONST ecma_invert_boolean_value (ecma_value_t value); +ecma_value_t ecma_copy_value (ecma_value_t value); +ecma_value_t ecma_fast_copy_value (ecma_value_t value); +ecma_value_t ecma_copy_value_if_not_object (ecma_value_t value); +void ecma_ref_if_object (ecma_value_t value); +void ecma_deref_if_object (ecma_value_t value); +ecma_value_t ecma_update_float_number (ecma_value_t float_value, ecma_number_t new_number); +void ecma_value_assign_value (ecma_value_t *value_p, ecma_value_t ecma_value); +void ecma_value_assign_number (ecma_value_t *value_p, ecma_number_t ecma_number); +void ecma_free_value (ecma_value_t value); +void ecma_fast_free_value (ecma_value_t value); +void ecma_free_value_if_not_object (ecma_value_t value); +void ecma_free_object (ecma_value_t value); +void ecma_free_number (ecma_value_t value); +lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value); + +/* ecma-helpers-string.c */ +ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc); +bool ecma_prop_name_is_symbol (ecma_string_t *string_p); +ecma_length_t ecma_op_advance_string_index (ecma_string_t *str_p, ecma_length_t index_num, bool is_unicode); +#if JERRY_BUILTIN_CONTAINER +ecma_string_t *ecma_new_map_key_string (ecma_value_t value); +bool ecma_prop_name_is_map_key (ecma_string_t *string_p); +#endif /* JERRY_BUILTIN_CONTAINER */ +ecma_string_t *ecma_new_ecma_string_from_ascii (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); +ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); +ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p, + lit_utf8_size_t string_size); +ecma_string_t * +ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size, void *user_p); +ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit); +ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit); +ecma_string_t *ecma_new_ecma_string_from_length (ecma_length_t index); +ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number); +ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number); +ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number); +ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num); +ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id); +ecma_string_t *ecma_get_internal_string (lit_magic_string_id_t id); +ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p, + const lit_utf8_byte_t *cesu8_string2_p, + lit_utf8_size_t cesu8_string2_size, + lit_utf8_size_t cesu8_string2_length); +ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p); +void ecma_ref_ecma_string (ecma_string_t *string_p); +void ecma_ref_ecma_string_non_direct (ecma_string_t *string_p); +void ecma_deref_ecma_string (ecma_string_t *string_p); +void ecma_deref_ecma_string_non_direct (ecma_string_t *string_p); +void ecma_destroy_ecma_string (ecma_string_t *string_p); +ecma_number_t ecma_string_to_number (const ecma_string_t *str_p); +uint32_t ecma_string_get_array_index (const ecma_string_t *str_p); + +lit_utf8_size_t ecma_string_copy_to_buffer (const ecma_string_t *string_desc_p, + lit_utf8_byte_t *buffer_p, + lit_utf8_size_t buffer_size, + jerry_encoding_t encoding); +void ecma_string_to_cesu8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); +const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, + lit_utf8_size_t *size_p, + lit_utf8_size_t *length_p, + lit_utf8_byte_t *uint32_buff_p, + uint8_t *flags_p); +bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id); +bool ecma_string_is_empty (const ecma_string_t *string_p); +bool ecma_string_is_length (const ecma_string_t *string_p); + +jmem_cpointer_t ecma_string_to_property_name (ecma_string_t *prop_name_p, ecma_property_t *name_type_p); +ecma_string_t *ecma_string_from_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp); +lit_string_hash_t ecma_string_get_property_name_hash (ecma_property_t property, jmem_cpointer_t prop_name_cp); +uint32_t ecma_string_get_property_index (ecma_property_t property, jmem_cpointer_t prop_name_cp); +bool ecma_string_compare_to_property_name (ecma_property_t property, + jmem_cpointer_t prop_name_cp, + const ecma_string_t *string_p); + +bool ecma_compare_ecma_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p); +bool ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p); +bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, const ecma_string_t *string2_p); +lit_utf8_size_t ecma_string_get_length (const ecma_string_t *string_p); +lit_utf8_size_t ecma_string_get_utf8_length (const ecma_string_t *string_p); +lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p); +lit_utf8_size_t ecma_string_get_utf8_size (const ecma_string_t *string_p); +ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, lit_utf8_size_t index); + +lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p); + +lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p); +ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, lit_utf8_size_t start_pos, lit_utf8_size_t end_pos); +const lit_utf8_byte_t *ecma_string_trim_front (const lit_utf8_byte_t *start_p, const lit_utf8_byte_t *end_p); +const lit_utf8_byte_t *ecma_string_trim_back (const lit_utf8_byte_t *start_p, const lit_utf8_byte_t *end_p); +void ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, lit_utf8_size_t *utf8_str_size); +ecma_string_t *ecma_string_trim (const ecma_string_t *string_p); +ecma_value_t +ecma_string_pad (ecma_value_t original_string_p, ecma_value_t max_length, ecma_value_t fill_string, bool pad_on_start); + +ecma_stringbuilder_t ecma_stringbuilder_create (void); +ecma_stringbuilder_t ecma_stringbuilder_create_from (ecma_string_t *string_p); +ecma_stringbuilder_t ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p, const lit_utf8_size_t data_size); +lit_utf8_size_t ecma_stringbuilder_get_size (ecma_stringbuilder_t *builder_p); +lit_utf8_byte_t *ecma_stringbuilder_get_data (ecma_stringbuilder_t *builder_p); +void ecma_stringbuilder_revert (ecma_stringbuilder_t *builder_p, const lit_utf8_size_t size); +void ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, const ecma_string_t *string_p); +void ecma_stringbuilder_append_magic (ecma_stringbuilder_t *builder_p, const lit_magic_string_id_t id); +void ecma_stringbuilder_append_raw (ecma_stringbuilder_t *builder_p, + const lit_utf8_byte_t *data_p, + const lit_utf8_size_t data_size); +void ecma_stringbuilder_append_codepoint (ecma_stringbuilder_t *builder_p, lit_code_point_t cp); +void ecma_stringbuilder_append_char (ecma_stringbuilder_t *builder_p, const ecma_char_t c); +void ecma_stringbuilder_append_byte (ecma_stringbuilder_t *builder_p, const lit_utf8_byte_t); +ecma_string_t *ecma_stringbuilder_finalize (ecma_stringbuilder_t *builder_p); +void ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p); + +/* ecma-helpers-number.c */ +ecma_number_t ecma_number_make_nan (void); +ecma_number_t ecma_number_make_infinity (bool sign); +bool ecma_number_is_nan (ecma_number_t num); +bool ecma_number_is_negative (ecma_number_t num); +bool ecma_number_is_zero (ecma_number_t num); +bool ecma_number_is_infinity (ecma_number_t num); +bool ecma_number_is_finite (ecma_number_t num); +ecma_number_t ecma_number_get_prev (ecma_number_t num); +ecma_number_t ecma_number_get_next (ecma_number_t num); +ecma_number_t ecma_number_trunc (ecma_number_t num); +ecma_number_t ecma_number_remainder (ecma_number_t left_num, ecma_number_t right_num); +ecma_number_t ecma_number_pow (ecma_number_t x, ecma_number_t y); +ecma_value_t +ecma_number_parse_int (const lit_utf8_byte_t *string_buff, lit_utf8_size_t string_buff_size, ecma_value_t radix); +ecma_value_t ecma_number_parse_float (const lit_utf8_byte_t *string_buff, lit_utf8_size_t string_buff_size); +ecma_value_t ecma_integer_multiply (ecma_integer_value_t left_integer, ecma_integer_value_t right_integer); +lit_utf8_size_t ecma_number_to_decimal (ecma_number_t num, lit_utf8_byte_t *out_digits_p, int32_t *out_decimal_exp_p); + +/* ecma-helpers-collection.c */ +ecma_collection_t *ecma_new_collection (void); +void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value); +void ecma_collection_reserve (ecma_collection_t *collection_p, uint32_t count); +void ecma_collection_append (ecma_collection_t *collection_p, const ecma_value_t *buffer_p, uint32_t count); +void ecma_collection_destroy (ecma_collection_t *collection_p); +void ecma_collection_free (ecma_collection_t *collection_p); +void ecma_collection_free_if_not_object (ecma_collection_t *collection_p); +void ecma_collection_free_objects (ecma_collection_t *collection_p); +void ecma_collection_free_template_literal (ecma_collection_t *collection_p); +bool ecma_collection_check_duplicated_entries (ecma_collection_t *collection_p); +bool ecma_collection_has_string_value (ecma_collection_t *collection_p, ecma_string_t *string_p); + +ecma_value_t *ecma_new_compact_collection (void); +ecma_value_t *ecma_compact_collection_push_back (ecma_value_t *compact_collection_p, ecma_value_t value); +ecma_value_t *ecma_compact_collection_shrink (ecma_value_t *compact_collection_p); +void ecma_compact_collection_free (ecma_value_t *compact_collection_p); +ecma_value_t *ecma_compact_collection_end (ecma_value_t *compact_collection_p); +void ecma_compact_collection_destroy (ecma_value_t *compact_collection_p); + +/* ecma-helpers.c */ +ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type); +ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p); +ecma_object_t *ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p); +ecma_object_t *ecma_create_lex_env_class (ecma_object_t *outer_lexical_environment_p, size_t lexical_env_size); +bool JERRY_ATTR_PURE ecma_is_lexical_environment (const ecma_object_t *object_p); +void ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p); +ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p); +ecma_object_base_type_t JERRY_ATTR_PURE ecma_get_object_base_type (const ecma_object_t *object_p); +bool JERRY_ATTR_PURE ecma_object_class_is (ecma_object_t *object_p, ecma_object_class_type_t class_id); +ecma_lexical_environment_type_t JERRY_ATTR_PURE ecma_get_lex_env_type (const ecma_object_t *object_p); +ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p); +ecma_object_t *ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, bool copy_values); + +ecma_property_value_t *ecma_create_named_data_property (ecma_object_t *object_p, + ecma_string_t *name_p, + uint8_t prop_attributes, + ecma_property_t **out_prop_p); +ecma_property_value_t *ecma_create_named_accessor_property (ecma_object_t *object_p, + ecma_string_t *name_p, + ecma_object_t *get_p, + ecma_object_t *set_p, + uint8_t prop_attributes, + ecma_property_t **out_prop_p); +#if JERRY_MODULE_SYSTEM +void ecma_create_named_reference_property (ecma_object_t *object_p, ecma_string_t *name_p, ecma_value_t reference); +#endif /* JERRY_MODULE_SYSTEM */ +ecma_property_t *ecma_find_named_property (ecma_object_t *obj_p, ecma_string_t *name_p); +ecma_property_value_t *ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p); + +void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p); + +void +ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p, ecma_value_t value); + +ecma_getter_setter_pointers_t *ecma_get_named_accessor_property (const ecma_property_value_t *prop_value_p); +void ecma_set_named_accessor_property_getter (ecma_object_t *object_p, + ecma_property_value_t *prop_value_p, + ecma_object_t *getter_p); +void ecma_set_named_accessor_property_setter (ecma_object_t *object_p, + ecma_property_value_t *prop_value_p, + ecma_object_t *setter_p); +#if JERRY_MODULE_SYSTEM +ecma_value_t ecma_property_to_reference (ecma_property_t *property_p); +ecma_property_value_t *ecma_get_property_value_from_named_reference (ecma_property_value_t *reference_p); +#endif /* JERRY_MODULE_SYSTEM */ +bool ecma_is_property_writable (ecma_property_t property); +void ecma_set_property_writable_attr (ecma_property_t *property_p, bool is_writable); +bool ecma_is_property_enumerable (ecma_property_t property); +void ecma_set_property_enumerable_attr (ecma_property_t *property_p, bool is_enumerable); +bool ecma_is_property_configurable (ecma_property_t property); +void ecma_set_property_configurable_attr (ecma_property_t *property_p, bool is_configurable); + +#if JERRY_LCACHE +bool ecma_is_property_lcached (ecma_property_t *property_p); +void ecma_set_property_lcached (ecma_property_t *property_p, bool is_lcached); +#endif /* JERRY_LCACHE */ + +ecma_property_descriptor_t ecma_make_empty_property_descriptor (void); +void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p); + +void ecma_ref_extended_primitive (ecma_extended_primitive_t *primitive_p); +void ecma_deref_exception (ecma_extended_primitive_t *exception_p); +#if JERRY_BUILTIN_BIGINT +void ecma_deref_bigint (ecma_extended_primitive_t *bigint_p); +#endif /* JERRY_BUILTIN_BIGINT */ + +ecma_value_t ecma_create_exception (ecma_value_t value, uint32_t options); +ecma_value_t ecma_create_exception_from_context (void); +ecma_value_t ecma_create_exception_from_object (ecma_object_t *object_p); +void ecma_throw_exception (ecma_value_t value); + +void ecma_script_deref (ecma_value_t script_value); +void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p); +void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p); +ecma_value_t ecma_script_get_from_value (ecma_value_t value); +ecma_value_t *ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p); +ecma_value_t *ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p); +ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p); +ecma_value_t ecma_get_source_name (const ecma_compiled_code_t *bytecode_p); +#if (JERRY_STACK_LIMIT != 0) +uintptr_t ecma_get_current_stack_usage (void); +#endif /* (JERRY_STACK_LIMIT != 0) */ + +/* ecma-helpers-external-pointers.c */ +bool ecma_create_native_pointer_property (ecma_object_t *obj_p, + void *native_p, + const jerry_object_native_info_t *native_info_p); +ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p, + const jerry_object_native_info_t *native_info_p); +bool ecma_delete_native_pointer_property (ecma_object_t *obj_p, const jerry_object_native_info_t *native_info_p); + +/* ecma-helpers-conversion.c */ +ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size, uint32_t option); +ecma_number_t ecma_utf8_string_to_number_by_radix (const lit_utf8_byte_t *str_p, + lit_utf8_size_t str_size, + uint32_t radix, + uint32_t option); +lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t value, lit_utf8_byte_t *out_buffer_p, lit_utf8_size_t buffer_size); +uint32_t ecma_number_to_uint32 (ecma_number_t num); +int32_t ecma_number_to_int32 (ecma_number_t num); +lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t num, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); + +/* ecma-helpers-errol.c */ +lit_utf8_size_t ecma_errol0_dtoa (double val, lit_utf8_byte_t *buffer_p, int32_t *exp_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_HELPERS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-init-finalize.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-init-finalize.cpp new file mode 100644 index 0000000..60a3b2e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-init-finalize.cpp @@ -0,0 +1,106 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-init-finalize.h" + +#include "ecma-builtins.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-literal-storage.h" + +#include "jcontext.h" +#include "jmem.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmainitfinalize Initialization and finalization of ECMA components + * @{ + */ + +/** + * Maximum number of GC loops on cleanup. + */ +#define JERRY_GC_LOOP_LIMIT 100 + +/** + * Initialize ECMA components + */ +void +ecma_init (void) +{ +#if (JERRY_GC_MARK_LIMIT != 0) + JERRY_CONTEXT (ecma_gc_mark_recursion_limit) = JERRY_GC_MARK_LIMIT; +#endif /* (JERRY_GC_MARK_LIMIT != 0) */ + + ecma_init_global_environment (); + +#if JERRY_PROPERTY_HASHMAP + JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) = ECMA_PROP_HASHMAP_ALLOC_ON; + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_HIGH_PRESSURE_GC; +#endif /* JERRY_PROPERTY_HASHMAP */ + +#if (JERRY_STACK_LIMIT != 0) + volatile int sp; + JERRY_CONTEXT (stack_base) = (uintptr_t) &sp; +#endif /* (JERRY_STACK_LIMIT != 0) */ + + ecma_job_queue_init (); + + JERRY_CONTEXT (current_new_target_p) = NULL; + +#if JERRY_BUILTIN_TYPEDARRAY + JERRY_CONTEXT (arraybuffer_compact_allocation_limit) = 256; +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +} /* ecma_init */ + +/** + * Finalize ECMA components + */ +void +ecma_finalize (void) +{ + JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p) == NULL); + + ecma_finalize_global_environment (); + uint8_t runs = 0; + + do + { + ecma_gc_run (); + if (++runs >= JERRY_GC_LOOP_LIMIT) + { + jerry_fatal (JERRY_FATAL_UNTERMINATED_GC_LOOPS); + } + } while (JERRY_CONTEXT (ecma_gc_new_objects) != 0); + + jmem_cpointer_t *global_symbols_cp = JERRY_CONTEXT (global_symbols_cp); + + for (uint32_t i = 0; i < ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT; i++) + { + if (global_symbols_cp[i] != JMEM_CP_NULL) + { + ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (ecma_string_t, global_symbols_cp[i])); + } + } + + ecma_finalize_lit_storage (); +} /* ecma_finalize */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-init-finalize.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-init-finalize.h new file mode 100644 index 0000000..0e4fda2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-init-finalize.h @@ -0,0 +1,34 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_INIT_FINALIZE_H +#define ECMA_INIT_FINALIZE_H + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmainitfinalize Initialization and finalization of ECMA components + * @{ + */ + +void ecma_init (void); +void ecma_finalize (void); + +/** + * @} + * @} + */ + +#endif /* !ECMA_INIT_FINALIZE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-lcache.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-lcache.cpp new file mode 100644 index 0000000..5f6ec9d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-lcache.cpp @@ -0,0 +1,217 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-lcache.h" + +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmalcache Property lookup cache + * @{ + */ + +#if JERRY_LCACHE + +/** + * Bitshift index for calculating hash. + */ +#define ECMA_LCACHE_HASH_BITSHIFT_INDEX 0 + +/** + * Mask for hash bits + */ +#define ECMA_LCACHE_HASH_MASK ((ECMA_LCACHE_HASH_ROWS_COUNT - 1) << ECMA_LCACHE_HASH_BITSHIFT_INDEX) + +/** + * Bitshift index for creating property identifier + */ +#define ECMA_LCACHE_HASH_ENTRY_ID_SHIFT (8 * sizeof (jmem_cpointer_t)) + +/** + * Create property identifier + */ +#define ECMA_LCACHE_CREATE_ID(object_cp, name_cp) \ + (((ecma_lcache_hash_entry_id_t) (object_cp) << ECMA_LCACHE_HASH_ENTRY_ID_SHIFT) | (name_cp)) + +/** + * Invalidate specified LCache entry + */ +static inline void +ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to invalidate */ +{ + JERRY_ASSERT (entry_p != NULL); + JERRY_ASSERT (entry_p->id != 0); + JERRY_ASSERT (entry_p->prop_p != NULL); + + entry_p->id = 0; + ecma_set_property_lcached (entry_p->prop_p, false); +} /* ecma_lcache_invalidate_entry */ + +/** + * Compute the row index of object / property name pair + * + * @return row index + */ +static inline size_t +ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to object */ + jmem_cpointer_t name_cp) /**< compressed pointer to property name */ +{ + /* Randomize the property name with the object pointer using a xor operation, + * so properties of different objects with the same name can be cached effectively. */ + return (size_t) (((name_cp ^ object_cp) & ECMA_LCACHE_HASH_MASK) >> ECMA_LCACHE_HASH_BITSHIFT_INDEX); +} /* ecma_lcache_row_index */ + +/** + * Insert an entry into LCache + */ +void +ecma_lcache_insert (const ecma_object_t *object_p, /**< object */ + const jmem_cpointer_t name_cp, /**< property name */ + ecma_property_t *prop_p) /**< property */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (prop_p != NULL && !ecma_is_property_lcached (prop_p)); + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*prop_p)); + + jmem_cpointer_t object_cp; + + ECMA_SET_NON_NULL_POINTER (object_cp, object_p); + + size_t row_index = ecma_lcache_row_index (object_cp, name_cp); + ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache)[row_index]; + ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH; + + do + { + if (entry_p->id == 0) + { + goto insert; + } + + entry_p++; + } while (entry_p < entry_end_p); + + /* Invalidate the last entry. */ + ecma_lcache_invalidate_entry (--entry_p); + + /* Shift other entries towards the end. */ + for (uint32_t i = 0; i < ECMA_LCACHE_HASH_ROW_LENGTH - 1; i++) + { + entry_p->id = entry_p[-1].id; + entry_p->prop_p = entry_p[-1].prop_p; + entry_p--; + } + +insert: + entry_p->prop_p = prop_p; + entry_p->id = ECMA_LCACHE_CREATE_ID (object_cp, name_cp); + + ecma_set_property_lcached (entry_p->prop_p, true); +} /* ecma_lcache_insert */ + +/** + * Lookup property in the LCache + * + * @return a pointer to an ecma_property_t if the lookup is successful + * NULL otherwise + */ +ecma_property_t * +ecma_lcache_lookup (const ecma_object_t *object_p, /**< object */ + const ecma_string_t *prop_name_p) /**< property's name */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (prop_name_p != NULL); + + jmem_cpointer_t object_cp; + ECMA_SET_NON_NULL_POINTER (object_cp, object_p); + + ecma_property_t prop_name_type = ECMA_DIRECT_STRING_PTR; + jmem_cpointer_t prop_name_cp; + + if (JERRY_UNLIKELY (ECMA_IS_DIRECT_STRING (prop_name_p))) + { + prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p); + prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p); + } + else + { + ECMA_SET_NON_NULL_POINTER (prop_name_cp, prop_name_p); + } + + size_t row_index = ecma_lcache_row_index (object_cp, prop_name_cp); + + ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache)[row_index]; + ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH; + ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp, prop_name_cp); + + do + { + if (entry_p->id == id && JERRY_LIKELY (ECMA_PROPERTY_GET_NAME_TYPE (*entry_p->prop_p) == prop_name_type)) + { + JERRY_ASSERT (entry_p->prop_p != NULL && ecma_is_property_lcached (entry_p->prop_p)); + return entry_p->prop_p; + } + entry_p++; + } while (entry_p < entry_end_p); + + return NULL; +} /* ecma_lcache_lookup */ + +/** + * Invalidate LCache entries associated with given object and property name / property + */ +void +ecma_lcache_invalidate (const ecma_object_t *object_p, /**< object */ + const jmem_cpointer_t name_cp, /**< property name */ + ecma_property_t *prop_p) /**< property */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (prop_p != NULL && ecma_is_property_lcached (prop_p)); + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*prop_p)); + + jmem_cpointer_t object_cp; + ECMA_SET_NON_NULL_POINTER (object_cp, object_p); + + size_t row_index = ecma_lcache_row_index (object_cp, name_cp); + ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache)[row_index]; + + while (true) + { + /* The property must be present. */ + JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache)[row_index] < ECMA_LCACHE_HASH_ROW_LENGTH); + + if (entry_p->id != 0 && entry_p->prop_p == prop_p) + { + JERRY_ASSERT (entry_p->id == ECMA_LCACHE_CREATE_ID (object_cp, name_cp)); + + ecma_lcache_invalidate_entry (entry_p); + return; + } + entry_p++; + } +} /* ecma_lcache_invalidate */ + +#endif /* JERRY_LCACHE */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-lcache.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-lcache.h new file mode 100644 index 0000000..818e410 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-lcache.h @@ -0,0 +1,40 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_LCACHE_H +#define ECMA_LCACHE_H + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmalcache Property lookup cache + * @{ + */ + +#include "ecma-globals.h" + +#if JERRY_LCACHE +void ecma_lcache_insert (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p); +ecma_property_t *ecma_lcache_lookup (const ecma_object_t *object_p, const ecma_string_t *prop_name_p); +void ecma_lcache_invalidate (const ecma_object_t *object_p, const jmem_cpointer_t name_cp, ecma_property_t *prop_p); + +#endif /* JERRY_LCACHE */ + +/** + * @} + * @} + */ + +#endif /* !ECMA_LCACHE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-literal-storage.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-literal-storage.cpp new file mode 100644 index 0000000..db086a5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-literal-storage.cpp @@ -0,0 +1,741 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-literal-storage.h" + +#include "ecma-alloc.h" +#include "ecma-big-uint.h" +#include "ecma-bigint.h" +#include "ecma-helpers.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmalitstorage Literal storage + * @{ + */ + +/** + * Free symbol list + */ +static void +ecma_free_symbol_list (jmem_cpointer_t symbol_list_cp) /**< symbol list */ +{ + while (symbol_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *symbol_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, symbol_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (symbol_list_p->values[i] != JMEM_CP_NULL) + { + ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, symbol_list_p->values[i]); + + JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p)); + ecma_deref_ecma_string (string_p); + } + } + + jmem_cpointer_t next_item_cp = symbol_list_p->next_cp; + jmem_pools_free (symbol_list_p, sizeof (ecma_lit_storage_item_t)); + symbol_list_cp = next_item_cp; + } +} /* ecma_free_symbol_list */ + +/** + * Free string list + */ +static void +ecma_free_string_list (jmem_cpointer_t string_list_cp) /**< string list */ +{ + while (string_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, string_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (string_list_p->values[i] != JMEM_CP_NULL) + { + ecma_string_t *string_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, string_list_p->values[i]); + + JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p)); + ecma_destroy_ecma_string (string_p); + } + } + + jmem_cpointer_t next_item_cp = string_list_p->next_cp; + jmem_pools_free (string_list_p, sizeof (ecma_lit_storage_item_t)); + string_list_cp = next_item_cp; + } +} /* ecma_free_string_list */ + +/** + * Free number list + */ +static void +ecma_free_number_list (jmem_cpointer_t number_list_cp) /**< number list */ +{ + while (number_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *number_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, number_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (number_list_p->values[i] != JMEM_CP_NULL) + { + ecma_dealloc_number (JMEM_CP_GET_NON_NULL_POINTER (ecma_number_t, number_list_p->values[i])); + } + } + + jmem_cpointer_t next_item_cp = number_list_p->next_cp; + jmem_pools_free (number_list_p, sizeof (ecma_lit_storage_item_t)); + number_list_cp = next_item_cp; + } +} /* ecma_free_number_list */ + +#if JERRY_BUILTIN_BIGINT + +/** + * Free bigint list + */ +static void +ecma_free_bigint_list (jmem_cpointer_t bigint_list_cp) /**< bigint list */ +{ + while (bigint_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *bigint_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, bigint_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (bigint_list_p->values[i] != JMEM_CP_NULL) + { + ecma_extended_primitive_t *bigint_p = + JMEM_CP_GET_NON_NULL_POINTER (ecma_extended_primitive_t, bigint_list_p->values[i]); + JERRY_ASSERT (ECMA_EXTENDED_PRIMITIVE_IS_REF_EQUALS_TO_ONE (bigint_p)); + ecma_deref_bigint (bigint_p); + } + } + + jmem_cpointer_t next_item_cp = bigint_list_p->next_cp; + jmem_pools_free (bigint_list_p, sizeof (ecma_lit_storage_item_t)); + bigint_list_cp = next_item_cp; + } +} /* ecma_free_bigint_list */ + +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Finalize literal storage + */ +void +ecma_finalize_lit_storage (void) +{ + ecma_free_symbol_list (JERRY_CONTEXT (symbol_list_first_cp)); + ecma_free_string_list (JERRY_CONTEXT (string_list_first_cp)); + ecma_free_number_list (JERRY_CONTEXT (number_list_first_cp)); +#if JERRY_BUILTIN_BIGINT + ecma_free_bigint_list (JERRY_CONTEXT (bigint_list_first_cp)); +#endif /* JERRY_BUILTIN_BIGINT */ +} /* ecma_finalize_lit_storage */ + +/** + * Find or create a literal string. + * + * @return ecma_string_t compressed pointer + */ +ecma_value_t +ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string to be searched */ + lit_utf8_size_t size, /**< size of the string */ + bool is_ascii) /**< encode of the string */ +{ + ecma_string_t *string_p = + (is_ascii ? ecma_new_ecma_string_from_ascii (chars_p, size) : ecma_new_ecma_string_from_utf8 (chars_p, size)); + + if (ECMA_IS_DIRECT_STRING (string_p)) + { + return ecma_make_string_value (string_p); + } + + jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp); + jmem_cpointer_t *empty_cpointer_p = NULL; + + while (string_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, string_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (string_list_p->values[i] == JMEM_CP_NULL) + { + if (empty_cpointer_p == NULL) + { + empty_cpointer_p = string_list_p->values + i; + } + } + else + { + ecma_string_t *value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, string_list_p->values[i]); + + if (ecma_compare_ecma_strings (string_p, value_p)) + { + /* Return with string if found in the list. */ + ecma_deref_ecma_string (string_p); + return ecma_make_string_value (value_p); + } + } + } + + string_list_cp = string_list_p->next_cp; + } + + ECMA_SET_STRING_AS_STATIC (string_p); + jmem_cpointer_t result; + JMEM_CP_SET_NON_NULL_POINTER (result, string_p); + + if (empty_cpointer_p != NULL) + { + *empty_cpointer_p = result; + return ecma_make_string_value (string_p); + } + + ecma_lit_storage_item_t *new_item_p; + new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t)); + + new_item_p->values[0] = result; + for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + new_item_p->values[i] = JMEM_CP_NULL; + } + + new_item_p->next_cp = JERRY_CONTEXT (string_list_first_cp); + JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (string_list_first_cp), new_item_p); + + return ecma_make_string_value (string_p); +} /* ecma_find_or_create_literal_string */ + +/** + * Find or create a literal number. + * + * @return ecma value + */ +ecma_value_t +ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be searched */ +{ + ecma_value_t num = ecma_make_number_value (number_arg); + + if (ecma_is_value_integer_number (num)) + { + return num; + } + + JERRY_ASSERT (ecma_is_value_float_number (num)); + + jmem_cpointer_t number_list_cp = JERRY_CONTEXT (number_list_first_cp); + jmem_cpointer_t *empty_cpointer_p = NULL; + + while (number_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *number_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, number_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (number_list_p->values[i] == JMEM_CP_NULL) + { + if (empty_cpointer_p == NULL) + { + empty_cpointer_p = number_list_p->values + i; + } + } + else + { + ecma_number_t *number_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_number_t, number_list_p->values[i]); + + if (*number_p == number_arg) + { + ecma_free_value (num); + return ecma_make_float_value (number_p); + } + } + } + + number_list_cp = number_list_p->next_cp; + } + + jmem_cpointer_t result; + JMEM_CP_SET_NON_NULL_POINTER (result, ecma_get_pointer_from_float_value (num)); + + if (empty_cpointer_p != NULL) + { + *empty_cpointer_p = result; + return num; + } + + ecma_lit_storage_item_t *new_item_p; + new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t)); + + new_item_p->values[0] = result; + for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + new_item_p->values[i] = JMEM_CP_NULL; + } + + new_item_p->next_cp = JERRY_CONTEXT (number_list_first_cp); + JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (number_list_first_cp), new_item_p); + + return num; +} /* ecma_find_or_create_literal_number */ + +#if JERRY_BUILTIN_BIGINT + +/** + * Find or create a literal BigInt. + * + * @return BigInt value + */ +ecma_value_t +ecma_find_or_create_literal_bigint (ecma_value_t bigint) /**< bigint to be searched */ +{ + JERRY_ASSERT (ecma_is_value_bigint (bigint)); + + if (bigint == ECMA_BIGINT_ZERO) + { + return bigint; + } + + jmem_cpointer_t bigint_list_cp = JERRY_CONTEXT (bigint_list_first_cp); + jmem_cpointer_t *empty_cpointer_p = NULL; + + while (bigint_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *bigint_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, bigint_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (bigint_list_p->values[i] == JMEM_CP_NULL) + { + if (empty_cpointer_p == NULL) + { + empty_cpointer_p = bigint_list_p->values + i; + } + } + else + { + ecma_extended_primitive_t *other_bigint_p = + JMEM_CP_GET_NON_NULL_POINTER (ecma_extended_primitive_t, bigint_list_p->values[i]); + ecma_value_t other_bigint = ecma_make_extended_primitive_value (other_bigint_p, ECMA_TYPE_BIGINT); + + if (ecma_bigint_is_equal_to_bigint (bigint, other_bigint)) + { + ecma_free_value (bigint); + return other_bigint; + } + } + } + + bigint_list_cp = bigint_list_p->next_cp; + } + + jmem_cpointer_t result; + JMEM_CP_SET_NON_NULL_POINTER (result, ecma_get_extended_primitive_from_value (bigint)); + + if (empty_cpointer_p != NULL) + { + *empty_cpointer_p = result; + return bigint; + } + + ecma_lit_storage_item_t *new_item_p; + new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t)); + + new_item_p->values[0] = result; + for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + new_item_p->values[i] = JMEM_CP_NULL; + } + + new_item_p->next_cp = JERRY_CONTEXT (bigint_list_first_cp); + JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (bigint_list_first_cp), new_item_p); + + return bigint; +} /* ecma_find_or_create_literal_bigint */ + +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Log2 of snapshot literal alignment. + */ +#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG 1 + +/** + * Snapshot literal alignment. + */ +#define JERRY_SNAPSHOT_LITERAL_ALIGNMENT (1u << JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG) + +/** + * Literal offset shift. + */ +#define JERRY_SNAPSHOT_LITERAL_SHIFT (ECMA_VALUE_SHIFT + 2) + +/** + * Literal value is number. + */ +#define JERRY_SNAPSHOT_LITERAL_IS_NUMBER (1u << ECMA_VALUE_SHIFT) + +#if JERRY_BUILTIN_BIGINT +/** + * Literal value is BigInt. + */ +#define JERRY_SNAPSHOT_LITERAL_IS_BIGINT (2u << ECMA_VALUE_SHIFT) +#endif /* JERRY_BUILTIN_BIGINT */ + +#if JERRY_SNAPSHOT_SAVE + +/** + * Append the value at the end of the appropriate list if it is not present there. + */ +void +ecma_save_literals_append_value (ecma_value_t value, /**< value to be appended */ + ecma_collection_t *lit_pool_p) /**< list of known values */ +{ + /* Unlike direct numbers, direct strings are converted to character literals. */ + if (!ecma_is_value_string (value) +#if JERRY_BUILTIN_BIGINT + && (!ecma_is_value_bigint (value) || value == ECMA_BIGINT_ZERO) +#endif /* JERRY_BUILTIN_BIGINT */ + && !ecma_is_value_float_number (value)) + { + return; + } + + ecma_value_t *buffer_p = lit_pool_p->buffer_p; + + for (uint32_t i = 0; i < lit_pool_p->item_count; i++) + { + /* Strings / numbers are direct strings or stored in the literal storage. + * Therefore direct comparison is enough to find the same strings / numbers. */ + if (buffer_p[i] == value) + { + return; + } + } + + ecma_collection_push_back (lit_pool_p, value); +} /* ecma_save_literals_append_value */ + +/** + * Add names from a byte-code data to a list. + */ +void +ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< byte-code data */ + ecma_collection_t *lit_pool_p) /**< list of known values */ +{ + ecma_value_t *literal_p; + uint32_t argument_end; + uint32_t register_end; + uint32_t const_literal_end; + uint32_t literal_end; + + JERRY_ASSERT (CBC_IS_FUNCTION (compiled_code_p->status_flags)); + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p; + uint8_t *byte_p = (uint8_t *) compiled_code_p; + + literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint16_arguments_t)); + register_end = args_p->register_end; + const_literal_end = args_p->const_literal_end - register_end; + literal_end = args_p->literal_end - register_end; + argument_end = args_p->argument_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p; + uint8_t *byte_p = (uint8_t *) compiled_code_p; + + literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint8_arguments_t)); + register_end = args_p->register_end; + const_literal_end = args_p->const_literal_end - register_end; + literal_end = args_p->literal_end - register_end; + argument_end = args_p->argument_end; + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED) + { + for (uint32_t i = 0; i < argument_end; i++) + { + ecma_save_literals_append_value (literal_p[i], lit_pool_p); + } + } + + for (uint32_t i = 0; i < const_literal_end; i++) + { + ecma_save_literals_append_value (literal_p[i], lit_pool_p); + } + + for (uint32_t i = const_literal_end; i < literal_end; i++) + { + ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, literal_p[i]); + + if (CBC_IS_FUNCTION (bytecode_p->status_flags) && bytecode_p != compiled_code_p) + { + ecma_save_literals_add_compiled_code (bytecode_p, lit_pool_p); + } + } + + uint8_t *byte_p = ((uint8_t *) compiled_code_p) + (((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG); + literal_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) compiled_code_p, byte_p); + + while (literal_p < (ecma_value_t *) byte_p) + { + ecma_save_literals_append_value (*literal_p, lit_pool_p); + literal_p++; + } +} /* ecma_save_literals_add_compiled_code */ + +/** + * Save literals to specified snapshot buffer. + * + * Note: + * Frees 'lit_pool_p' regardless of success. + * + * @return true - if save was performed successfully (i.e. buffer size is sufficient), + * false - otherwise + */ +bool +ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, /**< list of known values */ + uint32_t *buffer_p, /**< [out] output snapshot buffer */ + size_t buffer_size, /**< size of the buffer */ + size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */ + lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal identifiers + * to the literal offsets + * in snapshot */ + uint32_t *out_map_len_p) /**< [out] number of literals */ +{ + if (lit_pool_p->item_count == 0) + { + *out_map_p = NULL; + *out_map_len_p = 0; + } + + uint32_t lit_table_size = 0; + size_t max_lit_table_size = buffer_size - *in_out_buffer_offset_p; + + if (max_lit_table_size > (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT)) + { + max_lit_table_size = (UINT32_MAX >> JERRY_SNAPSHOT_LITERAL_SHIFT); + } + + ecma_value_t *lit_buffer_p = lit_pool_p->buffer_p; + + /* Compute the size of the literal pool. */ + for (uint32_t i = 0; i < lit_pool_p->item_count; i++) + { + if (ecma_is_value_float_number (lit_buffer_p[i])) + { + lit_table_size += (uint32_t) sizeof (ecma_number_t); + } +#if JERRY_BUILTIN_BIGINT + else if (ecma_is_value_bigint (lit_buffer_p[i])) + { + ecma_extended_primitive_t *bigint_p = ecma_get_extended_primitive_from_value (lit_buffer_p[i]); + + lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint32_t) + ECMA_BIGINT_GET_SIZE (bigint_p), + JERRY_SNAPSHOT_LITERAL_ALIGNMENT); + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + ecma_string_t *string_p = ecma_get_string_from_value (lit_buffer_p[i]); + + lit_table_size += (uint32_t) JERRY_ALIGNUP (sizeof (uint16_t) + ecma_string_get_size (string_p), + JERRY_SNAPSHOT_LITERAL_ALIGNMENT); + } + + /* Check whether enough space is available and the maximum size is not reached. */ + if (lit_table_size > max_lit_table_size) + { + ecma_collection_destroy (lit_pool_p); + return false; + } + } + + lit_mem_to_snapshot_id_map_entry_t *map_p; + uint32_t total_count = lit_pool_p->item_count; + + map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t)); + + /* Set return values (no error is possible from here). */ + JERRY_ASSERT ((*in_out_buffer_offset_p % sizeof (uint32_t)) == 0); + + uint8_t *destination_p = (uint8_t *) (buffer_p + (*in_out_buffer_offset_p / sizeof (uint32_t))); + uint32_t literal_offset = 0; + + *in_out_buffer_offset_p += lit_table_size; + *out_map_p = map_p; + *out_map_len_p = total_count; + + lit_buffer_p = lit_pool_p->buffer_p; + + /* Generate literal pool data. */ + for (uint32_t i = 0; i < lit_pool_p->item_count; i++) + { + map_p->literal_id = lit_buffer_p[i]; + map_p->literal_offset = (literal_offset << JERRY_SNAPSHOT_LITERAL_SHIFT) | ECMA_TYPE_SNAPSHOT_OFFSET; + + lit_utf8_size_t length; + + if (ecma_is_value_float_number (lit_buffer_p[i])) + { + map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_NUMBER; + + ecma_number_t num = ecma_get_float_from_value (lit_buffer_p[i]); + memcpy (destination_p, &num, sizeof (ecma_number_t)); + + length = JERRY_ALIGNUP (sizeof (ecma_number_t), JERRY_SNAPSHOT_LITERAL_ALIGNMENT); + } +#if JERRY_BUILTIN_BIGINT + else if (ecma_is_value_bigint (lit_buffer_p[i])) + { + map_p->literal_offset |= JERRY_SNAPSHOT_LITERAL_IS_BIGINT; + + ecma_extended_primitive_t *bigint_p = ecma_get_extended_primitive_from_value (lit_buffer_p[i]); + uint32_t size = ECMA_BIGINT_GET_SIZE (bigint_p); + + memcpy (destination_p, &bigint_p->u.bigint_sign_and_size, sizeof (uint32_t)); + memcpy (destination_p + sizeof (uint32_t), ECMA_BIGINT_GET_DIGITS (bigint_p, 0), size); + + length = JERRY_ALIGNUP (sizeof (uint32_t) + size, JERRY_SNAPSHOT_LITERAL_ALIGNMENT); + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + ecma_string_t *string_p = ecma_get_string_from_value (lit_buffer_p[i]); + length = ecma_string_get_size (string_p); + + *(uint16_t *) destination_p = (uint16_t) length; + + ecma_string_to_cesu8_bytes (string_p, destination_p + sizeof (uint16_t), length); + + length = JERRY_ALIGNUP (sizeof (uint16_t) + length, JERRY_SNAPSHOT_LITERAL_ALIGNMENT); + } + + JERRY_ASSERT ((length % sizeof (uint16_t)) == 0); + destination_p += length; + literal_offset += length; + + map_p++; + } + + ecma_collection_destroy (lit_pool_p); + return true; +} /* ecma_save_literals_for_snapshot */ + +#endif /* JERRY_SNAPSHOT_SAVE */ + +#if JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE + +/** + * Get the compressed pointer of a given literal. + * + * @return literal compressed pointer + */ +ecma_value_t +ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */ + ecma_value_t literal_value) /**< string / number offset */ +{ + JERRY_ASSERT ((literal_value & ECMA_VALUE_TYPE_MASK) == ECMA_TYPE_SNAPSHOT_OFFSET); + + const uint8_t *literal_p = literal_base_p + (literal_value >> JERRY_SNAPSHOT_LITERAL_SHIFT); + + if (literal_value & JERRY_SNAPSHOT_LITERAL_IS_NUMBER) + { + ecma_number_t num; + memcpy (&num, literal_p, sizeof (ecma_number_t)); + return ecma_find_or_create_literal_number (num); + } + +#if JERRY_BUILTIN_BIGINT + if (literal_value & JERRY_SNAPSHOT_LITERAL_IS_BIGINT) + { + uint32_t bigint_sign_and_size = *(uint32_t *) literal_p; + uint32_t size = bigint_sign_and_size & ~(uint32_t) (sizeof (ecma_bigint_digit_t) - 1); + + ecma_extended_primitive_t *bigint_p = ecma_bigint_create (size); + + if (bigint_p == NULL) + { + jerry_fatal (JERRY_FATAL_OUT_OF_MEMORY); + } + + /* Only the sign bit can differ. */ + JERRY_ASSERT (bigint_p->u.bigint_sign_and_size == (bigint_sign_and_size & ~(uint32_t) ECMA_BIGINT_SIGN)); + + bigint_p->u.bigint_sign_and_size = bigint_sign_and_size; + memcpy (ECMA_BIGINT_GET_DIGITS (bigint_p, 0), literal_p + sizeof (uint32_t), size); + return ecma_find_or_create_literal_bigint (ecma_make_extended_primitive_value (bigint_p, ECMA_TYPE_BIGINT)); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + uint16_t length = *(const uint16_t *) literal_p; + + return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t), length, false); +} /* ecma_snapshot_get_literal */ + +/** + * Compute the start of the serializable ecma-values of the bytecode + * Related values: + * - function argument names, if CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED is present + * - function name, if CBC_CODE_FLAGS_CLASS_CONSTRUCTOR is not present and es.next profile is enabled + * + * @return pointer to the beginning of the serializable ecma-values + */ +ecma_value_t * +ecma_snapshot_resolve_serializable_values (const ecma_compiled_code_t *compiled_code_p, /**< compiled code */ + uint8_t *bytecode_end_p) /**< end of the bytecode */ +{ + ecma_value_t *base_p = (ecma_value_t *) bytecode_end_p; + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED) + { + uint32_t argument_end; + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + argument_end = ((cbc_uint16_arguments_t *) compiled_code_p)->argument_end; + } + else + { + argument_end = ((cbc_uint8_arguments_t *) compiled_code_p)->argument_end; + } + + base_p -= argument_end; + } + + /* function name */ + if (CBC_FUNCTION_GET_TYPE (compiled_code_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR) + { + base_p--; + } + + return base_p; +} /* ecma_snapshot_resolve_serializable_values */ +#endif /* JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-literal-storage.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-literal-storage.h new file mode 100644 index 0000000..6850a86 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-literal-storage.h @@ -0,0 +1,72 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_LIT_STORAGE_H +#define ECMA_LIT_STORAGE_H + +#include "ecma-globals.h" + +#include "jmem.h" +#include "lit-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmalitstorage Literal storage + * @{ + */ + +#if JERRY_SNAPSHOT_SAVE +/** + * Snapshot literal - offset map + */ +typedef struct +{ + ecma_value_t literal_id; /**< literal id */ + ecma_value_t literal_offset; /**< literal offset */ +} lit_mem_to_snapshot_id_map_entry_t; +#endif /* JERRY_SNAPSHOT_SAVE */ + +void ecma_finalize_lit_storage (void); + +ecma_value_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, lit_utf8_size_t size, bool is_ascii); +ecma_value_t ecma_find_or_create_literal_number (ecma_number_t number_arg); +#if JERRY_BUILTIN_BIGINT +ecma_value_t ecma_find_or_create_literal_bigint (ecma_value_t bigint); +#endif /* JERRY_BUILTIN_BIGINT */ + +#if JERRY_SNAPSHOT_SAVE +void ecma_save_literals_append_value (ecma_value_t value, ecma_collection_t *lit_pool_p); +void ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, ecma_collection_t *lit_pool_p); +bool ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, + uint32_t *buffer_p, + size_t buffer_size, + size_t *in_out_buffer_offset_p, + lit_mem_to_snapshot_id_map_entry_t **out_map_p, + uint32_t *out_map_len_p); +#endif /* JERRY_SNAPSHOT_SAVE */ + +#if JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE +ecma_value_t ecma_snapshot_get_literal (const uint8_t *literal_base_p, ecma_value_t literal_value); +ecma_value_t *ecma_snapshot_resolve_serializable_values (const ecma_compiled_code_t *compiled_code_p, + uint8_t *byte_code_end_p); +#endif /* JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE */ + +/** + * @} + * @} + */ + +#endif /* !ECMA_LIT_STORAGE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-module.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-module.cpp new file mode 100644 index 0000000..fb59953 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-module.cpp @@ -0,0 +1,1444 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-module.h" + +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "lit-char-helpers.h" +#include "vm.h" + +#if JERRY_MODULE_SYSTEM + +/** + * Type of the result returned by ecma_module_resolve_export. + */ +typedef enum +{ + ECMA_MODULE_RESOLVE_NOT_FOUND, /**< reference not found */ + ECMA_MODULE_RESOLVE_CIRCULAR, /**< only circular references are found */ + ECMA_MODULE_RESOLVE_ERROR, /**< module in error state is encountered */ + ECMA_MODULE_RESOLVE_AMBIGUOUS, /**< reference is ambiguous */ + ECMA_MODULE_RESOLVE_FOUND, /**< reference found */ +} ecma_module_resolve_result_type_t; + +/** + * A record that stores the result of ecma_module_resolve_export. + */ +typedef struct +{ + ecma_module_resolve_result_type_t result_type; /**< result type */ + ecma_value_t result; /**< result value */ +} ecma_module_resolve_result_t; + +/** + * This flag is set in the result if the value is a namespace object. + */ +#define ECMA_MODULE_NAMESPACE_RESULT_FLAG 0x2 + +/** + * Initialize context variables for the root module. + * + * @return new module + */ +ecma_module_t * +ecma_module_create (void) +{ + JERRY_ASSERT (JERRY_CONTEXT (module_current_p) == NULL); + + ecma_object_t *obj_p = ecma_create_object (NULL, sizeof (ecma_module_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_MODULE; + ext_object_p->u.cls.u1.module_state = JERRY_MODULE_STATE_UNLINKED; + ext_object_p->u.cls.u2.module_flags = 0; + + ecma_module_t *module_p = (ecma_module_t *) obj_p; + + module_p->scope_p = NULL; + module_p->namespace_object_p = NULL; + module_p->imports_p = NULL; + module_p->local_exports_p = NULL; + module_p->indirect_exports_p = NULL; + module_p->star_exports_p = NULL; + module_p->u.compiled_code_p = NULL; + + return module_p; +} /* ecma_module_create */ + +/** + * Cleanup context variables for the root module. + */ +void +ecma_module_cleanup_context (void) +{ + ecma_deref_object ((ecma_object_t *) JERRY_CONTEXT (module_current_p)); +#ifndef JERRY_NDEBUG + JERRY_CONTEXT (module_current_p) = NULL; +#endif /* JERRY_NDEBUG */ +} /* ecma_module_cleanup_context */ + +/** + * Sets module state to error. + */ +static void +ecma_module_set_error_state (ecma_module_t *module_p) /**< module */ +{ + module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_ERROR; + + if (JERRY_CONTEXT (module_state_changed_callback_p) != NULL && !jcontext_has_pending_abort ()) + { + jerry_value_t exception = jcontext_take_exception (); + + JERRY_CONTEXT (module_state_changed_callback_p) + (JERRY_MODULE_STATE_ERROR, + ecma_make_object_value (&module_p->header.object), + exception, + JERRY_CONTEXT (module_state_changed_callback_user_p)); + jcontext_raise_exception (exception); + } +} /* ecma_module_set_error_state */ + +/** + * Gets the internal module pointer of a module + * + * @return module pointer + */ +static inline ecma_module_t * +ecma_module_get_from_object (ecma_value_t module_val) /**< module */ +{ + JERRY_ASSERT (ecma_is_value_object (module_val)); + + ecma_object_t *object_p = ecma_get_object_from_value (module_val); + + JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_MODULE)); + + return (ecma_module_t *) object_p; +} /* ecma_module_get_from_object */ + +/** + * Cleans up a list of module names. + */ +void +ecma_module_release_module_names (ecma_module_names_t *module_name_p) /**< first module name */ +{ + while (module_name_p != NULL) + { + ecma_module_names_t *next_p = module_name_p->next_p; + + ecma_deref_ecma_string (module_name_p->imex_name_p); + ecma_deref_ecma_string (module_name_p->local_name_p); + jmem_heap_free_block (module_name_p, sizeof (ecma_module_names_t)); + + module_name_p = next_p; + } +} /* ecma_module_release_module_names */ + +/** + * Cleans up a list of module nodes. + */ +static void +ecma_module_release_module_nodes (ecma_module_node_t *module_node_p, /**< first module node */ + bool is_import) /**< free path variable */ +{ + while (module_node_p != NULL) + { + ecma_module_node_t *next_p = module_node_p->next_p; + + ecma_module_release_module_names (module_node_p->module_names_p); + + if (is_import && ecma_is_value_string (module_node_p->u.path_or_module)) + { + ecma_deref_ecma_string (ecma_get_string_from_value (module_node_p->u.path_or_module)); + } + + jmem_heap_free_block (module_node_p, sizeof (ecma_module_node_t)); + module_node_p = next_p; + } +} /* ecma_module_release_module_nodes */ + +/** + * Creates a new resolve set item from a {module, export_name} pair. + * + * @return new resolve set item + */ +static ecma_module_resolve_set_t * +ecma_module_resolve_set_create (ecma_module_t *const module_p, /**< module */ + ecma_string_t *const export_name_p) /**< export name */ +{ + ecma_module_resolve_set_t *new_p; + new_p = (ecma_module_resolve_set_t *) jmem_heap_alloc_block (sizeof (ecma_module_resolve_set_t)); + + new_p->next_p = NULL; + new_p->module_p = module_p; + new_p->name_p = export_name_p; + + return new_p; +} /* ecma_module_resolve_set_create */ + +/** + * Appends a {module, export_name} record into a resolve set. + * + * @return true - if the record is appended successfully + * false - otherwise + */ +static bool +ecma_module_resolve_set_append (ecma_module_resolve_set_t *set_p, /**< resolve set */ + ecma_module_t *const module_p, /**< module */ + ecma_string_t *const export_name_p) /**< export name */ +{ + JERRY_ASSERT (set_p != NULL); + ecma_module_resolve_set_t *current_p = set_p; + + while (true) + { + if (current_p->module_p == module_p && ecma_compare_ecma_strings (current_p->name_p, export_name_p)) + { + return false; + } + + ecma_module_resolve_set_t *next_p = current_p->next_p; + + if (next_p == NULL) + { + current_p->next_p = ecma_module_resolve_set_create (module_p, export_name_p); + return true; + } + + current_p = next_p; + } +} /* ecma_module_resolve_set_append */ + +/** + * Cleans up contents of a resolve set. + */ +static void +ecma_module_resolve_set_cleanup (ecma_module_resolve_set_t *set_p) /**< resolve set */ +{ + while (set_p != NULL) + { + ecma_module_resolve_set_t *next_p = set_p->next_p; + jmem_heap_free_block (set_p, sizeof (ecma_module_resolve_set_t)); + set_p = next_p; + } +} /* ecma_module_resolve_set_cleanup */ + +/** + * Throws the appropriate error based on the resolve result + * + * @return error value + */ +static ecma_value_t +ecma_module_resolve_throw (ecma_module_resolve_result_t *resolve_result_p, /**< resolve result */ + ecma_string_t *name_p) /**< referenced value */ +{ +#if JERRY_ERROR_MESSAGES + ecma_value_t name_val = ecma_make_string_value (name_p); + const char *msg_p; + + switch (resolve_result_p->result_type) + { + case ECMA_MODULE_RESOLVE_CIRCULAR: + { + msg_p = "Detected cycle while resolving name '%' (module)"; + break; + } + case ECMA_MODULE_RESOLVE_AMBIGUOUS: + { + msg_p = "Name '%' is ambiguous (module)"; + break; + } + default: + { + JERRY_ASSERT (resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND + || resolve_result_p->result_type == ECMA_MODULE_RESOLVE_ERROR); + + msg_p = "Name '%' is not found (module)"; + break; + } + } + + return ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX, msg_p, name_val); +#else /* JERRY_ERROR_MESSAGES */ + JERRY_UNUSED (resolve_result_p); + JERRY_UNUSED (name_p); + + return ecma_raise_syntax_error (ECMA_ERR_EMPTY); +#endif /* !JERRY_ERROR_MESSAGES */ +} /* ecma_module_resolve_throw */ + +/** + * Updates the resolve record with the passed type/value pair + * + * @return true - if the record is updated successfully + * false - otherwise + */ +static bool +ecma_module_resolve_update (ecma_module_resolve_result_t *resolve_result_p, /**< [in,out] resolve result */ + ecma_value_t result) /**< result value */ +{ + JERRY_ASSERT (resolve_result_p->result_type != ECMA_MODULE_RESOLVE_AMBIGUOUS + && resolve_result_p->result_type != ECMA_MODULE_RESOLVE_ERROR); + + if (resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND + || resolve_result_p->result_type == ECMA_MODULE_RESOLVE_CIRCULAR) + { + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_FOUND; + resolve_result_p->result = result; + return true; + } + + JERRY_ASSERT (resolve_result_p->result_type == ECMA_MODULE_RESOLVE_FOUND); + + if (resolve_result_p->result == result) + { + return true; + } + + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_AMBIGUOUS; + return false; +} /* ecma_module_resolve_update */ + +/** + * Finds the reference in the imported bindings. + * + * Note: + * This function is needed because the namespace object is created before the imports are connected + * + * @return true - if the record is updated successfully + * false - otherwise + */ +static bool +ecma_module_resolve_import (ecma_module_resolve_result_t *resolve_result_p, /**< [in,out] resolve result */ + ecma_module_resolve_set_t *resolve_set_p, /**< resolve set */ + ecma_module_t *module_p, /**< base module */ + ecma_string_t *local_name_p) /**< local name */ +{ + ecma_module_node_t *import_node_p = module_p->imports_p; + + while (true) + { + JERRY_ASSERT (import_node_p != NULL); + + for (ecma_module_names_t *import_names_p = import_node_p->module_names_p; import_names_p != NULL; + import_names_p = import_names_p->next_p) + { + if (ecma_compare_ecma_strings (local_name_p, import_names_p->local_name_p)) + { + ecma_module_t *imported_module_p = ecma_module_get_from_object (import_node_p->u.path_or_module); + + if (ecma_compare_ecma_string_to_magic_id (import_names_p->imex_name_p, LIT_MAGIC_STRING_ASTERISK_CHAR)) + { + /* Namespace import. */ + ecma_value_t ns = ecma_make_object_value (imported_module_p->namespace_object_p); + + JERRY_ASSERT (ns & ECMA_MODULE_NAMESPACE_RESULT_FLAG); + + return ecma_module_resolve_update (resolve_result_p, ns); + } + + if (!ecma_module_resolve_set_append (resolve_set_p, imported_module_p, import_names_p->imex_name_p) + && resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND) + { + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_CIRCULAR; + } + + return true; + } + } + + import_node_p = import_node_p->next_p; + } +} /* ecma_module_resolve_import */ + +/** + * Resolves which module satisfies an export based from a specific module in the import tree. + * + * Note: See ES11 15.2.1.17.3 + */ +static void +ecma_module_resolve_export (ecma_module_t *const module_p, /**< base module */ + ecma_string_t *const export_name_p, /**< export name */ + ecma_module_resolve_result_t *resolve_result_p) /**< [out] resolve result */ +{ + ecma_module_resolve_set_t *resolve_set_p = ecma_module_resolve_set_create (module_p, export_name_p); + ecma_module_resolve_set_t *current_set_p = resolve_set_p; + ecma_module_node_t *star_export_p; + + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_NOT_FOUND; + resolve_result_p->result = ECMA_VALUE_UNDEFINED; + + do + { + ecma_module_t *current_module_p = current_set_p->module_p; + ecma_string_t *current_export_name_p = current_set_p->name_p; + + if (current_module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_ERROR) + { + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_ERROR; + goto exit; + } + + if (current_module_p->header.u.cls.u2.module_flags & ECMA_MODULE_HAS_NAMESPACE) + { + ecma_property_t *property_p = + ecma_find_named_property (current_module_p->namespace_object_p, current_export_name_p); + + if (property_p != NULL) + { + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + JERRY_ASSERT ( + (!(*property_p & ECMA_PROPERTY_FLAG_DATA) && !(property_value_p->value & ECMA_MODULE_NAMESPACE_RESULT_FLAG)) + || ((*property_p & ECMA_PROPERTY_FLAG_DATA) && ecma_is_value_object (property_value_p->value) + && ecma_object_class_is (ecma_get_object_from_value (property_value_p->value), + ECMA_OBJECT_CLASS_MODULE_NAMESPACE))); + + if (!ecma_module_resolve_update (resolve_result_p, property_value_p->value)) + { + goto exit; + } + + goto next_iteration; + } + } + else + { + /* 6. */ + ecma_module_names_t *export_names_p = current_module_p->local_exports_p; + + while (export_names_p != NULL) + { + if (ecma_compare_ecma_strings (current_export_name_p, export_names_p->imex_name_p)) + { + ecma_property_t *property_p = + ecma_find_named_property (current_module_p->scope_p, export_names_p->local_name_p); + + if (property_p != NULL) + { + ecma_value_t reference = ecma_property_to_reference (property_p); + + JERRY_ASSERT (!(reference & ECMA_MODULE_NAMESPACE_RESULT_FLAG)); + + if (!ecma_module_resolve_update (resolve_result_p, reference)) + { + goto exit; + } + } + else if (!ecma_module_resolve_import (resolve_result_p, + resolve_set_p, + current_module_p, + export_names_p->local_name_p)) + { + goto exit; + } + + goto next_iteration; + } + + export_names_p = export_names_p->next_p; + } + + /* 7. */ + ecma_module_node_t *indirect_export_p = current_module_p->indirect_exports_p; + + while (indirect_export_p != NULL) + { + export_names_p = indirect_export_p->module_names_p; + + while (export_names_p != NULL) + { + if (ecma_compare_ecma_strings (current_export_name_p, export_names_p->imex_name_p)) + { + ecma_module_t *target_module_p = ecma_module_get_from_object (*indirect_export_p->u.module_object_p); + + if (ecma_compare_ecma_string_to_magic_id (export_names_p->local_name_p, LIT_MAGIC_STRING_ASTERISK_CHAR)) + { + /* Namespace export. */ + ecma_value_t ns = ecma_make_object_value (target_module_p->namespace_object_p); + + JERRY_ASSERT (ns & ECMA_MODULE_NAMESPACE_RESULT_FLAG); + + if (!ecma_module_resolve_update (resolve_result_p, ns)) + { + goto exit; + } + } + else if (!ecma_module_resolve_set_append (resolve_set_p, target_module_p, export_names_p->local_name_p) + && resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND) + { + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_CIRCULAR; + } + + goto next_iteration; + } + + export_names_p = export_names_p->next_p; + } + + indirect_export_p = indirect_export_p->next_p; + } + } + + /* 8. */ + if (ecma_compare_ecma_string_to_magic_id (current_export_name_p, LIT_MAGIC_STRING_DEFAULT)) + { + goto exit; + } + + /* 10. */ + star_export_p = current_module_p->star_exports_p; + while (star_export_p != NULL) + { + JERRY_ASSERT (star_export_p->module_names_p == NULL); + + ecma_module_t *target_module_p = ecma_module_get_from_object (*star_export_p->u.module_object_p); + + if (!ecma_module_resolve_set_append (resolve_set_p, target_module_p, current_export_name_p) + && resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND) + { + resolve_result_p->result_type = ECMA_MODULE_RESOLVE_CIRCULAR; + } + + star_export_p = star_export_p->next_p; + } + +next_iteration: + current_set_p = current_set_p->next_p; + } while (current_set_p != NULL); + +exit: + ecma_module_resolve_set_cleanup (resolve_set_p); +} /* ecma_module_resolve_export */ + +/** + * Evaluates an EcmaScript module. + * + * @return ECMA_VALUE_ERROR - if an error occurred + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +ecma_module_evaluate (ecma_module_t *module_p) /**< module */ +{ + if (module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_ERROR) + { + return ecma_raise_range_error (ECMA_ERR_MODULE_IS_IN_ERROR_STATE); + } + + if (module_p->header.u.cls.u1.module_state >= JERRY_MODULE_STATE_EVALUATING) + { + return ECMA_VALUE_EMPTY; + } + + JERRY_ASSERT (module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKED); + JERRY_ASSERT (module_p->scope_p != NULL); + + module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_EVALUATING; + + ecma_value_t ret_value; + + if (module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) + { + ret_value = ECMA_VALUE_UNDEFINED; + + if (module_p->u.callback) + { + ret_value = module_p->u.callback (ecma_make_object_value (&module_p->header.object)); + + if (JERRY_UNLIKELY (ecma_is_value_exception (ret_value))) + { + ecma_throw_exception (ret_value); + ret_value = ECMA_VALUE_ERROR; + } + } + } + else + { + ret_value = vm_run_module (module_p); + } + + if (JERRY_LIKELY (!ECMA_IS_VALUE_ERROR (ret_value))) + { + module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_EVALUATED; + + if (JERRY_CONTEXT (module_state_changed_callback_p) != NULL) + { + JERRY_CONTEXT (module_state_changed_callback_p) + (JERRY_MODULE_STATE_EVALUATED, + ecma_make_object_value (&module_p->header.object), + ret_value, + JERRY_CONTEXT (module_state_changed_callback_user_p)); + } + } + else + { + ecma_module_set_error_state (module_p); + } + + if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE)) + { + ecma_bytecode_deref (module_p->u.compiled_code_p); + } + + module_p->u.compiled_code_p = NULL; + return ret_value; +} /* ecma_module_evaluate */ + +/** + * Resolves an export and adds it to the modules namespace object, if the export name is not yet handled. + * Note: See 15.2.1.16.2 and 15.2.1.18 + * + * @return ECMA_VALUE_ERROR - if an error occurred + * ECMA_VALUE_EMPTY - otherwise + */ +static ecma_value_t +ecma_module_namespace_object_add_export_if_needed (ecma_collection_t *properties_p, /**< collection of properties */ + ecma_module_t *module_p, /**< module */ + ecma_string_t *export_name_p, /**< export name */ + bool allow_default) /**< allow default export */ +{ + if (!allow_default) + { + if (ecma_compare_ecma_string_to_magic_id (export_name_p, LIT_MAGIC_STRING_DEFAULT)) + { + return ECMA_VALUE_EMPTY; + } + + /* No need to check duplications before star exports are processed. */ + ecma_value_t *buffer_p = properties_p->buffer_p; + ecma_value_t *buffer_end_p = properties_p->buffer_p + properties_p->item_count; + + while (buffer_p < buffer_end_p) + { + if (ecma_compare_ecma_strings (ecma_get_string_from_value (*buffer_p), export_name_p)) + { + return ECMA_VALUE_EMPTY; + } + + buffer_p += 2; + } + } + + ecma_module_resolve_result_t resolve_result; + ecma_module_resolve_export (module_p, export_name_p, &resolve_result); + + if (resolve_result.result_type == ECMA_MODULE_RESOLVE_AMBIGUOUS) + { + return ECMA_VALUE_EMPTY; + } + + if (resolve_result.result_type != ECMA_MODULE_RESOLVE_FOUND) + { + return ecma_module_resolve_throw (&resolve_result, export_name_p); + } + + ecma_collection_push_back (properties_p, ecma_make_string_value (export_name_p)); + ecma_collection_push_back (properties_p, resolve_result.result); + return ECMA_VALUE_EMPTY; +} /* ecma_module_namespace_object_add_export_if_needed */ + +/** + * Helper routine for heapsort algorithm. + */ +static void +ecma_module_heap_sort_shift_down (ecma_value_t *buffer_p, /**< array of items */ + uint32_t item_count, /**< number of items */ + uint32_t item_index) /**< index of updated item */ +{ + while (true) + { + uint32_t highest_index = item_index; + uint32_t current_index = (item_index << 1) + 2; + + if (current_index >= item_count) + { + return; + } + + if (ecma_compare_ecma_strings_relational (ecma_get_string_from_value (buffer_p[highest_index]), + ecma_get_string_from_value (buffer_p[current_index]))) + { + highest_index = current_index; + } + + current_index += 2; + + if (current_index < item_count + && ecma_compare_ecma_strings_relational (ecma_get_string_from_value (buffer_p[highest_index]), + ecma_get_string_from_value (buffer_p[current_index]))) + { + highest_index = current_index; + } + + if (highest_index == item_index) + { + return; + } + + ecma_value_t tmp = buffer_p[highest_index]; + buffer_p[highest_index] = buffer_p[item_index]; + buffer_p[item_index] = tmp; + + tmp = buffer_p[highest_index + 1]; + buffer_p[highest_index + 1] = buffer_p[item_index + 1]; + buffer_p[item_index + 1] = tmp; + + item_index = highest_index; + } +} /* ecma_module_heap_sort_shift_down */ + +/** + * Creates a namespace object for a module. + * Note: See 15.2.1.18 + * + * @return ECMA_VALUE_ERROR - if an error occurred + * ECMA_VALUE_EMPTY - otherwise + */ +static ecma_value_t +ecma_module_create_namespace_object (ecma_module_t *module_p) /**< module */ +{ + JERRY_ASSERT (module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKING); + JERRY_ASSERT (module_p->namespace_object_p != NULL); + JERRY_ASSERT (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_HAS_NAMESPACE)); + + ecma_module_resolve_set_t *resolve_set_p; + resolve_set_p = ecma_module_resolve_set_create (module_p, ecma_get_magic_string (LIT_MAGIC_STRING_ASTERISK_CHAR)); + + /* The properties collection stores name / result item pairs. Name is always + * a string, and result can be a property reference or namespace object. */ + ecma_module_resolve_set_t *current_set_p = resolve_set_p; + ecma_collection_t *properties_p = ecma_new_collection (); + ecma_value_t result = ECMA_VALUE_EMPTY; + bool allow_default = true; + + ecma_value_t *buffer_p; + uint32_t item_count; + ecma_value_t *buffer_end_p; + + do + { + ecma_module_t *current_module_p = current_set_p->module_p; + + if (current_module_p->header.u.cls.u2.module_flags & ECMA_MODULE_HAS_NAMESPACE) + { + JERRY_ASSERT (!allow_default); + + jmem_cpointer_t prop_iter_cp = current_module_p->namespace_object_p->u1.property_list_cp; + +#if JERRY_PROPERTY_HASHMAP + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prop_iter_cp = prop_iter_p->next_property_cp; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (!ECMA_PROPERTY_IS_RAW (prop_iter_p->types[i])) + { + continue; + } + + ecma_string_t *name_p = ecma_string_from_property_name (prop_iter_p->types[i], prop_pair_p->names_cp[i]); + result = ecma_module_namespace_object_add_export_if_needed (properties_p, module_p, name_p, false); + ecma_deref_ecma_string (name_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto exit; + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } + } + else + { + ecma_module_names_t *export_names_p = current_module_p->local_exports_p; + + if (export_names_p != NULL) + { + do + { + result = ecma_module_namespace_object_add_export_if_needed (properties_p, + module_p, + export_names_p->imex_name_p, + allow_default); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto exit; + } + + export_names_p = export_names_p->next_p; + } while (export_names_p != NULL); + } + + ecma_module_node_t *indirect_export_p = current_module_p->indirect_exports_p; + + while (indirect_export_p != NULL) + { + export_names_p = indirect_export_p->module_names_p; + + while (export_names_p != NULL) + { + result = ecma_module_namespace_object_add_export_if_needed (properties_p, + module_p, + export_names_p->imex_name_p, + allow_default); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto exit; + } + + export_names_p = export_names_p->next_p; + } + + indirect_export_p = indirect_export_p->next_p; + } + } + + allow_default = false; + + ecma_module_node_t *star_export_p = current_module_p->star_exports_p; + + while (star_export_p != NULL) + { + JERRY_ASSERT (star_export_p->module_names_p == NULL); + + /* Circular imports are ignored */ + ecma_module_resolve_set_append (resolve_set_p, + ecma_module_get_from_object (*star_export_p->u.module_object_p), + ecma_get_magic_string (LIT_MAGIC_STRING_ASTERISK_CHAR)); + + star_export_p = star_export_p->next_p; + } + + current_set_p = current_set_p->next_p; + } while (current_set_p != NULL); + + buffer_p = properties_p->buffer_p; + item_count = properties_p->item_count; + buffer_end_p = properties_p->buffer_p + item_count; + + if (item_count >= 4) + { + /* Sort items with heapsort if at least two items are stored in the buffer. */ + uint32_t end = (item_count >> 1) & ~(uint32_t) 0x1; + + do + { + end -= 2; + ecma_module_heap_sort_shift_down (buffer_p, item_count, end); + } while (end > 0); + + end = item_count - 2; + + do + { + ecma_value_t tmp = buffer_p[end]; + buffer_p[end] = buffer_p[0]; + buffer_p[0] = tmp; + + tmp = buffer_p[end + 1]; + buffer_p[end + 1] = buffer_p[1]; + buffer_p[1] = tmp; + + ecma_module_heap_sort_shift_down (buffer_p, end, 0); + end -= 2; + } while (end > 0); + } + + buffer_end_p = properties_p->buffer_p + item_count; + + while (buffer_p < buffer_end_p) + { + if (buffer_p[1] & ECMA_MODULE_NAMESPACE_RESULT_FLAG) + { + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (module_p->namespace_object_p, + ecma_get_string_from_value (buffer_p[0]), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE, + NULL); + property_value_p->value = buffer_p[1]; + } + else + { + ecma_create_named_reference_property (module_p->namespace_object_p, + ecma_get_string_from_value (buffer_p[0]), + buffer_p[1]); + } + + buffer_p += 2; + } + + module_p->header.u.cls.u2.module_flags |= ECMA_MODULE_HAS_NAMESPACE; + + ecma_module_release_module_names (module_p->local_exports_p); + module_p->local_exports_p = NULL; + + ecma_module_release_module_nodes (module_p->indirect_exports_p, false); + module_p->indirect_exports_p = NULL; + +exit: + /* Clean up. */ + ecma_module_resolve_set_cleanup (resolve_set_p); + ecma_collection_destroy (properties_p); + return result; +} /* ecma_module_create_namespace_object */ + +/** + * Connects imported values to the current module scope. + * + * @return ECMA_VALUE_ERROR - if an error occurred + * ECMA_VALUE_EMPTY - otherwise + */ +static ecma_value_t +ecma_module_connect_imports (ecma_module_t *module_p) +{ + ecma_object_t *local_env_p = module_p->scope_p; + JERRY_ASSERT (ecma_is_lexical_environment (local_env_p)); + + ecma_module_node_t *import_node_p = module_p->imports_p; + + /* Check that the imported bindings don't exist yet. */ + while (import_node_p != NULL) + { + ecma_module_names_t *import_names_p = import_node_p->module_names_p; + + JERRY_ASSERT (local_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK); + + while (import_names_p != NULL) + { + ecma_property_t *binding_p = ecma_find_named_property (local_env_p, import_names_p->local_name_p); + + if (binding_p != NULL) + { + return ecma_raise_syntax_error (ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE); + } + + import_names_p = import_names_p->next_p; + } + + import_node_p = import_node_p->next_p; + } + + import_node_p = module_p->imports_p; + + /* Resolve imports and create local bindings. */ + while (import_node_p != NULL) + { + ecma_module_names_t *import_names_p = import_node_p->module_names_p; + ecma_module_t *imported_module_p = ecma_module_get_from_object (import_node_p->u.path_or_module); + + while (import_names_p != NULL) + { + if (ecma_compare_ecma_string_to_magic_id (import_names_p->imex_name_p, LIT_MAGIC_STRING_ASTERISK_CHAR)) + { + /* Namespace import. */ + ecma_property_value_t *value_p; + value_p = + ecma_create_named_data_property (module_p->scope_p, import_names_p->local_name_p, ECMA_PROPERTY_FIXED, NULL); + value_p->value = ecma_make_object_value (imported_module_p->namespace_object_p); + } + else + { + ecma_module_resolve_result_t resolve_result; + ecma_module_resolve_export (imported_module_p, import_names_p->imex_name_p, &resolve_result); + + if (resolve_result.result_type != ECMA_MODULE_RESOLVE_FOUND) + { + return ecma_module_resolve_throw (&resolve_result, import_names_p->imex_name_p); + } + + if (resolve_result.result & ECMA_MODULE_NAMESPACE_RESULT_FLAG) + { + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (module_p->scope_p, + import_names_p->local_name_p, + ECMA_PROPERTY_FIXED, + NULL); + property_value_p->value = resolve_result.result; + } + else + { + ecma_create_named_reference_property (module_p->scope_p, import_names_p->local_name_p, resolve_result.result); + } + } + + import_names_p = import_names_p->next_p; + } + + ecma_module_release_module_names (import_node_p->module_names_p); + import_node_p->module_names_p = NULL; + + import_node_p = import_node_p->next_p; + } + + return ECMA_VALUE_EMPTY; +} /* ecma_module_connect_imports */ + +/** + * Initialize the current module by creating the local binding for the imported variables + * and verifying indirect exports. + * + * @return ECMA_VALUE_ERROR - if an error occurred + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +ecma_module_initialize (ecma_module_t *module_p) /**< module */ +{ + ecma_module_node_t *import_node_p = module_p->imports_p; + + while (import_node_p != NULL) + { + /* Module is evaluated even if it is used only in export-from statements. */ + ecma_value_t result = ecma_module_evaluate (ecma_module_get_from_object (import_node_p->u.path_or_module)); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ecma_free_value (result); + + import_node_p = import_node_p->next_p; + } + + return ECMA_VALUE_EMPTY; +} /* ecma_module_initialize */ + +/** + * Gets the internal module pointer of a module + * + * @return module pointer - if module_val is a valid module, + * NULL - otherwise + */ +ecma_module_t * +ecma_module_get_resolved_module (ecma_value_t module_val) /**< module */ +{ + if (!ecma_is_value_object (module_val)) + { + return NULL; + } + + ecma_object_t *object_p = ecma_get_object_from_value (module_val); + + if (!ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_MODULE)) + { + return NULL; + } + + return (ecma_module_t *) object_p; +} /* ecma_module_get_resolved_module */ + +/** + * A module stack for depth-first search + */ +typedef struct ecma_module_stack_item_t +{ + struct ecma_module_stack_item_t *prev_p; /**< prev in the stack */ + struct ecma_module_stack_item_t *parent_p; /**< parent item in the stack */ + ecma_module_t *module_p; /**< currently processed module */ + ecma_module_node_t *node_p; /**< currently processed node */ + uint32_t dfs_index; /**< dfs index (ES2020 15.2.1.16) */ +} ecma_module_stack_item_t; + +/** + * Link module dependencies + * + * @return ECMA_VALUE_ERROR - if an error occurred + * ECMA_VALUE_UNDEFINED - otherwise + */ +ecma_value_t +ecma_module_link (ecma_module_t *module_p, /**< root module */ + jerry_module_resolve_cb_t callback, /**< resolve module callback */ + void *user_p) /**< pointer passed to the resolve callback */ +{ + if (module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_UNLINKED) + { + return ecma_raise_type_error (ECMA_ERR_MODULE_MUST_BE_IN_UNLINKED_STATE); + } + + module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_LINKING; + + uint32_t dfs_index = 0; + ecma_module_stack_item_t *last_p; + ecma_module_node_t *node_p; + + last_p = (ecma_module_stack_item_t *) jmem_heap_alloc_block (sizeof (ecma_module_stack_item_t)); + last_p->prev_p = NULL; + last_p->parent_p = NULL; + last_p->module_p = module_p; + last_p->node_p = module_p->imports_p; + last_p->dfs_index = dfs_index; + + module_p->header.u.cls.u3.dfs_ancestor_index = dfs_index; + + ecma_value_t module_val = ecma_make_object_value (&module_p->header.object); + ecma_module_stack_item_t *current_p = last_p; + +restart: + /* Entering into processing new node phase. Resolve dependencies first. */ + node_p = current_p->node_p; + + JERRY_ASSERT (ecma_module_get_from_object (module_val)->imports_p == node_p); + + while (node_p != NULL) + { + ecma_module_t *resolved_module_p; + + if (!ecma_is_value_object (node_p->u.path_or_module)) + { + JERRY_ASSERT (ecma_is_value_string (node_p->u.path_or_module)); + + ecma_value_t resolve_result = callback (node_p->u.path_or_module, module_val, user_p); + + if (JERRY_UNLIKELY (ecma_is_value_exception (resolve_result))) + { + ecma_throw_exception (resolve_result); + goto error; + } + + resolved_module_p = ecma_module_get_resolved_module (resolve_result); + + if (resolved_module_p == NULL) + { + ecma_free_value (resolve_result); + ecma_raise_type_error (ECMA_ERR_CALLBACK_RESULT_NOT_MODULE); + goto error; + } + + ecma_deref_ecma_string (ecma_get_string_from_value (node_p->u.path_or_module)); + node_p->u.path_or_module = resolve_result; + ecma_deref_object (ecma_get_object_from_value (resolve_result)); + } + else + { + resolved_module_p = ecma_module_get_from_object (node_p->u.path_or_module); + } + + if (resolved_module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_ERROR) + { + ecma_raise_type_error (ECMA_ERR_LINK_TO_MODULE_IN_ERROR_STATE); + goto error; + } + + node_p = node_p->next_p; + } + + /* Find next unlinked node, or return to parent */ + while (true) + { + ecma_module_t *current_module_p = current_p->module_p; + node_p = current_p->node_p; + + while (node_p != NULL) + { + module_p = ecma_module_get_from_object (node_p->u.path_or_module); + + if (module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_UNLINKED) + { + current_p->node_p = node_p->next_p; + module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_LINKING; + + ecma_module_stack_item_t *item_p; + item_p = (ecma_module_stack_item_t *) jmem_heap_alloc_block (sizeof (ecma_module_stack_item_t)); + + dfs_index++; + + item_p->prev_p = last_p; + item_p->parent_p = current_p; + item_p->module_p = module_p; + item_p->node_p = module_p->imports_p; + item_p->dfs_index = dfs_index; + + module_p->header.u.cls.u3.dfs_ancestor_index = dfs_index; + + last_p = item_p; + current_p = item_p; + module_val = node_p->u.path_or_module; + goto restart; + } + + if (module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKING) + { + uint32_t dfs_ancestor_index = module_p->header.u.cls.u3.dfs_ancestor_index; + + if (dfs_ancestor_index < current_module_p->header.u.cls.u3.dfs_ancestor_index) + { + current_module_p->header.u.cls.u3.dfs_ancestor_index = dfs_ancestor_index; + } + } + + node_p = node_p->next_p; + } + + if (current_module_p->scope_p == NULL) + { + JERRY_ASSERT (!(current_module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE)); + + /* Initialize scope for handling circular references. */ + ecma_value_t result = vm_init_module_scope (current_module_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_module_set_error_state (current_module_p); + goto error; + } + + JERRY_ASSERT (result == ECMA_VALUE_EMPTY); + } + + if (current_module_p->namespace_object_p == NULL) + { + ecma_object_t *namespace_object_p = + ecma_create_object (NULL, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + namespace_object_p->type_flags_refs &= (ecma_object_descriptor_t) ~ECMA_OBJECT_FLAG_EXTENSIBLE; + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) namespace_object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_MODULE_NAMESPACE; + ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.cls.u3.value, module_p); + + current_module_p->namespace_object_p = namespace_object_p; + ecma_deref_object (namespace_object_p); + } + + if (current_module_p->header.u.cls.u3.dfs_ancestor_index != current_p->dfs_index) + { + current_p = current_p->parent_p; + JERRY_ASSERT (current_p != NULL); + + uint32_t dfs_ancestor_index = current_module_p->header.u.cls.u3.dfs_ancestor_index; + + if (dfs_ancestor_index < current_p->module_p->header.u.cls.u3.dfs_ancestor_index) + { + current_p->module_p->header.u.cls.u3.dfs_ancestor_index = dfs_ancestor_index; + } + continue; + } + + ecma_module_stack_item_t *end_p = current_p->prev_p; + current_p = current_p->parent_p; + + ecma_module_stack_item_t *iterator_p = last_p; + + do + { + JERRY_ASSERT (iterator_p->module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKING); + + if (ECMA_IS_VALUE_ERROR (ecma_module_create_namespace_object (iterator_p->module_p))) + { + ecma_module_set_error_state (iterator_p->module_p); + goto error; + } + + iterator_p = iterator_p->prev_p; + } while (iterator_p != end_p); + + iterator_p = last_p; + + do + { + JERRY_ASSERT (iterator_p->module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKING); + + if (ECMA_IS_VALUE_ERROR (ecma_module_connect_imports (iterator_p->module_p))) + { + ecma_module_set_error_state (iterator_p->module_p); + goto error; + } + + iterator_p = iterator_p->prev_p; + } while (iterator_p != end_p); + + do + { + ecma_module_stack_item_t *prev_p = last_p->prev_p; + + JERRY_ASSERT (last_p->module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKING); + last_p->module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_LINKED; + + if (JERRY_CONTEXT (module_state_changed_callback_p) != NULL) + { + JERRY_CONTEXT (module_state_changed_callback_p) + (JERRY_MODULE_STATE_LINKED, + ecma_make_object_value (&last_p->module_p->header.object), + ECMA_VALUE_UNDEFINED, + JERRY_CONTEXT (module_state_changed_callback_user_p)); + } + + jmem_heap_free_block (last_p, sizeof (ecma_module_stack_item_t)); + last_p = prev_p; + } while (last_p != end_p); + + if (current_p == NULL) + { + return ECMA_VALUE_TRUE; + } + } + +error: + JERRY_ASSERT (last_p != NULL); + + do + { + ecma_module_stack_item_t *prev_p = last_p->prev_p; + + if (last_p->module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_ERROR) + { + JERRY_ASSERT (last_p->module_p->header.u.cls.u1.module_state == JERRY_MODULE_STATE_LINKING); + last_p->module_p->header.u.cls.u1.module_state = JERRY_MODULE_STATE_UNLINKED; + } + + jmem_heap_free_block (last_p, sizeof (ecma_module_stack_item_t)); + last_p = prev_p; + } while (last_p != NULL); + + return ECMA_VALUE_ERROR; +} /* ecma_module_link */ + +/** + * Compute the result of 'import()' calls + * + * @return promise object representing the result of the operation + */ +ecma_value_t +ecma_module_import (ecma_value_t specifier, /**< module specifier */ + ecma_value_t user_value) /**< user value assigned to the script */ +{ + ecma_string_t *specifier_p = ecma_op_to_string (specifier); + ecma_module_t *module_p; + + if (JERRY_UNLIKELY (specifier_p == NULL)) + { + goto error; + } + + if (JERRY_CONTEXT (module_import_callback_p) == NULL) + { + ecma_deref_ecma_string (specifier_p); + goto error_module_instantiate; + } + + jerry_value_t result; + result = JERRY_CONTEXT (module_import_callback_p) (ecma_make_string_value (specifier_p), + user_value, + JERRY_CONTEXT (module_import_callback_user_p)); + ecma_deref_ecma_string (specifier_p); + + if (JERRY_UNLIKELY (ecma_is_value_exception (result))) + { + ecma_throw_exception (result); + goto error; + } + + if (ecma_is_value_object (result) && ecma_is_promise (ecma_get_object_from_value (result))) + { + return result; + } + + module_p = ecma_module_get_resolved_module (result); + + if (module_p == NULL) + { + ecma_free_value (result); + goto error_module_instantiate; + } + + if (module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_EVALUATED) + { + ecma_deref_object (&module_p->header.object); + goto error_module_instantiate; + } + + result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL); + ecma_fulfill_promise (result, ecma_make_object_value (module_p->namespace_object_p)); + ecma_deref_object (&module_p->header.object); + return result; + +error_module_instantiate: + ecma_raise_range_error (ECMA_ERR_MODULE_CANNOT_BE_INSTANTIATED); + +error: + if (jcontext_has_pending_abort ()) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t exception = jcontext_take_exception (); + + ecma_value_t promise = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL); + ecma_reject_promise (promise, exception); + ecma_free_value (exception); + return promise; +} /* ecma_module_import */ + +/** + * Cleans up and releases a module structure including all referenced modules. + */ +void +ecma_module_release_module (ecma_module_t *module_p) /**< module */ +{ + jerry_module_state_t state = (jerry_module_state_t) module_p->header.u.cls.u1.module_state; + + JERRY_ASSERT (state != JERRY_MODULE_STATE_INVALID); + +#ifndef JERRY_NDEBUG + module_p->scope_p = NULL; + module_p->namespace_object_p = NULL; +#endif /* JERRY_NDEBUG */ + + ecma_module_release_module_names (module_p->local_exports_p); + + if (module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) + { + return; + } + + ecma_module_release_module_nodes (module_p->imports_p, true); + ecma_module_release_module_nodes (module_p->indirect_exports_p, false); + ecma_module_release_module_nodes (module_p->star_exports_p, false); + + if (module_p->u.compiled_code_p != NULL) + { + ecma_bytecode_deref (module_p->u.compiled_code_p); +#ifndef JERRY_NDEBUG + module_p->u.compiled_code_p = NULL; +#endif /* JERRY_NDEBUG */ + } +} /* ecma_module_release_module */ + +#endif /* JERRY_MODULE_SYSTEM */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-module.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-module.h new file mode 100644 index 0000000..7b90697 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-module.h @@ -0,0 +1,132 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_MODULE_H +#define ECMA_MODULE_H + +#include "ecma-globals.h" + +#include "common.h" + +#if JERRY_MODULE_SYSTEM + +#define ECMA_MODULE_MAX_PATH 255u + +/** + * Module status flags. + */ +typedef enum +{ + ECMA_MODULE_IS_NATIVE = (1 << 0), /**< native module */ + ECMA_MODULE_HAS_NAMESPACE = (1 << 1), /**< namespace object has been initialized */ +} ecma_module_flags_t; + +/** + * Imported or exported names, such as "a as b" + * Note: See https://www.ecma-international.org/ecma-262/6.0/#table-39 + * and https://www.ecma-international.org/ecma-262/6.0/#table-41 + */ +typedef struct ecma_module_names +{ + struct ecma_module_names *next_p; /**< next linked list node */ + ecma_string_t *imex_name_p; /**< Import/export name of the item */ + ecma_string_t *local_name_p; /**< Local name of the item */ +} ecma_module_names_t; + +/** + * Module structure storing an instance of a module + * + * Note: + * The imports_p list follows the order of import-from/export-from statements in the source + * code of a module, even if a given module specifier is only used by export-from statements. + */ +typedef struct ecma_module +{ + /* Note: state is stored in header.u.class_prop.extra_info */ + ecma_extended_object_t header; /**< header part */ + /* TODO(dbatyai): These could be compressed pointers */ + ecma_object_t *scope_p; /**< lexical environment of the module */ + ecma_object_t *namespace_object_p; /**< namespace object of the module */ + struct ecma_module_node *imports_p; /**< import requests of the module */ + ecma_module_names_t *local_exports_p; /**< local exports of the module */ + struct ecma_module_node *indirect_exports_p; /**< indirect exports of the module */ + struct ecma_module_node *star_exports_p; /**< star exports of the module */ + + /* Code used for evaluating a module */ + union + { + ecma_compiled_code_t *compiled_code_p; /**< compiled code for the module */ + jerry_native_module_evaluate_cb_t callback; /**< callback for evaluating native modules */ + } u; +} ecma_module_t; + +/** + * Module node to store imports / exports. + * + * Note: + * Only one module node is created for each module specifier: the names are + * concatenated if the same specifier is used multiple times in the source code. + * However, multiple nodes are created for modules with multiple alias + * (for example ./a.mjs and ././a.mjs can refer to the same module). + */ +typedef struct ecma_module_node +{ + struct ecma_module_node *next_p; /**< next linked list node */ + ecma_module_names_t *module_names_p; /**< names of the requested import/export node */ + + union + { + ecma_value_t path_or_module; /**< imports: module specifier (if string) or module reference (if object) */ + ecma_value_t *module_object_p; /**< non-imports: reference to a path_or_module field in the imports */ + } u; +} ecma_module_node_t; + +/** + * A list of module records that can be used to identify circular imports during resolution + */ +typedef struct ecma_module_resolve_set +{ + struct ecma_module_resolve_set *next_p; /**< next in linked list */ + ecma_module_t *module_p; /**< module */ + ecma_string_t *name_p; /**< identifier name */ +} ecma_module_resolve_set_t; + +/** + * A list that is used like a stack to drive the resolution process, instead of recursion. + */ +typedef struct ecma_module_resolve_stack +{ + struct ecma_module_resolve_stack *next_p; /**< next in linked list */ + ecma_module_t *module_p; /**< module request */ + ecma_string_t *export_name_p; /**< export identifier name */ + bool resolving; /**< flag storing whether the current frame started resolving */ +} ecma_module_resolve_stack_t; + +ecma_value_t ecma_module_initialize (ecma_module_t *module_p); +ecma_module_t *ecma_module_get_resolved_module (ecma_value_t module_val); + +ecma_value_t ecma_module_link (ecma_module_t *module_p, jerry_module_resolve_cb_t callback_p, void *user_p); +ecma_value_t ecma_module_evaluate (ecma_module_t *module_p); +ecma_value_t ecma_module_import (ecma_value_t specifier, ecma_value_t user_value); + +ecma_module_t *ecma_module_create (void); +void ecma_module_cleanup_context (void); + +void ecma_module_release_module_names (ecma_module_names_t *module_name_p); +void ecma_module_release_module (ecma_module_t *module_p); + +#endif /* JERRY_MODULE_SYSTEM */ + +#endif /* !ECMA_MODULE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-property-hashmap.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-property-hashmap.cpp new file mode 100644 index 0000000..ebfc1d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-property-hashmap.cpp @@ -0,0 +1,532 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-property-hashmap.h" + +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "jcontext.h" +#include "jrt-libc-includes.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmapropertyhashmap Property hashmap + * @{ + */ + +#if JERRY_PROPERTY_HASHMAP + +/** + * Compute the total size of the property hashmap. + */ +#define ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE(max_property_count) \ + (sizeof (ecma_property_hashmap_t) + (max_property_count * sizeof (jmem_cpointer_t)) + (max_property_count >> 3)) + +/** + * Number of items in the stepping table. + */ +#define ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS 8 + +/** + * Stepping values for searching items in the hashmap. + */ +static const uint8_t ecma_property_hashmap_steps[ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS] JERRY_ATTR_CONST_DATA = { + 3, 5, 7, 11, 13, 17, 19, 23 +}; + +/** + * Get the value of a bit in a bitmap. + */ +#define ECMA_PROPERTY_HASHMAP_GET_BIT(byte_p, index) ((byte_p)[(index) >> 3] & (1 << ((index) &0x7))) + +/** + * Clear the value of a bit in a bitmap. + */ +#define ECMA_PROPERTY_HASHMAP_CLEAR_BIT(byte_p, index) \ + ((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] & ~(1 << ((index) &0x7)))) + +/** + * Set the value of a bit in a bitmap. + */ +#define ECMA_PROPERTY_HASHMAP_SET_BIT(byte_p, index) \ + ((byte_p)[(index) >> 3] = (uint8_t) ((byte_p)[(index) >> 3] | (1 << ((index) &0x7)))) + +/** + * Create a new property hashmap for the object. + * The object must not have a property hashmap. + */ +void +ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */ +{ + if (JERRY_CONTEXT (ecma_prop_hashmap_alloc_state) != ECMA_PROP_HASHMAP_ALLOC_ON) + { + return; + } + + jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp; + + if (prop_iter_cp == JMEM_CP_NULL) + { + return; + } + + uint32_t named_property_count = 0; + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i])); + named_property_count++; + } + } + prop_iter_cp = prop_iter_p->next_property_cp; + } + + if (named_property_count < (ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE / 2)) + { + return; + } + + /* The max_property_count must be power of 2. */ + uint32_t max_property_count = ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE; + + /* At least 1/3 items must be NULL. */ + while (max_property_count < (named_property_count + (named_property_count >> 1))) + { + max_property_count <<= 1; + } + + size_t total_size = ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (max_property_count); + + ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) jmem_heap_alloc_block_null_on_error (total_size); + + if (hashmap_p == NULL) + { + return; + } + + memset (hashmap_p, 0, total_size); + + hashmap_p->header.types[0] = ECMA_PROPERTY_TYPE_HASHMAP; + hashmap_p->header.next_property_cp = object_p->u1.property_list_cp; + hashmap_p->max_property_count = max_property_count; + hashmap_p->null_count = max_property_count - named_property_count; + hashmap_p->unused_count = max_property_count - named_property_count; + + jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1); + uint8_t *bits_p = (uint8_t *) (pair_list_p + max_property_count); + uint32_t mask = max_property_count - 1; + + prop_iter_cp = object_p->u1.property_list_cp; + ECMA_SET_NON_NULL_POINTER (object_p->u1.property_list_cp, hashmap_p); + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (prop_iter_p->types[i] == ECMA_PROPERTY_TYPE_DELETED) + { + continue; + } + + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i])); + + ecma_property_pair_t *property_pair_p = (ecma_property_pair_t *) prop_iter_p; + + uint32_t entry_index = ecma_string_get_property_name_hash (prop_iter_p->types[i], property_pair_p->names_cp[i]); + uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)]; + + entry_index &= mask; +#ifndef JERRY_NDEBUG + /* Because max_property_count (power of 2) and step (a prime + * number) are relative primes, all entries of the hashmap are + * visited exactly once before the start entry index is reached + * again. Furthermore because at least one NULL is present in + * the hashmap, the while loop must be terminated before the + * the starting index is reached again. */ + uint32_t start_entry_index = entry_index; +#endif /* !JERRY_NDEBUG */ + + while (pair_list_p[entry_index] != ECMA_NULL_POINTER) + { + entry_index = (entry_index + step) & mask; + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (entry_index != start_entry_index); +#endif /* !JERRY_NDEBUG */ + } + + ECMA_SET_NON_NULL_POINTER (pair_list_p[entry_index], property_pair_p); + + if (i != 0) + { + ECMA_PROPERTY_HASHMAP_SET_BIT (bits_p, entry_index); + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } +} /* ecma_property_hashmap_create */ + +/** + * Free the hashmap of the object. + * The object must have a property hashmap. + */ +void +ecma_property_hashmap_free (ecma_object_t *object_p) /**< object */ +{ + /* Property hash must be exists and must be the first property. */ + JERRY_ASSERT (object_p->u1.property_list_cp != JMEM_CP_NULL); + + ecma_property_header_t *property_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, object_p->u1.property_list_cp); + + JERRY_ASSERT (property_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP); + + ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) property_p; + + object_p->u1.property_list_cp = property_p->next_property_cp; + + jmem_heap_free_block (hashmap_p, ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (hashmap_p->max_property_count)); +} /* ecma_property_hashmap_free */ + +/** + * Insert named property into the hashmap. + */ +void +ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */ + ecma_string_t *name_p, /**< name of the property */ + ecma_property_pair_t *property_pair_p, /**< property pair */ + int property_index) /**< property index in the pair (0 or 1) */ +{ + JERRY_ASSERT (property_pair_p != NULL); + + ecma_property_hashmap_t *hashmap_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t, object_p->u1.property_list_cp); + + JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP); + + /* The NULLs are reduced below 1/8 of the hashmap. */ + if (hashmap_p->null_count < (hashmap_p->max_property_count >> 3)) + { + ecma_property_hashmap_free (object_p); + ecma_property_hashmap_create (object_p); + return; + } + + JERRY_ASSERT (property_index < ECMA_PROPERTY_PAIR_ITEM_COUNT); + + uint32_t entry_index = ecma_string_hash (name_p); + uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)]; + uint32_t mask = hashmap_p->max_property_count - 1; + entry_index &= mask; + +#ifndef JERRY_NDEBUG + /* See the comment for this variable in ecma_property_hashmap_create. */ + uint32_t start_entry_index = entry_index; +#endif /* !JERRY_NDEBUG */ + + jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1); + + while (pair_list_p[entry_index] != ECMA_NULL_POINTER) + { + entry_index = (entry_index + step) & mask; + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (entry_index != start_entry_index); +#endif /* !JERRY_NDEBUG */ + } + + ECMA_SET_NON_NULL_POINTER (pair_list_p[entry_index], property_pair_p); + + uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count); + bits_p += (entry_index >> 3); + mask = (uint32_t) (1 << (entry_index & 0x7)); + + if (!(*bits_p & mask)) + { + /* Deleted entries also has ECMA_NULL_POINTER + * value, but they are not NULL values. */ + hashmap_p->null_count--; + JERRY_ASSERT (hashmap_p->null_count > 0); + } + + hashmap_p->unused_count--; + JERRY_ASSERT (hashmap_p->unused_count > 0); + + if (property_index == 0) + { + *bits_p = (uint8_t) ((*bits_p) & ~mask); + } + else + { + *bits_p = (uint8_t) ((*bits_p) | mask); + } +} /* ecma_property_hashmap_insert */ + +/** + * Delete named property from the hashmap. + * + * @return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP if hashmap should be recreated + * ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP otherwise + */ +ecma_property_hashmap_delete_status +ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */ + jmem_cpointer_t name_cp, /**< property name */ + ecma_property_t *property_p) /**< property */ +{ + ecma_property_hashmap_t *hashmap_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_hashmap_t, object_p->u1.property_list_cp); + + JERRY_ASSERT (hashmap_p->header.types[0] == ECMA_PROPERTY_TYPE_HASHMAP); + + hashmap_p->unused_count++; + + /* The NULLs are above 3/4 of the hashmap. */ + if (hashmap_p->unused_count > ((hashmap_p->max_property_count * 3) >> 2)) + { + return ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP; + } + + uint32_t entry_index = ecma_string_get_property_name_hash (*property_p, name_cp); + uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)]; + uint32_t mask = hashmap_p->max_property_count - 1; + jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1); + uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count); + + entry_index &= mask; + +#ifndef JERRY_NDEBUG + /* See the comment for this variable in ecma_property_hashmap_create. */ + uint32_t start_entry_index = entry_index; +#endif /* !JERRY_NDEBUG */ + + while (true) + { + if (pair_list_p[entry_index] != ECMA_NULL_POINTER) + { + size_t offset = 0; + + if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index)) + { + offset = 1; + } + + ecma_property_pair_t *property_pair_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t, pair_list_p[entry_index]); + + if ((property_pair_p->header.types + offset) == property_p) + { + JERRY_ASSERT (property_pair_p->names_cp[offset] == name_cp); + + pair_list_p[entry_index] = ECMA_NULL_POINTER; + ECMA_PROPERTY_HASHMAP_SET_BIT (bits_p, entry_index); + return ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP; + } + } + else + { + /* Must be a deleted entry. */ + JERRY_ASSERT (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index)); + } + + entry_index = (entry_index + step) & mask; + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (entry_index != start_entry_index); +#endif /* !JERRY_NDEBUG */ + } +} /* ecma_property_hashmap_delete */ + +/** + * Find a named property. + * + * @return pointer to the property if found or NULL otherwise + */ +ecma_property_t * +ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */ + ecma_string_t *name_p, /**< property name */ + jmem_cpointer_t *property_real_name_cp) /**< [out] property real name */ +{ +#ifndef JERRY_NDEBUG + /* A sanity check in debug mode: a named property must be present + * in both the property hashmap and in the property chain, or missing + * from both data collection. The following code checks the property + * chain, and sets the property_found variable. */ + bool property_found = false; + + jmem_cpointer_t prop_iter_cp = hashmap_p->header.next_property_cp; + + while (prop_iter_cp != JMEM_CP_NULL && !property_found) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i])) + { + if (ecma_string_compare_to_property_name (prop_iter_p->types[i], prop_pair_p->names_cp[i], name_p)) + { + /* Property is found */ + property_found = true; + break; + } + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } +#endif /* !JERRY_NDEBUG */ + + uint32_t entry_index = ecma_string_hash (name_p); + uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)]; + uint32_t mask = hashmap_p->max_property_count - 1; + jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1); + uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count); + entry_index &= mask; + +#ifndef JERRY_NDEBUG + /* See the comment for this variable in ecma_property_hashmap_create. */ + uint32_t start_entry_index = entry_index; +#endif /* !JERRY_NDEBUG */ + + if (ECMA_IS_DIRECT_STRING (name_p)) + { + ecma_property_t prop_name_type = (ecma_property_t) ECMA_GET_DIRECT_STRING_TYPE (name_p); + jmem_cpointer_t property_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (name_p); + + JERRY_ASSERT (prop_name_type > 0); + + while (true) + { + if (pair_list_p[entry_index] != ECMA_NULL_POINTER) + { + size_t offset = 0; + if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index)) + { + offset = 1; + } + + ecma_property_pair_t *property_pair_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t, pair_list_p[entry_index]); + + ecma_property_t *property_p = property_pair_p->header.types + offset; + + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p)); + + if (property_pair_p->names_cp[offset] == property_name_cp + && ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == prop_name_type) + { +#ifndef JERRY_NDEBUG + JERRY_ASSERT (property_found); +#endif /* !JERRY_NDEBUG */ + + *property_real_name_cp = property_name_cp; + return property_p; + } + } + else + { + if (!ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index)) + { +#ifndef JERRY_NDEBUG + JERRY_ASSERT (!property_found); +#endif /* !JERRY_NDEBUG */ + + return NULL; + } + /* Otherwise it is a deleted entry. */ + } + + entry_index = (entry_index + step) & mask; + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (entry_index != start_entry_index); +#endif /* !JERRY_NDEBUG */ + } + } + + while (true) + { + if (pair_list_p[entry_index] != ECMA_NULL_POINTER) + { + size_t offset = 0; + if (ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index)) + { + offset = 1; + } + + ecma_property_pair_t *property_pair_p = + ECMA_GET_NON_NULL_POINTER (ecma_property_pair_t, pair_list_p[entry_index]); + + ecma_property_t *property_p = property_pair_p->header.types + offset; + + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (*property_p)); + + if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_PTR) + { + ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, property_pair_p->names_cp[offset]); + + if (ecma_compare_ecma_non_direct_strings (prop_name_p, name_p)) + { +#ifndef JERRY_NDEBUG + JERRY_ASSERT (property_found); +#endif /* !JERRY_NDEBUG */ + + *property_real_name_cp = property_pair_p->names_cp[offset]; + return property_p; + } + } + } + else + { + if (!ECMA_PROPERTY_HASHMAP_GET_BIT (bits_p, entry_index)) + { +#ifndef JERRY_NDEBUG + JERRY_ASSERT (!property_found); +#endif /* !JERRY_NDEBUG */ + + return NULL; + } + /* Otherwise it is a deleted entry. */ + } + + entry_index = (entry_index + step) & mask; + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (entry_index != start_entry_index); +#endif /* !JERRY_NDEBUG */ + } +} /* ecma_property_hashmap_find */ +#endif /* JERRY_PROPERTY_HASHMAP */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-property-hashmap.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-property-hashmap.h new file mode 100644 index 0000000..11f654b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/ecma-property-hashmap.h @@ -0,0 +1,89 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_PROPERTY_HASHMAP_H +#define ECMA_PROPERTY_HASHMAP_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmapropertyhashmap Property hashmap + * @{ + */ + +/** + * Recommended minimum number of items in a property cache. + */ +#define ECMA_PROPERTY_HASHMAP_MINIMUM_SIZE 32 + +/** + * Property hash. + */ +typedef struct +{ + ecma_property_header_t header; /**< header of the property */ + uint32_t max_property_count; /**< maximum property count (power of 2) */ + uint32_t null_count; /**< number of NULLs in the map */ + uint32_t unused_count; /**< number of unused entries in the map */ + + /* + * The hash is followed by max_property_count ecma_cpointer_t + * compressed pointers and (max_property_count + 7) / 8 bytes + * which stores a flag for each compressed pointer. + * + * If the compressed pointer is equal to ECMA_NULL_POINTER + * - flag is cleared if the entry is NULL + * - flag is set if the entry is deleted + * + * If the compressed pointer is not equal to ECMA_NULL_POINTER + * - flag is cleared if the first entry of a property pair is referenced + * - flag is set if the second entry of a property pair is referenced + */ +} ecma_property_hashmap_t; + +#if JERRY_PROPERTY_HASHMAP + +/** + * Simple ecma values + */ +typedef enum +{ + ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP, /**< object has no hashmap */ + ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP, /**< object has hashmap */ + ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP, /**< hashmap should be recreated */ +} ecma_property_hashmap_delete_status; + +void ecma_property_hashmap_create (ecma_object_t *object_p); +void ecma_property_hashmap_free (ecma_object_t *object_p); +void ecma_property_hashmap_insert (ecma_object_t *object_p, + ecma_string_t *name_p, + ecma_property_pair_t *property_pair_p, + int property_index); +ecma_property_hashmap_delete_status +ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p); + +ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, + ecma_string_t *name_p, + jmem_cpointer_t *property_real_name_cp); +#endif /* JERRY_PROPERTY_HASHMAP */ + +/** + * @} + * @} + */ + +#endif /* !ECMA_PROPERTY_HASHMAP_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/meson.build new file mode 100644 index 0000000..e9da86e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/base/meson.build @@ -0,0 +1,37 @@ +source_file = [ + 'ecma-alloc.h', + 'ecma-error-messages.inc.h', + 'ecma-errors.h', + 'ecma-extended-info.h', + 'ecma-gc.h', + 'ecma-globals.h', + 'ecma-helpers-number.h', + 'ecma-helpers.h', + 'ecma-init-finalize.h', + 'ecma-lcache.h', + 'ecma-literal-storage.h', + 'ecma-module.h', + 'ecma-property-hashmap.h', + 'ecma-alloc.cpp', + 'ecma-errors.cpp', + 'ecma-extended-info.cpp', + 'ecma-gc.cpp', + 'ecma-helpers-collection.cpp', + 'ecma-helpers-conversion.cpp', + 'ecma-helpers-errol.cpp', + 'ecma-helpers-external-pointers.cpp', + 'ecma-helpers-number.cpp', + 'ecma-helpers-string.cpp', + 'ecma-helpers-value.cpp', + 'ecma-helpers.cpp', + 'ecma-init-finalize.cpp', + 'ecma-lcache.cpp', + 'ecma-literal-storage.cpp', + 'ecma-module.cpp', + 'ecma-property-hashmap.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.cpp new file mode 100644 index 0000000..771fca8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.cpp @@ -0,0 +1,33 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-aggregateerror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID aggregate_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.inc.h new file mode 100644 index 0000000..515d1d7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.inc.h @@ -0,0 +1,31 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * AggregateError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror.cpp new file mode 100644 index 0000000..5c4511e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror.cpp @@ -0,0 +1,80 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-aggregateerror.inc.h" +#define BUILTIN_UNDERSCORED_ID aggregate_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup aggregateerror ECMA AggregateError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in AggregateError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_aggregate_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + ecma_value_t message_val = ECMA_VALUE_UNDEFINED; + ecma_value_t error_val = ECMA_VALUE_UNDEFINED; + + if (arguments_list_len > 0) + { + error_val = arguments_list_p[0]; + + if (arguments_list_len > 1) + { + message_val = arguments_list_p[1]; + } + } + + return ecma_new_aggregate_error (error_val, message_val); +} /* ecma_builtin_aggregate_error_dispatch_call */ + + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror.inc.h new file mode 100644 index 0000000..13fc6c5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-aggregateerror.inc.h @@ -0,0 +1,34 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * AggregateError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 2, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.cpp new file mode 100644 index 0000000..b8f0db5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.cpp @@ -0,0 +1,221 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-iterator-object.h" +#include "ecma-typedarray-object.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ARRAY_ITERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_ARRAY_ITERATOR_PROTOTYPE_OBJECT_NEXT, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID array_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %arrayiteratorprototype% ECMA %ArrayIteratorPrototype% object built-in + * @{ + */ + +/** + * The %ArrayIteratorPrototype% object's 'next' routine + * + * See also: + * ECMA-262 v6, 22.1.5.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +static ecma_value_t +ecma_builtin_array_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */ +{ + /* 1 - 2. */ + if (!ecma_is_value_object (this_val)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (this_val); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + /* 3. */ + if (!ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_ARRAY_ITERATOR)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR); + } + + ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value; + + /* 4 - 5 */ + if (ecma_is_value_empty (iterated_value)) + { + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + ecma_object_t *array_object_p = ecma_get_object_from_value (iterated_value); + + /* 8. */ + ecma_length_t length; + if (ecma_object_is_typedarray (array_object_p)) + { + /* a. */ + ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (array_object_p); + if (ecma_arraybuffer_is_detached (arraybuffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* b. */ + length = ecma_typedarray_get_length (array_object_p); + } + else + { + ecma_value_t len_value = ecma_op_object_get_length (array_object_p, &length); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + return len_value; + } + } + + ecma_length_t index = ext_obj_p->u.cls.u2.iterator_index; + + if (JERRY_UNLIKELY (index == ECMA_ITERATOR_INDEX_LIMIT)) + { + /* After the ECMA_ITERATOR_INDEX_LIMIT limit is reached the [[%Iterator%NextIndex]] + property is stored as an internal property */ + ecma_string_t *prop_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX); + ecma_value_t index_value = ecma_op_object_get (obj_p, prop_name_p); + + if (!ecma_is_value_undefined (index_value)) + { + index = (ecma_length_t) (ecma_get_number_from_value (index_value) + 1); + } + + ecma_op_object_put (obj_p, prop_name_p, ecma_make_length_value (index), true); + ecma_free_value (index_value); + } + else + { + /* 11. */ + ext_obj_p->u.cls.u2.iterator_index++; + } + + if (index >= length) + { + ext_obj_p->u.cls.u3.iterated_value = ECMA_VALUE_EMPTY; + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + /* 7. */ + uint8_t iterator_kind = ext_obj_p->u.cls.u1.iterator_kind; + + if (iterator_kind == ECMA_ITERATOR_KEYS) + { + /* 12. */ + return ecma_create_iter_result_object (ecma_make_length_value (index), ECMA_VALUE_FALSE); + } + + /* 14. */ + ecma_value_t get_value = ecma_op_object_get_by_index (array_object_p, index); + + /* 15. */ + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + ecma_value_t result; + + /* 16. */ + if (iterator_kind == ECMA_ITERATOR_VALUES) + { + result = ecma_create_iter_result_object (get_value, ECMA_VALUE_FALSE); + } + else + { + /* 17.a */ + JERRY_ASSERT (iterator_kind == ECMA_ITERATOR_ENTRIES); + + /* 17.b */ + ecma_value_t entry_array_value; + entry_array_value = ecma_create_array_from_iter_element (get_value, ecma_make_length_value (index)); + + result = ecma_create_iter_result_object (entry_array_value, ECMA_VALUE_FALSE); + ecma_free_value (entry_array_value); + } + + ecma_free_value (get_value); + + return result; +} /* ecma_builtin_array_iterator_prototype_object_next */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_array_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list_p, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_ARRAY_ITERATOR_PROTOTYPE_OBJECT_NEXT: + { + return ecma_builtin_array_iterator_prototype_object_next (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_array_iterator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.inc.h new file mode 100644 index 0000000..c74d68d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %ArrayIteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ARRAY_ITERATOR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_ARRAY_ITERATOR_PROTOTYPE_OBJECT_NEXT, 0, 0) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.cpp new file mode 100644 index 0000000..5f67573 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.cpp @@ -0,0 +1,24 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-prototype-unscopables.inc.h" +#define BUILTIN_UNDERSCORED_ID array_prototype_unscopables +#include "ecma-builtin-internal-routines-template.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.inc.h new file mode 100644 index 0000000..2cc4bc5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.inc.h @@ -0,0 +1,44 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Array.prototype[@@unscopables] built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +SIMPLE_VALUE (LIT_MAGIC_STRING_AT, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_COPY_WITHIN, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_ENTRIES, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_FILL, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_FIND, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_FIND_INDEX, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_FLAT, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_FLATMAP, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_INCLUDES, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_KEYS, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +SIMPLE_VALUE (LIT_MAGIC_STRING_VALUES, ECMA_VALUE_TRUE, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp new file mode 100644 index 0000000..334d61c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp @@ -0,0 +1,2973 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-comparison.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jcontext.h" +#include "jrt.h" +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_ARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ARRAY_PROTOTYPE_ROUTINE_START = 0, + /* Note: these 2 routine ids must be in this order */ + ECMA_ARRAY_PROTOTYPE_SORT, + ECMA_ARRAY_PROTOTYPE_CONCAT, + ECMA_ARRAY_PROTOTYPE_TO_LOCALE_STRING, + ECMA_ARRAY_PROTOTYPE_JOIN, + ECMA_ARRAY_PROTOTYPE_POP, + ECMA_ARRAY_PROTOTYPE_PUSH, + ECMA_ARRAY_PROTOTYPE_REVERSE, + ECMA_ARRAY_PROTOTYPE_SHIFT, + ECMA_ARRAY_PROTOTYPE_SLICE, + ECMA_ARRAY_PROTOTYPE_SPLICE, + ECMA_ARRAY_PROTOTYPE_UNSHIFT, + ECMA_ARRAY_PROTOTYPE_AT, + ECMA_ARRAY_PROTOTYPE_INDEX_OF, + ECMA_ARRAY_PROTOTYPE_LAST_INDEX_OF, + /* Note these 3 routines must be in this order */ + ECMA_ARRAY_PROTOTYPE_EVERY, + ECMA_ARRAY_PROTOTYPE_SOME, + ECMA_ARRAY_PROTOTYPE_FOR_EACH, + ECMA_ARRAY_PROTOTYPE_MAP, + ECMA_ARRAY_PROTOTYPE_FILTER, + /* Note these 2 routines must be in this order */ + ECMA_ARRAY_PROTOTYPE_REDUCE, + ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT, + ECMA_ARRAY_PROTOTYPE_FIND, + ECMA_ARRAY_PROTOTYPE_FIND_INDEX, + ECMA_ARRAY_PROTOTYPE_ENTRIES, + ECMA_ARRAY_PROTOTYPE_KEYS, + ECMA_ARRAY_PROTOTYPE_SYMBOL_ITERATOR, + ECMA_ARRAY_PROTOTYPE_FILL, + ECMA_ARRAY_PROTOTYPE_COPY_WITHIN, + ECMA_ARRAY_PROTOTYPE_INCLUDES, + ECMA_ARRAY_PROTOTYPE_FLAT, + ECMA_ARRAY_PROTOTYPE_FLATMAP, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup arrayprototype ECMA Array.prototype object built-in + * @{ + */ + +/** + * Helper function to set an object's length property + * + * @return ecma value (return value of the [[Put]] method) + * Calling ecma_free_value on the returned value is optional if it is not abrupt completion. + */ +static ecma_value_t +ecma_builtin_array_prototype_helper_set_length (ecma_object_t *object, /**< object*/ + ecma_number_t length) /**< new length */ +{ + ecma_value_t length_value = ecma_make_number_value (length); + ecma_value_t ret_value = + ecma_op_object_put (object, ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), length_value, true); + + ecma_free_value (length_value); + + JERRY_ASSERT (ecma_is_value_boolean (ret_value) || ecma_is_value_empty (ret_value) + || ECMA_IS_VALUE_ERROR (ret_value)); + return ret_value; +} /* ecma_builtin_array_prototype_helper_set_length */ + +/** + * The Array.prototype object's 'toLocaleString' routine + * + * See also: + * ECMA-262 v5, 15.4.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_to_locale_string (ecma_object_t *obj_p, /**< object */ + ecma_length_t length) /**< object's length */ +{ + /* 5. */ + if (length == 0) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + /* 7-8. */ + ecma_string_t *first_string_p = ecma_builtin_helper_get_to_locale_string_at_index (obj_p, 0); + + if (JERRY_UNLIKELY (first_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (first_string_p); + ecma_deref_ecma_string (first_string_p); + + /* 9-10. */ + for (ecma_length_t k = 1; k < length; k++) + { + /* 4. Implementation-defined: set the separator to a single comma character. */ + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_COMMA); + + ecma_string_t *next_string_p = ecma_builtin_helper_get_to_locale_string_at_index (obj_p, k); + + if (JERRY_UNLIKELY (next_string_p == NULL)) + { + ecma_stringbuilder_destroy (&builder); + return ECMA_VALUE_ERROR; + } + + ecma_stringbuilder_append (&builder, next_string_p); + ecma_deref_ecma_string (next_string_p); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_array_prototype_object_to_locale_string */ + +/** + * The Array.prototype object's 'concat' routine + * + * See also: + * ECMA-262 v5, 15.4.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_concat (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p) /**< array object */ +{ + /* 2. */ + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, 0); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 3. */ + ecma_length_t new_length = 0; + + /* 5.b - 5.c for this_arg */ + ecma_value_t concat_this_value = + ecma_builtin_helper_array_concat_value (new_array_p, &new_length, ecma_make_object_value (obj_p)); + if (ECMA_IS_VALUE_ERROR (concat_this_value)) + { + ecma_deref_object (new_array_p); + return concat_this_value; + } + + JERRY_ASSERT (ecma_is_value_empty (concat_this_value)); + + /* 5. */ + for (uint32_t arg_index = 0; arg_index < args_number; arg_index++) + { + ecma_value_t concat_value = ecma_builtin_helper_array_concat_value (new_array_p, &new_length, args[arg_index]); + + if (ECMA_IS_VALUE_ERROR (concat_value)) + { + ecma_deref_object (new_array_p); + return concat_value; + } + + JERRY_ASSERT (ecma_is_value_empty (concat_value)); + } + + ecma_value_t set_length_value = + ecma_builtin_array_prototype_helper_set_length (new_array_p, ((ecma_number_t) new_length)); + if (ECMA_IS_VALUE_ERROR (set_length_value)) + { + ecma_deref_object (new_array_p); + return set_length_value; + } + + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_concat */ + +/** + * The Array.prototype.toString's separator creation routine + * + * See also: + * ECMA-262 v5.1, 15.4.4.2 4th step + * + * @return NULL - if the conversion fails + * ecma_string_t * - otherwise + */ + +static ecma_string_t * +ecma_op_array_get_separator_string (ecma_value_t separator) /**< possible separator */ +{ + if (ecma_is_value_undefined (separator)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR); + } + + return ecma_op_to_string (separator); +} /* ecma_op_array_get_separator_string */ + +/** + * The Array.prototype's 'toString' single element operation routine + * + * See also: + * ECMA-262 v5.1, 15.4.4.2 + * + * @return NULL - if the conversion fails + * ecma_string_t * - otherwise + */ +static ecma_string_t * +ecma_op_array_get_to_string_at_index (ecma_object_t *obj_p, /**< this object */ + ecma_length_t index) /**< array index */ +{ + ecma_value_t index_value = ecma_op_object_get_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (index_value)) + { + return NULL; + } + + if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_string_t *ret_str_p = ecma_op_to_string (index_value); + + ecma_free_value (index_value); + + return ret_str_p; +} /* ecma_op_array_get_to_string_at_index */ + +/** + * The Array.prototype object's 'join' routine + * + * See also: + * ECMA-262 v5, 15.4.4.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_join (ecma_value_t separator_arg, /**< separator argument */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t length) /**< object's length */ +{ + /* 4-5. */ + ecma_string_t *separator_string_p = ecma_op_array_get_separator_string (separator_arg); + + if (JERRY_UNLIKELY (separator_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + if (length == 0) + { + /* 6. */ + ecma_deref_ecma_string (separator_string_p); + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + /* 7-8. */ + ecma_string_t *first_string_p = ecma_op_array_get_to_string_at_index (obj_p, 0); + + if (JERRY_UNLIKELY (first_string_p == NULL)) + { + ecma_deref_ecma_string (separator_string_p); + return ECMA_VALUE_ERROR; + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (first_string_p); + ecma_deref_ecma_string (first_string_p); + + /* 9-10. */ + for (ecma_length_t k = 1; k < length; k++) + { + /* 10.a */ + ecma_stringbuilder_append (&builder, separator_string_p); + + /* 10.d */ + ecma_string_t *next_string_p = ecma_op_array_get_to_string_at_index (obj_p, k); + + if (JERRY_UNLIKELY (next_string_p == NULL)) + { + ecma_deref_ecma_string (separator_string_p); + ecma_stringbuilder_destroy (&builder); + return ECMA_VALUE_ERROR; + } + + ecma_stringbuilder_append (&builder, next_string_p); + ecma_deref_ecma_string (next_string_p); + } + + ecma_deref_ecma_string (separator_string_p); + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_array_prototype_join */ + +/** + * The Array.prototype object's 'pop' routine + * + * See also: + * ECMA-262 v5, 15.4.4.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_pop (ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (len == 0) + { + /* 4.a */ + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, ECMA_NUMBER_ZERO); + + /* 4.b */ + return ECMA_IS_VALUE_ERROR (set_length_value) ? set_length_value : ECMA_VALUE_UNDEFINED; + } + + /* 5.b */ + len--; + ecma_value_t get_value = ecma_op_object_get_by_index (obj_p, len); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_delete_fast_array_properties (obj_p, (uint32_t) len); + + return get_value; + } + + /* 5.c */ + ecma_value_t del_value = ecma_op_object_delete_by_index (obj_p, len, true); + + if (ECMA_IS_VALUE_ERROR (del_value)) + { + ecma_free_value (get_value); + return del_value; + } + + ecma_free_value (del_value); + + /* 5.d */ + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, ((ecma_number_t) len)); + + if (ECMA_IS_VALUE_ERROR (set_length_value)) + { + ecma_free_value (get_value); + return set_length_value; + } + + return get_value; +} /* ecma_builtin_array_prototype_object_pop */ + +/** + * The Array.prototype object's 'push' routine + * + * See also: + * ECMA-262 v5, 15.4.4.7 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_push (const ecma_value_t *argument_list_p, /**< arguments list */ + uint32_t arguments_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t length) /**< object's length */ +{ + if (ecma_op_object_is_fast_array (obj_p)) + { + if ((ecma_number_t) (length + arguments_number) > UINT32_MAX) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_ARRAY_LENGTH); + } + + if (arguments_number == 0) + { + return ecma_make_uint32_value ((uint32_t) length); + } + + uint32_t new_length = ((uint32_t) length) + arguments_number; + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + ecma_value_t *buffer_p = ecma_fast_array_extend (obj_p, new_length) + length; + + for (uint32_t index = 0; index < arguments_number; index++) + { + buffer_p[index] = ecma_copy_value_if_not_object (argument_list_p[index]); + } + + ext_obj_p->u.array.length_prop_and_hole_count -= ECMA_FAST_ARRAY_HOLE_ONE * arguments_number; + + return ecma_make_uint32_value (new_length); + } + + /* 5. */ + if ((ecma_number_t) (length + arguments_number) > ECMA_NUMBER_MAX_SAFE_INTEGER) + { + return ecma_raise_type_error (ECMA_ERR_PUSHING_TOO_HIGH_ELEMENT); + } + + /* 6. */ + for (ecma_length_t index = 0; index < arguments_number; index++, length++) + { + /* 6.b */ + ecma_value_t put_value = ecma_op_object_put_by_index (obj_p, length, argument_list_p[index], true); + + if (ECMA_IS_VALUE_ERROR (put_value)) + { + return put_value; + } + } + + /* 6 - 7. */ + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, (ecma_number_t) length); + + if (ECMA_IS_VALUE_ERROR (set_length_value)) + { + return set_length_value; + } + + return ecma_make_length_value (length); +} /* ecma_builtin_array_prototype_object_push */ + +/** + * The Array.prototype object's 'reverse' routine + * + * See also: + * ECMA-262 v5, 15.4.4.8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg, /**< this argument */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + if (ecma_op_object_is_fast_array (obj_p)) + { + uint32_t middle = (uint32_t) len / 2; + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE && len != 0) + { + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + for (uint32_t i = 0; i < middle; i++) + { + ecma_value_t tmp = buffer_p[i]; + buffer_p[i] = buffer_p[len - 1 - i]; + buffer_p[len - 1 - i] = tmp; + } + + return ecma_copy_value (this_arg); + } + } + + ecma_length_t middle = len / 2; + for (ecma_length_t lower = 0; lower < middle; lower++) + { + ecma_length_t upper = len - lower - 1; + ecma_value_t ret_value = ECMA_VALUE_ERROR; + + ecma_string_t *lower_str_p = ecma_new_ecma_string_from_length (lower); + ecma_string_t *upper_str_p = ecma_new_ecma_string_from_length (upper); + + ecma_value_t lower_value = ECMA_VALUE_EMPTY; + ecma_value_t upper_value = ECMA_VALUE_EMPTY; + + ecma_value_t has_lower = ecma_op_object_has_property (obj_p, lower_str_p); + ecma_value_t has_upper; + + bool upper_exist; + bool lower_exist; + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (has_lower)) + { + goto clean_up; + } +#endif /* JERRY_BUILTIN_PROXY */ + + lower_exist = ecma_is_value_true (has_lower); + + if (lower_exist) + { + lower_value = ecma_op_object_get (obj_p, lower_str_p); + + if (ECMA_IS_VALUE_ERROR (lower_value)) + { + goto clean_up; + } + } + + has_upper = ecma_op_object_has_property (obj_p, upper_str_p); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (has_upper)) + { + goto clean_up; + } +#endif /* JERRY_BUILTIN_PROXY */ + + upper_exist = ecma_is_value_true (has_upper); + + if (upper_exist) + { + upper_value = ecma_op_object_get (obj_p, upper_str_p); + + if (ECMA_IS_VALUE_ERROR (upper_value)) + { + goto clean_up; + } + } + + if (lower_exist && upper_exist) + { + ecma_value_t outer_put_value = ecma_op_object_put (obj_p, lower_str_p, upper_value, true); + + if (ECMA_IS_VALUE_ERROR (outer_put_value)) + { + goto clean_up; + } + + ecma_value_t inner_put_value = ecma_op_object_put (obj_p, upper_str_p, lower_value, true); + + if (ECMA_IS_VALUE_ERROR (inner_put_value)) + { + goto clean_up; + } + } + else if (!lower_exist && upper_exist) + { + ecma_value_t put_value = ecma_op_object_put (obj_p, lower_str_p, upper_value, true); + + if (ECMA_IS_VALUE_ERROR (put_value)) + { + goto clean_up; + } + + ecma_value_t del_value = ecma_op_object_delete (obj_p, upper_str_p, true); + + if (ECMA_IS_VALUE_ERROR (del_value)) + { + goto clean_up; + } + } + else if (lower_exist) + { + ecma_value_t del_value = ecma_op_object_delete (obj_p, lower_str_p, true); + + if (ECMA_IS_VALUE_ERROR (del_value)) + { + goto clean_up; + } + + ecma_value_t put_value = ecma_op_object_put (obj_p, upper_str_p, lower_value, true); + + if (ECMA_IS_VALUE_ERROR (put_value)) + { + goto clean_up; + } + } + + ret_value = ECMA_VALUE_EMPTY; + +clean_up: + ecma_free_value (upper_value); + ecma_free_value (lower_value); + ecma_deref_ecma_string (lower_str_p); + ecma_deref_ecma_string (upper_str_p); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + return ret_value; + } + } + + return ecma_copy_value (this_arg); +} /* ecma_builtin_array_prototype_object_reverse */ + +/** + * The Array.prototype object's 'shift' routine + * + * See also: + * ECMA-262 v5, 15.4.4.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_shift (ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (len == 0) + { + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, ECMA_NUMBER_ZERO); + + return ECMA_IS_VALUE_ERROR (set_length_value) ? set_length_value : ECMA_VALUE_UNDEFINED; + } + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE && len != 0) + { + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + ecma_value_t ret_value = buffer_p[0]; + + if (ecma_is_value_object (ret_value)) + { + ecma_ref_object (ecma_get_object_from_value (ret_value)); + } + + memmove (buffer_p, buffer_p + 1, (size_t) (sizeof (ecma_value_t) * (len - 1))); + + buffer_p[len - 1] = ECMA_VALUE_UNDEFINED; + ecma_delete_fast_array_properties (obj_p, (uint32_t) (len - 1)); + + return ret_value; + } + } + + /* 5. */ + ecma_value_t first_value = ecma_op_object_get_by_index (obj_p, 0); + + if (ECMA_IS_VALUE_ERROR (first_value)) + { + return first_value; + } + + /* 6. and 7. */ + for (ecma_length_t k = 1; k < len; k++) + { + /* 7.a - 7.c */ + ecma_value_t curr_value = ecma_op_object_find_by_index (obj_p, k); + + if (ECMA_IS_VALUE_ERROR (curr_value)) + { + ecma_free_value (first_value); + return curr_value; + } + + /* 7.b */ + ecma_length_t to = k - 1; + ecma_value_t operation_value; + + if (ecma_is_value_found (curr_value)) + { + /* 7.d.i, 7.d.ii */ + operation_value = ecma_op_object_put_by_index (obj_p, to, curr_value, true); + ecma_free_value (curr_value); + } + else + { + /* 7.e.i */ + operation_value = ecma_op_object_delete_by_index (obj_p, to, true); + } + + if (ECMA_IS_VALUE_ERROR (operation_value)) + { + ecma_free_value (first_value); + return operation_value; + } + } + + /* 8. */ + ecma_value_t del_value = ecma_op_object_delete_by_index (obj_p, --len, true); + + if (ECMA_IS_VALUE_ERROR (del_value)) + { + ecma_free_value (first_value); + return del_value; + } + + /* 9. */ + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, ((ecma_number_t) len)); + + if (ECMA_IS_VALUE_ERROR (set_length_value)) + { + ecma_free_value (first_value); + return set_length_value; + } + + /* 10. */ + return first_value; +} /* ecma_builtin_array_prototype_object_shift */ + +/** + * The Array.prototype object's 'slice' routine + * + * See also: + * ECMA-262 v5, 15.4.4.10 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_slice (ecma_value_t arg1, /**< start */ + ecma_value_t arg2, /**< end */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + ecma_length_t start = 0, end = len; + + /* 5. 6.*/ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg1, len, &start))) + { + return ECMA_VALUE_ERROR; + } + + /* 7. */ + if (ecma_is_value_undefined (arg2)) + { + end = len; + } + else + { + /* 7. part 2, 8.*/ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (arg2, len, &end))) + { + return ECMA_VALUE_ERROR; + } + } + + JERRY_ASSERT (start <= len && end <= len); + + bool use_fast_path = ecma_op_object_is_fast_array (obj_p); + ecma_length_t copied_length = (end > start) ? end - start : 0; + + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, copied_length); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + use_fast_path &= ecma_op_object_is_fast_array (new_array_p); + + if (use_fast_path && copied_length > 0) + { + ecma_extended_object_t *ext_from_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_from_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE) + { + if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL)) + { + /** + * Very unlikely case: the buffer copied from is a fast buffer and the property list was deleted. + * There is no need to do any copy. + */ + return ecma_make_object_value (new_array_p); + } + + /* Source array's length could be changed during the start/end normalization. + * If the "end" value is greater than the current length, clamp the value to avoid buffer-overflow. */ + if (ext_from_obj_p->u.array.length < end) + { + end = ext_from_obj_p->u.array.length; + } + + ecma_extended_object_t *ext_to_obj_p = (ecma_extended_object_t *) new_array_p; + + uint32_t target_length = ext_to_obj_p->u.array.length; + ecma_value_t *to_buffer_p; + JERRY_ASSERT (copied_length <= UINT32_MAX); + + if (copied_length == target_length) + { + to_buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, new_array_p->u1.property_list_cp); + } + else if (copied_length > target_length) + { + to_buffer_p = ecma_fast_array_extend (new_array_p, (uint32_t) copied_length); + } + else + { + ecma_delete_fast_array_properties (new_array_p, (uint32_t) copied_length); + to_buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, new_array_p->u1.property_list_cp); + } + + ecma_value_t *from_buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + /* 9. */ + uint32_t n = 0; + + for (uint32_t k = (uint32_t) start; k < (uint32_t) end; k++, n++) + { + ecma_free_value_if_not_object (to_buffer_p[n]); + to_buffer_p[n] = ecma_copy_value_if_not_object (from_buffer_p[k]); + } + + ext_to_obj_p->u.array.length_prop_and_hole_count &= ECMA_FAST_ARRAY_HOLE_ONE - 1; + + return ecma_make_object_value (new_array_p); + } + } + + /* 9. */ + ecma_length_t n = 0; + + /* 10. */ + for (ecma_length_t k = start; k < end; k++, n++) + { + /* 10.c */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, k); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + ecma_deref_object (new_array_p); + return get_value; + } + + if (ecma_is_value_found (get_value)) + { + /* 10.c.ii */ + ecma_value_t put_comp; + put_comp = ecma_builtin_helper_def_prop_by_index (new_array_p, + n, + get_value, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE + | JERRY_PROP_SHOULD_THROW); + ecma_free_value (get_value); + + if (ECMA_IS_VALUE_ERROR (put_comp)) + { + ecma_deref_object (new_array_p); + return put_comp; + } + } + } + + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (new_array_p, ((ecma_number_t) n)); + + if (ECMA_IS_VALUE_ERROR (set_length_value)) + { + ecma_deref_object (new_array_p); + return set_length_value; + } + + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_slice */ + +/** + * SortCompare abstract method + * + * See also: + * ECMA-262 v5, 15.4.4.11 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_sort_compare_helper (ecma_value_t lhs, /**< left value */ + ecma_value_t rhs, /**< right value */ + ecma_value_t compare_func, /**< compare function */ + ecma_object_t *array_buffer_p) /**< arrayBuffer */ +{ + JERRY_UNUSED (array_buffer_p); + /* + * ECMA-262 v5, 15.4.4.11 NOTE1: Because nonexistent property values always + * compare greater than undefined property values, and undefined always + * compares greater than any other value, undefined property values always + * sort to the end of the result, followed by nonexistent property values. + */ + bool lhs_is_undef = ecma_is_value_undefined (lhs); + bool rhs_is_undef = ecma_is_value_undefined (rhs); + + if (lhs_is_undef) + { + return ecma_make_integer_value (rhs_is_undef ? 0 : 1); + } + + if (rhs_is_undef) + { + return ecma_make_integer_value (-1); + } + + ecma_number_t result = ECMA_NUMBER_ZERO; + + if (ecma_is_value_undefined (compare_func)) + { + /* Default comparison when no compare_func is passed. */ + ecma_string_t *lhs_str_p = ecma_op_to_string (lhs); + if (JERRY_UNLIKELY (lhs_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_string_t *rhs_str_p = ecma_op_to_string (rhs); + if (JERRY_UNLIKELY (rhs_str_p == NULL)) + { + ecma_deref_ecma_string (lhs_str_p); + return ECMA_VALUE_ERROR; + } + + if (ecma_compare_ecma_strings_relational (lhs_str_p, rhs_str_p)) + { + result = ECMA_NUMBER_MINUS_ONE; + } + else if (!ecma_compare_ecma_strings (lhs_str_p, rhs_str_p)) + { + result = ECMA_NUMBER_ONE; + } + else + { + result = ECMA_NUMBER_ZERO; + } + + ecma_deref_ecma_string (rhs_str_p); + ecma_deref_ecma_string (lhs_str_p); + } + else + { + /* + * compare_func, if not undefined, will always contain a callable function object. + * We checked this previously, before this function was called. + */ + JERRY_ASSERT (ecma_op_is_callable (compare_func)); + ecma_object_t *comparefn_obj_p = ecma_get_object_from_value (compare_func); + + ecma_value_t compare_args[] = { lhs, rhs }; + + ecma_value_t call_value = ecma_op_function_call (comparefn_obj_p, ECMA_VALUE_UNDEFINED, compare_args, 2); + if (ECMA_IS_VALUE_ERROR (call_value)) + { + return call_value; + } + + if (!ecma_is_value_number (call_value)) + { + ecma_number_t ret_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (call_value, &ret_num))) + { + ecma_free_value (call_value); + return ECMA_VALUE_ERROR; + } + + result = ret_num; + } + else + { + result = ecma_get_number_from_value (call_value); + } + + ecma_free_value (call_value); + } + + return ecma_make_number_value (result); +} /* ecma_builtin_array_prototype_object_sort_compare_helper */ + +/** + * The Array.prototype object's 'sort' routine + * + * See also: + * ECMA-262 v5, 15.4.4.11 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arg1, /**< comparefn */ + ecma_object_t *obj_p) /**< object */ +{ + /* Check if the provided compare function is callable. */ + if (!ecma_is_value_undefined (arg1) && !ecma_op_is_callable (arg1)) + { + return ecma_raise_type_error (ECMA_ERR_COMPARE_FUNC_NOT_CALLABLE); + } + + ecma_length_t len; + ecma_value_t len_value = ecma_op_object_get_length (obj_p, &len); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + return len_value; + } + ecma_collection_t *array_index_props_p = ecma_new_collection (); + + for (uint32_t i = 0; i < len; i++) + { + ecma_string_t *prop_name_p = ecma_new_ecma_string_from_uint32 (i); + + ecma_property_descriptor_t prop_desc; + ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc); + + if (ECMA_IS_VALUE_ERROR (get_desc)) + { + ecma_collection_free (array_index_props_p); + ecma_deref_ecma_string (prop_name_p); + return get_desc; + } + + if (ecma_is_value_true (get_desc)) + { + ecma_ref_ecma_string (prop_name_p); + ecma_collection_push_back (array_index_props_p, ecma_make_string_value (prop_name_p)); + ecma_free_property_descriptor (&prop_desc); + continue; + } + } + + uint32_t defined_prop_count = array_index_props_p->item_count; + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + uint32_t copied_num = 0; + JMEM_DEFINE_LOCAL_ARRAY (values_buffer, defined_prop_count, ecma_value_t); + + ecma_value_t *buffer_p = array_index_props_p->buffer_p; + + /* Copy unsorted array into a native c array. */ + for (uint32_t i = 0; i < array_index_props_p->item_count; i++) + { + ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]); + + uint32_t index = ecma_string_get_array_index (property_name_p); + JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX); + + if (index >= len) + { + break; + } + + ecma_value_t index_value = ecma_op_object_get (obj_p, property_name_p); + + if (ECMA_IS_VALUE_ERROR (index_value)) + { + goto clean_up; + } + + values_buffer[copied_num++] = index_value; + } + + JERRY_ASSERT (copied_num == defined_prop_count); + + /* Sorting. */ + if (copied_num > 1) + { + const ecma_builtin_helper_sort_compare_fn_t sort_cb = &ecma_builtin_array_prototype_object_sort_compare_helper; + ecma_value_t sort_value = + ecma_builtin_helper_array_merge_sort_helper (values_buffer, (uint32_t) (copied_num), arg1, sort_cb, NULL); + if (ECMA_IS_VALUE_ERROR (sort_value)) + { + goto clean_up; + } + + ecma_free_value (sort_value); + } + + /* Put sorted values to the front of the array. */ + for (uint32_t index = 0; index < copied_num; index++) + { + ecma_value_t put_value = ecma_op_object_put_by_index (obj_p, index, values_buffer[index], true); + + if (ECMA_IS_VALUE_ERROR (put_value)) + { + goto clean_up; + } + } + + ret_value = ECMA_VALUE_EMPTY; + +clean_up: + /* Free values that were copied to the local array. */ + for (uint32_t index = 0; index < copied_num; index++) + { + ecma_free_value (values_buffer[index]); + } + + JMEM_FINALIZE_LOCAL_ARRAY (values_buffer); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_collection_free (array_index_props_p); + return ret_value; + } + + JERRY_ASSERT (ecma_is_value_empty (ret_value)); + + /* Undefined properties should be in the back of the array. */ + ecma_value_t *buffer_p = array_index_props_p->buffer_p; + + for (uint32_t i = 0; i < array_index_props_p->item_count; i++) + { + ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]); + + uint32_t index = ecma_string_get_array_index (property_name_p); + JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX); + + if (index >= copied_num && index < len) + { + ecma_value_t del_value = ecma_op_object_delete (obj_p, property_name_p, true); + + if (ECMA_IS_VALUE_ERROR (del_value)) + { + ecma_collection_free (array_index_props_p); + return del_value; + } + } + } + + ecma_collection_free (array_index_props_p); + + return ecma_copy_value (this_arg); +} /* ecma_builtin_array_prototype_object_sort */ + +/** + * The Array.prototype object's 'splice' routine + * + * See also: + * ECMA-262 v11, 22.1.3.28 + * ECMA-262 v5, 15.4.4.12 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_splice (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + ecma_length_t actual_start = 0; + ecma_length_t actual_delete_count = 0; + ecma_length_t insert_count = 0; + + if (args_number > 0) + { + /* ES5.1: 6, ES11: 4. */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[0], len, &actual_start))) + { + return ECMA_VALUE_ERROR; + } + + /* ES11: 6. */ + if (args_number == 1) + { + actual_delete_count = len - actual_start; + } + /* ES11: 7. */ + else + { + insert_count = args_number - 2; + + ecma_number_t delete_num; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (args[1], &delete_num))) + { + return ECMA_VALUE_ERROR; + } + + /* ES5.1: 7 */ + actual_delete_count = + (ecma_length_t) (JERRY_MIN (JERRY_MAX (delete_num, 0), (ecma_number_t) (len - actual_start))); + } + } + + ecma_length_t new_length = len + insert_count - actual_delete_count; + + /* ES11: 8. */ + if ((ecma_number_t) new_length > ECMA_NUMBER_MAX_SAFE_INTEGER) + { + return ecma_raise_type_error (ECMA_ERR_INVALID_NEW_ARRAY_LENGTH); + } + + /* ES11: 9. */ + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, actual_delete_count); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* ES5.1: 8, ES11: 10. */ + ecma_length_t k = 0; + + /* ES5.1: 9, ES11: 11. */ + for (; k < actual_delete_count; k++) + { + ecma_length_t from = actual_start + k; + ecma_value_t from_present = ecma_op_object_find_by_index (obj_p, from); + + if (ECMA_IS_VALUE_ERROR (from_present)) + { + ecma_deref_object (new_array_p); + return from_present; + } + + if (ecma_is_value_found (from_present)) + { + ecma_value_t put_comp = ecma_builtin_helper_def_prop_by_index (new_array_p, + k, + from_present, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE + | JERRY_PROP_SHOULD_THROW); + ecma_free_value (from_present); + + if (ECMA_IS_VALUE_ERROR (put_comp)) + { + ecma_deref_object (new_array_p); + return put_comp; + } + } + } + + /* ES11: 12. */ + ecma_value_t set_length = + ecma_builtin_array_prototype_helper_set_length (new_array_p, ((ecma_number_t) actual_delete_count)); + + if (ECMA_IS_VALUE_ERROR (set_length)) + { + ecma_deref_object (new_array_p); + return set_length; + } + + /* ES5.1: 12, ES11: 15. */ + if (insert_count < actual_delete_count) + { + for (k = actual_start; k < len - actual_delete_count; k++) + { + ecma_length_t from = k + actual_delete_count; + ecma_length_t to = k + insert_count; + + ecma_value_t from_present = ecma_op_object_find_by_index (obj_p, from); + + if (ECMA_IS_VALUE_ERROR (from_present)) + { + ecma_deref_object (new_array_p); + return from_present; + } + + ecma_value_t operation_value; + + if (ecma_is_value_found (from_present)) + { + operation_value = ecma_op_object_put_by_index (obj_p, to, from_present, true); + ecma_free_value (from_present); + } + else + { + operation_value = ecma_op_object_delete_by_index (obj_p, to, true); + } + + if (ECMA_IS_VALUE_ERROR (operation_value)) + { + ecma_deref_object (new_array_p); + return operation_value; + } + } + + k = len; + + for (k = len; k > new_length; k--) + { + ecma_value_t del_value = ecma_op_object_delete_by_index (obj_p, k - 1, true); + + if (ECMA_IS_VALUE_ERROR (del_value)) + { + ecma_deref_object (new_array_p); + return del_value; + } + } + } + /* ES5.1: 13, ES11: 16. */ + else if (insert_count > actual_delete_count) + { + for (k = len - actual_delete_count; k > actual_start; k--) + { + ecma_length_t from = k + actual_delete_count - 1; + ecma_length_t to = k + insert_count - 1; + + ecma_value_t from_present = ecma_op_object_find_by_index (obj_p, from); + + if (ECMA_IS_VALUE_ERROR (from_present)) + { + ecma_deref_object (new_array_p); + return from_present; + } + + ecma_value_t operation_value; + + if (ecma_is_value_found (from_present)) + { + operation_value = ecma_op_object_put_by_index (obj_p, to, from_present, true); + ecma_free_value (from_present); + } + else + { + operation_value = ecma_op_object_delete_by_index (obj_p, to, true); + } + + if (ECMA_IS_VALUE_ERROR (operation_value)) + { + ecma_deref_object (new_array_p); + return operation_value; + } + } + } + + /* ES5.1: 14, ES11: 17. */ + k = actual_start; + + /* ES5.1: 15, ES11: 18. */ + uint32_t idx = 0; + for (uint32_t arg_index = 2; arg_index < args_number; arg_index++, idx++) + { + ecma_value_t put_value = ecma_op_object_put_by_index (obj_p, actual_start + idx, args[arg_index], true); + + if (ECMA_IS_VALUE_ERROR (put_value)) + { + ecma_deref_object (new_array_p); + return put_value; + } + } + + /* ES5.1: 16, ES11: 19. */ + ecma_value_t set_new_length = ecma_builtin_array_prototype_helper_set_length (obj_p, ((ecma_number_t) new_length)); + + if (ECMA_IS_VALUE_ERROR (set_new_length)) + { + ecma_deref_object (new_array_p); + return set_new_length; + } + + /* ES5.1: 17, ES11: 20. */ + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_splice */ + +/** + * The Array.prototype object's 'unshift' routine + * + * See also: + * ECMA-262 v5, 15.4.4.13 + * ECMA-262 v11, 22.1.3.31 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_unshift (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE && len != 0) + { + if (args_number > UINT32_MAX - len) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_ARRAY_LENGTH); + } + + if (args_number == 0) + { + return ecma_make_uint32_value ((uint32_t) len); + } + + uint32_t new_length = ((uint32_t) len) + args_number; + ecma_value_t *buffer_p = ecma_fast_array_extend (obj_p, new_length); + memmove (buffer_p + args_number, buffer_p, (size_t) (sizeof (ecma_value_t) * len)); + + uint32_t index = 0; + + while (index < args_number) + { + buffer_p[index] = ecma_copy_value_if_not_object (args[index]); + index++; + } + + ext_obj_p->u.array.length_prop_and_hole_count -= args_number * ECMA_FAST_ARRAY_HOLE_ONE; + + return ecma_make_uint32_value (new_length); + } + } + + if (args_number > 0) + { + /* ES11:4.a. */ + if ((ecma_number_t) (len + args_number) > ECMA_NUMBER_MAX_SAFE_INTEGER) + { + return ecma_raise_type_error (ECMA_ERR_UNSHIFT_TOO_HIGH); + } + + /* ES5.1:5.,6. ES11: 4.b, 4.c */ + for (ecma_length_t k = len; k > 0; k--) + { + /* ES5.1:6.a, 6.c, ES11:4.c.i., 4.c.iii. */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, k - 1); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + /* ES5.1:6.b, ES11:4.c.ii. */ + ecma_number_t new_idx = ((ecma_number_t) k) + ((ecma_number_t) args_number) - 1; + ecma_string_t *index_str_p = ecma_new_ecma_string_from_number (new_idx); + ecma_value_t operation_value; + + if (ecma_is_value_found (get_value)) + { + /* ES5.1:6.d.i, 6.d.ii, ES11:4.c.iv. */ + operation_value = ecma_op_object_put (obj_p, index_str_p, get_value, true); + ecma_free_value (get_value); + } + else + { + /* ES5.1:6.e.i, ES11:4.c.v. */ + operation_value = ecma_op_object_delete (obj_p, index_str_p, true); + } + + ecma_deref_ecma_string (index_str_p); + + if (ECMA_IS_VALUE_ERROR (operation_value)) + { + return operation_value; + } + } + + for (uint32_t arg_index = 0; arg_index < args_number; arg_index++) + { + /* ES5.1:9.b, ES11:4.f.ii. */ + ecma_value_t put_value = ecma_op_object_put_by_index (obj_p, arg_index, args[arg_index], true); + + if (ECMA_IS_VALUE_ERROR (put_value)) + { + return put_value; + } + } + } + + /* ES5.1:10., ES11:5. */ + ecma_number_t new_len = ((ecma_number_t) len) + ((ecma_number_t) args_number); + ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, new_len); + + if (ECMA_IS_VALUE_ERROR (set_length_value)) + { + return set_length_value; + } + + return ecma_make_number_value (new_len); +} /* ecma_builtin_array_prototype_object_unshift */ + +/** + * The Array.prototype object's 'at' routine + * + * See also: + * ECMA-262 Stage 3 Draft Relative Indexing Method proposal + * from: https://tc39.es/proposal-relative-indexing-method + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_at (const ecma_value_t index, /**< index argument */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + ecma_length_t res_index; + ecma_value_t return_value = ecma_builtin_helper_calculate_index (index, len, &res_index); + + if (return_value != ECMA_VALUE_EMPTY) + { + return return_value; + } + + return ecma_op_object_get_by_index (obj_p, res_index); +} /* ecma_builtin_array_prototype_object_at */ + +/** + * The Array.prototype object's 'indexOf' routine + * + * See also: + * ECMA-262 v5, 15.4.4.14 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_index_of (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (len == 0) + { + return ecma_make_integer_value (-1); + } + + /* 5. */ + ecma_number_t idx = 0; + if (args_number > 1) + { + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (args[1], &idx))) + { + return ECMA_VALUE_ERROR; + } + } + + /* 6. */ + if (idx >= (ecma_number_t) len) + { + return ecma_make_number_value (-1); + } + + /* 7. */ + ecma_length_t from_idx = (ecma_length_t) idx; + + /* 8. */ + if (idx < 0) + { + from_idx = (ecma_length_t) JERRY_MAX ((ecma_number_t) len + idx, 0); + } + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE) + { + if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL)) + { + return ecma_make_integer_value (-1); + } + + len = JERRY_MIN (ext_obj_p->u.array.length, len); + + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + while (from_idx < len) + { + if (ecma_op_strict_equality_compare (args[0], buffer_p[from_idx])) + { + return ecma_make_uint32_value ((uint32_t) from_idx); + } + + from_idx++; + } + + return ecma_make_integer_value (-1); + } + } + + /* 6. */ + while (from_idx < len) + { + /* 9.a */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, from_idx); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + /* 9.b.i, 9.b.ii */ + if (ecma_is_value_found (get_value) && ecma_op_strict_equality_compare (args[0], get_value)) + { + ecma_free_value (get_value); + return ecma_make_length_value (from_idx); + } + + from_idx++; + + ecma_free_value (get_value); + } + + return ecma_make_integer_value (-1); +} /* ecma_builtin_array_prototype_object_index_of */ + +/** + * The Array.prototype object's 'lastIndexOf' routine + * + * See also: + * ECMA-262 v5, 15.4.4.15 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_last_index_of (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (len == 0) + { + return ecma_make_integer_value (-1); + } + + /* 5. */ + ecma_number_t idx = (ecma_number_t) len - 1; + if (args_number > 1) + { + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (args[1], &idx))) + { + return ECMA_VALUE_ERROR; + } + } + + ecma_length_t from_idx; + + /* 6 */ + if (idx >= 0) + { + from_idx = (ecma_length_t) (JERRY_MIN (idx, (ecma_number_t) (len - 1))); + } + else + { + ecma_number_t k = (ecma_number_t) len + idx; + if (k < 0) + { + return ecma_make_integer_value (-1); + } + from_idx = (ecma_length_t) k; + } + + ecma_value_t search_element = (args_number > 0) ? args[0] : ECMA_VALUE_UNDEFINED; + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE) + { + if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL)) + { + return ecma_make_integer_value (-1); + } + + len = JERRY_MIN (ext_obj_p->u.array.length, len); + + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + while (from_idx < len) + { + if (ecma_op_strict_equality_compare (search_element, buffer_p[from_idx])) + { + return ecma_make_uint32_value ((uint32_t) from_idx); + } + from_idx--; + } + return ecma_make_integer_value (-1); + } + } + + /* 8. */ + while (from_idx < len) + { + /* 8.a */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, from_idx); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + /* 8.b.i, 8.b.ii */ + if (ecma_is_value_found (get_value) && ecma_op_strict_equality_compare (search_element, get_value)) + { + ecma_free_value (get_value); + return ecma_make_length_value (from_idx); + } + + from_idx--; + + ecma_free_value (get_value); + } + + return ecma_make_integer_value (-1); +} /* ecma_builtin_array_prototype_object_last_index_of */ + +/** + * Type of array routine. + */ +typedef enum +{ + ARRAY_ROUTINE_EVERY, /**< Array.every: ECMA-262 v5, 15.4.4.16 */ + ARRAY_ROUTINE_SOME, /**< Array.some: ECMA-262 v5, 15.4.4.17 */ + ARRAY_ROUTINE_FOREACH, /**< Array.forEach: ECMA-262 v5, 15.4.4.18 */ + ARRAY_ROUTINE__COUNT /**< count of the modes */ +} array_routine_mode; + +/** + * Applies the provided function to each element of the array as long as + * the return value stays empty. The common function for 'every', 'some' + * and 'forEach' of the Array prototype. + * + * See also: + * ECMA-262 v5, 15.4.4.16 + * ECMA-262 v5, 15.4.4.17 + * ECMA-262 v5, 15.4.4.18 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_apply (ecma_value_t arg1, /**< callbackfn */ + ecma_value_t arg2, /**< thisArg */ + array_routine_mode mode, /**< array routine mode */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ + +{ + JERRY_ASSERT (mode < ARRAY_ROUTINE__COUNT); + + /* 4. */ + if (!ecma_op_is_callable (arg1)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* We already checked that arg1 is callable */ + ecma_object_t *func_object_p = ecma_get_object_from_value (arg1); + ecma_value_t current_index; + + /* 7. */ + for (ecma_length_t index = 0; index < len; index++) + { + /* 7.a - 7.c */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + if (ecma_is_value_found (get_value)) + { + /* 7.c.i */ + current_index = ecma_make_length_value (index); + + ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) }; + /* 7.c.ii */ + ecma_value_t call_value = ecma_op_function_call (func_object_p, arg2, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + ecma_free_value (get_value); + return call_value; + } + + bool to_boolean = ecma_op_to_boolean (call_value); + + ecma_free_value (call_value); + ecma_free_value (get_value); + + /* 7.c.iii */ + if (mode == ARRAY_ROUTINE_EVERY && !to_boolean) + { + return ECMA_VALUE_FALSE; + } + else if (mode == ARRAY_ROUTINE_SOME && to_boolean) + { + return ECMA_VALUE_TRUE; + } + } + } + + /* 8. */ + + if (mode == ARRAY_ROUTINE_EVERY) + { + return ECMA_VALUE_TRUE; + } + else if (mode == ARRAY_ROUTINE_SOME) + { + return ECMA_VALUE_FALSE; + } + + JERRY_ASSERT (mode == ARRAY_ROUTINE_FOREACH); + return ECMA_VALUE_UNDEFINED; +} /* ecma_builtin_array_apply */ + +/** + * The Array.prototype object's 'map' routine + * + * See also: + * ECMA-262 v5, 15.4.4.19 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_map (ecma_value_t arg1, /**< callbackfn */ + ecma_value_t arg2, /**< thisArg */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (!ecma_op_is_callable (arg1)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* 6. */ + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, len); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + JERRY_ASSERT (ecma_is_value_object (arg1)); + ecma_object_t *func_object_p = ecma_get_object_from_value (arg1); + + /* 7-8. */ + ecma_value_t current_index; + + for (ecma_length_t index = 0; index < len; index++) + { + /* 8.a - 8.b */ + ecma_value_t current_value = ecma_op_object_find_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (current_value)) + { + ecma_deref_object (new_array_p); + return current_value; + } + + if (ecma_is_value_found (current_value)) + { + /* 8.c.i, 8.c.ii */ + current_index = ecma_make_length_value (index); + ecma_value_t call_args[] = { current_value, current_index, ecma_make_object_value (obj_p) }; + + ecma_value_t mapped_value = ecma_op_function_call (func_object_p, arg2, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (mapped_value)) + { + ecma_free_value (current_value); + ecma_deref_object (new_array_p); + return mapped_value; + } + + /* 8.c.iii */ + ecma_value_t put_comp; + put_comp = ecma_builtin_helper_def_prop_by_index (new_array_p, + index, + mapped_value, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE + | JERRY_PROP_SHOULD_THROW); + + ecma_free_value (mapped_value); + ecma_free_value (current_value); + + if (ECMA_IS_VALUE_ERROR (put_comp)) + { + ecma_deref_object (new_array_p); + return put_comp; + } + } + } + + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_map */ + +/** + * The Array.prototype object's 'filter' routine + * + * See also: + * ECMA-262 v5, 15.4.4.20 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_filter (ecma_value_t arg1, /**< callbackfn */ + ecma_value_t arg2, /**< thisArg */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (!ecma_op_is_callable (arg1)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* 6. */ + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, 0); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* ES11: 22.1.3.7. 7.c.iii.1 */ + const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + + /* We already checked that arg1 is callable, so it will always be an object. */ + JERRY_ASSERT (ecma_is_value_object (arg1)); + ecma_object_t *func_object_p = ecma_get_object_from_value (arg1); + + /* 8. */ + ecma_length_t new_array_index = 0; + ecma_value_t current_index; + + /* 9. */ + for (ecma_length_t index = 0; index < len; index++) + { + /* 9.a - 9.c */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + ecma_deref_object (new_array_p); + return get_value; + } + + if (ecma_is_value_found (get_value)) + { + /* 9.c.i */ + current_index = ecma_make_length_value (index); + + ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) }; + /* 9.c.ii */ + ecma_value_t call_value = ecma_op_function_call (func_object_p, arg2, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + ecma_free_value (get_value); + ecma_deref_object (new_array_p); + return call_value; + } + + /* 9.c.iii */ + if (ecma_op_to_boolean (call_value)) + { + ecma_value_t put_comp; + put_comp = ecma_builtin_helper_def_prop_by_index (new_array_p, new_array_index, get_value, prop_flags); + + if (ECMA_IS_VALUE_ERROR (put_comp)) + { + ecma_free_value (call_value); + ecma_free_value (get_value); + ecma_deref_object (new_array_p); + + return put_comp; + } + + new_array_index++; + } + + ecma_free_value (call_value); + ecma_free_value (get_value); + } + } + + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_filter */ + +/** + * The Array.prototype object's 'reduce' and 'reduceRight' routine + * + * See also: + * ECMA-262 v5, 15.4.4.21 + * ECMA-262 v5, 15.4.4.22 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_reduce_from (const ecma_value_t args_p[], /**< routine's arguments */ + uint32_t args_number, /**< arguments list length */ + bool start_from_left, /**< whether the reduce starts from left or right */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 4. */ + if (!ecma_op_is_callable (args_p[0])) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* 5. */ + if (len == 0 && args_number == 1) + { + return ecma_raise_type_error (ECMA_ERR_REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE); + } + + JERRY_ASSERT (ecma_is_value_object (args_p[0])); + ecma_object_t *func_object_p = ecma_get_object_from_value (args_p[0]); + + ecma_value_t accumulator = ECMA_VALUE_UNDEFINED; + + /* 6. */ + ecma_length_t index = 0; + const ecma_length_t last_index = len - 1; + + /* 7.a */ + if (args_number > 1) + { + accumulator = ecma_copy_value (args_p[1]); + } + else + { + /* 8.a */ + bool k_present = false; + + /* 8.b */ + while (!k_present && index < len) + { + /* 8.b.i */ + k_present = true; + + /* 8.b.ii-iii */ + ecma_value_t current_value = ecma_op_object_find_by_index (obj_p, start_from_left ? index : last_index - index); + + if (ECMA_IS_VALUE_ERROR (current_value)) + { + return current_value; + } + + if (ecma_is_value_found (current_value)) + { + accumulator = current_value; + } + else + { + k_present = false; + } + + /* 8.b.iv */ + index++; + } + + /* 8.c */ + if (!k_present) + { + return ecma_raise_type_error (ECMA_ERR_MISSING_ARRAY_ELEMENT); + } + } + /* 9. */ + ecma_value_t current_index; + + for (; index < len; index++) + { + const ecma_length_t corrected_index = start_from_left ? index : last_index - index; + + /* 9.a - 9.b */ + ecma_value_t current_value = ecma_op_object_find_by_index (obj_p, corrected_index); + + if (ECMA_IS_VALUE_ERROR (current_value)) + { + ecma_free_value (accumulator); + return current_value; + } + + if (ecma_is_value_found (current_value)) + { + /* 9.c.i, 9.c.ii */ + current_index = ecma_make_length_value (corrected_index); + ecma_value_t call_args[] = { accumulator, current_value, current_index, ecma_make_object_value (obj_p) }; + + ecma_value_t call_value = ecma_op_function_call (func_object_p, ECMA_VALUE_UNDEFINED, call_args, 4); + ecma_free_value (current_index); + ecma_free_value (accumulator); + ecma_free_value (current_value); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + return call_value; + } + + accumulator = call_value; + } + } + + return accumulator; +} /* ecma_builtin_array_reduce_from */ + +/** + * The Array.prototype object's 'fill' routine + * + * Note: this method only supports length up to uint32, instead of max_safe_integer + * + * See also: + * ECMA-262 v6, 22.1.3.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_fill (ecma_value_t value, /**< value */ + ecma_value_t start_val, /**< start value */ + ecma_value_t end_val, /**< end value */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + ecma_length_t k, final; + + /* 5. 6. 7. */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (start_val, len, &k))) + { + return ECMA_VALUE_ERROR; + } + + /* 8. */ + if (ecma_is_value_undefined (end_val)) + { + final = len; + } + else + { + /* 8 part 2, 9, 10 */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (end_val, len, &final))) + { + return ECMA_VALUE_ERROR; + } + } + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE) + { + if (JERRY_UNLIKELY (obj_p->u1.property_list_cp == JMEM_CP_NULL)) + { + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); + } + + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + while (k < final) + { + ecma_free_value_if_not_object (buffer_p[k]); + buffer_p[k] = ecma_copy_value_if_not_object (value); + k++; + } + + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); + } + } + + /* 11. */ + while (k < final) + { + /* 11.a - 11.b */ + ecma_value_t put_val = ecma_op_object_put_by_index (obj_p, k, value, true); + + /* 11. c */ + if (ECMA_IS_VALUE_ERROR (put_val)) + { + return put_val; + } + + /* 11.d */ + k++; + } + + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); +} /* ecma_builtin_array_prototype_fill */ + +/** + * The Array.prototype object's 'find' and 'findIndex' routine + * + * See also: + * ECMA-262 v6, 22.1.3.8 + * ECMA-262 v6, 22.1.3.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_find (ecma_value_t predicate, /**< callback function */ + ecma_value_t predicate_this_arg, /**< this argument for + * invoke predicate */ + bool is_find, /**< true - find routine + * false - findIndex routine */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 5. */ + if (!ecma_op_is_callable (predicate)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* We already checked that predicate is callable, so it will always be an object. */ + JERRY_ASSERT (ecma_is_value_object (predicate)); + ecma_object_t *func_object_p = ecma_get_object_from_value (predicate); + + /* 7 - 8. */ + for (ecma_length_t index = 0; index < len; index++) + { + /* 8.a - 8.c */ + ecma_value_t get_value = ecma_op_object_get_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + /* 8.d - 8.e */ + ecma_value_t current_index = ecma_make_length_value (index); + + ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) }; + + ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + ecma_free_value (get_value); + return call_value; + } + + bool call_value_to_bool = ecma_op_to_boolean (call_value); + + ecma_free_value (call_value); + + if (call_value_to_bool) + { + /* 8.f */ + if (is_find) + { + ecma_free_value (current_index); + return get_value; + } + + ecma_free_value (get_value); + return current_index; + } + + ecma_free_value (get_value); + ecma_free_value (current_index); + } + + /* 9. */ + return is_find ? ECMA_VALUE_UNDEFINED : ecma_make_integer_value (-1); +} /* ecma_builtin_array_prototype_object_find */ + +/** + * The Array.prototype object's 'copyWithin' routine + * + * See also: + * ECMA-262 v6, 22.1.3.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_copy_within (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + if (args_number == 0) + { + return ecma_copy_value (ecma_make_object_value (obj_p)); + } + + /* 5 - 7 */ + ecma_length_t target; + + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[0], len, &target))) + { + return ECMA_VALUE_ERROR; + } + + ecma_length_t start = 0; + ecma_length_t end = len; + + if (args_number > 1) + { + /* 8 - 10 */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[1], len, &start))) + { + return ECMA_VALUE_ERROR; + } + + if (args_number > 2) + { + /* 11 */ + if (ecma_is_value_undefined (args[2])) + { + end = len; + } + else + { + /* 11 part 2, 12, 13 */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[2], len, &end))) + { + return ECMA_VALUE_ERROR; + } + } + } + } + + ecma_length_t count = JERRY_MIN (end - start, len - target); + if (end <= start || len <= target) /* count <= 0 check, but variables are unsigned */ + { + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); + } + + bool forward = true; + + if (start < target && target < start + count) + { + start = start + count - 1; + target = target + count - 1; + forward = false; + } + + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + const uint32_t actual_length = ext_obj_p->u.array.length; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE + && ((forward && (target + count - 1 < actual_length)) || (!forward && (target < actual_length)))) + { + if (obj_p->u1.property_list_cp != JMEM_CP_NULL) + { + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + for (; count > 0; count--) + { + ecma_value_t copy_value = ecma_copy_value_if_not_object (buffer_p[start]); + + ecma_free_value_if_not_object (buffer_p[target]); + + buffer_p[target] = copy_value; + + if (forward) + { + start++; + target++; + } + else + { + start--; + target--; + } + } + } + + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); + } + } + + while (count > 0) + { + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, start); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + ecma_value_t op_value; + + if (ecma_is_value_found (get_value)) + { + op_value = ecma_op_object_put_by_index (obj_p, target, get_value, true); + } + else + { + op_value = ecma_op_object_delete_by_index (obj_p, target, true); + } + + ecma_free_value (get_value); + + if (ECMA_IS_VALUE_ERROR (op_value)) + { + return op_value; + } + + ecma_free_value (op_value); + + if (forward) + { + start++; + target++; + } + else + { + start--; + target--; + } + + count--; + } + + return ecma_copy_value (ecma_make_object_value (obj_p)); +} /* ecma_builtin_array_prototype_object_copy_within */ + +/** + * The Array.prototype object's 'includes' routine + * + * See also: + * ECMA-262 v11, 22.1.3.13 + * + * @return ECMA_VALUE_ERROR -if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the search element is in the array or not + */ +static ecma_value_t +ecma_builtin_array_prototype_includes (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< object */ + ecma_length_t len) /**< object's length */ +{ + /* 3. */ + if (len == 0) + { + return ECMA_VALUE_FALSE; + } + + ecma_length_t from_index = 0; + + /* 4-7. */ + if (args_number > 1) + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_array_index_normalize (args[1], len, &from_index))) + { + return ECMA_VALUE_ERROR; + } + } + + /* Fast array path */ + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE) + { + if (obj_p->u1.property_list_cp != JMEM_CP_NULL) + { + len = JERRY_MIN (ext_obj_p->u.array.length, len); + + ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp); + + while (from_index < len) + { + if (ecma_op_same_value_zero (buffer_p[from_index], args[0], false)) + { + return ECMA_VALUE_TRUE; + } + + from_index++; + } + } + + return ECMA_VALUE_FALSE; + } + } + + /* 8. */ + while (from_index < len) + { + ecma_value_t element = ecma_op_object_get_by_index (obj_p, from_index); + + if (ECMA_IS_VALUE_ERROR (element)) + { + return element; + } + + if (ecma_op_same_value_zero (element, args[0], false)) + { + ecma_free_value (element); + return ECMA_VALUE_TRUE; + } + + ecma_free_value (element); + from_index++; + } + + /* 9. */ + return ECMA_VALUE_FALSE; +} /* ecma_builtin_array_prototype_includes */ + +/** + * Abstract operation: FlattenIntoArray + * + * See also: + * ECMA-262 v10, 22.1.3.10.1 + * + * @return ECMA_VALUE_ERROR -if the operation fails + * ecma value which contains target_index + */ +static ecma_value_t +ecma_builtin_array_flatten_into_array (ecma_value_t target, /**< target will contains source's elements */ + ecma_object_t *source, /**< source object */ + ecma_length_t source_len, /**< source object length */ + ecma_length_t start, /**< remaining recursion depth */ + ecma_number_t depth, /**< start index offset */ + ecma_value_t mapped_value, /**< mapped value */ + ecma_value_t thisArg) /**< this arg */ +{ + ECMA_CHECK_STACK_USAGE (); + + /* 7. */ + ecma_length_t target_index = start; + + /* 9. */ + for (ecma_length_t source_index = 0; source_index < source_len; source_index++) + { + /* a. */ + ecma_value_t element = ecma_op_object_find_by_index (source, source_index); + + if (ECMA_IS_VALUE_ERROR (element)) + { + return element; + } + + if (!ecma_is_value_found (element)) + { + continue; + } + + /* b-c. */ + if (!ecma_is_value_undefined (mapped_value)) + { + /* i-ii. */ + ecma_value_t source_val = ecma_make_length_value (source_index); + ecma_value_t args[] = { element, source_val, ecma_make_object_value (source) }; + ecma_value_t temp_element = ecma_op_function_call (ecma_get_object_from_value (mapped_value), thisArg, args, 3); + + ecma_free_value (element); + ecma_free_value (source_val); + + if (ECMA_IS_VALUE_ERROR (temp_element)) + { + return temp_element; + } + + element = temp_element; + } + + /* iv-v. */ + if (depth > 0) + { + ecma_value_t is_array = ecma_is_value_array (element); + + if (ECMA_IS_VALUE_ERROR (is_array)) + { + ecma_free_value (element); + return is_array; + } + + if (ecma_is_value_true (is_array)) + { + ecma_object_t *element_obj = ecma_get_object_from_value (element); + ecma_length_t element_len; + ecma_value_t len_value = ecma_op_object_get_length (element_obj, &element_len); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + ecma_deref_object (element_obj); + return len_value; + } + + ecma_value_t target_index_val = ecma_builtin_array_flatten_into_array (target, + element_obj, + element_len, + target_index, + depth - 1, + ECMA_VALUE_UNDEFINED, + ECMA_VALUE_UNDEFINED); + + ecma_deref_object (element_obj); + + if (ECMA_IS_VALUE_ERROR (target_index_val)) + { + return target_index_val; + } + + target_index = (ecma_length_t) ecma_get_number_from_value (target_index_val); + continue; + } + } + + /* vi. */ + const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + ecma_value_t element_temp = + ecma_builtin_helper_def_prop_by_index (ecma_get_object_from_value (target), target_index, element, flags); + + ecma_free_value (element); + + if (ECMA_IS_VALUE_ERROR (element_temp)) + { + return element_temp; + } + + target_index++; + } + /* 10. */ + return ecma_make_length_value (target_index); +} /* ecma_builtin_array_flatten_into_array */ + +/** + * The Array.prototype object's 'flat' routine + * + * See also: + * ECMA-262 v10, 22.1.3.10 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_flat (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number, /**< number of arguments */ + ecma_object_t *obj_p, /**< array object */ + ecma_length_t len) /**< array object's length */ +{ + /* 3. */ + ecma_number_t depth_num = 1; + + /* 4. */ + if (args_number > 0 && ECMA_IS_VALUE_ERROR (ecma_op_to_integer (args[0], &depth_num))) + { + return ECMA_VALUE_ERROR; + } + + /* 5. */ + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, 0); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 6. */ + ecma_value_t flatten_val = ecma_builtin_array_flatten_into_array (ecma_make_object_value (new_array_p), + obj_p, + len, + 0, + depth_num, + ECMA_VALUE_UNDEFINED, + ECMA_VALUE_UNDEFINED); + + if (ECMA_IS_VALUE_ERROR (flatten_val)) + { + ecma_deref_object (new_array_p); + return flatten_val; + } + + /* 7. */ + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_flat */ + +/** + * The Array.prototype object's 'flatMap' routine + * + * See also: + * ECMA-262 v10, 22.1.3.11 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_prototype_object_flat_map (ecma_value_t callback, /**< callbackFn */ + ecma_value_t this_arg, /**< thisArg */ + ecma_object_t *obj_p, /**< array object */ + ecma_length_t len) /**< array object's length */ +{ + if (!ecma_op_is_callable (callback)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* 4. */ + ecma_object_t *new_array_p = ecma_op_array_species_create (obj_p, 0); + + if (JERRY_UNLIKELY (new_array_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 5. */ + ecma_value_t flatten_val = + ecma_builtin_array_flatten_into_array (ecma_make_object_value (new_array_p), obj_p, len, 0, 1, callback, this_arg); + if (ECMA_IS_VALUE_ERROR (flatten_val)) + { + ecma_deref_object (new_array_p); + return flatten_val; + } + + /* 6. */ + return ecma_make_object_value (new_array_p); +} /* ecma_builtin_array_prototype_object_flat_map */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_array_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + ecma_value_t obj_this = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (obj_this)) + { + return obj_this; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (obj_this); + + if (JERRY_UNLIKELY (builtin_routine_id <= ECMA_ARRAY_PROTOTYPE_CONCAT)) + { + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + if (builtin_routine_id == ECMA_ARRAY_PROTOTYPE_SORT) + { + ret_value = ecma_builtin_array_prototype_object_sort (this_arg, arguments_list_p[0], obj_p); + } + else if (builtin_routine_id == ECMA_ARRAY_PROTOTYPE_CONCAT) + { + ret_value = ecma_builtin_array_prototype_object_concat (arguments_list_p, arguments_number, obj_p); + } + + ecma_deref_object (obj_p); + return ret_value; + } + + if (JERRY_UNLIKELY (builtin_routine_id >= ECMA_ARRAY_PROTOTYPE_ENTRIES + && builtin_routine_id <= ECMA_ARRAY_PROTOTYPE_KEYS)) + { + ecma_value_t ret_value; + + if (builtin_routine_id == ECMA_ARRAY_PROTOTYPE_ENTRIES) + { + ret_value = ecma_op_create_array_iterator (obj_p, ECMA_ITERATOR_ENTRIES); + } + else + { + JERRY_ASSERT (builtin_routine_id == ECMA_ARRAY_PROTOTYPE_KEYS); + ret_value = ecma_op_create_array_iterator (obj_p, ECMA_ITERATOR_KEYS); + } + + ecma_deref_object (obj_p); + return ret_value; + } + + ecma_length_t length; + ecma_value_t len_value = ecma_op_object_get_length (obj_p, &length); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + ecma_deref_object (obj_p); + return len_value; + } + + ecma_value_t ret_value; + + switch (builtin_routine_id) + { + case ECMA_ARRAY_PROTOTYPE_TO_LOCALE_STRING: + { + ret_value = ecma_builtin_array_prototype_object_to_locale_string (obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_JOIN: + { + ret_value = ecma_builtin_array_prototype_join (arguments_list_p[0], obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_POP: + { + ret_value = ecma_builtin_array_prototype_object_pop (obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_PUSH: + { + ret_value = ecma_builtin_array_prototype_object_push (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_REVERSE: + { + ret_value = ecma_builtin_array_prototype_object_reverse (this_arg, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_SHIFT: + { + ret_value = ecma_builtin_array_prototype_object_shift (obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_SLICE: + { + ret_value = ecma_builtin_array_prototype_object_slice (arguments_list_p[0], arguments_list_p[1], obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_SPLICE: + { + ret_value = ecma_builtin_array_prototype_object_splice (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_UNSHIFT: + { + ret_value = ecma_builtin_array_prototype_object_unshift (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_AT: + { + ret_value = ecma_builtin_array_prototype_object_at (arguments_list_p[0], obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_INDEX_OF: + { + ret_value = ecma_builtin_array_prototype_object_index_of (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_LAST_INDEX_OF: + { + ret_value = ecma_builtin_array_prototype_object_last_index_of (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_EVERY: + case ECMA_ARRAY_PROTOTYPE_SOME: + case ECMA_ARRAY_PROTOTYPE_FOR_EACH: + { + ret_value = ecma_builtin_array_apply (arguments_list_p[0], + arguments_list_p[1], + (array_routine_mode) (builtin_routine_id - (uint8_t) ECMA_ARRAY_PROTOTYPE_EVERY), + obj_p, + length); + break; + } + case ECMA_ARRAY_PROTOTYPE_MAP: + { + ret_value = ecma_builtin_array_prototype_object_map (arguments_list_p[0], arguments_list_p[1], obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_REDUCE: + case ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT: + { + ret_value = ecma_builtin_array_reduce_from (arguments_list_p, + arguments_number, + builtin_routine_id == ECMA_ARRAY_PROTOTYPE_REDUCE, + obj_p, + length); + break; + } + case ECMA_ARRAY_PROTOTYPE_COPY_WITHIN: + { + ret_value = ecma_builtin_array_prototype_object_copy_within (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_FIND: + case ECMA_ARRAY_PROTOTYPE_FIND_INDEX: + { + ret_value = ecma_builtin_array_prototype_object_find (arguments_list_p[0], + arguments_list_p[1], + builtin_routine_id == ECMA_ARRAY_PROTOTYPE_FIND, + obj_p, + length); + break; + } + case ECMA_ARRAY_PROTOTYPE_FILL: + { + ret_value = ecma_builtin_array_prototype_fill (arguments_list_p[0], + arguments_list_p[1], + arguments_list_p[2], + obj_p, + length); + break; + } + case ECMA_ARRAY_PROTOTYPE_INCLUDES: + { + ret_value = ecma_builtin_array_prototype_includes (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_FLAT: + { + ret_value = ecma_builtin_array_prototype_object_flat (arguments_list_p, arguments_number, obj_p, length); + break; + } + case ECMA_ARRAY_PROTOTYPE_FLATMAP: + { + ret_value = + ecma_builtin_array_prototype_object_flat_map (arguments_list_p[0], arguments_list_p[1], obj_p, length); + break; + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_ARRAY_PROTOTYPE_FILTER); + + ret_value = ecma_builtin_array_prototype_object_filter (arguments_list_p[0], arguments_list_p[1], obj_p, length); + break; + } + } + + ecma_free_value (len_value); + ecma_deref_object (obj_p); + + return ret_value; +} /* ecma_builtin_array_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h new file mode 100644 index 0000000..19110f7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h @@ -0,0 +1,85 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Array.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ARRAY + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.4.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 22.1.3.31 */ +OBJECT_VALUE (LIT_GLOBAL_SYMBOL_UNSCOPABLES, + ECMA_BUILTIN_ID_ARRAY_PROTOTYPE_UNSCOPABLES, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Number properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.4.4 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_WRITABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_ARRAY_PROTOTYPE_TO_LOCALE_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_CONCAT, ECMA_ARRAY_PROTOTYPE_CONCAT, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_JOIN, ECMA_ARRAY_PROTOTYPE_JOIN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_POP, ECMA_ARRAY_PROTOTYPE_POP, 0, 0) +ROUTINE (LIT_MAGIC_STRING_PUSH, ECMA_ARRAY_PROTOTYPE_PUSH, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_REVERSE, ECMA_ARRAY_PROTOTYPE_REVERSE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_SHIFT, ECMA_ARRAY_PROTOTYPE_SHIFT, 0, 0) +ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_ARRAY_PROTOTYPE_SLICE, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SORT, ECMA_ARRAY_PROTOTYPE_SORT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_AT, ECMA_ARRAY_PROTOTYPE_AT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SPLICE, ECMA_ARRAY_PROTOTYPE_SPLICE, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_UNSHIFT, ECMA_ARRAY_PROTOTYPE_UNSHIFT, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ECMA_ARRAY_PROTOTYPE_INDEX_OF, 2, 1) +ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ECMA_ARRAY_PROTOTYPE_LAST_INDEX_OF, NON_FIXED, 1) +/* Note these 3 routines must be in this order */ +ROUTINE (LIT_MAGIC_STRING_EVERY, ECMA_ARRAY_PROTOTYPE_EVERY, 2, 1) +ROUTINE (LIT_MAGIC_STRING_SOME, ECMA_ARRAY_PROTOTYPE_SOME, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_ARRAY_PROTOTYPE_FOR_EACH, 2, 1) +ROUTINE (LIT_MAGIC_STRING_MAP, ECMA_ARRAY_PROTOTYPE_MAP, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FILTER, ECMA_ARRAY_PROTOTYPE_FILTER, 2, 1) +/* Note these 2 routines must be in this order */ +ROUTINE (LIT_MAGIC_STRING_REDUCE, ECMA_ARRAY_PROTOTYPE_REDUCE, 2, 1) +ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ECMA_ARRAY_PROTOTYPE_REDUCE_RIGHT, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FIND, ECMA_ARRAY_PROTOTYPE_FIND, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FIND_INDEX, ECMA_ARRAY_PROTOTYPE_FIND_INDEX, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FILL, ECMA_ARRAY_PROTOTYPE_FILL, 3, 1) +ROUTINE (LIT_MAGIC_STRING_COPY_WITHIN, ECMA_ARRAY_PROTOTYPE_COPY_WITHIN, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_ARRAY_PROTOTYPE_ENTRIES, 0, 0) +ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_ARRAY_PROTOTYPE_KEYS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_INCLUDES, ECMA_ARRAY_PROTOTYPE_INCLUDES, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_FLAT, ECMA_ARRAY_PROTOTYPE_FLAT, 1, 0) +ROUTINE (LIT_MAGIC_STRING_FLATMAP, ECMA_ARRAY_PROTOTYPE_FLATMAP, 2, 1) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_STRING_UL, LIT_MAGIC_STRING_TO_STRING_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_VALUES, + LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, + LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ARRAY */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.cpp new file mode 100644 index 0000000..0d88411 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.cpp @@ -0,0 +1,569 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ARRAY_ROUTINE_START = 0, + ECMA_ARRAY_ROUTINE_IS_ARRAY, + ECMA_ARRAY_ROUTINE_FROM, + ECMA_ARRAY_ROUTINE_OF, + ECMA_ARRAY_ROUTINE_SPECIES_GET +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array.inc.h" +#define BUILTIN_UNDERSCORED_ID array +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup array ECMA Array object built-in + * @{ + */ + +/** + * The Array object's 'from' routine + * + * See also: + * ECMA-262 v6, 22.1.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_object_from (ecma_value_t this_arg, /**< 'this' argument */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + /* 1. */ + ecma_value_t constructor = this_arg; + ecma_value_t call_this_arg = ECMA_VALUE_UNDEFINED; + ecma_value_t items = arguments_list_p[0]; + ecma_value_t mapfn = (arguments_list_len > 1) ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED; + ecma_length_t k = 0; + ecma_value_t set_status; + + /* 2. */ + ecma_object_t *mapfn_obj_p = NULL; + + /* 3. */ + if (!ecma_is_value_undefined (mapfn)) + { + /* 3.a */ + if (!ecma_op_is_callable (mapfn)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + /* 3.b */ + if (arguments_list_len > 2) + { + call_this_arg = arguments_list_p[2]; + } + + /* 3.c */ + mapfn_obj_p = ecma_get_object_from_value (mapfn); + } + + /* 4. */ + ecma_value_t using_iterator = ecma_op_get_method_by_symbol_id (items, LIT_GLOBAL_SYMBOL_ITERATOR); + + /* 5. */ + if (ECMA_IS_VALUE_ERROR (using_iterator)) + { + return using_iterator; + } + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + + /* 6. */ + if (!ecma_is_value_undefined (using_iterator)) + { + ecma_object_t *array_obj_p; + + /* 6.a */ + if (ecma_is_constructor (constructor)) + { + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor); + + ecma_value_t array = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, NULL, 0); + + if (ecma_is_value_undefined (array) || ecma_is_value_null (array)) + { + ecma_free_value (using_iterator); + return ecma_raise_type_error (ECMA_ERR_CANNOT_CONVERT_TO_OBJECT); + } + + /* 6.c */ + if (ECMA_IS_VALUE_ERROR (array)) + { + ecma_free_value (using_iterator); + return array; + } + + array_obj_p = ecma_get_object_from_value (array); + } + else + { + /* 6.b */ + array_obj_p = ecma_op_new_array_object (0); + } + + /* 6.d */ + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (items, using_iterator, &next_method); + ecma_free_value (using_iterator); + + /* 6.e */ + if (ECMA_IS_VALUE_ERROR (iterator)) + { + ecma_deref_object (array_obj_p); + return iterator; + } + + /* 6.f */ + uint32_t k = 0; + + /* 6.g */ + while (true) + { + /* 6.g.ii */ + ecma_value_t next = ecma_op_iterator_step (iterator, next_method); + + /* 6.g.iii */ + if (ECMA_IS_VALUE_ERROR (next)) + { + goto iterator_cleanup; + } + + /* 6.g.iii */ + if (ecma_is_value_false (next)) + { + /* 6.g.iv.1 */ + ecma_value_t len_value = ecma_make_uint32_value (k); + ecma_value_t set_status = + ecma_op_object_put (array_obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), len_value, true); + ecma_free_value (len_value); + + /* 6.g.iv.2 */ + if (ECMA_IS_VALUE_ERROR (set_status)) + { + goto iterator_cleanup; + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + /* 6.g.iv.3 */ + return ecma_make_object_value (array_obj_p); + } + + /* 6.g.v */ + ecma_value_t next_value = ecma_op_iterator_value (next); + + ecma_free_value (next); + + /* 6.g.vi */ + if (ECMA_IS_VALUE_ERROR (next_value)) + { + goto iterator_cleanup; + } + + ecma_value_t mapped_value; + /* 6.g.vii */ + if (mapfn_obj_p != NULL) + { + /* 6.g.vii.1 */ + ecma_value_t args_p[2] = { next_value, ecma_make_uint32_value (k) }; + /* 6.g.vii.3 */ + mapped_value = ecma_op_function_call (mapfn_obj_p, call_this_arg, args_p, 2); + ecma_free_value (args_p[1]); + ecma_free_value (next_value); + + /* 6.g.vii.2 */ + if (ECMA_IS_VALUE_ERROR (mapped_value)) + { + ecma_op_iterator_close (iterator); + goto iterator_cleanup; + } + } + else + { + /* 6.g.viii */ + mapped_value = next_value; + } + + /* 6.g.ix */ + const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + ecma_value_t set_status = ecma_builtin_helper_def_prop_by_index (array_obj_p, k, mapped_value, flags); + + ecma_free_value (mapped_value); + + /* 6.g.x */ + if (ECMA_IS_VALUE_ERROR (set_status)) + { + ecma_op_iterator_close (iterator); + goto iterator_cleanup; + } + + /* 6.g.xi */ + k++; + } + +iterator_cleanup: + ecma_free_value (iterator); + ecma_free_value (next_method); + ecma_deref_object (array_obj_p); + + return ret_value; + } + + /* 8. */ + ecma_value_t array_like = ecma_op_to_object (items); + + /* 9. */ + if (ECMA_IS_VALUE_ERROR (array_like)) + { + return array_like; + } + + ecma_object_t *array_like_obj_p = ecma_get_object_from_value (array_like); + + /* 10. */ + ecma_length_t len; + ecma_value_t len_value = ecma_op_object_get_length (array_like_obj_p, &len); + + /* 11. */ + if (ECMA_IS_VALUE_ERROR (len_value)) + { + goto cleanup; + } + + /* 12. */ + ecma_object_t *array_obj_p; + + /* 12.a */ + if (ecma_is_constructor (constructor)) + { + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor); + + len_value = ecma_make_length_value (len); + ecma_value_t array = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, &len_value, 1); + ecma_free_value (len_value); + + if (ecma_is_value_undefined (array) || ecma_is_value_null (array)) + { + ecma_raise_type_error (ECMA_ERR_CANNOT_CONVERT_TO_OBJECT); + goto cleanup; + } + + /* 14. */ + if (ECMA_IS_VALUE_ERROR (array)) + { + goto cleanup; + } + + array_obj_p = ecma_get_object_from_value (array); + } + else + { + /* 13.a */ + array_obj_p = ecma_op_new_array_object_from_length (len); + + if (JERRY_UNLIKELY (array_obj_p == NULL)) + { + goto cleanup; + } + } + + /* 15. */ + k = 0; + + /* 16. */ + while (k < len) + { + /* 16.b */ + ecma_value_t k_value = ecma_op_object_get_by_index (array_like_obj_p, k); + + /* 16.c */ + if (ECMA_IS_VALUE_ERROR (k_value)) + { + goto construct_cleanup; + } + + ecma_value_t mapped_value; + /* 16.d */ + if (mapfn_obj_p != NULL) + { + /* 16.d.i */ + ecma_value_t args_p[2] = { k_value, ecma_make_length_value (k) }; + mapped_value = ecma_op_function_call (mapfn_obj_p, call_this_arg, args_p, 2); + ecma_free_value (args_p[1]); + ecma_free_value (k_value); + + /* 16.d.ii */ + if (ECMA_IS_VALUE_ERROR (mapped_value)) + { + goto construct_cleanup; + } + } + else + { + /* 16.e */ + mapped_value = k_value; + } + + /* 16.f */ + const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + ecma_value_t set_status = ecma_builtin_helper_def_prop_by_index (array_obj_p, k, mapped_value, flags); + + ecma_free_value (mapped_value); + + /* 16.g */ + if (ECMA_IS_VALUE_ERROR (set_status)) + { + goto construct_cleanup; + } + + /* 16.h */ + k++; + } + + /* 17. */ + len_value = ecma_make_length_value (k); + set_status = ecma_op_object_put (array_obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), len_value, true); + ecma_free_value (len_value); + + /* 18. */ + if (ECMA_IS_VALUE_ERROR (set_status)) + { + goto construct_cleanup; + } + + /* 19. */ + ecma_deref_object (array_like_obj_p); + return ecma_make_object_value (array_obj_p); + +construct_cleanup: + ecma_deref_object (array_obj_p); +cleanup: + ecma_deref_object (array_like_obj_p); + return ret_value; +} /* ecma_builtin_array_object_from */ + +/** + * The Array object's 'of' routine + * + * See also: + * ECMA-262 v6, 22.1.2.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_array_object_of (ecma_value_t this_arg, /**< 'this' argument */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + if (!ecma_is_constructor (this_arg)) + { + return ecma_op_new_array_object_from_buffer (arguments_list_p, arguments_list_len); + } + + ecma_value_t len = ecma_make_uint32_value (arguments_list_len); + + ecma_value_t ret_val = + ecma_op_function_construct (ecma_get_object_from_value (this_arg), ecma_get_object_from_value (this_arg), &len, 1); + + if (ECMA_IS_VALUE_ERROR (ret_val)) + { + ecma_free_value (len); + return ret_val; + } + + uint32_t k = 0; + ecma_object_t *obj_p = ecma_get_object_from_value (ret_val); + const uint32_t prop_status_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + + while (k < arguments_list_len) + { + ecma_value_t define_status = + ecma_builtin_helper_def_prop_by_index (obj_p, k, arguments_list_p[k], prop_status_flags); + + if (ECMA_IS_VALUE_ERROR (define_status)) + { + ecma_free_value (len); + ecma_deref_object (obj_p); + return define_status; + } + + k++; + } + + ret_val = ecma_op_object_put (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), len, true); + + ecma_free_value (len); + + if (ECMA_IS_VALUE_ERROR (ret_val)) + { + ecma_deref_object (obj_p); + return ret_val; + } + + return ecma_make_object_value (obj_p); +} /* ecma_builtin_array_object_of */ + +/** + * Handle calling [[Call]] of built-in Array object + * + * @return ECMA_VALUE_ERROR - if the array construction fails + * constructed array object - otherwise + */ +ecma_value_t +ecma_builtin_array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len != 1 || !ecma_is_value_number (arguments_list_p[0])) + { + return ecma_op_new_array_object_from_buffer (arguments_list_p, arguments_list_len); + } + + ecma_number_t num = ecma_get_number_from_value (arguments_list_p[0]); + uint32_t num_uint32 = ecma_number_to_uint32 (num); + + if (num != ((ecma_number_t) num_uint32)) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_ARRAY_LENGTH); + } + + return ecma_make_object_value (ecma_op_new_array_object (num_uint32)); +} /* ecma_builtin_array_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Array object + * + * @return ECMA_VALUE_ERROR - if the array construction fails + * constructed array object - otherwise + */ +ecma_value_t +ecma_builtin_array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_object_t *proto_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_ARRAY_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_array_dispatch_call (arguments_list_p, arguments_list_len); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (proto_p); + return result; + } + + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + ecma_deref_object (proto_p); + return result; +} /* ecma_builtin_array_dispatch_construct */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_array_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + switch (builtin_routine_id) + { + case ECMA_ARRAY_ROUTINE_IS_ARRAY: + { + JERRY_UNUSED (this_arg); + + return ecma_is_value_array (arguments_list_p[0]); + } + case ECMA_ARRAY_ROUTINE_FROM: + { + return ecma_builtin_array_object_from (this_arg, arguments_list_p, arguments_number); + } + case ECMA_ARRAY_ROUTINE_OF: + { + return ecma_builtin_array_object_of (this_arg, arguments_list_p, arguments_number); + } + case ECMA_ARRAY_ROUTINE_SPECIES_GET: + { + return ecma_copy_value (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_array_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h new file mode 100644 index 0000000..bf43da9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h @@ -0,0 +1,47 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Array description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ARRAY + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.4.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_ARRAY_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* Number properties: + * (property name, object pointer getter) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ARRAY_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ECMA_ARRAY_ROUTINE_IS_ARRAY, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FROM, ECMA_ARRAY_ROUTINE_FROM, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_OF, ECMA_ARRAY_ROUTINE_OF, NON_FIXED, 0) + +/* ECMA-262 v6, 22.1.2.5 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ECMA_ARRAY_ROUTINE_SPECIES_GET, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* !(JERRY_BUILTIN_ARRAY) */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.cpp new file mode 100644 index 0000000..3e47e06 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.cpp @@ -0,0 +1,116 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jrt-libc-includes.h" +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID arraybuffer_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup arraybufferprototype ECMA ArrayBuffer.prototype object built-in + * @{ + */ + +/** + * The ArrayBuffer.prototype.bytelength accessor + * + * See also: + * ES2015, 24.1.4.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)) + { + if (ecma_arraybuffer_is_detached (object_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + uint32_t len = ecma_arraybuffer_get_length (object_p); + + return ecma_make_uint32_value (len); + } + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ARRAY_BUFFER_OBJECT); +} /* ecma_builtin_arraybuffer_prototype_bytelength_getter */ + +/** + * The ArrayBuffer.prototype object's 'slice' routine + * + * See also: + * ECMA-262 v11, 24.1.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< this argument */ + const ecma_value_t *argument_list_p, /**< arguments list */ + uint32_t arguments_number) /**< number of arguments */ +{ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + /* 2. */ + if (!ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ARRAY_BUFFER_OBJECT); + } + + return ecma_builtin_arraybuffer_slice (this_arg, argument_list_p, arguments_number); +} /* ecma_builtin_arraybuffer_prototype_object_slice */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h new file mode 100644 index 0000000..8046344 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * ArrayBuffer.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ARRAYBUFFER, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Readonly accessor properties */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL, + ecma_builtin_arraybuffer_prototype_bytelength_getter, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 24.1.4.4 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ARRAY_BUFFER_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, NON_FIXED, 2) + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.cpp new file mode 100644 index 0000000..27590f4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.cpp @@ -0,0 +1,114 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" +#include "ecma-builtins.h" +#include "ecma-dataview-object.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer.inc.h" +#define BUILTIN_UNDERSCORED_ID arraybuffer +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup arraybuffer ECMA ArrayBuffer object built-in + * @{ + */ + +/** + * The ArrayBuffer object's 'isView' routine + * + * See also: + * ES2015 24.1.3.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argument */ + ecma_value_t arg) /**< argument 1 */ +{ + JERRY_UNUSED (this_arg); + + return ecma_make_boolean_value (ecma_is_typedarray (arg)); +} /* ecma_builtin_arraybuffer_object_is_view */ + +/** + * Handle calling [[Call]] of built-in ArrayBuffer object + * + * ES2015 24.1.2 ArrayBuffer is not intended to be called as + * a function and will throw an exception when called in + * that manner. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_ARRAYBUFFER_REQUIRES_NEW); +} /* ecma_builtin_arraybuffer_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in ArrayBuffer object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_arraybuffer_object (arguments_list_p, arguments_list_len); +} /* ecma_builtin_arraybuffer_dispatch_construct */ + +/** + * 24.1.3.3 get ArrayBuffer [ @@species ] accessor + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */ +{ + return ecma_copy_value (this_value); +} /* ecma_builtin_arraybuffer_species_get */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h new file mode 100644 index 0000000..6fe1a93 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h @@ -0,0 +1,47 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * ArrayBuffer built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ARRAY_BUFFER_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ + +/* ES2015 24.1.3.1 */ +ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1) + +/* ES2015 24.1.3.3 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ecma_builtin_arraybuffer_species_get, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-from-sync-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-from-sync-iterator-prototype.cpp new file mode 100644 index 0000000..b012944 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-from-sync-iterator-prototype.cpp @@ -0,0 +1,355 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jerryscript-types.h" + +#include "ecma-builtin-handlers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" + +#include "jcontext.h" +#include "jrt.h" +#include "lit-magic-strings.h" +#include "lit-strings.h" +#include "opcodes.h" +#include "vm-defines.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_START = 0, /**< builtin routine start id */ + ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_NEXT, /**< 'next' routine v11, 25.1.4.2.1 */ + ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_RETURN, /**< 'return' routine v11, 25.1.4.2.2 */ + ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_THROW /**< 'throw' routine v11, 25.1.4.2.3 */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-from-sync-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID async_from_sync_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup asyncfromsynciteratorprototype ECMA %AsyncFromSyncIteratorPrototype% object built-in + * @{ + */ + +/** + * AsyncFromSyncIteratorContinuation operation + * + * See also: + * ECMAScript v11, 25.1.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_op_async_from_sync_iterator_prototype_continuation (ecma_value_t result, /**< routine's 'result' argument */ + ecma_object_t *capability_obj_p) /**< promise capability */ +{ + /* 1. */ + ecma_value_t done = ecma_op_iterator_complete (result); + + /* 2. */ + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&done, capability_obj_p))) + { + return done; + } + + uint16_t done_flag = ecma_is_value_false (done) ? 0 : (1 << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT); + ecma_free_value (done); + + /* 3. */ + ecma_value_t value = ecma_op_iterator_value (result); + + /* 4. */ + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&value, capability_obj_p))) + { + return value; + } + + /* 5. */ + ecma_value_t builtin_promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE)); + ecma_value_t value_wrapper = ecma_promise_reject_or_resolve (builtin_promise, value, true); + ecma_free_value (value); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&value_wrapper, capability_obj_p))) + { + return value_wrapper; + } + + /* 8 - 9. */ + ecma_object_t *on_fulfilled = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_ASYNC_FROM_SYNC_ITERATOR_UNWRAP, + sizeof (ecma_extended_object_t)); + ((ecma_extended_object_t *) on_fulfilled)->u.built_in.u2.routine_flags = (uint8_t) done_flag; + + /* 10. */ + ecma_value_t then_result = ecma_promise_perform_then (value_wrapper, + ecma_make_object_value (on_fulfilled), + ECMA_VALUE_UNDEFINED, + capability_obj_p); + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (then_result)); + ecma_deref_object (on_fulfilled); + ecma_free_value (value_wrapper); + + /* 11. */ + return then_result; +} /* ecma_op_async_from_sync_iterator_prototype_continuation */ + +/** + * The %AsyncFromSyncIteratorPrototype% object's 'next' routine + * + * See also: + * ECMAScript v11, 25.1.4.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_async_from_sync_iterator_prototype_next (ecma_async_from_sync_iterator_object_t *iter_p, /**< iterator + * record*/ + ecma_object_t *capability_p, /**< promise capability */ + ecma_value_t value) /**< routine's 'value' argument */ +{ + /* 5. */ + ecma_value_t next_result = + ecma_op_iterator_next (iter_p->header.u.cls.u3.sync_iterator, iter_p->sync_next_method, value); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&next_result, capability_p))) + { + return next_result; + } + + /* 7. */ + ecma_value_t result = ecma_op_async_from_sync_iterator_prototype_continuation (next_result, capability_p); + ecma_free_value (next_result); + + return result; +} /* ecma_builtin_async_from_sync_iterator_prototype_next */ + +/** + * The %AsyncFromSyncIteratorPrototype% object's 'return' and 'throw' routines + * + * See also: + * ECMAScript v11, 25.1.4.2.2 + * ECMAScript v11, 25.1.4.2.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_async_from_sync_iterator_prototype_do (ecma_async_from_sync_iterator_object_t *iter_p, /**< iterator + * record*/ + ecma_object_t *capability_obj_p, /**< promise capability */ + ecma_value_t value, /**< routine's 'value' argument */ + lit_magic_string_id_t method_id) /**< method id */ +{ + /* 5. */ + ecma_value_t sync_iterator = iter_p->header.u.cls.u3.sync_iterator; + ecma_value_t method = ecma_op_get_method_by_magic_id (sync_iterator, method_id); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&method, capability_obj_p))) + { + return method; + } + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + + ecma_value_t call_arg; + uint32_t arg_size; + + if (ecma_is_value_empty (value)) + { + arg_size = 0; + call_arg = ECMA_VALUE_UNDEFINED; + } + else + { + arg_size = 1; + call_arg = value; + } + + /* 7. */ + if (ecma_is_value_undefined (method)) + { + ecma_value_t func_obj; + + if (method_id == LIT_MAGIC_STRING_RETURN) + { + /* 7.a. */ + call_arg = ecma_create_iter_result_object (call_arg, ECMA_VALUE_TRUE); + arg_size = 1; + func_obj = capability_p->resolve; + } + else + { + func_obj = capability_p->reject; + } + + /* 7.b. */ + ecma_value_t resolve = + ecma_op_function_call (ecma_get_object_from_value (func_obj), ECMA_VALUE_UNDEFINED, &call_arg, arg_size); + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (resolve)); + ecma_free_value (resolve); + + if (method_id == LIT_MAGIC_STRING_RETURN) + { + ecma_free_value (call_arg); + } + + /* 7.c. */ + return ecma_copy_value (capability_p->header.u.cls.u3.promise); + } + + /* 8. */ + ecma_value_t call_result = ecma_op_function_validated_call (method, sync_iterator, &call_arg, arg_size); + ecma_free_value (method); + + /* 9. */ + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&call_result, capability_obj_p))) + { + return call_result; + } + + /* 10. */ + if (!ecma_is_value_object (call_result)) + { + ecma_free_value (call_result); + +#if JERRY_ERROR_MESSAGES + const lit_utf8_byte_t *msg_p = (lit_utf8_byte_t *) ecma_get_error_msg (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + lit_utf8_size_t msg_size = ecma_get_error_size (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + ecma_string_t *error_msg_p = ecma_new_ecma_string_from_ascii (msg_p, msg_size); +#else /* !JERRY_ERROR_MESSAGES */ + ecma_string_t *error_msg_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + + ecma_object_t *type_error_obj_p = ecma_new_standard_error (JERRY_ERROR_TYPE, error_msg_p); + +#if JERRY_ERROR_MESSAGES + ecma_deref_ecma_string (error_msg_p); +#endif /* JERRY_ERROR_MESSAGES */ + + ecma_value_t type_error = ecma_make_object_value (type_error_obj_p); + + /* 10.a. */ + ecma_value_t reject = + ecma_op_function_call (ecma_get_object_from_value (capability_p->reject), ECMA_VALUE_UNDEFINED, &type_error, 1); + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (reject)); + ecma_deref_object (type_error_obj_p); + ecma_free_value (reject); + + /* 10.b. */ + return ecma_copy_value (capability_p->header.u.cls.u3.promise); + } + + ecma_value_t result = ecma_op_async_from_sync_iterator_prototype_continuation (call_result, capability_obj_p); + ecma_free_value (call_result); + + return result; +} /* ecma_builtin_async_from_sync_iterator_prototype_do */ + +/** + * Dispatcher of the %AsyncFromSyncIteratorPrototype% built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_async_from_sync_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + * routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of + * arguments + * passed to + * routine */ + uint32_t arguments_number) /**< length of + * arguments' list */ +{ + JERRY_UNUSED (arguments_number); + JERRY_ASSERT (ecma_is_value_object (this_arg)); + + ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg); + + JERRY_ASSERT (ecma_object_class_is (this_obj_p, ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR)); + + ecma_async_from_sync_iterator_object_t *iter_p = (ecma_async_from_sync_iterator_object_t *) this_obj_p; + + ecma_value_t builtin_promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE)); + ecma_object_t *capability_p = ecma_promise_new_capability (builtin_promise, ECMA_VALUE_UNDEFINED); + JERRY_ASSERT (capability_p != NULL); + + ecma_value_t result; + ecma_value_t arg = (arguments_number == 0 ? ECMA_VALUE_EMPTY : arguments_list_p[0]); + + switch (builtin_routine_id) + { + case ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_NEXT: + { + result = ecma_builtin_async_from_sync_iterator_prototype_next (iter_p, capability_p, arg); + break; + } + case ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_RETURN: + { + result = ecma_builtin_async_from_sync_iterator_prototype_do (iter_p, capability_p, arg, LIT_MAGIC_STRING_RETURN); + break; + } + case ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_THROW: + { + result = ecma_builtin_async_from_sync_iterator_prototype_do (iter_p, capability_p, arg, LIT_MAGIC_STRING_THROW); + break; + } + default: + { + JERRY_UNREACHABLE (); + break; + } + } + + ecma_deref_object (capability_p); + + return result; +} /* ecma_builtin_async_from_sync_iterator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-from-sync-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-from-sync-iterator-prototype.inc.h new file mode 100644 index 0000000..7c5e9c3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-from-sync-iterator-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %AsyncFromSyncIteratorPrototype% built-in description (AsyncFunction.prototype) + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_NEXT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_RETURN, ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_RETURN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_THROW, ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_THROW, 1, 1) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function-prototype.cpp new file mode 100644 index 0000000..6be0c16 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function-prototype.cpp @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-function-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID async_function_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup asyncfunctionprototype ECMA AsyncFunction.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function-prototype.inc.h new file mode 100644 index 0000000..e4388d3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %AsyncFunctionPrototype% built-in description (AsyncFunction.prototype) + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ECMA-262 v11, 25.7.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ASYNC_FUNCTION, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v11, 25.7.3.2 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ASYNC_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function.cpp new file mode 100644 index 0000000..de1a7db --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function.cpp @@ -0,0 +1,68 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" +#include "ecma-function-object.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-function.inc.h" +#define BUILTIN_UNDERSCORED_ID async_function +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup asyncfunction ECMA AsyncFunction object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in AsyncFunction object + * + * @return constructed async function object - if success + * raised error otherwise + */ +ecma_value_t +ecma_builtin_async_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_dynamic_function (arguments_list_p, arguments_list_len, ECMA_PARSE_ASYNC_FUNCTION); +} /* ecma_builtin_async_function_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in AsyncFunction object + * + * @return constructed async function object - if success + * raised error otherwise + */ +ecma_value_t +ecma_builtin_async_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_async_function_dispatch_call (arguments_list_p, arguments_list_len); +} /* ecma_builtin_async_function_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function.inc.h new file mode 100644 index 0000000..0fe50ae --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-function.inc.h @@ -0,0 +1,34 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %AsyncFunction% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ECMA-262 v11, 25.7.2 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ASYNC_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v11, 25.7.2.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v10, 25.7.2.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v11, 25.7.3.2 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ASYNC_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-function.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-function.cpp new file mode 100644 index 0000000..18ad25e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-function.cpp @@ -0,0 +1,70 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" +#include "ecma-function-object.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-generator-function.inc.h" +#define BUILTIN_UNDERSCORED_ID async_generator_function +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup asyncgeneratorfunction ECMA AsyncGeneratorFunction object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in AsyncGeneratorFunction object + * + * @return constructed async generator function object - if success + * raised error otherwise + */ +ecma_value_t +ecma_builtin_async_generator_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_dynamic_function (arguments_list_p, + arguments_list_len, + (ecma_parse_opts_t)(((unsigned int) ECMA_PARSE_GENERATOR_FUNCTION) | ((unsigned int) ECMA_PARSE_ASYNC_FUNCTION))); +} /* ecma_builtin_async_generator_function_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in AsyncGeneratorFunction object + * + * @return constructed async generator function object - if success + * raised error otherwise + */ +ecma_value_t +ecma_builtin_async_generator_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_async_generator_function_dispatch_call (arguments_list_p, arguments_list_len); +} /* ecma_builtin_async_generator_function_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-function.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-function.inc.h new file mode 100644 index 0000000..edc88c7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-function.inc.h @@ -0,0 +1,31 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %AsyncGeneratorFunction% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ECMA-262 v10, 25.3.2 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ASYNC_GENERATOR_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v10, 25.3.2.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.3.2.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_ASYNC_GENERATOR, ECMA_PROPERTY_FIXED) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.cpp new file mode 100644 index 0000000..3ea9dea --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.cpp @@ -0,0 +1,147 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-async-generator-object.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-promise-object.h" + +#include "jcontext.h" +#include "opcodes.h" +#include "vm-defines.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_NEXT, + ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_THROW, + ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_RETURN +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-generator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID async_generator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup asyncgeneratorprototype ECMA AsyncGenerator.prototype object built-in + * @{ + */ + +/** + * Convert routine type to operation type. + */ +#define ECMA_ASYNC_GENERATOR_ROUTINE_TO_OPERATION(type) \ + ((ecma_async_generator_operation_type_t) ((type) -ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_NEXT)) + +JERRY_STATIC_ASSERT ((ECMA_ASYNC_GENERATOR_ROUTINE_TO_OPERATION (ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_NEXT) == ECMA_ASYNC_GENERATOR_DO_NEXT), + convert_ecma_async_generator_routine_next_to_ecma_async_generator_do_next_failed); + +JERRY_STATIC_ASSERT ((ECMA_ASYNC_GENERATOR_ROUTINE_TO_OPERATION (ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_THROW) == ECMA_ASYNC_GENERATOR_DO_THROW), + convert_ecma_async_generator_routine_throw_to_ecma_async_generator_do_throw_failed); + +JERRY_STATIC_ASSERT ((ECMA_ASYNC_GENERATOR_ROUTINE_TO_OPERATION (ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_RETURN) == ECMA_ASYNC_GENERATOR_DO_RETURN), + convert_ecma_async_generator_routine_return_to_ecma_async_generator_do_return_failed); + +/** + * Dispatcher of the Generator built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_async_generator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to + * routine */ + uint32_t arguments_number) /**< length of arguments' + * list */ +{ + JERRY_UNUSED (arguments_number); + + vm_executable_object_t *executable_object_p = NULL; + + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ASYNC_GENERATOR)) + { + executable_object_p = (vm_executable_object_t *) object_p; + } + } + + if (executable_object_p == NULL) + { + const char *msg_p = ecma_get_error_msg (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR); + lit_utf8_size_t msg_size = ecma_get_error_size (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR); + ecma_string_t *error_msg_p = ecma_new_ecma_string_from_ascii ((const lit_utf8_byte_t *) msg_p, msg_size); + + ecma_object_t *type_error_obj_p = ecma_new_standard_error (JERRY_ERROR_TYPE, error_msg_p); + ecma_deref_ecma_string (error_msg_p); + + ecma_value_t promise = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL); + ecma_reject_promise (promise, ecma_make_object_value (type_error_obj_p)); + ecma_deref_object (type_error_obj_p); + + return promise; + } + + if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED) + { + ecma_value_t promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE)); + + if (JERRY_UNLIKELY (builtin_routine_id == ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_THROW)) + { + return ecma_promise_reject_or_resolve (promise, arguments_list_p[0], false); + } + + ecma_value_t iter_result = ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + ecma_value_t result = ecma_promise_reject_or_resolve (promise, iter_result, true); + ecma_free_value (iter_result); + return result; + } + + return ecma_async_generator_enqueue (executable_object_p, + ECMA_ASYNC_GENERATOR_ROUTINE_TO_OPERATION (builtin_routine_id), + arguments_list_p[0]); +} /* ecma_builtin_async_generator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.inc.h new file mode 100644 index 0000000..dcad1c6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.inc.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * AsyncGenerator.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 25.3.1.5 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ASYNC_GENERATOR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.2.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ASYNC_GENERATOR, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_NEXT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_RETURN, ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_RETURN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_THROW, ECMA_ASYNC_GENERATOR_PROTOTYPE_ROUTINE_THROW, 1, 1) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator.cpp new file mode 100644 index 0000000..4693742 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator.cpp @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-generator.inc.h" +#define BUILTIN_UNDERSCORED_ID async_generator +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup asyncgenerator ECMA AsyncGenerator object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator.inc.h new file mode 100644 index 0000000..a856cbb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-generator.inc.h @@ -0,0 +1,33 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %AsyncGenerator% built-in description (AsyncGeneratorFunction.prototype) + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ECMA-262 v6, 25.3.2.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.3.2.3.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.3.2.3.3 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, + LIT_MAGIC_STRING_ASYNC_GENERATOR_FUNCTION_UL, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-iterator-prototype.cpp new file mode 100644 index 0000000..28579fe --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-iterator-prototype.cpp @@ -0,0 +1,103 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-iterator-object.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_ASYNC_ITERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_BUILTIN_ASYNC_ITERATOR_PROTOTYPE_OBJECT_ASYNC_ITERATOR, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID async_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %asynciteratorprototype% ECMA %AsyncIteratorPrototype% object built-in + * @{ + */ + +/** + * The %AsyncIteratorPrototype% object's '@@asyncIterator' routine + * + * See also: + * ECMA-262 v10, 25.1.3.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return the given this value + */ +static ecma_value_t +ecma_builtin_async_iterator_prototype_object_async_iterator (ecma_value_t this_val) /**< this argument */ +{ + /* 1. */ + return ecma_copy_value (this_val); +} /* ecma_builtin_async_iterator_prototype_object_async_iterator */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_async_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + * routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< + * list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list_p, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_ASYNC_ITERATOR_PROTOTYPE_OBJECT_ASYNC_ITERATOR: + { + return ecma_builtin_async_iterator_prototype_object_async_iterator (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_async_iterator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-iterator-prototype.inc.h new file mode 100644 index 0000000..53d43d0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-async-iterator-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %AsyncIteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, ECMA_BUILTIN_ASYNC_ITERATOR_PROTOTYPE_OBJECT_ASYNC_ITERATOR, 0, 0) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-atomics.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-atomics.cpp new file mode 100644 index 0000000..c7d1847 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-atomics.cpp @@ -0,0 +1,260 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-atomics-object.h" +#include "ecma-builtins.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ATOMICS + +#define ECMA_BUILTINS_INTERNAL + +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ATOMICS_ROUTINE_START = 0, /**< Special value, should be ignored */ + ECMA_ATOMICS_ROUTINE_ADD, /**< Atomics add routine */ + ECMA_ATOMICS_ROUTINE_AND, /**< Atomics and routine */ + ECMA_ATOMICS_ROUTINE_COMPAREEXCHANGE, /**< Atomics compare exchange routine */ + ECMA_ATOMICS_ROUTINE_EXCHANGE, /**< Atomics exchange routine */ + ECMA_ATOMICS_ROUTINE_ISLOCKFREE, /**< Atomics is lock free routine */ + ECMA_ATOMICS_ROUTINE_LOAD, /**< Atomics load routine */ + ECMA_ATOMICS_ROUTINE_OR, /**< Atomics or routine */ + ECMA_ATOMICS_ROUTINE_STORE, /**< Atomics store routine */ + ECMA_ATOMICS_ROUTINE_SUB, /**< Atomics sub routine */ + ECMA_ATOMICS_ROUTINE_WAIT, /**< Atomics wait routine */ + ECMA_ATOMICS_ROUTINE_NOTIFY, /**< Atomics notify routine */ + ECMA_ATOMICS_ROUTINE_XOR, /**< Atomics xor routine */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-atomics.inc.h" +#define BUILTIN_UNDERSCORED_ID atomics + +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup atomics ECMA Atomics object built-in + * @{ + */ + +/** + * The Atomics object's 'compareExchange' routine + * + * See also: ES11 24.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_atomics_compare_exchange (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t index, /**< index argument */ + ecma_value_t expected_value, /**< expectedValue argument */ + ecma_value_t replacement_value) /**< replacementValue argument*/ +{ + JERRY_UNUSED (typedarray); + JERRY_UNUSED (index); + JERRY_UNUSED (expected_value); + JERRY_UNUSED (replacement_value); + + return ecma_make_uint32_value (0); +} /* ecma_builtin_atomics_compare_exchange */ + +/** + * The Atomics object's 'isLockFree' routine + * + * See also: ES11 24.4.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_atomics_is_lock_free (ecma_value_t size) /**< size argument */ +{ + JERRY_UNUSED (size); + + return ECMA_VALUE_FALSE; +} /* ecma_builtin_atomics_is_lock_free */ + +/** + * The Atomics object's 'store' routine + * + * See also: ES11 24.4.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_atomics_store (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t index, /**< index argument */ + ecma_value_t value) /**< value argument */ +{ + JERRY_UNUSED (typedarray); + JERRY_UNUSED (index); + JERRY_UNUSED (value); + + return ecma_make_uint32_value (0); +} /* ecma_builtin_atomics_store */ + +/** + * The Atomics object's 'wait' routine + * + * See also: ES11 24.4.11 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_atomics_wait (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t index, /**< index argument */ + ecma_value_t value, /**< value argument */ + ecma_value_t timeout) /**< timeout argument */ +{ + JERRY_UNUSED (typedarray); + JERRY_UNUSED (index); + JERRY_UNUSED (value); + JERRY_UNUSED (timeout); + + return ecma_make_uint32_value (0); +} /* ecma_builtin_atomics_wait */ + +/** + * The Atomics object's 'notify' routine + * + * See also: ES11 24.4.12 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_atomics_notify (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t index, /**< index argument */ + ecma_value_t count) /**< count argument */ +{ + JERRY_UNUSED (typedarray); + JERRY_UNUSED (index); + JERRY_UNUSED (count); + + return ecma_make_uint32_value (0); +} /* ecma_builtin_atomics_notify */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_atomics_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (this_arg); + ecma_value_t arg1 = arguments_list_p[0]; + ecma_value_t arg2 = arguments_list_p[1]; + ecma_value_t arg3 = arguments_list_p[2]; + ecma_value_t arg4 = (arguments_number > 3) ? arguments_list_p[3] : ECMA_VALUE_UNDEFINED; + + ecma_atomics_op_t type; + + switch (builtin_routine_id) + { + case ECMA_ATOMICS_ROUTINE_ADD: + { + type = ECMA_ATOMICS_ADD; + break; + } + case ECMA_ATOMICS_ROUTINE_AND: + { + type = ECMA_ATOMICS_AND; + break; + } + case ECMA_ATOMICS_ROUTINE_COMPAREEXCHANGE: + { + return ecma_builtin_atomics_compare_exchange (arg1, arg2, arg3, arg4); + } + case ECMA_ATOMICS_ROUTINE_EXCHANGE: + { + type = ECMA_ATOMICS_EXCHANGE; + break; + } + case ECMA_ATOMICS_ROUTINE_ISLOCKFREE: + { + return ecma_builtin_atomics_is_lock_free (arg1); + } + case ECMA_ATOMICS_ROUTINE_LOAD: + { + return ecma_atomic_load (arg1, arg2); + } + case ECMA_ATOMICS_ROUTINE_OR: + { + type = ECMA_ATOMICS_OR; + break; + } + case ECMA_ATOMICS_ROUTINE_STORE: + { + return ecma_builtin_atomics_store (arg1, arg2, arg3); + } + case ECMA_ATOMICS_ROUTINE_SUB: + { + type = ECMA_ATOMICS_SUBTRACT; + break; + } + case ECMA_ATOMICS_ROUTINE_WAIT: + { + return ecma_builtin_atomics_wait (arg1, arg2, arg3, arg4); + } + case ECMA_ATOMICS_ROUTINE_NOTIFY: + { + return ecma_builtin_atomics_notify (arg1, arg2, arg3); + } + case ECMA_ATOMICS_ROUTINE_XOR: + { + type = ECMA_ATOMICS_XOR; + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + return ecma_atomic_read_modify_write (arg1, arg2, arg3, type); +} /* ecma_builtin_atomics_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ATOMICS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-atomics.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-atomics.inc.h new file mode 100644 index 0000000..a11b451 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-atomics.inc.h @@ -0,0 +1,44 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Atomics built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ATOMICS + +/* ECMA-262 v11, 24.4.14 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ATOMICS_U, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_ADD, ECMA_ATOMICS_ROUTINE_ADD, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_AND, ECMA_ATOMICS_ROUTINE_AND, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_COMPAREEXCHANGE, ECMA_ATOMICS_ROUTINE_COMPAREEXCHANGE, 4, 4) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_EXCHANGE, ECMA_ATOMICS_ROUTINE_EXCHANGE, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_ISLOCKFREE, ECMA_ATOMICS_ROUTINE_ISLOCKFREE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_LOAD, ECMA_ATOMICS_ROUTINE_LOAD, 2, 2) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_OR, ECMA_ATOMICS_ROUTINE_OR, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_STORE, ECMA_ATOMICS_ROUTINE_STORE, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_SUB, ECMA_ATOMICS_ROUTINE_SUB, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_WAIT, ECMA_ATOMICS_ROUTINE_WAIT, 4, 4) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_NOTIFY, ECMA_ATOMICS_ROUTINE_NOTIFY, 3, 3) +ROUTINE (LIT_MAGIC_STRING_ATOMICS_XOR, ECMA_ATOMICS_ROUTINE_XOR, 3, 3) + +#endif /* JERRY_BUILTIN_ATOMICS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint-prototype.cpp new file mode 100644 index 0000000..e421855 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint-prototype.cpp @@ -0,0 +1,186 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-bigint.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_BIGINT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BIGINT_PROTOTYPE_ROUTINE_START = 0, + ECMA_BIGINT_PROTOTYPE_VALUE_OF, + ECMA_BIGINT_PROTOTYPE_TO_STRING, + ECMA_BIGINT_PROTOTYPE_TO_LOCALE_STRING, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-bigint-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID bigint_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup bigint ECMA BigInt object built-in + * @{ + */ + +/** + * The BigInt.prototype object's 'valueOf' routine + * + * See also: + * ECMA-262 v11, 20.2.3.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_bigint_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_bigint (this_arg)) + { + return ecma_copy_value (this_arg); + } + + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_BIGINT)) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (ecma_is_value_bigint (ext_object_p->u.cls.u3.value)); + + return ecma_copy_value (ext_object_p->u.cls.u3.value); + } + } + + return ecma_raise_type_error (ECMA_ERR_BIGINT_VALUE_EXPECTED); +} /* ecma_builtin_bigint_prototype_object_value_of */ + +/** + * The BigInt.prototype object's 'toString' routine + * + * See also: + * ECMA-262 v11, 20.2.3.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_bigint_prototype_object_to_string (ecma_value_t this_arg, /**< this argument */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + uint32_t radix = 10; + + if (arguments_list_len > 0 && !ecma_is_value_undefined (arguments_list_p[0])) + { + ecma_number_t arg_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arguments_list_p[0], &arg_num))) + { + return ECMA_VALUE_ERROR; + } + + if (arg_num < 2 || arg_num > 36) + { + return ecma_raise_range_error (ECMA_ERR_RADIX_IS_OUT_OF_RANGE); + } + + radix = (uint32_t) arg_num; + } + + ecma_string_t *string_p = ecma_bigint_to_string (this_arg, radix); + + if (string_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + return ecma_make_string_value (string_p); +} /* ecma_builtin_bigint_prototype_object_to_string */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_bigint_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + ecma_value_t this_value = ecma_builtin_bigint_prototype_object_value_of (this_arg); + ecma_value_t ret_val; + + if (ECMA_IS_VALUE_ERROR (this_value)) + { + return this_value; + } + + switch (builtin_routine_id) + { + case ECMA_BIGINT_PROTOTYPE_VALUE_OF: + { + ret_val = this_value; + break; + } + case ECMA_BIGINT_PROTOTYPE_TO_STRING: + { + ret_val = ecma_builtin_bigint_prototype_object_to_string (this_value, arguments_list_p, arguments_number); + ecma_free_value (this_value); + break; + } + case ECMA_BIGINT_PROTOTYPE_TO_LOCALE_STRING: + { + ret_val = ecma_builtin_bigint_prototype_object_to_string (this_value, 0, 0); + ecma_free_value (this_value); + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + return ret_val; +} /* ecma_builtin_bigint_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint-prototype.inc.h new file mode 100644 index 0000000..1dc916b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint-prototype.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * BigInt.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_BIGINT + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v11, 20.2.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_BIGINT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v11, 20.2.3.5 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_BIGINT_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_BIGINT_PROTOTYPE_TO_STRING, NON_FIXED, 0) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_BIGINT_PROTOTYPE_VALUE_OF, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_BIGINT_PROTOTYPE_TO_LOCALE_STRING, 0, 0) + +#endif /* JERRY_BUILTIN_BIGINT */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint.cpp new file mode 100644 index 0000000..b349db1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint.cpp @@ -0,0 +1,80 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-bigint.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_BIGINT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-bigint.inc.h" +#define BUILTIN_UNDERSCORED_ID bigint +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup bigint ECMA BigInt object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in BigInt object + * + * See also: + * ECMA-262 v11, 20.2.1.1 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_bigint_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_value_t value = (arguments_list_len == 0) ? ECMA_VALUE_UNDEFINED : arguments_list_p[0]; + return ecma_bigint_to_bigint (value, true); +} /* ecma_builtin_bigint_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in BigInt object + * + * See also: + * ECMA-262 v11, 20.2.1 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_bigint_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_BIGINT_FUNCTION_NOT_CONSTRUCTOR); +} /* ecma_builtin_bigint_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint.inc.h new file mode 100644 index 0000000..d8b216a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-bigint.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * BigInt built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_BIGINT + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v11, 20.2.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v11, 20.2.1 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_BIGINT_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v11, 20.2.2.3 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_BIGINT_PROTOTYPE, ECMA_PROPERTY_FIXED) + +#endif /* JERRY_BUILTIN_BIGINT */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.cpp new file mode 100644 index 0000000..0d71a06 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.cpp @@ -0,0 +1,140 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_BOOLEAN + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BOOLEAN_PROTOTYPE_ROUTINE_START = 0, + ECMA_BOOLEAN_PROTOTYPE_ROUTINE_TO_STRING, + ECMA_BOOLEAN_PROTOTYPE_ROUTINE_VALUE_OF +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID boolean_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup booleanprototype ECMA Boolean.prototype object built-in + * @{ + */ + +/** + * The Boolean.prototype object's 'valueOf' routine + * + * See also: + * ECMA-262 v5, 15.6.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_boolean (this_arg)) + { + return this_arg; + } + else if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_BOOLEAN)) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.cls.u3.value)); + + return ext_object_p->u.cls.u3.value; + } + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_BOOLEAN_OBJECT); +} /* ecma_builtin_boolean_prototype_object_value_of */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_boolean_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_number, arguments_list_p); + + ecma_value_t value_of_ret = ecma_builtin_boolean_prototype_object_value_of (this_arg); + if (builtin_routine_id == ECMA_BOOLEAN_PROTOTYPE_ROUTINE_VALUE_OF) + { + return value_of_ret; + } + + JERRY_ASSERT (builtin_routine_id == ECMA_BOOLEAN_PROTOTYPE_ROUTINE_TO_STRING); + + if (ECMA_IS_VALUE_ERROR (value_of_ret)) + { + return value_of_ret; + } + + if (ecma_is_value_true (value_of_ret)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_TRUE); + } + + JERRY_ASSERT (ecma_is_value_false (value_of_ret)); + + return ecma_make_magic_string_value (LIT_MAGIC_STRING_FALSE); +} /* ecma_builtin_boolean_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BOOLEAN */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h new file mode 100644 index 0000000..82ef75f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Boolean.prototype description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_BOOLEAN + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.6.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_BOOLEAN, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_BOOLEAN_PROTOTYPE_ROUTINE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_BOOLEAN_PROTOTYPE_ROUTINE_VALUE_OF, 0, 0) + +#endif /* JERRY_BUILTIN_BOOLEAN */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.cpp new file mode 100644 index 0000000..603d610 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.cpp @@ -0,0 +1,99 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-boolean-object.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_BOOLEAN + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean.inc.h" +#define BUILTIN_UNDERSCORED_ID boolean +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup boolean ECMA Boolean object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Boolean object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_boolean_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_value_t arg_value; + + if (arguments_list_len == 0) + { + arg_value = ECMA_VALUE_UNDEFINED; + } + else + { + arg_value = arguments_list_p[0]; + } + + return ecma_make_boolean_value (ecma_op_to_boolean (arg_value)); +} /* ecma_builtin_boolean_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Boolean object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_boolean_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len == 0) + { + return ecma_op_create_boolean_object (ECMA_VALUE_FALSE); + } + else + { + return ecma_op_create_boolean_object (arguments_list_p[0]); + } +} /* ecma_builtin_boolean_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BOOLEAN */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h new file mode 100644 index 0000000..36f6845 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Boolean description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_BOOLEAN + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.6.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* Number properties: + * (property name, object pointer getter) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_BOOLEAN_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_BOOLEAN */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview-prototype.cpp new file mode 100644 index 0000000..6cb9ba3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview-prototype.cpp @@ -0,0 +1,238 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" +#include "ecma-dataview-object.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" + +#if JERRY_BUILTIN_DATAVIEW + +#if !JERRY_BUILTIN_TYPEDARRAY +#error "DataView builtin requires ES2015 TypedArray builtin" +#endif /* !JERRY_BUILTIN_TYPEDARRAY */ + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_DATAVIEW_PROTOTYPE_ROUTINE_START = 0, + ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER, + ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER, + ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER, + ECMA_DATAVIEW_PROTOTYPE_GET_INT8, + ECMA_DATAVIEW_PROTOTYPE_GET_UINT8, + ECMA_DATAVIEW_PROTOTYPE_GET_UINT8_CLAMPED, /* unused value */ + ECMA_DATAVIEW_PROTOTYPE_GET_INT16, + ECMA_DATAVIEW_PROTOTYPE_GET_UINT16, + ECMA_DATAVIEW_PROTOTYPE_GET_INT32, + ECMA_DATAVIEW_PROTOTYPE_GET_UINT32, + ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT32, +#if JERRY_NUMBER_TYPE_FLOAT64 + ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT64, +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_BIGINT + ECMA_DATAVIEW_PROTOTYPE_GET_BIGINT64, + ECMA_DATAVIEW_PROTOTYPE_GET_BIGUINT64, +#endif /* JERRY_BUILTIN_BIGINT */ + ECMA_DATAVIEW_PROTOTYPE_SET_INT8, + ECMA_DATAVIEW_PROTOTYPE_SET_UINT8, + ECMA_DATAVIEW_PROTOTYPE_SET_UINT8_CLAMPED, /* unused value */ + ECMA_DATAVIEW_PROTOTYPE_SET_INT16, + ECMA_DATAVIEW_PROTOTYPE_SET_UINT16, + ECMA_DATAVIEW_PROTOTYPE_SET_INT32, + ECMA_DATAVIEW_PROTOTYPE_SET_UINT32, + ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32, +#if JERRY_NUMBER_TYPE_FLOAT64 + ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT64, +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_BIGINT + ECMA_DATAVIEW_PROTOTYPE_SET_BIGINT64, + ECMA_DATAVIEW_PROTOTYPE_SET_BIGUINT64, +#endif /* JERRY_BUILTIN_BIGINT */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-dataview-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID dataview_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup dataviewprototype ECMA DataView.prototype object built-in + * @{ + */ + +/** + * The DataView.prototype object's {buffer, byteOffset, byteLength} getters + * + * See also: + * ECMA-262 v6, 24.2.4.1 + * ECMA-262 v6, 24.2.4.2 + * ECMA-262 v6, 24.2.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_dataview_prototype_object_getters (ecma_value_t this_arg, /**< this argument */ + uint16_t builtin_routine_id) /**< built-in wide routine identifier */ +{ + ecma_dataview_object_t *obj_p = ecma_op_dataview_get_object (this_arg); + + if (JERRY_UNLIKELY (obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + switch (builtin_routine_id) + { + case ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER: + { + ecma_object_t *buffer_p = obj_p->buffer_p; + ecma_ref_object (buffer_p); + + return ecma_make_object_value (buffer_p); + } + case ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER: + { + if (ecma_arraybuffer_is_detached (obj_p->buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + return ecma_make_uint32_value (obj_p->header.u.cls.u3.length); + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER); + + if (ecma_arraybuffer_is_detached (obj_p->buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + return ecma_make_uint32_value (obj_p->byte_offset); + } + } +} /* ecma_builtin_dataview_prototype_object_getters */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_dataview_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + switch (builtin_routine_id) + { + case ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER: + case ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER: + case ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER: + { + return ecma_builtin_dataview_prototype_object_getters (this_arg, builtin_routine_id); + } + case ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT32: +#if JERRY_NUMBER_TYPE_FLOAT64 + case ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT64: +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + case ECMA_DATAVIEW_PROTOTYPE_GET_INT16: + case ECMA_DATAVIEW_PROTOTYPE_GET_INT32: + case ECMA_DATAVIEW_PROTOTYPE_GET_UINT16: + case ECMA_DATAVIEW_PROTOTYPE_GET_UINT32: +#if JERRY_BUILTIN_BIGINT + case ECMA_DATAVIEW_PROTOTYPE_GET_BIGINT64: + case ECMA_DATAVIEW_PROTOTYPE_GET_BIGUINT64: +#endif /* JERRY_BUILTIN_BIGINT */ + { + ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8); + + return ecma_op_dataview_get_set_view_value (this_arg, + arguments_list_p[0], + arguments_list_p[1], + ECMA_VALUE_EMPTY, + id); + } + case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32: +#if JERRY_NUMBER_TYPE_FLOAT64 + case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT64: +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + case ECMA_DATAVIEW_PROTOTYPE_SET_INT16: + case ECMA_DATAVIEW_PROTOTYPE_SET_INT32: + case ECMA_DATAVIEW_PROTOTYPE_SET_UINT16: + case ECMA_DATAVIEW_PROTOTYPE_SET_UINT32: +#if JERRY_BUILTIN_BIGINT + case ECMA_DATAVIEW_PROTOTYPE_SET_BIGINT64: + case ECMA_DATAVIEW_PROTOTYPE_SET_BIGUINT64: +#endif /* JERRY_BUILTIN_BIGINT */ + { + ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8); + + return ecma_op_dataview_get_set_view_value (this_arg, + arguments_list_p[0], + arguments_list_p[2], + arguments_list_p[1], + id); + } + case ECMA_DATAVIEW_PROTOTYPE_GET_INT8: + case ECMA_DATAVIEW_PROTOTYPE_GET_UINT8: + { + ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8); + + return ecma_op_dataview_get_set_view_value (this_arg, + arguments_list_p[0], + ECMA_VALUE_FALSE, + ECMA_VALUE_EMPTY, + id); + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_INT8 + || builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_UINT8); + ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8); + + return ecma_op_dataview_get_set_view_value (this_arg, + arguments_list_p[0], + ECMA_VALUE_FALSE, + arguments_list_p[1], + id); + } + } +} /* ecma_builtin_dataview_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_DATAVIEW */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview-prototype.inc.h new file mode 100644 index 0000000..82ef26b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview-prototype.inc.h @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * DataView.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_DATAVIEW + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 24.2.3 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_DATAVIEW, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.2.4.21 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_DATAVIEW_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_GET_FLOAT_32_UL, ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT32, 2, 1) +#if JERRY_NUMBER_TYPE_FLOAT64 +ROUTINE (LIT_MAGIC_STRING_GET_FLOAT_64_UL, ECMA_DATAVIEW_PROTOTYPE_GET_FLOAT64, 2, 1) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +ROUTINE (LIT_MAGIC_STRING_GET_INT8_UL, ECMA_DATAVIEW_PROTOTYPE_GET_INT8, 1, 1) +ROUTINE (LIT_MAGIC_STRING_GET_INT16_UL, ECMA_DATAVIEW_PROTOTYPE_GET_INT16, 2, 1) +ROUTINE (LIT_MAGIC_STRING_GET_INT32_UL, ECMA_DATAVIEW_PROTOTYPE_GET_INT32, 2, 1) +ROUTINE (LIT_MAGIC_STRING_GET_UINT8_UL, ECMA_DATAVIEW_PROTOTYPE_GET_UINT8, 2, 1) +ROUTINE (LIT_MAGIC_STRING_GET_UINT16_UL, ECMA_DATAVIEW_PROTOTYPE_GET_UINT16, 2, 1) +ROUTINE (LIT_MAGIC_STRING_GET_UINT32_UL, ECMA_DATAVIEW_PROTOTYPE_GET_UINT32, 2, 1) +ROUTINE (LIT_MAGIC_STRING_SET_FLOAT_32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32, 2, 2) +#if JERRY_NUMBER_TYPE_FLOAT64 +ROUTINE (LIT_MAGIC_STRING_SET_FLOAT_64_UL, ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT64, 2, 2) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +ROUTINE (LIT_MAGIC_STRING_SET_INT8_UL, ECMA_DATAVIEW_PROTOTYPE_SET_INT8, 1, 2) +ROUTINE (LIT_MAGIC_STRING_SET_INT16_UL, ECMA_DATAVIEW_PROTOTYPE_SET_INT16, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_INT32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_INT32, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_UINT8_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT8, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_UINT16_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT16, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_UINT32_UL, ECMA_DATAVIEW_PROTOTYPE_SET_UINT32, 2, 2) +#if JERRY_BUILTIN_BIGINT +ROUTINE (LIT_MAGIC_STRING_GET_BIGINT64, ECMA_DATAVIEW_PROTOTYPE_GET_BIGINT64, 2, 1) +ROUTINE (LIT_MAGIC_STRING_GET_BIGUINT64, ECMA_DATAVIEW_PROTOTYPE_GET_BIGUINT64, 2, 1) +ROUTINE (LIT_MAGIC_STRING_SET_BIGINT64, ECMA_DATAVIEW_PROTOTYPE_SET_BIGINT64, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_BIGUINT64, ECMA_DATAVIEW_PROTOTYPE_SET_BIGUINT64, 2, 2) +#endif /* JERRY_BUILTIN_BIGINT */ + +/* ECMA-262 v6, 24.2.4.1 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BUFFER, ECMA_DATAVIEW_PROTOTYPE_BUFFER_GETTER, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 24.2.4.2 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL, + ECMA_DATAVIEW_PROTOTYPE_BYTE_LENGTH_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 24.2.4.3 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_OFFSET_UL, + ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_DATAVIEW */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview.cpp new file mode 100644 index 0000000..bfdb33f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview.cpp @@ -0,0 +1,71 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-dataview-object.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_DATAVIEW + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-dataview.inc.h" +#define BUILTIN_UNDERSCORED_ID dataview +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup dataview ECMA DataView object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in DataView object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_dataview_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_DATAVIEW_REQUIRES_NEW); +} /* ecma_builtin_dataview_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in DataView object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_dataview_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_op_dataview_create (arguments_list_p, arguments_list_len); +} /* ecma_builtin_dataview_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_DATAVIEW */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview.inc.h new file mode 100644 index 0000000..9b1027c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-dataview.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * DataView built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_DATAVIEW + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v6, 23.1.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 23.1 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_DATAVIEW_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.1.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE, ECMA_PROPERTY_FIXED) + +#endif /* JERRY_BUILTIN_DATAVIEW */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp new file mode 100644 index 0000000..5ad4f2d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp @@ -0,0 +1,722 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#if JERRY_BUILTIN_DATE + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * Checks whether the function uses UTC time zone. + */ +#define BUILTIN_DATE_FUNCTION_IS_UTC(builtin_routine_id) \ + (((builtin_routine_id) -ECMA_DATE_PROTOTYPE_GET_FULL_YEAR) & 0x1) + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_DATE_PROTOTYPE_ROUTINE_START = 0, + + ECMA_DATE_PROTOTYPE_GET_FULL_YEAR, /* ECMA-262 v5 15.9.5.10 */ + ECMA_DATE_PROTOTYPE_GET_UTC_FULL_YEAR, /* ECMA-262 v5 15.9.5.11 */ +#if JERRY_BUILTIN_ANNEXB + ECMA_DATE_PROTOTYPE_GET_YEAR, /* ECMA-262 v5, AnnexB.B.2.4 */ + ECMA_DATE_PROTOTYPE_GET_UTC_YEAR, /* has no UTC variant */ +#endif /* JERRY_BUILTIN_ANNEXB */ + ECMA_DATE_PROTOTYPE_GET_MONTH, /* ECMA-262 v5 15.9.5.12 */ + ECMA_DATE_PROTOTYPE_GET_UTC_MONTH, /* ECMA-262 v5 15.9.5.13 */ + ECMA_DATE_PROTOTYPE_GET_DATE, /* ECMA-262 v5 15.9.5.14 */ + ECMA_DATE_PROTOTYPE_GET_UTC_DATE, /* ECMA-262 v5 15.9.5.15 */ + ECMA_DATE_PROTOTYPE_GET_DAY, /* ECMA-262 v5 15.9.5.16 */ + ECMA_DATE_PROTOTYPE_GET_UTC_DAY, /* ECMA-262 v5 15.9.5.17 */ + ECMA_DATE_PROTOTYPE_GET_HOURS, /* ECMA-262 v5 15.9.5.18 */ + ECMA_DATE_PROTOTYPE_GET_UTC_HOURS, /* ECMA-262 v5 15.9.5.19 */ + ECMA_DATE_PROTOTYPE_GET_MINUTES, /* ECMA-262 v5 15.9.5.20 */ + ECMA_DATE_PROTOTYPE_GET_UTC_MINUTES, /* ECMA-262 v5 15.9.5.21 */ + ECMA_DATE_PROTOTYPE_GET_SECONDS, /* ECMA-262 v5 15.9.5.22 */ + ECMA_DATE_PROTOTYPE_GET_UTC_SECONDS, /* ECMA-262 v5 15.9.5.23 */ + ECMA_DATE_PROTOTYPE_GET_MILLISECONDS, /* ECMA-262 v5 15.9.5.24 */ + ECMA_DATE_PROTOTYPE_GET_UTC_MILLISECONDS, /* ECMA-262 v5 15.9.5.25 */ + ECMA_DATE_PROTOTYPE_GET_TIMEZONE_OFFSET, /* has no local time zone variant */ + ECMA_DATE_PROTOTYPE_GET_UTC_TIMEZONE_OFFSET, /* ECMA-262 v5 15.9.5.26 */ + + ECMA_DATE_PROTOTYPE_SET_FULL_YEAR, /* ECMA-262 v5, 15.9.5.40 */ + ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR, /* ECMA-262 v5, 15.9.5.41 */ +#if JERRY_BUILTIN_ANNEXB + ECMA_DATE_PROTOTYPE_SET_YEAR, /* ECMA-262 v5, ECMA-262 v5, AnnexB.B.2.5 */ + ECMA_DATE_PROTOTYPE_SET_UTC_YEAR, /* has no UTC variant */ +#endif /* JERRY_BUILTIN_ANNEXB */ + ECMA_DATE_PROTOTYPE_SET_MONTH, /* ECMA-262 v5, 15.9.5.38 */ + ECMA_DATE_PROTOTYPE_SET_UTC_MONTH, /* ECMA-262 v5, 15.9.5.39 */ + ECMA_DATE_PROTOTYPE_SET_DATE, /* ECMA-262 v5, 15.9.5.36 */ + ECMA_DATE_PROTOTYPE_SET_UTC_DATE, /* ECMA-262 v5, 15.9.5.37 */ + ECMA_DATE_PROTOTYPE_SET_HOURS, /* ECMA-262 v5, 15.9.5.34 */ + ECMA_DATE_PROTOTYPE_SET_UTC_HOURS, /* ECMA-262 v5, 15.9.5.35 */ + ECMA_DATE_PROTOTYPE_SET_MINUTES, /* ECMA-262 v5, 15.9.5.32 */ + ECMA_DATE_PROTOTYPE_SET_UTC_MINUTES, /* ECMA-262 v5, 15.9.5.33 */ + ECMA_DATE_PROTOTYPE_SET_SECONDS, /* ECMA-262 v5, 15.9.5.30 */ + ECMA_DATE_PROTOTYPE_SET_UTC_SECONDS, /* ECMA-262 v5, 15.9.5.31 */ + ECMA_DATE_PROTOTYPE_SET_MILLISECONDS, /* ECMA-262 v5, 15.9.5.28 */ + ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS, /* ECMA-262 v5, 15.9.5.29 */ + + ECMA_DATE_PROTOTYPE_TO_STRING, /* ECMA-262 v5, 15.9.5.2 */ + ECMA_DATE_PROTOTYPE_TO_DATE_STRING, /* ECMA-262 v5, 15.9.5.3 */ + ECMA_DATE_PROTOTYPE_TO_TIME_STRING, /* ECMA-262 v5, 15.9.5.4 */ + ECMA_DATE_PROTOTYPE_TO_ISO_STRING, /* ECMA-262 v5, 15.9.5.43 */ + + ECMA_DATE_PROTOTYPE_GET_TIME, /* ECMA-262 v5, 15.9.5.9 */ + ECMA_DATE_PROTOTYPE_SET_TIME, /* ECMA-262 v5, 15.9.5.27 */ + ECMA_DATE_PROTOTYPE_TO_JSON, /* ECMA-262 v5, 15.9.5.44 */ + + ECMA_DATE_PROTOTYPE_TO_PRIMITIVE, /* ECMA-262 v6 20.3.4.45 */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-date-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID date_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup dateprototype ECMA Date.prototype object built-in + * @{ + */ + +/** + * The Date.prototype object's 'toJSON' routine + * + * See also: + * ECMA-262 v5, 15.9.5.44 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_date_prototype_to_json (ecma_value_t this_arg) /**< this argument */ +{ + /* 1. */ + ecma_value_t obj = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (obj)) + { + return obj; + } + + /* 2. */ + ecma_value_t tv = ecma_op_to_primitive (obj, ECMA_PREFERRED_TYPE_NUMBER); + + if (ECMA_IS_VALUE_ERROR (tv)) + { + ecma_free_value (obj); + return tv; + } + + /* 3. */ + if (ecma_is_value_number (tv)) + { + ecma_number_t num_value = ecma_get_number_from_value (tv); + + ecma_free_value (tv); + + if (ecma_number_is_nan (num_value) || ecma_number_is_infinity (num_value)) + { + ecma_free_value (obj); + return ECMA_VALUE_NULL; + } + } + else + { + ecma_free_value (tv); + } + + ecma_object_t *value_obj_p = ecma_get_object_from_value (obj); + + /* 4. */ + ecma_value_t ret_value = ecma_op_invoke_by_magic_id (obj, LIT_MAGIC_STRING_TO_ISO_STRING_UL, NULL, 0); + + ecma_deref_object (value_obj_p); + + return ret_value; +} /* ecma_builtin_date_prototype_to_json */ + +/** + * The Date.prototype object's toPrimitive routine + * + * See also: + * ECMA-262 v6, 20.3.4.45 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_date_prototype_to_primitive (ecma_value_t this_arg, /**< this argument */ + ecma_value_t hint_arg) /**< {"default", "number", "string"} */ +{ + if (ecma_is_value_object (this_arg) && ecma_is_value_string (hint_arg)) + { + ecma_string_t *hint_str_p = ecma_get_string_from_value (hint_arg); + + ecma_preferred_type_hint_t hint = ECMA_PREFERRED_TYPE_NO; + + if (hint_str_p == ecma_get_magic_string (LIT_MAGIC_STRING_STRING) + || hint_str_p == ecma_get_magic_string (LIT_MAGIC_STRING_DEFAULT)) + { + hint = ECMA_PREFERRED_TYPE_STRING; + } + else if (hint_str_p == ecma_get_magic_string (LIT_MAGIC_STRING_NUMBER)) + { + hint = ECMA_PREFERRED_TYPE_NUMBER; + } + + if (hint != ECMA_PREFERRED_TYPE_NO) + { + return ecma_op_general_object_ordinary_value (ecma_get_object_from_value (this_arg), hint); + } + } + + return ecma_raise_type_error (ECMA_ERR_INVALID_ARGUMENT_TYPE_IN_TOPRIMITIVE); +} /* ecma_builtin_date_prototype_to_primitive */ + +/** + * Dispatch get date functions + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_date_prototype_dispatch_get (uint16_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_number_t date_value) /**< date converted to number */ +{ + if (ecma_number_is_nan (date_value)) + { + return ecma_make_nan_value (); + } + + int32_t result; + + switch (builtin_routine_id) + { + case ECMA_DATE_PROTOTYPE_GET_FULL_YEAR: + case ECMA_DATE_PROTOTYPE_GET_UTC_FULL_YEAR: + { + result = ecma_date_year_from_time (date_value); + break; + } +#if JERRY_BUILTIN_ANNEXB + case ECMA_DATE_PROTOTYPE_GET_YEAR: + { + result = (ecma_date_year_from_time (date_value) - 1900); + break; + } +#endif /* JERRY_BUILTIN_ANNEXB */ + case ECMA_DATE_PROTOTYPE_GET_MONTH: + case ECMA_DATE_PROTOTYPE_GET_UTC_MONTH: + { + result = ecma_date_month_from_time (date_value); + break; + } + case ECMA_DATE_PROTOTYPE_GET_DATE: + case ECMA_DATE_PROTOTYPE_GET_UTC_DATE: + { + result = ecma_date_date_from_time (date_value); + break; + } + case ECMA_DATE_PROTOTYPE_GET_DAY: + case ECMA_DATE_PROTOTYPE_GET_UTC_DAY: + { + result = ecma_date_week_day (date_value); + break; + } + case ECMA_DATE_PROTOTYPE_GET_HOURS: + case ECMA_DATE_PROTOTYPE_GET_UTC_HOURS: + { + result = ecma_date_hour_from_time (date_value); + break; + } + case ECMA_DATE_PROTOTYPE_GET_MINUTES: + case ECMA_DATE_PROTOTYPE_GET_UTC_MINUTES: + { + result = ecma_date_min_from_time (date_value); + break; + } + case ECMA_DATE_PROTOTYPE_GET_SECONDS: + case ECMA_DATE_PROTOTYPE_GET_UTC_SECONDS: + { + result = ecma_date_sec_from_time (date_value); + break; + } + case ECMA_DATE_PROTOTYPE_GET_MILLISECONDS: + case ECMA_DATE_PROTOTYPE_GET_UTC_MILLISECONDS: + { + result = ecma_date_ms_from_time (date_value); + break; + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATE_PROTOTYPE_GET_UTC_TIMEZONE_OFFSET); + + result = -ecma_date_local_time_zone_adjustment (date_value) / ECMA_DATE_MS_PER_MINUTE; + break; + } + } + + return ecma_make_int32_value (result); +} /* ecma_builtin_date_prototype_dispatch_get */ + +#if JERRY_BUILTIN_ANNEXB + +/** + * Returns true, if the built-in id sets a year. + */ +#define ECMA_DATE_PROTOTYPE_IS_SET_YEAR_ROUTINE(builtin_routine_id) \ + ((builtin_routine_id) == ECMA_DATE_PROTOTYPE_SET_FULL_YEAR \ + || (builtin_routine_id) == ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR \ + || (builtin_routine_id) == ECMA_DATE_PROTOTYPE_SET_YEAR) + +#else /* !JERRY_BUILTIN_ANNEXB */ + +/** + * Returns true, if the built-in id sets a year. + */ +#define ECMA_DATE_PROTOTYPE_IS_SET_YEAR_ROUTINE(builtin_routine_id) \ + ((builtin_routine_id) == ECMA_DATE_PROTOTYPE_SET_FULL_YEAR \ + || (builtin_routine_id) == ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR) + +#endif /* JERRY_BUILTIN_ANNEXB */ + +/** + * Dispatch set date functions + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_date_prototype_dispatch_set (uint16_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_object_t *object_p, /**< date object */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + ecma_number_t converted_number[4]; + uint32_t conversions = 0; + + /* If the first argument is not specified, it is always converted to NaN. */ + converted_number[0] = ecma_number_make_nan (); + + switch (builtin_routine_id) + { +#if JERRY_BUILTIN_ANNEXB + case ECMA_DATE_PROTOTYPE_SET_YEAR: +#endif /* JERRY_BUILTIN_ANNEXB */ + case ECMA_DATE_PROTOTYPE_SET_DATE: + case ECMA_DATE_PROTOTYPE_SET_UTC_DATE: + case ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS: + case ECMA_DATE_PROTOTYPE_SET_MILLISECONDS: + { + conversions = 1; + break; + } + case ECMA_DATE_PROTOTYPE_SET_MONTH: + case ECMA_DATE_PROTOTYPE_SET_UTC_MONTH: + case ECMA_DATE_PROTOTYPE_SET_UTC_SECONDS: + case ECMA_DATE_PROTOTYPE_SET_SECONDS: + { + conversions = 2; + break; + } + case ECMA_DATE_PROTOTYPE_SET_FULL_YEAR: + case ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR: + case ECMA_DATE_PROTOTYPE_SET_MINUTES: + case ECMA_DATE_PROTOTYPE_SET_UTC_MINUTES: + { + conversions = 3; + break; + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_HOURS + || builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_UTC_HOURS); + + conversions = 4; + break; + } + } + + if (conversions > arguments_number) + { + conversions = arguments_number; + } + + for (uint32_t i = 0; i < conversions; i++) + { + ecma_value_t value = ecma_op_to_number (arguments_list[i], &converted_number[i]); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + } + + ecma_date_object_t *date_object_p = (ecma_date_object_t *) object_p; + ecma_number_t *date_value_p = &date_object_p->date_value; + ecma_number_t date_value = *date_value_p; + + if (!BUILTIN_DATE_FUNCTION_IS_UTC (builtin_routine_id)) + { + ecma_number_t local_tza; + + if (date_object_p->header.u.cls.u1.date_flags & ECMA_DATE_TZA_SET) + { + local_tza = date_object_p->header.u.cls.u3.tza; + JERRY_ASSERT (local_tza == ecma_date_local_time_zone_adjustment (date_value)); + } + else + { + local_tza = ecma_date_local_time_zone_adjustment (date_value); + } + + date_value += local_tza; + } + + ecma_number_t day_part; + ecma_number_t time_part; + + if (builtin_routine_id <= ECMA_DATE_PROTOTYPE_SET_UTC_DATE) + { + if (ecma_number_is_nan (date_value)) + { + if (!ECMA_DATE_PROTOTYPE_IS_SET_YEAR_ROUTINE (builtin_routine_id)) + { + return ecma_make_number_value (date_value); + } + + date_value = ECMA_NUMBER_ZERO; + } + + time_part = ecma_date_time_in_day_from_time (date_value); + + ecma_number_t year = ecma_date_year_from_time (date_value); + ecma_number_t month = ecma_date_month_from_time (date_value); + ecma_number_t day = ecma_date_date_from_time (date_value); + + switch (builtin_routine_id) + { + case ECMA_DATE_PROTOTYPE_SET_FULL_YEAR: + case ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR: + { + year = converted_number[0]; + if (conversions >= 2) + { + month = converted_number[1]; + } + if (conversions >= 3) + { + day = converted_number[2]; + } + break; + } +#if JERRY_BUILTIN_ANNEXB + case ECMA_DATE_PROTOTYPE_SET_YEAR: + { + if (ecma_number_is_nan (converted_number[0])) + { + *date_value_p = converted_number[0]; + date_object_p->header.u.cls.u1.date_flags &= (uint8_t) ~ECMA_DATE_TZA_SET; + return ecma_make_number_value (converted_number[0]); + } + + year = ecma_number_trunc (converted_number[0]); + if (year >= 0 && year <= 99) + { + year += 1900; + } + break; + } +#endif /* JERRY_BUILTIN_ANNEXB */ + case ECMA_DATE_PROTOTYPE_SET_MONTH: + case ECMA_DATE_PROTOTYPE_SET_UTC_MONTH: + { + month = converted_number[0]; + if (conversions >= 2) + { + day = converted_number[1]; + } + break; + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_DATE + || builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_UTC_DATE); + + day = converted_number[0]; + break; + } + } + + day_part = ecma_date_make_day (year, month, day); + +#if JERRY_BUILTIN_ANNEXB + if (builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_YEAR) + { + if (ecma_number_is_nan (converted_number[0])) + { + day_part = 0; + time_part = converted_number[0]; + } + } +#endif /* JERRY_BUILTIN_ANNEXB */ + } + else + { + if (ecma_number_is_nan (date_value)) + { + return ecma_make_number_value (date_value); + } + + day_part = ecma_date_day_from_time (date_value) * (ecma_number_t) ECMA_DATE_MS_PER_DAY; + + ecma_number_t hour = ecma_date_hour_from_time (date_value); + ecma_number_t min = ecma_date_min_from_time (date_value); + ecma_number_t sec = ecma_date_sec_from_time (date_value); + ecma_number_t ms = ecma_date_ms_from_time (date_value); + + switch (builtin_routine_id) + { + case ECMA_DATE_PROTOTYPE_SET_HOURS: + case ECMA_DATE_PROTOTYPE_SET_UTC_HOURS: + { + hour = converted_number[0]; + if (conversions >= 2) + { + min = converted_number[1]; + } + if (conversions >= 3) + { + sec = converted_number[2]; + } + if (conversions >= 4) + { + ms = converted_number[3]; + } + break; + } + case ECMA_DATE_PROTOTYPE_SET_MINUTES: + case ECMA_DATE_PROTOTYPE_SET_UTC_MINUTES: + { + min = converted_number[0]; + if (conversions >= 2) + { + sec = converted_number[1]; + } + if (conversions >= 3) + { + ms = converted_number[2]; + } + break; + } + case ECMA_DATE_PROTOTYPE_SET_UTC_SECONDS: + case ECMA_DATE_PROTOTYPE_SET_SECONDS: + { + sec = converted_number[0]; + if (conversions >= 2) + { + ms = converted_number[1]; + } + break; + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS + || builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_MILLISECONDS); + + ms = converted_number[0]; + break; + } + } + + time_part = ecma_date_make_time (hour, min, sec, ms); + } + + bool is_utc = BUILTIN_DATE_FUNCTION_IS_UTC (builtin_routine_id); + + ecma_number_t full_date = ecma_date_make_date (day_part, time_part); + + if (!is_utc) + { + full_date = ecma_date_utc (full_date); + } + + full_date = ecma_date_time_clip (full_date); + + *date_value_p = full_date; + + date_object_p->header.u.cls.u1.date_flags &= (uint8_t) ~ECMA_DATE_TZA_SET; + + return ecma_make_number_value (full_date); +} /* ecma_builtin_date_prototype_dispatch_set */ + +#undef ECMA_DATE_PROTOTYPE_IS_SET_YEAR_ROUTINE + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_date_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + if (JERRY_UNLIKELY (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_JSON)) + { + return ecma_builtin_date_prototype_to_json (this_arg); + } + + if (JERRY_UNLIKELY (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_PRIMITIVE)) + { + return ecma_builtin_date_prototype_to_primitive (this_arg, arguments_list[0]); + } + + if (!ecma_is_value_object (this_arg) + || !ecma_object_class_is (ecma_get_object_from_value (this_arg), ECMA_OBJECT_CLASS_DATE)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_DATE_OBJECT); + } + + ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg); + + ecma_date_object_t *date_object_p = (ecma_date_object_t *) this_obj_p; + ecma_number_t *date_value_p = &date_object_p->date_value; + ecma_number_t date_value = *date_value_p; + + if (builtin_routine_id == ECMA_DATE_PROTOTYPE_GET_TIME) + { + return ecma_make_number_value (date_value); + } + + if (builtin_routine_id == ECMA_DATE_PROTOTYPE_SET_TIME) + { + ecma_number_t time_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (arguments_list[0], &time_num))) + { + return ECMA_VALUE_ERROR; + } + + *date_value_p = ecma_date_time_clip (time_num); + date_object_p->header.u.cls.u1.date_flags &= (uint8_t) ~ECMA_DATE_TZA_SET; + + return ecma_make_number_value (*date_value_p); + } + + if (builtin_routine_id <= ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS) + { + if (builtin_routine_id <= ECMA_DATE_PROTOTYPE_GET_UTC_TIMEZONE_OFFSET) + { + if (!BUILTIN_DATE_FUNCTION_IS_UTC (builtin_routine_id)) + { + ecma_number_t local_tza; + + if (date_object_p->header.u.cls.u1.date_flags & ECMA_DATE_TZA_SET) + { + local_tza = date_object_p->header.u.cls.u3.tza; + JERRY_ASSERT (local_tza == ecma_date_local_time_zone_adjustment (date_value)); + } + else + { + local_tza = ecma_date_local_time_zone_adjustment (date_value); + JERRY_ASSERT (local_tza <= INT32_MAX && local_tza >= INT32_MIN); + date_object_p->header.u.cls.u3.tza = (int32_t) local_tza; + date_object_p->header.u.cls.u1.date_flags |= ECMA_DATE_TZA_SET; + } + + date_value += local_tza; + } + + return ecma_builtin_date_prototype_dispatch_get (builtin_routine_id, date_value); + } + + return ecma_builtin_date_prototype_dispatch_set (builtin_routine_id, this_obj_p, arguments_list, arguments_number); + } + + if (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_ISO_STRING) + { + if (ecma_number_is_nan (date_value)) + { + return ecma_raise_range_error (ECMA_ERR_DATE_MUST_BE_A_FINITE_NUMBER); + } + + return ecma_date_value_to_iso_string (date_value); + } + + if (ecma_number_is_nan (date_value)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_INVALID_DATE_UL); + } + + switch (builtin_routine_id) + { + case ECMA_DATE_PROTOTYPE_TO_STRING: + { + return ecma_date_value_to_string (date_value); + } + case ECMA_DATE_PROTOTYPE_TO_DATE_STRING: + { + return ecma_date_value_to_date_string (date_value); + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_DATE_PROTOTYPE_TO_TIME_STRING); + + return ecma_date_value_to_time_string (date_value); + } + } +} /* ecma_builtin_date_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_DATE */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h new file mode 100644 index 0000000..a960cc4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h @@ -0,0 +1,83 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Date.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_DATE + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_DATE, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_DATE_PROTOTYPE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_DATE_STRING_UL, ECMA_DATE_PROTOTYPE_TO_DATE_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_TIME_STRING_UL, ECMA_DATE_PROTOTYPE_TO_TIME_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_DATE_PROTOTYPE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_DATE_STRING_UL, ECMA_DATE_PROTOTYPE_TO_DATE_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_TIME_STRING_UL, ECMA_DATE_PROTOTYPE_TO_TIME_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_DATE_PROTOTYPE_GET_TIME, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_TIME_UL, ECMA_DATE_PROTOTYPE_GET_TIME, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_GET_FULL_YEAR, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_GET_UTC_FULL_YEAR, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_MONTH_UL, ECMA_DATE_PROTOTYPE_GET_MONTH, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_MONTH_UL, ECMA_DATE_PROTOTYPE_GET_UTC_MONTH, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_DATE_UL, ECMA_DATE_PROTOTYPE_GET_DATE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_DATE_UL, ECMA_DATE_PROTOTYPE_GET_UTC_DATE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_DAY_UL, ECMA_DATE_PROTOTYPE_GET_DAY, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_DAY_UL, ECMA_DATE_PROTOTYPE_GET_UTC_DAY, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_HOURS_UL, ECMA_DATE_PROTOTYPE_GET_HOURS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_HOURS_UL, ECMA_DATE_PROTOTYPE_GET_UTC_HOURS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_MINUTES_UL, ECMA_DATE_PROTOTYPE_GET_MINUTES, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_MINUTES_UL, ECMA_DATE_PROTOTYPE_GET_UTC_MINUTES, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_SECONDS_UL, ECMA_DATE_PROTOTYPE_GET_SECONDS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_SECONDS_UL, ECMA_DATE_PROTOTYPE_GET_UTC_SECONDS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_GET_MILLISECONDS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_UTC_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_GET_UTC_MILLISECONDS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, ECMA_DATE_PROTOTYPE_GET_UTC_TIMEZONE_OFFSET, 0, 0) +ROUTINE (LIT_MAGIC_STRING_SET_TIME_UL, ECMA_DATE_PROTOTYPE_SET_TIME, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_SET_MILLISECONDS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_MILLISECONDS_UL, ECMA_DATE_PROTOTYPE_SET_UTC_MILLISECONDS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_SECONDS_UL, ECMA_DATE_PROTOTYPE_SET_SECONDS, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_SECONDS_UL, ECMA_DATE_PROTOTYPE_SET_UTC_SECONDS, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_MINUTES_UL, ECMA_DATE_PROTOTYPE_SET_MINUTES, NON_FIXED, 3) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_MINUTES_UL, ECMA_DATE_PROTOTYPE_SET_UTC_MINUTES, NON_FIXED, 3) +ROUTINE (LIT_MAGIC_STRING_SET_HOURS_UL, ECMA_DATE_PROTOTYPE_SET_HOURS, NON_FIXED, 4) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_HOURS_UL, ECMA_DATE_PROTOTYPE_SET_UTC_HOURS, NON_FIXED, 4) +ROUTINE (LIT_MAGIC_STRING_SET_DATE_UL, ECMA_DATE_PROTOTYPE_SET_DATE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_DATE_UL, ECMA_DATE_PROTOTYPE_SET_UTC_DATE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_MONTH_UL, ECMA_DATE_PROTOTYPE_SET_MONTH, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_MONTH_UL, ECMA_DATE_PROTOTYPE_SET_UTC_MONTH, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SET_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_FULL_YEAR, NON_FIXED, 3) +ROUTINE (LIT_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_UTC_FULL_YEAR, NON_FIXED, 3) +ROUTINE (LIT_MAGIC_STRING_TO_ISO_STRING_UL, ECMA_DATE_PROTOTYPE_TO_ISO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_JSON_UL, ECMA_DATE_PROTOTYPE_TO_JSON, 1, 1) +ROUTINE_CONFIGURABLE_ONLY (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE, ECMA_DATE_PROTOTYPE_TO_PRIMITIVE, 1, 1) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_UTC_STRING_UL, + LIT_MAGIC_STRING_TO_UTC_STRING_UL, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#if JERRY_BUILTIN_ANNEXB +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_GMT_STRING_UL, + LIT_MAGIC_STRING_TO_UTC_STRING_UL, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +ROUTINE (LIT_MAGIC_STRING_GET_YEAR_UL, ECMA_DATE_PROTOTYPE_GET_YEAR, 0, 0) +ROUTINE (LIT_MAGIC_STRING_SET_YEAR_UL, ECMA_DATE_PROTOTYPE_SET_YEAR, 1, 1) + +#endif /* JERRY_BUILTIN_ANNEXB */ + +#endif /* JERRY_BUILTIN_DATE */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.cpp new file mode 100644 index 0000000..682671c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.cpp @@ -0,0 +1,874 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "jcontext.h" +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_DATE + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_DATE_ROUTINE_START = 0, + ECMA_DATE_ROUTINE_PARSE, + ECMA_DATE_ROUTINE_UTC, + ECMA_DATE_ROUTINE_NOW, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-date.inc.h" +#define BUILTIN_UNDERSCORED_ID date +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup date ECMA Date object built-in + * @{ + */ + +/** + * Encode minimum/maximum limits + * + * See: ecma_date_parse_date_chars + * + * @param min: 8 bits unsigned number + * @param max: 24 bits unsigned number + */ +#define ECMA_DATE_LIMIT(min, max) (min << 24 | max) + +/** + * Decode the minimum value from the encoded limit + */ +#define ECMA_DATE_LIMIT_MIN(limit) (limit >> 24) + +/** + * Decode the maximum value from the encoded limit + */ +#define ECMA_DATE_LIMIT_MAX(limit) (limit & ((1 << 24) - 1)) + +/** + * Helper function to try to parse a part of a date string + * + * @return NaN if cannot read from string, ToNumber() otherwise + */ +static ecma_number_t +ecma_date_parse_date_chars (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */ + const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */ + uint32_t num_of_chars, /**< number of characters to read and convert */ + uint32_t limit) /**< minimum/maximum valid value */ +{ + JERRY_ASSERT (num_of_chars > 0 && num_of_chars <= 6); + + if (*str_p + num_of_chars > str_end_p) + { + return ecma_number_make_nan (); + } + + str_end_p = *str_p + num_of_chars; + + uint32_t num = 0; + + while (num_of_chars--) + { + lit_utf8_byte_t c = **str_p; + if (!lit_char_is_decimal_digit (c)) + { + return ecma_number_make_nan (); + } + + num = (num * 10) + (uint32_t) ((c - LIT_CHAR_0)); + (*str_p)++; + } + + if (num >= ECMA_DATE_LIMIT_MIN (limit) && num <= ECMA_DATE_LIMIT_MAX (limit)) + { + return (ecma_number_t) num; + } + + return ecma_number_make_nan (); +} /* ecma_date_parse_date_chars */ + +/** + * Helper function to try to parse a special character (+,-,T,Z,:,.) in a date string + * + * @return true if the first character is same as the expected, false otherwise + */ +static bool +ecma_date_parse_special_char (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */ + const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */ + ecma_char_t expected_char) /**< expected character */ +{ + if ((*str_p < str_end_p) && (**str_p == expected_char)) + { + (*str_p)++; + return true; + } + + return false; +} /* ecma_date_parse_special_char */ + +static inline bool +ecma_date_check_two_chars (const lit_utf8_byte_t *str_p, /**< pointer to the cesu8 string */ + const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */ + ecma_char_t expected_char1, /**< first expected character */ + ecma_char_t expected_char2) /**< second expected character */ +{ + return (str_p < str_end_p && (*str_p == expected_char1 || *str_p == expected_char2)); +} /* ecma_date_check_two_chars */ + +/** + * Helper function to try to parse a 4-5-6 digit year with optional negative sign in a date string + * + * Date.prototype.toString() and Date.prototype.toUTCString() emits year + * in this format and Date.parse() should parse this format too. + * + * @return the parsed year or NaN. + */ +static ecma_number_t +ecma_date_parse_year (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */ + const lit_utf8_byte_t *str_end_p) /**< pointer to the end of the string */ +{ + bool is_year_sign_negative = ecma_date_parse_special_char (str_p, str_end_p, LIT_CHAR_MINUS); + const lit_utf8_byte_t *str_start_p = *str_p; + int32_t parsed_year = 0; + + while ((str_start_p - *str_p < 6) && (str_start_p < str_end_p) && lit_char_is_decimal_digit (*str_start_p)) + { + parsed_year = 10 * parsed_year + *str_start_p - LIT_CHAR_0; + str_start_p++; + } + + if (str_start_p - *str_p >= 4) + { + *str_p = str_start_p; + return is_year_sign_negative ? -parsed_year : parsed_year; + } + + return ecma_number_make_nan (); +} /* ecma_date_parse_year */ + +/** + * Helper function to try to parse a day name in a date string + * Valid day names: Sun, Mon, Tue, Wed, Thu, Fri, Sat + * See also: + * ECMA-262 v9, 20.3.4.41.2 Table 46 + * + * @return true if the string starts with a valid day name, false otherwise + */ +static bool +ecma_date_parse_day_name (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */ + const lit_utf8_byte_t *str_end_p) /**< pointer to the end of the string */ +{ + if (*str_p + 3 < str_end_p) + { + for (uint32_t i = 0; i < 7; i++) + { + if (!memcmp (day_names_p[i], *str_p, 3)) + { + (*str_p) += 3; + return true; + } + } + } + return false; +} /* ecma_date_parse_day_name */ + +/** + * Helper function to try to parse a month name in a date string + * Valid month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec + * See also: + * ECMA-262 v9, 20.3.4.41.2 Table 47 + * + * @return number of the month if the string starts with a valid month name, 0 otherwise + */ +static uint32_t +ecma_date_parse_month_name (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */ + const lit_utf8_byte_t *str_end_p) /**< pointer to the end of the string */ +{ + if (*str_p + 3 < str_end_p) + { + for (uint32_t i = 0; i < 12; i++) + { + if (!memcmp (month_names_p[i], *str_p, 3)) + { + (*str_p) += 3; + return (i + 1); + } + } + } + return 0; +} /* ecma_date_parse_month_name */ + +/** + * Calculate MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)) for Date constructor and UTC + * + * See also: + * ECMA-262 v11, 20.4.3.4 + * + * @return false - if the operation fails + * true - otherwise + */ +static bool +ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to the Date constructor */ + uint32_t args_len, /**< number of arguments */ + ecma_number_t *tv_p) /**< [out] time value */ +{ + ecma_number_t date_nums[7] = { + ECMA_NUMBER_ZERO, /* year */ + ECMA_NUMBER_ZERO, /* month */ + ECMA_NUMBER_ONE, /* date */ + ECMA_NUMBER_ZERO, /* hours */ + ECMA_NUMBER_ZERO, /* minutes */ + ECMA_NUMBER_ZERO, /* seconds */ + ECMA_NUMBER_ZERO /* milliseconds */ + }; + + args_len = JERRY_MIN (args_len, sizeof (date_nums) / sizeof (date_nums[0])); + + /* 1-7. */ + for (uint32_t i = 0; i < args_len; i++) + { + ecma_value_t status = ecma_op_to_number (args[i], date_nums + i); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return false; + } + } + + /* 8. */ + if (!ecma_number_is_nan (date_nums[0])) + { + /* 9.a */ + ecma_number_t yi = ecma_number_trunc (date_nums[0]); + + /* 9.b */ + if (yi >= 0 && yi <= 99) + { + date_nums[0] = 1900 + yi; + } + } + + /* 10. */ + *tv_p = ecma_date_make_date (ecma_date_make_day (date_nums[0], date_nums[1], date_nums[2]), + ecma_date_make_time (date_nums[3], date_nums[4], date_nums[5], date_nums[6])); + return true; +} /* ecma_date_construct_helper */ + +/** + * Helper function used by ecma_builtin_date_parse + * + * See also: + * ECMA-262 v5, 15.9.4.2 Date.parse (string) + * ECMA-262 v5, 15.9.1.15 Date Time String Format + * + * @return the parsed date as ecma_number_t or NaN otherwise + */ +static ecma_number_t +ecma_builtin_date_parse_basic (const lit_utf8_byte_t *date_str_curr_p, /**< date string start */ + const lit_utf8_byte_t *date_str_end_p) /**< date string end */ +{ + /* 1. read year */ + + uint32_t year_digits = 4; + uint32_t year_limit = 9999; + + bool is_year_sign_negative = false; + + if (ecma_date_check_two_chars (date_str_curr_p, date_str_end_p, LIT_CHAR_MINUS, LIT_CHAR_PLUS)) + { + is_year_sign_negative = (*date_str_curr_p++ == LIT_CHAR_MINUS); + year_digits = 6; + year_limit = 999999; + } + + ecma_number_t year = + ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, year_digits, ECMA_DATE_LIMIT (0, year_limit)); + if (is_year_sign_negative) + { + year = -year; + } + + if (ecma_number_is_nan (year)) + { + return year; + } + + ecma_number_t month = ECMA_NUMBER_ONE; + ecma_number_t day = ECMA_NUMBER_ONE; + ecma_number_t time = ECMA_NUMBER_ZERO; + + /* 2. read month if any */ + if (ecma_date_check_two_chars (date_str_curr_p, date_str_end_p, LIT_CHAR_MINUS, LIT_CHAR_SLASH)) + { + lit_utf8_byte_t separator = *date_str_curr_p++; + month = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (1, 12)); + + /* 3. read day if any */ + if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, separator)) + { + day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (1, 31)); + } + } + + bool is_utc = true; + /* 4. read time if any */ + if (ecma_date_check_two_chars (date_str_curr_p, date_str_end_p, LIT_CHAR_UPPERCASE_T, LIT_CHAR_SP)) + { + date_str_curr_p++; + + ecma_number_t hours = ECMA_NUMBER_ZERO; + ecma_number_t minutes = ECMA_NUMBER_ZERO; + ecma_number_t seconds = ECMA_NUMBER_ZERO; + ecma_number_t milliseconds = ECMA_NUMBER_ZERO; + + /* 'HH:mm' must present */ + if (date_str_end_p - date_str_curr_p < 5) + { + return ecma_number_make_nan (); + } + + /* 4.1 read hours and minutes */ + hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 24)); + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_COLON)) + { + return ecma_number_make_nan (); + } + + minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 59)); + + /* 4.2 read seconds if any */ + if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_COLON)) + { + seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 59)); + + /* 4.3 read milliseconds if any */ + if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_DOT)) + { + milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3, ECMA_DATE_LIMIT (0, 999)); + } + } + + if (hours == 24 && (minutes != 0 || seconds != 0 || milliseconds != 0)) + { + return ecma_number_make_nan (); + } + + time = ecma_date_make_time (hours, minutes, seconds, milliseconds); + + if (ecma_number_is_nan (time)) + { + return time; + } + + /* 4.4 read timezone if any */ + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_UPPERCASE_Z)) + { + if ((date_str_end_p - date_str_curr_p) == 6 + && (*date_str_curr_p == LIT_CHAR_MINUS || *date_str_curr_p == LIT_CHAR_PLUS)) + { + bool is_timezone_sign_negative = (*date_str_curr_p++ == LIT_CHAR_MINUS); + /* read hours and minutes */ + hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 24)); + + if (hours == 24) + { + hours = ECMA_NUMBER_ZERO; + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_COLON)) + { + return ecma_number_make_nan (); + } + + minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 59)); + ecma_number_t timezone_offset = ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO); + time += is_timezone_sign_negative ? timezone_offset : -timezone_offset; + } + else + { + is_utc = false; + } + } + } + + if (date_str_curr_p < date_str_end_p) + { + return ecma_number_make_nan (); + } + + ecma_number_t date = ecma_date_make_day (year, month - 1, day); + ecma_number_t result_date = ecma_date_make_date (date, time); + + if (!is_utc) + { + result_date = ecma_date_utc (result_date); + } + + return result_date; +} /* ecma_builtin_date_parse_basic */ + +/** + * Helper function used by ecma_builtin_date_parse + * + * See also: + * ECMA-262 v5, 15.9.4.2 Date.parse (string) + * ECMA-262 v9, 20.3.4.41 Date.prototype.toString () + * ECMA-262 v9, 20.3.4.43 Date.prototype.toUTCString () + * + * Used by: ecma_builtin_date_parse + * + * @return the parsed date as ecma_number_t or NaN otherwise + */ +static ecma_number_t +ecma_builtin_date_parse_toString_formats (const lit_utf8_byte_t *date_str_curr_p, const lit_utf8_byte_t *date_str_end_p) +{ + const ecma_number_t nan = ecma_number_make_nan (); + + if (!ecma_date_parse_day_name (&date_str_curr_p, date_str_end_p)) + { + return nan; + } + + const bool is_toUTCString_format = ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_COMMA); + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_SP)) + { + return nan; + } + + ecma_number_t month = 0; + ecma_number_t day = 0; + if (is_toUTCString_format) + { + day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 31)); + + if (ecma_number_is_nan (day)) + { + return nan; + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_SP)) + { + return nan; + } + + month = ecma_date_parse_month_name (&date_str_curr_p, date_str_end_p); + + if (month == 0) + { + return ecma_number_make_nan (); + } + } + else + { + month = ecma_date_parse_month_name (&date_str_curr_p, date_str_end_p); + + if (month == 0) + { + return nan; + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_SP)) + { + return nan; + } + + day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 31)); + + if (ecma_number_is_nan (day)) + { + return nan; + } + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_SP)) + { + return nan; + } + + ecma_number_t year = ecma_date_parse_year (&date_str_curr_p, date_str_end_p); + + if (ecma_number_is_nan (year)) + { + return nan; + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_SP)) + { + return nan; + } + + ecma_number_t hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 24)); + + if (ecma_number_is_nan (hours)) + { + return nan; + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_COLON)) + { + return nan; + } + + ecma_number_t minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 59)); + + if (ecma_number_is_nan (minutes)) + { + return nan; + } + + if (!ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, LIT_CHAR_COLON)) + { + return nan; + } + + ecma_number_t seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 59)); + + if (ecma_number_is_nan (seconds)) + { + return nan; + } + + if (hours == 24 && (minutes != 0 || seconds != 0)) + { + return nan; + } + + const char gmt_p[] = " GMT"; + if (date_str_end_p - date_str_curr_p < 4 || memcmp (date_str_curr_p, gmt_p, 4) != 0) + { + return nan; + } + + date_str_curr_p += 4; + + ecma_number_t time = ecma_date_make_time (hours, minutes, seconds, 0); + + if (!is_toUTCString_format) + { + if (!ecma_date_check_two_chars (date_str_curr_p, date_str_end_p, LIT_CHAR_MINUS, LIT_CHAR_PLUS)) + { + return nan; + } + + bool is_timezone_sign_negative = (*date_str_curr_p++ == LIT_CHAR_MINUS); + + hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 24)); + + if (ecma_number_is_nan (hours)) + { + return nan; + } + + if (hours == 24) + { + hours = ECMA_NUMBER_ZERO; + } + + minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, ECMA_DATE_LIMIT (0, 59)); + + if (ecma_number_is_nan (minutes)) + { + return nan; + } + + ecma_number_t timezone_offset = ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO); + + time += is_timezone_sign_negative ? timezone_offset : -timezone_offset; + } + + if (date_str_curr_p < date_str_end_p) + { + return nan; + } + + ecma_number_t date = ecma_date_make_day (year, month - 1, day); + return ecma_date_make_date (date, time); +} /* ecma_builtin_date_parse_toString_formats */ + +/** + * The Date object's 'parse' routine + * + * See also: + * ECMA-262 v5, 15.9.4.2 Date.parse (string) + * ECMA-262 v5, 15.9.1.15 Date Time String Format + * ECMA-262 v9, 20.3.4.41 Date.prototype.toString () + * ECMA-262 v9, 20.3.4.43 Date.prototype.toUTCString () + * + * @return parsed time + */ +static ecma_number_t +ecma_builtin_date_parse (ecma_string_t *string_p) /**< string */ +{ + ECMA_STRING_TO_UTF8_STRING (string_p, str_p, str_size); + const lit_utf8_byte_t *date_str_curr_p = str_p; + const lit_utf8_byte_t *date_str_end_p = str_p + str_size; + + /* try to parse date string as ISO string - ECMA-262 v5, 15.9.1.15 */ + ecma_number_t tv = ecma_builtin_date_parse_basic (date_str_curr_p, date_str_end_p); + + if (ecma_number_is_nan (tv)) + { + /* try to parse date string in Date.prototype.toString() or toUTCString() format */ + tv = ecma_builtin_date_parse_toString_formats (date_str_curr_p, date_str_end_p); + } + + ECMA_FINALIZE_UTF8_STRING (str_p, str_size); + + return tv; +} /* ecma_builtin_date_parse */ + +/** + * The Date object's 'UTC' routine + * + * See also: + * ECMA-262 v5, 15.9.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_date_utc (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (args_number < 1) + { + return ecma_make_nan_value (); + } + + ecma_number_t tv; + + if (!ecma_date_construct_helper (args, args_number, &tv)) + { + return ECMA_VALUE_ERROR; + } + + return ecma_make_number_value ((ecma_number_t) ecma_date_time_clip (tv)); +} /* ecma_builtin_date_utc */ + +/** + * Helper method to get the current time + * + * @return ecma_number_t + */ +static ecma_number_t +ecma_builtin_date_now_helper (void) +{ + return floor (DOUBLE_TO_ECMA_NUMBER_T (jerry_port_current_time ())); +} /* ecma_builtin_date_now_helper */ + +/** + * Construct a date object with the given [[DateValue]] + * + * Note: New target must be a valid object + * + * @return ECMA_VALUE_ERROR - if the operation fails + * constructed date object - otherwise + */ +static ecma_value_t +ecma_builtin_date_create (ecma_number_t tv) +{ + JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p) != NULL); + + ecma_object_t *prototype_obj_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_DATE_PROTOTYPE); + + if (JERRY_UNLIKELY (prototype_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, sizeof (ecma_date_object_t), ECMA_OBJECT_TYPE_CLASS); + ecma_deref_object (prototype_obj_p); + + ecma_date_object_t *date_object_p = (ecma_date_object_t *) obj_p; + date_object_p->header.u.cls.type = ECMA_OBJECT_CLASS_DATE; + date_object_p->header.u.cls.u1.date_flags = ECMA_DATE_TZA_NONE; + date_object_p->header.u.cls.u3.tza = 0; + date_object_p->date_value = tv; + + return ecma_make_object_value (obj_p); +} /* ecma_builtin_date_create */ + +/** + * Handle calling [[Call]] of built-in Date object + * + * See also: + * ECMA-262 v5, 15.9.2.1 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_date_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_UNUSED (arguments_list_p); + JERRY_UNUSED (arguments_list_len); + + return ecma_date_value_to_string (ecma_builtin_date_now_helper ()); +} /* ecma_builtin_date_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Date object + * + * See also: + * ECMA-262 v5, 15.9.3.1 + * ECMA-262 v11, 20.4.2 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + /* 20.4.2.3 */ + if (arguments_list_len == 0) + { + return ecma_builtin_date_create (ecma_builtin_date_now_helper ()); + } + + ecma_number_t tv; + /* 20.4.2.2 */ + if (arguments_list_len == 1) + { + ecma_value_t argument = arguments_list_p[0]; + + /* 4.a */ + if (ecma_is_value_object (argument) + && ecma_object_class_is (ecma_get_object_from_value (argument), ECMA_OBJECT_CLASS_DATE)) + { + return ecma_builtin_date_create (((ecma_date_object_t *) ecma_get_object_from_value (argument))->date_value); + } + /* 4.b */ + ecma_value_t primitive = ecma_op_to_primitive (argument, ECMA_PREFERRED_TYPE_NO); + + if (ECMA_IS_VALUE_ERROR (primitive)) + { + return primitive; + } + + if (ecma_is_value_string (primitive)) + { + ecma_string_t *prim_str_p = ecma_get_string_from_value (primitive); + tv = ecma_builtin_date_parse (prim_str_p); + ecma_deref_ecma_string (prim_str_p); + } + else + { + ecma_value_t prim_value = ecma_op_to_number (primitive, &tv); + ecma_free_value (primitive); + + if (ECMA_IS_VALUE_ERROR (prim_value)) + { + return prim_value; + } + } + } + /* 20.4.2.1 */ + else if (ecma_date_construct_helper (arguments_list_p, arguments_list_len, &tv)) + { + tv = ecma_date_utc (tv); + } + else + { + return ECMA_VALUE_ERROR; + } + + return ecma_builtin_date_create (ecma_date_time_clip (tv)); +} /* ecma_builtin_date_dispatch_construct */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_date_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (this_arg); + + switch (builtin_routine_id) + { + case ECMA_DATE_ROUTINE_NOW: + { + return ecma_make_number_value (ecma_builtin_date_now_helper ()); + } + case ECMA_DATE_ROUTINE_UTC: + { + return ecma_builtin_date_utc (arguments_list_p, arguments_number); + } + case ECMA_DATE_ROUTINE_PARSE: + { + if (arguments_number < 1) + { + return ecma_make_nan_value (); + } + + ecma_string_t *str_p = ecma_op_to_string (arguments_list_p[0]); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_make_number_value (ecma_date_time_clip (ecma_builtin_date_parse (str_p))); + ecma_deref_ecma_string (str_p); + + return result; + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_date_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_DATE */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h new file mode 100644 index 0000000..a50ac00 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Date built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_DATE + +/* ECMA-262 v5, 15.9.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_DATE_PROTOTYPE, ECMA_PROPERTY_FIXED) + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 7, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +ROUTINE (LIT_MAGIC_STRING_PARSE, ECMA_DATE_ROUTINE_PARSE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_UTC_U, ECMA_DATE_ROUTINE_UTC, NON_FIXED, 7) +ROUTINE (LIT_MAGIC_STRING_NOW, ECMA_DATE_ROUTINE_NOW, 0, 0) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_DATE_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_DATE */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.cpp new file mode 100644 index 0000000..db69f1b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.cpp @@ -0,0 +1,180 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" +#include "lit-char-helpers.h" +#include "lit-magic-strings.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_ERROR_PROTOTYPE_ROUTINE_START = 0, + ECMA_ERROR_PROTOTYPE_ROUTINE_TO_STRING, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-error-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup errorprototype ECMA Error.prototype object built-in + * @{ + */ + +/** + * Helper method to get a property value from an error object + * + * @return ecma_string_t + */ +static ecma_string_t * +ecma_builtin_error_prototype_object_to_string_helper (ecma_object_t *obj_p, /**< error object */ + lit_magic_string_id_t property_id, /**< property id */ + lit_magic_string_id_t default_value) /**< default prop value */ +{ + ecma_value_t prop_value = ecma_op_object_get_by_magic_id (obj_p, property_id); + + if (ECMA_IS_VALUE_ERROR (prop_value)) + { + return NULL; + } + + if (ecma_is_value_undefined (prop_value)) + { + return ecma_get_magic_string (default_value); + } + + ecma_string_t *ret_str_p = ecma_op_to_string (prop_value); + ecma_free_value (prop_value); + + return ret_str_p; +} /* ecma_builtin_error_prototype_object_to_string_helper */ + +/** + * The Error.prototype object's 'toString' routine + * + * See also: + * ECMA-262 v5, 15.11.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */ +{ + /* 2. */ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (this_arg); + + ecma_string_t *name_string_p = + ecma_builtin_error_prototype_object_to_string_helper (obj_p, LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ERROR_UL); + + if (JERRY_UNLIKELY (name_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_string_t *msg_string_p = + ecma_builtin_error_prototype_object_to_string_helper (obj_p, LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY); + + if (JERRY_UNLIKELY (msg_string_p == NULL)) + { + ecma_deref_ecma_string (name_string_p); + return ECMA_VALUE_ERROR; + } + + if (ecma_string_is_empty (name_string_p)) + { + return ecma_make_string_value (msg_string_p); + } + + if (ecma_string_is_empty (msg_string_p)) + { + return ecma_make_string_value (name_string_p); + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (name_string_p); + + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) ": ", 2); + ecma_stringbuilder_append (&builder, msg_string_p); + + ecma_deref_ecma_string (name_string_p); + ecma_deref_ecma_string (msg_string_p); + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_error_prototype_object_to_string */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_error_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments passed to + * routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_number, arguments_list_p); + + switch (builtin_routine_id) + { + case ECMA_ERROR_PROTOTYPE_ROUTINE_TO_STRING: + { + return ecma_builtin_error_prototype_object_to_string (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_error_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h new file mode 100644 index 0000000..751094c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Error.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.4.2 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.4.3 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_ERROR_PROTOTYPE_ROUTINE_TO_STRING, 0, 0) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.cpp new file mode 100644 index 0000000..846186a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.cpp @@ -0,0 +1,93 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-error.inc.h" +#define BUILTIN_UNDERSCORED_ID error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup error ECMA Error object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Error object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_COMMON, arguments_list_p, arguments_list_len); +} /* ecma_builtin_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Error object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h new file mode 100644 index 0000000..d8cff1b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h @@ -0,0 +1,35 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Error built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.7.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.cpp new file mode 100644 index 0000000..3758803 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.cpp @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-evalerror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID eval_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h new file mode 100644 index 0000000..1f13dd2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * EvalError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_EVAL_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_EVAL_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.cpp new file mode 100644 index 0000000..341d179 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.cpp @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-evalerror.inc.h" +#define BUILTIN_UNDERSCORED_ID eval_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup evalerror ECMA EvalError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in EvalError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_eval_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_EVAL, arguments_list_p, arguments_list_len); +} /* ecma_builtin_eval_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in EvalError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_eval_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_eval_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_eval_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h new file mode 100644 index 0000000..29c8f96 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * EvalError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_EVAL_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp new file mode 100644 index 0000000..39afb4b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.cpp @@ -0,0 +1,452 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-function-prototype.h" + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-extended-info.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-proxy-object.h" + +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_FUNCTION_PROTOTYPE_ROUTINE_START = 0, + ECMA_FUNCTION_PROTOTYPE_TO_STRING, + ECMA_FUNCTION_PROTOTYPE_CALL, + ECMA_FUNCTION_PROTOTYPE_APPLY, + ECMA_FUNCTION_PROTOTYPE_BIND, + ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID function_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup functionprototype ECMA Function.prototype object built-in + * @{ + */ + +/** + * Maximum number of arguments for an apply function. + */ +#define ECMA_FUNCTION_APPLY_ARGUMENT_COUNT_LIMIT 65535 + +/** + * The Function.prototype object's 'toString' routine + * + * See also: + * ECMA-262 v5, 15.3.4.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_function_prototype_object_to_string (ecma_object_t *func_obj_p) /**< this argument object */ +{ + if (ecma_get_object_type (func_obj_p) != ECMA_OBJECT_TYPE_FUNCTION) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_FUNCTION_TO_STRING_NATIVE); + } + + return ecma_make_magic_string_value (LIT_MAGIC_STRING_FUNCTION_TO_STRING_ECMA); +} /* ecma_builtin_function_prototype_object_to_string */ + +/** + * The Function.prototype object's 'apply' routine + * + * See also: + * ECMA-262 v5, 15.3.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< this argument object */ + ecma_value_t arg1, /**< first argument */ + ecma_value_t arg2) /**< second argument */ +{ + /* 2. */ + if (ecma_is_value_null (arg2) || ecma_is_value_undefined (arg2)) + { + return ecma_op_function_call (func_obj_p, arg1, NULL, 0); + } + + /* 3. */ + if (!ecma_is_value_object (arg2)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (arg2); + + /* 4-5. */ + ecma_length_t length; + ecma_value_t len_value = ecma_op_object_get_length (obj_p, &length); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + return len_value; + } + + if (length >= ECMA_FUNCTION_APPLY_ARGUMENT_COUNT_LIMIT) + { + return ecma_raise_range_error (ECMA_ERR_TOO_MANY_ARGUMENTS_DECLARED_FOR_FUNCTION_APPLY); + } + + /* 6. */ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + JMEM_DEFINE_LOCAL_ARRAY (arguments_list_p, length, ecma_value_t); + ecma_length_t index = 0; + + /* 7. */ + for (index = 0; index < length; index++) + { + ecma_value_t get_value = ecma_op_object_get_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + ret_value = get_value; + break; + } + + arguments_list_p[index] = get_value; + } + + if (ecma_is_value_empty (ret_value)) + { + JERRY_ASSERT (index == length); + ret_value = ecma_op_function_call (func_obj_p, arg1, arguments_list_p, (uint32_t) length); + } + + for (uint32_t remove_index = 0; remove_index < index; remove_index++) + { + ecma_free_value (arguments_list_p[remove_index]); + } + + JMEM_FINALIZE_LOCAL_ARRAY (arguments_list_p); + + return ret_value; +} /* ecma_builtin_function_prototype_object_apply */ + +/** + * The Function.prototype object's 'call' routine + * + * See also: + * ECMA-262 v5, 15.3.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_function_prototype_object_call (ecma_object_t *func_obj_p, /**< this argument object */ + const ecma_value_t *arguments_list_p, /**< list of arguments */ + uint32_t arguments_number) /**< number of arguments */ +{ + if (arguments_number == 0) + { + /* Even a 'this' argument is missing. */ + return ecma_op_function_call (func_obj_p, ECMA_VALUE_UNDEFINED, NULL, 0); + } + + return ecma_op_function_call (func_obj_p, + arguments_list_p[0], + arguments_list_p + 1, + (uint32_t) (arguments_number - 1u)); +} /* ecma_builtin_function_prototype_object_call */ + +/** + * The Function.prototype object's 'bind' routine + * + * See also: + * ECMA-262 v5, 15.3.4.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_function_prototype_object_bind (ecma_object_t *this_arg_obj_p, /**< this argument object */ + const ecma_value_t *arguments_list_p, /**< list of arguments */ + uint32_t arguments_number) /**< number of arguments */ +{ + /* 4. 11. 18. */ + ecma_object_t *prototype_obj_p; + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (this_arg_obj_p)) + { + ecma_value_t proto = ecma_proxy_object_get_prototype_of (this_arg_obj_p); + + if (ECMA_IS_VALUE_ERROR (proto)) + { + return proto; + } + prototype_obj_p = ecma_is_value_null (proto) ? NULL : ecma_get_object_from_value (proto); + } + else + { +#endif /* JERRY_BUILTIN_PROXY */ + jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (this_arg_obj_p); + if (proto_cp != JMEM_CP_NULL) + { + prototype_obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp); + ecma_ref_object (prototype_obj_p); + } + else + { + prototype_obj_p = NULL; + } +#if JERRY_BUILTIN_PROXY + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_object_t *function_p; + ecma_bound_function_t *bound_func_p; + + if (arguments_number == 0 || (arguments_number == 1 && !ecma_is_value_integer_number (arguments_list_p[0]))) + { + function_p = ecma_create_object (prototype_obj_p, sizeof (ecma_bound_function_t), ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + /* 8. */ + bound_func_p = (ecma_bound_function_t *) function_p; + ECMA_SET_NON_NULL_POINTER_TAG (bound_func_p->header.u.bound_function.target_function, this_arg_obj_p, 0); + + bound_func_p->header.u.bound_function.args_len_or_this = ECMA_VALUE_UNDEFINED; + + if (arguments_number != 0) + { + bound_func_p->header.u.bound_function.args_len_or_this = ecma_copy_value_if_not_object (arguments_list_p[0]); + } + } + else + { + JERRY_ASSERT (arguments_number > 0); + + size_t obj_size = sizeof (ecma_bound_function_t) + (arguments_number * sizeof (ecma_value_t)); + + function_p = ecma_create_object (prototype_obj_p, obj_size, ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + /* 8. */ + bound_func_p = (ecma_bound_function_t *) function_p; + ECMA_SET_NON_NULL_POINTER_TAG (bound_func_p->header.u.bound_function.target_function, this_arg_obj_p, 0); + + /* NOTE: This solution provides temporary false data about the object's size + but prevents GC from freeing it until it's not fully initialized. */ + bound_func_p->header.u.bound_function.args_len_or_this = ECMA_VALUE_UNDEFINED; + ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1); + + for (uint32_t i = 0; i < arguments_number; i++) + { + *args_p++ = ecma_copy_value_if_not_object (arguments_list_p[i]); + } + + ecma_value_t args_len_or_this = ecma_make_integer_value ((ecma_integer_value_t) arguments_number); + bound_func_p->header.u.bound_function.args_len_or_this = args_len_or_this; + } + + if (prototype_obj_p != NULL) + { + ecma_deref_object (prototype_obj_p); + } + + bound_func_p->target_length = ecma_make_integer_value (0); + + ecma_string_t *len_string = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH); + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (this_arg_obj_p, len_string, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_deref_object (function_p); + return status; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_true (status)) + { + ecma_free_property_descriptor (&prop_desc); + ecma_value_t len_value = ecma_op_object_get (this_arg_obj_p, len_string); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + ecma_deref_object (function_p); + return len_value; + } + + if (ecma_is_value_number (len_value)) + { + ecma_number_t len_num; + ecma_op_to_integer (len_value, &len_num); + bound_func_p->target_length = ecma_make_number_value (len_num); + } + ecma_free_value (len_value); + } + + /* 12. */ + ecma_value_t name_value = ecma_op_object_get_by_magic_id (this_arg_obj_p, LIT_MAGIC_STRING_NAME); + if (ECMA_IS_VALUE_ERROR (name_value)) + { + ecma_deref_object (function_p); + return name_value; + } + + ecma_string_t *name_p; + + if (ecma_is_value_string (name_value)) + { + name_p = ecma_get_string_from_value (name_value); + } + else + { + ecma_free_value (name_value); + name_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_value_t bound_function_name = ecma_op_function_form_name (name_p, (char*)"bound ", 6); + + ecma_deref_ecma_string (name_p); + + ecma_property_value_t *name_prop_value_p; + name_prop_value_p = ecma_create_named_data_property (function_p, + ecma_get_magic_string (LIT_MAGIC_STRING_NAME), + ECMA_PROPERTY_FLAG_CONFIGURABLE, + NULL); + + name_prop_value_p->value = bound_function_name; + + /* + * [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_FUNCTION type. + * + * See also: ecma_object_get_class_name + */ + + /* 22. */ + return ecma_make_object_value (function_p); +} /* ecma_builtin_function_prototype_object_bind */ + +/** + * Handle calling [[Call]] of built-in Function.prototype object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_function_prototype_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ECMA_VALUE_UNDEFINED; +} /* ecma_builtin_function_prototype_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Function.prototype object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_function_prototype_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_FUNCTION_PROTOTYPE_NOT_A_CONSTRUCTOR); +} /* ecma_builtin_function_prototype_dispatch_construct */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_function_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + if (!ecma_op_is_callable (this_arg)) + { + if (JERRY_UNLIKELY (builtin_routine_id == ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE)) + { + return ECMA_VALUE_FALSE; + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_FUNCTION); + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (this_arg); + + switch (builtin_routine_id) + { + case ECMA_FUNCTION_PROTOTYPE_TO_STRING: + { + return ecma_builtin_function_prototype_object_to_string (func_obj_p); + } + case ECMA_FUNCTION_PROTOTYPE_APPLY: + { + return ecma_builtin_function_prototype_object_apply (func_obj_p, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_FUNCTION_PROTOTYPE_CALL: + { + return ecma_builtin_function_prototype_object_call (func_obj_p, arguments_list_p, arguments_number); + } + case ECMA_FUNCTION_PROTOTYPE_BIND: + { + return ecma_builtin_function_prototype_object_bind (func_obj_p, arguments_list_p, arguments_number); + } + case ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE: + { + return ecma_op_object_has_instance (func_obj_p, arguments_list_p[0]); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_function_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.h new file mode 100644 index 0000000..363681f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.h @@ -0,0 +1,24 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BUILTIN_FUNCTION_PROTOTYPE_H +#define ECMA_BUILTIN_FUNCTION_PROTOTYPE_H + +#include "ecma-globals.h" + +ecma_value_t +ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, ecma_value_t arg1, ecma_value_t arg2); + +#endif /* !ECMA_BUILTIN_FUNCTION_PROTOTYPE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h new file mode 100644 index 0000000..8bab444 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h @@ -0,0 +1,55 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Function.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.3.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_FUNCTION, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Number properties: + * (property name, object pointer getter) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_FUNCTION_PROTOTYPE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_APPLY, ECMA_FUNCTION_PROTOTYPE_APPLY, 2, 2) +ROUTINE (LIT_MAGIC_STRING_CALL, ECMA_FUNCTION_PROTOTYPE_CALL, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_BIND, ECMA_FUNCTION_PROTOTYPE_BIND, NON_FIXED, 1) + +/** + * ECMA-262 v6.0 19.2.3.6 @@hasInstance + * the property attributes are: { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. + */ +ROUTINE_WITH_FLAGS (LIT_GLOBAL_SYMBOL_HAS_INSTANCE, ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE, 1, 1, 0 /* flags */) +ACCESSOR_BUILTIN_FUNCTION (LIT_MAGIC_STRING_ARGUMENTS, + ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, + ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) +ACCESSOR_BUILTIN_FUNCTION (LIT_MAGIC_STRING_CALLER, + ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, + ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp new file mode 100644 index 0000000..7c8e1df --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-conversion.h" +#include "ecma-eval.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-lex-env.h" + +#include "js-parser.h" +#include "lit-magic-strings.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function.inc.h" +#define BUILTIN_UNDERSCORED_ID function +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup function ECMA Function object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Function object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len); +} /* ecma_builtin_function_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Function object + * + * See also: + * ECMA-262 v5, 15.3. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_op_create_dynamic_function (arguments_list_p, arguments_list_len, ECMA_PARSE_NO_OPTS); +} /* ecma_builtin_function_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h new file mode 100644 index 0000000..92e50ed --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h @@ -0,0 +1,34 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Function built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.3.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* Number properties: + * (property name, object pointer getter) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-function.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-function.cpp new file mode 100644 index 0000000..acb25ee --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-function.cpp @@ -0,0 +1,68 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" +#include "ecma-function-object.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-generator-function.inc.h" +#define BUILTIN_UNDERSCORED_ID generator_function +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup generatorfunction ECMA GeneratorFunction object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in GeneratorFunction object + * + * @return constructed generator function object - if success + * raised error otherwise + */ +ecma_value_t +ecma_builtin_generator_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_dynamic_function (arguments_list_p, arguments_list_len, ECMA_PARSE_GENERATOR_FUNCTION); +} /* ecma_builtin_generator_function_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in GeneratorFunction object + * + * @return constructed generator function object - if success + * raised error otherwise + */ +ecma_value_t +ecma_builtin_generator_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_generator_function_dispatch_call (arguments_list_p, arguments_list_len); +} /* ecma_builtin_generator_function_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-function.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-function.inc.h new file mode 100644 index 0000000..39416a9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-function.inc.h @@ -0,0 +1,31 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %GeneratorFunction% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ECMA-262 v6, 25.2.2 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.2.2.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.2.2.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_GENERATOR, ECMA_PROPERTY_FIXED) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.cpp new file mode 100644 index 0000000..da6269d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.cpp @@ -0,0 +1,258 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" + +#include "jcontext.h" +#include "opcodes.h" +#include "vm-defines.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_GENERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_GENERATOR_PROTOTYPE_ROUTINE_NEXT, + ECMA_GENERATOR_PROTOTYPE_ROUTINE_THROW, + ECMA_GENERATOR_PROTOTYPE_ROUTINE_RETURN +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-generator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID generator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup generatorprototype ECMA Generator.prototype object built-in + * @{ + */ + +/** + * Convert routine type to operation type. + */ +#define ECMA_GENERATOR_ROUTINE_TO_OPERATION(type) \ + ((ecma_iterator_command_type_t) ((type) -ECMA_GENERATOR_PROTOTYPE_ROUTINE_NEXT)) + +JERRY_STATIC_ASSERT ((ECMA_GENERATOR_ROUTINE_TO_OPERATION (ECMA_GENERATOR_PROTOTYPE_ROUTINE_NEXT) == ECMA_ITERATOR_NEXT), + convert_ecma_generator_routine_next_to_ecma_iterator_next_failed); + +JERRY_STATIC_ASSERT ((ECMA_GENERATOR_ROUTINE_TO_OPERATION (ECMA_GENERATOR_PROTOTYPE_ROUTINE_THROW) == ECMA_ITERATOR_THROW), + convert_ecma_generator_routine_throw_to_ecma_iterator_throw_failed); + +JERRY_STATIC_ASSERT ((ECMA_GENERATOR_ROUTINE_TO_OPERATION (ECMA_GENERATOR_PROTOTYPE_ROUTINE_RETURN) == ECMA_ITERATOR_RETURN), + convert_ecma_generator_routine_return_to_ecma_iterator_return_failed); + +/** + * Helper function for next / return / throw + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_generator_prototype_object_do (vm_executable_object_t *generator_object_p, /**< generator object */ + ecma_value_t arg, /**< argument */ + ecma_iterator_command_type_t resume_mode) /**< resume mode */ +{ + arg = ecma_copy_value (arg); + + while (true) + { + if (generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD) + { + if (generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_RUNNING) + { + return ecma_raise_type_error (ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION); + } + + ecma_value_t iterator = generator_object_p->iterator; + ecma_value_t next_method = generator_object_p->frame_ctx.stack_top_p[-1]; + + bool done = false; + + generator_object_p->extended_object.u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_RUNNING; + ecma_value_t result = ecma_op_iterator_do (resume_mode, iterator, next_method, arg, &done); + ecma_free_value (arg); + generator_object_p->extended_object.u.cls.u2.executable_obj_flags &= (uint8_t) ~ECMA_EXECUTABLE_OBJECT_RUNNING; + + if (ECMA_IS_VALUE_ERROR (result)) + { + arg = result; + } + else if (done) + { + arg = ecma_op_iterator_value (result); + ecma_free_value (result); + + if (resume_mode == ECMA_ITERATOR_THROW) + { + resume_mode = ECMA_ITERATOR_NEXT; + } + } + else + { + return result; + } + + ECMA_EXECUTABLE_OBJECT_RESUME_EXEC (generator_object_p); + generator_object_p->iterator = ECMA_VALUE_UNDEFINED; + + JERRY_ASSERT (generator_object_p->frame_ctx.stack_top_p[-1] == ECMA_VALUE_UNDEFINED + || ecma_is_value_object (generator_object_p->frame_ctx.stack_top_p[-1])); + generator_object_p->frame_ctx.stack_top_p--; + + if (ECMA_IS_VALUE_ERROR (arg)) + { + arg = jcontext_take_exception (); + resume_mode = ECMA_ITERATOR_THROW; + } + } + + if (resume_mode == ECMA_ITERATOR_RETURN) + { + generator_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_return; + } + else if (resume_mode == ECMA_ITERATOR_THROW) + { + generator_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_throw; + } + + ecma_value_t value = opfunc_resume_executable_object (generator_object_p, arg); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + bool done; + done = (generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED); + + if (!done) + { + const uint8_t *byte_code_p = generator_object_p->frame_ctx.byte_code_p; + + JERRY_ASSERT (byte_code_p[-2] == CBC_EXT_OPCODE + && (byte_code_p[-1] == CBC_EXT_YIELD || byte_code_p[-1] == CBC_EXT_YIELD_ITERATOR)); + + if (byte_code_p[-1] == CBC_EXT_YIELD_ITERATOR) + { + ecma_value_t iterator = + ecma_op_get_iterator (value, ECMA_VALUE_SYNC_ITERATOR, generator_object_p->frame_ctx.stack_top_p); + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (iterator)) + { + resume_mode = ECMA_ITERATOR_THROW; + arg = jcontext_take_exception (); + continue; + } + + ecma_deref_object (ecma_get_object_from_value (iterator)); + generator_object_p->extended_object.u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD; + generator_object_p->iterator = iterator; + + if (generator_object_p->frame_ctx.stack_top_p[0] != ECMA_VALUE_UNDEFINED) + { + ecma_deref_object (ecma_get_object_from_value (generator_object_p->frame_ctx.stack_top_p[0])); + } + + generator_object_p->frame_ctx.stack_top_p++; + arg = ECMA_VALUE_UNDEFINED; + continue; + } + } + + ecma_value_t result = ecma_create_iter_result_object (value, ecma_make_boolean_value (done)); + ecma_fast_free_value (value); + return result; + } +} /* ecma_builtin_generator_prototype_object_do */ + +/** + * Dispatcher of the Generator built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_generator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + vm_executable_object_t *executable_object_p = NULL; + + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_GENERATOR)) + { + executable_object_p = (vm_executable_object_t *) object_p; + } + } + + if (executable_object_p == NULL) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_GENERATOR_OBJECT); + } + + if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_RUNNING) + { + return ecma_raise_type_error (ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION); + } + + if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED) + { + if (builtin_routine_id != ECMA_GENERATOR_PROTOTYPE_ROUTINE_THROW) + { + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + jcontext_raise_exception (ecma_copy_value (arguments_list_p[0])); + return ECMA_VALUE_ERROR; + } + + return ecma_builtin_generator_prototype_object_do (executable_object_p, + arguments_list_p[0], + ECMA_GENERATOR_ROUTINE_TO_OPERATION (builtin_routine_id)); +} /* ecma_builtin_generator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.inc.h new file mode 100644 index 0000000..07086db --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.inc.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Generator.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 25.3.1.5 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_GENERATOR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.2.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_GENERATOR, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_GENERATOR_PROTOTYPE_ROUTINE_NEXT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_RETURN, ECMA_GENERATOR_PROTOTYPE_ROUTINE_RETURN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_THROW, ECMA_GENERATOR_PROTOTYPE_ROUTINE_THROW, 1, 1) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator.cpp new file mode 100644 index 0000000..6d82293 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator.cpp @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-generator.inc.h" +#define BUILTIN_UNDERSCORED_ID generator +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup generator ECMA Generator object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator.inc.h new file mode 100644 index 0000000..b45bd93 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-generator.inc.h @@ -0,0 +1,31 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %Generator% built-in description (GeneratorFunction.prototype) + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ECMA-262 v6, 25.3.2.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_GENERATOR_FUNCTION, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.3.2.3.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 25.3.2.3.3 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp new file mode 100644 index 0000000..d9ccc8f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp @@ -0,0 +1,700 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-eval.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "jcontext.h" +#include "jrt-bit-fields.h" +#include "jrt-libc-includes.h" +#include "jrt.h" +#include "lit-char-helpers.h" +#include "lit-magic-strings.h" +#include "lit-strings.h" +#include "vm.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_GLOBAL_ROUTINE_START = 0, + /* Note: these 5 routine ids must be in this order */ + ECMA_GLOBAL_IS_NAN, + ECMA_GLOBAL_IS_FINITE, + ECMA_GLOBAL_EVAL, + ECMA_GLOBAL_PARSE_INT, + ECMA_GLOBAL_PARSE_FLOAT, + ECMA_GLOBAL_DECODE_URI, + ECMA_GLOBAL_DECODE_URI_COMPONENT, + ECMA_GLOBAL_ENCODE_URI, + ECMA_GLOBAL_ENCODE_URI_COMPONENT, + ECMA_GLOBAL_ESCAPE, + ECMA_GLOBAL_UNESCAPE, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-global.inc.h" +#define BUILTIN_UNDERSCORED_ID global +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup global ECMA Global object built-in + * @{ + */ + +/** + * The Global object's 'eval' routine + * + * See also: + * ECMA-262 v5, 15.1.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument */ +{ + if (JERRY_UNLIKELY (!ecma_is_value_string (x))) + { + /* step 1 */ + return ecma_copy_value (x); + } + + uint32_t parse_opts = vm_is_direct_eval_form_call () ? ECMA_PARSE_DIRECT_EVAL : ECMA_PARSE_NO_OPTS; + + /* See also: ECMA-262 v5, 10.1.1 */ + if (parse_opts && vm_is_strict_mode ()) + { + JERRY_ASSERT (parse_opts & ECMA_PARSE_DIRECT_EVAL); + parse_opts |= ECMA_PARSE_STRICT_MODE; + } + + if (vm_is_direct_eval_form_call ()) + { + parse_opts |= ECMA_GET_LOCAL_PARSE_OPTS (); + } + + /* steps 2 to 8 */ + return ecma_op_eval (x, parse_opts); +} /* ecma_builtin_global_object_eval */ + +/** + * The Global object's 'isNaN' routine + * + * See also: + * ECMA-262 v5, 15.1.2.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_is_nan (ecma_number_t arg_num) /**< routine's first argument */ +{ + return ecma_make_boolean_value (ecma_number_is_nan (arg_num)); +} /* ecma_builtin_global_object_is_nan */ + +/** + * The Global object's 'isFinite' routine + * + * See also: + * ECMA-262 v5, 15.1.2.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_is_finite (ecma_number_t arg_num) /**< routine's first argument */ +{ + bool is_finite = !(ecma_number_is_nan (arg_num) || ecma_number_is_infinity (arg_num)); + + return ecma_make_boolean_value (is_finite); +} /* ecma_builtin_global_object_is_finite */ + +/** + * Helper function to check whether a character is in a character bitset. + * + * @return true if the character is in the character bitset. + */ +static bool +ecma_builtin_global_object_character_is_in (uint32_t character, /**< character */ + const uint8_t *bitset) /**< character set */ +{ + JERRY_ASSERT (character < 128); + return (bitset[character >> 3] & (1u << (character & 0x7))) != 0; +} /* ecma_builtin_global_object_character_is_in */ + +/** + * Unescaped URI characters bitset: + * One bit for each character between 0 - 127. + * Bit is set if the character is in the unescaped URI set. + */ +static const uint8_t unescaped_uri_set[16] = { 0x0, 0x0, 0x0, 0x0, 0xda, 0xff, 0xff, 0xaf, + 0xff, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47 }; + +/** + * Unescaped URI component characters bitset: + * One bit for each character between 0 - 127. + * Bit is set if the character is in the unescaped component URI set. + */ +static const uint8_t unescaped_uri_component_set[16] = { 0x0, 0x0, 0x0, 0x0, 0x82, 0x67, 0xff, 0x3, + 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47 }; + +/** + * Format is a percent sign followed by two hex digits. + */ +#define URI_ENCODED_BYTE_SIZE (3) + +/** + * The Global object's 'decodeURI' and 'decodeURIComponent' routines + * + * See also: + * ECMA-262 v5, 15.1.3.1 + * ECMA-262 v5, 15.1.3.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_decode_uri_helper (lit_utf8_byte_t *input_start_p, /**< routine's first argument's + * string buffer */ + lit_utf8_size_t input_size, /**< routine's first argument's + * string buffer's size */ + const uint8_t *reserved_uri_bitset) /**< reserved characters bitset */ +{ + lit_utf8_byte_t *input_char_p = input_start_p; + lit_utf8_byte_t *input_end_p = input_start_p + input_size; + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + while (input_char_p < input_end_p) + { + if (*input_char_p != '%') + { + ecma_stringbuilder_append_byte (&builder, *input_char_p++); + continue; + } + + uint32_t hex_value = lit_char_hex_lookup (input_char_p + 1, input_end_p, 2); + if (hex_value == UINT32_MAX) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_INVALID_HEXADECIMAL_VALUE); + } + + ecma_char_t decoded_byte = (ecma_char_t) hex_value; + input_char_p += URI_ENCODED_BYTE_SIZE; + + if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + if (ecma_builtin_global_object_character_is_in (decoded_byte, reserved_uri_bitset) + && !ecma_builtin_global_object_character_is_in (decoded_byte, unescaped_uri_component_set)) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_PERCENT); + input_char_p -= 2; + } + else + { + ecma_stringbuilder_append_byte (&builder, (lit_utf8_byte_t) decoded_byte); + } + } + else + { + uint32_t bytes_count; + + if ((decoded_byte & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER) + { + bytes_count = 2; + } + else if ((decoded_byte & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER) + { + bytes_count = 3; + } + else if ((decoded_byte & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER) + { + bytes_count = 4; + } + else + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_INVALID_UTF8_CHARACTER); + } + + lit_utf8_byte_t octets[LIT_UTF8_MAX_BYTES_IN_CODE_POINT]; + octets[0] = (lit_utf8_byte_t) decoded_byte; + bool is_valid = true; + + for (uint32_t i = 1; i < bytes_count; i++) + { + if (input_char_p >= input_end_p || *input_char_p != '%') + { + is_valid = false; + break; + } + else + { + hex_value = lit_char_hex_lookup (input_char_p + 1, input_end_p, 2); + + if (hex_value == UINT32_MAX || (hex_value & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER) + { + is_valid = false; + break; + } + + input_char_p += URI_ENCODED_BYTE_SIZE; + octets[i] = (lit_utf8_byte_t) hex_value; + } + } + + if (!is_valid || !lit_is_valid_utf8_string (octets, bytes_count, true)) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_INVALID_UTF8_STRING); + } + + lit_code_point_t cp; + lit_read_code_point_from_utf8 (octets, bytes_count, &cp); + + if (lit_is_code_point_utf16_high_surrogate (cp) || lit_is_code_point_utf16_low_surrogate (cp)) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_INVALID_UTF8_CODEPOINT); + } + + lit_utf8_byte_t result_chars[LIT_CESU8_MAX_BYTES_IN_CODE_POINT]; + lit_utf8_size_t cp_size = lit_code_point_to_cesu8 (cp, result_chars); + ecma_stringbuilder_append_raw (&builder, result_chars, cp_size); + } + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_global_object_decode_uri_helper */ + +/** + * Helper function to encode byte as hexadecimal values. + */ +static void +ecma_builtin_global_object_byte_to_hex (lit_utf8_byte_t *dest_p, /**< destination pointer */ + uint32_t byte) /**< value */ +{ + JERRY_ASSERT (byte < 256); + + dest_p[0] = LIT_CHAR_PERCENT; + ecma_char_t hex_digit = (ecma_char_t) (byte >> 4); + dest_p[1] = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0')); + hex_digit = (lit_utf8_byte_t) (byte & 0xf); + dest_p[2] = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0')); +} /* ecma_builtin_global_object_byte_to_hex */ + +/** + * The Global object's 'encodeURI' and 'encodeURIComponent' routines + * + * See also: + * ECMA-262 v5, 15.1.3.3 + * ECMA-262 v5, 15.1.3.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_encode_uri_helper (lit_utf8_byte_t *input_start_p, /**< routine's first argument's + * string buffer */ + lit_utf8_size_t input_size, /**< routine's first argument's + * string buffer's size */ + const uint8_t *unescaped_uri_bitset_p) /**< unescaped bitset */ +{ + lit_utf8_byte_t *input_char_p = input_start_p; + const lit_utf8_byte_t *input_end_p = input_start_p + input_size; + ecma_char_t ch; + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + lit_utf8_byte_t octets[LIT_UTF8_MAX_BYTES_IN_CODE_POINT]; + memset (octets, LIT_BYTE_NULL, LIT_UTF8_MAX_BYTES_IN_CODE_POINT); + + while (input_char_p < input_end_p) + { + input_char_p += lit_read_code_unit_from_cesu8 (input_char_p, &ch); + + if (lit_is_code_point_utf16_low_surrogate (ch)) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING); + } + + lit_code_point_t cp = ch; + + if (lit_is_code_point_utf16_high_surrogate (ch)) + { + if (input_char_p == input_end_p) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING); + } + + ecma_char_t next_ch; + lit_utf8_size_t read_size = lit_read_code_unit_from_cesu8 (input_char_p, &next_ch); + + if (lit_is_code_point_utf16_low_surrogate (next_ch)) + { + cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch); + input_char_p += read_size; + } + else + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_uri_error (ECMA_ERR_UNICODE_SURROGATE_PAIR_MISSING); + } + } + + lit_utf8_size_t utf_size = lit_code_point_to_utf8 (cp, octets); + lit_utf8_byte_t result_chars[URI_ENCODED_BYTE_SIZE]; + + if (utf_size == 1) + { + if (ecma_builtin_global_object_character_is_in (octets[0], unescaped_uri_bitset_p)) + { + ecma_stringbuilder_append_byte (&builder, octets[0]); + } + else + { + ecma_builtin_global_object_byte_to_hex (result_chars, octets[0]); + ecma_stringbuilder_append_raw (&builder, result_chars, URI_ENCODED_BYTE_SIZE); + } + } + else + { + for (uint32_t i = 0; i < utf_size; i++) + { + JERRY_ASSERT (utf_size <= LIT_UTF8_MAX_BYTES_IN_CODE_POINT); + ecma_builtin_global_object_byte_to_hex (result_chars, octets[i]); + ecma_stringbuilder_append_raw (&builder, result_chars, URI_ENCODED_BYTE_SIZE); + } + } + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_global_object_encode_uri_helper */ + +#if JERRY_BUILTIN_ANNEXB + +/** + * Maximum value of a byte. + */ +#define ECMA_ESCAPE_MAXIMUM_BYTE_VALUE (255) + +/** + * Format is a percent sign followed by lowercase u and four hex digits. + */ +#define ECMA_ESCAPE_ENCODED_UNICODE_CHARACTER_SIZE (6) + +/** + * Escape characters bitset: + * One bit for each character between 0 - 127. + * Bit is set if the character does not need to be converted to %xx form. + * These characters are: a-z A-Z 0-9 @ * _ + - . / + */ +static const uint8_t ecma_escape_set[16] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0xec, 0xff, 0x3, + 0xff, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x7 }; + +/** + * The Global object's 'escape' routine + * + * See also: + * ECMA-262 v5, B.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_escape (lit_utf8_byte_t *input_start_p, /**< routine's first argument's + * string buffer */ + lit_utf8_size_t input_size) /**< routine's first argument's + * string buffer's size */ +{ + const lit_utf8_byte_t *input_curr_p = input_start_p; + const lit_utf8_byte_t *input_end_p = input_start_p + input_size; + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + lit_utf8_byte_t result_chars[URI_ENCODED_BYTE_SIZE]; + + while (input_curr_p < input_end_p) + { + ecma_char_t chr = lit_cesu8_read_next (&input_curr_p); + + if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + if (ecma_builtin_global_object_character_is_in ((uint32_t) chr, ecma_escape_set)) + { + ecma_stringbuilder_append_char (&builder, chr); + } + else + { + ecma_builtin_global_object_byte_to_hex (result_chars, chr); + ecma_stringbuilder_append_raw (&builder, result_chars, URI_ENCODED_BYTE_SIZE); + } + } + else if (chr > ECMA_ESCAPE_MAXIMUM_BYTE_VALUE) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_PERCENT); + ecma_stringbuilder_append_char (&builder, LIT_CHAR_LOWERCASE_U); + + ecma_builtin_global_object_byte_to_hex (result_chars, (chr >> JERRY_BITSINBYTE)); + ecma_stringbuilder_append_raw (&builder, result_chars + 1, 2); + + ecma_builtin_global_object_byte_to_hex (result_chars, (chr & 0xff)); + ecma_stringbuilder_append_raw (&builder, result_chars + 1, 2); + } + else + { + ecma_builtin_global_object_byte_to_hex (result_chars, chr); + ecma_stringbuilder_append_raw (&builder, result_chars, URI_ENCODED_BYTE_SIZE); + } + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_global_object_escape */ + +/** + * Utility method to resolve character sequences for the 'unescape' method. + * + * Expected formats: %uxxxx or %yy + * + * @return number of characters processed during the escape resolve + */ +static uint8_t +ecma_builtin_global_object_unescape_resolve_escape (const lit_utf8_byte_t *buffer_p, /**< character buffer */ + bool unicode_sequence, /**< true if unescaping unicode sequence */ + ecma_char_t *out_result_p) /**< [out] resolved character */ +{ + JERRY_ASSERT (buffer_p != NULL); + JERRY_ASSERT (out_result_p != NULL); + + ecma_char_t unescaped_chr = 0; + uint8_t sequence_length = unicode_sequence ? 5 : 2; + uint8_t start = unicode_sequence ? 1 : 0; + + for (uint8_t i = start; i < sequence_length; i++) + { + const lit_utf8_byte_t current_char = buffer_p[i]; + + if (!lit_char_is_hex_digit (current_char)) + { + /* This was not an escape sequence, skip processing */ + return 0; + } + + unescaped_chr = (ecma_char_t) ((unescaped_chr << 4) + (ecma_char_t) lit_char_hex_to_int (current_char)); + } + + *out_result_p = unescaped_chr; + + return sequence_length; +} /* ecma_builtin_global_object_unescape_resolve_escape */ + +/** + * The Global object's 'unescape' routine + * + * See also: + * ECMA-262 v5, B.2.2 + * ECMA-262 v11, B.2.1.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_global_object_unescape (lit_utf8_byte_t *input_start_p, /**< routine's first argument's + * string buffer */ + lit_utf8_size_t input_size) /**< routine's first argument's + * string buffer's size */ +{ + if (input_size == 0) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + const lit_utf8_byte_t *input_curr_p = input_start_p; + const lit_utf8_byte_t *input_end_p = input_start_p + input_size; + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + while (input_curr_p < input_end_p) + { + ecma_char_t chr = lit_cesu8_read_next (&input_curr_p); + + // potential pattern + if (chr == LIT_CHAR_PERCENT) + { + const lit_utf8_size_t chars_leftover = (lit_utf8_size_t) (input_end_p - input_curr_p); + + // potential unicode sequence + if (chars_leftover >= 5 && input_curr_p[0] == LIT_CHAR_LOWERCASE_U) + { + input_curr_p += ecma_builtin_global_object_unescape_resolve_escape (input_curr_p, true, &chr); + } + // potential two hexa sequence + else if (chars_leftover >= 2) + { + input_curr_p += ecma_builtin_global_object_unescape_resolve_escape (input_curr_p, false, &chr); + } + } + + ecma_stringbuilder_append_char (&builder, chr); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_global_object_unescape */ + +#endif /* JERRY_BUILTIN_ANNEXB */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_global_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (this_arg, arguments_number); + + ecma_value_t routine_arg_1 = arguments_list_p[0]; + + if (builtin_routine_id == ECMA_GLOBAL_EVAL) + { + return ecma_builtin_global_object_eval (routine_arg_1); + } + + if (builtin_routine_id <= ECMA_GLOBAL_IS_FINITE) + { + ecma_number_t arg_num; + + routine_arg_1 = ecma_op_to_number (routine_arg_1, &arg_num); + + if (!ecma_is_value_empty (routine_arg_1)) + { + return routine_arg_1; + } + + if (builtin_routine_id == ECMA_GLOBAL_IS_NAN) + { + return ecma_builtin_global_object_is_nan (arg_num); + } + + JERRY_ASSERT (builtin_routine_id == ECMA_GLOBAL_IS_FINITE); + + return ecma_builtin_global_object_is_finite (arg_num); + } + + ecma_string_t *str_p = ecma_op_to_string (routine_arg_1); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_value; + + if (builtin_routine_id <= ECMA_GLOBAL_PARSE_FLOAT) + { + ECMA_STRING_TO_UTF8_STRING (str_p, string_buff, string_buff_size); + + if (builtin_routine_id == ECMA_GLOBAL_PARSE_INT) + { + ret_value = ecma_number_parse_int (string_buff, string_buff_size, arguments_list_p[1]); + } + else + { + JERRY_ASSERT (builtin_routine_id == ECMA_GLOBAL_PARSE_FLOAT); + ret_value = ecma_number_parse_float (string_buff, string_buff_size); + } + + ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size); + ecma_deref_ecma_string (str_p); + return ret_value; + } + + lit_utf8_size_t input_size = ecma_string_get_size (str_p); + + JMEM_DEFINE_LOCAL_ARRAY (input_start_p, input_size + 1, lit_utf8_byte_t); + + ecma_string_to_cesu8_bytes (str_p, input_start_p, input_size); + + input_start_p[input_size] = LIT_BYTE_NULL; + + switch (builtin_routine_id) + { +#if JERRY_BUILTIN_ANNEXB + case ECMA_GLOBAL_ESCAPE: + { + ret_value = ecma_builtin_global_object_escape (input_start_p, input_size); + break; + } + case ECMA_GLOBAL_UNESCAPE: + { + ret_value = ecma_builtin_global_object_unescape (input_start_p, input_size); + break; + } +#endif /* JERRY_BUILTIN_ANNEXB */ + case ECMA_GLOBAL_DECODE_URI: + case ECMA_GLOBAL_DECODE_URI_COMPONENT: + { + const uint8_t *uri_set = + (builtin_routine_id == ECMA_GLOBAL_DECODE_URI ? unescaped_uri_set : unescaped_uri_component_set); + + ret_value = ecma_builtin_global_object_decode_uri_helper (input_start_p, input_size, uri_set); + break; + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_GLOBAL_ENCODE_URI + || builtin_routine_id == ECMA_GLOBAL_ENCODE_URI_COMPONENT); + + const uint8_t *uri_set = + (builtin_routine_id == ECMA_GLOBAL_ENCODE_URI ? unescaped_uri_set : unescaped_uri_component_set); + + ret_value = ecma_builtin_global_object_encode_uri_helper (input_start_p, input_size, uri_set); + break; + } + } + + JMEM_FINALIZE_LOCAL_ARRAY (input_start_p); + + ecma_deref_ecma_string (str_p); + return ret_value; +} /* ecma_builtin_global_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h new file mode 100644 index 0000000..4c5515f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h @@ -0,0 +1,219 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Global built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Simple value properties: + * (property name, simple value, writable, enumerable, configurable) */ + +/* ECMA-262 v5, 15.1.1.3 */ +SIMPLE_VALUE (LIT_MAGIC_STRING_UNDEFINED, ECMA_VALUE_UNDEFINED, ECMA_PROPERTY_FIXED) + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v5, 15.1.1.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_NAN, ECMA_BUILTIN_NUMBER_NAN, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.1.1.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_INFINITY_UL, ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY, ECMA_PROPERTY_FIXED) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.1.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_OBJECT_UL, ECMA_BUILTIN_ID_OBJECT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_FUNCTION_UL, ECMA_BUILTIN_ID_FUNCTION, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.3 */ +#if JERRY_BUILTIN_ARRAY +OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_UL, ECMA_BUILTIN_ID_ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_ARRAY */ + +#if JERRY_BUILTIN_STRING +/* ECMA-262 v5, 15.1.4.4 */ +OBJECT_VALUE (LIT_MAGIC_STRING_STRING_UL, ECMA_BUILTIN_ID_STRING, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_STRING */ + +#if JERRY_BUILTIN_BOOLEAN +/* ECMA-262 v5, 15.1.4.5 */ +OBJECT_VALUE (LIT_MAGIC_STRING_BOOLEAN_UL, ECMA_BUILTIN_ID_BOOLEAN, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_BOOLEAN */ + +#if JERRY_BUILTIN_NUMBER +/* ECMA-262 v5, 15.1.4.6 */ +OBJECT_VALUE (LIT_MAGIC_STRING_NUMBER_UL, ECMA_BUILTIN_ID_NUMBER, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_NUMBER */ + +#if JERRY_BUILTIN_DATE +/* ECMA-262 v5, 15.1.4.7 */ +OBJECT_VALUE (LIT_MAGIC_STRING_DATE_UL, ECMA_BUILTIN_ID_DATE, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_DATE */ + +#if JERRY_BUILTIN_REGEXP +/* ECMA-262 v5, 15.1.4.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_REGEXP_UL, ECMA_BUILTIN_ID_REGEXP, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_REGEXP */ + +/* ECMA-262 v5, 15.1.4.9 */ +OBJECT_VALUE (LIT_MAGIC_STRING_ERROR_UL, ECMA_BUILTIN_ID_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#if JERRY_BUILTIN_ERRORS + +/* ECMA-262 v5, 15.1.4.10 */ +OBJECT_VALUE (LIT_MAGIC_STRING_EVAL_ERROR_UL, ECMA_BUILTIN_ID_EVAL_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.11 */ +OBJECT_VALUE (LIT_MAGIC_STRING_RANGE_ERROR_UL, ECMA_BUILTIN_ID_RANGE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.12 */ +OBJECT_VALUE (LIT_MAGIC_STRING_REFERENCE_ERROR_UL, ECMA_BUILTIN_ID_REFERENCE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.13 */ +OBJECT_VALUE (LIT_MAGIC_STRING_SYNTAX_ERROR_UL, ECMA_BUILTIN_ID_SYNTAX_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.14 */ +OBJECT_VALUE (LIT_MAGIC_STRING_TYPE_ERROR_UL, ECMA_BUILTIN_ID_TYPE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.1.4.15 */ +OBJECT_VALUE (LIT_MAGIC_STRING_URI_ERROR_UL, ECMA_BUILTIN_ID_URI_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_ERRORS */ + +#if JERRY_BUILTIN_MATH +/* ECMA-262 v5, 15.1.5.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_MATH_UL, ECMA_BUILTIN_ID_MATH, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_REFLECT +/* ECMA-262 v6, 26.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_REFLECT_UL, ECMA_BUILTIN_ID_REFLECT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_REFLECT */ + +#if JERRY_BUILTIN_ATOMICS +/* ECMA-262 v5, 15.1.5.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_ATOMICS_U, ECMA_BUILTIN_ID_ATOMICS, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_ATOMICS */ + +#if JERRY_BUILTIN_TYPEDARRAY +OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_BUFFER_UL, ECMA_BUILTIN_ID_ARRAYBUFFER, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER +OBJECT_VALUE (LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, + ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + +OBJECT_VALUE (LIT_MAGIC_STRING_INT8_ARRAY_UL, ECMA_BUILTIN_ID_INT8ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_UINT8_ARRAY_UL, ECMA_BUILTIN_ID_UINT8ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_INT16_ARRAY_UL, ECMA_BUILTIN_ID_INT16ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_UINT16_ARRAY_UL, ECMA_BUILTIN_ID_UINT16ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_INT32_ARRAY_UL, ECMA_BUILTIN_ID_INT32ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_UINT32_ARRAY_UL, ECMA_BUILTIN_ID_UINT32ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_FLOAT32_ARRAY_UL, ECMA_BUILTIN_ID_FLOAT32ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#if JERRY_NUMBER_TYPE_FLOAT64 +OBJECT_VALUE (LIT_MAGIC_STRING_FLOAT64_ARRAY_UL, ECMA_BUILTIN_ID_FLOAT64ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +#if JERRY_BUILTIN_BIGINT +OBJECT_VALUE (LIT_MAGIC_STRING_BIGINT64_ARRAY_UL, ECMA_BUILTIN_ID_BIGINT64ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +OBJECT_VALUE (LIT_MAGIC_STRING_BIGUINT64_ARRAY_UL, ECMA_BUILTIN_ID_BIGUINT64ARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_BIGINT */ + +OBJECT_VALUE (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL, + ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#if JERRY_BUILTIN_CONTAINER +/* ECMA-262 v6, 23.1.1.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_WEAKSET_UL, ECMA_BUILTIN_ID_WEAKSET, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.1.1.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_MAP_UL, ECMA_BUILTIN_ID_MAP, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.1.1.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_SET_UL, ECMA_BUILTIN_ID_SET, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.1.1.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_WEAKMAP_UL, ECMA_BUILTIN_ID_WEAKMAP, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_CONTAINER */ + +#if JERRY_BUILTIN_WEAKREF +OBJECT_VALUE (LIT_MAGIC_STRING_WEAKREF_UL, ECMA_BUILTIN_ID_WEAKREF, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_WEAKREF */ + +#if JERRY_BUILTIN_ERRORS +OBJECT_VALUE (LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, ECMA_BUILTIN_ID_AGGREGATE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_ERRORS */ + +OBJECT_VALUE (LIT_MAGIC_STRING_PROMISE_UL, ECMA_BUILTIN_ID_PROMISE, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 19.4.1.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_SYMBOL_UL, ECMA_BUILTIN_ID_SYMBOL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#if JERRY_BUILTIN_GLOBAL_THIS +/* ECMA-262 v11, 18.1.1 */ +SIMPLE_VALUE (LIT_MAGIC_STRING_GLOBAL_THIS_UL, ECMA_VALUE_GLOBAL_THIS, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_GLOBAL_THIS */ + +#if JERRY_BUILTIN_DATAVIEW +/* ECMA-262 v6, 23.1.1.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_DATAVIEW_UL, ECMA_BUILTIN_ID_DATAVIEW, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_DATAVIEW */ + +#if JERRY_BUILTIN_PROXY +/* ECMA-262 v6, 26.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROXY_UL, ECMA_BUILTIN_ID_PROXY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_PROXY */ + +#if JERRY_BUILTIN_BIGINT +/* ECMA-262 v11, 20.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_BIGINT_UL, ECMA_BUILTIN_ID_BIGINT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_BIGINT */ + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ + +ROUTINE (LIT_MAGIC_STRING_EVAL, ECMA_GLOBAL_EVAL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_NAN, ECMA_GLOBAL_IS_NAN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_FINITE, ECMA_GLOBAL_IS_FINITE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_DECODE_URI, ECMA_GLOBAL_DECODE_URI, 1, 1) +ROUTINE (LIT_MAGIC_STRING_DECODE_URI_COMPONENT, ECMA_GLOBAL_DECODE_URI_COMPONENT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ENCODE_URI, ECMA_GLOBAL_ENCODE_URI, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ENCODE_URI_COMPONENT, ECMA_GLOBAL_ENCODE_URI_COMPONENT, 1, 1) + +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_FLOAT, LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_INT, LIT_MAGIC_STRING_PARSE_INT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#if JERRY_BUILTIN_ANNEXB +ROUTINE (LIT_MAGIC_STRING_ESCAPE, ECMA_GLOBAL_ESCAPE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_UNESCAPE, ECMA_GLOBAL_UNESCAPE, 1, 1) +#endif /* JERRY_BUILTIN_ANNEXB */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.cpp new file mode 100644 index 0000000..3a048d2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.cpp @@ -0,0 +1,60 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-handlers.h" + +#include "ecma-globals.h" +#include "ecma-iterator-object.h" +#include "ecma-promise-object.h" + +static const ecma_builtin_handler_t ecma_native_handlers[] = { +/** @cond doxygen_suppress */ +#define ECMA_NATIVE_HANDLER(id, handler, length) handler, +#include "ecma-builtin-handlers.inc.h" +#undef ECMA_NATIVE_HANDLER + /** @endcond */ +}; + +static const uint8_t ecma_native_handler_lengths[] = { +/** @cond doxygen_suppress */ +#define ECMA_NATIVE_HANDLER(id, handler, length) length, +#include "ecma-builtin-handlers.inc.h" +#undef ECMA_NATIVE_HANDLER + /** @endcond */ +}; + +/** + * Get the native handler of a built-in handler type. + * + * return Function pointer of the handler + */ +ecma_builtin_handler_t +ecma_builtin_handler_get (ecma_native_handler_id_t id) /**< handler id */ +{ + JERRY_ASSERT (id != ECMA_NATIVE_HANDLER_START && id < ECMA_NATIVE_HANDLER__COUNT); + return ecma_native_handlers[id - 1]; +} /* ecma_builtin_handler_get */ + +/** + * Get the initial 'length' value of a built-in handler type. + * + * return 'length' value of the handler + */ +uint8_t +ecma_builtin_handler_get_length (ecma_native_handler_id_t id) /**< handler id */ +{ + JERRY_ASSERT (id != ECMA_NATIVE_HANDLER_START && id < ECMA_NATIVE_HANDLER__COUNT); + return ecma_native_handler_lengths[id - 1]; +} /* ecma_builtin_handler_get_length */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.h new file mode 100644 index 0000000..0143473 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.h @@ -0,0 +1,51 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BUILTIN_HANDLERS_H +#define ECMA_BUILTIN_HANDLERS_H + +#include "ecma-builtins.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-promise-object.h" +#include "ecma-proxy-object.h" + +typedef enum +{ + /** @cond doxygen_suppress */ + ECMA_NATIVE_HANDLER_START = 0, +#define ECMA_NATIVE_HANDLER(id, handler, length) id, +#include "ecma-builtin-handlers.inc.h" +#undef ECMA_NATIVE_HANDLER + ECMA_NATIVE_HANDLER__COUNT + /** @endcond */ +} ecma_native_handler_id_t; + +typedef enum +{ + ECMA_NATIVE_HANDLER_FLAGS_NONE = 0, + ECMA_NATIVE_HANDLER_FLAGS_NAME_INITIALIZED = (1 << 0), + ECMA_NATIVE_HANDLER_FLAGS_LENGTH_INITIALIZED = (1 << 1), +} ecma_native_handler_flags_t; + +/** + * Shift for Promise helper handler function. + */ +#define ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT 2 + +ecma_builtin_handler_t ecma_builtin_handler_get (ecma_native_handler_id_t id); +uint8_t ecma_builtin_handler_get_length (ecma_native_handler_id_t id); + +#endif /* !ECMA_BUILTIN_HANDLERS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.inc.h new file mode 100644 index 0000000..b5b7a60 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-handlers.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_RESOLVE, ecma_promise_resolve_handler, 1) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_REJECT, ecma_promise_reject_handler, 1) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_THEN_FINALLY, ecma_promise_then_finally_cb, 1) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_CATCH_FINALLY, ecma_promise_catch_finally_cb, 1) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER, ecma_promise_all_or_all_settled_handler_cb, 1) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_CAPABILITY_EXECUTOR, ecma_op_get_capabilities_executor_cb, 2) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_ASYNC_FROM_SYNC_ITERATOR_UNWRAP, ecma_async_from_sync_iterator_unwrap_cb, 1) +#if JERRY_BUILTIN_PROXY +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROXY_REVOKE, ecma_proxy_revoke_cb, 0) +#endif /* JERRY_BUILTIN_PROXY */ +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_VALUE_THUNK, ecma_value_thunk_helper_cb, 0) +ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_VALUE_THROWER, ecma_value_thunk_thrower_cb, 0) diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp new file mode 100644 index 0000000..71e43d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp @@ -0,0 +1,766 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-exceptions.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_DATE + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations + * @{ + */ + +/** + * Day names + */ +const char* day_names_p[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + +/** + * Month names + */ +const char* month_names_p[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +/** + * Calculate the elapsed days since Unix Epoch + * + * @return elapsed days since Unix Epoch + */ +int32_t +ecma_date_day_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + if (time < 0) + { + time -= ECMA_DATE_MS_PER_DAY - 1; + } + + return (int32_t) (time / ECMA_DATE_MS_PER_DAY); +} /* ecma_date_day_from_time */ + +/** + * Abstract operation: DayFromYear + * + * See also: + * ECMA-262 v11, 20.4.1.3 + * + * @return first of day in the given year + */ +static int32_t +ecma_date_day_from_year (int32_t year) /**< year value */ +{ + if (JERRY_LIKELY (year >= 1970)) + { + return (int32_t) (365 * (year - 1970) + ((year - 1969) / 4) - ((year - 1901) / 100) + ((year - 1601) / 400)); + } + + return (int32_t) (365 * (year - 1970) + floor ((year - 1969) / 4.0) - floor ((year - 1901) / 100.0) + + floor ((year - 1601) / 400.0)); +} /* ecma_date_day_from_year */ + +/** + * Abstract operation: DaysInYear + * + * See also: + * ECMA-262 v11, 20.4.1.3 + * + * @return number of days in the given year + */ +static int +ecma_date_days_in_year (int32_t year) /**< year */ +{ + if (year % 4 != 0 || (year % 100 == 0 && (year % 400 != 0))) + { + return ECMA_DATE_DAYS_IN_YEAR; + } + + return ECMA_DATE_DAYS_IN_LEAP_YEAR; +} /* ecma_date_days_in_year */ + +/** + * Abstract operation: InLeapYear + * + * See also: + * ECMA-262 v11, 20.4.1.3 + * + * @return 1 - if the year is leap + * 0 - otherwise + */ +static int32_t +ecma_date_in_leap_year (int32_t year) /**< time value */ +{ + return ecma_date_days_in_year (year) - ECMA_DATE_DAYS_IN_YEAR; +} /* ecma_date_in_leap_year */ + +/** + * First days of months in normal and leap years + */ +static const uint16_t first_day_in_month[2][12] = { { + 0, + 31, + 59, + 90, + 120, + 151, + 181, + 212, + 243, + 273, + 304, + 334, /* normal year */ + }, + { + 0, + 31, + 60, + 91, + 121, + 152, + 182, + 213, + 244, + 274, + 305, + 335 /* leap year */ + } }; + +/** + * Abstract operation: YearFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.3 + * + * @return year corresponds to the given time + */ +int32_t +ecma_date_year_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t approx = (int32_t) (floor (time / ECMA_DATE_MS_PER_DAY / 365.2425) + 1970); + int64_t year_ms = ecma_date_day_from_year (approx) * ((int64_t) ECMA_DATE_MS_PER_DAY); + + if ((ecma_number_t) year_ms > time) + { + approx--; + } + + if ((ecma_number_t) (year_ms + ecma_date_days_in_year (approx) * ((int64_t) ECMA_DATE_MS_PER_DAY)) <= time) + { + approx++; + } + + return approx; +} /* ecma_date_year_from_time */ + +/** + * Abstract operation: MonthFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.4 + * + * @return month corresponds to the given time + */ +int32_t +ecma_date_month_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t year = ecma_date_year_from_time (time); + int32_t day_within_year = ecma_date_day_from_time (time) - ecma_date_day_from_year (year); + + JERRY_ASSERT (day_within_year >= 0 && day_within_year < ECMA_DATE_DAYS_IN_LEAP_YEAR); + + int32_t in_leap_year = ecma_date_in_leap_year (year); + + for (int i = 1; i < 12; i++) + { + if (day_within_year < first_day_in_month[in_leap_year][i]) + { + return i - 1; + } + } + + return 11; +} /* ecma_date_month_from_time */ + +/** + * Abstract operation: DateFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.4 + * + * @return date corresponds to the given time + */ +int32_t +ecma_date_date_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t year = ecma_date_year_from_time (time); + int32_t day_within_year = ecma_date_day_from_time (time) - ecma_date_day_from_year (year); + + JERRY_ASSERT (day_within_year >= 0 && day_within_year < ECMA_DATE_DAYS_IN_LEAP_YEAR); + + int32_t in_leap_year = ecma_date_in_leap_year (year); + + int32_t month = 11; + + for (int i = 1; i < 12; i++) + { + if (day_within_year < first_day_in_month[in_leap_year][i]) + { + month = i - 1; + break; + } + } + + return day_within_year + 1 - first_day_in_month[in_leap_year][month]; +} /* ecma_date_date_from_time */ + +/** + * Abstract operation: WeekDay + * + * See also: + * ECMA-262 v11, 20.4.1.4 + * + * @return weekday corresponds to the given time + */ +int32_t +ecma_date_week_day (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t day = ecma_date_day_from_time (time); + + int week_day = (day + 4) % 7; + + return week_day >= 0 ? week_day : week_day + 7; +} /* ecma_date_week_day */ + +/** + * Abstract operation: LocalTZA + * + * See also: + * ECMA-262 v11, 20.4.1.7 + * + * @return local time zone adjustment + */ +int32_t +ecma_date_local_time_zone_adjustment (ecma_number_t time) /**< time value */ +{ + return jerry_port_local_tza (time); +} /* ecma_date_local_time_zone_adjustment */ + +/** + * Abstract operation: UTC + * + * See also: + * ECMA-262 v11, 20.4.1.9 + * + * @return UTC time + */ +ecma_number_t +ecma_date_utc (ecma_number_t time) /**< time value */ +{ + return time - jerry_port_local_tza (time); +} /* ecma_date_utc */ + +/** + * Calculate the time component from the given time + * + * @return time component of the given time + */ +int32_t +ecma_date_time_in_day_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + ecma_number_t day = ecma_date_day_from_time (time); + + return (int32_t) (time - (day * ECMA_DATE_MS_PER_DAY)); +} /* ecma_date_time_in_day_from_time */ + +/** + * Abstract operation: HourFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.10 + * + * @return hours component of the given time + */ +int32_t +ecma_date_hour_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t time_in_day = ecma_date_time_in_day_from_time (time); + + return (int32_t) (time_in_day / ECMA_DATE_MS_PER_HOUR); +} /* ecma_date_hour_from_time */ + +/** + * Abstract operation: HourFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.10 + * + * @return minutes component of the given time + */ +int32_t +ecma_date_min_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t time_in_day = ecma_date_time_in_day_from_time (time); + + return ((int32_t) (time_in_day / ECMA_DATE_MS_PER_MINUTE)) % ECMA_DATE_MINUTES_PER_HOUR; +} /* ecma_date_min_from_time */ + +/** + * Abstract operation: HourFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.10 + * + * @return seconds component of the given time + */ +int32_t +ecma_date_sec_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t time_in_day = ecma_date_time_in_day_from_time (time); + + return ((int32_t) (time_in_day / ECMA_DATE_MS_PER_SECOND)) % ECMA_DATE_SECONDS_PER_MINUTE; +} /* ecma_date_sec_from_time */ + +/** + * Abstract operation: HourFromTime + * + * See also: + * ECMA-262 v11, 20.4.1.10 + * + * @return milliseconds component of the given time + */ +int32_t +ecma_date_ms_from_time (ecma_number_t time) /**< time value */ +{ + JERRY_ASSERT (!ecma_number_is_nan (time)); + + int32_t time_in_day = ecma_date_time_in_day_from_time (time); + + return (int32_t) (time_in_day % ECMA_DATE_MS_PER_SECOND); +} /* ecma_date_ms_from_time */ + +/** + * Abstract operation: MakeTime + * + * See also: + * ECMA-262 v11, 20.4.1.11 + * + * @return constructed time in milliseconds + */ +ecma_number_t +ecma_date_make_time (ecma_number_t hour, /**< hour value */ + ecma_number_t min, /**< minute value */ + ecma_number_t sec, /**< second value */ + ecma_number_t ms) /**< millisecond value */ +{ + if (!ecma_number_is_finite (hour) || !ecma_number_is_finite (min) || !ecma_number_is_finite (sec) + || !ecma_number_is_finite (ms)) + { + return ecma_number_make_nan (); + } + + ecma_number_t h = ecma_number_trunc (hour); + ecma_number_t m = ecma_number_trunc (min); + ecma_number_t s = ecma_number_trunc (sec); + ecma_number_t milli = ecma_number_trunc (ms); + + return h * ECMA_DATE_MS_PER_HOUR + m * ECMA_DATE_MS_PER_MINUTE + s * ECMA_DATE_MS_PER_SECOND + milli; +} /* ecma_date_make_time */ + +/** + * Abstract operation: MakeDay + * + * See also: + * ECMA-262 v11, 20.4.1.12 + * + * @return elapsed number of days since Unix Epoch + */ +ecma_number_t +ecma_date_make_day (ecma_number_t year, /**< year value */ + ecma_number_t month, /**< month value */ + ecma_number_t date) /**< date value */ +{ + /* 1. */ + if (!ecma_number_is_finite (year) || !ecma_number_is_finite (month) || !ecma_number_is_finite (date) + || fabs (year) > INT32_MAX) + { + return ecma_number_make_nan (); + } + + /* 2., 3., 4. */ + int32_t y = (int32_t) (year); + ecma_number_t m = ecma_number_trunc (month); + ecma_number_t dt = ecma_number_trunc (date); + + /* 5. */ + int32_t ym = y + (int32_t) (floor (m / 12)); + + /* 6. */ + int32_t mn = (int32_t) fmod (m, 12); + + if (mn < 0) + { + mn += 12; + } + + /* 7. */ + ecma_number_t days = (ecma_date_day_from_year (ym) + first_day_in_month[ecma_date_in_leap_year (ym)][mn] + (dt - 1)); + return days * ECMA_DATE_MS_PER_DAY; +} /* ecma_date_make_day */ + +/** + * Abstract operation: MakeTime + * + * See also: + * ECMA-262 v11, 20.4.1.13 + * + * @return elapsed number of milliseconds since Unix Epoch + */ +ecma_number_t +ecma_date_make_date (ecma_number_t day, /**< day value */ + ecma_number_t time) /**< time value */ +{ + if (!ecma_number_is_finite (day) || !ecma_number_is_finite (time)) + { + return ecma_number_make_nan (); + } + + return day + time; +} /* ecma_date_make_date */ + +/** + * Abstract operation: TimeClip + * + * See also: + * ECMA-262 v11, 20.4.1.14 + * + * @return elapsed number of milliseconds since Unix Epoch + */ +ecma_number_t +ecma_date_time_clip (ecma_number_t time) /**< time value */ +{ + if (!ecma_number_is_finite (time) || fabs (time) > ECMA_DATE_MAX_VALUE) + { + return ecma_number_make_nan (); + } + + return ecma_number_trunc (time); +} /* ecma_date_time_clip */ + +/** + * Common function to convert date to string. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_date_to_string_format (ecma_number_t datetime_number, /**< datetime */ + const char *format_p) /**< format buffer */ +{ + const uint32_t date_buffer_length = 37; + JERRY_VLA (lit_utf8_byte_t, date_buffer, date_buffer_length); + + lit_utf8_byte_t *dest_p = date_buffer; + + while (*format_p != LIT_CHAR_NULL) + { + if (*format_p != LIT_CHAR_DOLLAR_SIGN) + { + *dest_p++ = (lit_utf8_byte_t) *format_p++; + continue; + } + + format_p++; + + const char *str_p = NULL; + int32_t number = 0; + int32_t number_length = 0; + + switch (*format_p) + { + case LIT_CHAR_UPPERCASE_Y: /* Year. */ + { + number = ecma_date_year_from_time (datetime_number); + + if (number >= 100000 || number <= -100000) + { + number_length = 6; + } + else if (number >= 10000 || number <= -10000) + { + number_length = 5; + } + else + { + number_length = 4; + } + break; + } + case LIT_CHAR_LOWERCASE_Y: /* ISO Year: -000001, 0000, 0001, 9999, +012345 */ + { + number = ecma_date_year_from_time (datetime_number); + if (0 <= number && number <= 9999) + { + number_length = 4; + } + else + { + number_length = 6; + } + break; + } + case LIT_CHAR_UPPERCASE_M: /* Month. */ + { + int32_t month = ecma_date_month_from_time (datetime_number); + + JERRY_ASSERT (month >= 0 && month <= 11); + + str_p = month_names_p[month]; + break; + } + case LIT_CHAR_UPPERCASE_O: /* Month as number. */ + { + /* The 'ecma_date_month_from_time' (ECMA 262 v5, 15.9.1.4) returns a + * number from 0 to 11, but we have to print the month from 1 to 12 + * for ISO 8601 standard (ECMA 262 v5, 15.9.1.15). */ + number = ecma_date_month_from_time (datetime_number) + 1; + number_length = 2; + break; + } + case LIT_CHAR_UPPERCASE_D: /* Day. */ + { + number = ecma_date_date_from_time (datetime_number); + number_length = 2; + break; + } + case LIT_CHAR_UPPERCASE_W: /* Day of week. */ + { + int32_t day = ecma_date_week_day (datetime_number); + + JERRY_ASSERT (day >= 0 && day <= 6); + + str_p = day_names_p[day]; + break; + } + case LIT_CHAR_LOWERCASE_H: /* Hour. */ + { + number = ecma_date_hour_from_time (datetime_number); + number_length = 2; + break; + } + case LIT_CHAR_LOWERCASE_M: /* Minutes. */ + { + number = ecma_date_min_from_time (datetime_number); + number_length = 2; + break; + } + case LIT_CHAR_LOWERCASE_S: /* Seconds. */ + { + number = ecma_date_sec_from_time (datetime_number); + number_length = 2; + break; + } + case LIT_CHAR_LOWERCASE_I: /* Milliseconds. */ + { + number = ecma_date_ms_from_time (datetime_number); + number_length = 3; + break; + } + case LIT_CHAR_LOWERCASE_Z: /* Time zone hours part. */ + { + int32_t time_zone = ecma_date_local_time_zone_adjustment (datetime_number); + + if (time_zone >= 0) + { + *dest_p++ = LIT_CHAR_PLUS; + } + else + { + *dest_p++ = LIT_CHAR_MINUS; + time_zone = -time_zone; + } + + number = time_zone / ECMA_DATE_MS_PER_HOUR; + number_length = 2; + break; + } + default: + { + JERRY_ASSERT (*format_p == LIT_CHAR_UPPERCASE_Z); /* Time zone minutes part. */ + + int32_t time_zone = ecma_date_local_time_zone_adjustment (datetime_number); + + if (time_zone < 0) + { + time_zone = -time_zone; + } + + number = (time_zone % ECMA_DATE_MS_PER_HOUR) / ECMA_DATE_MS_PER_MINUTE; + number_length = 2; + break; + } + } + + format_p++; + + if (str_p != NULL) + { + /* Print string values: month or day name which is always 3 characters */ + memcpy (dest_p, str_p, 3); + dest_p += 3; + continue; + } + + /* Print right aligned number values. */ + JERRY_ASSERT (number_length > 0); + + if (number < 0) + { + number = -number; + *dest_p++ = '-'; + } + else if (*(format_p - 1) == LIT_CHAR_LOWERCASE_Y && number_length == 6) + { + /* positive sign is compulsory for extended years */ + *dest_p++ = '+'; + } + + dest_p += number_length; + lit_utf8_byte_t *buffer_p = dest_p; + + do + { + buffer_p--; + *buffer_p = (lit_utf8_byte_t) ((number % 10) + (int32_t) LIT_CHAR_0); + number /= 10; + } while (--number_length); + } + + JERRY_ASSERT (dest_p <= date_buffer + date_buffer_length); + + return ecma_make_string_value ( + ecma_new_ecma_string_from_ascii (date_buffer, (lit_utf8_size_t) (dest_p - date_buffer))); +} /* ecma_date_to_string_format */ + +/** + * Common function to create a time zone specific string from a numeric value. + * + * Used by: + * - The Date routine. + * - The Date.prototype.toString routine. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_date_value_to_string (ecma_number_t datetime_number) /**< datetime */ +{ + datetime_number += ecma_date_local_time_zone_adjustment (datetime_number); + return ecma_date_to_string_format (datetime_number, "$W $M $D $Y $h:$m:$s GMT$z$Z"); +} /* ecma_date_value_to_string */ + +/** + * Common function to create a time zone specific string from a numeric value. + * + * Used by: + * - The Date.prototype.toUTCString routine. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_date_value_to_utc_string (ecma_number_t datetime_number) /**< datetime */ +{ + return ecma_date_to_string_format (datetime_number, "$W, $D $M $Y $h:$m:$s GMT"); +} /* ecma_date_value_to_utc_string */ + +/** + * Common function to create a ISO specific string from a numeric value. + * + * Used by: + * - The Date.prototype.toISOString routine. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_date_value_to_iso_string (ecma_number_t datetime_number) /** source_array_p [left_idx : right_idx - 1] + * Second -> source_array_p [right_idx : end_idx - 1] + * Output -> output_array_p + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_helper_array_merge_sort_bottom_up (ecma_value_t *source_array_p, /**< arrays to merge */ + uint32_t left_idx, /**< first array begin */ + uint32_t right_idx, /**< first array end */ + uint32_t end_idx, /**< second array end */ + ecma_value_t *output_array_p, /**< output array */ + ecma_value_t compare_func, /**< compare function */ + const ecma_builtin_helper_sort_compare_fn_t sort_cb, /**< sorting cb */ + ecma_object_t *array_buffer_p) /* array_buffer_p */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + uint32_t i = left_idx, j = right_idx; + + for (uint32_t k = left_idx; k < end_idx; k++) + { + ecma_value_t compare_value = ecma_make_number_value (ECMA_NUMBER_ZERO); + + if (i < right_idx && j < end_idx) + { + compare_value = sort_cb (source_array_p[i], source_array_p[j], compare_func, array_buffer_p); + if (ECMA_IS_VALUE_ERROR (compare_value)) + { + ret_value = ECMA_VALUE_ERROR; + break; + } + } + + if (i < right_idx && ecma_get_number_from_value (compare_value) <= ECMA_NUMBER_ZERO) + { + output_array_p[k] = source_array_p[i]; + i++; + } + else + { + output_array_p[k] = source_array_p[j]; + j++; + } + ecma_free_value (compare_value); + } + + return ret_value; +} /* ecma_builtin_helper_array_merge_sort_bottom_up */ + +/** + * Mergesort function + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_helper_array_merge_sort_helper (ecma_value_t *array_p, /**< array to sort */ + uint32_t length, /**< length */ + ecma_value_t compare_func, /**< compare function */ + const ecma_builtin_helper_sort_compare_fn_t sort_cb, /**< sorting cb */ + ecma_object_t *array_buffer_p) /**< arrayBuffer */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + JMEM_DEFINE_LOCAL_ARRAY (dest_array_p, length, ecma_value_t); + + ecma_value_t *temp_p; + ecma_value_t *base_array_p = array_p; + uint32_t r, e; + + for (uint32_t w = 1; w < length; w = 2 * w) + { + for (uint32_t i = 0; i < length; i = i + 2 * w) + { + // End of first array + r = i + w; + if (r > length) + { + r = length; + } + + // End of second array + e = i + 2 * w; + if (e > length) + { + e = length; + } + + // Merge two arrays + ret_value = ecma_builtin_helper_array_merge_sort_bottom_up (array_p, + i, + r, + e, + dest_array_p, + compare_func, + sort_cb, + array_buffer_p); + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + break; + } + } + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + break; + } + + // Swap arrays + temp_p = dest_array_p; + dest_array_p = array_p; + array_p = temp_p; + } + + // Sorted array is in dest_array_p - there was uneven number of arrays swaps + if (dest_array_p == base_array_p) + { + uint32_t index = 0; + temp_p = dest_array_p; + dest_array_p = array_p; + array_p = temp_p; + + while (index < length) + { + array_p[index] = dest_array_p[index]; + index++; + } + JERRY_ASSERT (index == length); + } + + JMEM_FINALIZE_LOCAL_ARRAY (dest_array_p); + + return ret_value; +} /* ecma_builtin_helper_array_merge_sort_helper */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp new file mode 100644 index 0000000..f491610 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp @@ -0,0 +1,1039 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jmem.h" +#include "lit-char-helpers.h" +#include "lit-magic-strings.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations + * @{ + */ + +/** + * Helper function for Object.prototype.toString routine when + * the @@toStringTag property is present + * + * See also: + * ECMA-262 v6, 19.1.3.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_helper_object_to_string_tag_helper (ecma_value_t tag_value) /**< string tag */ +{ + JERRY_ASSERT (ecma_is_value_string (tag_value)); + + ecma_string_t *tag_str_p = ecma_get_string_from_value (tag_value); + lit_utf8_size_t tag_str_size = ecma_string_get_size (tag_str_p); + ecma_string_t *ret_string_p; + + /* Building string "[object #@@toStringTag#]" + The string size will be size("[object ") + size(#@@toStringTag#) + size ("]"). */ + const lit_utf8_size_t buffer_size = 9 + tag_str_size; + JMEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, lit_utf8_byte_t); + + lit_utf8_byte_t *buffer_ptr = str_buffer; + + const lit_magic_string_id_t magic_string_ids[] = { + LIT_MAGIC_STRING_LEFT_SQUARE_CHAR, + LIT_MAGIC_STRING_OBJECT, + LIT_MAGIC_STRING_SPACE_CHAR, + }; + + /* Copy to buffer the "[object " string */ + for (uint32_t i = 0; i < sizeof (magic_string_ids) / sizeof (lit_magic_string_id_t); ++i) + { + buffer_ptr = lit_copy_magic_string_to_buffer (magic_string_ids[i], + buffer_ptr, + (lit_utf8_size_t) ((str_buffer + buffer_size) - buffer_ptr)); + + JERRY_ASSERT (buffer_ptr <= str_buffer + buffer_size); + } + + /* Copy to buffer the #@@toStringTag# string */ + ecma_string_to_cesu8_bytes (tag_str_p, buffer_ptr, tag_str_size); + buffer_ptr += tag_str_size; + + JERRY_ASSERT (buffer_ptr <= str_buffer + buffer_size); + + /* Copy to buffer the "]" string */ + buffer_ptr = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR, + buffer_ptr, + (lit_utf8_size_t) ((str_buffer + buffer_size) - buffer_ptr)); + + JERRY_ASSERT (buffer_ptr <= str_buffer + buffer_size); + + ret_string_p = ecma_new_ecma_string_from_utf8 (str_buffer, (lit_utf8_size_t) (buffer_ptr - str_buffer)); + + JMEM_FINALIZE_LOCAL_ARRAY (str_buffer); + ecma_deref_ecma_string (tag_str_p); + + return ecma_make_string_value (ret_string_p); +} /* ecma_builtin_helper_object_to_string_tag_helper */ + +/** + * Common implementation of the Object.prototype.toString routine + * + * See also: + * ECMA-262 v5, 15.2.4.2 + * + * Used by: + * - The Object.prototype.toString routine. + * - The Array.prototype.toString routine as fallback. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ + +ecma_value_t +ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this argument */ +{ + lit_magic_string_id_t builtin_tag; + + if (ecma_is_value_undefined (this_arg)) + { + builtin_tag = LIT_MAGIC_STRING_UNDEFINED_UL; + } + else if (ecma_is_value_null (this_arg)) + { + builtin_tag = LIT_MAGIC_STRING_NULL_UL; + } + else + { + ecma_value_t obj_this = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (obj_this)) + { + return obj_this; + } + + JERRY_ASSERT (ecma_is_value_object (obj_this)); + + ecma_object_t *obj_p = ecma_get_object_from_value (obj_this); + + builtin_tag = ecma_object_get_class_name (obj_p); + + ecma_value_t is_array = ecma_is_value_array (obj_this); + + if (ECMA_IS_VALUE_ERROR (is_array)) + { + ecma_deref_object (obj_p); + return is_array; + } + + if (ecma_is_value_true (is_array)) + { + builtin_tag = LIT_MAGIC_STRING_ARRAY_UL; + } + + ecma_value_t tag = ecma_op_object_get_by_symbol_id (obj_p, LIT_GLOBAL_SYMBOL_TO_STRING_TAG); + + if (ECMA_IS_VALUE_ERROR (tag)) + { + ecma_deref_object (obj_p); + return tag; + } + + if (ecma_is_value_string (tag)) + { + ecma_deref_object (obj_p); + return ecma_builtin_helper_object_to_string_tag_helper (tag); + } + else if (builtin_tag != LIT_MAGIC_STRING_ARGUMENTS_UL && builtin_tag != LIT_MAGIC_STRING_FUNCTION_UL + && builtin_tag != LIT_MAGIC_STRING_ERROR_UL && builtin_tag != LIT_MAGIC_STRING_BOOLEAN_UL + && builtin_tag != LIT_MAGIC_STRING_NUMBER_UL && builtin_tag != LIT_MAGIC_STRING_STRING_UL + && builtin_tag != LIT_MAGIC_STRING_DATE_UL && builtin_tag != LIT_MAGIC_STRING_REGEXP_UL + && builtin_tag != LIT_MAGIC_STRING_ARRAY_UL) + { + builtin_tag = LIT_MAGIC_STRING_OBJECT_UL; + } + + ecma_free_value (tag); + ecma_deref_object (obj_p); + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + ecma_stringbuilder_append_magic (&builder, LIT_MAGIC_STRING_OBJECT_TO_STRING_UL); + ecma_stringbuilder_append_magic (&builder, builtin_tag); + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_RIGHT_SQUARE); + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_helper_object_to_string */ + +/** + * The Array.prototype's 'toLocaleString' single element operation routine + * + * See also: + * ECMA-262 v5, 15.4.4.3 steps 6-8 and 10.b-d + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_string_t * +ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< this object */ + ecma_length_t index) /**< array index */ +{ + ecma_value_t index_value = ecma_op_object_get_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (index_value)) + { + return NULL; + } + + if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_value_t call_value = ecma_op_invoke_by_magic_id (index_value, LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, NULL, 0); + + ecma_free_value (index_value); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + return NULL; + } + + ecma_string_t *ret_string_p = ecma_op_to_string (call_value); + + ecma_free_value (call_value); + + return ret_string_p; +} /* ecma_builtin_helper_get_to_locale_string_at_index */ + +/** + * Helper function to normalizing an array index + * + * See also: + * ECMA-262 v5, 15.4.4.10 steps 5, 6, 7 part 2, 8 + * ECMA-262 v5, 15.4.4.12 steps 5, 6 + * + * ECMA-262 v6, 22.1.3.6 steps 5 - 7, 8 part 2, 9, 10 + * ECMA-262 v6, 22.1.3.3 steps 5 - 10, 11 part 2, 12, 13 + * + * Used by: + * - The Array.prototype.slice routine. + * - The Array.prototype.splice routine. + * - The Array.prototype.fill routine. + * - The Array.prototype.copyWithin routine. + * + * @return ECMA_VALUE_EMPTY if successful + * conversion error otherwise + */ +ecma_value_t +ecma_builtin_helper_array_index_normalize (ecma_value_t arg, /**< index */ + ecma_length_t length, /**< array's length */ + ecma_length_t *number_p) /**< [out] ecma_length_t */ +{ + ecma_number_t to_int; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg, &to_int))) + { + return ECMA_VALUE_ERROR; + } + + *number_p = ((to_int < 0) ? (ecma_length_t) JERRY_MAX (((ecma_number_t) length + to_int), 0) + : (ecma_length_t) JERRY_MIN (to_int, (ecma_number_t) length)); + + return ECMA_VALUE_EMPTY; +} /* ecma_builtin_helper_array_index_normalize */ + +/** + * Helper function to normalizing an uint32 index + * + * See also: + * ECMA-262 v5, 15.5.4.13 steps 4 - 7 + * ECMA-262 v6, 22.2.3.5 steps 5 - 10, 11 part 2, 12, 13 + * ECMA-262 v6, 22.2.3.23 steps 5 - 10 + * ECMA-262 v6, 24.1.4.3 steps 6 - 8, 9 part 2, 10, 11 + * ECMA-262 v6, 22.2.3.26 steps 7 - 9, 10 part 2, 11, 12 + * ECMA-262 v6, 22.2.3.8 steps 5 - 7, 8 part 2, 9, 10 + * + * Used by: + * - The String.prototype.slice routine. + * - The Array.prototype.copyWithin routine. + * - The TypedArray.prototype.copyWithin routine. + * - The TypedArray.prototype.slice routine. + * - The ArrayBuffer.prototype.slice routine. + * - The TypedArray.prototype.subarray routine. + * - The TypedArray.prototype.fill routine. + * + * @return ECMA_VALUE_EMPTY if successful + * conversion error otherwise + */ +ecma_value_t +ecma_builtin_helper_uint32_index_normalize (ecma_value_t arg, /**< index */ + uint32_t length, /**< array's length */ + uint32_t *number_p) /**< [out] uint32_t number */ +{ + ecma_number_t to_int; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg, &to_int))) + { + return ECMA_VALUE_ERROR; + } + + *number_p = ((to_int < 0) ? (uint32_t) JERRY_MAX ((ecma_number_t) length + to_int, 0) + : (uint32_t) JERRY_MIN (to_int, (ecma_number_t) length)); + + return ECMA_VALUE_EMPTY; +} /* ecma_builtin_helper_uint32_index_normalize */ + +/** + * Helper function for concatenating an ecma_value_t to an Array. + * + * See also: + * ECMA-262 v5, 15.4.4.4 steps 5.b - 5.c + * + * Used by: + * - The Array.prototype.concat routine. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_helper_array_concat_value (ecma_object_t *array_obj_p, /**< array */ + ecma_length_t *length_p, /**< [in,out] array's length */ + ecma_value_t value) /**< value to concat */ +{ + /* 5.b */ + ecma_value_t is_spreadable = ecma_op_is_concat_spreadable (value); + + if (ECMA_IS_VALUE_ERROR (is_spreadable)) + { + return is_spreadable; + } + + bool spread_object = is_spreadable == ECMA_VALUE_TRUE; + /* ES11: 22.1.3.1.5.c.iv.3.b */ + const uint32_t prop_flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + + if (spread_object) + { + ecma_object_t *obj_p = ecma_get_object_from_value (value); + + ecma_length_t arg_len; + ecma_value_t error = ecma_op_object_get_length (obj_p, &arg_len); + + if (ECMA_IS_VALUE_ERROR (error)) + { + return error; + } + + /* 4 . */ + if ((ecma_number_t) (*length_p + arg_len) > ECMA_NUMBER_MAX_SAFE_INTEGER) + { + return ecma_raise_type_error (ECMA_ERR_INVALID_ARRAY_LENGTH); + } + + /* 5.b.iii */ + for (ecma_length_t array_index = 0; array_index < arg_len; array_index++) + { + /* 5.b.iii.2 */ + ecma_value_t get_value = ecma_op_object_find_by_index (obj_p, array_index); + + if (ECMA_IS_VALUE_ERROR (get_value)) + { + return get_value; + } + + if (!ecma_is_value_found (get_value)) + { + continue; + } + + /* 5.b.iii.3.b */ + /* This will always be a simple value since 'is_throw' is false, so no need to free. */ + ecma_value_t put_comp = + ecma_builtin_helper_def_prop_by_index (array_obj_p, *length_p + array_index, get_value, prop_flags); + ecma_free_value (get_value); + + if (ECMA_IS_VALUE_ERROR (put_comp)) + { + return put_comp; + } + } + + *length_p += arg_len; + return ECMA_VALUE_EMPTY; + } + + /* 5.c.i */ + /* This will always be a simple value since 'is_throw' is false, so no need to free. */ + ecma_value_t put_comp = ecma_builtin_helper_def_prop_by_index (array_obj_p, (*length_p)++, value, prop_flags); + + if (ECMA_IS_VALUE_ERROR (put_comp)) + { + return put_comp; + } + + return ECMA_VALUE_EMPTY; +} /* ecma_builtin_helper_array_concat_value */ + +/** + * Helper function to normalizing a string index + * + * This function clamps the given index to the [0, length] range. + * If the index is negative, 0 value is used. + * If the index is greater than the length of the string, the normalized index will be the length of the string. + * NaN is mapped to zero or length depending on the nan_to_zero parameter. + * + * See also: + * ECMA-262 v5, 15.5.4.15 + * + * Used by: + * - The String.prototype.substring routine. + * - The ecma_builtin_helper_string_prototype_object_index_of helper routine. + * + * @return lit_utf8_size_t - the normalized value of the index + */ +lit_utf8_size_t +ecma_builtin_helper_string_index_normalize (ecma_number_t index, /**< index */ + lit_utf8_size_t length, /**< string's length */ + bool nan_to_zero) /**< whether NaN is mapped to zero (t) or length (f) */ +{ + uint32_t norm_index = 0; + + if (ecma_number_is_nan (index)) + { + if (!nan_to_zero) + { + norm_index = length; + } + } + else if (!ecma_number_is_negative (index)) + { + if (ecma_number_is_infinity (index)) + { + norm_index = length; + } + else + { + norm_index = ecma_number_to_uint32 (index); + + if (norm_index > length) + { + norm_index = length; + } + } + } + + return norm_index; +} /* ecma_builtin_helper_string_index_normalize */ + +/** + * Helper function for finding lastindex of a search string + * + * This function clamps the given index to the [0, length] range. + * If the index is negative, 0 value is used. + * If the index is greater than the length of the string, the normalized index will be the length of the string. + * + * See also: + * ECMA-262 v6, 21.1.3.9 + * + * Used by: + * - The ecma_builtin_helper_string_prototype_object_index_of helper routine. + * - The ecma_builtin_string_prototype_object_replace_match helper routine. + * + * @return uint32_t - whether there is a match for the search string + */ +static uint32_t +ecma_builtin_helper_string_find_last_index (ecma_string_t *original_str_p, /**< original string */ + ecma_string_t *search_str_p, /**< search string */ + uint32_t position) /**< start_position */ +{ + if (ecma_string_is_empty (search_str_p)) + { + return position; + } + + uint32_t original_length = ecma_string_get_length (original_str_p); + + ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8_p, search_str_size); + ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8_p, original_str_size); + + uint32_t ret_value = UINT32_MAX; + + if (original_str_size >= search_str_size) + { + const lit_utf8_byte_t *end_p = original_str_utf8_p + original_str_size; + const lit_utf8_byte_t *current_p = end_p; + + for (ecma_number_t i = original_length; i > position; i--) + { + lit_utf8_decr (¤t_p); + } + + while (current_p + search_str_size > end_p) + { + lit_utf8_decr (¤t_p); + position--; + } + + while (true) + { + if (memcmp (current_p, search_str_utf8_p, search_str_size) == 0) + { + ret_value = position; + break; + } + + if (position == 0) + { + break; + } + + lit_utf8_decr (¤t_p); + position--; + } + } + ECMA_FINALIZE_UTF8_STRING (original_str_utf8_p, original_str_size); + ECMA_FINALIZE_UTF8_STRING (search_str_utf8_p, search_str_size); + + return ret_value; +} /* ecma_builtin_helper_string_find_last_index */ + +/** + * Helper function for string indexOf, lastIndexOf, startsWith, includes, endsWith functions + * + * See also: + * ECMA-262 v5, 15.5.4.7 + * ECMA-262 v5, 15.5.4.8 + * ECMA-262 v6, 21.1.3.6 + * ECMA-262 v6, 21.1.3.7 + * ECMA-262 v6, 21.1.3.18 + * + * Used by: + * - The String.prototype.indexOf routine. + * - The String.prototype.lastIndexOf routine. + * - The String.prototype.startsWith routine. + * - The String.prototype.includes routine. + * - The String.prototype.endsWith routine. + * + * @return ecma_value_t - Returns index (last index) or a + * boolean value + */ +ecma_value_t +ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_str_p, /**< this argument */ + ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2, /**< routine's second argument */ + ecma_string_index_of_mode_t mode) /**< routine's mode */ +{ + /* 5 (indexOf) -- 6 (lastIndexOf) */ + const lit_utf8_size_t original_len = ecma_string_get_length (original_str_p); + + /* 4, 6 (startsWith, includes, endsWith) */ + if (mode >= ECMA_STRING_STARTS_WITH) + { + ecma_value_t regexp = ecma_op_is_regexp (arg1); + + if (ECMA_IS_VALUE_ERROR (regexp)) + { + return regexp; + } + + if (regexp == ECMA_VALUE_TRUE) + { + JERRY_ASSERT (ECMA_STRING_LAST_INDEX_OF < mode && mode <= ECMA_STRING_ENDS_WITH); + return ecma_raise_type_error (ECMA_ERR_SEARCH_STRING_CANNOT_BE_OF_TYPE_REGEXP); + } + } + + /* 7, 8 */ + ecma_string_t *search_str_p = ecma_op_to_string (arg1); + + if (JERRY_UNLIKELY (search_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_value; + + /* 4 (indexOf, lastIndexOf), 9 (startsWith, includes), 10 (endsWith) */ + ecma_number_t pos_num; + + if (mode > ECMA_STRING_LAST_INDEX_OF) + { + ret_value = ecma_op_to_integer (arg2, &pos_num); + } + else + { + ret_value = ecma_op_to_number (arg2, &pos_num); + } + + /* 10 (startsWith, includes), 11 (endsWith) */ + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_deref_ecma_string (search_str_p); + return ret_value; + } + + bool use_first_index = mode != ECMA_STRING_LAST_INDEX_OF; + + /* 4b, 6 (indexOf) - 4b, 5, 7 (lastIndexOf) */ + lit_utf8_size_t start = ecma_builtin_helper_string_index_normalize (pos_num, original_len, use_first_index); + + ecma_number_t ret_num = ECMA_NUMBER_MINUS_ONE; + + ret_value = ECMA_VALUE_FALSE; + + switch (mode) + { + case ECMA_STRING_STARTS_WITH: + { + if (start > original_len) + { + break; + } + /* 15, 16 (startsWith) */ + uint32_t index = ecma_builtin_helper_string_find_index (original_str_p, search_str_p, start); + ret_value = ecma_make_boolean_value (index == start); + break; + } + case ECMA_STRING_INCLUDES: + { + if (ecma_builtin_helper_string_find_index (original_str_p, search_str_p, start) != UINT32_MAX) + { + ret_value = ECMA_VALUE_TRUE; + } + break; + } + case ECMA_STRING_ENDS_WITH: + { + if (start == 0) + { + start = original_len; + } + + lit_utf8_size_t search_str_len = ecma_string_get_length (search_str_p); + + if (search_str_len == 0) + { + ret_value = ECMA_VALUE_TRUE; + break; + } + + int32_t start_ends_with = (int32_t) (start - search_str_len); + + if (start_ends_with < 0) + { + break; + } + uint32_t index = ecma_builtin_helper_string_find_index (original_str_p, search_str_p, (uint32_t) start_ends_with); + ret_value = ecma_make_boolean_value (index == (uint32_t) start_ends_with); + break; + } + case ECMA_STRING_INDEX_OF: + { + /* 8 (indexOf) -- 9 (lastIndexOf) */ + ecma_value_t find_index = ecma_builtin_helper_string_find_index (original_str_p, search_str_p, start); + + if (find_index != UINT32_MAX) + { + ret_num = ((ecma_number_t) find_index); + } + ret_value = ecma_make_number_value (ret_num); + break; + } + + case ECMA_STRING_LAST_INDEX_OF: + { + uint32_t index = ecma_builtin_helper_string_find_last_index (original_str_p, search_str_p, start); + + if (index != UINT32_MAX) + { + ret_num = ((ecma_number_t) index); + } + ret_value = ecma_make_number_value (ret_num); + break; + } + + default: + { + JERRY_UNREACHABLE (); + } + } + + ecma_deref_ecma_string (search_str_p); + + return ret_value; +} /* ecma_builtin_helper_string_prototype_object_index_of */ + +/** + * Helper function for finding index of a search string + * + * This function clamps the given index to the [0, length] range. + * If the index is negative, 0 value is used. + * If the index is greater than the length of the string, the normalized index will be the length of the string. + * + * See also: + * ECMA-262 v6, 21.1.3.8 + * + * Used by: + * - The ecma_builtin_helper_string_prototype_object_index_of helper routine. + * - The ecma_builtin_string_prototype_object_replace_match helper routine. + * + * @return uint32_t - whether there is a match for the search string + */ +uint32_t +ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index */ + ecma_string_t *search_str_p, /**< string's length */ + uint32_t start_pos) /**< start position */ +{ + uint32_t match_found = UINT32_MAX; + + if (ecma_string_is_empty (search_str_p)) + { + return start_pos; + } + + ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8_p, search_str_size); + ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8_p, original_str_size); + + const lit_utf8_byte_t *str_current_p = original_str_utf8_p; + + for (ecma_number_t i = 0; i < start_pos; i++) + { + lit_utf8_incr (&str_current_p); + } + + const lit_utf8_byte_t *original_end_p = original_str_utf8_p + original_str_size; + + while (!((size_t) (original_end_p - str_current_p) < search_str_size)) + { + if (memcmp (str_current_p, search_str_utf8_p, search_str_size) == 0) + { + match_found = start_pos; + break; + } + + lit_utf8_incr (&str_current_p); + start_pos++; + } + + ECMA_FINALIZE_UTF8_STRING (original_str_utf8_p, original_str_size); + ECMA_FINALIZE_UTF8_STRING (search_str_utf8_p, search_str_size); + + return match_found; +} /* ecma_builtin_helper_string_find_index */ + +/** + * Helper function for using [[DefineOwnProperty]] specialized for indexed property names + * + * Note: this method falls back to the general ecma_builtin_helper_def_prop + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, /**< object */ + ecma_length_t index, /**< property index */ + ecma_value_t value, /**< value */ + uint32_t opts) /**< any combination of ecma_property_flag_t bits */ +{ + if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return ecma_builtin_helper_def_prop (obj_p, ECMA_CREATE_DIRECT_UINT32_STRING (index), value, opts); + } + + ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index); + ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p, index_str_p, value, opts); + ecma_deref_ecma_string (index_str_p); + + return ret_value; +} /* ecma_builtin_helper_def_prop_by_index */ + +/** + * Helper function for at() functions. + * + * See also: + * ECMA-262 Stage 3 Draft Relative Indexing Method proposal 3. 4. 5. 6. + * + * Used by: + * - The Array.prototype.at routine. + * - The String.prototype.at routine. + * - The TypedArray.prototype.at routine. + * + * @return ECMA_VALUE_ERROR - on conversion error + * ECMA_VALUE_UNDEFINED - if the requested index is not exist + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +ecma_builtin_helper_calculate_index (ecma_value_t index, /**< relative index argument */ + ecma_length_t length, /**< object's length */ + ecma_length_t *out_index) /**< calculated index */ +{ + JERRY_ASSERT (out_index != NULL); + + ecma_number_t relative_index; + ecma_value_t conversion_result = ecma_op_to_integer (index, &relative_index); + + /* 4. */ + if (ECMA_IS_VALUE_ERROR (conversion_result)) + { + return ECMA_VALUE_ERROR; + } + + /* 5. 6. */ + ecma_number_t k; + + if (relative_index >= 0) + { + k = relative_index; + } + else + { + k = ((ecma_number_t) length + relative_index); + } + + /* 7. */ + if (k < 0 || k >= ((ecma_number_t) length)) + { + return ECMA_VALUE_UNDEFINED; + } + + *out_index = (ecma_length_t) k; + + return ECMA_VALUE_EMPTY; +} /* ecma_builtin_helper_calculate_index */ + +/** + * Helper function for using [[DefineOwnProperty]]. + * + * See also: + * ECMA-262 v5, 8.12.9 + * ECMA-262 v5, 15.4.5.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */ + ecma_string_t *name_p, /**< name string */ + ecma_value_t value, /**< value */ + uint32_t opts) /**< any combination of ecma_property_descriptor_status_flags_t bits */ +{ + ecma_property_descriptor_t prop_desc; + + prop_desc.flags = (uint16_t) (ECMA_NAME_DATA_PROPERTY_DESCRIPTOR_BITS | opts); + + prop_desc.value = value; + + return ecma_op_object_define_own_property (obj_p, name_p, &prop_desc); +} /* ecma_builtin_helper_def_prop */ + +/** + * GetSubstitution abstract operation + * + * See: + * ECMA-262 v6.0 21.1.3.14.1 + */ +void +ecma_builtin_replace_substitute (ecma_replace_context_t *ctx_p) /**< replace context */ +{ + JERRY_ASSERT (ctx_p->string_p != NULL); + JERRY_ASSERT (ctx_p->matched_p == NULL + || (ctx_p->matched_p >= ctx_p->string_p && ctx_p->matched_p <= ctx_p->string_p + ctx_p->string_size)); + + lit_utf8_size_t replace_size; + uint8_t replace_flags = ECMA_STRING_FLAG_IS_ASCII; + const lit_utf8_byte_t *replace_buf_p = + ecma_string_get_chars (ctx_p->replace_str_p, &replace_size, NULL, NULL, &replace_flags); + + const lit_utf8_byte_t *const replace_end_p = replace_buf_p + replace_size; + const lit_utf8_byte_t *curr_p = replace_buf_p; + const lit_utf8_byte_t *last_inserted_end_p = replace_buf_p; + + while (curr_p < replace_end_p) + { + if (*curr_p++ == LIT_CHAR_DOLLAR_SIGN) + { + ecma_stringbuilder_append_raw (&(ctx_p->builder), + last_inserted_end_p, + (lit_utf8_size_t) (curr_p - last_inserted_end_p - 1)); + if (curr_p >= replace_end_p) + { + last_inserted_end_p = curr_p - 1; + break; + } + + const lit_utf8_byte_t c = *curr_p++; + + switch (c) + { + case LIT_CHAR_DOLLAR_SIGN: + { + ecma_stringbuilder_append_byte (&(ctx_p->builder), LIT_CHAR_DOLLAR_SIGN); + break; + } + case LIT_CHAR_AMPERSAND: + { + if (JERRY_UNLIKELY (ctx_p->matched_p == NULL)) + { + JERRY_ASSERT (ctx_p->capture_count == 0); + JERRY_ASSERT (ctx_p->u.collection_p != NULL); + JERRY_ASSERT (ctx_p->u.collection_p->item_count > 0); + const ecma_value_t match_value = ctx_p->u.collection_p->buffer_p[0]; + + JERRY_ASSERT (ecma_is_value_string (match_value)); + ecma_stringbuilder_append (&(ctx_p->builder), ecma_get_string_from_value (match_value)); + break; + } + + JERRY_ASSERT (ctx_p->matched_p != NULL); + ecma_stringbuilder_append_raw (&(ctx_p->builder), ctx_p->matched_p, ctx_p->matched_size); + break; + } + case LIT_CHAR_GRAVE_ACCENT: + { + ecma_stringbuilder_append_raw (&(ctx_p->builder), ctx_p->string_p, ctx_p->match_byte_pos); + break; + } + case LIT_CHAR_SINGLE_QUOTE: + { + if (JERRY_UNLIKELY (ctx_p->matched_p == NULL)) + { + JERRY_ASSERT (ctx_p->capture_count == 0); + JERRY_ASSERT (ctx_p->u.collection_p != NULL); + JERRY_ASSERT (ctx_p->u.collection_p->item_count > 0); + const ecma_value_t match_value = ctx_p->u.collection_p->buffer_p[0]; + + JERRY_ASSERT (ecma_is_value_string (match_value)); + const ecma_string_t *const matched_p = ecma_get_string_from_value (match_value); + const lit_utf8_size_t match_size = ecma_string_get_size (matched_p); + const lit_utf8_byte_t *const begin_p = ctx_p->string_p + ctx_p->match_byte_pos + match_size; + + ecma_stringbuilder_append_raw (&(ctx_p->builder), + begin_p, + (lit_utf8_size_t) (ctx_p->string_p + ctx_p->string_size - begin_p)); + break; + } + + JERRY_ASSERT (ctx_p->matched_p != NULL); + ecma_stringbuilder_append_raw (&(ctx_p->builder), + ctx_p->matched_p + ctx_p->matched_size, + ctx_p->string_size - ctx_p->match_byte_pos - ctx_p->matched_size); + break; + } + default: + { + const lit_utf8_byte_t *const number_begin_p = curr_p - 1; + + if (lit_char_is_decimal_digit (c)) + { + uint32_t capture_count = ctx_p->capture_count; + + if (capture_count == 0 && ctx_p->u.collection_p != NULL) + { + capture_count = ctx_p->u.collection_p->item_count; + } + + uint8_t idx = (uint8_t) (c - LIT_CHAR_0); + if (curr_p < replace_end_p && lit_char_is_decimal_digit (*(curr_p))) + { + uint8_t two_digit_index = (uint8_t) (idx * 10 + (uint8_t) (*(curr_p) -LIT_CHAR_0)); + if (two_digit_index < capture_count) + { + idx = two_digit_index; + curr_p++; + } + } + + if (idx > 0 && idx < capture_count) + { + if (ctx_p->capture_count > 0) + { +#if JERRY_BUILTIN_REGEXP + JERRY_ASSERT (ctx_p->u.captures_p != NULL); + const ecma_regexp_capture_t *const capture_p = ctx_p->u.captures_p + idx; + + if (ECMA_RE_IS_CAPTURE_DEFINED (capture_p)) + { + ecma_stringbuilder_append_raw (&(ctx_p->builder), + capture_p->begin_p, + (lit_utf8_size_t) (capture_p->end_p - capture_p->begin_p)); + } + + break; +#endif /* JERRY_BUILTIN_REGEXP */ + } + else if (ctx_p->u.collection_p != NULL) + { + const ecma_value_t capture_value = ctx_p->u.collection_p->buffer_p[idx]; + if (!ecma_is_value_undefined (capture_value)) + { + ecma_stringbuilder_append (&(ctx_p->builder), ecma_get_string_from_value (capture_value)); + } + + break; + } + } + } + + ecma_stringbuilder_append_byte (&(ctx_p->builder), LIT_CHAR_DOLLAR_SIGN); + curr_p = number_begin_p; + break; + } + } + + last_inserted_end_p = curr_p; + } + } + + ecma_stringbuilder_append_raw (&(ctx_p->builder), + last_inserted_end_p, + (lit_utf8_size_t) (replace_end_p - last_inserted_end_p)); + + if (replace_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) replace_buf_p, replace_size); + } +} /* ecma_builtin_replace_substitute */ + +/** + * Helper function to determine if method is the builtin exec method + * + * @return true, if function is the builtin exec method + * false, otherwise + */ +bool +ecma_builtin_is_regexp_exec (ecma_extended_object_t *obj_p) /**< function object */ +{ + return (ecma_get_object_type (&obj_p->object) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION + && obj_p->u.built_in.routine_id == ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC); +} /* ecma_builtin_is_regexp_exec */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h new file mode 100644 index 0000000..34bf7d2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h @@ -0,0 +1,232 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BUILTIN_HELPERS_H +#define ECMA_BUILTIN_HELPERS_H + +#include "ecma-exceptions.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-regexp-object.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations + * @{ + */ + +/** + * List of built-in routine identifiers. + */ +enum +{ + /** These routines must be in this order */ + ECMA_REGEXP_PROTOTYPE_ROUTINE_START = 0, + ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC, +#if JERRY_BUILTIN_ANNEXB + ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE, +#endif /* JERRY_BUILTIN_ANNEXB */ + + ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST, + ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_FLAGS, + + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL, + + ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SEARCH, + ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH, + ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_REPLACE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SPLIT, + ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH_ALL, +}; + +/** + * Mode of string index routine. + */ +typedef enum +{ + /** These routines must be in this order */ + ECMA_STRING_LAST_INDEX_OF, /**< String.lastIndexOf: ECMA-262 v5, 15.5.4.8 */ + ECMA_STRING_INDEX_OF, /**< String.indexOf: ECMA-262 v5, 15.5.4.7 */ + ECMA_STRING_STARTS_WITH, /**< String.startsWith: ECMA-262 v6, 21.1.3.18 */ + ECMA_STRING_INCLUDES, /**< String.includes: ECMA-262 v6, 21.1.3.7 */ + ECMA_STRING_ENDS_WITH /**< String.includes: ECMA-262 v6, 21.1.3.6 */ +} ecma_string_index_of_mode_t; + +ecma_value_t ecma_builtin_helper_object_to_string (const ecma_value_t this_arg); +ecma_string_t *ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, ecma_length_t index); +ecma_value_t ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, ecma_length_t *length_p, ecma_value_t value); +ecma_value_t ecma_builtin_helper_uint32_index_normalize (ecma_value_t arg, uint32_t length, uint32_t *number_p); +ecma_value_t +ecma_builtin_helper_array_index_normalize (ecma_value_t arg, ecma_length_t length, ecma_length_t *number_p); +ecma_value_t ecma_builtin_helper_string_index_normalize (ecma_number_t index, uint32_t length, bool nan_to_zero); +ecma_value_t ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_str_p, + ecma_value_t arg1, + ecma_value_t arg2, + ecma_string_index_of_mode_t mode); +uint32_t +ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, ecma_string_t *search_str_p, uint32_t start_pos); +ecma_value_t +ecma_builtin_helper_def_prop (ecma_object_t *obj_p, ecma_string_t *name_p, ecma_value_t value, uint32_t opts); + +ecma_value_t +ecma_builtin_helper_def_prop_by_index (ecma_object_t *obj_p, ecma_length_t index, ecma_value_t value, uint32_t opts); +ecma_value_t ecma_builtin_helper_calculate_index (ecma_value_t index, ecma_length_t length, ecma_length_t *out_index); + +/** + * Context for replace substitutions + */ +typedef struct +{ + ecma_stringbuilder_t builder; /**< result string builder */ + const lit_utf8_byte_t *string_p; /**< source string */ + lit_utf8_size_t string_size; /**< source string size */ + const lit_utf8_byte_t *matched_p; /**< matched string */ + lit_utf8_size_t matched_size; /**< matched string size */ + lit_utf8_size_t match_byte_pos; /**< byte position of the match in the source string */ + uint16_t flags; /**< replace flags */ + + /** + * Capture results + */ + union + { +#if JERRY_BUILTIN_REGEXP + const ecma_regexp_capture_t *captures_p; /**< array of regexp capturing groups */ +#endif /* JERRY_BUILTIN_REGEXP */ + const ecma_collection_t *collection_p; /**< collection of captured substrings */ + } u; + + uint32_t capture_count; /**< number of captures in the capturing group array */ + ecma_string_t *replace_str_p; /**< replacement string */ +} ecma_replace_context_t; + +void ecma_builtin_replace_substitute (ecma_replace_context_t *ctx_p); +bool ecma_builtin_is_regexp_exec (ecma_extended_object_t *obj_p); + +#if JERRY_BUILTIN_DATE + +/** + * Time range defines for helper functions. + * + * See also: + * ECMA-262 v5, 15.9.1.1, 15.9.1.10 + */ + +/** Hours in a day. */ +#define ECMA_DATE_HOURS_PER_DAY (24) + +/** Minutes in an hour. */ +#define ECMA_DATE_MINUTES_PER_HOUR (60) + +/** Seconds in a minute. */ +#define ECMA_DATE_SECONDS_PER_MINUTE (60) + +/** Milliseconds in a second. */ +#define ECMA_DATE_MS_PER_SECOND (1000) + +/** ECMA_DATE_MS_PER_MINUTE == 60000 */ +#define ECMA_DATE_MS_PER_MINUTE (ECMA_DATE_MS_PER_SECOND * ECMA_DATE_SECONDS_PER_MINUTE) + +/** ECMA_DATE_MS_PER_HOUR == 3600000 */ +#define ECMA_DATE_MS_PER_HOUR (ECMA_DATE_MS_PER_MINUTE * ECMA_DATE_MINUTES_PER_HOUR) + +/** ECMA_DATE_MS_PER_DAY == 86400000 */ +#define ECMA_DATE_MS_PER_DAY ((ECMA_DATE_MS_PER_HOUR * ECMA_DATE_HOURS_PER_DAY)) + +#define ECMA_DATE_DAYS_IN_YEAR (365) + +#define ECMA_DATE_DAYS_IN_LEAP_YEAR (366) + +/** + * This gives a range of 8,640,000,000,000,000 milliseconds + * to either side of 01 January, 1970 UTC. + */ +#define ECMA_DATE_MAX_VALUE 8.64e15 + +/** + * Timezone type. + */ +typedef enum +{ + ECMA_DATE_UTC, /**< date value is in UTC */ + ECMA_DATE_LOCAL /**< date value is in local time */ +} ecma_date_timezone_t; + +/* ecma-builtin-helpers-date.c */ +extern const char* day_names_p[7]; +extern const char* month_names_p[12]; + +int32_t ecma_date_day_from_time (ecma_number_t time); +int32_t ecma_date_year_from_time (ecma_number_t time); +int32_t ecma_date_month_from_time (ecma_number_t time); +int32_t ecma_date_date_from_time (ecma_number_t time); +int32_t ecma_date_week_day (ecma_number_t time); +int32_t ecma_date_hour_from_time (ecma_number_t time); +int32_t ecma_date_min_from_time (ecma_number_t time); +int32_t ecma_date_sec_from_time (ecma_number_t time); +int32_t ecma_date_ms_from_time (ecma_number_t time); +int32_t ecma_date_time_in_day_from_time (ecma_number_t time); + +int32_t ecma_date_local_time_zone_adjustment (ecma_number_t time); +ecma_number_t ecma_date_utc (ecma_number_t time); +ecma_number_t ecma_date_make_time (ecma_number_t hour, ecma_number_t min, ecma_number_t sec, ecma_number_t ms); +ecma_number_t ecma_date_make_day (ecma_number_t year, ecma_number_t month, ecma_number_t date); +ecma_number_t ecma_date_make_date (ecma_number_t day, ecma_number_t time); +ecma_number_t ecma_date_time_clip (ecma_number_t time); + +ecma_value_t ecma_date_value_to_string (ecma_number_t datetime_number); +ecma_value_t ecma_date_value_to_utc_string (ecma_number_t datetime_number); +ecma_value_t ecma_date_value_to_iso_string (ecma_number_t datetime_number); +ecma_value_t ecma_date_value_to_date_string (ecma_number_t datetime_number); +ecma_value_t ecma_date_value_to_time_string (ecma_number_t datetime_number); + +#endif /* JERRY_BUILTIN_DATE */ + +/* ecma-builtin-helper-error.c */ + +ecma_value_t ecma_builtin_helper_error_dispatch_call (jerry_error_t error_type, + const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len); + +/* ecma-builtin-helpers-sort.c */ + +/** + * Comparison callback function header for sorting helper routines. + */ +typedef ecma_value_t (*ecma_builtin_helper_sort_compare_fn_t) (ecma_value_t lhs, /**< left value */ + ecma_value_t rhs, /**< right value */ + ecma_value_t compare_func, /**< compare function */ + ecma_object_t *array_buffer_p /**< arrayBuffer */); + +ecma_value_t ecma_builtin_helper_array_merge_sort_helper (ecma_value_t *array_p, + uint32_t length, + ecma_value_t compare_func, + const ecma_builtin_helper_sort_compare_fn_t sort_cb, + ecma_object_t *array_buffer_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_BUILTIN_HELPERS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h new file mode 100644 index 0000000..3755f61 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h @@ -0,0 +1,241 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BUILTIN_UNDERSCORED_ID +#error "Please, define BUILTIN_UNDERSCORED_ID" +#endif /* !BUILTIN_UNDERSCORED_ID */ + +#ifndef BUILTIN_INC_HEADER_NAME +#error "Please, define BUILTIN_INC_HEADER_NAME" +#endif /* !BUILTIN_INC_HEADER_NAME */ + +#include "ecma-objects.h" + +#define PASTE__(x, y) x##y +#define PASTE_(x, y) PASTE__ (x, y) +#define PASTE(x, y) PASTE_ (x, y) + +#define PROPERTY_DESCRIPTOR_LIST_NAME PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _property_descriptor_list) +#define DISPATCH_ROUTINE_ROUTINE_NAME PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _dispatch_routine) + +#ifndef BUILTIN_CUSTOM_DISPATCH + +#define ROUTINE_ARG(n) , ecma_value_t arg##n +#define ROUTINE_ARG_LIST_0 ecma_value_t this_arg +#define ROUTINE_ARG_LIST_1 ROUTINE_ARG_LIST_0 ROUTINE_ARG (1) +#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1 ROUTINE_ARG (2) +#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2 ROUTINE_ARG (3) +#define ROUTINE_ARG_LIST_NON_FIXED ROUTINE_ARG_LIST_0, const ecma_value_t *arguments_list_p, uint32_t arguments_list_len +#define ROUTINE(name, c_function_name, args_number, length_prop_value) \ + static ecma_value_t c_function_name (ROUTINE_ARG_LIST_##args_number); +#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \ + static ecma_value_t c_function_name (ROUTINE_ARG_LIST_##args_number); +#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \ + static ecma_value_t c_function_name (ROUTINE_ARG_LIST_##args_number); +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + static ecma_value_t c_getter_func_name (ROUTINE_ARG_LIST_0); \ + static ecma_value_t c_setter_func_name (ROUTINE_ARG_LIST_1); +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + static ecma_value_t c_getter_func_name (ROUTINE_ARG_LIST_0); +#include BUILTIN_INC_HEADER_NAME +#undef ROUTINE_ARG_LIST_NON_FIXED +#undef ROUTINE_ARG_LIST_3 +#undef ROUTINE_ARG_LIST_2 +#undef ROUTINE_ARG_LIST_1 +#undef ROUTINE_ARG_LIST_0 +#undef ROUTINE_ARG + +/** + * List of built-in routine identifiers. + */ +enum +{ + PASTE (ECMA_ROUTINE_START_, BUILTIN_UNDERSCORED_ID) = 0, +#define ROUTINE(name, c_function_name, args_number, length_prop_value) ECMA_ROUTINE_##name##c_function_name, +#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \ + ECMA_ROUTINE_##name##c_function_name, +#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \ + ECMA_ROUTINE_##name##c_function_name, +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + ECMA_ACCESSOR_##name##c_getter_func_name, ECMA_ACCESSOR_##name##c_setter_func_name, +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) ECMA_ACCESSOR_##name##c_getter_func_name, +#include BUILTIN_INC_HEADER_NAME +}; + +#endif /* !BUILTIN_CUSTOM_DISPATCH */ + +/** + * Built-in property list of the built-in object. + */ +const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] = { +#ifndef BUILTIN_CUSTOM_DISPATCH +#define ROUTINE(name, c_function_name, args_number, length_prop_value) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ROUTINE, \ + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_WRITABLE, \ + ECMA_ROUTINE_VALUE (ECMA_ROUTINE_##name##c_function_name, length_prop_value) }, +#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ROUTINE, \ + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, \ + ECMA_ROUTINE_VALUE (ECMA_ROUTINE_##name##c_function_name, length_prop_value) }, +#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ROUTINE, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + ECMA_ROUTINE_VALUE (ECMA_ROUTINE_##name##c_function_name, length_prop_value) }, +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + ECMA_ACCESSOR_##name##c_getter_func_name }, +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + ECMA_ACCESSOR_READ_WRITE (ECMA_ACCESSOR_##name##c_getter_func_name, ECMA_ACCESSOR_##name##c_setter_func_name) }, +#else /* BUILTIN_CUSTOM_DISPATCH */ +#define ROUTINE(name, c_function_name, args_number, length_prop_value) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ROUTINE, \ + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_WRITABLE, \ + ECMA_ROUTINE_VALUE (c_function_name, length_prop_value) }, +#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ROUTINE, \ + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, \ + ECMA_ROUTINE_VALUE (c_function_name, length_prop_value) }, +#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ROUTINE, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + ECMA_ROUTINE_VALUE (c_function_name, length_prop_value) }, +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + c_getter_func_name }, +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + ECMA_ACCESSOR_READ_WRITE (c_getter_func_name, c_setter_func_name) }, +#endif /* !BUILTIN_CUSTOM_DISPATCH */ +#define OBJECT_VALUE(name, obj_builtin_id, prop_attributes) \ + { name, ECMA_BUILTIN_PROPERTY_OBJECT, (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, obj_builtin_id }, +#define SIMPLE_VALUE(name, simple_value, prop_attributes) \ + { name, ECMA_BUILTIN_PROPERTY_SIMPLE, (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, simple_value }, +#define NUMBER_VALUE(name, number_value, prop_attributes) \ + { name, ECMA_BUILTIN_PROPERTY_NUMBER, (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, number_value }, +#define STRING_VALUE(name, magic_string_id, prop_attributes) \ + { name, ECMA_BUILTIN_PROPERTY_STRING, (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, magic_string_id }, +#define SYMBOL_VALUE(name, symbol) { name, ECMA_BUILTIN_PROPERTY_SYMBOL, ECMA_PROPERTY_BUILT_IN_FIXED, symbol }, +#define INTRINSIC_PROPERTY(name, magic_string_id, prop_attributes) \ + { name, ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY, (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, magic_string_id }, +#define ACCESSOR_BUILTIN_FUNCTION(name, getter_builtin_id, setter_builtin_id, prop_attributes) \ + { name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION, \ + (prop_attributes) | ECMA_PROPERTY_FLAG_BUILT_IN, \ + ECMA_ACCESSOR_READ_WRITE (getter_builtin_id, setter_builtin_id) }, +#include BUILTIN_INC_HEADER_NAME + { LIT_MAGIC_STRING__COUNT, ECMA_BUILTIN_PROPERTY_END, 0, 0 } +}; + +#ifndef BUILTIN_CUSTOM_DISPATCH + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +DISPATCH_ROUTINE_ROUTINE_NAME (uint8_t builtin_routine_id, /**< built-in wide routine + identifier */ + ecma_value_t this_arg_value, /**< 'this' argument + value */ + const ecma_value_t arguments_list[], /**< list of arguments + passed to routine */ + uint32_t arguments_number) /**< length of + * arguments' list */ +{ + /* the arguments may be unused for some built-ins */ + JERRY_UNUSED (this_arg_value); + JERRY_UNUSED (arguments_list); + JERRY_UNUSED (arguments_number); + + switch (builtin_routine_id) + { +#define ROUTINE_ARG(n) (arguments_list[n - 1]) +#define ROUTINE_ARG_LIST_0 +#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG (1) +#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG (2) +#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG (3) +#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number +#define ROUTINE(name, c_function_name, args_number, length_prop_value) \ + case ECMA_ROUTINE_##name##c_function_name: \ + { \ + return c_function_name (this_arg_value ROUTINE_ARG_LIST_##args_number); \ + } +#define ROUTINE_CONFIGURABLE_ONLY(name, c_function_name, args_number, length_prop_value) \ + case ECMA_ROUTINE_##name##c_function_name: \ + { \ + return c_function_name (this_arg_value ROUTINE_ARG_LIST_##args_number); \ + } +#define ROUTINE_WITH_FLAGS(name, c_function_name, args_number, length_prop_value, flags) \ + case ECMA_ROUTINE_##name##c_function_name: \ + { \ + return c_function_name (this_arg_value ROUTINE_ARG_LIST_##args_number); \ + } +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + case ECMA_ACCESSOR_##name##c_getter_func_name: \ + { \ + return c_getter_func_name (this_arg_value); \ + } \ + case ECMA_ACCESSOR_##name##c_setter_func_name: \ + { \ + return c_setter_func_name (this_arg_value ROUTINE_ARG_LIST_1); \ + } +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + case ECMA_ACCESSOR_##name##c_getter_func_name: \ + { \ + return c_getter_func_name (this_arg_value); \ + } +#include BUILTIN_INC_HEADER_NAME +#undef ROUTINE_ARG +#undef ROUTINE_ARG_LIST_0 +#undef ROUTINE_ARG_LIST_1 +#undef ROUTINE_ARG_LIST_2 +#undef ROUTINE_ARG_LIST_3 +#undef ROUTINE_ARG_LIST_NON_FIXED + + default: + { + JERRY_UNREACHABLE (); + } + } +} /* DISPATCH_ROUTINE_ROUTINE_NAME */ + +#endif /* !BUILTIN_CUSTOM_DISPATCH */ + +#undef BUILTIN_INC_HEADER_NAME +#undef BUILTIN_CUSTOM_DISPATCH +#undef BUILTIN_UNDERSCORED_ID +#undef DISPATCH_ROUTINE_ROUTINE_NAME +#undef ECMA_BUILTIN_PROPERTY_NAME_INDEX +#undef PASTE__ +#undef PASTE_ +#undef PASTE +#undef PROPERTY_DESCRIPTOR_LIST_NAME diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.cpp new file mode 100644 index 0000000..66519dc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.cpp @@ -0,0 +1,305 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-array-object.h" +#include "ecma-arraybuffer-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-container-object.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-string-object.h" +#include "ecma-typedarray-object.h" + +#include "lit-char-helpers.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_INTRINSIC_ROUTINE_START = 0, + ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES, + ECMA_INTRINSIC_TYPEDARRAY_PROTOTYPE_VALUES, + ECMA_INTRINSIC_MAP_PROTOTYPE_ENTRIES, + ECMA_INTRINSIC_SET_PROTOTYPE_VALUES, + ECMA_INTRINSIC_ARRAY_TO_STRING, + ECMA_INTRINSIC_DATE_TO_UTC_STRING, + ECMA_INTRINSIC_PARSE_FLOAT, + ECMA_INTRINSIC_PARSE_INT, + ECMA_INTRINSIC_STRING_TRIM_START, + ECMA_INTRINSIC_STRING_TRIM_END, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-intrinsic.inc.h" +#define BUILTIN_UNDERSCORED_ID intrinsic +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup intrinsic ECMA Intrinsic object built-in + * @{ + */ + +/** + * The %ArrayProto_values% intrinsic routine + * + * See also: + * ECMA-262 v5, 15.4.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_intrinsic_array_prototype_values (ecma_value_t this_value) /**< this argument */ +{ + ecma_value_t this_obj = ecma_op_to_object (this_value); + + if (ECMA_IS_VALUE_ERROR (this_obj)) + { + return this_obj; + } + + ecma_object_t *this_obj_p = ecma_get_object_from_value (this_obj); + + ecma_value_t ret_value = ecma_op_create_array_iterator (this_obj_p, ECMA_ITERATOR_VALUES); + + ecma_deref_object (this_obj_p); + + return ret_value; +} /* ecma_builtin_intrinsic_array_prototype_values */ + +/** + * The Map.prototype entries and [@@iterator] routines + * + * See also: + * ECMA-262 v6, 23.1.3.4 + * ECMA-262 v6, 23.1.3.12 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_intrinsic_map_prototype_entries (ecma_value_t this_value) /**< this value */ +{ + ecma_extended_object_t *map_object_p = ecma_op_container_get_object (this_value, LIT_MAGIC_STRING_MAP_UL); + + if (map_object_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + return ecma_op_container_create_iterator (this_value, + ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE, + ECMA_OBJECT_CLASS_MAP_ITERATOR, + ECMA_ITERATOR_ENTRIES); +} /* ecma_builtin_intrinsic_map_prototype_entries */ + +/** + * The Set.prototype values, keys and [@@iterator] routines + * + * See also: + * ECMA-262 v6, 23.2.3.8 + * ECMA-262 v6, 23.2.3.10 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_intrinsic_set_prototype_values (ecma_value_t this_value) /**< this value */ +{ + ecma_extended_object_t *map_object_p = ecma_op_container_get_object (this_value, LIT_MAGIC_STRING_SET_UL); + + if (map_object_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + return ecma_op_container_create_iterator (this_value, + ECMA_BUILTIN_ID_SET_ITERATOR_PROTOTYPE, + ECMA_OBJECT_CLASS_SET_ITERATOR, + ECMA_ITERATOR_VALUES); +} /* ecma_builtin_intrinsic_set_prototype_values */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_intrinsic_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + switch (builtin_routine_id) + { +#if JERRY_BUILTIN_ARRAY + case ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES: + { + return ecma_builtin_intrinsic_array_prototype_values (this_arg); + } + case ECMA_INTRINSIC_ARRAY_TO_STRING: + { + ecma_value_t this_obj = ecma_op_to_object (this_arg); + if (ECMA_IS_VALUE_ERROR (this_obj)) + { + return this_obj; + } + + ecma_value_t result = ecma_array_object_to_string (this_obj); + ecma_deref_object (ecma_get_object_from_value (this_obj)); + + return result; + } +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_TYPEDARRAY + case ECMA_INTRINSIC_TYPEDARRAY_PROTOTYPE_VALUES: + { + if (!ecma_is_typedarray (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY); + } + + if (ecma_arraybuffer_is_detached (ecma_typedarray_get_arraybuffer (ecma_get_object_from_value (this_arg)))) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + return ecma_typedarray_iterators_helper (this_arg, ECMA_ITERATOR_VALUES); + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_CONTAINER + case ECMA_INTRINSIC_SET_PROTOTYPE_VALUES: + { + return ecma_builtin_intrinsic_set_prototype_values (this_arg); + } + case ECMA_INTRINSIC_MAP_PROTOTYPE_ENTRIES: + { + return ecma_builtin_intrinsic_map_prototype_entries (this_arg); + } +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_DATE + case ECMA_INTRINSIC_DATE_TO_UTC_STRING: + { + if (!ecma_is_value_object (this_arg) + || !ecma_object_class_is (ecma_get_object_from_value (this_arg), ECMA_OBJECT_CLASS_DATE)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_DATE_OBJECT); + } + + ecma_number_t *date_value_p = &((ecma_date_object_t *) ecma_get_object_from_value (this_arg))->date_value; + + if (ecma_number_is_nan (*date_value_p)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_INVALID_DATE_UL); + } + + return ecma_date_value_to_utc_string (*date_value_p); + } +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_STRING + case ECMA_INTRINSIC_STRING_TRIM_START: + case ECMA_INTRINSIC_STRING_TRIM_END: + { + if (!ecma_op_require_object_coercible (this_arg)) + { + return ECMA_VALUE_ERROR; + } + + ecma_string_t *to_str_p = ecma_op_to_string (this_arg); + if (to_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ECMA_STRING_TO_UTF8_STRING (to_str_p, start_p, input_start_size); + + lit_utf8_size_t size; + const lit_utf8_byte_t *input_start_p = start_p; + const lit_utf8_byte_t *input_str_end_p = start_p + input_start_size; + + ecma_string_t *ret_str_p; + if (builtin_routine_id == ECMA_INTRINSIC_STRING_TRIM_START) + { + const lit_utf8_byte_t *new_start_p = ecma_string_trim_front (input_start_p, input_str_end_p); + size = (lit_utf8_size_t) (input_str_end_p - new_start_p); + ret_str_p = ecma_new_ecma_string_from_utf8 (new_start_p, size); + } + else + { + const lit_utf8_byte_t *new_end_p = ecma_string_trim_back (input_start_p, input_str_end_p); + size = (lit_utf8_size_t) (new_end_p - input_start_p); + ret_str_p = ecma_new_ecma_string_from_utf8 (input_start_p, size); + } + + ECMA_FINALIZE_UTF8_STRING (start_p, input_start_size); + ecma_value_t result = ecma_make_string_value (ret_str_p); + ecma_deref_ecma_string (to_str_p); + return result; + } +#endif /* JERRY_BUILTIN_STRING */ + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_INTRINSIC_PARSE_INT || builtin_routine_id == ECMA_INTRINSIC_PARSE_FLOAT); + + ecma_string_t *str_p = ecma_op_to_string (arguments_list_p[0]); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result; + ECMA_STRING_TO_UTF8_STRING (str_p, string_buff, string_buff_size); + + if (builtin_routine_id == ECMA_INTRINSIC_PARSE_INT) + { + result = ecma_number_parse_int (string_buff, string_buff_size, arguments_list_p[1]); + } + else + { + JERRY_ASSERT (builtin_routine_id == ECMA_INTRINSIC_PARSE_FLOAT); + result = ecma_number_parse_float (string_buff, string_buff_size); + } + + ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size); + ecma_deref_ecma_string (str_p); + return result; + } + } +} /* ecma_builtin_intrinsic_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.inc.h new file mode 100644 index 0000000..54c82c4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.inc.h @@ -0,0 +1,35 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Intrinsic built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES, 0, 0) +ROUTINE (LIT_INTERNAL_MAGIC_STRING_TYPEDARRAY_PROTOTYPE_VALUES, ECMA_INTRINSIC_TYPEDARRAY_PROTOTYPE_VALUES, 0, 0) +ROUTINE (LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES, ECMA_INTRINSIC_SET_PROTOTYPE_VALUES, 0, 0) +ROUTINE (LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES, ECMA_INTRINSIC_MAP_PROTOTYPE_ENTRIES, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TRIM_START, ECMA_INTRINSIC_STRING_TRIM_START, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TRIM_END, ECMA_INTRINSIC_STRING_TRIM_END, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_INTRINSIC_ARRAY_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_UTC_STRING_UL, ECMA_INTRINSIC_DATE_TO_UTC_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_INTRINSIC_PARSE_FLOAT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_PARSE_INT, ECMA_INTRINSIC_PARSE_INT, 2, 2) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.cpp new file mode 100644 index 0000000..ca991d6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.cpp @@ -0,0 +1,102 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-iterator-object.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_ITERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_BUILTIN_ITERATOR_PROTOTYPE_OBJECT_ITERATOR, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %iteratorprototype% ECMA %IteratorPrototype% object built-in + * @{ + */ + +/** + * The %IteratorPrototype% object's '@@iterator' routine + * + * See also: + * ECMA-262 v6, 22.1.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return the given this value + */ +static ecma_value_t +ecma_builtin_iterator_prototype_object_iterator (ecma_value_t this_val) /**< this argument */ +{ + /* 1. */ + return ecma_copy_value (this_val); +} /* ecma_builtin_iterator_prototype_object_iterator */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + * routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< + * list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list_p, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_ITERATOR_PROTOTYPE_OBJECT_ITERATOR: + { + return ecma_builtin_iterator_prototype_object_iterator (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_iterator_prototype_dispatch_routine */ +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.inc.h new file mode 100644 index 0000000..4054eb4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %IteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ECMA_BUILTIN_ITERATOR_PROTOTYPE_OBJECT_ITERATOR, 0, 0) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-iterator-prototype.cpp new file mode 100644 index 0000000..9471a45 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-iterator-prototype.cpp @@ -0,0 +1,106 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-container-object.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_MAP_ITERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_BUILTIN_MAP_ITERATOR_PROTOTYPE_ROUTINE_OBJECT_NEXT, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-map-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID map_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %mapiteratorprototype% ECMA %MapIteratorPrototype% object built-in + * @{ + */ + +/** + * The %MapIteratorPrototype% object's 'next' routine + * + * See also: + * ECMA-262 v6, 23.1.5.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +static ecma_value_t +ecma_builtin_map_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */ +{ + return ecma_op_container_iterator_next (this_val, ECMA_OBJECT_CLASS_MAP_ITERATOR); +} /* ecma_builtin_map_iterator_prototype_object_next */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_map_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + * routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list_p, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_MAP_ITERATOR_PROTOTYPE_ROUTINE_OBJECT_NEXT: + { + return ecma_builtin_map_iterator_prototype_object_next (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_map_iterator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-iterator-prototype.inc.h new file mode 100644 index 0000000..fe2b818 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-iterator-prototype.inc.h @@ -0,0 +1,32 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %MapIteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_MAP_ITERATOR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_BUILTIN_MAP_ITERATOR_PROTOTYPE_ROUTINE_OBJECT_NEXT, 0, 0) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.cpp new file mode 100644 index 0000000..d7a10cc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.cpp @@ -0,0 +1,66 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-container-object.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-map-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID map_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup map ECMA Map object built-in + * @{ + */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_map_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + return ecma_builtin_container_dispatch_routine (builtin_routine_id, + this_arg, + arguments_list_p, + LIT_MAGIC_STRING_MAP_UL); +} /* ecma_builtin_map_prototype_dispatch_routine */ +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.inc.h new file mode 100644 index 0000000..65d91d6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.inc.h @@ -0,0 +1,55 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Map.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.1.3.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_MAP, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.1.3.13 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_MAP_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_CLEAR, ECMA_CONTAINER_ROUTINE_CLEAR, 0, 0) +ROUTINE (LIT_MAGIC_STRING_DELETE, ECMA_CONTAINER_ROUTINE_DELETE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_CONTAINER_ROUTINE_FOREACH, 2, 1) +ROUTINE (LIT_MAGIC_STRING_GET, ECMA_CONTAINER_ROUTINE_GET, 1, 1) +ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_CONTAINER_ROUTINE_HAS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET, ECMA_CONTAINER_ROUTINE_SET, 2, 2) +ROUTINE (LIT_MAGIC_STRING_VALUES, ECMA_CONTAINER_ROUTINE_VALUES, 0, 0) +ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_CONTAINER_ROUTINE_KEYS, 0, 0) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_ENTRIES, + LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, + LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.1.3.10 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE, ECMA_CONTAINER_ROUTINE_SIZE_GETTER, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map.cpp new file mode 100644 index 0000000..817b5f9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map.cpp @@ -0,0 +1,86 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-container-object.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-map.inc.h" +#define BUILTIN_UNDERSCORED_ID map +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup map ECMA Map object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Map object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_map_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_MAP_REQUIRES_NEW); +} /* ecma_builtin_map_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Map object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_map_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_op_container_create (arguments_list_p, + arguments_list_len, + LIT_MAGIC_STRING_MAP_UL, + ECMA_BUILTIN_ID_MAP_PROTOTYPE); +} /* ecma_builtin_map_dispatch_construct */ + +/** + * 23.1.2.2 get Map [ @@species ] accessor + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_builtin_map_species_get (ecma_value_t this_value) /**< This Value */ +{ + return ecma_copy_value (this_value); +} /* ecma_builtin_map_species_get */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map.inc.h new file mode 100644 index 0000000..e1ff9c0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-map.inc.h @@ -0,0 +1,44 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Map built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v6, 23.1.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 23.1 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_MAP_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.1.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_MAP_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v6, 23.1.2.2 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ecma_builtin_map_species_get, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.cpp new file mode 100644 index 0000000..426dad9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.cpp @@ -0,0 +1,560 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jrt-libc-includes.h" +#include "jrt.h" + +#if defined(_WIN32) +#include +#endif /* defined(_WIN32) */ + +#if JERRY_BUILTIN_MATH + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_MATH_OBJECT_ROUTINE_START = 0, + + ECMA_MATH_OBJECT_ABS, /* ECMA-262 v5, 15.8.2.1 */ + ECMA_MATH_OBJECT_ACOS, /* ECMA-262 v5, 15.8.2.2 */ + ECMA_MATH_OBJECT_ASIN, /* ECMA-262 v5, 15.8.2.3 */ + ECMA_MATH_OBJECT_ATAN, /* ECMA-262 v5, 15.8.2.4 */ + ECMA_MATH_OBJECT_CEIL, /* ECMA-262 v5, 15.8.2.6 */ + ECMA_MATH_OBJECT_COS, /* ECMA-262 v5, 15.8.2.7 */ + ECMA_MATH_OBJECT_EXP, /* ECMA-262 v5, 15.8.2.8 */ + ECMA_MATH_OBJECT_FLOOR, /* ECMA-262 v5, 15.8.2.9 */ + ECMA_MATH_OBJECT_LOG, /* ECMA-262 v5, 15.8.2.10 */ + ECMA_MATH_OBJECT_ROUND, /* ECMA-262 v5, 15.8.2.15 */ + ECMA_MATH_OBJECT_SIN, /* ECMA-262 v5, 15.8.2.16 */ + ECMA_MATH_OBJECT_SQRT, /* ECMA-262 v5, 15.8.2.17 */ + ECMA_MATH_OBJECT_TAN, /* ECMA-262 v5, 15.8.2.18 */ + ECMA_MATH_OBJECT_ACOSH, /* ECMA-262 v6, 20.2.2.3 */ + ECMA_MATH_OBJECT_ASINH, /* ECMA-262 v6, 20.2.2.5 */ + ECMA_MATH_OBJECT_ATANH, /* ECMA-262 v6, 20.2.2.7 */ + ECMA_MATH_OBJECT_CBRT, /* ECMA-262 v6, 20.2.2.9 */ + ECMA_MATH_OBJECT_CLZ32, /* ECMA-262 v6, 20.2.2.11 */ + ECMA_MATH_OBJECT_COSH, /* ECMA-262 v6, 20.2.2.13 */ + ECMA_MATH_OBJECT_EXPM1, /* ECMA-262 v6, 20.2.2.15 */ + ECMA_MATH_OBJECT_FROUND, /* ECMA-262 v6, 20.2.2.17 */ + ECMA_MATH_OBJECT_LOG1P, /* ECMA-262 v6, 20.2.2.21 */ + ECMA_MATH_OBJECT_LOG10, /* ECMA-262 v6, 20.2.2.22 */ + ECMA_MATH_OBJECT_LOG2, /* ECMA-262 v6, 20.2.2.23 */ + ECMA_MATH_OBJECT_SIGN, /* ECMA-262 v6, 20.2.2.29 */ + ECMA_MATH_OBJECT_SINH, /* ECMA-262 v6, 20.2.2.31 */ + ECMA_MATH_OBJECT_TANH, /* ECMA-262 v6, 20.2.2.34 */ + ECMA_MATH_OBJECT_TRUNC, /* ECMA-262 v6, 20.2.2.35 */ + ECMA_MATH_OBJECT_ATAN2, + /* ECMA-262 v5, 15.8.2.5 */ /* first routine with 2 arguments */ + ECMA_MATH_OBJECT_IMUL, /* ECMA-262 v6, 20.2.2.19 */ + ECMA_MATH_OBJECT_POW, + /* ECMA-262 v5, 15.8.2.13 */ /* last routine with 1 or 2 arguments*/ + ECMA_MATH_OBJECT_MAX, /* ECMA-262 v5, 15.8.2.11 */ + ECMA_MATH_OBJECT_MIN, /* ECMA-262 v5, 15.8.2.12 */ + ECMA_MATH_OBJECT_HYPOT, /* ECMA-262 v6, 20.2.2.18 */ + ECMA_MATH_OBJECT_RANDOM, /* ECMA-262 v5, 15.8.2.14 */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-math.inc.h" +#define BUILTIN_UNDERSCORED_ID math +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup object ECMA Object object built-in + * @{ + */ + +/** + * The Math object's 'max' 'min' routines. + * + * See also: + * ECMA-262 v5, 15.8.2.11 + * ECMA-262 v5, 15.8.2.12 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */ + const ecma_value_t *arg, /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + ecma_number_t result_num = ecma_number_make_infinity (is_max); + + while (args_number > 0) + { + ecma_number_t arg_num; + ecma_value_t value = ecma_op_to_number (*arg, &arg_num); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + arg++; + args_number--; + + if (ecma_number_is_nan (arg_num)) + { + result_num = arg_num; + } + + if (ecma_number_is_zero (arg_num) && ecma_number_is_zero (result_num)) + { + bool is_negative = ecma_number_is_negative (arg_num); + + if (is_max ? !is_negative : is_negative) + { + result_num = arg_num; + } + } + else + { + if (is_max ? (arg_num > result_num) : (arg_num < result_num)) + { + result_num = arg_num; + } + } + } + + return ecma_make_number_value (result_num); +} /* ecma_builtin_math_object_max_min */ + +/** + * The Math object's 'hypot' routine + * + * See also: + * ECMA-262 v6, 20.2.2.18 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_math_object_hypot (const ecma_value_t *arg, /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (args_number == 0) + { + return ecma_make_number_value (0.0); + } + + ecma_number_t result_num = 0; + bool inf = false; + + while (args_number > 0) + { + ecma_number_t arg_num; + ecma_value_t value = ecma_op_to_number (*arg, &arg_num); + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + arg++; + args_number--; + + if (ecma_number_is_nan (arg_num) && !inf) + { + result_num = arg_num; + continue; + } + + if (ecma_number_is_infinity (arg_num)) + { + inf = true; + result_num = ecma_number_make_infinity (false); + continue; + } + + result_num += arg_num * arg_num; + } + + return ecma_make_number_value (sqrt (result_num)); +} /* ecma_builtin_math_object_hypot */ + +/** + * The Math object's 'trunc' routine + * + * See also: + * ECMA-262 v6, 20.2.2.35 + * + * @return ecma number + */ +static ecma_number_t +ecma_builtin_math_object_trunc (ecma_number_t arg) +{ + if (ecma_number_is_nan (arg) || ecma_number_is_infinity (arg) || ecma_number_is_zero (arg)) + { + return arg; + } + + if ((arg > 0) && (arg < 1)) + { + return (ecma_number_t) 0.0; + } + + if ((arg < 0) && (arg > -1)) + { + return (ecma_number_t) -0.0; + } + + return (ecma_number_t) arg - fmod (arg, 1); +} /* ecma_builtin_math_object_trunc */ + +/** + * The Math object's 'sign' routine + * + * See also: + * ECMA-262 v6, 20.2.2.29 + * + * @return ecma number + */ +static ecma_number_t +ecma_builtin_math_object_sign (ecma_number_t arg) +{ + if (ecma_number_is_nan (arg) || ecma_number_is_zero (arg)) + { + return arg; + } + + if (ecma_number_is_negative (arg)) + { + return (ecma_number_t) -1.0; + } + + return (ecma_number_t) 1.0; +} /* ecma_builtin_math_object_sign */ + +/** + * The Math object's 'random' routine. + * + * See also: + * ECMA-262 v5, 15.8.2.14 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_math_object_random (void) +{ + const ecma_number_t rand_max = (ecma_number_t) RAND_MAX; + const ecma_number_t rand_max_min_1 = (ecma_number_t) (RAND_MAX - 1); + + return ecma_make_number_value (((ecma_number_t) rand ()) / rand_max * rand_max_min_1 / rand_max); +} /* ecma_builtin_math_object_random */ + +/** + * Dispatcher for the built-in's routines. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_math_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (this_arg); + + if (builtin_routine_id <= ECMA_MATH_OBJECT_POW) + { + ecma_number_t x = ecma_number_make_nan (); + ecma_number_t y = ecma_number_make_nan (); + + if (arguments_number >= 1) + { + ecma_value_t value = ecma_op_to_number (arguments_list[0], &x); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + } + + if (builtin_routine_id >= ECMA_MATH_OBJECT_ATAN2 && arguments_number >= 2) + { + if (ecma_is_value_number (arguments_list[1])) + { + y = ecma_get_number_from_value (arguments_list[1]); + } + else + { + ecma_value_t value = ecma_op_to_number (arguments_list[1], &y); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + } + } + + switch (builtin_routine_id) + { + case ECMA_MATH_OBJECT_ABS: + { + x = DOUBLE_TO_ECMA_NUMBER_T (fabs (x)); + break; + } + case ECMA_MATH_OBJECT_ACOS: + { + x = DOUBLE_TO_ECMA_NUMBER_T (acos (x)); + break; + } + case ECMA_MATH_OBJECT_ASIN: + { + x = DOUBLE_TO_ECMA_NUMBER_T (asin (x)); + break; + } + case ECMA_MATH_OBJECT_ATAN: + { + x = DOUBLE_TO_ECMA_NUMBER_T (atan (x)); + break; + } + case ECMA_MATH_OBJECT_CEIL: + { + x = DOUBLE_TO_ECMA_NUMBER_T (ceil (x)); + break; + } + case ECMA_MATH_OBJECT_COS: + { + x = DOUBLE_TO_ECMA_NUMBER_T (cos (x)); + break; + } + case ECMA_MATH_OBJECT_EXP: + { + x = DOUBLE_TO_ECMA_NUMBER_T (exp (x)); + break; + } + case ECMA_MATH_OBJECT_FLOOR: + { + x = DOUBLE_TO_ECMA_NUMBER_T (floor (x)); + break; + } + case ECMA_MATH_OBJECT_LOG: + { + x = DOUBLE_TO_ECMA_NUMBER_T (log (x)); + break; + } + case ECMA_MATH_OBJECT_TRUNC: + { + x = ecma_builtin_math_object_trunc (x); + break; + } + case ECMA_MATH_OBJECT_SIGN: + { + x = ecma_builtin_math_object_sign (x); + break; + } + case ECMA_MATH_OBJECT_ROUND: + { + if (ecma_number_is_nan (x) || ecma_number_is_zero (x) || ecma_number_is_infinity (x)) + { + break; + } + + ecma_number_t fraction = fmod (x, ECMA_NUMBER_ONE); + + if (ecma_number_is_zero (fraction)) + { + break; + } + + if (ecma_number_is_negative (x)) + { + if (x >= -ECMA_NUMBER_HALF) + { + x = -ECMA_NUMBER_ZERO; + break; + } + + if (fraction < -ECMA_NUMBER_HALF) + { + x -= ECMA_NUMBER_HALF; + } + } + else if (fraction >= ECMA_NUMBER_HALF) + { + x += ECMA_NUMBER_HALF; + } + + x = ecma_number_trunc (x); + break; + } + case ECMA_MATH_OBJECT_SIN: + { + x = DOUBLE_TO_ECMA_NUMBER_T (sin (x)); + break; + } + case ECMA_MATH_OBJECT_SQRT: + { + x = DOUBLE_TO_ECMA_NUMBER_T (sqrt (x)); + break; + } + case ECMA_MATH_OBJECT_TAN: + { + x = DOUBLE_TO_ECMA_NUMBER_T (tan (x)); + break; + } + case ECMA_MATH_OBJECT_ATAN2: + { + x = DOUBLE_TO_ECMA_NUMBER_T (atan2 (x, y)); + break; + } + case ECMA_MATH_OBJECT_POW: + { + x = ecma_number_pow (x, y); + break; + } + case ECMA_MATH_OBJECT_ACOSH: + { + x = DOUBLE_TO_ECMA_NUMBER_T (acosh (x)); + break; + } + case ECMA_MATH_OBJECT_ASINH: + { + x = DOUBLE_TO_ECMA_NUMBER_T (asinh (x)); + break; + } + case ECMA_MATH_OBJECT_ATANH: + { + x = DOUBLE_TO_ECMA_NUMBER_T (atanh (x)); + break; + } + case ECMA_MATH_OBJECT_CBRT: + { + x = DOUBLE_TO_ECMA_NUMBER_T (cbrt (x)); + break; + } + case ECMA_MATH_OBJECT_COSH: + { + x = DOUBLE_TO_ECMA_NUMBER_T (cosh (x)); + break; + } + case ECMA_MATH_OBJECT_EXPM1: + { + x = DOUBLE_TO_ECMA_NUMBER_T (expm1 (x)); + break; + } + case ECMA_MATH_OBJECT_LOG1P: + { + x = DOUBLE_TO_ECMA_NUMBER_T (log1p (x)); + break; + } + case ECMA_MATH_OBJECT_LOG10: + { + x = DOUBLE_TO_ECMA_NUMBER_T (log10 (x)); + break; + } + case ECMA_MATH_OBJECT_LOG2: + { + x = DOUBLE_TO_ECMA_NUMBER_T (log2 (x)); + break; + } + case ECMA_MATH_OBJECT_SINH: + { + x = DOUBLE_TO_ECMA_NUMBER_T (sinh (x)); + break; + } + case ECMA_MATH_OBJECT_TANH: + { + x = DOUBLE_TO_ECMA_NUMBER_T (tanh (x)); + break; + } + case ECMA_MATH_OBJECT_CLZ32: + { + uint32_t n = ecma_number_to_uint32 (x); +#if defined(__GNUC__) || defined(__clang__) + x = n ? __builtin_clz (n) : 32; +#elif defined(_WIN32) + unsigned long ret; + x = _BitScanReverse (&ret, n) ? 31 - ret : 32; +#else /* !(defined(__GNUC__) || defined(__clang__) || defined(_WIN32)) */ + x = 32; + for (int i = 31; i >= 0; i--) + { + if (n >> i) + { + x = 31 - i; + break; + } + } +#endif /* defined (__GNUC__) || defined (__clang__) */ + break; + } + case ECMA_MATH_OBJECT_FROUND: + { + break; + } + case ECMA_MATH_OBJECT_IMUL: + { + x = (int32_t) (ecma_number_to_uint32 (x) * ecma_number_to_uint32 (y)); + break; + } + } + return ecma_make_number_value (x); + } /* if (builtin_routine_id <= ECMA_MATH_OBJECT_POW) */ + + if (builtin_routine_id <= ECMA_MATH_OBJECT_MIN) + { + return ecma_builtin_math_object_max_min (builtin_routine_id == ECMA_MATH_OBJECT_MAX, + arguments_list, + arguments_number); + } + + if (builtin_routine_id == ECMA_MATH_OBJECT_HYPOT) + { + return ecma_builtin_math_object_hypot (arguments_list, arguments_number); + } + + JERRY_ASSERT (builtin_routine_id == ECMA_MATH_OBJECT_RANDOM); + + return ecma_builtin_math_object_random (); +} /* ecma_builtin_math_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_MATH */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h new file mode 100644 index 0000000..c30ad25 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h @@ -0,0 +1,94 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Math built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_MATH + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v5, 15.8.1.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_E_U, ECMA_BUILTIN_NUMBER_E, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LN10_U, ECMA_BUILTIN_NUMBER_LN10, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.3 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LN2_U, ECMA_BUILTIN_NUMBER_LN2, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.4 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LOG2E_U, ECMA_BUILTIN_NUMBER_LOG2E, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.5 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LOG10E_U, ECMA_BUILTIN_NUMBER_LOG10E, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.6 */ +NUMBER_VALUE (LIT_MAGIC_STRING_PI_U, ECMA_BUILTIN_NUMBER_PI, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.7 */ +NUMBER_VALUE (LIT_MAGIC_STRING_SQRT1_2_U, ECMA_BUILTIN_NUMBER_SQRT_1_2, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.8.1.8 */ +NUMBER_VALUE (LIT_MAGIC_STRING_SQRT2_U, ECMA_BUILTIN_NUMBER_SQRT2, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v6, 20.2.1.9 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_MATH_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_ABS, ECMA_MATH_OBJECT_ABS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ACOS, ECMA_MATH_OBJECT_ACOS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ASIN, ECMA_MATH_OBJECT_ASIN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ATAN, ECMA_MATH_OBJECT_ATAN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ATAN2, ECMA_MATH_OBJECT_ATAN2, 2, 2) +ROUTINE (LIT_MAGIC_STRING_CEIL, ECMA_MATH_OBJECT_CEIL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_COS, ECMA_MATH_OBJECT_COS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_EXP, ECMA_MATH_OBJECT_EXP, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FLOOR, ECMA_MATH_OBJECT_FLOOR, 1, 1) +ROUTINE (LIT_MAGIC_STRING_LOG, ECMA_MATH_OBJECT_LOG, 1, 1) +ROUTINE (LIT_MAGIC_STRING_MAX, ECMA_MATH_OBJECT_MAX, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_MIN, ECMA_MATH_OBJECT_MIN, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_POW, ECMA_MATH_OBJECT_POW, 2, 2) +ROUTINE (LIT_MAGIC_STRING_RANDOM, ECMA_MATH_OBJECT_RANDOM, 0, 0) +ROUTINE (LIT_MAGIC_STRING_ROUND, ECMA_MATH_OBJECT_ROUND, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SIN, ECMA_MATH_OBJECT_SIN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SQRT, ECMA_MATH_OBJECT_SQRT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TAN, ECMA_MATH_OBJECT_TAN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ACOSH, ECMA_MATH_OBJECT_ACOSH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ASINH, ECMA_MATH_OBJECT_ASINH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ATANH, ECMA_MATH_OBJECT_ATANH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_CBRT, ECMA_MATH_OBJECT_CBRT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_CLZ32, ECMA_MATH_OBJECT_CLZ32, 1, 1) +ROUTINE (LIT_MAGIC_STRING_COSH, ECMA_MATH_OBJECT_COSH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_EXPM1, ECMA_MATH_OBJECT_EXPM1, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FROUND, ECMA_MATH_OBJECT_FROUND, 1, 1) +ROUTINE (LIT_MAGIC_STRING_HYPOT, ECMA_MATH_OBJECT_HYPOT, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_IMUL, ECMA_MATH_OBJECT_IMUL, 2, 2) +ROUTINE (LIT_MAGIC_STRING_LOG1P, ECMA_MATH_OBJECT_LOG1P, 1, 1) +ROUTINE (LIT_MAGIC_STRING_LOG10, ECMA_MATH_OBJECT_LOG10, 1, 1) +ROUTINE (LIT_MAGIC_STRING_LOG2, ECMA_MATH_OBJECT_LOG2, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SIGN, ECMA_MATH_OBJECT_SIGN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SINH, ECMA_MATH_OBJECT_SINH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TANH, ECMA_MATH_OBJECT_TANH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TRUNC, ECMA_MATH_OBJECT_TRUNC, 1, 1) + +#endif /* JERRY_BUILTIN_MATH */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.cpp new file mode 100644 index 0000000..989c2dc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.cpp @@ -0,0 +1,673 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt-libc-includes.h" +#include "jrt.h" +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_NUMBER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_NUMBER_PROTOTYPE_ROUTINE_START = 0, + ECMA_NUMBER_PROTOTYPE_VALUE_OF, + ECMA_NUMBER_PROTOTYPE_TO_STRING, + ECMA_NUMBER_PROTOTYPE_TO_LOCALE_STRING, + ECMA_NUMBER_PROTOTYPE_TO_FIXED, + ECMA_NUMBER_PROTOTYPE_TO_EXPONENTIAL, + ECMA_NUMBER_PROTOTYPE_TO_PRECISION, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID number_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup numberprototype ECMA Number.prototype object built-in + * @{ + */ + +/** + * Helper for rounding numbers + * + * @return rounded number + */ +static inline lit_utf8_size_t +ecma_builtin_number_prototype_helper_round (lit_utf8_byte_t *digits_p, /**< [in,out] number as a string in decimal + * form */ + lit_utf8_size_t num_digits, /**< length of the string representation */ + int32_t round_num, /**< number of digits to keep */ + int32_t *exponent_p, /**< [in, out] decimal exponent */ + bool zero) /**< true if digits_p represents zero */ +{ + if (round_num == 0 && *exponent_p == 0) + { + if (digits_p[0] >= 5) + { + digits_p[0] = '1'; + } + else + { + digits_p[0] = '0'; + } + + return 1; + } + + if (round_num < 1) + { + return 0; + } + + if ((lit_utf8_size_t) round_num >= num_digits || zero) + { + return num_digits; + } + + if (digits_p[round_num] >= '5') + { + digits_p[round_num] = '0'; + + int i = 1; + + /* Handle carry number. */ + for (; i <= round_num; i++) + { + if (++digits_p[round_num - i] <= '9') + { + break; + } + digits_p[round_num - i] = '0'; + } + + /* Prepend highest digit */ + if (i > round_num) + { + memmove (digits_p + 1, digits_p, num_digits); + digits_p[0] = '1'; + *exponent_p += 1; + } + } + + return (lit_utf8_size_t) round_num; +} /* ecma_builtin_number_prototype_helper_round */ + +/** + * Size of Number toString digit buffers. + */ +#define NUMBER_TO_STRING_MAX_DIGIT_COUNT 64u + +/** + * The Number.prototype object's 'toString' and 'toLocaleString' routines + * + * See also: + * ECMA-262 v5, 15.7.4.2 + * ECMA-262 v5, 15.7.4.7 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_number_prototype_object_to_string (ecma_number_t this_arg_number, /**< this argument number */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + static const lit_utf8_byte_t digit_chars[36] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; + + uint32_t radix = 10; + if (arguments_list_len > 0 && !ecma_is_value_undefined (arguments_list_p[0])) + { + ecma_number_t arg_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arguments_list_p[0], &arg_num))) + { + return ECMA_VALUE_ERROR; + } + + radix = ecma_number_to_uint32 (arg_num); + + if (radix < 2 || radix > 36) + { + return ecma_raise_range_error (ECMA_ERR_RADIX_IS_OUT_OF_RANGE); + } + } + + if (ecma_number_is_nan (this_arg_number) || ecma_number_is_infinity (this_arg_number) + || ecma_number_is_zero (this_arg_number) || radix == 10) + { + ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number); + return ecma_make_string_value (ret_str_p); + } + + uint8_t integer_digits[NUMBER_TO_STRING_MAX_DIGIT_COUNT]; + uint8_t fraction_digits[NUMBER_TO_STRING_MAX_DIGIT_COUNT]; + uint32_t integer_zeros = 0; + uint32_t fraction_zeros = 0; + bool is_number_negative = false; + + if (ecma_number_is_negative (this_arg_number)) + { + this_arg_number = -this_arg_number; + is_number_negative = true; + } + + ecma_number_t integer_part = floor (this_arg_number); + ecma_number_t fraction_part = this_arg_number - integer_part; + + uint8_t *integer_cursor_p = integer_digits + NUMBER_TO_STRING_MAX_DIGIT_COUNT; + uint8_t *fraction_cursor_p = fraction_digits; + + if (fraction_part > 0.0) + { + uint8_t digit; + ecma_number_t precision = (ecma_number_get_next (this_arg_number) - this_arg_number) * 0.5; + precision = JERRY_MAX (precision, ECMA_NUMBER_MIN_VALUE); + + do + { + fraction_part *= radix; + precision *= radix; + + digit = (uint8_t) floor (fraction_part); + + if (digit == 0 && fraction_cursor_p == fraction_digits) + { + fraction_zeros++; + continue; + } + + JERRY_ASSERT (fraction_cursor_p < fraction_digits + NUMBER_TO_STRING_MAX_DIGIT_COUNT); + *fraction_cursor_p++ = digit; + fraction_part -= (ecma_number_t) digit; + } while (fraction_part >= precision); + + /* Round to even */ + if (fraction_part > 0.5 || (fraction_part == 0.5 && (digit & 1) != 0)) + { + /* Add carry and remove overflowing trailing digits */ + while (true) + { + (*(--fraction_cursor_p))++; + + if (*fraction_cursor_p < radix) + { + /* Re-adjust cursor to point after the last significant digit */ + fraction_cursor_p++; + break; + } + + if (fraction_cursor_p == fraction_digits) + { + /* Carry overflowed to integer part */ + integer_part += 1; + break; + } + } + } + + /* Convert fraction digits to characters. */ + for (uint8_t *digit_p = fraction_digits; digit_p < fraction_cursor_p; digit_p++) + { + *digit_p = digit_chars[*digit_p]; + } + } + + while (ecma_number_biased_exp (ecma_number_to_binary (integer_part / radix)) + > ECMA_NUMBER_EXPONENT_BIAS + ECMA_NUMBER_FRACTION_WIDTH) + { + integer_zeros++; + integer_part /= radix; + } + + uint64_t integer_u64 = (uint64_t) integer_part; + + do + { + uint64_t remainder = integer_u64 % radix; + *(--integer_cursor_p) = (uint8_t) digit_chars[remainder]; + + integer_u64 /= radix; + } while (integer_u64 > 0); + + const uint32_t integer_digit_count = + (uint32_t) (integer_digits + NUMBER_TO_STRING_MAX_DIGIT_COUNT - integer_cursor_p); + JERRY_ASSERT (integer_digit_count > 0); + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + if (is_number_negative) + { + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_MINUS); + } + + ecma_stringbuilder_append_raw (&builder, integer_cursor_p, integer_digit_count); + + while (integer_zeros--) + { + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_0); + } + + if (fraction_cursor_p != fraction_digits) + { + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_DOT); + + while (fraction_zeros--) + { + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_0); + } + + const uint32_t fraction_digit_count = (uint32_t) (fraction_cursor_p - fraction_digits); + JERRY_ASSERT (fraction_digit_count > 0); + + ecma_stringbuilder_append_raw (&builder, fraction_digits, fraction_digit_count); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_number_prototype_object_to_string */ + +/** + * The Number.prototype object's 'valueOf' routine + * + * See also: + * ECMA-262 v5, 15.7.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_number_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_number (this_arg)) + { + return this_arg; + } + else if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_NUMBER)) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (ecma_is_value_number (ext_object_p->u.cls.u3.value)); + + return ext_object_p->u.cls.u3.value; + } + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_NUMBER); +} /* ecma_builtin_number_prototype_object_value_of */ + +/** + * Type of number routine + */ +typedef enum +{ + NUMBER_ROUTINE_TO_FIXED, /**< Number.prototype.toFixed: ECMA-262 v11, 20.1.3.3 */ + NUMBER_ROUTINE_TO_EXPONENTIAL, /**< Number.prototype.toExponential: ECMA-262 v11, 20.1.3.2 */ + NUMBER_ROUTINE_TO_PRECISION, /**< Number.prototype.toPrecision: ECMA-262 v11, 20.1.3.5 */ + NUMBER_ROUTINE__COUNT, /**< count of the modes */ +} number_routine_mode_t; + +/** + * Helper method to convert a number based on the given routine. + */ +static ecma_value_t +ecma_builtin_number_prototype_object_to_number_convert (ecma_number_t this_num, /**< this argument number */ + ecma_value_t arg, /**< routine's argument */ + number_routine_mode_t mode) /**< number routine mode */ +{ + if (ecma_is_value_undefined (arg) && mode == NUMBER_ROUTINE_TO_PRECISION) + { + return ecma_builtin_number_prototype_object_to_string (this_num, NULL, 0); + } + + ecma_number_t arg_num; + ecma_value_t to_integer = ecma_op_to_integer (arg, &arg_num); + + if (ECMA_IS_VALUE_ERROR (to_integer)) + { + return to_integer; + } + + /* Argument boundary check for toFixed method */ + if (mode == NUMBER_ROUTINE_TO_FIXED && (arg_num <= -1 || arg_num >= 101)) + { + return ecma_raise_range_error (ECMA_ERR_FRACTION_DIGITS_OUT_OF_RANGE); + } + + /* Handle NaN separately */ + if (ecma_number_is_nan (this_num)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_NAN); + } + + /* Get the parameters of the number */ + lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; + lit_utf8_size_t num_of_digits; + int32_t exponent; + int32_t arg_int = ecma_number_to_int32 (arg_num); + bool is_zero = ecma_number_is_zero (this_num); + bool is_negative = ecma_number_is_negative (this_num); + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + if (is_negative) + { + if (!is_zero) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_MINUS); + } + + this_num *= -1; + } + + /* Handle zero separately */ + if (is_zero) + { + if (mode == NUMBER_ROUTINE_TO_PRECISION) + { + arg_int--; + } + + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + + if (arg_int > 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_DOT); + } + + for (int32_t i = 0; i < arg_int; i++) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + } + + if (mode == NUMBER_ROUTINE_TO_EXPONENTIAL) + { + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "e+0", 3); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); + } + + /* Handle infinity separately */ + if (ecma_number_is_infinity (this_num)) + { + ecma_stringbuilder_append_magic (&builder, LIT_MAGIC_STRING_INFINITY_UL); + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); + } + + /* Argument boundary check for toExponential and toPrecision methods */ + if (mode == NUMBER_ROUTINE_TO_EXPONENTIAL && (arg_num <= -1 || arg_num >= 101)) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_range_error (ECMA_ERR_FRACTION_DIGITS_OUT_OF_RANGE); + } + else if (mode == NUMBER_ROUTINE_TO_PRECISION && (arg_num < 1 || arg_num > 100)) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_range_error (ECMA_ERR_PRECISION_DIGITS_MUST_BE_BETWEEN_IN_RANGE); + } + + num_of_digits = ecma_number_to_decimal (this_num, digits, &exponent); + + /* Handle undefined argument */ + if (ecma_is_value_undefined (arg) && mode == NUMBER_ROUTINE_TO_EXPONENTIAL) + { + arg_int = (int32_t) num_of_digits - 1; + } + + if (mode == NUMBER_ROUTINE_TO_FIXED && exponent > 21) + { + ecma_stringbuilder_destroy (&builder); + + if (is_negative) + { + this_num *= -1; + } + + return ecma_builtin_number_prototype_object_to_string (this_num, NULL, 0); + } + + int32_t digits_to_keep = arg_int; + + if (mode == NUMBER_ROUTINE_TO_FIXED) + { + digits_to_keep += exponent; + } + else if (mode == NUMBER_ROUTINE_TO_EXPONENTIAL) + { + digits_to_keep += 1; + } + + num_of_digits = ecma_builtin_number_prototype_helper_round (digits, num_of_digits, digits_to_keep, &exponent, false); + + /* toExponent routine and toPrecision cases where the exponent > precision or exponent < -5 */ + if (mode == NUMBER_ROUTINE_TO_EXPONENTIAL + || (mode == NUMBER_ROUTINE_TO_PRECISION && (exponent < -5 || exponent > arg_int))) + { + /* Append first digit */ + ecma_stringbuilder_append_byte (&builder, *digits); + + if (mode == NUMBER_ROUTINE_TO_PRECISION) + { + arg_int--; + } + + if (arg_int > 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_DOT); + } + + /* Append significant fraction digits */ + ecma_stringbuilder_append_raw (&builder, digits + 1, num_of_digits - 1); + + /* Append leading zeros */ + for (int32_t i = (int32_t) (num_of_digits); i < arg_int + 1; i++) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + } + + ecma_stringbuilder_append_char (&builder, LIT_CHAR_LOWERCASE_E); + + if (exponent <= 0) + { + exponent = (-exponent) + 1; + ecma_stringbuilder_append_char (&builder, LIT_CHAR_MINUS); + } + else + { + exponent -= 1; + ecma_stringbuilder_append_char (&builder, LIT_CHAR_PLUS); + } + + /* Append exponent part */ + lit_utf8_size_t exp_size = ecma_uint32_to_utf8_string ((uint32_t) exponent, digits, 3); + ecma_stringbuilder_append_raw (&builder, digits, exp_size); + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); + } + + /* toFixed routine and toPrecision cases where the exponent <= precision and exponent >= -5 */ + lit_utf8_size_t result_digits; + + if (mode == NUMBER_ROUTINE_TO_FIXED) + { + result_digits = ((exponent > 0) ? (lit_utf8_size_t) (exponent + arg_int) : (lit_utf8_size_t) (arg_int + 1)); + } + else + { + result_digits = ((exponent <= 0) ? (lit_utf8_size_t) (1 - exponent + arg_int) : (lit_utf8_size_t) arg_int); + } + + /* Number of digits we copied from digits array */ + lit_utf8_size_t copied_digits = 0; + + if (exponent == 0 && digits_to_keep == 0) + { + ecma_stringbuilder_append_char (&builder, *digits); + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); + } + + if (exponent <= 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + result_digits--; + + if (result_digits > 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_DOT); + + /* Append leading zeros to the fraction part */ + for (int32_t i = 0; i < -exponent && result_digits > 0; i++) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + result_digits--; + } + } + } + else + { + /* Append significant digits of integer part */ + copied_digits = JERRY_MIN (JERRY_MIN (num_of_digits, result_digits), (lit_utf8_size_t) exponent); + ecma_stringbuilder_append_raw (&builder, digits, copied_digits); + + result_digits -= copied_digits; + num_of_digits -= copied_digits; + exponent -= (int32_t) copied_digits; + + /* Append zeros before decimal point */ + while (exponent > 0 && result_digits > 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + result_digits--; + exponent--; + } + + if (result_digits > 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_DOT); + } + } + + if (result_digits > 0) + { + /* Append significant digits to the fraction part */ + lit_utf8_size_t to_copy = JERRY_MIN (num_of_digits, result_digits); + ecma_stringbuilder_append_raw (&builder, digits + copied_digits, to_copy); + result_digits -= to_copy; + + /* Append leading zeros */ + while (result_digits > 0) + { + ecma_stringbuilder_append_char (&builder, LIT_CHAR_0); + result_digits--; + } + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_number_prototype_object_to_number_convert */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_number_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + ecma_value_t this_value = ecma_builtin_number_prototype_object_value_of (this_arg); + + if (ECMA_IS_VALUE_ERROR (this_value)) + { + return this_value; + } + + if (builtin_routine_id == ECMA_NUMBER_PROTOTYPE_VALUE_OF) + { + return ecma_copy_value (this_value); + } + + ecma_number_t this_arg_number = ecma_get_number_from_value (this_value); + + switch (builtin_routine_id) + { + case ECMA_NUMBER_PROTOTYPE_TO_STRING: + { + return ecma_builtin_number_prototype_object_to_string (this_arg_number, arguments_list_p, arguments_number); + } + case ECMA_NUMBER_PROTOTYPE_TO_LOCALE_STRING: + { + return ecma_builtin_number_prototype_object_to_string (this_arg_number, NULL, 0); + } + case ECMA_NUMBER_PROTOTYPE_TO_FIXED: + case ECMA_NUMBER_PROTOTYPE_TO_EXPONENTIAL: + case ECMA_NUMBER_PROTOTYPE_TO_PRECISION: + { + const int option = NUMBER_ROUTINE_TO_FIXED + (builtin_routine_id - ECMA_NUMBER_PROTOTYPE_TO_FIXED); + return ecma_builtin_number_prototype_object_to_number_convert (this_arg_number, + arguments_list_p[0], + (number_routine_mode_t) option); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_number_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_NUMBER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h new file mode 100644 index 0000000..e5ac7dd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Number.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_NUMBER + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.7.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_NUMBER, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_NUMBER_PROTOTYPE_TO_STRING, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_NUMBER_PROTOTYPE_VALUE_OF, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_NUMBER_PROTOTYPE_TO_LOCALE_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_FIXED_UL, ECMA_NUMBER_PROTOTYPE_TO_FIXED, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TO_EXPONENTIAL_UL, ECMA_NUMBER_PROTOTYPE_TO_EXPONENTIAL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TO_PRECISION_UL, ECMA_NUMBER_PROTOTYPE_TO_PRECISION, 1, 1) + +#endif /* JERRY_BUILTIN_NUMBER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.cpp new file mode 100644 index 0000000..89fa1ab --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.cpp @@ -0,0 +1,246 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-alloc.h" +#include "ecma-bigint.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-number-object.h" +#include "ecma-objects.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_NUMBER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_NUMBER_OBJECT_ROUTINE_START = 0, + ECMA_NUMBER_OBJECT_ROUTINE_IS_FINITE, + ECMA_NUMBER_OBJECT_ROUTINE_IS_NAN, + ECMA_NUMBER_OBJECT_ROUTINE_IS_INTEGER, + ECMA_NUMBER_OBJECT_ROUTINE_IS_SAFE_INTEGER +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number.inc.h" +#define BUILTIN_UNDERSCORED_ID number +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup number ECMA Number object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Number object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_number_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + if (arguments_list_len == 0) + { + ret_value = ecma_make_integer_value (0); + } + else + { + ecma_number_t num; + ret_value = ecma_op_to_numeric (arguments_list_p[0], &num, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + return ret_value; + } + +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (ret_value)) + { + ecma_value_t bigint = ret_value; + ret_value = ecma_bigint_to_number (bigint); + ecma_free_value (bigint); + } + else +#endif /* JERRY_BUILTIN_BIGINT */ + { + ret_value = ecma_make_number_value (num); + } + } + + return ret_value; +} /* ecma_builtin_number_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Number object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len == 0) + { + return ecma_op_create_number_object (ecma_make_integer_value (0)); + } + +#if JERRY_BUILTIN_BIGINT + ecma_number_t num; + ecma_value_t value = ecma_op_to_numeric (arguments_list_p[0], &num, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + if (ecma_is_value_bigint (value)) + { + ecma_value_t bigint = value; + value = ecma_bigint_to_number (bigint); + ecma_free_value (bigint); + } + else + { + value = ecma_make_number_value (num); + } + + ecma_value_t result = ecma_op_create_number_object (value); + ecma_free_value (value); + return result; +#else /* !JERRY_BUILTIN_BIGINT */ + return ecma_op_create_number_object (arguments_list_p[0]); +#endif /* JERRY_BUILTIN_BIGINT */ +} /* ecma_builtin_number_dispatch_construct */ + +/** + * The Number object 'isInteger' and 'isSafeInteger' routine + * + * See also: + * ECMA-262 v6, 20.1.2.3 + * ECMA-262 v6, 20.1.2.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_number_object_is_integer_helper (ecma_value_t arg, /**< routine's argument */ + ecma_number_t num, /**< this number */ + bool is_safe) /**< is the number safe */ +{ + if (ecma_number_is_nan (num) || ecma_number_is_infinity (num)) + { + return ECMA_VALUE_FALSE; + } + + ecma_number_t int_num; + + if (is_safe) + { + int_num = ecma_number_trunc (num); + + if (fabs (int_num) > ECMA_NUMBER_MAX_SAFE_INTEGER) + { + return ECMA_VALUE_FALSE; + } + } + else + { + ecma_op_to_integer (arg, &int_num); + } + + return (int_num == num) ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE; +} /* ecma_builtin_number_object_is_integer_helper */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_number_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (this_arg, arguments_number); + + if (!ecma_is_value_number (arguments_list_p[0])) + { + return ECMA_VALUE_FALSE; + } + + ecma_number_t num = ecma_get_number_from_value (arguments_list_p[0]); + + switch (builtin_routine_id) + { + case ECMA_NUMBER_OBJECT_ROUTINE_IS_FINITE: + { + return ecma_make_boolean_value (!(ecma_number_is_nan (num) || ecma_number_is_infinity (num))); + } + case ECMA_NUMBER_OBJECT_ROUTINE_IS_NAN: + { + return ecma_make_boolean_value (ecma_number_is_nan (num)); + } + case ECMA_NUMBER_OBJECT_ROUTINE_IS_INTEGER: + case ECMA_NUMBER_OBJECT_ROUTINE_IS_SAFE_INTEGER: + { + bool is_safe = (builtin_routine_id == ECMA_NUMBER_OBJECT_ROUTINE_IS_SAFE_INTEGER); + return ecma_builtin_number_object_is_integer_helper (arguments_list_p[0], num, is_safe); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_number_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_NUMBER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h new file mode 100644 index 0000000..5a30cbf --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h @@ -0,0 +1,72 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Number built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_NUMBER + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* ECMA-262 v5, 15.7.3.4 */ +NUMBER_VALUE (LIT_MAGIC_STRING_NAN, ECMA_BUILTIN_NUMBER_NAN, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.7.3.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_MAX_VALUE_U, ECMA_BUILTIN_NUMBER_MAX, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.7.3.3 */ +NUMBER_VALUE (LIT_MAGIC_STRING_MIN_VALUE_U, ECMA_BUILTIN_NUMBER_MIN, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.7.3.5 */ +NUMBER_VALUE (LIT_MAGIC_STRING_POSITIVE_INFINITY_U, ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v5, 15.7.3.6 */ +NUMBER_VALUE (LIT_MAGIC_STRING_NEGATIVE_INFINITY_U, ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v6, 20.1.2.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_EPSILON_U, ECMA_BUILTIN_NUMBER_EPSILON, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v6, 20.1.2.6 */ +NUMBER_VALUE (LIT_MAGIC_STRING_MAX_SAFE_INTEGER_U, ECMA_BUILTIN_NUMBER_MAX_SAFE_INTEGER, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v6, 20.1.2.8 */ +NUMBER_VALUE (LIT_MAGIC_STRING_MIN_SAFE_INTEGER_U, ECMA_BUILTIN_NUMBER_MIN_SAFE_INTEGER, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_NUMBER_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.7.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_NUMBER_PROTOTYPE, ECMA_PROPERTY_FIXED) + +#endif /* JERRY_BUILTIN_NUMBER */ + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_IS_FINITE, ECMA_NUMBER_OBJECT_ROUTINE_IS_FINITE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_NAN, ECMA_NUMBER_OBJECT_ROUTINE_IS_NAN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_INTEGER, ECMA_NUMBER_OBJECT_ROUTINE_IS_INTEGER, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_SAFE_INTEGER, ECMA_NUMBER_OBJECT_ROUTINE_IS_SAFE_INTEGER, 1, 1) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_FLOAT, LIT_MAGIC_STRING_PARSE_FLOAT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_PARSE_INT, LIT_MAGIC_STRING_PARSE_INT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.cpp new file mode 100644 index 0000000..28abfbb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.cpp @@ -0,0 +1,513 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtin-object.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-proxy-object.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + /* Note: these 6 routines must be in this order */ + ECMA_OBJECT_PROTOTYPE_ROUTINE_START = 0, + ECMA_OBJECT_PROTOTYPE_TO_STRING, + ECMA_OBJECT_PROTOTYPE_VALUE_OF, + ECMA_OBJECT_PROTOTYPE_TO_LOCALE_STRING, + ECMA_OBJECT_PROTOTYPE_GET_PROTO, + ECMA_OBJECT_PROTOTYPE_IS_PROTOTYPE_OF, + ECMA_OBJECT_PROTOTYPE_HAS_OWN_PROPERTY, + ECMA_OBJECT_PROTOTYPE_PROPERTY_IS_ENUMERABLE, + ECMA_OBJECT_PROTOTYPE_SET_PROTO, +#if JERRY_BUILTIN_ANNEXB + ECMA_OBJECT_PROTOTYPE_DEFINE_GETTER, + ECMA_OBJECT_PROTOTYPE_DEFINE_SETTER, + ECMA_OBJECT_PROTOTYPE_LOOKUP_GETTER, + ECMA_OBJECT_PROTOTYPE_LOOKUP_SETTER, +#endif /* JERRY_BUILTIN_ANNEXB */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID object_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup objectprototype ECMA Object.prototype object built-in + * @{ + */ + +/** + * The Object.prototype object's 'toString' routine + * + * See also: + * ECMA-262 v5, 15.2.4.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */ +{ + return ecma_builtin_helper_object_to_string (this_arg); +} /* ecma_builtin_object_prototype_object_to_string */ + +/** + * The Object.prototype object's 'valueOf' routine + * + * See also: + * ECMA-262 v5, 15.2.4.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */ +{ + return ecma_op_to_object (this_arg); +} /* ecma_builtin_object_prototype_object_value_of */ + +/** + * The Object.prototype object's 'toLocaleString' routine + * + * See also: + * ECMA-262 v5, 15.2.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this_arg) /**< this argument */ +{ + return ecma_op_invoke_by_magic_id (this_arg, LIT_MAGIC_STRING_TO_STRING_UL, &this_arg, 1); +} /* ecma_builtin_object_prototype_object_to_locale_string */ + +/** + * The Object.prototype object's 'hasOwnProperty' routine + * + * See also: + * ECMA-262 v5, 15.2.4.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_prototype_object_has_own_property (ecma_object_t *obj_p, /**< this argument */ + ecma_string_t *prop_name_p) /**< first argument */ +{ + return ecma_op_object_has_own_property (obj_p, prop_name_p); +} /* ecma_builtin_object_prototype_object_has_own_property */ + +/** + * The Object.prototype object's 'isPrototypeOf' routine + * + * See also: + * ECMA-262 v5, 15.2.4.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_prototype_object_is_prototype_of (ecma_object_t *obj_p, /**< this argument */ + ecma_value_t arg) /**< routine's first argument */ +{ + /* 3. Compare prototype to object */ + ecma_value_t v_obj_value = ecma_op_to_object (arg); + + if (ECMA_IS_VALUE_ERROR (v_obj_value)) + { + return v_obj_value; + } + + ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value); + + ecma_value_t ret_value = ecma_op_object_is_prototype_of (obj_p, v_obj_p); + + ecma_deref_object (v_obj_p); + + return ret_value; +} /* ecma_builtin_object_prototype_object_is_prototype_of */ + +/** + * The Object.prototype object's 'propertyIsEnumerable' routine + * + * See also: + * ECMA-262 v5, 15.2.4.7 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_prototype_object_property_is_enumerable (ecma_object_t *obj_p, /**< this argument */ + ecma_string_t *prop_name_p) /**< first argument */ +{ + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc); + + if (!ecma_is_value_true (status)) + { + return status; + } + + bool is_enumerable = (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE); + + ecma_free_property_descriptor (&prop_desc); + + return ecma_make_boolean_value (is_enumerable); +} /* ecma_builtin_object_prototype_object_property_is_enumerable */ + +#if JERRY_BUILTIN_ANNEXB +/** + * The Object.prototype object's '__defineGetter__' and '__defineSetter__' routine + * + * See also: + * ECMA-262 v11, B.2.2.2 + * ECMA-262 v11, B.2.2.3 + * + * @return ECMA_VALUE_ERROR - if the operation fails, + * ECMA_VALUE_UNDEFINED - otherwise + */ +static ecma_value_t +ecma_builtin_object_prototype_define_getter_setter (ecma_value_t this_arg, /**< this argument */ + ecma_value_t prop, /**< property */ + ecma_value_t accessor, /**< getter/setter function */ + bool define_getter) /**< true - defineGetter method + false - defineSetter method */ +{ + /* 1. */ + ecma_value_t to_obj = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (to_obj)) + { + return to_obj; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (to_obj); + + /* 2. */ + if (!ecma_op_is_callable (accessor)) + { + ecma_deref_object (obj_p); + return ecma_raise_type_error (ECMA_ERR_GETTER_IS_NOT_CALLABLE); + } + + ecma_object_t *accessor_obj_p = ecma_get_object_from_value (accessor); + + /* 3. */ + ecma_property_descriptor_t desc = ecma_make_empty_property_descriptor (); + desc.flags |= (JERRY_PROP_IS_ENUMERABLE | JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_ENUMERABLE_DEFINED + | JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_SHOULD_THROW); + + if (define_getter) + { + desc.get_p = accessor_obj_p; + desc.flags |= JERRY_PROP_IS_GET_DEFINED; + } + else + { + desc.set_p = accessor_obj_p; + desc.flags |= JERRY_PROP_IS_SET_DEFINED; + } + + /* 4. */ + ecma_string_t *prop_name_p = ecma_op_to_property_key (prop); + + if (JERRY_UNLIKELY (prop_name_p == NULL)) + { + ecma_deref_object (obj_p); + return ECMA_VALUE_ERROR; + } + + /* 5. */ + ecma_value_t define_prop = ecma_op_object_define_own_property (obj_p, prop_name_p, &desc); + + ecma_deref_object (obj_p); + ecma_deref_ecma_string (prop_name_p); + + if (ECMA_IS_VALUE_ERROR (define_prop)) + { + return define_prop; + } + + /* 6. */ + return ECMA_VALUE_UNDEFINED; +} /* ecma_builtin_object_prototype_define_getter_setter */ + +/** + * The Object.prototype object's '__lookupGetter__' and '__lookupSetter__' routine + * + * See also: + * ECMA-262 v11, B.2.2.4 + * ECMA-262 v11, B.2.2.5 + * + * @return ECMA_VALUE_ERROR - if the operation fails, + * ECMA_VALUE_UNDEFINED - if the property was not found + * Accessor property - otherwise + */ +static ecma_value_t +ecma_builtin_object_prototype_lookup_getter_setter (ecma_value_t this_arg, /**< this argument */ + ecma_value_t prop, /**< property */ + bool lookup_getter) /**< true - lookupGetter method + false - lookupSetter method */ +{ + /* 1. */ + ecma_value_t to_obj = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (to_obj)) + { + return to_obj; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (to_obj); + + /* 2. */ + ecma_string_t *prop_name_p = ecma_op_to_property_key (prop); + + if (JERRY_UNLIKELY (prop_name_p == NULL)) + { + ecma_deref_object (obj_p); + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_value = ECMA_VALUE_UNDEFINED; + + ecma_ref_object (obj_p); + + /* 3. */ + while (true) + { + /* 3.a */ + ecma_property_descriptor_t desc; + ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &desc); + + if (ECMA_IS_VALUE_ERROR (get_desc)) + { + ret_value = get_desc; + ecma_deref_object (obj_p); + break; + } + + /* 3.b */ + if (ecma_is_value_true (get_desc)) + { + if ((desc.flags & JERRY_PROP_IS_SET_DEFINED) || (desc.flags & JERRY_PROP_IS_GET_DEFINED)) + { + if (lookup_getter && desc.get_p != NULL) + { + ecma_ref_object (desc.get_p); + ret_value = ecma_make_object_value (desc.get_p); + } + else if (!lookup_getter && desc.set_p != NULL) + { + ecma_ref_object (desc.set_p); + ret_value = ecma_make_object_value (desc.set_p); + } + } + + ecma_free_property_descriptor (&desc); + ecma_deref_object (obj_p); + break; + } + + /* 3.c */ + ecma_object_t *proto_p = ecma_op_object_get_prototype_of (obj_p); + ecma_deref_object (obj_p); + + if (proto_p == NULL) + { + break; + } + else if (JERRY_UNLIKELY (proto_p == ECMA_OBJECT_POINTER_ERROR)) + { + ret_value = ECMA_VALUE_ERROR; + break; + } + + /* Advance up on prototype chain. */ + obj_p = proto_p; + } + + ecma_free_value (to_obj); + ecma_deref_ecma_string (prop_name_p); + + return ret_value; +} /* ecma_builtin_object_prototype_lookup_getter_setter */ +#endif /* JERRY_BUILTIN_ANNEXB */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + /* no specialization */ + if (builtin_routine_id <= ECMA_OBJECT_PROTOTYPE_VALUE_OF) + { + if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_TO_STRING) + { + return ecma_builtin_object_prototype_object_to_string (this_arg); + } + + JERRY_ASSERT (builtin_routine_id <= ECMA_OBJECT_PROTOTYPE_VALUE_OF); + + return ecma_builtin_object_prototype_object_value_of (this_arg); + } + + if (builtin_routine_id <= ECMA_OBJECT_PROTOTYPE_IS_PROTOTYPE_OF) + { + if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_IS_PROTOTYPE_OF) + { + /* 15.2.4.6.1. */ + if (!ecma_is_value_object (arguments_list_p[0])) + { + return ECMA_VALUE_FALSE; + } + } + + if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_TO_LOCALE_STRING) + { + return ecma_builtin_object_prototype_object_to_locale_string (this_arg); + } + + ecma_value_t to_object = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (to_object)) + { + return to_object; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (to_object); + + ecma_value_t ret_value; + + if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_GET_PROTO) + { + ret_value = ecma_builtin_object_object_get_prototype_of (obj_p); + } + else + { + ret_value = ecma_builtin_object_prototype_object_is_prototype_of (obj_p, arguments_list_p[0]); + } + + ecma_deref_object (obj_p); + + return ret_value; + } + + JERRY_ASSERT (builtin_routine_id >= ECMA_OBJECT_PROTOTYPE_HAS_OWN_PROPERTY); + + if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_SET_PROTO) + { + return ecma_builtin_object_object_set_proto (this_arg, arguments_list_p[0]); + } +#if JERRY_BUILTIN_ANNEXB + else if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_LOOKUP_GETTER) + { + return ecma_builtin_object_prototype_lookup_getter_setter (this_arg, arguments_list_p[0], true); + } + else if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_LOOKUP_SETTER) + { + return ecma_builtin_object_prototype_lookup_getter_setter (this_arg, arguments_list_p[0], false); + } + else if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_DEFINE_GETTER) + { + return ecma_builtin_object_prototype_define_getter_setter (this_arg, + arguments_list_p[0], + arguments_list_p[1], + true); + } + else if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_DEFINE_SETTER) + { + return ecma_builtin_object_prototype_define_getter_setter (this_arg, + arguments_list_p[0], + arguments_list_p[1], + false); + } +#endif /* JERRY_BUILTIN_ANNEXB */ + + ecma_string_t *prop_name_p = ecma_op_to_property_key (arguments_list_p[0]); + + if (prop_name_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t to_object = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (to_object)) + { + ecma_deref_ecma_string (prop_name_p); + return to_object; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (to_object); + + ecma_value_t ret_value; + + if (builtin_routine_id == ECMA_OBJECT_PROTOTYPE_HAS_OWN_PROPERTY) + { + ret_value = ecma_builtin_object_prototype_object_has_own_property (obj_p, prop_name_p); + } + else + { + ret_value = ecma_builtin_object_prototype_object_property_is_enumerable (obj_p, prop_name_p); + } + + ecma_deref_ecma_string (prop_name_p); + ecma_deref_object (obj_p); + + return ret_value; +} /* ecma_builtin_object_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h new file mode 100644 index 0000000..b218eda --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h @@ -0,0 +1,49 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Object.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.2.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_OBJECT, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +ACCESSOR_READ_WRITE (LIT_MAGIC_STRING__PROTO__, + ECMA_OBJECT_PROTOTYPE_GET_PROTO, + ECMA_OBJECT_PROTOTYPE_SET_PROTO, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_OBJECT_PROTOTYPE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_OBJECT_PROTOTYPE_VALUE_OF, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_OBJECT_PROTOTYPE_TO_LOCALE_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_HAS_OWN_PROPERTY_UL, ECMA_OBJECT_PROTOTYPE_HAS_OWN_PROPERTY, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_PROTOTYPE_OF_UL, ECMA_OBJECT_PROTOTYPE_IS_PROTOTYPE_OF, 1, 1) +ROUTINE (LIT_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, ECMA_OBJECT_PROTOTYPE_PROPERTY_IS_ENUMERABLE, 1, 1) + +#if JERRY_BUILTIN_ANNEXB +ROUTINE (LIT_MAGIC_STRING_DEFINE_GETTER, ECMA_OBJECT_PROTOTYPE_DEFINE_GETTER, 2, 2) +ROUTINE (LIT_MAGIC_STRING_DEFINE_SETTER, ECMA_OBJECT_PROTOTYPE_DEFINE_SETTER, 2, 2) +ROUTINE (LIT_MAGIC_STRING_LOOKUP_GETTER, ECMA_OBJECT_PROTOTYPE_LOOKUP_GETTER, 1, 1) +ROUTINE (LIT_MAGIC_STRING_LOOKUP_SETTER, ECMA_OBJECT_PROTOTYPE_LOOKUP_SETTER, 1, 1) +#endif /* JERRY_BUILTIN_ANNEXB*/ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.cpp new file mode 100644 index 0000000..dd3e31b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.cpp @@ -0,0 +1,1555 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-object.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-proxy-object.h" + +#include "jcontext.h" +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_OBJECT_ROUTINE_START = 0, + + ECMA_OBJECT_ROUTINE_CREATE, + ECMA_OBJECT_ROUTINE_IS, + ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF, + + /* These should be in this order. */ + ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY, + ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES, + + /* These should be in this order. */ + ECMA_OBJECT_ROUTINE_ASSIGN, + ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR, + ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTORS, + ECMA_OBJECT_ROUTINE_HAS_OWN, + ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF, + ECMA_OBJECT_ROUTINE_FROM_ENTRIES, + ECMA_OBJECT_ROUTINE_KEYS, + ECMA_OBJECT_ROUTINE_VALUES, + ECMA_OBJECT_ROUTINE_ENTRIES, + + /* These should be in this order. */ + ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES, + ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS, + + /* These should be in this order. */ + ECMA_OBJECT_ROUTINE_FREEZE, + ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS, + ECMA_OBJECT_ROUTINE_SEAL, + + /* These should be in this order. */ + ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE, + ECMA_OBJECT_ROUTINE_IS_FROZEN, + ECMA_OBJECT_ROUTINE_IS_SEALED, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object.inc.h" +#define BUILTIN_UNDERSCORED_ID object +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup object ECMA Object object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Object object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_object_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + if (arguments_list_len == 0 || ecma_is_value_undefined (arguments_list_p[0]) + || ecma_is_value_null (arguments_list_p[0])) + { + return ecma_make_object_value (ecma_op_create_object_object_noarg ()); + } + + return ecma_op_to_object (arguments_list_p[0]); +} /* ecma_builtin_object_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Object object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + if (JERRY_CONTEXT (current_new_target_p) != ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT)) + { + ecma_object_t *prototype_obj_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + if (JERRY_UNLIKELY (prototype_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *object_p = ecma_create_object (prototype_obj_p, 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_deref_object (prototype_obj_p); + + return ecma_make_object_value (object_p); + } + + return ecma_builtin_object_dispatch_call (arguments_list_p, arguments_list_len); +} /* ecma_builtin_object_dispatch_construct */ + +/** + * The Object object's 'getPrototypeOf' routine + * + * See also: + * ECMA-262 v5, 15.2.3.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p) /**< routine's argument */ +{ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + return ecma_proxy_object_get_prototype_of (obj_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (obj_p); + + if (proto_cp != JMEM_CP_NULL) + { + ecma_object_t *prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp); + ecma_ref_object (prototype_p); + return ecma_make_object_value (prototype_p); + } + + return ECMA_VALUE_NULL; +} /* ecma_builtin_object_object_get_prototype_of */ + +/** + * The Object object's 'setPrototypeOf' routine + * + * See also: + * ES2015 19.1.2.18 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + /* 1., 2. */ + if (!ecma_op_require_object_coercible (arg1)) + { + return ECMA_VALUE_ERROR; + } + + /* 3. */ + if (!ecma_is_value_object (arg2) && !ecma_is_value_null (arg2)) + { + return ecma_raise_type_error (ECMA_ERR_PROTOTYPE_IS_NEITHER_OBJECT_NOR_NULL); + } + + /* 4. */ + if (!ecma_is_value_object (arg1)) + { + return ecma_copy_value (arg1); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (arg1); + ecma_value_t status; + + /* 5. */ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + status = ecma_proxy_object_set_prototype_of (obj_p, arg2); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + } + else + { +#endif /* JERRY_BUILTIN_PROXY */ + status = ecma_op_ordinary_object_set_prototype_of (obj_p, arg2); +#if JERRY_BUILTIN_PROXY + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_false (status)) + { + return ecma_raise_type_error (ECMA_ERR_SET_PROTOTYPE); + } + + JERRY_ASSERT (ecma_is_value_true (status)); + ecma_ref_object (obj_p); + + return arg1; +} /* ecma_builtin_object_object_set_prototype_of */ + +/** + * The Object object's set __proto__ routine + * + * See also: + * ECMA-262 v6, B.2.2.1.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_set_proto (ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + /* 1., 2. */ + if (!ecma_op_require_object_coercible (arg1)) + { + return ECMA_VALUE_ERROR; + } + + /* 3. */ + if (!ecma_is_value_object (arg2) && !ecma_is_value_null (arg2)) + { + return ECMA_VALUE_UNDEFINED; + } + + /* 4. */ + if (!ecma_is_value_object (arg1)) + { + return ECMA_VALUE_UNDEFINED; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (arg1); + ecma_value_t status; + + /* 5. */ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + status = ecma_proxy_object_set_prototype_of (obj_p, arg2); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + } + else + { +#endif /* JERRY_BUILTIN_PROXY */ + status = ecma_op_ordinary_object_set_prototype_of (obj_p, arg2); +#if JERRY_BUILTIN_PROXY + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_false (status)) + { + return ecma_raise_type_error (ECMA_ERR_SET_PROTOTYPE); + } + + JERRY_ASSERT (ecma_is_value_true (status)); + + return ECMA_VALUE_UNDEFINED; +} /* ecma_builtin_object_object_set_proto */ + +/** + * SetIntegrityLevel operation + * + * See also: + * ECMA-262 v6, 7.3.14 + * + * @return ECMA_VALUE_ERROR - if the operation raised an error + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the integrity level has been set successfully + */ +static ecma_value_t +ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */ + bool is_seal) /**< true - set "sealed" + * false - set "frozen" */ +{ + /* 3. */ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + ecma_value_t status = ecma_proxy_object_prevent_extensions (obj_p); + + if (!ecma_is_value_true (status)) + { + return status; + } + } + else +#endif /* JERRY_BUILTIN_PROXY */ + { + ecma_op_ordinary_object_prevent_extensions (obj_p); + } + + /* 6. */ + ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p, JERRY_PROPERTY_FILTER_ALL); + +#if JERRY_BUILTIN_PROXY + if (props_p == NULL) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t *buffer_p = props_p->buffer_p; + + if (is_seal) + { + /* 8.a */ + for (uint32_t i = 0; i < props_p->item_count; i++) + { + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[i]); + + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_collection_free (props_p); + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_false (status)) + { + continue; + } + + prop_desc.flags &= (uint16_t) ~JERRY_PROP_IS_CONFIGURABLE; + prop_desc.flags |= JERRY_PROP_SHOULD_THROW; + + /* 8.a.i */ + ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p, property_name_p, &prop_desc); + + ecma_free_property_descriptor (&prop_desc); + + /* 8.a.ii */ + if (ECMA_IS_VALUE_ERROR (define_own_prop_ret)) + { + ecma_collection_free (props_p); + return define_own_prop_ret; + } + + ecma_free_value (define_own_prop_ret); + } + } + else + { + /* 9.a */ + for (uint32_t i = 0; i < props_p->item_count; i++) + { + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[i]); + + /* 9.1 */ + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_collection_free (props_p); + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_false (status)) + { + continue; + } + + /* 9.2 */ + if ((prop_desc.flags & (JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_WRITABLE)) + == (JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_WRITABLE)) + { + prop_desc.flags &= (uint16_t) ~JERRY_PROP_IS_WRITABLE; + } + + prop_desc.flags &= (uint16_t) ~JERRY_PROP_IS_CONFIGURABLE; + prop_desc.flags |= JERRY_PROP_SHOULD_THROW; + + /* 9.3 */ + ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p, property_name_p, &prop_desc); + + ecma_free_property_descriptor (&prop_desc); + + /* 9.4 */ + if (ECMA_IS_VALUE_ERROR (define_own_prop_ret)) + { + ecma_collection_free (props_p); + return define_own_prop_ret; + } + + ecma_free_value (define_own_prop_ret); + } + } + + ecma_collection_free (props_p); + + return ECMA_VALUE_TRUE; +} /* ecma_builtin_object_set_integrity_level */ + +/** + * The Object object's 'seal' routine + * + * See also: + * ECMA-262 v5, 15.2.3.8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_seal (ecma_object_t *obj_p) /**< routine's argument */ +{ + ecma_value_t status = ecma_builtin_object_set_integrity_level (obj_p, true); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + +#if JERRY_BUILTIN_PROXY + if (ecma_is_value_false (status)) + { + return ecma_raise_type_error (ECMA_ERR_OBJECT_CANNOT_BE_SEALED); + } +#endif /* JERRY_BUILTIN_PROXY */ + + /* 4. */ + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); +} /* ecma_builtin_object_object_seal */ + +/** + * The Object object's 'freeze' routine + * + * See also: + * ECMA-262 v5, 15.2.3.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument */ +{ + ecma_value_t status = ecma_builtin_object_set_integrity_level (obj_p, false); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + +#if JERRY_BUILTIN_PROXY + if (ecma_is_value_false (status)) + { + return ecma_raise_type_error (ECMA_ERR_OBJECT_CANNOT_BE_FROZEN); + } +#endif /* JERRY_BUILTIN_PROXY */ + + /* 4. */ + ecma_ref_object (obj_p); + return ecma_make_object_value (obj_p); +} /* ecma_builtin_object_object_freeze */ + +/** + * The Object object's 'preventExtensions' routine + * + * See also: + * ECMA-262 v5, 15.2.3.10 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routine's argument */ +{ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + ecma_value_t status = ecma_proxy_object_prevent_extensions (obj_p); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + if (ecma_is_value_false (status)) + { + return ecma_raise_type_error (ECMA_ERR_SET_EXTENSIBLE_PROPERTY); + } + + JERRY_ASSERT (ecma_is_value_true (status)); + } + else + { +#endif /* JERRY_BUILTIN_PROXY */ + ecma_op_ordinary_object_prevent_extensions (obj_p); +#if JERRY_BUILTIN_PROXY + } +#endif /* JERRY_BUILTIN_PROXY */ + ecma_ref_object (obj_p); + + return ecma_make_object_value (obj_p); +} /* ecma_builtin_object_object_prevent_extensions */ + +/** + * The Object object's 'isSealed' and 'isFrozen' routines + * + * See also: + * ECMA-262 v5, 15.2.3.11 + * ECMA-262 v5, 15.2.3.12 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's argument */ + int mode) /**< routine mode */ +{ + JERRY_ASSERT (mode == ECMA_OBJECT_ROUTINE_IS_FROZEN || mode == ECMA_OBJECT_ROUTINE_IS_SEALED); + + /* 3. */ + bool is_extensible; +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + ecma_value_t status = ecma_proxy_object_is_extensible (obj_p); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + is_extensible = ecma_is_value_true (status); + } + else +#endif /* JERRY_BUILTIN_PROXY */ + { + is_extensible = ecma_op_ordinary_object_is_extensible (obj_p); + } + + if (is_extensible) + { + return ECMA_VALUE_FALSE; + } + + /* the value can be updated in the loop below */ + ecma_value_t ret_value = ECMA_VALUE_TRUE; + + /* 2. */ + ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p, JERRY_PROPERTY_FILTER_ALL); + +#if JERRY_BUILTIN_PROXY + if (props_p == NULL) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t *buffer_p = props_p->buffer_p; + + for (uint32_t i = 0; i < props_p->item_count; i++) + { + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[i]); + + /* 2.a */ + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (status)) + { + ret_value = status; + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_false (status)) + { + continue; + } + + bool is_writable_data = ((prop_desc.flags & (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE)) + == (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE)); + bool is_configurable = (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE); + + ecma_free_property_descriptor (&prop_desc); + + /* 2.b for isFrozen */ + /* 2.b for isSealed, 2.c for isFrozen */ + if ((mode == ECMA_OBJECT_ROUTINE_IS_FROZEN && is_writable_data) || is_configurable) + { + ret_value = ECMA_VALUE_FALSE; + break; + } + } + + ecma_collection_free (props_p); + + return ret_value; +} /* ecma_builtin_object_test_integrity_level */ + +/** + * The Object object's 'isExtensible' routine + * + * See also: + * ECMA-262 v5, 15.2.3.13 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p) /**< routine's argument */ +{ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + return ecma_proxy_object_is_extensible (obj_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + return ecma_make_boolean_value (ecma_op_ordinary_object_is_extensible (obj_p)); +} /* ecma_builtin_object_object_is_extensible */ + +/** + * Common implementation of the Object object's 'keys', 'values', 'entries' routines + * + * See also: + * ECMA-262 v11, 19.1.2.17 + * ECMA-262 v11, 19.1.2.22 + * ECMA-262 v11, 19.1.2.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_keys_values_helper (ecma_object_t *obj_p, /**< routine's first argument */ + ecma_enumerable_property_names_options_t option) /**< listing option */ +{ + /* 2. */ + ecma_collection_t *props_p = ecma_op_object_get_enumerable_property_names (obj_p, option); + + if (props_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + /* 3. */ + return ecma_op_new_array_object_from_collection (props_p, option != ECMA_ENUMERABLE_PROPERTY_KEYS); +} /* ecma_builtin_object_object_keys_values_helper */ + +/** + * The Object object's 'getOwnPropertyDescriptor' routine + * + * See also: + * ECMA-262 v5, 15.2.3.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< routine's first argument */ + ecma_string_t *name_str_p) /**< routine's second argument */ +{ + /* 3. */ + ecma_property_descriptor_t prop_desc; + + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, name_str_p, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_true (status)) + { + /* 4. */ + ecma_object_t *desc_obj_p = ecma_op_from_property_descriptor (&prop_desc); + + ecma_free_property_descriptor (&prop_desc); + + return ecma_make_object_value (desc_obj_p); + } + + return ECMA_VALUE_UNDEFINED; +} /* ecma_builtin_object_object_get_own_property_descriptor */ + +/** + * The Object object's 'getOwnPropertyDescriptors' routine + * + * See also: + * ECMA-262 v11, 19.1.2.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_get_own_property_descriptors (ecma_object_t *obj_p) /**< routine's first argument */ +{ + /* 2 */ + ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (obj_p, JERRY_PROPERTY_FILTER_ALL); + +#if JERRY_BUILTIN_PROXY + if (prop_names_p == NULL) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t *names_buffer_p = prop_names_p->buffer_p; + + /* 3 */ + ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + ecma_object_t *descriptors_p = ecma_create_object (object_prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); + + /* 4 */ + for (uint32_t i = 0; i < prop_names_p->item_count; i++) + { + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (names_buffer_p[i]); + + /* 4.a */ + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_deref_object (descriptors_p); + ecma_collection_free (prop_names_p); + + return status; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_true (status)) + { + /* 4.b */ + ecma_object_t *desc_obj_p = ecma_op_from_property_descriptor (&prop_desc); + /* 4.c */ + ecma_property_value_t *value_p = ecma_create_named_data_property (descriptors_p, + property_name_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + value_p->value = ecma_make_object_value (desc_obj_p); + + ecma_deref_object (desc_obj_p); + ecma_free_property_descriptor (&prop_desc); + } + } + + ecma_collection_free (prop_names_p); + + return ecma_make_object_value (descriptors_p); +} /* ecma_builtin_object_object_get_own_property_descriptors */ + +/** + * The Object object's 'defineProperties' routine + * + * See also: + * ECMA-262 v5, 15.2.3.7 + * ECMA-262 v11, 19.1.2.3.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + /* 2. */ + ecma_value_t props = ecma_op_to_object (arg2); + + if (ECMA_IS_VALUE_ERROR (props)) + { + return props; + } + + ecma_object_t *props_p = ecma_get_object_from_value (props); + + /* 3. */ + ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (props_p, JERRY_PROPERTY_FILTER_ALL); + ecma_value_t ret_value = ECMA_VALUE_ERROR; + +#if JERRY_BUILTIN_PROXY + if (prop_names_p == NULL) + { + ecma_deref_object (props_p); + return ret_value; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t *buffer_p = prop_names_p->buffer_p; + + /* 4. */ + JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, prop_names_p->item_count, ecma_property_descriptor_t); + uint32_t property_descriptor_number = 0; + ecma_collection_t *enum_prop_names = ecma_new_collection (); + + /* 5. */ + for (uint32_t i = 0; i < prop_names_p->item_count; i++) + { + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (buffer_p[i]); + + ecma_property_descriptor_t prop_desc; + ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (props_p, prop_name_p, &prop_desc); + + if (ECMA_IS_VALUE_ERROR (get_desc)) + { + goto cleanup; + } + + if (ecma_is_value_true (get_desc)) + { + if (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE) + { + ecma_value_t desc_obj = ecma_op_object_get (props_p, prop_name_p); + + if (ECMA_IS_VALUE_ERROR (desc_obj)) + { + ecma_free_property_descriptor (&prop_desc); + goto cleanup; + } + + ecma_value_t conv_result = + ecma_op_to_property_descriptor (desc_obj, &property_descriptors[property_descriptor_number]); + + property_descriptors[property_descriptor_number].flags |= JERRY_PROP_SHOULD_THROW; + + ecma_free_value (desc_obj); + + if (ECMA_IS_VALUE_ERROR (conv_result)) + { + ecma_free_property_descriptor (&prop_desc); + goto cleanup; + } + + property_descriptor_number++; + ecma_free_value (conv_result); + ecma_ref_ecma_string (prop_name_p); + ecma_collection_push_back (enum_prop_names, buffer_p[i]); + } + + ecma_free_property_descriptor (&prop_desc); + } + } + + /* 6. */ + for (uint32_t i = 0; i < enum_prop_names->item_count; i++) + { + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (enum_prop_names->buffer_p[i]); + + ecma_value_t define_own_prop_ret = + ecma_op_object_define_own_property (obj_p, prop_name_p, &property_descriptors[i]); + if (ECMA_IS_VALUE_ERROR (define_own_prop_ret)) + { + goto cleanup; + } + + ecma_free_value (define_own_prop_ret); + } + + ecma_ref_object (obj_p); + ret_value = ecma_make_object_value (obj_p); + +cleanup: + /* Clean up. */ + for (uint32_t index = 0; index < property_descriptor_number; index++) + { + ecma_free_property_descriptor (&property_descriptors[index]); + } + + ecma_collection_free (enum_prop_names); + + JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors); + + ecma_collection_free (prop_names_p); + + ecma_deref_object (props_p); + + return ret_value; +} /* ecma_builtin_object_object_define_properties */ + +/** + * The Object object's 'create' routine + * + * See also: + * ECMA-262 v5, 15.2.3.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_create (ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + /* 1. */ + if (!ecma_is_value_object (arg1) && !ecma_is_value_null (arg1)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + } + + ecma_object_t *obj_p = NULL; + + if (!ecma_is_value_null (arg1)) + { + obj_p = ecma_get_object_from_value (arg1); + } + /* 2-3. */ + ecma_object_t *result_obj_p = ecma_op_create_object_object_noarg_and_set_prototype (obj_p); + + /* 4. */ + if (!ecma_is_value_undefined (arg2)) + { + ecma_value_t obj = ecma_builtin_object_object_define_properties (result_obj_p, arg2); + + if (ECMA_IS_VALUE_ERROR (obj)) + { + ecma_deref_object (result_obj_p); + return obj; + } + + ecma_free_value (obj); + } + + /* 5. */ + return ecma_make_object_value (result_obj_p); +} /* ecma_builtin_object_object_create */ + +/** + * The Object object's 'defineProperty' routine + * + * See also: + * ECMA-262 v5, 15.2.3.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's first argument */ + ecma_string_t *name_str_p, /**< routine's second argument */ + ecma_value_t arg3) /**< routine's third argument */ +{ + ecma_property_descriptor_t prop_desc; + + ecma_value_t conv_result = ecma_op_to_property_descriptor (arg3, &prop_desc); + + if (ECMA_IS_VALUE_ERROR (conv_result)) + { + return conv_result; + } + + prop_desc.flags |= JERRY_PROP_SHOULD_THROW; + + ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p, name_str_p, &prop_desc); + + ecma_free_property_descriptor (&prop_desc); + ecma_free_value (conv_result); + + if (ECMA_IS_VALUE_ERROR (define_own_prop_ret)) + { + return define_own_prop_ret; + } + + if (ecma_is_value_false (define_own_prop_ret)) + { + return ecma_raise_type_error (ECMA_ERR_THE_REQUESTED_PROPERTY_UPDATE_CANNOT_BE_PERFORMED); + } + + JERRY_ASSERT (ecma_is_value_true (define_own_prop_ret)); + + ecma_ref_object (obj_p); + ecma_free_value (define_own_prop_ret); + + return ecma_make_object_value (obj_p); +} /* ecma_builtin_object_object_define_property */ + +/** + * The Object object's 'assign' routine + * + * See also: + * ECMA-262 v6, 19.1.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object */ + const ecma_value_t arguments_list_p[], /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + /* 4-5. */ + for (uint32_t i = 0; i < arguments_list_len && ecma_is_value_empty (ret_value); i++) + { + ecma_value_t next_source = arguments_list_p[i]; + + /* 5.a */ + if (ecma_is_value_undefined (next_source) || ecma_is_value_null (next_source)) + { + continue; + } + + /* 5.b.i */ + ecma_value_t from_value = ecma_op_to_object (next_source); + /* null and undefined cases are handled above, so this must be a valid object */ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (from_value)); + + ecma_object_t *from_obj_p = ecma_get_object_from_value (from_value); + + /* 5.b.iii */ + ecma_collection_t *props_p = ecma_op_object_own_property_keys (from_obj_p, JERRY_PROPERTY_FILTER_ALL); + +#if JERRY_BUILTIN_PROXY + if (props_p == NULL) + { + ecma_deref_object (from_obj_p); + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t *buffer_p = props_p->buffer_p; + + for (uint32_t j = 0; (j < props_p->item_count) && ecma_is_value_empty (ret_value); j++) + { + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (buffer_p[j]); + + /* 5.c.i-ii */ + ecma_property_descriptor_t prop_desc; + ecma_value_t desc_status = ecma_op_object_get_own_property_descriptor (from_obj_p, property_name_p, &prop_desc); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (desc_status)) + { + ret_value = desc_status; + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_false (desc_status)) + { + continue; + } + + /* 5.c.iii */ + if (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE) + { + /* 5.c.iii.1 */ + ecma_value_t prop_value = ecma_op_object_get (from_obj_p, property_name_p); + + /* 5.c.iii.2 */ + if (ECMA_IS_VALUE_ERROR (prop_value)) + { + ret_value = prop_value; + } + else + { + /* 5.c.iii.3 */ + ecma_value_t status = ecma_op_object_put (target_p, property_name_p, prop_value, true); + + /* 5.c.iii.4 */ + if (ECMA_IS_VALUE_ERROR (status)) + { + ret_value = status; + } + } + + ecma_free_value (prop_value); + } + + ecma_free_property_descriptor (&prop_desc); + } + + ecma_deref_object (from_obj_p); + ecma_collection_free (props_p); + } + + /* 6. */ + if (ecma_is_value_empty (ret_value)) + { + ecma_ref_object (target_p); + return ecma_make_object_value (target_p); + } + + return ret_value; +} /* ecma_builtin_object_object_assign */ + +/** + * The Object object's 'is' routine + * + * See also: + * ECMA-262 v6, 19.1.2.10 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_object_is (ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + return ecma_op_same_value (arg1, arg2) ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE; +} /* ecma_builtin_object_object_is */ + +/** + * The Object object's 'fromEntries' routine + * + * See also: + * ECMA-262 v10, 19.1.2.7 + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_object_from_entries (ecma_value_t iterator) /**< object's iterator */ +{ + JERRY_ASSERT (ecma_op_require_object_coercible (iterator)); + /* 2 */ + ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + ecma_object_t *obj_p = ecma_create_object (object_prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); + + /* 6.a */ + ecma_value_t next_method; + ecma_value_t result = ecma_op_get_iterator (iterator, ECMA_VALUE_SYNC_ITERATOR, &next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (obj_p); + return result; + } + + const ecma_value_t original_iterator = result; + + /* 6.b */ + while (true) + { + /* 6.a.i */ + result = ecma_op_iterator_step (original_iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_iterator; + } + + /* 6.a.ii */ + if (ecma_is_value_false (result)) + { + break; + } + + /* 6.a.iii */ + const ecma_value_t next = result; + result = ecma_op_iterator_value (next); + ecma_free_value (next); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_iterator; + } + + /* 6.a.iv */ + if (!ecma_is_value_object (result)) + { + ecma_free_value (result); + ecma_raise_type_error (ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT); + result = ecma_op_iterator_close (original_iterator); + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result)); + goto cleanup_iterator; + } + + /* 6.a.v-vi */ + ecma_object_t *next_object_p = ecma_get_object_from_value (result); + + result = ecma_op_object_get_by_index (next_object_p, 0); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (next_object_p); + ecma_op_iterator_close (original_iterator); + goto cleanup_iterator; + } + + const ecma_value_t key = result; + + result = ecma_op_object_get_by_index (next_object_p, 1); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (next_object_p); + ecma_free_value (key); + ecma_op_iterator_close (original_iterator); + goto cleanup_iterator; + } + + /* 6.a.vii */ + const ecma_value_t value = result; + ecma_string_t *property_key = ecma_op_to_property_key (key); + + if (property_key == NULL) + { + ecma_deref_object (next_object_p); + ecma_free_value (key); + ecma_op_iterator_close (original_iterator); + result = ECMA_VALUE_ERROR; + goto cleanup_iterator; + } + + ecma_property_t *property_p = ecma_find_named_property (obj_p, property_key); + + if (property_p == NULL) + { + ecma_property_value_t *prop; + prop = + ecma_create_named_data_property (obj_p, property_key, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, NULL); + prop->value = ecma_copy_value_if_not_object (value); + } + else + { + ecma_named_data_property_assign_value (obj_p, ECMA_PROPERTY_VALUE_PTR (property_p), value); + } + + ecma_deref_ecma_string (property_key); + ecma_free_value (key); + ecma_free_value (value); + ecma_deref_object (next_object_p); + } + + ecma_ref_object (obj_p); + result = ecma_make_object_value (obj_p); + +cleanup_iterator: + ecma_free_value (original_iterator); + ecma_free_value (next_method); + ecma_deref_object (obj_p); + + return result; +} /* ecma_builtin_object_from_entries */ + +/** + * GetOwnPropertyKeys abstract method + * + * See also: + * ECMA-262 v11, 19.1.2.11.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_op_object_get_own_property_keys (ecma_value_t this_arg, /**< this argument */ + uint16_t type) /**< routine type */ +{ + /* 1. */ + ecma_value_t object = ecma_op_to_object (this_arg); + + if (ECMA_IS_VALUE_ERROR (object)) + { + return object; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (object); + + /* 2. */ + jerry_property_filter_t filter = JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS; + + if (type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS) + { + filter = (jerry_property_filter_t) ((unsigned int) JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS | (unsigned int) JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES); + } + + ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p, filter); + + if (props_p == NULL) + { + ecma_deref_object (obj_p); + return ECMA_VALUE_ERROR; + } + + /* 3. */ + ecma_collection_t *name_list_p = ecma_new_collection (); + + /* 4. */ + for (uint32_t i = 0; i < props_p->item_count; i++) + { + ecma_value_t prop_name = props_p->buffer_p[i]; + ecma_string_t *name_p = ecma_get_prop_name_from_value (prop_name); + + if ((ecma_prop_name_is_symbol (name_p) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS) + || (ecma_is_value_string (prop_name) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES)) + { + ecma_ref_ecma_string (name_p); + ecma_collection_push_back (name_list_p, prop_name); + } + } + + ecma_value_t result_array = ecma_op_new_array_object_from_collection (name_list_p, false); + + ecma_deref_object (obj_p); + ecma_collection_free (props_p); + + return result_array; +} /* ecma_op_object_get_own_property_keys */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_object_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (this_arg, arguments_number); + + ecma_value_t arg1 = arguments_list_p[0]; + ecma_value_t arg2 = arguments_list_p[1]; + + /* No specialization for the arguments */ + switch (builtin_routine_id) + { + case ECMA_OBJECT_ROUTINE_CREATE: + { + return ecma_builtin_object_object_create (arg1, arg2); + } + case ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF: + { + return ecma_builtin_object_object_set_prototype_of (arg1, arg2); + } + case ECMA_OBJECT_ROUTINE_IS: + { + return ecma_builtin_object_object_is (arg1, arg2); + } + default: + { + break; + } + } + + ecma_object_t *obj_p; + + if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES) + { + if (!ecma_is_value_object (arg1)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + } + + obj_p = ecma_get_object_from_value (arg1); + + if (builtin_routine_id == ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY) + { + ecma_string_t *prop_name_p = ecma_op_to_property_key (arg2); + + if (prop_name_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_object_object_define_property (obj_p, prop_name_p, arguments_list_p[2]); + + ecma_deref_ecma_string (prop_name_p); + return result; + } + + JERRY_ASSERT (builtin_routine_id == ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES); + return ecma_builtin_object_object_define_properties (obj_p, arg2); + } + else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_ENTRIES) + { + ecma_value_t object = ecma_op_to_object (arg1); + if (ECMA_IS_VALUE_ERROR (object)) + { + return object; + } + + obj_p = ecma_get_object_from_value (object); + + ecma_value_t result; + switch (builtin_routine_id) + { + case ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF: + { + result = ecma_builtin_object_object_get_prototype_of (obj_p); + break; + } + case ECMA_OBJECT_ROUTINE_ASSIGN: + { + result = ecma_builtin_object_object_assign (obj_p, arguments_list_p + 1, arguments_number - 1); + break; + } + case ECMA_OBJECT_ROUTINE_ENTRIES: + case ECMA_OBJECT_ROUTINE_VALUES: + case ECMA_OBJECT_ROUTINE_KEYS: + { + JERRY_ASSERT (builtin_routine_id - ECMA_OBJECT_ROUTINE_KEYS < ECMA_ENUMERABLE_PROPERTY__COUNT); + + const int option = builtin_routine_id - ECMA_OBJECT_ROUTINE_KEYS; + result = + ecma_builtin_object_object_keys_values_helper (obj_p, (ecma_enumerable_property_names_options_t) option); + break; + } + case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR: + { + ecma_string_t *prop_name_p = ecma_op_to_property_key (arg2); + + if (prop_name_p == NULL) + { + result = ECMA_VALUE_ERROR; + break; + } + + result = ecma_builtin_object_object_get_own_property_descriptor (obj_p, prop_name_p); + ecma_deref_ecma_string (prop_name_p); + break; + } + case ECMA_OBJECT_ROUTINE_HAS_OWN: + { + ecma_string_t *prop_name_p = ecma_op_to_property_key (arg2); + + if (prop_name_p == NULL) + { + result = ECMA_VALUE_ERROR; + break; + } + + result = ecma_op_object_has_own_property (obj_p, prop_name_p); + ecma_deref_ecma_string (prop_name_p); + break; + } + case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTORS: + { + result = ecma_builtin_object_object_get_own_property_descriptors (obj_p); + break; + } + case ECMA_OBJECT_ROUTINE_FROM_ENTRIES: + { + result = ecma_builtin_object_from_entries (arg1); + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + + ecma_deref_object (obj_p); + return result; + } + else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS) + { + return ecma_op_object_get_own_property_keys (arg1, builtin_routine_id); + } + else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_SEAL) + { + if (!ecma_is_value_object (arg1)) + { + return ecma_copy_value (arg1); + } + + obj_p = ecma_get_object_from_value (arg1); + switch (builtin_routine_id) + { + case ECMA_OBJECT_ROUTINE_SEAL: + { + return ecma_builtin_object_object_seal (obj_p); + } + case ECMA_OBJECT_ROUTINE_FREEZE: + { + return ecma_builtin_object_object_freeze (obj_p); + } + case ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS: + { + return ecma_builtin_object_object_prevent_extensions (obj_p); + } + default: + { + JERRY_UNREACHABLE (); + } + } + } + else + { + JERRY_ASSERT (builtin_routine_id <= ECMA_OBJECT_ROUTINE_IS_SEALED); + + if (!ecma_is_value_object (arg1)) + { + return ecma_make_boolean_value (builtin_routine_id != ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE); + } + + obj_p = ecma_get_object_from_value (arg1); + switch (builtin_routine_id) + { + case ECMA_OBJECT_ROUTINE_IS_SEALED: + case ECMA_OBJECT_ROUTINE_IS_FROZEN: + { + return ecma_builtin_object_test_integrity_level (obj_p, builtin_routine_id); + } + case ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE: + { + return ecma_builtin_object_object_is_extensible (obj_p); + } + default: + { + JERRY_UNREACHABLE (); + } + } + } +} /* ecma_builtin_object_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.h new file mode 100644 index 0000000..f31b261 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.h @@ -0,0 +1,34 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef ECMA_BUILTIN_OBJECT_H +#define ECMA_BUILTIN_OBJECT_H + +#include "ecma-globals.h" + +ecma_value_t ecma_builtin_object_object_get_prototype_of (ecma_object_t *obj_p); + +ecma_value_t ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, ecma_value_t arg2); + +ecma_value_t ecma_builtin_object_object_set_proto (ecma_value_t arg1, ecma_value_t arg2); + +ecma_value_t ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p); + +ecma_value_t ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p); + +ecma_value_t ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, ecma_string_t *name_str_p); +ecma_value_t +ecma_builtin_object_object_define_property (ecma_object_t *obj_p, ecma_string_t *name_str_p, ecma_value_t arg3); + +#endif /* !ECMA_BUILTIN_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h new file mode 100644 index 0000000..ee02ad6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h @@ -0,0 +1,59 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Object built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.2.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_OBJECT_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF, 1, 1) +ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES, 1, 1) +ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_SYMBOLS_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SEAL, ECMA_OBJECT_ROUTINE_SEAL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FREEZE, ECMA_OBJECT_ROUTINE_FREEZE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_SEALED_UL, ECMA_OBJECT_ROUTINE_IS_SEALED, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_FROZEN_UL, ECMA_OBJECT_ROUTINE_IS_FROZEN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_EXTENSIBLE, ECMA_OBJECT_ROUTINE_IS_EXTENSIBLE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_OBJECT_ROUTINE_ENTRIES, 1, 1) +ROUTINE (LIT_MAGIC_STRING_VALUES, ECMA_OBJECT_ROUTINE_VALUES, 1, 1) +ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_OBJECT_ROUTINE_KEYS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR, 2, 2) +ROUTINE (LIT_MAGIC_STRING_HAS_OWN_UL, ECMA_OBJECT_ROUTINE_HAS_OWN, 2, 2) +ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTORS_UL, ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTORS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_OBJECT_FROM_ENTRIES, ECMA_OBJECT_ROUTINE_FROM_ENTRIES, 1, 1) +ROUTINE (LIT_MAGIC_STRING_CREATE, ECMA_OBJECT_ROUTINE_CREATE, 2, 2) +ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL, ECMA_OBJECT_ROUTINE_DEFINE_PROPERTIES, 2, 2) +ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ECMA_OBJECT_ROUTINE_DEFINE_PROPERTY, 3, 3) +ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_OBJECT_ROUTINE_SET_PROTOTYPE_OF, 2, 2) +ROUTINE (LIT_MAGIC_STRING_ASSIGN, ECMA_OBJECT_ROUTINE_ASSIGN, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_IS, ECMA_OBJECT_ROUTINE_IS, 2, 2) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise-prototype.cpp new file mode 100644 index 0000000..b24f6d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise-prototype.cpp @@ -0,0 +1,93 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-globals.h" +#include "ecma-promise-object.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_PROMISE_PROTOTYPE_ROUTINE_START = 0, + ECMA_PROMISE_PROTOTYPE_ROUTINE_THEN, + ECMA_PROMISE_PROTOTYPE_ROUTINE_CATCH, + ECMA_PROMISE_PROTOTYPE_ROUTINE_FINALLY +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-promise-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID promise_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup promiseprototype ECMA Promise.prototype object built-in + * @{ + */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_promise_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + switch (builtin_routine_id) + { + case ECMA_PROMISE_PROTOTYPE_ROUTINE_THEN: + { + return ecma_promise_then (this_arg, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_PROMISE_PROTOTYPE_ROUTINE_CATCH: + { + ecma_value_t args[] = { ECMA_VALUE_UNDEFINED, arguments_list_p[0] }; + return ecma_op_invoke_by_magic_id (this_arg, LIT_MAGIC_STRING_THEN, args, 2); + } + case ECMA_PROMISE_PROTOTYPE_ROUTINE_FINALLY: + { + return ecma_promise_finally (this_arg, arguments_list_p[0]); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_promise_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise-prototype.inc.h new file mode 100644 index 0000000..76ee6fd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise-prototype.inc.h @@ -0,0 +1,30 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_PROMISE, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 25.4.5.4 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_PROMISE_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ROUTINE (LIT_MAGIC_STRING_THEN, ECMA_PROMISE_PROTOTYPE_ROUTINE_THEN, 2, 2) +ROUTINE (LIT_MAGIC_STRING_CATCH, ECMA_PROMISE_PROTOTYPE_ROUTINE_CATCH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FINALLY, ECMA_PROMISE_PROTOTYPE_ROUTINE_FINALLY, 1, 1) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise.cpp new file mode 100644 index 0000000..1cfa5dd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise.cpp @@ -0,0 +1,527 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-handlers.h" +#include "ecma-builtin-helpers.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-iterator-object.h" +#include "ecma-number-object.h" +#include "ecma-promise-object.h" + +#include "jcontext.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_PROMISE_ROUTINE_START = 0, + ECMA_PROMISE_ROUTINE_REJECT, + ECMA_PROMISE_ROUTINE_RESOLVE, + ECMA_PROMISE_ROUTINE_RACE, + ECMA_PROMISE_ROUTINE_ALL, + ECMA_PROMISE_ROUTINE_ALLSETTLED, + ECMA_PROMISE_ROUTINE_ANY, + ECMA_PROMISE_ROUTINE_SPECIES_GET +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-promise.inc.h" +#define BUILTIN_UNDERSCORED_ID promise +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup promise ECMA Promise object built-in + * @{ + */ + +/** + * Runtime Semantics: PerformPromiseRace. + * + * See also: + * ES2020 25.6.4.4.1 + * + * @return ecma value of the new promise. + * Returned value must be freed with ecma_free_value. + */ +static inline ecma_value_t +ecma_builtin_promise_perform_race (ecma_value_t iterator, /**< the iterator for race */ + ecma_value_t next_method, /**< next method */ + ecma_object_t *capability_obj_p, /**< PromiseCapability record */ + ecma_value_t ctor, /**< Constructor value */ + bool *done_p) /**< [out] iteratorRecord[[done]] */ +{ + JERRY_ASSERT (ecma_is_value_object (iterator)); + JERRY_ASSERT (ecma_object_class_is (capability_obj_p, ECMA_OBJECT_CLASS_PROMISE_CAPABILITY)); + JERRY_ASSERT (ecma_is_constructor (ctor)); + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + + ecma_value_t resolve = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (ctor), LIT_MAGIC_STRING_RESOLVE); + + if (ECMA_IS_VALUE_ERROR (resolve)) + { + return resolve; + } + + if (!ecma_op_is_callable (resolve)) + { + ecma_free_value (resolve); + return ecma_raise_type_error (ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE); + } + + ecma_object_t *resolve_func_p = ecma_get_object_from_value (resolve); + ecma_value_t ret_value = ECMA_VALUE_ERROR; + + /* 5. */ + while (true) + { + /* a. */ + ecma_value_t next = ecma_op_iterator_step (iterator, next_method); + /* b, c. */ + if (ECMA_IS_VALUE_ERROR (next)) + { + goto done; + } + + /* d. */ + if (ecma_is_value_false (next)) + { + /* ii. */ + ret_value = ecma_copy_value (capability_p->header.u.cls.u3.promise); + goto done; + } + + /* e. */ + ecma_value_t next_val = ecma_op_iterator_value (next); + ecma_free_value (next); + + /* f, g. */ + if (ECMA_IS_VALUE_ERROR (next_val)) + { + goto done; + } + + /* h. */ + ecma_value_t next_promise = ecma_op_function_call (resolve_func_p, ctor, &next_val, 1); + ecma_free_value (next_val); + + if (ECMA_IS_VALUE_ERROR (next_promise)) + { + goto exit; + } + + /* i. */ + ecma_value_t args[2] = { capability_p->resolve, capability_p->reject }; + ecma_value_t result = ecma_op_invoke_by_magic_id (next_promise, LIT_MAGIC_STRING_THEN, args, 2); + ecma_free_value (next_promise); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto exit; + } + + ecma_free_value (result); + } + +done: + *done_p = true; +exit: + ecma_deref_object (resolve_func_p); + + return ret_value; +} /* ecma_builtin_promise_perform_race */ + +/** + * Runtime Semantics: Perform Promise all, allSettled or any. + * + * See also: + * ES2020 25.6.4.1.1 + * + * @return ecma value of the new promise. + * Returned value must be freed with ecma_free_value. + */ +static inline ecma_value_t +ecma_builtin_promise_perform (ecma_value_t iterator, /**< iteratorRecord */ + ecma_value_t next_method, /**< next method */ + ecma_object_t *capability_obj_p, /**< PromiseCapability record */ + ecma_value_t ctor, /**< the caller of Promise.all */ + uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + bool *done_p) /**< [out] iteratorRecord[[done]] */ +{ + /* 1. - 2. */ + JERRY_ASSERT (ecma_object_class_is (capability_obj_p, ECMA_OBJECT_CLASS_PROMISE_CAPABILITY)); + JERRY_ASSERT (ecma_is_constructor (ctor)); + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + + ecma_value_t resolve = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (ctor), LIT_MAGIC_STRING_RESOLVE); + + if (ECMA_IS_VALUE_ERROR (resolve)) + { + return resolve; + } + + if (!ecma_op_is_callable (resolve)) + { + ecma_free_value (resolve); + return ecma_raise_type_error (ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE); + } + + ecma_object_t *resolve_func_p = ecma_get_object_from_value (resolve); + + /* 3. */ + ecma_object_t *values_array_obj_p = ecma_op_new_array_object (0); + ecma_value_t values_array = ecma_make_object_value (values_array_obj_p); + /* 4. */ + ecma_value_t remaining = ecma_op_create_number_object (ecma_make_integer_value (1)); + /* 5. */ + uint32_t idx = 0; + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + + /* 6. */ + while (true) + { + /* a. */ + ecma_value_t next = ecma_op_iterator_step (iterator, next_method); + /* b. - c. */ + if (ECMA_IS_VALUE_ERROR (next)) + { + goto done; + } + + /* d. */ + if (ecma_is_value_false (next)) + { + /* ii. - iii. */ + if (ecma_promise_remaining_inc_or_dec (remaining, false) == 0) + { + if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ANY) + { + ret_value = ecma_raise_aggregate_error (values_array, ECMA_VALUE_UNDEFINED); + goto done; + } + + /* 2. */ + ecma_value_t resolve_result = ecma_op_function_call (ecma_get_object_from_value (capability_p->resolve), + ECMA_VALUE_UNDEFINED, + &values_array, + 1); + /* 3. */ + if (ECMA_IS_VALUE_ERROR (resolve_result)) + { + goto done; + } + + ecma_free_value (resolve_result); + } + + /* iv. */ + ret_value = ecma_copy_value (capability_p->header.u.cls.u3.promise); + goto done; + } + + /* e. */ + ecma_value_t next_value = ecma_op_iterator_value (next); + ecma_free_value (next); + + /* f. - g. */ + if (ECMA_IS_VALUE_ERROR (next_value)) + { + goto done; + } + + /* h. */ + ecma_builtin_helper_def_prop_by_index (values_array_obj_p, + idx, + ECMA_VALUE_UNDEFINED, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + + /* i. */ + ecma_value_t next_promise = ecma_op_function_call (resolve_func_p, ctor, &next_value, 1); + ecma_free_value (next_value); + + /* j. */ + if (ECMA_IS_VALUE_ERROR (next_promise)) + { + goto exit; + } + + if (JERRY_UNLIKELY (idx == UINT32_MAX - 1)) + { + ecma_raise_range_error (ECMA_ERR_PROMISE_ALL_REMAINING_ELEMENTS_LIMIT_REACHED); + goto exit; + } + + idx++; + ecma_value_t args[2]; + ecma_object_t *executor_func_p = NULL; + + if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ANY) + { + /* k. */ + executor_func_p = + ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER, sizeof (ecma_promise_all_executor_t)); + + ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) executor_func_p; + + /* m. + t. */ + executor_p->index = idx; + + /* n. */ + executor_p->values = values_array; + + /* o. */ + executor_p->capability = ecma_make_object_value (capability_obj_p); + + /* p. */ + executor_p->remaining_elements = remaining; + + uint8_t executor_type = ECMA_PROMISE_ALL_RESOLVE << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT; + + if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ALLSETTLED) + { + executor_type = ECMA_PROMISE_ALLSETTLED_RESOLVE << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT; + } + + executor_p->header.u.built_in.u2.routine_flags |= executor_type; + + args[0] = ecma_make_object_value (executor_func_p); + } + else + { + args[0] = capability_p->resolve; + } + + /* q. */ + ecma_promise_remaining_inc_or_dec (remaining, true); + ecma_value_t result; + + if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ALL) + { + uint8_t executor_type = ECMA_PROMISE_ALLSETTLED_REJECT << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT; + + if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ANY) + { + executor_type = ECMA_PROMISE_ANY_REJECT << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT; + } + + ecma_object_t *reject_func_p = + ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER, sizeof (ecma_promise_all_executor_t)); + + ecma_promise_all_executor_t *reject_p = (ecma_promise_all_executor_t *) reject_func_p; + reject_p->index = idx; + reject_p->values = values_array; + reject_p->capability = ecma_make_object_value (capability_obj_p); + reject_p->remaining_elements = remaining; + reject_p->header.u.built_in.u2.routine_flags |= executor_type; + args[1] = ecma_make_object_value (reject_func_p); + result = ecma_op_invoke_by_magic_id (next_promise, LIT_MAGIC_STRING_THEN, args, 2); + ecma_deref_object (reject_func_p); + } + else + { + args[1] = capability_p->reject; + result = ecma_op_invoke_by_magic_id (next_promise, LIT_MAGIC_STRING_THEN, args, 2); + } + + ecma_free_value (next_promise); + + if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ANY) + { + ecma_deref_object (executor_func_p); + } + + /* s. */ + if (ECMA_IS_VALUE_ERROR (result)) + { + goto exit; + } + + ecma_free_value (result); + } + +done: + *done_p = true; +exit: + ecma_free_value (remaining); + ecma_deref_object (values_array_obj_p); + ecma_deref_object (resolve_func_p); + + return ret_value; +} /* ecma_builtin_promise_perform */ + +/** + * The common function for Promise.race, Promise.all, Promise.any and Promise.allSettled. + * + * @return ecma value of the new promise. + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_promise_helper (ecma_value_t this_arg, /**< 'this' argument */ + ecma_value_t iterable, /**< the items to be resolved */ + uint8_t builtin_routine_id) /**< built-in wide routine identifier */ +{ + ecma_object_t *capability_obj_p = ecma_promise_new_capability (this_arg, ECMA_VALUE_UNDEFINED); + + if (JERRY_UNLIKELY (capability_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (iterable, ECMA_VALUE_SYNC_ITERATOR, &next_method); + ecma_value_t ret = ECMA_VALUE_ERROR; + + if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&iterator, capability_obj_p))) + { + ecma_free_value (next_method); + ecma_deref_object (capability_obj_p); + return iterator; + } + + bool is_done = false; + + if (builtin_routine_id == ECMA_PROMISE_ROUTINE_RACE) + { + ret = ecma_builtin_promise_perform_race (iterator, next_method, capability_obj_p, this_arg, &is_done); + } + else + { + ret = + ecma_builtin_promise_perform (iterator, next_method, capability_obj_p, this_arg, builtin_routine_id, &is_done); + } + + if (ECMA_IS_VALUE_ERROR (ret)) + { + if (!is_done) + { + ret = ecma_op_iterator_close (iterator); + } + + ecma_op_if_abrupt_reject_promise (&ret, capability_obj_p); + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + ecma_deref_object (capability_obj_p); + + return ret; +} /* ecma_builtin_promise_helper */ + +/** + * Handle calling [[Call]] of built-in Promise object. + * + * ES2015 25.4.3 Promise is not intended to be called + * as a function and will throw an exception when called + * in that manner. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_promise_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_PROMISE_REQUIRES_NEW); +} /* ecma_builtin_promise_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Promise object. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_promise_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len == 0 || !ecma_op_is_callable (arguments_list_p[0])) + { + return ecma_raise_type_error (ECMA_ERR_FIRST_PARAMETER_MUST_BE_CALLABLE); + } + + return ecma_op_create_promise_object (arguments_list_p[0], + ECMA_VALUE_UNDEFINED, + JERRY_CONTEXT (current_new_target_p)); +} /* ecma_builtin_promise_dispatch_construct */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_promise_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + switch (builtin_routine_id) + { + case ECMA_PROMISE_ROUTINE_REJECT: + case ECMA_PROMISE_ROUTINE_RESOLVE: + { + bool is_resolve = (builtin_routine_id == ECMA_PROMISE_ROUTINE_RESOLVE); + return ecma_promise_reject_or_resolve (this_arg, arguments_list_p[0], is_resolve); + } + case ECMA_PROMISE_ROUTINE_RACE: + case ECMA_PROMISE_ROUTINE_ALL: + case ECMA_PROMISE_ROUTINE_ALLSETTLED: + case ECMA_PROMISE_ROUTINE_ANY: + { + return ecma_builtin_promise_helper (this_arg, arguments_list_p[0], builtin_routine_id); + } + case ECMA_PROMISE_ROUTINE_SPECIES_GET: + { + return ecma_copy_value (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_promise_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise.inc.h new file mode 100644 index 0000000..d2bcff4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-promise.inc.h @@ -0,0 +1,46 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Promise built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_PROMISE_PROTOTYPE, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_PROMISE_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_REJECT, ECMA_PROMISE_ROUTINE_REJECT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_RESOLVE, ECMA_PROMISE_ROUTINE_RESOLVE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_RACE, ECMA_PROMISE_ROUTINE_RACE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ALL, ECMA_PROMISE_ROUTINE_ALL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ALLSETTLED, ECMA_PROMISE_ROUTINE_ALLSETTLED, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ANY, ECMA_PROMISE_ROUTINE_ANY, 1, 1) + +/* ES2015 25.4.4.6 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ECMA_PROMISE_ROUTINE_SPECIES_GET, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-proxy.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-proxy.cpp new file mode 100644 index 0000000..2a2097d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-proxy.cpp @@ -0,0 +1,160 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-proxy-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_PROXY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_PROXY_OBJECT_ROUTINE_START = 0, + ECMA_BUILTIN_PROXY_OBJECT_REVOCABLE, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-proxy.inc.h" +#define BUILTIN_UNDERSCORED_ID proxy +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup proxy ECMA Proxy object built-in + * @{ + */ + +/** + * The Proxy object's 'revocable' routine + * + * See also: + * ES2015 26.2.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_proxy_object_revocable (ecma_value_t target, /**< target argument */ + ecma_value_t handler) /**< handler argument */ +{ + ecma_object_t *rev_proxy_p = ecma_proxy_create_revocable (target, handler); + + if (JERRY_UNLIKELY (rev_proxy_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + return ecma_make_object_value (rev_proxy_p); +} /* ecma_builtin_proxy_object_revocable */ + +/** + * Handle calling [[Call]] of built-in Proxy object + * + * See also: + * ES2015 26.2.2 + * + * @return raised error + */ +ecma_value_t +ecma_builtin_proxy_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + /* 1. */ + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_PROXY_REQUIRES_NEW); +} /* ecma_builtin_proxy_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in proxy object + * + * See also: + * ES2015 26.2.2 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * new proxy object - otherwise + */ +ecma_value_t +ecma_builtin_proxy_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + /* 2. */ + ecma_object_t *proxy_p = ecma_proxy_create (arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED, + arguments_list_len > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED, + 0); + + if (JERRY_UNLIKELY (proxy_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + return ecma_make_object_value (proxy_p); +} /* ecma_builtin_proxy_dispatch_construct */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_proxy_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (this_arg, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_PROXY_OBJECT_REVOCABLE: + { + return ecma_builtin_proxy_object_revocable (arguments_list_p[0], arguments_list_p[1]); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_proxy_dispatch_routine */ +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_PROXY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-proxy.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-proxy.inc.h new file mode 100644 index 0000000..3267061 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-proxy.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Proxy object built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_PROXY + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 2, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_PROXY_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ + +ROUTINE (LIT_MAGIC_STRING_REVOCABLE, ECMA_BUILTIN_PROXY_OBJECT_REVOCABLE, 2, 2) + +#endif /* JERRY_BUILTIN_PROXY */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.cpp new file mode 100644 index 0000000..f72ac2c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.cpp @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-rangeerror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID range_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h new file mode 100644 index 0000000..1307e4a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * RangeError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_RANGE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_RANGE_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.cpp new file mode 100644 index 0000000..c17a236 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.cpp @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-rangeerror.inc.h" +#define BUILTIN_UNDERSCORED_ID range_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup rangeerror ECMA RangeError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in RangeError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_range_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_RANGE, arguments_list_p, arguments_list_len); +} /* ecma_builtin_range_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in RangeError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_range_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), + ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_range_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_range_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h new file mode 100644 index 0000000..6891fa5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * RangeError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_RANGE_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.cpp new file mode 100644 index 0000000..5212d6b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.cpp @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-referenceerror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID reference_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h new file mode 100644 index 0000000..caa9e0e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * ReferenceError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_REFERENCE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_REFERENCE_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.cpp new file mode 100644 index 0000000..2a3f2da --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.cpp @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-referenceerror.inc.h" +#define BUILTIN_UNDERSCORED_ID reference_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup referenceerror ECMA ReferenceError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in ReferenceError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_reference_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_REFERENCE, arguments_list_p, arguments_list_len); +} /* ecma_builtin_reference_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in ReferenceError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_reference_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), + ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_reference_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_reference_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h new file mode 100644 index 0000000..b28ada1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * ReferenceError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_REFERENCE_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.cpp new file mode 100644 index 0000000..056a6b5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.cpp @@ -0,0 +1,344 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-array-object.h" +#include "ecma-builtin-function-prototype.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtin-object.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-iterator-object.h" +#include "ecma-proxy-object.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_REFLECT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_REFLECT_OBJECT_ROUTINE_START = 0, + ECMA_REFLECT_OBJECT_GET, /* ECMA-262 v6, 26.1.6 */ + ECMA_REFLECT_OBJECT_SET, /* ECMA-262 v6, 26.1.13 */ + ECMA_REFLECT_OBJECT_HAS, /* ECMA-262 v6, 26.1.9 */ + ECMA_REFLECT_OBJECT_DELETE_PROPERTY, /* ECMA-262 v6, 26.1.4 */ + ECMA_REFLECT_OBJECT_CONSTRUCT, /* ECMA-262, 26.1.2 */ + ECMA_REFLECT_OBJECT_OWN_KEYS, /* ECMA-262 v6, 26.1.11 */ + ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF, /* ECMA-262 v6, 26.1.8 */ + ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF, /* ECMA-262 v6, 26.1.14 */ + ECMA_REFLECT_OBJECT_APPLY, /* ECMA-262 v6, 26.1.1 */ + ECMA_REFLECT_OBJECT_DEFINE_PROPERTY, /* ECMA-262 v6, 26.1.3 */ + ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR, /* ECMA-262 v6, 26.1.7 */ + ECMA_REFLECT_OBJECT_IS_EXTENSIBLE, /* ECMA-262 v6, 26.1.10 */ + ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS, /* ECMA-262 v6, 26.1.12 */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-reflect.inc.h" +#define BUILTIN_UNDERSCORED_ID reflect +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup object ECMA Reflect object built-in + * @{ + */ + +/** + * Dispatcher for the built-in's routines. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_reflect_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (this_arg); + + if (builtin_routine_id < ECMA_REFLECT_OBJECT_CONSTRUCT) + { + /* 1. */ + if (arguments_number == 0 || !ecma_is_value_object (arguments_list[0])) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + } + + /* 2. */ + ecma_string_t *name_str_p = ecma_op_to_property_key (arguments_list[1]); + + /* 3. */ + if (name_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_value; + ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]); + switch (builtin_routine_id) + { + case ECMA_REFLECT_OBJECT_GET: + { + ecma_value_t receiver = arguments_list[0]; + + /* 4. */ + if (arguments_number > 2) + { + receiver = arguments_list[2]; + } + + ret_value = ecma_op_object_get_with_receiver (target_p, name_str_p, receiver); + break; + } + + case ECMA_REFLECT_OBJECT_HAS: + { + ret_value = ecma_op_object_has_property (target_p, name_str_p); + break; + } + + case ECMA_REFLECT_OBJECT_DELETE_PROPERTY: + { + ret_value = ecma_op_object_delete (target_p, name_str_p, false); + break; + } + + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_REFLECT_OBJECT_SET); + + ecma_value_t receiver = arguments_list[0]; + + if (arguments_number > 3) + { + receiver = arguments_list[3]; + } + + ret_value = ecma_op_object_put_with_receiver (target_p, name_str_p, arguments_list[2], receiver, false); + break; + } + } + + ecma_deref_ecma_string (name_str_p); + return ret_value; + } + + if (builtin_routine_id == ECMA_REFLECT_OBJECT_OWN_KEYS) + { + /* 1. */ + if (arguments_number == 0 || !ecma_is_value_object (arguments_list[0])) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + } + + ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]); + + /* 2. */ + ecma_collection_t *prop_names = ecma_op_object_own_property_keys (target_p, JERRY_PROPERTY_FILTER_ALL); + +#if JERRY_BUILTIN_PROXY + if (prop_names == NULL) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + /* 3. */ + return ecma_op_new_array_object_from_collection (prop_names, false); + } + + if (builtin_routine_id == ECMA_REFLECT_OBJECT_CONSTRUCT) + { + /* 1. */ + if (arguments_number < 1 || !ecma_is_constructor (arguments_list[0])) + { + return ecma_raise_type_error (ECMA_ERR_TARGET_IS_NOT_A_CONSTRUCTOR); + } + + ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]); + + /* 2. */ + ecma_object_t *new_target_p = target_p; + + if (arguments_number > 2) + { + /* 3. */ + if (!ecma_is_constructor (arguments_list[2])) + { + return ecma_raise_type_error (ECMA_ERR_TARGET_IS_NOT_A_CONSTRUCTOR); + } + + new_target_p = ecma_get_object_from_value (arguments_list[2]); + } + + /* 4. */ + if (arguments_number < 2) + { + return ecma_raise_type_error (ECMA_ERR_REFLECT_EXPECTS_AN_OBJECT_AS_SECOND_ARGUMENT); + } + + ecma_collection_t *coll_p = ecma_op_create_list_from_array_like (arguments_list[1], false); + + if (coll_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_value = ecma_op_function_construct (target_p, new_target_p, coll_p->buffer_p, coll_p->item_count); + + ecma_collection_free (coll_p); + return ret_value; + } + + if (!ecma_is_value_object (arguments_list[0])) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + } + + switch (builtin_routine_id) + { + case ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF: + { + return ecma_builtin_object_object_get_prototype_of (ecma_get_object_from_value (arguments_list[0])); + } + case ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF: + { + if (!ecma_is_value_object (arguments_list[1]) && !ecma_is_value_null (arguments_list[1])) + { + return ecma_raise_type_error (ECMA_ERR_PROTOTYPE_IS_NEITHER_OBJECT_NOR_NULL); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + ecma_value_t status; + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + status = ecma_proxy_object_set_prototype_of (obj_p, arguments_list[1]); + } + else +#endif /* JERRY_BUILTIN_PROXY */ + { + status = ecma_op_ordinary_object_set_prototype_of (obj_p, arguments_list[1]); + } + + return status; + } + case ECMA_REFLECT_OBJECT_APPLY: + { + if (!ecma_op_is_callable (arguments_list[0])) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_FUNCTION); + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (arguments_list[0]); + return ecma_builtin_function_prototype_object_apply (func_obj_p, arguments_list[1], arguments_list[2]); + } + case ECMA_REFLECT_OBJECT_DEFINE_PROPERTY: + { + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + ecma_string_t *name_str_p = ecma_op_to_property_key (arguments_list[1]); + + if (name_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_property_descriptor_t prop_desc; + ecma_value_t conv_result = ecma_op_to_property_descriptor (arguments_list[2], &prop_desc); + + if (ECMA_IS_VALUE_ERROR (conv_result)) + { + ecma_deref_ecma_string (name_str_p); + return conv_result; + } + + ecma_value_t result = ecma_op_object_define_own_property (obj_p, name_str_p, &prop_desc); + + ecma_deref_ecma_string (name_str_p); + ecma_free_property_descriptor (&prop_desc); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + bool boolean_result = ecma_op_to_boolean (result); + + return ecma_make_boolean_value (boolean_result); + } + case ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR: + { + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + ecma_string_t *name_str_p = ecma_op_to_property_key (arguments_list[1]); + + if (name_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_val = ecma_builtin_object_object_get_own_property_descriptor (obj_p, name_str_p); + ecma_deref_ecma_string (name_str_p); + return ret_val; + } + case ECMA_REFLECT_OBJECT_IS_EXTENSIBLE: + { + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + return ecma_builtin_object_object_is_extensible (obj_p); + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS); + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + return ecma_proxy_object_prevent_extensions (obj_p); + } +#endif /* !JERRY_BUILTIN_PROXY */ + + ecma_op_ordinary_object_prevent_extensions (obj_p); + + return ECMA_VALUE_TRUE; + } + } +} /* ecma_builtin_reflect_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REFLECT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.inc.h new file mode 100644 index 0000000..4f4c824 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_REFLECT + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_APPLY, ECMA_REFLECT_OBJECT_APPLY, 3, 3) +ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ECMA_REFLECT_OBJECT_DEFINE_PROPERTY, 3, 3) +ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR, 2, 2) +ROUTINE (LIT_MAGIC_STRING_GET, ECMA_REFLECT_OBJECT_GET, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_SET, ECMA_REFLECT_OBJECT_SET, NON_FIXED, 3) +ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_REFLECT_OBJECT_HAS, 2, 2) +ROUTINE (LIT_MAGIC_STRING_DELETE_PROPERTY_UL, ECMA_REFLECT_OBJECT_DELETE_PROPERTY, 2, 2) +ROUTINE (LIT_MAGIC_STRING_OWN_KEYS_UL, ECMA_REFLECT_OBJECT_OWN_KEYS, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_CONSTRUCT, ECMA_REFLECT_OBJECT_CONSTRUCT, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_EXTENSIBLE, ECMA_REFLECT_OBJECT_IS_EXTENSIBLE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF, 2, 2) + +#endif /* JERRY_BUILTIN_REFLECT */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.cpp new file mode 100644 index 0000000..94c0384 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.cpp @@ -0,0 +1,659 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-regexp-object.h" + +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_REGEXP +#include "ecma-regexp-object.h" + +#include "re-compiler.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID regexp_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup regexpprototype ECMA RegExp.prototype object built-in + * @{ + */ + +/** + * Helper function to retrieve the flags associated with a RegExp object + * + * @return ECMA_VALUE_{TRUE,FALSE} depends on whether the given flag is present. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_flags_helper (ecma_extended_object_t *re_obj_p, /**< this object */ + uint16_t builtin_routine_id) /**< id of the flag */ +{ + re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, re_obj_p->u.cls.u3.value); + + uint16_t flags = bc_p->header.status_flags; + + static const uint8_t re_flags[] = { + RE_FLAG_GLOBAL, RE_FLAG_IGNORE_CASE, RE_FLAG_MULTILINE, RE_FLAG_STICKY, RE_FLAG_UNICODE, RE_FLAG_DOTALL, + }; + + uint16_t offset = (uint16_t) (builtin_routine_id - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL); + return ecma_make_boolean_value ((flags & re_flags[offset]) != 0); +} /* ecma_builtin_regexp_prototype_flags_helper */ + +/** + * The RegExp.prototype object's 'flags' accessor property + * + * See also: + * ECMA-262 v6, 21.2.5.3 + * + * @return ECMA_VALUE_ERROR - if 'this' is not a RegExp object + * string value - otherwise + * + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_get_flags (ecma_object_t *object_p) /**< this object */ +{ + static const lit_magic_string_id_t flag_lit_ids[] = { LIT_MAGIC_STRING_GLOBAL, LIT_MAGIC_STRING_IGNORECASE_UL, + LIT_MAGIC_STRING_MULTILINE, LIT_MAGIC_STRING_DOTALL, + LIT_MAGIC_STRING_UNICODE, LIT_MAGIC_STRING_STICKY }; + + static const lit_utf8_byte_t flag_chars[] = { LIT_CHAR_LOWERCASE_G, LIT_CHAR_LOWERCASE_I, LIT_CHAR_LOWERCASE_M, + LIT_CHAR_LOWERCASE_S, LIT_CHAR_LOWERCASE_U, LIT_CHAR_LOWERCASE_Y }; + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + for (uint32_t i = 0; i < sizeof (flag_lit_ids) / sizeof (lit_magic_string_id_t); i++) + { + ecma_value_t result = ecma_op_object_get_by_magic_id (object_p, flag_lit_ids[i]); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_stringbuilder_destroy (&builder); + return result; + } + + if (ecma_op_to_boolean (result)) + { + ecma_stringbuilder_append_byte (&builder, flag_chars[i]); + } + + ecma_free_value (result); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_regexp_prototype_get_flags */ + +/** + * The EscapeRegExpPattern method. + * + * See also: + * ECMA-262 v6, 21.2.3.2.4 + * + * @return ecma_value_t + */ +static ecma_value_t +ecma_op_escape_regexp_pattern (ecma_string_t *pattern_str_p) /**< RegExp pattern */ +{ + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start_p, pattern_start_size); + + const lit_utf8_byte_t *pattern_str_curr_p = pattern_start_p; + const lit_utf8_byte_t *pattern_str_end_p = pattern_start_p + pattern_start_size; + + while (pattern_str_curr_p < pattern_str_end_p) + { + ecma_char_t c = lit_cesu8_read_next (&pattern_str_curr_p); + + switch (c) + { + case LIT_CHAR_SLASH: + { + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\/", 2); + break; + } + case LIT_CHAR_LF: + { + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\n", 2); + break; + } + case LIT_CHAR_CR: + { + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\r", 2); + break; + } + case LIT_CHAR_LS: + { + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\u2028", 6); + break; + } + case LIT_CHAR_PS: + { + ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *) "\\u2029", 6); + break; + } + case LIT_CHAR_BACKSLASH: + { + JERRY_ASSERT (pattern_str_curr_p < pattern_str_end_p); + ecma_stringbuilder_append_char (&builder, LIT_CHAR_BACKSLASH); + ecma_stringbuilder_append_char (&builder, lit_cesu8_read_next (&pattern_str_curr_p)); + break; + } + default: + { + ecma_stringbuilder_append_char (&builder, c); + break; + } + } + } + + ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size); + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_op_escape_regexp_pattern */ + +/** + * The RegExp.prototype object's 'source' accessor property + * + * See also: + * ECMA-262 v6, 21.2.5.10 + * + * @return ECMA_VALUE_ERROR - if 'this' is not a RegExp object + * string value - otherwise + * + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_get_source (ecma_extended_object_t *re_obj_p) /**< this argument */ +{ + re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, re_obj_p->u.cls.u3.value); + + return ecma_op_escape_regexp_pattern (ecma_get_string_from_value (bc_p->source)); +} /* ecma_builtin_regexp_prototype_get_source */ + +#if JERRY_BUILTIN_ANNEXB +/** + * The RegExp.prototype object's 'compile' routine + * + * See also: + * ECMA-262 v11, B.2.5.1 + * + * @return undefined - if compiled successfully + * error ecma value - otherwise + * + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this */ + ecma_value_t pattern_arg, /**< pattern or RegExp object */ + ecma_value_t flags_arg) /**< flags */ +{ + ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg); + ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) this_obj_p; + re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, re_obj_p->u.cls.u3.value); + + ecma_value_t ret_value; + + if (ecma_object_is_regexp_object (pattern_arg)) + { + if (!ecma_is_value_undefined (flags_arg)) + { + return ecma_raise_type_error (ECMA_ERR_INVALID_ARGUMENT); + } + + ecma_extended_object_t *pattern_obj_p = (ecma_extended_object_t *) ecma_get_object_from_value (pattern_arg); + re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, pattern_obj_p->u.cls.u3.value); + + ret_value = ecma_op_create_regexp_from_bytecode (this_obj_p, bc_p); + } + else + { + ret_value = ecma_op_create_regexp_from_pattern (this_obj_p, pattern_arg, flags_arg); + } + + if (!ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_value_t status = ecma_builtin_helper_def_prop (this_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_uint32_value (0), + ECMA_PROPERTY_FLAG_WRITABLE | JERRY_PROP_SHOULD_THROW); + + ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + ecma_ref_object (this_obj_p); + } + + return ret_value; +} /* ecma_builtin_regexp_prototype_compile */ + +#endif /* JERRY_BUILTIN_ANNEXB */ + +/** + * The RegExp.prototype object's 'exec' routine + * + * See also: + * ECMA-262 v5, 15.10.6.2 + * + * @return array object containing the results - if the matched + * null - otherwise + * + * May raise error, so returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arg) /**< routine's argument */ +{ + ecma_value_t obj_this = ecma_op_to_object (this_arg); + if (ECMA_IS_VALUE_ERROR (obj_this)) + { + return obj_this; + } + + ecma_string_t *input_str_p = ecma_op_to_string (arg); + if (JERRY_UNLIKELY (input_str_p == NULL)) + { + ecma_free_value (obj_this); + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_value = ecma_regexp_exec_helper (ecma_get_object_from_value (obj_this), input_str_p); + + ecma_free_value (obj_this); + ecma_deref_ecma_string (input_str_p); + + return ret_value; +} /* ecma_builtin_regexp_prototype_exec */ + +/** + * The RegExp.prototype object's 'test' routine + * + * See also: + * ECMA-262 v5, 15.10.6.3 + * ECMA-262 v6, 21.2.5.13 + * + * @return true - if match is not null + * false - otherwise + * + * May raise error, so returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_test (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arg) /**< routine's argument */ +{ + ecma_string_t *arg_str_p = ecma_op_to_string (arg); + + if (JERRY_UNLIKELY (arg_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_op_regexp_exec (this_arg, arg_str_p); + + ecma_deref_ecma_string (arg_str_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ecma_value_t ret_value = ecma_make_boolean_value (!ecma_is_value_null (result)); + ecma_free_value (result); + + return ret_value; +} /* ecma_builtin_regexp_prototype_test */ + +/** + * The RegExp.prototype object's 'toString' routine + * + * See also: + * ECMA-262 v5, 15.10.6.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_regexp_prototype_to_string (ecma_object_t *object_p) /**< this object */ +{ + ecma_value_t result = ecma_op_object_get_by_magic_id (object_p, LIT_MAGIC_STRING_SOURCE); + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ecma_string_t *source_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (source_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + result = ecma_op_object_get_by_magic_id (object_p, LIT_MAGIC_STRING_FLAGS); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_ecma_string (source_p); + return result; + } + + ecma_string_t *flags_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (flags_p == NULL) + { + ecma_deref_ecma_string (source_p); + return ECMA_VALUE_ERROR; + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_SLASH); + ecma_stringbuilder_append (&builder, source_p); + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_SLASH); + ecma_stringbuilder_append (&builder, flags_p); + + ecma_deref_ecma_string (source_p); + ecma_deref_ecma_string (flags_p); + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_regexp_prototype_to_string */ + +/** + * The RegExp.prototype object's 'matchAll' routine + * + * See also: + * ECMA-262 v11, 21.2.5.8 + * + * @return ecma_value_t + */ +static ecma_value_t +ecma_builtin_regexp_prototype_match_all (ecma_object_t *regexp_obj_p, /**< this argument */ + ecma_value_t string_arg) /**< source string */ +{ + /* 3. */ + ecma_string_t *str_p = ecma_op_to_string (string_arg); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 4. */ + ecma_value_t constructor = ecma_op_species_constructor (regexp_obj_p, ECMA_BUILTIN_ID_REGEXP); + + if (ECMA_IS_VALUE_ERROR (constructor)) + { + ecma_deref_ecma_string (str_p); + return constructor; + } + + /* 5. */ + ecma_value_t get_flag = ecma_op_object_get_by_magic_id (regexp_obj_p, LIT_MAGIC_STRING_FLAGS); + + if (ECMA_IS_VALUE_ERROR (get_flag)) + { + ecma_deref_ecma_string (str_p); + ecma_free_value (constructor); + return get_flag; + } + + ecma_string_t *flags = ecma_op_to_string (get_flag); + + ecma_free_value (get_flag); + + if (JERRY_UNLIKELY (flags == NULL)) + { + ecma_deref_ecma_string (str_p); + ecma_free_value (constructor); + return ECMA_VALUE_ERROR; + } + + /* 6. */ + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor); + ecma_value_t flags_value = ecma_make_string_value (flags); + ecma_value_t match_args[] = { ecma_make_object_value (regexp_obj_p), flags_value }; + ecma_value_t matcher = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, match_args, 2); + + ecma_deref_object (constructor_obj_p); + + if (ECMA_IS_VALUE_ERROR (matcher)) + { + ecma_deref_ecma_string (str_p); + ecma_deref_ecma_string (flags); + return matcher; + } + + /* 7. */ + ecma_value_t get_last_index = ecma_op_object_get_by_magic_id (regexp_obj_p, LIT_MAGIC_STRING_LASTINDEX_UL); + + if (ECMA_IS_VALUE_ERROR (get_last_index)) + { + ecma_deref_ecma_string (str_p); + ecma_deref_ecma_string (flags); + ecma_free_value (matcher); + return get_last_index; + } + + ecma_length_t last_index; + ecma_value_t to_len = ecma_op_to_length (get_last_index, &last_index); + + ecma_free_value (get_last_index); + + if (ECMA_IS_VALUE_ERROR (to_len)) + { + ecma_deref_ecma_string (str_p); + ecma_deref_ecma_string (flags); + ecma_free_value (matcher); + return to_len; + } + + /* 8. */ + ecma_object_t *matcher_obj_p = ecma_get_object_from_value (matcher); + ecma_value_t last_index_value = ecma_make_length_value (last_index); + ecma_value_t set = + ecma_op_object_put (matcher_obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), last_index_value, true); + + ecma_free_value (last_index_value); + + if (ECMA_IS_VALUE_ERROR (set)) + { + ecma_deref_ecma_string (str_p); + ecma_deref_ecma_string (flags); + ecma_deref_object (matcher_obj_p); + } + + uint16_t parsed_flag; + ecma_value_t flag_parse = ecma_regexp_parse_flags (flags, &parsed_flag); + + ecma_deref_ecma_string (flags); + + if (ECMA_IS_VALUE_ERROR (flag_parse)) + { + ecma_deref_ecma_string (str_p); + ecma_deref_object (matcher_obj_p); + return flag_parse; + } + + /* 13. */ + ecma_object_t *result_obj; + ecma_object_t *proto_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_STRING_ITERATOR_PROTOTYPE); + result_obj = ecma_create_object (proto_p, sizeof (ecma_regexp_string_iterator_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) result_obj; + ext_obj_p->u.cls.type = ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR; + ext_obj_p->u.cls.u1.regexp_string_iterator_flags = (uint8_t) (parsed_flag & (RE_FLAG_GLOBAL | RE_FLAG_UNICODE)); + + ecma_regexp_string_iterator_t *regexp_string_iterator_obj = (ecma_regexp_string_iterator_t *) result_obj; + + regexp_string_iterator_obj->iterating_regexp = matcher; + regexp_string_iterator_obj->iterated_string = ecma_make_string_value (str_p); + + ecma_deref_object (matcher_obj_p); + + return ecma_make_object_value (result_obj); +} /* ecma_builtin_regexp_prototype_match_all */ + +/** + * Dispatcher of the Regexp built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_regexp_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + + ecma_object_t *obj_p = NULL; + + /* 1. && 2. */ + if (ecma_is_value_object (this_arg)) + { + obj_p = ecma_get_object_from_value (this_arg); + + if (builtin_routine_id < ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST + && !ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_REGEXP)) + { + obj_p = NULL; + } + } + + if (obj_p == NULL) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + switch (builtin_routine_id) + { +#if JERRY_BUILTIN_ANNEXB + case ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE: + { + return ecma_builtin_regexp_prototype_compile (this_arg, arguments_list_p[0], arguments_list_p[1]); + } +#endif /* JERRY_BUILTIN_ANNEXB */ + case ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST: + { + return ecma_builtin_regexp_prototype_test (this_arg, arguments_list_p[0]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC: + { + return ecma_builtin_regexp_prototype_exec (this_arg, arguments_list_p[0]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING: + { + return ecma_builtin_regexp_prototype_to_string (obj_p); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SEARCH: + { + return ecma_regexp_search_helper (this_arg, arguments_list_p[0]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH: + { + return ecma_regexp_match_helper (this_arg, arguments_list_p[0]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH_ALL: + { + return ecma_builtin_regexp_prototype_match_all (obj_p, arguments_list_p[0]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_REPLACE: + { + return ecma_regexp_replace_helper (this_arg, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SPLIT: + { + return ecma_regexp_split_helper (this_arg, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_FLAGS: + { + return ecma_builtin_regexp_prototype_get_flags (obj_p); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE: + { + if (!ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_REGEXP)) + { + if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP); + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_REGEXP); + } + + ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p; + return ecma_builtin_regexp_prototype_get_source (re_obj_p); + } + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL: + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE: + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE: + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY: + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE: + case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL: + { + if (!ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_REGEXP)) + { + if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)) + { + return ECMA_VALUE_UNDEFINED; + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_REGEXP); + } + + ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p; + return ecma_builtin_regexp_prototype_flags_helper (re_obj_p, builtin_routine_id); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_regexp_prototype_dispatch_routine */ +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h new file mode 100644 index 0000000..51486e9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h @@ -0,0 +1,64 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * RegExp.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_REGEXP + +/* ECMA-262 v5, 15.10.6.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_REGEXP, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_FLAGS, ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_FLAGS, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SOURCE, ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_GLOBAL, ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_IGNORECASE_UL, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_DOTALL, ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_MULTILINE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_UNICODE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_STICKY, ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +ROUTINE (LIT_GLOBAL_SYMBOL_REPLACE, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_REPLACE, 2, 2) +ROUTINE (LIT_GLOBAL_SYMBOL_SEARCH, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SEARCH, 1, 1) +ROUTINE (LIT_GLOBAL_SYMBOL_SPLIT, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SPLIT, 2, 2) +ROUTINE (LIT_GLOBAL_SYMBOL_MATCH, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH, 1, 1) +ROUTINE (LIT_GLOBAL_SYMBOL_MATCH_ALL, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH_ALL, 1, 1) + +#if JERRY_BUILTIN_ANNEXB +ROUTINE (LIT_MAGIC_STRING_COMPILE, ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE, 2, 2) +#endif /* JERRY_BUILTIN_ANNEXB */ +ROUTINE (LIT_MAGIC_STRING_EXEC, ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TEST, ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST, 1, 1) +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING, 0, 0) + +#endif /* JERRY_BUILTIN_REGEXP */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-string-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-string-iterator-prototype.cpp new file mode 100644 index 0000000..cbf509d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-string-iterator-prototype.cpp @@ -0,0 +1,186 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-gc.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp-string-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID regexp_string_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %regexpstringiteratorprototype% ECMA %ArrayIteratorPrototype% object built-in + * @{ + */ + +/** + * The %RegExpStringIteratorPrototype% object's 'next' routine + * + * See also: + * ECMA-262 v11, 21.2.7.1.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +#ifdef JERRY_BUILTIN_REGEXP +static ecma_value_t +ecma_builtin_regexp_string_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */ +{ + /* 2. */ + if (!ecma_is_value_object (this_val)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (this_val); + + /* 3. */ + if (!ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR); + } + + ecma_regexp_string_iterator_t *regexp_string_iterator_obj = (ecma_regexp_string_iterator_t *) obj_p; + + /* 4. */ + if (ecma_is_value_empty (regexp_string_iterator_obj->iterated_string)) + { + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + /* 5. */ + ecma_value_t regexp = regexp_string_iterator_obj->iterating_regexp; + + /* 6. */ + ecma_value_t matcher_str_value = regexp_string_iterator_obj->iterated_string; + ecma_string_t *matcher_str_p = ecma_get_string_from_value (matcher_str_value); + + /* 9. */ + ecma_value_t match = ecma_op_regexp_exec (regexp, matcher_str_p); + + if (ECMA_IS_VALUE_ERROR (match)) + { + return match; + } + + /* 10. */ + if (ecma_is_value_null (match)) + { + ecma_free_value (regexp_string_iterator_obj->iterated_string); + regexp_string_iterator_obj->iterated_string = ECMA_VALUE_EMPTY; + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + ecma_object_t *match_result_array_p = ecma_get_object_from_value (match); + + ecma_value_t result = ECMA_VALUE_ERROR; + + /* 11. */ + if (regexp_string_iterator_obj->header.u.cls.u1.regexp_string_iterator_flags & RE_FLAG_GLOBAL) + { + ecma_value_t matched_str_value = ecma_op_object_get_by_index (match_result_array_p, 0); + + if (ECMA_IS_VALUE_ERROR (matched_str_value)) + { + goto free_variables; + } + + ecma_string_t *matched_str_p = ecma_op_to_string (matched_str_value); + + ecma_free_value (matched_str_value); + + if (JERRY_UNLIKELY (matched_str_p == NULL)) + { + goto free_variables; + } + + if (ecma_string_is_empty (matched_str_p)) + { + ecma_object_t *regexp_obj_p = ecma_get_object_from_value (regexp); + + ecma_value_t get_last_index = ecma_op_object_get_by_magic_id (regexp_obj_p, LIT_MAGIC_STRING_LASTINDEX_UL); + + if (ECMA_IS_VALUE_ERROR (get_last_index)) + { + goto free_variables; + } + + ecma_length_t this_index; + ecma_value_t to_len = ecma_op_to_length (get_last_index, &this_index); + + ecma_free_value (get_last_index); + + if (ECMA_IS_VALUE_ERROR (to_len)) + { + goto free_variables; + } + + uint8_t flags = regexp_string_iterator_obj->header.u.cls.u1.regexp_string_iterator_flags; + ecma_length_t next_index = + ecma_op_advance_string_index (matcher_str_p, this_index, (flags & RE_FLAG_UNICODE) != 0); + + ecma_value_t next_index_value = ecma_make_length_value (next_index); + ecma_value_t set = ecma_op_object_put (regexp_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + next_index_value, + true); + + ecma_free_value (next_index_value); + + if (ECMA_IS_VALUE_ERROR (set)) + { + goto free_variables; + } + } + else + { + ecma_deref_ecma_string (matched_str_p); + } + } + else + { + ecma_free_value (regexp_string_iterator_obj->iterated_string); + regexp_string_iterator_obj->iterated_string = ECMA_VALUE_EMPTY; + } + + result = ecma_create_iter_result_object (match, ECMA_VALUE_FALSE); + +free_variables: + ecma_deref_object (match_result_array_p); + + return result; +} /* ecma_builtin_regexp_string_iterator_prototype_object_next */ +#endif + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-string-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-string-iterator-prototype.inc.h new file mode 100644 index 0000000..80568ee --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-string-iterator-prototype.inc.h @@ -0,0 +1,34 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %RegExpStringIteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#ifdef JERRY_BUILTIN_REGEXP + +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, + LIT_MAGIC_STRING_REGEXP_STRING_ITERATOR_UL, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ecma_builtin_regexp_string_iterator_prototype_object_next, 0, 0) + +#endif + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp new file mode 100644 index 0000000..0b3cfe5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp @@ -0,0 +1,217 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-regexp-object.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_REGEXP + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp.inc.h" +#define BUILTIN_UNDERSCORED_ID regexp +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup regexp ECMA RegExp object built-in + * @{ + */ + +static ecma_value_t +ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_value_t pattern_value = ECMA_VALUE_UNDEFINED; + ecma_value_t flags_value = ECMA_VALUE_UNDEFINED; + bool create_regexp_from_bc = false; + bool free_arguments = false; + ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target_p); + + if (arguments_list_len > 0) + { + /* pattern string or RegExp object */ + pattern_value = arguments_list_p[0]; + + if (arguments_list_len > 1) + { + flags_value = arguments_list_p[1]; + } + } + + ecma_value_t regexp_value = ecma_op_is_regexp (pattern_value); + + if (ECMA_IS_VALUE_ERROR (regexp_value)) + { + return regexp_value; + } + + bool pattern_is_regexp = regexp_value == ECMA_VALUE_TRUE; + re_compiled_code_t *bc_p = NULL; + + if (new_target_p == NULL) + { + new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP); + + if (pattern_is_regexp && ecma_is_value_undefined (flags_value)) + { + ecma_object_t *pattern_obj_p = ecma_get_object_from_value (pattern_value); + + ecma_value_t pattern_constructor = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_CONSTRUCTOR); + + if (ECMA_IS_VALUE_ERROR (pattern_constructor)) + { + return pattern_constructor; + } + + bool is_same = ecma_op_same_value (ecma_make_object_value (new_target_p), pattern_constructor); + ecma_free_value (pattern_constructor); + + if (is_same) + { + return ecma_copy_value (pattern_value); + } + } + } + + if (ecma_object_is_regexp_object (pattern_value)) + { + ecma_extended_object_t *pattern_obj_p = (ecma_extended_object_t *) ecma_get_object_from_value (pattern_value); + bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, pattern_obj_p->u.cls.u3.value); + + create_regexp_from_bc = ecma_is_value_undefined (flags_value); + + if (!create_regexp_from_bc) + { + pattern_value = bc_p->source; + } + } + else if (pattern_is_regexp) + { + ecma_object_t *pattern_obj_p = ecma_get_object_from_value (pattern_value); + + pattern_value = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_SOURCE); + + if (ECMA_IS_VALUE_ERROR (pattern_value)) + { + return pattern_value; + } + + if (ecma_is_value_undefined (flags_value)) + { + flags_value = ecma_op_object_get_by_magic_id (pattern_obj_p, LIT_MAGIC_STRING_FLAGS); + + if (ECMA_IS_VALUE_ERROR (flags_value)) + { + ecma_free_value (pattern_value); + return flags_value; + } + } + else + { + flags_value = ecma_copy_value (flags_value); + } + + free_arguments = true; + } + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + ecma_object_t *new_target_obj_p = ecma_op_regexp_alloc (new_target_p); + + if (JERRY_LIKELY (new_target_obj_p != NULL)) + { + if (create_regexp_from_bc) + { + ret_value = ecma_op_create_regexp_from_bytecode (new_target_obj_p, bc_p); + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (ret_value)); + } + else + { + ret_value = ecma_op_create_regexp_from_pattern (new_target_obj_p, pattern_value, flags_value); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_deref_object (new_target_obj_p); + } + } + } + + if (free_arguments) + { + ecma_free_value (pattern_value); + ecma_free_value (flags_value); + } + + return ret_value; +} /* ecma_builtin_regexp_dispatch_helper */ + +/** + * Handle calling [[Call]] of built-in RegExp object + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_regexp_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_regexp_dispatch_helper (arguments_list_p, arguments_list_len); +} /* ecma_builtin_regexp_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in RegExp object + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_regexp_dispatch_helper (arguments_list_p, arguments_list_len); +} /* ecma_builtin_regexp_dispatch_construct */ + +/** + * 21.2.4.2 get RegExp [ @@species ] accessor + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_builtin_regexp_species_get (ecma_value_t this_value) /**< This Value */ +{ + return ecma_copy_value (this_value); +} /* ecma_builtin_regexp_species_get */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h new file mode 100644 index 0000000..a9fa892 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h @@ -0,0 +1,35 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * RegExp built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_REGEXP + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 2, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* ECMA-262 v5, 15.10.5.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_REGEXP_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_REGEXP_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 21.2.4.2 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ecma_builtin_regexp_species_get, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_REGEXP */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-iterator-prototype.cpp new file mode 100644 index 0000000..e435626 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-iterator-prototype.cpp @@ -0,0 +1,106 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-container-object.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_SET_ITERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_BUILTIN_SET_ITERATOR_PROTOTYPE_OBJECT_NEXT, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-set-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID set_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %setiteratorprototype% ECMA %SetIteratorPrototype% object built-in + * @{ + */ + +/** + * The %SetIteratorPrototype% object's 'next' routine + * + * See also: + * ECMA-262 v6, 23.2.5.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +static ecma_value_t +ecma_builtin_set_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */ +{ + return ecma_op_container_iterator_next (this_val, ECMA_OBJECT_CLASS_SET_ITERATOR); +} /* ecma_builtin_set_iterator_prototype_object_next */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_set_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + *routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_SET_ITERATOR_PROTOTYPE_OBJECT_NEXT: + { + return ecma_builtin_set_iterator_prototype_object_next (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_set_iterator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-iterator-prototype.inc.h new file mode 100644 index 0000000..4704236 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-iterator-prototype.inc.h @@ -0,0 +1,32 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %SetIteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_SET_ITERATOR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_BUILTIN_SET_ITERATOR_PROTOTYPE_OBJECT_NEXT, 0, 0) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-prototype.cpp new file mode 100644 index 0000000..8ff2687 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-prototype.cpp @@ -0,0 +1,65 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-container-object.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-set-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID set_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup set ECMA Set object built-in + * @{ + */ +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_set_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + return ecma_builtin_container_dispatch_routine (builtin_routine_id, + this_arg, + arguments_list_p, + LIT_MAGIC_STRING_SET_UL); +} /* ecma_builtin_set_prototype_dispatch_routine */ +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-prototype.inc.h new file mode 100644 index 0000000..8c6f874 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set-prototype.inc.h @@ -0,0 +1,55 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Set.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.2.3.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_SET, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.1.3.13 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_SET_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_CLEAR, ECMA_CONTAINER_ROUTINE_CLEAR, 0, 0) +ROUTINE (LIT_MAGIC_STRING_ADD, ECMA_CONTAINER_ROUTINE_ADD, 1, 1) +ROUTINE (LIT_MAGIC_STRING_DELETE, ECMA_CONTAINER_ROUTINE_DELETE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_CONTAINER_ROUTINE_FOREACH, 2, 1) +ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_CONTAINER_ROUTINE_HAS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_CONTAINER_ROUTINE_ENTRIES, 0, 0) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_VALUES, + LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, + LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_KEYS, + LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE, ECMA_CONTAINER_ROUTINE_SIZE_GETTER, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set.cpp new file mode 100644 index 0000000..d875fda --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set.cpp @@ -0,0 +1,86 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-container-object.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-set.inc.h" +#define BUILTIN_UNDERSCORED_ID set +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup set ECMA Set object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Set object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_set_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_SET_REQUIRES_NEW); +} /* ecma_builtin_set_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Map object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_set_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_op_container_create (arguments_list_p, + arguments_list_len, + LIT_MAGIC_STRING_SET_UL, + ECMA_BUILTIN_ID_SET_PROTOTYPE); +} /* ecma_builtin_set_dispatch_construct */ + +/** + * 23.2.2.2 get Set [ @@species ] accessor + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_builtin_set_species_get (ecma_value_t this_value) /**< This Value */ +{ + return ecma_copy_value (this_value); +} /* ecma_builtin_set_species_get */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set.inc.h new file mode 100644 index 0000000..559b4cc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-set.inc.h @@ -0,0 +1,44 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Set built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v6, 23.2.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 23.1 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_SET_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.2.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_SET_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v6, 23.2.2.2 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ecma_builtin_set_species_get, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.cpp new file mode 100644 index 0000000..321c2c8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.cpp @@ -0,0 +1,113 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-shared-arraybuffer-object.h" + +#include "jrt-libc-includes.h" +#include "jrt.h" + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-shared-arraybuffer-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID shared_arraybuffer_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup sharedarraybufferprototype ECMA SharedArrayBuffer.prototype object built-in + * @{ + */ + +/** + * The SharedArrayBuffer.prototype.bytelength accessor + * + * See also: + * ES11, 24.2.4.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_shared_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER)) + { + uint32_t len = ecma_arraybuffer_get_length (object_p); + + return ecma_make_uint32_value (len); + } + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER); +} /* ecma_builtin_shared_arraybuffer_prototype_bytelength_getter */ + +/** + * The SharedArrayBuffer.prototype object's 'slice' routine + * + * See also: + * ECMA-262 v11, 24.2.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_shared_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< this argument */ + const ecma_value_t *argument_list_p, /**< arguments list */ + uint32_t arguments_number) /**< number of arguments */ +{ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + /* 2. */ + if (!ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_SHARED_ARRAY_BUFFER_OBJECT); + } + + return ecma_builtin_arraybuffer_slice (this_arg, argument_list_p, arguments_number); +} /* ecma_builtin_shared_arraybuffer_prototype_object_slice */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h new file mode 100644 index 0000000..c7b0b9e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * SharedArrayBuffer.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Readonly accessor properties */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL, + ecma_builtin_shared_arraybuffer_prototype_bytelength_getter, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v11, 24.2.4.4 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_shared_arraybuffer_prototype_object_slice, NON_FIXED, 2) + +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.cpp new file mode 100644 index 0000000..38fc8f1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.cpp @@ -0,0 +1,96 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-dataview-object.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-shared-arraybuffer-object.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-shared-arraybuffer.inc.h" +#define BUILTIN_UNDERSCORED_ID shared_arraybuffer +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup sharedarraybuffer ECMA SharedArrayBuffer object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in SharedArrayBuffer object + * + * ES11 24.2.2 SharedArrayBuffer is not intended to be called as + * a function and will throw an exception when called in + * that manner. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_shared_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_SHAREDARRAYBUFFER_REQUIRES_NEW); +} /* ecma_builtin_shared_arraybuffer_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in SharedArrayBuffer object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_shared_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_shared_arraybuffer_object (arguments_list_p, arguments_list_len); +} /* ecma_builtin_shared_arraybuffer_dispatch_construct */ + +/** + * 24.2.3.2 get SharedArrayBuffer [ @@species ] accessor + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_builtin_shared_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */ +{ + return ecma_copy_value (this_value); +} /* ecma_builtin_shared_arraybuffer_species_get */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h new file mode 100644 index 0000000..8a7c73a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h @@ -0,0 +1,46 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * SharedArrayBuffer built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ + +/* ES11 24.1.3.3 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, + ecma_builtin_shared_arraybuffer_species_get, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-iterator-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-iterator-prototype.cpp new file mode 100644 index 0000000..7ff48fb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-iterator-prototype.cpp @@ -0,0 +1,202 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-iterator-object.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_STRING_ITERATOR_PROTOTYPE_ROUTINE_START = 0, + ECMA_BUILTIN_STRING_ITERATOR_PROTOTYPE_OBJECT_NEXT, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string-iterator-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID string_iterator_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup %stringiteratorprototype% ECMA %ArrayIteratorPrototype% object built-in + * @{ + */ + +/** + * The %StringIteratorPrototype% object's 'next' routine + * + * See also: + * ECMA-262 v6, 22.1.5.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +static ecma_value_t +ecma_builtin_string_iterator_prototype_object_next (ecma_value_t this_val) /**< this argument */ +{ + /* 1 - 2. */ + if (!ecma_is_value_object (this_val)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (this_val); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + /* 3. */ + if (!ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_STRING_ITERATOR)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR); + } + + ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value; + + /* 4 - 5 */ + if (ecma_is_value_empty (iterated_value)) + { + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + JERRY_ASSERT (ecma_is_value_string (iterated_value)); + + ecma_string_t *string_p = ecma_get_string_from_value (iterated_value); + + /* 6. */ + lit_utf8_size_t position = ext_obj_p->u.cls.u2.iterator_index; + + if (JERRY_UNLIKELY (position == ECMA_ITERATOR_INDEX_LIMIT)) + { + /* After the ECMA_ITERATOR_INDEX_LIMIT limit is reached the [[%Iterator%NextIndex]] + property is stored as an internal property */ + ecma_string_t *prop_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX); + ecma_value_t position_value = ecma_op_object_get (obj_p, prop_name_p); + + position = (lit_utf8_size_t) (ecma_get_number_from_value (position_value)); + ecma_free_value (position_value); + } + + /* 7. */ + lit_utf8_size_t len = ecma_string_get_length (string_p); + + /* 8. */ + if (position >= len) + { + ecma_deref_ecma_string (string_p); + ext_obj_p->u.cls.u3.iterated_value = ECMA_VALUE_EMPTY; + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + /* 9. */ + ecma_char_t first = ecma_string_get_char_at_pos (string_p, position); + + ecma_string_t *result_str_p; + lit_utf8_size_t result_size = 1; + + /* 10. */ + if (first < LIT_UTF16_HIGH_SURROGATE_MIN || first > LIT_UTF16_HIGH_SURROGATE_MAX || (position + 1 == len)) + { + result_str_p = ecma_new_ecma_string_from_code_unit (first); + } + /* 11. */ + else + { + /* 11.a */ + ecma_char_t second = ecma_string_get_char_at_pos (string_p, position + 1); + + /* 11.b */ + if (second < LIT_UTF16_LOW_SURROGATE_MIN || second > LIT_UTF16_LOW_SURROGATE_MAX) + { + result_str_p = ecma_new_ecma_string_from_code_unit (first); + } + /* 11.c */ + else + { + result_str_p = ecma_new_ecma_string_from_code_units (first, second); + result_size = 2; + } + } + + /* 13. */ + if (position + result_size < ECMA_ITERATOR_INDEX_LIMIT) + { + ext_obj_p->u.cls.u2.iterator_index = (uint16_t) (position + result_size); + } + else + { + ext_obj_p->u.cls.u2.iterator_index = ECMA_ITERATOR_INDEX_LIMIT; + + ecma_string_t *prop_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX); + ecma_op_object_put (obj_p, prop_name_p, ecma_make_length_value (position + result_size), true); + } + + /* 14. */ + ecma_value_t result = ecma_create_iter_result_object (ecma_make_string_value (result_str_p), ECMA_VALUE_FALSE); + ecma_deref_ecma_string (result_str_p); + + return result; +} /* ecma_builtin_string_iterator_prototype_object_next */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_string_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + * routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< + * list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list_p, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_STRING_ITERATOR_PROTOTYPE_OBJECT_NEXT: + { + return ecma_builtin_string_iterator_prototype_object_next (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_string_iterator_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-iterator-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-iterator-prototype.inc.h new file mode 100644 index 0000000..adc799d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-iterator-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %StringIteratorPrototype% built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_STRING_ITERATOR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_BUILTIN_STRING_ITERATOR_PROTOTYPE_OBJECT_NEXT, 0, 0) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp new file mode 100644 index 0000000..668f95e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp @@ -0,0 +1,1541 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtin-regexp.inc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jcontext.h" +#include "jrt-libc-includes.h" +#include "jrt.h" +#include "lit-char-helpers.h" +#include "lit-strings.h" + +#if JERRY_BUILTIN_REGEXP +#include "ecma-regexp-object.h" +#endif /* JERRY_BUILTIN_REGEXP */ + +#if JERRY_BUILTIN_STRING + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_STRING_PROTOTYPE_ROUTINE_START = 0, + /* Note: These 4 routines MUST be in this order */ + ECMA_STRING_PROTOTYPE_TO_STRING, + ECMA_STRING_PROTOTYPE_VALUE_OF, + ECMA_STRING_PROTOTYPE_CHAR_AT, + ECMA_STRING_PROTOTYPE_CHAR_CODE_AT, + + ECMA_STRING_PROTOTYPE_CONCAT, + ECMA_STRING_PROTOTYPE_SLICE, + ECMA_STRING_PROTOTYPE_AT, + + ECMA_STRING_PROTOTYPE_LOCALE_COMPARE, + + ECMA_STRING_PROTOTYPE_MATCH, + ECMA_STRING_PROTOTYPE_REPLACE, + ECMA_STRING_PROTOTYPE_SEARCH, + + ECMA_STRING_PROTOTYPE_SPLIT, + ECMA_STRING_PROTOTYPE_SUBSTRING, + ECMA_STRING_PROTOTYPE_TO_LOWER_CASE, + ECMA_STRING_PROTOTYPE_TO_LOCAL_LOWER_CASE, + ECMA_STRING_PROTOTYPE_TO_UPPER_CASE, + ECMA_STRING_PROTOTYPE_TO_LOCAL_UPPER_CASE, + ECMA_STRING_PROTOTYPE_TRIM, + + ECMA_STRING_PROTOTYPE_SUBSTR, + + ECMA_STRING_PROTOTYPE_REPEAT, + ECMA_STRING_PROTOTYPE_CODE_POINT_AT, + ECMA_STRING_PROTOTYPE_PAD_START, + ECMA_STRING_PROTOTYPE_PAD_END, + /* Note: These 5 routines MUST be in this order */ + ECMA_STRING_PROTOTYPE_LAST_INDEX_OF, + ECMA_STRING_PROTOTYPE_INDEX_OF, + ECMA_STRING_PROTOTYPE_STARTS_WITH, + ECMA_STRING_PROTOTYPE_INCLUDES, + ECMA_STRING_PROTOTYPE_ENDS_WITH, + + ECMA_STRING_PROTOTYPE_ITERATOR, + ECMA_STRING_PROTOTYPE_REPLACE_ALL, + ECMA_STRING_PROTOTYPE_MATCH_ALL, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID string_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup stringprototype ECMA String.prototype object built-in + * @{ + */ + +/** + * The String.prototype object's 'toString' and 'valueOf' routines + * + * See also: + * ECMA-262 v5, 15.5.4.2 + * ECMA-262 v5, 15.5.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_string (this_arg)) + { + return ecma_copy_value (this_arg); + } + + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_STRING)) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (ecma_is_value_string (ext_object_p->u.cls.u3.value)); + + return ecma_copy_value (ext_object_p->u.cls.u3.value); + } + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_STRING_OBJECT); +} /* ecma_builtin_string_prototype_object_to_string */ + +/** + * Helper function for the String.prototype object's 'charAt' and charCodeAt' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_char_at_helper (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arg, /**< routine's argument */ + bool charcode_mode) /**< routine mode */ +{ + /* 3 */ + ecma_number_t index_num; + ecma_value_t to_num_result = ecma_op_to_integer (arg, &index_num); + + if (JERRY_UNLIKELY (!ecma_is_value_empty (to_num_result))) + { + return to_num_result; + } + + /* 2 */ + ecma_string_t *original_string_p = ecma_op_to_string (this_arg); + if (JERRY_UNLIKELY (original_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 4 */ + const lit_utf8_size_t len = ecma_string_get_length (original_string_p); + + /* 5 */ + // When index_num is NaN, then the first two comparisons are false + if (index_num < 0 || index_num >= len || (ecma_number_is_nan (index_num) && len == 0)) + { + ecma_deref_ecma_string (original_string_p); + return (charcode_mode ? ecma_make_nan_value () : ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY)); + } + + /* 6 */ + /* + * String length is currently uint32_t, but index_num may be bigger, + * ToInteger performs floor, while ToUInt32 performs modulo 2^32, + * hence after the check 0 <= index_num < len we assume to_uint32 can be used. + * We assume to_uint32 (NaN) is 0. + */ + JERRY_ASSERT (ecma_number_is_nan (index_num) || ecma_number_to_uint32 (index_num) == ecma_number_trunc (index_num)); + + ecma_char_t new_ecma_char = ecma_string_get_char_at_pos (original_string_p, ecma_number_to_uint32 (index_num)); + ecma_deref_ecma_string (original_string_p); + + return (charcode_mode ? ecma_make_uint32_value (new_ecma_char) + : ecma_make_string_value (ecma_new_ecma_string_from_code_unit (new_ecma_char))); +} /* ecma_builtin_string_prototype_char_at_helper */ + +/** + * The String.prototype object's 'concat' routine + * + * See also: + * ECMA-262 v5, 15.5.4.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_concat (ecma_string_t *this_string_p, /**< this argument */ + const ecma_value_t *argument_list_p, /**< arguments list */ + uint32_t arguments_number) /**< number of arguments */ +{ + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (this_string_p); + + /* 5 */ + for (uint32_t arg_index = 0; arg_index < arguments_number; ++arg_index) + { + /* 5a, b */ + ecma_string_t *get_arg_string_p = ecma_op_to_string (argument_list_p[arg_index]); + + if (JERRY_UNLIKELY (get_arg_string_p == NULL)) + { + ecma_stringbuilder_destroy (&builder); + return ECMA_VALUE_ERROR; + } + + ecma_stringbuilder_append (&builder, get_arg_string_p); + + ecma_deref_ecma_string (get_arg_string_p); + } + + /* 6 */ + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_string_prototype_object_concat */ + +/** + * The String.prototype object's 'localeCompare' routine + * + * See also: + * ECMA-262 v5, 15.5.4.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_locale_compare (ecma_string_t *this_string_p, /**< this argument */ + ecma_value_t arg) /**< routine's argument */ +{ + /* 3. */ + ecma_string_t *arg_string_p = ecma_op_to_string (arg); + + if (JERRY_UNLIKELY (arg_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_number_t result = ECMA_NUMBER_ZERO; + + if (ecma_compare_ecma_strings_relational (this_string_p, arg_string_p)) + { + result = ECMA_NUMBER_MINUS_ONE; + } + else if (!ecma_compare_ecma_strings (this_string_p, arg_string_p)) + { + result = ECMA_NUMBER_ONE; + } + else + { + result = ECMA_NUMBER_ZERO; + } + + ecma_deref_ecma_string (arg_string_p); + + return ecma_make_number_value (result); +} /* ecma_builtin_string_prototype_object_locale_compare */ + +#if JERRY_BUILTIN_REGEXP +/** + * The String.prototype object's 'match' routine + * + * See also: + * ECMA-262 v5, 15.5.4.10 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_match (ecma_value_t this_argument, /**< this argument */ + ecma_value_t regexp_arg) /**< routine's argument */ +{ + /* 3. */ + if (!(ecma_is_value_undefined (regexp_arg) || ecma_is_value_null (regexp_arg))) + { + /* 3.a */ + ecma_value_t matcher = ecma_op_get_method_by_symbol_id (regexp_arg, LIT_GLOBAL_SYMBOL_MATCH); + + /* 3.b */ + if (ECMA_IS_VALUE_ERROR (matcher)) + { + return matcher; + } + + /* 3.c */ + if (!ecma_is_value_undefined (matcher)) + { + /* 3.c.i */ + ecma_object_t *matcher_method = ecma_get_object_from_value (matcher); + ecma_value_t result = ecma_op_function_call (matcher_method, regexp_arg, &this_argument, 1); + ecma_deref_object (matcher_method); + return result; + } + } + + /* 4. */ + ecma_string_t *this_str_p = ecma_op_to_string (this_argument); + + /* 5. */ + if (JERRY_UNLIKELY (this_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 6. */ + ecma_object_t *regexp_obj_p = ecma_op_regexp_alloc (NULL); + + if (JERRY_UNLIKELY (regexp_obj_p == NULL)) + { + ecma_deref_ecma_string (this_str_p); + return ECMA_VALUE_ERROR; + } + + ecma_value_t new_regexp = ecma_op_create_regexp_from_pattern (regexp_obj_p, regexp_arg, ECMA_VALUE_UNDEFINED); + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (new_regexp)) + { + ecma_deref_object (regexp_obj_p); + ecma_deref_ecma_string (this_str_p); + return new_regexp; + } + ecma_value_t this_str_value = ecma_make_string_value (this_str_p); + + /* 8. */ + ecma_value_t ret_value = ecma_op_invoke_by_symbol_id (new_regexp, LIT_GLOBAL_SYMBOL_MATCH, &this_str_value, 1); + + ecma_deref_ecma_string (this_str_p); + ecma_free_value (new_regexp); + + return ret_value; +} /* ecma_builtin_string_prototype_object_match */ + +/** + * The String.prototype object's 'matchAll' routine + * + * See also: + * ECMA-262 v11, 21.1.3.12 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_match_all (ecma_value_t this_argument, /**< this argument */ + ecma_value_t regexp_arg) /**< routine's argument */ +{ + /* 2. */ + if (!ecma_is_value_null (regexp_arg) && !ecma_is_value_undefined (regexp_arg)) + { + /* 2.a */ + ecma_value_t is_regexp = ecma_op_is_regexp (regexp_arg); + + if (ECMA_IS_VALUE_ERROR (is_regexp)) + { + return is_regexp; + } + + /* 2.b */ + if (ecma_is_value_true (is_regexp)) + { + /* 2.b.i */ + ecma_object_t *regexp_obj_p = ecma_get_object_from_value (regexp_arg); + ecma_value_t get_flags = ecma_op_object_get_by_magic_id (regexp_obj_p, LIT_MAGIC_STRING_FLAGS); + + if (ECMA_IS_VALUE_ERROR (get_flags)) + { + return get_flags; + } + + /* 2.b.ii */ + if (!ecma_op_require_object_coercible (get_flags)) + { + ecma_free_value (get_flags); + return ECMA_VALUE_ERROR; + } + + /* 2.b.iii */ + ecma_string_t *flags = ecma_op_to_string (get_flags); + + ecma_free_value (get_flags); + + if (JERRY_UNLIKELY (flags == NULL)) + { + return ECMA_VALUE_ERROR; + } + + uint16_t parsed_flag; + ecma_value_t flag_parse = ecma_regexp_parse_flags (flags, &parsed_flag); + + ecma_deref_ecma_string (flags); + + if (ECMA_IS_VALUE_ERROR (flag_parse)) + { + return flag_parse; + } + + if (!(parsed_flag & RE_FLAG_GLOBAL)) + { + return ecma_raise_type_error (ECMA_ERR_REGEXP_ARGUMENT_SHOULD_HAVE_GLOBAL_FLAG); + } + } + + /* 2.c */ + ecma_value_t matcher = ecma_op_get_method_by_symbol_id (regexp_arg, LIT_GLOBAL_SYMBOL_MATCH_ALL); + + if (ECMA_IS_VALUE_ERROR (matcher)) + { + return matcher; + } + + /* 2.d */ + if (!ecma_is_value_undefined (matcher)) + { + /* 2.d.i */ + ecma_object_t *matcher_method = ecma_get_object_from_value (matcher); + ecma_value_t result = ecma_op_function_call (matcher_method, regexp_arg, &this_argument, 1); + ecma_deref_object (matcher_method); + return result; + } + } + + /* 3. */ + ecma_string_t *str_p = ecma_op_to_string (this_argument); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 4. */ + ecma_object_t *new_regexp_obj_p = ecma_op_regexp_alloc (NULL); + + if (JERRY_UNLIKELY (new_regexp_obj_p == NULL)) + { + ecma_deref_ecma_string (str_p); + return ECMA_VALUE_ERROR; + } + + ecma_value_t new_regexp = ecma_op_create_regexp_from_pattern (new_regexp_obj_p, regexp_arg, ECMA_VALUE_UNDEFINED); + + if (ECMA_IS_VALUE_ERROR (new_regexp)) + { + ecma_deref_ecma_string (str_p); + ecma_deref_object (new_regexp_obj_p); + return new_regexp; + } + + /* 5. */ + ecma_value_t string_arg = ecma_make_string_value (str_p); + ecma_value_t ret_value = ecma_op_invoke_by_symbol_id (new_regexp, LIT_GLOBAL_SYMBOL_MATCH_ALL, &string_arg, 1); + + ecma_deref_ecma_string (str_p); + ecma_free_value (new_regexp); + + return ret_value; +} /* ecma_builtin_string_prototype_object_match_all */ + +/** + * The String.prototype object's 'replace' and 'replaceAll' routine + * + * See also: + * ECMA-262 v5, 15.5.4.11 (replace ES5) + * ECMA-262 v6, 21.1.3.14 (replace ES6) + * ECMA-262 v12, 21.1.3.18 (replaceAll) + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_replace_helper (ecma_value_t this_value, /**< this argument */ + ecma_value_t search_value, /**< routine's first argument */ + ecma_value_t replace_value, /**< routine's second argument */ + bool replace_all) +{ + ecma_string_t *result_string_p; + lit_utf8_byte_t *search_buf_p; + uint8_t search_flags; + uint8_t input_flags; + + if (!(ecma_is_value_undefined (search_value) || ecma_is_value_null (search_value))) + { + if (replace_all) + { + ecma_value_t is_regexp = ecma_op_is_regexp (search_value); + + if (ECMA_IS_VALUE_ERROR (is_regexp)) + { + return is_regexp; + } + + if (ecma_is_value_true (is_regexp)) + { + ecma_object_t *regexp_obj_p = ecma_get_object_from_value (search_value); + ecma_value_t get_flags = ecma_op_object_get_by_magic_id (regexp_obj_p, LIT_MAGIC_STRING_FLAGS); + + if (ECMA_IS_VALUE_ERROR (get_flags)) + { + return get_flags; + } + + if (!ecma_op_require_object_coercible (get_flags)) + { + ecma_free_value (get_flags); + return ECMA_VALUE_ERROR; + } + + ecma_string_t *flags = ecma_op_to_string (get_flags); + + ecma_free_value (get_flags); + + if (JERRY_UNLIKELY (flags == NULL)) + { + return ECMA_VALUE_ERROR; + } + + bool have_global_flag = lit_find_char_in_string (flags, LIT_CHAR_LOWERCASE_G); + + ecma_deref_ecma_string (flags); + + if (!have_global_flag) + { + return ecma_raise_type_error (ECMA_ERR_REGEXP_ARGUMENT_SHOULD_HAVE_GLOBAL_FLAG); + } + } + } + + ecma_object_t *obj_p = ecma_get_object_from_value (ecma_op_to_object (search_value)); + ecma_value_t replace_symbol = ecma_op_object_get_by_symbol_id (obj_p, LIT_GLOBAL_SYMBOL_REPLACE); + ecma_deref_object (obj_p); + + if (ECMA_IS_VALUE_ERROR (replace_symbol)) + { + return replace_symbol; + } + + if (!ecma_is_value_undefined (replace_symbol) && !ecma_is_value_null (replace_symbol)) + { + ecma_value_t arguments[] = { this_value, replace_value }; + ecma_value_t replace_result = ecma_op_function_validated_call (replace_symbol, search_value, arguments, 2); + ecma_free_value (replace_symbol); + + return replace_result; + } + } + + ecma_string_t *input_str_p = ecma_op_to_string (this_value); + + if (input_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ECMA_VALUE_ERROR; + + ecma_string_t *search_str_p = ecma_op_to_string (search_value); + if (search_str_p == NULL) + { + ecma_deref_ecma_string (input_str_p); + return result; + } + + ecma_replace_context_t replace_ctx; + replace_ctx.capture_count = 0; + replace_ctx.u.captures_p = NULL; + + replace_ctx.replace_str_p = NULL; + if (!ecma_op_is_callable (replace_value)) + { + replace_ctx.replace_str_p = ecma_op_to_string (replace_value); + if (replace_ctx.replace_str_p == NULL) + { + goto cleanup_search; + } + } + + input_flags = ECMA_STRING_FLAG_IS_ASCII; + replace_ctx.string_p = ecma_string_get_chars (input_str_p, &(replace_ctx.string_size), NULL, NULL, &input_flags); + + lit_utf8_size_t search_size; + lit_utf8_size_t search_length; + search_flags = ECMA_STRING_FLAG_IS_ASCII; + search_buf_p = (lit_utf8_byte_t *) ecma_string_get_chars (search_str_p, &search_size, &search_length, NULL, &search_flags); + + result_string_p = NULL; + + if (replace_ctx.string_size >= search_size) + { + replace_ctx.builder = ecma_stringbuilder_create (); + replace_ctx.matched_size = search_size; + const lit_utf8_byte_t *const input_end_p = replace_ctx.string_p + replace_ctx.string_size; + const lit_utf8_byte_t *const loop_end_p = input_end_p - search_size; + const lit_utf8_byte_t *last_match_end_p = replace_ctx.string_p; + const lit_utf8_byte_t *curr_p = replace_ctx.string_p; + + lit_utf8_size_t pos = 0; + while (curr_p <= loop_end_p) + { + if (!memcmp (curr_p, search_buf_p, search_size)) + { + const lit_utf8_size_t prefix_size = (lit_utf8_size_t) (curr_p - last_match_end_p); + ecma_stringbuilder_append_raw (&replace_ctx.builder, last_match_end_p, prefix_size); + + last_match_end_p = curr_p + search_size; + + if (replace_ctx.replace_str_p == NULL) + { + ecma_object_t *function_p = ecma_get_object_from_value (replace_value); + + ecma_value_t args[] = { ecma_make_string_value (search_str_p), + ecma_make_uint32_value (pos), + ecma_make_string_value (input_str_p) }; + + result = ecma_op_function_call (function_p, ECMA_VALUE_UNDEFINED, args, 3); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_stringbuilder_destroy (&replace_ctx.builder); + goto cleanup_replace; + } + + ecma_string_t *const result_str_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (result_str_p == NULL) + { + ecma_stringbuilder_destroy (&replace_ctx.builder); + result = ECMA_VALUE_ERROR; + goto cleanup_replace; + } + + ecma_stringbuilder_append (&replace_ctx.builder, result_str_p); + ecma_deref_ecma_string (result_str_p); + } + else + { + replace_ctx.matched_p = curr_p; + replace_ctx.match_byte_pos = (lit_utf8_size_t) (curr_p - replace_ctx.string_p); + + ecma_builtin_replace_substitute (&replace_ctx); + } + + if (!replace_all || last_match_end_p == input_end_p) + { + break; + } + + if (search_size != 0) + { + curr_p = last_match_end_p; + pos += search_length; + continue; + } + } + + pos++; + lit_utf8_incr (&curr_p); + } + + ecma_stringbuilder_append_raw (&replace_ctx.builder, + last_match_end_p, + (lit_utf8_size_t) (input_end_p - last_match_end_p)); + result_string_p = ecma_stringbuilder_finalize (&replace_ctx.builder); + } + + if (result_string_p == NULL) + { + ecma_ref_ecma_string (input_str_p); + result_string_p = input_str_p; + } + + result = ecma_make_string_value (result_string_p); + +cleanup_replace: + if (input_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) replace_ctx.string_p, replace_ctx.string_size); + } + + if (search_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) search_buf_p, search_size); + } + + if (replace_ctx.replace_str_p != NULL) + { + ecma_deref_ecma_string (replace_ctx.replace_str_p); + } + +cleanup_search: + ecma_deref_ecma_string (search_str_p); + ecma_deref_ecma_string (input_str_p); + + return result; +} /* ecma_builtin_string_prototype_object_replace_helper */ + +/** + * The String.prototype object's 'search' routine + * + * See also: + * ECMA-262 v5, 15.5.4.12 + * ECMA-262 v6, 21.1.3.15 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_search (ecma_value_t this_value, /**< this argument */ + ecma_value_t regexp_value) /**< routine's argument */ +{ + if (!(ecma_is_value_undefined (regexp_value) || ecma_is_value_null (regexp_value))) + { + ecma_object_t *obj_p = ecma_get_object_from_value (ecma_op_to_object (regexp_value)); + ecma_value_t search_symbol = ecma_op_object_get_by_symbol_id (obj_p, LIT_GLOBAL_SYMBOL_SEARCH); + ecma_deref_object (obj_p); + + if (ECMA_IS_VALUE_ERROR (search_symbol)) + { + return search_symbol; + } + + if (!ecma_is_value_undefined (search_symbol) && !ecma_is_value_null (search_symbol)) + { + ecma_value_t search_result = ecma_op_function_validated_call (search_symbol, regexp_value, &this_value, 1); + ecma_free_value (search_symbol); + return search_result; + } + } + + ecma_value_t result = ECMA_VALUE_ERROR; + + ecma_string_t *string_p = ecma_op_to_string (this_value); + if (string_p == NULL) + { + return result; + } + + ecma_string_t *pattern_p = ecma_regexp_read_pattern_str_helper (regexp_value); + if (pattern_p == NULL) + { + ecma_deref_ecma_string (string_p); + return result; + } + + ecma_object_t *new_regexp_obj_p = ecma_op_regexp_alloc (NULL); + + if (JERRY_UNLIKELY (new_regexp_obj_p == NULL)) + { + ecma_deref_ecma_string (string_p); + ecma_deref_ecma_string (pattern_p); + return result; + } + + ecma_value_t new_regexp = + ecma_op_create_regexp_from_pattern (new_regexp_obj_p, ecma_make_string_value (pattern_p), ECMA_VALUE_UNDEFINED); + + ecma_deref_ecma_string (pattern_p); + + if (ECMA_IS_VALUE_ERROR (new_regexp)) + { + ecma_deref_ecma_string (string_p); + ecma_deref_object (new_regexp_obj_p); + return result; + } + + ecma_object_t *regexp_obj_p = ecma_get_object_from_value (new_regexp); + ecma_value_t this_str_value = ecma_make_string_value (string_p); + result = ecma_op_invoke_by_symbol_id (new_regexp, LIT_GLOBAL_SYMBOL_SEARCH, &this_str_value, 1); + ecma_deref_object (regexp_obj_p); + ecma_deref_ecma_string (string_p); + + return result; +} /* ecma_builtin_string_prototype_object_search */ + +#endif /* JERRY_BUILTIN_REGEXP */ + +/** + * The String.prototype object's 'slice' routine + * + * See also: + * ECMA-262 v5, 15.5.4.13 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_slice (ecma_string_t *get_string_val, /**< this argument */ + ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + const lit_utf8_size_t len = ecma_string_get_length (get_string_val); + + /* 4. 6. */ + lit_utf8_size_t start = 0, end = len; + + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (arg1, len, &start))) + { + return ECMA_VALUE_ERROR; + } + + /* 5. 7. */ + if (ecma_is_value_undefined (arg2)) + { + end = len; + } + else + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (arg2, len, &end))) + { + return ECMA_VALUE_ERROR; + } + } + + JERRY_ASSERT (start <= len && end <= len); + + /* 8-9. */ + ecma_string_t *new_str_p = ecma_string_substr (get_string_val, start, end); + + return ecma_make_string_value (new_str_p); +} /* ecma_builtin_string_prototype_object_slice */ + +/** + * The String.prototype object's 'at' routine + * + * See also: + * ECMA-262 Stage 3 Draft Relative Indexing Method proposal + * from: https://tc39.es/proposal-relative-indexing-method + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_at (ecma_string_t *string_val, /**< this argument */ + const ecma_value_t index) /**< index argument */ +{ + ecma_length_t len = (ecma_length_t) ecma_string_get_length (string_val); + ecma_length_t res_index; + ecma_value_t return_value = ecma_builtin_helper_calculate_index (index, len, &res_index); + + if (return_value != ECMA_VALUE_EMPTY) + { + return return_value; + } + + ecma_char_t character = ecma_string_get_char_at_pos (string_val, (lit_utf8_size_t) res_index); + + return ecma_make_string_value (ecma_new_ecma_string_from_code_unit (character)); +} /* ecma_builtin_string_prototype_object_at */ + +/** + * The String.prototype object's 'split' routine + * + * See also: + * ECMA-262 v5, 15.5.4.14 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_split (ecma_value_t this_value, /**< this argument */ + ecma_value_t separator_value, /**< separator */ + ecma_value_t limit_value) /**< limit */ +{ + if (!(ecma_is_value_undefined (separator_value) || ecma_is_value_null (separator_value))) + { + ecma_object_t *obj_p = ecma_get_object_from_value (ecma_op_to_object (separator_value)); + ecma_value_t split_symbol = ecma_op_object_get_by_symbol_id (obj_p, LIT_GLOBAL_SYMBOL_SPLIT); + ecma_deref_object (obj_p); + + if (ECMA_IS_VALUE_ERROR (split_symbol)) + { + return split_symbol; + } + + if (!ecma_is_value_undefined (split_symbol) && !ecma_is_value_null (split_symbol)) + { + ecma_value_t arguments[] = { this_value, limit_value }; + ecma_value_t split_result = ecma_op_function_validated_call (split_symbol, separator_value, arguments, 2); + ecma_free_value (split_symbol); + + return split_result; + } + } + + ecma_value_t result = ECMA_VALUE_ERROR; + ecma_string_t *end_substr_p; + + lit_utf8_size_t string_size; + uint8_t string_flags; + lit_utf8_byte_t *string_buffer_p; + lit_utf8_size_t separator_size; + uint8_t separator_flags; + lit_utf8_byte_t *separator_buffer_p; + + lit_utf8_byte_t *string_end_p; + lit_utf8_byte_t *compare_end_p; + const lit_utf8_byte_t *current_p; + const lit_utf8_byte_t *last_str_begin_p; + + lit_utf8_size_t array_length; + + uint32_t limit; + + ecma_string_t *separator_p; + ecma_object_t *array_p; + + /* 4. */ + ecma_string_t *string_p = ecma_op_to_string (this_value); + if (string_p == NULL) + { + return result; + } + + /* 8. */ + limit = UINT32_MAX - 1; + + if (!ecma_is_value_undefined (limit_value)) + { + /* ECMA-262 v11, 21.1.3.20 6 */ + ecma_number_t num; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (limit_value, &num))) + { + goto cleanup_string; + } + limit = ecma_number_to_uint32 (num); + } + + /* 12. */ + separator_p = ecma_op_to_string (separator_value); + if (separator_p == NULL) + { + goto cleanup_string; + } + + /* 6. */ + array_p = ecma_op_new_array_object (0); + result = ecma_make_object_value (array_p); + + /* 14. */ + if (limit == 0) + { + goto cleanup_separator; + } + + /* 6. */ + array_length = 0; + + /* 15. */ + if (ecma_is_value_undefined (separator_value)) + { + ecma_builtin_helper_def_prop_by_index (array_p, array_length, ecma_make_string_value (string_p), ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + goto cleanup_separator; + } + + /* 16. */ + if (ecma_string_is_empty (string_p)) + { + if (!ecma_string_is_empty (separator_p)) + { + ecma_builtin_helper_def_prop_by_index (array_p, array_length, ecma_make_string_value (string_p), ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + } + goto cleanup_separator; + } + + string_flags = ECMA_STRING_FLAG_IS_ASCII; + string_buffer_p = (lit_utf8_byte_t *) ecma_string_get_chars (string_p, &string_size, NULL, NULL, &string_flags); + separator_flags = ECMA_STRING_FLAG_IS_ASCII; + separator_buffer_p = (lit_utf8_byte_t *) ecma_string_get_chars (separator_p, &separator_size, NULL, NULL, &separator_flags); + + string_end_p = string_buffer_p + string_size; + compare_end_p = JERRY_MIN (string_end_p - separator_size + 1, string_end_p); + current_p = string_buffer_p; + last_str_begin_p = string_buffer_p; + + while (current_p < compare_end_p) + { + if (!memcmp (current_p, separator_buffer_p, separator_size) && (last_str_begin_p != current_p + separator_size)) + { + auto substr_p = ecma_new_ecma_string_from_utf8 (last_str_begin_p, (lit_utf8_size_t) (current_p - last_str_begin_p)); + ecma_builtin_helper_def_prop_by_index (array_p, array_length++, ecma_make_string_value (substr_p), ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_deref_ecma_string (substr_p); + + if (array_length >= limit) + { + goto cleanup_buffers; + } + + current_p += separator_size; + last_str_begin_p = current_p; + continue; + } + + lit_utf8_incr (¤t_p); + } + + end_substr_p = ecma_new_ecma_string_from_utf8 (last_str_begin_p, (lit_utf8_size_t) (string_end_p - last_str_begin_p)); + ecma_builtin_helper_def_prop_by_index (array_p, array_length, ecma_make_string_value (end_substr_p), ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_deref_ecma_string (end_substr_p); + +cleanup_buffers: + if (string_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) string_buffer_p, string_size); + } + + if (separator_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) separator_buffer_p, separator_size); + } + +cleanup_separator: + ecma_deref_ecma_string (separator_p); +cleanup_string: + ecma_deref_ecma_string (string_p); + return result; +} /* ecma_builtin_string_prototype_object_split */ + +/** + * The String.prototype object's 'substring' routine + * + * See also: + * ECMA-262 v5, 15.5.4.15 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_substring (ecma_string_t *original_string_p, /**< this argument */ + ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + /* 3 */ + const lit_utf8_size_t len = ecma_string_get_length (original_string_p); + lit_utf8_size_t start = 0, end = len; + + /* 4 */ + ecma_number_t start_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg1, &start_num))) + { + return ECMA_VALUE_ERROR; + } + + /* 6 */ + start = (uint32_t) JERRY_MIN (JERRY_MAX (start_num, 0), len); + + /* 5 */ + if (ecma_is_value_undefined (arg2)) + { + end = len; + } + else + { + /* 5 part 2 */ + ecma_number_t end_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arg2, &end_num))) + { + return ECMA_VALUE_ERROR; + } + /* 7 */ + end = (uint32_t) JERRY_MIN (JERRY_MAX (end_num, 0), len); + } + + JERRY_ASSERT (start <= len && end <= len); + + /* 8 */ + uint32_t from = start < end ? start : end; + + /* 9 */ + uint32_t to = start > end ? start : end; + + /* 10 */ + ecma_string_t *new_str_p = ecma_string_substr (original_string_p, from, to); + return ecma_make_string_value (new_str_p); +} /* ecma_builtin_string_prototype_object_substring */ + +/** + * The common implementation of the String.prototype object's + * 'toLowerCase', 'toLocaleLowerCase', 'toUpperCase', 'toLocalUpperCase' routines + * + * See also: + * ECMA-262 v5, 15.5.4.16 + * ECMA-262 v5, 15.5.4.17 + * ECMA-262 v5, 15.5.4.18 + * ECMA-262 v5, 15.5.4.19 + * + * Helper function to convert a string to upper or lower case. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_conversion_helper (ecma_string_t *input_string_p, /**< this argument */ + bool lower_case) /**< convert to lower (true) + * or upper (false) case */ +{ + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + ECMA_STRING_TO_UTF8_STRING (input_string_p, input_start_p, input_start_size); + + const lit_utf8_byte_t *input_curr_p = input_start_p; + const lit_utf8_byte_t *input_str_end_p = input_start_p + input_start_size; + + while (input_curr_p < input_str_end_p) + { + lit_code_point_t cp = lit_cesu8_read_next (&input_curr_p); + + if (lit_is_code_point_utf16_high_surrogate (cp) && input_curr_p < input_str_end_p) + { + const ecma_char_t next_ch = lit_cesu8_peek_next (input_curr_p); + if (lit_is_code_point_utf16_low_surrogate (next_ch)) + { + cp = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) cp, next_ch); + input_curr_p += LIT_UTF8_MAX_BYTES_IN_CODE_UNIT; + } + } + + if (lower_case) + { + lit_char_to_lower_case (cp, &builder); + } + else + { + lit_char_to_upper_case (cp, &builder); + } + } + + ECMA_FINALIZE_UTF8_STRING (input_start_p, input_start_size); + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_string_prototype_object_conversion_helper */ + +/** + * The String.prototype object's 'trim' routine + * + * See also: + * ECMA-262 v5, 15.5.4.20 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_trim (ecma_string_t *original_string_p) /**< this argument */ +{ + ecma_string_t *trimmed_string_p = ecma_string_trim (original_string_p); + + return ecma_make_string_value (trimmed_string_p); +} /* ecma_builtin_string_prototype_object_trim */ + +/** + * The String.prototype object's 'repeat' routine + * + * See also: + * ECMA-262 v6, 21.1.3.13 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_repeat (ecma_string_t *original_string_p, /**< this argument */ + ecma_value_t repeat) /**< times to repeat */ +{ + ecma_string_t *ret_string_p; + + /* 4 */ + ecma_number_t count_number; + ecma_value_t count_value = ecma_op_to_integer (repeat, &count_number); + + /* 5 */ + if (ECMA_IS_VALUE_ERROR (count_value)) + { + return count_value; + } + + int32_t repeat_count = ecma_number_to_int32 (count_number); + + bool isNan = ecma_number_is_nan (count_number); + + /* 6, 7 */ + if (count_number < 0 || (!isNan && ecma_number_is_infinity (count_number))) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_COUNT_VALUE); + } + + lit_utf8_size_t size = ecma_string_get_size (original_string_p); + + if (repeat_count == 0 || size == 0 || isNan) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + if ((uint32_t) repeat_count >= (ECMA_STRING_SIZE_LIMIT / size)) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_STRING_); + } + + lit_utf8_size_t total_size = size * (lit_utf8_size_t) repeat_count; + + JMEM_DEFINE_LOCAL_ARRAY (str_buffer, total_size, lit_utf8_byte_t); + + ecma_string_to_cesu8_bytes (original_string_p, str_buffer, size); + lit_utf8_byte_t *buffer_ptr = str_buffer + size; + + for (int32_t n = 1; n < repeat_count; n++) + { + memcpy (buffer_ptr, str_buffer, size); + buffer_ptr += size; + } + + ret_string_p = ecma_new_ecma_string_from_utf8 (str_buffer, (lit_utf8_size_t) (buffer_ptr - str_buffer)); + JMEM_FINALIZE_LOCAL_ARRAY (str_buffer); + + return ecma_make_string_value (ret_string_p); +} /* ecma_builtin_string_prototype_object_repeat */ + +/** + * The String.prototype object's 'codePointAt' routine + * + * See also: + * ECMA-262 v6, 21.1.3.3 + * + * @return lit_code_point_t + */ +static ecma_value_t +ecma_builtin_string_prototype_object_code_point_at (ecma_string_t *this_string_p, /**< this argument */ + ecma_value_t pos) /**< given position */ +{ + ecma_number_t pos_num; + ecma_value_t error = ecma_op_to_integer (pos, &pos_num); + + if (ECMA_IS_VALUE_ERROR (error)) + { + return error; + } + + lit_utf8_size_t length = ecma_string_get_length (this_string_p); + + if (pos_num < 0 || pos_num >= length) + { + return ECMA_VALUE_UNDEFINED; + } + + uint32_t index = (uint32_t) pos_num; + + ecma_char_t first = ecma_string_get_char_at_pos (this_string_p, index); + + if (first < LIT_UTF16_HIGH_SURROGATE_MIN || first > LIT_UTF16_HIGH_SURROGATE_MAX || index + 1 == length) + { + return ecma_make_uint32_value (first); + } + + ecma_char_t second = ecma_string_get_char_at_pos (this_string_p, index + 1); + + if (second < LIT_UTF16_LOW_SURROGATE_MARKER || second > LIT_UTF16_LOW_SURROGATE_MAX) + { + return ecma_make_uint32_value (first); + } + + return ecma_make_uint32_value (lit_convert_surrogate_pair_to_code_point (first, second)); +} /* ecma_builtin_string_prototype_object_code_point_at */ + +#if JERRY_BUILTIN_ANNEXB + +/** + * The String.prototype object's 'substr' routine + * + * See also: + * ECMA-262 v5, B.2.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_substr (ecma_string_t *this_string_p, /**< this argument */ + ecma_value_t start, /**< routine's first argument */ + ecma_value_t length) /**< routine's second argument */ +{ + /* 2. */ + ecma_number_t start_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (start, &start_num))) + { + return ECMA_VALUE_ERROR; + } + + /* 3. */ + ecma_number_t length_num = ecma_number_make_infinity (false); + + if (!ecma_is_value_undefined (length)) + { + ecma_number_t len; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (length, &len))) + { + return ECMA_VALUE_ERROR; + } + + length_num = ecma_number_is_nan (len) ? 0 : len; + } + + /* 4. */ + lit_utf8_size_t this_len = ecma_string_get_length (this_string_p); + + /* 5. */ + uint32_t from = (uint32_t) ((start_num < 0) ? JERRY_MAX (this_len + start_num, 0) : start_num); + + if (from > this_len) + { + from = this_len; + } + + /* 6. */ + ecma_number_t to_num = JERRY_MIN (JERRY_MAX (length_num, 0), this_len - from); + + /* 7. */ + uint32_t to = from + (uint32_t) to_num; + + /* 8. */ + ecma_string_t *new_str_p = ecma_string_substr (this_string_p, from, to); + return ecma_make_string_value (new_str_p); +} /* ecma_builtin_string_prototype_object_substr */ + +#endif /* JERRY_BUILTIN_ANNEXB */ + +/** + * The String.prototype object's @@iterator routine + * + * See also: + * ECMA-262 v6, 21.1.3.27 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_prototype_object_iterator (ecma_value_t to_string) /**< this argument */ +{ + return ecma_op_create_iterator_object (ecma_copy_value (to_string), + ecma_builtin_get (ECMA_BUILTIN_ID_STRING_ITERATOR_PROTOTYPE), + ECMA_OBJECT_CLASS_STRING_ITERATOR, + ECMA_ITERATOR_VALUES); +} /* ecma_builtin_string_prototype_object_iterator */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_string_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + if (builtin_routine_id <= ECMA_STRING_PROTOTYPE_VALUE_OF) + { + return ecma_builtin_string_prototype_object_to_string (this_arg); + } + + if (!ecma_op_require_object_coercible (this_arg)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t arg1 = arguments_list_p[0]; + ecma_value_t arg2 = arguments_list_p[1]; + +#if JERRY_BUILTIN_REGEXP + if (builtin_routine_id == ECMA_STRING_PROTOTYPE_MATCH) + { + return ecma_builtin_string_prototype_object_match (this_arg, arg1); + } + + if (builtin_routine_id == ECMA_STRING_PROTOTYPE_MATCH_ALL) + { + return ecma_builtin_string_prototype_object_match_all (this_arg, arg1); + } +#endif /* JERRY_BUILTIN_REGEXP */ + + if (builtin_routine_id <= ECMA_STRING_PROTOTYPE_CHAR_CODE_AT) + { + return ecma_builtin_string_prototype_char_at_helper (this_arg, + arg1, + builtin_routine_id == ECMA_STRING_PROTOTYPE_CHAR_CODE_AT); + } + +#if JERRY_BUILTIN_REGEXP + if (builtin_routine_id == ECMA_STRING_PROTOTYPE_REPLACE) + { + return ecma_builtin_string_prototype_object_replace_helper (this_arg, arg1, arg2, false); + } + + else if (builtin_routine_id == ECMA_STRING_PROTOTYPE_REPLACE_ALL) + { + return ecma_builtin_string_prototype_object_replace_helper (this_arg, arg1, arg2, true); + } +#endif /* JERRY_BUILTIN_REGEXP */ + + ecma_string_t *string_p = ecma_op_to_string (this_arg); + + if (JERRY_UNLIKELY (string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t to_string_val = ecma_make_string_value (string_p); + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + switch (builtin_routine_id) + { + case ECMA_STRING_PROTOTYPE_CONCAT: + { + ret_value = ecma_builtin_string_prototype_object_concat (string_p, arguments_list_p, arguments_number); + break; + } + case ECMA_STRING_PROTOTYPE_SLICE: + { + ret_value = ecma_builtin_string_prototype_object_slice (string_p, arg1, arg2); + break; + } + case ECMA_STRING_PROTOTYPE_AT: + { + ret_value = ecma_builtin_string_prototype_object_at (string_p, arg1); + break; + } + case ECMA_STRING_PROTOTYPE_LAST_INDEX_OF: + case ECMA_STRING_PROTOTYPE_INDEX_OF: + case ECMA_STRING_PROTOTYPE_STARTS_WITH: + case ECMA_STRING_PROTOTYPE_INCLUDES: + case ECMA_STRING_PROTOTYPE_ENDS_WITH: + { + ecma_string_index_of_mode_t mode; + mode = (ecma_string_index_of_mode_t) (builtin_routine_id - ECMA_STRING_PROTOTYPE_LAST_INDEX_OF); + ret_value = ecma_builtin_helper_string_prototype_object_index_of (string_p, arg1, arg2, mode); + break; + } + case ECMA_STRING_PROTOTYPE_LOCALE_COMPARE: + { + ret_value = ecma_builtin_string_prototype_object_locale_compare (string_p, arg1); + break; + } +#if JERRY_BUILTIN_REGEXP + case ECMA_STRING_PROTOTYPE_SEARCH: + { + ret_value = ecma_builtin_string_prototype_object_search (to_string_val, arg1); + break; + } +#endif /* JERRY_BUILTIN_REGEXP */ + case ECMA_STRING_PROTOTYPE_SPLIT: + { + ret_value = ecma_builtin_string_prototype_object_split (to_string_val, arg1, arg2); + break; + } + case ECMA_STRING_PROTOTYPE_SUBSTRING: + { + ret_value = ecma_builtin_string_prototype_object_substring (string_p, arg1, arg2); + break; + } + case ECMA_STRING_PROTOTYPE_TO_LOWER_CASE: + case ECMA_STRING_PROTOTYPE_TO_LOCAL_LOWER_CASE: + case ECMA_STRING_PROTOTYPE_TO_UPPER_CASE: + case ECMA_STRING_PROTOTYPE_TO_LOCAL_UPPER_CASE: + { + bool is_lower_case = builtin_routine_id <= ECMA_STRING_PROTOTYPE_TO_LOCAL_LOWER_CASE; + ret_value = ecma_builtin_string_prototype_object_conversion_helper (string_p, is_lower_case); + break; + } + case ECMA_STRING_PROTOTYPE_TRIM: + { + ret_value = ecma_builtin_string_prototype_object_trim (string_p); + break; + } +#if JERRY_BUILTIN_ANNEXB + case ECMA_STRING_PROTOTYPE_SUBSTR: + { + ret_value = ecma_builtin_string_prototype_object_substr (string_p, arg1, arg2); + break; + } +#endif /* JERRY_BUILTIN_ANNEXB */ + case ECMA_STRING_PROTOTYPE_REPEAT: + { + ret_value = ecma_builtin_string_prototype_object_repeat (string_p, arg1); + break; + } + case ECMA_STRING_PROTOTYPE_CODE_POINT_AT: + { + ret_value = ecma_builtin_string_prototype_object_code_point_at (string_p, arg1); + break; + } + case ECMA_STRING_PROTOTYPE_ITERATOR: + { + ret_value = ecma_builtin_string_prototype_object_iterator (to_string_val); + break; + } + case ECMA_STRING_PROTOTYPE_PAD_END: + case ECMA_STRING_PROTOTYPE_PAD_START: + { + ret_value = ecma_string_pad (to_string_val, arg1, arg2, builtin_routine_id == ECMA_STRING_PROTOTYPE_PAD_START); + break; + } + default: + { + JERRY_UNREACHABLE (); + } + } + + ecma_deref_ecma_string (string_p); + + return ret_value; +} /* ecma_builtin_string_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_STRING */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h new file mode 100644 index 0000000..3e54d26 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h @@ -0,0 +1,85 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * String.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_STRING + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.5.4.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_STRING, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Number properties: + * (property name, number value) */ + +/* ECMA-262 v5, 15.5.4 (String.prototype is itself a String object whose value is an empty String), 15.5.5.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FIXED) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_STRING_PROTOTYPE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_STRING_PROTOTYPE_VALUE_OF, 0, 0) +ROUTINE (LIT_MAGIC_STRING_CONCAT, ECMA_STRING_PROTOTYPE_CONCAT, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_STRING_PROTOTYPE_SLICE, 2, 2) +ROUTINE (LIT_MAGIC_STRING_AT, ECMA_STRING_PROTOTYPE_AT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ECMA_STRING_PROTOTYPE_INDEX_OF, 2, 1) +ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ECMA_STRING_PROTOTYPE_LAST_INDEX_OF, 2, 1) +ROUTINE (LIT_MAGIC_STRING_CHAR_AT_UL, ECMA_STRING_PROTOTYPE_CHAR_AT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_CHAR_CODE_AT_UL, ECMA_STRING_PROTOTYPE_CHAR_CODE_AT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_LOCALE_COMPARE_UL, ECMA_STRING_PROTOTYPE_LOCALE_COMPARE, 1, 1) + +#if JERRY_BUILTIN_REGEXP +ROUTINE (LIT_MAGIC_STRING_MATCH, ECMA_STRING_PROTOTYPE_MATCH, 1, 1) +ROUTINE (LIT_MAGIC_STRING_REPLACE, ECMA_STRING_PROTOTYPE_REPLACE, 2, 2) +ROUTINE (LIT_MAGIC_STRING_REPLACE_ALL, ECMA_STRING_PROTOTYPE_REPLACE_ALL, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SEARCH, ECMA_STRING_PROTOTYPE_SEARCH, 1, 1) +#endif /* JERRY_BUILTIN_REGEXP */ + +ROUTINE (LIT_MAGIC_STRING_SPLIT, ECMA_STRING_PROTOTYPE_SPLIT, 2, 2) +ROUTINE (LIT_MAGIC_STRING_SUBSTRING, ECMA_STRING_PROTOTYPE_SUBSTRING, 2, 2) +ROUTINE (LIT_MAGIC_STRING_TO_LOWER_CASE_UL, ECMA_STRING_PROTOTYPE_TO_LOWER_CASE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, ECMA_STRING_PROTOTYPE_TO_LOCAL_LOWER_CASE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_UPPER_CASE_UL, ECMA_STRING_PROTOTYPE_TO_UPPER_CASE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, ECMA_STRING_PROTOTYPE_TO_LOCAL_UPPER_CASE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_TRIM, ECMA_STRING_PROTOTYPE_TRIM, 0, 0) + +#if JERRY_BUILTIN_ANNEXB +ROUTINE (LIT_MAGIC_STRING_SUBSTR, ECMA_STRING_PROTOTYPE_SUBSTR, 2, 2) +#endif /* JERRY_BUILTIN_ANNEXB */ + +ROUTINE (LIT_MAGIC_STRING_REPEAT, ECMA_STRING_PROTOTYPE_REPEAT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_STARTS_WITH, ECMA_STRING_PROTOTYPE_STARTS_WITH, 2, 1) +ROUTINE (LIT_MAGIC_STRING_INCLUDES, ECMA_STRING_PROTOTYPE_INCLUDES, 2, 1) +ROUTINE (LIT_MAGIC_STRING_ENDS_WITH, ECMA_STRING_PROTOTYPE_ENDS_WITH, 2, 1) +ROUTINE (LIT_MAGIC_STRING_CODE_POINT_AT, ECMA_STRING_PROTOTYPE_CODE_POINT_AT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_PAD_START, ECMA_STRING_PROTOTYPE_PAD_START, 2, 1) +ROUTINE (LIT_MAGIC_STRING_PAD_END, ECMA_STRING_PROTOTYPE_PAD_END, 2, 1) +ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ECMA_STRING_PROTOTYPE_ITERATOR, 0, 0) +ROUTINE (LIT_MAGIC_STRING_MATCH_ALL, ECMA_STRING_PROTOTYPE_MATCH_ALL, 1, 1) + +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TRIM_START, LIT_MAGIC_STRING_TRIM_START, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TRIM_LEFT, LIT_MAGIC_STRING_TRIM_START, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TRIM_END, LIT_MAGIC_STRING_TRIM_END, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TRIM_RIGHT, LIT_MAGIC_STRING_TRIM_END, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_STRING */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.cpp new file mode 100644 index 0000000..0da8ee1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.cpp @@ -0,0 +1,430 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" +#include "ecma-symbol-object.h" + +#include "jrt.h" +#include "lit-strings.h" + +#if JERRY_BUILTIN_STRING + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_STRING_ROUTINE_START = 0, + ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE, + ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT, + ECMA_BUILTIN_STRING_OBJECT_RAW, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string.inc.h" +#define BUILTIN_UNDERSCORED_ID string +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup string ECMA String object built-in + * @{ + */ + +/** + * The String object's 'fromCharCode' routine + * + * See also: + * ECMA-262 v5, 15.5.3.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_object_from_char_code (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (args_number == 0) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + lit_utf8_size_t utf8_buf_size = args_number * LIT_CESU8_MAX_BYTES_IN_CODE_UNIT; + ecma_string_t *ret_string_p = NULL; + bool isError = false; + + JMEM_DEFINE_LOCAL_ARRAY (utf8_buf_p, utf8_buf_size, lit_utf8_byte_t); + + lit_utf8_size_t utf8_buf_used = 0; + + for (uint32_t arg_index = 0; arg_index < args_number; arg_index++) + { + ecma_number_t arg_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (args[arg_index], &arg_num))) + { + isError = true; + break; + } + + uint32_t uint32_char_code = ecma_number_to_uint32 (arg_num); + ecma_char_t code_unit = (uint16_t) uint32_char_code; + + JERRY_ASSERT (utf8_buf_used <= utf8_buf_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT); + utf8_buf_used += lit_code_unit_to_utf8 (code_unit, utf8_buf_p + utf8_buf_used); + JERRY_ASSERT (utf8_buf_used <= utf8_buf_size); + } + + if (!isError) + { + ret_string_p = ecma_new_ecma_string_from_utf8 (utf8_buf_p, utf8_buf_used); + } + + JMEM_FINALIZE_LOCAL_ARRAY (utf8_buf_p); + + return isError ? ECMA_VALUE_ERROR : ecma_make_string_value (ret_string_p); +} /* ecma_builtin_string_object_from_char_code */ + +/** + * The String object's 'raw' routine + * + * See also: + * ECMA-262 v6, 21.1.2.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_object_raw (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + /* 1 - 2. */ + const ecma_value_t *substitutions; + uint32_t number_of_substitutions; + ecma_length_t next_index; + ecma_stringbuilder_t builder; + + if (args_number > 1) + { + substitutions = args + 1; + number_of_substitutions = args_number - 1; + } + else + { + substitutions = NULL; + number_of_substitutions = 0; + } + + /* 3. */ + ecma_value_t templated = args_number > 0 ? args[0] : ECMA_VALUE_UNDEFINED; + + ecma_value_t cooked = ecma_op_to_object (templated); + + /* 4. */ + if (ECMA_IS_VALUE_ERROR (cooked)) + { + return cooked; + } + + ecma_object_t *cooked_obj_p = ecma_get_object_from_value (cooked); + + /* 5. */ + ecma_value_t raw = ecma_op_object_get_by_magic_id (cooked_obj_p, LIT_MAGIC_STRING_RAW); + + ecma_deref_object (cooked_obj_p); + + if (ECMA_IS_VALUE_ERROR (raw)) + { + return raw; + } + + ecma_value_t raw_obj = ecma_op_to_object (raw); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (raw_obj)) + { + ecma_free_value (raw); + return raw_obj; + } + + ecma_object_t *raw_obj_p = ecma_get_object_from_value (raw_obj); + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + + /* 7 - 8. */ + ecma_length_t literal_segments; + if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (raw_obj_p, &literal_segments))) + { + goto cleanup; + } + + /* 9. */ + if (literal_segments == 0) + { + ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + goto cleanup; + } + + /* 10. */ + builder = ecma_stringbuilder_create (); + + /* 11. */ + next_index = 0; + + /* 12. */ + while (true) + { + /* 12.a,b */ + ecma_value_t next_seg = ecma_op_object_get_by_index (raw_obj_p, next_index); + + if (ECMA_IS_VALUE_ERROR (next_seg)) + { + goto builder_cleanup; + } + + ecma_string_t *next_seg_srt_p = ecma_op_to_string (next_seg); + + /* 12.c */ + if (JERRY_UNLIKELY (next_seg_srt_p == NULL)) + { + ecma_free_value (next_seg); + goto builder_cleanup; + } + + /* 12.d */ + ecma_stringbuilder_append (&builder, next_seg_srt_p); + + ecma_deref_ecma_string (next_seg_srt_p); + ecma_free_value (next_seg); + + /* 12.e */ + if (next_index + 1 == literal_segments) + { + ret_value = ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); + goto cleanup; + } + + /* 12.f-g */ + if (next_index >= number_of_substitutions) + { + next_index++; + continue; + } + + /* 12.h */ + ecma_string_t *next_sub_p = ecma_op_to_string (substitutions[next_index]); + + /* 12.i */ + if (JERRY_UNLIKELY (next_sub_p == NULL)) + { + goto builder_cleanup; + } + + /* 12.j */ + ecma_stringbuilder_append (&builder, next_sub_p); + ecma_deref_ecma_string (next_sub_p); + + /* 12.k */ + next_index++; + } + +builder_cleanup: + ecma_stringbuilder_destroy (&builder); + +cleanup: + ecma_deref_object (raw_obj_p); + ecma_free_value (raw); + + return ret_value; +} /* ecma_builtin_string_object_raw */ + +/** + * The String object's 'fromCodePoint' routine + * + * See also: + * ECMA-262 v6, 21.1.2.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_string_object_from_code_point (const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (args_number == 0) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + for (uint32_t index = 0; index < args_number; index++) + { + ecma_number_t to_number_num; + ecma_value_t to_number_value = ecma_op_to_number (args[index], &to_number_num); + + if (ECMA_IS_VALUE_ERROR (to_number_value)) + { + ecma_stringbuilder_destroy (&builder); + return to_number_value; + } + + if (!ecma_op_is_integer (to_number_num)) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_range_error (ECMA_ERR_INVALID_CODE_POINT_ERROR); + } + + ecma_free_value (to_number_value); + + if (to_number_num < 0 || to_number_num > LIT_UNICODE_CODE_POINT_MAX) + { + ecma_stringbuilder_destroy (&builder); + return ecma_raise_range_error (ECMA_ERR_INVALID_CODE_POINT); + } + + lit_code_point_t code_point = (lit_code_point_t) to_number_num; + + ecma_char_t converted_cp[2]; + uint8_t encoded_size = lit_utf16_encode_code_point (code_point, converted_cp); + + for (uint8_t i = 0; i < encoded_size; i++) + { + ecma_stringbuilder_append_char (&builder, converted_cp[i]); + } + } + + ecma_string_t *ret_str_p = ecma_stringbuilder_finalize (&builder); + + return ecma_make_string_value (ret_str_p); +} /* ecma_builtin_string_object_from_code_point */ + +/** + * Handle calling [[Call]] of built-in String object + * + * See also: + * ECMA-262 v6, 21.1.1.1 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_string_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + /* 1. */ + if (arguments_list_len == 0) + { + ret_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + /* 2.a */ + else if (ecma_is_value_symbol (arguments_list_p[0])) + { + ret_value = ecma_get_symbol_descriptive_string (arguments_list_p[0]); + } + /* 2.b */ + else + { + ecma_string_t *str_p = ecma_op_to_string (arguments_list_p[0]); + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ret_value = ecma_make_string_value (str_p); + } + + return ret_value; +} /* ecma_builtin_string_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in String object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_string_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_string_object (arguments_list_p, arguments_list_len); +} /* ecma_builtin_string_dispatch_construct */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_string_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (this_arg); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE: + { + return ecma_builtin_string_object_from_char_code (arguments_list_p, arguments_number); + } + case ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT: + { + return ecma_builtin_string_object_from_code_point (arguments_list_p, arguments_number); + } + case ECMA_BUILTIN_STRING_OBJECT_RAW: + { + return ecma_builtin_string_object_raw (arguments_list_p, arguments_number); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_string_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_STRING */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h new file mode 100644 index 0000000..2178acf --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h @@ -0,0 +1,44 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * String built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_STRING + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.7.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_STRING_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_STRING_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_FROM_CODE_POINT_UL, ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_RAW, ECMA_BUILTIN_STRING_OBJECT_RAW, NON_FIXED, 1) + +#endif /* JERRY_BUILTIN_STRING */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.cpp new file mode 100644 index 0000000..df4c9d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.cpp @@ -0,0 +1,111 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-symbol-object.h" + +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_SYMBOL_PROTOTYPE_ROUTINE_START = 0, + ECMA_SYMBOL_PROTOTYPE_VALUE_OF, /**< ECMA-262 v11, 19.4.3.4 */ + ECMA_SYMBOL_PROTOTYPE_TO_PRIMITIVE, /**< ECMA-262 v11, 19.4.3.5 */ + ECMA_SYMBOL_PROTOTYPE_TO_STRING, /**< ECMA-262 v11, 19.4.3.3 */ + ECMA_SYMBOL_PROTOTYPE_DESCRIPTION, /**< ECMA-262 v11, 19.4.3.2 */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-symbol-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID symbol_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup symbolprototype ECMA Symbol prototype object built-in + * @{ + */ + +/** + * Dispatcher of the Symbol built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_symbol_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list, arguments_number); + + ecma_value_t sym = ecma_symbol_this_value (this_arg); + + if (ECMA_IS_VALUE_ERROR (sym)) + { + return sym; + } + + if (builtin_routine_id < ECMA_SYMBOL_PROTOTYPE_TO_STRING) + { + return ecma_copy_value (sym); + } + + if (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_TO_STRING) + { + return ecma_get_symbol_descriptive_string (sym); + } + + JERRY_ASSERT (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_DESCRIPTION); + ecma_string_t *symbol_p = ecma_get_symbol_from_value (sym); + ecma_value_t desc = ecma_get_symbol_description (symbol_p); + if (ecma_is_value_undefined (desc)) + { + return desc; + } + + ecma_string_t *desc_p = ecma_get_string_from_value (desc); + ecma_ref_ecma_string (desc_p); + return desc; +} /* ecma_builtin_symbol_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.inc.h new file mode 100644 index 0000000..9b0daa0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.inc.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Symbol prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_SYMBOL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_SYMBOL_PROTOTYPE_TO_STRING, 0, 0) +ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_SYMBOL_PROTOTYPE_VALUE_OF, 0, 0) +ROUTINE_CONFIGURABLE_ONLY (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE, ECMA_SYMBOL_PROTOTYPE_TO_PRIMITIVE, 0, 1) + +/* ECMA-262 v6, 19.4.3.4 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_SYMBOL_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262, v11, 19.4.3.2 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_DESCRIPTION, ECMA_SYMBOL_PROTOTYPE_DESCRIPTION, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol.cpp new file mode 100644 index 0000000..20d1f70 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol.cpp @@ -0,0 +1,253 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-literal-storage.h" +#include "ecma-objects.h" +#include "ecma-symbol-object.h" + +#include "jcontext.h" +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-symbol.inc.h" +#define BUILTIN_UNDERSCORED_ID symbol +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup symbol ECMA Symbol object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in Symbol object. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_symbol_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_op_create_symbol (arguments_list_p, arguments_list_len); +} /* ecma_builtin_symbol_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in Symbol object. + * + * Symbol constructor is not intended to be used + * with the new operator or to be subclassed. + * + * See also: + * ECMA-262 v6, 19.4.1 + * @return ecma value + */ +ecma_value_t +ecma_builtin_symbol_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_SYMBOL_IS_NOT_A_CONSTRUCTOR); +} /* ecma_builtin_symbol_dispatch_construct */ + +/** + * Helper function for Symbol object's 'for' and `keyFor` + * routines common parts + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_symbol_for_helper (ecma_value_t value_to_find) /**< symbol or ecma-string */ +{ + ecma_string_t *string_p; + + bool is_for = ecma_is_value_string (value_to_find); + + if (is_for) + { + string_p = ecma_get_string_from_value (value_to_find); + } + else + { + string_p = ecma_get_symbol_from_value (value_to_find); + } + + jmem_cpointer_t symbol_list_cp = JERRY_CONTEXT (symbol_list_first_cp); + jmem_cpointer_t *empty_cpointer_p = NULL; + + while (symbol_list_cp != JMEM_CP_NULL) + { + ecma_lit_storage_item_t *symbol_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t, symbol_list_cp); + + for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + if (symbol_list_p->values[i] != JMEM_CP_NULL) + { + ecma_string_t *value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, symbol_list_p->values[i]); + + if (is_for) + { + ecma_value_t symbol_desc = ecma_get_symbol_description (value_p); + + if (ecma_is_value_undefined (symbol_desc)) + { + ecma_ref_ecma_string (value_p); + return ecma_make_symbol_value (value_p); + } + + ecma_string_t *symbol_desc_p = ecma_get_string_from_value (symbol_desc); + + if (ecma_compare_ecma_strings (symbol_desc_p, string_p)) + { + /* The current symbol's descriptor matches with the value_to_find, + so the value is no longer needed. */ + ecma_deref_ecma_string (string_p); + return ecma_copy_value (ecma_make_symbol_value (value_p)); + } + } + else + { + if (string_p == value_p) + { + ecma_value_t symbol_desc = ecma_get_symbol_description (string_p); + + if (ecma_is_value_undefined (symbol_desc)) + { + return symbol_desc; + } + + ecma_string_t *symbol_desc_p = ecma_get_string_from_value (symbol_desc); + ecma_ref_ecma_string (symbol_desc_p); + return symbol_desc; + } + } + } + else + { + if (empty_cpointer_p == NULL) + { + empty_cpointer_p = symbol_list_p->values + i; + } + } + } + + symbol_list_cp = symbol_list_p->next_cp; + } + + if (!is_for) + { + return ECMA_VALUE_UNDEFINED; + } + + /* There was no matching, sp a new symbol should be added the global symbol list. The symbol creation requires + an extra reference to the descriptor string, but this reference has already been added. */ + ecma_string_t *new_symbol_p = ecma_new_symbol_from_descriptor_string (value_to_find); + + jmem_cpointer_t result; + JMEM_CP_SET_NON_NULL_POINTER (result, new_symbol_p); + + if (empty_cpointer_p != NULL) + { + *empty_cpointer_p = result; + return ecma_copy_value (ecma_make_symbol_value (new_symbol_p)); + } + + ecma_lit_storage_item_t *new_item_p; + new_item_p = (ecma_lit_storage_item_t *) jmem_pools_alloc (sizeof (ecma_lit_storage_item_t)); + + new_item_p->values[0] = result; + for (int i = 1; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++) + { + new_item_p->values[i] = JMEM_CP_NULL; + } + + new_item_p->next_cp = JERRY_CONTEXT (symbol_list_first_cp); + JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (symbol_list_first_cp), new_item_p); + + return ecma_copy_value (ecma_make_symbol_value (new_symbol_p)); +} /* ecma_builtin_symbol_for_helper */ + +/** + * The Symbol object's 'for' routine + * + * See also: + * ECMA-262 v6, 19.4.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_symbol_for (ecma_value_t this_arg, /**< this argument */ + ecma_value_t key) /**< key string */ +{ + JERRY_UNUSED (this_arg); + ecma_string_t *string_desc_p = ecma_op_to_string (key); + + /* 1. */ + if (JERRY_UNLIKELY (string_desc_p == NULL)) + { + /* 2. */ + return ECMA_VALUE_ERROR; + } + + return ecma_builtin_symbol_for_helper (ecma_make_string_value (string_desc_p)); +} /* ecma_builtin_symbol_for */ + +/** + * The Symbol object's 'keyFor' routine + * + * See also: + * ECMA-262 v6, 19.4.2. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_symbol_key_for (ecma_value_t this_arg, /**< this argument */ + ecma_value_t symbol) /**< symbol */ +{ + JERRY_UNUSED (this_arg); + + /* 1. */ + if (!ecma_is_value_symbol (symbol)) + { + return ecma_raise_type_error (ECMA_ERR_THE_GIVEN_ARGUMENT_IS_NOT_A_SYMBOL); + } + + /* 2-4. */ + return ecma_builtin_symbol_for_helper (symbol); +} /* ecma_builtin_symbol_key_for */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol.inc.h new file mode 100644 index 0000000..9fecbd4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-symbol.inc.h @@ -0,0 +1,80 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Symbol built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v6, 19.4.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_SYMBOL_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 19.4.2.7 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* ECMA-262 v10, 19.4.2.1 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_ASYNC_ITERATOR, LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR) + +/* ECMA-262 v6, 19.4.2.2 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_HAS_INSTANCE, LIT_GLOBAL_SYMBOL_HAS_INSTANCE) + +/* ECMA-262 v6, 19.4.2.3 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE, LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE) + +/* ECMA-262 v6, 19.4.2.4 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_ITERATOR, LIT_GLOBAL_SYMBOL_ITERATOR) + +/* ECMA-262 v6, 19.4.2.6 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_MATCH, LIT_GLOBAL_SYMBOL_MATCH) + +/* ECMA-262 v6, 19.4.2.8 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_REPLACE, LIT_GLOBAL_SYMBOL_REPLACE) + +/* ECMA-262 v6, 19.4.2.9 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_SEARCH, LIT_GLOBAL_SYMBOL_SEARCH) + +/* ECMA-262 v6, 19.4.2.10 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_SPECIES, LIT_GLOBAL_SYMBOL_SPECIES) + +/* ECMA-262 v6, 19.4.2.11 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_SPLIT, LIT_GLOBAL_SYMBOL_SPLIT) + +/* ECMA-262 v6, 19.4.2.12 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_TO_PRIMITIVE, LIT_GLOBAL_SYMBOL_TO_PRIMITIVE) + +/* ECMA-262 v6, 19.4.2.13 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_TO_STRING_TAG, LIT_GLOBAL_SYMBOL_TO_STRING_TAG) + +/* ECMA-262 v6, 19.4.2.14 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_UNSCOPABLES, LIT_GLOBAL_SYMBOL_UNSCOPABLES) + +/* ECMA-262 v11, 19.4.2.8 */ +SYMBOL_VALUE (LIT_MAGIC_STRING_MATCH_ALL, LIT_GLOBAL_SYMBOL_MATCH_ALL) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_FOR, ecma_builtin_symbol_for, 1, 1) +ROUTINE (LIT_MAGIC_STRING_KEY_FOR, ecma_builtin_symbol_key_for, 1, 1) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.cpp new file mode 100644 index 0000000..2e5e7b8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.cpp @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-syntaxerror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID syntax_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h new file mode 100644 index 0000000..670efc1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * SyntaxError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_SYNTAX_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_SYNTAX_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.cpp new file mode 100644 index 0000000..449c0db --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.cpp @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-syntaxerror.inc.h" +#define BUILTIN_UNDERSCORED_ID syntax_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup syntaxerror ECMA SyntaxError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in SyntaxError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_syntax_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_SYNTAX, arguments_list_p, arguments_list_len); +} /* ecma_builtin_syntax_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in SyntaxError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_syntax_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), + ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_syntax_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_syntax_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h new file mode 100644 index 0000000..bee730c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * SyntaxError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_SYNTAX_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.cpp new file mode 100644 index 0000000..fdae8b7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.cpp @@ -0,0 +1,82 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jrt.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-type-error-thrower.inc.h" +#define BUILTIN_UNDERSCORED_ID type_error_thrower +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup type_error_thrower ECMA [[ThrowTypeError]] object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in [[ThrowTypeError]] object + * + * See also: + * ECMA-262 v5, 13.2.3 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_type_error_thrower_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CANNOT_ACCESS_CALLER_CALLEE_ARGUMENTS); +} /* ecma_builtin_type_error_thrower_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in [[ThrowTypeError]] object + * + * See also: + * ECMA-262 v5, 13.2.3 + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_type_error_thrower_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_builtin_type_error_thrower_dispatch_call (arguments_list_p, arguments_list_len); +} /* ecma_builtin_type_error_thrower_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h new file mode 100644 index 0000000..e44c8ab --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h @@ -0,0 +1,31 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * [[ThrowTypeError]] description + * + * See also: ECMA-262 v5, 13.2.3 + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FIXED) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_FIXED) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.cpp new file mode 100644 index 0000000..9e9971a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.cpp @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typeerror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID type_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h new file mode 100644 index 0000000..4d0b4f2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * TypeError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_TYPE_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_TYPE_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.cpp new file mode 100644 index 0000000..c18cdaa --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.cpp @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typeerror.inc.h" +#define BUILTIN_UNDERSCORED_ID type_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup typeerror ECMA TypeError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in TypeError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_type_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_TYPE, arguments_list_p, arguments_list_len); +} /* ecma_builtin_type_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in TypeError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_type_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_type_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_type_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h new file mode 100644 index 0000000..d2bb8e3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * TypeError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_TYPE_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.cpp new file mode 100644 index 0000000..26acbab --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.cpp @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-urierror-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID uri_error_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h new file mode 100644 index 0000000..2b6fd89 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * UriError.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.7.8 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_URI_ERROR, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.9 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_URI_ERROR_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v5, 15.11.7.10 */ +STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, LIT_MAGIC_STRING__EMPTY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.cpp new file mode 100644 index 0000000..1c7333e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.cpp @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt.h" + +#if JERRY_BUILTIN_ERRORS + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-urierror.inc.h" +#define BUILTIN_UNDERSCORED_ID uri_error +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup urierror ECMA UriError object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in UriError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uri_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_builtin_helper_error_dispatch_call (JERRY_ERROR_URI, arguments_list_p, arguments_list_len); +} /* ecma_builtin_uri_error_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in UriError object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uri_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + ecma_object_t *proto_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_uri_error_dispatch_call (arguments_list_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + ecma_object_t *object_p = ecma_get_object_from_value (result); + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p); + } + + ecma_deref_object (proto_p); + + return result; +} /* ecma_builtin_uri_error_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ERRORS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h new file mode 100644 index 0000000..ed1d3d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * UriError built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_ERRORS + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_DEFAULT_LENGTH) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v5, 15.11.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE, ECMA_PROPERTY_FIXED) +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_URI_ERROR_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_ERRORS */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap-prototype.cpp new file mode 100644 index 0000000..2a8d676 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap-prototype.cpp @@ -0,0 +1,65 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-container-object.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-weakmap-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID weakmap_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup weakmap ECMA WeakMap object built-in + * @{ + */ +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_weakmap_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + return ecma_builtin_container_dispatch_routine (builtin_routine_id, + this_arg, + arguments_list_p, + LIT_MAGIC_STRING_WEAKMAP_UL); +} /* ecma_builtin_weakmap_prototype_dispatch_routine */ +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap-prototype.inc.h new file mode 100644 index 0000000..75d6177 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap-prototype.inc.h @@ -0,0 +1,42 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * WeakMap.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.3.3.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_WEAKMAP, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.3.3.6 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_WEAKMAP_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_DELETE, ECMA_CONTAINER_ROUTINE_DELETE_WEAK, 1, 1) +ROUTINE (LIT_MAGIC_STRING_GET, ECMA_CONTAINER_ROUTINE_GET, 1, 1) +ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_CONTAINER_ROUTINE_HAS, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET, ECMA_CONTAINER_ROUTINE_SET, 2, 2) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap.cpp new file mode 100644 index 0000000..afc2f66 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap.cpp @@ -0,0 +1,74 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-container-object.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-weakmap.inc.h" +#define BUILTIN_UNDERSCORED_ID weakmap +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup weakmap ECMA WeakMap object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in WeakMap object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_weakmap_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_WEAKMAP_REQUIRES_NEW); +} /* ecma_builtin_weakmap_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in WeakMap object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_weakmap_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_op_container_create (arguments_list_p, + arguments_list_len, + LIT_MAGIC_STRING_WEAKMAP_UL, + ECMA_BUILTIN_ID_WEAKMAP_PROTOTYPE); +} /* ecma_builtin_weakmap_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap.inc.h new file mode 100644 index 0000000..8bf9843 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakmap.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * WeakMap built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v6, 23.3.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 23.1 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_WEAKMAP_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.3.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_WEAKMAP_PROTOTYPE, ECMA_PROPERTY_FIXED) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref-prototype.cpp new file mode 100644 index 0000000..4b4caf2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref-prototype.cpp @@ -0,0 +1,114 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-container-object.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_WEAKREF + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_BUILTIN_WEAKREF_PROTOTYPE_OBJECT_ROUTINE_START = 0, + ECMA_BUILTIN_WEAKREF_PROTOTYPE_OBJECT_DEREF +}; + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-weakref-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID weakref_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup weakref ECMA WeakRef object built-in + * @{ + */ + +/** + * Deref checks weakRef target + * + * @return weakRef target + * error - otherwise + */ +static ecma_value_t +ecma_builtin_weakref_prototype_object_deref (ecma_value_t this_arg) /**< this argument */ +{ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_TARGET_IS_NOT_OBJECT); + } + + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + ecma_extended_object_t *this_ext_obj = (ecma_extended_object_t *) object_p; + + if (!ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_WEAKREF)) + { + return ecma_raise_type_error (ECMA_ERR_TARGET_IS_NOT_WEAKREF); + } + + return ecma_copy_value (this_ext_obj->u.cls.u3.target); +} /* ecma_builtin_weakref_prototype_object_deref */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_weakref_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED_2 (arguments_list_p, arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_WEAKREF_PROTOTYPE_OBJECT_DEREF: + { + return ecma_builtin_weakref_prototype_object_deref (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_weakref_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_WEAKREF */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref-prototype.inc.h new file mode 100644 index 0000000..533d395 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref-prototype.inc.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * WeakSet.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_WEAKREF + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_WEAKREF, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_WEAKREF_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_DEREF, ECMA_BUILTIN_WEAKREF_PROTOTYPE_OBJECT_DEREF, 0, 0) + +#endif /* JERRY_BUILTIN_WEAKREF */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref.cpp new file mode 100644 index 0000000..bf15aae --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref.cpp @@ -0,0 +1,96 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_WEAKREF + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-weakref.inc.h" +#define BUILTIN_UNDERSCORED_ID weakref +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup weakref ECMA WeakRef object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in WeakRef object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_weakref_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_WEAKREF_REQUIRES_NEW); +} /* ecma_builtin_weakref_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in WeakRef object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_weakref_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + if (arguments_list_len == 0 || !ecma_is_value_object (arguments_list_p[0])) + { + return ecma_raise_type_error (ECMA_ERR_WEAKREF_TARGET_MUST_BE_AN_OBJECT); + } + + JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p) != NULL); + + ecma_object_t *proto_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_WEAKREF_PROTOTYPE); + + if (JERRY_UNLIKELY (proto_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *object_p = ecma_create_object (proto_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + ecma_deref_object (proto_p); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ext_obj_p->u.cls.type = ECMA_OBJECT_CLASS_WEAKREF; + ext_obj_p->u.cls.u3.target = arguments_list_p[0]; + ecma_op_object_set_weak (ecma_get_object_from_value (arguments_list_p[0]), object_p); + + return ecma_make_object_value (object_p); +} /* ecma_builtin_weakref_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_WEAKREF */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref.inc.h new file mode 100644 index 0000000..d4e6e5b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakref.inc.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * WeakRef built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_WEAKREF + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 1, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_WEAKREF_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_WEAKREF_PROTOTYPE, ECMA_PROPERTY_FIXED) + +#endif /* JERRY_BUILTIN_WEAKREF */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset-prototype.cpp new file mode 100644 index 0000000..370c504 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset-prototype.cpp @@ -0,0 +1,67 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-container-object.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-weakset-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID weakset_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup weakset ECMA WeakSet object built-in + * @{ + */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_weakset_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (arguments_number); + return ecma_builtin_container_dispatch_routine (builtin_routine_id, + this_arg, + arguments_list_p, + LIT_MAGIC_STRING_WEAKSET_UL); +} /* ecma_builtin_weakset_prototype_dispatch_routine */ +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset-prototype.inc.h new file mode 100644 index 0000000..6221f89 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset-prototype.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * WeakSet.prototype built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.4.3.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_WEAKSET, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ECMA-262 v6, 23.4.3.5 */ +STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_WEAKSET_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_ADD, ECMA_CONTAINER_ROUTINE_ADD, 1, 1) +ROUTINE (LIT_MAGIC_STRING_DELETE, ECMA_CONTAINER_ROUTINE_DELETE_WEAK, 1, 1) +ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_CONTAINER_ROUTINE_HAS, 1, 1) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset.cpp new file mode 100644 index 0000000..f30c6c2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset.cpp @@ -0,0 +1,74 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-container-object.h" +#include "ecma-exceptions.h" + +#if JERRY_BUILTIN_CONTAINER + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-weakset.inc.h" +#define BUILTIN_UNDERSCORED_ID weakset +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup weakset ECMA WeakSet object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in WeakSet object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_weakset_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_WEAKSET_REQUIRES_NEW); +} /* ecma_builtin_weakset_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in WeakSet object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_weakset_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_op_container_create (arguments_list_p, + arguments_list_len, + LIT_MAGIC_STRING_WEAKSET_UL, + ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE); +} /* ecma_builtin_weakset_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset.inc.h new file mode 100644 index 0000000..8aa16c8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-weakset.inc.h @@ -0,0 +1,41 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * WeakSet built-in description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_CONTAINER + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +/* ECMA-262 v6, 23.4.2 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 23.4 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_WEAKSET_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Object properties: + * (property name, object pointer getter) */ + +/* ECMA-262 v6, 23.4.2.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE, ECMA_PROPERTY_FIXED) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h new file mode 100644 index 0000000..5695e2d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h @@ -0,0 +1,98 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BUILTINS_INTERNAL_H +#define ECMA_BUILTINS_INTERNAL_H + +#ifndef ECMA_BUILTINS_INTERNAL +#error "!ECMA_BUILTINS_INTERNAL" +#endif /* !ECMA_BUILTINS_INTERNAL */ + +#include "ecma-builtins.h" +#include "ecma-globals.h" + +/** + * Type of built-in properties. + */ +typedef enum +{ + ECMA_BUILTIN_PROPERTY_SIMPLE, /**< simple value property */ + ECMA_BUILTIN_PROPERTY_NUMBER, /**< number value property */ + ECMA_BUILTIN_PROPERTY_STRING, /**< string value property */ + ECMA_BUILTIN_PROPERTY_SYMBOL, /**< symbol value property */ + ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY, /**< intrinsic routine property */ + ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION, /**< full accessor property with builtin function object + getter/setter pair */ + ECMA_BUILTIN_PROPERTY_OBJECT, /**< builtin object property */ + ECMA_BUILTIN_PROPERTY_ROUTINE, /**< routine property */ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, /**< full accessor property */ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY, /**< read-only accessor property */ + ECMA_BUILTIN_PROPERTY_END, /**< last property */ +} ecma_builtin_property_type_t; + +/** + * Type of symbolic built-in number types (starting from 256). + */ +typedef enum +{ + ECMA_BUILTIN_NUMBER_MAX = 256, /**< value of ECMA_NUMBER_MAX_VALUE */ + ECMA_BUILTIN_NUMBER_MIN, /**< value of ECMA_NUMBER_MIN_VALUE */ + ECMA_BUILTIN_NUMBER_EPSILON, /**< value of ECMA_NUMBER_EPSILON */ + ECMA_BUILTIN_NUMBER_MAX_SAFE_INTEGER, /**< value of ECMA_NUMBER_MAX_SAFE_INTEGER */ + ECMA_BUILTIN_NUMBER_MIN_SAFE_INTEGER, /**< value of ECMA_NUMBER_MIN_SAFE_INTEGER */ + ECMA_BUILTIN_NUMBER_E, /**< value of ECMA_NUMBER_E */ + ECMA_BUILTIN_NUMBER_PI, /**< value of ECMA_NUMBER_PI */ + ECMA_BUILTIN_NUMBER_LN10, /**< value of ECMA_NUMBER_LN10 */ + ECMA_BUILTIN_NUMBER_LN2, /**< value of ECMA_NUMBER_LN2 */ + ECMA_BUILTIN_NUMBER_LOG2E, /**< value of ECMA_NUMBER_LOG2E */ + ECMA_BUILTIN_NUMBER_LOG10E, /**< value of ECMA_NUMBER_LOG10E */ + ECMA_BUILTIN_NUMBER_SQRT2, /**< value of ECMA_NUMBER_SQRT2 */ + ECMA_BUILTIN_NUMBER_SQRT_1_2, /**< value of ECMA_NUMBER_SQRT_1_2 */ + ECMA_BUILTIN_NUMBER_NAN, /**< result of ecma_number_make_nan () */ + ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY, /**< result of ecma_number_make_infinity (false) */ + ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY, /**< result of ecma_number_make_infinity (true) */ +} ecma_builtin_number_type_t; + +/** + * Description of built-in properties. + */ +typedef struct +{ + uint16_t magic_string_id; /**< name of the property */ + uint8_t type; /**< type of the property */ + uint8_t attributes; /**< attributes of the property */ + uint16_t value; /**< value of the property */ +} ecma_builtin_property_descriptor_t; + +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + extern const ecma_builtin_property_descriptor_t ecma_builtin_##lowercase_name##_property_descriptor_list[]; \ + ecma_value_t ecma_builtin_##lowercase_name##_dispatch_call (const ecma_value_t *, uint32_t); \ + ecma_value_t ecma_builtin_##lowercase_name##_dispatch_construct (const ecma_value_t *, uint32_t); \ + ecma_value_t ecma_builtin_##lowercase_name##_dispatch_routine (uint8_t builtin_routine_id, \ + ecma_value_t this_arg_value, \ + const ecma_value_t[], \ + uint32_t); +#define BUILTIN(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + extern const ecma_builtin_property_descriptor_t ecma_builtin_##lowercase_name##_property_descriptor_list[]; \ + ecma_value_t ecma_builtin_##lowercase_name##_dispatch_routine (uint8_t builtin_routine_id, \ + ecma_value_t this_arg_value, \ + const ecma_value_t[], \ + uint32_t); +#include "ecma-builtins.inc.h" + +#undef BUILTIN_ROUTINE +#undef BUILTIN + +#endif /* !ECMA_BUILTINS_INTERNAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.cpp new file mode 100644 index 0000000..d82f1bd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.cpp @@ -0,0 +1,1511 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#include "ecma-alloc.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt-bit-fields.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + */ + +JERRY_STATIC_ASSERT ((((int)ECMA_BUILTIN_ID_GLOBAL) == ((int)ECMA_BUILTIN_OBJECTS_COUNT)), + ecma_builtin_id_global_must_be_the_last_builtin_id); + +/** + * Checks whether the built-in is an ecma_extended_built_in_object_t + */ +#define ECMA_BUILTIN_IS_EXTENDED_BUILT_IN(object_type) \ + ((object_type) == ECMA_OBJECT_TYPE_BUILT_IN_CLASS || (object_type) == ECMA_OBJECT_TYPE_BUILT_IN_ARRAY) + +/** + * Helper definition for ecma_builtin_property_list_references. + */ +typedef const ecma_builtin_property_descriptor_t *ecma_builtin_property_list_reference_t; + +/** + * Definition of built-in dispatch routine function pointer. + */ +typedef ecma_value_t (*ecma_builtin_dispatch_routine_t) (uint8_t builtin_routine_id, + ecma_value_t this_arg, + const ecma_value_t arguments_list[], + uint32_t arguments_number); +/** + * Definition of built-in dispatch call function pointer. + */ +typedef ecma_value_t (*ecma_builtin_dispatch_call_t) (const ecma_value_t arguments_list[], uint32_t arguments_number); +/** + * Definition of a builtin descriptor which contains the builtin object's: + * - prototype objects's id (13-bits) + * - type (3-bits) + * + * Layout: + * + * |----------------------|---------------| + * prototype_id(12) obj_type(4) + */ +typedef uint16_t ecma_builtin_descriptor_t; + +/** + * Bitshift index for get the prototype object's id from a builtin descriptor + */ +#define ECMA_BUILTIN_PROTOTYPE_ID_SHIFT 4 + +/** + * Bitmask for get the object's type from a builtin descriptor + */ +#define ECMA_BUILTIN_OBJECT_TYPE_MASK ((1 << ECMA_BUILTIN_PROTOTYPE_ID_SHIFT) - 1) + +/** + * Create a builtin descriptor value + */ +#define ECMA_MAKE_BUILTIN_DESCRIPTOR(type, proto_id) (((proto_id) << ECMA_BUILTIN_PROTOTYPE_ID_SHIFT) | (type)) + +/** + * List of the built-in descriptors. + */ +static const ecma_builtin_descriptor_t ecma_builtin_descriptors[] = { +/** @cond doxygen_suppress */ +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ECMA_MAKE_BUILTIN_DESCRIPTOR (object_type, object_prototype_builtin_id), +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE +#define BUILTIN_ROUTINE(a, b, c, d, e) +#define BUILTIN(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ECMA_MAKE_BUILTIN_DESCRIPTOR (object_type, object_prototype_builtin_id), +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE + /** @endcond */ +}; + +#ifndef JERRY_NDEBUG +/** @cond doxygen_suppress */ +enum +{ + ECMA_BUILTIN_EXTENSIBLE_CHECK = +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + (is_extensible != 0 || builtin_id == ECMA_BUILTIN_ID_TYPE_ERROR_THROWER) && +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE +#define BUILTIN_ROUTINE(a, b, c, d, e) +#define BUILTIN(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + (is_extensible != 0 || builtin_id == ECMA_BUILTIN_ID_TYPE_ERROR_THROWER) && +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE + true +}; +/** @endcond */ + +/** + * All the builtin object must be extensible except the ThrowTypeError object. + */ +JERRY_STATIC_ASSERT (ECMA_BUILTIN_EXTENSIBLE_CHECK == true, + ecma_builtin_must_be_extensible_except_the_builtin_throw_type_error_object); +#endif /* !JERRY_NDEBUG */ + +/** + * List of the built-in routines. + */ +static const ecma_builtin_dispatch_routine_t ecma_builtin_routines[] = { +/** @cond doxygen_suppress */ +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ecma_builtin_##lowercase_name##_dispatch_routine, +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE +#define BUILTIN_ROUTINE(a, b, c, d, e) +#define BUILTIN(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ecma_builtin_##lowercase_name##_dispatch_routine, +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE + /** @endcond */ +}; + +/** + * List of the built-in call functions. + */ +static const ecma_builtin_dispatch_call_t ecma_builtin_call_functions[] = { +/** @cond doxygen_suppress */ +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ecma_builtin_##lowercase_name##_dispatch_call, +#include "ecma-builtins.inc.h" +#undef BUILTIN_ROUTINE +#undef BUILTIN + /** @endcond */ +}; + +/** + * List of the built-in construct functions. + */ +static const ecma_builtin_dispatch_call_t ecma_builtin_construct_functions[] = { +/** @cond doxygen_suppress */ +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ecma_builtin_##lowercase_name##_dispatch_construct, +#include "ecma-builtins.inc.h" +#undef BUILTIN_ROUTINE +#undef BUILTIN + /** @endcond */ +}; + +/** + * Property descriptor lists for all built-ins. + */ +static const ecma_builtin_property_list_reference_t ecma_builtin_property_list_references[] = { +/** @cond doxygen_suppress */ +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ecma_builtin_##lowercase_name##_property_descriptor_list, +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE +#define BUILTIN_ROUTINE(a, b, c, d, e) +#define BUILTIN(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) \ + ecma_builtin_##lowercase_name##_property_descriptor_list, +#include "ecma-builtins.inc.h" +#undef BUILTIN_ROUTINE +#undef BUILTIN + /** @endcond */ +}; + +/** + * Get the number of properties of a built-in object. + * + * @return the number of properties + */ +static size_t +ecma_builtin_get_property_count (ecma_builtin_id_t builtin_id) /**< built-in ID */ +{ + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); + const ecma_builtin_property_descriptor_t *property_list_p = ecma_builtin_property_list_references[builtin_id]; + + const ecma_builtin_property_descriptor_t *curr_property_p = property_list_p; + + while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT) + { + curr_property_p++; + } + + return (size_t) (curr_property_p - property_list_p); +} /* ecma_builtin_get_property_count */ + +/** + * Check if passed object is a global built-in. + * + * @return true - if the object is a global built-in + * false - otherwise + */ +bool +ecma_builtin_is_global (ecma_object_t *object_p) /**< pointer to an object */ +{ + return (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_GENERAL + && ((ecma_extended_object_t *) object_p)->u.built_in.id == ECMA_BUILTIN_ID_GLOBAL); +} /* ecma_builtin_is_global */ + +/** + * Get reference to the global object + * + * Note: + * Does not increase the reference counter. + * + * @return pointer to the global object + */ +ecma_object_t * +ecma_builtin_get_global (void) +{ + JERRY_ASSERT (JERRY_CONTEXT (global_object_p) != NULL); + + return (ecma_object_t *) JERRY_CONTEXT (global_object_p); +} /* ecma_builtin_get_global */ + +/** + * Checks whether the given function is a built-in routine + * + * @return true - if the function object is a built-in routine + * false - otherwise + */ +bool +ecma_builtin_function_is_routine (ecma_object_t *func_obj_p) /**< function object */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p; + return (ext_func_obj_p->u.built_in.routine_id != 0); +} /* ecma_builtin_function_is_routine */ + +#if JERRY_BUILTIN_REALMS + +/** + * Get reference to the realm provided by another built-in object + * + * Note: + * Does not increase the reference counter. + * + * @return pointer to the global object + */ +static ecma_global_object_t * +ecma_builtin_get_realm (ecma_object_t *builtin_object_p) /**< built-in object */ +{ + ecma_object_type_t object_type = ecma_get_object_type (builtin_object_p); + ecma_value_t realm_value; + + JERRY_ASSERT (object_type == ECMA_OBJECT_TYPE_BUILT_IN_GENERAL || object_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS + || object_type == ECMA_OBJECT_TYPE_BUILT_IN_ARRAY || object_type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + if (ECMA_BUILTIN_IS_EXTENDED_BUILT_IN (object_type)) + { + realm_value = ((ecma_extended_built_in_object_t *) builtin_object_p)->built_in.realm_value; + } + else + { + realm_value = ((ecma_extended_object_t *) builtin_object_p)->u.built_in.realm_value; + } + + return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, realm_value); +} /* ecma_builtin_get_realm */ + +#endif /* JERRY_BUILTIN_REALMS */ + +/** + * Instantiate specified ECMA built-in object + * + * @return the newly instantiated built-in + */ +static ecma_object_t * +ecma_instantiate_builtin (ecma_global_object_t *global_object_p, /**< global object */ + ecma_builtin_id_t obj_builtin_id) /**< built-in id */ +{ + jmem_cpointer_t *builtin_objects = global_object_p->builtin_objects; + + JERRY_ASSERT (obj_builtin_id < ECMA_BUILTIN_OBJECTS_COUNT); + JERRY_ASSERT (builtin_objects[obj_builtin_id] == JMEM_CP_NULL); + + ecma_builtin_descriptor_t builtin_desc = ecma_builtin_descriptors[obj_builtin_id]; + ecma_builtin_id_t object_prototype_builtin_id = (ecma_builtin_id_t) (builtin_desc >> ECMA_BUILTIN_PROTOTYPE_ID_SHIFT); + + ecma_object_t *prototype_obj_p; + + if (JERRY_UNLIKELY (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT)) + { + prototype_obj_p = NULL; + } + else + { + if (builtin_objects[object_prototype_builtin_id] == JMEM_CP_NULL) + { + ecma_instantiate_builtin (global_object_p, object_prototype_builtin_id); + } + prototype_obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, builtin_objects[object_prototype_builtin_id]); + JERRY_ASSERT (prototype_obj_p != NULL); + } + + ecma_object_type_t obj_type = (ecma_object_type_t) (builtin_desc & ECMA_BUILTIN_OBJECT_TYPE_MASK); + + JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_BUILT_IN_GENERAL || obj_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS + || obj_type == ECMA_OBJECT_TYPE_BUILT_IN_ARRAY || obj_type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + bool is_extended_built_in = ECMA_BUILTIN_IS_EXTENDED_BUILT_IN (obj_type); + + size_t ext_object_size = + (is_extended_built_in ? sizeof (ecma_extended_built_in_object_t) : sizeof (ecma_extended_object_t)); + + size_t property_count = ecma_builtin_get_property_count (obj_builtin_id); + + if (property_count > ECMA_BUILTIN_INSTANTIATED_BITSET_MIN_SIZE) + { + /* Only 64 extra properties supported at the moment. + * This can be extended to 256 later. */ + JERRY_ASSERT (property_count <= (ECMA_BUILTIN_INSTANTIATED_BITSET_MIN_SIZE + 64)); + + ext_object_size += sizeof (uint64_t); + } + + ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, ext_object_size, obj_type); + + if (JERRY_UNLIKELY (obj_builtin_id == ECMA_BUILTIN_ID_TYPE_ERROR_THROWER)) + { + ecma_op_ordinary_object_prevent_extensions (obj_p); + } + else + { + ecma_op_ordinary_object_set_extensible (obj_p); + } + + /* + * [[Class]] property of built-in object is not stored explicitly. + * + * See also: ecma_object_get_class_name + */ + + ecma_built_in_props_t *built_in_props_p; + + if (is_extended_built_in) + { + built_in_props_p = &((ecma_extended_built_in_object_t *) obj_p)->built_in; + } + else + { + built_in_props_p = &((ecma_extended_object_t *) obj_p)->u.built_in; + } + + built_in_props_p->id = (uint8_t) obj_builtin_id; + built_in_props_p->routine_id = 0; + built_in_props_p->u.length_and_bitset_size = 0; + built_in_props_p->u2.instantiated_bitset[0] = 0; +#if JERRY_BUILTIN_REALMS + ECMA_SET_INTERNAL_VALUE_POINTER (built_in_props_p->realm_value, global_object_p); +#else /* !JERRY_BUILTIN_REALMS */ + built_in_props_p->continue_instantiated_bitset[0] = 0; +#endif /* JERRY_BUILTIN_REALMS */ + + if (property_count > ECMA_BUILTIN_INSTANTIATED_BITSET_MIN_SIZE) + { + built_in_props_p->u.length_and_bitset_size = 1 << ECMA_BUILT_IN_BITSET_SHIFT; + + uint32_t *instantiated_bitset_p = (uint32_t *) (built_in_props_p + 1); + instantiated_bitset_p[0] = 0; + instantiated_bitset_p[1] = 0; + } + + /** Initializing [[PrimitiveValue]] properties of built-in prototype objects */ + switch (obj_builtin_id) + { +#if JERRY_BUILTIN_ARRAY + case ECMA_BUILTIN_ID_ARRAY_PROTOTYPE: + { + JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_BUILT_IN_ARRAY); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + ext_object_p->u.array.length = 0; + ext_object_p->u.array.length_prop_and_hole_count = ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROPERTY_VIRTUAL; + break; + } +#endif /* JERRY_BUILTIN_ARRAY */ + +#if JERRY_BUILTIN_STRING + case ECMA_BUILTIN_ID_STRING_PROTOTYPE: + { + JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_STRING; + ext_object_p->u.cls.u3.value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + break; + } +#endif /* JERRY_BUILTIN_STRING */ + +#if JERRY_BUILTIN_NUMBER + case ECMA_BUILTIN_ID_NUMBER_PROTOTYPE: + { + JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_NUMBER; + ext_object_p->u.cls.u3.value = ecma_make_integer_value (0); + break; + } +#endif /* JERRY_BUILTIN_NUMBER */ + +#if JERRY_BUILTIN_BOOLEAN + case ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE: + { + JERRY_ASSERT (obj_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_BOOLEAN; + ext_object_p->u.cls.u3.value = ECMA_VALUE_FALSE; + break; + } +#endif /* JERRY_BUILTIN_BOOLEAN */ + + default: + { + JERRY_ASSERT (obj_type != ECMA_OBJECT_TYPE_BUILT_IN_CLASS); + break; + } + } + + ECMA_SET_NON_NULL_POINTER (builtin_objects[obj_builtin_id], obj_p); + ecma_deref_object (obj_p); + return obj_p; +} /* ecma_instantiate_builtin */ + +/** + * Create a global object + * + * @return a new global object + */ +ecma_global_object_t * +ecma_builtin_create_global_object (void) +{ + ecma_builtin_descriptor_t builtin_desc = ecma_builtin_descriptors[ECMA_BUILTIN_ID_GLOBAL]; + ecma_builtin_id_t prototype_builtin_id = (ecma_builtin_id_t) (builtin_desc >> ECMA_BUILTIN_PROTOTYPE_ID_SHIFT); + ecma_object_type_t obj_type = (ecma_object_type_t) (builtin_desc & ECMA_BUILTIN_OBJECT_TYPE_MASK); + ecma_builtin_get_property_count (ECMA_BUILTIN_ID_GLOBAL); + ecma_object_t *object_p = ecma_create_object (NULL, sizeof (ecma_global_object_t), obj_type); + + ecma_op_ordinary_object_set_extensible (object_p); + + ecma_global_object_t *global_object_p = (ecma_global_object_t *) object_p; + + global_object_p->extended_object.u.built_in.id = (uint8_t) ECMA_BUILTIN_ID_GLOBAL; + global_object_p->extended_object.u.built_in.routine_id = 0; + /* Bitset size is ignored by the gc. */ + global_object_p->extended_object.u.built_in.u.length_and_bitset_size = 0; + global_object_p->extended_object.u.built_in.u2.instantiated_bitset[0] = 0; + global_object_p->extra_instantiated_bitset[0] = 0; +#if JERRY_BUILTIN_REALMS + ECMA_SET_INTERNAL_VALUE_POINTER (global_object_p->extended_object.u.built_in.realm_value, global_object_p); + global_object_p->extra_realms_bitset = 0; + global_object_p->this_binding = ecma_make_object_value (object_p); +#else /* !JERRY_BUILTIN_REALMS */ + global_object_p->extended_object.u.built_in.continue_instantiated_bitset[0] = 0; +#endif /* JERRY_BUILTIN_REALMS */ + + memset (global_object_p->builtin_objects, 0, (sizeof (jmem_cpointer_t) * ECMA_BUILTIN_OBJECTS_COUNT)); + + /* Temporary self reference for GC mark. */ + ECMA_SET_NON_NULL_POINTER (global_object_p->global_env_cp, object_p); + global_object_p->global_scope_cp = global_object_p->global_env_cp; + + ecma_object_t *global_lex_env_p = ecma_create_object_lex_env (NULL, object_p); + + ECMA_SET_NON_NULL_POINTER (global_object_p->global_env_cp, global_lex_env_p); + global_object_p->global_scope_cp = global_object_p->global_env_cp; + + ecma_deref_object (global_lex_env_p); + + ecma_object_t *prototype_object_p; + prototype_object_p = ecma_instantiate_builtin (global_object_p, prototype_builtin_id); + JERRY_ASSERT (prototype_object_p != NULL); + + ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, prototype_object_p); + + return global_object_p; +} /* ecma_builtin_create_global_object */ + +/** + * Get reference to specified built-in object + * + * Note: + * Does not increase the reference counter. + * + * @return pointer to the object's instance + */ +ecma_object_t * +ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on */ +{ + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_OBJECTS_COUNT); + + ecma_global_object_t *global_object_p = (ecma_global_object_t *) ecma_builtin_get_global (); + jmem_cpointer_t *builtin_p = global_object_p->builtin_objects + builtin_id; + + if (JERRY_UNLIKELY (*builtin_p == JMEM_CP_NULL)) + { + return ecma_instantiate_builtin (global_object_p, builtin_id); + } + + return ECMA_GET_NON_NULL_POINTER (ecma_object_t, *builtin_p); +} /* ecma_builtin_get */ + +#if JERRY_BUILTIN_REALMS + +/** + * Get reference to specified built-in object using the realm provided by another built-in object + * + * Note: + * Does not increase the reference counter. + * + * @return pointer to the object's instance + */ +ecma_object_t * +ecma_builtin_get_from_realm (ecma_global_object_t *global_object_p, /**< global object */ + ecma_builtin_id_t builtin_id) /**< id of built-in to check on */ +{ + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_OBJECTS_COUNT); + + jmem_cpointer_t *builtin_p = global_object_p->builtin_objects + builtin_id; + + if (JERRY_UNLIKELY (*builtin_p == JMEM_CP_NULL)) + { + return ecma_instantiate_builtin (global_object_p, builtin_id); + } + + return ECMA_GET_NON_NULL_POINTER (ecma_object_t, *builtin_p); +} /* ecma_builtin_get_from_realm */ + +#endif /* JERRY_BUILTIN_REALMS */ + +/** + * Get reference to specified built-in object using the realm provided by another built-in object + * + * Note: + * Does not increase the reference counter. + * + * @return pointer to the object's instance + */ +static inline ecma_object_t * +ecma_builtin_get_from_builtin (ecma_object_t *builtin_object_p, /**< built-in object */ + ecma_builtin_id_t builtin_id) /**< id of built-in to check on */ +{ + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_OBJECTS_COUNT); + +#if JERRY_BUILTIN_REALMS + return ecma_builtin_get_from_realm (ecma_builtin_get_realm (builtin_object_p), builtin_id); +#else /* !JERRY_BUILTIN_REALMS */ + JERRY_UNUSED (builtin_object_p); + return ecma_builtin_get (builtin_id); +#endif /* JERRY_BUILTIN_REALMS */ +} /* ecma_builtin_get_from_builtin */ + +/** + * Construct a Function object for specified built-in routine + * + * See also: ECMA-262 v5, 15 + * + * @return pointer to constructed Function object + */ +static ecma_object_t * +ecma_builtin_make_function_object_for_routine (ecma_object_t *builtin_object_p, /**< builtin object */ + uint8_t routine_id, /**< builtin-wide identifier of the built-in + * object's routine property */ + uint32_t routine_index, /**< property descriptor index of routine */ + uint8_t flags) /**< see also: ecma_builtin_routine_flags */ +{ + ecma_object_t *prototype_obj_p = ecma_builtin_get_from_builtin (builtin_object_p, ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); + + size_t ext_object_size = sizeof (ecma_extended_object_t); + + ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p, ext_object_size, ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + JERRY_ASSERT (routine_id > 0); + JERRY_ASSERT (routine_index <= UINT8_MAX); + + ecma_built_in_props_t *built_in_props_p; + + if (ECMA_BUILTIN_IS_EXTENDED_BUILT_IN (ecma_get_object_type (builtin_object_p))) + { + built_in_props_p = &((ecma_extended_built_in_object_t *) builtin_object_p)->built_in; + } + else + { + built_in_props_p = &((ecma_extended_object_t *) builtin_object_p)->u.built_in; + } + + ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p; + ext_func_obj_p->u.built_in.id = built_in_props_p->id; + ext_func_obj_p->u.built_in.routine_id = routine_id; + ext_func_obj_p->u.built_in.u.routine_index = (uint8_t) routine_index; + ext_func_obj_p->u.built_in.u2.routine_flags = flags; + +#if JERRY_BUILTIN_REALMS + ext_func_obj_p->u.built_in.realm_value = built_in_props_p->realm_value; +#endif /* JERRY_BUILTIN_REALMS */ + + return func_obj_p; +} /* ecma_builtin_make_function_object_for_routine */ + +/** + * Construct a Function object for specified built-in accessor getter + * + * @return pointer to constructed accessor getter Function object + */ +static ecma_object_t * +ecma_builtin_make_function_object_for_getter_accessor (ecma_object_t *builtin_object_p, /**< builtin object */ + uint8_t routine_id, /**< builtin-wide id of the built-in + * object's routine property */ + uint32_t routine_index) /**< property descriptor index + * of routine */ +{ + return ecma_builtin_make_function_object_for_routine (builtin_object_p, + routine_id, + routine_index, + ECMA_BUILTIN_ROUTINE_GETTER); +} /* ecma_builtin_make_function_object_for_getter_accessor */ + +/** + * Construct a Function object for specified built-in accessor setter + * + * @return pointer to constructed accessor getter Function object + */ +static ecma_object_t * +ecma_builtin_make_function_object_for_setter_accessor (ecma_object_t *builtin_object_p, /**< builtin object */ + uint8_t routine_id, /**< builtin-wide id of the built-in + * object's routine property */ + uint32_t routine_index) /**< property descriptor index + * of routine */ +{ + return ecma_builtin_make_function_object_for_routine (builtin_object_p, + routine_id, + routine_index, + ECMA_BUILTIN_ROUTINE_SETTER); +} /* ecma_builtin_make_function_object_for_setter_accessor */ + +/** + * Create specification defined properties for built-in native handlers. + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +static ecma_property_t * +ecma_builtin_native_handler_try_to_instantiate_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property's name */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ecma_property_t *prop_p = NULL; + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_NAME)) + { + if ((ext_obj_p->u.built_in.u2.routine_flags & ECMA_NATIVE_HANDLER_FLAGS_NAME_INITIALIZED) == 0) + { + ecma_property_value_t *value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, &prop_p); + + value_p->value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + } + else if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)) + { + if ((ext_obj_p->u.built_in.u2.routine_flags & ECMA_NATIVE_HANDLER_FLAGS_LENGTH_INITIALIZED) == 0) + { + ecma_property_value_t *value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, &prop_p); + + const uint8_t length = ecma_builtin_handler_get_length ((ecma_native_handler_id_t) ext_obj_p->u.built_in.routine_id); + value_p->value = ecma_make_integer_value (length); + } + } + + return prop_p; +} /* ecma_builtin_native_handler_try_to_instantiate_property */ + +/** + * Lazy instantiation of builtin routine property of builtin object + * + * If the property is not instantiated yet, instantiate the property and + * return pointer to the instantiated property. + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +ecma_property_t * +ecma_builtin_routine_try_to_instantiate_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION + && ecma_builtin_function_is_routine (object_p)); + + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + + if (JERRY_UNLIKELY (ext_func_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER)) + { + return ecma_builtin_native_handler_try_to_instantiate_property (object_p, property_name_p); + } + + if (ecma_string_is_length (property_name_p)) + { + /* + * Lazy instantiation of 'length' property + */ + ecma_property_t *len_prop_p; + + uint8_t *bitset_p = &ext_func_p->u.built_in.u2.routine_flags; + + if (*bitset_p & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED) + { + /* length property was already instantiated */ + return NULL; + } + + /* We mark that the property was lazily instantiated, + * as it is configurable and so can be deleted (ECMA-262 v6, 19.2.4.1) */ + ecma_property_value_t *len_prop_value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, &len_prop_p); + + uint8_t length = 0; + + if (ext_func_p->u.built_in.u2.routine_flags & ECMA_BUILTIN_ROUTINE_SETTER) + { + length = 1; + } + else if (!(ext_func_p->u.built_in.u2.routine_flags & ECMA_BUILTIN_ROUTINE_GETTER)) + { + uint8_t routine_index = ext_func_p->u.built_in.u.routine_index; + const ecma_builtin_property_descriptor_t *property_list_p; + + property_list_p = ecma_builtin_property_list_references[ext_func_p->u.built_in.id]; + + JERRY_ASSERT (property_list_p[routine_index].type == ECMA_BUILTIN_PROPERTY_ROUTINE); + + length = ECMA_GET_ROUTINE_LENGTH (property_list_p[routine_index].value); + } + + len_prop_value_p->value = ecma_make_integer_value (length); + return len_prop_p; + } + + /* + * Lazy instantiation of 'name' property + */ + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_NAME)) + { + uint8_t *bitset_p = &ext_func_p->u.built_in.u2.routine_flags; + + if (*bitset_p & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED) + { + /* name property was already instantiated */ + return NULL; + } + + /* We mark that the property was lazily instantiated */ + ecma_property_t *name_prop_p; + ecma_property_value_t *name_prop_value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, &name_prop_p); + + uint8_t routine_index = ext_func_p->u.built_in.u.routine_index; + const ecma_builtin_property_descriptor_t *property_list_p; + + property_list_p = ecma_builtin_property_list_references[ext_func_p->u.built_in.id]; + + JERRY_ASSERT (property_list_p[routine_index].type == ECMA_BUILTIN_PROPERTY_ROUTINE + || property_list_p[routine_index].type == ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE + || property_list_p[routine_index].type == ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY); + + lit_magic_string_id_t name_id = (lit_magic_string_id_t) property_list_p[routine_index].magic_string_id; + ecma_string_t *name_p; + + if (JERRY_UNLIKELY (name_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT)) + { + /* Note: Whenever new intrinsic routine is being added this mapping should be updated as well! */ + if (JERRY_UNLIKELY (name_id == LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES) + || JERRY_UNLIKELY (name_id == LIT_INTERNAL_MAGIC_STRING_TYPEDARRAY_PROTOTYPE_VALUES) + || JERRY_UNLIKELY (name_id == LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES)) + { + name_p = ecma_get_magic_string (LIT_MAGIC_STRING_VALUES); + } + else if (JERRY_UNLIKELY (name_id == LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES)) + { + name_p = ecma_get_magic_string (LIT_MAGIC_STRING_ENTRIES); + } + else + { + JERRY_ASSERT (LIT_IS_GLOBAL_SYMBOL (name_id)); + name_p = ecma_op_get_global_symbol (name_id); + } + } + else + { + name_p = ecma_get_magic_string (name_id); + } + + const char *prefix_p = NULL; + lit_utf8_size_t prefix_size = 0; + + if (*bitset_p & (ECMA_BUILTIN_ROUTINE_GETTER | ECMA_BUILTIN_ROUTINE_SETTER)) + { + prefix_size = 4; + prefix_p = (*bitset_p & ECMA_BUILTIN_ROUTINE_GETTER) ? "get " : "set "; + } + + name_prop_value_p->value = ecma_op_function_form_name (name_p, (char*)prefix_p, prefix_size); + + if (JERRY_UNLIKELY (name_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT)) + { + ecma_deref_ecma_string (name_p); + } + + return name_prop_p; + } + + return NULL; +} /* ecma_builtin_routine_try_to_instantiate_property */ + +/** + * If the property's name is one of built-in properties of the object + * that is not instantiated yet, instantiate the property and + * return pointer to the instantiated property. + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +ecma_property_t * +ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property's name */ +{ + lit_magic_string_id_t magic_string_id = ecma_get_string_magic (property_name_p); + + if (JERRY_UNLIKELY (ecma_prop_name_is_symbol (property_name_p)) && property_name_p->u.hash & ECMA_SYMBOL_FLAG_GLOBAL) + { + magic_string_id = (lit_magic_string_id_t) ((int) property_name_p->u.hash >> (int) ECMA_SYMBOL_FLAGS_SHIFT); + } + + if (magic_string_id == LIT_MAGIC_STRING__COUNT) + { + return NULL; + } + + ecma_built_in_props_t *built_in_props_p; + ecma_object_type_t object_type = ecma_get_object_type (object_p); + + JERRY_ASSERT (object_type == ECMA_OBJECT_TYPE_BUILT_IN_GENERAL || object_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS + || object_type == ECMA_OBJECT_TYPE_BUILT_IN_ARRAY + || (object_type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION && !ecma_builtin_function_is_routine (object_p))); + + if (ECMA_BUILTIN_IS_EXTENDED_BUILT_IN (object_type)) + { + built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in; + } + else + { + built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in; + } + + ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id; + + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); + + const ecma_builtin_property_descriptor_t *property_list_p = ecma_builtin_property_list_references[builtin_id]; + const ecma_builtin_property_descriptor_t *curr_property_p = property_list_p; + + while (curr_property_p->magic_string_id != magic_string_id) + { + if (curr_property_p->magic_string_id == LIT_MAGIC_STRING__COUNT) + { + return NULL; + } + curr_property_p++; + } + + uint32_t index = (uint32_t) (curr_property_p - property_list_p); + uint8_t *bitset_p = built_in_props_p->u2.instantiated_bitset + (index >> 3); + +#if JERRY_BUILTIN_REALMS + if (index >= 8 * sizeof (uint8_t)) + { + bitset_p += sizeof (ecma_value_t); + } +#endif /* JERRY_BUILTIN_REALMS */ + + uint8_t bit_for_index = (uint8_t) (1u << (index & 0x7)); + + if (*bitset_p & bit_for_index) + { + /* This property was instantiated before. */ + return NULL; + } + + ecma_value_t value = ECMA_VALUE_EMPTY; + bool is_accessor = false; + ecma_object_t *getter_p = NULL; + ecma_object_t *setter_p = NULL; + + switch (curr_property_p->type) + { + case ECMA_BUILTIN_PROPERTY_SIMPLE: + { + value = curr_property_p->value; + +#if JERRY_BUILTIN_GLOBAL_THIS + if (value == ECMA_VALUE_GLOBAL_THIS) + { + /* Only the global object has globalThis property. */ + JERRY_ASSERT (ecma_builtin_is_global (object_p)); + ecma_ref_object (object_p); + value = ecma_make_object_value (object_p); + } +#endif /* JERRY_BUILTIN_GLOBAL_THIS */ + break; + } + case ECMA_BUILTIN_PROPERTY_NUMBER: + { + ecma_number_t num = 0.0; + + if (curr_property_p->value < ECMA_BUILTIN_NUMBER_MAX) + { + num = curr_property_p->value; + } + else if (curr_property_p->value < ECMA_BUILTIN_NUMBER_NAN) + { + static const ecma_number_t builtin_number_list[] = { + ECMA_NUMBER_MAX_VALUE, + ECMA_NUMBER_MIN_VALUE, + ECMA_NUMBER_EPSILON, + ECMA_NUMBER_MAX_SAFE_INTEGER, + ECMA_NUMBER_MIN_SAFE_INTEGER, + ECMA_NUMBER_E, + ECMA_NUMBER_PI, + ECMA_NUMBER_LN10, + ECMA_NUMBER_LN2, + ECMA_NUMBER_LOG2E, + ECMA_NUMBER_LOG10E, + ECMA_NUMBER_SQRT2, + ECMA_NUMBER_SQRT_1_2, + }; + + num = builtin_number_list[curr_property_p->value - ECMA_BUILTIN_NUMBER_MAX]; + } + else + { + switch (curr_property_p->value) + { + case ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY: + { + num = ecma_number_make_infinity (false); + break; + } + case ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY: + { + num = ecma_number_make_infinity (true); + break; + } + default: + { + JERRY_ASSERT (curr_property_p->value == ECMA_BUILTIN_NUMBER_NAN); + + num = ecma_number_make_nan (); + break; + } + } + } + + value = ecma_make_number_value (num); + break; + } + case ECMA_BUILTIN_PROPERTY_STRING: + { + value = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->value); + break; + } + case ECMA_BUILTIN_PROPERTY_SYMBOL: + { + lit_magic_string_id_t symbol_id = (lit_magic_string_id_t) curr_property_p->value; + + value = ecma_make_symbol_value (ecma_op_get_global_symbol (symbol_id)); + break; + } + case ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY: + { + ecma_object_t *intrinsic_object_p = ecma_builtin_get_from_builtin (object_p, ECMA_BUILTIN_ID_INTRINSIC_OBJECT); + value = ecma_op_object_get_by_magic_id (intrinsic_object_p, (lit_magic_string_id_t) curr_property_p->value); + break; + } + case ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION: + { + is_accessor = true; + uint16_t getter_id = ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID (curr_property_p->value); + uint16_t setter_id = ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID (curr_property_p->value); + getter_p = ecma_builtin_get_from_builtin (object_p, (ecma_builtin_id_t) getter_id); + setter_p = ecma_builtin_get_from_builtin (object_p, (ecma_builtin_id_t) setter_id); + ecma_ref_object (getter_p); + ecma_ref_object (setter_p); + break; + } + case ECMA_BUILTIN_PROPERTY_OBJECT: + { + ecma_object_t *builtin_object_p; + builtin_object_p = ecma_builtin_get_from_builtin (object_p, (ecma_builtin_id_t) curr_property_p->value); + ecma_ref_object (builtin_object_p); + value = ecma_make_object_value (builtin_object_p); + break; + } + case ECMA_BUILTIN_PROPERTY_ROUTINE: + { + ecma_object_t *func_obj_p; + func_obj_p = ecma_builtin_make_function_object_for_routine (object_p, + ECMA_GET_ROUTINE_ID (curr_property_p->value), + index, + ECMA_BUILTIN_ROUTINE_NO_OPTS); + value = ecma_make_object_value (func_obj_p); + break; + } + case ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE: + { + is_accessor = true; + uint8_t getter_id = ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID (curr_property_p->value); + uint8_t setter_id = ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID (curr_property_p->value); + getter_p = ecma_builtin_make_function_object_for_getter_accessor (object_p, getter_id, index); + setter_p = ecma_builtin_make_function_object_for_setter_accessor (object_p, setter_id, index); + break; + } + default: + { + JERRY_ASSERT (curr_property_p->type == ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY); + + is_accessor = true; + uint8_t getter_id = (uint8_t) curr_property_p->value; + getter_p = ecma_builtin_make_function_object_for_getter_accessor (object_p, getter_id, index); + break; + } + } + + ecma_property_t *prop_p; + + JERRY_ASSERT (curr_property_p->attributes & ECMA_PROPERTY_FLAG_BUILT_IN); + + if (is_accessor) + { + ecma_create_named_accessor_property (object_p, + property_name_p, + getter_p, + setter_p, + curr_property_p->attributes, + &prop_p); + + if (setter_p) + { + ecma_deref_object (setter_p); + } + if (getter_p) + { + ecma_deref_object (getter_p); + } + } + else + { + ecma_property_value_t *prop_value_p = + ecma_create_named_data_property (object_p, property_name_p, curr_property_p->attributes, &prop_p); + prop_value_p->value = value; + + /* Reference count of objects must be decreased. */ + ecma_deref_if_object (value); + } + + return prop_p; +} /* ecma_builtin_try_to_instantiate_property */ + +/** + * Delete configurable properties of native handlers. + */ +static void +ecma_builtin_native_handler_delete_built_in_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + ecma_extended_object_t *extended_obj_p = (ecma_extended_object_t *) object_p; + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)) + { + JERRY_ASSERT (!(extended_obj_p->u.built_in.u2.routine_flags & ECMA_NATIVE_HANDLER_FLAGS_LENGTH_INITIALIZED)); + + extended_obj_p->u.built_in.u2.routine_flags |= ECMA_NATIVE_HANDLER_FLAGS_LENGTH_INITIALIZED; + return; + } + + JERRY_ASSERT (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_NAME)); + JERRY_ASSERT (!(extended_obj_p->u.built_in.u2.routine_flags & ECMA_NATIVE_HANDLER_FLAGS_NAME_INITIALIZED)); + + extended_obj_p->u.built_in.u2.routine_flags |= ECMA_NATIVE_HANDLER_FLAGS_NAME_INITIALIZED; +} /* ecma_builtin_native_handler_delete_built_in_property */ + +/** + * Delete configurable properties of built-in routines. + */ +void +ecma_builtin_routine_delete_built_in_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION + && ecma_builtin_function_is_routine (object_p)); + + ecma_extended_object_t *extended_obj_p = (ecma_extended_object_t *) object_p; + + if (JERRY_UNLIKELY (extended_obj_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER)) + { + ecma_builtin_native_handler_delete_built_in_property (object_p, property_name_p); + return; + } + + uint8_t *bitset_p = &extended_obj_p->u.built_in.u2.routine_flags; + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)) + { + JERRY_ASSERT (!(*bitset_p & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED)); + + *bitset_p |= ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED; + return; + } + + JERRY_ASSERT (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_NAME)); + JERRY_ASSERT (!(*bitset_p & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED)); + + *bitset_p |= ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED; +} /* ecma_builtin_routine_delete_built_in_property */ + +/** + * Delete configurable properties of built-ins. + */ +void +ecma_builtin_delete_built_in_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + lit_magic_string_id_t magic_string_id = ecma_get_string_magic (property_name_p); + + if (JERRY_UNLIKELY (ecma_prop_name_is_symbol (property_name_p))) + { + if (property_name_p->u.hash & ECMA_SYMBOL_FLAG_GLOBAL) + { + magic_string_id = (lit_magic_string_id_t ) ((int) property_name_p->u.hash >> ECMA_SYMBOL_FLAGS_SHIFT); + } + } + + ecma_built_in_props_t *built_in_props_p; + ecma_object_type_t object_type = ecma_get_object_type (object_p); + + JERRY_ASSERT (object_type == ECMA_OBJECT_TYPE_BUILT_IN_GENERAL || object_type == ECMA_OBJECT_TYPE_BUILT_IN_CLASS + || object_type == ECMA_OBJECT_TYPE_BUILT_IN_ARRAY + || (object_type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION && !ecma_builtin_function_is_routine (object_p))); + + if (ECMA_BUILTIN_IS_EXTENDED_BUILT_IN (object_type)) + { + built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in; + } + else + { + built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in; + } + + ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id; + + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); + + const ecma_builtin_property_descriptor_t *property_list_p = ecma_builtin_property_list_references[builtin_id]; + const ecma_builtin_property_descriptor_t *curr_property_p = property_list_p; + + while (curr_property_p->magic_string_id != magic_string_id) + { + JERRY_ASSERT (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT); + curr_property_p++; + } + + uint32_t index = (uint32_t) (curr_property_p - property_list_p); + uint8_t *bitset_p = built_in_props_p->u2.instantiated_bitset + (index >> 3); + +#if JERRY_BUILTIN_REALMS + if (index >= 8 * sizeof (uint8_t)) + { + bitset_p += sizeof (ecma_value_t); + } +#endif /* JERRY_BUILTIN_REALMS */ + + uint8_t bit_for_index = (uint8_t) (1u << (index & 0x7)); + JERRY_ASSERT (!(*bitset_p & bit_for_index)); + + *bitset_p |= bit_for_index; +} /* ecma_builtin_delete_built_in_property */ + +/** + * List names of an Built-in native handler object's lazy instantiated properties, + * adding them to corresponding string collections + */ +static void +ecma_builtin_native_handler_list_lazy_property_names (ecma_object_t *object_p, /**< function object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p) /**< prop counter */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + + if ((ext_obj_p->u.built_in.u2.routine_flags & ECMA_NATIVE_HANDLER_FLAGS_NAME_INITIALIZED) == 0) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME)); + prop_counter_p->string_named_props++; + } + + if ((ext_obj_p->u.built_in.u2.routine_flags & ECMA_NATIVE_HANDLER_FLAGS_LENGTH_INITIALIZED) == 0) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } +} /* ecma_builtin_native_handler_list_lazy_property_names */ + +/** + * List names of a built-in function's lazy instantiated properties + * + * See also: + * ecma_builtin_routine_try_to_instantiate_property + */ +void +ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< name filters */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + JERRY_ASSERT (ecma_builtin_function_is_routine (object_p)); + + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS) + { + return; + } + + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + + if (JERRY_UNLIKELY (ext_func_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER)) + { + ecma_builtin_native_handler_list_lazy_property_names (object_p, prop_names_p, prop_counter_p); + return; + } + + if (!(ext_func_p->u.built_in.u2.routine_flags & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED)) + { + /* Uninitialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } + if (!(ext_func_p->u.built_in.u2.routine_flags & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED)) + { + /* Uninitialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME)); + prop_counter_p->string_named_props++; + } +} /* ecma_builtin_routine_list_lazy_property_names */ + +/** + * List names of a built-in object's lazy instantiated properties + * + * See also: + * ecma_builtin_try_to_instantiate_property + */ +void +ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< name filters */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) != ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION + || !ecma_builtin_function_is_routine (object_p)); + + ecma_built_in_props_t *built_in_props_p; + ecma_object_type_t object_type = ecma_get_object_type (object_p); + + if (ECMA_BUILTIN_IS_EXTENDED_BUILT_IN (object_type)) + { + built_in_props_p = &((ecma_extended_built_in_object_t *) object_p)->built_in; + } + else + { + built_in_props_p = &((ecma_extended_object_t *) object_p)->u.built_in; + } + + ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_props_p->id; + + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); + +#if JERRY_BUILTIN_REALMS + uint8_t *bitset_p = built_in_props_p->u2.instantiated_bitset + 1 + sizeof (ecma_value_t); +#else /* !JERRY_BUILTIN_REALMS */ + uint8_t *bitset_p = built_in_props_p->u2.instantiated_bitset + 1; +#endif /* JERRY_BUILTIN_REALMS */ + + uint8_t *symbol_bitset_p = bitset_p; + bool has_symbol = true; + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS)) + { + const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id]; + uint8_t bitset = built_in_props_p->u2.instantiated_bitset[0]; + uint32_t index = 0; + + has_symbol = false; + + while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT) + { + if (index == 8) + { + bitset = *bitset_p++; + index = 0; + } + + uint32_t bit_for_index = (uint32_t) 1u << index; + + if (!(bitset & bit_for_index)) + { + if (JERRY_LIKELY (curr_property_p->magic_string_id < LIT_NON_INTERNAL_MAGIC_STRING__COUNT)) + { + ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id); + ecma_collection_push_back (prop_names_p, name); + prop_counter_p->string_named_props++; + } + else + { + JERRY_ASSERT (LIT_IS_GLOBAL_SYMBOL (curr_property_p->magic_string_id)); + has_symbol = true; + } + } + + curr_property_p++; + index++; + } + } + + if (has_symbol && !(filter & JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS)) + { + const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id]; + uint8_t bitset = built_in_props_p->u2.instantiated_bitset[0]; + uint32_t index = 0; + + while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT) + { + if (index == 8) + { + bitset = *symbol_bitset_p++; + index = 0; + } + + uint32_t bit_for_index = (uint32_t) 1u << index; + + if (curr_property_p->magic_string_id > LIT_NON_INTERNAL_MAGIC_STRING__COUNT && !(bitset & bit_for_index)) + { + ecma_string_t *name_p = ecma_op_get_global_symbol ((lit_magic_string_id_t ) curr_property_p->magic_string_id); + ecma_collection_push_back (prop_names_p, ecma_make_symbol_value (name_p)); + prop_counter_p->symbol_named_props++; + } + + curr_property_p++; + index++; + } + } +} /* ecma_builtin_list_lazy_property_names */ + +/** + * Dispatcher of built-in routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_dispatch_routine (ecma_extended_object_t *func_obj_p, /**< builtin object */ + ecma_value_t this_arg_value, /**< 'this' argument value */ + const ecma_value_t *arguments_list_p, /**< list of arguments passed to routine */ + uint32_t arguments_list_len) /**< length of arguments' list */ +{ + JERRY_ASSERT (ecma_builtin_function_is_routine ((ecma_object_t *) func_obj_p)); + + ecma_value_t padded_arguments_list_p[3] = { ECMA_VALUE_UNDEFINED, ECMA_VALUE_UNDEFINED, ECMA_VALUE_UNDEFINED }; + + if (arguments_list_len <= 2) + { + switch (arguments_list_len) + { + case 2: + { + padded_arguments_list_p[1] = arguments_list_p[1]; + /* FALLTHRU */ + } + case 1: + { + padded_arguments_list_p[0] = arguments_list_p[0]; + break; + } + default: + { + JERRY_ASSERT (arguments_list_len == 0); + } + } + + arguments_list_p = padded_arguments_list_p; + } + + return ecma_builtin_routines[func_obj_p->u.built_in.id](func_obj_p->u.built_in.routine_id, + this_arg_value, + arguments_list_p, + arguments_list_len); +} /* ecma_builtin_dispatch_routine */ + +/** + * Handle calling [[Call]] of built-in object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */ + ecma_value_t this_arg_value, /**< 'this' argument value */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< arguments list length */ +{ + JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (ecma_builtin_function_is_routine (obj_p)) + { + if (JERRY_UNLIKELY (ext_obj_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER)) + { + ecma_builtin_handler_t handler = ecma_builtin_handler_get ((ecma_native_handler_id_t ) ext_obj_p->u.built_in.routine_id); + return handler (obj_p, arguments_list_p, arguments_list_len); + } + + return ecma_builtin_dispatch_routine (ext_obj_p, this_arg_value, arguments_list_p, arguments_list_len); + } + + ecma_builtin_id_t builtin_object_id = (ecma_builtin_id_t) ext_obj_p->u.built_in.id; + JERRY_ASSERT (builtin_object_id < sizeof (ecma_builtin_call_functions) / sizeof (ecma_builtin_dispatch_call_t)); + return ecma_builtin_call_functions[builtin_object_id](arguments_list_p, arguments_list_len); +} /* ecma_builtin_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< arguments list length */ +{ + JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + if (ecma_builtin_function_is_routine (obj_p)) + { + return ecma_raise_type_error (ECMA_ERR_BUILTIN_ROUTINES_HAVE_NO_CONSTRUCTOR); + } + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + ecma_builtin_id_t builtin_object_id = (ecma_builtin_id_t) ext_obj_p->u.built_in.id; + JERRY_ASSERT (builtin_object_id < sizeof (ecma_builtin_construct_functions) / sizeof (ecma_builtin_dispatch_call_t)); + + return ecma_builtin_construct_functions[builtin_object_id](arguments_list_p, arguments_list_len); +} /* ecma_builtin_dispatch_construct */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.h new file mode 100644 index 0000000..82761cd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.h @@ -0,0 +1,136 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BUILTINS_H +#define ECMA_BUILTINS_H + +#include "ecma-globals.h" + +/** + * A built-in object's identifier + */ +typedef enum +{ +/** @cond doxygen_suppress */ +#define BUILTIN(a, b, c, d, e) +#define BUILTIN_ROUTINE(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) builtin_id, +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE +#define BUILTIN_ROUTINE(a, b, c, d, e) +#define BUILTIN(builtin_id, object_type, object_prototype_builtin_id, is_extensible, lowercase_name) builtin_id, +#include "ecma-builtins.inc.h" +#undef BUILTIN +#undef BUILTIN_ROUTINE + /** @endcond */ + ECMA_BUILTIN_ID__COUNT /**< number of built-in objects */ +} ecma_builtin_id_t; + +/** + * Special id for handlers (handlers are not regular built-ins, but + * they use the same ecma_built_in_props_t structure as other built-ins) + */ +#define ECMA_BUILTIN_ID_HANDLER ECMA_BUILTIN_ID__COUNT + +/** + * Number of global symbols + */ +#define ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT (LIT_GLOBAL_SYMBOL__LAST - LIT_GLOBAL_SYMBOL__FIRST + 1) + +/** + * Construct a routine value + */ +#define ECMA_ROUTINE_VALUE(id, length) (((id) << 4) | length) + +/** + * Get routine length + */ +#define ECMA_GET_ROUTINE_LENGTH(value) ((uint8_t) ((value) &0xf)) + +/** + * Get routine ID + */ +#define ECMA_GET_ROUTINE_ID(value) ((uint8_t) ((value) >> 4)) + +/** + * Construct a fully accessor value + */ +#define ECMA_ACCESSOR_READ_WRITE(getter, setter) (((getter) << 8) | (setter)) + +/** + * Get accessor setter ID + */ +#define ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID(value) ((uint8_t) ((value) &0xff)) + +/** + * Get accessor getter ID + */ +#define ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID(value) ((uint8_t) ((value) >> 8)) + +/** + * Number ob built-in objects excluding global object + */ +#define ECMA_BUILTIN_OBJECTS_COUNT (ECMA_BUILTIN_ID__COUNT - 1) + +/** + * Description of built-in global ECMA-object. + */ +typedef struct +{ + ecma_extended_object_t extended_object; /**< extended object part */ + uint32_t extra_instantiated_bitset[1]; /**< extra bit set for instantiated properties */ +#if JERRY_BUILTIN_REALMS + uint32_t extra_realms_bitset; /**< extra bit set for instantiated properties when realms is enabled */ + ecma_value_t this_binding; /**< 'this' binding of this global object */ +#endif /* JERRY_BUILTIN_REALMS */ + jmem_cpointer_t global_env_cp; /**< global lexical environment */ + jmem_cpointer_t global_scope_cp; /**< global lexical scope */ + jmem_cpointer_t builtin_objects[ECMA_BUILTIN_OBJECTS_COUNT]; /**< pointer to instances of built-in objects */ +} ecma_global_object_t; + +/* ecma-builtins.c */ + +ecma_global_object_t *ecma_builtin_create_global_object (void); + +ecma_value_t ecma_builtin_dispatch_call (ecma_object_t *obj_p, + ecma_value_t this_arg_value, + const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len); +ecma_value_t ecma_builtin_dispatch_construct (ecma_object_t *obj_p, + const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len); +ecma_property_t *ecma_builtin_routine_try_to_instantiate_property (ecma_object_t *object_p, + ecma_string_t *property_name_p); +ecma_property_t *ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +void ecma_builtin_routine_delete_built_in_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +void ecma_builtin_delete_built_in_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +void ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); +void ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); +bool ecma_builtin_is_global (ecma_object_t *object_p); +ecma_object_t *ecma_builtin_get (ecma_builtin_id_t builtin_id); +ecma_object_t *ecma_builtin_get_global (void); +bool ecma_builtin_function_is_routine (ecma_object_t *func_obj_p); + +#if JERRY_BUILTIN_REALMS +ecma_object_t *ecma_builtin_get_from_realm (ecma_global_object_t *global_object_p, ecma_builtin_id_t builtin_id); +#endif /* JERRY_BUILTIN_REALMS */ + +#endif /* !ECMA_BUILTINS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h new file mode 100644 index 0000000..9cbfae2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h @@ -0,0 +1,747 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Description of built-in objects + in format (ECMA_BUILTIN_ID_id, object_type, prototype_id, is_extensible, is_static, underscored_id) */ + +/* The Object.prototype object (15.2.4) */ +BUILTIN (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID__COUNT /* no prototype */, + true, + object_prototype) + +/* The Object object (15.2.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_OBJECT, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + object) + +#if JERRY_BUILTIN_ARRAY +/* The Array.prototype object (15.4.4) */ +BUILTIN (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_ARRAY, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + array_prototype) + +/* The Array object (15.4.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + array) +#endif /* JERRY_BUILTIN_ARRAY */ + +#if JERRY_BUILTIN_DATE +/* The Date.prototype object (20.3.4) */ +BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + date_prototype) +#endif /* JERRY_BUILTIN_DATE */ + +#if JERRY_BUILTIN_REGEXP +/* The RegExp.prototype object (21.2.5) */ +BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + regexp_prototype) +#endif /* JERRY_BUILTIN_REGEXP */ + +#if JERRY_BUILTIN_STRING +/* The String.prototype object (15.5.4) */ +BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_CLASS, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + string_prototype) + +/* The String object (15.5.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_STRING, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + string) +#endif /* JERRY_BUILTIN_STRING */ + +#if JERRY_BUILTIN_BOOLEAN +/* The Boolean.prototype object (15.6.4) */ +BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_CLASS, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + boolean_prototype) + +/* The Boolean object (15.6.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BOOLEAN, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + boolean) +#endif /* JERRY_BUILTIN_BOOLEAN */ + +#if JERRY_BUILTIN_NUMBER +/* The Number.prototype object (15.7.4) */ +BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_CLASS, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + number_prototype) + +/* The Number object (15.7.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_NUMBER, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + number) +#endif /* JERRY_BUILTIN_NUMBER */ + +/* The Function.prototype object (15.3.4) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + function_prototype) + +/* The Function object (15.3.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FUNCTION, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + function) + +#if JERRY_BUILTIN_MATH +/* The Math object (15.8) */ +BUILTIN (ECMA_BUILTIN_ID_MATH, ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, true, math) +#endif /* JERRY_BUILTIN_MATH */ + +#if JERRY_BUILTIN_REFLECT + +/* The Reflect object (26.1) */ +BUILTIN (ECMA_BUILTIN_ID_REFLECT, ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, true, reflect) +#endif /* JERRY_BUILTIN_REFLECT */ + +#if JERRY_BUILTIN_ATOMICS +/* The Atomics object (24.4) */ +BUILTIN (ECMA_BUILTIN_ID_ATOMICS, ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, true, atomics) +#endif /* JERRY_BUILTIN_ATOMICS */ + +#if JERRY_BUILTIN_DATE +/* The Date object (15.9.3) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_DATE, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + date) +#endif /* JERRY_BUILTIN_DATE */ + +#if JERRY_BUILTIN_REGEXP +/* The RegExp object (15.10) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_REGEXP, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + regexp) +#endif /* JERRY_BUILTIN_REGEXP */ + +#define ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID ECMA_BUILTIN_ID_ERROR + +/* The Error object (15.11.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + error) + +/* The Error.prototype object (15.11.4) */ +BUILTIN (ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + error_prototype) + +#if JERRY_BUILTIN_ERRORS +/* The EvalError.prototype object (15.11.6.1) */ +BUILTIN (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + eval_error_prototype) + +/* The EvalError object (15.11.6.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_EVAL_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + eval_error) + +/* The RangeError.prototype object (15.11.6.2) */ +BUILTIN (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + range_error_prototype) + +/* The RangeError object (15.11.6.2) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_RANGE_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + range_error) + +/* The ReferenceError.prototype object (15.11.6.3) */ +BUILTIN (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + reference_error_prototype) + +/* The ReferenceError object (15.11.6.3) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_REFERENCE_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + reference_error) + +/* The SyntaxError.prototype object (15.11.6.4) */ +BUILTIN (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + syntax_error_prototype) + +/* The SyntaxError object (15.11.6.4) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SYNTAX_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + syntax_error) + +/* The TypeError.prototype object (15.11.6.5) */ +BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + type_error_prototype) + +/* The TypeError object (15.11.6.5) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_TYPE_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + type_error) + +/* The AggregateError.prototype object (15.11.6.5) */ +BUILTIN (ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + aggregate_error_prototype) + +/* The AggregateError object (15.11.6.5) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_AGGREGATE_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + aggregate_error) + +/* The URIError.prototype object (15.11.6.6) */ +BUILTIN (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, + true, + uri_error_prototype) + +/* The URIError object (15.11.6.6) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_URI_ERROR, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID, + true, + uri_error) +#endif /* JERRY_BUILTIN_ERRORS */ + +/**< The [[ThrowTypeError]] object (13.2.3) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + false, + type_error_thrower) + +#if JERRY_BUILTIN_TYPEDARRAY + +/* The ArrayBuffer.prototype object (ES2015 24.1.4) */ +BUILTIN (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + arraybuffer_prototype) + +/* The ArrayBuffer object (ES2015 24.1.2) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ARRAYBUFFER, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + arraybuffer) + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +/* The SharedArrayBuffer.prototype object (ES2015 24.2.4) */ +BUILTIN (ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + shared_arraybuffer_prototype) + +/* The SharedArrayBuffer object (ES2015 24.2.2) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + shared_arraybuffer) +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + +/* The %TypedArrayPrototype% object (ES2015 24.2.3) */ +BUILTIN (ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + typedarray_prototype) + +/* The %TypedArray% intrinsic object (ES2015 22.2.1) + Note: The routines must be in this order. */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_TYPEDARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + typedarray) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT8ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + int8array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT8ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + uint8array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + uint8clampedarray) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT16ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + int16array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT16ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + uint16array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT32ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + int32array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT32ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + uint32array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FLOAT32ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + float32array) + +#if JERRY_NUMBER_TYPE_FLOAT64 +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FLOAT64ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + float64array) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +#if JERRY_BUILTIN_BIGINT +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BIGINT64ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + bigint64array) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BIGUINT64ARRAY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_TYPEDARRAY, + true, + biguint64array) +#endif /* JERRY_BUILTIN_BIGINT */ + +BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + int8array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + uint8array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + uint8clampedarray_prototype) + +BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + int16array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + uint16array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + int32array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + uint32array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + float32array_prototype) + +#if JERRY_NUMBER_TYPE_FLOAT64 +BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + float64array_prototype) +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +#if JERRY_BUILTIN_BIGINT +BUILTIN (ECMA_BUILTIN_ID_BIGINT64ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + bigint64array_prototype) + +BUILTIN (ECMA_BUILTIN_ID_BIGUINT64ARRAY_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, + true, + biguint64array_prototype) +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +BUILTIN (ECMA_BUILTIN_ID_PROMISE_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + promise_prototype) + +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_PROMISE, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + promise) + +#if JERRY_BUILTIN_CONTAINER + +/* The Map prototype object (23.1.3) */ +BUILTIN (ECMA_BUILTIN_ID_MAP_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + map_prototype) + +/* The Map routine (ECMA-262 v6, 23.1.1.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_MAP, ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, true, map) + +/* The Set prototype object (23.1.3) */ +BUILTIN (ECMA_BUILTIN_ID_SET_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + set_prototype) + +/* The Set routine (ECMA-262 v6, 23.1.1.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SET, ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, true, set) + +/* The WeakMap prototype object (23.1.3) */ +BUILTIN (ECMA_BUILTIN_ID_WEAKMAP_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + weakmap_prototype) + +/* The WeakMap routine (ECMA-262 v6, 23.1.1.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_WEAKMAP, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + weakmap) + +/* The WeakSet prototype object (23.1.3) */ +BUILTIN (ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + weakset_prototype) + +/* The WeakSet routine (ECMA-262 v6, 23.1.1.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_WEAKSET, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + weakset) + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#if JERRY_BUILTIN_WEAKREF + +/* The WeakRef prototype object */ +BUILTIN (ECMA_BUILTIN_ID_WEAKREF_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + weakref_prototype) + +/* The WeakRef routine */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_WEAKREF, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + weakref) + +#endif /* JERRY_BUILTIN_WEAKREF */ + +#if (JERRY_BUILTIN_PROXY) +/* The Proxy routine (ECMA-262 v6, 26.2.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_PROXY, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + proxy) +#endif /* JERRY_BUILTIN_PROXY */ + +/* Intrinsic hidden builtin object */ +BUILTIN (ECMA_BUILTIN_ID_INTRINSIC_OBJECT, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID__COUNT /* no prototype */, + true, + intrinsic) + +/* The Array.prototype[@@unscopables] object */ +BUILTIN (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE_UNSCOPABLES, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID__COUNT /* no prototype */, + true, + array_prototype_unscopables) + +/* The Symbol prototype object (ECMA-262 v6, 19.4.2.7) */ +BUILTIN (ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + symbol_prototype) + +/* The Symbol routine (ECMA-262 v6, 19.4.2.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SYMBOL, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + symbol) + +/* The %AsyncFunction% object (ECMA-262 v11, 25.7.2) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ASYNC_FUNCTION, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION, + true, + async_function) + +/* The %AsyncFunctionPrototype% object (ECMA-262 v11, 25.7.3) */ +BUILTIN (ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + async_function_prototype) + +/* The %IteratorPrototype% object (ECMA-262 v6, 25.1.2) */ +BUILTIN (ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + iterator_prototype) + +/* The %ArrayIteratorPrototype% object (ECMA-262 v6, 22.1.5.2) */ +BUILTIN (ECMA_BUILTIN_ID_ARRAY_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + true, + array_iterator_prototype) + +/* The %StringIteratorPrototype% object (ECMA-262 v6, 22.1.5.2) */ +BUILTIN (ECMA_BUILTIN_ID_STRING_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + true, + string_iterator_prototype) + +/* The %RegExpStringIteratorPrototype% object (ECMA-262 v11, 21.2.7.1) */ +BUILTIN (ECMA_BUILTIN_ID_REGEXP_STRING_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + true, + regexp_string_iterator_prototype) + +/* The %AsyncIteratorPrototype% object (ECMA-262 v10, 25.1.3) */ +BUILTIN (ECMA_BUILTIN_ID_ASYNC_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + async_iterator_prototype) + +/* The %AsyncFromSyncIteratorPrototype% object (ECMA-262 v11, 25.1.4.2) */ +BUILTIN (ECMA_BUILTIN_ID_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ASYNC_ITERATOR_PROTOTYPE, + true, + async_from_sync_iterator_prototype) + +/* The %(GeneratorFunction)% object */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_GENERATOR_FUNCTION, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION, + true, + generator_function) + +/* The %(Generator)% object */ +BUILTIN (ECMA_BUILTIN_ID_GENERATOR, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + generator) + +/* The %(Generator).prototype% object */ +BUILTIN (ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + true, + generator_prototype) + +/* The %(AsyncGeneratorFunction)% object */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION, + true, + async_generator_function) + +/* The %(AsyncGenerator)% object */ +BUILTIN (ECMA_BUILTIN_ID_ASYNC_GENERATOR, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + async_generator) + +/* The %(AsyncGenerator).prototype% object */ +BUILTIN (ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ASYNC_ITERATOR_PROTOTYPE, + true, + async_generator_prototype) + +#if JERRY_BUILTIN_CONTAINER +/* The %SetIteratorPrototype% object (ECMA-262 v6, 23.2.5.2) */ +BUILTIN (ECMA_BUILTIN_ID_SET_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + true, + set_iterator_prototype) + +/* The %MapIteratorPrototype% object (ECMA-262 v6, 23.1.5.2) */ +BUILTIN (ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_ITERATOR_PROTOTYPE, + true, + map_iterator_prototype) +#endif /* JERRY_BUILTIN_CONTAINER */ + +#if JERRY_BUILTIN_BIGINT +/* The %BigInt.prototype% object */ +BUILTIN (ECMA_BUILTIN_ID_BIGINT_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + bigint_prototype) + +/* The %BigInt% object */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_BIGINT, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + bigint) +#endif /* JERRY_BUILTIN_BIGINT */ + +#if JERRY_BUILTIN_DATAVIEW +/* The DataView prototype object (ECMA-262 v6, 24.2.3.1) */ +BUILTIN (ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + dataview_prototype) + +/* The DataView routine (ECMA-262 v6, 24.2.2.1) */ +BUILTIN_ROUTINE (ECMA_BUILTIN_ID_DATAVIEW, + ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + dataview) +#endif /* JERRY_BUILTIN_DATAVIEW */ + +/* The Global object (15.1) */ +BUILTIN (ECMA_BUILTIN_ID_GLOBAL, + ECMA_OBJECT_TYPE_BUILT_IN_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, /* Implementation-dependent */ + true, + global) + +#undef BUILTIN diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/meson.build new file mode 100644 index 0000000..89a95c0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/meson.build @@ -0,0 +1,182 @@ +subdir('typedarray') + +source_file = [ + 'ecma-builtin-aggregateerror-prototype.inc.h', + 'ecma-builtin-aggregateerror.inc.h', + 'ecma-builtin-array-iterator-prototype.inc.h', + 'ecma-builtin-array-prototype-unscopables.inc.h', + 'ecma-builtin-array-prototype.inc.h', + 'ecma-builtin-array.inc.h', + 'ecma-builtin-arraybuffer-prototype.inc.h', + 'ecma-builtin-arraybuffer.inc.h', + 'ecma-builtin-async-from-sync-iterator-prototype.inc.h', + 'ecma-builtin-async-function-prototype.inc.h', + 'ecma-builtin-async-function.inc.h', + 'ecma-builtin-async-generator-function.inc.h', + 'ecma-builtin-async-generator-prototype.inc.h', + 'ecma-builtin-async-generator.inc.h', + 'ecma-builtin-async-iterator-prototype.inc.h', + 'ecma-builtin-atomics.inc.h', + 'ecma-builtin-bigint-prototype.inc.h', + 'ecma-builtin-bigint.inc.h', + 'ecma-builtin-boolean-prototype.inc.h', + 'ecma-builtin-boolean.inc.h', + 'ecma-builtin-dataview-prototype.inc.h', + 'ecma-builtin-dataview.inc.h', + 'ecma-builtin-date-prototype.inc.h', + 'ecma-builtin-date.inc.h', + 'ecma-builtin-error-prototype.inc.h', + 'ecma-builtin-error.inc.h', + 'ecma-builtin-evalerror-prototype.inc.h', + 'ecma-builtin-evalerror.inc.h', + 'ecma-builtin-function-prototype.h', + 'ecma-builtin-function-prototype.inc.h', + 'ecma-builtin-function.inc.h', + 'ecma-builtin-generator-function.inc.h', + 'ecma-builtin-generator-prototype.inc.h', + 'ecma-builtin-generator.inc.h', + 'ecma-builtin-global.inc.h', + 'ecma-builtin-handlers.h', + 'ecma-builtin-handlers.inc.h', + 'ecma-builtin-helpers-macro-defines.inc.h', + 'ecma-builtin-helpers-macro-undefs.inc.h', + 'ecma-builtin-helpers.h', + 'ecma-builtin-internal-routines-template.inc.h', + 'ecma-builtin-intrinsic.inc.h', + 'ecma-builtin-iterator-prototype.inc.h', + 'ecma-builtin-map-iterator-prototype.inc.h', + 'ecma-builtin-map-prototype.inc.h', + 'ecma-builtin-map.inc.h', + 'ecma-builtin-math.inc.h', + 'ecma-builtin-number-prototype.inc.h', + 'ecma-builtin-number.inc.h', + 'ecma-builtin-object-prototype.inc.h', + 'ecma-builtin-object.h', + 'ecma-builtin-object.inc.h', + 'ecma-builtin-promise-prototype.inc.h', + 'ecma-builtin-promise.inc.h', + 'ecma-builtin-proxy.inc.h', + 'ecma-builtin-rangeerror-prototype.inc.h', + 'ecma-builtin-rangeerror.inc.h', + 'ecma-builtin-referenceerror-prototype.inc.h', + 'ecma-builtin-referenceerror.inc.h', + 'ecma-builtin-reflect.inc.h', + 'ecma-builtin-regexp-prototype.inc.h', + 'ecma-builtin-regexp-string-iterator-prototype.inc.h', + 'ecma-builtin-regexp.inc.h', + 'ecma-builtin-set-iterator-prototype.inc.h', + 'ecma-builtin-set-prototype.inc.h', + 'ecma-builtin-set.inc.h', + 'ecma-builtin-shared-arraybuffer-prototype.inc.h', + 'ecma-builtin-shared-arraybuffer.inc.h', + 'ecma-builtin-string-iterator-prototype.inc.h', + 'ecma-builtin-string-prototype.inc.h', + 'ecma-builtin-string.inc.h', + 'ecma-builtin-symbol-prototype.inc.h', + 'ecma-builtin-symbol.inc.h', + 'ecma-builtin-syntaxerror-prototype.inc.h', + 'ecma-builtin-syntaxerror.inc.h', + 'ecma-builtin-type-error-thrower.inc.h', + 'ecma-builtin-typeerror-prototype.inc.h', + 'ecma-builtin-typeerror.inc.h', + 'ecma-builtin-urierror-prototype.inc.h', + 'ecma-builtin-urierror.inc.h', + 'ecma-builtin-weakmap-prototype.inc.h', + 'ecma-builtin-weakmap.inc.h', + 'ecma-builtin-weakref-prototype.inc.h', + 'ecma-builtin-weakref.inc.h', + 'ecma-builtin-weakset-prototype.inc.h', + 'ecma-builtin-weakset.inc.h', + 'ecma-builtins-internal.h', + 'ecma-builtins.h', + 'ecma-builtins.inc.h', + 'ecma-builtin-aggregateerror-prototype.cpp', + 'ecma-builtin-aggregateerror.cpp', + 'ecma-builtin-array-iterator-prototype.cpp', + 'ecma-builtin-array-prototype-unscopables.cpp', + 'ecma-builtin-array-prototype.cpp', + 'ecma-builtin-array.cpp', + 'ecma-builtin-arraybuffer-prototype.cpp', + 'ecma-builtin-arraybuffer.cpp', + 'ecma-builtin-async-from-sync-iterator-prototype.cpp', + 'ecma-builtin-async-function-prototype.cpp', + 'ecma-builtin-async-function.cpp', + 'ecma-builtin-async-generator-function.cpp', + 'ecma-builtin-async-generator-prototype.cpp', + 'ecma-builtin-async-generator.cpp', + 'ecma-builtin-async-iterator-prototype.cpp', + 'ecma-builtin-atomics.cpp', + 'ecma-builtin-bigint-prototype.cpp', + 'ecma-builtin-bigint.cpp', + 'ecma-builtin-boolean-prototype.cpp', + 'ecma-builtin-boolean.cpp', + 'ecma-builtin-dataview-prototype.cpp', + 'ecma-builtin-dataview.cpp', + 'ecma-builtin-date-prototype.cpp', + 'ecma-builtin-date.cpp', + 'ecma-builtin-error-prototype.cpp', + 'ecma-builtin-error.cpp', + 'ecma-builtin-evalerror-prototype.cpp', + 'ecma-builtin-evalerror.cpp', + 'ecma-builtin-function-prototype.cpp', + 'ecma-builtin-function.cpp', + 'ecma-builtin-generator-function.cpp', + 'ecma-builtin-generator-prototype.cpp', + 'ecma-builtin-generator.cpp', + 'ecma-builtin-global.cpp', + 'ecma-builtin-handlers.cpp', + 'ecma-builtin-helpers-date.cpp', + 'ecma-builtin-helpers-error.cpp', + 'ecma-builtin-helpers-sort.cpp', + 'ecma-builtin-helpers.cpp', + 'ecma-builtin-intrinsic.cpp', + 'ecma-builtin-iterator-prototype.cpp', + 'ecma-builtin-map-iterator-prototype.cpp', + 'ecma-builtin-map-prototype.cpp', + 'ecma-builtin-map.cpp', + 'ecma-builtin-math.cpp', + 'ecma-builtin-number-prototype.cpp', + 'ecma-builtin-number.cpp', + 'ecma-builtin-object-prototype.cpp', + 'ecma-builtin-object.cpp', + 'ecma-builtin-promise-prototype.cpp', + 'ecma-builtin-promise.cpp', + 'ecma-builtin-proxy.cpp', + 'ecma-builtin-rangeerror-prototype.cpp', + 'ecma-builtin-rangeerror.cpp', + 'ecma-builtin-referenceerror-prototype.cpp', + 'ecma-builtin-referenceerror.cpp', + 'ecma-builtin-reflect.cpp', + 'ecma-builtin-regexp-prototype.cpp', + 'ecma-builtin-regexp-string-iterator-prototype.cpp', + 'ecma-builtin-regexp.cpp', + 'ecma-builtin-set-iterator-prototype.cpp', + 'ecma-builtin-set-prototype.cpp', + 'ecma-builtin-set.cpp', + 'ecma-builtin-shared-arraybuffer-prototype.cpp', + 'ecma-builtin-shared-arraybuffer.cpp', + 'ecma-builtin-string-iterator-prototype.cpp', + 'ecma-builtin-string-prototype.cpp', + 'ecma-builtin-string.cpp', + 'ecma-builtin-symbol-prototype.cpp', + 'ecma-builtin-symbol.cpp', + 'ecma-builtin-syntaxerror-prototype.cpp', + 'ecma-builtin-syntaxerror.cpp', + 'ecma-builtin-type-error-thrower.cpp', + 'ecma-builtin-typeerror-prototype.cpp', + 'ecma-builtin-typeerror.cpp', + 'ecma-builtin-urierror-prototype.cpp', + 'ecma-builtin-urierror.cpp', + 'ecma-builtin-weakmap-prototype.cpp', + 'ecma-builtin-weakmap.cpp', + 'ecma-builtin-weakref-prototype.cpp', + 'ecma-builtin-weakref.cpp', + 'ecma-builtin-weakset-prototype.cpp', + 'ecma-builtin-weakset.cpp', + 'ecma-builtins.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array-prototype.cpp new file mode 100644 index 0000000..3b33e03 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array-prototype.cpp @@ -0,0 +1,45 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-bigint64array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID bigint64array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup bigint64arrayprototype ECMA BigInt64Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array-prototype.inc.h new file mode 100644 index 0000000..5e1087b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * BigInt64Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define TYPEDARRAY_BYTES_PER_ELEMENT 8 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_BIGINT64ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array.cpp new file mode 100644 index 0000000..ae7fc96 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array.cpp @@ -0,0 +1,79 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-bigint64array.inc.h" +#define BUILTIN_UNDERSCORED_ID bigint64array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup bigint64array ECMA BigInt64Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of BigInt64Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_bigint64array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_BIGINT64_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_bigint64array_dispatch_call */ + +/** + * Handle calling [[Construct]] of BigInt64Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_bigint64array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_BIGINT64_ARRAY); +} /* ecma_builtin_bigint64array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array.inc.h new file mode 100644 index 0000000..176fc26 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-bigint64array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * BigInt64Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 8 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_BIGINT64_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_BIGINT64ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array-prototype.cpp new file mode 100644 index 0000000..9844fbd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array-prototype.cpp @@ -0,0 +1,45 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-biguint64array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID biguint64array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup biguint64arrayprototype ECMA BigUInt64Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array-prototype.inc.h new file mode 100644 index 0000000..0362644 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * BigUInt64Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define TYPEDARRAY_BYTES_PER_ELEMENT 8 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_BIGUINT64ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array.cpp new file mode 100644 index 0000000..2482ec2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array.cpp @@ -0,0 +1,79 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-biguint64array.inc.h" +#define BUILTIN_UNDERSCORED_ID biguint64array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup biguint64array ECMA BigUInt64Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of BigUInt64Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_biguint64array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_BIG_UINT64_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_biguint64array_dispatch_call */ + +/** + * Handle calling [[Construct]] of BigUInt64Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_biguint64array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_BIGUINT64_ARRAY); +} /* ecma_builtin_biguint64array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array.inc.h new file mode 100644 index 0000000..ea38782 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-biguint64array.inc.h @@ -0,0 +1,29 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * BigUInt64Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_BUILTIN_BIGINT + +#define TYPEDARRAY_BYTES_PER_ELEMENT 8 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_BIGUINT64_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_BIGUINT64ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_BIGINT */ +#endif /* JERRY_BUILTIN_TYPEDARRAY && JERRY_BUILTIN_BIGINT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array-prototype.cpp new file mode 100644 index 0000000..1e6a604 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float32array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID float32array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup float32arrayprototype ECMA Float32Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array-prototype.inc.h new file mode 100644 index 0000000..56bfeea --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Float32Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 4 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_FLOAT32ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array.cpp new file mode 100644 index 0000000..f4f3959 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float32array.inc.h" +#define BUILTIN_UNDERSCORED_ID float32array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup float32array ECMA Float32Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Float32Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_float32array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_FLOAT32_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_float32array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Float32Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_float32array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_FLOAT32_ARRAY); +} /* ecma_builtin_float32array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array.inc.h new file mode 100644 index 0000000..832b511 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float32array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Float32Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 4 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_FLOAT32_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array-prototype.cpp new file mode 100644 index 0000000..205d23a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array-prototype.cpp @@ -0,0 +1,45 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_NUMBER_TYPE_FLOAT64 + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float64array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID float64array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup float64arrayprototype ECMA Float64Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array-prototype.inc.h new file mode 100644 index 0000000..815be71 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array-prototype.inc.h @@ -0,0 +1,28 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Float64Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_NUMBER_TYPE_FLOAT64 + +#define TYPEDARRAY_BYTES_PER_ELEMENT 8 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_FLOAT64ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array.cpp new file mode 100644 index 0000000..fe3cebb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array.cpp @@ -0,0 +1,79 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_NUMBER_TYPE_FLOAT64 + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float64array.inc.h" +#define BUILTIN_UNDERSCORED_ID float64array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup float64array ECMA Float64Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Float64Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_float64array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_FLOAT64_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_float64array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Float64Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_float64array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_FLOAT64_ARRAY); +} /* ecma_builtin_float64array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array.inc.h new file mode 100644 index 0000000..ea8bd42 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-float64array.inc.h @@ -0,0 +1,29 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Float64Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY +#if JERRY_NUMBER_TYPE_FLOAT64 + +#define TYPEDARRAY_BYTES_PER_ELEMENT 8 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_FLOAT64_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_FLOAT64ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array-prototype.cpp new file mode 100644 index 0000000..1b9c435 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int16array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID int16array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup int16arrayprototype ECMA Int16Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array-prototype.inc.h new file mode 100644 index 0000000..7815d9a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Int16Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 2 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_INT16ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array.cpp new file mode 100644 index 0000000..076a853 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int16array.inc.h" +#define BUILTIN_UNDERSCORED_ID int16array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup int64array ECMA Int16Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Int16Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_int16array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_INT16_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_int16array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Int16Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_int16array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_INT16_ARRAY); +} /* ecma_builtin_int16array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array.inc.h new file mode 100644 index 0000000..f744ed7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int16array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Int16Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 2 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_INT16_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_INT16ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array-prototype.cpp new file mode 100644 index 0000000..36fc847 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int32array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID int32array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup int32arrayprototype ECMA Int32Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array-prototype.inc.h new file mode 100644 index 0000000..9a31a06 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Int32Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 4 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_INT32ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array.cpp new file mode 100644 index 0000000..a322a30 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int32array.inc.h" +#define BUILTIN_UNDERSCORED_ID int32array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup int32array ECMA Int32Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Int32Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_int32array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_INT32_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_int32array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Int32Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_int32array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_INT32_ARRAY); +} /* ecma_builtin_int32array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array.inc.h new file mode 100644 index 0000000..ac786a0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int32array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Int32Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 4 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_INT32_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_INT32ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array-prototype.cpp new file mode 100644 index 0000000..8221f30 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int8array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID int8array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup int8arrayprototype ECMA Int8Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array-prototype.inc.h new file mode 100644 index 0000000..99d072b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Int8Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 1 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_INT8ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array.cpp new file mode 100644 index 0000000..402e383 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int8array.inc.h" +#define BUILTIN_UNDERSCORED_ID int8array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup int8array ECMA Int8Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Int8Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_int8array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_INT8_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_int8array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Int8Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_int8array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_INT8_ARRAY); +} /* ecma_builtin_int8array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array.inc.h new file mode 100644 index 0000000..25c84de --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-int8array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Int8Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 1 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_INT8_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.cpp new file mode 100644 index 0000000..23681dd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.cpp @@ -0,0 +1,74 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtin-typedarray-helpers.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#include "ecma-builtins.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-objects.h" +#include "ecma-typedarray-object.h" + +#include "jcontext.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * Common implementation of the [[Construct]] call of TypedArrays. + * + * @return ecma value of the new TypedArray object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len, /**< number of arguments */ + ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + ecma_builtin_id_t proto_id = ecma_typedarray_helper_get_prototype_id (typedarray_id); + ecma_object_t *prototype_obj_p = NULL; + ecma_object_t *current_new_target_p = JERRY_CONTEXT (current_new_target_p); + + if (current_new_target_p != NULL) + { + prototype_obj_p = ecma_op_get_prototype_from_constructor (current_new_target_p, proto_id); + if (prototype_obj_p == NULL) + { + return ECMA_VALUE_ERROR; + } + } + else + { + prototype_obj_p = ecma_builtin_get (proto_id); + } + + ecma_value_t val = ecma_op_create_typedarray (arguments_list_p, + arguments_list_len, + prototype_obj_p, + ecma_typedarray_helper_get_shift_size (typedarray_id), + typedarray_id); + + if (current_new_target_p != NULL) + { + ecma_deref_object (prototype_obj_p); + } + + return val; +} /* ecma_typedarray_helper_dispatch_construct */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.h new file mode 100644 index 0000000..d406437 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.h @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_TYPEDARRAY_HELPERS_H +#define ECMA_TYPEDARRAY_HELPERS_H +#include "ecma-globals.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations + * @{ + */ + +ecma_value_t ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len, + ecma_typedarray_type_t typedarray_id); + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#endif /* !ECMA_TYPEDARRAY_HELPERS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype-template.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype-template.inc.h new file mode 100644 index 0000000..beb6335 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype-template.inc.h @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#ifndef TYPEDARRAY_BYTES_PER_ELEMENT +#error "Please define TYPEDARRAY_BYTES_PER_ELEMENT" +#endif /* !TYPEDARRAY_BYTES_PER_ELEMENT */ + +#ifndef TYPEDARRAY_BUILTIN_ID +#error "Please define TYPEDARRAY_BUILTIN_ID" +#endif /* !TYPEDARRAY_BUILTIN_ID */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ES2015 22.2.3.4 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, TYPEDARRAY_BUILTIN_ID, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* ES2015 22.2.6.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U, TYPEDARRAY_BYTES_PER_ELEMENT, ECMA_PROPERTY_FIXED) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" + +#undef TYPEDARRAY_BUILTIN_ID +#undef TYPEDARRAY_BYTES_PER_ELEMENT + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.cpp new file mode 100644 index 0000000..0515634 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.cpp @@ -0,0 +1,2106 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ecma-arraybuffer-object.h" +#include "ecma-bigint.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtin-typedarray-helpers.h" +#include "ecma-builtins.h" +#include "ecma-comparison.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-number-object.h" +#include "ecma-objects.h" +#include "ecma-typedarray-object.h" + +#include "jcontext.h" +#include "jmem.h" +#include "jrt-libc-includes.h" +#include "jrt.h" +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + /* These routines must be in this order */ + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_START = 0, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_MAP, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE_RIGHT, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_EVERY, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SOME, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FOR_EACH, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FILTER, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND_INDEX, + + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INDEX_OF, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_AT, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_LAST_INDEX_OF, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INCLUDES, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FILL, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SORT, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REVERSE, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_COPY_WITHIN, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SLICE, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SUBARRAY, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_LOCALE_STRING, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_JOIN, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_KEYS, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_ENTRIES, + + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BUFFER_GETTER, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BYTELENGTH_GETTER, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BYTEOFFSET_GETTER, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_LENGTH_GETTER, + + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SET, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_STRING_TAG_GETTER, +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typedarray-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID typedarray_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup typedarrayprototype ECMA %TypedArray%.prototype object built-in + * @{ + */ + +/** + * Type of routine. + */ +typedef enum +{ + TYPEDARRAY_ROUTINE_EVERY, /**< routine: every ES2015, 22.2.3.7 */ + TYPEDARRAY_ROUTINE_SOME, /**< routine: some ES2015, 22.2.3.9 */ + TYPEDARRAY_ROUTINE_FOREACH, /**< routine: forEach ES2015, 15.4.4.18 */ + TYPEDARRAY_ROUTINE__COUNT /**< count of the modes */ +} typedarray_routine_mode; + +/** + * The common function for 'every', 'some' and 'forEach' + * because they have a similar structure. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_exec_routine (ecma_value_t this_arg, /**< this argument */ + ecma_typedarray_info_t *info_p, /**< object info */ + ecma_value_t cb_func_val, /**< callback function */ + ecma_value_t cb_this_arg, /**< 'this' of the callback function */ + typedarray_routine_mode mode) /**< mode: which routine */ +{ + JERRY_ASSERT (mode < TYPEDARRAY_ROUTINE__COUNT); + + ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg); + ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val); + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + uint32_t byte_pos = 0; + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + for (uint32_t index = 0; index < info_p->length && ecma_is_value_empty (ret_value); index++) + { + ecma_value_t current_index = ecma_make_uint32_value (index); + ecma_value_t element = typedarray_getter_cb (buffer_p + byte_pos); + + ecma_value_t call_args[] = { element, current_index, this_arg }; + + ecma_value_t call_value = ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3); + + ecma_fast_free_value (current_index); + ecma_fast_free_value (element); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + return call_value; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + ecma_free_value (call_value); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + bool to_bool_result = ecma_op_to_boolean (call_value); + ecma_free_value (call_value); + + if (mode == TYPEDARRAY_ROUTINE_EVERY) + { + if (!to_bool_result) + { + return ECMA_VALUE_FALSE; + } + } + else if (mode == TYPEDARRAY_ROUTINE_SOME && to_bool_result) + { + return ECMA_VALUE_TRUE; + } + + byte_pos += info_p->element_size; + } + + if (mode == TYPEDARRAY_ROUTINE_EVERY) + { + ret_value = ECMA_VALUE_TRUE; + } + else if (mode == TYPEDARRAY_ROUTINE_SOME) + { + ret_value = ECMA_VALUE_FALSE; + } + else + { + ret_value = ECMA_VALUE_UNDEFINED; + } + + return ret_value; +} /* ecma_builtin_typedarray_prototype_exec_routine */ + +/** + * The %TypedArray%.prototype object's 'map' routine + * + * See also: + * ES2015, 22.2.3.8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_map (ecma_value_t this_arg, /**< this object */ + ecma_typedarray_info_t *src_info_p, /**< object info */ + ecma_value_t cb_func_val, /**< callback function */ + ecma_value_t cb_this_arg) /**< this' of the callback function */ +{ + ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (src_info_p->array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (src_info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + // TODO: 22.2.3.18, 7-8. + ecma_value_t len = ecma_make_number_value (src_info_p->length); + ecma_value_t new_typedarray = ecma_typedarray_species_create (this_arg, &len, 1); + ecma_free_value (len); + + if (ECMA_IS_VALUE_ERROR (new_typedarray)) + { + return new_typedarray; + } + + ecma_object_t *target_obj_p = ecma_get_object_from_value (new_typedarray); + + uint8_t *src_buffer_p = ecma_typedarray_get_buffer (src_info_p); + + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (target_obj_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (target_info.array_buffer_p)) + { + ecma_deref_object (target_obj_p); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (target_info.array_buffer_p)) + { + ecma_deref_object (target_obj_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *target_buffer_p = ecma_typedarray_get_buffer (&target_info); + + ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (src_info_p->id); + ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.id); + + for (uint32_t index = 0; index < src_info_p->length; index++) + { + ecma_value_t current_index = ecma_make_uint32_value (index); + ecma_value_t element = src_typedarray_getter_cb (src_buffer_p); + src_buffer_p += src_info_p->element_size; + + ecma_value_t call_args[] = { element, current_index, this_arg }; + ecma_value_t mapped_value = ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3); + + ecma_free_value (current_index); + ecma_free_value (element); + + if (ECMA_IS_VALUE_ERROR (mapped_value)) + { + ecma_free_value (new_typedarray); + return mapped_value; + } + + if (ecma_arraybuffer_is_detached (src_info_p->array_buffer_p)) + { + ecma_free_value (mapped_value); + ecma_free_value (new_typedarray); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_value_t set_element = target_typedarray_setter_cb (target_buffer_p, mapped_value); + target_buffer_p += target_info.element_size; + ecma_free_value (mapped_value); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_free_value (new_typedarray); + return set_element; + } + } + + return new_typedarray; +} /* ecma_builtin_typedarray_prototype_map */ + +/** + * Reduce and reduceRight routines share a similar structure. + * And we use 'is_right' to distinguish between them. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_reduce_with_direction (ecma_value_t this_arg, /**< this object */ + ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t arguments_list_p[], /**arg_list*/ + uint32_t arguments_number, /**< length of arguments' list*/ + bool is_right) /**< choose order, true is reduceRight */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + uint32_t byte_pos; + + if (info_p->length == 0) + { + if (arguments_number < 2) + { + return ecma_raise_type_error (ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED); + } + + return ecma_copy_value (arguments_list_p[1]); + } + + JERRY_ASSERT (info_p->length > 0); + + ecma_value_t accumulator = ECMA_VALUE_UNDEFINED; + uint32_t index = is_right ? (info_p->length - 1) : 0; + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + + if (ecma_is_value_undefined (arguments_list_p[1])) + { + byte_pos = index << info_p->shift; + accumulator = getter_cb (buffer_p + byte_pos); + + if (is_right) + { + if (index == 0) + { + return accumulator; + } + + index--; + } + else + { + index++; + + if (index == info_p->length) + { + return accumulator; + } + } + } + else + { + accumulator = ecma_copy_value (arguments_list_p[1]); + } + + ecma_object_t *func_object_p = ecma_get_object_from_value (arguments_list_p[0]); + + while (true) + { + ecma_value_t current_index = ecma_make_uint32_value (index); + byte_pos = index << info_p->shift; + ecma_value_t get_value = getter_cb (buffer_p + byte_pos); + + ecma_value_t call_args[] = { accumulator, get_value, current_index, this_arg }; + + JERRY_ASSERT (ecma_is_value_number (get_value) || ecma_is_value_bigint (get_value)); + + ecma_value_t call_value = ecma_op_function_call (func_object_p, ECMA_VALUE_UNDEFINED, call_args, 4); + + ecma_fast_free_value (accumulator); + ecma_fast_free_value (get_value); + ecma_fast_free_value (current_index); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + return call_value; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + ecma_free_value (call_value); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + accumulator = call_value; + + if (is_right) + { + if (index == 0) + { + break; + } + + index--; + } + else + { + index++; + + if (index == info_p->length) + { + break; + } + } + } + + return accumulator; +} /* ecma_builtin_typedarray_prototype_reduce_with_direction */ + +/** + * The %TypedArray%.prototype object's 'filter' routine + * + * See also: + * ES2015, 22.2.3.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this object */ + ecma_typedarray_info_t *info_p, /**< object info */ + ecma_value_t cb_func_val, /**< callback function */ + ecma_value_t cb_this_arg) /**< 'this' of the callback function */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + + ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val); + ecma_value_t ret_value = ECMA_VALUE_ERROR; + + // TODO: 22.2.3.9, 7-8. + if (info_p->length == 0) + { + return ecma_op_create_typedarray_with_type_and_length (info_p->id, 0); + } + + ecma_collection_t *collected_p = ecma_new_collection (); + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + ecma_value_t collected; + + for (uint32_t index = 0; index < info_p->length; index++) + { + ecma_value_t current_index = ecma_make_uint32_value (index); + ecma_value_t get_value = getter_cb (buffer_p); + + JERRY_ASSERT (ecma_is_value_number (get_value) || ecma_is_value_bigint (get_value)); + + ecma_value_t call_args[] = { get_value, current_index, this_arg }; + + ecma_value_t call_value = ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3); + + ecma_fast_free_value (current_index); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + ecma_fast_free_value (get_value); + goto cleanup; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + ecma_free_value (call_value); + ecma_fast_free_value (get_value); + ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + goto cleanup; + } + + if (ecma_op_to_boolean (call_value)) + { + ecma_collection_push_back (collected_p, get_value); + } + else + { + ecma_fast_free_value (get_value); + } + + buffer_p += info_p->element_size; + ecma_fast_free_value (call_value); + } + + collected = ecma_make_number_value (collected_p->item_count); + ret_value = ecma_typedarray_species_create (this_arg, &collected, 1); + ecma_free_value (collected); + + if (!ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_object_t *new_typedarray_p = ecma_get_object_from_value (ret_value); + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (new_typedarray_p); + + JERRY_ASSERT (target_info.offset == 0); + + uint8_t *target_buffer_p = ecma_typedarray_get_buffer (&target_info); + + ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.id); + + for (uint32_t idx = 0; idx < collected_p->item_count; idx++) + { + ecma_value_t set_element = target_typedarray_setter_cb (target_buffer_p, collected_p->buffer_p[idx]); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_deref_object (new_typedarray_p); + ret_value = ECMA_VALUE_ERROR; + goto cleanup; + } + + target_buffer_p += target_info.element_size; + } + } + +cleanup: + ecma_collection_free (collected_p); + + return ret_value; +} /* ecma_builtin_typedarray_prototype_filter */ + +/** + * The %TypedArray%.prototype object's 'reverse' routine + * + * See also: + * ES2015, 22.2.3.21 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_reverse (ecma_value_t this_arg, /**< this argument */ + ecma_typedarray_info_t *info_p) /**< object info */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + uint32_t middle = (info_p->length / 2) << info_p->shift; + uint32_t buffer_last = (info_p->length << info_p->shift) - info_p->element_size; + + for (uint32_t lower = 0; lower < middle; lower += info_p->element_size) + { + uint32_t upper = buffer_last - lower; + uint8_t *lower_p = buffer_p + lower; + uint8_t *upper_p = buffer_p + upper; + + uint8_t tmp[8]; + memcpy (&tmp[0], lower_p, info_p->element_size); + memcpy (lower_p, upper_p, info_p->element_size); + memcpy (upper_p, &tmp[0], info_p->element_size); + } + + return ecma_copy_value (this_arg); +} /* ecma_builtin_typedarray_prototype_reverse */ + +/** + * The %TypedArray%.prototype object's 'set' routine for a typedArray source + * + * See also: + * ES2015, 22.2.3.22, 22.2.3.22.2 + * + * @return ecma value of undefined if success, error otherwise. + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_op_typedarray_set_with_typedarray (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arr_val, /**< typedarray object */ + ecma_value_t offset_val) /**< offset value */ +{ + /* 6.~ 8. targetOffset */ + ecma_number_t target_offset_num; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (offset_val, &target_offset_num))) + { + return ECMA_VALUE_ERROR; + } + + if (target_offset_num <= -1.0 || target_offset_num >= (ecma_number_t) UINT32_MAX + 0.5) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_OFFSET); + } + + ecma_object_t *target_typedarray_p = ecma_get_object_from_value (this_arg); + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (target_typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (target_info.array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (target_info.array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *target_buffer_p = ecma_typedarray_get_buffer (&target_info); + + ecma_object_t *src_typedarray_p = ecma_get_object_from_value (arr_val); + ecma_typedarray_info_t src_info = ecma_typedarray_get_info (src_typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (src_info.array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (src_info.array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *src_buffer_p = ecma_typedarray_get_buffer (&src_info); + + uint32_t target_offset_uint32 = ecma_number_to_uint32 (target_offset_num); + + if ((int64_t) src_info.length + target_offset_uint32 > target_info.length) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_RANGE_OF_INDEX); + } + + /* Fast path first. If the source and target arrays are the same we do not need to copy anything. */ + if (this_arg == arr_val) + { + return ECMA_VALUE_UNDEFINED; + } + + /* 26. targetByteIndex */ + target_buffer_p += target_offset_uint32 << target_info.shift; + + /* 27. limit */ + uint32_t limit = src_info.length << target_info.shift; + + if (src_info.id == target_info.id) + { + memmove (target_buffer_p, src_buffer_p, limit); + } + else + { + uint8_t *target_limit_p = target_buffer_p + limit; + ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (src_info.id); + ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.id); + + while (target_buffer_p < target_limit_p) + { + ecma_value_t element = src_typedarray_getter_cb (src_buffer_p); + ecma_value_t set_element = target_typedarray_setter_cb (target_buffer_p, element); + ecma_free_value (element); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + return set_element; + } + + src_buffer_p += src_info.element_size; + target_buffer_p += target_info.element_size; + } + } + + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_typedarray_set_with_typedarray */ + +/** + * The %TypedArray%.prototype object's 'set' routine + * + * See also: + * ES2015, 22.2.3.22, 22.2.3.22.1 + * + * @return ecma value of undefined if success, error otherwise. + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arr_val, /**< array object */ + ecma_value_t offset_val) /**< offset value */ +{ + /* 1. */ + if (ecma_is_typedarray (arr_val)) + { + /* 22.2.3.22.2 */ + return ecma_op_typedarray_set_with_typedarray (this_arg, arr_val, offset_val); + } + + /* 6.~ 8. targetOffset */ + ecma_number_t target_offset_num; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (offset_val, &target_offset_num))) + { + return ECMA_VALUE_ERROR; + } + + if (target_offset_num <= -1.0 || target_offset_num >= (ecma_number_t) UINT32_MAX + 0.5) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_OFFSET); + } + uint32_t target_offset_uint32 = ecma_number_to_uint32 (target_offset_num); + + /* 11. ~ 15. */ + ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg); + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (target_info.array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (target_info.array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *target_buffer_p = ecma_typedarray_get_buffer (&target_info); + + /* 16.~ 17. */ + ecma_value_t source_obj = ecma_op_to_object (arr_val); + + if (ECMA_IS_VALUE_ERROR (source_obj)) + { + return source_obj; + } + + /* 18.~ 19. */ + ecma_object_t *source_obj_p = ecma_get_object_from_value (source_obj); + + ecma_length_t source_length; + + if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (source_obj_p, &source_length))) + { + ecma_deref_object (source_obj_p); + return ECMA_VALUE_ERROR; + } + + /* 20. if srcLength + targetOffset > targetLength, throw a RangeError */ + if ((int64_t) source_length + target_offset_uint32 > target_info.length) + { + ecma_deref_object (source_obj_p); + return ecma_raise_range_error (ECMA_ERR_INVALID_RANGE_OF_INDEX); + } + JERRY_ASSERT (source_length <= UINT32_MAX); + uint32_t source_length_uint32 = (uint32_t) source_length; + + /* 21.~ 25. */ + target_buffer_p += target_offset_uint32 << target_info.shift; + + ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.id); + uint32_t k = 0; + + while (k < source_length_uint32) + { + ecma_value_t elem = ecma_op_object_get_by_index (source_obj_p, k); + + if (ECMA_IS_VALUE_ERROR (elem)) + { + ecma_deref_object (source_obj_p); + return elem; + } + + ecma_value_t value_to_set; + +#if JERRY_BUILTIN_BIGINT + if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (target_info.id)) + { + value_to_set = ecma_bigint_to_bigint (elem, false); + + if (ECMA_IS_VALUE_ERROR (value_to_set)) + { + ecma_deref_object (source_obj_p); + ecma_free_value (elem); + return value_to_set; + } + } + else +#endif /* JERRY_BUILTIN_BIGINT */ + { + ecma_number_t elem_num; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_numeric (elem, &elem_num, ECMA_TO_NUMERIC_NO_OPTS))) + { + ecma_free_value (elem); + ecma_deref_object (source_obj_p); + return ECMA_VALUE_ERROR; + } + + value_to_set = ecma_make_number_value (elem_num); + } + + ecma_free_value (elem); + + if (ecma_arraybuffer_is_detached (target_info.array_buffer_p)) + { + ecma_deref_object (source_obj_p); + ecma_free_value (value_to_set); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_value_t set_element = target_typedarray_setter_cb (target_buffer_p, value_to_set); + + ecma_free_value (value_to_set); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_deref_object (source_obj_p); + return set_element; + } + + k++; + target_buffer_p += target_info.element_size; + } + + ecma_deref_object (source_obj_p); + + return ECMA_VALUE_UNDEFINED; +} /* ecma_builtin_typedarray_prototype_set */ + +/** + * TypedArray.prototype's 'toString' single element operation routine based + * on the Array.prototype's 'toString' single element operation routine + * + * See also: + * ECMA-262 v5.1, 15.4.4.2 + * + * @return NULL - if the conversion fails + * ecma_string_t * - otherwise + */ +static ecma_string_t * +ecma_op_typedarray_get_to_string_at_index (ecma_object_t *obj_p, /**< this object */ + uint32_t index) /**< array index */ +{ + ecma_value_t index_value = ecma_op_object_get_by_index (obj_p, index); + + if (ECMA_IS_VALUE_ERROR (index_value)) + { + return NULL; + } + + if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value)) + { + ecma_free_value (index_value); + return ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_string_t *ret_str_p = ecma_op_to_string (index_value); + + ecma_free_value (index_value); + + return ret_str_p; +} /* ecma_op_typedarray_get_to_string_at_index */ + +/** + * The TypedArray.prototype.toString's separator creation routine based on + * the Array.prototype.toString's separator routine + * + * See also: + * ECMA-262 v5.1, 15.4.4.2 4th step + * + * @return NULL - if the conversion fails + * ecma_string_t * - otherwise + */ +static ecma_string_t * +ecma_op_typedarray_get_separator_string (ecma_value_t separator) /**< possible separator */ +{ + if (ecma_is_value_undefined (separator)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR); + } + + return ecma_op_to_string (separator); +} /* ecma_op_typedarray_get_separator_string */ + +/** + * The TypedArray.prototype object's 'join' routine based on + * the Array.prototype object's 'join' + * + * See also: + * ECMA-262 v5, 15.4.4.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_join (ecma_object_t *obj_p, /**< this object */ + ecma_value_t separator_arg) /**< separator argument */ +{ + ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p); + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* 2. */ + uint32_t length = ecma_typedarray_get_length (obj_p); + ecma_string_t *separator_string_p = ecma_op_typedarray_get_separator_string (separator_arg); + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + if (JERRY_UNLIKELY (separator_string_p == NULL)) + { + return ret_value; + } + + /* 7-8. */ + ecma_string_t *first_string_p = ecma_op_typedarray_get_to_string_at_index (obj_p, 0); + + if (JERRY_UNLIKELY (first_string_p == NULL)) + { + ecma_deref_ecma_string (separator_string_p); + return ret_value; + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (first_string_p); + + ecma_deref_ecma_string (first_string_p); + + /* 9-10. */ + for (uint32_t k = 1; k < length; k++) + { + /* 10.a */ + ecma_stringbuilder_append (&builder, separator_string_p); + + /* 10.d */ + ecma_string_t *next_string_p = ecma_op_typedarray_get_to_string_at_index (obj_p, k); + + if (JERRY_UNLIKELY (next_string_p == NULL)) + { + ecma_stringbuilder_destroy (&builder); + ecma_deref_ecma_string (separator_string_p); + return ret_value; + } + + ecma_stringbuilder_append (&builder, next_string_p); + + ecma_deref_ecma_string (next_string_p); + } + + ecma_deref_ecma_string (separator_string_p); + ret_value = ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); + + return ret_value; +} /* ecma_builtin_typedarray_prototype_join */ + +/** + * The %TypedArray%.prototype object's 'subarray' routine. + * + * See also: + * ES2015, 22.2.3.26 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_subarray (ecma_value_t this_arg, /**< this object */ + ecma_typedarray_info_t *info_p, /**< object info */ + ecma_value_t begin, /**< begin */ + ecma_value_t end) /**< end */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + /* 9. beginIndex, 12. endIndex */ + uint32_t begin_index_uint32 = 0, end_index_uint32 = 0; + + /* 7. relativeBegin */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (begin, info_p->length, &begin_index_uint32))) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_is_value_undefined (end)) + { + end_index_uint32 = (uint32_t) info_p->length; + } + else + { + /* 10. relativeEnd */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (end, info_p->length, &end_index_uint32))) + { + return ECMA_VALUE_ERROR; + } + } + + /* 13. newLength */ + uint32_t subarray_length = 0; + + if (end_index_uint32 > begin_index_uint32) + { + subarray_length = end_index_uint32 - begin_index_uint32; + } + + /* 17. beginByteOffset */ + uint32_t begin_byte_offset = info_p->offset + (begin_index_uint32 << info_p->shift); + + ecma_value_t arguments_p[3] = { ecma_make_object_value (info_p->array_buffer_p), + ecma_make_uint32_value (begin_byte_offset), + ecma_make_uint32_value (subarray_length) }; + + ret_value = ecma_typedarray_species_create (this_arg, arguments_p, 3); + + ecma_free_value (arguments_p[1]); + ecma_free_value (arguments_p[2]); + return ret_value; +} /* ecma_builtin_typedarray_prototype_subarray */ + +/** + * The %TypedArray%.prototype object's 'fill' routine. + * + * See also: + * ES2015, 22.2.3.8, 22.1.3.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_fill (ecma_value_t this_arg, /**< this object */ + ecma_typedarray_info_t *info_p, /**< object info */ + ecma_value_t value, /**< value */ + ecma_value_t begin, /**< begin */ + ecma_value_t end) /**< end */ +{ + ecma_value_t value_to_set; + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + +#if JERRY_BUILTIN_BIGINT + if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info_p->id)) + { + value_to_set = ecma_bigint_to_bigint (value, true); + + if (ECMA_IS_VALUE_ERROR (value_to_set)) + { + return value_to_set; + } + } + else +#endif /* JERRY_BUILTIN_BIGINT */ + { + ecma_number_t value_num; + ecma_value_t ret_value = ecma_op_to_numeric (value, &value_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (!ecma_is_value_empty (ret_value)) + { + return ret_value; + } + + value_to_set = ecma_make_number_value (value_num); + } + + uint32_t begin_index_uint32 = 0, end_index_uint32 = 0; + + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (begin, info_p->length, &begin_index_uint32))) + { + ecma_free_value (value_to_set); + return ECMA_VALUE_ERROR; + } + + if (ecma_is_value_undefined (end)) + { + end_index_uint32 = (uint32_t) info_p->length; + } + else + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (end, info_p->length, &end_index_uint32))) + { + ecma_free_value (value_to_set); + return ECMA_VALUE_ERROR; + } + } + + uint32_t subarray_length = 0; + + if (end_index_uint32 > begin_index_uint32) + { + subarray_length = end_index_uint32 - begin_index_uint32; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); + + buffer_p += begin_index_uint32 << info_p->shift; + + uint8_t *limit_p = buffer_p + (subarray_length << info_p->shift); + ecma_typedarray_setter_fn_t typedarray_setter_cb = ecma_get_typedarray_setter_fn (info_p->id); + + while (buffer_p < limit_p) + { + ecma_value_t set_element = typedarray_setter_cb (buffer_p, value_to_set); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_free_value (value_to_set); + return set_element; + } + + buffer_p += info_p->element_size; + } + + ecma_free_value (value_to_set); + + return ecma_copy_value (this_arg); +} /* ecma_builtin_typedarray_prototype_fill */ + +/** + * SortCompare abstract method + * + * See also: + * ECMA-262 v5, 15.4.4.11 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_sort_compare_helper (ecma_value_t lhs, /**< left value */ + ecma_value_t rhs, /**< right value */ + ecma_value_t compare_func, /**< compare function */ + ecma_object_t *array_buffer_p) /**< array buffer */ +{ + if (ecma_is_value_undefined (compare_func)) + { + /* Default comparison when no comparefn is passed. */ +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (lhs) && ecma_is_value_bigint (rhs)) + { + return ecma_make_number_value (ecma_bigint_compare_to_bigint (lhs, rhs)); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + ecma_number_t result = ECMA_NUMBER_ZERO; + + double lhs_value = (double) ecma_get_number_from_value (lhs); + double rhs_value = (double) ecma_get_number_from_value (rhs); + + if (ecma_number_is_nan (lhs_value)) + { + // Keep NaNs at the end of the array. + result = ECMA_NUMBER_ONE; + } + else if (ecma_number_is_nan (rhs_value)) + { + // Keep NaNs at the end of the array. + result = ECMA_NUMBER_MINUS_ONE; + } + else if (lhs_value < rhs_value) + { + result = ECMA_NUMBER_MINUS_ONE; + } + else if (lhs_value > rhs_value || (ecma_number_is_zero (rhs_value) && ecma_number_is_negative (rhs_value))) + { + result = ECMA_NUMBER_ONE; + } + else + { + result = ECMA_NUMBER_ZERO; + } + + return ecma_make_number_value (result); + } + + /* + * compare_func, if not undefined, will always contain a callable function object. + * We checked this previously, before this function was called. + */ + JERRY_ASSERT (ecma_op_is_callable (compare_func)); + ecma_object_t *comparefn_obj_p = ecma_get_object_from_value (compare_func); + + ecma_value_t compare_args[] = { lhs, rhs }; + + ecma_value_t call_value = ecma_op_function_call (comparefn_obj_p, ECMA_VALUE_UNDEFINED, compare_args, 2); + + if (ECMA_IS_VALUE_ERROR (call_value) || ecma_is_value_number (call_value)) + { + return call_value; + } + + ecma_number_t ret_num; + ecma_value_t number_result = ecma_op_to_number (call_value, &ret_num); + + ecma_free_value (call_value); + + if (ECMA_IS_VALUE_ERROR (number_result)) + { + return number_result; + } + + if (ecma_arraybuffer_is_detached (array_buffer_p)) + { + ecma_free_value (number_result); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + // If the coerced value can't be represented as a Number, compare them as equals. + if (ecma_number_is_nan (ret_num)) + { + return ecma_make_number_value (ECMA_NUMBER_ZERO); + } + + return ecma_make_number_value (ret_num); +} /* ecma_builtin_typedarray_prototype_sort_compare_helper */ + +/** + * The %TypedArray%.prototype object's 'sort' routine. + * + * See also: + * ES2015, 22.2.3.25, 22.1.3.24 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_sort (ecma_value_t this_arg, /**< this argument */ + ecma_typedarray_info_t *info_p, /**< object info */ + ecma_value_t compare_func) /**< comparator fn */ +{ + JERRY_ASSERT (ecma_is_typedarray (this_arg)); + JERRY_ASSERT (ecma_is_value_undefined (compare_func) || ecma_op_is_callable (compare_func)); + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + if (!info_p->length) + { + return ecma_copy_value (this_arg); + } + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + JMEM_DEFINE_LOCAL_ARRAY (values_buffer, info_p->length, ecma_value_t); + + uint32_t buffer_index = 0; + + ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + uint8_t *limit_p = buffer_p + (info_p->length << info_p->shift); + ecma_typedarray_setter_fn_t typedarray_setter_cb; + + /* Copy unsorted array into a native c array. */ + while (buffer_p < limit_p) + { + JERRY_ASSERT (buffer_index < info_p->length); + ecma_value_t element_value = typedarray_getter_cb (buffer_p); + values_buffer[buffer_index++] = element_value; + buffer_p += info_p->element_size; + } + + JERRY_ASSERT (buffer_index == info_p->length); + + const ecma_builtin_helper_sort_compare_fn_t sort_cb = &ecma_builtin_typedarray_prototype_sort_compare_helper; + + ecma_value_t sort_value = ecma_builtin_helper_array_merge_sort_helper (values_buffer, + (uint32_t) (info_p->length), + compare_func, + sort_cb, + info_p->array_buffer_p); + + if (ECMA_IS_VALUE_ERROR (sort_value)) + { + ret_value = sort_value; + goto free_values; + } + + JERRY_ASSERT (sort_value == ECMA_VALUE_EMPTY); + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + typedarray_setter_cb = ecma_get_typedarray_setter_fn (info_p->id); + + buffer_p = limit_p - (info_p->length << info_p->shift); + buffer_index = 0; + + /* Put sorted values from the native array back into the typedarray buffer. */ + while (buffer_p < limit_p) + { + JERRY_ASSERT (buffer_index < info_p->length); + ecma_value_t element_value = values_buffer[buffer_index++]; + ecma_value_t set_element = typedarray_setter_cb (buffer_p, element_value); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ret_value = set_element; + goto free_values; + } + + buffer_p += info_p->element_size; + } + + JERRY_ASSERT (buffer_index == info_p->length); + + ret_value = ecma_copy_value (this_arg); + +free_values: + /* Free values that were copied to the local array. */ + for (uint32_t index = 0; index < info_p->length; index++) + { + ecma_free_value (values_buffer[index]); + } + + JMEM_FINALIZE_LOCAL_ARRAY (values_buffer); + + return ret_value; +} /* ecma_builtin_typedarray_prototype_sort */ + +/** + * The %TypedArray%.prototype object's 'find' and 'findIndex' routine helper + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_find_helper (ecma_value_t this_arg, /**< this argument */ + ecma_typedarray_info_t *info_p, /**< object info */ + ecma_value_t predicate, /**< callback function */ + ecma_value_t predicate_this_arg, /**< this argument for + * invoke predicate */ + bool is_find) /**< true - find routine + * false - findIndex routine */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + JERRY_ASSERT (ecma_is_value_object (predicate)); + ecma_object_t *func_object_p = ecma_get_object_from_value (predicate); + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + uint8_t *limit_p = buffer_p + (info_p->length << info_p->shift); + ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + uint32_t buffer_index = 0; + + while (buffer_p < limit_p) + { + JERRY_ASSERT (buffer_index < info_p->length); + ecma_value_t element_value = typedarray_getter_cb (buffer_p); + buffer_p += info_p->element_size; + + ecma_value_t call_args[] = { element_value, ecma_make_uint32_value (buffer_index), this_arg }; + ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + ecma_free_value (element_value); + return call_value; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + ecma_free_value (element_value); + ecma_free_value (call_value); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + bool call_result = ecma_op_to_boolean (call_value); + ecma_free_value (call_value); + + if (call_result) + { + if (is_find) + { + return element_value; + } + + ecma_free_value (element_value); + return ecma_make_uint32_value (buffer_index); + } + + buffer_index++; + ecma_free_value (element_value); + } + + return is_find ? ECMA_VALUE_UNDEFINED : ecma_make_integer_value (-1); +} /* ecma_builtin_typedarray_prototype_find_helper */ + +/** + * The %TypedArray%.prototype object's 'at' routine + * + * See also: + * ECMA-262 Stage 3 Draft Relative Indexing Method proposal + * from: https://tc39.es/proposal-relative-indexing-method + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_at (ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t index) /**< index argument */ +{ + ecma_length_t len = info_p->length; + ecma_length_t res_index; + ecma_value_t return_value = ecma_builtin_helper_calculate_index (index, len, &res_index); + + if (return_value != ECMA_VALUE_EMPTY) + { + return return_value; + } + + if (res_index >= UINT32_MAX) + { + return ECMA_VALUE_UNDEFINED; + } + + return ecma_get_typedarray_element (info_p, (uint32_t) res_index); +} /* ecma_builtin_typedarray_prototype_at */ + +/** + * The %TypedArray%.prototype object's 'indexOf' routine + * + * See also: + * ECMA-262 v6, 22.2.3.13 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_index_of (ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + +#if JERRY_BUILTIN_BIGINT + bool is_bigint = ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info_p->id); +#else /* !JERRY_BUILTIN_BIGINT */ + bool is_bigint = false; +#endif /* JERRY_BUILTIN_BIGINT */ + + uint32_t from_index; + + /* 5. */ + if (args_number == 0 || (!ecma_is_value_number (args[0]) && !is_bigint) || info_p->length == 0) + { + return ecma_make_integer_value (-1); + } + if (args_number == 1) + { + from_index = 0; + } + else + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &from_index))) + { + return ECMA_VALUE_ERROR; + } + } + + uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); + + uint8_t *limit_p = buffer_p + (info_p->length << info_p->shift); + ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + + buffer_p += from_index << info_p->shift; + + /* 11. */ + while (buffer_p < limit_p) + { + ecma_value_t element = getter_cb (buffer_p); + + if (ecma_op_same_value_zero (args[0], element, true)) + { + ecma_free_value (element); + return ecma_make_number_value (from_index); + } + + ecma_free_value (element); + buffer_p += info_p->element_size; + from_index++; + } + + /* 12. */ + return ecma_make_integer_value (-1); +} /* ecma_builtin_typedarray_prototype_index_of */ + +/** + * The %TypedArray%.prototype object's 'lastIndexOf' routine + * + * See also: + * ECMA-262 v6, 22.2.3.16 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_last_index_of (ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + +#if JERRY_BUILTIN_BIGINT + bool is_bigint = ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info_p->id); +#else /* !JERRY_BUILTIN_BIGINT */ + bool is_bigint = false; +#endif /* JERRY_BUILTIN_BIGINT */ + + uint32_t from_index; + + /* 5. */ + if (args_number == 0 || (!ecma_is_value_number (args[0]) && !is_bigint) || info_p->length == 0) + { + return ecma_make_integer_value (-1); + } + + if (args_number == 1) + { + from_index = info_p->length - 1; + } + else + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &from_index))) + { + return ECMA_VALUE_ERROR; + } + + ecma_number_t to_int; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (args[1], &to_int))) + { + return ECMA_VALUE_ERROR; + } + + if (info_p->length + to_int < 0) + { + return ecma_make_integer_value (-1); + } + + from_index = JERRY_MIN (from_index, info_p->length - 1); + } + + ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + uint8_t *buffer_p = ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; + uint8_t *current_element_p = buffer_p + (from_index << info_p->shift); + + /* 10. */ + while (current_element_p >= buffer_p) + { + ecma_value_t element = getter_cb (current_element_p); + + if (ecma_op_same_value_zero (args[0], element, true)) + { + ecma_free_value (element); + return ecma_make_number_value ((ecma_number_t) from_index); + } + + ecma_free_value (element); + current_element_p -= info_p->element_size; + from_index--; + } + + /* 11. */ + return ecma_make_integer_value (-1); +} /* ecma_builtin_typedarray_prototype_last_index_of */ + +/** + * The %TypedArray%.prototype object's 'copyWithin' routine + * + * See also: + * ECMA-262 v6, 22.2.3.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_copy_within (ecma_value_t this_arg, /**< this argument */ + ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint32_t relative_target = 0; + uint32_t relative_start = 0; + uint32_t relative_end = info_p->length; + + if (args_number > 0) + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[0], info_p->length, &relative_target))) + { + return ECMA_VALUE_ERROR; + } + + if (args_number > 1) + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &relative_start))) + { + return ECMA_VALUE_ERROR; + } + + if (args_number > 2 && args[2] != ECMA_VALUE_UNDEFINED) + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[2], info_p->length, &relative_end))) + { + return ECMA_VALUE_ERROR; + } + } + } + } + + if (relative_target >= info_p->length || relative_start >= relative_end || relative_end == 0) + { + return ecma_copy_value (this_arg); + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); + + uint32_t distance = relative_end - relative_start; + uint32_t offset = info_p->length - relative_target; + uint32_t count = JERRY_MIN (distance, offset); + + memmove (buffer_p + (relative_target << info_p->shift), + buffer_p + (relative_start << info_p->shift), + (size_t) (count << info_p->shift)); + + return ecma_copy_value (this_arg); +} /* ecma_builtin_typedarray_prototype_copy_within */ + +/** + * The %TypedArray%.prototype object's 'slice' routine + * + * See also: + * ECMA-262 v6, 22.2.3.23 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_slice (ecma_value_t this_arg, /**< this argument */ + ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ + uint32_t relative_start = 0; + uint32_t relative_end = info_p->length; + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + if (args_number > 0) + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[0], info_p->length, &relative_start))) + { + return ECMA_VALUE_ERROR; + } + + if (args_number > 1 && args[1] != ECMA_VALUE_UNDEFINED + && ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &relative_end))) + { + return ECMA_VALUE_ERROR; + } + } + + uint8_t *src_buffer_p = ecma_typedarray_get_buffer (info_p); + + int32_t distance = (int32_t) (relative_end - relative_start); + uint32_t count = distance > 0 ? (uint32_t) distance : 0; + + ecma_value_t len = ecma_make_number_value (count); + // TODO: 22.2.3.23, 12-13. + ecma_value_t new_typedarray = ecma_typedarray_species_create (this_arg, &len, 1); + ecma_free_value (len); + + if (ECMA_IS_VALUE_ERROR (new_typedarray) || count == 0) + { + return new_typedarray; + } + + ecma_object_t *new_typedarray_p = ecma_get_object_from_value (new_typedarray); + ecma_typedarray_info_t new_typedarray_info = ecma_typedarray_get_info (new_typedarray_p); + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + ecma_deref_object (new_typedarray_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + uint8_t *dst_buffer_p = ecma_typedarray_get_buffer (&new_typedarray_info); + + JERRY_ASSERT (new_typedarray_info.offset == 0); + + src_buffer_p += relative_start << info_p->shift; + + if (info_p->id == new_typedarray_info.id) + { + // 22.2.3.23. Step 22. h-i. + memcpy (dst_buffer_p, src_buffer_p, count << info_p->shift); + } + else + { + // 22.2.3.23. Step 21. b. + ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + ecma_typedarray_setter_fn_t new_typedarray_setter_cb = ecma_get_typedarray_setter_fn (new_typedarray_info.id); + + for (uint32_t idx = 0; idx < count; idx++) + { + ecma_value_t element = src_typedarray_getter_cb (src_buffer_p); + ecma_value_t set_element = new_typedarray_setter_cb (dst_buffer_p, element); + ecma_free_value (element); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_deref_object (new_typedarray_p); + return set_element; + } + + src_buffer_p += info_p->element_size; + dst_buffer_p += new_typedarray_info.element_size; + } + } + + return new_typedarray; +} /* ecma_builtin_typedarray_prototype_slice */ + +/** + * The TypedArray.prototype's 'toLocaleString' single element operation routine. + * + * See also: + * ECMA-262 v6, 22.1.3.26 steps 7-10 and 12.b-e + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_to_locale_string_helper (ecma_typedarray_info_t *info_p, /**< object info */ + uint32_t index) /** array index */ +{ + ecma_value_t element_value = ecma_get_typedarray_element (info_p, index); + + if (ECMA_IS_VALUE_ERROR (element_value)) + { + return element_value; + } + + ecma_value_t call_value = ecma_op_invoke_by_magic_id (element_value, LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, NULL, 0); + + ecma_free_value (element_value); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + return call_value; + } + + ecma_string_t *str_p = ecma_op_to_string (call_value); + + ecma_free_value (call_value); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + return ecma_make_string_value (str_p); +} /* ecma_builtin_typedarray_prototype_to_locale_string_helper */ + +/** + * The %TypedArray%.prototype object's 'toLocaleString' routine + * + * See also: + * ECMA-262 v6, 22.2.3.27 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_to_locale_string (ecma_typedarray_info_t *info_p) /**< object info */ +{ + if (info_p->length == 0) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + ecma_value_t first_element = ecma_builtin_typedarray_prototype_to_locale_string_helper (info_p, 0); + + if (ECMA_IS_VALUE_ERROR (first_element)) + { + return first_element; + } + + ecma_string_t *return_string_p = ecma_get_string_from_value (first_element); + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (return_string_p); + ecma_deref_ecma_string (return_string_p); + + for (uint32_t k = 1; k < info_p->length; k++) + { + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_COMMA); + ecma_value_t next_element = ecma_builtin_typedarray_prototype_to_locale_string_helper (info_p, k); + + if (ECMA_IS_VALUE_ERROR (next_element)) + { + ecma_stringbuilder_destroy (&builder); + return next_element; + } + + ecma_string_t *next_element_p = ecma_get_string_from_value (next_element); + ecma_stringbuilder_append (&builder, next_element_p); + ecma_deref_ecma_string (next_element_p); + } + + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_builtin_typedarray_prototype_to_locale_string */ + +/** + * The %TypedArray%.prototype object's 'includes' routine + * + * See also: + * ECMA-262 v11, 22.2.3.13. + */ +static ecma_value_t +ecma_builtin_typedarray_prototype_includes (ecma_typedarray_info_t *info_p, /**< object info */ + const ecma_value_t args[], /**< arguments list */ + uint32_t args_number) /**< number of arguments */ +{ +#if JERRY_BUILTIN_BIGINT + bool is_bigint = ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info_p->id); +#else /* !JERRY_BUILTIN_BIGINT */ + bool is_bigint = false; +#endif /* JERRY_BUILTIN_BIGINT */ + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + if (args_number == 0 || (!ecma_is_value_number (args[0]) && !is_bigint) || info_p->length == 0) + { + return ECMA_VALUE_FALSE; + } + + uint32_t from_index = 0; + + if (args_number > 1) + { + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &from_index))) + { + return ECMA_VALUE_ERROR; + } + } + + uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); + + ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id); + uint8_t *limit_p = buffer_p + (info_p->length << info_p->shift); + + buffer_p += from_index << info_p->shift; + + while (buffer_p < limit_p) + { + ecma_value_t element = getter_cb (buffer_p); + + if (ecma_op_same_value_zero (args[0], element, false)) + { + ecma_free_value (element); + return ECMA_VALUE_TRUE; + } + + ecma_free_value (element); + buffer_p += info_p->element_size; + } + + return ECMA_VALUE_FALSE; +} /* ecma_builtin_typedarray_prototype_includes */ + +/** + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_typedarray_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide + * routine identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + uint32_t arguments_number) /**< length of arguments' list */ +{ + if (!ecma_is_typedarray (this_arg)) + { + if (builtin_routine_id == ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_STRING_TAG_GETTER) + { + return ECMA_VALUE_UNDEFINED; + } + + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY); + } + + ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg); + ecma_typedarray_info_t info = { 0 }; + + if (builtin_routine_id < ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BUFFER_GETTER) + { + info = ecma_typedarray_get_info (typedarray_p); + + if (builtin_routine_id != ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SUBARRAY + && ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + } + + if (builtin_routine_id < ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INDEX_OF && !ecma_op_is_callable (arguments_list_p[0])) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + switch (builtin_routine_id) + { + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INCLUDES: + { + return ecma_builtin_typedarray_prototype_includes (&info, arguments_list_p, arguments_number); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_JOIN: + { + return ecma_builtin_typedarray_prototype_join (typedarray_p, arguments_list_p[0]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_EVERY: + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SOME: + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FOR_EACH: + { + uint8_t offset = (uint8_t) (builtin_routine_id - ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_EVERY); + + return ecma_builtin_typedarray_prototype_exec_routine (this_arg, + &info, + arguments_list_p[0], + arguments_list_p[1], + (typedarray_routine_mode) offset); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_MAP: + { + return ecma_builtin_typedarray_prototype_map (this_arg, &info, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE: + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE_RIGHT: + { + bool is_reduce = builtin_routine_id == ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE_RIGHT; + return ecma_builtin_typedarray_prototype_reduce_with_direction (this_arg, + &info, + arguments_list_p, + arguments_number, + is_reduce); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FILTER: + { + return ecma_builtin_typedarray_prototype_filter (this_arg, &info, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REVERSE: + { + return ecma_builtin_typedarray_prototype_reverse (this_arg, &info); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SET: + { + return ecma_builtin_typedarray_prototype_set (this_arg, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SUBARRAY: + { + return ecma_builtin_typedarray_prototype_subarray (this_arg, &info, arguments_list_p[0], arguments_list_p[1]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FILL: + { + return ecma_builtin_typedarray_prototype_fill (this_arg, + &info, + arguments_list_p[0], + arguments_list_p[1], + arguments_list_p[2]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SORT: + { + if (!ecma_is_value_undefined (arguments_list_p[0]) && !ecma_op_is_callable (arguments_list_p[0])) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + return ecma_builtin_typedarray_prototype_sort (this_arg, &info, arguments_list_p[0]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND: + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND_INDEX: + { + bool is_find = builtin_routine_id == ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND; + return ecma_builtin_typedarray_prototype_find_helper (this_arg, + &info, + arguments_list_p[0], + arguments_list_p[1], + is_find); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_AT: + { + return ecma_builtin_typedarray_prototype_at (&info, arguments_list_p[0]); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INDEX_OF: + { + return ecma_builtin_typedarray_prototype_index_of (&info, arguments_list_p, arguments_number); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_LAST_INDEX_OF: + { + return ecma_builtin_typedarray_prototype_last_index_of (&info, arguments_list_p, arguments_number); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_COPY_WITHIN: + { + return ecma_builtin_typedarray_prototype_copy_within (this_arg, &info, arguments_list_p, arguments_number); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SLICE: + { + return ecma_builtin_typedarray_prototype_slice (this_arg, &info, arguments_list_p, arguments_number); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_LOCALE_STRING: + { + return ecma_builtin_typedarray_prototype_to_locale_string (&info); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_KEYS: + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_ENTRIES: + { + ecma_iterator_kind_t iter_id = + (builtin_routine_id == ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_KEYS) ? ECMA_ITERATOR_KEYS : ECMA_ITERATOR_ENTRIES; + + return ecma_typedarray_iterators_helper (this_arg, iter_id); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BUFFER_GETTER: + { + ecma_object_t *buffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + ecma_ref_object (buffer_p); + + return ecma_make_object_value (buffer_p); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BYTELENGTH_GETTER: + { + ecma_object_t *buffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + + if (ecma_arraybuffer_is_detached (buffer_p)) + { + return ecma_make_uint32_value (0); + } + + uint32_t length = ecma_typedarray_get_length (typedarray_p); + uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p); + return ecma_make_uint32_value (length << shift); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BYTEOFFSET_GETTER: + { + return ecma_make_uint32_value (ecma_typedarray_get_offset (typedarray_p)); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_LENGTH_GETTER: + { + ecma_object_t *buffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + + if (ecma_arraybuffer_is_detached (buffer_p)) + { + return ecma_make_uint32_value (0); + } + + return ecma_make_uint32_value (ecma_typedarray_get_length (typedarray_p)); + } + case ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_STRING_TAG_GETTER: + { + ecma_extended_object_t *object_p = (ecma_extended_object_t *) typedarray_p; + return ecma_make_magic_string_value (ecma_get_typedarray_magic_string_id ((ecma_typedarray_type_t) object_p->u.cls.u1.typedarray_type)); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_typedarray_prototype_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.inc.h new file mode 100644 index 0000000..9cace68 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.inc.h @@ -0,0 +1,86 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %TypedArrayPrototype% description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/* ES2015 22.2.3.4 */ +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_TYPEDARRAY, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Readonly accessor properties */ +/* ES2015 22.2.3.1 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BUFFER, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BUFFER_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) +/* ES2015 22.2.3.2 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BYTELENGTH_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) +/* ES2015 22.2.3.3 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_OFFSET_UL, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_BYTEOFFSET_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ES2015 22.2.3.17 */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_LENGTH, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_LENGTH_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ECMA-262 v6, 23.1.3.13 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, + ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_STRING_TAG_GETTER, + ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_COPY_WITHIN, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_COPY_WITHIN, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_ENTRIES, 0, 0) +ROUTINE (LIT_MAGIC_STRING_EVERY, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_EVERY, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FILL, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FILL, 3, 1) +ROUTINE (LIT_MAGIC_STRING_FILTER, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FILTER, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FIND, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FIND_INDEX, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FIND_INDEX, 2, 1) +ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_FOR_EACH, 2, 1) +ROUTINE (LIT_MAGIC_STRING_INCLUDES, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INCLUDES, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_AT, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_AT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_INDEX_OF, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_JOIN, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_JOIN, 1, 1) +ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_KEYS, 0, 0) +ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_LAST_INDEX_OF, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_MAP, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_MAP, 2, 1) +ROUTINE (LIT_MAGIC_STRING_REDUCE, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE, 2, 1) +ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REDUCE_RIGHT, 2, 1) +ROUTINE (LIT_MAGIC_STRING_REVERSE, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_REVERSE, 0, 0) +ROUTINE (LIT_MAGIC_STRING_SET, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SET, 2, 1) +ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SLICE, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_SOME, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SOME, 2, 1) +ROUTINE (LIT_MAGIC_STRING_SORT, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SORT, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SUBARRAY, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_SUBARRAY, 2, 2) +ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_TYPEDARRAY_PROTOTYPE_ROUTINE_TO_LOCALE_STRING, 0, 0) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_STRING_UL, LIT_MAGIC_STRING_TO_STRING_UL, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_MAGIC_STRING_VALUES, + LIT_INTERNAL_MAGIC_STRING_TYPEDARRAY_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +INTRINSIC_PROPERTY (LIT_GLOBAL_SYMBOL_ITERATOR, + LIT_INTERNAL_MAGIC_STRING_TYPEDARRAY_PROTOTYPE_VALUES, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-template.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-template.inc.h new file mode 100644 index 0000000..7c9313f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-template.inc.h @@ -0,0 +1,50 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#ifndef TYPEDARRAY_BYTES_PER_ELEMENT +#error "Please define TYPEDARRAY_BYTES_PER_ELEMENT" +#endif /* !TYPEDARRAY_BYTES_PER_ELEMENT */ + +#ifndef TYPEDARRAY_MAGIC_STRING_ID +#error "Please define TYPEDARRAY_MAGIC_STRING_ID" +#endif /* !TYPEDARRAY_MAGIC_STRING_ID */ + +#ifndef TYPEDARRAY_BUILTIN_ID +#error "Please define TYPEDARRAY_BUILTIN_ID" +#endif /* !TYPEDARRAY_BUILTIN_ID */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +/* ES2015 22.2.5 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 3, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ES2015 22.2.5.1 */ +NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U, TYPEDARRAY_BYTES_PER_ELEMENT, ECMA_PROPERTY_FIXED) + +/* ES2015 22.2.5 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, TYPEDARRAY_MAGIC_STRING_ID, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ES2015 22.2.5.2 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, TYPEDARRAY_BUILTIN_ID, ECMA_PROPERTY_FIXED) + +#include "ecma-builtin-helpers-macro-undefs.inc.h" + +#undef TYPEDARRAY_BUILTIN_ID +#undef TYPEDARRAY_MAGIC_STRING_ID +#undef TYPEDARRAY_BYTES_PER_ELEMENT + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray.cpp new file mode 100644 index 0000000..eb67eab --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray.cpp @@ -0,0 +1,215 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typedarray.inc.h" +#define BUILTIN_UNDERSCORED_ID typedarray +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup typedarray ECMA %TypedArray% object built-in + * @{ + */ + +/** + * The %TypedArray%.from routine + * + * See also: + * ES2015 22.2.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_from (ecma_value_t this_arg, /**< 'this' argument */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (!ecma_is_constructor (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_CONSTRUCTOR); + } + + ecma_value_t source; + ecma_value_t map_fn = ECMA_VALUE_UNDEFINED; + ecma_value_t this_in_fn = ECMA_VALUE_UNDEFINED; + + if (arguments_list_len == 0) + { + return ecma_raise_type_error (ECMA_ERR_NO_SOURCE_ARGUMENT); + } + + source = arguments_list_p[0]; + + if (arguments_list_len > 1) + { + map_fn = arguments_list_p[1]; + + if (!ecma_op_is_callable (map_fn)) + { + return ecma_raise_type_error (ECMA_ERR_THE_MAPFN_ARGUMENT_IS_NOT_CALLABLE); + } + + if (arguments_list_len > 2) + { + this_in_fn = arguments_list_p[2]; + } + } + + return ecma_op_typedarray_from (this_arg, source, map_fn, this_in_fn); + +} /* ecma_builtin_typedarray_from */ + +/** + * The %TypedArray%.of routine + * + * See also: + * ES2015 22.2.2.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_typedarray_of (ecma_value_t this_arg, /**< 'this' argument */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + if (!ecma_is_constructor (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_CONSTRUCTOR); + } + + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (this_arg); + ecma_value_t len_val = ecma_make_uint32_value (arguments_list_len); + ecma_value_t ret_val = ecma_typedarray_create (constructor_obj_p, &len_val, 1); + ecma_free_value (len_val); + + if (ECMA_IS_VALUE_ERROR (ret_val)) + { + return ret_val; + } + + uint32_t k = 0; + ecma_object_t *ret_obj_p = ecma_get_object_from_value (ret_val); + ecma_typedarray_info_t info = ecma_typedarray_get_info (ret_obj_p); + ecma_typedarray_setter_fn_t setter_cb = ecma_get_typedarray_setter_fn (info.id); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + ecma_deref_object (ret_obj_p); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + ecma_deref_object (ret_obj_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + lit_utf8_byte_t *buffer_p = ecma_typedarray_get_buffer (&info); + + while (k < arguments_list_len) + { + ecma_value_t set_element = setter_cb (buffer_p, arguments_list_p[k]); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_deref_object (ret_obj_p); + return set_element; + } + + k++; + buffer_p += info.element_size; + } + + return ret_val; +} /* ecma_builtin_typedarray_of */ + +/** + * Handle calling [[Call]] of built-in %TypedArray% object + * + * ES2015 22.2.1 If %TypedArray% is directly called or + * called as part of a new expression an exception is thrown + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_typedarray_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_TYPEDARRAY_INTRINSIC_DIRECTLY_CALLED); +} /* ecma_builtin_typedarray_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in %TypedArray% object + * + * ES2015 22.2.1 If %TypedArray% is directly called or + * called as part of a new expression an exception is thrown + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_typedarray_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_TYPEDARRAY_INTRINSIC_CALLED_BY_NEW_EXPRESSION); +} /* ecma_builtin_typedarray_dispatch_construct */ + +/** + * 22.2.2.4 get %TypedArray% [ @@species ] accessor + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_builtin_typedarray_species_get (ecma_value_t this_value) /**< This Value */ +{ + return ecma_copy_value (this_value); +} /* ecma_builtin_typedarray_species_get */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray.inc.h new file mode 100644 index 0000000..bc8ab47 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray.inc.h @@ -0,0 +1,48 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * %TypedArray% description + */ + +#include "ecma-builtin-helpers-macro-defines.inc.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/* ES2015 22.2.2 */ +/* ES11 22.2.1.1 - value of length changed to 0 */ +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, 0, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ES2015 22.2.2 */ +STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_TYPED_ARRAY_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +/* ES2015 22.2.2.3 */ +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE, ECMA_PROPERTY_FIXED) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ + +/* ES2015 22.2.2.1 */ +ROUTINE (LIT_MAGIC_STRING_FROM, ecma_builtin_typedarray_from, NON_FIXED, 1) + +/* ES2015 22.2.2.2 */ +ROUTINE (LIT_MAGIC_STRING_OF, ecma_builtin_typedarray_of, NON_FIXED, 0) + +/* ES2015 22.2.2.4 */ +ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ecma_builtin_typedarray_species_get, ECMA_PROPERTY_FLAG_CONFIGURABLE) + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array-prototype.cpp new file mode 100644 index 0000000..691da4b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint16array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID uint16array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint16arrayprototype ECMA Uint16Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array-prototype.inc.h new file mode 100644 index 0000000..ec055f6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint16Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 2 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT16ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array.cpp new file mode 100644 index 0000000..18e5c6b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint16array.inc.h" +#define BUILTIN_UNDERSCORED_ID uint16array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint16array ECMA Uint16Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Uint16Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint16array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_UINT16_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_uint16array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Uint16Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint16array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_UINT16_ARRAY); +} /* ecma_builtin_uint16array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array.inc.h new file mode 100644 index 0000000..2c0af1f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint16array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint16Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 2 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_UINT16_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT16ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array-prototype.cpp new file mode 100644 index 0000000..4b5e384 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint32array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID uint32array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint32arrayprototype ECMA Uint32Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array-prototype.inc.h new file mode 100644 index 0000000..a04098a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint32Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 4 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT32ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array.cpp new file mode 100644 index 0000000..cb49561 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array.cpp @@ -0,0 +1,79 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint32array.inc.h" +#define BUILTIN_UNDERSCORED_ID uint32array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint32array ECMA Uint32Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Uint32Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint32array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_UINT32_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_uint32array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Uint32Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint32array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_UINT32_ARRAY); +} /* ecma_builtin_uint32array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array.inc.h new file mode 100644 index 0000000..fd0389a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint32array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint32Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 4 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_UINT32_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array-prototype.cpp new file mode 100644 index 0000000..8a8edb4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint8array-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID uint8array_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint8arrayprototype ECMA Uint8Array.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array-prototype.inc.h new file mode 100644 index 0000000..07f94b0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint8Array prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 1 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT8ARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array.cpp new file mode 100644 index 0000000..5d20b7a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array.cpp @@ -0,0 +1,77 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint8array.inc.h" +#define BUILTIN_UNDERSCORED_ID uint8array +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint8array ECMA Uint8Array object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Uint8Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint8array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_UINT8_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_uint8array_dispatch_call */ + +/** + * Handle calling [[Construct]] of Uint8Array + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint8array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_UINT8_ARRAY); +} /* ecma_builtin_uint8array_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array.inc.h new file mode 100644 index 0000000..d0259e9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8array.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint8Array description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 1 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_UINT8_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray-prototype.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray-prototype.cpp new file mode 100644 index 0000000..534014b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray-prototype.cpp @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint8clampedarray-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID uint8clampedarray_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint8clampedarrayprototype ECMA Uint8ClampedArray.prototype object built-in + * @{ + */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray-prototype.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray-prototype.inc.h new file mode 100644 index 0000000..8564828 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray-prototype.inc.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint8ClampedArray prototype description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 1 +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY +#include "ecma-builtin-typedarray-prototype-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray.cpp new file mode 100644 index 0000000..9b348c2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray.cpp @@ -0,0 +1,79 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-typedarray-object.h" + +#include "jrt.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-uint8clampedarray.inc.h" +#define BUILTIN_UNDERSCORED_ID uint8clampedarray +#include "ecma-builtin-internal-routines-template.inc.h" +#include "ecma-builtin-typedarray-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup uint8clampedarray ECMA Uint8ClampedArray object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of Uint8ClampedArray + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint8clampedarray_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_UINT8_CLAMPED_ARRAY_REQUIRES_NEW); +} /* ecma_builtin_uint8clampedarray_dispatch_call */ + +/** + * Handle calling [[Construct]] of Uint8ClampedArray + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_uint8clampedarray_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len, ECMA_UINT8_CLAMPED_ARRAY); +} /* ecma_builtin_uint8clampedarray_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray.inc.h new file mode 100644 index 0000000..d3f0eb1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-uint8clampedarray.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Uint8ClampedArray description + */ + +#if JERRY_BUILTIN_TYPEDARRAY + +#define TYPEDARRAY_BYTES_PER_ELEMENT 1 +#define TYPEDARRAY_MAGIC_STRING_ID LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL +#define TYPEDARRAY_BUILTIN_ID ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY_PROTOTYPE +#include "ecma-builtin-typedarray-template.inc.h" + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/meson.build new file mode 100644 index 0000000..0f00f5c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/builtin-objects/typedarray/meson.build @@ -0,0 +1,59 @@ +source_file = [ +'ecma-builtin-bigint64array-prototype.inc.h', +'ecma-builtin-bigint64array.inc.h', +'ecma-builtin-biguint64array-prototype.inc.h', +'ecma-builtin-biguint64array.inc.h', +'ecma-builtin-float32array-prototype.inc.h', +'ecma-builtin-float32array.inc.h', +'ecma-builtin-float64array-prototype.inc.h', +'ecma-builtin-float64array.inc.h', +'ecma-builtin-int16array-prototype.inc.h', +'ecma-builtin-int16array.inc.h', +'ecma-builtin-int32array-prototype.inc.h', +'ecma-builtin-int32array.inc.h', +'ecma-builtin-int8array-prototype.inc.h', +'ecma-builtin-int8array.inc.h', +'ecma-builtin-typedarray-helpers.h', +'ecma-builtin-typedarray-prototype-template.inc.h', +'ecma-builtin-typedarray-prototype.inc.h', +'ecma-builtin-typedarray-template.inc.h', +'ecma-builtin-typedarray.inc.h', +'ecma-builtin-uint16array-prototype.inc.h', +'ecma-builtin-uint16array.inc.h', +'ecma-builtin-uint32array-prototype.inc.h', +'ecma-builtin-uint32array.inc.h', +'ecma-builtin-uint8array-prototype.inc.h', +'ecma-builtin-uint8array.inc.h', +'ecma-builtin-uint8clampedarray-prototype.inc.h', +'ecma-builtin-uint8clampedarray.inc.h', +'ecma-builtin-bigint64array-prototype.cpp', +'ecma-builtin-bigint64array.cpp', +'ecma-builtin-biguint64array-prototype.cpp', +'ecma-builtin-biguint64array.cpp', +'ecma-builtin-float32array-prototype.cpp', +'ecma-builtin-float32array.cpp', +'ecma-builtin-float64array-prototype.cpp', +'ecma-builtin-float64array.cpp', +'ecma-builtin-int16array-prototype.cpp', +'ecma-builtin-int16array.cpp', +'ecma-builtin-int32array-prototype.cpp', +'ecma-builtin-int32array.cpp', +'ecma-builtin-int8array-prototype.cpp', +'ecma-builtin-int8array.cpp', +'ecma-builtin-typedarray-helpers.cpp', +'ecma-builtin-typedarray-prototype.cpp', +'ecma-builtin-typedarray.cpp', +'ecma-builtin-uint16array-prototype.cpp', +'ecma-builtin-uint16array.cpp', +'ecma-builtin-uint32array-prototype.cpp', +'ecma-builtin-uint32array.cpp', +'ecma-builtin-uint8array-prototype.cpp', +'ecma-builtin-uint8array.cpp', +'ecma-builtin-uint8clampedarray-prototype.cpp', +'ecma-builtin-uint8clampedarray.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/meson.build new file mode 100644 index 0000000..31e83fc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/meson.build @@ -0,0 +1,3 @@ +subdir('base') +subdir('builtin-objects') +subdir('operations') diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arguments-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arguments-object.cpp new file mode 100644 index 0000000..cfb04af --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arguments-object.cpp @@ -0,0 +1,458 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arguments-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaargumentsobject ECMA arguments object related routines + * @{ + */ + +/** + * Arguments object creation operation. + * + * See also: ECMA-262 v5, 10.6 + * + * @return ecma value of arguments object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_arguments_object (vm_frame_ctx_shared_args_t *shared_p, /**< shared context data */ + ecma_object_t *lex_env_p) /**< lexical environment the Arguments + * object is created for */ +{ + ecma_object_t *func_obj_p = shared_p->header.function_object_p; + const ecma_compiled_code_t *bytecode_data_p = shared_p->header.bytecode_header_p; + uint16_t formal_params_number; + + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + formal_params_number = ((cbc_uint16_arguments_t *) bytecode_data_p)->argument_end; + } + else + { + formal_params_number = ((cbc_uint8_arguments_t *) bytecode_data_p)->argument_end; + } + + uint32_t object_size = sizeof (ecma_unmapped_arguments_t); + uint32_t saved_arg_count = JERRY_MAX (shared_p->arg_list_len, formal_params_number); + + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED) + { + object_size = sizeof (ecma_mapped_arguments_t); + } + + ecma_object_t *obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), + object_size + (saved_arg_count * sizeof (ecma_value_t)), + ECMA_OBJECT_TYPE_CLASS); + + ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) obj_p; + + arguments_p->header.u.cls.type = ECMA_OBJECT_CLASS_ARGUMENTS; + arguments_p->header.u.cls.u1.arguments_flags = ECMA_ARGUMENTS_OBJECT_NO_FLAGS; + arguments_p->header.u.cls.u2.formal_params_number = formal_params_number; + arguments_p->header.u.cls.u3.arguments_number = 0; + arguments_p->callee = ecma_make_object_value (func_obj_p); + + ecma_value_t *argv_p = (ecma_value_t *) (((uint8_t *) obj_p) + object_size); + + for (uint32_t i = 0; i < shared_p->arg_list_len; i++) + { + argv_p[i] = ecma_copy_value_if_not_object (shared_p->arg_list_p[i]); + } + + for (uint32_t i = shared_p->arg_list_len; i < saved_arg_count; i++) + { + argv_p[i] = ECMA_VALUE_UNDEFINED; + } + + arguments_p->header.u.cls.u3.arguments_number = shared_p->arg_list_len; + + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED) + { + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) obj_p; + + ECMA_SET_INTERNAL_VALUE_POINTER (mapped_arguments_p->lex_env, lex_env_p); + arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_MAPPED; + +#if JERRY_SNAPSHOT_EXEC + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION) + { + arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE; + mapped_arguments_p->u.byte_code_p = (ecma_compiled_code_t *) bytecode_data_p; + } + else +#endif /* JERRY_SNAPSHOT_EXEC */ + { + ECMA_SET_INTERNAL_VALUE_POINTER (mapped_arguments_p->u.byte_code, bytecode_data_p); + } + + /* Static snapshots are not ref counted. */ + if ((bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION) == 0) + { + ecma_bytecode_ref ((ecma_compiled_code_t *) bytecode_data_p); + } + + ecma_value_t *formal_parameter_start_p; + formal_parameter_start_p = ecma_compiled_code_resolve_arguments_start ((ecma_compiled_code_t *) bytecode_data_p); + + for (uint32_t i = 0; i < formal_params_number; i++) + { + /* For legacy (non-strict) argument definition the trailing duplicated arguments cannot be lazy instantiated + E.g: function f (a,a,a,a) {} */ + if (JERRY_UNLIKELY (ecma_is_value_empty (formal_parameter_start_p[i]))) + { + ecma_property_value_t *prop_value_p; + ecma_string_t *prop_name_p = ecma_new_ecma_string_from_uint32 (i); + + prop_value_p = + ecma_create_named_data_property (obj_p, prop_name_p, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, NULL); + + ecma_deref_ecma_string (prop_name_p); + + prop_value_p->value = argv_p[i]; + argv_p[i] = ECMA_VALUE_EMPTY; + } + } + } + + return ecma_make_object_value (obj_p); +} /* ecma_op_create_arguments_object */ + +/** + * [[DefineOwnProperty]] ecma Arguments object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 10.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_arguments_object_define_own_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + const ecma_property_descriptor_t *property_desc_p) /**< property + * descriptor */ +{ + /* 3. */ + ecma_value_t ret_value = ecma_op_general_object_define_own_property (object_p, property_name_p, property_desc_p); + + if (ECMA_IS_VALUE_ERROR (ret_value) + || !(((ecma_extended_object_t *) object_p)->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)) + { + return ret_value; + } + + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) object_p; + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index >= mapped_arguments_p->unmapped.header.u.cls.u2.formal_params_number) + { + return ret_value; + } + + ecma_value_t *argv_p = (ecma_value_t *) (mapped_arguments_p + 1); + + if (ecma_is_value_empty (argv_p[index]) || argv_p[index] == ECMA_VALUE_ARGUMENT_NO_TRACK) + { + return ret_value; + } + + if (property_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + { + ecma_free_value_if_not_object (argv_p[index]); + argv_p[index] = ECMA_VALUE_ARGUMENT_NO_TRACK; + return ret_value; + } + + if (property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + { + ecma_string_t *name_p = ecma_op_arguments_object_get_formal_parameter (mapped_arguments_p, index); + ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, mapped_arguments_p->lex_env); + ecma_op_set_mutable_binding (lex_env_p, name_p, property_desc_p->value, true); + } + + if ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) && !(property_desc_p->flags & JERRY_PROP_IS_WRITABLE)) + { + ecma_free_value_if_not_object (argv_p[index]); + argv_p[index] = ECMA_VALUE_ARGUMENT_NO_TRACK; + } + + return ret_value; +} /* ecma_op_arguments_object_define_own_property */ + +/** + * Try to lazy instantiate the given property of a mapped/unmapped arguments object + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +ecma_property_t * +ecma_op_arguments_object_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property's name */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARGUMENTS)); + + ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) object_p; + ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1); + ecma_property_value_t *prop_value_p; + ecma_property_t *prop_p; + uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number; + uint8_t flags = arguments_p->header.u.cls.u1.arguments_flags; + + if (flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + argv_p = (ecma_value_t *) (((ecma_mapped_arguments_t *) object_p) + 1); + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index != ECMA_STRING_NOT_ARRAY_INDEX) + { + if (index >= arguments_number || ecma_is_value_empty (argv_p[index])) + { + return NULL; + } + + JERRY_ASSERT (argv_p[index] != ECMA_VALUE_ARGUMENT_NO_TRACK); + + prop_value_p = ecma_create_named_data_property (object_p, + property_name_p, + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_ENUMERABLE_WRITABLE, + &prop_p); + + /* Passing the reference */ + prop_value_p->value = argv_p[index]; + + argv_p[index] = ECMA_VALUE_UNDEFINED; + return prop_p; + } + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH) + && !(flags & ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED)) + { + prop_value_p = ecma_create_named_data_property (object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_WRITABLE, + &prop_p); + + prop_value_p->value = ecma_make_uint32_value (arguments_number); + return prop_p; + } + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_CALLEE) + && !(flags & ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED)) + { + if (flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + prop_value_p = ecma_create_named_data_property (object_p, + property_name_p, + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_WRITABLE, + &prop_p); + + prop_value_p->value = arguments_p->callee; + } + else + { + ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER); + + ecma_create_named_accessor_property (object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_CALLEE), + thrower_p, + thrower_p, + ECMA_PROPERTY_BUILT_IN_FIXED, + &prop_p); + } + return prop_p; + } + + if (ecma_op_compare_string_to_global_symbol (property_name_p, LIT_GLOBAL_SYMBOL_ITERATOR) + && !(flags & ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED)) + { + prop_value_p = ecma_create_named_data_property (object_p, + property_name_p, + ECMA_PROPERTY_BUILT_IN_CONFIGURABLE_WRITABLE, + &prop_p); + + prop_value_p->value = ecma_op_object_get_by_magic_id (ecma_builtin_get (ECMA_BUILTIN_ID_INTRINSIC_OBJECT), + LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES); + + JERRY_ASSERT (ecma_is_value_object (prop_value_p->value)); + ecma_deref_object (ecma_get_object_from_value (prop_value_p->value)); + return prop_p; + } + + return NULL; +} /* ecma_op_arguments_object_try_to_lazy_instantiate_property */ + +/** + * Delete configurable properties of arguments object + */ +void +ecma_op_arguments_delete_built_in_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p) /**< property name */ +{ + ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) object_p; + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)) + { + JERRY_ASSERT (!(arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED)); + + arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED; + return; + } + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_CALLEE)) + { + JERRY_ASSERT (!(arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED)); + JERRY_ASSERT (arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED); + + arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED; + return; + } + + if (ecma_prop_name_is_symbol (property_name_p)) + { + JERRY_ASSERT (!(arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED)); + JERRY_ASSERT (ecma_op_compare_string_to_global_symbol (property_name_p, LIT_GLOBAL_SYMBOL_ITERATOR)); + + arguments_p->header.u.cls.u1.arguments_flags |= ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED; + return; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1); + + if (arguments_p->header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + argv_p = (ecma_value_t *) (((ecma_mapped_arguments_t *) object_p) + 1); + } + + JERRY_ASSERT (argv_p[index] == ECMA_VALUE_UNDEFINED || argv_p[index] == ECMA_VALUE_ARGUMENT_NO_TRACK); + + argv_p[index] = ECMA_VALUE_EMPTY; +} /* ecma_op_arguments_delete_built_in_property */ + +/** + * List names of an arguments object's lazy instantiated properties + */ +void +ecma_op_arguments_object_list_lazy_property_names (ecma_object_t *obj_p, /**< arguments object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + JERRY_ASSERT (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_ARGUMENTS)); + + ecma_unmapped_arguments_t *arguments_p = (ecma_unmapped_arguments_t *) obj_p; + + uint32_t arguments_number = arguments_p->header.u.cls.u3.arguments_number; + uint8_t flags = arguments_p->header.u.cls.u1.arguments_flags; + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES)) + { + ecma_value_t *argv_p = (ecma_value_t *) (arguments_p + 1); + + if (flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + argv_p = (ecma_value_t *) (((ecma_mapped_arguments_t *) obj_p) + 1); + } + + for (uint32_t index = 0; index < arguments_number; index++) + { + if (!ecma_is_value_empty (argv_p[index])) + { + ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index); + ecma_collection_push_back (prop_names_p, ecma_make_string_value (index_string_p)); + prop_counter_p->array_index_named_props++; + } + } + } + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS)) + { + if (!(flags & ECMA_ARGUMENTS_OBJECT_LENGTH_INITIALIZED)) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } + + if (!(flags & ECMA_ARGUMENTS_OBJECT_CALLEE_INITIALIZED)) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLEE)); + prop_counter_p->string_named_props++; + } + } + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS) && !(flags & ECMA_ARGUMENTS_OBJECT_ITERATOR_INITIALIZED)) + { + ecma_string_t *symbol_p = ecma_op_get_global_symbol (LIT_GLOBAL_SYMBOL_ITERATOR); + ecma_collection_push_back (prop_names_p, ecma_make_symbol_value (symbol_p)); + prop_counter_p->symbol_named_props++; + } +} /* ecma_op_arguments_object_list_lazy_property_names */ + +/** + * Get the formal parameter name corresponding to the given property index + * + * @return pointer to the formal parameter name + */ +ecma_string_t * +ecma_op_arguments_object_get_formal_parameter (ecma_mapped_arguments_t *mapped_arguments_p, /**< mapped arguments + * object */ + uint32_t index) /**< formal parameter index */ +{ + JERRY_ASSERT (mapped_arguments_p->unmapped.header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED); + JERRY_ASSERT (index < mapped_arguments_p->unmapped.header.u.cls.u2.formal_params_number); + + ecma_compiled_code_t *byte_code_p; + +#if JERRY_SNAPSHOT_EXEC + if (mapped_arguments_p->unmapped.header.u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_STATIC_BYTECODE) + { + byte_code_p = mapped_arguments_p->u.byte_code_p; + } + else +#endif /* JERRY_SNAPSHOT_EXEC */ + { + byte_code_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, mapped_arguments_p->u.byte_code); + } + + ecma_value_t *formal_param_names_p = ecma_compiled_code_resolve_arguments_start (byte_code_p); + + return ecma_get_string_from_value (formal_param_names_p[index]); +} /* ecma_op_arguments_object_get_formal_parameter */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arguments-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arguments-object.h new file mode 100644 index 0000000..755b755 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arguments-object.h @@ -0,0 +1,42 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ARGUMENTS_OBJECT_H +#define ECMA_ARGUMENTS_OBJECT_H + +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#include "vm-defines.h" + +ecma_value_t ecma_op_create_arguments_object (vm_frame_ctx_shared_args_t *shared_p, ecma_object_t *lex_env_p); + +ecma_value_t ecma_op_arguments_object_define_own_property (ecma_object_t *object_p, + ecma_string_t *property_name_p, + const ecma_property_descriptor_t *property_desc_p); + +ecma_property_t *ecma_op_arguments_object_try_to_lazy_instantiate_property (ecma_object_t *object_p, + ecma_string_t *property_name_p); + +void ecma_op_arguments_delete_built_in_property (ecma_object_t *object_p, ecma_string_t *property_name_p); + +void ecma_op_arguments_object_list_lazy_property_names (ecma_object_t *obj_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); + +ecma_string_t *ecma_op_arguments_object_get_formal_parameter (ecma_mapped_arguments_t *mapped_arguments_p, + uint32_t index); +#endif /* !ECMA_ARGUMENTS_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-array-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-array-object.cpp new file mode 100644 index 0000000..2ee4d80 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-array-object.cpp @@ -0,0 +1,1215 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-array-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-property-hashmap.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarrayobject ECMA Array object related routines + * @{ + */ + +/** + * Property name type flag for array indices. + */ +#define ECMA_FAST_ARRAY_UINT_DIRECT_STRING_PROP_TYPE (ECMA_DIRECT_STRING_UINT << ECMA_PROPERTY_NAME_TYPE_SHIFT) + +/** + * Allocate a new array object with the given length + * + * @return pointer to the constructed array object + */ +static ecma_object_t * +ecma_op_alloc_array_object (uint32_t length) /**< length of the new array */ +{ +#if JERRY_BUILTIN_ARRAY + ecma_object_t *array_prototype_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE); +#else /* !JERRY_BUILTIN_ARRAY */ + ecma_object_t *array_prototype_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); +#endif /* JERRY_BUILTIN_ARRAY */ + + ecma_object_t *object_p = + ecma_create_object (array_prototype_object_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_ARRAY); + + /* + * [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_ARRAY type. + * + * See also: ecma_object_get_class_name + */ + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ext_obj_p->u.array.length = length; + ext_obj_p->u.array.length_prop_and_hole_count = ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROPERTY_VIRTUAL; + + return object_p; +} /* ecma_op_alloc_array_object */ + +/** + * Check whether the given object is fast-access mode array + * + * @return true - if the object is fast-access mode array + * false, otherwise + */ +bool +ecma_op_object_is_fast_array (ecma_object_t *object_p) /**< ecma-object */ +{ + return (ecma_get_object_base_type (object_p) == ECMA_OBJECT_BASE_TYPE_ARRAY + && ecma_op_array_is_fast_array ((ecma_extended_object_t *) object_p)); +} /* ecma_op_object_is_fast_array */ + +/** + * Check whether the given array object is fast-access mode array + * + * @return true - if the array object is fast-access mode array + * false, otherwise + */ +bool +ecma_op_array_is_fast_array (ecma_extended_object_t *array_p) /**< ecma-array-object */ +{ + JERRY_ASSERT (ecma_get_object_base_type ((ecma_object_t *) array_p) == ECMA_OBJECT_BASE_TYPE_ARRAY); + + return array_p->u.array.length_prop_and_hole_count & ECMA_FAST_ARRAY_FLAG; +} /* ecma_op_array_is_fast_array */ + +/** + * Allocate a new array object with the given length + * + * Note: The returned array can be normal of fast access mode + * + * @return pointer to the constructed array object + */ +ecma_object_t * +ecma_op_new_array_object (uint32_t length) /**< length of the new array */ +{ + ecma_object_t *object_p = ecma_op_alloc_array_object (length); + + const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (length); + ecma_value_t *values_p = NULL; + + if (length > 0) + { + if (length >= ECMA_FAST_ARRAY_MAX_HOLE_COUNT) + { + return object_p; + } + + values_p = (ecma_value_t *) jmem_heap_alloc_block_null_on_error (aligned_length * sizeof (ecma_value_t)); + + if (JERRY_UNLIKELY (values_p == NULL)) + { + return object_p; + } + } + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ext_obj_p->u.array.length_prop_and_hole_count |= ECMA_FAST_ARRAY_FLAG; + ext_obj_p->u.array.length_prop_and_hole_count += length * ECMA_FAST_ARRAY_HOLE_ONE; + + for (uint32_t i = 0; i < aligned_length; i++) + { + values_p[i] = ECMA_VALUE_ARRAY_HOLE; + } + + JERRY_ASSERT (object_p->u1.property_list_cp == JMEM_CP_NULL); + ECMA_SET_POINTER (object_p->u1.property_list_cp, values_p); + return object_p; +} /* ecma_op_new_array_object */ + +/** + * Allocate a new array object from the given length + * + * Note: The returned array can be normal of fast access mode + * + * @return NULL - if the given length is invalid + * pointer to the constructed array object - otherwise + */ +ecma_object_t * +ecma_op_new_array_object_from_length (ecma_length_t length) /**< length of the new array */ +{ + if (length > UINT32_MAX) + { + ecma_raise_range_error (ECMA_ERR_INVALID_ARRAY_LENGTH); + return NULL; + } + + return ecma_op_new_array_object ((uint32_t) length); +} /* ecma_op_new_array_object_from_length */ + +/** + * Allocate a new array object from the given buffer + * + * Note: The returned array can be normal of fast access mode + * + * @return ecma_value - constructed array object + */ +ecma_value_t +ecma_op_new_array_object_from_buffer (const ecma_value_t *args_p, /**< array element list */ + uint32_t length) /**< number of array elements */ +{ + if (length == 0) + { + return ecma_make_object_value (ecma_op_new_array_object (0)); + } + + ecma_object_t *object_p = ecma_op_alloc_array_object (length); + const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (length); + ecma_value_t *values_p; + values_p = (ecma_value_t *) jmem_heap_alloc_block_null_on_error (aligned_length * sizeof (ecma_value_t)); + + if (values_p != NULL) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ext_obj_p->u.array.length_prop_and_hole_count |= ECMA_FAST_ARRAY_FLAG; + JERRY_ASSERT (object_p->u1.property_list_cp == JMEM_CP_NULL); + + for (uint32_t i = 0; i < length; i++) + { + JERRY_ASSERT (!ecma_is_value_array_hole (args_p[i])); + values_p[i] = ecma_copy_value_if_not_object (args_p[i]); + } + + for (uint32_t i = length; i < aligned_length; i++) + { + values_p[i] = ECMA_VALUE_ARRAY_HOLE; + } + + ECMA_SET_POINTER (object_p->u1.property_list_cp, values_p); + } + else + { + for (uint32_t i = 0; i < length; i++) + { + JERRY_ASSERT (!ecma_is_value_array_hole (args_p[i])); + + ecma_string_t *prop_name_p = ecma_new_ecma_string_from_uint32 (i); + ecma_property_value_t *prop_value_p; + prop_value_p = + ecma_create_named_data_property (object_p, prop_name_p, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, NULL); + ecma_deref_ecma_string (prop_name_p); + prop_value_p->value = ecma_copy_value_if_not_object (args_p[i]); + } + } + + return ecma_make_object_value (object_p); +} /* ecma_op_new_array_object_from_buffer */ + +/** + * Allocate a new fast access mode array object from the given collection + * + * Note: The given collection will be unavailable after and it's underlying buffer is reused + * + * @return ecma_value - constructed fast access mode array object + */ +ecma_value_t +ecma_op_new_array_object_from_collection (ecma_collection_t *collection_p, /**< collection to create array from */ + bool unref_objects) /**< true - if the collection potentially + contains objects + false - otherwise */ +{ + const uint32_t item_count = collection_p->item_count; + + if (item_count == 0) + { + ecma_collection_destroy (collection_p); + return ecma_make_object_value (ecma_op_new_array_object (0)); + } + + ecma_object_t *object_p; + ecma_value_t *buffer_p = collection_p->buffer_p; + const uint32_t old_size = ECMA_COLLECTION_ALLOCATED_SIZE (collection_p->capacity); + const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (collection_p->item_count); + + jmem_heap_free_block (collection_p, sizeof (ecma_collection_t)); + buffer_p = (ecma_value_t *) jmem_heap_realloc_block (buffer_p, old_size, aligned_length * sizeof (ecma_value_t)); + object_p = (ecma_object_t *) ecma_op_alloc_array_object (item_count); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ext_obj_p->u.array.length_prop_and_hole_count |= ECMA_FAST_ARRAY_FLAG; + JERRY_ASSERT (object_p->u1.property_list_cp == JMEM_CP_NULL); + JERRY_ASSERT (ext_obj_p->u.array.length_prop_and_hole_count < ECMA_FAST_ARRAY_HOLE_ONE); + ECMA_SET_POINTER (object_p->u1.property_list_cp, buffer_p); + + if (JERRY_UNLIKELY (unref_objects)) + { + for (uint32_t i = 0; i < item_count; i++) + { + /* Strong references from the collection are no longer needed + since GC will mark these object as a fast access mode array properties */ + ecma_deref_if_object (buffer_p[i]); + } + } + + for (uint32_t i = item_count; i < aligned_length; i++) + { + buffer_p[i] = ECMA_VALUE_ARRAY_HOLE; + } + + return ecma_make_object_value (object_p); +} /* ecma_op_new_array_object_from_collection */ + +/** + * Converts a fast access mode array back to a normal property list based array + */ +void +ecma_fast_array_convert_to_normal (ecma_object_t *object_p) /**< fast access mode array object */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + + if (object_p->u1.property_list_cp == JMEM_CP_NULL) + { + ext_obj_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_FAST_ARRAY_FLAG; + return; + } + + uint32_t length = ext_obj_p->u.array.length; + const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (length); + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + ecma_ref_object (object_p); + + ecma_property_pair_t *property_pair_p = NULL; + jmem_cpointer_t next_property_pair_cp = JMEM_CP_NULL; + + uint32_t prop_index = 1; + int32_t index = (int32_t) (length - 1); + + while (index >= 0) + { + if (ecma_is_value_array_hole (values_p[index])) + { + index--; + continue; + } + + if (prop_index == 1) + { + property_pair_p = ecma_alloc_property_pair (); + property_pair_p->header.next_property_cp = next_property_pair_cp; + property_pair_p->names_cp[0] = LIT_INTERNAL_MAGIC_STRING_DELETED; + property_pair_p->header.types[0] = ECMA_PROPERTY_TYPE_DELETED; + ECMA_SET_NON_NULL_POINTER (next_property_pair_cp, property_pair_p); + } + + JERRY_ASSERT (index <= ECMA_DIRECT_STRING_MAX_IMM); + + property_pair_p->names_cp[prop_index] = (jmem_cpointer_t) index; + property_pair_p->header.types[prop_index] = + (ecma_property_t) (ECMA_PROPERTY_FLAG_DATA | ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE + | ECMA_FAST_ARRAY_UINT_DIRECT_STRING_PROP_TYPE); + + property_pair_p->values[prop_index].value = values_p[index]; + + index--; + prop_index = !prop_index; + } + + ext_obj_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_FAST_ARRAY_FLAG; + jmem_heap_free_block (values_p, aligned_length * sizeof (ecma_value_t)); + ECMA_SET_POINTER (object_p->u1.property_list_cp, property_pair_p); + + ecma_deref_object (object_p); +} /* ecma_fast_array_convert_to_normal */ + +/** + * [[Put]] operation for a fast access mode array + * + * @return false - If the property name is not array index, or the requested index to be set + * would result too much array hole in the underlying buffer. The these cases + * the array is converted back to normal property list based array. + * true - If the indexed property can be set with/without resizing the underlying buffer. + */ +bool +ecma_fast_array_set_property (ecma_object_t *object_p, /**< fast access mode array object */ + uint32_t index, /**< property name index */ + ecma_value_t value) /**< value to be set */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + uint32_t old_length = ext_obj_p->u.array.length; + + ecma_value_t *values_p; + + if (JERRY_LIKELY (index < old_length)) + { + JERRY_ASSERT (object_p->u1.property_list_cp != JMEM_CP_NULL); + + values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + if (ecma_is_value_array_hole (values_p[index])) + { + ext_obj_p->u.array.length_prop_and_hole_count -= ECMA_FAST_ARRAY_HOLE_ONE; + } + else + { + ecma_free_value_if_not_object (values_p[index]); + } + + values_p[index] = ecma_copy_value_if_not_object (value); + + return true; + } + + uint32_t old_holes = ext_obj_p->u.array.length_prop_and_hole_count; + uint32_t new_holes = index - old_length; + + if (JERRY_UNLIKELY (new_holes > (ECMA_FAST_ARRAY_MAX_HOLE_COUNT - (old_holes >> ECMA_FAST_ARRAY_HOLE_SHIFT)))) + { + ecma_fast_array_convert_to_normal (object_p); + + return false; + } + + uint32_t new_length = index + 1; + + JERRY_ASSERT (new_length < UINT32_MAX); + + const uint32_t aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (old_length); + + if (JERRY_LIKELY (index < aligned_length)) + { + JERRY_ASSERT (object_p->u1.property_list_cp != JMEM_CP_NULL); + + values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + /* This area is filled with ECMA_VALUE_ARRAY_HOLE, but not counted in u.array.length_prop_and_hole_count */ + JERRY_ASSERT (ecma_is_value_array_hole (values_p[index])); + ext_obj_p->u.array.length_prop_and_hole_count += new_holes * ECMA_FAST_ARRAY_HOLE_ONE; + ext_obj_p->u.array.length = new_length; + } + else + { + values_p = ecma_fast_array_extend (object_p, new_length); + ext_obj_p->u.array.length_prop_and_hole_count -= ECMA_FAST_ARRAY_HOLE_ONE; + } + + values_p[index] = ecma_copy_value_if_not_object (value); + + return true; +} /* ecma_fast_array_set_property */ + +/** + * Get the number of array holes in a fast access array object + * + * @return number of array holes in a fast access array object + */ +uint32_t +ecma_fast_array_get_hole_count (ecma_object_t *obj_p) /**< fast access mode array object */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (obj_p)); + + return ((ecma_extended_object_t *) obj_p)->u.array.length_prop_and_hole_count >> ECMA_FAST_ARRAY_HOLE_SHIFT; +} /* ecma_fast_array_get_hole_count */ + +/** + * Extend the underlying buffer of a fast mode access array for the given new length + * + * @return pointer to the extended underlying buffer + */ +ecma_value_t * +ecma_fast_array_extend (ecma_object_t *object_p, /**< fast access mode array object */ + uint32_t new_length) /**< new length of the fast access mode array */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + uint32_t old_length = ext_obj_p->u.array.length; + + JERRY_ASSERT (old_length < new_length); + + ecma_ref_object (object_p); + + ecma_value_t *new_values_p; + const uint32_t old_length_aligned = ECMA_FAST_ARRAY_ALIGN_LENGTH (old_length); + const uint32_t new_length_aligned = ECMA_FAST_ARRAY_ALIGN_LENGTH (new_length); + + if (object_p->u1.property_list_cp == JMEM_CP_NULL) + { + new_values_p = (ecma_value_t *) jmem_heap_alloc_block (new_length_aligned * sizeof (ecma_value_t)); + } + else + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + new_values_p = (ecma_value_t *) jmem_heap_realloc_block (values_p, + old_length_aligned * sizeof (ecma_value_t), + new_length_aligned * sizeof (ecma_value_t)); + } + + for (uint32_t i = old_length; i < new_length_aligned; i++) + { + new_values_p[i] = ECMA_VALUE_ARRAY_HOLE; + } + + ext_obj_p->u.array.length_prop_and_hole_count += (new_length - old_length) * ECMA_FAST_ARRAY_HOLE_ONE; + ext_obj_p->u.array.length = new_length; + + ECMA_SET_NON_NULL_POINTER (object_p->u1.property_list_cp, new_values_p); + + ecma_deref_object (object_p); + return new_values_p; +} /* ecma_fast_array_extend */ + +/** + * Delete the array object's property referenced by its value pointer. + * + * Note: specified property must be owned by specified object. + * + * @return true, if the property is deleted + * false, otherwise + */ +bool +ecma_array_object_delete_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_ASSERT (ecma_get_object_base_type (object_p) == ECMA_OBJECT_BASE_TYPE_ARRAY); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + + if (!ecma_op_object_is_fast_array (object_p)) + { + return false; + } + + JERRY_ASSERT (object_p->u1.property_list_cp != JMEM_CP_NULL); + + uint32_t index = ecma_string_get_array_index (property_name_p); + + JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX); + JERRY_ASSERT (index < ext_obj_p->u.array.length); + + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + if (ecma_is_value_array_hole (values_p[index])) + { + return true; + } + + ecma_free_value_if_not_object (values_p[index]); + + values_p[index] = ECMA_VALUE_ARRAY_HOLE; + ext_obj_p->u.array.length_prop_and_hole_count += ECMA_FAST_ARRAY_HOLE_ONE; + return true; +} /* ecma_array_object_delete_property */ + +/** + * Low level delete of fast access mode array items + * + * @return the updated value of new_length + */ +uint32_t +ecma_delete_fast_array_properties (ecma_object_t *object_p, /**< fast access mode array */ + uint32_t new_length) /**< new length of the fast access mode array */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + + ecma_ref_object (object_p); + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + uint32_t old_length = ext_obj_p->u.array.length; + const uint32_t old_aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (old_length); + JERRY_ASSERT (new_length < old_length); + + for (uint32_t i = new_length; i < old_length; i++) + { + if (ecma_is_value_array_hole (values_p[i])) + { + ext_obj_p->u.array.length_prop_and_hole_count -= ECMA_FAST_ARRAY_HOLE_ONE; + } + else + { + ecma_free_value_if_not_object (values_p[i]); + } + } + + jmem_cpointer_t new_property_list_cp; + + if (new_length == 0) + { + jmem_heap_free_block (values_p, old_aligned_length * sizeof (ecma_value_t)); + new_property_list_cp = JMEM_CP_NULL; + } + else + { + const uint32_t new_aligned_length = ECMA_FAST_ARRAY_ALIGN_LENGTH (new_length); + + ecma_value_t *new_values_p; + new_values_p = (ecma_value_t *) jmem_heap_realloc_block (values_p, + old_aligned_length * sizeof (ecma_value_t), + new_aligned_length * sizeof (ecma_value_t)); + + for (uint32_t i = new_length; i < new_aligned_length; i++) + { + new_values_p[i] = ECMA_VALUE_ARRAY_HOLE; + } + + ECMA_SET_NON_NULL_POINTER (new_property_list_cp, new_values_p); + } + + ext_obj_p->u.array.length = new_length; + object_p->u1.property_list_cp = new_property_list_cp; + + ecma_deref_object (object_p); + + return new_length; +} /* ecma_delete_fast_array_properties */ + +/** + * Update the length of a fast access mode array to a new length + * + * Note: if the new length would result too much array hole in the underlying arraybuffer + * the array is converted back to normal property list based array + */ +static void +ecma_fast_array_set_length (ecma_object_t *object_p, /**< fast access mode array object */ + uint32_t new_length) /**< new length of the fast access mode array object*/ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + uint32_t old_length = ext_obj_p->u.array.length; + + JERRY_ASSERT (new_length >= old_length); + + if (new_length == old_length) + { + return; + } + + uint32_t old_holes = ext_obj_p->u.array.length_prop_and_hole_count; + uint32_t new_holes = new_length - old_length; + + if (JERRY_UNLIKELY (new_holes > (ECMA_FAST_ARRAY_MAX_HOLE_COUNT - (old_holes >> ECMA_FAST_ARRAY_HOLE_SHIFT)))) + { + ecma_fast_array_convert_to_normal (object_p); + } + else + { + ecma_fast_array_extend (object_p, new_length); + } +} /* ecma_fast_array_set_length */ + +/** + * Get collection of property names of a fast access mode array object + * + * Note: Since the fast array object only contains indexed, enumerable, writable, configurable properties + * we can return a collection of non-array hole array indices + * + * @return collection of strings - property names + */ +ecma_collection_t * +ecma_fast_array_object_own_property_keys (ecma_object_t *object_p, /**< fast access mode array object */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + JERRY_ASSERT (ecma_op_object_is_fast_array (object_p)); + + ecma_collection_t *ret_p = ecma_new_collection (); + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES)) + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + uint32_t length = ext_obj_p->u.array.length; + + if (length != 0) + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + for (uint32_t i = 0; i < length; i++) + { + if (ecma_is_value_array_hole (values_p[i])) + { + continue; + } + + ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i); + + ecma_collection_push_back (ret_p, ecma_make_string_value (index_str_p)); + } + } + } + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS)) + { + ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + } + + return ret_p; +} /* ecma_fast_array_object_own_property_keys */ + +/** + * Array object creation with custom prototype. + * + * See also: ECMA-262 v6, 9.4.2.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_object_t * +ecma_op_array_species_create (ecma_object_t *original_array_p, /**< The object from whom the new array object + * is being created */ + ecma_length_t length) /**< length of the array */ +{ + ecma_value_t constructor = ECMA_VALUE_UNDEFINED; + ecma_value_t original_array = ecma_make_object_value (original_array_p); + + ecma_value_t is_array = ecma_is_value_array (original_array); + + if (ECMA_IS_VALUE_ERROR (is_array)) + { + return NULL; + } + + if (ecma_is_value_true (is_array)) + { + constructor = ecma_op_object_get_by_magic_id (original_array_p, LIT_MAGIC_STRING_CONSTRUCTOR); + if (ECMA_IS_VALUE_ERROR (constructor)) + { + return NULL; + } + +#if JERRY_BUILTIN_REALMS + if (ecma_is_constructor (constructor)) + { + ecma_object_t *constructor_p = ecma_get_object_from_value (constructor); + ecma_global_object_t *global_object_p = ecma_op_function_get_function_realm (constructor_p); + + if ((ecma_object_t *) global_object_p != ecma_builtin_get_global () + && constructor_p == ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_ARRAY)) + { + ecma_deref_object (constructor_p); + constructor = ECMA_VALUE_UNDEFINED; + } + } +#endif /* JERRY_BUILTIN_REALMS */ + + if (ecma_is_value_object (constructor)) + { + ecma_object_t *ctor_object_p = ecma_get_object_from_value (constructor); + constructor = ecma_op_object_get_by_symbol_id (ctor_object_p, LIT_GLOBAL_SYMBOL_SPECIES); + ecma_deref_object (ctor_object_p); + + if (ECMA_IS_VALUE_ERROR (constructor)) + { + return NULL; + } + + if (ecma_is_value_null (constructor)) + { + constructor = ECMA_VALUE_UNDEFINED; + } + } + } + + if (ecma_is_value_undefined (constructor)) + { + return ecma_op_new_array_object_from_length (length); + } + + if (!ecma_is_constructor (constructor)) + { + ecma_free_value (constructor); + ecma_raise_type_error (ECMA_ERR_INVALID_SPECIES_CONSTRUCTOR); + return NULL; + } + + ecma_value_t len_val = ecma_make_length_value (length); + ecma_object_t *ctor_object_p = ecma_get_object_from_value (constructor); + ecma_value_t ret_val = ecma_op_function_construct (ctor_object_p, ctor_object_p, &len_val, 1); + + ecma_deref_object (ctor_object_p); + ecma_free_value (len_val); + + if (ECMA_IS_VALUE_ERROR (ret_val)) + { + return NULL; + } + + return ecma_get_object_from_value (ret_val); +} /* ecma_op_array_species_create */ + +/** + * CreateArrayIterator Abstract Operation + * + * See also: + * ECMA-262 v6, 22.1.5.1 + * + * Referenced by: + * ECMA-262 v6, 22.1.3.4 + * ECMA-262 v6, 22.1.3.13 + * ECMA-262 v6, 22.1.3.29 + * ECMA-262 v6, 22.1.3.30 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return array iterator object + */ +ecma_value_t +ecma_op_create_array_iterator (ecma_object_t *obj_p, /**< array object */ + ecma_iterator_kind_t kind) /**< array iterator kind */ +{ + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_ITERATOR_PROTOTYPE); + + return ecma_op_create_iterator_object (ecma_make_object_value (obj_p), + prototype_obj_p, + ECMA_OBJECT_CLASS_ARRAY_ITERATOR, + kind); +} /* ecma_op_create_array_iterator */ + +/** + * Low level delete of array items from new_length to old_length + * + * Note: new_length must be less than old_length + * + * @return the updated value of new_length + */ +static uint32_t +ecma_delete_array_properties (ecma_object_t *object_p, /**< object */ + uint32_t new_length, /**< new length */ + uint32_t old_length) /**< old length */ +{ + JERRY_ASSERT (new_length < old_length); + JERRY_ASSERT (ecma_get_object_base_type (object_p) == ECMA_OBJECT_BASE_TYPE_ARRAY); + + if (ecma_op_object_is_fast_array (object_p)) + { + return ecma_delete_fast_array_properties (object_p, new_length); + } + + /* First the minimum value of new_length is updated. */ + jmem_cpointer_t current_prop_cp = object_p->u1.property_list_cp; + + if (current_prop_cp == JMEM_CP_NULL) + { + return new_length; + } + + ecma_property_header_t *current_prop_p; + +#if JERRY_PROPERTY_HASHMAP + current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp); + + if (current_prop_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + current_prop_cp = current_prop_p->next_property_cp; + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (current_prop_cp != JMEM_CP_NULL) + { + current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (current_prop_p)); + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) current_prop_p; + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (current_prop_p->types[i] != ECMA_PROPERTY_TYPE_DELETED + && !ecma_is_property_configurable (current_prop_p->types[i])) + { + uint32_t index = ecma_string_get_property_index (current_prop_p->types[i], prop_pair_p->names_cp[i]); + + if (index < old_length && index >= new_length) + { + JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX); + + new_length = index + 1; + + if (new_length == old_length) + { + /* Early return. */ + return new_length; + } + } + } + } + + current_prop_cp = current_prop_p->next_property_cp; + } + + /* Second all properties between new_length and old_length are deleted. */ + current_prop_cp = object_p->u1.property_list_cp; + ecma_property_header_t *prev_prop_p = NULL; + +#if JERRY_PROPERTY_HASHMAP + JERRY_ASSERT (current_prop_cp != JMEM_CP_NULL); + + ecma_property_hashmap_delete_status hashmap_status = ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP; + current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp); + + if (current_prop_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prev_prop_p = current_prop_p; + current_prop_cp = current_prop_p->next_property_cp; + hashmap_status = ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP; + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (current_prop_cp != JMEM_CP_NULL) + { + current_prop_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, current_prop_cp); + + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (current_prop_p)); + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) current_prop_p; + + for (uint32_t i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + if (current_prop_p->types[i] != ECMA_PROPERTY_TYPE_DELETED + && ecma_is_property_configurable (current_prop_p->types[i])) + { + uint32_t index = ecma_string_get_property_index (current_prop_p->types[i], prop_pair_p->names_cp[i]); + + if (index < old_length && index >= new_length) + { + JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX); + +#if JERRY_PROPERTY_HASHMAP + if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP) + { + hashmap_status = + ecma_property_hashmap_delete (object_p, prop_pair_p->names_cp[i], current_prop_p->types + i); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + ecma_gc_free_property (object_p, prop_pair_p, i); + current_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED; + prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED; + } + } + } + + if (current_prop_p->types[0] == ECMA_PROPERTY_TYPE_DELETED + && current_prop_p->types[1] == ECMA_PROPERTY_TYPE_DELETED) + { + if (prev_prop_p == NULL) + { + object_p->u1.property_list_cp = current_prop_p->next_property_cp; + } + else + { + prev_prop_p->next_property_cp = current_prop_p->next_property_cp; + } + + jmem_cpointer_t next_prop_cp = current_prop_p->next_property_cp; + ecma_dealloc_property_pair ((ecma_property_pair_t *) current_prop_p); + current_prop_cp = next_prop_cp; + } + else + { + prev_prop_p = current_prop_p; + current_prop_cp = current_prop_p->next_property_cp; + } + } + +#if JERRY_PROPERTY_HASHMAP + if (hashmap_status == ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP) + { + ecma_property_hashmap_free (object_p); + ecma_property_hashmap_create (object_p); + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + return new_length; +} /* ecma_delete_array_properties */ + +/** + * Update the length of an array to a new length + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_array_object_set_length (ecma_object_t *object_p, /**< the array object */ + ecma_value_t new_value, /**< new length value */ + uint16_t flags) /**< property descriptor flags */ +{ + ecma_number_t new_len_num; + ecma_value_t completion = ecma_op_to_number (new_value, &new_len_num); + + if (ECMA_IS_VALUE_ERROR (completion)) + { + return completion; + } + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (completion)); + + if (ecma_is_value_object (new_value)) + { + ecma_value_t compared_num_val = ecma_op_to_number (new_value, &new_len_num); + + if (ECMA_IS_VALUE_ERROR (compared_num_val)) + { + return compared_num_val; + } + } + + uint32_t new_len_uint32 = ecma_number_to_uint32 (new_len_num); + + if (((ecma_number_t) new_len_uint32) != new_len_num) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_ARRAY_LENGTH); + } + + /* Only the writable and data properties can be modified. */ + if (flags + & (JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_ENUMERABLE | JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + { + return ecma_raise_property_redefinition (ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), flags); + } + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + uint32_t old_len_uint32 = ext_object_p->u.array.length; + + if (new_len_num == old_len_uint32) + { + /* Only the writable flag must be updated. */ + if (flags & JERRY_PROP_IS_WRITABLE_DEFINED) + { + if (!(flags & JERRY_PROP_IS_WRITABLE)) + { + if (ecma_op_array_is_fast_array (ext_object_p)) + { + ecma_fast_array_convert_to_normal (object_p); + } + + ext_object_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_PROPERTY_FLAG_WRITABLE; + } + else if (!ecma_is_property_writable ((ecma_property_t) ext_object_p->u.array.length_prop_and_hole_count)) + { + return ecma_raise_property_redefinition (ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), flags); + } + } + return ECMA_VALUE_TRUE; + } + else if (!ecma_is_property_writable ((ecma_property_t) ext_object_p->u.array.length_prop_and_hole_count)) + { + return ecma_raise_property_redefinition (ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), flags); + } + + uint32_t current_len_uint32 = new_len_uint32; + + if (new_len_uint32 < old_len_uint32) + { + current_len_uint32 = ecma_delete_array_properties (object_p, new_len_uint32, old_len_uint32); + } + else if (ecma_op_object_is_fast_array (object_p)) + { + ecma_fast_array_set_length (object_p, new_len_uint32); + } + + ext_object_p->u.array.length = current_len_uint32; + + if ((flags & JERRY_PROP_IS_WRITABLE_DEFINED) && !(flags & JERRY_PROP_IS_WRITABLE)) + { + if (ecma_op_array_is_fast_array (ext_object_p)) + { + ecma_fast_array_convert_to_normal (object_p); + } + + ext_object_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_PROPERTY_FLAG_WRITABLE; + } + + if (current_len_uint32 == new_len_uint32) + { + return ECMA_VALUE_TRUE; + } + + return ecma_raise_property_redefinition (ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), flags); +} /* ecma_op_array_object_set_length */ + +/** + * Property descriptor bitset for fast array data properties. + * If the property descriptor fields contains all the flags below + * attempt to stay fast access array during [[DefineOwnProperty]] operation. + */ +#define ECMA_FAST_ARRAY_DATA_PROP_FLAGS \ + (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE \ + | JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_WRITABLE_DEFINED \ + | JERRY_PROP_IS_WRITABLE) + +/** + * [[DefineOwnProperty]] ecma array object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 15.4.5.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_array_object_define_own_property (ecma_object_t *object_p, /**< the array object */ + ecma_string_t *property_name_p, /**< property name */ + const ecma_property_descriptor_t *property_desc_p) /**< property descriptor */ +{ + if (ecma_string_is_length (property_name_p)) + { + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED) + || !(property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE)); + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + || !(property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE)); + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) + || !(property_desc_p->flags & JERRY_PROP_IS_WRITABLE)); + + if (property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + { + return ecma_op_array_object_set_length (object_p, property_desc_p->value, property_desc_p->flags); + } + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ecma_value_t length_value = ecma_make_uint32_value (ext_object_p->u.array.length); + + ecma_value_t result = ecma_op_array_object_set_length (object_p, length_value, property_desc_p->flags); + + ecma_fast_free_value (length_value); + return result; + } + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ecma_op_object_is_fast_array (object_p)) + { + if ((property_desc_p->flags & ECMA_FAST_ARRAY_DATA_PROP_FLAGS) == ECMA_FAST_ARRAY_DATA_PROP_FLAGS) + { + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (JERRY_UNLIKELY (index == ECMA_STRING_NOT_ARRAY_INDEX)) + { + ecma_fast_array_convert_to_normal (object_p); + } + else if (ecma_fast_array_set_property (object_p, index, property_desc_p->value)) + { + return ECMA_VALUE_TRUE; + } + + JERRY_ASSERT (!ecma_op_array_is_fast_array (ext_object_p)); + } + else + { + ecma_fast_array_convert_to_normal (object_p); + } + } + + JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p)); + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) + { + return ecma_op_general_object_define_own_property (object_p, property_name_p, property_desc_p); + } + + bool update_length = (index >= ext_object_p->u.array.length); + + if (update_length && !ecma_is_property_writable ((ecma_property_t) ext_object_p->u.array.length_prop_and_hole_count)) + { + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + ecma_property_descriptor_t prop_desc; + + prop_desc = *property_desc_p; + prop_desc.flags &= (uint16_t) ~JERRY_PROP_SHOULD_THROW; + + ecma_value_t completion = ecma_op_general_object_define_own_property (object_p, property_name_p, &prop_desc); + JERRY_ASSERT (ecma_is_value_boolean (completion)); + + if (ecma_is_value_false (completion)) + { + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + if (update_length) + { + ext_object_p->u.array.length = index + 1; + } + + return ECMA_VALUE_TRUE; +} /* ecma_op_array_object_define_own_property */ + +/** + * Get the length of the an array object + * + * @return the array length + */ +uint32_t +ecma_array_get_length (ecma_object_t *array_p) /**< array object */ +{ + JERRY_ASSERT (ecma_get_object_base_type (array_p) == ECMA_OBJECT_BASE_TYPE_ARRAY); + + return ((ecma_extended_object_t *) array_p)->u.array.length; +} /* ecma_array_get_length */ + +/** + * The Array.prototype and %TypedArray%.prototype objects' 'toString' routine. + * + * See also: + * ECMA-262 v5, 15.4.4.2 + * ECMA-262 v6, 22.1.3.7 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_array_object_to_string (ecma_value_t this_arg) /**< this argument */ +{ + JERRY_ASSERT (ecma_is_value_object (this_arg)); + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + ecma_object_t *obj_p = ecma_get_object_from_value (this_arg); + + /* 2. */ + ecma_value_t join_value = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_JOIN); + if (ECMA_IS_VALUE_ERROR (join_value)) + { + return join_value; + } + + if (!ecma_op_is_callable (join_value)) + { + /* 3. */ + ret_value = ecma_builtin_helper_object_to_string (this_arg); + } + else + { + /* 4. */ + ecma_object_t *join_func_obj_p = ecma_get_object_from_value (join_value); + + ret_value = ecma_op_function_call (join_func_obj_p, this_arg, NULL, 0); + } + + ecma_free_value (join_value); + + return ret_value; +} /* ecma_array_object_to_string */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-array-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-array-object.h new file mode 100644 index 0000000..144635e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-array-object.h @@ -0,0 +1,110 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ARRAY_OBJECT_H +#define ECMA_ARRAY_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarrayobject ECMA Array object related routines + * @{ + */ + +/** + * Attributes of fast access mode arrays: + * + * - The internal property is replaced with a buffer which directly stores the values + * - Whenever any operation would change the following attributes of the array it should be converted back to normal + * - All properties must be enumerable configurable writable data properties + * - The prototype must be Array.prototype + * - [[Extensible]] internal property must be true + * - 'length' property of the array must be writable + * + * - The conversion is also required when a property is set if: + * - The property name is not an array index + * - The new hole count of the array would reach ECMA_FAST_ARRAY_MAX_NEW_HOLES_COUNT + */ + +/** + * Maximum number of new array holes in a fast mode access array. + * If the number of new holes exceeds this limit, the array is converted back + * to normal property list based array. + */ +#define ECMA_FAST_ARRAY_MAX_NEW_HOLES_COUNT 32 + +/** + * Bitshift index for fast array hole count representation + */ +#define ECMA_FAST_ARRAY_HOLE_SHIFT 8 + +/** + * This number represents 1 array hole in underlying buffer of a fast access mode array + */ +#define ECMA_FAST_ARRAY_HOLE_ONE (1 << ECMA_FAST_ARRAY_HOLE_SHIFT) + +/** + * Maximum number of array holes in a fast access mode array + */ +#define ECMA_FAST_ARRAY_MAX_HOLE_COUNT (1 << 16) + +ecma_object_t *ecma_op_new_array_object (uint32_t length); + +ecma_object_t *ecma_op_new_array_object_from_length (ecma_length_t length); + +ecma_value_t ecma_op_new_array_object_from_buffer (const ecma_value_t *args_p, uint32_t length); + +ecma_value_t ecma_op_new_array_object_from_collection (ecma_collection_t *collection_p, bool unref_objects); + +bool ecma_op_object_is_fast_array (ecma_object_t *object_p); + +bool ecma_op_array_is_fast_array (ecma_extended_object_t *array_p); + +uint32_t ecma_fast_array_get_hole_count (ecma_object_t *obj_p); + +ecma_value_t *ecma_fast_array_extend (ecma_object_t *object_p, uint32_t new_length); + +bool ecma_fast_array_set_property (ecma_object_t *object_p, uint32_t index, ecma_value_t value); + +bool ecma_array_object_delete_property (ecma_object_t *object_p, ecma_string_t *property_name_p); + +uint32_t ecma_delete_fast_array_properties (ecma_object_t *object_p, uint32_t new_length); + +ecma_collection_t *ecma_fast_array_object_own_property_keys (ecma_object_t *object_p, jerry_property_filter_t filter); + +void ecma_fast_array_convert_to_normal (ecma_object_t *object_p); + +ecma_object_t *ecma_op_array_species_create (ecma_object_t *original_array_p, ecma_length_t length); + +ecma_value_t ecma_op_create_array_iterator (ecma_object_t *obj_p, ecma_iterator_kind_t kind); + +ecma_value_t ecma_op_array_object_set_length (ecma_object_t *object_p, ecma_value_t new_value, uint16_t flags); + +ecma_value_t ecma_op_array_object_define_own_property (ecma_object_t *object_p, + ecma_string_t *property_name_p, + const ecma_property_descriptor_t *property_desc_p); + +uint32_t ecma_array_get_length (ecma_object_t *array_p); + +ecma_value_t ecma_array_object_to_string (ecma_value_t this_arg); + +/** + * @} + * @} + */ + +#endif /* !ECMA_ARRAY_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arraybuffer-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arraybuffer-object.cpp new file mode 100644 index 0000000..f97db44 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arraybuffer-object.cpp @@ -0,0 +1,557 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-arraybuffer-object.h" + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-shared-arraybuffer-object.h" +#include "ecma-typedarray-object.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines + * @{ + */ + +/** + * Creating ArrayBuffer objects with a buffer after the arraybuffer header + * + * @return new ArrayBuffer object + */ +ecma_object_t * +ecma_arraybuffer_create_object (uint8_t type, /**< type of the arraybuffer */ + uint32_t length) /**< length of the arraybuffer */ +{ + ecma_builtin_id_t prototype_id; + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + JERRY_ASSERT (type == ECMA_OBJECT_CLASS_ARRAY_BUFFER || type == ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER); + + prototype_id = (type == ECMA_OBJECT_CLASS_ARRAY_BUFFER ? ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE + : ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE); +#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */ + JERRY_ASSERT (type == ECMA_OBJECT_CLASS_ARRAY_BUFFER); + + prototype_id = ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE; +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + + ecma_object_t *object_p = ecma_create_object (ecma_builtin_get (prototype_id), + sizeof (ecma_extended_object_t) + length, + ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = type; + ext_object_p->u.cls.u1.array_buffer_flags = ECMA_ARRAYBUFFER_ALLOCATED; + ext_object_p->u.cls.u3.length = length; + + memset ((uint8_t *) (ext_object_p + 1), 0, length); + return object_p; +} /* ecma_arraybuffer_create_object */ + +/** + * Creating ArrayBuffer objects with a pointer to its buffer + * + * @return new ArrayBuffer object + */ +ecma_object_t * +ecma_arraybuffer_create_object_with_buffer (uint8_t type, /**< type of the arraybuffer */ + uint32_t length) +{ + ecma_builtin_id_t prototype_id; + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + JERRY_ASSERT (type == ECMA_OBJECT_CLASS_ARRAY_BUFFER || type == ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER); + + prototype_id = (type == ECMA_OBJECT_CLASS_ARRAY_BUFFER ? ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE + : ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE); +#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */ + JERRY_ASSERT (type == ECMA_OBJECT_CLASS_ARRAY_BUFFER); + + prototype_id = ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE; +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + + ecma_object_t *object_p = + ecma_create_object (ecma_builtin_get (prototype_id), sizeof (ecma_arraybuffer_pointer_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_arraybuffer_pointer_t *arraybuffer_pointer_p = (ecma_arraybuffer_pointer_t *) object_p; + arraybuffer_pointer_p->extended_object.u.cls.type = type; + arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags = ECMA_ARRAYBUFFER_HAS_POINTER; + arraybuffer_pointer_p->extended_object.u.cls.u3.length = length; + + arraybuffer_pointer_p->buffer_p = NULL; + arraybuffer_pointer_p->arraybuffer_user_p = NULL; + + return object_p; +} /* ecma_arraybuffer_create_object_with_buffer */ + +/** + * Creating ArrayBuffer objects based on the array length + * + * @return new ArrayBuffer object + */ +ecma_object_t * +ecma_arraybuffer_new_object (uint32_t length) /**< length of the arraybuffer */ +{ + if (length > JERRY_CONTEXT (arraybuffer_compact_allocation_limit)) + { + return ecma_arraybuffer_create_object_with_buffer (ECMA_OBJECT_CLASS_ARRAY_BUFFER, length); + } + + return ecma_arraybuffer_create_object (ECMA_OBJECT_CLASS_ARRAY_BUFFER, length); +} /* ecma_arraybuffer_new_object */ + +/** + * Allocate a backing store for an array buffer. + * + * @return buffer pointer on success, + * NULL otherwise + */ +ecma_value_t +ecma_arraybuffer_allocate_buffer (ecma_object_t *arraybuffer_p) /**< ArrayBuffer object */ +{ + JERRY_ASSERT (!(ECMA_ARRAYBUFFER_GET_FLAGS (arraybuffer_p) & ECMA_ARRAYBUFFER_ALLOCATED)); + + ecma_extended_object_t *extended_object_p = (ecma_extended_object_t *) arraybuffer_p; + + if (ECMA_ARRAYBUFFER_GET_FLAGS (arraybuffer_p) & ECMA_ARRAYBUFFER_DETACHED) + { + extended_object_p->u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED; + return ECMA_VALUE_UNDEFINED; + } + + uint32_t arraybuffer_length = extended_object_p->u.cls.u3.length; + ecma_arraybuffer_pointer_t *arraybuffer_pointer_p = (ecma_arraybuffer_pointer_t *) arraybuffer_p; + jerry_arraybuffer_allocate_cb_t arraybuffer_allocate_callback = JERRY_CONTEXT (arraybuffer_allocate_callback); + uint8_t *buffer_p; + + if (arraybuffer_allocate_callback != NULL) + { + jerry_arraybuffer_type_t type = JERRY_ARRAYBUFFER_TYPE_ARRAYBUFFER; + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + if (extended_object_p->u.cls.type == ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER) + { + type = JERRY_ARRAYBUFFER_TYPE_SHARED_ARRAYBUFFER; + } +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + + buffer_p = arraybuffer_allocate_callback (type, + arraybuffer_length, + &arraybuffer_pointer_p->arraybuffer_user_p, + JERRY_CONTEXT (arraybuffer_allocate_callback_user_p)); + } + else + { + buffer_p = (uint8_t *) jmem_heap_alloc_block_null_on_error (arraybuffer_length); + } + + if (buffer_p == NULL) + { + return ecma_raise_range_error (ECMA_ERR_ALLOCATE_ARRAY_BUFFER); + } + + arraybuffer_pointer_p->buffer_p = buffer_p; + extended_object_p->u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED; + + memset (buffer_p, 0, arraybuffer_length); + return ECMA_VALUE_UNDEFINED; +} /* ecma_arraybuffer_allocate_buffer */ + +/** + * Allocate a backing store for an array buffer, throws an error if the allocation fails. + * + * @return ECMA_VALUE_UNDEFINED on success, + * ECMA_VALUE_ERROR otherwise + */ +ecma_value_t +ecma_arraybuffer_allocate_buffer_throw (ecma_object_t *arraybuffer_p) +{ + JERRY_ASSERT (!(ECMA_ARRAYBUFFER_GET_FLAGS (arraybuffer_p) & ECMA_ARRAYBUFFER_ALLOCATED)); + + return ecma_arraybuffer_allocate_buffer (arraybuffer_p); +} /* ecma_arraybuffer_allocate_buffer_throw */ + +/** + * Release the backing store allocated by an array buffer. + */ +void +ecma_arraybuffer_release_buffer (ecma_object_t *arraybuffer_p) /**< ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (arraybuffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (arraybuffer_p)); + + jerry_arraybuffer_free_cb_t free_callback = JERRY_CONTEXT (arraybuffer_free_callback); + ecma_arraybuffer_pointer_t *arraybuffer_pointer_p = (ecma_arraybuffer_pointer_t *) arraybuffer_p; + + if (arraybuffer_pointer_p->buffer_p == NULL) + { + return; + } + + uint32_t arraybuffer_length = arraybuffer_pointer_p->extended_object.u.cls.u3.length; + + if (free_callback == NULL) + { + jmem_heap_free_block (arraybuffer_pointer_p->buffer_p, arraybuffer_length); + return; + } + + jerry_arraybuffer_type_t type = JERRY_ARRAYBUFFER_TYPE_ARRAYBUFFER; + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + if (arraybuffer_pointer_p->extended_object.u.cls.type == ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER) + { + type = JERRY_ARRAYBUFFER_TYPE_SHARED_ARRAYBUFFER; + } +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + + free_callback (type, + (uint8_t*) arraybuffer_pointer_p->buffer_p, + arraybuffer_length, + arraybuffer_pointer_p->arraybuffer_user_p, + JERRY_CONTEXT (arraybuffer_allocate_callback_user_p)); +} /* ecma_arraybuffer_release_buffer */ + +/** + * ArrayBuffer object creation operation. + * + * See also: ES2015 24.1.1.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< list of arguments that + * are passed to String constructor */ + uint32_t arguments_list_len) /**< length of the arguments' list */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), + ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_number_t length_num = 0; + + if (arguments_list_len > 0) + { + if (ecma_is_value_number (arguments_list_p[0])) + { + length_num = ecma_get_number_from_value (arguments_list_p[0]); + } + else + { + ecma_value_t to_number_value = ecma_op_to_number (arguments_list_p[0], &length_num); + + if (ECMA_IS_VALUE_ERROR (to_number_value)) + { + ecma_deref_object (proto_p); + return to_number_value; + } + } + + if (ecma_number_is_nan (length_num)) + { + length_num = 0; + } + + const uint32_t maximum_size_in_byte = UINT32_MAX - sizeof (ecma_extended_object_t) - JMEM_ALIGNMENT + 1; + + if (length_num <= -1.0 || length_num > (ecma_number_t) maximum_size_in_byte + 0.5) + { + ecma_deref_object (proto_p); + return ecma_raise_range_error (ECMA_ERR_INVALID_ARRAYBUFFER_LENGTH); + } + } + + uint32_t length_uint32 = ecma_number_to_uint32 (length_num); + + ecma_object_t *array_buffer = ecma_arraybuffer_new_object (length_uint32); + ECMA_SET_NON_NULL_POINTER (array_buffer->u2.prototype_cp, proto_p); + ecma_deref_object (proto_p); + + return ecma_make_object_value (array_buffer); +} /* ecma_op_create_arraybuffer_object */ + +/** + * Helper function: check if the target is ArrayBuffer + * + * + * See also: ES2015 24.1.1.4 + * + * @return true - if value is an ArrayBuffer object + * false - otherwise + */ +bool +ecma_is_arraybuffer (ecma_value_t target) /**< the target value */ +{ + return (ecma_is_value_object (target) + && ecma_object_class_is (ecma_get_object_from_value (target), ECMA_OBJECT_CLASS_ARRAY_BUFFER)); +} /* ecma_is_arraybuffer */ + +/** + * Helper function: return the length of the buffer inside the arraybuffer object + * + * @return uint32_t, the length of the arraybuffer + */ +uint32_t JERRY_ATTR_PURE +ecma_arraybuffer_get_length (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (object_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + return ecma_arraybuffer_is_detached (object_p) ? 0 : ext_object_p->u.cls.u3.length; +} /* ecma_arraybuffer_get_length */ + +/** + * Helper function: return the pointer to the data buffer inside the arraybuffer object + * + * @return pointer to the data buffer + */ +uint8_t *JERRY_ATTR_PURE +ecma_arraybuffer_get_buffer (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (object_p)); + + if (!(ECMA_ARRAYBUFFER_GET_FLAGS (object_p) & ECMA_ARRAYBUFFER_HAS_POINTER)) + { + return (uint8_t *) object_p + sizeof (ecma_extended_object_t); + } + + ecma_arraybuffer_pointer_t *arraybuffer_pointer_p = (ecma_arraybuffer_pointer_t *) object_p; + return (uint8_t *) arraybuffer_pointer_p->buffer_p; +} /* ecma_arraybuffer_get_buffer */ + +/** + * Helper function: check if the target ArrayBuffer is detached + * + * @return true - if value is an detached ArrayBuffer object + * false - otherwise + */ +bool JERRY_ATTR_PURE +ecma_arraybuffer_is_detached (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (object_p)); + + return (ECMA_ARRAYBUFFER_GET_FLAGS (object_p) & ECMA_ARRAYBUFFER_DETACHED) != 0; +} /* ecma_arraybuffer_is_detached */ + +/** + * ArrayBuffer object detaching operation + * + * See also: ES2015 24.1.1.3 + * + * @return true - if detach operation is succeeded + * false - otherwise + */ +bool +ecma_arraybuffer_detach (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)); + + if (ECMA_ARRAYBUFFER_GET_FLAGS (object_p) & ECMA_ARRAYBUFFER_DETACHED) + { + return false; + } + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_DETACHED; + + if (!(ECMA_ARRAYBUFFER_GET_FLAGS (object_p) & ECMA_ARRAYBUFFER_ALLOCATED)) + { + return true; + } + + ext_object_p->u.cls.u1.array_buffer_flags &= (uint8_t) ~ECMA_ARRAYBUFFER_ALLOCATED; + + if (!(ECMA_ARRAYBUFFER_GET_FLAGS (object_p) & ECMA_ARRAYBUFFER_HAS_POINTER)) + { + return true; + } + + ecma_arraybuffer_release_buffer (object_p); + return true; +} /* ecma_arraybuffer_detach */ + +/** + * ArrayBuffer slice operation + * + * See also: + * ECMA-262 v11, 24.1.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_arraybuffer_slice (ecma_value_t this_arg, const ecma_value_t *argument_list_p, uint32_t arguments_number) +{ + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + /* 3-4. */ + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (object_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (object_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* 5. */ + uint32_t len = ecma_arraybuffer_get_length (object_p); + + uint32_t start = 0; + uint32_t end = len; + + if (arguments_number > 0) + { + /* 6-7. */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (argument_list_p[0], len, &start))) + { + return ECMA_VALUE_ERROR; + } + + if (arguments_number > 1 && !ecma_is_value_undefined (argument_list_p[1])) + { + /* 8-9. */ + if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (argument_list_p[1], len, &end))) + { + return ECMA_VALUE_ERROR; + } + } + } + + /* 10. */ + uint32_t new_len = (end >= start) ? (end - start) : 0; + + /* 11. */ + ecma_builtin_id_t buffer_builtin_id = ECMA_BUILTIN_ID_ARRAYBUFFER; + + ecma_value_t ctor = ecma_op_species_constructor (object_p, buffer_builtin_id); + + if (ECMA_IS_VALUE_ERROR (ctor)) + { + return ctor; + } + + /* 12. */ + ecma_object_t *ctor_obj_p = ecma_get_object_from_value (ctor); + ecma_value_t new_len_value = ecma_make_uint32_value (new_len); + + ecma_value_t new_arraybuffer = ecma_op_function_construct (ctor_obj_p, ctor_obj_p, &new_len_value, 1); + + ecma_deref_object (ctor_obj_p); + ecma_free_value (new_len_value); + + if (ECMA_IS_VALUE_ERROR (new_arraybuffer)) + { + return new_arraybuffer; + } + + ecma_object_t *new_arraybuffer_p = ecma_get_object_from_value (new_arraybuffer); + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + lit_utf8_byte_t *old_buf; + lit_utf8_byte_t *new_buf; + + /* 13. */ + if (!(ecma_object_class_is (new_arraybuffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (new_arraybuffer_p))) + { + ret_value = ecma_raise_type_error (ECMA_ERR_RETURN_VALUE_IS_NOT_AN_ARRAYBUFFER_OBJECT); + goto free_new_arraybuffer; + } + + /* 14-15. */ + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (new_arraybuffer_p)) + { + ret_value = ECMA_VALUE_ERROR; + goto free_new_arraybuffer; + } + + if (ecma_arraybuffer_is_detached (new_arraybuffer_p)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + goto free_new_arraybuffer; + } + + /* 16. */ + if (new_arraybuffer == this_arg) + { + ret_value = ecma_raise_type_error (ECMA_ERR_ARRAY_BUFFER_RETURNED_THIS_FROM_CONSTRUCTOR); + goto free_new_arraybuffer; + } + + /* 17. */ + if (ecma_arraybuffer_get_length (new_arraybuffer_p) < new_len) + { + ret_value = ecma_raise_type_error (ECMA_ERR_DERIVED_ARRAY_BUFFER_CTOR_BUFFER_TOO_SMALL); + goto free_new_arraybuffer; + } + + /* 19. */ + if (ecma_arraybuffer_is_detached (object_p)) + { + ret_value = ECMA_VALUE_ERROR; + goto free_new_arraybuffer; + } + + /* 20. */ + old_buf = ecma_arraybuffer_get_buffer (object_p); + + /* 21. */ + new_buf = ecma_arraybuffer_get_buffer (new_arraybuffer_p); + + /* 22. */ + memcpy (new_buf, old_buf + start, new_len); + +free_new_arraybuffer: + if (ret_value != ECMA_VALUE_EMPTY) + { + ecma_deref_object (new_arraybuffer_p); + } + else + { + /* 23. */ + ret_value = ecma_make_object_value (new_arraybuffer_p); + } + + return ret_value; +} /* ecma_builtin_arraybuffer_slice */ + +/** + * @} + * @} + */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arraybuffer-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arraybuffer-object.h new file mode 100644 index 0000000..6dc28b5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-arraybuffer-object.h @@ -0,0 +1,68 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ARRAYBUFFER_OBJECT_H +#define ECMA_ARRAYBUFFER_OBJECT_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines + * @{ + */ + +/** + * Get array buffer flags. + */ +#define ECMA_ARRAYBUFFER_GET_FLAGS(arraybuffer_p) \ + (((ecma_extended_object_t *) (arraybuffer_p))->u.cls.u1.array_buffer_flags) + +/** + * Check whether the backing store is allocated for an array buffer. + */ +#define ECMA_ARRAYBUFFER_LAZY_ALLOC(arraybuffer_p) \ + (JERRY_UNLIKELY (!(ECMA_ARRAYBUFFER_GET_FLAGS (arraybuffer_p) & ECMA_ARRAYBUFFER_ALLOCATED)) \ + && ecma_arraybuffer_allocate_buffer_throw (arraybuffer_p) == ECMA_VALUE_ERROR) + +ecma_value_t ecma_op_create_arraybuffer_object (const ecma_value_t *, uint32_t); + +/** + * Helper functions for arraybuffer. + */ +ecma_object_t *ecma_arraybuffer_create_object (uint8_t type, uint32_t length); +ecma_object_t *ecma_arraybuffer_create_object_with_buffer (uint8_t type, uint32_t length); +ecma_object_t *ecma_arraybuffer_new_object (uint32_t length); +ecma_value_t ecma_arraybuffer_allocate_buffer (ecma_object_t *arraybuffer_p); +ecma_value_t ecma_arraybuffer_allocate_buffer_throw (ecma_object_t *arraybuffer_p); +void ecma_arraybuffer_release_buffer (ecma_object_t *arraybuffer_p); +uint8_t *JERRY_ATTR_PURE ecma_arraybuffer_get_buffer (ecma_object_t *obj_p); +uint32_t JERRY_ATTR_PURE ecma_arraybuffer_get_length (ecma_object_t *obj_p); +bool JERRY_ATTR_PURE ecma_arraybuffer_is_detached (ecma_object_t *obj_p); +bool ecma_arraybuffer_detach (ecma_object_t *obj_p); +bool ecma_is_arraybuffer (ecma_value_t val); +ecma_value_t +ecma_builtin_arraybuffer_slice (ecma_value_t this_arg, const ecma_value_t *argument_list_p, uint32_t arguments_number); + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#endif /* !ECMA_ARRAYBUFFER_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-async-generator-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-async-generator-object.cpp new file mode 100644 index 0000000..fa4e0b5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-async-generator-object.cpp @@ -0,0 +1,523 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-async-generator-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-errors.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" + +#include "jcontext.h" +#include "opcodes.h" +#include "vm-stack.h" +#include "vm.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaasyncgeneratorobject ECMA AsyncGenerator object related routines + * @{ + */ + +/** + * Enqueue a task into the command queue of an async generator + * + * @return ecma Promise value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_async_generator_enqueue (vm_executable_object_t *async_generator_object_p, /**< async generator */ + ecma_async_generator_operation_type_t operation, /**< operation */ + ecma_value_t value) /**< value argument of operation */ +{ + ecma_async_generator_task_t *task_p = (ecma_async_generator_task_t *) jmem_heap_alloc_block (sizeof (ecma_async_generator_task_t)); + + ECMA_SET_INTERNAL_VALUE_ANY_POINTER (task_p->next, NULL); + task_p->operation_value = ecma_copy_value_if_not_object (value); + task_p->operation_type = (uint8_t) operation; + + ecma_value_t result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL); + task_p->promise = result; + + ecma_value_t head = async_generator_object_p->extended_object.u.cls.u3.head; + + if (ECMA_IS_INTERNAL_VALUE_NULL (head)) + { + ECMA_SET_INTERNAL_VALUE_POINTER (async_generator_object_p->extended_object.u.cls.u3.head, task_p); + + if (async_generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_ASYNC_GENERATOR_CALLED) + { + ecma_value_t executable_object = ecma_make_object_value ((ecma_object_t *) async_generator_object_p); + ecma_enqueue_promise_async_generator_job (executable_object); + return result; + } + + async_generator_object_p->extended_object.u.cls.u2.executable_obj_flags |= ECMA_ASYNC_GENERATOR_CALLED; + ecma_async_generator_run (async_generator_object_p); + return result; + } + + /* Append the new task at the end. */ + ecma_async_generator_task_t *prev_task_p; + prev_task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, head); + + while (!ECMA_IS_INTERNAL_VALUE_NULL (prev_task_p->next)) + { + prev_task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, prev_task_p->next); + } + + ECMA_SET_INTERNAL_VALUE_POINTER (prev_task_p->next, task_p); + return result; +} /* ecma_async_generator_enqueue */ + +/** + * Call a function and await its return value + * + * @return ECMA_VALUE_UNDEFINED on success, error otherwise + */ +static ecma_value_t +ecma_async_yield_call (ecma_value_t function, /**< function (takes reference) */ + vm_executable_object_t *async_generator_object_p, /**< async generator */ + ecma_value_t argument) /**< argument passed to the function */ +{ + ecma_value_t iterator = async_generator_object_p->iterator; + ecma_value_t result; + + if (argument == ECMA_VALUE_EMPTY) + { + result = ecma_op_function_validated_call (function, iterator, NULL, 0); + } + else + { + result = ecma_op_function_validated_call (function, iterator, &argument, 1); + } + + ecma_free_value (function); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + return ecma_promise_async_await ((ecma_extended_object_t *) async_generator_object_p, result); +} /* ecma_async_yield_call */ + +/** + * Perform an exception throw and call the appropriate handler + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_async_yield_throw (vm_executable_object_t *async_generator_object_p, /**< async generator */ + ecma_value_t value) /**< thrown value */ +{ + ecma_object_t *obj_p = ecma_get_object_from_value (async_generator_object_p->iterator); + ecma_value_t result = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_THROW); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (result == ECMA_VALUE_UNDEFINED) + { + result = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_RETURN); + + if (result == ECMA_VALUE_UNDEFINED) + { + return ecma_raise_type_error (ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE); + } + + result = ecma_async_yield_call (result, async_generator_object_p, ECMA_VALUE_EMPTY); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ECMA_AWAIT_CHANGE_STATE (async_generator_object_p, YIELD_OPERATION, YIELD_CLOSE); + return ECMA_VALUE_UNDEFINED; + } + + result = ecma_async_yield_call (result, async_generator_object_p, value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ECMA_AWAIT_CHANGE_STATE (async_generator_object_p, YIELD_OPERATION, YIELD_NEXT); + return ECMA_VALUE_UNDEFINED; +} /* ecma_async_yield_throw */ + +/** + * Execute the next task in the command queue of the async generator + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_async_generator_run (vm_executable_object_t *async_generator_object_p) /**< async generator */ +{ + JERRY_ASSERT (async_generator_object_p->extended_object.u.cls.type == ECMA_OBJECT_CLASS_ASYNC_GENERATOR); + JERRY_ASSERT (!ECMA_IS_INTERNAL_VALUE_NULL (async_generator_object_p->extended_object.u.cls.u3.head)); + + ecma_value_t head = async_generator_object_p->extended_object.u.cls.u3.head; + ecma_async_generator_task_t *task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, head); + ecma_value_t result; + + if (async_generator_object_p->extended_object.u.cls.u2.executable_obj_flags + & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD) + { + switch (task_p->operation_type) + { + case ECMA_ASYNC_GENERATOR_DO_NEXT: + { + result = ecma_op_iterator_next (async_generator_object_p->iterator, + async_generator_object_p->frame_ctx.stack_top_p[-1], + task_p->operation_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + break; + } + + result = ecma_promise_async_await ((ecma_extended_object_t *) async_generator_object_p, result); + + if (ECMA_IS_VALUE_ERROR (result)) + { + break; + } + + ECMA_AWAIT_CHANGE_STATE (async_generator_object_p, YIELD_OPERATION, YIELD_NEXT); + break; + } + case ECMA_ASYNC_GENERATOR_DO_THROW: + { + result = ecma_async_yield_throw (async_generator_object_p, task_p->operation_value); + break; + } + default: + { + JERRY_ASSERT (task_p->operation_type == ECMA_ASYNC_GENERATOR_DO_RETURN); + + result = ecma_copy_value (task_p->operation_value); + result = ecma_promise_async_await ((ecma_extended_object_t *) async_generator_object_p, result); + + if (ECMA_IS_VALUE_ERROR (result)) + { + break; + } + + ECMA_AWAIT_CHANGE_STATE (async_generator_object_p, YIELD_OPERATION, YIELD_RETURN); + break; + } + } + + ecma_free_value_if_not_object (task_p->operation_value); + task_p->operation_value = ECMA_VALUE_UNDEFINED; + + if (result == ECMA_VALUE_UNDEFINED) + { + return ECMA_VALUE_UNDEFINED; + } + + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result)); + + async_generator_object_p->extended_object.u.cls.u2.executable_obj_flags &= ECMA_AWAIT_CLEAR_MASK; + async_generator_object_p->iterator = ECMA_VALUE_UNDEFINED; + async_generator_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_throw; + + JERRY_ASSERT (async_generator_object_p->frame_ctx.stack_top_p[-1] == ECMA_VALUE_UNDEFINED + || ecma_is_value_object (async_generator_object_p->frame_ctx.stack_top_p[-1])); + async_generator_object_p->frame_ctx.stack_top_p--; + + result = jcontext_take_exception (); + } + else + { + if (task_p->operation_type == ECMA_ASYNC_GENERATOR_DO_RETURN) + { + async_generator_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_return; + } + else if (task_p->operation_type == ECMA_ASYNC_GENERATOR_DO_THROW) + { + async_generator_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_throw; + } + + result = task_p->operation_value; + ecma_ref_if_object (result); + task_p->operation_value = ECMA_VALUE_UNDEFINED; + } + + result = opfunc_resume_executable_object (async_generator_object_p, result); + + if (async_generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED) + { + JERRY_ASSERT (head == async_generator_object_p->extended_object.u.cls.u3.head); + ecma_async_generator_finalize (async_generator_object_p, result); + result = ECMA_VALUE_UNDEFINED; + } + + return result; +} /* ecma_async_generator_run */ + +/** + * Finalize the promises of an executable generator + */ +void +ecma_async_generator_finalize (vm_executable_object_t *async_generator_object_p, /**< async generator */ + ecma_value_t value) /**< final value (takes reference) */ +{ + ecma_value_t next = async_generator_object_p->extended_object.u.cls.u3.head; + ecma_async_generator_task_t *task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, next); + + if (ECMA_IS_VALUE_ERROR (value)) + { + value = jcontext_take_exception (); + ecma_reject_promise (task_p->promise, value); + } + else + { + ecma_value_t result = ecma_create_iter_result_object (value, ECMA_VALUE_TRUE); + ecma_fulfill_promise (task_p->promise, result); + ecma_free_value (result); + } + + ecma_free_value (value); + + next = task_p->next; + async_generator_object_p->extended_object.u.cls.u3.head = next; + jmem_heap_free_block (task_p, sizeof (ecma_async_generator_task_t)); + + while (!ECMA_IS_INTERNAL_VALUE_NULL (next)) + { + task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, next); + + if (task_p->operation_type != ECMA_ASYNC_GENERATOR_DO_THROW) + { + value = ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + ecma_fulfill_promise (task_p->promise, value); + ecma_free_value (value); + } + else + { + ecma_reject_promise (task_p->promise, task_p->operation_value); + } + + ecma_free_value_if_not_object (task_p->operation_value); + + next = task_p->next; + async_generator_object_p->extended_object.u.cls.u3.head = next; + jmem_heap_free_block (task_p, sizeof (ecma_async_generator_task_t)); + } +} /* ecma_async_generator_finalize */ + +/** + * Continue after an await operation is completed. + * + * @return an updated value for the value argument + */ +ecma_value_t +ecma_await_continue (vm_executable_object_t *executable_object_p, /**< executable object */ + ecma_value_t value) /**< job value (takes reference) */ +{ + ecma_await_states_t state = (ecma_await_states_t) ECMA_AWAIT_GET_STATE (executable_object_p); + + switch (state) + { + case ECMA_AWAIT_YIELD_NEXT: + case ECMA_AWAIT_YIELD_NEXT_RETURN: + { + if (!ecma_is_value_object (value)) + { + ecma_free_value (value); + return ecma_raise_type_error (ECMA_ERR_VALUE_RECEIVED_BY_YIELD_IS_NOT_OBJECT); + } + + ecma_object_t *result_obj_p = ecma_get_object_from_value (value); + ecma_value_t result = ecma_op_object_get_by_magic_id (result_obj_p, LIT_MAGIC_STRING_DONE); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (result_obj_p); + return result; + } + + bool done = ecma_op_to_boolean (result); + ecma_free_value (result); + result = ecma_op_object_get_by_magic_id (result_obj_p, LIT_MAGIC_STRING_VALUE); + ecma_deref_object (result_obj_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (!done) + { + ECMA_AWAIT_SET_STATE (executable_object_p, YIELD_NEXT_VALUE); + return ecma_promise_async_await ((ecma_extended_object_t *) executable_object_p, result); + } + + ECMA_EXECUTABLE_OBJECT_RESUME_EXEC (executable_object_p); + + if (state == ECMA_AWAIT_YIELD_NEXT_RETURN) + { + executable_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_return; + } + return result; + } + case ECMA_AWAIT_YIELD_RETURN: + { + ecma_object_t *obj_p = ecma_get_object_from_value (executable_object_p->iterator); + ecma_value_t result = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_RETURN); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_free_value (value); + return result; + } + + if (result == ECMA_VALUE_UNDEFINED) + { + ECMA_EXECUTABLE_OBJECT_RESUME_EXEC (executable_object_p); + executable_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_return; + return value; + } + + result = ecma_async_yield_call (result, executable_object_p, value); + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + JERRY_ASSERT (result == ECMA_VALUE_UNDEFINED); + ECMA_AWAIT_CHANGE_STATE (executable_object_p, YIELD_RETURN, YIELD_NEXT_RETURN); + return ECMA_VALUE_UNDEFINED; + } + case ECMA_AWAIT_YIELD_NEXT_VALUE: + { + ECMA_AWAIT_CHANGE_STATE (executable_object_p, YIELD_NEXT_VALUE, YIELD_OPERATION); + opfunc_async_generator_yield ((ecma_extended_object_t *) executable_object_p, value); + return ECMA_VALUE_UNDEFINED; + } + case ECMA_AWAIT_YIELD_OPERATION: + { + /* Currently this is always a throw exception case. */ + ecma_value_t result = ecma_async_yield_throw (executable_object_p, value); + ecma_free_value (value); + return result; + } + case ECMA_AWAIT_YIELD_CLOSE: + { + ecma_error_msg_t msg = (ecma_is_value_object (value) ? ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE + : ECMA_ERR_VALUE_RECEIVED_BY_YIELD_IS_NOT_OBJECT); + + ecma_free_value (value); + return ecma_raise_type_error (msg); + } + case ECMA_AWAIT_FOR_CLOSE: + { + bool is_value_object = ecma_is_value_object (value); + ecma_free_value (value); + ECMA_EXECUTABLE_OBJECT_RESUME_EXEC (executable_object_p); + + if (!is_value_object + && VM_GET_CONTEXT_TYPE (executable_object_p->frame_ctx.stack_top_p[-1]) != VM_CONTEXT_FINALLY_THROW) + { + return ecma_raise_type_error (ECMA_ERR_ITERATOR_RETURN_RESULT_IS_NOT_OBJECT); + } + return ECMA_VALUE_EMPTY; + } + default: + { + JERRY_ASSERT (state == ECMA_AWAIT_FOR_NEXT); + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (executable_object_p->frame_ctx.stack_top_p[-1]) == VM_CONTEXT_FOR_AWAIT_OF); + JERRY_ASSERT (!(executable_object_p->frame_ctx.stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR)); + + if (!ecma_is_value_object (value)) + { + ecma_free_value (value); + return ecma_raise_type_error (ECMA_ERR_VALUE_RECEIVED_BY_FOR_ASYNC_OF_IS_NOT_OBJECT); + } + + ecma_object_t *result_obj_p = ecma_get_object_from_value (value); + ecma_value_t result = ecma_op_object_get_by_magic_id (result_obj_p, LIT_MAGIC_STRING_DONE); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (result_obj_p); + return result; + } + + bool done = ecma_op_to_boolean (result); + ecma_free_value (result); + + ecma_value_t *stack_top_p = executable_object_p->frame_ctx.stack_top_p; + JERRY_ASSERT (stack_top_p[-2] == ECMA_VALUE_UNDEFINED); + JERRY_ASSERT (ecma_is_value_object (stack_top_p[-3])); + JERRY_ASSERT (stack_top_p[-4] == ECMA_VALUE_UNDEFINED || ecma_is_value_object (stack_top_p[-4])); + + if (!done) + { + result = ecma_op_object_get_by_magic_id (result_obj_p, LIT_MAGIC_STRING_VALUE); + ecma_deref_object (result_obj_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + /* It seems browsers call Await(result) here, although the standard does not + * requests to do so. The following code might follow browsers in the future. */ + ecma_deref_if_object (result); + stack_top_p[-1] |= VM_CONTEXT_CLOSE_ITERATOR; + stack_top_p[-2] = result; + ECMA_EXECUTABLE_OBJECT_RESUME_EXEC (executable_object_p); + return ECMA_VALUE_EMPTY; + } + + ecma_deref_object (result_obj_p); + + /* This code jumps to the end regardless of the byte code which triggered this await. */ + uint32_t context_end = VM_GET_CONTEXT_END (stack_top_p[-1]); + executable_object_p->frame_ctx.byte_code_p = executable_object_p->frame_ctx.byte_code_start_p + context_end; + + VM_MINUS_EQUAL_U16 (executable_object_p->frame_ctx.context_depth, PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION); + stack_top_p -= PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION; + executable_object_p->frame_ctx.stack_top_p = stack_top_p; + + ECMA_EXECUTABLE_OBJECT_RESUME_EXEC (executable_object_p); + return ECMA_VALUE_EMPTY; + } + } +} /* ecma_await_continue */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-async-generator-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-async-generator-object.h new file mode 100644 index 0000000..bcd58e0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-async-generator-object.h @@ -0,0 +1,88 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ASYNC_GENERATOR_OBJECT_H +#define ECMA_ASYNC_GENERATOR_OBJECT_H + +#include "ecma-globals.h" + +#include "vm-defines.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaasyncgeneratorobject ECMA AsyncGenerator object related routines + * @{ + */ + +/** + * AsyncGenerator command types. + */ +typedef enum +{ + ECMA_ASYNC_GENERATOR_DO_NEXT, /**< async generator next operation */ + ECMA_ASYNC_GENERATOR_DO_THROW, /**< async generator throw operation */ + ECMA_ASYNC_GENERATOR_DO_RETURN, /**< async generator return operation */ +} ecma_async_generator_operation_type_t; + +/** + * Get the state of an async yield iterator. + */ +#define ECMA_AWAIT_GET_STATE(async_generator_object_p) \ + ((async_generator_object_p)->extended_object.u.cls.u2.executable_obj_flags >> ECMA_AWAIT_STATE_SHIFT) + +/** + * Set the state of an async yield iterator. + */ +#define ECMA_AWAIT_SET_STATE(async_generator_object_p, to) \ + do \ + { \ + uint16_t extra_info = (async_generator_object_p)->extended_object.u.cls.u2.executable_obj_flags; \ + extra_info &= ((1 << ECMA_AWAIT_STATE_SHIFT) - 1); \ + extra_info |= (ECMA_AWAIT_##to) << ECMA_AWAIT_STATE_SHIFT; \ + (async_generator_object_p)->extended_object.u.cls.u2.executable_obj_flags = extra_info; \ + } while (false) + +/** + * Mask for clearing all ASYNC_AWAIT status bits + */ +#define ECMA_AWAIT_CLEAR_MASK (((1 << ECMA_AWAIT_STATE_SHIFT) - 1) - ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD) + +/** + * Helper macro for ECMA_AWAIT_CHANGE_STATE. + */ +#define ECMA_AWAIT_CS_HELPER(from, to) (((ECMA_AWAIT_##from) ^ (ECMA_AWAIT_##to)) << ECMA_AWAIT_STATE_SHIFT) + +/** + * Change the state of an async yield iterator. + */ +#define ECMA_AWAIT_CHANGE_STATE(async_generator_object_p, from, to) \ + ((async_generator_object_p)->extended_object.u.cls.u2.executable_obj_flags ^= ECMA_AWAIT_CS_HELPER (from, to)) + +ecma_value_t ecma_async_generator_enqueue (vm_executable_object_t *async_generator_object_p, + ecma_async_generator_operation_type_t operation, + ecma_value_t value); + +ecma_value_t ecma_async_generator_run (vm_executable_object_t *async_generator_object_p); +void ecma_async_generator_finalize (vm_executable_object_t *async_generator_object_p, ecma_value_t value); + +ecma_value_t ecma_await_continue (vm_executable_object_t *async_generator_object_p, ecma_value_t value); + +/** + * @} + * @} + */ + +#endif /* !ECMA_ASYNC_GENERATOR_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-atomics-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-atomics-object.cpp new file mode 100644 index 0000000..c42ad87 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-atomics-object.cpp @@ -0,0 +1,263 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-atomics-object.h" + +#include "ecma-arraybuffer-object.h" +#include "ecma-bigint.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-shared-arraybuffer-object.h" +#include "ecma-typedarray-object.h" + +#include "jcontext.h" +#include "jmem.h" + +#if JERRY_BUILTIN_ATOMICS + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaatomicsobject ECMA builtin Atomics helper functions + * @{ + */ + +/** + * Atomics validate Shared integer typedArray + * + * See also: ES11 24.4.1.1 + * + * @return ecma value + */ +ecma_value_t +ecma_validate_shared_integer_typedarray (ecma_value_t typedarray, /**< typedArray argument */ + bool waitable) /**< waitable argument */ +{ + /* 2. */ + if (!ecma_is_typedarray (typedarray)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_TYPED_ARRAY); + } + + /* 3-4. */ + ecma_object_t *typedarray_p = ecma_get_object_from_value (typedarray); + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (typedarray_p); + + /* 5-6. */ + if (waitable) + { + if (!(target_info.id == ECMA_BIGINT64_ARRAY || target_info.id == ECMA_INT32_ARRAY)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_NOT_SUPPORTED); + } + } + else + { + if (target_info.id == ECMA_UINT8_CLAMPED_ARRAY || target_info.id == ECMA_FLOAT32_ARRAY + || target_info.id == ECMA_FLOAT64_ARRAY) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_NOT_SUPPORTED); + } + } + + /* 7. */ + JERRY_ASSERT (target_info.array_buffer_p != NULL); + + /* 8-10. */ + ecma_object_t *buffer = ecma_typedarray_get_arraybuffer (typedarray_p); + + if (!ecma_object_class_is (buffer, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_NOT_SHARED_ARRAY_BUFFER); + } + + return ecma_make_object_value (buffer); +} /* ecma_validate_shared_integer_typedarray */ + +/** + * Atomics validate Atomic Access + * + * See also: ES11 24.4.1.2 + * + * @return ecma value + */ +ecma_value_t +ecma_validate_atomic_access (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t request_index) /**< request_index argument */ +{ + /* 1. */ + JERRY_ASSERT (ecma_is_value_object (typedarray) + && ecma_typedarray_get_arraybuffer (ecma_get_object_from_value (typedarray)) != NULL); + + ecma_object_t *typedarray_p = ecma_get_object_from_value (typedarray); + + /* 2. */ + ecma_number_t access_index; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_index (request_index, &access_index))) + { + return ECMA_VALUE_ERROR; + } + + /* 3. */ + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (typedarray_p); + + /* 4. */ + JERRY_ASSERT (access_index >= 0); + + /* 5-6. */ + if (JERRY_UNLIKELY (access_index >= target_info.length)) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_LENGTH); + } + + return ecma_make_number_value (access_index); +} /* ecma_validate_atomic_access */ + +/** + * Atomics read, modify, write + * + * See also: ES11 24.4.1.11 + * + * @return ecma value + */ +ecma_value_t +ecma_atomic_read_modify_write (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t index, /**< index argument */ + ecma_value_t value, /**< value argument */ + ecma_atomics_op_t op) /**< operation argument */ +{ + /* 1. */ + ecma_value_t buffer = ecma_validate_shared_integer_typedarray (typedarray, false); + + if (ECMA_IS_VALUE_ERROR (buffer)) + { + return buffer; + } + + /* 2. */ + ecma_value_t idx = ecma_validate_atomic_access (typedarray, index); + + if (ECMA_IS_VALUE_ERROR (idx)) + { + return idx; + } + + /* 3. */ + ecma_object_t *typedarray_p = ecma_get_object_from_value (typedarray); + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (typedarray_p); + + /* 4-5. */ + ecma_value_t val = ECMA_VALUE_ERROR; + ecma_number_t tmp; + if (target_info.id == ECMA_BIGINT64_ARRAY || target_info.id == ECMA_BIGUINT64_ARRAY) + { + val = ecma_bigint_to_bigint (value, true); + } + else if (!ECMA_IS_VALUE_ERROR (ecma_op_to_integer (value, &tmp))) + { + val = ecma_make_number_value (tmp); + } + + if (ECMA_IS_VALUE_ERROR (val)) + { + return val; + } + + /* 6. */ + uint8_t element_size = target_info.element_size; + + /* 7. */ + ecma_typedarray_type_t element_type = target_info.id; + + /* 8. */ + uint32_t offset = target_info.offset; + + /* 9. */ + uint32_t indexed_position = ecma_number_to_uint32 (idx) * element_size + offset; + + ecma_free_value (idx); + + JERRY_UNUSED (indexed_position); + JERRY_UNUSED (element_type); + JERRY_UNUSED (val); + JERRY_UNUSED (buffer); + JERRY_UNUSED (op); + + ecma_free_value (val); + + /* 10. */ + return ecma_make_uint32_value (0); +} /* ecma_atomic_read_modify_write */ + +/** + * Atomics load + * + * See also: ES11 24.4.1.12 + * + * @return ecma value + */ +ecma_value_t +ecma_atomic_load (ecma_value_t typedarray, /**< typedArray argument */ + ecma_value_t index) /**< index argument */ +{ + ecma_value_t buffer = ecma_validate_shared_integer_typedarray (typedarray, false); + + if (ECMA_IS_VALUE_ERROR (buffer)) + { + return buffer; + } + + /* 2. */ + ecma_value_t idx = ecma_validate_atomic_access (typedarray, index); + + if (ECMA_IS_VALUE_ERROR (idx)) + { + return idx; + } + + /* 3. */ + ecma_object_t *typedarray_p = ecma_get_object_from_value (typedarray); + ecma_typedarray_info_t target_info = ecma_typedarray_get_info (typedarray_p); + + /* 4. */ + uint8_t element_size = target_info.element_size; + + /* 5. */ + ecma_typedarray_type_t element_type = target_info.id; + + /* 6. */ + uint32_t offset = target_info.offset; + + /* 7. */ + uint32_t indexed_position = ecma_number_to_uint32 (idx) * element_size + offset; + + JERRY_UNUSED (indexed_position); + JERRY_UNUSED (element_type); + JERRY_UNUSED (buffer); + + /* 8. */ + return ecma_make_uint32_value (0); +} /* ecma_atomic_load */ + +/** + * @} + * @} + */ +#endif /* JERRY_BUILTIN_ATOMICS */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-atomics-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-atomics-object.h new file mode 100644 index 0000000..d73ae99 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-atomics-object.h @@ -0,0 +1,56 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ATOMICS_OBJECT_H +#define ECMA_ATOMICS_OBJECT_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_ATOMICS + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaatomicsobject ECMA builtin Atomics helper functions + * @{ + */ + +/** + * Atomics flags. + */ +typedef enum +{ + ECMA_ATOMICS_ADD, /**< Atomics add operation */ + ECMA_ATOMICS_SUBTRACT, /**< Atomics subtract operation */ + ECMA_ATOMICS_AND, /**< Atomics and operation */ + ECMA_ATOMICS_OR, /**< Atomics or operation */ + ECMA_ATOMICS_XOR, /**< Atomics xor operation */ + ECMA_ATOMICS_EXCHANGE, /**< Atomics exchange operation */ + ECMA_ATOMICS_COMPARE_EXCHANGE /**< Atomics compare exchange operation */ +} ecma_atomics_op_t; + +ecma_value_t ecma_validate_shared_integer_typedarray (ecma_value_t typedarray, bool waitable); +ecma_value_t ecma_validate_atomic_access (ecma_value_t typedarray, ecma_value_t request_index); +ecma_value_t +ecma_atomic_read_modify_write (ecma_value_t typedarray, ecma_value_t index, ecma_value_t value, ecma_atomics_op_t op); +ecma_value_t ecma_atomic_load (ecma_value_t typedarray, ecma_value_t index); +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_ATOMICS */ + +#endif /* ECMA_ATOMICS_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-big-uint.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-big-uint.cpp new file mode 100644 index 0000000..70d63c7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-big-uint.cpp @@ -0,0 +1,1775 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-big-uint.h" + +#include "ecma-helpers.h" + +#include "jmem.h" +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_BIGINT + +JERRY_STATIC_ASSERT ((sizeof (ecma_bigint_two_digits_t) == 2 * sizeof (ecma_bigint_digit_t)), + ecma_big_int_two_digits_must_be_twice_as_long_as_ecma_big_int_digit); + +JERRY_STATIC_ASSERT (((1 << (int)ECMA_BIGINT_DIGIT_SHIFT) == (8 * sizeof (ecma_bigint_digit_t))), + ecma_bigint_digit_shift_is_incorrect); + +JERRY_STATIC_ASSERT ((((int)ECMA_BIG_UINT_BITWISE_DECREASE_LEFT << 1) == (int)ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT), + ecma_big_uint_bitwise_left_and_right_sub_option_bits_must_follow_each_other); + +/** + * Create a new BigInt value + * + * @return new BigInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_bigint_create (uint32_t size) /**< size of the new BigInt value */ +{ + JERRY_ASSERT (size > 0); + JERRY_ASSERT ((size % sizeof (ecma_bigint_digit_t)) == 0); + + if (JERRY_UNLIKELY (size > ECMA_BIGINT_MAX_SIZE)) + { + return NULL; + } + + ecma_extended_primitive_t *value_p; + + size_t mem_size = ECMA_BIGINT_GET_BYTE_SIZE (size) + sizeof (ecma_extended_primitive_t); + value_p = (ecma_extended_primitive_t *) jmem_heap_alloc_block_null_on_error (mem_size); + + if (JERRY_UNLIKELY (value_p == NULL)) + { + return NULL; + } + + value_p->refs_and_type = ECMA_EXTENDED_PRIMITIVE_REF_ONE | ECMA_TYPE_BIGINT; + value_p->u.bigint_sign_and_size = size; + return value_p; +} /* ecma_bigint_create */ + +/** + * Extend a BigUInt value with a new data prefix value + * + * @return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_extend (ecma_extended_primitive_t *value_p, /**< BigUInt value */ + ecma_bigint_digit_t digit) /**< new digit */ +{ + uint32_t old_size = ECMA_BIGINT_GET_SIZE (value_p); + + if (ECMA_BIGINT_SIZE_IS_ODD (old_size)) + { + value_p->u.bigint_sign_and_size += (uint32_t) sizeof (ecma_bigint_digit_t); + *ECMA_BIGINT_GET_DIGITS (value_p, old_size) = digit; + return value_p; + } + + ecma_extended_primitive_t *result_p = ecma_bigint_create (old_size + (uint32_t) sizeof (ecma_bigint_digit_t)); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + ecma_deref_bigint (value_p); + return NULL; + } + + memcpy (result_p + 1, value_p + 1, old_size); + ecma_deref_bigint (value_p); + + *ECMA_BIGINT_GET_DIGITS (result_p, old_size) = digit; + return result_p; +} /* ecma_big_uint_extend */ + +/** + * Count the number of leading zero bits of a digit + * + * return number of leading zero bits + */ +ecma_bigint_digit_t +ecma_big_uint_count_leading_zero (ecma_bigint_digit_t digit) /**< digit value */ +{ + ecma_bigint_digit_t shift = 4 * sizeof (ecma_bigint_digit_t); + ecma_bigint_digit_t result = 8 * sizeof (ecma_bigint_digit_t); + + do + { + ecma_bigint_digit_t value = digit >> shift; + if (value > 0) + { + digit = value; + result -= shift; + } + shift >>= 1; + } while (shift > 0); + + return result - digit; +} /* ecma_big_uint_count_leading_zero */ + +/** + * Helper function which discards the leading zero digits of a BigUInt value + * + * @return new BigUInt value, NULL on error + */ +static ecma_extended_primitive_t * +ecma_big_uint_normalize_result (ecma_extended_primitive_t *value_p, /**< BigUInt value */ + ecma_bigint_digit_t *last_digit_p) /**< points to the end of BigUInt */ +{ + JERRY_ASSERT (last_digit_p[-1] == 0); + + ecma_bigint_digit_t *first_digit_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + + /* The following code is tricky. The value stored in first_digit_p[-1] is the size + * of the BigUInt value, and it cannot be zero. Hence the loop below will terminate. */ + JERRY_ASSERT (first_digit_p[-1] != 0); + + do + { + --last_digit_p; + } while (last_digit_p[-1] == 0); + + JERRY_ASSERT (last_digit_p >= first_digit_p); + + if (first_digit_p == last_digit_p) + { + ecma_deref_bigint (value_p); + return ECMA_BIGINT_POINTER_TO_ZERO; + } + + uint32_t new_size = (uint32_t) ((uint8_t *) last_digit_p - (uint8_t *) first_digit_p); + + if (ECMA_BIGINT_SIZE_IS_ODD (new_size) + && ((new_size + sizeof (ecma_bigint_digit_t)) == ECMA_BIGINT_GET_SIZE (value_p))) + { + value_p->u.bigint_sign_and_size -= (uint32_t) sizeof (ecma_bigint_digit_t); + return value_p; + } + + ecma_extended_primitive_t *result_p = ecma_bigint_create (new_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + ecma_deref_bigint (value_p); + return NULL; + } + + memcpy (ECMA_BIGINT_GET_DIGITS (result_p, 0), ECMA_BIGINT_GET_DIGITS (value_p, 0), new_size); + ecma_deref_bigint (value_p); + + return result_p; +} /* ecma_big_uint_normalize_result */ + +/** + * Helper function which increases the result by 1 and extends or shrinks the BigUInt when necessary + * + * @return new BigUInt value, NULL on error + */ +static ecma_extended_primitive_t * +ecma_big_uint_increase_result (ecma_extended_primitive_t *value_p) /**< BigUInt value */ +{ + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (size > 0); + + ecma_bigint_digit_t *first_digit_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + ecma_bigint_digit_t *last_digit_p = ECMA_BIGINT_GET_DIGITS (value_p, size); + + while (*first_digit_p == ~((ecma_bigint_digit_t) 0)) + { + *first_digit_p++ = 0; + + if (first_digit_p == last_digit_p) + { + return ecma_big_uint_extend (value_p, 1); + } + } + + (*first_digit_p)++; + + if (last_digit_p[-1] != 0) + { + return value_p; + } + + return ecma_big_uint_normalize_result (value_p, last_digit_p); +} /* ecma_big_uint_increase_result */ + +/** + * Compare two BigUInt numbers + * + * return -1, if left value < right value, 0 if they are equal, and 1 otherwise + */ +int +ecma_big_uint_compare (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + ecma_extended_primitive_t *right_value_p) /**< right BigUInt value */ +{ + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + uint32_t right_size = ECMA_BIGINT_GET_SIZE (right_value_p); + + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + JERRY_ASSERT (right_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (right_value_p, right_size) != 0); + + if (left_size > right_size) + { + return 1; + } + + if (left_size < right_size) + { + return -1; + } + + ecma_bigint_digit_t *start_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, left_size); + ecma_bigint_digit_t *right_p = ECMA_BIGINT_GET_DIGITS (right_value_p, left_size); + + do + { + ecma_bigint_digit_t left_value = *(--left_p); + ecma_bigint_digit_t right_value = *(--right_p); + + if (left_value < right_value) + { + return -1; + } + + if (left_value > right_value) + { + return 1; + } + } while (left_p > start_p); + + return 0; +} /* ecma_big_uint_compare */ + +/** + * In-place multiply and addition operation with digit + * + * return updated value on success, NULL if no memory is available + */ +ecma_extended_primitive_t * +ecma_big_uint_mul_digit (ecma_extended_primitive_t *value_p, /**< BigUInt value */ + ecma_bigint_digit_t mul, /**< multiply value */ + ecma_bigint_digit_t add) /**< addition value */ +{ + JERRY_ASSERT (mul > 1); + JERRY_ASSERT (add < mul); + + if (JERRY_UNLIKELY (value_p == NULL)) + { + JERRY_ASSERT (add > 0); + + value_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t)); + + if (JERRY_UNLIKELY (value_p == NULL)) + { + return NULL; + } + + *ECMA_BIGINT_GET_DIGITS (value_p, 0) = add; + return value_p; + } + + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (value_p, size) != 0); + + ecma_bigint_digit_t *current_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + ecma_bigint_digit_t *end_p = ECMA_BIGINT_GET_DIGITS (value_p, size); + ecma_bigint_digit_t carry = add; + + do + { + ecma_bigint_two_digits_t multiply_result = ((ecma_bigint_two_digits_t) *current_p) * mul; + ecma_bigint_digit_t multiply_result_low, new_carry; + + multiply_result_low = (ecma_bigint_digit_t) multiply_result; + new_carry = (ecma_bigint_digit_t) (multiply_result >> (8 * sizeof (ecma_bigint_digit_t))); + + multiply_result_low += carry; + if (multiply_result_low < carry) + { + new_carry++; + } + + *current_p++ = multiply_result_low; + carry = new_carry; + } while (current_p < end_p); + + if (carry == 0) + { + return value_p; + } + + return ecma_big_uint_extend (value_p, carry); +} /* ecma_big_uint_mul_digit */ + +/** + * Convert a BigUInt to a human readable number + * + * return char sequence on success, NULL otherwise + */ +lit_utf8_byte_t * +ecma_big_uint_to_string (ecma_extended_primitive_t *value_p, /**< BigUInt value */ + uint32_t radix, /**< radix number between 2 and 36 */ + uint32_t *char_start_p, /**< [out] start offset of numbers */ + uint32_t *char_size_p) /**< [out] size of the output buffer */ +{ + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (radix >= 2 && radix <= 36); + JERRY_ASSERT (size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (value_p, size) != 0); + + uint32_t max_size = size * 8; + + if (radix < 16) + { + if (radix >= 8) + { + /* Most frequent case. */ + max_size = (max_size + 2) / 3; + } + else if (radix >= 4) + { + max_size = (max_size + 1) >> 1; + } + } + else if (radix < 32) + { + max_size = (max_size + 3) >> 2; + } + else + { + max_size = (max_size + 4) / 5; + } + + /* This space can be used to store a sign. */ + max_size += (uint32_t) (2 * sizeof (ecma_bigint_digit_t) - 1); + max_size &= ~(uint32_t) (sizeof (ecma_bigint_digit_t) - 1); + *char_size_p = max_size; + + lit_utf8_byte_t *result_p = (lit_utf8_byte_t *) jmem_heap_alloc_block_null_on_error (max_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return NULL; + } + + memcpy (result_p, value_p + 1, size); + + ecma_bigint_digit_t *start_p = (ecma_bigint_digit_t *) (result_p + size); + ecma_bigint_digit_t *end_p = (ecma_bigint_digit_t *) result_p; + lit_utf8_byte_t *string_p = result_p + max_size; + + do + { + ecma_bigint_digit_t *current_p = (ecma_bigint_digit_t *) start_p; + ecma_bigint_digit_t remainder = 0; + + if (sizeof (uintptr_t) == sizeof (ecma_bigint_two_digits_t)) + { + do + { + ecma_bigint_two_digits_t result = *(--current_p) | ECMA_BIGINT_HIGH_DIGIT (remainder); + + *current_p = (ecma_bigint_digit_t) (result / radix); + remainder = (ecma_bigint_digit_t) (result % radix); + } while (current_p > end_p); + } + else + { + if (ECMA_BIGINT_SIZE_IS_ODD ((uintptr_t) current_p - (uintptr_t) end_p)) + { + ecma_bigint_digit_t result = *(--current_p); + *current_p = result / radix; + remainder = result % radix; + } + + while (current_p > end_p) + { + /* The following algorithm splits the 64 bit input into three numbers, extend + * them with remainder, divide them by radix, and updates the three bit ranges + * corresponding to the three numbers. */ + + const uint32_t extract_bits_low = 10; + const uint32_t extract_bits_low_mask = (uint32_t) ((1 << extract_bits_low) - 1); + const uint32_t extract_bits_high = (uint32_t) ((sizeof (ecma_bigint_digit_t) * 8) - extract_bits_low); + const uint32_t extract_bits_high_mask = (uint32_t) ((1 << extract_bits_high) - 1); + + ecma_bigint_digit_t result_high = current_p[-1]; + ecma_bigint_digit_t result_mid = (result_high & extract_bits_low_mask) << extract_bits_low; + + result_high = (result_high >> extract_bits_low) | (remainder << extract_bits_high); + result_mid |= (result_high % radix) << (extract_bits_low * 2); + result_high = (result_high / radix) << extract_bits_low; + + ecma_bigint_digit_t result_low = current_p[-2]; + result_mid |= result_low >> extract_bits_high; + result_low = (result_low & extract_bits_high_mask) | ((result_mid % radix) << extract_bits_high); + + result_mid = result_mid / radix; + + current_p[-1] = result_high | (result_mid >> extract_bits_low); + current_p[-2] = (result_low / radix) | (result_mid << extract_bits_high); + + remainder = result_low % radix; + current_p -= 2; + } + } + + *(--string_p) = + (lit_utf8_byte_t) ((remainder < 10) ? (remainder + LIT_CHAR_0) : (remainder + (LIT_CHAR_LOWERCASE_A - 10))); + JERRY_ASSERT (string_p >= (lit_utf8_byte_t *) start_p); + + if (start_p[-1] == 0) + { + start_p--; + } + } while (start_p > end_p); + + *char_start_p = (uint32_t) (string_p - result_p); + return result_p; +} /* ecma_big_uint_to_string */ + +/** + * Increase the value of a BigUInt value by 1 + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_increase (ecma_extended_primitive_t *value_p) /**< BigUInt value */ +{ + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (value_p, size) != 0); + + ecma_bigint_digit_t *digits_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + ecma_bigint_digit_t *digits_end_p = ECMA_BIGINT_GET_DIGITS (value_p, size); + + if (JERRY_UNLIKELY (digits_p[0] == ~((ecma_bigint_digit_t) 0) && digits_end_p[-1] == ~((ecma_bigint_digit_t) 0))) + { + do + { + digits_p++; + } while (digits_p < digits_end_p && digits_p[0] == ~((ecma_bigint_digit_t) 0)); + + if (digits_p == digits_end_p) + { + ecma_extended_primitive_t *result_value_p; + result_value_p = ecma_bigint_create ((uint32_t) (size + sizeof (ecma_bigint_digit_t))); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + memset (ECMA_BIGINT_GET_DIGITS (result_value_p, 0), 0, size); + *ECMA_BIGINT_GET_DIGITS (result_value_p, size) = 1; + return result_value_p; + } + + digits_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + } + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0); + + while (digits_p[0] == ~((ecma_bigint_digit_t) 0)) + { + digits_p++; + *result_p++ = 0; + } + + *result_p++ = (*digits_p++) + 1; + + if (digits_p < digits_end_p) + { + memcpy (result_p, digits_p, (size_t) ((uint8_t *) digits_end_p - (uint8_t *) digits_p)); + } + return result_value_p; +} /* ecma_big_uint_increase */ + +/** + * Decrease the value of a BigUInt value by 1 + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_decrease (ecma_extended_primitive_t *value_p) /**< BigUInt value */ +{ + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (value_p, size) != 0); + + ecma_bigint_digit_t *digits_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + ecma_bigint_digit_t *digits_end_p = ECMA_BIGINT_GET_DIGITS (value_p, size); + + JERRY_ASSERT (size > sizeof (ecma_bigint_digit_t) || *digits_p > 1); + + if (JERRY_UNLIKELY (digits_p[0] == 0 && digits_end_p[-1] == 1)) + { + do + { + digits_p++; + JERRY_ASSERT (digits_p < digits_end_p); + } while (digits_p[0] == 0); + + if (digits_p + 1 == digits_end_p) + { + size -= (uint32_t) sizeof (ecma_bigint_digit_t); + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + memset (ECMA_BIGINT_GET_DIGITS (result_value_p, 0), 0xff, size); + return result_value_p; + } + + digits_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + } + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0); + + while (digits_p[0] == 0) + { + digits_p++; + *result_p++ = ~((ecma_bigint_digit_t) 0); + } + + *result_p++ = (*digits_p++) - 1; + + if (digits_p < digits_end_p) + { + memcpy (result_p, digits_p, (size_t) ((uint8_t *) digits_end_p - (uint8_t *) digits_p)); + } + return result_value_p; +} /* ecma_big_uint_decrease */ + +/** + * Add right BigUInt value to the left BigUInt value + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_add (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + ecma_extended_primitive_t *right_value_p) /**< right BigUInt value */ +{ + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + uint32_t right_size = ECMA_BIGINT_GET_SIZE (right_value_p); + + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + JERRY_ASSERT (right_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (right_value_p, right_size) != 0); + + if (left_size < right_size) + { + /* Swap values. */ + ecma_extended_primitive_t *tmp_value_p = left_value_p; + left_value_p = right_value_p; + right_value_p = tmp_value_p; + + uint32_t tmp_size = left_size; + left_size = right_size; + right_size = tmp_size; + } + + ecma_extended_primitive_t *result_p = ecma_bigint_create (left_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return NULL; + } + + ecma_bigint_digit_t *current_p = ECMA_BIGINT_GET_DIGITS (result_p, 0); + ecma_bigint_digit_t *end_p = ECMA_BIGINT_GET_DIGITS (result_p, right_size); + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *right_p = ECMA_BIGINT_GET_DIGITS (right_value_p, 0); + ecma_bigint_digit_t carry = 0; + + left_size -= right_size; + + do + { + ecma_bigint_digit_t left = *left_p++; + + if (carry == 0 || left != ~(ecma_bigint_digit_t) 0) + { + left += carry; + carry = 0; + } + else + { + left = 0; + carry = 1; + } + + ecma_bigint_digit_t right = *right_p++; + left += right; + + if (left < right) + { + JERRY_ASSERT (carry == 0); + carry = 1; + } + + *current_p++ = left; + } while (current_p < end_p); + + end_p = (ecma_bigint_digit_t *) (((uint8_t *) end_p) + left_size); + + if (carry != 0) + { + while (true) + { + if (JERRY_UNLIKELY (current_p == end_p)) + { + return ecma_big_uint_extend (result_p, 1); + } + + ecma_bigint_digit_t value = *left_p++; + + if (value != ~(ecma_bigint_digit_t) 0) + { + *current_p++ = value + 1; + break; + } + + *current_p++ = 0; + } + } + + if (current_p < end_p) + { + memcpy (current_p, left_p, (size_t) ((uint8_t *) end_p - (uint8_t *) current_p)); + } + + return result_p; +} /* ecma_big_uint_add */ + +/** + * Subtract right BigUInt value from the left BigUInt value + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_sub (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + ecma_extended_primitive_t *right_value_p) /**< right BigUInt value */ +{ + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + uint32_t right_size = ECMA_BIGINT_GET_SIZE (right_value_p); + + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + JERRY_ASSERT (right_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (right_value_p, right_size) != 0); + JERRY_ASSERT (left_size >= right_size); + + ecma_extended_primitive_t *result_p = ecma_bigint_create (left_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return NULL; + } + + ecma_bigint_digit_t *current_p = ECMA_BIGINT_GET_DIGITS (result_p, 0); + ecma_bigint_digit_t *end_p = ECMA_BIGINT_GET_DIGITS (result_p, right_size); + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *right_p = ECMA_BIGINT_GET_DIGITS (right_value_p, 0); + ecma_bigint_digit_t carry = 0; + + left_size -= right_size; + + do + { + ecma_bigint_digit_t left = *left_p++; + ecma_bigint_digit_t right = *right_p++; + + if (carry == 0 || left != 0) + { + left -= carry; + carry = left < right; + } + else + { + left = ~(ecma_bigint_digit_t) 0; + carry = 1; + } + + *current_p++ = left - right; + } while (current_p < end_p); + + end_p = (ecma_bigint_digit_t *) (((uint8_t *) end_p) + left_size); + + if (carry != 0) + { + while (true) + { + JERRY_ASSERT (current_p < end_p); + + ecma_bigint_digit_t value = *left_p++; + + if (value != 0) + { + *current_p++ = value - 1; + break; + } + + *current_p++ = ~(ecma_bigint_digit_t) 0; + } + } + + if (current_p < end_p) + { + memcpy (current_p, left_p, (size_t) ((uint8_t *) end_p - (uint8_t *) current_p)); + return result_p; + } + + if (current_p[-1] != 0) + { + return result_p; + } + + return ecma_big_uint_normalize_result (result_p, current_p); +} /* ecma_big_uint_sub */ + +/** + * Multiply two BigUInt values + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_mul (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + ecma_extended_primitive_t *right_value_p) /**< right BigUInt value */ +{ + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + uint32_t right_size = ECMA_BIGINT_GET_SIZE (right_value_p); + + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + JERRY_ASSERT (right_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (right_value_p, right_size) != 0); + + if (left_size < right_size) + { + /* Swap values. */ + ecma_extended_primitive_t *tmp_value_p = left_value_p; + left_value_p = right_value_p; + right_value_p = tmp_value_p; + + uint32_t tmp_size = left_size; + left_size = right_size; + right_size = tmp_size; + } + + uint32_t result_size = left_size + right_size - (uint32_t) sizeof (ecma_bigint_digit_t); + + ecma_extended_primitive_t *result_p = ecma_bigint_create (result_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return NULL; + } + + memset (ECMA_BIGINT_GET_DIGITS (result_p, 0), 0, result_size); + + /* Lower amount of space is allocated by default. This value provides extra space if needed. */ + ecma_bigint_digit_t extra_space[1] = { 0 }; + + ecma_bigint_digit_t *right_p = ECMA_BIGINT_GET_DIGITS (right_value_p, 0); + ecma_bigint_digit_t *right_end_p = ECMA_BIGINT_GET_DIGITS (right_value_p, right_size); + ecma_bigint_digit_t *left_start_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *left_end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, left_size); + + ecma_bigint_digit_t *result_start_p = ECMA_BIGINT_GET_DIGITS (result_p, 0); + ecma_bigint_digit_t *result_end_p = ECMA_BIGINT_GET_DIGITS (result_p, result_size); + + do + { + ecma_bigint_two_digits_t right = *right_p++; + + if (right == 0) + { + result_start_p++; + continue; + } + + ecma_bigint_digit_t *left_p = left_start_p; + ecma_bigint_digit_t *destination_p = result_start_p; + ecma_bigint_digit_t carry = 0; + + do + { + JERRY_ASSERT (destination_p != (ecma_bigint_digit_t *) (extra_space + 1)); + + ecma_bigint_two_digits_t multiply_result; + ecma_bigint_digit_t multiply_result_low, new_carry; + ecma_bigint_digit_t value = *destination_p; + + multiply_result = ((ecma_bigint_two_digits_t) (*left_p++)) * ((ecma_bigint_two_digits_t) right); + multiply_result_low = (ecma_bigint_digit_t) multiply_result; + value += multiply_result_low; + new_carry = (ecma_bigint_digit_t) (multiply_result >> (8 * sizeof (ecma_bigint_digit_t))); + + /* The new_carry can never overflow because: + * a) If left or right is less than 0xff..ff, new_carry will be less than or equal to + * 0xff...fd, and increasing it by maximum of two (carries) cannot overflow. + * b) If left and right are both equal to 0xff..ff, multiply_result_low will be 1, + * and computing value + carry + 1 can only increase new_carry at most once. */ + + if (value < multiply_result_low) + { + JERRY_ASSERT (new_carry < ~(ecma_bigint_digit_t) 0); + new_carry++; + } + + value += carry; + + if (value < carry) + { + JERRY_ASSERT (new_carry < ~(ecma_bigint_digit_t) 0); + new_carry++; + } + + carry = new_carry; + *destination_p++ = value; + + if (destination_p == result_end_p) + { + destination_p = (ecma_bigint_digit_t *) extra_space; + } + } while (left_p < left_end_p); + + while (carry > 0) + { + JERRY_ASSERT (destination_p != (ecma_bigint_digit_t *) (extra_space + 1)); + + ecma_bigint_digit_t value = *destination_p; + + value += carry; + carry = (value < carry); + + *destination_p++ = value; + + if (destination_p == result_end_p) + { + destination_p = (ecma_bigint_digit_t *) extra_space; + } + } + + result_start_p++; + } while (right_p < right_end_p); + + if (extra_space[0] == 0) + { + return result_p; + } + + return ecma_big_uint_extend (result_p, extra_space[0]); +} /* ecma_big_uint_mul */ + +/** + * Divide left BigUInt value with right digit value + * + * return new BigUInt value, NULL on error + */ +static ecma_extended_primitive_t * +ecma_big_uint_div_digit (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + ecma_bigint_digit_t divisor_digit, /**< divisor value */ + bool is_mod) /**< true if return with remainder */ +{ + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + JERRY_ASSERT (divisor_digit > 0); + + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, left_size - sizeof (ecma_bigint_digit_t)); + ecma_bigint_digit_t *end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + + ecma_bigint_digit_t last_digit = *left_p; + ecma_bigint_digit_t remainder = last_digit % divisor_digit; + + last_digit = last_digit / divisor_digit; + + ecma_extended_primitive_t *result_p = NULL; + ecma_bigint_digit_t *current_p = NULL; + + if (!is_mod) + { + ecma_bigint_digit_t result_size = left_size; + + if (last_digit == 0) + { + result_size -= (uint32_t) sizeof (ecma_bigint_digit_t); + } + + result_p = ecma_bigint_create (result_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return NULL; + } + + current_p = ECMA_BIGINT_GET_DIGITS (result_p, result_size); + + if (last_digit != 0) + { + *(--current_p) = last_digit; + } + } + + while (left_p > end_p) + { + const uint32_t shift = 1 << ECMA_BIGINT_DIGIT_SHIFT; + + ecma_bigint_two_digits_t result = *(--left_p) | (((ecma_bigint_two_digits_t) remainder) << shift); + + if (!is_mod) + { + *(--current_p) = (ecma_bigint_digit_t) (result / divisor_digit); + } + + remainder = (ecma_bigint_digit_t) (result % divisor_digit); + } + + if (!is_mod) + { + JERRY_ASSERT (current_p == ECMA_BIGINT_GET_DIGITS (result_p, 0)); + return result_p; + } + + if (remainder == 0) + { + return ECMA_BIGINT_POINTER_TO_ZERO; + } + + result_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t)); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return NULL; + } + + *ECMA_BIGINT_GET_DIGITS (result_p, 0) = remainder; + return result_p; +} /* ecma_big_uint_div_digit */ + +/** + * Shift left a BigUInt value by a digit value + * + * return newly allocated buffer, NULL on error + */ +static ecma_bigint_digit_t * +ecma_big_uint_div_shift_left (ecma_extended_primitive_t *value_p, /**< BigUInt value */ + ecma_bigint_digit_t shift_left, /**< left shift */ + bool extend) /**< extend the result with an extra digit */ +{ + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (value_p, size) != 0); + + ecma_bigint_digit_t *source_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + ecma_bigint_digit_t *end_p = ECMA_BIGINT_GET_DIGITS (value_p, size); + + if (extend) + { + size += (uint32_t) sizeof (ecma_bigint_digit_t); + } + + ecma_bigint_digit_t *result_p = (ecma_bigint_digit_t *) jmem_heap_alloc_block_null_on_error (size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return result_p; + } + + if (shift_left == 0) + { + JERRY_ASSERT (extend); + + size -= (uint32_t) sizeof (ecma_bigint_digit_t); + *(ecma_bigint_digit_t *) (((uint8_t *) result_p) + size) = 0; + + memcpy (result_p, source_p, size); + return result_p; + } + + ecma_bigint_digit_t *destination_p = result_p; + ecma_bigint_digit_t carry = 0; + uint32_t shift_right = (1 << ECMA_BIGINT_DIGIT_SHIFT) - shift_left; + + do + { + ecma_bigint_digit_t value = *source_p++; + + *destination_p++ = (value << shift_left) | carry; + carry = value >> shift_right; + } while (source_p < end_p); + + if (extend) + { + *destination_p++ = carry; + } + + return result_p; +} /* ecma_big_uint_div_shift_left */ + +/** + * Divide left BigUInt value with right BigUInt value + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_div_mod (ecma_extended_primitive_t *dividend_value_p, /**< divider BigUInt value */ + ecma_extended_primitive_t *divisor_value_p, /**< divisor BigUInt value */ + bool is_mod) /**< true if return with remainder instead of quotient */ +{ + /* This algorithm is based on Donald Knuth’s "Algorithm D" */ + uint32_t divisor_size = ECMA_BIGINT_GET_SIZE (divisor_value_p); + + JERRY_ASSERT (divisor_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (divisor_value_p, divisor_size) != 0); + + /* The divisor must have at least two digits, so the single digit case is handled separately. */ + if (divisor_size == sizeof (ecma_bigint_digit_t)) + { + return ecma_big_uint_div_digit (dividend_value_p, *ECMA_BIGINT_GET_DIGITS (divisor_value_p, 0), is_mod); + } + + /* D1. [Normalize] */ + ecma_bigint_digit_t divisor_high = ECMA_BIGINT_GET_LAST_DIGIT (divisor_value_p, divisor_size); + ecma_bigint_digit_t shift_left = ecma_big_uint_count_leading_zero (divisor_high); + ecma_bigint_digit_t *buffer_p = ecma_big_uint_div_shift_left (dividend_value_p, shift_left, true); + ecma_bigint_digit_t *dividend_end_p; + ecma_bigint_digit_t *dividend_p; + ecma_bigint_digit_t *divisor_end_p; + ecma_bigint_digit_t divisor_low; + + if (JERRY_UNLIKELY (buffer_p == NULL)) + { + return NULL; + } + + uint32_t dividend_size = ECMA_BIGINT_GET_SIZE (dividend_value_p); + ecma_extended_primitive_t *result_p = NULL; + ecma_bigint_digit_t *divisor_p; + + JERRY_ASSERT (dividend_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (dividend_value_p, dividend_size) != 0); + JERRY_ASSERT (dividend_size >= divisor_size); + + if (shift_left > 0) + { + divisor_p = ecma_big_uint_div_shift_left (divisor_value_p, shift_left, false); + + if (JERRY_UNLIKELY (divisor_p == NULL)) + { + goto error; + } + } + else + { + divisor_p = ECMA_BIGINT_GET_DIGITS (divisor_value_p, 0); + } + + dividend_end_p = (ecma_bigint_digit_t *) (((uint8_t *) buffer_p) + dividend_size); + dividend_p = (ecma_bigint_digit_t *) (((uint8_t *) dividend_end_p) - divisor_size); + divisor_end_p = (ecma_bigint_digit_t *) (((uint8_t *) divisor_p) + divisor_size); + divisor_low = divisor_end_p[-2]; + + divisor_high = divisor_end_p[-1]; + JERRY_ASSERT ((divisor_high & (((ecma_bigint_digit_t) 1) << (8 * sizeof (ecma_bigint_digit_t) - 1))) != 0); + + do + { + /* D3. [Calculate Q′] */ + ecma_bigint_digit_t result_div; + + /* This do-while(false) statement allows local declarations and early exit. */ + do + { + ecma_bigint_digit_t result_mod; + + if (dividend_end_p[0] < divisor_high) + { + ecma_bigint_two_digits_t dividend = dividend_end_p[-1] | ECMA_BIGINT_HIGH_DIGIT (dividend_end_p[0]); + result_div = (ecma_bigint_digit_t) (dividend / divisor_high); + result_mod = (ecma_bigint_digit_t) (dividend % divisor_high); + } + else + { + JERRY_ASSERT (dividend_end_p[0] == divisor_high && dividend_end_p[-1] < divisor_high); + + result_div = ~((ecma_bigint_digit_t) 0); + result_mod = dividend_end_p[-1] + divisor_high; + + if (result_mod < divisor_high) + { + break; + } + } + + ecma_bigint_two_digits_t low_digits = ((ecma_bigint_two_digits_t) result_div) * divisor_low; + + while (low_digits > (ECMA_BIGINT_HIGH_DIGIT (result_mod) | divisor_low)) + { + result_div--; + result_mod += divisor_high; + + /* If result_mod becomes a two digit long number, the condition of the loop must be true, + * so the loop can be aborted. This loop stops after maximum of two iterations, since + * the highest bit of divisor_high is set. */ + if (result_mod < divisor_high) + { + break; + } + + /* Subtraction is faster than recomputing result_div * divisor_low. */ + low_digits -= divisor_low; + } + } while (false); + + /* D4. [Multiply and subtract] */ + ecma_bigint_digit_t *destination_p = dividend_p; + ecma_bigint_digit_t *source_p = divisor_p; + ecma_bigint_digit_t carry = 0; + + do + { + ecma_bigint_two_digits_t multiply_result = ((ecma_bigint_two_digits_t) (*source_p++)) * result_div; + ecma_bigint_digit_t multiply_result_low, new_carry; + ecma_bigint_digit_t value = *destination_p; + + /* The new carry never overflows. See the comment in ecma_big_uint_mul. */ + new_carry = (ecma_bigint_digit_t) (multiply_result >> (8 * sizeof (ecma_bigint_digit_t))); + multiply_result_low = (ecma_bigint_digit_t) multiply_result; + + if (value < multiply_result_low) + { + new_carry++; + } + + value -= multiply_result_low; + + if (value < carry) + { + new_carry++; + } + + *destination_p++ = value - carry; + carry = new_carry; + } while (source_p < divisor_end_p); + + bool negative_result = *destination_p < carry; + *destination_p -= carry; + + if (negative_result) + { + /* D6. [Add back] */ + result_div--; + + destination_p = dividend_p; + source_p = divisor_p; + carry = 0; + + do + { + ecma_bigint_digit_t left = *destination_p; + + if (carry == 0 || left != ~(ecma_bigint_digit_t) 0) + { + left += carry; + carry = 0; + } + else + { + left = 0; + carry = 1; + } + + ecma_bigint_digit_t right = *source_p++; + left += right; + + if (left < right) + { + JERRY_ASSERT (carry == 0); + carry = 1; + } + + *destination_p++ = left; + } while (source_p < divisor_end_p); + } + + *dividend_end_p = result_div; + + dividend_p--; + dividend_end_p--; + } while (dividend_p >= buffer_p); + + ecma_bigint_digit_t *source_p; + ecma_bigint_digit_t *source_end_p; + + if (is_mod) + { + source_p = buffer_p; + source_end_p = dividend_end_p; + + while (source_end_p > source_p && *source_end_p == 0) + { + source_end_p--; + } + + if ((*source_end_p >> shift_left) != 0) + { + source_end_p++; + /* This is required to reset carry below. */ + *source_end_p = 0; + } + } + else + { + source_p = dividend_end_p + 1; + source_end_p = (ecma_bigint_digit_t *) (((uint8_t *) buffer_p) + dividend_size); + + if (*source_end_p != 0) + { + source_end_p++; + } + } + + result_p = ECMA_BIGINT_POINTER_TO_ZERO; + + if (source_p < source_end_p) + { + result_p = ecma_bigint_create ((uint32_t) ((uint8_t *) source_end_p - (uint8_t *) source_p)); + + if (result_p != NULL) + { + ecma_bigint_digit_t *destination_p = ECMA_BIGINT_GET_DIGITS (result_p, 0); + + if (is_mod && shift_left > 0) + { + ecma_bigint_digit_t shift_right = shift_left; + + shift_left = (ecma_bigint_digit_t) (8 * (sizeof (ecma_bigint_digit_t)) - shift_left); + destination_p += source_end_p - source_p; + + ecma_bigint_digit_t carry = *source_end_p << shift_left; + + do + { + ecma_bigint_digit_t value = *(--source_end_p); + + *(--destination_p) = (value >> shift_right) | carry; + carry = value << shift_left; + } while (source_end_p > source_p); + } + else + { + memcpy (destination_p, source_p, (size_t) ((uint8_t *) source_end_p - (uint8_t *) source_p)); + } + } + } + +error: + jmem_heap_free_block (buffer_p, dividend_size + sizeof (ecma_bigint_digit_t)); + + if (shift_left > 0 && divisor_p != NULL) + { + jmem_heap_free_block (divisor_p, divisor_size); + } + + return result_p; +} /* ecma_big_uint_div_mod */ + +/** + * Shift left BigUInt values by an uint32 value + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_shift_left (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + uint32_t right_value) /**< shift value */ +{ + JERRY_ASSERT (right_value > 0); + + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + + uint32_t zero_size = (right_value >> ECMA_BIGINT_DIGIT_SHIFT) * (uint32_t) sizeof (ecma_bigint_digit_t); + uint32_t result_size = left_size + zero_size; + + uint32_t shift_left = right_value & ((1 << ECMA_BIGINT_DIGIT_SHIFT) - 1); + uint32_t shift_right = (1 << ECMA_BIGINT_DIGIT_SHIFT) - shift_left; + + if (shift_left > 0 && (ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) >> shift_right) != 0) + { + result_size += (uint32_t) sizeof (ecma_bigint_digit_t); + } + + if (result_size > ECMA_BIGINT_MAX_SIZE) + { + return NULL; + } + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (result_size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0); + + if (zero_size > 0) + { + memset (result_p, 0, zero_size); + result_p = (ecma_bigint_digit_t *) (((uint8_t *) result_p) + zero_size); + } + + if (shift_left == 0) + { + /* Shift by full digits. */ + memcpy (result_p, left_p, left_size); + return result_value_p; + } + + ecma_bigint_digit_t *left_end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, left_size); + ecma_bigint_digit_t carry = 0; + + do + { + ecma_bigint_digit_t value = *left_p++; + + *result_p++ = (value << shift_left) | carry; + carry = value >> shift_right; + } while (left_p < left_end_p); + + if (carry > 0) + { + *result_p = carry; + } + + return result_value_p; +} /* ecma_big_uint_shift_left */ + +/** + * Shift right BigUInt values by an uint32 value + * + * @return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_shift_right (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + uint32_t right_value, /**< shift value */ + bool increase_result) /**< increase result */ +{ + JERRY_ASSERT (right_value > 0); + + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + + uint32_t crop_size = (right_value >> ECMA_BIGINT_DIGIT_SHIFT) * (uint32_t) sizeof (ecma_bigint_digit_t); + + uint32_t shift_right = right_value & ((1 << ECMA_BIGINT_DIGIT_SHIFT) - 1); + uint32_t shift_left = (1 << ECMA_BIGINT_DIGIT_SHIFT) - shift_right; + ecma_bigint_digit_t carry = 0; + + if (shift_right > 0 && (ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) >> shift_right) == 0) + { + carry = ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) << shift_left; + left_size -= (uint32_t) sizeof (ecma_bigint_digit_t); + } + + if (left_size <= crop_size) + { + if (JERRY_LIKELY (!increase_result)) + { + return ECMA_BIGINT_POINTER_TO_ZERO; + } + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t)); + if (result_value_p != NULL) + { + *ECMA_BIGINT_GET_DIGITS (result_value_p, 0) = 1; + } + return result_value_p; + } + + if (JERRY_UNLIKELY (increase_result) + && (shift_right == 0 || (*ECMA_BIGINT_GET_DIGITS (left_value_p, crop_size) << shift_left) == 0)) + { + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *left_end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, crop_size); + + while (left_p < left_end_p) + { + if (*left_p != 0) + { + break; + } + left_p++; + } + + if (left_p == left_end_p) + { + increase_result = false; + } + } + + uint32_t size = left_size - crop_size; + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + if (shift_right == 0) + { + memcpy (ECMA_BIGINT_GET_DIGITS (result_value_p, 0), ECMA_BIGINT_GET_DIGITS (left_value_p, crop_size), size); + + if (JERRY_LIKELY (!increase_result)) + { + return result_value_p; + } + return ecma_big_uint_increase_result (result_value_p); + } + + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, left_size); + ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, size); + ecma_bigint_digit_t *end_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0); + + do + { + ecma_bigint_digit_t value = *(--left_p); + + *(--result_p) = (value >> shift_right) | carry; + carry = value << shift_left; + } while (result_p > end_p); + + if (JERRY_LIKELY (!increase_result)) + { + return result_value_p; + } + return ecma_big_uint_increase_result (result_value_p); +} /* ecma_big_uint_shift_right */ + +/** + * Compute the left value raised to the power of right value + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_pow (ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + uint32_t right_value) /**< power value */ +{ + ecma_extended_primitive_t *result_p = ECMA_BIGINT_NUMBER_IS_ODD (right_value) ? left_value_p : NULL; + ecma_extended_primitive_t *square_p = left_value_p; + + JERRY_ASSERT (right_value >= 2); + + while (true) + { + ecma_extended_primitive_t *new_square_p = ecma_big_uint_mul (square_p, square_p); + + if (JERRY_UNLIKELY (new_square_p == NULL)) + { + if (result_p != NULL && result_p != left_value_p) + { + ecma_deref_bigint (result_p); + } + result_p = NULL; + break; + } + + if (square_p != left_value_p) + { + ecma_deref_bigint (square_p); + } + + square_p = new_square_p; + right_value >>= 1; + + if (ECMA_BIGINT_NUMBER_IS_ODD (right_value)) + { + if (result_p != NULL) + { + ecma_extended_primitive_t *new_result_p = ecma_big_uint_mul (square_p, result_p); + + if (result_p != left_value_p) + { + ecma_deref_bigint (result_p); + } + + result_p = new_result_p; + } + else + { + ecma_ref_extended_primitive (square_p); + result_p = square_p; + } + + if (JERRY_UNLIKELY (result_p == NULL) || right_value == 1) + { + break; + } + } + } + + if (square_p != left_value_p) + { + ecma_deref_bigint (square_p); + } + + return result_p; +} /* ecma_big_uint_pow */ + +/** + * Perform bitwise operations on two BigUInt numbers + * + * return new BigUInt value, NULL on error + */ +ecma_extended_primitive_t * +ecma_big_uint_bitwise_op (uint32_t operation_and_options, /**< bitwise operation type and options */ + ecma_extended_primitive_t *left_value_p, /**< left BigUInt value */ + ecma_extended_primitive_t *right_value_p) /**< right BigUInt value */ +{ + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + uint32_t right_size = ECMA_BIGINT_GET_SIZE (right_value_p); + + JERRY_ASSERT (left_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (left_value_p, left_size) != 0); + JERRY_ASSERT (right_size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (right_value_p, right_size) != 0); + + uint32_t operation_type = ECMA_BIGINT_BITWISE_GET_OPERATION_TYPE (operation_and_options); + + switch (operation_type) + { + case ECMA_BIG_UINT_BITWISE_AND: + { + if (left_size > right_size) + { + left_size = right_size; + break; + } + /* FALLTHRU */ + } + case ECMA_BIG_UINT_BITWISE_AND_NOT: + { + if (right_size > left_size) + { + right_size = left_size; + } + break; + } + default: + { + JERRY_ASSERT (operation_type == ECMA_BIG_UINT_BITWISE_OR || operation_type == ECMA_BIG_UINT_BITWISE_XOR); + + if (right_size <= left_size) + { + break; + } + + /* Swap values. */ + ecma_extended_primitive_t *tmp_value_p = left_value_p; + left_value_p = right_value_p; + right_value_p = tmp_value_p; + + uint32_t tmp_size = left_size; + left_size = right_size; + right_size = tmp_size; + + uint32_t decrease_opts = (operation_and_options & ECMA_BIG_UINT_BITWISE_DECREASE_BOTH); + + /* When exactly one bit is set, invert both bits. */ + if (decrease_opts >= ECMA_BIG_UINT_BITWISE_DECREASE_LEFT && decrease_opts <= ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT) + { + operation_and_options ^= ECMA_BIG_UINT_BITWISE_DECREASE_BOTH; + } + break; + } + } + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (left_size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return NULL; + } + + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *right_p = ECMA_BIGINT_GET_DIGITS (right_value_p, 0); + ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0); + ecma_bigint_digit_t *result_end_p = ECMA_BIGINT_GET_DIGITS (result_value_p, right_size); + + if (!(operation_and_options & ECMA_BIG_UINT_BITWISE_DECREASE_BOTH)) + { + JERRY_ASSERT (!(operation_and_options & ECMA_BIG_UINT_BITWISE_INCREASE_RESULT)); + + if (operation_type == ECMA_BIG_UINT_BITWISE_AND) + { + do + { + *result_p++ = *left_p++ & *right_p++; + } while (result_p < result_end_p); + + if (result_p[-1] == 0) + { + return ecma_big_uint_normalize_result (result_value_p, result_p); + } + return result_value_p; + } + + if (operation_type == ECMA_BIG_UINT_BITWISE_OR) + { + do + { + *result_p++ = *left_p++ | *right_p++; + } while (result_p < result_end_p); + + if (left_size > right_size) + { + memcpy (result_p, left_p, left_size - right_size); + } + return result_value_p; + } + + JERRY_ASSERT (operation_type == ECMA_BIG_UINT_BITWISE_XOR); + + do + { + *result_p++ = *left_p++ ^ *right_p++; + } while (result_p < result_end_p); + + if (left_size > right_size) + { + memcpy (result_p, left_p, left_size - right_size); + return result_value_p; + } + + if (result_p[-1] == 0) + { + return ecma_big_uint_normalize_result (result_value_p, result_p); + } + return result_value_p; + } + + uint32_t left_carry = 0, right_carry = 0; + + if (operation_and_options & ECMA_BIG_UINT_BITWISE_DECREASE_LEFT) + { + left_carry = 1; + } + + if (operation_and_options & ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT) + { + right_carry = 1; + } + + do + { + ecma_bigint_digit_t left = (*left_p++) - left_carry; + + if (left != ~((ecma_bigint_digit_t) 0)) + { + left_carry = 0; + } + + ecma_bigint_digit_t right = (*right_p++) - right_carry; + + if (right != ~((ecma_bigint_digit_t) 0)) + { + right_carry = 0; + } + + switch (operation_type) + { + case ECMA_BIG_UINT_BITWISE_AND: + { + *result_p++ = left & right; + break; + } + case ECMA_BIG_UINT_BITWISE_OR: + { + *result_p++ = left | right; + break; + } + case ECMA_BIG_UINT_BITWISE_XOR: + { + *result_p++ = left ^ right; + break; + } + default: + { + JERRY_ASSERT (operation_type == ECMA_BIG_UINT_BITWISE_AND_NOT); + *result_p++ = left & ~right; + break; + } + } + } while (result_p < result_end_p); + + if (operation_type != ECMA_BIG_UINT_BITWISE_AND) + { + result_end_p = ECMA_BIGINT_GET_DIGITS (result_value_p, left_size); + + if (left_carry > 0) + { + while (*left_p == 0) + { + *result_p++ = ~((ecma_bigint_digit_t) 0); + left_p++; + + JERRY_ASSERT (result_p < result_end_p); + } + + *result_p++ = *left_p++ - 1; + } + + if (result_p < result_end_p) + { + memcpy (result_p, left_p, (size_t) ((uint8_t *) result_end_p - (uint8_t *) result_p)); + + if (operation_and_options & ECMA_BIG_UINT_BITWISE_INCREASE_RESULT) + { + return ecma_big_uint_increase_result (result_value_p); + } + return result_value_p; + } + } + + if (operation_and_options & ECMA_BIG_UINT_BITWISE_INCREASE_RESULT) + { + return ecma_big_uint_increase_result (result_value_p); + } + + if (result_p[-1] == 0) + { + return ecma_big_uint_normalize_result (result_value_p, result_p); + } + return result_value_p; +} /* ecma_big_uint_bitwise_op */ + +#endif /* JERRY_BUILTIN_BIGINT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-big-uint.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-big-uint.h new file mode 100644 index 0000000..727d780 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-big-uint.h @@ -0,0 +1,135 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BIG_UINT_H +#define ECMA_BIG_UINT_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_BIGINT + +/** + * Limit of BigUInt memory allocation in JerryScript. + */ +#define ECMA_BIGINT_MAX_SIZE 0x10000 + +/** + * Unsigned type which can hold two digits. + */ +typedef uint64_t ecma_bigint_two_digits_t; + +/** + * Shift used by left/right shifting of a value. + */ +#define ECMA_BIGINT_DIGIT_SHIFT 5 + +/** + * Return with the digits of a BigInt value. + */ +#define ECMA_BIGINT_GET_DIGITS(value_p, offset) \ + ((ecma_bigint_digit_t *) (((uint8_t *) (value_p)) + sizeof (ecma_extended_primitive_t) + (offset))) + +/** + * Return with the digits of a BigInt value. + */ +#define ECMA_BIGINT_GET_LAST_DIGIT(value_p, size) *ECMA_BIGINT_GET_DIGITS (value_p, size - sizeof (ecma_bigint_digit_t)) + +/** + * Returns true if size is an odd number. + */ +#define ECMA_BIGINT_SIZE_IS_ODD(size) (((size) & sizeof (ecma_bigint_digit_t)) != 0) + +/** + * Returns a two digit value where the high digit is set to the passed digit. + */ +#define ECMA_BIGINT_HIGH_DIGIT(digit) (((ecma_bigint_two_digits_t) digit) << (8 * sizeof (ecma_bigint_digit_t))) + +/** + * Tells whether a number (usually a digit or uint32_t value) is an odd number. + */ +#define ECMA_BIGINT_NUMBER_IS_ODD(number) ((number & 0x1) != 0) + +/** + * Bitwise operation types. + */ +typedef enum +{ + ECMA_BIG_UINT_BITWISE_AND, /**< bitwise 'and' operation */ + ECMA_BIG_UINT_BITWISE_OR, /**< bitwise 'or' operation */ + ECMA_BIG_UINT_BITWISE_XOR, /**< bitwise 'xor' operation */ + ECMA_BIG_UINT_BITWISE_AND_NOT, /**< bitwise 'and not' operation */ +} ecma_big_uint_bitwise_operation_types_t; + +/** + * Returns with the type of the operation. + */ +#define ECMA_BIGINT_BITWISE_GET_OPERATION_TYPE(operation_and_options) ((operation_and_options) &0xf) + +/** + * Options for bitwise operations. + */ +typedef enum +{ + ECMA_BIG_UINT_BITWISE_DECREASE_LEFT = (1 << 4), /**< subtract 1 from left value */ + ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT = (1 << 5), /**< subtract 1 from right value */ + ECMA_BIG_UINT_BITWISE_INCREASE_RESULT = (1 << 6), /**< add 1 to the result */ +} ecma_big_uint_bitwise_options_t; + +/** + * Subtract 1 from both left and right values. + */ +#define ECMA_BIG_UINT_BITWISE_DECREASE_BOTH (ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT) + +ecma_extended_primitive_t *ecma_bigint_create (uint32_t size); +ecma_extended_primitive_t *ecma_big_uint_extend (ecma_extended_primitive_t *value_p, ecma_bigint_digit_t digit); + +ecma_bigint_digit_t ecma_big_uint_count_leading_zero (ecma_bigint_digit_t digit); + +int ecma_big_uint_compare (ecma_extended_primitive_t *left_value_p, ecma_extended_primitive_t *right_value_p); + +ecma_extended_primitive_t * +ecma_big_uint_mul_digit (ecma_extended_primitive_t *value_p, ecma_bigint_digit_t mul, ecma_bigint_digit_t add); + +uint8_t *ecma_big_uint_to_string (ecma_extended_primitive_t *value_p, + uint32_t radix, + uint32_t *char_start_p, + uint32_t *char_size_p); + +ecma_extended_primitive_t *ecma_big_uint_increase (ecma_extended_primitive_t *value_p); +ecma_extended_primitive_t *ecma_big_uint_decrease (ecma_extended_primitive_t *value_p); + +ecma_extended_primitive_t *ecma_big_uint_add (ecma_extended_primitive_t *left_value_p, + ecma_extended_primitive_t *right_value_p); +ecma_extended_primitive_t *ecma_big_uint_sub (ecma_extended_primitive_t *left_value_p, + ecma_extended_primitive_t *right_value_p); +ecma_extended_primitive_t *ecma_big_uint_mul (ecma_extended_primitive_t *left_value_p, + ecma_extended_primitive_t *right_value_p); +ecma_extended_primitive_t *ecma_big_uint_div_mod (ecma_extended_primitive_t *dividend_value_p, + ecma_extended_primitive_t *divisor_value_p, + bool is_mod); + +ecma_extended_primitive_t *ecma_big_uint_shift_left (ecma_extended_primitive_t *left_value_p, uint32_t right_value); +ecma_extended_primitive_t * +ecma_big_uint_shift_right (ecma_extended_primitive_t *left_value_p, uint32_t right_value, bool increase_result); + +ecma_extended_primitive_t *ecma_big_uint_pow (ecma_extended_primitive_t *left_value_p, uint32_t right_value); + +ecma_extended_primitive_t *ecma_big_uint_bitwise_op (uint32_t operation_and_options, + ecma_extended_primitive_t *left_value_p, + ecma_extended_primitive_t *right_value_p); + +#endif /* JERRY_BUILTIN_BIGINT */ + +#endif /* ECMA_BIG_UINT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint-object.cpp new file mode 100644 index 0000000..6d03cd5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint-object.cpp @@ -0,0 +1,66 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-bigint-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#if JERRY_BUILTIN_BIGINT + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabigintobject ECMA BigInt object related routines + * @{ + */ + +/** + * BigInt object creation operation. + * + * See also: ECMA-262 v11, 7.1.18 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_bigint_object (ecma_value_t arg) /**< argument passed to the toObject operation */ +{ + JERRY_ASSERT (ecma_is_value_bigint (arg)); + + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_BIGINT_PROTOTYPE); + + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_BIGINT; + ext_object_p->u.cls.u3.value = ecma_copy_value (arg); + + return ecma_make_object_value (object_p); +} /* ecma_op_create_bigint_object */ + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint-object.h new file mode 100644 index 0000000..72adefe --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint-object.h @@ -0,0 +1,39 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BIGINT_OBJECT_H +#define ECMA_BIGINT_OBJECT_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_BIGINT + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabigintobject ECMA BigInt object related routines + * @{ + */ + +ecma_value_t ecma_op_create_bigint_object (ecma_value_t arg); + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_BIGINT */ + +#endif /* !ECMA_BIGINT_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint.cpp new file mode 100644 index 0000000..71c100a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint.cpp @@ -0,0 +1,1703 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-bigint.h" + +#include "ecma-big-uint.h" +#include "ecma-exceptions.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "lit-char-helpers.h" + +#if JERRY_BUILTIN_BIGINT + +/** + * Raise a not enough memory error + * + * @return ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_bigint_raise_memory_error (void) +{ + return ecma_raise_range_error (ECMA_ERR_ALLOCATE_BIGINT_VALUE); +} /* ecma_bigint_raise_memory_error */ + +/** + * Create a single digit long BigInt value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_bigint_create_from_digit (ecma_bigint_digit_t digit, /* single digit */ + bool sign) /* set ECMA_BIGINT_SIGN if true */ +{ + JERRY_ASSERT (digit != 0); + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t)); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + if (sign) + { + result_value_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + + *ECMA_BIGINT_GET_DIGITS (result_value_p, 0) = digit; + return ecma_make_extended_primitive_value (result_value_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_create_from_digit */ + +/** + * Parse a string and create a BigInt value + * + * @return ecma BigInt value or a special value allowed by the option flags + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_parse_string (const lit_utf8_byte_t *string_p, /**< string representation of the BigInt */ + lit_utf8_size_t size, /**< string size */ + uint32_t options) /**< ecma_bigint_parse_string_options_t option bits */ +{ + ecma_bigint_digit_t radix = 10; + uint32_t sign = (options & ECMA_BIGINT_PARSE_SET_NEGATIVE) ? ECMA_BIGINT_SIGN : 0; + bool allow_underscore = options & ECMA_BIGINT_PARSE_ALLOW_UNDERSCORE; + + const lit_utf8_byte_t *string_end_p = string_p + size; + string_p = ecma_string_trim_front (string_p, string_p + size); + size = (lit_utf8_size_t) (string_end_p - string_p); + + if (size >= 3 && string_p[0] == LIT_CHAR_0) + { + radix = lit_char_to_radix (string_p[1]); + + if (radix != 10) + { + string_p += 2; + size -= 2; + } + } + else if (size >= 2) + { + if (string_p[0] == LIT_CHAR_PLUS) + { + size--; + string_p++; + } + else if (string_p[0] == LIT_CHAR_MINUS) + { + sign = ECMA_BIGINT_SIGN; + size--; + string_p++; + } + } + else if (size == 0) + { + return ECMA_BIGINT_ZERO; + } + + while (string_p < string_end_p && (*string_p == LIT_CHAR_0 || (*string_p == LIT_CHAR_UNDERSCORE && allow_underscore))) + { + string_p++; + } + + ecma_extended_primitive_t *result_p = NULL; + + if (string_p == string_end_p) + { + return ECMA_BIGINT_ZERO; + } + + do + { + ecma_bigint_digit_t digit = radix; + + if (*string_p >= LIT_CHAR_0 && *string_p <= LIT_CHAR_9) + { + digit = (ecma_bigint_digit_t) (*string_p - LIT_CHAR_0); + } + else if (*string_p == LIT_CHAR_UNDERSCORE && allow_underscore) + { + continue; + } + else + { + lit_utf8_byte_t character = (lit_utf8_byte_t) LEXER_TO_ASCII_LOWERCASE (*string_p); + + if (character >= LIT_CHAR_LOWERCASE_A && character <= LIT_CHAR_LOWERCASE_F) + { + digit = (ecma_bigint_digit_t) (character - (LIT_CHAR_LOWERCASE_A - 10)); + } + else if (ecma_string_trim_front (string_p, string_end_p) == string_end_p) + { + string_p = string_end_p; + break; + } + } + if (digit >= radix) + { + if (result_p != NULL) + { + ecma_deref_bigint (result_p); + } + + if (options & ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR) + { + return ECMA_VALUE_FALSE; + } + return ecma_raise_syntax_error (ECMA_ERR_STRING_CANNOT_BE_CONVERTED_TO_BIGINT_VALUE); + } + + result_p = ecma_big_uint_mul_digit (result_p, radix, digit); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + break; + } + } while (++string_p < string_end_p); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + if (options & ECMA_BIGINT_PARSE_DISALLOW_MEMORY_ERROR) + { + return ECMA_VALUE_NULL; + } + return ecma_bigint_raise_memory_error (); + } + + result_p->u.bigint_sign_and_size |= sign; + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_parse_string */ + +/** + * Parse a string value and create a BigInt value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_parse_string_value (ecma_value_t string, /**< ecma string */ + uint32_t options) /**< ecma_bigint_parse_string_options_t option bits */ +{ + JERRY_ASSERT (ecma_is_value_string (string)); + + ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (string), string_buffer_p, string_buffer_size); + + ecma_value_t result = ecma_bigint_parse_string (string_buffer_p, string_buffer_size, options); + ECMA_FINALIZE_UTF8_STRING (string_buffer_p, string_buffer_size); + + return result; +} /* ecma_bigint_parse_string_value */ + +/** + * Create a string representation for a BigInt value + * + * @return ecma string or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_string_t * +ecma_bigint_to_string (ecma_value_t value, /**< BigInt value */ + ecma_bigint_digit_t radix) /**< conversion radix */ +{ + JERRY_ASSERT (ecma_is_value_bigint (value)); + + if (value == ECMA_BIGINT_ZERO) + { + return ecma_new_ecma_string_from_code_unit (LIT_CHAR_0); + } + + uint32_t char_start_p, char_size_p; + ecma_extended_primitive_t *bigint_p = ecma_get_extended_primitive_from_value (value); + lit_utf8_byte_t *string_buffer_p = ecma_big_uint_to_string (bigint_p, radix, &char_start_p, &char_size_p); + + if (JERRY_UNLIKELY (string_buffer_p == NULL)) + { + ecma_raise_range_error (ECMA_ERR_ALLOCATE_BIGINT_STRING); + return NULL; + } + + JERRY_ASSERT (char_start_p > 0); + + if (bigint_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + string_buffer_p[--char_start_p] = LIT_CHAR_MINUS; + } + + ecma_string_t *string_p; + string_p = ecma_new_ecma_string_from_ascii (string_buffer_p + char_start_p, char_size_p - char_start_p); + + jmem_heap_free_block (string_buffer_p, char_size_p); + return string_p; +} /* ecma_bigint_to_string */ + +/** + * Get the size of zero digits from the result of ecma_bigint_number_to_digits + */ +#define ECMA_BIGINT_NUMBER_TO_DIGITS_GET_ZERO_SIZE(value) (((value) &0xffff) * (uint32_t) sizeof (ecma_bigint_digit_t)) + +/** + * Get the number of digits from the result of ecma_bigint_number_to_digits + */ +#define ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS(value) ((value) >> 20) + +/** + * Get the size of digits from the result of ecma_bigint_number_to_digits + */ +#define ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS_SIZE(value) \ + (ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (value) * (uint32_t) sizeof (ecma_bigint_digit_t)) + +/** + * Set number of digits in the result of ecma_bigint_number_to_digits + */ +#define ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS(value) ((uint32_t) (value) << 20) + +/** + * This flag is set when the number passed to ecma_bigint_number_to_digits has fraction part + */ +#define ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION 0x10000 + +/** + * Convert a number to maximum of 3 digits and left shift + * + * @return packed value, ECMA_BIGINT_NUMBER_TO_DIGITS* macros can be used to decode it + */ +static uint32_t +ecma_bigint_number_to_digits (ecma_number_t number, /**< ecma number */ + ecma_bigint_digit_t *digits_p) /**< [out] BigInt digits */ +{ + if (ecma_number_is_zero (number)) + { + return ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (0); + } + + ecma_binary_num_t binary = ecma_number_to_binary (number); + uint32_t biased_exp = ecma_number_biased_exp (binary); + uint64_t fraction = ecma_number_fraction (binary); + + if (biased_exp < ((1 << (ECMA_NUMBER_BIASED_EXP_WIDTH - 1)) - 1)) + { + /* Number is less than 1. */ + return ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (0) | ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION; + } + + biased_exp -= ((1 << (ECMA_NUMBER_BIASED_EXP_WIDTH - 1)) - 1); + fraction |= ((uint64_t) 1) << ECMA_NUMBER_FRACTION_WIDTH; + + if (biased_exp <= ECMA_NUMBER_FRACTION_WIDTH) + { + uint32_t has_fraction = 0; + + if (biased_exp < ECMA_NUMBER_FRACTION_WIDTH + && (fraction << (biased_exp + ((8 * sizeof (uint64_t)) - ECMA_NUMBER_FRACTION_WIDTH))) != 0) + { + has_fraction |= ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION; + } + + fraction >>= ECMA_NUMBER_FRACTION_WIDTH - biased_exp; + digits_p[0] = (ecma_bigint_digit_t) fraction; + +#if JERRY_NUMBER_TYPE_FLOAT64 + digits_p[1] = (ecma_bigint_digit_t) (fraction >> (8 * sizeof (ecma_bigint_digit_t))); + return ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (digits_p[1] == 0 ? 1 : 2) | has_fraction; +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ + return ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (1) | has_fraction; +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + } + + digits_p[0] = (ecma_bigint_digit_t) fraction; +#if JERRY_NUMBER_TYPE_FLOAT64 + digits_p[1] = (ecma_bigint_digit_t) (fraction >> (8 * sizeof (ecma_bigint_digit_t))); +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + + biased_exp -= ECMA_NUMBER_FRACTION_WIDTH; + + uint32_t shift_left = biased_exp & ((8 * sizeof (ecma_bigint_digit_t)) - 1); + biased_exp = biased_exp >> ECMA_BIGINT_DIGIT_SHIFT; + + if (shift_left == 0) + { +#if JERRY_NUMBER_TYPE_FLOAT64 + return biased_exp | ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (2); +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ + return biased_exp | ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (1); +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + } + + uint32_t shift_right = (1 << ECMA_BIGINT_DIGIT_SHIFT) - shift_left; + +#if JERRY_NUMBER_TYPE_FLOAT64 + digits_p[2] = digits_p[1] >> shift_right; + digits_p[1] = (digits_p[1] << shift_left) | (digits_p[0] >> shift_right); + digits_p[0] <<= shift_left; + + return biased_exp | ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (digits_p[2] == 0 ? 2 : 3); +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ + digits_p[1] = digits_p[0] >> shift_right; + digits_p[0] <<= shift_left; + + return biased_exp | ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (digits_p[1] == 0 ? 1 : 2); +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +} /* ecma_bigint_number_to_digits */ + +/** + * Convert an ecma number to BigInt value + * + * See also: + * ECMA-262 v11, 20.2.1.1.1 + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_bigint_number_to_bigint (ecma_number_t number) /**< ecma number */ +{ + if (ecma_number_is_nan (number) || ecma_number_is_infinity (number)) + { + return ecma_raise_range_error (ECMA_ERR_INFINITY_OR_NAN_CANNOT_BE_CONVERTED_TO_BIGINT); + } + + ecma_bigint_digit_t digits[3]; + uint32_t result = ecma_bigint_number_to_digits (number, digits); + + JERRY_ASSERT (ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) == 0 + || digits[ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) - 1] > 0); + + if (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION) + { + return ecma_raise_range_error (ECMA_ERR_ONLY_INTEGER_NUMBERS_CAN_BE_CONVERTED_TO_BIGINT); + } + + uint32_t digits_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS_SIZE (result); + + if (digits_size == 0) + { + return ECMA_BIGINT_ZERO; + } + + uint32_t zero_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_ZERO_SIZE (result); + + ecma_extended_primitive_t *result_p = ecma_bigint_create (digits_size + zero_size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + uint8_t *data_p = (uint8_t *) ECMA_BIGINT_GET_DIGITS (result_p, 0); + memset (data_p, 0, zero_size); + memcpy (data_p + zero_size, digits, digits_size); + + if (number < 0) + { + result_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_number_to_bigint */ + +/** + * Convert a value to BigInt value + * + * See also: + * ECMA-262 v11, 7.1.13 + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_to_bigint (ecma_value_t value, /**< any value */ + bool allow_numbers) /**< converting ecma numbers is allowed */ +{ + bool free_value = false; + + if (ecma_is_value_object (value)) + { + value = ecma_op_object_default_value (ecma_get_object_from_value (value), ECMA_PREFERRED_TYPE_NUMBER); + free_value = true; + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + } + + ecma_value_t result; + + if (ecma_is_value_string (value)) + { + result = ecma_bigint_parse_string_value (value, ECMA_BIGINT_PARSE_NO_OPTIONS); + } + else if (ecma_is_value_bigint (value)) + { + result = value; + + if (!free_value && value != ECMA_BIGINT_ZERO) + { + ecma_ref_extended_primitive (ecma_get_extended_primitive_from_value (value)); + } + else + { + free_value = false; + } + } + else if (allow_numbers && ecma_is_value_number (value)) + { + result = ecma_bigint_number_to_bigint (ecma_get_number_from_value (value)); + } + else if (ecma_is_value_false (value)) + { + result = ECMA_BIGINT_ZERO; + } + else if (ecma_is_value_true (value)) + { + result = ecma_bigint_create_from_digit (1, false); + } + else + { + result = ecma_raise_type_error (ECMA_ERR_VALUE_CANNOT_BE_CONVERTED_TO_BIGINT); + } + + if (free_value) + { + ecma_free_value (value); + } + + return result; +} /* ecma_bigint_to_bigint */ + +/** + * Convert a BigInt value to number value + * + * @return ecma number value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_to_number (ecma_value_t value) /**< BigInt value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (value)); + + if (value == ECMA_BIGINT_ZERO) + { + return ecma_make_integer_value (0); + } + + ecma_extended_primitive_t *value_p = ecma_get_extended_primitive_from_value (value); + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + ecma_bigint_digit_t *digits_p = ECMA_BIGINT_GET_DIGITS (value_p, size); + + if (size == sizeof (ecma_bigint_digit_t)) + { + if (!(value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + if (digits_p[-1] <= ECMA_INTEGER_NUMBER_MAX) + { + return ecma_make_integer_value ((ecma_integer_value_t) digits_p[-1]); + } + } + else if (digits_p[-1] <= -ECMA_INTEGER_NUMBER_MIN) + { + return ecma_make_integer_value (-(ecma_integer_value_t) digits_p[-1]); + } + } + + uint64_t fraction = 0; + ecma_bigint_digit_t shift_left; + + if (digits_p[-1] == 1) + { + JERRY_ASSERT (size > sizeof (ecma_bigint_digit_t)); + + fraction = ((uint64_t) digits_p[-2]) << (8 * sizeof (ecma_bigint_digit_t)); + shift_left = (uint32_t) (8 * sizeof (ecma_bigint_digit_t)); + + if (size >= 3 * sizeof (ecma_bigint_digit_t)) + { + fraction |= (uint64_t) digits_p[-3]; + } + } + else + { + shift_left = ecma_big_uint_count_leading_zero (digits_p[-1]) + 1; + + fraction = ((uint64_t) digits_p[-1]) << (8 * sizeof (ecma_bigint_digit_t) + shift_left); + + if (size >= 2 * sizeof (ecma_bigint_digit_t)) + { + fraction |= ((uint64_t) digits_p[-2]) << shift_left; + } + + if (size >= 3 * sizeof (ecma_bigint_digit_t)) + { + fraction |= ((uint64_t) digits_p[-3]) >> (8 * sizeof (ecma_bigint_digit_t) - shift_left); + } + } + + uint32_t biased_exp = (uint32_t) (((1 << (ECMA_NUMBER_BIASED_EXP_WIDTH - 1)) - 1) + (size * 8 - shift_left)); + + /* Rounding result. */ + const uint64_t rounding_bit = (((uint64_t) 1) << (8 * sizeof (uint64_t) - ECMA_NUMBER_FRACTION_WIDTH - 1)); + bool round_up = false; + + if (fraction & rounding_bit) + { + round_up = true; + + /* IEEE_754 roundTiesToEven mode: when rounding_bit is set, and all the remaining bits + * are zero, the number needs to be rounded down the bit before rounding_bit is zero. */ + if ((fraction & ((rounding_bit << 2) - 1)) == rounding_bit) + { + round_up = false; + + if ((size >= (3 * sizeof (ecma_bigint_digit_t))) + && (shift_left == (8 * sizeof (ecma_bigint_digit_t)) + || (digits_p[-3] & ((((ecma_bigint_digit_t) 1) << shift_left) - 1)) == 0)) + { + ecma_bigint_digit_t *digits_start_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + + digits_p -= 3; + + while (digits_p > digits_start_p) + { + if (digits_p[-1] != 0) + { + round_up = true; + break; + } + digits_p--; + } + } + } + } + + if (round_up) + { + fraction += rounding_bit; + fraction >>= (8 * sizeof (uint64_t) - ECMA_NUMBER_FRACTION_WIDTH); + + if (fraction == 0) + { + biased_exp++; + } + } + else + { + fraction >>= (8 * sizeof (uint64_t) - ECMA_NUMBER_FRACTION_WIDTH); + } + + bool sign = (value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN); + ecma_number_t result; + + if (biased_exp < (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1) + { + result = ecma_number_create (sign, biased_exp, fraction); + } + else + { + result = ecma_number_make_infinity (sign); + } + + return ecma_make_number_value (result); +} /* ecma_bigint_to_number */ + +/** + * Returns with a BigInt if the value is BigInt, + * or the value is object, and its default value is BigInt + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_get_bigint (ecma_value_t value, /**< any value */ + bool *free_result_p) /**< [out] result should be freed */ +{ + *free_result_p = false; + + if (ecma_is_value_bigint (value)) + { + return value; + } + + if (ecma_is_value_object (value)) + { + ecma_object_t *object_p = ecma_get_object_from_value (value); + ecma_value_t default_value = ecma_op_object_default_value (object_p, ECMA_PREFERRED_TYPE_NUMBER); + + if (ECMA_IS_VALUE_ERROR (default_value)) + { + return default_value; + } + + if (ecma_is_value_bigint (default_value)) + { + *free_result_p = (default_value != ECMA_BIGINT_ZERO); + return default_value; + } + + ecma_free_value (default_value); + } + + return ecma_raise_type_error (ECMA_ERR_CONVERT_BIGINT_TO_NUMBER); +} /* ecma_bigint_get_bigint */ + +/** + * Create BigInt value from uint64 digits + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_create_from_digits (const uint64_t *digits_p, /**< BigInt digits */ + uint32_t size, /**< number of BigInt digits */ + bool sign) /**< sign bit, true if the result should be negative */ +{ + const uint64_t *digits_end_p = digits_p + size; + + while (digits_end_p > digits_p && digits_end_p[-1] == 0) + { + digits_end_p--; + } + + if (digits_p == digits_end_p) + { + return ECMA_BIGINT_ZERO; + } + + size = (uint32_t) (digits_end_p - digits_p); + + if (size < ECMA_BIGINT_MAX_SIZE) + { + size *= (uint32_t) sizeof (uint64_t); + } + + if ((digits_end_p[-1] >> (8 * sizeof (ecma_bigint_digit_t))) == 0) + { + size -= (uint32_t) sizeof (ecma_bigint_digit_t); + } + + ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size); + + if (JERRY_UNLIKELY (result_value_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + if (sign) + { + result_value_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + + ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0); + + while (digits_p < digits_end_p) + { + uint64_t digit = *digits_p++; + + result_p[0] = (ecma_bigint_digit_t) digit; + result_p[1] = (ecma_bigint_digit_t) (digit >> (8 * sizeof (ecma_bigint_digit_t))); + result_p += 2; + } + + return ecma_make_extended_primitive_value (result_value_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_create_from_digits */ + +/** + * Get the number of uint64 digits of a BigInt value + * + * @return number of uint64 digits + */ +uint32_t +ecma_bigint_get_size_in_digits (ecma_value_t value) /**< BigInt value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (value)); + + if (value == ECMA_BIGINT_ZERO) + { + return 0; + } + + ecma_extended_primitive_t *value_p = ecma_get_extended_primitive_from_value (value); + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + return (size + (uint32_t) sizeof (ecma_bigint_digit_t)) / sizeof (uint64_t); +} /* ecma_bigint_get_size_in_digits */ + +/** + * Get the uint64 digits of a BigInt value + */ +void +ecma_bigint_get_digits_and_sign (ecma_value_t value, /**< BigInt value */ + uint64_t *digits_p, /**< [out] buffer for digits */ + uint32_t size, /**< buffer size in digits */ + bool *sign_p) /**< [out] sign of BigInt */ +{ + JERRY_ASSERT (ecma_is_value_bigint (value)); + + if (value == ECMA_BIGINT_ZERO) + { + if (sign_p != NULL) + { + *sign_p = false; + } + memset (digits_p, 0, size * sizeof (uint64_t)); + return; + } + + ecma_extended_primitive_t *value_p = ecma_get_extended_primitive_from_value (value); + + if (sign_p != NULL) + { + *sign_p = (value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) != 0; + } + + uint32_t bigint_size = ECMA_BIGINT_GET_SIZE (value_p); + uint32_t copy_size = bigint_size / sizeof (uint64_t); + + if (copy_size > size) + { + copy_size = size; + } + + const uint64_t *digits_end_p = digits_p + copy_size; + ecma_bigint_digit_t *source_p = ECMA_BIGINT_GET_DIGITS (value_p, 0); + + while (digits_p < digits_end_p) + { + *digits_p++ = source_p[0] | (((uint64_t) source_p[1]) << (8 * sizeof (ecma_bigint_digit_t))); + source_p += 2; + } + + size -= copy_size; + + if (size == 0) + { + return; + } + + if (ECMA_BIGINT_SIZE_IS_ODD (bigint_size)) + { + *digits_p++ = source_p[0]; + size--; + } + + if (size > 0) + { + memset (digits_p, 0, size * sizeof (uint64_t)); + } +} /* ecma_bigint_get_digits_and_sign */ + +/** + * Compare two BigInt values + * + * @return true if they are the same, false otherwise + */ +bool +ecma_bigint_is_equal_to_bigint (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (left_value == ECMA_BIGINT_ZERO) + { + return right_value == ECMA_BIGINT_ZERO; + } + else if (right_value == ECMA_BIGINT_ZERO) + { + return false; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (left_p->u.bigint_sign_and_size != right_p->u.bigint_sign_and_size) + { + return false; + } + + uint32_t size = ECMA_BIGINT_GET_SIZE (left_p); + return memcmp (ECMA_BIGINT_GET_DIGITS (left_p, 0), ECMA_BIGINT_GET_DIGITS (right_p, 0), size) == 0; +} /* ecma_bigint_is_equal_to_bigint */ + +/** + * Compare a BigInt value and a number + * + * @return true if they are the same, false otherwise + */ +bool +ecma_bigint_is_equal_to_number (ecma_value_t left_value, /**< left BigInt value */ + ecma_number_t right_value) /**< right number value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value)); + + if (ecma_number_is_nan (right_value) || ecma_number_is_infinity (right_value)) + { + return false; + } + + if (left_value == ECMA_BIGINT_ZERO) + { + return right_value == 0; + } + + ecma_extended_primitive_t *left_value_p = ecma_get_extended_primitive_from_value (left_value); + + /* Sign must be the same. */ + if (left_value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + if (right_value > 0) + { + return false; + } + } + else if (right_value < 0) + { + return false; + } + + ecma_bigint_digit_t digits[3]; + uint32_t result = ecma_bigint_number_to_digits (right_value, digits); + + JERRY_ASSERT (ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) == 0 + || digits[ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) - 1] > 0); + + if (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION) + { + return false; + } + + uint32_t digits_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS_SIZE (result); + uint32_t zero_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_ZERO_SIZE (result); + + if (ECMA_BIGINT_GET_SIZE (left_value_p) != digits_size + zero_size) + { + return false; + } + + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + ecma_bigint_digit_t *left_end_p = (ecma_bigint_digit_t *) (((uint8_t *) left_p) + zero_size); + + /* Check value bits first. */ + if (memcmp (left_end_p, digits, digits_size) != 0) + { + return false; + } + + while (left_p < left_end_p) + { + if (*left_p++ != 0) + { + return false; + } + } + + return true; +} /* ecma_bigint_is_equal_to_number */ + +/** + * Convert 0 to 1, and 1 to -1. Useful for getting sign. + */ +#define ECMA_BIGINT_TO_SIGN(value) (1 - (((int) (value)) << 1)) + +/** + * Convert 0 to -1, and 1 to 1. Useful for getting negated sign. + */ +#define ECMA_BIGINT_TO_NEGATED_SIGN(value) (-1 + (((int) (value)) << 1)) + +/** + * Compare two BigInt values + * + * return -1, if left value < right value, 0 if they are equal, 1 otherwise + */ +int +ecma_bigint_compare_to_bigint (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (left_value == ECMA_BIGINT_ZERO) + { + if (right_value == ECMA_BIGINT_ZERO) + { + return 0; + } + + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + return ECMA_BIGINT_TO_NEGATED_SIGN (right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN); + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + uint32_t left_sign = left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + + if (right_value == ECMA_BIGINT_ZERO) + { + return ECMA_BIGINT_TO_SIGN (left_sign); + } + + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + uint32_t right_sign = right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + + if ((left_sign ^ right_sign) != 0) + { + return ECMA_BIGINT_TO_SIGN (left_sign); + } + + if (left_sign == 0) + { + return ecma_big_uint_compare (left_p, right_p); + } + + return -ecma_big_uint_compare (left_p, right_p); +} /* ecma_bigint_compare_to_bigint */ + +/** + * Compare a BigInt value and a number + * + * return -1, if left value < right value, 0 if they are equal, 1 otherwise + */ +int +ecma_bigint_compare_to_number (ecma_value_t left_value, /**< left BigInt value */ + ecma_number_t right_value) /**< right number value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value)); + JERRY_ASSERT (!ecma_number_is_nan (right_value)); + + int right_invert_sign = ECMA_BIGINT_TO_SIGN (right_value > 0); + + if (left_value == ECMA_BIGINT_ZERO) + { + if (right_value == 0) + { + return 0; + } + + return right_invert_sign; + } + + ecma_extended_primitive_t *left_value_p = ecma_get_extended_primitive_from_value (left_value); + int left_sign = ECMA_BIGINT_TO_SIGN (left_value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN); + + if (right_value == 0 || left_sign == right_invert_sign) + { + /* Second condition: a positive BigInt is always greater than any negative number, and the opposite is true. */ + return left_sign; + } + + if (ecma_number_is_infinity (right_value)) + { + /* Infinity is always bigger than any BigInt number. */ + return right_invert_sign; + } + + ecma_bigint_digit_t digits[3]; + uint32_t result = ecma_bigint_number_to_digits (right_value, digits); + + JERRY_ASSERT (ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) == 0 + || digits[ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) - 1] > 0); + + uint32_t digits_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS_SIZE (result); + + if (digits_size == 0) + { + JERRY_ASSERT (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION); + /* The number is between [-1 .. 1] exclusive. */ + return left_sign; + } + + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p); + uint32_t right_size = digits_size + ECMA_BIGINT_NUMBER_TO_DIGITS_GET_ZERO_SIZE (result); + + if (left_size != right_size) + { + return left_size > right_size ? left_sign : -left_sign; + } + + ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, right_size); + ecma_bigint_digit_t *left_end_p = (ecma_bigint_digit_t *) (((uint8_t *) left_p) - digits_size); + ecma_bigint_digit_t *digits_p = (ecma_bigint_digit_t *) (((uint8_t *) digits) + digits_size); + + do + { + ecma_bigint_digit_t left = *(--left_p); + ecma_bigint_digit_t right = *(--digits_p); + + if (left != right) + { + return left > right ? left_sign : -left_sign; + } + } while (left_p > left_end_p); + + left_end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0); + + while (left_p > left_end_p) + { + if (*(--left_p) != 0) + { + return left_sign; + } + } + + return (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION) ? -left_sign : 0; +} /* ecma_bigint_compare_to_number */ + +#undef ECMA_BIGINT_TO_SIGN + +/** + * Negate a non-zero BigInt value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_negate (ecma_extended_primitive_t *value_p) /**< BigInt value */ +{ + uint32_t size = ECMA_BIGINT_GET_SIZE (value_p); + + JERRY_ASSERT (size > 0 && ECMA_BIGINT_GET_LAST_DIGIT (value_p, size) != 0); + + ecma_extended_primitive_t *result_p = ecma_bigint_create (size); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + memcpy (result_p + 1, value_p + 1, size); + result_p->refs_and_type = ECMA_EXTENDED_PRIMITIVE_REF_ONE | ECMA_TYPE_BIGINT; + result_p->u.bigint_sign_and_size = value_p->u.bigint_sign_and_size ^ ECMA_BIGINT_SIGN; + + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_negate */ + +/** + * Invert all bits of a BigInt value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_unary (ecma_value_t value, /**< BigInt value */ + ecma_bigint_unary_operation_type type) /**< type of unary operation */ +{ + JERRY_ASSERT (ecma_is_value_bigint (value)); + + if (value == ECMA_BIGINT_ZERO) + { + return ecma_bigint_create_from_digit (1, type != ECMA_BIGINT_UNARY_INCREASE); + } + + ecma_extended_primitive_t *value_p = ecma_get_extended_primitive_from_value (value); + + uint32_t sign = (type != ECMA_BIGINT_UNARY_DECREASE) ? ECMA_BIGINT_SIGN : 0; + + if ((value_p->u.bigint_sign_and_size == (uint32_t) (sizeof (ecma_bigint_digit_t) | sign)) + && *ECMA_BIGINT_GET_DIGITS (value_p, 0) == 1) + { + return ECMA_BIGINT_ZERO; + } + + ecma_extended_primitive_t *result_p; + + if ((value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) == (sign ^ ECMA_BIGINT_SIGN)) + { + result_p = ecma_big_uint_increase (value_p); + + if (type != ECMA_BIGINT_UNARY_INCREASE && result_p != NULL) + { + result_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + } + else + { + result_p = ecma_big_uint_decrease (value_p); + + if (type == ECMA_BIGINT_UNARY_INCREASE && result_p != NULL) + { + result_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + } + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_unary */ + +/** + * Add/subtract right BigInt value to/from left BigInt value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_add_sub (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value, /**< right BigInt value */ + bool is_add) /**< true if add operation should be performed */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (right_value == ECMA_BIGINT_ZERO) + { + return ecma_copy_value (left_value); + } + + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (left_value == ECMA_BIGINT_ZERO) + { + if (!is_add) + { + return ecma_bigint_negate (right_p); + } + + ecma_ref_extended_primitive (right_p); + return right_value; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + uint32_t sign = is_add ? 0 : ECMA_BIGINT_SIGN; + + if (((left_p->u.bigint_sign_and_size ^ right_p->u.bigint_sign_and_size) & ECMA_BIGINT_SIGN) == sign) + { + ecma_extended_primitive_t *result_p = ecma_big_uint_add (left_p, right_p); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + result_p->u.bigint_sign_and_size |= left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); + } + + int compare_result = ecma_big_uint_compare (left_p, right_p); + ecma_extended_primitive_t *result_p; + + if (compare_result == 0) + { + return ECMA_BIGINT_ZERO; + } + + if (compare_result > 0) + { + sign = left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + result_p = ecma_big_uint_sub (left_p, right_p); + } + else + { + sign = right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + + if (!is_add) + { + sign ^= ECMA_BIGINT_SIGN; + } + + result_p = ecma_big_uint_sub (right_p, left_p); + } + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + result_p->u.bigint_sign_and_size |= sign; + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_add_sub */ + +/** + * Multiply two BigInt values + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_mul (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (left_value == ECMA_BIGINT_ZERO || right_value == ECMA_BIGINT_ZERO) + { + return ECMA_BIGINT_ZERO; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_p); + uint32_t right_size = ECMA_BIGINT_GET_SIZE (right_p); + + if (left_size == sizeof (ecma_bigint_digit_t) + && ECMA_BIGINT_GET_LAST_DIGIT (left_p, sizeof (ecma_bigint_digit_t)) == 1) + { + if (left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + return ecma_bigint_negate (right_p); + } + + ecma_ref_extended_primitive (right_p); + return right_value; + } + + if (right_size == sizeof (ecma_bigint_digit_t) + && ECMA_BIGINT_GET_LAST_DIGIT (right_p, sizeof (ecma_bigint_digit_t)) == 1) + { + if (right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + return ecma_bigint_negate (left_p); + } + + ecma_ref_extended_primitive (left_p); + return left_value; + } + + ecma_extended_primitive_t *result_p = ecma_big_uint_mul (left_p, right_p); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + uint32_t sign = (left_p->u.bigint_sign_and_size ^ right_p->u.bigint_sign_and_size) & ECMA_BIGINT_SIGN; + result_p->u.bigint_sign_and_size |= sign; + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_mul */ + +/** + * Divide two BigInt values + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_div_mod (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value, /**< right BigInt value */ + bool is_mod) /**< true if return with remainder */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (right_value == ECMA_BIGINT_ZERO) + { + return ecma_raise_range_error (ECMA_ERR_BIGINT_ZERO_DIVISION); + } + + if (left_value == ECMA_BIGINT_ZERO) + { + return left_value; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + int compare_result = ecma_big_uint_compare (left_p, right_p); + ecma_extended_primitive_t *result_p; + + if (compare_result < 0) + { + if (!is_mod) + { + return ECMA_BIGINT_ZERO; + } + + ecma_ref_extended_primitive (left_p); + return left_value; + } + else if (compare_result == 0) + { + if (is_mod) + { + return ECMA_BIGINT_ZERO; + } + + result_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t)); + + if (result_p != NULL) + { + *ECMA_BIGINT_GET_DIGITS (result_p, 0) = 1; + } + } + else + { + result_p = ecma_big_uint_div_mod (left_p, right_p, is_mod); + + if (result_p == ECMA_BIGINT_POINTER_TO_ZERO) + { + return ECMA_BIGINT_ZERO; + } + } + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + if (is_mod) + { + result_p->u.bigint_sign_and_size |= left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + } + else + { + uint32_t sign = (left_p->u.bigint_sign_and_size ^ right_p->u.bigint_sign_and_size) & ECMA_BIGINT_SIGN; + result_p->u.bigint_sign_and_size |= sign; + } + + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_div_mod */ + +/** + * Shift left BigInt value to left or right + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_shift (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value, /**< right BigInt value */ + bool is_left) /**< true if left shift operation should be performed */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (left_value == ECMA_BIGINT_ZERO) + { + return ECMA_BIGINT_ZERO; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + + if (right_value == ECMA_BIGINT_ZERO) + { + ecma_ref_extended_primitive (left_p); + return left_value; + } + + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + is_left = !is_left; + } + + if (ECMA_BIGINT_GET_SIZE (right_p) > sizeof (ecma_bigint_digit_t)) + { + if (is_left) + { + return ecma_bigint_raise_memory_error (); + } + else if (left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + /* Shifting a negative value with a very big number to the right should be -1. */ + return ecma_bigint_create_from_digit (1, true); + } + + return ECMA_BIGINT_ZERO; + } + + ecma_extended_primitive_t *result_p; + ecma_bigint_digit_t shift = ECMA_BIGINT_GET_LAST_DIGIT (right_p, sizeof (ecma_bigint_digit_t)); + uint32_t left_sign = left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN; + + if (is_left) + { + result_p = ecma_big_uint_shift_left (left_p, shift); + } + else + { + /* -x >> y == ~(x - 1) >> y == ~((x - 1) >> y) == -(((x - 1) >> y) + 1) + * When a non-zero bit is shifted out: (x - 1) >> y == x >> y, so the formula is -((x >> y) + 1) + * When only zero bits are shifted out: (((x - 1) >> y) + 1) == x >> y so the formula is: -(x >> y) */ + result_p = ecma_big_uint_shift_right (left_p, shift, left_sign != 0); + + if (result_p == ECMA_BIGINT_POINTER_TO_ZERO) + { + return ECMA_BIGINT_ZERO; + } + } + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + result_p->u.bigint_sign_and_size |= left_sign; + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_shift */ + +/** + * Compute the left value raised to the power of right value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_pow (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value)); + + if (right_value == ECMA_BIGINT_ZERO) + { + return ecma_bigint_create_from_digit (1, false); + } + + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + return ecma_raise_range_error (ECMA_ERR_NEGATIVE_EXPONENT_IS_NOT_ALLOWED_FOR_BIGINTS); + } + + if (left_value == ECMA_BIGINT_ZERO) + { + return ECMA_BIGINT_ZERO; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_bigint_digit_t base = 0; + + if (ECMA_BIGINT_GET_SIZE (left_p) == sizeof (ecma_bigint_digit_t)) + { + base = *ECMA_BIGINT_GET_DIGITS (left_p, 0); + + JERRY_ASSERT (base != 0); + + if (base == 1) + { + if (!(left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + || ECMA_BIGINT_NUMBER_IS_ODD (*ECMA_BIGINT_GET_DIGITS (right_p, 0))) + { + ecma_ref_extended_primitive (left_p); + return left_value; + } + + return ecma_bigint_create_from_digit (1, false); + } + } + + if (JERRY_UNLIKELY (ECMA_BIGINT_GET_SIZE (right_p) > sizeof (ecma_bigint_digit_t))) + { + return ecma_bigint_raise_memory_error (); + } + + ecma_bigint_digit_t power = *ECMA_BIGINT_GET_DIGITS (right_p, 0); + + if (power == 1) + { + ecma_ref_extended_primitive (left_p); + return left_value; + } + + ecma_extended_primitive_t *result_p; + + if (base == 2) + { + result_p = ecma_big_uint_shift_left (left_p, power - 1); + } + else + { + result_p = ecma_big_uint_pow (left_p, power); + } + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + if ((left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) && ECMA_BIGINT_NUMBER_IS_ODD (power)) + { + result_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_pow */ + +/** + * Convert the result to an ecma value + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_bigint_bitwise_op (uint32_t operation_and_options, /**< bitwise operation type and options */ + ecma_extended_primitive_t *left_value_p, /**< left BigInt value */ + ecma_extended_primitive_t *right_value_p) /**< right BigInt value */ +{ + ecma_extended_primitive_t *result_p; + result_p = ecma_big_uint_bitwise_op (operation_and_options, left_value_p, right_value_p); + + if (JERRY_UNLIKELY (result_p == NULL)) + { + return ecma_bigint_raise_memory_error (); + } + + if (result_p == ECMA_BIGINT_POINTER_TO_ZERO) + { + return ECMA_BIGINT_ZERO; + } + + if (operation_and_options & ECMA_BIG_UINT_BITWISE_INCREASE_RESULT) + { + result_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN; + } + + return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT); +} /* ecma_bigint_bitwise_op */ + +/** + * Perform bitwise 'and' operations on two BigUInt numbers + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_and (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + if (left_value == ECMA_BIGINT_ZERO || right_value == ECMA_BIGINT_ZERO) + { + return ECMA_BIGINT_ZERO; + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (!(left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + return ecma_bigint_bitwise_op (ECMA_BIG_UINT_BITWISE_AND, left_p, right_p); + } + + /* x & (-y) == x & ~(y-1) == x &~ (y-1) */ + uint32_t operation_and_options = ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT; + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); + } + + if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + /* (-x) & y == ~(x-1) & y == y &~ (x-1) */ + uint32_t operation_and_options = ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT; + return ecma_bigint_bitwise_op (operation_and_options, right_p, left_p); + } + + /* (-x) & (-y) == ~(x-1) & ~(y-1) == ~((x-1) | (y-1)) == -(((x-1) | (y-1)) + 1) */ + uint32_t operation_and_options = + (ECMA_BIG_UINT_BITWISE_OR | ECMA_BIG_UINT_BITWISE_DECREASE_BOTH | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT); + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); +} /* ecma_bigint_and */ + +/** + * Perform bitwise 'or' operations on two BigUInt numbers + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_or (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + if (left_value == ECMA_BIGINT_ZERO) + { + return ecma_copy_value (right_value); + } + + if (right_value == ECMA_BIGINT_ZERO) + { + return ecma_copy_value (left_value); + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (!(left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + return ecma_bigint_bitwise_op (ECMA_BIG_UINT_BITWISE_OR, left_p, right_p); + } + + /* x | (-y) == x | ~(y-1) == ~((y-1) &~ x) == -(((y-1) &~ x) + 1) */ + uint32_t operation_and_options = + (ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT); + return ecma_bigint_bitwise_op (operation_and_options, right_p, left_p); + } + + if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + /* (-x) | y == ~(x-1) | y == ~((x-1) &~ y) == -(((x-1) &~ y) + 1) */ + uint32_t operation_and_options = + (ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT); + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); + } + + /* (-x) | (-y) == ~(x-1) | ~(y-1) == ~((x-1) & (y-1)) = -(((x-1) & (y-1)) + 1) */ + uint32_t operation_and_options = + (ECMA_BIG_UINT_BITWISE_AND | ECMA_BIG_UINT_BITWISE_DECREASE_BOTH | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT); + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); +} /* ecma_bigint_or */ + +/** + * Perform bitwise 'xor' operations on two BigUInt numbers + * + * @return ecma BigInt value or ECMA_VALUE_ERROR + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_bigint_xor (ecma_value_t left_value, /**< left BigInt value */ + ecma_value_t right_value) /**< right BigInt value */ +{ + if (left_value == ECMA_BIGINT_ZERO) + { + return ecma_copy_value (right_value); + } + + if (right_value == ECMA_BIGINT_ZERO) + { + return ecma_copy_value (left_value); + } + + ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value); + ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value); + + if (!(left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + return ecma_bigint_bitwise_op (ECMA_BIG_UINT_BITWISE_XOR, left_p, right_p); + } + + /* x ^ (-y) == x ^ ~(y-1) == ~(x ^ (y-1)) == -((x ^ (y-1)) + 1) */ + uint32_t operation_and_options = + (ECMA_BIG_UINT_BITWISE_XOR | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT); + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); + } + + if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)) + { + /* (-x) | y == ~(x-1) ^ y == ~((x-1) ^ y) == -(((x-1) ^ y) + 1) */ + uint32_t operation_and_options = + (ECMA_BIG_UINT_BITWISE_XOR | ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT); + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); + } + + /* (-x) ^ (-y) == ~(x-1) ^ ~(y-1) == (x-1) ^ (y-1) */ + uint32_t operation_and_options = ECMA_BIG_UINT_BITWISE_XOR | ECMA_BIG_UINT_BITWISE_DECREASE_BOTH; + return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p); +} /* ecma_bigint_xor */ + +#endif /* JERRY_BUILTIN_BIGINT */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint.h new file mode 100644 index 0000000..460ed76 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-bigint.h @@ -0,0 +1,81 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BIG_INT_H +#define ECMA_BIG_INT_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_BIGINT + +/** + * Sign bit of a BigInt value. The number is negative, if this bit is set. + */ +#define ECMA_BIGINT_SIGN 0x1 + +/** + * Flags for ecma_bigint_parse_string. + */ +typedef enum +{ + ECMA_BIGINT_PARSE_NO_OPTIONS = 0, /**< no options */ + ECMA_BIGINT_PARSE_SET_NEGATIVE = (1 << 0), /**< return with a negative BigInt value */ + ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR = (1 << 1), /**< don't throw SyntaxError, + * return with ECMA_VALUE_FALSE */ + ECMA_BIGINT_PARSE_DISALLOW_MEMORY_ERROR = (1 << 2), /**< don't throw out-of-memory error, + * return with ECMA_VALUE_NULL instead */ + ECMA_BIGINT_PARSE_ALLOW_UNDERSCORE = (1 << 3), /** allow parse underscore characters */ +} ecma_bigint_parse_string_options_t; + +/** + * Types for unary operations + */ +typedef enum +{ + ECMA_BIGINT_UNARY_BITWISE_NOT, /**< bitwise not operation */ + ECMA_BIGINT_UNARY_INCREASE, /**< increase operation */ + ECMA_BIGINT_UNARY_DECREASE, /**< decrease operation */ +} ecma_bigint_unary_operation_type; + +ecma_value_t ecma_bigint_parse_string (const lit_utf8_byte_t *string_p, lit_utf8_size_t size, uint32_t options); +ecma_value_t ecma_bigint_parse_string_value (ecma_value_t string, uint32_t options); +ecma_string_t *ecma_bigint_to_string (ecma_value_t value, ecma_bigint_digit_t radix); +ecma_value_t ecma_bigint_to_bigint (ecma_value_t value, bool allow_numbers); +ecma_value_t ecma_bigint_to_number (ecma_value_t value); +ecma_value_t ecma_bigint_get_bigint (ecma_value_t value, bool *free_result_p); +ecma_value_t ecma_bigint_create_from_digits (const uint64_t *digits_p, uint32_t size, bool sign); +uint32_t ecma_bigint_get_size_in_digits (ecma_value_t value); +void ecma_bigint_get_digits_and_sign (ecma_value_t value, uint64_t *digits_p, uint32_t size, bool *sign_p); + +bool ecma_bigint_is_equal_to_bigint (ecma_value_t left_value, ecma_value_t right_value); +bool ecma_bigint_is_equal_to_number (ecma_value_t left_value, ecma_number_t right_value); +int ecma_bigint_compare_to_bigint (ecma_value_t left_value, ecma_value_t right_value); +int ecma_bigint_compare_to_number (ecma_value_t left_value, ecma_number_t right_value); + +ecma_value_t ecma_bigint_negate (ecma_extended_primitive_t *value_p); +ecma_value_t ecma_bigint_unary (ecma_value_t value, ecma_bigint_unary_operation_type type); +ecma_value_t ecma_bigint_add_sub (ecma_value_t left_value, ecma_value_t right_value, bool is_add); +ecma_value_t ecma_bigint_mul (ecma_value_t left_value, ecma_value_t right_value); +ecma_value_t ecma_bigint_div_mod (ecma_value_t left_value, ecma_value_t right_value, bool is_mod); +ecma_value_t ecma_bigint_shift (ecma_value_t left_value, ecma_value_t right_value, bool is_left); +ecma_value_t ecma_bigint_pow (ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t ecma_bigint_and (ecma_value_t left_value, ecma_value_t right_value); +ecma_value_t ecma_bigint_or (ecma_value_t left_value, ecma_value_t right_value); +ecma_value_t ecma_bigint_xor (ecma_value_t left_value, ecma_value_t right_value); + +#endif /* JERRY_BUILTIN_BIGINT */ + +#endif /* ECMA_BIG_INT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-boolean-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-boolean-object.cpp new file mode 100644 index 0000000..956aa4a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-boolean-object.cpp @@ -0,0 +1,88 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-boolean-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabooleanobject ECMA Boolean object related routines + * @{ + */ + +/** + * Boolean object creation operation. + * + * See also: ECMA-262 v5, 15.6.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_boolean_object (ecma_value_t arg) /**< argument passed to the Boolean constructor */ +{ + bool boolean_value = ecma_op_to_boolean (arg); + ecma_builtin_id_t proto_id; + +#if JERRY_BUILTIN_BOOLEAN + proto_id = ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE; +#else /* JERRY_BUILTIN_BOOLEAN */ + proto_id = ECMA_BUILTIN_ID_OBJECT_PROTOTYPE; +#endif /* !(JERRY_BUILTIN_BOOLEAN */ + + ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id); + + ecma_object_t *new_target = JERRY_CONTEXT (current_new_target_p); + if (new_target) + { + prototype_obj_p = ecma_op_get_prototype_from_constructor (new_target, proto_id); + + if (JERRY_UNLIKELY (prototype_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + } + + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_BOOLEAN; + ext_object_p->u.cls.u3.value = ecma_make_boolean_value (boolean_value); + + if (new_target) + { + ecma_deref_object (prototype_obj_p); + } + + return ecma_make_object_value (object_p); +} /* ecma_op_create_boolean_object */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-boolean-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-boolean-object.h new file mode 100644 index 0000000..adf0353 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-boolean-object.h @@ -0,0 +1,35 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_BOOLEAN_OBJECT_H +#define ECMA_BOOLEAN_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabooleanobject ECMA Boolean object related routines + * @{ + */ + +ecma_value_t ecma_op_create_boolean_object (ecma_value_t arg); + +/** + * @} + * @} + */ + +#endif /* !ECMA_BOOLEAN_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-comparison.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-comparison.cpp new file mode 100644 index 0000000..5a32a2c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-comparison.cpp @@ -0,0 +1,536 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-comparison.h" + +#include "ecma-bigint.h" +#include "ecma-conversion.h" +#include "ecma-globals.h" +#include "ecma-objects.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmacomparison ECMA comparison + * @{ + */ + +/** + * ECMA abstract equality comparison routine. + * + * See also: ECMA-262 v5, 11.9.3 + * + * Note: + * This function might raise an exception, so the + * returned value must be freed with ecma_free_value. + * + * @return true - if values are equal, + * false - otherwise + * error - in case of any problems + */ +ecma_value_t +ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */ + ecma_value_t y) /**< second operand */ +{ + if (x == y) + { + return ECMA_VALUE_TRUE; + } + + if (ecma_are_values_integer_numbers (x, y)) + { + /* Note: the (x == y) comparison captures the true case. */ + return ECMA_VALUE_FALSE; + } + + if (ecma_is_value_number (x)) + { + if (ecma_is_value_number (y)) + { + /* 1.c */ + ecma_number_t x_num = ecma_get_number_from_value (x); + ecma_number_t y_num = ecma_get_number_from_value (y); + + bool is_x_equal_to_y = (x_num == y_num); + +#ifndef JERRY_NDEBUG + bool is_x_equal_to_y_check; + + if (ecma_number_is_nan (x_num) || ecma_number_is_nan (y_num)) + { + is_x_equal_to_y_check = false; + } + else if (x_num == y_num || (ecma_number_is_zero (x_num) && ecma_number_is_zero (y_num))) + { + is_x_equal_to_y_check = true; + } + else + { + is_x_equal_to_y_check = false; + } + + JERRY_ASSERT (is_x_equal_to_y == is_x_equal_to_y_check); +#endif /* !JERRY_NDEBUG */ + + return ecma_make_boolean_value (is_x_equal_to_y); + } + + /* Swap values. */ + x ^= y; + y ^= x; + x ^= y; + } + + if (ecma_is_value_string (x)) + { + if (ecma_is_value_string (y)) + { + /* 1., d. */ + ecma_string_t *x_str_p = ecma_get_string_from_value (x); + ecma_string_t *y_str_p = ecma_get_string_from_value (y); + + bool is_equal = ecma_compare_ecma_strings (x_str_p, y_str_p); + + return ecma_make_boolean_value (is_equal); + } + + if (ecma_is_value_number (y)) + { + /* 4. */ + ecma_number_t num; + ecma_value_t x_num_value = ecma_op_to_number (x, &num); + + if (ECMA_IS_VALUE_ERROR (x_num_value)) + { + return x_num_value; + } + ecma_value_t num_value = ecma_make_number_value (num); + ecma_value_t compare_result = ecma_op_abstract_equality_compare (num_value, y); + + ecma_free_value (num_value); + return compare_result; + } + + /* Swap values. */ + x ^= y; + y ^= x; + x ^= y; + } + + if (ecma_is_value_boolean (y)) + { + if (ecma_is_value_boolean (x)) + { + /* 1., e. */ + /* Note: the (x == y) comparison captures the true case. */ + return ECMA_VALUE_FALSE; + } + + /* 7. */ + return ecma_op_abstract_equality_compare (x, ecma_make_integer_value (ecma_is_value_true (y) ? 1 : 0)); + } + + if (ecma_is_value_boolean (x)) + { + /* 6. */ + return ecma_op_abstract_equality_compare (ecma_make_integer_value (ecma_is_value_true (x) ? 1 : 0), y); + } + +#if JERRY_BUILTIN_BIGINT + if (JERRY_UNLIKELY (ecma_is_value_bigint (x))) + { + if (ecma_is_value_bigint (y)) + { + return ecma_make_boolean_value (ecma_bigint_is_equal_to_bigint (x, y)); + } + + if (ecma_is_value_string (y)) + { + ecma_value_t bigint = ecma_bigint_parse_string_value (y, ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR); + + if (ECMA_IS_VALUE_ERROR (bigint) || bigint == ECMA_VALUE_FALSE) + { + return bigint; + } + + JERRY_ASSERT (ecma_is_value_bigint (bigint)); + + ecma_value_t result = ecma_make_boolean_value (ecma_bigint_is_equal_to_bigint (x, bigint)); + + ecma_free_value (bigint); + return result; + } + + if (ecma_is_value_number (y)) + { + return ecma_make_boolean_value (ecma_bigint_is_equal_to_number (x, ecma_get_number_from_value (y))); + } + + /* Swap values. */ + x ^= y; + y ^= x; + x ^= y; + } +#endif /* JERRY_BUILTIN_BIGINT */ + + if (ecma_is_value_undefined (x) || ecma_is_value_null (x)) + { + /* 1. a., b. */ + /* 2., 3. */ + bool is_equal = ecma_is_value_undefined (y) || ecma_is_value_null (y); + + return ecma_make_boolean_value (is_equal); + } + + if (JERRY_UNLIKELY (ecma_is_value_symbol (x))) + { + if (!ecma_is_value_object (y)) + { + return ECMA_VALUE_FALSE; + } + + /* Swap values. */ + x ^= y; + y ^= x; + x ^= y; + } + + JERRY_ASSERT (ecma_is_value_object (x)); + + if (ecma_is_value_string (y) || ecma_is_value_symbol (y) +#if JERRY_BUILTIN_BIGINT + || ecma_is_value_bigint (y) +#endif /* JERRY_BUILTIN_BIGINT */ + || ecma_is_value_number (y)) + { + /* 9. */ + ecma_object_t *obj_p = ecma_get_object_from_value (x); + + ecma_value_t def_value = ecma_op_object_default_value (obj_p, ECMA_PREFERRED_TYPE_NO); + + if (ECMA_IS_VALUE_ERROR (def_value)) + { + return def_value; + } + + ecma_value_t compare_result = ecma_op_abstract_equality_compare (def_value, y); + + ecma_free_value (def_value); + + return compare_result; + } + + return ECMA_VALUE_FALSE; +} /* ecma_op_abstract_equality_compare */ + +/** + * ECMA strict equality comparison routine. + * + * See also: ECMA-262 v5, 11.9.6 + * + * @return true - if values are strict equal, + * false - otherwise + */ +bool +ecma_op_strict_equality_compare (ecma_value_t x, /**< first operand */ + ecma_value_t y) /**< second operand */ +{ + if (ecma_is_value_direct (x) || ecma_is_value_direct (y) || ecma_is_value_symbol (x) || ecma_is_value_symbol (y) + || ecma_is_value_object (x) || ecma_is_value_object (y)) + { + JERRY_ASSERT (!ecma_is_value_direct (x) || ecma_is_value_undefined (x) || ecma_is_value_null (x) + || ecma_is_value_boolean (x) || ecma_is_value_integer_number (x)); + + JERRY_ASSERT (!ecma_is_value_direct (y) || ecma_is_value_undefined (y) || ecma_is_value_null (y) + || ecma_is_value_boolean (y) || ecma_is_value_integer_number (y)); + + if ((x != ecma_make_integer_value (0) || !ecma_is_value_float_number (y)) + && (y != ecma_make_integer_value (0) || !ecma_is_value_float_number (x))) + { + return (x == y); + } + + /* The +0 === -0 case handled below. */ + } + + JERRY_ASSERT (ecma_is_value_number (x) || ecma_is_value_string (x) || ecma_is_value_bigint (x)); + JERRY_ASSERT (ecma_is_value_number (y) || ecma_is_value_string (y) || ecma_is_value_bigint (y)); + + if (ecma_is_value_string (x)) + { + if (!ecma_is_value_string (y)) + { + return false; + } + + ecma_string_t *x_str_p = ecma_get_string_from_value (x); + ecma_string_t *y_str_p = ecma_get_string_from_value (y); + + return ecma_compare_ecma_strings (x_str_p, y_str_p); + } + +#if JERRY_BUILTIN_BIGINT + if (JERRY_UNLIKELY (ecma_is_value_bigint (x))) + { + if (!ecma_is_value_bigint (y)) + { + return false; + } + + return ecma_bigint_is_equal_to_bigint (x, y); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + if (!ecma_is_value_number (y)) + { + return false; + } + + ecma_number_t x_num = ecma_get_number_from_value (x); + ecma_number_t y_num = ecma_get_number_from_value (y); + + bool is_x_equal_to_y = (x_num == y_num); + +#ifndef JERRY_NDEBUG + bool is_x_equal_to_y_check; + + if (ecma_number_is_nan (x_num) || ecma_number_is_nan (y_num)) + { + is_x_equal_to_y_check = false; + } + else if (x_num == y_num || (ecma_number_is_zero (x_num) && ecma_number_is_zero (y_num))) + { + is_x_equal_to_y_check = true; + } + else + { + is_x_equal_to_y_check = false; + } + + JERRY_ASSERT (is_x_equal_to_y == is_x_equal_to_y_check); +#endif /* !JERRY_NDEBUG */ + + return is_x_equal_to_y; +} /* ecma_op_strict_equality_compare */ + +/** + * ECMA abstract relational comparison routine. + * + * See also: ECMA-262 v5, 11.8.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_abstract_relational_compare (ecma_value_t x, /**< first operand */ + ecma_value_t y, /**< second operand */ + bool left_first) /**< 'LeftFirst' flag */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + /* 1., 2. */ + ecma_value_t prim_first_converted_value = ecma_op_to_primitive (x, ECMA_PREFERRED_TYPE_NUMBER); + if (ECMA_IS_VALUE_ERROR (prim_first_converted_value)) + { + return prim_first_converted_value; + } + + ecma_value_t prim_second_converted_value = ecma_op_to_primitive (y, ECMA_PREFERRED_TYPE_NUMBER); + if (ECMA_IS_VALUE_ERROR (prim_second_converted_value)) + { + ecma_free_value (prim_first_converted_value); + return prim_second_converted_value; + } + + ecma_value_t px = left_first ? prim_first_converted_value : prim_second_converted_value; + ecma_value_t py = left_first ? prim_second_converted_value : prim_first_converted_value; + + const bool is_px_string = ecma_is_value_string (px); + const bool is_py_string = ecma_is_value_string (py); + + if (!(is_px_string && is_py_string)) + { +#if JERRY_BUILTIN_BIGINT + if (JERRY_LIKELY (!ecma_is_value_bigint (px)) && JERRY_LIKELY (!ecma_is_value_bigint (py))) + { +#endif /* JERRY_BUILTIN_BIGINT */ + /* 3. */ + + /* a. */ + + ecma_number_t nx; + ecma_number_t ny; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (px, &nx)) || ECMA_IS_VALUE_ERROR (ecma_op_to_number (py, &ny))) + { + ret_value = ECMA_VALUE_ERROR; + goto end; + } + + /* b. */ + if (ecma_number_is_nan (nx) || ecma_number_is_nan (ny)) + { + /* c., d. */ + ret_value = ECMA_VALUE_UNDEFINED; + } + else + { + bool is_x_less_than_y = (nx < ny); + +#ifndef JERRY_NDEBUG + bool is_x_less_than_y_check; + + if (nx == ny || (ecma_number_is_zero (nx) && ecma_number_is_zero (ny))) + { + /* e., f., g. */ + is_x_less_than_y_check = false; + } + else if (ecma_number_is_infinity (nx) && !ecma_number_is_negative (nx)) + { + /* h. */ + is_x_less_than_y_check = false; + } + else if (ecma_number_is_infinity (ny) && !ecma_number_is_negative (ny)) + { + /* i. */ + is_x_less_than_y_check = true; + } + else if (ecma_number_is_infinity (ny) && ecma_number_is_negative (ny)) + { + /* j. */ + is_x_less_than_y_check = false; + } + else if (ecma_number_is_infinity (nx) && ecma_number_is_negative (nx)) + { + /* k. */ + is_x_less_than_y_check = true; + } + else + { + /* l. */ + JERRY_ASSERT (!ecma_number_is_nan (nx) && !ecma_number_is_infinity (nx)); + JERRY_ASSERT (!ecma_number_is_nan (ny) && !ecma_number_is_infinity (ny)); + JERRY_ASSERT (!(ecma_number_is_zero (nx) && ecma_number_is_zero (ny))); + + if (nx < ny) + { + is_x_less_than_y_check = true; + } + else + { + is_x_less_than_y_check = false; + } + } + + JERRY_ASSERT (is_x_less_than_y_check == is_x_less_than_y); +#endif /* !JERRY_NDEBUG */ + + ret_value = ecma_make_boolean_value (is_x_less_than_y); + } +#if JERRY_BUILTIN_BIGINT + } + else + { + bool invert_result = false; + int compare_result = 0; + + if (!ecma_is_value_bigint (px)) + { + ecma_value_t tmp = px; + px = py; + py = tmp; + invert_result = true; + } + + JERRY_ASSERT (ecma_is_value_bigint (px)); + + if (ecma_is_value_bigint (py)) + { + compare_result = ecma_bigint_compare_to_bigint (px, py); + } + else if (ecma_is_value_string (py)) + { + ret_value = ecma_bigint_parse_string_value (py, ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR); + + if (!ECMA_IS_VALUE_ERROR (ret_value)) + { + if (ret_value == ECMA_VALUE_FALSE) + { + ret_value = ECMA_VALUE_UNDEFINED; + } + else + { + compare_result = ecma_bigint_compare_to_bigint (px, ret_value); + ecma_free_value (ret_value); + ret_value = ECMA_VALUE_EMPTY; + } + } + } + else + { + ecma_number_t ny; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (py, &ny))) + { + ret_value = ECMA_VALUE_ERROR; + goto end; + } + + if (ecma_number_is_nan (ny)) + { + ret_value = ECMA_VALUE_UNDEFINED; + } + else + { + compare_result = ecma_bigint_compare_to_number (px, ny); + } + } + + if (ret_value == ECMA_VALUE_EMPTY) + { + if (invert_result) + { + compare_result = -compare_result; + } + + ret_value = ecma_make_boolean_value (compare_result < 0); + } + } +#endif /* JERRY_BUILTIN_BIGINT */ + } + else + { /* 4. */ + JERRY_ASSERT (is_px_string && is_py_string); + + ecma_string_t *str_x_p = ecma_get_string_from_value (px); + ecma_string_t *str_y_p = ecma_get_string_from_value (py); + + bool is_px_less = ecma_compare_ecma_strings_relational (str_x_p, str_y_p); + + ret_value = ecma_make_boolean_value (is_px_less); + } + +end: + ecma_free_value (prim_second_converted_value); + ecma_free_value (prim_first_converted_value); + + return ret_value; +} /* ecma_op_abstract_relational_compare */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-comparison.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-comparison.h new file mode 100644 index 0000000..d8e0084 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-comparison.h @@ -0,0 +1,38 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_COMPARISON_H +#define ECMA_COMPARISON_H + +#include "ecma-globals.h" +#include "ecma-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmacomparison ECMA comparison + * @{ + */ + +ecma_value_t ecma_op_abstract_equality_compare (ecma_value_t x, ecma_value_t y); +bool ecma_op_strict_equality_compare (ecma_value_t x, ecma_value_t y); +ecma_value_t ecma_op_abstract_relational_compare (ecma_value_t x, ecma_value_t y, bool left_first); + +/** + * @} + * @} + */ + +#endif /* !ECMA_COMPARISON_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-container-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-container-object.cpp new file mode 100644 index 0000000..c3c84f9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-container-object.cpp @@ -0,0 +1,1143 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ecma-container-object.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" +#include "ecma-property-hashmap.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_CONTAINER + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup \addtogroup ecmamaphelpers ECMA builtin Map/Set helper functions + * @{ + */ + +/** + * Create a new internal buffer. + * + * Note: + * The first element of the collection tracks the size of the buffer. + * ECMA_VALUE_EMPTY values are not calculated into the size. + * + * @return pointer to the internal buffer + */ +static inline ecma_collection_t * +ecma_op_create_internal_buffer (void) +{ + ecma_collection_t *collection_p = ecma_new_collection (); + ecma_collection_push_back (collection_p, (ecma_value_t) 0); + + return collection_p; +} /* ecma_op_create_internal_buffer */ + +/** + * Append values to the internal buffer. + */ +static void +ecma_op_internal_buffer_append (ecma_collection_t *container_p, /**< internal container pointer */ + ecma_value_t key_arg, /**< key argument */ + ecma_value_t value_arg, /**< value argument */ + lit_magic_string_id_t lit_id) /**< class id */ +{ + JERRY_ASSERT (container_p != NULL); + + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_MAP_UL) + { + ecma_value_t values[] = { ecma_copy_value_if_not_object (key_arg), ecma_copy_value_if_not_object (value_arg) }; + ecma_collection_append (container_p, values, 2); + } + else + { + ecma_collection_push_back (container_p, ecma_copy_value_if_not_object (key_arg)); + } + + ECMA_CONTAINER_SET_SIZE (container_p, ECMA_CONTAINER_GET_SIZE (container_p) + 1); +} /* ecma_op_internal_buffer_append */ + +/** + * Update the value of a given entry. + */ +static inline void +ecma_op_internal_buffer_update (ecma_value_t *entry_p, /**< entry pointer */ + ecma_value_t value_arg, /**< value argument */ + lit_magic_string_id_t lit_id) /**< class id */ +{ + JERRY_ASSERT (entry_p != NULL); + + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_MAP_UL) + { + ecma_free_value_if_not_object (((ecma_container_pair_t *) entry_p)->value); + + ((ecma_container_pair_t *) entry_p)->value = ecma_copy_value_if_not_object (value_arg); + } +} /* ecma_op_internal_buffer_update */ + +/** + * Delete element from the internal buffer. + */ +static void +ecma_op_internal_buffer_delete (ecma_collection_t *container_p, /**< internal container pointer */ + ecma_container_pair_t *entry_p, /**< entry pointer */ + lit_magic_string_id_t lit_id) /**< class id */ +{ + JERRY_ASSERT (container_p != NULL); + JERRY_ASSERT (entry_p != NULL); + + ecma_free_value_if_not_object (entry_p->key); + entry_p->key = ECMA_VALUE_EMPTY; + + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_MAP_UL) + { + ecma_free_value_if_not_object (entry_p->value); + entry_p->value = ECMA_VALUE_EMPTY; + } + + ECMA_CONTAINER_SET_SIZE (container_p, ECMA_CONTAINER_GET_SIZE (container_p) - 1); +} /* ecma_op_internal_buffer_delete */ + +/** + * Find an entry in the collection. + * + * @return pointer to the appropriate entry. + */ +static ecma_value_t * +ecma_op_internal_buffer_find (ecma_collection_t *container_p, /**< internal container pointer */ + ecma_value_t key_arg, /**< key argument */ + lit_magic_string_id_t lit_id) /**< class id */ +{ + JERRY_ASSERT (container_p != NULL); + + uint8_t entry_size = ecma_op_container_entry_size (lit_id); + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + + for (uint32_t i = 0; i < entry_count; i += entry_size) + { + ecma_value_t *entry_p = start_p + i; + + if (ecma_op_same_value_zero (*entry_p, key_arg, false)) + { + return entry_p; + } + } + + return NULL; +} /* ecma_op_internal_buffer_find */ + +/** + * Get the value that belongs to the key. + * + * Note: in case of Set containers, the values are the same as the keys. + * + * @return ecma value + */ +static ecma_value_t +ecma_op_container_get_value (ecma_value_t *entry_p, /**< entry (key) pointer */ + lit_magic_string_id_t lit_id) /**< class id */ +{ + JERRY_ASSERT (entry_p != NULL); + + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_MAP_UL) + { + return ((ecma_container_pair_t *) entry_p)->value; + } + + return *entry_p; +} /* ecma_op_container_get_value */ + +/** + * Get the size (in ecma_value_t) of the stored entries. + * + * @return size of the entries. + */ +uint8_t +ecma_op_container_entry_size (lit_magic_string_id_t lit_id) /**< class id */ +{ + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_MAP_UL) + { + return ECMA_CONTAINER_PAIR_SIZE; + } + + return ECMA_CONTAINER_VALUE_SIZE; +} /* ecma_op_container_entry_size */ + +/** + * Release the entries in the WeakSet container. + */ +static void +ecma_op_container_free_weakset_entries (ecma_object_t *object_p, /**< object pointer */ + ecma_collection_t *container_p) /** internal buffer pointer */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (container_p != NULL); + + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_VALUE_SIZE) + { + ecma_value_t *entry_p = start_p + i; + + if (ecma_is_value_empty (*entry_p)) + { + continue; + } + + ecma_op_object_unref_weak (ecma_get_object_from_value (*entry_p), ecma_make_object_value (object_p)); + ecma_op_container_remove_weak_entry (object_p, *entry_p); + + *entry_p = ECMA_VALUE_EMPTY; + } +} /* ecma_op_container_free_weakset_entries */ + +/** + * Release the entries in the WeakMap container. + */ +static void +ecma_op_container_free_weakmap_entries (ecma_object_t *object_p, /**< object pointer */ + ecma_collection_t *container_p) /**< internal buffer pointer */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (container_p != NULL); + + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_PAIR_SIZE) + { + ecma_container_pair_t *entry_p = (ecma_container_pair_t *) (start_p + i); + + if (ecma_is_value_empty (entry_p->key)) + { + continue; + } + + ecma_op_object_unref_weak (ecma_get_object_from_value (entry_p->key), ecma_make_object_value (object_p)); + ecma_op_container_remove_weak_entry (object_p, entry_p->key); + + ecma_free_value_if_not_object (entry_p->value); + + entry_p->key = ECMA_VALUE_EMPTY; + entry_p->value = ECMA_VALUE_EMPTY; + } +} /* ecma_op_container_free_weakmap_entries */ + +/** + * Release the entries in the Set container. + */ +static void +ecma_op_container_free_set_entries (ecma_collection_t *container_p) +{ + JERRY_ASSERT (container_p != NULL); + + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_VALUE_SIZE) + { + ecma_value_t *entry_p = start_p + i; + + if (ecma_is_value_empty (*entry_p)) + { + continue; + } + + ecma_free_value_if_not_object (*entry_p); + *entry_p = ECMA_VALUE_EMPTY; + } +} /* ecma_op_container_free_set_entries */ + +/** + * Release the entries in the Map container. + */ +static void +ecma_op_container_free_map_entries (ecma_collection_t *container_p) +{ + JERRY_ASSERT (container_p != NULL); + + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + + for (uint32_t i = 0; i < entry_count; i += ECMA_CONTAINER_PAIR_SIZE) + { + ecma_container_pair_t *entry_p = (ecma_container_pair_t *) (start_p + i); + + if (ecma_is_value_empty (entry_p->key)) + { + continue; + } + + ecma_free_value_if_not_object (entry_p->key); + ecma_free_value_if_not_object (entry_p->value); + + entry_p->key = ECMA_VALUE_EMPTY; + entry_p->value = ECMA_VALUE_EMPTY; + } +} /* ecma_op_container_free_map_entries */ + +/** + * Release the internal buffer and the stored entries. + */ +void +ecma_op_container_free_entries (ecma_object_t *object_p) /**< collection object pointer */ +{ + JERRY_ASSERT (object_p != NULL); + + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + switch (map_object_p->u.cls.u2.container_id) + { + case LIT_MAGIC_STRING_WEAKSET_UL: + { + ecma_op_container_free_weakset_entries (object_p, container_p); + break; + } + case LIT_MAGIC_STRING_WEAKMAP_UL: + { + ecma_op_container_free_weakmap_entries (object_p, container_p); + break; + } + case LIT_MAGIC_STRING_SET_UL: + { + ecma_op_container_free_set_entries (container_p); + break; + } + case LIT_MAGIC_STRING_MAP_UL: + { + ecma_op_container_free_map_entries (container_p); + break; + } + default: + { + break; + } + } + + ECMA_CONTAINER_SET_SIZE (container_p, 0); +} /* ecma_op_container_free_entries */ + +/** + * Handle calling [[Construct]] of built-in Map/Set like objects + * + * @return ecma value + */ +ecma_value_t +ecma_op_container_create (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len, /**< number of arguments */ + lit_magic_string_id_t lit_id, /**< internal class id */ + ecma_builtin_id_t proto_id) /**< prototype builtin id */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + JERRY_ASSERT (lit_id == LIT_MAGIC_STRING_MAP_UL || lit_id == LIT_MAGIC_STRING_SET_UL + || lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_WEAKSET_UL); + JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p) != NULL); + + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), proto_id); + + if (JERRY_UNLIKELY (proto_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_collection_t *container_p = ecma_op_create_internal_buffer (); + ecma_object_t *object_p = ecma_create_object (proto_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + ecma_deref_object (proto_p); + ecma_extended_object_t *map_obj_p = (ecma_extended_object_t *) object_p; + map_obj_p->u.cls.type = ECMA_OBJECT_CLASS_CONTAINER; + map_obj_p->u.cls.u1.container_flags = ECMA_CONTAINER_FLAGS_EMPTY; + map_obj_p->u.cls.u2.container_id = (uint16_t) lit_id; + ecma_value_t iterator; + ecma_object_t *adder_func_p; + + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL || lit_id == LIT_MAGIC_STRING_WEAKSET_UL) + { + map_obj_p->u.cls.u1.container_flags |= ECMA_CONTAINER_FLAGS_WEAK; + } + + ECMA_SET_INTERNAL_VALUE_POINTER (map_obj_p->u.cls.u3.value, container_p); + + ecma_value_t set_value = ecma_make_object_value (object_p); + ecma_value_t result = set_value; + + if (arguments_list_len == 0) + { + return result; + } + + ecma_value_t iterable = arguments_list_p[0]; + + if (ecma_is_value_undefined (iterable) || ecma_is_value_null (iterable)) + { + return result; + } + + lit_magic_string_id_t adder_string_id; + if (lit_id == LIT_MAGIC_STRING_MAP_UL || lit_id == LIT_MAGIC_STRING_WEAKMAP_UL) + { + adder_string_id = LIT_MAGIC_STRING_SET; + } + else + { + adder_string_id = LIT_MAGIC_STRING_ADD; + } + + result = ecma_op_object_get_by_magic_id (object_p, adder_string_id); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_object; + } + + if (!ecma_op_is_callable (result)) + { + ecma_free_value (result); + result = ecma_raise_type_error (ECMA_ERR_FUNCTION_ADD_ORSET_IS_NOT_CALLABLE); + goto cleanup_object; + } + + adder_func_p = ecma_get_object_from_value (result); + + ecma_value_t next_method; + result = ecma_op_get_iterator (iterable, ECMA_VALUE_SYNC_ITERATOR, &next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_adder; + } + + iterator = result; + + while (true) + { + result = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_iterator; + } + + if (ecma_is_value_false (result)) + { + break; + } + + const ecma_value_t next = result; + result = ecma_op_iterator_value (next); + ecma_free_value (next); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_iterator; + } + + if (lit_id == LIT_MAGIC_STRING_SET_UL || lit_id == LIT_MAGIC_STRING_WEAKSET_UL) + { + const ecma_value_t value = result; + + ecma_value_t arguments[] = { value }; + result = ecma_op_function_call (adder_func_p, set_value, arguments, 1); + + ecma_free_value (value); + } + else + { + if (!ecma_is_value_object (result)) + { + ecma_free_value (result); + ecma_raise_type_error (ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT); + result = ecma_op_iterator_close (iterator); + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result)); + goto cleanup_iterator; + } + + ecma_object_t *next_object_p = ecma_get_object_from_value (result); + + result = ecma_op_object_get_by_index (next_object_p, 0); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (next_object_p); + ecma_op_iterator_close (iterator); + goto cleanup_iterator; + } + + const ecma_value_t key = result; + + result = ecma_op_object_get_by_index (next_object_p, 1); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (next_object_p); + ecma_free_value (key); + ecma_op_iterator_close (iterator); + goto cleanup_iterator; + } + + const ecma_value_t value = result; + ecma_value_t arguments[] = { key, value }; + result = ecma_op_function_call (adder_func_p, set_value, arguments, 2); + + ecma_free_value (key); + ecma_free_value (value); + ecma_deref_object (next_object_p); + } + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_op_iterator_close (iterator); + goto cleanup_iterator; + } + + ecma_free_value (result); + } + + ecma_ref_object (object_p); + result = ecma_make_object_value (object_p); + +cleanup_iterator: + ecma_free_value (iterator); + ecma_free_value (next_method); +cleanup_adder: + ecma_deref_object (adder_func_p); +cleanup_object: + ecma_deref_object (object_p); + + return result; +} /* ecma_op_container_create */ + +/** + * Get Map/Set object pointer + * + * Note: + * If the function returns with NULL, the error object has + * already set, and the caller must return with ECMA_VALUE_ERROR + * + * @return pointer to the Map/Set if this_arg is a valid Map/Set object + * NULL otherwise + */ +ecma_extended_object_t * +ecma_op_container_get_object (ecma_value_t this_arg, /**< this argument */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *map_object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (map_object_p, ECMA_OBJECT_CLASS_CONTAINER) + && ((ecma_extended_object_t *) map_object_p)->u.cls.u2.container_id == lit_id) + { + return (ecma_extended_object_t *) map_object_p; + } + } + +#if JERRY_ERROR_MESSAGES + ecma_raise_standard_error_with_format (JERRY_ERROR_TYPE, + "Expected a % object", + ecma_make_string_value (ecma_get_magic_string (lit_id))); +#else /* !JERRY_ERROR_MESSAGES */ + ecma_raise_type_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + + return NULL; +} /* ecma_op_container_get_object */ + +/** + * Returns with the size of the Map/Set object. + * + * @return size of the Map/Set object as ecma-value. + */ +ecma_value_t +ecma_op_container_size (ecma_extended_object_t *map_object_p) /**< internal class id */ +{ + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + return ecma_make_uint32_value (ECMA_CONTAINER_GET_SIZE (container_p)); +} /* ecma_op_container_size */ + +/** + * The generic Map/WeakMap prototype object's 'get' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_get (ecma_extended_object_t *map_object_p, /**< map object */ + ecma_value_t key_arg, /**< key argument */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL && !ecma_is_value_object (key_arg)) + { + return ECMA_VALUE_UNDEFINED; + } + + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + if (ECMA_CONTAINER_GET_SIZE (container_p) == 0) + { + return ECMA_VALUE_UNDEFINED; + } + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, lit_id); + + if (entry_p == NULL) + { + return ECMA_VALUE_UNDEFINED; + } + + return ecma_copy_value (((ecma_container_pair_t *) entry_p)->value); +} /* ecma_op_container_get */ + +/** + * The generic Map/Set prototype object's 'has' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_has (ecma_extended_object_t *map_object_p, /**< map object */ + ecma_value_t key_arg, /**< key argument */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + if ((map_object_p->u.cls.u1.container_flags & ECMA_CONTAINER_FLAGS_WEAK) != 0 && !ecma_is_value_object (key_arg)) + { + return ECMA_VALUE_FALSE; + } + + if (ECMA_CONTAINER_GET_SIZE (container_p) == 0) + { + return ECMA_VALUE_FALSE; + } + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, lit_id); + + return ecma_make_boolean_value (entry_p != NULL); +} /* ecma_op_container_has */ + +/** + * Helper method for the Map.prototype.set and Set.prototype.add methods to swap the sign of the given value if needed + * + * See also: + * ECMA-262 v6, 23.2.3.1 step 6 + * ECMA-262 v6, 23.1.3.9 step 6 + * + * @return ecma value + */ +static ecma_value_t +ecma_op_container_set_normalize_zero (ecma_value_t this_arg) /*< this arg */ +{ + if (ecma_is_value_number (this_arg)) + { + ecma_number_t number_value = ecma_get_number_from_value (this_arg); + + if (JERRY_UNLIKELY (ecma_number_is_zero (number_value) && ecma_number_is_negative (number_value))) + { + return ecma_make_integer_value (0); + } + } + + return this_arg; +} /* ecma_op_container_set_normalize_zero */ + +/** + * The generic Map prototype object's 'set' and Set prototype object's 'add' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_set (ecma_extended_object_t *map_object_p, /**< map object */ + ecma_value_t key_arg, /**< key argument */ + ecma_value_t value_arg, /**< value argument */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + if ((map_object_p->u.cls.u1.container_flags & ECMA_CONTAINER_FLAGS_WEAK) != 0 && !ecma_is_value_object (key_arg)) + { + return ecma_raise_type_error (ECMA_ERR_KEY_MUST_BE_AN_OBJECT); + } + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, lit_id); + + if (entry_p == NULL) + { + ecma_op_internal_buffer_append (container_p, ecma_op_container_set_normalize_zero (key_arg), value_arg, lit_id); + + if ((map_object_p->u.cls.u1.container_flags & ECMA_CONTAINER_FLAGS_WEAK) != 0) + { + ecma_object_t *key_p = ecma_get_object_from_value (key_arg); + ecma_op_object_set_weak (key_p, (ecma_object_t *) map_object_p); + } + } + else + { + ecma_op_internal_buffer_update (entry_p, ecma_op_container_set_normalize_zero (value_arg), lit_id); + } + + ecma_ref_object ((ecma_object_t *) map_object_p); + return ecma_make_object_value ((ecma_object_t *) map_object_p); +} /* ecma_op_container_set */ + +/** + * The generic Map/Set prototype object's 'forEach' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_foreach (ecma_extended_object_t *map_object_p, /**< map object */ + ecma_value_t predicate, /**< callback function */ + ecma_value_t predicate_this_arg, /**< this argument for + * invoke predicate */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + if (!ecma_op_is_callable (predicate)) + { + return ecma_raise_type_error (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE); + } + + JERRY_ASSERT (ecma_is_value_object (predicate)); + ecma_object_t *func_object_p = ecma_get_object_from_value (predicate); + ecma_value_t ret_value = ECMA_VALUE_UNDEFINED; + + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + uint8_t entry_size = ecma_op_container_entry_size (lit_id); + + for (uint32_t i = 0; i < ECMA_CONTAINER_ENTRY_COUNT (container_p); i += entry_size) + { + ecma_value_t *entry_p = ECMA_CONTAINER_START (container_p) + i; + + if (ecma_is_value_empty (*entry_p)) + { + continue; + } + + ecma_value_t key_arg = *entry_p; + ecma_value_t value_arg = ecma_op_container_get_value (entry_p, lit_id); + + ecma_value_t this_arg = ecma_make_object_value ((ecma_object_t *) map_object_p); + ecma_value_t call_args[] = { value_arg, key_arg, this_arg }; + ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (call_value)) + { + ret_value = call_value; + break; + } + + ecma_free_value (call_value); + } + + return ret_value; +} /* ecma_op_container_foreach */ + +/** + * The Map/Set prototype object's 'clear' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_clear (ecma_extended_object_t *map_object_p) /**< this argument */ +{ + ecma_op_container_free_entries ((ecma_object_t *) map_object_p); + + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_container_clear */ + +/** + * The generic Map/Set prototype object's 'delete' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_delete (ecma_extended_object_t *map_object_p, /**< map object */ + ecma_value_t key_arg, /**< key argument */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, lit_id); + + if (entry_p == NULL) + { + return ECMA_VALUE_FALSE; + } + + ecma_op_internal_buffer_delete (container_p, (ecma_container_pair_t *) entry_p, lit_id); + return ECMA_VALUE_TRUE; +} /* ecma_op_container_delete */ + +/** + * The generic WeakMap/WeakSet prototype object's 'delete' routine + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_container_delete_weak (ecma_extended_object_t *map_object_p, /**< map object */ + ecma_value_t key_arg, /**< key argument */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + if (!ecma_is_value_object (key_arg)) + { + return ECMA_VALUE_FALSE; + } + + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, lit_id); + + if (entry_p == NULL) + { + return ECMA_VALUE_FALSE; + } + + ecma_op_internal_buffer_delete (container_p, (ecma_container_pair_t *) entry_p, lit_id); + + ecma_object_t *key_object_p = ecma_get_object_from_value (key_arg); + ecma_op_object_unref_weak (key_object_p, ecma_make_object_value ((ecma_object_t *) map_object_p)); + + return ECMA_VALUE_TRUE; +} /* ecma_op_container_delete_weak */ + +/** + * Helper function to get the value from a weak container object + * + * @return value property + */ +ecma_value_t +ecma_op_container_find_weak_value (ecma_object_t *object_p, /**< internal container object */ + ecma_value_t key_arg) /**< key */ +{ + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (map_object_p->u.cls.type == ECMA_OBJECT_CLASS_CONTAINER + && map_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL); + + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, (lit_magic_string_id_t) map_object_p->u.cls.u2.container_id); + + JERRY_ASSERT (entry_p != NULL); + + return entry_p[1]; +} /* ecma_op_container_find_weak_value */ + +/** + * Helper function to remove a key/value pair from a weak container object + */ +void +ecma_op_container_remove_weak_entry (ecma_object_t *object_p, /**< internal container object */ + ecma_value_t key_arg) /**< key */ +{ + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) object_p; + + JERRY_ASSERT (map_object_p->u.cls.type == ECMA_OBJECT_CLASS_CONTAINER + && (map_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKSET_UL + || map_object_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL)); + + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + + ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, (lit_magic_string_id_t) map_object_p->u.cls.u2.container_id); + + JERRY_ASSERT (entry_p != NULL); + + ecma_op_internal_buffer_delete (container_p, (ecma_container_pair_t *) entry_p, (lit_magic_string_id_t) map_object_p->u.cls.u2.container_id); +} /* ecma_op_container_remove_weak_entry */ + +/** + * The Create{Set, Map}Iterator Abstract operation + * + * See also: + * ECMA-262 v6, 23.1.5.1 + * ECMA-262 v6, 23.2.5.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return Map/Set iterator object, if success + * error - otherwise + */ +ecma_value_t +ecma_op_container_create_iterator (ecma_value_t this_arg, /**< this argument */ + ecma_builtin_id_t proto_id, /**< prototype builtin id */ + ecma_object_class_type_t iterator_type, /**< iterator type */ + ecma_iterator_kind_t kind) /**< iterator kind */ +{ + return ecma_op_create_iterator_object (this_arg, ecma_builtin_get (proto_id), iterator_type, kind); +} /* ecma_op_container_create_iterator */ + +/** + * Get the index of the iterator object. + * + * @return index of the iterator. + */ +static uint32_t +ecma_op_iterator_get_index (ecma_object_t *iter_obj_p) /**< iterator object pointer */ +{ + uint32_t index = ((ecma_extended_object_t *) iter_obj_p)->u.cls.u2.iterator_index; + + if (JERRY_UNLIKELY (index == ECMA_ITERATOR_INDEX_LIMIT)) + { + ecma_string_t *prop_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX); + ecma_property_t *property_p = ecma_find_named_property (iter_obj_p, prop_name_p); + ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + return (uint32_t) (ecma_get_number_from_value (value_p->value)); + } + + return index; +} /* ecma_op_iterator_get_index */ + +/** + * Set the index of the iterator object. + */ +static void +ecma_op_iterator_set_index (ecma_object_t *iter_obj_p, /**< iterator object pointer */ + uint32_t index) /* iterator index to set */ +{ + if (JERRY_UNLIKELY (index >= ECMA_ITERATOR_INDEX_LIMIT)) + { + /* After the ECMA_ITERATOR_INDEX_LIMIT limit is reached the [[%Iterator%NextIndex]] + property is stored as an internal property */ + ecma_string_t *prop_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX); + ecma_property_t *property_p = ecma_find_named_property (iter_obj_p, prop_name_p); + ecma_property_value_t *value_p; + + if (property_p == NULL) + { + value_p = ecma_create_named_data_property (iter_obj_p, prop_name_p, ECMA_PROPERTY_FLAG_WRITABLE, &property_p); + value_p->value = ecma_make_uint32_value (index); + } + else + { + value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + value_p->value = ecma_make_uint32_value (index); + } + } + else + { + ((ecma_extended_object_t *) iter_obj_p)->u.cls.u2.iterator_index = (uint16_t) index; + } +} /* ecma_op_iterator_set_index */ + +/** + * The %{Set, Map}IteratorPrototype% object's 'next' routine + * + * See also: + * ECMA-262 v6, 23.1.5.2.1 + * ECMA-262 v6, 23.2.5.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +ecma_value_t +ecma_op_container_iterator_next (ecma_value_t this_val, /**< this argument */ + ecma_object_class_type_t iterator_type) /**< type of the iterator */ +{ + if (!ecma_is_value_object (this_val)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (this_val); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + if (!ecma_object_class_is (obj_p, iterator_type)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ITERATOR); + } + + ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value; + + if (ecma_is_value_empty (iterated_value)) + { + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) (ecma_get_object_from_value (iterated_value)); + lit_magic_string_id_t lit_id = (lit_magic_string_id_t) map_object_p->u.cls.u2.container_id; + + ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value); + uint32_t entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); + uint32_t index = ecma_op_iterator_get_index (obj_p); + + if (index == entry_count) + { + ext_obj_p->u.cls.u3.iterated_value = ECMA_VALUE_EMPTY; + + return ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + } + + uint8_t entry_size = ecma_op_container_entry_size (lit_id); + uint8_t iterator_kind = ext_obj_p->u.cls.u1.iterator_kind; + ecma_value_t *start_p = ECMA_CONTAINER_START (container_p); + ecma_value_t ret_value = ECMA_VALUE_UNDEFINED; + + for (uint32_t i = index; i < entry_count; i += entry_size) + { + ecma_value_t *entry_p = start_p + i; + + if (ecma_is_value_empty (*entry_p)) + { + if (i == (entry_count - entry_size)) + { + ret_value = ecma_create_iter_result_object (ECMA_VALUE_UNDEFINED, ECMA_VALUE_TRUE); + break; + } + + continue; + } + + ecma_op_iterator_set_index (obj_p, i + entry_size); + + ecma_value_t key_arg = *entry_p; + ecma_value_t value_arg = ecma_op_container_get_value (entry_p, lit_id); + + if (iterator_kind == ECMA_ITERATOR_KEYS) + { + ret_value = ecma_create_iter_result_object (key_arg, ECMA_VALUE_FALSE); + } + else if (iterator_kind == ECMA_ITERATOR_VALUES) + { + ret_value = ecma_create_iter_result_object (value_arg, ECMA_VALUE_FALSE); + } + else + { + JERRY_ASSERT (iterator_kind == ECMA_ITERATOR_ENTRIES); + + ecma_value_t entry_array_value; + entry_array_value = ecma_create_array_from_iter_element (value_arg, key_arg); + + ret_value = ecma_create_iter_result_object (entry_array_value, ECMA_VALUE_FALSE); + ecma_free_value (entry_array_value); + } + + break; + } + + return ret_value; +} /* ecma_op_container_iterator_next */ + +/** + * Dispatcher of builtin container routines. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_container_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list_p[], /**< list of arguments + * passed to routine */ + lit_magic_string_id_t lit_id) /**< internal class id */ +{ + ecma_extended_object_t *map_object_p = ecma_op_container_get_object (this_arg, lit_id); + + if (map_object_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + switch (builtin_routine_id) + { + case ECMA_CONTAINER_ROUTINE_DELETE: + { + return ecma_op_container_delete (map_object_p, arguments_list_p[0], lit_id); + } + case ECMA_CONTAINER_ROUTINE_DELETE_WEAK: + { + return ecma_op_container_delete_weak (map_object_p, arguments_list_p[0], lit_id); + } + case ECMA_CONTAINER_ROUTINE_GET: + { + return ecma_op_container_get (map_object_p, arguments_list_p[0], lit_id); + } + case ECMA_CONTAINER_ROUTINE_SET: + { + return ecma_op_container_set (map_object_p, arguments_list_p[0], arguments_list_p[1], lit_id); + } + case ECMA_CONTAINER_ROUTINE_HAS: + { + return ecma_op_container_has (map_object_p, arguments_list_p[0], lit_id); + } + case ECMA_CONTAINER_ROUTINE_FOREACH: + { + return ecma_op_container_foreach (map_object_p, arguments_list_p[0], arguments_list_p[1], lit_id); + } + case ECMA_CONTAINER_ROUTINE_SIZE_GETTER: + { + return ecma_op_container_size (map_object_p); + } + case ECMA_CONTAINER_ROUTINE_ADD: + { + return ecma_op_container_set (map_object_p, arguments_list_p[0], arguments_list_p[0], lit_id); + } + case ECMA_CONTAINER_ROUTINE_CLEAR: + { + return ecma_op_container_clear (map_object_p); + } + case ECMA_CONTAINER_ROUTINE_KEYS: + case ECMA_CONTAINER_ROUTINE_VALUES: + case ECMA_CONTAINER_ROUTINE_ENTRIES: + { + ecma_builtin_id_t builtin_iterator_prototype = ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE; + ecma_object_class_type_t iterator_type = ECMA_OBJECT_CLASS_MAP_ITERATOR; + + if (lit_id != LIT_MAGIC_STRING_MAP_UL) + { + builtin_iterator_prototype = ECMA_BUILTIN_ID_SET_ITERATOR_PROTOTYPE; + iterator_type = ECMA_OBJECT_CLASS_SET_ITERATOR; + } + + ecma_iterator_kind_t kind = (ecma_iterator_kind_t) (builtin_routine_id - ECMA_CONTAINER_ROUTINE_KEYS); + + return ecma_op_container_create_iterator (this_arg, builtin_iterator_prototype, iterator_type, kind); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_container_dispatch_routine */ + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-container-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-container-object.h new file mode 100644 index 0000000..92fc6eb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-container-object.h @@ -0,0 +1,97 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_CONTAINER_OBJECT_H +#define ECMA_CONTAINER_OBJECT_H + +#include "ecma-builtins.h" +#include "ecma-globals.h" + +#if JERRY_BUILTIN_CONTAINER + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmamaphelpers ECMA builtin map/set helper functions + * @{ + */ + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_CONTAINER_ROUTINE_START = 0, + ECMA_CONTAINER_ROUTINE_ADD, + ECMA_CONTAINER_ROUTINE_CLEAR, + ECMA_CONTAINER_ROUTINE_DELETE_WEAK, + ECMA_CONTAINER_ROUTINE_DELETE, + ECMA_CONTAINER_ROUTINE_FOREACH, + ECMA_CONTAINER_ROUTINE_HAS, + ECMA_CONTAINER_ROUTINE_SIZE_GETTER, + ECMA_CONTAINER_ROUTINE_GET, + ECMA_CONTAINER_ROUTINE_SET, + /* Note: These 3 routines MUST be in this order */ + ECMA_CONTAINER_ROUTINE_KEYS, + ECMA_CONTAINER_ROUTINE_VALUES, + ECMA_CONTAINER_ROUTINE_ENTRIES +}; + +uint8_t ecma_op_container_entry_size (lit_magic_string_id_t lit_id); +ecma_extended_object_t *ecma_op_container_get_object (ecma_value_t this_arg, lit_magic_string_id_t lit_id); +ecma_value_t ecma_op_container_create (const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len, + lit_magic_string_id_t lit_id, + ecma_builtin_id_t proto_id); +ecma_value_t ecma_op_container_size (ecma_extended_object_t *map_object_p); +ecma_value_t +ecma_op_container_get (ecma_extended_object_t *map_object_p, ecma_value_t key_arg, lit_magic_string_id_t lit_id); +ecma_value_t ecma_op_container_foreach (ecma_extended_object_t *map_object_p, + ecma_value_t predicate, + ecma_value_t predicate_this_arg, + lit_magic_string_id_t lit_id); +ecma_value_t +ecma_op_container_has (ecma_extended_object_t *map_object_p, ecma_value_t key_arg, lit_magic_string_id_t lit_id); +ecma_value_t ecma_op_container_set (ecma_extended_object_t *map_object_p, + ecma_value_t key_arg, + ecma_value_t value_arg, + lit_magic_string_id_t lit_id); +ecma_value_t ecma_op_container_clear (ecma_extended_object_t *map_object_p); +ecma_value_t +ecma_op_container_delete (ecma_extended_object_t *map_object_p, ecma_value_t key_arg, lit_magic_string_id_t lit_id); +ecma_value_t ecma_op_container_delete_weak (ecma_extended_object_t *map_object_p, + ecma_value_t key_arg, + lit_magic_string_id_t lit_id); +ecma_value_t ecma_op_container_find_weak_value (ecma_object_t *object_p, ecma_value_t key_arg); +void ecma_op_container_remove_weak_entry (ecma_object_t *object_p, ecma_value_t key_arg); +void ecma_op_container_free_entries (ecma_object_t *object_p); +ecma_value_t ecma_op_container_create_iterator (ecma_value_t this_arg, + ecma_builtin_id_t proto_id, + ecma_object_class_type_t iterator_type, + ecma_iterator_kind_t kind); +ecma_value_t ecma_op_container_iterator_next (ecma_value_t this_val, ecma_object_class_type_t iterator_type); +ecma_value_t ecma_builtin_container_dispatch_routine (uint16_t builtin_routine_id, + ecma_value_t this_arg, + const ecma_value_t arguments_list_p[], + lit_magic_string_id_t lit_id); + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_CONTAINER */ + +#endif /* !ECMA_CONTAINER_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-conversion.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-conversion.cpp new file mode 100644 index 0000000..00fbc20 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-conversion.cpp @@ -0,0 +1,1063 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Implementation of ECMA-defined conversion routines + */ + +#include "ecma-conversion.h" + +#include + +#include "ecma-alloc.h" +#include "ecma-bigint-object.h" +#include "ecma-bigint.h" +#include "ecma-boolean-object.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-number-object.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-string-object.h" +#include "ecma-symbol-object.h" + +#include "jrt-libc-includes.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaconversion ECMA conversion routines + * @{ + */ + +/** + * RequireObjectCoercible operation. + * + * See also: + * ECMA-262 v11, 7.2.1 + * + * @return true - if the value can be coerced to object without any exceptions + * false - otherwise + */ +bool +ecma_op_require_object_coercible (ecma_value_t value) /**< ecma value */ +{ + ecma_check_value_type_is_spec_defined (value); + + if (ecma_is_value_undefined (value) || ecma_is_value_null (value)) + { + ecma_raise_type_error (ECMA_ERR_ARGUMENT_CANNOT_CONVERT_TO_OBJECT); + return false; + } + + return true; +} /* ecma_op_require_object_coercible */ + +/** + * SameValue operation. + * + * See also: + * ECMA-262 v5, 9.12 + * + * @return true - if the value are same according to ECMA-defined SameValue algorithm, + * false - otherwise + */ +bool +ecma_op_same_value (ecma_value_t x, /**< ecma value */ + ecma_value_t y) /**< ecma value */ +{ + if (x == y) + { + return true; + } + + ecma_type_t type_of_x = ecma_get_value_type_field (x); + + if (type_of_x != ecma_get_value_type_field (y) || type_of_x == ECMA_TYPE_DIRECT) + { + return false; + } + + if (ecma_is_value_number (x)) + { + ecma_number_t x_num = ecma_get_number_from_value (x); + ecma_number_t y_num = ecma_get_number_from_value (y); + + bool is_x_nan = ecma_number_is_nan (x_num); + bool is_y_nan = ecma_number_is_nan (y_num); + + if (is_x_nan || is_y_nan) + { + return is_x_nan && is_y_nan; + } + + if (ecma_number_is_zero (x_num) && ecma_number_is_zero (y_num) + && ecma_number_is_negative (x_num) != ecma_number_is_negative (y_num)) + { + return false; + } + + return (x_num == y_num); + } + + if (ecma_is_value_string (x)) + { + ecma_string_t *x_str_p = ecma_get_string_from_value (x); + ecma_string_t *y_str_p = ecma_get_string_from_value (y); + + return ecma_compare_ecma_strings (x_str_p, y_str_p); + } + +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (x)) + { + return (ecma_is_value_bigint (y) && ecma_bigint_compare_to_bigint (x, y) == 0); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + JERRY_ASSERT (ecma_is_value_object (x) || ecma_is_value_symbol (x)); + + return false; +} /* ecma_op_same_value */ + +#if JERRY_BUILTIN_CONTAINER +/** + * SameValueZero operation. + * + * See also: + * ECMA-262 v6, 7.2.10 + * + * @return true - if the value are same according to ECMA-defined SameValueZero algorithm, + * false - otherwise + */ +bool +ecma_op_same_value_zero (ecma_value_t x, /**< ecma value */ + ecma_value_t y, /**< ecma value */ + bool strict_equality) /**< strict equality */ +{ + if (ecma_is_value_number (x) && ecma_is_value_number (y)) + { + ecma_number_t x_num = ecma_get_number_from_value (x); + ecma_number_t y_num = ecma_get_number_from_value (y); + + bool is_x_nan = ecma_number_is_nan (x_num); + bool is_y_nan = ecma_number_is_nan (y_num); + + if (strict_equality && is_x_nan && is_y_nan) + { + return false; + } + + if (is_x_nan || is_y_nan) + { + return (is_x_nan && is_y_nan); + } + + if (ecma_number_is_zero (x_num) && ecma_number_is_zero (y_num) + && ecma_number_is_negative (x_num) != ecma_number_is_negative (y_num)) + { + return true; + } + + return (x_num == y_num); + } + + return ecma_op_same_value (x, y); +} /* ecma_op_same_value_zero */ +#endif /* JERRY_BUILTIN_CONTAINER */ + +/** + * ToPrimitive operation. + * + * See also: + * ECMA-262 v5, 9.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_to_primitive (ecma_value_t value, /**< ecma value */ + ecma_preferred_type_hint_t preferred_type) /**< preferred type hint */ +{ + ecma_check_value_type_is_spec_defined (value); + + if (ecma_is_value_object (value)) + { + ecma_object_t *obj_p = ecma_get_object_from_value (value); + + return ecma_op_object_default_value (obj_p, preferred_type); + } + else + { + return ecma_copy_value (value); + } +} /* ecma_op_to_primitive */ + +/** + * ToBoolean operation. Cannot throw an exception. + * + * See also: + * ECMA-262 v5, 9.2 + * + * @return true - if the logical value is true + * false - otherwise + */ +bool +ecma_op_to_boolean (ecma_value_t value) /**< ecma value */ +{ + ecma_check_value_type_is_spec_defined (value); + + if (ecma_is_value_simple (value)) + { + JERRY_ASSERT (ecma_is_value_boolean (value) || ecma_is_value_undefined (value) || ecma_is_value_null (value)); + + return ecma_is_value_true (value); + } + + if (ecma_is_value_integer_number (value)) + { + return (value != ecma_make_integer_value (0)); + } + + if (ecma_is_value_float_number (value)) + { + ecma_number_t num = ecma_get_float_from_value (value); + + return (!ecma_number_is_nan (num) && !ecma_number_is_zero (num)); + } + + if (ecma_is_value_string (value)) + { + ecma_string_t *str_p = ecma_get_string_from_value (value); + + return !ecma_string_is_empty (str_p); + } + +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (value)) + { + return value != ECMA_BIGINT_ZERO; + } +#endif /* JERRY_BUILTIN_BIGINT */ + + JERRY_ASSERT (ecma_is_value_object (value) || ecma_is_value_symbol (value)); + + return true; +} /* ecma_op_to_boolean */ + +/** + * ToNumber operation. + * + * See also: + * ECMA-262 v5, 9.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_to_number (ecma_value_t value, /**< ecma value */ + ecma_number_t *number_p) /**< [out] ecma number */ +{ + return ecma_op_to_numeric (value, number_p, ECMA_TO_NUMERIC_NO_OPTS); +} /* ecma_op_to_number */ + +/** + * Helper to get the numeric value of an ecma value + * + * See also: + * ECMA-262 v11, 7.1.3 + * + * @return ECMA_VALUE_EMPTY if converted to number, BigInt if + * converted to BigInt, and conversion error otherwise + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_to_numeric (ecma_value_t value, /**< ecma value */ + ecma_number_t *number_p, /**< [out] ecma number */ + ecma_to_numeric_options_t options) /**< option bits */ +{ + JERRY_UNUSED (options); + + if (ecma_is_value_integer_number (value)) + { + *number_p = (ecma_number_t) ecma_get_integer_from_value (value); + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_float_number (value)) + { + *number_p = ecma_get_float_from_value (value); + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_string (value)) + { + ecma_string_t *str_p = ecma_get_string_from_value (value); + *number_p = ecma_string_to_number (str_p); + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_undefined (value)) + { + *number_p = ecma_number_make_nan (); + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_null (value)) + { + *number_p = 0; + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_true (value)) + { + *number_p = 1; + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_false (value)) + { + *number_p = 0; + return ECMA_VALUE_EMPTY; + } + + if (ecma_is_value_symbol (value)) + { + return ecma_raise_type_error (ECMA_ERR_CONVERT_SYMBOL_TO_NUMBER); + } + +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (value)) + { + if (options & ECMA_TO_NUMERIC_ALLOW_BIGINT) + { + return ecma_copy_value (value); + } + return ecma_raise_type_error (ECMA_ERR_CONVERT_BIGINT_TO_NUMBER); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + JERRY_ASSERT (ecma_is_value_object (value)); + + ecma_object_t *object_p = ecma_get_object_from_value (value); + + ecma_value_t def_value = ecma_op_object_default_value (object_p, ECMA_PREFERRED_TYPE_NUMBER); + + if (ECMA_IS_VALUE_ERROR (def_value)) + { + return def_value; + } + + ecma_value_t ret_value = ecma_op_to_numeric (def_value, number_p, options); + + ecma_fast_free_value (def_value); + + return ret_value; +} /* ecma_op_to_numeric */ + +/** + * ToString operation. + * + * See also: + * ECMA-262 v5, 9.8 + * + * @return NULL - if the conversion fails + * pointer to the string descriptor - otherwise + */ +ecma_string_t * +ecma_op_to_string (ecma_value_t value) /**< ecma value */ +{ + ecma_check_value_type_is_spec_defined (value); + + if (ecma_is_value_string (value)) + { + ecma_string_t *res_p = ecma_get_string_from_value (value); + ecma_ref_ecma_string (res_p); + return res_p; + } + + if (ecma_is_value_integer_number (value)) + { + ecma_integer_value_t num = ecma_get_integer_from_value (value); + + if (num < 0) + { + return ecma_new_ecma_string_from_number ((ecma_number_t) num); + } + else + { + return ecma_new_ecma_string_from_uint32 ((uint32_t) num); + } + } + + if (ecma_is_value_float_number (value)) + { + ecma_number_t num = ecma_get_float_from_value (value); + return ecma_new_ecma_string_from_number (num); + } + + if (ecma_is_value_undefined (value)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_UNDEFINED); + } + + if (ecma_is_value_null (value)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_NULL); + } + + if (ecma_is_value_true (value)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_TRUE); + } + + if (ecma_is_value_false (value)) + { + return ecma_get_magic_string (LIT_MAGIC_STRING_FALSE); + } + + if (ecma_is_value_symbol (value)) + { + ecma_raise_type_error (ECMA_ERR_CONVERT_SYMBOL_TO_STRING); + return NULL; + } + +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (value)) + { + return ecma_bigint_to_string (value, 10); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + JERRY_ASSERT (ecma_is_value_object (value)); + + ecma_object_t *obj_p = ecma_get_object_from_value (value); + + ecma_value_t def_value = ecma_op_object_default_value (obj_p, ECMA_PREFERRED_TYPE_STRING); + + if (ECMA_IS_VALUE_ERROR (def_value)) + { + return NULL; + } + + ecma_string_t *ret_string_p = ecma_op_to_string (def_value); + + ecma_free_value (def_value); + + return ret_string_p; +} /* ecma_op_to_string */ + +/** + * ToPropertyKey operation. + * + * See also: + * ECMA 262 v6, 7.1.14 + * ECMA 262 v10, 7.1.14 + * ECMA 262 v11, 7.1.19 + * + * @return NULL - if the conversion fails + * ecma-string - otherwise + */ +ecma_string_t * +ecma_op_to_property_key (ecma_value_t value) /**< ecma value */ +{ + /* Fast path for strings and symbols */ + if (JERRY_LIKELY (ecma_is_value_prop_name (value))) + { + ecma_string_t *key_p = ecma_get_prop_name_from_value (value); + ecma_ref_ecma_string (key_p); + return key_p; + } + + ecma_value_t key = ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_STRING); + + if (ECMA_IS_VALUE_ERROR (key)) + { + return NULL; + } + + if (ecma_is_value_symbol (key)) + { + ecma_string_t *symbol_p = ecma_get_symbol_from_value (key); + return symbol_p; + } + + ecma_string_t *result = ecma_op_to_string (key); + ecma_free_value (key); + + return result; +} /* ecma_op_to_property_key */ + +/** + * ToObject operation. + * + * See also: + * ECMA-262 v5, 9.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_to_object (ecma_value_t value) /**< ecma value */ +{ + ecma_check_value_type_is_spec_defined (value); + ecma_builtin_id_t proto_id = ECMA_BUILTIN_ID_OBJECT_PROTOTYPE; + uint8_t class_type; + + if (ecma_is_value_number (value)) + { +#if JERRY_BUILTIN_NUMBER + proto_id = ECMA_BUILTIN_ID_NUMBER_PROTOTYPE; +#endif /* JERRY_BUILTIN_NUMBER */ + class_type = ECMA_OBJECT_CLASS_NUMBER; + } + else if (ecma_is_value_string (value)) + { +#if JERRY_BUILTIN_STRING + proto_id = ECMA_BUILTIN_ID_STRING_PROTOTYPE; +#endif /* JERRY_BUILTIN_STRING */ + class_type = ECMA_OBJECT_CLASS_STRING; + } + else if (ecma_is_value_object (value)) + { + return ecma_copy_value (value); + } + else if (ecma_is_value_symbol (value)) + { + proto_id = ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE; + class_type = ECMA_OBJECT_CLASS_SYMBOL; + } +#if JERRY_BUILTIN_BIGINT + else if (ecma_is_value_bigint (value)) + { + return ecma_op_create_bigint_object (value); + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + if (ecma_is_value_undefined (value) || ecma_is_value_null (value)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_CANNOT_CONVERT_TO_OBJECT); + } + else + { + JERRY_ASSERT (ecma_is_value_boolean (value)); +#if JERRY_BUILTIN_BOOLEAN + proto_id = ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE; +#endif /* JERRY_BUILTIN_BOOLEAN */ + class_type = ECMA_OBJECT_CLASS_BOOLEAN; + } + } + + ecma_object_t *object_p = + ecma_create_object (ecma_builtin_get (proto_id), sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = class_type; + ext_object_p->u.cls.u3.value = ecma_copy_value_if_not_object (value); + + return ecma_make_object_value (object_p); +} /* ecma_op_to_object */ + +/** + * FromPropertyDescriptor operation. + * + * See also: + * ECMA-262 v5, 8.10.4 + * + * @return constructed object + */ +ecma_object_t * +ecma_op_from_property_descriptor (const ecma_property_descriptor_t *src_prop_desc_p) /**< property descriptor */ +{ + /* 2. */ + ecma_object_t *obj_p = ecma_op_create_object_object_noarg (); + ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor (); + { + prop_desc.flags = (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_WRITABLE + | JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE + | JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE); + } + + /* 3. */ + if (src_prop_desc_p->flags & (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED)) + { + /* a. */ + prop_desc.value = src_prop_desc_p->value; + ecma_op_object_define_own_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_VALUE), &prop_desc); + + /* b. */ + prop_desc.value = ecma_make_boolean_value (src_prop_desc_p->flags & JERRY_PROP_IS_WRITABLE); + ecma_op_object_define_own_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_WRITABLE), &prop_desc); + } + else if (src_prop_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + { + /* a. */ + if (src_prop_desc_p->get_p == NULL) + { + prop_desc.value = ECMA_VALUE_UNDEFINED; + } + else + { + prop_desc.value = ecma_make_object_value (src_prop_desc_p->get_p); + } + + ecma_op_object_define_own_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_GET), &prop_desc); + + /* b. */ + if (src_prop_desc_p->set_p == NULL) + { + prop_desc.value = ECMA_VALUE_UNDEFINED; + } + else + { + prop_desc.value = ecma_make_object_value (src_prop_desc_p->set_p); + } + ecma_op_object_define_own_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_SET), &prop_desc); + } + + prop_desc.value = ecma_make_boolean_value (src_prop_desc_p->flags & JERRY_PROP_IS_ENUMERABLE); + ecma_op_object_define_own_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_ENUMERABLE), &prop_desc); + + prop_desc.value = ecma_make_boolean_value (src_prop_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE); + ecma_op_object_define_own_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_CONFIGURABLE), &prop_desc); + + return obj_p; +} /* ecma_op_from_property_descriptor */ + +/** + * ToPropertyDescriptor operation. + * + * See also: + * ECMA-262 v5, 8.10.5 + * + * @return ECMA_VALUE_EMPTY if successful, ECMA_VALUE_ERROR otherwise + */ +ecma_value_t +ecma_op_to_property_descriptor (ecma_value_t obj_value, /**< object value */ + ecma_property_descriptor_t *out_prop_desc_p) /**< [out] filled property descriptor + * if the operation is successful, + * unmodified otherwise */ +{ + /* 1. */ + if (!ecma_is_value_object (obj_value)) + { + return ecma_raise_type_error (ECMA_ERR_EXPECTED_AN_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (obj_value); + ecma_value_t ret_value = ECMA_VALUE_ERROR; + ecma_value_t set_prop_value; + ecma_value_t get_prop_value; + ecma_value_t writable_prop_value; + ecma_value_t value_prop_value; + ecma_value_t configurable_prop_value; + ecma_property_descriptor_t prop_desc; + ecma_value_t enumerable_prop_value; + + /* 3. */ + enumerable_prop_value = ecma_op_object_find (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_ENUMERABLE)); + + if (ECMA_IS_VALUE_ERROR (enumerable_prop_value)) + { + return enumerable_prop_value; + } + + /* 2. */ + prop_desc = ecma_make_empty_property_descriptor (); + + if (ecma_is_value_found (enumerable_prop_value)) + { + uint32_t is_enumerable = + (ecma_op_to_boolean (enumerable_prop_value) ? JERRY_PROP_IS_ENUMERABLE : JERRY_PROP_NO_OPTS); + + prop_desc.flags |= (uint16_t) (JERRY_PROP_IS_ENUMERABLE_DEFINED | is_enumerable); + + ecma_free_value (enumerable_prop_value); + } + + /* 4. */ + configurable_prop_value = ecma_op_object_find (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_CONFIGURABLE)); + + if (ECMA_IS_VALUE_ERROR (configurable_prop_value)) + { + goto free_desc; + } + + if (ecma_is_value_found (configurable_prop_value)) + { + uint32_t is_configurable = + (ecma_op_to_boolean (configurable_prop_value) ? JERRY_PROP_IS_CONFIGURABLE : JERRY_PROP_NO_OPTS); + + prop_desc.flags |= (uint16_t) (JERRY_PROP_IS_CONFIGURABLE_DEFINED | is_configurable); + + ecma_free_value (configurable_prop_value); + } + + /* 5. */ + value_prop_value = ecma_op_object_find (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_VALUE)); + + if (ECMA_IS_VALUE_ERROR (value_prop_value)) + { + goto free_desc; + } + + if (ecma_is_value_found (value_prop_value)) + { + prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED; + prop_desc.value = ecma_copy_value (value_prop_value); + ecma_free_value (value_prop_value); + } + + /* 6. */ + writable_prop_value = ecma_op_object_find (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_WRITABLE)); + + if (ECMA_IS_VALUE_ERROR (writable_prop_value)) + { + goto free_desc; + } + + if (ecma_is_value_found (writable_prop_value)) + { + uint32_t is_writable = (ecma_op_to_boolean (writable_prop_value) ? JERRY_PROP_IS_WRITABLE : JERRY_PROP_NO_OPTS); + + prop_desc.flags |= (uint16_t) (JERRY_PROP_IS_WRITABLE_DEFINED | is_writable); + + ecma_free_value (writable_prop_value); + } + + /* 7. */ + get_prop_value = ecma_op_object_find (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_GET)); + + if (ECMA_IS_VALUE_ERROR (get_prop_value)) + { + goto free_desc; + } + + if (ecma_is_value_found (get_prop_value)) + { + if (!ecma_op_is_callable (get_prop_value) && !ecma_is_value_undefined (get_prop_value)) + { + ecma_free_value (get_prop_value); + ret_value = ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION); + goto free_desc; + } + + prop_desc.flags |= JERRY_PROP_IS_GET_DEFINED; + + if (ecma_is_value_undefined (get_prop_value)) + { + prop_desc.get_p = NULL; + } + else + { + JERRY_ASSERT (ecma_is_value_object (get_prop_value)); + + ecma_object_t *get_p = ecma_get_object_from_value (get_prop_value); + ecma_ref_object (get_p); + + prop_desc.get_p = get_p; + } + + ecma_free_value (get_prop_value); + } + + /* 8. */ + set_prop_value = ecma_op_object_find (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_SET)); + + if (ECMA_IS_VALUE_ERROR (set_prop_value)) + { + goto free_desc; + } + + if (ecma_is_value_found (set_prop_value)) + { + if (!ecma_op_is_callable (set_prop_value) && !ecma_is_value_undefined (set_prop_value)) + { + ecma_free_value (set_prop_value); + ret_value = ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION); + goto free_desc; + } + + prop_desc.flags |= JERRY_PROP_IS_SET_DEFINED; + + if (ecma_is_value_undefined (set_prop_value)) + { + prop_desc.set_p = NULL; + } + else + { + JERRY_ASSERT (ecma_is_value_object (set_prop_value)); + + ecma_object_t *set_p = ecma_get_object_from_value (set_prop_value); + ecma_ref_object (set_p); + + prop_desc.set_p = set_p; + } + + ecma_free_value (set_prop_value); + } + + /* 9. */ + if ((prop_desc.flags & (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED)) + && (prop_desc.flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED))) + { + ret_value = ecma_raise_type_error (ECMA_ERR_ACCESSOR_WRITABLE); + } + else + { + *out_prop_desc_p = prop_desc; + ret_value = ECMA_VALUE_EMPTY; + } + +free_desc: + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_free_property_descriptor (&prop_desc); + } + + return ret_value; +} /* ecma_op_to_property_descriptor */ + +/** + * IsInteger operation. + * + * See also: + * ECMA-262 v5, 9.4 + * ECMA-262 v6, 7.1.4 + * + * @return true - if the argument is integer + * false - otherwise + */ +bool +ecma_op_is_integer (ecma_number_t num) /**< ecma number */ +{ + if (ecma_number_is_nan (num) || ecma_number_is_infinity (num)) + { + return false; + } + + ecma_number_t floor_fabs = (ecma_number_t) floor (fabs (num)); + ecma_number_t fabs_value = (ecma_number_t) fabs (num); + + return (floor_fabs == fabs_value); +} /* ecma_op_is_integer */ + +/** + * ToInteger operation. + * + * See also: + * ECMA-262 v5, 9.4 + * ECMA-262 v6, 7.1.4 + * + * @return ECMA_VALUE_EMPTY if successful + * conversion error otherwise + */ +ecma_value_t +ecma_op_to_integer (ecma_value_t value, /**< ecma value */ + ecma_number_t *number_p) /**< [out] ecma number */ +{ + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + /* 1 */ + ecma_value_t to_number = ecma_op_to_number (value, number_p); + + /* 2 */ + if (ECMA_IS_VALUE_ERROR (to_number)) + { + return to_number; + } + + ecma_number_t number = *number_p; + + /* 3 */ + if (ecma_number_is_nan (number)) + { + *number_p = ECMA_NUMBER_ZERO; + return ECMA_VALUE_EMPTY; + } + + /* 4 */ + if (ecma_number_is_zero (number) || ecma_number_is_infinity (number)) + { + return ECMA_VALUE_EMPTY; + } + + ecma_number_t floor_fabs = (ecma_number_t) floor (fabs (number)); + /* 5 */ + *number_p = ecma_number_is_negative (number) ? -floor_fabs : floor_fabs; + return ECMA_VALUE_EMPTY; +} /* ecma_op_to_integer */ + +/** + * ToLength operation. + * + * See also: + * ECMA-262 v6, 7.1.15 + * + * @return ECMA_VALUE_EMPTY if successful + * conversion error otherwise + */ +ecma_value_t +ecma_op_to_length (ecma_value_t value, /**< ecma value */ + ecma_length_t *length) /**< [out] ecma number */ +{ + /* 1 */ + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + /* 2 */ + ecma_number_t num; + ecma_value_t length_num = ecma_op_to_integer (value, &num); + + /* 3 */ + if (ECMA_IS_VALUE_ERROR (length_num)) + { + return length_num; + } + + /* 4 */ + if (num <= 0) + { + *length = 0; + return ECMA_VALUE_EMPTY; + } + + /* 5 */ + if (num >= ECMA_NUMBER_MAX_SAFE_INTEGER) + { + *length = (ecma_length_t) ECMA_NUMBER_MAX_SAFE_INTEGER; + return ECMA_VALUE_EMPTY; + } + + /* 6 */ + *length = (ecma_length_t) num; + return ECMA_VALUE_EMPTY; +} /* ecma_op_to_length */ + +/** + * ToIndex operation. + * + * See also: + * ECMA-262 v11, 7.1.22 + * + * @return ECMA_VALUE_EMPTY if successful + * conversion error otherwise + */ +ecma_value_t +ecma_op_to_index (ecma_value_t value, /**< ecma value */ + ecma_number_t *index) /**< [out] ecma number */ +{ + /* 1. */ + if (ecma_is_value_undefined (value)) + { + *index = 0; + return ECMA_VALUE_EMPTY; + } + + /* 2.a */ + ecma_number_t integer_index; + ecma_value_t index_value = ecma_op_to_integer (value, &integer_index); + + if (ECMA_IS_VALUE_ERROR (index_value)) + { + return index_value; + } + + /* 2.b - 2.d */ + if (integer_index < 0 || integer_index > ECMA_NUMBER_MAX_SAFE_INTEGER) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_OR_OUT_OF_RANGE_INDEX); + } + + /* 3. */ + *index = integer_index; + return ECMA_VALUE_EMPTY; +} /* ecma_op_to_index */ + +/** + * CreateListFromArrayLike operation. + * Different types are not handled yet. + * + * See also: + * ECMA-262 v6, 7.3.17 + * + * @return ecma_collection_t if successful + * NULL otherwise + */ +ecma_collection_t * +ecma_op_create_list_from_array_like (ecma_value_t arr, /**< array value */ + bool prop_names_only) /**< true - accept only property names + false - otherwise */ +{ + /* 1. */ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (arr)); + + /* 3. */ + if (!ecma_is_value_object (arr)) + { + ecma_raise_type_error (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT); + return NULL; + } + ecma_object_t *obj_p = ecma_get_object_from_value (arr); + + /* 4. 5. */ + ecma_length_t len; + if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (obj_p, &len))) + { + return NULL; + } + + /* 6. */ + ecma_collection_t *list_ptr = ecma_new_collection (); + + /* 7. 8. */ + for (ecma_length_t idx = 0; idx < len; idx++) + { + ecma_value_t next = ecma_op_object_get_by_index (obj_p, idx); + if (ECMA_IS_VALUE_ERROR (next)) + { + ecma_collection_free (list_ptr); + return NULL; + } + + if (prop_names_only && !ecma_is_value_prop_name (next)) + { + ecma_free_value (next); + ecma_collection_free (list_ptr); + ecma_raise_type_error (ECMA_ERR_PROPERTY_NAME_IS_NEITHER_SYMBOL_NOR_STRING); + return NULL; + } + + ecma_collection_push_back (list_ptr, next); + } + + /* 9. */ + return list_ptr; +} /* ecma_op_create_list_from_array_like */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-conversion.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-conversion.h new file mode 100644 index 0000000..a19ade5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-conversion.h @@ -0,0 +1,76 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_CONVERSION_H +#define ECMA_CONVERSION_H + +#include "ecma-builtins.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaconversion ECMA conversion routines + * @{ + */ + +/** + * Second argument of 'ToPrimitive' operation that is a hint, + * specifying the preferred type of conversion result. + */ +typedef enum +{ + ECMA_PREFERRED_TYPE_NO = 0, /**< no preferred type is specified */ + ECMA_PREFERRED_TYPE_NUMBER, /**< Number */ + ECMA_PREFERRED_TYPE_STRING /**< String */ +} ecma_preferred_type_hint_t; + +/** + * Option bits for ecma_op_to_numeric. + */ +typedef enum +{ + ECMA_TO_NUMERIC_NO_OPTS = 0, /**< no options (same as toNumber operation) */ + ECMA_TO_NUMERIC_ALLOW_BIGINT = (1 << 0), /**< allow BigInt values (ignored if BigInts are disabled) */ +} ecma_to_numeric_options_t; + +bool ecma_op_require_object_coercible (ecma_value_t value); +bool ecma_op_same_value (ecma_value_t x, ecma_value_t y); +#if JERRY_BUILTIN_CONTAINER +bool ecma_op_same_value_zero (ecma_value_t x, ecma_value_t y, bool strict_equality); +#endif /* JERRY_BUILTIN_CONTAINER */ +ecma_value_t ecma_op_to_primitive (ecma_value_t value, ecma_preferred_type_hint_t preferred_type); +bool ecma_op_to_boolean (ecma_value_t value); +ecma_value_t ecma_op_to_number (ecma_value_t value, ecma_number_t *number_p); +ecma_value_t ecma_op_to_numeric (ecma_value_t value, ecma_number_t *number_p, ecma_to_numeric_options_t options); +ecma_string_t *ecma_op_to_string (ecma_value_t value); +ecma_string_t *ecma_op_to_property_key (ecma_value_t value); +ecma_value_t ecma_op_to_object (ecma_value_t value); +bool ecma_op_is_integer (ecma_number_t value); +ecma_value_t ecma_op_to_integer (ecma_value_t value, ecma_number_t *number_p); +ecma_value_t ecma_op_to_length (ecma_value_t value, ecma_length_t *length); +ecma_value_t ecma_op_to_index (ecma_value_t value, ecma_number_t *index); +ecma_collection_t *ecma_op_create_list_from_array_like (ecma_value_t arr, bool prop_names_only); + +ecma_object_t *ecma_op_from_property_descriptor (const ecma_property_descriptor_t *src_prop_desc_p); +ecma_value_t ecma_op_to_property_descriptor (ecma_value_t obj_value, ecma_property_descriptor_t *out_prop_desc_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_CONVERSION_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-dataview-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-dataview-object.cpp new file mode 100644 index 0000000..d82289d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-dataview-object.cpp @@ -0,0 +1,409 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-dataview-object.h" + +#include "ecma-arraybuffer-object.h" +#include "ecma-bigint.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-shared-arraybuffer-object.h" +#include "ecma-typedarray-object.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_DATAVIEW + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmadataviewobject ECMA builtin DataView helper functions + * @{ + */ + +/** + * Handle calling [[Construct]] of built-in DataView like objects + * + * See also: + * ECMA-262 v11, 24.3.2.1 + * + * @return created DataView object as an ecma-value - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + JERRY_ASSERT (JERRY_CONTEXT (current_new_target_p)); + + ecma_value_t buffer = arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED; + + /* 2. */ + if (!ecma_is_value_object (buffer)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_BUFFER_NOT_OBJECT); + } + + ecma_object_t *buffer_p = ecma_get_object_from_value (buffer); + + if (!(ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (buffer_p))) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_BUFFER_NOT_ARRAY_OR_SHARED_BUFFER); + } + + /* 3. */ + ecma_number_t offset = 0; + + if (arguments_list_len > 1) + { + ecma_value_t offset_value = ecma_op_to_index (arguments_list_p[1], &offset); + if (ECMA_IS_VALUE_ERROR (offset_value)) + { + return offset_value; + } + } + + /* 4. */ + if (ecma_arraybuffer_is_detached (buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* 5. */ + ecma_number_t buffer_byte_length = ecma_arraybuffer_get_length (buffer_p); + + /* 6. */ + if (offset > buffer_byte_length) + { + return ecma_raise_range_error (ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER); + } + + /* 7. */ + uint32_t view_byte_length; + if (arguments_list_len > 2 && !ecma_is_value_undefined (arguments_list_p[2])) + { + /* 8.a */ + ecma_number_t byte_length_to_index; + ecma_value_t byte_length_value = ecma_op_to_index (arguments_list_p[2], &byte_length_to_index); + + if (ECMA_IS_VALUE_ERROR (byte_length_value)) + { + return byte_length_value; + } + + /* 8.b */ + if (offset + byte_length_to_index > buffer_byte_length) + { + return ecma_raise_range_error (ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER); + } + + JERRY_ASSERT (byte_length_to_index <= UINT32_MAX); + view_byte_length = (uint32_t) byte_length_to_index; + } + else + { + /* 7.a */ + view_byte_length = (uint32_t) (buffer_byte_length - offset); + } + + /* 9. */ + ecma_object_t *prototype_obj_p = + ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE); + if (JERRY_UNLIKELY (prototype_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* 10. */ + if (ecma_arraybuffer_is_detached (buffer_p)) + { + ecma_deref_object (prototype_obj_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* 9. */ + /* It must happen after 10., because uninitialized object can't be destroyed properly. */ + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_dataview_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_deref_object (prototype_obj_p); + + /* 11 - 14. */ + ecma_dataview_object_t *dataview_obj_p = (ecma_dataview_object_t *) object_p; + dataview_obj_p->header.u.cls.type = ECMA_OBJECT_CLASS_DATAVIEW; + dataview_obj_p->header.u.cls.u3.length = view_byte_length; + dataview_obj_p->buffer_p = buffer_p; + dataview_obj_p->byte_offset = (uint32_t) offset; + + return ecma_make_object_value (object_p); +} /* ecma_op_dataview_create */ + +/** + * Get the DataView object pointer + * + * Note: + * If the function returns with NULL, the error object has + * already set, and the caller must return with ECMA_VALUE_ERROR + * + * @return pointer to the dataView if this_arg is a valid dataView object + * NULL otherwise + */ +ecma_dataview_object_t * +ecma_op_dataview_get_object (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_DATAVIEW)) + { + return (ecma_dataview_object_t *) object_p; + } + } + + ecma_raise_type_error (ECMA_ERR_EXPECTED_A_DATAVIEW_OBJECT); + return NULL; +} /* ecma_op_dataview_get_object */ + +/** + * Helper union to specify the system's endianness + */ +typedef union +{ + uint32_t number; /**< for write numeric data */ + char data[sizeof (uint32_t)]; /**< for read numeric data */ +} ecma_dataview_endianness_check_t; + +/** + * Helper function to check the current system endianness + * + * @return true - if the current system has little endian byteorder + * false - otherwise + */ +static bool +ecma_dataview_check_little_endian (void) +{ + ecma_dataview_endianness_check_t checker; + checker.number = 0x01; + + return checker.data[0] == 0x01; +} /* ecma_dataview_check_little_endian */ + +/** + * Helper function for swap bytes if the system's endianness + * does not match with the requested endianness. + */ +static void +ecma_dataview_swap_order (bool system_is_little_endian, /**< true - if the system has little endian byteorder + * false - otherwise */ + bool is_little_endian, /**< true - if little endian byteorder is requested + * false - otherwise */ + uint32_t element_size, /**< element size byte according to the Table 49.*/ + lit_utf8_byte_t *block_p) /**< data block */ +{ + if (system_is_little_endian ^ is_little_endian) + { + for (uint32_t i = 0; i < element_size / 2; i++) + { + lit_utf8_byte_t tmp = block_p[i]; + block_p[i] = block_p[element_size - i - 1]; + block_p[element_size - i - 1] = tmp; + } + } +} /* ecma_dataview_swap_order */ + +/** + * GetViewValue and SetViewValue abstract operation + * + * See also: + * ECMA-262 v11, 24.3.1.1 + * ECMA-262 v11, 24.3.1.2 + * + * @return ecma value + */ +ecma_value_t +ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'view' argument */ + ecma_value_t request_index, /**< the operation's 'requestIndex' argument */ + ecma_value_t is_little_endian_value, /**< the operation's + * 'isLittleEndian' argument */ + ecma_value_t value_to_set, /**< the operation's 'value' argument */ + ecma_typedarray_type_t id) /**< the operation's 'type' argument */ +{ + /* 1 - 2. */ + ecma_dataview_object_t *view_p = ecma_op_dataview_get_object (view); + + if (JERRY_UNLIKELY (view_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *buffer_p = view_p->buffer_p; + JERRY_ASSERT (ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) + || ecma_object_is_shared_arraybuffer (buffer_p)); + + /* 3. */ + ecma_number_t get_index; + ecma_value_t number_index_value = ecma_op_to_index (request_index, &get_index); + + if (ECMA_IS_VALUE_ERROR (number_index_value)) + { + return number_index_value; + } + + /* SetViewValue 4 - 5. */ + if (!ecma_is_value_empty (value_to_set)) + { +#if JERRY_BUILTIN_BIGINT + if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (id)) + { + value_to_set = ecma_bigint_to_bigint (value_to_set, true); + + if (ECMA_IS_VALUE_ERROR (value_to_set)) + { + return value_to_set; + } + } + else +#endif /* JERRY_BUILTIN_BIGINT */ + { + ecma_number_t value_to_set_number; + ecma_value_t value = ecma_op_to_number (value_to_set, &value_to_set_number); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + value_to_set = ecma_make_number_value (value_to_set_number); + } + } + + /* GetViewValue 4., SetViewValue 6. */ + bool is_little_endian = ecma_op_to_boolean (is_little_endian_value); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (buffer_p)) + { + ecma_free_value (value_to_set); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (buffer_p)) + { + ecma_free_value (value_to_set); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* GetViewValue 7., SetViewValue 9. */ + uint32_t view_offset = view_p->byte_offset; + + /* GetViewValue 8., SetViewValue 10. */ + uint32_t view_size = view_p->header.u.cls.u3.length; + + /* GetViewValue 9., SetViewValue 11. */ + uint8_t element_size = (uint8_t) (1 << (ecma_typedarray_helper_get_shift_size (id))); + + /* GetViewValue 10., SetViewValue 12. */ + if (get_index + element_size > (ecma_number_t) view_size) + { + ecma_free_value (value_to_set); + return ecma_raise_range_error (ECMA_ERR_START_OFFSET_IS_OUTSIDE_THE_BOUNDS_OF_THE_BUFFER); + } + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (buffer_p)) + { + ecma_free_value (value_to_set); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (buffer_p)) + { + ecma_free_value (value_to_set); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + /* GetViewValue 11., SetViewValue 13. */ + bool system_is_little_endian = ecma_dataview_check_little_endian (); + + ecma_typedarray_info_t info; + info.id = id; + info.length = view_size; + info.shift = ecma_typedarray_helper_get_shift_size (id); + info.element_size = element_size; + info.offset = view_p->byte_offset; + info.array_buffer_p = buffer_p; + + /* GetViewValue 12. */ + uint8_t *block_p = ecma_arraybuffer_get_buffer (buffer_p) + (uint32_t) get_index + view_offset; + + if (ecma_is_value_empty (value_to_set)) + { + JERRY_VLA (lit_utf8_byte_t, swap_block_p, element_size); + memcpy (swap_block_p, block_p, element_size * sizeof (lit_utf8_byte_t)); + ecma_dataview_swap_order (system_is_little_endian, is_little_endian, element_size, swap_block_p); + + ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info.id); + return typedarray_getter_cb (swap_block_p); + } + + if (!ecma_number_is_nan (get_index) && get_index <= 0) + { + get_index = 0; + } + + /* SetViewValue 14. */ + ecma_typedarray_setter_fn_t typedarray_setter_cb = ecma_get_typedarray_setter_fn (info.id); + ecma_value_t set_element = typedarray_setter_cb (block_p, value_to_set); + + ecma_free_value (value_to_set); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + return set_element; + } + + ecma_dataview_swap_order (system_is_little_endian, is_little_endian, element_size, block_p); + + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_dataview_get_set_view_value */ + +/** + * Check if the value is dataview + * + * @return true - if value is a DataView object + * false - otherwise + */ +bool +ecma_is_dataview (ecma_value_t value) /**< the target need to be checked */ +{ + if (!ecma_is_value_object (value)) + { + return false; + } + + return ecma_object_class_is (ecma_get_object_from_value (value), ECMA_OBJECT_CLASS_DATAVIEW); +} /* ecma_is_dataview */ + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_DATAVIEW */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-dataview-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-dataview-object.h new file mode 100644 index 0000000..1d56c9b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-dataview-object.h @@ -0,0 +1,46 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_DATAVIEW_OBJECT_H +#define ECMA_DATAVIEW_OBJECT_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_DATAVIEW + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmadataviewobject ECMA builtin DataView helper functions + * @{ + */ + +ecma_value_t ecma_op_dataview_create (const ecma_value_t *arguments_list_p, uint32_t arguments_list_len); +ecma_dataview_object_t *ecma_op_dataview_get_object (ecma_value_t this_arg); +ecma_value_t ecma_op_dataview_get_set_view_value (ecma_value_t view, + ecma_value_t request_index, + ecma_value_t little_endian, + ecma_value_t value_to_set, + ecma_typedarray_type_t id); +bool ecma_is_dataview (ecma_value_t value); + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_DATAVIEW */ + +#endif /* !ECMA_DATAVIEW_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-eval.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-eval.cpp new file mode 100644 index 0000000..ac8e2c4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-eval.cpp @@ -0,0 +1,100 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-eval.h" + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" + +#include "jcontext.h" +#include "js-parser.h" +#include "vm.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup eval eval + * @{ + */ + +/** + * Perform 'eval' with code stored in ecma-string + * + * See also: + * ecma_op_eval_chars_buffer + * ECMA-262 v5, 15.1.2.1 (steps 2 to 8) + * + * @return ecma value + */ +ecma_value_t +ecma_op_eval (ecma_value_t source_code, /**< source code */ + uint32_t parse_opts) /**< ecma_parse_opts_t option bits */ +{ + JERRY_ASSERT (ecma_is_value_string (source_code)); + + if (ecma_is_value_magic_string (source_code, LIT_MAGIC_STRING__EMPTY)) + { + return ECMA_VALUE_UNDEFINED; + } + + return ecma_op_eval_chars_buffer ((void *) &source_code, parse_opts | ECMA_PARSE_HAS_SOURCE_VALUE); +} /* ecma_op_eval */ + +/** + * Perform 'eval' with code stored in continuous character buffer + * + * See also: + * ecma_op_eval + * ECMA-262 v5, 15.1.2.1 (steps 2 to 8) + * + * @return ecma value + */ +ecma_value_t +ecma_op_eval_chars_buffer (void *source_p, /**< source code */ + uint32_t parse_opts) /**< ecma_parse_opts_t option bits */ +{ +#if JERRY_PARSER + JERRY_ASSERT (source_p != NULL); + + uint32_t is_strict_call = ECMA_PARSE_STRICT_MODE | ECMA_PARSE_DIRECT_EVAL; + + if ((parse_opts & is_strict_call) != is_strict_call) + { + parse_opts &= (uint32_t) ~ECMA_PARSE_STRICT_MODE; + } + + parse_opts |= ECMA_PARSE_EVAL; + + ECMA_CLEAR_LOCAL_PARSE_OPTS (); + + ecma_compiled_code_t *bytecode_p = parser_parse_script (source_p, parse_opts, NULL); + + if (JERRY_UNLIKELY (bytecode_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + return vm_run_eval (bytecode_p, parse_opts); +#endif /* JERRY_PARSER */ +} /* ecma_op_eval_chars_buffer */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-eval.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-eval.h new file mode 100644 index 0000000..c06ad5d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-eval.h @@ -0,0 +1,37 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_EVAL_H +#define ECMA_EVAL_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup eval eval + * @{ + */ + +ecma_value_t ecma_op_eval (ecma_value_t source_code, uint32_t parse_opts); + +ecma_value_t ecma_op_eval_chars_buffer (void *source_p, uint32_t parse_opts); + +/** + * @} + * @} + */ + +#endif /* !ECMA_EVAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-exceptions.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-exceptions.cpp new file mode 100644 index 0000000..019fb03 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-exceptions.cpp @@ -0,0 +1,500 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-exceptions.h" + +#include + +#include "ecma-array-object.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" +#include "ecma-symbol-object.h" + +#include "jcontext.h" +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup exceptions Exceptions + * @{ + */ + +/** + * Standard ecma-error object constructor. + * + * Note: + * message_string_p can be NULL. + * + * Note: + * calling with JERRY_ERROR_NONE does not make sense thus it will + * cause a fault in the system. + * + * @return pointer to ecma-object representing specified error + * with reference counter set to one. + */ +ecma_object_t * +ecma_new_standard_error (jerry_error_t error_type, /**< native error type */ + ecma_string_t *message_string_p) /**< message string */ +{ +#if JERRY_BUILTIN_ERRORS + ecma_builtin_id_t prototype_id = ECMA_BUILTIN_ID__COUNT; + + switch (error_type) + { + case JERRY_ERROR_EVAL: + { + prototype_id = ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE; + break; + } + + case JERRY_ERROR_RANGE: + { + prototype_id = ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE; + break; + } + + case JERRY_ERROR_REFERENCE: + { + prototype_id = ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE; + break; + } + + case JERRY_ERROR_TYPE: + { + prototype_id = ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE; + break; + } + + case JERRY_ERROR_AGGREGATE: + { + prototype_id = ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE; + break; + } + + case JERRY_ERROR_URI: + { + prototype_id = ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE; + break; + } + + case JERRY_ERROR_SYNTAX: + { + prototype_id = ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE; + break; + } + + default: + { + JERRY_ASSERT (error_type == JERRY_ERROR_COMMON); + + prototype_id = ECMA_BUILTIN_ID_ERROR_PROTOTYPE; + break; + } + } +#else /* !JERRY_BUILTIN_ERRORS */ + JERRY_UNUSED (error_type); + ecma_builtin_id_t prototype_id = ECMA_BUILTIN_ID_ERROR_PROTOTYPE; +#endif /* JERRY_BUILTIN_ERRORS */ + + ecma_object_t *prototype_obj_p = ecma_builtin_get (prototype_id); + + ecma_object_t *error_object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *extended_object_p = (ecma_extended_object_t *) error_object_p; + extended_object_p->u.cls.type = ECMA_OBJECT_CLASS_ERROR; + extended_object_p->u.cls.u1.error_type = (uint8_t) error_type; + + if (message_string_p != NULL) + { + ecma_property_value_t *prop_value_p; + prop_value_p = ecma_create_named_data_property (error_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE), + ECMA_PROPERTY_CONFIGURABLE_WRITABLE, + NULL); + + ecma_ref_ecma_string (message_string_p); + prop_value_p->value = ecma_make_string_value (message_string_p); + } + + /* Avoid calling the decorator function recursively. */ + if (JERRY_CONTEXT (error_object_created_callback_p) != NULL + && !(JERRY_CONTEXT (status_flags) & ECMA_STATUS_ERROR_UPDATE)) + { + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_ERROR_UPDATE; + JERRY_CONTEXT (error_object_created_callback_p) + (ecma_make_object_value (error_object_p), JERRY_CONTEXT (error_object_created_callback_user_p)); + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_ERROR_UPDATE; + } + + return error_object_p; +} /* ecma_new_standard_error */ + +/** + * aggregate-error object constructor. + * + * @return newly constructed aggregate errors + */ +ecma_value_t +ecma_new_aggregate_error (ecma_value_t error_list_val, /**< errors list */ + ecma_value_t message_val) /**< message string */ +{ + ecma_object_t *new_error_object_p; + + if (!ecma_is_value_undefined (message_val)) + { + ecma_string_t *message_string_p = ecma_op_to_string (message_val); + + if (JERRY_UNLIKELY (message_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + new_error_object_p = ecma_new_standard_error (JERRY_ERROR_AGGREGATE, message_string_p); + ecma_deref_ecma_string (message_string_p); + } + else + { + new_error_object_p = ecma_new_standard_error (JERRY_ERROR_AGGREGATE, NULL); + } + + ecma_value_t using_iterator = ecma_op_get_method_by_symbol_id (error_list_val, LIT_GLOBAL_SYMBOL_ITERATOR); + + if (ECMA_IS_VALUE_ERROR (using_iterator)) + { + ecma_deref_object (new_error_object_p); + return using_iterator; + } + + if (!ecma_is_value_undefined (using_iterator)) + { + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (error_list_val, using_iterator, &next_method); + ecma_free_value (using_iterator); + + if (ECMA_IS_VALUE_ERROR (iterator)) + { + ecma_deref_object (new_error_object_p); + return iterator; + } + + ecma_collection_t *error_list_p = ecma_new_collection (); + ecma_value_t result = ECMA_VALUE_ERROR; + + while (true) + { + ecma_value_t next = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (next)) + { + break; + } + + if (next == ECMA_VALUE_FALSE) + { + result = ECMA_VALUE_UNDEFINED; + break; + } + + /* 8.e.iii */ + ecma_value_t next_error = ecma_op_iterator_value (next); + ecma_free_value (next); + + if (ECMA_IS_VALUE_ERROR (next_error)) + { + break; + } + + ecma_collection_push_back (error_list_p, next_error); + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_collection_free (error_list_p); + ecma_deref_object (new_error_object_p); + return result; + } + + JERRY_ASSERT (ecma_is_value_undefined (result)); + + ecma_value_t error_list_arr = ecma_op_new_array_object_from_collection (error_list_p, true); + ecma_property_value_t *prop_value_p; + prop_value_p = ecma_create_named_data_property (new_error_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_ERRORS_UL), + ECMA_PROPERTY_CONFIGURABLE_WRITABLE, + NULL); + prop_value_p->value = error_list_arr; + ecma_free_value (error_list_arr); + } + + return ecma_make_object_value (new_error_object_p); +} /* ecma_new_aggregate_error */ + +/** + * Return the error type for an Error object. + * + * @return one of the jerry_error_t value + * if it is not an Error object then JERRY_ERROR_NONE will be returned + */ +jerry_error_t +ecma_get_error_type (ecma_object_t *error_object_p) /**< possible error object */ +{ + if (!ecma_object_class_is (error_object_p, ECMA_OBJECT_CLASS_ERROR)) + { + return JERRY_ERROR_NONE; + } + + return (jerry_error_t) ((ecma_extended_object_t *) error_object_p)->u.cls.u1.error_type; +} /* ecma_get_error_type */ + +/** + * Raise a standard ecma-error with the given type and message. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_standard_error (jerry_error_t error_type, /**< error type */ + ecma_error_msg_t msg) /**< error message */ +{ + ecma_object_t *error_obj_p; + const lit_utf8_byte_t *str_p = (lit_utf8_byte_t *) ecma_get_error_msg (msg); + + if (msg != ECMA_ERR_EMPTY) + { + ecma_string_t *error_msg_p = ecma_new_ecma_external_string_from_cesu8 (str_p, ecma_get_error_size (msg), NULL); + error_obj_p = ecma_new_standard_error (error_type, error_msg_p); + ecma_deref_ecma_string (error_msg_p); + } + else + { + error_obj_p = ecma_new_standard_error (error_type, NULL); + } + + jcontext_raise_exception (ecma_make_object_value (error_obj_p)); + return ECMA_VALUE_ERROR; +} /* ecma_raise_standard_error */ + +#if JERRY_ERROR_MESSAGES + +/** + * Raise a standard ecma-error with the given format string and arguments. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_standard_error_with_format (jerry_error_t error_type, /**< error type */ + const char *format, /**< format string */ + ...) /**< ecma-values */ +{ + JERRY_ASSERT (format != NULL); + + ecma_stringbuilder_t builder = ecma_stringbuilder_create (); + + const char *start_p = format; + const char *end_p = format; + + va_list args; + + va_start (args, format); + + while (*end_p) + { + if (*end_p == '%') + { + /* Concat template string. */ + if (end_p > start_p) + { + ecma_stringbuilder_append_raw (&builder, (lit_utf8_byte_t *) start_p, (lit_utf8_size_t) (end_p - start_p)); + } + + /* Convert an argument to string without side effects. */ + ecma_string_t *arg_string_p; + const ecma_value_t arg_val = va_arg (args, ecma_value_t); + + if (JERRY_UNLIKELY (ecma_is_value_object (arg_val))) + { + ecma_object_t *arg_object_p = ecma_get_object_from_value (arg_val); + lit_magic_string_id_t class_name = ecma_object_get_class_name (arg_object_p); + arg_string_p = ecma_get_magic_string (class_name); + } + else if (ecma_is_value_symbol (arg_val)) + { + ecma_value_t symbol_desc_value = ecma_get_symbol_descriptive_string (arg_val); + arg_string_p = ecma_get_string_from_value (symbol_desc_value); + } + else + { + arg_string_p = ecma_op_to_string (arg_val); + JERRY_ASSERT (arg_string_p != NULL); + } + + /* Concat argument. */ + ecma_stringbuilder_append (&builder, arg_string_p); + + ecma_deref_ecma_string (arg_string_p); + + start_p = end_p + 1; + } + + end_p++; + } + + va_end (args); + + /* Concat reset of template string. */ + if (start_p < end_p) + { + ecma_stringbuilder_append_raw (&builder, (lit_utf8_byte_t *) start_p, (lit_utf8_size_t) (end_p - start_p)); + } + + ecma_string_t *builder_str_p = ecma_stringbuilder_finalize (&builder); + + ecma_object_t *error_obj_p = ecma_new_standard_error (error_type, builder_str_p); + + ecma_deref_ecma_string (builder_str_p); + + jcontext_raise_exception (ecma_make_object_value (error_obj_p)); + return ECMA_VALUE_ERROR; +} /* ecma_raise_standard_error_with_format */ + +#endif /* JERRY_ERROR_MESSAGES */ + +/** + * Raise a common error with the given message. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_common_error (ecma_error_msg_t msg) /**< error message */ +{ + return ecma_raise_standard_error (JERRY_ERROR_COMMON, msg); +} /* ecma_raise_common_error */ + +/** + * Raise a RangeError with the given message. + * + * See also: ECMA-262 v5, 15.11.6.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_range_error (ecma_error_msg_t msg) /**< error message */ +{ + return ecma_raise_standard_error (JERRY_ERROR_RANGE, msg); +} /* ecma_raise_range_error */ + +/** + * Raise a ReferenceError with the given message. + * + * See also: ECMA-262 v5, 15.11.6.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_reference_error (ecma_error_msg_t msg) /**< error message */ +{ + return ecma_raise_standard_error (JERRY_ERROR_REFERENCE, msg); +} /* ecma_raise_reference_error */ + +/** + * Raise a SyntaxError with the given message. + * + * See also: ECMA-262 v5, 15.11.6.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_syntax_error (ecma_error_msg_t msg) /**< error message */ +{ + return ecma_raise_standard_error (JERRY_ERROR_SYNTAX, msg); +} /* ecma_raise_syntax_error */ + +/** + * Raise a TypeError with the given message. + * + * See also: ECMA-262 v5, 15.11.6.5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_type_error (ecma_error_msg_t msg) /**< error message */ +{ + return ecma_raise_standard_error (JERRY_ERROR_TYPE, msg); +} /* ecma_raise_type_error */ + +/** + * Raise a URIError with the given message. + * + * See also: ECMA-262 v5, 15.11.6.6 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_uri_error (ecma_error_msg_t msg) /**< error message */ +{ + return ecma_raise_standard_error (JERRY_ERROR_URI, msg); +} /* ecma_raise_uri_error */ + +#if (JERRY_STACK_LIMIT != 0) +/** + * Raise a RangeError with "Maximum call stack size exceeded" message. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_maximum_callstack_error (void) +{ + return ecma_raise_range_error (ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED); +} /* ecma_raise_maximum_callstack_error */ +#endif /* (JERRY_STACK_LIMIT != 0) */ + +/** + * Raise a AggregateError with the given errors and message. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_raise_aggregate_error (ecma_value_t error_list_val, /**< errors list */ + ecma_value_t message_val) /**< error message */ +{ + ecma_value_t aggre_val = ecma_new_aggregate_error (error_list_val, message_val); + jcontext_raise_exception (aggre_val); + + return ECMA_VALUE_ERROR; +} /* ecma_raise_aggregate_error */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-exceptions.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-exceptions.h new file mode 100644 index 0000000..c367a6b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-exceptions.h @@ -0,0 +1,53 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_EXCEPTIONS_H +#define ECMA_EXCEPTIONS_H + +#include "ecma-globals.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup exceptions Exceptions + * @{ + */ + +jerry_error_t ecma_get_error_type (ecma_object_t *error_object_p); +ecma_object_t *ecma_new_standard_error (jerry_error_t error_type, ecma_string_t *message_string_p); +#if JERRY_ERROR_MESSAGES +ecma_value_t ecma_raise_standard_error_with_format (jerry_error_t error_type, const char *msg_p, ...); +#endif /* JERRY_ERROR_MESSAGES */ +ecma_value_t ecma_raise_standard_error (jerry_error_t error_type, ecma_error_msg_t msg); +ecma_value_t ecma_raise_common_error (ecma_error_msg_t msg); +ecma_value_t ecma_raise_range_error (ecma_error_msg_t msg); +ecma_value_t ecma_raise_reference_error (ecma_error_msg_t msg); +ecma_value_t ecma_raise_syntax_error (ecma_error_msg_t msg); +ecma_value_t ecma_raise_type_error (ecma_error_msg_t msg); +ecma_value_t ecma_raise_uri_error (ecma_error_msg_t msg); +#if (JERRY_STACK_LIMIT != 0) +ecma_value_t ecma_raise_maximum_callstack_error (void); +#endif /* (JERRY_STACK_LIMIT != 0) */ +ecma_value_t ecma_new_aggregate_error (ecma_value_t error_list_val, ecma_value_t message_val); +ecma_value_t ecma_raise_aggregate_error (ecma_value_t error_list_val, ecma_value_t message_val); + +/** + * @} + * @} + */ + +#endif /* !ECMA_EXCEPTIONS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-function-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-function-object.cpp new file mode 100644 index 0000000..8d6738d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-function-object.cpp @@ -0,0 +1,2207 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-function-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtin-handlers.h" +#include "ecma-builtin-helpers.h" +#include "ecma-errors.h" +#include "ecma-exceptions.h" +#include "ecma-extended-info.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" +#include "ecma-proxy-object.h" +#include "ecma-symbol-object.h" + +#include "jcontext.h" +#include "lit-char-helpers.h" +#include "opcodes.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmafunctionobject ECMA Function object related routines + * @{ + */ + +/** + * SetFunctionName operation + * + * See also: ECMAScript v6, 9.2.1.1 + * + * @return source name as ecma-string + */ +ecma_value_t +ecma_op_function_form_name (ecma_string_t *prop_name_p, /**< property name */ + char *prefix_p, /**< prefix */ + lit_utf8_size_t prefix_size) /**< prefix length */ +{ + /* 4. */ + if (ecma_prop_name_is_symbol (prop_name_p)) + { + /* .a */ + ecma_value_t string_desc = ecma_get_symbol_description (prop_name_p); + + /* .b */ + if (ecma_is_value_undefined (string_desc)) + { + prop_name_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + /* .c */ + else + { + ecma_string_t *string_desc_p = ecma_get_string_from_value (string_desc); + ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) "[", 1); + ecma_stringbuilder_append (&builder, string_desc_p); + ecma_stringbuilder_append_byte (&builder, (lit_utf8_byte_t) LIT_CHAR_RIGHT_SQUARE); + prop_name_p = ecma_stringbuilder_finalize (&builder); + } + } + else + { + ecma_ref_ecma_string (prop_name_p); + } + + /* 5. */ + if (JERRY_UNLIKELY (prefix_p != NULL)) + { + ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) prefix_p, prefix_size); + ecma_stringbuilder_append (&builder, prop_name_p); + ecma_deref_ecma_string (prop_name_p); + prop_name_p = ecma_stringbuilder_finalize (&builder); + } + + return ecma_make_string_value (prop_name_p); +} /* ecma_op_function_form_name */ + +#if JERRY_BUILTIN_PROXY +/** + * IsCallable operation for proxy object. + * + * @return true - if the given proxy object is callable; + * false - otherwise + */ +bool +ecma_op_proxy_object_is_callable (ecma_object_t *obj_p) /**< ecma object */ +{ + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + + return (obj_p->u2.prototype_cp & ECMA_PROXY_IS_CALLABLE) != 0; +} /* ecma_op_proxy_object_is_callable */ +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * IsCallable operation. + * + * See also: ECMA-262 v5, 9.11 + * + * @return true - if the given object is callable; + * false - otherwise + */ +bool +ecma_op_object_is_callable (ecma_object_t *obj_p) /**< ecma object */ +{ + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + + const ecma_object_type_t type = ecma_get_object_type (obj_p); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_TYPE_IS_PROXY (type)) + { + return ecma_op_proxy_object_is_callable (obj_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + return type >= ECMA_OBJECT_TYPE_FUNCTION; +} /* ecma_op_object_is_callable */ + +/** + * IsCallable operation. + * + * See also: ECMA-262 v5, 9.11 + * + * @return true - if value is callable object; + * false - otherwise + */ +bool +ecma_op_is_callable (ecma_value_t value) /**< ecma value */ +{ + return (ecma_is_value_object (value) && ecma_op_object_is_callable (ecma_get_object_from_value (value))); +} /* ecma_op_is_callable */ + +/** + * Implement IsConstructor abstract operation. + * + * + * @return ECMA_IS_VALID_CONSTRUCTOR - if object is a valid for constructor call + * ecma_error_msg_t id of error - otherwise + */ +ecma_error_msg_t +ecma_object_check_constructor (ecma_object_t *obj_p) /**< ecma object */ +{ + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + + ecma_object_type_t type = ecma_get_object_type (obj_p); + + if (JERRY_UNLIKELY (type < ECMA_OBJECT_TYPE_PROXY)) + { + return ECMA_ERR_INVALID_TYPE_FOR_CONSTRUCTOR_CALL; + } + + while (JERRY_UNLIKELY (type == ECMA_OBJECT_TYPE_BOUND_FUNCTION)) + { + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) obj_p; + + obj_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, bound_func_p->header.u.bound_function.target_function); + + type = ecma_get_object_type (obj_p); + } + + if (JERRY_LIKELY (type == ECMA_OBJECT_TYPE_FUNCTION)) + { + const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) obj_p); + + if (!CBC_FUNCTION_IS_CONSTRUCTABLE (byte_code_p->status_flags)) + { +#if JERRY_ERROR_MESSAGES + switch (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags)) + { + case CBC_FUNCTION_SCRIPT: + { + return ECMA_ERR_SCRIPT_GLOBAL_FUNCTIONS_INVOKE_WITH_NEW; + } + case CBC_FUNCTION_GENERATOR: + { + return ECMA_ERR_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW; + } + case CBC_FUNCTION_ASYNC: + { + return ECMA_ERR_ASYNC_FUNCTIONS_INVOKE_WITH_NEW; + } + case CBC_FUNCTION_ASYNC_GENERATOR: + { + return ECMA_ERR_ASYNC_GENERATOR_FUNCTIONS_INVOKE_WITH_NEW; + } + case CBC_FUNCTION_ACCESSOR: + { + return ECMA_ERR_ACCESSOR_FUNCTIONS_INVOKE_WITH_NEW; + } + case CBC_FUNCTION_METHOD: + { + return ECMA_ERR_METHODS_INVOKE_WITH_NEW; + } + case CBC_FUNCTION_ARROW: + { + return ECMA_ERR_ARROW_FUNCTIONS_INVOKE_WITH_NEW; + } + default: + { + JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags) == CBC_FUNCTION_ASYNC_ARROW); + return ECMA_ERR_ASYNC_ARROW_FUNCTIONS_INVOKE_WITH_NEW; + } + } +#else /* !JERRY_ERROR_MESSAGES */ + return ECMA_ERR_EMPTY; +#endif /* JERRY_ERROR_MESSAGES */ + } + + return ECMA_IS_VALID_CONSTRUCTOR; + } + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_TYPE_IS_PROXY (type)) + { + if (!(obj_p->u2.prototype_cp & ECMA_PROXY_IS_CONSTRUCTABLE)) + { + return ECMA_ERR_PROXY_TARGET_IS_NOT_A_CONSTRUCTOR; + } + + return ECMA_IS_VALID_CONSTRUCTOR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + JERRY_ASSERT (type == ECMA_OBJECT_TYPE_NATIVE_FUNCTION || type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION + || type == ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION); + + if (type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION) + { + if (ecma_builtin_function_is_routine (obj_p)) + { + return ECMA_ERR_BUILTIN_ROUTINES_HAVE_NO_CONSTRUCTOR; + } + + JERRY_ASSERT (((ecma_extended_object_t *) obj_p)->u.built_in.id != ECMA_BUILTIN_ID_HANDLER); + } + + return ECMA_IS_VALID_CONSTRUCTOR; +} /* ecma_object_check_constructor */ + +/** + * Implement IsConstructor abstract operation. + * + * @return ECMA_IS_VALID_CONSTRUCTOR - if the input value is a constructor. + * ecma_error_msg_t id of error - otherwise + */ +ecma_error_msg_t +ecma_check_constructor (ecma_value_t value) /**< ecma object */ +{ + if (!ecma_is_value_object (value)) + { + return ECMA_ERR_INVALID_TYPE_FOR_CONSTRUCTOR_CALL; + } + + return ecma_object_check_constructor (ecma_get_object_from_value (value)); +} /* ecma_check_constructor */ + +/** + * Checks whether the given object implements [[Construct]]. + * + * @return true - if the given object is constructor; + * false - otherwise + */ +bool +ecma_object_is_constructor (ecma_object_t *obj_p) /**< ecma object */ +{ + return ecma_object_check_constructor (obj_p) == ECMA_IS_VALID_CONSTRUCTOR; +} /* ecma_object_is_constructor */ + +/** + * Checks whether the value is Object that implements [[Construct]]. + * + * @return true - if value is constructor object; + * false - otherwise + */ +bool +ecma_is_constructor (ecma_value_t value) /**< ecma value */ +{ + return (ecma_is_value_object (value) && ecma_object_is_constructor (ecma_get_object_from_value (value))); +} /* ecma_is_constructor */ + +/** + * Helper method to count and convert the arguments for the Function/GeneratorFunction constructor call. + * + * See also: + * ECMA 262 v5.1 15.3.2.1 steps 5.a-d + * ECMA 262 v6 19.2.1.1.1 steps 8 + * + * @return ecma value - concatenated arguments as a string. + * Returned value must be freed with ecma_free_value. + */ +static ecma_string_t * +ecma_op_create_dynamic_function_arguments_helper (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len <= 1) + { + return ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_string_t *str_p = ecma_op_to_string (arguments_list_p[0]); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return str_p; + } + + if (arguments_list_len == 2) + { + return str_p; + } + + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (str_p); + ecma_deref_ecma_string (str_p); + + for (uint32_t idx = 1; idx < arguments_list_len - 1; idx++) + { + str_p = ecma_op_to_string (arguments_list_p[idx]); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + ecma_stringbuilder_destroy (&builder); + return str_p; + } + + ecma_stringbuilder_append_char (&builder, LIT_CHAR_COMMA); + ecma_stringbuilder_append (&builder, str_p); + ecma_deref_ecma_string (str_p); + } + + return ecma_stringbuilder_finalize (&builder); +} /* ecma_op_create_dynamic_function_arguments_helper */ + +/** + * Function object creation operation. + * + * See also: ECMA-262 v5, 13.2 + * + * @return pointer to newly created Function object + */ +static ecma_object_t * +ecma_op_create_function_object (ecma_object_t *scope_p, /**< function's scope */ + const ecma_compiled_code_t *bytecode_data_p, /**< byte-code array */ + ecma_builtin_id_t proto_id) /**< builtin id of the prototype object */ +{ + JERRY_ASSERT (ecma_is_lexical_environment (scope_p)); + + /* 1., 4., 13. */ + ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id); + + size_t function_object_size = sizeof (ecma_extended_object_t); + +#if JERRY_SNAPSHOT_EXEC + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION) + { + function_object_size = sizeof (ecma_static_function_t); + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + ecma_object_t *func_p = ecma_create_object (prototype_obj_p, function_object_size, ECMA_OBJECT_TYPE_FUNCTION); + + /* 2., 6., 7., 8. */ + /* + * We don't setup [[Get]], [[Call]], [[Construct]], [[HasInstance]] for each function object. + * Instead we set the object's type to ECMA_OBJECT_TYPE_FUNCTION + * that defines which version of the routine should be used on demand. + */ + + /* 3. */ + /* + * [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_FUNCTION type. + * + * See also: ecma_object_get_class_name + */ + + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_p; + + /* 9. */ + ECMA_SET_NON_NULL_POINTER_TAG (ext_func_p->u.function.scope_cp, scope_p, 0); + + /* 10., 11., 12. */ + +#if JERRY_SNAPSHOT_EXEC + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION) + { + ext_func_p->u.function.bytecode_cp = JMEM_CP_NULL; + ((ecma_static_function_t *) func_p)->bytecode_p = bytecode_data_p; + } + else +#endif /* JERRY_SNAPSHOT_EXEC */ + { + ECMA_SET_INTERNAL_VALUE_POINTER (ext_func_p->u.function.bytecode_cp, bytecode_data_p); + ecma_bytecode_ref ((ecma_compiled_code_t *) bytecode_data_p); + } + + /* 14., 15., 16., 17., 18. */ + /* + * 'length' and 'prototype' properties are instantiated lazily + * + * See also: ecma_op_function_try_to_lazy_instantiate_property + */ + + return func_p; +} /* ecma_op_create_function_object */ + +/** + * CreateDynamicFunction operation + * + * See also: + * ECMA-262 v5, 15.3. + * ECMA-262 v6, 19.2.1.1 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * constructed function object - otherwise + */ +ecma_value_t +ecma_op_create_dynamic_function (const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len, /**< number of arguments */ + ecma_parse_opts_t parse_opts) /**< parse options */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_string_t *arguments_str_p = + ecma_op_create_dynamic_function_arguments_helper (arguments_list_p, arguments_list_len); + + if (JERRY_UNLIKELY (arguments_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_string_t *function_body_str_p; + + if (arguments_list_len > 0) + { + function_body_str_p = ecma_op_to_string (arguments_list_p[arguments_list_len - 1]); + + if (JERRY_UNLIKELY (function_body_str_p == NULL)) + { + ecma_deref_ecma_string (arguments_str_p); + return ECMA_VALUE_ERROR; + } + } + else + { + /* Very unlikely code path, not optimized. */ + function_body_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); + } + + ecma_value_t source[2]; + source[0] = ecma_make_string_value (function_body_str_p); + source[1] = ecma_make_string_value (arguments_str_p); + + parse_opts = (ecma_parse_opts_t) ((int) parse_opts | ((int) ECMA_PARSE_HAS_SOURCE_VALUE | (int) ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE)); + + ecma_compiled_code_t *bytecode_p = parser_parse_script ((void *) source, parse_opts, NULL); + + ecma_deref_ecma_string (arguments_str_p); + ecma_deref_ecma_string (function_body_str_p); + + if (JERRY_UNLIKELY (bytecode_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t *func_name_p; + func_name_p = ecma_compiled_code_resolve_function_name ((const ecma_compiled_code_t *) bytecode_p); + *func_name_p = ecma_make_magic_string_value (LIT_MAGIC_STRING_ANONYMOUS); + + ecma_object_t *global_object_p = ecma_builtin_get_global (); + +#if JERRY_BUILTIN_REALMS + JERRY_ASSERT (global_object_p == (ecma_object_t *) ecma_op_function_get_realm (bytecode_p)); +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_object_t *global_env_p = ecma_get_global_environment (global_object_p); + ecma_builtin_id_t fallback_proto = ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE; + ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target_p); + ecma_builtin_id_t fallback_ctor = ECMA_BUILTIN_ID_FUNCTION; + + if (JERRY_UNLIKELY (parse_opts & (ECMA_PARSE_GENERATOR_FUNCTION | ECMA_PARSE_ASYNC_FUNCTION))) + { + fallback_proto = ECMA_BUILTIN_ID_ASYNC_GENERATOR; + fallback_ctor = ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION; + + if (!(parse_opts & ECMA_PARSE_GENERATOR_FUNCTION)) + { + fallback_proto = ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE; + fallback_ctor = ECMA_BUILTIN_ID_ASYNC_FUNCTION; + } + else if (!(parse_opts & ECMA_PARSE_ASYNC_FUNCTION)) + { + fallback_proto = ECMA_BUILTIN_ID_GENERATOR; + fallback_ctor = ECMA_BUILTIN_ID_GENERATOR_FUNCTION; + } + } + + if (new_target_p == NULL) + { + new_target_p = ecma_builtin_get (fallback_ctor); + } + + ecma_object_t *proto = ecma_op_get_prototype_from_constructor (new_target_p, fallback_proto); + + if (JERRY_UNLIKELY (proto == NULL)) + { + ecma_bytecode_deref (bytecode_p); + return ECMA_VALUE_ERROR; + } + + ecma_object_t *func_obj_p = ecma_op_create_function_object (global_env_p, bytecode_p, fallback_proto); + + ECMA_SET_NON_NULL_POINTER (func_obj_p->u2.prototype_cp, proto); + ecma_deref_object (proto); + + ecma_bytecode_deref (bytecode_p); + return ecma_make_object_value (func_obj_p); +} /* ecma_op_create_dynamic_function */ + +/** + * Function object creation operation. + * + * See also: ECMA-262 v5, 13.2 + * + * @return pointer to newly created Function object + */ +ecma_object_t * +ecma_op_create_simple_function_object (ecma_object_t *scope_p, /**< function's scope */ + const ecma_compiled_code_t *bytecode_data_p) /**< byte-code array */ +{ + return ecma_op_create_function_object (scope_p, bytecode_data_p, ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); +} /* ecma_op_create_simple_function_object */ + +/** + * Create a function object with the appropriate prototype. + * + * @return pointer to newly created Function object + */ +ecma_object_t * +ecma_op_create_any_function_object (ecma_object_t *scope_p, /**< function's scope */ + const ecma_compiled_code_t *bytecode_data_p) /**< byte-code array */ +{ + ecma_builtin_id_t proto_id; + + switch (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags)) + { + case CBC_FUNCTION_GENERATOR: + { + proto_id = ECMA_BUILTIN_ID_GENERATOR; + break; + } + case CBC_FUNCTION_ASYNC: + { + proto_id = ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE; + break; + } + case CBC_FUNCTION_ASYNC_GENERATOR: + { + proto_id = ECMA_BUILTIN_ID_ASYNC_GENERATOR; + break; + } + default: + { + proto_id = ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE; + break; + } + } + + return ecma_op_create_function_object (scope_p, bytecode_data_p, proto_id); +} /* ecma_op_create_any_function_object */ + +/** + * Arrow function object creation operation. + * + * See also: ES2015, 9.2.12 + * + * @return pointer to newly created Function object + */ +ecma_object_t * +ecma_op_create_arrow_function_object (ecma_object_t *scope_p, /**< function's scope */ + const ecma_compiled_code_t *bytecode_data_p, /**< byte-code array */ + ecma_value_t this_binding) /**< value of 'this' binding */ +{ + ecma_object_t *prototype_obj_p; + + if (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_ARROW) + { + prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); + } + else + { + JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_ASYNC_ARROW); + prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE); + } + + size_t arrow_function_object_size = sizeof (ecma_arrow_function_t); + +#if JERRY_SNAPSHOT_EXEC + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION) + { + arrow_function_object_size = sizeof (ecma_static_arrow_function_t); + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + ecma_object_t *func_p = ecma_create_object (prototype_obj_p, arrow_function_object_size, ECMA_OBJECT_TYPE_FUNCTION); + + ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) func_p; + + ECMA_SET_NON_NULL_POINTER_TAG (arrow_func_p->header.u.function.scope_cp, scope_p, 0); + +#if JERRY_SNAPSHOT_EXEC + if ((bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)) + { + arrow_func_p->header.u.function.bytecode_cp = ECMA_NULL_POINTER; + ((ecma_static_arrow_function_t *) func_p)->bytecode_p = bytecode_data_p; + } + else + { +#endif /* JERRY_SNAPSHOT_EXEC */ + ECMA_SET_INTERNAL_VALUE_POINTER (arrow_func_p->header.u.function.bytecode_cp, bytecode_data_p); + ecma_bytecode_ref ((ecma_compiled_code_t *) bytecode_data_p); +#if JERRY_SNAPSHOT_EXEC + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + arrow_func_p->this_binding = ecma_copy_value_if_not_object (this_binding); + arrow_func_p->new_target = ECMA_VALUE_UNDEFINED; + + if (JERRY_CONTEXT (current_new_target_p) != NULL) + { + arrow_func_p->new_target = ecma_make_object_value (JERRY_CONTEXT (current_new_target_p)); + } + return func_p; +} /* ecma_op_create_arrow_function_object */ + +/** + * External function object creation operation. + * + * Note: + * external function object is implementation-defined object type + * that represent functions implemented in native code, using Embedding API + * + * @return pointer to newly created external function object + */ +ecma_object_t * +ecma_op_create_external_function_object (ecma_native_handler_t handler_cb) /**< pointer to external native handler */ +{ + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); + + ecma_object_t *function_obj_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_native_function_t), ECMA_OBJECT_TYPE_NATIVE_FUNCTION); + + /* + * [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_NATIVE_FUNCTION type. + * + * See also: ecma_object_get_class_name + */ + + ecma_native_function_t *native_function_p = (ecma_native_function_t *) function_obj_p; +#if JERRY_BUILTIN_REALMS + ECMA_SET_INTERNAL_VALUE_POINTER (native_function_p->realm_value, ecma_builtin_get_global ()); +#endif /* JERRY_BUILTIN_REALMS */ + native_function_p->native_handler_cb = handler_cb; + + return function_obj_p; +} /* ecma_op_create_external_function_object */ + +/** + * Create built-in native handler object. + * + * @return pointer to newly created native handler object + */ +ecma_object_t * +ecma_op_create_native_handler (ecma_native_handler_id_t id, /**< handler id */ + size_t object_size) /**< created object size */ +{ + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); + + ecma_object_t *function_obj_p = ecma_create_object (prototype_obj_p, object_size, ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + + ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) function_obj_p; + ext_func_obj_p->u.built_in.id = ECMA_BUILTIN_ID_HANDLER; + ext_func_obj_p->u.built_in.routine_id = (uint8_t) id; + ext_func_obj_p->u.built_in.u2.routine_flags = ECMA_NATIVE_HANDLER_FLAGS_NONE; + +#if JERRY_BUILTIN_REALMS + ECMA_SET_INTERNAL_VALUE_POINTER (ext_func_obj_p->u.built_in.realm_value, ecma_builtin_get_global ()); +#endif /* JERRY_BUILTIN_REALMS */ + + return function_obj_p; +} /* ecma_op_create_native_handler */ + +/** + * Get compiled code of a function object. + * + * @return compiled code + */ +const ecma_compiled_code_t * +ecma_op_function_get_compiled_code (ecma_extended_object_t *function_p) /**< function pointer */ +{ +#if JERRY_SNAPSHOT_EXEC + if (JERRY_LIKELY (function_p->u.function.bytecode_cp != ECMA_NULL_POINTER)) + { + return ECMA_GET_INTERNAL_VALUE_POINTER (const ecma_compiled_code_t, function_p->u.function.bytecode_cp); + } + + return ((ecma_static_function_t *) function_p)->bytecode_p; +#else /* !JERRY_SNAPSHOT_EXEC */ + return ECMA_GET_INTERNAL_VALUE_POINTER (const ecma_compiled_code_t, function_p->u.function.bytecode_cp); +#endif /* JERRY_SNAPSHOT_EXEC */ +} /* ecma_op_function_get_compiled_code */ + +#if JERRY_BUILTIN_REALMS + +/** + * Get realm from a byte code. + * + * Note: + * Does not increase the reference counter. + * + * @return pointer to realm (global) object + */ +ecma_global_object_t * +ecma_op_function_get_realm (const ecma_compiled_code_t *bytecode_header_p) /**< byte code header */ +{ +#if JERRY_SNAPSHOT_EXEC + if (JERRY_UNLIKELY (bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)) + { + return (ecma_global_object_t *) ecma_builtin_get_global (); + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value; + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + + return (ecma_global_object_t *) script_p->realm_p; +} /* ecma_op_function_get_realm */ + +/** + * Get realm from a function + * + * Note: + * Does not increase the reference counter. + * + * @return realm (global) object + */ +ecma_global_object_t * +ecma_op_function_get_function_realm (ecma_object_t *func_obj_p) /**< function object */ +{ + while (true) + { + ecma_object_type_t type = ecma_get_object_type (func_obj_p); + + if (type == ECMA_OBJECT_TYPE_FUNCTION) + { + ecma_extended_object_t *ext_function_obj_p = (ecma_extended_object_t *) func_obj_p; + const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_function_obj_p); + return ecma_op_function_get_realm (bytecode_data_p); + } + + if (type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION) + { + ecma_extended_object_t *ext_function_obj_p = (ecma_extended_object_t *) func_obj_p; + return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, ext_function_obj_p->u.built_in.realm_value); + } + + if (type == ECMA_OBJECT_TYPE_NATIVE_FUNCTION) + { + ecma_native_function_t *native_function_p = (ecma_native_function_t *) func_obj_p; + return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, native_function_p->realm_value); + } + + if (type == ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION) + { + ecma_value_t script_value = ((ecma_extended_object_t *) func_obj_p)->u.constructor_function.script_value; + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + + return (ecma_global_object_t *) script_p->realm_p; + } + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (func_obj_p)) + { + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) func_obj_p; + if (ecma_is_value_null (proxy_obj_p->handler)) + { + ecma_raise_type_error (ECMA_ERR_PROTOTYPE_FROM_REVOKED_PROXY_IS_INVALID); + return NULL; + } + func_obj_p = ecma_get_object_from_value (proxy_obj_p->target); + continue; + } +#endif /* JERRY_BUILTIN_PROXY */ + + JERRY_ASSERT (type == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) func_obj_p; + func_obj_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, bound_func_p->header.u.bound_function.target_function); + } +} /* ecma_op_function_get_function_realm */ + +#endif /* JERRY_BUILTIN_REALMS */ + +/** + * 15.3.5.3 implementation of [[HasInstance]] for Function objects + * + * @return true/false - if arguments are valid + * error - otherwise + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object */ + ecma_value_t value) /**< argument 'V' */ +{ + JERRY_ASSERT (func_obj_p != NULL && !ecma_is_lexical_environment (func_obj_p)); + + if (!ecma_is_value_object (value)) + { + return ECMA_VALUE_FALSE; + } + + while (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION) + { + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + /* 1. 3. */ + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) func_obj_p; + + func_obj_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, bound_func_p->header.u.bound_function.target_function); + } + + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION + || ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION + || ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION + || ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION + || ECMA_OBJECT_IS_PROXY (func_obj_p)); + + ecma_object_t *v_obj_p = ecma_get_object_from_value (value); + + ecma_value_t prototype_obj_value = ecma_op_object_get_by_magic_id (func_obj_p, LIT_MAGIC_STRING_PROTOTYPE); + + if (ECMA_IS_VALUE_ERROR (prototype_obj_value)) + { + return prototype_obj_value; + } + + if (!ecma_is_value_object (prototype_obj_value)) + { + ecma_free_value (prototype_obj_value); + return ecma_raise_type_error (ECMA_ERR_OBJECT_EXPECTED); + } + + ecma_object_t *prototype_obj_p = ecma_get_object_from_value (prototype_obj_value); + JERRY_ASSERT (prototype_obj_p != NULL); + +#if JERRY_BUILTIN_PROXY + ecma_value_t result = ECMA_VALUE_ERROR; +#else /* !JERRY_BUILTIN_PROXY */ + ecma_value_t result = ECMA_VALUE_FALSE; +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_ref_object (v_obj_p); + + while (true) + { + ecma_object_t *current_proto_p = ecma_op_object_get_prototype_of (v_obj_p); + ecma_deref_object (v_obj_p); + + if (current_proto_p == NULL) + { +#if JERRY_BUILTIN_PROXY + result = ECMA_VALUE_FALSE; +#endif /* JERRY_BUILTIN_PROXY */ + break; + } + else if (current_proto_p == ECMA_OBJECT_POINTER_ERROR) + { + break; + } + + if (current_proto_p == prototype_obj_p) + { + ecma_deref_object (current_proto_p); + result = ECMA_VALUE_TRUE; + break; + } + + /* Advance up on prototype chain. */ + v_obj_p = current_proto_p; + } + + ecma_deref_object (prototype_obj_p); + return result; +} /* ecma_op_function_has_instance */ + +/** + * GetSuperConstructor operation for class methods + * + * See also: ECMAScript v6, 12.3.5.2 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * super constructor - otherwise + */ +ecma_value_t +ecma_op_function_get_super_constructor (ecma_object_t *func_obj_p) /**< function object */ +{ + ecma_object_t *super_ctor_p = ecma_op_object_get_prototype_of (func_obj_p); + + if (JERRY_UNLIKELY (super_ctor_p == ECMA_OBJECT_POINTER_ERROR)) + { + return ECMA_VALUE_ERROR; + } + else if (super_ctor_p == NULL || !ecma_object_is_constructor (super_ctor_p)) + { + if (super_ctor_p != NULL) + { + ecma_deref_object (super_ctor_p); + } + return ecma_raise_type_error (ECMA_ERR_SUPER_BINDING_MUST_BE_A_CONSTRUCTOR); + } + + return ecma_make_object_value (super_ctor_p); +} /* ecma_op_function_get_super_constructor */ + +/** + * Ordinary internal method: GetPrototypeFromConstructor (constructor, intrinsicDefaultProto) + * + * See also: + * - ECMAScript v6, 9.1.15 + * - ECMAScript v10, 9.1.14 + * + * @return NULL - if the operation fail (exception on the global context is raised) + * pointer to the prototype object - otherwise + */ +ecma_object_t * +ecma_op_get_prototype_from_constructor (ecma_object_t *ctor_obj_p, /**< constructor to get prototype from */ + ecma_builtin_id_t default_proto_id) /**< intrinsicDefaultProto */ +{ + JERRY_ASSERT (ecma_op_object_is_callable (ctor_obj_p)); + JERRY_ASSERT (default_proto_id < ECMA_BUILTIN_ID__COUNT); + + ecma_value_t proto = ecma_op_object_get_by_magic_id (ctor_obj_p, LIT_MAGIC_STRING_PROTOTYPE); + + if (ECMA_IS_VALUE_ERROR (proto)) + { + return NULL; + } + + ecma_object_t *proto_obj_p; + + if (!ecma_is_value_object (proto)) + { + ecma_free_value (proto); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (ctor_obj_p)) + { + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) ctor_obj_p; + if (ecma_is_value_null (proxy_obj_p->handler)) + { + ecma_raise_type_error (ECMA_ERR_PROTOTYPE_FROM_REVOKED_PROXY_IS_INVALID); + return NULL; + } + } +#endif /* JERRY_BUILTIN_PROXY */ + +#if JERRY_BUILTIN_REALMS + proto_obj_p = ecma_builtin_get_from_realm (ecma_op_function_get_function_realm (ctor_obj_p), default_proto_id); +#else /* !JERRY_BUILTIN_REALMS */ + proto_obj_p = ecma_builtin_get (default_proto_id); +#endif /* JERRY_BUILTIN_REALMS */ + ecma_ref_object (proto_obj_p); + } + else + { + proto_obj_p = ecma_get_object_from_value (proto); + } + + return proto_obj_p; +} /* ecma_op_get_prototype_from_constructor */ + +/** + * Perform a JavaScript class function object method call. + * + * The input function object should be a JavaScript class constructor + * + * @return the result of the function call. + */ +static ecma_value_t JERRY_ATTR_NOINLINE +ecma_op_function_call_constructor (vm_frame_ctx_shared_args_t *shared_args_p, /**< shared data */ + ecma_object_t *scope_p, /**< lexical environment to use */ + ecma_value_t this_binding) /**< value of 'ThisBinding' */ +{ + shared_args_p->header.status_flags |= VM_FRAME_CTX_SHARED_NON_ARROW_FUNC; + + ecma_value_t ret_value; + ecma_extended_object_t *ext_func_p; + + if (JERRY_CONTEXT (current_new_target_p) == NULL) + { + ret_value = ecma_raise_type_error (ECMA_ERR_CLASS_CONSTRUCTOR_REQUIRES_NEW); + goto exit; + } + + ext_func_p = (ecma_extended_object_t *) shared_args_p->header.function_object_p; + if (ECMA_GET_THIRD_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) + { + this_binding = ECMA_VALUE_UNINITIALIZED; + } + + ecma_op_create_environment_record (scope_p, this_binding, shared_args_p->header.function_object_p); + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + JERRY_CONTEXT (global_object_p) = ecma_op_function_get_realm (shared_args_p->header.bytecode_header_p); +#endif /* JERRY_BUILTIN_REALMS */ + + ret_value = vm_run (&shared_args_p->header, this_binding, scope_p); + +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + + /* ECMAScript v6, 9.2.2.13 */ + if (JERRY_UNLIKELY (this_binding == ECMA_VALUE_UNINITIALIZED)) + { + if (!ECMA_IS_VALUE_ERROR (ret_value) && !ecma_is_value_object (ret_value)) + { + if (!ecma_is_value_undefined (ret_value)) + { + ecma_free_value (ret_value); + ret_value = ecma_raise_type_error (ECMA_ERR_DERIVED_CTOR_RETURN_NOR_OBJECT_OR_UNDEFINED); + } + else + { + ret_value = ecma_op_get_this_binding (scope_p); + } + } + } + +exit: + if (JERRY_UNLIKELY (shared_args_p->header.status_flags & VM_FRAME_CTX_SHARED_FREE_LOCAL_ENV)) + { + ecma_deref_object (scope_p); + } + + return ret_value; +} /* ecma_op_function_call_constructor */ + +/** + * Perform a JavaScript function object method call. + * + * The input function object should be a pure JavaScript method + * + * @return the result of the function call. + */ +static ecma_value_t +ecma_op_function_call_simple (ecma_object_t *func_obj_p, /**< Function object */ + ecma_value_t this_binding, /**< 'this' argument's value */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION); + + vm_frame_ctx_shared_args_t shared_args; + shared_args.header.status_flags = VM_FRAME_CTX_SHARED_HAS_ARG_LIST; + shared_args.header.function_object_p = func_obj_p; + shared_args.arg_list_p = arguments_list_p; + shared_args.arg_list_len = arguments_list_len; + + /* Entering Function Code (ECMA-262 v5, 10.4.3) */ + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_obj_p; + + ecma_object_t *scope_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, ext_func_p->u.function.scope_cp); + + /* 8. */ + const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p); + uint16_t status_flags = bytecode_data_p->status_flags; + + shared_args.header.bytecode_header_p = bytecode_data_p; + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *realm_p = ecma_op_function_get_realm (bytecode_data_p); +#endif /* JERRY_BUILTIN_REALMS */ + + /* 5. */ + if (!(status_flags & CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED)) + { + shared_args.header.status_flags |= VM_FRAME_CTX_SHARED_FREE_LOCAL_ENV; + scope_p = ecma_create_decl_lex_env (scope_p); + } + + /* 1. */ + switch (CBC_FUNCTION_GET_TYPE (status_flags)) + { + case CBC_FUNCTION_CONSTRUCTOR: + { + return ecma_op_function_call_constructor (&shared_args, scope_p, this_binding); + } + case CBC_FUNCTION_ARROW: + { + ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) func_obj_p; + + if (ecma_is_value_undefined (arrow_func_p->new_target)) + { + JERRY_CONTEXT (current_new_target_p) = NULL; + } + else + { + JERRY_CONTEXT (current_new_target_p) = ecma_get_object_from_value (arrow_func_p->new_target); + } + + this_binding = arrow_func_p->this_binding; + + if (JERRY_UNLIKELY (this_binding == ECMA_VALUE_UNINITIALIZED)) + { + ecma_environment_record_t *env_record_p = ecma_op_get_environment_record (scope_p); + JERRY_ASSERT (env_record_p); + this_binding = env_record_p->this_binding; + } + break; + } + default: + { + shared_args.header.status_flags |= VM_FRAME_CTX_SHARED_NON_ARROW_FUNC; + + if (status_flags & CBC_CODE_FLAGS_STRICT_MODE) + { + break; + } + + if (ecma_is_value_undefined (this_binding) || ecma_is_value_null (this_binding)) + { + /* 2. */ +#if JERRY_BUILTIN_REALMS + this_binding = realm_p->this_binding; +#else /* !JERRY_BUILTIN_REALMS */ + this_binding = ecma_make_object_value (ecma_builtin_get_global ()); +#endif /* JERRY_BUILTIN_REALMS */ + } + else if (!ecma_is_value_object (this_binding)) + { + /* 3., 4. */ + this_binding = ecma_op_to_object (this_binding); + shared_args.header.status_flags |= VM_FRAME_CTX_SHARED_FREE_THIS; + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (this_binding)); + } + break; + } + } + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + JERRY_CONTEXT (global_object_p) = realm_p; +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_value_t ret_value = vm_run (&shared_args.header, this_binding, scope_p); + +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + + if (JERRY_UNLIKELY (shared_args.header.status_flags & VM_FRAME_CTX_SHARED_FREE_LOCAL_ENV)) + { + ecma_deref_object (scope_p); + } + + if (JERRY_UNLIKELY (shared_args.header.status_flags & VM_FRAME_CTX_SHARED_FREE_THIS)) + { + ecma_free_value (this_binding); + } + + return ret_value; +} /* ecma_op_function_call_simple */ + +/** + * Perform a built-in method call. + * + * @return the result of the function call. + */ +static ecma_value_t JERRY_ATTR_NOINLINE +ecma_op_function_call_native_built_in (ecma_object_t *func_obj_p, /**< Function object */ + ecma_value_t this_arg_value, /**< 'this' argument's value */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + + ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p; + JERRY_CONTEXT (global_object_p) = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, ext_func_obj_p->u.built_in.realm_value); +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_value_t ret_value = + ecma_builtin_dispatch_call (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len); + +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + return ret_value; +} /* ecma_op_function_call_native_built_in */ + +/** + * Perform a native C method call which was registered via the API. + * + * @return the result of the function call. + */ +static ecma_value_t JERRY_ATTR_NOINLINE +ecma_op_function_call_native (ecma_object_t *func_obj_p, /**< Function object */ + ecma_value_t this_arg_value, /**< 'this' argument's value */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION); + + ecma_native_function_t *native_function_p = (ecma_native_function_t *) func_obj_p; + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + JERRY_CONTEXT (global_object_p) = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, native_function_p->realm_value); +#endif /* JERRY_BUILTIN_REALMS */ + + jerry_call_info_t call_info; + call_info.function = ecma_make_object_value (func_obj_p); + call_info.this_value = this_arg_value; + + ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target_p); + call_info.new_target = (new_target_p == NULL) ? ECMA_VALUE_UNDEFINED : ecma_make_object_value (new_target_p); + + JERRY_ASSERT (native_function_p->native_handler_cb != NULL); + ecma_value_t ret_value = native_function_p->native_handler_cb (&call_info, arguments_list_p, arguments_list_len); +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + + if (JERRY_UNLIKELY (ecma_is_value_exception (ret_value))) + { + ecma_throw_exception (ret_value); + return ECMA_VALUE_ERROR; + } + + return ret_value; +} /* ecma_op_function_call_native */ + +/** + * Append the bound arguments into the given collection + * + * Note: + * - The whole bound chain is resolved + * - The first element of the collection contains the bounded this value + * + * @return target function of the bound function + */ +JERRY_ATTR_NOINLINE static ecma_object_t * +ecma_op_bound_function_get_argument_list (ecma_object_t *func_obj_p, /**< bound function object */ + ecma_collection_t *list_p) /**< list of arguments */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) func_obj_p; + + func_obj_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, bound_func_p->header.u.bound_function.target_function); + + ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this; + + uint32_t args_length = 1; + + if (ecma_is_value_integer_number (args_len_or_this)) + { + args_length = (uint32_t) ecma_get_integer_from_value (args_len_or_this); + } + + /* 5. */ + if (args_length != 1) + { + const ecma_value_t *args_p = (const ecma_value_t *) (bound_func_p + 1); + list_p->buffer_p[0] = *args_p; + + if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION) + { + func_obj_p = ecma_op_bound_function_get_argument_list (func_obj_p, list_p); + } + ecma_collection_append (list_p, args_p + 1, args_length - 1); + } + else + { + list_p->buffer_p[0] = args_len_or_this; + } + + return func_obj_p; +} /* ecma_op_bound_function_get_argument_list */ + +/** + * [[Call]] internal method for bound function objects + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t JERRY_ATTR_NOINLINE +ecma_op_function_call_bound (ecma_object_t *func_obj_p, /**< Function object */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_DIRECT_EVAL; + + ecma_collection_t *bound_arg_list_p = ecma_new_collection (); + ecma_collection_push_back (bound_arg_list_p, ECMA_VALUE_EMPTY); + + ecma_object_t *target_obj_p = ecma_op_bound_function_get_argument_list (func_obj_p, bound_arg_list_p); + + ecma_collection_append (bound_arg_list_p, arguments_list_p, arguments_list_len); + + JERRY_ASSERT (!ecma_is_value_empty (bound_arg_list_p->buffer_p[0])); + + ecma_value_t ret_value = ecma_op_function_call (target_obj_p, + bound_arg_list_p->buffer_p[0], + bound_arg_list_p->buffer_p + 1, + (uint32_t) (bound_arg_list_p->item_count - 1)); + + ecma_collection_destroy (bound_arg_list_p); + + return ret_value; +} /* ecma_op_function_call_bound */ + +/** + * General [[Call]] implementation + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_function_validated_call (ecma_value_t callee, /**< callee */ + ecma_value_t this_arg_value, /**< 'this' argument's value */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + if (!ecma_is_value_object (callee)) + { + return ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION); + } + + return ecma_op_function_call (ecma_get_object_from_value (callee), + this_arg_value, + arguments_list_p, + arguments_list_len); +} /* ecma_op_function_validated_call */ + +/** + * General [[Call]] implementation + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */ + ecma_value_t this_arg_value, /**< 'this' argument's value */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (func_obj_p != NULL && !ecma_is_lexical_environment (func_obj_p)); + + ECMA_CHECK_STACK_USAGE (); + + ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p); + + if (JERRY_UNLIKELY (!(JERRY_CONTEXT (status_flags) & ECMA_STATUS_DIRECT_EVAL))) + { + JERRY_CONTEXT (current_new_target_p) = NULL; + } + + ecma_value_t result; + + switch (ecma_get_object_type (func_obj_p)) + { + case ECMA_OBJECT_TYPE_FUNCTION: + { + result = ecma_op_function_call_simple (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len); + break; + } + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + result = ecma_op_function_call_native_built_in (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len); + break; + } +#if JERRY_BUILTIN_PROXY + case ECMA_OBJECT_TYPE_PROXY: + { + result = ecma_proxy_object_call (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len); + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION: + { + result = ecma_raise_type_error (ECMA_ERR_CLASS_CONSTRUCTOR_NEW); + break; + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + result = ecma_op_function_call_native (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + result = ecma_op_function_call_bound (func_obj_p, arguments_list_p, arguments_list_len); + break; + } + default: + { + result = ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION); + break; + } + } + + JERRY_CONTEXT (current_new_target_p) = old_new_target_p; + + return result; +} /* ecma_op_function_call */ + +/** + * [[Construct]] internal method for ECMAScript function objects + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_op_function_construct_simple (ecma_object_t *func_obj_p, /**< Function object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION); + + ecma_object_t *new_this_obj_p = NULL; + ecma_value_t this_arg; + + ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p; + + /* 5. */ + if (!ECMA_GET_THIRD_BIT_FROM_POINTER_TAG (ext_func_obj_p->u.function.scope_cp)) + { + /* 5.a */ + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (new_target_p, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + + /* 5.b */ + if (JERRY_UNLIKELY (proto_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + new_this_obj_p = ecma_create_object (proto_p, 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_deref_object (proto_p); + this_arg = ecma_make_object_value (new_this_obj_p); + } + else + { + this_arg = ECMA_VALUE_UNDEFINED; + } + + /* 6. */ + ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p); + JERRY_CONTEXT (current_new_target_p) = new_target_p; + + ecma_value_t ret_value = ecma_op_function_call_simple (func_obj_p, this_arg, arguments_list_p, arguments_list_len); + + JERRY_CONTEXT (current_new_target_p) = old_new_target_p; + + /* 13.a */ + if (ECMA_IS_VALUE_ERROR (ret_value) || ecma_is_value_object (ret_value)) + { + if (new_this_obj_p != NULL) + { + ecma_deref_object (new_this_obj_p); + } + + return ret_value; + } + + /* 13.b */ + ecma_free_value (ret_value); + return this_arg; +} /* ecma_op_function_construct_simple */ + +/** + * [[Construct]] internal method for built-in function objects + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_op_function_construct_built_in (ecma_object_t *func_obj_p, /**< Function object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_UNUSED (new_target_p); + + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION); + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + ecma_value_t realm_value = ((ecma_extended_object_t *) func_obj_p)->u.built_in.realm_value; + JERRY_CONTEXT (global_object_p) = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, realm_value); +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_object_t *old_new_target = JERRY_CONTEXT (current_new_target_p); + JERRY_CONTEXT (current_new_target_p) = new_target_p; + + ecma_value_t ret_value = ecma_builtin_dispatch_construct (func_obj_p, arguments_list_p, arguments_list_len); + + JERRY_CONTEXT (current_new_target_p) = old_new_target; + +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + return ret_value; +} /* ecma_op_function_construct_built_in */ + +/** + * [[Construct]] internal method for bound function objects + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t JERRY_ATTR_NOINLINE +ecma_op_function_construct_bound (ecma_object_t *func_obj_p, /**< Function object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + ecma_collection_t *bound_arg_list_p = ecma_new_collection (); + ecma_collection_push_back (bound_arg_list_p, ECMA_VALUE_EMPTY); + + ecma_object_t *target_obj_p = ecma_op_bound_function_get_argument_list (func_obj_p, bound_arg_list_p); + + ecma_collection_append (bound_arg_list_p, arguments_list_p, arguments_list_len); + + if (func_obj_p == new_target_p) + { + new_target_p = target_obj_p; + } + + ecma_value_t ret_value = ecma_op_function_construct (target_obj_p, + new_target_p, + bound_arg_list_p->buffer_p + 1, + (uint32_t) (bound_arg_list_p->item_count - 1)); + + ecma_collection_destroy (bound_arg_list_p); + + return ret_value; +} /* ecma_op_function_construct_bound */ + +/** + * [[Construct]] internal method for class implicit constructor objects + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_op_function_construct_constructor (ecma_object_t *func_obj_p, /**< Function object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION); + + ecma_extended_object_t *constructor_object_p = (ecma_extended_object_t *) func_obj_p; + + if (!(constructor_object_p->u.constructor_function.flags & ECMA_CONSTRUCTOR_FUNCTION_HAS_HERITAGE)) + { + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (new_target_p, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + + if (JERRY_UNLIKELY (proto_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *new_this_object_p = ecma_create_object (proto_p, 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_deref_object (proto_p); + + jerry_value_t new_this_value = ecma_make_object_value (new_this_object_p); + jerry_value_t ret_value = opfunc_init_class_fields (func_obj_p, new_this_value); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_deref_object (new_this_object_p); + return ret_value; + } + + return new_this_value; + } + + ecma_value_t super_ctor = ecma_op_function_get_super_constructor (func_obj_p); + + if (ECMA_IS_VALUE_ERROR (super_ctor)) + { + return super_ctor; + } + + ecma_object_t *super_ctor_p = ecma_get_object_from_value (super_ctor); + ecma_value_t result = ecma_op_function_construct (super_ctor_p, new_target_p, arguments_list_p, arguments_list_len); + ecma_deref_object (super_ctor_p); + + if (ecma_is_value_object (result)) + { + ecma_value_t fields_value = opfunc_init_class_fields (func_obj_p, result); + + if (ECMA_IS_VALUE_ERROR (fields_value)) + { + ecma_free_value (result); + return fields_value; + } + } + + return result; +} /* ecma_op_function_construct_constructor */ + +/** + * [[Construct]] internal method for external function objects + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_op_function_construct_native (ecma_object_t *func_obj_p, /**< Function object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION); + + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (new_target_p, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + + if (JERRY_UNLIKELY (proto_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *new_this_obj_p = ecma_create_object (proto_p, 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_value_t this_arg = ecma_make_object_value (new_this_obj_p); + ecma_deref_object (proto_p); + + ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p); + JERRY_CONTEXT (current_new_target_p) = new_target_p; + + ecma_value_t ret_value = ecma_op_function_call_native (func_obj_p, this_arg, arguments_list_p, arguments_list_len); + + JERRY_CONTEXT (current_new_target_p) = old_new_target_p; + + if (ECMA_IS_VALUE_ERROR (ret_value) || ecma_is_value_object (ret_value)) + { + ecma_deref_object (new_this_obj_p); + return ret_value; + } + + ecma_free_value (ret_value); + + return this_arg; +} /* ecma_op_function_construct_native */ + +/** + * General [[Construct]] implementation function objects + * + * See also: ECMAScript v6, 9.2.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + uint32_t arguments_list_len) /**< length of arguments list */ +{ + JERRY_ASSERT (func_obj_p != NULL && !ecma_is_lexical_environment (func_obj_p)); + + ECMA_CHECK_STACK_USAGE (); + + switch (ecma_get_object_type (func_obj_p)) + { + case ECMA_OBJECT_TYPE_FUNCTION: + { + return ecma_op_function_construct_simple (func_obj_p, new_target_p, arguments_list_p, arguments_list_len); + } + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + return ecma_op_function_construct_built_in (func_obj_p, new_target_p, arguments_list_p, arguments_list_len); + } +#if JERRY_BUILTIN_PROXY + case ECMA_OBJECT_TYPE_PROXY: + { + return ecma_proxy_object_construct (func_obj_p, new_target_p, arguments_list_p, arguments_list_len); + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION: + { + return ecma_op_function_construct_constructor (func_obj_p, new_target_p, arguments_list_p, arguments_list_len); + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + return ecma_op_function_construct_bound (func_obj_p, new_target_p, arguments_list_p, arguments_list_len); + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + return ecma_op_function_construct_native (func_obj_p, new_target_p, arguments_list_p, arguments_list_len); + } + default: + { + JERRY_UNREACHABLE (); + } + } + + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_function_construct */ + +/** + * Lazy instantiation of 'prototype' property for non-builtin and external functions + * + * @return pointer to newly instantiated property + */ +static ecma_property_t * +ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the function object */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION + || ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION); + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *global_object_p; + + if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + const ecma_compiled_code_t *bytecode_data_p; + bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); + + global_object_p = ecma_op_function_get_realm (bytecode_data_p); + } + else + { + ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p; + + global_object_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, native_function_p->realm_value); + } +#endif /* JERRY_BUILTIN_REALMS */ + + /* ECMA-262 v5, 13.2, 16-18 */ + + ecma_object_t *proto_object_p = NULL; + bool init_constructor = true; + + if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); + + if (!CBC_FUNCTION_HAS_PROTOTYPE (byte_code_p->status_flags)) + { + return NULL; + } + + if (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags) == CBC_FUNCTION_GENERATOR) + { + ecma_object_t *prototype_p; + +#if JERRY_BUILTIN_REALMS + prototype_p = ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE); +#else /* !JERRY_BUILTIN_REALMS */ + prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE); +#endif /* JERRY_BUILTIN_REALMS */ + + proto_object_p = ecma_create_object (prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); + init_constructor = false; + } + + if (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags) == CBC_FUNCTION_ASYNC_GENERATOR) + { + ecma_object_t *prototype_p; + +#if JERRY_BUILTIN_REALMS + prototype_p = ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE); +#else /* !JERRY_BUILTIN_REALMS */ + prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE); +#endif /* JERRY_BUILTIN_REALMS */ + + proto_object_p = ecma_create_object (prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); + init_constructor = false; + } + } + + if (proto_object_p == NULL) + { + ecma_object_t *prototype_p; + +#if JERRY_BUILTIN_REALMS + prototype_p = ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); +#else /* !JERRY_BUILTIN_REALMS */ + prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); +#endif /* JERRY_BUILTIN_REALMS */ + + proto_object_p = ecma_op_create_object_object_noarg_and_set_prototype (prototype_p); + } + + /* 17. */ + if (init_constructor) + { + ecma_property_value_t *constructor_prop_value_p; + constructor_prop_value_p = ecma_create_named_data_property (proto_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_CONSTRUCTOR), + ECMA_PROPERTY_CONFIGURABLE_WRITABLE, + NULL); + + constructor_prop_value_p->value = ecma_make_object_value (object_p); + } + + /* 18. */ + ecma_property_t *prototype_prop_p; + ecma_property_value_t *prototype_prop_value_p; + prototype_prop_value_p = ecma_create_named_data_property (object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_PROTOTYPE), + ECMA_PROPERTY_BUILT_IN_WRITABLE, + &prototype_prop_p); + + prototype_prop_value_p->value = ecma_make_object_value (proto_object_p); + + ecma_deref_object (proto_object_p); + + return prototype_prop_p; +} /* ecma_op_lazy_instantiate_prototype_object */ + +/** + * Lazy instantiation of non-builtin ecma function object's properties + * + * Warning: + * Only non-configurable properties could be instantiated lazily in this function, + * as configurable properties could be deleted and it would be incorrect + * to reinstantiate them in the function in second time. + * + * @return pointer to newly instantiated property, if a property was instantiated, + * NULL - otherwise + */ +ecma_property_t * +ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**< the function object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION); + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)) + { + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + + if (ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) + { + return NULL; + } + + /* Initialize 'length' property */ + const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p); + uint32_t len; + + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_data_p; + len = args_p->argument_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_data_p; + len = args_p->argument_end; + } + + if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_HAS_EXTENDED_INFO) + { + uint8_t *extended_info_p = ecma_compiled_code_resolve_extended_info (bytecode_data_p); + + if (*extended_info_p & CBC_EXTENDED_CODE_FLAGS_HAS_ARGUMENT_LENGTH) + { + len = ecma_extended_info_decode_vlq (&extended_info_p); + } + } + + ecma_property_t *value_prop_p; + ecma_property_value_t *value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, &value_prop_p); + value_p->value = ecma_make_uint32_value (len); + return value_prop_p; + } + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_NAME)) + { + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + + if (ECMA_GET_SECOND_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) + { + return NULL; + } + + const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p); + + if (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_CONSTRUCTOR) + { + return NULL; + } + + ecma_value_t value = *ecma_compiled_code_resolve_function_name (bytecode_data_p); + JERRY_ASSERT (ecma_is_value_string (value)); + + /* Initialize 'name' property */ + ecma_property_t *value_prop_p; + ecma_property_value_t *value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_CONFIGURABLE, &value_prop_p); + value_p->value = ecma_copy_value (value); + return value_prop_p; + } + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_PROTOTYPE) + && ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + return ecma_op_lazy_instantiate_prototype_object (object_p); + } + + const bool is_arguments = ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_ARGUMENTS); + + if (is_arguments || ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_CALLER)) + { + const ecma_compiled_code_t *bytecode_data_p; + bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); + + if (!(bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) + && CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_NORMAL) + { + ecma_property_t *value_prop_p; + /* The property_name_p argument contains the name. */ + ecma_property_value_t *value_p = + ecma_create_named_data_property (object_p, property_name_p, ECMA_PROPERTY_BUILT_IN_FIXED, &value_prop_p); + value_p->value = is_arguments ? ECMA_VALUE_NULL : ECMA_VALUE_UNDEFINED; + return value_prop_p; + } + } + + return NULL; +} /* ecma_op_function_try_to_lazy_instantiate_property */ + +/** + * Create specification defined non-configurable properties for external functions. + * + * See also: + * ECMA-262 v5, 15.3.4.5 + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +ecma_property_t * +ecma_op_external_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property's name */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION); + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_PROTOTYPE)) + { + return ecma_op_lazy_instantiate_prototype_object (object_p); + } + + return NULL; +} /* ecma_op_external_function_try_to_lazy_instantiate_property */ + +/** + * Create specification defined non-configurable properties for bound functions. + * + * See also: + * ECMA-262 v5, 15.3.4.5 + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +ecma_property_t * +ecma_op_bound_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property's name */ +{ + JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION); + + if (ecma_string_is_length (property_name_p)) + { + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p; + ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this; + ecma_number_t length = 0; + ecma_integer_value_t args_length = 1; + uint8_t length_attributes; + + if (ecma_is_value_integer_number (args_len_or_this)) + { + args_length = ecma_get_integer_from_value (args_len_or_this); + } + + if (ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (bound_func_p->header.u.bound_function.target_function)) + { + return NULL; + } + + length_attributes = ECMA_PROPERTY_BUILT_IN_CONFIGURABLE; + length = ecma_get_number_from_value (bound_func_p->target_length) - (args_length - 1); + + if (length < 0) + { + length = 0; + } + + ecma_property_t *len_prop_p; + ecma_property_value_t *len_prop_value_p = + ecma_create_named_data_property (object_p, property_name_p, length_attributes, &len_prop_p); + + len_prop_value_p->value = ecma_make_number_value (length); + return len_prop_p; + } + + return NULL; +} /* ecma_op_bound_function_try_to_lazy_instantiate_property */ + +/** + * Delete configurable properties of functions. + */ +void +ecma_op_function_delete_built_in_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + + if (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)) + { + JERRY_ASSERT (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)); + ECMA_SET_FIRST_BIT_TO_POINTER_TAG (ext_func_p->u.function.scope_cp); + return; + } + + JERRY_ASSERT (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_NAME)); + JERRY_ASSERT (!ECMA_GET_SECOND_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)); + + ECMA_SET_SECOND_BIT_TO_POINTER_TAG (ext_func_p->u.function.scope_cp); +} /* ecma_op_function_delete_built_in_property */ + +/** + * Delete configurable properties of bound functions. + */ +void +ecma_op_bound_function_delete_built_in_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_UNUSED (property_name_p); + + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p; + + JERRY_ASSERT (ecma_compare_ecma_string_to_magic_id (property_name_p, LIT_MAGIC_STRING_LENGTH)); + JERRY_ASSERT (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (bound_func_p->header.u.bound_function.target_function)); + + ECMA_SET_FIRST_BIT_TO_POINTER_TAG (bound_func_p->header.u.bound_function.target_function); +} /* ecma_op_bound_function_delete_built_in_property */ + +/** + * List names of a Function object's lazy instantiated properties, + * adding them to corresponding string collections + * + * See also: + * ecma_op_function_try_to_lazy_instantiate_property + */ +void +ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functionobject */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS) + { + return; + } + + const ecma_compiled_code_t *bytecode_data_p; + bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); + + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + + if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) + { + /* Uninitialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } + + if (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR + && !ECMA_GET_SECOND_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) + { + /* Uninitialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME)); + prop_counter_p->string_named_props++; + } + + if (!CBC_FUNCTION_HAS_PROTOTYPE (bytecode_data_p->status_flags) + || (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_CONSTRUCTOR)) + { + return; + } + + if (!(bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE)) + { + /* 'arguments' property is non-enumerable (ECMA-262 v5, 13.2.5) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_ARGUMENTS)); + + /* 'caller' property is non-enumerable (ECMA-262 v5, 13.2.5) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLER)); + + prop_counter_p->string_named_props += 2; + } + + /* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE)); + prop_counter_p->string_named_props++; +} /* ecma_op_function_list_lazy_property_names */ + +/** + * List names of an External Function object's lazy instantiated properties, + * adding them to corresponding string collections + * + * See also: + * ecma_op_external_function_try_to_lazy_instantiate_property + */ +void +ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p, /**< function object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name + * filter options */ +{ + JERRY_UNUSED (object_p); + + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS) + { + return; + } + + /* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE)); + prop_counter_p->string_named_props++; +} /* ecma_op_external_function_list_lazy_property_names */ + +/** + * List names of a Bound Function object's lazy instantiated properties, + * adding them to corresponding string collections + * + * See also: + * ecma_op_bound_function_try_to_lazy_instantiate_property + */ +void +ecma_op_bound_function_list_lazy_property_names (ecma_object_t *object_p, /**< bound function object*/ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS) + { + return; + } + + /* Uninitialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */ + ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p; + if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (bound_func_p->header.u.bound_function.target_function)) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } + + /* 'caller' property is non-enumerable (ECMA-262 v5, 13.2.5) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLER)); + + /* 'arguments' property is non-enumerable (ECMA-262 v5, 13.2.5) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_ARGUMENTS)); + + prop_counter_p->string_named_props += 2; +} /* ecma_op_bound_function_list_lazy_property_names */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-function-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-function-object.h new file mode 100644 index 0000000..08300f5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-function-object.h @@ -0,0 +1,130 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_FUNCTION_OBJECT_H +#define ECMA_FUNCTION_OBJECT_H + +#include "ecma-builtin-handlers.h" +#include "ecma-builtins.h" +#include "ecma-globals.h" + +#include "vm.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmafunctionobject ECMA Function object related routines + * @{ + */ + +ecma_value_t ecma_op_function_form_name (ecma_string_t *prop_name_p, char *prefix_p, lit_utf8_size_t prefix_size); + +bool ecma_op_is_callable (ecma_value_t value); +#if JERRY_BUILTIN_PROXY +bool ecma_op_proxy_object_is_callable (ecma_object_t *obj_p); +#endif /* JERRY_BUILTIN_PROXY */ +bool ecma_op_object_is_callable (ecma_object_t *obj_p); +bool ecma_is_constructor (ecma_value_t value); +bool ecma_object_is_constructor (ecma_object_t *obj_p); + +/** + * Special constant indicating that the value is a valid constructor + * + * Use after the ecma_*_check_constructor calls. + */ + +ecma_error_msg_t ecma_object_check_constructor (ecma_object_t *obj_p); +ecma_error_msg_t ecma_check_constructor (ecma_value_t value); + +ecma_object_t *ecma_op_create_simple_function_object (ecma_object_t *scope_p, + const ecma_compiled_code_t *bytecode_data_p); + +ecma_object_t *ecma_op_create_external_function_object (ecma_native_handler_t handler_cb); + +const ecma_compiled_code_t *ecma_op_function_get_compiled_code (ecma_extended_object_t *function_p); + +#if JERRY_BUILTIN_REALMS +ecma_global_object_t *ecma_op_function_get_realm (const ecma_compiled_code_t *bytecode_header_p); + +ecma_global_object_t *ecma_op_function_get_function_realm (ecma_object_t *func_obj_p); +#endif /* JERRY_BUILTIN_REALMS */ + +ecma_value_t ecma_op_create_dynamic_function (const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len, + ecma_parse_opts_t opts); + +ecma_value_t ecma_op_function_get_super_constructor (ecma_object_t *func_obj_p); + +ecma_object_t *ecma_op_create_any_function_object (ecma_object_t *scope_p, const ecma_compiled_code_t *bytecode_data_p); + +ecma_object_t *ecma_op_create_arrow_function_object (ecma_object_t *scope_p, + const ecma_compiled_code_t *bytecode_data_p, + ecma_value_t this_binding); + +ecma_object_t *ecma_op_create_native_handler (ecma_native_handler_id_t id, size_t object_size); + +ecma_object_t *ecma_op_get_prototype_from_constructor (ecma_object_t *ctor_obj_p, ecma_builtin_id_t default_proto_id); + +ecma_value_t ecma_op_function_has_instance (ecma_object_t *func_obj_p, ecma_value_t value); + +ecma_value_t ecma_op_function_validated_call (ecma_value_t callee, + ecma_value_t this_arg_value, + const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len); + +ecma_value_t ecma_op_function_call (ecma_object_t *func_obj_p, + ecma_value_t this_arg_value, + const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len); + +ecma_value_t ecma_op_function_construct (ecma_object_t *func_obj_p, + ecma_object_t *new_target_p, + const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len); + +ecma_property_t *ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, + ecma_string_t *property_name_p); + +ecma_property_t *ecma_op_external_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, + ecma_string_t *property_name_p); + +ecma_property_t *ecma_op_bound_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, + ecma_string_t *property_name_p); + +void ecma_op_function_delete_built_in_property (ecma_object_t *object_p, ecma_string_t *property_name_p); + +void ecma_op_bound_function_delete_built_in_property (ecma_object_t *object_p, ecma_string_t *property_name_p); + +void ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); + +void ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); + +void ecma_op_bound_function_list_lazy_property_names (ecma_object_t *object_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); + +/** + * @} + * @} + */ + +#endif /* !ECMA_FUNCTION_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-get-put-value.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-get-put-value.cpp new file mode 100644 index 0000000..edc06e9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-get-put-value.cpp @@ -0,0 +1,319 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Implementation of ECMA GetValue and PutValue + */ + +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-reference.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup lexicalenvironment Lexical environment + * @{ + */ + +/** + * GetValue operation part + * + * See also: ECMA-262 v5, 8.7.1, sections 3 and 5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_get_value_lex_env_base (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_object_t **ref_base_lex_env_p, /**< [out] reference's base (lexical environment) */ + ecma_string_t *name_p) /**< variable name */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + + while (true) + { + switch (ecma_get_lex_env_type (lex_env_p)) + { + case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p != NULL) + { + *ref_base_lex_env_p = lex_env_p; + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (JERRY_UNLIKELY (property_value_p->value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + + return ecma_fast_copy_value (property_value_p->value); + } + break; + } + case ECMA_LEXICAL_ENVIRONMENT_CLASS: + { +#if JERRY_MODULE_SYSTEM + if (ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p != NULL) + { + *ref_base_lex_env_p = lex_env_p; + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (!(*property_p & ECMA_PROPERTY_FLAG_DATA)) + { + property_value_p = ecma_get_property_value_from_named_reference (property_value_p); + } + + if (JERRY_UNLIKELY (property_value_p->value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + + return ecma_fast_copy_value (property_value_p->value); + } + } +#endif /* JERRY_MODULE_SYSTEM */ + break; + } + default: + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_value_t result = ecma_op_object_bound_environment_resolve_reference_value (lex_env_p, name_p); + + if (ecma_is_value_found (result)) + { + /* Note: the result may contains ECMA_VALUE_ERROR */ + *ref_base_lex_env_p = lex_env_p; + return result; + } + + break; + } + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + *ref_base_lex_env_p = NULL; +#if JERRY_ERROR_MESSAGES + return ecma_raise_standard_error_with_format (JERRY_ERROR_REFERENCE, + "% is not defined", + ecma_make_string_value (name_p)); +#else /* JERRY_ERROR_MESSAGES */ + return ecma_raise_reference_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + +} /* ecma_op_get_value_lex_env_base */ + +/** + * GetValue operation part (object base). + * + * See also: ECMA-262 v5, 8.7.1, section 4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_get_value_object_base (ecma_value_t base_value, /**< base value */ + ecma_string_t *property_name_p) /**< property name */ +{ + ecma_object_t *obj_p; + + if (JERRY_UNLIKELY (ecma_is_value_object (base_value))) + { + obj_p = ecma_get_object_from_value (base_value); + } + else + { + ecma_builtin_id_t id = ECMA_BUILTIN_ID_OBJECT_PROTOTYPE; + + if (JERRY_LIKELY (ecma_is_value_string (base_value))) + { + ecma_string_t *string_p = ecma_get_string_from_value (base_value); + + if (ecma_string_is_length (property_name_p)) + { + return ecma_make_uint32_value (ecma_string_get_length (string_p)); + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index != ECMA_STRING_NOT_ARRAY_INDEX && index < ecma_string_get_length (string_p)) + { + ecma_char_t char_at_idx = ecma_string_get_char_at_pos (string_p, index); + return ecma_make_string_value (ecma_new_ecma_string_from_code_unit (char_at_idx)); + } + +#if JERRY_BUILTIN_STRING + id = ECMA_BUILTIN_ID_STRING_PROTOTYPE; +#endif /* JERRY_BUILTIN_STRING */ + } + else if (ecma_is_value_number (base_value)) + { +#if JERRY_BUILTIN_NUMBER + id = ECMA_BUILTIN_ID_NUMBER_PROTOTYPE; +#endif /* JERRY_BUILTIN_NUMBER */ + } + else if (ecma_is_value_symbol (base_value)) + { + id = ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE; + } +#if JERRY_BUILTIN_BIGINT + else if (ecma_is_value_bigint (base_value)) + { + id = ECMA_BUILTIN_ID_BIGINT_PROTOTYPE; + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + JERRY_ASSERT (ecma_is_value_boolean (base_value)); +#if JERRY_BUILTIN_BOOLEAN + id = ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE; +#endif /* JERRY_BUILTIN_BOOLEAN */ + } + + obj_p = ecma_builtin_get (id); + } + + return ecma_op_object_get_with_receiver (obj_p, property_name_p, base_value); +} /* ecma_op_get_value_object_base */ + +/** + * PutValue operation part + * + * See also: ECMA-262 v5, 8.7.2, sections 3 and 5 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_put_value_lex_env_base (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p, /**< variable name */ + bool is_strict, /**< flag indicating strict mode */ + ecma_value_t value) /**< ECMA-value */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + + while (true) + { + switch (ecma_get_lex_env_type (lex_env_p)) + { + case ECMA_LEXICAL_ENVIRONMENT_CLASS: + { + if (!ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + break; + } + /* FALLTHRU */ + } + case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p != NULL) + { + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + JERRY_ASSERT (!(*property_p & ECMA_PROPERTY_FLAG_WRITABLE) || (*property_p & ECMA_PROPERTY_FLAG_DATA)); + + if ((*property_p & ECMA_PROPERTY_FLAG_WRITABLE) && property_value_p->value != ECMA_VALUE_UNINITIALIZED) + { + ecma_named_data_property_assign_value (lex_env_p, property_value_p, value); + return ECMA_VALUE_EMPTY; + } + + return ecma_op_raise_set_binding_error (property_p, is_strict); + } + break; + } + default: + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + + ecma_value_t has_property = ecma_op_object_has_property (binding_obj_p, name_p); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (has_property)) + { + return has_property; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_true (has_property)) + { + ecma_value_t completion = ecma_op_object_put (binding_obj_p, name_p, value, is_strict); + + if (ECMA_IS_VALUE_ERROR (completion)) + { + return completion; + } + + JERRY_ASSERT (ecma_is_value_boolean (completion)); + return ECMA_VALUE_EMPTY; + } + + break; + } + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + if (is_strict) + { +#if JERRY_ERROR_MESSAGES + return ecma_raise_standard_error_with_format (JERRY_ERROR_REFERENCE, + "% is not defined", + ecma_make_string_value (name_p)); +#else /* !JERRY_ERROR_MESSAGES */ + return ecma_raise_reference_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + } + + ecma_op_object_put (ecma_get_lex_env_binding_object (lex_env_p), name_p, value, false); + return ECMA_VALUE_EMPTY; +} /* ecma_op_put_value_lex_env_base */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-iterator-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-iterator-object.cpp new file mode 100644 index 0000000..68db184 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-iterator-object.cpp @@ -0,0 +1,708 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-iterator-object.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaiteratorobject ECMA iterator object related routines + * @{ + */ + +/** + * Implementation of 'CreateArrayFromList' specialized for iterators + * + * See also: + * ECMA-262 v6, 7.3.16. + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return new array object + */ +ecma_value_t +ecma_create_array_from_iter_element (ecma_value_t value, /**< value */ + ecma_value_t index_value) /**< iterator index */ +{ + auto new_array_p = ecma_op_new_array_object (0); + ecma_builtin_helper_def_prop_by_index (new_array_p, 0, index_value, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_builtin_helper_def_prop_by_index (new_array_p, 1, value, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + return ecma_make_object_value (new_array_p); +} + +/** + * CreateIterResultObject operation + * + * See also: + * ECMA-262 v6, 7.4.7. + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object + */ +ecma_value_t +ecma_create_iter_result_object (ecma_value_t value, /**< value */ + ecma_value_t done) /**< ECMA_VALUE_{TRUE,FALSE} based + * on the iterator index */ +{ + /* 1. */ + JERRY_ASSERT (ecma_is_value_boolean (done)); + + /* 2. */ + ecma_object_t *object_p = + ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), 0, ECMA_OBJECT_TYPE_GENERAL); + + /* 3. */ + ecma_property_value_t *prop_value_p; + prop_value_p = ecma_create_named_data_property (object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_VALUE), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + + prop_value_p->value = ecma_copy_value_if_not_object (value); + + /* 4. */ + prop_value_p = ecma_create_named_data_property (object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_DONE), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + prop_value_p->value = done; + + /* 5. */ + return ecma_make_object_value (object_p); +} /* ecma_create_iter_result_object */ + +/** + * General iterator object creation operation. + * + * See also: ECMA-262 v6, 21.1.5.1, 22.1.5.1, 23.1.5.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator object + */ +ecma_value_t +ecma_op_create_iterator_object (ecma_value_t iterated_value, /**< value from create iterator */ + ecma_object_t *prototype_obj_p, /**< prototype object */ + ecma_object_class_type_t iterator_type, /**< iterator type */ + ecma_iterator_kind_t kind) /**< iterator kind*/ +{ + /* 1. */ +#ifdef JERRY_BUILTIN_REGEXP + JERRY_ASSERT (iterator_type == ECMA_OBJECT_CLASS_ARRAY_ITERATOR || iterator_type == ECMA_OBJECT_CLASS_SET_ITERATOR || iterator_type == ECMA_OBJECT_CLASS_MAP_ITERATOR || + iterator_type == ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR || iterator_type == ECMA_OBJECT_CLASS_STRING_ITERATOR); +#else + JERRY_ASSERT (iterator_type == ECMA_OBJECT_CLASS_ARRAY_ITERATOR || iterator_type == ECMA_OBJECT_CLASS_SET_ITERATOR || iterator_type == ECMA_OBJECT_CLASS_MAP_ITERATOR || + iterator_type == ECMA_OBJECT_CLASS_STRING_ITERATOR); +#endif + + /* 2. */ + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p; + ext_obj_p->u.cls.type = (uint8_t) iterator_type; + + /* 3. */ + ext_obj_p->u.cls.u3.iterated_value = iterated_value; + /* 4. */ + ext_obj_p->u.cls.u2.iterator_index = 0; + /* 5. */ + ext_obj_p->u.cls.u1.iterator_kind = (uint8_t) kind; + + /* 6. */ + return ecma_make_object_value (object_p); +} /* ecma_op_create_iterator_object */ + +/** + * GetIterator operation + * + * See also: ECMA-262 v10, 7.4.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator object - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_get_iterator (ecma_value_t value, /**< value to get iterator from */ + ecma_value_t method, /**< provided method argument */ + ecma_value_t *next_method_p) /**< [out] next method */ +{ + JERRY_ASSERT (next_method_p != NULL); + *next_method_p = ECMA_VALUE_UNDEFINED; + + /* 1. */ + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + + bool use_default_method = false; + + /* 2. */ + if (method == ECMA_VALUE_SYNC_ITERATOR) + { + /* 2.a */ + use_default_method = true; + method = ecma_op_get_method_by_symbol_id (value, LIT_GLOBAL_SYMBOL_ITERATOR); + + /* 2.b */ + if (ECMA_IS_VALUE_ERROR (method)) + { + return method; + } + } + /* 3.a */ + else if (method == ECMA_VALUE_ASYNC_ITERATOR) + { + use_default_method = true; + + /* 3.a.i */ + method = ecma_op_get_method_by_symbol_id (value, LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR); + + if (ECMA_IS_VALUE_ERROR (method)) + { + return method; + } + + /* 3.a.ii */ + + if (ecma_is_value_undefined (method)) + { + method = ecma_op_get_method_by_symbol_id (value, LIT_GLOBAL_SYMBOL_ITERATOR); + + if (ECMA_IS_VALUE_ERROR (method)) + { + return method; + } + + ecma_value_t sync_next_method; + ecma_value_t sync_iterator = ecma_op_get_iterator (value, method, &sync_next_method); + + if (ECMA_IS_VALUE_ERROR (sync_iterator)) + { + ecma_free_value (method); + return sync_iterator; + } + + ecma_value_t async_iterator = + ecma_op_create_async_from_sync_iterator (sync_iterator, sync_next_method, next_method_p); + + ecma_free_value (method); + ecma_free_value (sync_iterator); + ecma_free_value (sync_next_method); + + return async_iterator; + } + } + + /* 3. */ + ecma_value_t iterator = ecma_op_function_validated_call (method, value, NULL, 0); + + if (use_default_method) + { + ecma_free_value (method); + } + + /* 4. */ + if (ECMA_IS_VALUE_ERROR (iterator)) + { + return iterator; + } + + /* 5. */ + if (!ecma_is_value_object (iterator)) + { + ecma_free_value (iterator); + return ecma_raise_type_error (ECMA_ERR_ITERATOR_IS_NOT_AN_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (iterator); + ecma_value_t next_method = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_NEXT); + + if (ECMA_IS_VALUE_ERROR (next_method)) + { + ecma_free_value (iterator); + return next_method; + } + + if (ecma_op_is_callable (next_method)) + { + *next_method_p = next_method; + } + else + { + ecma_free_value (next_method); + } + + /* 6. */ + return iterator; +} /* ecma_op_get_iterator */ + +/** + * IteratorNext operation + * + * See also: ECMA-262 v10, 7.4.2 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_iterator_next (ecma_value_t iterator, /**< iterator value */ + ecma_value_t next_method, /**< next method */ + ecma_value_t value) /**< the routines's value argument */ +{ + JERRY_ASSERT (ecma_is_value_object (iterator)); + + /* 1 - 2. */ + if (next_method == ECMA_VALUE_UNDEFINED) + { + return ecma_raise_type_error (ECMA_ERR_ITERATOR_NEXT_IS_NOT_CALLABLE); + } + + ecma_object_t *next_method_obj_p = ecma_get_object_from_value (next_method); + + bool has_value = !ecma_is_value_empty (value); + + if (has_value) + { + return ecma_op_function_call (next_method_obj_p, iterator, &value, 1); + } + + return ecma_op_function_call (next_method_obj_p, iterator, NULL, 0); +} /* ecma_op_iterator_next */ + +/** + * IteratorReturn operation + * + * See also: ECMA-262 v6, 14.4.14 (last part) + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object - if success + * raised error - otherwise + */ +static ecma_value_t +ecma_op_iterator_return (ecma_value_t iterator, /**< iterator value */ + ecma_value_t value) /**< the routines's value argument */ +{ + JERRY_ASSERT (ecma_is_value_object (iterator)); + + ecma_object_t *obj_p = ecma_get_object_from_value (iterator); + ecma_value_t func_return = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_RETURN); + + if (ECMA_IS_VALUE_ERROR (func_return)) + { + return func_return; + } + + if (func_return == ECMA_VALUE_UNDEFINED) + { + return ecma_create_iter_result_object (value, ECMA_VALUE_TRUE); + } + + ecma_value_t result = ecma_op_function_validated_call (func_return, iterator, &value, 1); + ecma_free_value (func_return); + + return result; +} /* ecma_op_iterator_return */ + +/** + * IteratorThrow operation + * + * See also: ECMA-262 v6, 14.4.14 (last part) + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object - if success + * raised error - otherwise + */ +static ecma_value_t +ecma_op_iterator_throw (ecma_value_t iterator, /**< iterator value */ + ecma_value_t value) /**< the routines's value argument */ +{ + JERRY_ASSERT (ecma_is_value_object (iterator)); + + ecma_object_t *obj_p = ecma_get_object_from_value (iterator); + ecma_value_t func_throw = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_THROW); + + if (ECMA_IS_VALUE_ERROR (func_throw)) + { + return func_throw; + } + + if (func_throw == ECMA_VALUE_UNDEFINED) + { + ecma_value_t result = ecma_op_iterator_close (iterator); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ecma_free_value (result); + return ecma_raise_type_error (ECMA_ERR_ITERATOR_THROW_IS_NOT_AVAILABLE); + } + + ecma_value_t result = ecma_op_function_validated_call (func_throw, iterator, &value, 1); + ecma_free_value (func_throw); + + return result; +} /* ecma_op_iterator_throw */ + +/** + * IteratorComplete operation + * + * See also: ECMA-262 v10, 7.4.3 + * + * @return true/false - whether the iteration ended + */ +ecma_value_t +ecma_op_iterator_complete (ecma_value_t iter_result) /**< iterator value */ +{ + /* 1. */ + JERRY_ASSERT (ecma_is_value_object (iter_result)); + + /* 2. */ + ecma_object_t *obj_p = ecma_get_object_from_value (iter_result); + + ecma_value_t done = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_DONE); + + if (ECMA_IS_VALUE_ERROR (done)) + { + return done; + } + + ecma_value_t res = ecma_make_boolean_value (ecma_op_to_boolean (done)); + ecma_free_value (done); + + return res; +} /* ecma_op_iterator_complete */ + +/** + * IteratorValue operation + * + * See also: ECMA-262 v6, 7.4.4 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return value of the iterator result object + */ +ecma_value_t +ecma_op_iterator_value (ecma_value_t iter_result) /**< iterator value */ +{ + /* 1. */ + JERRY_ASSERT (ecma_is_value_object (iter_result)); + + /* 2. */ + ecma_object_t *obj_p = ecma_get_object_from_value (iter_result); + return ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_VALUE); +} /* ecma_op_iterator_value */ + +/** + * IteratorClose operation + * + * See also: ECMA-262 v6, 7.4.6 + * + * @return ECMA_VALUE_EMPTY - if "return" is successfully invoked, + * and the operation is called with normal completion + * ECMA_VALUE_ERROR - otherwise + */ +ecma_value_t +ecma_op_iterator_close (ecma_value_t iterator) /**< iterator value */ +{ + /* 1. */ + JERRY_ASSERT (ecma_is_value_object (iterator)); + + /* 2. */ + ecma_value_t completion = ECMA_VALUE_EMPTY; + + if (jcontext_has_pending_exception ()) + { + completion = jcontext_take_exception (); + } + + /* 3. */ + ecma_value_t return_method = ecma_op_get_method_by_magic_id (iterator, LIT_MAGIC_STRING_RETURN); + + /* 4. */ + if (ECMA_IS_VALUE_ERROR (return_method)) + { + ecma_free_value (completion); + return return_method; + } + + /* 5. */ + if (ecma_is_value_undefined (return_method)) + { + if (ecma_is_value_empty (completion)) + { + return ECMA_VALUE_UNDEFINED; + } + + jcontext_raise_exception (completion); + return ECMA_VALUE_ERROR; + } + + /* 6. */ + ecma_object_t *return_obj_p = ecma_get_object_from_value (return_method); + ecma_value_t inner_result = ecma_op_function_call (return_obj_p, iterator, NULL, 0); + ecma_deref_object (return_obj_p); + + /* 7. */ + if (!ecma_is_value_empty (completion)) + { + if (ECMA_IS_VALUE_ERROR (inner_result)) + { + jcontext_release_exception (); + } + else + { + ecma_free_value (inner_result); + } + + jcontext_raise_exception (completion); + return ECMA_VALUE_ERROR; + } + + /* 8. */ + if (ECMA_IS_VALUE_ERROR (inner_result)) + { + ecma_free_value (completion); + return inner_result; + } + + /* 9. */ + bool is_object = ecma_is_value_object (inner_result); + ecma_free_value (inner_result); + + if (!is_object) + { + ecma_free_value (completion); + return ecma_raise_type_error (ECMA_ERR_METHOD_RETURN_IS_NOT_CALLABLE); + } + + /* 10. */ + if (ecma_is_value_empty (completion)) + { + return ECMA_VALUE_UNDEFINED; + } + + jcontext_raise_exception (completion); + return ECMA_VALUE_ERROR; +} /* ecma_op_iterator_close */ + +/** + * IteratorStep operation + * + * See also: ECMA-262 v6, 7.4.5 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator object or ECMA_VALUE_FALSE - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_iterator_step (ecma_value_t iterator, /**< iterator value */ + ecma_value_t next_method) /**< next method */ +{ + /* 1. */ + ecma_value_t result = ecma_op_iterator_next (iterator, next_method, ECMA_VALUE_EMPTY); + + /* 2. */ + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (!ecma_is_value_object (result)) + { + ecma_free_value (result); + return ecma_raise_type_error (ECMA_ERR_ITERATOR_RESULT_IS_NOT_AN_OBJECT); + } + + /* 3. */ + ecma_object_t *obj_p = ecma_get_object_from_value (result); + ecma_value_t done = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_DONE); + + /* 4. */ + if (ECMA_IS_VALUE_ERROR (done)) + { + ecma_free_value (result); + return done; + } + + bool is_done = ecma_op_to_boolean (done); + ecma_free_value (done); + + /* 5. */ + if (is_done) + { + ecma_free_value (result); + return ECMA_VALUE_FALSE; + } + + /* 6. */ + return result; +} /* ecma_op_iterator_step */ + +/** + * Perform a command specified by the command argument + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator object - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_iterator_do (ecma_iterator_command_type_t command, /**< command to be executed */ + ecma_value_t iterator, /**< iterator object */ + ecma_value_t next_method, /**< next method */ + ecma_value_t value, /**< the routines's value argument */ + bool *done_p) /**< it contains the logical value of the done property */ +{ + ecma_value_t result; + + if (command == ECMA_ITERATOR_NEXT) + { + result = ecma_op_iterator_next (iterator, next_method, value); + } + else if (command == ECMA_ITERATOR_THROW) + { + result = ecma_op_iterator_throw (iterator, value); + } + else + { + JERRY_ASSERT (command == ECMA_ITERATOR_RETURN); + result = ecma_op_iterator_return (iterator, value); + } + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (!ecma_is_value_object (result)) + { + ecma_free_value (result); + return ecma_raise_type_error (ECMA_ERR_ITERATOR_RESULT_IS_NOT_AN_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (result); + ecma_value_t done = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_DONE); + + if (ECMA_IS_VALUE_ERROR (done)) + { + ecma_free_value (result); + return done; + } + + *done_p = ecma_op_to_boolean (done); + ecma_free_value (done); + + return result; +} /* ecma_op_iterator_do */ + +/** + * CreateAsyncFromSyncIterator operation + * + * See also: ECMA-262 v10, 25.1.4.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return async from sync iterator object + */ +ecma_value_t +ecma_op_create_async_from_sync_iterator (ecma_value_t sync_iterator, /**< sync iterator */ + ecma_value_t sync_next_method, /**< sync iterator next method */ + ecma_value_t *async_next_method_p) /**< [out] async next method */ +{ + JERRY_ASSERT (ecma_is_value_object (sync_iterator)); + JERRY_ASSERT (ecma_is_value_object (sync_next_method) || ecma_is_value_undefined (sync_next_method)); + + /* 1. */ + ecma_object_t *obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE), + sizeof (ecma_async_from_sync_iterator_object_t), + ECMA_OBJECT_TYPE_CLASS); + + ecma_async_from_sync_iterator_object_t *ext_obj_p = (ecma_async_from_sync_iterator_object_t *) obj_p; + + /* 2. */ + ext_obj_p->sync_next_method = sync_next_method; + ext_obj_p->header.u.cls.u3.sync_iterator = sync_iterator; + ext_obj_p->header.u.cls.type = ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR; + + /* 3. */ + *async_next_method_p = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_NEXT); + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (*async_next_method_p)); + + /* 4. */ + return ecma_make_object_value (obj_p); +} /* ecma_op_create_async_from_sync_iterator */ + +/** + * Async-from-Sync Iterator Value Unwrap Functions + * + * See also: ES11 25.1.4.2.4 + * + * @return iterator result object + */ +ecma_value_t +ecma_async_from_sync_iterator_unwrap_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + ecma_extended_object_t *unwrap_p = (ecma_extended_object_t *) function_obj_p; + + /* 2. */ + ecma_value_t arg = args_count > 0 ? args_p[0] : ECMA_VALUE_UNDEFINED; + ecma_value_t done = + ecma_make_boolean_value (unwrap_p->u.built_in.u2.routine_flags >> ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT); + + return ecma_create_iter_result_object (arg, done); +} /* ecma_async_from_sync_iterator_unwrap_cb */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-iterator-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-iterator-object.h new file mode 100644 index 0000000..0963b03 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-iterator-object.h @@ -0,0 +1,84 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_ITERATOR_OBJECT_H +#define ECMA_ITERATOR_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaiteratorobject ECMA iterator object related routines + * @{ + */ + +/** + * Generator resume execution flags. + */ +typedef enum +{ + ECMA_ITERATOR_NEXT, /**< generator should continue its execution */ + ECMA_ITERATOR_THROW, /**< generator should perform a throw operation */ + ECMA_ITERATOR_RETURN, /**< generator should perform a return operation */ +} ecma_iterator_command_type_t; + +/** + * Maximum value of [[%Iterator%NextIndex]] until it can be stored + * in an ecma pseudo array object structure element. + */ +#define ECMA_ITERATOR_INDEX_LIMIT UINT16_MAX + +ecma_value_t ecma_op_create_iterator_object (ecma_value_t iterated_value, + ecma_object_t *prototype_obj_p, + ecma_object_class_type_t iterator_type, + ecma_iterator_kind_t kind); + +ecma_value_t ecma_create_iter_result_object (ecma_value_t value, ecma_value_t done); + +ecma_value_t ecma_create_array_from_iter_element (ecma_value_t value, ecma_value_t index_value); + +ecma_value_t ecma_op_get_iterator (ecma_value_t value, ecma_value_t method, ecma_value_t *next_method_p); + +ecma_value_t ecma_op_iterator_complete (ecma_value_t iter_result); + +ecma_value_t ecma_op_iterator_value (ecma_value_t iter_result); + +ecma_value_t ecma_op_iterator_next (ecma_value_t iterator, ecma_value_t next_method, ecma_value_t value); + +ecma_value_t ecma_op_iterator_close (ecma_value_t iterator); + +ecma_value_t ecma_op_iterator_step (ecma_value_t iterator, ecma_value_t next_method); + +ecma_value_t ecma_op_iterator_do (ecma_iterator_command_type_t command, + ecma_value_t iterator, + ecma_value_t next_method, + ecma_value_t value, + bool *done_p); + +ecma_value_t ecma_op_create_async_from_sync_iterator (ecma_value_t sync_iterator, + ecma_value_t sync_next_method, + ecma_value_t *async_next_method_p); + +ecma_value_t ecma_async_from_sync_iterator_unwrap_cb (ecma_object_t *function_obj_p, + const ecma_value_t args_p[], + const uint32_t args_count); + +/** + * @} + * @} + */ + +#endif /* !ECMA_ITERATOR_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-jobqueue.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-jobqueue.cpp new file mode 100644 index 0000000..6f798c7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-jobqueue.cpp @@ -0,0 +1,582 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-jobqueue.h" + +#include "ecma-async-generator-object.h" +#include "ecma-function-object.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" + +#include "jcontext.h" +#include "opcodes.h" +#include "vm-stack.h" + +/** + * Mask for job queue type. + */ +#define ECMA_JOB_QUEUE_TYPE_MASK ((uintptr_t) 0x07) + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmajobqueue ECMA Job Queue related routines + * @{ + */ + +/** + * Description of the PromiseReactionJob + */ +typedef struct +{ + ecma_job_queue_item_t header; /**< job queue item header */ + ecma_value_t capability; /**< capability object */ + ecma_value_t handler; /**< handler function */ + ecma_value_t argument; /**< argument for the reaction */ +} ecma_job_promise_reaction_t; + +/** + * Description of the PromiseAsyncReactionJob + */ +typedef struct +{ + ecma_job_queue_item_t header; /**< job queue item header */ + ecma_value_t executable_object; /**< executable object */ + ecma_value_t argument; /**< argument for the reaction */ +} ecma_job_promise_async_reaction_t; + +/** + * Description of the PromiseAsyncGeneratorJob + */ +typedef struct +{ + ecma_job_queue_item_t header; /**< job queue item header */ + ecma_value_t executable_object; /**< executable object */ +} ecma_job_promise_async_generator_t; + +/** + * Description of the PromiseResolveThenableJob + */ +typedef struct +{ + ecma_job_queue_item_t header; /**< job queue item header */ + ecma_value_t promise; /**< promise to be resolved */ + ecma_value_t thenable; /**< thenable object */ + ecma_value_t then; /**< 'then' function */ +} ecma_job_promise_resolve_thenable_t; + +/** + * Initialize the jobqueue. + */ +void +ecma_job_queue_init (void) +{ + JERRY_CONTEXT (job_queue_head_p) = NULL; + JERRY_CONTEXT (job_queue_tail_p) = NULL; +} /* ecma_job_queue_init */ + +/** + * Get the type of the job. + * + * @return type of the job + */ +static inline ecma_job_queue_item_type_t +ecma_job_queue_get_type (ecma_job_queue_item_t *job_p) /**< the job */ +{ + return (ecma_job_queue_item_type_t) (job_p->next_and_type & ECMA_JOB_QUEUE_TYPE_MASK); +} /* ecma_job_queue_get_type */ + +/** + * Get the next job of the job queue. + * + * @return next job + */ +static inline ecma_job_queue_item_t * +ecma_job_queue_get_next (ecma_job_queue_item_t *job_p) /**< the job */ +{ + return (ecma_job_queue_item_t *) (job_p->next_and_type & ~ECMA_JOB_QUEUE_TYPE_MASK); +} /* ecma_job_queue_get_next */ + +/** + * Free the heap and the member of the PromiseReactionJob. + */ +static void +ecma_free_promise_reaction_job (ecma_job_promise_reaction_t *job_p) /**< points to the PromiseReactionJob */ +{ + JERRY_ASSERT (job_p != NULL); + + ecma_free_value (job_p->capability); + ecma_free_value (job_p->handler); + ecma_free_value (job_p->argument); + + jmem_heap_free_block (job_p, sizeof (ecma_job_promise_reaction_t)); +} /* ecma_free_promise_reaction_job */ + +/** + * Free the heap and the member of the PromiseAsyncReactionJob. + */ +static void +ecma_free_promise_async_reaction_job (ecma_job_promise_async_reaction_t *job_p) /**< points to the + * PromiseAsyncReactionJob */ +{ + JERRY_ASSERT (job_p != NULL); + + ecma_free_value (job_p->executable_object); + ecma_free_value (job_p->argument); + + jmem_heap_free_block (job_p, sizeof (ecma_job_promise_async_reaction_t)); +} /* ecma_free_promise_async_reaction_job */ + +/** + * Free the heap and the member of the PromiseAsyncGeneratorJob. + */ +static void +ecma_free_promise_async_generator_job (ecma_job_promise_async_generator_t *job_p) /**< points to the + * PromiseAsyncReactionJob */ +{ + JERRY_ASSERT (job_p != NULL); + + ecma_free_value (job_p->executable_object); + + jmem_heap_free_block (job_p, sizeof (ecma_job_promise_async_generator_t)); +} /* ecma_free_promise_async_generator_job */ + +/** + * Free the heap and the member of the PromiseResolveThenableJob. + */ +static void +ecma_free_promise_resolve_thenable_job (ecma_job_promise_resolve_thenable_t *job_p) /**< points to the + * PromiseResolveThenableJob */ +{ + JERRY_ASSERT (job_p != NULL); + + ecma_free_value (job_p->promise); + ecma_free_value (job_p->thenable); + ecma_free_value (job_p->then); + + jmem_heap_free_block (job_p, sizeof (ecma_job_promise_resolve_thenable_t)); +} /* ecma_free_promise_resolve_thenable_job */ + +/** + * The processor for PromiseReactionJob. + * + * See also: ES2015 25.4.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_process_promise_reaction_job (ecma_job_promise_reaction_t *job_p) /**< the job to be operated */ +{ + /* 2. */ + JERRY_ASSERT ( + ecma_object_class_is (ecma_get_object_from_value (job_p->capability), ECMA_OBJECT_CLASS_PROMISE_CAPABILITY)); + ecma_promise_capability_t *capability_p; + capability_p = (ecma_promise_capability_t *) ecma_get_object_from_value (job_p->capability); + + /* 3. */ + ecma_value_t handler = job_p->handler; + + JERRY_ASSERT (ecma_is_value_boolean (handler) || ecma_op_is_callable (handler)); + + ecma_value_t handler_result; + + if (ecma_is_value_boolean (handler)) + { + /* 4-5. True indicates "identity" and false indicates "thrower" */ + handler_result = ecma_copy_value (job_p->argument); + } + else + { + /* 6. */ + handler_result = + ecma_op_function_call (ecma_get_object_from_value (handler), ECMA_VALUE_UNDEFINED, &(job_p->argument), 1); + } + + ecma_value_t status; + + if (ecma_is_value_false (handler) || ECMA_IS_VALUE_ERROR (handler_result)) + { + if (ECMA_IS_VALUE_ERROR (handler_result)) + { + handler_result = jcontext_take_exception (); + } + + /* 7. */ + status = ecma_op_function_call (ecma_get_object_from_value (capability_p->reject), + ECMA_VALUE_UNDEFINED, + &handler_result, + 1); + } + else + { + /* 8. */ + status = ecma_op_function_call (ecma_get_object_from_value (capability_p->resolve), + ECMA_VALUE_UNDEFINED, + &handler_result, + 1); + } + + ecma_free_value (handler_result); + + ecma_free_promise_reaction_job (job_p); + + return status; +} /* ecma_process_promise_reaction_job */ + +/** + * The processor for PromiseAsyncReactionJob. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_process_promise_async_reaction_job (ecma_job_promise_async_reaction_t *job_p) /**< the job to be operated */ +{ + ecma_object_t *object_p = ecma_get_object_from_value (job_p->executable_object); + vm_executable_object_t *executable_object_p = (vm_executable_object_t *) object_p; + + if (ecma_job_queue_get_type (&job_p->header) == ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED) + { + if (!(executable_object_p->extended_object.u.cls.u2.executable_obj_flags + & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD)) + { + executable_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_throw; + } + else if (ECMA_AWAIT_GET_STATE (executable_object_p) == ECMA_AWAIT_YIELD_RETURN) + { + /* Unlike other operations, return captures rejected promises as well. */ + ECMA_AWAIT_CHANGE_STATE (executable_object_p, YIELD_RETURN, YIELD_OPERATION); + } + else + { + if (ECMA_AWAIT_GET_STATE (executable_object_p) <= ECMA_AWAIT_YIELD_END) + { + JERRY_ASSERT (ecma_is_value_object (executable_object_p->iterator)); + executable_object_p->iterator = ECMA_VALUE_UNDEFINED; + + JERRY_ASSERT (executable_object_p->frame_ctx.stack_top_p[-1] == ECMA_VALUE_UNDEFINED + || ecma_is_value_object (executable_object_p->frame_ctx.stack_top_p[-1])); + executable_object_p->frame_ctx.stack_top_p--; + } + else if (ECMA_AWAIT_GET_STATE (executable_object_p) == ECMA_AWAIT_FOR_CLOSE + && VM_GET_CONTEXT_TYPE (executable_object_p->frame_ctx.stack_top_p[-1]) == VM_CONTEXT_FINALLY_THROW) + { + ecma_free_value (job_p->argument); + job_p->argument = ecma_copy_value (executable_object_p->frame_ctx.stack_top_p[-2]); + } + + /* Exception: Abort iterators, clear all status. */ + executable_object_p->extended_object.u.cls.u2.executable_obj_flags &= ECMA_AWAIT_CLEAR_MASK; + executable_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_throw; + } + } + + ecma_value_t result; + uint16_t expected_bits; + + if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD) + { + job_p->argument = ecma_await_continue (executable_object_p, job_p->argument); + + if (ECMA_IS_VALUE_ERROR (job_p->argument)) + { + job_p->argument = jcontext_take_exception (); + executable_object_p->frame_ctx.byte_code_p = opfunc_resume_executable_object_with_throw; + } + else if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags + & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD) + { + /* Continue iteration. */ + JERRY_ASSERT (job_p->argument == ECMA_VALUE_UNDEFINED); + result = ECMA_VALUE_UNDEFINED; + goto free_job; + } + + if (ECMA_AWAIT_GET_STATE (executable_object_p) <= ECMA_AWAIT_YIELD_END) + { + JERRY_ASSERT (ecma_is_value_object (executable_object_p->iterator)); + executable_object_p->iterator = ECMA_VALUE_UNDEFINED; + + JERRY_ASSERT (executable_object_p->frame_ctx.stack_top_p[-1] == ECMA_VALUE_UNDEFINED + || ecma_is_value_object (executable_object_p->frame_ctx.stack_top_p[-1])); + executable_object_p->frame_ctx.stack_top_p--; + } + + /* Clear all status. */ + executable_object_p->extended_object.u.cls.u2.executable_obj_flags &= ECMA_AWAIT_CLEAR_MASK; + } + + result = opfunc_resume_executable_object (executable_object_p, job_p->argument); + /* Argument reference has been taken by opfunc_resume_executable_object. */ + job_p->argument = ECMA_VALUE_UNDEFINED; + + expected_bits = (ECMA_EXECUTABLE_OBJECT_COMPLETED | ECMA_ASYNC_GENERATOR_CALLED); + if ((executable_object_p->extended_object.u.cls.u2.executable_obj_flags & expected_bits) == expected_bits) + { + ecma_async_generator_finalize (executable_object_p, result); + result = ECMA_VALUE_UNDEFINED; + } + +free_job: + + ecma_free_promise_async_reaction_job (job_p); + return result; +} /* ecma_process_promise_async_reaction_job */ + +/** + * The processor for PromiseAsyncGeneratorJob. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_process_promise_async_generator_job (ecma_job_promise_async_generator_t *job_p) /**< the job to be operated */ +{ + ecma_object_t *object_p = ecma_get_object_from_value (job_p->executable_object); + + ecma_value_t result = ecma_async_generator_run ((vm_executable_object_t *) object_p); + + ecma_free_value (job_p->executable_object); + jmem_heap_free_block (job_p, sizeof (ecma_job_promise_async_generator_t)); + return result; +} /* ecma_process_promise_async_generator_job */ + +/** + * Process the PromiseResolveThenableJob. + * + * See also: ES2015 25.4.2.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_process_promise_resolve_thenable_job (ecma_job_promise_resolve_thenable_t *job_p) /**< the job to be operated */ +{ + ecma_promise_object_t *promise_p = (ecma_promise_object_t *) ecma_get_object_from_value (job_p->promise); + + promise_p->header.u.cls.u1.promise_flags &= (uint8_t) ~ECMA_PROMISE_ALREADY_RESOLVED; + + ecma_value_t ret = ecma_promise_run_executor ((ecma_object_t *) promise_p, job_p->then, job_p->thenable); + + if (ECMA_IS_VALUE_ERROR (ret)) + { + ret = jcontext_take_exception (); + ecma_reject_promise_with_checks (job_p->promise, ret); + ecma_free_value (ret); + ret = ECMA_VALUE_UNDEFINED; + } + + ecma_free_promise_resolve_thenable_job (job_p); + + return ret; +} /* ecma_process_promise_resolve_thenable_job */ + +/** + * Enqueue a Promise job into the jobqueue. + */ +static void +ecma_enqueue_job (ecma_job_queue_item_t *job_p) /**< the job */ +{ + JERRY_ASSERT (job_p->next_and_type <= ECMA_JOB_QUEUE_TYPE_MASK); + + if (JERRY_CONTEXT (job_queue_head_p) == NULL) + { + JERRY_CONTEXT (job_queue_head_p) = job_p; + JERRY_CONTEXT (job_queue_tail_p) = job_p; + } + else + { + JERRY_ASSERT ((JERRY_CONTEXT (job_queue_tail_p)->next_and_type & ~ECMA_JOB_QUEUE_TYPE_MASK) == 0); + + JERRY_CONTEXT (job_queue_tail_p)->next_and_type |= (uintptr_t) job_p; + JERRY_CONTEXT (job_queue_tail_p) = job_p; + } +} /* ecma_enqueue_job */ + +/** + * Enqueue a PromiseReactionJob into the job queue. + */ +void +ecma_enqueue_promise_reaction_job (ecma_value_t capability, /**< capability object */ + ecma_value_t handler, /**< handler function */ + ecma_value_t argument) /**< argument for the reaction */ +{ + ecma_job_promise_reaction_t *job_p; + job_p = (ecma_job_promise_reaction_t *) jmem_heap_alloc_block (sizeof (ecma_job_promise_reaction_t)); + job_p->header.next_and_type = ECMA_JOB_PROMISE_REACTION; + job_p->capability = ecma_copy_value (capability); + job_p->handler = ecma_copy_value (handler); + job_p->argument = ecma_copy_value (argument); + + ecma_enqueue_job (&job_p->header); +} /* ecma_enqueue_promise_reaction_job */ + +/** + * Enqueue a PromiseAsyncReactionJob into the job queue. + */ +void +ecma_enqueue_promise_async_reaction_job (ecma_value_t executable_object, /**< executable object */ + ecma_value_t argument, /**< argument */ + bool is_rejected) /**< is_fulfilled */ +{ + ecma_job_promise_async_reaction_t *job_p; + job_p = (ecma_job_promise_async_reaction_t *) jmem_heap_alloc_block (sizeof (ecma_job_promise_async_reaction_t)); + job_p->header.next_and_type = + (is_rejected ? ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED : ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED); + job_p->executable_object = ecma_copy_value (executable_object); + job_p->argument = ecma_copy_value (argument); + + ecma_enqueue_job (&job_p->header); +} /* ecma_enqueue_promise_async_reaction_job */ + +/** + * Enqueue a PromiseAsyncGeneratorJob into the job queue. + */ +void +ecma_enqueue_promise_async_generator_job (ecma_value_t executable_object) /**< executable object */ +{ + ecma_job_promise_async_generator_t *job_p; + job_p = (ecma_job_promise_async_generator_t *) jmem_heap_alloc_block (sizeof (ecma_job_promise_async_generator_t)); + job_p->header.next_and_type = ECMA_JOB_PROMISE_ASYNC_GENERATOR; + job_p->executable_object = ecma_copy_value (executable_object); + + ecma_enqueue_job (&job_p->header); +} /* ecma_enqueue_promise_async_generator_job */ + +/** + * Enqueue a PromiseResolveThenableJob into the job queue. + */ +void +ecma_enqueue_promise_resolve_thenable_job (ecma_value_t promise, /**< promise to be resolved */ + ecma_value_t thenable, /**< thenable object */ + ecma_value_t then) /**< 'then' function */ +{ + JERRY_ASSERT (ecma_is_promise (ecma_get_object_from_value (promise))); + JERRY_ASSERT (ecma_is_value_object (thenable)); + JERRY_ASSERT (ecma_op_is_callable (then)); + + ecma_job_promise_resolve_thenable_t *job_p; + job_p = (ecma_job_promise_resolve_thenable_t *) jmem_heap_alloc_block (sizeof (ecma_job_promise_resolve_thenable_t)); + job_p->header.next_and_type = ECMA_JOB_PROMISE_THENABLE; + job_p->promise = ecma_copy_value (promise); + job_p->thenable = ecma_copy_value (thenable); + job_p->then = ecma_copy_value (then); + + ecma_enqueue_job (&job_p->header); +} /* ecma_enqueue_promise_resolve_thenable_job */ + +/** + * Process enqueued Promise jobs until the first thrown error or until the + * jobqueue becomes empty. + * + * @return result of the last processed job - if the jobqueue was non-empty, + * undefined - otherwise. + */ +ecma_value_t +ecma_process_all_enqueued_jobs (void) +{ + ecma_value_t ret = ECMA_VALUE_UNDEFINED; + + while (JERRY_CONTEXT (job_queue_head_p) != NULL) + { + ecma_job_queue_item_t *job_p = JERRY_CONTEXT (job_queue_head_p); + JERRY_CONTEXT (job_queue_head_p) = ecma_job_queue_get_next (job_p); + + ecma_fast_free_value (ret); + + switch (ecma_job_queue_get_type (job_p)) + { + case ECMA_JOB_PROMISE_REACTION: + { + ret = ecma_process_promise_reaction_job ((ecma_job_promise_reaction_t *) job_p); + break; + } + case ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED: + case ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED: + { + ret = ecma_process_promise_async_reaction_job ((ecma_job_promise_async_reaction_t *) job_p); + break; + } + case ECMA_JOB_PROMISE_ASYNC_GENERATOR: + { + ret = ecma_process_promise_async_generator_job ((ecma_job_promise_async_generator_t *) job_p); + break; + } + default: + { + JERRY_ASSERT (ecma_job_queue_get_type (job_p) == ECMA_JOB_PROMISE_THENABLE); + + ret = ecma_process_promise_resolve_thenable_job ((ecma_job_promise_resolve_thenable_t *) job_p); + break; + } + } + + if (ECMA_IS_VALUE_ERROR (ret)) + { + return ret; + } + } + + ecma_free_value (ret); + return ECMA_VALUE_UNDEFINED; +} /* ecma_process_all_enqueued_jobs */ + +/** + * Release enqueued Promise jobs. + */ +void +ecma_free_all_enqueued_jobs (void) +{ + while (JERRY_CONTEXT (job_queue_head_p) != NULL) + { + ecma_job_queue_item_t *job_p = JERRY_CONTEXT (job_queue_head_p); + JERRY_CONTEXT (job_queue_head_p) = ecma_job_queue_get_next (job_p); + + switch (ecma_job_queue_get_type (job_p)) + { + case ECMA_JOB_PROMISE_REACTION: + { + ecma_free_promise_reaction_job ((ecma_job_promise_reaction_t *) job_p); + break; + } + case ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED: + case ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED: + { + ecma_free_promise_async_reaction_job ((ecma_job_promise_async_reaction_t *) job_p); + break; + } + case ECMA_JOB_PROMISE_ASYNC_GENERATOR: + { + ecma_free_promise_async_generator_job ((ecma_job_promise_async_generator_t *) job_p); + break; + } + default: + { + JERRY_ASSERT (ecma_job_queue_get_type (job_p) == ECMA_JOB_PROMISE_THENABLE); + + ecma_free_promise_resolve_thenable_job ((ecma_job_promise_resolve_thenable_t *) job_p); + break; + } + } + } +} /* ecma_free_all_enqueued_jobs */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-jobqueue.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-jobqueue.h new file mode 100644 index 0000000..b56027c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-jobqueue.h @@ -0,0 +1,63 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_JOB_QUEUE_H +#define ECMA_JOB_QUEUE_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmajobqueue ECMA Job Queue related routines + * @{ + */ + +/** + * Job queue item types. + */ +typedef enum +{ + ECMA_JOB_PROMISE_REACTION, /**< promise reaction job */ + ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED, /**< fulfilled promise async reaction job */ + ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED, /**< rejected promise async reaction job */ + ECMA_JOB_PROMISE_ASYNC_GENERATOR, /**< continue async generator */ + ECMA_JOB_PROMISE_THENABLE, /**< promise thenable job */ +} ecma_job_queue_item_type_t; + +/** + * Description of the job queue item. + */ +typedef struct +{ + uintptr_t next_and_type; /**< next and type members of a queue item */ +} ecma_job_queue_item_t; + +void ecma_job_queue_init (void); + +void ecma_enqueue_promise_reaction_job (ecma_value_t capability, ecma_value_t handler, ecma_value_t argument); +void ecma_enqueue_promise_async_reaction_job (ecma_value_t executable_object, ecma_value_t argument, bool is_rejected); +void ecma_enqueue_promise_async_generator_job (ecma_value_t executable_object); +void ecma_enqueue_promise_resolve_thenable_job (ecma_value_t promise, ecma_value_t thenable, ecma_value_t then); +void ecma_free_all_enqueued_jobs (void); + +ecma_value_t ecma_process_all_enqueued_jobs (void); + +/** + * @} + * @} + */ + +#endif /* !ECMA_JOB_QUEUE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-lex-env.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-lex-env.cpp new file mode 100644 index 0000000..c4001d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-lex-env.cpp @@ -0,0 +1,643 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-lex-env.h" + +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-proxy-object.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup lexicalenvironment Lexical environment + * @{ + * + * \addtogroup globallexicalenvironment Global lexical environment + * @{ + */ + +/** + * Initialize Global environment + */ +void +ecma_init_global_environment (void) +{ + JERRY_CONTEXT (global_object_p) = ecma_builtin_create_global_object (); +} /* ecma_init_global_environment */ + +/** + * Finalize Global environment + */ +void +ecma_finalize_global_environment (void) +{ + /* After this point the gc can free the global object, but the global_object_p pointer + * is not set to NULL because the global object might still be used before the free. */ + ecma_deref_object ((ecma_object_t *) JERRY_CONTEXT (global_object_p)); +} /* ecma_finalize_global_environment */ + +/** + * Get reference to Global lexical environment + * without increasing its reference count. + * + * @return pointer to the object's instance + */ +ecma_object_t * +ecma_get_global_environment (ecma_object_t *global_object_p) /**< global object */ +{ + JERRY_ASSERT (global_object_p != NULL && ecma_builtin_is_global (global_object_p)); + return ECMA_GET_NON_NULL_POINTER (ecma_object_t, ((ecma_global_object_t *) global_object_p)->global_env_cp); +} /* ecma_get_global_environment */ + +/** + * Create the global lexical block on top of the global environment. + */ +void +ecma_create_global_lexical_block (ecma_object_t *global_object_p) /**< global object */ +{ + JERRY_ASSERT (global_object_p != NULL && ecma_builtin_is_global (global_object_p)); + + ecma_global_object_t *real_global_object_p = (ecma_global_object_t *) global_object_p; + + if (real_global_object_p->global_scope_cp == real_global_object_p->global_env_cp) + { + ecma_object_t *global_scope_p = ecma_create_decl_lex_env (ecma_get_global_environment (global_object_p)); + global_scope_p->type_flags_refs |= ECMA_OBJECT_FLAG_BLOCK; + ECMA_SET_NON_NULL_POINTER (real_global_object_p->global_scope_cp, global_scope_p); + ecma_deref_object (global_scope_p); + } +} /* ecma_create_global_lexical_block */ + +/** + * Raise the appropriate error when setting a binding is failed + * + * @return ECMA_VALUE_EMPTY or ECMA_VALUE_ERROR + */ +ecma_value_t +ecma_op_raise_set_binding_error (ecma_property_t *property_p, /**< property */ + bool is_strict) /**< flag indicating strict mode */ +{ + JERRY_UNUSED (property_p); + + const ecma_property_t expected_bits = (ECMA_PROPERTY_FLAG_DATA | ECMA_PROPERTY_FLAG_ENUMERABLE); + + if ((*property_p & expected_bits) == expected_bits) + { + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (JERRY_UNLIKELY (property_value_p->value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + + JERRY_ASSERT (!ecma_is_property_writable (*property_p)); + + return ecma_raise_type_error (ECMA_ERR_CONSTANT_BINDINGS_CANNOT_BE_REASSIGNED); + } + + if (is_strict) + { + return ecma_raise_type_error (ECMA_ERR_BINDING_CANNOT_SET); + } + return ECMA_VALUE_EMPTY; +} /* ecma_op_raise_set_binding_error */ + +/** + * Get reference to Global lexical scope + * without increasing its reference count. + * + * @return pointer to the object's instance + */ +ecma_object_t * +ecma_get_global_scope (ecma_object_t *global_object_p) /**< global object */ +{ + JERRY_ASSERT (global_object_p != NULL && ecma_builtin_is_global (global_object_p)); + return ECMA_GET_NON_NULL_POINTER (ecma_object_t, ((ecma_global_object_t *) global_object_p)->global_scope_cp); +} /* ecma_get_global_scope */ + +/** + * @} + */ + +/** + * HasBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + * + * @return true / false + */ +ecma_value_t +ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p) /**< argument N */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + + ecma_lexical_environment_type_t lex_env_type = ecma_get_lex_env_type (lex_env_p); + + switch (lex_env_type) + { + case ECMA_LEXICAL_ENVIRONMENT_CLASS: + { + if (!ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + return ECMA_VALUE_FALSE; + } + /* FALLTHRU */ + } + case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + return ecma_make_boolean_value (property_p != NULL); + } + default: + { + JERRY_ASSERT (lex_env_type == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + + return ecma_op_object_has_property (binding_obj_p, name_p); + } + } +} /* ecma_op_has_binding */ + +/** + * CreateMutableBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + * + * @return ECMA_PROPERTY_POINTER_ERROR - if the operation raises error + * pointer to the created property - if the binding was created into a declarative environment + * NULL - otherwise + */ +ecma_property_t * +ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p, /**< argument N */ + bool is_deletable) /**< argument D */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + JERRY_ASSERT (name_p != NULL); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_WRITABLE; + + if (is_deletable) + { + prop_attributes = (uint8_t) (prop_attributes | ECMA_PROPERTY_FLAG_CONFIGURABLE); + } + + ecma_property_t *prop_p; + + ecma_create_named_data_property (lex_env_p, name_p, prop_attributes, &prop_p); + return prop_p; + } + else + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + +#if JERRY_BUILTIN_PROXY && JERRY_BUILTIN_REALMS + if (ECMA_OBJECT_IS_PROXY (binding_obj_p)) + { + ecma_value_t result = ecma_proxy_object_is_extensible (binding_obj_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return ECMA_PROPERTY_POINTER_ERROR; + } + + if (result == ECMA_VALUE_FALSE) + { + return NULL; + } + } + else if (!ecma_op_ordinary_object_is_extensible (binding_obj_p)) + { + return NULL; + } +#else /* !JERRY_BUILTIN_PROXY || !JERRY_BUILTIN_REALMS */ + if (!ecma_op_ordinary_object_is_extensible (binding_obj_p)) + { + return NULL; + } +#endif /* JERRY_BUILTIN_PROXY && JERRY_BUILTIN_REALMS */ + + const uint32_t flags = ECMA_PROPERTY_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + + ecma_value_t completion = + ecma_builtin_helper_def_prop (binding_obj_p, + name_p, + ECMA_VALUE_UNDEFINED, + is_deletable ? flags | ECMA_PROPERTY_FLAG_CONFIGURABLE : flags); + + if (ECMA_IS_VALUE_ERROR (completion)) + { + return ECMA_PROPERTY_POINTER_ERROR; + } + else + { + JERRY_ASSERT (ecma_is_value_boolean (completion)); + } + } + + return NULL; +} /* ecma_op_create_mutable_binding */ + +/** + * SetMutableBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p, /**< argument N */ + ecma_value_t value, /**< argument V */ + bool is_strict) /**< argument S */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + JERRY_ASSERT (name_p != NULL); + + switch (ecma_get_lex_env_type (lex_env_p)) + { + case ECMA_LEXICAL_ENVIRONMENT_CLASS: + { + if (!ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + return ECMA_VALUE_EMPTY; + } + /* FALLTHRU */ + } + case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (JERRY_UNLIKELY (property_p == NULL)) + { + property_p = ecma_op_create_mutable_binding (lex_env_p, name_p, is_strict); + JERRY_ASSERT (property_p != ECMA_PROPERTY_POINTER_ERROR); + } + + JERRY_ASSERT (property_p != NULL && ECMA_PROPERTY_IS_RAW_DATA (*property_p)); + JERRY_ASSERT (!(*property_p & ECMA_PROPERTY_FLAG_WRITABLE) || (*property_p & ECMA_PROPERTY_FLAG_DATA)); + + if ((*property_p & ECMA_PROPERTY_FLAG_WRITABLE)) + { + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + JERRY_ASSERT (property_value_p->value != ECMA_VALUE_UNINITIALIZED); + + ecma_named_data_property_assign_value (lex_env_p, property_value_p, value); + return ECMA_VALUE_EMPTY; + } + + return ecma_op_raise_set_binding_error (property_p, is_strict); + } + default: + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + + ecma_value_t completion = ecma_op_object_put (binding_obj_p, name_p, value, is_strict); + + if (ECMA_IS_VALUE_ERROR (completion)) + { + return completion; + } + + JERRY_ASSERT (ecma_is_value_boolean (completion)); + return ECMA_VALUE_EMPTY; + } + } +} /* ecma_op_set_mutable_binding */ + +/** + * GetBindingValue operation. + * + * See also: ECMA-262 v5, 10.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p, /**< argument N */ + bool is_strict) /**< argument S */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + JERRY_ASSERT (name_p != NULL); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_value_t *prop_value_p = ecma_get_named_data_property (lex_env_p, name_p); + + return ecma_copy_value (prop_value_p->value); + } + else + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + + ecma_value_t result = ecma_op_object_find (binding_obj_p, name_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (!ecma_is_value_found (result)) + { + if (is_strict) + { + result = ecma_raise_reference_error (ECMA_ERR_BINDING_NOT_EXIST_OR_UNINITIALIZED); + } + else + { + result = ECMA_VALUE_UNDEFINED; + } + } + + return result; + } +} /* ecma_op_get_binding_value */ + +/** + * DeleteBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + * + * @return ecma value + * Return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the binding can be deleted + */ +ecma_value_t +ecma_op_delete_binding (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p) /**< argument N */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + JERRY_ASSERT (name_p != NULL); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *prop_p = ecma_find_named_property (lex_env_p, name_p); + ecma_value_t ret_val; + + if (prop_p == NULL) + { + ret_val = ECMA_VALUE_TRUE; + } + else + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW_DATA (*prop_p)); + + if (!ecma_is_property_configurable (*prop_p)) + { + ret_val = ECMA_VALUE_FALSE; + } + else + { + ecma_delete_property (lex_env_p, ECMA_PROPERTY_VALUE_PTR (prop_p)); + + ret_val = ECMA_VALUE_TRUE; + } + } + + return ret_val; + } + else + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + + return ecma_op_object_delete (binding_obj_p, name_p, false); + } +} /* ecma_op_delete_binding */ + +/** + * ImplicitThisValue operation. + * + * See also: ECMA-262 v5, 10.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_implicit_this_value (ecma_object_t *lex_env_p) /**< lexical environment */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + return ECMA_VALUE_UNDEFINED; + } + else + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + ecma_ref_object (binding_obj_p); + + return ecma_make_object_value (binding_obj_p); + } +} /* ecma_op_implicit_this_value */ + +/** + * CreateImmutableBinding operation. + * + * See also: ECMA-262 v5, 10.2.1 + */ +void +ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p, /**< argument N */ + ecma_value_t value) /**< argument V */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + + /* + * Warning: + * Whether immutable bindings are deletable seems not to be defined by ECMA v5. + */ + ecma_property_value_t *prop_value_p = ecma_create_named_data_property (lex_env_p, name_p, ECMA_PROPERTY_FIXED, NULL); + + prop_value_p->value = ecma_copy_value_if_not_object (value); +} /* ecma_op_create_immutable_binding */ + +/** + * InitializeBinding operation. + * + * See also: ECMA-262 v6, 8.1.1.1.4 + */ +void +ecma_op_initialize_binding (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p, /**< argument N */ + ecma_value_t value) /**< argument V */ +{ + JERRY_ASSERT (lex_env_p != NULL && ecma_is_lexical_environment (lex_env_p)); + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + + ecma_property_t *prop_p = ecma_find_named_property (lex_env_p, name_p); + JERRY_ASSERT (prop_p != NULL && ECMA_PROPERTY_IS_RAW_DATA (*prop_p)); + + ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (prop_p); + JERRY_ASSERT (prop_value_p->value == ECMA_VALUE_UNINITIALIZED); + + prop_value_p->value = ecma_copy_value_if_not_object (value); +} /* ecma_op_initialize_binding */ + +/** + * BindThisValue operation for an empty lexical environment + * + * See also: ECMA-262 v6, 8.1.1.3.1 + */ +void +ecma_op_create_environment_record (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_value_t this_binding, /**< this binding value */ + ecma_object_t *func_obj_p) /**< function object */ +{ + JERRY_ASSERT (lex_env_p != NULL); + JERRY_ASSERT (ecma_is_value_object (this_binding) || this_binding == ECMA_VALUE_UNINITIALIZED); + + ecma_environment_record_t *environment_record_p; + environment_record_p = (ecma_environment_record_t *) jmem_heap_alloc_block (sizeof (ecma_environment_record_t)); + + environment_record_p->this_binding = this_binding; + environment_record_p->function_object = ecma_make_object_value (func_obj_p); + + ecma_string_t *property_name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD); + + ecma_property_t *property_p; + ecma_property_value_t *prop_value_p; + ECMA_CREATE_INTERNAL_PROPERTY (lex_env_p, property_name_p, property_p, prop_value_p); + + ECMA_SET_INTERNAL_VALUE_POINTER (prop_value_p->value, environment_record_p); +} /* ecma_op_create_environment_record */ + +/** + * GetThisEnvironment operation. + * + * See also: ECMA-262 v6, 8.3.2 + * + * @return property pointer for the internal [[ThisBindingValue]] property + */ +ecma_environment_record_t * +ecma_op_get_environment_record (ecma_object_t *lex_env_p) /**< lexical environment */ +{ + JERRY_ASSERT (lex_env_p != NULL); + + ecma_string_t *property_name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD); + while (true) + { + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, property_name_p); + + if (property_p != NULL) + { + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_environment_record_t, property_value_p->value); + } + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + return NULL; +} /* ecma_op_get_environment_record */ + +/** + * Get the environment record [[ThisBindingStatus]] internal property. + * + * See also: ECMA-262 v6, 8.1.1.3 + * + * @return true - if the status is "initialized" + * false - otherwise + */ +bool +ecma_op_this_binding_is_initialized (ecma_environment_record_t *environment_record_p) /**< environment record */ +{ + JERRY_ASSERT (environment_record_p != NULL); + + return environment_record_p->this_binding != ECMA_VALUE_UNINITIALIZED; +} /* ecma_op_this_binding_is_initialized */ + +/** + * BindThisValue operation. + * + * See also: ECMA-262 v6, 8.1.1.3.1 + */ +void +ecma_op_bind_this_value (ecma_environment_record_t *environment_record_p, /**< environment record */ + ecma_value_t this_binding) /**< this binding value */ +{ + JERRY_ASSERT (environment_record_p != NULL); + JERRY_ASSERT (ecma_is_value_object (this_binding)); + JERRY_ASSERT (!ecma_op_this_binding_is_initialized (environment_record_p)); + + environment_record_p->this_binding = this_binding; +} /* ecma_op_bind_this_value */ + +/** + * GetThisBinding operation. + * + * See also: ECMA-262 v6, 8.1.1.3.4 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ecma-object - otherwise + */ +ecma_value_t +ecma_op_get_this_binding (ecma_object_t *lex_env_p) /**< lexical environment */ +{ + JERRY_ASSERT (lex_env_p != NULL); + + ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (lex_env_p); + JERRY_ASSERT (environment_record_p != NULL); + + ecma_value_t this_value = environment_record_p->this_binding; + + if (this_value == ECMA_VALUE_UNINITIALIZED) + { + return ecma_raise_reference_error (ECMA_ERR_CALL_SUPER_CONSTRUCTOR_DERIVED_CLASS_BEFORE_THIS); + } + + ecma_ref_object (ecma_get_object_from_value (this_value)); + + return this_value; +} /* ecma_op_get_this_binding */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-lex-env.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-lex-env.h new file mode 100644 index 0000000..e71d729 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-lex-env.h @@ -0,0 +1,85 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_LEX_ENV_H +#define ECMA_LEX_ENV_H + +#include "ecma-globals.h" +#include "ecma-reference.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup lexicalenvironment Lexical environment + * @{ + * + * \addtogroup globallexicalenvironment Global lexical environment + * @{ + */ + +void ecma_init_global_environment (void); +void ecma_finalize_global_environment (void); +ecma_object_t *ecma_get_global_environment (ecma_object_t *global_object_p); +ecma_object_t *ecma_get_global_scope (ecma_object_t *global_object_p); +void ecma_create_global_lexical_block (ecma_object_t *global_object_p); +ecma_value_t ecma_op_raise_set_binding_error (ecma_property_t *property_p, bool is_strict); + +#if JERRY_MODULE_SYSTEM +void ecma_module_add_lex_env (ecma_object_t *lex_env_p); +void ecma_module_finalize_lex_envs (void); +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * @} + */ + +/* ECMA-262 v5, 8.7.1 and 8.7.2 */ +ecma_value_t +ecma_op_get_value_lex_env_base (ecma_object_t *lex_env_p, ecma_object_t **ref_base_lex_env_p, ecma_string_t *name_p); +ecma_value_t ecma_op_get_value_object_base (ecma_value_t base_value, ecma_string_t *property_name_p); +ecma_value_t ecma_op_put_value_lex_env_base (ecma_object_t *lex_env_p, + ecma_string_t *var_name_string_p, + bool is_strict, + ecma_value_t value); + +/* ECMA-262 v5, Table 17. Abstract methods of Environment Records */ +ecma_value_t ecma_op_has_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p); +ecma_property_t *ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p, bool is_deletable); +ecma_value_t +ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p, ecma_value_t value, bool is_strict); +ecma_value_t ecma_op_get_binding_value (ecma_object_t *lex_env_p, ecma_string_t *name_p, bool is_strict); +ecma_value_t ecma_op_delete_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p); +ecma_value_t ecma_op_implicit_this_value (ecma_object_t *lex_env_p); + +/* ECMA-262 v5, Table 18. Additional methods of Declarative Environment Records */ +void ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p, ecma_value_t value); + +void ecma_op_initialize_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p, ecma_value_t value); + +void ecma_op_create_environment_record (ecma_object_t *lex_env_p, ecma_value_t this_binding, ecma_object_t *func_obj_p); +ecma_environment_record_t *ecma_op_get_environment_record (ecma_object_t *lex_env_p); + +bool ecma_op_this_binding_is_initialized (ecma_environment_record_t *environment_record_p); +void ecma_op_bind_this_value (ecma_environment_record_t *environment_record_p, ecma_value_t this_binding); +ecma_value_t ecma_op_get_this_binding (ecma_object_t *lex_env_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_LEX_ENV_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-number-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-number-object.cpp new file mode 100644 index 0000000..548f2f7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-number-object.cpp @@ -0,0 +1,95 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-number-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmanumberobject ECMA Number object related routines + * @{ + */ + +/** + * Number object creation operation. + * + * See also: ECMA-262 v5, 15.7.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_number_object (ecma_value_t arg) /**< argument passed to the Number constructor */ +{ + ecma_number_t num; + ecma_value_t conv_to_num_completion = ecma_op_to_number (arg, &num); + + if (ECMA_IS_VALUE_ERROR (conv_to_num_completion)) + { + return conv_to_num_completion; + } + + conv_to_num_completion = ecma_make_number_value (num); + ecma_builtin_id_t proto_id; +#if JERRY_BUILTIN_NUMBER + proto_id = ECMA_BUILTIN_ID_NUMBER_PROTOTYPE; +#else /* JERRY_BUILTIN_NUMBER */ + proto_id = ECMA_BUILTIN_ID_OBJECT_PROTOTYPE; +#endif /* JERRY_BUILTIN_NUMBER */ + ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id); + + ecma_object_t *new_target = JERRY_CONTEXT (current_new_target_p); + if (new_target) + { + prototype_obj_p = ecma_op_get_prototype_from_constructor (new_target, proto_id); + if (JERRY_UNLIKELY (prototype_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + } + + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_NUMBER; + + /* Pass reference (no need to free conv_to_num_completion). */ + ext_object_p->u.cls.u3.value = conv_to_num_completion; + + if (new_target) + { + ecma_deref_object (prototype_obj_p); + } + + return ecma_make_object_value (object_p); +} /* ecma_op_create_number_object */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-number-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-number-object.h new file mode 100644 index 0000000..c4baf75 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-number-object.h @@ -0,0 +1,35 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_NUMBER_OBJECT_H +#define ECMA_NUMBER_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmanumberobject ECMA Number object related routines + * @{ + */ + +ecma_value_t ecma_op_create_number_object (ecma_value_t arg); + +/** + * @} + * @} + */ + +#endif /* !ECMA_NUMBER_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects-general.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects-general.cpp new file mode 100644 index 0000000..e304778 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects-general.cpp @@ -0,0 +1,740 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-objects-general.h" + +#include "ecma-arguments-object.h" +#include "ecma-array-object.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-proxy-object.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaobjectsinternalops ECMA objects' operations + * @{ + */ + +/** + * 'Object' object creation operation with no arguments. + * + * See also: ECMA-262 v5, 15.2.2.1 + * + * @return pointer to newly created 'Object' object + */ +ecma_object_t * +ecma_op_create_object_object_noarg (void) +{ + ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + + /* 3., 4., 6., 7. */ + return ecma_op_create_object_object_noarg_and_set_prototype (object_prototype_p); +} /* ecma_op_create_object_object_noarg */ + +/** + * Object creation operation with no arguments. + * It sets the given prototype to the newly created object. + * + * See also: ECMA-262 v5, 15.2.2.1, 15.2.3.5 + * + * @return pointer to newly created object + */ +ecma_object_t * +ecma_op_create_object_object_noarg_and_set_prototype (ecma_object_t *object_prototype_p) /**< pointer to prototype of + the object + (can be NULL) */ +{ + ecma_object_t *obj_p = ecma_create_object (object_prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); + + /* + * [[Class]] property of ECMA_OBJECT_TYPE_GENERAL type objects + * without ECMA_INTERNAL_PROPERTY_CLASS internal property + * is "Object". + * + * See also: ecma_object_get_class_name + */ + + return obj_p; +} /* ecma_op_create_object_object_noarg_and_set_prototype */ + +/** + * [[Delete]] ecma general object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 8.12.7 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + bool is_throw) /**< flag that controls failure handling */ +{ + JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); + JERRY_ASSERT (property_name_p != NULL); + + /* 1. */ + ecma_property_ref_t property_ref; + + ecma_property_t property = + ecma_op_object_get_own_property (obj_p, property_name_p, &property_ref, ECMA_PROPERTY_GET_NO_OPTIONS); + + /* 2. */ + if (!ECMA_PROPERTY_IS_FOUND (property)) + { + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + return ECMA_VALUE_TRUE; + } + + /* 3. */ + if (!ecma_is_property_configurable (property)) + { + /* 4. */ + if (is_throw) + { + return ecma_raise_type_error (ECMA_ERR_EXPECTED_A_CONFIGURABLE_PROPERTY); + } + + /* 5. */ + return ECMA_VALUE_FALSE; + } + + ecma_object_type_t type = ecma_get_object_type (obj_p); + + if (type == ECMA_OBJECT_TYPE_ARRAY && ecma_array_object_delete_property (obj_p, property_name_p)) + { + return ECMA_VALUE_TRUE; + } + + /* a. */ + ecma_delete_property (obj_p, property_ref.value_p); + + if (property & ECMA_PROPERTY_FLAG_BUILT_IN) + { + switch (type) + { + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + if (ecma_builtin_function_is_routine (obj_p)) + { + ecma_builtin_routine_delete_built_in_property (obj_p, property_name_p); + break; + } + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + ecma_builtin_delete_built_in_property (obj_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_CLASS: + { + JERRY_ASSERT (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_ARGUMENTS)); + ecma_op_arguments_delete_built_in_property (obj_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_FUNCTION: + { + ecma_op_function_delete_built_in_property (obj_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + ecma_op_bound_function_delete_built_in_property (obj_p, property_name_p); + break; + } + default: + { + JERRY_UNREACHABLE (); + break; + } + } + } + + /* b. */ + return ECMA_VALUE_TRUE; +} /* ecma_op_general_object_delete */ + +/** + * Property invocation order during [[DefaultValue]] operation with string hint + */ +static const lit_magic_string_id_t to_primitive_string_hint_method_names[2] = { + LIT_MAGIC_STRING_TO_STRING_UL, /**< toString operation */ + LIT_MAGIC_STRING_VALUE_OF_UL, /**< valueOf operation */ +}; + +/** + * Property invocation order during [[DefaultValue]] operation with non string hint + */ +static const lit_magic_string_id_t to_primitive_non_string_hint_method_names[2] = { + LIT_MAGIC_STRING_VALUE_OF_UL, /**< valueOf operation */ + LIT_MAGIC_STRING_TO_STRING_UL, /**< toString operation */ +}; + +/** + * Hints for the ecma general object's toPrimitive operation + */ +static const lit_magic_string_id_t hints[3] = { + LIT_MAGIC_STRING_DEFAULT, /**< "default" hint */ + LIT_MAGIC_STRING_NUMBER, /**< "number" hint */ + LIT_MAGIC_STRING_STRING, /**< "string" hint */ +}; + +/** + * [[DefaultValue]] ecma general object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 8.12.8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_general_object_default_value (ecma_object_t *obj_p, /**< the object */ + ecma_preferred_type_hint_t hint) /**< hint on preferred result type */ +{ + JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); + + ecma_value_t obj_value = ecma_make_object_value (obj_p); + + ecma_value_t exotic_to_prim = ecma_op_get_method_by_symbol_id (obj_value, LIT_GLOBAL_SYMBOL_TO_PRIMITIVE); + + if (ECMA_IS_VALUE_ERROR (exotic_to_prim)) + { + return exotic_to_prim; + } + + if (!ecma_is_value_undefined (exotic_to_prim)) + { + ecma_object_t *call_func_p = ecma_get_object_from_value (exotic_to_prim); + ecma_value_t argument = ecma_make_magic_string_value (hints[hint]); + + ecma_value_t result = ecma_op_function_call (call_func_p, obj_value, &argument, 1); + + ecma_free_value (exotic_to_prim); + + if (ECMA_IS_VALUE_ERROR (result) || !ecma_is_value_object (result)) + { + return result; + } + + ecma_free_value (result); + + return ecma_raise_type_error (ECMA_ERR_RESULT_OF_DEFAULTVALUE_IS_INVALID); + } + + ecma_free_value (exotic_to_prim); + + if (hint == ECMA_PREFERRED_TYPE_NO) + { + hint = ECMA_PREFERRED_TYPE_NUMBER; + } + + return ecma_op_general_object_ordinary_value (obj_p, hint); +} /* ecma_op_general_object_default_value */ + +/** + * Ecma general object's OrdinaryToPrimitive operation + * + * See also: + * ECMA-262 v6 7.1.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_general_object_ordinary_value (ecma_object_t *obj_p, /**< the object */ + ecma_preferred_type_hint_t hint) /**< hint on preferred result type */ +{ + const lit_magic_string_id_t *function_name_ids_p = + (hint == ECMA_PREFERRED_TYPE_STRING ? to_primitive_string_hint_method_names + : to_primitive_non_string_hint_method_names); + + for (uint32_t i = 0; i < 2; i++) + { + ecma_value_t function_value = ecma_op_object_get_by_magic_id (obj_p, function_name_ids_p[i]); + + if (ECMA_IS_VALUE_ERROR (function_value)) + { + return function_value; + } + + ecma_value_t call_completion = ECMA_VALUE_EMPTY; + + if (ecma_op_is_callable (function_value)) + { + ecma_object_t *func_obj_p = ecma_get_object_from_value (function_value); + + call_completion = ecma_op_function_call (func_obj_p, ecma_make_object_value (obj_p), NULL, 0); + } + + ecma_free_value (function_value); + + if (ECMA_IS_VALUE_ERROR (call_completion) + || (!ecma_is_value_empty (call_completion) && !ecma_is_value_object (call_completion))) + { + return call_completion; + } + + ecma_free_value (call_completion); + } + + return ecma_raise_type_error (ECMA_ERR_RESULT_OF_DEFAULTVALUE_IS_INVALID); +} /* ecma_op_general_object_ordinary_value */ + +/** + * Special types for ecma_op_general_object_define_own_property. + */ +typedef enum +{ + ECMA_OP_OBJECT_DEFINE_GENERIC = 1, /**< generic property */ + ECMA_OP_OBJECT_DEFINE_ACCESSOR = 0, /**< accessor property */ + ECMA_OP_OBJECT_DEFINE_DATA = ECMA_PROPERTY_FLAG_DATA /**< data property */ +} ecma_op_object_define_own_property_type_t; + +/** + * [[DefineOwnProperty]] ecma general object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 8.12.9 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + const ecma_property_descriptor_t *property_desc_p) /**< property + * descriptor */ +{ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + return ecma_proxy_object_define_own_property (object_p, property_name_p, property_desc_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + JERRY_ASSERT (object_p != NULL && !ecma_is_lexical_environment (object_p)); + JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p)); + JERRY_ASSERT (property_name_p != NULL); + + uint8_t property_desc_type = ECMA_OP_OBJECT_DEFINE_GENERIC; + + if (property_desc_p->flags & (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED)) + { + /* A property descriptor cannot be both named data and named accessor. */ + JERRY_ASSERT ((property_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + != (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)); + property_desc_type = ECMA_OP_OBJECT_DEFINE_DATA; + } + else if (property_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + { + JERRY_ASSERT (!(property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED)); + property_desc_type = ECMA_OP_OBJECT_DEFINE_ACCESSOR; + } + + /* These three asserts ensures that a new property is created with the appropriate default flags. + * E.g. if JERRY_PROP_IS_CONFIGURABLE_DEFINED is false, the newly created property must be non-configurable. */ + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED) + || !(property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE)); + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + || !(property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE)); + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) + || !(property_desc_p->flags & JERRY_PROP_IS_WRITABLE)); + + /* 1. */ + ecma_extended_property_ref_t ext_property_ref = { {NULL, }, NULL }; + ecma_property_t current_prop; + + current_prop = ecma_op_object_get_own_property (object_p, + property_name_p, + &ext_property_ref.property_ref, + ECMA_PROPERTY_GET_VALUE | ECMA_PROPERTY_GET_EXT_REFERENCE); + + if (!ECMA_PROPERTY_IS_FOUND (current_prop)) + { + JERRY_ASSERT (current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND + || current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + + /* 3. */ + if (!ecma_op_ordinary_object_is_extensible (object_p)) + { + /* 2. */ + return ECMA_REJECT_WITH_FORMAT (property_desc_p->flags & JERRY_PROP_SHOULD_THROW, + "Cannot define property '%', object is not extensible", + ecma_make_prop_name_value (property_name_p)); + } + + /* 4. */ + uint8_t prop_attributes = (uint8_t) (property_desc_p->flags & ECMA_PROPERTY_FLAGS_MASK); + + if (property_desc_type != ECMA_OP_OBJECT_DEFINE_ACCESSOR) + { + /* a. */ + JERRY_ASSERT (property_desc_type == ECMA_OP_OBJECT_DEFINE_GENERIC + || property_desc_type == ECMA_OP_OBJECT_DEFINE_DATA); + + ecma_property_value_t *new_prop_value_p = + ecma_create_named_data_property (object_p, property_name_p, prop_attributes, NULL); + + JERRY_ASSERT ((property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + || ecma_is_value_undefined (property_desc_p->value)); + + new_prop_value_p->value = ecma_copy_value_if_not_object (property_desc_p->value); + } + else + { + /* b. */ + ecma_create_named_accessor_property (object_p, + property_name_p, + property_desc_p->get_p, + property_desc_p->set_p, + prop_attributes, + NULL); + } + + return ECMA_VALUE_TRUE; + } + + /* 6. */ + const bool is_current_configurable = ecma_is_property_configurable (current_prop); + + /* 7. a., b. */ + bool is_enumerable = (property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE) != 0; + if (!is_current_configurable + && ((property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE) + || ((property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + && (is_enumerable != ecma_is_property_enumerable (current_prop))))) + { + if (ECMA_PROPERTY_IS_VIRTUAL (current_prop)) + { + ecma_free_value (ext_property_ref.property_ref.virtual_value); + } + + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + if (ECMA_PROPERTY_IS_VIRTUAL (current_prop)) + { + bool writable_check_failed = (property_desc_p->flags & JERRY_PROP_IS_WRITABLE); + +#if JERRY_MODULE_SYSTEM + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_MODULE_NAMESPACE)) + { + if (JERRY_UNLIKELY (ext_property_ref.property_ref.virtual_value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + + if (property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) + { + writable_check_failed = ((property_desc_p->flags ^ current_prop) & JERRY_PROP_IS_WRITABLE) != 0; + } + } + else + { + JERRY_ASSERT (!is_current_configurable && !ecma_is_property_writable (current_prop)); + } +#else /* !JERRY_MODULE_SYSTEM */ + JERRY_ASSERT (!is_current_configurable && !ecma_is_property_writable (current_prop)); +#endif /* JERRY_MODULE_SYSTEM */ + + ecma_value_t result = ECMA_VALUE_TRUE; + + if (property_desc_type == ECMA_OP_OBJECT_DEFINE_ACCESSOR || writable_check_failed + || ((property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + && !ecma_op_same_value (property_desc_p->value, ext_property_ref.property_ref.virtual_value))) + { + result = ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + ecma_free_value (ext_property_ref.property_ref.virtual_value); + return result; + } + + /* 8. */ + if (property_desc_type == ECMA_OP_OBJECT_DEFINE_GENERIC) + { + /* No action required. */ + } + else if (JERRY_LIKELY (property_desc_type == (current_prop & ECMA_PROPERTY_FLAG_DATA))) + { + /* If property is configurable, there is no need for checks. */ + if (JERRY_UNLIKELY (!is_current_configurable)) + { + if (property_desc_type == ECMA_OP_OBJECT_DEFINE_DATA) + { + /* 10. a. i. & ii. */ + if (!ecma_is_property_writable (current_prop) + && ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE) + || ((property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + && !ecma_op_same_value (property_desc_p->value, ext_property_ref.property_ref.value_p->value)))) + { + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + } + else + { + /* 11. */ + + /* a. */ + ecma_property_value_t *value_p = ext_property_ref.property_ref.value_p; + + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (value_p); + jmem_cpointer_t prop_desc_getter_cp, prop_desc_setter_cp; + ECMA_SET_POINTER (prop_desc_getter_cp, property_desc_p->get_p); + ECMA_SET_POINTER (prop_desc_setter_cp, property_desc_p->set_p); + + if (((property_desc_p->flags & JERRY_PROP_IS_GET_DEFINED) && prop_desc_getter_cp != get_set_pair_p->getter_cp) + || ((property_desc_p->flags & JERRY_PROP_IS_SET_DEFINED) + && prop_desc_setter_cp != get_set_pair_p->setter_cp)) + { + /* i., ii. */ + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + } + } + } + else + { + /* 9. */ + if (!is_current_configurable) + { + /* a. */ + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + ecma_property_value_t *value_p = ext_property_ref.property_ref.value_p; + + if (property_desc_type == ECMA_OP_OBJECT_DEFINE_ACCESSOR) + { + JERRY_ASSERT (current_prop & ECMA_PROPERTY_FLAG_DATA); + ecma_free_value_if_not_object (value_p->value); + + value_p->getter_setter_pair.getter_cp = JMEM_CP_NULL; + value_p->getter_setter_pair.setter_cp = JMEM_CP_NULL; + } + else + { + JERRY_ASSERT (!(current_prop & ECMA_PROPERTY_FLAG_DATA)); + value_p->value = ECMA_VALUE_UNDEFINED; + } + + /* Update flags */ + ecma_property_t prop_flags = *(ext_property_ref.property_p); + prop_flags = (ecma_property_t) (prop_flags & ~ECMA_PROPERTY_FLAG_WRITABLE); + prop_flags ^= ECMA_PROPERTY_FLAG_DATA; + *(ext_property_ref.property_p) = prop_flags; + } + + /* 12. */ + if (property_desc_type == ECMA_OP_OBJECT_DEFINE_DATA) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW_DATA (*ext_property_ref.property_p)); + + if (property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + { + ecma_named_data_property_assign_value (object_p, ext_property_ref.property_ref.value_p, property_desc_p->value); + } + + if (property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) + { + ecma_set_property_writable_attr (ext_property_ref.property_p, (property_desc_p->flags & JERRY_PROP_IS_WRITABLE)); + } + } + else if (property_desc_type == ECMA_OP_OBJECT_DEFINE_ACCESSOR) + { + JERRY_ASSERT (!(*ext_property_ref.property_p & ECMA_PROPERTY_FLAG_DATA)); + + if (property_desc_p->flags & JERRY_PROP_IS_GET_DEFINED) + { + ecma_set_named_accessor_property_getter (object_p, ext_property_ref.property_ref.value_p, property_desc_p->get_p); + } + + if (property_desc_p->flags & JERRY_PROP_IS_SET_DEFINED) + { + ecma_set_named_accessor_property_setter (object_p, ext_property_ref.property_ref.value_p, property_desc_p->set_p); + } + } + + if (property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + { + ecma_set_property_enumerable_attr (ext_property_ref.property_p, + (property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE)); + } + + if (property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED) + { + ecma_set_property_configurable_attr (ext_property_ref.property_p, + (property_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE)); + } + + return ECMA_VALUE_TRUE; +} /* ecma_op_general_object_define_own_property */ + +/** + * The IsCompatiblePropertyDescriptor method for Proxy object internal methods + * + * See also: + * ECMAScript v6, 9.1.6.2 + * + * @return bool + */ +bool +ecma_op_is_compatible_property_descriptor (const ecma_property_descriptor_t *desc_p, /**< target descriptor */ + const ecma_property_descriptor_t *current_p, /**< current descriptor */ + bool is_extensible) /**< true - if target object is extensible + false - otherwise */ +{ + JERRY_ASSERT (desc_p != NULL); + + /* 2. */ + if (current_p == NULL) + { + return is_extensible; + } + + /* 3. */ + if (desc_p->flags == 0) + { + return true; + } + + /* 4. */ + if ((current_p->flags & desc_p->flags) == desc_p->flags) + { + if ((current_p->flags & JERRY_PROP_IS_VALUE_DEFINED) && ecma_op_same_value (current_p->value, desc_p->value)) + { + return true; + } + + if ((current_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED) && current_p->get_p == desc_p->get_p + && current_p->set_p == desc_p->set_p)) + { + return true; + } + } + + /* 5. */ + if (!(current_p->flags & JERRY_PROP_IS_CONFIGURABLE)) + { + if (desc_p->flags & JERRY_PROP_IS_CONFIGURABLE) + { + return false; + } + if ((desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + && ((current_p->flags & JERRY_PROP_IS_ENUMERABLE) != (desc_p->flags & JERRY_PROP_IS_ENUMERABLE))) + { + return false; + } + } + + const uint32_t accessor_desc_flags = (JERRY_PROP_IS_SET_DEFINED | JERRY_PROP_IS_GET_DEFINED); + const uint32_t data_desc_flags = (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED); + + bool desc_is_accessor = (desc_p->flags & accessor_desc_flags) != 0; + bool desc_is_data = (desc_p->flags & data_desc_flags) != 0; + bool current_is_data = (current_p->flags & data_desc_flags) != 0; + + /* 6. */ + if (!desc_is_accessor && !desc_is_data) + { + return true; + } + + /* 7. */ + if (current_is_data != desc_is_data) + { + return (current_p->flags & JERRY_PROP_IS_CONFIGURABLE) != 0; + } + + /* 8. */ + if (current_is_data) + { + if (!(current_p->flags & JERRY_PROP_IS_CONFIGURABLE)) + { + if (!(current_p->flags & JERRY_PROP_IS_WRITABLE) && (desc_p->flags & JERRY_PROP_IS_WRITABLE)) + { + return false; + } + + if (!(current_p->flags & JERRY_PROP_IS_WRITABLE) && (desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + && !ecma_op_same_value (desc_p->value, current_p->value)) + { + return false; + } + } + + return true; + } + + JERRY_ASSERT ((current_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) != 0); + JERRY_ASSERT ((desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) != 0); + + /* 9. */ + if (!(current_p->flags & JERRY_PROP_IS_CONFIGURABLE)) + { + if ((desc_p->flags & JERRY_PROP_IS_SET_DEFINED) && desc_p->set_p != current_p->set_p) + { + return false; + } + + if ((desc_p->flags & JERRY_PROP_IS_GET_DEFINED) && desc_p->get_p != current_p->get_p) + { + return false; + } + } + + return true; +} /* ecma_op_is_compatible_property_descriptor */ + +/** + * CompletePropertyDescriptor method for proxy internal method + * + * See also: + * ECMA-262 v6, 6.2.4.5 + */ +void +ecma_op_to_complete_property_descriptor (ecma_property_descriptor_t *desc_p) /**< target descriptor */ +{ + /* 4. */ + if (!(desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED))) + { + /* a. */ + desc_p->flags |= JERRY_PROP_IS_VALUE_DEFINED; + } + /* 5. */ + else + { + desc_p->flags |= (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED); + } +} /* ecma_op_to_complete_property_descriptor */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects-general.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects-general.h new file mode 100644 index 0000000..210f176 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects-general.h @@ -0,0 +1,50 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_OBJECTS_GENERAL_H +#define ECMA_OBJECTS_GENERAL_H + +#include "ecma-conversion.h" +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaobjectsinternalops ECMA objects' operations + * @{ + */ + +ecma_object_t *ecma_op_create_object_object_noarg (void); +ecma_object_t *ecma_op_create_object_object_noarg_and_set_prototype (ecma_object_t *object_prototype_p); + +ecma_value_t ecma_op_general_object_delete (ecma_object_t *obj_p, ecma_string_t *property_name_p, bool is_throw); +ecma_value_t ecma_op_general_object_default_value (ecma_object_t *obj_p, ecma_preferred_type_hint_t hint); +ecma_value_t ecma_op_general_object_ordinary_value (ecma_object_t *obj_p, ecma_preferred_type_hint_t hint); +ecma_value_t ecma_op_general_object_define_own_property (ecma_object_t *object_p, + ecma_string_t *property_name_p, + const ecma_property_descriptor_t *property_desc_p); + +void ecma_op_to_complete_property_descriptor (ecma_property_descriptor_t *desc_p); + +bool ecma_op_is_compatible_property_descriptor (const ecma_property_descriptor_t *desc_p, + const ecma_property_descriptor_t *current_p, + bool is_extensible); + +/** + * @} + * @} + */ + +#endif /* !ECMA_OBJECTS_GENERAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects.cpp new file mode 100644 index 0000000..d0a9508 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects.cpp @@ -0,0 +1,3379 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-objects.h" + +#include "ecma-arguments-object.h" +#include "ecma-array-object.h" +#include "ecma-bigint.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lcache.h" +#include "ecma-lex-env.h" +#include "ecma-objects-general.h" +#include "ecma-proxy-object.h" +#include "ecma-string-object.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_TYPEDARRAY +#include "ecma-arraybuffer-object.h" +#include "ecma-typedarray-object.h" +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaobjectsinternalops ECMA objects' operations + * @{ + */ + +/** + * Hash bitmap size for ecma objects + */ +#define ECMA_OBJECT_HASH_BITMAP_SIZE 256 + +/** + * Assert that specified object type value is valid + * + * @param type object's implementation-defined type + */ +#ifndef JERRY_NDEBUG +#define JERRY_ASSERT_OBJECT_TYPE_IS_VALID(type) JERRY_ASSERT (type < ECMA_OBJECT_TYPE__MAX); +#else /* JERRY_NDEBUG */ +#define JERRY_ASSERT_OBJECT_TYPE_IS_VALID(type) +#endif /* !JERRY_NDEBUG */ + +/** + * [[GetOwnProperty]] ecma object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * @return pointer to a property - if it exists, + * NULL (i.e. ecma-undefined) - otherwise. + */ +ecma_property_t +ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + ecma_property_ref_t *property_ref_p, /**< property reference */ + uint32_t options) /**< option bits */ +{ + JERRY_ASSERT (object_p != NULL && !ecma_is_lexical_environment (object_p)); +#if JERRY_BUILTIN_PROXY + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p)); +#endif /* JERRY_BUILTIN_PROXY */ + JERRY_ASSERT (property_name_p != NULL); + JERRY_ASSERT (options == ECMA_PROPERTY_GET_NO_OPTIONS || property_ref_p != NULL); + + ecma_object_base_type_t base_type = ecma_get_object_base_type (object_p); + + switch (base_type) + { + case ECMA_OBJECT_BASE_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_STRING: + { + if (ecma_string_is_length (property_name_p)) + { + if (options & ECMA_PROPERTY_GET_VALUE) + { + ecma_value_t prim_value_p = ext_object_p->u.cls.u3.value; + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); + + lit_utf8_size_t length = ecma_string_get_length (prim_value_str_p); + property_ref_p->virtual_value = ecma_make_uint32_value (length); + } + + return ECMA_PROPERTY_VIRTUAL; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index != ECMA_STRING_NOT_ARRAY_INDEX) + { + ecma_value_t prim_value_p = ext_object_p->u.cls.u3.value; + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); + + if (index < ecma_string_get_length (prim_value_str_p)) + { + if (options & ECMA_PROPERTY_GET_VALUE) + { + ecma_char_t char_at_idx = ecma_string_get_char_at_pos (prim_value_str_p, index); + ecma_string_t *char_str_p = ecma_new_ecma_string_from_code_unit (char_at_idx); + property_ref_p->virtual_value = ecma_make_string_value (char_str_p); + } + + return ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_VIRTUAL; + } + } + break; + } +#if JERRY_BUILTIN_TYPEDARRAY + /* ES2015 9.4.5.1 */ + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + if (ecma_prop_name_is_symbol (property_name_p)) + { + break; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) + { + JERRY_ASSERT (index == UINT32_MAX); + + if (!ecma_typedarray_is_element_index (property_name_p)) + { + break; + } + } + + ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); + ecma_value_t value = ecma_get_typedarray_element (&info, index); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW; + } + + if (JERRY_UNLIKELY (ecma_is_value_undefined (value))) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP; + } + + if (options & ECMA_PROPERTY_GET_VALUE) + { + property_ref_p->virtual_value = value; + } + else + { + ecma_fast_free_value (value); + } + + return ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROPERTY_VIRTUAL; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE_NAMESPACE: + { + if (JERRY_UNLIKELY (ecma_prop_name_is_symbol (property_name_p))) + { + if (!ecma_op_compare_string_to_global_symbol (property_name_p, LIT_GLOBAL_SYMBOL_TO_STRING_TAG)) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP; + } + + /* ECMA-262 v11, 26.3.1 */ + if (options & ECMA_PROPERTY_GET_VALUE) + { + property_ref_p->virtual_value = ecma_make_magic_string_value (LIT_MAGIC_STRING_MODULE_UL); + } + + return ECMA_PROPERTY_VIRTUAL; + } + + ecma_property_t *property_p = ecma_find_named_property (object_p, property_name_p); + + if (property_p == NULL) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP; + } + + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + if (*property_p & ECMA_PROPERTY_FLAG_DATA) + { + if (options & ECMA_PROPERTY_GET_EXT_REFERENCE) + { + ((ecma_extended_property_ref_t *) property_ref_p)->property_p = property_p; + } + + if (property_ref_p != NULL) + { + property_ref_p->value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + } + + return *property_p; + } + + if (options & ECMA_PROPERTY_GET_VALUE) + { + ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + prop_value_p = ecma_get_property_value_from_named_reference (prop_value_p); + property_ref_p->virtual_value = ecma_fast_copy_value (prop_value_p->value); + } + + return ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROPERTY_VIRTUAL; + } +#endif /* JERRY_MODULE_SYSTEM */ + } + break; + } + case ECMA_OBJECT_BASE_TYPE_ARRAY: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ecma_string_is_length (property_name_p)) + { + if (options & ECMA_PROPERTY_GET_VALUE) + { + property_ref_p->virtual_value = ecma_make_uint32_value (ext_object_p->u.array.length); + } + + uint32_t length_prop = ext_object_p->u.array.length_prop_and_hole_count; + return length_prop & (ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROPERTY_VIRTUAL); + } + + if (ecma_op_array_is_fast_array (ext_object_p)) + { + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index != ECMA_STRING_NOT_ARRAY_INDEX) + { + if (JERRY_LIKELY (index < ext_object_p->u.array.length)) + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + if (ecma_is_value_array_hole (values_p[index])) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND; + } + + if (options & ECMA_PROPERTY_GET_VALUE) + { + property_ref_p->virtual_value = ecma_fast_copy_value (values_p[index]); + } + + return ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | ECMA_PROPERTY_VIRTUAL; + } + } + + return ECMA_PROPERTY_TYPE_NOT_FOUND; + } + + break; + } + default: + { + break; + } + } + + ecma_property_t *property_p = ecma_find_named_property (object_p, property_name_p); + ecma_object_type_t type = ecma_get_object_type (object_p); + + if (property_p == NULL) + { + switch (type) + { + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + if (ecma_builtin_function_is_routine (object_p)) + { + property_p = ecma_builtin_routine_try_to_instantiate_property (object_p, property_name_p); + break; + } + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + property_p = ecma_builtin_try_to_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_CLASS: + { + if (((ecma_extended_object_t *) object_p)->u.cls.type == ECMA_OBJECT_CLASS_ARGUMENTS) + { + property_p = ecma_op_arguments_object_try_to_lazy_instantiate_property (object_p, property_name_p); + } + break; + } + case ECMA_OBJECT_TYPE_FUNCTION: + { + /* Get prototype physical property. */ + property_p = ecma_op_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + property_p = ecma_op_external_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + property_p = ecma_op_bound_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + default: + { + break; + } + } + + if (property_p == NULL) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND; + } + } + else if (type == ECMA_OBJECT_TYPE_CLASS + && ((ecma_extended_object_t *) object_p)->u.cls.type == ECMA_OBJECT_CLASS_ARGUMENTS + && (((ecma_extended_object_t *) object_p)->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index < ext_object_p->u.cls.u2.formal_params_number) + { + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p; + + ecma_value_t *argv_p = (ecma_value_t *) (mapped_arguments_p + 1); + + if (!ecma_is_value_empty (argv_p[index]) && argv_p[index] != ECMA_VALUE_ARGUMENT_NO_TRACK) + { +#if JERRY_LCACHE + /* Mapped arguments initialized properties MUST not be lcached */ + if (ecma_is_property_lcached (property_p)) + { + jmem_cpointer_t prop_name_cp; + + if (JERRY_UNLIKELY (ECMA_IS_DIRECT_STRING (property_name_p))) + { + prop_name_cp = (jmem_cpointer_t) ECMA_GET_DIRECT_STRING_VALUE (property_name_p); + } + else + { + ECMA_SET_NON_NULL_POINTER (prop_name_cp, property_name_p); + } + ecma_lcache_invalidate (object_p, prop_name_cp, property_p); + } +#endif /* JERRY_LCACHE */ + ecma_string_t *name_p = ecma_op_arguments_object_get_formal_parameter (mapped_arguments_p, index); + ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, mapped_arguments_p->lex_env); + + ecma_value_t binding_value = ecma_op_get_binding_value (lex_env_p, name_p, true); + + ecma_named_data_property_assign_value (object_p, ECMA_PROPERTY_VALUE_PTR (property_p), binding_value); + ecma_free_value (binding_value); + } + } + } + + if (options & ECMA_PROPERTY_GET_EXT_REFERENCE) + { + ((ecma_extended_property_ref_t *) property_ref_p)->property_p = property_p; + } + + if (property_ref_p != NULL) + { + property_ref_p->value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + } + + return *property_p; +} /* ecma_op_object_get_own_property */ + +/** + * Generic [[HasProperty]] operation + * + * See also: + * ECMAScript v6, 9.1.7.1 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE_FALSE} - whether the property is found + */ +ecma_value_t +ecma_op_object_has_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p) /**< property name */ +{ + while (true) + { +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + return ecma_proxy_object_has (object_p, property_name_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + /* 2 - 3. */ + ecma_property_t property = + ecma_op_object_get_own_property (object_p, property_name_p, NULL, ECMA_PROPERTY_GET_NO_OPTIONS); + + if (property != ECMA_PROPERTY_TYPE_NOT_FOUND) + { +#if JERRY_BUILTIN_TYPEDARRAY + if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW)) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP || ECMA_PROPERTY_IS_FOUND (property)); + + return ecma_make_boolean_value (property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + } + + jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (object_p); + + /* 7. */ + if (proto_cp == JMEM_CP_NULL) + { + return ECMA_VALUE_FALSE; + } + + object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp); + } +} /* ecma_op_object_has_property */ + +/** + * Search the value corresponding to a property name + * + * Note: search includes prototypes + * + * @return ecma value if property is found + * ECMA_VALUE_NOT_FOUND if property is not found + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_find_own (ecma_value_t base_value, /**< base value */ + ecma_object_t *object_p, /**< target object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_ASSERT (object_p != NULL && !ecma_is_lexical_environment (object_p)); + JERRY_ASSERT (property_name_p != NULL); + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p)); + + ecma_object_base_type_t base_type = ecma_get_object_base_type (object_p); + + switch (base_type) + { + case ECMA_OBJECT_BASE_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_STRING: + { + if (ecma_string_is_length (property_name_p)) + { + ecma_value_t prim_value_p = ext_object_p->u.cls.u3.value; + + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); + lit_utf8_size_t length = ecma_string_get_length (prim_value_str_p); + + return ecma_make_uint32_value (length); + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index != ECMA_STRING_NOT_ARRAY_INDEX) + { + ecma_value_t prim_value_p = ext_object_p->u.cls.u3.value; + + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); + + if (index < ecma_string_get_length (prim_value_str_p)) + { + ecma_char_t char_at_idx = ecma_string_get_char_at_pos (prim_value_str_p, index); + return ecma_make_string_value (ecma_new_ecma_string_from_code_unit (char_at_idx)); + } + } + break; + } + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + if (!(ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)) + { + break; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index < ext_object_p->u.cls.u2.formal_params_number) + { + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p; + + ecma_value_t *argv_p = (ecma_value_t *) (mapped_arguments_p + 1); + + if (!ecma_is_value_empty (argv_p[index]) && argv_p[index] != ECMA_VALUE_ARGUMENT_NO_TRACK) + { + ecma_string_t *name_p = ecma_op_arguments_object_get_formal_parameter (mapped_arguments_p, index); + ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, mapped_arguments_p->lex_env); + + return ecma_op_get_binding_value (lex_env_p, name_p, true); + } + } + break; + } +#if JERRY_BUILTIN_TYPEDARRAY + /* ES2015 9.4.5.4 */ + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + if (ecma_prop_name_is_symbol (property_name_p)) + { + break; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) + { + JERRY_ASSERT (index == UINT32_MAX); + + if (!ecma_typedarray_is_element_index (property_name_p)) + { + break; + } + } + + ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); + return ecma_get_typedarray_element (&info, index); + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE_NAMESPACE: + { + if (JERRY_UNLIKELY (ecma_prop_name_is_symbol (property_name_p))) + { + /* ECMA-262 v11, 26.3.1 */ + if (ecma_op_compare_string_to_global_symbol (property_name_p, LIT_GLOBAL_SYMBOL_TO_STRING_TAG)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_MODULE_UL); + } + + return ECMA_VALUE_NOT_FOUND; + } + + ecma_property_t *property_p = ecma_find_named_property (object_p, property_name_p); + + if (property_p == NULL) + { + return ECMA_VALUE_NOT_FOUND; + } + + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (!(*property_p & ECMA_PROPERTY_FLAG_DATA)) + { + prop_value_p = ecma_get_property_value_from_named_reference (prop_value_p); + + if (JERRY_UNLIKELY (prop_value_p->value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + } + + return ecma_fast_copy_value (prop_value_p->value); + } +#endif /* JERRY_MODULE_SYSTEM */ + } + break; + } + case ECMA_OBJECT_BASE_TYPE_ARRAY: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ecma_string_is_length (property_name_p)) + { + return ecma_make_uint32_value (ext_object_p->u.array.length); + } + + if (JERRY_LIKELY (ecma_op_array_is_fast_array (ext_object_p))) + { + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (JERRY_LIKELY (index != ECMA_STRING_NOT_ARRAY_INDEX)) + { + if (JERRY_LIKELY (index < ext_object_p->u.array.length)) + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + return (ecma_is_value_array_hole (values_p[index]) ? ECMA_VALUE_NOT_FOUND + : ecma_fast_copy_value (values_p[index])); + } + } + return ECMA_VALUE_NOT_FOUND; + } + + break; + } + default: + { + break; + } + } + + ecma_property_t *property_p = ecma_find_named_property (object_p, property_name_p); + + if (property_p == NULL) + { + switch (ecma_get_object_type (object_p)) + { + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + if (ecma_builtin_function_is_routine (object_p)) + { + property_p = ecma_builtin_routine_try_to_instantiate_property (object_p, property_name_p); + break; + } + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + property_p = ecma_builtin_try_to_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_CLASS: + { + if (((ecma_extended_object_t *) object_p)->u.cls.type == ECMA_OBJECT_CLASS_ARGUMENTS) + { + property_p = ecma_op_arguments_object_try_to_lazy_instantiate_property (object_p, property_name_p); + } + break; + } + case ECMA_OBJECT_TYPE_FUNCTION: + { + /* Get prototype physical property. */ + property_p = ecma_op_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + property_p = ecma_op_external_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + property_p = ecma_op_bound_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + default: + { + break; + } + } + + if (property_p == NULL) + { + return ECMA_VALUE_NOT_FOUND; + } + } + + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (*property_p & ECMA_PROPERTY_FLAG_DATA) + { + return ecma_fast_copy_value (prop_value_p->value); + } + + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (prop_value_p); + + if (get_set_pair_p->getter_cp == JMEM_CP_NULL) + { + return ECMA_VALUE_UNDEFINED; + } + + ecma_object_t *getter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp); + + return ecma_op_function_call (getter_p, base_value, NULL, 0); +} /* ecma_op_object_find_own */ + +/** + * Search the value corresponding to a property index + * + * Note: this method falls back to the general ecma_op_object_find + * + * @return ecma value if property is found + * ECMA_VALUE_NOT_FOUND if property is not found + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_find_by_index (ecma_object_t *object_p, /**< the object */ + ecma_length_t index) /**< property index */ +{ + if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return ecma_op_object_find (object_p, ECMA_CREATE_DIRECT_UINT32_STRING (index)); + } + + ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index); + ecma_value_t ret_value = ecma_op_object_find (object_p, index_str_p); + ecma_deref_ecma_string (index_str_p); + + return ret_value; +} /* ecma_op_object_find_by_index */ + +/** + * Search the value corresponding to a property name + * + * Note: search includes prototypes + * + * @return ecma value if property is found + * ECMA_VALUE_NOT_FOUND if property is not found + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_find (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p) /**< property name */ +{ + ecma_value_t base_value = ecma_make_object_value (object_p); + + while (true) + { +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + return ecma_proxy_object_find (object_p, property_name_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t value = ecma_op_object_find_own (base_value, object_p, property_name_p); + + if (ecma_is_value_found (value)) + { + return value; + } + + if (object_p->u2.prototype_cp == JMEM_CP_NULL) + { + break; + } + + object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, object_p->u2.prototype_cp); + } + + return ECMA_VALUE_NOT_FOUND; +} /* ecma_op_object_find */ + +/** + * [[Get]] operation of ecma object + * + * This function returns the value of a named property, or undefined + * if the property is not found in the prototype chain. If the property + * is an accessor, it calls the "get" callback function and returns + * with its result (including error throws). + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_get (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p) /**< property name */ +{ + return ecma_op_object_get_with_receiver (object_p, property_name_p, ecma_make_object_value (object_p)); +} /* ecma_op_object_get */ + +/** + * [[Get]] operation of ecma object with the specified receiver + * + * This function returns the value of a named property, or undefined + * if the property is not found in the prototype chain. If the property + * is an accessor, it calls the "get" callback function and returns + * with its result (including error throws). + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_get_with_receiver (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + ecma_value_t receiver) /**< receiver to invoke getter function */ +{ + while (true) + { +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + return ecma_proxy_object_get (object_p, property_name_p, receiver); + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t value = ecma_op_object_find_own (receiver, object_p, property_name_p); + + if (ecma_is_value_found (value)) + { + return value; + } + + jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (object_p); + + if (proto_cp == JMEM_CP_NULL) + { + break; + } + + object_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp); + } + + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_object_get_with_receiver */ + +/** + * [[Get]] operation of ecma object specified for property index + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_get_by_index (ecma_object_t *object_p, /**< the object */ + ecma_length_t index) /**< property index */ +{ + if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return ecma_op_object_get (object_p, ECMA_CREATE_DIRECT_UINT32_STRING (index)); + } + + ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index); + ecma_value_t ret_value = ecma_op_object_get (object_p, index_str_p); + ecma_deref_ecma_string (index_str_p); + + return ret_value; +} /* ecma_op_object_get_by_index */ + +/** + * Perform ToLength(O.[[Get]]("length")) operation + * + * The property is converted to uint32 during the operation + * + * @return ECMA_VALUE_ERROR - if there was any error during the operation + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +ecma_op_object_get_length (ecma_object_t *object_p, /**< the object */ + ecma_length_t *length_p) /**< [out] length value converted to uint32 */ +{ + if (JERRY_LIKELY (ecma_get_object_base_type (object_p) == ECMA_OBJECT_BASE_TYPE_ARRAY)) + { + *length_p = (ecma_length_t) ecma_array_get_length (object_p); + return ECMA_VALUE_EMPTY; + } + + ecma_value_t len_value = ecma_op_object_get_by_magic_id (object_p, LIT_MAGIC_STRING_LENGTH); + ecma_value_t len_number = ecma_op_to_length (len_value, length_p); + ecma_free_value (len_value); + + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (len_number) || ecma_is_value_empty (len_number)); + + return len_number; +} /* ecma_op_object_get_length */ + +/** + * [[Get]] operation of ecma object where the property name is a magic string + * + * This function returns the value of a named property, or undefined + * if the property is not found in the prototype chain. If the property + * is an accessor, it calls the "get" callback function and returns + * with its result (including error throws). + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_get_by_magic_id (ecma_object_t *object_p, /**< the object */ + lit_magic_string_id_t property_id) /**< property magic string id */ +{ + return ecma_op_object_get (object_p, ecma_get_magic_string (property_id)); +} /* ecma_op_object_get_by_magic_id */ + +/** + * Descriptor string for each global symbol + */ +static const uint16_t ecma_global_symbol_descriptions[] = { + LIT_MAGIC_STRING_ASYNC_ITERATOR, LIT_MAGIC_STRING_HAS_INSTANCE, LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE, + LIT_MAGIC_STRING_ITERATOR, LIT_MAGIC_STRING_MATCH, LIT_MAGIC_STRING_REPLACE, + LIT_MAGIC_STRING_SEARCH, LIT_MAGIC_STRING_SPECIES, LIT_MAGIC_STRING_SPLIT, + LIT_MAGIC_STRING_TO_PRIMITIVE, LIT_MAGIC_STRING_TO_STRING_TAG, LIT_MAGIC_STRING_UNSCOPABLES, + LIT_MAGIC_STRING_MATCH_ALL, +}; + +JERRY_STATIC_ASSERT ((sizeof (ecma_global_symbol_descriptions) / sizeof (uint16_t) == ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT), + ecma_global_symbol_descriptions_must_have_global_symbol_count_elements); + +/** + * [[Get]] a well-known symbol by the given property id + * + * @return pointer to the requested well-known symbol + */ +ecma_string_t * +ecma_op_get_global_symbol (lit_magic_string_id_t property_id) /**< property symbol id */ +{ + JERRY_ASSERT (LIT_IS_GLOBAL_SYMBOL (property_id)); + + uint32_t symbol_index = (uint32_t) property_id - (uint32_t) LIT_GLOBAL_SYMBOL__FIRST; + jmem_cpointer_t symbol_cp = JERRY_CONTEXT (global_symbols_cp)[symbol_index]; + + if (symbol_cp != JMEM_CP_NULL) + { + ecma_string_t *symbol_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, symbol_cp); + ecma_ref_ecma_string (symbol_p); + return symbol_p; + } + + ecma_string_t *symbol_dot_p = ecma_get_magic_string (LIT_MAGIC_STRING_SYMBOL_DOT_UL); + uint16_t description = ecma_global_symbol_descriptions[symbol_index]; + ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) description); + ecma_string_t *descriptor_p = ecma_concat_ecma_strings (symbol_dot_p, name_p); + + ecma_string_t *symbol_p = ecma_new_symbol_from_descriptor_string (ecma_make_string_value (descriptor_p)); + symbol_p->u.hash = (uint16_t) ((property_id << ECMA_SYMBOL_FLAGS_SHIFT) | ECMA_SYMBOL_FLAG_GLOBAL); + + ECMA_SET_NON_NULL_POINTER (JERRY_CONTEXT (global_symbols_cp)[symbol_index], symbol_p); + + ecma_ref_ecma_string (symbol_p); + return symbol_p; +} /* ecma_op_get_global_symbol */ + +/** + * Checks whether the string equals to the global symbol. + * + * @return true - if the string equals to the global symbol + * false - otherwise + */ +bool +ecma_op_compare_string_to_global_symbol (ecma_string_t *string_p, /**< string to compare */ + lit_magic_string_id_t property_id) /**< property symbol id */ +{ + JERRY_ASSERT (LIT_IS_GLOBAL_SYMBOL (property_id)); + + uint32_t symbol_index = (uint32_t) property_id - (uint32_t) LIT_GLOBAL_SYMBOL__FIRST; + jmem_cpointer_t symbol_cp = JERRY_CONTEXT (global_symbols_cp)[symbol_index]; + + return (symbol_cp != JMEM_CP_NULL && string_p == ECMA_GET_NON_NULL_POINTER (ecma_string_t, symbol_cp)); +} /* ecma_op_compare_string_to_global_symbol */ + +/** + * [[Get]] operation of ecma object where the property is a well-known symbol + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_get_by_symbol_id (ecma_object_t *object_p, /**< the object */ + lit_magic_string_id_t property_id) /**< property symbol id */ +{ + ecma_string_t *symbol_p = ecma_op_get_global_symbol (property_id); + ecma_value_t ret_value = ecma_op_object_get (object_p, symbol_p); + ecma_deref_ecma_string (symbol_p); + + return ret_value; +} /* ecma_op_object_get_by_symbol_id */ + +/** + * GetMethod operation + * + * See also: ECMA-262 v6, 7.3.9 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator function object - if success + * raised error - otherwise + */ +static ecma_value_t +ecma_op_get_method (ecma_value_t value, /**< ecma value */ + ecma_string_t *prop_name_p) /**< property name */ +{ + /* 2. */ + ecma_value_t obj_value = ecma_op_to_object (value); + + if (ECMA_IS_VALUE_ERROR (obj_value)) + { + return obj_value; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (obj_value); + ecma_value_t func; + + func = ecma_op_object_get (obj_p, prop_name_p); + ecma_deref_object (obj_p); + + /* 3. */ + if (ECMA_IS_VALUE_ERROR (func)) + { + return func; + } + + /* 4. */ + if (ecma_is_value_undefined (func) || ecma_is_value_null (func)) + { + return ECMA_VALUE_UNDEFINED; + } + + /* 5. */ + if (!ecma_op_is_callable (func)) + { + ecma_free_value (func); + return ecma_raise_type_error (ECMA_ERR_ITERATOR_IS_NOT_CALLABLE); + } + + /* 6. */ + return func; +} /* ecma_op_get_method */ + +/** + * GetMethod operation when the property is a well-known symbol + * + * See also: ECMA-262 v6, 7.3.9 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator function object - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_get_method_by_symbol_id (ecma_value_t value, /**< ecma value */ + lit_magic_string_id_t symbol_id) /**< property symbol id */ +{ + ecma_string_t *prop_name_p = ecma_op_get_global_symbol (symbol_id); + ecma_value_t ret_value = ecma_op_get_method (value, prop_name_p); + ecma_deref_ecma_string (prop_name_p); + + return ret_value; +} /* ecma_op_get_method_by_symbol_id */ + +/** + * GetMethod operation when the property is a magic string + * + * See also: ECMA-262 v6, 7.3.9 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator function object - if success + * raised error - otherwise + */ +ecma_value_t +ecma_op_get_method_by_magic_id (ecma_value_t value, /**< ecma value */ + lit_magic_string_id_t magic_id) /**< property magic id */ +{ + return ecma_op_get_method (value, ecma_get_magic_string (magic_id)); +} /* ecma_op_get_method_by_magic_id */ + +/** + * [[Put]] ecma general object's operation specialized for property index + * + * Note: This function falls back to the general ecma_op_object_put + * + * @return ecma value + * The returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_object_put_by_index (ecma_object_t *object_p, /**< the object */ + ecma_length_t index, /**< property index */ + ecma_value_t value, /**< ecma value */ + bool is_throw) /**< flag that controls failure handling */ +{ + if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return ecma_op_object_put (object_p, ECMA_CREATE_DIRECT_UINT32_STRING (index), value, is_throw); + } + + ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index); + ecma_value_t ret_value = ecma_op_object_put (object_p, index_str_p, value, is_throw); + ecma_deref_ecma_string (index_str_p); + + return ret_value; +} /* ecma_op_object_put_by_index */ + +/** + * [[Put]] ecma general object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 8.12.5 + * Also incorporates [[CanPut]] ECMA-262 v5, 8.12.4 + * + * @return ecma value + * The returned value must be freed with ecma_free_value. + * + * Returns with ECMA_VALUE_TRUE if the operation is + * successful. Otherwise it returns with an error object + * or ECMA_VALUE_FALSE. + * + * Note: even if is_throw is false, the setter can throw an + * error, and this function returns with that error. + */ +ecma_value_t +ecma_op_object_put (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + ecma_value_t value, /**< ecma value */ + bool is_throw) /**< flag that controls failure handling */ +{ + return ecma_op_object_put_with_receiver (object_p, + property_name_p, + value, + ecma_make_object_value (object_p), + is_throw); +} /* ecma_op_object_put */ + +/** + * [[Set]] ( P, V, Receiver) operation part for ordinary objects + * + * See also: ECMAScript v6, 9.19.9 + * + * @return ecma value + * The returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_op_object_put_apply_receiver (ecma_value_t receiver, /**< receiver */ + ecma_string_t *property_name_p, /**< property name */ + ecma_value_t value, /**< value to set */ + bool is_throw) /**< flag that controls failure handling */ +{ + /* 5.b */ + if (!ecma_is_value_object (receiver)) + { + return ECMA_REJECT (is_throw, ECMA_ERR_RECEIVER_MUST_BE_AN_OBJECT); + } + + ecma_object_t *receiver_obj_p = ecma_get_object_from_value (receiver); + + ecma_property_descriptor_t prop_desc; + /* 5.c */ + ecma_value_t status = ecma_op_object_get_own_property_descriptor (receiver_obj_p, property_name_p, &prop_desc); + + /* 5.d */ + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + /* 5.e */ + if (ecma_is_value_true (status)) + { + ecma_value_t result; + + /* 5.e.i - 5.e.ii */ + if (prop_desc.flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED) + || !(prop_desc.flags & JERRY_PROP_IS_WRITABLE)) + { + result = ecma_raise_property_redefinition (property_name_p, prop_desc.flags); + } + else + { + /* 5.e.iii */ + JERRY_ASSERT (prop_desc.flags & JERRY_PROP_IS_VALUE_DEFINED); + ecma_free_value (prop_desc.value); + prop_desc.value = ecma_copy_value (value); + + /* 5.e.iv */ + result = ecma_op_object_define_own_property (receiver_obj_p, property_name_p, &prop_desc); + + if (JERRY_UNLIKELY (ecma_is_value_false (result))) + { + result = ECMA_REJECT (is_throw, ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH); + } + } + + ecma_free_property_descriptor (&prop_desc); + + return result; + } + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (receiver_obj_p)) + { + ecma_property_descriptor_t desc; + /* Based on: ES6 9.1.9 [[Set]] 4.d.i. / ES11 9.1.9.2 OrdinarySetWithOwnDescriptor 2.c.i. */ + desc.flags = (JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE + | JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_WRITABLE | JERRY_PROP_IS_WRITABLE_DEFINED + | JERRY_PROP_IS_VALUE_DEFINED); + desc.value = value; + ecma_value_t ret_value = ecma_proxy_object_define_own_property (receiver_obj_p, property_name_p, &desc); + + if (JERRY_UNLIKELY (ecma_is_value_false (ret_value))) + { + ret_value = ECMA_REJECT (is_throw, ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH); + } + + return ret_value; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (JERRY_UNLIKELY (ecma_op_object_is_fast_array (receiver_obj_p))) + { + ecma_fast_array_convert_to_normal (receiver_obj_p); + } + + /* 5.f.i */ + ecma_property_value_t *new_prop_value_p; + new_prop_value_p = ecma_create_named_data_property (receiver_obj_p, + property_name_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + JERRY_ASSERT (ecma_is_value_undefined (new_prop_value_p->value)); + new_prop_value_p->value = ecma_copy_value_if_not_object (value); + + return ECMA_VALUE_TRUE; +} /* ecma_op_object_put_apply_receiver */ + +/** + * [[Put]] ecma general object's operation with given receiver + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * ECMA-262 v5, 8.12.5 + * ECMA-262 v6, 9.1.9 + * Also incorporates [[CanPut]] ECMA-262 v5, 8.12.4 + * + * @return ecma value + * The returned value must be freed with ecma_free_value. + * + * Returns with ECMA_VALUE_TRUE if the operation is + * successful. Otherwise it returns with an error object + * or ECMA_VALUE_FALSE. + * + * Note: even if is_throw is false, the setter can throw an + * error, and this function returns with that error. + */ +ecma_value_t +ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + ecma_value_t value, /**< ecma value */ + ecma_value_t receiver, /**< receiver */ + bool is_throw) /**< flag that controls failure handling */ +{ + JERRY_ASSERT (object_p != NULL && !ecma_is_lexical_environment (object_p)); + JERRY_ASSERT (property_name_p != NULL); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + return ecma_proxy_object_set (object_p, property_name_p, value, receiver, is_throw); + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_object_base_type_t base_type = ecma_get_object_base_type (object_p); + + switch (base_type) + { + case ECMA_OBJECT_BASE_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + if (!(ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED)) + { + break; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index < ext_object_p->u.cls.u2.formal_params_number) + { + ecma_mapped_arguments_t *mapped_arguments_p = (ecma_mapped_arguments_t *) ext_object_p; + + ecma_value_t *argv_p = (ecma_value_t *) (mapped_arguments_p + 1); + + if (!ecma_is_value_empty (argv_p[index]) && argv_p[index] != ECMA_VALUE_ARGUMENT_NO_TRACK) + { + ecma_string_t *name_p = ecma_op_arguments_object_get_formal_parameter (mapped_arguments_p, index); + ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, mapped_arguments_p->lex_env); + ecma_op_set_mutable_binding (lex_env_p, name_p, value, true); + return ECMA_VALUE_TRUE; + } + } + break; + } +#if JERRY_BUILTIN_TYPEDARRAY + /* ES2015 9.4.5.5 */ + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + if (ecma_prop_name_is_symbol (property_name_p)) + { + break; + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) + { + JERRY_ASSERT (index == UINT32_MAX); + + if (!ecma_typedarray_is_element_index (property_name_p)) + { + break; + } + } + + ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); + return ecma_set_typedarray_element (&info, value, index); + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + case ECMA_OBJECT_CLASS_MODULE_NAMESPACE: + { + return ecma_raise_readonly_assignment (property_name_p, is_throw); + } +#endif /* JERRY_MODULE_SYSTEM */ + } + break; + } + case ECMA_OBJECT_BASE_TYPE_ARRAY: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ecma_string_is_length (property_name_p)) + { + if (ecma_is_property_writable ((ecma_property_t) ext_object_p->u.array.length_prop_and_hole_count)) + { + return ecma_op_array_object_set_length (object_p, value, 0); + } + + return ecma_raise_readonly_assignment (property_name_p, is_throw); + } + + if (JERRY_LIKELY (ecma_op_array_is_fast_array (ext_object_p))) + { + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (JERRY_UNLIKELY (index == ECMA_STRING_NOT_ARRAY_INDEX)) + { + ecma_fast_array_convert_to_normal (object_p); + } + else if (ecma_fast_array_set_property (object_p, index, value)) + { + return ECMA_VALUE_TRUE; + } + } + + JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p)); + break; + } + default: + { + break; + } + } + + ecma_property_t *property_p = ecma_find_named_property (object_p, property_name_p); + + if (property_p == NULL) + { + switch (ecma_get_object_type (object_p)) + { + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + if (ecma_builtin_function_is_routine (object_p)) + { + property_p = ecma_builtin_routine_try_to_instantiate_property (object_p, property_name_p); + break; + } + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + property_p = ecma_builtin_try_to_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_STRING: + { + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index != ECMA_STRING_NOT_ARRAY_INDEX) + { + ecma_value_t prim_value_p = ext_object_p->u.cls.u3.value; + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); + + if (index < ecma_string_get_length (prim_value_str_p)) + { + return ecma_raise_readonly_assignment (property_name_p, is_throw); + } + } + break; + } + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + property_p = ecma_op_arguments_object_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + } + break; + } + case ECMA_OBJECT_TYPE_FUNCTION: + { + if (ecma_string_is_length (property_name_p)) + { + /* Uninitialized 'length' property is non-writable (ECMA-262 v6, 19.2.4.1) */ + if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (((ecma_extended_object_t *) object_p)->u.function.scope_cp)) + { + return ecma_raise_readonly_assignment (property_name_p, is_throw); + } + } + + /* Get prototype physical property. */ + property_p = ecma_op_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + property_p = ecma_op_external_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + property_p = ecma_op_bound_function_try_to_lazy_instantiate_property (object_p, property_name_p); + break; + } + default: + { + break; + } + } + } + + jmem_cpointer_t setter_cp = JMEM_CP_NULL; + + if (property_p != NULL) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + if (*property_p & ECMA_PROPERTY_FLAG_DATA) + { + if (ecma_is_property_writable (*property_p)) + { + if (ecma_make_object_value (object_p) != receiver) + { + return ecma_op_object_put_apply_receiver (receiver, property_name_p, value, is_throw); + } + + /* There is no need for special casing arrays here because changing the + * value of an existing property never changes the length of an array. */ + ecma_named_data_property_assign_value (object_p, ECMA_PROPERTY_VALUE_PTR (property_p), value); + return ECMA_VALUE_TRUE; + } + } + else + { + ecma_getter_setter_pointers_t *get_set_pair_p; + get_set_pair_p = ecma_get_named_accessor_property (ECMA_PROPERTY_VALUE_PTR (property_p)); + setter_cp = get_set_pair_p->setter_cp; + } + } + else + { + bool create_new_property = true; + + jmem_cpointer_t obj_cp; + ECMA_SET_NON_NULL_POINTER (obj_cp, object_p); + ecma_object_t *proto_p = object_p; + + while (true) + { + obj_cp = ecma_op_ordinary_object_get_prototype_of (proto_p); + + if (obj_cp == JMEM_CP_NULL) + { + break; + } + + ecma_property_ref_t property_ref = { NULL }; + proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_cp); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (proto_p)) + { + return ecma_op_object_put_with_receiver (proto_p, property_name_p, value, receiver, is_throw); + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_property_t inherited_property = + ecma_op_object_get_own_property (proto_p, property_name_p, &property_ref, ECMA_PROPERTY_GET_NO_OPTIONS); + + if (ECMA_PROPERTY_IS_FOUND (inherited_property)) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (inherited_property)); + + if (!(inherited_property & ECMA_PROPERTY_FLAG_DATA)) + { + setter_cp = ecma_get_named_accessor_property (property_ref.value_p)->setter_cp; + create_new_property = false; + break; + } + + create_new_property = ecma_is_property_writable (inherited_property); + break; + } + + JERRY_ASSERT (inherited_property == ECMA_PROPERTY_TYPE_NOT_FOUND + || inherited_property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + } + +#if JERRY_BUILTIN_PROXY + if (create_new_property && ecma_is_value_object (receiver) + && ECMA_OBJECT_IS_PROXY (ecma_get_object_from_value (receiver))) + { + return ecma_op_object_put_apply_receiver (receiver, property_name_p, value, is_throw); + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (create_new_property && ecma_op_ordinary_object_is_extensible (object_p)) + { + const ecma_object_base_type_t obj_base_type = ecma_get_object_base_type (object_p); + + if (obj_base_type == ECMA_OBJECT_BASE_TYPE_CLASS) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_ARGUMENTS + && ext_object_p->u.cls.u1.arguments_flags & ECMA_ARGUMENTS_OBJECT_MAPPED) + { + const uint32_t flags = ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE | JERRY_PROP_SHOULD_THROW; + return ecma_builtin_helper_def_prop (object_p, property_name_p, value, flags); + } + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (obj_base_type == ECMA_OBJECT_BASE_TYPE_ARRAY && index != ECMA_STRING_NOT_ARRAY_INDEX) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (index < UINT32_MAX && index >= ext_object_p->u.array.length) + { + if (!ecma_is_property_writable ((ecma_property_t) ext_object_p->u.array.length_prop_and_hole_count)) + { + return ecma_raise_readonly_assignment (property_name_p, is_throw); + } + + ext_object_p->u.array.length = index + 1; + } + } + + return ecma_op_object_put_apply_receiver (receiver, property_name_p, value, is_throw); + + ecma_property_value_t *new_prop_value_p; + new_prop_value_p = ecma_create_named_data_property (object_p, + property_name_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + + JERRY_ASSERT (ecma_is_value_undefined (new_prop_value_p->value)); + new_prop_value_p->value = ecma_copy_value_if_not_object (value); + return ECMA_VALUE_TRUE; + } + } + + if (setter_cp == JMEM_CP_NULL) + { + return ecma_raise_readonly_assignment (property_name_p, is_throw); + } + + ecma_value_t ret_value = + ecma_op_function_call (ECMA_GET_NON_NULL_POINTER (ecma_object_t, setter_cp), receiver, &value, 1); + + if (!ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_fast_free_value (ret_value); + ret_value = ECMA_VALUE_TRUE; + } + + return ret_value; +} /* ecma_op_object_put_with_receiver */ + +/** + * [[Delete]] ecma object's operation specialized for property index + * + * Note: + * This method falls back to the general ecma_op_object_delete + * + * @return true - if deleted successfully + * false - or type error otherwise (based in 'is_throw') + */ +ecma_value_t +ecma_op_object_delete_by_index (ecma_object_t *obj_p, /**< the object */ + ecma_length_t index, /**< property index */ + bool is_throw) /**< flag that controls failure handling */ +{ + if (JERRY_LIKELY (index <= ECMA_DIRECT_STRING_MAX_IMM)) + { + return ecma_op_object_delete (obj_p, ECMA_CREATE_DIRECT_UINT32_STRING (index), is_throw); + ; + } + + ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index); + ecma_value_t ret_value = ecma_op_object_delete (obj_p, index_str_p, is_throw); + ecma_deref_ecma_string (index_str_p); + + return ret_value; +} /* ecma_op_object_delete_by_index */ + +/** + * [[Delete]] ecma object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * Note: + * returned value must be freed with ecma_free_value + * + * @return true - if deleted successfully + * false - or type error otherwise (based in 'is_throw') + */ +ecma_value_t +ecma_op_object_delete (ecma_object_t *obj_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + bool is_strict) /**< flag that controls failure handling */ +{ + JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); + JERRY_ASSERT (property_name_p != NULL); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + return ecma_proxy_object_delete_property (obj_p, property_name_p, is_strict); + } +#endif /* JERRY_BUILTIN_PROXY */ + + JERRY_ASSERT_OBJECT_TYPE_IS_VALID (ecma_get_object_type (obj_p)); + + return ecma_op_general_object_delete (obj_p, property_name_p, is_strict); +} /* ecma_op_object_delete */ + +/** + * [[DefaultValue]] ecma object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_default_value (ecma_object_t *obj_p, /**< the object */ + ecma_preferred_type_hint_t hint) /**< hint on preferred result type */ +{ + JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); + + JERRY_ASSERT_OBJECT_TYPE_IS_VALID (ecma_get_object_type (obj_p)); + + /* + * typedef ecma_property_t * (*default_value_ptr_t) (ecma_object_t *, ecma_string_t *); + * static const default_value_ptr_t default_value [ECMA_OBJECT_TYPE__COUNT] = + * { + * [ECMA_OBJECT_TYPE_GENERAL] = &ecma_op_general_object_default_value, + * [ECMA_OBJECT_TYPE_CLASS] = &ecma_op_general_object_default_value, + * [ECMA_OBJECT_TYPE_FUNCTION] = &ecma_op_general_object_default_value, + * [ECMA_OBJECT_TYPE_NATIVE_FUNCTION] = &ecma_op_general_object_default_value, + * [ECMA_OBJECT_TYPE_ARRAY] = &ecma_op_general_object_default_value, + * [ECMA_OBJECT_TYPE_BOUND_FUNCTION] = &ecma_op_general_object_default_value, + * [ECMA_OBJECT_TYPE_PSEUDO_ARRAY] = &ecma_op_general_object_default_value + * }; + * + * return default_value[type] (obj_p, property_name_p); + */ + + return ecma_op_general_object_default_value (obj_p, hint); +} /* ecma_op_object_default_value */ + +/** + * [[DefineOwnProperty]] ecma object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + const ecma_property_descriptor_t *property_desc_p) /**< property + * descriptor */ +{ + JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); + JERRY_ASSERT (property_name_p != NULL); + + const ecma_object_type_t type = ecma_get_object_type (obj_p); + + switch (type) + { + case ECMA_OBJECT_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + return ecma_op_arguments_object_define_own_property (obj_p, property_name_p, property_desc_p); + } +#if JERRY_BUILTIN_TYPEDARRAY + /* ES2015 9.4.5.1 */ + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + return ecma_op_typedarray_define_own_property (obj_p, property_name_p, property_desc_p); + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + } + break; + } + case ECMA_OBJECT_TYPE_ARRAY: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + return ecma_op_array_object_define_own_property (obj_p, property_name_p, property_desc_p); + } +#if JERRY_BUILTIN_PROXY + case ECMA_OBJECT_TYPE_PROXY: + { + return ecma_proxy_object_define_own_property (obj_p, property_name_p, property_desc_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + default: + { + break; + } + } + + return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p); +} /* ecma_op_object_define_own_property */ + +/** + * Get property descriptor from specified property + * + * depending on the property type the following fields are set: + * - for named data properties: { [Value], [Writable], [Enumerable], [Configurable] }; + * - for named accessor properties: { [Get] - if defined, + * [Set] - if defined, + * [Enumerable], [Configurable] + * }. + * + * The output property descriptor will always be initialized to an empty descriptor. + * + * @return ECMA_VALUE_ERROR - if the Proxy.[[GetOwnProperty]] operation raises error + * ECMA_VALUE_{TRUE, FALSE} - if property found or not + */ +ecma_value_t +ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p, /**< property name */ + ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */ +{ + *prop_desc_p = ecma_make_empty_property_descriptor (); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + return ecma_proxy_object_get_own_property_descriptor (object_p, property_name_p, prop_desc_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_property_ref_t property_ref; + property_ref.virtual_value = ECMA_VALUE_EMPTY; + ecma_property_t property = + ecma_op_object_get_own_property (object_p, property_name_p, &property_ref, ECMA_PROPERTY_GET_VALUE); + + if (!ECMA_PROPERTY_IS_FOUND (property)) + { +#if JERRY_BUILTIN_TYPEDARRAY + if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW)) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + + return ECMA_VALUE_FALSE; + } + + uint32_t flags = ecma_is_property_enumerable (property) ? JERRY_PROP_IS_ENUMERABLE : JERRY_PROP_NO_OPTS; + flags |= ecma_is_property_configurable (property) ? JERRY_PROP_IS_CONFIGURABLE : JERRY_PROP_NO_OPTS; + + prop_desc_p->flags = (uint16_t) (JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE_DEFINED | flags); + + if (property & ECMA_PROPERTY_FLAG_DATA) + { + if (!ECMA_PROPERTY_IS_VIRTUAL (property)) + { + prop_desc_p->value = ecma_copy_value (property_ref.value_p->value); + } + else + { +#if JERRY_MODULE_SYSTEM + if (JERRY_UNLIKELY (property_ref.virtual_value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } +#endif /* JERRY_MODULE_SYSTEM */ + prop_desc_p->value = property_ref.virtual_value; + } + + prop_desc_p->flags |= + (uint16_t) (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED + | (ecma_is_property_writable (property) ? JERRY_PROP_IS_WRITABLE : JERRY_PROP_NO_OPTS)); + } + else + { + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (property_ref.value_p); + prop_desc_p->flags |= (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED); + + if (get_set_pair_p->getter_cp == JMEM_CP_NULL) + { + prop_desc_p->get_p = NULL; + } + else + { + prop_desc_p->get_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp); + ecma_ref_object (prop_desc_p->get_p); + } + + if (get_set_pair_p->setter_cp == JMEM_CP_NULL) + { + prop_desc_p->set_p = NULL; + } + else + { + prop_desc_p->set_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->setter_cp); + ecma_ref_object (prop_desc_p->set_p); + } + } + + return ECMA_VALUE_TRUE; +} /* ecma_op_object_get_own_property_descriptor */ + +#if JERRY_BUILTIN_PROXY +/** + * Get property descriptor from a target value for a specified property. + * + * For more details see ecma_op_object_get_own_property_descriptor + * + * @return ECMA_VALUE_ERROR - if the Proxy.[[GetOwnProperty]] operation raises error + * ECMA_VALUE_{TRUE, FALSE} - if property found or not + */ +ecma_value_t +ecma_op_get_own_property_descriptor (ecma_value_t target, /**< target value */ + ecma_string_t *property_name_p, /**< property name */ + ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */ +{ + if (!ecma_is_value_object (target)) + { + return ECMA_VALUE_FALSE; + } + + return ecma_op_object_get_own_property_descriptor (ecma_get_object_from_value (target), property_name_p, prop_desc_p); +} /* ecma_op_get_own_property_descriptor */ +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * [[HasInstance]] ecma object's operation + * + * See also: + * ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 9 + * + * @return ecma value containing a boolean value or an error + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_object_has_instance (ecma_object_t *obj_p, /**< the object */ + ecma_value_t value) /**< argument 'V' */ +{ + JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p)); + + JERRY_ASSERT_OBJECT_TYPE_IS_VALID (ecma_get_object_type (obj_p)); + + if (ecma_op_object_is_callable (obj_p)) + { + return ecma_op_function_has_instance (obj_p, value); + } + + return ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION_OBJECT); +} /* ecma_op_object_has_instance */ + +/** + * General [[GetPrototypeOf]] abstract operation + * + * Note: returned valid object must be freed. + * + * @return ecma_object_t * - prototype of the input object. + * ECMA_OBJECT_POINTER_ERROR - error reported during Proxy resolve. + * NULL - the input object does not have a prototype. + */ +ecma_object_t * +ecma_op_object_get_prototype_of (ecma_object_t *obj_p) /**< input object */ +{ + JERRY_ASSERT (obj_p != NULL); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + ecma_value_t proto = ecma_proxy_object_get_prototype_of (obj_p); + + if (ECMA_IS_VALUE_ERROR (proto)) + { + return ECMA_OBJECT_POINTER_ERROR; + } + if (ecma_is_value_null (proto)) + { + return NULL; + } + + JERRY_ASSERT (ecma_is_value_object (proto)); + + return ecma_get_object_from_value (proto); + } + else +#endif /* JERRY_BUILTIN_PROXY */ + { + jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (obj_p); + + if (proto_cp == JMEM_CP_NULL) + { + return NULL; + } + + ecma_object_t *proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp); + ecma_ref_object (proto_p); + + return proto_p; + } +} /* ecma_op_object_get_prototype_of */ + +/** + * Object's isPrototypeOf operation + * + * See also: + * ECMA-262 v5, 15.2.4.6; 3 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_TRUE - if the target object is prototype of the base object + * ECMA_VALUE_FALSE - if the target object is not prototype of the base object + */ +ecma_value_t +ecma_op_object_is_prototype_of (ecma_object_t *base_p, /**< base object */ + ecma_object_t *target_p) /**< target object */ +{ + ecma_ref_object (target_p); + + do + { + ecma_object_t *proto_p = ecma_op_object_get_prototype_of (target_p); + ecma_deref_object (target_p); + + if (proto_p == NULL) + { + return ECMA_VALUE_FALSE; + } + else if (proto_p == ECMA_OBJECT_POINTER_ERROR) + { + return ECMA_VALUE_ERROR; + } + else if (proto_p == base_p) + { + ecma_deref_object (proto_p); + return ECMA_VALUE_TRUE; + } + + /* Advance up on prototype chain. */ + target_p = proto_p; + } while (true); +} /* ecma_op_object_is_prototype_of */ + +/** + * Object's EnumerableOwnPropertyNames operation + * + * See also: + * ECMA-262 v11, 7.3.23 + * + * @return NULL - if operation fails + * collection of property names / values / name-value pairs - otherwise + */ +ecma_collection_t * +ecma_op_object_get_enumerable_property_names (ecma_object_t *obj_p, /**< routine's first argument */ + ecma_enumerable_property_names_options_t option) /**< listing option */ +{ + /* 2. */ + ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (obj_p, JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS); + +#if JERRY_BUILTIN_PROXY + if (JERRY_UNLIKELY (prop_names_p == NULL)) + { + return prop_names_p; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t *names_buffer_p = prop_names_p->buffer_p; + /* 3. */ + ecma_collection_t *properties_p = ecma_new_collection (); + + /* 4. */ + for (uint32_t i = 0; i < prop_names_p->item_count; i++) + { + /* 4.a */ + if (ecma_is_value_string (names_buffer_p[i])) + { + ecma_string_t *key_p = ecma_get_string_from_value (names_buffer_p[i]); + + /* 4.a.i */ + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_op_object_get_own_property_descriptor (obj_p, key_p, &prop_desc); + + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_collection_free (prop_names_p); + ecma_collection_free (properties_p); + + return NULL; + } + + const bool is_enumerable = (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE) != 0; + ecma_free_property_descriptor (&prop_desc); + /* 4.a.ii */ + if (is_enumerable) + { + /* 4.a.ii.1 */ + if (option == ECMA_ENUMERABLE_PROPERTY_KEYS) + { + ecma_collection_push_back (properties_p, ecma_copy_value (names_buffer_p[i])); + } + else + { + /* 4.a.ii.2.a */ + ecma_value_t value = ecma_op_object_get (obj_p, key_p); + + if (ECMA_IS_VALUE_ERROR (value)) + { + ecma_collection_free (prop_names_p); + ecma_collection_free (properties_p); + + return NULL; + } + + /* 4.a.ii.2.b */ + if (option == ECMA_ENUMERABLE_PROPERTY_VALUES) + { + ecma_collection_push_back (properties_p, value); + } + else + { + /* 4.a.ii.2.c.i */ + JERRY_ASSERT (option == ECMA_ENUMERABLE_PROPERTY_ENTRIES); + + /* 4.a.ii.2.c.ii */ + ecma_object_t *entry_p = ecma_op_new_array_object (2); + + ecma_builtin_helper_def_prop_by_index (entry_p, + 0, + names_buffer_p[i], + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_builtin_helper_def_prop_by_index (entry_p, 1, value, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_free_value (value); + + /* 4.a.ii.2.c.iii */ + ecma_collection_push_back (properties_p, ecma_make_object_value (entry_p)); + } + } + } + } + } + + ecma_collection_free (prop_names_p); + + return properties_p; +} /* ecma_op_object_get_enumerable_property_names */ + +/** + * Helper method for getting lazy instantiated properties for [[OwnPropertyKeys]] + */ +static void +ecma_object_list_lazy_property_names (ecma_object_t *obj_p, /**< object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + switch (ecma_get_object_type (obj_p)) + { + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + if (ecma_builtin_function_is_routine (obj_p)) + { + ecma_builtin_routine_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } + /* FALLTHRU */ + } + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + ecma_builtin_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } + case ECMA_OBJECT_TYPE_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + switch (ext_object_p->u.cls.type) + { + case ECMA_OBJECT_CLASS_STRING: + { + ecma_op_string_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } + case ECMA_OBJECT_CLASS_ARGUMENTS: + { + ecma_op_arguments_object_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } +#if JERRY_BUILTIN_TYPEDARRAY + /* ES2015 9.4.5.1 */ + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + ecma_op_typedarray_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + } + break; + } + case ECMA_OBJECT_TYPE_FUNCTION: + { + ecma_op_function_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + { + ecma_op_external_function_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + { + ecma_op_bound_function_list_lazy_property_names (obj_p, prop_names_p, prop_counter_p, filter); + break; + } + case ECMA_OBJECT_TYPE_ARRAY: + { + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS)) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } + break; + } + default: + { + JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_GENERAL + || ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION); + break; + } + } +} /* ecma_object_list_lazy_property_names */ + +/** + * Helper routine for heapsort algorithm. + */ +static void +ecma_op_object_heap_sort_shift_down (ecma_value_t *buffer_p, /**< array of items */ + uint32_t item_count, /**< number of items */ + uint32_t item_index) /**< index of updated item */ +{ + while (true) + { + uint32_t highest_index = item_index; + uint32_t current_index = (item_index << 1) + 1; + + if (current_index >= item_count) + { + return; + } + + uint32_t value = ecma_string_get_array_index (ecma_get_string_from_value (buffer_p[highest_index])); + uint32_t left_value = ecma_string_get_array_index (ecma_get_string_from_value (buffer_p[current_index])); + + if (value < left_value) + { + highest_index = current_index; + value = left_value; + } + + current_index++; + + if (current_index < item_count + && value < ecma_string_get_array_index (ecma_get_string_from_value (buffer_p[current_index]))) + { + highest_index = current_index; + } + + if (highest_index == item_index) + { + return; + } + + ecma_value_t tmp = buffer_p[highest_index]; + buffer_p[highest_index] = buffer_p[item_index]; + buffer_p[item_index] = tmp; + + item_index = highest_index; + } +} /* ecma_op_object_heap_sort_shift_down */ + +/** + * Object's [[OwnPropertyKeys]] internal method + * + * Order of names in the collection: + * - integer indices in ascending order + * - other indices in creation order (for built-ins: the order of the properties are listed in specification). + * + * Note: + * Implementation of the routine assumes that new properties are appended to beginning of corresponding object's + * property list, and the list is not reordered (in other words, properties are stored in order that is reversed + * to the properties' addition order). + * + * @return NULL - if the Proxy.[[OwnPropertyKeys]] operation raises error + * collection of property names - otherwise + */ +ecma_collection_t * +ecma_op_object_own_property_keys (ecma_object_t *obj_p, /**< object */ + jerry_property_filter_t filter) /**< name filters */ +{ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (obj_p)) + { + return ecma_proxy_object_own_property_keys (obj_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_op_object_is_fast_array (obj_p)) + { + return ecma_fast_array_object_own_property_keys (obj_p, filter); + } + + ecma_collection_t *prop_names_p = ecma_new_collection (); + ecma_property_counter_t prop_counter = { 0, 0, 0 }; + + ecma_object_list_lazy_property_names (obj_p, prop_names_p, &prop_counter, filter); + + jmem_cpointer_t prop_iter_cp = obj_p->u1.property_list_cp; + +#if JERRY_PROPERTY_HASHMAP + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prop_iter_cp = prop_iter_p->next_property_cp; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + jmem_cpointer_t counter_prop_iter_cp = prop_iter_cp; + + uint32_t array_index_named_props = 0; + uint32_t string_named_props = 0; + uint32_t symbol_named_props = 0; + + while (counter_prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, counter_prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + ecma_property_t *property_p = prop_iter_p->types + i; + + if (!ECMA_PROPERTY_IS_RAW (*property_p) || (*property_p & ECMA_PROPERTY_FLAG_BUILT_IN)) + { + continue; + } + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC + && prop_pair_p->names_cp[i] >= LIT_NON_INTERNAL_MAGIC_STRING__COUNT + && prop_pair_p->names_cp[i] < LIT_MAGIC_STRING__COUNT) + { + continue; + } + + ecma_string_t *name_p = ecma_string_from_property_name (*property_p, prop_pair_p->names_cp[i]); + + if (ecma_string_get_array_index (name_p) != ECMA_STRING_NOT_ARRAY_INDEX) + { + array_index_named_props++; + } + else if (ecma_prop_name_is_symbol (name_p)) + { + if (!(name_p->u.hash & ECMA_SYMBOL_FLAG_PRIVATE_KEY)) + { + symbol_named_props++; + } + } + else + { + string_named_props++; + } + + ecma_deref_ecma_string (name_p); + } + + counter_prop_iter_cp = prop_iter_p->next_property_cp; + } + + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES) + { + JERRY_ASSERT (prop_counter.array_index_named_props == 0); + array_index_named_props = 0; + } + + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS) + { + JERRY_ASSERT (prop_counter.string_named_props == 0); + string_named_props = 0; + } + + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS) + { + JERRY_ASSERT (prop_counter.symbol_named_props == 0); + symbol_named_props = 0; + } + + uint32_t total = array_index_named_props + string_named_props + symbol_named_props; + + if (total == 0) + { + return prop_names_p; + } + + ecma_collection_reserve (prop_names_p, total); + prop_names_p->item_count += total; + + ecma_value_t *buffer_p = prop_names_p->buffer_p; + ecma_value_t *array_index_current_p = buffer_p + array_index_named_props + prop_counter.array_index_named_props; + ecma_value_t *string_current_p = array_index_current_p + string_named_props + prop_counter.string_named_props; + + ecma_value_t *symbol_current_p = string_current_p + symbol_named_props + prop_counter.symbol_named_props; + + if (prop_counter.symbol_named_props > 0 && (array_index_named_props + string_named_props) > 0) + { + memmove ((void *) string_current_p, + (void *) (buffer_p + prop_counter.array_index_named_props + prop_counter.string_named_props), + prop_counter.symbol_named_props * sizeof (ecma_value_t)); + } + + if (prop_counter.string_named_props > 0 && array_index_named_props > 0) + { + memmove ((void *) array_index_current_p, + (void *) (buffer_p + prop_counter.array_index_named_props), + prop_counter.string_named_props * sizeof (ecma_value_t)); + } + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) + { + ecma_property_t *property_p = prop_iter_p->types + i; + + if (!ECMA_PROPERTY_IS_RAW (*property_p) || (*property_p & ECMA_PROPERTY_FLAG_BUILT_IN)) + { + continue; + } + + ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p; + + if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC + && prop_pair_p->names_cp[i] >= LIT_NON_INTERNAL_MAGIC_STRING__COUNT + && prop_pair_p->names_cp[i] < LIT_MAGIC_STRING__COUNT) + { + continue; + } + + ecma_string_t *name_p = ecma_string_from_property_name (*property_p, prop_pair_p->names_cp[i]); + + if (ecma_string_get_array_index (name_p) != ECMA_STRING_NOT_ARRAY_INDEX) + { + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES)) + { + *(--array_index_current_p) = ecma_make_string_value (name_p); + continue; + } + } + else if (ecma_prop_name_is_symbol (name_p)) + { + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS) && !(name_p->u.hash & ECMA_SYMBOL_FLAG_PRIVATE_KEY)) + { + *(--symbol_current_p) = ecma_make_symbol_value (name_p); + continue; + } + } + else + { + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS)) + { + *(--string_current_p) = ecma_make_string_value (name_p); + continue; + } + } + + ecma_deref_ecma_string (name_p); + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } + + if (array_index_named_props > 1 || (array_index_named_props == 1 && prop_counter.array_index_named_props > 0)) + { + uint32_t prev_value = 0; + ecma_value_t *array_index_p = buffer_p + prop_counter.array_index_named_props; + ecma_value_t *array_index_end_p = array_index_p + array_index_named_props; + + if (prop_counter.array_index_named_props > 0) + { + prev_value = ecma_string_get_array_index (ecma_get_string_from_value (array_index_p[-1])); + } + + do + { + uint32_t value = ecma_string_get_array_index (ecma_get_string_from_value (*array_index_p++)); + + if (value < prev_value) + { + uint32_t array_props = prop_counter.array_index_named_props + array_index_named_props; + uint32_t i = (array_props >> 1) - 1; + + do + { + ecma_op_object_heap_sort_shift_down (buffer_p, array_props, i); + } while (i-- > 0); + + i = array_props - 1; + + do + { + ecma_value_t tmp = buffer_p[i]; + buffer_p[i] = buffer_p[0]; + buffer_p[0] = tmp; + + ecma_op_object_heap_sort_shift_down (buffer_p, i, 0); + } while (--i > 0); + + break; + } + + prev_value = value; + } while (array_index_p < array_index_end_p); + } + + return prop_names_p; +} /* ecma_op_object_own_property_keys */ + +/** + * EnumerateObjectProperties abstract method + * + * See also: + * ECMA-262 v11, 13.7.5.15 + * + * @return NULL - if the Proxy.[[OwnPropertyKeys]] operation raises error + * collection of enumerable property names - otherwise + */ +ecma_collection_t * +ecma_op_object_enumerate (ecma_object_t *obj_p) /**< object */ +{ + ecma_collection_t *visited_names_p = ecma_new_collection (); + ecma_collection_t *return_names_p = ecma_new_collection (); + + ecma_ref_object (obj_p); + + while (true) + { + ecma_collection_t *keys = ecma_op_object_own_property_keys (obj_p, JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS); + + if (JERRY_UNLIKELY (keys == NULL)) + { + ecma_collection_free (return_names_p); + ecma_collection_free (visited_names_p); + ecma_deref_object (obj_p); + return keys; + } + + for (uint32_t i = 0; i < keys->item_count; i++) + { + ecma_value_t prop_name = keys->buffer_p[i]; + ecma_string_t *name_p = ecma_get_prop_name_from_value (prop_name); + + if (ecma_prop_name_is_symbol (name_p)) + { + continue; + } + + ecma_property_descriptor_t prop_desc; + ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (obj_p, name_p, &prop_desc); + + if (ECMA_IS_VALUE_ERROR (get_desc)) + { + ecma_collection_free (keys); + ecma_collection_free (return_names_p); + ecma_collection_free (visited_names_p); + ecma_deref_object (obj_p); + return NULL; + } + + if (ecma_is_value_true (get_desc)) + { + bool is_enumerable = (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE) != 0; + ecma_free_property_descriptor (&prop_desc); + + if (ecma_collection_has_string_value (visited_names_p, name_p) + || ecma_collection_has_string_value (return_names_p, name_p)) + { + continue; + } + + ecma_ref_ecma_string (name_p); + + if (is_enumerable) + { + ecma_collection_push_back (return_names_p, prop_name); + } + else + { + ecma_collection_push_back (visited_names_p, prop_name); + } + } + } + + ecma_collection_free (keys); + + /* Query the prototype. */ + ecma_object_t *proto_p = ecma_op_object_get_prototype_of (obj_p); + ecma_deref_object (obj_p); + + if (proto_p == NULL) + { + break; + } + else if (JERRY_UNLIKELY (proto_p == ECMA_OBJECT_POINTER_ERROR)) + { + ecma_collection_free (return_names_p); + ecma_collection_free (visited_names_p); + return NULL; + } + + /* Advance up on prototype chain. */ + obj_p = proto_p; + } + + ecma_collection_free (visited_names_p); + + return return_names_p; +} /* ecma_op_object_enumerate */ + +#ifndef JERRY_NDEBUG + +/** + * Check if passed object is the instance of specified built-in. + * + * @return true - if the object is instance of the specified built-in + * false - otherwise + */ +static bool +ecma_builtin_is (ecma_object_t *object_p, /**< pointer to an object */ + ecma_builtin_id_t builtin_id) /**< id of built-in to check on */ +{ + JERRY_ASSERT (object_p != NULL && !ecma_is_lexical_environment (object_p)); + JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT); + + ecma_object_type_t type = ecma_get_object_type (object_p); + + switch (type) + { + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + { + ecma_extended_object_t *built_in_object_p = (ecma_extended_object_t *) object_p; + + return (built_in_object_p->u.built_in.id == builtin_id && built_in_object_p->u.built_in.routine_id == 0); + } + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + ecma_extended_built_in_object_t *extended_built_in_object_p = (ecma_extended_built_in_object_t *) object_p; + + return (extended_built_in_object_p->built_in.id == builtin_id + && extended_built_in_object_p->built_in.routine_id == 0); + } + default: + { + return false; + } + } +} /* ecma_builtin_is */ + +#endif /* !JERRY_NDEBUG */ + +/** + * Used by ecma_object_get_class_name to get the magic string id of class objects + */ +static const uint16_t ecma_class_object_magic_string_id[] = { + /* These objects require custom property resolving. */ + LIT_MAGIC_STRING_STRING_UL, /**< magic string id of ECMA_OBJECT_CLASS_STRING */ + LIT_MAGIC_STRING_ARGUMENTS_UL, /**< magic string id of ECMA_OBJECT_CLASS_ARGUMENTS */ +#if JERRY_BUILTIN_TYPEDARRAY + LIT_MAGIC_STRING__EMPTY, /**< ECMA_OBJECT_CLASS_TYPEDARRAY needs special resolver */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_MODULE_SYSTEM + LIT_MAGIC_STRING_MODULE_UL, /**< magic string id of ECMA_OBJECT_CLASS_MODULE_NAMESPACE */ +#endif /* JERRY_MODULE_SYSTEM */ + + /* These objects are marked by Garbage Collector. */ + LIT_MAGIC_STRING_GENERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_GENERATOR */ + LIT_MAGIC_STRING_ASYNC_GENERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_ASYNC_GENERATOR */ + LIT_MAGIC_STRING_ARRAY_ITERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_ARRAY_ITERATOR */ + LIT_MAGIC_STRING_SET_ITERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_SET_ITERATOR */ + LIT_MAGIC_STRING_MAP_ITERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_MAP_ITERATOR */ +#if JERRY_BUILTIN_REGEXP + LIT_MAGIC_STRING_REGEXP_STRING_ITERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_REGEXP_STRING_ITERATOR */ +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_MODULE_SYSTEM + LIT_MAGIC_STRING_MODULE_UL, /**< magic string id of ECMA_OBJECT_CLASS_MODULE */ +#endif /* JERRY_MODULE_SYSTEM */ + LIT_MAGIC_STRING_PROMISE_UL, /**< magic string id of ECMA_OBJECT_CLASS_PROMISE */ + LIT_MAGIC_STRING_OBJECT_UL, /**< magic string id of ECMA_OBJECT_CLASS_PROMISE_CAPABILITY */ + LIT_MAGIC_STRING_OBJECT_UL, /**< magic string id of ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR */ +#if JERRY_BUILTIN_DATAVIEW + LIT_MAGIC_STRING_DATAVIEW_UL, /**< magic string id of ECMA_OBJECT_CLASS_DATAVIEW */ +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_CONTAINER + LIT_MAGIC_STRING__EMPTY, /**< magic string id of ECMA_OBJECT_CLASS_CONTAINER needs special resolver */ +#endif /* JERRY_BUILTIN_CONTAINER */ + + /* Normal objects. */ + LIT_MAGIC_STRING_BOOLEAN_UL, /**< magic string id of ECMA_OBJECT_CLASS_BOOLEAN */ + LIT_MAGIC_STRING_NUMBER_UL, /**< magic string id of ECMA_OBJECT_CLASS_NUMBER */ + LIT_MAGIC_STRING_ERROR_UL, /**< magic string id of ECMA_OBJECT_CLASS_ERROR */ + LIT_MAGIC_STRING_OBJECT_UL, /**< magic string id of ECMA_OBJECT_CLASS_INTERNAL_OBJECT */ +#if JERRY_PARSER + LIT_MAGIC_STRING_SCRIPT_UL, /**< magic string id of ECMA_OBJECT_CLASS_SCRIPT */ +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_DATE + LIT_MAGIC_STRING_DATE_UL, /**< magic string id of ECMA_OBJECT_CLASS_DATE */ +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_REGEXP + LIT_MAGIC_STRING_REGEXP_UL, /**< magic string id of ECMA_OBJECT_CLASS_REGEXP */ +#endif /* JERRY_BUILTIN_REGEXP */ + LIT_MAGIC_STRING_SYMBOL_UL, /**< magic string id of ECMA_OBJECT_CLASS_SYMBOL */ + LIT_MAGIC_STRING_STRING_ITERATOR_UL, /**< magic string id of ECMA_OBJECT_CLASS_STRING_ITERATOR */ +#if JERRY_BUILTIN_TYPEDARRAY + LIT_MAGIC_STRING_ARRAY_BUFFER_UL, /**< magic string id of ECMA_OBJECT_CLASS_ARRAY_BUFFER */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, /**< magic string id of ECMA_OBJECT_CLASS_SHAREDARRAY_BUFFER */ +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +#if JERRY_BUILTIN_BIGINT + LIT_MAGIC_STRING_BIGINT_UL, /**< magic string id of ECMA_OBJECT_CLASS_BIGINT */ +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_WEAKREF + LIT_MAGIC_STRING_WEAKREF_UL, /**< magic string id of ECMA_OBJECT_CLASS_WEAKREF */ +#endif /* JERRY_BUILTIN_WEAKREF */ +}; + +JERRY_STATIC_ASSERT ((sizeof (ecma_class_object_magic_string_id) == ECMA_OBJECT_CLASS__MAX * sizeof (uint16_t)), + ecma_class_object_magic_string_id_must_have_object_class_max_elements); + +/** + * Get [[Class]] string of specified object + * + * @return class name magic string + */ +lit_magic_string_id_t +ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */ +{ + ecma_object_type_t type = ecma_get_object_type (obj_p); + + switch (type) + { + case ECMA_OBJECT_TYPE_ARRAY: + case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY: + { + return LIT_MAGIC_STRING_ARRAY_UL; + } + case ECMA_OBJECT_TYPE_CLASS: + case ECMA_OBJECT_TYPE_BUILT_IN_CLASS: + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + switch (ext_object_p->u.cls.type) + { +#if JERRY_BUILTIN_TYPEDARRAY + case ECMA_OBJECT_CLASS_TYPEDARRAY: + { + return ecma_get_typedarray_magic_string_id ((ecma_typedarray_type_t) ext_object_p->u.cls.u1.typedarray_type); + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_CONTAINER + case ECMA_OBJECT_CLASS_CONTAINER: + { + return (lit_magic_string_id_t) ext_object_p->u.cls.u2.container_id; + } +#endif /* JERRY_BUILTIN_CONTAINER */ + default: + { + break; + } + } + + JERRY_ASSERT (ext_object_p->u.cls.type < ECMA_OBJECT_CLASS__MAX); + JERRY_ASSERT (ecma_class_object_magic_string_id[ext_object_p->u.cls.type] != LIT_MAGIC_STRING__EMPTY); + + return (lit_magic_string_id_t) ecma_class_object_magic_string_id[ext_object_p->u.cls.type]; + } + case ECMA_OBJECT_TYPE_FUNCTION: + case ECMA_OBJECT_TYPE_NATIVE_FUNCTION: + case ECMA_OBJECT_TYPE_BOUND_FUNCTION: + case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: + case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION: + { + return LIT_MAGIC_STRING_FUNCTION_UL; + } +#if JERRY_BUILTIN_PROXY + case ECMA_OBJECT_TYPE_PROXY: + { + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + if (!ecma_is_value_null (proxy_obj_p->target) && ecma_is_value_object (proxy_obj_p->target)) + { + ecma_object_t *target_obj_p = ecma_get_object_from_value (proxy_obj_p->target); + return ecma_object_get_class_name (target_obj_p); + } + return LIT_MAGIC_STRING_OBJECT_UL; + } +#endif /* JERRY_BUILTIN_PROXY */ + case ECMA_OBJECT_TYPE_BUILT_IN_GENERAL: + { + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + + switch (ext_obj_p->u.built_in.id) + { +#if JERRY_BUILTIN_MATH + case ECMA_BUILTIN_ID_MATH: + { + return LIT_MAGIC_STRING_MATH_UL; + } +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_REFLECT + case ECMA_BUILTIN_ID_REFLECT: + { + return LIT_MAGIC_STRING_REFLECT_UL; + } +#endif /* JERRY_BUILTIN_REFLECT */ + case ECMA_BUILTIN_ID_GENERATOR: + { + return LIT_MAGIC_STRING_GENERATOR_UL; + } + case ECMA_BUILTIN_ID_ASYNC_GENERATOR: + { + return LIT_MAGIC_STRING_ASYNC_GENERATOR_UL; + } +#if JERRY_BUILTIN_ATOMICS + case ECMA_BUILTIN_ID_ATOMICS: + { + return LIT_MAGIC_STRING_ATOMICS_U; + } +#endif /* JERRY_BUILTIN_ATOMICS */ + default: + { + break; + } + } + + return LIT_MAGIC_STRING_OBJECT_UL; + } + default: + { + JERRY_ASSERT (type == ECMA_OBJECT_TYPE_GENERAL || type == ECMA_OBJECT_TYPE_PROXY); + + return LIT_MAGIC_STRING_OBJECT_UL; + } + } +} /* ecma_object_get_class_name */ + +#if JERRY_BUILTIN_REGEXP +/** + * Checks if the given argument has [[RegExpMatcher]] internal slot + * + * @return true - if the given argument is a regexp + * false - otherwise + */ +bool +ecma_object_is_regexp_object (ecma_value_t arg) /**< argument */ +{ + return (ecma_is_value_object (arg) + && ecma_object_class_is (ecma_get_object_from_value (arg), ECMA_OBJECT_CLASS_REGEXP)); +} /* ecma_object_is_regexp_object */ +#endif /* JERRY_BUILTIN_REGEXP */ + +/** + * Object's IsConcatSpreadable operation, used for Array.prototype.concat + * It checks the argument's [Symbol.isConcatSpreadable] property value + * + * See also: + * ECMA-262 v6, 22.1.3.1.1; + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_TRUE - if the argument is concatSpreadable + * ECMA_VALUE_FALSE - otherwise + */ +ecma_value_t +ecma_op_is_concat_spreadable (ecma_value_t arg) /**< argument */ +{ + if (!ecma_is_value_object (arg)) + { + return ECMA_VALUE_FALSE; + } + + ecma_value_t spreadable = + ecma_op_object_get_by_symbol_id (ecma_get_object_from_value (arg), LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE); + + if (ECMA_IS_VALUE_ERROR (spreadable)) + { + return spreadable; + } + + if (!ecma_is_value_undefined (spreadable)) + { + const bool to_bool = ecma_op_to_boolean (spreadable); + ecma_free_value (spreadable); + return ecma_make_boolean_value (to_bool); + } + + return ecma_is_value_array (arg); +} /* ecma_op_is_concat_spreadable */ + +/** + * IsRegExp operation + * + * See also: + * ECMA-262 v6, 22.1.3.1.1; + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_TRUE - if the argument is regexp + * ECMA_VALUE_FALSE - otherwise + */ +ecma_value_t +ecma_op_is_regexp (ecma_value_t arg) /**< argument */ +{ +#if JERRY_BUILTIN_REGEXP + if (!ecma_is_value_object (arg)) + { + return ECMA_VALUE_FALSE; + } + + ecma_value_t is_regexp = ecma_op_object_get_by_symbol_id (ecma_get_object_from_value (arg), LIT_GLOBAL_SYMBOL_MATCH); + + if (ECMA_IS_VALUE_ERROR (is_regexp)) + { + return is_regexp; + } + + if (!ecma_is_value_undefined (is_regexp)) + { + const bool to_bool = ecma_op_to_boolean (is_regexp); + ecma_free_value (is_regexp); + return ecma_make_boolean_value (to_bool); + } + + return ecma_make_boolean_value (ecma_object_is_regexp_object (arg)); +#else + return ECMA_VALUE_FALSE; +#endif +} /* ecma_op_is_regexp */ + +/** + * SpeciesConstructor operation + * See also: + * ECMA-262 v6, 7.3.20; + * + * @return ecma_value + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_species_constructor (ecma_object_t *this_value, /**< This Value */ + ecma_builtin_id_t default_constructor_id) /**< Builtin ID of default constructor */ +{ + ecma_object_t *default_constructor_p = ecma_builtin_get (default_constructor_id); + ecma_value_t constructor = ecma_op_object_get_by_magic_id (this_value, LIT_MAGIC_STRING_CONSTRUCTOR); + if (ECMA_IS_VALUE_ERROR (constructor)) + { + return constructor; + } + + if (ecma_is_value_undefined (constructor)) + { + ecma_ref_object (default_constructor_p); + return ecma_make_object_value (default_constructor_p); + } + + if (!ecma_is_value_object (constructor)) + { + ecma_free_value (constructor); + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTOR_NOT_AN_OBJECT); + } + + ecma_object_t *ctor_object_p = ecma_get_object_from_value (constructor); + ecma_value_t species = ecma_op_object_get_by_symbol_id (ctor_object_p, LIT_GLOBAL_SYMBOL_SPECIES); + ecma_deref_object (ctor_object_p); + + if (ECMA_IS_VALUE_ERROR (species)) + { + return species; + } + + if (ecma_is_value_undefined (species) || ecma_is_value_null (species)) + { + ecma_ref_object (default_constructor_p); + return ecma_make_object_value (default_constructor_p); + } + + if (!ecma_is_constructor (species)) + { + ecma_free_value (species); + return ecma_raise_type_error (ECMA_ERR_SPECIES_MUST_BE_A_CONSTRUCTOR); + } + + return species; +} /* ecma_op_species_constructor */ + +/** + * 7.3.18 Abstract operation Invoke when property name is a magic string + * + * @return ecma_value result of the invoked function or raised error + * note: returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_invoke_by_symbol_id (ecma_value_t object, /**< Object value */ + lit_magic_string_id_t symbol_id, /**< Symbol ID */ + ecma_value_t *args_p, /**< Argument list */ + uint32_t args_len) /**< Argument list length */ +{ + ecma_string_t *symbol_p = ecma_op_get_global_symbol (symbol_id); + ecma_value_t ret_value = ecma_op_invoke (object, symbol_p, args_p, args_len); + ecma_deref_ecma_string (symbol_p); + + return ret_value; +} /* ecma_op_invoke_by_symbol_id */ + +/** + * 7.3.18 Abstract operation Invoke when property name is a magic string + * + * @return ecma_value result of the invoked function or raised error + * note: returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_invoke_by_magic_id (ecma_value_t object, /**< Object value */ + lit_magic_string_id_t magic_string_id, /**< Magic string ID */ + ecma_value_t *args_p, /**< Argument list */ + uint32_t args_len) /**< Argument list length */ +{ + return ecma_op_invoke (object, ecma_get_magic_string (magic_string_id), args_p, args_len); +} /* ecma_op_invoke_by_magic_id */ + +/** + * 7.3.18 Abstract operation Invoke + * + * @return ecma_value result of the invoked function or raised error + * note: returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_invoke (ecma_value_t object, /**< Object value */ + ecma_string_t *property_name_p, /**< Property name */ + ecma_value_t *args_p, /**< Argument list */ + uint32_t args_len) /**< Argument list length */ +{ + /* 3. */ + ecma_value_t object_value = ecma_op_to_object (object); + if (ECMA_IS_VALUE_ERROR (object_value)) + { + return object_value; + } + + ecma_object_t *object_p = ecma_get_object_from_value (object_value); + + ecma_value_t func = ecma_op_object_get_with_receiver (object_p, property_name_p, object); + + if (ECMA_IS_VALUE_ERROR (func)) + { + ecma_deref_object (object_p); + return func; + } + + /* 4. */ + ecma_value_t call_result = ecma_op_function_validated_call (func, object, args_p, args_len); + ecma_free_value (func); + + ecma_deref_object (object_p); + + return call_result; +} /* ecma_op_invoke */ + +/** + * Ordinary object [[GetPrototypeOf]] operation + * + * See also: + * ECMAScript v6, 9.1.1 + * + * @return the value of the [[Prototype]] internal slot of the given object. + */ +jmem_cpointer_t +ecma_op_ordinary_object_get_prototype_of (ecma_object_t *obj_p) /**< object */ +{ + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (obj_p)); + + return obj_p->u2.prototype_cp; +} /* ecma_op_ordinary_object_get_prototype_of */ + +/** + * Ordinary object [[SetPrototypeOf]] operation + * + * See also: + * ECMAScript v6, 9.1.2 + * + * @return ECMA_VALUE_FALSE - if the operation fails + * ECMA_VALUE_TRUE - otherwise + */ +ecma_value_t +ecma_op_ordinary_object_set_prototype_of (ecma_object_t *obj_p, /**< base object */ + ecma_value_t proto) /**< prototype object */ +{ + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (obj_p)); + + /* 1. */ + JERRY_ASSERT (ecma_is_value_object (proto) || ecma_is_value_null (proto)); + + /* 3. */ + ecma_object_t *current_proto_p = ECMA_GET_POINTER (ecma_object_t, ecma_op_ordinary_object_get_prototype_of (obj_p)); + ecma_object_t *new_proto_p = ecma_is_value_null (proto) ? NULL : ecma_get_object_from_value (proto); + + /* 4. */ + if (new_proto_p == current_proto_p) + { + return ECMA_VALUE_TRUE; + } + + /* 2 - 5. */ + if (!ecma_op_ordinary_object_is_extensible (obj_p)) + { + return ECMA_VALUE_FALSE; + } + + /** + * When the prototype of a fast array changes, it is required to convert the + * array to a "normal" array. This ensures that all [[Get]]/[[Set]]/etc. + * calls works as expected. + */ + if (ecma_op_object_is_fast_array (obj_p)) + { + ecma_fast_array_convert_to_normal (obj_p); + } + + /* 6. */ + ecma_object_t *iter_p = new_proto_p; + + /* 7 - 8. */ + while (true) + { + /* 8.a */ + if (iter_p == NULL) + { + break; + } + + /* 8.b */ + if (obj_p == iter_p) + { + return ECMA_VALUE_FALSE; + } + + /* 8.c.i */ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (iter_p)) + { + /** + * Prevent setting 'Object.prototype.__proto__' + * to avoid circular referencing in the prototype chain. + */ + if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE)) + { + return ECMA_VALUE_FALSE; + } + + break; + } +#endif /* JERRY_BUILTIN_PROXY */ + + /* 8.c.ii */ + iter_p = ECMA_GET_POINTER (ecma_object_t, ecma_op_ordinary_object_get_prototype_of (iter_p)); + } + + /* 9. */ + ECMA_SET_POINTER (obj_p->u2.prototype_cp, new_proto_p); + + /* 10. */ + return ECMA_VALUE_TRUE; +} /* ecma_op_ordinary_object_set_prototype_of */ + +/** + * [[IsExtensible]] operation for Ordinary object. + * + * See also: + * ECMAScript v6, 9.1.2 + * + * @return true - if object is extensible + * false - otherwise + */ +bool JERRY_ATTR_PURE +ecma_op_ordinary_object_is_extensible (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p)); + + bool is_extensible = (object_p->type_flags_refs & ECMA_OBJECT_FLAG_EXTENSIBLE) != 0; + + JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p) || is_extensible); + + return is_extensible; +} /* ecma_op_ordinary_object_is_extensible */ + +/** + * Set value of [[Extensible]] object's internal property. + * + * @return void + */ +void JERRY_ATTR_NOINLINE +ecma_op_ordinary_object_prevent_extensions (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p)); + + if (JERRY_UNLIKELY (ecma_op_object_is_fast_array (object_p))) + { + ecma_fast_array_convert_to_normal (object_p); + } + + object_p->type_flags_refs &= (ecma_object_descriptor_t) ~ECMA_OBJECT_FLAG_EXTENSIBLE; +} /* ecma_op_ordinary_object_prevent_extensions */ + +/** + * Checks whether an object (excluding prototypes) has a named property + * + * @return true - if property is found + * false - otherwise + */ +ecma_value_t +ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p) /**< property name */ +{ + JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p)); + + ecma_property_t property = + ecma_op_object_get_own_property (object_p, property_name_p, NULL, ECMA_PROPERTY_GET_NO_OPTIONS); + +#if JERRY_BUILTIN_TYPEDARRAY + if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW)) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + + JERRY_ASSERT (ECMA_PROPERTY_IS_FOUND (property) || property == ECMA_PROPERTY_TYPE_NOT_FOUND + || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + + return ecma_make_boolean_value (ECMA_PROPERTY_IS_FOUND (property)); +} /* ecma_op_ordinary_object_has_own_property */ + +/** + * Checks whether an object (excluding prototypes) has a named property. Handles proxy objects too. + * + * @return true - if property is found + * false - otherwise + */ +ecma_value_t +ecma_op_object_has_own_property (ecma_object_t *object_p, /**< the object */ + ecma_string_t *property_name_p) /**< property name */ +{ +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (object_p)) + { + ecma_property_descriptor_t prop_desc; + + ecma_value_t status = ecma_proxy_object_get_own_property_descriptor (object_p, property_name_p, &prop_desc); + + if (ecma_is_value_true (status)) + { + ecma_free_property_descriptor (&prop_desc); + } + + return status; + } +#endif /* JERRY_BUILTIN_PROXY */ + + return ecma_op_ordinary_object_has_own_property (object_p, property_name_p); +} /* ecma_op_object_has_own_property */ + +#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER + +/** + * Set a weak reference from a container or WeakRefObject to a key object + */ +void +ecma_op_object_set_weak (ecma_object_t *object_p, /**< key object */ + ecma_object_t *target_p) /**< target object */ +{ + if (JERRY_UNLIKELY (ecma_op_object_is_fast_array (object_p))) + { + ecma_fast_array_convert_to_normal (object_p); + } + + ecma_string_t *weak_refs_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_WEAK_REFS); + ecma_property_t *property_p = ecma_find_named_property (object_p, weak_refs_string_p); + ecma_collection_t *refs_p; + + if (property_p == NULL) + { + refs_p = ecma_new_collection (); + + ecma_property_value_t *value_p; + ECMA_CREATE_INTERNAL_PROPERTY (object_p, weak_refs_string_p, property_p, value_p); + ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, refs_p); + } + else + { + refs_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, (ECMA_PROPERTY_VALUE_PTR (property_p)->value)); + } + + const ecma_value_t target_value = ecma_make_object_value ((ecma_object_t *) target_p); + for (uint32_t i = 0; i < refs_p->item_count; i++) + { + if (ecma_is_value_empty (refs_p->buffer_p[i])) + { + refs_p->buffer_p[i] = target_value; + return; + } + } + + ecma_collection_push_back (refs_p, target_value); +} /* ecma_op_object_set_weak */ + +/** + * Helper function to remove a weak reference to an object. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +void +ecma_op_object_unref_weak (ecma_object_t *object_p, /**< this argument */ + ecma_value_t ref_holder) /**< key argument */ +{ + ecma_string_t *weak_refs_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_WEAK_REFS); + + ecma_property_t *property_p = ecma_find_named_property (object_p, weak_refs_string_p); + JERRY_ASSERT (property_p != NULL); + + ecma_collection_t *refs_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ECMA_PROPERTY_VALUE_PTR (property_p)->value); + ecma_value_t *buffer_p = refs_p->buffer_p; + + while (true) + { + if (*buffer_p == ref_holder) + { + *buffer_p = ECMA_VALUE_EMPTY; + return; + } + JERRY_ASSERT (buffer_p < refs_p->buffer_p + refs_p->item_count); + buffer_p++; + } +} /* ecma_op_object_unref_weak */ + +#endif /* JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER */ +/** + * Raise property redefinition error + * + * @return ECMA_VALUE_FALSE - if JERRY_PROP_SHOULD_THROW is not set + * raised TypeError - otherwise + */ +ecma_value_t +ecma_raise_property_redefinition (ecma_string_t *property_name_p, /**< property name */ + uint16_t flags) /**< property descriptor flags */ +{ + JERRY_UNUSED (property_name_p); + + return ECMA_REJECT_WITH_FORMAT (flags & JERRY_PROP_SHOULD_THROW, + "Cannot redefine property: %", + ecma_make_prop_name_value (property_name_p)); +} /* ecma_raise_property_redefinition */ + +/** + * Raise readonly assignment error + * + * @return ECMA_VALUE_FALSE - if is_throw is true + * raised TypeError - otherwise + */ +ecma_value_t +ecma_raise_readonly_assignment (ecma_string_t *property_name_p, /**< property name */ + bool is_throw) /**< is throw flag */ +{ + JERRY_UNUSED (property_name_p); + + return ECMA_REJECT_WITH_FORMAT (is_throw, + "Cannot assign to read only property '%'", + ecma_make_prop_name_value (property_name_p)); +} /* ecma_raise_readonly_assignment */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects.h new file mode 100644 index 0000000..87e2538 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-objects.h @@ -0,0 +1,147 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_OBJECTS_H +#define ECMA_OBJECTS_H + +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaobjectsinternalops ECMA objects' operations + * @{ + */ + +#if JERRY_ERROR_MESSAGES +/** + * Reject with TypeError depending on 'is_throw' with the given format + */ +#define ECMA_REJECT_WITH_FORMAT(is_throw, msg, ...) \ + ((is_throw) ? ecma_raise_standard_error_with_format (JERRY_ERROR_TYPE, (msg), __VA_ARGS__) : ECMA_VALUE_FALSE) + +/** + * Reject with TypeError depending on 'is_throw' with the given message + */ +#define ECMA_REJECT(is_throw, msg) ((is_throw) ? ecma_raise_type_error (msg) : ECMA_VALUE_FALSE) +#else /* !JERRY_ERROR_MESSAGES */ +/** + * Reject with TypeError depending on is_throw flags wit the given format + */ +#define ECMA_REJECT_WITH_FORMAT(is_throw, msg, ...) ECMA_REJECT ((is_throw), (msg)) + +/** + * Reject with TypeError depending on is_throw flags wit the given message + */ +#define ECMA_REJECT(is_throw, msg) ((is_throw) ? ecma_raise_type_error (ECMA_ERR_EMPTY) : ECMA_VALUE_FALSE) +#endif /* JERRY_ERROR_MESSAGES */ + +ecma_value_t ecma_raise_property_redefinition (ecma_string_t *property_name_p, uint16_t flags); +ecma_value_t ecma_raise_readonly_assignment (ecma_string_t *property_name_p, bool is_throw); + +ecma_property_t ecma_op_object_get_own_property (ecma_object_t *object_p, + ecma_string_t *property_name_p, + ecma_property_ref_t *property_ref_p, + uint32_t options); +ecma_value_t ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t ecma_op_object_has_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t ecma_op_object_has_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t ecma_op_object_find_own (ecma_value_t base_value, ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t ecma_op_object_find (ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t ecma_op_object_find_by_index (ecma_object_t *object_p, ecma_length_t index); +ecma_value_t ecma_op_object_get (ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t +ecma_op_object_get_with_receiver (ecma_object_t *object_p, ecma_string_t *property_name_p, ecma_value_t receiver); +ecma_value_t ecma_op_object_get_length (ecma_object_t *object_p, ecma_length_t *length_p); +ecma_value_t ecma_op_object_get_by_index (ecma_object_t *object_p, ecma_length_t index); +ecma_value_t ecma_op_object_get_by_magic_id (ecma_object_t *object_p, lit_magic_string_id_t property_id); +ecma_string_t *ecma_op_get_global_symbol (lit_magic_string_id_t property_id); +bool ecma_op_compare_string_to_global_symbol (ecma_string_t *string_p, lit_magic_string_id_t property_id); +ecma_value_t ecma_op_object_get_by_symbol_id (ecma_object_t *object_p, lit_magic_string_id_t property_id); +ecma_value_t ecma_op_get_method_by_symbol_id (ecma_value_t value, lit_magic_string_id_t symbol_id); +ecma_value_t ecma_op_get_method_by_magic_id (ecma_value_t value, lit_magic_string_id_t magic_id); +ecma_value_t ecma_op_object_put_with_receiver (ecma_object_t *object_p, + ecma_string_t *property_name_p, + ecma_value_t value, + ecma_value_t receiver, + bool is_throw); +ecma_value_t +ecma_op_object_put (ecma_object_t *object_p, ecma_string_t *property_name_p, ecma_value_t value, bool is_throw); +ecma_value_t ecma_op_object_put_with_receiver (ecma_object_t *object_p, + ecma_string_t *property_name_p, + ecma_value_t value, + ecma_value_t receiver, + bool is_throw); +ecma_value_t +ecma_op_object_put_by_index (ecma_object_t *object_p, ecma_length_t index, ecma_value_t value, bool is_throw); +ecma_value_t ecma_op_object_delete (ecma_object_t *obj_p, ecma_string_t *property_name_p, bool is_throw); +ecma_value_t ecma_op_object_delete_by_index (ecma_object_t *obj_p, ecma_length_t index, bool is_throw); +ecma_value_t ecma_op_object_default_value (ecma_object_t *obj_p, ecma_preferred_type_hint_t hint); +ecma_value_t ecma_op_object_define_own_property (ecma_object_t *obj_p, + ecma_string_t *property_name_p, + const ecma_property_descriptor_t *property_desc_p); +ecma_value_t ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, + ecma_string_t *property_name_p, + ecma_property_descriptor_t *prop_desc_p); +ecma_value_t ecma_op_object_has_instance (ecma_object_t *obj_p, ecma_value_t value); +ecma_object_t *ecma_op_object_get_prototype_of (ecma_object_t *obj_p); + +ecma_value_t ecma_op_object_is_prototype_of (ecma_object_t *base_p, ecma_object_t *target_p); +ecma_collection_t *ecma_op_object_get_enumerable_property_names (ecma_object_t *obj_p, + ecma_enumerable_property_names_options_t option); +ecma_collection_t *ecma_op_object_own_property_keys (ecma_object_t *obj_p, jerry_property_filter_t filter); +ecma_collection_t *ecma_op_object_enumerate (ecma_object_t *obj_p); + +lit_magic_string_id_t ecma_object_get_class_name (ecma_object_t *obj_p); +#if JERRY_BUILTIN_REGEXP +bool ecma_object_is_regexp_object (ecma_value_t arg); +#endif /* JERRY_BUILTIN_REGEXP */ +ecma_value_t ecma_op_is_concat_spreadable (ecma_value_t arg); +ecma_value_t ecma_op_is_regexp (ecma_value_t arg); +ecma_value_t ecma_op_species_constructor (ecma_object_t *this_value, ecma_builtin_id_t default_constructor_id); +ecma_value_t ecma_op_invoke_by_symbol_id (ecma_value_t object, + lit_magic_string_id_t magic_string_id, + ecma_value_t *args_p, + uint32_t args_len); +#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER +void ecma_op_object_set_weak (ecma_object_t *object_p, ecma_object_t *target_p); +void ecma_op_object_unref_weak (ecma_object_t *object_p, ecma_value_t ref_holder); +#endif /* JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER */ +ecma_value_t +ecma_op_invoke (ecma_value_t object, ecma_string_t *property_name_p, ecma_value_t *args_p, uint32_t args_len); +ecma_value_t ecma_op_invoke_by_magic_id (ecma_value_t object, + lit_magic_string_id_t magic_string_id, + ecma_value_t *args_p, + uint32_t args_len); + +jmem_cpointer_t ecma_op_ordinary_object_get_prototype_of (ecma_object_t *obj_p); +ecma_value_t ecma_op_ordinary_object_set_prototype_of (ecma_object_t *base_p, ecma_value_t proto); +bool JERRY_ATTR_PURE ecma_op_ordinary_object_is_extensible (ecma_object_t *object_p); +void ecma_op_ordinary_object_prevent_extensions (ecma_object_t *object_p); + +#if JERRY_BUILTIN_PROXY +ecma_value_t ecma_op_get_own_property_descriptor (ecma_value_t target, + ecma_string_t *property_name_p, + ecma_property_descriptor_t *prop_desc_p); +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * @} + * @} + */ + +#endif /* !ECMA_OBJECTS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-promise-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-promise-object.cpp new file mode 100644 index 0000000..203dff2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-promise-object.cpp @@ -0,0 +1,1237 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-promise-object.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-boolean-object.h" +#include "ecma-builtin-handlers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-jobqueue.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmapromiseobject ECMA Promise object related routines + * @{ + */ + +/** + * Check if an object is promise. + * + * @return true - if the object is a promise. + * false - otherwise. + */ +bool +ecma_is_promise (ecma_object_t *obj_p) /**< points to object */ +{ + return ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_PROMISE); +} /* ecma_is_promise */ + +/** + * Get the result of the promise. + * + * @return ecma value of the promise result. + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_promise_get_result (ecma_object_t *obj_p) /**< points to promise object */ +{ + JERRY_ASSERT (ecma_is_promise (obj_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + return ecma_copy_value (ext_object_p->u.cls.u3.value); +} /* ecma_promise_get_result */ + +/** + * Set the PromiseResult of promise. + * + * @return void + */ +static inline void +ecma_promise_set_result (ecma_object_t *obj_p, /**< points to promise object */ + ecma_value_t result) /**< the result value */ +{ + JERRY_ASSERT (ecma_is_promise (obj_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + JERRY_ASSERT (ext_object_p->u.cls.u3.value == ECMA_VALUE_UNDEFINED); + + ext_object_p->u.cls.u3.value = result; +} /* ecma_promise_set_result */ + +/** + * Get the PromiseState of promise. + * + * @return the state's enum value + */ +uint8_t +ecma_promise_get_flags (ecma_object_t *obj_p) /**< points to promise object */ +{ + JERRY_ASSERT (ecma_is_promise (obj_p)); + + return ((ecma_extended_object_t *) obj_p)->u.cls.u1.promise_flags; +} /* ecma_promise_get_flags */ + +/** + * Set the PromiseState of promise. + * + * @return void + */ +static inline void +ecma_promise_set_state (ecma_object_t *obj_p, /**< points to promise object */ + bool is_fulfilled) /**< new flags */ +{ + JERRY_ASSERT (ecma_is_promise (obj_p)); + JERRY_ASSERT (ecma_promise_get_flags (obj_p) & ECMA_PROMISE_IS_PENDING); + + uint8_t flags_to_invert = + (is_fulfilled ? (ECMA_PROMISE_IS_PENDING | ECMA_PROMISE_IS_FULFILLED) : ECMA_PROMISE_IS_PENDING); + + ((ecma_extended_object_t *) obj_p)->u.cls.u1.promise_flags ^= flags_to_invert; +} /* ecma_promise_set_state */ + +/** + * Take a collection of Reactions and enqueue a new PromiseReactionJob for each Reaction. + * + * See also: ES2015 25.4.1.8 + */ +static void +ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reactions */ + ecma_value_t value, /**< value for resolve or reject */ + bool is_reject) /**< true if promise is rejected, false otherwise */ +{ + ecma_value_t *buffer_p = reactions->buffer_p; + ecma_value_t *buffer_end_p = buffer_p + reactions->item_count; + + while (buffer_p < buffer_end_p) + { + ecma_value_t object_with_tag = *buffer_p++; + ecma_object_t *object_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, object_with_tag); + ecma_value_t object = ecma_make_object_value (object_p); + + if (JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (object_with_tag)) + { + ecma_enqueue_promise_async_reaction_job (object, value, is_reject); + continue; + } + + if (!is_reject) + { + ecma_value_t handler = ECMA_VALUE_TRUE; + + if (JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (object_with_tag)) + { + handler = *buffer_p++; + } + + ecma_enqueue_promise_reaction_job (object, handler, value); + } + else if (JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (object_with_tag)) + { + buffer_p++; + } + + if (is_reject) + { + ecma_value_t handler = ECMA_VALUE_FALSE; + + if (JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (object_with_tag)) + { + handler = *buffer_p++; + } + + ecma_enqueue_promise_reaction_job (object, handler, value); + } + else if (JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (object_with_tag)) + { + buffer_p++; + } + } +} /* ecma_promise_trigger_reactions */ + +/** + * Checks whether a resolver is called before. + * + * @return true if it was called before, false otherwise + */ +static inline bool +ecma_is_resolver_already_called (ecma_object_t *promise_obj_p) /**< promise */ +{ + return (ecma_promise_get_flags (promise_obj_p) & ECMA_PROMISE_ALREADY_RESOLVED) != 0; +} /* ecma_is_resolver_already_called */ + +/** + * Reject a Promise with a reason. + * + * See also: ES2015 25.4.1.7 + */ +void +ecma_reject_promise (ecma_value_t promise, /**< promise */ + ecma_value_t reason) /**< reason for reject */ +{ + ecma_object_t *obj_p = ecma_get_object_from_value (promise); + + JERRY_ASSERT (ecma_promise_get_flags (obj_p) & ECMA_PROMISE_IS_PENDING); + + ecma_promise_set_state (obj_p, false); + ecma_promise_set_result (obj_p, ecma_copy_value_if_not_object (reason)); + ecma_promise_object_t *promise_p = (ecma_promise_object_t *) obj_p; + + /* GC can be triggered by ecma_new_collection so freeing the collection + first and creating a new one might cause a heap after use event. */ + ecma_collection_t *reactions = promise_p->reactions; + + /* Fulfill reactions will never be triggered. */ + ecma_promise_trigger_reactions (reactions, reason, true); + + promise_p->reactions = ecma_new_collection (); + + ecma_collection_destroy (reactions); +} /* ecma_reject_promise */ + +/** + * Fulfill a Promise with a value. + * + * See also: ES2015 25.4.1.4 + */ +void +ecma_fulfill_promise (ecma_value_t promise, /**< promise */ + ecma_value_t value) /**< fulfilled value */ +{ + ecma_object_t *obj_p = ecma_get_object_from_value (promise); + + JERRY_ASSERT (ecma_promise_get_flags (obj_p) & ECMA_PROMISE_IS_PENDING); + + if (promise == value) + { + ecma_raise_type_error (ECMA_ERR_PROMISE_RESOLVE_ITSELF); + ecma_value_t exception = jcontext_take_exception (); + ecma_reject_promise (promise, exception); + ecma_free_value (exception); + return; + } + + if (ecma_is_value_object (value)) + { + ecma_value_t then = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (value), LIT_MAGIC_STRING_THEN); + + if (ECMA_IS_VALUE_ERROR (then)) + { + then = jcontext_take_exception (); + ecma_reject_promise (promise, then); + ecma_free_value (then); + return; + } + + if (ecma_op_is_callable (then)) + { + ecma_enqueue_promise_resolve_thenable_job (promise, value, then); + ecma_free_value (then); + return; + } + + ecma_free_value (then); + } + + ecma_promise_set_state (obj_p, true); + ecma_promise_set_result (obj_p, ecma_copy_value_if_not_object (value)); + ecma_promise_object_t *promise_p = (ecma_promise_object_t *) obj_p; + + /* GC can be triggered by ecma_new_collection so freeing the collection + first and creating a new one might cause a heap after use event. */ + ecma_collection_t *reactions = promise_p->reactions; + + /* Reject reactions will never be triggered. */ + ecma_promise_trigger_reactions (reactions, value, false); + + promise_p->reactions = ecma_new_collection (); + + ecma_collection_destroy (reactions); +} /* ecma_fulfill_promise */ + +/** + * Reject a Promise with a reason. Sanity checks are performed before the reject. + * + * See also: ES2015 25.4.1.3.1 + * + * @return ecma value of undefined. + */ +ecma_value_t +ecma_reject_promise_with_checks (ecma_value_t promise, /**< promise */ + ecma_value_t reason) /**< reason for reject */ +{ + /* 1. */ + ecma_object_t *promise_obj_p = ecma_get_object_from_value (promise); + JERRY_ASSERT (ecma_is_promise (promise_obj_p)); + + /* 3., 4. */ + if (JERRY_UNLIKELY (ecma_is_resolver_already_called (promise_obj_p))) + { + return ECMA_VALUE_UNDEFINED; + } + + /* 5. */ + ((ecma_extended_object_t *) promise_obj_p)->u.cls.u1.promise_flags |= ECMA_PROMISE_ALREADY_RESOLVED; + + /* 6. */ + ecma_reject_promise (promise, reason); + return ECMA_VALUE_UNDEFINED; +} /* ecma_reject_promise_with_checks */ + +/** + * Fulfill a Promise with a value. Sanity checks are performed before the resolve. + * + * See also: ES2015 25.4.1.3.2 + * + * @return ecma value of undefined. + */ +ecma_value_t +ecma_fulfill_promise_with_checks (ecma_value_t promise, /**< promise */ + ecma_value_t value) /**< fulfilled value */ +{ + /* 1. */ + ecma_object_t *promise_obj_p = ecma_get_object_from_value (promise); + JERRY_ASSERT (ecma_is_promise (promise_obj_p)); + + /* 3., 4. */ + if (JERRY_UNLIKELY (ecma_is_resolver_already_called (promise_obj_p))) + { + return ECMA_VALUE_UNDEFINED; + } + + /* 5. */ + ((ecma_extended_object_t *) promise_obj_p)->u.cls.u1.promise_flags |= ECMA_PROMISE_ALREADY_RESOLVED; + + ecma_fulfill_promise (promise, value); + return ECMA_VALUE_UNDEFINED; +} /* ecma_fulfill_promise_with_checks */ + +/** + * Native handler for Promise Reject Function. + * + * @return ecma value of undefined. + */ +ecma_value_t +ecma_promise_reject_handler (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + ecma_promise_resolver_t *function_p = (ecma_promise_resolver_t *) function_obj_p; + + ecma_value_t reject_value = (args_count == 0) ? ECMA_VALUE_UNDEFINED : args_p[0]; + return ecma_reject_promise_with_checks (function_p->promise, reject_value); +} /* ecma_promise_reject_handler */ + +/** + * Native handler for Promise Resolve Function. + * + * @return ecma value of undefined. + */ +ecma_value_t +ecma_promise_resolve_handler (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + ecma_promise_resolver_t *function_p = (ecma_promise_resolver_t *) function_obj_p; + + ecma_value_t fulfilled_value = (args_count == 0) ? ECMA_VALUE_UNDEFINED : args_p[0]; + return ecma_fulfill_promise_with_checks (function_p->promise, fulfilled_value); +} /* ecma_promise_resolve_handler */ + +/** + * Helper function for PromiseCreateResolvingFunctions. + * + * See also: ES2015 25.4.1.3 2. - 7. + * + * @return pointer to the resolving function + */ +static ecma_object_t * +ecma_promise_create_resolving_function (ecma_object_t *promise_p, /**< Promise Object */ + ecma_native_handler_id_t id) /**< Callback handler */ +{ + ecma_object_t *func_obj_p = ecma_op_create_native_handler (id, sizeof (ecma_promise_resolver_t)); + + ecma_promise_resolver_t *resolver_p = (ecma_promise_resolver_t *) func_obj_p; + resolver_p->promise = ecma_make_object_value (promise_p); + + return func_obj_p; +} /* ecma_promise_create_resolving_function */ + +/** + * Helper function for running an executor. + * + * @return ecma value of the executor callable + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_promise_run_executor (ecma_object_t *promise_p, /**< Promise Object */ + ecma_value_t executor, /**< executor function */ + ecma_value_t this_value) /**< this value */ +{ + ecma_object_t *resolve_func_p, *reject_func_p; + resolve_func_p = ecma_promise_create_resolving_function (promise_p, ECMA_NATIVE_HANDLER_PROMISE_RESOLVE); + reject_func_p = ecma_promise_create_resolving_function (promise_p, ECMA_NATIVE_HANDLER_PROMISE_REJECT); + + ecma_value_t argv[] = { ecma_make_object_value (resolve_func_p), ecma_make_object_value (reject_func_p) }; + ecma_value_t result = ecma_op_function_call (ecma_get_object_from_value (executor), this_value, argv, 2); + ecma_deref_object (resolve_func_p); + ecma_deref_object (reject_func_p); + + return result; +} /* ecma_promise_run_executor */ + +/** + * Create a promise object. + * + * See also: ES2015 25.4.3.1 + * + * @return ecma value of the new promise object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function or ECMA_VALUE_EMPTY */ + ecma_value_t parent, /**< parent promise if available */ + ecma_object_t *new_target_p) /**< new.target value */ +{ + JERRY_UNUSED (parent); + + if (new_target_p == NULL) + { + new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE); + } + + /* 3. */ + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (new_target_p, ECMA_BUILTIN_ID_PROMISE_PROTOTYPE); + + if (JERRY_UNLIKELY (proto_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + /* Calling ecma_new_collection might trigger a GC call, so this + * allocation is performed before the object is constructed. */ + ecma_collection_t *reactions = ecma_new_collection (); + + ecma_object_t *object_p = ecma_create_object (proto_p, sizeof (ecma_promise_object_t), ECMA_OBJECT_TYPE_CLASS); + ecma_deref_object (proto_p); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_PROMISE; + /* 5 */ + ext_object_p->u.cls.u1.promise_flags = ECMA_PROMISE_IS_PENDING; + ext_object_p->u.cls.u3.value = ECMA_VALUE_UNDEFINED; + + /* 6-8. */ + ecma_promise_object_t *promise_object_p = (ecma_promise_object_t *) object_p; + promise_object_p->reactions = reactions; + + /* 9. */ + ecma_value_t completion = ECMA_VALUE_UNDEFINED; + + if (executor != ECMA_VALUE_EMPTY) + { + JERRY_ASSERT (ecma_op_is_callable (executor)); + + completion = ecma_promise_run_executor (object_p, executor, ECMA_VALUE_UNDEFINED); + } + + ecma_value_t status = ECMA_VALUE_EMPTY; + + if (ECMA_IS_VALUE_ERROR (completion)) + { + /* 10.a. */ + completion = jcontext_take_exception (); + ecma_reject_promise_with_checks (ecma_make_object_value (object_p), completion); + } + + ecma_free_value (completion); + + /* 10.b. */ + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_deref_object (object_p); + return status; + } + + /* 11. */ + ecma_free_value (status); + return ecma_make_object_value (object_p); +} /* ecma_op_create_promise_object */ + +/** + * Helper function for increase or decrease the remaining count. + * + * @return the current remaining count after increase or decrease. + */ +uint32_t +ecma_promise_remaining_inc_or_dec (ecma_value_t remaining, /**< the remaining count */ + bool is_inc) /**< whether to increase the count */ +{ + JERRY_ASSERT (ecma_is_value_object (remaining)); + + ecma_object_t *remaining_p = ecma_get_object_from_value (remaining); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) remaining_p; + + JERRY_ASSERT (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_NUMBER); + + JERRY_ASSERT (ecma_is_value_integer_number (ext_object_p->u.cls.u3.value)); + + uint32_t current = (uint32_t) ecma_get_integer_from_value (ext_object_p->u.cls.u3.value); + + if (is_inc) + { + current++; + } + else + { + current--; + } + ext_object_p->u.cls.u3.value = ecma_make_uint32_value (current); + + return current; +} /* ecma_promise_remaining_inc_or_dec */ + +/** + * Native handler for Promise.all and Promise.allSettled Resolve Element Function. + * + * See also: + * ES2015 25.4.4.1.2 + * + * @return ecma value of undefined. + */ +ecma_value_t +ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + ecma_value_t arg = args_count > 0 ? args_p[0] : ECMA_VALUE_UNDEFINED; + + ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) function_obj_p; + uint8_t promise_type = executor_p->header.u.built_in.u2.routine_flags; + + promise_type = (uint8_t) (promise_type >> ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT); + + /* 1 - 2. */ + if (executor_p->index == 0) + { + return ECMA_VALUE_UNDEFINED; + } + + if (promise_type == ECMA_PROMISE_ALL_RESOLVE || promise_type == ECMA_PROMISE_ANY_REJECT) + { + /* 8. */ + ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values), + (uint32_t) (executor_p->index - 1), + arg, + false); + } + else + { + lit_magic_string_id_t status_property_val = LIT_MAGIC_STRING_REJECTED; + lit_magic_string_id_t data_property_name = LIT_MAGIC_STRING_REASON; + + if (promise_type == ECMA_PROMISE_ALLSETTLED_RESOLVE) + { + status_property_val = LIT_MAGIC_STRING_FULFILLED; + data_property_name = LIT_MAGIC_STRING_VALUE; + } + + ecma_object_t *obj_p = + ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_property_value_t *prop_value_p; + prop_value_p = ecma_create_named_data_property (obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_STATUS), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + + prop_value_p->value = ecma_make_magic_string_value (status_property_val); + + prop_value_p = ecma_create_named_data_property (obj_p, + ecma_get_magic_string (data_property_name), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + prop_value_p->value = ecma_copy_value_if_not_object (arg); + + ecma_value_t obj_val = ecma_make_object_value (obj_p); + /* 12. */ + ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values), + (uint32_t) (executor_p->index - 1), + obj_val, + false); + ecma_deref_object (obj_p); + } + /* 3. */ + executor_p->index = 0; + + /* 9-10. */ + ecma_value_t ret = ECMA_VALUE_UNDEFINED; + if (ecma_promise_remaining_inc_or_dec (executor_p->remaining_elements, false) == 0) + { + ecma_value_t capability = executor_p->capability; + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) ecma_get_object_from_value (capability); + if (promise_type == ECMA_PROMISE_ANY_REJECT) + { + ecma_value_t error_val = ecma_new_aggregate_error (executor_p->values, ECMA_VALUE_UNDEFINED); + ret = + ecma_op_function_call (ecma_get_object_from_value (capability_p->reject), ECMA_VALUE_UNDEFINED, &error_val, 1); + ecma_free_value (error_val); + } + else + { + ret = ecma_op_function_call (ecma_get_object_from_value (capability_p->resolve), + ECMA_VALUE_UNDEFINED, + &executor_p->values, + 1); + } + } + + return ret; +} /* ecma_promise_all_or_all_settled_handler_cb */ + +/** + * GetCapabilitiesExecutor Functions + * + * Checks and sets a promiseCapability's resolve and reject properties. + * + * See also: ES11 25.6.1.5.1 + * + * @return ECMA_VALUE_UNDEFINED or TypeError + * returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_get_capabilities_executor_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + /* 1. */ + ecma_promise_capability_executor_t *executor_p = (ecma_promise_capability_executor_t *) function_obj_p; + + /* 2-3. */ + ecma_object_t *capability_obj_p = ecma_get_object_from_value (executor_p->capability); + JERRY_ASSERT (ecma_object_class_is (capability_obj_p, ECMA_OBJECT_CLASS_PROMISE_CAPABILITY)); + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + + /* 4. */ + if (!ecma_is_value_undefined (capability_p->resolve)) + { + return ecma_raise_type_error (ECMA_ERR_RESOLVE_MUST_BE_UNDEFINED); + } + + /* 5. */ + if (!ecma_is_value_undefined (capability_p->reject)) + { + return ecma_raise_type_error (ECMA_ERR_REJECT_MUST_BE_UNDEFINED); + } + + /* 6. */ + capability_p->resolve = (args_count > 0) ? args_p[0] : ECMA_VALUE_UNDEFINED; + /* 7. */ + capability_p->reject = (args_count > 1) ? args_p[1] : ECMA_VALUE_UNDEFINED; + + /* 8. */ + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_get_capabilities_executor_cb */ + +/** + * Create a new PromiseCapability. + * + * See also: ES11 25.6.1.5 + * + * @return NULL - if the operation raises error + * new PromiseCapability object - otherwise + */ +ecma_object_t * +ecma_promise_new_capability (ecma_value_t constructor, /**< constructor function */ + ecma_value_t parent) /**< parent promise if available */ +{ + /* 1. */ + if (!ecma_is_constructor (constructor)) + { + ecma_raise_type_error (ECMA_ERR_INVALID_CAPABILITY); + return NULL; + } + + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor); + + /* 3. */ + ecma_object_t *capability_obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), + sizeof (ecma_promise_capability_t), + ECMA_OBJECT_TYPE_CLASS); + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + capability_p->header.u.cls.type = ECMA_OBJECT_CLASS_PROMISE_CAPABILITY; + capability_p->header.u.cls.u3.promise = ECMA_VALUE_UNDEFINED; + capability_p->resolve = ECMA_VALUE_UNDEFINED; + capability_p->reject = ECMA_VALUE_UNDEFINED; + + /* 4-5. */ + ecma_object_t *executor_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_CAPABILITY_EXECUTOR, + sizeof (ecma_promise_capability_executor_t)); + + /* 6. */ + ecma_promise_capability_executor_t *executor_func_p = (ecma_promise_capability_executor_t *) executor_p; + executor_func_p->capability = ecma_make_object_value (capability_obj_p); + + /* 7. */ + ecma_value_t executor = ecma_make_object_value (executor_p); + ecma_value_t promise; + + if (constructor_obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE)) + { + promise = ecma_op_create_promise_object (executor, parent, constructor_obj_p); + } + else + { + promise = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, &executor, 1); + } + + ecma_deref_object (executor_p); + + if (ECMA_IS_VALUE_ERROR (promise)) + { + ecma_deref_object (capability_obj_p); + return NULL; + } + + /* 8. */ + if (!ecma_op_is_callable (capability_p->resolve)) + { + ecma_free_value (promise); + ecma_deref_object (capability_obj_p); + ecma_raise_type_error (ECMA_ERR_PARAMETER_RESOLVE_MUST_BE_CALLABLE); + return NULL; + } + + /* 9. */ + if (!ecma_op_is_callable (capability_p->reject)) + { + ecma_free_value (promise); + ecma_deref_object (capability_obj_p); + ecma_raise_type_error (ECMA_ERR_PARAMETER_REJECT_MUST_BE_CALLABLE); + return NULL; + } + + /* 10. */ + capability_p->header.u.cls.u3.promise = promise; + + ecma_free_value (promise); + + /* 11. */ + return capability_obj_p; +} /* ecma_promise_new_capability */ + +/** + * The common function for 'reject' and 'resolve'. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_promise_reject_or_resolve (ecma_value_t this_arg, /**< "this" argument */ + ecma_value_t value, /**< rejected or resolved value */ + bool is_resolve) /**< the operation is resolve */ +{ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + if (is_resolve && ecma_is_value_object (value) && ecma_is_promise (ecma_get_object_from_value (value))) + { + ecma_object_t *object_p = ecma_get_object_from_value (value); + ecma_value_t constructor = ecma_op_object_get_by_magic_id (object_p, LIT_MAGIC_STRING_CONSTRUCTOR); + + if (ECMA_IS_VALUE_ERROR (constructor)) + { + return constructor; + } + + /* The this_arg must be an object. */ + bool is_same_value = (constructor == this_arg); + ecma_free_value (constructor); + + if (is_same_value) + { + return ecma_copy_value (value); + } + } + + ecma_object_t *capability_obj_p = ecma_promise_new_capability (this_arg, ECMA_VALUE_UNDEFINED); + + if (JERRY_UNLIKELY (capability_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + + ecma_value_t func = is_resolve ? capability_p->resolve : capability_p->reject; + + ecma_value_t call_ret = ecma_op_function_call (ecma_get_object_from_value (func), ECMA_VALUE_UNDEFINED, &value, 1); + + if (ECMA_IS_VALUE_ERROR (call_ret)) + { + ecma_deref_object (capability_obj_p); + return call_ret; + } + + ecma_free_value (call_ret); + + ecma_value_t promise = ecma_copy_value (capability_p->header.u.cls.u3.promise); + ecma_deref_object (capability_obj_p); + + return promise; +} /* ecma_promise_reject_or_resolve */ + +/** + * The common function for ecma_builtin_promise_prototype_then + * and ecma_builtin_promise_prototype_catch. + * + * @return ecma value of a new promise object. + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_promise_then (ecma_value_t promise, /**< the promise which call 'then' */ + ecma_value_t on_fulfilled, /**< on_fulfilled function */ + ecma_value_t on_rejected) /**< on_rejected function */ +{ + if (!ecma_is_value_object (promise)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj = ecma_get_object_from_value (promise); + + if (!ecma_is_promise (obj)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_PROMISE); + } + + ecma_value_t species = ecma_op_species_constructor (obj, ECMA_BUILTIN_ID_PROMISE); + if (ECMA_IS_VALUE_ERROR (species)) + { + return species; + } + + ecma_object_t *result_capability_obj_p = ecma_promise_new_capability (species, promise); + ecma_free_value (species); + + if (JERRY_UNLIKELY (result_capability_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret = ecma_promise_perform_then (promise, on_fulfilled, on_rejected, result_capability_obj_p); + ecma_deref_object (result_capability_obj_p); + + return ret; +} /* ecma_promise_then */ + +/** + * Definition of valueThunk function + * + * See also: + * ES2020 25.6.5.3.1 step 8. + * + * @return ecma value + */ +ecma_value_t +ecma_value_thunk_helper_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + JERRY_UNUSED_2 (args_p, args_count); + + ecma_promise_value_thunk_t *value_thunk_obj_p = (ecma_promise_value_thunk_t *) function_obj_p; + + return ecma_copy_value (value_thunk_obj_p->value); +} /* ecma_value_thunk_helper_cb */ + +/** + * Definition of thrower function + * + * See also: + * ES2020 25.6.5.3.2 step 8. + * + * @return ecma value + */ +ecma_value_t +ecma_value_thunk_thrower_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + JERRY_UNUSED_2 (args_p, args_count); + + ecma_promise_value_thunk_t *value_thunk_obj_p = (ecma_promise_value_thunk_t *) function_obj_p; + + jcontext_raise_exception (ecma_copy_value (value_thunk_obj_p->value)); + + return ECMA_VALUE_ERROR; +} /* ecma_value_thunk_thrower_cb */ + +/** + * Helper function for Then Finally and Catch Finally common parts + * + * See also: + * ES2020 25.6.5.3.1 + * ES2020 25.6.5.3.2 + * + * @return ecma value + */ +static ecma_value_t +ecma_promise_then_catch_finally_helper (ecma_object_t *function_obj_p, /**< function object */ + ecma_native_handler_id_t id, /**< handler id */ + ecma_value_t arg) /**< callback function argument */ +{ + /* 2. */ + ecma_promise_finally_function_t *finally_func_obj = (ecma_promise_finally_function_t *) function_obj_p; + + /* 3. */ + JERRY_ASSERT (ecma_op_is_callable (finally_func_obj->on_finally)); + + /* 4. */ + ecma_value_t result = + ecma_op_function_call (ecma_get_object_from_value (finally_func_obj->on_finally), ECMA_VALUE_UNDEFINED, NULL, 0); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + /* 6. */ + JERRY_ASSERT (ecma_is_constructor (finally_func_obj->constructor)); + + /* 7. */ + ecma_value_t promise = ecma_promise_reject_or_resolve (finally_func_obj->constructor, result, true); + + ecma_free_value (result); + + if (ECMA_IS_VALUE_ERROR (promise)) + { + return promise; + } + + /* 8. */ + ecma_object_t *value_thunk_func_p; + value_thunk_func_p = ecma_op_create_native_handler (id, sizeof (ecma_promise_value_thunk_t)); + + ecma_promise_value_thunk_t *value_thunk_func_obj = (ecma_promise_value_thunk_t *) value_thunk_func_p; + value_thunk_func_obj->value = ecma_copy_value_if_not_object (arg); + + /* 9. */ + ecma_value_t value_thunk = ecma_make_object_value (value_thunk_func_p); + ecma_value_t ret_value = ecma_op_invoke_by_magic_id (promise, LIT_MAGIC_STRING_THEN, &value_thunk, 1); + + ecma_free_value (promise); + ecma_deref_object (value_thunk_func_p); + + return ret_value; +} /* ecma_promise_then_catch_finally_helper */ + +/** + * Definition of Then Finally Function + * + * See also: + * ES2020 25.6.5.3.1 + * + * @return ecma value + */ +ecma_value_t +ecma_promise_then_finally_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + JERRY_UNUSED (args_count); + JERRY_ASSERT (args_count > 0); + + return ecma_promise_then_catch_finally_helper (function_obj_p, ECMA_NATIVE_HANDLER_VALUE_THUNK, args_p[0]); +} /* ecma_promise_then_finally_cb */ + +/** + * Definition of Catch Finally Function + * + * See also: + * ES2020 25.6.5.3.2 + * + * @return ecma value + */ +ecma_value_t +ecma_promise_catch_finally_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + JERRY_UNUSED (args_count); + JERRY_ASSERT (args_count > 0); + + return ecma_promise_then_catch_finally_helper (function_obj_p, ECMA_NATIVE_HANDLER_VALUE_THROWER, args_p[0]); +} /* ecma_promise_catch_finally_cb */ + +/** + * The common function for ecma_builtin_promise_prototype_finally + * + * @return ecma value of a new promise object. + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_promise_finally (ecma_value_t promise, /**< the promise which call 'finally' */ + ecma_value_t on_finally) /**< on_finally function */ +{ + /* 2. */ + if (!ecma_is_value_object (promise)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_object_t *obj = ecma_get_object_from_value (promise); + + /* 3. */ + ecma_value_t species = ecma_op_species_constructor (obj, ECMA_BUILTIN_ID_PROMISE); + + if (ECMA_IS_VALUE_ERROR (species)) + { + return species; + } + + /* 4. */ + JERRY_ASSERT (ecma_is_constructor (species)); + + /* 5. */ + if (!ecma_op_is_callable (on_finally)) + { + ecma_free_value (species); + ecma_value_t invoke_args[2] = { on_finally, on_finally }; + return ecma_op_invoke_by_magic_id (promise, LIT_MAGIC_STRING_THEN, invoke_args, 2); + } + + /* 6.a-b */ + ecma_object_t *then_finally_obj_p; + then_finally_obj_p = + ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_THEN_FINALLY, sizeof (ecma_promise_finally_function_t)); + + /* 6.c-d */ + ecma_promise_finally_function_t *then_finally_func_obj_p = (ecma_promise_finally_function_t *) then_finally_obj_p; + then_finally_func_obj_p->constructor = species; + then_finally_func_obj_p->on_finally = on_finally; + + /* 6.e-f */ + ecma_object_t *catch_finally_obj_p; + catch_finally_obj_p = + ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_CATCH_FINALLY, sizeof (ecma_promise_finally_function_t)); + + /* 6.g-h */ + ecma_promise_finally_function_t *catch_finally_func_obj = (ecma_promise_finally_function_t *) catch_finally_obj_p; + catch_finally_func_obj->constructor = species; + catch_finally_func_obj->on_finally = on_finally; + + ecma_deref_object (ecma_get_object_from_value (species)); + + /* 7. */ + ecma_value_t invoke_args[2] = { ecma_make_object_value (then_finally_obj_p), + ecma_make_object_value (catch_finally_obj_p) }; + + ecma_value_t ret_value = ecma_op_invoke_by_magic_id (promise, LIT_MAGIC_STRING_THEN, invoke_args, 2); + + ecma_deref_object (then_finally_obj_p); + ecma_deref_object (catch_finally_obj_p); + + return ret_value; +} /* ecma_promise_finally */ + +/** + * Resume the execution of an async function after the promise is resolved + */ +void +ecma_promise_async_then (ecma_value_t promise, /**< promise object */ + ecma_value_t executable_object) /**< executable object of the async function */ +{ + ecma_object_t *promise_obj_p = ecma_get_object_from_value (promise); + uint16_t flags = ecma_promise_get_flags (promise_obj_p); + + if (flags & ECMA_PROMISE_IS_PENDING) + { + ecma_value_t executable_object_with_tag; + ECMA_SET_NON_NULL_POINTER_TAG (executable_object_with_tag, ecma_get_object_from_value (executable_object), 0); + ECMA_SET_THIRD_BIT_TO_POINTER_TAG (executable_object_with_tag); + + ecma_collection_push_back (((ecma_promise_object_t *) promise_obj_p)->reactions, executable_object_with_tag); + return; + } + + ecma_value_t value = ecma_promise_get_result (promise_obj_p); + ecma_enqueue_promise_async_reaction_job (executable_object, value, !(flags & ECMA_PROMISE_IS_FULFILLED)); + ecma_free_value (value); + +} /* ecma_promise_async_then */ + +/** + * Resolves the value and resume the execution of an async function after the resolve is completed + * + * @return ECMA_VALUE_UNDEFINED if not error is occurred, an error otherwise + */ +ecma_value_t +ecma_promise_async_await (ecma_extended_object_t *async_generator_object_p, /**< async generator function */ + ecma_value_t value) /**< value to be resolved (takes the reference) */ +{ + ecma_value_t promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE)); + ecma_value_t result = ecma_promise_reject_or_resolve (promise, value, true); + + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ecma_promise_async_then (result, ecma_make_object_value ((ecma_object_t *) async_generator_object_p)); + ecma_free_value (result); + return ECMA_VALUE_UNDEFINED; +} /* ecma_promise_async_await */ + +/** + * Reject the promise if the value is error. + * + * See also: + * ES2015 25.4.1.1.1 + * + * @return ecma value of the new promise. + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_if_abrupt_reject_promise (ecma_value_t *value_p, /**< [in - out] completion value */ + ecma_object_t *capability_obj_p) /**< capability */ +{ + JERRY_ASSERT (ecma_object_class_is (capability_obj_p, ECMA_OBJECT_CLASS_PROMISE_CAPABILITY)); + + if (!ECMA_IS_VALUE_ERROR (*value_p)) + { + return ECMA_VALUE_EMPTY; + } + + ecma_value_t reason = jcontext_take_exception (); + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) capability_obj_p; + ecma_value_t call_ret = + ecma_op_function_call (ecma_get_object_from_value (capability_p->reject), ECMA_VALUE_UNDEFINED, &reason, 1); + ecma_free_value (reason); + + if (ECMA_IS_VALUE_ERROR (call_ret)) + { + *value_p = call_ret; + return call_ret; + } + + ecma_free_value (call_ret); + *value_p = ecma_copy_value (capability_p->header.u.cls.u3.promise); + + return ECMA_VALUE_EMPTY; +} /* ecma_op_if_abrupt_reject_promise */ + +/** + * It performs the "then" operation on promiFulfilled + * and onRejected as its settlement actions. + * + * See also: 25.4.5.3.1 + * + * @return ecma value of the new promise object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_promise_perform_then (ecma_value_t promise, /**< the promise which call 'then' */ + ecma_value_t on_fulfilled, /**< on_fulfilled function */ + ecma_value_t on_rejected, /**< on_rejected function */ + ecma_object_t *result_capability_obj_p) /**< promise capability */ +{ + JERRY_ASSERT (ecma_object_class_is (result_capability_obj_p, ECMA_OBJECT_CLASS_PROMISE_CAPABILITY)); + + ecma_promise_capability_t *capability_p = (ecma_promise_capability_t *) result_capability_obj_p; + + /* 3. boolean true indicates "identity" */ + if (!ecma_op_is_callable (on_fulfilled)) + { + on_fulfilled = ECMA_VALUE_TRUE; + } + + /* 4. boolean false indicates "thrower" */ + if (!ecma_op_is_callable (on_rejected)) + { + on_rejected = ECMA_VALUE_FALSE; + } + + ecma_object_t *promise_obj_p = ecma_get_object_from_value (promise); + ecma_promise_object_t *promise_p = (ecma_promise_object_t *) promise_obj_p; + + uint16_t flags = ecma_promise_get_flags (promise_obj_p); + + if (flags & ECMA_PROMISE_IS_PENDING) + { + /* 7. */ + /* [ capability, (on_fulfilled), (on_rejected) ] */ + ecma_value_t reaction_values[3]; + ecma_value_t *reactions_p = reaction_values + 1; + + uint8_t tag = 0; + + if (on_fulfilled != ECMA_VALUE_TRUE) + { + tag |= JMEM_FIRST_TAG_BIT_MASK; + *reactions_p++ = on_fulfilled; + } + + if (on_rejected != ECMA_VALUE_FALSE) + { + tag |= JMEM_SECOND_TAG_BIT_MASK; + *reactions_p++ = on_rejected; + } + + ECMA_SET_NON_NULL_POINTER_TAG (reaction_values[0], result_capability_obj_p, tag); + + uint32_t value_count = (uint32_t) (reactions_p - reaction_values); + ecma_collection_append (promise_p->reactions, reaction_values, value_count); + } + else if (flags & ECMA_PROMISE_IS_FULFILLED) + { + /* 8. */ + ecma_value_t value = ecma_promise_get_result (promise_obj_p); + ecma_enqueue_promise_reaction_job (ecma_make_object_value (result_capability_obj_p), on_fulfilled, value); + ecma_free_value (value); + } + else + { + /* 9. */ + ecma_value_t reason = ecma_promise_get_result (promise_obj_p); + ecma_enqueue_promise_reaction_job (ecma_make_object_value (result_capability_obj_p), on_rejected, reason); + ecma_free_value (reason); + } + + /* 10. */ + return ecma_copy_value (capability_p->header.u.cls.u3.promise); +} /* ecma_promise_perform_then */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-promise-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-promise-object.h new file mode 100644 index 0000000..b9fe92c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-promise-object.h @@ -0,0 +1,142 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_PROMISE_OBJECT_H +#define ECMA_PROMISE_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines + * @{ + */ + +/** + * The PromiseState of promise object. + */ +typedef enum +{ + ECMA_PROMISE_IS_PENDING = (1 << 0), /**< pending state */ + ECMA_PROMISE_IS_FULFILLED = (1 << 1), /**< fulfilled state */ + ECMA_PROMISE_ALREADY_RESOLVED = (1 << 2), /**< already resolved */ +} ecma_promise_flags_t; + +/** + * Description of a promise resolving function. + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object part */ + ecma_value_t promise; /**< [[Promise]] internal slot */ +} ecma_promise_resolver_t; + +/** + * Description of the promise object. + * It need more space than normal object to store builtin properties. + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object part */ + ecma_collection_t *reactions; /**< list of promise reactions */ +} ecma_promise_object_t; + +/** + * Description of the finally function object + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object part */ + ecma_value_t constructor; /**< [[Constructor]] internal slot */ + ecma_value_t on_finally; /**< [[OnFinally]] internal slot */ +} ecma_promise_finally_function_t; + +/** + * Description of the thunk function object + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object part */ + ecma_value_t value; /**< value thunk */ +} ecma_promise_value_thunk_t; + +/* The Promise reaction is a compressed structure, where each item can + * be a sequence of up to three ecma object values as seen below: + * + * [ Capability ][ Optional fulfilled callback ][ Optional rejected callback ] + * [ Async function callback ] + * + * The first member is an object, which lower bits specify the type of the reaction: + * bit 2 is not set: callback reactions + * The first two objects specify the resolve/reject functions of the promise + * returned by the `then` operation which can be used to chain event handlers. + * + * bit 0: has a fulfilled callback + * bit 1: has a rejected callback + * + * bit 2 is set: async function callback + */ + +bool ecma_is_promise (ecma_object_t *obj_p); +ecma_value_t ecma_op_create_promise_object (ecma_value_t executor, ecma_value_t parent, ecma_object_t *new_target_p); +uint8_t ecma_promise_get_flags (ecma_object_t *promise_p); +ecma_value_t ecma_promise_get_result (ecma_object_t *promise_p); +void ecma_reject_promise (ecma_value_t promise, ecma_value_t reason); +void ecma_fulfill_promise (ecma_value_t promise, ecma_value_t value); +ecma_value_t ecma_reject_promise_with_checks (ecma_value_t promise, ecma_value_t reason); +ecma_value_t ecma_fulfill_promise_with_checks (ecma_value_t promise, ecma_value_t value); +ecma_object_t *ecma_promise_new_capability (ecma_value_t constructor, ecma_value_t parent); +ecma_value_t ecma_promise_reject_or_resolve (ecma_value_t this_arg, ecma_value_t value, bool is_resolve); +ecma_value_t ecma_promise_then (ecma_value_t promise, ecma_value_t on_fulfilled, ecma_value_t on_rejected); + +ecma_value_t +ecma_value_thunk_helper_cb (ecma_object_t *function_obj_p, const ecma_value_t args_p[], const uint32_t args_count); +ecma_value_t +ecma_value_thunk_thrower_cb (ecma_object_t *function_obj_p, const ecma_value_t args_p[], const uint32_t args_count); +ecma_value_t +ecma_promise_then_finally_cb (ecma_object_t *function_obj_p, const ecma_value_t args_p[], const uint32_t args_count); +ecma_value_t +ecma_promise_catch_finally_cb (ecma_object_t *function_obj_p, const ecma_value_t args_p[], const uint32_t args_count); +ecma_value_t +ecma_promise_reject_handler (ecma_object_t *function_obj_p, const ecma_value_t argv[], const uint32_t args_count); +ecma_value_t +ecma_promise_resolve_handler (ecma_object_t *function_obj_p, const ecma_value_t argv[], const uint32_t args_count); +ecma_value_t ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, + const ecma_value_t args_p[], + const uint32_t args_count); +ecma_value_t ecma_op_get_capabilities_executor_cb (ecma_object_t *function_obj_p, + const ecma_value_t args_p[], + const uint32_t args_count); + +ecma_value_t ecma_promise_finally (ecma_value_t promise, ecma_value_t on_finally); +void ecma_promise_async_then (ecma_value_t promise, ecma_value_t executable_object); +ecma_value_t ecma_promise_async_await (ecma_extended_object_t *async_generator_object_p, ecma_value_t value); +ecma_value_t ecma_promise_run_executor (ecma_object_t *promise_p, ecma_value_t executor, ecma_value_t this_value); +ecma_value_t ecma_op_if_abrupt_reject_promise (ecma_value_t *value_p, ecma_object_t *capability_obj_p); + +uint32_t ecma_promise_remaining_inc_or_dec (ecma_value_t remaining, bool is_inc); + +ecma_value_t ecma_promise_perform_then (ecma_value_t promise, + ecma_value_t on_fulfilled, + ecma_value_t on_rejected, + ecma_object_t *result_capability_obj_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_PROMISE_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-proxy-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-proxy-object.cpp new file mode 100644 index 0000000..7b26978 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-proxy-object.cpp @@ -0,0 +1,1875 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-proxy-object.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-handlers.h" +#include "ecma-builtin-object.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaproxyobject ECMA Proxy object related routines + * @{ + */ + +#if JERRY_BUILTIN_PROXY +/** + * ProxyCreate operation for create a new proxy object + * + * See also: + * ES2015 9.5.15 + * ES11+: 9.5.14 ProxyCreate + * + * @return created Proxy object as an ecma-value - if success + * raised error - otherwise + */ +ecma_object_t * +ecma_proxy_create (ecma_value_t target, /**< proxy target */ + ecma_value_t handler, /**< proxy handler */ + uint32_t options) /**< ecma_proxy_flag_types_t option bits */ +{ + /* ES2015: 1, 3. */ + /* ES11+: 1 - 2. */ + if (!ecma_is_value_object (target) || !ecma_is_value_object (handler)) + { + ecma_raise_type_error (ECMA_ERR_CANNOT_CREATE_PROXY); + return NULL; + } + + /* ES2015: 5 - 6. */ + /* ES11+: 3 - 4. */ + /* A Proxy does not have [[Prototype]] value as per standard */ + ecma_object_t *obj_p = ecma_create_object (NULL, sizeof (ecma_proxy_object_t), ECMA_OBJECT_TYPE_PROXY); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + obj_p->u2.prototype_cp = (jmem_cpointer_t) options; + + /* ES2015: 7. */ + /* ES11+: 5. */ + if (ecma_op_is_callable (target)) + { + obj_p->u2.prototype_cp |= ECMA_PROXY_IS_CALLABLE; + + /* ES2015: 7.b. */ + /* ES11+: 5.b. */ + if (ecma_is_constructor (target)) + { + obj_p->u2.prototype_cp |= ECMA_PROXY_IS_CONSTRUCTABLE; + } + } + + /* ES2015: 8. */ + /* ES11+: 6. */ + proxy_obj_p->target = target; + + /* ES2015: 9. */ + /* ES11+: 7. */ + proxy_obj_p->handler = handler; + + /* ES2015: 10. */ + /* ES11+: 8 */ + return obj_p; +} /* ecma_proxy_create */ + +/** + * Definition of Proxy Revocation Function + * + * See also: + * ES2015 26.2.2.1.1 + * + * @return ECMA_VALUE_UNDEFINED + */ +ecma_value_t +ecma_proxy_revoke_cb (ecma_object_t *function_obj_p, /**< function object */ + const ecma_value_t args_p[], /**< argument list */ + const uint32_t args_count) /**< argument number */ +{ + JERRY_UNUSED_2 (args_p, args_count); + + /* 1. */ + ecma_revocable_proxy_object_t *rev_proxy_p = (ecma_revocable_proxy_object_t *) function_obj_p; + + /* 2. */ + if (ecma_is_value_null (rev_proxy_p->proxy)) + { + return ECMA_VALUE_UNDEFINED; + } + + /* 4. */ + ecma_proxy_object_t *proxy_p = (ecma_proxy_object_t *) ecma_get_object_from_value (rev_proxy_p->proxy); + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY ((ecma_object_t *) proxy_p)); + + /* 3. */ + rev_proxy_p->proxy = ECMA_VALUE_NULL; + + /* 5. */ + proxy_p->target = ECMA_VALUE_NULL; + + /* 6. */ + proxy_p->handler = ECMA_VALUE_NULL; + + /* 7. */ + return ECMA_VALUE_UNDEFINED; +} /* ecma_proxy_revoke_cb */ + +/** + * Proxy.revocable operation for create a new revocable proxy object + * + * See also: + * ES2015 26.2.2.1 + * + * @return NULL - if the operation fails + * pointer to the newly created revocable proxy object - otherwise + */ +ecma_object_t * +ecma_proxy_create_revocable (ecma_value_t target, /**< target argument */ + ecma_value_t handler) /**< handler argument */ +{ + /* 1. */ + ecma_object_t *proxy_p = ecma_proxy_create (target, handler, 0); + + /* 2. */ + if (proxy_p == NULL) + { + return proxy_p; + } + + ecma_value_t proxy_value = ecma_make_object_value (proxy_p); + + /* 3. */ + ecma_object_t *func_obj_p; + func_obj_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROXY_REVOKE, sizeof (ecma_revocable_proxy_object_t)); + + /* 4. */ + ecma_revocable_proxy_object_t *rev_proxy_p = (ecma_revocable_proxy_object_t *) func_obj_p; + rev_proxy_p->proxy = proxy_value; + + ecma_property_value_t *prop_value_p; + ecma_value_t revoker = ecma_make_object_value (func_obj_p); + + /* 5. */ + ecma_object_t *obj_p = + ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), 0, ECMA_OBJECT_TYPE_GENERAL); + + /* 6. */ + prop_value_p = ecma_create_named_data_property (obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_PROXY), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + prop_value_p->value = proxy_value; + + /* 7. */ + prop_value_p = ecma_create_named_data_property (obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_REVOKE), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + prop_value_p->value = revoker; + + ecma_deref_object (proxy_p); + ecma_deref_object (func_obj_p); + + /* 8. */ + return obj_p; +} /* ecma_proxy_create_revocable */ + +/** + * Internal find property operation for Proxy object + * + * Note: Returned value must be freed with ecma_free_value. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_NOT_FOUND - if the property is not found + * value of the property - otherwise + */ +ecma_value_t +ecma_proxy_object_find (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p) /**< property name */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + + ecma_value_t has_result = ecma_proxy_object_has (obj_p, prop_name_p); + + if (ECMA_IS_VALUE_ERROR (has_result)) + { + return has_result; + } + + if (ecma_is_value_false (has_result)) + { + return ECMA_VALUE_NOT_FOUND; + } + + return ecma_proxy_object_get (obj_p, prop_name_p, ecma_make_object_value (obj_p)); +} /* ecma_proxy_object_find */ + +/** + * Helper method for validate the proxy object + * + * @return proxy trap - if the validation is successful + * ECMA_VALUE_ERROR - otherwise + */ +static ecma_value_t +ecma_validate_proxy_object (ecma_value_t handler, /**< proxy handler */ + lit_magic_string_id_t magic_id) /**< routine magic id */ +{ + if (ecma_is_value_null (handler)) + { + return ecma_raise_type_error (ECMA_ERR_HANDLER_CANNOT_BE_NULL); + } + + JERRY_ASSERT (ecma_is_value_object (handler)); + + return ecma_op_get_method_by_magic_id (handler, magic_id); +} /* ecma_validate_proxy_object */ + +/* Internal operations */ + +/** + * The Proxy object [[GetPrototypeOf]] internal routine + * + * See also: + * ECMAScript v6, 9.5.1 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_NULL or valid object (prototype) otherwise + */ +ecma_value_t +ecma_proxy_object_get_prototype_of (ecma_object_t *obj_p) /**< proxy object */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 1. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 2-5. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 7. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_builtin_object_object_get_prototype_of (target_obj_p); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + + /* 8. */ + ecma_value_t handler_proto = ecma_op_function_call (func_obj_p, handler, &target, 1); + + ecma_deref_object (func_obj_p); + + /* 9. */ + if (ECMA_IS_VALUE_ERROR (handler_proto)) + { + return handler_proto; + } + + /* 10. */ + if (!ecma_is_value_object (handler_proto) && !ecma_is_value_null (handler_proto)) + { + ecma_free_value (handler_proto); + + return ecma_raise_type_error (ECMA_ERR_TRAP_RETURNED_NEITHER_OBJECT_NOR_NULL); + } + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + return handler_proto; + } + + /* 11. */ + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + /* 12. */ + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + ecma_free_value (handler_proto); + + return extensible_target; + } + + /* 13. */ + if (ecma_is_value_true (extensible_target)) + { + return handler_proto; + } + + /* 14. */ + ecma_value_t target_proto = ecma_builtin_object_object_get_prototype_of (target_obj_p); + + /* 15. */ + if (ECMA_IS_VALUE_ERROR (target_proto)) + { + return target_proto; + } + + ecma_value_t ret_value = handler_proto; + + /* 16. */ + if (handler_proto != target_proto) + { + ecma_free_value (handler_proto); + + ret_value = ecma_raise_type_error (ECMA_ERR_TARGET_NOT_EXTENSIBLE_NOT_RETURNED_ITS_PROTOTYPE); + } + + ecma_free_value (target_proto); + + /* 17. */ + return ret_value; +} /* ecma_proxy_object_get_prototype_of */ + +/** + * The Proxy object [[SetPrototypeOf]] internal routine + * + * See also: + * ECMAScript v6, 9.5.2 + * ECMAScript v11: 9.5.2 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the new prototype can be set for the given object + */ +ecma_value_t +ecma_proxy_object_set_prototype_of (ecma_object_t *obj_p, /**< proxy object */ + ecma_value_t proto) /**< new prototype object */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + /* 1. */ + JERRY_ASSERT (ecma_is_value_object (proto) || ecma_is_value_null (proto)); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL); + + /* 7.*/ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + if (ECMA_OBJECT_IS_PROXY (target_obj_p)) + { + ecma_value_t result = ecma_proxy_object_set_prototype_of (target_obj_p, proto); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_value_t result = ecma_op_ordinary_object_set_prototype_of (target_obj_p, proto); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t args[] = { target, proto }; + + /* 9. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 2); + + ecma_deref_object (func_obj_p); + + /* 10. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + /* ES11: 9 */ + if (!boolean_trap_result) + { + return ecma_make_boolean_value (false); + } + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + return ecma_make_boolean_value (boolean_trap_result); + } + + /* 11. */ + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + /* 12. */ + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + return extensible_target; + } + + /* 13. */ + if (ecma_is_value_true (extensible_target)) + { + return ecma_make_boolean_value (boolean_trap_result); + } + + /* 14. */ + ecma_value_t target_proto = ecma_builtin_object_object_get_prototype_of (target_obj_p); + + /* 15. */ + if (ECMA_IS_VALUE_ERROR (target_proto)) + { + return target_proto; + } + + ecma_value_t ret_value = ecma_make_boolean_value (boolean_trap_result); + + /* 16. */ + if (boolean_trap_result && (target_proto != proto)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_TARGET_NOT_EXTENSIBLE_DIFFERENT_PROTOTYPE_RETURNED); + } + + ecma_free_value (target_proto); + + /* 17. */ + return ret_value; +} /* ecma_proxy_object_set_prototype_of */ + +/** + * The Proxy object [[isExtensible]] internal routine + * + * See also: + * ECMAScript v6, 9.5.3 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the object is extensible + */ +ecma_value_t +ecma_proxy_object_is_extensible (ecma_object_t *obj_p) /**< proxy object */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 1. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 2-5. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_IS_EXTENSIBLE); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 7. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_builtin_object_object_is_extensible (target_obj_p); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + + /* 8. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, &target, 1); + + ecma_deref_object (func_obj_p); + + /* 9. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + return ecma_make_boolean_value (boolean_trap_result); + } + + bool target_result; + + /* 10. */ + if (ECMA_OBJECT_IS_PROXY (target_obj_p)) + { + ecma_value_t proxy_is_ext = ecma_proxy_object_is_extensible (target_obj_p); + + if (ECMA_IS_VALUE_ERROR (proxy_is_ext)) + { + return proxy_is_ext; + } + + target_result = ecma_is_value_true (proxy_is_ext); + } + else + { + target_result = ecma_op_ordinary_object_is_extensible (target_obj_p); + } + + /* 12. */ + if (boolean_trap_result != target_result) + { + return ecma_raise_type_error (ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_EXTENSIBILITY); + } + + return ecma_make_boolean_value (boolean_trap_result); +} /* ecma_proxy_object_is_extensible */ + +/** + * The Proxy object [[PreventExtensions]] internal routine + * + * See also: + * ECMAScript v6, 9.5.4 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the object can be set as inextensible + */ +ecma_value_t +ecma_proxy_object_prevent_extensions (ecma_object_t *obj_p) /**< proxy object */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 1. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 2-5. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 7. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t ret_value = ecma_builtin_object_object_prevent_extensions (target_obj_p); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + return ret_value; + } + + ecma_deref_object (target_obj_p); + + return ECMA_VALUE_TRUE; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + + /* 8. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, &target, 1); + + ecma_deref_object (func_obj_p); + + /* 9. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + /* 10. */ + if (boolean_trap_result && !(obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION)) + { + ecma_value_t target_is_ext = ecma_builtin_object_object_is_extensible (target_obj_p); + + if (ECMA_IS_VALUE_ERROR (target_is_ext)) + { + return target_is_ext; + } + + if (ecma_is_value_true (target_is_ext)) + { + return ecma_raise_type_error (ECMA_ERR_TRAP_RESULT_NOT_REFLECT_TARGET_INEXTENSIBILITY); + } + } + + /* 11. */ + return ecma_make_boolean_value (boolean_trap_result); +} /* ecma_proxy_object_prevent_extensions */ + +/** + * The Proxy object [[GetOwnProperty]] internal routine + * + * See also: + * ECMAScript v6, 9.5.5 + * + * Note: - Returned value is always a simple value so freeing it is unnecessary. + * - If the operation does not fail, freeing the filled property descriptor is the caller's responsibility + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE_FALSE} - depends on whether object has property with the given name + */ +ecma_value_t +ecma_proxy_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p, /**< property name */ + ecma_property_descriptor_t *prop_desc_p) /**< [out] property + * descriptor */ +{ + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL); + + ecma_value_t target = proxy_obj_p->target; + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, prop_desc_p); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t prop_value = ecma_make_prop_name_value (prop_name_p); + ecma_value_t args[] = { target, prop_value }; + + /* 9. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 2); + ecma_deref_object (func_obj_p); + + /* 10. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + /* 11. */ + if (!ecma_is_value_object (trap_result) && !ecma_is_value_undefined (trap_result)) + { + ecma_free_value (trap_result); + return ecma_raise_type_error (ECMA_ERR_TRAP_IS_NEITHER_AN_OBJECT_NOR_UNDEFINED); + } + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + if (ecma_is_value_undefined (trap_result)) + { + return ECMA_VALUE_FALSE; + } + + ecma_value_t result_val = ecma_op_to_property_descriptor (trap_result, prop_desc_p); + ecma_free_value (trap_result); + + if (ECMA_IS_VALUE_ERROR (result_val)) + { + return result_val; + } + + ecma_op_to_complete_property_descriptor (prop_desc_p); + return ECMA_VALUE_TRUE; + } + + /* 12. */ + ecma_property_descriptor_t target_desc; + ecma_value_t target_status = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, &target_desc); + + /* 13. */ + if (ECMA_IS_VALUE_ERROR (target_status)) + { + ecma_free_value (trap_result); + return target_status; + } + + /* 14. */ + if (ecma_is_value_undefined (trap_result)) + { + /* .a */ + if (ecma_is_value_false (target_status)) + { + return ECMA_VALUE_FALSE; + } + /* .b */ + if (!(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE)) + { + ecma_free_property_descriptor (&target_desc); + return ecma_raise_type_error (ECMA_ERR_GIVEN_PROPERTY_IS_A_NON_CONFIGURABLE); + } + + /* .c */ + ecma_free_property_descriptor (&target_desc); + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + /* .d */ + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + return extensible_target; + } + + /* .e */ + JERRY_ASSERT (ecma_is_value_boolean (extensible_target)); + + /* .f */ + if (ecma_is_value_false (extensible_target)) + { + return ecma_raise_type_error (ECMA_ERR_TARGET_NOT_EXTENSIBLE); + } + + /* .g */ + return ECMA_VALUE_FALSE; + } + + /* 15. */ + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + /* 16. */ + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + if (ecma_is_value_true (target_status)) + { + ecma_free_property_descriptor (&target_desc); + } + ecma_free_value (trap_result); + return extensible_target; + } + + /* 17, 19 */ + ecma_value_t result_val = ecma_op_to_property_descriptor (trap_result, prop_desc_p); + + ecma_op_to_complete_property_descriptor (prop_desc_p); + ecma_free_value (trap_result); + + /* 18. */ + if (ECMA_IS_VALUE_ERROR (result_val)) + { + if (ecma_is_value_true (target_status)) + { + ecma_free_property_descriptor (&target_desc); + } + return result_val; + } + + /* 20. */ + bool is_extensible = ecma_is_value_true (extensible_target); + + bool is_valid = ecma_op_is_compatible_property_descriptor (prop_desc_p, + (ecma_is_value_true (target_status) ? &target_desc : NULL), + is_extensible); + + bool target_has_desc = ecma_is_value_true (target_status); + bool target_is_writable = (target_desc.flags & JERRY_PROP_IS_WRITABLE); + bool target_is_configurable = false; + + if (target_has_desc) + { + target_is_configurable = ((target_desc.flags & JERRY_PROP_IS_CONFIGURABLE) != 0); + ecma_free_property_descriptor (&target_desc); + } + + /* 21. */ + if (!is_valid) + { + ecma_free_property_descriptor (prop_desc_p); + return ecma_raise_type_error (ECMA_ERR_THE_TWO_DESCRIPTORS_ARE_INCOMPATIBLE); + } + + /* 22. */ + else if (!(prop_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE)) + { + const uint16_t mask = (JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_WRITABLE); + + if (!target_has_desc || target_is_configurable + || ((prop_desc_p->flags & mask) == JERRY_PROP_IS_WRITABLE_DEFINED && target_is_writable)) + { + ecma_free_property_descriptor (prop_desc_p); + return ecma_raise_type_error (ECMA_ERR_THE_TWO_DESCRIPTORS_ARE_INCOMPATIBLE); + } + } + return ECMA_VALUE_TRUE; +} /* ecma_proxy_object_get_own_property_descriptor */ + +/** + * The Proxy object [[DefineOwnProperty]] internal routine + * + * See also: + * ECMAScript v6, 9.5.6 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE_FALSE} - depends on whether the property can be defined for the given object + */ +ecma_value_t +ecma_proxy_object_define_own_property (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p, /**< property name */ + const ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_DEFINE_PROPERTY_UL); + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_op_object_define_own_property (target_obj_p, prop_name_p, prop_desc_p); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + /* 9. */ + ecma_object_t *desc_obj = ecma_op_from_property_descriptor (prop_desc_p); + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t prop_value = ecma_make_prop_name_value (prop_name_p); + ecma_value_t desc_obj_value = ecma_make_object_value (desc_obj); + ecma_value_t args[] = { target, prop_value, desc_obj_value }; + + /* 10. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 3); + + ecma_deref_object (func_obj_p); + ecma_deref_object (desc_obj); + + /* 11. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + /* 12. */ + if (!boolean_trap_result) + { + return ECMA_VALUE_FALSE; + } + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + return ECMA_VALUE_TRUE; + } + + /* 13. */ + ecma_property_descriptor_t target_desc; + + ecma_value_t status = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, &target_desc); + + /* 14. */ + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + bool target_prop_found = ecma_is_value_true (status); + + /* 15. */ + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + bool is_target_ext = ecma_is_value_true (extensible_target); + + /* 16. */ + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + if (target_prop_found) + { + ecma_free_property_descriptor (&target_desc); + } + + return extensible_target; + } + + /* 17. */ + bool setting_config_false = + ((prop_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED) && !(prop_desc_p->flags & JERRY_PROP_IS_CONFIGURABLE)); + + /* 19. */ + if (!target_prop_found) + { + if (!is_target_ext) + { + return ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_ADDING_PROPERTY_NON_EXTENSIBLE_TARGET); + } + + if (setting_config_false) + { + return ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY); + } + } + /* 20. */ + else + { + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + if (!ecma_op_is_compatible_property_descriptor (prop_desc_p, &target_desc, is_target_ext)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_ADD_PROPERTY_INCOMPATIBLE_OTHER_PROP); + } + else if (setting_config_false && (target_desc.flags & JERRY_PROP_IS_CONFIGURABLE)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY); + } + /* ES11: 16.c */ + else if ((target_desc.flags & (JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED)) != 0 + && (prop_desc_p->flags & (JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_WRITABLE)) + == JERRY_PROP_IS_WRITABLE_DEFINED + && (target_desc.flags & (JERRY_PROP_IS_WRITABLE | JERRY_PROP_IS_CONFIGURABLE)) == JERRY_PROP_IS_WRITABLE) + + { + ret_value = ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_DEFINING_NON_EXISTENT_PROPERTY); + } + + ecma_free_property_descriptor (&target_desc); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + return ret_value; + } + } + + return ECMA_VALUE_TRUE; +} /* ecma_proxy_object_define_own_property */ + +/** + * The Proxy object [[HasProperty]] internal routine + * + * See also: + * ECMAScript v6, 9.5.7 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE_FALSE} - depends on whether the property is found + */ +ecma_value_t +ecma_proxy_object_has (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p) /**< property name */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_HAS); + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_op_object_has_property (target_obj_p, prop_name_p); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t prop_value = ecma_make_prop_name_value (prop_name_p); + ecma_value_t args[] = { target, prop_value }; + + /* 9. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 2); + + ecma_deref_object (func_obj_p); + + /* 10. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + /* 11. */ + if (!boolean_trap_result && !(obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION)) + { + ecma_property_descriptor_t target_desc; + + ecma_value_t status = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, &target_desc); + + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + if (ecma_is_value_true (status)) + { + bool prop_is_configurable = target_desc.flags & JERRY_PROP_IS_CONFIGURABLE; + + ecma_free_property_descriptor (&target_desc); + + if (!prop_is_configurable) + { + return ecma_raise_type_error (ECMA_ERR_TRAP_FALSISH_PROPERTY_NON_CONFIGURABLE); + } + + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + return extensible_target; + } + + if (ecma_is_value_false (extensible_target)) + { + return ecma_raise_type_error (ECMA_ERR_TRAP_FALSISH_PROPERTY_TARGET_NOT_EXTENSIBLE); + } + } + } + + /* 12. */ + return ecma_make_boolean_value (boolean_trap_result); +} /* ecma_proxy_object_has */ + +/** + * The Proxy object [[Get]] internal routine + * + * See also: + * ECMAScript v6, 9.5.8 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * value of the given named data property or the result of the getter function call - otherwise + */ +ecma_value_t +ecma_proxy_object_get (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p, /**< property name */ + ecma_value_t receiver) /**< receiver to invoke getter function */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_GET); + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + ecma_object_t *target_obj_p = ecma_get_object_from_value (proxy_obj_p->target); + ecma_value_t result = ecma_op_object_get_with_receiver (target_obj_p, prop_name_p, receiver); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t prop_value = ecma_make_prop_name_value (prop_name_p); + ecma_value_t args[] = { proxy_obj_p->target, prop_value, receiver }; + + /* 9. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 3); + + ecma_deref_object (func_obj_p); + + /* 10. */ + if (ECMA_IS_VALUE_ERROR (trap_result) || (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION)) + { + return trap_result; + } + + /* 11. */ + ecma_property_descriptor_t target_desc; + ecma_value_t status = ecma_op_get_own_property_descriptor (proxy_obj_p->target, prop_name_p, &target_desc); + + /* 12. */ + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_free_value (trap_result); + return status; + } + + /* 13. */ + if (ecma_is_value_true (status)) + { + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + if ((target_desc.flags & JERRY_PROP_IS_VALUE_DEFINED) && !(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE) + && !(target_desc.flags & JERRY_PROP_IS_WRITABLE) && !ecma_op_same_value (trap_result, target_desc.value)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_INCORRECT_RETURN_PROXY_GET_TRAP); + } + else if (!(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE) + && (target_desc.flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + && target_desc.get_p == NULL && !ecma_is_value_undefined (trap_result)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_PROXY_PROPERTY_NOT_CONFIGURABLE_NOT_HAVE_GETTER); + } + + ecma_free_property_descriptor (&target_desc); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_free_value (trap_result); + + return ret_value; + } + } + + /* 14. */ + return trap_result; +} /* ecma_proxy_object_get */ + +/** + * The Proxy object [[Set]] internal routine + * + * See also: + * ECMAScript v6, 9.5.9 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the property can be set to the given object + */ +ecma_value_t +ecma_proxy_object_set (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p, /**< property name */ + ecma_value_t value, /**< value to set */ + ecma_value_t receiver, /**< receiver to invoke setter function */ + bool is_strict) /**< indicate strict mode */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_SET); + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_op_object_put_with_receiver (target_obj_p, prop_name_p, value, receiver, is_strict); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t prop_name_value = ecma_make_prop_name_value (prop_name_p); + ecma_value_t args[] = { target, prop_name_value, value, receiver }; + + /* 9. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 4); + + ecma_deref_object (func_obj_p); + + /* 10. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + /* 11. */ + if (!boolean_trap_result) + { + if (is_strict) + { + return ecma_raise_type_error (ECMA_ERR_PROXY_TRAP_RETURNED_FALSISH); + } + + return ECMA_VALUE_FALSE; + } + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + return ECMA_VALUE_TRUE; + } + + /* 12. */ + ecma_property_descriptor_t target_desc; + + ecma_value_t status = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, &target_desc); + + /* 13. */ + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + /* 14. */ + if (ecma_is_value_true (status)) + { + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + if ((target_desc.flags & JERRY_PROP_IS_VALUE_DEFINED) && !(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE) + && !(target_desc.flags & JERRY_PROP_IS_WRITABLE) && !ecma_op_same_value (value, target_desc.value)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_INCORRECT_RETURN_PROXY_SET_TRAP); + } + else if (!(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE) + && (target_desc.flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + && target_desc.set_p == NULL) + { + ret_value = ecma_raise_type_error (ECMA_ERR_TARGET_PROPERTY_CONFIGURE_ACCESSOR_WITHOUT_SETTER); + } + + ecma_free_property_descriptor (&target_desc); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + return ret_value; + } + } + + /* 15. */ + return ECMA_VALUE_TRUE; +} /* ecma_proxy_object_set */ + +/** + * The Proxy object [[Delete]] internal routine + * + * See also: + * ECMAScript v6, 9.5.10 + * + * Note: Returned value is always a simple value so freeing it is unnecessary. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_{TRUE/FALSE} - depends on whether the property can be deleted + */ +ecma_value_t +ecma_proxy_object_delete_property (ecma_object_t *obj_p, /**< proxy object */ + ecma_string_t *prop_name_p, /**< property name */ + bool is_strict) /**< delete in strict mode? */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 2. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 3-6.*/ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_DELETE_PROPERTY_UL); + + /* 7. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 8. */ + if (ecma_is_value_undefined (trap)) + { + ecma_value_t result = ecma_op_object_delete (target_obj_p, prop_name_p, is_strict); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t prop_name_value = ecma_make_prop_name_value (prop_name_p); + ecma_value_t args[] = { target, prop_name_value }; + + /* 9. */ + ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 2); + + ecma_deref_object (func_obj_p); + + /* 10. */ + if (ECMA_IS_VALUE_ERROR (trap_result)) + { + return trap_result; + } + + bool boolean_trap_result = ecma_op_to_boolean (trap_result); + + ecma_free_value (trap_result); + + /* 11. */ + if (!boolean_trap_result) + { + return ECMA_VALUE_FALSE; + } + + if (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION) + { + return ECMA_VALUE_TRUE; + } + + /* 12. */ + ecma_property_descriptor_t target_desc; + + ecma_value_t status = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, &target_desc); + + /* 13. */ + if (ECMA_IS_VALUE_ERROR (status)) + { + return status; + } + + /* 14. */ + if (ecma_is_value_false (status)) + { + return ECMA_VALUE_TRUE; + } + + ecma_value_t ret_value = ECMA_VALUE_TRUE; + + /* 15. */ + if (!(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_PROPERTY_NON_CONFIGURABLE); + } + /* ES11: 13-14 */ + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + if (!ecma_is_value_true (extensible_target)) + { + ret_value = ecma_raise_type_error (ECMA_ERR_TRAP_TRUISH_TARGET_NOT_EXTENSIBLE); + } + + ecma_free_property_descriptor (&target_desc); + + /* 16. */ + return ret_value; +} /* ecma_proxy_object_delete_property */ + +/** + * Helper method for the Proxy object [[OwnPropertyKeys]] operation + * + * See also: + * ECMAScript v6, 9.5.12 steps 21. 23. + * + * @return ECMA_VALUE_ERROR - if a target key is not in the unchecked_result_keys collection + * ECMA_VALUE_EMPTY - otherwise + */ +static ecma_value_t +ecma_proxy_object_own_property_keys_helper (ecma_collection_t *target_collection, /**< target keys */ + ecma_collection_t *unchecked_result_keys, /**< unchecked keys */ + uint32_t *counter) /**< unchecked property counter */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + for (uint32_t i = 0; i < target_collection->item_count; i++) + { + ecma_string_t *current_prop_name = ecma_get_prop_name_from_value (target_collection->buffer_p[i]); + + ret_value = ECMA_VALUE_ERROR; + + for (uint32_t j = 0; j < unchecked_result_keys->item_count; j++) + { + if (ecma_is_value_empty (unchecked_result_keys->buffer_p[j])) + { + continue; + } + + ecma_string_t *unchecked_prop_name = ecma_get_prop_name_from_value (unchecked_result_keys->buffer_p[j]); + + if (ecma_compare_ecma_strings (current_prop_name, unchecked_prop_name)) + { + ecma_deref_ecma_string (unchecked_prop_name); + ret_value = ECMA_VALUE_EMPTY; + unchecked_result_keys->buffer_p[j] = ECMA_VALUE_EMPTY; + (*counter)++; + } + } + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + break; + } + } + + return ret_value; +} /* ecma_proxy_object_own_property_keys_helper */ + +/** + * Helper method for checking the invariants in the Proxy object [[OwnPropertyKeys]] operation + * + * See also: + * ECMAScript v6, 9.5.12 steps 20-25. + * + * @return true - if none of the invariants got violated + * false - otherwise + */ +static bool +ecma_proxy_check_invariants_for_own_prop_keys (ecma_collection_t *trap_result, + ecma_collection_t *target_non_configurable_keys, + ecma_collection_t *target_configurable_keys, + ecma_value_t extensible_target) +{ + /* 20. */ + ecma_collection_t *unchecked_result_keys = ecma_new_collection (); + + ecma_collection_append (unchecked_result_keys, trap_result->buffer_p, trap_result->item_count); + + for (uint32_t i = 0; i < unchecked_result_keys->item_count; i++) + { + ecma_string_t *unchecked_prop_name = ecma_get_prop_name_from_value (unchecked_result_keys->buffer_p[i]); + ecma_ref_ecma_string (unchecked_prop_name); + } + + bool check_ok = false; + uint32_t unchecked_prop_name_counter = 0; + + /* 21. */ + if (ECMA_IS_VALUE_ERROR (ecma_proxy_object_own_property_keys_helper (target_non_configurable_keys, + unchecked_result_keys, + &unchecked_prop_name_counter))) + { + ecma_raise_type_error (ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_NON_CONFIGURABLE_KEYS); + } + /* 22. */ + else if (ecma_is_value_true (extensible_target)) + { + check_ok = true; + } + /* 23. */ + else if (ECMA_IS_VALUE_ERROR (ecma_proxy_object_own_property_keys_helper (target_configurable_keys, + unchecked_result_keys, + &unchecked_prop_name_counter))) + { + ecma_raise_type_error (ECMA_ERR_TRAP_RESULT_NOT_INCLUDE_ALL_CONFIGURABLE_KEYS); + } + /* 24. */ + else if (unchecked_result_keys->item_count != unchecked_prop_name_counter) + { + ecma_raise_type_error (ECMA_ERR_TRAP_EXTRA_KEYS_FOR_A_NON_EXTENSIBLE_TARGET); + } + /* 25. */ + else + { + check_ok = true; + } + + ecma_collection_free (unchecked_result_keys); + + return check_ok; +} /* ecma_proxy_check_invariants_for_own_prop_keys */ + +/** + * The Proxy object [[OwnPropertyKeys]] internal routine + * + * See also: + * ECMAScript v11, 9.5.11 + * + * Note: If the returned collection is not NULL, it must be freed with + * ecma_collection_free if it is no longer needed + * + * @return NULL - if the operation fails + * pointer to a newly allocated list of property names - otherwise + */ +ecma_collection_t * +ecma_proxy_object_own_property_keys (ecma_object_t *obj_p) /**< proxy object */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE_RETURN (NULL); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 1. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 2-5. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_OWN_KEYS_UL); + + if (ECMA_IS_VALUE_ERROR (trap)) + { + return NULL; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 6. */ + if (ecma_is_value_undefined (trap)) + { + ecma_collection_t *result = ecma_op_object_own_property_keys (target_obj_p, JERRY_PROPERTY_FILTER_ALL); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + + /* 7. */ + ecma_value_t trap_result_array = ecma_op_function_call (func_obj_p, handler, &target, 1); + + ecma_deref_object (func_obj_p); + + if (ECMA_IS_VALUE_ERROR (trap_result_array)) + { + return NULL; + } + + /* 8. */ + ecma_collection_t *trap_result = ecma_op_create_list_from_array_like (trap_result_array, true); + + ecma_free_value (trap_result_array); + + if (trap_result == NULL || (obj_p->u2.prototype_cp & JERRY_PROXY_SKIP_RESULT_VALIDATION)) + { + return trap_result; + } + + /* 9. */ + if (ecma_collection_check_duplicated_entries (trap_result)) + { + ecma_collection_free (trap_result); + ecma_raise_type_error (ECMA_ERR_TRAP_WITH_DUPLICATED_ENTRIES); + return NULL; + } + + /* 10. */ + ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p); + + if (ECMA_IS_VALUE_ERROR (extensible_target)) + { + ecma_collection_free (trap_result); + return NULL; + } + + /* 11. */ + ecma_collection_t *target_keys = ecma_op_object_own_property_keys (target_obj_p, JERRY_PROPERTY_FILTER_ALL); + + if (target_keys == NULL) + { + ecma_collection_free (trap_result); + return target_keys; + } + + /* 14. */ + ecma_collection_t *target_configurable_keys = ecma_new_collection (); + + /* 15. */ + ecma_collection_t *target_non_configurable_keys = ecma_new_collection (); + + ecma_collection_t *ret_value = NULL; + + /* 16. */ + for (uint32_t i = 0; i < target_keys->item_count; i++) + { + ecma_property_descriptor_t target_desc; + + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (target_keys->buffer_p[i]); + + ecma_value_t status = ecma_op_object_get_own_property_descriptor (target_obj_p, prop_name_p, &target_desc); + + if (ECMA_IS_VALUE_ERROR (status)) + { + ecma_collection_free (trap_result); + goto free_target_collections; + } + + ecma_value_t prop_value = ecma_make_prop_name_value (prop_name_p); + + if (ecma_is_value_true (status) && !(target_desc.flags & JERRY_PROP_IS_CONFIGURABLE)) + { + ecma_collection_push_back (target_non_configurable_keys, prop_value); + } + else + { + ecma_collection_push_back (target_configurable_keys, prop_value); + } + + if (ecma_is_value_true (status)) + { + ecma_free_property_descriptor (&target_desc); + } + } + + /* 17. */ + if (ecma_is_value_true (extensible_target) && target_non_configurable_keys->item_count == 0) + { + ret_value = trap_result; + } + /* 18-22. */ + else if (ecma_proxy_check_invariants_for_own_prop_keys (trap_result, + target_non_configurable_keys, + target_configurable_keys, + extensible_target)) + { + ret_value = trap_result; + } + else + { + JERRY_ASSERT (ret_value == NULL); + ecma_collection_free (trap_result); + } + +free_target_collections: + ecma_collection_destroy (target_keys); + ecma_collection_free (target_configurable_keys); + ecma_collection_free (target_non_configurable_keys); + + /* 23. */ + return ret_value; +} /* ecma_proxy_object_own_property_keys */ + +/** + * The Proxy object [[Call]] internal routine + * + * See also: + * ECMAScript v6, 9.5.13 + * + * Note: Returned value must be freed with ecma_free_value. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * result of the function call - otherwise + */ +ecma_value_t +ecma_proxy_object_call (ecma_object_t *obj_p, /**< proxy object */ + ecma_value_t this_argument, /**< this argument to invoke the function */ + const ecma_value_t *args_p, /**< argument list */ + uint32_t argc) /**< number of arguments */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + + if (!ecma_op_proxy_object_is_callable (obj_p)) + { + return ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION); + } + + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 1. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 2-5.*/ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_APPLY); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + + /* 7. */ + if (ecma_is_value_undefined (trap)) + { + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + ecma_value_t result = ecma_op_function_call (target_obj_p, this_argument, args_p, argc); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + /* 8. */ + ecma_value_t args_array = ecma_op_new_array_object_from_buffer (args_p, argc); + ecma_value_t value_array[] = { target, this_argument, args_array }; + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + /* 9. */ + ecma_value_t ret_value = ecma_op_function_call (func_obj_p, handler, value_array, 3); + ecma_deref_object (func_obj_p); + ecma_free_object (args_array); + + return ret_value; +} /* ecma_proxy_object_call */ + +/** + * The Proxy object [[Construct]] internal routine + * + * See also: + * ECMAScript v6, 9.5.14 + * + * Note: Returned value must be freed with ecma_free_value. + * + * @return ECMA_VALUE_ERROR - if the operation fails + * result of the construct call - otherwise + */ +ecma_value_t +ecma_proxy_object_construct (ecma_object_t *obj_p, /**< proxy object */ + ecma_object_t *new_target_p, /**< new target */ + const ecma_value_t *args_p, /**< argument list */ + uint32_t argc) /**< number of arguments */ +{ + JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p)); + ECMA_CHECK_STACK_USAGE (); + + ecma_proxy_object_t *proxy_obj_p = (ecma_proxy_object_t *) obj_p; + + /* 1. */ + ecma_value_t handler = proxy_obj_p->handler; + + /* 2-5. */ + ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_CONSTRUCT); + + /* 6. */ + if (ECMA_IS_VALUE_ERROR (trap)) + { + return trap; + } + + ecma_value_t target = proxy_obj_p->target; + ecma_object_t *target_obj_p = ecma_get_object_from_value (target); + + /* 7. */ + if (ecma_is_value_undefined (trap)) + { + JERRY_ASSERT (ecma_object_is_constructor (target_obj_p)); + + ecma_value_t result = ecma_op_function_construct (target_obj_p, new_target_p, args_p, argc); + JERRY_BLOCK_TAIL_CALL_OPTIMIZATION (); + return result; + } + + /* 8. */ + ecma_value_t args_array = ecma_op_new_array_object_from_buffer (args_p, argc); + + ecma_object_t *func_obj_p = ecma_get_object_from_value (trap); + ecma_value_t new_target_value = ecma_make_object_value (new_target_p); + ecma_value_t function_call_args[] = { target, args_array, new_target_value }; + + /* 9. */ + ecma_value_t new_obj = ecma_op_function_call (func_obj_p, handler, function_call_args, 3); + + ecma_free_object (args_array); + ecma_deref_object (func_obj_p); + + /* 10 .*/ + if (ECMA_IS_VALUE_ERROR (new_obj)) + { + return new_obj; + } + + /* 11. */ + if (!ecma_is_value_object (new_obj)) + { + ecma_free_value (new_obj); + + return ecma_raise_type_error (ECMA_ERR_TRAP_MUST_RETURN_WITH_AN_OBJECT); + } + + /* 12. */ + return new_obj; +} /* ecma_proxy_object_construct */ + +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-proxy-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-proxy-object.h new file mode 100644 index 0000000..84acdf8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-proxy-object.h @@ -0,0 +1,86 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_PROXY_OBJECT_H +#define ECMA_PROXY_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaproxyobject ECMA Proxy object related routines + * @{ + */ + +#if JERRY_BUILTIN_PROXY + +ecma_object_t *ecma_proxy_create (ecma_value_t target, ecma_value_t handler, uint32_t options); + +ecma_object_t *ecma_proxy_create_revocable (ecma_value_t target, ecma_value_t handler); + +ecma_value_t +ecma_proxy_revoke_cb (ecma_object_t *function_obj_p, const ecma_value_t args_p[], const uint32_t args_count); + +ecma_value_t ecma_proxy_object_find (ecma_object_t *obj_p, ecma_string_t *prop_name_p); + +/* Internal operations */ + +ecma_value_t ecma_proxy_object_get_prototype_of (ecma_object_t *obj_p); + +ecma_value_t ecma_proxy_object_set_prototype_of (ecma_object_t *obj_p, ecma_value_t proto); + +ecma_value_t ecma_proxy_object_is_extensible (ecma_object_t *obj_p); + +ecma_value_t ecma_proxy_object_prevent_extensions (ecma_object_t *obj_p); + +ecma_value_t ecma_proxy_object_get_own_property_descriptor (ecma_object_t *obj_p, + ecma_string_t *prop_name_p, + ecma_property_descriptor_t *prop_desc_p); + +ecma_value_t ecma_proxy_object_define_own_property (ecma_object_t *obj_p, + ecma_string_t *prop_name_p, + const ecma_property_descriptor_t *prop_desc_p); + +ecma_value_t ecma_proxy_object_has (ecma_object_t *obj_p, ecma_string_t *prop_name_p); + +ecma_value_t ecma_proxy_object_get (ecma_object_t *obj_p, ecma_string_t *prop_name_p, ecma_value_t receiver); + +ecma_value_t ecma_proxy_object_set (ecma_object_t *obj_p, + ecma_string_t *prop_name_p, + ecma_value_t name, + ecma_value_t receiver, + bool is_strict); + +ecma_value_t ecma_proxy_object_delete_property (ecma_object_t *obj_p, ecma_string_t *prop_name_p, bool is_strict); + +ecma_collection_t *ecma_proxy_object_own_property_keys (ecma_object_t *obj_p); + +ecma_value_t +ecma_proxy_object_call (ecma_object_t *obj_p, ecma_value_t this_argument, const ecma_value_t *args_p, uint32_t argc); + +ecma_value_t ecma_proxy_object_construct (ecma_object_t *obj_p, + ecma_object_t *new_target_p, + const ecma_value_t *args_p, + uint32_t argc); + +#endif /* JERRY_BUILTIN_PROXY */ + +/** + * @} + * @} + */ + +#endif /* !ECMA_PROXY_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-reference.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-reference.cpp new file mode 100644 index 0000000..bc8f386 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-reference.cpp @@ -0,0 +1,404 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-reference.h" + +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lcache.h" +#include "ecma-lex-env.h" +#include "ecma-objects.h" +#include "ecma-proxy-object.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup references ECMA-Reference + * @{ + */ + +/** + * Resolve syntactic reference. + * + * @return ECMA_OBJECT_POINTER_ERROR - if the operation fails + * pointer to lexical environment - if the reference's base is resolved successfully, + * NULL - otherwise. + */ +ecma_object_t * +ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical environment */ + ecma_string_t *name_p) /**< identifier's name */ +{ + JERRY_ASSERT (lex_env_p != NULL); + + while (true) + { + ecma_value_t has_binding = ecma_op_has_binding (lex_env_p, name_p); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (has_binding)) + { + return ECMA_OBJECT_POINTER_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_true (has_binding)) + { + return lex_env_p; + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + return NULL; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } +} /* ecma_op_resolve_reference_base */ + +/** + * Check if the passed lexical environment is a global lexical environment + * + * @return true - if the lexical environment is a global lexical environment + * false - otherwise + */ +static inline bool +ecma_op_is_global_environment (ecma_object_t *lex_env_p) /**< lexical environment */ +{ + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); +#if JERRY_BUILTIN_REALMS + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL + || (ecma_make_object_value (ecma_get_lex_env_binding_object (lex_env_p)) + == ((ecma_global_object_t *) ecma_builtin_get_global ())->this_binding)); +#else /* !JERRY_BUILTIN_REALMS */ + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL + || ecma_get_lex_env_binding_object (lex_env_p) == ecma_builtin_get_global ()); +#endif /* JERRY_BUILTIN_REALMS */ + + return lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL; +} /* ecma_op_is_global_environment */ + +/** + * Perform GetThisEnvironment and GetSuperBase operations + * + * See also: ECMAScript v6, 8.1.1.3.5 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_UNDEFINED - if the home object is null + * value of the [[HomeObject]].[[Prototype]] internal slot - otherwise + */ +ecma_value_t +ecma_op_resolve_super_base (ecma_object_t *lex_env_p) /**< starting lexical environment */ +{ + while (true) + { + JERRY_ASSERT (lex_env_p != NULL); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && !ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + ecma_object_t *home_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u1.home_object_cp); + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (home_p)) + { + return ecma_proxy_object_get_prototype_of (home_p); + } +#endif /* JERRY_BUILTIN_PROXY */ + + jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (home_p); + + if (proto_cp == JMEM_CP_NULL) + { + return ECMA_VALUE_NULL; + } + + ecma_object_t *proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp); + ecma_ref_object (proto_p); + + return ecma_make_object_value (proto_p); + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + return ECMA_VALUE_UNDEFINED; +} /* ecma_op_resolve_super_base */ + +/** + * Helper method for HasBindig operation + * + * See also: + * ECMA-262 v6, 8.1.1.2.1 steps 7-9; + * + * @return ECMA_VALUE_TRUE - if the property is unscopable + * ECMA_VALUE_FALSE - if a the property is not unscopable + * ECMA_VALUE_ERROR - otherwise + */ +static ecma_value_t +ecma_op_is_prop_unscopable (ecma_object_t *binding_obj_p, /**< binding object */ + ecma_string_t *prop_name_p) /**< property's name */ +{ + ecma_value_t unscopables = ecma_op_object_get_by_symbol_id (binding_obj_p, LIT_GLOBAL_SYMBOL_UNSCOPABLES); + + if (ECMA_IS_VALUE_ERROR (unscopables)) + { + return unscopables; + } + + if (ecma_is_value_object (unscopables)) + { + ecma_object_t *unscopables_obj_p = ecma_get_object_from_value (unscopables); + ecma_value_t get_unscopables_value = ecma_op_object_get (unscopables_obj_p, prop_name_p); + ecma_deref_object (unscopables_obj_p); + + if (ECMA_IS_VALUE_ERROR (get_unscopables_value)) + { + return get_unscopables_value; + } + + bool is_blocked = ecma_op_to_boolean (get_unscopables_value); + + ecma_free_value (get_unscopables_value); + + return ecma_make_boolean_value (is_blocked); + } + + ecma_free_value (unscopables); + + return ECMA_VALUE_FALSE; +} /* ecma_op_is_prop_unscopable */ + +/** + * Helper method for HasBindig operation + * + * See also: + * ECMA-262 v6, 8.1.1.2.1 steps 7-9; + * + * @return ECMA_VALUE_TRUE - if the property is unscopable + * ECMA_VALUE_FALSE - if a the property is not unscopable + * ECMA_VALUE_ERROR - otherwise + */ + +/** + * Resolve value corresponding to the given object environment reference. + * + * Note: the steps are already include the HasBindig operation steps + * + * See also: + * ECMA-262 v6, 8.1.1.2.1 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_NOT_FOUND - if the binding not exists or blocked via @@unscopables + * result of the binding - otherwise + */ +ecma_value_t +ecma_op_object_bound_environment_resolve_reference_value (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_string_t *name_p) /**< variable name */ +{ + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + ecma_value_t found_binding; + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (binding_obj_p)) + { + found_binding = ecma_proxy_object_has (binding_obj_p, name_p); + + if (!ecma_is_value_true (found_binding)) + { + return ECMA_IS_VALUE_ERROR (found_binding) ? found_binding : ECMA_VALUE_NOT_FOUND; + } + } + else + { +#endif /* JERRY_BUILTIN_PROXY */ + found_binding = ecma_op_object_find (binding_obj_p, name_p); + + if (ECMA_IS_VALUE_ERROR (found_binding) || !ecma_is_value_found (found_binding)) + { + return found_binding; + } + + if (JERRY_LIKELY (ecma_op_is_global_environment (lex_env_p))) + { + return found_binding; + } +#if JERRY_BUILTIN_PROXY + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_value_t blocked = ecma_op_is_prop_unscopable (binding_obj_p, name_p); + + if (ecma_is_value_false (blocked)) + { +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (binding_obj_p)) + { + return ecma_proxy_object_get (binding_obj_p, name_p, ecma_make_object_value (binding_obj_p)); + } +#endif /* JERRY_BUILTIN_PROXY */ + return found_binding; + } + +#if JERRY_BUILTIN_PROXY + if (!ECMA_OBJECT_IS_PROXY (binding_obj_p)) + { + ecma_free_value (found_binding); + } +#endif /* JERRY_BUILTIN_PROXY */ + + return ECMA_IS_VALUE_ERROR (blocked) ? blocked : ECMA_VALUE_NOT_FOUND; +} /* ecma_op_object_bound_environment_resolve_reference_value */ + +/** + * Resolve value corresponding to reference. + * + * @return value of the reference + */ +ecma_value_t +ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, /**< starting lexical environment */ + ecma_string_t *name_p) /**< identifier's name */ +{ + JERRY_ASSERT (lex_env_p != NULL); + + while (true) + { + switch (ecma_get_lex_env_type (lex_env_p)) + { + case ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE: + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p == NULL) + { + break; + } + + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (JERRY_UNLIKELY (property_value_p->value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + + return ecma_fast_copy_value (property_value_p->value); + } + case ECMA_LEXICAL_ENVIRONMENT_CLASS: + { +#if JERRY_MODULE_SYSTEM + if (ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p == NULL) + { + break; + } + + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (!(*property_p & ECMA_PROPERTY_FLAG_DATA)) + { + property_value_p = ecma_get_property_value_from_named_reference (property_value_p); + } + + if (JERRY_UNLIKELY (property_value_p->value == ECMA_VALUE_UNINITIALIZED)) + { + return ecma_raise_reference_error (ECMA_ERR_LET_CONST_NOT_INITIALIZED); + } + + return ecma_fast_copy_value (property_value_p->value); + } +#endif /* JERRY_MODULE_SYSTEM */ + break; + } + default: + { + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND); + + if (ecma_op_is_global_environment (lex_env_p)) + { +#if JERRY_LCACHE + ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); + ecma_property_t *property_p = ecma_lcache_lookup (binding_obj_p, name_p); + + if (property_p != NULL) + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (*property_p & ECMA_PROPERTY_FLAG_DATA) + { + return ecma_fast_copy_value (prop_value_p->value); + } + + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (prop_value_p); + + if (get_set_pair_p->getter_cp == JMEM_CP_NULL) + { + return ECMA_VALUE_UNDEFINED; + } + + ecma_object_t *getter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp); + + ecma_value_t base_value = ecma_make_object_value (binding_obj_p); + return ecma_op_function_call (getter_p, base_value, NULL, 0); + } +#endif /* JERRY_LCACHE */ + } + + ecma_value_t result = ecma_op_object_bound_environment_resolve_reference_value (lex_env_p, name_p); + + if (ecma_is_value_found (result)) + { + /* Note: the result may contains ECMA_VALUE_ERROR */ + return result; + } + break; + } + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + +#if JERRY_ERROR_MESSAGES + ecma_value_t name_val = ecma_make_string_value (name_p); + ecma_value_t error_value = + ecma_raise_standard_error_with_format (JERRY_ERROR_REFERENCE, "% is not defined", name_val); +#else /* JERRY_ERROR_MESSAGES */ + ecma_value_t error_value = ecma_raise_reference_error (ECMA_ERR_EMPTY); +#endif /* !JERRY_ERROR_MESSAGES */ + return error_value; +} /* ecma_op_resolve_reference_value */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-reference.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-reference.h new file mode 100644 index 0000000..e1d4ae7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-reference.h @@ -0,0 +1,40 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_REFERENCE_H +#define ECMA_REFERENCE_H + +#include "ecma-globals.h" + +#include "jrt.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup references ECMA-Reference + * @{ + */ + +ecma_object_t *ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, ecma_string_t *name_p); +ecma_value_t ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, ecma_string_t *name_p); +ecma_value_t ecma_op_object_bound_environment_resolve_reference_value (ecma_object_t *lex_env_p, ecma_string_t *name_p); +ecma_value_t ecma_op_resolve_super_base (ecma_object_t *lex_env_p); + +/** + * @} + * @} + */ + +#endif /* !ECMA_REFERENCE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-regexp-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-regexp-object.cpp new file mode 100644 index 0000000..5f7f9d0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-regexp-object.cpp @@ -0,0 +1,3219 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-regexp-object.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-objects.h" + +#include "jcontext.h" +#include "jrt-libc-includes.h" +#include "lit-char-helpers.h" +#include "re-compiler.h" + +#if JERRY_BUILTIN_REGEXP + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaregexpobject ECMA RegExp object related routines + * @{ + */ + +/** + * Index of the global capturing group + */ +#define RE_GLOBAL_CAPTURE 0 + +/** + * Parse RegExp flags (global, ignoreCase, multiline) + * + * See also: ECMA-262 v5, 15.10.4.1 + * + * @return empty ecma value - if parsed successfully + * error ecma value - otherwise + * + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_regexp_parse_flags (ecma_string_t *flags_str_p, /**< Input string with flags */ + uint16_t *flags_p) /**< [out] parsed flag bits */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + uint16_t result_flags = RE_FLAG_EMPTY; + + ECMA_STRING_TO_UTF8_STRING (flags_str_p, flags_start_p, flags_start_size); + + const lit_utf8_byte_t *flags_str_curr_p = flags_start_p; + const lit_utf8_byte_t *flags_str_end_p = flags_start_p + flags_start_size; + + while (flags_str_curr_p < flags_str_end_p) + { + ecma_regexp_flags_t flag; + switch (*flags_str_curr_p++) + { + case 'g': + { + flag = RE_FLAG_GLOBAL; + break; + } + case 'i': + { + flag = RE_FLAG_IGNORE_CASE; + break; + } + case 'm': + { + flag = RE_FLAG_MULTILINE; + break; + } + case 'y': + { + flag = RE_FLAG_STICKY; + break; + } + case 'u': + { + flag = RE_FLAG_UNICODE; + break; + } + case 's': + { + flag = RE_FLAG_DOTALL; + break; + } + default: + { + flag = RE_FLAG_EMPTY; + break; + } + } + + if (flag == RE_FLAG_EMPTY || (result_flags & flag) != 0) + { + ret_value = ecma_raise_syntax_error (ECMA_ERR_INVALID_REGEXP_FLAGS); + break; + } + + result_flags = (uint16_t) (result_flags | flag); + } + + ECMA_FINALIZE_UTF8_STRING (flags_start_p, flags_start_size); + + *flags_p = result_flags; + return ret_value; +} /* ecma_regexp_parse_flags */ + +/** + * RegExpAlloc method + * + * See also: ECMA-262 v5, 15.10.4.1 + * ECMA-262 v6, 21.2.3.2.1 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return ecma_object_t + */ +ecma_object_t * +ecma_op_regexp_alloc (ecma_object_t *ctr_obj_p) /**< constructor object pointer */ +{ + if (ctr_obj_p == NULL) + { + ctr_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP); + } + + ecma_object_t *proto_obj_p = ecma_op_get_prototype_from_constructor (ctr_obj_p, ECMA_BUILTIN_ID_REGEXP_PROTOTYPE); + + if (JERRY_UNLIKELY (proto_obj_p == NULL)) + { + return proto_obj_p; + } + + ecma_object_t *new_object_p = + ecma_create_object (proto_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_deref_object (proto_obj_p); + + ecma_extended_object_t *regexp_obj_p = (ecma_extended_object_t *) new_object_p; + + /* Class id will be initialized after the bytecode is compiled. */ + regexp_obj_p->u.cls.type = ECMA_OBJECT_CLASS__MAX; + + ecma_value_t status = ecma_builtin_helper_def_prop (new_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_uint32_value (0), + ECMA_PROPERTY_FLAG_WRITABLE | JERRY_PROP_SHOULD_THROW); + + JERRY_ASSERT (ecma_is_value_true (status)); + + return new_object_p; +} /* ecma_op_regexp_alloc */ + +/** + * Helper method for initializing an already existing RegExp object. + */ +static inline void +ecma_op_regexp_initialize (ecma_object_t *regexp_obj_p, /**< RegExp object */ + const re_compiled_code_t *bc_p) /**< bytecode */ +{ + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) regexp_obj_p; + ext_obj_p->u.cls.type = ECMA_OBJECT_CLASS_REGEXP; + ECMA_SET_INTERNAL_VALUE_POINTER (ext_obj_p->u.cls.u3.value, bc_p); +} /* ecma_op_regexp_initialize */ + +/** + * Method for creating a RegExp object from pattern. + * + * Note: + * Allocation have to happen before invoking this function using ecma_op_regexp_alloc. + * + * @return ecma_value_t + */ +ecma_value_t +ecma_op_create_regexp_from_pattern (ecma_object_t *regexp_obj_p, /**< RegExp object */ + ecma_value_t pattern_value, /**< pattern */ + ecma_value_t flags_value) /**< flags */ +{ + ecma_string_t *pattern_str_p = ecma_regexp_read_pattern_str_helper (pattern_value); + uint16_t flags = 0; + + if (JERRY_UNLIKELY (pattern_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + if (!ecma_is_value_undefined (flags_value)) + { + ecma_string_t *flags_str_p = ecma_op_to_string (flags_value); + + if (JERRY_UNLIKELY (flags_str_p == NULL)) + { + ecma_deref_ecma_string (pattern_str_p); + return ECMA_VALUE_ERROR; + } + + ecma_value_t parse_flags_value = ecma_regexp_parse_flags (flags_str_p, &flags); + ecma_deref_ecma_string (flags_str_p); + + if (ECMA_IS_VALUE_ERROR (parse_flags_value)) + { + ecma_deref_ecma_string (pattern_str_p); + return parse_flags_value; + } + + JERRY_ASSERT (ecma_is_value_empty (parse_flags_value)); + } + + re_compiled_code_t *bc_p = re_compile_bytecode (pattern_str_p, flags); + + if (JERRY_UNLIKELY (bc_p == NULL)) + { + ecma_deref_ecma_string (pattern_str_p); + return ECMA_VALUE_ERROR; + } + + ecma_op_regexp_initialize (regexp_obj_p, bc_p); + ecma_deref_ecma_string (pattern_str_p); + + return ecma_make_object_value (regexp_obj_p); +} /* ecma_op_create_regexp_from_pattern */ + +/** + * Method for creating a RegExp object from bytecode. + * + * Note: + * Allocation have to happen before invoking this function using ecma_op_regexp_alloc. + * + * @return ecma_value_t + */ +ecma_value_t +ecma_op_create_regexp_from_bytecode (ecma_object_t *regexp_obj_p, /**< RegExp object */ + re_compiled_code_t *bc_p) /**< bytecode */ +{ + ecma_bytecode_ref ((ecma_compiled_code_t *) bc_p); + + ecma_op_regexp_initialize (regexp_obj_p, bc_p); + + return ecma_make_object_value (regexp_obj_p); +} /* ecma_op_create_regexp_from_bytecode */ + +/** + * Method for creating a RegExp object from pattern with already parsed flags. + * + * Note: + * Allocation have to happen before invoking this function using ecma_op_regexp_alloc. + * + * @return ecma_value_t + */ +ecma_value_t +ecma_op_create_regexp_with_flags (ecma_object_t *regexp_obj_p, /**< RegExp object */ + ecma_value_t pattern_value, /**< pattern */ + uint16_t flags) /**< flags */ +{ + ecma_string_t *pattern_str_p = ecma_regexp_read_pattern_str_helper (pattern_value); + + if (JERRY_UNLIKELY (pattern_str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + re_compiled_code_t *bc_p = re_compile_bytecode (pattern_str_p, flags); + ecma_deref_ecma_string (pattern_str_p); + + if (JERRY_UNLIKELY (bc_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_op_regexp_initialize (regexp_obj_p, bc_p); + + return ecma_make_object_value (regexp_obj_p); +} /* ecma_op_create_regexp_with_flags */ + +/** + * Canonicalize a character + * + * @return ecma_char_t canonicalized character + */ +lit_code_point_t +ecma_regexp_canonicalize_char (lit_code_point_t ch, /**< character */ + bool unicode) /**< unicode */ +{ + if (unicode) + { + /* In unicode mode the mappings contained in the CaseFolding.txt file should be used to canonicalize the character. + * These mappings generally correspond to the lowercase variant of the character, however there are some + * differences. In some cases the uppercase variant is used, in others the lowercase of the uppercase character is + * used, and there are also cases where the character has no case folding mapping even though it has upper/lower + * variants. Since lowercasing is the most common this is used as the default behaviour, and characters with + * differing behaviours are encoded in lookup tables. */ + + if (lit_char_fold_to_upper (ch)) + { + ch = lit_char_to_upper_case (ch, NULL); + JERRY_ASSERT (ch != LIT_MULTIPLE_CU); + } + + if (lit_char_fold_to_lower (ch)) + { + ch = lit_char_to_lower_case (ch, NULL); + JERRY_ASSERT (ch != LIT_MULTIPLE_CU); + } + + return ch; + } + + JERRY_UNUSED (unicode); + lit_code_point_t cu = lit_char_to_upper_case (ch, NULL); + + if (ch <= LIT_UTF8_1_BYTE_CODE_POINT_MAX || (cu > LIT_UTF8_1_BYTE_CODE_POINT_MAX && cu != LIT_MULTIPLE_CU)) + { + return cu; + } + + return ch; +} /* ecma_regexp_canonicalize_char */ + +/** + * RegExp Canonicalize abstract operation + * + * See also: ECMA-262 v5, 15.10.2.8 + * + * @return ecma_char_t canonicalized character + */ +static inline lit_code_point_t +ecma_regexp_canonicalize (lit_code_point_t ch, /**< character */ + uint16_t flags) /**< flags */ +{ + if (flags & RE_FLAG_IGNORE_CASE) + { + return ecma_regexp_canonicalize_char (ch, flags & RE_FLAG_UNICODE); + } + + return ch; +} /* ecma_regexp_canonicalize */ + +/** + * Check if a code point is matched by a class escape. + * + * @return true, if code point matches escape + * false, otherwise + */ +static bool +ecma_regexp_check_class_escape (lit_code_point_t cp, /**< char */ + ecma_class_escape_t escape) /**< escape */ +{ + switch (escape) + { + case RE_ESCAPE_DIGIT: + { + return (cp >= LIT_CHAR_0 && cp <= LIT_CHAR_9); + } + case RE_ESCAPE_NOT_DIGIT: + { + return (cp < LIT_CHAR_0 || cp > LIT_CHAR_9); + } + case RE_ESCAPE_WORD_CHAR: + { + return lit_char_is_word_char (cp); + } + case RE_ESCAPE_NOT_WORD_CHAR: + { + return !lit_char_is_word_char (cp); + } + case RE_ESCAPE_WHITESPACE: + { + return lit_char_is_white_space ((ecma_char_t) cp); + } + case RE_ESCAPE_NOT_WHITESPACE: + { + return !lit_char_is_white_space ((ecma_char_t) cp); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_regexp_check_class_escape */ + +/** + * Helper function to get current code point or code unit depending on execution mode, + * and advance the string pointer. + * + * @return lit_code_point_t current code point + */ +static lit_code_point_t +ecma_regexp_advance (ecma_regexp_ctx_t *re_ctx_p, /**< regexp context */ + const lit_utf8_byte_t **str_p) /**< reference to string pointer */ +{ + JERRY_ASSERT (str_p != NULL); + lit_code_point_t cp = lit_cesu8_read_next (str_p); + + if (JERRY_UNLIKELY (re_ctx_p->flags & RE_FLAG_UNICODE) && lit_is_code_point_utf16_high_surrogate ((ecma_char_t) cp) + && *str_p < re_ctx_p->input_end_p) + { + const ecma_char_t next_ch = lit_cesu8_peek_next (*str_p); + if (lit_is_code_point_utf16_low_surrogate (next_ch)) + { + cp = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) cp, next_ch); + *str_p += LIT_UTF8_MAX_BYTES_IN_CODE_UNIT; + } + } + + return ecma_regexp_canonicalize (cp, re_ctx_p->flags); +} /* ecma_regexp_advance */ + +/** + * Helper function to get current full unicode code point and advance the string pointer. + * + * @return lit_code_point_t current code point + */ +lit_code_point_t +ecma_regexp_unicode_advance (const lit_utf8_byte_t **str_p, /**< reference to string pointer */ + const lit_utf8_byte_t *end_p) /**< string end pointer */ +{ + JERRY_ASSERT (str_p != NULL); + const lit_utf8_byte_t *current_p = *str_p; + + lit_code_point_t ch = lit_cesu8_read_next (¤t_p); + if (lit_is_code_point_utf16_high_surrogate ((ecma_char_t) ch) && current_p < end_p) + { + const ecma_char_t next_ch = lit_cesu8_peek_next (current_p); + if (lit_is_code_point_utf16_low_surrogate (next_ch)) + { + ch = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) ch, next_ch); + current_p += LIT_UTF8_MAX_BYTES_IN_CODE_UNIT; + } + } + + *str_p = current_p; + return ch; +} /* ecma_regexp_unicode_advance */ + +/** + * Helper function to revert the string pointer to the previous code point. + * + * @return pointer to previous code point + */ +static JERRY_ATTR_NOINLINE const lit_utf8_byte_t * +ecma_regexp_step_back (ecma_regexp_ctx_t *re_ctx_p, /**< regexp context */ + const lit_utf8_byte_t *str_p) /**< reference to string pointer */ +{ + JERRY_ASSERT (str_p != NULL); + + lit_code_point_t ch = lit_cesu8_read_prev (&str_p); + if (JERRY_UNLIKELY (re_ctx_p->flags & RE_FLAG_UNICODE) && lit_is_code_point_utf16_low_surrogate (ch) + && lit_is_code_point_utf16_high_surrogate (lit_cesu8_peek_prev (str_p))) + { + str_p -= LIT_UTF8_MAX_BYTES_IN_CODE_UNIT; + } + + return str_p; +} /* ecma_regexp_step_back */ + +/** + * Check if the current position is on a word boundary. + * + * @return true, if on a word boundary + * false - otherwise + */ +static bool +ecma_regexp_is_word_boundary (ecma_regexp_ctx_t *re_ctx_p, /**< regexp context */ + const lit_utf8_byte_t *str_p) /**< string pointer */ +{ + lit_code_point_t left_cp; + lit_code_point_t right_cp; + + if (JERRY_UNLIKELY (str_p <= re_ctx_p->input_start_p)) + { + left_cp = LIT_INVALID_CP; + } + else if (JERRY_UNLIKELY ((re_ctx_p->flags & (RE_FLAG_UNICODE | RE_FLAG_IGNORE_CASE)) + == (RE_FLAG_UNICODE | RE_FLAG_IGNORE_CASE))) + { + const lit_utf8_byte_t *prev_p = ecma_regexp_step_back (re_ctx_p, str_p); + left_cp = ecma_regexp_advance (re_ctx_p, &prev_p); + JERRY_ASSERT (prev_p == str_p); + } + else + { + left_cp = str_p[-1]; + } + + if (JERRY_UNLIKELY (str_p >= re_ctx_p->input_end_p)) + { + right_cp = LIT_INVALID_CP; + } + else if (JERRY_UNLIKELY ((re_ctx_p->flags & (RE_FLAG_UNICODE | RE_FLAG_IGNORE_CASE)) + == (RE_FLAG_UNICODE | RE_FLAG_IGNORE_CASE))) + { + right_cp = ecma_regexp_advance (re_ctx_p, &str_p); + } + else + { + right_cp = str_p[0]; + } + + return lit_char_is_word_char (left_cp) != lit_char_is_word_char (right_cp); +} /* ecma_regexp_is_word_boundary */ + +/** + * Recursive function for executing RegExp bytecode. + * + * See also: + * ECMA-262 v5, 15.10.2.1 + * + * @return pointer to the end of the currently matched substring + * NULL, if pattern did not match + */ +static const lit_utf8_byte_t * +ecma_regexp_run (ecma_regexp_ctx_t *re_ctx_p, /**< RegExp matcher context */ + const uint8_t *bc_p, /**< pointer to the current RegExp bytecode */ + const lit_utf8_byte_t *str_curr_p) /**< input string pointer */ +{ +#if (JERRY_STACK_LIMIT != 0) + if (JERRY_UNLIKELY (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT)) + { + return ECMA_RE_OUT_OF_STACK; + } +#endif /* JERRY_STACK_LIMIT != 0 */ + + const lit_utf8_byte_t *str_start_p = str_curr_p; + const uint8_t *next_alternative_p = NULL; + + while (true) + { + const re_opcode_t op = re_get_opcode (&bc_p); + + switch (op) + { + case RE_OP_EOF: + { + re_ctx_p->captures_p[RE_GLOBAL_CAPTURE].end_p = str_curr_p; + /* FALLTHRU */ + } + case RE_OP_ASSERT_END: + case RE_OP_ITERATOR_END: + { + return str_curr_p; + } + case RE_OP_ALTERNATIVE_START: + { + const uint32_t offset = re_get_value (&bc_p); + next_alternative_p = bc_p + offset; + continue; + } + case RE_OP_ALTERNATIVE_NEXT: + { + while (true) + { + const uint32_t offset = re_get_value (&bc_p); + bc_p += offset; + + if (*bc_p != RE_OP_ALTERNATIVE_NEXT) + { + break; + } + + bc_p++; + } + + continue; + } + case RE_OP_NO_ALTERNATIVE: + { + return NULL; + } + case RE_OP_CAPTURING_GROUP_START: + { + const uint32_t group_idx = re_get_value (&bc_p); + ecma_regexp_capture_t *const group_p = re_ctx_p->captures_p + group_idx; + group_p->subcapture_count = re_get_value (&bc_p); + + const lit_utf8_byte_t *const saved_begin_p = group_p->begin_p; + const lit_utf8_byte_t *const saved_end_p = group_p->end_p; + const uint32_t saved_iterator = group_p->iterator; + + const uint32_t qmin = re_get_value (&bc_p); + group_p->end_p = NULL; + + /* If zero iterations are allowed, then execute the end opcode which will handle further iterations, + * otherwise run the 1st iteration immediately by executing group bytecode. */ + if (qmin == 0) + { + group_p->iterator = 0; + group_p->begin_p = NULL; + const uint32_t end_offset = re_get_value (&bc_p); + group_p->bc_p = bc_p; + + bc_p += end_offset; + } + else + { + group_p->iterator = 1; + group_p->begin_p = str_curr_p; + group_p->bc_p = bc_p; + } + + const lit_utf8_byte_t *matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + group_p->iterator = saved_iterator; + + if (matched_p == NULL) + { + group_p->begin_p = saved_begin_p; + group_p->end_p = saved_end_p; + goto fail; + } + + return matched_p; + } + case RE_OP_NON_CAPTURING_GROUP_START: + { + const uint32_t group_idx = re_get_value (&bc_p); + ecma_regexp_non_capture_t *const group_p = re_ctx_p->non_captures_p + group_idx; + + group_p->subcapture_start = re_get_value (&bc_p); + group_p->subcapture_count = re_get_value (&bc_p); + + const lit_utf8_byte_t *const saved_begin_p = group_p->begin_p; + const uint32_t saved_iterator = group_p->iterator; + const uint32_t qmin = re_get_value (&bc_p); + + /* If zero iterations are allowed, then execute the end opcode which will handle further iterations, + * otherwise run the 1st iteration immediately by executing group bytecode. */ + if (qmin == 0) + { + group_p->iterator = 0; + group_p->begin_p = NULL; + const uint32_t end_offset = re_get_value (&bc_p); + group_p->bc_p = bc_p; + + bc_p += end_offset; + } + else + { + group_p->iterator = 1; + group_p->begin_p = str_curr_p; + group_p->bc_p = bc_p; + } + + const lit_utf8_byte_t *matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + group_p->iterator = saved_iterator; + + if (matched_p == NULL) + { + group_p->begin_p = saved_begin_p; + goto fail; + } + + return matched_p; + } + case RE_OP_GREEDY_CAPTURING_GROUP_END: + { + const uint32_t group_idx = re_get_value (&bc_p); + ecma_regexp_capture_t *const group_p = re_ctx_p->captures_p + group_idx; + const uint32_t qmin = re_get_value (&bc_p); + + if (group_p->iterator < qmin) + { + /* No need to save begin_p since we don't have to backtrack beyond the minimum iteration count, but we have + * to clear nested capturing groups. */ + group_p->begin_p = str_curr_p; + for (uint32_t i = 1; i < group_p->subcapture_count; ++i) + { + group_p[i].begin_p = NULL; + } + + group_p->iterator++; + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + group_p->iterator--; + goto fail; + } + + /* Empty matches are not allowed after reaching the minimum number of iterations. */ + if (JERRY_UNLIKELY (group_p->begin_p >= str_curr_p) && (group_p->iterator > qmin)) + { + goto fail; + } + + const uint32_t qmax = re_get_value (&bc_p) - RE_QMAX_OFFSET; + if (JERRY_UNLIKELY (group_p->iterator >= qmax)) + { + /* Reached maximum number of iterations, try to match tail bytecode. */ + group_p->end_p = str_curr_p; + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + goto fail; + } + + { + /* Save and clear all nested capturing groups, and try to iterate. */ + JERRY_VLA (const lit_utf8_byte_t *, saved_captures_p, group_p->subcapture_count); + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + saved_captures_p[i] = group_p[i].begin_p; + group_p[i].begin_p = NULL; + } + + group_p->iterator++; + group_p->begin_p = str_curr_p; + + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + /* Failed to iterate again, backtrack to current match, and try to run tail bytecode. */ + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + group_p[i].begin_p = saved_captures_p[i]; + } + + group_p->iterator--; + group_p->end_p = str_curr_p; + } + + const lit_utf8_byte_t *const tail_match_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (tail_match_p != NULL) + { + return tail_match_p; + } + + goto fail; + } + case RE_OP_GREEDY_NON_CAPTURING_GROUP_END: + { + const uint32_t group_idx = re_get_value (&bc_p); + ecma_regexp_non_capture_t *const group_p = re_ctx_p->non_captures_p + group_idx; + const uint32_t qmin = re_get_value (&bc_p); + + if (group_p->iterator < qmin) + { + /* No need to save begin_p but we have to clear nested capturing groups. */ + group_p->begin_p = str_curr_p; + + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + group_p->subcapture_start; + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + capture_p[i].begin_p = NULL; + } + + group_p->iterator++; + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + group_p->iterator--; + goto fail; + } + + /* Empty matches are not allowed after reaching the minimum number of iterations. */ + if (JERRY_UNLIKELY (group_p->begin_p >= str_curr_p) && (group_p->iterator > qmin)) + { + goto fail; + } + + const uint32_t qmax = re_get_value (&bc_p) - RE_QMAX_OFFSET; + if (JERRY_UNLIKELY (group_p->iterator >= qmax)) + { + /* Reached maximum number of iterations, try to match tail bytecode. */ + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + goto fail; + } + + { + /* Save and clear all nested capturing groups, and try to iterate. */ + JERRY_VLA (const lit_utf8_byte_t *, saved_captures_p, group_p->subcapture_count); + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + group_p->subcapture_start + i; + saved_captures_p[i] = capture_p->begin_p; + capture_p->begin_p = NULL; + } + + group_p->iterator++; + const lit_utf8_byte_t *const saved_begin_p = group_p->begin_p; + group_p->begin_p = str_curr_p; + + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + /* Failed to iterate again, backtrack to current match, and try to run tail bytecode. */ + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + group_p->subcapture_start + i; + capture_p->begin_p = saved_captures_p[i]; + } + + group_p->iterator--; + group_p->begin_p = saved_begin_p; + } + + const lit_utf8_byte_t *const tail_match_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (tail_match_p != NULL) + { + return tail_match_p; + } + + goto fail; + } + case RE_OP_LAZY_CAPTURING_GROUP_END: + { + const uint32_t group_idx = re_get_value (&bc_p); + ecma_regexp_capture_t *const group_p = re_ctx_p->captures_p + group_idx; + const uint32_t qmin = re_get_value (&bc_p); + + if (group_p->iterator < qmin) + { + /* No need to save begin_p but we have to clear nested capturing groups. */ + group_p->begin_p = str_curr_p; + for (uint32_t i = 1; i < group_p->subcapture_count; ++i) + { + group_p[i].begin_p = NULL; + } + + group_p->iterator++; + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + group_p->iterator--; + goto fail; + } + + /* Empty matches are not allowed after reaching the minimum number of iterations. */ + if (JERRY_UNLIKELY (group_p->begin_p >= str_curr_p) && (group_p->iterator > qmin)) + { + goto fail; + } + + const uint32_t qmax = re_get_value (&bc_p) - RE_QMAX_OFFSET; + group_p->end_p = str_curr_p; + + /* Try to match tail bytecode. */ + const lit_utf8_byte_t *const tail_match_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (tail_match_p != NULL) + { + return tail_match_p; + } + + if (JERRY_UNLIKELY (group_p->iterator >= qmax)) + { + /* Reached maximum number of iterations and tail bytecode did not match. */ + goto fail; + } + + { + /* Save and clear all nested capturing groups, and try to iterate. */ + JERRY_VLA (const lit_utf8_byte_t *, saved_captures_p, group_p->subcapture_count); + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + saved_captures_p[i] = group_p[i].begin_p; + group_p[i].begin_p = NULL; + } + + group_p->iterator++; + group_p->begin_p = str_curr_p; + + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + /* Backtrack to current match. */ + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + group_p[i].begin_p = saved_captures_p[i]; + } + + group_p->iterator--; + } + + goto fail; + } + case RE_OP_LAZY_NON_CAPTURING_GROUP_END: + { + const uint32_t group_idx = re_get_value (&bc_p); + ecma_regexp_non_capture_t *const group_p = re_ctx_p->non_captures_p + group_idx; + const uint32_t qmin = re_get_value (&bc_p); + + if (group_p->iterator < qmin) + { + /* Clear nested captures. */ + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + group_p->subcapture_start; + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + capture_p[i].begin_p = NULL; + } + + group_p->iterator++; + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + group_p->iterator--; + goto fail; + } + + /* Empty matches are not allowed after reaching the minimum number of iterations. */ + if (JERRY_UNLIKELY (group_p->begin_p >= str_curr_p) && (group_p->iterator > qmin)) + { + goto fail; + } + + const uint32_t qmax = re_get_value (&bc_p) - RE_QMAX_OFFSET; + + /* Try to match tail bytecode. */ + const lit_utf8_byte_t *const tail_match_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (tail_match_p != NULL) + { + return tail_match_p; + } + + if (JERRY_UNLIKELY (group_p->iterator >= qmax)) + { + /* Reached maximum number of iterations and tail bytecode did not match. */ + goto fail; + } + + { + /* Save and clear all nested capturing groups, and try to iterate. */ + JERRY_VLA (const lit_utf8_byte_t *, saved_captures_p, group_p->subcapture_count); + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + group_p->subcapture_start + i; + saved_captures_p[i] = capture_p->begin_p; + capture_p->begin_p = NULL; + } + + group_p->iterator++; + const lit_utf8_byte_t *const saved_begin_p = group_p->begin_p; + group_p->begin_p = str_curr_p; + + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, group_p->bc_p, str_curr_p); + + if (matched_p != NULL) + { + return matched_p; + } + + /* Backtrack to current match. */ + for (uint32_t i = 0; i < group_p->subcapture_count; ++i) + { + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + group_p->subcapture_start + i; + capture_p->begin_p = saved_captures_p[i]; + } + + group_p->iterator--; + group_p->begin_p = saved_begin_p; + } + + goto fail; + } + case RE_OP_GREEDY_ITERATOR: + { + const uint32_t qmin = re_get_value (&bc_p); + const uint32_t qmax = re_get_value (&bc_p) - RE_QMAX_OFFSET; + const uint32_t end_offset = re_get_value (&bc_p); + + uint32_t iterator = 0; + while (iterator < qmin) + { + str_curr_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (str_curr_p == NULL) + { + goto fail; + } + + if (ECMA_RE_STACK_LIMIT_REACHED (str_curr_p)) + { + return str_curr_p; + } + + iterator++; + } + + while (iterator < qmax) + { + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (matched_p == NULL) + { + break; + } + + if (ECMA_RE_STACK_LIMIT_REACHED (str_curr_p)) + { + return str_curr_p; + } + + str_curr_p = matched_p; + iterator++; + } + + const uint8_t *const tail_bc_p = bc_p + end_offset; + while (true) + { + const lit_utf8_byte_t *const tail_match_p = ecma_regexp_run (re_ctx_p, tail_bc_p, str_curr_p); + + if (tail_match_p != NULL) + { + return tail_match_p; + } + + if (JERRY_UNLIKELY (iterator <= qmin)) + { + goto fail; + } + + iterator--; + JERRY_ASSERT (str_curr_p > re_ctx_p->input_start_p); + str_curr_p = ecma_regexp_step_back (re_ctx_p, str_curr_p); + } + + JERRY_UNREACHABLE (); + } + case RE_OP_LAZY_ITERATOR: + { + const uint32_t qmin = re_get_value (&bc_p); + const uint32_t qmax = re_get_value (&bc_p) - RE_QMAX_OFFSET; + const uint32_t end_offset = re_get_value (&bc_p); + + uint32_t iterator = 0; + while (iterator < qmin) + { + str_curr_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (str_curr_p == NULL) + { + goto fail; + } + + if (ECMA_RE_STACK_LIMIT_REACHED (str_curr_p)) + { + return str_curr_p; + } + + iterator++; + } + + const uint8_t *const tail_bc_p = bc_p + end_offset; + while (true) + { + const lit_utf8_byte_t *const tail_match_p = ecma_regexp_run (re_ctx_p, tail_bc_p, str_curr_p); + + if (tail_match_p != NULL) + { + return tail_match_p; + } + + if (JERRY_UNLIKELY (iterator >= qmax)) + { + goto fail; + } + + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (matched_p == NULL) + { + goto fail; + } + + if (ECMA_RE_STACK_LIMIT_REACHED (matched_p)) + { + return matched_p; + } + + iterator++; + str_curr_p = matched_p; + } + + JERRY_UNREACHABLE (); + } + case RE_OP_BACKREFERENCE: + { + const uint32_t backref_idx = re_get_value (&bc_p); + JERRY_ASSERT (backref_idx >= 1 && backref_idx < re_ctx_p->captures_count); + const ecma_regexp_capture_t *capture_p = re_ctx_p->captures_p + backref_idx; + + if (!ECMA_RE_IS_CAPTURE_DEFINED (capture_p) || capture_p->end_p <= capture_p->begin_p) + { + /* Undefined or zero length captures always match. */ + continue; + } + + const lit_utf8_size_t capture_size = (lit_utf8_size_t) (capture_p->end_p - capture_p->begin_p); + + if (str_curr_p + capture_size > re_ctx_p->input_end_p || memcmp (str_curr_p, capture_p->begin_p, capture_size)) + { + goto fail; + } + + str_curr_p += capture_size; + continue; + } + case RE_OP_ASSERT_LINE_START: + { + if (str_curr_p <= re_ctx_p->input_start_p) + { + continue; + } + + if (!(re_ctx_p->flags & RE_FLAG_MULTILINE) || !lit_char_is_line_terminator (lit_cesu8_peek_prev (str_curr_p))) + { + goto fail; + } + + continue; + } + case RE_OP_ASSERT_LINE_END: + { + if (str_curr_p >= re_ctx_p->input_end_p) + { + continue; + } + + if (!(re_ctx_p->flags & RE_FLAG_MULTILINE) || !lit_char_is_line_terminator (lit_cesu8_peek_next (str_curr_p))) + { + goto fail; + } + + continue; + } + case RE_OP_ASSERT_WORD_BOUNDARY: + { + if (!ecma_regexp_is_word_boundary (re_ctx_p, str_curr_p)) + { + goto fail; + } + + continue; + } + case RE_OP_ASSERT_NOT_WORD_BOUNDARY: + { + if (ecma_regexp_is_word_boundary (re_ctx_p, str_curr_p)) + { + goto fail; + } + + continue; + } + case RE_OP_ASSERT_LOOKAHEAD_POS: + { + const uint8_t qmin = re_get_byte (&bc_p); + const uint32_t capture_start = re_get_value (&bc_p); + const uint32_t capture_count = re_get_value (&bc_p); + const uint32_t end_offset = re_get_value (&bc_p); + + /* If qmin is zero, the assertion implicitly matches. */ + if (qmin == 0) + { + bc_p += end_offset; + continue; + } + + /* Capture end pointers might get clobbered and need to be restored after a tail match fail. */ + JERRY_VLA (const lit_utf8_byte_t *, saved_captures_p, capture_count); + for (uint32_t i = 0; i < capture_count; ++i) + { + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + capture_start + i; + saved_captures_p[i] = capture_p->end_p; + } + + /* The first iteration will decide whether the assertion matches depending on whether + * the iteration matched or not. */ + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (ECMA_RE_STACK_LIMIT_REACHED (matched_p)) + { + return matched_p; + } + + if (matched_p == NULL) + { + goto fail; + } + + const lit_utf8_byte_t *tail_match_p = ecma_regexp_run (re_ctx_p, bc_p + end_offset, str_curr_p); + + if (tail_match_p == NULL) + { + for (uint32_t i = 0; i < capture_count; ++i) + { + ecma_regexp_capture_t *const capture_p = re_ctx_p->captures_p + capture_start + i; + capture_p->begin_p = NULL; + capture_p->end_p = saved_captures_p[i]; + } + + goto fail; + } + + return tail_match_p; + } + case RE_OP_ASSERT_LOOKAHEAD_NEG: + { + const uint8_t qmin = re_get_byte (&bc_p); + uint32_t capture_idx = re_get_value (&bc_p); + const uint32_t capture_count = re_get_value (&bc_p); + const uint32_t end_offset = re_get_value (&bc_p); + + /* If qmin is zero, the assertion implicitly matches. */ + if (qmin > 0) + { + /* The first iteration will decide whether the assertion matches depending on whether + * the iteration matched or not. */ + const lit_utf8_byte_t *const matched_p = ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); + + if (ECMA_RE_STACK_LIMIT_REACHED (matched_p)) + { + return matched_p; + } + + if (matched_p != NULL) + { + /* Nested capturing groups inside a negative lookahead can never capture, so we clear their results. */ + const uint32_t capture_end = capture_idx + capture_count; + while (capture_idx < capture_end) + { + re_ctx_p->captures_p[capture_idx++].begin_p = NULL; + } + + goto fail; + } + } + + bc_p += end_offset; + continue; + } + case RE_OP_CLASS_ESCAPE: + { + if (str_curr_p >= re_ctx_p->input_end_p) + { + goto fail; + } + + const lit_code_point_t cp = ecma_regexp_advance (re_ctx_p, &str_curr_p); + + const ecma_class_escape_t escape = (ecma_class_escape_t) re_get_byte (&bc_p); + if (!ecma_regexp_check_class_escape (cp, escape)) + { + goto fail; + } + + continue; + } + case RE_OP_CHAR_CLASS: + { + if (str_curr_p >= re_ctx_p->input_end_p) + { + goto fail; + } + + uint8_t flags = re_get_byte (&bc_p); + uint32_t char_count = (flags & RE_CLASS_HAS_CHARS) ? re_get_value (&bc_p) : 0; + uint32_t range_count = (flags & RE_CLASS_HAS_RANGES) ? re_get_value (&bc_p) : 0; + + const lit_code_point_t cp = ecma_regexp_advance (re_ctx_p, &str_curr_p); + + uint8_t escape_count = flags & RE_CLASS_ESCAPE_COUNT_MASK; + while (escape_count > 0) + { + escape_count--; + const ecma_class_escape_t escape = (ecma_class_escape_t) re_get_byte (&bc_p); + if (ecma_regexp_check_class_escape (cp, escape)) + { + goto class_found; + } + } + + while (char_count > 0) + { + char_count--; + const lit_code_point_t curr = re_get_char (&bc_p, re_ctx_p->flags & RE_FLAG_UNICODE); + if (cp == curr) + { + goto class_found; + } + } + + while (range_count > 0) + { + range_count--; + const lit_code_point_t begin = re_get_char (&bc_p, re_ctx_p->flags & RE_FLAG_UNICODE); + + if (cp < begin) + { + bc_p += re_ctx_p->char_size; + continue; + } + + const lit_code_point_t end = re_get_char (&bc_p, re_ctx_p->flags & RE_FLAG_UNICODE); + if (cp <= end) + { + goto class_found; + } + } + + /* Not found */ + if (flags & RE_CLASS_INVERT) + { + continue; + } + + goto fail; + +class_found: + if (flags & RE_CLASS_INVERT) + { + goto fail; + } + + const uint32_t chars_size = char_count * re_ctx_p->char_size; + const uint32_t ranges_size = range_count * re_ctx_p->char_size * 2; + bc_p = bc_p + escape_count + chars_size + ranges_size; + continue; + } + case RE_OP_UNICODE_PERIOD: + { + if (str_curr_p >= re_ctx_p->input_end_p) + { + goto fail; + } + + const lit_code_point_t cp = ecma_regexp_unicode_advance (&str_curr_p, re_ctx_p->input_end_p); + + if (!(re_ctx_p->flags & RE_FLAG_DOTALL) + && JERRY_UNLIKELY (cp <= LIT_UTF16_CODE_UNIT_MAX && lit_char_is_line_terminator ((ecma_char_t) cp))) + { + goto fail; + } + + continue; + } + case RE_OP_PERIOD: + { + if (str_curr_p >= re_ctx_p->input_end_p) + { + goto fail; + } + + const ecma_char_t ch = lit_cesu8_read_next (&str_curr_p); + + if (!(re_ctx_p->flags & RE_FLAG_DOTALL) && lit_char_is_line_terminator (ch)) + { + goto fail; + } + + continue; + } + case RE_OP_CHAR: + { + if (str_curr_p >= re_ctx_p->input_end_p) + { + goto fail; + } + + const lit_code_point_t ch1 = re_get_char (&bc_p, re_ctx_p->flags & RE_FLAG_UNICODE); + const lit_code_point_t ch2 = ecma_regexp_advance (re_ctx_p, &str_curr_p); + + if (ch1 != ch2) + { + goto fail; + } + + continue; + } + default: + { + JERRY_ASSERT (op == RE_OP_BYTE); + + if (str_curr_p >= re_ctx_p->input_end_p || *bc_p++ != *str_curr_p++) + { + goto fail; + } + + continue; + } + } + + JERRY_UNREACHABLE (); +fail: + bc_p = next_alternative_p; + + if (bc_p == NULL || *bc_p++ != RE_OP_ALTERNATIVE_NEXT) + { + /* None of the alternatives matched. */ + return NULL; + } + + /* Get the end of the new alternative and continue execution. */ + str_curr_p = str_start_p; + const uint32_t offset = re_get_value (&bc_p); + next_alternative_p = bc_p + offset; + } +} /* ecma_regexp_run */ + +/** + * Match a RegExp at a specific position in the input string. + * + * @return pointer to the end of the matched sub-string + * NULL, if pattern did not match + */ +static const lit_utf8_byte_t * +ecma_regexp_match (ecma_regexp_ctx_t *re_ctx_p, /**< RegExp matcher context */ + const uint8_t *bc_p, /**< pointer to the current RegExp bytecode */ + const lit_utf8_byte_t *str_curr_p) /**< input string pointer */ +{ + re_ctx_p->captures_p[RE_GLOBAL_CAPTURE].begin_p = str_curr_p; + + for (uint32_t i = 1; i < re_ctx_p->captures_count; ++i) + { + re_ctx_p->captures_p[i].begin_p = NULL; + } + + return ecma_regexp_run (re_ctx_p, bc_p, str_curr_p); +} /* ecma_regexp_match */ + +/* + * Helper function to get the result of a capture + * + * @return string value, if capture is defined + * undefined, otherwise + */ +ecma_value_t +ecma_regexp_get_capture_value (const ecma_regexp_capture_t *const capture_p) /**< capture */ +{ + if (ECMA_RE_IS_CAPTURE_DEFINED (capture_p)) + { + JERRY_ASSERT (capture_p->end_p >= capture_p->begin_p); + const lit_utf8_size_t capture_size = (lit_utf8_size_t) (capture_p->end_p - capture_p->begin_p); + ecma_string_t *const capture_str_p = ecma_new_ecma_string_from_utf8 (capture_p->begin_p, capture_size); + return ecma_make_string_value (capture_str_p); + } + + return ECMA_VALUE_UNDEFINED; +} /* ecma_regexp_get_capture_value */ + +/** + * Helper function to create a result array from the captures in a regexp context + * + * @return ecma value containing the created array object + */ +static ecma_value_t +ecma_regexp_create_result_object (ecma_regexp_ctx_t *re_ctx_p, /**< regexp context */ + ecma_string_t *input_string_p, /**< input ecma string */ + uint32_t index) /**< match index */ +{ + ecma_object_t *result_p = ecma_op_new_array_object (0); + + for (uint32_t i = 0; i < re_ctx_p->captures_count; i++) + { + ecma_value_t capture_value = ecma_regexp_get_capture_value (re_ctx_p->captures_p + i); + ecma_builtin_helper_def_prop_by_index (result_p, i, capture_value, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_free_value (capture_value); + } + + ecma_builtin_helper_def_prop (result_p, + ecma_get_magic_string (LIT_MAGIC_STRING_INDEX), + ecma_make_uint32_value (index), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + + ecma_builtin_helper_def_prop (result_p, + ecma_get_magic_string (LIT_MAGIC_STRING_INPUT), + ecma_make_string_value (input_string_p), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + + return ecma_make_object_value (result_p); +} /* ecma_regexp_create_result_object */ + +/** + * Helper function to initialize a regexp match context + */ +static void +ecma_regexp_initialize_context (ecma_regexp_ctx_t *ctx_p, /**< regexp context */ + const re_compiled_code_t *bc_p, /**< regexp bytecode */ + const lit_utf8_byte_t *input_start_p, /**< pointer to input string */ + const lit_utf8_byte_t *input_end_p) /**< pointer to end of input string */ +{ + JERRY_ASSERT (ctx_p != NULL); + JERRY_ASSERT (bc_p != NULL); + JERRY_ASSERT (input_start_p != NULL); + JERRY_ASSERT (input_end_p >= input_start_p); + + ctx_p->flags = bc_p->header.status_flags; + ctx_p->char_size = (ctx_p->flags & RE_FLAG_UNICODE) ? sizeof (lit_code_point_t) : sizeof (ecma_char_t); + + ctx_p->input_start_p = input_start_p; + ctx_p->input_end_p = input_end_p; + + ctx_p->captures_count = bc_p->captures_count; + ctx_p->non_captures_count = bc_p->non_captures_count; + + ctx_p->captures_p = (ecma_regexp_capture_t *) jmem_heap_alloc_block (ctx_p->captures_count * sizeof (ecma_regexp_capture_t)); + + if (ctx_p->non_captures_count > 0) + { + ctx_p->non_captures_p = (ecma_regexp_non_capture_t *) jmem_heap_alloc_block (ctx_p->non_captures_count * sizeof (ecma_regexp_non_capture_t)); + } +} /* ecma_regexp_initialize_context */ + +/** + * Helper function to clean up a regexp context + */ +static void +ecma_regexp_cleanup_context (ecma_regexp_ctx_t *ctx_p) /**< regexp context */ +{ + JERRY_ASSERT (ctx_p != NULL); + jmem_heap_free_block (ctx_p->captures_p, ctx_p->captures_count * sizeof (ecma_regexp_capture_t)); + + if (ctx_p->non_captures_count > 0) + { + jmem_heap_free_block (ctx_p->non_captures_p, ctx_p->non_captures_count * sizeof (ecma_regexp_non_capture_t)); + } +} /* ecma_regexp_cleanup_context */ + +/** + * RegExp helper function to start the recursive matching algorithm + * and create the result Array object + * + * See also: + * ECMA-262 v5, 15.10.6.2 + * ECMA-262 v11, 21.2.5.2.2 + * + * @return array object - if matched + * null - otherwise + * + * May raise error. + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_regexp_exec_helper (ecma_object_t *regexp_object_p, /**< RegExp object */ + ecma_string_t *input_string_p) /**< input string */ +{ + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + lit_utf8_byte_t *matched_p; + uint8_t *bc_start_p; + + /* 1. */ + JERRY_ASSERT (ecma_object_is_regexp_object (ecma_make_object_value (regexp_object_p))); + + /* 9. */ + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) regexp_object_p; + re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, ext_object_p->u.cls.u3.value); + + /* 3. */ + lit_utf8_size_t input_size; + lit_utf8_size_t input_length; + uint8_t input_flags = ECMA_STRING_FLAG_IS_ASCII; + const lit_utf8_byte_t *input_buffer_p = + ecma_string_get_chars (input_string_p, &input_size, &input_length, NULL, &input_flags); + + const lit_utf8_byte_t *input_curr_p = input_buffer_p; + const lit_utf8_byte_t *input_end_p = input_buffer_p + input_size; + + ecma_regexp_ctx_t re_ctx; + ecma_regexp_initialize_context (&re_ctx, bc_p, input_buffer_p, input_end_p); + + /* 4. */ + ecma_length_t index = 0; + ecma_value_t lastindex_value = ecma_op_object_get_by_magic_id (regexp_object_p, LIT_MAGIC_STRING_LASTINDEX_UL); + + ret_value = ecma_op_to_length (lastindex_value, &index); + ecma_free_value (lastindex_value); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + goto cleanup_context; + } + + if (re_ctx.flags & (RE_FLAG_GLOBAL | RE_FLAG_STICKY)) + { + /* 12.a */ + if (index > input_length) + { + goto fail_put_lastindex; + } + + if (index > 0) + { + if (input_flags & ECMA_STRING_FLAG_IS_ASCII) + { + input_curr_p += index; + } + else + { + for (uint32_t i = 0; i < index; i++) + { + lit_utf8_incr (&input_curr_p); + } + } + } + } + /* 8. */ + else + { + index = 0; + } + + /* 9. */ + bc_start_p = (uint8_t *) (bc_p + 1); + + /* 11. */ + matched_p = NULL; + + /* 12. */ + JERRY_ASSERT (index <= input_length); + while (true) + { + matched_p = (lit_utf8_byte_t *) ecma_regexp_match (&re_ctx, bc_start_p, input_curr_p); + + if (matched_p != NULL) + { + goto match_found; + } + + /* 12.c.i */ + if (re_ctx.flags & RE_FLAG_STICKY) + { + goto fail_put_lastindex; + } + + /* 12.a */ + if (input_curr_p >= input_end_p) + { + if (re_ctx.flags & RE_FLAG_GLOBAL) + { + goto fail_put_lastindex; + } + + goto match_failed; + } + + JERRY_ASSERT (input_curr_p < input_end_p); + + /* 12.c.ii */ + index++; + + if (re_ctx.flags & RE_FLAG_UNICODE) + { + const lit_code_point_t cp = ecma_regexp_unicode_advance (&input_curr_p, input_end_p); + + if (cp > LIT_UTF16_CODE_UNIT_MAX) + { + index++; + } + + continue; + } + + lit_utf8_incr (&input_curr_p); + } + + JERRY_UNREACHABLE (); + +fail_put_lastindex: + /* We should only get here if the regexp is global or sticky */ + JERRY_ASSERT ((re_ctx.flags & (RE_FLAG_GLOBAL | RE_FLAG_STICKY)) != 0); + + ret_value = ecma_op_object_put (regexp_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_integer_value (0), + true); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + goto cleanup_context; + } + + JERRY_ASSERT (ecma_is_value_boolean (ret_value)); + +match_failed: + /* 12.a.ii */ + ret_value = ECMA_VALUE_NULL; + goto cleanup_context; + +match_found: + JERRY_ASSERT (matched_p != NULL); + + if (ECMA_RE_STACK_LIMIT_REACHED (matched_p)) + { + ret_value = ecma_raise_range_error (ECMA_ERR_STACK_LIMIT_EXCEEDED); + goto cleanup_context; + } + + JERRY_ASSERT (index <= input_length); + + /* 15. */ + if (re_ctx.flags & (RE_FLAG_GLOBAL | RE_FLAG_STICKY)) + { + /* 13-14. */ + lit_utf8_size_t match_length; + const lit_utf8_byte_t *match_begin_p = re_ctx.captures_p[0].begin_p; + const lit_utf8_byte_t *match_end_p = re_ctx.captures_p[0].end_p; + + if (input_flags & ECMA_STRING_FLAG_IS_ASCII) + { + match_length = (lit_utf8_size_t) (match_end_p - match_begin_p); + } + else + { + match_length = lit_utf8_string_length (match_begin_p, (lit_utf8_size_t) (match_end_p - match_begin_p)); + } + + ret_value = ecma_op_object_put (regexp_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_uint32_value ((uint32_t) index + match_length), + true); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + goto cleanup_context; + } + + JERRY_ASSERT (ecma_is_value_boolean (ret_value)); + } + + /* 16-27. */ + ret_value = ecma_regexp_create_result_object (&re_ctx, input_string_p, (uint32_t) index); + +cleanup_context: + ecma_regexp_cleanup_context (&re_ctx); + + if (input_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) input_buffer_p, input_size); + } + + return ret_value; +} /* ecma_regexp_exec_helper */ + +/** + * Helper function for converting a RegExp pattern parameter to string. + * + * See also: + * RegExp.compile + * RegExp dispatch call + * + * @return empty value if success, error value otherwise + * Returned value must be freed with ecma_free_value. + */ +ecma_string_t * +ecma_regexp_read_pattern_str_helper (ecma_value_t pattern_arg) /**< the RegExp pattern */ +{ + if (!ecma_is_value_undefined (pattern_arg)) + { + ecma_string_t *pattern_string_p = ecma_op_to_string (pattern_arg); + if (JERRY_UNLIKELY (pattern_string_p == NULL) || !ecma_string_is_empty (pattern_string_p)) + { + return pattern_string_p; + } + } + + return ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP); +} /* ecma_regexp_read_pattern_str_helper */ + +/** + * Helper function for RegExp based string searches + * + * See also: + * ECMA-262 v6, 21.2.5.9 + * + * @return index of the match + */ +ecma_value_t +ecma_regexp_search_helper (ecma_value_t regexp_arg, /**< regexp argument */ + ecma_value_t string_arg) /**< string argument */ +{ + /* 2. */ + if (!ecma_is_value_object (regexp_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_value_t result = ECMA_VALUE_ERROR; + ecma_value_t current_last_index; + ecma_value_t match; + bool same_value; + + /* 3. */ + ecma_string_t *const string_p = ecma_op_to_string (string_arg); + if (string_p == NULL) + { + return result; + } + + ecma_object_t *const regexp_object_p = ecma_get_object_from_value (regexp_arg); + + /* 4. */ + ecma_string_t *const last_index_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL); + const ecma_value_t prev_last_index = ecma_op_object_get (regexp_object_p, last_index_str_p); + if (ECMA_IS_VALUE_ERROR (prev_last_index)) + { + goto cleanup_string; + } + + /* 5. */ + if (prev_last_index != ecma_make_uint32_value (0)) + { + const ecma_value_t status = + ecma_op_object_put (regexp_object_p, last_index_str_p, ecma_make_uint32_value (0), true); + + if (ECMA_IS_VALUE_ERROR (status)) + { + goto cleanup_prev_last_index; + } + + JERRY_ASSERT (ecma_is_value_boolean (status)); + } + + /* 6. */ + match = ecma_op_regexp_exec (regexp_arg, string_p); + if (ECMA_IS_VALUE_ERROR (match)) + { + goto cleanup_prev_last_index; + } + + /* 7. */ + current_last_index = ecma_op_object_get (regexp_object_p, last_index_str_p); + if (ECMA_IS_VALUE_ERROR (current_last_index)) + { + ecma_free_value (match); + goto cleanup_prev_last_index; + } + + same_value = ecma_op_same_value (prev_last_index, current_last_index); + + ecma_free_value (current_last_index); + + /* 8. */ + if (!same_value) + { + result = ecma_op_object_put (regexp_object_p, last_index_str_p, prev_last_index, true); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_free_value (match); + goto cleanup_prev_last_index; + } + + JERRY_ASSERT (ecma_is_value_boolean (result)); + } + + /* 9-10. */ + if (ecma_is_value_null (match)) + { + result = ecma_make_int32_value (-1); + } + else + { + ecma_object_t *const match_p = ecma_get_object_from_value (match); + result = ecma_op_object_get_by_magic_id (match_p, LIT_MAGIC_STRING_INDEX); + ecma_deref_object (match_p); + } + +cleanup_prev_last_index: + ecma_free_value (prev_last_index); + +cleanup_string: + ecma_deref_ecma_string (string_p); + return result; +} /* ecma_regexp_search_helper */ + +/** + * Helper function for RegExp based string split operation + * + * See also: + * ECMA-262 v6, 21.2.5.11 + * + * @return array of split and captured strings + */ +ecma_value_t +ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */ + ecma_value_t string_arg, /**< string value */ + ecma_value_t limit_arg) /**< limit value */ +{ + /* 2. */ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_value_t result = ECMA_VALUE_ERROR; + ecma_length_t current_index; + ecma_length_t previous_index; + ecma_object_t *constructor_obj_p; + ecma_value_t flags; + ecma_string_t *flags_str_p; + lit_utf8_size_t flags_size; + uint8_t flags_str_flags; + lit_utf8_byte_t *flags_buffer_p; + lit_utf8_byte_t *flags_end_p; + ecma_value_t arguments[2]; + ecma_value_t splitter; + ecma_object_t *splitter_obj_p; + ecma_object_t *array_p; + ecma_value_t array; + ecma_string_t *end_str_p; + ecma_string_t *lastindex_str_p; + lit_utf8_size_t string_length; + uint32_t array_length; + uint32_t limit; + bool unicode; + bool sticky; + + /* 3-4. */ + ecma_string_t *const string_p = ecma_op_to_string (string_arg); + if (string_p == NULL) + { + return result; + } + + /* 5-6. */ + ecma_object_t *const regexp_obj_p = ecma_get_object_from_value (this_arg); + ecma_value_t constructor = ecma_op_species_constructor (regexp_obj_p, ECMA_BUILTIN_ID_REGEXP); + if (ECMA_IS_VALUE_ERROR (constructor)) + { + goto cleanup_string; + } + + constructor_obj_p = ecma_get_object_from_value (constructor); + + /* 7-8. */ + flags = ecma_op_object_get_by_magic_id (regexp_obj_p, LIT_MAGIC_STRING_FLAGS); + if (ECMA_IS_VALUE_ERROR (flags)) + { + ecma_deref_object (constructor_obj_p); + goto cleanup_string; + } + + flags_str_p = ecma_op_to_string (flags); + ecma_free_value (flags); + + if (JERRY_UNLIKELY (flags_str_p == NULL)) + { + ecma_deref_object (constructor_obj_p); + goto cleanup_string; + } + + flags_str_flags = ECMA_STRING_FLAG_IS_ASCII; + flags_buffer_p = (lit_utf8_byte_t *) ecma_string_get_chars (flags_str_p, &flags_size, NULL, NULL, &flags_str_flags); + + unicode = false; + sticky = false; + + /* 9-11. */ + flags_end_p = flags_buffer_p + flags_size; + for (const lit_utf8_byte_t *current_p = flags_buffer_p; current_p < flags_end_p; ++current_p) + { + switch (*current_p) + { + case LIT_CHAR_LOWERCASE_U: + { + unicode = true; + break; + } + case LIT_CHAR_LOWERCASE_Y: + { + sticky = true; + break; + } + } + } + + if (flags_str_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) flags_buffer_p, flags_size); + } + + /* 12. */ + if (!sticky) + { + ecma_stringbuilder_t builder = ecma_stringbuilder_create_from (flags_str_p); + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_LOWERCASE_Y); + + ecma_deref_ecma_string (flags_str_p); + flags_str_p = ecma_stringbuilder_finalize (&builder); + } + + /* 13-14. */ + arguments[0] = this_arg; + arguments[1] = ecma_make_string_value (flags_str_p); + splitter = ecma_op_function_construct (constructor_obj_p, constructor_obj_p, arguments, 2); + + ecma_deref_ecma_string (flags_str_p); + ecma_deref_object (constructor_obj_p); + + if (ECMA_IS_VALUE_ERROR (splitter)) + { + goto cleanup_string; + } + + splitter_obj_p = ecma_get_object_from_value (splitter); + + /* 17. */ + limit = UINT32_MAX - 1; + if (!ecma_is_value_undefined (limit_arg)) + { + /* ECMA-262 v11, 21.2.5.13 13 */ + ecma_number_t num; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (limit_arg, &num))) + { + goto cleanup_splitter; + } + limit = ecma_number_to_uint32 (num); + } + + /* 15. */ + array_p = ecma_op_new_array_object (0); + array = ecma_make_object_value (array_p); + + /* 21. */ + if (limit == 0) + { + result = array; + goto cleanup_splitter; + } + + string_length = ecma_string_get_length (string_p); + array_length = 0; + + /* 22. */ + if (string_length == 0) + { + const ecma_value_t match = ecma_op_regexp_exec (splitter, string_p); + + if (ECMA_IS_VALUE_ERROR (match)) + { + goto cleanup_array; + } + + if (ecma_is_value_null (match)) + { + result = ecma_builtin_helper_def_prop_by_index (array_p, + array_length, + ecma_make_string_value (string_p), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + JERRY_ASSERT (ecma_is_value_true (result)); + } + + ecma_free_value (match); + result = array; + goto cleanup_splitter; + } + + /* 23. */ + current_index = 0; + previous_index = 0; + + lastindex_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL); + + /* 24. */ + while (current_index < string_length) + { + /* 24.a-b. */ + ecma_value_t index_value = ecma_make_length_value (current_index); + result = ecma_op_object_put (splitter_obj_p, lastindex_str_p, index_value, true); + + ecma_free_value (index_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_array; + } + + JERRY_ASSERT (ecma_is_value_true (result)); + + /* 24.c-d. */ + result = ecma_op_regexp_exec (splitter, string_p); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_array; + } + + /* 24.e. */ + if (ecma_is_value_null (result)) + { + current_index = ecma_op_advance_string_index (string_p, current_index, unicode); + continue; + } + + ecma_object_t *const match_array_p = ecma_get_object_from_value (result); + + /* 24.f.i. */ + result = ecma_op_object_get (splitter_obj_p, lastindex_str_p); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (match_array_p); + goto cleanup_array; + } + + ecma_length_t end_index; + const ecma_value_t length_value = ecma_op_to_length (result, &end_index); + ecma_free_value (result); + + if (ECMA_IS_VALUE_ERROR (length_value)) + { + result = ECMA_VALUE_ERROR; + ecma_deref_object (match_array_p); + goto cleanup_array; + } + + /* ECMA-262 v11, 21.2.5.11 19.d.ii */ + if (end_index > string_length) + { + end_index = string_length; + } + + /* 24.f.iii. */ + if (previous_index == end_index) + { + ecma_deref_object (match_array_p); + current_index = ecma_op_advance_string_index (string_p, current_index, unicode); + continue; + } + + /* 24.f.iv.1-4. */ + JERRY_ASSERT (previous_index <= string_length && current_index <= string_length); + ecma_string_t *const split_str_p = + ecma_string_substr (string_p, (lit_utf8_size_t) previous_index, (lit_utf8_size_t) current_index); + + result = ecma_builtin_helper_def_prop_by_index (array_p, + array_length++, + ecma_make_string_value (split_str_p), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + JERRY_ASSERT (ecma_is_value_true (result)); + ecma_deref_ecma_string (split_str_p); + + /* 24.f.iv.5. */ + if (array_length == limit) + { + ecma_deref_object (match_array_p); + result = array; + goto cleanup_splitter; + } + + /* 24.f.iv.6. */ + previous_index = end_index; + + /* 24.f.iv.7-8. */ + ecma_length_t match_length; + result = ecma_op_object_get_length (match_array_p, &match_length); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (match_array_p); + goto cleanup_array; + } + + /* 24.f.iv.9. */ + match_length = (match_length > 0) ? match_length - 1 : match_length; + + ecma_length_t match_index = 1; + while (match_index <= match_length) + { + /* 24.f.iv.11.a-b. */ + result = ecma_op_object_get_by_index (match_array_p, match_index++); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_object (match_array_p); + goto cleanup_array; + } + + const ecma_value_t capture = result; + + /* 24.f.iv.11.c. */ + result = ecma_builtin_helper_def_prop_by_index (array_p, + array_length++, + capture, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + JERRY_ASSERT (ecma_is_value_true (result)); + + ecma_free_value (capture); + + if (array_length == limit) + { + ecma_deref_object (match_array_p); + result = array; + goto cleanup_splitter; + } + } + + /* 24.f.iv.12. */ + JERRY_ASSERT (end_index <= UINT32_MAX); + current_index = (uint32_t) end_index; + + ecma_deref_object (match_array_p); + } + + JERRY_ASSERT (previous_index <= string_length); + end_str_p = ecma_string_substr (string_p, (lit_utf8_size_t) previous_index, string_length); + result = ecma_builtin_helper_def_prop_by_index (array_p, + array_length++, + ecma_make_string_value (end_str_p), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + JERRY_ASSERT (ecma_is_value_true (result)); + ecma_deref_ecma_string (end_str_p); + + result = array; + goto cleanup_splitter; + +cleanup_array: + ecma_deref_object (array_p); +cleanup_splitter: + ecma_deref_object (splitter_obj_p); +cleanup_string: + ecma_deref_ecma_string (string_p); + + return result; +} /* ecma_regexp_split_helper */ + +/** + * Fast path for RegExp based replace operation + * + * This method assumes the following: + * - The RegExp object is a built-in RegExp + * - The 'exec' method of the RegExp object is the built-in 'exec' method + * - The 'lastIndex' property is writable + * + * The standard would normally require us to first execute the regexp and collect the results, + * and after that iterate over the collected results and replace them. + * The assumptions above guarantee that during the matching phase there will be no exceptions thrown, + * which means we can do the match/replace in a single loop, without collecting the results. + * + * @return string value if successful + * thrown value otherwise + */ +static ecma_value_t +ecma_regexp_replace_helper_fast (ecma_replace_context_t *ctx_p, /**u.cls.u3.value); + ecma_bytecode_ref ((ecma_compiled_code_t *) bc_p); + + JERRY_ASSERT (bc_p != NULL); + + uint8_t string_flags = ECMA_STRING_FLAG_IS_ASCII; + lit_utf8_size_t string_length; + ctx_p->string_p = ecma_string_get_chars (string_p, &(ctx_p->string_size), &string_length, NULL, &string_flags); + + const lit_utf8_byte_t *const string_end_p = ctx_p->string_p + ctx_p->string_size; + const uint8_t *const bc_start_p = (const uint8_t *) (bc_p + 1); + const lit_utf8_byte_t *matched_p = NULL; + const lit_utf8_byte_t *current_p = ctx_p->string_p; + const lit_utf8_byte_t *last_append_p = current_p; + ecma_length_t index; + lit_utf8_size_t trailing_size; + + ecma_regexp_ctx_t re_ctx; + ecma_regexp_initialize_context (&re_ctx, bc_p, ctx_p->string_p, string_end_p); + + /* lastIndex must be accessed to remain consistent with the standard, even though we may not need the value. */ + ecma_value_t lastindex_value = + ecma_op_object_get_by_magic_id ((ecma_object_t *) re_obj_p, LIT_MAGIC_STRING_LASTINDEX_UL); + ecma_value_t result = ecma_op_to_length (lastindex_value, &index); + ecma_free_value (lastindex_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_context; + } + + /* Only non-global sticky matches use the lastIndex value, otherwise the starting index is 0. */ + if (JERRY_UNLIKELY ((ctx_p->flags & RE_FLAG_GLOBAL) == 0 && (re_ctx.flags & RE_FLAG_STICKY) != 0)) + { + if (index > string_length) + { + result = ecma_op_object_put ((ecma_object_t *) re_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_uint32_value (0), + true); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + JERRY_ASSERT (ecma_is_value_true (result)); + ecma_ref_ecma_string (string_p); + result = ecma_make_string_value (string_p); + } + + goto cleanup_context; + } + + if (string_flags & ECMA_STRING_FLAG_IS_ASCII) + { + current_p += index; + } + else + { + ecma_length_t counter = index; + while (counter--) + { + lit_utf8_incr (¤t_p); + } + } + } + else + { + index = 0; + } + + ctx_p->builder = ecma_stringbuilder_create (); + ctx_p->capture_count = re_ctx.captures_count; + ctx_p->u.captures_p = re_ctx.captures_p; + + while (true) + { + matched_p = ecma_regexp_match (&re_ctx, bc_start_p, current_p); + + if (matched_p != NULL) + { + if (ECMA_RE_STACK_LIMIT_REACHED (matched_p)) + { + result = ecma_raise_range_error (ECMA_ERR_STACK_LIMIT_EXCEEDED); + goto cleanup_builder; + } + + const lit_utf8_size_t remaining_size = (lit_utf8_size_t) (current_p - last_append_p); + ecma_stringbuilder_append_raw (&(ctx_p->builder), last_append_p, remaining_size); + + if (ctx_p->replace_str_p != NULL) + { + ctx_p->matched_p = current_p; + const ecma_regexp_capture_t *const global_capture_p = re_ctx.captures_p; + ctx_p->matched_size = (lit_utf8_size_t) (global_capture_p->end_p - global_capture_p->begin_p); + ctx_p->match_byte_pos = (lit_utf8_size_t) (current_p - re_ctx.input_start_p); + + ecma_builtin_replace_substitute (ctx_p); + } + else + { + ecma_collection_t *arguments_p = ecma_new_collection (); + + for (uint32_t i = 0; i < re_ctx.captures_count; i++) + { + ecma_value_t capture = ecma_regexp_get_capture_value (re_ctx.captures_p + i); + ecma_collection_push_back (arguments_p, capture); + } + + ecma_collection_push_back (arguments_p, ecma_make_length_value (index)); + ecma_ref_ecma_string (string_p); + ecma_collection_push_back (arguments_p, ecma_make_string_value (string_p)); + ecma_object_t *function_p = ecma_get_object_from_value (replace_arg); + + result = + ecma_op_function_call (function_p, ECMA_VALUE_UNDEFINED, arguments_p->buffer_p, arguments_p->item_count); + + ecma_collection_free (arguments_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_builder; + } + + /* 16.m.v */ + ecma_string_t *const replace_result_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (replace_result_p == NULL) + { + result = ECMA_VALUE_ERROR; + goto cleanup_builder; + } + + ecma_stringbuilder_append (&(ctx_p->builder), replace_result_p); + ecma_deref_ecma_string (replace_result_p); + } + + const ecma_regexp_capture_t *global_capture_p = re_ctx.captures_p; + last_append_p = global_capture_p->end_p; + + const lit_utf8_size_t matched_size = (lit_utf8_size_t) (global_capture_p->end_p - global_capture_p->begin_p); + + const bool is_ascii = (string_flags & ECMA_STRING_FLAG_IS_ASCII) != 0; + index += is_ascii ? matched_size : lit_utf8_string_length (current_p, matched_size); + + if (!(ctx_p->flags & RE_FLAG_GLOBAL)) + { + if (JERRY_UNLIKELY ((re_ctx.flags & RE_FLAG_STICKY) != 0)) + { + ecma_value_t index_value = ecma_make_length_value (index); + result = ecma_op_object_put ((ecma_object_t *) re_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + index_value, + true); + + ecma_free_value (index_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_builder; + } + } + + break; + } + + if (matched_size > 0) + { + current_p = last_append_p; + continue; + } + } + else if (JERRY_UNLIKELY ((re_ctx.flags & RE_FLAG_STICKY) != 0)) + { + result = ecma_op_object_put ((ecma_object_t *) re_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_uint32_value (0), + true); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_builder; + } + + break; + } + + if (current_p >= string_end_p) + { + break; + } + + if ((ctx_p->flags & RE_FLAG_UNICODE) != 0) + { + index++; + const lit_code_point_t cp = ecma_regexp_unicode_advance (¤t_p, string_end_p); + + if (cp > LIT_UTF16_CODE_UNIT_MAX) + { + index++; + } + + continue; + } + + index++; + lit_utf8_incr (¤t_p); + } + + trailing_size = (lit_utf8_size_t) (string_end_p - last_append_p); + ecma_stringbuilder_append_raw (&(ctx_p->builder), last_append_p, trailing_size); + + result = ecma_make_string_value (ecma_stringbuilder_finalize (&(ctx_p->builder))); + goto cleanup_context; + +cleanup_builder: + ecma_stringbuilder_destroy (&(ctx_p->builder)); + +cleanup_context: + ecma_regexp_cleanup_context (&re_ctx); + ecma_bytecode_deref ((ecma_compiled_code_t *) bc_p); + + if (string_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) ctx_p->string_p, ctx_p->string_size); + } + + return result; +} /* ecma_regexp_replace_helper_fast */ + +/** + * Helper function for RegExp based replacing + * + * See also: + * String.prototype.replace + * RegExp.prototype[@@replace] + * + * @return result string of the replacement, if successful + * error value, otherwise + */ +ecma_value_t +ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */ + ecma_value_t string_arg, /**< source string */ + ecma_value_t replace_arg) /**< replace string */ +{ + /* 2. */ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + lit_utf8_size_t index; + uint8_t string_flags; + ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg); + ecma_replace_context_t replace_ctx; + ecma_collection_t *results_p; + lit_utf8_size_t string_length; + lit_utf8_byte_t *source_position_p; + lit_utf8_byte_t *string_end_p; + + replace_ctx.flags = RE_FLAG_EMPTY; + + /* 3. */ + ecma_string_t *string_p = ecma_op_to_string (string_arg); + if (string_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ECMA_VALUE_ERROR; + + /* 6. */ + replace_ctx.replace_str_p = NULL; + if (!ecma_op_is_callable (replace_arg)) + { + replace_ctx.replace_str_p = ecma_op_to_string (replace_arg); + + if (replace_ctx.replace_str_p == NULL) + { + goto cleanup_string; + } + } + + /* 8 */ + result = ecma_op_object_get_by_magic_id (this_obj_p, LIT_MAGIC_STRING_GLOBAL); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_replace; + } + + if (ecma_op_to_boolean (result)) + { + replace_ctx.flags |= RE_FLAG_GLOBAL; + } + + ecma_free_value (result); + + string_length = ecma_string_get_length (string_p); + + /* 10. */ + if (replace_ctx.flags & RE_FLAG_GLOBAL) + { + result = ecma_op_object_get_by_magic_id (this_obj_p, LIT_MAGIC_STRING_UNICODE); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_replace; + } + + if (ecma_op_to_boolean (result)) + { + replace_ctx.flags |= RE_FLAG_UNICODE; + } + + ecma_free_value (result); + + result = ecma_op_object_put (this_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), + ecma_make_uint32_value (0), + true); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_replace; + } + + JERRY_ASSERT (ecma_is_value_boolean (result)); + } + + result = ecma_op_object_get_by_magic_id (this_obj_p, LIT_MAGIC_STRING_EXEC); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_replace; + } + + /* Check for fast path. */ + if (ecma_op_is_callable (result)) + { + ecma_extended_object_t *function_p = (ecma_extended_object_t *) ecma_get_object_from_value (result); + if (ecma_object_class_is (this_obj_p, ECMA_OBJECT_CLASS_REGEXP) && ecma_builtin_is_regexp_exec (function_p)) + { + ecma_deref_object ((ecma_object_t *) function_p); + + result = + ecma_regexp_replace_helper_fast (&replace_ctx, (ecma_extended_object_t *) this_obj_p, string_p, replace_arg); + + goto cleanup_replace; + } + } + + results_p = ecma_new_collection (); + + while (true) + { + /* 13.a */ + if (ecma_op_is_callable (result)) + { + ecma_object_t *const function_p = ecma_get_object_from_value (result); + + ecma_value_t arguments[] = { ecma_make_string_value (string_p) }; + result = ecma_op_function_call (function_p, this_arg, arguments, 1); + + ecma_deref_object (function_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_results; + } + + if (!ecma_is_value_object (result) && !ecma_is_value_null (result)) + { + ecma_free_value (result); + result = ecma_raise_type_error (ECMA_ERR_RETURN_VALUE_OF_EXEC_MUST_BE_AN_OBJECT_OR_NULL); + goto cleanup_results; + } + } + else + { + ecma_free_value (result); + + if (!ecma_object_class_is (this_obj_p, ECMA_OBJECT_CLASS_REGEXP)) + { + result = ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP_OBJECT); + goto cleanup_results; + } + + result = ecma_regexp_exec_helper (this_obj_p, string_p); + } + + /* 13.c */ + if (ecma_is_value_null (result)) + { + break; + } + + /* 13.d.i */ + ecma_collection_push_back (results_p, result); + + if ((replace_ctx.flags & RE_FLAG_GLOBAL) == 0) + { + break; + } + + /* 13.d.iii.1 */ + result = ecma_op_object_get_by_index (ecma_get_object_from_value (result), 0); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_results; + } + + ecma_string_t *match_str_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (match_str_p == NULL) + { + result = ECMA_VALUE_ERROR; + goto cleanup_results; + } + + const bool is_empty = ecma_string_is_empty (match_str_p); + ecma_deref_ecma_string (match_str_p); + + /* 13.d.iii.3 */ + if (is_empty) + { + result = ecma_op_object_get_by_magic_id (this_obj_p, LIT_MAGIC_STRING_LASTINDEX_UL); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_results; + } + + ecma_value_t last_index = result; + + ecma_length_t index; + result = ecma_op_to_length (last_index, &index); + ecma_free_value (last_index); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_results; + } + + index = ecma_op_advance_string_index (string_p, index, (replace_ctx.flags & RE_FLAG_UNICODE) != 0); + last_index = ecma_make_length_value (index); + + /* 10.d.iii.3.c */ + result = ecma_op_object_put (this_obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), last_index, true); + + ecma_free_value (last_index); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_results; + } + + JERRY_ASSERT (ecma_is_value_boolean (result)); + } + + result = ecma_op_object_get_by_magic_id (this_obj_p, LIT_MAGIC_STRING_EXEC); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_results; + } + } + + string_flags = ECMA_STRING_FLAG_IS_ASCII; + replace_ctx.string_p = ecma_string_get_chars (string_p, &(replace_ctx.string_size), NULL, NULL, &string_flags); + + /* 14. */ + replace_ctx.builder = ecma_stringbuilder_create (); + replace_ctx.matched_p = NULL; + replace_ctx.capture_count = 0; + index = 0; + + /* 15. */ + source_position_p = (lit_utf8_byte_t*) replace_ctx.string_p; + string_end_p = (lit_utf8_byte_t*) replace_ctx.string_p + replace_ctx.string_size; + + /* 16. */ + for (ecma_value_t *current_p = results_p->buffer_p; current_p < results_p->buffer_p + results_p->item_count; + current_p++) + { + /* 16.a */ + ecma_object_t *current_object_p = ecma_get_object_from_value (*current_p); + + ecma_length_t capture_count; + result = ecma_op_object_get_length (current_object_p, &capture_count); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_builder; + } + + /* 16.c */ + capture_count = (capture_count > 0) ? capture_count - 1 : capture_count; + + /* 16.d */ + result = ecma_op_object_get_by_index (current_object_p, 0); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_builder; + } + + ecma_string_t *matched_str_p = ecma_op_to_string (result); + ecma_free_value (result); + + /* 16.e */ + if (matched_str_p == NULL) + { + result = ECMA_VALUE_ERROR; + goto cleanup_builder; + } + + /* 16.g */ + result = ecma_op_object_get_by_magic_id (current_object_p, LIT_MAGIC_STRING_INDEX); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_ecma_string (matched_str_p); + goto cleanup_builder; + } + + const ecma_value_t index_value = result; + + ecma_number_t position_num; + result = ecma_op_to_integer (index_value, &position_num); + ecma_free_value (index_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_deref_ecma_string (matched_str_p); + goto cleanup_builder; + } + + /* 16.i */ + lit_utf8_size_t position = JERRY_MIN ((lit_utf8_size_t) JERRY_MAX (position_num, 0.0f), string_length); + + /* 16.k */ + ecma_collection_t *arguments_p = ecma_new_collection (); + ecma_collection_push_back (arguments_p, ecma_make_string_value (matched_str_p)); + + /* 16.j, l */ + ecma_length_t n = 1; + while (n <= capture_count) + { + result = ecma_op_object_get_by_index (current_object_p, n); + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_collection_free (arguments_p); + goto cleanup_builder; + } + + /* 16.l.iii */ + if (!ecma_is_value_undefined (result)) + { + ecma_string_t *capture_str_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (capture_str_p == NULL) + { + ecma_collection_free (arguments_p); + result = ECMA_VALUE_ERROR; + goto cleanup_builder; + } + + result = ecma_make_string_value (capture_str_p); + } + + /* 16.l.iv */ + ecma_collection_push_back (arguments_p, result); + n++; + } + + const bool should_replace = (position >= index); + /* 16.p */ + if (should_replace) + { + const lit_utf8_byte_t *match_position_p; + const lit_utf8_size_t matched_str_size = ecma_string_get_size (matched_str_p); + const lit_utf8_size_t matched_str_length = ecma_string_get_length (matched_str_p); + + if (string_flags & ECMA_STRING_FLAG_IS_ASCII) + { + match_position_p = replace_ctx.string_p + position; + } + else + { + match_position_p = source_position_p; + lit_utf8_size_t distance = position - index; + while (distance--) + { + lit_utf8_incr (&match_position_p); + } + } + + ecma_stringbuilder_append_raw (&replace_ctx.builder, + source_position_p, + (lit_utf8_size_t) (match_position_p - source_position_p)); + replace_ctx.match_byte_pos = (lit_utf8_size_t) (match_position_p - replace_ctx.string_p); + + if ((string_flags & ECMA_STRING_FLAG_IS_ASCII) && matched_str_size == matched_str_length) + { + source_position_p = (lit_utf8_byte_t*) JERRY_MIN (match_position_p + matched_str_size, string_end_p); + } + else + { + lit_utf8_size_t code_unit_count = matched_str_length; + + while (code_unit_count-- > 0 && JERRY_LIKELY (match_position_p < string_end_p)) + { + lit_utf8_incr (&match_position_p); + } + + source_position_p = (lit_utf8_byte_t*) match_position_p; + } + + index = JERRY_MIN (position + matched_str_length, string_length); + } + + /* 16.m */ + if (replace_ctx.replace_str_p == NULL) + { + /* 16.m.i-ii. + * arguments_p already contains <> */ + + /* 16.m.iii */ + ecma_collection_push_back (arguments_p, ecma_make_uint32_value (position)); + ecma_ref_ecma_string (string_p); + ecma_collection_push_back (arguments_p, ecma_make_string_value (string_p)); + + result = ecma_op_function_call (ecma_get_object_from_value (replace_arg), + ECMA_VALUE_UNDEFINED, + arguments_p->buffer_p, + arguments_p->item_count); + + ecma_collection_free (arguments_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto cleanup_builder; + } + + /* 16.m.v */ + ecma_string_t *const replace_result_p = ecma_op_to_string (result); + ecma_free_value (result); + + if (replace_result_p == NULL) + { + result = ECMA_VALUE_ERROR; + goto cleanup_builder; + } + + /* 16.m/p */ + if (should_replace) + { + ecma_stringbuilder_append (&replace_ctx.builder, replace_result_p); + } + + ecma_deref_ecma_string (replace_result_p); + } + else + { + /* 16.n/p */ + if (should_replace) + { + replace_ctx.u.collection_p = arguments_p; + ecma_builtin_replace_substitute (&replace_ctx); + } + + ecma_collection_free (arguments_p); + } + } + + /* 18. */ + JERRY_ASSERT (index <= string_length); + ecma_stringbuilder_append_raw (&(replace_ctx.builder), + source_position_p, + (lit_utf8_size_t) (string_end_p - source_position_p)); + + result = ecma_make_string_value (ecma_stringbuilder_finalize (&replace_ctx.builder)); + goto cleanup_chars; + +cleanup_builder: + ecma_stringbuilder_destroy (&replace_ctx.builder); + +cleanup_chars: + if (string_flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + jmem_heap_free_block ((void *) replace_ctx.string_p, replace_ctx.string_size); + } + +cleanup_results: + ecma_collection_free (results_p); + +cleanup_replace: + if (replace_ctx.replace_str_p != NULL) + { + ecma_deref_ecma_string (replace_ctx.replace_str_p); + } + +cleanup_string: + ecma_deref_ecma_string (string_p); + + return result; +} /* ecma_regexp_replace_helper */ + +/** + * Helper function for RegExp based matching + * + * See also: + * String.prototype.match + * RegExp.prototype[@@match] + * + * @return ecma_value_t + */ +ecma_value_t +ecma_regexp_match_helper (ecma_value_t this_arg, /**< this argument */ + ecma_value_t string_arg) /**< source string */ +{ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_OBJECT); + } + + ecma_string_t *str_p = ecma_op_to_string (string_arg); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (this_arg); + + ecma_value_t global_value = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_GLOBAL); + + if (ECMA_IS_VALUE_ERROR (global_value)) + { + ecma_deref_ecma_string (str_p); + return global_value; + } + + bool global = ecma_op_to_boolean (global_value); + + ecma_free_value (global_value); + + if (!global) + { + ecma_value_t result = ecma_op_regexp_exec (this_arg, str_p); + ecma_deref_ecma_string (str_p); + return result; + } + + ecma_value_t full_unicode_value = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_UNICODE); + + if (ECMA_IS_VALUE_ERROR (full_unicode_value)) + { + ecma_deref_ecma_string (str_p); + return full_unicode_value; + } + + bool full_unicode = ecma_op_to_boolean (full_unicode_value); + + ecma_free_value (full_unicode_value); + + ecma_value_t set_status = + ecma_op_object_put (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), ecma_make_uint32_value (0), true); + + if (ECMA_IS_VALUE_ERROR (set_status)) + { + ecma_deref_ecma_string (str_p); + return set_status; + } + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + ecma_object_t *result_array_p = ecma_op_new_array_object (0); + uint32_t n = 0; + + while (true) + { + ecma_value_t result_value = ecma_op_regexp_exec (this_arg, str_p); + + if (ECMA_IS_VALUE_ERROR (result_value)) + { + goto result_cleanup; + } + + if (ecma_is_value_null (result_value)) + { + if (n == 0) + { + ret_value = ECMA_VALUE_NULL; + goto result_cleanup; + } + + ecma_deref_ecma_string (str_p); + return ecma_make_object_value (result_array_p); + } + + ecma_object_t *result_value_p = ecma_get_object_from_value (result_value); + ecma_value_t match_value = ecma_op_object_get_by_index (result_value_p, 0); + + ecma_deref_object (result_value_p); + + if (ECMA_IS_VALUE_ERROR (match_value)) + { + goto result_cleanup; + } + + ecma_string_t *match_str_p = ecma_op_to_string (match_value); + ecma_free_value (match_value); + + if (JERRY_UNLIKELY (match_str_p == NULL)) + { + goto result_cleanup; + } + + ecma_value_t new_prop = ecma_builtin_helper_def_prop_by_index (result_array_p, + n, + ecma_make_string_value (match_str_p), + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_prop)); + + const bool is_match_empty = ecma_string_is_empty (match_str_p); + ecma_deref_ecma_string (match_str_p); + + if (is_match_empty) + { + ecma_value_t last_index = ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_LASTINDEX_UL); + + if (ECMA_IS_VALUE_ERROR (last_index)) + { + goto result_cleanup; + } + + ecma_length_t index; + ecma_value_t length_value = ecma_op_to_length (last_index, &index); + + ecma_free_value (last_index); + + if (ECMA_IS_VALUE_ERROR (length_value)) + { + goto result_cleanup; + } + + index = ecma_op_advance_string_index (str_p, index, full_unicode); + + last_index = ecma_make_length_value (index); + ecma_value_t next_set_status = + ecma_op_object_put (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL), last_index, true); + + ecma_free_value (last_index); + + if (ECMA_IS_VALUE_ERROR (next_set_status)) + { + goto result_cleanup; + } + } + + n++; + } + +result_cleanup: + ecma_deref_ecma_string (str_p); + ecma_deref_object (result_array_p); + return ret_value; +} /* ecma_regexp_match_helper */ + +/** + * RegExpExec operation + * + * See also: + * ECMA-262 v6.0, 21.2.5.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_op_regexp_exec (ecma_value_t this_arg, /**< this argument */ + ecma_string_t *str_p) /**< input string */ +{ + ecma_object_t *arg_obj_p = ecma_get_object_from_value (this_arg); + + ecma_value_t exec = ecma_op_object_get_by_magic_id (arg_obj_p, LIT_MAGIC_STRING_EXEC); + + if (ECMA_IS_VALUE_ERROR (exec)) + { + return exec; + } + + if (ecma_op_is_callable (exec)) + { + ecma_object_t *function_p = ecma_get_object_from_value (exec); + ecma_value_t arguments[] = { ecma_make_string_value (str_p) }; + + ecma_value_t result = ecma_op_function_call (function_p, this_arg, arguments, 1); + + ecma_deref_object (function_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (!ecma_is_value_object (result) && !ecma_is_value_null (result)) + { + ecma_free_value (result); + return ecma_raise_type_error (ECMA_ERR_RETURN_VALUE_OF_EXEC_MUST_BE_AN_OBJECT_OR_NULL); + } + + return result; + } + else + { + ecma_free_value (exec); + } + + if (!ecma_object_is_regexp_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_REG_EXP); + } + + return ecma_regexp_exec_helper (arg_obj_p, str_p); +} /* ecma_op_regexp_exec */ + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-regexp-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-regexp-object.h new file mode 100644 index 0000000..8981589 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-regexp-object.h @@ -0,0 +1,191 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_REGEXP_OBJECT_H +#define ECMA_REGEXP_OBJECT_H + +#include "ecma-globals.h" + +#include "re-compiler.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaregexpobject ECMA RegExp object related routines + * @{ + */ + +/** + * RegExp flags + * Note: + * This enum has to be kept in sync with jerry_regexp_flags_t. + */ +typedef enum +{ + RE_FLAG_EMPTY = 0u, /* Empty RegExp flags */ + RE_FLAG_GLOBAL = (1u << 1), /**< ECMA-262 v5, 15.10.7.2 */ + RE_FLAG_IGNORE_CASE = (1u << 2), /**< ECMA-262 v5, 15.10.7.3 */ + RE_FLAG_MULTILINE = (1u << 3), /**< ECMA-262 v5, 15.10.7.4 */ + RE_FLAG_STICKY = (1u << 4), /**< ECMA-262 v6, 21.2.5.12 */ + RE_FLAG_UNICODE = (1u << 5), /**< ECMA-262 v6, 21.2.5.15 */ + RE_FLAG_DOTALL = (1u << 6) /**< ECMA-262 v9, 21.2.5.3 */ + + /* Bits from bit 13 is reserved for function types (see CBC_FUNCTION_TYPE_SHIFT). */ +} ecma_regexp_flags_t; + +/** + * Class escapes + */ +typedef enum +{ + RE_ESCAPE__START, /**< escapes start */ + RE_ESCAPE_DIGIT = RE_ESCAPE__START, /**< digit */ + RE_ESCAPE_NOT_DIGIT, /**< not digit */ + RE_ESCAPE_WORD_CHAR, /**< word char */ + RE_ESCAPE_NOT_WORD_CHAR, /**< not word char */ + RE_ESCAPE_WHITESPACE, /**< whitespace */ + RE_ESCAPE_NOT_WHITESPACE, /**< not whitespace */ + RE_ESCAPE__COUNT, /**< escape count */ +} ecma_class_escape_t; + +/** + * Character class flags escape count mask size. + */ +#define RE_CLASS_ESCAPE_COUNT_MASK_SIZE (3u) + +/** + * Character class flags escape count mask. + */ +#define RE_CLASS_ESCAPE_COUNT_MASK ((1 << RE_CLASS_ESCAPE_COUNT_MASK_SIZE) - 1u) + +/** + * Character class flags that are present in the upper bits of the class flags byte, while the 3 least significant bits + * hold a value that contains the number of class escapes present in the character class. + */ +typedef enum +{ + RE_CLASS_HAS_CHARS = (1 << 5), /**< contains individual characters */ + RE_CLASS_HAS_RANGES = (1 << 6), /**< contains character ranges */ + RE_CLASS_INVERT = (1 << 7), /**< inverted */ +} ecma_char_class_flags_t; + +/** + * Structure for matching capturing groups and storing their result + */ +typedef struct +{ + const lit_utf8_byte_t *begin_p; /**< capture start pointer */ + const lit_utf8_byte_t *end_p; /**< capture end pointer */ + const uint8_t *bc_p; /**< group bytecode pointer */ + uint32_t iterator; /**< iteration counter */ + uint32_t subcapture_count; /**< number of nested capturing groups */ +} ecma_regexp_capture_t; + +/** + * Structure for matching non-capturing groups + */ +typedef struct +{ + const lit_utf8_byte_t *begin_p; /**< substring start pointer */ + const uint8_t *bc_p; /**< group bytecode pointer */ + uint32_t iterator; /**< iteration counter */ + uint32_t subcapture_start; /**< first nested capturing group index */ + uint32_t subcapture_count; /**< number of nested capturing groups */ +} ecma_regexp_non_capture_t; + +/** + * Check if an ecma_regexp_capture_t contains a defined capture + */ +#define ECMA_RE_IS_CAPTURE_DEFINED(c) ((c)->begin_p != NULL) + +ecma_value_t ecma_regexp_get_capture_value (const ecma_regexp_capture_t *const capture_p); + +#if (JERRY_STACK_LIMIT != 0) +/** + * Value used ase result when stack limit is reached + */ +#define ECMA_RE_OUT_OF_STACK ((const lit_utf8_byte_t *) UINTPTR_MAX) + +/** + * Checks if the stack limit has been reached during regexp matching + */ +#define ECMA_RE_STACK_LIMIT_REACHED(p) (JERRY_UNLIKELY (p == ECMA_RE_OUT_OF_STACK)) +#else /* JERRY_STACK_LIMIT == 0 */ +#define ECMA_RE_STACK_LIMIT_REACHED(p) (false) +#endif /* JERRY_STACK_LIMIT != 0 */ + +/** + * Offset applied to qmax when encoded into the bytecode. + * + * It's common for qmax to be Infinity, which is represented a UINT32_MAX. By applying the offset we are able to store + * it in a single byte az zero. + */ +#define RE_QMAX_OFFSET 1 + +/** + * RegExp executor context + */ +typedef struct +{ + const lit_utf8_byte_t *input_start_p; /**< start of input string */ + const lit_utf8_byte_t *input_end_p; /**< end of input string */ + uint32_t captures_count; /**< number of capture groups */ + uint32_t non_captures_count; /**< number of non-capture groups */ + ecma_regexp_capture_t *captures_p; /**< capturing groups */ + ecma_regexp_non_capture_t *non_captures_p; /**< non-capturing groups */ + uint16_t flags; /**< RegExp flags */ + uint8_t char_size; /**< size of encoded characters */ +} ecma_regexp_ctx_t; + +/** + * RegExpStringIterator object internal slots + * + * See also: + * ECMA-262 v11, 21.2.7.2 + */ +typedef struct +{ + ecma_extended_object_t header; /**< extended object part */ + ecma_value_t iterating_regexp; /**< [[IteratingRegExp]] internal slot */ + ecma_value_t iterated_string; /**< [[IteratedString]] internal slot */ +} ecma_regexp_string_iterator_t; + +lit_code_point_t ecma_regexp_unicode_advance (const lit_utf8_byte_t **str_p, const lit_utf8_byte_t *end_p); +ecma_object_t *ecma_op_regexp_alloc (ecma_object_t *new_target_obj_p); +ecma_value_t ecma_regexp_exec_helper (ecma_object_t *regexp_object_p, ecma_string_t *input_string_p); +ecma_string_t *ecma_regexp_read_pattern_str_helper (ecma_value_t pattern_arg); +lit_code_point_t ecma_regexp_canonicalize_char (lit_code_point_t ch, bool unicode); +ecma_value_t ecma_regexp_parse_flags (ecma_string_t *flags_str_p, uint16_t *flags_p); +void ecma_regexp_create_and_initialize_props (ecma_object_t *re_object_p, ecma_string_t *source_p, uint16_t flags); +ecma_value_t ecma_regexp_replace_helper (ecma_value_t this_arg, ecma_value_t string_arg, ecma_value_t replace_arg); +ecma_value_t ecma_regexp_search_helper (ecma_value_t regexp_arg, ecma_value_t string_arg); +ecma_value_t ecma_regexp_split_helper (ecma_value_t this_arg, ecma_value_t string_arg, ecma_value_t limit_arg); +ecma_value_t ecma_regexp_match_helper (ecma_value_t this_arg, ecma_value_t string_arg); + +ecma_value_t ecma_op_regexp_exec (ecma_value_t this_arg, ecma_string_t *str_p); + +ecma_value_t ecma_op_create_regexp_from_bytecode (ecma_object_t *regexp_obj_p, re_compiled_code_t *bc_p); +ecma_value_t +ecma_op_create_regexp_from_pattern (ecma_object_t *regexp_obj_p, ecma_value_t pattern_value, ecma_value_t flags_value); +ecma_value_t ecma_op_create_regexp_with_flags (ecma_object_t *regexp_obj_p, ecma_value_t pattern_value, uint16_t flags); +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ +#endif /* !ECMA_REGEXP_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.cpp new file mode 100644 index 0000000..658af2d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.cpp @@ -0,0 +1,161 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-shared-arraybuffer-object.h" + +#include "ecma-arraybuffer-object.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-typedarray-object.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmasharedarraybufferobject ECMA SharedArrayBuffer object related routines + * @{ + */ + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +/** + * Creating SharedArrayBuffer objects based on the array length + * + * @return new SharedArrayBuffer object + */ +ecma_object_t * +ecma_shared_arraybuffer_new_object (uint32_t length) /**< length of the SharedArrayBuffer */ +{ + if (length > 0) + { + return ecma_arraybuffer_create_object_with_buffer (ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER, length); + } + + return ecma_arraybuffer_create_object (ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER, length); +} /* ecma_shared_arraybuffer_new_object */ + +/** + * SharedArrayBuffer object creation operation. + * + * See also: ES11 24.1.1.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_shared_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< list of arguments that + * are passed to String constructor */ + uint32_t arguments_list_len) /**< length of the arguments' list */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p), + ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_number_t length_num = 0; + + if (arguments_list_len > 0) + { + if (ecma_is_value_number (arguments_list_p[0])) + { + length_num = ecma_get_number_from_value (arguments_list_p[0]); + } + else + { + ecma_value_t to_number_value = ecma_op_to_number (arguments_list_p[0], &length_num); + + if (ECMA_IS_VALUE_ERROR (to_number_value)) + { + ecma_deref_object (proto_p); + return to_number_value; + } + } + + if (ecma_number_is_nan (length_num)) + { + length_num = 0; + } + + const uint32_t maximum_size_in_byte = UINT32_MAX - sizeof (ecma_extended_object_t) - JMEM_ALIGNMENT + 1; + + if (length_num <= -1.0 || length_num > (ecma_number_t) maximum_size_in_byte + 0.5) + { + ecma_deref_object (proto_p); + return ecma_raise_range_error (ECMA_ERR_INVALID_SHARED_ARRAYBUFFER_LENGTH); + } + } + + uint32_t length_uint32 = ecma_number_to_uint32 (length_num); + ecma_object_t *shared_array_buffer = ecma_shared_arraybuffer_new_object (length_uint32); + ECMA_SET_NON_NULL_POINTER (shared_array_buffer->u2.prototype_cp, proto_p); + ecma_deref_object (proto_p); + + return ecma_make_object_value (shared_array_buffer); +} /* ecma_op_create_shared_arraybuffer_object */ + +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ + +/** + * Helper function: check if the target is SharedArrayBuffer + * + * See also: ES11 24.1.1.4 + * + * @return true - if value is a SharedArrayBuffer object + * false - otherwise + */ +bool +ecma_is_shared_arraybuffer (ecma_value_t target) /**< the target value */ +{ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + return (ecma_is_value_object (target) + && ecma_object_class_is (ecma_get_object_from_value (target), ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER)); +#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */ + JERRY_UNUSED (target); + return false; +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +} /* ecma_is_shared_arraybuffer */ + +/** + * Helper function: check if the target is SharedArrayBuffer Object + * + * @return true - if value is a SharedArrayBuffer object + * false - otherwise + */ +bool +ecma_object_is_shared_arraybuffer (ecma_object_t *object_p) /**< the target object */ +{ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + return ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER); +#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */ + JERRY_UNUSED (object_p); + return false; +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +} /* ecma_object_is_shared_arraybuffer */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.h new file mode 100644 index 0000000..413b173 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.h @@ -0,0 +1,45 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_SHARED_ARRAYBUFFER_OBJECT_H +#define ECMA_SHARED_ARRAYBUFFER_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmasharedarraybufferobject ECMA SharedArrayBuffer object related routines + * @{ + */ + +#if JERRY_BUILTIN_SHAREDARRAYBUFFER + +ecma_value_t ecma_op_create_shared_arraybuffer_object (const ecma_value_t *, uint32_t); + +/** + * Helper functions for SharedArrayBuffer. + */ +ecma_object_t *ecma_shared_arraybuffer_new_object (uint32_t length); +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +bool ecma_is_shared_arraybuffer (ecma_value_t val); +bool ecma_object_is_shared_arraybuffer (ecma_object_t *val); + +/** + * @} + * @} + */ + +#endif /* !ECMA_SHARED_ARRAYBUFFER_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-string-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-string-object.cpp new file mode 100644 index 0000000..95b78c9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-string-object.cpp @@ -0,0 +1,140 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-string-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "jcontext.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmastringobject ECMA String object related routines + * @{ + */ + +/** + * String object creation operation. + * + * See also: ECMA-262 v5, 15.5.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of arguments that + are passed to String constructor */ + uint32_t arguments_list_len) /**< length of the arguments' list */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_value_t prim_value = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + + if (arguments_list_len > 0) + { + ecma_string_t *str_p = ecma_op_to_string (arguments_list_p[0]); + + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + prim_value = ecma_make_string_value (str_p); + } + + ecma_builtin_id_t proto_id; +#if JERRY_BUILTIN_STRING + proto_id = ECMA_BUILTIN_ID_STRING_PROTOTYPE; +#else /* !JERRY_BUILTIN_STRING */ + proto_id = ECMA_BUILTIN_ID_OBJECT_PROTOTYPE; +#endif /* JERRY_BUILTIN_STRING */ + ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id); + + ecma_object_t *new_target = JERRY_CONTEXT (current_new_target_p); + if (new_target) + { + prototype_obj_p = ecma_op_get_prototype_from_constructor (new_target, proto_id); + if (JERRY_UNLIKELY (prototype_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + } + + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_STRING; + ext_object_p->u.cls.u3.value = prim_value; + + if (new_target) + { + ecma_deref_object (prototype_obj_p); + } + + return ecma_make_object_value (object_p); +} /* ecma_op_create_string_object */ + +/** + * List names of a String object's lazy instantiated properties + */ +void +ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, /**< a String object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + JERRY_ASSERT (ecma_get_object_base_type (obj_p) == ECMA_OBJECT_BASE_TYPE_CLASS); + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES)) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + JERRY_ASSERT (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_STRING); + + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (ext_object_p->u.cls.u3.value); + + lit_utf8_size_t length = ecma_string_get_length (prim_value_str_p); + + for (lit_utf8_size_t i = 0; i < length; i++) + { + ecma_string_t *name_p = ecma_new_ecma_string_from_uint32 (i); + + /* the properties are enumerable (ECMA-262 v5, 15.5.5.2.9) */ + ecma_collection_push_back (prop_names_p, ecma_make_string_value (name_p)); + } + + prop_counter_p->array_index_named_props += length; + } + + if (!(filter & JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS)) + { + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); + prop_counter_p->string_named_props++; + } +} /* ecma_op_string_list_lazy_property_names */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-string-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-string-object.h new file mode 100644 index 0000000..0ebb2c1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-string-object.h @@ -0,0 +1,40 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_STRING_OBJECT_H +#define ECMA_STRING_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmastringobject ECMA String object related routines + * @{ + */ + +ecma_value_t ecma_op_create_string_object (const ecma_value_t *arguments_list_p, uint32_t arguments_list_len); + +void ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); + +/** + * @} + * @} + */ + +#endif /* !ECMA_STRING_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-symbol-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-symbol-object.cpp new file mode 100644 index 0000000..adf8436 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-symbol-object.cpp @@ -0,0 +1,177 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-symbol-object.h" + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" + +#include "lit-char-helpers.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmasymbolobject ECMA Symbol object related routines + * @{ + */ + +/** + * Symbol creation operation. + * + * See also: ECMA-262 v6, 6.1.5.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_symbol (const ecma_value_t *arguments_list_p, /**< list of arguments */ + uint32_t arguments_list_len) /**< length of the arguments' list */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + ecma_value_t string_desc; + + /* 1-3. */ + if (arguments_list_len == 0 || ecma_is_value_undefined (arguments_list_p[0])) + { + string_desc = ECMA_VALUE_UNDEFINED; + } + else + { + ecma_string_t *str_p = ecma_op_to_string (arguments_list_p[0]); + + /* 4. */ + if (JERRY_UNLIKELY (str_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + string_desc = ecma_make_string_value (str_p); + } + + /* 5. */ + return ecma_make_symbol_value (ecma_new_symbol_from_descriptor_string (string_desc)); +} /* ecma_op_create_symbol */ + +/** + * Symbol object creation operation. + * + * See also: ECMA-262 v6, 19.4.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_symbol_object (const ecma_value_t value) /**< symbol value */ +{ + JERRY_ASSERT (ecma_is_value_symbol (value)); + + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE); + ecma_object_t *object_p = + ecma_create_object (prototype_obj_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_SYMBOL; + ext_object_p->u.cls.u3.value = ecma_copy_value (value); + + return ecma_make_object_value (object_p); +} /* ecma_op_create_symbol_object */ + +/** + * Get the symbol descriptor ecma-string from an ecma-symbol + * + * @return pointer to ecma-string descriptor + */ +ecma_value_t +ecma_get_symbol_description (ecma_string_t *symbol_p) /**< ecma-symbol */ +{ + JERRY_ASSERT (symbol_p != NULL); + JERRY_ASSERT (ecma_prop_name_is_symbol (symbol_p)); + + return ((ecma_extended_string_t *) symbol_p)->u.symbol_descriptor; +} /* ecma_get_symbol_description */ + +/** + * Get the descriptive string of the Symbol. + * + * See also: ECMA-262 v6, 19.4.3.2.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_get_symbol_descriptive_string (ecma_value_t symbol_value) /**< symbol to stringify */ +{ + /* 1. */ + JERRY_ASSERT (ecma_is_value_symbol (symbol_value)); + + /* 2 - 3. */ + ecma_string_t *symbol_p = ecma_get_symbol_from_value (symbol_value); + ecma_value_t string_desc = ecma_get_symbol_description (symbol_p); + ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) ("Symbol("), 7); + + if (!ecma_is_value_undefined (string_desc)) + { + ecma_string_t *string_desc_p = ecma_get_string_from_value (string_desc); + ecma_stringbuilder_append (&builder, string_desc_p); + } + + ecma_stringbuilder_append_byte (&builder, LIT_CHAR_RIGHT_PAREN); + return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); +} /* ecma_get_symbol_descriptive_string */ + +/** + * thisSymbolValue abstract operation + * + * See also: + * ECMA-262 v11, 19.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_symbol_this_value (ecma_value_t this_arg) /**< this argument value */ +{ + /* 1. */ + if (ecma_is_value_symbol (this_arg)) + { + return this_arg; + } + + /* 2. */ + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SYMBOL)) + { + return ((ecma_extended_object_t *) object_p)->u.cls.u3.value; + } + } + + /* 3. */ + return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_SYMBOL); +} /* ecma_symbol_this_value */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-symbol-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-symbol-object.h new file mode 100644 index 0000000..4f27e02 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-symbol-object.h @@ -0,0 +1,45 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_SYMBOL_H +#define ECMA_SYMBOL_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmasymbolobject ECMA Symbol object related routines + * @{ + */ + +ecma_value_t ecma_op_create_symbol (const ecma_value_t *arguments_list_p, uint32_t arguments_list_len); + +ecma_value_t ecma_op_create_symbol_object (const ecma_value_t value); + +bool ecma_prop_name_is_symbol (ecma_string_t *string_p); + +ecma_value_t ecma_get_symbol_description (ecma_string_t *symbol_p); + +ecma_value_t ecma_symbol_this_value (ecma_value_t this_arg); + +ecma_value_t ecma_get_symbol_descriptive_string (ecma_value_t symbol_value); + +/** + * @} + * @} + */ + +#endif /* !ECMA_SYMBOL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-typedarray-object.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-typedarray-object.cpp new file mode 100644 index 0000000..7fc36ff --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-typedarray-object.cpp @@ -0,0 +1,2107 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-typedarray-object.h" + +#include + +#include "ecma-arraybuffer-object.h" +#include "ecma-big-uint.h" +#include "ecma-bigint.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers-number.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-shared-arraybuffer-object.h" + +#include "jcontext.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmatypedarrayobject ECMA TypedArray object related routines + * @{ + */ + +/** + * Read and copy a number from a given buffer to a value. + **/ +#define ECMA_TYPEDARRAY_GET_ELEMENT(src_p, num, type) \ + do \ + { \ + if (JERRY_LIKELY ((((uintptr_t) (src_p)) & (sizeof (type) - 1)) == 0)) \ + { \ + num = *(type *) ((void *) src_p); \ + } \ + else \ + { \ + memcpy (&num, (void *) src_p, sizeof (type)); \ + } \ + } while (0) + +/** + * Copy a number from a value to the given buffer + **/ +#define ECMA_TYPEDARRAY_SET_ELEMENT(src_p, num, type) \ + do \ + { \ + if (JERRY_LIKELY ((((uintptr_t) (src_p)) & (sizeof (type) - 1)) == 0)) \ + { \ + *(type *) ((void *) src_p) = num; \ + } \ + else \ + { \ + memcpy ((void *) src_p, &num, sizeof (type)); \ + } \ + } while (0) + +/** + * Read an int8_t value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_int8_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + int8_t num = (int8_t) *src; + return ecma_make_integer_value (num); +} /* ecma_typedarray_get_int8_element */ + +/** + * Read an uint8_t value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_uint8_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + uint8_t num = (uint8_t) *src; + return ecma_make_integer_value (num); +} /* ecma_typedarray_get_uint8_element */ + +/** + * Read an int16_t value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_int16_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + int16_t num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, int16_t); + return ecma_make_integer_value (num); +} /* ecma_typedarray_get_int16_element */ + +/** + * Read an uint16_t value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_uint16_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + uint16_t num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, uint16_t); + return ecma_make_integer_value (num); +} /* ecma_typedarray_get_uint16_element */ + +/** + * Read an int32_t value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_int32_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + int32_t num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, int32_t); + return ecma_make_number_value (num); +} /* ecma_typedarray_get_int32_element */ + +/** + * Read an uint32_t value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_uint32_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + uint32_t num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, uint32_t); + return ecma_make_number_value (num); +} /* ecma_typedarray_get_uint32_element */ + +/** + * Read a float value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_float_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + float num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, float); + return ecma_make_number_value ((ecma_value_t)num); +} /* ecma_typedarray_get_float_element */ + +/** + * Read a double value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_double_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + double num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, double); + return ecma_make_number_value (num); +} /* ecma_typedarray_get_double_element */ + +#if JERRY_BUILTIN_BIGINT +/** + * Read a bigint64 value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_bigint64_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + uint64_t num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, uint64_t); + bool sign = (num >> 63) != 0; + + if (sign) + { + num = (uint64_t) (-(int64_t) num); + } + + return ecma_bigint_create_from_digits (&num, 1, sign); +} /* ecma_typedarray_get_bigint64_element */ + +/** + * Read a biguint64 value from the given arraybuffer + */ +static ecma_value_t +ecma_typedarray_get_biguint64_element (lit_utf8_byte_t *src) /**< the location in the internal arraybuffer */ +{ + uint64_t num; + ECMA_TYPEDARRAY_GET_ELEMENT (src, num, uint64_t); + return ecma_bigint_create_from_digits (&num, 1, false); +} /* ecma_typedarray_get_biguint64_element */ +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Normalize the given ecma_number_t to an uint32_t value + */ +static uint32_t +ecma_typedarray_setter_number_to_uint32 (ecma_number_t value) /**< the number value to normalize */ +{ + uint32_t uint32_value = 0; + + if (!ecma_number_is_nan (value) && !ecma_number_is_infinity (value)) + { + bool is_negative = false; + + if (value < 0) + { + is_negative = true; + value = -value; + } + + if (value > ((ecma_number_t) 0xffffffff)) + { + value = (ecma_number_t) (fmod (value, (ecma_number_t) 0x100000000)); + } + + uint32_value = (uint32_t) value; + + if (is_negative) + { + uint32_value = (uint32_t) (-(int32_t) uint32_value); + } + } + + return uint32_value; +} /* ecma_typedarray_setter_number_to_uint32 */ + +/** + * Write an int8_t value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_int8_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + int8_t num = (int8_t) ecma_typedarray_setter_number_to_uint32 (result_num); + *dst_p = (lit_utf8_byte_t) num; + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_int8_element */ + +/** + * Write an uint8_t value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_uint8_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + uint8_t num = (uint8_t) ecma_typedarray_setter_number_to_uint32 (result_num); + *dst_p = (lit_utf8_byte_t) num; + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_uint8_element */ + +/** + * Write an uint8_t clamped value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_uint8_clamped_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + uint8_t clamped; + + if (result_num > 255) + { + clamped = 255; + } + else if (result_num <= 0) + { + clamped = 0; + } + else + { + clamped = (uint8_t) result_num; + + if (clamped + 0.5 < result_num || (clamped + 0.5 == result_num && (clamped % 2) == 1)) + { + clamped++; + } + } + + *dst_p = (lit_utf8_byte_t) clamped; + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_uint8_clamped_element */ + +/** + * Write an int16_t value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_int16_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + int16_t num = (int16_t) ecma_typedarray_setter_number_to_uint32 (result_num); + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, int16_t); + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_int16_element */ + +/** + * Write an uint8_t value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_uint16_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + uint16_t num = (uint16_t) ecma_typedarray_setter_number_to_uint32 (result_num); + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, uint16_t); + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_uint16_element */ + +/** + * Write an int32_t value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_int32_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + int32_t num = (int32_t) ecma_typedarray_setter_number_to_uint32 (result_num); + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, int32_t); + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_int32_element */ + +/** + * Write an uint32_t value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_uint32_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + uint32_t num = (uint32_t) ecma_typedarray_setter_number_to_uint32 (result_num); + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, uint32_t); + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_uint32_element */ + +/** + * Write a float value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_float_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + float num = (float) result_num; + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, float); + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_float_element */ + +#if JERRY_NUMBER_TYPE_FLOAT64 +/** + * Write a double value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToNumber operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_double_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the number value to set */ +{ + ecma_number_t result_num; + ecma_value_t to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + double num = (double) result_num; + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, double); + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_double_element */ +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +#if JERRY_BUILTIN_BIGINT +/** + * Write a bigint64/biguint64 value into the given arraybuffer + * + * @return ECMA_VALUE_ERROR - if the ToBigInt operation fails + * ECMA_VALUE_TRUE - otherwise + */ +static ecma_value_t +ecma_typedarray_set_bigint_element (lit_utf8_byte_t *dst_p, /**< the location in the internal arraybuffer */ + ecma_value_t value) /**< the bigint value to set */ +{ + ecma_value_t bigint = ecma_bigint_to_bigint (value, false); + + if (ECMA_IS_VALUE_ERROR (bigint)) + { + return bigint; + } + + uint64_t num; + bool sign; + ecma_bigint_get_digits_and_sign (bigint, &num, 1, &sign); + + if (sign) + { + num = (uint64_t) (-(int64_t) num); + } + + ECMA_TYPEDARRAY_SET_ELEMENT (dst_p, num, uint64_t); + + ecma_free_value (bigint); + + return ECMA_VALUE_TRUE; +} /* ecma_typedarray_set_bigint_element */ +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Builtin id of the first %TypedArray% builtin routine intrinsic object + */ +#define ECMA_FIRST_TYPEDARRAY_BUILTIN_ROUTINE_ID ECMA_BUILTIN_ID_INT8ARRAY + +#if JERRY_BUILTIN_BIGINT +/** + * Builtin id of the last %TypedArray% builtin routine intrinsic object + */ +#define ECMA_LAST_TYPEDARRAY_BUILTIN_ROUTINE_ID ECMA_BUILTIN_ID_BIGUINT64ARRAY +#elif !JERRY_BUILTIN_BIGINT && JERRY_NUMBER_TYPE_FLOAT64 +/** + * Builtin id of the last %TypedArray% builtin routine intrinsic object + */ +#define ECMA_LAST_TYPEDARRAY_BUILTIN_ROUTINE_ID ECMA_BUILTIN_ID_FLOAT64ARRAY +#else /* !JERRY_NUMBER_TYPE_FLOAT64 */ +/** + * Builtin id of the last %TypedArray% builtin routine intrinsic object + */ +#define ECMA_LAST_TYPEDARRAY_BUILTIN_ROUTINE_ID ECMA_BUILTIN_ID_FLOAT32ARRAY +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Builtin id of the first %TypedArray% builtin prototype intrinsic object + */ +#define ECMA_FIRST_TYPEDARRAY_BUILTIN_PROTOTYPE_ID ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE + +/** + * List of typedarray getters based on their builtin id + */ +static const ecma_typedarray_getter_fn_t ecma_typedarray_getters[] = { + ecma_typedarray_get_int8_element, /**< Int8Array */ + ecma_typedarray_get_uint8_element, /**< Uint8Array */ + ecma_typedarray_get_uint8_element, /**< Uint8ClampedArray */ + ecma_typedarray_get_int16_element, /**< Int16Array */ + ecma_typedarray_get_uint16_element, /**< Int32Array */ + ecma_typedarray_get_int32_element, /**< Uint32Array */ + ecma_typedarray_get_uint32_element, /**< Uint32Array */ + ecma_typedarray_get_float_element, /**< Float32Array */ +#if JERRY_NUMBER_TYPE_FLOAT64 + ecma_typedarray_get_double_element, /**< Float64Array */ +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_BIGINT + ecma_typedarray_get_bigint64_element, /**< BigInt64Array*/ + ecma_typedarray_get_biguint64_element, /**< BigUint64Array */ +#endif /* JERRY_BUILTIN_BIGINT */ +}; + +/** + * List of typedarray setters based on their builtin id + */ +static const ecma_typedarray_setter_fn_t ecma_typedarray_setters[] = { + ecma_typedarray_set_int8_element, /**< Int8Array */ + ecma_typedarray_set_uint8_element, /**< Uint8Array */ + ecma_typedarray_set_uint8_clamped_element, /**< Uint8ClampedArray */ + ecma_typedarray_set_int16_element, /**< Int16Array */ + ecma_typedarray_set_uint16_element, /**< Int32Array */ + ecma_typedarray_set_int32_element, /**< Uint32Array */ + ecma_typedarray_set_uint32_element, /**< Uint32Array */ + ecma_typedarray_set_float_element, /**< Float32Array */ +#if JERRY_NUMBER_TYPE_FLOAT64 + ecma_typedarray_set_double_element, /**< Float64Array */ +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_BIGINT + ecma_typedarray_set_bigint_element, /**< BigInt64Array */ + ecma_typedarray_set_bigint_element, /**< BigUInt64Array */ +#endif /* JERRY_BUILTIN_BIGINT */ +}; + +/** + * List of typedarray element shift sizes based on their builtin id + */ +static const uint8_t ecma_typedarray_element_shift_sizes[] = { + 0, /**< Int8Array */ + 0, /**< Uint8Array */ + 0, /**< Uint8ClampedArray */ + 1, /**< Int16Array */ + 1, /**< Uint16Array */ + 2, /**< Int32Array */ + 2, /**< Uint32Array */ + 2, /**< Float32Array */ +#if JERRY_NUMBER_TYPE_FLOAT64 + 3, /**< Float64Array */ +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_BIGINT + 3, /**< BigInt64Array */ + 3, /**< BigUInt64Array */ +#endif /* JERRY_BUILTIN_BIGINT */ +}; + +/** + * List of typedarray class magic strings based on their builtin id + */ +static const uint16_t ecma_typedarray_magic_string_list[] = { + (uint16_t) LIT_MAGIC_STRING_INT8_ARRAY_UL, /**< Int8Array */ + (uint16_t) LIT_MAGIC_STRING_UINT8_ARRAY_UL, /**< Uint8Array */ + (uint16_t) LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL, /**< Uint8ClampedArray */ + (uint16_t) LIT_MAGIC_STRING_INT16_ARRAY_UL, /**< Int16Array */ + (uint16_t) LIT_MAGIC_STRING_UINT16_ARRAY_UL, /**< Uint16Array */ + (uint16_t) LIT_MAGIC_STRING_INT32_ARRAY_UL, /**< Int32Array */ + (uint16_t) LIT_MAGIC_STRING_UINT32_ARRAY_UL, /**< Uint32Array */ + (uint16_t) LIT_MAGIC_STRING_FLOAT32_ARRAY_UL, /**< Float32Array */ +#if JERRY_NUMBER_TYPE_FLOAT64 + (uint16_t) LIT_MAGIC_STRING_FLOAT64_ARRAY_UL, /**< Float64Array */ +#endif /* JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_BIGINT + (uint16_t) LIT_MAGIC_STRING_BIGINT64_ARRAY_UL, /**< BigInt64Array */ + (uint16_t) LIT_MAGIC_STRING_BIGUINT64_ARRAY_UL, /**< BigUInt64Array */ +#endif /* JERRY_BUILTIN_BIGINT */ +}; + +/** + * Get the magic string id of a typedarray + * + * @return magic string + */ +lit_magic_string_id_t +ecma_get_typedarray_magic_string_id (ecma_typedarray_type_t typedarray_id) +{ + return (lit_magic_string_id_t) ecma_typedarray_magic_string_list[typedarray_id]; +} /* ecma_get_typedarray_magic_string_id */ + +/** + * Get typedarray's getter function callback + * + * @return ecma_typedarray_getter_fn_t: the getter function for the given builtin TypedArray id + */ +ecma_typedarray_getter_fn_t +ecma_get_typedarray_getter_fn (ecma_typedarray_type_t typedarray_id) /**< typedarray id */ +{ + return ecma_typedarray_getters[typedarray_id]; +} /* ecma_get_typedarray_getter_fn */ + +/** + * Get element from a TypedArray + * + * @return the value of the element + */ +ecma_value_t +ecma_get_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */ + uint32_t index) /**< element index */ +{ + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info_p->array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p) || index >= info_p->length) + { + return ECMA_VALUE_UNDEFINED; + } + + uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); + + return ecma_typedarray_getters[info_p->id](buffer_p + (index << info_p->shift)); +} /* ecma_get_typedarray_element */ + +/** + * Get typedarray's setter function callback + * + * @return ecma_typedarray_setter_fn_t: the setter function for the given builtin TypedArray id + */ +ecma_typedarray_setter_fn_t +ecma_get_typedarray_setter_fn (ecma_typedarray_type_t typedarray_id) /**< typedarray id */ +{ + return ecma_typedarray_setters[typedarray_id]; +} /* ecma_get_typedarray_setter_fn */ + +/** + * set typedarray's element value + */ +ecma_value_t +ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */ + ecma_value_t value, /**< value to be set */ + uint32_t index) /**< element index */ +{ + ecma_value_t to_num; + ecma_number_t result_num; + to_num = ecma_op_to_numeric (value, &result_num, ECMA_TO_NUMERIC_NO_OPTS); + + if (ECMA_IS_VALUE_ERROR (to_num)) + { + return to_num; + } + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info_p->array_buffer_p)) + { + ecma_free_value (to_num); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (info_p->array_buffer_p) || index >= info_p->length) + { + ecma_free_value (to_num); + return ECMA_VALUE_FALSE; + } + + uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); + + ecma_free_value (to_num); + + return ecma_typedarray_setters[info_p->id](buffer_p + (index << info_p->shift), value); +} /* ecma_set_typedarray_element */ + +/** + * Get the element shift size of a TypedArray type. + * + * @return uint8_t + */ +uint8_t +ecma_typedarray_helper_get_shift_size (ecma_typedarray_type_t typedarray_id) +{ + return ecma_typedarray_element_shift_sizes[typedarray_id]; +} /* ecma_typedarray_helper_get_shift_size */ + +/** + * Check if the builtin is a TypedArray type. + * + * @return bool: - true if based on the given id it is a TypedArray + * - false if based on the given id it is not a TypedArray + */ +bool +ecma_typedarray_helper_is_typedarray (ecma_builtin_id_t builtin_id) /**< the builtin id of a type **/ +{ + return ((builtin_id >= ECMA_FIRST_TYPEDARRAY_BUILTIN_ROUTINE_ID) + && (builtin_id <= ECMA_LAST_TYPEDARRAY_BUILTIN_ROUTINE_ID)); +} /* ecma_typedarray_helper_is_typedarray */ + +/** + * Get the prototype ID of a TypedArray type. + * + * @return ecma_builtin_id_t + */ +ecma_builtin_id_t +ecma_typedarray_helper_get_prototype_id (ecma_typedarray_type_t typedarray_id) /**< the id of the typedarray **/ +{ + return (ecma_builtin_id_t) (ECMA_FIRST_TYPEDARRAY_BUILTIN_PROTOTYPE_ID + typedarray_id); +} /* ecma_typedarray_helper_get_prototype_id */ + +/** + * Get the constructor ID of a TypedArray type. + * + * @return ecma_builtin_id_t + */ +ecma_builtin_id_t +ecma_typedarray_helper_get_constructor_id (ecma_typedarray_type_t typedarray_id) /**< the id of the typedarray **/ +{ + return (ecma_builtin_id_t) (ECMA_FIRST_TYPEDARRAY_BUILTIN_ROUTINE_ID + typedarray_id); +} /* ecma_typedarray_helper_get_constructor_id */ + +/** + * Get the built-in TypedArray type of the given object. + * + * @return ecma_typedarray_type_t + */ +ecma_typedarray_type_t +ecma_get_typedarray_id (ecma_object_t *obj_p) /**< typedarray object **/ +{ + JERRY_ASSERT (ecma_object_is_typedarray (obj_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; + + return (ecma_typedarray_type_t) ext_object_p->u.cls.u1.typedarray_type; +} /* ecma_get_typedarray_id */ + +/** + * Get the built-in TypedArray type of the given object. + * + * @return ecma_typedarray_type_t + */ +ecma_typedarray_type_t +ecma_typedarray_helper_builtin_to_typedarray_id (ecma_builtin_id_t builtin_id) +{ + JERRY_ASSERT (ecma_typedarray_helper_is_typedarray (builtin_id)); + + return (ecma_typedarray_type_t) (builtin_id - ECMA_FIRST_TYPEDARRAY_BUILTIN_ROUTINE_ID); +} /* ecma_typedarray_helper_builtin_to_typedarray_id */ + +/** + * Create a TypedArray object by given array_length + * + * See also: ES2015 22.2.1.2.1 + * + * @return ecma value of the new typedarray object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_typedarray_create_object_with_length (uint32_t array_length, /**< length of the typedarray */ + ecma_object_t *src_buffer_p, /**< source buffer */ + ecma_object_t *proto_p, /**< prototype object */ + uint8_t element_size_shift, /**< the size shift of the element length */ + ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */ +{ + uint32_t byte_length = UINT32_MAX; + + if (array_length <= (UINT32_MAX >> element_size_shift)) + { + byte_length = array_length << element_size_shift; + } + + if (byte_length > UINT32_MAX - sizeof (ecma_extended_object_t) - JMEM_ALIGNMENT + 1) + { +#if JERRY_ERROR_MESSAGES + ecma_value_t array_length_value = ecma_make_number_value (array_length); + + ecma_value_t result = + ecma_raise_standard_error_with_format (JERRY_ERROR_RANGE, "Invalid typed array length: %", array_length_value); + ecma_free_value (array_length_value); + return result; +#else /* !JERRY_ERROR_MESSAGES */ + return ecma_raise_range_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + } + + ecma_object_t *new_arraybuffer_p = NULL; + if (src_buffer_p == NULL) + { + new_arraybuffer_p = ecma_arraybuffer_new_object (byte_length); + } + else + { + ecma_value_t ctor_proto = ecma_op_species_constructor (src_buffer_p, ECMA_BUILTIN_ID_ARRAYBUFFER); + + if (ECMA_IS_VALUE_ERROR (ctor_proto)) + { + return ctor_proto; + } + + ecma_object_t *ctor_proto_p = ecma_get_object_from_value (ctor_proto); + + ecma_object_t *prototype_p = + ecma_op_get_prototype_from_constructor (ctor_proto_p, ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE); + + ecma_deref_object (ctor_proto_p); + + if (JERRY_UNLIKELY (prototype_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + new_arraybuffer_p = ecma_arraybuffer_new_object (byte_length); + + ECMA_SET_NON_NULL_POINTER (new_arraybuffer_p->u2.prototype_cp, prototype_p); + + ecma_deref_object (prototype_p); + + if (ecma_arraybuffer_is_detached (src_buffer_p)) + { + ecma_deref_object (new_arraybuffer_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + } + + ecma_object_t *object_p = ecma_create_object (proto_p, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_TYPEDARRAY; + ext_object_p->u.cls.u1.typedarray_type = (uint8_t) typedarray_id; + ext_object_p->u.cls.u2.typedarray_flags = 0; + ext_object_p->u.cls.u3.arraybuffer = ecma_make_object_value (new_arraybuffer_p); + + ecma_deref_object (new_arraybuffer_p); + + return ecma_make_object_value (object_p); +} /* ecma_typedarray_create_object_with_length */ + +/** + * Create a TypedArray object by given another TypedArray object + * + * See also: ES2015 22.2.1.3 + * + * @return ecma value of the new typedarray object + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +ecma_typedarray_create_object_with_typedarray (ecma_object_t *typedarray_p, /**< a typedarray object */ + ecma_object_t *proto_p, /**< prototype object */ + uint8_t element_size_shift, /**< the size shift of the element length */ + ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */ +{ + uint32_t array_length = ecma_typedarray_get_length (typedarray_p); + ecma_object_t *src_arraybuffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (src_arraybuffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (src_arraybuffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_value_t new_typedarray = ecma_typedarray_create_object_with_length (array_length, + src_arraybuffer_p, + proto_p, + element_size_shift, + typedarray_id); + + if (ECMA_IS_VALUE_ERROR (new_typedarray)) + { + return new_typedarray; + } + + ecma_object_t *new_typedarray_p = ecma_get_object_from_value (new_typedarray); + ecma_object_t *dst_arraybuffer_p = ecma_typedarray_get_arraybuffer (new_typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (dst_arraybuffer_p)) + { + ecma_deref_object (new_typedarray_p); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (dst_arraybuffer_p)) + { + ecma_deref_object (new_typedarray_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + lit_utf8_byte_t *src_buf_p = ecma_arraybuffer_get_buffer (src_arraybuffer_p); + lit_utf8_byte_t *dst_buf_p = ecma_arraybuffer_get_buffer (dst_arraybuffer_p); + + src_buf_p += ecma_typedarray_get_offset (typedarray_p); + + ecma_typedarray_type_t src_id = ecma_get_typedarray_id (typedarray_p); + + if (src_id == typedarray_id) + { + memcpy (dst_buf_p, src_buf_p, array_length << element_size_shift); + } + else + { +#if JERRY_BUILTIN_BIGINT + if ((ECMA_TYPEDARRAY_IS_BIGINT_TYPE (src_id) ^ ECMA_TYPEDARRAY_IS_BIGINT_TYPE (typedarray_id)) == 1) + { + ecma_deref_object (new_typedarray_p); + return ecma_raise_type_error (ECMA_ERR_INCOMPATIBLE_TYPEDARRAY_TYPES); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + uint32_t src_element_size = 1u << ecma_typedarray_get_element_size_shift (typedarray_p); + uint32_t dst_element_size = 1u << element_size_shift; + ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (src_id); + ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (typedarray_id); + + for (uint32_t i = 0; i < array_length; i++) + { + /* Convert values from source to destination format. */ + ecma_value_t tmp = src_typedarray_getter_cb (src_buf_p); + ecma_value_t set_element = target_typedarray_setter_cb (dst_buf_p, tmp); + + ecma_free_value (tmp); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + ecma_deref_object (new_typedarray_p); + return set_element; + } + + src_buf_p += src_element_size; + dst_buf_p += dst_element_size; + } + } + + return new_typedarray; +} /* ecma_typedarray_create_object_with_typedarray */ + +/** + * Helper method for ecma_op_typedarray_from + * + * @return ECMA_VALUE_TRUE - if setting the given value to the new typedarray was successful + * ECMA_VALUE_ERROR - otherwise + */ +static ecma_value_t +ecma_op_typedarray_from_helper (ecma_value_t this_val, /**< this_arg for the above from function */ + ecma_value_t current_value, /**< given value to set */ + uint32_t index, /**< current index */ + ecma_object_t *func_object_p, /**< map function object */ + uint8_t *buffer_p, /**< target buffer */ + ecma_typedarray_setter_fn_t setter_cb) /**< setter callback function */ +{ + ecma_value_t mapped_value = current_value; + + if (func_object_p != NULL) + { + /* 17.d 17.f */ + ecma_value_t current_index = ecma_make_uint32_value (index); + ecma_value_t call_args[] = { current_value, current_index }; + + ecma_value_t cb_value = ecma_op_function_call (func_object_p, this_val, call_args, 2); + + ecma_free_value (current_value); + ecma_free_value (current_index); + + if (ECMA_IS_VALUE_ERROR (cb_value)) + { + return cb_value; + } + + mapped_value = cb_value; + } + + ecma_value_t set_element = setter_cb (buffer_p, mapped_value); + ecma_free_value (mapped_value); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + return set_element; + } + + return ECMA_VALUE_TRUE; +} /* ecma_op_typedarray_from_helper */ + +/** + * Create a TypedArray object by transforming from an array-like object or iterable object + * + * See also: ES11 22.2.4.4 + * + * @return ecma value of the new typedarray object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_typedarray_create_object_with_object (ecma_value_t items_val, /**< the source array-like object */ + ecma_object_t *proto_p, /**< prototype object */ + uint8_t element_size_shift, /**< the size shift of the element length */ + ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */ +{ + /* 5 */ + ecma_value_t using_iterator = ecma_op_get_method_by_symbol_id (items_val, LIT_GLOBAL_SYMBOL_ITERATOR); + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + ecma_object_t *new_typedarray_p; + ecma_typedarray_info_t info; + ecma_value_t *next_value_p; + + uint8_t *buffer_p; + ecma_typedarray_setter_fn_t setter_cb; + uint8_t *limit_p; + + if (ECMA_IS_VALUE_ERROR (using_iterator)) + { + return using_iterator; + } + + /* 6 */ + if (!ecma_is_value_undefined (using_iterator)) + { + /* 6.a */ + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (items_val, using_iterator, &next_method); + ecma_free_value (using_iterator); + + if (ECMA_IS_VALUE_ERROR (iterator)) + { + return iterator; + } + + ecma_collection_t *values_p = ecma_new_collection (); + + while (true) + { + ecma_value_t next = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (next)) + { + ret_value = next; + break; + } + + if (next == ECMA_VALUE_FALSE) + { + break; + } + + ecma_value_t next_value = ecma_op_iterator_value (next); + ecma_free_value (next); + + if (ECMA_IS_VALUE_ERROR (next_value)) + { + ret_value = next_value; + break; + } + + ecma_collection_push_back (values_p, next_value); + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_collection_free (values_p); + return ret_value; + } + + /* 8.c */ + ecma_value_t new_typedarray = ecma_typedarray_create_object_with_length (values_p->item_count, + NULL, + proto_p, + element_size_shift, + typedarray_id); + + if (ECMA_IS_VALUE_ERROR (new_typedarray)) + { + ecma_collection_free (values_p); + return new_typedarray; + } + + new_typedarray_p = ecma_get_object_from_value (new_typedarray); + info = ecma_typedarray_get_info (new_typedarray_p); + next_value_p = values_p->buffer_p; + + ret_value = ECMA_VALUE_ERROR; + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + goto free_collection; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + goto free_collection; + } + + buffer_p = ecma_typedarray_get_buffer (&info); + setter_cb = ecma_get_typedarray_setter_fn (info.id); + limit_p = buffer_p + (values_p->item_count << info.shift); + ret_value = ecma_make_object_value (new_typedarray_p); + + /* 8.e */ + while (buffer_p < limit_p) + { + ecma_value_t value = *next_value_p++; + ecma_value_t set_value = setter_cb (buffer_p, value); + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (set_value)) + { + ret_value = set_value; + break; + } + + buffer_p += info.element_size; + } + +free_collection: + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_value_t *last_value_p = values_p->buffer_p + values_p->item_count; + + while (next_value_p < last_value_p) + { + ecma_free_value (*next_value_p++); + } + + ecma_deref_object (new_typedarray_p); + } + + ecma_collection_destroy (values_p); + return ret_value; + } + + /* 8 */ + ecma_value_t arraylike_object_val = ecma_op_to_object (items_val); + + if (ECMA_IS_VALUE_ERROR (arraylike_object_val)) + { + return arraylike_object_val; + } + + ecma_object_t *arraylike_object_p = ecma_get_object_from_value (arraylike_object_val); + + /* 9 */ + ecma_length_t length_index; + ecma_value_t len_value = ecma_op_object_get_length (arraylike_object_p, &length_index); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + ecma_deref_object (arraylike_object_p); + return len_value; + } + + if (length_index >= UINT32_MAX) + { + ecma_deref_object (arraylike_object_p); + return ecma_raise_range_error (ECMA_ERR_INVALID_TYPEDARRAY_LENGTH); + } + + uint32_t len = (uint32_t) length_index; + + /* 10 */ + ecma_value_t new_typedarray = + ecma_typedarray_create_object_with_length (len, NULL, proto_p, element_size_shift, typedarray_id); + + if (ECMA_IS_VALUE_ERROR (new_typedarray)) + { + ecma_deref_object (arraylike_object_p); + return new_typedarray; + } + + new_typedarray_p = ecma_get_object_from_value (new_typedarray); + info = ecma_typedarray_get_info (new_typedarray_p); + ret_value = ECMA_VALUE_ERROR; + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + goto free_object; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + goto free_object; + } + + buffer_p = ecma_typedarray_get_buffer (&info); + setter_cb = ecma_get_typedarray_setter_fn (info.id); + ret_value = ecma_make_object_value (new_typedarray_p); + + /* 12 */ + for (uint32_t index = 0; index < len; index++) + { + ecma_value_t value = ecma_op_object_find_by_index (arraylike_object_p, index); + + if (ECMA_IS_VALUE_ERROR (value)) + { + ret_value = value; + break; + } + + if (!ecma_is_value_found (value)) + { + value = ECMA_VALUE_UNDEFINED; + } + + ecma_value_t set_value = setter_cb (buffer_p, value); + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (set_value)) + { + ret_value = set_value; + break; + } + + buffer_p += info.element_size; + } + +free_object: + ecma_deref_object (arraylike_object_p); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_deref_object (new_typedarray_p); + } + + return ret_value; +} /* ecma_typedarray_create_object_with_object */ + +/** + * Create a TypedArray object by transforming from an array-like object or iterable object + * + * See also: ES11 22.2.2.1 + * + * @return ecma value of the new typedarray object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_typedarray_from (ecma_value_t this_val, /**< this value */ + ecma_value_t source_val, /**< source value */ + ecma_value_t map_fn_val, /**< mapped function value */ + ecma_value_t this_arg) /**< this argument */ +{ + JERRY_UNUSED (this_arg); + /* 3 */ + JERRY_ASSERT (ecma_op_is_callable (map_fn_val) || ecma_is_value_undefined (map_fn_val)); + + /* 4 */ + ecma_object_t *func_object_p = NULL; + + if (!ecma_is_value_undefined (map_fn_val)) + { + func_object_p = ecma_get_object_from_value (map_fn_val); + } + + /* 5 */ + ecma_value_t using_iterator = ecma_op_get_method_by_symbol_id (source_val, LIT_GLOBAL_SYMBOL_ITERATOR); + + if (ECMA_IS_VALUE_ERROR (using_iterator)) + { + return using_iterator; + } + + /* 6 */ + if (!ecma_is_value_undefined (using_iterator)) + { + /* 6.a */ + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (source_val, using_iterator, &next_method); + ecma_free_value (using_iterator); + + /* 6.b */ + if (ECMA_IS_VALUE_ERROR (iterator)) + { + return iterator; + } + + /* 6.c */ + ecma_collection_t *values_p = ecma_new_collection (); + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + /* 6.e */ + while (true) + { + ecma_value_t next = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (next)) + { + ret_value = next; + break; + } + + if (next == ECMA_VALUE_FALSE) + { + break; + } + + ecma_value_t next_value = ecma_op_iterator_value (next); + ecma_free_value (next); + + if (ECMA_IS_VALUE_ERROR (next_value)) + { + ret_value = next_value; + break; + } + + ecma_collection_push_back (values_p, next_value); + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_collection_free (values_p); + return ret_value; + } + + /* 6.c */ + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (this_val); + ecma_value_t len_val = ecma_make_uint32_value (values_p->item_count); + ecma_value_t new_typedarray = ecma_typedarray_create (constructor_obj_p, &len_val, 1); + ecma_free_value (len_val); + + if (ECMA_IS_VALUE_ERROR (new_typedarray)) + { + ecma_collection_free (values_p); + return new_typedarray; + } + + ecma_object_t *new_typedarray_p = ecma_get_object_from_value (new_typedarray); + ecma_typedarray_info_t info = ecma_typedarray_get_info (new_typedarray_p); + ecma_typedarray_setter_fn_t setter_cb = ecma_get_typedarray_setter_fn (info.id); + ecma_value_t *next_value_p = values_p->buffer_p; + uint8_t *buffer_p; + + ret_value = ECMA_VALUE_ERROR; + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + goto free_collection; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + goto free_collection; + } + + buffer_p = ecma_typedarray_get_buffer (&info); + ret_value = ecma_make_object_value (new_typedarray_p); + + /* 6.e */ + for (uint32_t index = 0; index < values_p->item_count; index++) + { + ecma_value_t set_value = + ecma_op_typedarray_from_helper (this_arg, *next_value_p++, index, func_object_p, buffer_p, setter_cb); + + if (ECMA_IS_VALUE_ERROR (set_value)) + { + ret_value = set_value; + break; + } + + buffer_p += info.element_size; + } + +free_collection: + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_value_t *last_value_p = values_p->buffer_p + values_p->item_count; + + while (next_value_p < last_value_p) + { + ecma_free_value (*next_value_p++); + } + + ecma_deref_object (new_typedarray_p); + } + + ecma_collection_destroy (values_p); + return ret_value; + } + + /* 8 */ + ecma_value_t arraylike_object_val = ecma_op_to_object (source_val); + + if (ECMA_IS_VALUE_ERROR (arraylike_object_val)) + { + return arraylike_object_val; + } + + ecma_object_t *arraylike_object_p = ecma_get_object_from_value (arraylike_object_val); + + /* 9 */ + ecma_length_t length_index; + ecma_value_t len_value = ecma_op_object_get_length (arraylike_object_p, &length_index); + + if (ECMA_IS_VALUE_ERROR (len_value)) + { + ecma_deref_object (arraylike_object_p); + return len_value; + } + + if (length_index >= UINT32_MAX) + { + ecma_deref_object (arraylike_object_p); + return ecma_raise_range_error (ECMA_ERR_INVALID_TYPEDARRAY_LENGTH); + } + + uint32_t len = (uint32_t) length_index; + + /* 10 */ + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (this_val); + ecma_value_t len_val = ecma_make_uint32_value (len); + ecma_value_t new_typedarray = ecma_typedarray_create (constructor_obj_p, &len_val, 1); + ecma_free_value (len_val); + + if (ECMA_IS_VALUE_ERROR (new_typedarray)) + { + ecma_deref_object (arraylike_object_p); + return new_typedarray; + } + + ecma_object_t *new_typedarray_p = ecma_get_object_from_value (new_typedarray); + ecma_typedarray_info_t info = ecma_typedarray_get_info (new_typedarray_p); + ecma_value_t ret_value = ECMA_VALUE_ERROR; + uint8_t *buffer_p; + + ecma_typedarray_setter_fn_t setter_cb; + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + goto free_object; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + goto free_object; + } + + buffer_p = ecma_typedarray_get_buffer (&info); + setter_cb = ecma_get_typedarray_setter_fn (info.id); + ret_value = ecma_make_object_value (new_typedarray_p); + + /* 12 */ + for (uint32_t index = 0; index < len; index++) + { + ecma_value_t value = ecma_op_object_find_by_index (arraylike_object_p, index); + + if (ECMA_IS_VALUE_ERROR (value)) + { + ret_value = value; + break; + } + + if (!ecma_is_value_found (value)) + { + value = ECMA_VALUE_UNDEFINED; + } + + ecma_value_t set_value = + ecma_op_typedarray_from_helper (this_arg, value, index, func_object_p, buffer_p, setter_cb); + + if (ECMA_IS_VALUE_ERROR (set_value)) + { + ret_value = set_value; + break; + } + + buffer_p += info.element_size; + } + +free_object: + ecma_deref_object (arraylike_object_p); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + ecma_deref_object (new_typedarray_p); + } + + return ret_value; +} /* ecma_op_typedarray_from */ + +/** + * Get the arraybuffer of the typedarray object + * + * @return the pointer to the internal arraybuffer + */ +ecma_object_t * +ecma_typedarray_get_arraybuffer (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */ +{ + JERRY_ASSERT (ecma_object_is_typedarray (typedarray_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p; + + return ecma_get_object_from_value (ext_object_p->u.cls.u3.arraybuffer); +} /* ecma_typedarray_get_arraybuffer */ + +/** + * Get the element size shift in the typedarray object + * + * @return the size shift of the element, size is 1 << shift + */ +uint8_t +ecma_typedarray_get_element_size_shift (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */ +{ + JERRY_ASSERT (ecma_object_is_typedarray (typedarray_p)); + + return ecma_typedarray_helper_get_shift_size (ecma_get_typedarray_id (typedarray_p)); +} /* ecma_typedarray_get_element_size_shift */ + +/** + * Get the array length of the typedarray object + * + * @return the array length + */ +uint32_t +ecma_typedarray_get_length (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */ +{ + JERRY_ASSERT (ecma_object_is_typedarray (typedarray_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p; + + if (!(ext_object_p->u.cls.u2.typedarray_flags & ECMA_TYPEDARRAY_IS_EXTENDED)) + { + ecma_object_t *arraybuffer_p = ecma_get_object_from_value (ext_object_p->u.cls.u3.arraybuffer); + ecma_extended_object_t *arraybuffer_object_p = (ecma_extended_object_t *) arraybuffer_p; + uint32_t buffer_length = arraybuffer_object_p->u.cls.u3.length; + uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p); + + return buffer_length >> shift; + } + + ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + + if (ecma_arraybuffer_is_detached (arraybuffer_p)) + { + return 0; + } + + ecma_extended_typedarray_object_t *info_p = (ecma_extended_typedarray_object_t *) ext_object_p; + + return info_p->array_length; +} /* ecma_typedarray_get_length */ + +/** + * Get the offset of the internal arraybuffer + * + * @return the offset + */ +uint32_t +ecma_typedarray_get_offset (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */ +{ + JERRY_ASSERT (ecma_object_is_typedarray (typedarray_p)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p; + + if (!(ext_object_p->u.cls.u2.typedarray_flags & ECMA_TYPEDARRAY_IS_EXTENDED)) + { + return 0; + } + + ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + + if (ecma_arraybuffer_is_detached (arraybuffer_p)) + { + return 0; + } + + ecma_extended_typedarray_object_t *info_p = (ecma_extended_typedarray_object_t *) ext_object_p; + + return info_p->byte_offset; +} /* ecma_typedarray_get_offset */ + +/** + * Utility function: return the pointer of the data buffer referenced by the typedarray info + * + * @return pointer to the data buffer if successful, + * NULL otherwise + */ +uint8_t * +ecma_typedarray_get_buffer (ecma_typedarray_info_t *info_p) /**< typedarray info */ +{ + return ecma_arraybuffer_get_buffer (info_p->array_buffer_p) + info_p->offset; +} /* ecma_typedarray_get_buffer */ + +/** + * Create a new typedarray object. + * + * The struct of the typedarray object + * ecma_object_t + * extend_part + * typedarray_info + * + * @return ecma value of the new typedarray object + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg list passed to typedarray construct */ + uint32_t arguments_list_len, /**< the length of the arguments_list_p */ + ecma_object_t *proto_p, /**< prototype object */ + uint8_t element_size_shift, /**< the size shift of the element length */ + ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len == 0) + { + /* 22.2.1.1 */ + return ecma_typedarray_create_object_with_length (0, NULL, proto_p, element_size_shift, typedarray_id); + } + + if (!ecma_is_value_object (arguments_list_p[0])) + { + ecma_number_t num = 0; + + if (!ecma_is_value_undefined (arguments_list_p[0]) + && ECMA_IS_VALUE_ERROR (ecma_op_to_index (arguments_list_p[0], &num))) + { + return ECMA_VALUE_ERROR; + } + + JERRY_ASSERT (num >= 0 && num <= ECMA_NUMBER_MAX_SAFE_INTEGER); + + if (num > UINT32_MAX) + { +#if JERRY_ERROR_MESSAGES + return ecma_raise_standard_error_with_format (JERRY_ERROR_RANGE, + "Invalid typed array length: %", + arguments_list_p[0]); +#else /* !JERRY_ERROR_MESSAGES */ + return ecma_raise_range_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + } + + return ecma_typedarray_create_object_with_length ((uint32_t) num, NULL, proto_p, element_size_shift, typedarray_id); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list_p[0]); + + if (ecma_object_is_typedarray (obj_p)) + { + /* 22.2.1.3 */ + ecma_object_t *typedarray_p = obj_p; + return ecma_typedarray_create_object_with_typedarray (typedarray_p, proto_p, element_size_shift, typedarray_id); + } + + if (!ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) && !ecma_object_is_shared_arraybuffer (obj_p)) + { + /* 22.2.1.4 */ + return ecma_typedarray_create_object_with_object (arguments_list_p[0], proto_p, element_size_shift, typedarray_id); + } + + /* 22.2.1.5 */ + ecma_object_t *arraybuffer_p = obj_p; + ecma_value_t byte_offset_value = ((arguments_list_len > 1) ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED); + + ecma_value_t length_value = ((arguments_list_len > 2) ? arguments_list_p[2] : ECMA_VALUE_UNDEFINED); + + ecma_number_t offset; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_index (byte_offset_value, &offset))) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_number_is_negative (offset) || fmod (offset, (1 << element_size_shift)) != 0) + { + /* ES2015 22.2.1.5: 9 - 10. */ + if (ecma_number_is_zero (offset)) + { + offset = 0; + } + else + { + return ecma_raise_range_error (ECMA_ERR_INVALID_OFFSET); + } + } + + ecma_number_t new_length = 0; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_index (length_value, &new_length))) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (arraybuffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + if (offset > UINT32_MAX) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_LENGTH); + } + + uint32_t byte_offset = (uint32_t) offset; + + uint32_t buf_byte_length = ecma_arraybuffer_get_length (arraybuffer_p); + uint32_t new_byte_length = 0; + + if (ecma_is_value_undefined (length_value)) + { + if ((buf_byte_length % (uint32_t) (1 << element_size_shift) != 0) || (buf_byte_length < byte_offset)) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_LENGTH); + } + + new_byte_length = (uint32_t) (buf_byte_length - byte_offset); + } + else + { + if (new_length > (UINT32_MAX >> element_size_shift)) + { + return ecma_raise_range_error (ECMA_ERR_MAXIMUM_TYPEDARRAY_SIZE_IS_REACHED); + } + + new_byte_length = (uint32_t) new_length << element_size_shift; + + if (byte_offset > buf_byte_length || new_byte_length > (buf_byte_length - byte_offset)) + { + return ecma_raise_range_error (ECMA_ERR_INVALID_LENGTH); + } + } + + bool needs_ext_typedarray_obj = (byte_offset != 0 || new_byte_length != buf_byte_length); + + size_t object_size = + (needs_ext_typedarray_obj ? sizeof (ecma_extended_typedarray_object_t) : sizeof (ecma_extended_object_t)); + + ecma_object_t *object_p = ecma_create_object (proto_p, object_size, ECMA_OBJECT_TYPE_CLASS); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_TYPEDARRAY; + ext_object_p->u.cls.u1.typedarray_type = (uint8_t) typedarray_id; + ext_object_p->u.cls.u2.typedarray_flags = 0; + ext_object_p->u.cls.u3.arraybuffer = ecma_make_object_value (arraybuffer_p); + + if (needs_ext_typedarray_obj) + { + ext_object_p->u.cls.u2.typedarray_flags |= ECMA_TYPEDARRAY_IS_EXTENDED; + + ecma_extended_typedarray_object_t *typedarray_info_p = (ecma_extended_typedarray_object_t *) object_p; + typedarray_info_p->array_length = new_byte_length >> element_size_shift; + typedarray_info_p->byte_offset = byte_offset; + } + + return ecma_make_object_value (object_p); +} /* ecma_op_create_typedarray */ + +/** + * Helper function for typedArray.prototype object's {'keys', 'values', 'entries', '@@iterator'} + * routines common parts. + * + * See also: + * ECMA-262 v6, 22.2.3.15 + * ECMA-262 v6, 22.2.3.29 + * ECMA-262 v6, 22.2.3.6 + * ECMA-262 v6, 22.1.3.30 + * + * Note: + * Returned value must be freed with ecma_free_value. + * + * @return iterator result object, if success + * error - otherwise + */ +ecma_value_t +ecma_typedarray_iterators_helper (ecma_value_t this_arg, /**< this argument */ + ecma_iterator_kind_t kind) /**< iterator kind */ +{ + JERRY_ASSERT (ecma_is_typedarray (this_arg)); + + ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg); + ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_ITERATOR_PROTOTYPE); + + return ecma_op_create_iterator_object (this_arg, prototype_obj_p, ECMA_OBJECT_CLASS_ARRAY_ITERATOR, kind); +} /* ecma_typedarray_iterators_helper */ + +/** + * Check if the object is typedarray + * + * @return true - if object is a TypedArray object + * false - otherwise + */ +bool +ecma_object_is_typedarray (ecma_object_t *obj_p) /**< the target object need to be checked */ +{ + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + + return ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_TYPEDARRAY); +} /* ecma_object_is_typedarray */ + +/** + * Check if the value is typedarray + * + * @return true - if value is a TypedArray object + * false - otherwise + */ +bool +ecma_is_typedarray (ecma_value_t value) /**< the target need to be checked */ +{ + if (!ecma_is_value_object (value)) + { + return false; + } + + return ecma_object_is_typedarray (ecma_get_object_from_value (value)); +} /* ecma_is_typedarray */ + +/** + * Checks whether the property name is a valid element index + * + * @return true, if valid + * false, otherwise + */ +bool +ecma_typedarray_is_element_index (ecma_string_t *property_name_p) /**< property name */ +{ + ecma_number_t num = ecma_string_to_number (property_name_p); + + if (num == 0) + { + return true; + } + + ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); + bool is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); + ecma_deref_ecma_string (num_to_str); + return is_same; +} /* ecma_typedarray_is_element_index */ + +/** + * List names of a TypedArray object's integer indexed properties + */ +void +ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedArray object */ + ecma_collection_t *prop_names_p, /**< prop name collection */ + ecma_property_counter_t *prop_counter_p, /**< property counters */ + jerry_property_filter_t filter) /**< property name filter options */ +{ + JERRY_ASSERT (ecma_object_is_typedarray (obj_p)); + + if (filter & JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES) + { + return; + } + + uint32_t array_length = ecma_typedarray_get_length (obj_p); + + for (uint32_t i = 0; i < array_length; i++) + { + ecma_string_t *name_p = ecma_new_ecma_string_from_uint32 (i); + ecma_collection_push_back (prop_names_p, ecma_make_string_value (name_p)); + } + + prop_counter_p->array_index_named_props += array_length; +} /* ecma_op_typedarray_list_lazy_property_names */ + +/** + * [[DefineOwnProperty]] operation for TypedArray objects + * + * See also: ES2015 9.4.5.3 + * + * @return ECMA_VALUE_TRUE - if the property is successfully defined + * ECMA_VALUE_FALSE - if is JERRY_PROP_SHOULD_THROW is not set + * raised TypeError - otherwise + */ +ecma_value_t +ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, /**< TypedArray object */ + ecma_string_t *property_name_p, /**< property name */ + const ecma_property_descriptor_t *property_desc_p) /**< property descriptor */ +{ + JERRY_ASSERT (ecma_object_is_typedarray (obj_p)); + + if (JERRY_UNLIKELY (ecma_prop_name_is_symbol (property_name_p))) + { + return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p); + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX && !ecma_typedarray_is_element_index (property_name_p)) + { + return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p); + } + + if ((property_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + || ((property_desc_p->flags & (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE)) + == (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE)) + || ((property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + && !(property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE)) + || ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) + && !(property_desc_p->flags & JERRY_PROP_IS_WRITABLE))) + { + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p); + + if (index >= info.length || ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + return ECMA_VALUE_FALSE; + } + + if (property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + { + ecma_value_t set_element = ecma_set_typedarray_element (&info, property_desc_p->value, index); + + if (ECMA_IS_VALUE_ERROR (set_element)) + { + return set_element; + } + } + + return ECMA_VALUE_TRUE; +} /* ecma_op_typedarray_define_own_property */ + +/** + * Specify the creation of a new TypedArray + * object using a constructor function. + * + * See also: ES11 22.2.4.6 + * + * Used by: + * - ecma_typedarray_species_create + * + * @return ecma_value_t function object from created from constructor_p argument + */ + +ecma_value_t +ecma_typedarray_create (ecma_object_t *constructor_p, /**< constructor function */ + ecma_value_t *arguments_list_p, /**< argument list */ + uint32_t arguments_list_len) /**< length of argument list */ +{ + ecma_value_t ret_val = + ecma_op_function_construct (constructor_p, constructor_p, arguments_list_p, arguments_list_len); + if (ECMA_IS_VALUE_ERROR (ret_val)) + { + return ret_val; + } + + if (!ecma_is_typedarray (ret_val)) + { + ecma_free_value (ret_val); + return ecma_raise_type_error (ECMA_ERR_CONSTRUCTED_OBJECT_IS_NOT_TYPEDARRAY); + } + + ecma_object_t *typedarray_p = ecma_get_object_from_value (ret_val); + ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p); + + if (ECMA_ARRAYBUFFER_LAZY_ALLOC (info.array_buffer_p)) + { + ecma_deref_object (typedarray_p); + return ECMA_VALUE_ERROR; + } + + if (ecma_arraybuffer_is_detached (info.array_buffer_p)) + { + ecma_deref_object (typedarray_p); + return ecma_raise_type_error (ECMA_ERR_ARRAYBUFFER_IS_DETACHED); + } + + if ((arguments_list_len == 1) && (ecma_is_value_number (arguments_list_p[0]))) + { + ecma_number_t num = ecma_get_number_from_value (arguments_list_p[0]); + + if (info.length < num) + { + ecma_free_value (ret_val); + return ecma_raise_type_error (ECMA_ERR_TYPEDARRAY_SMALLER_THAN_FILTER_CALL_RESULT); + } + } + return ret_val; +} /* ecma_typedarray_create */ + +/* Specify the creation of a new TypedArray object + * using a constructor function that is derived from this_arg. + * + * See also: ES11 22.2.4.7 + * + * @return ecma value of the new typedarray object, constructed by default or species constructor + */ +ecma_value_t +ecma_typedarray_species_create (ecma_value_t this_arg, /**< this argument */ + ecma_value_t *arguments_list_p, /**< the arg list passed to typedarray construct */ + uint32_t arguments_list_len) /**< length of the arg list */ +{ + ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg); + ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p); + + JERRY_ASSERT (ecma_is_typedarray (this_arg)); + + ecma_builtin_id_t default_constructor = ecma_typedarray_helper_get_constructor_id (info.id); + + ecma_value_t constructor = ecma_op_species_constructor (typedarray_p, default_constructor); + + if (ECMA_IS_VALUE_ERROR (constructor)) + { + return constructor; + } + + ecma_object_t *constructor_proto_p = ecma_get_object_from_value (constructor); + + ecma_value_t result = ecma_typedarray_create (constructor_proto_p, arguments_list_p, arguments_list_len); + ecma_deref_object (constructor_proto_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + +#if JERRY_BUILTIN_BIGINT + ecma_object_t *result_p = ecma_get_object_from_value (result); + ecma_typedarray_info_t result_info = ecma_typedarray_get_info (result_p); + /* + * Check result_info.id to to be either bigint type if info.id is one + * or be neither of them is info.id is none of them as well. + */ + if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info.id) ^ ECMA_TYPEDARRAY_IS_BIGINT_TYPE (result_info.id)) + { + ecma_free_value (result); + return ecma_raise_type_error (ECMA_ERR_CONTENTTYPE_RETURNED_TYPEDARRAY_NOT_MATCH_SOURCE); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + return result; +} /* ecma_typedarray_species_create */ + +/** + * Create a typedarray object based on the "type" and arraylength + * The "type" is same with arg1 + * + * @return ecma_value_t + */ +ecma_value_t +ecma_op_create_typedarray_with_type_and_length (ecma_typedarray_type_t typedarray_id, /** TypedArray id */ + uint32_t array_length) /**< length of the typedarray */ +{ + // TODO: assert validate typedarray_id + ecma_object_t *proto_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (typedarray_id)); + uint8_t element_size_shift = ecma_typedarray_helper_get_shift_size (typedarray_id); + + ecma_value_t new_obj = + ecma_typedarray_create_object_with_length (array_length, NULL, proto_p, element_size_shift, typedarray_id); + + return new_obj; +} /* ecma_op_create_typedarray_with_type_and_length */ + +/** + * Method for getting the additional typedArray information. + */ +ecma_typedarray_info_t +ecma_typedarray_get_info (ecma_object_t *typedarray_p) +{ + ecma_typedarray_info_t info; + + info.id = ecma_get_typedarray_id (typedarray_p); + info.length = ecma_typedarray_get_length (typedarray_p); + info.shift = ecma_typedarray_get_element_size_shift (typedarray_p); + info.element_size = (uint8_t) (1 << info.shift); + info.offset = ecma_typedarray_get_offset (typedarray_p); + info.array_buffer_p = ecma_typedarray_get_arraybuffer (typedarray_p); + + return info; +} /* ecma_typedarray_get_info */ + +/** + * @} + * @} + */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-typedarray-object.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-typedarray-object.h new file mode 100644 index 0000000..ab00426 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/ecma-typedarray-object.h @@ -0,0 +1,89 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_TYPEDARRAY_OBJECT_H +#define ECMA_TYPEDARRAY_OBJECT_H + +#include "ecma-builtins.h" +#include "ecma-globals.h" + +#if JERRY_BUILTIN_TYPEDARRAY + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmatypedarrayobject ECMA TypedArray object related routines + * @{ + */ + +uint8_t ecma_typedarray_helper_get_shift_size (ecma_typedarray_type_t typedarray_id); +lit_magic_string_id_t ecma_get_typedarray_magic_string_id (ecma_typedarray_type_t typedarray_id); +ecma_typedarray_getter_fn_t ecma_get_typedarray_getter_fn (ecma_typedarray_type_t typedarray_id); +ecma_typedarray_setter_fn_t ecma_get_typedarray_setter_fn (ecma_typedarray_type_t typedarray_id); +ecma_value_t ecma_get_typedarray_element (ecma_typedarray_info_t *info_p, uint32_t index); +ecma_value_t ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, ecma_value_t value, uint32_t index); +bool ecma_typedarray_helper_is_typedarray (ecma_builtin_id_t builtin_id); +ecma_typedarray_type_t ecma_get_typedarray_id (ecma_object_t *obj_p); +ecma_builtin_id_t ecma_typedarray_helper_get_prototype_id (ecma_typedarray_type_t typedarray_id); +ecma_builtin_id_t ecma_typedarray_helper_get_constructor_id (ecma_typedarray_type_t typedarray_id); +ecma_typedarray_type_t ecma_typedarray_helper_builtin_to_typedarray_id (ecma_builtin_id_t builtin_id); + +ecma_value_t +ecma_op_typedarray_from (ecma_value_t this_val, ecma_value_t source_val, ecma_value_t mapfn_val, ecma_value_t this_arg); +uint32_t ecma_typedarray_get_length (ecma_object_t *typedarray_p); +uint32_t ecma_typedarray_get_offset (ecma_object_t *typedarray_p); +uint8_t *ecma_typedarray_get_buffer (ecma_typedarray_info_t *info_p); +uint8_t ecma_typedarray_get_element_size_shift (ecma_object_t *typedarray_p); +ecma_object_t *ecma_typedarray_get_arraybuffer (ecma_object_t *typedarray_p); +ecma_value_t ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, + uint32_t arguments_list_len, + ecma_object_t *proto_p, + uint8_t element_size_shift, + ecma_typedarray_type_t typedarray_id); +ecma_value_t ecma_typedarray_iterators_helper (ecma_value_t this_arg, ecma_iterator_kind_t kind); + +bool ecma_object_is_typedarray (ecma_object_t *obj_p); +bool ecma_is_typedarray (ecma_value_t target); +bool ecma_typedarray_is_element_index (ecma_string_t *property_name_p); +void ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, + ecma_collection_t *prop_names_p, + ecma_property_counter_t *prop_counter_p, + jerry_property_filter_t filter); +ecma_value_t ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, + ecma_string_t *property_name_p, + const ecma_property_descriptor_t *property_desc_p); +ecma_value_t ecma_op_create_typedarray_with_type_and_length (ecma_typedarray_type_t typedarray_id, + uint32_t array_length); +ecma_typedarray_info_t ecma_typedarray_get_info (ecma_object_t *typedarray_p); +ecma_value_t ecma_typedarray_create_object_with_length (uint32_t array_length, + ecma_object_t *src_arraybuffer_p, + ecma_object_t *proto_p, + uint8_t element_size_shift, + ecma_typedarray_type_t typedarray_id); +ecma_value_t ecma_typedarray_create_object_with_object (ecma_value_t items_val, + ecma_object_t *proto_p, + uint8_t element_size_shift, + ecma_typedarray_type_t typedarray_id); +ecma_value_t +ecma_typedarray_create (ecma_object_t *constructor_p, ecma_value_t *arguments_list_p, uint32_t arguments_list_len); +ecma_value_t ecma_typedarray_species_create (ecma_value_t this_arg, ecma_value_t *length, uint32_t arguments_list_len); + +/** + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#endif /* !ECMA_TYPEDARRAY_OBJECT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/meson.build new file mode 100644 index 0000000..aa9fe30 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/ecma/operations/meson.build @@ -0,0 +1,68 @@ +source_file = [ + 'ecma-arguments-object.h', + 'ecma-array-object.h', + 'ecma-arraybuffer-object.h', + 'ecma-async-generator-object.h', + 'ecma-atomics-object.h', + 'ecma-big-uint.h', + 'ecma-bigint-object.h', + 'ecma-bigint.h', + 'ecma-boolean-object.h', + 'ecma-comparison.h', + 'ecma-container-object.h', + 'ecma-conversion.h', + 'ecma-dataview-object.h', + 'ecma-eval.h', + 'ecma-exceptions.h', + 'ecma-function-object.h', + 'ecma-iterator-object.h', + 'ecma-jobqueue.h', + 'ecma-lex-env.h', + 'ecma-number-object.h', + 'ecma-objects-general.h', + 'ecma-objects.h', + 'ecma-promise-object.h', + 'ecma-proxy-object.h', + 'ecma-reference.h', + 'ecma-regexp-object.h', + 'ecma-shared-arraybuffer-object.h', + 'ecma-string-object.h', + 'ecma-symbol-object.h', + 'ecma-typedarray-object.h', + 'ecma-arguments-object.cpp', + 'ecma-array-object.cpp', + 'ecma-arraybuffer-object.cpp', + 'ecma-async-generator-object.cpp', + 'ecma-atomics-object.cpp', + 'ecma-big-uint.cpp', + 'ecma-bigint-object.cpp', + 'ecma-bigint.cpp', + 'ecma-boolean-object.cpp', + 'ecma-comparison.cpp', + 'ecma-container-object.cpp', + 'ecma-conversion.cpp', + 'ecma-dataview-object.cpp', + 'ecma-eval.cpp', + 'ecma-exceptions.cpp', + 'ecma-function-object.cpp', + 'ecma-get-put-value.cpp', + 'ecma-iterator-object.cpp', + 'ecma-jobqueue.cpp', + 'ecma-lex-env.cpp', + 'ecma-number-object.cpp', + 'ecma-objects-general.cpp', + 'ecma-objects.cpp', + 'ecma-promise-object.cpp', + 'ecma-proxy-object.cpp', + 'ecma-reference.cpp', + 'ecma-regexp-object.cpp', + 'ecma-shared-arraybuffer-object.cpp', + 'ecma-string-object.cpp', + 'ecma-symbol-object.cpp', + 'ecma-typedarray-object.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerry-config.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerry-config.h new file mode 100644 index 0000000..b92d0bf --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerry-config.h @@ -0,0 +1,324 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRYSCRIPT_CONFIG_H +#define JERRYSCRIPT_CONFIG_H + +// @JERRY_BUILD_CFG@ + +/** + * Built-in configurations + * + * Allowed values for built-in defines: + * 0: Disable the given built-in. + * 1: Enable the given built-in. + */ +/* + * By default all built-ins are enabled if they are not defined. + */ +#ifndef JERRY_BUILTINS +#define JERRY_BUILTINS 1 +#endif /* !defined (JERRY_BUILTINS) */ + +#ifndef JERRY_BUILTIN_ARRAY +#define JERRY_BUILTIN_ARRAY JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_ARRAY) */ + +#ifndef JERRY_BUILTIN_BOOLEAN +#define JERRY_BUILTIN_BOOLEAN JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_BOOLEAN) */ + +#ifndef JERRY_BUILTIN_MATH +#define JERRY_BUILTIN_MATH JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_MATH) */ + +#ifndef JERRY_BUILTIN_NUMBER +#define JERRY_BUILTIN_NUMBER JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_NUMBER) */ + +#ifndef JERRY_BUILTIN_STRING +#define JERRY_BUILTIN_STRING JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_STRING) */ + +#ifndef JERRY_BUILTIN_CONTAINER +#define JERRY_BUILTIN_CONTAINER JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_CONTAINER) */ + +#ifndef JERRY_BUILTIN_TYPEDARRAY +#define JERRY_BUILTIN_TYPEDARRAY JERRY_BUILTINS +#endif /* !defined (JERRY_BUILTIN_TYPEDARRAY) */ + +/** + * Engine internal and misc configurations. + */ + +/** + * Enable/Disable built-in error messages for error objects. + * + * Allowed values: + * 0: Disable error messages. + * 1: Enable error message. + * + * Default value: 0 + */ +#ifndef JERRY_ERROR_MESSAGES +#define JERRY_ERROR_MESSAGES 0 +#endif /* !defined (JERRY_ERROR_MESSAGES) */ + +/** + * Enable/Disable external context. + * + * Allowed values: + * 0: Disable external context. + * 1: Enable external context support. + * + * Default value: 0 + */ +#ifndef JERRY_EXTERNAL_CONTEXT +#define JERRY_EXTERNAL_CONTEXT 0 +#endif /* !defined (JERRY_EXTERNAL_CONTEXT) */ + +/** + * Maximum size of heap in kilobytes + * + * Default value: 512 KiB + */ +#ifndef JERRY_GLOBAL_HEAP_SIZE +#define JERRY_GLOBAL_HEAP_SIZE (512) +#endif /* !defined (JERRY_GLOBAL_HEAP_SIZE) */ + +/** + * The allowed heap usage limit until next garbage collection, in bytes. + * + * If value is 0, the default is 1/32 of JERRY_HEAP_SIZE + */ +#ifndef JERRY_GC_LIMIT +#define JERRY_GC_LIMIT 0 +#endif /* !defined (JERRY_GC_LIMIT) */ + +/** + * Maximum stack usage size in kilobytes + * + * Note: This feature cannot be used when 'detect_stack_use_after_return=1' ASAN option is enabled. + * For more detailed description: + * - https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn#compatibility + * + * Default value: 0, unlimited + */ +#ifndef JERRY_STACK_LIMIT +#define JERRY_STACK_LIMIT (0) +#endif /* !defined (JERRY_STACK_LIMIT) */ + +/** + * Maximum depth of recursion during GC mark phase + * + * Default value: 8 + */ +#ifndef JERRY_GC_MARK_LIMIT +#define JERRY_GC_MARK_LIMIT (8) +#endif /* !defined (JERRY_GC_MARK_LIMIT) */ + +/** + * Enable/Disable property lookup cache. + * + * Allowed values: + * 0: Disable lookup cache. + * 1: Enable lookup cache. + * + * Default value: 1 + */ +#ifndef JERRY_LCACHE +#define JERRY_LCACHE 1 +#endif /* !defined (JERRY_LCACHE) */ + +/** + * Use 32-bit/64-bit float for ecma-numbers + * This option is for expert use only! + * + * Allowed values: + * 1: use 64-bit floating point number mode + * 0: use 32-bit floating point number mode + * + * Default value: 1 + */ +#ifndef JERRY_NUMBER_TYPE_FLOAT64 +#define JERRY_NUMBER_TYPE_FLOAT64 1 +#endif /* !defined (JERRY_NUMBER_TYPE_FLOAT64 */ + +/** + * Enable/Disable the JavaScript parser. + * + * Allowed values: + * 0: Disable the JavaScript parser and all related functionality. + * 1: Enable the JavaScript parser. + * + * Default value: 1 + */ +#ifndef JERRY_PARSER +#define JERRY_PARSER 1 +#endif /* !defined (JERRY_PARSER) */ + +/** + * Enable/Disable JerryScript byte code dump functions during parsing. + * To dump the JerryScript byte code the engine must be initialized with opcodes + * display flag. This option does not influence RegExp byte code dumps. + * + * Allowed values: + * 0: Disable all bytecode dump functions. + * 1: Enable bytecode dump functions. + * + * Default value: 0 + */ +#ifndef JERRY_PARSER_DUMP_BYTE_CODE +#define JERRY_PARSER_DUMP_BYTE_CODE 0 +#endif /* defined (JERRY_PARSER_DUMP_BYTE_CODE) */ + +/** + * Enable/Disable ECMA property hashmap. + * + * Allowed values: + * 0: Disable property hashmap. + * 1: Enable property hashmap. + * + * Default value: 1 + */ +#ifndef JERRY_PROPERTY_HASHMAP +#define JERRY_PROPERTY_HASHMAP 0 +#endif /* !defined (JERRY_PROPERTY_HASHMAP) */ + +/** + * Enable/Disable byte code dump functions for RegExp objects. + * To dump the RegExp byte code the engine must be initialized with + * regexp opcodes display flag. This option does not influence the + * JerryScript byte code dumps. + * + * Allowed values: + * 0: Disable all bytecode dump functions. + * 1: Enable bytecode dump functions. + * + * Default value: 0 + */ +#ifndef JERRY_REGEXP_DUMP_BYTE_CODE +#define JERRY_REGEXP_DUMP_BYTE_CODE 0 +#endif /* !defined (JERRY_REGEXP_DUMP_BYTE_CODE) */ + +/** + * Enable/Disable the snapshot execution functions. + * + * Allowed values: + * 0: Disable snapshot execution. + * 1: Enable snapshot execution. + * + * Default value: 0 + */ +#ifndef JERRY_SNAPSHOT_EXEC +#define JERRY_SNAPSHOT_EXEC 0 +#endif /* !defined (JERRY_SNAPSHOT_EXEC) */ + +/** + * Enable/Disable the snapshot save functions. + * + * Allowed values: + * 0: Disable snapshot save functions. + * 1: Enable snapshot save functions. + */ +#ifndef JERRY_SNAPSHOT_SAVE +#define JERRY_SNAPSHOT_SAVE 0 +#endif /* !defined (JERRY_SNAPSHOT_SAVE) */ + +/** + * Enable/Disable usage of system allocator. + * + * Allowed values: + * 0: Disable usage of system allocator. + * 1: Enable usage of system allocator. + * + * Default value: 0 + */ +#ifndef JERRY_SYSTEM_ALLOCATOR +#define JERRY_SYSTEM_ALLOCATOR 0 +#endif /* !defined (JERRY_SYSTEM_ALLOCATOR) */ + +/** + * Enables/disables the unicode case conversion in the engine. + * By default Unicode case conversion is enabled. + */ +#ifndef JERRY_UNICODE_CASE_CONVERSION +#define JERRY_UNICODE_CASE_CONVERSION 0 +#endif /* !defined (JERRY_UNICODE_CASE_CONVERSION) */ + +/** + * Enable/Disable the vm execution stop callback function. + * + * Allowed values: + * 0: Disable vm exec stop callback support. + * 1: Enable vm exec stop callback support. + */ +#ifndef JERRY_VM_HALT +#define JERRY_VM_HALT 0 +#endif /* !defined (JERRY_VM_HALT) */ + +/** + * Enable/Disable the vm throw callback function. + * + * Allowed values: + * 0: Disable vm throw callback support. + * 1: Enable vm throw callback support. + */ +#ifndef JERRY_VM_THROW +#define JERRY_VM_THROW 0 +#endif /* !defined (JERRY_VM_THROW) */ + +/** + * Advanced section configurations. + */ + +/** + * Allow configuring attributes on a few constant data inside the engine. + * + * One of the main usages: + * Normally compilers store const(ant)s in ROM. Thus saving RAM. + * But if your compiler does not support it then the directive below can force it. + * + * For the moment it is mainly meant for the following targets: + * - ESP8266 + * + * Example configuration for moving (some) constants into a given section: + * # define JERRY_ATTR_CONST_DATA __attribute__((section(".rodata.const"))) + */ +#ifndef JERRY_ATTR_CONST_DATA +#define JERRY_ATTR_CONST_DATA +#endif /* !defined (JERRY_ATTR_CONST_DATA) */ + +/** + * The JERRY_ATTR_GLOBAL_HEAP allows adding extra attributes for the Jerry global heap. + * + * Example on how to move the global heap into its own section: + * #define JERRY_ATTR_GLOBAL_HEAP __attribute__((section(".text.globalheap"))) + */ +#ifndef JERRY_ATTR_GLOBAL_HEAP +#define JERRY_ATTR_GLOBAL_HEAP +#endif /* !defined (JERRY_ATTR_GLOBAL_HEAP) */ + +/** + * Source name related types into a single guard + */ +#if JERRY_ERROR_MESSAGES +#define JERRY_SOURCE_NAME 1 +#else /* !(JERRY_ERROR_MESSAGES) */ +#define JERRY_SOURCE_NAME 0 +#endif /* JERRY_ERROR_MESSAGES */ + +#endif /* !JERRYSCRIPT_CONFIG_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-compiler.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-compiler.h new file mode 100644 index 0000000..c507576 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-compiler.h @@ -0,0 +1,187 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRYSCRIPT_COMPILER_H +#define JERRYSCRIPT_COMPILER_H + +#ifdef __cplusplus +#define JERRY_C_API_BEGIN extern "C" { +#define JERRY_C_API_END } +#else /* !__cplusplus */ +#define JERRY_C_API_BEGIN +#define JERRY_C_API_END +#endif /* __cplusplus */ + +JERRY_C_API_BEGIN + +/** \addtogroup jerry-compiler Jerry compiler compatibility components + * @{ + */ + +#ifdef __GNUC__ + +/* + * Compiler-specific macros relevant for GCC. + */ +#define JERRY_ATTR_ALIGNED(ALIGNMENT) __attribute__ ((aligned (ALIGNMENT))) +#define JERRY_ATTR_CONST __attribute__ ((const)) +#define JERRY_ATTR_DEPRECATED __attribute__ ((deprecated)) +#define JERRY_ATTR_FORMAT(...) __attribute__ ((format (__VA_ARGS__))) +#define JERRY_ATTR_HOT __attribute__ ((hot)) +#define JERRY_ATTR_NOINLINE __attribute__ ((noinline)) +#define JERRY_ATTR_NORETURN __attribute__ ((noreturn)) +#define JERRY_ATTR_PURE __attribute__ ((pure)) +#define JERRY_ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) +#define JERRY_ATTR_WEAK __attribute__ ((weak)) + +#define JERRY_WEAK_SYMBOL_SUPPORT + +#ifndef JERRY_LIKELY +#define JERRY_LIKELY(x) __builtin_expect (!!(x), 1) +#endif /* !JERRY_LIKELY */ + +#ifndef JERRY_UNLIKELY +#define JERRY_UNLIKELY(x) __builtin_expect (!!(x), 0) +#endif /* !JERRY_UNLIKELY */ + +#endif /* __GNUC__ */ + +#ifdef _MSC_VER + +/* + * Compiler-specific macros relevant for Microsoft Visual C/C++ Compiler. + */ +#define JERRY_ATTR_DEPRECATED __declspec (deprecated) +#define JERRY_ATTR_NOINLINE __declspec (noinline) +#define JERRY_ATTR_NORETURN __declspec (noreturn) + +/* + * Microsoft Visual C/C++ Compiler doesn't support for VLA, using _alloca + * instead. + */ +void *__cdecl _alloca (size_t _Size); +#define JERRY_VLA(type, name, size) type *name = (type *) (_alloca (sizeof (type) * (size))) + +#endif /* _MSC_VER */ + +/* + * Default empty definitions for all compiler-specific macros. Define any of + * these in a guarded block above (e.g., as for GCC) to fine tune compilation + * for your own compiler. */ + +/** + * Function attribute to align function to given number of bytes. + */ +#ifndef JERRY_ATTR_ALIGNED +#define JERRY_ATTR_ALIGNED(ALIGNMENT) +#endif /* !JERRY_ATTR_ALIGNED */ + + +/** + * Function attribute to declare that function has no effect except the return + * value and it only depends on parameters. + */ +#ifndef JERRY_ATTR_CONST +#define JERRY_ATTR_CONST +#endif /* !JERRY_ATTR_CONST */ + +/** + * Function attribute to trigger warning if deprecated function is called. + */ +#ifndef JERRY_ATTR_DEPRECATED +#define JERRY_ATTR_DEPRECATED +#endif /* !JERRY_ATTR_DEPRECATED */ + +/** + * Function attribute to declare that function is variadic and takes a format + * string and some arguments as parameters. + */ +#ifndef JERRY_ATTR_FORMAT +#define JERRY_ATTR_FORMAT(...) +#endif /* !JERRY_ATTR_FORMAT */ + +/** + * Function attribute to predict that function is a hot spot, and therefore + * should be optimized aggressively. + */ +#ifndef JERRY_ATTR_HOT +#define JERRY_ATTR_HOT +#endif /* !JERRY_ATTR_HOT */ + +/** + * Function attribute not to inline function ever. + */ +#ifndef JERRY_ATTR_NOINLINE +#define JERRY_ATTR_NOINLINE +#endif /* !JERRY_ATTR_NOINLINE */ + +/** + * Function attribute to declare that function never returns. + */ +#ifndef JERRY_ATTR_NORETURN +#define JERRY_ATTR_NORETURN +#endif /* !JERRY_ATTR_NORETURN */ + +/** + * Function attribute to declare that function has no effect except the return + * value and it only depends on parameters and global variables. + */ +#ifndef JERRY_ATTR_PURE +#define JERRY_ATTR_PURE +#endif /* !JERRY_ATTR_PURE */ + +/** + * Function attribute to trigger warning if function's caller doesn't use (e.g., + * check) the return value. + */ +#ifndef JERRY_ATTR_WARN_UNUSED_RESULT +#define JERRY_ATTR_WARN_UNUSED_RESULT +#endif /* !JERRY_ATTR_WARN_UNUSED_RESULT */ + +/** + * Function attribute to declare a function a weak symbol + */ +#ifndef JERRY_ATTR_WEAK +#define JERRY_ATTR_WEAK +#endif /* !JERRY_ATTR_WEAK */ + +/** + * Helper to predict that a condition is likely. + */ +#ifndef JERRY_LIKELY +#define JERRY_LIKELY(x) (x) +#endif /* !JERRY_LIKELY */ + +/** + * Helper to predict that a condition is unlikely. + */ +#ifndef JERRY_UNLIKELY +#define JERRY_UNLIKELY(x) (x) +#endif /* !JERRY_UNLIKELY */ + +/** + * Helper to declare (or mimic) a C99 variable-length array. + */ +#ifndef JERRY_VLA +#define JERRY_VLA(type, name, size) type* name = (type*)alloca((size) * sizeof(type)) +#endif /* !JERRY_VLA */ + +/** + * @} + */ + +JERRY_C_API_END + +#endif /* !JERRYSCRIPT_COMPILER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h new file mode 100644 index 0000000..e10e6e3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h @@ -0,0 +1,68 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRYSCRIPT_CORE_H +#define JERRYSCRIPT_CORE_H + +#include "jerryscript-types.h" + +JERRY_C_API_BEGIN + +void jerry_init (jerry_init_flag_t flags); +void jerry_cleanup (void); +jerry_value_t jerry_current_realm (void); +jerry_value_t jerry_set_realm (jerry_value_t realm); +jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, uint32_t flags); +jerry_value_t jerry_run (const jerry_value_t script); +bool jerry_value_is_undefined (const jerry_value_t value); +bool jerry_value_is_number (const jerry_value_t value); +bool jerry_value_is_object (const jerry_value_t value); +bool jerry_value_is_string (const jerry_value_t value); +bool jerry_value_is_exception (const jerry_value_t value); +jerry_value_t jerry_value_to_object (const jerry_value_t value); +jerry_value_t jerry_value_to_string (const jerry_value_t value); +float jerry_value_as_number (const jerry_value_t value); +int32_t jerry_value_as_int32 (const jerry_value_t value); +uint32_t jerry_value_as_uint32 (const jerry_value_t value); +jerry_value_t JERRY_ATTR_CONST jerry_undefined (void); +jerry_value_t JERRY_ATTR_CONST jerry_null (void); +jerry_value_t JERRY_ATTR_CONST jerry_boolean (bool value); +jerry_value_t jerry_number (float value); +jerry_value_t jerry_string (const jerry_char_t *buffer_p, jerry_size_t buffer_size, jerry_encoding_t encoding); +jerry_value_t jerry_string_sz (const char *str_p); +jerry_length_t jerry_string_length (const jerry_value_t value); +jerry_size_t jerry_string_to_buffer (const jerry_value_t value, + jerry_encoding_t encoding, + jerry_char_t *buffer_p, + jerry_size_t buffer_size); +jerry_value_t jerry_object (void); +jerry_value_t jerry_object_set (jerry_value_t object, const jerry_value_t key, const jerry_value_t value); +jerry_value_t jerry_object_set_sz (jerry_value_t object, const char *key_p, const jerry_value_t value); +jerry_value_t jerry_object_set_index (jerry_value_t object, uint32_t index, const jerry_value_t value); +void jerry_object_set_native_ptr (jerry_value_t object, + const jerry_object_native_info_t *native_info_p, + void *native_pointer_p); +jerry_value_t jerry_object_get (const jerry_value_t object, const jerry_value_t key); +jerry_value_t jerry_object_get_sz (const jerry_value_t object, const char *key_p); +jerry_value_t jerry_object_get_index (const jerry_value_t object, uint32_t index); +void *jerry_object_get_native_ptr (const jerry_value_t object, const jerry_object_native_info_t *native_info_p); +jerry_value_t jerry_function_external (jerry_external_handler_t handler); +void jerry_value_free (jerry_value_t value); + +JERRY_C_API_END + +#endif /* !JERRYSCRIPT_CORE_H */ + +/* vim: set fdm=marker fmr=@{,@}: */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-port.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-port.h new file mode 100644 index 0000000..9567480 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-port.h @@ -0,0 +1,313 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRYSCRIPT_PORT_H +#define JERRYSCRIPT_PORT_H + +#include "jerryscript-types.h" + +JERRY_C_API_BEGIN + +/** + * @defgroup jerry-port JerryScript Port API + * @{ + */ + +/** + * @defgroup jerry-port-process Process management API + * + * It is questionable whether a library should be able to terminate an + * application. However, as of now, we only have the concept of completion + * code around jerry_parse and jerry_run. Most of the other API functions + * have no way of signaling an error. So, we keep the termination approach + * with this port function. + * + * @{ + */ + +/** + * Error codes that can be passed by the engine when calling jerry_port_fatal + */ +typedef enum +{ + JERRY_FATAL_OUT_OF_MEMORY = 10, /**< Out of memory */ + JERRY_FATAL_REF_COUNT_LIMIT = 12, /**< Reference count limit reached */ + JERRY_FATAL_DISABLED_BYTE_CODE = 13, /**< Executed disabled instruction */ + JERRY_FATAL_UNTERMINATED_GC_LOOPS = 14, /**< Garbage collection loop limit reached */ + JERRY_FATAL_FAILED_ASSERTION = 120 /**< Assertion failed */ +} jerry_fatal_code_t; + +/** + * Signal the port that the process experienced a fatal failure from which it cannot + * recover. + * + * A libc-based port may implement this with exit() or abort(), or both. + * + * @param code: the cause of the error. + * @return This function is expected to not return. + */ +void JERRY_ATTR_NORETURN jerry_port_fatal (jerry_fatal_code_t code); + +/** + * Make the process sleep for a given time. + * + * This port function can be called by jerry-core when JERRY_DEBUGGER is enabled. + * Otherwise this function is not used. + * + * @param sleep_time: milliseconds to sleep. + */ +void jerry_port_sleep (uint32_t sleep_time); + +/** + * jerry-port-process @} + */ + +/** + * @defgroup jerry-port-context External Context API + * @{ + */ + +/** + * Allocate a new context for the engine. + * + * This port function is called by jerry_init when JERRY_EXTERNAL_CONTEXT is enabled. Otherwise this function is not + * used. + * + * The engine will pass the size required for the context structure. An implementation must make sure to + * allocate at least this amount. + * + * Excess allocated space will be used as the engine heap when JerryScript is configured to use it's internal allocator, + * this can be used to control the internal heap size. + * + * NOTE: The allocated memory must be pointer-aligned, otherwise the behavior is undefined. + * + * @param context_size: the size of the internal context structure + * + * @return total size of the allocated buffer + */ +size_t jerry_port_context_alloc (size_t context_size); + +/** + * Get the currently active context of the engine. + * + * This port function is called by jerry-core when JERRY_EXTERNAL_CONTEXT is enabled. + * Otherwise this function is not used. + * + * @return the pointer to the currently used engine context. + */ +struct jerry_context_t *jerry_port_context_get (void); + +/** + * Free the currently used context. + * + * This port function is called by jerry_cleanup when JERRY_EXTERNAL_CONTEXT is enabled. + * Otherwise this function is not used. + */ +void jerry_port_context_free (void); + +/** + * jerry-port-context @} + */ + +/** + * @defgroup jerry-port-io I/O API + * @{ + */ + +/** + * Display or log a debug/error message. + * + * The message is passed as a zero-terminated string. Messages may be logged in parts, which + * will result in multiple calls to this functions. The implementation should consider + * this before appending or prepending strings to the argument. + * + * This function is called with messages coming from the jerry engine as + * the result of some abnormal operation or describing its internal operations + * (e.g., data structure dumps or tracing info). + * + * The implementation can decide whether error and debug messages are logged to + * the console, or saved to a database or to a file. + */ +void jerry_port_log (const char *message_p); + +/** + * Print a single character to standard output. + * + * This port function is never called from jerry-core directly, it is only used by jerry-ext components to print + * information. + * + * @param byte: the byte to print. + */ +void jerry_port_print_byte (jerry_char_t byte); + +/** + * Print a buffer to standard output + * + * This port function is never called from jerry-core directly, it is only used by jerry-ext components to print + * information. + * + * @param buffer_p: input buffer + * @param buffer_size: data size + */ +void jerry_port_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size); + +/** + * Read a line from standard input. + * + * The implementation should allocate storage necessary for the string. The result string should include the ending line + * terminator character(s) and should be zero terminated. + * + * An implementation may return NULL to signal that the end of input is reached, or an error occurred. + * + * When a non-NULL value is returned, the caller will pass the returned value to `jerry_port_line_free` when the line is + * no longer needed. This can be used to finalize dynamically allocated buffers if necessary. + * + * This port function is never called from jerry-core directly, it is only used by some jerry-ext components that + * require user input. + * + * @param out_size_p: size of the input string in bytes, excluding terminating zero byte + * + * @return pointer to the buffer storing the string, + * or NULL if end of input + */ +jerry_char_t *jerry_port_line_read (jerry_size_t *out_size_p); + +/** + * Free a line buffer allocated by jerry_port_line_read + * + * @param buffer_p: buffer returned by jerry_port_line_read + */ +void jerry_port_line_free (jerry_char_t *buffer_p); + +/** + * jerry-port-io @} + */ + +/** + * @defgroup jerry-port-fd Filesystem API + * @{ + */ + +/** + * Canonicalize a file path. + * + * If possible, the implementation should resolve symbolic links and other directory references found in the input path, + * and create a fully canonicalized file path as the result. + * + * The function may return with NULL in case an error is encountered, in which case the calling operation will not + * proceed. + * + * The implementation should allocate storage for the result path as necessary. Non-NULL return values will be passed + * to `jerry_port_path_free` when the result is no longer needed by the caller, which can be used to finalize + * dynamically allocated buffers. + * + * NOTE: The implementation must not return directly with the input, as the input buffer is released after the call. + * + * @param path_p: zero-terminated string containing the input path + * @param path_size: size of the input path string in bytes, excluding terminating zero + * + * @return buffer with the normalized path if the operation is successful, + * NULL otherwise + */ +jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size); + +/** + * Free a path buffer returned by jerry_port_path_normalize. + * + * @param path_p: the path buffer to free + */ +void jerry_port_path_free (jerry_char_t *path_p); + +/** + * Get the offset of the basename component in the input path. + * + * The implementation should return the offset of the first character after the last path separator found in the path. + * This is used by the caller to split the path into a directory name and a file name. + * + * @param path_p: input zero-terminated path string + * + * @return offset of the basename component in the input path + */ +jerry_size_t jerry_port_path_base (const jerry_char_t *path_p); + +/** + * Open a source file and read the content into a buffer. + * + * When the source file is no longer needed by the caller, the returned pointer will be passed to + * `jerry_port_source_free`, which can be used to finalize the buffer. + * + * @param file_name_p: Path that points to the source file in the filesystem. + * @param out_size_p: The opened file's size in bytes. + * + * @return pointer to the buffer which contains the content of the file. + */ +jerry_char_t *jerry_port_source_read (const char *file_name_p, jerry_size_t *out_size_p); + +/** + * Free a source file buffer. + * + * @param buffer_p: buffer returned by jerry_port_source_read + */ +void jerry_port_source_free (jerry_char_t *buffer_p); + +/** + * jerry-port-fs @} + */ + +/** + * @defgroup jerry-port-date Date API + * @{ + */ + +/** + * Get local time zone adjustment in milliseconds for the given input time. + * + * The argument is a time value representing milliseconds since unix epoch. + * + * Ideally, this function should satisfy the stipulations applied to LocalTZA + * in section 21.4.1.7 of the ECMAScript version 12.0, as if called with isUTC true. + * + * This port function can be called by jerry-core when JERRY_BUILTIN_DATE is enabled. + * Otherwise this function is not used. + * + * @param unix_ms: time value in milliseconds since unix epoch + * + * @return local time offset in milliseconds applied to UTC for the given time value + */ +int32_t jerry_port_local_tza (double unix_ms); + +/** + * Get the current system time in UTC. + * + * This port function is called by jerry-core when JERRY_BUILTIN_DATE is enabled. + * It can also be used in the implementing application to initialize the random number generator. + * + * @return milliseconds since Unix epoch + */ +double jerry_port_current_time (void); + +/** + * jerry-port-date @} + */ + +/** + * jerry-port @} + */ + +JERRY_C_API_END + +#endif /* !JERRYSCRIPT_PORT_H */ + +/* vim: set fdm=marker fmr=@{,@}: */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-types.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-types.h new file mode 100644 index 0000000..eb9cd12 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-types.h @@ -0,0 +1,865 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRYSCRIPT_TYPES_H +#define JERRYSCRIPT_TYPES_H + +#include +#include +#include + +#include "jerryscript-compiler.h" + +JERRY_C_API_BEGIN + +/** + * @defgroup jerry-api-types JerryScript public API types + * @{ + */ + +/** + * JerryScript init flags. + */ +typedef enum +{ + JERRY_INIT_EMPTY = (0u), /**< empty flag set */ + JERRY_INIT_SHOW_OPCODES = (1u << 0), /**< dump byte-code to log after parse */ + JERRY_INIT_SHOW_REGEXP_OPCODES = (1u << 1), /**< dump regexp byte-code to log after compilation */ + JERRY_INIT_MEM_STATS = (1u << 2), /**< dump memory statistics */ +} jerry_init_flag_t; + +/** + * Jerry log levels. The levels are in severity order + * where the most serious levels come first. + */ +typedef enum +{ + JERRY_LOG_LEVEL_ERROR = 0u, /**< the engine will terminate after the message is printed */ + JERRY_LOG_LEVEL_WARNING = 1u, /**< a request is aborted, but the engine continues its operation */ + JERRY_LOG_LEVEL_DEBUG = 2u, /**< debug messages from the engine, low volume */ + JERRY_LOG_LEVEL_TRACE = 3u /**< detailed info about engine internals, potentially high volume */ +} jerry_log_level_t; + +/** + * JerryScript API Error object types. + */ +typedef enum +{ + JERRY_ERROR_NONE = 0, /**< No Error */ + + JERRY_ERROR_COMMON, /**< Error */ + JERRY_ERROR_EVAL, /**< EvalError */ + JERRY_ERROR_RANGE, /**< RangeError */ + JERRY_ERROR_REFERENCE, /**< ReferenceError */ + JERRY_ERROR_SYNTAX, /**< SyntaxError */ + JERRY_ERROR_TYPE, /**< TypeError */ + JERRY_ERROR_URI, /**< URIError */ + JERRY_ERROR_AGGREGATE /**< AggregateError */ +} jerry_error_t; + +/** + * JerryScript feature types. + */ +typedef enum +{ + JERRY_FEATURE_CPOINTER_32_BIT, /**< 32 bit compressed pointers */ + JERRY_FEATURE_ERROR_MESSAGES, /**< error messages */ + JERRY_FEATURE_JS_PARSER, /**< js-parser */ + JERRY_FEATURE_HEAP_STATS, /**< memory statistics */ + JERRY_FEATURE_PARSER_DUMP, /**< parser byte-code dumps */ + JERRY_FEATURE_REGEXP_DUMP, /**< regexp byte-code dumps */ + JERRY_FEATURE_SNAPSHOT_SAVE, /**< saving snapshot files */ + JERRY_FEATURE_SNAPSHOT_EXEC, /**< executing snapshot files */ + JERRY_FEATURE_DEBUGGER, /**< debugging */ + JERRY_FEATURE_VM_EXEC_STOP, /**< stopping ECMAScript execution */ + JERRY_FEATURE_VM_THROW, /**< capturing ECMAScript throws */ + JERRY_FEATURE_JSON, /**< JSON support */ + JERRY_FEATURE_PROMISE, /**< promise support */ + JERRY_FEATURE_TYPEDARRAY, /**< Typedarray support */ + JERRY_FEATURE_DATE, /**< Date support */ + JERRY_FEATURE_REGEXP, /**< Regexp support */ + JERRY_FEATURE_LINE_INFO, /**< line info available */ + JERRY_FEATURE_LOGGING, /**< logging */ + JERRY_FEATURE_SYMBOL, /**< symbol support */ + JERRY_FEATURE_DATAVIEW, /**< DataView support */ + JERRY_FEATURE_PROXY, /**< Proxy support */ + JERRY_FEATURE_MAP, /**< Map support */ + JERRY_FEATURE_SET, /**< Set support */ + JERRY_FEATURE_WEAKMAP, /**< WeakMap support */ + JERRY_FEATURE_WEAKSET, /**< WeakSet support */ + JERRY_FEATURE_BIGINT, /**< BigInt support */ + JERRY_FEATURE_REALM, /**< realm support */ + JERRY_FEATURE_GLOBAL_THIS, /**< GlobalThisValue support */ + JERRY_FEATURE_PROMISE_CALLBACK, /**< Promise callback support */ + JERRY_FEATURE_MODULE, /**< Module support */ + JERRY_FEATURE_WEAKREF, /**< WeakRef support */ + JERRY_FEATURE_FUNCTION_TO_STRING, /**< function toString support */ + JERRY_FEATURE__COUNT /**< number of features. NOTE: must be at the end of the list */ +} jerry_feature_t; + +/** + * GC operational modes. + */ +typedef enum +{ + JERRY_GC_PRESSURE_LOW, /**< free unused objects, but keep memory + * allocated for performance improvements + * such as property hash tables for large objects */ + JERRY_GC_PRESSURE_HIGH /**< free as much memory as possible */ +} jerry_gc_mode_t; + +/** + * Jerry regexp flags. + */ +typedef enum +{ + JERRY_REGEXP_FLAG_GLOBAL = (1u << 1), /**< Globally scan string */ + JERRY_REGEXP_FLAG_IGNORE_CASE = (1u << 2), /**< Ignore case */ + JERRY_REGEXP_FLAG_MULTILINE = (1u << 3), /**< Multiline string scan */ + JERRY_REGEXP_FLAG_STICKY = (1u << 4), /**< ECMAScript v11, 21.2.5.14 */ + JERRY_REGEXP_FLAG_UNICODE = (1u << 5), /**< ECMAScript v11, 21.2.5.17 */ + JERRY_REGEXP_FLAG_DOTALL = (1u << 6) /**< ECMAScript v11, 21.2.5.3 */ +} jerry_regexp_flags_t; + +/** + * Character type of JerryScript. + */ +typedef uint8_t jerry_char_t; + +/** + * Size type of JerryScript. + */ +typedef uint32_t jerry_size_t; + +/** + * Length type of JerryScript. + */ +typedef uint32_t jerry_length_t; + +/** + * Description of a JerryScript value. + */ +typedef uint32_t jerry_value_t; + +/** + * Option bits for jerry_parse_options_t. + */ +typedef enum +{ + JERRY_PARSE_NO_OPTS = 0, /**< no options passed */ + JERRY_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */ + JERRY_PARSE_MODULE = (1 << 1), /**< parse source as an ECMAScript module */ + JERRY_PARSE_HAS_ARGUMENT_LIST = (1 << 2), /**< argument_list field is valid, + * this also means that function parsing will be done */ + JERRY_PARSE_HAS_SOURCE_NAME = (1 << 3), /**< source_name field is valid */ + JERRY_PARSE_HAS_START = (1 << 4), /**< start_line and start_column fields are valid */ + JERRY_PARSE_HAS_USER_VALUE = (1 << 5), /**< user_value field is valid */ +} jerry_parse_option_enable_feature_t; + +/** + * Various configuration options for parsing functions such as jerry_parse or jerry_parse_function. + */ +typedef struct +{ + uint32_t options; /**< combination of jerry_parse_option_enable_feature_t values */ + jerry_value_t argument_list; /**< function argument list if JERRY_PARSE_HAS_ARGUMENT_LIST is set in options + * Note: must be string value */ + jerry_value_t source_name; /**< source name string (usually a file name) + * if JERRY_PARSE_HAS_SOURCE_NAME is set in options + * Note: must be string value */ + uint32_t start_line; /**< start line of the source code if JERRY_PARSE_HAS_START is set in options */ + uint32_t start_column; /**< start column of the source code if JERRY_PARSE_HAS_START is set in options */ + jerry_value_t user_value; /**< user value assigned to all functions created by this script including eval + * calls executed by the script if JERRY_PARSE_HAS_USER_VALUE is set in options */ +} jerry_parse_options_t; + +/** + * Description of ECMA property descriptor. + */ +typedef enum +{ + JERRY_PROP_NO_OPTS = (0), /**< empty property descriptor */ + JERRY_PROP_IS_CONFIGURABLE = (1 << 0), /**< [[Configurable]] */ + JERRY_PROP_IS_ENUMERABLE = (1 << 1), /**< [[Enumerable]] */ + JERRY_PROP_IS_WRITABLE = (1 << 2), /**< [[Writable]] */ + + JERRY_PROP_IS_CONFIGURABLE_DEFINED = (1 << 3), /**< is [[Configurable]] defined? */ + JERRY_PROP_IS_ENUMERABLE_DEFINED = (1 << 4), /**< is [[Enumerable]] defined? */ + JERRY_PROP_IS_WRITABLE_DEFINED = (1 << 5), /**< is [[Writable]] defined? */ + + JERRY_PROP_IS_VALUE_DEFINED = (1 << 6), /**< is [[Value]] defined? */ + JERRY_PROP_IS_GET_DEFINED = (1 << 7), /**< is [[Get]] defined? */ + JERRY_PROP_IS_SET_DEFINED = (1 << 8), /**< is [[Set]] defined? */ + + JERRY_PROP_SHOULD_THROW = (1 << 9), /**< should throw on error, instead of returning with false */ +} jerry_property_descriptor_flags_t; + +/** + * Description of ECMA property descriptor. + */ +typedef struct +{ + uint16_t flags; /**< any combination of jerry_property_descriptor_flags_t bits */ + jerry_value_t value; /**< [[Value]] */ + jerry_value_t getter; /**< [[Get]] */ + jerry_value_t setter; /**< [[Set]] */ +} jerry_property_descriptor_t; + +/** + * JerryScript object property filter options. + */ +typedef enum +{ + JERRY_PROPERTY_FILTER_ALL = 0, /**< List all property keys independently + * from key type or property value attributes + * (equivalent to Reflect.ownKeys call) */ + JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN = (1 << 0), /**< Include keys from the objects's + * prototype chain as well */ + JERRY_PROPERTY_FILTER_EXCLUDE_NON_CONFIGURABLE = (1 << 1), /**< Exclude property key if + * the property is non-configurable */ + JERRY_PROPERTY_FILTER_EXCLUDE_NON_ENUMERABLE = (1 << 2), /**< Exclude property key if + * the property is non-enumerable */ + JERRY_PROPERTY_FILTER_EXCLUDE_NON_WRITABLE = (1 << 3), /**< Exclude property key if + * the property is non-writable */ + JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS = (1 << 4), /**< Exclude property key if it is a string */ + JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS = (1 << 5), /**< Exclude property key if it is a symbol */ + JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES = (1 << 6), /**< Exclude property key if it is an integer index */ + JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER = (1 << 7), /**< By default integer index property keys are + * converted to string. Enabling this flags keeps + * integer index property keys as numbers. */ +} jerry_property_filter_t; + +/** + * String encoding. + */ +typedef enum +{ + JERRY_ENCODING_CESU8, /**< cesu-8 encoding */ + JERRY_ENCODING_UTF8, /**< utf-8 encoding */ +} jerry_encoding_t; + +/** + * Description of JerryScript heap memory stats. + * It is for memory profiling. + */ +typedef struct +{ + size_t version; /**< the version of the stats struct */ + size_t size; /**< heap total size */ + size_t allocated_bytes; /**< currently allocated bytes */ + size_t peak_allocated_bytes; /**< peak allocated bytes */ + size_t reserved[4]; /**< padding for future extensions */ +} jerry_heap_stats_t; + +/** + * Call related information passed to jerry_external_handler_t. + */ +typedef struct jerry_call_info_t +{ + jerry_value_t function; /**< invoked function object */ + jerry_value_t this_value; /**< this value passed to the function */ + jerry_value_t new_target; /**< current new target value, undefined for non-constructor calls */ +} jerry_call_info_t; + +/** + * Type of an external function handler. + */ +typedef jerry_value_t (*jerry_external_handler_t) (const jerry_call_info_t *call_info_p, + const jerry_value_t args_p[], + const jerry_length_t args_count); + +/** + * Native free callback of generic value types. + */ +typedef void (*jerry_value_free_cb_t) (void *native_p); + +/** + * Forward definition of jerry_object_native_info_t. + */ +struct jerry_object_native_info_t; + +/** + * Native free callback of an object. + */ +typedef void (*jerry_object_native_free_cb_t) (void *native_p, struct jerry_object_native_info_t *info_p); + +/** + * Free callback for external strings. + */ +typedef void (*jerry_external_string_free_cb_t) (jerry_char_t *string_p, jerry_size_t string_size, void *user_p); + +/** + * Decorator callback for Error objects. The decorator can create + * or update any properties of the newly created Error object. + */ +typedef void (*jerry_error_object_created_cb_t) (const jerry_value_t error_object, void *user_p); + +/** + * Callback which tells whether the ECMAScript execution should be stopped. + * + * As long as the function returns with undefined the execution continues. + * When a non-undefined value is returned the execution stops and the value + * is thrown by the engine as an exception. + * + * Note: if the function returns with a non-undefined value it + * must return with the same value for future calls. + */ +typedef jerry_value_t (*jerry_halt_cb_t) (void *user_p); + +/** + * Callback function which is called when an exception is thrown in an ECMAScript code. + * The callback should not change the exception_value. The callback is not called again + * until the value is caught. + * + * Note: the engine considers exceptions thrown by external functions as never caught. + */ +typedef void (*jerry_throw_cb_t) (const jerry_value_t exception_value, void *user_p); + +/** + * Function type applied to each unit of encoding when iterating over a string. + */ +typedef void (*jerry_string_iterate_cb_t) (uint32_t value, void *user_p); + +/** + * Function type applied for each data property of an object. + */ +typedef bool (*jerry_object_property_foreach_cb_t) (const jerry_value_t property_name, + const jerry_value_t property_value, + void *user_data_p); + +/** + * Function type applied for each object in the engine. + */ +typedef bool (*jerry_foreach_live_object_cb_t) (const jerry_value_t object, void *user_data_p); + +/** + * Function type applied for each matching object in the engine. + */ +typedef bool (*jerry_foreach_live_object_with_info_cb_t) (const jerry_value_t object, + void *object_data_p, + void *user_data_p); + +/** + * User context item manager + */ +typedef struct +{ + /** + * Callback responsible for initializing a context item, or NULL to zero out the memory. This is called lazily, the + * first time jerry_context_data () is called with this manager. + * + * @param [in] data The buffer that JerryScript allocated for the manager. The buffer is zeroed out. The size is + * determined by the bytes_needed field. The buffer is kept alive until jerry_cleanup () is called. + */ + void (*init_cb) (void *data); + + /** + * Callback responsible for deinitializing a context item, or NULL. This is called as part of jerry_cleanup (), + * right *before* the VM has been cleaned up. This is a good place to release strong references to jerry_value_t's + * that the manager may be holding. + * Note: because the VM has not been fully cleaned up yet, jerry_object_native_info_t free_cb's can still get called + * *after* all deinit_cb's have been run. See finalize_cb for a callback that is guaranteed to run *after* all + * free_cb's have been run. + * + * @param [in] data The buffer that JerryScript allocated for the manager. + */ + void (*deinit_cb) (void *data); + + /** + * Callback responsible for finalizing a context item, or NULL. This is called as part of jerry_cleanup (), + * right *after* the VM has been cleaned up and destroyed and jerry_... APIs cannot be called anymore. At this point, + * all values in the VM have been cleaned up. This is a good place to clean up native state that can only be cleaned + * up at the very end when there are no more VM values around that may need to access that state. + * + * @param [in] data The buffer that JerryScript allocated for the manager. After returning from this callback, + * the data pointer may no longer be used. + */ + void (*finalize_cb) (void *data); + + /** + * Number of bytes to allocate for this manager. This is the size of the buffer that JerryScript will allocate on + * behalf of the manager. The pointer to this buffer is passed into init_cb, deinit_cb and finalize_cb. It is also + * returned from the jerry_context_data () API. + */ + size_t bytes_needed; +} jerry_context_data_manager_t; + +/** + * Function type for allocating buffer for JerryScript context. + */ +typedef void *(*jerry_context_alloc_cb_t) (size_t size, void *cb_data_p); + +/** + * Type information of a native pointer. + */ +typedef struct jerry_object_native_info_t +{ + jerry_object_native_free_cb_t free_cb; /**< the free callback of the native pointer */ + uint16_t number_of_references; /**< the number of value references which are marked by the garbage collector */ + uint16_t offset_of_references; /**< byte offset indicating the start offset of value + * references in the user allocated buffer */ +} jerry_object_native_info_t; + +/** + * An opaque declaration of the JerryScript context structure. + */ +typedef struct jerry_context_t jerry_context_t; + +/** + * Enum that contains the supported binary operation types + */ +typedef enum +{ + JERRY_BIN_OP_EQUAL = 0u, /**< equal comparison (==) */ + JERRY_BIN_OP_STRICT_EQUAL, /**< strict equal comparison (===) */ + JERRY_BIN_OP_LESS, /**< less relation (<) */ + JERRY_BIN_OP_LESS_EQUAL, /**< less or equal relation (<=) */ + JERRY_BIN_OP_GREATER, /**< greater relation (>) */ + JERRY_BIN_OP_GREATER_EQUAL, /**< greater or equal relation (>=)*/ + JERRY_BIN_OP_INSTANCEOF, /**< instanceof operation */ + JERRY_BIN_OP_ADD, /**< addition operator (+) */ + JERRY_BIN_OP_SUB, /**< subtraction operator (-) */ + JERRY_BIN_OP_MUL, /**< multiplication operator (*) */ + JERRY_BIN_OP_DIV, /**< division operator (/) */ + JERRY_BIN_OP_REM, /**< remainder operator (%) */ +} jerry_binary_op_t; + +/** + * Backtrace related types. + */ + +/** + * List of backtrace frame types returned by jerry_frame_type. + */ +typedef enum +{ + JERRY_BACKTRACE_FRAME_JS, /**< indicates that the frame is created for a JavaScript function/method */ +} jerry_frame_type_t; + +/** + * Location info retrieved by jerry_frame_location. + */ +typedef struct +{ + jerry_value_t source_name; /**< source name */ + jerry_size_t line; /**< line index */ + jerry_size_t column; /**< column index */ +} jerry_frame_location_t; + +/* + * Internal data structure for jerry_frame_t definition. + */ +struct jerry_frame_internal_t; + +/** + * Backtrace frame data passed to the jerry_backtrace_cb_t handler. + */ +typedef struct jerry_frame_internal_t jerry_frame_t; + +/** + * Callback function which is called by jerry_backtrace for each stack frame. + */ +typedef bool (*jerry_backtrace_cb_t) (jerry_frame_t *frame_p, void *user_p); + +/** + * Detailed value type related types. + */ + +/** + * JerryScript API value type information. + */ +typedef enum +{ + JERRY_TYPE_NONE = 0u, /**< no type information */ + JERRY_TYPE_UNDEFINED, /**< undefined type */ + JERRY_TYPE_NULL, /**< null type */ + JERRY_TYPE_BOOLEAN, /**< boolean type */ + JERRY_TYPE_NUMBER, /**< number type */ + JERRY_TYPE_STRING, /**< string type */ + JERRY_TYPE_OBJECT, /**< object type */ + JERRY_TYPE_FUNCTION, /**< function type */ + JERRY_TYPE_EXCEPTION, /**< exception/abort type */ + JERRY_TYPE_SYMBOL, /**< symbol type */ + JERRY_TYPE_BIGINT, /**< bigint type */ +} jerry_type_t; + +/** + * JerryScript object type information. + */ +typedef enum +{ + JERRY_OBJECT_TYPE_NONE = 0u, /**< Non object type */ + JERRY_OBJECT_TYPE_GENERIC, /**< Generic JavaScript object without any internal property */ + JERRY_OBJECT_TYPE_MODULE_NAMESPACE, /**< Namespace object */ + JERRY_OBJECT_TYPE_ARRAY, /**< Array object */ + JERRY_OBJECT_TYPE_PROXY, /**< Proxy object */ + JERRY_OBJECT_TYPE_SCRIPT, /**< Script object (see jerry_parse) */ + JERRY_OBJECT_TYPE_MODULE, /**< Module object (see jerry_parse) */ + JERRY_OBJECT_TYPE_PROMISE, /**< Promise object */ + JERRY_OBJECT_TYPE_DATAVIEW, /**< Dataview object */ + JERRY_OBJECT_TYPE_FUNCTION, /**< Function object (see jerry_function_type) */ + JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_typedarray_type) */ + JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_type) */ + JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */ + JERRY_OBJECT_TYPE_ERROR, /**< Error object */ + JERRY_OBJECT_TYPE_ARRAYBUFFER, /**< Array buffer object */ + JERRY_OBJECT_TYPE_SHARED_ARRAY_BUFFER, /**< Shared Array Buffer object */ + + JERRY_OBJECT_TYPE_ARGUMENTS, /**< Arguments object */ + JERRY_OBJECT_TYPE_BOOLEAN, /**< Boolean object */ + JERRY_OBJECT_TYPE_DATE, /**< Date object */ + JERRY_OBJECT_TYPE_NUMBER, /**< Number object */ + JERRY_OBJECT_TYPE_REGEXP, /**< RegExp object */ + JERRY_OBJECT_TYPE_STRING, /**< String object */ + JERRY_OBJECT_TYPE_SYMBOL, /**< Symbol object */ + JERRY_OBJECT_TYPE_GENERATOR, /**< Generator object */ + JERRY_OBJECT_TYPE_BIGINT, /**< BigInt object */ + JERRY_OBJECT_TYPE_WEAKREF, /**< WeakRef object */ +} jerry_object_type_t; + +/** + * JerryScript function object type information. + */ +typedef enum +{ + JERRY_FUNCTION_TYPE_NONE = 0u, /**< Non function type */ + JERRY_FUNCTION_TYPE_GENERIC, /**< Generic JavaScript function */ + JERRY_FUNCTION_TYPE_ACCESSOR, /**< Accessor function */ + JERRY_FUNCTION_TYPE_BOUND, /**< Bound function */ + JERRY_FUNCTION_TYPE_ARROW, /**< Arrow function */ + JERRY_FUNCTION_TYPE_GENERATOR, /**< Generator function */ +} jerry_function_type_t; + +/** + * JerryScript iterator object type information. + */ +typedef enum +{ + JERRY_ITERATOR_TYPE_NONE = 0u, /**< Non iterator type */ + JERRY_ITERATOR_TYPE_ARRAY, /**< Array iterator */ + JERRY_ITERATOR_TYPE_STRING, /**< String iterator */ + JERRY_ITERATOR_TYPE_MAP, /**< Map iterator */ + JERRY_ITERATOR_TYPE_SET, /**< Set iterator */ +} jerry_iterator_type_t; + +/** + * Module related types. + */ + +/** + * An enum representing the current status of a module + */ +typedef enum +{ + JERRY_MODULE_STATE_INVALID = 0, /**< return value for jerry_module_state when its argument is not a module */ + JERRY_MODULE_STATE_UNLINKED = 1, /**< module is currently unlinked */ + JERRY_MODULE_STATE_LINKING = 2, /**< module is currently being linked */ + JERRY_MODULE_STATE_LINKED = 3, /**< module has been linked (its dependencies has been resolved) */ + JERRY_MODULE_STATE_EVALUATING = 4, /**< module is currently being evaluated */ + JERRY_MODULE_STATE_EVALUATED = 5, /**< module has been evaluated (its source code has been executed) */ + JERRY_MODULE_STATE_ERROR = 6, /**< an error has been encountered before the evaluated state is reached */ +} jerry_module_state_t; + +/** + * Callback which is called by jerry_module_link to get the referenced module. + */ +typedef jerry_value_t (*jerry_module_resolve_cb_t) (const jerry_value_t specifier, + const jerry_value_t referrer, + void *user_p); + +/** + * Callback which is called when an import is resolved dynamically to get the referenced module. + */ +typedef jerry_value_t (*jerry_module_import_cb_t) (const jerry_value_t specifier, + const jerry_value_t user_value, + void *user_p); + +/** + * Callback which is called after the module enters into linked, evaluated or error state. + */ +typedef void (*jerry_module_state_changed_cb_t) (jerry_module_state_t new_state, + const jerry_value_t module, + const jerry_value_t value, + void *user_p); + +/** + * Callback which is called when an import.meta expression of a module is evaluated the first time. + */ +typedef void (*jerry_module_import_meta_cb_t) (const jerry_value_t module, + const jerry_value_t meta_object, + void *user_p); + +/** + * Callback which is called by jerry_module_evaluate to evaluate the native module. + */ +typedef jerry_value_t (*jerry_native_module_evaluate_cb_t) (const jerry_value_t native_module); + +/** + * Proxy related types. + */ + +/** + * JerryScript special Proxy object options. + */ +typedef enum +{ + JERRY_PROXY_SKIP_RESULT_VALIDATION = (1u << 0), /**< skip result validation for [[GetPrototypeOf]], + * [[SetPrototypeOf]], [[IsExtensible]], + * [[PreventExtensions]], [[GetOwnProperty]], + * [[DefineOwnProperty]], [[HasProperty]], [[Get]], + * [[Set]], [[Delete]] and [[OwnPropertyKeys]] */ +} jerry_proxy_custom_behavior_t; + +/** + * Promise related types. + */ + +/** + * Enum values representing various Promise states. + */ +typedef enum +{ + JERRY_PROMISE_STATE_NONE = 0u, /**< Invalid/Unknown state (possibly called on a non-promise object). */ + JERRY_PROMISE_STATE_PENDING, /**< Promise is in "Pending" state. */ + JERRY_PROMISE_STATE_FULFILLED, /**< Promise is in "Fulfilled" state. */ + JERRY_PROMISE_STATE_REJECTED, /**< Promise is in "Rejected" state. */ +} jerry_promise_state_t; + +/** + * Event types for jerry_promise_event_cb_t callback function. + * The description of the 'object' and 'value' arguments are provided for each type. + */ +typedef enum +{ + JERRY_PROMISE_EVENT_CREATE = 0u, /**< a new Promise object is created + * object: the new Promise object + * value: parent Promise for `then` chains, undefined otherwise */ + JERRY_PROMISE_EVENT_RESOLVE, /**< called when a Promise is about to be resolved + * object: the Promise object + * value: value for resolving */ + JERRY_PROMISE_EVENT_REJECT, /**< called when a Promise is about to be rejected + * object: the Promise object + * value: value for rejecting */ + JERRY_PROMISE_EVENT_RESOLVE_FULFILLED, /**< called when a resolve is called on a fulfilled Promise + * object: the Promise object + * value: value for resolving */ + JERRY_PROMISE_EVENT_REJECT_FULFILLED, /**< called when a reject is called on a fulfilled Promise + * object: the Promise object + * value: value for rejecting */ + JERRY_PROMISE_EVENT_REJECT_WITHOUT_HANDLER, /**< called when a Promise is rejected without a handler + * object: the Promise object + * value: value for rejecting */ + JERRY_PROMISE_EVENT_CATCH_HANDLER_ADDED, /**< called when a catch handler is added to a rejected + * Promise which did not have a catch handler before + * object: the Promise object + * value: undefined */ + JERRY_PROMISE_EVENT_BEFORE_REACTION_JOB, /**< called before executing a Promise reaction job + * object: the Promise object + * value: undefined */ + JERRY_PROMISE_EVENT_AFTER_REACTION_JOB, /**< called after a Promise reaction job is completed + * object: the Promise object + * value: undefined */ + JERRY_PROMISE_EVENT_ASYNC_AWAIT, /**< called when an async function awaits the result of a Promise object + * object: internal object representing the execution status + * value: the Promise object */ + JERRY_PROMISE_EVENT_ASYNC_BEFORE_RESOLVE, /**< called when an async function is continued with resolve + * object: internal object representing the execution status + * value: value for resolving */ + JERRY_PROMISE_EVENT_ASYNC_BEFORE_REJECT, /**< called when an async function is continued with reject + * object: internal object representing the execution status + * value: value for rejecting */ + JERRY_PROMISE_EVENT_ASYNC_AFTER_RESOLVE, /**< called when an async function resolve is completed + * object: internal object representing the execution status + * value: value for resolving */ + JERRY_PROMISE_EVENT_ASYNC_AFTER_REJECT, /**< called when an async function reject is completed + * object: internal object representing the execution status + * value: value for rejecting */ +} jerry_promise_event_type_t; + +/** + * Filter types for jerry_promise_on_event callback function. + * The callback is only called for those events which are enabled by the filters. + */ +typedef enum +{ + JERRY_PROMISE_EVENT_FILTER_DISABLE = 0, /**< disable reporting of all events */ + JERRY_PROMISE_EVENT_FILTER_CREATE = (1 << 0), /**< enables the following event: + * JERRY_PROMISE_EVENT_CREATE */ + JERRY_PROMISE_EVENT_FILTER_RESOLVE = (1 << 1), /**< enables the following event: + * JERRY_PROMISE_EVENT_RESOLVE */ + JERRY_PROMISE_EVENT_FILTER_REJECT = (1 << 2), /**< enables the following event: + * JERRY_PROMISE_EVENT_REJECT */ + JERRY_PROMISE_EVENT_FILTER_ERROR = (1 << 3), /**< enables the following events: + * JERRY_PROMISE_EVENT_RESOLVE_FULFILLED + * JERRY_PROMISE_EVENT_REJECT_FULFILLED + * JERRY_PROMISE_EVENT_REJECT_WITHOUT_HANDLER + * JERRY_PROMISE_EVENT_CATCH_HANDLER_ADDED */ + JERRY_PROMISE_EVENT_FILTER_REACTION_JOB = (1 << 4), /**< enables the following events: + * JERRY_PROMISE_EVENT_BEFORE_REACTION_JOB + * JERRY_PROMISE_EVENT_AFTER_REACTION_JOB */ + JERRY_PROMISE_EVENT_FILTER_ASYNC_MAIN = (1 << 5), /**< enables the following event: + * JERRY_PROMISE_EVENT_ASYNC_AWAIT */ + JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB = (1 << 6), /**< enables the following events: + * JERRY_PROMISE_EVENT_ASYNC_BEFORE_RESOLVE + * JERRY_PROMISE_EVENT_ASYNC_BEFORE_REJECT + * JERRY_PROMISE_EVENT_ASYNC_AFTER_RESOLVE + * JERRY_PROMISE_EVENT_ASYNC_AFTER_REJECT */ +} jerry_promise_event_filter_t; + +/** + * Notification callback for tracking Promise and async function operations. + */ +typedef void (*jerry_promise_event_cb_t) (jerry_promise_event_type_t event_type, + const jerry_value_t object, + const jerry_value_t value, + void *user_p); + +/** + * Symbol related types. + */ + +/** + * List of well-known symbols. + */ +typedef enum +{ + JERRY_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well-known symbol */ + JERRY_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well-known symbol */ + JERRY_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well-known symbol */ + JERRY_SYMBOL_ITERATOR, /**< @@iterator well-known symbol */ + JERRY_SYMBOL_MATCH, /**< @@match well-known symbol */ + JERRY_SYMBOL_REPLACE, /**< @@replace well-known symbol */ + JERRY_SYMBOL_SEARCH, /**< @@search well-known symbol */ + JERRY_SYMBOL_SPECIES, /**< @@species well-known symbol */ + JERRY_SYMBOL_SPLIT, /**< @@split well-known symbol */ + JERRY_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well-known symbol */ + JERRY_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well-known symbol */ + JERRY_SYMBOL_UNSCOPABLES, /**< @@unscopables well-known symbol */ + JERRY_SYMBOL_MATCH_ALL, /**< @@matchAll well-known symbol */ +} jerry_well_known_symbol_t; + +/** + * TypedArray related types. + */ + +/** + * TypedArray types. + */ +typedef enum +{ + JERRY_TYPEDARRAY_INVALID = 0, + JERRY_TYPEDARRAY_UINT8, + JERRY_TYPEDARRAY_UINT8CLAMPED, + JERRY_TYPEDARRAY_INT8, + JERRY_TYPEDARRAY_UINT16, + JERRY_TYPEDARRAY_INT16, + JERRY_TYPEDARRAY_UINT32, + JERRY_TYPEDARRAY_INT32, + JERRY_TYPEDARRAY_FLOAT32, + JERRY_TYPEDARRAY_FLOAT64, + JERRY_TYPEDARRAY_BIGINT64, + JERRY_TYPEDARRAY_BIGUINT64, +} jerry_typedarray_type_t; + +/** + * Container types. + */ +typedef enum +{ + JERRY_CONTAINER_TYPE_INVALID = 0, /**< Invalid container */ + JERRY_CONTAINER_TYPE_MAP, /**< Map type */ + JERRY_CONTAINER_TYPE_SET, /**< Set type */ + JERRY_CONTAINER_TYPE_WEAKMAP, /**< WeakMap type */ + JERRY_CONTAINER_TYPE_WEAKSET, /**< WeakSet type */ +} jerry_container_type_t; + +/** + * Container operations + */ +typedef enum +{ + JERRY_CONTAINER_OP_ADD, /**< Set/WeakSet add operation */ + JERRY_CONTAINER_OP_GET, /**< Map/WeakMap get operation */ + JERRY_CONTAINER_OP_SET, /**< Map/WeakMap set operation */ + JERRY_CONTAINER_OP_HAS, /**< Set/WeakSet/Map/WeakMap has operation */ + JERRY_CONTAINER_OP_DELETE, /**< Set/WeakSet/Map/WeakMap delete operation */ + JERRY_CONTAINER_OP_SIZE, /**< Set/WeakSet/Map/WeakMap size operation */ + JERRY_CONTAINER_OP_CLEAR, /**< Set/Map clear operation */ +} jerry_container_op_t; + +/** + * Miscellaneous types. + */ + +/** + * Enabled fields of jerry_source_info_t. + */ +typedef enum +{ + JERRY_SOURCE_INFO_HAS_SOURCE_CODE = (1 << 0), /**< source_code field is valid */ + JERRY_SOURCE_INFO_HAS_FUNCTION_ARGUMENTS = (1 << 1), /**< function_arguments field is valid */ + JERRY_SOURCE_INFO_HAS_SOURCE_RANGE = (1 << 2), /**< both source_range_start and source_range_length + * fields are valid */ +} jerry_source_info_enabled_fields_t; + +/** + * Source related information of a script/module/function. + */ +typedef struct +{ + uint32_t enabled_fields; /**< combination of jerry_source_info_enabled_fields_t values */ + jerry_value_t source_code; /**< script source code or function body */ + jerry_value_t function_arguments; /**< function arguments */ + uint32_t source_range_start; /**< start position of the function in the source code */ + uint32_t source_range_length; /**< source length of the function in the source code */ +} jerry_source_info_t; + +/** + * Array buffer types. + */ + +/** + * Type of an array buffer. + */ +typedef enum +{ + JERRY_ARRAYBUFFER_TYPE_ARRAYBUFFER, /**< the object is an array buffer object */ + JERRY_ARRAYBUFFER_TYPE_SHARED_ARRAYBUFFER, /**< the object is a shared array buffer object */ +} jerry_arraybuffer_type_t; + +/** + * Callback for allocating the backing store of array buffer or shared array buffer objects. + */ +typedef uint8_t *(*jerry_arraybuffer_allocate_cb_t) (jerry_arraybuffer_type_t buffer_type, + uint32_t buffer_size, + void **arraybuffer_user_p, + void *user_p); + +/** + * Callback for freeing the backing store of array buffer or shared array buffer objects. + */ +typedef void (*jerry_arraybuffer_free_cb_t) (jerry_arraybuffer_type_t buffer_type, + uint8_t *buffer_p, + uint32_t buffer_size, + void *arraybuffer_user_p, + void *user_p); + +/** + * @} + */ + +JERRY_C_API_END + +#endif /* !JERRYSCRIPT_TYPES_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript.h new file mode 100644 index 0000000..5a38ad0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript.h @@ -0,0 +1,36 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JERRYSCRIPT_H +#define JERRYSCRIPT_H + +/** + * Major version of JerryScript API. + */ +#define JERRY_API_MAJOR_VERSION 3 + +/** + * Minor version of JerryScript API. + */ +#define JERRY_API_MINOR_VERSION 0 + +/** + * Patch version of JerryScript API. + */ +#define JERRY_API_PATCH_VERSION 0 + +#include "jerryscript-core.h" + +#endif /* !JERRYSCRIPT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/meson.build new file mode 100644 index 0000000..36caaca --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/include/meson.build @@ -0,0 +1,13 @@ +source_file = [ + 'jerry-config.h', + 'jerryscript-compiler.h', + 'jerryscript-core.h', + 'jerryscript-port.h', + 'jerryscript-types.h', + 'jerryscript.h' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/jcontext.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/jcontext.cpp new file mode 100644 index 0000000..7a7a429 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/jcontext.cpp @@ -0,0 +1,156 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jcontext.h" + +/** \addtogroup context Context + * @{ + */ + +/** + * Check the existence of the ECMA_STATUS_EXCEPTION flag. + * + * @return true - if the flag is set + * false - otherwise + */ +bool +jcontext_has_pending_exception (void) +{ + return JERRY_CONTEXT (status_flags) & ECMA_STATUS_EXCEPTION; +} /* jcontext_has_pending_exception */ + +/** + * Check the existence of the ECMA_STATUS_ABORT flag. + * + * @return true - if the flag is set + * false - otherwise + */ +bool +jcontext_has_pending_abort (void) +{ + return JERRY_CONTEXT (status_flags) & ECMA_STATUS_ABORT; +} /* jcontext_has_pending_abort */ + +/** + * Set the abort flag for the context. + * + * @return void + */ +void +jcontext_set_abort_flag (bool is_abort) /**< true - if the abort flag should be set + * false - if the abort flag should be removed */ +{ + JERRY_ASSERT (jcontext_has_pending_exception ()); + + if (is_abort) + { + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_ABORT; + } + else + { + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_ABORT; + } +} /* jcontext_set_abort_flag */ + +/** + * Set the exception flag for the context. + * + * @return void + */ +void +jcontext_set_exception_flag (bool is_exception) /**< true - if the exception flag should be set + * false - if the exception flag should be removed */ +{ + if (is_exception) + { + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION; + } + else + { + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_EXCEPTION; + } +} /* jcontext_set_exception_flag */ + +/** + * Raise exception from the given error value. + * + * @return void + */ +void +jcontext_raise_exception (ecma_value_t error) /**< error to raise */ +{ + JERRY_ASSERT (!jcontext_has_pending_exception ()); + JERRY_ASSERT (!jcontext_has_pending_abort ()); + + JERRY_CONTEXT (error_value) = error; + jcontext_set_exception_flag (true); +} /* jcontext_raise_exception */ + +/** + * Release the current exception/abort of the context. + */ +void +jcontext_release_exception (void) +{ + JERRY_ASSERT (jcontext_has_pending_exception ()); + + ecma_free_value (jcontext_take_exception ()); +} /* jcontext_release_exception */ + +/** + * Take the current exception/abort of context. + * + * @return current exception as an ecma-value + */ +ecma_value_t +jcontext_take_exception (void) +{ + JERRY_ASSERT (jcontext_has_pending_exception ()); + + JERRY_CONTEXT (status_flags) &= (uint32_t) ~(ECMA_STATUS_EXCEPTION +#if JERRY_VM_THROW + | ECMA_STATUS_ERROR_THROWN +#endif /* JERRY_VM_THROW */ + | ECMA_STATUS_ABORT); + return JERRY_CONTEXT (error_value); +} /* jcontext_take_exception */ + +#if !JERRY_EXTERNAL_CONTEXT + +/** + * Global context. + */ +jerry_context_t jerry_global_context; + +#if !JERRY_SYSTEM_ALLOCATOR + +/** + * Check size of heap is corresponding to configuration + */ +JERRY_STATIC_ASSERT ((sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE), + size_of_mem_heap_must_be_less_than_or_equal_to_JMEM_HEAP_SIZE); + +/** + * Global heap. + */ +jmem_heap_t jerry_global_heap JERRY_ATTR_ALIGNED (JMEM_ALIGNMENT) JERRY_ATTR_GLOBAL_HEAP; + +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + +#endif /* !JERRY_EXTERNAL_CONTEXT */ + +/** + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/jcontext.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/jcontext.h new file mode 100644 index 0000000..7594e98 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/jcontext.h @@ -0,0 +1,314 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Engine context for JerryScript + */ +#ifndef JCONTEXT_H +#define JCONTEXT_H + +#include "ecma-builtins.h" +#include "ecma-helpers.h" +#include "ecma-jobqueue.h" + +#include "jmem.h" +#include "js-parser-internal.h" +#include "re-bytecode.h" +#include "vm-defines.h" + +/** \addtogroup context Context + * @{ + */ + +/** + * Advanced allocator configurations. + */ +/** + * Maximum global heap size in bytes + */ +#define CONFIG_MEM_HEAP_SIZE (JERRY_GLOBAL_HEAP_SIZE * 1024) + +/** + * Maximum stack usage size in bytes + */ +#define CONFIG_MEM_STACK_LIMIT (JERRY_STACK_LIMIT * 1024) + +/** + * Max heap usage limit + */ +#define CONFIG_MAX_GC_LIMIT 8192 + +/** + * Allowed heap usage limit until next garbage collection + * + * Whenever the total allocated memory size reaches the current heap limit, garbage collection will be triggered + * to try and reduce clutter from unreachable objects. If the allocated memory can't be reduced below the limit, + * then the current limit will be incremented by CONFIG_MEM_HEAP_LIMIT. + */ +#if defined(JERRY_GC_LIMIT) && (JERRY_GC_LIMIT != 0) +#define CONFIG_GC_LIMIT JERRY_GC_LIMIT +#else /* !(defined(JERRY_GC_LIMIT) && (JERRY_GC_LIMIT != 0)) */ +#define CONFIG_GC_LIMIT (JERRY_MIN (CONFIG_MEM_HEAP_SIZE / 32, CONFIG_MAX_GC_LIMIT)) +#endif /* defined(JERRY_GC_LIMIT) && (JERRY_GC_LIMIT != 0) */ + +/** + * Amount of newly allocated objects since the last GC run, represented as a fraction of all allocated objects, + * which when reached will trigger garbage collection to run with a low pressure setting. + * + * The fraction is calculated as: + * 1.0 / CONFIG_ECMA_GC_NEW_OBJECTS_FRACTION + */ +#define CONFIG_ECMA_GC_NEW_OBJECTS_FRACTION (16) + +#if !JERRY_SYSTEM_ALLOCATOR +/** + * Heap structure + * + * Memory blocks returned by the allocator must not start from the + * beginning of the heap area because offset 0 is reserved for + * JMEM_CP_NULL. This special constant is used in several places, + * e.g. it marks the end of the property chain list, so it cannot + * be eliminated from the project. Although the allocator cannot + * use the first 8 bytes of the heap, nothing prevents to use it + * for other purposes. Currently the free region start is stored + * there. + */ +typedef struct jmem_heap_t jmem_heap_t; +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + +/** + * User context item + */ +typedef struct jerry_context_data_header +{ + struct jerry_context_data_header *next_p; /**< pointer to next context item */ + const jerry_context_data_manager_t *manager_p; /**< manager responsible for deleting this item */ +} jerry_context_data_header_t; + +#define JERRY_CONTEXT_DATA_HEADER_USER_DATA(item_p) ((uint8_t *) (item_p + 1)) + +/** + * JerryScript context + * + * The purpose of this header is storing + * all global variables for Jerry + */ +struct jerry_context_t +{ + /* The value of external context members must be preserved across initializations and cleanups. */ +#if JERRY_EXTERNAL_CONTEXT +#if !JERRY_SYSTEM_ALLOCATOR + jmem_heap_t *heap_p; /**< point to the heap aligned to JMEM_ALIGNMENT. */ + uint32_t heap_size; /**< size of the heap */ +#endif /* !JERRY_SYSTEM_ALLOCATOR */ +#endif /* JERRY_EXTERNAL_CONTEXT */ + + ecma_global_object_t *global_object_p; /**< current global object */ + jmem_heap_free_t *jmem_heap_list_skip_p; /**< improves deallocation performance */ + jmem_pools_chunk_t *jmem_free_8_byte_chunk_p; /**< list of free eight byte pool chunks */ +#if JERRY_BUILTIN_REGEXP + re_compiled_code_t *re_cache[RE_CACHE_SIZE]; /**< regex cache */ +#endif /* JERRY_BUILTIN_REGEXP */ + const lit_utf8_byte_t *const *lit_magic_string_ex_array; /**< array of external magic strings */ + const lit_utf8_size_t *lit_magic_string_ex_sizes; /**< external magic string lengths */ + jmem_cpointer_t ecma_gc_objects_cp; /**< List of currently alive objects. */ + jmem_cpointer_t string_list_first_cp; /**< first item of the literal string list */ + jmem_cpointer_t symbol_list_first_cp; /**< first item of the global symbol list */ + jmem_cpointer_t number_list_first_cp; /**< first item of the literal number list */ +#if JERRY_BUILTIN_BIGINT + jmem_cpointer_t bigint_list_first_cp; /**< first item of the literal bigint list */ +#endif /* JERRY_BUILTIN_BIGINT */ + jmem_cpointer_t global_symbols_cp[ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT]; /**< global symbols */ + +#if JERRY_MODULE_SYSTEM + ecma_module_t *module_current_p; /**< current module context */ + jerry_module_state_changed_cb_t module_state_changed_callback_p; /**< callback which is called after the + * state of a module is changed */ + void *module_state_changed_callback_user_p; /**< user pointer for module_state_changed_callback_p */ + jerry_module_import_meta_cb_t module_import_meta_callback_p; /**< callback which is called when an + * import.meta expression of a module + * is evaluated the first time */ + void *module_import_meta_callback_user_p; /**< user pointer for module_import_meta_callback_p */ + jerry_module_import_cb_t module_import_callback_p; /**< callback for dynamic module import */ + void *module_import_callback_user_p; /**< user pointer for module_import_callback_p */ +#endif /* JERRY_MODULE_SYSTEM */ + + vm_frame_ctx_t *vm_top_context_p; /**< top (current) interpreter context */ + jerry_context_data_header_t *context_data_p; /**< linked list of user-provided context-specific pointers */ + jerry_external_string_free_cb_t external_string_free_callback_p; /**< free callback for external strings */ + void *error_object_created_callback_user_p; /**< user pointer for error_object_update_callback_p */ + jerry_error_object_created_cb_t error_object_created_callback_p; /**< decorator callback for Error objects */ + size_t ecma_gc_objects_number; /**< number of currently allocated objects */ + size_t ecma_gc_new_objects; /**< number of newly allocated objects since last GC session */ + size_t jmem_heap_allocated_size; /**< size of allocated regions */ + size_t jmem_heap_limit; /**< current limit of heap usage, that is upon being reached, + * causes call of "try give memory back" callbacks */ + ecma_value_t error_value; /**< currently thrown error value */ + uint32_t lit_magic_string_ex_count; /**< external magic strings count */ + uint32_t jerry_init_flags; /**< run-time configuration flags */ + uint32_t status_flags; /**< run-time flags (the top 8 bits are used for passing class parsing options) */ + +#if (JERRY_GC_MARK_LIMIT != 0) + uint32_t ecma_gc_mark_recursion_limit; /**< GC mark recursion limit */ +#endif /* (JERRY_GC_MARK_LIMIT != 0) */ + +#if JERRY_PROPERTY_HASHMAP + uint8_t ecma_prop_hashmap_alloc_state; /**< property hashmap allocation state: 0-4, + * if !0 property hashmap allocation is disabled */ +#endif /* JERRY_PROPERTY_HASHMAP */ + +#if JERRY_BUILTIN_REGEXP + uint8_t re_cache_idx; /**< evicted item index when regex cache is full (round-robin) */ +#endif /* JERRY_BUILTIN_REGEXP */ + ecma_job_queue_item_t *job_queue_head_p; /**< points to the head item of the job queue */ + ecma_job_queue_item_t *job_queue_tail_p; /**< points to the tail item of the job queue */ + +#if JERRY_BUILTIN_TYPEDARRAY + uint32_t arraybuffer_compact_allocation_limit; /**< maximum size of compact allocation */ + jerry_arraybuffer_allocate_cb_t arraybuffer_allocate_callback; /**< callback for allocating + * arraybuffer memory */ + jerry_arraybuffer_free_cb_t arraybuffer_free_callback; /**< callback for freeing arraybuffer memory */ + void *arraybuffer_allocate_callback_user_p; /**< user pointer passed to arraybuffer_allocate_callback + * and arraybuffer_free_callback functions */ +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + +#if JERRY_VM_HALT + uint32_t vm_exec_stop_frequency; /**< reset value for vm_exec_stop_counter */ + uint32_t vm_exec_stop_counter; /**< down counter for reducing the calls of vm_exec_stop_cb */ + void *vm_exec_stop_user_p; /**< user pointer for vm_exec_stop_cb */ + ecma_vm_exec_stop_callback_t vm_exec_stop_cb; /**< user function which returns whether the + * ECMAScript execution should be stopped */ +#endif /* JERRY_VM_HALT */ + +#if JERRY_VM_THROW + void *vm_throw_callback_user_p; /**< user pointer for vm_throw_callback_p */ + jerry_throw_cb_t vm_throw_callback_p; /**< callback for capturing throws */ +#endif /* JERRY_VM_THROW */ + +#if (JERRY_STACK_LIMIT != 0) + uintptr_t stack_base; /**< stack base marker */ +#endif /* (JERRY_STACK_LIMIT != 0) */ + + /* This must be at the end of the context for performance reasons */ +#if JERRY_LCACHE + /** hash table for caching the last access of properties */ + ecma_lcache_hash_entry_t lcache[ECMA_LCACHE_HASH_ROWS_COUNT][ECMA_LCACHE_HASH_ROW_LENGTH]; +#endif /* JERRY_LCACHE */ + + /** + * Allowed values and it's meaning: + * * NULL (0x0): the current "new.target" is undefined, that is the execution is inside a normal method. + * * Any other valid function object pointer: the current "new.target" is valid and it is constructor call. + */ + ecma_object_t *current_new_target_p; +}; + +#if JERRY_EXTERNAL_CONTEXT + +/* + * This part is for JerryScript which uses external context. + */ + +#define JERRY_CONTEXT_STRUCT (*jerry_port_context_get ()) +#define JERRY_CONTEXT(field) (jerry_port_context_get ()->field) + +#if !JERRY_SYSTEM_ALLOCATOR + +#define JMEM_HEAP_SIZE (JERRY_CONTEXT (heap_size)) + +#define JMEM_HEAP_AREA_SIZE (JMEM_HEAP_SIZE - JMEM_ALIGNMENT) + +struct jmem_heap_t +{ + jmem_heap_free_t first; /**< first node in free region list */ + uint8_t area[]; /**< heap area */ +}; + +#define JERRY_HEAP_CONTEXT(field) (JERRY_CONTEXT (heap_p)->field) + +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + +#else /* !JERRY_EXTERNAL_CONTEXT */ + +/* + * This part is for JerryScript which uses default context. + */ + +/** + * Global context. + */ +extern jerry_context_t jerry_global_context; + +/** + * Config-independent name for context. + */ +#define JERRY_CONTEXT_STRUCT (jerry_global_context) + +/** + * Provides a reference to a field in the current context. + */ +#define JERRY_CONTEXT(field) (jerry_global_context.field) + +#if !JERRY_SYSTEM_ALLOCATOR + +/** + * Size of heap + */ +#define JMEM_HEAP_SIZE ((size_t) (CONFIG_MEM_HEAP_SIZE)) + +/** + * Calculate heap area size, leaving space for a pointer to the free list + */ +#define JMEM_HEAP_AREA_SIZE (JMEM_HEAP_SIZE - JMEM_ALIGNMENT) + +struct jmem_heap_t +{ + jmem_heap_free_t first; /**< first node in free region list */ + uint8_t area[JMEM_HEAP_AREA_SIZE]; /**< heap area */ +}; + +/** + * Global heap. + */ +extern jmem_heap_t jerry_global_heap; + +/** + * Provides a reference to a field of the heap. + */ +#define JERRY_HEAP_CONTEXT(field) (jerry_global_heap.field) + +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + +#endif /* JERRY_EXTERNAL_CONTEXT */ + +void jcontext_set_exception_flag (bool is_exception); + +void jcontext_set_abort_flag (bool is_abort); + +bool jcontext_has_pending_exception (void); + +bool jcontext_has_pending_abort (void); + +void jcontext_raise_exception (ecma_value_t error); + +void jcontext_release_exception (void); + +ecma_value_t jcontext_take_exception (void); + +/** + * @} + */ + +#endif /* !JCONTEXT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/meson.build new file mode 100644 index 0000000..ca41b81 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jcontext/meson.build @@ -0,0 +1,9 @@ +source_file = [ + 'jcontext.h', + 'jcontext.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-allocator-internal.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-allocator-internal.h new file mode 100644 index 0000000..a88f8ba --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-allocator-internal.h @@ -0,0 +1,67 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JMEM_ALLOCATOR_INTERNAL_H +#define JMEM_ALLOCATOR_INTERNAL_H + +#ifndef JMEM_ALLOCATOR_INTERNAL +#error "The header is for internal routines of memory allocator component. Please, don't use the routines directly." +#endif /* !JMEM_ALLOCATOR_INTERNAL */ + +/** \addtogroup mem Memory allocation + * @{ + */ + +/** + * @{ + * Valgrind-related options and headers + */ +#define JMEM_VALGRIND_NOACCESS_SPACE(p, s) +#define JMEM_VALGRIND_UNDEFINED_SPACE(p, s) +#define JMEM_VALGRIND_DEFINED_SPACE(p, s) +#define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s) +#define JMEM_VALGRIND_RESIZE_SPACE(p, o, n) +#define JMEM_VALGRIND_FREELIKE_SPACE(p) +/** @} */ + +void jmem_heap_init (void); +void jmem_heap_finalize (void); +bool jmem_is_heap_pointer (const void *pointer); +void *jmem_heap_alloc_block_internal (const size_t size); +void jmem_heap_free_block_internal (void *ptr, const size_t size); + +/** + * \addtogroup poolman Memory pool manager + * @{ + */ + +void jmem_pools_finalize (void); + +/** + * @} + * @} + */ + +/** + * @{ + * Jerry mem-stat definitions + */ +#define JMEM_HEAP_STAT_INIT() +#define JMEM_HEAP_STAT_ALLOC(v1) JERRY_UNUSED (v1) +#define JMEM_HEAP_STAT_FREE(v1) JERRY_UNUSED (v1) + +/** @} */ + +#endif /* !JMEM_ALLOCATOR_INTERNAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-allocator.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-allocator.cpp new file mode 100644 index 0000000..e26871c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-allocator.cpp @@ -0,0 +1,95 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Allocator implementation + */ +#include "ecma-globals.h" + +#include "jcontext.h" +#include "jmem.h" +#include "jrt-libc-includes.h" + +#define JMEM_ALLOCATOR_INTERNAL +#include "jmem-allocator-internal.h" + +/** + * Initialize memory allocators. + */ +void +jmem_init (void) +{ + jmem_heap_init (); +} /* jmem_init */ + +/** + * Finalize memory allocators. + */ +void +jmem_finalize (void) +{ + jmem_pools_finalize (); + jmem_heap_finalize (); +} /* jmem_finalize */ + +/** + * Compress pointer + * + * @return packed pointer + */ +jmem_cpointer_t JERRY_ATTR_PURE +jmem_compress_pointer (const void *pointer_p) /**< pointer to compress */ +{ + JERRY_ASSERT (pointer_p != NULL); + JERRY_ASSERT (jmem_is_heap_pointer (pointer_p)); + + uintptr_t uint_ptr = (uintptr_t) pointer_p; + + JERRY_ASSERT (uint_ptr % JMEM_ALIGNMENT == 0); + + const uintptr_t heap_start = (uintptr_t) &JERRY_HEAP_CONTEXT (first); + + uint_ptr -= heap_start; + uint_ptr >>= JMEM_ALIGNMENT_LOG; + + JERRY_ASSERT (uint_ptr <= UINT16_MAX); + JERRY_ASSERT (uint_ptr != JMEM_CP_NULL); + + return (jmem_cpointer_t) uint_ptr; +} /* jmem_compress_pointer */ + +/** + * Decompress pointer + * + * @return unpacked pointer + */ +void *JERRY_ATTR_PURE +jmem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */ +{ + JERRY_ASSERT (compressed_pointer != JMEM_CP_NULL); + + uintptr_t uint_ptr = compressed_pointer; + + JERRY_ASSERT (((jmem_cpointer_t) uint_ptr) == uint_ptr); + + const uintptr_t heap_start = (uintptr_t) &JERRY_HEAP_CONTEXT (first); + + uint_ptr <<= JMEM_ALIGNMENT_LOG; + uint_ptr += heap_start; + + JERRY_ASSERT (jmem_is_heap_pointer ((void *) uint_ptr)); + + return (void *) uint_ptr; +} /* jmem_decompress_pointer */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-heap.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-heap.cpp new file mode 100644 index 0000000..d339086 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-heap.cpp @@ -0,0 +1,715 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Heap implementation + */ + +#include "ecma-gc.h" + +#include "jcontext.h" +#include "jmem.h" +#include "jrt-bit-fields.h" +#include "jrt-libc-includes.h" + +#define JMEM_ALLOCATOR_INTERNAL +#include "jmem-allocator-internal.h" + +/** \addtogroup mem Memory allocation + * @{ + * + * \addtogroup heap Heap + * @{ + */ + +#if !JERRY_SYSTEM_ALLOCATOR +/** + * End of list marker. + */ +#define JMEM_HEAP_END_OF_LIST ((uint32_t) 0xffffffff) + +/** + * @{ + */ +#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY +/* In this case we simply store the pointer, since it fits anyway. */ +#define JMEM_HEAP_GET_OFFSET_FROM_ADDR(p) ((uint32_t) (p)) +#define JMEM_HEAP_GET_ADDR_FROM_OFFSET(u) ((jmem_heap_free_t *) (u)) +#else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ +/** + * Get heap offset from address + */ +#define JMEM_HEAP_GET_OFFSET_FROM_ADDR(p) ((uint32_t) ((uint8_t *) (p) -JERRY_HEAP_CONTEXT (area))) + +/** + * Get heap address from offset + */ +#define JMEM_HEAP_GET_ADDR_FROM_OFFSET(u) ((jmem_heap_free_t *) (JERRY_HEAP_CONTEXT (area) + (u))) +#endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ +/** + * @} + */ + +/** + * Get end of region + * + * @return pointer to the end of the region + */ +static inline jmem_heap_free_t * JERRY_ATTR_PURE +jmem_heap_get_region_end (jmem_heap_free_t *curr_p) /**< current region */ +{ + return (jmem_heap_free_t *) ((uint8_t *) curr_p + curr_p->size); +} /* jmem_heap_get_region_end */ +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + +/** + * Startup initialization of heap + */ +void +jmem_heap_init (void) +{ +#if !JERRY_SYSTEM_ALLOCATOR + JERRY_ASSERT ((uintptr_t) JERRY_HEAP_CONTEXT (area) % JMEM_ALIGNMENT == 0); + + JERRY_CONTEXT (jmem_heap_limit) = CONFIG_GC_LIMIT; + + jmem_heap_free_t *const region_p = (jmem_heap_free_t *) JERRY_HEAP_CONTEXT (area); + + region_p->size = JMEM_HEAP_AREA_SIZE; + region_p->next_offset = JMEM_HEAP_END_OF_LIST; + + JERRY_HEAP_CONTEXT (first).size = 0; + JERRY_HEAP_CONTEXT (first).next_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (region_p); + + JERRY_CONTEXT (jmem_heap_list_skip_p) = &JERRY_HEAP_CONTEXT (first); + + JMEM_VALGRIND_NOACCESS_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_free_t)); + JMEM_VALGRIND_NOACCESS_SPACE (JERRY_HEAP_CONTEXT (area), JMEM_HEAP_AREA_SIZE); + +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + JMEM_HEAP_STAT_INIT (); +} /* jmem_heap_init */ + +/** + * Finalize heap + */ +void +jmem_heap_finalize (void) +{ + JERRY_ASSERT (JERRY_CONTEXT (jmem_heap_allocated_size) == 0); +#if !JERRY_SYSTEM_ALLOCATOR + JMEM_VALGRIND_NOACCESS_SPACE (&JERRY_HEAP_CONTEXT (first), JMEM_HEAP_SIZE); +#endif /* !JERRY_SYSTEM_ALLOCATOR */ +} /* jmem_heap_finalize */ + +/** + * Allocation of memory region. + * + * See also: + * jmem_heap_alloc_block + * + * @return pointer to allocated memory block - if allocation is successful, + * NULL - if there is not enough memory. + */ +static void *JERRY_ATTR_HOT +jmem_heap_alloc (const size_t size) /**< size of requested block */ +{ +#if !JERRY_SYSTEM_ALLOCATOR + /* Align size. */ + const size_t required_size = ((size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT) * JMEM_ALIGNMENT; + jmem_heap_free_t *data_space_p = NULL; + + JMEM_VALGRIND_DEFINED_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_free_t)); + + /* Fast path for 8 byte chunks, first region is guaranteed to be sufficient. */ + if (required_size == JMEM_ALIGNMENT && JERRY_LIKELY (JERRY_HEAP_CONTEXT (first).next_offset != JMEM_HEAP_END_OF_LIST)) + { + data_space_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (JERRY_HEAP_CONTEXT (first).next_offset); + JERRY_ASSERT (jmem_is_heap_pointer (data_space_p)); + + JMEM_VALGRIND_DEFINED_SPACE (data_space_p, sizeof (jmem_heap_free_t)); + JERRY_CONTEXT (jmem_heap_allocated_size) += JMEM_ALIGNMENT; + + if (JERRY_CONTEXT (jmem_heap_allocated_size) >= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) += CONFIG_GC_LIMIT; + } + + if (data_space_p->size == JMEM_ALIGNMENT) + { + JERRY_HEAP_CONTEXT (first).next_offset = data_space_p->next_offset; + } + else + { + JERRY_ASSERT (data_space_p->size > JMEM_ALIGNMENT); + + jmem_heap_free_t *remaining_p; + remaining_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (JERRY_HEAP_CONTEXT (first).next_offset) + 1; + + JMEM_VALGRIND_DEFINED_SPACE (remaining_p, sizeof (jmem_heap_free_t)); + remaining_p->size = data_space_p->size - JMEM_ALIGNMENT; + remaining_p->next_offset = data_space_p->next_offset; + JMEM_VALGRIND_NOACCESS_SPACE (remaining_p, sizeof (jmem_heap_free_t)); + + JERRY_HEAP_CONTEXT (first).next_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (remaining_p); + } + + JMEM_VALGRIND_NOACCESS_SPACE (data_space_p, sizeof (jmem_heap_free_t)); + + if (JERRY_UNLIKELY (data_space_p == JERRY_CONTEXT (jmem_heap_list_skip_p))) + { + JERRY_CONTEXT (jmem_heap_list_skip_p) = JMEM_HEAP_GET_ADDR_FROM_OFFSET (JERRY_HEAP_CONTEXT (first).next_offset); + } + } + /* Slow path for larger regions. */ + else + { + uint32_t current_offset = JERRY_HEAP_CONTEXT (first).next_offset; + jmem_heap_free_t *prev_p = &JERRY_HEAP_CONTEXT (first); + + while (JERRY_LIKELY (current_offset != JMEM_HEAP_END_OF_LIST)) + { + jmem_heap_free_t *current_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (current_offset); + JERRY_ASSERT (jmem_is_heap_pointer (current_p)); + JMEM_VALGRIND_DEFINED_SPACE (current_p, sizeof (jmem_heap_free_t)); + + const uint32_t next_offset = current_p->next_offset; + JERRY_ASSERT (next_offset == JMEM_HEAP_END_OF_LIST + || jmem_is_heap_pointer (JMEM_HEAP_GET_ADDR_FROM_OFFSET (next_offset))); + + if (current_p->size >= required_size) + { + /* Region is sufficiently big, store address. */ + data_space_p = current_p; + + /* Region was larger than necessary. */ + if (current_p->size > required_size) + { + /* Get address of remaining space. */ + jmem_heap_free_t *const remaining_p = (jmem_heap_free_t *) ((uint8_t *) current_p + required_size); + + /* Update metadata. */ + JMEM_VALGRIND_DEFINED_SPACE (remaining_p, sizeof (jmem_heap_free_t)); + remaining_p->size = current_p->size - (uint32_t) required_size; + remaining_p->next_offset = next_offset; + JMEM_VALGRIND_NOACCESS_SPACE (remaining_p, sizeof (jmem_heap_free_t)); + + /* Update list. */ + JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t)); + prev_p->next_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (remaining_p); + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + } + /* Block is an exact fit. */ + else + { + /* Remove the region from the list. */ + JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t)); + prev_p->next_offset = next_offset; + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + } + + JERRY_CONTEXT (jmem_heap_list_skip_p) = prev_p; + + /* Found enough space. */ + JERRY_CONTEXT (jmem_heap_allocated_size) += required_size; + + while (JERRY_CONTEXT (jmem_heap_allocated_size) >= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) += CONFIG_GC_LIMIT; + } + + break; + } + + JMEM_VALGRIND_NOACCESS_SPACE (current_p, sizeof (jmem_heap_free_t)); + /* Next in list. */ + prev_p = current_p; + current_offset = next_offset; + } + } + + JMEM_VALGRIND_NOACCESS_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_free_t)); + + JERRY_ASSERT ((uintptr_t) data_space_p % JMEM_ALIGNMENT == 0); + JMEM_VALGRIND_MALLOCLIKE_SPACE (data_space_p, size); + + return (void *) data_space_p; +#else /* JERRY_SYSTEM_ALLOCATOR */ + JERRY_CONTEXT (jmem_heap_allocated_size) += size; + + while (JERRY_CONTEXT (jmem_heap_allocated_size) >= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) += CONFIG_GC_LIMIT; + } + + return malloc (size); +#endif /* !JERRY_SYSTEM_ALLOCATOR */ +} /* jmem_heap_alloc */ + +/** + * Allocation of memory block, reclaiming memory if the request cannot be fulfilled. + * + * Note: + * Each failed allocation attempt tries to reclaim memory with an increasing pressure, + * up to 'max_pressure', or until a sufficient memory block is found. When JMEM_PRESSURE_FULL + * is reached, the engine is terminated with JERRY_FATAL_OUT_OF_MEMORY. The `max_pressure` argument + * can be used to limit the maximum pressure, and prevent the engine from terminating. + * + * @return NULL, if the required memory size is 0 or not enough memory + * pointer to the allocated memory block, if allocation is successful + */ +static void * +jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size */ + jmem_pressure_t max_pressure) /**< pressure limit */ +{ + if (JERRY_UNLIKELY (size == 0)) + { + return NULL; + } + + jmem_pressure_t pressure = JMEM_PRESSURE_NONE; + + if (JERRY_CONTEXT (jmem_heap_allocated_size) + size >= JERRY_CONTEXT (jmem_heap_limit)) + { + pressure = JMEM_PRESSURE_LOW; + ecma_free_unused_memory (pressure); + } + + void *data_space_p = jmem_heap_alloc (size); + + while (JERRY_UNLIKELY (data_space_p == NULL) && JERRY_LIKELY (pressure < max_pressure)) + { + auto v = (int)(pressure); + pressure = (jmem_pressure_t)(++v); + ecma_free_unused_memory (pressure); + data_space_p = jmem_heap_alloc (size); + } + + return data_space_p; +} /* jmem_heap_gc_and_alloc_block */ + +/** + * Internal method for allocating a memory block. + * + * @return NULL, if the required memory size is 0 or not enough memory, or + * pointer to the allocated memory block, if allocation is successful + */ +void *JERRY_ATTR_HOT +jmem_heap_alloc_block_internal (const size_t size) /**< required memory size */ +{ + return jmem_heap_gc_and_alloc_block (size, JMEM_PRESSURE_FULL); +} /* jmem_heap_alloc_block_internal */ + +/** + * Allocation of memory block, reclaiming unused memory if there is not enough. + * + * Note: + * If a sufficiently sized block can't be found, the engine will be terminated with JERRY_FATAL_OUT_OF_MEMORY. + * + * @return NULL, if the required memory is 0 + * pointer to allocated memory block, otherwise + */ +void *JERRY_ATTR_HOT +jmem_heap_alloc_block (const size_t size) /**< required memory size */ +{ + void *block_p = jmem_heap_gc_and_alloc_block (size, JMEM_PRESSURE_FULL); + JMEM_HEAP_STAT_ALLOC (size); + return block_p; +} /* jmem_heap_alloc_block */ + +/** + * Allocation of memory block, reclaiming unused memory if there is not enough. + * + * Note: + * If a sufficiently sized block can't be found, NULL will be returned. + * + * @return NULL, if the required memory size is 0 + * also NULL, if the allocation has failed + * pointer to the allocated memory block, otherwise + */ +void *JERRY_ATTR_HOT +jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory size */ +{ + void *block_p = jmem_heap_gc_and_alloc_block (size, JMEM_PRESSURE_HIGH); + + return block_p; +} /* jmem_heap_alloc_block_null_on_error */ + +#if !JERRY_SYSTEM_ALLOCATOR +/** + * Finds the block in the free block list which precedes the argument block + * + * @return pointer to the preceding block + */ +static jmem_heap_free_t * +jmem_heap_find_prev (const jmem_heap_free_t *const block_p) /**< which memory block's predecessor we're looking for */ +{ + const jmem_heap_free_t *prev_p; + + if (block_p > JERRY_CONTEXT (jmem_heap_list_skip_p)) + { + prev_p = JERRY_CONTEXT (jmem_heap_list_skip_p); + } + else + { + prev_p = &JERRY_HEAP_CONTEXT (first); + } + + JERRY_ASSERT (jmem_is_heap_pointer (block_p)); + const uint32_t block_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (block_p); + + JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t)); + /* Find position of region in the list. */ + while (prev_p->next_offset < block_offset) + { + const jmem_heap_free_t *const next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset); + JERRY_ASSERT (jmem_is_heap_pointer (next_p)); + + JMEM_VALGRIND_DEFINED_SPACE (next_p, sizeof (jmem_heap_free_t)); + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + prev_p = next_p; + } + + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + return (jmem_heap_free_t *) prev_p; +} /* jmem_heap_find_prev */ + +/** + * Inserts the block into the free chain after a specified block. + * + * Note: + * 'jmem_heap_find_prev' can and should be used to find the previous free block + */ +static void +jmem_heap_insert_block (jmem_heap_free_t *block_p, /**< block to insert */ + jmem_heap_free_t *prev_p, /**< the free block after which to insert 'block_p' */ + const size_t size) /**< size of the inserted block */ +{ + JERRY_ASSERT ((uintptr_t) block_p % JMEM_ALIGNMENT == 0); + JERRY_ASSERT (size % JMEM_ALIGNMENT == 0); + + JMEM_VALGRIND_NOACCESS_SPACE (block_p, size); + + JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t)); + jmem_heap_free_t *next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset); + JMEM_VALGRIND_DEFINED_SPACE (block_p, sizeof (jmem_heap_free_t)); + JMEM_VALGRIND_DEFINED_SPACE (next_p, sizeof (jmem_heap_free_t)); + + const uint32_t block_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (block_p); + + /* Update prev. */ + if (jmem_heap_get_region_end (prev_p) == block_p) + { + /* Can be merged. */ + prev_p->size += (uint32_t) size; + JMEM_VALGRIND_NOACCESS_SPACE (block_p, sizeof (jmem_heap_free_t)); + block_p = prev_p; + } + else + { + block_p->size = (uint32_t) size; + prev_p->next_offset = block_offset; + } + + /* Update next. */ + if (jmem_heap_get_region_end (block_p) == next_p) + { + /* Can be merged. */ + block_p->size += next_p->size; + block_p->next_offset = next_p->next_offset; + } + else + { + block_p->next_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (next_p); + } + + JERRY_CONTEXT (jmem_heap_list_skip_p) = prev_p; + + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + JMEM_VALGRIND_NOACCESS_SPACE (block_p, sizeof (jmem_heap_free_t)); + JMEM_VALGRIND_NOACCESS_SPACE (next_p, sizeof (jmem_heap_free_t)); +} /* jmem_heap_insert_block */ +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + +/** + * Internal method for freeing a memory block. + * + * @return void + */ +void JERRY_ATTR_HOT +jmem_heap_free_block_internal (void *ptr, /**< pointer to beginning of data space of the block */ + const size_t size /**< size of allocated region */) +{ + JERRY_ASSERT (size > 0); + JERRY_ASSERT (JERRY_CONTEXT (jmem_heap_limit) >= JERRY_CONTEXT (jmem_heap_allocated_size)); + JERRY_ASSERT (JERRY_CONTEXT (jmem_heap_allocated_size) > 0); + +#if !JERRY_SYSTEM_ALLOCATOR + /* checking that ptr points to the heap */ + JERRY_ASSERT (jmem_is_heap_pointer (ptr)); + JERRY_ASSERT ((uintptr_t) ptr % JMEM_ALIGNMENT == 0); + + const size_t aligned_size = (size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT; + + jmem_heap_free_t *const block_p = (jmem_heap_free_t *) ptr; + jmem_heap_free_t *const prev_p = jmem_heap_find_prev (block_p); + jmem_heap_insert_block (block_p, prev_p, aligned_size); + + JERRY_CONTEXT (jmem_heap_allocated_size) -= aligned_size; + + JMEM_VALGRIND_FREELIKE_SPACE (ptr); +#else /* JERRY_SYSTEM_ALLOCATOR */ + JERRY_CONTEXT (jmem_heap_allocated_size) -= size; + free (ptr); +#endif /* !JERRY_SYSTEM_ALLOCATOR */ + while (JERRY_CONTEXT (jmem_heap_allocated_size) + CONFIG_GC_LIMIT <= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) -= CONFIG_GC_LIMIT; + } + + JERRY_ASSERT (JERRY_CONTEXT (jmem_heap_limit) >= JERRY_CONTEXT (jmem_heap_allocated_size)); +} /* jmem_heap_free_block_internal */ + +/** + * Reallocates the memory region pointed to by 'ptr', changing the size of the allocated region. + * + * @return pointer to the reallocated region + */ +void *JERRY_ATTR_HOT +jmem_heap_realloc_block (void *ptr, /**< memory region to reallocate */ + const size_t old_size, /**< current size of the region */ + const size_t new_size) /**< desired new size */ +{ +#if !JERRY_SYSTEM_ALLOCATOR + JERRY_ASSERT (jmem_is_heap_pointer (ptr)); + JERRY_ASSERT ((uintptr_t) ptr % JMEM_ALIGNMENT == 0); + JERRY_ASSERT (old_size != 0); + JERRY_ASSERT (new_size != 0); + + jmem_heap_free_t *const block_p = (jmem_heap_free_t *) ptr; + const size_t aligned_new_size = (new_size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT; + const size_t aligned_old_size = (old_size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT; + + if (aligned_old_size == aligned_new_size) + { + JMEM_VALGRIND_RESIZE_SPACE (block_p, old_size, new_size); + JMEM_HEAP_STAT_FREE (old_size); + JMEM_HEAP_STAT_ALLOC (new_size); + return block_p; + } + + if (aligned_new_size < aligned_old_size) + { + JMEM_VALGRIND_RESIZE_SPACE (block_p, old_size, new_size); + JMEM_HEAP_STAT_FREE (old_size); + JMEM_HEAP_STAT_ALLOC (new_size); + jmem_heap_insert_block ((jmem_heap_free_t *) ((uint8_t *) block_p + aligned_new_size), + jmem_heap_find_prev (block_p), + aligned_old_size - aligned_new_size); + + JERRY_CONTEXT (jmem_heap_allocated_size) -= (aligned_old_size - aligned_new_size); + while (JERRY_CONTEXT (jmem_heap_allocated_size) + CONFIG_GC_LIMIT <= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) -= CONFIG_GC_LIMIT; + } + + return block_p; + } + + void *ret_block_p = NULL; + const size_t required_size = aligned_new_size - aligned_old_size; + + if (JERRY_CONTEXT (jmem_heap_allocated_size) + required_size >= JERRY_CONTEXT (jmem_heap_limit)) + { + ecma_free_unused_memory (JMEM_PRESSURE_LOW); + } + + jmem_heap_free_t *prev_p = jmem_heap_find_prev (block_p); + JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t)); + jmem_heap_free_t *const next_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (prev_p->next_offset); + + /* Check if block can be extended at the end */ + if (((jmem_heap_free_t *) ((uint8_t *) block_p + aligned_old_size)) == next_p) + { + JMEM_VALGRIND_DEFINED_SPACE (next_p, sizeof (jmem_heap_free_t)); + + if (required_size <= next_p->size) + { + /* Block can be extended, update the list. */ + if (required_size == next_p->size) + { + prev_p->next_offset = next_p->next_offset; + } + else + { + jmem_heap_free_t *const new_next_p = (jmem_heap_free_t *) ((uint8_t *) next_p + required_size); + JMEM_VALGRIND_DEFINED_SPACE (new_next_p, sizeof (jmem_heap_free_t)); + new_next_p->next_offset = next_p->next_offset; + new_next_p->size = (uint32_t) (next_p->size - required_size); + JMEM_VALGRIND_NOACCESS_SPACE (new_next_p, sizeof (jmem_heap_free_t)); + prev_p->next_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (new_next_p); + } + + /* next_p will be marked as undefined space. */ + JMEM_VALGRIND_RESIZE_SPACE (block_p, old_size, new_size); + ret_block_p = block_p; + } + else + { + JMEM_VALGRIND_NOACCESS_SPACE (next_p, sizeof (jmem_heap_free_t)); + } + + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + } + /* + * Check if block can be extended at the front. + * This is less optimal because we need to copy the data, but still better than allocating a new block. + */ + else if (jmem_heap_get_region_end (prev_p) == block_p) + { + if (required_size <= prev_p->size) + { + if (required_size == prev_p->size) + { + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + prev_p = jmem_heap_find_prev (prev_p); + JMEM_VALGRIND_DEFINED_SPACE (prev_p, sizeof (jmem_heap_free_t)); + prev_p->next_offset = JMEM_HEAP_GET_OFFSET_FROM_ADDR (next_p); + } + else + { + prev_p->size = (uint32_t) (prev_p->size - required_size); + } + + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + + ret_block_p = (uint8_t *) block_p - required_size; + + /* Mark the new block as undefined so that we are able to write to it. */ + JMEM_VALGRIND_UNDEFINED_SPACE (ret_block_p, old_size); + /* The blocks are likely to overlap, so mark the old block as defined memory again. */ + JMEM_VALGRIND_DEFINED_SPACE (block_p, old_size); + memmove (ret_block_p, block_p, old_size); + + JMEM_VALGRIND_FREELIKE_SPACE (block_p); + JMEM_VALGRIND_MALLOCLIKE_SPACE (ret_block_p, new_size); + JMEM_VALGRIND_DEFINED_SPACE (ret_block_p, old_size); + } + else + { + JMEM_VALGRIND_NOACCESS_SPACE (prev_p, sizeof (jmem_heap_free_t)); + } + } + + if (ret_block_p != NULL) + { + /* Managed to extend the block. Update memory usage and the skip pointer. */ + JERRY_CONTEXT (jmem_heap_list_skip_p) = prev_p; + JERRY_CONTEXT (jmem_heap_allocated_size) += required_size; + + while (JERRY_CONTEXT (jmem_heap_allocated_size) >= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) += CONFIG_GC_LIMIT; + } + } + else + { + /* Could not extend block. Allocate new region and copy the data. */ + /* jmem_heap_alloc_block_internal will adjust the allocated_size, but insert_block will not, + so we reduce it here first, so that the limit calculation remains consistent. */ + JERRY_CONTEXT (jmem_heap_allocated_size) -= aligned_old_size; + ret_block_p = jmem_heap_alloc_block_internal (new_size); + + /* jmem_heap_alloc_block_internal may trigger garbage collection, which can create new free blocks + * in the heap structure, so we need to look up the previous block again. */ + prev_p = jmem_heap_find_prev (block_p); + + memcpy (ret_block_p, block_p, old_size); + jmem_heap_insert_block (block_p, prev_p, aligned_old_size); + /* jmem_heap_alloc_block_internal will call JMEM_VALGRIND_MALLOCLIKE_SPACE */ + JMEM_VALGRIND_FREELIKE_SPACE (block_p); + } + + JMEM_HEAP_STAT_FREE (old_size); + JMEM_HEAP_STAT_ALLOC (new_size); + return ret_block_p; +#else /* JERRY_SYSTEM_ALLOCATOR */ + const size_t required_size = new_size - old_size; + + if (JERRY_CONTEXT (jmem_heap_allocated_size) + required_size >= JERRY_CONTEXT (jmem_heap_limit)) + { + ecma_free_unused_memory (JMEM_PRESSURE_LOW); + } + + JERRY_CONTEXT (jmem_heap_allocated_size) += required_size; + + while (JERRY_CONTEXT (jmem_heap_allocated_size) >= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) += CONFIG_GC_LIMIT; + } + + while (JERRY_CONTEXT (jmem_heap_allocated_size) + CONFIG_GC_LIMIT <= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) -= CONFIG_GC_LIMIT; + } + + JMEM_HEAP_STAT_FREE (old_size); + JMEM_HEAP_STAT_ALLOC (new_size); + return realloc (ptr, new_size); +#endif /* !JERRY_SYSTEM_ALLOCATOR */ +} /* jmem_heap_realloc_block */ + +/** + * Free memory block + * + * @return void + */ +void JERRY_ATTR_HOT +jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the block */ + const size_t size) /**< size of allocated region */ +{ + jmem_heap_free_block_internal (ptr, size); + JMEM_HEAP_STAT_FREE (size); + return; +} /* jmem_heap_free_block */ + +#ifndef JERRY_NDEBUG +/** + * Check whether the pointer points to the heap + * + * Note: + * the routine should be used only for assertion checks + * + * @return true - if pointer points to the heap, + * false - otherwise + */ +bool +jmem_is_heap_pointer (const void *pointer) /**< pointer */ +{ +#if !JERRY_SYSTEM_ALLOCATOR + return ((uint8_t *) pointer >= JERRY_HEAP_CONTEXT (area) + && (uint8_t *) pointer <= (JERRY_HEAP_CONTEXT (area) + JMEM_HEAP_AREA_SIZE)); +#else /* JERRY_SYSTEM_ALLOCATOR */ + JERRY_UNUSED (pointer); + return true; +#endif /* !JERRY_SYSTEM_ALLOCATOR */ +} /* jmem_is_heap_pointer */ +#endif /* !JERRY_NDEBUG */ + + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-poolman.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-poolman.cpp new file mode 100644 index 0000000..f0a9f1e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem-poolman.cpp @@ -0,0 +1,122 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Memory pool manager implementation + */ + +#include "jcontext.h" +#include "jmem.h" +#include "jrt-libc-includes.h" + +#define JMEM_ALLOCATOR_INTERNAL +#include "jmem-allocator-internal.h" + +/** \addtogroup mem Memory allocation + * @{ + * + * \addtogroup poolman Memory pool manager + * @{ + */ + +/** + * Finalize pool manager + */ +void +jmem_pools_finalize (void) +{ + jmem_pools_collect_empty (); + + JERRY_ASSERT (JERRY_CONTEXT (jmem_free_8_byte_chunk_p) == NULL); +} /* jmem_pools_finalize */ + +/** + * Allocate a chunk of specified size + * + * @return pointer to allocated chunk, if allocation was successful, + * or NULL - if not enough memory. + */ +void *JERRY_ATTR_HOT +jmem_pools_alloc (size_t size) /**< size of the chunk */ +{ + JERRY_ASSERT (size <= 8); + + if (JERRY_CONTEXT (jmem_free_8_byte_chunk_p) != NULL) + { + const jmem_pools_chunk_t *const chunk_p = JERRY_CONTEXT (jmem_free_8_byte_chunk_p); + + JMEM_VALGRIND_DEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t)); + JERRY_CONTEXT (jmem_free_8_byte_chunk_p) = chunk_p->next_p; + JMEM_VALGRIND_UNDEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t)); + + JMEM_HEAP_STAT_ALLOC (8); + return (void *) chunk_p; + } + else + { + void *chunk_p = jmem_heap_alloc_block_internal (8); + JMEM_HEAP_STAT_ALLOC (8); + return chunk_p; + } +} /* jmem_pools_alloc */ + +/** + * Free the chunk + * + * @return void + */ +void JERRY_ATTR_HOT +jmem_pools_free (void *chunk_p, /**< pointer to the chunk */ + size_t size) /**< size of the chunk */ +{ + JERRY_ASSERT (chunk_p != NULL); + JMEM_HEAP_STAT_FREE (size); + + jmem_pools_chunk_t *const chunk_to_free_p = (jmem_pools_chunk_t *) chunk_p; + + JMEM_VALGRIND_DEFINED_SPACE (chunk_to_free_p, size); + + JERRY_ASSERT (size <= 8); + + chunk_to_free_p->next_p = JERRY_CONTEXT (jmem_free_8_byte_chunk_p); + JERRY_CONTEXT (jmem_free_8_byte_chunk_p) = chunk_to_free_p; + + JMEM_VALGRIND_NOACCESS_SPACE (chunk_to_free_p, size); +} /* jmem_pools_free */ + +/** + * Collect empty pool chunks + */ +void +jmem_pools_collect_empty (void) +{ + jmem_pools_chunk_t *chunk_p = JERRY_CONTEXT (jmem_free_8_byte_chunk_p); + JERRY_CONTEXT (jmem_free_8_byte_chunk_p) = NULL; + + while (chunk_p) + { + JMEM_VALGRIND_DEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t)); + jmem_pools_chunk_t *const next_p = chunk_p->next_p; + JMEM_VALGRIND_NOACCESS_SPACE (chunk_p, sizeof (jmem_pools_chunk_t)); + + jmem_heap_free_block_internal (chunk_p, 8); + chunk_p = next_p; + } +} /* jmem_pools_collect_empty */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem.h new file mode 100644 index 0000000..3251913 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/jmem.h @@ -0,0 +1,274 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JMEM_H +#define JMEM_H + +#include "jrt.h" + +/** \addtogroup mem Memory allocation + * @{ + * + * \addtogroup heap Heap + * @{ + */ + +/** + * Logarithm of required alignment for allocated units/blocks + */ +#define JMEM_ALIGNMENT_LOG 3 + +/** + * Representation of NULL value for compressed pointers + */ +#define JMEM_CP_NULL ((jmem_cpointer_t) 0) + +/** + * Required alignment for allocated units/blocks + */ +#define JMEM_ALIGNMENT (1u << JMEM_ALIGNMENT_LOG) + +/** + * Pointer value can be directly stored without compression + */ +#if UINTPTR_MAX <= UINT32_MAX +#define JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY +#endif /* UINTPTR_MAX <= UINT32_MAX */ + +/** + * Mask for tag part in jmem_cpointer_tag_t + */ +#define JMEM_TAG_MASK 0x7u + +/** + * Shift for tag part in jmem_cpointer_tag_t + */ +#define JMEM_TAG_SHIFT 3 + +/** + * Bit mask for tag part in jmem_cpointer_tag_t + */ +enum +{ + JMEM_FIRST_TAG_BIT_MASK = (1u << 0), /**< first tag bit mask **/ + JMEM_SECOND_TAG_BIT_MASK = (1u << 1), /**< second tag bit mask **/ + JMEM_THIRD_TAG_BIT_MASK = (1u << 2), /**< third tag bit mask **/ +}; + +/** + * Compressed pointer representations + * + * 16 bit representation: + * The jmem_cpointer_t is defined as uint16_t + * and it can contain any sixteen bit value. + * + * 32 bit representation: + * The jmem_cpointer_t is defined as uint32_t. + * The lower JMEM_ALIGNMENT_LOG bits must be zero. + * The other bits can have any value. + * + * The 16 bit representation always encodes an offset from + * a heap base. The 32 bit representation currently encodes + * raw 32 bit JMEM_ALIGNMENT aligned pointers on 32 bit systems. + * This can be extended to encode a 32 bit offset from a heap + * base on 64 bit systems in the future. There are no plans + * to support more than 4G address space for JerryScript. + */ + +/** + * Compressed pointer + */ +typedef uint16_t jmem_cpointer_t; + +/** + * Compressed pointer with tag value + */ +typedef uint32_t jmem_cpointer_tag_t; + +/** + * Memory usage pressure for reclaiming unused memory. + * + * Each failed allocation will try to reclaim memory with increasing pressure, + * until enough memory is freed to fulfill the allocation request. + * + * If not enough memory is freed and JMEM_PRESSURE_FULL is reached, + * then the engine is shut down with JERRY_FATAL_OUT_OF_MEMORY. + */ +typedef enum +{ + JMEM_PRESSURE_NONE, /**< no memory pressure */ + JMEM_PRESSURE_LOW, /**< low memory pressure */ + JMEM_PRESSURE_HIGH, /**< high memory pressure */ + JMEM_PRESSURE_FULL, /**< memory full */ +} jmem_pressure_t; + +/** + * Node for free chunk list + */ +typedef struct jmem_pools_chunk_t +{ + struct jmem_pools_chunk_t *next_p; /**< pointer to next pool chunk */ +} jmem_pools_chunk_t; + +/** + * Free region node + */ +typedef struct +{ + uint32_t next_offset; /**< Offset of next region in list */ + uint32_t size; /**< Size of region */ +} jmem_heap_free_t; + +void jmem_init (void); +void jmem_finalize (void); + +void *jmem_heap_alloc_block (const size_t size); +void *jmem_heap_alloc_block_null_on_error (const size_t size); +void *jmem_heap_realloc_block (void *ptr, const size_t old_size, const size_t new_size); +void jmem_heap_free_block (void *ptr, const size_t size); + + +jmem_cpointer_t JERRY_ATTR_PURE jmem_compress_pointer (const void *pointer_p); +void *JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer); + +/** + * Define a local array variable and allocate memory for the array on the heap. + * + * If requested number of elements is zero, assign NULL to the variable. + * + * Warning: + * if there is not enough memory on the heap, shutdown engine with JERRY_FATAL_OUT_OF_MEMORY. + */ +#define JMEM_DEFINE_LOCAL_ARRAY(var_name, number, type) \ + { \ + size_t var_name##___size = (size_t) (number) * sizeof (type); \ + type *var_name = (type *) (jmem_heap_alloc_block (var_name##___size)); + +/** + * Free the previously defined local array variable, freeing corresponding block on the heap, + * if it was allocated (i.e. if the array's size was non-zero). + */ +#define JMEM_FINALIZE_LOCAL_ARRAY(var_name) \ + if (var_name != NULL) \ + { \ + JERRY_ASSERT (var_name##___size != 0); \ + \ + jmem_heap_free_block (var_name, var_name##___size); \ + } \ + else \ + { \ + JERRY_ASSERT (var_name##___size == 0); \ + } \ + } + +/** + * Get value of pointer from specified non-null compressed pointer value + */ +#define JMEM_CP_GET_NON_NULL_POINTER(type, cp_value) ((type *) (jmem_decompress_pointer (cp_value))) + +/** + * Get value of pointer from specified compressed pointer value + */ +#define JMEM_CP_GET_POINTER(type, cp_value) \ + (((JERRY_UNLIKELY ((cp_value) == JMEM_CP_NULL)) ? NULL : JMEM_CP_GET_NON_NULL_POINTER (type, cp_value))) + +/** + * Set value of non-null compressed pointer so that it will correspond + * to specified non_compressed_pointer + */ +#define JMEM_CP_SET_NON_NULL_POINTER(cp_value, non_compressed_pointer) \ + (cp_value) = jmem_compress_pointer (non_compressed_pointer) + +/** + * Set value of compressed pointer so that it will correspond + * to specified non_compressed_pointer + */ +#define JMEM_CP_SET_POINTER(cp_value, non_compressed_pointer) \ + do \ + { \ + void *ptr_value = (void *) non_compressed_pointer; \ + \ + if (JERRY_UNLIKELY ((ptr_value) == NULL)) \ + { \ + (cp_value) = JMEM_CP_NULL; \ + } \ + else \ + { \ + JMEM_CP_SET_NON_NULL_POINTER (cp_value, ptr_value); \ + } \ + } while (false); + +/** + * Set value of pointer-tag value so that it will correspond + * to specified non_compressed_pointer along with tag + */ +#define JMEM_CP_SET_NON_NULL_POINTER_TAG(cp_value, pointer, tag) \ + do \ + { \ + JERRY_ASSERT ((uintptr_t) tag < (uintptr_t) (JMEM_ALIGNMENT)); \ + jmem_cpointer_tag_t compressed_ptr = jmem_compress_pointer (pointer); \ + (cp_value) = (jmem_cpointer_tag_t) ((compressed_ptr << JMEM_TAG_SHIFT) | tag); \ + } while (false); + +/** + * Extract value of pointer from specified pointer-tag value + */ +#define JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, cp_value) \ + ((type *) (jmem_decompress_pointer ((cp_value & ~JMEM_TAG_MASK) >> JMEM_TAG_SHIFT))) + +/** + * Extract tag bits from pointer-tag value + */ +#define JMEM_CP_GET_POINTER_TAG_BITS(cp_value) \ + (cp_value & (JMEM_FIRST_TAG_BIT_MASK | JMEM_SECOND_TAG_BIT_MASK | JMEM_THIRD_TAG_BIT_MASK)) + +/** + * Get value of each tag from specified pointer-tag value + */ +#define JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG(cp_value) \ + (cp_value & JMEM_FIRST_TAG_BIT_MASK) /**< get first tag bit \ + **/ +#define JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG(cp_value) \ + (cp_value & JMEM_SECOND_TAG_BIT_MASK) /**< get second tag bit **/ +#define JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG(cp_value) \ + (cp_value & JMEM_THIRD_TAG_BIT_MASK) /**< get third tag bit \ + **/ + +/** + * Set value of each tag to specified pointer-tag value + */ +#define JMEM_CP_SET_FIRST_BIT_TO_POINTER_TAG(cp_value) \ + (cp_value) = (cp_value | JMEM_FIRST_TAG_BIT_MASK) /**< set first tag bit **/ +#define JMEM_CP_SET_SECOND_BIT_TO_POINTER_TAG(cp_value) \ + (cp_value) = (cp_value | JMEM_SECOND_TAG_BIT_MASK) /**< set second tag bit **/ +#define JMEM_CP_SET_THIRD_BIT_TO_POINTER_TAG(cp_value) \ + (cp_value) = (cp_value | JMEM_THIRD_TAG_BIT_MASK) /**< set third tag bit **/ + +/** + * @} + * \addtogroup poolman Memory pool manager + * @{ + */ + +void *jmem_pools_alloc (size_t size); +void jmem_pools_free (void *chunk_p, size_t size); +void jmem_pools_collect_empty (void); + +/** + * @} + * @} + */ + +#endif /* !JMEM_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/meson.build new file mode 100644 index 0000000..b95f6dd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jmem/meson.build @@ -0,0 +1,12 @@ +source_file = [ + 'jmem-allocator-internal.h', + 'jmem.h', + 'jmem-allocator.cpp', + 'jmem-heap.cpp', + 'jmem-poolman.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-bit-fields.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-bit-fields.h new file mode 100644 index 0000000..53ea31b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-bit-fields.h @@ -0,0 +1,43 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JRT_BIT_FIELDS_H +#define JRT_BIT_FIELDS_H + +/** + * Extract a bit-field. + * + * @param type type of container + * @param container container to extract bit-field from + * @param lsb least significant bit of the value to be extracted + * @param width width of the bit-field to be extracted + * @return bit-field's value + */ +#define JRT_EXTRACT_BIT_FIELD(type, container, lsb, width) (((container) >> lsb) & ((((type) 1) << (width)) - 1)) + +/** + * Set a bit-field. + * + * @param type type of container + * @param container container to insert bit-field to + * @param new_bit_field_value value of bit-field to insert + * @param lsb least significant bit of the value to be inserted + * @param width width of the bit-field to be inserted + * @return bit-field's value + */ +#define JRT_SET_BIT_FIELD_VALUE(type, container, new_bit_field_value, lsb, width) \ + (((container) & ~(((((type) 1) << (width)) - 1) << (lsb))) | (((type) new_bit_field_value) << (lsb))) + +#endif /* !JRT_BIT_FIELDS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-fatals.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-fatals.cpp new file mode 100644 index 0000000..4ce3729 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-fatals.cpp @@ -0,0 +1,96 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Implementation of exit with specified status code. + */ + +#include "jrt-libc-includes.h" +#include "jrt.h" + +/* + * Exit with specified status code. + * + * If !JERRY_NDEBUG and code != 0, print status code with description + * and call assertion fail handler. + */ +void JERRY_ATTR_NORETURN +jerry_fatal (jerry_fatal_code_t code) /**< status code */ +{ +#ifndef JERRY_NDEBUG + switch (code) + { + case JERRY_FATAL_OUT_OF_MEMORY: + { + JERRY_ERROR_MSG ("Error: JERRY_FATAL_OUT_OF_MEMORY\n"); + break; + } + case JERRY_FATAL_REF_COUNT_LIMIT: + { + JERRY_ERROR_MSG ("Error: JERRY_FATAL_REF_COUNT_LIMIT\n"); + break; + } + case JERRY_FATAL_UNTERMINATED_GC_LOOPS: + { + JERRY_ERROR_MSG ("Error: JERRY_FATAL_UNTERMINATED_GC_LOOPS\n"); + break; + } + case JERRY_FATAL_DISABLED_BYTE_CODE: + { + JERRY_ERROR_MSG ("Error: JERRY_FATAL_DISABLED_BYTE_CODE\n"); + break; + } + case JERRY_FATAL_FAILED_ASSERTION: + { + JERRY_ERROR_MSG ("Error: JERRY_FATAL_FAILED_ASSERTION\n"); + break; + } + } +#endif /* !JERRY_NDEBUG */ + + /* to make compiler happy for some RTOS: 'control reaches end of non-void function' */ + while (true) + { + } +} /* jerry_fatal */ + +#ifndef JERRY_NDEBUG +/** + * Handle failed assertion + */ +void JERRY_ATTR_NORETURN +jerry_assert_fail (const char *assertion, /**< assertion condition string */ + const char *file, /**< file name */ + const char *function, /**< function name */ + const uint32_t line) /**< line */ +{ + JERRY_ERROR_MSG ("ICE: Assertion '%s' failed at %s(%s):%u.\n", assertion, file, function, line); + + jerry_fatal (JERRY_FATAL_FAILED_ASSERTION); +} /* jerry_assert_fail */ + +/** + * Handle execution of control path that should be unreachable + */ +void JERRY_ATTR_NORETURN +jerry_unreachable (const char *file, /**< file name */ + const char *function, /**< function name */ + const uint32_t line) /**< line */ +{ + JERRY_ERROR_MSG ("ICE: Unreachable control path at %s(%s):%u was executed.\n", file, function, line); + + jerry_fatal (JERRY_FATAL_FAILED_ASSERTION); +} /* jerry_unreachable */ +#endif /* !JERRY_NDEBUG */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-libc-includes.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-libc-includes.h new file mode 100644 index 0000000..bf87a86 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-libc-includes.h @@ -0,0 +1,26 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JRT_LIBC_INCLUDES_H +#define JRT_LIBC_INCLUDES_H + +#include +#include +#include +#include +#include +#include + +#endif /* !JRT_LIBC_INCLUDES_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-logging.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-logging.cpp new file mode 100644 index 0000000..512abb6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-logging.cpp @@ -0,0 +1,40 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jrt.h" + +static jerry_log_level_t jerry_log_level = JERRY_LOG_LEVEL_ERROR; + +/** + * Get current log level + * + * @return log level + */ +jerry_log_level_t +jerry_jrt_get_log_level (void) +{ + return jerry_log_level; +} /* jerry_jrt_get_log_level */ + +/** + * Set log level + * + * @param level: new log level + */ +void +jerry_jrt_set_log_level (jerry_log_level_t level) +{ + jerry_log_level = level; +} /* jerry_jrt_set_log_level */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-types.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-types.h new file mode 100644 index 0000000..16d444e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt-types.h @@ -0,0 +1,24 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JRT_TYPES_H +#define JRT_TYPES_H + +#include +#include +#include +#include + +#endif /* !JRT_TYPES_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt.h new file mode 100644 index 0000000..dcf2147 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/jrt.h @@ -0,0 +1,218 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JRT_H +#define JRT_H + +#include +#include + +#include "jerryscript-core.h" +#include "jerryscript-port.h" +#include "jrt-types.h" + + +#define JERRY_NDEBUG + +/* + * Constants + */ +#define JERRY_BITSINBYTE 8 + +/* + * Make sure unused parameters, variables, or expressions trigger no compiler warning. + */ +#define JERRY_UNUSED(x) ((void) (x)) + +#define JERRY_UNUSED_1(_1) JERRY_UNUSED (_1) +#define JERRY_UNUSED_2(_1, _2) JERRY_UNUSED (_1), JERRY_UNUSED_1 (_2) +#define JERRY_UNUSED_3(_1, _2, _3) JERRY_UNUSED (_1), JERRY_UNUSED_2 (_2, _3) +#define JERRY_UNUSED_4(_1, _2, _3, _4) JERRY_UNUSED (_1), JERRY_UNUSED_3 (_2, _3, _4) +#define JERRY_UNUSED_5(_1, _2, _3, _4, _5) JERRY_UNUSED (_1), JERRY_UNUSED_4 (_2, _3, _4, _5) +#define JERRY_UNUSED_6(_1, _2, _3, _4, _5, _6) JERRY_UNUSED (_1), JERRY_UNUSED_5 (_2, _3, _4, _5, _6) +#define JERRY_UNUSED_7(_1, _2, _3, _4, _5, _6, _7) JERRY_UNUSED (_1), JERRY_UNUSED_6 (_2, _3, _4, _5, _6, _7) +#define JERRY_UNUSED_8(_1, _2, _3, _4, _5, _6, _7, _8) JERRY_UNUSED (_1), JERRY_UNUSED_7 (_2, _3, _4, _5, _6, _7, _8) + +#define JERRY_VA_ARGS_NUM_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N +#define JERRY_VA_ARGS_NUM(...) JERRY_VA_ARGS_NUM_IMPL (__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0) + +#define JERRY_UNUSED_ALL_IMPL_(nargs) JERRY_UNUSED_##nargs +#define JERRY_UNUSED_ALL_IMPL(nargs) JERRY_UNUSED_ALL_IMPL_ (nargs) +#define JERRY_UNUSED_ALL(...) JERRY_UNUSED_ALL_IMPL (JERRY_VA_ARGS_NUM (__VA_ARGS__)) (__VA_ARGS__) + +/* + * Asserts + * + * Warning: + * Don't use JERRY_STATIC_ASSERT in headers, because + * __LINE__ may be the same for asserts in a header + * and in an implementation file. + */ +#define JERRY_STATIC_ASSERT_GLUE_(a, b, c) a##b##_##c +#define JERRY_STATIC_ASSERT_GLUE(a, b, c) JERRY_STATIC_ASSERT_GLUE_ (a, b, c) +#define JERRY_STATIC_ASSERT(x, msg) \ + enum \ + { \ + JERRY_STATIC_ASSERT_GLUE (static_assertion_failed_, __LINE__, msg) = (!!x) \ + } + +#ifndef JERRY_NDEBUG +void JERRY_ATTR_NORETURN jerry_assert_fail (const char *assertion, + const char *file, + const char *function, + const uint32_t line); +void JERRY_ATTR_NORETURN jerry_unreachable (const char *file, const char *function, const uint32_t line); + +#define JERRY_ASSERT(x) \ + do \ + { \ + if (JERRY_UNLIKELY (!(x))) \ + { \ + jerry_assert_fail (#x, __FILE__, __func__, __LINE__); \ + } \ + } while (0) + +#define JERRY_UNREACHABLE() \ + do \ + { \ + jerry_unreachable (__FILE__, __func__, __LINE__); \ + } while (0) +#else /* JERRY_NDEBUG */ +#define JERRY_ASSERT(x) \ + do \ + { \ + } while (0) + +#if defined(__GNUC__) || defined(__clang__) + #define JERRY_UNREACHABLE() __builtin_unreachable () +#elif defined(_MSC_VER) + #define JERRY_UNREACHABLE() _assume (0) +#else + #ifndef JERRY_UNREACHABLE + #define JERRY_UNREACHABLE() + #endif +#endif /* !JERRY_UNREACHABLE */ + +#endif /* !JERRY_NDEBUG */ + +/** + * Exit on fatal error + */ +void JERRY_ATTR_NORETURN jerry_fatal (jerry_fatal_code_t code); + +jerry_log_level_t jerry_jrt_get_log_level (void); +void jerry_jrt_set_log_level (jerry_log_level_t level); + +/* + * Logging + */ +#define JERRY_ERROR_MSG(...) \ + do \ + { \ + if (false) \ + { \ + JERRY_UNUSED_ALL (__VA_ARGS__); \ + } \ + } while (0) +#define JERRY_WARNING_MSG(...) \ + do \ + { \ + if (false) \ + { \ + JERRY_UNUSED_ALL (__VA_ARGS__); \ + } \ + } while (0) +#define JERRY_DEBUG_MSG(...) \ + do \ + { \ + if (false) \ + { \ + JERRY_UNUSED_ALL (__VA_ARGS__); \ + } \ + } while (0) +#define JERRY_TRACE_MSG(...) \ + do \ + { \ + if (false) \ + { \ + JERRY_UNUSED_ALL (__VA_ARGS__); \ + } \ + } while (0) + +/** + * Size of struct member + */ +#define JERRY_SIZE_OF_STRUCT_MEMBER(struct_name, member_name) sizeof (((struct_name *) NULL)->member_name) + +/** + * Aligns @a value to @a alignment. @a must be the power of 2. + * + * Returns minimum positive value, that divides @a alignment and is more than or equal to @a value + */ +#define JERRY_ALIGNUP(value, alignment) (((value) + ((alignment) -1)) & ~((alignment) -1)) + +/** + * Align value down + */ +#define JERRY_ALIGNDOWN(value, alignment) ((value) & ~((alignment) -1)) + +/* + * min, max + */ +#define JERRY_MIN(v1, v2) (((v1) < (v2)) ? (v1) : (v2)) +#define JERRY_MAX(v1, v2) (((v1) < (v2)) ? (v2) : (v1)) + +/** + * Calculate the index of the first non-zero bit of a 32 bit integer value + */ +#define JERRY__LOG2_1(n) (((n) >= 2) ? 1 : 0) +#define JERRY__LOG2_2(n) (((n) >= 1 << 2) ? (2 + JERRY__LOG2_1 ((n) >> 2)) : JERRY__LOG2_1 (n)) +#define JERRY__LOG2_4(n) (((n) >= 1 << 4) ? (4 + JERRY__LOG2_2 ((n) >> 4)) : JERRY__LOG2_2 (n)) +#define JERRY__LOG2_8(n) (((n) >= 1 << 8) ? (8 + JERRY__LOG2_4 ((n) >> 8)) : JERRY__LOG2_4 (n)) +#define JERRY_LOG2(n) (((n) >= 1 << 16) ? (16 + JERRY__LOG2_8 ((n) >> 16)) : JERRY__LOG2_8 (n)) + +/** + * JERRY_BLOCK_TAIL_CALL_OPTIMIZATION + * + * Adapted from abseil ( https://github.com/abseil/ ) + * + * Instructs the compiler to avoid optimizing tail-call recursion. This macro is + * useful when you wish to preserve the existing function order within a stack + * trace for logging, debugging, or profiling purposes. + * + * Example: + * + * int f() { + * int result = g(); + * JERRY_BLOCK_TAIL_CALL_OPTIMIZATION(); + * return result; + * } + * + * This macro is intentionally here as jerryscript-compiler.h is a public header and + * it does not make sense to expose this macro to the public. + */ +#if defined(__clang__) || defined(__GNUC__) +/* Clang/GCC will not tail call given inline volatile assembly. */ +#define JERRY_BLOCK_TAIL_CALL_OPTIMIZATION() __asm__ __volatile__ ("") +#else /* !defined(__clang__) && !defined(__GNUC__) */ +/* On GCC 10.x this version also works. */ +#define JERRY_BLOCK_TAIL_CALL_OPTIMIZATION() \ + do \ + { \ + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_ENABLED; \ + } while (0) +#endif /* defined(__clang__) || defined (__GNUC__) */ + +#endif /* !JRT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/meson.build new file mode 100644 index 0000000..08b94cf --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/jrt/meson.build @@ -0,0 +1,13 @@ +source_file = [ + 'jrt-bit-fields.h', + 'jrt-libc-includes.h', + 'jrt-types.h', + 'jrt.h', + 'jrt-fatals.cpp', + 'jrt-logging.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-char-helpers.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-char-helpers.cpp new file mode 100644 index 0000000..251fa68 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-char-helpers.cpp @@ -0,0 +1,995 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lit-char-helpers.h" + +#include "ecma-helpers.h" + +#include "jerry-config.h" +#include "lit-strings.h" +#include "lit-unicode-ranges-sup.inc.h" +#include "lit-unicode-ranges.inc.h" + +#if JERRY_UNICODE_CASE_CONVERSION +#include "lit-unicode-conversions-sup.inc.h" +#include "lit-unicode-conversions.inc.h" +#include "lit-unicode-folding.inc.h" +#endif /* JERRY_UNICODE_CASE_CONVERSION */ + +#define NUM_OF_ELEMENTS(array) (sizeof (array) / sizeof ((array)[0])) + +/** + * Binary search algorithm that searches the a + * character in the given char array. + * + * @return true - if the character is in the given array + * false - otherwise + */ +#define LIT_SEARCH_CHAR_IN_ARRAY_FN(function_name, char_type, array_type) \ + static bool function_name (char_type c, /**< code unit */ \ + const array_type *array, /**< array */ \ + int size_of_array) /**< length of the array */ \ + { \ + int bottom = 0; \ + int top = size_of_array - 1; \ + \ + while (bottom <= top) \ + { \ + int middle = (bottom + top) / 2; \ + char_type current = array[middle]; \ + \ + if (current == c) \ + { \ + return true; \ + } \ + \ + if (c < current) \ + { \ + top = middle - 1; \ + } \ + else \ + { \ + bottom = middle + 1; \ + } \ + } \ + \ + return false; \ + } /* __function_name */ + +LIT_SEARCH_CHAR_IN_ARRAY_FN (lit_search_char_in_array, ecma_char_t, uint16_t) + +LIT_SEARCH_CHAR_IN_ARRAY_FN (lit_search_codepoint_in_array, lit_code_point_t, uint32_t) + +/** + * Binary search algorithm that searches a character in the given intervals. + * Intervals specified by two arrays. The first one contains the starting points + * of the intervals, the second one contains the length of them. + * + * @return true - if the character is included (inclusively) in one of the intervals in the given array + * false - otherwise + */ +#define LIT_SEARCH_CHAR_IN_INTERVAL_ARRAY_FN(function_name, char_type, array_type, interval_type) \ + static bool function_name (char_type c, /**< code unit */ \ + const array_type *array_sp, /**< array of interval starting points */ \ + const interval_type *lengths, /**< array of interval lengths */ \ + int size_of_array) /**< length of the array */ \ + { \ + int bottom = 0; \ + int top = size_of_array - 1; \ + \ + while (bottom <= top) \ + { \ + int middle = (bottom + top) / 2; \ + char_type current_sp = array_sp[middle]; \ + \ + if (current_sp <= c && c <= current_sp + lengths[middle]) \ + { \ + return true; \ + } \ + \ + if (c > current_sp) \ + { \ + bottom = middle + 1; \ + } \ + else \ + { \ + top = middle - 1; \ + } \ + } \ + \ + return false; \ + } /* function_name */ + +LIT_SEARCH_CHAR_IN_INTERVAL_ARRAY_FN (lit_search_char_in_interval_array, ecma_char_t, uint16_t, uint8_t) + +LIT_SEARCH_CHAR_IN_INTERVAL_ARRAY_FN (lit_search_codepoint_in_interval_array, lit_code_point_t, uint32_t, uint16_t) + +/** + * Check if specified character is one of the Whitespace characters including those that fall into + * "Space, Separator" ("Zs") Unicode character category or one of the Line Terminator characters. + * + * @return true - if the character is one of characters, listed in ECMA-262 v5, Table 2, + * false - otherwise + */ +bool +lit_char_is_white_space (lit_code_point_t c) /**< code point */ +{ + if (c <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + return (c == LIT_CHAR_SP || (c >= LIT_CHAR_TAB && c <= LIT_CHAR_CR)); + } + + if (c == LIT_CHAR_BOM || c == LIT_CHAR_LS || c == LIT_CHAR_PS) + { + return true; + } + + return (c <= LIT_UTF16_CODE_UNIT_MAX + && ((c >= lit_unicode_white_space_interval_starts[0] + && c <= lit_unicode_white_space_interval_starts[0] + lit_unicode_white_space_interval_lengths[0]) + || lit_search_char_in_array ((ecma_char_t) c, + lit_unicode_white_space_chars, + NUM_OF_ELEMENTS (lit_unicode_white_space_chars)))); +} /* lit_char_is_white_space */ + +/** + * Check if specified character is one of LineTerminator characters + * + * @return true - if the character is one of characters, listed in ECMA-262 v5, Table 3, + * false - otherwise + */ +bool +lit_char_is_line_terminator (ecma_char_t c) /**< code unit */ +{ + return (c == LIT_CHAR_LF || c == LIT_CHAR_CR || c == LIT_CHAR_LS || c == LIT_CHAR_PS); +} /* lit_char_is_line_terminator */ + +/** + * Check if specified character is a Unicode ID_Start + * + * See also: + * ECMA-262 v1, 11.6: UnicodeIDStart + * + * @return true - if the codepoint has Unicode property "ID_Start" + * false - otherwise + */ +static bool +lit_char_is_unicode_id_start (lit_code_point_t code_point) /**< code unit */ +{ + if (JERRY_UNLIKELY (code_point >= LIT_UTF8_4_BYTE_CODE_POINT_MIN)) + { + return (lit_search_codepoint_in_interval_array (code_point, + lit_unicode_id_start_interval_starts_sup, + lit_unicode_id_start_interval_lengths_sup, + NUM_OF_ELEMENTS (lit_unicode_id_start_interval_starts_sup)) + || lit_search_codepoint_in_array (code_point, + lit_unicode_id_start_chars_sup, + NUM_OF_ELEMENTS (lit_unicode_id_start_chars_sup))); + } + ecma_char_t c = (ecma_char_t) code_point; + + return (lit_search_char_in_interval_array (c, + lit_unicode_id_start_interval_starts, + lit_unicode_id_start_interval_lengths, + NUM_OF_ELEMENTS (lit_unicode_id_start_interval_starts)) + || lit_search_char_in_array (c, lit_unicode_id_start_chars, NUM_OF_ELEMENTS (lit_unicode_id_start_chars))); +} /* lit_char_is_unicode_id_start */ + +/** + * Check if specified character is a Unicode ID_Continue + * + * See also: + * ECMA-262 v1, 11.6: UnicodeIDContinue + * + * @return true - if the codepoint has Unicode property "ID_Continue" + * false - otherwise + */ +static bool +lit_char_is_unicode_id_continue (lit_code_point_t code_point) /**< code unit */ +{ + /* Each ID_Start codepoint is ID_Continue as well. */ + if (lit_char_is_unicode_id_start (code_point)) + { + return true; + } + + if (JERRY_UNLIKELY (code_point >= LIT_UTF8_4_BYTE_CODE_POINT_MIN)) + { + return (lit_search_codepoint_in_interval_array (code_point, + lit_unicode_id_continue_interval_starts_sup, + lit_unicode_id_continue_interval_lengths_sup, + NUM_OF_ELEMENTS (lit_unicode_id_continue_interval_starts_sup)) + || lit_search_codepoint_in_array (code_point, + lit_unicode_id_continue_chars_sup, + NUM_OF_ELEMENTS (lit_unicode_id_continue_chars_sup))); + } + ecma_char_t c = (ecma_char_t) code_point; + + return ( + lit_search_char_in_interval_array (c, + lit_unicode_id_continue_interval_starts, + lit_unicode_id_continue_interval_lengths, + NUM_OF_ELEMENTS (lit_unicode_id_continue_interval_starts)) + || lit_search_char_in_array (c, lit_unicode_id_continue_chars, NUM_OF_ELEMENTS (lit_unicode_id_continue_chars))); +} /* lit_char_is_unicode_id_continue */ + +/** + * Checks whether the character is a valid identifier start. + * + * @return true if it is. + */ +bool +lit_code_point_is_identifier_start (lit_code_point_t code_point) /**< code point */ +{ + /* Fast path for ASCII-defined letters. */ + if (code_point <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + return ((LEXER_TO_ASCII_LOWERCASE (code_point) >= LIT_CHAR_LOWERCASE_A + && LEXER_TO_ASCII_LOWERCASE (code_point) <= LIT_CHAR_LOWERCASE_Z) + || code_point == LIT_CHAR_DOLLAR_SIGN || code_point == LIT_CHAR_UNDERSCORE); + } + + return lit_char_is_unicode_id_start (code_point); +} /* lit_code_point_is_identifier_start */ + +/** + * Checks whether the character is a valid identifier part. + * + * @return true if it is. + */ +bool +lit_code_point_is_identifier_part (lit_code_point_t code_point) /**< code point */ +{ + /* Fast path for ASCII-defined letters. */ + if (code_point <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + return ((LEXER_TO_ASCII_LOWERCASE (code_point) >= LIT_CHAR_LOWERCASE_A + && LEXER_TO_ASCII_LOWERCASE (code_point) <= LIT_CHAR_LOWERCASE_Z) + || (code_point >= LIT_CHAR_0 && code_point <= LIT_CHAR_9) || code_point == LIT_CHAR_DOLLAR_SIGN + || code_point == LIT_CHAR_UNDERSCORE); + } + + return lit_char_is_unicode_id_continue (code_point); +} /* lit_code_point_is_identifier_part */ + +/** + * Check if specified character is one of OctalDigit characters (ECMA-262 v5, B.1.2) + * + * @return true / false + */ +bool +lit_char_is_octal_digit (ecma_char_t c) /**< code unit */ +{ + return (c >= LIT_CHAR_ASCII_OCTAL_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_OCTAL_DIGITS_END); +} /* lit_char_is_octal_digit */ + +/** + * Check if specified character is one of DecimalDigit characters (ECMA-262 v5, 7.8.3) + * + * @return true / false + */ +bool +lit_char_is_decimal_digit (ecma_char_t c) /**< code unit */ +{ + return (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END); +} /* lit_char_is_decimal_digit */ + +/** + * Check if specified character is one of HexDigit characters (ECMA-262 v5, 7.8.3) + * + * @return true / false + */ +bool +lit_char_is_hex_digit (ecma_char_t c) /**< code unit */ +{ + return ((c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END) + || (LEXER_TO_ASCII_LOWERCASE (c) >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_BEGIN + && LEXER_TO_ASCII_LOWERCASE (c) <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_END)); +} /* lit_char_is_hex_digit */ + +/** + * Check if specified character is one of BinaryDigits characters (ECMA-262 v6, 11.8.3) + * + * @return true / false + */ +bool +lit_char_is_binary_digit (ecma_char_t c) /** code unit */ +{ + return (c == LIT_CHAR_0 || c == LIT_CHAR_1); +} /* lit_char_is_binary_digit */ + +/** + * @return radix value + */ +uint8_t +lit_char_to_radix (lit_utf8_byte_t c) /** code unit */ +{ + switch (LEXER_TO_ASCII_LOWERCASE (c)) + { + case LIT_CHAR_LOWERCASE_X: + { + return 16; + } + case LIT_CHAR_LOWERCASE_O: + { + return 8; + } + case LIT_CHAR_LOWERCASE_B: + { + return 2; + } + default: + { + return 10; + } + } +} /* lit_char_to_radix */ + +/** + * UnicodeEscape abstract method + * + * See also: ECMA-262 v10, 24.5.2.3 + */ +void +lit_char_unicode_escape (ecma_stringbuilder_t *builder_p, /**< stringbuilder to append */ + ecma_char_t c) /**< code unit to convert */ +{ + ecma_stringbuilder_append_raw (builder_p, (lit_utf8_byte_t *) "\\u", 2); + + for (int8_t i = 3; i >= 0; i--) + { + int32_t result_char = (c >> (i * 4)) & 0xF; + ecma_stringbuilder_append_byte ( + builder_p, + (lit_utf8_byte_t) (result_char + (result_char <= 9 ? LIT_CHAR_0 : (LIT_CHAR_LOWERCASE_A - 10)))); + } +} /* lit_char_unicode_escape */ + +/** + * Convert a HexDigit character to its numeric value, as defined in ECMA-262 v5, 7.8.3 + * + * @return digit value, corresponding to the hex char + */ +uint32_t +lit_char_hex_to_int (ecma_char_t c) /**< code unit, corresponding to + * one of HexDigit characters */ +{ + JERRY_ASSERT (lit_char_is_hex_digit (c)); + + if (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END) + { + return (uint32_t) (c - LIT_CHAR_ASCII_DIGITS_BEGIN); + } + + const uint32_t hex_offset = 10 - (LIT_CHAR_LOWERCASE_A % 32); + return (c % 32) + hex_offset; +} /* lit_char_hex_to_int */ + +/** + * Converts a character to UTF8 bytes. + * + * @return length of the UTF8 representation. + */ +size_t +lit_code_point_to_cesu8_bytes (uint8_t *dst_p, /**< destination buffer */ + lit_code_point_t code_point) /**< code point */ +{ + if (code_point < LIT_UTF8_2_BYTE_CODE_POINT_MIN) + { + /* 00000000 0xxxxxxx -> 0xxxxxxx */ + dst_p[0] = (uint8_t) code_point; + return 1; + } + + if (code_point < LIT_UTF8_3_BYTE_CODE_POINT_MIN) + { + /* 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx */ + dst_p[0] = (uint8_t) (LIT_UTF8_2_BYTE_MARKER | ((code_point >> 6) & LIT_UTF8_LAST_5_BITS_MASK)); + dst_p[1] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | (code_point & LIT_UTF8_LAST_6_BITS_MASK)); + return 2; + } + + if (code_point < LIT_UTF8_4_BYTE_CODE_POINT_MIN) + { + /* zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx */ + dst_p[0] = (uint8_t) (LIT_UTF8_3_BYTE_MARKER | ((code_point >> 12) & LIT_UTF8_LAST_4_BITS_MASK)); + dst_p[1] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | ((code_point >> 6) & LIT_UTF8_LAST_6_BITS_MASK)); + dst_p[2] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | (code_point & LIT_UTF8_LAST_6_BITS_MASK)); + return 3; + } + + JERRY_ASSERT (code_point <= LIT_UNICODE_CODE_POINT_MAX); + + code_point -= LIT_UTF8_4_BYTE_CODE_POINT_MIN; + + dst_p[0] = (uint8_t) (LIT_UTF8_3_BYTE_MARKER | 0xd); + dst_p[1] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | 0x20 | ((code_point >> 16) & LIT_UTF8_LAST_4_BITS_MASK)); + dst_p[2] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | ((code_point >> 10) & LIT_UTF8_LAST_6_BITS_MASK)); + + dst_p[3] = (uint8_t) (LIT_UTF8_3_BYTE_MARKER | 0xd); + dst_p[4] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | 0x30 | ((code_point >> 6) & LIT_UTF8_LAST_4_BITS_MASK)); + dst_p[5] = (uint8_t) (LIT_UTF8_EXTRA_BYTE_MARKER | (code_point & LIT_UTF8_LAST_6_BITS_MASK)); + + return 3 * 2; +} /* lit_code_point_to_cesu8_bytes */ + +/** + * Returns the length of the UTF8 representation of a character. + * + * @return length of the UTF8 representation. + */ +size_t +lit_code_point_get_cesu8_length (lit_code_point_t code_point) /**< code point */ +{ + if (code_point < LIT_UTF8_2_BYTE_CODE_POINT_MIN) + { + /* 00000000 0xxxxxxx */ + return 1; + } + + if (code_point < LIT_UTF8_3_BYTE_CODE_POINT_MIN) + { + /* 00000yyy yyxxxxxx */ + return 2; + } + + if (code_point < LIT_UTF8_4_BYTE_CODE_POINT_MIN) + { + /* zzzzyyyy yyxxxxxx */ + return 3; + } + + /* high + low surrogate */ + return 2 * 3; +} /* lit_code_point_get_cesu8_length */ + +/** + * Convert a four byte long utf8 character to two three byte long cesu8 characters + */ +void +lit_four_byte_utf8_char_to_cesu8 (uint8_t *dst_p, /**< destination buffer */ + const uint8_t *source_p) /**< source buffer */ +{ + lit_code_point_t code_point = ((((uint32_t) source_p[0]) & LIT_UTF8_LAST_3_BITS_MASK) << 18); + code_point |= ((((uint32_t) source_p[1]) & LIT_UTF8_LAST_6_BITS_MASK) << 12); + code_point |= ((((uint32_t) source_p[2]) & LIT_UTF8_LAST_6_BITS_MASK) << 6); + code_point |= (((uint32_t) source_p[3]) & LIT_UTF8_LAST_6_BITS_MASK); + + lit_code_point_to_cesu8_bytes (dst_p, code_point); +} /* lit_four_byte_utf8_char_to_cesu8 */ + +/** + * Lookup hex digits in a buffer + * + * @return UINT32_MAX - if next 'lookup' number of characters do not form a valid hex number + * value of hex number, otherwise + */ +uint32_t +lit_char_hex_lookup (const lit_utf8_byte_t *buf_p, /**< buffer */ + const lit_utf8_byte_t *const buf_end_p, /**< buffer end */ + uint32_t lookup) /**< size of lookup */ +{ + JERRY_ASSERT (lookup <= 4); + + if (JERRY_UNLIKELY (buf_p + lookup > buf_end_p)) + { + return UINT32_MAX; + } + + uint32_t value = 0; + + while (lookup--) + { + lit_utf8_byte_t ch = *buf_p++; + if (!lit_char_is_hex_digit (ch)) + { + return UINT32_MAX; + } + + value <<= 4; + value += lit_char_hex_to_int (ch); + } + + JERRY_ASSERT (value <= LIT_UTF16_CODE_UNIT_MAX); + return value; +} /* lit_char_hex_lookup */ + +/** + * Parse a decimal number with the value clamped to UINT32_MAX. + * + * @returns uint32_t number + */ +uint32_t +lit_parse_decimal (const lit_utf8_byte_t **buffer_p, /**< [in/out] character buffer */ + const lit_utf8_byte_t *buffer_end_p) /**< buffer end */ +{ + const lit_utf8_byte_t *current_p = *buffer_p; + JERRY_ASSERT (lit_char_is_decimal_digit (*current_p)); + + uint32_t value = (uint32_t) (*current_p++ - LIT_CHAR_0); + + while (current_p < buffer_end_p && lit_char_is_decimal_digit (*current_p)) + { + const uint32_t digit = (uint32_t) (*current_p++ - LIT_CHAR_0); + uint32_t new_value = value * 10 + digit; + + if (JERRY_UNLIKELY (value > UINT32_MAX / 10) || JERRY_UNLIKELY (new_value < value)) + { + value = UINT32_MAX; + continue; + } + + value = new_value; + } + + *buffer_p = current_p; + return value; +} /* lit_parse_decimal */ + +/** + * Check if specified character is a word character (part of IsWordChar abstract operation) + * + * See also: ECMA-262 v5, 15.10.2.6 (IsWordChar) + * + * @return true - if the character is a word character + * false - otherwise + */ +bool +lit_char_is_word_char (lit_code_point_t c) /**< code point */ +{ + return ((c >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && c <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END) + || (c >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && c <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END) + || (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END) || c == LIT_CHAR_UNDERSCORE); +} /* lit_char_is_word_char */ + +#if JERRY_UNICODE_CASE_CONVERSION + +/** + * Check if the specified character is in one of those tables which contain bidirectional conversions. + * + * @return codepoint of the converted character if it is found the tables + * LIT_INVALID_CP - otherwise. + */ +static lit_code_point_t +lit_search_in_bidirectional_conversion_tables (lit_code_point_t cp, /**< code point */ + bool is_lowercase) /**< is lowercase conversion */ +{ + /* 1, Check if the specified character is part of the lit_unicode_character_case_ranges_{sup} table. */ + int number_of_case_ranges; + bool is_supplementary = cp > LIT_UTF16_CODE_UNIT_MAX; + + if (is_supplementary) + { + number_of_case_ranges = NUM_OF_ELEMENTS (lit_unicode_character_case_ranges_sup); + } + else + { + number_of_case_ranges = NUM_OF_ELEMENTS (lit_unicode_character_case_ranges); + } + + int conv_counter = 0; + + for (int i = 0; i < number_of_case_ranges; i++) + { + if (i % 2 == 0 && i > 0) + { + conv_counter++; + } + + size_t range_length; + lit_code_point_t start_point; + + if (is_supplementary) + { + range_length = lit_unicode_character_case_range_lengths_sup[conv_counter]; + start_point = lit_unicode_character_case_ranges_sup[i]; + } + else + { + range_length = lit_unicode_character_case_range_lengths[conv_counter]; + start_point = lit_unicode_character_case_ranges[i]; + } + + if (start_point > cp || cp >= start_point + range_length) + { + continue; + } + + uint32_t char_dist = (uint32_t) cp - start_point; + int offset; + if (i % 2 == 0) + { + if (!is_lowercase) + { + return cp; + } + + offset = i + 1; + } + else + { + if (is_lowercase) + { + return cp; + } + + offset = i - 1; + } + + if (is_supplementary) + { + start_point = lit_unicode_character_case_ranges_sup[offset]; + } + else + { + start_point = lit_unicode_character_case_ranges[offset]; + } + + return (lit_code_point_t) (start_point + char_dist); + } + + /* Note: After this point based on the latest unicode standard(13.0.0.6) no conversion characters are + defined for supplementary planes */ + if (is_supplementary) + { + return cp; + } + + /* 2, Check if the specified character is part of the character_pair_ranges table. */ + int bottom = 0; + int top = NUM_OF_ELEMENTS (lit_unicode_character_pair_ranges) - 1; + + while (bottom <= top) + { + int middle = (bottom + top) / 2; + lit_code_point_t current_sp = lit_unicode_character_pair_ranges[middle]; + + if (current_sp <= cp && cp < current_sp + lit_unicode_character_pair_range_lengths[middle]) + { + uint32_t char_dist = (uint32_t) (cp - current_sp); + + if ((cp - current_sp) % 2 == 0) + { + return is_lowercase ? (lit_code_point_t) (current_sp + char_dist + 1) : cp; + } + + return is_lowercase ? cp : (lit_code_point_t) (current_sp + char_dist - 1); + } + + if (cp > current_sp) + { + bottom = middle + 1; + } + else + { + top = middle - 1; + } + } + + /* 3, Check if the specified character is part of the character_pairs table. */ + int number_of_character_pairs = NUM_OF_ELEMENTS (lit_unicode_character_pairs); + + for (int i = 0; i < number_of_character_pairs; i++) + { + if (cp != lit_unicode_character_pairs[i]) + { + continue; + } + + if (i % 2 == 0) + { + return is_lowercase ? lit_unicode_character_pairs[i + 1] : cp; + } + + return is_lowercase ? cp : lit_unicode_character_pairs[i - 1]; + } + + return LIT_INVALID_CP; +} /* lit_search_in_bidirectional_conversion_tables */ + +/** + * Check if the specified character is in the given conversion table. + * + * @return LIT_MULTIPLE_CU if the converted character consist more than a single code unit + * converted code point - otherwise + */ +static lit_code_point_t +lit_search_in_conversion_table (ecma_char_t character, /**< code unit */ + ecma_stringbuilder_t *builder_p, /**< string builder */ + const ecma_char_t *array, /**< array */ + const uint8_t *counters) /**< case_values counter */ +{ + int end_point = 0; + + for (int i = 0; i < 3; i++) + { + int start_point = end_point; + int size_of_case_value = i + 1; + end_point += counters[i] * (size_of_case_value + 1); + + int bottom = start_point; + int top = end_point - size_of_case_value; + + while (bottom <= top) + { + int middle = (bottom + top) / 2; + + middle -= ((middle - bottom) % (size_of_case_value + 1)); + + ecma_char_t current = array[middle]; + + if (current == character) + { + if (builder_p != NULL) + { + ecma_stringbuilder_append_char (builder_p, array[middle + 1]); + + if (size_of_case_value > 1) + { + ecma_stringbuilder_append_char (builder_p, array[middle + 2]); + } + if (size_of_case_value > 2) + { + ecma_stringbuilder_append_char (builder_p, array[middle + 3]); + } + } + + return size_of_case_value == 1 ? array[middle + 1] : LIT_MULTIPLE_CU; + } + + if (character < current) + { + top = middle - (size_of_case_value + 1); + } + else + { + bottom = middle + (size_of_case_value + 1); + } + } + } + + if (builder_p != NULL) + { + ecma_stringbuilder_append_char (builder_p, character); + } + + return (lit_code_point_t) character; +} /* lit_search_in_conversion_table */ +#endif /* JERRY_UNICODE_CASE_CONVERSION */ + +/** + * Append the converted lowercase codeunit sequence of an a given codepoint into the stringbuilder if it is present. + * + * @return LIT_MULTIPLE_CU if the converted codepoint consist more than a single code unit + * converted code point - otherwise + */ +lit_code_point_t +lit_char_to_lower_case (lit_code_point_t cp, /**< code point */ + ecma_stringbuilder_t *builder_p) /**< string builder */ +{ + if (cp <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + if (cp >= LIT_CHAR_UPPERCASE_A && cp <= LIT_CHAR_UPPERCASE_Z) + { + cp = (lit_utf8_byte_t) (cp + (LIT_CHAR_LOWERCASE_A - LIT_CHAR_UPPERCASE_A)); + } + + if (builder_p != NULL) + { + ecma_stringbuilder_append_byte (builder_p, (lit_utf8_byte_t) cp); + } + + return cp; + } + +#if JERRY_UNICODE_CASE_CONVERSION + lit_code_point_t lowercase_cp = lit_search_in_bidirectional_conversion_tables (cp, true); + + if (lowercase_cp != LIT_INVALID_CP) + { + if (builder_p != NULL) + { + ecma_stringbuilder_append_codepoint (builder_p, lowercase_cp); + } + + return lowercase_cp; + } + + JERRY_ASSERT (cp < LIT_UTF8_4_BYTE_CODE_POINT_MIN); + + int num_of_lowercase_ranges = NUM_OF_ELEMENTS (lit_unicode_lower_case_ranges); + + for (int i = 0, j = 0; i < num_of_lowercase_ranges; i += 2, j++) + { + JERRY_ASSERT (lit_unicode_lower_case_range_lengths[j] > 0); + uint32_t range_length = (uint32_t) (lit_unicode_lower_case_range_lengths[j] - 1); + lit_code_point_t start_point = lit_unicode_lower_case_ranges[i]; + + if (start_point <= cp && cp <= start_point + range_length) + { + lowercase_cp = lit_unicode_lower_case_ranges[i + 1] + (cp - start_point); + if (builder_p != NULL) + { + ecma_stringbuilder_append_codepoint (builder_p, lowercase_cp); + } + + return lowercase_cp; + } + } + + return lit_search_in_conversion_table ((ecma_char_t) cp, + builder_p, + lit_unicode_lower_case_conversions, + lit_unicode_lower_case_conversion_counters); +#else /* !JERRY_UNICODE_CASE_CONVERSION */ + if (builder_p != NULL) + { + ecma_stringbuilder_append_codepoint (builder_p, cp); + } + + return cp; +#endif /* JERRY_UNICODE_CASE_CONVERSION */ +} /* lit_char_to_lower_case */ + +/** + * Append the converted uppercase codeunit sequence of an a given codepoint into the stringbuilder if it is present. + * + * @return LIT_MULTIPLE_CU if the converted codepoint consist more than a single code unit + * converted code point - otherwise + */ +lit_code_point_t +lit_char_to_upper_case (lit_code_point_t cp, /**< code point */ + ecma_stringbuilder_t *builder_p) /**< string builder */ +{ + if (cp <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + if (cp >= LIT_CHAR_LOWERCASE_A && cp <= LIT_CHAR_LOWERCASE_Z) + { + cp = (lit_utf8_byte_t) (cp - (LIT_CHAR_LOWERCASE_A - LIT_CHAR_UPPERCASE_A)); + } + + if (builder_p != NULL) + { + ecma_stringbuilder_append_byte (builder_p, (lit_utf8_byte_t) cp); + } + + return cp; + } + +#if JERRY_UNICODE_CASE_CONVERSION + lit_code_point_t uppercase_cp = lit_search_in_bidirectional_conversion_tables (cp, false); + + if (uppercase_cp != LIT_INVALID_CP) + { + if (builder_p != NULL) + { + ecma_stringbuilder_append_codepoint (builder_p, uppercase_cp); + } + + return uppercase_cp; + } + + int num_of_upper_case_special_ranges = NUM_OF_ELEMENTS (lit_unicode_upper_case_special_ranges); + + for (int i = 0, j = 0; i < num_of_upper_case_special_ranges; i += 3, j++) + { + uint32_t range_length = lit_unicode_upper_case_special_range_lengths[j]; + ecma_char_t start_point = lit_unicode_upper_case_special_ranges[i]; + + if (start_point <= cp && cp <= start_point + range_length) + { + if (builder_p != NULL) + { + uppercase_cp = lit_unicode_upper_case_special_ranges[i + 1] + (cp - start_point); + ecma_stringbuilder_append_codepoint (builder_p, uppercase_cp); + ecma_stringbuilder_append_codepoint (builder_p, lit_unicode_upper_case_special_ranges[i + 2]); + } + + return LIT_MULTIPLE_CU; + } + } + + return lit_search_in_conversion_table ((ecma_char_t) cp, + builder_p, + lit_unicode_upper_case_conversions, + lit_unicode_upper_case_conversion_counters); +#else /* !JERRY_UNICODE_CASE_CONVERSION */ + if (builder_p != NULL) + { + ecma_stringbuilder_append_codepoint (builder_p, cp); + } + + return cp; +#endif /* JERRY_UNICODE_CASE_CONVERSION */ +} /* lit_char_to_upper_case */ + +/* + * Look up whether the character should be folded to the lowercase variant. + * + * @return true, if character should be lowercased + * false, otherwise + */ +bool +lit_char_fold_to_lower (lit_code_point_t cp) /**< code point */ +{ +#if JERRY_UNICODE_CASE_CONVERSION + return (cp <= LIT_UTF8_1_BYTE_CODE_POINT_MAX || cp > LIT_UTF16_CODE_UNIT_MAX + || (!lit_search_char_in_interval_array ((ecma_char_t) cp, + lit_unicode_folding_skip_to_lower_interval_starts, + lit_unicode_folding_skip_to_lower_interval_lengths, + NUM_OF_ELEMENTS (lit_unicode_folding_skip_to_lower_interval_starts)) + && !lit_search_char_in_array ((ecma_char_t) cp, + lit_unicode_folding_skip_to_lower_chars, + NUM_OF_ELEMENTS (lit_unicode_folding_skip_to_lower_chars)))); +#else /* !JERRY_UNICODE_CASE_CONVERSION */ + return true; +#endif /* JERRY_UNICODE_CASE_CONVERSION */ +} /* lit_char_fold_to_lower */ + +/* + * Look up whether the character should be folded to the uppercase variant. + * + * @return true, if character should be uppercased + * false, otherwise + */ +bool +lit_char_fold_to_upper (lit_code_point_t cp) /**< code point */ +{ +#if JERRY_UNICODE_CASE_CONVERSION + return (cp > LIT_UTF8_1_BYTE_CODE_POINT_MAX && cp <= LIT_UTF16_CODE_UNIT_MAX + && (lit_search_char_in_interval_array ((ecma_char_t) cp, + lit_unicode_folding_to_upper_interval_starts, + lit_unicode_folding_to_upper_interval_lengths, + NUM_OF_ELEMENTS (lit_unicode_folding_to_upper_interval_starts)) + || lit_search_char_in_array ((ecma_char_t) cp, + lit_unicode_folding_to_upper_chars, + NUM_OF_ELEMENTS (lit_unicode_folding_to_upper_chars)))); +#else /* !JERRY_UNICODE_CASE_CONVERSION */ + return false; +#endif /* JERRY_UNICODE_CASE_CONVERSION */ +} /* lit_char_fold_to_upper */ + +/** + * Helper method to find a specific character in a string + * + * Used by: + * ecma_builtin_string_prototype_object_replace_helper + * + * @return true - if the given character is in the string + * false - otherwise + */ +bool +lit_find_char_in_string (ecma_string_t *str_p, /**< source string */ + lit_utf8_byte_t c) /**< character to find*/ +{ + ECMA_STRING_TO_UTF8_STRING (str_p, start_p, start_size); + + const lit_utf8_byte_t *str_curr_p = start_p; + const lit_utf8_byte_t *str_end_p = start_p + start_size; + bool have_char = false; + + while (str_curr_p < str_end_p) + { + if (*str_curr_p++ == c) + { + have_char = true; + break; + } + } + + ECMA_FINALIZE_UTF8_STRING (start_p, start_size); + + return have_char; +} /* lit_find_char_in_string */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-char-helpers.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-char-helpers.h new file mode 100644 index 0000000..9b69617 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-char-helpers.h @@ -0,0 +1,260 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIT_CHAR_HELPERS_H +#define LIT_CHAR_HELPERS_H + +#include "ecma-globals.h" + +#include "lit-globals.h" + +/** + * Invalid character code point + */ +#define LIT_INVALID_CP 0xFFFFFFFF + +/** + * Result of lit_char_to_lower_case/lit_char_to_upper_case consist more than of a single code unit + */ +#define LIT_MULTIPLE_CU 0xFFFFFFFE + +/* + * Format control characters (ECMA-262 v5, Table 1) + */ +#define LIT_CHAR_ZWNJ ((ecma_char_t) 0x200C) /* zero width non-joiner */ +#define LIT_CHAR_ZWJ ((ecma_char_t) 0x200D) /* zero width joiner */ +#define LIT_CHAR_BOM ((ecma_char_t) 0xFEFF) /* byte order mark */ + +/* + * Whitespace characters (ECMA-262 v5, Table 2) + */ +#define LIT_CHAR_TAB ((ecma_char_t) 0x0009) /* tab */ +#define LIT_CHAR_VTAB ((ecma_char_t) 0x000B) /* vertical tab */ +#define LIT_CHAR_FF ((ecma_char_t) 0x000C) /* form feed */ +#define LIT_CHAR_SP ((ecma_char_t) 0x0020) /* space */ +#define LIT_CHAR_NBSP ((ecma_char_t) 0x00A0) /* no-break space */ +#define LIT_CHAR_MVS ((ecma_char_t) 0x180E) /* mongolian vowel separator */ +/* LIT_CHAR_BOM is defined above */ + +bool lit_char_is_white_space (lit_code_point_t c); + +/* + * Line terminator characters (ECMA-262 v5, Table 3) + */ +#define LIT_CHAR_LF ((ecma_char_t) 0x000A) /* line feed */ +#define LIT_CHAR_CR ((ecma_char_t) 0x000D) /* carriage return */ +#define LIT_CHAR_LS ((ecma_char_t) 0x2028) /* line separator */ +#define LIT_CHAR_PS ((ecma_char_t) 0x2029) /* paragraph separator */ + +bool lit_char_is_line_terminator (ecma_char_t c); + +/* + * String Single Character Escape Sequences (ECMA-262 v5, Table 4) + */ +#define LIT_CHAR_BS ((ecma_char_t) 0x0008) /* backspace */ +/* LIT_CHAR_TAB is defined above */ +/* LIT_CHAR_LF is defined above */ +/* LIT_CHAR_VTAB is defined above */ +/* LIT_CHAR_FF is defined above */ +/* LIT_CHAR_CR is defined above */ +#define LIT_CHAR_DOUBLE_QUOTE ((ecma_char_t) '"') /* double quote */ +#define LIT_CHAR_SINGLE_QUOTE ((ecma_char_t) '\'') /* single quote */ +#define LIT_CHAR_BACKSLASH ((ecma_char_t) '\\') /* reverse solidus (backslash) */ + +/* + * Comment characters (ECMA-262 v5, 7.4) + */ +#define LIT_CHAR_SLASH ((ecma_char_t) '/') /* solidus */ +#define LIT_CHAR_ASTERISK ((ecma_char_t) '*') /* asterisk */ + +/* + * Identifier name characters (ECMA-262 v5, 7.6) + */ +#define LIT_CHAR_DOLLAR_SIGN ((ecma_char_t) '$') /* dollar sign */ +#define LIT_CHAR_UNDERSCORE ((ecma_char_t) '_') /* low line (underscore) */ +/* LIT_CHAR_BACKSLASH defined above */ + +bool lit_code_point_is_identifier_start (lit_code_point_t code_point); +bool lit_code_point_is_identifier_part (lit_code_point_t code_point); + +/* + * Punctuator characters (ECMA-262 v5, 7.7) + */ +#define LIT_CHAR_LEFT_BRACE ((ecma_char_t) '{') /* left curly bracket */ +#define LIT_CHAR_RIGHT_BRACE ((ecma_char_t) '}') /* right curly bracket */ +#define LIT_CHAR_LEFT_PAREN ((ecma_char_t) '(') /* left parenthesis */ +#define LIT_CHAR_RIGHT_PAREN ((ecma_char_t) ')') /* right parenthesis */ +#define LIT_CHAR_LEFT_SQUARE ((ecma_char_t) '[') /* left square bracket */ +#define LIT_CHAR_RIGHT_SQUARE ((ecma_char_t) ']') /* right square bracket */ +#define LIT_CHAR_DOT ((ecma_char_t) '.') /* dot */ +#define LIT_CHAR_SEMICOLON ((ecma_char_t) ';') /* semicolon */ +#define LIT_CHAR_COMMA ((ecma_char_t) ',') /* comma */ +#define LIT_CHAR_LESS_THAN ((ecma_char_t) '<') /* less-than sign */ +#define LIT_CHAR_GREATER_THAN ((ecma_char_t) '>') /* greater-than sign */ +#define LIT_CHAR_EQUALS ((ecma_char_t) '=') /* equals sign */ +#define LIT_CHAR_PLUS ((ecma_char_t) '+') /* plus sign */ +#define LIT_CHAR_MINUS ((ecma_char_t) '-') /* hyphen-minus */ +/* LIT_CHAR_ASTERISK is defined above */ +#define LIT_CHAR_PERCENT ((ecma_char_t) '%') /* percent sign */ +#define LIT_CHAR_AMPERSAND ((ecma_char_t) '&') /* ampersand */ +#define LIT_CHAR_VLINE ((ecma_char_t) '|') /* vertical line */ +#define LIT_CHAR_CIRCUMFLEX ((ecma_char_t) '^') /* circumflex accent */ +#define LIT_CHAR_EXCLAMATION ((ecma_char_t) '!') /* exclamation mark */ +#define LIT_CHAR_TILDE ((ecma_char_t) '~') /* tilde */ +#define LIT_CHAR_QUESTION ((ecma_char_t) '?') /* question mark */ +#define LIT_CHAR_COLON ((ecma_char_t) ':') /* colon */ +#define LIT_CHAR_HASHMARK ((ecma_char_t) '#') /* hashmark */ + +/* + * Special characters for String.prototype.replace. + */ +#define LIT_CHAR_GRAVE_ACCENT ((ecma_char_t) '`') /* grave accent */ + +/** + * Uppercase ASCII letters + */ +#define LIT_CHAR_UPPERCASE_A ((ecma_char_t) 'A') +#define LIT_CHAR_UPPERCASE_B ((ecma_char_t) 'B') +#define LIT_CHAR_UPPERCASE_C ((ecma_char_t) 'C') +#define LIT_CHAR_UPPERCASE_D ((ecma_char_t) 'D') +#define LIT_CHAR_UPPERCASE_E ((ecma_char_t) 'E') +#define LIT_CHAR_UPPERCASE_F ((ecma_char_t) 'F') +#define LIT_CHAR_UPPERCASE_G ((ecma_char_t) 'G') +#define LIT_CHAR_UPPERCASE_H ((ecma_char_t) 'H') +#define LIT_CHAR_UPPERCASE_I ((ecma_char_t) 'I') +#define LIT_CHAR_UPPERCASE_J ((ecma_char_t) 'J') +#define LIT_CHAR_UPPERCASE_K ((ecma_char_t) 'K') +#define LIT_CHAR_UPPERCASE_L ((ecma_char_t) 'L') +#define LIT_CHAR_UPPERCASE_M ((ecma_char_t) 'M') +#define LIT_CHAR_UPPERCASE_N ((ecma_char_t) 'N') +#define LIT_CHAR_UPPERCASE_O ((ecma_char_t) 'O') +#define LIT_CHAR_UPPERCASE_P ((ecma_char_t) 'P') +#define LIT_CHAR_UPPERCASE_Q ((ecma_char_t) 'Q') +#define LIT_CHAR_UPPERCASE_R ((ecma_char_t) 'R') +#define LIT_CHAR_UPPERCASE_S ((ecma_char_t) 'S') +#define LIT_CHAR_UPPERCASE_T ((ecma_char_t) 'T') +#define LIT_CHAR_UPPERCASE_U ((ecma_char_t) 'U') +#define LIT_CHAR_UPPERCASE_V ((ecma_char_t) 'V') +#define LIT_CHAR_UPPERCASE_W ((ecma_char_t) 'W') +#define LIT_CHAR_UPPERCASE_X ((ecma_char_t) 'X') +#define LIT_CHAR_UPPERCASE_Y ((ecma_char_t) 'Y') +#define LIT_CHAR_UPPERCASE_Z ((ecma_char_t) 'Z') + +/** + * Lowercase ASCII letters + */ +#define LIT_CHAR_LOWERCASE_A ((ecma_char_t) 'a') +#define LIT_CHAR_LOWERCASE_B ((ecma_char_t) 'b') +#define LIT_CHAR_LOWERCASE_C ((ecma_char_t) 'c') +#define LIT_CHAR_LOWERCASE_D ((ecma_char_t) 'd') +#define LIT_CHAR_LOWERCASE_E ((ecma_char_t) 'e') +#define LIT_CHAR_LOWERCASE_F ((ecma_char_t) 'f') +#define LIT_CHAR_LOWERCASE_G ((ecma_char_t) 'g') +#define LIT_CHAR_LOWERCASE_H ((ecma_char_t) 'h') +#define LIT_CHAR_LOWERCASE_I ((ecma_char_t) 'i') +#define LIT_CHAR_LOWERCASE_J ((ecma_char_t) 'j') +#define LIT_CHAR_LOWERCASE_K ((ecma_char_t) 'k') +#define LIT_CHAR_LOWERCASE_L ((ecma_char_t) 'l') +#define LIT_CHAR_LOWERCASE_M ((ecma_char_t) 'm') +#define LIT_CHAR_LOWERCASE_N ((ecma_char_t) 'n') +#define LIT_CHAR_LOWERCASE_O ((ecma_char_t) 'o') +#define LIT_CHAR_LOWERCASE_P ((ecma_char_t) 'p') +#define LIT_CHAR_LOWERCASE_Q ((ecma_char_t) 'q') +#define LIT_CHAR_LOWERCASE_R ((ecma_char_t) 'r') +#define LIT_CHAR_LOWERCASE_S ((ecma_char_t) 's') +#define LIT_CHAR_LOWERCASE_T ((ecma_char_t) 't') +#define LIT_CHAR_LOWERCASE_U ((ecma_char_t) 'u') +#define LIT_CHAR_LOWERCASE_V ((ecma_char_t) 'v') +#define LIT_CHAR_LOWERCASE_W ((ecma_char_t) 'w') +#define LIT_CHAR_LOWERCASE_X ((ecma_char_t) 'x') +#define LIT_CHAR_LOWERCASE_Y ((ecma_char_t) 'y') +#define LIT_CHAR_LOWERCASE_Z ((ecma_char_t) 'z') + +/** + * ASCII decimal digits + */ +#define LIT_CHAR_0 ((ecma_char_t) '0') +#define LIT_CHAR_1 ((ecma_char_t) '1') +#define LIT_CHAR_2 ((ecma_char_t) '2') +#define LIT_CHAR_3 ((ecma_char_t) '3') +#define LIT_CHAR_4 ((ecma_char_t) '4') +#define LIT_CHAR_5 ((ecma_char_t) '5') +#define LIT_CHAR_6 ((ecma_char_t) '6') +#define LIT_CHAR_7 ((ecma_char_t) '7') +#define LIT_CHAR_8 ((ecma_char_t) '8') +#define LIT_CHAR_9 ((ecma_char_t) '9') + +/** + * ASCII character ranges + */ +#define LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN LIT_CHAR_UPPERCASE_A /* uppercase letters range */ +#define LIT_CHAR_ASCII_UPPERCASE_LETTERS_END LIT_CHAR_UPPERCASE_Z + +#define LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN LIT_CHAR_LOWERCASE_A /* lowercase letters range */ +#define LIT_CHAR_ASCII_LOWERCASE_LETTERS_END LIT_CHAR_LOWERCASE_Z + +#define LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN \ + LIT_CHAR_UPPERCASE_A /* uppercase letters for \ + * hexadecimal digits range */ +#define LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_END LIT_CHAR_UPPERCASE_F + +#define LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_BEGIN \ + LIT_CHAR_LOWERCASE_A /* lowercase letters for \ + * hexadecimal digits range */ +#define LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_END LIT_CHAR_LOWERCASE_F + +#define LIT_CHAR_ASCII_OCTAL_DIGITS_BEGIN LIT_CHAR_0 /* octal digits range */ +#define LIT_CHAR_ASCII_OCTAL_DIGITS_END LIT_CHAR_7 + +#define LIT_CHAR_ASCII_DIGITS_BEGIN LIT_CHAR_0 /* decimal digits range */ +#define LIT_CHAR_ASCII_DIGITS_END LIT_CHAR_9 + +#define LEXER_TO_ASCII_LOWERCASE(character) ((character) | LIT_CHAR_SP) + +bool lit_char_is_octal_digit (ecma_char_t c); +bool lit_char_is_decimal_digit (ecma_char_t c); +bool lit_char_is_hex_digit (ecma_char_t c); +bool lit_char_is_binary_digit (ecma_char_t c); +uint8_t lit_char_to_radix (lit_utf8_byte_t c); +void lit_char_unicode_escape (ecma_stringbuilder_t *builder_p, ecma_char_t c); +uint32_t lit_char_hex_to_int (ecma_char_t c); +size_t lit_code_point_to_cesu8_bytes (uint8_t *dst_p, lit_code_point_t code_point); +size_t lit_code_point_get_cesu8_length (lit_code_point_t code_point); +void lit_four_byte_utf8_char_to_cesu8 (uint8_t *dst_p, const uint8_t *source_p); +uint32_t lit_char_hex_lookup (const lit_utf8_byte_t *buf_p, const lit_utf8_byte_t *const buf_end_p, uint32_t lookup); +uint32_t lit_parse_decimal (const lit_utf8_byte_t **buffer_p, const lit_utf8_byte_t *const buffer_end_p); +bool lit_find_char_in_string (ecma_string_t *str_p, lit_utf8_byte_t c); + +/** + * Null character + */ +#define LIT_CHAR_NULL ((ecma_char_t) '\0') + +/* + * Part of IsWordChar abstract operation (ECMA-262 v5, 15.10.2.6, step 3) + */ +bool lit_char_is_word_char (lit_code_point_t c); + +/* + * Utility functions for uppercasing / lowercasing + */ + +lit_code_point_t lit_char_to_lower_case (lit_code_point_t cp, ecma_stringbuilder_t *builder_p); +lit_code_point_t lit_char_to_upper_case (lit_code_point_t cp, ecma_stringbuilder_t *builder_p); + +bool lit_char_fold_to_lower (lit_code_point_t cp); +bool lit_char_fold_to_upper (lit_code_point_t cp); + +#endif /* !LIT_CHAR_HELPERS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-globals.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-globals.h new file mode 100644 index 0000000..a970eee --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-globals.h @@ -0,0 +1,121 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIT_GLOBALS_H +#define LIT_GLOBALS_H + +#include "jrt.h" + +/** + * ECMAScript standard defines terms "code unit" and "character" as 16-bit unsigned value + * used to represent 16-bit unit of text, this is the same as code unit in UTF-16 (See ECMA-262 5.1 Chapter 6). + * + * The term "code point" or "Unicode character" is used to refer a single Unicode scalar value (may be longer + * than 16 bits: 0x0 - 0x10FFFFF). One code point could be represented with one ore two 16-bit code units. + * + * According to the standard all strings and source text are assumed to be a sequence of code units. + * Length of a string equals to number of code units in the string, which is not the same as number of Unicode + * characters in a string. + * + * Internally JerryScript engine uses UTF-8 representation of strings to reduce memory overhead. Unicode character + * occupies from one to four bytes in UTF-8 representation. + * + * Unicode scalar value | Bytes in UTF-8 | Bytes in UTF-16 + * | (internal representation) | + * ---------------------------------------------------------------------- + * 0x0 - 0x7F | 1 byte | 2 bytes + * 0x80 - 0x7FF | 2 bytes | 2 bytes + * 0x800 - 0xFFFF | 3 bytes | 2 bytes + * 0x10000 - 0x10FFFF | 4 bytes | 4 bytes + * + * Scalar values from 0xD800 to 0xDFFF are permanently reserved by Unicode standard to encode high and low + * surrogates in UTF-16 (Code points 0x10000 - 0x10FFFF are encoded via pair of surrogates in UTF-16). + * Despite that the official Unicode standard says that no UTF forms can encode these code points, we allow + * them to be encoded inside strings. The reason for that is compatibility with ECMA standard. + * + * For example, assume a string which consists one Unicode character: 0x1D700 (Mathematical Italic Small Epsilon). + * It has the following representation in UTF-16: 0xD835 0xDF00. + * + * ECMA standard allows extracting a substring from this string: + * > var str = String.fromCharCode (0xD835, 0xDF00); // Create a string containing one character: 0x1D700 + * > str.length; // 2 + * > var str1 = str.substring (0, 1); + * > str1.length; // 1 + * > str1.charCodeAt (0); // 55349 (this equals to 0xD835) + * + * Internally original string would be represented in UTF-8 as the following byte sequence: 0xF0 0x9D 0x9C 0x80. + * After substring extraction high surrogate 0xD835 should be encoded via UTF-8: 0xED 0xA0 0xB5. + * + * Pair of low and high surrogates encoded separately should never occur in internal string representation, + * it should be encoded as any code point and occupy 4 bytes. So, when constructing a string from two surrogates, + * it should be processed gracefully; + * > var str1 = String.fromCharCode (0xD835); // 0xED 0xA0 0xB5 - internal representation + * > var str2 = String.fromCharCode (0xDF00); // 0xED 0xBC 0x80 - internal representation + * > var str = str1 + str2; // 0xF0 0x9D 0x9C 0x80 - internal representation, + * // !!! not 0xED 0xA0 0xB5 0xED 0xBC 0x80 + */ + +/** + * Description of an ecma-character, which represents 16-bit code unit, + * which is equal to UTF-16 character (see Chapter 6 from ECMA-262 5.1) + */ +typedef uint16_t ecma_char_t; + +/** + * Max bytes needed to represent a code unit (utf-16 char) via utf-8 encoding + */ +#define LIT_UTF8_MAX_BYTES_IN_CODE_UNIT (3) + +/** + * Max bytes needed to represent a code point (Unicode character) via utf-8 encoding + */ +#define LIT_UTF8_MAX_BYTES_IN_CODE_POINT (4) + +/** + * Max bytes needed to represent a code unit (utf-16 char) via cesu-8 encoding + */ +#define LIT_CESU8_MAX_BYTES_IN_CODE_UNIT (3) + +/** + * Max bytes needed to represent a code point (Unicode character) via cesu-8 encoding + */ +#define LIT_CESU8_MAX_BYTES_IN_CODE_POINT (6) + +/** + * A byte of utf-8 string + */ +typedef uint8_t lit_utf8_byte_t; + +/** + * Size of a utf-8 string in bytes + */ +typedef uint32_t lit_utf8_size_t; + +/** + * Size of a magic string in bytes + */ +typedef uint8_t lit_magic_size_t; + +/** + * Unicode code point + */ +typedef uint32_t lit_code_point_t; + +/** + * ECMA string hash + */ +typedef uint32_t lit_string_hash_t; + +#endif /* !LIT_GLOBALS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.cpp new file mode 100644 index 0000000..6e90953 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.cpp @@ -0,0 +1,428 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jerry-config.h" +#include "lit-magic-strings.h" + +#include "jcontext.h" +#include "lit-strings.h" + +/** + * Maximum number of external magic strings that can be registered. + */ +#define LIT_EXTERNAL_MAGIC_STRING_LIMIT (UINT32_MAX / 2) + +/** + * Get number of external magic strings + * + * @return number of the strings, if there were registered, + * zero - otherwise. + */ +uint32_t +lit_get_magic_string_ex_count (void) +{ + return JERRY_CONTEXT (lit_magic_string_ex_count); +} /* lit_get_magic_string_ex_count */ + +/** + * Get specified magic string as zero-terminated string + * + * @return pointer to zero-terminated magic string + */ +const lit_utf8_byte_t * +lit_get_magic_string_utf8 (uint32_t id) /**< magic string id */ +{ + static const lit_utf8_byte_t *const lit_magic_strings[] JERRY_ATTR_CONST_DATA = { +/** @cond doxygen_suppress */ +#define LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE(size, id) +#define LIT_MAGIC_STRING_DEF(id, utf8_string) (const lit_utf8_byte_t *) utf8_string, +#include "lit-magic-strings.inc.h" +#undef LIT_MAGIC_STRING_DEF +#undef LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE + /** @endcond */ + }; + + JERRY_ASSERT (id < LIT_NON_INTERNAL_MAGIC_STRING__COUNT); + + return lit_magic_strings[id]; +} /* lit_get_magic_string_utf8 */ + +/** + * Get size of specified magic string + * + * @return size in bytes + */ +lit_utf8_size_t +lit_get_magic_string_size (uint32_t id) /**< magic string id */ +{ + static const lit_magic_size_t lit_magic_string_sizes[] JERRY_ATTR_CONST_DATA = { +/** @cond doxygen_suppress */ +#define LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE(size, id) +#define LIT_MAGIC_STRING_DEF(id, utf8_string) sizeof (utf8_string) - 1, +#include "lit-magic-strings.inc.h" +#undef LIT_MAGIC_STRING_DEF +#undef LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE + /** @endcond */ + }; + + JERRY_ASSERT (id < LIT_NON_INTERNAL_MAGIC_STRING__COUNT); + + return lit_magic_string_sizes[id]; +} /* lit_get_magic_string_size */ + +/** + * Get the block start element with the given size from + * the list of ECMA and implementation-defined magic string constants + * + * @return magic string id + */ +static lit_magic_string_id_t +lit_get_magic_string_size_block_start (lit_utf8_size_t size) /**< magic string size */ +{ + static const lit_magic_string_id_t lit_magic_string_size_block_starts[] JERRY_ATTR_CONST_DATA = { +/** @cond doxygen_suppress */ +#define LIT_MAGIC_STRING_DEF(id, utf8_string) +#define LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE(size, id) id, +#include "lit-magic-strings.inc.h" + LIT_NON_INTERNAL_MAGIC_STRING__COUNT +#undef LIT_MAGIC_STRING_DEF +#undef LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE + /** @endcond */ + }; + + JERRY_ASSERT (size <= (sizeof (lit_magic_string_size_block_starts) / sizeof (lit_magic_string_id_t))); + + return lit_magic_string_size_block_starts[size]; +} /* lit_get_magic_string_size_block_start */ + +/** + * Get specified magic string as zero-terminated string from external table + * + * @return pointer to zero-terminated magic string + */ +const lit_utf8_byte_t * +lit_get_magic_string_ex_utf8 (uint32_t id) /**< extern magic string id */ +{ + JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_array) && id < JERRY_CONTEXT (lit_magic_string_ex_count)); + + return JERRY_CONTEXT (lit_magic_string_ex_array)[id]; +} /* lit_get_magic_string_ex_utf8 */ + +/** + * Get size of specified external magic string + * + * @return size in bytes + */ +lit_utf8_size_t +lit_get_magic_string_ex_size (uint32_t id) /**< external magic string id */ +{ + return JERRY_CONTEXT (lit_magic_string_ex_sizes)[id]; +} /* lit_get_magic_string_ex_size */ + +/** + * Register external magic strings + */ +void +lit_magic_strings_ex_set (const lit_utf8_byte_t *const *ex_str_items, /**< character arrays, representing + * external magic strings' contents */ + uint32_t count, /**< number of the strings */ + const lit_utf8_size_t *ex_str_sizes) /**< sizes of the strings */ +{ + JERRY_ASSERT (ex_str_items != NULL); + JERRY_ASSERT (count > 0); + JERRY_ASSERT (ex_str_sizes != NULL); + + JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_array) == NULL); + JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_count) == 0); + JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes) == NULL); + + /* Limit the number of external magic strings */ + if (count > LIT_EXTERNAL_MAGIC_STRING_LIMIT) + { + count = LIT_EXTERNAL_MAGIC_STRING_LIMIT; + } + + /* Set external magic strings information */ + JERRY_CONTEXT (lit_magic_string_ex_array) = ex_str_items; + JERRY_CONTEXT (lit_magic_string_ex_count) = count; + JERRY_CONTEXT (lit_magic_string_ex_sizes) = ex_str_sizes; + +#ifndef JERRY_NDEBUG + for (lit_magic_string_ex_id_t id = (lit_magic_string_ex_id_t) 0; id < JERRY_CONTEXT (lit_magic_string_ex_count); + id = (lit_magic_string_ex_id_t) (id + 1)) + { + lit_utf8_size_t string_size = JERRY_CONTEXT (lit_magic_string_ex_sizes)[id]; + + /** + * Check whether the strings are sorted by size and lexicographically, + * e.g., "Bb" < "aa" < "aaa" < "xyz0". + */ + if (id > 0) + { + const lit_magic_string_ex_id_t prev_id = id - 1; + const lit_utf8_size_t prev_string_size = lit_get_magic_string_ex_size (prev_id); + JERRY_ASSERT (lit_is_valid_cesu8_string (lit_get_magic_string_ex_utf8 (id), string_size)); + JERRY_ASSERT (prev_string_size <= string_size); + + if (prev_string_size == string_size) + { + const lit_utf8_byte_t *prev_ex_string_p = lit_get_magic_string_ex_utf8 (prev_id); + const lit_utf8_byte_t *curr_ex_string_p = lit_get_magic_string_ex_utf8 (id); + JERRY_ASSERT (memcmp (prev_ex_string_p, curr_ex_string_p, string_size) < 0); + } + } + } +#endif /* !JERRY_NDEBUG */ +} /* lit_magic_strings_ex_set */ + +/** + * Returns the magic string id of the argument string if it is available. + * + * @return id - if magic string id is found, + * LIT_MAGIC_STRING__COUNT - otherwise. + */ +lit_magic_string_id_t +lit_is_utf8_string_magic (const lit_utf8_byte_t *string_p, /**< utf-8 string */ + lit_utf8_size_t string_size) /**< string size in bytes */ +{ + if (string_size > lit_get_magic_string_size (LIT_NON_INTERNAL_MAGIC_STRING__COUNT - 1)) + { + return LIT_MAGIC_STRING__COUNT; + } + + /**< The string must be in this id range. */ + lit_utf8_size_t first = lit_get_magic_string_size_block_start (string_size); + lit_utf8_size_t last = lit_get_magic_string_size_block_start (string_size + 1); + + while (first < last) + { + lit_utf8_size_t middle = ((first + last) / 2); /**< mid point of search */ + int compare = memcmp (lit_get_magic_string_utf8 ((lit_magic_string_id_t) middle), string_p, string_size); + + if (compare == 0) + { + return (lit_magic_string_id_t) middle; + } + else if (compare > 0) + { + last = middle; + } + else + { + first = middle + 1; + } + } + + return LIT_MAGIC_STRING__COUNT; +} /* lit_is_utf8_string_magic */ + +/** + * Returns the magic string id of the argument string pair if it is available. + * + * @return id - if magic string id is found, + * LIT_MAGIC_STRING__COUNT - otherwise. + */ +lit_magic_string_id_t +lit_is_utf8_string_pair_magic (const lit_utf8_byte_t *string1_p, /**< first utf-8 string */ + lit_utf8_size_t string1_size, /**< first string size in bytes */ + const lit_utf8_byte_t *string2_p, /**< second utf-8 string */ + lit_utf8_size_t string2_size) /**< second string size in bytes */ +{ + lit_utf8_size_t total_string_size = string1_size + string2_size; + + if (total_string_size > lit_get_magic_string_size (LIT_NON_INTERNAL_MAGIC_STRING__COUNT - 1)) + { + return LIT_MAGIC_STRING__COUNT; + } + + /**< The string must be in this id range. */ + lit_utf8_size_t first = lit_get_magic_string_size_block_start (total_string_size); + lit_utf8_size_t last = lit_get_magic_string_size_block_start (total_string_size + 1); + + while (first < last) + { + lit_utf8_size_t middle = ((first + last) / 2); /**< mid point of search */ + const lit_utf8_byte_t *middle_string_p = lit_get_magic_string_utf8 ((lit_magic_string_id_t) middle); + + int compare = memcmp (middle_string_p, string1_p, string1_size); + + if (compare == 0) + { + compare = memcmp (middle_string_p + string1_size, string2_p, string2_size); + } + + if (compare == 0) + { + return (lit_magic_string_id_t) middle; + } + else if (compare > 0) + { + last = middle; + } + else + { + first = middle + 1; + } + } + + return LIT_MAGIC_STRING__COUNT; +} /* lit_is_utf8_string_pair_magic */ + +/** + * Returns the ex magic string id of the argument string if it is available. + * + * @return id - if magic string id is found, + * lit_get_magic_string_ex_count () - otherwise. + */ +lit_magic_string_ex_id_t +lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *string_p, /**< utf-8 string */ + lit_utf8_size_t string_size) /**< string size in bytes */ +{ + const uint32_t magic_string_ex_count = lit_get_magic_string_ex_count (); + + if (magic_string_ex_count == 0 || string_size > lit_get_magic_string_ex_size (magic_string_ex_count - 1)) + { + return (lit_magic_string_ex_id_t) magic_string_ex_count; + } + + lit_magic_string_ex_id_t first = 0; + lit_magic_string_ex_id_t last = (lit_magic_string_ex_id_t) magic_string_ex_count; + + while (first < last) + { + const lit_magic_string_ex_id_t middle = (first + last) / 2; + const lit_utf8_byte_t *ext_string_p = lit_get_magic_string_ex_utf8 (middle); + const lit_utf8_size_t ext_string_size = lit_get_magic_string_ex_size (middle); + + if (string_size == ext_string_size) + { + const int string_compare = memcmp (ext_string_p, string_p, string_size); + + if (string_compare == 0) + { + return middle; + } + else if (string_compare < 0) + { + first = middle + 1; + } + else + { + last = middle; + } + } + else if (string_size > ext_string_size) + { + first = middle + 1; + } + else + { + last = middle; + } + } + + return (lit_magic_string_ex_id_t) magic_string_ex_count; +} /* lit_is_ex_utf8_string_magic */ + +/** + * Returns the ex magic string id of the argument string pair if it is available. + * + * @return id - if magic string id is found, + * lit_get_magic_string_ex_count () - otherwise. + */ +lit_magic_string_ex_id_t +lit_is_ex_utf8_string_pair_magic (const lit_utf8_byte_t *string1_p, /**< first utf-8 string */ + lit_utf8_size_t string1_size, /**< first string size in bytes */ + const lit_utf8_byte_t *string2_p, /**< second utf-8 string */ + lit_utf8_size_t string2_size) /**< second string size in bytes */ +{ + const uint32_t magic_string_ex_count = lit_get_magic_string_ex_count (); + const lit_utf8_size_t total_string_size = string1_size + string2_size; + + if (magic_string_ex_count == 0 || total_string_size > lit_get_magic_string_ex_size (magic_string_ex_count - 1)) + { + return (lit_magic_string_ex_id_t) magic_string_ex_count; + } + + lit_magic_string_ex_id_t first = 0; + lit_magic_string_ex_id_t last = (lit_magic_string_ex_id_t) magic_string_ex_count; + + while (first < last) + { + const lit_magic_string_ex_id_t middle = (first + last) / 2; + const lit_utf8_byte_t *ext_string_p = lit_get_magic_string_ex_utf8 (middle); + const lit_utf8_size_t ext_string_size = lit_get_magic_string_ex_size (middle); + + if (total_string_size == ext_string_size) + { + int string_compare = memcmp (ext_string_p, string1_p, string1_size); + + if (string_compare == 0) + { + string_compare = memcmp (ext_string_p + string1_size, string2_p, string2_size); + } + + if (string_compare == 0) + { + return middle; + } + else if (string_compare < 0) + { + first = middle + 1; + } + else + { + last = middle; + } + } + else if (total_string_size > ext_string_size) + { + first = middle + 1; + } + else + { + last = middle; + } + } + + return (lit_magic_string_ex_id_t) magic_string_ex_count; +} /* lit_is_ex_utf8_string_pair_magic */ + +/** + * Copy magic string to buffer + * + * Warning: + * the routine requires that buffer size is enough + * + * @return pointer to the byte next to the last copied in the buffer + */ +lit_utf8_byte_t * +lit_copy_magic_string_to_buffer (lit_magic_string_id_t id, /**< magic string id */ + lit_utf8_byte_t *buffer_p, /**< destination buffer */ + lit_utf8_size_t buffer_size) /**< size of buffer */ +{ + const lit_utf8_byte_t *magic_string_bytes_p = lit_get_magic_string_utf8 (id); + lit_utf8_size_t magic_string_bytes_count = lit_get_magic_string_size (id); + + const lit_utf8_byte_t *str_iter_p = magic_string_bytes_p; + lit_utf8_byte_t *buf_iter_p = buffer_p; + + while (magic_string_bytes_count--) + { + *buf_iter_p++ = *str_iter_p++; + } + + return buf_iter_p; +} /* lit_copy_magic_string_to_buffer */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.h new file mode 100644 index 0000000..a079396 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.h @@ -0,0 +1,118 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIT_MAGIC_STRINGS_H +#define LIT_MAGIC_STRINGS_H + +#include "lit-globals.h" + +/** + * Identifiers of ECMA and implementation-defined magic string constants + */ +typedef enum +{ +/** @cond doxygen_suppress */ +#define LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE(size, id) +#define LIT_MAGIC_STRING_DEF(id, ascii_zt_string) id, +#include "lit-magic-strings.inc.h" +#undef LIT_MAGIC_STRING_DEF +#undef LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE + /** @endcond */ + LIT_NON_INTERNAL_MAGIC_STRING__COUNT, /**< number of non-internal magic strings */ + LIT_INTERNAL_MAGIC_API_INTERNAL = LIT_NON_INTERNAL_MAGIC_STRING__COUNT, /**< Used to add non-visible JS properties + * from the public API */ + LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX, /**< [[%Iterator%NextIndex]] property */ + LIT_INTERNAL_MAGIC_STRING_MAP_KEY, /**< Property key used when an object is a key in a map object */ + LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, /**< %ArrayProto_values% intrinsic routine */ + LIT_INTERNAL_MAGIC_STRING_TYPEDARRAY_PROTOTYPE_VALUES, /**< %TypedArray%.prototype values and [@@iterator] routine */ + LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES, /**< Set.prototype values, keys and [@@iterator] routines */ + LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES, /**< Map.prototype entries and [@@iterator] routines */ + /* List of well known symbols */ + LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well known symbol */ + LIT_GLOBAL_SYMBOL__FIRST = LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< first global symbol */ + LIT_GLOBAL_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well known symbol */ + LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well known symbol */ + LIT_GLOBAL_SYMBOL_ITERATOR, /**< @@iterator well known symbol */ + LIT_GLOBAL_SYMBOL_MATCH, /**< @@match well known symbol */ + LIT_GLOBAL_SYMBOL_REPLACE, /**< @@replace well known symbol */ + LIT_GLOBAL_SYMBOL_SEARCH, /**< @@search well known symbol */ + LIT_GLOBAL_SYMBOL_SPECIES, /**< @@species well known symbol */ + LIT_GLOBAL_SYMBOL_SPLIT, /**< @@split well known symbol */ + LIT_GLOBAL_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well known symbol */ + LIT_GLOBAL_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well known symbol */ + LIT_GLOBAL_SYMBOL_UNSCOPABLES, /**< @@unscopables well known symbol */ + LIT_GLOBAL_SYMBOL_MATCH_ALL, /**< @@matchAll well known symbol */ + LIT_GLOBAL_SYMBOL__LAST = LIT_GLOBAL_SYMBOL_MATCH_ALL, /**< last global symbol */ + + LIT_INTERNAL_MAGIC_STRING_DELETED, /**< special value for deleted properties */ + LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_INIT, /**< function which initializes properties */ + + LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< native pointer info associated with an object */ + LIT_INTERNAL_MAGIC_STRING_FIRST_DATA = LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< first index of special + * data properties */ + LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER_WITH_REFERENCES, /**< native pointer info associated with an object + * which contains references to other values */ + LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD, /**< dynamic environment record needed by class constructors */ + LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED, /**< computed class field name list */ + LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS, /**< internal collection for storing private elements */ + LIT_INTERNAL_MAGIC_STRING_CONTAINER_WEAK_REFS, /**< Weak references to the current container object */ + LIT_INTERNAL_MAGIC_STRING_WEAK_REFS, /**< Weak references to the current object */ + LIT_MAGIC_STRING__COUNT /**< number of magic strings */ +} lit_magic_string_id_t; + +/** + * Properties that are need to be ignored for opfunc_set_class_attributes + */ +#define LIT_INTERNAL_MAGIC_STRING_IGNORED(id) \ + ((id) >= LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED && (id) <= LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS) + +/** + * Checks whether the given id corresponds to a global symbol + */ +#define LIT_IS_GLOBAL_SYMBOL(id) ((id) >= LIT_GLOBAL_SYMBOL__FIRST && (id) <= LIT_GLOBAL_SYMBOL__LAST) + +/** + * Identifiers of implementation-defined external magic string constants + */ +typedef uint32_t lit_magic_string_ex_id_t; + +uint32_t lit_get_magic_string_ex_count (void); + +const lit_utf8_byte_t *lit_get_magic_string_utf8 (uint32_t id); +lit_utf8_size_t lit_get_magic_string_size (uint32_t id); + +const lit_utf8_byte_t *lit_get_magic_string_ex_utf8 (uint32_t id); +lit_utf8_size_t lit_get_magic_string_ex_size (uint32_t id); + +void lit_magic_strings_ex_set (const lit_utf8_byte_t *const *ex_str_items, + uint32_t count, + const lit_utf8_size_t *ex_str_sizes); + +lit_magic_string_id_t lit_is_utf8_string_magic (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); +lit_magic_string_id_t lit_is_utf8_string_pair_magic (const lit_utf8_byte_t *string1_p, + lit_utf8_size_t string1_size, + const lit_utf8_byte_t *string2_p, + lit_utf8_size_t string2_size); + +lit_magic_string_ex_id_t lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); +lit_magic_string_ex_id_t lit_is_ex_utf8_string_pair_magic (const lit_utf8_byte_t *string1_p, + lit_utf8_size_t string1_size, + const lit_utf8_byte_t *string2_p, + lit_utf8_size_t string2_size); + +lit_utf8_byte_t * +lit_copy_magic_string_to_buffer (lit_magic_string_id_t id, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); + +#endif /* !LIT_MAGIC_STRINGS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.inc.h new file mode 100644 index 0000000..dea77b6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-magic-strings.inc.h @@ -0,0 +1,942 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-strings.py script + * from lit-magic-strings.ini. Do not edit! */ + +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING__EMPTY, "") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SPACE_CHAR, " ") +#if JERRY_MODULE_SYSTEM +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASTERISK_CHAR, "*") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COMMA_CHAR, ",") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_E_U, "E") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LEFT_SQUARE_CHAR, "[") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR, "]") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PI_U, "PI") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_AT, "at") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS, "is") +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OF, "of") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_OR, "or") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LN2_U, "LN2") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAP_UL, "Map") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NAN, "NaN") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UL, "Set") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UTC_U, "UTC") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ABS, "abs") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_ATOMICS || JERRY_BUILTIN_CONTAINER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ADD, "add") +#endif /* JERRY_BUILTIN_ATOMICS \ +|| JERRY_BUILTIN_CONTAINER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ALL, "all") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_AND, "and") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ANY, "any") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COS, "cos") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EXP, "exp") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FOR, "for") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET, "get") +#if JERRY_BUILTIN_CONTAINER || JERRY_BUILTIN_PROXY || JERRY_BUILTIN_REFLECT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_HAS, "has") +#endif /* JERRY_BUILTIN_CONTAINER \ +|| JERRY_BUILTIN_PROXY \ +|| JERRY_BUILTIN_REFLECT */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOG, "log") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAP, "map") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAX, "max") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MIN, "min") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NOW, "now") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_ARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_POP, "pop") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_POW, "pow") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RAW, "raw") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET, "set") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SIN, "sin") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_SUB, "sub") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TAN, "tan") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_XOR, "xor") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP, "(?:)") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DATE_UL, "Date") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LN10_U, "LN10") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MATH_UL, "Math") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NULL_UL, "Null") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ACOS, "acos") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASIN, "asin") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATAN, "atan") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BIND, "bind") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CALL, "call") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CBRT, "cbrt") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CEIL, "ceil") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COSH, "cosh") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DONE, "done") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EVAL, "eval") +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EXEC, "exec") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FILL, "fill") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FIND, "find") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLAT, "flat") +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FROM, "from") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IMUL, "imul") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_JOIN, "join") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_KEYS, "keys") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_LOAD, "load") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOG2, "log2") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NAME, "name") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NEXT, "next") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NULL, "null") +#if JERRY_BUILTIN_ARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PUSH, "push") +#endif /* JERRY_BUILTIN_ARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RACE, "race") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SEAL, "seal") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SIGN, "sign") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SINH, "sinh") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_CONTAINER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SIZE, "size") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SOME, "some") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SORT, "sort") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SQRT, "sqrt") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TANH, "tanh") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TEST, "test") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_THEN, "then") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRIM, "trim") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRUE, "true") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_WAIT, "wait") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_UL, "Array") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ERROR_UL, "Error") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOG2E_U, "LOG2E") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_PROXY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROXY_UL, "Proxy") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SQRT2_U, "SQRT2") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ACOSH, "acosh") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_APPLY, "apply") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASINH, "asinh") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATAN2, "atan2") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATANH, "atanh") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CATCH, "catch") +#if JERRY_BUILTIN_CONTAINER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CLEAR, "clear") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CLZ32, "clz32") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_WEAKREF +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEREF, "deref") +#endif /* JERRY_BUILTIN_WEAKREF */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EVERY, "every") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EXPM1, "expm1") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FALSE, "false") +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLAGS, "flags") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLOOR, "floor") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_HYPOT, "hypot") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INDEX, "index") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INPUT, "input") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_NAN, "isNaN") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOG10, "log10") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOG1P, "log1p") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MATCH, "match") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PARSE, "parse") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_PROXY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROXY, "proxy") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ROUND, "round") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_ARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SHIFT, "shift") +#endif /* JERRY_BUILTIN_ARRAY */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_SHAREDARRAYBUFFER || JERRY_BUILTIN_STRING || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SLICE, "slice") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_SHAREDARRAYBUFFER \ +|| JERRY_BUILTIN_STRING \ +|| JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SPLIT, "split") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_STORE, "store") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_THROW, "throw") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRUNC, "trunc") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_VALUE, "value") +#if JERRY_PARSER && JERRY_SOURCE_NAME +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SOURCE_NAME_EVAL, "") +#endif /* JERRY_PARSER && JERRY_SOURCE_NAME */ +#if JERRY_BUILTIN_BIGINT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BIGINT_UL, "BigInt") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOG10E_U, "LOG10E") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_MODULE_SYSTEM +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MODULE_UL, "Module") +#endif /* JERRY_MODULE_SYSTEM */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NUMBER_UL, "Number") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OBJECT_UL, "Object") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REGEXP_UL, "RegExp") +#if JERRY_PARSER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SCRIPT_UL, "Script") +#endif /* JERRY_PARSER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STRING_UL, "String") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYMBOL_UL, "Symbol") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASSIGN, "assign") +#if JERRY_BUILTIN_BIGINT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BIGINT, "bigint") +#endif /* JERRY_BUILTIN_BIGINT */ +#if JERRY_BUILTIN_DATAVIEW || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BUFFER, "buffer") +#endif /* JERRY_BUILTIN_DATAVIEW \ +|| JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CALLEE, "callee") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CALLER, "caller") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CHAR_AT_UL, "charAt") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONCAT, "concat") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CREATE, "create") +#if JERRY_BUILTIN_CONTAINER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DELETE, "delete") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DOTALL, "dotAll") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ERRORS_UL, "errors") +#if JERRY_BUILTIN_ANNEXB +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ESCAPE, "escape") +#endif /* JERRY_BUILTIN_ANNEXB */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FILTER, "filter") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FREEZE, "freeze") +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FROUND, "fround") +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_DAY_UL, "getDay") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GLOBAL, "global") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_HAS_OWN_UL, "hasOwn") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_VIEW_UL, "isView") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_KEY_FOR, "keyFor") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LENGTH, "length") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_NOTIFY, "notify") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NUMBER, "number") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OBJECT, "object") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PAD_END, "padEnd") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RANDOM, "random") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REASON, "reason") +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REDUCE, "reduce") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REJECT, "reject") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REPEAT, "repeat") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RETURN, "return") +#if JERRY_BUILTIN_PROXY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REVOKE, "revoke") +#endif /* JERRY_BUILTIN_PROXY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SEARCH, "search") +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SOURCE, "source") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_ARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SPLICE, "splice") +#endif /* JERRY_BUILTIN_ARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STATUS, "status") +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STICKY, "sticky") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STRING, "string") +#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SUBSTR, "substr") +#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYMBOL, "symbol") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_JSON_UL, "toJSON") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_VALUES, "values") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_U, "Atomics") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BOOLEAN_UL, "Boolean") +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EPSILON_U, "EPSILON") +#endif /* JERRY_BUILTIN_NUMBER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROMISE_UL, "Promise") +#if JERRY_BUILTIN_REFLECT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REFLECT_UL, "Reflect") +#endif /* JERRY_BUILTIN_REFLECT */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SQRT1_2_U, "SQRT1_2") +#endif /* JERRY_BUILTIN_MATH */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYMBOL_DOT_UL, "Symbol.") +#if JERRY_BUILTIN_CONTAINER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_WEAKMAP_UL, "WeakMap") +#endif /* JERRY_BUILTIN_CONTAINER */ +#if JERRY_BUILTIN_WEAKREF +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_WEAKREF_UL, "WeakRef") +#endif /* JERRY_BUILTIN_WEAKREF */ +#if JERRY_BUILTIN_CONTAINER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_WEAKSET_UL, "WeakSet") +#endif /* JERRY_BUILTIN_CONTAINER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BOOLEAN, "boolean") +#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COMPILE, "compile") +#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEFAULT, "default") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENTRIES, "entries") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FINALLY, "finally") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLATMAP, "flatMap") +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_CONTAINER || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FOR_EACH_UL, "forEach") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_CONTAINER \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_DATE_UL, "getDate") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_INT8_UL, "getInt8") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_TIME_UL, "getTime") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_YEAR_UL, "getYear") +#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_STRING || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INDEX_OF_UL, "indexOf") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_STRING \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_ARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_ARRAY_UL, "isArray") +#endif /* JERRY_BUILTIN_ARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MESSAGE, "message") +#if JERRY_BUILTIN_PROXY || JERRY_BUILTIN_REFLECT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OWN_KEYS_UL, "ownKeys") +#endif /* JERRY_BUILTIN_PROXY \ +|| JERRY_BUILTIN_REFLECT */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REPLACE, "replace") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RESOLVE, "resolve") +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REVERSE, "reverse") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_DATE_UL, "setDate") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_INT8_UL, "setInt8") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_TIME_UL, "setTime") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_YEAR_UL, "setYear") +#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SPECIES, "species") +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_FIXED_UL, "toFixed") +#endif /* JERRY_BUILTIN_NUMBER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRIM_END, "trimEnd") +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNICODE, "unicode") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_ARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNSHIFT, "unshift") +#endif /* JERRY_BUILTIN_ARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_VALUE_OF_UL, "valueOf") +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DATAVIEW_UL, "DataView") +#endif /* JERRY_BUILTIN_DATAVIEW */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FUNCTION_UL, "Function") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INFINITY_UL, "Infinity") +#if JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_URI_ERROR_UL, "URIError") +#endif /* JERRY_BUILTIN_ERRORS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OBJECT_TO_STRING_UL, "[object ") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENDS_WITH, "endsWith") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_EXCHANGE, "exchange") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FUNCTION, "function") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_HOURS_UL, "getHours") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_INT16_UL, "getInt16") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_INT32_UL, "getInt32") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_MONTH_UL, "getMonth") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UINT8_UL, "getUint8") +#endif /* JERRY_BUILTIN_DATAVIEW */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INCLUDES, "includes") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_FINITE, "isFinite") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_FROZEN_UL, "isFrozen") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_SEALED_UL, "isSealed") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ITERATOR, "iterator") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MATCH_ALL, "matchAll") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PAD_START, "padStart") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PARSE_INT, "parseInt") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REJECTED, "rejected") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_HOURS_UL, "setHours") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_INT16_UL, "setInt16") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_INT32_UL, "setInt32") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_MONTH_UL, "setMonth") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UINT8_UL, "setUint8") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SUBARRAY, "subarray") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_STRING_UL, "toString") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRIM_LEFT, "trimLeft") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_ANNEXB +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNESCAPE, "unescape") +#endif /* JERRY_BUILTIN_ANNEXB */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_WRITABLE, "writable") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NEGATIVE_INFINITY_UL, "-Infinity") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARGUMENTS_UL, "Arguments") +#if JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EVAL_ERROR_UL, "EvalError") +#endif /* JERRY_BUILTIN_ERRORS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GENERATOR_UL, "Generator") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INT8_ARRAY_UL, "Int8Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAX_VALUE_U, "MAX_VALUE") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MIN_VALUE_U, "MIN_VALUE") +#endif /* JERRY_BUILTIN_NUMBER */ +#if JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TYPE_ERROR_UL, "TypeError") +#endif /* JERRY_BUILTIN_ERRORS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNDEFINED_UL, "Undefined") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING__PROTO__, "__proto__") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ANONYMOUS, "anonymous") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARGUMENTS, "arguments") +#if JERRY_BUILTIN_PROXY || JERRY_BUILTIN_REFLECT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONSTRUCT, "construct") +#endif /* JERRY_BUILTIN_PROXY \ +|| JERRY_BUILTIN_REFLECT */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DECODE_URI, "decodeURI") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENCODE_URI, "encodeURI") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FIND_INDEX, "findIndex") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FULFILLED, "fulfilled") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_DAY_UL, "getUTCDay") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UINT16_UL, "getUint16") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UINT32_UL, "getUint32") +#endif /* JERRY_BUILTIN_DATAVIEW */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_INTEGER, "isInteger") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LASTINDEX_UL, "lastIndex") +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MULTILINE, "multiline") +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROTOTYPE, "prototype") +#if JERRY_BUILTIN_PROXY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REVOCABLE, "revocable") +#endif /* JERRY_BUILTIN_PROXY */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UINT16_UL, "setUint16") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UINT32_UL, "setUint32") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SUBSTRING, "substring") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRIM_RIGHT, "trimRight") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRIM_START, "trimStart") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNDEFINED, "undefined") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INT16_ARRAY_UL, "Int16Array") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INT32_ARRAY_UL, "Int32Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RANGE_ERROR_UL, "RangeError") +#endif /* JERRY_BUILTIN_ERRORS */ +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TYPED_ARRAY_UL, "TypedArray") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT8_ARRAY_UL, "Uint8Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ALLSETTLED, "allSettled") +#if JERRY_BUILTIN_DATAVIEW || JERRY_BUILTIN_SHAREDARRAYBUFFER || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTE_LENGTH_UL, "byteLength") +#endif /* JERRY_BUILTIN_DATAVIEW \ +|| JERRY_BUILTIN_SHAREDARRAYBUFFER \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_DATAVIEW || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTE_OFFSET_UL, "byteOffset") +#endif /* JERRY_BUILTIN_DATAVIEW \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CHAR_CODE_AT_UL, "charCodeAt") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COPY_WITHIN, "copyWithin") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENUMERABLE, "enumerable") +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_FLOAT_32_UL, "getFloat32") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATAVIEW && JERRY_NUMBER_TYPE_FLOAT64 +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_FLOAT_64_UL, "getFloat64") +#endif /* JERRY_BUILTIN_DATAVIEW && JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_MINUTES_UL, "getMinutes") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_SECONDS_UL, "getSeconds") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_DATE_UL, "getUTCDate") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_GLOBAL_THIS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GLOBAL_THIS_UL, "globalThis") +#endif /* JERRY_BUILTIN_GLOBAL_THIS */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IGNORECASE_UL, "ignoreCase") +#endif /* JERRY_BUILTIN_REGEXP */ +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_ISLOCKFREE, "isLockFree") +#endif /* JERRY_BUILTIN_ATOMICS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PARSE_FLOAT, "parseFloat") +#if JERRY_BUILTIN_REGEXP && JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REPLACE_ALL, "replaceAll") +#endif /* JERRY_BUILTIN_REGEXP && JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_FLOAT_32_UL, "setFloat32") +#endif /* JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATAVIEW && JERRY_NUMBER_TYPE_FLOAT64 +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_FLOAT_64_UL, "setFloat64") +#endif /* JERRY_BUILTIN_DATAVIEW && JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_MINUTES_UL, "setMinutes") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_SECONDS_UL, "setSeconds") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_DATE_UL, "setUTCDate") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STARTS_WITH, "startsWith") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SOURCE_NAME_ANON, "") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_BUFFER_UL, "ArrayBuffer") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYNTAX_ERROR_UL, "SyntaxError") +#endif /* JERRY_BUILTIN_ERRORS */ +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT16_ARRAY_UL, "Uint16Array") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT32_ARRAY_UL, "Uint32Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CODE_POINT_AT, "codePointAt") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONSTRUCTOR, "constructor") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DESCRIPTION, "description") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OBJECT_FROM_ENTRIES, "fromEntries") +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_BIGINT64, "getBigInt64") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, "getFullYear") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_HOURS_UL, "getUTCHours") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_MONTH_UL, "getUTCMonth") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_HAS_INSTANCE, "hasInstance") +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_STRING || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, "lastIndexOf") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_STRING \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_ARRAY || JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, "reduceRight") +#endif /* JERRY_BUILTIN_ARRAY \ +|| JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_BIGINT64, "setBigInt64") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_FULL_YEAR_UL, "setFullYear") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_HOURS_UL, "setUTCHours") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_MONTH_UL, "setUTCMonth") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_GMT_STRING_UL, "toGMTString") +#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_ISO_STRING_UL, "toISOString") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOWER_CASE_UL, "toLowerCase") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_PRECISION_UL, "toPrecision") +#endif /* JERRY_BUILTIN_NUMBER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_PRIMITIVE, "toPrimitive") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_STRING_TAG, "toStringTag") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_UTC_STRING_UL, "toUTCString") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_UPPER_CASE_UL, "toUpperCase") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNSCOPABLES, "unscopables") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLOAT32_ARRAY_UL, "Float32Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64 +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLOAT64_ARRAY_UL, "Float64Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64 */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INVALID_DATE_UL, "Invalid Date") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAP_ITERATOR_UL, "Map Iterator") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_ITERATOR_UL, "Set Iterator") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONFIGURABLE, "configurable") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, "fromCharCode") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_BIGUINT64, "getBigUint64") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_EXTENSIBLE, "isExtensible") +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_BIGUINT64, "setBigUint64") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_DATAVIEW */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_DATE_STRING_UL, "toDateString") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_TIME_STRING_UL, "toTimeString") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASYNC_FUNCTION_UL, "AsyncFunction") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BIGINT64_ARRAY_UL, "BigInt64Array") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASYNC_ITERATOR, "asyncIterator") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FROM_CODE_POINT_UL, "fromCodePoint") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_MINUTES_UL, "getUTCMinutes") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_SECONDS_UL, "getUTCSeconds") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_PROTOTYPE_OF_UL, "isPrototypeOf") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_SAFE_INTEGER, "isSafeInteger") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOCALE_COMPARE_UL, "localeCompare") +#endif /* JERRY_BUILTIN_STRING */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_MINUTES_UL, "setUTCMinutes") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_SECONDS_UL, "setUTCSeconds") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_EXPONENTIAL_UL, "toExponential") +#endif /* JERRY_BUILTIN_NUMBER */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, "AggregateError") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_ITERATOR_UL, "Array Iterator") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASYNC_GENERATOR_UL, "AsyncGenerator") +#if JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BIGUINT64_ARRAY_UL, "BigUint64Array") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REFERENCE_ERROR_UL, "ReferenceError") +#endif /* JERRY_BUILTIN_ERRORS */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, "defineProperty") +#if JERRY_BUILTIN_PROXY || JERRY_BUILTIN_REFLECT +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DELETE_PROPERTY_UL, "deleteProperty") +#endif /* JERRY_BUILTIN_PROXY \ +|| JERRY_BUILTIN_REFLECT */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, "getPrototypeOf") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, "getUTCFullYear") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_HAS_OWN_PROPERTY_UL, "hasOwnProperty") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, "setPrototypeOf") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, "setUTCFullYear") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, "toLocaleString") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STRING_ITERATOR_UL, "String Iterator") +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ATOMICS_COMPAREEXCHANGE, "compareExchange") +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_MILLISECONDS_UL, "getMilliseconds") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_MILLISECONDS_UL, "setMilliseconds") +#endif /* JERRY_BUILTIN_DATE */ +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAX_SAFE_INTEGER_U, "MAX_SAFE_INTEGER") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MIN_SAFE_INTEGER_U, "MIN_SAFE_INTEGER") +#endif /* JERRY_BUILTIN_NUMBER */ +#if JERRY_BUILTIN_ANNEXB +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEFINE_GETTER, "__defineGetter__") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEFINE_SETTER, "__defineSetter__") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOOKUP_GETTER, "__lookupGetter__") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LOOKUP_SETTER, "__lookupSetter__") +#endif /* JERRY_BUILTIN_ANNEXB */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL, "defineProperties") +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U, "BYTES_PER_ELEMENT") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL, "GeneratorFunction") +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NEGATIVE_INFINITY_U, "NEGATIVE_INFINITY") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_POSITIVE_INFINITY_U, "POSITIVE_INFINITY") +#endif /* JERRY_BUILTIN_NUMBER */ +#if JERRY_BUILTIN_SHAREDARRAYBUFFER +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, "SharedArrayBuffer") +#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL, "Uint8ClampedArray") +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, "getTimezoneOffset") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, "preventExtensions") +#if JERRY_BUILTIN_STRING +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, "toLocaleLowerCase") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, "toLocaleUpperCase") +#endif /* JERRY_BUILTIN_STRING */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DECODE_URI_COMPONENT, "decodeURIComponent") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENCODE_URI_COMPONENT, "encodeURIComponent") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_MILLISECONDS_UL, "getUTCMilliseconds") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE, "isConcatSpreadable") +#if JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_MILLISECONDS_UL, "setUTCMilliseconds") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOCALE_DATE_STRING_UL, "toLocaleDateString") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOCALE_TIME_STRING_UL, "toLocaleTimeString") +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, "getOwnPropertyNames") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, "propertyIsEnumerable") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_OWN_PROPERTY_SYMBOLS_UL, "getOwnPropertySymbols") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASYNC_GENERATOR_FUNCTION_UL, "AsyncGeneratorFunction") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REGEXP_STRING_ITERATOR_UL, "RegExp String Iterator") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, "getOwnPropertyDescriptor") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTORS_UL, "getOwnPropertyDescriptors") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FUNCTION_TO_STRING_NATIVE, "function () { [native code] }") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FUNCTION_TO_STRING_ECMA, "function () { /* ecmascript */ }") + +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (0, LIT_MAGIC_STRING__EMPTY) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (1, LIT_MAGIC_STRING_SPACE_CHAR) +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (2, LIT_MAGIC_STRING_PI_U) +#else /* !(JERRY_BUILTIN_MATH) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (2, LIT_MAGIC_STRING_AT) +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (3, LIT_MAGIC_STRING_LN2_U) +#else /* !(JERRY_BUILTIN_MATH) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (3, LIT_MAGIC_STRING_MAP_UL) +#endif /* JERRY_BUILTIN_MATH */ +#if JERRY_BUILTIN_REGEXP +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (4, LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP) +#else /* !(JERRY_BUILTIN_REGEXP) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (4, LIT_MAGIC_STRING_DATE_UL) +#endif /* JERRY_BUILTIN_REGEXP */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (5, LIT_MAGIC_STRING_ARRAY_UL) +#if JERRY_PARSER && JERRY_SOURCE_NAME +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_SOURCE_NAME_EVAL) +#elif JERRY_BUILTIN_BIGINT +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_BIGINT_UL) +#elif JERRY_BUILTIN_MATH +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_LOG10E_U) +#elif JERRY_MODULE_SYSTEM +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_MODULE_UL) +#else /* !(JERRY_MODULE_SYSTEM) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_NUMBER_UL) +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_BUILTIN_ATOMICS +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (7, LIT_MAGIC_STRING_ATOMICS_U) +#else /* !(JERRY_BUILTIN_ATOMICS) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (7, LIT_MAGIC_STRING_BOOLEAN_UL) +#endif /* JERRY_BUILTIN_ATOMICS */ +#if JERRY_BUILTIN_DATAVIEW +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (8, LIT_MAGIC_STRING_DATAVIEW_UL) +#else /* !(JERRY_BUILTIN_DATAVIEW) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (8, LIT_MAGIC_STRING_FUNCTION_UL) +#endif /* JERRY_BUILTIN_DATAVIEW */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (9, LIT_MAGIC_STRING_NEGATIVE_INFINITY_UL) +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_INT16_ARRAY_UL) +#elif JERRY_BUILTIN_ERRORS +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_RANGE_ERROR_UL) +#elif JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_TYPED_ARRAY_UL) +#else /* !(JERRY_BUILTIN_TYPEDARRAY) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_ALLSETTLED) +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_SOURCE_NAME_ANON) +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_FLOAT32_ARRAY_UL) +#elif JERRY_BUILTIN_TYPEDARRAY && JERRY_NUMBER_TYPE_FLOAT64 +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_FLOAT64_ARRAY_UL) +#elif JERRY_BUILTIN_DATE +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_INVALID_DATE_UL) +#else /* !(JERRY_BUILTIN_DATE) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_MAP_ITERATOR_UL) +#endif /* JERRY_BUILTIN_DATE */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (13, LIT_MAGIC_STRING_ASYNC_FUNCTION_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (14, LIT_MAGIC_STRING_AGGREGATE_ERROR_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (15, LIT_MAGIC_STRING_STRING_ITERATOR_UL) +#if JERRY_BUILTIN_NUMBER +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (16, LIT_MAGIC_STRING_MAX_SAFE_INTEGER_U) +#elif JERRY_BUILTIN_ANNEXB +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (16, LIT_MAGIC_STRING_DEFINE_GETTER) +#else /* !(JERRY_BUILTIN_ANNEXB) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (16, LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL) +#endif /* JERRY_BUILTIN_ANNEXB */ +#if JERRY_BUILTIN_TYPEDARRAY +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U) +#else /* !(JERRY_BUILTIN_TYPEDARRAY) */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL) +#endif /* JERRY_BUILTIN_TYPEDARRAY */ +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (18, LIT_MAGIC_STRING_DECODE_URI_COMPONENT) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (19, LIT_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (20, LIT_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (21, LIT_MAGIC_STRING_GET_OWN_PROPERTY_SYMBOLS_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (22, LIT_MAGIC_STRING_ASYNC_GENERATOR_FUNCTION_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (23, LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (24, LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (25, LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTORS_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (26, LIT_MAGIC_STRING_FUNCTION_TO_STRING_NATIVE) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (27, LIT_MAGIC_STRING_FUNCTION_TO_STRING_NATIVE) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (28, LIT_MAGIC_STRING_FUNCTION_TO_STRING_NATIVE) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (29, LIT_MAGIC_STRING_FUNCTION_TO_STRING_NATIVE) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (30, LIT_MAGIC_STRING_FUNCTION_TO_STRING_ECMA) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (31, LIT_MAGIC_STRING_FUNCTION_TO_STRING_ECMA) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (32, LIT_MAGIC_STRING_FUNCTION_TO_STRING_ECMA) diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-strings.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-strings.cpp new file mode 100644 index 0000000..22ab4dd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-strings.cpp @@ -0,0 +1,934 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lit-strings.h" + +#include "jrt-libc-includes.h" + +#define LIT_UTF8_SURROGATE_MARKER 0xed /**< utf8 surrogate marker */ +#define LIT_UTF8_HIGH_SURROGATE_MIN 0xa0 /**< utf8 high surrogate minimum */ +#define LIT_UTF8_HIGH_SURROGATE_MAX 0xaf /**< utf8 high surrogate maximum */ +#define LIT_UTF8_LOW_SURROGATE_MIN 0xb0 /**< utf8 low surrogate minimum */ +#define LIT_UTF8_LOW_SURROGATE_MAX 0xbf /**< utf8 low surrogate maximum */ +#define LIT_UTF8_1_BYTE_MAX 0xf4 /**< utf8 one byte max */ +#define LIT_UTF8_2_BYTE_MAX 0x8f /**< utf8 two byte max */ +#define LIT_UTF8_VALID_TWO_BYTE_START 0xc2 /**< utf8 two byte start */ + +/** + * Validate utf-8 string + * + * NOTE: + * Isolated surrogates are allowed. + * + * @return true if utf-8 string is well-formed + * false otherwise + */ +bool +lit_is_valid_utf8_string (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */ + lit_utf8_size_t buf_size, /**< string size */ + bool is_strict) /**< true if surrogate pairs are not allowed */ +{ + const unsigned char *end = buf_size + utf8_buf_p; + + const unsigned char *idx = (const unsigned char *) utf8_buf_p; + + while (idx < end) + { + const uint8_t first_byte = *idx++; + + if (first_byte < LIT_UTF8_EXTRA_BYTE_MARKER) + { + continue; + } + + if (first_byte < LIT_UTF8_VALID_TWO_BYTE_START || idx >= end) + { + return false; + } + + const uint8_t second_byte = *idx++; + + if ((second_byte & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER) + { + return false; + } + + if (first_byte < LIT_UTF8_3_BYTE_MARKER) + { + continue; + } + + if (idx >= end || (*idx++ & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER) + { + return false; + } + + if (first_byte < LIT_UTF8_4_BYTE_MARKER) + { + if (first_byte == LIT_UTF8_3_BYTE_MARKER && (second_byte & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER) + { + return false; + } + + if (is_strict && first_byte == LIT_UTF8_SURROGATE_MARKER && second_byte >= LIT_UTF8_HIGH_SURROGATE_MIN + && second_byte <= LIT_UTF8_HIGH_SURROGATE_MAX && idx + 3 <= end && idx[0] == LIT_UTF8_SURROGATE_MARKER + && idx[1] >= LIT_UTF8_LOW_SURROGATE_MIN && idx[1] <= LIT_UTF8_LOW_SURROGATE_MAX) + { + return false; + } + continue; + } + + if (idx >= end || first_byte > LIT_UTF8_1_BYTE_MAX + || (first_byte == LIT_UTF8_4_BYTE_MARKER && second_byte <= LIT_UTF8_EXTRA_BYTE_MARKER) + || (first_byte == LIT_UTF8_1_BYTE_MAX && second_byte > LIT_UTF8_2_BYTE_MAX) + || (*idx++ & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER) + { + return false; + } + } + + return true; +} /* lit_is_valid_utf8_string */ + +/** + * Validate cesu-8 string + * + * @return true if cesu-8 string is well-formed + * false otherwise + */ +bool +lit_is_valid_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, /**< cesu-8 string */ + lit_utf8_size_t buf_size) /**< string size */ +{ + lit_utf8_size_t idx = 0; + + while (idx < buf_size) + { + lit_utf8_byte_t c = cesu8_buf_p[idx++]; + if ((c & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER) + { + continue; + } + + lit_code_point_t code_point = 0; + lit_code_point_t min_code_point = 0; + lit_utf8_size_t extra_bytes_count; + if ((c & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER) + { + extra_bytes_count = 1; + min_code_point = LIT_UTF8_2_BYTE_CODE_POINT_MIN; + code_point = ((uint32_t) (c & LIT_UTF8_LAST_5_BITS_MASK)); + } + else if ((c & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER) + { + extra_bytes_count = 2; + min_code_point = LIT_UTF8_3_BYTE_CODE_POINT_MIN; + code_point = ((uint32_t) (c & LIT_UTF8_LAST_4_BITS_MASK)); + } + else + { + return false; + } + + if (idx + extra_bytes_count > buf_size) + { + /* cesu-8 string breaks in the middle */ + return false; + } + + for (lit_utf8_size_t offset = 0; offset < extra_bytes_count; ++offset) + { + c = cesu8_buf_p[idx + offset]; + if ((c & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER) + { + /* invalid continuation byte */ + return false; + } + code_point <<= LIT_UTF8_BITS_IN_EXTRA_BYTES; + code_point |= (c & LIT_UTF8_LAST_6_BITS_MASK); + } + + if (code_point < min_code_point) + { + /* cesu-8 string doesn't encode valid unicode code point */ + return false; + } + + idx += extra_bytes_count; + } + + return true; +} /* lit_is_valid_cesu8_string */ + +/** + * Check if the code point is UTF-16 low surrogate + * + * @return true / false + */ +bool +lit_is_code_point_utf16_low_surrogate (lit_code_point_t code_point) /**< code point */ +{ + return LIT_UTF16_LOW_SURROGATE_MIN <= code_point && code_point <= LIT_UTF16_LOW_SURROGATE_MAX; +} /* lit_is_code_point_utf16_low_surrogate */ + +/** + * Check if the code point is UTF-16 high surrogate + * + * @return true / false + */ +bool +lit_is_code_point_utf16_high_surrogate (lit_code_point_t code_point) /**< code point */ +{ + return LIT_UTF16_HIGH_SURROGATE_MIN <= code_point && code_point <= LIT_UTF16_HIGH_SURROGATE_MAX; +} /* lit_is_code_point_utf16_high_surrogate */ + +/** + * Represents code point (>0xFFFF) as surrogate pair and returns its lower part + * + * @return lower code_unit of the surrogate pair + */ +static ecma_char_t +convert_code_point_to_low_surrogate (lit_code_point_t code_point) /**< code point, should be > 0xFFFF */ +{ + JERRY_ASSERT (code_point > LIT_UTF16_CODE_UNIT_MAX); + + ecma_char_t code_unit_bits; + code_unit_bits = (ecma_char_t) (code_point & LIT_UTF16_LAST_10_BITS_MASK); + + return (ecma_char_t) (LIT_UTF16_LOW_SURROGATE_MARKER | code_unit_bits); +} /* convert_code_point_to_low_surrogate */ + +/** + * Represents code point (>0xFFFF) as surrogate pair and returns its higher part + * + * @return higher code_unit of the surrogate pair + */ +static ecma_char_t +convert_code_point_to_high_surrogate (lit_code_point_t code_point) /**< code point, should be > 0xFFFF */ +{ + JERRY_ASSERT (code_point > LIT_UTF16_CODE_UNIT_MAX); + JERRY_ASSERT (code_point <= LIT_UNICODE_CODE_POINT_MAX); + + ecma_char_t code_unit_bits; + code_unit_bits = (ecma_char_t) ((code_point - LIT_UTF16_FIRST_SURROGATE_CODE_POINT) >> LIT_UTF16_BITS_IN_SURROGATE); + + return (LIT_UTF16_HIGH_SURROGATE_MARKER | code_unit_bits); +} /* convert_code_point_to_high_surrogate */ + +/** + * UTF16 Encoding method for a code point + * + * See also: + * ECMA-262 v6, 10.1.1 + * + * @return uint8_t, the number of returning code points + */ +uint8_t +lit_utf16_encode_code_point (lit_code_point_t cp, /**< the code point we encode */ + ecma_char_t *cu_p) /**< result of the encoding */ +{ + if (cp <= LIT_UTF16_CODE_UNIT_MAX) + { + cu_p[0] = (ecma_char_t) cp; + return 1; + } + + cu_p[0] = convert_code_point_to_high_surrogate (cp); + cu_p[1] = convert_code_point_to_low_surrogate (cp); + return 2; +} /* lit_utf16_encode_code_point */ + +/** + * Calculate size of a zero-terminated utf-8 string + * + * NOTE: + * - string cannot be NULL + * - string should not contain zero characters in the middle + * + * @return size of a string + */ +lit_utf8_size_t +lit_zt_utf8_string_size (const lit_utf8_byte_t *utf8_str_p) /**< zero-terminated utf-8 string */ +{ + JERRY_ASSERT (utf8_str_p != NULL); + return (lit_utf8_size_t) strlen ((const char *) utf8_str_p); +} /* lit_zt_utf8_string_size */ + +/** + * Calculate length of a cesu-8 encoded string + * + * @return UTF-16 code units count + */ +lit_utf8_size_t +lit_utf8_string_length (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */ + lit_utf8_size_t utf8_buf_size) /**< string size */ +{ + lit_utf8_size_t length = 0; + lit_utf8_size_t size = 0; + + while (size < utf8_buf_size) + { + size += lit_get_unicode_char_size_by_utf8_first_byte (*(utf8_buf_p + size)); + length++; + } + + JERRY_ASSERT (size == utf8_buf_size); + + return length; +} /* lit_utf8_string_length */ + +/** + * Calculate the required size of an utf-8 encoded string from cesu-8 encoded string + * + * @return size of an utf-8 encoded string + */ +lit_utf8_size_t +lit_get_utf8_size_of_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, /**< cesu-8 string */ + lit_utf8_size_t cesu8_buf_size) /**< string size */ +{ + lit_utf8_size_t offset = 0; + lit_utf8_size_t utf8_buf_size = cesu8_buf_size; + ecma_char_t prev_ch = 0; + + while (offset < cesu8_buf_size) + { + ecma_char_t ch; + offset += lit_read_code_unit_from_cesu8 (cesu8_buf_p + offset, &ch); + + if (lit_is_code_point_utf16_low_surrogate (ch) && lit_is_code_point_utf16_high_surrogate (prev_ch)) + { + utf8_buf_size -= 2; + } + + prev_ch = ch; + } + + JERRY_ASSERT (offset == cesu8_buf_size); + + return utf8_buf_size; +} /* lit_get_utf8_size_of_cesu8_string */ + +/** + * Calculate length of an utf-8 encoded string from cesu-8 encoded string + * + * @return length of an utf-8 encoded string + */ +lit_utf8_size_t +lit_get_utf8_length_of_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, /**< cesu-8 string */ + lit_utf8_size_t cesu8_buf_size) /**< string size */ +{ + lit_utf8_size_t offset = 0; + lit_utf8_size_t utf8_length = 0; + ecma_char_t prev_ch = 0; + + while (offset < cesu8_buf_size) + { + ecma_char_t ch; + offset += lit_read_code_unit_from_cesu8 (cesu8_buf_p + offset, &ch); + + if (!lit_is_code_point_utf16_low_surrogate (ch) || !lit_is_code_point_utf16_high_surrogate (prev_ch)) + { + utf8_length++; + } + + prev_ch = ch; + } + + JERRY_ASSERT (offset == cesu8_buf_size); + + return utf8_length; +} /* lit_get_utf8_length_of_cesu8_string */ + +/** + * Decodes a unicode code point from non-empty utf-8-encoded buffer + * + * @return number of bytes occupied by code point in the string + */ +lit_utf8_size_t +lit_read_code_point_from_utf8 (const lit_utf8_byte_t *buf_p, /**< buffer with characters */ + lit_utf8_size_t buf_size, /**< size of the buffer in bytes */ + lit_code_point_t *code_point) /**< [out] code point */ +{ + JERRY_ASSERT (buf_p && buf_size); + + lit_utf8_byte_t c = buf_p[0]; + if ((c & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER) + { + *code_point = (lit_code_point_t) (c & LIT_UTF8_LAST_7_BITS_MASK); + return 1; + } + + lit_code_point_t ret = LIT_UNICODE_CODE_POINT_NULL; + lit_utf8_size_t bytes_count = 0; + if ((c & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER) + { + bytes_count = 2; + ret = ((lit_code_point_t) (c & LIT_UTF8_LAST_5_BITS_MASK)); + } + else if ((c & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER) + { + bytes_count = 3; + ret = ((lit_code_point_t) (c & LIT_UTF8_LAST_4_BITS_MASK)); + } + else + { + JERRY_ASSERT ((c & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER); + bytes_count = 4; + ret = ((lit_code_point_t) (c & LIT_UTF8_LAST_3_BITS_MASK)); + } + + JERRY_ASSERT (buf_size >= bytes_count); + + for (uint32_t i = 1; i < bytes_count; ++i) + { + ret <<= LIT_UTF8_BITS_IN_EXTRA_BYTES; + ret |= (buf_p[i] & LIT_UTF8_LAST_6_BITS_MASK); + } + + *code_point = ret; + return bytes_count; +} /* lit_read_code_point_from_utf8 */ + +/** + * Decodes a unicode code unit from non-empty cesu-8-encoded buffer + * + * @return number of bytes occupied by code point in the string + */ +lit_utf8_size_t +lit_read_code_unit_from_cesu8 (const lit_utf8_byte_t *buf_p, /**< buffer with characters */ + ecma_char_t *code_unit) /**< [out] code unit */ +{ + JERRY_ASSERT (buf_p); + + lit_utf8_byte_t c = buf_p[0]; + if ((c & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER) + { + *code_unit = (ecma_char_t) (c & LIT_UTF8_LAST_7_BITS_MASK); + return 1; + } + + lit_code_point_t ret = LIT_UNICODE_CODE_POINT_NULL; + lit_utf8_size_t bytes_count; + + if ((c & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER) + { + bytes_count = 2; + ret = ((lit_code_point_t) (c & LIT_UTF8_LAST_5_BITS_MASK)); + } + else + { + JERRY_ASSERT ((c & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER); + bytes_count = 3; + ret = ((lit_code_point_t) (c & LIT_UTF8_LAST_4_BITS_MASK)); + } + + for (uint32_t i = 1; i < bytes_count; ++i) + { + ret <<= LIT_UTF8_BITS_IN_EXTRA_BYTES; + ret |= (buf_p[i] & LIT_UTF8_LAST_6_BITS_MASK); + } + + JERRY_ASSERT (ret <= LIT_UTF16_CODE_UNIT_MAX); + *code_unit = (ecma_char_t) ret; + return bytes_count; +} /* lit_read_code_unit_from_cesu8 */ + +/** + * Decodes a unicode code point from non-empty cesu-8-encoded buffer + * + * @return number of bytes occupied by code point in the string + */ +lit_utf8_size_t +lit_read_code_point_from_cesu8 (const lit_utf8_byte_t *buf_p, /**< buffer with characters */ + const lit_utf8_byte_t *buf_end_p, /**< buffer end */ + lit_code_point_t *code_point) /**< [out] code point */ +{ + ecma_char_t code_unit; + lit_utf8_size_t size = lit_read_code_unit_from_cesu8 (buf_p, &code_unit); + + JERRY_ASSERT (buf_p + size <= buf_end_p); + + if (lit_is_code_point_utf16_high_surrogate (code_unit)) + { + buf_p += size; + + if (buf_p < buf_end_p) + { + ecma_char_t next_code_unit; + lit_utf8_size_t next_size = lit_read_code_unit_from_cesu8 (buf_p, &next_code_unit); + + if (lit_is_code_point_utf16_low_surrogate (next_code_unit)) + { + JERRY_ASSERT (buf_p + next_size <= buf_end_p); + + *code_point = lit_convert_surrogate_pair_to_code_point (code_unit, next_code_unit); + return size + next_size; + } + } + } + + *code_point = code_unit; + return size; +} /* lit_read_code_point_from_cesu8 */ + +/** + * Decodes a unicode code unit from non-empty cesu-8-encoded buffer + * + * @return number of bytes occupied by code point in the string + */ +lit_utf8_size_t +lit_read_prev_code_unit_from_utf8 (const lit_utf8_byte_t *buf_p, /**< buffer with characters */ + ecma_char_t *code_point) /**< [out] code point */ +{ + JERRY_ASSERT (buf_p); + + lit_utf8_decr (&buf_p); + return lit_read_code_unit_from_cesu8 (buf_p, code_point); +} /* lit_read_prev_code_unit_from_utf8 */ + +/** + * Decodes a unicode code unit from non-empty cesu-8-encoded buffer + * + * @return next code unit + */ +ecma_char_t +lit_cesu8_read_next (const lit_utf8_byte_t **buf_p) /**< [in,out] buffer with characters */ +{ + JERRY_ASSERT (*buf_p); + ecma_char_t ch; + + *buf_p += lit_read_code_unit_from_cesu8 (*buf_p, &ch); + + return ch; +} /* lit_cesu8_read_next */ + +/** + * Decodes a unicode code unit from non-empty cesu-8-encoded buffer + * + * @return previous code unit + */ +ecma_char_t +lit_cesu8_read_prev (const lit_utf8_byte_t **buf_p) /**< [in,out] buffer with characters */ +{ + JERRY_ASSERT (*buf_p); + ecma_char_t ch; + + lit_utf8_decr (buf_p); + lit_read_code_unit_from_cesu8 (*buf_p, &ch); + + return ch; +} /* lit_cesu8_read_prev */ + +/** + * Decodes a unicode code unit from non-empty cesu-8-encoded buffer + * + * @return next code unit + */ +ecma_char_t JERRY_ATTR_NOINLINE +lit_cesu8_peek_next (const lit_utf8_byte_t *buf_p) /**< [in,out] buffer with characters */ +{ + JERRY_ASSERT (buf_p != NULL); + ecma_char_t ch; + + lit_read_code_unit_from_cesu8 (buf_p, &ch); + + return ch; +} /* lit_cesu8_peek_next */ + +/** + * Decodes a unicode code unit from non-empty cesu-8-encoded buffer + * + * @return previous code unit + */ +ecma_char_t JERRY_ATTR_NOINLINE +lit_cesu8_peek_prev (const lit_utf8_byte_t *buf_p) /**< [in,out] buffer with characters */ +{ + JERRY_ASSERT (buf_p != NULL); + ecma_char_t ch; + + lit_read_prev_code_unit_from_utf8 (buf_p, &ch); + + return ch; +} /* lit_cesu8_peek_prev */ + +/** + * Increase cesu-8 encoded string pointer by one code unit. + */ +void +lit_utf8_incr (const lit_utf8_byte_t **buf_p) /**< [in,out] buffer with characters */ +{ + JERRY_ASSERT (*buf_p); + + *buf_p += lit_get_unicode_char_size_by_utf8_first_byte (**buf_p); +} /* lit_utf8_incr */ + +/** + * Decrease cesu-8 encoded string pointer by one code unit. + */ +void +lit_utf8_decr (const lit_utf8_byte_t **buf_p) /**< [in,out] buffer with characters */ +{ + JERRY_ASSERT (*buf_p); + const lit_utf8_byte_t *current_p = *buf_p; + + do + { + current_p--; + } while ((*current_p & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER); + + *buf_p = current_p; +} /* lit_utf8_decr */ + +/** + * Calc hash using the specified hash_basis. + * + * NOTE: + * This is implementation of FNV-1a hash function, which is released into public domain. + * Constants used, are carefully picked primes by the authors. + * More info: http://www.isthe.com/chongo/tech/comp/fnv/ + * + * @return ecma-string's hash + */ +lit_string_hash_t +lit_utf8_string_hash_combine (lit_string_hash_t hash_basis, /**< hash to be combined with */ + const lit_utf8_byte_t *utf8_buf_p, /**< characters buffer */ + lit_utf8_size_t utf8_buf_size) /**< number of characters in the buffer */ +{ + JERRY_ASSERT (utf8_buf_p != NULL || utf8_buf_size == 0); + + uint32_t hash = hash_basis; + + for (uint32_t i = 0; i < utf8_buf_size; i++) + { + /* 16777619 is 32 bit FNV_prime = 2^24 + 2^8 + 0x93 = 16777619 */ + hash = (hash ^ utf8_buf_p[i]) * 16777619; + } + + return (lit_string_hash_t) hash; +} /* lit_utf8_string_hash_combine */ + +/** + * Calculate hash from the buffer. + * + * @return ecma-string's hash + */ +lit_string_hash_t +lit_utf8_string_calc_hash (const lit_utf8_byte_t *utf8_buf_p, /**< characters buffer */ + lit_utf8_size_t utf8_buf_size) /**< number of characters in the buffer */ +{ + JERRY_ASSERT (utf8_buf_p != NULL || utf8_buf_size == 0); + + /* 32 bit offset_basis for FNV = 2166136261 */ + return lit_utf8_string_hash_combine ((lit_string_hash_t) 2166136261, utf8_buf_p, utf8_buf_size); +} /* lit_utf8_string_calc_hash */ + +/** + * Return code unit at the specified position in string + * + * NOTE: + * code_unit_offset should be less than string's length + * + * @return code unit value + */ +ecma_char_t +lit_utf8_string_code_unit_at (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */ + lit_utf8_size_t utf8_buf_size, /**< string size in bytes */ + lit_utf8_size_t code_unit_offset) /**< offset of a code_unit */ +{ + lit_utf8_byte_t *current_p = (lit_utf8_byte_t *) utf8_buf_p; + ecma_char_t code_unit; + + do + { + JERRY_ASSERT (current_p < utf8_buf_p + utf8_buf_size); + current_p += lit_read_code_unit_from_cesu8 (current_p, &code_unit); + } while (code_unit_offset--); + + return code_unit; +} /* lit_utf8_string_code_unit_at */ + +/** + * Get CESU-8 encoded size of character + * + * @return number of bytes occupied in CESU-8 + */ +lit_utf8_size_t +lit_get_unicode_char_size_by_utf8_first_byte (const lit_utf8_byte_t first_byte) /**< buffer with characters */ +{ + if ((first_byte & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER) + { + return 1; + } + else if ((first_byte & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER) + { + return 2; + } + else + { + JERRY_ASSERT ((first_byte & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER); + return 3; + } +} /* lit_get_unicode_char_size_by_utf8_first_byte */ + +/** + * Convert code unit to cesu-8 representation + * + * @return byte count required to represent the code unit + */ +lit_utf8_size_t +lit_code_unit_to_utf8 (ecma_char_t code_unit, /**< code unit */ + lit_utf8_byte_t *buf_p) /**< buffer where to store the result and its size + * should be at least LIT_UTF8_MAX_BYTES_IN_CODE_UNIT */ +{ + if (code_unit <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + buf_p[0] = (lit_utf8_byte_t) code_unit; + return 1; + } + else if (code_unit <= LIT_UTF8_2_BYTE_CODE_POINT_MAX) + { + uint32_t code_unit_bits = code_unit; + lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_unit_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_unit_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_unit_bits & LIT_UTF8_LAST_5_BITS_MASK); + JERRY_ASSERT (first_byte_bits == code_unit_bits); + + buf_p[0] = LIT_UTF8_2_BYTE_MARKER | first_byte_bits; + buf_p[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits; + return 2; + } + else + { + uint32_t code_unit_bits = code_unit; + lit_utf8_byte_t third_byte_bits = (lit_utf8_byte_t) (code_unit_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_unit_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_unit_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_unit_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_unit_bits & LIT_UTF8_LAST_4_BITS_MASK); + JERRY_ASSERT (first_byte_bits == code_unit_bits); + + buf_p[0] = LIT_UTF8_3_BYTE_MARKER | first_byte_bits; + buf_p[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits; + buf_p[2] = LIT_UTF8_EXTRA_BYTE_MARKER | third_byte_bits; + return 3; + } +} /* lit_code_unit_to_utf8 */ + +/** + * Convert code point to cesu-8 representation + * + * @return byte count required to represent the code point + */ +lit_utf8_size_t +lit_code_point_to_cesu8 (lit_code_point_t code_point, /**< code point */ + lit_utf8_byte_t *buf) /**< buffer where to store the result, + * its size should be at least 6 bytes */ +{ + if (code_point <= LIT_UTF16_CODE_UNIT_MAX) + { + return lit_code_unit_to_utf8 ((ecma_char_t) code_point, buf); + } + else + { + lit_utf8_size_t offset = lit_code_unit_to_utf8 (convert_code_point_to_high_surrogate (code_point), buf); + offset += lit_code_unit_to_utf8 (convert_code_point_to_low_surrogate (code_point), buf + offset); + return offset; + } +} /* lit_code_point_to_cesu8 */ + +/** + * Convert code point to utf-8 representation + * + * @return byte count required to represent the code point + */ +lit_utf8_size_t +lit_code_point_to_utf8 (lit_code_point_t code_point, /**< code point */ + lit_utf8_byte_t *buf) /**< buffer where to store the result, + * its size should be at least 4 bytes */ +{ + if (code_point <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + buf[0] = (lit_utf8_byte_t) code_point; + return 1; + } + else if (code_point <= LIT_UTF8_2_BYTE_CODE_POINT_MAX) + { + uint32_t code_point_bits = code_point; + lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_5_BITS_MASK); + JERRY_ASSERT (first_byte_bits == code_point_bits); + + buf[0] = LIT_UTF8_2_BYTE_MARKER | first_byte_bits; + buf[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits; + return 2; + } + else if (code_point <= LIT_UTF8_3_BYTE_CODE_POINT_MAX) + { + uint32_t code_point_bits = code_point; + lit_utf8_byte_t third_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_4_BITS_MASK); + JERRY_ASSERT (first_byte_bits == code_point_bits); + + buf[0] = LIT_UTF8_3_BYTE_MARKER | first_byte_bits; + buf[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits; + buf[2] = LIT_UTF8_EXTRA_BYTE_MARKER | third_byte_bits; + return 3; + } + else + { + JERRY_ASSERT (code_point <= LIT_UTF8_4_BYTE_CODE_POINT_MAX); + + uint32_t code_point_bits = code_point; + lit_utf8_byte_t fourth_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t third_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK); + code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES; + + lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_3_BITS_MASK); + JERRY_ASSERT (first_byte_bits == code_point_bits); + + buf[0] = LIT_UTF8_4_BYTE_MARKER | first_byte_bits; + buf[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits; + buf[2] = LIT_UTF8_EXTRA_BYTE_MARKER | third_byte_bits; + buf[3] = LIT_UTF8_EXTRA_BYTE_MARKER | fourth_byte_bits; + return 4; + } +} /* lit_code_point_to_utf8 */ + +/** + * Convert cesu-8 string to an utf-8 string and put it into the buffer. + * String will be truncated to fit the buffer. + * + * @return number of bytes copied to the buffer. + */ +lit_utf8_size_t +lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string_p, /**< cesu-8 string */ + lit_utf8_size_t cesu8_size, /**< size of cesu-8 string */ + lit_utf8_byte_t *utf8_string_p, /**< destination utf-8 buffer pointer + * (can be NULL if buffer_size == 0) */ + lit_utf8_size_t utf8_size) /**< size of utf-8 buffer */ +{ + const lit_utf8_byte_t *cesu8_cursor_p = cesu8_string_p; + const lit_utf8_byte_t *cesu8_end_p = cesu8_string_p + cesu8_size; + + lit_utf8_byte_t *utf8_cursor_p = utf8_string_p; + lit_utf8_byte_t *utf8_end_p = utf8_string_p + utf8_size; + + while (cesu8_cursor_p < cesu8_end_p) + { + lit_code_point_t cp; + lit_utf8_size_t read_size = lit_read_code_point_from_cesu8 (cesu8_cursor_p, cesu8_end_p, &cp); + lit_utf8_size_t encoded_size = (cp >= LIT_UTF16_FIRST_SURROGATE_CODE_POINT) ? 4 : read_size; + + if (utf8_cursor_p + encoded_size > utf8_end_p) + { + break; + } + + if (cp >= LIT_UTF16_FIRST_SURROGATE_CODE_POINT) + { + lit_code_point_to_utf8 (cp, utf8_cursor_p); + } + else + { + memcpy (utf8_cursor_p, cesu8_cursor_p, encoded_size); + } + + utf8_cursor_p += encoded_size; + cesu8_cursor_p += read_size; + } + + JERRY_ASSERT (cesu8_cursor_p <= cesu8_end_p); + JERRY_ASSERT (utf8_cursor_p <= utf8_end_p); + + return (lit_utf8_byte_t) (utf8_cursor_p - utf8_string_p); +} /* lit_convert_cesu8_string_to_utf8_string */ + +/** + * Convert surrogate pair to code point + * + * @return code point + */ +lit_code_point_t +lit_convert_surrogate_pair_to_code_point (ecma_char_t high_surrogate, /**< high surrogate code point */ + ecma_char_t low_surrogate) /**< low surrogate code point */ +{ + JERRY_ASSERT (lit_is_code_point_utf16_high_surrogate (high_surrogate)); + JERRY_ASSERT (lit_is_code_point_utf16_low_surrogate (low_surrogate)); + + lit_code_point_t code_point; + code_point = (uint16_t) (high_surrogate - LIT_UTF16_HIGH_SURROGATE_MIN); + code_point <<= LIT_UTF16_BITS_IN_SURROGATE; + + code_point += LIT_UTF16_FIRST_SURROGATE_CODE_POINT; + + code_point |= (uint16_t) (low_surrogate - LIT_UTF16_LOW_SURROGATE_MIN); + return code_point; +} /* lit_convert_surrogate_pair_to_code_point */ + +/** + * Relational compare of cesu-8 strings + * + * First string is less than second string if: + * - strings are not equal; + * - first string is prefix of second or is lexicographically less than second. + * + * @return true - if first string is less than second string, + * false - otherwise + */ +bool +lit_compare_utf8_strings_relational (const lit_utf8_byte_t *string1_p, /**< utf-8 string */ + lit_utf8_size_t string1_size, /**< string size */ + const lit_utf8_byte_t *string2_p, /**< utf-8 string */ + lit_utf8_size_t string2_size) /**< string size */ +{ + lit_utf8_byte_t *string1_pos = (lit_utf8_byte_t *) string1_p; + lit_utf8_byte_t *string2_pos = (lit_utf8_byte_t *) string2_p; + const lit_utf8_byte_t *string1_end_p = string1_p + string1_size; + const lit_utf8_byte_t *string2_end_p = string2_p + string2_size; + + while (string1_pos < string1_end_p && string2_pos < string2_end_p) + { + ecma_char_t ch1, ch2; + string1_pos += lit_read_code_unit_from_cesu8 (string1_pos, &ch1); + string2_pos += lit_read_code_unit_from_cesu8 (string2_pos, &ch2); + + if (ch1 < ch2) + { + return true; + } + else if (ch1 > ch2) + { + return false; + } + } + + return (string1_pos >= string1_end_p && string2_pos < string2_end_p); +} /* lit_compare_utf8_strings_relational */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-strings.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-strings.h new file mode 100644 index 0000000..8e63283 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-strings.h @@ -0,0 +1,150 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIT_STRINGS_H +#define LIT_STRINGS_H + +#include "jrt.h" +#include "lit-globals.h" + +/** + * Null character (used in few cases as utf-8 string end marker) + */ +#define LIT_BYTE_NULL (0) + +/** + * For the formal definition of Unicode transformation formats (UTF) see Section 3.9, Unicode Encoding Forms in The + * Unicode Standard (http://www.unicode.org/versions/Unicode3.0.0/ch03.pdf#G7404). + */ +#define LIT_UNICODE_CODE_POINT_NULL (0x0) +#define LIT_UNICODE_CODE_POINT_MAX (0x10FFFF) + +#define LIT_UTF16_CODE_UNIT_MAX (0xFFFF) +#define LIT_UTF16_FIRST_SURROGATE_CODE_POINT (0x10000) +#define LIT_UTF16_LOW_SURROGATE_MARKER (0xDC00) +#define LIT_UTF16_HIGH_SURROGATE_MARKER (0xD800) +#define LIT_UTF16_HIGH_SURROGATE_MIN (0xD800) +#define LIT_UTF16_HIGH_SURROGATE_MAX (0xDBFF) +#define LIT_UTF16_LOW_SURROGATE_MIN (0xDC00) +#define LIT_UTF16_LOW_SURROGATE_MAX (0xDFFF) +#define LIT_UTF16_BITS_IN_SURROGATE (10) +#define LIT_UTF16_LAST_10_BITS_MASK (0x3FF) + +#define LIT_UTF8_1_BYTE_MARKER (0x00) +#define LIT_UTF8_2_BYTE_MARKER (0xC0) +#define LIT_UTF8_3_BYTE_MARKER (0xE0) +#define LIT_UTF8_4_BYTE_MARKER (0xF0) +#define LIT_UTF8_EXTRA_BYTE_MARKER (0x80) + +#define LIT_UTF8_1_BYTE_MASK (0x80) +#define LIT_UTF8_2_BYTE_MASK (0xE0) +#define LIT_UTF8_3_BYTE_MASK (0xF0) +#define LIT_UTF8_4_BYTE_MASK (0xF8) +#define LIT_UTF8_EXTRA_BYTE_MASK (0xC0) + +#define LIT_UTF8_LAST_7_BITS_MASK (0x7F) +#define LIT_UTF8_LAST_6_BITS_MASK (0x3F) +#define LIT_UTF8_LAST_5_BITS_MASK (0x1F) +#define LIT_UTF8_LAST_4_BITS_MASK (0x0F) +#define LIT_UTF8_LAST_3_BITS_MASK (0x07) +#define LIT_UTF8_LAST_2_BITS_MASK (0x03) +#define LIT_UTF8_LAST_1_BIT_MASK (0x01) + +#define LIT_UTF8_BITS_IN_EXTRA_BYTES (6) + +#define LIT_UTF8_1_BYTE_CODE_POINT_MAX (0x7F) +#define LIT_UTF8_2_BYTE_CODE_POINT_MIN (0x80) +#define LIT_UTF8_2_BYTE_CODE_POINT_MAX (0x7FF) +#define LIT_UTF8_3_BYTE_CODE_POINT_MIN (0x800) +#define LIT_UTF8_3_BYTE_CODE_POINT_MAX (LIT_UTF16_CODE_UNIT_MAX) +#define LIT_UTF8_4_BYTE_CODE_POINT_MIN (0x10000) +#define LIT_UTF8_4_BYTE_CODE_POINT_MAX (LIT_UNICODE_CODE_POINT_MAX) + +/** + * Difference between byte count needed to represent code point greater than 0xFFFF + * in common UTF-8 (4 bytes required) and CESU-8 (6 bytes required) + */ +#define LIT_UTF8_CESU8_SURROGATE_SIZE_DIF (2 * LIT_UTF8_MAX_BYTES_IN_CODE_UNIT - LIT_UTF8_MAX_BYTES_IN_CODE_POINT) + +/** + * Byte values >= LIT_UTF8_FIRST_BYTE_MAX are not allowed in internal strings + */ +#define LIT_UTF8_FIRST_BYTE_MAX (0xF8) + +/* validation */ +bool lit_is_valid_utf8_string (const lit_utf8_byte_t *utf8_buf_p, lit_utf8_size_t buf_size, bool strict); +bool lit_is_valid_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, lit_utf8_size_t buf_size); + +/* checks */ +bool lit_is_code_point_utf16_low_surrogate (lit_code_point_t code_point); +bool lit_is_code_point_utf16_high_surrogate (lit_code_point_t code_point); + +/* size */ +lit_utf8_size_t lit_zt_utf8_string_size (const lit_utf8_byte_t *utf8_str_p); +lit_utf8_size_t lit_get_utf8_size_of_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, lit_utf8_size_t cesu8_buf_size); + +/* length */ +lit_utf8_size_t lit_utf8_string_length (const lit_utf8_byte_t *utf8_buf_p, lit_utf8_size_t utf8_buf_size); +lit_utf8_size_t lit_get_utf8_length_of_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, + lit_utf8_size_t cesu8_buf_size); + +/* hash */ +lit_string_hash_t lit_utf8_string_calc_hash (const lit_utf8_byte_t *utf8_buf_p, lit_utf8_size_t utf8_buf_size); +lit_string_hash_t lit_utf8_string_hash_combine (lit_string_hash_t hash_basis, + const lit_utf8_byte_t *utf8_buf_p, + lit_utf8_size_t utf8_buf_size); + +/* code unit access */ +ecma_char_t lit_utf8_string_code_unit_at (const lit_utf8_byte_t *utf8_buf_p, + lit_utf8_size_t utf8_buf_size, + lit_utf8_size_t code_unit_offset); +lit_utf8_size_t lit_get_unicode_char_size_by_utf8_first_byte (const lit_utf8_byte_t first_byte); + +/* conversion */ +lit_utf8_size_t lit_code_unit_to_utf8 (ecma_char_t code_unit, lit_utf8_byte_t *buf_p); +lit_utf8_size_t lit_code_point_to_utf8 (lit_code_point_t code_point, lit_utf8_byte_t *buf); +lit_utf8_size_t lit_code_point_to_cesu8 (lit_code_point_t code_point, lit_utf8_byte_t *buf); +lit_utf8_size_t lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string_p, + lit_utf8_size_t cesu8_size, + lit_utf8_byte_t *utf8_string_p, + lit_utf8_size_t utf8_size); +lit_code_point_t lit_convert_surrogate_pair_to_code_point (ecma_char_t high_surrogate, ecma_char_t low_surrogate); + +bool lit_compare_utf8_strings_relational (const lit_utf8_byte_t *string1_p, + lit_utf8_size_t string1_size, + const lit_utf8_byte_t *string2_p, + lit_utf8_size_t string2_size); + +uint8_t lit_utf16_encode_code_point (lit_code_point_t cp, ecma_char_t *cu_p); + +/* read code point from buffer */ +lit_utf8_size_t +lit_read_code_point_from_utf8 (const lit_utf8_byte_t *buf_p, lit_utf8_size_t buf_size, lit_code_point_t *code_point); + +lit_utf8_size_t lit_read_code_unit_from_cesu8 (const lit_utf8_byte_t *buf_p, ecma_char_t *code_unit); +lit_utf8_size_t lit_read_code_point_from_cesu8 (const lit_utf8_byte_t *buf_p, + const lit_utf8_byte_t *buf_end_p, + lit_code_point_t *code_point); + +lit_utf8_size_t lit_read_prev_code_unit_from_utf8 (const lit_utf8_byte_t *buf_p, ecma_char_t *code_point); + +ecma_char_t lit_cesu8_read_next (const lit_utf8_byte_t **buf_p); +ecma_char_t lit_cesu8_read_prev (const lit_utf8_byte_t **buf_p); +ecma_char_t lit_cesu8_peek_next (const lit_utf8_byte_t *buf_p); +ecma_char_t lit_cesu8_peek_prev (const lit_utf8_byte_t *buf_p); +void lit_utf8_incr (const lit_utf8_byte_t **buf_p); +void lit_utf8_decr (const lit_utf8_byte_t **buf_p); + +#endif /* !LIT_STRINGS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-conversions-sup.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-conversions-sup.inc.h new file mode 100644 index 0000000..5a12a33 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-conversions-sup.inc.h @@ -0,0 +1,27 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-unicode.py script + * from UnicodeData.txt and SpecialCasing.txt files. Do not edit! */ + +/* Contains start points of character case ranges (these are bidirectional conversions). */ +static const uint32_t lit_unicode_character_case_ranges_sup[] JERRY_ATTR_CONST_DATA = { + 0x010400, 0x010428, 0x0104b0, 0x0104d8, 0x010c80, 0x010cc0, 0x0118a0, 0x0118c0, 0x016e40, 0x016e60, 0x01e900, 0x01e922 +}; + +/* Interval lengths of start points in `character_case_ranges` table. */ +static const uint16_t lit_unicode_character_case_range_lengths_sup[] JERRY_ATTR_CONST_DATA = { 0x000028, 0x000024, + 0x000033, 0x000020, + 0x000020, 0x000022 }; diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-conversions.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-conversions.inc.h new file mode 100644 index 0000000..7c6279b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-conversions.inc.h @@ -0,0 +1,119 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-unicode.py script + * from UnicodeData.txt and SpecialCasing.txt files. Do not edit! */ + +/* Contains start points of character case ranges (these are bidirectional conversions). */ +static const uint16_t lit_unicode_character_case_ranges[] JERRY_ATTR_CONST_DATA = { + 0x00c0, 0x00e0, 0x00d8, 0x00f8, 0x0189, 0x0256, 0x01b1, 0x028a, 0x0388, 0x03ad, 0x038e, 0x03cd, 0x0391, + 0x03b1, 0x03a3, 0x03c3, 0x03fd, 0x037b, 0x0400, 0x0450, 0x0410, 0x0430, 0x0531, 0x0561, 0x10a0, 0x2d00, + 0x13a0, 0xab70, 0x13f0, 0x13f8, 0x1c90, 0x10d0, 0x1cbd, 0x10fd, 0x1f08, 0x1f00, 0x1f18, 0x1f10, 0x1f28, + 0x1f20, 0x1f38, 0x1f30, 0x1f48, 0x1f40, 0x1f68, 0x1f60, 0x1fb8, 0x1fb0, 0x1fba, 0x1f70, 0x1fc8, 0x1f72, + 0x1fd8, 0x1fd0, 0x1fda, 0x1f76, 0x1fe8, 0x1fe0, 0x1fea, 0x1f7a, 0x1ff8, 0x1f78, 0x1ffa, 0x1f7c, 0x2160, + 0x2170, 0x24b6, 0x24d0, 0x2c00, 0x2c30, 0x2c7e, 0x023f, 0xff21, 0xff41 +}; + +/* Interval lengths of start points in `character_case_ranges` table. */ +static const uint8_t lit_unicode_character_case_range_lengths[] JERRY_ATTR_CONST_DATA = { + 0x0017, 0x0007, 0x0002, 0x0002, 0x0003, 0x0002, 0x0011, 0x0009, 0x0003, 0x0010, 0x0020, 0x0026, 0x0026, + 0x0050, 0x0006, 0x002b, 0x0003, 0x0008, 0x0006, 0x0008, 0x0008, 0x0006, 0x0008, 0x0002, 0x0002, 0x0004, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0010, 0x001a, 0x002f, 0x0002, 0x001a +}; + +/* Contains the start points of bidirectional conversion ranges. */ +static const uint16_t lit_unicode_character_pair_ranges[] JERRY_ATTR_CONST_DATA = { + 0x0100, 0x0132, 0x0139, 0x014a, 0x0179, 0x0182, 0x0187, 0x018b, 0x0191, 0x0198, 0x01a0, 0x01a7, + 0x01ac, 0x01af, 0x01b3, 0x01b8, 0x01bc, 0x01cd, 0x01de, 0x01f4, 0x01f8, 0x0222, 0x023b, 0x0241, + 0x0246, 0x0370, 0x0376, 0x03d8, 0x03f7, 0x03fa, 0x0460, 0x048a, 0x04c1, 0x04d0, 0x1e00, 0x1ea0, + 0x2183, 0x2c60, 0x2c67, 0x2c72, 0x2c75, 0x2c80, 0x2ceb, 0x2cf2, 0xa640, 0xa680, 0xa722, 0xa732, + 0xa779, 0xa77e, 0xa78b, 0xa790, 0xa796, 0xa7b4, 0xa7c2, 0xa7c7, 0xa7f5 +}; + +/* Interval lengths of start points in `character_pair_ranges` table. */ +static const uint8_t lit_unicode_character_pair_range_lengths[] JERRY_ATTR_CONST_DATA = { + 0x0030, 0x0006, 0x0010, 0x002e, 0x0006, 0x0004, 0x0002, 0x0002, 0x0002, 0x0002, 0x0006, 0x0002, + 0x0002, 0x0002, 0x0004, 0x0002, 0x0002, 0x0010, 0x0012, 0x0002, 0x0028, 0x0012, 0x0002, 0x0002, + 0x000a, 0x0004, 0x0002, 0x0018, 0x0002, 0x0002, 0x0022, 0x0036, 0x000e, 0x0060, 0x0096, 0x0060, + 0x0002, 0x0002, 0x0006, 0x0002, 0x0002, 0x0064, 0x0004, 0x0002, 0x002e, 0x001c, 0x000e, 0x003e, + 0x0004, 0x000a, 0x0002, 0x0004, 0x0014, 0x000c, 0x0002, 0x0004, 0x0002 +}; + +/* Contains lower/upper case bidirectional conversion pairs. */ +static const uint16_t lit_unicode_character_pairs[] JERRY_ATTR_CONST_DATA = { + 0x0178, 0x00ff, 0x0181, 0x0253, 0x0186, 0x0254, 0x018e, 0x01dd, 0x018f, 0x0259, 0x0190, 0x025b, 0x0193, + 0x0260, 0x0194, 0x0263, 0x0196, 0x0269, 0x0197, 0x0268, 0x019c, 0x026f, 0x019d, 0x0272, 0x019f, 0x0275, + 0x01a6, 0x0280, 0x01a9, 0x0283, 0x01ae, 0x0288, 0x01b7, 0x0292, 0x01c4, 0x01c6, 0x01c7, 0x01c9, 0x01ca, + 0x01cc, 0x01f1, 0x01f3, 0x01f6, 0x0195, 0x01f7, 0x01bf, 0x0220, 0x019e, 0x023a, 0x2c65, 0x023d, 0x019a, + 0x023e, 0x2c66, 0x0243, 0x0180, 0x0244, 0x0289, 0x0245, 0x028c, 0x037f, 0x03f3, 0x0386, 0x03ac, 0x038c, + 0x03cc, 0x03cf, 0x03d7, 0x03f9, 0x03f2, 0x04c0, 0x04cf, 0x10c7, 0x2d27, 0x10cd, 0x2d2d, 0x1f59, 0x1f51, + 0x1f5b, 0x1f53, 0x1f5d, 0x1f55, 0x1f5f, 0x1f57, 0x1fec, 0x1fe5, 0x2132, 0x214e, 0x2c62, 0x026b, 0x2c63, + 0x1d7d, 0x2c64, 0x027d, 0x2c6d, 0x0251, 0x2c6e, 0x0271, 0x2c6f, 0x0250, 0x2c70, 0x0252, 0xa77d, 0x1d79, + 0xa78d, 0x0265, 0xa7aa, 0x0266, 0xa7ab, 0x025c, 0xa7ac, 0x0261, 0xa7ad, 0x026c, 0xa7ae, 0x026a, 0xa7b0, + 0x029e, 0xa7b1, 0x0287, 0xa7b2, 0x029d, 0xa7b3, 0xab53, 0xa7c4, 0xa794, 0xa7c5, 0x0282, 0xa7c6, 0x1d8e +}; + +/* Contains start points of one-to-two uppercase ranges where the second character + * is always the same. + */ +static const uint16_t lit_unicode_upper_case_special_ranges[] JERRY_ATTR_CONST_DATA = { + 0x1f80, 0x1f08, 0x0399, 0x1f88, 0x1f08, 0x0399, 0x1f90, 0x1f28, 0x0399, + 0x1f98, 0x1f28, 0x0399, 0x1fa0, 0x1f68, 0x0399, 0x1fa8, 0x1f68, 0x0399 +}; + +/* Interval lengths for start points in `upper_case_special_ranges` table. */ +static const uint8_t lit_unicode_upper_case_special_range_lengths[] JERRY_ATTR_CONST_DATA = { 0x0007, 0x0007, 0x0007, + 0x0007, 0x0007, 0x0007 }; + +/* Contains start points of lowercase ranges. */ +static const uint16_t lit_unicode_lower_case_ranges[] JERRY_ATTR_CONST_DATA = { 0x1f88, 0x1f80, 0x1f98, + 0x1f90, 0x1fa8, 0x1fa0 }; + +/* Interval lengths for start points in `lower_case_ranges` table. */ +static const uint8_t lit_unicode_lower_case_range_lengths[] JERRY_ATTR_CONST_DATA = { 0x0008, 0x0008, 0x0008 }; + +/* The remaining lowercase conversions. The lowercase variant can be one-to-three character long. */ +static const uint16_t lit_unicode_lower_case_conversions[] JERRY_ATTR_CONST_DATA = { + 0x01c5, 0x01c6, 0x01c8, 0x01c9, 0x01cb, 0x01cc, 0x01f2, 0x01f3, 0x03f4, 0x03b8, 0x1e9e, 0x00df, 0x1fbc, 0x1fb3, + 0x1fcc, 0x1fc3, 0x1ffc, 0x1ff3, 0x2126, 0x03c9, 0x212a, 0x006b, 0x212b, 0x00e5, 0x0130, 0x0069, 0x0307 +}; + +/* Number of one-to-one, one-to-two, and one-to-three lowercase conversions. */ +static const uint8_t lit_unicode_lower_case_conversion_counters[] JERRY_ATTR_CONST_DATA = { 0x000c, 0x0001, 0x0000 }; + +/* The remaining uppercase conversions. The uppercase variant can be one-to-three character long. */ +static const uint16_t lit_unicode_upper_case_conversions[] JERRY_ATTR_CONST_DATA = { + 0x00b5, 0x039c, 0x0131, 0x0049, 0x017f, 0x0053, 0x01c5, 0x01c4, 0x01c8, 0x01c7, 0x01cb, 0x01ca, 0x01f2, 0x01f1, + 0x0345, 0x0399, 0x03c2, 0x03a3, 0x03d0, 0x0392, 0x03d1, 0x0398, 0x03d5, 0x03a6, 0x03d6, 0x03a0, 0x03f0, 0x039a, + 0x03f1, 0x03a1, 0x03f5, 0x0395, 0x1c80, 0x0412, 0x1c81, 0x0414, 0x1c82, 0x041e, 0x1c83, 0x0421, 0x1c84, 0x0422, + 0x1c85, 0x0422, 0x1c86, 0x042a, 0x1c87, 0x0462, 0x1c88, 0xa64a, 0x1e9b, 0x1e60, 0x1fbe, 0x0399, 0x00df, 0x0053, + 0x0053, 0x0149, 0x02bc, 0x004e, 0x01f0, 0x004a, 0x030c, 0x0587, 0x0535, 0x0552, 0x1e96, 0x0048, 0x0331, 0x1e97, + 0x0054, 0x0308, 0x1e98, 0x0057, 0x030a, 0x1e99, 0x0059, 0x030a, 0x1e9a, 0x0041, 0x02be, 0x1f50, 0x03a5, 0x0313, + 0x1f87, 0x1f0f, 0x0399, 0x1f8f, 0x1f0f, 0x0399, 0x1f97, 0x1f2f, 0x0399, 0x1f9f, 0x1f2f, 0x0399, 0x1fa7, 0x1f6f, + 0x0399, 0x1faf, 0x1f6f, 0x0399, 0x1fb2, 0x1fba, 0x0399, 0x1fb3, 0x0391, 0x0399, 0x1fb4, 0x0386, 0x0399, 0x1fb6, + 0x0391, 0x0342, 0x1fbc, 0x0391, 0x0399, 0x1fc2, 0x1fca, 0x0399, 0x1fc3, 0x0397, 0x0399, 0x1fc4, 0x0389, 0x0399, + 0x1fc6, 0x0397, 0x0342, 0x1fcc, 0x0397, 0x0399, 0x1fd6, 0x0399, 0x0342, 0x1fe4, 0x03a1, 0x0313, 0x1fe6, 0x03a5, + 0x0342, 0x1ff2, 0x1ffa, 0x0399, 0x1ff3, 0x03a9, 0x0399, 0x1ff4, 0x038f, 0x0399, 0x1ff6, 0x03a9, 0x0342, 0x1ffc, + 0x03a9, 0x0399, 0xfb00, 0x0046, 0x0046, 0xfb01, 0x0046, 0x0049, 0xfb02, 0x0046, 0x004c, 0xfb05, 0x0053, 0x0054, + 0xfb06, 0x0053, 0x0054, 0xfb13, 0x0544, 0x0546, 0xfb14, 0x0544, 0x0535, 0xfb15, 0x0544, 0x053b, 0xfb16, 0x054e, + 0x0546, 0xfb17, 0x0544, 0x053d, 0x0390, 0x0399, 0x0308, 0x0301, 0x03b0, 0x03a5, 0x0308, 0x0301, 0x1f52, 0x03a5, + 0x0313, 0x0300, 0x1f54, 0x03a5, 0x0313, 0x0301, 0x1f56, 0x03a5, 0x0313, 0x0342, 0x1fb7, 0x0391, 0x0342, 0x0399, + 0x1fc7, 0x0397, 0x0342, 0x0399, 0x1fd2, 0x0399, 0x0308, 0x0300, 0x1fd3, 0x0399, 0x0308, 0x0301, 0x1fd7, 0x0399, + 0x0308, 0x0342, 0x1fe2, 0x03a5, 0x0308, 0x0300, 0x1fe3, 0x03a5, 0x0308, 0x0301, 0x1fe7, 0x03a5, 0x0308, 0x0342, + 0x1ff7, 0x03a9, 0x0342, 0x0399, 0xfb03, 0x0046, 0x0046, 0x0049, 0xfb04, 0x0046, 0x0046, 0x004c +}; + +/* Number of one-to-one, one-to-two, and one-to-three uppercase conversions. */ +static const uint8_t lit_unicode_upper_case_conversion_counters[] JERRY_ATTR_CONST_DATA = { 0x001b, 0x002c, 0x0010 }; diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-folding.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-folding.inc.h new file mode 100644 index 0000000..d9cd46f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-folding.inc.h @@ -0,0 +1,54 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-unicode.py script + * from the CaseFolding.txt file. Do not edit! */ + +/** + * Character interval starting points for folding_skip_to_lower. + */ +static const uint16_t lit_unicode_folding_skip_to_lower_interval_starts[] JERRY_ATTR_CONST_DATA = { 0x13a0, + 0x13f8, + 0xab70 }; + +/** + * Character interval lengths for folding_skip_to_lower. + */ +static const uint8_t lit_unicode_folding_skip_to_lower_interval_lengths[] JERRY_ATTR_CONST_DATA = { 0x0055, + 0x0005, + 0x004f }; + +/** + * Non-interval characters for folding_skip_to_lower. + */ +static const uint16_t lit_unicode_folding_skip_to_lower_chars[] JERRY_ATTR_CONST_DATA = { 0x0130 }; + +/** + * Character interval starting points for folding_to_upper. + */ +static const uint16_t lit_unicode_folding_to_upper_interval_starts[] JERRY_ATTR_CONST_DATA = { 0x03d0, 0x03d5, 0x03f0, + 0x13f8, 0x1c80, 0xab70 }; + +/** + * Character interval lengths for folding_to_upper. + */ +static const uint8_t lit_unicode_folding_to_upper_interval_lengths[] JERRY_ATTR_CONST_DATA = { 0x0001, 0x0001, 0x0001, + 0x0005, 0x0008, 0x004f }; + +/** + * Non-interval characters for folding_to_upper. + */ +static const uint16_t lit_unicode_folding_to_upper_chars[] JERRY_ATTR_CONST_DATA = { 0x00b5, 0x017f, 0x0345, 0x03c2, + 0x03f5, 0x1e9b, 0x1fbe }; diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-ranges-sup.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-ranges-sup.inc.h new file mode 100644 index 0000000..2e034fa --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-ranges-sup.inc.h @@ -0,0 +1,116 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-unicode.py script + * from DerivedCoreProperties.txt. Do not edit! */ + +/** + * Character interval starting points for ID_Start. + */ +static const uint32_t lit_unicode_id_start_interval_starts_sup[] JERRY_ATTR_CONST_DATA = { + 0x010000, 0x01000d, 0x010028, 0x01003c, 0x01003f, 0x010050, 0x010080, 0x010140, 0x010280, 0x0102a0, 0x010300, + 0x01032d, 0x010350, 0x010380, 0x0103a0, 0x0103c8, 0x0103d1, 0x010400, 0x0104b0, 0x0104d8, 0x010500, 0x010530, + 0x010600, 0x010740, 0x010760, 0x010800, 0x01080a, 0x010837, 0x01083f, 0x010860, 0x010880, 0x0108e0, 0x0108f4, + 0x010900, 0x010920, 0x010980, 0x0109be, 0x010a10, 0x010a15, 0x010a19, 0x010a60, 0x010a80, 0x010ac0, 0x010ac9, + 0x010b00, 0x010b40, 0x010b60, 0x010b80, 0x010c00, 0x010c80, 0x010cc0, 0x010d00, 0x010e80, 0x010eb0, 0x010f00, + 0x010f30, 0x010fb0, 0x010fe0, 0x011003, 0x011083, 0x0110d0, 0x011103, 0x011150, 0x011183, 0x0111c1, 0x011200, + 0x011213, 0x011280, 0x01128a, 0x01128f, 0x01129f, 0x0112b0, 0x011305, 0x01130f, 0x011313, 0x01132a, 0x011332, + 0x011335, 0x01135d, 0x011400, 0x011447, 0x01145f, 0x011480, 0x0114c4, 0x011580, 0x0115d8, 0x011600, 0x011680, + 0x011700, 0x011800, 0x0118a0, 0x0118ff, 0x01190c, 0x011915, 0x011918, 0x0119a0, 0x0119aa, 0x011a0b, 0x011a5c, + 0x011ac0, 0x011c00, 0x011c0a, 0x011c72, 0x011d00, 0x011d08, 0x011d0b, 0x011d60, 0x011d67, 0x011d6a, 0x011ee0, + 0x012000, 0x012400, 0x012480, 0x013000, 0x014400, 0x016800, 0x016a40, 0x016ad0, 0x016b00, 0x016b40, 0x016b63, + 0x016b7d, 0x016e40, 0x016f00, 0x016f93, 0x016fe0, 0x017000, 0x018800, 0x018d00, 0x01b000, 0x01b150, 0x01b164, + 0x01b170, 0x01bc00, 0x01bc70, 0x01bc80, 0x01bc90, 0x01d400, 0x01d456, 0x01d49e, 0x01d4a5, 0x01d4a9, 0x01d4ae, + 0x01d4bd, 0x01d4c5, 0x01d507, 0x01d50d, 0x01d516, 0x01d51e, 0x01d53b, 0x01d540, 0x01d54a, 0x01d552, 0x01d6a8, + 0x01d6c2, 0x01d6dc, 0x01d6fc, 0x01d716, 0x01d736, 0x01d750, 0x01d770, 0x01d78a, 0x01d7aa, 0x01d7c4, 0x01e100, + 0x01e137, 0x01e2c0, 0x01e800, 0x01e900, 0x01ee00, 0x01ee05, 0x01ee21, 0x01ee29, 0x01ee34, 0x01ee4d, 0x01ee51, + 0x01ee61, 0x01ee67, 0x01ee6c, 0x01ee74, 0x01ee79, 0x01ee80, 0x01ee8b, 0x01eea1, 0x01eea5, 0x01eeab, 0x020000, + 0x02a700, 0x02b740, 0x02b820, 0x02ceb0, 0x02f800, 0x030000 +}; + +/** + * Character interval lengths for ID_Start. + */ +static const uint16_t lit_unicode_id_start_interval_lengths_sup[] JERRY_ATTR_CONST_DATA = { + 0x00000b, 0x000019, 0x000012, 0x000001, 0x00000e, 0x00000d, 0x00007a, 0x000034, 0x00001c, 0x000030, 0x00001f, + 0x00001d, 0x000025, 0x00001d, 0x000023, 0x000007, 0x000004, 0x00009d, 0x000023, 0x000023, 0x000027, 0x000033, + 0x000136, 0x000015, 0x000007, 0x000005, 0x00002b, 0x000001, 0x000016, 0x000016, 0x00001e, 0x000012, 0x000001, + 0x000015, 0x000019, 0x000037, 0x000001, 0x000003, 0x000002, 0x00001c, 0x00001c, 0x00001c, 0x000007, 0x00001b, + 0x000035, 0x000015, 0x000012, 0x000011, 0x000048, 0x000032, 0x000032, 0x000023, 0x000029, 0x000001, 0x00001c, + 0x000015, 0x000014, 0x000016, 0x000034, 0x00002c, 0x000018, 0x000023, 0x000022, 0x00002f, 0x000003, 0x000011, + 0x000018, 0x000006, 0x000003, 0x00000e, 0x000009, 0x00002e, 0x000007, 0x000001, 0x000015, 0x000006, 0x000001, + 0x000004, 0x000004, 0x000034, 0x000003, 0x000002, 0x00002f, 0x000001, 0x00002e, 0x000003, 0x00002f, 0x00002a, + 0x00001a, 0x00002b, 0x00003f, 0x000007, 0x000007, 0x000001, 0x000017, 0x000007, 0x000026, 0x000027, 0x00002d, + 0x000038, 0x000008, 0x000024, 0x00001d, 0x000006, 0x000001, 0x000025, 0x000005, 0x000001, 0x00001f, 0x000012, + 0x000399, 0x00006e, 0x0000c3, 0x00042e, 0x000246, 0x000238, 0x00001e, 0x00001d, 0x00002f, 0x000003, 0x000014, + 0x000012, 0x00003f, 0x00004a, 0x00000c, 0x000001, 0x0017f7, 0x0004d5, 0x000008, 0x00011e, 0x000002, 0x000003, + 0x00018b, 0x00006a, 0x00000c, 0x000008, 0x000009, 0x000054, 0x000046, 0x000001, 0x000001, 0x000003, 0x00000b, + 0x000006, 0x000040, 0x000003, 0x000007, 0x000006, 0x00001b, 0x000003, 0x000004, 0x000006, 0x000153, 0x000018, + 0x000018, 0x00001e, 0x000018, 0x00001e, 0x000018, 0x00001e, 0x000018, 0x00001e, 0x000018, 0x000007, 0x00002c, + 0x000006, 0x00002b, 0x0000c4, 0x000043, 0x000003, 0x00001a, 0x000001, 0x000009, 0x000003, 0x000002, 0x000001, + 0x000001, 0x000003, 0x000006, 0x000003, 0x000003, 0x000009, 0x000010, 0x000002, 0x000004, 0x000010, 0x00a6dd, + 0x001034, 0x0000dd, 0x001681, 0x001d30, 0x00021d, 0x00134a +}; + +/** + * Non-interval characters for ID_Start. + */ +static const uint32_t lit_unicode_id_start_chars_sup[] JERRY_ATTR_CONST_DATA = { + 0x010808, 0x01083c, 0x010a00, 0x010f27, 0x011144, 0x011147, 0x011176, 0x0111da, 0x0111dc, 0x011288, 0x01133d, + 0x011350, 0x0114c7, 0x011644, 0x0116b8, 0x011909, 0x01193f, 0x011941, 0x0119e1, 0x0119e3, 0x011a00, 0x011a3a, + 0x011a50, 0x011a9d, 0x011c40, 0x011d46, 0x011d98, 0x011fb0, 0x016f50, 0x016fe3, 0x01d4a2, 0x01d4bb, 0x01d546, + 0x01e14e, 0x01e94b, 0x01ee24, 0x01ee27, 0x01ee39, 0x01ee3b, 0x01ee42, 0x01ee47, 0x01ee49, 0x01ee4b, 0x01ee54, + 0x01ee57, 0x01ee59, 0x01ee5b, 0x01ee5d, 0x01ee5f, 0x01ee64, 0x01ee7e +}; + +/** + * Character interval starting points for ID_Continue. + */ +static const uint32_t lit_unicode_id_continue_interval_starts_sup[] JERRY_ATTR_CONST_DATA = { + 0x010376, 0x0104a0, 0x010a01, 0x010a05, 0x010a0c, 0x010a38, 0x010ae5, 0x010d24, 0x010d30, 0x010eab, 0x010f46, + 0x011000, 0x011038, 0x011066, 0x01107f, 0x0110b0, 0x0110f0, 0x011100, 0x011127, 0x011136, 0x011145, 0x011180, + 0x0111b3, 0x0111c9, 0x0111ce, 0x01122c, 0x0112df, 0x0112f0, 0x011300, 0x01133b, 0x01133e, 0x011347, 0x01134b, + 0x011362, 0x011366, 0x011370, 0x011435, 0x011450, 0x0114b0, 0x0114d0, 0x0115af, 0x0115b8, 0x0115dc, 0x011630, + 0x011650, 0x0116ab, 0x0116c0, 0x01171d, 0x011730, 0x01182c, 0x0118e0, 0x011930, 0x011937, 0x01193b, 0x011942, + 0x011950, 0x0119d1, 0x0119da, 0x011a01, 0x011a33, 0x011a3b, 0x011a51, 0x011a8a, 0x011c2f, 0x011c38, 0x011c50, + 0x011c92, 0x011ca9, 0x011d31, 0x011d3c, 0x011d3f, 0x011d50, 0x011d8a, 0x011d90, 0x011d93, 0x011da0, 0x011ef3, + 0x016a60, 0x016af0, 0x016b30, 0x016b50, 0x016f51, 0x016f8f, 0x016ff0, 0x01bc9d, 0x01d165, 0x01d16d, 0x01d17b, + 0x01d185, 0x01d1aa, 0x01d242, 0x01d7ce, 0x01da00, 0x01da3b, 0x01da9b, 0x01daa1, 0x01e000, 0x01e008, 0x01e01b, + 0x01e023, 0x01e026, 0x01e130, 0x01e140, 0x01e2ec, 0x01e8d0, 0x01e944, 0x01e950, 0x01fbf0, 0x0e0100 +}; + +/** + * Character interval lengths for ID_Continue. + */ +static const uint16_t lit_unicode_id_continue_interval_lengths_sup[] JERRY_ATTR_CONST_DATA = { + 0x000004, 0x000009, 0x000002, 0x000001, 0x000003, 0x000002, 0x000001, 0x000003, 0x000009, 0x000001, 0x00000a, + 0x000002, 0x00000e, 0x000009, 0x000003, 0x00000a, 0x000009, 0x000002, 0x00000d, 0x000009, 0x000001, 0x000002, + 0x00000d, 0x000003, 0x00000b, 0x00000b, 0x00000b, 0x000009, 0x000003, 0x000001, 0x000006, 0x000001, 0x000002, + 0x000001, 0x000006, 0x000004, 0x000011, 0x000009, 0x000013, 0x000009, 0x000006, 0x000008, 0x000001, 0x000010, + 0x000009, 0x00000c, 0x000009, 0x00000e, 0x000009, 0x00000e, 0x000009, 0x000005, 0x000001, 0x000003, 0x000001, + 0x000009, 0x000006, 0x000006, 0x000009, 0x000006, 0x000003, 0x00000a, 0x00000f, 0x000007, 0x000007, 0x000009, + 0x000015, 0x00000d, 0x000005, 0x000001, 0x000006, 0x000009, 0x000004, 0x000001, 0x000004, 0x000009, 0x000003, + 0x000009, 0x000004, 0x000006, 0x000009, 0x000036, 0x000003, 0x000001, 0x000001, 0x000004, 0x000005, 0x000007, + 0x000006, 0x000003, 0x000002, 0x000031, 0x000036, 0x000031, 0x000004, 0x00000e, 0x000006, 0x000010, 0x000006, + 0x000001, 0x000004, 0x000006, 0x000009, 0x00000d, 0x000006, 0x000006, 0x000009, 0x000009, 0x0000ef +}; + +/** + * Non-interval characters for ID_Continue. + */ +static const uint32_t lit_unicode_id_continue_chars_sup[] JERRY_ATTR_CONST_DATA = { + 0x0101fd, 0x0102e0, 0x010a3f, 0x011173, 0x01123e, 0x011357, 0x01145e, 0x011940, + 0x0119e4, 0x011a47, 0x011d3a, 0x011d47, 0x016f4f, 0x016fe4, 0x01da75, 0x01da84 +}; diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-ranges.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-ranges.inc.h new file mode 100644 index 0000000..75022dd --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/lit-unicode-ranges.inc.h @@ -0,0 +1,176 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-unicode.py script + * from DerivedCoreProperties.txt. Do not edit! */ + +/** + * Character interval starting points for ID_Start. + */ +static const uint16_t lit_unicode_id_start_interval_starts[] JERRY_ATTR_CONST_DATA = { + 0x00c0, 0x00d8, 0x00f8, 0x01f8, 0x02c6, 0x02e0, 0x0370, 0x0376, 0x037a, 0x0388, 0x038e, 0x03a3, 0x03f7, 0x048a, + 0x0531, 0x0560, 0x05d0, 0x05ef, 0x0620, 0x066e, 0x0671, 0x06e5, 0x06ee, 0x06fa, 0x0712, 0x074d, 0x07ca, 0x07f4, + 0x0800, 0x0840, 0x0860, 0x08a0, 0x08b6, 0x0904, 0x0958, 0x0971, 0x0985, 0x098f, 0x0993, 0x09aa, 0x09b6, 0x09dc, + 0x09df, 0x09f0, 0x0a05, 0x0a0f, 0x0a13, 0x0a2a, 0x0a32, 0x0a35, 0x0a38, 0x0a59, 0x0a72, 0x0a85, 0x0a8f, 0x0a93, + 0x0aaa, 0x0ab2, 0x0ab5, 0x0ae0, 0x0b05, 0x0b0f, 0x0b13, 0x0b2a, 0x0b32, 0x0b35, 0x0b5c, 0x0b5f, 0x0b85, 0x0b8e, + 0x0b92, 0x0b99, 0x0b9e, 0x0ba3, 0x0ba8, 0x0bae, 0x0c05, 0x0c0e, 0x0c12, 0x0c2a, 0x0c58, 0x0c60, 0x0c85, 0x0c8e, + 0x0c92, 0x0caa, 0x0cb5, 0x0ce0, 0x0cf1, 0x0d04, 0x0d0e, 0x0d12, 0x0d54, 0x0d5f, 0x0d7a, 0x0d85, 0x0d9a, 0x0db3, + 0x0dc0, 0x0e01, 0x0e32, 0x0e40, 0x0e81, 0x0e86, 0x0e8c, 0x0ea7, 0x0eb2, 0x0ec0, 0x0edc, 0x0f40, 0x0f49, 0x0f88, + 0x1000, 0x1050, 0x105a, 0x1065, 0x106e, 0x1075, 0x10a0, 0x10d0, 0x10fc, 0x11fc, 0x124a, 0x1250, 0x125a, 0x1260, + 0x128a, 0x1290, 0x12b2, 0x12b8, 0x12c2, 0x12c8, 0x12d8, 0x1312, 0x1318, 0x1380, 0x13a0, 0x13f8, 0x1401, 0x1501, + 0x1601, 0x166f, 0x1681, 0x16a0, 0x16ee, 0x1700, 0x170e, 0x1720, 0x1740, 0x1760, 0x176e, 0x1780, 0x1820, 0x1880, + 0x18b0, 0x1900, 0x1950, 0x1970, 0x1980, 0x19b0, 0x1a00, 0x1a20, 0x1b05, 0x1b45, 0x1b83, 0x1bae, 0x1bba, 0x1c00, + 0x1c4d, 0x1c5a, 0x1c80, 0x1c90, 0x1cbd, 0x1ce9, 0x1cee, 0x1cf5, 0x1d00, 0x1e00, 0x1f00, 0x1f18, 0x1f20, 0x1f48, + 0x1f50, 0x1f5f, 0x1f80, 0x1fb6, 0x1fc2, 0x1fc6, 0x1fd0, 0x1fd6, 0x1fe0, 0x1ff2, 0x1ff6, 0x2090, 0x210a, 0x2118, + 0x212a, 0x213c, 0x2145, 0x2160, 0x2c00, 0x2c30, 0x2c60, 0x2ceb, 0x2cf2, 0x2d00, 0x2d30, 0x2d80, 0x2da0, 0x2da8, + 0x2db0, 0x2db8, 0x2dc0, 0x2dc8, 0x2dd0, 0x2dd8, 0x3005, 0x3021, 0x3031, 0x3038, 0x3041, 0x309b, 0x30a1, 0x30fc, + 0x3105, 0x3131, 0x31a0, 0x31f0, 0x3400, 0x3500, 0x3600, 0x3700, 0x3800, 0x3900, 0x3a00, 0x3b00, 0x3c00, 0x3d00, + 0x3e00, 0x3f00, 0x4000, 0x4100, 0x4200, 0x4300, 0x4400, 0x4500, 0x4600, 0x4700, 0x4800, 0x4900, 0x4a00, 0x4b00, + 0x4c00, 0x4d00, 0x4e00, 0x4f00, 0x5000, 0x5100, 0x5200, 0x5300, 0x5400, 0x5500, 0x5600, 0x5700, 0x5800, 0x5900, + 0x5a00, 0x5b00, 0x5c00, 0x5d00, 0x5e00, 0x5f00, 0x6000, 0x6100, 0x6200, 0x6300, 0x6400, 0x6500, 0x6600, 0x6700, + 0x6800, 0x6900, 0x6a00, 0x6b00, 0x6c00, 0x6d00, 0x6e00, 0x6f00, 0x7000, 0x7100, 0x7200, 0x7300, 0x7400, 0x7500, + 0x7600, 0x7700, 0x7800, 0x7900, 0x7a00, 0x7b00, 0x7c00, 0x7d00, 0x7e00, 0x7f00, 0x8000, 0x8100, 0x8200, 0x8300, + 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, 0x8900, 0x8a00, 0x8b00, 0x8c00, 0x8d00, 0x8e00, 0x8f00, 0x9000, 0x9100, + 0x9200, 0x9300, 0x9400, 0x9500, 0x9600, 0x9700, 0x9800, 0x9900, 0x9a00, 0x9b00, 0x9c00, 0x9d00, 0x9e00, 0x9f00, + 0xa000, 0xa100, 0xa200, 0xa300, 0xa400, 0xa4d0, 0xa500, 0xa600, 0xa610, 0xa62a, 0xa640, 0xa67f, 0xa6a0, 0xa717, + 0xa722, 0xa78b, 0xa7c2, 0xa7f5, 0xa803, 0xa807, 0xa80c, 0xa840, 0xa882, 0xa8f2, 0xa8fd, 0xa90a, 0xa930, 0xa960, + 0xa984, 0xa9e0, 0xa9e6, 0xa9fa, 0xaa00, 0xaa40, 0xaa44, 0xaa60, 0xaa7e, 0xaab5, 0xaab9, 0xaadb, 0xaae0, 0xaaf2, + 0xab01, 0xab09, 0xab11, 0xab20, 0xab28, 0xab30, 0xab5c, 0xab70, 0xac00, 0xad00, 0xae00, 0xaf00, 0xb000, 0xb100, + 0xb200, 0xb300, 0xb400, 0xb500, 0xb600, 0xb700, 0xb800, 0xb900, 0xba00, 0xbb00, 0xbc00, 0xbd00, 0xbe00, 0xbf00, + 0xc000, 0xc100, 0xc200, 0xc300, 0xc400, 0xc500, 0xc600, 0xc700, 0xc800, 0xc900, 0xca00, 0xcb00, 0xcc00, 0xcd00, + 0xce00, 0xcf00, 0xd000, 0xd100, 0xd200, 0xd300, 0xd400, 0xd500, 0xd600, 0xd700, 0xd7b0, 0xd7cb, 0xf900, 0xfa00, + 0xfa70, 0xfb00, 0xfb13, 0xfb1f, 0xfb2a, 0xfb38, 0xfb40, 0xfb43, 0xfb46, 0xfbd3, 0xfcd3, 0xfd50, 0xfd92, 0xfdf0, + 0xfe70, 0xfe76, 0xff21, 0xff41, 0xff66, 0xffc2, 0xffca, 0xffd2, 0xffda +}; + +/** + * Character interval lengths for ID_Start. + */ +static const uint8_t lit_unicode_id_start_interval_lengths[] JERRY_ATTR_CONST_DATA = { + 0x0016, 0x001e, 0x00ff, 0x00c9, 0x000b, 0x0004, 0x0004, 0x0001, 0x0003, 0x0002, 0x0013, 0x0052, 0x008a, 0x00a5, + 0x0025, 0x0028, 0x001a, 0x0003, 0x002a, 0x0001, 0x0062, 0x0001, 0x0001, 0x0002, 0x001d, 0x0058, 0x0020, 0x0001, + 0x0015, 0x0018, 0x000a, 0x0014, 0x0011, 0x0035, 0x0009, 0x000f, 0x0007, 0x0001, 0x0015, 0x0006, 0x0003, 0x0001, + 0x0002, 0x0001, 0x0005, 0x0001, 0x0015, 0x0006, 0x0001, 0x0001, 0x0001, 0x0003, 0x0002, 0x0008, 0x0002, 0x0015, + 0x0006, 0x0001, 0x0004, 0x0001, 0x0007, 0x0001, 0x0015, 0x0006, 0x0001, 0x0004, 0x0001, 0x0002, 0x0005, 0x0002, + 0x0003, 0x0001, 0x0001, 0x0001, 0x0002, 0x000b, 0x0007, 0x0002, 0x0016, 0x000f, 0x0002, 0x0001, 0x0007, 0x0002, + 0x0016, 0x0009, 0x0004, 0x0001, 0x0001, 0x0008, 0x0002, 0x0028, 0x0002, 0x0002, 0x0005, 0x0011, 0x0017, 0x0008, + 0x0006, 0x002f, 0x0001, 0x0006, 0x0001, 0x0004, 0x0017, 0x0009, 0x0001, 0x0004, 0x0003, 0x0007, 0x0023, 0x0004, + 0x002a, 0x0005, 0x0003, 0x0001, 0x0002, 0x000c, 0x0025, 0x002a, 0x00ff, 0x004c, 0x0003, 0x0006, 0x0003, 0x0028, + 0x0003, 0x0020, 0x0003, 0x0006, 0x0003, 0x000e, 0x0038, 0x0003, 0x0042, 0x000f, 0x0055, 0x0005, 0x00ff, 0x00ff, + 0x006b, 0x0010, 0x0019, 0x004a, 0x000a, 0x000c, 0x0003, 0x0011, 0x0011, 0x000c, 0x0002, 0x0033, 0x0058, 0x0028, + 0x0045, 0x001e, 0x001d, 0x0004, 0x002b, 0x0019, 0x0016, 0x0034, 0x002e, 0x0006, 0x001d, 0x0001, 0x002b, 0x0023, + 0x0002, 0x0023, 0x0008, 0x002a, 0x0002, 0x0003, 0x0005, 0x0001, 0x00bf, 0x00ff, 0x0015, 0x0005, 0x0025, 0x0005, + 0x0007, 0x001e, 0x0034, 0x0006, 0x0002, 0x0006, 0x0003, 0x0005, 0x000c, 0x0002, 0x0006, 0x000c, 0x0009, 0x0005, + 0x000f, 0x0003, 0x0004, 0x0028, 0x002e, 0x002e, 0x0084, 0x0003, 0x0001, 0x0025, 0x0037, 0x0016, 0x0006, 0x0006, + 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0002, 0x0008, 0x0004, 0x0004, 0x0055, 0x0004, 0x0059, 0x0003, + 0x002a, 0x005d, 0x001f, 0x000f, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00bf, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00fc, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x008c, 0x002d, 0x00ff, 0x000c, 0x000f, 0x0001, 0x002e, 0x001e, 0x004f, 0x0008, + 0x0066, 0x0034, 0x0008, 0x000c, 0x0002, 0x0003, 0x0016, 0x0033, 0x0031, 0x0005, 0x0001, 0x001b, 0x0016, 0x001c, + 0x002e, 0x0004, 0x0009, 0x0004, 0x0028, 0x0002, 0x0007, 0x0016, 0x0031, 0x0001, 0x0004, 0x0002, 0x000a, 0x0002, + 0x0005, 0x0005, 0x0005, 0x0006, 0x0006, 0x002a, 0x000d, 0x0072, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, + 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x00a3, 0x0016, 0x0030, 0x00ff, 0x006d, + 0x0069, 0x0006, 0x0004, 0x0009, 0x000c, 0x0004, 0x0001, 0x0001, 0x006b, 0x00ff, 0x006a, 0x003f, 0x0035, 0x000b, + 0x0004, 0x0086, 0x0019, 0x0019, 0x0058, 0x0005, 0x0005, 0x0005, 0x0002 +}; + +/** + * Non-interval characters for ID_Start. + */ +static const uint16_t lit_unicode_id_start_chars[] JERRY_ATTR_CONST_DATA = { + 0x00aa, 0x00b5, 0x00ba, 0x02ec, 0x02ee, 0x037f, 0x0386, 0x038c, 0x0559, 0x06d5, 0x06ff, 0x0710, 0x07b1, 0x07fa, + 0x081a, 0x0824, 0x0828, 0x093d, 0x0950, 0x09b2, 0x09bd, 0x09ce, 0x09fc, 0x0a5e, 0x0abd, 0x0ad0, 0x0af9, 0x0b3d, + 0x0b71, 0x0b83, 0x0b9c, 0x0bd0, 0x0c3d, 0x0c80, 0x0cbd, 0x0cde, 0x0d3d, 0x0d4e, 0x0dbd, 0x0e84, 0x0ea5, 0x0ebd, + 0x0ec6, 0x0f00, 0x103f, 0x1061, 0x108e, 0x10c7, 0x10cd, 0x1258, 0x12c0, 0x17d7, 0x17dc, 0x18aa, 0x1aa7, 0x1cfa, + 0x1f59, 0x1f5b, 0x1f5d, 0x1fbe, 0x2071, 0x207f, 0x2102, 0x2107, 0x2115, 0x2124, 0x2126, 0x2128, 0x214e, 0x2d27, + 0x2d2d, 0x2d6f, 0xa8fb, 0xa9cf, 0xaa7a, 0xaab1, 0xaac0, 0xaac2, 0xfb1d, 0xfb3e +}; + +/** + * Character interval starting points for ID_Continue. + */ +static const uint16_t lit_unicode_id_continue_interval_starts[] JERRY_ATTR_CONST_DATA = { + 0x0300, 0x0483, 0x0591, 0x05c1, 0x05c4, 0x0610, 0x064b, 0x06d6, 0x06df, 0x06e7, 0x06ea, 0x06f0, 0x0730, 0x07a6, + 0x07c0, 0x07eb, 0x0816, 0x081b, 0x0825, 0x0829, 0x0859, 0x08d3, 0x08e3, 0x093a, 0x093e, 0x0951, 0x0962, 0x0966, + 0x0981, 0x09be, 0x09c7, 0x09cb, 0x09e2, 0x09e6, 0x0a01, 0x0a3e, 0x0a47, 0x0a4b, 0x0a66, 0x0a81, 0x0abe, 0x0ac7, + 0x0acb, 0x0ae2, 0x0ae6, 0x0afa, 0x0b01, 0x0b3e, 0x0b47, 0x0b4b, 0x0b55, 0x0b62, 0x0b66, 0x0bbe, 0x0bc6, 0x0bca, + 0x0be6, 0x0c00, 0x0c3e, 0x0c46, 0x0c4a, 0x0c55, 0x0c62, 0x0c66, 0x0c81, 0x0cbe, 0x0cc6, 0x0cca, 0x0cd5, 0x0ce2, + 0x0ce6, 0x0d00, 0x0d3b, 0x0d3e, 0x0d46, 0x0d4a, 0x0d62, 0x0d66, 0x0d81, 0x0dcf, 0x0dd8, 0x0de6, 0x0df2, 0x0e34, + 0x0e47, 0x0e50, 0x0eb4, 0x0ec8, 0x0ed0, 0x0f18, 0x0f20, 0x0f3e, 0x0f71, 0x0f86, 0x0f8d, 0x0f99, 0x102b, 0x1040, + 0x1056, 0x105e, 0x1062, 0x1067, 0x1071, 0x1082, 0x108f, 0x135d, 0x1369, 0x1712, 0x1732, 0x1752, 0x1772, 0x17b4, + 0x17e0, 0x180b, 0x1810, 0x1920, 0x1930, 0x1946, 0x19d0, 0x1a17, 0x1a55, 0x1a60, 0x1a7f, 0x1a90, 0x1ab0, 0x1abf, + 0x1b00, 0x1b34, 0x1b50, 0x1b6b, 0x1b80, 0x1ba1, 0x1bb0, 0x1be6, 0x1c24, 0x1c40, 0x1c50, 0x1cd0, 0x1cd4, 0x1cf7, + 0x1dc0, 0x1dfb, 0x200c, 0x203f, 0x20d0, 0x20e5, 0x2cef, 0x2de0, 0x302a, 0x3099, 0xa620, 0xa674, 0xa69e, 0xa6f0, + 0xa823, 0xa880, 0xa8b4, 0xa8d0, 0xa8e0, 0xa8ff, 0xa926, 0xa947, 0xa980, 0xa9b3, 0xa9d0, 0xa9f0, 0xaa29, 0xaa4c, + 0xaa50, 0xaa7b, 0xaab2, 0xaab7, 0xaabe, 0xaaeb, 0xaaf5, 0xabe3, 0xabec, 0xabf0, 0xfe00, 0xfe20, 0xfe33, 0xfe4d, + 0xff10 +}; + +/** + * Character interval lengths for ID_Continue. + */ +static const uint8_t lit_unicode_id_continue_interval_lengths[] JERRY_ATTR_CONST_DATA = { + 0x006f, 0x0004, 0x002c, 0x0001, 0x0001, 0x000a, 0x001e, 0x0006, 0x0005, 0x0001, 0x0003, 0x0009, 0x001a, 0x000a, + 0x0009, 0x0008, 0x0003, 0x0008, 0x0002, 0x0004, 0x0002, 0x000e, 0x0020, 0x0002, 0x0011, 0x0006, 0x0001, 0x0009, + 0x0002, 0x0006, 0x0001, 0x0002, 0x0001, 0x0009, 0x0002, 0x0004, 0x0001, 0x0002, 0x000b, 0x0002, 0x0007, 0x0002, + 0x0002, 0x0001, 0x0009, 0x0005, 0x0002, 0x0006, 0x0001, 0x0002, 0x0002, 0x0001, 0x0009, 0x0004, 0x0002, 0x0003, + 0x0009, 0x0004, 0x0006, 0x0002, 0x0003, 0x0001, 0x0001, 0x0009, 0x0002, 0x0006, 0x0002, 0x0003, 0x0001, 0x0001, + 0x0009, 0x0003, 0x0001, 0x0006, 0x0002, 0x0003, 0x0001, 0x0009, 0x0002, 0x0005, 0x0007, 0x0009, 0x0001, 0x0006, + 0x0007, 0x0009, 0x0008, 0x0005, 0x0009, 0x0001, 0x0009, 0x0001, 0x0013, 0x0001, 0x000a, 0x0023, 0x0013, 0x0009, + 0x0003, 0x0002, 0x0002, 0x0006, 0x0003, 0x000b, 0x000e, 0x0002, 0x0008, 0x0002, 0x0002, 0x0001, 0x0001, 0x001f, + 0x0009, 0x0002, 0x0009, 0x000b, 0x000b, 0x0009, 0x000a, 0x0004, 0x0009, 0x001c, 0x000a, 0x0009, 0x000d, 0x0001, + 0x0004, 0x0010, 0x0009, 0x0008, 0x0002, 0x000c, 0x0009, 0x000d, 0x0013, 0x0009, 0x0009, 0x0002, 0x0014, 0x0002, + 0x0039, 0x0004, 0x0001, 0x0001, 0x000c, 0x000b, 0x0002, 0x001f, 0x0005, 0x0001, 0x0009, 0x0009, 0x0001, 0x0001, + 0x0004, 0x0001, 0x0011, 0x0009, 0x0011, 0x000a, 0x0007, 0x000c, 0x0003, 0x000d, 0x0009, 0x0009, 0x000d, 0x0001, + 0x0009, 0x0002, 0x0002, 0x0001, 0x0001, 0x0004, 0x0001, 0x0007, 0x0001, 0x0009, 0x000f, 0x000f, 0x0001, 0x0002, + 0x0009 +}; + +/** + * Non-interval characters for ID_Continue. + */ +static const uint16_t lit_unicode_id_continue_chars[] JERRY_ATTR_CONST_DATA = { + 0x00b7, 0x0387, 0x05bf, 0x05c7, 0x0670, 0x0711, 0x07fd, 0x09bc, 0x09d7, 0x09fe, 0x0a3c, 0x0a51, + 0x0a75, 0x0abc, 0x0b3c, 0x0b82, 0x0bd7, 0x0cbc, 0x0d57, 0x0dca, 0x0dd6, 0x0e31, 0x0eb1, 0x0f35, + 0x0f37, 0x0f39, 0x0fc6, 0x17dd, 0x18a9, 0x1ced, 0x1cf4, 0x2054, 0x20e1, 0x2d7f, 0xa66f, 0xa802, + 0xa806, 0xa80b, 0xa82c, 0xa9e5, 0xaa43, 0xaab0, 0xaac1, 0xfb1e, 0xff3f +}; + +/** + * Character interval starting points for White_Space. + */ +static const uint16_t lit_unicode_white_space_interval_starts[] JERRY_ATTR_CONST_DATA = { 0x2000 }; + +/** + * Character interval lengths for White_Space. + */ +static const uint8_t lit_unicode_white_space_interval_lengths[] JERRY_ATTR_CONST_DATA = { 0x000a }; + +/** + * Non-interval characters for White_Space. + */ +static const uint16_t lit_unicode_white_space_chars[] JERRY_ATTR_CONST_DATA = { 0x00a0, + 0x1680, + 0x202f, + 0x205f, + 0x3000 }; diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/meson.build new file mode 100644 index 0000000..83faa5f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/lit/meson.build @@ -0,0 +1,20 @@ +source_file = [ + 'lit-char-helpers.h', + 'lit-globals.h', + 'lit-magic-strings.h', + 'lit-magic-strings.inc.h', + 'lit-strings.h', + 'lit-unicode-conversions-sup.inc.h', + 'lit-unicode-conversions.inc.h', + 'lit-unicode-folding.inc.h', + 'lit-unicode-ranges-sup.inc.h', + 'lit-unicode-ranges.inc.h', + 'lit-char-helpers.cpp', + 'lit-magic-strings.cpp', + 'lit-strings.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/meson.build new file mode 100644 index 0000000..adbbffb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/meson.build @@ -0,0 +1,9 @@ +subdir('api') +subdir('include') +subdir('ecma') +subdir('jcontext') +subdir('jmem') +subdir('jrt') +subdir('lit') +subdir('parser') +subdir('vm') diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/byte-code.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/byte-code.cpp new file mode 100644 index 0000000..d2c4fc1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/byte-code.cpp @@ -0,0 +1,86 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-internal.h" + +/* These two checks only checks the compiler, they have no effect on the code. */ +JERRY_STATIC_ASSERT ((sizeof (cbc_uint8_arguments_t) == 16), sizeof_cbc_uint8_arguments_t_must_be_16_byte_long); + +JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) == 24), sizeof_cbc_uint16_arguments_t_must_be_24_byte_long); + +JERRY_STATIC_ASSERT ((offsetof (cbc_uint8_arguments_t, script_value) == offsetof (cbc_uint16_arguments_t, script_value)), + script_value_in_cbc_uint8_arguments_and_cbc_uint16_arguments_must_be_in_the_same_offset); + +/** + * The reason of these two static asserts to notify the developer to increase the JERRY_SNAPSHOT_VERSION + * whenever new bytecodes are introduced or existing ones have been deleted. + */ +JERRY_STATIC_ASSERT ((((int) CBC_END) == 238), number_of_cbc_opcodes_changed); +JERRY_STATIC_ASSERT ((((int) CBC_EXT_END) == 167), number_of_cbc_ext_opcodes_changed); + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_bytecode Bytecode + * @{ + */ + +#if JERRY_PARSER || JERRY_PARSER_DUMP_BYTE_CODE + +/** + * Compact bytecode definition + */ +#define CBC_OPCODE(arg1, arg2, arg3, arg4) ((arg2) | (((arg3) + CBC_STACK_ADJUST_BASE) << CBC_STACK_ADJUST_SHIFT)), + +/** + * Flags of the opcodes. + */ +const uint8_t cbc_flags[] JERRY_ATTR_CONST_DATA = { CBC_OPCODE_LIST }; + +/** + * Flags of the extended opcodes. + */ +const uint8_t cbc_ext_flags[] = { CBC_EXT_OPCODE_LIST }; + +#undef CBC_OPCODE + +#endif /* JERRY_PARSER || JERRY_PARSER_DUMP_BYTE_CODE */ + +#if JERRY_PARSER_DUMP_BYTE_CODE + +#define CBC_OPCODE(arg1, arg2, arg3, arg4) #arg1, + +/** + * Names of the opcodes. + */ +const char* const cbc_names[] = { CBC_OPCODE_LIST }; + +/** + * Names of the extended opcodes. + */ +const char* const cbc_ext_names[] = { CBC_EXT_OPCODE_LIST }; + +#undef CBC_OPCODE + +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/byte-code.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/byte-code.h new file mode 100644 index 0000000..a4df0de --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/byte-code.h @@ -0,0 +1,1051 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BYTE_CODE_H +#define BYTE_CODE_H + +#include "ecma-globals.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_bytecode Bytecode + * @{ + */ + +/** + * Compact byte code (CBC) is a byte code representation + * of EcmaScript which is designed for low memory + * environments. Most opcodes are only one or sometimes + * two byte long so the CBC provides a small binary size. + * + * The execution engine of CBC is a stack machine, where + * the maximum stack size is known in advance for each + * function. + */ + +/** + * Byte code flags. Only the lower 5 bit can be used + * since the stack change is encoded in the upper + * three bits for each instruction between -4 and 3 + * (except for call / construct opcodes). + */ +#define CBC_STACK_ADJUST_BASE 4 +#define CBC_STACK_ADJUST_SHIFT 5 +#define CBC_STACK_ADJUST_VALUE(value) (((value) >> CBC_STACK_ADJUST_SHIFT) - CBC_STACK_ADJUST_BASE) + +#define CBC_NO_FLAG 0x00u +#define CBC_HAS_LITERAL_ARG 0x01u +#define CBC_HAS_LITERAL_ARG2 0x02u +#define CBC_HAS_BYTE_ARG 0x04u +#define CBC_HAS_BRANCH_ARG 0x08u + +/* These flags are shared */ +#define CBC_FORWARD_BRANCH_ARG 0x10u +#define CBC_POP_STACK_BYTE_ARG 0x10u + +#define CBC_ARG_TYPES (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2 | CBC_HAS_BYTE_ARG | CBC_HAS_BRANCH_ARG) + +#define CBC_HAS_POP_STACK_BYTE_ARG (CBC_HAS_BYTE_ARG | CBC_POP_STACK_BYTE_ARG) + +/** + * CBC_NO_RESULT_OPERATION for ext opcodes + */ +#define CBC_EXT_NO_RESULT_OPERATION(opcode) \ + ((opcode) >= PARSER_TO_EXT_OPCODE (CBC_EXT_ASSIGN_SUPER) \ + && (opcode) <= PARSER_TO_EXT_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK)) + +/* Debug macro. */ +#define CBC_ARGS_EQ(op, types) ((cbc_flags[op] & CBC_ARG_TYPES) == (types)) + +/* Debug macro. */ +#define CBC_SAME_ARGS(op1, op2) \ + (CBC_EXT_NO_RESULT_OPERATION (op1) ? ((cbc_ext_flags[PARSER_GET_EXT_OPCODE (op1)] & CBC_ARG_TYPES) \ + == (cbc_ext_flags[PARSER_GET_EXT_OPCODE (op2)] & CBC_ARG_TYPES)) \ + : ((cbc_flags[op1] & CBC_ARG_TYPES) == (cbc_flags[op2] & CBC_ARG_TYPES))) + +#define CBC_UNARY_OPERATION(name, group) \ + CBC_OPCODE (name, CBC_NO_FLAG, 0, (VM_OC_##group) | VM_OC_GET_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_LITERAL, CBC_HAS_LITERAL_ARG, 1, (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) + +#define CBC_BINARY_OPERATION(name, group) \ + CBC_OPCODE (name, CBC_NO_FLAG, -1, (VM_OC_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_RIGHT_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + (VM_OC_##group) | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_TWO_LITERALS, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + (VM_OC_##group) | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) + +#define CBC_UNARY_LVALUE_OPERATION(name, group) \ + CBC_OPCODE (name, CBC_NO_FLAG, -2, (VM_OC_PROP_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (name##_PUSH_RESULT, \ + CBC_NO_FLAG, \ + -1, \ + (VM_OC_PROP_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_BLOCK, \ + CBC_NO_FLAG, \ + -2, \ + (VM_OC_PROP_##group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (name##_IDENT, CBC_HAS_LITERAL_ARG, 0, (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ + CBC_OPCODE (name##_IDENT_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ + CBC_OPCODE (name##_IDENT_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + (VM_OC_##group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) + +#define CBC_UNARY_LVALUE_WITH_IDENT 3 + +#define CBC_BINARY_WITH_LITERAL 1 +#define CBC_BINARY_WITH_TWO_LITERALS 2 + +/** + * Several opcodes (mostly call and assignment opcodes) have + * two forms: one which does not push a return value onto + * the stack, and another which does. The reason is that + * the return value of these opcodes are often not used + * and the first form provides smaller byte code. + * + * The following rules must be kept by the code generator: + * - only the opcode without return value can be emitted + * by the code generator + * - the first form can be converted to the second form + * by adding 1 to the opcode + * - after the conversion the opcode must be immediately + * flushed, so no further changes are possible + * + * Hence CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode) + * cannot be true for an opcode which has a result + */ +#define CBC_NO_RESULT_OPERATION(opcode) \ + (((opcode) >= CBC_PRE_INCR && (opcode) < CBC_END) || CBC_EXT_NO_RESULT_OPERATION ((opcode))) + +/** + * Branch instructions are organized in group of 8 opcodes. + * - 1st opcode: unused, can be used for other purpose + * - 2nd opcode: forward branch with 1 byte offset + * - 3rd opcode: forward branch with 2 byte offset + * - 4th opcode: forward branch with 3 byte offset + * - 5th opcode: unused, can be used for other purpose + * - 6th opcode: backward branch with 1 byte offset + * - 7th opcode: backward branch with 2 byte offset + * - 8th opcode: backward branch with 3 byte offset + * + * Reasons: + * The branch_opcode & 0x3 tells the length in bytes of the offset + * If branch offset & 0x4 == 0, it is a forward branch. Otherwise + * it is backward. + * + * The offset bytes are encoded in higher to lower order. + */ + +#define CBC_FORWARD_BRANCH(name, stack, vm_oc) \ + CBC_OPCODE (name, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH) \ + CBC_OPCODE (name##_2, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH) \ + CBC_OPCODE (name##_3, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH) + +#define CBC_BACKWARD_BRANCH(name, stack, vm_oc) \ + CBC_OPCODE (name, CBC_HAS_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \ + CBC_OPCODE (name##_2, CBC_HAS_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \ + CBC_OPCODE (name##_3, CBC_HAS_BRANCH_ARG, stack, (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) + +#define CBC_BRANCH_OFFSET_LENGTH(opcode) ((opcode) &0x3) + +#define CBC_BRANCH_IS_BACKWARD(flags) (!((flags) &CBC_FORWARD_BRANCH_ARG)) + +#define CBC_BRANCH_IS_FORWARD(flags) ((flags) &CBC_FORWARD_BRANCH_ARG) + +/* Stack consumption of opcodes with context. */ + +/* PARSER_TRY_CONTEXT_STACK_ALLOCATION must be <= 3 */ +#define PARSER_TRY_CONTEXT_STACK_ALLOCATION 1 +/* PARSER_FINALLY_CONTEXT_STACK_ALLOCATION must be <= 3 */ +#define PARSER_FINALLY_CONTEXT_STACK_ALLOCATION 2 +/* PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION must be <= 4 */ +#define PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION 4 +/* PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION must be <= 4 */ +#define PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION 4 +/* PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION must be <= 4 */ +#define PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION 4 +/* PARSER_WITH_CONTEXT_STACK_ALLOCATION must be <= 4 */ +#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 1 +/* PARSER_BLOCK_CONTEXT_STACK_ALLOCATION must be <= 3 */ +#define PARSER_BLOCK_CONTEXT_STACK_ALLOCATION 1 +/* PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION must be <= 3 */ +#define PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION 3 +/* PARSER_OBJECT_INITIALIZER_CONTEXT_STACK_ALLOCATION must be <= 2 */ +#define PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION 1 +/* PARSER_OBJECT_INITIALIZER_CONTEXT_STACK_ALLOCATION must be <= 2 */ +#define PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION 2 + +/** + * Extra stack consumption for finally context. + */ +#define PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION \ + (PARSER_FINALLY_CONTEXT_STACK_ALLOCATION - PARSER_TRY_CONTEXT_STACK_ALLOCATION) + +#define PARSER_STATIC_PRIVATE_TO_PRIVATE_OFFSET (CBC_EXT_COLLECT_PRIVATE_STATIC_FIELD - CBC_EXT_COLLECT_PRIVATE_FIELD) + +/** + * Opcode definitions. + */ +#define CBC_OPCODE_LIST \ + /* Branch opcodes first. Some other opcodes are mixed. */ \ + CBC_OPCODE (CBC_EXT_OPCODE, CBC_NO_FLAG, 0, VM_OC_NONE) \ + CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD, 0, VM_OC_JUMP) \ + CBC_OPCODE (CBC_POP, CBC_NO_FLAG, -1, VM_OC_POP) \ + CBC_BACKWARD_BRANCH (CBC_JUMP_BACKWARD, 0, VM_OC_JUMP) \ + CBC_OPCODE (CBC_POP_BLOCK, CBC_NO_FLAG, -1, VM_OC_POP_BLOCK | VM_OC_PUT_BLOCK) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_TRUE_FORWARD, -1, VM_OC_BRANCH_IF_TRUE) \ + CBC_OPCODE (CBC_THROW, CBC_NO_FLAG, -1, VM_OC_THROW | VM_OC_GET_STACK) \ + CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_TRUE_BACKWARD, -1, VM_OC_BRANCH_IF_TRUE) \ + CBC_OPCODE (CBC_CONTEXT_END, CBC_NO_FLAG, 0, VM_OC_CONTEXT_END) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_FALSE_FORWARD, -1, VM_OC_BRANCH_IF_FALSE) \ + CBC_OPCODE (CBC_CREATE_OBJECT, CBC_NO_FLAG, 1, VM_OC_PUSH_OBJECT | VM_OC_PUT_STACK) \ + CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_FALSE_BACKWARD, -1, VM_OC_BRANCH_IF_FALSE) \ + CBC_OPCODE (CBC_SET_PROPERTY, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \ + CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD_EXIT_CONTEXT, 0, VM_OC_JUMP_AND_EXIT_CONTEXT) \ + CBC_OPCODE (CBC_CREATE_ARRAY, CBC_NO_FLAG, 1, VM_OC_PUSH_ARRAY | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_TRUE, -1, VM_OC_BRANCH_IF_LOGICAL_TRUE) \ + CBC_OPCODE (CBC_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_APPEND_ARRAY) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_FALSE, -1, VM_OC_BRANCH_IF_LOGICAL_FALSE) \ + CBC_OPCODE (CBC_PUSH_ELISION, CBC_NO_FLAG, 1, VM_OC_PUSH_ELISON | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_BRANCH_IF_STRICT_EQUAL, -1, VM_OC_BRANCH_IF_STRICT_EQUAL) \ + CBC_OPCODE (CBC_PUSH_NULL, CBC_NO_FLAG, 1, VM_OC_PUSH_NULL | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_BLOCK_CREATE_CONTEXT, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION, VM_OC_BLOCK_CREATE_CONTEXT) \ + \ + /* Basic opcodes. Note: These 4 opcodes must me in this order */ \ + CBC_OPCODE (CBC_PUSH_LITERAL, CBC_HAS_LITERAL_ARG, 1, VM_OC_PUSH | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_PUSH_TWO_LITERALS, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 2, \ + VM_OC_PUSH_TWO | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_PUSH_THIS_LITERAL, CBC_HAS_LITERAL_ARG, 2, VM_OC_PUSH_TWO | VM_OC_GET_THIS_LITERAL) \ + CBC_OPCODE (CBC_PUSH_THREE_LITERALS, CBC_HAS_LITERAL_ARG2, 3, VM_OC_PUSH_THREE | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_PUSH_UNDEFINED, CBC_NO_FLAG, 1, VM_OC_PUSH_UNDEFINED | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_TRUE, CBC_NO_FLAG, 1, VM_OC_PUSH_TRUE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_FALSE, CBC_NO_FLAG, 1, VM_OC_PUSH_FALSE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_THIS, CBC_NO_FLAG, 1, VM_OC_PUSH_THIS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_NUMBER_0, CBC_NO_FLAG, 1, VM_OC_PUSH_0 | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_NUMBER_POS_BYTE, CBC_HAS_BYTE_ARG, 1, VM_OC_PUSH_POS_BYTE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_NUMBER_NEG_BYTE, CBC_HAS_BYTE_ARG, 1, VM_OC_PUSH_NEG_BYTE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_0, CBC_HAS_LITERAL_ARG, 2, VM_OC_PUSH_LIT_0 | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, \ + 2, \ + VM_OC_PUSH_LIT_POS_BYTE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, \ + 2, \ + VM_OC_PUSH_LIT_NEG_BYTE | VM_OC_GET_LITERAL) \ + /* Note: These 4 opcodes must me in this order */ \ + CBC_OPCODE (CBC_PUSH_PROP, CBC_NO_FLAG, -1, VM_OC_PROP_GET | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_PROP_GET | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_PROP_GET | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_PROP_GET | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_IDENT_REFERENCE, CBC_HAS_LITERAL_ARG, 3, VM_OC_IDENT_REFERENCE | VM_OC_PUT_STACK) \ + /* Note: These 4 opcodes must me in this order */ \ + CBC_OPCODE (CBC_PUSH_PROP_REFERENCE, CBC_NO_FLAG, 1, VM_OC_PROP_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 2, \ + VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 3, \ + VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 3, \ + VM_OC_PROP_REFERENCE | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_NEW | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_NEW0, CBC_NO_FLAG, 0, VM_OC_NEW | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_NEW1, CBC_NO_FLAG, -1, VM_OC_NEW | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EVAL, CBC_NO_FLAG, 0, VM_OC_EVAL) \ + CBC_OPCODE (CBC_CHECK_VAR, CBC_HAS_LITERAL_ARG, 0, VM_OC_CHECK_VAR) \ + CBC_OPCODE (CBC_CHECK_LET, CBC_HAS_LITERAL_ARG, 0, VM_OC_CHECK_LET) \ + CBC_OPCODE (CBC_CREATE_VAR, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_CREATE_LET, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_CREATE_CONST, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_CREATE_LOCAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_BINDING) \ + CBC_OPCODE (CBC_INIT_ARG_OR_CATCH, CBC_HAS_LITERAL_ARG, -1, VM_OC_INIT_BINDING) \ + CBC_OPCODE (CBC_INIT_LET, CBC_HAS_LITERAL_ARG, -1, VM_OC_INIT_BINDING) \ + CBC_OPCODE (CBC_INIT_CONST, CBC_HAS_LITERAL_ARG, -1, VM_OC_INIT_BINDING) \ + CBC_OPCODE (CBC_INIT_ARG_OR_FUNC, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_INIT_ARG_OR_FUNC) \ + CBC_OPCODE (CBC_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_VAR_EVAL) \ + CBC_OPCODE (CBC_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_VAR_EVAL) \ + CBC_OPCODE (CBC_SET_VAR_FUNC, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_SET_BYTECODE_PTR, CBC_NO_FLAG, 0, VM_OC_SET_BYTECODE_PTR) \ + CBC_OPCODE (CBC_RETURN, CBC_NO_FLAG, -1, VM_OC_RETURN | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_RETURN_FUNCTION_END, CBC_NO_FLAG, 0, VM_OC_RETURN_FUNCTION_END) \ + CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_RETURN | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_SET_LITERAL_PROPERTY, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_COPY_TO_GLOBAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COPY_TO_GLOBAL | VM_OC_GET_LITERAL) \ + \ + /* Unary opcodes. */ \ + CBC_UNARY_OPERATION (CBC_PLUS, PLUS) \ + CBC_UNARY_OPERATION (CBC_NEGATE, MINUS) \ + CBC_UNARY_OPERATION (CBC_LOGICAL_NOT, NOT) \ + CBC_UNARY_OPERATION (CBC_BIT_NOT, BIT_NOT) \ + CBC_UNARY_OPERATION (CBC_VOID, VOID) \ + CBC_OPCODE (CBC_TYPEOF, CBC_NO_FLAG, 0, VM_OC_TYPEOF | VM_OC_GET_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_TYPEOF_IDENT, CBC_HAS_LITERAL_ARG, 1, VM_OC_TYPEOF_IDENT | VM_OC_PUT_STACK) \ + \ + /* Binary opcodes. */ \ + CBC_BINARY_OPERATION (CBC_BIT_OR, BIT_OR) \ + CBC_BINARY_OPERATION (CBC_BIT_XOR, BIT_XOR) \ + CBC_BINARY_OPERATION (CBC_BIT_AND, BIT_AND) \ + CBC_BINARY_OPERATION (CBC_EQUAL, EQUAL) \ + CBC_BINARY_OPERATION (CBC_NOT_EQUAL, NOT_EQUAL) \ + CBC_BINARY_OPERATION (CBC_STRICT_EQUAL, STRICT_EQUAL) \ + CBC_BINARY_OPERATION (CBC_STRICT_NOT_EQUAL, STRICT_NOT_EQUAL) \ + CBC_BINARY_OPERATION (CBC_LESS, LESS) \ + CBC_BINARY_OPERATION (CBC_GREATER, GREATER) \ + CBC_BINARY_OPERATION (CBC_LESS_EQUAL, LESS_EQUAL) \ + CBC_BINARY_OPERATION (CBC_GREATER_EQUAL, GREATER_EQUAL) \ + CBC_BINARY_OPERATION (CBC_IN, IN) \ + CBC_BINARY_OPERATION (CBC_INSTANCEOF, INSTANCEOF) \ + CBC_BINARY_OPERATION (CBC_LEFT_SHIFT, LEFT_SHIFT) \ + CBC_BINARY_OPERATION (CBC_RIGHT_SHIFT, RIGHT_SHIFT) \ + CBC_BINARY_OPERATION (CBC_UNS_RIGHT_SHIFT, UNS_RIGHT_SHIFT) \ + CBC_BINARY_OPERATION (CBC_ADD, ADD) \ + CBC_BINARY_OPERATION (CBC_SUBTRACT, SUB) \ + CBC_BINARY_OPERATION (CBC_MULTIPLY, MUL) \ + CBC_BINARY_OPERATION (CBC_DIVIDE, DIV) \ + CBC_BINARY_OPERATION (CBC_MODULO, MOD) \ + CBC_BINARY_OPERATION (CBC_EXPONENTIATION, EXP) \ + \ + /* Unary lvalue opcodes. */ \ + CBC_OPCODE (CBC_DELETE_PUSH_RESULT, CBC_NO_FLAG, -1, VM_OC_PROP_DELETE | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_DELETE_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 1, VM_OC_DELETE | VM_OC_PUT_STACK) \ + CBC_UNARY_LVALUE_OPERATION (CBC_PRE_INCR, PRE_INCR) \ + CBC_UNARY_LVALUE_OPERATION (CBC_PRE_DECR, PRE_DECR) \ + CBC_UNARY_LVALUE_OPERATION (CBC_POST_INCR, POST_INCR) \ + CBC_UNARY_LVALUE_OPERATION (CBC_POST_DECR, POST_DECR) \ + \ + /* Call opcodes. */ \ + CBC_OPCODE (CBC_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL_PROP_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, -2, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL0, CBC_NO_FLAG, -1, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL0_PUSH_RESULT, CBC_NO_FLAG, 0, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL0_BLOCK, CBC_NO_FLAG, -1, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL0_PROP, CBC_NO_FLAG, -3, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL0_PROP_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL0_PROP_BLOCK, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL1, CBC_NO_FLAG, -2, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL1_PUSH_RESULT, CBC_NO_FLAG, -1, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL1_BLOCK, CBC_NO_FLAG, -2, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL1_PROP, CBC_NO_FLAG, -4, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL1_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL1_PROP_BLOCK, CBC_NO_FLAG, -4, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL2, CBC_NO_FLAG, -3, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL2_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL2_BLOCK, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_CALL2_PROP, CBC_NO_FLAG, -4, VM_OC_CALL) \ + CBC_OPCODE (CBC_CALL2_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, VM_OC_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_CALL2_PROP_BLOCK, CBC_NO_FLAG, -4, VM_OC_CALL | VM_OC_PUT_BLOCK) \ + \ + /* Binary assignment opcodes. */ \ + CBC_OPCODE (CBC_ASSIGN, CBC_NO_FLAG, -3, VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_ASSIGN_PUSH_RESULT, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_BLOCK, \ + CBC_NO_FLAG, \ + -3, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_SET_IDENT, CBC_HAS_LITERAL_ARG, -1, VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_ASSIGN_SET_IDENT_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_SET_IDENT_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_BLOCK, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + -2, \ + VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + -2, \ + VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_PUSH_RESULT, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_MOV_IDENT, CBC_HAS_LITERAL_ARG, -1, VM_OC_MOV_IDENT | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \ + CBC_OPCODE (CBC_ASSIGN_LET_CONST, CBC_HAS_LITERAL_ARG, -1, VM_OC_ASSIGN_LET_CONST | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_ASSIGN_LET_CONST_LITERAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_ASSIGN_LET_CONST | VM_OC_GET_LITERAL) \ + \ + /* Last opcode (not a real opcode). */ \ + CBC_OPCODE (CBC_END, CBC_NO_FLAG, 0, VM_OC_NONE) + +/* All EXT branches are statement block end + * marks, so they are always forward branches. */ + +#define CBC_EXT_OPCODE_LIST \ + /* Branch opcodes first. Some other opcodes are mixed. */ \ + CBC_OPCODE (CBC_EXT_NOP, CBC_NO_FLAG, 0, VM_OC_NONE) \ + CBC_FORWARD_BRANCH (CBC_EXT_WITH_CREATE_CONTEXT, -1 + PARSER_WITH_CONTEXT_STACK_ALLOCATION, VM_OC_WITH) \ + CBC_OPCODE (CBC_EXT_FOR_IN_GET_NEXT, CBC_NO_FLAG, 1, VM_OC_FOR_IN_GET_NEXT | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_EXT_FOR_IN_INIT, -1 + PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_IN_INIT) \ + CBC_OPCODE (CBC_EXT_SET_GETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ + CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_IN_HAS_NEXT, 0, VM_OC_FOR_IN_HAS_NEXT) \ + CBC_OPCODE (CBC_EXT_FOR_OF_GET_NEXT, CBC_NO_FLAG, 1, VM_OC_FOR_OF_GET_NEXT | VM_OC_PUT_STACK) \ + CBC_FORWARD_BRANCH (CBC_EXT_FOR_OF_INIT, -1 + PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_OF_INIT) \ + CBC_OPCODE (CBC_EXT_PUSH_NAMED_FUNC_EXPRESSION, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_PUSH_NAMED_FUNC_EXPR | VM_OC_GET_LITERAL_LITERAL) \ + CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_OF_HAS_NEXT, 0, VM_OC_FOR_OF_HAS_NEXT) \ + CBC_OPCODE (CBC_EXT_CLONE_CONTEXT, CBC_NO_FLAG, 0, VM_OC_CLONE_CONTEXT) \ + CBC_FORWARD_BRANCH (CBC_EXT_FOR_AWAIT_OF_INIT, \ + -1 + PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION, \ + VM_OC_FOR_AWAIT_OF_INIT) \ + CBC_OPCODE (CBC_EXT_CLONE_FULL_CONTEXT, CBC_NO_FLAG, 0, VM_OC_CLONE_CONTEXT) \ + CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_AWAIT_OF_HAS_NEXT, 0, VM_OC_FOR_AWAIT_OF_HAS_NEXT) \ + CBC_OPCODE (CBC_EXT_SET_SETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \ + CBC_FORWARD_BRANCH (CBC_EXT_TRY_CREATE_CONTEXT, PARSER_TRY_CONTEXT_STACK_ALLOCATION, VM_OC_TRY) \ + CBC_OPCODE (CBC_EXT_TRY_CREATE_ENV, CBC_NO_FLAG, 0, VM_OC_BLOCK_CREATE_CONTEXT) \ + CBC_FORWARD_BRANCH (CBC_EXT_CATCH, 1, VM_OC_CATCH) \ + CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, VM_OC_RESOLVE_BASE_FOR_CALL) \ + CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION, VM_OC_FINALLY) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP, CBC_NO_FLAG, 0, VM_OC_INITIALIZER_PUSH_PROP) \ + CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, VM_OC_DEFAULT_INITIALIZER) \ + CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, VM_OC_ERROR) \ + CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_IF_NULLISH, -1, VM_OC_BRANCH_IF_NULLISH) \ + \ + /* Basic opcodes. */ \ + CBC_OPCODE (CBC_EXT_POP_REFERENCE, CBC_NO_FLAG, -2, VM_OC_POP_REFERENCE) \ + CBC_OPCODE (CBC_EXT_CREATE_ARGUMENTS, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_ARGUMENTS) \ + CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_EXT_VAR_EVAL) \ + CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_EXT_VAR_EVAL) \ + CBC_OPCODE (CBC_EXT_COPY_FROM_ARG, CBC_HAS_LITERAL_ARG, 0, VM_OC_COPY_FROM_ARG) \ + CBC_OPCODE (CBC_EXT_PUSH_REST_OBJECT, CBC_NO_FLAG, 1, VM_OC_PUSH_REST_OBJECT) \ + CBC_OPCODE (CBC_EXT_MODULE_IMPORT, CBC_NO_FLAG, 0, VM_OC_MODULE_IMPORT) \ + CBC_OPCODE (CBC_EXT_MODULE_IMPORT_META, CBC_NO_FLAG, 1, VM_OC_MODULE_IMPORT_META) \ + CBC_OPCODE (CBC_EXT_STRING_CONCAT, CBC_NO_FLAG, -1, VM_OC_STRING_CONCAT | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_STRING_CONCAT | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_STRING_CONCAT_TWO_LITERALS, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 1, \ + VM_OC_STRING_CONCAT | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_GET_TAGGED_TEMPLATE_LITERAL, CBC_HAS_BYTE_ARG, 1, VM_OC_GET_TEMPLATE_OBJECT | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, VM_OC_THROW_REFERENCE_ERROR) \ + CBC_OPCODE (CBC_EXT_THROW_ASSIGN_CONST_ERROR, CBC_NO_FLAG, 0, VM_OC_THROW_CONST_ERROR) \ + CBC_OPCODE (CBC_EXT_REQUIRE_OBJECT_COERCIBLE, CBC_NO_FLAG, 0, VM_OC_REQUIRE_OBJECT_COERCIBLE) \ + CBC_OPCODE (CBC_EXT_COPY_DATA_PROPERTIES, CBC_NO_FLAG, -1, VM_OC_COPY_DATA_PROPERTIES) \ + CBC_OPCODE (CBC_EXT_SET_FUNCTION_NAME, CBC_HAS_LITERAL_ARG, 0, VM_OC_SET_FUNCTION_NAME | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_CLASS_NAME, CBC_HAS_LITERAL_ARG, 0, VM_OC_SET_FUNCTION_NAME) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_FUNCTION_NAME, CBC_NO_FLAG, 0, VM_OC_SET_FUNCTION_NAME) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER_NAME, CBC_NO_FLAG, 0, VM_OC_SET_FUNCTION_NAME) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER_NAME, CBC_NO_FLAG, 0, VM_OC_SET_FUNCTION_NAME) \ + \ + /* Computed / class property related opcodes. */ \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + -1, \ + VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY, CBC_HAS_LITERAL_ARG, -1, VM_OC_SET_PROPERTY | VM_OC_GET_STACK_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY_LITERAL, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_PROPERTY, \ + CBC_NO_FLAG, \ + -2, \ + VM_OC_SET_COMPUTED_PROPERTY | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_GETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_GETTER | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_SETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_SET_SETTER | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_GETTER, CBC_NO_FLAG, -2, VM_OC_SET_GETTER | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_SETTER, CBC_NO_FLAG, -2, VM_OC_SET_SETTER | VM_OC_GET_STACK_STACK) \ + CBC_OPCODE (CBC_EXT_SET__PROTO__, CBC_NO_FLAG, -1, VM_OC_SET__PROTO__ | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_STATIC_FIELD_FUNC, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_ADD_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_ADD_STATIC_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_CLASS_CALL_STATIC_BLOCK, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_CLASS_CALL_STATIC_BLOCK | VM_OC_GET_LITERAL) \ + /* Class private property related opcodes */ \ + CBC_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 2, \ + VM_OC_PRIVATE_PROP_REFERENCE | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_PRIVATE_PROP_GET | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_IN, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_PRIVATE_IN | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_PRIVATE_FIELD_ADD, CBC_HAS_LITERAL_ARG, -1, VM_OC_PRIVATE_FIELD_ADD | VM_OC_GET_STACK_LITERAL) \ + /* These 8 opcodes must be in this order */ \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_FIELD, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_METHOD, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_GETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_SETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_STATIC_FIELD, \ + CBC_HAS_LITERAL_ARG, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_STATIC_METHOD, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_STATIC_GETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + CBC_OPCODE (CBC_EXT_COLLECT_PRIVATE_STATIC_SETTER, \ + CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, \ + 0, \ + VM_OC_COLLECT_PRIVATE_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \ + /* Class related opcodes. */ \ + CBC_OPCODE (CBC_EXT_PUSH_NAMED_CLASS_ENV, CBC_HAS_LITERAL_ARG, 1, VM_OC_PUSH_CLASS_ENVIRONMENT) \ + CBC_OPCODE (CBC_EXT_DEFINE_FIELD, CBC_HAS_LITERAL_ARG, -1, VM_OC_DEFINE_FIELD | VM_OC_GET_STACK_LITERAL) \ + CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR, CBC_NO_FLAG, 1, VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE, CBC_NO_FLAG, 1, VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_INIT_CLASS, CBC_NO_FLAG, 0, VM_OC_INIT_CLASS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_FINALIZE_NAMED_CLASS, CBC_HAS_LITERAL_ARG, -2, VM_OC_FINALIZE_CLASS) \ + CBC_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS, CBC_NO_FLAG, -2, VM_OC_FINALIZE_CLASS) \ + CBC_OPCODE (CBC_EXT_SET_FIELD_INIT, CBC_HAS_LITERAL_ARG, 0, VM_OC_SET_FIELD_INIT | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_RUN_FIELD_INIT, CBC_NO_FLAG, 0, VM_OC_RUN_FIELD_INIT) \ + CBC_OPCODE (CBC_EXT_RUN_STATIC_FIELD_INIT, CBC_NO_FLAG, -1, VM_OC_RUN_STATIC_FIELD_INIT) \ + CBC_OPCODE (CBC_EXT_SET_NEXT_COMPUTED_FIELD_ANONYMOUS_FUNC, \ + CBC_NO_FLAG, \ + -1, \ + VM_OC_SET_NEXT_COMPUTED_FIELD | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_EXT_SET_NEXT_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_SET_NEXT_COMPUTED_FIELD | VM_OC_PUT_REFERENCE) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER, CBC_NO_FLAG, 1, VM_OC_NONE) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR, CBC_NO_FLAG, 1, VM_OC_PUSH_SUPER_CONSTRUCTOR) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP, CBC_NO_FLAG, 0, VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE, CBC_NO_FLAG, 2, VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE, CBC_NO_FLAG, 1, VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE, \ + CBC_HAS_LITERAL_ARG, \ + 2, \ + VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT, CBC_NO_FLAG, 0, VM_OC_SET_HOME_OBJECT) \ + CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED, CBC_NO_FLAG, 0, VM_OC_SET_HOME_OBJECT) \ + CBC_OPCODE (CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, 1, VM_OC_OBJECT_LITERAL_HOME_ENV) \ + CBC_OPCODE (CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, -1, VM_OC_OBJECT_LITERAL_HOME_ENV) \ + CBC_OPCODE (CBC_EXT_RESOLVE_LEXICAL_THIS, CBC_NO_FLAG, 1, VM_OC_RESOLVE_LEXICAL_THIS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_LOCAL_EVAL, CBC_HAS_BYTE_ARG, 0, VM_OC_LOCAL_EVAL) \ + CBC_OPCODE (CBC_EXT_ASSIGN_SUPER, CBC_NO_FLAG, -3, VM_OC_ASSIGN_SUPER) \ + CBC_OPCODE (CBC_EXT_ASSIGN_SUPER_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_ASSIGN_SUPER | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_ASSIGN_SUPER_BLOCK, CBC_NO_FLAG, -3, VM_OC_ASSIGN_SUPER | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_ASSIGN_PRIVATE, CBC_NO_FLAG, -3, VM_OC_ASSIGN_PRIVATE) \ + CBC_OPCODE (CBC_EXT_ASSIGN_PRIVATE_PUSH_RESULT, CBC_NO_FLAG, -2, VM_OC_ASSIGN_PRIVATE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_ASSIGN_PRIVATE_BLOCK, CBC_NO_FLAG, -3, VM_OC_ASSIGN_PRIVATE | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL) \ + CBC_OPCODE (CBC_EXT_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL) \ + CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_PUSH_RESULT, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + 0, \ + VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \ + \ + /* Spread / rest operation related opcodes. */ \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SPREAD_ARGUMENTS) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PUSH_RESULT, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + 0, \ + VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, VM_OC_SPREAD_ARGUMENTS) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_PUSH_RESULT, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + -2, \ + VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK, \ + CBC_HAS_POP_STACK_BYTE_ARG, \ + -3, \ + VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \ + CBC_OPCODE (CBC_EXT_PUSH_SPREAD_ELEMENT, CBC_NO_FLAG, 1, VM_OC_PUSH_SPREAD_ELEMENT) \ + CBC_OPCODE (CBC_EXT_SPREAD_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_APPEND_ARRAY) \ + CBC_OPCODE (CBC_EXT_REST_INITIALIZER, CBC_NO_FLAG, 1, VM_OC_REST_INITIALIZER) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_LITERAL) \ + CBC_OPCODE (CBC_EXT_SPREAD_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \ + \ + /* Iterator related opcodes. */ \ + CBC_OPCODE (CBC_EXT_ITERATOR_CONTEXT_CREATE, \ + CBC_NO_FLAG, \ + PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION, \ + VM_OC_ITERATOR_CONTEXT_CREATE) \ + CBC_OPCODE (CBC_EXT_ITERATOR_CONTEXT_END, \ + CBC_NO_FLAG, \ + -PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION, \ + VM_OC_ITERATOR_CONTEXT_END) \ + CBC_OPCODE (CBC_EXT_ITERATOR_STEP, CBC_NO_FLAG, 1, VM_OC_ITERATOR_STEP) \ + \ + /* Object initializer related opcodes. */ \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_CONTEXT_CREATE, \ + CBC_NO_FLAG, \ + PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION, \ + VM_OC_OBJ_INIT_CONTEXT_CREATE) \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_REST_CONTEXT_CREATE, \ + CBC_NO_FLAG, \ + PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION, \ + VM_OC_OBJ_INIT_CONTEXT_CREATE) \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_PUSH_REST, CBC_NO_FLAG, 1, VM_OC_OBJ_INIT_PUSH_REST) \ + CBC_OPCODE (CBC_EXT_OBJ_INIT_CONTEXT_END, \ + CBC_NO_FLAG, \ + -PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION, \ + VM_OC_OBJ_INIT_CONTEXT_END) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_NAME, CBC_NO_FLAG, 0, VM_OC_INITIALIZER_PUSH_NAME | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_NAME_LITERAL, \ + CBC_HAS_LITERAL_ARG, \ + 1, \ + VM_OC_INITIALIZER_PUSH_NAME | VM_OC_GET_LITERAL) \ + \ + /* Executable object related opcodes. */ \ + CBC_OPCODE (CBC_EXT_CREATE_GENERATOR, CBC_NO_FLAG, 1, VM_OC_CREATE_GENERATOR) \ + CBC_OPCODE (CBC_EXT_YIELD, CBC_NO_FLAG, 0, VM_OC_YIELD) \ + CBC_OPCODE (CBC_EXT_YIELD_ITERATOR, CBC_NO_FLAG, 0, VM_OC_YIELD) \ + CBC_OPCODE (CBC_EXT_ASYNC_YIELD, CBC_NO_FLAG, 0, VM_OC_ASYNC_YIELD) \ + CBC_OPCODE (CBC_EXT_ASYNC_YIELD_ITERATOR, CBC_NO_FLAG, 0, VM_OC_ASYNC_YIELD_ITERATOR) \ + CBC_OPCODE (CBC_EXT_AWAIT, CBC_NO_FLAG, 0, VM_OC_AWAIT) \ + CBC_OPCODE (CBC_EXT_GENERATOR_AWAIT, CBC_NO_FLAG, 0, VM_OC_GENERATOR_AWAIT) \ + CBC_OPCODE (CBC_EXT_ASYNC_EXIT, CBC_NO_FLAG, 0, VM_OC_ASYNC_EXIT) \ + CBC_OPCODE (CBC_EXT_RETURN, CBC_NO_FLAG, -1, VM_OC_EXT_RETURN | VM_OC_GET_STACK) \ + CBC_OPCODE (CBC_EXT_RETURN_UNDEFINED, CBC_NO_FLAG, 0, VM_OC_EXT_RETURN) \ + CBC_OPCODE (CBC_EXT_PUSH_NEW_TARGET, CBC_NO_FLAG, 1, VM_OC_PUSH_NEW_TARGET | VM_OC_PUT_STACK) \ + \ + /* Last opcode (not a real opcode). */ \ + CBC_OPCODE (CBC_EXT_END, CBC_NO_FLAG, 0, VM_OC_NONE) + +#define CBC_MAXIMUM_BYTE_VALUE 255 +#define CBC_MAXIMUM_SMALL_VALUE 510 +#define CBC_MAXIMUM_FULL_VALUE 32767 + +#define CBC_PUSH_NUMBER_BYTE_RANGE_END 256 + +#define CBC_HIGHEST_BIT_MASK 0x80 +#define CBC_LOWER_SEVEN_BIT_MASK 0x7f + +/** + * Literal encoding limit when full literal encoding mode is enabled + */ +#define CBC_FULL_LITERAL_ENCODING_LIMIT 128 + +/** + * Literal encoding delta when full literal encoding mode is enabled + */ +#define CBC_FULL_LITERAL_ENCODING_DELTA 0x8000 + +/** + * Literal encoding limit when full literal encoding mode is disabled + */ +#define CBC_SMALL_LITERAL_ENCODING_LIMIT 255 + +/** + * Literal encoding delta when full literal encoding mode is disabled + */ +#define CBC_SMALL_LITERAL_ENCODING_DELTA 0xfe01 + +/** + * Literal indices belong to one of the following groups: + * + * 0 <= index < argument_end : arguments + * argument_end <= index < register_end : registers + * register_end <= index < ident_end : identifiers + * ident_end <= index < const_literal_end : constant literals + * const_literal_end <= index < literal_end : template literals + */ + +/** + * Compiled byte code arguments. + */ +typedef struct +{ + ecma_compiled_code_t header; /**< compiled code header */ + uint8_t stack_limit; /**< maximum number of values stored on the stack */ + uint8_t argument_end; /**< number of arguments expected by the function */ + ecma_value_t script_value; /**< script value */ + uint8_t register_end; /**< end position of the register group */ + uint8_t ident_end; /**< end position of the identifier group */ + uint8_t const_literal_end; /**< end position of the const literal group */ + uint8_t literal_end; /**< end position of the literal group */ +} cbc_uint8_arguments_t; + +/** + * Compiled byte code arguments. + */ +typedef struct +{ + ecma_compiled_code_t header; /**< compiled code header */ + uint16_t stack_limit; /**< maximum number of values stored on the stack */ + ecma_value_t script_value; /**< script value */ + uint16_t argument_end; /**< number of arguments expected by the function */ + uint16_t register_end; /**< end position of the register group */ + uint16_t ident_end; /**< end position of the identifier group */ + uint16_t const_literal_end; /**< end position of the const literal group */ + uint16_t literal_end; /**< end position of the literal group */ + uint16_t padding; /**< an unused value */ +} cbc_uint16_arguments_t; + +/** + * Compact byte code status flags. + */ +typedef enum +{ + CBC_CODE_FLAGS_FULL_LITERAL_ENCODING = (1u << 0), /**< full literal encoding mode is enabled */ + CBC_CODE_FLAGS_UINT16_ARGUMENTS = (1u << 1), /**< compiled code data is cbc_uint16_arguments_t */ + CBC_CODE_FLAGS_STRICT_MODE = (1u << 2), /**< strict mode is enabled */ + CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED = (1u << 3), /**< mapped arguments object must be constructed */ + CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED = (1u << 4), /**< no need to create a lexical environment */ + CBC_CODE_FLAGS_HAS_EXTENDED_INFO = (1u << 5), /**< this function has extended info block */ + CBC_CODE_FLAGS_HAS_TAGGED_LITERALS = (1u << 6), /**< this function has tagged template literal list */ + CBC_CODE_FLAGS_HAS_LINE_INFO = (1u << 7), /**< this function has line info block */ + CBC_CODE_FLAGS_STATIC_FUNCTION = (1u << 8), /**< this function is a static snapshot function */ + CBC_CODE_FLAGS_DEBUGGER_IGNORE = (1u << 9), /**< this function should be ignored by debugger */ + CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED = (1u << 10), /**< compiled code needs a lexical block */ + + /* Bits from bit 12 is reserved for function types (see CBC_FUNCTION_TYPE_SHIFT). + * Note: the last bits are used for type flags because < and >= operators can be used to + check a range of types without decoding the actual type. */ +} cbc_code_flags_t; + +/** + * Optional byte code fields. These fields are stored in a reversed + * order from the end of the byte code data. + * + * Value fields: + * - when CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED is set: + * argument_end number of argument names encoded as strings + * - when function type is not CBC_FUNCTION_CONSTRUCTOR: + * function name encoded as string + * - when CBC_CODE_FLAGS_HAS_TAGGED_LITERALS is set: + * pointer to the tagged template collection encoded as value + * + * Byte fields when CBC_CODE_FLAGS_HAS_EXTENDED_INFO is set: + * - always available: + * a byte which contains a combination of CBC_EXTENDED_CODE_FLAGS bits + * - when CBC_EXTENDED_CODE_FLAGS_HAS_ARGUMENT_LENGTH is set: + * a vlq encoded default value for function length + * - when CBC_EXTENDED_CODE_FLAGS_HAS_SOURCE_CODE_RANGE is set: + * a pair of vlq encoded values, representing the start and size of the range + */ + +/** + * Compact byte code function types. + */ +typedef enum +{ + /* The first type must be regular expression (see CBC_IS_FUNCTION) */ + CBC_REGULAR_EXPRESSION, /**< regular expression literal */ + CBC_FUNCTION_NORMAL, /**< function without special properties */ + CBC_FUNCTION_CONSTRUCTOR, /**< constructor function */ + + /* The following functions cannot be constructed (see CBC_FUNCTION_IS_CONSTRUCTABLE) */ + CBC_FUNCTION_SCRIPT, /**< script (global) function */ + CBC_FUNCTION_GENERATOR, /**< generator function */ + CBC_FUNCTION_ASYNC_GENERATOR, /**< async generator function */ + + /* The following functions has no prototype (see CBC_FUNCTION_HAS_PROTOTYPE) */ + CBC_FUNCTION_ACCESSOR, /**< property accessor function */ + CBC_FUNCTION_ASYNC, /**< async function */ + CBC_FUNCTION_METHOD, /**< method */ + + /* The following functions are arrow function (see CBC_FUNCTION_IS_ARROW) */ + CBC_FUNCTION_ARROW, /**< arrow function */ + CBC_FUNCTION_ASYNC_ARROW, /**< arrow function */ +} cbc_code_function_types_t; + +/** + * Shift for getting / setting the function type of a byte code. + */ +#define CBC_FUNCTION_TYPE_SHIFT 12 + +/** + * Compute function type bits in code flags. + */ +#define CBC_FUNCTION_TO_TYPE_BITS(name) ((name) << CBC_FUNCTION_TYPE_SHIFT) + +/** + * Get function type from code flags. + */ +#define CBC_FUNCTION_GET_TYPE(flags) ((uint16_t) ((flags) >> CBC_FUNCTION_TYPE_SHIFT)) + +/** + * Checks whether the byte code is a function or a regular expression. + */ +#define CBC_IS_FUNCTION(flags) ((flags) >= (CBC_FUNCTION_NORMAL << CBC_FUNCTION_TYPE_SHIFT)) + +/** + * Checks whether the function can be constructed with new operator. + */ +#define CBC_FUNCTION_IS_CONSTRUCTABLE(flags) ((flags) < (CBC_FUNCTION_GENERATOR << CBC_FUNCTION_TYPE_SHIFT)) + +/** + * Checks whether the function has prototype property. + */ +#define CBC_FUNCTION_HAS_PROTOTYPE(flags) ((flags) < (CBC_FUNCTION_ACCESSOR << CBC_FUNCTION_TYPE_SHIFT)) + +/** + * Checks whether the function is an arrow function. + */ +#define CBC_FUNCTION_IS_ARROW(flags) ((flags) >= (CBC_FUNCTION_ARROW << CBC_FUNCTION_TYPE_SHIFT)) + +/** + * Compact byte code extended status flags. + */ +typedef enum +{ + CBC_EXTENDED_CODE_FLAGS_HAS_ARGUMENT_LENGTH = (1u << 0), /**< has argument length */ + CBC_EXTENDED_CODE_FLAGS_HAS_SOURCE_CODE_RANGE = (1u << 1), /**< has source code range (start, end) */ + CBC_EXTENDED_CODE_FLAGS_SOURCE_CODE_IN_ARGUMENTS = (1u << 2), /**< source code range is inside + * the function arguments */ +} cbc_extended_code_flags_t; + +/** + * Shared script data. + */ +typedef enum +{ + CBC_SCRIPT_HAS_USER_VALUE = (1 << 0), /**< script has user value */ + CBC_SCRIPT_USER_VALUE_IS_OBJECT = (1 << 1), /**< user value is object */ + CBC_SCRIPT_HAS_FUNCTION_ARGUMENTS = (1 << 2), /**< script is a function with arguments source code */ + CBC_SCRIPT_HAS_IMPORT_META = (1 << 3), /**< script is a module with import.meta object */ + CBC_SCRIPT_IS_EVAL_CODE = (1 << 4), /**< script is compiled by eval like (eval, new Function, etc.) expression */ +} cbc_script_type; + +/** + * Value for increasing or decreasing the script reference counter. + */ +#define CBC_SCRIPT_REF_ONE 0x20 + +/** + * Maximum value of script reference counter. + */ +#define CBC_SCRIPT_REF_MAX (UINT32_MAX - CBC_SCRIPT_REF_ONE + 1) + +/** + * Sets the type of a script using the user_value. + */ +#define CBC_SCRIPT_SET_TYPE(script_p, user_value, ref_count) \ + do \ + { \ + (script_p)->refs_and_type = (ref_count); \ + if ((user_value) != ECMA_VALUE_EMPTY) \ + { \ + (script_p)->refs_and_type |= CBC_SCRIPT_HAS_USER_VALUE; \ + if (ecma_is_value_object (user_value)) \ + { \ + (script_p)->refs_and_type |= CBC_SCRIPT_USER_VALUE_IS_OBJECT; \ + } \ + } \ + } while (false) + +/** + * Shared script data. + */ +typedef struct +{ +#if JERRY_BUILTIN_REALMS + ecma_object_t *realm_p; /**< realm object */ +#endif /* JERRY_BUILTIN_REALMS */ + uint32_t refs_and_type; /**< reference counter and type of the function */ +#if JERRY_SOURCE_NAME + ecma_value_t source_name; /**< source name */ +#endif /* JERRY_SOURCE_NAME */ +} cbc_script_t; + +/** + * Get the array of optional values assigned to a script. + * + * First value: user value + * Second value: function arguments value + */ +#define CBC_SCRIPT_GET_OPTIONAL_VALUES(script_p) ((ecma_value_t *) ((script_p) + 1)) + +/** + * Get user value. + */ +#define CBC_SCRIPT_GET_USER_VALUE(script_p) (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[0]) + +/** + * Get function arguments. + */ +#define CBC_SCRIPT_GET_FUNCTION_ARGUMENTS(script_p, type) \ + (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[((type) &CBC_SCRIPT_HAS_USER_VALUE) ? 1 : 0]) + +/** + * Get import.meta object. + */ +#define CBC_SCRIPT_GET_IMPORT_META(script_p, type) \ + (CBC_SCRIPT_GET_OPTIONAL_VALUES (script_p)[((type) &CBC_SCRIPT_HAS_USER_VALUE) ? 1 : 0]) + +#define CBC_OPCODE(arg1, arg2, arg3, arg4) arg1, + +/** + * Opcode list. + */ +typedef enum +{ + CBC_OPCODE_LIST /**< list of opcodes */ +} cbc_opcode_t; + +/** + * Extended opcode list. + */ +typedef enum +{ + CBC_EXT_OPCODE_LIST /**< list extended opcodes */ +} cbc_ext_opcode_t; + +#undef CBC_OPCODE + +/** + * Opcode flags. + */ +extern const uint8_t cbc_flags[]; +extern const uint8_t cbc_ext_flags[]; + +#if JERRY_PARSER_DUMP_BYTE_CODE + +/** + * Opcode names for debugging. + */ +extern const char *const cbc_names[]; +extern const char *const cbc_ext_names[]; + +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +/** + * @} + * @} + * @} + */ + +#endif /* !BYTE_CODE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/common.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/common.cpp new file mode 100644 index 0000000..eafd167 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/common.cpp @@ -0,0 +1,550 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common.h" + +#include "ecma-big-uint.h" +#include "ecma-bigint.h" +#include "ecma-extended-info.h" +#include "ecma-helpers.h" + +#include "js-parser-internal.h" +#include "lit-char-helpers.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_utils Utility + * @{ + */ + +#if JERRY_PARSER + +/** + * Free literal. + */ +void +util_free_literal (lexer_literal_t *literal_p) /**< literal */ +{ + if (literal_p->type == LEXER_IDENT_LITERAL || literal_p->type == LEXER_STRING_LITERAL) + { + if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR)) + { + jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length); + } + } + else if ((literal_p->type == LEXER_FUNCTION_LITERAL) || (literal_p->type == LEXER_REGEXP_LITERAL)) + { + ecma_bytecode_deref (literal_p->u.bytecode_p); + } +} /* util_free_literal */ + +#endif /* JERRY_PARSER */ + +#if JERRY_PARSER_DUMP_BYTE_CODE + +/** + * Debug utility to print a character sequence. + */ +static void +util_print_chars (const uint8_t *char_p, /**< character pointer */ + size_t size) /**< size */ +{ + while (size > 0) + { + JERRY_DEBUG_MSG ("%c", *char_p++); + size--; + } +} /* util_print_chars */ + +/** + * Debug utility to print a number. + */ +static void +util_print_number (ecma_number_t num_p) /**< number to print */ +{ + lit_utf8_byte_t str_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER]; + lit_utf8_size_t str_size = ecma_number_to_utf8_string (num_p, str_buf, sizeof (str_buf)); + str_buf[str_size] = 0; + JERRY_DEBUG_MSG ("%s", str_buf); +} /* util_print_number */ + +#if JERRY_BUILTIN_BIGINT + +/** + * Debug utility to print a bigint. + */ +static void +util_print_bigint (ecma_value_t bigint) /**< bigint to print */ +{ + if (bigint == ECMA_BIGINT_ZERO) + { + JERRY_DEBUG_MSG ("0"); + return; + } + + ecma_extended_primitive_t *bigint_p = ecma_get_extended_primitive_from_value (bigint); + uint32_t char_start_p, char_size_p; + lit_utf8_byte_t *string_buffer_p = ecma_big_uint_to_string (bigint_p, 10, &char_start_p, &char_size_p); + + if (JERRY_UNLIKELY (string_buffer_p == NULL)) + { + JERRY_DEBUG_MSG (""); + return; + } + + JERRY_ASSERT (char_start_p > 0); + + if (bigint_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN) + { + string_buffer_p[--char_start_p] = LIT_CHAR_MINUS; + } + + util_print_chars (string_buffer_p + char_start_p, char_size_p - char_start_p); + jmem_heap_free_block (string_buffer_p, char_size_p); +} /* util_print_bigint */ + +#endif /* JERRY_BUILTIN_BIGINT */ + +/** + * Print literal + */ +void +util_print_literal (lexer_literal_t *literal_p) /**< literal */ +{ + switch (literal_p->type) + { + case LEXER_IDENT_LITERAL: + { + JERRY_DEBUG_MSG ("ident("); + util_print_chars (literal_p->u.char_p, literal_p->prop.length); + break; + } + case LEXER_FUNCTION_LITERAL: + { + JERRY_DEBUG_MSG ("function"); + return; + } + case LEXER_STRING_LITERAL: + { + JERRY_DEBUG_MSG ("string("); + util_print_chars (literal_p->u.char_p, literal_p->prop.length); + break; + } + case LEXER_NUMBER_LITERAL: + { +#if JERRY_BUILTIN_BIGINT + if (ecma_is_value_bigint (literal_p->u.value)) + { + JERRY_DEBUG_MSG ("bigint("); + util_print_bigint (literal_p->u.value); + break; + } +#endif /* JERRY_BUILTIN_BIGINT */ + JERRY_DEBUG_MSG ("number("); + util_print_number (ecma_get_number_from_value (literal_p->u.value)); + break; + } + case LEXER_REGEXP_LITERAL: + { + JERRY_DEBUG_MSG ("regexp"); + return; + } + default: + { + JERRY_DEBUG_MSG ("unknown"); + return; + } + } + + JERRY_DEBUG_MSG (")"); +} /* util_print_literal */ + +/** + * Print literal. + */ +static void +util_print_literal_value (ecma_compiled_code_t *compiled_code_p, /**< compiled code */ + uint16_t literal_index) /**< literal index */ +{ + uint16_t argument_end; + uint16_t register_end; + uint16_t ident_end; + uint16_t const_literal_end; + ecma_value_t *literal_start_p; + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p; + argument_end = args_p->argument_end; + register_end = args_p->register_end; + ident_end = args_p->ident_end; + const_literal_end = args_p->const_literal_end; + literal_start_p = (ecma_value_t *) (args_p + 1); + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p; + argument_end = args_p->argument_end; + register_end = args_p->register_end; + ident_end = args_p->ident_end; + const_literal_end = args_p->const_literal_end; + literal_start_p = (ecma_value_t *) (args_p + 1); + } + + if (literal_index < argument_end) + { + JERRY_DEBUG_MSG (" arg:%d", literal_index); + return; + } + + if (literal_index < register_end) + { + JERRY_DEBUG_MSG (" reg:%d", literal_index); + return; + } + + if (literal_index >= const_literal_end) + { + JERRY_DEBUG_MSG (" lit:%d", literal_index); + return; + } + + if (literal_index < ident_end) + { + JERRY_DEBUG_MSG (" ident:%d->", literal_index); + } + else + { + JERRY_DEBUG_MSG (" const:%d->", literal_index); + } + + ecma_value_t value = literal_start_p[literal_index - register_end]; + + if (ecma_is_value_number (value)) + { + JERRY_DEBUG_MSG ("number("); + util_print_number (ecma_get_number_from_value (value)); + } +#if JERRY_BUILTIN_BIGINT + else if (ecma_is_value_bigint (value)) + { + JERRY_DEBUG_MSG ("bigint("); + util_print_bigint (value); + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + ecma_string_t *literal_p = ecma_get_string_from_value (value); + + JERRY_DEBUG_MSG ("string("); + + ECMA_STRING_TO_UTF8_STRING (literal_p, chars_p, literal_size); + util_print_chars (chars_p, literal_size); + ECMA_FINALIZE_UTF8_STRING (chars_p, literal_size); + } + + JERRY_DEBUG_MSG (")"); +} /* util_print_literal_value */ + +#define PARSER_READ_IDENTIFIER_INDEX(name) \ + name = *byte_code_p++; \ + if (name >= encoding_limit) \ + { \ + name = (uint16_t) (((name << 8) | byte_code_p[0]) - encoding_delta); \ + byte_code_p++; \ + } + +/** + * Print byte code. + */ +void +util_print_cbc (ecma_compiled_code_t *compiled_code_p) /**< compiled code */ +{ + uint8_t flags; + uint8_t *byte_code_start_p; + uint8_t *byte_code_end_p; + uint8_t *byte_code_p; + uint16_t encoding_limit; + uint16_t encoding_delta; + uint16_t stack_limit; + uint16_t argument_end; + uint16_t register_end; + uint16_t ident_end; + uint16_t const_literal_end; + uint16_t literal_end; + size_t size = ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG; + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args = (cbc_uint16_arguments_t *) compiled_code_p; + stack_limit = args->stack_limit; + argument_end = args->argument_end; + register_end = args->register_end; + ident_end = args->ident_end; + const_literal_end = args->const_literal_end; + literal_end = args->literal_end; + } + else + { + cbc_uint8_arguments_t *args = (cbc_uint8_arguments_t *) compiled_code_p; + stack_limit = args->stack_limit; + argument_end = args->argument_end; + register_end = args->register_end; + ident_end = args->ident_end; + const_literal_end = args->const_literal_end; + literal_end = args->literal_end; + } + + JERRY_DEBUG_MSG ("\nByte code dump:\n\n Maximum stack depth: %d\n Flags: [", (int) (stack_limit + register_end)); + + if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING)) + { + JERRY_DEBUG_MSG ("small_lit_enc"); + encoding_limit = CBC_SMALL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_SMALL_LITERAL_ENCODING_DELTA; + } + else + { + JERRY_DEBUG_MSG ("full_lit_enc"); + encoding_limit = CBC_FULL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_FULL_LITERAL_ENCODING_DELTA; + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + JERRY_DEBUG_MSG (",uint16_arguments"); + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) + { + JERRY_DEBUG_MSG (",strict_mode"); + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED) + { + JERRY_DEBUG_MSG (",mapped_arguments_needed"); + size -= argument_end * sizeof (ecma_value_t); + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED) + { + JERRY_DEBUG_MSG (",no_lexical_env"); + } + + switch (CBC_FUNCTION_GET_TYPE (compiled_code_p->status_flags)) + { + case CBC_FUNCTION_CONSTRUCTOR: + { + JERRY_DEBUG_MSG (",constructor"); + break; + } + case CBC_FUNCTION_GENERATOR: + { + JERRY_DEBUG_MSG (",generator"); + break; + } + case CBC_FUNCTION_ASYNC: + { + JERRY_DEBUG_MSG (",async"); + break; + } + case CBC_FUNCTION_ASYNC_GENERATOR: + { + JERRY_DEBUG_MSG (",async_generator"); + break; + } + case CBC_FUNCTION_ACCESSOR: + { + JERRY_DEBUG_MSG (",accessor"); + break; + } + case CBC_FUNCTION_ARROW: + { + JERRY_DEBUG_MSG (",arrow"); + break; + } + case CBC_FUNCTION_ASYNC_ARROW: + { + JERRY_DEBUG_MSG (",async_arrow"); + break; + } + } + + JERRY_DEBUG_MSG ("]\n"); + + JERRY_DEBUG_MSG (" Argument range end: %d\n", (int) argument_end); + JERRY_DEBUG_MSG (" Register range end: %d\n", (int) register_end); + JERRY_DEBUG_MSG (" Identifier range end: %d\n", (int) ident_end); + JERRY_DEBUG_MSG (" Const literal range end: %d\n", (int) const_literal_end); + JERRY_DEBUG_MSG (" Literal range end: %d\n\n", (int) literal_end); + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_HAS_EXTENDED_INFO) + { + uint8_t *extended_info_p = ecma_compiled_code_resolve_extended_info (compiled_code_p); + uint8_t *extended_info_start_p = extended_info_p + sizeof (uint8_t); + uint8_t extended_info = *extended_info_p; + + if (extended_info & CBC_EXTENDED_CODE_FLAGS_HAS_ARGUMENT_LENGTH) + { + uint32_t argument_length = ecma_extended_info_decode_vlq (&extended_info_p); + JERRY_DEBUG_MSG (" [Extended] Argument length: %d\n", (int) argument_length); + } + + if (extended_info & CBC_EXTENDED_CODE_FLAGS_HAS_SOURCE_CODE_RANGE) + { + uint32_t range_start = ecma_extended_info_decode_vlq (&extended_info_p); + uint32_t range_end = ecma_extended_info_decode_vlq (&extended_info_p) + range_start; + JERRY_DEBUG_MSG (" [Extended] Source code range: %d - %d\n", (int) range_start, (int) range_end); + } + + JERRY_DEBUG_MSG ("\n"); + + size -= (size_t) (extended_info_start_p - extended_info_p); + } + + byte_code_start_p = (uint8_t *) compiled_code_p; + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + byte_code_start_p += sizeof (cbc_uint16_arguments_t); + } + else + { + byte_code_start_p += sizeof (cbc_uint8_arguments_t); + } + + byte_code_start_p += (unsigned int) (literal_end - register_end) * sizeof (ecma_value_t); + + if (CBC_FUNCTION_GET_TYPE (compiled_code_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR) + { + size -= sizeof (ecma_value_t); + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS) + { + size -= sizeof (ecma_value_t); + } + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_HAS_LINE_INFO) + { + size -= sizeof (ecma_value_t); + } + + byte_code_end_p = ((uint8_t *) compiled_code_p) + size; + byte_code_p = byte_code_start_p; + + while (byte_code_p < byte_code_end_p) + { + cbc_opcode_t opcode = (cbc_opcode_t) *byte_code_p; + cbc_ext_opcode_t ext_opcode = CBC_EXT_NOP; + size_t cbc_offset = (size_t) (byte_code_p - byte_code_start_p); + + if (opcode != CBC_EXT_OPCODE) + { + flags = cbc_flags[opcode]; + JERRY_DEBUG_MSG (" %3d : %s", (int) cbc_offset, cbc_names[opcode]); + byte_code_p++; + } + else + { + if (byte_code_p + 1 >= byte_code_end_p) + { + break; + } + + ext_opcode = (cbc_ext_opcode_t) byte_code_p[1]; + + if (ext_opcode == CBC_EXT_NOP) + { + break; + } + + flags = cbc_ext_flags[ext_opcode]; + JERRY_DEBUG_MSG (" %3d : %s", (int) cbc_offset, cbc_ext_names[ext_opcode]); + byte_code_p += 2; + } + + if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) + { + uint16_t literal_index; + + PARSER_READ_IDENTIFIER_INDEX (literal_index); + util_print_literal_value (compiled_code_p, literal_index); + } + + if (flags & CBC_HAS_LITERAL_ARG2) + { + uint16_t literal_index; + + PARSER_READ_IDENTIFIER_INDEX (literal_index); + util_print_literal_value (compiled_code_p, literal_index); + + if (!(flags & CBC_HAS_LITERAL_ARG)) + { + PARSER_READ_IDENTIFIER_INDEX (literal_index); + util_print_literal_value (compiled_code_p, literal_index); + } + } + + if (flags & CBC_HAS_BYTE_ARG) + { + if (opcode == CBC_PUSH_NUMBER_POS_BYTE || opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) + { + JERRY_DEBUG_MSG (" number:%d", (int) *byte_code_p + 1); + } + else if (opcode == CBC_PUSH_NUMBER_NEG_BYTE || opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) + { + JERRY_DEBUG_MSG (" number:%d", -((int) *byte_code_p + 1)); + } + else + { + JERRY_DEBUG_MSG (" byte_arg:%d", *byte_code_p); + } + byte_code_p++; + } + + if (flags & CBC_HAS_BRANCH_ARG) + { + size_t branch_offset_length = + (opcode != CBC_EXT_OPCODE ? CBC_BRANCH_OFFSET_LENGTH (opcode) : CBC_BRANCH_OFFSET_LENGTH (ext_opcode)); + size_t offset = 0; + + do + { + offset = (offset << 8) | *byte_code_p++; + } while (--branch_offset_length > 0); + + JERRY_DEBUG_MSG (" offset:%d(->%d)", + (int) offset, + (int) (cbc_offset + (CBC_BRANCH_IS_FORWARD (flags) ? offset : -offset))); + } + + JERRY_DEBUG_MSG ("\n"); + } +} /* util_print_cbc */ + +#undef PARSER_READ_IDENTIFIER_INDEX + +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/common.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/common.h new file mode 100644 index 0000000..0091240 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/common.h @@ -0,0 +1,158 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMMON_H +#define COMMON_H + +#include +#include +#include +#include +#include + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_utils Utility + * @{ + */ + +#include "ecma-globals.h" +#include "ecma-regexp-object.h" + +#include "jerry-config.h" +#include "jmem.h" + +/* Immediate management. */ + +/** + * Literal types. + * + * The LEXER_UNUSED_LITERAL type is internal and + * used for various purposes. + */ +typedef enum +{ + /* The LEXER_IS_IDENT_OR_STRING macro must be updated if the order is changed. */ + LEXER_IDENT_LITERAL = 0, /**< identifier literal */ + LEXER_STRING_LITERAL = 1, /**< string literal */ + LEXER_NUMBER_LITERAL = 2, /**< number literal */ + LEXER_FUNCTION_LITERAL = 3, /**< function literal */ + LEXER_REGEXP_LITERAL = 4, /**< regexp literal */ + LEXER_UNUSED_LITERAL = 5, /**< unused literal, can only be + used by the byte code generator. */ + LEXER_NEW_IDENT_LITERAL = 6, /**< new local variable, can only be + used by the byte code generator. */ +} lexer_literal_type_t; + +/** + * Checks whether the literal type is identifier or string. + */ +#define LEXER_IS_IDENT_OR_STRING(literal_type) ((literal_type) <= LEXER_STRING_LITERAL) + +/** + * Flag bits for status_flags member of lexer_literal_t. + */ +typedef enum +{ + LEXER_FLAG_USED = (1 << 0), /**< this local identifier needs to be stored in the constant pool */ + LEXER_FLAG_FUNCTION_ARGUMENT = (1 << 1), /**< this local identifier is a function argument */ + LEXER_FLAG_SOURCE_PTR = (1 << 2), /**< the literal is directly referenced in the source code + * (no need to allocate memory) */ + LEXER_FLAG_LATE_INIT = (1 << 3), /**< initialize this variable after the byte code is freed */ + LEXER_FLAG_ASCII = (1 << 4), /**< the literal contains only ascii characters */ + LEXER_FLAG_GLOBAL = (1 << 5), /**< this local identifier is not a let or const declaration */ +} lexer_literal_status_flags_t; + +/** + * Type of property length. + */ +typedef uint16_t prop_length_t; + +/** + * Literal data. + */ +typedef struct +{ + union + { + ecma_value_t value; /**< literal value (not processed by the parser) */ + const uint8_t *char_p; /**< character value */ + ecma_compiled_code_t *bytecode_p; /**< compiled function or regexp pointer */ + uint32_t source_data; /**< encoded source literal */ + } u; + +#if JERRY_PARSER_DUMP_BYTE_CODE + struct +#else /* !JERRY_PARSER_DUMP_BYTE_CODE */ + union +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + { + prop_length_t length; /**< length of ident / string literal */ + uint16_t index; /**< real index during post processing */ + } prop; + + uint8_t type; /**< type of the literal */ + uint8_t status_flags; /**< status flags */ +} lexer_literal_t; + +void util_free_literal (lexer_literal_t *literal_p); + +#if JERRY_PARSER_DUMP_BYTE_CODE +void util_print_literal (lexer_literal_t *); +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +/** + * Source code line counter type. + */ +typedef uint32_t parser_line_counter_t; + +/** + * Source code as character data. + */ +typedef struct +{ + const uint8_t *source_p; /**< valid UTF-8 source code */ + size_t source_size; /**< size of the source code */ +} parser_source_char_t; + +/* TRY/CATCH block */ + +#define PARSER_TRY_CONTEXT(context_name) jmp_buf context_name + +#define PARSER_THROW(context_name) longjmp (context_name, 1); + +#define PARSER_TRY(context_name) \ + { \ + if (!setjmp (context_name)) \ + { +#define PARSER_CATCH \ + } \ + else \ + { +#define PARSER_TRY_END \ + } \ + } + +/** + * @} + * @} + * @} + */ + +#endif /* !COMMON_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-lexer.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-lexer.cpp new file mode 100644 index 0000000..0db01ee --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-lexer.cpp @@ -0,0 +1,3596 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-bigint.h" +#include "ecma-function-object.h" +#include "ecma-helpers.h" +#include "ecma-literal-storage.h" + +#include "jcontext.h" +#include "js-parser-internal.h" +#include "lit-char-helpers.h" + +#if JERRY_PARSER + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_lexer Lexer + * @{ + */ + +JERRY_STATIC_ASSERT (((int)LEXER_NUMBER_BINARY > (int)LEXER_NUMBER_OCTAL), + lexer_number_binary_must_be_greater_than_lexer_number_octal); + +/** + * Check whether the UTF-8 intermediate is an octet or not + */ +#define IS_UTF8_INTERMEDIATE_OCTET(byte) (((byte) &LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_2_BYTE_CODE_POINT_MIN) + +/** + * Align column to the next tab position. + * + * @return aligned position + */ +static parser_line_counter_t +align_column_to_tab (parser_line_counter_t column) /**< current column */ +{ + /* Tab aligns to zero column start position. */ + return (parser_line_counter_t) (((column + (8u - 1u)) & ~ECMA_STRING_CONTAINER_MASK) + 1u); +} /* align_column_to_tab */ + +/** + * Parse hexadecimal character sequence + * + * @return character value or UINT32_MAX on error + */ +static lit_code_point_t +lexer_hex_to_code_point (const uint8_t *source_p, /**< current source position */ + parser_line_counter_t length) /**< source length */ +{ + lit_code_point_t result = 0; + + do + { + uint32_t byte = *source_p++; + + result <<= 4; + + if (byte >= LIT_CHAR_0 && byte <= LIT_CHAR_9) + { + result += byte - LIT_CHAR_0; + } + else + { + byte = LEXER_TO_ASCII_LOWERCASE (byte); + if (byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F) + { + result += byte - (LIT_CHAR_LOWERCASE_A - 10); + } + else + { + return UINT32_MAX; + } + } + } while (--length > 0); + + return result; +} /* lexer_hex_to_code_point */ + +/** + * Parse hexadecimal character sequence enclosed in braces + * + * @return character value or UINT32_MAX on error + */ +static lit_code_point_t +lexer_hex_in_braces_to_code_point (const uint8_t *source_p, /**< current source position */ + const uint8_t *source_end_p, /**< source end */ + uint32_t *length_p) /**< [out] length of the sequence */ +{ + lit_code_point_t result = 0; + /* Four is the size of \u{} sequence. */ + uint32_t length = 4; + + JERRY_ASSERT (source_p[-1] == LIT_CHAR_LEFT_BRACE); + JERRY_ASSERT (source_p < source_end_p); + + do + { + uint32_t byte = *source_p++; + + result <<= 4; + + if (byte >= LIT_CHAR_0 && byte <= LIT_CHAR_9) + { + result += byte - LIT_CHAR_0; + } + else + { + byte = LEXER_TO_ASCII_LOWERCASE (byte); + if (byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F) + { + result += byte - (LIT_CHAR_LOWERCASE_A - 10); + } + else + { + return UINT32_MAX; + } + } + + if (result >= (LIT_UNICODE_CODE_POINT_MAX + 1) || source_p >= source_end_p) + { + return UINT32_MAX; + } + length++; + } while (*source_p != LIT_CHAR_RIGHT_BRACE); + + *length_p = length; + return result; +} /* lexer_hex_in_braces_to_code_point */ + +/** + * Parse hexadecimal character sequence + * + * @return character value + */ +static lit_code_point_t +lexer_unchecked_hex_to_character (const uint8_t **source_p) /**< [in, out] current source position */ +{ + lit_code_point_t result = 0; + const uint8_t *char_p = *source_p; + uint32_t length = (char_p[-1] == LIT_CHAR_LOWERCASE_U) ? 4 : 2; + + if (char_p[0] == LIT_CHAR_LEFT_BRACE) + { + length = 0; + char_p++; + } + + while (true) + { + uint32_t byte = *char_p++; + + result <<= 4; + + if (byte >= LIT_CHAR_0 && byte <= LIT_CHAR_9) + { + result += byte - LIT_CHAR_0; + } + else + { + JERRY_ASSERT ((byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F) + || (byte >= LIT_CHAR_UPPERCASE_A && byte <= LIT_CHAR_UPPERCASE_F)); + + result += LEXER_TO_ASCII_LOWERCASE (byte) - (LIT_CHAR_LOWERCASE_A - 10); + } + + JERRY_ASSERT (result <= LIT_UNICODE_CODE_POINT_MAX); + + if (length == 0) + { + if (*char_p != LIT_CHAR_RIGHT_BRACE) + { + continue; + } + + *source_p = char_p + 1; + return result; + } + + if (--length == 0) + { + *source_p = char_p; + return result; + } + } +} /* lexer_unchecked_hex_to_character */ + +/** + * Skip space mode + */ +typedef enum +{ + LEXER_SKIP_SPACES, /**< skip spaces mode */ + LEXER_SKIP_SINGLE_LINE_COMMENT, /**< parse single line comment */ + LEXER_SKIP_MULTI_LINE_COMMENT, /**< parse multi line comment */ +} skip_mode_t; + +/** + * Skip spaces. + */ +static void +lexer_skip_spaces (parser_context_t *context_p) /**< context */ +{ + skip_mode_t mode = LEXER_SKIP_SPACES; + const uint8_t *source_end_p = context_p->source_end_p; + + if (context_p->token.flags & LEXER_NO_SKIP_SPACES) + { + context_p->token.flags &= (uint8_t) ~LEXER_NO_SKIP_SPACES; + return; + } + + context_p->token.flags = 0; + + while (true) + { + if (context_p->source_p >= source_end_p) + { + if (mode == LEXER_SKIP_MULTI_LINE_COMMENT) + { + parser_raise_error (context_p, PARSER_ERR_UNTERMINATED_MULTILINE_COMMENT); + } + return; + } + + switch (context_p->source_p[0]) + { + case LIT_CHAR_CR: + { + if (context_p->source_p + 1 < source_end_p && context_p->source_p[1] == LIT_CHAR_LF) + { + context_p->source_p++; + } + /* FALLTHRU */ + } + + case LIT_CHAR_LF: + { + context_p->line++; + context_p->column = 0; + context_p->token.flags = LEXER_WAS_NEWLINE; + + if (mode == LEXER_SKIP_SINGLE_LINE_COMMENT) + { + mode = LEXER_SKIP_SPACES; + } + /* FALLTHRU */ + } + + case LIT_CHAR_VTAB: + case LIT_CHAR_FF: + case LIT_CHAR_SP: + { + context_p->source_p++; + context_p->column++; + continue; + } + + case LIT_CHAR_TAB: + { + context_p->column = align_column_to_tab (context_p->column); + context_p->source_p++; + continue; + } + + case LIT_CHAR_SLASH: + { + if (mode == LEXER_SKIP_SPACES && context_p->source_p + 1 < source_end_p) + { + if (context_p->source_p[1] == LIT_CHAR_SLASH) + { + mode = LEXER_SKIP_SINGLE_LINE_COMMENT; + } + else if (context_p->source_p[1] == LIT_CHAR_ASTERISK) + { + mode = LEXER_SKIP_MULTI_LINE_COMMENT; + context_p->token.line = context_p->line; + context_p->token.column = context_p->column; + } + + if (mode != LEXER_SKIP_SPACES) + { + context_p->source_p += 2; + PARSER_PLUS_EQUAL_LC (context_p->column, 2); + continue; + } + } + break; + } + + case LIT_CHAR_ASTERISK: + { + if (mode == LEXER_SKIP_MULTI_LINE_COMMENT && context_p->source_p + 1 < source_end_p + && context_p->source_p[1] == LIT_CHAR_SLASH) + { + mode = LEXER_SKIP_SPACES; + context_p->source_p += 2; + PARSER_PLUS_EQUAL_LC (context_p->column, 2); + continue; + } + break; + } + + case 0xc2: + { + if (context_p->source_p + 1 < source_end_p && context_p->source_p[1] == 0xa0) + { + /* Codepoint \u00A0 */ + context_p->source_p += 2; + context_p->column++; + continue; + } + break; + } + + case LEXER_NEWLINE_LS_PS_BYTE_1: + { + JERRY_ASSERT (context_p->source_p + 2 < source_end_p); + if (LEXER_NEWLINE_LS_PS_BYTE_23 (context_p->source_p)) + { + /* Codepoint \u2028 and \u2029 */ + context_p->source_p += 3; + context_p->line++; + context_p->column = 1; + context_p->token.flags = LEXER_WAS_NEWLINE; + + if (mode == LEXER_SKIP_SINGLE_LINE_COMMENT) + { + mode = LEXER_SKIP_SPACES; + } + continue; + } + break; + } + + case 0xef: + { + if (context_p->source_p + 2 < source_end_p && context_p->source_p[1] == 0xbb && context_p->source_p[2] == 0xbf) + { + /* Codepoint \uFEFF */ + context_p->source_p += 3; + context_p->column++; + continue; + } + break; + } + + default: + { + break; + } + } + + if (mode == LEXER_SKIP_SPACES) + { + return; + } + + context_p->source_p++; + + if (context_p->source_p < source_end_p && !IS_UTF8_INTERMEDIATE_OCTET (context_p->source_p[0])) + { + context_p->column++; + } + } +} /* lexer_skip_spaces */ + +/** + * Skip all the continuous empty statements. + */ +void +lexer_skip_empty_statements (parser_context_t *context_p) /**< context */ +{ + lexer_skip_spaces (context_p); + + while (context_p->source_p < context_p->source_end_p && *context_p->source_p == LIT_CHAR_SEMICOLON) + { + lexer_consume_next_character (context_p); + lexer_skip_spaces (context_p); + } + + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); +} /* lexer_skip_empty_statements */ + +/** + * Checks whether the keyword has escape sequences. + */ +#define LEXER_CHECK_INVALID_KEYWORD(ident_start_p, buffer_p) \ + (JERRY_UNLIKELY ((ident_start_p) == (buffer_p)) \ + && !(context_p->global_status_flags & ECMA_PARSE_INTERNAL_PRE_SCANNING)) + +/** + * Keyword data. + */ +typedef struct +{ + const uint8_t *keyword_p; /**< keyword string */ + lexer_token_type_t type; /**< keyword token type */ +} keyword_string_t; + +/** + * @{ + * Keyword defines + */ +#define LEXER_KEYWORD(name, type) \ + { \ + (const uint8_t *) (name), (type) \ + } +#define LEXER_KEYWORD_LIST_LENGTH(name) (const uint8_t) (sizeof ((name)) / sizeof ((name)[0])) +/** @} */ + +/** + * Length of the shortest keyword. + */ +#define LEXER_KEYWORD_MIN_LENGTH 2 + +/** + * Length of the longest keyword. + */ +#define LEXER_KEYWORD_MAX_LENGTH 10 + +/** + * Keywords with 2 characters. + */ +static const keyword_string_t keywords_with_length_2[] = { + LEXER_KEYWORD ("do", LEXER_KEYW_DO), + LEXER_KEYWORD ("if", LEXER_KEYW_IF), + LEXER_KEYWORD ("in", LEXER_KEYW_IN), +}; + +/** + * Keywords with 3 characters. + */ +static const keyword_string_t keywords_with_length_3[] = { + LEXER_KEYWORD ("for", LEXER_KEYW_FOR), LEXER_KEYWORD ("let", LEXER_KEYW_LET), LEXER_KEYWORD ("new", LEXER_KEYW_NEW), + LEXER_KEYWORD ("try", LEXER_KEYW_TRY), LEXER_KEYWORD ("var", LEXER_KEYW_VAR), +}; + +/** + * Keywords with 4 characters. + */ +static const keyword_string_t keywords_with_length_4[] = { + LEXER_KEYWORD ("case", LEXER_KEYW_CASE), LEXER_KEYWORD ("else", LEXER_KEYW_ELSE), + LEXER_KEYWORD ("enum", LEXER_KEYW_ENUM), LEXER_KEYWORD ("eval", LEXER_KEYW_EVAL), +#if JERRY_MODULE_SYSTEM + LEXER_KEYWORD ("meta", LEXER_KEYW_META), +#endif /* JERRY_MODULE_SYSTEM */ + LEXER_KEYWORD ("null", LEXER_LIT_NULL), LEXER_KEYWORD ("this", LEXER_KEYW_THIS), + LEXER_KEYWORD ("true", LEXER_LIT_TRUE), LEXER_KEYWORD ("void", LEXER_KEYW_VOID), + LEXER_KEYWORD ("with", LEXER_KEYW_WITH), +}; + +/** + * Keywords with 5 characters. + */ +static const keyword_string_t keywords_with_length_5[] = { + LEXER_KEYWORD ("async", LEXER_KEYW_ASYNC), LEXER_KEYWORD ("await", LEXER_KEYW_AWAIT), + LEXER_KEYWORD ("break", LEXER_KEYW_BREAK), LEXER_KEYWORD ("catch", LEXER_KEYW_CATCH), + LEXER_KEYWORD ("class", LEXER_KEYW_CLASS), LEXER_KEYWORD ("const", LEXER_KEYW_CONST), + LEXER_KEYWORD ("false", LEXER_LIT_FALSE), LEXER_KEYWORD ("super", LEXER_KEYW_SUPER), + LEXER_KEYWORD ("throw", LEXER_KEYW_THROW), LEXER_KEYWORD ("while", LEXER_KEYW_WHILE), + LEXER_KEYWORD ("yield", LEXER_KEYW_YIELD), +}; + +/** + * Keywords with 6 characters. + */ +static const keyword_string_t keywords_with_length_6[] = { + LEXER_KEYWORD ("delete", LEXER_KEYW_DELETE), LEXER_KEYWORD ("export", LEXER_KEYW_EXPORT), + LEXER_KEYWORD ("import", LEXER_KEYW_IMPORT), LEXER_KEYWORD ("public", LEXER_KEYW_PUBLIC), + LEXER_KEYWORD ("return", LEXER_KEYW_RETURN), LEXER_KEYWORD ("static", LEXER_KEYW_STATIC), + LEXER_KEYWORD ("switch", LEXER_KEYW_SWITCH), LEXER_KEYWORD ("typeof", LEXER_KEYW_TYPEOF), +}; + +/** + * Keywords with 7 characters. + */ +static const keyword_string_t keywords_with_length_7[] = { + LEXER_KEYWORD ("default", LEXER_KEYW_DEFAULT), LEXER_KEYWORD ("extends", LEXER_KEYW_EXTENDS), + LEXER_KEYWORD ("finally", LEXER_KEYW_FINALLY), LEXER_KEYWORD ("package", LEXER_KEYW_PACKAGE), + LEXER_KEYWORD ("private", LEXER_KEYW_PRIVATE), +}; + +/** + * Keywords with 8 characters. + */ +static const keyword_string_t keywords_with_length_8[] = { + LEXER_KEYWORD ("continue", LEXER_KEYW_CONTINUE), + LEXER_KEYWORD ("debugger", LEXER_KEYW_DEBUGGER), + LEXER_KEYWORD ("function", LEXER_KEYW_FUNCTION), +}; + +/** + * Keywords with 9 characters. + */ +static const keyword_string_t keywords_with_length_9[] = { + LEXER_KEYWORD ("arguments", LEXER_KEYW_ARGUMENTS), + LEXER_KEYWORD ("interface", LEXER_KEYW_INTERFACE), + LEXER_KEYWORD ("protected", LEXER_KEYW_PROTECTED), +}; + +/** + * Keywords with 10 characters. + */ +static const keyword_string_t keywords_with_length_10[] = { + LEXER_KEYWORD ("implements", LEXER_KEYW_IMPLEMENTS), + LEXER_KEYWORD ("instanceof", LEXER_KEYW_INSTANCEOF), +}; + +/** + * List of the keyword groups. + */ +static const keyword_string_t *const keyword_strings_list[] = { keywords_with_length_2, keywords_with_length_3, + keywords_with_length_4, keywords_with_length_5, + keywords_with_length_6, keywords_with_length_7, + keywords_with_length_8, keywords_with_length_9, + keywords_with_length_10 }; + +JERRY_STATIC_ASSERT ((sizeof (keyword_strings_list) / sizeof (const keyword_string_t *) == (LEXER_KEYWORD_MAX_LENGTH - LEXER_KEYWORD_MIN_LENGTH) + 1), + keyword_strings_list_size_must_equal_to_keyword_max_length_difference); + +/** + * List of the keyword groups length. + */ +static const uint8_t keyword_lengths_list[] = { + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_2), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_3), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_4), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_5), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_6), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_7), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_8), LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_9), + LEXER_KEYWORD_LIST_LENGTH (keywords_with_length_10) +}; + +#undef LEXER_KEYWORD +#undef LEXER_KEYWORD_LIST_LENGTH + +JERRY_STATIC_ASSERT (((int)LEXER_FIRST_NON_RESERVED_KEYWORD < (int)LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD), + lexer_first_non_reserved_keyword_must_be_before_lexer_first_future_strict_reserved_word); + +/** + * Parse identifier. + * + * @return true, if an identifier is parsed, false otherwise + */ +static bool +lexer_parse_identifier (parser_context_t *context_p, /**< context */ + lexer_parse_options_t options) /**< check keywords */ +{ + /* Only very few identifiers contains \u escape sequences. */ + const uint8_t *source_p = context_p->source_p; + /* Note: newline or tab cannot be part of an identifier. */ + parser_line_counter_t column = context_p->column; + const uint8_t *source_end_p = context_p->source_end_p; + size_t length = 0; + lexer_lit_location_flags_t status_flags = LEXER_LIT_LOCATION_IS_ASCII; + + do + { + if (*source_p == LIT_CHAR_BACKSLASH) + { + /* After a backslash an identifier must start. */ + lit_code_point_t code_point = UINT32_MAX; + uint32_t escape_length = 6; + + if (options & (LEXER_PARSE_CHECK_START_AND_RETURN | LEXER_PARSE_CHECK_PART_AND_RETURN)) + { + return true; + } + + status_flags = LEXER_LIT_LOCATION_HAS_ESCAPE; + + if (source_p + 5 <= source_end_p && source_p[1] == LIT_CHAR_LOWERCASE_U) + { + if (source_p[2] == LIT_CHAR_LEFT_BRACE) + { + code_point = lexer_hex_in_braces_to_code_point (source_p + 3, source_end_p, &escape_length); + } + else if (source_p + 6 <= source_end_p) + { + code_point = lexer_hex_to_code_point (source_p + 2, 4); + } + } + + if (code_point == UINT32_MAX) + { + context_p->source_p = source_p; + context_p->token.column = column; + parser_raise_error (context_p, PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE); + } + + if (length == 0) + { + if (!lit_code_point_is_identifier_start (code_point)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_IDENTIFIER_START); + } + } + else + { + if (!lit_code_point_is_identifier_part (code_point)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_IDENTIFIER_PART); + } + } + + length += lit_code_point_get_cesu8_length (code_point); + source_p += escape_length; + PARSER_PLUS_EQUAL_LC (column, escape_length); + continue; + } + + lit_code_point_t code_point = *source_p; + lit_utf8_size_t utf8_length = 1, decoded_length = 1, char_count = 1; + + if (JERRY_UNLIKELY (code_point >= LIT_UTF8_2_BYTE_MARKER)) + { + status_flags = (lexer_lit_location_flags_t) ((uint32_t) status_flags & (uint32_t) ~LEXER_LIT_LOCATION_IS_ASCII); + + utf8_length = lit_read_code_point_from_utf8 (source_p, (lit_utf8_size_t) (source_end_p - source_p), &code_point); + decoded_length = utf8_length; + + /* Only ES2015+ supports code points outside of the basic plane which can be part of an identifier. */ + if ((code_point >= LIT_UTF16_HIGH_SURROGATE_MIN && code_point <= LIT_UTF16_HIGH_SURROGATE_MAX) + && source_p + 3 < source_end_p) + { + lit_code_point_t low_surrogate; + lit_read_code_point_from_utf8 (source_p + 3, (lit_utf8_size_t) (source_end_p - (source_p + 3)), &low_surrogate); + + if (low_surrogate >= LIT_UTF16_LOW_SURROGATE_MIN && low_surrogate <= LIT_UTF16_LOW_SURROGATE_MAX) + { + code_point = lit_convert_surrogate_pair_to_code_point ((ecma_char_t) code_point, (ecma_char_t) low_surrogate); + utf8_length = 2 * 3; + decoded_length = 2 * 3; + char_count = 2; + } + } + else if (source_p[0] >= LIT_UTF8_4_BYTE_MARKER) + { + decoded_length = 2 * 3; + status_flags = LEXER_LIT_LOCATION_HAS_ESCAPE; + } + } + + if (length == 0) + { + if (JERRY_UNLIKELY (options & (LEXER_PARSE_CHECK_START_AND_RETURN | LEXER_PARSE_CHECK_PART_AND_RETURN))) + { + if (options & LEXER_PARSE_CHECK_START_AND_RETURN) + { + return lit_code_point_is_identifier_start (code_point); + } + else + { + return lit_code_point_is_identifier_part (code_point); + } + } + + if (!lit_code_point_is_identifier_start (code_point)) + { + return false; + } + } + else if (!lit_code_point_is_identifier_part (code_point)) + { + break; + } + + source_p += utf8_length; + length += decoded_length; + PARSER_PLUS_EQUAL_LC (column, char_count); + } while (source_p < source_end_p); + + JERRY_ASSERT (length > 0); + + context_p->token.type = LEXER_LITERAL; + context_p->token.lit_location.type = LEXER_IDENT_LITERAL; + context_p->token.lit_location.status_flags = (uint8_t) status_flags; + + context_p->token.column = context_p->column; + context_p->token.lit_location.char_p = context_p->source_p; + context_p->token.lit_location.length = (prop_length_t) length; + + if (JERRY_UNLIKELY (length > PARSER_MAXIMUM_IDENT_LENGTH)) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_TOO_LONG); + } + + /* Check keywords. */ + if ((options & LEXER_PARSE_CHECK_KEYWORDS) + && (length >= LEXER_KEYWORD_MIN_LENGTH && length <= LEXER_KEYWORD_MAX_LENGTH)) + { + const uint8_t *ident_start_p = context_p->source_p; + uint8_t buffer_p[LEXER_KEYWORD_MAX_LENGTH]; + + if (JERRY_UNLIKELY (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + lexer_convert_ident_to_cesu8 (buffer_p, ident_start_p, (prop_length_t) length); + ident_start_p = buffer_p; + } + + const keyword_string_t *keyword_list_p = keyword_strings_list[length - LEXER_KEYWORD_MIN_LENGTH]; + + int start = 0; + int end = keyword_lengths_list[length - LEXER_KEYWORD_MIN_LENGTH]; + int middle = end / 2; + + do + { + const keyword_string_t *keyword_p = keyword_list_p + middle; + int compare_result = ident_start_p[0] - keyword_p->keyword_p[0]; + + if (compare_result == 0) + { + compare_result = memcmp (ident_start_p, keyword_p->keyword_p, length); + + if (compare_result == 0) + { + context_p->token.keyword_type = (uint8_t) keyword_p->type; + + if (JERRY_LIKELY (keyword_p->type < LEXER_FIRST_NON_RESERVED_KEYWORD)) + { + if (JERRY_UNLIKELY (keyword_p->type == LEXER_KEYW_AWAIT)) + { + if (!(context_p->status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_CLASS_STATIC_BLOCK)) + && !(context_p->global_status_flags & ECMA_PARSE_MODULE)) + { + break; + } + + if (context_p->status_flags & PARSER_DISALLOW_AWAIT_YIELD) + { + if (LEXER_CHECK_INVALID_KEYWORD (ident_start_p, buffer_p)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + parser_raise_error (context_p, PARSER_ERR_AWAIT_NOT_ALLOWED); + } + + context_p->token.type = (uint8_t) LEXER_KEYW_AWAIT; + break; + } + + if (LEXER_CHECK_INVALID_KEYWORD (ident_start_p, buffer_p)) + { + /* Escape sequences are not allowed in a keyword. */ + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + + context_p->token.type = (uint8_t) keyword_p->type; + break; + } + + if (keyword_p->type == LEXER_KEYW_LET && (context_p->status_flags & PARSER_IS_STRICT)) + { + if (LEXER_CHECK_INVALID_KEYWORD (ident_start_p, buffer_p)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + + context_p->token.type = (uint8_t) LEXER_KEYW_LET; + break; + } + + if (keyword_p->type == LEXER_KEYW_YIELD && (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION)) + { + if (context_p->status_flags & PARSER_DISALLOW_AWAIT_YIELD) + { + if (LEXER_CHECK_INVALID_KEYWORD (ident_start_p, buffer_p)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + parser_raise_error (context_p, PARSER_ERR_YIELD_NOT_ALLOWED); + } + + context_p->token.type = (uint8_t) LEXER_KEYW_YIELD; + break; + } + + if (keyword_p->type == LEXER_KEYW_ARGUMENTS && (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD)) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENTS_IN_CLASS_FIELD); + } + + if (keyword_p->type >= LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD && (context_p->status_flags & PARSER_IS_STRICT) + && !(options & LEXER_PARSE_NO_STRICT_IDENT_ERROR)) + { + parser_raise_error (context_p, PARSER_ERR_STRICT_IDENT_NOT_ALLOWED); + } + break; + } + } + + if (compare_result > 0) + { + start = middle + 1; + } + else + { + JERRY_ASSERT (compare_result < 0); + end = middle; + } + + middle = (start + end) / 2; + } while (start < end); + } + + context_p->source_p = source_p; + context_p->column = column; + return true; +} /* lexer_parse_identifier */ + +#undef LEXER_CHECK_INVALID_KEYWORD + +/** + * Parse string. + */ +void +lexer_parse_string (parser_context_t *context_p, /**< context */ + lexer_string_options_t opts) /**< options */ +{ + int32_t raw_length_adjust = 0; + + uint8_t str_end_character = context_p->source_p[0]; + const uint8_t *source_p = context_p->source_p + 1; + const uint8_t *string_start_p = source_p; + const uint8_t *source_end_p = context_p->source_end_p; + parser_line_counter_t line = context_p->line; + parser_line_counter_t column = (parser_line_counter_t) (context_p->column + 1); + parser_line_counter_t original_line = line; + parser_line_counter_t original_column = column; + size_t length = 0; + lexer_lit_location_flags_t status_flags = LEXER_LIT_LOCATION_IS_ASCII; + + if (str_end_character == LIT_CHAR_RIGHT_BRACE) + { + str_end_character = LIT_CHAR_GRAVE_ACCENT; + } + + while (true) + { + if (source_p >= source_end_p) + { + context_p->token.line = original_line; + context_p->token.column = (parser_line_counter_t) (original_column - 1); + parser_raise_error (context_p, PARSER_ERR_UNTERMINATED_STRING); + } + + if (*source_p == str_end_character) + { + break; + } + + if (*source_p == LIT_CHAR_BACKSLASH) + { + source_p++; + column++; + if (source_p >= source_end_p) + { + /* Will throw an unterminated string error. */ + continue; + } + + status_flags = LEXER_LIT_LOCATION_HAS_ESCAPE; + + /* Newline is ignored. */ + if (*source_p == LIT_CHAR_CR) + { + source_p++; + if (source_p < source_end_p && *source_p == LIT_CHAR_LF) + { + raw_length_adjust--; + source_p++; + } + + line++; + column = 1; + continue; + } + else if (*source_p == LIT_CHAR_LF) + { + source_p++; + line++; + column = 1; + continue; + } + else if (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) + { + source_p += 3; + line++; + column = 1; + continue; + } + + if (opts & LEXER_STRING_RAW) + { + if ((*source_p == LIT_CHAR_GRAVE_ACCENT) || (*source_p == LIT_CHAR_BACKSLASH)) + { + source_p++; + column++; + length++; + } + continue; + } + + if (*source_p == LIT_CHAR_0 && source_p + 1 < source_end_p + && (*(source_p + 1) < LIT_CHAR_0 || *(source_p + 1) > LIT_CHAR_9)) + { + source_p++; + column++; + length++; + continue; + } + + /* Except \x, \u, and octal numbers, everything is + * converted to a character which has the same byte length. */ + if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_3) + { + if (str_end_character == LIT_CHAR_GRAVE_ACCENT) + { + parser_raise_error (context_p, PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE); + } + + if (context_p->status_flags & PARSER_IS_STRICT) + { + parser_raise_error (context_p, PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED); + } + + source_p++; + column++; + + if (source_p < source_end_p && *source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_7) + { + source_p++; + column++; + + if (source_p < source_end_p && *source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_7) + { + /* Numbers >= 0x200 (0x80) requires + * two bytes for encoding in UTF-8. */ + if (source_p[-2] >= LIT_CHAR_2) + { + length++; + } + + source_p++; + column++; + } + } + + length++; + continue; + } + + if (*source_p >= LIT_CHAR_4 && *source_p <= LIT_CHAR_7) + { + if (context_p->status_flags & PARSER_IS_STRICT) + { + parser_raise_error (context_p, PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED); + } + + source_p++; + column++; + + if (source_p < source_end_p && *source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_7) + { + source_p++; + column++; + } + + /* The maximum number is 0x4d so the UTF-8 + * representation is always one byte. */ + length++; + continue; + } + + if (*source_p == LIT_CHAR_LOWERCASE_X || *source_p == LIT_CHAR_LOWERCASE_U) + { + uint32_t escape_length = (*source_p == LIT_CHAR_LOWERCASE_X) ? 3 : 5; + lit_code_point_t code_point = UINT32_MAX; + + if (source_p + 4 <= source_end_p && source_p[0] == LIT_CHAR_LOWERCASE_U && source_p[1] == LIT_CHAR_LEFT_BRACE) + { + code_point = lexer_hex_in_braces_to_code_point (source_p + 2, source_end_p, &escape_length); + escape_length--; + } + else + { + if (source_p + escape_length <= source_end_p) + { + code_point = lexer_hex_to_code_point (source_p + 1, escape_length - 1); + } + } + + if (code_point == UINT32_MAX) + { + context_p->token.line = line; + context_p->token.column = (parser_line_counter_t) (column - 1); + parser_raise_error (context_p, PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE); + } + + length += lit_code_point_get_cesu8_length (code_point); + + source_p += escape_length; + PARSER_PLUS_EQUAL_LC (column, escape_length); + continue; + } + } + else if (str_end_character == LIT_CHAR_GRAVE_ACCENT && source_p[0] == LIT_CHAR_DOLLAR_SIGN + && source_p + 1 < source_end_p && source_p[1] == LIT_CHAR_LEFT_BRACE) + { + raw_length_adjust--; + source_p++; + break; + } + + if (*source_p >= LIT_UTF8_4_BYTE_MARKER) + { + /* Processing 4 byte unicode sequence (even if it is + * after a backslash). Always converted to two 3 byte + * long sequence. */ + length += 2 * 3; + status_flags = LEXER_LIT_LOCATION_HAS_ESCAPE; + source_p += 4; + raw_length_adjust += 2; + column++; + continue; + } + else if (*source_p == LIT_CHAR_TAB) + { + column = align_column_to_tab (column); + /* Subtract -1 because column is increased below. */ + column--; + } + else if (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) + { + source_p += 3; + length += 3; + line++; + column = 1; + continue; + } + else if (str_end_character == LIT_CHAR_GRAVE_ACCENT) + { + /* Newline (without backslash) is part of the string. + Note: ECMAScript v6, 11.8.6.1 or are both normalized to */ + if (*source_p == LIT_CHAR_CR) + { + status_flags = LEXER_LIT_LOCATION_HAS_ESCAPE; + source_p++; + length++; + if (source_p < source_end_p && *source_p == LIT_CHAR_LF) + { + source_p++; + raw_length_adjust--; + } + line++; + column = 1; + continue; + } + else if (*source_p == LIT_CHAR_LF) + { + source_p++; + length++; + line++; + column = 1; + continue; + } + } + else if (*source_p == LIT_CHAR_CR || *source_p == LIT_CHAR_LF) + { + context_p->token.line = line; + context_p->token.column = column; + parser_raise_error (context_p, PARSER_ERR_NEWLINE_NOT_ALLOWED); + } + + source_p++; + column++; + length++; + + while (source_p < source_end_p && IS_UTF8_INTERMEDIATE_OCTET (*source_p)) + { + source_p++; + length++; + } + } + + if (opts & LEXER_STRING_RAW) + { + length = (size_t) ((source_p - string_start_p) + raw_length_adjust); + } + + if (length > PARSER_MAXIMUM_STRING_LENGTH) + { + parser_raise_error (context_p, PARSER_ERR_STRING_TOO_LONG); + } + + context_p->token.type = ((str_end_character != LIT_CHAR_GRAVE_ACCENT) ? LEXER_LITERAL : LEXER_TEMPLATE_LITERAL); + + /* Fill literal data. */ + context_p->token.lit_location.char_p = string_start_p; + context_p->token.lit_location.length = (prop_length_t) length; + context_p->token.lit_location.type = LEXER_STRING_LITERAL; + context_p->token.lit_location.status_flags = (uint8_t) status_flags; + + context_p->source_p = source_p + 1; + context_p->line = line; + context_p->column = (parser_line_counter_t) (column + 1); +} /* lexer_parse_string */ + +/** + * Check number + */ +static void +lexer_check_numbers (parser_context_t *context_p, /**< context */ + const uint8_t **source_p, /**< source_pointer */ + const uint8_t *source_end_p, /**< end of the source */ + const ecma_char_t digit_max, /**< maximum of the number range */ + const bool is_legacy) /**< is legacy octal number */ +{ + while (true) + { + while (*source_p < source_end_p && *source_p[0] >= LIT_CHAR_0 && *source_p[0] <= digit_max) + { + *source_p += 1; + } + if (*source_p != source_end_p && *source_p[0] == LIT_CHAR_UNDERSCORE) + { + *source_p += 1; + if (is_legacy || *source_p == source_end_p || *source_p[0] == LIT_CHAR_UNDERSCORE || *source_p[0] > digit_max + || *source_p[0] < LIT_CHAR_0) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); + } + continue; + } + + break; + } +} /* lexer_check_numbers */ + +/** + * Parse number. + */ +static void +lexer_parse_number (parser_context_t *context_p) /**< context */ +{ + const uint8_t *source_p = context_p->source_p; + const uint8_t *source_end_p = context_p->source_end_p; + bool can_be_float = false; +#if JERRY_BUILTIN_BIGINT + bool can_be_bigint = true; +#endif /* JERRY_BUILTIN_BIGINT */ + size_t length; + + context_p->token.type = LEXER_LITERAL; + context_p->token.extra_value = LEXER_NUMBER_DECIMAL; + context_p->token.lit_location.char_p = source_p; + context_p->token.lit_location.type = LEXER_NUMBER_LITERAL; + context_p->token.lit_location.status_flags = LEXER_LIT_LOCATION_IS_ASCII; + + if (source_p[0] == LIT_CHAR_0 && source_p + 1 < source_end_p) + { + if (source_p[1] == LIT_CHAR_UNDERSCORE) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); + } + + if (LEXER_TO_ASCII_LOWERCASE (source_p[1]) == LIT_CHAR_LOWERCASE_X) + { + context_p->token.extra_value = LEXER_NUMBER_HEXADECIMAL; + source_p += 2; + + if (source_p >= source_end_p || !lit_char_is_hex_digit (source_p[0])) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_HEX_DIGIT); + } + + do + { + source_p++; + if (source_p < source_end_p && source_p[0] == LIT_CHAR_UNDERSCORE) + { + source_p++; + if (source_p == source_end_p || !lit_char_is_hex_digit (source_p[0])) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); + } + } + } while (source_p < source_end_p && lit_char_is_hex_digit (source_p[0])); + } + else if (LEXER_TO_ASCII_LOWERCASE (source_p[1]) == LIT_CHAR_LOWERCASE_O) + { + context_p->token.extra_value = LEXER_NUMBER_OCTAL; + source_p += 2; + + if (source_p >= source_end_p || !lit_char_is_octal_digit (source_p[0])) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_OCTAL_DIGIT); + } + + lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_7, false); + } + else if (source_p[1] >= LIT_CHAR_0 && source_p[1] <= LIT_CHAR_9) + { + context_p->token.extra_value = LEXER_NUMBER_OCTAL; +#if JERRY_BUILTIN_BIGINT + can_be_bigint = false; +#endif /* JERRY_BUILTIN_BIGINT */ + + if (context_p->status_flags & PARSER_IS_STRICT) + { + parser_raise_error (context_p, PARSER_ERR_OCTAL_NUMBER_NOT_ALLOWED); + } + + lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_7, true); + + if (source_p < source_end_p && source_p[0] >= LIT_CHAR_8 && source_p[0] <= LIT_CHAR_9) + { + lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_9, true); + context_p->token.extra_value = LEXER_NUMBER_DECIMAL; + } + } + + else if (LEXER_TO_ASCII_LOWERCASE (source_p[1]) == LIT_CHAR_LOWERCASE_B) + { + context_p->token.extra_value = LEXER_NUMBER_BINARY; + source_p += 2; + + if (source_p >= source_end_p || !lit_char_is_binary_digit (source_p[0])) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_BIN_DIGIT); + } + + do + { + source_p++; + if (source_p < source_end_p && source_p[0] == LIT_CHAR_UNDERSCORE) + { + source_p++; + if (source_p == source_end_p || source_p[0] > LIT_CHAR_9 || source_p[0] < LIT_CHAR_0) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); + } + } + } while (source_p < source_end_p && lit_char_is_binary_digit (source_p[0])); + } + else + { + can_be_float = true; + source_p++; + } + } + else + { + lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_9, false); + can_be_float = true; + } + + if (can_be_float) + { + if (source_p < source_end_p && source_p[0] == LIT_CHAR_DOT) + { + source_p++; +#if JERRY_BUILTIN_BIGINT + can_be_bigint = false; +#endif /* JERRY_BUILTIN_BIGINT */ + + if (source_p < source_end_p && source_p[0] == LIT_CHAR_UNDERSCORE) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER); + } + + lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_9, false); + } + + if (source_p < source_end_p && LEXER_TO_ASCII_LOWERCASE (source_p[0]) == LIT_CHAR_LOWERCASE_E) + { + source_p++; +#if JERRY_BUILTIN_BIGINT + can_be_bigint = false; +#endif /* JERRY_BUILTIN_BIGINT */ + + if (source_p < source_end_p && (source_p[0] == LIT_CHAR_PLUS || source_p[0] == LIT_CHAR_MINUS)) + { + source_p++; + } + + if (source_p >= source_end_p || source_p[0] < LIT_CHAR_0 || source_p[0] > LIT_CHAR_9) + { + parser_raise_error (context_p, PARSER_ERR_MISSING_EXPONENT); + } + + lexer_check_numbers (context_p, &source_p, source_end_p, LIT_CHAR_9, false); + } + } + +#if JERRY_BUILTIN_BIGINT + if (source_p < source_end_p && source_p[0] == LIT_CHAR_LOWERCASE_N) + { + if (!can_be_bigint) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_BIGINT); + } + context_p->token.extra_value = LEXER_NUMBER_BIGINT; + source_p++; + } +#endif /* JERRY_BUILTIN_BIGINT */ + + length = (size_t) (source_p - context_p->source_p); + if (length > PARSER_MAXIMUM_STRING_LENGTH) + { + parser_raise_error (context_p, PARSER_ERR_NUMBER_TOO_LONG); + } + + context_p->token.lit_location.length = (prop_length_t) length; + PARSER_PLUS_EQUAL_LC (context_p->column, length); + context_p->source_p = source_p; + + if (source_p < source_end_p && lexer_parse_identifier (context_p, LEXER_PARSE_CHECK_START_AND_RETURN)) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_AFTER_NUMBER); + } +} /* lexer_parse_number */ + +/** + * One character long token (e.g. comma). + * + * @param char1 character + * @param type1 type + */ +#define LEXER_TYPE_A_TOKEN(char1, type1) \ + case (uint8_t) (char1): \ + { \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ + } + +/** + * Token pair, where the first token is prefix of the second (e.g. % and %=). + * + * @param char1 first character + * @param type1 type of the first character + * @param char2 second character + * @param type2 type of the second character + */ +#define LEXER_TYPE_B_TOKEN(char1, type1, char2, type2) \ + case (uint8_t) (char1): \ + { \ + if (length >= 2 && context_p->source_p[1] == (uint8_t) (char2)) \ + { \ + context_p->token.type = (type2); \ + length = 2; \ + break; \ + } \ + \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ + } + +/** + * Three tokens, where the first is the prefix of the other two (e.g. &, &&, &=). + * + * @param char1 first character + * @param type1 type of the first character + * @param char2 second character + * @param type2 type of the second character + * @param char3 third character + * @param type3 type of the third character + */ +#define LEXER_TYPE_C_TOKEN(char1, type1, char2, type2, char3, type3) \ + case (uint8_t) (char1): \ + { \ + if (length >= 2) \ + { \ + if (context_p->source_p[1] == (uint8_t) (char2)) \ + { \ + context_p->token.type = (type2); \ + length = 2; \ + break; \ + } \ + \ + if (context_p->source_p[1] == (uint8_t) (char3)) \ + { \ + context_p->token.type = (type3); \ + length = 2; \ + break; \ + } \ + } \ + \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ + } + +/** + * Four tokens, where the first is the prefix of the other three + * and the second is prefix of the fourth (e.g. &, &&, &=, &&= ). + * + * @param char1 first character + * @param type1 type of the first character + * @param char2 second character + * @param type2 type of the second character + * @param char3 third character + * @param type3 type of the third character + * @param char4 fourth character + * @param type4 type of the fourth character + */ +#define LEXER_TYPE_D_TOKEN(char1, type1, char2, type2, char3, type3, char4, type4) \ + case (uint8_t) (char1): \ + { \ + if (length >= 2) \ + { \ + if (context_p->source_p[1] == (uint8_t) (char2)) \ + { \ + context_p->token.type = (type2); \ + length = 2; \ + break; \ + } \ + \ + if (context_p->source_p[1] == (uint8_t) (char3)) \ + { \ + if (length >= 3 && context_p->source_p[2] == (uint8_t) (char4)) \ + { \ + context_p->token.type = (type4); \ + length = 3; \ + break; \ + } \ + context_p->token.type = (type3); \ + length = 2; \ + break; \ + } \ + } \ + \ + context_p->token.type = (type1); \ + length = 1; \ + break; \ + } + +/** + * Get next token. + */ +void +lexer_next_token (parser_context_t *context_p) /**< context */ +{ + size_t length; + + lexer_skip_spaces (context_p); + + context_p->token.keyword_type = LEXER_EOS; + context_p->token.line = context_p->line; + context_p->token.column = context_p->column; + + length = (size_t) (context_p->source_end_p - context_p->source_p); + if (length == 0) + { + context_p->token.type = LEXER_EOS; + return; + } + + if (lexer_parse_identifier (context_p, LEXER_PARSE_CHECK_KEYWORDS)) + { + return; + } + + if (context_p->source_p[0] >= LIT_CHAR_0 && context_p->source_p[0] <= LIT_CHAR_9) + { + lexer_parse_number (context_p); + return; + } + + switch (context_p->source_p[0]) + { + LEXER_TYPE_A_TOKEN (LIT_CHAR_LEFT_BRACE, LEXER_LEFT_BRACE); + LEXER_TYPE_A_TOKEN (LIT_CHAR_LEFT_PAREN, LEXER_LEFT_PAREN); + LEXER_TYPE_A_TOKEN (LIT_CHAR_LEFT_SQUARE, LEXER_LEFT_SQUARE); + LEXER_TYPE_A_TOKEN (LIT_CHAR_RIGHT_BRACE, LEXER_RIGHT_BRACE); + LEXER_TYPE_A_TOKEN (LIT_CHAR_RIGHT_PAREN, LEXER_RIGHT_PAREN); + LEXER_TYPE_A_TOKEN (LIT_CHAR_RIGHT_SQUARE, LEXER_RIGHT_SQUARE); + LEXER_TYPE_A_TOKEN (LIT_CHAR_SEMICOLON, LEXER_SEMICOLON); + LEXER_TYPE_A_TOKEN (LIT_CHAR_COMMA, LEXER_COMMA); + LEXER_TYPE_A_TOKEN (LIT_CHAR_HASHMARK, LEXER_HASHMARK); + + case (uint8_t) LIT_CHAR_DOT: + { + if (length >= 2 && (context_p->source_p[1] >= LIT_CHAR_0 && context_p->source_p[1] <= LIT_CHAR_9)) + { + lexer_parse_number (context_p); + return; + } + + if (length >= 3 && context_p->source_p[1] == LIT_CHAR_DOT && context_p->source_p[2] == LIT_CHAR_DOT) + { + context_p->token.type = LEXER_THREE_DOTS; + length = 3; + break; + } + + context_p->token.type = LEXER_DOT; + length = 1; + break; + } + + case (uint8_t) LIT_CHAR_LESS_THAN: + { + if (length >= 2) + { + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_LESS_EQUAL; + length = 2; + break; + } + + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_LESS_THAN) + { + if (length >= 3 && context_p->source_p[2] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_ASSIGN_LEFT_SHIFT; + length = 3; + break; + } + + context_p->token.type = LEXER_LEFT_SHIFT; + length = 2; + break; + } + } + + context_p->token.type = LEXER_LESS; + length = 1; + break; + } + + case (uint8_t) LIT_CHAR_GREATER_THAN: + { + if (length >= 2) + { + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_GREATER_EQUAL; + length = 2; + break; + } + + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_GREATER_THAN) + { + if (length >= 3) + { + if (context_p->source_p[2] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_ASSIGN_RIGHT_SHIFT; + length = 3; + break; + } + + if (context_p->source_p[2] == (uint8_t) LIT_CHAR_GREATER_THAN) + { + if (length >= 4 && context_p->source_p[3] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_ASSIGN_UNS_RIGHT_SHIFT; + length = 4; + break; + } + + context_p->token.type = LEXER_UNS_RIGHT_SHIFT; + length = 3; + break; + } + } + + context_p->token.type = LEXER_RIGHT_SHIFT; + length = 2; + break; + } + } + + context_p->token.type = LEXER_GREATER; + length = 1; + break; + } + + case (uint8_t) LIT_CHAR_EQUALS: + { + if (length >= 2) + { + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_EQUALS) + { + if (length >= 3 && context_p->source_p[2] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_STRICT_EQUAL; + length = 3; + break; + } + + context_p->token.type = LEXER_EQUAL; + length = 2; + break; + } + + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_GREATER_THAN) + { + context_p->token.type = LEXER_ARROW; + length = 2; + break; + } + } + + context_p->token.type = LEXER_ASSIGN; + length = 1; + break; + } + + case (uint8_t) LIT_CHAR_EXCLAMATION: + { + if (length >= 2 && context_p->source_p[1] == (uint8_t) LIT_CHAR_EQUALS) + { + if (length >= 3 && context_p->source_p[2] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_STRICT_NOT_EQUAL; + length = 3; + break; + } + + context_p->token.type = LEXER_NOT_EQUAL; + length = 2; + break; + } + + context_p->token.type = LEXER_LOGICAL_NOT; + length = 1; + break; + } + + LEXER_TYPE_C_TOKEN (LIT_CHAR_PLUS, LEXER_ADD, LIT_CHAR_EQUALS, LEXER_ASSIGN_ADD, LIT_CHAR_PLUS, LEXER_INCREASE) + LEXER_TYPE_C_TOKEN (LIT_CHAR_MINUS, + LEXER_SUBTRACT, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_SUBTRACT, + LIT_CHAR_MINUS, + LEXER_DECREASE) + + case (uint8_t) LIT_CHAR_ASTERISK: + { + if (length >= 2) + { + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_ASSIGN_MULTIPLY; + length = 2; + break; + } + + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_ASTERISK) + { + if (length >= 3 && context_p->source_p[2] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_ASSIGN_EXPONENTIATION; + length = 3; + break; + } + + context_p->token.type = LEXER_EXPONENTIATION; + length = 2; + break; + } + } + + context_p->token.type = LEXER_MULTIPLY; + length = 1; + break; + } + + LEXER_TYPE_B_TOKEN (LIT_CHAR_SLASH, LEXER_DIVIDE, LIT_CHAR_EQUALS, LEXER_ASSIGN_DIVIDE) + LEXER_TYPE_B_TOKEN (LIT_CHAR_PERCENT, LEXER_MODULO, LIT_CHAR_EQUALS, LEXER_ASSIGN_MODULO) + + LEXER_TYPE_D_TOKEN (LIT_CHAR_AMPERSAND, + LEXER_BIT_AND, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_BIT_AND, + LIT_CHAR_AMPERSAND, + LEXER_LOGICAL_AND, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_LOGICAL_AND) + LEXER_TYPE_D_TOKEN (LIT_CHAR_VLINE, + LEXER_BIT_OR, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_BIT_OR, + LIT_CHAR_VLINE, + LEXER_LOGICAL_OR, + LIT_CHAR_EQUALS, + LEXER_ASSIGN_LOGICAL_OR) + + LEXER_TYPE_B_TOKEN (LIT_CHAR_CIRCUMFLEX, LEXER_BIT_XOR, LIT_CHAR_EQUALS, LEXER_ASSIGN_BIT_XOR) + + LEXER_TYPE_A_TOKEN (LIT_CHAR_TILDE, LEXER_BIT_NOT); + case (uint8_t) (LIT_CHAR_QUESTION): + { + if (length >= 2) + { + if (context_p->source_p[1] == (uint8_t) LIT_CHAR_QUESTION) + { + if (length >= 3 && context_p->source_p[2] == (uint8_t) LIT_CHAR_EQUALS) + { + context_p->token.type = LEXER_ASSIGN_NULLISH_COALESCING; + length = 3; + break; + } + context_p->token.type = LEXER_NULLISH_COALESCING; + length = 2; + break; + } + } + + context_p->token.type = LEXER_QUESTION_MARK; + length = 1; + break; + } + + LEXER_TYPE_A_TOKEN (LIT_CHAR_COLON, LEXER_COLON); + + case LIT_CHAR_SINGLE_QUOTE: + case LIT_CHAR_DOUBLE_QUOTE: + case LIT_CHAR_GRAVE_ACCENT: + { + lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); + return; + } + + default: + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CHARACTER); + } + } + + context_p->source_p += length; + PARSER_PLUS_EQUAL_LC (context_p->column, length); +} /* lexer_next_token */ + +#undef LEXER_TYPE_A_TOKEN +#undef LEXER_TYPE_B_TOKEN +#undef LEXER_TYPE_C_TOKEN +#undef LEXER_TYPE_D_TOKEN + +/** + * Checks whether the next token starts with the specified character. + * + * @return true - if the next is the specified character + * false - otherwise + */ +bool +lexer_check_next_character (parser_context_t *context_p, /**< context */ + lit_utf8_byte_t character) /**< specified character */ +{ + if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + } + + return (context_p->source_p < context_p->source_end_p && context_p->source_p[0] == (uint8_t) character); +} /* lexer_check_next_character */ + +/** + * Checks whether the next token starts with either specified characters. + * + * @return true - if the next is the specified character + * false - otherwise + */ +bool +lexer_check_next_characters (parser_context_t *context_p, /**< context */ + lit_utf8_byte_t character1, /**< first alternative character */ + lit_utf8_byte_t character2) /**< second alternative character */ +{ + if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + } + + return (context_p->source_p < context_p->source_end_p + && (context_p->source_p[0] == (uint8_t) character1 || context_p->source_p[0] == (uint8_t) character2)); +} /* lexer_check_next_characters */ + +/** + * Consumes the next character. The character cannot be a white space. + * + * @return consumed character + */ +uint8_t +lexer_consume_next_character (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->source_p < context_p->source_end_p); + + context_p->token.flags &= (uint8_t) ~LEXER_NO_SKIP_SPACES; + + PARSER_PLUS_EQUAL_LC (context_p->column, 1); + return *context_p->source_p++; +} /* lexer_consume_next_character */ + +/** + * Checks whether the next character can be the start of a post primary expression + * + * Note: + * the result is not precise, but this imprecise result + * has no side effects for negating number literals + * + * @return true if the next character can be the start of a post primary expression + */ +bool +lexer_check_post_primary_exp (parser_context_t *context_p) /**< context */ +{ + if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + } + + if (context_p->source_p >= context_p->source_end_p) + { + return false; + } + + switch (context_p->source_p[0]) + { + case LIT_CHAR_DOT: + case LIT_CHAR_LEFT_PAREN: + case LIT_CHAR_LEFT_SQUARE: + case LIT_CHAR_GRAVE_ACCENT: + { + return true; + } + case LIT_CHAR_PLUS: + case LIT_CHAR_MINUS: + { + return (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->source_p + 1 < context_p->source_end_p + && context_p->source_p[1] == context_p->source_p[0]); + } + case LIT_CHAR_ASTERISK: + { + return (context_p->source_p + 1 < context_p->source_end_p + && context_p->source_p[1] == (uint8_t) LIT_CHAR_ASTERISK); + } + } + + return false; +} /* lexer_check_post_primary_exp */ + +/** + * Checks whether the next token is a type used for detecting arrow functions. + * + * @return true if the next token is an arrow token + */ +bool +lexer_check_arrow (parser_context_t *context_p) /**< context */ +{ + if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + } + + return (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->source_p + 2 <= context_p->source_end_p + && context_p->source_p[0] == (uint8_t) LIT_CHAR_EQUALS + && context_p->source_p[1] == (uint8_t) LIT_CHAR_GREATER_THAN); +} /* lexer_check_arrow */ + +/** + * Checks whether the next token is a comma or equal sign. + * + * @return true if the next token is a comma or equal sign + */ +bool +lexer_check_arrow_param (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.flags & LEXER_NO_SKIP_SPACES); + + if (context_p->source_p >= context_p->source_end_p) + { + return false; + } + + if (context_p->source_p[0] == LIT_CHAR_COMMA) + { + return true; + } + + if (context_p->source_p[0] != LIT_CHAR_EQUALS) + { + return false; + } + + return (context_p->source_p + 1 >= context_p->source_end_p || context_p->source_p[1] != LIT_CHAR_EQUALS); +} /* lexer_check_arrow_param */ + +/** + * Checks whether the yield expression has no argument. + * + * @return true if it has no argument + */ +bool +lexer_check_yield_no_arg (parser_context_t *context_p) /**< context */ +{ + if (context_p->token.flags & LEXER_WAS_NEWLINE) + { + return true; + } + + switch (context_p->token.type) + { + case LEXER_RIGHT_BRACE: + case LEXER_RIGHT_PAREN: + case LEXER_RIGHT_SQUARE: + case LEXER_COMMA: + case LEXER_COLON: + case LEXER_SEMICOLON: + case LEXER_EOS: + { + return true; + } + default: + { + return false; + } + } +} /* lexer_check_yield_no_arg */ + +/** + * Checks whether the next token is a multiply and consumes it. + * + * @return true if the next token is a multiply + */ +bool +lexer_consume_generator (parser_context_t *context_p) /**< context */ +{ + if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + } + + if (context_p->source_p >= context_p->source_end_p || context_p->source_p[0] != LIT_CHAR_ASTERISK + || (context_p->source_p + 1 < context_p->source_end_p + && (context_p->source_p[1] == LIT_CHAR_EQUALS || context_p->source_p[1] == LIT_CHAR_ASTERISK))) + { + return false; + } + + lexer_consume_next_character (context_p); + context_p->token.type = LEXER_MULTIPLY; + return true; +} /* lexer_consume_generator */ + +/** + * Checks whether the next token is an equal sign and consumes it. + * + * @return true if the next token is an equal sign + */ +bool +lexer_consume_assign (parser_context_t *context_p) /**< context */ +{ + if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + } + + if (context_p->source_p >= context_p->source_end_p || context_p->source_p[0] != LIT_CHAR_EQUALS + || (context_p->source_p + 1 < context_p->source_end_p + && (context_p->source_p[1] == LIT_CHAR_EQUALS || context_p->source_p[1] == LIT_CHAR_GREATER_THAN))) + { + return false; + } + + lexer_consume_next_character (context_p); + context_p->token.type = LEXER_ASSIGN; + return true; +} /* lexer_consume_assign */ + +/** + * Update await / yield keywords after an arrow function with expression. + */ +void +lexer_update_await_yield (parser_context_t *context_p, /**< context */ + uint32_t status_flags) /**< parser status flags after restore */ +{ + if (!(status_flags & PARSER_IS_STRICT)) + { + if (status_flags & PARSER_IS_GENERATOR_FUNCTION) + { + if (context_p->token.type == LEXER_LITERAL && context_p->token.keyword_type == LEXER_KEYW_YIELD) + { + context_p->token.type = LEXER_KEYW_YIELD; + } + } + else + { + if (context_p->token.type == LEXER_KEYW_YIELD) + { + JERRY_ASSERT (context_p->token.keyword_type == LEXER_KEYW_YIELD); + context_p->token.type = LEXER_LITERAL; + } + } + } + + if (!(context_p->global_status_flags & ECMA_PARSE_MODULE)) + { + if (status_flags & PARSER_IS_ASYNC_FUNCTION) + { + if (context_p->token.type == LEXER_LITERAL && context_p->token.keyword_type == LEXER_KEYW_AWAIT) + { + context_p->token.type = LEXER_KEYW_AWAIT; + } + } + else + { + if (context_p->token.type == LEXER_KEYW_AWAIT) + { + JERRY_ASSERT (context_p->token.keyword_type == LEXER_KEYW_AWAIT); + context_p->token.type = LEXER_LITERAL; + } + } + } +} /* lexer_update_await_yield */ + +/** + * Read next token without skipping whitespaces and checking keywords + * + * @return true if the next literal is private identifier, false otherwise + */ +bool +lexer_scan_private_identifier (parser_context_t *context_p) /**< context */ +{ + context_p->token.keyword_type = LEXER_EOS; + context_p->token.line = context_p->line; + context_p->token.column = context_p->column; + + return (context_p->source_p < context_p->source_end_p && lexer_parse_identifier (context_p, LEXER_PARSE_NO_OPTS)); +} /* lexer_scan_private_identifier */ + +/** + * Convert an ident with escapes to a utf8 string. + */ +void +lexer_convert_ident_to_cesu8 (uint8_t *destination_p, /**< destination string */ + const uint8_t *source_p, /**< source string */ + prop_length_t length) /**< length of destination string */ +{ + const uint8_t *destination_end_p = destination_p + length; + + JERRY_ASSERT (length <= PARSER_MAXIMUM_IDENT_LENGTH); + + do + { + if (*source_p == LIT_CHAR_BACKSLASH) + { + source_p += 2; + destination_p += lit_code_point_to_cesu8_bytes (destination_p, lexer_unchecked_hex_to_character (&source_p)); + continue; + } + + if (*source_p >= LIT_UTF8_4_BYTE_MARKER) + { + lit_four_byte_utf8_char_to_cesu8 (destination_p, source_p); + + destination_p += 6; + source_p += 4; + continue; + } + + *destination_p++ = *source_p++; + } while (destination_p < destination_end_p); +} /* lexer_convert_ident_to_cesu8 */ + +/** + * Convert literal to character sequence + */ +const uint8_t * +lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */ + const lexer_lit_location_t *literal_p, /**< literal location */ + uint8_t *local_byte_array_p, /**< local byte array to store chars */ + lexer_string_options_t opts) /**< options */ +{ + JERRY_ASSERT (context_p->u.allocated_buffer_p == NULL); + + if (!(literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + return literal_p->char_p; + } + + uint8_t *destination_start_p; + if (literal_p->length > LEXER_MAX_LITERAL_LOCAL_BUFFER_SIZE) + { + context_p->u.allocated_buffer_p = (uint8_t *) parser_malloc_local (context_p, literal_p->length); + context_p->allocated_buffer_size = literal_p->length; + destination_start_p = (uint8_t*) context_p->u.allocated_buffer_p; + } + else + { + destination_start_p = local_byte_array_p; + } + + if (literal_p->type == LEXER_IDENT_LITERAL) + { + lexer_convert_ident_to_cesu8 (destination_start_p, literal_p->char_p, literal_p->length); + return destination_start_p; + } + + const uint8_t *source_p = literal_p->char_p; + uint8_t *destination_p = destination_start_p; + + uint8_t str_end_character = source_p[-1]; + + if (str_end_character == LIT_CHAR_RIGHT_BRACE) + { + str_end_character = LIT_CHAR_GRAVE_ACCENT; + } + + bool is_raw = (opts & LEXER_STRING_RAW) != 0; + + while (true) + { + if (*source_p == str_end_character) + { + break; + } + + if (*source_p == LIT_CHAR_BACKSLASH && !is_raw) + { + uint8_t conv_character; + + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + + /* Newline is ignored. */ + if (*source_p == LIT_CHAR_CR) + { + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + + if (*source_p == LIT_CHAR_LF) + { + source_p++; + } + continue; + } + else if (*source_p == LIT_CHAR_LF) + { + source_p++; + continue; + } + else if (*source_p == LEXER_NEWLINE_LS_PS_BYTE_1 && LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) + { + source_p += 3; + continue; + } + + if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_3) + { + lit_code_point_t octal_number = (uint32_t) (*source_p - LIT_CHAR_0); + + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + + if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_7) + { + octal_number = octal_number * 8 + (uint32_t) (*source_p - LIT_CHAR_0); + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + + if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_7) + { + octal_number = octal_number * 8 + (uint32_t) (*source_p - LIT_CHAR_0); + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + } + } + + destination_p += lit_code_point_to_cesu8_bytes (destination_p, octal_number); + continue; + } + + if (*source_p >= LIT_CHAR_4 && *source_p <= LIT_CHAR_7) + { + uint32_t octal_number = (uint32_t) (*source_p - LIT_CHAR_0); + + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + + if (*source_p >= LIT_CHAR_0 && *source_p <= LIT_CHAR_7) + { + octal_number = octal_number * 8 + (uint32_t) (*source_p - LIT_CHAR_0); + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + } + + *destination_p++ = (uint8_t) octal_number; + continue; + } + + if (*source_p == LIT_CHAR_LOWERCASE_X || *source_p == LIT_CHAR_LOWERCASE_U) + { + source_p++; + destination_p += lit_code_point_to_cesu8_bytes (destination_p, lexer_unchecked_hex_to_character (&source_p)); + continue; + } + + conv_character = *source_p; + switch (*source_p) + { + case LIT_CHAR_LOWERCASE_B: + { + conv_character = 0x08; + break; + } + case LIT_CHAR_LOWERCASE_T: + { + conv_character = 0x09; + break; + } + case LIT_CHAR_LOWERCASE_N: + { + conv_character = 0x0a; + break; + } + case LIT_CHAR_LOWERCASE_V: + { + conv_character = 0x0b; + break; + } + case LIT_CHAR_LOWERCASE_F: + { + conv_character = 0x0c; + break; + } + case LIT_CHAR_LOWERCASE_R: + { + conv_character = 0x0d; + break; + } + } + + if (conv_character != *source_p) + { + *destination_p++ = conv_character; + source_p++; + continue; + } + } + else if (str_end_character == LIT_CHAR_GRAVE_ACCENT) + { + if (source_p[0] == LIT_CHAR_DOLLAR_SIGN && source_p[1] == LIT_CHAR_LEFT_BRACE) + { + source_p++; + JERRY_ASSERT (source_p < context_p->source_end_p); + break; + } + if (*source_p == LIT_CHAR_CR) + { + *destination_p++ = LIT_CHAR_LF; + source_p++; + if (*source_p != str_end_character && *source_p == LIT_CHAR_LF) + { + source_p++; + } + continue; + } + if ((*source_p == LIT_CHAR_BACKSLASH) && is_raw) + { + JERRY_ASSERT (source_p + 1 < context_p->source_end_p); + if ((*(source_p + 1) == LIT_CHAR_GRAVE_ACCENT) || (*(source_p + 1) == LIT_CHAR_BACKSLASH)) + { + *destination_p++ = *source_p++; + *destination_p++ = *source_p++; + continue; + } + } + } + + if (*source_p >= LIT_UTF8_4_BYTE_MARKER) + { + /* Processing 4 byte unicode sequence (even if it is + * after a backslash). Always converted to two 3 byte + * long sequence. */ + lit_four_byte_utf8_char_to_cesu8 (destination_p, source_p); + + destination_p += 6; + source_p += 4; + continue; + } + + *destination_p++ = *source_p++; + + /* There is no need to check the source_end_p + * since the string is terminated by a quotation mark. */ + while (IS_UTF8_INTERMEDIATE_OCTET (*source_p)) + { + *destination_p++ = *source_p++; + } + } + + JERRY_ASSERT (destination_p == destination_start_p + literal_p->length); + + return destination_start_p; +} /* lexer_convert_literal_to_chars */ + +/** + * Construct an unused literal. + * + * @return a newly allocated literal + */ +lexer_literal_t * +lexer_construct_unused_literal (parser_context_t *context_p) /**< context */ +{ + lexer_literal_t *literal_p; + + if (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED); + } + + literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool); + literal_p->type = LEXER_UNUSED_LITERAL; + literal_p->status_flags = 0; + return literal_p; +} /* lexer_construct_unused_literal */ + +/** + * Construct a literal object from an identifier. + */ +void +lexer_construct_literal_object (parser_context_t *context_p, /**< context */ + const lexer_lit_location_t *lit_location_p, /**< literal location */ + uint8_t literal_type) /**< final literal type */ +{ + uint8_t local_byte_array[LEXER_MAX_LITERAL_LOCAL_BUFFER_SIZE]; + + const uint8_t *char_p = + lexer_convert_literal_to_chars (context_p, lit_location_p, local_byte_array, LEXER_STRING_NO_OPTS); + + size_t length = lit_location_p->length; + parser_list_iterator_t literal_iterator; + lexer_literal_t *literal_p; + uint32_t literal_index = 0; + bool search_scope_stack = (literal_type == LEXER_IDENT_LITERAL); + + if (JERRY_UNLIKELY (literal_type == LEXER_NEW_IDENT_LITERAL)) + { + literal_type = LEXER_IDENT_LITERAL; + } + + JERRY_ASSERT (literal_type == LEXER_IDENT_LITERAL || literal_type == LEXER_STRING_LITERAL); + + JERRY_ASSERT (literal_type != LEXER_IDENT_LITERAL || length <= PARSER_MAXIMUM_IDENT_LENGTH); + JERRY_ASSERT (literal_type != LEXER_STRING_LITERAL || length <= PARSER_MAXIMUM_STRING_LENGTH); + + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (literal_p->type == literal_type && literal_p->prop.length == length + && memcmp (literal_p->u.char_p, char_p, length) == 0) + { + context_p->lit_object.literal_p = literal_p; + context_p->lit_object.index = (uint16_t) literal_index; + + parser_free_allocated_buffer (context_p); + + if (search_scope_stack) + { + parser_scope_stack_t *scope_stack_start_p = context_p->scope_stack_p; + parser_scope_stack_t *scope_stack_p = scope_stack_start_p + context_p->scope_stack_top; + + while (scope_stack_p > scope_stack_start_p) + { + scope_stack_p--; + + if (scope_stack_p->map_from == literal_index) + { + JERRY_ASSERT (scanner_decode_map_to (scope_stack_p) >= PARSER_REGISTER_START + || (literal_p->status_flags & LEXER_FLAG_USED)); + context_p->lit_object.index = scanner_decode_map_to (scope_stack_p); + return; + } + } + + literal_p->status_flags |= LEXER_FLAG_USED; + } + return; + } + + literal_index++; + } + + JERRY_ASSERT (literal_index == context_p->literal_count); + + if (literal_index >= PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED); + } + + literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool); + literal_p->prop.length = (prop_length_t) length; + literal_p->type = literal_type; + + uint8_t status_flags = LEXER_FLAG_SOURCE_PTR; + + if (length > 0 && char_p == local_byte_array) + { + literal_p->u.char_p = (uint8_t *) jmem_heap_alloc_block (length); + memcpy ((uint8_t *) literal_p->u.char_p, char_p, length); + status_flags = 0; + } + else + { + literal_p->u.char_p = char_p; + + /* Buffer is taken over when a new literal is constructed. */ + if (context_p->u.allocated_buffer_p != NULL) + { + JERRY_ASSERT (char_p == context_p->u.allocated_buffer_p); + + context_p->u.allocated_buffer_p = NULL; + status_flags = 0; + } + } + + if (search_scope_stack) + { + status_flags |= LEXER_FLAG_USED; + } + + if (lit_location_p->status_flags & LEXER_LIT_LOCATION_IS_ASCII) + { + literal_p->status_flags |= LEXER_FLAG_ASCII; + } + + literal_p->status_flags = status_flags; + + context_p->lit_object.literal_p = literal_p; + context_p->lit_object.index = (uint16_t) literal_index; + context_p->literal_count++; + + JERRY_ASSERT (context_p->u.allocated_buffer_p == NULL); +} /* lexer_construct_literal_object */ + +/** + * Construct a number object. + * + * @return true if number is small number + */ +bool +lexer_construct_number_object (parser_context_t *context_p, /**< context */ + bool is_expr, /**< expression is parsed */ + bool is_negative_number) /**< sign is negative */ +{ + parser_list_iterator_t literal_iterator; + lexer_literal_t *literal_p; + ecma_value_t lit_value; + uint32_t literal_index = 0; + prop_length_t length = context_p->token.lit_location.length; + +#if JERRY_BUILTIN_BIGINT + if (JERRY_LIKELY (context_p->token.extra_value != LEXER_NUMBER_BIGINT)) + { +#endif /* JERRY_BUILTIN_BIGINT */ + ecma_number_t num; + uint32_t options = ECMA_CONVERSION_ALLOW_UNDERSCORE; + + if (context_p->token.extra_value == LEXER_NUMBER_OCTAL) + { + num = ecma_utf8_string_to_number_by_radix (context_p->token.lit_location.char_p, length, 8, options); + } + else + { + num = ecma_utf8_string_to_number (context_p->token.lit_location.char_p, length, options); + } + + if (is_expr) + { + int32_t int_num = (int32_t) num; + + if (int_num == num && int_num <= CBC_PUSH_NUMBER_BYTE_RANGE_END && (int_num != 0 || !is_negative_number)) + { + context_p->lit_object.index = (uint16_t) int_num; + return true; + } + } + + if (is_negative_number) + { + num = -num; + } + + lit_value = ecma_find_or_create_literal_number (num); +#if JERRY_BUILTIN_BIGINT + } + else + { + uint32_t options = (ECMA_BIGINT_PARSE_DISALLOW_SYNTAX_ERROR | ECMA_BIGINT_PARSE_DISALLOW_MEMORY_ERROR + | ECMA_BIGINT_PARSE_ALLOW_UNDERSCORE); + + if (is_negative_number) + { + options |= ECMA_BIGINT_PARSE_SET_NEGATIVE; + } + + JERRY_ASSERT (length >= 2); + lit_value = + ecma_bigint_parse_string (context_p->token.lit_location.char_p, (lit_utf8_size_t) (length - 1), options); + + JERRY_ASSERT (lit_value != ECMA_VALUE_FALSE && !ECMA_IS_VALUE_ERROR (lit_value)); + + if (lit_value == ECMA_VALUE_NULL) + { + parser_raise_error (context_p, PARSER_ERR_OUT_OF_MEMORY); + } + + lit_value = ecma_find_or_create_literal_bigint (lit_value); + } +#endif /* JERRY_BUILTIN_BIGINT */ + + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (literal_p->type == LEXER_NUMBER_LITERAL && literal_p->u.value == lit_value) + { + context_p->lit_object.literal_p = literal_p; + context_p->lit_object.index = (uint16_t) literal_index; + return false; + } + + literal_index++; + } + + JERRY_ASSERT (literal_index == context_p->literal_count); + + if (literal_index >= PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED); + } + + literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool); + literal_p->u.value = lit_value; + literal_p->prop.length = 0; /* Unused. */ + literal_p->type = LEXER_NUMBER_LITERAL; + literal_p->status_flags = 0; + + context_p->lit_object.literal_p = literal_p; + context_p->lit_object.index = (uint16_t) literal_index; + + context_p->literal_count++; + return false; +} /* lexer_construct_number_object */ + +/** + * Convert a push number opcode to push literal opcode + */ +void +lexer_convert_push_number_to_push_literal (parser_context_t *context_p) /**< context */ +{ + ecma_integer_value_t value; + bool two_literals = context_p->last_cbc_opcode >= CBC_PUSH_LITERAL_PUSH_NUMBER_0; + + if (context_p->last_cbc_opcode == CBC_PUSH_NUMBER_0 || context_p->last_cbc_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_0) + { + value = 0; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_NUMBER_POS_BYTE + || context_p->last_cbc_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) + { + value = ((ecma_integer_value_t) context_p->last_cbc.value) + 1; + } + else + { + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_NUMBER_NEG_BYTE + || context_p->last_cbc_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE); + value = -((ecma_integer_value_t) context_p->last_cbc.value) - 1; + } + + ecma_value_t lit_value = ecma_make_integer_value (value); + + parser_list_iterator_t literal_iterator; + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + + context_p->last_cbc_opcode = two_literals ? CBC_PUSH_TWO_LITERALS : CBC_PUSH_LITERAL; + + uint32_t literal_index = 0; + lexer_literal_t *literal_p; + + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (literal_p->type == LEXER_NUMBER_LITERAL && literal_p->u.value == lit_value) + { + if (two_literals) + { + context_p->last_cbc.value = (uint16_t) literal_index; + } + else + { + context_p->last_cbc.literal_index = (uint16_t) literal_index; + } + return; + } + + literal_index++; + } + + JERRY_ASSERT (literal_index == context_p->literal_count); + + if (literal_index >= PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED); + } + + literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool); + literal_p->u.value = lit_value; + literal_p->prop.length = 0; /* Unused. */ + literal_p->type = LEXER_NUMBER_LITERAL; + literal_p->status_flags = 0; + + context_p->literal_count++; + + if (two_literals) + { + context_p->last_cbc.value = (uint16_t) literal_index; + } + else + { + context_p->last_cbc.literal_index = (uint16_t) literal_index; + } +} /* lexer_convert_push_number_to_push_literal */ + +/** + * Construct a function literal object. + * + * @return function object literal index + */ +uint16_t +lexer_construct_function_object (parser_context_t *context_p, /**< context */ + uint32_t extra_status_flags) /**< extra status flags */ +{ +#if (JERRY_STACK_LIMIT != 0) + if (JERRY_UNLIKELY (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT)) + { + parser_raise_error (context_p, PARSER_ERR_STACK_OVERFLOW); + } +#endif /* JERRY_STACK_LIMIT != 0 */ + ecma_compiled_code_t *compiled_code_p; + lexer_literal_t *literal_p; + uint16_t result_index; + + if (context_p->status_flags & PARSER_INSIDE_WITH) + { + extra_status_flags |= PARSER_INSIDE_WITH; + } + + literal_p = lexer_construct_unused_literal (context_p); + result_index = context_p->literal_count; + context_p->literal_count++; + + parser_flush_cbc (context_p); + + if (JERRY_LIKELY (!(extra_status_flags & PARSER_IS_ARROW_FUNCTION))) + { + compiled_code_p = parser_parse_function (context_p, extra_status_flags); + } + else + { + compiled_code_p = parser_parse_arrow_function (context_p, extra_status_flags); + } + + literal_p->u.bytecode_p = compiled_code_p; + literal_p->type = LEXER_FUNCTION_LITERAL; + + return result_index; +} /* lexer_construct_function_object */ + +/** + * Construct a class static block function literal object. + * + * @return function object literal index + */ +uint16_t +lexer_construct_class_static_block_function (parser_context_t *context_p) /**< context */ +{ + ecma_compiled_code_t *compiled_code_p; + lexer_literal_t *literal_p; + uint16_t result_index; + + literal_p = lexer_construct_unused_literal (context_p); + result_index = context_p->literal_count; + context_p->literal_count++; + + parser_flush_cbc (context_p); + compiled_code_p = parser_parse_class_static_block (context_p); + + literal_p->u.bytecode_p = compiled_code_p; + literal_p->type = LEXER_FUNCTION_LITERAL; + + return result_index; +} /* lexer_construct_class_static_block_function */ + +/** + * Construct a regular expression object. + * + * Note: In ESNEXT the constructed literal's type can be LEXER_STRING_LITERAL which represents + * invalid pattern. In this case the lit_object's index contains the thrown error message literal. + * Otherwise a new literal is appended to the end of the literal pool. + */ +void +lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ + bool parse_only) /**< parse only */ +{ +#if JERRY_BUILTIN_REGEXP + const uint8_t *source_p = context_p->source_p; + const uint8_t *regex_start_p = context_p->source_p; + const uint8_t *regex_end_p = regex_start_p; + const uint8_t *source_end_p = context_p->source_end_p; + parser_line_counter_t column = context_p->column; + bool in_class = false; + uint16_t current_flags; + lit_utf8_size_t length; + + JERRY_ASSERT (context_p->token.type == LEXER_DIVIDE || context_p->token.type == LEXER_ASSIGN_DIVIDE); + + if (context_p->token.type == LEXER_ASSIGN_DIVIDE) + { + regex_start_p--; + } + + while (true) + { + if (source_p >= source_end_p) + { + parser_raise_error (context_p, PARSER_ERR_UNTERMINATED_REGEXP); + } + + if (!in_class && source_p[0] == LIT_CHAR_SLASH) + { + regex_end_p = source_p; + source_p++; + column++; + break; + } + + switch (source_p[0]) + { + case LIT_CHAR_CR: + case LIT_CHAR_LF: + case LEXER_NEWLINE_LS_PS_BYTE_1: + { + if (source_p[0] != LEXER_NEWLINE_LS_PS_BYTE_1 || LEXER_NEWLINE_LS_PS_BYTE_23 (source_p)) + { + parser_raise_error (context_p, PARSER_ERR_NEWLINE_NOT_ALLOWED); + } + break; + } + case LIT_CHAR_TAB: + { + column = align_column_to_tab (column); + /* Subtract -1 because column is increased below. */ + column--; + break; + } + case LIT_CHAR_LEFT_SQUARE: + { + in_class = true; + break; + } + case LIT_CHAR_RIGHT_SQUARE: + { + in_class = false; + break; + } + case LIT_CHAR_BACKSLASH: + { + if (source_p + 1 >= source_end_p) + { + parser_raise_error (context_p, PARSER_ERR_UNTERMINATED_REGEXP); + } + + if (source_p[1] >= 0x20 && source_p[1] <= LIT_UTF8_1_BYTE_CODE_POINT_MAX) + { + source_p++; + column++; + } + } + } + + source_p++; + column++; + + while (source_p < source_end_p && IS_UTF8_INTERMEDIATE_OCTET (source_p[0])) + { + source_p++; + } + } + + current_flags = 0; + while (source_p < source_end_p) + { + uint32_t flag = 0; + + if (source_p[0] == LIT_CHAR_LOWERCASE_G) + { + flag = RE_FLAG_GLOBAL; + } + else if (source_p[0] == LIT_CHAR_LOWERCASE_I) + { + flag = RE_FLAG_IGNORE_CASE; + } + else if (source_p[0] == LIT_CHAR_LOWERCASE_M) + { + flag = RE_FLAG_MULTILINE; + } + else if (source_p[0] == LIT_CHAR_LOWERCASE_U) + { + flag = RE_FLAG_UNICODE; + } + else if (source_p[0] == LIT_CHAR_LOWERCASE_Y) + { + flag = RE_FLAG_STICKY; + } + else if (source_p[0] == LIT_CHAR_LOWERCASE_S) + { + flag = RE_FLAG_DOTALL; + } + + if (flag == 0) + { + break; + } + + if (current_flags & flag) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_REGEXP_FLAG); + } + + current_flags = (uint16_t) (current_flags | flag); + source_p++; + column++; + } + + context_p->source_p = source_p; + context_p->column = column; + + if (source_p < source_end_p && lexer_parse_identifier (context_p, LEXER_PARSE_CHECK_PART_AND_RETURN)) + { + parser_raise_error (context_p, PARSER_ERR_UNKNOWN_REGEXP_FLAG); + } + + length = (lit_utf8_size_t) (regex_end_p - regex_start_p); + if (length > PARSER_MAXIMUM_STRING_LENGTH) + { + parser_raise_error (context_p, PARSER_ERR_REGEXP_TOO_LONG); + } + + context_p->column = column; + context_p->source_p = source_p; + + if (parse_only) + { + return; + } + + if (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED); + } + + /* Compile the RegExp literal and store the RegExp bytecode pointer */ + ecma_string_t *pattern_str_p = NULL; + + if (lit_is_valid_cesu8_string (regex_start_p, length)) + { + pattern_str_p = ecma_new_ecma_string_from_utf8 (regex_start_p, length); + } + else + { + JERRY_ASSERT (lit_is_valid_utf8_string (regex_start_p, length, false)); + pattern_str_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (regex_start_p, length); + } + + re_compiled_code_t *re_bytecode_p = re_compile_bytecode (pattern_str_p, current_flags); + ecma_deref_ecma_string (pattern_str_p); + + if (JERRY_UNLIKELY (re_bytecode_p == NULL)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_REGEXP); + } + + lexer_literal_t *literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool); + literal_p->u.bytecode_p = (ecma_compiled_code_t *) re_bytecode_p; + literal_p->type = LEXER_REGEXP_LITERAL; + literal_p->prop.length = (prop_length_t) length; + literal_p->status_flags = 0; + + context_p->token.type = LEXER_LITERAL; + context_p->token.lit_location.type = LEXER_REGEXP_LITERAL; + + context_p->lit_object.literal_p = literal_p; + context_p->lit_object.index = context_p->literal_count++; +#else /* !JERRY_BUILTIN_REGEXP */ + JERRY_UNUSED (parse_only); + parser_raise_error (context_p, PARSER_ERR_UNSUPPORTED_REGEXP); +#endif /* JERRY_BUILTIN_REGEXP */ +} /* lexer_construct_regexp_object */ + +/** + * Next token must be an identifier. + */ +void +lexer_expect_identifier (parser_context_t *context_p, /**< context */ + uint8_t literal_type) /**< literal type */ +{ + JERRY_ASSERT (literal_type == LEXER_STRING_LITERAL || literal_type == LEXER_IDENT_LITERAL + || literal_type == LEXER_NEW_IDENT_LITERAL); + + lexer_skip_spaces (context_p); + context_p->token.keyword_type = LEXER_EOS; + context_p->token.line = context_p->line; + context_p->token.column = context_p->column; + + if (context_p->source_p < context_p->source_end_p + && lexer_parse_identifier ( + context_p, + (literal_type != LEXER_STRING_LITERAL ? LEXER_PARSE_CHECK_KEYWORDS : LEXER_PARSE_NO_OPTS))) + { + if (context_p->token.type == LEXER_LITERAL) + { + JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, literal_type); + + if (literal_type != LEXER_STRING_LITERAL && (context_p->status_flags & PARSER_IS_STRICT)) + { + if (context_p->token.keyword_type == LEXER_KEYW_EVAL) + { + parser_raise_error (context_p, PARSER_ERR_EVAL_NOT_ALLOWED); + } + else if (context_p->token.keyword_type == LEXER_KEYW_ARGUMENTS) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENTS_NOT_ALLOWED); + } + } + return; + } + } +#if JERRY_MODULE_SYSTEM + else if (context_p->status_flags & PARSER_MODULE_DEFAULT_CLASS_OR_FUNC) + { + /* When parsing default exports for modules, it is not required by functions or classes to have identifiers. + * In this case we use a synthetic name for them. */ + context_p->token.type = LEXER_LITERAL; + context_p->token.lit_location = lexer_default_literal; + lexer_construct_literal_object (context_p, &context_p->token.lit_location, literal_type); + context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC); + return; + } +#endif /* JERRY_MODULE_SYSTEM */ + if (context_p->token.type == LEXER_KEYW_YIELD) + { + parser_raise_error (context_p, PARSER_ERR_YIELD_NOT_ALLOWED); + } + if (context_p->token.type == LEXER_KEYW_AWAIT) + { + parser_raise_error (context_p, PARSER_ERR_AWAIT_NOT_ALLOWED); + } + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); +} /* lexer_expect_identifier */ + +/** + * Next token must be an identifier. + */ +void +lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */ + uint32_t ident_opts) /**< lexer_obj_ident_opts_t option bits */ +{ + lexer_skip_spaces (context_p); + + if (context_p->source_p >= context_p->source_end_p) + { + parser_raise_error (context_p, PARSER_ERR_PROPERTY_IDENTIFIER_EXPECTED); + } + + context_p->token.keyword_type = LEXER_EOS; + context_p->token.line = context_p->line; + context_p->token.column = context_p->column; + bool create_literal_object = false; + + JERRY_ASSERT ((ident_opts & LEXER_OBJ_IDENT_CLASS_IDENTIFIER) || !(ident_opts & LEXER_OBJ_IDENT_CLASS_NO_STATIC)); + + if (lexer_parse_identifier (context_p, LEXER_PARSE_NO_OPTS)) + { + if (!(ident_opts & (LEXER_OBJ_IDENT_ONLY_IDENTIFIERS | LEXER_OBJ_IDENT_OBJECT_PATTERN))) + { + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + + if (context_p->source_p < context_p->source_end_p && context_p->source_p[0] != LIT_CHAR_COMMA + && context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE && context_p->source_p[0] != LIT_CHAR_LEFT_PAREN + && context_p->source_p[0] != LIT_CHAR_SEMICOLON && context_p->source_p[0] != LIT_CHAR_EQUALS + && context_p->source_p[0] != LIT_CHAR_COLON) + { + if (lexer_compare_literal_to_string (context_p, "get", 3)) + { + context_p->token.type = LEXER_PROPERTY_GETTER; + return; + } + + if (lexer_compare_literal_to_string (context_p, "set", 3)) + { + context_p->token.type = LEXER_PROPERTY_SETTER; + return; + } + + if (lexer_compare_literal_to_string (context_p, "async", 5)) + { + context_p->token.type = LEXER_KEYW_ASYNC; + return; + } + + if (ident_opts & LEXER_OBJ_IDENT_CLASS_NO_STATIC) + { + if (lexer_compare_literal_to_string (context_p, "static", 6)) + { + context_p->token.type = LEXER_KEYW_STATIC; + } + return; + } + } + } + + create_literal_object = true; + } + else if (ident_opts & LEXER_OBJ_IDENT_CLASS_PRIVATE) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CHARACTER); + } + else + { + switch (context_p->source_p[0]) + { + case LIT_CHAR_DOUBLE_QUOTE: + case LIT_CHAR_SINGLE_QUOTE: + { + lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); + create_literal_object = true; + break; + } + case LIT_CHAR_LEFT_SQUARE: + { + lexer_consume_next_character (context_p); + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (context_p->token.type != LEXER_RIGHT_SQUARE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_SQUARE_EXPECTED); + } + return; + } + case LIT_CHAR_ASTERISK: + { + if (ident_opts & (LEXER_OBJ_IDENT_ONLY_IDENTIFIERS | LEXER_OBJ_IDENT_OBJECT_PATTERN)) + { + break; + } + + context_p->token.type = LEXER_MULTIPLY; + lexer_consume_next_character (context_p); + return; + } + case LIT_CHAR_HASHMARK: + { + if (ident_opts & LEXER_OBJ_IDENT_CLASS_IDENTIFIER) + { + context_p->token.type = LEXER_HASHMARK; + return; + } + + break; + } + case LIT_CHAR_LEFT_BRACE: + { + const uint32_t static_block_flags = + (LEXER_OBJ_IDENT_CLASS_NO_STATIC | LEXER_OBJ_IDENT_CLASS_PRIVATE | LEXER_OBJ_IDENT_CLASS_IDENTIFIER); + + if ((ident_opts & static_block_flags) == LEXER_OBJ_IDENT_CLASS_IDENTIFIER) + { + context_p->token.type = LEXER_LEFT_BRACE; + lexer_consume_next_character (context_p); + return; + } + + break; + } + case LIT_CHAR_RIGHT_BRACE: + { + if (ident_opts & LEXER_OBJ_IDENT_ONLY_IDENTIFIERS) + { + break; + } + + context_p->token.type = LEXER_RIGHT_BRACE; + lexer_consume_next_character (context_p); + return; + } + case LIT_CHAR_DOT: + { + if (!(context_p->source_p + 1 >= context_p->source_end_p || lit_char_is_decimal_digit (context_p->source_p[1]))) + { + if ((ident_opts & ((uint32_t) ~(LEXER_OBJ_IDENT_OBJECT_PATTERN | LEXER_OBJ_IDENT_SET_FUNCTION_START))) + || context_p->source_p + 2 >= context_p->source_end_p || context_p->source_p[1] != LIT_CHAR_DOT + || context_p->source_p[2] != LIT_CHAR_DOT) + { + break; + } + + context_p->token.type = LEXER_THREE_DOTS; + context_p->token.flags &= (uint8_t) ~LEXER_NO_SKIP_SPACES; + PARSER_PLUS_EQUAL_LC (context_p->column, 3); + context_p->source_p += 3; + return; + } + /* FALLTHRU */ + } + default: + { + const uint8_t *char_p = context_p->source_p; + + if (char_p[0] == LIT_CHAR_DOT) + { + char_p++; + } + + if (char_p < context_p->source_end_p && char_p[0] >= LIT_CHAR_0 && char_p[0] <= LIT_CHAR_9) + { + lexer_parse_number (context_p); + + if (!(ident_opts & LEXER_OBJ_IDENT_CLASS_IDENTIFIER)) + { + lexer_construct_number_object (context_p, false, false); + } + return; + } + break; + } + } + } + + if (create_literal_object) + { + if (ident_opts & LEXER_OBJ_IDENT_CLASS_IDENTIFIER) + { + return; + } + + if (ident_opts & LEXER_OBJ_IDENT_CLASS_PRIVATE) + { + parser_resolve_private_identifier (context_p); + return; + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + return; + } + + parser_raise_error (context_p, PARSER_ERR_PROPERTY_IDENTIFIER_EXPECTED); +} /* lexer_expect_object_literal_id */ + +/** + * Read next token without checking keywords + * + * @return true if the next literal is identifier, false otherwise + */ +bool +lexer_scan_identifier (parser_context_t *context_p, /**< context */ + lexer_parse_options_t opts) /**< identifier parse options */ +{ + lexer_skip_spaces (context_p); + context_p->token.keyword_type = LEXER_EOS; + context_p->token.line = context_p->line; + context_p->token.column = context_p->column; + + if (context_p->source_p < context_p->source_end_p && lexer_parse_identifier (context_p, opts)) + { + return true; + } + + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + lexer_next_token (context_p); + return false; +} /* lexer_scan_identifier */ + +/** + * Check whether the identifier is a modifier in a property definition. + */ +void +lexer_check_property_modifier (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (!(context_p->token.flags & LEXER_NO_SKIP_SPACES)); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + lexer_skip_spaces (context_p); + context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES); + + if (context_p->source_p >= context_p->source_end_p || context_p->source_p[0] == LIT_CHAR_COMMA + || context_p->source_p[0] == LIT_CHAR_RIGHT_BRACE || context_p->source_p[0] == LIT_CHAR_LEFT_PAREN + || context_p->source_p[0] == LIT_CHAR_EQUALS || context_p->source_p[0] == LIT_CHAR_COLON) + { + return; + } + + if (lexer_compare_literal_to_string (context_p, "get", 3)) + { + context_p->token.type = LEXER_PROPERTY_GETTER; + return; + } + + if (lexer_compare_literal_to_string (context_p, "set", 3)) + { + context_p->token.type = LEXER_PROPERTY_SETTER; + return; + } + + if (lexer_compare_literal_to_string (context_p, "async", 5)) + { + context_p->token.type = LEXER_KEYW_ASYNC; + return; + } +} /* lexer_check_property_modifier */ + +/** + * Compares two identifiers. + * + * Note: + * Escape sequences are allowed in the left identifier, but not in the right + * + * @return true if the two identifiers are the same + */ +static bool +lexer_compare_identifier_to_chars (const uint8_t *left_p, /**< left identifier */ + const uint8_t *right_p, /**< right identifier string */ + size_t size) /**< byte size of the two identifiers */ +{ + uint8_t utf8_buf[6]; + + do + { + if (*left_p == *right_p) + { + left_p++; + right_p++; + size--; + continue; + } + + size_t escape_size; + + if (*left_p == LIT_CHAR_BACKSLASH) + { + left_p += 2; + lit_code_point_t code_point = lexer_unchecked_hex_to_character (&left_p); + + escape_size = lit_code_point_to_cesu8_bytes (utf8_buf, code_point); + } + else if (*left_p >= LIT_UTF8_4_BYTE_MARKER) + { + lit_four_byte_utf8_char_to_cesu8 (utf8_buf, left_p); + escape_size = 3 * 2; + left_p += 4; + } + else + { + return false; + } + + size -= escape_size; + + uint8_t *utf8_p = utf8_buf; + do + { + if (*right_p++ != *utf8_p++) + { + return false; + } + } while (--escape_size > 0); + } while (size > 0); + + return true; +} /* lexer_compare_identifier_to_chars */ + +/** + * Compares an identifier to a string. + * + * Note: + * Escape sequences are allowed in the left identifier, but not in the right + * + * @return true if the identifier equals to string + */ +bool +lexer_compare_identifier_to_string (const lexer_lit_location_t *left_p, /**< left literal */ + const uint8_t *right_p, /**< right identifier string */ + size_t size) /**< byte size of the right identifier */ +{ + if (left_p->length != size) + { + return false; + } + + if (!(left_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + return memcmp (left_p->char_p, right_p, size) == 0; + } + + return lexer_compare_identifier_to_chars (left_p->char_p, right_p, size); +} /* lexer_compare_identifier_to_string */ + +/** + * Compares two identifiers. + * + * Note: + * Escape sequences are allowed in both identifiers + * + * @return true if the two identifiers are the same + */ +bool +lexer_compare_identifiers (parser_context_t *context_p, /**< context */ + const lexer_lit_location_t *left_p, /**< left literal */ + const lexer_lit_location_t *right_p) /**< right literal */ +{ + prop_length_t length = left_p->length; + + if (length != right_p->length) + { + return false; + } + + if (!(left_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + return lexer_compare_identifier_to_chars (right_p->char_p, left_p->char_p, length); + } + + if (!(right_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + return lexer_compare_identifier_to_chars (left_p->char_p, right_p->char_p, length); + } + + if (length <= 64) + { + uint8_t buf_p[64]; + lexer_convert_ident_to_cesu8 (buf_p, left_p->char_p, length); + return lexer_compare_identifier_to_chars (right_p->char_p, buf_p, length); + } + + uint8_t *dynamic_buf_p = (uint8_t*) parser_malloc (context_p, length); + + lexer_convert_ident_to_cesu8 (dynamic_buf_p, left_p->char_p, length); + bool result = lexer_compare_identifier_to_chars (right_p->char_p, dynamic_buf_p, length); + parser_free (dynamic_buf_p, length); + + return result; +} /* lexer_compare_identifiers */ + +/** + * Compares the current identifier in the context to the parameter identifier + * + * Note: + * Escape sequences are allowed. + * + * @return true if the input identifiers are the same + */ +bool +lexer_current_is_literal (parser_context_t *context_p, /**< context */ + const lexer_lit_location_t *right_ident_p) /**< identifier */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + lexer_lit_location_t *left_ident_p = &context_p->token.lit_location; + + JERRY_ASSERT (left_ident_p->length > 0 && right_ident_p->length > 0); + + if (left_ident_p->length != right_ident_p->length) + { + return false; + } + + if (!((left_ident_p->status_flags | right_ident_p->status_flags) & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + return memcmp (left_ident_p->char_p, right_ident_p->char_p, left_ident_p->length) == 0; + } + + return lexer_compare_identifiers (context_p, left_ident_p, right_ident_p); +} /* lexer_current_is_literal */ + +/** + * Compares the current string token to "use strict". + * + * Note: + * Escape sequences are not allowed. + * + * @return true if "use strict" is found, false otherwise + */ +bool +lexer_string_is_use_strict (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL); + + return (context_p->token.lit_location.length == 10 + && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE) + && memcmp (context_p->token.lit_location.char_p, "use strict", 10) == 0); +} /* lexer_string_is_use_strict */ + +/** + * Checks whether the string before the current token is a directive or a string literal. + * + * @return true if the string is a directive, false otherwise + */ +bool +lexer_string_is_directive (parser_context_t *context_p) /**< context */ +{ + return (context_p->token.type == LEXER_SEMICOLON || context_p->token.type == LEXER_RIGHT_BRACE + || context_p->token.type == LEXER_EOS + || ((context_p->token.flags & LEXER_WAS_NEWLINE) && !LEXER_IS_BINARY_OP_TOKEN (context_p->token.type) + && context_p->token.type != LEXER_LEFT_PAREN && context_p->token.type != LEXER_LEFT_SQUARE + && context_p->token.type != LEXER_DOT)); +} /* lexer_string_is_directive */ + +/** + * Compares the current token to an expected identifier. + * + * Note: + * Escape sequences are not allowed. + * + * @return true if they are the same, false otherwise + */ +bool +lexer_token_is_identifier (parser_context_t *context_p, /**< context */ + const char *identifier_p, /**< identifier */ + size_t identifier_length) /**< identifier length */ +{ + /* Checking has_escape is unnecessary because memcmp will fail if escape sequences are present. */ + return (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL + && context_p->token.lit_location.length == identifier_length + && memcmp (context_p->token.lit_location.char_p, identifier_p, identifier_length) == 0); +} /* lexer_token_is_identifier */ + +/** + * Compares the current identifier token to "let". + * + * Note: + * Escape sequences are not allowed. + * + * @return true if "let" is found, false otherwise + */ +bool +lexer_token_is_let (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL); + + return (context_p->token.keyword_type == LEXER_KEYW_LET + && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)); +} /* lexer_token_is_let */ + +/** + * Compares the current identifier token to "async". + * + * Note: + * Escape sequences are not allowed. + * + * @return true if "async" is found, false otherwise + */ +bool +lexer_token_is_async (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL || context_p->token.type == LEXER_TEMPLATE_LITERAL); + + return (context_p->token.keyword_type == LEXER_KEYW_ASYNC + && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)); +} /* lexer_token_is_async */ + +/** + * Compares the current identifier or string to an expected string. + * + * Note: + * Escape sequences are not allowed. + * + * @return true if they are the same, false otherwise + */ +bool +lexer_compare_literal_to_string (parser_context_t *context_p, /**< context */ + const char *string_p, /**< string */ + size_t string_length) /**< string length */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL + && (context_p->token.lit_location.type == LEXER_IDENT_LITERAL + || context_p->token.lit_location.type == LEXER_STRING_LITERAL)); + + /* Checking has_escape is unnecessary because memcmp will fail if escape sequences are present. */ + return (context_p->token.lit_location.length == string_length + && memcmp (context_p->token.lit_location.char_p, string_p, string_length) == 0); +} /* lexer_compare_literal_to_string */ + +/** + * Initialize line info to its default value + */ +void +lexer_init_line_info (parser_context_t *context_p) /**< context */ +{ + context_p->line = 1; + context_p->column = 1; + + const jerry_parse_options_t *options_p = context_p->options_p; + + if (options_p != NULL && (options_p->options & JERRY_PARSE_HAS_START)) + { + if (options_p->start_line > 0) + { + context_p->line = options_p->start_line; + } + + if (options_p->start_column > 0) + { + context_p->column = options_p->start_column; + } + } +} /* lexer_init_line_info */ + +/** + * Convert binary lvalue token to binary token + * e.g. += -> + + * ^= -> ^ + * + * @return binary token + */ +uint8_t +lexer_convert_binary_lvalue_token_to_binary (uint8_t token) /**< binary lvalue token */ +{ + JERRY_ASSERT (LEXER_IS_BINARY_LVALUE_OP_TOKEN (token)); + JERRY_ASSERT (token != LEXER_ASSIGN); + + if (token <= LEXER_ASSIGN_EXPONENTIATION) + { + return (uint8_t) (LEXER_ADD + (token - LEXER_ASSIGN_ADD)); + } + + if (token <= LEXER_ASSIGN_UNS_RIGHT_SHIFT) + { + return (uint8_t) (LEXER_LEFT_SHIFT + (token - LEXER_ASSIGN_LEFT_SHIFT)); + } + + switch (token) + { + case LEXER_ASSIGN_BIT_AND: + { + return LEXER_BIT_AND; + } + case LEXER_ASSIGN_BIT_OR: + { + return LEXER_BIT_OR; + } + default: + { + JERRY_ASSERT (token == LEXER_ASSIGN_BIT_XOR); + return LEXER_BIT_XOR; + } + } +} /* lexer_convert_binary_lvalue_token_to_binary */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-lexer.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-lexer.h new file mode 100644 index 0000000..d39fd8b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-lexer.h @@ -0,0 +1,353 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JS_LEXER_H +#define JS_LEXER_H + +#include "ecma-globals.h" + +#include "common.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_lexer Lexer + * @{ + */ + +/** + * Flags for lexer_parse_identifier. + */ +typedef enum +{ + LEXER_PARSE_NO_OPTS = 0, /**< no options */ + LEXER_PARSE_CHECK_KEYWORDS = (1 << 0), /**< check keywords */ + LEXER_PARSE_NO_STRICT_IDENT_ERROR = (1 << 1), /**< do not throw exception for strict mode keywords */ + LEXER_PARSE_CHECK_START_AND_RETURN = (1 << 2), /**< check identifier start and return */ + LEXER_PARSE_CHECK_PART_AND_RETURN = (1 << 3), /**< check identifier part and return */ +} lexer_parse_options_t; + +/** + * Lexer token types. + */ +typedef enum +{ + LEXER_EOS, /**< end of source */ + + /* Primary expressions */ + LEXER_LITERAL, /**< literal token */ + LEXER_KEYW_THIS, /**< this */ + LEXER_LIT_TRUE, /**< true (not a keyword!) */ + LEXER_LIT_FALSE, /**< false (not a keyword!) */ + LEXER_LIT_NULL, /**< null (not a keyword!) */ + LEXER_TEMPLATE_LITERAL, /**< multi segment template literal */ + LEXER_THREE_DOTS, /**< ... (rest or spread operator) */ + +/* Unary operators + * IMPORTANT: update CBC_UNARY_OP_TOKEN_TO_OPCODE and + * CBC_UNARY_LVALUE_OP_TOKEN_TO_OPCODE after changes. */ +#define LEXER_IS_UNARY_OP_TOKEN(token_type) ((token_type) >= LEXER_PLUS && (token_type) <= LEXER_DECREASE) +#define LEXER_IS_UNARY_LVALUE_OP_TOKEN(token_type) ((token_type) >= LEXER_KEYW_DELETE && (token_type) <= LEXER_DECREASE) + + LEXER_PLUS, /**< "+" */ + LEXER_NEGATE, /**< "-" */ + LEXER_LOGICAL_NOT, /**< "!" */ + LEXER_BIT_NOT, /**< "~" */ + LEXER_KEYW_VOID, /**< void */ + LEXER_KEYW_TYPEOF, /**< typeof */ + LEXER_KEYW_AWAIT, /**< await */ + LEXER_KEYW_DELETE, /**< delete */ + LEXER_INCREASE, /**< "++" */ + LEXER_DECREASE, /**< "--" */ + +/* Binary operators + * IMPORTANT: update CBC_BINARY_OP_TOKEN_TO_OPCODE, + * CBC_BINARY_LVALUE_OP_TOKEN_TO_OPCODE and + * parser_binary_precedence_table after changes. */ +/** + * Index of first binary operation opcode. + */ +#define LEXER_FIRST_BINARY_OP LEXER_ASSIGN + +/** + * Index of last binary operation opcode. + */ +#define LEXER_LAST_BINARY_OP LEXER_EXPONENTIATION + +/** + * Checks whether the token is a binary operation token. + */ +#define LEXER_IS_BINARY_OP_TOKEN(token_type) \ + ((token_type) >= LEXER_FIRST_BINARY_OP && (token_type) <= LEXER_LAST_BINARY_OP) +/** + * Checks whether the token is an lvalue (assignment) operation token. + */ +#define LEXER_IS_BINARY_LVALUE_OP_TOKEN(token_type) \ + ((token_type) >= LEXER_ASSIGN && (token_type) <= LEXER_ASSIGN_BIT_XOR) +/** + * Checks whether the token is a non-lvalue (assignment) operation token. + */ +#define LEXER_IS_BINARY_NON_LVALUE_OP_TOKEN(token_type) \ + ((token_type) >= LEXER_QUESTION_MARK && (token_type) <= LEXER_LAST_BINARY_OP) + + LEXER_ASSIGN, /**< "=" (prec: 3) */ + LEXER_ASSIGN_ADD, /**< "+=" (prec: 3) */ + LEXER_ASSIGN_SUBTRACT, /**< "-=" (prec: 3) */ + LEXER_ASSIGN_MULTIPLY, /**< "*=" (prec: 3) */ + LEXER_ASSIGN_DIVIDE, /**< "/=" (prec: 3) */ + LEXER_ASSIGN_MODULO, /**< "%=" (prec: 3) */ + LEXER_ASSIGN_EXPONENTIATION, /**< "**=" (prec: 3) */ + LEXER_ASSIGN_NULLISH_COALESCING, /**< "??=" (prec: 3) */ + LEXER_ASSIGN_LOGICAL_OR, /**< "||=" (prec: 3) */ + LEXER_ASSIGN_LOGICAL_AND, /**< "&&=" (prec: 3) */ + LEXER_ASSIGN_LEFT_SHIFT, /**< "<<=" (prec: 3) */ + LEXER_ASSIGN_RIGHT_SHIFT, /**< ">>=" (prec: 3) */ + LEXER_ASSIGN_UNS_RIGHT_SHIFT, /**< ">>>=" (prec: 3) */ + LEXER_ASSIGN_BIT_AND, /**< "&=" (prec: 3) */ + LEXER_ASSIGN_BIT_OR, /**< "|=" (prec: 3) */ + LEXER_ASSIGN_BIT_XOR, /**< "^=" (prec: 3) */ + LEXER_QUESTION_MARK, /**< "?" (prec: 4) */ + LEXER_NULLISH_COALESCING, /**< "??" (prec: 5) */ + LEXER_LOGICAL_OR, /**< "||" (prec: 6) */ + LEXER_LOGICAL_AND, /**< "&&" (prec: 7) */ + LEXER_BIT_OR, /**< "|" (prec: 8) */ + LEXER_BIT_XOR, /**< "^" (prec: 9) */ + LEXER_BIT_AND, /**< "&" (prec: 10) */ + LEXER_EQUAL, /**< "==" (prec: 11) */ + LEXER_NOT_EQUAL, /**< "!=" (prec: 11) */ + LEXER_STRICT_EQUAL, /**< "===" (prec: 11) */ + LEXER_STRICT_NOT_EQUAL, /**< "!==" (prec: 11) */ + LEXER_LESS, /**< "<" (prec: 12) */ + LEXER_GREATER, /**< ">" (prec: 12) */ + LEXER_LESS_EQUAL, /**< "<=" (prec: 12) */ + LEXER_GREATER_EQUAL, /**< ">=" (prec: 12) */ + LEXER_KEYW_IN, /**< in (prec: 12) */ + LEXER_KEYW_INSTANCEOF, /**< instanceof (prec: 12) */ + LEXER_LEFT_SHIFT, /**< "<<" (prec: 13) */ + LEXER_RIGHT_SHIFT, /**< ">>" (prec: 13) */ + LEXER_UNS_RIGHT_SHIFT, /**< ">>>" (prec: 13) */ + LEXER_ADD, /**< "+" (prec: 14) */ + LEXER_SUBTRACT, /**< "-" (prec: 14) */ + LEXER_MULTIPLY, /**< "*" (prec: 15) */ + LEXER_DIVIDE, /**< "/" (prec: 15) */ + LEXER_MODULO, /**< "%" (prec: 15) */ + LEXER_EXPONENTIATION, /**< "**" (prec: 16) */ + LEXER_LEFT_BRACE, /**< "{" */ + LEXER_LEFT_PAREN, /**< "(" */ + LEXER_LEFT_SQUARE, /**< "[" */ + LEXER_RIGHT_BRACE, /**< "}" */ + LEXER_RIGHT_PAREN, /**< ")" */ + LEXER_RIGHT_SQUARE, /**< "]" */ + LEXER_DOT, /**< "." */ + LEXER_SEMICOLON, /**< ";" */ + LEXER_COLON, /**< ":" */ + LEXER_COMMA, /**< "," */ + LEXER_ARROW, /**< "=>" */ + LEXER_HASHMARK, /**< "#" */ + + LEXER_KEYW_BREAK, /**< break */ + LEXER_KEYW_DO, /**< do */ + LEXER_KEYW_CASE, /**< case */ + LEXER_KEYW_ELSE, /**< else */ + LEXER_KEYW_NEW, /**< new */ + LEXER_KEYW_VAR, /**< var */ + LEXER_KEYW_CATCH, /**< catch */ + LEXER_KEYW_FINALLY, /**< finally */ + LEXER_KEYW_RETURN, /**< return */ + LEXER_KEYW_CONTINUE, /**< continue */ + LEXER_KEYW_FOR, /**< for */ + LEXER_KEYW_SWITCH, /**< switch */ + LEXER_KEYW_WHILE, /**< while */ + LEXER_KEYW_DEBUGGER, /**< debugger */ + LEXER_KEYW_FUNCTION, /**< function */ + LEXER_KEYW_WITH, /**< with */ + LEXER_KEYW_DEFAULT, /**< default */ + LEXER_KEYW_IF, /**< if */ + LEXER_KEYW_THROW, /**< throw */ + LEXER_KEYW_TRY, /**< try */ + + LEXER_KEYW_CLASS, /**< class */ + LEXER_KEYW_EXTENDS, /**< extends */ + LEXER_KEYW_SUPER, /**< super */ + LEXER_KEYW_CONST, /**< const */ + LEXER_KEYW_EXPORT, /**< export */ + LEXER_KEYW_IMPORT, /**< import */ + LEXER_KEYW_ENUM, /**< enum */ + +#define LEXER_FIRST_NON_RESERVED_KEYWORD LEXER_EXPRESSION_START + + /* These are virtual tokens. */ + LEXER_EXPRESSION_START, /**< expression start */ + LEXER_PROPERTY_GETTER, /**< property getter function */ + LEXER_PROPERTY_SETTER, /**< property setter function */ + LEXER_COMMA_SEP_LIST, /**< comma separated bracketed expression list */ + LEXER_ASSIGN_GROUP_EXPR, /**< identifier for the assignment is located in a group expression */ + LEXER_ASSIGN_CONST, /**< a const binding is reassigned */ + LEXER_INVALID_PATTERN, /**< special value for invalid destructuring pattern */ + LEXER_PRIVATE_PRIMARY_EXPR, /**< private field in primary expression position */ + LEXER_ASSIGN_REFERENCE, /**< special value for reference assignment */ + + /* Keywords which are not keyword tokens. */ + LEXER_KEYW_ASYNC, /**< async */ +#if JERRY_MODULE_SYSTEM + LEXER_KEYW_META, /**< meta */ +#endif /* JERRY_MODULE_SYSTEM */ + +/* Keywords which cannot be assigned in strict mode. */ +#define LEXER_FIRST_NON_STRICT_ARGUMENTS LEXER_KEYW_EVAL + LEXER_KEYW_EVAL, /**< eval */ + LEXER_KEYW_ARGUMENTS, /**< arguments */ + +/* Future strict reserved words: these keywords + * must form a group after non-reserved keywords. */ +#define LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD LEXER_KEYW_IMPLEMENTS + LEXER_KEYW_IMPLEMENTS, /**< implements */ + LEXER_KEYW_PRIVATE, /**< private */ + LEXER_KEYW_PUBLIC, /**< public */ + LEXER_KEYW_INTERFACE, /**< interface */ + LEXER_KEYW_PACKAGE, /**< package */ + LEXER_KEYW_PROTECTED, /**< protected */ + + /* Context dependent future strict reserved words: + * See also: ECMA-262 v6, 11.6.2.1 */ + LEXER_KEYW_LET, /**< let */ + LEXER_KEYW_YIELD, /**< yield */ + LEXER_KEYW_STATIC, /**< static */ +} lexer_token_type_t; + +#define LEXER_NEWLINE_LS_PS_BYTE_1 0xe2 +#define LEXER_NEWLINE_LS_PS_BYTE_23(source) \ + ((source)[1] == LIT_UTF8_2_BYTE_CODE_POINT_MIN && ((source)[2] | 0x1) == 0xa9) + +#define LEXER_IS_LEFT_BRACKET(type) \ + ((type) == LEXER_LEFT_BRACE || (type) == LEXER_LEFT_PAREN || (type) == LEXER_LEFT_SQUARE) + +#define LEXER_IS_RIGHT_BRACKET(type) \ + ((type) == LEXER_RIGHT_BRACE || (type) == LEXER_RIGHT_PAREN || (type) == LEXER_RIGHT_SQUARE) + +#define LEXER_UNARY_OP_TOKEN_TO_OPCODE(token_type) ((((token_type) -LEXER_PLUS) * 2) + CBC_PLUS) + +#define LEXER_UNARY_LVALUE_OP_TOKEN_TO_OPCODE(token_type) ((((token_type) -LEXER_INCREASE) * 6) + CBC_PRE_INCR) + +#define LEXER_BINARY_OP_TOKEN_TO_OPCODE(token_type) ((uint16_t) ((((token_type) -LEXER_BIT_OR) * 3) + CBC_BIT_OR)) + +#define LEXER_BINARY_LVALUE_OP_TOKEN_TO_OPCODE(token_type) \ + ((cbc_opcode_t) ((((token_type) -LEXER_ASSIGN_ADD) * 2) + CBC_ASSIGN_ADD)) + +/** + * Maximum local buffer size for identifiers which contains escape sequences. + */ +#define LEXER_MAX_LITERAL_LOCAL_BUFFER_SIZE 48 + +/** + * Lexer newline flags. + */ +typedef enum +{ + LEXER_WAS_NEWLINE = (1u << 0), /**< newline was seen */ + LEXER_NO_SKIP_SPACES = (1u << 1) /**< ignore skip spaces */ +} lexer_newline_flags_t; + +/** + * Lexer object identifier parse options. + */ +typedef enum +{ + LEXER_OBJ_IDENT_NO_OPTS = 0, /**< no options */ + LEXER_OBJ_IDENT_ONLY_IDENTIFIERS = (1u << 0), /**< only identifiers are accepted */ + LEXER_OBJ_IDENT_CLASS_IDENTIFIER = (1u << 1), /**< expect identifier inside a class body */ + LEXER_OBJ_IDENT_CLASS_NO_STATIC = (1u << 2), /**< static keyword was not present before the identifier */ + LEXER_OBJ_IDENT_OBJECT_PATTERN = (1u << 3), /**< parse "get"/"set" as string literal in object pattern */ + LEXER_OBJ_IDENT_CLASS_PRIVATE = (1u << 4), /**< static keyword was not present before the identifier */ + LEXER_OBJ_IDENT_SET_FUNCTION_START = 0, /**< set function start (disabled) */ +} lexer_obj_ident_opts_t; + +/** + * Lexer string options. + */ +typedef enum +{ + LEXER_STRING_NO_OPTS = (1u << 0), /**< no options */ + LEXER_STRING_RAW = (1u << 1), /**< raw string ECMAScript v6, 11.8.6.1: TVR */ +} lexer_string_options_t; + +/** + * Lexer number types. + */ +typedef enum +{ + LEXER_NUMBER_DECIMAL, /**< decimal number */ + LEXER_NUMBER_HEXADECIMAL, /**< hexadecimal number */ + LEXER_NUMBER_OCTAL, /**< octal number */ + LEXER_NUMBER_BINARY, /**< binary number */ +#if JERRY_BUILTIN_BIGINT + LEXER_NUMBER_BIGINT, /**< bigint number */ +#endif /* JERRY_BUILTIN_BIGINT */ +} lexer_number_type_t; + +/** + * Lexer literal flags. + **/ +typedef enum +{ + LEXER_LIT_LOCATION_NO_OPTS = 0, /**< no options */ + LEXER_LIT_LOCATION_HAS_ESCAPE = (1 << 0), /**< binding has escape */ + LEXER_LIT_LOCATION_IS_ASCII = (1 << 1), /**< all characters are ascii characters */ +} lexer_lit_location_flags_t; + +/** + * Lexer character (string / identifier) literal data. + */ +typedef struct +{ + const uint8_t *char_p; /**< start of identifier or string token */ + prop_length_t length; /**< length or index of a literal */ + uint8_t type; /**< type of the current literal */ + uint8_t status_flags; /**< any combination of lexer_lit_location_flags_t status bits */ +} lexer_lit_location_t; + +/** + * Lexer token. + */ +typedef struct +{ + uint8_t type; /**< token type */ + uint8_t keyword_type; /**< keyword type for identifiers */ + uint8_t extra_value; /**< helper value for different purposes */ + uint8_t flags; /**< flag bits for the current token */ + parser_line_counter_t line; /**< token start line */ + parser_line_counter_t column; /**< token start column */ + lexer_lit_location_t lit_location; /**< extra data for character literals */ +} lexer_token_t; + +/** + * Literal data set by lexer_construct_literal_object. + */ +typedef struct +{ + lexer_literal_t *literal_p; /**< pointer to the literal object */ + uint16_t index; /**< literal index */ +} lexer_lit_object_t; + +/** + * @} + * @} + * @} + */ + +#endif /* !JS_LEXER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-expr.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-expr.cpp new file mode 100644 index 0000000..20c074e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-expr.cpp @@ -0,0 +1,4162 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-internal.h" + +#if JERRY_PARSER +#include "ecma-helpers.h" + +#include "jcontext.h" +#include "js-parser-tagged-template-literal.h" +#include "lit-char-helpers.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_expr Expression parser + * @{ + */ + +/** + * Maximum precedence for right-to-left binary operation evaluation. + */ +#define PARSER_RIGHT_TO_LEFT_ORDER_MAX_PRECEDENCE 7 + +/** + * Precedence for ternary operation. + */ +#define PARSER_RIGHT_TO_LEFT_ORDER_TERNARY_PRECEDENCE 4 + +/** + * Precedence for exponentiation operation. + */ +#define PARSER_RIGHT_TO_LEFT_ORDER_EXPONENTIATION 16 + +/** + * Value of grouping level increase and decrease. + */ +#define PARSER_GROUPING_LEVEL_INCREASE 2 + +/** + * Precedence of the binary tokens. + * + * See also: + * lexer_token_type_t + */ +static const uint8_t parser_binary_precedence_table[] = { + 3, /**< "=" */ + 3, /**< "+=" */ + 3, /**< "-=" */ + 3, /**< "*=" */ + 3, /**< "/=" */ + 3, /**< "=" */ + 3, /**< "<<=" */ + 3, /**< ">>=" */ + 3, /**< ">>>=" */ + 3, /**< "&=" */ + 3, /**< "|=" */ + 3, /**< "^=" */ + 3, /**< "**=" */ + 3, /**< "??=" */ + 3, /**< "||=" */ + 3, /**< "&&=" */ + 4, /**< "?"*/ + 5, /**< "??" */ + 6, /**< "||" */ + 7, /**< "&&" */ + 8, /**< "|" */ + 9, /**< "^" */ + 10, /**< "&" */ + 11, /**< "==" */ + 11, /**< "!=" */ + 11, /**< "===" */ + 11, /**< "!==" */ + 12, /**< "<" */ + 12, /**< ">" */ + 12, /**< "<=" */ + 12, /**< ">=" */ + 12, /**< in */ + 12, /**< instanceof */ + 13, /**< "<<" */ + 13, /**< ">>" */ + 13, /**< ">>>" */ + 14, /**< "+" */ + 14, /**< "-" */ + 15, /**< "*" */ + 15, /**< "/" */ + 15, /**< "%" */ + 16, /**< "**" */ +}; + +JERRY_STATIC_ASSERT ((sizeof (parser_binary_precedence_table) == 42), + parser_binary_precedence_table_should_have_39_values_in_es2015); + +/** + * Generate byte code for operators with lvalue. + */ +static inline void +parser_push_result (parser_context_t *context_p) /**< context */ +{ + if (CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode)) + { + JERRY_ASSERT (CBC_SAME_ARGS (context_p->last_cbc_opcode, context_p->last_cbc_opcode + 1)); + + if ((context_p->last_cbc_opcode == CBC_POST_INCR || context_p->last_cbc_opcode == CBC_POST_DECR) + && context_p->stack_depth >= context_p->stack_limit) + { + /* Stack limit is increased for CBC_POST_INCR_PUSH_RESULT + * and CBC_POST_DECR_PUSH_RESULT opcodes. Needed by vm.c. */ + JERRY_ASSERT (context_p->stack_depth == context_p->stack_limit); + + context_p->stack_limit++; + + if (context_p->stack_limit > PARSER_MAXIMUM_STACK_LIMIT) + { + parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED); + } + } + + context_p->last_cbc_opcode++; + parser_flush_cbc (context_p); + } +} /* parser_push_result */ + +/** + * Check for invalid assignment for "eval" and "arguments" + */ +static void +parser_check_invalid_assign (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL); + + if (JERRY_UNLIKELY (context_p->status_flags & PARSER_IS_STRICT)) + { + if (context_p->last_cbc.literal_keyword_type == LEXER_KEYW_EVAL) + { + parser_raise_error (context_p, PARSER_ERR_EVAL_CANNOT_ASSIGNED); + } + else if (context_p->last_cbc.literal_keyword_type == LEXER_KEYW_ARGUMENTS) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENTS_CANNOT_ASSIGNED); + } + } +} /* parser_check_invalid_assign */ + +/** + * Check and throw an error if the "new.target" is invalid as a left-hand side expression. + */ +static void +parser_check_invalid_new_target (parser_context_t *context_p, /**< parser context */ + cbc_opcode_t opcode) /**< current opcode under parsing */ +{ + /* new.target is an invalid left-hand side target */ + if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_NEW_TARGET)) + { + /* Make sure that the call side is a post/pre increment or an assignment expression. + * There should be no other ways the "new.target" expression should be here. */ + JERRY_ASSERT ( + (opcode >= CBC_PRE_INCR && opcode <= CBC_POST_DECR) + || (opcode == CBC_ASSIGN + && (context_p->token.type == LEXER_ASSIGN || LEXER_IS_BINARY_LVALUE_OP_TOKEN (context_p->token.type)))); + + parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_NOT_ALLOWED); + } +} /* parser_check_invalid_new_target */ + +/** + * Emit identifier reference + */ +static void +parser_emit_ident_reference (parser_context_t *context_p, /**< context */ + uint16_t opcode) /* opcode */ +{ + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = opcode; + return; + } + + uint16_t literal_index; + + if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + context_p->last_cbc_opcode = CBC_PUSH_LITERAL; + literal_index = context_p->last_cbc.value; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_THIS_LITERAL) + { + context_p->last_cbc_opcode = CBC_PUSH_THIS; + literal_index = context_p->last_cbc.literal_index; + } + else + { + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_THREE_LITERALS); + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + literal_index = context_p->last_cbc.third_literal_index; + } + + parser_emit_cbc_literal (context_p, opcode, literal_index); +} /* parser_emit_ident_reference */ + +/** + * Generate byte code for operators with lvalue. + */ +static void +parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */ + cbc_opcode_t opcode) /**< opcode */ +{ + if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + parser_check_invalid_assign (context_p); + + uint16_t unary_opcode; + + if (opcode == CBC_DELETE_PUSH_RESULT) + { + if (JERRY_UNLIKELY (context_p->status_flags & PARSER_IS_STRICT)) + { + parser_raise_error (context_p, PARSER_ERR_DELETE_IDENT_NOT_ALLOWED); + } + + unary_opcode = CBC_DELETE_IDENT_PUSH_RESULT; + } + else + { + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_LITERAL, opcode + CBC_UNARY_LVALUE_WITH_IDENT)); + unary_opcode = (uint16_t) (opcode + CBC_UNARY_LVALUE_WITH_IDENT); + } + + parser_emit_ident_reference (context_p, unary_opcode); + + if (unary_opcode != CBC_DELETE_IDENT_PUSH_RESULT + && scanner_literal_is_const_reg (context_p, context_p->last_cbc.literal_index)) + { + /* The current value must be read, but it cannot be changed. */ + context_p->last_cbc_opcode = CBC_PUSH_LITERAL; + parser_emit_cbc_ext (context_p, CBC_EXT_THROW_ASSIGN_CONST_ERROR); + } + return; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_PROP) + { + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP, opcode)); + context_p->last_cbc_opcode = (uint16_t) opcode; + return; + } + + if (PARSER_IS_PUSH_PROP_LITERAL (context_p->last_cbc_opcode)) + { + context_p->last_cbc_opcode = PARSER_PUSH_PROP_LITERAL_TO_PUSH_LITERAL (context_p->last_cbc_opcode); + } + else + { + /* Invalid LeftHandSide expression. */ + if (opcode == CBC_DELETE_PUSH_RESULT) + { + if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL)) + { + parser_raise_error (context_p, PARSER_ERR_DELETE_PRIVATE_FIELD); + } + + if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL) + || context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR); + parser_emit_cbc (context_p, CBC_POP); + return; + } + + parser_emit_cbc (context_p, CBC_POP); + parser_emit_cbc (context_p, CBC_PUSH_TRUE); + return; + } + + parser_check_invalid_new_target (context_p, opcode); + if (opcode == CBC_PRE_INCR || opcode == CBC_PRE_DECR) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_PREFIX_OP); + } + else + { + parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_POSTFIX_OP); + } + } + + parser_emit_cbc (context_p, (uint16_t) opcode); +} /* parser_emit_unary_lvalue_opcode */ + +/** + * Parse array literal. + */ +static void +parser_parse_array_literal (parser_context_t *context_p) /**< context */ +{ + uint32_t pushed_items = 0; + uint16_t opcode = (uint16_t) CBC_ARRAY_APPEND; + + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_SQUARE); + + parser_emit_cbc (context_p, CBC_CREATE_ARRAY); + lexer_next_token (context_p); + + while (true) + { + if (context_p->token.type == LEXER_RIGHT_SQUARE) + { + if (pushed_items > 0) + { + parser_emit_cbc_call (context_p, opcode, pushed_items); + } + return; + } + + pushed_items++; + + if (context_p->token.type == LEXER_COMMA) + { + parser_emit_cbc (context_p, CBC_PUSH_ELISION); + lexer_next_token (context_p); + } + else + { + if (context_p->token.type == LEXER_THREE_DOTS) + { + opcode = (uint16_t) (PARSER_TO_EXT_OPCODE (CBC_EXT_SPREAD_ARRAY_APPEND)); + pushed_items++; + lexer_next_token (context_p); + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SPREAD_ELEMENT); + } + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (context_p->last_cbc_opcode == CBC_PUSH_THIS) + { + parser_flush_cbc (context_p); + } + + if (context_p->token.type == LEXER_COMMA) + { + lexer_next_token (context_p); + } + else if (context_p->token.type != LEXER_RIGHT_SQUARE) + { + parser_raise_error (context_p, PARSER_ERR_ARRAY_ITEM_SEPARATOR_EXPECTED); + } + } + + if (pushed_items >= 64) + { + parser_emit_cbc_call (context_p, opcode, pushed_items); + opcode = (uint16_t) CBC_ARRAY_APPEND; + pushed_items = 0; + } + } +} /* parser_parse_array_literal */ + +/** Forward definition of parse array initializer. */ +static void parser_parse_array_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); + +/** Forward definition of parse object initializer. */ +static void parser_parse_object_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); + +/** + * Class literal parsing options. + */ +typedef enum +{ + PARSER_CLASS_LITERAL_NO_OPTS = 0, /**< no options are provided */ + PARSER_CLASS_LITERAL_CTOR_PRESENT = (1 << 0), /**< class constructor is present */ + PARSER_CLASS_LITERAL_HERITAGE_PRESENT = (1 << 1), /**< class heritage is present */ +} parser_class_literal_opts_t; + +/** + * Checks whether the current string or identifier literal is constructor + * + * @return true, if constructor and false otherwise + */ +static inline bool +parser_is_constructor_literal (parser_context_t *context_p) /**< context */ +{ + return (LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type) + && lexer_compare_literal_to_string (context_p, "constructor", 11)); +} /* parser_is_constructor_literal */ + +/** + * Checks if current private field is already declared + */ +static void +parser_check_duplicated_private_field (parser_context_t *context_p, /**< context */ + uint8_t opts) /**< options */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL); + JERRY_ASSERT (context_p->private_context_p); + scanner_class_private_member_t *iter = context_p->private_context_p->members_p; + + bool search_for_property = (opts & SCANNER_PRIVATE_FIELD_PROPERTY); + + while (iter != NULL) + { + if (lexer_compare_identifiers (context_p, &context_p->token.lit_location, &iter->loc) && (iter->u8_arg & opts)) + { + if (iter->u8_arg & SCANNER_PRIVATE_FIELD_SEEN) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_PRIVATE_FIELD); + } + + iter->u8_arg |= SCANNER_PRIVATE_FIELD_SEEN; + + if (!search_for_property) + { + break; + } + } + + iter = iter->prev_p; + } +} /* parser_check_duplicated_private_field */ + +/** + * Parse class literal. + * + * @return true - if the class has static fields, false - otherwise + */ +static bool +parser_parse_class_body (parser_context_t *context_p, /**< context */ + parser_class_literal_opts_t opts, /**< class literal parsing options */ + uint16_t class_name_index) /**< class literal index */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE); + + lexer_literal_t *ctor_literal_p = NULL; + lexer_literal_t *static_fields_literal_p = NULL; + + if (opts & PARSER_CLASS_LITERAL_CTOR_PRESENT) + { + ctor_literal_p = lexer_construct_unused_literal (context_p); + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, (uint16_t) (context_p->literal_count++)); + } + else if (opts & PARSER_CLASS_LITERAL_HERITAGE_PRESENT) + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE); + } + else + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR); + } + + if (class_name_index != PARSER_INVALID_LITERAL_INDEX) + { + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, class_name_index); + } + + parser_emit_cbc_ext (context_p, CBC_EXT_INIT_CLASS); + + bool is_static = false; + bool is_private = false; + size_t fields_size = 0; + uint32_t computed_field_count = 0; + + while (true) + { + if (!is_static) + { + lexer_skip_empty_statements (context_p); + } + + uint32_t flags = (LEXER_OBJ_IDENT_CLASS_IDENTIFIER | LEXER_OBJ_IDENT_SET_FUNCTION_START); + + if (!is_static) + { + flags |= LEXER_OBJ_IDENT_CLASS_NO_STATIC; + } + + if (is_private) + { + flags |= LEXER_OBJ_IDENT_CLASS_PRIVATE; + } + + lexer_expect_object_literal_id (context_p, flags); + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + JERRY_ASSERT (!is_static); + break; + } + + if (context_p->token.type == LEXER_HASHMARK) + { + is_private = true; + lexer_next_token (context_p); + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + continue; + } + + if (context_p->token.type == LEXER_KEYW_STATIC) + { + JERRY_ASSERT (!is_static); + is_static = true; + continue; + } + + bool is_constructor_literal = false; + + if (context_p->token.type == LEXER_LITERAL) + { + is_constructor_literal = parser_is_constructor_literal (context_p); + + if (is_private) + { + if (is_constructor_literal && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + { + parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR); + } + + parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER); + } + } + + if (!is_static && is_constructor_literal) + { + JERRY_ASSERT (!is_static); + JERRY_ASSERT (opts & PARSER_CLASS_LITERAL_CTOR_PRESENT); + JERRY_ASSERT (ctor_literal_p != NULL); + + if (ctor_literal_p->type == LEXER_FUNCTION_LITERAL) + { + /* 14.5.1 */ + parser_raise_error (context_p, PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS); + } + + uint32_t constructor_status_flags = + (PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER | PARSER_CLASS_CONSTRUCTOR | PARSER_LEXICAL_ENV_NEEDED); + + if (opts & PARSER_CLASS_LITERAL_HERITAGE_PRESENT) + { + constructor_status_flags |= PARSER_ALLOW_SUPER_CALL; + } + + if (context_p->status_flags & PARSER_INSIDE_WITH) + { + constructor_status_flags |= PARSER_INSIDE_WITH; + } + + parser_flush_cbc (context_p); + ecma_compiled_code_t *compiled_code_p = parser_parse_function (context_p, constructor_status_flags); + ctor_literal_p->u.bytecode_p = compiled_code_p; + ctor_literal_p->type = LEXER_FUNCTION_LITERAL; + continue; + } + + bool is_computed = false; + + if (context_p->token.type == LEXER_PROPERTY_GETTER || context_p->token.type == LEXER_PROPERTY_SETTER) + { + uint16_t literal_index, function_literal_index; + bool is_getter = (context_p->token.type == LEXER_PROPERTY_GETTER); + + uint32_t accessor_status_flags = PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER; + accessor_status_flags |= (is_getter ? PARSER_IS_PROPERTY_GETTER : PARSER_IS_PROPERTY_SETTER); + + uint8_t ident_opts = LEXER_OBJ_IDENT_ONLY_IDENTIFIERS; + + if (lexer_check_next_character (context_p, LIT_CHAR_HASHMARK)) + { + lexer_next_token (context_p); + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + ident_opts |= LEXER_OBJ_IDENT_CLASS_PRIVATE; + is_private = true; + } + + lexer_expect_object_literal_id (context_p, ident_opts); + + if (is_private) + { + parser_check_duplicated_private_field (context_p, + is_getter ? SCANNER_PRIVATE_FIELD_GETTER : SCANNER_PRIVATE_FIELD_SETTER); + } + + literal_index = context_p->lit_object.index; + + if (context_p->token.type == LEXER_RIGHT_SQUARE) + { + is_computed = true; + } + else if (is_static && !is_private) + { + if (LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type) + && lexer_compare_identifier_to_string (&context_p->token.lit_location, (uint8_t *) "prototype", 9)) + { + parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE); + } + } + else if (parser_is_constructor_literal (context_p)) + { + JERRY_ASSERT (!is_static || is_private); + parser_raise_error (context_p, PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR); + } + + function_literal_index = lexer_construct_function_object (context_p, accessor_status_flags); + + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, literal_index); + + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + + cbc_ext_opcode_t opcode; + + if (is_computed) + { + context_p->last_cbc.literal_index = function_literal_index; + + if (is_getter) + { + opcode = is_static ? CBC_EXT_SET_STATIC_COMPUTED_GETTER : CBC_EXT_SET_COMPUTED_GETTER; + } + else + { + opcode = is_static ? CBC_EXT_SET_STATIC_COMPUTED_SETTER : CBC_EXT_SET_COMPUTED_SETTER; + } + } + else + { + context_p->last_cbc.value = function_literal_index; + + if (is_getter) + { + opcode = is_static ? (is_private ? CBC_EXT_COLLECT_PRIVATE_STATIC_GETTER : CBC_EXT_SET_STATIC_GETTER) + : (is_private ? CBC_EXT_COLLECT_PRIVATE_GETTER : CBC_EXT_SET_GETTER); + } + else + { + opcode = is_static ? (is_private ? CBC_EXT_COLLECT_PRIVATE_STATIC_SETTER : CBC_EXT_SET_STATIC_SETTER) + : (is_private ? CBC_EXT_COLLECT_PRIVATE_SETTER : CBC_EXT_SET_SETTER); + } + } + + if (is_computed) + { + parser_emit_cbc_ext (context_p, + is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME : CBC_EXT_SET_COMPUTED_SETTER_NAME); + parser_emit_cbc_ext (context_p, opcode); + } + else + { + if (is_private) + { + accessor_status_flags |= PARSER_PRIVATE_FUNCTION_NAME; + } + parser_set_function_name (context_p, function_literal_index, literal_index, accessor_status_flags); + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode); + } + + is_static = false; + is_private = false; + continue; + } + + uint32_t status_flags = PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER; + + if (context_p->token.type == LEXER_KEYW_ASYNC) + { + status_flags |= PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + + uint8_t ident_opts = LEXER_OBJ_IDENT_ONLY_IDENTIFIERS; + + if (lexer_check_next_character (context_p, LIT_CHAR_HASHMARK)) + { + lexer_next_token (context_p); + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + ident_opts |= LEXER_OBJ_IDENT_CLASS_PRIVATE; + is_private = true; + } + + if (!lexer_consume_generator (context_p)) + { + lexer_expect_object_literal_id (context_p, ident_opts); + } + + if (is_private && context_p->token.type == LEXER_LITERAL) + { + if (parser_is_constructor_literal (context_p)) + { + parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR); + } + + parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER); + } + } + + if (context_p->token.type == LEXER_MULTIPLY) + { + uint8_t ident_opts = LEXER_OBJ_IDENT_ONLY_IDENTIFIERS; + + if (lexer_check_next_character (context_p, LIT_CHAR_HASHMARK)) + { + lexer_next_token (context_p); + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + ident_opts |= LEXER_OBJ_IDENT_CLASS_PRIVATE; + is_private = true; + } + + lexer_expect_object_literal_id (context_p, ident_opts); + + status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + + if (is_private && context_p->token.type == LEXER_LITERAL) + { + if (parser_is_constructor_literal (context_p)) + { + parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR); + } + + parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER); + } + } + + bool is_static_block = context_p->token.type == LEXER_LEFT_BRACE; + + if (context_p->token.type == LEXER_RIGHT_SQUARE) + { + is_computed = true; + } + else if (!is_static_block && LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type)) + { + if (is_static && !is_private) + { + if (lexer_compare_identifier_to_string (&context_p->token.lit_location, (uint8_t *) "prototype", 9)) + { + parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE); + } + } + else if ((status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION)) + && lexer_compare_literal_to_string (context_p, "constructor", 11)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CLASS_CONSTRUCTOR); + } + } + + if (!(status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION))) + { + if (is_static_block || !lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + { + /* Class field. */ + if (fields_size == 0) + { + parser_stack_push_uint8 (context_p, PARSER_CLASS_FIELD_END); + } + + scanner_range_t range; + uint8_t class_field_type = is_static ? PARSER_CLASS_FIELD_STATIC : 0; + + if (!is_computed) + { + if (is_private) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + uint8_t field_opcode = is_static ? CBC_EXT_COLLECT_PRIVATE_STATIC_FIELD : CBC_EXT_COLLECT_PRIVATE_FIELD; + parser_emit_cbc_ext_literal_from_token (context_p, field_opcode); + } + + if (is_static && !is_static_block && parser_is_constructor_literal (context_p)) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIST_EXPECTED); + } + + range.start_location.source_p = context_p->token.lit_location.char_p; + range.start_location.line = context_p->token.line; + range.start_location.column = context_p->token.column; + class_field_type |= PARSER_CLASS_FIELD_NORMAL; + + if (context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + range.start_location.source_p--; + } + } + else + { + if (++computed_field_count > ECMA_INTEGER_NUMBER_MAX) + { + parser_raise_error (context_p, PARSER_ERR_TOO_MANY_CLASS_FIELDS); + } + + if (is_static && static_fields_literal_p == NULL) + { + static_fields_literal_p = lexer_construct_unused_literal (context_p); + parser_emit_cbc_ext_literal (context_p, + CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC, + (uint16_t) (context_p->literal_count++)); + } + else + { + parser_emit_cbc_ext (context_p, + (is_static ? CBC_EXT_ADD_STATIC_COMPUTED_FIELD : CBC_EXT_ADD_COMPUTED_FIELD)); + } + } + + if (is_static_block) + { + class_field_type |= PARSER_CLASS_FIELD_STATIC_BLOCK; + + if (context_p->next_scanner_info_p->type != SCANNER_TYPE_CLASS_STATIC_BLOCK_END) + { + parser_flush_cbc (context_p); + parser_parse_class_static_block (context_p); + } + + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_CLASS_STATIC_BLOCK_END); + + scanner_set_location (context_p, &((scanner_location_info_t *) context_p->next_scanner_info_p)->location); + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + range.start_location.source_p = context_p->next_scanner_info_p->source_p - 1; + + scanner_seek (context_p); + + parser_stack_push (context_p, &range.start_location, sizeof (scanner_location_t)); + fields_size += sizeof (scanner_location_t); + + lexer_consume_next_character (context_p); + } + else if (lexer_consume_assign (context_p)) + { + class_field_type |= PARSER_CLASS_FIELD_INITIALIZED; + + if (context_p->next_scanner_info_p->source_p != context_p->source_p) + { + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + + if (is_computed) + { + scanner_get_location (&range.start_location, context_p); + } + + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END); + range.source_end_p = ((scanner_location_info_t *) context_p->next_scanner_info_p)->location.source_p; + + scanner_set_location (context_p, &((scanner_location_info_t *) context_p->next_scanner_info_p)->location); + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + scanner_seek (context_p); + + parser_stack_push (context_p, &range, sizeof (scanner_range_t)); + fields_size += sizeof (scanner_range_t); + } + else + { + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) + && !lexer_check_next_characters (context_p, LIT_CHAR_SEMICOLON, LIT_CHAR_RIGHT_BRACE)) + { + lexer_next_token (context_p); + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + + if (!is_computed) + { + parser_stack_push (context_p, &range.start_location, sizeof (scanner_location_t)); + fields_size += sizeof (scanner_location_t); + } + } + + parser_stack_push_uint8 (context_p, class_field_type); + fields_size++; + is_static = false; + is_private = false; + continue; + } + + if (!is_computed) + { + if (context_p->token.lit_location.type != LEXER_NUMBER_LITERAL) + { + JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL + || context_p->token.lit_location.type == LEXER_STRING_LITERAL); + if (is_private) + { + parser_resolve_private_identifier (context_p); + } + else + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + } + } + else + { + lexer_construct_number_object (context_p, false, false); + } + } + } + + uint16_t literal_index = context_p->lit_object.index; + uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags | PARSER_IS_METHOD); + + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); + + if (is_computed) + { + parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME); + parser_emit_cbc_ext (context_p, is_static ? CBC_EXT_SET_STATIC_COMPUTED_PROPERTY : CBC_EXT_SET_COMPUTED_PROPERTY); + is_static = false; + continue; + } + + uint32_t function_name_status_flags = 0; + + if (is_private) + { + function_name_status_flags = PARSER_PRIVATE_FUNCTION_NAME; + } + + parser_set_function_name (context_p, function_literal_index, literal_index, function_name_status_flags); + + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + + context_p->last_cbc.value = literal_index; + + if (is_static) + { + context_p->last_cbc_opcode = (is_private ? PARSER_TO_EXT_OPCODE (CBC_EXT_COLLECT_PRIVATE_STATIC_METHOD) + : PARSER_TO_EXT_OPCODE (CBC_EXT_SET_STATIC_PROPERTY_LITERAL)); + is_static = false; + } + else if (is_private) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_COLLECT_PRIVATE_METHOD); + } + else + { + context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY; + } + + is_private = false; + } + + if (fields_size == 0) + { + return false; + } + + parser_reverse_class_fields (context_p, fields_size); + + /* Since PARSER_IS_ARROW_FUNCTION and PARSER_CLASS_CONSTRUCTOR bits cannot + * be set at the same time, this bit combination triggers class field parsing. */ + + if (!(context_p->stack_top_uint8 & PARSER_CLASS_FIELD_STATIC)) + { + lexer_literal_t *literal_p = lexer_construct_unused_literal (context_p); + + uint16_t function_literal_index = (uint16_t) (context_p->literal_count++); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_FIELD_INIT, function_literal_index); + parser_flush_cbc (context_p); + + literal_p->u.bytecode_p = parser_parse_class_fields (context_p); + literal_p->type = LEXER_FUNCTION_LITERAL; + } + + bool has_static_field = false; + + if (context_p->stack_top_uint8 & PARSER_CLASS_FIELD_STATIC) + { + if (static_fields_literal_p == NULL) + { + static_fields_literal_p = lexer_construct_unused_literal (context_p); + uint16_t function_literal_index = (uint16_t) (context_p->literal_count++); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_STATIC_FIELD_FUNC, function_literal_index); + } + + parser_flush_cbc (context_p); + static_fields_literal_p->u.bytecode_p = parser_parse_class_fields (context_p); + static_fields_literal_p->type = LEXER_FUNCTION_LITERAL; + + has_static_field = true; + } + + parser_stack_pop_uint8 (context_p); + return has_static_field; +} /* parser_parse_class_body */ + +/** + * Parse class statement or expression. + */ +void +parser_parse_class (parser_context_t *context_p, /**< context */ + bool is_statement) /**< true - if class is parsed as a statement + * false - otherwise (as an expression) */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS); + + uint16_t class_ident_index = PARSER_INVALID_LITERAL_INDEX; + uint16_t class_name_index = PARSER_INVALID_LITERAL_INDEX; + parser_class_literal_opts_t opts = PARSER_CLASS_LITERAL_NO_OPTS; + scanner_info_t *scanner_info_p = context_p->next_scanner_info_p; + + scanner_class_info_t *class_info_p = (scanner_class_info_t *) scanner_info_p; + parser_private_context_t private_ctx; + + if (scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR); + parser_save_private_context (context_p, &private_ctx, class_info_p); + + if (scanner_info_p->u8_arg & SCANNER_CONSTRUCTOR_EXPLICIT) + { + opts = (parser_class_literal_opts_t) ((int) opts | (int) PARSER_CLASS_LITERAL_CTOR_PRESENT); + } + + scanner_release_next (context_p, sizeof (scanner_class_info_t)); + } + + if (is_statement) + { + /* Class statement must contain an identifier. */ + lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED); + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + class_ident_index = context_p->lit_object.index; + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED; + class_name_index = context_p->lit_object.index; + +#if JERRY_MODULE_SYSTEM + parser_module_append_export_name (context_p); + context_p->status_flags &= (uint32_t) ~PARSER_MODULE_STORE_IDENT; +#endif /* JERRY_MODULE_SYSTEM */ + + lexer_next_token (context_p); + } + else + { + lexer_next_token (context_p); + + /* Class expression may contain an identifier. */ + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED; + class_name_index = context_p->lit_object.index; + lexer_next_token (context_p); + } + } + + if (class_name_index != PARSER_INVALID_LITERAL_INDEX) + { + if (JERRY_UNLIKELY (context_p->scope_stack_top >= context_p->scope_stack_size)) + { + JERRY_ASSERT (context_p->scope_stack_size == PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK); + parser_raise_error (context_p, PARSER_ERR_SCOPE_STACK_LIMIT_REACHED); + } + + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top; + + PARSER_PLUS_EQUAL_U16 (context_p->scope_stack_top, 1); + scope_stack_p->map_from = class_name_index; + scope_stack_p->map_to = 0; + + parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_NAMED_CLASS_ENV, class_name_index); + } + else + { + parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED); + } + + bool is_strict = (context_p->status_flags & PARSER_IS_STRICT) != 0; + + /* 14.5. A ClassBody is always strict code. */ + context_p->status_flags |= PARSER_IS_STRICT; + + if (context_p->token.type == LEXER_KEYW_EXTENDS) + { + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR | PARSE_EXPR_LEFT_HAND_SIDE); + opts = (parser_class_literal_opts_t) ((int) opts | (int) PARSER_CLASS_LITERAL_HERITAGE_PRESENT); + } + else + { + /* Elisions represents that the classHeritage is not present */ + parser_emit_cbc (context_p, CBC_PUSH_ELISION); + } + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED); + } + + context_p->private_context_p->opts |= SCANNER_PRIVATE_FIELD_ACTIVE; + + /* ClassDeclaration is parsed. Continue with class body. */ + bool has_static_field = parser_parse_class_body (context_p, opts, class_name_index); + + if (class_name_index != PARSER_INVALID_LITERAL_INDEX) + { + parser_emit_cbc_ext_literal (context_p, CBC_EXT_FINALIZE_NAMED_CLASS, class_name_index); + PARSER_MINUS_EQUAL_U16 (context_p->scope_stack_top, 1); + } + else + { + parser_emit_cbc_ext (context_p, CBC_EXT_FINALIZE_ANONYMOUS_CLASS); + } + + if (has_static_field) + { + parser_emit_cbc_ext (context_p, CBC_EXT_RUN_STATIC_FIELD_INIT); + } + + if (is_statement) + { + cbc_opcode_t opcode = CBC_MOV_IDENT; + + if (class_ident_index < PARSER_REGISTER_START) + { + opcode = (scanner_literal_is_created (context_p, class_ident_index) ? CBC_ASSIGN_LET_CONST : CBC_INIT_LET); + } + + parser_emit_cbc_literal (context_p, (uint16_t) opcode, class_ident_index); + parser_flush_cbc (context_p); + } + + if (!is_strict) + { + /* Restore flag */ + context_p->status_flags &= (uint32_t) ~PARSER_IS_STRICT; + } + context_p->status_flags &= (uint32_t) ~PARSER_ALLOW_SUPER; + + parser_restore_private_context (context_p, &private_ctx); + + lexer_next_token (context_p); +} /* parser_parse_class */ + +/** + * Parse object initializer method definition. + * + * See also: ES2015 14.3 + */ +static void +parser_parse_object_method (parser_context_t *context_p) /**< context */ +{ + context_p->source_p--; + context_p->column--; + uint16_t function_literal_index = + lexer_construct_function_object (context_p, (PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER | PARSER_IS_METHOD)); + + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); + + context_p->last_cbc.literal_type = LEXER_FUNCTION_LITERAL; + + lexer_next_token (context_p); +} /* parser_parse_object_method */ + +/** + * Reparse the current literal as a common identifier. + */ +static void +parser_reparse_as_common_identifier (parser_context_t *context_p, /**< context */ + parser_line_counter_t start_line, /**< start line */ + parser_line_counter_t start_column) /**< start column */ +{ + /* context_p->token.lit_location.char_p is showing the character after the string start, + so it is not suitable for reparsing as identifier. + e.g.: { 'foo' } */ + if (context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + context_p->source_p = context_p->token.lit_location.char_p; + context_p->line = start_line; + context_p->column = start_column; + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); + +} /* parser_reparse_as_common_identifier */ + +/** + * Parse object literal. + */ +static void +parser_parse_object_literal (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE); + + parser_emit_cbc (context_p, CBC_CREATE_OBJECT); + + bool proto_seen = false; + bool has_super_env = false; + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS); + + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_SUPER) + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT); + has_super_env = true; + } + + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + + while (true) + { + lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_SET_FUNCTION_START); + + switch (context_p->token.type) + { + case LEXER_RIGHT_BRACE: + { + break; + } + case LEXER_PROPERTY_GETTER: + case LEXER_PROPERTY_SETTER: + { + uint32_t status_flags; + cbc_ext_opcode_t opcode; + bool is_getter = context_p->token.type == LEXER_PROPERTY_GETTER; + + if (is_getter) + { + status_flags = PARSER_FUNCTION_CLOSURE | PARSER_IS_PROPERTY_GETTER; + opcode = CBC_EXT_SET_GETTER; + } + else + { + status_flags = PARSER_FUNCTION_CLOSURE | PARSER_IS_PROPERTY_SETTER; + opcode = CBC_EXT_SET_SETTER; + } + + status_flags |= PARSER_ALLOW_SUPER; + + lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_ONLY_IDENTIFIERS); + + /* This assignment is a nop for computed getters/setters. */ + uint16_t literal_index = context_p->lit_object.index; + + bool is_computed = context_p->token.type == LEXER_RIGHT_SQUARE; + + if (is_computed) + { + opcode = ((opcode == CBC_EXT_SET_GETTER) ? CBC_EXT_SET_COMPUTED_GETTER : CBC_EXT_SET_COMPUTED_SETTER); + } + + uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags); + + if (opcode >= CBC_EXT_SET_COMPUTED_GETTER) + { + literal_index = function_literal_index; + } + + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, literal_index); + + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + + if (is_computed) + { + parser_emit_cbc_ext (context_p, + is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME : CBC_EXT_SET_COMPUTED_SETTER_NAME); + + if (has_super_env) + { + parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED); + } + parser_emit_cbc_ext (context_p, opcode); + lexer_next_token (context_p); + break; + } + + parser_set_function_name (context_p, function_literal_index, literal_index, status_flags); + + if (has_super_env) + { + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + context_p->last_cbc.value = function_literal_index; + parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED); + parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER : CBC_EXT_SET_COMPUTED_SETTER); + } + else + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode); + context_p->last_cbc.value = function_literal_index; + } + + lexer_next_token (context_p); + break; + } + case LEXER_RIGHT_SQUARE: + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + parser_parse_object_method (context_p); + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + + if (parser_check_anonymous_function_declaration (context_p) < PARSER_NAMED_FUNCTION) + { + parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME); + if (has_super_env) + { + parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED); + } + parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_PROPERTY); + } + else + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL); + } + + break; + } + + if (context_p->token.type != LEXER_COLON) + { + parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); + } + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (parser_check_anonymous_function_declaration (context_p) < PARSER_NAMED_FUNCTION) + { + parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME); + } + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL); + } + else + { + parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_PROPERTY); + } + break; + } + case LEXER_THREE_DOTS: + { + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + parser_emit_cbc_ext (context_p, CBC_EXT_COPY_DATA_PROPERTIES); + break; + } + case LEXER_KEYW_ASYNC: + case LEXER_MULTIPLY: + { + uint32_t status_flags = PARSER_FUNCTION_CLOSURE; + + if (context_p->token.type == LEXER_KEYW_ASYNC) + { + status_flags |= PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + lexer_consume_generator (context_p); + } + + if (context_p->token.type == LEXER_MULTIPLY) + { + status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + } + + if (has_super_env) + { + status_flags |= PARSER_ALLOW_SUPER; + } + + lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_ONLY_IDENTIFIERS); + + uint16_t opcode = CBC_SET_LITERAL_PROPERTY; + /* This assignment is a nop for CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL. */ + uint16_t literal_index = context_p->lit_object.index; + bool is_computed = context_p->token.type == LEXER_RIGHT_SQUARE; + + if (is_computed) + { + opcode = CBC_EXT_SET_COMPUTED_PROPERTY; + } + + uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags); + + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); + + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + + if (is_computed) + { + parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME); + if (has_super_env) + { + parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED); + } + parser_emit_cbc_ext (context_p, opcode); + lexer_next_token (context_p); + break; + } + + parser_set_function_name (context_p, function_literal_index, literal_index, status_flags); + + if (has_super_env) + { + parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT); + parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index); + } + else + { + context_p->last_cbc_opcode = opcode; + context_p->last_cbc.value = literal_index; + } + + lexer_next_token (context_p); + break; + } + default: + { + const lexer_lit_location_t *literal_p = (const lexer_lit_location_t *) context_p->lit_object.literal_p; + bool is_proto = ((context_p->token.lit_location.type == LEXER_IDENT_LITERAL + || context_p->token.lit_location.type == LEXER_STRING_LITERAL) + && lexer_compare_identifier_to_string (literal_p, (uint8_t *) "__proto__", 9) + && lexer_check_next_character (context_p, LIT_CHAR_COLON)); + if (is_proto) + { + if (proto_seen) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_PROTO); + } + + proto_seen = true; + } + + uint16_t literal_index = context_p->lit_object.index; + parser_line_counter_t start_line = context_p->token.line; + parser_line_counter_t start_column = context_p->token.column; + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LEFT_PAREN && !is_proto) + { + parser_parse_object_method (context_p); + + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + parser_set_function_name (context_p, context_p->last_cbc.literal_index, literal_index, 0); + + if (has_super_env) + { + parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT); + parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index); + break; + } + + context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY; + context_p->last_cbc.value = literal_index; + break; + } + + if ((context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_COMMA) && !is_proto) + { + parser_reparse_as_common_identifier (context_p, start_line, start_column); + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + + context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY; + context_p->last_cbc.value = literal_index; + + lexer_next_token (context_p); + break; + } + + if (context_p->token.type != LEXER_COLON) + { + parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); + } + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (is_proto) + { + parser_emit_cbc_ext (context_p, CBC_EXT_SET__PROTO__); + break; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + if (context_p->last_cbc.literal_type == LEXER_FUNCTION_LITERAL) + { + parser_set_function_name (context_p, context_p->last_cbc.literal_index, literal_index, 0); + } + context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY; + context_p->last_cbc.value = literal_index; + } + else + { + if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS)) + { + uint16_t name_index = scanner_save_literal (context_p, literal_index); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, name_index); + } + + parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index); + } + + break; + } + } + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + break; + } + else if (context_p->token.type != LEXER_COMMA) + { + parser_raise_error (context_p, PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED); + } + } + + if (has_super_env) + { + parser_emit_cbc_ext (context_p, CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT); + } +} /* parser_parse_object_literal */ + +/** + * Parse function literal. + */ +static void +parser_parse_function_expression (parser_context_t *context_p, /**< context */ + uint32_t status_flags) /**< function status flags */ +{ + int literals = 0; + uint16_t literal1 = 0; + uint16_t literal2 = 0; + uint16_t function_literal_index; + int32_t function_name_index = -1; + + if (status_flags & PARSER_IS_FUNC_EXPRESSION) + { + uint32_t parent_status_flags = context_p->status_flags; + + context_p->status_flags &= + (uint32_t) ~(PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD); + + if (status_flags & PARSER_IS_ASYNC_FUNCTION) + { + /* The name of the function cannot be await. */ + context_p->status_flags |= PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + } + + if (lexer_consume_generator (context_p)) + { + /* The name of the function cannot be yield. */ + context_p->status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + } + + if (!lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + { + /* The `await` keyword is interpreted as an IdentifierReference within function expressions */ + context_p->status_flags &= (uint32_t) ~PARSER_IS_CLASS_STATIC_BLOCK; + + lexer_next_token (context_p); + + context_p->status_flags |= parent_status_flags & PARSER_IS_CLASS_STATIC_BLOCK; + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + parser_flush_cbc (context_p); + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + + if (context_p->token.keyword_type >= LEXER_FIRST_NON_STRICT_ARGUMENTS) + { + status_flags |= PARSER_HAS_NON_STRICT_ARG; + } + + function_name_index = context_p->lit_object.index; + } + + context_p->status_flags = parent_status_flags; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + literals = 1; + literal1 = context_p->last_cbc.literal_index; + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + literals = 2; + literal1 = context_p->last_cbc.literal_index; + literal2 = context_p->last_cbc.value; + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + + function_literal_index = lexer_construct_function_object (context_p, status_flags); + + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + + if (function_name_index != -1) + { + parser_set_function_name (context_p, function_literal_index, (uint16_t) function_name_index, 0); + } + + if (literals == 1) + { + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + context_p->last_cbc.literal_index = literal1; + context_p->last_cbc.value = function_literal_index; + } + else if (literals == 2) + { + context_p->last_cbc_opcode = CBC_PUSH_THREE_LITERALS; + context_p->last_cbc.literal_index = literal1; + context_p->last_cbc.value = literal2; + context_p->last_cbc.third_literal_index = function_literal_index; + } + else + { + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, function_literal_index); + + if (function_name_index != -1) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_NAMED_FUNC_EXPRESSION); + context_p->last_cbc.value = (uint16_t) function_name_index; + } + } + + context_p->last_cbc.literal_type = LEXER_FUNCTION_LITERAL; + context_p->last_cbc.literal_keyword_type = LEXER_EOS; +} /* parser_parse_function_expression */ + +/** + * Parse template literal. + */ +static void +parser_parse_template_literal (parser_context_t *context_p) /**< context */ +{ + bool is_empty_head = true; + + if (context_p->token.lit_location.length > 0) + { + is_empty_head = false; + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); + + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + } + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_RIGHT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED); + } + + if (!is_empty_head) + { + if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_STRING_CONCAT_TWO_LITERALS); + } + else if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL); + } + else + { + parser_emit_cbc_ext (context_p, CBC_EXT_STRING_CONCAT); + } + } + + context_p->source_p--; + context_p->column--; + lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); + + if (is_empty_head || context_p->token.lit_location.length > 0) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_STRING_CONCAT_TWO_LITERALS); + context_p->last_cbc.value = context_p->lit_object.index; + context_p->last_cbc.literal_type = context_p->token.lit_location.type; + context_p->last_cbc.literal_keyword_type = context_p->token.keyword_type; + } + else + { + parser_emit_cbc_ext_literal_from_token (context_p, CBC_EXT_STRING_CONCAT_RIGHT_LITERAL); + } + } + + while (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) + { + lexer_next_token (context_p); + + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_RIGHT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED); + } + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL); + } + else + { + parser_emit_cbc_ext (context_p, CBC_EXT_STRING_CONCAT); + } + + context_p->source_p--; + context_p->column--; + lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); + + if (context_p->token.lit_location.length > 0) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); + + parser_emit_cbc_ext_literal_from_token (context_p, CBC_EXT_STRING_CONCAT_RIGHT_LITERAL); + } + } +} /* parser_parse_template_literal */ + +/** + * Parse tagged template literal. + */ +static size_t +parser_parse_tagged_template_literal (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_TEMPLATE_LITERAL); + + uint32_t call_arguments = 0; + ecma_collection_t *collection_p; + + if (context_p->tagged_template_literal_cp == JMEM_CP_NULL) + { + collection_p = ecma_new_collection (); + ECMA_SET_INTERNAL_VALUE_POINTER (context_p->tagged_template_literal_cp, collection_p); + } + else + { + collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, context_p->tagged_template_literal_cp); + if (collection_p->item_count > CBC_MAXIMUM_BYTE_VALUE) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIMIT_REACHED); + } + } + + const uint32_t tagged_id = collection_p->item_count; + uint32_t prop_idx = 0; + ecma_object_t *raw_strings_p; + ecma_object_t *template_obj_p = parser_new_tagged_template_literal (&raw_strings_p); + ecma_collection_push_back (collection_p, ecma_make_object_value (template_obj_p)); + + parser_tagged_template_literal_append_strings (context_p, template_obj_p, raw_strings_p, prop_idx++); + + call_arguments++; + parser_emit_cbc_ext_call (context_p, CBC_EXT_GET_TAGGED_TEMPLATE_LITERAL, tagged_id); + + while (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) + { + JERRY_ASSERT (context_p->source_p[-1] == LIT_CHAR_LEFT_BRACE); + lexer_next_token (context_p); + + if (++call_arguments > CBC_MAXIMUM_BYTE_VALUE) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIMIT_REACHED); + } + + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_RIGHT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED); + } + + context_p->source_p--; + context_p->column--; + lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); + + parser_tagged_template_literal_append_strings (context_p, template_obj_p, raw_strings_p, prop_idx++); + } + + parser_tagged_template_literal_finalize (template_obj_p, raw_strings_p); + + return call_arguments; +} /* parser_parse_tagged_template_literal */ + +/** + * Checks whether the current expression can be an assignment expression. + * + * @return true if the current expression can be an assignment expression, false otherwise + */ +static inline bool +parser_is_assignment_expr (parser_context_t *context_p) +{ + return (context_p->stack_top_uint8 == LEXER_EXPRESSION_START || context_p->stack_top_uint8 == LEXER_LEFT_PAREN + || context_p->stack_top_uint8 == LEXER_COMMA_SEP_LIST + || LEXER_IS_BINARY_LVALUE_OP_TOKEN (context_p->stack_top_uint8)); +} /* parser_is_assignment_expr */ + +/** + * Throws an error if the current expression is not an assignment expression. + */ +static inline void +parser_check_assignment_expr (parser_context_t *context_p) +{ + if (!parser_is_assignment_expr (context_p)) + { + parser_raise_error (context_p, PARSER_ERR_ASSIGNMENT_EXPECTED); + } +} /* parser_check_assignment_expr */ + +/** + * Checks whether the next token is a valid continuation token after an AssignmentExpression. + */ +static inline bool +parser_abort_parsing_after_assignment_expression (parser_context_t *context_p) +{ + return (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_COMMA); +} /* parser_abort_parsing_after_assignment_expression */ + +/** + * Parse and record unary operators, and parse the primary literal. + * + * @return true if parsing should be aborted, true otherwise + */ +static bool +parser_parse_unary_expression (parser_context_t *context_p, /**< context */ + size_t *grouping_level_p) /**< grouping level */ +{ + bool new_was_seen = false; + + /* Collect unary operators. */ + while (true) + { + /* Convert plus and minus binary operators to unary operators. */ + switch (context_p->token.type) + { + case LEXER_ADD: + { + context_p->token.type = LEXER_PLUS; + break; + } + case LEXER_SUBTRACT: + { + context_p->token.type = LEXER_NEGATE; + break; + } + case LEXER_KEYW_AWAIT: + { +#if JERRY_MODULE_SYSTEM + if ((context_p->global_status_flags & ECMA_PARSE_MODULE) + && !(context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)) + { + parser_raise_error (context_p, PARSER_ERR_AWAIT_NOT_ALLOWED); + } +#endif /* JERRY_MODULE_SYSTEM */ + + if (JERRY_UNLIKELY (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + break; + } + } + + /* Bracketed expressions are primary expressions. At this + * point their left paren is pushed onto the stack and + * they are processed when their closing paren is reached. */ + if (context_p->token.type == LEXER_LEFT_PAREN) + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + break; + } + (*grouping_level_p) += PARSER_GROUPING_LEVEL_INCREASE; + new_was_seen = false; + } + else if (context_p->token.type == LEXER_KEYW_NEW) + { + /* After 'new' unary operators are not allowed. */ + new_was_seen = true; + + /* Check if "new.target" is written here. */ + if (scanner_try_scan_new_target (context_p)) + { + if (!(context_p->status_flags & PARSER_ALLOW_NEW_TARGET)) + { + parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_NOT_ALLOWED); + } + + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_NEW_TARGET); + lexer_next_token (context_p); + /* Found "new.target" return here */ + return false; + } + } + else if (new_was_seen || (*grouping_level_p == PARSE_EXPR_LEFT_HAND_SIDE) + || !LEXER_IS_UNARY_OP_TOKEN (context_p->token.type)) + { + break; + } + + parser_stack_push_uint8 (context_p, context_p->token.type); + lexer_next_token (context_p); + } + + /* Parse primary expression. */ + switch (context_p->token.type) + { + case LEXER_HASHMARK: + { + if (!lexer_scan_private_identifier (context_p)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CHARACTER); + } + + parser_resolve_private_identifier (context_p); + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_KEYW_IN) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CHARACTER); + } + + parser_stack_push_uint16 (context_p, context_p->lit_object.index); + parser_stack_push_uint8 (context_p, LEXER_PRIVATE_PRIMARY_EXPR); + return false; + } + case LEXER_TEMPLATE_LITERAL: + { + if (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) + { + parser_parse_template_literal (context_p); + break; + } + + /* The string is a normal string literal. */ + /* FALLTHRU */ + } + case LEXER_LITERAL: + { + if (JERRY_UNLIKELY (context_p->next_scanner_info_p->source_p == context_p->source_p)) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + + uint32_t arrow_status_flags = + (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION + | (context_p->status_flags & (PARSER_INSIDE_CLASS_FIELD | PARSER_IS_CLASS_STATIC_BLOCK))); + + if (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_ASYNC) + { + JERRY_ASSERT (lexer_token_is_async (context_p)); + JERRY_ASSERT (!(context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_STATEMENT)); + + uint32_t saved_status_flags = context_p->status_flags; + + context_p->status_flags |= PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + lexer_next_token (context_p); + context_p->status_flags = saved_status_flags; + + if (context_p->token.type == LEXER_KEYW_FUNCTION) + { + uint32_t status_flags = (PARSER_FUNCTION_CLOSURE | PARSER_IS_FUNC_EXPRESSION | PARSER_IS_ASYNC_FUNCTION + | PARSER_DISALLOW_AWAIT_YIELD); + parser_parse_function_expression (context_p, status_flags); + break; + } + + arrow_status_flags = + (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD); + } + + parser_check_assignment_expr (context_p); + parser_parse_function_expression (context_p, arrow_status_flags); + return parser_abort_parsing_after_assignment_expression (context_p); + } + + uint8_t type = context_p->token.lit_location.type; + + if (type == LEXER_IDENT_LITERAL || type == LEXER_STRING_LITERAL) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, context_p->token.lit_location.type); + } + else if (type == LEXER_NUMBER_LITERAL) + { + bool is_negative_number = false; + + if ((context_p->stack_top_uint8 == LEXER_PLUS || context_p->stack_top_uint8 == LEXER_NEGATE) + && !lexer_check_post_primary_exp (context_p)) + { + do + { + if (context_p->stack_top_uint8 == LEXER_NEGATE) + { + is_negative_number = !is_negative_number; + } +#if JERRY_BUILTIN_BIGINT + else if (JERRY_LIKELY (context_p->token.extra_value == LEXER_NUMBER_BIGINT)) + { + break; + } +#endif /* JERRY_BUILTIN_BIGINT */ + parser_stack_pop_uint8 (context_p); + } while (context_p->stack_top_uint8 == LEXER_PLUS || context_p->stack_top_uint8 == LEXER_NEGATE); + } + + if (lexer_construct_number_object (context_p, true, is_negative_number)) + { + JERRY_ASSERT (context_p->lit_object.index <= CBC_PUSH_NUMBER_BYTE_RANGE_END); + + parser_emit_cbc_push_number (context_p, is_negative_number); + break; + } + } + + cbc_opcode_t opcode = CBC_PUSH_LITERAL; + + if (context_p->token.keyword_type != LEXER_KEYW_EVAL) + { + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + context_p->last_cbc.value = context_p->lit_object.index; + context_p->last_cbc.literal_type = context_p->token.lit_location.type; + context_p->last_cbc.literal_keyword_type = context_p->token.keyword_type; + break; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + context_p->last_cbc_opcode = CBC_PUSH_THREE_LITERALS; + context_p->last_cbc.third_literal_index = context_p->lit_object.index; + context_p->last_cbc.literal_type = context_p->token.lit_location.type; + context_p->last_cbc.literal_keyword_type = context_p->token.keyword_type; + break; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_THIS) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_PUSH_THIS_LITERAL; + } + } + + parser_emit_cbc_literal_from_token (context_p, (uint16_t) opcode); + break; + } + case LEXER_KEYW_FUNCTION: + { + parser_parse_function_expression (context_p, PARSER_FUNCTION_CLOSURE | PARSER_IS_FUNC_EXPRESSION); + break; + } + case LEXER_LEFT_BRACE: + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER) + { + if (parser_is_assignment_expr (context_p)) + { + uint32_t flags = PARSER_PATTERN_NO_OPTS; + + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags |= PARSER_PATTERN_HAS_REST_ELEMENT; + } + + parser_parse_object_initializer (context_p, (parser_pattern_flags_t) flags); + return parser_abort_parsing_after_assignment_expression (context_p); + } + + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + } + + parser_parse_object_literal (context_p); + break; + } + case LEXER_LEFT_SQUARE: + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER) + { + if (parser_is_assignment_expr (context_p)) + { + parser_parse_array_initializer (context_p, PARSER_PATTERN_NO_OPTS); + return parser_abort_parsing_after_assignment_expression (context_p); + } + + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + } + else + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS + && context_p->next_scanner_info_p->u8_arg == SCANNER_LITERAL_NO_DESTRUCTURING); + + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + } + + parser_parse_array_literal (context_p); + break; + } + case LEXER_DIVIDE: + case LEXER_ASSIGN_DIVIDE: + { + lexer_construct_regexp_object (context_p, false); + uint16_t literal_index = (uint16_t) (context_p->literal_count - 1); + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + context_p->last_cbc.value = literal_index; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + context_p->last_cbc_opcode = CBC_PUSH_THREE_LITERALS; + context_p->last_cbc.third_literal_index = literal_index; + } + else + { + parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, literal_index); + } + + context_p->last_cbc.literal_type = LEXER_REGEXP_LITERAL; + context_p->last_cbc.literal_keyword_type = LEXER_EOS; + break; + } + case LEXER_KEYW_THIS: + { + if (context_p->status_flags & PARSER_ALLOW_SUPER_CALL) + { + parser_emit_cbc_ext (context_p, CBC_EXT_RESOLVE_LEXICAL_THIS); + } + else + { + parser_emit_cbc (context_p, CBC_PUSH_THIS); + } + + break; + } + case LEXER_LIT_TRUE: + { + parser_emit_cbc (context_p, CBC_PUSH_TRUE); + break; + } + case LEXER_LIT_FALSE: + { + parser_emit_cbc (context_p, CBC_PUSH_FALSE); + break; + } + case LEXER_LIT_NULL: + { + parser_emit_cbc (context_p, CBC_PUSH_NULL); + break; + } + case LEXER_KEYW_CLASS: + { + parser_parse_class (context_p, false); + return false; + } + case LEXER_KEYW_SUPER: + { + if (context_p->status_flags & PARSER_ALLOW_SUPER) + { + if (lexer_check_next_characters (context_p, LIT_CHAR_DOT, LIT_CHAR_LEFT_SQUARE)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER); + break; + } + + if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN) + && (context_p->status_flags & PARSER_ALLOW_SUPER_CALL)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER_CONSTRUCTOR); + break; + } + } + + parser_raise_error (context_p, PARSER_ERR_UNEXPECTED_SUPER_KEYWORD); + } + case LEXER_LEFT_PAREN: + { + JERRY_ASSERT (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + + parser_check_assignment_expr (context_p); + + uint32_t arrow_status_flags = + (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION + | (context_p->status_flags & (PARSER_INSIDE_CLASS_FIELD | PARSER_IS_CLASS_STATIC_BLOCK))); + parser_parse_function_expression (context_p, arrow_status_flags); + return parser_abort_parsing_after_assignment_expression (context_p); + } + case LEXER_KEYW_YIELD: + { + JERRY_ASSERT ((context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) + && !(context_p->status_flags & PARSER_DISALLOW_AWAIT_YIELD)); + + if (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + + parser_check_assignment_expr (context_p); + lexer_next_token (context_p); + + cbc_ext_opcode_t opcode = + ((context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) ? CBC_EXT_ASYNC_YIELD : CBC_EXT_YIELD); + if (!lexer_check_yield_no_arg (context_p)) + { + if (context_p->token.type == LEXER_MULTIPLY) + { + lexer_next_token (context_p); + opcode = ((context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) ? CBC_EXT_ASYNC_YIELD_ITERATOR + : CBC_EXT_YIELD_ITERATOR); + } + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + } + else + { + parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED); + } + + parser_emit_cbc_ext (context_p, opcode); + + return (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_COMMA); + } +#if JERRY_MODULE_SYSTEM + case LEXER_KEYW_IMPORT: + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_DOT) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL + || context_p->token.keyword_type != LEXER_KEYW_META + || (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + parser_raise_error (context_p, PARSER_ERR_META_EXPECTED); + } + + if (!(context_p->global_status_flags & ECMA_PARSE_MODULE)) + { + parser_raise_error (context_p, PARSER_ERR_IMPORT_META_REQUIRE_MODULE); + } + + JERRY_ASSERT (context_p->global_status_flags & ECMA_PARSE_INTERNAL_HAS_IMPORT_META); + + parser_emit_cbc_ext (context_p, CBC_EXT_MODULE_IMPORT_META); + break; + } + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED); + } + + if (new_was_seen) + { + parser_raise_error (context_p, PARSER_ERR_IMPORT_AFTER_NEW); + } + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + parser_emit_cbc_ext (context_p, CBC_EXT_MODULE_IMPORT); + break; + } +#endif /* JERRY_MODULE_SYSTEM */ + default: + { + bool is_left_hand_side = (*grouping_level_p == PARSE_EXPR_LEFT_HAND_SIDE); + parser_raise_error (context_p, + (is_left_hand_side ? PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED : PARSER_ERR_UNEXPECTED_END)); + break; + } + } + lexer_next_token (context_p); + return false; +} /* parser_parse_unary_expression */ + +/** + * Parse the postfix part of unary operators, and + * generate byte code for the whole expression. + */ +static void +parser_process_unary_expression (parser_context_t *context_p, /**< context */ + size_t grouping_level) /**< grouping level */ +{ + /* Parse postfix part of a primary expression. */ + while (true) + { + /* Since break would only break the switch, we use + * continue to continue this loop. Without continue, + * the code abandons the loop. */ + switch (context_p->token.type) + { + case LEXER_DOT: + { + parser_push_result (context_p); + + if (lexer_check_next_character (context_p, LIT_CHAR_HASHMARK)) + { + lexer_next_token (context_p); + + if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER)) + { + parser_raise_error (context_p, PARSER_ERR_UNEXPECTED_PRIVATE_FIELD); + } + + if (!lexer_scan_private_identifier (context_p)) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + parser_resolve_private_identifier (context_p); + + parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_PRIVATE_PROP_LITERAL, context_p->lit_object.index); + lexer_next_token (context_p); + continue; + } + + lexer_expect_identifier (context_p, LEXER_STRING_LITERAL); + + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL + && context_p->lit_object.literal_p->type == LEXER_STRING_LITERAL); + context_p->token.lit_location.type = LEXER_STRING_LITERAL; + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + JERRY_ASSERT (CBC_ARGS_EQ (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + context_p->last_cbc_opcode = CBC_PUSH_PROP_LITERAL_LITERAL; + context_p->last_cbc.value = context_p->lit_object.index; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_THIS) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_THIS_LITERAL); + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER)) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL); + context_p->last_cbc.literal_index = context_p->lit_object.index; + } + else + { + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_LITERAL); + } + lexer_next_token (context_p); + continue; + } + + case LEXER_LEFT_SQUARE: + { + parser_push_result (context_p); + + uint16_t last_cbc_opcode = context_p->last_cbc_opcode; + + if (last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER)) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR); + if (context_p->token.type != LEXER_RIGHT_SQUARE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_SQUARE_EXPECTED); + } + lexer_next_token (context_p); + + if (last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER_PROP); + continue; + } + + if (PARSER_IS_MUTABLE_PUSH_LITERAL (context_p->last_cbc_opcode)) + { + context_p->last_cbc_opcode = PARSER_PUSH_LITERAL_TO_PUSH_PROP_LITERAL (context_p->last_cbc_opcode); + } + else + { + parser_emit_cbc (context_p, CBC_PUSH_PROP); + } + continue; + } + case LEXER_TEMPLATE_LITERAL: + case LEXER_LEFT_PAREN: + { + size_t call_arguments = 0; + uint16_t opcode = CBC_CALL; + bool is_eval = false; + + parser_push_result (context_p); + + if (context_p->stack_top_uint8 == LEXER_KEYW_NEW) + { + if (context_p->token.type == LEXER_LEFT_PAREN) + { + parser_stack_pop_uint8 (context_p); + opcode = CBC_NEW; + } + } + else + { + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL + && context_p->last_cbc.literal_keyword_type == LEXER_KEYW_EVAL + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + is_eval = true; + } + + if (PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode)) + { + opcode = CBC_CALL_PROP; + context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_opcode); + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR)) + { + opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL); + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL)) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE); + opcode = CBC_CALL_PROP; + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP)) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE); + opcode = CBC_CALL_PROP; + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL)) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE); + opcode = CBC_CALL_PROP; + } + else if (JERRY_UNLIKELY (context_p->status_flags & PARSER_INSIDE_WITH) + && PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + opcode = CBC_CALL_PROP; + parser_emit_ident_reference (context_p, CBC_PUSH_IDENT_REFERENCE); + parser_emit_cbc_ext (context_p, CBC_EXT_RESOLVE_BASE); + } + } + + bool has_spread_element = false; + + if (context_p->token.type == LEXER_TEMPLATE_LITERAL) + { + call_arguments = parser_parse_tagged_template_literal (context_p); + } + else + { + lexer_next_token (context_p); + + while (context_p->token.type != LEXER_RIGHT_PAREN) + { + if (++call_arguments > CBC_MAXIMUM_BYTE_VALUE) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIMIT_REACHED); + } + + if (context_p->token.type == LEXER_THREE_DOTS) + { + has_spread_element = true; + call_arguments++; + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SPREAD_ELEMENT); + lexer_next_token (context_p); + } + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (context_p->token.type == LEXER_COMMA) + { + lexer_next_token (context_p); + continue; + } + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + break; + } + } + + lexer_next_token (context_p); + + if (is_eval) + { + context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED; + + uint16_t eval_flags = PARSER_SAVE_STATUS_FLAGS (context_p->status_flags); + const uint32_t required_flags = PARSER_IS_FUNCTION | PARSER_LEXICAL_BLOCK_NEEDED; + + if (context_p->status_flags & PARSER_FUNCTION_IS_PARSING_ARGS) + { + context_p->status_flags |= PARSER_LEXICAL_BLOCK_NEEDED; + } + else if (((context_p->status_flags & (required_flags | PARSER_IS_STRICT)) == required_flags) + || ((context_p->global_status_flags & ECMA_PARSE_FUNCTION_CONTEXT) + && !(context_p->status_flags & PARSER_IS_FUNCTION))) + { + eval_flags |= PARSER_GET_EVAL_FLAG (ECMA_PARSE_FUNCTION_CONTEXT); + } + + if (eval_flags != 0) + { + parser_emit_cbc_ext_call (context_p, CBC_EXT_LOCAL_EVAL, eval_flags); + } + else + { + parser_emit_cbc (context_p, CBC_EVAL); + } + } + + if (has_spread_element) + { + uint16_t spread_opcode; + + if (opcode == CBC_CALL) + { + spread_opcode = CBC_EXT_SPREAD_CALL; + } + else if (opcode == CBC_CALL_PROP) + { + spread_opcode = CBC_EXT_SPREAD_CALL_PROP; + } + else if (opcode == CBC_NEW) + { + spread_opcode = CBC_EXT_SPREAD_NEW; + } + else + { + /* opcode is unchanged */ + JERRY_ASSERT (opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL)); + spread_opcode = CBC_EXT_SPREAD_SUPER_CALL; + } + + parser_emit_cbc_ext_call (context_p, spread_opcode, call_arguments); + continue; + } + + if (call_arguments <= 1) + { + if (opcode == CBC_CALL) + { + parser_emit_cbc (context_p, (uint16_t) (CBC_CALL0 + (call_arguments * 6))); + continue; + } + if (opcode == CBC_CALL_PROP) + { + parser_emit_cbc (context_p, (uint16_t) (CBC_CALL0_PROP + (call_arguments * 6))); + continue; + } + if (opcode == CBC_NEW) + { + parser_emit_cbc (context_p, (uint16_t) (CBC_NEW0 + call_arguments)); + continue; + } + } + else if (call_arguments == 2) + { + if (opcode == CBC_CALL) + { + parser_emit_cbc (context_p, CBC_CALL2); + continue; + } + if (opcode == CBC_CALL_PROP) + { + parser_flush_cbc (context_p); + /* Manually adjusting stack usage. */ + JERRY_ASSERT (context_p->stack_depth > 0); + context_p->stack_depth--; + parser_emit_cbc (context_p, CBC_CALL2_PROP); + continue; + } + } + + parser_emit_cbc_call (context_p, opcode, call_arguments); + continue; + } + default: + { + if (context_p->stack_top_uint8 == LEXER_KEYW_NEW) + { + parser_push_result (context_p); + parser_emit_cbc (context_p, CBC_NEW0); + parser_stack_pop_uint8 (context_p); + continue; + } + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) + && (context_p->token.type == LEXER_INCREASE || context_p->token.type == LEXER_DECREASE) + && grouping_level != PARSE_EXPR_LEFT_HAND_SIDE) + { + cbc_opcode_t opcode = (context_p->token.type == LEXER_INCREASE) ? CBC_POST_INCR : CBC_POST_DECR; + parser_push_result (context_p); + parser_emit_unary_lvalue_opcode (context_p, opcode); + lexer_next_token (context_p); + } + break; + } + } + break; + } + + uint8_t last_unary_token = LEXER_INCREASE; + + /* Generate byte code for the unary operators. */ + while (true) + { + uint8_t token = context_p->stack_top_uint8; + if (!LEXER_IS_UNARY_OP_TOKEN (token)) + { + if (context_p->token.type == LEXER_EXPONENTIATION && last_unary_token != LEXER_INCREASE + && last_unary_token != LEXER_DECREASE) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_EXPONENTIATION); + } + + break; + } + + last_unary_token = token; + parser_push_result (context_p); + parser_stack_pop_uint8 (context_p); + + if (LEXER_IS_UNARY_LVALUE_OP_TOKEN (token)) + { + if (token == LEXER_KEYW_DELETE) + { + token = CBC_DELETE_PUSH_RESULT; + } + else + { + token = (uint8_t) (LEXER_UNARY_LVALUE_OP_TOKEN_TO_OPCODE (token)); + } + parser_emit_unary_lvalue_opcode (context_p, (cbc_opcode_t) token); + } + else if (JERRY_UNLIKELY (token == LEXER_KEYW_AWAIT)) + { + cbc_ext_opcode_t opcode = + ((context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) ? CBC_EXT_GENERATOR_AWAIT : CBC_EXT_AWAIT); + parser_emit_cbc_ext (context_p, opcode); + } + else + { + token = (uint8_t) (LEXER_UNARY_OP_TOKEN_TO_OPCODE (token)); + + if (token == CBC_TYPEOF) + { + if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + parser_emit_ident_reference (context_p, CBC_TYPEOF_IDENT); + } + else + { + parser_emit_cbc (context_p, token); + } + } + else + { + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + /* It is not worth to combine with push multiple literals + * since the byte code size will not decrease. */ + JERRY_ASSERT (CBC_SAME_ARGS (context_p->last_cbc_opcode, token + 1)); + context_p->last_cbc_opcode = (uint16_t) (token + 1); + } + else + { + parser_emit_cbc (context_p, token); + } + } + } + } +} /* parser_process_unary_expression */ + +/** + * Append a binary '=' token. + * + * @return - pushed assignment opcode onto the parser stack + */ +static void +parser_append_binary_single_assignment_token (parser_context_t *context_p, /**< context */ + uint32_t pattern_flags) /**< pattern flags */ +{ + JERRY_UNUSED (pattern_flags); + + /* Unlike other tokens, the whole byte code is saved for binary + * assignment, since it has multiple forms depending on the + * previous instruction. */ + + uint8_t assign_opcode = CBC_ASSIGN; + + if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + parser_check_invalid_assign (context_p); + + uint16_t literal_index; + + switch (context_p->last_cbc_opcode) + { + case CBC_PUSH_LITERAL: + { + literal_index = context_p->last_cbc.literal_index; + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + break; + } + case CBC_PUSH_TWO_LITERALS: + { + literal_index = context_p->last_cbc.value; + context_p->last_cbc_opcode = CBC_PUSH_LITERAL; + break; + } + case CBC_PUSH_THIS_LITERAL: + { + literal_index = context_p->last_cbc.literal_index; + context_p->last_cbc_opcode = CBC_PUSH_THIS; + parser_flush_cbc (context_p); + break; + } + default: + { + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_THREE_LITERALS); + literal_index = context_p->last_cbc.third_literal_index; + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + break; + } + } + + assign_opcode = CBC_ASSIGN_SET_IDENT; + + if (!(pattern_flags & (PARSER_PATTERN_LET | PARSER_PATTERN_CONST | PARSER_PATTERN_LOCAL))) + { + if (scanner_literal_is_const_reg (context_p, literal_index)) + { + parser_stack_push_uint8 (context_p, LEXER_ASSIGN_CONST); + } + } + else if (literal_index < PARSER_REGISTER_START) + { + assign_opcode = CBC_INIT_LET; + + if (scanner_literal_is_created (context_p, literal_index)) + { + assign_opcode = CBC_ASSIGN_LET_CONST; + } + else if (pattern_flags & PARSER_PATTERN_CONST) + { + assign_opcode = CBC_INIT_CONST; + } + else if (pattern_flags & PARSER_PATTERN_LOCAL) + { + assign_opcode = CBC_INIT_ARG_OR_CATCH; + } + } + + parser_stack_push_uint16 (context_p, literal_index); + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_LITERAL, assign_opcode)); + } + else if (context_p->last_cbc_opcode == CBC_PUSH_PROP) + { + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP, CBC_ASSIGN)); + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_PROP_LITERAL) + { + if (context_p->last_cbc.literal_type != LEXER_IDENT_LITERAL) + { + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP_LITERAL, CBC_ASSIGN_PROP_LITERAL)); + parser_stack_push_uint16 (context_p, context_p->last_cbc.literal_index); + assign_opcode = CBC_ASSIGN_PROP_LITERAL; + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + else + { + context_p->last_cbc_opcode = CBC_PUSH_LITERAL; + } + } + else if (context_p->last_cbc_opcode == CBC_PUSH_PROP_LITERAL_LITERAL) + { + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_PUSH_TWO_LITERALS)); + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_PROP_THIS_LITERAL) + { + if (context_p->last_cbc.literal_type != LEXER_IDENT_LITERAL) + { + JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP_THIS_LITERAL, CBC_ASSIGN_PROP_THIS_LITERAL)); + parser_stack_push_uint16 (context_p, context_p->last_cbc.literal_index); + assign_opcode = CBC_ASSIGN_PROP_THIS_LITERAL; + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + else + { + context_p->last_cbc_opcode = CBC_PUSH_THIS_LITERAL; + } + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL)) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE); + parser_stack_push_uint8 (context_p, CBC_EXT_ASSIGN_SUPER); + assign_opcode = CBC_EXT_OPCODE; + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP)) + { + context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE); + parser_stack_push_uint8 (context_p, CBC_EXT_ASSIGN_SUPER); + assign_opcode = CBC_EXT_OPCODE; + } + else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL)) + { + context_p->last_cbc_opcode = CBC_PUSH_LITERAL; + parser_stack_push_uint8 (context_p, CBC_EXT_ASSIGN_PRIVATE); + assign_opcode = CBC_EXT_OPCODE; + } + else + { + /* Invalid LeftHandSide expression. */ // 3820, 3815 + parser_check_invalid_new_target (context_p, CBC_ASSIGN); + parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT); + } + + parser_stack_push_uint8 (context_p, assign_opcode); + parser_stack_push_uint8 (context_p, LEXER_ASSIGN); +} /* parser_append_binary_single_assignment_token */ + +/** + * Check for invalid chain of logical operators + */ +static void +parser_check_invalid_logical_op (parser_context_t *context_p, /**< context */ + uint8_t invalid_token1, /**< token id of first invalid token */ + uint8_t invalid_token2) /**< token id of second invalid token */ +{ + parser_stack_iterator_t iterator; + parser_stack_iterator_init (context_p, &iterator); + + while (true) + { + uint8_t token = parser_stack_iterator_read_uint8 (&iterator); + + if (!LEXER_IS_BINARY_NON_LVALUE_OP_TOKEN (token)) + { + return; + } + + if (token == invalid_token1 || token == invalid_token2) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_NULLISH_COALESCING); + } + + /* If a logical operator is found, and there is no SyntaxError, the scan can be terminated + * since there was no SyntaxError when the logical operator was pushed onto the stack. */ + if (token == LEXER_LOGICAL_OR || token == LEXER_LOGICAL_AND || token == LEXER_NULLISH_COALESCING) + { + return; + } + + parser_stack_iterator_skip (&iterator, sizeof (uint8_t)); + } +} /* parser_check_invalid_logical_op */ + +/** + * Append a binary lvalue token. + */ +static void +parser_append_binary_lvalue_token (parser_context_t *context_p, /**< context */ + bool is_logical_assignment) /**< true - if form logical assignment reference + * false - otherwise */ +{ + if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + parser_check_invalid_assign (context_p); + + parser_emit_ident_reference (context_p, CBC_PUSH_IDENT_REFERENCE); + + if (!is_logical_assignment && scanner_literal_is_const_reg (context_p, context_p->last_cbc.literal_index)) + { + parser_stack_push_uint8 (context_p, LEXER_ASSIGN_CONST); + } + } + else if (PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode)) + { + context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_opcode); + } + else + { + /* Invalid LeftHandSide expression. */ + parser_check_invalid_new_target (context_p, CBC_ASSIGN); + parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT); + parser_emit_cbc (context_p, CBC_PUSH_PROP_REFERENCE); + } + + if (!is_logical_assignment) + { + parser_stack_push_uint8 (context_p, (uint8_t) context_p->token.type); + } +} /* parser_append_binary_lvalue_token */ + +/** + * Append a logical token. + */ +static void +parser_append_logical_token (parser_context_t *context_p, /**< context */ + uint16_t opcode) /**< opcode */ +{ + if (opcode != PARSER_TO_EXT_OPCODE (CBC_EXT_BRANCH_IF_NULLISH)) + { + parser_check_invalid_logical_op (context_p, LEXER_NULLISH_COALESCING, LEXER_NULLISH_COALESCING); + } + + parser_branch_t branch; + parser_emit_cbc_forward_branch (context_p, opcode, &branch); + parser_stack_push (context_p, &branch, sizeof (parser_branch_t)); + parser_stack_push_uint8 (context_p, (uint8_t) context_p->token.type); +} /* parser_append_logical_token */ + +/** + * Append a logical token. + */ +static void +parser_append_logical_assignment_token (parser_context_t *context_p, /**< context */ + uint16_t opcode) /**< opcode */ +{ + uint16_t last_cbc_opcode = context_p->last_cbc_opcode; + parser_append_binary_single_assignment_token (context_p, 0); + parser_stack_change_last_uint8 (context_p, LEXER_ASSIGN_REFERENCE); + context_p->last_cbc_opcode = last_cbc_opcode; + + parser_append_binary_lvalue_token (context_p, true); + parser_append_logical_token (context_p, opcode); +} /* parser_append_logical_assignment_token */ + +/** + * Append a binary token. + */ +static void +parser_append_binary_token (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (LEXER_IS_BINARY_OP_TOKEN (context_p->token.type)); + parser_push_result (context_p); + + switch (context_p->token.type) + { + case LEXER_ASSIGN: + { + parser_append_binary_single_assignment_token (context_p, 0); + break; + } + /* Binary lvalue-opcodes */ + case LEXER_ASSIGN_ADD: + case LEXER_ASSIGN_SUBTRACT: + case LEXER_ASSIGN_MULTIPLY: + case LEXER_ASSIGN_DIVIDE: + case LEXER_ASSIGN_MODULO: + case LEXER_ASSIGN_EXPONENTIATION: + case LEXER_ASSIGN_LEFT_SHIFT: + case LEXER_ASSIGN_RIGHT_SHIFT: + case LEXER_ASSIGN_UNS_RIGHT_SHIFT: + case LEXER_ASSIGN_BIT_AND: + case LEXER_ASSIGN_BIT_OR: + case LEXER_ASSIGN_BIT_XOR: + { + parser_append_binary_lvalue_token (context_p, false); + break; + } + case LEXER_ASSIGN_NULLISH_COALESCING: + { + parser_append_logical_assignment_token (context_p, PARSER_TO_EXT_OPCODE (CBC_EXT_BRANCH_IF_NULLISH)); + break; + } + case LEXER_ASSIGN_LOGICAL_OR: + { + parser_append_logical_assignment_token (context_p, CBC_BRANCH_IF_LOGICAL_TRUE); + break; + } + case LEXER_ASSIGN_LOGICAL_AND: + { + parser_append_logical_assignment_token (context_p, CBC_BRANCH_IF_LOGICAL_FALSE); + break; + } + case LEXER_NULLISH_COALESCING: + { + parser_append_logical_token (context_p, PARSER_TO_EXT_OPCODE (CBC_EXT_BRANCH_IF_NULLISH)); + break; + } + case LEXER_LOGICAL_OR: + { + parser_append_logical_token (context_p, CBC_BRANCH_IF_LOGICAL_TRUE); + break; + } + case LEXER_LOGICAL_AND: + { + parser_append_logical_token (context_p, CBC_BRANCH_IF_LOGICAL_FALSE); + break; + } + default: + { + parser_stack_push_uint8 (context_p, (uint8_t) context_p->token.type); + break; + } + } +} /* parser_append_binary_token */ + +/** + * Emit opcode for binary assignment token. + */ +static void +parser_process_binary_assignment_token (parser_context_t *context_p, /**< context */ + uint8_t token) /**< token */ +{ + uint16_t index = PARSER_INVALID_LITERAL_INDEX; + uint16_t opcode = context_p->stack_top_uint8; + + if (JERRY_UNLIKELY (opcode == CBC_EXT_OPCODE)) + { + parser_stack_pop_uint8 (context_p); + JERRY_ASSERT (context_p->stack_top_uint8 == CBC_EXT_ASSIGN_SUPER + || context_p->stack_top_uint8 == CBC_EXT_ASSIGN_PRIVATE); + opcode = PARSER_TO_EXT_OPCODE (context_p->stack_top_uint8); + parser_stack_pop_uint8 (context_p); + } + else + { + parser_stack_pop_uint8 (context_p); + + if (cbc_flags[opcode] & CBC_HAS_LITERAL_ARG) + { + JERRY_ASSERT (opcode == CBC_ASSIGN_SET_IDENT || opcode == CBC_ASSIGN_PROP_LITERAL + || opcode == CBC_ASSIGN_PROP_THIS_LITERAL || opcode == CBC_ASSIGN_LET_CONST + || opcode == CBC_INIT_ARG_OR_CATCH || opcode == CBC_INIT_LET || opcode == CBC_INIT_CONST); + + index = parser_stack_pop_uint16 (context_p); + } + } + + bool group_expr_assignment = false; + + if (JERRY_UNLIKELY (context_p->stack_top_uint8 == LEXER_ASSIGN_GROUP_EXPR)) + { + group_expr_assignment = true; + parser_stack_pop_uint8 (context_p); + } + + if (JERRY_UNLIKELY (context_p->stack_top_uint8 == LEXER_ASSIGN_CONST)) + { + parser_stack_pop_uint8 (context_p); + parser_emit_cbc_ext (context_p, CBC_EXT_THROW_ASSIGN_CONST_ERROR); + } + + if (index == PARSER_INVALID_LITERAL_INDEX) + { + if (JERRY_UNLIKELY (token == LEXER_ASSIGN_REFERENCE)) + { + opcode = CBC_ASSIGN_PUSH_RESULT; + } + + parser_emit_cbc (context_p, opcode); + return; + } + + if (!group_expr_assignment) + { + uint16_t function_literal_index = parser_check_anonymous_function_declaration (context_p); + + if (function_literal_index == PARSER_ANONYMOUS_CLASS) + { + uint16_t name_index = scanner_save_literal (context_p, index); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, name_index); + } + else if (function_literal_index < PARSER_NAMED_FUNCTION) + { + parser_set_function_name (context_p, function_literal_index, (uint16_t) index, 0); + } + } + + if (JERRY_UNLIKELY (token == LEXER_ASSIGN_REFERENCE)) + { + parser_emit_cbc (context_p, CBC_ASSIGN_PUSH_RESULT); + return; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL && opcode == CBC_ASSIGN_SET_IDENT) + { + JERRY_ASSERT (CBC_ARGS_EQ (CBC_ASSIGN_LITERAL_SET_IDENT, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + + context_p->last_cbc.value = index; + context_p->last_cbc_opcode = CBC_ASSIGN_LITERAL_SET_IDENT; + return; + } + + parser_emit_cbc_literal (context_p, (uint16_t) opcode, index); + + if (opcode == CBC_ASSIGN_PROP_THIS_LITERAL && (context_p->stack_depth >= context_p->stack_limit)) + { + /* Stack limit is increased for VM_OC_ASSIGN_PROP_THIS. Needed by vm.c. */ + JERRY_ASSERT (context_p->stack_depth == context_p->stack_limit); + + context_p->stack_limit++; + + if (context_p->stack_limit > PARSER_MAXIMUM_STACK_LIMIT) + { + parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED); + } + } +} /* parser_process_binary_opcodes */ + +/** + * Emit opcode for logical tokens. + */ +static void +parser_process_logical_token (parser_context_t *context_p) /**< context */ +{ + parser_branch_t branch; + parser_stack_pop (context_p, &branch, sizeof (parser_branch_t)); + parser_set_branch_to_current_position (context_p, &branch); +} /* parser_process_logical_token */ + +/** + * Emit opcode for logical assignment tokens. + */ +static void +parser_process_logical_assignment_token (parser_context_t *context_p) /**< context */ +{ + parser_branch_t condition_branch; + parser_stack_pop (context_p, &condition_branch, sizeof (parser_branch_t)); + + uint8_t token = context_p->stack_top_uint8; + JERRY_ASSERT (token == LEXER_ASSIGN_REFERENCE); + parser_stack_pop_uint8 (context_p); + parser_process_binary_assignment_token (context_p, token); + + parser_branch_t prop_reference_branch; + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &prop_reference_branch); + + parser_set_branch_to_current_position (context_p, &condition_branch); + parser_emit_cbc_ext (context_p, CBC_EXT_POP_REFERENCE); + + JERRY_ASSERT (context_p->stack_limit - context_p->stack_depth >= 2); + PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, 2); + + parser_set_branch_to_current_position (context_p, &prop_reference_branch); +} /* parser_process_logical_assignment_token */ + +/** + * Emit opcode for binary tokens. + */ +static void +parser_process_binary_token (parser_context_t *context_p, /**< context */ + uint8_t token) /**< token */ +{ + uint16_t opcode = LEXER_BINARY_OP_TOKEN_TO_OPCODE (token); + + if (PARSER_IS_PUSH_NUMBER (context_p->last_cbc_opcode)) + { + lexer_convert_push_number_to_push_literal (context_p); + } + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + JERRY_ASSERT (CBC_SAME_ARGS (context_p->last_cbc_opcode, opcode + CBC_BINARY_WITH_LITERAL)); + context_p->last_cbc_opcode = (uint16_t) (opcode + CBC_BINARY_WITH_LITERAL); + return; + } + + if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + JERRY_ASSERT (CBC_ARGS_EQ (opcode + CBC_BINARY_WITH_TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + context_p->last_cbc_opcode = (uint16_t) (opcode + CBC_BINARY_WITH_TWO_LITERALS); + return; + } + + parser_emit_cbc (context_p, opcode); +} /* parser_process_binary_token */ + +/** + * Emit opcode for binary lvalue tokens. + */ +static void +parser_process_binary_lvalue_token (parser_context_t *context_p, /**< context */ + uint8_t token) /**< token */ +{ + parser_stack_push_uint8 (context_p, CBC_ASSIGN); + parser_stack_push_uint8 (context_p, LEXER_ASSIGN); + parser_stack_push_uint8 (context_p, lexer_convert_binary_lvalue_token_to_binary (token)); +} /* parser_process_binary_lvalue_token */ + +/** + * Emit opcode for binary computations. + */ +static void +parser_process_binary_opcodes (parser_context_t *context_p, /**< context */ + uint8_t min_prec_threshhold) /**< minimal precedence of tokens */ +{ + while (true) + { + uint8_t token = context_p->stack_top_uint8; + + /* For left-to-right operators (all binary operators except assignment + * and logical operators), the byte code is flushed if the precedence + * of the next operator is less or equal than the current operator. For + * assignment and logical operators, we add 1 to the min precedence to + * force right-to-left evaluation order. */ + + if (!LEXER_IS_BINARY_OP_TOKEN (token) + || parser_binary_precedence_table[token - LEXER_FIRST_BINARY_OP] < min_prec_threshhold) + { + return; + } + + parser_push_result (context_p); + parser_stack_pop_uint8 (context_p); + + switch (token) + { + case LEXER_ASSIGN: + { + parser_process_binary_assignment_token (context_p, token); + continue; + } + /* Binary lvalue-opcodes */ + case LEXER_ASSIGN_ADD: + case LEXER_ASSIGN_SUBTRACT: + case LEXER_ASSIGN_MULTIPLY: + case LEXER_ASSIGN_DIVIDE: + case LEXER_ASSIGN_MODULO: + case LEXER_ASSIGN_EXPONENTIATION: + case LEXER_ASSIGN_LEFT_SHIFT: + case LEXER_ASSIGN_RIGHT_SHIFT: + case LEXER_ASSIGN_UNS_RIGHT_SHIFT: + case LEXER_ASSIGN_BIT_AND: + case LEXER_ASSIGN_BIT_OR: + case LEXER_ASSIGN_BIT_XOR: + { + parser_process_binary_lvalue_token (context_p, token); + continue; + } + case LEXER_ASSIGN_NULLISH_COALESCING: + case LEXER_ASSIGN_LOGICAL_OR: + case LEXER_ASSIGN_LOGICAL_AND: + { + parser_process_logical_assignment_token (context_p); + continue; + } + case LEXER_NULLISH_COALESCING: + case LEXER_LOGICAL_OR: + case LEXER_LOGICAL_AND: + { + parser_process_logical_token (context_p); + continue; + } + case LEXER_KEYW_IN: + { + if (context_p->stack_top_uint8 == LEXER_PRIVATE_PRIMARY_EXPR) + { + parser_stack_pop_uint8 (context_p); + uint16_t lit_id = parser_stack_pop_uint16 (context_p); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_IN, lit_id); + continue; + } + + /* FALLTHRU */ + } + default: + { + parser_process_binary_token (context_p, token); + continue; + } + } + } +} /* parser_process_binary_opcodes */ + +/** + * End position marker of a pattern. + */ +typedef struct +{ + scanner_location_t location; /**< end position of the pattern */ + lexer_token_t token; /**< token at the end position */ +} parser_pattern_end_marker_t; + +/** + * Literal index should not be emitted while processing rhs target value + */ +#define PARSER_PATTERN_RHS_NO_LIT PARSER_INVALID_LITERAL_INDEX + +/** + * Process the target of an initializer pattern. + */ +static parser_pattern_end_marker_t +parser_pattern_get_target (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags) /**< flags */ +{ + parser_pattern_end_marker_t end_marker; + end_marker.token.type = LEXER_INVALID_PATTERN; + parser_branch_t skip_init; + + if (flags & PARSER_PATTERN_TARGET_DEFAULT) + { + JERRY_ASSERT (flags & PARSER_PATTERN_TARGET_ON_STACK); + + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_DEFAULT_INITIALIZER, &skip_init); + } + + if ((flags & (PARSER_PATTERN_TARGET_ON_STACK | PARSER_PATTERN_TARGET_DEFAULT)) != PARSER_PATTERN_TARGET_ON_STACK) + { + scanner_location_t start_location; + + if (context_p->next_scanner_info_p->source_p != context_p->source_p + || context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED || (flags & PARSER_PATTERN_REST_ELEMENT)) + { + /* Found invalid pattern, push null value to fake the rhs target. */ + parser_emit_cbc (context_p, CBC_PUSH_NULL); + } + else + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER); + scanner_get_location (&start_location, context_p); + + scanner_set_location (context_p, &((scanner_location_info_t *) context_p->next_scanner_info_p)->location); + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + scanner_seek (context_p); + lexer_next_token (context_p); + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + scanner_get_location (&(end_marker.location), context_p); + end_marker.token = context_p->token; + + scanner_set_location (context_p, &start_location); + scanner_seek (context_p); + parser_flush_cbc (context_p); + } + } + + if (flags & PARSER_PATTERN_TARGET_DEFAULT) + { + parser_set_branch_to_current_position (context_p, &skip_init); + } + + return end_marker; +} /* parser_pattern_get_target */ + +/** + * Finalize an assignment/binding pattern. + */ +static void +parser_pattern_finalize (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags, /**< flags */ + parser_pattern_end_marker_t *end_marker_p) /**< pattern end position */ +{ + if ((flags & (PARSER_PATTERN_TARGET_ON_STACK | PARSER_PATTERN_TARGET_DEFAULT)) != PARSER_PATTERN_TARGET_ON_STACK) + { + if (end_marker_p->token.type == LEXER_INVALID_PATTERN) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_DESTRUCTURING_PATTERN); + } + + scanner_set_location (context_p, &(end_marker_p->location)); + context_p->token = end_marker_p->token; + } + else + { + JERRY_ASSERT (!(flags & PARSER_PATTERN_TARGET_DEFAULT)); + lexer_next_token (context_p); + } + + if ((flags & (PARSER_PATTERN_BINDING | PARSER_PATTERN_NESTED_PATTERN)) == PARSER_PATTERN_BINDING) + { + /* Pop the result of the expression. */ + parser_emit_cbc (context_p, CBC_POP); + } + + parser_flush_cbc (context_p); +} /* parser_pattern_finalize */ + +/** + * Emit right-hand-side target value. + */ +static void +parser_pattern_emit_rhs (parser_context_t *context_p, /**< context */ + uint16_t rhs_opcode, /**< opcode to process the rhs value */ + uint16_t literal_index) /**< literal index for object pattern */ +{ + if (literal_index != PARSER_PATTERN_RHS_NO_LIT) + { + parser_emit_cbc_ext_literal (context_p, rhs_opcode, literal_index); + } + else + { + parser_emit_cbc_ext (context_p, rhs_opcode); + } +} /* parser_pattern_emit_rhs */ + +/** + * Form an assignment from a pattern. + */ +static void +parser_pattern_form_assignment (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags, /**< flags */ + uint16_t rhs_opcode, /**< opcode to process the rhs value */ + uint16_t literal_index, /**< literal index for object pattern */ + parser_line_counter_t ident_line_counter) /**< identifier line counter */ +{ + JERRY_UNUSED (ident_line_counter); + + uint16_t name_index = PARSER_INVALID_LITERAL_INDEX; + + if ((flags & PARSER_PATTERN_BINDING) + || (context_p->last_cbc_opcode == CBC_PUSH_LITERAL && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)) + { + name_index = context_p->lit_object.index; + } + + parser_stack_push_uint8 (context_p, LEXER_EXPRESSION_START); + parser_append_binary_single_assignment_token (context_p, flags); + parser_pattern_emit_rhs (context_p, rhs_opcode, literal_index); + + if (context_p->token.type == LEXER_ASSIGN && !(flags & PARSER_PATTERN_REST_ELEMENT)) + { + parser_branch_t skip_init; + lexer_next_token (context_p); + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_DEFAULT_INITIALIZER, &skip_init); + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (name_index != PARSER_INVALID_LITERAL_INDEX) + { + uint16_t function_literal_index = parser_check_anonymous_function_declaration (context_p); + + if (function_literal_index == PARSER_ANONYMOUS_CLASS) + { + name_index = scanner_save_literal (context_p, name_index); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, name_index); + } + else if (function_literal_index < PARSER_NAMED_FUNCTION) + { + parser_set_function_name (context_p, function_literal_index, name_index, 0); + } + } + parser_set_branch_to_current_position (context_p, &skip_init); + } + + parser_process_binary_opcodes (context_p, 0); + + JERRY_ASSERT (context_p->stack_top_uint8 == LEXER_EXPRESSION_START); + parser_stack_pop_uint8 (context_p); + +} /* parser_pattern_form_assignment */ + +/** + * Parse pattern inside a pattern. + */ +static void +parser_pattern_process_nested_pattern (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags, /**< flags */ + uint16_t rhs_opcode, /**< opcode to process the rhs value */ + uint16_t literal_index) /**< literal index for object pattern */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE || context_p->token.type == LEXER_LEFT_SQUARE); + + parser_pattern_flags_t options = (parser_pattern_flags_t) ((int) PARSER_PATTERN_NESTED_PATTERN | (int) PARSER_PATTERN_TARGET_ON_STACK + | ((int) flags & ((int) PARSER_PATTERN_BINDING | (int) PARSER_PATTERN_LET | (int) PARSER_PATTERN_CONST + | (int) PARSER_PATTERN_LOCAL | (int) PARSER_PATTERN_ARGUMENTS))); + + JERRY_ASSERT (context_p->next_scanner_info_p->source_p != context_p->source_p + || context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER + || context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS); + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER) + { + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + options = (parser_pattern_flags_t) ((int) options | (int) PARSER_PATTERN_HAS_REST_ELEMENT); + } + + if (!(flags & PARSER_PATTERN_REST_ELEMENT)) + { + options = (parser_pattern_flags_t) ((int) options | (int) PARSER_PATTERN_TARGET_DEFAULT); + } + else + { + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + } + } + else + { + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + options = (parser_pattern_flags_t) ((int) options | (int) PARSER_PATTERN_HAS_REST_ELEMENT); + } + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + } + + parser_pattern_emit_rhs (context_p, rhs_opcode, literal_index); + + if (context_p->token.type == LEXER_LEFT_BRACE) + { + parser_parse_object_initializer (context_p, options); + } + else + { + parser_parse_array_initializer (context_p, options); + } + + parser_emit_cbc (context_p, CBC_POP); +} /* parser_pattern_process_nested_pattern */ + +/** + * Process the current {Binding, Assignment}Property + * + * @return true, if a nested pattern is processed, false otherwise + */ +static bool +parser_pattern_process_assignment (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags, /**< flags */ + uint16_t rhs_opcode, /**< opcode to process the rhs value */ + uint16_t literal_index, /**< literal index for object pattern */ + lexer_token_type_t end_type) /**< end type token */ +{ + if ((context_p->token.type == LEXER_LEFT_BRACE || context_p->token.type == LEXER_LEFT_SQUARE) + && (context_p->next_scanner_info_p->source_p != context_p->source_p + || !(context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_NO_DESTRUCTURING))) + { + parser_pattern_process_nested_pattern (context_p, flags, rhs_opcode, literal_index); + return true; + } + + parser_line_counter_t ident_line_counter = context_p->token.line; + + if (flags & PARSER_PATTERN_BINDING) + { + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); + + if (flags & (PARSER_PATTERN_LET | PARSER_PATTERN_CONST) && context_p->token.keyword_type == LEXER_KEYW_LET) + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_LET_BINDING); + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED); + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + + if (flags & PARSER_PATTERN_ARGUMENTS) + { + if (context_p->lit_object.literal_p->status_flags & LEXER_FLAG_FUNCTION_ARGUMENT) + { + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_FUNCTION_ARGUMENT; + } +#if JERRY_MODULE_SYSTEM + parser_module_append_export_name (context_p); +#endif /* JERRY_MODULE_SYSTEM */ + + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + lexer_next_token (context_p); + + if (context_p->token.type != end_type && context_p->token.type != LEXER_ASSIGN + && context_p->token.type != LEXER_COMMA) + { + parser_raise_error (context_p, PARSER_ERR_ILLEGAL_PROPERTY_IN_DECLARATION); + } + } + else + { + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA | PARSE_EXPR_LEFT_HAND_SIDE); + + if (!PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode) && !PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_DESTRUCTURING_PATTERN); + } + } + + parser_pattern_form_assignment (context_p, flags, rhs_opcode, literal_index, ident_line_counter); + return false; +} /* parser_pattern_process_assignment */ + +/** + * Parse array initializer. + */ +static void +parser_parse_array_initializer (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags) /**< flags */ +{ + parser_pattern_end_marker_t end_pos = parser_pattern_get_target (context_p, flags); + + lexer_next_token (context_p); + parser_emit_cbc_ext (context_p, CBC_EXT_ITERATOR_CONTEXT_CREATE); + + while (context_p->token.type != LEXER_RIGHT_SQUARE) + { + uint16_t rhs_opcode = CBC_EXT_ITERATOR_STEP; + + if (context_p->token.type == LEXER_COMMA) + { + parser_emit_cbc_ext (context_p, rhs_opcode); + parser_emit_cbc (context_p, CBC_POP); + lexer_next_token (context_p); + continue; + } + + parser_pattern_flags_t options = flags; + + if (context_p->token.type == LEXER_THREE_DOTS) + { + lexer_next_token (context_p); + rhs_opcode = CBC_EXT_REST_INITIALIZER; + options = (parser_pattern_flags_t) ((int) options | (int) PARSER_PATTERN_REST_ELEMENT); + } + + parser_pattern_process_assignment (context_p, options, rhs_opcode, PARSER_PATTERN_RHS_NO_LIT, LEXER_RIGHT_SQUARE); + + if (context_p->token.type == LEXER_COMMA && rhs_opcode != CBC_EXT_REST_INITIALIZER) + { + lexer_next_token (context_p); + } + else if (context_p->token.type != LEXER_RIGHT_SQUARE) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_DESTRUCTURING_PATTERN); + } + } + + /* close the iterator */ + parser_emit_cbc_ext (context_p, CBC_EXT_ITERATOR_CONTEXT_END); + + parser_pattern_finalize (context_p, flags, &end_pos); +} /* parser_parse_array_initializer */ + +/** + * Parse object initializer. + */ +static void +parser_parse_object_initializer (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags) /**< flags */ +{ + parser_pattern_end_marker_t end_pos = parser_pattern_get_target (context_p, flags); + + /* 12.14.5.2: ObjectAssignmentPattern : { } */ + if (lexer_check_next_character (context_p, LIT_CHAR_RIGHT_BRACE)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_REQUIRE_OBJECT_COERCIBLE); + lexer_consume_next_character (context_p); + parser_pattern_finalize (context_p, flags, &end_pos); + return; + } + +#ifndef JERRY_NDEBUG + bool rest_found = false; +#endif /* !defined(JERRY_NDEBUG) */ + + cbc_ext_opcode_t context_opcode = CBC_EXT_OBJ_INIT_CONTEXT_CREATE; + + if (flags & PARSER_PATTERN_HAS_REST_ELEMENT) + { + context_opcode = CBC_EXT_OBJ_INIT_REST_CONTEXT_CREATE; + } + + parser_emit_cbc_ext (context_p, context_opcode); + + while (true) + { + lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_OBJECT_PATTERN); + + uint16_t prop_index = context_p->lit_object.index; + parser_line_counter_t start_line = context_p->token.line; + parser_line_counter_t start_column = context_p->token.column; + uint16_t push_prop_opcode = CBC_EXT_INITIALIZER_PUSH_PROP_LITERAL; + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + break; + } + + if (context_p->token.type == LEXER_THREE_DOTS) + { + lexer_next_token (context_p); + + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_REST_ELEMENT); + + if (parser_pattern_process_assignment (context_p, + flags, + CBC_EXT_OBJ_INIT_PUSH_REST, + PARSER_PATTERN_RHS_NO_LIT, + LEXER_RIGHT_BRACE)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT); + } + + if (context_p->token.type != LEXER_RIGHT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED); + } + +#ifndef JERRY_NDEBUG + rest_found = true; +#endif /* !defined(JERRY_NDEBUG) */ + break; + } + + if (context_p->token.type == LEXER_RIGHT_SQUARE) + { + prop_index = PARSER_PATTERN_RHS_NO_LIT; + push_prop_opcode = + ((flags & PARSER_PATTERN_HAS_REST_ELEMENT) ? CBC_EXT_INITIALIZER_PUSH_NAME : CBC_EXT_INITIALIZER_PUSH_PROP); + } + else if (flags & PARSER_PATTERN_HAS_REST_ELEMENT) + { + push_prop_opcode = CBC_EXT_INITIALIZER_PUSH_NAME_LITERAL; + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED); + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_COLON) + { + lexer_next_token (context_p); + parser_pattern_process_assignment (context_p, flags, push_prop_opcode, prop_index, LEXER_RIGHT_BRACE); + } + else + { + if (push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_NAME || push_prop_opcode == CBC_EXT_INITIALIZER_PUSH_PROP) + { + parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); + } + + if (context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_ASSIGN + && context_p->token.type != LEXER_COMMA) + { + parser_raise_error (context_p, PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED); + } + + parser_reparse_as_common_identifier (context_p, start_line, start_column); + + if (flags & PARSER_PATTERN_ARGUMENTS) + { + if (context_p->lit_object.literal_p->status_flags & LEXER_FLAG_FUNCTION_ARGUMENT) + { + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_FUNCTION_ARGUMENT; + } + +#if JERRY_MODULE_SYSTEM + parser_module_append_export_name (context_p); +#endif /* JERRY_MODULE_SYSTEM */ + + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + + lexer_next_token (context_p); + JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE || context_p->token.type == LEXER_ASSIGN + || context_p->token.type == LEXER_COMMA); + + parser_pattern_form_assignment (context_p, flags, push_prop_opcode, prop_index, start_line); + } + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + break; + } + else if (context_p->token.type != LEXER_COMMA) + { + parser_raise_error (context_p, PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED); + } + } + + if (flags & PARSER_PATTERN_HAS_REST_ELEMENT) + { + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, + (PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION - PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION)); + } + + parser_emit_cbc_ext (context_p, CBC_EXT_OBJ_INIT_CONTEXT_END); + + parser_pattern_finalize (context_p, flags, &end_pos); + +#ifndef JERRY_NDEBUG + /* Checked at the end because there might be syntax errors before. */ + JERRY_ASSERT (!!(flags & PARSER_PATTERN_HAS_REST_ELEMENT) == rest_found); +#endif /* !defined(JERRY_NDEBUG) */ +} /* parser_parse_object_initializer */ + +/** + * Parse an initializer. + */ +void +parser_parse_initializer (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags) /**< flags */ +{ + if (context_p->token.type == LEXER_LEFT_BRACE) + { + parser_parse_object_initializer (context_p, flags); + } + else + { + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_SQUARE); + parser_parse_array_initializer (context_p, flags); + } +} /* parser_parse_initializer */ + +/** + * Parse an initializer using the next character. + */ +void +parser_parse_initializer_by_next_char (parser_context_t *context_p, /**< context */ + parser_pattern_flags_t flags) /**< flags */ +{ + JERRY_ASSERT (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE)); + + if (lexer_consume_next_character (context_p) == LIT_CHAR_LEFT_BRACE) + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER + || context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS); + + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_HAS_REST_ELEMENT); + } + + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS) + { + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + } + + parser_parse_object_initializer (context_p, flags); + } + else + { + parser_parse_array_initializer (context_p, flags); + } +} /* parser_parse_initializer_by_next_char */ + +/** + * Process ternary expression. + */ +static void +parser_process_ternary_expression (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_QUESTION_MARK); + + cbc_opcode_t opcode = CBC_BRANCH_IF_FALSE_FORWARD; + parser_branch_t cond_branch; + parser_branch_t uncond_branch; + + parser_push_result (context_p); + + if (context_p->last_cbc_opcode == CBC_LOGICAL_NOT) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_BRANCH_IF_TRUE_FORWARD; + } + + parser_emit_cbc_forward_branch (context_p, (uint16_t) opcode, &cond_branch); + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &uncond_branch); + parser_set_branch_to_current_position (context_p, &cond_branch); + + /* Although byte code is constructed for two branches, + * only one of them will be executed. To reflect this + * the stack is manually adjusted. */ + JERRY_ASSERT (context_p->stack_depth > 0); + context_p->stack_depth--; + + if (context_p->token.type != LEXER_COLON) + { + parser_raise_error (context_p, PARSER_ERR_COLON_FOR_CONDITIONAL_EXPECTED); + } + + lexer_next_token (context_p); + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + parser_set_branch_to_current_position (context_p, &uncond_branch); + + /* Last opcode rewrite is not allowed because + * the result may come from the first branch. */ + parser_flush_cbc (context_p); + + parser_process_binary_opcodes (context_p, 0); +} /* parser_process_ternary_expression */ + +/** + * Process expression sequence. + */ +static void +parser_process_expression_sequence (parser_context_t *context_p) /**< context */ +{ + if (!CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode)) + { + parser_emit_cbc (context_p, CBC_POP); + } + + if (context_p->stack_top_uint8 == LEXER_LEFT_PAREN) + { + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL); + + page_p->bytes[context_p->stack.last_position - 1] = LEXER_COMMA_SEP_LIST; + context_p->stack_top_uint8 = LEXER_COMMA_SEP_LIST; + } + + lexer_next_token (context_p); +} /* parser_process_expression_sequence */ + +/** + * Process group expression. + */ +static void +parser_process_group_expression (parser_context_t *context_p, /**< context */ + size_t *grouping_level_p) /**< grouping level */ +{ + JERRY_ASSERT (*grouping_level_p >= PARSER_GROUPING_LEVEL_INCREASE); + (*grouping_level_p) -= PARSER_GROUPING_LEVEL_INCREASE; + + uint8_t token = context_p->stack_top_uint8; + + if (token == LEXER_COMMA_SEP_LIST) + { + parser_push_result (context_p); + parser_flush_cbc (context_p); + } + + parser_stack_pop_uint8 (context_p); + lexer_next_token (context_p); + + /* Lookahead for anonymous function declaration after '=' token when the assignment base is LHS expression + with a single identifier in it. e.g.: (a) = function () {} */ + if (JERRY_UNLIKELY (context_p->token.type == LEXER_ASSIGN + && PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode) + && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL + && parser_is_assignment_expr (context_p) && *grouping_level_p != PARSE_EXPR_LEFT_HAND_SIDE)) + { + parser_stack_push_uint8 (context_p, LEXER_ASSIGN_GROUP_EXPR); + } +} /* parser_process_group_expression */ + +/** + * Parse block expression. + */ +void +parser_parse_block_expression (parser_context_t *context_p, /**< context */ + int options) /**< option flags */ +{ + parser_parse_expression (context_p, options | PARSE_EXPR_NO_PUSH_RESULT); + + if (CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode)) + { + JERRY_ASSERT (CBC_SAME_ARGS (context_p->last_cbc_opcode, context_p->last_cbc_opcode + 2)); + PARSER_PLUS_EQUAL_U16 (context_p->last_cbc_opcode, 2); + parser_flush_cbc (context_p); + } + else + { + parser_emit_cbc (context_p, CBC_POP_BLOCK); + } +} /* parser_parse_block_expression */ + +/** + * Parse expression statement. + */ +void +parser_parse_expression_statement (parser_context_t *context_p, /**< context */ + int options) /**< option flags */ +{ + parser_parse_expression (context_p, options | PARSE_EXPR_NO_PUSH_RESULT); + + if (!CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode)) + { + parser_emit_cbc (context_p, CBC_POP); + } +} /* parser_parse_expression_statement */ + +JERRY_STATIC_ASSERT ((PARSE_EXPR_LEFT_HAND_SIDE == 0x1), value_of_parse_expr_left_hand_side_must_be_1); + +/** + * Parse expression. + */ +void +parser_parse_expression (parser_context_t *context_p, /**< context */ + int options) /**< option flags */ +{ + size_t grouping_level = (options & PARSE_EXPR_LEFT_HAND_SIDE); + + parser_stack_push_uint8 (context_p, LEXER_EXPRESSION_START); + + if (options & PARSE_EXPR_HAS_LITERAL) + { + JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL); + goto process_unary_expression; + } + + while (true) + { + if (parser_parse_unary_expression (context_p, &grouping_level)) + { + parser_process_binary_opcodes (context_p, 0); + break; + } + + while (true) + { +process_unary_expression: + parser_process_unary_expression (context_p, grouping_level); + + if (JERRY_LIKELY (grouping_level != PARSE_EXPR_LEFT_HAND_SIDE)) + { + uint8_t min_prec_threshhold = 0; + + if (LEXER_IS_BINARY_OP_TOKEN (context_p->token.type)) + { + if (JERRY_UNLIKELY (context_p->token.type == LEXER_NULLISH_COALESCING)) + { + parser_check_invalid_logical_op (context_p, LEXER_LOGICAL_OR, LEXER_LOGICAL_AND); + } + + min_prec_threshhold = parser_binary_precedence_table[context_p->token.type - LEXER_FIRST_BINARY_OP]; + + /* Check for BINARY_LVALUE tokens + LEXER_LOGICAL_OR + LEXER_LOGICAL_AND + LEXER_EXPONENTIATION */ + if ((min_prec_threshhold == PARSER_RIGHT_TO_LEFT_ORDER_EXPONENTIATION) + || (min_prec_threshhold <= PARSER_RIGHT_TO_LEFT_ORDER_MAX_PRECEDENCE + && min_prec_threshhold != PARSER_RIGHT_TO_LEFT_ORDER_TERNARY_PRECEDENCE)) + { + /* Right-to-left evaluation order. */ + min_prec_threshhold++; + } + } + + parser_process_binary_opcodes (context_p, min_prec_threshhold); + } + if (context_p->token.type == LEXER_RIGHT_PAREN + && (context_p->stack_top_uint8 == LEXER_LEFT_PAREN || context_p->stack_top_uint8 == LEXER_COMMA_SEP_LIST)) + { + parser_process_group_expression (context_p, &grouping_level); + continue; + } + + break; + } + + if (grouping_level == PARSE_EXPR_LEFT_HAND_SIDE) + { + break; + } + + if (JERRY_UNLIKELY (context_p->token.type == LEXER_QUESTION_MARK)) + { + parser_process_ternary_expression (context_p); + + if (context_p->token.type == LEXER_RIGHT_PAREN) + { + goto process_unary_expression; + } + } + else if (LEXER_IS_BINARY_OP_TOKEN (context_p->token.type)) + { + parser_append_binary_token (context_p); + lexer_next_token (context_p); + continue; + } + + if (JERRY_UNLIKELY (context_p->token.type == LEXER_COMMA) + && (!(options & PARSE_EXPR_NO_COMMA) || grouping_level >= PARSER_GROUPING_LEVEL_INCREASE)) + { + parser_process_expression_sequence (context_p); + continue; + } + + break; + } + + if (grouping_level >= PARSER_GROUPING_LEVEL_INCREASE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + JERRY_ASSERT (context_p->stack_top_uint8 == LEXER_EXPRESSION_START); + parser_stack_pop_uint8 (context_p); + + if (!(options & PARSE_EXPR_NO_PUSH_RESULT)) + { + parser_push_result (context_p); + } +} /* parser_parse_expression */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-internal.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-internal.h new file mode 100644 index 0000000..2f1048a --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-internal.h @@ -0,0 +1,859 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JS_PARSER_INTERNAL_H +#define JS_PARSER_INTERNAL_H + +#include "ecma-module.h" + +#include "byte-code.h" +#include "common.h" +#include "js-lexer.h" +#include "js-parser-limits.h" +#include "js-parser.h" +#include "js-scanner.h" +#include "parser-errors.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_internals Internals + * @{ + */ + +/** + * General parser flags. + */ +typedef enum +{ + PARSER_IS_STRICT = (1u << 0), /**< strict mode code */ + PARSER_IS_FUNCTION = (1u << 1), /**< function body is parsed */ + PARSER_IS_CLOSURE = (1u << 2), /**< function body is encapsulated in {} block */ + PARSER_IS_FUNC_EXPRESSION = (1u << 3), /**< a function expression is parsed */ + PARSER_IS_PROPERTY_GETTER = (1u << 4), /**< a property getter function is parsed */ + PARSER_IS_PROPERTY_SETTER = (1u << 5), /**< a property setter function is parsed */ + PARSER_HAS_NON_STRICT_ARG = (1u << 6), /**< the function has arguments which + * are not supported in strict mode */ + PARSER_ARGUMENTS_NEEDED = (1u << 7), /**< arguments object must be created */ + PARSER_LEXICAL_ENV_NEEDED = (1u << 8), /**< lexical environment object must be created */ + PARSER_INSIDE_WITH = (1u << 9), /**< code block is inside a with statement */ + PARSER_NO_END_LABEL = (1u << 10), /**< return instruction must be inserted + * after the last byte code */ + PARSER_DEBUGGER_BREAKPOINT_APPENDED = (1u << 11), /**< pending (unsent) breakpoint + * info is available */ + PARSER_LEXICAL_BLOCK_NEEDED = (1u << 12), /**< global script: needs a lexical environment for let and const + * function: needs a lexical environment for arguments */ + PARSER_IS_ARROW_FUNCTION = (1u << 13), /**< an arrow function is parsed */ + PARSER_IS_GENERATOR_FUNCTION = (1u << 14), /**< a generator function is parsed */ + PARSER_IS_ASYNC_FUNCTION = (1u << 15), /**< an async function is parsed */ + PARSER_DISALLOW_AWAIT_YIELD = (1u << 16), /**< throw SyntaxError for await / yield keywords */ + PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT = (1u << 17), /**< function has complex (ES2015+) argument definition */ + PARSER_FUNCTION_HAS_REST_PARAM = (1u << 18), /**< function has rest parameter */ + PARSER_CLASS_CONSTRUCTOR = (1u << 19), /**< a class constructor is parsed + * Note: PARSER_ALLOW_SUPER must be present */ + /* These five status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */ + PARSER_ALLOW_SUPER = (1u << 20), /**< allow super property access */ + PARSER_ALLOW_SUPER_CALL = (1u << 21), /**< allow super constructor call + * Note: PARSER_CLASS_CONSTRUCTOR must be present */ + PARSER_FUNCTION_IS_PARSING_ARGS = (1u << 22), /**< set when parsing function arguments */ + PARSER_INSIDE_CLASS_FIELD = (1u << 23), /**< a class field is being parsed */ + PARSER_ALLOW_NEW_TARGET = (1u << 24), /**< allow new.target parsing in the current context */ + PARSER_IS_METHOD = (1u << 25), /**< method is parsed */ + PARSER_IS_CLASS_STATIC_BLOCK = (1u << 26), /**< a class static block is parsed */ + PARSER_PRIVATE_FUNCTION_NAME = PARSER_IS_FUNC_EXPRESSION, /**< represents private method for + * parser_set_function_name*/ +#if JERRY_MODULE_SYSTEM + PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 27), /**< parsing a function or class default export */ + PARSER_MODULE_STORE_IDENT = (1u << 28), /**< store identifier of the current export statement */ +#endif /* JERRY_MODULE_SYSTEM */ + PARSER_HAS_LATE_LIT_INIT = (1u << 30), /**< there are identifier or string literals which construction + * is postponed after the local parser data is freed */ +#ifndef JERRY_NDEBUG + PARSER_SCANNING_SUCCESSFUL = PARSER_HAS_LATE_LIT_INIT, /**< scanning process was successful */ +#endif /* !JERRY_NDEBUG */ +} parser_general_flags_t; + +/** + * Expression parsing flags. + */ +typedef enum +{ + PARSE_EXPR = 0, /**< parse an expression without any special flags */ + PARSE_EXPR_LEFT_HAND_SIDE = (1u << 0), /**< parse a left-hand-side expression */ + PARSE_EXPR_NO_PUSH_RESULT = (1u << 1), /**< do not push the result of the expression onto the stack */ + PARSE_EXPR_NO_COMMA = (1u << 2), /**< do not parse comma operator */ + PARSE_EXPR_HAS_LITERAL = (1u << 3), /**< a primary literal is provided by a + * CBC_PUSH_LITERAL instruction */ +} parser_expression_flags_t; + +/** + * Pattern parsing flags. + */ +typedef enum +{ + PARSER_PATTERN_NO_OPTS = 0, /**< parse the expression after '=' */ + PARSER_PATTERN_BINDING = (1u << 0), /**< parse BindingPattern */ + PARSER_PATTERN_TARGET_ON_STACK = (1u << 1), /**< assignment target is the topmost element on the stack */ + PARSER_PATTERN_TARGET_DEFAULT = (1u << 2), /**< perform default value comparison for assignment target */ + PARSER_PATTERN_NESTED_PATTERN = (1u << 3), /**< parse pattern inside a pattern */ + PARSER_PATTERN_LET = (1u << 4), /**< pattern is a let declaration */ + PARSER_PATTERN_CONST = (1u << 5), /**< pattern is a const declaration */ + PARSER_PATTERN_LOCAL = (1u << 6), /**< pattern is a local (catch parameter) declaration */ + PARSER_PATTERN_REST_ELEMENT = (1u << 7), /**< parse rest array / object element */ + PARSER_PATTERN_HAS_REST_ELEMENT = (1u << 8), /**< object literal rest element will be present */ + PARSER_PATTERN_ARGUMENTS = (1u << 9), /**< parse arguments binding */ +} parser_pattern_flags_t; + +/** + * Check type for scanner_is_context_needed function. + */ +typedef enum +{ + PARSER_CHECK_BLOCK_CONTEXT, /**< check block context */ + PARSER_CHECK_GLOBAL_CONTEXT, /**< check global context */ + PARSER_CHECK_FUNCTION_CONTEXT, /**< check function context */ +} parser_check_context_type_t; + +/** + * Class field bits. + */ +typedef enum +{ + PARSER_CLASS_FIELD_END = (1u << 0), /**< last class field */ + PARSER_CLASS_FIELD_NORMAL = (1u << 1), /**< normal (non-computed) class field */ + PARSER_CLASS_FIELD_INITIALIZED = (1u << 2), /**< class field is initialized */ + PARSER_CLASS_FIELD_STATIC = (1u << 3), /**< static class field */ + PARSER_CLASS_FIELD_STATIC_BLOCK = (1u << 4), /**< static class field */ +} parser_class_field_type_t; + +/** + * Mask for strict mode code + */ +#define PARSER_STRICT_MODE_MASK 0x1 + +/** + * Shorthand for function closure definition + */ +#define PARSER_FUNCTION_CLOSURE (PARSER_IS_FUNCTION | PARSER_IS_CLOSURE) + +#if PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX +/** + * Maximum number of bytes for branch target. + */ +#define PARSER_MAX_BRANCH_LENGTH 2 +#else /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */ +/** + * Maximum number of bytes for branch target. + */ +#define PARSER_MAX_BRANCH_LENGTH 3 +#endif /* PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX */ + +/** + * Offset of PARSER_ALLOW_SUPER + */ +#define PARSER_SAVED_FLAGS_OFFSET JERRY_LOG2 (PARSER_ALLOW_SUPER) + +/** + * Mask of saved flags + */ +#define PARSER_SAVED_FLAGS_MASK \ + ((1 << (JERRY_LOG2 (PARSER_ALLOW_NEW_TARGET) - JERRY_LOG2 (PARSER_ALLOW_SUPER) + 1)) - 1) + +/** + * Get class option bits from parser_general_flags_t + */ +#define PARSER_SAVE_STATUS_FLAGS(opts) ((uint16_t) (((opts) >> PARSER_SAVED_FLAGS_OFFSET) & PARSER_SAVED_FLAGS_MASK)) + +/** + * Mask for get class option bits from ecma_parse_opts_t + */ +#define PARSER_RESTORE_STATUS_FLAGS_MASK (((ECMA_PARSE_ALLOW_NEW_TARGET << 1) - 1) - (ECMA_PARSE_ALLOW_SUPER - 1)) + +/** + * Shift for get class option bits from ecma_parse_opts_t + */ +#define PARSER_RESTORE_STATUS_FLAGS_SHIFT (JERRY_LOG2 (PARSER_ALLOW_SUPER) - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)) + +/** + * Get class option bits from ecma_parse_opts_t + */ +#define PARSER_RESTORE_STATUS_FLAGS(opts) \ + (((opts) &PARSER_RESTORE_STATUS_FLAGS_MASK) << PARSER_RESTORE_STATUS_FLAGS_SHIFT) + +/** + * All flags that affect exotic arguments object creation. + */ +#define PARSER_ARGUMENTS_RELATED_FLAGS \ + (PARSER_ARGUMENTS_NEEDED | PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT | PARSER_IS_STRICT) + +/** + * Get the corresponding eval flag for a ecma_parse_opts_t flag + */ +#define PARSER_GET_EVAL_FLAG(type) ((type) >> JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)) + +/** + * Check non-generator async functions + */ +#define PARSER_IS_NORMAL_ASYNC_FUNCTION(status_flags) \ + (((status_flags) & (PARSER_IS_GENERATOR_FUNCTION | PARSER_IS_ASYNC_FUNCTION)) == PARSER_IS_ASYNC_FUNCTION) + +/* Checks whether unmapped arguments are needed. */ +#define PARSER_NEEDS_MAPPED_ARGUMENTS(status_flags) \ + (((status_flags) &PARSER_ARGUMENTS_RELATED_FLAGS) == PARSER_ARGUMENTS_NEEDED) + +/* The maximum of PARSER_CBC_STREAM_PAGE_SIZE is 127. */ +#define PARSER_CBC_STREAM_PAGE_SIZE ((uint32_t) (64 - sizeof (void *))) + +/* Defines the size of the max page. */ +#define PARSER_STACK_PAGE_SIZE ((uint32_t) (((sizeof (void *) > 4) ? 128 : 64) - sizeof (void *))) + +/* Avoid compiler warnings for += operations. */ +#define PARSER_PLUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) + (value)) +#define PARSER_MINUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) - (value)) +#define PARSER_PLUS_EQUAL_LC(base, value) (base) = (parser_line_counter_t) ((base) + (value)) + +/** + * Argument for a compact-byte code. + */ +typedef struct +{ + uint16_t literal_index; /**< literal index argument */ + uint16_t value; /**< other argument (second literal or byte). */ + uint16_t third_literal_index; /**< literal index argument */ + uint8_t literal_type; /**< last literal type */ + uint8_t literal_keyword_type; /**< last literal keyword type */ +} cbc_argument_t; + +/* Useful parser macros. */ + +#define PARSER_CBC_UNAVAILABLE CBC_EXT_OPCODE + +#define PARSER_TO_EXT_OPCODE(opcode) ((uint16_t) ((opcode) + 256)) +#define PARSER_GET_EXT_OPCODE(opcode) ((opcode) -256) +#define PARSER_IS_BASIC_OPCODE(opcode) ((opcode) < 256) +#define PARSER_IS_PUSH_LITERAL(opcode) \ + ((opcode) == CBC_PUSH_LITERAL || (opcode) == CBC_PUSH_TWO_LITERALS || (opcode) == CBC_PUSH_THREE_LITERALS) +#define PARSER_IS_PUSH_NUMBER(opcode) \ + ((opcode) >= CBC_PUSH_NUMBER_0 && (opcode) <= CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) + +#define PARSER_IS_MUTABLE_PUSH_LITERAL(opcode) ((opcode) >= CBC_PUSH_LITERAL && (opcode) <= CBC_PUSH_THIS_LITERAL) + +#define PARSER_IS_PUSH_LITERALS_WITH_THIS(opcode) ((opcode) >= CBC_PUSH_LITERAL && (opcode) <= CBC_PUSH_THREE_LITERALS) + +#define PARSER_IS_PUSH_PROP(opcode) ((opcode) >= CBC_PUSH_PROP && (opcode) <= CBC_PUSH_PROP_THIS_LITERAL) + +#define PARSER_IS_PUSH_PROP_LITERAL(opcode) \ + ((opcode) >= CBC_PUSH_PROP_LITERAL && (opcode) <= CBC_PUSH_PROP_THIS_LITERAL) + +#define PARSER_PUSH_LITERAL_TO_PUSH_PROP_LITERAL(opcode) \ + (uint16_t) ((opcode) + (CBC_PUSH_PROP_LITERAL - CBC_PUSH_LITERAL)) + +#define PARSER_PUSH_PROP_LITERAL_TO_PUSH_LITERAL(opcode) \ + (uint16_t) ((opcode) - (CBC_PUSH_PROP_LITERAL - CBC_PUSH_LITERAL)) + +#define PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE(opcode) \ + (uint16_t) ((opcode) + (CBC_PUSH_PROP_REFERENCE - CBC_PUSH_PROP)) + +#define PARSER_PUSH_PROP_REFERENCE_TO_PUSH_PROP(opcode) \ + (uint16_t) ((opcode) - (CBC_PUSH_PROP_REFERENCE - CBC_PUSH_PROP)) + +#define PARSER_GET_LITERAL(literal_index) \ + ((lexer_literal_t *) parser_list_get (&context_p->literal_pool, (literal_index))) + +#define PARSER_TO_BINARY_OPERATION_WITH_RESULT(opcode) \ + (PARSER_TO_EXT_OPCODE (opcode) - CBC_ASSIGN_ADD + CBC_EXT_ASSIGN_ADD_PUSH_RESULT) + +#define PARSER_TO_BINARY_OPERATION_WITH_BLOCK(opcode) \ + ((uint16_t) (PARSER_TO_EXT_OPCODE (opcode) - CBC_ASSIGN_ADD + CBC_EXT_ASSIGN_ADD_BLOCK)) + +#define PARSER_GET_FLAGS(op) (PARSER_IS_BASIC_OPCODE (op) ? cbc_flags[(op)] : cbc_ext_flags[PARSER_GET_EXT_OPCODE (op)]) + +#define PARSER_OPCODE_IS_RETURN(op) \ + ((op) == CBC_RETURN || (op) == CBC_RETURN_FUNCTION_END || (op) == CBC_RETURN_WITH_LITERAL) + +#define PARSER_ARGS_EQ(op, types) ((PARSER_GET_FLAGS (op) & CBC_ARG_TYPES) == (types)) + +/** + * All data allocated by the parser is + * stored in parser_data_pages in the memory. + */ +#if defined(_MSC_VER ) +#pragma warning(push) +#pragma warning(disable:4200) +#endif +typedef struct parser_mem_page_t +{ + struct parser_mem_page_t *next_p; /**< next page */ + uint8_t bytes[]; /**< memory bytes, C99 flexible array member */ +} parser_mem_page_t; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +/** + * Structure for managing parser memory. + */ +typedef struct +{ + parser_mem_page_t *first_p; /**< first allocated page */ + parser_mem_page_t *last_p; /**< last allocated page */ + uint32_t last_position; /**< position of the last allocated byte */ +} parser_mem_data_t; + +/** + * Parser memory list. + */ +typedef struct +{ + parser_mem_data_t data; /**< storage space */ + uint32_t page_size; /**< size of each page */ + uint32_t item_size; /**< size of each item */ + uint32_t item_count; /**< number of items on each page */ +} parser_list_t; + +/** + * Iterator for parser memory list. + */ +typedef struct +{ + parser_list_t *list_p; /**< parser list */ + parser_mem_page_t *current_p; /**< currently processed page */ + size_t current_position; /**< current position on the page */ +} parser_list_iterator_t; + +/** + * Parser memory stack. + */ +typedef struct +{ + parser_mem_data_t data; /**< storage space */ + parser_mem_page_t *free_page_p; /**< space for fast allocation */ +} parser_stack_t; + +/** + * Iterator for parser memory stack. + */ +typedef struct +{ + parser_mem_page_t *current_p; /**< currently processed page */ + size_t current_position; /**< current position on the page */ +} parser_stack_iterator_t; + +/** + * Branch type. + */ +typedef struct +{ + parser_mem_page_t *page_p; /**< branch location page */ + uint32_t offset; /**< branch location offset */ +} parser_branch_t; + +/** + * Branch chain type. + */ +typedef struct parser_branch_node_t +{ + struct parser_branch_node_t *next_p; /**< next linked list node */ + parser_branch_t branch; /**< branch */ +} parser_branch_node_t; + +/** + * Items of scope stack. + */ +typedef struct +{ + uint16_t map_from; /**< original literal index */ + uint16_t map_to; /**< encoded register or literal index and flags */ +} parser_scope_stack_t; + +/** + * This item represents a function literal in the scope stack. + * + * When map_from == PARSER_SCOPE_STACK_FUNC: + * map_to represents the literal reserved for a function literal + * Note: the name of the function is the previous value in the scope stack + * Note: map_to is not encoded in this case + */ +#define PARSER_SCOPE_STACK_FUNC 0xffff + +/** + * Mask for decoding the register index of map_to + */ +#define PARSER_SCOPE_STACK_REGISTER_MASK 0x3fff + +/** + * Function statements with the name specified + * in map_from should not be copied to global scope. + */ +#define PARSER_SCOPE_STACK_NO_FUNCTION_COPY 0x8000 + +/** + * The scope stack item represents a const binding stored in register + */ +#define PARSER_SCOPE_STACK_IS_CONST_REG 0x4000 + +/** + * The scope stack item represents a binding which has already created with ECMA_VALUE_UNINITIALIZED + */ +#define PARSER_SCOPE_STACK_IS_LOCAL_CREATED (PARSER_SCOPE_STACK_IS_CONST_REG) + +/** + * Starting literal index for registers. + */ +#define PARSER_REGISTER_START 0x8000 + +/** + * Invalid literal index + */ +#define PARSER_INVALID_LITERAL_INDEX UINT16_MAX + +/** + * Lastly emitted opcode is not a function literal + */ +#define PARSER_NOT_FUNCTION_LITERAL PARSER_INVALID_LITERAL_INDEX + +/** + * Lastly emitted opcode is not a named function literal + */ +#define PARSER_NAMED_FUNCTION (uint16_t) (PARSER_NOT_FUNCTION_LITERAL - 1) + +/** + * Lastly emitted opcode is not an anonymous class literal + */ +#define PARSER_ANONYMOUS_CLASS (uint16_t) (PARSER_NAMED_FUNCTION - 1) + +/* Forward definitions for js-scanner-internal.h. */ +struct scanner_context_t; +typedef struct scanner_context_t scanner_context_t; + +/** + * List of private field contexts + */ +typedef struct parser_private_context_t +{ + scanner_class_private_member_t *members_p; /**< current private field context members */ + struct parser_private_context_t *prev_p; /**< previous private field context */ + uint8_t opts; /**< options */ +} parser_private_context_t; + +/** + * Those members of a context which needs + * to be saved when a sub-function is parsed. + */ +typedef struct parser_saved_context_t +{ + /* Parser members. */ + uint32_t status_flags; /**< parsing options */ + uint16_t stack_depth; /**< current stack depth */ + uint16_t stack_limit; /**< maximum stack depth */ + struct parser_saved_context_t *prev_context_p; /**< last saved context */ + parser_stack_iterator_t last_statement; /**< last statement position */ + + /* Literal types */ + uint16_t argument_count; /**< number of function arguments */ + uint16_t argument_length; /**< length property of arguments */ + uint16_t register_count; /**< number of registers */ + uint16_t literal_count; /**< number of literals */ + + /* Memory storage members. */ + parser_mem_data_t byte_code; /**< byte code buffer */ + uint32_t byte_code_size; /**< byte code size for branches */ + parser_mem_data_t literal_pool_data; /**< literal list */ + parser_scope_stack_t *scope_stack_p; /**< scope stack */ + uint16_t scope_stack_size; /**< size of scope stack */ + uint16_t scope_stack_top; /**< preserved top of scope stack */ + uint16_t scope_stack_reg_top; /**< preserved top register of scope stack */ + uint16_t scope_stack_global_end; /**< end of global declarations of a function */ + ecma_value_t tagged_template_literal_cp; /**< compressed pointer to the tagged template literal collection */ +#ifndef JERRY_NDEBUG + uint16_t context_stack_depth; /**< current context stack depth */ +#endif /* !JERRY_NDEBUG */ +} parser_saved_context_t; + +/** + * Shared parser context. + */ +typedef struct +{ + PARSER_TRY_CONTEXT (try_buffer); /**< try_buffer */ + parser_error_msg_t error; /**< error code */ + /** Union for rarely used members. */ + union + { + void *allocated_buffer_p; /**< dynamically allocated buffer + * which needs to be freed on error */ + scanner_context_t *scanner_context_p; /**< scanner context for the pre-scanner */ + } u; + uint32_t allocated_buffer_size; /**< size of the dynamically allocated buffer */ + + /* Parser members. */ + uint32_t status_flags; /**< status flags */ + uint32_t global_status_flags; /**< global status flags */ + uint16_t stack_depth; /**< current stack depth */ + uint16_t stack_limit; /**< maximum stack depth */ + const jerry_parse_options_t *options_p; /**< parse options */ + parser_saved_context_t *last_context_p; /**< last saved context */ + parser_stack_iterator_t last_statement; /**< last statement position */ + cbc_script_t *script_p; /**< current script */ + const uint8_t *source_start_p; /**< source start */ + lit_utf8_size_t source_size; /**< source size */ + const uint8_t *arguments_start_p; /**< function argument list start */ + lit_utf8_size_t arguments_size; /**< function argument list size */ + ecma_value_t script_value; /**< current script as value */ + ecma_value_t argument_list; /**< current argument list as value */ + ecma_value_t user_value; /**< current user value */ + +#if JERRY_MODULE_SYSTEM + ecma_module_names_t *module_names_p; /**< import / export names that is being processed */ + lexer_literal_t *module_identifier_lit_p; /**< the literal for the identifier of the current element */ +#endif /* JERRY_MODULE_SYSTEM */ + + /* Lexer members. */ + lexer_token_t token; /**< current token */ + lexer_lit_object_t lit_object; /**< current literal object */ + const uint8_t *source_p; /**< next source byte */ + const uint8_t *source_end_p; /**< last source byte */ + parser_line_counter_t line; /**< current line */ + parser_line_counter_t column; /**< current column */ + + /* Scanner members. */ + scanner_info_t *next_scanner_info_p; /**< next scanner info block */ + scanner_info_t *active_scanner_info_p; /**< currently active scanner info block */ + scanner_info_t *skipped_scanner_info_p; /**< next scanner info block */ + scanner_info_t *skipped_scanner_info_end_p; /**< currently active scanner info block */ + + /* Compact byte code members. */ + cbc_argument_t last_cbc; /**< argument of the last cbc */ + uint16_t last_cbc_opcode; /**< opcode of the last cbc */ + + /* Literal types */ + uint16_t argument_count; /**< number of function arguments */ + uint16_t argument_length; /**< length property of arguments */ + uint16_t register_count; /**< number of registers */ + uint16_t literal_count; /**< number of literals */ + + /* Memory storage members. */ + parser_mem_data_t byte_code; /**< byte code buffer */ + uint32_t byte_code_size; /**< current byte code size for branches */ + parser_list_t literal_pool; /**< literal list */ + parser_mem_data_t stack; /**< storage space */ + parser_scope_stack_t *scope_stack_p; /**< scope stack */ + parser_mem_page_t *free_page_p; /**< space for fast allocation */ + uint16_t scope_stack_size; /**< size of scope stack */ + uint16_t scope_stack_top; /**< current top of scope stack */ + uint16_t scope_stack_reg_top; /**< current top register of scope stack */ + uint16_t scope_stack_global_end; /**< end of global declarations of a function */ + ecma_value_t tagged_template_literal_cp; /**< compressed pointer to the tagged template literal collection */ + parser_private_context_t *private_context_p; /**< private context */ + uint8_t stack_top_uint8; /**< top byte stored on the stack */ + +#ifndef JERRY_NDEBUG + /* Variables for debugging / logging. */ + uint16_t context_stack_depth; /**< current context stack depth */ +#endif /* !JERRY_NDEBUG */ + +#if JERRY_PARSER_DUMP_BYTE_CODE + int is_show_opcodes; /**< show opcodes */ + uint32_t total_byte_code_size; /**< total byte code size */ +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +} parser_context_t; + +/** + * @} + * @} + * @} + * + * \addtogroup mem Memory allocation + * @{ + * + * \addtogroup mem_parser Parser memory manager + * @{ + */ + +/* Memory management. + * Note: throws an error if unsuccessful. */ +void *parser_malloc (parser_context_t *context_p, size_t size); +void parser_free (void *ptr, size_t size); +void *parser_malloc_local (parser_context_t *context_p, size_t size); +void parser_free_local (void *ptr, size_t size); +void parser_free_allocated_buffer (parser_context_t *context_p); + +/* Parser byte stream. */ + +void parser_cbc_stream_init (parser_mem_data_t *data_p); +void parser_cbc_stream_free (parser_mem_data_t *data_p); +void parser_cbc_stream_alloc_page (parser_context_t *context_p, parser_mem_data_t *data_p); + +/* Parser list. Ensures pointer alignment. */ + +void parser_list_init (parser_list_t *list_p, uint32_t item_size, uint32_t item_count); +void parser_list_free (parser_list_t *list_p); +void parser_list_reset (parser_list_t *list_p); +void *parser_list_append (parser_context_t *context_p, parser_list_t *list_p); +void *parser_list_get (parser_list_t *list_p, size_t index); +void parser_list_iterator_init (parser_list_t *list_p, parser_list_iterator_t *iterator_p); +void *parser_list_iterator_next (parser_list_iterator_t *iterator_p); + +/* Parser stack. Optimized for pushing bytes. + * Pop functions never throws error. */ + +void parser_stack_init (parser_context_t *context_p); +void parser_stack_free (parser_context_t *context_p); +void parser_stack_push_uint8 (parser_context_t *context_p, uint8_t uint8_value); +void parser_stack_pop_uint8 (parser_context_t *context_p); +void parser_stack_change_last_uint8 (parser_context_t *context_p, uint8_t new_value); +uint8_t *parser_stack_get_prev_uint8 (parser_context_t *context_p); +void parser_stack_push_uint16 (parser_context_t *context_p, uint16_t uint16_value); +uint16_t parser_stack_pop_uint16 (parser_context_t *context_p); +void parser_stack_push (parser_context_t *context_p, const void *data_p, uint32_t length); +void parser_stack_pop (parser_context_t *context_p, void *data_p, uint32_t length); +void parser_stack_iterator_init (parser_context_t *context_p, parser_stack_iterator_t *iterator); +uint8_t parser_stack_iterator_read_uint8 (parser_stack_iterator_t *iterator); +void parser_stack_iterator_skip (parser_stack_iterator_t *iterator, size_t length); +void parser_stack_iterator_read (parser_stack_iterator_t *iterator, void *data_p, size_t length); +void parser_stack_iterator_write (parser_stack_iterator_t *iterator, const void *data_p, size_t length); + +/** + * @} + * @} + * + * \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_utils Utility + * @{ + */ + +/* Compact byte code emitting functions. */ + +void parser_flush_cbc (parser_context_t *context_p); +void parser_emit_cbc (parser_context_t *context_p, uint16_t opcode); +void parser_emit_cbc_literal (parser_context_t *context_p, uint16_t opcode, uint16_t literal_index); +void +parser_emit_cbc_literal_value (parser_context_t *context_p, uint16_t opcode, uint16_t literal_index, uint16_t value); +void parser_emit_cbc_literal_from_token (parser_context_t *context_p, uint16_t opcode); +void parser_emit_cbc_call (parser_context_t *context_p, uint16_t opcode, size_t call_arguments); +void parser_emit_cbc_push_number (parser_context_t *context_p, bool is_negative_number); +void parser_emit_cbc_forward_branch (parser_context_t *context_p, uint16_t opcode, parser_branch_t *branch_p); +parser_branch_node_t * +parser_emit_cbc_forward_branch_item (parser_context_t *context_p, uint16_t opcode, parser_branch_node_t *next_p); +void parser_emit_cbc_backward_branch (parser_context_t *context_p, uint16_t opcode, uint32_t offset); +ecma_string_t *parser_new_ecma_string_from_literal (lexer_literal_t *literal_p); +void parser_set_branch_to_current_position (parser_context_t *context_p, parser_branch_t *branch_p); +void parser_set_breaks_to_current_position (parser_context_t *context_p, parser_branch_node_t *current_p); +void parser_set_continues_to_current_position (parser_context_t *context_p, parser_branch_node_t *current_p); +void parser_reverse_class_fields (parser_context_t *context_p, size_t fields_size); + +/* Convenience macros. */ +#define parser_emit_cbc_ext(context_p, opcode) parser_emit_cbc ((context_p), PARSER_TO_EXT_OPCODE (opcode)) +#define parser_emit_cbc_ext_literal(context_p, opcode, literal_index) \ + parser_emit_cbc_literal ((context_p), PARSER_TO_EXT_OPCODE (opcode), (literal_index)) +#define parser_emit_cbc_ext_literal_from_token(context_p, opcode) \ + parser_emit_cbc_literal_from_token ((context_p), PARSER_TO_EXT_OPCODE (opcode)) +#define parser_emit_cbc_ext_call(context_p, opcode, call_arguments) \ + parser_emit_cbc_call ((context_p), PARSER_TO_EXT_OPCODE (opcode), (call_arguments)) +#define parser_emit_cbc_ext_call(context_p, opcode, call_arguments) \ + parser_emit_cbc_call ((context_p), PARSER_TO_EXT_OPCODE (opcode), (call_arguments)) +#define parser_emit_cbc_ext_forward_branch(context_p, opcode, branch_p) \ + parser_emit_cbc_forward_branch ((context_p), PARSER_TO_EXT_OPCODE (opcode), (branch_p)) +#define parser_emit_cbc_ext_backward_branch(context_p, opcode, offset) \ + parser_emit_cbc_backward_branch ((context_p), PARSER_TO_EXT_OPCODE (opcode), (offset)) + +/** + * @} + * + * \addtogroup jsparser_lexer Lexer + * @{ + */ + +/* Lexer functions */ + +void lexer_next_token (parser_context_t *context_p); +bool lexer_check_next_character (parser_context_t *context_p, lit_utf8_byte_t character); +bool lexer_check_next_characters (parser_context_t *context_p, lit_utf8_byte_t character1, lit_utf8_byte_t character2); +uint8_t lexer_consume_next_character (parser_context_t *context_p); +bool lexer_check_post_primary_exp (parser_context_t *context_p); +void lexer_skip_empty_statements (parser_context_t *context_p); +bool lexer_check_arrow (parser_context_t *context_p); +bool lexer_check_arrow_param (parser_context_t *context_p); +bool lexer_check_yield_no_arg (parser_context_t *context_p); +bool lexer_consume_generator (parser_context_t *context_p); +bool lexer_consume_assign (parser_context_t *context_p); +void lexer_update_await_yield (parser_context_t *context_p, uint32_t status_flags); +bool lexer_scan_private_identifier (parser_context_t *context_p); +void lexer_parse_string (parser_context_t *context_p, lexer_string_options_t opts); +void lexer_expect_identifier (parser_context_t *context_p, uint8_t literal_type); +bool lexer_scan_identifier (parser_context_t *context_p, lexer_parse_options_t opts); +void lexer_check_property_modifier (parser_context_t *context_p); +void lexer_convert_ident_to_cesu8 (uint8_t *destination_p, const uint8_t *source_p, prop_length_t length); + +const uint8_t *lexer_convert_literal_to_chars (parser_context_t *context_p, + const lexer_lit_location_t *literal_p, + uint8_t *local_byte_array_p, + lexer_string_options_t opts); +void lexer_expect_object_literal_id (parser_context_t *context_p, uint32_t ident_opts); +lexer_literal_t *lexer_construct_unused_literal (parser_context_t *context_p); +void lexer_construct_literal_object (parser_context_t *context_p, + const lexer_lit_location_t *lit_location_p, + uint8_t literal_type); +bool lexer_construct_number_object (parser_context_t *context_p, bool is_expr, bool is_negative_number); +void lexer_convert_push_number_to_push_literal (parser_context_t *context_p); +uint16_t lexer_construct_function_object (parser_context_t *context_p, uint32_t extra_status_flags); +uint16_t lexer_construct_class_static_block_function (parser_context_t *context_p); +void lexer_construct_regexp_object (parser_context_t *context_p, bool parse_only); +bool lexer_compare_identifier_to_string (const lexer_lit_location_t *left_p, const uint8_t *right_p, size_t size); +bool lexer_compare_identifiers (parser_context_t *context_p, + const lexer_lit_location_t *left_p, + const lexer_lit_location_t *right_p); +bool lexer_current_is_literal (parser_context_t *context_p, const lexer_lit_location_t *right_ident_p); +bool lexer_string_is_use_strict (parser_context_t *context_p); +bool lexer_string_is_directive (parser_context_t *context_p); +bool lexer_token_is_identifier (parser_context_t *context_p, const char *identifier_p, size_t identifier_length); +bool lexer_token_is_let (parser_context_t *context_p); +bool lexer_token_is_async (parser_context_t *context_p); +bool lexer_compare_literal_to_string (parser_context_t *context_p, const char *string_p, size_t string_length); +void lexer_init_line_info (parser_context_t *context_p); +uint8_t lexer_convert_binary_lvalue_token_to_binary (uint8_t token); + +/** + * @} + * + * \addtogroup jsparser_expr Expression parser + * @{ + */ + +/* Parser functions. */ + +void parser_parse_block_expression (parser_context_t *context_p, int options); +void parser_parse_expression_statement (parser_context_t *context_p, int options); +void parser_parse_expression (parser_context_t *context_p, int options); +void parser_resolve_private_identifier (parser_context_t *context_p); +void parser_save_private_context (parser_context_t *context_p, + parser_private_context_t *private_ctx_p, + scanner_class_info_t *class_info_p); +void parser_restore_private_context (parser_context_t *context_p, parser_private_context_t *private_ctx_p); +void parser_parse_class (parser_context_t *context_p, bool is_statement); +void parser_parse_initializer (parser_context_t *context_p, parser_pattern_flags_t flags); +void parser_parse_initializer_by_next_char (parser_context_t *context_p, parser_pattern_flags_t flags); +/** + * @} + * + * \addtogroup jsparser_scanner Scanner + * @{ + */ + +void scanner_release_next (parser_context_t *context_p, size_t size); +void scanner_set_active (parser_context_t *context_p); +void scanner_revert_active (parser_context_t *context_p); +void scanner_release_active (parser_context_t *context_p, size_t size); +void scanner_release_switch_cases (scanner_case_info_t *case_p); +void scanner_release_private_fields (scanner_class_private_member_t *member_p); +void scanner_seek (parser_context_t *context_p); +void scanner_reverse_info_list (parser_context_t *context_p); +void scanner_cleanup (parser_context_t *context_p); + +bool scanner_is_context_needed (parser_context_t *context_p, parser_check_context_type_t check_type); +bool scanner_try_scan_new_target (parser_context_t *context_p); +void scanner_check_variables (parser_context_t *context_p); +void scanner_create_variables (parser_context_t *context_p, uint32_t option_flags); + +void scanner_get_location (scanner_location_t *location_p, parser_context_t *context_p); +void scanner_set_location (parser_context_t *context_p, scanner_location_t *location_p); +uint16_t scanner_decode_map_to (parser_scope_stack_t *stack_item_p); +uint16_t scanner_save_literal (parser_context_t *context_p, uint16_t ident_index); +bool scanner_literal_is_const_reg (parser_context_t *context_p, uint16_t literal_index); +bool scanner_literal_is_created (parser_context_t *context_p, uint16_t literal_index); +bool scanner_literal_exists (parser_context_t *context_p, uint16_t literal_index); + +void scanner_scan_all (parser_context_t *context_p); + +/** + * @} + * + * \addtogroup jsparser_stmt Statement parser + * @{ + */ + +void parser_parse_statements (parser_context_t *context_p); +void parser_free_jumps (parser_stack_iterator_t iterator); + +#if JERRY_MODULE_SYSTEM +/** + * @} + * + * \addtogroup jsparser_stmt Module statement parser + * @{ + */ + +extern const lexer_lit_location_t lexer_default_literal; +void parser_module_check_request_place (parser_context_t *context_p); +void parser_module_context_init (parser_context_t *context_p); +void parser_module_append_names (parser_context_t *context_p, ecma_module_names_t **module_names_p); +void parser_module_handle_module_specifier (parser_context_t *context_p, ecma_module_node_t **node_list_p); +void parser_module_handle_requests (parser_context_t *context_p); +void parser_module_parse_export_clause (parser_context_t *context_p); +void parser_module_parse_import_clause (parser_context_t *context_p); +void parser_module_set_default (parser_context_t *context_p); +bool parser_module_check_duplicate_import (parser_context_t *context_p, ecma_string_t *local_name_p); +bool parser_module_check_duplicate_export (parser_context_t *context_p, ecma_string_t *export_name_p); +void parser_module_append_export_name (parser_context_t *context_p); +void +parser_module_add_names_to_node (parser_context_t *context_p, ecma_string_t *imex_name_p, ecma_string_t *local_name_p); + +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * @} + * + * \addtogroup jsparser_parser Parser + * @{ + */ + +ecma_compiled_code_t *parser_parse_function (parser_context_t *context_p, uint32_t status_flags); +ecma_compiled_code_t *parser_parse_class_static_block (parser_context_t *context_p); +ecma_compiled_code_t *parser_parse_arrow_function (parser_context_t *context_p, uint32_t status_flags); +ecma_compiled_code_t *parser_parse_class_fields (parser_context_t *context_p); +void parser_set_function_name (parser_context_t *context_p, + uint16_t function_literal_index, + uint16_t name_index, + uint32_t status_flags); +void parser_compiled_code_set_function_name (parser_context_t *context_p, + ecma_compiled_code_t *bytecode_p, + uint16_t name_index, + uint32_t status_flags); +uint16_t parser_check_anonymous_function_declaration (parser_context_t *context_p); + +/* Error management. */ + +void parser_raise_error (parser_context_t *context_p, parser_error_msg_t error); + +#if JERRY_PARSER_DUMP_BYTE_CODE +void util_print_cbc (ecma_compiled_code_t *compiled_code_p); +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +/** + * @} + * @} + * @} + */ + +#endif /* !JS_PARSER_INTERNAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-limits.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-limits.h new file mode 100644 index 0000000..b0059d8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-limits.h @@ -0,0 +1,130 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JS_PARSER_LIMITS_H +#define JS_PARSER_LIMITS_H + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_internals Internals + * @{ + */ + +/** + * Maximum identifier length accepted by the parser. + * Limit: LEXER_MAX_STRING_LENGTH. + */ +#ifndef PARSER_MAXIMUM_IDENT_LENGTH +#define PARSER_MAXIMUM_IDENT_LENGTH 255 +#endif /* !PARSER_MAXIMUM_IDENT_LENGTH */ + +/** + * Maximum string limit. + * Limit: 2147483647 / 65535. + */ +#define PARSER_MAXIMUM_STRING_LIMIT 65535 + +/** + * Maximum string length. + * Limit: PARSER_MAXIMUM_STRING_LIMIT. + */ +#ifndef PARSER_MAXIMUM_STRING_LENGTH +#define PARSER_MAXIMUM_STRING_LENGTH PARSER_MAXIMUM_STRING_LIMIT +#endif /* !PARSER_MAXIMUM_STRING_LENGTH */ + +/** + * Maximum number of registers. + * Limit: min: 256, max: min(PARSER_MAXIMUM_NUMBER_OF_LITERALS / 2, 16383) + */ +#ifndef PARSER_MAXIMUM_NUMBER_OF_REGISTERS +#define PARSER_MAXIMUM_NUMBER_OF_REGISTERS 256 +#endif /* !PARSER_MAXIMUM_NUMBER_OF_REGISTERS */ + +/** + * Maximum number of literals. + * Limit: 32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS. Recommended: 32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS. + */ +#ifndef PARSER_MAXIMUM_NUMBER_OF_LITERALS +#define PARSER_MAXIMUM_NUMBER_OF_LITERALS (32767 - PARSER_MAXIMUM_NUMBER_OF_REGISTERS) +#endif /* !PARSER_MAXIMUM_NUMBER_OF_LITERALS */ + +/** + * Maximum depth of scope stack. + * Limit: 32767. Recommended: 32767 + */ +#ifndef PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK +#define PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK 32767 +#endif /* !PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK */ + +/** + * Maximum code size. + * Limit: 16777215. Recommended: 65535, 16777215. + */ +#ifndef PARSER_MAXIMUM_CODE_SIZE +#define PARSER_MAXIMUM_CODE_SIZE (65535 << (JMEM_ALIGNMENT_LOG)) +#endif /* !PARSER_MAXIMUM_CODE_SIZE */ + +/** + * Maximum number of values pushed onto the stack by a function. + * Limit: 65500. Recommended: 1024. + */ +#ifndef PARSER_MAXIMUM_STACK_LIMIT +#define PARSER_MAXIMUM_STACK_LIMIT 1024 + +#endif /* !PARSER_MAXIMUM_STACK_LIMIT */ + +/* Checks. */ + +#if (PARSER_MAXIMUM_STRING_LENGTH < 1) || (PARSER_MAXIMUM_STRING_LENGTH > PARSER_MAXIMUM_STRING_LIMIT) +#error "Maximum string length is not within range." +#endif /* (PARSER_MAXIMUM_STRING_LENGTH < 1) || (PARSER_MAXIMUM_STRING_LENGTH > PARSER_MAXIMUM_STRING_LIMIT) */ + +#if (PARSER_MAXIMUM_IDENT_LENGTH < 1) || (PARSER_MAXIMUM_IDENT_LENGTH > PARSER_MAXIMUM_STRING_LENGTH) +#error "Maximum identifier length is not within range." +#endif /* (PARSER_MAXIMUM_IDENT_LENGTH < 1) || (PARSER_MAXIMUM_IDENT_LENGTH > PARSER_MAXIMUM_STRING_LENGTH) */ + +#if ((PARSER_MAXIMUM_NUMBER_OF_LITERALS < 1) \ + || (PARSER_MAXIMUM_NUMBER_OF_LITERALS + PARSER_MAXIMUM_NUMBER_OF_REGISTERS > 32767)) +#error "Maximum number of literals is not within range." +#endif /* ((PARSER_MAXIMUM_NUMBER_OF_LITERALS < 1) \ + || (PARSER_MAXIMUM_NUMBER_OF_LITERALS > 32767)) */ + +#if (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK < 1) || (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK > 32767) +#error "Maximum depth of scope stack is not within range." +#endif /* (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK < 1) || (PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK > 32767) */ + +#if ((PARSER_MAXIMUM_NUMBER_OF_REGISTERS * 2) > PARSER_MAXIMUM_NUMBER_OF_LITERALS) +#error "Maximum number of registers is not within range." +#endif /* ((PARSER_MAXIMUM_NUMBER_OF_REGISTERS * 2) > PARSER_MAXIMUM_NUMBER_OF_LITERALS) */ + +#if (PARSER_MAXIMUM_CODE_SIZE < 4096) || (PARSER_MAXIMUM_CODE_SIZE > 16777215) +#error "Maximum code size is not within range." +#endif /* (PARSER_MAXIMUM_CODE_SIZE < 4096) || (PARSER_MAXIMUM_CODE_SIZE > 16777215) */ + +#if (PARSER_MAXIMUM_STACK_LIMIT < 16) || (PARSER_MAXIMUM_STACK_LIMIT > 65500) +#error "Maximum function stack usage is not within range." +#endif /* (PARSER_MAXIMUM_STACK_LIMIT < 16) || (PARSER_MAXIMUM_STACK_LIMIT > 65500) */ + +/** + * @} + * @} + * @} + */ + +#endif /* !JS_PARSER_LIMITS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-mem.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-mem.cpp new file mode 100644 index 0000000..4c8d2b6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-mem.cpp @@ -0,0 +1,729 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-internal.h" + +#if JERRY_PARSER + +/** \addtogroup mem Memory allocation + * @{ + * + * \addtogroup mem_parser Parser memory manager + * @{ + */ + +/**********************************************************************/ +/* Memory allocation */ +/**********************************************************************/ + +/** + * Allocate memory. + * + * @return allocated memory. + */ +void * +parser_malloc (parser_context_t *context_p, /**< context */ + size_t size) /**< size of the memory block */ +{ + void *result; + + JERRY_ASSERT (size > 0); + result = jmem_heap_alloc_block_null_on_error (size); + + if (result == NULL) + { + parser_raise_error (context_p, PARSER_ERR_OUT_OF_MEMORY); + } + return result; +} /* parser_malloc */ + +/** + * Free memory allocated by parser_malloc. + */ +void +parser_free (void *ptr, /**< pointer to free */ + size_t size) /**< size of the memory block */ +{ + jmem_heap_free_block (ptr, size); +} /* parser_free */ + +/** + * Allocate local memory for short term use. + * + * @return allocated memory. + */ +void * +parser_malloc_local (parser_context_t *context_p, /**< context */ + size_t size) /**< size of the memory */ +{ + void *result; + + JERRY_ASSERT (size > 0); + result = jmem_heap_alloc_block (size); + if (result == 0) + { + parser_raise_error (context_p, PARSER_ERR_OUT_OF_MEMORY); + } + return result; +} /* parser_malloc_local */ + +/** + * Free memory allocated by parser_malloc_local. + */ +void +parser_free_local (void *ptr, /**< pointer to free */ + size_t size) /**< size of the memory */ +{ + jmem_heap_free_block (ptr, size); +} /* parser_free_local */ + +/** + * Free the dynamically allocated buffer stored in the context + */ +void +parser_free_allocated_buffer (parser_context_t *context_p) /**< context */ +{ + if (context_p->u.allocated_buffer_p != NULL) + { + parser_free_local (context_p->u.allocated_buffer_p, context_p->allocated_buffer_size); + context_p->u.allocated_buffer_p = NULL; + } +} /* parser_free_allocated_buffer */ + +/**********************************************************************/ +/* Parser data management functions */ +/**********************************************************************/ + +/** + * Initialize parse data. + */ +static void +parser_data_init (parser_mem_data_t *data_p, /**< memory manager */ + uint32_t page_size) /**< size of each page */ +{ + data_p->first_p = NULL; + data_p->last_p = NULL; + data_p->last_position = page_size; +} /* parser_data_init */ + +/** + * Free parse data. + */ +static void +parser_data_free (parser_mem_data_t *data_p, /**< memory manager */ + uint32_t page_size) /**< size of each page */ +{ + parser_mem_page_t *page_p = data_p->first_p; + + while (page_p != NULL) + { + parser_mem_page_t *next_p = page_p->next_p; + + parser_free (page_p, page_size); + page_p = next_p; + } +} /* parser_data_free */ + +/**********************************************************************/ +/* Parser byte stream management functions */ +/**********************************************************************/ + +/** + * Initialize byte stream. + */ +void +parser_cbc_stream_init (parser_mem_data_t *data_p) /**< memory manager */ +{ + parser_data_init (data_p, PARSER_CBC_STREAM_PAGE_SIZE); +} /* parser_cbc_stream_init */ + +/** + * Free byte stream. + */ +void +parser_cbc_stream_free (parser_mem_data_t *data_p) /**< memory manager */ +{ + parser_data_free (data_p, sizeof (parser_mem_page_t *) + PARSER_CBC_STREAM_PAGE_SIZE); +} /* parser_cbc_stream_free */ + +/** + * Appends a byte at the end of the byte stream. + */ +void +parser_cbc_stream_alloc_page (parser_context_t *context_p, /**< context */ + parser_mem_data_t *data_p) /**< memory manager */ +{ + size_t size = sizeof (parser_mem_page_t *) + PARSER_CBC_STREAM_PAGE_SIZE; + parser_mem_page_t *page_p = (parser_mem_page_t *) parser_malloc (context_p, size); + + page_p->next_p = NULL; + data_p->last_position = 0; + + if (data_p->last_p != NULL) + { + data_p->last_p->next_p = page_p; + } + else + { + data_p->first_p = page_p; + } + data_p->last_p = page_p; +} /* parser_cbc_stream_alloc_page */ + +/**********************************************************************/ +/* Parser list management functions */ +/**********************************************************************/ + +/** + * Initialize parser list. + */ +void +parser_list_init (parser_list_t *list_p, /**< parser list */ + uint32_t item_size, /**< size for each page */ + uint32_t item_count) /**< number of items on each page */ +{ + /* Align to pointer size. */ + item_size = (uint32_t) (((item_size) + sizeof (void *) - 1) & ~(sizeof (void *) - 1)); + parser_data_init (&list_p->data, item_size * item_count); + list_p->page_size = item_size * item_count; + list_p->item_size = item_size; + list_p->item_count = item_count; +} /* parser_list_init */ + +/** + * Free parser list. + */ +void +parser_list_free (parser_list_t *list_p) /**< parser list */ +{ + parser_data_free (&list_p->data, (uint32_t) (sizeof (parser_mem_page_t *) + list_p->page_size)); +} /* parser_list_free */ + +/** + * Reset parser list. + */ +void +parser_list_reset (parser_list_t *list_p) /**< parser list */ +{ + parser_data_init (&list_p->data, list_p->page_size); +} /* parser_list_reset */ + +/** + * Allocate space for the next item. + * + * @return pointer to the appended item. + */ +void * +parser_list_append (parser_context_t *context_p, /**< context */ + parser_list_t *list_p) /**< parser list */ +{ + parser_mem_page_t *page_p = list_p->data.last_p; + void *result; + + if (list_p->data.last_position + list_p->item_size > list_p->page_size) + { + size_t size = sizeof (parser_mem_page_t *) + list_p->page_size; + + page_p = (parser_mem_page_t *) parser_malloc (context_p, size); + + page_p->next_p = NULL; + list_p->data.last_position = 0; + + if (list_p->data.last_p != NULL) + { + list_p->data.last_p->next_p = page_p; + } + else + { + list_p->data.first_p = page_p; + } + list_p->data.last_p = page_p; + } + + result = page_p->bytes + list_p->data.last_position; + list_p->data.last_position += list_p->item_size; + return result; +} /* parser_list_append */ + +/** + * Return the nth item of the list. + * + * @return pointer to the item. + */ +void * +parser_list_get (parser_list_t *list_p, /**< parser list */ + size_t index) /**< item index */ +{ + size_t item_count = list_p->item_count; + parser_mem_page_t *page_p = list_p->data.first_p; + + while (index >= item_count) + { + JERRY_ASSERT (page_p != NULL); + page_p = page_p->next_p; + index -= item_count; + } + + JERRY_ASSERT (page_p != NULL); + JERRY_ASSERT (page_p != list_p->data.last_p || (index * list_p->item_size < list_p->data.last_position)); + return page_p->bytes + (index * list_p->item_size); +} /* parser_list_get */ + +/** + * Initialize a parser list iterator. + */ +void +parser_list_iterator_init (parser_list_t *list_p, /**< parser list */ + parser_list_iterator_t *iterator_p) /**< iterator */ +{ + iterator_p->list_p = list_p; + iterator_p->current_p = list_p->data.first_p; + iterator_p->current_position = 0; +} /* parser_list_iterator_init */ + +/** + * Next iterator step. + * + * @return the address of the current item, or NULL at the end. + */ +void * +parser_list_iterator_next (parser_list_iterator_t *iterator_p) /**< iterator */ +{ + void *result; + + if (iterator_p->current_p == NULL) + { + return NULL; + } + + result = iterator_p->current_p->bytes + iterator_p->current_position; + iterator_p->current_position += iterator_p->list_p->item_size; + + if (iterator_p->current_p->next_p == NULL) + { + if (iterator_p->current_position >= iterator_p->list_p->data.last_position) + { + iterator_p->current_p = NULL; + iterator_p->current_position = 0; + } + } + else if (iterator_p->current_position >= iterator_p->list_p->page_size) + { + iterator_p->current_p = iterator_p->current_p->next_p; + iterator_p->current_position = 0; + } + return result; +} /* parser_list_iterator_next */ + +/**********************************************************************/ +/* Parser stack management functions */ +/**********************************************************************/ + +/* Stack is a reversed storage. */ + +/** + * Initialize parser stack. + */ +void +parser_stack_init (parser_context_t *context_p) /**< context */ +{ + parser_data_init (&context_p->stack, PARSER_STACK_PAGE_SIZE); + context_p->free_page_p = NULL; +} /* parser_stack_init */ + +/** + * Free parser stack. + */ +void +parser_stack_free (parser_context_t *context_p) /**< context */ +{ + parser_data_free (&context_p->stack, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + + if (context_p->free_page_p != NULL) + { + parser_free (context_p->free_page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + } +} /* parser_stack_free */ + +/** + * Pushes an uint8_t value onto the stack. + */ +void +parser_stack_push_uint8 (parser_context_t *context_p, /**< context */ + uint8_t uint8_value) /**< value pushed onto the stack */ +{ + parser_mem_page_t *page_p = context_p->stack.first_p; + + /* This assert might trigger false positive valgrind errors, when + * parser_stack_push() pushes not fully initialized structures. + * More precisely when the last byte of the structure is uninitialized. */ + JERRY_ASSERT (page_p == NULL || context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + + if (context_p->stack.last_position >= PARSER_STACK_PAGE_SIZE) + { + if (context_p->free_page_p != NULL) + { + page_p = context_p->free_page_p; + context_p->free_page_p = NULL; + } + else + { + size_t size = sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE; + page_p = (parser_mem_page_t *) parser_malloc (context_p, size); + } + + page_p->next_p = context_p->stack.first_p; + context_p->stack.last_position = 0; + context_p->stack.first_p = page_p; + } + + page_p->bytes[context_p->stack.last_position++] = uint8_value; + context_p->stack_top_uint8 = uint8_value; +} /* parser_stack_push_uint8 */ + +/** + * Pops the last uint8_t value from the stack. + */ +void +parser_stack_pop_uint8 (parser_context_t *context_p) /**< context */ +{ + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + + context_p->stack.last_position--; + + if (context_p->stack.last_position == 0) + { + context_p->stack.first_p = page_p->next_p; + context_p->stack.last_position = PARSER_STACK_PAGE_SIZE; + + if (context_p->free_page_p == NULL) + { + context_p->free_page_p = page_p; + } + else + { + parser_free (page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + } + + page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL); + } + + context_p->stack_top_uint8 = page_p->bytes[context_p->stack.last_position - 1]; +} /* parser_stack_pop_uint8 */ + +/** + * Change last byte of the stack. + */ +void +parser_stack_change_last_uint8 (parser_context_t *context_p, /**< context */ + uint8_t new_value) /**< new value */ +{ + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + + page_p->bytes[context_p->stack.last_position - 1] = new_value; + context_p->stack_top_uint8 = new_value; +} /* parser_stack_change_last_uint8 */ + +/** + * Get the uint8 value before the top of the stack. + * + * Pointer to the uint8 value + */ +uint8_t * +parser_stack_get_prev_uint8 (parser_context_t *context_p) /**< context */ +{ + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL && (context_p->stack.last_position >= 2 || page_p->next_p != NULL)); + + if (context_p->stack.last_position >= 2) + { + return page_p->bytes + (context_p->stack.last_position - 2); + } + + return page_p->next_p->bytes + (PARSER_STACK_PAGE_SIZE - 1); +} /* parser_stack_get_prev_uint8 */ + +/** + * Pushes an uint16_t value onto the stack. + */ +void +parser_stack_push_uint16 (parser_context_t *context_p, /**< context */ + uint16_t uint16_value) /**< value pushed onto the stack */ +{ + if (context_p->stack.last_position + 2 <= PARSER_STACK_PAGE_SIZE) + { + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + + page_p->bytes[context_p->stack.last_position++] = (uint8_t) (uint16_value >> 8); + page_p->bytes[context_p->stack.last_position++] = (uint8_t) uint16_value; + context_p->stack_top_uint8 = (uint8_t) uint16_value; + } + else + { + parser_stack_push_uint8 (context_p, (uint8_t) (uint16_value >> 8)); + parser_stack_push_uint8 (context_p, (uint8_t) uint16_value); + } +} /* parser_stack_push_uint16 */ + +/** + * Pops the last uint16_t value from the stack. + * + * @return the value popped from the stack. + */ +uint16_t +parser_stack_pop_uint16 (parser_context_t *context_p) /**< context */ +{ + uint32_t value = context_p->stack_top_uint8; + + if (context_p->stack.last_position >= 3) + { + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (page_p != NULL && context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]); + + value |= ((uint32_t) page_p->bytes[context_p->stack.last_position - 2]) << 8; + context_p->stack_top_uint8 = page_p->bytes[context_p->stack.last_position - 3]; + context_p->stack.last_position -= 2; + } + else + { + parser_stack_pop_uint8 (context_p); + value |= ((uint32_t) context_p->stack_top_uint8) << 8; + parser_stack_pop_uint8 (context_p); + } + return (uint16_t) value; +} /* parser_stack_pop_uint16 */ + +/** + * Pushes a data onto the stack. + */ +void +parser_stack_push (parser_context_t *context_p, /**< context */ + const void *data_p, /**< data pushed onto the stack */ + uint32_t length) /**< length of the data */ +{ + uint32_t fragment_length = PARSER_STACK_PAGE_SIZE - context_p->stack.last_position; + const uint8_t *bytes_p = (const uint8_t *) data_p; + parser_mem_page_t *page_p; + + JERRY_ASSERT (length < PARSER_STACK_PAGE_SIZE && length > 0); + + context_p->stack_top_uint8 = bytes_p[length - 1]; + + if (fragment_length > 0) + { + /* Fill the remaining bytes. */ + if (fragment_length > length) + { + fragment_length = length; + } + + memcpy (context_p->stack.first_p->bytes + context_p->stack.last_position, bytes_p, fragment_length); + + if (fragment_length == length) + { + context_p->stack.last_position += length; + return; + } + + bytes_p += fragment_length; + length -= fragment_length; + } + + if (context_p->free_page_p != NULL) + { + page_p = context_p->free_page_p; + context_p->free_page_p = NULL; + } + else + { + size_t size = sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE; + + page_p = (parser_mem_page_t *) parser_malloc (context_p, size); + } + + page_p->next_p = context_p->stack.first_p; + + context_p->stack.first_p = page_p; + + memcpy (page_p->bytes, bytes_p, length); + context_p->stack.last_position = length; +} /* parser_stack_push */ + +/** + * Pop bytes from the top of the stack. + */ +void +parser_stack_pop (parser_context_t *context_p, /**< context */ + void *data_p, /**< destination buffer, can be NULL */ + uint32_t length) /**< length of the data */ +{ + uint8_t *bytes_p = (uint8_t *) data_p; + parser_mem_page_t *page_p = context_p->stack.first_p; + + JERRY_ASSERT (length < PARSER_STACK_PAGE_SIZE && length > 0); + + if (context_p->stack.last_position > length) + { + context_p->stack.last_position -= length; + context_p->stack_top_uint8 = page_p->bytes[context_p->stack.last_position - 1]; + + if (bytes_p != NULL) + { + memcpy (bytes_p, context_p->stack.first_p->bytes + context_p->stack.last_position, length); + } + return; + } + + JERRY_ASSERT (page_p->next_p != NULL); + + length -= context_p->stack.last_position; + + if (bytes_p != NULL) + { + memcpy (bytes_p + length, page_p->bytes, context_p->stack.last_position); + } + + context_p->stack.first_p = page_p->next_p; + context_p->stack.last_position = PARSER_STACK_PAGE_SIZE - length; + context_p->stack_top_uint8 = page_p->next_p->bytes[context_p->stack.last_position - 1]; + + if (bytes_p != NULL && length > 0) + { + memcpy (bytes_p, page_p->next_p->bytes + context_p->stack.last_position, length); + } + + JERRY_ASSERT (context_p->stack.last_position > 0); + + if (context_p->free_page_p == NULL) + { + context_p->free_page_p = page_p; + } + else + { + parser_free (page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE); + } +} /* parser_stack_pop */ + +/** + * Initialize stack iterator. + */ +void +parser_stack_iterator_init (parser_context_t *context_p, /**< context */ + parser_stack_iterator_t *iterator) /**< iterator */ +{ + iterator->current_p = context_p->stack.first_p; + iterator->current_position = context_p->stack.last_position; +} /* parser_stack_iterator_init */ + +/** + * Read the next byte from the stack. + * + * @return byte + */ +uint8_t +parser_stack_iterator_read_uint8 (parser_stack_iterator_t *iterator) /**< iterator */ +{ + JERRY_ASSERT (iterator->current_position > 0 && iterator->current_position <= PARSER_STACK_PAGE_SIZE); + return iterator->current_p->bytes[iterator->current_position - 1]; +} /* parser_stack_iterator_read_uint8 */ + +/** + * Skip the next n bytes of the stack. + */ +void +parser_stack_iterator_skip (parser_stack_iterator_t *iterator, /**< iterator */ + size_t length) /**< number of skipped bytes */ +{ + JERRY_ASSERT (length < PARSER_STACK_PAGE_SIZE && length > 0); + + if (length < iterator->current_position) + { + iterator->current_position -= length; + } + else + { + iterator->current_position = PARSER_STACK_PAGE_SIZE - (length - iterator->current_position); + iterator->current_p = iterator->current_p->next_p; + } +} /* parser_stack_iterator_skip */ + +/** + * Read bytes from the stack. + */ +void +parser_stack_iterator_read (parser_stack_iterator_t *iterator, /**< iterator */ + void *data_p, /**< destination buffer */ + size_t length) /**< length of the data */ +{ + uint8_t *bytes_p = (uint8_t *) data_p; + + JERRY_ASSERT (length < PARSER_STACK_PAGE_SIZE && length > 0); + + if (length <= iterator->current_position) + { + memcpy (bytes_p, iterator->current_p->bytes + iterator->current_position - length, length); + } + else + { + JERRY_ASSERT (iterator->current_p->next_p != NULL); + + length -= iterator->current_position; + memcpy (bytes_p + length, iterator->current_p->bytes, iterator->current_position); + memcpy (bytes_p, iterator->current_p->next_p->bytes + PARSER_STACK_PAGE_SIZE - length, length); + } +} /* parser_stack_iterator_read */ + +/** + * Write bytes onto the stack. + */ +void +parser_stack_iterator_write (parser_stack_iterator_t *iterator, /**< iterator */ + const void *data_p, /**< destination buffer */ + size_t length) /**< length of the data */ +{ + const uint8_t *bytes_p = (const uint8_t *) data_p; + + JERRY_ASSERT (length < PARSER_STACK_PAGE_SIZE && length > 0); + + if (length <= iterator->current_position) + { + memcpy (iterator->current_p->bytes + iterator->current_position - length, bytes_p, length); + } + else + { + JERRY_ASSERT (iterator->current_p->next_p != NULL); + + length -= iterator->current_position; + memcpy (iterator->current_p->bytes, bytes_p + length, iterator->current_position); + memcpy (iterator->current_p->next_p->bytes + PARSER_STACK_PAGE_SIZE - length, bytes_p, length); + } +} /* parser_stack_iterator_write */ + +/** + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-module.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-module.cpp new file mode 100644 index 0000000..465f812 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-module.cpp @@ -0,0 +1,529 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-internal.h" + +#if JERRY_MODULE_SYSTEM +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-lex-env.h" +#include "ecma-module.h" + +#include "jcontext.h" + +/** + * Description of "*default*" literal string. + */ +const lexer_lit_location_t lexer_default_literal = { (const uint8_t *) "*default*", + 9, + LEXER_IDENT_LITERAL, + LEXER_LIT_LOCATION_IS_ASCII }; + +/** + * Check for duplicated imported binding names. + * + * @return true - if the given name is a duplicate + * false - otherwise + */ +bool +parser_module_check_duplicate_import (parser_context_t *context_p, /**< parser context */ + ecma_string_t *local_name_p) /**< newly imported name */ +{ + ecma_module_names_t *module_names_p = context_p->module_names_p; + + while (module_names_p != NULL) + { + if (ecma_compare_ecma_strings (module_names_p->local_name_p, local_name_p)) + { + return true; + } + + module_names_p = module_names_p->next_p; + } + + ecma_module_node_t *module_node_p = JERRY_CONTEXT (module_current_p)->imports_p; + + while (module_node_p != NULL) + { + module_names_p = module_node_p->module_names_p; + + while (module_names_p != NULL) + { + if (ecma_compare_ecma_strings (module_names_p->local_name_p, local_name_p)) + { + return true; + } + + module_names_p = module_names_p->next_p; + } + + module_node_p = module_node_p->next_p; + } + + return false; +} /* parser_module_check_duplicate_import */ + +/** + * Append an identifier to the exported bindings. + */ +void +parser_module_append_export_name (parser_context_t *context_p) /**< parser context */ +{ + if (!(context_p->status_flags & PARSER_MODULE_STORE_IDENT)) + { + return; + } + + context_p->module_identifier_lit_p = context_p->lit_object.literal_p; + ecma_string_t *name_p = parser_new_ecma_string_from_literal (context_p->lit_object.literal_p); + + if (parser_module_check_duplicate_export (context_p, name_p)) + { + ecma_deref_ecma_string (name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER); + } + + parser_module_add_names_to_node (context_p, name_p, name_p); + ecma_deref_ecma_string (name_p); +} /* parser_module_append_export_name */ + +/** + * Check for duplicated exported bindings. + * @return - true - if the exported name is a duplicate + * false - otherwise + */ +bool +parser_module_check_duplicate_export (parser_context_t *context_p, /**< parser context */ + ecma_string_t *export_name_p) /**< exported identifier */ +{ + /* We have to check in the currently constructed node, as well as all of the already added nodes. */ + ecma_module_names_t *current_names_p = context_p->module_names_p; + + while (current_names_p != NULL) + { + if (ecma_compare_ecma_strings (current_names_p->imex_name_p, export_name_p)) + { + return true; + } + current_names_p = current_names_p->next_p; + } + + ecma_module_names_t *name_p = JERRY_CONTEXT (module_current_p)->local_exports_p; + + while (name_p != NULL) + { + if (ecma_compare_ecma_strings (name_p->imex_name_p, export_name_p)) + { + return true; + } + + name_p = name_p->next_p; + } + + ecma_module_node_t *export_node_p = JERRY_CONTEXT (module_current_p)->indirect_exports_p; + + while (export_node_p != NULL) + { + name_p = export_node_p->module_names_p; + + while (name_p != NULL) + { + if (ecma_compare_ecma_strings (name_p->imex_name_p, export_name_p)) + { + return true; + } + + name_p = name_p->next_p; + } + + export_node_p = export_node_p->next_p; + } + + /* Star exports don't have any names associated with them, so no need to check those. */ + return false; +} /* parser_module_check_duplicate_export */ + +/** + * Add module names to current module node. + */ +void +parser_module_add_names_to_node (parser_context_t *context_p, /**< parser context */ + ecma_string_t *imex_name_p, /**< import/export name */ + ecma_string_t *local_name_p) /**< local name */ +{ + ecma_module_names_t *new_name_p = (ecma_module_names_t *) parser_malloc (context_p, sizeof (ecma_module_names_t)); + + new_name_p->next_p = context_p->module_names_p; + context_p->module_names_p = new_name_p; + + JERRY_ASSERT (imex_name_p != NULL); + ecma_ref_ecma_string (imex_name_p); + new_name_p->imex_name_p = imex_name_p; + + JERRY_ASSERT (local_name_p != NULL); + ecma_ref_ecma_string (local_name_p); + new_name_p->local_name_p = local_name_p; +} /* parser_module_add_names_to_node */ + +/** + * Parse an ExportClause. + */ +void +parser_module_parse_export_clause (parser_context_t *context_p) /**< parser context */ +{ + bool has_module_specifier = false; + + if (context_p->source_p == context_p->next_scanner_info_p->source_p) + { + has_module_specifier = true; + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_EXPORT_MODULE_SPECIFIER); + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE); + lexer_next_token (context_p); + + while (true) + { + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + lexer_next_token (context_p); + break; + } + + /* 15.2.3.1 The referenced binding cannot be a reserved word. */ + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL + || context_p->token.keyword_type >= LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + ecma_string_t *export_name_p = NULL; + ecma_string_t *local_name_p = NULL; + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + + if (!has_module_specifier && !scanner_literal_exists (context_p, context_p->lit_object.index)) + { + parser_raise_error (context_p, PARSER_ERR_EXPORT_NOT_DEFINED); + } + + uint16_t local_name_index = context_p->lit_object.index; + uint16_t export_name_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS; + + lexer_next_token (context_p); + if (lexer_token_is_identifier (context_p, "as", 2)) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + + export_name_index = context_p->lit_object.index; + + lexer_next_token (context_p); + } + + local_name_p = parser_new_ecma_string_from_literal (PARSER_GET_LITERAL (local_name_index)); + + if (export_name_index != PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + export_name_p = parser_new_ecma_string_from_literal (PARSER_GET_LITERAL (export_name_index)); + } + else + { + export_name_p = local_name_p; + ecma_ref_ecma_string (local_name_p); + } + + if (parser_module_check_duplicate_export (context_p, export_name_p)) + { + ecma_deref_ecma_string (local_name_p); + ecma_deref_ecma_string (export_name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER); + } + + parser_module_add_names_to_node (context_p, export_name_p, local_name_p); + ecma_deref_ecma_string (local_name_p); + ecma_deref_ecma_string (export_name_p); + + if (context_p->token.type != LEXER_COMMA && context_p->token.type != LEXER_RIGHT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED); + } + else if (context_p->token.type == LEXER_COMMA) + { + lexer_next_token (context_p); + } + + if (lexer_token_is_identifier (context_p, "from", 4)) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED); + } + } +} /* parser_module_parse_export_clause */ + +/** + * Parse an ImportClause + */ +void +parser_module_parse_import_clause (parser_context_t *context_p) /**< parser context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE); + lexer_next_token (context_p); + + while (true) + { + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + lexer_next_token (context_p); + break; + } + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED); + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + + ecma_string_t *import_name_p = NULL; + ecma_string_t *local_name_p = NULL; + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + + uint16_t import_name_index = context_p->lit_object.index; + uint16_t local_name_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS; + + lexer_next_token (context_p); + if (lexer_token_is_identifier (context_p, "as", 2)) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED); + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + + local_name_index = context_p->lit_object.index; + + lexer_next_token (context_p); + } + + import_name_p = parser_new_ecma_string_from_literal (PARSER_GET_LITERAL (import_name_index)); + + if (local_name_index != PARSER_MAXIMUM_NUMBER_OF_LITERALS) + { + local_name_p = parser_new_ecma_string_from_literal (PARSER_GET_LITERAL (local_name_index)); + } + else + { + local_name_p = import_name_p; + ecma_ref_ecma_string (local_name_p); + } + + if (parser_module_check_duplicate_import (context_p, local_name_p)) + { + ecma_deref_ecma_string (local_name_p); + ecma_deref_ecma_string (import_name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_IMPORT_BINDING); + } + + parser_module_add_names_to_node (context_p, import_name_p, local_name_p); + ecma_deref_ecma_string (local_name_p); + ecma_deref_ecma_string (import_name_p); + + if (context_p->token.type != LEXER_COMMA && (context_p->token.type != LEXER_RIGHT_BRACE)) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED); + } + else if (context_p->token.type == LEXER_COMMA) + { + lexer_next_token (context_p); + } + + if (lexer_token_is_identifier (context_p, "from", 4)) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED); + } + } +} /* parser_module_parse_import_clause */ + +/** + * Raises parser error if the import or export statement is not in the global scope. + */ +void +parser_module_check_request_place (parser_context_t *context_p) /**< parser context */ +{ + if (context_p->last_context_p != NULL || context_p->stack_top_uint8 != 0 + || (context_p->status_flags & PARSER_IS_FUNCTION) || (context_p->global_status_flags & ECMA_PARSE_EVAL) + || (context_p->global_status_flags & ECMA_PARSE_MODULE) == 0) + { + parser_raise_error (context_p, PARSER_ERR_MODULE_UNEXPECTED); + } +} /* parser_module_check_request_place */ + +/** + * Append names to the names list. + */ +void +parser_module_append_names (parser_context_t *context_p, /**< parser context */ + ecma_module_names_t **module_names_p) /**< target names */ +{ + ecma_module_names_t *last_name_p = context_p->module_names_p; + + if (last_name_p == NULL) + { + return; + } + + if (*module_names_p != NULL) + { + while (last_name_p->next_p != NULL) + { + last_name_p = last_name_p->next_p; + } + + last_name_p->next_p = *module_names_p; + } + + *module_names_p = context_p->module_names_p; + context_p->module_names_p = NULL; +} /* parser_module_append_names */ + +/** + * Handle module specifier at the end of the import / export statement. + */ +void +parser_module_handle_module_specifier (parser_context_t *context_p, /**< parser context */ + ecma_module_node_t **node_list_p) /**< target node list */ +{ + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_STRING_LITERAL + || context_p->token.lit_location.length == 0) + { + parser_raise_error (context_p, PARSER_ERR_STRING_EXPECTED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + + lexer_literal_t *path_p = context_p->lit_object.literal_p; + + lexer_next_token (context_p); + + /* The lexer_next_token may throw an error, so the path is constructed after its call. */ + ecma_string_t *path_string_p = parser_new_ecma_string_from_literal (path_p); + + ecma_module_node_t *node_p = JERRY_CONTEXT (module_current_p)->imports_p; + ecma_module_node_t *last_node_p = NULL; + + /* Check if we have an import node with the same module request. */ + + while (node_p != NULL) + { + if (ecma_compare_ecma_strings (ecma_get_string_from_value (node_p->u.path_or_module), path_string_p)) + { + ecma_deref_ecma_string (path_string_p); + break; + } + + last_node_p = node_p; + node_p = node_p->next_p; + } + + if (node_p == NULL) + { + node_p = (ecma_module_node_t *) jmem_heap_alloc_block_null_on_error (sizeof (ecma_module_node_t)); + + if (node_p == NULL) + { + ecma_deref_ecma_string (path_string_p); + parser_raise_error (context_p, PARSER_ERR_OUT_OF_MEMORY); + } + + if (last_node_p == NULL) + { + JERRY_CONTEXT (module_current_p)->imports_p = node_p; + } + else + { + last_node_p->next_p = node_p; + } + + node_p->next_p = NULL; + node_p->module_names_p = NULL; + node_p->u.path_or_module = ecma_make_string_value (path_string_p); + } + + /* Append to imports. */ + if (node_list_p == NULL) + { + parser_module_append_names (context_p, &node_p->module_names_p); + return; + } + + ecma_value_t *module_object_p = &node_p->u.path_or_module; + + node_p = *node_list_p; + last_node_p = NULL; + + while (node_p != NULL) + { + if (node_p->u.module_object_p == module_object_p) + { + parser_module_append_names (context_p, &node_p->module_names_p); + return; + } + + last_node_p = node_p; + node_p = node_p->next_p; + } + + node_p = (ecma_module_node_t *) parser_malloc (context_p, sizeof (ecma_module_node_t)); + + if (last_node_p == NULL) + { + *node_list_p = node_p; + } + else + { + last_node_p->next_p = node_p; + } + + node_p->next_p = NULL; + node_p->module_names_p = context_p->module_names_p; + node_p->u.module_object_p = module_object_p; + + context_p->module_names_p = NULL; +} /* parser_module_handle_module_specifier */ + +#endif /* JERRY_MODULE_SYSTEM */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-statm.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-statm.cpp new file mode 100644 index 0000000..a8098cc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-statm.cpp @@ -0,0 +1,3259 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-internal.h" + +#if JERRY_PARSER +#include "ecma-helpers.h" + +#include "jcontext.h" +#include "lit-char-helpers.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_stmt Statement parser + * @{ + */ + +/** + * Parser statement types. + * + * When a new statement is added, the following + * arrays must be updated as well: + * - statement_lengths[] + * - parser_statement_flags[] + */ +typedef enum +{ + PARSER_STATEMENT_START, + PARSER_STATEMENT_BLOCK, + PARSER_STATEMENT_BLOCK_SCOPE, + PARSER_STATEMENT_PRIVATE_SCOPE, + PARSER_STATEMENT_BLOCK_CONTEXT, + PARSER_STATEMENT_PRIVATE_CONTEXT, + PARSER_STATEMENT_LABEL, + PARSER_STATEMENT_IF, + PARSER_STATEMENT_ELSE, + PARSER_STATEMENT_SWITCH, + PARSER_STATEMENT_SWITCH_NO_DEFAULT, + PARSER_STATEMENT_DO_WHILE, + PARSER_STATEMENT_WHILE, + PARSER_STATEMENT_FOR, + PARSER_STATEMENT_FOR_IN, + PARSER_STATEMENT_FOR_OF, + PARSER_STATEMENT_FOR_AWAIT_OF, + PARSER_STATEMENT_WITH, + PARSER_STATEMENT_TRY, +} parser_statement_type_t; + +/** + * Parser statement type flags. + */ +typedef enum +{ + PARSER_STATM_NO_OPTS = 0, /**< no options */ + PARSER_STATM_SINGLE_STATM = (1 << 0), /**< statement can form single statement context */ + PARSER_STATM_HAS_BLOCK = (1 << 1), /**< statement always has a code block */ + PARSER_STATM_BREAK_TARGET = (1 << 2), /**< break target statement */ + PARSER_STATM_CONTINUE_TARGET = (1 << 3), /**< continue target statement */ + PARSER_STATM_CONTEXT_BREAK = (1 << 4), /**< uses another instruction form when crosses their borders */ +} parser_statement_flags_t; + +/** + * Parser statement attributes. + * Note: the order of the attributes must be keep in sync with parser_statement_type_t + */ +static const uint8_t parser_statement_flags[] = { + /* PARSER_STATEMENT_START */ + PARSER_STATM_HAS_BLOCK, + /* PARSER_STATEMENT_BLOCK, */ + PARSER_STATM_HAS_BLOCK, + /* PARSER_STATEMENT_BLOCK_SCOPE, */ + PARSER_STATM_HAS_BLOCK, + /* PARSER_STATEMENT_PRIVATE_SCOPE, */ + PARSER_STATM_NO_OPTS, + /* PARSER_STATEMENT_BLOCK_CONTEXT, */ + PARSER_STATM_HAS_BLOCK | PARSER_STATM_CONTEXT_BREAK, + /* PARSER_STATEMENT_PRIVATE_CONTEXT, */ + PARSER_STATM_CONTEXT_BREAK, + /* PARSER_STATEMENT_LABEL */ + PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_IF */ + PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_ELSE */ + PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_SWITCH */ + PARSER_STATM_HAS_BLOCK | PARSER_STATM_BREAK_TARGET, + /* PARSER_STATEMENT_SWITCH_NO_DEFAULT */ + PARSER_STATM_HAS_BLOCK | PARSER_STATM_BREAK_TARGET, + /* PARSER_STATEMENT_DO_WHILE */ + PARSER_STATM_BREAK_TARGET | PARSER_STATM_CONTINUE_TARGET | PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_WHILE */ + PARSER_STATM_BREAK_TARGET | PARSER_STATM_CONTINUE_TARGET | PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_FOR */ + PARSER_STATM_BREAK_TARGET | PARSER_STATM_CONTINUE_TARGET | PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_FOR_IN */ + PARSER_STATM_BREAK_TARGET | PARSER_STATM_CONTINUE_TARGET | PARSER_STATM_SINGLE_STATM | PARSER_STATM_CONTEXT_BREAK, + /* PARSER_STATEMENT_FOR_OF */ + PARSER_STATM_BREAK_TARGET | PARSER_STATM_CONTINUE_TARGET | PARSER_STATM_SINGLE_STATM | PARSER_STATM_CONTEXT_BREAK, + /* PARSER_STATEMENT_FOR_AWAIT_OF */ + PARSER_STATM_BREAK_TARGET | PARSER_STATM_CONTINUE_TARGET | PARSER_STATM_SINGLE_STATM | PARSER_STATM_CONTEXT_BREAK, + /* PARSER_STATEMENT_WITH */ + PARSER_STATM_CONTEXT_BREAK | PARSER_STATM_SINGLE_STATM, + /* PARSER_STATEMENT_TRY */ + PARSER_STATM_HAS_BLOCK | PARSER_STATM_CONTEXT_BREAK +}; + +/** + * Block statement. + */ +typedef struct +{ + uint16_t scope_stack_top; /**< preserved top of scope stack */ + uint16_t scope_stack_reg_top; /**< preserved top register of scope stack */ +} parser_block_statement_t; + +/** + * Context of block statement. + */ +typedef struct +{ + parser_branch_t branch; /**< branch to the end */ +} parser_block_context_t; + +/** + * Loop statement. + */ +typedef struct +{ + parser_branch_node_t *branch_list_p; /**< list of breaks and continues targeting this statement */ +} parser_loop_statement_t; + +/** + * Label statement. + */ +typedef struct +{ + lexer_lit_location_t label_ident; /**< name of the label */ + parser_branch_node_t *break_list_p; /**< list of breaks targeting this label */ +} parser_label_statement_t; + +/** + * If/else statement. + */ +typedef struct +{ + parser_branch_t branch; /**< branch to the end */ +} parser_if_else_statement_t; + +/** + * Switch statement. + */ +typedef struct +{ + parser_branch_t default_branch; /**< branch to the default case */ + parser_branch_node_t *branch_list_p; /**< branches of case statements */ +} parser_switch_statement_t; + +/** + * Do-while statement. + */ +typedef struct +{ + uint32_t start_offset; /**< start byte code offset */ +} parser_do_while_statement_t; + +/** + * While statement. + */ +typedef struct +{ + parser_branch_t branch; /**< branch to the end */ + scanner_location_t condition_location; /**< condition part */ + uint32_t start_offset; /**< start byte code offset */ +} parser_while_statement_t; + +/** + * For statement. + */ +typedef struct +{ + parser_branch_t branch; /**< branch to the end */ + scanner_location_t condition_location; /**< condition part */ + scanner_location_t expression_location; /**< expression part */ + uint32_t start_offset; /**< start byte code offset */ +} parser_for_statement_t; + +/** + * For-in statement. + */ +typedef struct +{ + parser_branch_t branch; /**< branch to the end */ + uint32_t start_offset; /**< start byte code offset */ +} parser_for_in_of_statement_t; + +/** + * With statement. + */ +typedef struct +{ + parser_branch_t branch; /**< branch to the end */ +} parser_with_statement_t; + +/** + * Lexer token types. + */ +typedef enum +{ + parser_try_block, /**< try block */ + parser_catch_block, /**< catch block */ + parser_finally_block, /**< finally block */ +} parser_try_block_type_t; + +/** + * Try statement. + */ +typedef struct +{ + parser_try_block_type_t type; /**< current block type */ + uint16_t scope_stack_top; /**< current top of scope stack */ + uint16_t scope_stack_reg_top; /**< current top register of scope stack */ + parser_branch_t branch; /**< branch to the end of the current block */ +} parser_try_statement_t; + +/** + * Returns the data consumed by a statement. It can be used + * to skip undesired frames on the stack during frame search. + * + * @return size consumed by a statement. + */ +static inline size_t +parser_statement_length (uint8_t type) /**< type of statement */ +{ + static const uint8_t statement_lengths[] = { + /* PARSER_STATEMENT_BLOCK */ + 1, + /* PARSER_STATEMENT_BLOCK_SCOPE */ + (uint8_t) (sizeof (parser_block_statement_t) + 1), + /* PARSER_STATEMENT_PRIVATE_SCOPE */ + (uint8_t) (sizeof (parser_block_statement_t) + 1), + /* PARSER_STATEMENT_BLOCK_CONTEXT */ + (uint8_t) (sizeof (parser_block_statement_t) + sizeof (parser_block_context_t) + 1), + /* PARSER_STATEMENT_PRIVATE_CONTEXT */ + (uint8_t) (sizeof (parser_block_statement_t) + sizeof (parser_block_context_t) + 1), + /* PARSER_STATEMENT_LABEL */ + (uint8_t) (sizeof (parser_label_statement_t) + 1), + /* PARSER_STATEMENT_IF */ + (uint8_t) (sizeof (parser_if_else_statement_t) + 1), + /* PARSER_STATEMENT_ELSE */ + (uint8_t) (sizeof (parser_if_else_statement_t) + 1), + /* PARSER_STATEMENT_SWITCH */ + (uint8_t) (sizeof (parser_switch_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_SWITCH_NO_DEFAULT */ + (uint8_t) (sizeof (parser_switch_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_DO_WHILE */ + (uint8_t) (sizeof (parser_do_while_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_WHILE */ + (uint8_t) (sizeof (parser_while_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_FOR */ + (uint8_t) (sizeof (parser_for_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_FOR_IN */ + (uint8_t) (sizeof (parser_for_in_of_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_FOR_OF */ + (uint8_t) (sizeof (parser_for_in_of_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_FOR_AWAIT_OF */ + (uint8_t) (sizeof (parser_for_in_of_statement_t) + sizeof (parser_loop_statement_t) + 1), + /* PARSER_STATEMENT_WITH */ + (uint8_t) (sizeof (parser_with_statement_t) + 1 + 1), + /* PARSER_STATEMENT_TRY */ + (uint8_t) (sizeof (parser_try_statement_t) + 1), + }; + + JERRY_ASSERT (type >= PARSER_STATEMENT_BLOCK && type <= PARSER_STATEMENT_TRY); + + return statement_lengths[type - PARSER_STATEMENT_BLOCK]; +} /* parser_statement_length */ +/** + * Parse expression enclosed in parens. + */ +static inline void +parser_parse_enclosed_expr (parser_context_t *context_p) /**< context */ +{ + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED); + } + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + lexer_next_token (context_p); +} /* parser_parse_enclosed_expr */ + +/** + * Create a block context. + * + * @return true - when a context is created, false - otherwise + */ +static bool +parser_push_block_context (parser_context_t *context_p, /**< context */ + bool is_private) /**< is private (bound to a statement) context */ +{ + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_BLOCK); + + parser_block_statement_t block_statement; + block_statement.scope_stack_top = context_p->scope_stack_top; + block_statement.scope_stack_reg_top = context_p->scope_stack_reg_top; + + bool is_context_needed = false; + + if (scanner_is_context_needed (context_p, PARSER_CHECK_BLOCK_CONTEXT)) + { + parser_block_context_t block_context; + +#ifndef JERRY_NDEBUG + PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + parser_emit_cbc_forward_branch (context_p, CBC_BLOCK_CREATE_CONTEXT, &block_context.branch); + parser_stack_push (context_p, &block_context, sizeof (parser_block_context_t)); + is_context_needed = true; + } + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS); + parser_stack_push (context_p, &block_statement, sizeof (parser_block_statement_t)); + + uint8_t statement_type; + + if (is_private) + { + statement_type = (is_context_needed ? PARSER_STATEMENT_PRIVATE_CONTEXT : PARSER_STATEMENT_PRIVATE_SCOPE); + } + else + { + statement_type = (is_context_needed ? PARSER_STATEMENT_BLOCK_CONTEXT : PARSER_STATEMENT_BLOCK_SCOPE); + } + + parser_stack_push_uint8 (context_p, statement_type); + + return is_context_needed; +} /* parser_push_block_context */ + +/** + * Pop block context. + */ +static void +parser_pop_block_context (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->stack_top_uint8 == PARSER_STATEMENT_BLOCK_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_BLOCK_CONTEXT + || context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_CONTEXT); + + uint8_t type = context_p->stack_top_uint8; + + parser_block_statement_t block_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &block_statement, sizeof (parser_block_statement_t)); + + context_p->scope_stack_top = block_statement.scope_stack_top; + context_p->scope_stack_reg_top = block_statement.scope_stack_reg_top; + + if (type == PARSER_STATEMENT_BLOCK_CONTEXT || type == PARSER_STATEMENT_PRIVATE_CONTEXT) + { + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + parser_block_context_t block_context; + parser_stack_pop (context_p, &block_context, sizeof (parser_block_context_t)); + + parser_emit_cbc (context_p, CBC_CONTEXT_END); + parser_set_branch_to_current_position (context_p, &block_context.branch); + } + + parser_stack_iterator_init (context_p, &context_p->last_statement); +} /* parser_pop_block_context */ + +/** + * Validate lexical context for a declaration. + */ +static void +parser_validate_lexical_context (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_LET || context_p->token.type == LEXER_KEYW_CONST + || context_p->token.type == LEXER_KEYW_CLASS); + + if (parser_statement_flags[context_p->stack_top_uint8] & PARSER_STATM_SINGLE_STATM) + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_SINGLE_STATEMENT); + } +} /* parser_validate_lexical_context */ + +/** + * Parse var statement. + */ +static void +parser_parse_var_statement (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_VAR || context_p->token.type == LEXER_KEYW_LET + || context_p->token.type == LEXER_KEYW_CONST); + + uint8_t declaration_type = context_p->token.type; + + if (declaration_type != LEXER_KEYW_VAR) + { + parser_validate_lexical_context (context_p); + } + + while (true) + { + if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE)) + { + parser_pattern_flags_t flags = PARSER_PATTERN_BINDING; + + if (declaration_type == LEXER_KEYW_LET) + { + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_LET); + } + else if (declaration_type == LEXER_KEYW_CONST) + { + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_CONST); + } + + parser_parse_initializer_by_next_char (context_p, flags); + } + else + { + lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL + && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + #if JERRY_MODULE_SYSTEM + parser_module_append_export_name (context_p); +#endif /* JERRY_MODULE_SYSTEM */ + + if (declaration_type != LEXER_KEYW_VAR && context_p->token.keyword_type == LEXER_KEYW_LET) + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_LET_BINDING); + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED); + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_ASSIGN) + { + + uint16_t index = context_p->lit_object.index; + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + cbc_opcode_t opcode = CBC_ASSIGN_SET_IDENT; + + uint16_t function_literal_index = parser_check_anonymous_function_declaration (context_p); + + if (function_literal_index == PARSER_ANONYMOUS_CLASS) + { + uint16_t name_index = scanner_save_literal (context_p, index); + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, name_index); + } + else if (function_literal_index < PARSER_NAMED_FUNCTION) + { + parser_set_function_name (context_p, function_literal_index, index, 0); + } + + if (declaration_type != LEXER_KEYW_VAR && (index < PARSER_REGISTER_START)) + { + opcode = CBC_INIT_LET; + + if (scanner_literal_is_created (context_p, index)) + { + opcode = CBC_ASSIGN_LET_CONST; + } + else if (declaration_type == LEXER_KEYW_CONST) + { + opcode = CBC_INIT_CONST; + } + } + + parser_emit_cbc_literal (context_p, (uint16_t) opcode, index); + } + else if (declaration_type == LEXER_KEYW_LET) + { + parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED); + + uint16_t index = context_p->lit_object.index; + cbc_opcode_t opcode = CBC_MOV_IDENT; + + if (index < PARSER_REGISTER_START) + { + opcode = (scanner_literal_is_created (context_p, index) ? CBC_ASSIGN_LET_CONST : CBC_INIT_LET); + } + + parser_emit_cbc_literal (context_p, (uint16_t) opcode, index); + } + else if (declaration_type == LEXER_KEYW_CONST) + { + parser_raise_error (context_p, PARSER_ERR_MISSING_ASSIGN_AFTER_CONST); + } + } + + if (context_p->token.type != LEXER_COMMA) + { + break; + } + } + +#if JERRY_MODULE_SYSTEM + context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT); +#endif /* JERRY_MODULE_SYSTEM */ +} /* parser_parse_var_statement */ + +/** + * Parse function statement. + */ +static void +parser_parse_function_statement (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_FUNCTION); + + bool is_single_statement = (parser_statement_flags[context_p->stack_top_uint8] & PARSER_STATM_SINGLE_STATM) != 0; + + if (JERRY_UNLIKELY (is_single_statement)) + { + if (context_p->status_flags & PARSER_IS_STRICT) + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_SINGLE_STATEMENT); + } + + if (context_p->stack_top_uint8 == PARSER_STATEMENT_IF || context_p->stack_top_uint8 == PARSER_STATEMENT_ELSE) + { + /* There must be a parser error later if this check fails. */ + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + parser_push_block_context (context_p, true); + } + } + else if (context_p->stack_top_uint8 == PARSER_STATEMENT_LABEL) + { + parser_stack_iterator_t iterator; + parser_stack_iterator_init (context_p, &iterator); + parser_stack_iterator_skip (&iterator, sizeof (parser_label_statement_t) + 1); + + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + + if (type == PARSER_STATEMENT_LABEL) + { + parser_stack_iterator_skip (&iterator, sizeof (parser_label_statement_t) + 1); + continue; + } + + if (parser_statement_flags[type] & PARSER_STATM_HAS_BLOCK) + { + break; + } + + parser_raise_error (context_p, PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK); + } + } + else + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_SINGLE_STATEMENT); + } + } + bool is_generator_function = false; + + if (lexer_consume_generator (context_p)) + { + if (is_single_statement) + { + parser_raise_error (context_p, PARSER_ERR_GENERATOR_IN_SINGLE_STATEMENT_POS); + } + is_generator_function = true; + } + + lexer_expect_identifier (context_p, LEXER_NEW_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + if (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED) + { + parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED); + } + + uint16_t function_name_index = context_p->lit_object.index; + +#if JERRY_MODULE_SYSTEM + parser_module_append_export_name (context_p); + context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT); +#endif /* JERRY_MODULE_SYSTEM */ + + uint32_t status_flags = PARSER_FUNCTION_CLOSURE; + + if (context_p->token.keyword_type >= LEXER_FIRST_NON_STRICT_ARGUMENTS) + { + status_flags |= PARSER_HAS_NON_STRICT_ARG; + } + + if (is_generator_function) + { + status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + } + + if (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_ASYNC) + { + status_flags |= PARSER_IS_ASYNC_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD; + } + + JERRY_ASSERT (context_p->scope_stack_top >= 2); + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top - 2; + + uint16_t literal_index = context_p->lit_object.index; + + while (literal_index != scope_stack_p->map_from) + { + scope_stack_p--; + + JERRY_ASSERT (scope_stack_p >= context_p->scope_stack_p); + } + + JERRY_ASSERT (scope_stack_p[1].map_from == PARSER_SCOPE_STACK_FUNC); + + if (!(context_p->status_flags & PARSER_IS_STRICT) + && (scope_stack_p >= context_p->scope_stack_p + context_p->scope_stack_global_end)) + { + bool copy_value = true; + + parser_scope_stack_t *stack_p = context_p->scope_stack_p; + + while (stack_p < scope_stack_p) + { + if (literal_index == stack_p->map_from && (stack_p->map_to & PARSER_SCOPE_STACK_NO_FUNCTION_COPY)) + { + copy_value = false; + break; + } + stack_p++; + } + + if (copy_value) + { + stack_p = context_p->scope_stack_p; + + while (stack_p < scope_stack_p) + { + if (literal_index == stack_p->map_from) + { + JERRY_ASSERT (!(stack_p->map_to & PARSER_SCOPE_STACK_NO_FUNCTION_COPY)); + + uint16_t map_to = scanner_decode_map_to (stack_p); + uint16_t opcode = ((map_to >= PARSER_REGISTER_START) ? CBC_ASSIGN_LITERAL_SET_IDENT : CBC_COPY_TO_GLOBAL); + + parser_emit_cbc_literal_value (context_p, opcode, scanner_decode_map_to (scope_stack_p), map_to); + break; + } + stack_p++; + } + + parser_flush_cbc (context_p); + } + + if (JERRY_UNLIKELY (context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_CONTEXT)) + { + parser_pop_block_context (context_p); + } + } + + lexer_literal_t *literal_p = PARSER_GET_LITERAL ((size_t) scope_stack_p[1].map_to); + + JERRY_ASSERT ((literal_p->type == LEXER_UNUSED_LITERAL || literal_p->type == LEXER_FUNCTION_LITERAL) + && literal_p->status_flags == 0); + + ecma_compiled_code_t *compiled_code_p = parser_parse_function (context_p, status_flags); + + if (literal_p->type == LEXER_FUNCTION_LITERAL) + { + ecma_bytecode_deref (literal_p->u.bytecode_p); + } + + literal_p->u.bytecode_p = compiled_code_p; + literal_p->type = LEXER_FUNCTION_LITERAL; + + parser_compiled_code_set_function_name (context_p, compiled_code_p, function_name_index, 0); + lexer_next_token (context_p); +} /* parser_parse_function_statement */ + +/** + * Parse if statement (starting part). + */ +static void +parser_parse_if_statement_start (parser_context_t *context_p) /**< context */ +{ + parser_if_else_statement_t if_statement; + + parser_parse_enclosed_expr (context_p); + + parser_emit_cbc_forward_branch (context_p, CBC_BRANCH_IF_FALSE_FORWARD, &if_statement.branch); + + parser_stack_push (context_p, &if_statement, sizeof (parser_if_else_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_IF); + parser_stack_iterator_init (context_p, &context_p->last_statement); +} /* parser_parse_if_statement_start */ + +/** + * Parse if statement (ending part). + * + * @return true - if parsing an 'else' statement + * false - otherwise + */ +static bool +parser_parse_if_statement_end (parser_context_t *context_p) /**< context */ +{ + parser_if_else_statement_t if_statement; + parser_if_else_statement_t else_statement; + parser_stack_iterator_t iterator; + + JERRY_ASSERT (context_p->stack_top_uint8 == PARSER_STATEMENT_IF); + + if (context_p->token.type != LEXER_KEYW_ELSE) + { + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &if_statement, sizeof (parser_if_else_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_set_branch_to_current_position (context_p, &if_statement.branch); + + return false; + } + + parser_stack_change_last_uint8 (context_p, PARSER_STATEMENT_ELSE); + parser_stack_iterator_init (context_p, &iterator); + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &if_statement, sizeof (parser_if_else_statement_t)); + + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &else_statement.branch); + + parser_set_branch_to_current_position (context_p, &if_statement.branch); + + parser_stack_iterator_write (&iterator, &else_statement, sizeof (parser_if_else_statement_t)); + + lexer_next_token (context_p); + return true; +} /* parser_parse_if_statement_end */ + +/** + * Parse with statement (starting part). + */ +static void +parser_parse_with_statement_start (parser_context_t *context_p) /**< context */ +{ + parser_with_statement_t with_statement; + + if (context_p->status_flags & PARSER_IS_STRICT) + { + parser_raise_error (context_p, PARSER_ERR_WITH_NOT_ALLOWED); + } + + parser_parse_enclosed_expr (context_p); + +#ifndef JERRY_NDEBUG + PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + uint8_t inside_with = (context_p->status_flags & PARSER_INSIDE_WITH) != 0; + + context_p->status_flags |= PARSER_INSIDE_WITH; + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_WITH_CREATE_CONTEXT, &with_statement.branch); + + parser_stack_push (context_p, &with_statement, sizeof (parser_with_statement_t)); + parser_stack_push_uint8 (context_p, inside_with); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_WITH); + parser_stack_iterator_init (context_p, &context_p->last_statement); +} /* parser_parse_with_statement_start */ + +/** + * Parse with statement (ending part). + */ +static void +parser_parse_with_statement_end (parser_context_t *context_p) /**< context */ +{ + parser_with_statement_t with_statement; + + JERRY_ASSERT (context_p->status_flags & PARSER_INSIDE_WITH); + + parser_stack_pop_uint8 (context_p); + + if (!context_p->stack_top_uint8) + { + context_p->status_flags &= (uint32_t) ~PARSER_INSIDE_WITH; + } + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &with_statement, sizeof (parser_with_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_flush_cbc (context_p); + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + parser_emit_cbc (context_p, CBC_CONTEXT_END); + parser_set_branch_to_current_position (context_p, &with_statement.branch); +} /* parser_parse_with_statement_end */ + +/** + * Parse do-while statement (ending part). + */ +static void +parser_parse_do_while_statement_end (parser_context_t *context_p) /**< context */ +{ + parser_loop_statement_t loop; + + JERRY_ASSERT (context_p->stack_top_uint8 == PARSER_STATEMENT_DO_WHILE); + + if (context_p->token.type != LEXER_KEYW_WHILE) + { + parser_raise_error (context_p, PARSER_ERR_WHILE_EXPECTED); + } + + parser_stack_iterator_t iterator; + parser_stack_iterator_init (context_p, &iterator); + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + + parser_set_continues_to_current_position (context_p, loop.branch_list_p); + + JERRY_ASSERT (context_p->next_scanner_info_p->source_p != context_p->source_p); + + parser_parse_enclosed_expr (context_p); + + if (context_p->last_cbc_opcode != CBC_PUSH_FALSE) + { + cbc_opcode_t opcode = CBC_BRANCH_IF_TRUE_BACKWARD; + if (context_p->last_cbc_opcode == CBC_LOGICAL_NOT) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_BRANCH_IF_FALSE_BACKWARD; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_TRUE) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_JUMP_BACKWARD; + } + + parser_do_while_statement_t do_while_statement; + parser_stack_iterator_skip (&iterator, sizeof (parser_loop_statement_t)); + parser_stack_iterator_read (&iterator, &do_while_statement, sizeof (parser_do_while_statement_t)); + + parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, do_while_statement.start_offset); + } + else + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + } + + parser_stack_pop (context_p, NULL, 1 + sizeof (parser_loop_statement_t) + sizeof (parser_do_while_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_set_breaks_to_current_position (context_p, loop.branch_list_p); +} /* parser_parse_do_while_statement_end */ + +/** + * Parse while statement (starting part). + */ +static void +parser_parse_while_statement_start (parser_context_t *context_p) /**< context */ +{ + parser_while_statement_t while_statement; + parser_loop_statement_t loop; + + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_WHILE); + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED); + } + + JERRY_ASSERT (context_p->next_scanner_info_p->source_p != context_p->source_p + || context_p->next_scanner_info_p->type == SCANNER_TYPE_WHILE); + + if (context_p->next_scanner_info_p->source_p != context_p->source_p) + { + /* The prescanner couldn't find the end of the while condition. */ + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR); + + JERRY_ASSERT (context_p->token.type != LEXER_RIGHT_PAREN); + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &while_statement.branch); + + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + + while_statement.start_offset = context_p->byte_code_size; + scanner_get_location (&while_statement.condition_location, context_p); + + scanner_set_location (context_p, &((scanner_location_info_t *) context_p->next_scanner_info_p)->location); + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + scanner_seek (context_p); + lexer_next_token (context_p); + + loop.branch_list_p = NULL; + + parser_stack_push (context_p, &while_statement, sizeof (parser_while_statement_t)); + parser_stack_push (context_p, &loop, sizeof (parser_loop_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_WHILE); + parser_stack_iterator_init (context_p, &context_p->last_statement); +} /* parser_parse_while_statement_start */ + +/** + * Parse while statement (ending part). + */ +static void JERRY_ATTR_NOINLINE +parser_parse_while_statement_end (parser_context_t *context_p) /**< context */ +{ + parser_while_statement_t while_statement; + parser_loop_statement_t loop; + lexer_token_t current_token; + scanner_location_t location; + cbc_opcode_t opcode; + + JERRY_ASSERT (context_p->stack_top_uint8 == PARSER_STATEMENT_WHILE); + + parser_stack_iterator_t iterator; + parser_stack_iterator_init (context_p, &iterator); + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + parser_stack_iterator_skip (&iterator, sizeof (parser_loop_statement_t)); + parser_stack_iterator_read (&iterator, &while_statement, sizeof (parser_while_statement_t)); + + scanner_get_location (&location, context_p); + current_token = context_p->token; + + parser_set_branch_to_current_position (context_p, &while_statement.branch); + parser_set_continues_to_current_position (context_p, loop.branch_list_p); + + scanner_set_location (context_p, &while_statement.condition_location); + scanner_seek (context_p); + lexer_next_token (context_p); + + parser_parse_expression (context_p, PARSE_EXPR); + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + opcode = CBC_BRANCH_IF_TRUE_BACKWARD; + if (context_p->last_cbc_opcode == CBC_LOGICAL_NOT) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_BRANCH_IF_FALSE_BACKWARD; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_TRUE) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_JUMP_BACKWARD; + } + + parser_stack_pop (context_p, NULL, 1 + sizeof (parser_loop_statement_t) + sizeof (parser_while_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, while_statement.start_offset); + parser_set_breaks_to_current_position (context_p, loop.branch_list_p); + + /* Calling scanner_seek is unnecessary because all + * info blocks inside the while statement should be processed. */ + scanner_set_location (context_p, &location); + context_p->token = current_token; +} /* parser_parse_while_statement_end */ + +/** + * Check whether the opcode is a valid LeftHandSide expression + * and convert it back to an assignment. + * + * @return the compatible assignment opcode + */ +static uint16_t +parser_check_left_hand_side_expression (parser_context_t *context_p, /**< context */ + uint16_t opcode) /**< opcode to check */ +{ + if (opcode == CBC_PUSH_LITERAL && context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + return CBC_ASSIGN_SET_IDENT; + } + else if (opcode == CBC_PUSH_PROP) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + return CBC_ASSIGN; + } + else if (opcode == CBC_PUSH_PROP_LITERAL) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + return CBC_ASSIGN_PROP_LITERAL; + } + else if (opcode == CBC_PUSH_PROP_LITERAL_LITERAL) + { + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + return CBC_ASSIGN; + } + else if (opcode == CBC_PUSH_PROP_THIS_LITERAL) + { + context_p->last_cbc_opcode = CBC_PUSH_THIS_LITERAL; + return CBC_ASSIGN; + } + else + { + /* Invalid LeftHandSide expression. */ + parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_FOR_LOOP); + return CBC_ASSIGN; + } + + return opcode; +} /* parser_check_left_hand_side_expression */ + +/** + * Parse for statement (starting part). + */ +static void +parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ +{ + parser_loop_statement_t loop; + + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_FOR); + lexer_next_token (context_p); + bool is_for_await = false; + + if (context_p->token.type == LEXER_KEYW_AWAIT) + { + if (JERRY_UNLIKELY (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_KEYWORD); + } + lexer_next_token (context_p); + is_for_await = true; + } + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + if (context_p->token.type == LEXER_LITERAL && context_p->token.keyword_type == LEXER_KEYW_AWAIT + && !(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + parser_raise_error (context_p, PARSER_ERR_FOR_AWAIT_NO_ASYNC); + } + + parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED); + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + parser_for_in_of_statement_t for_in_of_statement; + scanner_location_t start_location, end_location; + + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FOR_IN + || context_p->next_scanner_info_p->type == SCANNER_TYPE_FOR_OF); + + bool is_for_in = (context_p->next_scanner_info_p->type == SCANNER_TYPE_FOR_IN); + end_location = ((scanner_location_info_t *) context_p->next_scanner_info_p)->location; + + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + + scanner_get_location (&start_location, context_p); + lexer_next_token (context_p); + + uint8_t token_type = LEXER_EOS; + bool has_context = false; + + if (context_p->token.type == LEXER_KEYW_VAR || context_p->token.type == LEXER_KEYW_LET + || context_p->token.type == LEXER_KEYW_CONST) + { + token_type = context_p->token.type; + has_context = context_p->next_scanner_info_p->source_p == context_p->source_p; + JERRY_ASSERT (!has_context || context_p->next_scanner_info_p->type == SCANNER_TYPE_BLOCK); + scanner_get_location (&start_location, context_p); + + /* TODO: remove this after the pre-scanner supports strict mode detection. */ + if (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION) + { + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + } + else if (context_p->token.type == LEXER_LITERAL && lexer_token_is_let (context_p)) + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION) + { + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + else + { + token_type = LEXER_KEYW_LET; + has_context = (context_p->next_scanner_info_p->source_p == context_p->source_p); + scanner_get_location (&start_location, context_p); + } + } + + if (has_context) + { + has_context = parser_push_block_context (context_p, true); + } + + scanner_set_location (context_p, &end_location); + + /* The length of both 'in' and 'of' is two. */ + const uint8_t *source_end_p = context_p->source_p - 2; + + scanner_seek (context_p); + + if (is_for_in && is_for_await) + { + context_p->token.line = context_p->line; + context_p->token.column = context_p->column - 2; + parser_raise_error (context_p, PARSER_ERR_FOR_AWAIT_NO_OF); + } + + lexer_next_token (context_p); + int options = is_for_in ? PARSE_EXPR : PARSE_EXPR_NO_COMMA; + parser_parse_expression (context_p, options); + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + +#ifndef JERRY_NDEBUG + PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, + is_for_in ? PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION : PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + cbc_ext_opcode_t init_opcode = CBC_EXT_FOR_IN_INIT; + + if (!is_for_in) + { + init_opcode = is_for_await ? CBC_EXT_FOR_AWAIT_OF_INIT : CBC_EXT_FOR_OF_INIT; + } + + parser_emit_cbc_ext_forward_branch (context_p, init_opcode, &for_in_of_statement.branch); + + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + for_in_of_statement.start_offset = context_p->byte_code_size; + + if (has_context) + { + parser_emit_cbc_ext (context_p, CBC_EXT_CLONE_CONTEXT); + } + + /* The expression parser must not read the 'in' or 'of' tokens. */ + scanner_get_location (&end_location, context_p); + scanner_set_location (context_p, &start_location); + + const uint8_t *original_source_end_p = context_p->source_end_p; + context_p->source_end_p = source_end_p; + scanner_seek (context_p); + + if (token_type == LEXER_EOS) + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE) + { + token_type = context_p->token.type; + } + } + + switch (token_type) + { + case LEXER_KEYW_LET: + case LEXER_KEYW_CONST: + case LEXER_KEYW_VAR: + { + if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE)) + { + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); + + parser_pattern_flags_t flags = (parser_pattern_flags_t ) ((unsigned int) PARSER_PATTERN_BINDING | (unsigned int) PARSER_PATTERN_TARGET_ON_STACK); + + if (context_p->next_scanner_info_p->source_p == (context_p->source_p + 1)) + { + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER) + { + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + } + else + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS); + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_HAS_REST_ELEMENT); + } + + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + } + + if (token_type == LEXER_KEYW_LET) + { + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_LET); + } + else if (token_type == LEXER_KEYW_CONST) + { + flags = (parser_pattern_flags_t) ((int) flags | (int) PARSER_PATTERN_CONST); + } + + parser_parse_initializer_by_next_char (context_p, flags); + break; + } + + lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); + + if (context_p->token.keyword_type == LEXER_KEYW_LET && token_type != LEXER_KEYW_VAR) + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_LET_BINDING); + } + + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL + && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + uint16_t literal_index = context_p->lit_object.index; + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_ASSIGN) + { + if ((context_p->status_flags & PARSER_IS_STRICT) || !is_for_in) + { + parser_raise_error (context_p, PARSER_ERR_FOR_IN_OF_DECLARATION); + } + parser_branch_t branch; + + /* Initialiser is never executed. */ + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &branch); + lexer_next_token (context_p); + parser_parse_expression_statement (context_p, PARSE_EXPR_NO_COMMA); + parser_set_branch_to_current_position (context_p, &branch); + } + + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); +#ifndef JERRY_NDEBUG + if (literal_index < PARSER_REGISTER_START && has_context + && !scanner_literal_is_created (context_p, literal_index)) + { + context_p->global_status_flags |= ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR; + } +#endif /* !JERRY_NDEBUG */ + + uint16_t opcode = (has_context ? CBC_ASSIGN_LET_CONST : CBC_ASSIGN_SET_IDENT); + parser_emit_cbc_literal (context_p, opcode, literal_index); + break; + } + case LEXER_LEFT_BRACE: + case LEXER_LEFT_SQUARE: + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS + && (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_DESTRUCTURING_FOR)) + { + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); + + uint32_t flags = PARSER_PATTERN_TARGET_ON_STACK; + + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags |= PARSER_PATTERN_HAS_REST_ELEMENT; + } + + scanner_release_next (context_p, sizeof (scanner_info_t)); + parser_parse_initializer (context_p, (parser_pattern_flags_t) flags); + /* Pop the value returned by GET_NEXT. */ + parser_emit_cbc (context_p, CBC_POP); + break; + } + /* FALLTHRU */ + } + default: + { + uint16_t opcode; + + parser_parse_expression (context_p, PARSE_EXPR_LEFT_HAND_SIDE); + + opcode = context_p->last_cbc_opcode; + + /* The CBC_EXT_FOR_IN_CREATE_CONTEXT flushed the opcode combiner. */ + JERRY_ASSERT (opcode != CBC_PUSH_TWO_LITERALS && opcode != CBC_PUSH_THREE_LITERALS); + + opcode = parser_check_left_hand_side_expression (context_p, opcode); + + parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); + parser_flush_cbc (context_p); + + context_p->last_cbc_opcode = opcode; + break; + } + } + + if (context_p->token.type != LEXER_EOS) + { + parser_raise_error (context_p, is_for_in ? PARSER_ERR_IN_EXPECTED : PARSER_ERR_OF_EXPECTED); + } + + parser_flush_cbc (context_p); + scanner_set_location (context_p, &end_location); + context_p->source_end_p = original_source_end_p; + lexer_next_token (context_p); + + loop.branch_list_p = NULL; + + parser_stack_push (context_p, &for_in_of_statement, sizeof (parser_for_in_of_statement_t)); + parser_stack_push (context_p, &loop, sizeof (parser_loop_statement_t)); + + uint8_t for_type = PARSER_STATEMENT_FOR_IN; + + if (!is_for_in) + { + for_type = is_for_await ? PARSER_STATEMENT_FOR_AWAIT_OF : PARSER_STATEMENT_FOR_OF; + } + + parser_stack_push_uint8 (context_p, for_type); + parser_stack_iterator_init (context_p, &context_p->last_statement); + return; + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_SEMICOLON) + { + const uint8_t *source_p = context_p->source_p; + + switch (context_p->token.type) + { + case LEXER_LITERAL: + { + if (!lexer_token_is_let (context_p)) + { + parser_parse_expression_statement (context_p, PARSE_EXPR); + break; + } + + /* FALLTHRU */ + } + case LEXER_KEYW_LET: + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type != SCANNER_TYPE_BLOCK) + { + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION) + { + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + + parser_parse_expression_statement (context_p, PARSE_EXPR); + break; + } + + context_p->token.type = LEXER_KEYW_LET; + + /* FALLTHRU */ + } + case LEXER_KEYW_CONST: + { + if (context_p->next_scanner_info_p->source_p == source_p) + { + parser_push_block_context (context_p, true); + } + /* FALLTHRU */ + } + case LEXER_KEYW_VAR: + { + parser_parse_var_statement (context_p); + break; + } + default: + { + parser_parse_expression_statement (context_p, PARSE_EXPR); + break; + } + } + + if (context_p->token.type != LEXER_SEMICOLON) + { + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + } + + if (is_for_await) + { + parser_raise_error (context_p, PARSER_ERR_FOR_AWAIT_NO_OF); + } + + JERRY_ASSERT (context_p->next_scanner_info_p->source_p != context_p->source_p + || context_p->next_scanner_info_p->type == SCANNER_TYPE_FOR); + + if (context_p->next_scanner_info_p->source_p != context_p->source_p + || ((scanner_for_info_t *) context_p->next_scanner_info_p)->end_location.source_p == NULL) + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + /* Even though the scanning is failed, there might be valid statements + * inside the for statement which depend on scanner info blocks. */ + scanner_release_next (context_p, sizeof (scanner_for_info_t)); + } + + /* The prescanner couldn't find the second semicolon or the closing parentheses. */ + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_SEMICOLON) + { + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + + lexer_next_token (context_p); + parser_parse_expression_statement (context_p, PARSE_EXPR); + + JERRY_ASSERT (context_p->token.type != LEXER_RIGHT_PAREN); + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + parser_for_statement_t for_statement; + scanner_for_info_t *for_info_p = (scanner_for_info_t *) context_p->next_scanner_info_p; + + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &for_statement.branch); + + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + + for_statement.start_offset = context_p->byte_code_size; + scanner_get_location (&for_statement.condition_location, context_p); + for_statement.expression_location = for_info_p->expression_location; + + scanner_set_location (context_p, &for_info_p->end_location); + scanner_release_next (context_p, sizeof (scanner_for_info_t)); + scanner_seek (context_p); + lexer_next_token (context_p); + + loop.branch_list_p = NULL; + + parser_stack_push (context_p, &for_statement, sizeof (parser_for_statement_t)); + parser_stack_push (context_p, &loop, sizeof (parser_loop_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_FOR); + parser_stack_iterator_init (context_p, &context_p->last_statement); +} /* parser_parse_for_statement_start */ + +/** + * Parse for statement (ending part). + */ +static void JERRY_ATTR_NOINLINE +parser_parse_for_statement_end (parser_context_t *context_p) /**< context */ +{ + parser_for_statement_t for_statement; + parser_loop_statement_t loop; + lexer_token_t current_token; + scanner_location_t location; + cbc_opcode_t opcode; + + JERRY_ASSERT (context_p->stack_top_uint8 == PARSER_STATEMENT_FOR); + + parser_stack_iterator_t iterator; + parser_stack_iterator_init (context_p, &iterator); + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + parser_stack_iterator_skip (&iterator, sizeof (parser_loop_statement_t)); + parser_stack_iterator_read (&iterator, &for_statement, sizeof (parser_for_statement_t)); + + bool has_block_context = false; + uint8_t next_statement_type; + + parser_stack_iterator_skip (&iterator, sizeof (parser_for_statement_t)); + parser_stack_iterator_read (&iterator, &next_statement_type, 1); + + if (next_statement_type == PARSER_STATEMENT_PRIVATE_CONTEXT) + { + has_block_context = true; + } + + scanner_get_location (&location, context_p); + current_token = context_p->token; + + scanner_set_location (context_p, &for_statement.expression_location); + scanner_seek (context_p); + lexer_next_token (context_p); + + parser_set_continues_to_current_position (context_p, loop.branch_list_p); + + if (has_block_context) + { + parser_emit_cbc_ext (context_p, CBC_EXT_CLONE_FULL_CONTEXT); + } + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_parse_expression_statement (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + } + + parser_set_branch_to_current_position (context_p, &for_statement.branch); + + scanner_set_location (context_p, &for_statement.condition_location); + scanner_seek (context_p); + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_SEMICOLON) + { + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_SEMICOLON) + { + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + + opcode = CBC_BRANCH_IF_TRUE_BACKWARD; + if (context_p->last_cbc_opcode == CBC_LOGICAL_NOT) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_BRANCH_IF_FALSE_BACKWARD; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_TRUE) + { + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + opcode = CBC_JUMP_BACKWARD; + } + } + else + { + opcode = CBC_JUMP_BACKWARD; + } + + parser_stack_pop (context_p, NULL, 1 + sizeof (parser_loop_statement_t) + sizeof (parser_for_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, for_statement.start_offset); + parser_set_breaks_to_current_position (context_p, loop.branch_list_p); + + if (context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_CONTEXT) + { + parser_pop_block_context (context_p); + } + + /* Calling scanner_seek is unnecessary because all + * info blocks inside the for statement should be processed. */ + scanner_set_location (context_p, &location); + context_p->token = current_token; +} /* parser_parse_for_statement_end */ + +/** + * Parse switch statement (starting part). + */ +static void JERRY_ATTR_NOINLINE +parser_parse_switch_statement_start (parser_context_t *context_p) /**< context */ +{ + parser_switch_statement_t switch_statement; + parser_loop_statement_t loop; + parser_stack_iterator_t iterator; + scanner_location_t start_location; + bool switch_case_was_found; + bool default_case_was_found; + parser_branch_node_t *case_branches_p = NULL; + + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_SWITCH); + + parser_parse_enclosed_expr (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED); + } + + if (context_p->next_scanner_info_p->source_p == context_p->source_p - 1) + { + parser_push_block_context (context_p, true); + } + + JERRY_ASSERT (context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_SWITCH); + + scanner_case_info_t *case_info_p = ((scanner_switch_info_t *) context_p->next_scanner_info_p)->case_p; + scanner_set_active (context_p); + + if (case_info_p == NULL) + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + scanner_release_active (context_p, sizeof (scanner_switch_info_t)); + + parser_emit_cbc (context_p, CBC_POP); + parser_flush_cbc (context_p); + + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_BLOCK); + parser_stack_iterator_init (context_p, &context_p->last_statement); + return; + } + + parser_raise_error (context_p, PARSER_ERR_INVALID_SWITCH); + } + + scanner_get_location (&start_location, context_p); + + /* The reason of using an iterator is error management. If an error + * occur, parser_free_jumps() free all data. However, the branches + * created by parser_emit_cbc_forward_branch_item() would not be freed. + * To free these branches, the current switch data is always stored + * on the stack. If any change happens, this data is updated. Updates + * are done using the iterator. */ + + switch_statement.branch_list_p = NULL; + loop.branch_list_p = NULL; + + parser_stack_push (context_p, &switch_statement, sizeof (parser_switch_statement_t)); + parser_stack_iterator_init (context_p, &iterator); + parser_stack_push (context_p, &loop, sizeof (parser_loop_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_SWITCH); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + switch_case_was_found = false; + default_case_was_found = false; + + do + { + scanner_set_location (context_p, &case_info_p->location); + scanner_seek (context_p); + case_info_p = case_info_p->next_p; + + /* The last letter of case and default is 'e' and 't' respectively. */ + JERRY_ASSERT (context_p->source_p[-1] == LIT_CHAR_LOWERCASE_E || context_p->source_p[-1] == LIT_CHAR_LOWERCASE_T); + + bool is_default = context_p->source_p[-1] == LIT_CHAR_LOWERCASE_T; + lexer_next_token (context_p); + + if (is_default) + { + if (default_case_was_found) + { + parser_raise_error (context_p, PARSER_ERR_MULTIPLE_DEFAULTS_NOT_ALLOWED); + } + + if (context_p->token.type != LEXER_COLON) + { + parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); + } + + default_case_was_found = true; + continue; + } + + switch_case_was_found = true; + + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->token.type != LEXER_COLON) + { + parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); + } + + uint16_t opcode = CBC_BRANCH_IF_STRICT_EQUAL; + + if (case_info_p == NULL + || (case_info_p->next_p == NULL && case_info_p->location.source_p[-1] == LIT_CHAR_LOWERCASE_T)) + { + /* There are no more 'case' statements in the switch. */ + parser_emit_cbc (context_p, CBC_STRICT_EQUAL); + opcode = CBC_BRANCH_IF_TRUE_FORWARD; + } + + parser_branch_node_t *new_case_p = parser_emit_cbc_forward_branch_item (context_p, opcode, NULL); + + if (case_branches_p == NULL) + { + switch_statement.branch_list_p = new_case_p; + parser_stack_iterator_write (&iterator, &switch_statement, sizeof (parser_switch_statement_t)); + } + else + { + case_branches_p->next_p = new_case_p; + } + + case_branches_p = new_case_p; + } while (case_info_p != NULL); + + JERRY_ASSERT (switch_case_was_found || default_case_was_found); + + if (!switch_case_was_found) + { + /* There was no case statement, so the expression result + * of the switch must be popped from the stack */ + parser_emit_cbc (context_p, CBC_POP); + } + + parser_emit_cbc_forward_branch (context_p, CBC_JUMP_FORWARD, &switch_statement.default_branch); + parser_stack_iterator_write (&iterator, &switch_statement, sizeof (parser_switch_statement_t)); + + if (!default_case_was_found) + { + parser_stack_change_last_uint8 (context_p, PARSER_STATEMENT_SWITCH_NO_DEFAULT); + } + + scanner_release_switch_cases (((scanner_switch_info_t *) context_p->active_scanner_info_p)->case_p); + scanner_release_active (context_p, sizeof (scanner_switch_info_t)); + + scanner_set_location (context_p, &start_location); + scanner_seek (context_p); + lexer_next_token (context_p); +} /* parser_parse_switch_statement_start */ + +/** + * Parse try statement (ending part). + */ +static void +parser_parse_try_statement_end (parser_context_t *context_p) /**< context */ +{ + parser_try_statement_t try_statement; + parser_stack_iterator_t iterator; + + JERRY_ASSERT (context_p->stack_top_uint8 == PARSER_STATEMENT_TRY); + + parser_stack_iterator_init (context_p, &iterator); + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &try_statement, sizeof (parser_try_statement_t)); + + context_p->scope_stack_top = try_statement.scope_stack_top; + context_p->scope_stack_reg_top = try_statement.scope_stack_reg_top; + + lexer_next_token (context_p); + + if (try_statement.type == parser_finally_block) + { + parser_flush_cbc (context_p); + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + parser_emit_cbc (context_p, CBC_CONTEXT_END); + parser_set_branch_to_current_position (context_p, &try_statement.branch); + } + else + { + parser_set_branch_to_current_position (context_p, &try_statement.branch); + + if (try_statement.type == parser_catch_block) + { + if (context_p->token.type != LEXER_KEYW_FINALLY) + { + parser_flush_cbc (context_p); + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + parser_emit_cbc (context_p, CBC_CONTEXT_END); + parser_flush_cbc (context_p); + + try_statement.type = parser_finally_block; + } + } + else + { + JERRY_ASSERT (try_statement.type == parser_try_block); + + if (context_p->token.type != LEXER_KEYW_CATCH && context_p->token.type != LEXER_KEYW_FINALLY) + { + parser_raise_error (context_p, PARSER_ERR_CATCH_FINALLY_EXPECTED); + } + } + } + + if (try_statement.type == parser_finally_block) + { + parser_stack_pop (context_p, NULL, (uint32_t) (sizeof (parser_try_statement_t) + 1)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + return; + } + + if (context_p->token.type == LEXER_KEYW_CATCH) + { + lexer_next_token (context_p); + + try_statement.type = parser_catch_block; + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_CATCH, &try_statement.branch); + + try_statement.scope_stack_top = context_p->scope_stack_top; + try_statement.scope_stack_reg_top = context_p->scope_stack_reg_top; + +#ifndef JERRY_NDEBUG + bool block_found = false; +#endif /* !JERRY_NDEBUG */ + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_BLOCK); +#ifndef JERRY_NDEBUG + block_found = true; +#endif /* !JERRY_NDEBUG */ + + if (scanner_is_context_needed (context_p, PARSER_CHECK_BLOCK_CONTEXT)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_TRY_CREATE_ENV); + } + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS); + } + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE)) + { + parser_pattern_flags_t flags = (parser_pattern_flags_t) ((unsigned int) PARSER_PATTERN_BINDING | (unsigned int) PARSER_PATTERN_TARGET_ON_STACK | (unsigned int) PARSER_PATTERN_LET); + + parser_parse_initializer_by_next_char (context_p, flags); + } + else + { + lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL); + JERRY_ASSERT (context_p->token.type == LEXER_LITERAL + && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + uint16_t literal_index = context_p->lit_object.index; + parser_emit_cbc_literal (context_p, + (literal_index >= PARSER_REGISTER_START) ? CBC_ASSIGN_SET_IDENT : CBC_ASSIGN_LET_CONST, + literal_index); + + lexer_next_token (context_p); + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (block_found); +#endif /* !JERRY_NDEBUG */ + } + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED); + } + } + else if (context_p->token.type == LEXER_LEFT_BRACE) + { + parser_emit_cbc (context_p, CBC_POP); + } + else + { + parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED); + } + + parser_flush_cbc (context_p); + } + else + { + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_FINALLY); + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED); + } + +#ifndef JERRY_NDEBUG + PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + try_statement.type = parser_finally_block; + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_FINALLY, &try_statement.branch); + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_BLOCK); + + if (scanner_is_context_needed (context_p, PARSER_CHECK_BLOCK_CONTEXT)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_TRY_CREATE_ENV); + } + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS); + } + } + + lexer_next_token (context_p); + parser_stack_iterator_write (&iterator, &try_statement, sizeof (parser_try_statement_t)); +} /* parser_parse_try_statement_end */ + +/** + * Parse default statement. + */ +static void +parser_parse_default_statement (parser_context_t *context_p) /**< context */ +{ + parser_stack_iterator_t iterator; + parser_switch_statement_t switch_statement; + + if (context_p->stack_top_uint8 != PARSER_STATEMENT_SWITCH + && context_p->stack_top_uint8 != PARSER_STATEMENT_SWITCH_NO_DEFAULT) + { + parser_raise_error (context_p, PARSER_ERR_DEFAULT_NOT_IN_SWITCH); + } + + lexer_next_token (context_p); + /* Already checked in parser_parse_switch_statement_start. */ + JERRY_ASSERT (context_p->token.type == LEXER_COLON); + lexer_next_token (context_p); + + parser_stack_iterator_init (context_p, &iterator); + parser_stack_iterator_skip (&iterator, 1 + sizeof (parser_loop_statement_t)); + parser_stack_iterator_read (&iterator, &switch_statement, sizeof (parser_switch_statement_t)); + + parser_set_branch_to_current_position (context_p, &switch_statement.default_branch); +} /* parser_parse_default_statement */ + +/** + * Parse case statement. + */ +static void +parser_parse_case_statement (parser_context_t *context_p) /**< context */ +{ + parser_stack_iterator_t iterator; + parser_switch_statement_t switch_statement; + parser_branch_node_t *branch_p; + + if (context_p->stack_top_uint8 != PARSER_STATEMENT_SWITCH + && context_p->stack_top_uint8 != PARSER_STATEMENT_SWITCH_NO_DEFAULT) + { + parser_raise_error (context_p, PARSER_ERR_CASE_NOT_IN_SWITCH); + } + + if (context_p->next_scanner_info_p->source_p != context_p->source_p) + { + lexer_next_token (context_p); + + parser_parse_expression (context_p, PARSE_EXPR); + + JERRY_ASSERT (context_p->token.type != LEXER_COLON); + parser_raise_error (context_p, PARSER_ERR_COLON_EXPECTED); + } + + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_CASE); + + scanner_set_location (context_p, &((scanner_location_info_t *) context_p->next_scanner_info_p)->location); + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + scanner_seek (context_p); + lexer_next_token (context_p); + + parser_stack_iterator_init (context_p, &iterator); + parser_stack_iterator_skip (&iterator, 1 + sizeof (parser_loop_statement_t)); + parser_stack_iterator_read (&iterator, &switch_statement, sizeof (parser_switch_statement_t)); + + /* Free memory after the case statement is found. */ + + branch_p = switch_statement.branch_list_p; + JERRY_ASSERT (branch_p != NULL); + switch_statement.branch_list_p = branch_p->next_p; + parser_stack_iterator_write (&iterator, &switch_statement, sizeof (parser_switch_statement_t)); + + parser_set_branch_to_current_position (context_p, &branch_p->branch); + parser_free (branch_p, sizeof (parser_branch_node_t)); +} /* parser_parse_case_statement */ + +/** + * Parse break statement. + */ +static void +parser_parse_break_statement (parser_context_t *context_p) /**< context */ +{ + parser_stack_iterator_t iterator; + cbc_opcode_t opcode = CBC_JUMP_FORWARD; + + lexer_next_token (context_p); + parser_stack_iterator_init (context_p, &iterator); + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type == LEXER_LITERAL + && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + /* The label with the same name is searched on the stack. */ + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + if (type == PARSER_STATEMENT_START) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_BREAK_LABEL); + } + + if (parser_statement_flags[type] & PARSER_STATM_CONTEXT_BREAK) + { + opcode = CBC_JUMP_FORWARD_EXIT_CONTEXT; + } + + if (type == PARSER_STATEMENT_LABEL) + { + parser_label_statement_t label_statement; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &label_statement, sizeof (parser_label_statement_t)); + + if (lexer_current_is_literal (context_p, &label_statement.label_ident)) + { + label_statement.break_list_p = + parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, label_statement.break_list_p); + parser_stack_iterator_write (&iterator, &label_statement, sizeof (parser_label_statement_t)); + lexer_next_token (context_p); + return; + } + parser_stack_iterator_skip (&iterator, sizeof (parser_label_statement_t)); + } + else + { + parser_stack_iterator_skip (&iterator, parser_statement_length (type)); + } + } + } + + /* The first switch or loop statement is searched. */ + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + if (type == PARSER_STATEMENT_START) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_BREAK); + } + + if (parser_statement_flags[type] & PARSER_STATM_CONTEXT_BREAK) + { + opcode = CBC_JUMP_FORWARD_EXIT_CONTEXT; + } + + if (parser_statement_flags[type] & PARSER_STATM_BREAK_TARGET) + { + parser_loop_statement_t loop; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, loop.branch_list_p); + parser_stack_iterator_write (&iterator, &loop, sizeof (parser_loop_statement_t)); + return; + } + + parser_stack_iterator_skip (&iterator, parser_statement_length (type)); + } +} /* parser_parse_break_statement */ + +/** + * Parse continue statement. + */ +static void +parser_parse_continue_statement (parser_context_t *context_p) /**< context */ +{ + parser_stack_iterator_t iterator; + cbc_opcode_t opcode = CBC_JUMP_FORWARD; + + lexer_next_token (context_p); + parser_stack_iterator_init (context_p, &iterator); + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type == LEXER_LITERAL + && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + parser_stack_iterator_t loop_iterator; + + loop_iterator.current_p = NULL; + + /* The label with the same name is searched on the stack. */ + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + + if (type == PARSER_STATEMENT_START) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CONTINUE_LABEL); + } + + /* Only those labels are checked, whose are label of a loop. */ + if (loop_iterator.current_p != NULL && type == PARSER_STATEMENT_LABEL) + { + parser_label_statement_t label_statement; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &label_statement, sizeof (parser_label_statement_t)); + + if (lexer_current_is_literal (context_p, &label_statement.label_ident)) + { + parser_loop_statement_t loop; + + parser_stack_iterator_skip (&loop_iterator, 1); + parser_stack_iterator_read (&loop_iterator, &loop, sizeof (parser_loop_statement_t)); + loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, loop.branch_list_p); + loop.branch_list_p->branch.offset |= CBC_HIGHEST_BIT_MASK; + parser_stack_iterator_write (&loop_iterator, &loop, sizeof (parser_loop_statement_t)); + lexer_next_token (context_p); + return; + } + parser_stack_iterator_skip (&iterator, sizeof (parser_label_statement_t)); + continue; + } + + if (parser_statement_flags[type] & PARSER_STATM_CONTEXT_BREAK) + { + opcode = CBC_JUMP_FORWARD_EXIT_CONTEXT; + } + + const bool is_private_scope = + (type == PARSER_STATEMENT_PRIVATE_SCOPE || type == PARSER_STATEMENT_PRIVATE_CONTEXT); + + if (parser_statement_flags[type] & PARSER_STATM_CONTINUE_TARGET) + { + loop_iterator = iterator; + } + else if (!is_private_scope) + { + loop_iterator.current_p = NULL; + } + + parser_stack_iterator_skip (&iterator, parser_statement_length (type)); + } + } + + /* The first loop statement is searched. */ + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + if (type == PARSER_STATEMENT_START) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CONTINUE); + } + + if (parser_statement_flags[type] & PARSER_STATM_CONTINUE_TARGET) + { + parser_loop_statement_t loop; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p, (uint16_t) opcode, loop.branch_list_p); + loop.branch_list_p->branch.offset |= CBC_HIGHEST_BIT_MASK; + parser_stack_iterator_write (&iterator, &loop, sizeof (parser_loop_statement_t)); + return; + } + + if (parser_statement_flags[type] & PARSER_STATM_CONTEXT_BREAK) + { + opcode = CBC_JUMP_FORWARD_EXIT_CONTEXT; + } + + parser_stack_iterator_skip (&iterator, parser_statement_length (type)); + } +} /* parser_parse_continue_statement */ + +#if JERRY_MODULE_SYSTEM +/** + * Parse import statement. + * Note: See 15.2.2 + */ +static void +parser_parse_import_statement (parser_context_t *context_p) /**< parser context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_IMPORT); + JERRY_ASSERT (context_p->module_names_p == NULL); + + if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_PAREN, LIT_CHAR_DOT)) + { + if (context_p->status_flags & PARSER_IS_FUNCTION) + { + parser_parse_expression_statement (context_p, PARSE_EXPR); + return; + } + + parser_parse_block_expression (context_p, PARSE_EXPR); + return; + } + + parser_module_check_request_place (context_p); + lexer_next_token (context_p); + + /* Check for a ModuleSpecifier*/ + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_STRING_LITERAL) + { + if (!(context_p->token.type == LEXER_LEFT_BRACE || context_p->token.type == LEXER_MULTIPLY + || (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL))) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED); + } + + if (context_p->token.type == LEXER_LITERAL) + { + /* Handle ImportedDefaultBinding */ + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); + + ecma_string_t *local_name_p = parser_new_ecma_string_from_literal (context_p->lit_object.literal_p); + + if (parser_module_check_duplicate_import (context_p, local_name_p)) + { + ecma_deref_ecma_string (local_name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_IMPORT_BINDING); + } + + ecma_string_t *import_name_p = ecma_get_magic_string (LIT_MAGIC_STRING_DEFAULT); + parser_module_add_names_to_node (context_p, import_name_p, local_name_p); + + ecma_deref_ecma_string (local_name_p); + ecma_deref_ecma_string (import_name_p); + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_COMMA) + { + lexer_next_token (context_p); + if (context_p->token.type != LEXER_MULTIPLY && context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_MULTIPLY_EXPECTED); + } + } + else if (!lexer_token_is_identifier (context_p, "from", 4)) + { + parser_raise_error (context_p, PARSER_ERR_FROM_COMMA_EXPECTED); + } + } + + if (context_p->token.type == LEXER_MULTIPLY) + { + /* NameSpaceImport */ + lexer_next_token (context_p); + if (!lexer_token_is_identifier (context_p, "as", 2)) + { + parser_raise_error (context_p, PARSER_ERR_AS_EXPECTED); + } + + lexer_next_token (context_p); + if (context_p->token.type != LEXER_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); + + ecma_string_t *local_name_p = parser_new_ecma_string_from_literal (context_p->lit_object.literal_p); + + if (parser_module_check_duplicate_import (context_p, local_name_p)) + { + ecma_deref_ecma_string (local_name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_IMPORT_BINDING); + } + + ecma_string_t *import_name_p = ecma_get_magic_string (LIT_MAGIC_STRING_ASTERISK_CHAR); + + parser_module_add_names_to_node (context_p, import_name_p, local_name_p); + ecma_deref_ecma_string (local_name_p); + ecma_deref_ecma_string (import_name_p); + + lexer_next_token (context_p); + } + else if (context_p->token.type == LEXER_LEFT_BRACE) + { + /* Handle NamedImports */ + parser_module_parse_import_clause (context_p); + } + + if (!lexer_token_is_identifier (context_p, "from", 4)) + { + parser_raise_error (context_p, PARSER_ERR_FROM_EXPECTED); + } + lexer_next_token (context_p); + } + + parser_module_handle_module_specifier (context_p, NULL); +} /* parser_parse_import_statement */ + +/** + * Parse export statement. + * + * @return true - if function of class statement was found + * false - otherwise + */ +static bool +parser_parse_export_statement (parser_context_t *context_p) /**< context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_EXPORT); + JERRY_ASSERT (context_p->module_names_p == NULL); + + parser_module_check_request_place (context_p); + + bool consume_last_statement = false; + + lexer_next_token (context_p); + switch (context_p->token.type) + { + case LEXER_KEYW_DEFAULT: + { + scanner_location_t location; + scanner_get_location (&location, context_p); + + context_p->status_flags |= PARSER_MODULE_STORE_IDENT; + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LITERAL && lexer_token_is_async (context_p) + && context_p->next_scanner_info_p->source_p == context_p->source_p + && context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION) + { + lexer_next_token (context_p); + } + + if (context_p->token.type == LEXER_KEYW_CLASS) + { + context_p->status_flags |= PARSER_MODULE_DEFAULT_CLASS_OR_FUNC; + parser_parse_class (context_p, true); + consume_last_statement = true; + } + else if (context_p->token.type == LEXER_KEYW_FUNCTION) + { + context_p->status_flags |= PARSER_MODULE_DEFAULT_CLASS_OR_FUNC; + parser_parse_function_statement (context_p); + consume_last_statement = true; + } + else + { + /* Assignment expression */ + scanner_set_location (context_p, &location); + + /* 15.2.3.5 Use the synthetic name '*default*' as the identifier. */ + lexer_construct_literal_object (context_p, &lexer_default_literal, lexer_default_literal.type); + + context_p->token.lit_location.type = LEXER_IDENT_LITERAL; + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + + /* Do not overwrite this identifier. */ + context_p->status_flags &= (uint32_t) ~PARSER_MODULE_STORE_IDENT; + context_p->module_identifier_lit_p = context_p->lit_object.literal_p; + + /* Fake an assignment to the default identifier */ + context_p->token.type = LEXER_ASSIGN; + + parser_parse_expression_statement (context_p, PARSE_EXPR_NO_COMMA | PARSE_EXPR_HAS_LITERAL); + } + + ecma_string_t *name_p = parser_new_ecma_string_from_literal (context_p->module_identifier_lit_p); + + ecma_string_t *export_name_p = ecma_get_magic_string (LIT_MAGIC_STRING_DEFAULT); + + if (parser_module_check_duplicate_export (context_p, export_name_p)) + { + ecma_deref_ecma_string (name_p); + ecma_deref_ecma_string (export_name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER); + } + + parser_module_add_names_to_node (context_p, export_name_p, name_p); + ecma_deref_ecma_string (name_p); + ecma_deref_ecma_string (export_name_p); + break; + } + case LEXER_MULTIPLY: + { + lexer_next_token (context_p); + + ecma_module_node_t **target_node_list_p = &(JERRY_CONTEXT (module_current_p)->star_exports_p); + + if (lexer_token_is_identifier (context_p, "as", 2)) + { + target_node_list_p = &(JERRY_CONTEXT (module_current_p)->indirect_exports_p); + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL); + + lexer_literal_t *literal_p = PARSER_GET_LITERAL (context_p->lit_object.index); + ecma_string_t *export_name_p = parser_new_ecma_string_from_literal (literal_p); + + if (parser_module_check_duplicate_export (context_p, export_name_p)) + { + ecma_deref_ecma_string (export_name_p); + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER); + } + + ecma_string_t *local_name_p = ecma_get_magic_string (LIT_MAGIC_STRING_ASTERISK_CHAR); + parser_module_add_names_to_node (context_p, export_name_p, local_name_p); + ecma_deref_ecma_string (export_name_p); + + lexer_next_token (context_p); + } + + if (!lexer_token_is_identifier (context_p, "from", 4)) + { + parser_raise_error (context_p, PARSER_ERR_FROM_EXPECTED); + } + + lexer_next_token (context_p); + parser_module_handle_module_specifier (context_p, target_node_list_p); + return false; + } + case LEXER_KEYW_VAR: + case LEXER_KEYW_LET: + case LEXER_KEYW_CONST: + { + context_p->status_flags |= PARSER_MODULE_STORE_IDENT; + parser_parse_var_statement (context_p); + break; + } + case LEXER_KEYW_CLASS: + { + context_p->status_flags |= PARSER_MODULE_STORE_IDENT; + parser_parse_class (context_p, true); + consume_last_statement = true; + break; + } + case LEXER_KEYW_FUNCTION: + { + context_p->status_flags |= PARSER_MODULE_STORE_IDENT; + parser_parse_function_statement (context_p); + consume_last_statement = true; + break; + } + case LEXER_LEFT_BRACE: + { + parser_module_parse_export_clause (context_p); + + if (lexer_token_is_identifier (context_p, "from", 4)) + { + lexer_next_token (context_p); + parser_module_handle_module_specifier (context_p, &(JERRY_CONTEXT (module_current_p)->indirect_exports_p)); + return false; + } + break; + } + default: + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED); + break; + } + } + + context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC | PARSER_MODULE_STORE_IDENT); + parser_module_append_names (context_p, &(JERRY_CONTEXT (module_current_p)->local_exports_p)); + + return consume_last_statement; +} /* parser_parse_export_statement */ +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * Parse label statement. + */ +static void +parser_parse_label (parser_context_t *context_p) /**< context */ +{ + parser_stack_iterator_t iterator; + parser_label_statement_t label_statement; + + parser_stack_iterator_init (context_p, &iterator); + + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + if (type == PARSER_STATEMENT_START) + { + break; + } + + if (type == PARSER_STATEMENT_LABEL) + { + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &label_statement, sizeof (parser_label_statement_t)); + parser_stack_iterator_skip (&iterator, sizeof (parser_label_statement_t)); + + if (lexer_current_is_literal (context_p, &label_statement.label_ident)) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_LABEL); + } + } + else + { + parser_stack_iterator_skip (&iterator, parser_statement_length (type)); + } + } + + label_statement.label_ident = context_p->token.lit_location; + label_statement.break_list_p = NULL; + parser_stack_push (context_p, &label_statement, sizeof (parser_label_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_LABEL); + parser_stack_iterator_init (context_p, &context_p->last_statement); +} /* parser_parse_label */ + +/** + * Strict mode types for statement parsing. + */ +typedef enum +{ + PARSER_USE_STRICT_NOT_FOUND = 0, /**< 'use strict' directive is not found */ + PARSER_USE_STRICT_FOUND = 1, /**< 'use strict' directive is found but strict mode has already been enabled */ + PARSER_USE_STRICT_SET = 2, /**< strict mode is enabled after 'use strict' directive is found */ +} parser_strict_mode_type_t; + +/** + * Parse statements. + */ +void +parser_parse_statements (parser_context_t *context_p) /**< context */ +{ + /* Statement parsing cannot be nested. */ + JERRY_ASSERT (context_p->last_statement.current_p == NULL); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_START); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + while (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + lexer_lit_location_t lit_location; + parser_strict_mode_type_t strict_mode = PARSER_USE_STRICT_NOT_FOUND; + + JERRY_ASSERT (context_p->stack_depth <= 1); +#ifndef JERRY_NDEBUG + JERRY_ASSERT (context_p->context_stack_depth == context_p->stack_depth); +#endif /* !JERRY_NDEBUG */ + + if (lexer_string_is_use_strict (context_p)) + { + strict_mode = PARSER_USE_STRICT_FOUND; + + if (!(context_p->status_flags & PARSER_IS_STRICT)) + { + /* The next token should be parsed in strict mode. */ + context_p->status_flags |= PARSER_IS_STRICT; + strict_mode = PARSER_USE_STRICT_SET; + } + } + + lit_location = context_p->token.lit_location; + lexer_next_token (context_p); + + if (!lexer_string_is_directive (context_p)) + { + /* The string is part of an expression statement. */ + if (strict_mode == PARSER_USE_STRICT_SET) + { + context_p->status_flags &= (uint32_t) ~PARSER_IS_STRICT; + } + + lexer_construct_literal_object (context_p, &lit_location, LEXER_STRING_LITERAL); + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + /* The extra_value is used for saving the token. */ + context_p->token.extra_value = context_p->token.type; + context_p->token.type = LEXER_EXPRESSION_START; + break; + } + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (strict_mode == PARSER_USE_STRICT_SET && context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG (" Note: switch to strict mode\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + if (strict_mode != PARSER_USE_STRICT_NOT_FOUND && (context_p->status_flags & PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT)) + { + parser_raise_error (context_p, PARSER_ERR_USE_STRICT_NOT_ALLOWED); + } + + if (context_p->token.type == LEXER_SEMICOLON) + { + lexer_next_token (context_p); + } + + /* The last directive prologue can be the result of the script. */ + if (!(context_p->status_flags & PARSER_IS_FUNCTION) + && (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_STRING_LITERAL)) + { + lexer_construct_literal_object (context_p, &lit_location, LEXER_STRING_LITERAL); + parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL); + parser_emit_cbc (context_p, CBC_POP_BLOCK); + parser_flush_cbc (context_p); + break; + } + } + + if (context_p->status_flags & PARSER_IS_STRICT && context_p->status_flags & PARSER_HAS_NON_STRICT_ARG) + { + parser_raise_error (context_p, PARSER_ERR_NON_STRICT_ARG_DEFINITION); + } + + while (context_p->token.type != LEXER_EOS || context_p->stack_top_uint8 != PARSER_STATEMENT_START) + { +#ifndef JERRY_NDEBUG + JERRY_ASSERT (context_p->stack_depth == context_p->context_stack_depth); +#endif /* !JERRY_NDEBUG */ + + JERRY_ASSERT (context_p->stack_top_uint8 != PARSER_STATEMENT_PRIVATE_SCOPE + && context_p->stack_top_uint8 != PARSER_STATEMENT_PRIVATE_CONTEXT); + + switch (context_p->token.type) + { + case LEXER_SEMICOLON: + { + break; + } + + case LEXER_RIGHT_BRACE: + { + if (parser_statement_flags[context_p->stack_top_uint8] & PARSER_STATM_SINGLE_STATM) + { + parser_raise_error (context_p, PARSER_ERR_STATEMENT_EXPECTED); + } + break; + } + + case LEXER_LEFT_BRACE: + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + parser_push_block_context (context_p, false); + } + else + { + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_BLOCK); + } + + parser_stack_iterator_init (context_p, &context_p->last_statement); + lexer_next_token (context_p); + continue; + } + + case LEXER_KEYW_VAR: + case LEXER_KEYW_LET: + case LEXER_KEYW_CONST: + { + parser_parse_var_statement (context_p); + break; + } + case LEXER_KEYW_CLASS: + { + parser_validate_lexical_context (context_p); + parser_parse_class (context_p, true); + goto consume_last_statement; + } +#if JERRY_MODULE_SYSTEM + case LEXER_KEYW_IMPORT: + { + parser_parse_import_statement (context_p); + break; + } + + case LEXER_KEYW_EXPORT: + { + if (parser_parse_export_statement (context_p)) + { + goto consume_last_statement; + } + break; + } +#endif /* JERRY_MODULE_SYSTEM */ + + case LEXER_KEYW_FUNCTION: + { + parser_parse_function_statement (context_p); + goto consume_last_statement; + } + + case LEXER_KEYW_IF: + { + parser_parse_if_statement_start (context_p); + continue; + } + + case LEXER_KEYW_SWITCH: + { + parser_parse_switch_statement_start (context_p); + continue; + } + + case LEXER_KEYW_DO: + { + parser_do_while_statement_t do_while_statement; + parser_loop_statement_t loop; + + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + + do_while_statement.start_offset = context_p->byte_code_size; + loop.branch_list_p = NULL; + + parser_stack_push (context_p, &do_while_statement, sizeof (parser_do_while_statement_t)); + parser_stack_push (context_p, &loop, sizeof (parser_loop_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_DO_WHILE); + parser_stack_iterator_init (context_p, &context_p->last_statement); + lexer_next_token (context_p); + continue; + } + + case LEXER_KEYW_WHILE: + { + parser_parse_while_statement_start (context_p); + continue; + } + + case LEXER_KEYW_FOR: + { + parser_parse_for_statement_start (context_p); + continue; + } + + case LEXER_KEYW_WITH: + { + parser_parse_with_statement_start (context_p); + continue; + } + + case LEXER_KEYW_TRY: + { + parser_try_statement_t try_statement; + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED); + } + +#ifndef JERRY_NDEBUG + PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + try_statement.type = parser_try_block; + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_TRY_CREATE_CONTEXT, &try_statement.branch); + + try_statement.scope_stack_top = context_p->scope_stack_top; + try_statement.scope_stack_reg_top = context_p->scope_stack_reg_top; + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_BLOCK); + + if (scanner_is_context_needed (context_p, PARSER_CHECK_BLOCK_CONTEXT)) + { + parser_emit_cbc_ext (context_p, CBC_EXT_TRY_CREATE_ENV); + } + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS); + } + + parser_stack_push (context_p, &try_statement, sizeof (parser_try_statement_t)); + parser_stack_push_uint8 (context_p, PARSER_STATEMENT_TRY); + parser_stack_iterator_init (context_p, &context_p->last_statement); + lexer_next_token (context_p); + continue; + } + + case LEXER_KEYW_DEFAULT: + { + parser_parse_default_statement (context_p); + continue; + } + + case LEXER_KEYW_CASE: + { + parser_parse_case_statement (context_p); + continue; + } + + case LEXER_KEYW_BREAK: + { + parser_parse_break_statement (context_p); + break; + } + + case LEXER_KEYW_CONTINUE: + { + parser_parse_continue_statement (context_p); + break; + } + + case LEXER_KEYW_THROW: + { + lexer_next_token (context_p); + if (context_p->token.flags & LEXER_WAS_NEWLINE) + { + parser_raise_error (context_p, PARSER_ERR_EXPRESSION_EXPECTED); + } + parser_parse_expression (context_p, PARSE_EXPR); + parser_emit_cbc (context_p, CBC_THROW); + break; + } + + case LEXER_KEYW_RETURN: + { + if (!(context_p->status_flags & PARSER_IS_FUNCTION)) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_RETURN); + } + if (context_p->status_flags & PARSER_IS_CLASS_STATIC_BLOCK) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_RETURN); + } + + lexer_next_token (context_p); + + if ((context_p->token.flags & LEXER_WAS_NEWLINE) || context_p->token.type == LEXER_SEMICOLON + || context_p->token.type == LEXER_EOS || context_p->token.type == LEXER_RIGHT_BRACE) + { + if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) + { + parser_emit_cbc_ext (context_p, CBC_EXT_RETURN_UNDEFINED); + break; + } + + parser_emit_cbc (context_p, CBC_RETURN_FUNCTION_END); + break; + } + + parser_parse_expression (context_p, PARSE_EXPR); + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = CBC_RETURN_WITH_LITERAL; + break; + } + + parser_emit_cbc (context_p, CBC_RETURN); + break; + } + + case LEXER_KEYW_DEBUGGER: + { + lexer_next_token (context_p); + break; + } + + case LEXER_LITERAL: + { + if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + if (JERRY_UNLIKELY (lexer_check_next_character (context_p, LIT_CHAR_COLON))) + { + parser_parse_label (context_p); + lexer_consume_next_character (context_p); + lexer_next_token (context_p); + continue; + } + + if (JERRY_UNLIKELY (lexer_token_is_let (context_p))) + { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION) + { + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + + if (context_p->status_flags & PARSER_IS_FUNCTION) + { + parser_parse_expression_statement (context_p, PARSE_EXPR); + break; + } + + parser_parse_block_expression (context_p, PARSE_EXPR); + break; + } + + context_p->token.type = LEXER_KEYW_LET; + parser_parse_var_statement (context_p); + break; + } + + if (JERRY_UNLIKELY (lexer_token_is_async (context_p)) + && context_p->next_scanner_info_p->source_p == context_p->source_p) + { + bool is_statement = true; + + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION) + { + is_statement = (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_STATEMENT) != 0; + + JERRY_ASSERT (!is_statement || (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_ASYNC)); + } + else + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION); + + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + + if (is_statement) + { + if (parser_statement_flags[context_p->stack_top_uint8] & PARSER_STATM_SINGLE_STATM) + { + parser_raise_error (context_p, PARSER_ERR_LEXICAL_SINGLE_STATEMENT); + } + + lexer_next_token (context_p); + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_FUNCTION); + continue; + } + } + } + /* FALLTHRU */ + } + + default: + { + int options = PARSE_EXPR; + + if (context_p->token.type == LEXER_EXPRESSION_START) + { + /* Restore the token type form the extra_value. */ + context_p->token.type = context_p->token.extra_value; + options |= PARSE_EXPR_HAS_LITERAL; + } + + if (context_p->status_flags & PARSER_IS_FUNCTION) + { + parser_parse_expression_statement (context_p, options); + } + else + { + parser_parse_block_expression (context_p, options); + } + + break; + } + } + + parser_flush_cbc (context_p); + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + if (context_p->stack_top_uint8 == PARSER_STATEMENT_BLOCK) + { + parser_stack_pop_uint8 (context_p); + parser_stack_iterator_init (context_p, &context_p->last_statement); + lexer_next_token (context_p); + } + else if (context_p->stack_top_uint8 == PARSER_STATEMENT_BLOCK_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_BLOCK_CONTEXT) + { + parser_pop_block_context (context_p); + lexer_next_token (context_p); + } + else if (context_p->stack_top_uint8 == PARSER_STATEMENT_SWITCH + || context_p->stack_top_uint8 == PARSER_STATEMENT_SWITCH_NO_DEFAULT) + { + int has_default = (context_p->stack_top_uint8 == PARSER_STATEMENT_SWITCH); + parser_loop_statement_t loop; + parser_switch_statement_t switch_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &loop, sizeof (parser_loop_statement_t)); + parser_stack_pop (context_p, &switch_statement, sizeof (parser_switch_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + JERRY_ASSERT (switch_statement.branch_list_p == NULL); + + if (!has_default) + { + parser_set_branch_to_current_position (context_p, &switch_statement.default_branch); + } + + parser_set_breaks_to_current_position (context_p, loop.branch_list_p); + lexer_next_token (context_p); + + if (context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_CONTEXT) + { + parser_pop_block_context (context_p); + } + } + else if (context_p->stack_top_uint8 == PARSER_STATEMENT_TRY) + { + parser_parse_try_statement_end (context_p); + } + else if (context_p->stack_top_uint8 == PARSER_STATEMENT_START) + { + if (context_p->status_flags & PARSER_IS_CLOSURE) + { + parser_stack_pop_uint8 (context_p); + context_p->last_statement.current_p = NULL; + /* There is no lexer_next_token here, since the + * next token belongs to the parent context. */ + return; + } + parser_raise_error (context_p, PARSER_ERR_INVALID_RIGHT_SQUARE); + } + } + else if (context_p->token.type == LEXER_SEMICOLON) + { + lexer_next_token (context_p); + } + else if (context_p->token.type != LEXER_EOS && !(context_p->token.flags & LEXER_WAS_NEWLINE)) + { + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + +consume_last_statement: + while (true) + { + switch (context_p->stack_top_uint8) + { + case PARSER_STATEMENT_LABEL: + { + parser_label_statement_t label; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &label, sizeof (parser_label_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_set_breaks_to_current_position (context_p, label.break_list_p); + continue; + } + + case PARSER_STATEMENT_IF: + { + if (parser_parse_if_statement_end (context_p)) + { + break; + } + continue; + } + + case PARSER_STATEMENT_ELSE: + { + parser_if_else_statement_t else_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &else_statement, sizeof (parser_if_else_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_set_branch_to_current_position (context_p, &else_statement.branch); + continue; + } + + case PARSER_STATEMENT_DO_WHILE: + { + parser_parse_do_while_statement_end (context_p); + if (context_p->token.type == LEXER_SEMICOLON) + { + lexer_next_token (context_p); + } + continue; + } + + case PARSER_STATEMENT_WHILE: + { + parser_parse_while_statement_end (context_p); + continue; + } + + case PARSER_STATEMENT_FOR: + { + parser_parse_for_statement_end (context_p); + continue; + } + + case PARSER_STATEMENT_FOR_IN: + case PARSER_STATEMENT_FOR_OF: + case PARSER_STATEMENT_FOR_AWAIT_OF: + { + parser_for_in_of_statement_t for_in_of_statement; + parser_loop_statement_t loop; + + uint8_t for_type = context_p->stack_top_uint8; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &loop, sizeof (parser_loop_statement_t)); + parser_stack_pop (context_p, &for_in_of_statement, sizeof (parser_for_in_of_statement_t)); + parser_stack_iterator_init (context_p, &context_p->last_statement); + + parser_set_continues_to_current_position (context_p, loop.branch_list_p); + + parser_flush_cbc (context_p); + + uint16_t stack_allocation = PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION; + if (for_type != PARSER_STATEMENT_FOR_IN) + { + stack_allocation = (for_type == PARSER_STATEMENT_FOR_OF ? PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION + : PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION); + } + + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, stack_allocation); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, stack_allocation); +#endif /* !JERRY_NDEBUG */ + + cbc_ext_opcode_t opcode = CBC_EXT_BRANCH_IF_FOR_IN_HAS_NEXT; + + if (for_type != PARSER_STATEMENT_FOR_IN) + { + opcode = (for_type == PARSER_STATEMENT_FOR_OF ? CBC_EXT_BRANCH_IF_FOR_OF_HAS_NEXT + : CBC_EXT_BRANCH_IF_FOR_AWAIT_OF_HAS_NEXT); + } + + parser_emit_cbc_ext_backward_branch (context_p, opcode, for_in_of_statement.start_offset); + + parser_set_breaks_to_current_position (context_p, loop.branch_list_p); + parser_set_branch_to_current_position (context_p, &for_in_of_statement.branch); + + if (context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_SCOPE + || context_p->stack_top_uint8 == PARSER_STATEMENT_PRIVATE_CONTEXT) + { + parser_pop_block_context (context_p); + } + + continue; + } + + case PARSER_STATEMENT_WITH: + { + parser_parse_with_statement_end (context_p); + continue; + } + + default: + { + break; + } + } + break; + } + } + + parser_stack_pop_uint8 (context_p); + context_p->last_statement.current_p = NULL; + + if (context_p->status_flags & PARSER_IS_CLOSURE) + { + parser_raise_error (context_p, PARSER_ERR_STATEMENT_EXPECTED); + } +} /* parser_parse_statements */ + +/** + * Free jumps stored on the stack if a parse error is occurred. + */ +void JERRY_ATTR_NOINLINE +parser_free_jumps (parser_stack_iterator_t iterator) /**< iterator position */ +{ + while (true) + { + uint8_t type = parser_stack_iterator_read_uint8 (&iterator); + parser_branch_node_t *branch_list_p = NULL; + + switch (type) + { + case PARSER_STATEMENT_START: + { + return; + } + + case PARSER_STATEMENT_LABEL: + { + parser_label_statement_t label; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &label, sizeof (parser_label_statement_t)); + parser_stack_iterator_skip (&iterator, sizeof (parser_label_statement_t)); + branch_list_p = label.break_list_p; + break; + } + + case PARSER_STATEMENT_SWITCH: + case PARSER_STATEMENT_SWITCH_NO_DEFAULT: + { + parser_switch_statement_t switch_statement; + parser_loop_statement_t loop; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + parser_stack_iterator_skip (&iterator, sizeof (parser_loop_statement_t)); + parser_stack_iterator_read (&iterator, &switch_statement, sizeof (parser_switch_statement_t)); + parser_stack_iterator_skip (&iterator, sizeof (parser_switch_statement_t)); + + branch_list_p = switch_statement.branch_list_p; + while (branch_list_p != NULL) + { + parser_branch_node_t *next_p = branch_list_p->next_p; + parser_free (branch_list_p, sizeof (parser_branch_node_t)); + branch_list_p = next_p; + } + branch_list_p = loop.branch_list_p; + break; + } + + case PARSER_STATEMENT_DO_WHILE: + case PARSER_STATEMENT_WHILE: + case PARSER_STATEMENT_FOR: + case PARSER_STATEMENT_FOR_IN: + case PARSER_STATEMENT_FOR_OF: + { + parser_loop_statement_t loop; + + parser_stack_iterator_skip (&iterator, 1); + parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t)); + parser_stack_iterator_skip (&iterator, parser_statement_length (type) - 1); + branch_list_p = loop.branch_list_p; + break; + } + + default: + { + parser_stack_iterator_skip (&iterator, parser_statement_length (type)); + continue; + } + } + + while (branch_list_p != NULL) + { + parser_branch_node_t *next_p = branch_list_p->next_p; + parser_free (branch_list_p, sizeof (parser_branch_node_t)); + branch_list_p = next_p; + } + } +} /* parser_free_jumps */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-tagged-template-literal.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-tagged-template-literal.cpp new file mode 100644 index 0000000..f2ce91e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-tagged-template-literal.cpp @@ -0,0 +1,161 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-tagged-template-literal.h" + +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "js-lexer.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_tagged_template_literal Tagged template literal + * @{ + */ + +/** + * Append the cooked and raw string to the corresponding array + */ +void +parser_tagged_template_literal_append_strings (parser_context_t *context_p, /**< parser context */ + ecma_object_t *template_obj_p, /**< template object */ + ecma_object_t *raw_strings_p, /**< raw strings object */ + uint32_t prop_idx) /**< property index to set the values */ +{ + lexer_lit_location_t *lit_loc_p = &context_p->token.lit_location; + + if (lit_loc_p->length == 0 && !(lit_loc_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + ecma_builtin_helper_def_prop_by_index (template_obj_p, + prop_idx, + ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY), + ECMA_PROPERTY_FLAG_ENUMERABLE); + + ecma_builtin_helper_def_prop_by_index (raw_strings_p, + prop_idx, + ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY), + ECMA_PROPERTY_FLAG_ENUMERABLE); + return; + } + + uint8_t local_byte_array[LEXER_MAX_LITERAL_LOCAL_BUFFER_SIZE]; + const uint8_t *source_p = + lexer_convert_literal_to_chars (context_p, &context_p->token.lit_location, local_byte_array, LEXER_STRING_NO_OPTS); + + ecma_string_t *raw_str_p; + ecma_string_t *cooked_str_p = + ((lit_loc_p->status_flags & LEXER_FLAG_ASCII) ? ecma_new_ecma_string_from_ascii (source_p, lit_loc_p->length) + : ecma_new_ecma_string_from_utf8 (source_p, lit_loc_p->length)); + + parser_free_allocated_buffer (context_p); + + if (lit_loc_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE) + { + context_p->source_p = context_p->token.lit_location.char_p - 1; + lexer_parse_string (context_p, LEXER_STRING_RAW); + source_p = + lexer_convert_literal_to_chars (context_p, &context_p->token.lit_location, local_byte_array, LEXER_STRING_RAW); + + raw_str_p = + ((lit_loc_p->status_flags & LEXER_FLAG_ASCII) ? ecma_new_ecma_string_from_ascii (source_p, lit_loc_p->length) + : ecma_new_ecma_string_from_utf8 (source_p, lit_loc_p->length)); + + parser_free_allocated_buffer (context_p); + } + else + { + ecma_ref_ecma_string (cooked_str_p); + raw_str_p = cooked_str_p; + } + + ecma_builtin_helper_def_prop_by_index (template_obj_p, + prop_idx, + ecma_make_string_value (cooked_str_p), + ECMA_PROPERTY_FLAG_ENUMERABLE); + + ecma_builtin_helper_def_prop_by_index (raw_strings_p, + prop_idx, + ecma_make_string_value (raw_str_p), + ECMA_PROPERTY_FLAG_ENUMERABLE); + + ecma_deref_ecma_string (cooked_str_p); + ecma_deref_ecma_string (raw_str_p); +} /* parser_tagged_template_literal_append_strings */ + +/** + * Create new tagged template literal object + * + * @return pointer to the allocated object + */ +ecma_object_t * +parser_new_tagged_template_literal (ecma_object_t **raw_strings_p) /**< [out] raw strings object */ +{ + ecma_object_t *template_obj_p = ecma_op_new_array_object (0); + *raw_strings_p = ecma_op_new_array_object (0); + + ecma_extended_object_t *template_ext_obj_p = (ecma_extended_object_t *) template_obj_p; + ecma_extended_object_t *raw_ext_obj_p = (ecma_extended_object_t *) *raw_strings_p; + + const uint8_t flags = ECMA_PROPERTY_VIRTUAL | ECMA_PROPERTY_FLAG_WRITABLE | ECMA_FAST_ARRAY_FLAG; + JERRY_ASSERT (template_ext_obj_p->u.array.length_prop_and_hole_count == flags); + JERRY_ASSERT (raw_ext_obj_p->u.array.length_prop_and_hole_count == flags); + + template_ext_obj_p->u.array.length_prop_and_hole_count = flags | ECMA_ARRAY_TEMPLATE_LITERAL; + raw_ext_obj_p->u.array.length_prop_and_hole_count = flags | ECMA_ARRAY_TEMPLATE_LITERAL; + + ecma_builtin_helper_def_prop (template_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_RAW), + ecma_make_object_value (*raw_strings_p), + ECMA_PROPERTY_FIXED); + + return template_obj_p; +} /* parser_new_tagged_template_literal */ + +/** + * Set integrity level of the given template array object to "frozen" + */ +static void +parser_tagged_template_literal_freeze_array (ecma_object_t *obj_p /**< template object */) +{ + JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY); + ecma_op_ordinary_object_prevent_extensions (obj_p); + ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; + ext_obj_p->u.array.length_prop_and_hole_count &= (uint32_t) ~ECMA_PROPERTY_FLAG_WRITABLE; +} /* parser_tagged_template_literal_freeze_array */ + +/** + * Finalize the tagged template object + */ +void +parser_tagged_template_literal_finalize (ecma_object_t *template_obj_p, /**< template object */ + ecma_object_t *raw_strings_p) /**< raw strings object */ +{ + parser_tagged_template_literal_freeze_array (template_obj_p); + parser_tagged_template_literal_freeze_array (raw_strings_p); +} /* parser_tagged_template_literal_finalize */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-tagged-template-literal.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-tagged-template-literal.h new file mode 100644 index 0000000..919cc1b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-tagged-template-literal.h @@ -0,0 +1,49 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMA_TAGGED_TEMPLATE_LITERAL_H +#define ECMA_TAGGED_TEMPLATE_LITERAL_H + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_tagged_template_literal Tagged template literal + * @{ + */ + +#include "ecma-globals.h" + +#include "common.h" +#include "js-parser-internal.h" + +ecma_object_t *parser_new_tagged_template_literal (ecma_object_t **raw_strings_p); + +void parser_tagged_template_literal_append_strings (parser_context_t *context_p, + ecma_object_t *template_obj_p, + ecma_object_t *raw_strings_p, + uint32_t prop_index); + +void parser_tagged_template_literal_finalize (ecma_object_t *template_obj_p, ecma_object_t *raw_strings_p); + +/** + * @} + * @} + * @} + */ + +#endif /* ECMA_TAGGED_TEMPLATE_LITERAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-util.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-util.cpp new file mode 100644 index 0000000..7cdcc01 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser-util.cpp @@ -0,0 +1,870 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-helpers.h" + +#include "js-parser-internal.h" + +#if JERRY_PARSER + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_utils Utility + * @{ + */ + +/**********************************************************************/ +/* Emitting byte codes */ +/**********************************************************************/ + +/** + * Append two bytes to the cbc stream. + */ +static void +parser_emit_two_bytes (parser_context_t *context_p, /**< context */ + uint8_t first_byte, /**< first byte */ + uint8_t second_byte) /**< second byte */ +{ + uint32_t last_position = context_p->byte_code.last_position; + + if (last_position + 2 <= PARSER_CBC_STREAM_PAGE_SIZE) + { + parser_mem_page_t *page_p = context_p->byte_code.last_p; + + page_p->bytes[last_position] = first_byte; + page_p->bytes[last_position + 1] = second_byte; + context_p->byte_code.last_position = last_position + 2; + } + else if (last_position >= PARSER_CBC_STREAM_PAGE_SIZE) + { + parser_mem_page_t *page_p; + + parser_cbc_stream_alloc_page (context_p, &context_p->byte_code); + page_p = context_p->byte_code.last_p; + page_p->bytes[0] = first_byte; + page_p->bytes[1] = second_byte; + context_p->byte_code.last_position = 2; + } + else + { + context_p->byte_code.last_p->bytes[PARSER_CBC_STREAM_PAGE_SIZE - 1] = first_byte; + parser_cbc_stream_alloc_page (context_p, &context_p->byte_code); + context_p->byte_code.last_p->bytes[0] = second_byte; + context_p->byte_code.last_position = 1; + } +} /* parser_emit_two_bytes */ + +/** + * Append byte to the end of the current byte code stream. + * + * @param context_p parser context + * @param byte byte + */ +#define PARSER_APPEND_TO_BYTE_CODE(context_p, byte) \ + if ((context_p)->byte_code.last_position >= PARSER_CBC_STREAM_PAGE_SIZE) \ + { \ + parser_cbc_stream_alloc_page ((context_p), &(context_p)->byte_code); \ + } \ + (context_p)->byte_code.last_p->bytes[(context_p)->byte_code.last_position++] = (uint8_t) (byte) + +#if JERRY_PARSER_DUMP_BYTE_CODE + +/** + * Print literal corresponding to the current index + */ +static void +parser_print_literal (parser_context_t *context_p, /**< context */ + uint16_t literal_index) /**< index of literal */ +{ + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p; + parser_scope_stack_t *scope_stack_end_p = scope_stack_p + context_p->scope_stack_top; + bool in_scope_literal = false; + + while (scope_stack_p < scope_stack_end_p) + { + scope_stack_end_p--; + + if (scope_stack_end_p->map_from == PARSER_SCOPE_STACK_FUNC) + { + if (literal_index == scope_stack_end_p->map_to) + { + in_scope_literal = true; + break; + } + } + else if (literal_index == scanner_decode_map_to (scope_stack_end_p)) + { + in_scope_literal = true; + break; + } + } + + if (literal_index < PARSER_REGISTER_START) + { + JERRY_DEBUG_MSG (in_scope_literal ? " IDX:%d->" : " idx:%d->", literal_index); + lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index); + util_print_literal (literal_p); + return; + } + + if (!in_scope_literal) + { + JERRY_DEBUG_MSG (" reg:%d", (int) (literal_index - PARSER_REGISTER_START)); + return; + } + + JERRY_DEBUG_MSG (" REG:%d->", (int) (literal_index - PARSER_REGISTER_START)); + + lexer_literal_t *literal_p = PARSER_GET_LITERAL (scope_stack_end_p->map_from); + util_print_literal (literal_p); +} /* parser_print_literal */ + +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + +/** + * Append the current byte code to the stream + */ +void +parser_flush_cbc (parser_context_t *context_p) /**< context */ +{ + uint8_t flags; + uint16_t last_opcode = context_p->last_cbc_opcode; + + if (last_opcode == PARSER_CBC_UNAVAILABLE) + { + return; + } + + context_p->status_flags |= PARSER_NO_END_LABEL; + + if (PARSER_IS_BASIC_OPCODE (last_opcode)) + { + cbc_opcode_t opcode = (cbc_opcode_t) last_opcode; + + JERRY_ASSERT (opcode < CBC_END); + flags = cbc_flags[opcode]; + + PARSER_APPEND_TO_BYTE_CODE (context_p, opcode); + context_p->byte_code_size++; + } + else + { + cbc_ext_opcode_t opcode = (cbc_ext_opcode_t) PARSER_GET_EXT_OPCODE (last_opcode); + + JERRY_ASSERT (opcode < CBC_EXT_END); + flags = cbc_ext_flags[opcode]; + parser_emit_two_bytes (context_p, CBC_EXT_OPCODE, (uint8_t) opcode); + context_p->byte_code_size += 2; + } + + JERRY_ASSERT ((flags >> CBC_STACK_ADJUST_SHIFT) >= CBC_STACK_ADJUST_BASE + || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); + PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, CBC_STACK_ADJUST_VALUE (flags)); + + if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) + { + uint16_t literal_index = context_p->last_cbc.literal_index; + + parser_emit_two_bytes (context_p, (uint8_t) (literal_index & 0xff), (uint8_t) (literal_index >> 8)); + context_p->byte_code_size += 2; + } + + if (flags & CBC_HAS_LITERAL_ARG2) + { + uint16_t literal_index = context_p->last_cbc.value; + + parser_emit_two_bytes (context_p, (uint8_t) (literal_index & 0xff), (uint8_t) (literal_index >> 8)); + context_p->byte_code_size += 2; + + if (!(flags & CBC_HAS_LITERAL_ARG)) + { + literal_index = context_p->last_cbc.third_literal_index; + + parser_emit_two_bytes (context_p, (uint8_t) (literal_index & 0xff), (uint8_t) (literal_index >> 8)); + context_p->byte_code_size += 2; + } + } + + if (flags & CBC_HAS_BYTE_ARG) + { + uint8_t byte_argument = (uint8_t) context_p->last_cbc.value; + + JERRY_ASSERT (context_p->last_cbc.value <= CBC_MAXIMUM_BYTE_VALUE); + + if (flags & CBC_POP_STACK_BYTE_ARG) + { + JERRY_ASSERT (context_p->stack_depth >= byte_argument); + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, byte_argument); + } + + PARSER_APPEND_TO_BYTE_CODE (context_p, byte_argument); + context_p->byte_code_size++; + } + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG (" [%3d] %s", + (int) context_p->stack_depth, + PARSER_IS_BASIC_OPCODE (last_opcode) ? cbc_names[last_opcode] + : cbc_ext_names[PARSER_GET_EXT_OPCODE (last_opcode)]); + + if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) + { + parser_print_literal (context_p, context_p->last_cbc.literal_index); + } + + if (flags & CBC_HAS_LITERAL_ARG2) + { + parser_print_literal (context_p, context_p->last_cbc.value); + + if (!(flags & CBC_HAS_LITERAL_ARG)) + { + parser_print_literal (context_p, context_p->last_cbc.third_literal_index); + } + } + + if (flags & CBC_HAS_BYTE_ARG) + { + if (last_opcode == CBC_PUSH_NUMBER_POS_BYTE || last_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE) + { + JERRY_DEBUG_MSG (" number:%d", (int) context_p->last_cbc.value + 1); + } + else if (last_opcode == CBC_PUSH_NUMBER_NEG_BYTE || last_opcode == CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE) + { + JERRY_DEBUG_MSG (" number:%d", -((int) context_p->last_cbc.value + 1)); + } + else + { + JERRY_DEBUG_MSG (" byte_arg:%d", (int) context_p->last_cbc.value); + } + } + + JERRY_DEBUG_MSG ("\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + if (context_p->stack_depth > context_p->stack_limit) + { + context_p->stack_limit = context_p->stack_depth; + if (context_p->stack_limit > PARSER_MAXIMUM_STACK_LIMIT) + { + parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED); + } + } + + context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE; +} /* parser_flush_cbc */ + +/** + * Append a byte code + */ +void +parser_emit_cbc (parser_context_t *context_p, /**< context */ + uint16_t opcode) /**< opcode */ +{ + JERRY_ASSERT (PARSER_ARGS_EQ (opcode, 0)); + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->last_cbc_opcode = opcode; +} /* parser_emit_cbc */ + +/** + * Append a byte code with a literal argument + */ +void +parser_emit_cbc_literal (parser_context_t *context_p, /**< context */ + uint16_t opcode, /**< opcode */ + uint16_t literal_index) /**< literal index */ +{ + JERRY_ASSERT (PARSER_ARGS_EQ (opcode, CBC_HAS_LITERAL_ARG)); + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->last_cbc_opcode = opcode; + context_p->last_cbc.literal_index = literal_index; + context_p->last_cbc.literal_type = LEXER_UNUSED_LITERAL; + context_p->last_cbc.literal_keyword_type = LEXER_EOS; +} /* parser_emit_cbc_literal */ + +/** + * Append a byte code with a literal and value argument + */ +void +parser_emit_cbc_literal_value (parser_context_t *context_p, /**< context */ + uint16_t opcode, /**< opcode */ + uint16_t literal_index, /**< literal index */ + uint16_t value) /**< value */ +{ + JERRY_ASSERT (PARSER_ARGS_EQ (opcode, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)); + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->last_cbc_opcode = opcode; + context_p->last_cbc.literal_index = literal_index; + context_p->last_cbc.literal_type = LEXER_UNUSED_LITERAL; + context_p->last_cbc.literal_keyword_type = LEXER_EOS; + context_p->last_cbc.value = value; +} /* parser_emit_cbc_literal_value */ + +/** + * Append a byte code with the current literal argument + */ +void +parser_emit_cbc_literal_from_token (parser_context_t *context_p, /**< context */ + uint16_t opcode) /**< opcode */ +{ + JERRY_ASSERT (PARSER_ARGS_EQ (opcode, CBC_HAS_LITERAL_ARG)); + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->last_cbc_opcode = opcode; + context_p->last_cbc.literal_index = context_p->lit_object.index; + context_p->last_cbc.literal_type = context_p->token.lit_location.type; + context_p->last_cbc.literal_keyword_type = context_p->token.keyword_type; +} /* parser_emit_cbc_literal_from_token */ + +/** + * Append a byte code with a call argument + */ +void +parser_emit_cbc_call (parser_context_t *context_p, /**< context */ + uint16_t opcode, /**< opcode */ + size_t call_arguments) /**< number of arguments */ +{ + JERRY_ASSERT (PARSER_ARGS_EQ (opcode, CBC_HAS_BYTE_ARG)); + JERRY_ASSERT (call_arguments <= CBC_MAXIMUM_BYTE_VALUE); + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->last_cbc_opcode = opcode; + context_p->last_cbc.value = (uint16_t) call_arguments; +} /* parser_emit_cbc_call */ + +/** + * Append a push number 1/2 byte code + */ +void +parser_emit_cbc_push_number (parser_context_t *context_p, /**< context */ + bool is_negative_number) /**< sign is negative */ +{ + uint16_t value = context_p->lit_object.index; + uint16_t lit_value = PARSER_INVALID_LITERAL_INDEX; + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + lit_value = context_p->last_cbc.literal_index; + } + else + { + if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + context_p->last_cbc_opcode = CBC_PUSH_LITERAL; + lit_value = context_p->last_cbc.value; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_THREE_LITERALS) + { + context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS; + lit_value = context_p->last_cbc.third_literal_index; + } + + parser_flush_cbc (context_p); + } + } + + if (value == 0) + { + if (lit_value == PARSER_INVALID_LITERAL_INDEX) + { + context_p->last_cbc_opcode = CBC_PUSH_NUMBER_0; + return; + } + + context_p->last_cbc_opcode = CBC_PUSH_LITERAL_PUSH_NUMBER_0; + context_p->last_cbc.literal_index = lit_value; + return; + } + + uint16_t opcode; + + if (lit_value == PARSER_INVALID_LITERAL_INDEX) + { + opcode = (is_negative_number ? CBC_PUSH_NUMBER_NEG_BYTE : CBC_PUSH_NUMBER_POS_BYTE); + + JERRY_ASSERT (CBC_STACK_ADJUST_VALUE (PARSER_GET_FLAGS (opcode)) == 1); + } + else + { + opcode = (is_negative_number ? CBC_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE : CBC_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE); + JERRY_ASSERT (CBC_STACK_ADJUST_VALUE (PARSER_GET_FLAGS (opcode)) == 2); + + context_p->last_cbc.literal_index = lit_value; + } + + JERRY_ASSERT (value > 0 && value <= CBC_PUSH_NUMBER_BYTE_RANGE_END); + + context_p->last_cbc_opcode = opcode; + context_p->last_cbc.value = (uint16_t) (value - 1); +} /* parser_emit_cbc_push_number */ + +/** + * Append a byte code with a branch argument + */ +void +parser_emit_cbc_forward_branch (parser_context_t *context_p, /**< context */ + uint16_t opcode, /**< opcode */ + parser_branch_t *branch_p) /**< branch result */ +{ + uint8_t flags; + uint32_t extra_byte_code_increase; + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->status_flags |= PARSER_NO_END_LABEL; + + if (PARSER_IS_BASIC_OPCODE (opcode)) + { + JERRY_ASSERT (opcode < CBC_END); + flags = cbc_flags[opcode]; + extra_byte_code_increase = 0; + } + else + { + PARSER_APPEND_TO_BYTE_CODE (context_p, CBC_EXT_OPCODE); + opcode = (uint16_t) PARSER_GET_EXT_OPCODE (opcode); + + JERRY_ASSERT (opcode < CBC_EXT_END); + flags = cbc_ext_flags[opcode]; + extra_byte_code_increase = 1; + } + + JERRY_ASSERT (flags & CBC_HAS_BRANCH_ARG); + JERRY_ASSERT (CBC_BRANCH_IS_FORWARD (flags)); + JERRY_ASSERT (CBC_BRANCH_OFFSET_LENGTH (opcode) == 1); + + /* Branch opcodes never push anything onto the stack. */ + JERRY_ASSERT ((flags >> CBC_STACK_ADJUST_SHIFT) >= CBC_STACK_ADJUST_BASE + || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); + PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, CBC_STACK_ADJUST_VALUE (flags)); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG (" [%3d] %s\n", + (int) context_p->stack_depth, + extra_byte_code_increase == 0 ? cbc_names[opcode] : cbc_ext_names[opcode]); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + PARSER_PLUS_EQUAL_U16 (opcode, PARSER_MAX_BRANCH_LENGTH - 1); + + parser_emit_two_bytes (context_p, (uint8_t) opcode, 0); + branch_p->page_p = context_p->byte_code.last_p; + branch_p->offset = (context_p->byte_code.last_position - 1) | (context_p->byte_code_size << 8); + + context_p->byte_code_size += extra_byte_code_increase; + +#if PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX + PARSER_APPEND_TO_BYTE_CODE (context_p, 0); +#else /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */ + parser_emit_two_bytes (context_p, 0, 0); +#endif /* PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX */ + + context_p->byte_code_size += PARSER_MAX_BRANCH_LENGTH + 1; + + if (context_p->stack_depth > context_p->stack_limit) + { + context_p->stack_limit = context_p->stack_depth; + if (context_p->stack_limit > PARSER_MAXIMUM_STACK_LIMIT) + { + parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED); + } + } +} /* parser_emit_cbc_forward_branch */ + +/** + * Append a branch byte code and create an item. + * + * @return newly created parser branch node + */ +parser_branch_node_t * +parser_emit_cbc_forward_branch_item (parser_context_t *context_p, /**< context */ + uint16_t opcode, /**< opcode */ + parser_branch_node_t *next_p) /**< next branch */ +{ + parser_branch_t branch; + parser_branch_node_t *new_item; + + /* Since byte code insertion may throw an out-of-memory error, + * the branch is constructed locally, and copied later. */ + parser_emit_cbc_forward_branch (context_p, opcode, &branch); + + new_item = (parser_branch_node_t *) parser_malloc (context_p, sizeof (parser_branch_node_t)); + new_item->branch = branch; + new_item->next_p = next_p; + return new_item; +} /* parser_emit_cbc_forward_branch_item */ + +/** + * Append a byte code with a branch argument + */ +void +parser_emit_cbc_backward_branch (parser_context_t *context_p, /**< context */ + uint16_t opcode, /**< opcode */ + uint32_t offset) /**< destination offset */ +{ + uint8_t flags; +#if JERRY_PARSER_DUMP_BYTE_CODE + const char *name; +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->status_flags |= PARSER_NO_END_LABEL; + offset = context_p->byte_code_size - offset; + + if (PARSER_IS_BASIC_OPCODE (opcode)) + { + JERRY_ASSERT (opcode < CBC_END); + flags = cbc_flags[opcode]; + +#if JERRY_PARSER_DUMP_BYTE_CODE + name = cbc_names[opcode]; +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + } + else + { + PARSER_APPEND_TO_BYTE_CODE (context_p, CBC_EXT_OPCODE); + opcode = (uint16_t) PARSER_GET_EXT_OPCODE (opcode); + + JERRY_ASSERT (opcode < CBC_EXT_END); + flags = cbc_ext_flags[opcode]; + context_p->byte_code_size++; + +#if JERRY_PARSER_DUMP_BYTE_CODE + name = cbc_ext_names[opcode]; +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + } + + JERRY_ASSERT (flags & CBC_HAS_BRANCH_ARG); + JERRY_ASSERT (CBC_BRANCH_IS_BACKWARD (flags)); + JERRY_ASSERT (CBC_BRANCH_OFFSET_LENGTH (opcode) == 1); + JERRY_ASSERT (offset <= context_p->byte_code_size); + + /* Branch opcodes never push anything onto the stack. */ + JERRY_ASSERT ((flags >> CBC_STACK_ADJUST_SHIFT) >= CBC_STACK_ADJUST_BASE + || (CBC_STACK_ADJUST_BASE - (flags >> CBC_STACK_ADJUST_SHIFT)) <= context_p->stack_depth); + PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, CBC_STACK_ADJUST_VALUE (flags)); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG (" [%3d] %s\n", (int) context_p->stack_depth, name); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + context_p->byte_code_size += 2; +#if PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX + if (offset > UINT16_MAX) + { + opcode++; + context_p->byte_code_size++; + } +#endif /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */ + + if (offset > UINT8_MAX) + { + opcode++; + context_p->byte_code_size++; + } + + PARSER_APPEND_TO_BYTE_CODE (context_p, (uint8_t) opcode); + +#if PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX + if (offset > UINT16_MAX) + { + PARSER_APPEND_TO_BYTE_CODE (context_p, offset >> 16); + } +#endif /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */ + + if (offset > UINT8_MAX) + { + PARSER_APPEND_TO_BYTE_CODE (context_p, (offset >> 8) & 0xff); + } + + PARSER_APPEND_TO_BYTE_CODE (context_p, offset & 0xff); +} /* parser_emit_cbc_backward_branch */ + +#undef PARSER_CHECK_LAST_POSITION +#undef PARSER_APPEND_TO_BYTE_CODE + +/** + * Helper function for parser. + * + * @return a new string based on encode. + */ +ecma_string_t * +parser_new_ecma_string_from_literal (lexer_literal_t *literal_p) /**< literal */ +{ + JERRY_ASSERT (literal_p != NULL); + + ecma_string_t *new_string = NULL; + + if (literal_p->status_flags & LEXER_FLAG_ASCII) + { + new_string = ecma_new_ecma_string_from_ascii (literal_p->u.char_p, literal_p->prop.length); + } + else + { + new_string = ecma_new_ecma_string_from_utf8 (literal_p->u.char_p, literal_p->prop.length); + } + + return new_string; +} /* parser_new_ecma_string_from_literal */ + +/** + * Set a branch to the current byte code position + */ +void +parser_set_branch_to_current_position (parser_context_t *context_p, /**< context */ + parser_branch_t *branch_p) /**< branch result */ +{ + uint32_t delta; + size_t offset; + parser_mem_page_t *page_p = branch_p->page_p; + + if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE) + { + parser_flush_cbc (context_p); + } + + context_p->status_flags &= (uint32_t) ~PARSER_NO_END_LABEL; + + JERRY_ASSERT (context_p->byte_code_size > (branch_p->offset >> 8)); + + delta = context_p->byte_code_size - (branch_p->offset >> 8); + offset = (branch_p->offset & CBC_LOWER_SEVEN_BIT_MASK); + + JERRY_ASSERT (delta <= PARSER_MAXIMUM_CODE_SIZE); + +#if PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX + page_p->bytes[offset++] = (uint8_t) (delta >> 8); + if (offset >= PARSER_CBC_STREAM_PAGE_SIZE) + { + page_p = page_p->next_p; + offset = 0; + } +#else /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */ + page_p->bytes[offset++] = (uint8_t) (delta >> 16); + if (offset >= PARSER_CBC_STREAM_PAGE_SIZE) + { + page_p = page_p->next_p; + offset = 0; + } + page_p->bytes[offset++] = (uint8_t) ((delta >> 8) & 0xff); + if (offset >= PARSER_CBC_STREAM_PAGE_SIZE) + { + page_p = page_p->next_p; + offset = 0; + } +#endif /* PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX */ + page_p->bytes[offset] = delta & 0xff; +} /* parser_set_branch_to_current_position */ + +/** + * Set breaks to the current byte code position + */ +void +parser_set_breaks_to_current_position (parser_context_t *context_p, /**< context */ + parser_branch_node_t *current_p) /**< branch list */ +{ + while (current_p != NULL) + { + parser_branch_node_t *next_p = current_p->next_p; + + if (!(current_p->branch.offset & CBC_HIGHEST_BIT_MASK)) + { + parser_set_branch_to_current_position (context_p, ¤t_p->branch); + } + parser_free (current_p, sizeof (parser_branch_node_t)); + current_p = next_p; + } +} /* parser_set_breaks_to_current_position */ + +/** + * Set continues to the current byte code position + */ +void +parser_set_continues_to_current_position (parser_context_t *context_p, /**< context */ + parser_branch_node_t *current_p) /**< branch list */ +{ + while (current_p != NULL) + { + if (current_p->branch.offset & CBC_HIGHEST_BIT_MASK) + { + parser_set_branch_to_current_position (context_p, ¤t_p->branch); + } + current_p = current_p->next_p; + } +} /* parser_set_continues_to_current_position */ + +/** + * Return the size of internal record corresponding to a class field + * + * @return internal record size + */ +static size_t +parser_get_class_field_info_size (uint8_t class_field_type) /**< class field type */ +{ + if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED) + { + return sizeof (scanner_range_t) + 1; + } + + if (class_field_type & PARSER_CLASS_FIELD_NORMAL) + { + return sizeof (scanner_location_t) + 1; + } + + return 1; +} /* parser_get_class_field_info_size */ + +/** + * Reverse the field list of a class + */ +void +parser_reverse_class_fields (parser_context_t *context_p, /**< context */ + size_t fields_size) /**< size of consumed memory */ +{ + uint8_t *data_p = (uint8_t *) parser_malloc (context_p, fields_size); + uint8_t *data_end_p = data_p + fields_size; + uint8_t *current_p = data_p; + bool has_fields = false; + parser_stack_iterator_t iterator; + + JERRY_ASSERT (!(context_p->stack_top_uint8 & PARSER_CLASS_FIELD_END)); + + parser_stack_iterator_init (context_p, &iterator); + + do + { + uint8_t class_field_type = parser_stack_iterator_read_uint8 (&iterator); + size_t info_size = parser_get_class_field_info_size (class_field_type); + + parser_stack_iterator_read (&iterator, current_p, info_size); + parser_stack_iterator_skip (&iterator, info_size); + current_p += info_size; + + if (!(class_field_type & PARSER_CLASS_FIELD_STATIC)) + { + has_fields = true; + context_p->stack_top_uint8 = class_field_type; + } + } while (current_p < data_end_p); + + parser_stack_iterator_init (context_p, &iterator); + current_p = data_end_p; + + bool has_static_fields = false; + + if (has_fields) + { + do + { + uint8_t class_field_type = current_p[-1]; + + size_t info_size = parser_get_class_field_info_size (class_field_type); + + if (!(class_field_type & PARSER_CLASS_FIELD_STATIC)) + { + current_p -= info_size; + parser_stack_iterator_write (&iterator, current_p, info_size); + parser_stack_iterator_skip (&iterator, info_size); + continue; + } + + if (!has_static_fields) + { + has_static_fields = true; + current_p[-1] |= PARSER_CLASS_FIELD_END; + } + current_p -= info_size; + } while (current_p > data_p); + } + else + { + /* All class fields are static. */ + has_static_fields = true; + JERRY_ASSERT (data_end_p[-1] & PARSER_CLASS_FIELD_STATIC); + context_p->stack_top_uint8 = data_end_p[-1]; + } + + if (has_static_fields) + { + current_p = data_end_p; + + do + { + uint8_t class_field_type = current_p[-1]; + + size_t info_size = parser_get_class_field_info_size (class_field_type); + current_p -= info_size; + + if (class_field_type & PARSER_CLASS_FIELD_STATIC) + { + parser_stack_iterator_write (&iterator, current_p, info_size); + parser_stack_iterator_skip (&iterator, info_size); + } + } while (current_p > data_p); + } + + parser_free (data_p, fields_size); +} /* parser_reverse_class_fields */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser.cpp new file mode 100644 index 0000000..77fc7de --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser.cpp @@ -0,0 +1,3056 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-exceptions.h" +#include "ecma-extended-info.h" +#include "ecma-helpers.h" +#include "ecma-literal-storage.h" +#include "ecma-module.h" + +#include "jcontext.h" +#include "js-parser-internal.h" +#include "lit-char-helpers.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_parser Parser + * @{ + */ + +#if JERRY_PARSER + +JERRY_STATIC_ASSERT (((int) ECMA_PARSE_STRICT_MODE == (int) PARSER_IS_STRICT), + ecma_parse_strict_mode_must_be_equal_to_parser_is_strict); + +JERRY_STATIC_ASSERT (PARSER_SAVE_STATUS_FLAGS (PARSER_ALLOW_SUPER) == 0x1, incorrect_saving_of_ecma_parse_allow_super); +JERRY_STATIC_ASSERT ((PARSER_RESTORE_STATUS_FLAGS (ECMA_PARSE_ALLOW_SUPER) == PARSER_ALLOW_SUPER), + incorrect_restoring_of_ecma_parse_allow_super); + +JERRY_STATIC_ASSERT ((PARSER_RESTORE_STATUS_FLAGS (ECMA_PARSE_FUNCTION_CONTEXT) == 0), + ecma_parse_function_context_must_not_be_transformed); + +/** + * Compute real literal indices. + * + * @return length of the prefix opcodes + */ +static void +parser_compute_indices (parser_context_t *context_p, /**< context */ + uint16_t *ident_end, /**< end of the identifier group */ + uint16_t *const_literal_end) /**< end of the const literal group */ +{ + parser_list_iterator_t literal_iterator; + lexer_literal_t *literal_p; + + uint16_t ident_count = 0; + uint16_t const_literal_count = 0; + + uint16_t ident_index; + uint16_t const_literal_index; + uint16_t literal_index; + + /* First phase: count the number of items in each group. */ + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator))) + { + switch (literal_p->type) + { + case LEXER_IDENT_LITERAL: + { + if (literal_p->status_flags & LEXER_FLAG_USED) + { + ident_count++; + break; + } + else if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR)) + { + jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length); + /* This literal should not be freed even if an error is encountered later. */ + literal_p->status_flags |= LEXER_FLAG_SOURCE_PTR; + } + continue; + } + case LEXER_STRING_LITERAL: + { + const_literal_count++; + break; + } + case LEXER_NUMBER_LITERAL: + { + const_literal_count++; + continue; + } + case LEXER_FUNCTION_LITERAL: + case LEXER_REGEXP_LITERAL: + { + continue; + } + default: + { + JERRY_ASSERT (literal_p->type == LEXER_UNUSED_LITERAL); + continue; + } + } + + const uint8_t *char_p = literal_p->u.char_p; + uint32_t status_flags = context_p->status_flags; + + if ((literal_p->status_flags & LEXER_FLAG_SOURCE_PTR) && literal_p->prop.length < 0xfff) + { + size_t bytes_to_end = (size_t) (context_p->source_end_p - char_p); + + if (bytes_to_end < 0xfffff) + { + literal_p->u.source_data = ((uint32_t) bytes_to_end) | (((uint32_t) literal_p->prop.length) << 20); + literal_p->status_flags |= LEXER_FLAG_LATE_INIT; + status_flags |= PARSER_HAS_LATE_LIT_INIT; + context_p->status_flags = status_flags; + char_p = NULL; + } + } + + if (char_p != NULL) + { + literal_p->u.value = ecma_find_or_create_literal_string (char_p, + literal_p->prop.length, + (literal_p->status_flags & LEXER_FLAG_ASCII) != 0); + + if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR)) + { + jmem_heap_free_block ((void *) char_p, literal_p->prop.length); + /* This literal should not be freed even if an error is encountered later. */ + literal_p->status_flags |= LEXER_FLAG_SOURCE_PTR; + } + } + } + + ident_index = context_p->register_count; + const_literal_index = (uint16_t) (ident_index + ident_count); + literal_index = (uint16_t) (const_literal_index + const_literal_count); + + /* Second phase: Assign an index to each literal. */ + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator))) + { + switch (literal_p->type) + { + case LEXER_IDENT_LITERAL: + { + if (literal_p->status_flags & LEXER_FLAG_USED) + { + literal_p->prop.index = ident_index; + ident_index++; + } + break; + } + case LEXER_STRING_LITERAL: + case LEXER_NUMBER_LITERAL: + { + JERRY_ASSERT ((literal_p->status_flags & ~(LEXER_FLAG_SOURCE_PTR | LEXER_FLAG_LATE_INIT)) == 0); + literal_p->prop.index = const_literal_index; + const_literal_index++; + break; + } + case LEXER_FUNCTION_LITERAL: + case LEXER_REGEXP_LITERAL: + { + JERRY_ASSERT (literal_p->status_flags == 0); + + literal_p->prop.index = literal_index; + literal_index++; + break; + } + default: + { + JERRY_ASSERT (literal_p->type == LEXER_UNUSED_LITERAL + && literal_p->status_flags == LEXER_FLAG_FUNCTION_ARGUMENT); + break; + } + } + } + + JERRY_ASSERT (ident_index == context_p->register_count + ident_count); + JERRY_ASSERT (const_literal_index == ident_index + const_literal_count); + JERRY_ASSERT (literal_index <= context_p->register_count + context_p->literal_count); + + context_p->literal_count = literal_index; + + *ident_end = ident_index; + *const_literal_end = const_literal_index; +} /* parser_compute_indices */ + +/** + * Initialize literal pool. + */ +static void +parser_init_literal_pool (parser_context_t *context_p, /**< context */ + ecma_value_t *literal_pool_p) /**< start of literal pool */ +{ + parser_list_iterator_t literal_iterator; + lexer_literal_t *literal_p; + + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator))) + { + switch (literal_p->type) + { + case LEXER_IDENT_LITERAL: + { + if (!(literal_p->status_flags & LEXER_FLAG_USED)) + { + break; + } + /* FALLTHRU */ + } + case LEXER_STRING_LITERAL: + { + ecma_value_t lit_value = literal_p->u.value; + + JERRY_ASSERT (literal_p->prop.index >= context_p->register_count); + literal_pool_p[literal_p->prop.index] = lit_value; + break; + } + case LEXER_NUMBER_LITERAL: + { + JERRY_ASSERT (literal_p->prop.index >= context_p->register_count); + + literal_pool_p[literal_p->prop.index] = literal_p->u.value; + break; + } + case LEXER_FUNCTION_LITERAL: + case LEXER_REGEXP_LITERAL: + { + JERRY_ASSERT (literal_p->prop.index >= context_p->register_count); + + ECMA_SET_INTERNAL_VALUE_POINTER (literal_pool_p[literal_p->prop.index], literal_p->u.bytecode_p); + break; + } + default: + { + JERRY_ASSERT (literal_p->type == LEXER_UNUSED_LITERAL); + break; + } + } + } +} /* parser_init_literal_pool */ + +/* + * During byte code post processing certain bytes are not + * copied into the final byte code buffer. For example, if + * one byte is enough for encoding a literal index, the + * second byte is not copied. However, when a byte is skipped, + * the offsets of those branches which crosses (jumps over) + * that byte code should also be decreased by one. Instead + * of finding these jumps every time when a byte is skipped, + * all branch offset updates are computed in one step. + * + * Branch offset mapping example: + * + * Let's assume that each parser_mem_page of the byte_code + * buffer is 8 bytes long and only 4 bytes are kept for a + * given page: + * + * +---+---+---+---+---+---+---+---+ + * | X | 1 | 2 | 3 | X | 4 | X | X | + * +---+---+---+---+---+---+---+---+ + * + * X marks those bytes which are removed. The resulting + * offset mapping is the following: + * + * +---+---+---+---+---+---+---+---+ + * | 0 | 1 | 2 | 3 | 3 | 4 | 4 | 4 | + * +---+---+---+---+---+---+---+---+ + * + * Each X is simply replaced by the index of the previous + * index starting from zero. This shows the number of + * copied bytes before a given byte including the byte + * itself. The last byte always shows the number of bytes + * copied from this page. + * + * This mapping allows recomputing all branch targets, + * since mapping[to] - mapping[from] is the new argument + * for forward branches. As for backward branches, the + * equation is reversed to mapping[from] - mapping[to]. + * + * The mapping is relative to one page, so distance + * computation affecting multiple pages requires a loop. + * We should also note that only argument bytes can + * be skipped, so removed bytes cannot be targeted by + * branches. Valid branches always target instruction + * starts only. + */ + +/** + * Recompute the argument of a forward branch. + * + * @return the new distance + */ +static size_t +parser_update_forward_branch (parser_mem_page_t *page_p, /**< current page */ + size_t full_distance, /**< full distance */ + uint8_t bytes_copied_before_jump) /**< bytes copied before jump */ +{ + size_t new_distance = 0; + + while (full_distance > PARSER_CBC_STREAM_PAGE_SIZE) + { + new_distance += page_p->bytes[PARSER_CBC_STREAM_PAGE_SIZE - 1] & CBC_LOWER_SEVEN_BIT_MASK; + full_distance -= PARSER_CBC_STREAM_PAGE_SIZE; + page_p = page_p->next_p; + } + + new_distance += page_p->bytes[full_distance - 1] & CBC_LOWER_SEVEN_BIT_MASK; + return new_distance - bytes_copied_before_jump; +} /* parser_update_forward_branch */ + +/** + * Recompute the argument of a backward branch. + * + * @return the new distance + */ +static size_t +parser_update_backward_branch (parser_mem_page_t *page_p, /**< current page */ + size_t full_distance, /**< full distance */ + uint8_t bytes_copied_before_jump) /**< bytes copied before jump */ +{ + size_t new_distance = bytes_copied_before_jump; + + while (full_distance >= PARSER_CBC_STREAM_PAGE_SIZE) + { + JERRY_ASSERT (page_p != NULL); + new_distance += page_p->bytes[PARSER_CBC_STREAM_PAGE_SIZE - 1] & CBC_LOWER_SEVEN_BIT_MASK; + full_distance -= PARSER_CBC_STREAM_PAGE_SIZE; + page_p = page_p->next_p; + } + + if (full_distance > 0) + { + size_t offset = PARSER_CBC_STREAM_PAGE_SIZE - full_distance; + + JERRY_ASSERT (page_p != NULL); + + new_distance += page_p->bytes[PARSER_CBC_STREAM_PAGE_SIZE - 1] & CBC_LOWER_SEVEN_BIT_MASK; + new_distance -= page_p->bytes[offset - 1] & CBC_LOWER_SEVEN_BIT_MASK; + } + + return new_distance; +} /* parser_update_backward_branch */ + +/** + * Update targets of all branches in one step. + */ +static void +parse_update_branches (parser_context_t *context_p, /**< context */ + uint8_t *byte_code_p) /**< byte code */ +{ + parser_mem_page_t *page_p = context_p->byte_code.first_p; + parser_mem_page_t *prev_page_p = NULL; + parser_mem_page_t *last_page_p = context_p->byte_code.last_p; + size_t last_position = context_p->byte_code.last_position; + size_t offset = 0; + size_t bytes_copied = 0; + + if (last_position >= PARSER_CBC_STREAM_PAGE_SIZE) + { + last_page_p = NULL; + last_position = 0; + } + + while (page_p != last_page_p || offset < last_position) + { + /* Branch instructions are marked to improve search speed. */ + if (page_p->bytes[offset] & CBC_HIGHEST_BIT_MASK) + { + uint8_t *bytes_p = byte_code_p + bytes_copied; + uint8_t flags; + uint8_t bytes_copied_before_jump = 0; + size_t branch_argument_length; + size_t target_distance; + size_t length; + + if (offset > 0) + { + bytes_copied_before_jump = page_p->bytes[offset - 1] & CBC_LOWER_SEVEN_BIT_MASK; + } + bytes_p += bytes_copied_before_jump; + + if (*bytes_p == CBC_EXT_OPCODE) + { + bytes_p++; + flags = cbc_ext_flags[*bytes_p]; + } + else + { + flags = cbc_flags[*bytes_p]; + } + + JERRY_ASSERT (flags & CBC_HAS_BRANCH_ARG); + branch_argument_length = CBC_BRANCH_OFFSET_LENGTH (*bytes_p); + bytes_p++; + + /* Decoding target. */ + length = branch_argument_length; + target_distance = 0; + do + { + target_distance = (target_distance << 8) | *bytes_p; + bytes_p++; + } while (--length > 0); + + if (CBC_BRANCH_IS_FORWARD (flags)) + { + /* Branch target was not set. */ + JERRY_ASSERT (target_distance > 0); + + target_distance = parser_update_forward_branch (page_p, offset + target_distance, bytes_copied_before_jump); + } + else + { + if (target_distance < offset) + { + uint8_t bytes_copied_before_target = page_p->bytes[offset - target_distance - 1]; + bytes_copied_before_target = bytes_copied_before_target & CBC_LOWER_SEVEN_BIT_MASK; + + target_distance = (size_t) (bytes_copied_before_jump - bytes_copied_before_target); + } + else if (target_distance == offset) + { + target_distance = bytes_copied_before_jump; + } + else + { + target_distance = + parser_update_backward_branch (prev_page_p, target_distance - offset, bytes_copied_before_jump); + } + } + + /* Encoding target again. */ + do + { + bytes_p--; + *bytes_p = (uint8_t) (target_distance & 0xff); + target_distance >>= 8; + } while (--branch_argument_length > 0); + } + + offset++; + if (offset >= PARSER_CBC_STREAM_PAGE_SIZE) + { + parser_mem_page_t *next_p = page_p->next_p; + + /* We reverse the pages before the current page. */ + page_p->next_p = prev_page_p; + prev_page_p = page_p; + + bytes_copied += page_p->bytes[PARSER_CBC_STREAM_PAGE_SIZE - 1] & CBC_LOWER_SEVEN_BIT_MASK; + page_p = next_p; + offset = 0; + } + } + + /* After this point the pages of the byte code stream are + * not used anymore. However, they needs to be freed during + * cleanup, so the first and last pointers of the stream + * descriptor are reversed as well. */ + if (last_page_p != NULL) + { + JERRY_ASSERT (last_page_p == context_p->byte_code.last_p); + last_page_p->next_p = prev_page_p; + } + else + { + last_page_p = context_p->byte_code.last_p; + } + + context_p->byte_code.last_p = context_p->byte_code.first_p; + context_p->byte_code.first_p = last_page_p; +} /* parse_update_branches */ + +/** + * Forward iterator: move to the next byte code + * + * @param page_p page + * @param offset offset + */ +#define PARSER_NEXT_BYTE(page_p, offset) \ + do \ + { \ + if (++(offset) >= PARSER_CBC_STREAM_PAGE_SIZE) \ + { \ + offset = 0; \ + page_p = page_p->next_p; \ + } \ + } while (0) + +/** + * Forward iterator: move to the next byte code. Also updates the offset of the previous byte code. + * + * @param page_p page + * @param offset offset + * @param real_offset real offset + */ +#define PARSER_NEXT_BYTE_UPDATE(page_p, offset, real_offset) \ + do \ + { \ + page_p->bytes[offset] = real_offset; \ + if (++(offset) >= PARSER_CBC_STREAM_PAGE_SIZE) \ + { \ + offset = 0; \ + real_offset = 0; \ + page_p = page_p->next_p; \ + } \ + } while (0) + +/** + * Post processing main function. + * + * @return compiled code + */ +static ecma_compiled_code_t * +parser_post_processing (parser_context_t *context_p) /**< context */ +{ + uint16_t literal_one_byte_limit; + uint16_t ident_end; + uint16_t const_literal_end; + parser_mem_page_t *page_p; + parser_mem_page_t *last_page_p; + size_t last_position; + size_t offset; + size_t length; + size_t literal_length; + size_t total_size; + uint8_t real_offset; + uint8_t *byte_code_p; + bool needs_uint16_arguments; + cbc_opcode_t last_opcode = CBC_EXT_OPCODE; + ecma_compiled_code_t *compiled_code_p; + ecma_value_t *literal_pool_p; + uint8_t *dst_p; + + if ((context_p->status_flags & (PARSER_IS_FUNCTION | PARSER_LEXICAL_BLOCK_NEEDED)) + == (PARSER_IS_FUNCTION | PARSER_LEXICAL_BLOCK_NEEDED)) + { + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + context_p->status_flags &= (uint32_t) ~PARSER_LEXICAL_BLOCK_NEEDED; + + parser_emit_cbc (context_p, CBC_CONTEXT_END); + + parser_branch_t branch; + parser_stack_pop (context_p, &branch, sizeof (parser_branch_t)); + parser_set_branch_to_current_position (context_p, &branch); + + JERRY_ASSERT (!(context_p->status_flags & PARSER_NO_END_LABEL)); + } + + if (PARSER_IS_NORMAL_ASYNC_FUNCTION (context_p->status_flags)) + { + PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); +#ifndef JERRY_NDEBUG + PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + + if (context_p->stack_limit < PARSER_FINALLY_CONTEXT_STACK_ALLOCATION) + { + context_p->stack_limit = PARSER_FINALLY_CONTEXT_STACK_ALLOCATION; + } + + parser_branch_t branch; + + parser_stack_pop (context_p, &branch, sizeof (parser_branch_t)); + parser_set_branch_to_current_position (context_p, &branch); + + JERRY_ASSERT (!(context_p->status_flags & PARSER_NO_END_LABEL)); + } + + JERRY_ASSERT (context_p->stack_depth == 0); +#ifndef JERRY_NDEBUG + JERRY_ASSERT (context_p->context_stack_depth == 0); +#endif /* !JERRY_NDEBUG */ + + if ((size_t) context_p->stack_limit + (size_t) context_p->register_count > PARSER_MAXIMUM_STACK_LIMIT) + { + parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED); + } + + if (JERRY_UNLIKELY (context_p->script_p->refs_and_type >= CBC_SCRIPT_REF_MAX)) + { + /* This is probably never happens in practice. */ + jerry_fatal (JERRY_FATAL_REF_COUNT_LIMIT); + } + + context_p->script_p->refs_and_type += CBC_SCRIPT_REF_ONE; + + JERRY_ASSERT (context_p->literal_count <= PARSER_MAXIMUM_NUMBER_OF_LITERALS); + + parser_compute_indices (context_p, &ident_end, &const_literal_end); + + if (context_p->literal_count <= CBC_MAXIMUM_SMALL_VALUE) + { + literal_one_byte_limit = CBC_MAXIMUM_BYTE_VALUE - 1; + } + else + { + literal_one_byte_limit = CBC_LOWER_SEVEN_BIT_MASK; + } + + last_page_p = context_p->byte_code.last_p; + last_position = context_p->byte_code.last_position; + + if (last_position >= PARSER_CBC_STREAM_PAGE_SIZE) + { + last_page_p = NULL; + last_position = 0; + } + + page_p = context_p->byte_code.first_p; + offset = 0; + length = 0; + + while (page_p != last_page_p || offset < last_position) + { + uint8_t *opcode_p; + uint8_t flags; + size_t branch_offset_length; + + opcode_p = page_p->bytes + offset; + last_opcode = (cbc_opcode_t) (*opcode_p); + PARSER_NEXT_BYTE (page_p, offset); + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (last_opcode); + flags = cbc_flags[last_opcode]; + length++; + + switch (last_opcode) + { + case CBC_EXT_OPCODE: + { + cbc_ext_opcode_t ext_opcode; + + ext_opcode = (cbc_ext_opcode_t) page_p->bytes[offset]; + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (ext_opcode); + flags = cbc_ext_flags[ext_opcode]; + PARSER_NEXT_BYTE (page_p, offset); + length++; + break; + } + case CBC_POST_DECR: + { + *opcode_p = CBC_PRE_DECR; + break; + } + case CBC_POST_INCR: + { + *opcode_p = CBC_PRE_INCR; + break; + } + case CBC_POST_DECR_IDENT: + { + *opcode_p = CBC_PRE_DECR_IDENT; + break; + } + case CBC_POST_INCR_IDENT: + { + *opcode_p = CBC_PRE_INCR_IDENT; + break; + } + default: + { + break; + } + } + + while (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) + { + uint8_t *first_byte = page_p->bytes + offset; + uint32_t literal_index = *first_byte; + + PARSER_NEXT_BYTE (page_p, offset); + length++; + + literal_index |= ((uint32_t) page_p->bytes[offset]) << 8; + + if (literal_index >= PARSER_REGISTER_START) + { + literal_index -= PARSER_REGISTER_START; + } + else + { + literal_index = (PARSER_GET_LITERAL (literal_index))->prop.index; + } + + if (literal_index <= literal_one_byte_limit) + { + *first_byte = (uint8_t) literal_index; + } + else + { + if (context_p->literal_count <= CBC_MAXIMUM_SMALL_VALUE) + { + JERRY_ASSERT (literal_index <= CBC_MAXIMUM_SMALL_VALUE); + *first_byte = CBC_MAXIMUM_BYTE_VALUE; + page_p->bytes[offset] = (uint8_t) (literal_index - CBC_MAXIMUM_BYTE_VALUE); + length++; + } + else + { + JERRY_ASSERT (literal_index <= CBC_MAXIMUM_FULL_VALUE); + *first_byte = (uint8_t) ((literal_index >> 8) | CBC_HIGHEST_BIT_MASK); + page_p->bytes[offset] = (uint8_t) (literal_index & 0xff); + length++; + } + } + PARSER_NEXT_BYTE (page_p, offset); + + if (flags & CBC_HAS_LITERAL_ARG2) + { + if (flags & CBC_HAS_LITERAL_ARG) + { + flags = CBC_HAS_LITERAL_ARG; + } + else + { + flags = CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2; + } + } + else + { + break; + } + } + + if (flags & CBC_HAS_BYTE_ARG) + { + /* This argument will be copied without modification. */ + PARSER_NEXT_BYTE (page_p, offset); + length++; + } + + if (flags & CBC_HAS_BRANCH_ARG) + { + bool prefix_zero = true; + + /* The leading zeroes are dropped from the stream. + * Although dropping these zeroes for backward + * branches are unnecessary, we use the same + * code path for simplicity. */ + JERRY_ASSERT (branch_offset_length > 0 && branch_offset_length <= 3); + + while (--branch_offset_length > 0) + { + uint8_t byte = page_p->bytes[offset]; + if (byte > 0 || !prefix_zero) + { + prefix_zero = false; + length++; + } + else + { + JERRY_ASSERT (CBC_BRANCH_IS_FORWARD (flags)); + } + PARSER_NEXT_BYTE (page_p, offset); + } + + if (last_opcode == (cbc_opcode_t) (CBC_JUMP_FORWARD + PARSER_MAX_BRANCH_LENGTH - 1) && prefix_zero + && page_p->bytes[offset] == PARSER_MAX_BRANCH_LENGTH + 1) + { + /* Unconditional jumps which jump right after the instruction + * are effectively NOPs. These jumps are removed from the + * stream. The 1 byte long CBC_JUMP_FORWARD form marks these + * instructions, since this form is constructed during post + * processing and cannot be emitted directly. */ + *opcode_p = CBC_JUMP_FORWARD; + length--; + } + else + { + /* Other last bytes are always copied. */ + length++; + } + + PARSER_NEXT_BYTE (page_p, offset); + } + } + + if (!(context_p->status_flags & PARSER_NO_END_LABEL) || !(PARSER_OPCODE_IS_RETURN (last_opcode))) + { + context_p->status_flags &= (uint32_t) ~PARSER_NO_END_LABEL; + + if (PARSER_IS_NORMAL_ASYNC_FUNCTION (context_p->status_flags)) + { + length++; + } + + length++; + } + + needs_uint16_arguments = false; + total_size = sizeof (cbc_uint8_arguments_t); + + if (context_p->stack_limit > CBC_MAXIMUM_BYTE_VALUE || context_p->register_count > CBC_MAXIMUM_BYTE_VALUE + || context_p->literal_count > CBC_MAXIMUM_BYTE_VALUE) + { + needs_uint16_arguments = true; + total_size = sizeof (cbc_uint16_arguments_t); + } + + literal_length = (size_t) (context_p->literal_count - context_p->register_count) * sizeof (ecma_value_t); + + total_size += literal_length + length; + + if (PARSER_NEEDS_MAPPED_ARGUMENTS (context_p->status_flags)) + { + total_size += context_p->argument_count * sizeof (ecma_value_t); + } + + /* function.name */ + if (!(context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)) + { + total_size += sizeof (ecma_value_t); + } + + if (context_p->tagged_template_literal_cp != JMEM_CP_NULL) + { + total_size += sizeof (ecma_value_t); + } + + uint8_t extended_info = 0; + + if (context_p->argument_length != UINT16_MAX) + { + extended_info |= CBC_EXTENDED_CODE_FLAGS_HAS_ARGUMENT_LENGTH; + total_size += ecma_extended_info_get_encoded_length (context_p->argument_length); + } + if (extended_info != 0) + { + total_size += sizeof (uint8_t); + } + + total_size = JERRY_ALIGNUP (total_size, JMEM_ALIGNMENT); + compiled_code_p = (ecma_compiled_code_t *) parser_malloc (context_p, total_size); + +#if JERRY_SNAPSHOT_SAVE || JERRY_PARSER_DUMP_BYTE_CODE + // Avoid getting junk bytes + memset (compiled_code_p, 0, total_size); +#endif /* JERRY_SNAPSHOT_SAVE || JERRY_PARSER_DUMP_BYTE_CODE */ + + byte_code_p = (uint8_t *) compiled_code_p; + compiled_code_p->size = (uint16_t) (total_size >> JMEM_ALIGNMENT_LOG); + compiled_code_p->refs = 1; + compiled_code_p->status_flags = 0; + + if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM) + { + JERRY_ASSERT (context_p->argument_count > 0); + context_p->argument_count--; + } + + if (needs_uint16_arguments) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p; + + args_p->stack_limit = context_p->stack_limit; + args_p->script_value = context_p->script_value; + args_p->argument_end = context_p->argument_count; + args_p->register_end = context_p->register_count; + args_p->ident_end = ident_end; + args_p->const_literal_end = const_literal_end; + args_p->literal_end = context_p->literal_count; + + compiled_code_p->status_flags |= CBC_CODE_FLAGS_UINT16_ARGUMENTS; + byte_code_p += sizeof (cbc_uint16_arguments_t); + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p; + + args_p->stack_limit = (uint8_t) context_p->stack_limit; + args_p->argument_end = (uint8_t) context_p->argument_count; + args_p->script_value = context_p->script_value; + args_p->register_end = (uint8_t) context_p->register_count; + args_p->ident_end = (uint8_t) ident_end; + args_p->const_literal_end = (uint8_t) const_literal_end; + args_p->literal_end = (uint8_t) context_p->literal_count; + + byte_code_p += sizeof (cbc_uint8_arguments_t); + } + + uint16_t encoding_limit; + uint16_t encoding_delta; + + if (context_p->literal_count > CBC_MAXIMUM_SMALL_VALUE) + { + compiled_code_p->status_flags |= CBC_CODE_FLAGS_FULL_LITERAL_ENCODING; + encoding_limit = CBC_FULL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_FULL_LITERAL_ENCODING_DELTA; + } + else + { + encoding_limit = CBC_SMALL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_SMALL_LITERAL_ENCODING_DELTA; + } + + if (context_p->status_flags & PARSER_IS_STRICT) + { + compiled_code_p->status_flags |= CBC_CODE_FLAGS_STRICT_MODE; + } + + if ((context_p->status_flags & PARSER_ARGUMENTS_NEEDED) && PARSER_NEEDS_MAPPED_ARGUMENTS (context_p->status_flags)) + { + compiled_code_p->status_flags |= CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED; + } + + if (!(context_p->status_flags & PARSER_LEXICAL_ENV_NEEDED)) + { + compiled_code_p->status_flags |= CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED; + } + + uint16_t function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL); + + if (context_p->status_flags & (PARSER_IS_PROPERTY_GETTER | PARSER_IS_PROPERTY_SETTER)) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ACCESSOR); + } + else if (!(context_p->status_flags & PARSER_IS_FUNCTION)) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_SCRIPT); + } + else if (context_p->status_flags & PARSER_IS_ARROW_FUNCTION) + { + if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ASYNC_ARROW); + } + else + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ARROW); + } + } + else if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) + { + if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ASYNC_GENERATOR); + } + else + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_GENERATOR); + } + } + else if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_ASYNC); + } + else if (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_CONSTRUCTOR); + } + else if (context_p->status_flags & PARSER_IS_METHOD) + { + function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_METHOD); + } + + if (context_p->status_flags & PARSER_LEXICAL_BLOCK_NEEDED) + { + JERRY_ASSERT (!(context_p->status_flags & PARSER_IS_FUNCTION)); + compiled_code_p->status_flags |= CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED; + } + + compiled_code_p->status_flags |= function_type; + literal_pool_p = ((ecma_value_t *) byte_code_p) - context_p->register_count; + byte_code_p += literal_length; + dst_p = byte_code_p; + + parser_init_literal_pool (context_p, literal_pool_p); + + page_p = context_p->byte_code.first_p; + offset = 0; + real_offset = 0; + uint8_t last_register_index = + (uint8_t) JERRY_MIN (context_p->register_count, (PARSER_MAXIMUM_NUMBER_OF_REGISTERS - 1)); + + while (page_p != last_page_p || offset < last_position) + { + uint8_t flags; + uint8_t *opcode_p; + uint8_t *branch_mark_p; + cbc_opcode_t opcode; + size_t branch_offset_length; + + opcode_p = dst_p; + branch_mark_p = page_p->bytes + offset; + opcode = (cbc_opcode_t) (*branch_mark_p); + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (opcode); + + if (opcode == CBC_JUMP_FORWARD) + { + /* These opcodes are deleted from the stream. */ + size_t counter = PARSER_MAX_BRANCH_LENGTH + 1; + + do + { + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + } while (--counter > 0); + + continue; + } + + /* Storing the opcode */ + *dst_p++ = (uint8_t) opcode; + real_offset++; + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + flags = cbc_flags[opcode]; + + if (opcode == CBC_EXT_OPCODE) + { + cbc_ext_opcode_t ext_opcode; + + ext_opcode = (cbc_ext_opcode_t) page_p->bytes[offset]; + flags = cbc_ext_flags[ext_opcode]; + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (ext_opcode); + + /* Storing the extended opcode */ + *dst_p++ = (uint8_t) ext_opcode; + opcode_p++; + real_offset++; + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + } + + /* Only literal and call arguments can be combined. */ + JERRY_ASSERT (!(flags & CBC_HAS_BRANCH_ARG) || !(flags & (CBC_HAS_BYTE_ARG | CBC_HAS_LITERAL_ARG))); + + while (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) + { + uint16_t first_byte = page_p->bytes[offset]; + + uint8_t *opcode_pos_p = dst_p - 1; + *dst_p++ = (uint8_t) first_byte; + real_offset++; + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + + if (first_byte > literal_one_byte_limit) + { + *dst_p++ = page_p->bytes[offset]; + + if (first_byte >= encoding_limit) + { + first_byte = (uint16_t) (((first_byte << 8) | dst_p[-1]) - encoding_delta); + } + real_offset++; + } + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + + if (flags & CBC_HAS_LITERAL_ARG2) + { + if (flags & CBC_HAS_LITERAL_ARG) + { + flags = CBC_HAS_LITERAL_ARG; + } + else + { + flags = CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2; + } + } + else + { + if (opcode == CBC_ASSIGN_SET_IDENT && JERRY_LIKELY (first_byte < last_register_index)) + { + *opcode_pos_p = CBC_MOV_IDENT; + } + + break; + } + } + + if (flags & CBC_HAS_BYTE_ARG) + { + /* This argument will be copied without modification. */ + *dst_p++ = page_p->bytes[offset]; + real_offset++; + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + continue; + } + + if (flags & CBC_HAS_BRANCH_ARG) + { + *branch_mark_p |= CBC_HIGHEST_BIT_MASK; + bool prefix_zero = true; + + /* The leading zeroes are dropped from the stream. */ + JERRY_ASSERT (branch_offset_length > 0 && branch_offset_length <= 3); + + while (--branch_offset_length > 0) + { + uint8_t byte = page_p->bytes[offset]; + if (byte > 0 || !prefix_zero) + { + prefix_zero = false; + *dst_p++ = page_p->bytes[offset]; + real_offset++; + } + else + { + /* When a leading zero is dropped, the branch + * offset length must be decreased as well. */ + (*opcode_p)--; + } + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + } + + *dst_p++ = page_p->bytes[offset]; + real_offset++; + PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset); + continue; + } + } + + if (!(context_p->status_flags & PARSER_NO_END_LABEL)) + { + *dst_p++ = CBC_RETURN_FUNCTION_END; + + if (PARSER_IS_NORMAL_ASYNC_FUNCTION (context_p->status_flags)) + { + dst_p[-1] = CBC_EXT_OPCODE; + dst_p[0] = CBC_EXT_ASYNC_EXIT; + dst_p++; + } + } + JERRY_ASSERT (dst_p == byte_code_p + length); + + parse_update_branches (context_p, byte_code_p); + + parser_cbc_stream_free (&context_p->byte_code); + + if (context_p->status_flags & PARSER_HAS_LATE_LIT_INIT) + { + parser_list_iterator_t literal_iterator; + lexer_literal_t *literal_p; + uint16_t register_count = context_p->register_count; + + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator))) + { + if ((literal_p->status_flags & LEXER_FLAG_LATE_INIT) && literal_p->prop.index >= register_count) + { + uint32_t source_data = literal_p->u.source_data; + const uint8_t *char_p = context_p->source_end_p - (source_data & 0xfffff); + ecma_value_t lit_value = ecma_find_or_create_literal_string (char_p, + source_data >> 20, + (literal_p->status_flags & LEXER_FLAG_ASCII) != 0); + literal_pool_p[literal_p->prop.index] = lit_value; + } + } + } + + ecma_value_t *base_p = (ecma_value_t *) (((uint8_t *) compiled_code_p) + total_size); + + if (PARSER_NEEDS_MAPPED_ARGUMENTS (context_p->status_flags)) + { + parser_list_iterator_t literal_iterator; + uint16_t argument_count = 0; + base_p -= context_p->argument_count; + + parser_list_iterator_init (&context_p->literal_pool, &literal_iterator); + while (argument_count < context_p->argument_count) + { + lexer_literal_t *literal_p; + literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator); + + if (!(literal_p->status_flags & LEXER_FLAG_FUNCTION_ARGUMENT)) + { + continue; + } + + /* All arguments must be moved to initialized registers. */ + if (literal_p->type == LEXER_UNUSED_LITERAL) + { + base_p[argument_count] = ECMA_VALUE_EMPTY; + argument_count++; + continue; + } + base_p[argument_count] = literal_pool_p[literal_p->prop.index]; + argument_count++; + } + } + + if (!(context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)) + { + *(--base_p) = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); + } + + if (context_p->tagged_template_literal_cp != JMEM_CP_NULL) + { + compiled_code_p->status_flags |= CBC_CODE_FLAGS_HAS_TAGGED_LITERALS; + *(--base_p) = (ecma_value_t) context_p->tagged_template_literal_cp; + } + + if (extended_info != 0) + { + uint8_t *extended_info_p = ((uint8_t *) base_p) - 1; + + compiled_code_p->status_flags |= CBC_CODE_FLAGS_HAS_EXTENDED_INFO; + *extended_info_p = extended_info; + + if (context_p->argument_length != UINT16_MAX) + { + ecma_extended_info_encode_vlq (&extended_info_p, context_p->argument_length); + } + } + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + util_print_cbc (compiled_code_p); + JERRY_DEBUG_MSG ("\nByte code size: %d bytes\n", (int) length); + context_p->total_byte_code_size += (uint32_t) length; + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + return compiled_code_p; +} /* parser_post_processing */ + +#undef PARSER_NEXT_BYTE +#undef PARSER_NEXT_BYTE_UPDATE + +/** + * Resolve private identifier in direct eval context + */ +static bool +parser_resolve_private_identifier_eval (parser_context_t *context_p) /**< context */ +{ + ecma_string_t *search_key_p; + uint8_t *destination_p = (uint8_t *) parser_malloc (context_p, context_p->token.lit_location.length); + + lexer_convert_ident_to_cesu8 (destination_p, + context_p->token.lit_location.char_p, + context_p->token.lit_location.length); + + search_key_p = ecma_new_ecma_string_from_utf8 (destination_p, context_p->token.lit_location.length); + + parser_free (destination_p, context_p->token.lit_location.length); + + ecma_object_t *lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p; + + while (true) + { + JERRY_ASSERT (lex_env_p != NULL); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA) != 0 + && !ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + ecma_object_t *class_object_p = ((ecma_lexical_environment_class_t *) lex_env_p)->object_p; + + ecma_string_t *internal_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS); + ecma_property_t *prop_p = ecma_find_named_property (class_object_p, internal_string_p); + + if (prop_p != NULL) + { + ecma_value_t *collection_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, ECMA_PROPERTY_VALUE_PTR (prop_p)->value); + ecma_value_t *current_p = collection_p + 1; + ecma_value_t *end_p = ecma_compact_collection_end (collection_p); + + while (current_p < end_p) + { + current_p++; /* skip kind */ + ecma_string_t *private_key_p = ecma_get_prop_name_from_value (*current_p++); + current_p++; /* skip value */ + + JERRY_ASSERT (ecma_prop_name_is_symbol (private_key_p)); + + ecma_string_t *private_key_desc_p = + ecma_get_string_from_value (((ecma_extended_string_t *) private_key_p)->u.symbol_descriptor); + + if (ecma_compare_ecma_strings (private_key_desc_p, search_key_p)) + { + ecma_deref_ecma_string (search_key_p); + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + return true; + } + } + } + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + ecma_deref_ecma_string (search_key_p); + return false; +} /* parser_resolve_private_identifier_eval */ + +/** + * Resolve private identifier + */ +void +parser_resolve_private_identifier (parser_context_t *context_p) /**< context */ +{ + if ((context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL) && parser_resolve_private_identifier_eval (context_p)) + { + return; + } + + parser_private_context_t *context_iter_p = context_p->private_context_p; + + while (context_iter_p) + { + if (context_iter_p == NULL || !(context_iter_p->opts & SCANNER_PRIVATE_FIELD_ACTIVE)) + { + parser_raise_error (context_p, PARSER_ERR_UNDECLARED_PRIVATE_FIELD); + } + + if (!(context_iter_p->opts & SCANNER_SUCCESSFUL_CLASS_SCAN)) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + return; + } + + parser_private_context_t *private_context_p = context_iter_p; + + if (private_context_p == NULL) + { + parser_raise_error (context_p, PARSER_ERR_UNDECLARED_PRIVATE_FIELD); + } + + scanner_class_private_member_t *ident_iter = private_context_p->members_p; + + while (ident_iter) + { + if (lexer_compare_identifiers (context_p, &context_p->token.lit_location, &ident_iter->loc)) + { + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL); + return; + } + + ident_iter = ident_iter->prev_p; + } + + context_iter_p = context_iter_p->prev_p; + } + + parser_raise_error (context_p, PARSER_ERR_UNDECLARED_PRIVATE_FIELD); +} /* parser_resolve_private_identifier */ + +/** + * Save private field context + */ +void +parser_save_private_context (parser_context_t *context_p, /**< context */ + parser_private_context_t *private_ctx_p, /**< private context */ + scanner_class_info_t *class_info_p) /**< class scanner info */ +{ + private_ctx_p->prev_p = context_p->private_context_p; + context_p->private_context_p = private_ctx_p; + + context_p->private_context_p->members_p = class_info_p->members; + context_p->private_context_p->opts = class_info_p->info.u8_arg; + class_info_p->members = NULL; +} /* parser_save_private_context */ + +/** + * Release contexts private fields + */ +static void +parser_free_private_fields (parser_context_t *context_p) /**< context */ +{ + parser_private_context_t *iter = context_p->private_context_p; + + while (iter != NULL) + { + parser_private_context_t *prev_p = iter->prev_p; + scanner_release_private_fields (iter->members_p); + iter = prev_p; + } +} /* parser_free_private_fields */ + +/** + * Restore contexts private fields + */ +void +parser_restore_private_context (parser_context_t *context_p, /**< context */ + parser_private_context_t *private_ctx_p) /**< private context */ +{ + scanner_release_private_fields (context_p->private_context_p->members_p); + context_p->private_context_p = private_ctx_p->prev_p; +} /* parser_restore_private_context */ + +/** + * Free identifiers and literals. + */ +static void +parser_free_literals (parser_list_t *literal_pool_p) /**< literals */ +{ + parser_list_iterator_t literal_iterator; + lexer_literal_t *literal_p; + + parser_list_iterator_init (literal_pool_p, &literal_iterator); + while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + util_free_literal (literal_p); + } + + parser_list_free (literal_pool_p); +} /* parser_free_literals */ + +/** + * Parse function arguments + */ +static void +parser_parse_function_arguments (parser_context_t *context_p, /**< context */ + lexer_token_type_t end_type) /**< expected end type */ +{ + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + + JERRY_ASSERT (context_p->status_flags & PARSER_IS_FUNCTION); + JERRY_ASSERT (!(context_p->status_flags & PARSER_LEXICAL_BLOCK_NEEDED)); + + bool has_duplicated_arg_names = false; + + if (PARSER_IS_NORMAL_ASYNC_FUNCTION (context_p->status_flags)) + { + parser_branch_t branch; + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_TRY_CREATE_CONTEXT, &branch); + parser_stack_push (context_p, &branch, sizeof (parser_branch_t)); + +#ifndef JERRY_NDEBUG + context_p->context_stack_depth = PARSER_TRY_CONTEXT_STACK_ALLOCATION; +#endif /* !JERRY_NDEBUG */ + } + + if (context_p->token.type == end_type) + { + context_p->status_flags &= (uint32_t) ~PARSER_DISALLOW_AWAIT_YIELD; + + if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) + { + scanner_create_variables (context_p, SCANNER_CREATE_VARS_IS_FUNCTION_ARGS); + parser_emit_cbc_ext (context_p, CBC_EXT_CREATE_GENERATOR); + parser_emit_cbc (context_p, CBC_POP); + scanner_create_variables (context_p, SCANNER_CREATE_VARS_IS_FUNCTION_BODY); + return; + } + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS); + return; + } + + bool has_complex_argument = (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_HAS_COMPLEX_ARGUMENT) != 0; + bool is_strict = (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_IS_STRICT) != 0; + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_IS_FUNCTION_ARGS); + scanner_set_active (context_p); + + context_p->status_flags |= PARSER_FUNCTION_IS_PARSING_ARGS; + + while (true) + { + if (context_p->token.type == LEXER_THREE_DOTS) + { + if (context_p->status_flags & PARSER_IS_PROPERTY_SETTER) + { + parser_raise_error (context_p, PARSER_ERR_SETTER_REST_PARAMETER); + } + lexer_next_token (context_p); + + if (has_duplicated_arg_names) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES); + } + + context_p->status_flags |= PARSER_FUNCTION_HAS_REST_PARAM | PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT; + } + + if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE) + { + if (has_duplicated_arg_names) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES); + } + + context_p->status_flags |= PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT; + + if (!(context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)) + { + parser_emit_cbc_literal (context_p, + CBC_PUSH_LITERAL, + (uint16_t) (PARSER_REGISTER_START + context_p->argument_count)); + } + else + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_REST_OBJECT); + } + + uint32_t flags = + (PARSER_PATTERN_BINDING | PARSER_PATTERN_TARGET_ON_STACK | PARSER_PATTERN_LOCAL | PARSER_PATTERN_ARGUMENTS); + + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER) + { + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags |= PARSER_PATTERN_HAS_REST_ELEMENT; + } + + if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM) + { + parser_raise_error (context_p, PARSER_ERR_REST_PARAMETER_DEFAULT_INITIALIZER); + } + + if (context_p->argument_length == UINT16_MAX) + { + context_p->argument_length = context_p->argument_count; + } + + flags |= PARSER_PATTERN_TARGET_DEFAULT; + } + else if (context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS) + { + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags |= PARSER_PATTERN_HAS_REST_ELEMENT; + } + scanner_release_next (context_p, sizeof (scanner_info_t)); + } + else + { + parser_raise_error (context_p, PARSER_ERR_INVALID_DESTRUCTURING_PATTERN); + } + } + + parser_parse_initializer (context_p, (parser_pattern_flags_t) flags); + + context_p->argument_count++; + if (context_p->argument_count >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIMIT_REACHED); + } + + if (context_p->token.type != LEXER_COMMA) + { + if (context_p->token.type != end_type) + { + parser_error_msg_t error = + ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED : PARSER_ERR_IDENTIFIER_EXPECTED); + + parser_raise_error (context_p, error); + } + break; + } + + lexer_next_token (context_p); + + if (context_p->token.type == end_type) + { + break; + } + continue; + } + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED); + } + + lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL); + + if (context_p->token.keyword_type >= LEXER_FIRST_NON_STRICT_ARGUMENTS) + { + context_p->status_flags |= PARSER_HAS_NON_STRICT_ARG; + } + + if (JERRY_UNLIKELY (context_p->lit_object.literal_p->status_flags & LEXER_FLAG_FUNCTION_ARGUMENT)) + { + if ((context_p->status_flags & PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT) + || (context_p->status_flags & PARSER_IS_ARROW_FUNCTION)) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES); + } + has_duplicated_arg_names = true; + + context_p->status_flags |= PARSER_HAS_NON_STRICT_ARG; + } + else + { + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_FUNCTION_ARGUMENT; + } + + lexer_next_token (context_p); + + uint16_t literal_index = context_p->lit_object.index; + + if (context_p->token.type == LEXER_ASSIGN) + { + JERRY_ASSERT (has_complex_argument); + + if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM) + { + parser_raise_error (context_p, PARSER_ERR_REST_PARAMETER_DEFAULT_INITIALIZER); + } + + if (context_p->argument_length == UINT16_MAX) + { + context_p->argument_length = context_p->argument_count; + } + + parser_branch_t skip_init; + + if (has_duplicated_arg_names) + { + parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES); + } + + context_p->status_flags |= PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT; + + /* LEXER_ASSIGN does not overwrite lit_object. */ + parser_emit_cbc_literal (context_p, + CBC_PUSH_LITERAL, + (uint16_t) (PARSER_REGISTER_START + context_p->argument_count)); + parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_DEFAULT_INITIALIZER, &skip_init); + + lexer_next_token (context_p); + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + parser_set_branch_to_current_position (context_p, &skip_init); + + uint16_t opcode = CBC_ASSIGN_LET_CONST; + + if (literal_index >= PARSER_REGISTER_START) + { + opcode = CBC_MOV_IDENT; + } + else if (!scanner_literal_is_created (context_p, literal_index)) + { + opcode = CBC_INIT_ARG_OR_CATCH; + } + + parser_emit_cbc_literal (context_p, opcode, literal_index); + } + else if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM) + { + parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_REST_OBJECT); + + uint16_t opcode = CBC_MOV_IDENT; + + if (literal_index < PARSER_REGISTER_START) + { + opcode = CBC_INIT_ARG_OR_CATCH; + + if (scanner_literal_is_created (context_p, literal_index)) + { + opcode = CBC_ASSIGN_LET_CONST; + } + } + + parser_emit_cbc_literal (context_p, opcode, literal_index); + } + else if (has_complex_argument && literal_index < PARSER_REGISTER_START) + { + uint16_t opcode = CBC_INIT_ARG_OR_FUNC; + + if (scanner_literal_is_created (context_p, literal_index)) + { + opcode = CBC_ASSIGN_LET_CONST_LITERAL; + } + + parser_emit_cbc_literal_value (context_p, + opcode, + (uint16_t) (PARSER_REGISTER_START + context_p->argument_count), + literal_index); + } + + context_p->argument_count++; + if (context_p->argument_count >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIMIT_REACHED); + } + + if (context_p->token.type != LEXER_COMMA) + { + if (context_p->token.type != end_type) + { + parser_error_msg_t error = + ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED : PARSER_ERR_IDENTIFIER_EXPECTED); + + parser_raise_error (context_p, error); + } + break; + } + + if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM) + { + parser_raise_error (context_p, PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER); + } + + lexer_next_token (context_p); + + if (context_p->token.type == end_type) + { + break; + } + } + + scanner_revert_active (context_p); + + JERRY_ASSERT (has_complex_argument || !(context_p->status_flags & PARSER_FUNCTION_HAS_COMPLEX_ARGUMENT)); + + if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) + { + parser_emit_cbc_ext (context_p, CBC_EXT_CREATE_GENERATOR); + parser_emit_cbc (context_p, CBC_POP); + } + + if (context_p->status_flags & PARSER_LEXICAL_BLOCK_NEEDED) + { + if ((context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_LEXICAL_ENV_NEEDED) + || scanner_is_context_needed (context_p, PARSER_CHECK_FUNCTION_CONTEXT)) + { + context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED; + + parser_branch_t branch; + parser_emit_cbc_forward_branch (context_p, CBC_BLOCK_CREATE_CONTEXT, &branch); + parser_stack_push (context_p, &branch, sizeof (parser_branch_t)); + +#ifndef JERRY_NDEBUG + PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); +#endif /* !JERRY_NDEBUG */ + } + else + { + context_p->status_flags &= (uint32_t) ~PARSER_LEXICAL_BLOCK_NEEDED; + } + } + + context_p->status_flags &= (uint32_t) ~(PARSER_DISALLOW_AWAIT_YIELD | PARSER_FUNCTION_IS_PARSING_ARGS); + scanner_create_variables (context_p, SCANNER_CREATE_VARS_IS_FUNCTION_BODY); + + if (is_strict) + { + context_p->status_flags |= PARSER_IS_STRICT; + } +} /* parser_parse_function_arguments */ + +#ifndef JERRY_NDEBUG +JERRY_STATIC_ASSERT ((PARSER_SCANNING_SUCCESSFUL == PARSER_HAS_LATE_LIT_INIT), + parser_scanning_successful_should_share_the_bit_position_with_parser_has_late_lit_init); +#endif /* !JERRY_NDEBUG */ + +/** + * Parser script size + */ +static size_t +parser_script_size (parser_context_t *context_p) /**< context */ +{ + size_t script_size = sizeof (cbc_script_t); + + if (context_p->user_value != ECMA_VALUE_EMPTY) + { + script_size += sizeof (ecma_value_t); + } + +#if JERRY_MODULE_SYSTEM + if (context_p->global_status_flags & ECMA_PARSE_INTERNAL_HAS_IMPORT_META) + { + script_size += sizeof (ecma_value_t); + } +#endif /* JERRY_MODULE_SYSTEM */ + return script_size; +} /* parser_script_size */ + +#if JERRY_SOURCE_NAME +/** + * Parser resource name + */ +static ecma_value_t +parser_source_name (parser_context_t *context_p) /**< context */ +{ + if (context_p->options_p != NULL && (context_p->options_p->options & JERRY_PARSE_HAS_SOURCE_NAME)) + { + JERRY_ASSERT (ecma_is_value_string (context_p->options_p->source_name)); + + ecma_ref_ecma_string (ecma_get_string_from_value (context_p->options_p->source_name)); + return context_p->options_p->source_name; + } + + if (context_p->global_status_flags & ECMA_PARSE_EVAL) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_EVAL); + } + + return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON); +} /* parser_source_name */ +#endif /* JERRY_SOURCE_NAME */ + +/** + * Parse and compile EcmaScript source code + * + * Note: source must be a valid UTF-8 string + * + * @return compiled code + */ +static ecma_compiled_code_t * +parser_parse_source (void *source_p, /**< source code */ + uint32_t parse_opts, /**< ecma_parse_opts_t option bits */ + const jerry_parse_options_t *options_p) /**< additional configuration options */ +{ + parser_context_t context; + ecma_compiled_code_t *compiled_code_p; + + context.error = PARSER_ERR_NO_ERROR; + context.status_flags = parse_opts & PARSER_STRICT_MODE_MASK; + context.global_status_flags = parse_opts; + + context.status_flags |= PARSER_RESTORE_STATUS_FLAGS (parse_opts); + context.tagged_template_literal_cp = JMEM_CP_NULL; + + context.stack_depth = 0; + context.stack_limit = 0; + context.options_p = options_p; + context.script_p = NULL; + context.arguments_start_p = NULL; + context.arguments_size = 0; +#if JERRY_MODULE_SYSTEM + if (context.global_status_flags & ECMA_PARSE_MODULE) + { + context.status_flags |= PARSER_IS_STRICT; + } + + context.module_names_p = NULL; +#endif /* JERRY_MODULE_SYSTEM */ + + context.argument_list = ECMA_VALUE_EMPTY; + + if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_ARGUMENT_LIST)) + { + context.argument_list = context.options_p->argument_list; + } + else if (context.global_status_flags & ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE) + { + JERRY_ASSERT (context.global_status_flags & ECMA_PARSE_HAS_SOURCE_VALUE); + context.argument_list = ((ecma_value_t *) source_p)[1]; + } + + if (context.argument_list != ECMA_VALUE_EMPTY) + { + JERRY_ASSERT (ecma_is_value_string (context.argument_list)); + + context.status_flags |= PARSER_IS_FUNCTION; + + if (parse_opts & ECMA_PARSE_GENERATOR_FUNCTION) + { + context.status_flags |= PARSER_IS_GENERATOR_FUNCTION; + } + if (parse_opts & ECMA_PARSE_ASYNC_FUNCTION) + { + context.status_flags |= PARSER_IS_ASYNC_FUNCTION; + } + + ecma_string_t *string_p = ecma_get_string_from_value (context.argument_list); + uint8_t flags = ECMA_STRING_FLAG_EMPTY; + + context.arguments_start_p = ecma_string_get_chars (string_p, &context.arguments_size, NULL, NULL, &flags); + + if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + context.global_status_flags |= ECMA_PARSE_INTERNAL_FREE_ARG_LIST; + } + } + + if (!(context.global_status_flags & ECMA_PARSE_HAS_SOURCE_VALUE)) + { + context.source_start_p = ((parser_source_char_t *) source_p)->source_p; + context.source_size = (lit_utf8_size_t) ((parser_source_char_t *) source_p)->source_size; + } + else + { + ecma_value_t source = ((ecma_value_t *) source_p)[0]; + + JERRY_ASSERT (ecma_is_value_string (source)); + + ecma_string_t *string_p = ecma_get_string_from_value (source); + uint8_t flags = ECMA_STRING_FLAG_EMPTY; + + context.source_start_p = ecma_string_get_chars (string_p, &context.source_size, NULL, NULL, &flags); + + if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) + { + context.global_status_flags |= ECMA_PARSE_INTERNAL_FREE_SOURCE; + } + } + + context.user_value = ECMA_VALUE_EMPTY; + + if ((context.global_status_flags & ECMA_PARSE_EVAL) && JERRY_CONTEXT (vm_top_context_p) != NULL) + { + const ecma_compiled_code_t *bytecode_header_p = JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p; + +#if JERRY_SNAPSHOT_EXEC + if (JERRY_LIKELY (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))) + { +#endif /* JERRY_SNAPSHOT_EXEC */ + ecma_value_t parent_script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value; + ; + cbc_script_t *parent_script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, parent_script_value); + + if (parent_script_p->refs_and_type & CBC_SCRIPT_HAS_USER_VALUE) + { + context.user_value = CBC_SCRIPT_GET_USER_VALUE (parent_script_p); + } +#if JERRY_SNAPSHOT_EXEC + } +#endif /* JERRY_SNAPSHOT_EXEC */ + } + else if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_USER_VALUE)) + { + context.user_value = context.options_p->user_value; + } + + context.last_context_p = NULL; + context.last_statement.current_p = NULL; + context.token.flags = 0; + lexer_init_line_info (&context); + + scanner_info_t scanner_info_end; + scanner_info_end.next_p = NULL; + scanner_info_end.source_p = NULL; + scanner_info_end.type = SCANNER_TYPE_END; + context.next_scanner_info_p = &scanner_info_end; + context.active_scanner_info_p = NULL; + context.skipped_scanner_info_p = NULL; + context.skipped_scanner_info_end_p = NULL; + + context.last_cbc_opcode = PARSER_CBC_UNAVAILABLE; + + context.argument_count = 0; + context.argument_length = UINT16_MAX; + context.register_count = 0; + context.literal_count = 0; + + parser_cbc_stream_init (&context.byte_code); + context.byte_code_size = 0; + parser_list_init (&context.literal_pool, + sizeof (lexer_literal_t), + (uint32_t) ((128 - sizeof (void *)) / sizeof (lexer_literal_t))); + context.scope_stack_p = NULL; + context.scope_stack_size = 0; + context.scope_stack_top = 0; + context.scope_stack_reg_top = 0; + context.scope_stack_global_end = 0; + context.tagged_template_literal_cp = JMEM_CP_NULL; + context.private_context_p = NULL; + +#ifndef JERRY_NDEBUG + context.context_stack_depth = 0; +#endif /* !JERRY_NDEBUG */ + +#if JERRY_PARSER_DUMP_BYTE_CODE + context.is_show_opcodes = (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_SHOW_OPCODES); + context.total_byte_code_size = 0; + + if (context.is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", (context.arguments_start_p == NULL) ? "Script" : "Function"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + scanner_scan_all (&context); + + if (JERRY_UNLIKELY (context.error != PARSER_ERR_NO_ERROR)) + { + JERRY_ASSERT (context.error == PARSER_ERR_OUT_OF_MEMORY); + + /* It is unlikely that memory can be allocated in an out-of-memory + * situation. However, a simple value can still be thrown. */ + jcontext_raise_exception (ECMA_VALUE_NULL); + return NULL; + } + + if (context.arguments_start_p == NULL) + { + context.source_p = context.source_start_p; + context.source_end_p = context.source_start_p + context.source_size; + } + else + { + context.source_p = context.arguments_start_p; + context.source_end_p = context.arguments_start_p + context.arguments_size; + } + + context.u.allocated_buffer_p = NULL; + context.token.flags = 0; + lexer_init_line_info (&context); + + parser_stack_init (&context); + + JERRY_ASSERT (context.next_scanner_info_p->source_p == context.source_p); + JERRY_ASSERT (context.next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + + if (context.next_scanner_info_p->u8_arg & SCANNER_FUNCTION_IS_STRICT) + { + context.status_flags |= PARSER_IS_STRICT; + } + + PARSER_TRY (context.try_buffer) + { + context.script_p = (cbc_script_t *) parser_malloc (&context, parser_script_size (&context)); + + CBC_SCRIPT_SET_TYPE (context.script_p, context.user_value, CBC_SCRIPT_REF_ONE); + + if (context.global_status_flags & (ECMA_PARSE_EVAL | ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE)) + { + context.script_p->refs_and_type |= CBC_SCRIPT_IS_EVAL_CODE; + } + +#if JERRY_BUILTIN_REALMS + context.script_p->realm_p = (ecma_object_t *) JERRY_CONTEXT (global_object_p); +#endif /* JERRY_BUILTIN_REALMS */ + +#if JERRY_SOURCE_NAME + context.script_p->source_name = parser_source_name (&context); +#endif /* JERRY_SOURCE_NAME */ + + ECMA_SET_INTERNAL_VALUE_POINTER (context.script_value, context.script_p); + + /* Pushing a dummy value ensures the stack is never empty. + * This simplifies the stack management routines. */ + parser_stack_push_uint8 (&context, CBC_MAXIMUM_BYTE_VALUE); + /* The next token must always be present to make decisions + * in the parser. Therefore when a token is consumed, the + * lexer_next_token() must be immediately called. */ + lexer_next_token (&context); + + if (context.arguments_start_p != NULL) + { + parser_parse_function_arguments (&context, LEXER_EOS); + + JERRY_ASSERT (context.next_scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS); + scanner_release_next (&context, sizeof (scanner_info_t)); + + context.source_p = context.source_start_p; + context.source_end_p = context.source_start_p + context.source_size; + lexer_init_line_info (&context); + + lexer_next_token (&context); + } +#if JERRY_MODULE_SYSTEM + else if (parse_opts & ECMA_PARSE_MODULE) + { + parser_branch_t branch; + parser_emit_cbc_forward_branch (&context, CBC_JUMP_FORWARD, &branch); + + scanner_create_variables (&context, SCANNER_CREATE_VARS_IS_MODULE); + parser_emit_cbc (&context, CBC_RETURN_FUNCTION_END); + + parser_set_branch_to_current_position (&context, &branch); + } +#endif /* JERRY_MODULE_SYSTEM */ + else + { + JERRY_ASSERT (context.next_scanner_info_p->source_p == context.source_start_p + && context.next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); + + if (scanner_is_context_needed (&context, PARSER_CHECK_GLOBAL_CONTEXT)) + { + context.status_flags |= PARSER_LEXICAL_BLOCK_NEEDED; + } + + if (!(parse_opts & ECMA_PARSE_EVAL)) + { + scanner_check_variables (&context); + } + + scanner_create_variables (&context, SCANNER_CREATE_VARS_IS_SCRIPT); + } + + parser_parse_statements (&context); + + JERRY_ASSERT (context.last_statement.current_p == NULL); + + JERRY_ASSERT (context.last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + JERRY_ASSERT (context.u.allocated_buffer_p == NULL); + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (context.status_flags & PARSER_SCANNING_SUCCESSFUL); + JERRY_ASSERT (!(context.global_status_flags & ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR)); + context.status_flags &= (uint32_t) ~PARSER_SCANNING_SUCCESSFUL; +#endif /* !JERRY_NDEBUG */ + + JERRY_ASSERT (!(context.status_flags & PARSER_HAS_LATE_LIT_INIT)); + + compiled_code_p = parser_post_processing (&context); + parser_list_free (&context.literal_pool); + + /* When parsing is successful, only the dummy value can be remained on the stack. */ + JERRY_ASSERT (context.stack_top_uint8 == CBC_MAXIMUM_BYTE_VALUE && context.stack.last_position == 1 + && context.stack.first_p != NULL && context.stack.first_p->next_p == NULL + && context.stack.last_p == NULL); + + JERRY_ASSERT (context.arguments_start_p != NULL || !(context.status_flags & PARSER_ARGUMENTS_NEEDED)); + + context.script_p->refs_and_type -= CBC_SCRIPT_REF_ONE; + + if (context.user_value != ECMA_VALUE_EMPTY) + { + CBC_SCRIPT_GET_USER_VALUE (context.script_p) = ecma_copy_value_if_not_object (context.user_value); + } + +#if JERRY_MODULE_SYSTEM + if (context.global_status_flags & ECMA_PARSE_INTERNAL_HAS_IMPORT_META) + { + int idx = (context.user_value != ECMA_VALUE_EMPTY) ? 1 : 0; + ecma_value_t module = ecma_make_object_value ((ecma_object_t *) JERRY_CONTEXT (module_current_p)); + + CBC_SCRIPT_GET_OPTIONAL_VALUES (context.script_p)[idx] = module; + context.script_p->refs_and_type |= CBC_SCRIPT_HAS_IMPORT_META; + } +#endif /* JERRY_MODULE_SYSTEM */ + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context.is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n%s parsing successfully completed. Total byte code size: %d bytes\n", + (context.arguments_start_p == NULL) ? "Script" : "Function", + (int) context.total_byte_code_size); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + } + PARSER_CATCH + { + if (context.last_statement.current_p != NULL) + { + parser_free_jumps (context.last_statement); + } + + parser_free_allocated_buffer (&context); + + scanner_cleanup (&context); + +#if JERRY_MODULE_SYSTEM + if (context.module_names_p != NULL) + { + ecma_module_release_module_names (context.module_names_p); + } +#endif /* JERRY_MODULE_SYSTEM */ + + compiled_code_p = NULL; + parser_free_literals (&context.literal_pool); + parser_cbc_stream_free (&context.byte_code); + +#if JERRY_SOURCE_NAME + ecma_deref_ecma_string (ecma_get_string_from_value (context.script_p->source_name)); +#endif /* JERRY_SOURCE_NAME */ + + if (context.script_p != NULL) + { + JERRY_ASSERT (context.script_p->refs_and_type >= CBC_SCRIPT_REF_ONE); + jmem_heap_free_block (context.script_p, parser_script_size (&context)); + } + } + PARSER_TRY_END + + if (context.scope_stack_p != NULL) + { + parser_free (context.scope_stack_p, context.scope_stack_size * sizeof (parser_scope_stack_t)); + } + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context.is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", (context.arguments_start_p == NULL) ? "Script" : "Function"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_stack_free (&context); + + if (context.global_status_flags & ECMA_PARSE_INTERNAL_FREE_SOURCE) + { + jmem_heap_free_block ((void *) context.source_start_p, context.source_size); + } + + if (context.global_status_flags & ECMA_PARSE_INTERNAL_FREE_ARG_LIST) + { + jmem_heap_free_block ((void *) context.arguments_start_p, context.arguments_size); + } + + if (compiled_code_p != NULL) + { + return compiled_code_p; + } + + if (context.error == PARSER_ERR_OUT_OF_MEMORY) + { + /* It is unlikely that memory can be allocated in an out-of-memory + * situation. However, a simple value can still be thrown. */ + jcontext_raise_exception (ECMA_VALUE_NULL); + return NULL; + } +#if (JERRY_STACK_LIMIT != 0) + if (context.error == PARSER_ERR_STACK_OVERFLOW) + { + ecma_raise_standard_error (JERRY_ERROR_RANGE, ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED); + return NULL; + } +#endif /* JERRY_STACK_LIMIT != 0 */ + +#if JERRY_ERROR_MESSAGES + ecma_string_t *err_str_p; + + if (context.error == PARSER_ERR_INVALID_REGEXP) + { + ecma_value_t error = jcontext_take_exception (); + ecma_property_t *prop_p = + ecma_find_named_property (ecma_get_object_from_value (error), ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE)); + ecma_free_value (error); + JERRY_ASSERT (prop_p); + err_str_p = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (prop_p)->value); + ecma_ref_ecma_string (err_str_p); + } + else + { + err_str_p = ecma_new_ecma_external_string_from_cesu8 (parser_get_error_utf8 (context.error), + parser_get_error_size (context.error), + NULL); + } + ecma_value_t err_str_val = ecma_make_string_value (err_str_p); + ecma_value_t line_str_val = ecma_make_uint32_value (context.token.line); + ecma_value_t col_str_val = ecma_make_uint32_value (context.token.column); + ecma_value_t source_name = parser_source_name (&context); + + ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX, + "% [%:%:%]", + err_str_val, + source_name, + line_str_val, + col_str_val); + + ecma_free_value (source_name); + ecma_free_value (col_str_val); + ecma_free_value (line_str_val); + ecma_deref_ecma_string (err_str_p); +#else /* !JERRY_ERROR_MESSAGES */ + if (context.error == PARSER_ERR_INVALID_REGEXP) + { + jcontext_release_exception (); + } + + ecma_raise_syntax_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + + return NULL; +} /* parser_parse_source */ + +/** + * Save parser context before function parsing. + */ +static void +parser_save_context (parser_context_t *context_p, /**< context */ + parser_saved_context_t *saved_context_p) /**< target for saving the context */ +{ + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + + if (context_p->status_flags & PARSER_FUNCTION_IS_PARSING_ARGS) + { + context_p->status_flags |= PARSER_LEXICAL_BLOCK_NEEDED; + } + + /* Save private part of the context. */ + + saved_context_p->status_flags = context_p->status_flags; + saved_context_p->stack_depth = context_p->stack_depth; + saved_context_p->stack_limit = context_p->stack_limit; + saved_context_p->prev_context_p = context_p->last_context_p; + saved_context_p->last_statement = context_p->last_statement; + + saved_context_p->argument_count = context_p->argument_count; + saved_context_p->argument_length = context_p->argument_length; + saved_context_p->register_count = context_p->register_count; + saved_context_p->literal_count = context_p->literal_count; + + saved_context_p->byte_code = context_p->byte_code; + saved_context_p->byte_code_size = context_p->byte_code_size; + saved_context_p->literal_pool_data = context_p->literal_pool.data; + saved_context_p->scope_stack_p = context_p->scope_stack_p; + saved_context_p->scope_stack_size = context_p->scope_stack_size; + saved_context_p->scope_stack_top = context_p->scope_stack_top; + saved_context_p->scope_stack_reg_top = context_p->scope_stack_reg_top; + saved_context_p->scope_stack_global_end = context_p->scope_stack_global_end; + saved_context_p->tagged_template_literal_cp = context_p->tagged_template_literal_cp; + +#ifndef JERRY_NDEBUG + saved_context_p->context_stack_depth = context_p->context_stack_depth; +#endif /* !JERRY_NDEBUG */ + + /* Reset private part of the context. */ + + context_p->status_flags &= PARSER_IS_STRICT; + context_p->stack_depth = 0; + context_p->stack_limit = 0; + context_p->last_context_p = saved_context_p; + context_p->last_statement.current_p = NULL; + + context_p->argument_count = 0; + context_p->argument_length = UINT16_MAX; + context_p->register_count = 0; + context_p->literal_count = 0; + + parser_cbc_stream_init (&context_p->byte_code); + context_p->byte_code_size = 0; + parser_list_reset (&context_p->literal_pool); + context_p->scope_stack_p = NULL; + context_p->scope_stack_size = 0; + context_p->scope_stack_top = 0; + context_p->scope_stack_reg_top = 0; + context_p->scope_stack_global_end = 0; + context_p->tagged_template_literal_cp = JMEM_CP_NULL; + +#ifndef JERRY_NDEBUG + context_p->context_stack_depth = 0; +#endif /* !JERRY_NDEBUG */ + +} /* parser_save_context */ + +/** + * Restore parser context after function parsing. + */ +static void +parser_restore_context (parser_context_t *context_p, /**< context */ + parser_saved_context_t *saved_context_p) /**< target for saving the context */ +{ + parser_list_free (&context_p->literal_pool); + + if (context_p->scope_stack_p != NULL) + { + parser_free (context_p->scope_stack_p, context_p->scope_stack_size * sizeof (parser_scope_stack_t)); + } + + /* Restore private part of the context. */ + + JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE); + + context_p->status_flags = saved_context_p->status_flags; + context_p->stack_depth = saved_context_p->stack_depth; + context_p->stack_limit = saved_context_p->stack_limit; + context_p->last_context_p = saved_context_p->prev_context_p; + context_p->last_statement = saved_context_p->last_statement; + + context_p->argument_count = saved_context_p->argument_count; + context_p->argument_length = saved_context_p->argument_length; + context_p->register_count = saved_context_p->register_count; + context_p->literal_count = saved_context_p->literal_count; + + context_p->byte_code = saved_context_p->byte_code; + context_p->byte_code_size = saved_context_p->byte_code_size; + context_p->literal_pool.data = saved_context_p->literal_pool_data; + context_p->scope_stack_p = saved_context_p->scope_stack_p; + context_p->scope_stack_size = saved_context_p->scope_stack_size; + context_p->scope_stack_top = saved_context_p->scope_stack_top; + context_p->scope_stack_reg_top = saved_context_p->scope_stack_reg_top; + context_p->scope_stack_global_end = saved_context_p->scope_stack_global_end; + context_p->tagged_template_literal_cp = saved_context_p->tagged_template_literal_cp; + +#ifndef JERRY_NDEBUG + context_p->context_stack_depth = saved_context_p->context_stack_depth; +#endif /* !JERRY_NDEBUG */ + +} /* parser_restore_context */ + +/** + * Parse function code + * + * @return compiled code + */ +ecma_compiled_code_t * +parser_parse_function (parser_context_t *context_p, /**< context */ + uint32_t status_flags) /**< extra status flags */ +{ + parser_saved_context_t saved_context; + ecma_compiled_code_t *compiled_code_p; + + JERRY_ASSERT (status_flags & PARSER_IS_FUNCTION); + parser_save_context (context_p, &saved_context); + context_p->status_flags |= status_flags; + context_p->status_flags |= PARSER_ALLOW_NEW_TARGET; + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", + (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) ? "Class constructor" : "Function"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIST_EXPECTED); + } + + lexer_next_token (context_p); + + parser_parse_function_arguments (context_p, LEXER_RIGHT_PAREN); + lexer_next_token (context_p); + + if ((context_p->status_flags & PARSER_IS_PROPERTY_GETTER) && context_p->argument_count != 0) + { + parser_raise_error (context_p, PARSER_ERR_NO_ARGUMENTS_EXPECTED); + } + + if ((context_p->status_flags & PARSER_IS_PROPERTY_SETTER) && context_p->argument_count != 1) + { + parser_raise_error (context_p, PARSER_ERR_ONE_ARGUMENT_EXPECTED); + } + + if ((context_p->status_flags & (PARSER_CLASS_CONSTRUCTOR | PARSER_ALLOW_SUPER_CALL)) == PARSER_CLASS_CONSTRUCTOR) + { + parser_emit_cbc_ext (context_p, CBC_EXT_RUN_FIELD_INIT); + parser_flush_cbc (context_p); + } + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes && (context_p->status_flags & PARSER_HAS_NON_STRICT_ARG)) + { + JERRY_DEBUG_MSG (" Note: legacy (non-strict) argument definition\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED); + } + + lexer_next_token (context_p); + parser_parse_statements (context_p); + compiled_code_p = parser_post_processing (context_p); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", + (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR) ? "Class constructor" : "Function"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_restore_context (context_p, &saved_context); + + return compiled_code_p; +} /* parser_parse_function */ + +/** + * Parse static class block code + * + * @return compiled code + */ +ecma_compiled_code_t * +parser_parse_class_static_block (parser_context_t *context_p) /**< context */ +{ + parser_saved_context_t saved_context; + ecma_compiled_code_t *compiled_code_p; + + parser_save_context (context_p, &saved_context); + context_p->status_flags |= (PARSER_IS_CLASS_STATIC_BLOCK | PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER + | PARSER_INSIDE_CLASS_FIELD | PARSER_ALLOW_NEW_TARGET | PARSER_DISALLOW_AWAIT_YIELD); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Static class block parsing start ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS); + lexer_next_token (context_p); + + parser_parse_statements (context_p); + compiled_code_p = parser_post_processing (context_p); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Static class block parsing end ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_restore_context (context_p, &saved_context); + + return compiled_code_p; +} /* parser_parse_class_static_block */ + +/** + * Parse arrow function code + * + * @return compiled code + */ +ecma_compiled_code_t * +parser_parse_arrow_function (parser_context_t *context_p, /**< context */ + uint32_t status_flags) /**< extra status flags */ +{ + parser_saved_context_t saved_context; + ecma_compiled_code_t *compiled_code_p; + + JERRY_ASSERT (status_flags & PARSER_IS_FUNCTION); + JERRY_ASSERT (status_flags & PARSER_IS_ARROW_FUNCTION); + parser_save_context (context_p, &saved_context); + context_p->status_flags |= status_flags; + context_p->status_flags |= + saved_context.status_flags & (PARSER_ALLOW_NEW_TARGET | PARSER_ALLOW_SUPER | PARSER_ALLOW_SUPER_CALL); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Arrow function parsing start ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + /* The `await` keyword is disallowed in the IdentifierReference position */ + if (status_flags & PARSER_IS_CLASS_STATIC_BLOCK) + { + context_p->status_flags |= PARSER_DISALLOW_AWAIT_YIELD; + } + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + lexer_next_token (context_p); + parser_parse_function_arguments (context_p, LEXER_RIGHT_PAREN); + lexer_next_token (context_p); + } + else + { + parser_parse_function_arguments (context_p, LEXER_ARROW); + } + + /* The `await` keyword is interpreted as an identifier within the body of arrow functions */ + if (status_flags & PARSER_IS_CLASS_STATIC_BLOCK) + { + context_p->status_flags &= (uint32_t) ~(PARSER_DISALLOW_AWAIT_YIELD | PARSER_IS_CLASS_STATIC_BLOCK); + } + + JERRY_ASSERT (context_p->token.type == LEXER_ARROW); + + lexer_next_token (context_p); + bool next_token_needed = false; + + if (context_p->token.type == LEXER_LEFT_BRACE) + { + lexer_next_token (context_p); + + context_p->status_flags |= PARSER_IS_CLOSURE; + parser_parse_statements (context_p); + + /* Unlike normal function, arrow functions consume their close brace. */ + JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE); + next_token_needed = true; + } + else + { + if (context_p->status_flags & PARSER_IS_STRICT && context_p->status_flags & PARSER_HAS_NON_STRICT_ARG) + { + parser_raise_error (context_p, PARSER_ERR_NON_STRICT_ARG_DEFINITION); + } + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + context_p->last_cbc_opcode = CBC_RETURN_WITH_LITERAL; + } + else + { + parser_emit_cbc (context_p, CBC_RETURN); + } + parser_flush_cbc (context_p); + + lexer_update_await_yield (context_p, saved_context.status_flags); + } + + compiled_code_p = parser_post_processing (context_p); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Arrow function parsing end ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_restore_context (context_p, &saved_context); + + if (next_token_needed) + { + lexer_next_token (context_p); + } + + return compiled_code_p; +} /* parser_parse_arrow_function */ + +/** + * Parse class fields + * + * @return compiled code + */ +ecma_compiled_code_t * +parser_parse_class_fields (parser_context_t *context_p) /**< context */ +{ + parser_saved_context_t saved_context; + ecma_compiled_code_t *compiled_code_p; + + uint32_t extra_status_flags = context_p->status_flags & PARSER_INSIDE_WITH; + + parser_save_context (context_p, &saved_context); + context_p->status_flags |= (PARSER_IS_FUNCTION | PARSER_ALLOW_SUPER | PARSER_INSIDE_CLASS_FIELD + | PARSER_ALLOW_NEW_TARGET | extra_status_flags); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Class fields parsing start ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + const uint8_t *source_end_p = context_p->source_end_p; + bool first_computed_class_field = true; + scanner_location_t end_location; + scanner_get_location (&end_location, context_p); + + do + { + uint8_t class_field_type = context_p->stack_top_uint8; + parser_stack_pop_uint8 (context_p); + + scanner_range_t range = { 0 }; + + if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED) + { + parser_stack_pop (context_p, &range, sizeof (scanner_range_t)); + } + else if (class_field_type & PARSER_CLASS_FIELD_NORMAL) + { + parser_stack_pop (context_p, &range.start_location, sizeof (scanner_location_t)); + } + + uint16_t literal_index = 0; + bool is_private = false; + + if (class_field_type & PARSER_CLASS_FIELD_NORMAL) + { + scanner_set_location (context_p, &range.start_location); + + if (class_field_type & PARSER_CLASS_FIELD_STATIC_BLOCK) + { + scanner_seek (context_p); + JERRY_ASSERT (context_p->source_p[1] == LIT_CHAR_LEFT_BRACE); + context_p->source_p += 2; + context_p->source_end_p = source_end_p; + + uint16_t func_index = lexer_construct_class_static_block_function (context_p); + + parser_emit_cbc_ext_literal (context_p, CBC_EXT_CLASS_CALL_STATIC_BLOCK, func_index); + continue; + } + + uint32_t ident_opts = LEXER_OBJ_IDENT_ONLY_IDENTIFIERS; + is_private = context_p->source_p[-1] == LIT_CHAR_HASHMARK; + + if (is_private) + { + ident_opts |= LEXER_OBJ_IDENT_CLASS_PRIVATE; + } + + context_p->source_end_p = source_end_p; + scanner_seek (context_p); + + lexer_expect_object_literal_id (context_p, ident_opts); + + literal_index = context_p->lit_object.index; + + if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED) + { + lexer_next_token (context_p); + JERRY_ASSERT (context_p->token.type == LEXER_ASSIGN); + } + } + else if (first_computed_class_field) + { + parser_emit_cbc (context_p, CBC_PUSH_NUMBER_0); + first_computed_class_field = false; + } + + if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED) + { + if (!(class_field_type & PARSER_CLASS_FIELD_NORMAL)) + { + scanner_set_location (context_p, &range.start_location); + scanner_seek (context_p); + } + + context_p->source_end_p = range.source_end_p; + lexer_next_token (context_p); + + parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA); + + if (context_p->token.type != LEXER_EOS) + { + parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED); + } + } + else + { + parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED); + } + + if (class_field_type & PARSER_CLASS_FIELD_NORMAL) + { + uint16_t function_literal_index = parser_check_anonymous_function_declaration (context_p); + + if (function_literal_index == PARSER_ANONYMOUS_CLASS) + { + parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, literal_index); + } + else if (function_literal_index < PARSER_NAMED_FUNCTION) + { + uint32_t function_name_status_flags = is_private ? PARSER_PRIVATE_FUNCTION_NAME : 0; + parser_set_function_name (context_p, function_literal_index, literal_index, function_name_status_flags); + } + + if (is_private) + { + parser_emit_cbc_ext_literal (context_p, CBC_EXT_PRIVATE_FIELD_ADD, literal_index); + } + else + { + parser_emit_cbc_ext_literal (context_p, CBC_EXT_DEFINE_FIELD, literal_index); + } + + /* Prepare stack slot for assignment property reference base. Needed by vm.c */ + if (context_p->stack_limit == context_p->stack_depth) + { + context_p->stack_limit++; + JERRY_ASSERT (context_p->stack_limit <= PARSER_MAXIMUM_STACK_LIMIT); + } + } + else + { + uint16_t function_literal_index = parser_check_anonymous_function_declaration (context_p); + uint16_t opcode = CBC_EXT_SET_NEXT_COMPUTED_FIELD; + + if (function_literal_index < PARSER_NAMED_FUNCTION || function_literal_index == PARSER_ANONYMOUS_CLASS) + { + opcode = CBC_EXT_SET_NEXT_COMPUTED_FIELD_ANONYMOUS_FUNC; + } + + parser_flush_cbc (context_p); + + /* The next opcode pushes two more temporary values onto the stack */ + if (context_p->stack_depth + 1 > context_p->stack_limit) + { + context_p->stack_limit = (uint16_t) (context_p->stack_depth + 1); + if (context_p->stack_limit > PARSER_MAXIMUM_STACK_LIMIT) + { + parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED); + } + } + + parser_emit_cbc_ext (context_p, opcode); + } + } while (!(context_p->stack_top_uint8 & PARSER_CLASS_FIELD_END)); + + if (!first_computed_class_field) + { + parser_emit_cbc (context_p, CBC_POP); + } + + parser_flush_cbc (context_p); + context_p->source_end_p = source_end_p; + scanner_set_location (context_p, &end_location); + + compiled_code_p = parser_post_processing (context_p); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Class fields parsing end ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_restore_context (context_p, &saved_context); + + return compiled_code_p; +} /* parser_parse_class_fields */ + +/** + * Check whether the last emitted cbc opcode was an anonymous function declaration + * + * @return PARSER_NOT_FUNCTION_LITERAL - if the last opcode is not a function literal + * PARSER_NAMED_FUNCTION - if the last opcode is not a named function declaration + * PARSER_ANONYMOUS_CLASS - if the last opcode is an anonymous class declaration + * literal index of the anonymous function literal - otherwise + */ +uint16_t +parser_check_anonymous_function_declaration (parser_context_t *context_p) /**< context */ +{ + if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS)) + { + return PARSER_ANONYMOUS_CLASS; + } + + if (context_p->last_cbc.literal_type != LEXER_FUNCTION_LITERAL) + { + return PARSER_NOT_FUNCTION_LITERAL; + } + + uint16_t literal_index = PARSER_NOT_FUNCTION_LITERAL; + + if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL) + { + literal_index = context_p->last_cbc.literal_index; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS) + { + literal_index = context_p->last_cbc.value; + } + else if (context_p->last_cbc_opcode == CBC_PUSH_THREE_LITERALS) + { + literal_index = context_p->last_cbc.third_literal_index; + } + else + { + return PARSER_NOT_FUNCTION_LITERAL; + } + + const ecma_compiled_code_t *bytecode_p; + bytecode_p = (const ecma_compiled_code_t *) (PARSER_GET_LITERAL (literal_index)->u.bytecode_p); + bool is_anon = + ecma_is_value_magic_string (*ecma_compiled_code_resolve_function_name (bytecode_p), LIT_MAGIC_STRING__EMPTY); + + return (is_anon ? literal_index : PARSER_NAMED_FUNCTION); +} /* parser_check_anonymous_function_declaration */ + +/** + * Set the function name of the function literal corresponds to the given function literal index + * to the given character buffer of literal corresponds to the given name index. + */ +void +parser_set_function_name (parser_context_t *context_p, /**< context */ + uint16_t function_literal_index, /**< function literal index */ + uint16_t name_index, /**< function name literal index */ + uint32_t status_flags) /**< status flags */ +{ + ecma_compiled_code_t *bytecode_p; + bytecode_p = (ecma_compiled_code_t *) (PARSER_GET_LITERAL (function_literal_index)->u.bytecode_p); + + parser_compiled_code_set_function_name (context_p, bytecode_p, name_index, status_flags); +} /* parser_set_function_name */ + +/** + * Prepend the given prefix into the current function name literal + * + * @return pointer to the newly allocated buffer + */ +static uint8_t * +parser_add_function_name_prefix (parser_context_t *context_p, /**< context */ + const char *prefix_p, /**< prefix */ + uint32_t prefix_size, /**< prefix's length */ + uint32_t *name_length_p, /**< [out] function name's size */ + lexer_literal_t *name_lit_p) /**< function name literal */ +{ + *name_length_p += prefix_size; + uint8_t *name_buffer_p = (uint8_t *) parser_malloc (context_p, *name_length_p * sizeof (uint8_t)); + memcpy (name_buffer_p, prefix_p, prefix_size); + memcpy (name_buffer_p + prefix_size, name_lit_p->u.char_p, name_lit_p->prop.length); + + return name_buffer_p; +} /* parser_add_function_name_prefix */ + +/** + * Set the function name of the given compiled code + * to the given character buffer of literal corresponds to the given name index. + */ +void +parser_compiled_code_set_function_name (parser_context_t *context_p, /**< context */ + ecma_compiled_code_t *bytecode_p, /**< function literal index */ + uint16_t name_index, /**< function name literal index */ + uint32_t status_flags) /**< status flags */ +{ + ecma_value_t *func_name_start_p; + func_name_start_p = ecma_compiled_code_resolve_function_name ((const ecma_compiled_code_t *) bytecode_p); + + if (JERRY_UNLIKELY (!ecma_is_value_magic_string (*func_name_start_p, LIT_MAGIC_STRING__EMPTY))) + { + return; + } + + parser_scope_stack_t *scope_stack_start_p = context_p->scope_stack_p; + parser_scope_stack_t *scope_stack_p = scope_stack_start_p + context_p->scope_stack_top; + + while (scope_stack_p > scope_stack_start_p) + { + scope_stack_p--; + + if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC && scanner_decode_map_to (scope_stack_p) == name_index) + { + name_index = scope_stack_p->map_from; + break; + } + } + + lexer_literal_t *name_lit_p = (lexer_literal_t *) PARSER_GET_LITERAL (name_index); + + if (name_lit_p->type != LEXER_IDENT_LITERAL && name_lit_p->type != LEXER_STRING_LITERAL) + { + return; + } + + uint8_t *name_buffer_p = (uint8_t *) name_lit_p->u.char_p; + uint32_t name_length = name_lit_p->prop.length; + + if (status_flags & PARSER_PRIVATE_FUNCTION_NAME) + { + name_buffer_p = parser_add_function_name_prefix (context_p, "#", 1, &name_length, name_lit_p); + } + else if (status_flags & (PARSER_IS_PROPERTY_GETTER | PARSER_IS_PROPERTY_SETTER)) + { + name_buffer_p = parser_add_function_name_prefix (context_p, + (status_flags & PARSER_IS_PROPERTY_GETTER) ? "get " : "set ", + 4, + &name_length, + name_lit_p); + } + + *func_name_start_p = + ecma_find_or_create_literal_string (name_buffer_p, name_length, (status_flags & LEXER_FLAG_ASCII) != 0); + + if (name_buffer_p != name_lit_p->u.char_p) + { + parser_free (name_buffer_p, name_length); + } +} /* parser_compiled_code_set_function_name */ + +/** + * Raise a parse error. + */ +void +parser_raise_error (parser_context_t *context_p, /**< context */ + parser_error_msg_t error) /**< error code */ +{ + /* Must be compatible with the scanner because + * the lexer might throws errors during prescanning. */ + parser_saved_context_t *saved_context_p = context_p->last_context_p; + + while (saved_context_p != NULL) + { + parser_cbc_stream_free (&saved_context_p->byte_code); + + /* First the current literal pool is freed, and then it is replaced + * by the literal pool coming from the saved context. Since literals + * are not used anymore, this is a valid replacement. The last pool + * is freed by parser_parse_source. */ + + parser_free_literals (&context_p->literal_pool); + context_p->literal_pool.data = saved_context_p->literal_pool_data; + + if (context_p->scope_stack_p != NULL) + { + parser_free (context_p->scope_stack_p, context_p->scope_stack_size * sizeof (parser_scope_stack_t)); + } + context_p->scope_stack_p = saved_context_p->scope_stack_p; + context_p->scope_stack_size = saved_context_p->scope_stack_size; + + if (saved_context_p->last_statement.current_p != NULL) + { + parser_free_jumps (saved_context_p->last_statement); + } + + if (saved_context_p->tagged_template_literal_cp != JMEM_CP_NULL) + { + ecma_collection_t *collection = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, saved_context_p->tagged_template_literal_cp); + ecma_collection_free_template_literal (collection); + } + + saved_context_p = saved_context_p->prev_context_p; + } + + parser_free_private_fields (context_p); + + if (context_p->tagged_template_literal_cp != JMEM_CP_NULL) + { + ecma_collection_t *collection = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, context_p->tagged_template_literal_cp); + ecma_collection_free_template_literal (collection); + } + + context_p->error = error; + PARSER_THROW (context_p->try_buffer); + /* Should never been reached. */ + JERRY_ASSERT (0); +} /* parser_raise_error */ + +#endif /* JERRY_PARSER */ + +/** + * Parse EcmaScript source code + * + * Note: + * if arg_list_p is not NULL, a function body is parsed + * returned value must be freed with ecma_free_value + * + * @return pointer to compiled byte code - if success + * NULL - otherwise + */ +ecma_compiled_code_t * +parser_parse_script (void *source_p, /**< source code */ + uint32_t parse_opts, /**< ecma_parse_opts_t option bits */ + const jerry_parse_options_t *options_p) /**< additional configuration options */ +{ +#if JERRY_PARSER + ecma_compiled_code_t *bytecode_p = parser_parse_source (source_p, parse_opts, options_p); + + if (JERRY_UNLIKELY (bytecode_p == NULL)) + { + /* Exception has already thrown. */ + return NULL; + } + + return bytecode_p; +#else /* !JERRY_PARSER */ + JERRY_UNUSED (arg_list_p); + JERRY_UNUSED (arg_list_size); + JERRY_UNUSED (source_p); + JERRY_UNUSED (source_size); + JERRY_UNUSED (parse_opts); + JERRY_UNUSED (source_name); + + ecma_raise_syntax_error (ECMA_ERR_PARSER_NOT_SUPPORTED); + return NULL; +#endif /* JERRY_PARSER */ +} /* parser_parse_script */ + +/** + * @} + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser.h new file mode 100644 index 0000000..59238d5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-parser.h @@ -0,0 +1,40 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JS_PARSER_H +#define JS_PARSER_H + +#include "ecma-globals.h" + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_parser Parser + * @{ + */ + +/* Note: source must be a valid UTF-8 string */ +ecma_compiled_code_t *parser_parse_script (void *source_p, uint32_t parse_opts, const jerry_parse_options_t *options_p); + +/** + * @} + * @} + * @} + */ + +#endif /* !JS_PARSER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-internal.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-internal.h new file mode 100644 index 0000000..98b1b28 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-internal.h @@ -0,0 +1,399 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JS_SCANNER_INTERNAL_H +#define JS_SCANNER_INTERNAL_H + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_scanner Scanner + * @{ + */ + +/** + * Scan mode types. + */ +typedef enum +{ + SCAN_MODE_PRIMARY_EXPRESSION, /**< scanning primary expression */ + SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW, /**< scanning primary expression after new */ + SCAN_MODE_POST_PRIMARY_EXPRESSION, /**< scanning post primary expression */ + SCAN_MODE_PRIMARY_EXPRESSION_END, /**< scanning primary expression end */ + SCAN_MODE_STATEMENT, /**< scanning statement */ + SCAN_MODE_STATEMENT_OR_TERMINATOR, /**< scanning statement or statement end */ + SCAN_MODE_STATEMENT_END, /**< scanning statement end */ + SCAN_MODE_VAR_STATEMENT, /**< scanning var statement */ + SCAN_MODE_PROPERTY_NAME, /**< scanning property name */ + SCAN_MODE_FUNCTION_ARGUMENTS, /**< scanning function arguments */ + SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS, /**< continue scanning function arguments */ + SCAN_MODE_BINDING, /**< array or object binding */ + SCAN_MODE_CLASS_DECLARATION, /**< scanning class declaration */ + SCAN_MODE_CLASS_BODY, /**< scanning class body */ + SCAN_MODE_CLASS_BODY_NO_SCAN, /**< scanning class body without calling lexer_scan_identifier */ +} scan_modes_t; + +/** + * Scan stack mode types. + */ +typedef enum +{ + SCAN_STACK_SCRIPT, /**< script */ + SCAN_STACK_SCRIPT_FUNCTION, /**< script is a function body */ + SCAN_STACK_BLOCK_STATEMENT, /**< block statement group */ + SCAN_STACK_FUNCTION_STATEMENT, /**< function statement */ + SCAN_STACK_FUNCTION_EXPRESSION, /**< function expression */ + SCAN_STACK_FUNCTION_PROPERTY, /**< function expression in an object literal */ + SCAN_STACK_FUNCTION_ARROW, /**< arrow function expression */ + SCAN_STACK_SWITCH_BLOCK, /**< block part of "switch" statement */ + SCAN_STACK_IF_STATEMENT, /**< statement part of "if" statements */ + SCAN_STACK_WITH_STATEMENT, /**< statement part of "with" statements */ + SCAN_STACK_WITH_EXPRESSION, /**< expression part of "with" statements */ + SCAN_STACK_DO_STATEMENT, /**< statement part of "do" statements */ + SCAN_STACK_DO_EXPRESSION, /**< expression part of "do" statements */ + SCAN_STACK_WHILE_EXPRESSION, /**< expression part of "while" iterator */ + SCAN_STACK_PAREN_EXPRESSION, /**< expression in brackets */ + SCAN_STACK_STATEMENT_WITH_EXPR, /**< statement which starts with expression enclosed in brackets */ + SCAN_STACK_BINDING_INIT, /**< post processing after a single initializer */ + SCAN_STACK_BINDING_LIST_INIT, /**< post processing after an initializer list */ + SCAN_STACK_LET, /**< let statement */ + SCAN_STACK_CONST, /**< const statement */ + /* The SCANNER_IS_FOR_START macro needs to be updated when the following constants are reordered. */ + SCAN_STACK_VAR, /**< var statement */ + SCAN_STACK_FOR_VAR_START, /**< start of "for" iterator with var statement */ + SCAN_STACK_FOR_LET_START, /**< start of "for" iterator with let statement */ + SCAN_STACK_FOR_CONST_START, /**< start of "for" iterator with const statement */ + SCAN_STACK_FOR_START, /**< start of "for" iterator */ + SCAN_STACK_FOR_CONDITION, /**< condition part of "for" iterator */ + SCAN_STACK_FOR_EXPRESSION, /**< expression part of "for" iterator */ + SCAN_STACK_SWITCH_EXPRESSION, /**< expression part of "switch" statement */ + SCAN_STACK_CASE_STATEMENT, /**< case statement inside a switch statement */ + SCAN_STACK_COLON_EXPRESSION, /**< expression between a question mark and colon */ + SCAN_STACK_TRY_STATEMENT, /**< try statement */ + SCAN_STACK_CATCH_STATEMENT, /**< catch statement */ + SCAN_STACK_ARRAY_LITERAL, /**< array literal or destructuring assignment or binding */ + SCAN_STACK_OBJECT_LITERAL, /**< object literal group */ + SCAN_STACK_PROPERTY_ACCESSOR, /**< property accessor in square brackets */ + /* These four must be in this order. */ + SCAN_STACK_COMPUTED_PROPERTY, /**< computed property name */ + SCAN_STACK_COMPUTED_GENERATOR, /**< computed generator function */ + SCAN_STACK_COMPUTED_ASYNC, /**< computed async function */ + SCAN_STACK_COMPUTED_ASYNC_GENERATOR, /**< computed async function */ + SCAN_STACK_TEMPLATE_STRING, /**< template string */ + SCAN_STACK_TAGGED_TEMPLATE_LITERAL, /**< tagged template literal */ + SCAN_STACK_PRIVATE_BLOCK_EARLY, /**< private block for single statements (force early declarations) */ + SCAN_STACK_PRIVATE_BLOCK, /**< private block for single statements */ + SCAN_STACK_ARROW_ARGUMENTS, /**< might be arguments of an arrow function */ + SCAN_STACK_ARROW_EXPRESSION, /**< expression body of an arrow function */ + SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR, /**< explicit class constructor */ + SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR, /**< implicit class constructor */ + SCAN_STACK_CLASS_STATEMENT, /**< class statement */ + SCAN_STACK_CLASS_EXPRESSION, /**< class expression */ + SCAN_STACK_CLASS_EXTENDS, /**< class extends expression */ + SCAN_STACK_CLASS_FIELD_INITIALIZER, /**< class field initializer */ + SCAN_STACK_FUNCTION_PARAMETERS, /**< function parameter initializer */ + SCAN_STACK_FOR_START_PATTERN, /**< possible assignment pattern for "for" iterator */ + SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */ + SCAN_STACK_CLASS_STATIC_BLOCK, /**< class static block */ +#if JERRY_MODULE_SYSTEM + SCAN_STACK_EXPORT_DEFAULT, /**< scan primary expression after export default */ +#endif /* JERRY_MODULE_SYSTEM */ +} scan_stack_modes_t; + +/** + * Scanner context flag types. + */ +typedef enum +{ + SCANNER_CONTEXT_NO_FLAGS = 0, /**< no flags are set */ + SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION = (1 << 0), /**< throw async function error */ +} scanner_context_flags_t; + +/** + * Checks whether the stack top is a for statement start. + */ +#define SCANNER_IS_FOR_START(stack_top) ((stack_top) >= SCAN_STACK_FOR_VAR_START && (stack_top) <= SCAN_STACK_FOR_START) + +/** + * Generic descriptor which stores only the start position. + */ +typedef struct +{ + const uint8_t *source_p; /**< start source byte */ +} scanner_source_start_t; + +/** + * Descriptor for storing a binding literal on stack. + */ +typedef struct +{ + lexer_lit_location_t *literal_p; /**< binding literal */ +} scanner_binding_literal_t; + +/** + * Flags for type member of lexer_lit_location_t structure in the literal pool. + */ +typedef enum +{ + SCANNER_LITERAL_IS_ARG = (1 << 0), /**< literal is argument */ + SCANNER_LITERAL_IS_VAR = (1 << 1), /**< literal is var */ + /** literal is a destructured argument binding of a possible arrow function */ + SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG = SCANNER_LITERAL_IS_VAR, + SCANNER_LITERAL_IS_FUNC = (1 << 2), /**< literal is function */ + SCANNER_LITERAL_NO_REG = (1 << 3), /**< literal cannot be stored in a register */ + SCANNER_LITERAL_IS_LET = (1 << 4), /**< literal is let */ + /** literal is a function declared in this block (prevents declaring let/const with the same name) */ + SCANNER_LITERAL_IS_FUNC_DECLARATION = SCANNER_LITERAL_IS_LET, + SCANNER_LITERAL_IS_CONST = (1 << 5), /**< literal is const */ + /** literal is a destructured argument binding */ + SCANNER_LITERAL_IS_DESTRUCTURED_ARG = SCANNER_LITERAL_IS_CONST, + SCANNER_LITERAL_IS_USED = (1 << 6), /**< literal is used */ + SCANNER_LITERAL_EARLY_CREATE = (1 << 7), /**< binding should be created early with ECMA_VALUE_UNINITIALIZED */ +} scanner_literal_type_flags_t; + +/* + * Known combinations: + * + * SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION : + * function declared in this block + * SCANNER_LITERAL_IS_LOCAL : + * module import on global scope, catch block variable otherwise + * SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC : + * a function argument which is reassigned to a function later + * SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG : + * destructured binding argument + * SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_FUNC : + * destructured binding argument which is reassigned to a function later + */ + +/** + * Literal is a local declaration (let, const, catch variable, etc.) + */ +#define SCANNER_LITERAL_IS_LOCAL (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST) + +/** + * Literal is a local function declaration + */ +#define SCANNER_LITERAL_IS_LOCAL_FUNC (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION) + +/** + * For statement descriptor. + */ +typedef struct +{ + /** shared fields of for statements */ + union + { + const uint8_t *source_p; /**< start source byte */ + scanner_for_info_t *for_info_p; /**< for info */ + } u; +} scanner_for_statement_t; + +/** + * Switch statement descriptor. + */ +typedef struct +{ + scanner_case_info_t **last_case_p; /**< last case info */ +} scanner_switch_statement_t; + +/** + * Types of scanner destructuring bindings. + */ +typedef enum +{ + /* Update SCANNER_NEEDS_BINDING_LIST after changing these values. */ + SCANNER_BINDING_NONE, /**< not a destructuring binding expression */ + SCANNER_BINDING_VAR, /**< destructuring var binding */ + SCANNER_BINDING_LET, /**< destructuring let binding */ + SCANNER_BINDING_CATCH, /**< destructuring catch binding */ + SCANNER_BINDING_CONST, /**< destructuring const binding */ + SCANNER_BINDING_ARG, /**< destructuring arg binding */ + SCANNER_BINDING_ARROW_ARG, /**< possible destructuring arg binding of an arrow function */ +} scanner_binding_type_t; + +/** + * Check whether a binding list is needed for the binding pattern. + */ +#define SCANNER_NEEDS_BINDING_LIST(type) ((type) >= SCANNER_BINDING_LET) + +/** + * Scanner binding items for destructuring binding patterns. + */ +typedef struct scanner_binding_item_t +{ + struct scanner_binding_item_t *next_p; /**< next binding in the list */ + lexer_lit_location_t *literal_p; /**< binding literal */ +} scanner_binding_item_t; + +/** + * Scanner binding lists for destructuring binding patterns. + */ +typedef struct scanner_binding_list_t +{ + struct scanner_binding_list_t *prev_p; /**< prev list */ + scanner_binding_item_t *items_p; /**< list of bindings */ + bool is_nested; /**< is nested binding declaration */ +} scanner_binding_list_t; + +/** + * Flags for scanner_literal_pool_t structure. + */ +typedef enum +{ + SCANNER_LITERAL_POOL_FUNCTION = (1 << 0), /**< literal pool represents a function */ + SCANNER_LITERAL_POOL_CLASS_NAME = (1 << 1), /**< literal pool which contains a class name */ + SCANNER_LITERAL_POOL_CLASS_FIELD = (1 << 2), /**< literal pool is created for a class field initializer */ + SCANNER_LITERAL_POOL_IS_STRICT = (1 << 3), /**< literal pool represents a strict mode code block */ + SCANNER_LITERAL_POOL_CAN_EVAL = (1 << 4), /**< prepare for executing eval in this block */ + SCANNER_LITERAL_POOL_NO_ARGUMENTS = (1 << 5), /**< arguments object must not be constructed, + * or arguments cannot be stored in registers if + * SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS is set */ + SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS = (1 << 6), /**< arguments is referenced in function args */ + SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT = (1 << 7), /**< function has complex (ES2015+) argument definition */ + SCANNER_LITERAL_POOL_IN_WITH = (1 << 8), /**< literal pool is in a with statement */ + SCANNER_LITERAL_POOL_ARROW = (1 << 9), /**< arrow function */ + SCANNER_LITERAL_POOL_GENERATOR = (1 << 10), /**< generator function */ + SCANNER_LITERAL_POOL_ASYNC = (1 << 11), /**< async function */ + SCANNER_LITERAL_POOL_FUNCTION_STATEMENT = (1 << 12), /**< function statement */ + SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE = (1 << 13), /**< function body contains super reference */ +#if JERRY_MODULE_SYSTEM + SCANNER_LITERAL_POOL_IN_EXPORT = (1 << 14), /**< the declared variables are exported by the module system */ +#endif /* JERRY_MODULE_SYSTEM */ +} scanner_literal_pool_flags_t; + +/** + * Define a function where no arguments are allowed. + */ +#define SCANNER_LITERAL_POOL_ARROW_FLAGS \ + (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_NO_ARGUMENTS | SCANNER_LITERAL_POOL_ARROW) + +/** + * This flag represents that the bracketed expression might be an async arrow function. + * The SCANNER_LITERAL_POOL_ARROW flag is reused for this purpose. + */ +#define SCANNER_LITERAL_POOL_MAY_ASYNC_ARROW SCANNER_LITERAL_POOL_ARROW + +/** + * Getting the generator and async properties of literal pool status flags. + */ +#define SCANNER_FROM_LITERAL_POOL_TO_COMPUTED(status_flags) \ + ((uint8_t) ((((status_flags) >> 10) & 0x3) + SCAN_STACK_COMPUTED_PROPERTY)) + +/** + * Setting the generator and async properties of literal pool status flags. + */ +#define SCANNER_FROM_COMPUTED_TO_LITERAL_POOL(mode) (((mode) -SCAN_STACK_COMPUTED_PROPERTY) << 10) + +/** + * Literal pool which may contains function argument identifiers + */ +#define SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS(status_flags) \ + (!((status_flags) & (SCANNER_LITERAL_POOL_CLASS_NAME | SCANNER_LITERAL_POOL_CLASS_FIELD))) + +/** + * Local literal pool. + */ +typedef struct scanner_literal_pool_t +{ + struct scanner_literal_pool_t *prev_p; /**< previous literal pool */ + const uint8_t *source_p; /**< source position where the final data needs to be inserted */ + parser_list_t literal_pool; /**< list of literal */ + uint16_t status_flags; /**< combination of scanner_literal_pool_flags_t flags */ + uint16_t no_declarations; /**< size of scope stack required during parsing */ +} scanner_literal_pool_t; + +/** + * Scanner context. + */ +struct scanner_context_t +{ + uint32_t context_status_flags; /**< original status flags of the context */ + uint8_t mode; /**< scanner mode */ + uint8_t binding_type; /**< current destructuring binding type */ + uint16_t status_flags; /**< scanner status flags */ + scanner_binding_list_t *active_binding_list_p; /**< currently active binding list */ + scanner_literal_pool_t *active_literal_pool_p; /**< currently active literal pool */ + scanner_switch_statement_t active_switch_statement; /**< currently active switch statement */ + scanner_info_t *end_arguments_p; /**< position of end arguments */ + const uint8_t *async_source_p; /**< source position for async functions */ +}; + +/* Scanner utils. */ + +void scanner_raise_error (parser_context_t *context_p); +void scanner_raise_redeclaration_error (parser_context_t *context_p); + +void *scanner_malloc (parser_context_t *context_p, size_t size); +void scanner_free (void *ptr, size_t size); + +size_t scanner_get_stream_size (scanner_info_t *info_p, size_t size); +scanner_info_t *scanner_insert_info (parser_context_t *context_p, const uint8_t *source_p, size_t size); +scanner_info_t *scanner_insert_info_before (parser_context_t *context_p, + const uint8_t *source_p, + scanner_info_t *start_info_p, + size_t size); +scanner_literal_pool_t * +scanner_push_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p, uint16_t status_flags); +void scanner_pop_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_filter_arguments (parser_context_t *context_p, scanner_context_t *scanner_context_p); +lexer_lit_location_t *scanner_add_custom_literal (parser_context_t *context_p, + scanner_literal_pool_t *literal_pool_p, + const lexer_lit_location_t *literal_location_p); +lexer_lit_location_t *scanner_add_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_add_reference (parser_context_t *context_p, scanner_context_t *scanner_context_p); +lexer_lit_location_t *scanner_append_argument (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_add_private_identifier (parser_context_t *context_p, scanner_private_field_flags_t opts); +void scanner_detect_invalid_var (parser_context_t *context_p, + scanner_context_t *scanner_context_p, + lexer_lit_location_t *var_literal_p); +void scanner_detect_invalid_let (parser_context_t *context_p, lexer_lit_location_t *let_literal_p); +void scanner_detect_eval_call (parser_context_t *context_p, scanner_context_t *scanner_context_p); + +lexer_lit_location_t * +scanner_push_class_declaration (parser_context_t *context_p, scanner_context_t *scanner_context_p, uint8_t stack_mode); +void scanner_push_class_field_initializer (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_push_destructuring_pattern (parser_context_t *context_p, + scanner_context_t *scanner_context_p, + uint8_t binding_type, + bool is_nested); +void scanner_pop_binding_list (scanner_context_t *scanner_context_p); +void scanner_append_hole (parser_context_t *context_p, scanner_context_t *scanner_context_p); + +/* Scanner operations. */ + +void scanner_add_async_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_check_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void +scanner_scan_simple_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p, const uint8_t *source_p); +void scanner_check_arrow_arg (parser_context_t *context_p, scanner_context_t *scanner_context_p); +bool scanner_check_async_function (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_check_function_after_if (parser_context_t *context_p, scanner_context_t *scanner_context_p); +#if JERRY_MODULE_SYSTEM +void scanner_check_import_meta (parser_context_t *context_p); +#endif /* JERRY_MODULE_SYSTEM */ +void scanner_scan_bracket (parser_context_t *context_p, scanner_context_t *scanner_context_p); +void scanner_check_directives (parser_context_t *context_p, scanner_context_t *scanner_context_p); + +/** + * @} + * @} + * @} + */ + +#endif /* !JS_SCANNER_INTERNAL_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-ops.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-ops.cpp new file mode 100644 index 0000000..98dadc0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-ops.cpp @@ -0,0 +1,602 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js-parser-internal.h" +#include "js-scanner-internal.h" +#include "lit-char-helpers.h" + +#if JERRY_PARSER + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_scanner Scanner + * @{ + */ + +/** + * Add the "async" literal to the literal pool. + */ +void +scanner_add_async_literal (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + lexer_lit_location_t async_literal; + + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC); + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &async_literal, sizeof (lexer_lit_location_t)); + + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &async_literal); + + lit_location_p->type |= SCANNER_LITERAL_IS_USED; + + if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) + { + lit_location_p->type |= SCANNER_LITERAL_NO_REG; + } +} /* scanner_add_async_literal */ + +/** + * Init scanning the body of an arrow function. + */ +static void +scanner_check_arrow_body (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + lexer_next_token (context_p); + + scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARROW; + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + parser_stack_push_uint8 (context_p, SCAN_STACK_ARROW_EXPRESSION); + return; + } + + lexer_next_token (context_p); + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_ARROW); + scanner_check_directives (context_p, scanner_context_p); +} /* scanner_check_arrow_body */ + +/** + * Process arrow function with argument list. + */ +void +scanner_check_arrow (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + parser_stack_pop_uint8 (context_p); + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_ARROW || (context_p->token.flags & LEXER_WAS_NEWLINE)) + { + if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) + { + scanner_add_async_literal (context_p, scanner_context_p); + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + scanner_pop_literal_pool (context_p, scanner_context_p); + return; + } + + if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) + { + parser_stack_pop (context_p, NULL, sizeof (lexer_lit_location_t) + 1); + } + + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + uint16_t status_flags = literal_pool_p->status_flags; + + bool is_async_arrow = (status_flags & SCANNER_LITERAL_POOL_MAY_ASYNC_ARROW) != 0; + + status_flags |= SCANNER_LITERAL_POOL_ARROW_FLAGS; + status_flags &= + (uint16_t) ~(SCANNER_LITERAL_POOL_IN_WITH | SCANNER_LITERAL_POOL_GENERATOR | SCANNER_LITERAL_POOL_ASYNC); + + context_p->status_flags &= (uint32_t) ~(PARSER_IS_GENERATOR_FUNCTION | PARSER_IS_ASYNC_FUNCTION); + + if (is_async_arrow) + { + status_flags |= SCANNER_LITERAL_POOL_ASYNC; + context_p->status_flags |= PARSER_IS_ASYNC_FUNCTION; + } + + literal_pool_p->status_flags = status_flags; + + scanner_filter_arguments (context_p, scanner_context_p); + scanner_check_arrow_body (context_p, scanner_context_p); +} /* scanner_check_arrow */ + +/** + * Process arrow function with a single argument. + */ +void +scanner_scan_simple_arrow (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + const uint8_t *source_p) /**< identifier end position */ +{ + uint16_t status_flags = SCANNER_LITERAL_POOL_ARROW_FLAGS; + + context_p->status_flags &= (uint32_t) ~(PARSER_IS_GENERATOR_FUNCTION | PARSER_IS_ASYNC_FUNCTION); + + if (scanner_context_p->async_source_p != NULL) + { + JERRY_ASSERT (scanner_context_p->async_source_p == source_p); + + status_flags |= SCANNER_LITERAL_POOL_ASYNC; + context_p->status_flags |= PARSER_IS_ASYNC_FUNCTION; + } + + scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, status_flags); + literal_pool_p->source_p = source_p; + + lexer_lit_location_t *location_p = scanner_add_literal (context_p, scanner_context_p); + location_p->type |= SCANNER_LITERAL_IS_ARG; + + /* Skip the => token, which size is two. */ + context_p->source_p += 2; + PARSER_PLUS_EQUAL_LC (context_p->column, 2); + context_p->token.flags = (uint8_t) (context_p->token.flags & ~LEXER_NO_SKIP_SPACES); + + scanner_check_arrow_body (context_p, scanner_context_p); +} /* scanner_scan_simple_arrow */ + +/** + * Process the next argument of a might-be arrow function. + */ +void +scanner_check_arrow_arg (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARROW_ARGUMENTS); + + const uint8_t *source_p = context_p->source_p; + bool process_arrow = false; + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (context_p->token.type == LEXER_THREE_DOTS) + { + lexer_next_token (context_p); + } + + switch (context_p->token.type) + { + case LEXER_RIGHT_PAREN: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + return; + } + case LEXER_LITERAL: + { + if (context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + + if (lexer_check_arrow (context_p)) + { + process_arrow = true; + break; + } + + lexer_lit_location_t *argument_literal_p = scanner_append_argument (context_p, scanner_context_p); + + scanner_detect_eval_call (context_p, scanner_context_p); + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_COMMA || context_p->token.type == LEXER_RIGHT_PAREN) + { + return; + } + + if (context_p->token.type != LEXER_ASSIGN) + { + break; + } + + if (argument_literal_p->type & SCANNER_LITERAL_IS_USED) + { + JERRY_ASSERT (argument_literal_p->type & SCANNER_LITERAL_EARLY_CREATE); + return; + } + + scanner_binding_literal_t binding_literal; + binding_literal.literal_p = argument_literal_p; + + parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); + return; + } + case LEXER_LEFT_SQUARE: + case LEXER_LEFT_BRACE: + { + scanner_append_hole (context_p, scanner_context_p); + scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_ARROW_ARG, false); + + if (context_p->token.type == LEXER_LEFT_BRACE) + { + parser_stack_push_uint8 (context_p, 0); + parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); + scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; + return; + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); + scanner_context_p->mode = SCAN_MODE_BINDING; + lexer_next_token (context_p); + return; + } + } + + scanner_pop_literal_pool (context_p, scanner_context_p); + parser_stack_pop_uint8 (context_p); + + if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) + { + scanner_add_async_literal (context_p, scanner_context_p); + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_EXPRESSION); + + if (process_arrow) + { + scanner_scan_simple_arrow (context_p, scanner_context_p, source_p); + } +} /* scanner_check_arrow_arg */ + +/** + * Detect async functions. + * + * @return true, if async is followed by a function keyword, false otherwise + */ +bool +scanner_check_async_function (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + JERRY_ASSERT (lexer_token_is_async (context_p)); + JERRY_ASSERT (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION + || scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW); + JERRY_ASSERT (scanner_context_p->async_source_p != NULL); + + lexer_lit_location_t async_literal = context_p->token.lit_location; + + lexer_next_token (context_p); + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE)) + { + if (context_p->token.type == LEXER_KEYW_FUNCTION) + { + return true; + } + + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + if (!lexer_check_arrow (context_p)) + { + scanner_raise_error (context_p); + } + + scanner_scan_simple_arrow (context_p, scanner_context_p, scanner_context_p->async_source_p); + scanner_context_p->async_source_p = NULL; + return false; + } + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + parser_stack_push (context_p, &async_literal, sizeof (lexer_lit_location_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_USE_ASYNC); + return false; + } + } + + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &async_literal); + lit_location_p->type |= SCANNER_LITERAL_IS_USED; + + if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) + { + lit_location_p->type |= SCANNER_LITERAL_NO_REG; + } + + scanner_context_p->async_source_p = NULL; + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return false; +} /* scanner_check_async_function */ + +/** + * Check whether the statement of an if/else construct is a function statement. + */ +void +scanner_check_function_after_if (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + lexer_next_token (context_p); + scanner_context_p->mode = SCAN_MODE_STATEMENT; + + if (JERRY_UNLIKELY (context_p->token.type == LEXER_KEYW_FUNCTION)) + { + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + + literal_pool_p->source_p = context_p->source_p; + parser_stack_push_uint8 (context_p, SCAN_STACK_PRIVATE_BLOCK); + } +} /* scanner_check_function_after_if */ + +#if JERRY_MODULE_SYSTEM + +/** + * Check whether the next token is meta. + */ +void +scanner_check_import_meta (parser_context_t *context_p) /**< context */ +{ + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL + || context_p->token.keyword_type != LEXER_KEYW_META + || (context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE)) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + context_p->global_status_flags |= ECMA_PARSE_INTERNAL_HAS_IMPORT_META; +} /* scanner_check_import_meta */ + +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * Arrow types for scanner_scan_bracket() function. + */ +typedef enum +{ + SCANNER_SCAN_BRACKET_NO_ARROW, /**< not an arrow function */ + SCANNER_SCAN_BRACKET_SIMPLE_ARROW, /**< simple arrow function */ + SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG, /**< arrow function with one argument */ +} scanner_scan_bracket_arrow_type_t; + +/** + * Scan bracketed expressions. + */ +void +scanner_scan_bracket (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + size_t depth = 0; + const uint8_t *arrow_source_p; + const uint8_t *async_source_p = NULL; + scanner_scan_bracket_arrow_type_t arrow_type = SCANNER_SCAN_BRACKET_NO_ARROW; + + JERRY_ASSERT (context_p->token.type == LEXER_LEFT_PAREN); + + do + { + arrow_source_p = context_p->source_p; + depth++; + lexer_next_token (context_p); + } while (context_p->token.type == LEXER_LEFT_PAREN); + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + switch (context_p->token.type) + { + case LEXER_LITERAL: + { + if (context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + arrow_source_p = NULL; + break; + } + + const uint8_t *source_p = context_p->source_p; + + if (lexer_check_arrow (context_p)) + { + arrow_source_p = source_p; + arrow_type = SCANNER_SCAN_BRACKET_SIMPLE_ARROW; + break; + } + + size_t total_depth = depth; + + while (depth > 0 && lexer_check_next_character (context_p, LIT_CHAR_RIGHT_PAREN)) + { + lexer_consume_next_character (context_p); + depth--; + } + + if (context_p->token.keyword_type == LEXER_KEYW_EVAL + && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + { + /* A function call cannot be an eval function. */ + arrow_source_p = NULL; + const uint16_t flags = (uint16_t) (SCANNER_LITERAL_POOL_CAN_EVAL | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE); + + scanner_context_p->active_literal_pool_p->status_flags |= flags; + break; + } + + if (total_depth == depth) + { + if (lexer_check_arrow_param (context_p)) + { + JERRY_ASSERT (depth > 0); + depth--; + break; + } + + if (JERRY_UNLIKELY (lexer_token_is_async (context_p))) + { + async_source_p = source_p; + } + } + + if (depth == total_depth - 1 && lexer_check_arrow (context_p)) + { + arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG; + break; + } + + if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) + { + scanner_add_async_literal (context_p, scanner_context_p); + } + + arrow_source_p = NULL; + break; + } + case LEXER_THREE_DOTS: + case LEXER_LEFT_SQUARE: + case LEXER_LEFT_BRACE: + case LEXER_RIGHT_PAREN: + { + JERRY_ASSERT (depth > 0); + depth--; + break; + } + default: + { + arrow_source_p = NULL; + break; + } + } + + if (JERRY_UNLIKELY (scanner_context_p->async_source_p != NULL) && (arrow_source_p == NULL || depth > 0)) + { + scanner_context_p->async_source_p = NULL; + } + + while (depth > 0) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_EXPRESSION); + depth--; + } + + if (arrow_source_p != NULL) + { + JERRY_ASSERT (async_source_p == NULL); + + if (arrow_type == SCANNER_SCAN_BRACKET_SIMPLE_ARROW) + { + scanner_scan_simple_arrow (context_p, scanner_context_p, arrow_source_p); + return; + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_ARROW_ARGUMENTS); + + uint16_t status_flags = 0; + + if (JERRY_UNLIKELY (scanner_context_p->async_source_p != NULL)) + { + status_flags |= SCANNER_LITERAL_POOL_MAY_ASYNC_ARROW; + arrow_source_p = scanner_context_p->async_source_p; + scanner_context_p->async_source_p = NULL; + } + + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, status_flags); + literal_pool_p->source_p = arrow_source_p; + + if (arrow_type == SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG) + { + scanner_append_argument (context_p, scanner_context_p); + scanner_detect_eval_call (context_p, scanner_context_p); + + context_p->token.type = LEXER_RIGHT_PAREN; + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + } + else if (context_p->token.type == LEXER_RIGHT_PAREN) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + } + else + { + scanner_check_arrow_arg (context_p, scanner_context_p); + } + } + else if (JERRY_UNLIKELY (async_source_p != NULL)) + { + scanner_context_p->async_source_p = async_source_p; + scanner_check_async_function (context_p, scanner_context_p); + } +} /* scanner_scan_bracket */ + +/** + * Check directives before a source block. + */ +void +scanner_check_directives (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + + while (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + bool is_use_strict = false; + + if (lexer_string_is_use_strict (context_p) && !(context_p->status_flags & PARSER_IS_STRICT)) + { + is_use_strict = true; + context_p->status_flags |= PARSER_IS_STRICT; + } + + lexer_next_token (context_p); + + if (!lexer_string_is_directive (context_p)) + { + if (is_use_strict) + { + context_p->status_flags &= (uint32_t) ~PARSER_IS_STRICT; + } + + /* The string is part of an expression statement. */ + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + break; + } + + if (is_use_strict) + { + scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_IS_STRICT; + } + + if (context_p->token.type == LEXER_SEMICOLON) + { + lexer_next_token (context_p); + } + } +} /* scanner_check_directives */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-util.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-util.cpp new file mode 100644 index 0000000..5713fea --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner-util.cpp @@ -0,0 +1,2950 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-helpers.h" +#include "ecma-lex-env.h" + +#include "jcontext.h" +#include "js-parser-internal.h" +#include "js-scanner-internal.h" +#include "lit-char-helpers.h" + +#if JERRY_PARSER + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_scanner Scanner + * @{ + */ + +JERRY_STATIC_ASSERT (PARSER_MAXIMUM_NUMBER_OF_LITERALS + PARSER_MAXIMUM_NUMBER_OF_REGISTERS < PARSER_REGISTER_START, + maximum_number_of_literals_plus_registers_must_be_less_than_register_start); + +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG & SCANNER_LITERAL_IS_LOCAL) == 0, + is_arrow_arg_binding_flag_must_not_use_local_flags); + +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_LET & SCANNER_LITERAL_IS_LOCAL) != 0, is_let_flag_must_use_local_flags); + +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_CONST & SCANNER_LITERAL_IS_LOCAL) != 0, is_const_flag_must_use_local_flags); + +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_FUNC_DECLARATION & SCANNER_LITERAL_IS_LOCAL) != 0, + is_func_declaration_flag_must_use_local_flags); + +JERRY_STATIC_ASSERT ((SCANNER_LITERAL_IS_DESTRUCTURED_ARG & SCANNER_LITERAL_IS_LOCAL) != 0, + is_arg_binding_flag_must_use_local_flags); + +JERRY_STATIC_ASSERT (((int)SCANNER_LITERAL_IS_FUNC_DECLARATION != (int)SCANNER_LITERAL_IS_DESTRUCTURED_ARG), + is_func_declaration_must_be_different_from_is_arg_binding); + +JERRY_STATIC_ASSERT (((int)PARSER_SCOPE_STACK_IS_CONST_REG == (int)PARSER_SCOPE_STACK_IS_LOCAL_CREATED), + scope_stack_is_const_reg_and_scope_stack_is_local_created_must_be_the_same); + +/** + * Raise a scanner error. + */ +void +scanner_raise_error (parser_context_t *context_p /**< context */) +{ + PARSER_THROW (context_p->try_buffer); + /* Should never been reached. */ + JERRY_ASSERT (0); +} /* scanner_raise_error */ + +/** + * Raise a variable redeclaration error. + */ +void +scanner_raise_redeclaration_error (parser_context_t *context_p) /**< context */ +{ + scanner_info_t *info_p = scanner_insert_info (context_p, context_p->source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_ERR_REDECLARED; + + scanner_raise_error (context_p); +} /* scanner_raise_redeclaration_error */ + +/** + * Allocate memory for scanner. + * + * @return allocated memory + */ +void * +scanner_malloc (parser_context_t *context_p, /**< context */ + size_t size) /**< size of the memory block */ +{ + void *result; + + JERRY_ASSERT (size > 0); + result = jmem_heap_alloc_block_null_on_error (size); + + if (result == NULL) + { + scanner_cleanup (context_p); + + /* This is the only error which specify its reason. */ + context_p->error = PARSER_ERR_OUT_OF_MEMORY; + PARSER_THROW (context_p->try_buffer); + } + return result; +} /* scanner_malloc */ + +/** + * Free memory allocated by scanner_malloc. + */ +void +scanner_free (void *ptr, /**< pointer to free */ + size_t size) /**< size of the memory block */ +{ + jmem_heap_free_block (ptr, size); +} /* scanner_free */ + +/** + * Count the size of a stream after an info block. + * + * @return the size in bytes + */ +size_t +scanner_get_stream_size (scanner_info_t *info_p, /**< scanner info block */ + size_t size) /**< size excluding the stream */ +{ + const uint8_t *data_p = ((const uint8_t *) info_p) + size; + const uint8_t *data_p_start = data_p; + + while (data_p[0] != SCANNER_STREAM_TYPE_END) + { + switch (data_p[0] & SCANNER_STREAM_TYPE_MASK) + { + case SCANNER_STREAM_TYPE_VAR: + case SCANNER_STREAM_TYPE_LET: + case SCANNER_STREAM_TYPE_CONST: + case SCANNER_STREAM_TYPE_LOCAL: +#if JERRY_MODULE_SYSTEM + case SCANNER_STREAM_TYPE_IMPORT: +#endif /* JERRY_MODULE_SYSTEM */ + case SCANNER_STREAM_TYPE_ARG: + case SCANNER_STREAM_TYPE_ARG_VAR: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR: + case SCANNER_STREAM_TYPE_ARG_FUNC: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC: + case SCANNER_STREAM_TYPE_FUNC: + { + break; + } + default: + { + JERRY_ASSERT ((data_p[0] & SCANNER_STREAM_TYPE_MASK) == SCANNER_STREAM_TYPE_HOLE + || SCANNER_STREAM_TYPE_IS_ARGUMENTS (data_p[0] & SCANNER_STREAM_TYPE_MASK)); + data_p++; + continue; + } + } + + data_p += 3; + + if (data_p[-3] & SCANNER_STREAM_UINT16_DIFF) + { + data_p++; + } + else if (data_p[-1] == 0) + { + data_p += sizeof (const uint8_t *); + } + } + + return size + 1 + (size_t) (data_p - data_p_start); +} /* scanner_get_stream_size */ + +/** + * Insert a scanner info block into the scanner info chain. + * + * @return newly allocated scanner info + */ +scanner_info_t * +scanner_insert_info (parser_context_t *context_p, /**< context */ + const uint8_t *source_p, /**< triggering position */ + size_t size) /**< size of the memory block */ +{ + scanner_info_t *new_scanner_info_p = (scanner_info_t *) scanner_malloc (context_p, size); + scanner_info_t *scanner_info_p = context_p->next_scanner_info_p; + scanner_info_t *prev_scanner_info_p = NULL; + + JERRY_ASSERT (scanner_info_p != NULL); + JERRY_ASSERT (source_p != NULL); + + new_scanner_info_p->source_p = source_p; + + while (source_p < scanner_info_p->source_p) + { + prev_scanner_info_p = scanner_info_p; + scanner_info_p = scanner_info_p->next_p; + + JERRY_ASSERT (scanner_info_p != NULL); + } + + /* Multiple scanner info blocks cannot be assigned to the same position. */ + JERRY_ASSERT (source_p != scanner_info_p->source_p); + + new_scanner_info_p->next_p = scanner_info_p; + + if (JERRY_LIKELY (prev_scanner_info_p == NULL)) + { + context_p->next_scanner_info_p = new_scanner_info_p; + } + else + { + prev_scanner_info_p->next_p = new_scanner_info_p; + } + + return new_scanner_info_p; +} /* scanner_insert_info */ + +/** + * Insert a scanner info block into the scanner info chain before a given info block. + * + * @return newly allocated scanner info + */ +scanner_info_t * +scanner_insert_info_before (parser_context_t *context_p, /**< context */ + const uint8_t *source_p, /**< triggering position */ + scanner_info_t *start_info_p, /**< first info position */ + size_t size) /**< size of the memory block */ +{ + JERRY_ASSERT (start_info_p != NULL); + + scanner_info_t *new_scanner_info_p = (scanner_info_t *) scanner_malloc (context_p, size); + scanner_info_t *scanner_info_p = start_info_p->next_p; + scanner_info_t *prev_scanner_info_p = start_info_p; + + new_scanner_info_p->source_p = source_p; + + while (source_p < scanner_info_p->source_p) + { + prev_scanner_info_p = scanner_info_p; + scanner_info_p = scanner_info_p->next_p; + + JERRY_ASSERT (scanner_info_p != NULL); + } + + /* Multiple scanner info blocks cannot be assigned to the same position. */ + JERRY_ASSERT (source_p != scanner_info_p->source_p); + + new_scanner_info_p->next_p = scanner_info_p; + + prev_scanner_info_p->next_p = new_scanner_info_p; + return new_scanner_info_p; +} /* scanner_insert_info_before */ + +/** + * Release the next scanner info. + */ +void +scanner_release_next (parser_context_t *context_p, /**< context */ + size_t size) /**< size of the memory block */ +{ + scanner_info_t *next_p = context_p->next_scanner_info_p->next_p; + + jmem_heap_free_block (context_p->next_scanner_info_p, size); + context_p->next_scanner_info_p = next_p; +} /* scanner_release_next */ + +/** + * Set the active scanner info to the next scanner info. + */ +void +scanner_set_active (parser_context_t *context_p) /**< context */ +{ + scanner_info_t *scanner_info_p = context_p->next_scanner_info_p; + + context_p->next_scanner_info_p = scanner_info_p->next_p; + scanner_info_p->next_p = context_p->active_scanner_info_p; + context_p->active_scanner_info_p = scanner_info_p; +} /* scanner_set_active */ + +/** + * Set the next scanner info to the active scanner info. + */ +void +scanner_revert_active (parser_context_t *context_p) /**< context */ +{ + scanner_info_t *scanner_info_p = context_p->active_scanner_info_p; + + context_p->active_scanner_info_p = scanner_info_p->next_p; + scanner_info_p->next_p = context_p->next_scanner_info_p; + context_p->next_scanner_info_p = scanner_info_p; +} /* scanner_revert_active */ + +/** + * Release the active scanner info. + */ +void +scanner_release_active (parser_context_t *context_p, /**< context */ + size_t size) /**< size of the memory block */ +{ + scanner_info_t *next_p = context_p->active_scanner_info_p->next_p; + + jmem_heap_free_block (context_p->active_scanner_info_p, size); + context_p->active_scanner_info_p = next_p; +} /* scanner_release_active */ + +/** + * Release switch cases. + */ +void +scanner_release_switch_cases (scanner_case_info_t *case_p) /**< case list */ +{ + while (case_p != NULL) + { + scanner_case_info_t *next_p = case_p->next_p; + + jmem_heap_free_block (case_p, sizeof (scanner_case_info_t)); + case_p = next_p; + } +} /* scanner_release_switch_cases */ + +/** + * Release private fields. + */ +void +scanner_release_private_fields (scanner_class_private_member_t *member_p) /**< private member list */ +{ + while (member_p != NULL) + { + scanner_class_private_member_t *prev_p = member_p->prev_p; + + jmem_heap_free_block (member_p, sizeof (scanner_class_private_member_t)); + member_p = prev_p; + } +} /* scanner_release_private_fields */ + +/** + * Seek to correct position in the scanner info list. + */ +void +scanner_seek (parser_context_t *context_p) /**< context */ +{ + const uint8_t *source_p = context_p->source_p; + scanner_info_t *prev_p; + + if (context_p->skipped_scanner_info_p != NULL) + { + JERRY_ASSERT (context_p->skipped_scanner_info_p->source_p != NULL); + + context_p->skipped_scanner_info_end_p->next_p = context_p->next_scanner_info_p; + + if (context_p->skipped_scanner_info_end_p->source_p <= source_p) + { + prev_p = context_p->skipped_scanner_info_end_p; + } + else + { + prev_p = context_p->skipped_scanner_info_p; + + if (prev_p->source_p > source_p) + { + context_p->next_scanner_info_p = prev_p; + context_p->skipped_scanner_info_p = NULL; + return; + } + + context_p->skipped_scanner_info_p = prev_p; + } + } + else + { + prev_p = context_p->next_scanner_info_p; + + if (prev_p->source_p == NULL || prev_p->source_p > source_p) + { + return; + } + + context_p->skipped_scanner_info_p = prev_p; + } + + while (prev_p->next_p->source_p != NULL && prev_p->next_p->source_p <= source_p) + { + prev_p = prev_p->next_p; + } + + context_p->skipped_scanner_info_end_p = prev_p; + context_p->next_scanner_info_p = prev_p->next_p; +} /* scanner_seek */ + +/** + * Checks whether a literal is equal to "arguments". + */ +static inline bool +scanner_literal_is_arguments (lexer_lit_location_t *literal_p) /**< literal */ +{ + return lexer_compare_identifier_to_string (literal_p, (const uint8_t *) "arguments", 9); +} /* scanner_literal_is_arguments */ + +/** + * Find if there is a duplicated argument in the given context + * + * @return true - if there are duplicates, false - otherwise + */ +static bool +scanner_find_duplicated_arg (parser_context_t *context_p, lexer_lit_location_t *lit_loc_p) +{ + if (!(context_p->status_flags & PARSER_FUNCTION_IS_PARSING_ARGS)) + { + return false; + } + + if (scanner_literal_is_arguments (lit_loc_p)) + { + return true; + } + + uint16_t register_end, encoding_limit, encoding_delta; + ecma_value_t *literal_p; + ecma_value_t *literal_start_p; + + const ecma_compiled_code_t *bytecode_header_p = JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + + register_end = args_p->register_end; + + literal_p = (ecma_value_t *) (args_p + 1); + literal_p -= register_end; + literal_start_p = literal_p; + literal_p += args_p->literal_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + + register_end = args_p->register_end; + + literal_p = (ecma_value_t *) (args_p + 1); + literal_p -= register_end; + literal_start_p = literal_p; + literal_p += args_p->literal_end; + } + + if (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING)) + { + encoding_limit = CBC_SMALL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_SMALL_LITERAL_ENCODING_DELTA; + } + else + { + encoding_limit = CBC_FULL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_FULL_LITERAL_ENCODING_DELTA; + } + + uint8_t *byte_code_p = (uint8_t *) literal_p; + + bool found_duplicate = false; + + while (*byte_code_p == CBC_CREATE_LOCAL) + { + byte_code_p++; + uint16_t literal_index = *byte_code_p++; + + if (literal_index >= encoding_limit) + { + literal_index = (uint16_t) (((literal_index << 8) | *byte_code_p++) - encoding_delta); + } + + ecma_string_t *arg_string = ecma_get_string_from_value (literal_start_p[literal_index]); + uint8_t *destination_p = (uint8_t *) parser_malloc (context_p, lit_loc_p->length); + lexer_convert_ident_to_cesu8 (destination_p, lit_loc_p->char_p, lit_loc_p->length); + ecma_string_t *search_key_p = ecma_new_ecma_string_from_utf8 (destination_p, lit_loc_p->length); + scanner_free (destination_p, lit_loc_p->length); + + found_duplicate = ecma_compare_ecma_strings (arg_string, search_key_p); + ecma_deref_ecma_string (search_key_p); + + if (found_duplicate) + { + break; + } + } + + return found_duplicate; +} /* scanner_find_duplicated_arg */ + +/** + * Find any let/const declaration of a given literal. + * + * @return true - if the literal is found, false - otherwise + */ +static bool +scanner_scope_find_lexical_declaration (parser_context_t *context_p, /**< context */ + lexer_lit_location_t *literal_p) /**< literal */ +{ + ecma_string_t *name_p; + uint32_t flags = context_p->global_status_flags; + + if (!(flags & ECMA_PARSE_EVAL) || (!(flags & ECMA_PARSE_DIRECT_EVAL) && (context_p->status_flags & PARSER_IS_STRICT))) + { + return false; + } + + if (JERRY_LIKELY (!(literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + name_p = ecma_new_ecma_string_from_utf8 (literal_p->char_p, literal_p->length); + } + else + { + uint8_t *destination_p = (uint8_t *) scanner_malloc (context_p, literal_p->length); + + lexer_convert_ident_to_cesu8 (destination_p, literal_p->char_p, literal_p->length); + + name_p = ecma_new_ecma_string_from_utf8 (destination_p, literal_p->length); + + scanner_free (destination_p, literal_p->length); + } + + ecma_object_t *lex_env_p; + + if (flags & ECMA_PARSE_DIRECT_EVAL) + { + lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p; + + while (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + { + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p != NULL && ecma_is_property_enumerable (*property_p)) + { + ecma_deref_ecma_string (name_p); + return true; + } + } + + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + } + else + { + lex_env_p = ecma_get_global_scope (ecma_builtin_get_global ()); + } + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + if (property_p != NULL + && (ecma_is_property_enumerable (*property_p) || scanner_find_duplicated_arg (context_p, literal_p))) + { + ecma_deref_ecma_string (name_p); + return true; + } + } + + ecma_deref_ecma_string (name_p); + return false; +} /* scanner_scope_find_lexical_declaration */ + +/** + * Push a new literal pool. + * + * @return the newly created literal pool + */ +scanner_literal_pool_t * +scanner_push_literal_pool (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + uint16_t status_flags) /**< combination of scanner_literal_pool_flags_t flags */ +{ + scanner_literal_pool_t *prev_literal_pool_p = scanner_context_p->active_literal_pool_p; + scanner_literal_pool_t *literal_pool_p; + + literal_pool_p = (scanner_literal_pool_t *) scanner_malloc (context_p, sizeof (scanner_literal_pool_t)); + + if (!(status_flags & SCANNER_LITERAL_POOL_FUNCTION)) + { + JERRY_ASSERT (prev_literal_pool_p != NULL); + status_flags |= SCANNER_LITERAL_POOL_NO_ARGUMENTS; + + const uint16_t copied_flags = + (SCANNER_LITERAL_POOL_IN_WITH | SCANNER_LITERAL_POOL_GENERATOR | SCANNER_LITERAL_POOL_ASYNC); + + status_flags |= (uint16_t) (prev_literal_pool_p->status_flags & copied_flags); + } + else + { + context_p->status_flags &= (uint32_t) ~(PARSER_IS_GENERATOR_FUNCTION | PARSER_IS_ASYNC_FUNCTION); + + if (status_flags & SCANNER_LITERAL_POOL_GENERATOR) + { + context_p->status_flags |= PARSER_IS_GENERATOR_FUNCTION; + } + + if (status_flags & SCANNER_LITERAL_POOL_ASYNC) + { + context_p->status_flags |= PARSER_IS_ASYNC_FUNCTION; + } + } + + if (prev_literal_pool_p != NULL) + { + const uint16_t copied_flags = SCANNER_LITERAL_POOL_IS_STRICT; + status_flags |= (uint16_t) (prev_literal_pool_p->status_flags & copied_flags); + + /* The logical value of these flags must be the same. */ + JERRY_ASSERT (!(status_flags & SCANNER_LITERAL_POOL_IS_STRICT) == !(context_p->status_flags & PARSER_IS_STRICT)); + } + + parser_list_init (&literal_pool_p->literal_pool, + sizeof (lexer_lit_location_t), + (uint32_t) ((128 - sizeof (void *)) / sizeof (lexer_lit_location_t))); + literal_pool_p->source_p = NULL; + literal_pool_p->status_flags = status_flags; + literal_pool_p->no_declarations = 0; + + literal_pool_p->prev_p = prev_literal_pool_p; + scanner_context_p->active_literal_pool_p = literal_pool_p; + + return literal_pool_p; +} /* scanner_push_literal_pool */ + +JERRY_STATIC_ASSERT (((uint8_t)PARSER_MAXIMUM_IDENT_LENGTH <= UINT8_MAX), maximum_ident_length_must_fit_in_a_byte); + +/** + * Current status of arguments. + */ +typedef enum +{ + SCANNER_ARGUMENTS_NOT_PRESENT, /**< arguments object must not be created */ + SCANNER_ARGUMENTS_MAY_PRESENT, /**< arguments object can be created */ + SCANNER_ARGUMENTS_MAY_PRESENT_IN_EVAL, /**< arguments object must be present unless otherwise declared */ + SCANNER_ARGUMENTS_PRESENT, /**< arguments object must be created */ + SCANNER_ARGUMENTS_PRESENT_NO_REG, /**< arguments object must be created and cannot be stored in registers */ +} scanner_arguments_type_t; + +/** + * Pop the last literal pool from the end. + */ +void +scanner_pop_literal_pool (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + scanner_literal_pool_t *prev_literal_pool_p = literal_pool_p->prev_p; + + const uint32_t arrow_super_flags = (SCANNER_LITERAL_POOL_ARROW | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE); + if ((literal_pool_p->status_flags & arrow_super_flags) == arrow_super_flags) + { + prev_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE; + } + + if (JERRY_UNLIKELY (literal_pool_p->source_p == NULL)) + { + JERRY_ASSERT (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION); + JERRY_ASSERT (literal_pool_p->literal_pool.data.first_p == NULL + && literal_pool_p->literal_pool.data.last_p == NULL); + + scanner_context_p->active_literal_pool_p = literal_pool_p->prev_p; + scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t)); + return; + } + + uint16_t status_flags = literal_pool_p->status_flags; + scanner_arguments_type_t arguments_type = SCANNER_ARGUMENTS_MAY_PRESENT; + + if (status_flags & SCANNER_LITERAL_POOL_NO_ARGUMENTS) + { + arguments_type = SCANNER_ARGUMENTS_NOT_PRESENT; + } + else if (status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) + { + arguments_type = SCANNER_ARGUMENTS_MAY_PRESENT_IN_EVAL; + } + + if (status_flags & SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT; + + if (status_flags & (SCANNER_LITERAL_POOL_NO_ARGUMENTS | SCANNER_LITERAL_POOL_CAN_EVAL)) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT_NO_REG; + status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_NO_ARGUMENTS; + } + } + + uint8_t can_eval_types = 0; + + if (prev_literal_pool_p == NULL && !(context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL)) + { + can_eval_types |= SCANNER_LITERAL_IS_FUNC; + } + + if ((status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) && prev_literal_pool_p != NULL) + { + prev_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CAN_EVAL; + } + + parser_list_iterator_t literal_iterator; + lexer_lit_location_t *literal_p; + int32_t no_declarations = literal_pool_p->no_declarations; + + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + + uint8_t arguments_stream_type = SCANNER_STREAM_TYPE_ARGUMENTS; + const uint8_t *prev_source_p = literal_pool_p->source_p - 1; + lexer_lit_location_t *last_argument_p = NULL; + size_t compressed_size = 1; + + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + uint8_t type = literal_p->type; + + if (JERRY_UNLIKELY (no_declarations > PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK)) + { + continue; + } + + if (!(status_flags & SCANNER_LITERAL_POOL_NO_ARGUMENTS) && scanner_literal_is_arguments (literal_p)) + { + JERRY_ASSERT (arguments_type != SCANNER_ARGUMENTS_NOT_PRESENT); + status_flags |= SCANNER_LITERAL_POOL_NO_ARGUMENTS; + + if (type & SCANNER_LITERAL_IS_ARG) + { + JERRY_ASSERT (arguments_type != SCANNER_ARGUMENTS_PRESENT + && arguments_type != SCANNER_ARGUMENTS_PRESENT_NO_REG); + arguments_type = SCANNER_ARGUMENTS_NOT_PRESENT; + last_argument_p = literal_p; + } + else if (type & SCANNER_LITERAL_IS_LOCAL) + { + if (arguments_type == SCANNER_ARGUMENTS_MAY_PRESENT || arguments_type == SCANNER_ARGUMENTS_MAY_PRESENT_IN_EVAL) + { + arguments_type = SCANNER_ARGUMENTS_NOT_PRESENT; + } + else + { + if (arguments_type == SCANNER_ARGUMENTS_PRESENT_NO_REG) + { + type |= SCANNER_LITERAL_NO_REG; + } + else if (type & (SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_EARLY_CREATE)) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT_NO_REG; + } + + if ((type & SCANNER_LITERAL_IS_LOCAL_FUNC) == SCANNER_LITERAL_IS_LOCAL_FUNC) + { + type |= SCANNER_LITERAL_IS_ARG; + literal_p->type = type; + no_declarations--; + arguments_stream_type = SCANNER_STREAM_TYPE_ARGUMENTS_FUNC; + } + else + { + arguments_stream_type |= SCANNER_STREAM_LOCAL_ARGUMENTS; + } + } + } + else + { + if ((type & SCANNER_LITERAL_IS_VAR) + && (arguments_type == SCANNER_ARGUMENTS_PRESENT || arguments_type == SCANNER_ARGUMENTS_PRESENT_NO_REG)) + { + if (arguments_type == SCANNER_ARGUMENTS_PRESENT_NO_REG) + { + type |= SCANNER_LITERAL_NO_REG; + } + else if (type & (SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_EARLY_CREATE)) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT_NO_REG; + } + + type |= SCANNER_LITERAL_IS_ARG; + literal_p->type = type; + no_declarations--; + } + + if ((type & SCANNER_LITERAL_NO_REG) || arguments_type == SCANNER_ARGUMENTS_MAY_PRESENT_IN_EVAL) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT_NO_REG; + } + else if (arguments_type == SCANNER_ARGUMENTS_MAY_PRESENT) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT; + } + + /* The SCANNER_LITERAL_IS_ARG may be set above. */ + if (!(type & SCANNER_LITERAL_IS_ARG)) + { + literal_p->type = 0; + continue; + } + } + } + else if (type & SCANNER_LITERAL_IS_ARG) + { + last_argument_p = literal_p; + } + + if ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) + && (type & SCANNER_LITERAL_IS_LOCAL_FUNC) == SCANNER_LITERAL_IS_FUNC) + { + if (prev_literal_pool_p == NULL && scanner_scope_find_lexical_declaration (context_p, literal_p)) + { + literal_p->type = 0; + continue; + } + + if (!(type & SCANNER_LITERAL_IS_ARG)) + { + type |= SCANNER_LITERAL_IS_VAR; + } + + type &= (uint8_t) ~SCANNER_LITERAL_IS_FUNC; + literal_p->type = type; + } + + if ((type & SCANNER_LITERAL_IS_LOCAL) + || ((type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_ARG)) + && (status_flags & SCANNER_LITERAL_POOL_FUNCTION))) + { + JERRY_ASSERT ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) || !(literal_p->type & SCANNER_LITERAL_IS_ARG)); + + if (literal_p->length == 0) + { + compressed_size += 1; + continue; + } + + no_declarations++; + + if ((status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) || (type & can_eval_types)) + { + type |= SCANNER_LITERAL_NO_REG; + literal_p->type = type; + } + + if (type & SCANNER_LITERAL_IS_FUNC) + { + no_declarations++; + + if ((type & (SCANNER_LITERAL_IS_CONST | SCANNER_LITERAL_IS_ARG)) == SCANNER_LITERAL_IS_CONST) + { + JERRY_ASSERT (type & SCANNER_LITERAL_IS_LET); + + /* Catch parameters cannot be functions. */ + literal_p->type = (uint8_t) (type & ~SCANNER_LITERAL_IS_FUNC); + no_declarations--; + } + } + + intptr_t diff = (intptr_t) (literal_p->char_p - prev_source_p); + + if (diff >= 1 && diff <= (intptr_t) UINT8_MAX) + { + compressed_size += 2 + 1; + } + else if (diff >= -(intptr_t) UINT8_MAX && diff <= (intptr_t) UINT16_MAX) + { + compressed_size += 2 + 2; + } + else + { + compressed_size += 2 + 1 + sizeof (const uint8_t *); + } + + prev_source_p = literal_p->char_p + literal_p->length; + + if ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) + || ((type & SCANNER_LITERAL_IS_FUNC) && (status_flags & SCANNER_LITERAL_POOL_IS_STRICT)) + || !(type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC))) + { + continue; + } + } + + if (prev_literal_pool_p != NULL && literal_p->length > 0) + { + /* Propagate literal to upper level. */ + lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p, prev_literal_pool_p, literal_p); + uint8_t extended_type = literal_location_p->type; + + if ((status_flags & (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_CLASS_FIELD)) + || (type & SCANNER_LITERAL_NO_REG)) + { + extended_type |= SCANNER_LITERAL_NO_REG; + } + + extended_type |= SCANNER_LITERAL_IS_USED; + + if (status_flags & SCANNER_LITERAL_POOL_FUNCTION_STATEMENT) + { + extended_type |= SCANNER_LITERAL_EARLY_CREATE; + } + + const uint8_t mask = (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_LOCAL); + + if ((type & SCANNER_LITERAL_IS_ARG) || (literal_location_p->type & mask) == SCANNER_LITERAL_IS_LET + || (literal_location_p->type & mask) == SCANNER_LITERAL_IS_CONST) + { + /* Clears the SCANNER_LITERAL_IS_VAR and SCANNER_LITERAL_IS_FUNC flags + * for speculative arrow parameters and local (non-var) functions. */ + type = 0; + } + + type = (uint8_t) (type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC)); + JERRY_ASSERT (type == 0 || !(status_flags & SCANNER_LITERAL_POOL_FUNCTION)); + + literal_location_p->type = (uint8_t) (extended_type | type); + } + } + + if ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) || (compressed_size > 1)) + { + if (arguments_type == SCANNER_ARGUMENTS_MAY_PRESENT) + { + arguments_type = SCANNER_ARGUMENTS_NOT_PRESENT; + } + else if (arguments_type == SCANNER_ARGUMENTS_MAY_PRESENT_IN_EVAL) + { + arguments_type = SCANNER_ARGUMENTS_PRESENT_NO_REG; + } + + if (arguments_type != SCANNER_ARGUMENTS_NOT_PRESENT) + { + compressed_size++; + } + + compressed_size += sizeof (scanner_info_t); + + scanner_info_t *info_p; + + if (prev_literal_pool_p != NULL || scanner_context_p->end_arguments_p == NULL) + { + info_p = scanner_insert_info (context_p, literal_pool_p->source_p, compressed_size); + } + else + { + scanner_info_t *start_info_p = scanner_context_p->end_arguments_p; + info_p = scanner_insert_info_before (context_p, literal_pool_p->source_p, start_info_p, compressed_size); + } + + if (no_declarations > PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK) + { + no_declarations = PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK; + } + + uint8_t *data_p = (uint8_t *) (info_p + 1); + bool mapped_arguments = false; + + if (status_flags & SCANNER_LITERAL_POOL_FUNCTION) + { + info_p->type = SCANNER_TYPE_FUNCTION; + + uint8_t u8_arg = 0; + + if (arguments_type != SCANNER_ARGUMENTS_NOT_PRESENT) + { + u8_arg |= SCANNER_FUNCTION_ARGUMENTS_NEEDED; + + if (no_declarations < PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK) + { + no_declarations++; + } + + if (!(status_flags & (SCANNER_LITERAL_POOL_IS_STRICT | SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT))) + { + mapped_arguments = true; + } + + if (arguments_type == SCANNER_ARGUMENTS_PRESENT_NO_REG) + { + arguments_stream_type |= SCANNER_STREAM_NO_REG; + } + + if (last_argument_p == NULL) + { + *data_p++ = arguments_stream_type; + } + } + else + { + last_argument_p = NULL; + } + + if (status_flags & (SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT | SCANNER_LITERAL_POOL_ARROW)) + { + u8_arg |= SCANNER_FUNCTION_HAS_COMPLEX_ARGUMENT; + } + + if (status_flags & SCANNER_LITERAL_POOL_ASYNC) + { + u8_arg |= SCANNER_FUNCTION_ASYNC; + + if (status_flags & SCANNER_LITERAL_POOL_FUNCTION_STATEMENT) + { + u8_arg |= SCANNER_FUNCTION_STATEMENT; + } + } + + if (status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) + { + u8_arg |= SCANNER_FUNCTION_LEXICAL_ENV_NEEDED; + } + + if (status_flags & SCANNER_LITERAL_POOL_IS_STRICT) + { + u8_arg |= SCANNER_FUNCTION_IS_STRICT; + } + + info_p->u8_arg = u8_arg; + info_p->u16_arg = (uint16_t) no_declarations; + } + else + { + info_p->type = SCANNER_TYPE_BLOCK; + + JERRY_ASSERT (prev_literal_pool_p != NULL); + } + + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + prev_source_p = literal_pool_p->source_p - 1; + no_declarations = literal_pool_p->no_declarations; + + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (JERRY_UNLIKELY (no_declarations > PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK) + || (!(literal_p->type & SCANNER_LITERAL_IS_LOCAL) + && (!(literal_p->type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_ARG)) + || !(status_flags & SCANNER_LITERAL_POOL_FUNCTION)))) + { + continue; + } + + if (literal_p->length == 0) + { + *data_p++ = SCANNER_STREAM_TYPE_HOLE; + + if (literal_p == last_argument_p) + { + *data_p++ = arguments_stream_type; + } + continue; + } + + no_declarations++; + + uint8_t type = SCANNER_STREAM_TYPE_VAR; + + if (literal_p->type & SCANNER_LITERAL_IS_FUNC) + { + no_declarations++; + type = SCANNER_STREAM_TYPE_FUNC; + + if (literal_p->type & SCANNER_LITERAL_IS_ARG) + { + type = SCANNER_STREAM_TYPE_ARG_FUNC; + + if (literal_p->type & SCANNER_LITERAL_IS_DESTRUCTURED_ARG) + { + type = SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC; + } + } + } + else if (literal_p->type & SCANNER_LITERAL_IS_ARG) + { + type = SCANNER_STREAM_TYPE_ARG; + + if (literal_p->type & SCANNER_LITERAL_IS_DESTRUCTURED_ARG) + { + type = SCANNER_STREAM_TYPE_DESTRUCTURED_ARG; + } + + if (literal_p->type & SCANNER_LITERAL_IS_VAR) + { + type = (uint8_t) (type + 1); + + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_ARG_VAR || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR); + } + } + else if (literal_p->type & SCANNER_LITERAL_IS_LET) + { + if (!(literal_p->type & SCANNER_LITERAL_IS_CONST)) + { + type = SCANNER_STREAM_TYPE_LET; + + if ((status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) && (literal_p->type & SCANNER_LITERAL_NO_REG)) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + } +#if JERRY_MODULE_SYSTEM + else if (prev_literal_pool_p == NULL) + { + type = SCANNER_STREAM_TYPE_IMPORT; + } +#endif /* JERRY_MODULE_SYSTEM */ + else + { + type = SCANNER_STREAM_TYPE_LOCAL; + } + } + else if (literal_p->type & SCANNER_LITERAL_IS_CONST) + { + type = SCANNER_STREAM_TYPE_CONST; + + if ((status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) && (literal_p->type & SCANNER_LITERAL_NO_REG)) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + } + + if (literal_p->type & SCANNER_LITERAL_EARLY_CREATE) + { + type |= SCANNER_STREAM_NO_REG | SCANNER_STREAM_EARLY_CREATE; + } + + if (literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE) + { + type |= SCANNER_STREAM_HAS_ESCAPE; + } + + if ((literal_p->type & SCANNER_LITERAL_NO_REG) + || (mapped_arguments && (literal_p->type & SCANNER_LITERAL_IS_ARG))) + { + type |= SCANNER_STREAM_NO_REG; + } + + data_p[0] = type; + data_p[1] = (uint8_t) literal_p->length; + data_p += 3; + + intptr_t diff = (intptr_t) (literal_p->char_p - prev_source_p); + + if (diff >= 1 && diff <= (intptr_t) UINT8_MAX) + { + data_p[-1] = (uint8_t) diff; + } + else if (diff >= -(intptr_t) UINT8_MAX && diff <= (intptr_t) UINT16_MAX) + { + if (diff < 0) + { + diff = -diff; + } + + data_p[-3] |= SCANNER_STREAM_UINT16_DIFF; + data_p[-1] = (uint8_t) diff; + data_p[0] = (uint8_t) (diff >> 8); + data_p += 1; + } + else + { + data_p[-1] = 0; + memcpy (data_p, &literal_p->char_p, sizeof (uintptr_t)); + data_p += sizeof (uintptr_t); + } + + if (literal_p == last_argument_p) + { + *data_p++ = arguments_stream_type; + } + + prev_source_p = literal_p->char_p + literal_p->length; + } + + data_p[0] = SCANNER_STREAM_TYPE_END; + + JERRY_ASSERT (((uint8_t *) info_p) + compressed_size == data_p + 1); + } + + if (!(status_flags & SCANNER_LITERAL_POOL_FUNCTION) + && (int32_t) prev_literal_pool_p->no_declarations < no_declarations) + { + prev_literal_pool_p->no_declarations = (uint16_t) no_declarations; + } + + if ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) && prev_literal_pool_p != NULL) + { + if (prev_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IS_STRICT) + { + context_p->status_flags |= PARSER_IS_STRICT; + } + else + { + context_p->status_flags &= (uint32_t) ~PARSER_IS_STRICT; + } + + if (prev_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_GENERATOR) + { + context_p->status_flags |= PARSER_IS_GENERATOR_FUNCTION; + } + else + { + context_p->status_flags &= (uint32_t) ~PARSER_IS_GENERATOR_FUNCTION; + } + + if (prev_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_ASYNC) + { + context_p->status_flags |= PARSER_IS_ASYNC_FUNCTION; + } + else + { + context_p->status_flags &= (uint32_t) ~PARSER_IS_ASYNC_FUNCTION; + } + } + + scanner_context_p->active_literal_pool_p = literal_pool_p->prev_p; + + parser_list_free (&literal_pool_p->literal_pool); + scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t)); +} /* scanner_pop_literal_pool */ + +/** + * Filter out the arguments from a literal pool. + */ +void +scanner_filter_arguments (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + /* Fast case: check whether all literals are arguments. */ + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + scanner_literal_pool_t *prev_literal_pool_p = literal_pool_p->prev_p; + parser_list_iterator_t literal_iterator; + lexer_lit_location_t *literal_p; + bool can_eval = (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) != 0; + bool has_arguments = (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_NO_ARGUMENTS) == 0; + + JERRY_ASSERT (SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS (literal_pool_p->status_flags)); + + if (JERRY_UNLIKELY (can_eval)) + { + if (prev_literal_pool_p != NULL) + { + prev_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CAN_EVAL; + } + + literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_CAN_EVAL; + } + else + { + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + + while (true) + { + literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator); + + if (literal_p == NULL) + { + return; + } + + if (can_eval || (literal_p->type & SCANNER_LITERAL_EARLY_CREATE)) + { + literal_p->type |= SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_EARLY_CREATE; + } + + uint8_t type = literal_p->type; + const uint8_t mask = + (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG); + + if ((type & mask) != SCANNER_LITERAL_IS_ARG) + { + break; + } + } + } + + /* Destructured args are placed after the other arguments because of register assignments. */ + bool has_destructured_arg = false; + scanner_literal_pool_t *new_literal_pool_p; + + new_literal_pool_p = (scanner_literal_pool_t *) scanner_malloc (context_p, sizeof (scanner_literal_pool_t)); + + new_literal_pool_p->prev_p = literal_pool_p; + scanner_context_p->active_literal_pool_p = new_literal_pool_p; + + *new_literal_pool_p = *literal_pool_p; + parser_list_init (&new_literal_pool_p->literal_pool, + sizeof (lexer_lit_location_t), + (uint32_t) ((128 - sizeof (void *)) / sizeof (lexer_lit_location_t))); + + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + uint8_t type = literal_p->type; + + if (type & SCANNER_LITERAL_IS_ARG) + { + if (can_eval || (literal_p->type & SCANNER_LITERAL_EARLY_CREATE)) + { + type |= SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_EARLY_CREATE; + literal_p->type = type; + } + + if (has_arguments && scanner_literal_is_arguments (literal_p)) + { + has_arguments = false; + } + + if (type & (SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG)) + { + has_destructured_arg = true; + + if (type & SCANNER_LITERAL_IS_DESTRUCTURED_ARG) + { + continue; + } + + type &= (uint8_t) ~SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG; + type |= SCANNER_LITERAL_IS_DESTRUCTURED_ARG; + + literal_p->type = type; + continue; + } + + lexer_lit_location_t *new_literal_p; + new_literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &new_literal_pool_p->literal_pool); + *new_literal_p = *literal_p; + } + else if (has_arguments && scanner_literal_is_arguments (literal_p)) + { + /* Arguments object is directly referenced from the function arguments */ + new_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS; + + if (type & SCANNER_LITERAL_NO_REG) + { + new_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_NO_ARGUMENTS; + } + } + else if (prev_literal_pool_p != NULL) + { + /* Propagate literal to upper level. */ + lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p, prev_literal_pool_p, literal_p); + type |= SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_IS_USED; + literal_location_p->type |= type; + } + } + + if (has_destructured_arg) + { + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + const uint8_t expected_flags = SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG; + + if ((literal_p->type & expected_flags) == expected_flags) + { + lexer_lit_location_t *new_literal_p; + new_literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &new_literal_pool_p->literal_pool); + *new_literal_p = *literal_p; + } + } + } + + if (has_arguments) + { + /* Force the lexically stored arguments object creation */ + new_literal_pool_p->status_flags |= (SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS | SCANNER_LITERAL_POOL_NO_ARGUMENTS); + } + + new_literal_pool_p->prev_p = prev_literal_pool_p; + + parser_list_free (&literal_pool_p->literal_pool); + scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t)); +} /* scanner_filter_arguments */ + +/** + * Add any literal to the specified literal pool. + * + * @return pointer to the literal + */ +lexer_lit_location_t * +scanner_add_custom_literal (parser_context_t *context_p, /**< context */ + scanner_literal_pool_t *literal_pool_p, /**< literal pool */ + const lexer_lit_location_t *literal_location_p) /**< literal */ +{ + while (true) + { + parser_list_iterator_t literal_iterator; + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + lexer_lit_location_t *literal_p; + + const uint8_t *char_p = literal_location_p->char_p; + prop_length_t length = literal_location_p->length; + + if (JERRY_LIKELY (!(literal_location_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (literal_p->length == length) + { + if (JERRY_LIKELY (!(literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + if (memcmp (literal_p->char_p, char_p, length) == 0) + { + return literal_p; + } + } + else if (lexer_compare_identifier_to_string (literal_p, char_p, length)) + { + /* The non-escaped version is preferred. */ + literal_p->char_p = char_p; + literal_p->status_flags = LEXER_LIT_LOCATION_NO_OPTS; + return literal_p; + } + } + } + } + else + { + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (lexer_compare_identifiers (context_p, literal_p, literal_location_p)) + { + return literal_p; + } + } + } + + if (JERRY_UNLIKELY (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME)) + { + literal_pool_p = literal_pool_p->prev_p; + continue; + } + + literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &literal_pool_p->literal_pool); + *literal_p = *literal_location_p; + + literal_p->type = 0; + + return literal_p; + } +} /* scanner_add_custom_literal */ + +/** + * Add the current literal token to the current literal pool. + * + * @return pointer to the literal + */ +lexer_lit_location_t * +scanner_add_literal (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + return scanner_add_custom_literal (context_p, + scanner_context_p->active_literal_pool_p, + &context_p->token.lit_location); +} /* scanner_add_literal */ + +/** + * Add the current literal token to the current literal pool and + * set SCANNER_LITERAL_NO_REG if it is inside a with statement. + * + * @return pointer to the literal + */ +void +scanner_add_reference (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &context_p->token.lit_location); + lit_location_p->type |= SCANNER_LITERAL_IS_USED; + + if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) + { + lit_location_p->type |= SCANNER_LITERAL_NO_REG; + } + + scanner_detect_eval_call (context_p, scanner_context_p); +} /* scanner_add_reference */ + +/** + * Append an argument to the literal pool. If the argument is already present, make it a "hole". + * + * @return newly created literal + */ +lexer_lit_location_t * +scanner_append_argument (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + parser_list_iterator_t literal_iterator; + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + lexer_lit_location_t *literal_location_p = &context_p->token.lit_location; + lexer_lit_location_t *literal_p; + + const uint8_t *char_p = literal_location_p->char_p; + prop_length_t length = literal_location_p->length; + + JERRY_ASSERT (SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS (literal_pool_p->status_flags)); + + if (JERRY_LIKELY (!(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (literal_p->length == length) + { + if (JERRY_LIKELY (!(literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + if (memcmp (literal_p->char_p, char_p, length) == 0) + { + break; + } + } + else if (lexer_compare_identifier_to_string (literal_p, char_p, length)) + { + break; + } + } + } + } + else + { + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if (lexer_compare_identifiers (context_p, literal_p, literal_location_p)) + { + break; + } + } + } + + uint8_t literal_type = SCANNER_LITERAL_IS_ARG; + + if (literal_p != NULL) + { + literal_p->length = 0; + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_type = SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_EARLY_CREATE; + } + } + + literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &literal_pool_p->literal_pool); + + *literal_p = context_p->token.lit_location; + literal_p->type = literal_type; + + return literal_p; +} /* scanner_append_argument */ + +/** + * Add private identifiers to private ident pool + */ +void +scanner_add_private_identifier (parser_context_t *context_p, /**< context */ + scanner_private_field_flags_t opts) /**< options */ +{ + scan_stack_modes_t stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; + parser_stack_pop_uint8 (context_p); + scanner_class_info_t *class_info_p; + parser_stack_pop (context_p, &class_info_p, sizeof (scanner_class_info_t *)); + + scanner_class_private_member_t *iter = class_info_p->members; + + scanner_private_field_flags_t search_flag = + (((unsigned int) opts & (unsigned int) SCANNER_PRIVATE_FIELD_PROPERTY) ? SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER + : (scanner_private_field_flags_t) ((unsigned int) opts & (unsigned int) SCANNER_PRIVATE_FIELD_GETTER_SETTER)); + + while (iter != NULL) + { + if (lexer_compare_identifiers (context_p, &context_p->token.lit_location, &iter->loc) + && (iter->u8_arg & search_flag)) + { + scanner_raise_error (context_p); + } + + iter = iter->prev_p; + } + + scanner_class_private_member_t *p_member; + p_member = (scanner_class_private_member_t *) scanner_malloc (context_p, sizeof (scanner_class_private_member_t)); + p_member->loc = context_p->token.lit_location; + p_member->u8_arg = (uint8_t) opts; + p_member->prev_p = class_info_p->members; + class_info_p->members = p_member; + + parser_stack_push (context_p, &class_info_p, sizeof (scanner_class_info_t *)); + parser_stack_push_uint8 (context_p, (uint8_t) stack_top); +} /* scanner_add_private_identifier */ + +/** + * Check whether an eval call is performed and update the status flags accordingly. + */ +void +scanner_detect_eval_call (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /**< scanner context */ +{ + if (context_p->token.keyword_type == LEXER_KEYW_EVAL && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + { + scanner_context_p->active_literal_pool_p->status_flags |= + (SCANNER_LITERAL_POOL_CAN_EVAL | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE); + } +} /* scanner_detect_eval_call */ + +/** + * Throws an error for invalid var statements. + */ +void +scanner_detect_invalid_var (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + lexer_lit_location_t *var_literal_p) /**< var literal */ +{ + if (var_literal_p->type & SCANNER_LITERAL_IS_LOCAL + && !(var_literal_p->type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_ARG)) + && (var_literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL) + { + scanner_raise_redeclaration_error (context_p); + } + + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + + if (!(literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION) + && ((var_literal_p->type & SCANNER_LITERAL_IS_LOCAL_FUNC) == SCANNER_LITERAL_IS_LOCAL_FUNC)) + { + scanner_raise_redeclaration_error (context_p); + } + + const uint8_t *char_p = var_literal_p->char_p; + prop_length_t length = var_literal_p->length; + + while (!(literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)) + { + literal_pool_p = literal_pool_p->prev_p; + + parser_list_iterator_t literal_iterator; + parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator); + lexer_lit_location_t *literal_p; + + if (JERRY_LIKELY (!(context_p->token.lit_location.status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) && !(literal_p->type & SCANNER_LITERAL_IS_ARG) + && !((literal_p->type & SCANNER_LITERAL_IS_FUNC) + && (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)) + && (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL && literal_p->length == length) + { + if (JERRY_LIKELY (!(literal_p->status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE))) + { + if (memcmp (literal_p->char_p, char_p, length) == 0) + { + scanner_raise_redeclaration_error (context_p); + return; + } + } + else if (lexer_compare_identifier_to_string (literal_p, char_p, length)) + { + scanner_raise_redeclaration_error (context_p); + return; + } + } + } + } + else + { + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) && !(literal_p->type & SCANNER_LITERAL_IS_ARG) + && !((literal_p->type & SCANNER_LITERAL_IS_FUNC) + && (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)) + && (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL + && lexer_compare_identifiers (context_p, literal_p, var_literal_p)) + { + scanner_raise_redeclaration_error (context_p); + return; + } + } + } + } + + if (scanner_scope_find_lexical_declaration (context_p, var_literal_p)) + { + scanner_raise_redeclaration_error (context_p); + } +} /* scanner_detect_invalid_var */ + +/** + * Throws an error for invalid let statements. + */ +void +scanner_detect_invalid_let (parser_context_t *context_p, /**< context */ + lexer_lit_location_t *let_literal_p) /**< let literal */ +{ + if (let_literal_p->type & (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_LOCAL)) + { + scanner_raise_redeclaration_error (context_p); + } + + if (let_literal_p->type & SCANNER_LITERAL_IS_FUNC) + { + let_literal_p->type &= (uint8_t) ~SCANNER_LITERAL_IS_FUNC; + } +} /* scanner_detect_invalid_let */ + +/** + * Push the values required for class declaration parsing. + * + * @return literal reference created for class statements, NULL otherwise + */ +lexer_lit_location_t * +scanner_push_class_declaration (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /* scanner context */ + uint8_t stack_mode) /**< stack mode */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS); + + const uint8_t *source_p = context_p->source_p; + lexer_lit_location_t *literal_p = NULL; + +#if JERRY_MODULE_SYSTEM + bool is_export_default = context_p->stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT; + JERRY_ASSERT (!is_export_default || stack_mode == SCAN_STACK_CLASS_EXPRESSION); +#endif /* JERRY_MODULE_SYSTEM */ + + parser_stack_push_uint8 (context_p, stack_mode); + lexer_next_token (context_p); + + bool class_has_name = + (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + if (class_has_name) + { + literal_p = scanner_add_literal (context_p, scanner_context_p); + scanner_context_p->active_literal_pool_p->no_declarations++; + +#if JERRY_MODULE_SYSTEM + if (is_export_default) + { + scanner_detect_invalid_let (context_p, literal_p); + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + + literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG; + } +#endif /* JERRY_MODULE_SYSTEM */ + } + + scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + + if (class_has_name) + { + scanner_add_literal (context_p, scanner_context_p); + scanner_context_p->active_literal_pool_p->no_declarations++; + } +#if JERRY_MODULE_SYSTEM + else if (is_export_default) + { + lexer_lit_location_t *name_literal_p; + name_literal_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p->prev_p, &lexer_default_literal); + + name_literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG; + scanner_context_p->active_literal_pool_p->no_declarations++; + } +#endif /* JERRY_MODULE_SYSTEM */ + + literal_pool_p->source_p = source_p; + literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CLASS_NAME; + + const uint8_t *class_source_p = scanner_context_p->active_literal_pool_p->source_p; + scanner_class_info_t *class_info_p = + (scanner_class_info_t *) scanner_insert_info (context_p, class_source_p, sizeof (scanner_class_info_t)); + + class_info_p->info.type = SCANNER_TYPE_CLASS_CONSTRUCTOR; + class_info_p->members = NULL; + class_info_p->info.u8_arg = SCANNER_CONSTRUCTOR_IMPLICIT; + + parser_stack_push (context_p, &class_info_p, sizeof (scanner_class_info_t *)); + parser_stack_push_uint8 (context_p, SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR); + scanner_context_p->mode = SCAN_MODE_CLASS_DECLARATION; + + return literal_p; +} /* scanner_push_class_declaration */ + +/** + * Push the start of a class field initializer. + */ +void +scanner_push_class_field_initializer (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /* scanner context */ +{ + scanner_source_start_t source_start; + source_start.source_p = context_p->source_p; + + parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_FIELD_INITIALIZER); + + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_CLASS_FIELD); + literal_pool_p->source_p = context_p->source_p; + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; +} /* scanner_push_class_field_initializer */ + +/** + * Push the values required for destructuring assignment or binding parsing. + */ +void +scanner_push_destructuring_pattern (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + uint8_t binding_type, /**< type of destructuring binding pattern */ + bool is_nested) /**< nested declaration */ +{ + JERRY_ASSERT (binding_type != SCANNER_BINDING_NONE || !is_nested); + + scanner_source_start_t source_start; + source_start.source_p = context_p->source_p; + + parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t)); + parser_stack_push_uint8 (context_p, scanner_context_p->binding_type); + scanner_context_p->binding_type = binding_type; + + if (SCANNER_NEEDS_BINDING_LIST (binding_type)) + { + scanner_binding_list_t *binding_list_p; + binding_list_p = (scanner_binding_list_t *) scanner_malloc (context_p, sizeof (scanner_binding_list_t)); + + binding_list_p->prev_p = scanner_context_p->active_binding_list_p; + binding_list_p->items_p = NULL; + binding_list_p->is_nested = is_nested; + + scanner_context_p->active_binding_list_p = binding_list_p; + } +} /* scanner_push_destructuring_pattern */ + +/** + * Pop binding list. + */ +void +scanner_pop_binding_list (scanner_context_t *scanner_context_p) /**< scanner context */ +{ + scanner_binding_list_t *binding_list_p = scanner_context_p->active_binding_list_p; + JERRY_ASSERT (binding_list_p != NULL); + + scanner_binding_item_t *item_p = binding_list_p->items_p; + scanner_binding_list_t *prev_binding_list_p = binding_list_p->prev_p; + bool is_nested = binding_list_p->is_nested; + + scanner_free (binding_list_p, sizeof (scanner_binding_list_t)); + scanner_context_p->active_binding_list_p = prev_binding_list_p; + + if (!is_nested) + { + while (item_p != NULL) + { + scanner_binding_item_t *next_p = item_p->next_p; + + JERRY_ASSERT (item_p->literal_p->type & (SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_IS_ARG)); + + scanner_free (item_p, sizeof (scanner_binding_item_t)); + item_p = next_p; + } + return; + } + + JERRY_ASSERT (prev_binding_list_p != NULL); + + while (item_p != NULL) + { + scanner_binding_item_t *next_p = item_p->next_p; + + item_p->next_p = prev_binding_list_p->items_p; + prev_binding_list_p->items_p = item_p; + + item_p = next_p; + } +} /* scanner_pop_binding_list */ + +/** + * Append a hole into the literal pool. + */ +void +scanner_append_hole (parser_context_t *context_p, scanner_context_t *scanner_context_p) +{ + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + + lexer_lit_location_t *literal_p; + literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &literal_pool_p->literal_pool); + + literal_p->char_p = NULL; + literal_p->length = 0; + literal_p->type = SCANNER_LITERAL_IS_ARG; + literal_p->status_flags = LEXER_LIT_LOCATION_NO_OPTS; +} /* scanner_append_hole */ + +/** + * Reverse the scanner info chain after the scanning is completed. + */ +void +scanner_reverse_info_list (parser_context_t *context_p) /**< context */ +{ + scanner_info_t *scanner_info_p = context_p->next_scanner_info_p; + scanner_info_t *last_scanner_info_p = NULL; + + if (scanner_info_p->type == SCANNER_TYPE_END) + { + return; + } + + do + { + scanner_info_t *next_scanner_info_p = scanner_info_p->next_p; + scanner_info_p->next_p = last_scanner_info_p; + + last_scanner_info_p = scanner_info_p; + scanner_info_p = next_scanner_info_p; + } while (scanner_info_p->type != SCANNER_TYPE_END); + + context_p->next_scanner_info_p->next_p = scanner_info_p; + context_p->next_scanner_info_p = last_scanner_info_p; +} /* scanner_reverse_info_list */ + +/** + * Release unused scanner info blocks. + * This should happen only if an error is occurred. + */ +void +scanner_cleanup (parser_context_t *context_p) /**< context */ +{ + if (context_p->skipped_scanner_info_p != NULL) + { + context_p->skipped_scanner_info_end_p->next_p = context_p->next_scanner_info_p; + context_p->next_scanner_info_p = context_p->skipped_scanner_info_p; + context_p->skipped_scanner_info_p = NULL; + } + + scanner_info_t *scanner_info_p = context_p->next_scanner_info_p; + + while (scanner_info_p != NULL) + { + scanner_info_t *next_scanner_info_p = scanner_info_p->next_p; + + size_t size = sizeof (scanner_info_t); + + switch (scanner_info_p->type) + { + case SCANNER_TYPE_END: + { + scanner_info_p = context_p->active_scanner_info_p; + continue; + } + case SCANNER_TYPE_FUNCTION: + case SCANNER_TYPE_BLOCK: + { + size = scanner_get_stream_size (scanner_info_p, sizeof (scanner_info_t)); + break; + } + case SCANNER_TYPE_WHILE: + case SCANNER_TYPE_FOR_IN: + case SCANNER_TYPE_FOR_OF: + case SCANNER_TYPE_CASE: + case SCANNER_TYPE_INITIALIZER: + case SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END: + case SCANNER_TYPE_CLASS_STATIC_BLOCK_END: + { + size = sizeof (scanner_location_info_t); + break; + } + case SCANNER_TYPE_FOR: + { + size = sizeof (scanner_for_info_t); + break; + } + case SCANNER_TYPE_SWITCH: + { + scanner_release_switch_cases (((scanner_switch_info_t *) scanner_info_p)->case_p); + size = sizeof (scanner_switch_info_t); + break; + } + case SCANNER_TYPE_CLASS_CONSTRUCTOR: + { + scanner_release_private_fields (((scanner_class_info_t *) scanner_info_p)->members); + size = sizeof (scanner_class_info_t); + break; + } + default: + { + JERRY_ASSERT ( + scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS || scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS + || scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION || scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED + || scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION + || scanner_info_p->type == SCANNER_TYPE_EXPORT_MODULE_SPECIFIER); + break; + } + } + + scanner_free (scanner_info_p, size); + scanner_info_p = next_scanner_info_p; + } + + context_p->next_scanner_info_p = NULL; + context_p->active_scanner_info_p = NULL; +} /* scanner_cleanup */ + +/** + * Checks whether a context needs to be created for a block. + * + * @return true - if context is needed, + * false - otherwise + */ +bool +scanner_is_context_needed (parser_context_t *context_p, /**< context */ + parser_check_context_type_t check_type) /**< context type */ +{ + scanner_info_t *info_p = context_p->next_scanner_info_p; + const uint8_t *data_p = (const uint8_t *) (info_p + 1); + + JERRY_UNUSED (check_type); + + JERRY_ASSERT ((check_type == PARSER_CHECK_BLOCK_CONTEXT ? info_p->type == SCANNER_TYPE_BLOCK + : info_p->type == SCANNER_TYPE_FUNCTION)); + + uint32_t scope_stack_reg_top = + (check_type != PARSER_CHECK_GLOBAL_CONTEXT ? context_p->scope_stack_reg_top : 1); /* block result */ + + while (data_p[0] != SCANNER_STREAM_TYPE_END) + { + uint8_t data = data_p[0]; + uint32_t type = data & SCANNER_STREAM_TYPE_MASK; + + if (JERRY_UNLIKELY (check_type == PARSER_CHECK_FUNCTION_CONTEXT)) + { + if (JERRY_UNLIKELY (type == SCANNER_STREAM_TYPE_HOLE)) + { + data_p++; + continue; + } + + if (JERRY_UNLIKELY (SCANNER_STREAM_TYPE_IS_ARGUMENTS (type))) + { + if ((data & SCANNER_STREAM_NO_REG) || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + return true; + } + + scope_stack_reg_top++; + data_p++; + continue; + } + } + +#ifndef JERRY_NDEBUG + if (check_type == PARSER_CHECK_BLOCK_CONTEXT) + { + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_LET + || type == SCANNER_STREAM_TYPE_CONST || type == SCANNER_STREAM_TYPE_LOCAL + || type == SCANNER_STREAM_TYPE_FUNC); + } + else if (check_type == PARSER_CHECK_GLOBAL_CONTEXT) + { +#if JERRY_MODULE_SYSTEM + const bool is_import = (type == SCANNER_STREAM_TYPE_IMPORT); +#else /* !JERRY_MODULE_SYSTEM */ + const bool is_import = true; +#endif /* JERRY_MODULE_SYSTEM */ + + /* FIXME: a private declarative lexical environment should always be present + * for modules. Remove SCANNER_STREAM_TYPE_IMPORT after it is implemented. */ + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_LET + || type == SCANNER_STREAM_TYPE_CONST || type == SCANNER_STREAM_TYPE_FUNC || is_import); + + /* Only let/const can be stored in registers */ + JERRY_ASSERT ((data & SCANNER_STREAM_NO_REG) + || (type == SCANNER_STREAM_TYPE_FUNC && (context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL)) + || type == SCANNER_STREAM_TYPE_LET || type == SCANNER_STREAM_TYPE_CONST); + } + else + { + JERRY_ASSERT (check_type == PARSER_CHECK_FUNCTION_CONTEXT); + + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_LET + || type == SCANNER_STREAM_TYPE_CONST || type == SCANNER_STREAM_TYPE_LOCAL + || type == SCANNER_STREAM_TYPE_ARG || type == SCANNER_STREAM_TYPE_ARG_VAR + || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR + || type == SCANNER_STREAM_TYPE_ARG_FUNC || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC + || type == SCANNER_STREAM_TYPE_FUNC); + } +#endif /* !JERRY_NDEBUG */ + if (!(data & SCANNER_STREAM_UINT16_DIFF)) + { + if (data_p[2] != 0) + { + data_p += 2 + 1; + } + else + { + data_p += 2 + 1 + sizeof (const uint8_t *); + } + } + else + { + data_p += 2 + 2; + } + +#if JERRY_MODULE_SYSTEM + const bool is_import = (type == SCANNER_STREAM_TYPE_IMPORT); +#else /* !JERRY_MODULE_SYSTEM */ + const bool is_import = false; +#endif /* JERRY_MODULE_SYSTEM */ + + if (JERRY_UNLIKELY (check_type == PARSER_CHECK_GLOBAL_CONTEXT) + && (type == SCANNER_STREAM_TYPE_VAR + || (type == SCANNER_STREAM_TYPE_FUNC && !(context_p->global_status_flags & ECMA_PARSE_EVAL)) || is_import)) + { + continue; + } + + if (JERRY_UNLIKELY (check_type == PARSER_CHECK_FUNCTION_CONTEXT)) + { + if (SCANNER_STREAM_TYPE_IS_ARG_FUNC (type) || type == SCANNER_STREAM_TYPE_ARG_VAR + || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR) + { + /* The return value is true, if the variable is stored in the lexical environment + * or all registers have already been used for function arguments. This can be + * imprecise in the latter case, but this is a very rare corner case. A more + * sophisticated check would require to decode the literal. */ + if ((data & SCANNER_STREAM_NO_REG) || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + return true; + } + continue; + } + + if (SCANNER_STREAM_TYPE_IS_ARG (type)) + { + continue; + } + } + + if ((data & SCANNER_STREAM_NO_REG) || scope_stack_reg_top >= PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + return true; + } + + scope_stack_reg_top++; + } + + return false; +} /* scanner_is_context_needed */ + +/** + * Try to scan/parse the ".target" part in the "new.target" expression. + * + * Upon exiting with "true" the current token will point to the "target" + * literal. + * + * If the "target" literal is not after the "new." then a scanner/parser + * error will be raised. + * + * @returns true if the ".target" part was found + * false if there is no "." after the new. + */ +bool +scanner_try_scan_new_target (parser_context_t *context_p) /**< parser/scanner context */ +{ + JERRY_ASSERT (context_p->token.type == LEXER_KEYW_NEW); + + if (lexer_check_next_character (context_p, LIT_CHAR_DOT)) + { + lexer_next_token (context_p); + if (context_p->token.type != LEXER_DOT) + { + parser_raise_error (context_p, PARSER_ERR_INVALID_CHARACTER); + } + + lexer_next_token (context_p); + if (!lexer_token_is_identifier (context_p, "target", 6)) + { + parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_EXPECTED); + } + + return true; + } + return false; +} /* scanner_try_scan_new_target */ + +/** + * Description of "arguments" literal string. + */ +const lexer_lit_location_t lexer_arguments_literal = { (const uint8_t *) "arguments", + 9, + LEXER_IDENT_LITERAL, + LEXER_LIT_LOCATION_IS_ASCII }; + +/** + * Create an unused literal. + */ +static void +scanner_create_unused_literal (parser_context_t *context_p, /**< context */ + uint8_t status_flags) /**< initial status flags */ +{ + if (JERRY_UNLIKELY (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS)) + { + parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED); + } + + lexer_literal_t *literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool); + + literal_p->type = LEXER_UNUSED_LITERAL; + literal_p->status_flags = status_flags; + + context_p->literal_count++; +} /* scanner_create_unused_literal */ + +/** + * Emit checks for redeclared bindings in the global lexical scope. + */ +void +scanner_check_variables (parser_context_t *context_p) /**< context */ +{ + scanner_info_t *info_p = context_p->next_scanner_info_p; + const uint8_t *next_data_p = (const uint8_t *) (info_p + 1); + lexer_lit_location_t literal; + + JERRY_ASSERT (info_p->type == SCANNER_TYPE_FUNCTION); + + literal.char_p = info_p->source_p - 1; + + while (next_data_p[0] != SCANNER_STREAM_TYPE_END) + { + uint32_t type = next_data_p[0] & SCANNER_STREAM_TYPE_MASK; + const uint8_t *data_p = next_data_p; + + JERRY_ASSERT (type != SCANNER_STREAM_TYPE_HOLE && !SCANNER_STREAM_TYPE_IS_ARG (type) + && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type)); + JERRY_ASSERT (data_p[0] & SCANNER_STREAM_NO_REG); + + if (!(data_p[0] & SCANNER_STREAM_UINT16_DIFF)) + { + if (data_p[2] != 0) + { + literal.char_p += data_p[2]; + next_data_p += 2 + 1; + } + else + { + memcpy (&literal.char_p, data_p + 2 + 1, sizeof (uintptr_t)); + next_data_p += 2 + 1 + sizeof (uintptr_t); + } + } + else + { + int32_t diff = ((int32_t) data_p[2]) | ((int32_t) data_p[3]) << 8; + + if (diff <= (intptr_t) UINT8_MAX) + { + diff = -diff; + } + + literal.char_p += diff; + next_data_p += 2 + 2; + } + + literal.length = data_p[1]; + literal.type = LEXER_IDENT_LITERAL; + literal.status_flags = + ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE : LEXER_LIT_LOCATION_NO_OPTS); + + lexer_construct_literal_object (context_p, &literal, LEXER_NEW_IDENT_LITERAL); + literal.char_p += data_p[1]; + +#if JERRY_MODULE_SYSTEM + if (type == SCANNER_STREAM_TYPE_IMPORT) + { + continue; + } +#endif /* JERRY_MODULE_SYSTEM */ + + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED; + + uint16_t opcode; + if (type == SCANNER_STREAM_TYPE_VAR || type == SCANNER_STREAM_TYPE_FUNC) + { + opcode = CBC_CHECK_VAR; + } + else + { + opcode = CBC_CHECK_LET; + } + + parser_emit_cbc_literal (context_p, opcode, context_p->lit_object.index); + } + + parser_flush_cbc (context_p); +} /* scanner_check_variables */ + +/** + * Create and/or initialize var/let/const/function/etc. variables. + */ +void +scanner_create_variables (parser_context_t *context_p, /**< context */ + uint32_t option_flags) /**< combination of scanner_create_variables_flags_t bits */ +{ + scanner_info_t *info_p = context_p->next_scanner_info_p; + const uint8_t *next_data_p = (const uint8_t *) (info_p + 1); + uint8_t info_type = info_p->type; + uint8_t info_u8_arg = info_p->u8_arg; + lexer_lit_location_t literal; + parser_scope_stack_t *scope_stack_p; + parser_scope_stack_t *scope_stack_end_p; + + JERRY_ASSERT (info_type == SCANNER_TYPE_FUNCTION || info_type == SCANNER_TYPE_BLOCK); + JERRY_ASSERT (!(option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_ARGS) + || !(option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_BODY)); + JERRY_ASSERT (info_type == SCANNER_TYPE_FUNCTION + || !(option_flags & (SCANNER_CREATE_VARS_IS_FUNCTION_ARGS | SCANNER_CREATE_VARS_IS_FUNCTION_BODY))); + + uint32_t scope_stack_reg_top = context_p->scope_stack_reg_top; + + if (info_type == SCANNER_TYPE_FUNCTION && !(option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_BODY)) + { + JERRY_ASSERT (context_p->scope_stack_p == NULL); + + size_t stack_size = info_p->u16_arg * sizeof (parser_scope_stack_t); + context_p->scope_stack_size = info_p->u16_arg; + + scope_stack_p = NULL; + + if (stack_size > 0) + { + scope_stack_p = (parser_scope_stack_t *) parser_malloc (context_p, stack_size); + } + + context_p->scope_stack_p = scope_stack_p; + scope_stack_end_p = scope_stack_p + context_p->scope_stack_size; + + if (option_flags & (SCANNER_CREATE_VARS_IS_SCRIPT | SCANNER_CREATE_VARS_IS_MODULE)) + { + scope_stack_reg_top++; /* block result */ + } + } + else + { + JERRY_ASSERT (context_p->scope_stack_p != NULL || context_p->scope_stack_size == 0); + + scope_stack_p = context_p->scope_stack_p; + scope_stack_end_p = scope_stack_p + context_p->scope_stack_size; + scope_stack_p += context_p->scope_stack_top; + } + + literal.char_p = info_p->source_p - 1; + + while (next_data_p[0] != SCANNER_STREAM_TYPE_END) + { + uint32_t type = next_data_p[0] & SCANNER_STREAM_TYPE_MASK; + const uint8_t *data_p = next_data_p; + + JERRY_ASSERT ((option_flags & (SCANNER_CREATE_VARS_IS_FUNCTION_BODY | SCANNER_CREATE_VARS_IS_FUNCTION_ARGS)) + || (type != SCANNER_STREAM_TYPE_HOLE && !SCANNER_STREAM_TYPE_IS_ARG (type) + && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type))); + +#if JERRY_MODULE_SYSTEM + JERRY_ASSERT (type != SCANNER_STREAM_TYPE_IMPORT || (data_p[0] & SCANNER_STREAM_NO_REG)); +#endif /* JERRY_MODULE_SYSTEM */ + + if (JERRY_UNLIKELY (type == SCANNER_STREAM_TYPE_HOLE)) + { + JERRY_ASSERT (info_type == SCANNER_TYPE_FUNCTION); + next_data_p++; + + if (option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_BODY) + { + continue; + } + + uint8_t mask = SCANNER_FUNCTION_ARGUMENTS_NEEDED | SCANNER_FUNCTION_HAS_COMPLEX_ARGUMENT; + + if (!(context_p->status_flags & PARSER_IS_STRICT) && (info_u8_arg & mask) == SCANNER_FUNCTION_ARGUMENTS_NEEDED) + { + scanner_create_unused_literal (context_p, LEXER_FLAG_FUNCTION_ARGUMENT); + } + + if (scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + scope_stack_reg_top++; + } + continue; + } + + if (JERRY_UNLIKELY (SCANNER_STREAM_TYPE_IS_ARGUMENTS (type))) + { + JERRY_ASSERT (info_type == SCANNER_TYPE_FUNCTION); + next_data_p++; + + if (option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_BODY) + { + continue; + } + + context_p->status_flags |= PARSER_ARGUMENTS_NEEDED; + + if (JERRY_UNLIKELY (scope_stack_p >= scope_stack_end_p)) + { + JERRY_ASSERT (context_p->scope_stack_size == PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK); + parser_raise_error (context_p, PARSER_ERR_SCOPE_STACK_LIMIT_REACHED); + } + + lexer_construct_literal_object (context_p, &lexer_arguments_literal, LEXER_NEW_IDENT_LITERAL); + scope_stack_p->map_from = context_p->lit_object.index; + + uint16_t map_to; + + if (!(data_p[0] & SCANNER_STREAM_NO_REG) && scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + map_to = (uint16_t) (PARSER_REGISTER_START + scope_stack_reg_top); + + scope_stack_p->map_to = (uint16_t) (scope_stack_reg_top + 1); + scope_stack_reg_top++; + } + else + { + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED; + map_to = context_p->lit_object.index; + + context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED; + + if (data_p[0] & SCANNER_STREAM_LOCAL_ARGUMENTS) + { + context_p->status_flags |= PARSER_LEXICAL_BLOCK_NEEDED; + } + + scope_stack_p->map_to = 0; + } + + scope_stack_p++; + +#if JERRY_PARSER_DUMP_BYTE_CODE + context_p->scope_stack_top = (uint16_t) (scope_stack_p - context_p->scope_stack_p); +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_emit_cbc_ext_literal (context_p, CBC_EXT_CREATE_ARGUMENTS, map_to); + + if (type == SCANNER_STREAM_TYPE_ARGUMENTS_FUNC) + { + if (JERRY_UNLIKELY (scope_stack_p >= scope_stack_end_p)) + { + JERRY_ASSERT (context_p->scope_stack_size == PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK); + parser_raise_error (context_p, PARSER_ERR_SCOPE_STACK_LIMIT_REACHED); + } + + scope_stack_p->map_from = PARSER_SCOPE_STACK_FUNC; + scope_stack_p->map_to = context_p->literal_count; + scope_stack_p++; + + scanner_create_unused_literal (context_p, 0); + } + + if (option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_ARGS) + { + break; + } + continue; + } + + JERRY_ASSERT (context_p->scope_stack_size != 0); + + if (!(data_p[0] & SCANNER_STREAM_UINT16_DIFF)) + { + if (data_p[2] != 0) + { + literal.char_p += data_p[2]; + next_data_p += 2 + 1; + } + else + { + memcpy (&literal.char_p, data_p + 2 + 1, sizeof (uintptr_t)); + next_data_p += 2 + 1 + sizeof (uintptr_t); + } + } + else + { + int32_t diff = ((int32_t) data_p[2]) | ((int32_t) data_p[3]) << 8; + + if (diff <= (intptr_t) UINT8_MAX) + { + diff = -diff; + } + + literal.char_p += diff; + next_data_p += 2 + 2; + } + + if (SCANNER_STREAM_TYPE_IS_ARG (type)) + { + if (option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_BODY) + { + if ((context_p->status_flags & PARSER_LEXICAL_BLOCK_NEEDED) + && (type == SCANNER_STREAM_TYPE_ARG_VAR || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR)) + { + literal.length = data_p[1]; + literal.type = LEXER_IDENT_LITERAL; + literal.status_flags = + ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE : LEXER_LIT_LOCATION_NO_OPTS); + + /* Literal must be exists. */ + lexer_construct_literal_object (context_p, &literal, LEXER_IDENT_LITERAL); + + if (context_p->lit_object.index < PARSER_REGISTER_START) + { + parser_emit_cbc_ext_literal_from_token (context_p, CBC_EXT_COPY_FROM_ARG); + } + } + + literal.char_p += data_p[1]; + continue; + } + } + else if ((option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_ARGS) && !SCANNER_STREAM_TYPE_IS_ARG_FUNC (type)) + { + /* Function arguments must come first. */ + break; + } + + literal.length = data_p[1]; + literal.type = LEXER_IDENT_LITERAL; + literal.status_flags = + ((data_p[0] & SCANNER_STREAM_HAS_ESCAPE) ? LEXER_LIT_LOCATION_HAS_ESCAPE : LEXER_LIT_LOCATION_NO_OPTS); + + lexer_construct_literal_object (context_p, &literal, LEXER_NEW_IDENT_LITERAL); + literal.char_p += data_p[1]; + + if (SCANNER_STREAM_TYPE_IS_ARG_FUNC (type) && (option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_BODY)) + { + JERRY_ASSERT (scope_stack_p >= context_p->scope_stack_p + 2); + JERRY_ASSERT (context_p->status_flags & PARSER_IS_FUNCTION); + JERRY_ASSERT (!(context_p->status_flags & PARSER_FUNCTION_IS_PARSING_ARGS)); + + parser_scope_stack_t *function_map_p = scope_stack_p - 2; + uint16_t literal_index = context_p->lit_object.index; + + while (literal_index != function_map_p->map_from) + { + function_map_p--; + + JERRY_ASSERT (function_map_p >= context_p->scope_stack_p); + } + + JERRY_ASSERT (function_map_p[1].map_from == PARSER_SCOPE_STACK_FUNC); + + cbc_opcode_t opcode = CBC_SET_VAR_FUNC; + + if (JERRY_UNLIKELY (context_p->status_flags & PARSER_LEXICAL_BLOCK_NEEDED) + && (function_map_p[0].map_to & PARSER_SCOPE_STACK_REGISTER_MASK) == 0) + { + opcode = CBC_INIT_ARG_OR_FUNC; + } + + parser_emit_cbc_literal_value (context_p, + (uint16_t) opcode, + function_map_p[1].map_to, + scanner_decode_map_to (function_map_p)); + continue; + } + + if (JERRY_UNLIKELY (scope_stack_p >= scope_stack_end_p)) + { + JERRY_ASSERT (context_p->scope_stack_size == PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK); + parser_raise_error (context_p, PARSER_ERR_SCOPE_STACK_LIMIT_REACHED); + } + + scope_stack_p->map_from = context_p->lit_object.index; + + if (info_type == SCANNER_TYPE_FUNCTION) + { + if (type != SCANNER_STREAM_TYPE_LET +#if JERRY_MODULE_SYSTEM + && type != SCANNER_STREAM_TYPE_IMPORT +#endif /* JERRY_MODULE_SYSTEM */ + && type != SCANNER_STREAM_TYPE_CONST) + { + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_GLOBAL; + } + } + + uint16_t map_to; + uint16_t func_init_opcode = CBC_INIT_ARG_OR_FUNC; + + if (!(data_p[0] & SCANNER_STREAM_NO_REG) && scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + map_to = (uint16_t) (PARSER_REGISTER_START + scope_stack_reg_top); + scope_stack_p->map_to = (uint16_t) (scope_stack_reg_top + 1); + scope_stack_reg_top++; + + switch (type) + { + case SCANNER_STREAM_TYPE_CONST: + { + scope_stack_p->map_to |= PARSER_SCOPE_STACK_IS_CONST_REG; + /* FALLTHRU */ + } + case SCANNER_STREAM_TYPE_LET: + case SCANNER_STREAM_TYPE_ARG: + case SCANNER_STREAM_TYPE_ARG_VAR: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR: + case SCANNER_STREAM_TYPE_ARG_FUNC: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC: + { + scope_stack_p->map_to |= PARSER_SCOPE_STACK_NO_FUNCTION_COPY; + break; + } + } + + func_init_opcode = CBC_SET_VAR_FUNC; + } + else + { + context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED; + map_to = context_p->lit_object.index; + + uint16_t scope_stack_map_to = 0; + + if (info_type == SCANNER_TYPE_FUNCTION) + { + context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED; + } + + switch (type) + { + case SCANNER_STREAM_TYPE_LET: + case SCANNER_STREAM_TYPE_CONST: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR: + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC: + { + scope_stack_map_to |= PARSER_SCOPE_STACK_NO_FUNCTION_COPY; + + if (!(data_p[0] & SCANNER_STREAM_EARLY_CREATE)) + { + break; + } + scope_stack_map_to |= PARSER_SCOPE_STACK_IS_LOCAL_CREATED; + /* FALLTHRU */ + } + case SCANNER_STREAM_TYPE_LOCAL: + case SCANNER_STREAM_TYPE_VAR: + { +#if JERRY_PARSER_DUMP_BYTE_CODE + context_p->scope_stack_top = (uint16_t) (scope_stack_p - context_p->scope_stack_p); +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + uint16_t opcode; + + switch (type) + { + case SCANNER_STREAM_TYPE_LET: + { + opcode = CBC_CREATE_LET; + break; + } + case SCANNER_STREAM_TYPE_CONST: + { + opcode = CBC_CREATE_CONST; + break; + } + case SCANNER_STREAM_TYPE_VAR: + { + opcode = CBC_CREATE_VAR; + + if (option_flags & SCANNER_CREATE_VARS_IS_SCRIPT) + { + opcode = CBC_CREATE_VAR_EVAL; + + if ((context_p->global_status_flags & ECMA_PARSE_FUNCTION_CONTEXT) + && !(context_p->status_flags & PARSER_IS_STRICT)) + { + opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_CREATE_VAR_EVAL); + } + } + break; + } + default: + { + JERRY_ASSERT (type == SCANNER_STREAM_TYPE_LOCAL || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG + || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR + || type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC); + + opcode = CBC_CREATE_LOCAL; + break; + } + } + + parser_emit_cbc_literal (context_p, opcode, map_to); + break; + } + case SCANNER_STREAM_TYPE_ARG: + case SCANNER_STREAM_TYPE_ARG_VAR: + case SCANNER_STREAM_TYPE_ARG_FUNC: + { +#if JERRY_PARSER_DUMP_BYTE_CODE + context_p->scope_stack_top = (uint16_t) (scope_stack_p - context_p->scope_stack_p); +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + scope_stack_map_to |= PARSER_SCOPE_STACK_NO_FUNCTION_COPY; + + /* Argument initializers of functions with simple arguments (e.g. function f(a,b,a) {}) are + * generated here. The other initializers are handled by parser_parse_function_arguments(). */ + if (!(info_u8_arg & SCANNER_FUNCTION_HAS_COMPLEX_ARGUMENT)) + { + parser_emit_cbc_literal_value (context_p, + CBC_INIT_ARG_OR_FUNC, + (uint16_t) (PARSER_REGISTER_START + scope_stack_reg_top), + map_to); + } + else if (data_p[0] & SCANNER_STREAM_EARLY_CREATE) + { + parser_emit_cbc_literal (context_p, CBC_CREATE_LOCAL, map_to); + scope_stack_map_to |= PARSER_SCOPE_STACK_IS_LOCAL_CREATED; + } + + if (scope_stack_reg_top < PARSER_MAXIMUM_NUMBER_OF_REGISTERS) + { + scope_stack_reg_top++; + } + break; + } + } + + scope_stack_p->map_to = scope_stack_map_to; + } + + scope_stack_p++; + + if (!SCANNER_STREAM_TYPE_IS_FUNCTION (type)) + { + continue; + } + + if (JERRY_UNLIKELY (scope_stack_p >= scope_stack_end_p)) + { + JERRY_ASSERT (context_p->scope_stack_size == PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK); + parser_raise_error (context_p, PARSER_ERR_SCOPE_STACK_LIMIT_REACHED); + } + +#if JERRY_PARSER_DUMP_BYTE_CODE + context_p->scope_stack_top = (uint16_t) (scope_stack_p - context_p->scope_stack_p); +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + if (!SCANNER_STREAM_TYPE_IS_ARG_FUNC (type)) + { + if (func_init_opcode == CBC_INIT_ARG_OR_FUNC && (option_flags & SCANNER_CREATE_VARS_IS_SCRIPT)) + { + literal.char_p -= data_p[1]; + + if (!scanner_scope_find_lexical_declaration (context_p, &literal)) + { + func_init_opcode = CBC_CREATE_VAR_FUNC_EVAL; + + if (context_p->global_status_flags & ECMA_PARSE_FUNCTION_CONTEXT) + { + func_init_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL); + } + } + literal.char_p += data_p[1]; + } + + parser_emit_cbc_literal_value (context_p, func_init_opcode, context_p->literal_count, map_to); + } + + scope_stack_p->map_from = PARSER_SCOPE_STACK_FUNC; + scope_stack_p->map_to = context_p->literal_count; + scope_stack_p++; + + scanner_create_unused_literal (context_p, 0); + } + + context_p->scope_stack_top = (uint16_t) (scope_stack_p - context_p->scope_stack_p); + context_p->scope_stack_reg_top = (uint16_t) scope_stack_reg_top; + + if (info_type == SCANNER_TYPE_FUNCTION) + { + context_p->scope_stack_global_end = context_p->scope_stack_top; + } + + if (context_p->register_count < scope_stack_reg_top) + { + context_p->register_count = (uint16_t) scope_stack_reg_top; + } + + if (!(option_flags & SCANNER_CREATE_VARS_IS_FUNCTION_ARGS)) + { + scanner_release_next (context_p, (size_t) (next_data_p + 1 - ((const uint8_t *) info_p))); + } + parser_flush_cbc (context_p); +} /* scanner_create_variables */ + +/** + * Get location from context. + */ +void +scanner_get_location (scanner_location_t *location_p, /**< location */ + parser_context_t *context_p) /**< context */ +{ + location_p->source_p = context_p->source_p; + location_p->line = context_p->line; + location_p->column = context_p->column; +} /* scanner_get_location */ + +/** + * Set context location. + */ +void +scanner_set_location (parser_context_t *context_p, /**< context */ + scanner_location_t *location_p) /**< location */ +{ + context_p->source_p = location_p->source_p; + context_p->line = location_p->line; + context_p->column = location_p->column; +} /* scanner_set_location */ + +/** + * Get the real map_to value. + */ +uint16_t +scanner_decode_map_to (parser_scope_stack_t *stack_item_p) /**< scope stack item */ +{ + JERRY_ASSERT (stack_item_p->map_from != PARSER_SCOPE_STACK_FUNC); + + uint16_t value = (stack_item_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK); + return (value == 0) ? stack_item_p->map_from : (uint16_t) (value + (PARSER_REGISTER_START - 1)); +} /* scanner_decode_map_to */ + +/** + * Find the given literal index in the scope stack + * and save it the constant literal pool if the literal is register stored + * + * @return given literal index - if literal corresponds to this index is not register stored + * literal index on which literal index has been mapped - otherwise + */ +uint16_t +scanner_save_literal (parser_context_t *context_p, /**< context */ + uint16_t literal_index) /**< literal index */ +{ + if (literal_index >= PARSER_REGISTER_START) + { + literal_index = (uint16_t) (literal_index - (PARSER_REGISTER_START - 1)); + + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top; + + do + { + /* Registers must be found in the scope stack. */ + JERRY_ASSERT (scope_stack_p > context_p->scope_stack_p); + scope_stack_p--; + } while (scope_stack_p->map_from == PARSER_SCOPE_STACK_FUNC + || literal_index != (scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK)); + + literal_index = scope_stack_p->map_from; + PARSER_GET_LITERAL (literal_index)->status_flags |= LEXER_FLAG_USED; + } + + return literal_index; +} /* scanner_save_literal */ + +/** + * Checks whether the literal is a const in the current scope. + * + * @return true if the literal is a const, false otherwise + */ +bool +scanner_literal_is_const_reg (parser_context_t *context_p, /**< context */ + uint16_t literal_index) /**< literal index */ +{ + if (literal_index < PARSER_REGISTER_START) + { + /* Re-assignment of non-register const bindings are detected elsewhere. */ + return false; + } + + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top; + + literal_index = (uint16_t) (literal_index - (PARSER_REGISTER_START - 1)); + + do + { + /* Registers must be found in the scope stack. */ + JERRY_ASSERT (scope_stack_p > context_p->scope_stack_p); + scope_stack_p--; + } while (scope_stack_p->map_from == PARSER_SCOPE_STACK_FUNC + || literal_index != (scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK)); + + return (scope_stack_p->map_to & PARSER_SCOPE_STACK_IS_CONST_REG) != 0; +} /* scanner_literal_is_const_reg */ + +/** + * Checks whether the literal is created before. + * + * @return true if the literal is created before, false otherwise + */ +bool +scanner_literal_is_created (parser_context_t *context_p, /**< context */ + uint16_t literal_index) /**< literal index */ +{ + JERRY_ASSERT (literal_index < PARSER_REGISTER_START); + + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top; + + do + { + /* These literals must be found in the scope stack. */ + JERRY_ASSERT (scope_stack_p > context_p->scope_stack_p); + scope_stack_p--; + } while (literal_index != scope_stack_p->map_from); + + JERRY_ASSERT ((scope_stack_p->map_to & PARSER_SCOPE_STACK_REGISTER_MASK) == 0); + + return (scope_stack_p->map_to & PARSER_SCOPE_STACK_IS_LOCAL_CREATED) != 0; +} /* scanner_literal_is_created */ + +/** + * Checks whether the literal exists. + * + * @return true if the literal exists, false otherwise + */ +bool +scanner_literal_exists (parser_context_t *context_p, /**< context */ + uint16_t literal_index) /**< literal index */ +{ + JERRY_ASSERT (literal_index < PARSER_REGISTER_START); + + parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top; + + while (scope_stack_p-- > context_p->scope_stack_p) + { + if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC && scanner_decode_map_to (scope_stack_p) == literal_index) + { + return true; + } + } + + return false; +} /* scanner_literal_exists */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner.cpp new file mode 100644 index 0000000..c975992 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner.cpp @@ -0,0 +1,3715 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jcontext.h" +#include "js-parser-internal.h" +#include "js-scanner-internal.h" +#include "lit-char-helpers.h" + +#if JERRY_PARSER + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_scanner Scanner + * @{ + */ + +/** + * Scan return types. + */ +typedef enum +{ + SCAN_NEXT_TOKEN, /**< get next token after return */ + SCAN_KEEP_TOKEN, /**< keep the current token after return */ +} scan_return_types_t; + +/** + * Checks whether token type is "of". + */ +#define SCANNER_IDENTIFIER_IS_OF() (lexer_token_is_identifier (context_p, "of", 2)) + +JERRY_STATIC_ASSERT ((SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_GENERATOR) == SCAN_STACK_COMPUTED_GENERATOR), + scanner_invalid_conversion_from_literal_pool_generator_to_computed_generator); +JERRY_STATIC_ASSERT ((SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (SCANNER_LITERAL_POOL_ASYNC) == SCAN_STACK_COMPUTED_ASYNC), + scanner_invalid_conversion_from_literal_pool_async_to_computed_async); + +JERRY_STATIC_ASSERT ((SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_GENERATOR) == SCANNER_LITERAL_POOL_GENERATOR), + scanner_invalid_conversion_from_computed_generator_to_literal_pool_generator); +JERRY_STATIC_ASSERT ((SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (SCAN_STACK_COMPUTED_ASYNC) == SCANNER_LITERAL_POOL_ASYNC), + scanner_invalid_conversion_from_computed_async_to_literal_pool_async); + +/** + * Change scanner mode from primary expression to post primary expression. + * + * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing + */ +static scan_return_types_t +scanner_primary_to_post_primary_expression (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p) /* scanner context */ +{ + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + + if (JERRY_UNLIKELY (context_p->stack_top_uint8 == SCAN_STACK_CLASS_FIELD_INITIALIZER + && (context_p->status_flags & PARSER_IS_STRICT))) + { + lexer_scan_identifier (context_p, (lexer_parse_options_t) ((unsigned int) LEXER_PARSE_CHECK_KEYWORDS | (unsigned int) LEXER_PARSE_NO_STRICT_IDENT_ERROR)); + + if (context_p->token.type == LEXER_LITERAL && lexer_compare_literal_to_string (context_p, "static", 6)) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + } + + return SCAN_KEEP_TOKEN; + } + + return SCAN_NEXT_TOKEN; +} /* scanner_primary_to_post_primary_expression */ + +/** + * Scan primary expression. + * + * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing + */ +static scan_return_types_t +scanner_scan_primary_expression (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /* scanner context */ + lexer_token_type_t type, /**< current token type */ + scan_stack_modes_t stack_top) /**< current stack top */ +{ + switch (type) + { + case LEXER_KEYW_NEW: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW; + + if (scanner_try_scan_new_target (context_p)) + { + return scanner_primary_to_post_primary_expression (context_p, scanner_context_p); + } + + break; + } + case LEXER_DIVIDE: + case LEXER_ASSIGN_DIVIDE: + { + lexer_construct_regexp_object (context_p, true); + return scanner_primary_to_post_primary_expression (context_p, scanner_context_p); + } + case LEXER_KEYW_FUNCTION: + { + uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; +#if JERRY_MODULE_SYSTEM + bool is_export_default = stack_top == SCAN_STACK_EXPORT_DEFAULT; +#endif /* JERRY_MODULE_SYSTEM */ + + if (scanner_context_p->async_source_p != NULL) + { + status_flags |= SCANNER_LITERAL_POOL_ASYNC; + } + + if (lexer_consume_generator (context_p)) + { + status_flags |= SCANNER_LITERAL_POOL_GENERATOR; + } + + scanner_push_literal_pool (context_p, scanner_context_p, status_flags); + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { +#if JERRY_MODULE_SYSTEM + if (is_export_default) + { + lexer_lit_location_t *location_p; + location_p = scanner_add_custom_literal (context_p, + scanner_context_p->active_literal_pool_p->prev_p, + &context_p->token.lit_location); + + scanner_detect_invalid_let (context_p, location_p); + location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET; + } +#endif /* JERRY_MODULE_SYSTEM */ + lexer_next_token (context_p); + } +#if JERRY_MODULE_SYSTEM + else if (is_export_default) + { + lexer_lit_location_t *location_p; + location_p = scanner_add_custom_literal (context_p, + scanner_context_p->active_literal_pool_p->prev_p, + &lexer_default_literal); + location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET; + } +#endif /* JERRY_MODULE_SYSTEM */ + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_EXPRESSION); + scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; + return SCAN_KEEP_TOKEN; + } + case LEXER_LEFT_PAREN: + { + scanner_scan_bracket (context_p, scanner_context_p); + return SCAN_KEEP_TOKEN; + } + case LEXER_LEFT_SQUARE: + { + scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_NONE, false); + + parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + case LEXER_LEFT_BRACE: + { + scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_NONE, false); + parser_stack_push_uint8 (context_p, 0); + + parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); + scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; + return SCAN_KEEP_TOKEN; + } + case LEXER_HASHMARK: + { + if (!lexer_scan_private_identifier (context_p)) + { + scanner_raise_error (context_p); + } + + return SCAN_KEEP_TOKEN; + } + case LEXER_TEMPLATE_LITERAL: + { + if (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_TEMPLATE_STRING); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + + /* The string is a normal string literal. */ + /* FALLTHRU */ + } + case LEXER_LITERAL: + { + const uint8_t *source_p = context_p->source_p; + + if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL && lexer_check_arrow (context_p)) + { + scanner_scan_simple_arrow (context_p, scanner_context_p, source_p); + return SCAN_KEEP_TOKEN; + } + + if (JERRY_UNLIKELY (lexer_token_is_async (context_p))) + { + scanner_context_p->async_source_p = source_p; + scanner_check_async_function (context_p, scanner_context_p); + return SCAN_KEEP_TOKEN; + } + + if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { +#if JERRY_MODULE_SYSTEM + if (stack_top == SCAN_STACK_EXPORT_DEFAULT) + { + lexer_lit_location_t *location_p = scanner_add_literal (context_p, scanner_context_p); + location_p->type |= (SCANNER_LITERAL_IS_USED | SCANNER_LITERAL_IS_VAR); + scanner_detect_eval_call (context_p, scanner_context_p); + return scanner_primary_to_post_primary_expression (context_p, scanner_context_p); + } +#endif /* JERRY_MODULE_SYSTEM */ + + scanner_add_reference (context_p, scanner_context_p); + } + /* FALLTHRU */ + } + case LEXER_KEYW_THIS: + case LEXER_LIT_TRUE: + case LEXER_LIT_FALSE: + case LEXER_LIT_NULL: + { + return scanner_primary_to_post_primary_expression (context_p, scanner_context_p); + } + case LEXER_KEYW_SUPER: + { + scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE; + return scanner_primary_to_post_primary_expression (context_p, scanner_context_p); + } + case LEXER_KEYW_CLASS: + { + scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_EXPRESSION); + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + return SCAN_KEEP_TOKEN; + } + break; + } + case LEXER_RIGHT_SQUARE: + { + if (stack_top != SCAN_STACK_ARRAY_LITERAL) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + return SCAN_KEEP_TOKEN; + } + case LEXER_THREE_DOTS: + { + /* Elision or spread arguments */ + if (stack_top != SCAN_STACK_PAREN_EXPRESSION && stack_top != SCAN_STACK_ARRAY_LITERAL) + { + scanner_raise_error (context_p); + } + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + case LEXER_COMMA: + { + if (stack_top != SCAN_STACK_ARRAY_LITERAL) + { + scanner_raise_error (context_p); + } + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (scanner_context_p->binding_type != SCANNER_BINDING_NONE) + { + scanner_context_p->mode = SCAN_MODE_BINDING; + } + + break; + } + case LEXER_KEYW_YIELD: + { + lexer_next_token (context_p); + + if (lexer_check_yield_no_arg (context_p)) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + } + + if (context_p->token.type == LEXER_MULTIPLY) + { + return SCAN_NEXT_TOKEN; + } + return SCAN_KEEP_TOKEN; + } +#if JERRY_MODULE_SYSTEM + case LEXER_KEYW_IMPORT: + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_DOT) + { + scanner_check_import_meta (context_p); + } + else if (context_p->token.type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } +#endif /* JERRY_MODULE_SYSTEM */ + case LEXER_RIGHT_PAREN: + { + if (stack_top == SCAN_STACK_PAREN_EXPRESSION) + { + parser_stack_pop_uint8 (context_p); + + if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) + { + scanner_add_async_literal (context_p, scanner_context_p); + } + + return scanner_primary_to_post_primary_expression (context_p, scanner_context_p); + } + /* FALLTHRU */ + } + default: + { + scanner_raise_error (context_p); + } + } + return SCAN_NEXT_TOKEN; +} /* scanner_scan_primary_expression */ + +/** + * Scan the tokens after the primary expression. + * + * @return true for break, false for fall through + */ +static bool +scanner_scan_post_primary_expression (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + lexer_token_type_t type, /**< current token type */ + scan_stack_modes_t stack_top) /**< current stack top */ +{ + switch (type) + { + case LEXER_DOT: + { + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + + if (context_p->token.type == LEXER_HASHMARK) + { + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + lexer_next_token (context_p); + } + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + return true; + } + case LEXER_LEFT_PAREN: + { + parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_EXPRESSION); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return true; + } + case LEXER_TEMPLATE_LITERAL: + { + if (JERRY_UNLIKELY (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT)) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + parser_stack_push_uint8 (context_p, SCAN_STACK_TAGGED_TEMPLATE_LITERAL); + } + return true; + } + case LEXER_LEFT_SQUARE: + { + parser_stack_push_uint8 (context_p, SCAN_STACK_PROPERTY_ACCESSOR); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return true; + } + case LEXER_INCREASE: + case LEXER_DECREASE: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + + if (context_p->token.flags & LEXER_WAS_NEWLINE) + { + return false; + } + + lexer_next_token (context_p); + type = (lexer_token_type_t) context_p->token.type; + + if (type != LEXER_QUESTION_MARK) + { + break; + } + /* FALLTHRU */ + } + case LEXER_QUESTION_MARK: + { + parser_stack_push_uint8 (context_p, SCAN_STACK_COLON_EXPRESSION); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return true; + } + default: + { + break; + } + } + + if (LEXER_IS_BINARY_OP_TOKEN (type) && (type != LEXER_KEYW_IN || !SCANNER_IS_FOR_START (stack_top))) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return true; + } + + return false; +} /* scanner_scan_post_primary_expression */ + +/** + * Scan the tokens after the primary expression. + * + * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing + */ +static scan_return_types_t +scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + lexer_token_type_t type, /**< current token type */ + scan_stack_modes_t stack_top) /**< current stack top */ +{ + if (type == LEXER_COMMA) + { + switch (stack_top) + { + case SCAN_STACK_VAR: + case SCAN_STACK_LET: + case SCAN_STACK_CONST: + case SCAN_STACK_FOR_VAR_START: + case SCAN_STACK_FOR_LET_START: + case SCAN_STACK_FOR_CONST_START: + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_COLON_EXPRESSION: + { + scanner_raise_error (context_p); + break; + } + case SCAN_STACK_BINDING_INIT: + case SCAN_STACK_BINDING_LIST_INIT: + { + break; + } + case SCAN_STACK_ARROW_ARGUMENTS: + { + lexer_next_token (context_p); + scanner_check_arrow_arg (context_p, scanner_context_p); + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_ARROW_EXPRESSION: + { + break; + } + case SCAN_STACK_CLASS_FIELD_INITIALIZER: + { + scanner_raise_error (context_p); + break; + } + case SCAN_STACK_FUNCTION_PARAMETERS: + { + scanner_context_p->mode = SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS; + parser_stack_pop_uint8 (context_p); + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_ARRAY_LITERAL: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (scanner_context_p->binding_type != SCANNER_BINDING_NONE) + { + scanner_context_p->mode = SCAN_MODE_BINDING; + } + + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_OBJECT_LITERAL: + { + scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; + return SCAN_KEEP_TOKEN; + } + default: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + } + } + + switch (stack_top) + { + case SCAN_STACK_WITH_EXPRESSION: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + parser_stack_pop_uint8 (context_p); + + uint16_t status_flags = scanner_context_p->active_literal_pool_p->status_flags; + parser_stack_push_uint8 (context_p, (status_flags & SCANNER_LITERAL_POOL_IN_WITH) ? 1 : 0); + parser_stack_push_uint8 (context_p, SCAN_STACK_WITH_STATEMENT); + status_flags |= SCANNER_LITERAL_POOL_IN_WITH; + scanner_context_p->active_literal_pool_p->status_flags = status_flags; + + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_DO_EXPRESSION: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_WHILE_EXPRESSION: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + scanner_source_start_t source_start; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); + + scanner_location_info_t *location_info_p; + location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, + source_start.source_p, + sizeof (scanner_location_info_t)); + location_info_p->info.type = SCANNER_TYPE_WHILE; + + scanner_get_location (&location_info_p->location, context_p); + + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_PAREN_EXPRESSION: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + parser_stack_pop_uint8 (context_p); + + if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC) + { + scanner_add_async_literal (context_p, scanner_context_p); + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_STATEMENT_WITH_EXPR: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + parser_stack_pop_uint8 (context_p); + + if (context_p->stack_top_uint8 == SCAN_STACK_IF_STATEMENT) + { + scanner_check_function_after_if (context_p, scanner_context_p); + return SCAN_KEEP_TOKEN; + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_BINDING_LIST_INIT: + { + parser_stack_pop_uint8 (context_p); + + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL + || context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL + || context_p->stack_top_uint8 == SCAN_STACK_LET || context_p->stack_top_uint8 == SCAN_STACK_CONST + || context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START + || context_p->stack_top_uint8 == SCAN_STACK_FOR_CONST_START + || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS + || context_p->stack_top_uint8 == SCAN_STACK_ARROW_ARGUMENTS); + + scanner_binding_item_t *item_p = scanner_context_p->active_binding_list_p->items_p; + + while (item_p != NULL) + { + if (item_p->literal_p->type & SCANNER_LITERAL_IS_USED) + { + item_p->literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + item_p = item_p->next_p; + } + + scanner_pop_binding_list (scanner_context_p); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_BINDING_INIT: + { + scanner_binding_literal_t binding_literal; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); + + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL + || context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL + || context_p->stack_top_uint8 == SCAN_STACK_LET || context_p->stack_top_uint8 == SCAN_STACK_CONST + || context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START + || context_p->stack_top_uint8 == SCAN_STACK_FOR_CONST_START + || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS + || context_p->stack_top_uint8 == SCAN_STACK_ARROW_ARGUMENTS); + + JERRY_ASSERT (SCANNER_NEEDS_BINDING_LIST (scanner_context_p->binding_type) + || (stack_top != SCAN_STACK_ARRAY_LITERAL && stack_top != SCAN_STACK_OBJECT_LITERAL)); + + if (binding_literal.literal_p->type & SCANNER_LITERAL_IS_USED) + { + binding_literal.literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_VAR: + case SCAN_STACK_LET: + case SCAN_STACK_CONST: + { +#if JERRY_MODULE_SYSTEM + scanner_context_p->active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; +#endif /* JERRY_MODULE_SYSTEM */ + + parser_stack_pop_uint8 (context_p); + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_FOR_VAR_START: + case SCAN_STACK_FOR_LET_START: + case SCAN_STACK_FOR_CONST_START: + case SCAN_STACK_FOR_START: + { + if (type == LEXER_KEYW_IN || SCANNER_IDENTIFIER_IS_OF ()) + { + scanner_for_statement_t for_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); + + scanner_location_info_t *location_info; + location_info = (scanner_location_info_t *) scanner_insert_info (context_p, + for_statement.u.source_p, + sizeof (scanner_location_info_t)); + location_info->info.type = (type == LEXER_KEYW_IN) ? SCANNER_TYPE_FOR_IN : SCANNER_TYPE_FOR_OF; + + if (stack_top == SCAN_STACK_FOR_LET_START || stack_top == SCAN_STACK_FOR_CONST_START) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_PRIVATE_BLOCK_EARLY); + } + scanner_get_location (&location_info->location, context_p); + + parser_stack_push_uint8 (context_p, SCAN_STACK_STATEMENT_WITH_EXPR); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + + if (type != LEXER_SEMICOLON) + { + break; + } + + scanner_for_statement_t for_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, NULL, sizeof (scanner_for_statement_t)); + + if (stack_top == SCAN_STACK_FOR_LET_START || stack_top == SCAN_STACK_FOR_CONST_START) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_PRIVATE_BLOCK); + } + + for_statement.u.source_p = context_p->source_p; + parser_stack_push (context_p, &for_statement, sizeof (scanner_for_statement_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_FOR_CONDITION); + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_SEMICOLON) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + type = LEXER_SEMICOLON; + /* FALLTHRU */ + } + case SCAN_STACK_FOR_CONDITION: + { + if (type != LEXER_SEMICOLON) + { + break; + } + + scanner_for_statement_t for_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); + + scanner_for_info_t *for_info_p; + for_info_p = + (scanner_for_info_t *) scanner_insert_info (context_p, for_statement.u.source_p, sizeof (scanner_for_info_t)); + for_info_p->info.type = SCANNER_TYPE_FOR; + + scanner_get_location (&for_info_p->expression_location, context_p); + for_info_p->end_location.source_p = NULL; + + for_statement.u.for_info_p = for_info_p; + + parser_stack_push (context_p, &for_statement, sizeof (scanner_for_statement_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_FOR_EXPRESSION); + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + type = LEXER_RIGHT_PAREN; + /* FALLTHRU */ + } + case SCAN_STACK_FOR_EXPRESSION: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + scanner_for_statement_t for_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &for_statement, sizeof (scanner_for_statement_t)); + + scanner_get_location (&for_statement.u.for_info_p->end_location, context_p); + + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_SWITCH_EXPRESSION: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + break; + } + + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + literal_pool_p->source_p = context_p->source_p - 1; + + parser_stack_pop_uint8 (context_p); + + scanner_switch_statement_t switch_statement = scanner_context_p->active_switch_statement; + parser_stack_push (context_p, &switch_statement, sizeof (scanner_switch_statement_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_SWITCH_BLOCK); + + scanner_switch_info_t *switch_info_p; + switch_info_p = + (scanner_switch_info_t *) scanner_insert_info (context_p, context_p->source_p, sizeof (scanner_switch_info_t)); + switch_info_p->info.type = SCANNER_TYPE_SWITCH; + switch_info_p->case_p = NULL; + scanner_context_p->active_switch_statement.last_case_p = &switch_info_p->case_p; + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_KEYW_CASE + && context_p->token.type != LEXER_KEYW_DEFAULT) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_CASE_STATEMENT: + { + if (type != LEXER_COLON) + { + break; + } + + scanner_source_start_t source_start; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); + + scanner_location_info_t *location_info_p; + location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, + source_start.source_p, + sizeof (scanner_location_info_t)); + location_info_p->info.type = SCANNER_TYPE_CASE; + + scanner_get_location (&location_info_p->location, context_p); + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_COLON_EXPRESSION: + { + if (type != LEXER_COLON) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + parser_stack_pop_uint8 (context_p); + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_ARRAY_LITERAL: + case SCAN_STACK_OBJECT_LITERAL: + { + if ((stack_top == SCAN_STACK_ARRAY_LITERAL && type != LEXER_RIGHT_SQUARE) + || (stack_top == SCAN_STACK_OBJECT_LITERAL && type != LEXER_RIGHT_BRACE)) + { + break; + } + + scanner_source_start_t source_start; + uint8_t binding_type = scanner_context_p->binding_type; + uint8_t object_literal_flags = 0; + + parser_stack_pop_uint8 (context_p); + + if (stack_top == SCAN_STACK_OBJECT_LITERAL) + { + object_literal_flags = context_p->stack_top_uint8; + parser_stack_pop_uint8 (context_p); + } + + scanner_context_p->binding_type = context_p->stack_top_uint8; + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); + + lexer_next_token (context_p); + + stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; + + if (binding_type == SCANNER_BINDING_CATCH && stack_top == SCAN_STACK_CATCH_STATEMENT) + { + scanner_pop_binding_list (scanner_context_p); + + if (object_literal_flags != 0) + { + scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_LITERAL_FLAGS; + info_p->u8_arg = object_literal_flags; + } + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + + if (stack_top == SCAN_STACK_FOR_START_PATTERN) + { + JERRY_ASSERT (binding_type == SCANNER_BINDING_NONE); + + parser_stack_change_last_uint8 (context_p, SCAN_STACK_FOR_START); + + if (context_p->token.type == LEXER_KEYW_IN || SCANNER_IDENTIFIER_IS_OF ()) + { + scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_LITERAL_FLAGS; + info_p->u8_arg = object_literal_flags | SCANNER_LITERAL_DESTRUCTURING_FOR; + return SCAN_KEEP_TOKEN; + } + } + + if (context_p->token.type != LEXER_ASSIGN) + { + if (SCANNER_NEEDS_BINDING_LIST (binding_type)) + { + scanner_pop_binding_list (scanner_context_p); + } + + if ((stack_top == SCAN_STACK_ARRAY_LITERAL || stack_top == SCAN_STACK_OBJECT_LITERAL) + && (binding_type == SCANNER_BINDING_NONE || binding_type == SCANNER_BINDING_ARROW_ARG) + && context_p->token.type != LEXER_EOS && context_p->token.type != LEXER_COMMA + && context_p->token.type != LEXER_RIGHT_BRACE && context_p->token.type != LEXER_RIGHT_SQUARE) + { + object_literal_flags |= SCANNER_LITERAL_NO_DESTRUCTURING; + } + + if (object_literal_flags != 0) + { + scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_LITERAL_FLAGS; + info_p->u8_arg = object_literal_flags; + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + scanner_location_info_t *location_info_p; + location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, + source_start.source_p, + sizeof (scanner_location_info_t)); + location_info_p->info.type = SCANNER_TYPE_INITIALIZER; + location_info_p->info.u8_arg = object_literal_flags; + scanner_get_location (&location_info_p->location, context_p); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (SCANNER_NEEDS_BINDING_LIST (binding_type)) + { + scanner_binding_item_t *item_p = scanner_context_p->active_binding_list_p->items_p; + + while (item_p != NULL) + { + item_p->literal_p->type &= (uint8_t) ~SCANNER_LITERAL_IS_USED; + item_p = item_p->next_p; + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_LIST_INIT); + } + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_PROPERTY_ACCESSOR: + { + if (type != LEXER_RIGHT_SQUARE) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + parser_stack_pop_uint8 (context_p); + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_COMPUTED_PROPERTY: + { + if (type != LEXER_RIGHT_SQUARE) + { + break; + } + + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + + parser_stack_pop_uint8 (context_p); + stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; + + if (stack_top == SCAN_STACK_FUNCTION_PROPERTY) + { + scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION); + scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; + return SCAN_KEEP_TOKEN; + } + + if (stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR || stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) + { + JERRY_ASSERT (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME); + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION); + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; + return SCAN_KEEP_TOKEN; + } + + if (context_p->token.type == LEXER_ASSIGN) + { + scanner_push_class_field_initializer (context_p, scanner_context_p); + return SCAN_NEXT_TOKEN; + } + + scanner_context_p->mode = + (context_p->token.type != LEXER_SEMICOLON ? SCAN_MODE_CLASS_BODY_NO_SCAN : SCAN_MODE_CLASS_BODY); + return SCAN_KEEP_TOKEN; + } + + JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL); + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION); + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; + return SCAN_KEEP_TOKEN; + } + + if (context_p->token.type != LEXER_COLON) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (scanner_context_p->binding_type != SCANNER_BINDING_NONE) + { + scanner_context_p->mode = SCAN_MODE_BINDING; + } + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_COMPUTED_GENERATOR: + case SCAN_STACK_COMPUTED_ASYNC: + case SCAN_STACK_COMPUTED_ASYNC_GENERATOR: + { + if (type != LEXER_RIGHT_SQUARE) + { + break; + } + + lexer_next_token (context_p); + parser_stack_pop_uint8 (context_p); + + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL + || context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PROPERTY); + + uint16_t status_flags = (uint16_t) (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_GENERATOR + | SCANNER_FROM_COMPUTED_TO_LITERAL_POOL (stack_top)); + + scanner_push_literal_pool (context_p, scanner_context_p, status_flags); + + scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_TEMPLATE_STRING: + case SCAN_STACK_TAGGED_TEMPLATE_LITERAL: + { + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + context_p->source_p--; + context_p->column--; + lexer_parse_string (context_p, LEXER_STRING_NO_OPTS); + + if (context_p->source_p[-1] != LIT_CHAR_GRAVE_ACCENT) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + } + else + { + parser_stack_pop_uint8 (context_p); + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + } + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_ARROW_ARGUMENTS: + { + if (type != LEXER_RIGHT_PAREN) + { + break; + } + + scanner_check_arrow (context_p, scanner_context_p); + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_ARROW_EXPRESSION: + { + scanner_pop_literal_pool (context_p, scanner_context_p); + parser_stack_pop_uint8 (context_p); + lexer_update_await_yield (context_p, context_p->status_flags); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_CLASS_EXTENDS: + { + if (type != LEXER_LEFT_BRACE) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_CLASS_BODY; + parser_stack_pop_uint8 (context_p); + + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_CLASS_FIELD_INITIALIZER: + { + scanner_source_start_t source_start; + const uint8_t *source_p = NULL; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t)); + scanner_pop_literal_pool (context_p, scanner_context_p); + scanner_context_p->mode = SCAN_MODE_CLASS_BODY_NO_SCAN; + + switch (type) + { + case LEXER_SEMICOLON: + { + source_p = context_p->source_p - 1; + scanner_context_p->mode = SCAN_MODE_CLASS_BODY; + break; + } + case LEXER_RIGHT_BRACE: + { + source_p = context_p->source_p - 1; + break; + } + default: + { + if (!(context_p->token.flags & LEXER_WAS_NEWLINE)) + { + break; + } + + if (type == LEXER_LEFT_SQUARE) + { + source_p = context_p->source_p - 1; + break; + } + + if (type == LEXER_LITERAL) + { + if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL + || context_p->token.lit_location.type == LEXER_NUMBER_LITERAL) + { + source_p = context_p->token.lit_location.char_p; + } + else if (context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + source_p = context_p->token.lit_location.char_p - 1; + } + break; + } + + if (type == context_p->token.keyword_type && type != LEXER_EOS) + { + /* Convert keyword to literal. */ + source_p = context_p->token.lit_location.char_p; + context_p->token.type = LEXER_LITERAL; + } + break; + } + } + + if (JERRY_UNLIKELY (source_p == NULL)) + { + scanner_raise_error (context_p); + } + + scanner_location_info_t *location_info_p; + location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, + source_start.source_p, + sizeof (scanner_location_info_t)); + location_info_p->info.type = SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END; + location_info_p->location.source_p = source_p; + location_info_p->location.line = context_p->token.line; + location_info_p->location.column = context_p->token.column; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_FUNCTION_PARAMETERS: + { + parser_stack_pop_uint8 (context_p); + + if (type != LEXER_RIGHT_PAREN && (type != LEXER_EOS || context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION)) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS; + return SCAN_KEEP_TOKEN; + } + default: + { + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + return SCAN_KEEP_TOKEN; + } + } + + scanner_raise_error (context_p); + return SCAN_NEXT_TOKEN; +} /* scanner_scan_primary_expression_end */ + +/** + * Scan statements. + * + * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing + */ +static scan_return_types_t +scanner_scan_statement (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + lexer_token_type_t type, /**< current token type */ + scan_stack_modes_t stack_top) /**< current stack top */ +{ + switch (type) + { + case LEXER_SEMICOLON: + { + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + return SCAN_KEEP_TOKEN; + } + case LEXER_LEFT_BRACE: + { + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + literal_pool_p->source_p = context_p->source_p; + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_DO: + { + scanner_context_p->mode = SCAN_MODE_STATEMENT; + parser_stack_push_uint8 (context_p, SCAN_STACK_DO_STATEMENT); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_TRY: + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_raise_error (context_p); + } + + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + literal_pool_p->source_p = context_p->source_p; + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + parser_stack_push_uint8 (context_p, SCAN_STACK_TRY_STATEMENT); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_DEBUGGER: + { + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_IF: + case LEXER_KEYW_WITH: + case LEXER_KEYW_SWITCH: + { + lexer_next_token (context_p); + if (context_p->token.type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + + uint8_t mode = SCAN_STACK_STATEMENT_WITH_EXPR; + + if (type == LEXER_KEYW_IF) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_IF_STATEMENT); + } + else if (type == LEXER_KEYW_WITH) + { + mode = SCAN_STACK_WITH_EXPRESSION; + } + else if (type == LEXER_KEYW_SWITCH) + { + mode = SCAN_STACK_SWITCH_EXPRESSION; + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + parser_stack_push_uint8 (context_p, mode); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_WHILE: + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + scanner_source_start_t source_start; + source_start.source_p = context_p->source_p; + + parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_WHILE_EXPRESSION); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_FOR: + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_KEYW_AWAIT) + { + lexer_next_token (context_p); + } + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + + scanner_for_statement_t for_statement; + for_statement.u.source_p = context_p->source_p; + uint8_t stack_mode = SCAN_STACK_FOR_START; + scan_return_types_t return_type = SCAN_KEEP_TOKEN; + + lexer_next_token (context_p); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + const uint8_t *source_p = context_p->source_p; + + switch (context_p->token.type) + { + case LEXER_SEMICOLON: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + break; + } + case LEXER_KEYW_VAR: + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + stack_mode = SCAN_STACK_FOR_VAR_START; + return_type = SCAN_NEXT_TOKEN; + break; + } + case LEXER_LEFT_BRACE: + case LEXER_LEFT_SQUARE: + { + stack_mode = SCAN_STACK_FOR_START_PATTERN; + break; + } + case LEXER_LITERAL: + { + if (!lexer_token_is_let (context_p)) + { + break; + } + + parser_line_counter_t line = context_p->line; + parser_line_counter_t column = context_p->column; + + if (lexer_check_arrow (context_p)) + { + context_p->source_p = source_p; + context_p->line = line; + context_p->column = column; + context_p->token.flags &= (uint8_t) ~LEXER_NO_SKIP_SPACES; + break; + } + + lexer_next_token (context_p); + + type = (lexer_token_type_t) context_p->token.type; + + if (type != LEXER_LEFT_SQUARE && type != LEXER_LEFT_BRACE + && (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)) + { + scanner_info_t *info_p = scanner_insert_info (context_p, source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_LET_EXPRESSION; + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + break; + } + + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + /* FALLTHRU */ + } + case LEXER_KEYW_LET: + case LEXER_KEYW_CONST: + { + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + literal_pool_p->source_p = source_p; + + if (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION) + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + return_type = SCAN_NEXT_TOKEN; + } + + stack_mode = + ((context_p->token.type == LEXER_KEYW_CONST) ? SCAN_STACK_FOR_CONST_START : SCAN_STACK_FOR_LET_START); + break; + } + } + + parser_stack_push (context_p, &for_statement, sizeof (scanner_for_statement_t)); + parser_stack_push_uint8 (context_p, stack_mode); + return return_type; + } + case LEXER_KEYW_VAR: + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + parser_stack_push_uint8 (context_p, SCAN_STACK_VAR); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_LET: + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + parser_stack_push_uint8 (context_p, SCAN_STACK_LET); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_CONST: + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + parser_stack_push_uint8 (context_p, SCAN_STACK_CONST); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_THROW: + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_RETURN: + { + lexer_next_token (context_p); + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type != LEXER_SEMICOLON + && context_p->token.type != LEXER_EOS && context_p->token.type != LEXER_RIGHT_BRACE) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + return SCAN_KEEP_TOKEN; + } + case LEXER_KEYW_BREAK: + case LEXER_KEYW_CONTINUE: + { + lexer_next_token (context_p); + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE) && context_p->token.type == LEXER_LITERAL + && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + return SCAN_NEXT_TOKEN; + } + return SCAN_KEEP_TOKEN; + } + case LEXER_KEYW_CASE: + case LEXER_KEYW_DEFAULT: + { + if (stack_top != SCAN_STACK_SWITCH_BLOCK) + { + scanner_raise_error (context_p); + } + + scanner_case_info_t *case_info_p; + case_info_p = (scanner_case_info_t *) scanner_malloc (context_p, sizeof (scanner_case_info_t)); + + *(scanner_context_p->active_switch_statement.last_case_p) = case_info_p; + scanner_context_p->active_switch_statement.last_case_p = &case_info_p->next_p; + + case_info_p->next_p = NULL; + scanner_get_location (&case_info_p->location, context_p); + + if (type == LEXER_KEYW_DEFAULT) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_COLON) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + + scanner_source_start_t source_start; + source_start.source_p = context_p->source_p; + + parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_CASE_STATEMENT); + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_FUNCTION: + { + uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_FUNCTION_STATEMENT; + + if (scanner_context_p->async_source_p != NULL) + { + scanner_context_p->status_flags |= SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION; + status_flags |= SCANNER_LITERAL_POOL_ASYNC; + } + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_MULTIPLY) + { + status_flags |= SCANNER_LITERAL_POOL_GENERATOR; + lexer_next_token (context_p); + } + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); + + const uint8_t mask = (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LOCAL); + + if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL) + && (literal_p->type & mask) != (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG) + && (literal_p->type & mask) != SCANNER_LITERAL_IS_LOCAL_FUNC) + { + scanner_raise_redeclaration_error (context_p); + } + + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + + if (!(literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION) + && (literal_p->type & (SCANNER_LITERAL_IS_VAR))) + { + scanner_raise_redeclaration_error (context_p); + } + + literal_p->type |= SCANNER_LITERAL_IS_LOCAL_FUNC; + + scanner_context_p->status_flags &= (uint16_t) ~SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION; + + scanner_push_literal_pool (context_p, scanner_context_p, status_flags); + + scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS; + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_STATEMENT); + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_CLASS: + { + lexer_lit_location_t *literal_p; + literal_p = scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT); + + if (literal_p == NULL) + { + scanner_raise_error (context_p); + } + + scanner_detect_invalid_let (context_p, literal_p); + literal_p->type |= SCANNER_LITERAL_IS_LET; + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + +#if JERRY_MODULE_SYSTEM + if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT) + { + literal_p->type |= SCANNER_LITERAL_NO_REG; + scanner_context_p->active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; + } +#endif /* JERRY_MODULE_SYSTEM */ + + return SCAN_NEXT_TOKEN; + } +#if JERRY_MODULE_SYSTEM + case LEXER_KEYW_IMPORT: + { + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_DOT) + { + scanner_check_import_meta (context_p); + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + if (stack_top != SCAN_STACK_SCRIPT) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + return SCAN_NEXT_TOKEN; + } + + bool parse_imports = true; + + if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); + + scanner_detect_invalid_let (context_p, literal_p); + literal_p->type |= SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_NO_REG; + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_COMMA) + { + lexer_next_token (context_p); + } + else + { + parse_imports = false; + } + } + + if (parse_imports) + { + if (context_p->token.type == LEXER_MULTIPLY) + { + lexer_next_token (context_p); + if (!lexer_token_is_identifier (context_p, "as", 2)) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); + + scanner_detect_invalid_let (context_p, literal_p); + literal_p->type |= SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_NO_REG; + + lexer_next_token (context_p); + } + else if (context_p->token.type == LEXER_LEFT_BRACE) + { + lexer_next_token (context_p); + + while (context_p->token.type != LEXER_RIGHT_BRACE) + { + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + const uint8_t *source_p = context_p->source_p; + + if (lexer_check_next_character (context_p, LIT_CHAR_LOWERCASE_A)) + { + lexer_next_token (context_p); + + if (!lexer_token_is_identifier (context_p, "as", 2)) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + source_p = context_p->source_p; + } + + lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p); + + if (literal_p->type & (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_LOCAL)) + { + context_p->source_p = source_p; + scanner_raise_redeclaration_error (context_p); + } + + if (literal_p->type & SCANNER_LITERAL_IS_FUNC) + { + literal_p->type &= (uint8_t) ~SCANNER_LITERAL_IS_FUNC; + } + + literal_p->type |= SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_NO_REG; + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_RIGHT_BRACE) + { + if (context_p->token.type != LEXER_COMMA) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + } + } + + lexer_next_token (context_p); + } + else + { + scanner_raise_error (context_p); + } + } + + if (!lexer_token_is_identifier (context_p, "from", 4)) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type != LEXER_STRING_LITERAL) + { + scanner_raise_error (context_p); + } + + return SCAN_NEXT_TOKEN; + } + case LEXER_KEYW_EXPORT: + { + if (stack_top != SCAN_STACK_SCRIPT) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_KEYW_DEFAULT) + { + lexer_next_token (context_p); + parser_stack_push_uint8 (context_p, SCAN_STACK_EXPORT_DEFAULT); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_END; + + if (context_p->token.type == LEXER_MULTIPLY) + { + lexer_next_token (context_p); + + if (lexer_token_is_identifier (context_p, "as", 2)) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + } + + if (!lexer_token_is_identifier (context_p, "from", 4)) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + scanner_raise_error (context_p); + } + + return SCAN_NEXT_TOKEN; + } + + scanner_source_start_t source_start; + source_start.source_p = context_p->source_p; + + if (context_p->token.type == LEXER_LEFT_BRACE) + { + lexer_next_token (context_p); + + while (context_p->token.type != LEXER_RIGHT_BRACE) + { + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (lexer_token_is_identifier (context_p, "as", 2)) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + } + + if (context_p->token.type != LEXER_RIGHT_BRACE) + { + if (context_p->token.type != LEXER_COMMA) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + } + } + + lexer_next_token (context_p); + + if (!lexer_token_is_identifier (context_p, "from", 4)) + { + return SCAN_KEEP_TOKEN; + } + + scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_EXPORT_MODULE_SPECIFIER; + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LITERAL && context_p->token.lit_location.type == LEXER_STRING_LITERAL) + { + scanner_raise_error (context_p); + } + + return SCAN_NEXT_TOKEN; + } + + switch (context_p->token.type) + { + case LEXER_KEYW_CLASS: + case LEXER_KEYW_LET: + case LEXER_KEYW_CONST: + case LEXER_KEYW_VAR: + { + scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_IN_EXPORT; + break; + } + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_KEEP_TOKEN; + } +#endif /* JERRY_MODULE_SYSTEM */ + default: + { + break; + } + } + + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL) + { + if (JERRY_UNLIKELY (lexer_check_next_character (context_p, LIT_CHAR_COLON))) + { + lexer_consume_next_character (context_p); + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_NEXT_TOKEN; + } + + JERRY_ASSERT (context_p->token.flags & LEXER_NO_SKIP_SPACES); + + /* The colon needs to be checked first because the parser also checks + * it first, and this check skips the spaces which affects source_p. */ + if (JERRY_UNLIKELY (lexer_check_arrow (context_p))) + { + scanner_scan_simple_arrow (context_p, scanner_context_p, context_p->source_p); + return SCAN_KEEP_TOKEN; + } + + if (JERRY_UNLIKELY (lexer_token_is_let (context_p))) + { + lexer_lit_location_t let_literal = context_p->token.lit_location; + const uint8_t *source_p = context_p->source_p; + + lexer_next_token (context_p); + + type = (lexer_token_type_t) context_p->token.type; + + if (type == LEXER_LEFT_SQUARE || type == LEXER_LEFT_BRACE + || (type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)) + { + scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT; + parser_stack_push_uint8 (context_p, SCAN_STACK_LET); + return SCAN_KEEP_TOKEN; + } + + scanner_info_t *info_p = scanner_insert_info (context_p, source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_LET_EXPRESSION; + + lexer_lit_location_t *lit_location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &let_literal); + lit_location_p->type |= SCANNER_LITERAL_IS_USED; + + if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) + { + lit_location_p->type |= SCANNER_LITERAL_NO_REG; + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_KEEP_TOKEN; + } + + if (JERRY_UNLIKELY (lexer_token_is_async (context_p))) + { + scanner_context_p->async_source_p = context_p->source_p; + + if (scanner_check_async_function (context_p, scanner_context_p)) + { + scanner_context_p->mode = SCAN_MODE_STATEMENT; + } + return SCAN_KEEP_TOKEN; + } + + scanner_add_reference (context_p, scanner_context_p); + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + + return SCAN_KEEP_TOKEN; +} /* scanner_scan_statement */ + +/** + * Scan statement terminator. + * + * @return SCAN_NEXT_TOKEN to read the next token, or SCAN_KEEP_TOKEN to do nothing + */ +static scan_return_types_t +scanner_scan_statement_end (parser_context_t *context_p, /**< context */ + scanner_context_t *scanner_context_p, /**< scanner context */ + lexer_token_type_t type) /**< current token type */ +{ + bool terminator_found = false; + + if (type == LEXER_SEMICOLON) + { + lexer_next_token (context_p); + terminator_found = true; + } + + while (true) + { + type = (lexer_token_type_t) context_p->token.type; + + switch (context_p->stack_top_uint8) + { + case SCAN_STACK_SCRIPT: + case SCAN_STACK_SCRIPT_FUNCTION: + { + if (type == LEXER_EOS) + { + return SCAN_NEXT_TOKEN; + } + break; + } + case SCAN_STACK_BLOCK_STATEMENT: + case SCAN_STACK_CLASS_STATEMENT: + case SCAN_STACK_FUNCTION_STATEMENT: + { + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + if (context_p->stack_top_uint8 != SCAN_STACK_CLASS_STATEMENT) + { + scanner_pop_literal_pool (context_p, scanner_context_p); + } + + terminator_found = true; + parser_stack_pop_uint8 (context_p); +#if JERRY_MODULE_SYSTEM + scanner_context_p->active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; +#endif /* JERRY_MODULE_SYSTEM */ + lexer_next_token (context_p); + continue; + } + case SCAN_STACK_FUNCTION_EXPRESSION: + case SCAN_STACK_FUNCTION_ARROW: + { + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + + if (context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_ARROW) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + } + + scanner_pop_literal_pool (context_p, scanner_context_p); + parser_stack_pop_uint8 (context_p); + +#if JERRY_MODULE_SYSTEM + if (context_p->stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT) + { + terminator_found = true; + parser_stack_pop_uint8 (context_p); + lexer_next_token (context_p); + continue; + } +#endif /* JERRY_MODULE_SYSTEM */ + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_FUNCTION_PROPERTY: + { + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + bool has_super_reference = + (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE) != 0; + + scanner_pop_literal_pool (context_p, scanner_context_p); + parser_stack_pop_uint8 (context_p); + + if (context_p->stack_top_uint8 == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR + || context_p->stack_top_uint8 == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) + { + scanner_context_p->mode = SCAN_MODE_CLASS_BODY; + return SCAN_KEEP_TOKEN; + } + + if (has_super_reference && context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL) + { + *parser_stack_get_prev_uint8 (context_p) |= SCANNER_LITERAL_OBJECT_HAS_SUPER; + } + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + return SCAN_KEEP_TOKEN; + } + + if (context_p->token.type != LEXER_COMMA) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_SWITCH_BLOCK: + { + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + scanner_switch_statement_t switch_statement; + + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &switch_statement, sizeof (scanner_switch_statement_t)); + + scanner_context_p->active_switch_statement = switch_statement; + + scanner_pop_literal_pool (context_p, scanner_context_p); + + terminator_found = true; + lexer_next_token (context_p); + continue; + } + case SCAN_STACK_IF_STATEMENT: + { + parser_stack_pop_uint8 (context_p); + + if (type == LEXER_KEYW_ELSE && (terminator_found || (context_p->token.flags & LEXER_WAS_NEWLINE))) + { + scanner_check_function_after_if (context_p, scanner_context_p); + return SCAN_KEEP_TOKEN; + } + + continue; + } + case SCAN_STACK_WITH_STATEMENT: + { + scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p; + + JERRY_ASSERT (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH); + + parser_stack_pop_uint8 (context_p); + + if (context_p->stack_top_uint8 == 0) + { + literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_WITH; + } + + parser_stack_pop_uint8 (context_p); + continue; + } + case SCAN_STACK_DO_STATEMENT: + { + parser_stack_pop_uint8 (context_p); + + if (type != LEXER_KEYW_WHILE || (!terminator_found && !(context_p->token.flags & LEXER_WAS_NEWLINE))) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + if (context_p->token.type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_DO_EXPRESSION); + scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION; + return SCAN_NEXT_TOKEN; + } + case SCAN_STACK_DO_EXPRESSION: + { + parser_stack_pop_uint8 (context_p); + terminator_found = true; + continue; + } + case SCAN_STACK_CLASS_STATIC_BLOCK: + { + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + scanner_pop_literal_pool (context_p, scanner_context_p); + scanner_source_start_t start_range; + parser_stack_pop_uint8 (context_p); + parser_stack_pop (context_p, &start_range, sizeof (scanner_source_start_t)); + + scanner_context_p->mode = SCAN_MODE_CLASS_BODY_NO_SCAN; + + scanner_location_info_t *location_info_p; + location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p, + start_range.source_p, + sizeof (scanner_location_info_t)); + + location_info_p->info.type = SCANNER_TYPE_CLASS_STATIC_BLOCK_END; + location_info_p->location.source_p = context_p->source_p; + location_info_p->location.line = context_p->token.line; + location_info_p->location.column = context_p->token.column; + + lexer_scan_identifier (context_p, (lexer_parse_options_t) ((unsigned int) LEXER_PARSE_CHECK_KEYWORDS | (unsigned int) LEXER_PARSE_NO_STRICT_IDENT_ERROR)); + return SCAN_KEEP_TOKEN; + } + case SCAN_STACK_PRIVATE_BLOCK_EARLY: + { + parser_list_iterator_t literal_iterator; + lexer_lit_location_t *literal_p; + + parser_list_iterator_init (&scanner_context_p->active_literal_pool_p->literal_pool, &literal_iterator); + + while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL) + { + if ((literal_p->type & (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)) + && (literal_p->type & SCANNER_LITERAL_IS_USED)) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + } + /* FALLTHRU */ + } + case SCAN_STACK_PRIVATE_BLOCK: + { + parser_stack_pop_uint8 (context_p); + scanner_pop_literal_pool (context_p, scanner_context_p); + continue; + } +#if JERRY_MODULE_SYSTEM + case SCAN_STACK_EXPORT_DEFAULT: + { + parser_stack_pop_uint8 (context_p); + lexer_lit_location_t *location_p = + scanner_add_custom_literal (context_p, scanner_context_p->active_literal_pool_p, &lexer_default_literal); + location_p->type |= SCANNER_LITERAL_IS_VAR; + continue; + } +#endif /* JERRY_MODULE_SYSTEM */ + default: + { + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_TRY_STATEMENT + || context_p->stack_top_uint8 == SCAN_STACK_CATCH_STATEMENT); + + if (type != LEXER_RIGHT_BRACE) + { + break; + } + + uint8_t stack_top = context_p->stack_top_uint8; + parser_stack_pop_uint8 (context_p); + lexer_next_token (context_p); + + scanner_pop_literal_pool (context_p, scanner_context_p); + + /* A finally statement is optional after a try or catch statement. */ + if (context_p->token.type == LEXER_KEYW_FINALLY) + { + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_raise_error (context_p); + } + + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + literal_pool_p->source_p = context_p->source_p; + + parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT); + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + + if (stack_top == SCAN_STACK_CATCH_STATEMENT) + { + terminator_found = true; + continue; + } + + /* A catch statement must be present after a try statement unless a finally is provided. */ + if (context_p->token.type != LEXER_KEYW_CATCH) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + scanner_literal_pool_t *literal_pool_p; + literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0); + literal_pool_p->source_p = context_p->source_p; + parser_stack_push_uint8 (context_p, SCAN_STACK_CATCH_STATEMENT); + + if (context_p->token.type == LEXER_LEFT_BRACE) + { + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + + if (context_p->token.type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE) + { + scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_CATCH, false); + + if (context_p->token.type == LEXER_LEFT_SQUARE) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); + scanner_context_p->mode = SCAN_MODE_BINDING; + return SCAN_NEXT_TOKEN; + } + + parser_stack_push_uint8 (context_p, 0); + parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); + scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME; + return SCAN_KEEP_TOKEN; + } + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_lit_location_t *lit_location_p = scanner_add_literal (context_p, scanner_context_p); + lit_location_p->type |= SCANNER_LITERAL_IS_LOCAL; + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + return SCAN_NEXT_TOKEN; + } + } + + if (!terminator_found && !(context_p->token.flags & LEXER_WAS_NEWLINE)) + { + scanner_raise_error (context_p); + } + + scanner_context_p->mode = SCAN_MODE_STATEMENT; + return SCAN_KEEP_TOKEN; + } +} /* scanner_scan_statement_end */ + +/** + * Scan the whole source code. + */ +void JERRY_ATTR_NOINLINE +scanner_scan_all (parser_context_t *context_p) /**< context */ +{ + scanner_context_t scanner_context; + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + JERRY_DEBUG_MSG ("\n--- Scanning start ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + scanner_context.context_status_flags = context_p->status_flags; + scanner_context.status_flags = SCANNER_CONTEXT_NO_FLAGS; + scanner_context.binding_type = SCANNER_BINDING_NONE; + scanner_context.active_binding_list_p = NULL; + scanner_context.active_literal_pool_p = NULL; + scanner_context.active_switch_statement.last_case_p = NULL; + scanner_context.end_arguments_p = NULL; + scanner_context.async_source_p = NULL; + + /* This assignment must be here because of Apple compilers. */ + context_p->u.scanner_context_p = &scanner_context; + context_p->global_status_flags |= ECMA_PARSE_INTERNAL_PRE_SCANNING; + + parser_stack_init (context_p); + + PARSER_TRY (context_p->try_buffer) + { + if (context_p->arguments_start_p == NULL) + { + context_p->source_p = context_p->source_start_p; + context_p->source_end_p = context_p->source_start_p + context_p->source_size; + + uint16_t status_flags = + (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_NO_ARGUMENTS | SCANNER_LITERAL_POOL_CAN_EVAL); + + if (context_p->status_flags & PARSER_IS_STRICT) + { + status_flags |= SCANNER_LITERAL_POOL_IS_STRICT; + } + + scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, &scanner_context, status_flags); + literal_pool_p->source_p = context_p->source_start_p; + + parser_stack_push_uint8 (context_p, SCAN_STACK_SCRIPT); + + lexer_next_token (context_p); + scanner_check_directives (context_p, &scanner_context); + } + else + { + context_p->source_p = context_p->arguments_start_p; + context_p->source_end_p = context_p->arguments_start_p + context_p->arguments_size; + + uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; + + if (context_p->status_flags & PARSER_IS_STRICT) + { + status_flags |= SCANNER_LITERAL_POOL_IS_STRICT; + } + + if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION) + { + status_flags |= SCANNER_LITERAL_POOL_GENERATOR; + } + if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION) + { + status_flags |= SCANNER_LITERAL_POOL_ASYNC; + } + + scanner_push_literal_pool (context_p, &scanner_context, status_flags); + scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; + parser_stack_push_uint8 (context_p, SCAN_STACK_SCRIPT_FUNCTION); + + /* Faking the first token. */ + context_p->token.type = LEXER_LEFT_PAREN; + } + + while (true) + { + lexer_token_type_t type = (lexer_token_type_t) context_p->token.type; + scan_stack_modes_t stack_top = (scan_stack_modes_t) context_p->stack_top_uint8; + + switch (scanner_context.mode) + { + case SCAN_MODE_PRIMARY_EXPRESSION: + { + if (type == LEXER_ADD || type == LEXER_SUBTRACT || LEXER_IS_UNARY_OP_TOKEN (type)) + { + break; + } + /* FALLTHRU */ + } + case SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW: + { + if (scanner_scan_primary_expression (context_p, &scanner_context, type, stack_top) != SCAN_NEXT_TOKEN) + { + continue; + } + break; + } + case SCAN_MODE_CLASS_DECLARATION: + { + if (context_p->token.type == LEXER_KEYW_EXTENDS) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_EXTENDS); + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + else if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_raise_error (context_p); + } + + scanner_context.mode = SCAN_MODE_CLASS_BODY; + /* FALLTHRU */ + } + case SCAN_MODE_CLASS_BODY: + { + lexer_skip_empty_statements (context_p); + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + /* FALLTHRU */ + } + case SCAN_MODE_CLASS_BODY_NO_SCAN: + { + JERRY_ASSERT (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR + || stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR); + JERRY_ASSERT (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME); + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + parser_stack_pop_uint8 (context_p); + + scanner_class_info_t *private_members_p; + parser_stack_pop (context_p, &private_members_p, sizeof (scanner_class_info_t *)); + + private_members_p->info.u8_arg |= SCANNER_SUCCESSFUL_CLASS_SCAN; + + scanner_pop_literal_pool (context_p, &scanner_context); + + JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_CLASS_STATEMENT + || context_p->stack_top_uint8 == SCAN_STACK_CLASS_EXPRESSION); + + if (context_p->stack_top_uint8 == SCAN_STACK_CLASS_STATEMENT) + { + /* The token is kept to disallow consuming a semicolon after it. */ + scanner_context.mode = SCAN_MODE_STATEMENT_END; + continue; + } + + scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + parser_stack_pop_uint8 (context_p); + +#if JERRY_MODULE_SYSTEM + if (context_p->stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT) + { + /* The token is kept to disallow consuming a semicolon after it. */ + parser_stack_change_last_uint8 (context_p, SCAN_STACK_CLASS_STATEMENT); + scanner_context.mode = SCAN_MODE_STATEMENT_END; + continue; + } +#endif /* JERRY_MODULE_SYSTEM */ + break; + } + + bool is_private = false; + scanner_private_field_flags_t private_field_flags = SCANNER_PRIVATE_FIELD_PROPERTY; + + if (context_p->token.type == LEXER_HASHMARK) + { + is_private = true; + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + lexer_next_token (context_p); + } + + bool identifier_found = false; + + if (context_p->token.type == LEXER_LITERAL && LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type) + && lexer_compare_literal_to_string (context_p, "constructor", 11) + && stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR) + { + parser_stack_pop_uint8 (context_p); + scanner_class_info_t *private_members_p; + parser_stack_pop (context_p, &private_members_p, sizeof (scanner_class_info_t *)); + private_members_p->info.u8_arg = SCANNER_CONSTRUCTOR_EXPLICIT; + parser_stack_push (context_p, &private_members_p, sizeof (scanner_class_info_t *)); + parser_stack_push_uint8 (context_p, SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR); + } + else if (lexer_token_is_identifier (context_p, "static", 6)) + { + scanner_source_start_t static_start; + static_start.source_p = context_p->source_p - 1; + + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + identifier_found = true; + private_field_flags = (scanner_private_field_flags_t) ((unsigned int) private_field_flags | (unsigned int) SCANNER_PRIVATE_FIELD_STATIC); + + if (!is_private && context_p->token.type == LEXER_LEFT_BRACE) + { + parser_stack_push (context_p, &static_start, sizeof (scanner_source_start_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_STATIC_BLOCK); + + scanner_literal_pool_t *literal_pool_p = + scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); + literal_pool_p->source_p = context_p->source_p - 1; + + lexer_next_token (context_p); + + scanner_context.mode = SCAN_MODE_STATEMENT_OR_TERMINATOR; + + continue; + } + } + + scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; + + uint16_t literal_pool_flags = SCANNER_LITERAL_POOL_FUNCTION; + + private_field_flags = ((bool)private_field_flags || lexer_token_is_identifier (context_p, "get", 3) ? SCANNER_PRIVATE_FIELD_GETTER : (scanner_private_field_flags_t) 0); + private_field_flags = ((bool)private_field_flags || lexer_token_is_identifier (context_p, "set", 3) ? SCANNER_PRIVATE_FIELD_SETTER : (scanner_private_field_flags_t) 0); + + if (private_field_flags & SCANNER_PRIVATE_FIELD_GETTER_SETTER) + { + private_field_flags = (scanner_private_field_flags_t) ((uint32_t) private_field_flags & ~(uint32_t) SCANNER_PRIVATE_FIELD_PROPERTY); + + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + identifier_found = true; + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + if (is_private) + { + private_field_flags = (scanner_private_field_flags_t) ((int) private_field_flags | (int) SCANNER_PRIVATE_FIELD_METHOD); + scanner_add_private_identifier (context_p, private_field_flags); + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); + continue; + } + } + else if (lexer_token_is_identifier (context_p, "async", 5)) + { + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + identifier_found = true; + + if (!(context_p->token.flags & LEXER_WAS_NEWLINE)) + { + if (context_p->token.type == LEXER_LEFT_PAREN) + { + if (is_private) + { + private_field_flags = (scanner_private_field_flags_t) ((int) private_field_flags | (int) SCANNER_PRIVATE_FIELD_METHOD); + scanner_add_private_identifier (context_p, private_field_flags); + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); + continue; + } + + literal_pool_flags |= SCANNER_LITERAL_POOL_ASYNC; + + if (context_p->token.type == LEXER_MULTIPLY) + { + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; + } + } + } + else if (context_p->token.type == LEXER_MULTIPLY) + { + if (is_private) + { + scanner_raise_error (context_p); + } + + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; + } + + if (context_p->token.type == LEXER_LEFT_SQUARE) + { + if (is_private) + { + scanner_raise_error (context_p); + } + + if (literal_pool_flags != SCANNER_LITERAL_POOL_FUNCTION) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + } + + parser_stack_push_uint8 (context_p, SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (literal_pool_flags)); + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + + if (context_p->token.type == LEXER_HASHMARK) + { + if (is_private) + { + scanner_raise_error (context_p); + } + + is_private = true; + context_p->token.flags |= LEXER_NO_SKIP_SPACES; + lexer_next_token (context_p); + } + + if (is_private) + { + if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)) + { + private_field_flags = (scanner_private_field_flags_t) ((int) private_field_flags | (int) SCANNER_PRIVATE_FIELD_METHOD); + } + + scanner_add_private_identifier (context_p, private_field_flags); + } + + if (context_p->token.type == LEXER_LITERAL) + { + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + identifier_found = true; + } + + if (!identifier_found) + { + scanner_raise_error (context_p); + } + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + if (literal_pool_flags & SCANNER_LITERAL_POOL_GENERATOR) + { + context_p->status_flags |= PARSER_IS_GENERATOR_FUNCTION; + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + scanner_push_literal_pool (context_p, &scanner_context, literal_pool_flags); + continue; + } + + if (literal_pool_flags & SCANNER_LITERAL_POOL_GENERATOR) + { + scanner_raise_error (context_p); + } + + if (context_p->token.type == LEXER_ASSIGN) + { + scanner_push_class_field_initializer (context_p, &scanner_context); + break; + } + + if (context_p->token.type == LEXER_SEMICOLON) + { + scanner_context.mode = SCAN_MODE_CLASS_BODY; + continue; + } + + if (context_p->token.type != LEXER_RIGHT_BRACE && !(context_p->token.flags & LEXER_WAS_NEWLINE)) + { + scanner_raise_error (context_p); + } + + scanner_context.mode = SCAN_MODE_CLASS_BODY_NO_SCAN; + continue; + } + case SCAN_MODE_POST_PRIMARY_EXPRESSION: + { + if (scanner_scan_post_primary_expression (context_p, &scanner_context, type, stack_top)) + { + break; + } + type = (lexer_token_type_t) context_p->token.type; + /* FALLTHRU */ + } + case SCAN_MODE_PRIMARY_EXPRESSION_END: + { + if (scanner_scan_primary_expression_end (context_p, &scanner_context, type, stack_top) != SCAN_NEXT_TOKEN) + { + continue; + } + break; + } + case SCAN_MODE_STATEMENT_OR_TERMINATOR: + { + if (type == LEXER_RIGHT_BRACE || type == LEXER_EOS) + { + scanner_context.mode = SCAN_MODE_STATEMENT_END; + continue; + } + /* FALLTHRU */ + } + case SCAN_MODE_STATEMENT: + { + if (scanner_scan_statement (context_p, &scanner_context, type, stack_top) != SCAN_NEXT_TOKEN) + { + continue; + } + break; + } + case SCAN_MODE_STATEMENT_END: + { + if (scanner_scan_statement_end (context_p, &scanner_context, type) != SCAN_NEXT_TOKEN) + { + continue; + } + + if (context_p->token.type == LEXER_EOS) + { + goto scan_completed; + } + + break; + } + case SCAN_MODE_VAR_STATEMENT: + { + if (type == LEXER_LEFT_SQUARE || type == LEXER_LEFT_BRACE) + { + uint8_t binding_type = SCANNER_BINDING_VAR; + + if (stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_FOR_LET_START) + { + binding_type = SCANNER_BINDING_LET; + } + else if (stack_top == SCAN_STACK_CONST || stack_top == SCAN_STACK_FOR_CONST_START) + { + binding_type = SCANNER_BINDING_CONST; + } + + scanner_push_destructuring_pattern (context_p, &scanner_context, binding_type, false); + + if (type == LEXER_LEFT_SQUARE) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); + scanner_context.mode = SCAN_MODE_BINDING; + break; + } + + parser_stack_push_uint8 (context_p, 0); + parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); + scanner_context.mode = SCAN_MODE_PROPERTY_NAME; + continue; + } + + if (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + lexer_lit_location_t *literal_p = scanner_add_literal (context_p, &scanner_context); + + if (stack_top != SCAN_STACK_VAR && stack_top != SCAN_STACK_FOR_VAR_START) + { + scanner_detect_invalid_let (context_p, literal_p); + + if (stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_FOR_LET_START) + { + literal_p->type |= SCANNER_LITERAL_IS_LET; + } + else + { + JERRY_ASSERT (stack_top == SCAN_STACK_CONST || stack_top == SCAN_STACK_FOR_CONST_START); + literal_p->type |= SCANNER_LITERAL_IS_CONST; + } + + lexer_next_token (context_p); + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + } + else if (context_p->token.type == LEXER_ASSIGN) + { + scanner_binding_literal_t binding_literal; + binding_literal.literal_p = literal_p; + + parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); + } + } + else + { + if (!(literal_p->type & SCANNER_LITERAL_IS_VAR)) + { + scanner_detect_invalid_var (context_p, &scanner_context, literal_p); + literal_p->type |= SCANNER_LITERAL_IS_VAR; + + if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) + { + literal_p->type |= SCANNER_LITERAL_NO_REG; + } + } + + lexer_next_token (context_p); + } + +#if JERRY_MODULE_SYSTEM + if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT) + { + literal_p->type |= SCANNER_LITERAL_NO_REG; + } +#endif /* JERRY_MODULE_SYSTEM */ + + switch (context_p->token.type) + { + case LEXER_ASSIGN: + { + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + /* FALLTHRU */ + } + case LEXER_COMMA: + { + lexer_next_token (context_p); + continue; + } + } + + if (SCANNER_IS_FOR_START (stack_top)) + { +#if JERRY_MODULE_SYSTEM + JERRY_ASSERT (!(scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT)); +#endif /* JERRY_MODULE_SYSTEM */ + + if (context_p->token.type != LEXER_SEMICOLON && context_p->token.type != LEXER_KEYW_IN + && !SCANNER_IDENTIFIER_IS_OF ()) + { + scanner_raise_error (context_p); + } + + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + continue; + } + + JERRY_ASSERT (stack_top == SCAN_STACK_VAR || stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_CONST); + +#if JERRY_MODULE_SYSTEM + scanner_context.active_literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_IN_EXPORT; +#endif /* JERRY_MODULE_SYSTEM */ + + scanner_context.mode = SCAN_MODE_STATEMENT_END; + parser_stack_pop_uint8 (context_p); + continue; + } + case SCAN_MODE_FUNCTION_ARGUMENTS: + { + JERRY_ASSERT (stack_top == SCAN_STACK_SCRIPT_FUNCTION || stack_top == SCAN_STACK_FUNCTION_STATEMENT + || stack_top == SCAN_STACK_FUNCTION_EXPRESSION || stack_top == SCAN_STACK_FUNCTION_PROPERTY); + + scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p; + + JERRY_ASSERT (literal_pool_p != NULL && (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)); + + literal_pool_p->source_p = context_p->source_p; + + if (JERRY_UNLIKELY (scanner_context.async_source_p != NULL)) + { + literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ASYNC; + literal_pool_p->source_p = scanner_context.async_source_p; + scanner_context.async_source_p = NULL; + } + + if (type != LEXER_LEFT_PAREN) + { + scanner_raise_error (context_p); + } + lexer_next_token (context_p); + + /* FALLTHRU */ + } + case SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS: + { + if (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS) + { + lexer_lit_location_t *argument_literal_p; + + do + { + if (context_p->token.type == LEXER_THREE_DOTS) + { + scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT; + lexer_next_token (context_p); + } + + if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE) + { + argument_literal_p = NULL; + break; + } + + if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_raise_error (context_p); + } + + argument_literal_p = scanner_append_argument (context_p, &scanner_context); + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_COMMA) + { + break; + } + + lexer_next_token (context_p); + } while (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS); + + if (argument_literal_p == NULL) + { + scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT; + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PARAMETERS); + scanner_append_hole (context_p, &scanner_context); + scanner_push_destructuring_pattern (context_p, &scanner_context, SCANNER_BINDING_ARG, false); + + if (context_p->token.type == LEXER_LEFT_SQUARE) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); + scanner_context.mode = SCAN_MODE_BINDING; + break; + } + + parser_stack_push_uint8 (context_p, 0); + parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); + scanner_context.mode = SCAN_MODE_PROPERTY_NAME; + continue; + } + + if (context_p->token.type == LEXER_ASSIGN) + { + scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT; + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PARAMETERS); + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (argument_literal_p->type & SCANNER_LITERAL_IS_USED) + { + JERRY_ASSERT (argument_literal_p->type & SCANNER_LITERAL_EARLY_CREATE); + break; + } + + scanner_binding_literal_t binding_literal; + binding_literal.literal_p = argument_literal_p; + + parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); + break; + } + } + + if (context_p->token.type == LEXER_EOS && stack_top == SCAN_STACK_SCRIPT_FUNCTION) + { + /* End of argument parsing. */ + scanner_info_t *scanner_info_p = (scanner_info_t *) scanner_malloc (context_p, sizeof (scanner_info_t)); + scanner_info_p->next_p = context_p->next_scanner_info_p; + scanner_info_p->source_p = NULL; + scanner_info_p->type = SCANNER_TYPE_END_ARGUMENTS; + scanner_context.end_arguments_p = scanner_info_p; + + context_p->next_scanner_info_p = scanner_info_p; + context_p->source_p = context_p->source_start_p; + context_p->source_end_p = context_p->source_start_p + context_p->source_size; + lexer_init_line_info (context_p); + + scanner_filter_arguments (context_p, &scanner_context); + lexer_next_token (context_p); + scanner_check_directives (context_p, &scanner_context); + continue; + } + + if (context_p->token.type != LEXER_RIGHT_PAREN) + { + scanner_raise_error (context_p); + } + + lexer_next_token (context_p); + + if (context_p->token.type != LEXER_LEFT_BRACE) + { + scanner_raise_error (context_p); + } + + scanner_filter_arguments (context_p, &scanner_context); + lexer_next_token (context_p); + scanner_check_directives (context_p, &scanner_context); + continue; + } + case SCAN_MODE_PROPERTY_NAME: + { + JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL); + + if (lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS)) + { + lexer_check_property_modifier (context_p); + } + + if (context_p->token.type == LEXER_LEFT_SQUARE) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_COMPUTED_PROPERTY); + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + + if (context_p->token.type == LEXER_THREE_DOTS) + { + *parser_stack_get_prev_uint8 (context_p) |= SCANNER_LITERAL_OBJECT_HAS_REST; + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (scanner_context.binding_type != SCANNER_BINDING_NONE) + { + scanner_context.mode = SCAN_MODE_BINDING; + } + break; + } + + if (context_p->token.type == LEXER_RIGHT_BRACE) + { + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + continue; + } + + if (context_p->token.type == LEXER_PROPERTY_GETTER || context_p->token.type == LEXER_KEYW_ASYNC + || context_p->token.type == LEXER_MULTIPLY || context_p->token.type == LEXER_PROPERTY_SETTER) + { + uint16_t literal_pool_flags = SCANNER_LITERAL_POOL_FUNCTION; + + if (context_p->token.type == LEXER_MULTIPLY) + { + literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; + } + else if (context_p->token.type == LEXER_KEYW_ASYNC) + { + literal_pool_flags |= SCANNER_LITERAL_POOL_ASYNC; + + if (lexer_consume_generator (context_p)) + { + literal_pool_flags |= SCANNER_LITERAL_POOL_GENERATOR; + } + } + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS); + + if (context_p->token.type == LEXER_LEFT_SQUARE) + { + parser_stack_push_uint8 (context_p, SCANNER_FROM_LITERAL_POOL_TO_COMPUTED (literal_pool_flags)); + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + + if (context_p->token.type != LEXER_LITERAL) + { + scanner_raise_error (context_p); + } + + scanner_push_literal_pool (context_p, &scanner_context, literal_pool_flags); + scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; + break; + } + + if (context_p->token.type != LEXER_LITERAL) + { + scanner_raise_error (context_p); + } + + parser_line_counter_t start_line = context_p->token.line; + parser_line_counter_t start_column = context_p->token.column; + bool is_ident = (context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_LEFT_PAREN) + { + scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION); + + parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_PROPERTY); + scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; + continue; + } + + if (is_ident + && (context_p->token.type == LEXER_COMMA || context_p->token.type == LEXER_RIGHT_BRACE + || context_p->token.type == LEXER_ASSIGN)) + { + context_p->source_p = context_p->token.lit_location.char_p; + context_p->line = start_line; + context_p->column = start_column; + + lexer_next_token (context_p); + + JERRY_ASSERT (context_p->token.type != LEXER_LITERAL + || context_p->token.lit_location.type == LEXER_IDENT_LITERAL); + + if (context_p->token.type != LEXER_LITERAL) + { + scanner_raise_error (context_p); + } + + if (scanner_context.binding_type != SCANNER_BINDING_NONE) + { + scanner_context.mode = SCAN_MODE_BINDING; + continue; + } + + scanner_add_reference (context_p, &scanner_context); + + lexer_next_token (context_p); + + if (context_p->token.type == LEXER_ASSIGN) + { + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION_END; + continue; + } + + if (context_p->token.type != LEXER_COLON) + { + scanner_raise_error (context_p); + } + + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + + if (scanner_context.binding_type != SCANNER_BINDING_NONE) + { + scanner_context.mode = SCAN_MODE_BINDING; + } + break; + } + case SCAN_MODE_BINDING: + { + JERRY_ASSERT (scanner_context.binding_type == SCANNER_BINDING_VAR + || scanner_context.binding_type == SCANNER_BINDING_LET + || scanner_context.binding_type == SCANNER_BINDING_CATCH + || scanner_context.binding_type == SCANNER_BINDING_CONST + || scanner_context.binding_type == SCANNER_BINDING_ARG + || scanner_context.binding_type == SCANNER_BINDING_ARROW_ARG); + + if (type == LEXER_THREE_DOTS) + { + lexer_next_token (context_p); + type = (lexer_token_type_t) context_p->token.type; + } + + if (type == LEXER_LEFT_SQUARE || type == LEXER_LEFT_BRACE) + { + scanner_push_destructuring_pattern (context_p, &scanner_context, scanner_context.binding_type, true); + + if (type == LEXER_LEFT_SQUARE) + { + parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL); + break; + } + + parser_stack_push_uint8 (context_p, 0); + parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL); + scanner_context.mode = SCAN_MODE_PROPERTY_NAME; + continue; + } + + if (type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL) + { + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + continue; + } + + lexer_lit_location_t *literal_p = scanner_add_literal (context_p, &scanner_context); + + scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION; + + if (scanner_context.binding_type == SCANNER_BINDING_VAR) + { + if (!(literal_p->type & SCANNER_LITERAL_IS_VAR)) + { + scanner_detect_invalid_var (context_p, &scanner_context, literal_p); + literal_p->type |= SCANNER_LITERAL_IS_VAR; + + if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH) + { + literal_p->type |= SCANNER_LITERAL_NO_REG; + } + } + break; + } + + if (scanner_context.binding_type == SCANNER_BINDING_ARROW_ARG) + { + literal_p->type |= SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG; + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + break; + } + } + else + { + scanner_detect_invalid_let (context_p, literal_p); + + if (scanner_context.binding_type <= SCANNER_BINDING_CATCH) + { + JERRY_ASSERT ((scanner_context.binding_type == SCANNER_BINDING_LET) + || (scanner_context.binding_type == SCANNER_BINDING_CATCH)); + + literal_p->type |= SCANNER_LITERAL_IS_LET; + } + else + { + literal_p->type |= SCANNER_LITERAL_IS_CONST; + + if (scanner_context.binding_type == SCANNER_BINDING_ARG) + { + literal_p->type |= SCANNER_LITERAL_IS_ARG; + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + break; + } + } + } + + if (literal_p->type & SCANNER_LITERAL_IS_USED) + { + literal_p->type |= SCANNER_LITERAL_EARLY_CREATE; + break; + } + } + + scanner_binding_item_t *binding_item_p; + binding_item_p = (scanner_binding_item_t *) scanner_malloc (context_p, sizeof (scanner_binding_item_t)); + + binding_item_p->next_p = scanner_context.active_binding_list_p->items_p; + binding_item_p->literal_p = literal_p; + + scanner_context.active_binding_list_p->items_p = binding_item_p; + + lexer_next_token (context_p); + if (context_p->token.type != LEXER_ASSIGN) + { + continue; + } + + scanner_binding_literal_t binding_literal; + binding_literal.literal_p = literal_p; + + parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t)); + parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT); + + scanner_context.mode = SCAN_MODE_PRIMARY_EXPRESSION; + break; + } + } + + lexer_next_token (context_p); + } + +scan_completed: + if (context_p->stack_top_uint8 != SCAN_STACK_SCRIPT && context_p->stack_top_uint8 != SCAN_STACK_SCRIPT_FUNCTION) + { + scanner_raise_error (context_p); + } + + scanner_pop_literal_pool (context_p, &scanner_context); + + JERRY_ASSERT (scanner_context.active_binding_list_p == NULL); + JERRY_ASSERT (scanner_context.active_literal_pool_p == NULL); + +#ifndef JERRY_NDEBUG + scanner_context.context_status_flags |= PARSER_SCANNING_SUCCESSFUL; +#endif /* !JERRY_NDEBUG */ + } + PARSER_CATCH + { + while (scanner_context.active_binding_list_p != NULL) + { + scanner_pop_binding_list (&scanner_context); + } + + if (JERRY_UNLIKELY (context_p->error != PARSER_ERR_OUT_OF_MEMORY)) + { + /* Ignore the errors thrown by the lexer. */ + context_p->error = PARSER_ERR_NO_ERROR; + + /* The following code may allocate memory, so it is enclosed in a try/catch. */ + PARSER_TRY (context_p->try_buffer) + { + if (scanner_context.status_flags & SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION) + { + JERRY_ASSERT (scanner_context.async_source_p != NULL); + + scanner_info_t *info_p; + info_p = scanner_insert_info (context_p, scanner_context.async_source_p, sizeof (scanner_info_t)); + info_p->type = SCANNER_TYPE_ERR_ASYNC_FUNCTION; + } + + while (scanner_context.active_literal_pool_p != NULL) + { + scanner_pop_literal_pool (context_p, &scanner_context); + } + } + PARSER_CATCH + { + JERRY_ASSERT (context_p->error == PARSER_ERR_OUT_OF_MEMORY); + } + PARSER_TRY_END + } + + JERRY_ASSERT (context_p->error == PARSER_ERR_NO_ERROR || context_p->error == PARSER_ERR_OUT_OF_MEMORY); + + if (context_p->error == PARSER_ERR_OUT_OF_MEMORY) + { + while (scanner_context.active_literal_pool_p != NULL) + { + scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p; + + scanner_context.active_literal_pool_p = literal_pool_p->prev_p; + + parser_list_free (&literal_pool_p->literal_pool); + scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t)); + } + + parser_stack_free (context_p); + return; + } + } + PARSER_TRY_END + + context_p->status_flags = scanner_context.context_status_flags; + context_p->global_status_flags &= (uint32_t) ~ECMA_PARSE_INTERNAL_PRE_SCANNING; + scanner_reverse_info_list (context_p); + +#if JERRY_PARSER_DUMP_BYTE_CODE + if (context_p->is_show_opcodes) + { + scanner_info_t *info_p = context_p->next_scanner_info_p; + const uint8_t *source_start_p = + (context_p->arguments_start_p == NULL ? context_p->source_start_p : context_p->arguments_start_p); + + while (info_p->type != SCANNER_TYPE_END) + { + const char *name_p = NULL; + bool print_location = false; + + switch (info_p->type) + { + case SCANNER_TYPE_END_ARGUMENTS: + { + JERRY_DEBUG_MSG (" END_ARGUMENTS\n"); + source_start_p = context_p->source_start_p; + break; + } + case SCANNER_TYPE_FUNCTION: + case SCANNER_TYPE_BLOCK: + { + const uint8_t *prev_source_p = info_p->source_p - 1; + const uint8_t *data_p; + + if (info_p->type == SCANNER_TYPE_FUNCTION) + { + data_p = (const uint8_t *) (info_p + 1); + + JERRY_DEBUG_MSG (" FUNCTION: flags: 0x%x declarations: %d", (int) info_p->u8_arg, (int) info_p->u16_arg); + } + else + { + data_p = (const uint8_t *) (info_p + 1); + + JERRY_DEBUG_MSG (" BLOCK:"); + } + + JERRY_DEBUG_MSG (" source:%d\n", (int) (info_p->source_p - source_start_p)); + + while (data_p[0] != SCANNER_STREAM_TYPE_END) + { + switch (data_p[0] & SCANNER_STREAM_TYPE_MASK) + { + case SCANNER_STREAM_TYPE_HOLE: + { + JERRY_DEBUG_MSG (" HOLE\n"); + data_p++; + continue; + } + case SCANNER_STREAM_TYPE_ARGUMENTS: + { + JERRY_DEBUG_MSG (" ARGUMENTS%s%s\n", + (data_p[0] & SCANNER_STREAM_NO_REG) ? " *" : "", + (data_p[0] & SCANNER_STREAM_LOCAL_ARGUMENTS) ? " L" : ""); + data_p++; + continue; + } + case SCANNER_STREAM_TYPE_ARGUMENTS_FUNC: + { + JERRY_DEBUG_MSG (" ARGUMENTS_FUNC%s%s\n", + (data_p[0] & SCANNER_STREAM_NO_REG) ? " *" : "", + (data_p[0] & SCANNER_STREAM_LOCAL_ARGUMENTS) ? " L" : ""); + data_p++; + continue; + } + case SCANNER_STREAM_TYPE_VAR: + { + JERRY_DEBUG_MSG (" VAR "); + break; + } + case SCANNER_STREAM_TYPE_LET: + { + JERRY_DEBUG_MSG (" LET "); + break; + } + case SCANNER_STREAM_TYPE_CONST: + { + JERRY_DEBUG_MSG (" CONST "); + break; + } + case SCANNER_STREAM_TYPE_LOCAL: + { + JERRY_DEBUG_MSG (" LOCAL "); + break; + } +#if JERRY_MODULE_SYSTEM + case SCANNER_STREAM_TYPE_IMPORT: + { + JERRY_DEBUG_MSG (" IMPORT "); + break; + } +#endif /* JERRY_MODULE_SYSTEM */ + case SCANNER_STREAM_TYPE_ARG: + { + JERRY_DEBUG_MSG (" ARG "); + break; + } + case SCANNER_STREAM_TYPE_ARG_VAR: + { + JERRY_DEBUG_MSG (" ARG_VAR "); + break; + } + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG: + { + JERRY_DEBUG_MSG (" DESTRUCTURED_ARG "); + break; + } + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR: + { + JERRY_DEBUG_MSG (" DESTRUCTURED_ARG_VAR "); + break; + } + case SCANNER_STREAM_TYPE_ARG_FUNC: + { + JERRY_DEBUG_MSG (" ARG_FUNC "); + break; + } + case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC: + { + JERRY_DEBUG_MSG (" DESTRUCTURED_ARG_FUNC "); + break; + } + case SCANNER_STREAM_TYPE_FUNC: + { + JERRY_DEBUG_MSG (" FUNC "); + break; + } + default: + { + JERRY_UNREACHABLE (); + data_p++; + continue; + } + } + + size_t length; + + if (!(data_p[0] & SCANNER_STREAM_UINT16_DIFF)) + { + if (data_p[2] != 0) + { + prev_source_p += data_p[2]; + length = 2 + 1; + } + else + { + memcpy (&prev_source_p, data_p + 2 + 1, sizeof (uintptr_t)); + length = 2 + 1 + sizeof (uintptr_t); + } + } + else + { + int32_t diff = ((int32_t) data_p[2]) | ((int32_t) data_p[3]) << 8; + + if (diff <= UINT8_MAX) + { + diff = -diff; + } + + prev_source_p += diff; + length = 2 + 2; + } + + if (data_p[0] & SCANNER_STREAM_EARLY_CREATE) + { + JERRY_ASSERT (data_p[0] & SCANNER_STREAM_NO_REG); + JERRY_DEBUG_MSG ("*"); + } + + if (data_p[0] & SCANNER_STREAM_NO_REG) + { + JERRY_DEBUG_MSG ("* "); + } + + JERRY_DEBUG_MSG ("'%.*s'\n", data_p[1], (char *) prev_source_p); + prev_source_p += data_p[1]; + data_p += length; + } + break; + } + case SCANNER_TYPE_WHILE: + { + name_p = "WHILE"; + print_location = true; + break; + } + case SCANNER_TYPE_FOR: + { + scanner_for_info_t *for_info_p = (scanner_for_info_t *) info_p; + JERRY_DEBUG_MSG (" FOR: source:%d expression:%d[%d:%d] end:%d[%d:%d]\n", + (int) (for_info_p->info.source_p - source_start_p), + (int) (for_info_p->expression_location.source_p - source_start_p), + (int) for_info_p->expression_location.line, + (int) for_info_p->expression_location.column, + (int) (for_info_p->end_location.source_p - source_start_p), + (int) for_info_p->end_location.line, + (int) for_info_p->end_location.column); + break; + } + case SCANNER_TYPE_FOR_IN: + { + name_p = "FOR-IN"; + print_location = true; + break; + } + case SCANNER_TYPE_FOR_OF: + { + name_p = "FOR-OF"; + print_location = true; + break; + } + case SCANNER_TYPE_SWITCH: + { + JERRY_DEBUG_MSG (" SWITCH: source:%d\n", (int) (info_p->source_p - source_start_p)); + + scanner_case_info_t *current_case_p = ((scanner_switch_info_t *) info_p)->case_p; + + while (current_case_p != NULL) + { + JERRY_DEBUG_MSG (" CASE: location:%d[%d:%d]\n", + (int) (current_case_p->location.source_p - source_start_p), + (int) current_case_p->location.line, + (int) current_case_p->location.column); + + current_case_p = current_case_p->next_p; + } + break; + } + case SCANNER_TYPE_CASE: + { + name_p = "CASE"; + print_location = true; + break; + } + case SCANNER_TYPE_INITIALIZER: + { + scanner_location_info_t *location_info_p = (scanner_location_info_t *) info_p; + JERRY_DEBUG_MSG (" INITIALIZER: flags: 0x%x source:%d location:%d[%d:%d]\n", + (int) info_p->u8_arg, + (int) (location_info_p->info.source_p - source_start_p), + (int) (location_info_p->location.source_p - source_start_p), + (int) location_info_p->location.line, + (int) location_info_p->location.column); + break; + } + case SCANNER_TYPE_CLASS_CONSTRUCTOR: + { + JERRY_DEBUG_MSG (" CLASS: source:%d\n", (int) (info_p->source_p - source_start_p)); + print_location = false; + break; + } + case SCANNER_TYPE_CLASS_STATIC_BLOCK_END: + { + name_p = "SCANNER_TYPE_CLASS_STATIC_BLOCK_END"; + print_location = true; + break; + } + case SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END: + { + name_p = "SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END"; + print_location = true; + break; + } + case SCANNER_TYPE_LET_EXPRESSION: + { + JERRY_DEBUG_MSG (" LET_EXPRESSION: source:%d\n", (int) (info_p->source_p - source_start_p)); + break; + } + case SCANNER_TYPE_ERR_REDECLARED: + { + JERRY_DEBUG_MSG (" JERRY_FATAL_REDECLARED: source:%d\n", (int) (info_p->source_p - source_start_p)); + break; + } + case SCANNER_TYPE_ERR_ASYNC_FUNCTION: + { + JERRY_DEBUG_MSG (" JERRY_FATAL_ASYNC_FUNCTION: source:%d\n", (int) (info_p->source_p - source_start_p)); + break; + } + case SCANNER_TYPE_LITERAL_FLAGS: + { + JERRY_DEBUG_MSG (" SCANNER_TYPE_LITERAL_FLAGS: flags: 0x%x source:%d\n", + (int) info_p->u8_arg, + (int) (info_p->source_p - source_start_p)); + print_location = false; + break; + } + case SCANNER_TYPE_EXPORT_MODULE_SPECIFIER: + { + JERRY_DEBUG_MSG (" EXPORT_WITH_MODULE_SPECIFIER: source:%d\n", (int) (info_p->source_p - source_start_p)); + print_location = false; + break; + } + } + + if (print_location) + { + scanner_location_info_t *location_info_p = (scanner_location_info_t *) info_p; + JERRY_DEBUG_MSG (" %s: source:%d location:%d[%d:%d]\n", + name_p, + (int) (location_info_p->info.source_p - source_start_p), + (int) (location_info_p->location.source_p - source_start_p), + (int) location_info_p->location.line, + (int) location_info_p->location.column); + } + + info_p = info_p->next_p; + } + + JERRY_DEBUG_MSG ("\n--- Scanning end ---\n\n"); + } +#endif /* JERRY_PARSER_DUMP_BYTE_CODE */ + + parser_stack_free (context_p); +} /* scanner_scan_all */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner.h new file mode 100644 index 0000000..7865568 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/js-scanner.h @@ -0,0 +1,303 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JS_SCANNER_H +#define JS_SCANNER_H + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup jsparser JavaScript + * @{ + * + * \addtogroup jsparser_scanner Scanner + * @{ + */ + +/** + * Allowed types for scanner_info_t structures. + */ +typedef enum +{ + SCANNER_TYPE_END, /**< mark the last info block */ + SCANNER_TYPE_END_ARGUMENTS, /**< mark the end of function arguments + * (only present if a function script is parsed) */ + SCANNER_TYPE_FUNCTION, /**< declarations in a function */ + SCANNER_TYPE_BLOCK, /**< declarations in a code block (usually enclosed in {}) */ + SCANNER_TYPE_WHILE, /**< while statement */ + SCANNER_TYPE_FOR, /**< for statement */ + SCANNER_TYPE_FOR_IN, /**< for-in statement */ + SCANNER_TYPE_FOR_OF, /**< for-of statement */ + SCANNER_TYPE_SWITCH, /**< switch statement */ + SCANNER_TYPE_CASE, /**< case statement */ + SCANNER_TYPE_INITIALIZER, /**< destructuring binding or assignment pattern with initializer */ + SCANNER_TYPE_LITERAL_FLAGS, /**< object or array literal with non-zero flags (stored in u8_arg) */ + SCANNER_TYPE_CLASS_CONSTRUCTOR, /**< class constructor */ + SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END, /**< class field initializer end */ + SCANNER_TYPE_CLASS_STATIC_BLOCK_END, /**< class static block end */ + SCANNER_TYPE_LET_EXPRESSION, /**< let expression */ + SCANNER_TYPE_ERR_REDECLARED, /**< syntax error: a variable is redeclared */ + SCANNER_TYPE_ERR_ASYNC_FUNCTION, /**< an invalid async function follows */ + SCANNER_TYPE_EXPORT_MODULE_SPECIFIER, /**< export with module specifier */ +} scanner_info_type_t; + +/** + * Source code location which can be used to change the position of parsing. + */ +typedef struct +{ + const uint8_t *source_p; /**< next source byte */ + parser_line_counter_t line; /**< token start line */ + parser_line_counter_t column; /**< token start column */ +} scanner_location_t; + +/** + * Source code range with its start and end position. + */ +typedef struct +{ + const uint8_t *source_end_p; /**< end position */ + scanner_location_t start_location; /**< start location */ +} scanner_range_t; + +/** + * Scanner info blocks which provides information for the parser. + */ +typedef struct scanner_info_t +{ + struct scanner_info_t *next_p; /**< next info structure */ + const uint8_t *source_p; /**< triggering position of this scanner info */ + uint8_t type; /**< type of the scanner info */ + uint8_t u8_arg; /**< custom 8-bit value */ + uint16_t u16_arg; /**< custom 16-bit value */ +} scanner_info_t; + +/** + * Scanner info for class private field + */ +typedef struct scanner_class_private_member_t +{ + lexer_lit_location_t loc; /**< loc */ + uint8_t u8_arg; /**< custom 8-bit value */ + struct scanner_class_private_member_t *prev_p; /**< prev private field */ +} scanner_class_private_member_t; + +/** + * Scanner info extended with class private fields. + */ +typedef struct +{ + scanner_info_t info; /**< header */ + scanner_class_private_member_t *members; /**< first private field */ +} scanner_class_info_t; + +/** + * Scanner info extended with a location. + */ +typedef struct +{ + scanner_info_t info; /**< header */ + scanner_location_t location; /**< location */ +} scanner_location_info_t; + +/** + * Scanner info for "for" statements. + */ +typedef struct +{ + scanner_info_t info; /**< header */ + scanner_location_t expression_location; /**< location of expression start */ + scanner_location_t end_location; /**< location of expression end */ +} scanner_for_info_t; + +/** + * Case statement list for scanner_switch_info_t structure. + */ +typedef struct scanner_case_info_t +{ + struct scanner_case_info_t *next_p; /**< next case statement info */ + scanner_location_t location; /**< location of case statement */ +} scanner_case_info_t; + +/** + * Scanner info for "switch" statements. + */ +typedef struct +{ + scanner_info_t info; /**< header */ + scanner_case_info_t *case_p; /**< list of switch cases */ +} scanner_switch_info_t; + +/* + * Description of compressed streams. + * + * The stream is a sequence of commands which encoded as bytes. The first byte + * contains the type of the command (see scanner_function_compressed_stream_types_t). + * + * The variable declaration commands has two arguments: + * - The first represents the length of the declared identifier + * - The second contains the relative distance from the end of the previous declaration + * Usually the distance is between 1 and 255, and represented as a single byte + * Distances between -256 and 65535 are encoded as two bytes + * Larger distances are encoded as pointers + */ + +/** + * Constants for compressed streams. + */ +typedef enum +{ + SCANNER_STREAM_UINT16_DIFF = (1 << 7), /**< relative distance is between -256 and 65535 */ + SCANNER_STREAM_HAS_ESCAPE = (1 << 6), /**< binding has escape */ + SCANNER_STREAM_NO_REG = (1 << 5), /**< binding cannot be stored in register */ + SCANNER_STREAM_EARLY_CREATE = (1 << 4), /**< binding must be created with ECMA_VALUE_UNINITIALIZED */ + SCANNER_STREAM_LOCAL_ARGUMENTS = SCANNER_STREAM_EARLY_CREATE, /**< arguments is redeclared + * as let/const binding later */ + /* Update SCANNER_STREAM_TYPE_MASK macro if more bits are added. */ +} scanner_compressed_stream_flags_t; + +/** + * Types for compressed streams. + */ +typedef enum +{ + SCANNER_STREAM_TYPE_END, /**< end of scanner data */ + SCANNER_STREAM_TYPE_HOLE, /**< no name is assigned to this argument */ + SCANNER_STREAM_TYPE_ARGUMENTS, /**< arguments object should be created */ + SCANNER_STREAM_TYPE_ARGUMENTS_FUNC, /**< arguments object should be created which + * is later initialized with a function */ + SCANNER_STREAM_TYPE_VAR, /**< var declaration */ + SCANNER_STREAM_TYPE_LET, /**< let declaration */ + SCANNER_STREAM_TYPE_CONST, /**< const declaration */ + SCANNER_STREAM_TYPE_LOCAL, /**< local declaration (e.g. catch block) */ +#if JERRY_MODULE_SYSTEM + SCANNER_STREAM_TYPE_IMPORT, /**< module import */ +#endif /* JERRY_MODULE_SYSTEM */ + /* The next four types must be in this order (see SCANNER_STREAM_TYPE_IS_ARG). */ + SCANNER_STREAM_TYPE_ARG, /**< argument declaration */ + SCANNER_STREAM_TYPE_ARG_VAR, /**< argument declaration which is later copied + * into a variable declared by var statement */ + SCANNER_STREAM_TYPE_DESTRUCTURED_ARG, /**< destructuring argument declaration */ + SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR, /**< destructuring argument declaration which is later + * copied into a variable declared by var statement */ + /* Function types should be at the end. See the SCANNER_STREAM_TYPE_IS_FUNCTION macro. */ + SCANNER_STREAM_TYPE_ARG_FUNC, /**< argument declaration which + * is later initialized with a function */ + SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC, /**< destructuring argument declaration which + * is later initialized with a function */ + SCANNER_STREAM_TYPE_FUNC, /**< function declaration */ +} scanner_compressed_stream_types_t; + +/** + * Mask for decoding the type from the compressed stream. + */ +#define SCANNER_STREAM_TYPE_MASK 0xf + +/** + * Checks whether the decoded type represents a function declaration. + */ +#define SCANNER_STREAM_TYPE_IS_FUNCTION(type) ((type) >= SCANNER_STREAM_TYPE_ARG_FUNC) + +/** + * Checks whether the decoded type represents a function argument. + */ +#define SCANNER_STREAM_TYPE_IS_ARG(type) \ + ((type) >= SCANNER_STREAM_TYPE_ARG && (type) <= SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_VAR) + +/** + * Checks whether the decoded type represents both a function argument and a function declaration. + */ +#define SCANNER_STREAM_TYPE_IS_ARG_FUNC(type) \ + ((type) == SCANNER_STREAM_TYPE_ARG_FUNC || (type) == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC) + +/** + * Checks whether the decoded type represents an arguments declaration + */ +#define SCANNER_STREAM_TYPE_IS_ARGUMENTS(type) \ + ((type) == SCANNER_STREAM_TYPE_ARGUMENTS || (type) == SCANNER_STREAM_TYPE_ARGUMENTS_FUNC) + +/** + * Constants for u8_arg flags in scanner_function_info_t. + */ +typedef enum +{ + SCANNER_FUNCTION_ARGUMENTS_NEEDED = (1 << 0), /**< arguments object needs to be created */ + SCANNER_FUNCTION_HAS_COMPLEX_ARGUMENT = (1 << 1), /**< function has complex (ES2015+) argument definition */ + SCANNER_FUNCTION_LEXICAL_ENV_NEEDED = (1 << 2), /**< lexical environment is needed for the function body */ + SCANNER_FUNCTION_STATEMENT = (1 << 3), /**< function is function statement (not arrow expression) + * this flag must be combined with the type of function (e.g. async) */ + SCANNER_FUNCTION_ASYNC = (1 << 4), /**< function is async function */ + SCANNER_FUNCTION_IS_STRICT = (1 << 5), /**< function is strict */ +} scanner_function_flags_t; + +/** + * Constants for u8_arg flags in scanner_class_info_t. + */ +typedef enum +{ + SCANNER_CONSTRUCTOR_IMPLICIT = 0, /**< implicit constructor */ + SCANNER_CONSTRUCTOR_EXPLICIT = (1 << 0), /**< explicit constructor */ + SCANNER_SUCCESSFUL_CLASS_SCAN = (1 << 1), /**< class scan was successful */ + SCANNER_PRIVATE_FIELD_ACTIVE = (1 << 2), /**< private field is active */ +} scanner_constuctor_flags_t; + +/** + * Constants for u8_arg flags in scanner_class_private_member_t. + */ +typedef enum +{ + SCANNER_PRIVATE_FIELD_PROPERTY = (1 << 0), /**< private field initializer */ + SCANNER_PRIVATE_FIELD_METHOD = (1 << 1), /**< private field method */ + SCANNER_PRIVATE_FIELD_STATIC = (1 << 2), /**< static private property */ + SCANNER_PRIVATE_FIELD_GETTER = (1 << 3), /**< private field getter */ + SCANNER_PRIVATE_FIELD_SETTER = (1 << 4), /**< private field setter */ + SCANNER_PRIVATE_FIELD_SEEN = (1 << 5), /**< private field has already been seen */ + SCANNER_PRIVATE_FIELD_IGNORED = SCANNER_PRIVATE_FIELD_METHOD | SCANNER_PRIVATE_FIELD_STATIC, + SCANNER_PRIVATE_FIELD_GETTER_SETTER = (SCANNER_PRIVATE_FIELD_GETTER | SCANNER_PRIVATE_FIELD_SETTER), + SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER = (SCANNER_PRIVATE_FIELD_PROPERTY | SCANNER_PRIVATE_FIELD_GETTER_SETTER), +} scanner_private_field_flags_t; + +/** + * Object or array literal constants for u8_arg flags in scanner_info_t. + */ +typedef enum +{ + /* These flags affects both array and object literals */ + SCANNER_LITERAL_DESTRUCTURING_FOR = (1 << 0), /**< for loop with destructuring pattern */ + SCANNER_LITERAL_NO_DESTRUCTURING = (1 << 1), /**< this literal cannot be a destructuring pattern */ + /* These flags affects only object literals */ + SCANNER_LITERAL_OBJECT_HAS_SUPER = (1 << 2), /**< super keyword is used in the object literal */ + SCANNER_LITERAL_OBJECT_HAS_REST = (1 << 3), /**< the object literal has a member prefixed with three dots */ +} scanner_literal_flags_t; + +/** + * Option bits for scanner_create_variables function. + */ +typedef enum +{ + SCANNER_CREATE_VARS_NO_OPTS = 0, /**< no options */ + SCANNER_CREATE_VARS_IS_SCRIPT = (1 << 0), /**< create variables for script or direct eval */ + SCANNER_CREATE_VARS_IS_MODULE = (1 << 1), /**< create variables for module */ + SCANNER_CREATE_VARS_IS_FUNCTION_ARGS = (1 << 2), /**< create variables for function arguments */ + SCANNER_CREATE_VARS_IS_FUNCTION_BODY = (1 << 3), /**< create variables for function body */ +} scanner_create_variables_flags_t; + +/** + * @} + * @} + * @} + */ + +#endif /* !JS_SCANNER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/meson.build new file mode 100644 index 0000000..f203fe5 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/meson.build @@ -0,0 +1,32 @@ +source_file = [ + 'byte-code.h', + 'common.h', + 'js-lexer.h', + 'js-parser-limits.h', + 'js-parser.h', + 'js-scanner.h', + 'js-parser-internal.h', + 'js-parser-tagged-template-literal.h', + 'js-scanner-internal.h', + 'parser-errors.h', + 'parser-error-messages.inc.h', + 'byte-code.cpp', + 'common.cpp', + 'js-lexer.cpp', + 'js-parser.cpp', + 'js-parser-expr.cpp', + 'js-parser-mem.cpp', + 'js-parser-module.cpp', + 'js-parser-statm.cpp', + 'js-parser-tagged-template-literal.cpp', + 'js-parser-util.cpp', + 'js-scanner.cpp', + 'js-scanner-ops.cpp', + 'js-scanner-util.cpp', + 'parser-errors.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-error-messages.inc.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-error-messages.inc.h new file mode 100644 index 0000000..233a249 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-error-messages.inc.h @@ -0,0 +1,233 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This file is automatically generated by the gen-strings.py script + * from parser-error-messages.ini. Do not edit! */ + +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_LABEL, "Duplicated label") +PARSER_ERROR_DEF (PARSER_ERR_LEFT_PAREN_EXPECTED, "Expected '(' token") +PARSER_ERROR_DEF (PARSER_ERR_RIGHT_PAREN_EXPECTED, "Expected ')' token") +PARSER_ERROR_DEF (PARSER_ERR_COLON_EXPECTED, "Expected ':' token") +PARSER_ERROR_DEF (PARSER_ERR_SEMICOLON_EXPECTED, "Expected ';' token") +PARSER_ERROR_DEF (PARSER_ERR_RIGHT_SQUARE_EXPECTED, "Expected ']' token") +PARSER_ERROR_DEF (PARSER_ERR_LEFT_BRACE_EXPECTED, "Expected '{' token") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM || JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_RIGHT_BRACE_EXPECTED, "Expected '}' token") +#endif /* JERRY_MODULE_SYSTEM \ +|| JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_NUMBER_TOO_LONG, "Number is too long") +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_REGEXP && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_REGEXP_TOO_LONG, "Regexp is too long") +#endif /* JERRY_BUILTIN_REGEXP && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_STATEMENT_EXPECTED, "Statement expected") +PARSER_ERROR_DEF (PARSER_ERR_STRING_TOO_LONG, "String is too long") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_AS_EXPECTED, "Expected 'as' token") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_IN_EXPECTED, "Expected 'in' token") +PARSER_ERROR_DEF (PARSER_ERR_OF_EXPECTED, "Expected 'of' token") +PARSER_ERROR_DEF (PARSER_ERR_EXPRESSION_EXPECTED, "Expression expected") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM || JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_IDENTIFIER_EXPECTED, "Identifier expected") +#endif /* JERRY_MODULE_SYSTEM \ +|| JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_OCTAL_DIGIT, "Invalid octal digit") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_SWITCH, "Invalid switch body") +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_REGEXP && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_UNKNOWN_REGEXP_FLAG, "Unknown regexp flag") +#endif /* JERRY_BUILTIN_REGEXP && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_BIN_DIGIT, "Invalid binary digit") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_RIGHT_SQUARE, "Unexpected '}' token") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_FROM_EXPECTED, "Expected 'from' token") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_MISSING_EXPONENT, "Missing exponent part") +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_REGEXP && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_REGEXP_FLAG, "Duplicated regexp flag") +#endif /* JERRY_BUILTIN_REGEXP && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_ARGUMENT_LIST_EXPECTED, "Expected argument list") +PARSER_ERROR_DEF (PARSER_ERR_IDENTIFIER_TOO_LONG, "Identifier is too long") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_META_EXPECTED, "Expected 'meta' keyword") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_UNEXPECTED_END, "Unexpected end of input") +PARSER_ERROR_DEF (PARSER_ERR_UNEXPECTED_PRIVATE_FIELD, "Unexpected private field") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_LEFT_BRACE_MULTIPLY_EXPECTED, "Expected '{' or '*' token") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM +PARSER_ERROR_DEF (PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED, "Expected '}' or ',' token") +PARSER_ERROR_DEF (PARSER_ERR_STRING_EXPECTED, "Expected a string literal") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_HEX_DIGIT, "Invalid hexadecimal digit") +#endif /* JERRY_PARSER */ +#if JERRY_BUILTIN_REGEXP && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_UNTERMINATED_REGEXP, "Unterminated regexp literal") +#endif /* JERRY_BUILTIN_REGEXP && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_UNTERMINATED_STRING, "Unterminated string literal") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_FROM_COMMA_EXPECTED, "Expected 'from' or ',' token") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM +PARSER_ERROR_DEF (PARSER_ERR_EXPORT_NOT_DEFINED, "Export not defined in module") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_MODULE_SYSTEM || JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_VARIABLE_REDECLARED, "Local variable is redeclared") +#endif /* JERRY_MODULE_SYSTEM \ +|| JERRY_PARSER */ +#if JERRY_BUILTIN_BIGINT && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_BIGINT, "Number is not a valid BigInt") +#endif /* JERRY_BUILTIN_BIGINT && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_PROPERTY_IDENTIFIER_EXPECTED, "Property identifier expected") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER, "Duplicate exported identifier") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_NEW_TARGET_EXPECTED, "Expected new.target expression") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_CHARACTER, "Invalid (unexpected) character") +PARSER_ERROR_DEF (PARSER_ERR_NON_STRICT_ARG_DEFINITION, "Non-strict argument definition") +PARSER_ERROR_DEF (PARSER_ERR_UNTERMINATED_MULTILINE_COMMENT, "Unterminated multiline comment") +PARSER_ERROR_DEF (PARSER_ERR_CATCH_FINALLY_EXPECTED, "Catch or finally block expected") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE, "Invalid unicode escape sequence") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_IMPORT_BINDING, "Duplicated imported binding name") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_WHILE_EXPECTED, "While expected for do-while loop") +PARSER_ERROR_DEF (PARSER_ERR_DELETE_PRIVATE_FIELD, "Private fields cannot be deleted") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_LHS_FOR_LOOP, "Invalid left-hand-side in for-loop") +PARSER_ERROR_DEF (PARSER_ERR_LEFT_HAND_SIDE_EXP_EXPECTED, "Left-hand-side expression expected") +PARSER_ERROR_DEF (PARSER_ERR_LITERAL_LIMIT_REACHED, "Maximum number of literals reached") +PARSER_ERROR_DEF (PARSER_ERR_STACK_LIMIT_REACHED, "Maximum function stack size reached") +PARSER_ERROR_DEF (PARSER_ERR_AWAIT_NOT_ALLOWED, "Await expression is not allowed here") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_LEFT_BRACE_MULTIPLY_LITERAL_EXPECTED, "Expected '{' or '*' or literal token") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_LHS_ASSIGNMENT, "Invalid left-hand side in assignment") +PARSER_ERROR_DEF (PARSER_ERR_SCOPE_STACK_LIMIT_REACHED, "Maximum depth of scope stack reached") +PARSER_ERROR_DEF (PARSER_ERR_UNEXPECTED_SUPER_KEYWORD, "Super is not allowed to be used here") +PARSER_ERROR_DEF (PARSER_ERR_YIELD_NOT_ALLOWED, "Yield expression is not allowed here") +PARSER_ERROR_DEF (PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS, "Multiple constructors are not allowed") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM +PARSER_ERROR_DEF (PARSER_ERR_MODULE_UNEXPECTED, "Unexpected import or export statement") +#endif /* JERRY_MODULE_SYSTEM */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_IDENTIFIER_AFTER_NUMBER, "Identifier cannot start after a number") +PARSER_ERROR_DEF (PARSER_ERR_MULTIPLE_DEFAULTS_NOT_ALLOWED, "Multiple default cases are not allowed") +PARSER_ERROR_DEF (PARSER_ERR_ARRAY_ITEM_SEPARATOR_EXPECTED, "Expected ',' or ']' after an array item") +PARSER_ERROR_DEF (PARSER_ERR_ILLEGAL_PROPERTY_IN_DECLARATION, "Illegal property in declaration context") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_DESTRUCTURING_PATTERN, "Invalid destructuring assignment target") +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_PRIVATE_FIELD, "Private field has already been declared") +PARSER_ERROR_DEF (PARSER_ERR_NO_ARGUMENTS_EXPECTED, "Property getters must have no arguments") +PARSER_ERROR_DEF (PARSER_ERR_ONE_ARGUMENT_EXPECTED, "Property setters must have one argument") +PARSER_ERROR_DEF (PARSER_ERR_CASE_NOT_IN_SWITCH, "Case statement must be in a switch block") +PARSER_ERROR_DEF (PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, "Class constructor may not be an accessor") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_CONTINUE, "Continue statement must be inside a loop") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_IMPORT_META_REQUIRE_MODULE, "Cannot use 'import.meta' outside a module") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_IDENTIFIER_PART, "Character cannot be part of an identifier") +PARSER_ERROR_DEF (PARSER_ERR_EVAL_CANNOT_ASSIGNED, "Eval cannot be assigned to in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_WITH_NOT_ALLOWED, "With statement not allowed in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_NEW_TARGET_NOT_ALLOWED, "new.target expression is not allowed here") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_IDENTIFIER_START, "Character cannot be start of an identifier") +PARSER_ERROR_DEF (PARSER_ERR_STRICT_IDENT_NOT_ALLOWED, "Identifier name is reserved in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_NULLISH_COALESCING, "Cannot chain nullish with logical AND or OR") +PARSER_ERROR_DEF (PARSER_ERR_DEFAULT_NOT_IN_SWITCH, "Default statement must be in a switch block") +#endif /* JERRY_PARSER */ +#if JERRY_MODULE_SYSTEM && JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_IMPORT_AFTER_NEW, "Module import call is not allowed after new") +#endif /* JERRY_MODULE_SYSTEM && JERRY_PARSER */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_TOO_MANY_CLASS_FIELDS, "Too many computed class fields are declared") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_KEYWORD, "Escape sequences are not allowed in keywords") +PARSER_ERROR_DEF (PARSER_ERR_ARGUMENT_LIMIT_REACHED, "Maximum number of function arguments reached") +PARSER_ERROR_DEF (PARSER_ERR_NEWLINE_NOT_ALLOWED, "Newline is not allowed in strings or regexps") +PARSER_ERROR_DEF (PARSER_ERR_OCTAL_NUMBER_NOT_ALLOWED, "Octal numbers are not allowed in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR, "Class constructor may not be a private method") +PARSER_ERROR_DEF (PARSER_ERR_FOR_AWAIT_NO_OF, "only 'of' form is allowed for for-await loops") +PARSER_ERROR_DEF (PARSER_ERR_ARGUMENTS_CANNOT_ASSIGNED, "Arguments cannot be assigned to in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_BREAK, "Break statement must be inside a loop or switch") +PARSER_ERROR_DEF (PARSER_ERR_OBJECT_ITEM_SEPARATOR_EXPECTED, "Expected ',' or '}' after a property definition") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_BREAK_LABEL, "Labeled statement targeted by a break not found") +#endif /* JERRY_PARSER */ +#if JERRY_PARSER && !(JERRY_BUILTIN_REGEXP) +PARSER_ERROR_DEF (PARSER_ERR_UNSUPPORTED_REGEXP, "Regexp is not supported in the selected profile") +#endif /* JERRY_PARSER && !(JERRY_BUILTIN_REGEXP) */ +#if JERRY_PARSER +PARSER_ERROR_DEF (PARSER_ERR_INVALID_RETURN, "Return statement must be inside a function body") +PARSER_ERROR_DEF (PARSER_ERR_COLON_FOR_CONDITIONAL_EXPECTED, "Expected ':' token for ?: conditional expression") +PARSER_ERROR_DEF (PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER, "Rest parameter must be the last formal parameter") +PARSER_ERROR_DEF (PARSER_ERR_DELETE_IDENT_NOT_ALLOWED, "Deleting identifier is not allowed in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK, "Labelled functions are only allowed inside blocks") +PARSER_ERROR_DEF (PARSER_ERR_REST_PARAMETER_DEFAULT_INITIALIZER, "Rest parameter may not have a default initializer") +PARSER_ERROR_DEF (PARSER_ERR_EVAL_NOT_ALLOWED, "Eval is not allowed to be used here in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_CONTINUE_LABEL, "Labeled statement targeted by a continue not found") +PARSER_ERROR_DEF (PARSER_ERR_LEXICAL_LET_BINDING, "Let binding cannot appear in let/const declarations") +PARSER_ERROR_DEF (PARSER_ERR_UNDECLARED_PRIVATE_FIELD, "Private field must be declared in an enclosing class") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_LHS_PREFIX_OP, "Invalid left-hand side expression in prefix operation") +PARSER_ERROR_DEF (PARSER_ERR_OCTAL_ESCAPE_NOT_ALLOWED, "Octal escape sequences are not allowed in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_SETTER_REST_PARAMETER, "Setter function argument must not be a rest parameter") +PARSER_ERROR_DEF (PARSER_ERR_ARGUMENTS_IN_CLASS_FIELD, "In class field declarations 'arguments' is not allowed") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_LHS_POSTFIX_OP, "Invalid left-hand side expression in postfix operation") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER, "Invalid use of underscore character in number literals") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_EXPONENTIATION, "Left operand of ** operator cannot be unary expression") +PARSER_ERROR_DEF (PARSER_ERR_MISSING_ASSIGN_AFTER_CONST, "Value assignment is expected after a const declaration") +PARSER_ERROR_DEF (PARSER_ERR_ARGUMENTS_NOT_ALLOWED, "Arguments is not allowed to be used here in strict mode") +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_ARGUMENT_NAMES, "Duplicated function argument names are not allowed here") +PARSER_ERROR_DEF (PARSER_ERR_CLASS_STATIC_PROTOTYPE, "Classes may not have a static property called 'prototype'") +PARSER_ERROR_DEF (PARSER_ERR_INVALID_CLASS_CONSTRUCTOR, "Class constructor may not be a generator or async function") +PARSER_ERROR_DEF (PARSER_ERR_TEMPLATE_STR_OCTAL_ESCAPE, "Octal escape sequences are not allowed in template strings") +PARSER_ERROR_DEF (PARSER_ERR_DUPLICATED_PROTO, "Duplicate __proto__ fields are not allowed in object literals") +PARSER_ERROR_DEF (PARSER_ERR_GENERATOR_IN_SINGLE_STATEMENT_POS, + "Generator function cannot appear in a single-statement context") +PARSER_ERROR_DEF (PARSER_ERR_LEXICAL_SINGLE_STATEMENT, + "Lexical declaration cannot appear in a single-statement context") +PARSER_ERROR_DEF (PARSER_ERR_FOR_IN_OF_DECLARATION, "for in-of loop variable declaration may not have an initializer") +PARSER_ERROR_DEF (PARSER_ERR_FOR_AWAIT_NO_ASYNC, "for-await-of is only allowed inside async functions and generators") +PARSER_ERROR_DEF (PARSER_ERR_USE_STRICT_NOT_ALLOWED, + "The 'use strict' directive is not allowed for functions with non-simple arguments") +PARSER_ERROR_DEF (PARSER_ERR_ASSIGNMENT_EXPECTED, + "Unexpected arrow function or yield expression (parentheses around the expression may help)") +#endif /* JERRY_PARSER */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-errors.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-errors.cpp new file mode 100644 index 0000000..e21f9b0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-errors.cpp @@ -0,0 +1,71 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "parser-errors.h" + +#if JERRY_ERROR_MESSAGES +/** + * Struct to store parser error message with its size. + */ +typedef struct +{ + lit_utf8_byte_t *text; /* Text of parser error message. */ + uint8_t size; /* Size of parser error message. */ +} parser_error_message_t; + +/* Error message texts with size. */ +static parser_error_message_t parser_error_messages[] JERRY_ATTR_CONST_DATA = { + { (lit_utf8_byte_t *) "", 0 }, /* PARSER_ERR_EMPTY */ +/** @cond doxygen_suppress */ +#define PARSER_ERROR_DEF(id, utf8_string) { (lit_utf8_byte_t *) utf8_string, sizeof (utf8_string) - 1 }, +#include "parser-error-messages.inc.h" +#undef PARSER_ERROR_DEF + /** @endcond */ +}; +#endif /* JERRY_ERROR_MESSAGES */ + +/** + * Get specified parser error as zero-terminated string + * + * @return pointer to zero-terminated parser error + */ +const lit_utf8_byte_t * +parser_get_error_utf8 (uint32_t id) /**< parser error id */ +{ + JERRY_ASSERT (id < PARSER_ERR_OUT_OF_MEMORY); + +#if JERRY_ERROR_MESSAGES + return parser_error_messages[id].text; +#else /* !JERRY_ERROR_MESSAGES */ + return NULL; +#endif /* JERRY_ERROR_MESSAGES */ +} /* parser_get_error_utf8 */ + +/** + * Get size of specified parser error + * + * @return size in bytes + */ +lit_utf8_size_t +parser_get_error_size (uint32_t id) /**< parser error id */ +{ + JERRY_ASSERT (id < PARSER_ERR_OUT_OF_MEMORY); + +#if JERRY_ERROR_MESSAGES + return parser_error_messages[id].size; +#else /* !JERRY_ERROR_MESSAGES */ + return 0; +#endif /* JERRY_ERROR_MESSAGES */ +} /* parser_get_error_size */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-errors.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-errors.h new file mode 100644 index 0000000..775dee0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/js/parser-errors.h @@ -0,0 +1,44 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PARSER_ERRORS_H +#define PARSER_ERRORS_H + +#include "lit-globals.h" + +typedef enum +{ + PARSER_ERR_EMPTY, +/** @cond doxygen_suppress */ +#if JERRY_ERROR_MESSAGES +#define PARSER_ERROR_DEF(id, ascii_zt_string) id, +#else /* !JERRY_ERROR_MESSAGES */ +#define PARSER_ERROR_DEF(id, ascii_zt_string) id = PARSER_ERR_EMPTY, +#endif /* JERRY_ERROR_MESSAGES */ +#include "parser-error-messages.inc.h" +#undef PARSER_ERROR_DEF + /** @endcond */ + PARSER_ERR_OUT_OF_MEMORY, + PARSER_ERR_INVALID_REGEXP, +#if (JERRY_STACK_LIMIT != 0) + PARSER_ERR_STACK_OVERFLOW, +#endif /* JERRY_STACK_LIMIT != 0 */ + PARSER_ERR_NO_ERROR, +} parser_error_msg_t; + +const lit_utf8_byte_t* parser_get_error_utf8 (uint32_t id); +lit_utf8_size_t parser_get_error_size (uint32_t id); + +#endif /* !PARSER_ERRORS_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/meson.build new file mode 100644 index 0000000..f0519b2 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/meson.build @@ -0,0 +1,2 @@ +subdir('js') +subdir('regexp') diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/meson.build new file mode 100644 index 0000000..2bcc0ad --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/meson.build @@ -0,0 +1,15 @@ +source_file = [ + 're-bytecode.h', + 're-compiler-context.h', + 're-compiler.h', + 're-parser.h', + 're-token.h', + 're-bytecode.cpp', + 're-compiler.cpp', + 're-parser.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-bytecode.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-bytecode.cpp new file mode 100644 index 0000000..8cb0fe3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-bytecode.cpp @@ -0,0 +1,620 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "re-bytecode.h" + +#include "ecma-globals.h" +#include "ecma-regexp-object.h" + +#include "lit-strings.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_bytecode Bytecode + * @{ + */ + +void +re_initialize_regexp_bytecode (re_compiler_ctx_t *re_ctx_p) /**< RegExp bytecode context */ +{ + const size_t initial_size = sizeof (re_compiled_code_t); + re_ctx_p->bytecode_start_p = (uint8_t *) jmem_heap_alloc_block (initial_size); + re_ctx_p->bytecode_size = initial_size; +} /* re_initialize_regexp_bytecode */ + +uint32_t +re_bytecode_size (re_compiler_ctx_t *re_ctx_p) /**< RegExp bytecode context */ +{ + return (uint32_t) re_ctx_p->bytecode_size; +} /* re_bytecode_size */ + +/** + * Append a new bytecode to the and of the bytecode container + */ +static uint8_t * +re_bytecode_reserve (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const size_t size) /**< size */ +{ + const size_t old_size = re_ctx_p->bytecode_size; + const size_t new_size = old_size + size; + re_ctx_p->bytecode_start_p = reinterpret_cast(jmem_heap_realloc_block (re_ctx_p->bytecode_start_p, old_size, new_size)); + re_ctx_p->bytecode_size = new_size; + return re_ctx_p->bytecode_start_p + old_size; +} /* re_bytecode_reserve */ + +/** + * Insert a new bytecode to the bytecode container + */ +static uint8_t * +re_bytecode_insert (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const size_t offset, /**< distance from the start of the container */ + const size_t size) /**< size */ +{ + const size_t tail_size = re_ctx_p->bytecode_size - offset; + re_bytecode_reserve (re_ctx_p, size); + + uint8_t *dest_p = re_ctx_p->bytecode_start_p + offset; + memmove (dest_p + size, dest_p, tail_size); + + return dest_p; +} /* re_bytecode_insert */ + +/** + * Append a byte + */ +void +re_append_byte (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const uint8_t byte) /**< byte value */ +{ + uint8_t *dest_p = re_bytecode_reserve (re_ctx_p, sizeof (uint8_t)); + *dest_p = byte; +} /* re_append_byte */ + +/** + * Insert a byte value + */ +void +re_insert_byte (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const uint32_t offset, /**< distance from the start of the container */ + const uint8_t byte) /**< byte value */ +{ + uint8_t *dest_p = re_bytecode_insert (re_ctx_p, offset, sizeof (uint8_t)); + *dest_p = byte; +} /* re_insert_byte */ + +/** + * Get a single byte and increase bytecode position. + */ +uint8_t +re_get_byte (const uint8_t **bc_p) /**< pointer to bytecode start */ +{ + return *((*bc_p)++); +} /* re_get_byte */ + +/** + * Append a RegExp opcode + */ +void +re_append_opcode (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const re_opcode_t opcode) /**< input opcode */ +{ + re_append_byte (re_ctx_p, (uint8_t) opcode); +} /* re_append_opcode */ + +/** + * Insert a RegExp opcode + */ +void +re_insert_opcode (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const uint32_t offset, /**< distance from the start of the container */ + const re_opcode_t opcode) /**< input opcode */ +{ + re_insert_byte (re_ctx_p, offset, (uint8_t) opcode); +} /* re_insert_opcode */ + +/** + * Get a RegExp opcode and increase the bytecode position + * + * @return current RegExp opcode + */ +re_opcode_t +re_get_opcode (const uint8_t **bc_p) /**< pointer to bytecode start */ +{ + return (re_opcode_t) re_get_byte (bc_p); +} /* re_get_opcode */ + +/** + * Encode 2 byte unsigned integer into the bytecode + */ +static void +re_encode_u16 (uint8_t *dest_p, /**< destination */ + const uint16_t value) /**< value */ +{ + *dest_p++ = (uint8_t) ((value >> 8) & 0xFF); + *dest_p = (uint8_t) (value & 0xFF); +} /* re_encode_u16 */ + +/** + * Encode 4 byte unsigned integer into the bytecode + */ +static void +re_encode_u32 (uint8_t *dest_p, /**< destination */ + const uint32_t value) /**< value */ +{ + *dest_p++ = (uint8_t) ((value >> 24) & 0xFF); + *dest_p++ = (uint8_t) ((value >> 16) & 0xFF); + *dest_p++ = (uint8_t) ((value >> 8) & 0xFF); + *dest_p = (uint8_t) (value & 0xFF); +} /* re_encode_u32 */ + +/** + * Decode 2 byte unsigned integer from bytecode + * + * @return uint16_t value + */ +static uint16_t +re_decode_u16 (const uint8_t *src_p) /**< source */ +{ + uint16_t value = (uint16_t) (((uint16_t) *src_p++) << 8); + value = (uint16_t) (value + *src_p++); + return value; +} /* re_decode_u16 */ + +/** + * Decode 4 byte unsigned integer from bytecode + * + * @return uint32_t value + */ +static uint32_t JERRY_ATTR_NOINLINE +re_decode_u32 (const uint8_t *src_p) /**< source */ +{ + uint32_t value = (uint32_t) (((uint32_t) *src_p++) << 24); + value += (uint32_t) (((uint32_t) *src_p++) << 16); + value += (uint32_t) (((uint32_t) *src_p++) << 8); + value += (uint32_t) (*src_p++); + return value; +} /* re_decode_u32 */ + +/** + * Get the encoded size of an uint32_t value. + * + * @return encoded value size + */ +static inline size_t +re_get_encoded_value_size (uint32_t value) /**< value */ +{ + if (JERRY_LIKELY (value <= RE_VALUE_1BYTE_MAX)) + { + return 1; + } + + return 5; +} /* re_get_encoded_value_size */ + +/* + * Encode a value to the specified position in the bytecode. + */ +static void +re_encode_value (uint8_t *dest_p, /**< position in bytecode */ + const uint32_t value) /**< value */ +{ + if (JERRY_LIKELY (value <= RE_VALUE_1BYTE_MAX)) + { + *dest_p = (uint8_t) value; + return; + } + + *dest_p++ = (uint8_t) (RE_VALUE_4BYTE_MARKER); + re_encode_u32 (dest_p, value); +} /* re_encode_value */ + +/** + * Append a value to the end of the bytecode. + */ +void +re_append_value (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const uint32_t value) /**< value */ +{ + const size_t size = re_get_encoded_value_size (value); + uint8_t *dest_p = re_bytecode_reserve (re_ctx_p, size); + re_encode_value (dest_p, value); +} /* re_append_value */ + +/** + * Insert a value into the bytecode at a specific offset. + */ +void +re_insert_value (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const uint32_t offset, /**< bytecode offset */ + const uint32_t value) /**< value */ +{ + const size_t size = re_get_encoded_value_size (value); + uint8_t *dest_p = re_bytecode_insert (re_ctx_p, offset, size); + re_encode_value (dest_p, value); +} /* re_insert_value */ + +/** + * Read an encoded value from the bytecode. + * + * @return decoded value + */ +uint32_t +re_get_value (const uint8_t **bc_p) /** refence to bytecode pointer */ +{ + uint32_t value = *(*bc_p)++; + if (JERRY_LIKELY (value <= RE_VALUE_1BYTE_MAX)) + { + return value; + } + + value = re_decode_u32 (*bc_p); + *bc_p += sizeof (uint32_t); + return value; +} /* re_get_value */ + +/** + * Append a character to the RegExp bytecode + */ +void +re_append_char (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const lit_code_point_t cp) /**< code point */ +{ + const size_t size = (re_ctx_p->flags & RE_FLAG_UNICODE) ? sizeof (lit_code_point_t) : sizeof (ecma_char_t); + uint8_t *dest_p = re_bytecode_reserve (re_ctx_p, size); + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + re_encode_u32 (dest_p, cp); + return; + } + + JERRY_ASSERT (cp <= LIT_UTF16_CODE_UNIT_MAX); + re_encode_u16 (dest_p, (ecma_char_t) cp); +} /* re_append_char */ + +/** + * Append a character to the RegExp bytecode + */ +void +re_insert_char (re_compiler_ctx_t *re_ctx_p, /**< RegExp bytecode context */ + const uint32_t offset, /**< bytecode offset */ + const lit_code_point_t cp) /**< code point*/ +{ + const size_t size = (re_ctx_p->flags & RE_FLAG_UNICODE) ? sizeof (lit_code_point_t) : sizeof (ecma_char_t); + + uint8_t *dest_p = re_bytecode_insert (re_ctx_p, offset, size); + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + re_encode_u32 (dest_p, cp); + return; + } + + JERRY_ASSERT (cp <= LIT_UTF16_CODE_UNIT_MAX); + re_encode_u16 (dest_p, (ecma_char_t) cp); +} /* re_insert_char */ + +/** + * Decode a character from the bytecode. + * + * @return decoded character + */ +lit_code_point_t +re_get_char (const uint8_t **bc_p, /**< reference to bytecode pointer */ + bool unicode) /**< full unicode mode */ +{ + lit_code_point_t cp; + + if (unicode) + { + cp = re_decode_u32 (*bc_p); + *bc_p += sizeof (lit_code_point_t); + } + else + { + cp = re_decode_u16 (*bc_p); + *bc_p += sizeof (ecma_char_t); + } + + return cp; +} /* re_get_char */ + +#if JERRY_REGEXP_DUMP_BYTE_CODE +static uint32_t +re_get_bytecode_offset (const uint8_t *start_p, /**< bytecode start pointer */ + const uint8_t *current_p) /**< current bytecode pointer */ +{ + return (uint32_t) ((uintptr_t) current_p - (uintptr_t) start_p); +} /* re_get_bytecode_offset */ + +/** + * RegExp bytecode dumper + */ +void +re_dump_bytecode (re_compiler_ctx_t *re_ctx_p) /**< RegExp bytecode context */ +{ + static const char escape_chars[] = { 'd', 'D', 'w', 'W', 's', 'S' }; + + re_compiled_code_t *compiled_code_p = (re_compiled_code_t *) re_ctx_p->bytecode_start_p; + JERRY_DEBUG_MSG ("Flags: 0x%x ", compiled_code_p->header.status_flags); + JERRY_DEBUG_MSG ("Capturing groups: %d ", compiled_code_p->captures_count); + JERRY_DEBUG_MSG ("Non-capturing groups: %d\n", compiled_code_p->non_captures_count); + + const uint8_t *bytecode_start_p = (const uint8_t *) (compiled_code_p + 1); + const uint8_t *bytecode_p = bytecode_start_p; + + while (true) + { + JERRY_DEBUG_MSG ("[%3u] ", (uint32_t) ((uintptr_t) bytecode_p - (uintptr_t) bytecode_start_p)); + re_opcode_t op = *bytecode_p++; + switch (op) + { + case RE_OP_ALTERNATIVE_START: + { + JERRY_DEBUG_MSG ("ALTERNATIVE_START "); + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG ("tail offset: [%3u]\n", offset); + break; + } + case RE_OP_ALTERNATIVE_NEXT: + { + JERRY_DEBUG_MSG ("ALTERNATIVE_NEXT "); + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG ("tail offset: [%3u]\n", offset); + break; + } + case RE_OP_NO_ALTERNATIVE: + { + JERRY_DEBUG_MSG ("NO_ALTERNATIVES\n"); + break; + } + case RE_OP_CAPTURING_GROUP_START: + { + JERRY_DEBUG_MSG ("CAPTURING_GROUP_START "); + JERRY_DEBUG_MSG ("idx: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("capture count: %u, ", re_get_value (&bytecode_p)); + + const uint32_t qmin = re_get_value (&bytecode_p); + JERRY_DEBUG_MSG ("qmin: %u", qmin); + if (qmin == 0) + { + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG (", tail offset: [%3u]\n", offset); + } + else + { + JERRY_DEBUG_MSG ("\n"); + } + + break; + } + case RE_OP_NON_CAPTURING_GROUP_START: + { + JERRY_DEBUG_MSG ("NON_CAPTURING_GROUP_START "); + JERRY_DEBUG_MSG ("idx: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("capture start: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("capture count: %u, ", re_get_value (&bytecode_p)); + + const uint32_t qmin = re_get_value (&bytecode_p); + JERRY_DEBUG_MSG ("qmin: %u", qmin); + if (qmin == 0) + { + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG (", tail offset: [%3u]\n", offset); + } + else + { + JERRY_DEBUG_MSG ("\n"); + } + + break; + } + case RE_OP_GREEDY_CAPTURING_GROUP_END: + { + JERRY_DEBUG_MSG ("GREEDY_CAPTURING_GROUP_END "); + JERRY_DEBUG_MSG ("idx: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmin: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmax: %u\n", re_get_value (&bytecode_p) - RE_QMAX_OFFSET); + break; + } + case RE_OP_LAZY_CAPTURING_GROUP_END: + { + JERRY_DEBUG_MSG ("LAZY_CAPTURING_GROUP_END "); + JERRY_DEBUG_MSG ("idx: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmin: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmax: %u\n", re_get_value (&bytecode_p) - RE_QMAX_OFFSET); + break; + } + case RE_OP_GREEDY_NON_CAPTURING_GROUP_END: + { + JERRY_DEBUG_MSG ("GREEDY_NON_CAPTURING_GROUP_END "); + JERRY_DEBUG_MSG ("idx: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmin: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmax: %u\n", re_get_value (&bytecode_p) - RE_QMAX_OFFSET); + break; + } + case RE_OP_LAZY_NON_CAPTURING_GROUP_END: + { + JERRY_DEBUG_MSG ("LAZY_NON_CAPTURING_GROUP_END "); + JERRY_DEBUG_MSG ("idx: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmin: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmax: %u\n", re_get_value (&bytecode_p) - RE_QMAX_OFFSET); + break; + } + case RE_OP_GREEDY_ITERATOR: + { + JERRY_DEBUG_MSG ("GREEDY_ITERATOR "); + JERRY_DEBUG_MSG ("qmin: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmax: %u, ", re_get_value (&bytecode_p) - RE_QMAX_OFFSET); + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG ("tail offset: [%3u]\n", offset); + break; + } + case RE_OP_LAZY_ITERATOR: + { + JERRY_DEBUG_MSG ("LAZY_ITERATOR "); + JERRY_DEBUG_MSG ("qmin: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("qmax: %u, ", re_get_value (&bytecode_p) - RE_QMAX_OFFSET); + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG ("tail offset: [%3u]\n", offset); + break; + } + case RE_OP_ITERATOR_END: + { + JERRY_DEBUG_MSG ("ITERATOR_END\n"); + break; + } + case RE_OP_BACKREFERENCE: + { + JERRY_DEBUG_MSG ("BACKREFERENCE "); + JERRY_DEBUG_MSG ("idx: %d\n", re_get_value (&bytecode_p)); + break; + } + case RE_OP_ASSERT_LINE_START: + { + JERRY_DEBUG_MSG ("ASSERT_LINE_START\n"); + break; + } + case RE_OP_ASSERT_LINE_END: + { + JERRY_DEBUG_MSG ("ASSERT_LINE_END\n"); + break; + } + case RE_OP_ASSERT_LOOKAHEAD_POS: + { + JERRY_DEBUG_MSG ("ASSERT_LOOKAHEAD_POS "); + JERRY_DEBUG_MSG ("qmin: %u, ", *bytecode_p++); + JERRY_DEBUG_MSG ("capture start: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("capture count: %u, ", re_get_value (&bytecode_p)); + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG ("tail offset: [%3u]\n", offset); + break; + } + case RE_OP_ASSERT_LOOKAHEAD_NEG: + { + JERRY_DEBUG_MSG ("ASSERT_LOOKAHEAD_NEG "); + JERRY_DEBUG_MSG ("qmin: %u, ", *bytecode_p++); + JERRY_DEBUG_MSG ("capture start: %u, ", re_get_value (&bytecode_p)); + JERRY_DEBUG_MSG ("capture count: %u, ", re_get_value (&bytecode_p)); + const uint32_t offset = re_get_value (&bytecode_p) + re_get_bytecode_offset (bytecode_start_p, bytecode_p); + JERRY_DEBUG_MSG ("tail offset: [%3u]\n", offset); + break; + } + case RE_OP_ASSERT_END: + { + JERRY_DEBUG_MSG ("ASSERT_END\n"); + break; + } + case RE_OP_ASSERT_WORD_BOUNDARY: + { + JERRY_DEBUG_MSG ("ASSERT_WORD_BOUNDARY\n"); + break; + } + case RE_OP_ASSERT_NOT_WORD_BOUNDARY: + { + JERRY_DEBUG_MSG ("ASSERT_NOT_WORD_BOUNDARY\n"); + break; + } + case RE_OP_CLASS_ESCAPE: + { + ecma_class_escape_t escape = (ecma_class_escape_t) *bytecode_p++; + JERRY_DEBUG_MSG ("CLASS_ESCAPE \\%c\n", escape_chars[escape]); + break; + } + case RE_OP_CHAR_CLASS: + { + JERRY_DEBUG_MSG ("CHAR_CLASS "); + uint8_t flags = *bytecode_p++; + uint32_t char_count = (flags & RE_CLASS_HAS_CHARS) ? re_get_value (&bytecode_p) : 0; + uint32_t range_count = (flags & RE_CLASS_HAS_RANGES) ? re_get_value (&bytecode_p) : 0; + + if (flags & RE_CLASS_INVERT) + { + JERRY_DEBUG_MSG ("inverted "); + } + + JERRY_DEBUG_MSG ("escapes: "); + uint8_t escape_count = flags & RE_CLASS_ESCAPE_COUNT_MASK; + while (escape_count--) + { + JERRY_DEBUG_MSG ("\\%c, ", escape_chars[*bytecode_p++]); + } + + JERRY_DEBUG_MSG ("chars: "); + while (char_count--) + { + JERRY_DEBUG_MSG ("\\u%04x, ", re_get_char (&bytecode_p, re_ctx_p->flags & RE_FLAG_UNICODE)); + } + + JERRY_DEBUG_MSG ("ranges: "); + while (range_count--) + { + const lit_code_point_t begin = re_get_char (&bytecode_p, re_ctx_p->flags & RE_FLAG_UNICODE); + const lit_code_point_t end = re_get_char (&bytecode_p, re_ctx_p->flags & RE_FLAG_UNICODE); + JERRY_DEBUG_MSG ("\\u%04x-\\u%04x, ", begin, end); + } + + JERRY_DEBUG_MSG ("\n"); + break; + } + case RE_OP_UNICODE_PERIOD: + { + JERRY_DEBUG_MSG ("UNICODE_PERIOD\n"); + break; + } + case RE_OP_PERIOD: + { + JERRY_DEBUG_MSG ("PERIOD\n"); + break; + } + case RE_OP_CHAR: + { + JERRY_DEBUG_MSG ("CHAR \\u%04x\n", re_get_char (&bytecode_p, re_ctx_p->flags & RE_FLAG_UNICODE)); + break; + } + case RE_OP_BYTE: + { + const uint8_t ch = *bytecode_p++; + JERRY_DEBUG_MSG ("BYTE \\u%04x '%c'\n", ch, (char) ch); + break; + } + case RE_OP_EOF: + { + JERRY_DEBUG_MSG ("EOF\n"); + return; + } + default: + { + JERRY_DEBUG_MSG ("UNKNOWN(%d)\n", (uint32_t) op); + break; + } + } + } +} /* re_dump_bytecode */ +#endif /* JERRY_REGEXP_DUMP_BYTE_CODE */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-bytecode.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-bytecode.h new file mode 100644 index 0000000..783d92b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-bytecode.h @@ -0,0 +1,131 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RE_BYTECODE_H +#define RE_BYTECODE_H + +#include "ecma-globals.h" + +#include "re-compiler-context.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_bytecode Bytecode + * @{ + */ + +/** + * Size of the RegExp bytecode cache + */ +#define RE_CACHE_SIZE 8u + +/** + * Maximum value that can be encoded in the RegExp bytecode as a single byte. + */ +#define RE_VALUE_1BYTE_MAX 0xFE + +/** + * Marker that signals that the actual value is encoded in the following 4 bytes in the bytecode. + */ +#define RE_VALUE_4BYTE_MARKER 0xFF + +/** + * RegExp opcodes + */ +typedef enum +{ + RE_OP_EOF, /**< end of pattern */ + + RE_OP_ALTERNATIVE_START, /**< start of alternatives */ + RE_OP_ALTERNATIVE_NEXT, /**< next alternative */ + RE_OP_NO_ALTERNATIVE, /**< no alternative */ + + RE_OP_CAPTURING_GROUP_START, /**< start of a capturing group */ + RE_OP_NON_CAPTURING_GROUP_START, /**< start of a non-capturing group */ + + RE_OP_GREEDY_CAPTURING_GROUP_END, /**< end of a greedy capturing group */ + RE_OP_GREEDY_NON_CAPTURING_GROUP_END, /**< end of a greedy non-capturing group */ + RE_OP_LAZY_CAPTURING_GROUP_END, /**< end of a lazy capturing group */ + RE_OP_LAZY_NON_CAPTURING_GROUP_END, /**< end of a lazy non-capturing group */ + + RE_OP_GREEDY_ITERATOR, /**< greedy iterator */ + RE_OP_LAZY_ITERATOR, /**< lazy iterator */ + RE_OP_ITERATOR_END, /*** end of an iterator */ + + RE_OP_BACKREFERENCE, /**< backreference */ + + RE_OP_ASSERT_LINE_START, /**< line start assertion */ + RE_OP_ASSERT_LINE_END, /**< line end assertion */ + RE_OP_ASSERT_WORD_BOUNDARY, /**< word boundary assertion */ + RE_OP_ASSERT_NOT_WORD_BOUNDARY, /**< not word boundary assertion */ + RE_OP_ASSERT_LOOKAHEAD_POS, /**< positive lookahead assertion */ + RE_OP_ASSERT_LOOKAHEAD_NEG, /**< negative lookahead assertion */ + RE_OP_ASSERT_END, /**< end of an assertion */ + + RE_OP_CLASS_ESCAPE, /**< class escape */ + RE_OP_CHAR_CLASS, /**< character class */ + RE_OP_UNICODE_PERIOD, /**< period in full unicode mode */ + RE_OP_PERIOD, /**< period in non-unicode mode */ + RE_OP_CHAR, /**< any code point */ + RE_OP_BYTE, /**< 1-byte utf8 character */ +} re_opcode_t; + +/** + * Compiled byte code data. + */ +typedef struct +{ + ecma_compiled_code_t header; /**< compiled code header */ + uint32_t captures_count; /**< number of capturing groups */ + uint32_t non_captures_count; /**< number of non-capturing groups */ + ecma_value_t source; /**< original RegExp pattern */ +} re_compiled_code_t; + +void re_initialize_regexp_bytecode (re_compiler_ctx_t *re_ctx_p); +uint32_t re_bytecode_size (re_compiler_ctx_t *re_ctx_p); + +void re_append_opcode (re_compiler_ctx_t *re_ctx_p, const re_opcode_t opcode); +void re_append_byte (re_compiler_ctx_t *re_ctx_p, const uint8_t byte); +void re_append_char (re_compiler_ctx_t *re_ctx_p, const lit_code_point_t cp); +void re_append_value (re_compiler_ctx_t *re_ctx_p, const uint32_t value); + +void re_insert_opcode (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const re_opcode_t opcode); +void re_insert_byte (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const uint8_t byte); +void re_insert_char (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const lit_code_point_t cp); +void re_insert_value (re_compiler_ctx_t *re_ctx_p, const uint32_t offset, const uint32_t value); + +re_opcode_t re_get_opcode (const uint8_t **bc_p); +uint8_t re_get_byte (const uint8_t **bc_p); +lit_code_point_t re_get_char (const uint8_t **bc_p, bool unicode); +uint32_t re_get_value (const uint8_t **bc_p); + +#if JERRY_REGEXP_DUMP_BYTE_CODE +void re_dump_bytecode (re_compiler_ctx_t *bc_ctx); +#endif /* JERRY_REGEXP_DUMP_BYTE_CODE */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ +#endif /* !RE_BYTECODE_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler-context.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler-context.h new file mode 100644 index 0000000..b7dbb02 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler-context.h @@ -0,0 +1,60 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RE_COMPILER_CONTEXT_H +#define RE_COMPILER_CONTEXT_H + +#include "re-token.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_compiler Compiler + * @{ + */ + +/** + * RegExp compiler context + */ +typedef struct +{ + const lit_utf8_byte_t *input_start_p; /**< start of input pattern */ + const lit_utf8_byte_t *input_curr_p; /**< current position in input pattern */ + const lit_utf8_byte_t *input_end_p; /**< end of input pattern */ + + uint8_t *bytecode_start_p; /**< start of bytecode block */ + size_t bytecode_size; /**< size of bytecode */ + + uint32_t captures_count; /**< number of capture groups */ + uint32_t non_captures_count; /**< number of non-capture groups */ + + int groups_count; /**< number of groups */ + uint16_t flags; /**< RegExp flags */ + re_token_t token; /**< current token */ +} re_compiler_ctx_t; + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ +#endif /* !RE_COMPILER_CONTEXT_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler.cpp new file mode 100644 index 0000000..a495616 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler.cpp @@ -0,0 +1,184 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "re-compiler.h" + +#include "ecma-exceptions.h" +#include "ecma-helpers.h" +#include "ecma-regexp-object.h" + +#include "jcontext.h" +#include "jmem.h" +#include "jrt-libc-includes.h" +#include "lit-char-helpers.h" +#include "re-bytecode.h" +#include "re-compiler-context.h" +#include "re-parser.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_compiler Compiler + * @{ + */ + +/** + * Search for the given pattern in the RegExp cache. + * + * @return pointer to bytecode if found + * NULL - otherwise + */ +static re_compiled_code_t * +re_cache_lookup (ecma_string_t *pattern_str_p, /**< pattern string */ + uint16_t flags) /**< flags */ +{ + re_compiled_code_t **cache_p = JERRY_CONTEXT (re_cache); + + for (uint8_t idx = 0u; idx < RE_CACHE_SIZE; idx++) + { + re_compiled_code_t *cached_bytecode_p = cache_p[idx]; + + if (cached_bytecode_p == NULL) + { + break; + } + + ecma_string_t *cached_pattern_str_p = ecma_get_string_from_value (cached_bytecode_p->source); + + if (cached_bytecode_p->header.status_flags == flags + && ecma_compare_ecma_strings (cached_pattern_str_p, pattern_str_p)) + { + return cached_bytecode_p; + } + } + + return NULL; +} /* re_cache_lookup */ + +/** + * Run garbage collection in RegExp cache. + */ +void +re_cache_gc (void) +{ + re_compiled_code_t **cache_p = JERRY_CONTEXT (re_cache); + + for (uint32_t i = 0u; i < RE_CACHE_SIZE; i++) + { + const re_compiled_code_t *cached_bytecode_p = cache_p[i]; + + if (cached_bytecode_p == NULL) + { + break; + } + + ecma_bytecode_deref ((ecma_compiled_code_t *) cached_bytecode_p); + cache_p[i] = NULL; + } + + JERRY_CONTEXT (re_cache_idx) = 0; +} /* re_cache_gc */ + +/** + * Compilation of RegExp bytecode + * + * @return pointer to bytecode if compilation was successful + * NULL - otherwise + */ +re_compiled_code_t * +re_compile_bytecode (ecma_string_t *pattern_str_p, /**< pattern */ + uint16_t flags) /**< flags */ +{ + re_compiled_code_t *cached_bytecode_p = re_cache_lookup (pattern_str_p, flags); + + if (cached_bytecode_p != NULL) + { + ecma_bytecode_ref ((ecma_compiled_code_t *) cached_bytecode_p); + return cached_bytecode_p; + } + + re_compiler_ctx_t re_ctx; + re_ctx.flags = flags; + re_ctx.captures_count = 1; + re_ctx.non_captures_count = 0; + + re_initialize_regexp_bytecode (&re_ctx); + + ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start_p, pattern_start_size); + + re_ctx.input_start_p = pattern_start_p; + re_ctx.input_curr_p = (lit_utf8_byte_t *) pattern_start_p; + re_ctx.input_end_p = pattern_start_p + pattern_start_size; + re_ctx.groups_count = -1; + + /* Parse RegExp pattern */ + ecma_value_t result = re_parse_alternative (&re_ctx, true); + + ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size); + + if (ECMA_IS_VALUE_ERROR (result)) + { + /* Compilation failed, free bytecode. */ + jmem_heap_free_block (re_ctx.bytecode_start_p, re_ctx.bytecode_size); + return NULL; + } + + /* Align bytecode size to JMEM_ALIGNMENT so that it can be stored in the bytecode header. */ + const uint32_t final_size = JERRY_ALIGNUP (re_ctx.bytecode_size, JMEM_ALIGNMENT); + re_compiled_code_t *re_compiled_code_p = + (re_compiled_code_t *) jmem_heap_realloc_block (re_ctx.bytecode_start_p, re_ctx.bytecode_size, final_size); + + /* Bytecoded will be inserted into the cache and returned to the caller, so refcount is implicitly set to 2. */ + re_compiled_code_p->header.refs = 2; + re_compiled_code_p->header.size = (uint16_t) (final_size >> JMEM_ALIGNMENT_LOG); + re_compiled_code_p->header.status_flags = re_ctx.flags; + + ecma_ref_ecma_string (pattern_str_p); + re_compiled_code_p->source = ecma_make_string_value (pattern_str_p); + re_compiled_code_p->captures_count = re_ctx.captures_count; + re_compiled_code_p->non_captures_count = re_ctx.non_captures_count; + +#if JERRY_REGEXP_DUMP_BYTE_CODE + if (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_SHOW_REGEXP_OPCODES) + { + re_dump_bytecode (&re_ctx); + } +#endif /* JERRY_REGEXP_DUMP_BYTE_CODE */ + + uint8_t cache_idx = JERRY_CONTEXT (re_cache_idx); + + if (JERRY_CONTEXT (re_cache)[cache_idx] != NULL) + { + ecma_bytecode_deref ((ecma_compiled_code_t *) JERRY_CONTEXT (re_cache)[cache_idx]); + } + + JERRY_CONTEXT (re_cache)[cache_idx] = re_compiled_code_p; + JERRY_CONTEXT (re_cache_idx) = (uint8_t) (cache_idx + 1) % RE_CACHE_SIZE; + + return re_compiled_code_p; +} /* re_compile_bytecode */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler.h new file mode 100644 index 0000000..ace781e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-compiler.h @@ -0,0 +1,46 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RE_COMPILER_H +#define RE_COMPILER_H + +#include "ecma-globals.h" + +#include "re-bytecode.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_compiler Compiler + * @{ + */ + +re_compiled_code_t *re_compile_bytecode (ecma_string_t *pattern_str_p, uint16_t flags); + +void re_cache_gc (void); + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ +#endif /* !RE_COMPILER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-parser.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-parser.cpp new file mode 100644 index 0000000..93114df --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-parser.cpp @@ -0,0 +1,1327 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "re-parser.h" + +#include "ecma-exceptions.h" +#include "ecma-globals.h" + +#include "jcontext.h" +#include "jrt-libc-includes.h" +#include "lit-char-helpers.h" +#include "re-compiler.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_parser Parser + * @{ + */ + +/** + * Get the start opcode for the current group. + * + * @return RegExp opcode + */ +static re_opcode_t +re_get_group_start_opcode (bool is_capturing) /**< is capturing group */ +{ + return (is_capturing) ? RE_OP_CAPTURING_GROUP_START : RE_OP_NON_CAPTURING_GROUP_START; +} /* re_get_group_start_opcode */ + +/** + * Get the end opcode for the current group. + * + * @return RegExp opcode + */ +static re_opcode_t +re_get_group_end_opcode (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + bool is_capturing) /**< is capturing group */ +{ + if (is_capturing) + { + if (re_ctx_p->token.greedy) + { + return RE_OP_GREEDY_CAPTURING_GROUP_END; + } + + return RE_OP_LAZY_CAPTURING_GROUP_END; + } + + if (re_ctx_p->token.greedy) + { + return RE_OP_GREEDY_NON_CAPTURING_GROUP_END; + } + + return RE_OP_LAZY_NON_CAPTURING_GROUP_END; +} /* re_get_group_end_opcode */ + +/** + * Enclose the given bytecode to a group. + */ +static void +re_insert_into_group (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + uint32_t group_start_offset, /**< offset of group start */ + uint32_t idx, /**< index of group */ + uint32_t capture_start, /**< index of first nested capture */ + bool is_capturing) /**< is capturing group */ +{ + uint32_t qmin = re_ctx_p->token.qmin; + uint32_t qmax = re_ctx_p->token.qmax; + + if (JERRY_UNLIKELY (!is_capturing && re_bytecode_size (re_ctx_p) == group_start_offset)) + { + return; + } + + if (qmin == 0) + { + re_insert_value (re_ctx_p, group_start_offset, re_bytecode_size (re_ctx_p) - group_start_offset); + } + + re_insert_value (re_ctx_p, group_start_offset, qmin); + re_insert_value (re_ctx_p, group_start_offset, re_ctx_p->captures_count - capture_start); + + if (!is_capturing) + { + re_insert_value (re_ctx_p, group_start_offset, capture_start); + } + else + { + JERRY_ASSERT (idx == capture_start); + } + + re_insert_value (re_ctx_p, group_start_offset, idx); + re_insert_opcode (re_ctx_p, group_start_offset, re_get_group_start_opcode (is_capturing)); + + re_append_opcode (re_ctx_p, re_get_group_end_opcode (re_ctx_p, is_capturing)); + re_append_value (re_ctx_p, idx); + re_append_value (re_ctx_p, qmin); + re_append_value (re_ctx_p, qmax + RE_QMAX_OFFSET); +} /* re_insert_into_group */ + +/** + * Insert simple atom iterator. + */ +static void +re_insert_atom_iterator (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + uint32_t start_offset) /**< atom start offset */ +{ + const uint32_t qmin = re_ctx_p->token.qmin; + const uint32_t qmax = re_ctx_p->token.qmax; + + if (qmin == 1 && qmax == 1) + { + return; + } + + re_append_opcode (re_ctx_p, RE_OP_ITERATOR_END); + re_insert_value (re_ctx_p, start_offset, re_bytecode_size (re_ctx_p) - start_offset); + re_insert_value (re_ctx_p, start_offset, qmax + RE_QMAX_OFFSET); + re_insert_value (re_ctx_p, start_offset, qmin); + re_insert_opcode (re_ctx_p, start_offset, re_ctx_p->token.greedy ? RE_OP_GREEDY_ITERATOR : RE_OP_LAZY_ITERATOR); +} /* re_insert_atom_iterator */ + +/** + * Insert a lookahead assertion. + */ +static void +re_insert_assertion_lookahead (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + uint32_t start_offset, /**< atom start offset */ + uint32_t capture_start, /**< index of first nested capture */ + bool negative) /** lookahead type */ +{ + const uint32_t qmin = re_ctx_p->token.qmin; + + re_append_opcode (re_ctx_p, RE_OP_ASSERT_END); + re_insert_value (re_ctx_p, start_offset, re_bytecode_size (re_ctx_p) - start_offset); + + /* We need to clear nested capturing group results when a negative assertion or the tail after a positive assertion + * does not match, so we store the begin and end index of nested capturing groups. */ + re_insert_value (re_ctx_p, start_offset, re_ctx_p->captures_count - capture_start); + re_insert_value (re_ctx_p, start_offset, capture_start); + + /* Lookaheads always result in zero length matches, which means iterations will always stop on the first match. + * This allows us to not have to deal with iterations beyond one. Either qmin == 0 which will implicitly match, + * or qmin > 0, in which case the first iteration will decide whether the assertion matches depending on whether + * the iteration matched or not. This also allows us to ignore qmax entirely. */ + re_insert_byte (re_ctx_p, start_offset, (uint8_t) JERRY_MIN (qmin, 1)); + + const re_opcode_t opcode = (negative) ? RE_OP_ASSERT_LOOKAHEAD_NEG : RE_OP_ASSERT_LOOKAHEAD_POS; + re_insert_opcode (re_ctx_p, start_offset, opcode); +} /* re_insert_assertion_lookahead */ + +/** + * Consume non greedy (question mark) character if present. + */ +static void +re_parse_lazy_char (re_compiler_ctx_t *re_ctx_p) /**< RegExp parser context */ +{ + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && *re_ctx_p->input_curr_p == LIT_CHAR_QUESTION) + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.greedy = false; + return; + } + + re_ctx_p->token.greedy = true; +} /* re_parse_lazy_char */ + +/** + * Parse a max 3 digit long octal number from the input string, with a decimal value less than 256. + * + * @return value of the octal number + */ +static uint32_t +re_parse_octal (re_compiler_ctx_t *re_ctx_p) /**< RegExp parser context */ +{ + JERRY_ASSERT (re_ctx_p->input_curr_p < re_ctx_p->input_end_p); + JERRY_ASSERT (lit_char_is_octal_digit (*re_ctx_p->input_curr_p)); + + uint32_t value = (uint32_t) (*re_ctx_p->input_curr_p++) - LIT_CHAR_0; + + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) + { + value = value * 8 + (*re_ctx_p->input_curr_p++) - LIT_CHAR_0; + } + + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) + { + const uint32_t new_value = value * 8 + (*re_ctx_p->input_curr_p) - LIT_CHAR_0; + + if (new_value <= RE_MAX_OCTAL_VALUE) + { + value = new_value; + re_ctx_p->input_curr_p++; + } + } + + return value; +} /* re_parse_octal */ + +/** + * Check that the currently parsed quantifier is valid. + * + * @return ECMA_VALUE_ERROR, if quantifier is invalid + * ECMA_VALUE_EMPTY, otherwise + */ +static ecma_value_t +re_check_quantifier (re_compiler_ctx_t *re_ctx_p) +{ + if (re_ctx_p->token.qmin > re_ctx_p->token.qmax) + { + /* ECMA-262 v5.1 15.10.2.5 */ + return ecma_raise_syntax_error (ECMA_ERR_MIN_GREATER_THAN_MAX); + } + + return ECMA_VALUE_EMPTY; +} /* re_check_quantifier */ + +/** + * Parse RegExp quantifier. + * + * @return ECMA_VALUE_TRUE - if parsed successfully + * ECMA_VALUE_FALSE - otherwise + */ +static ecma_value_t +re_parse_quantifier (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ +{ + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p) + { + switch (*re_ctx_p->input_curr_p) + { + case LIT_CHAR_QUESTION: + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.qmin = 0; + re_ctx_p->token.qmax = 1; + + re_parse_lazy_char (re_ctx_p); + return ECMA_VALUE_TRUE; + } + case LIT_CHAR_ASTERISK: + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.qmin = 0; + re_ctx_p->token.qmax = RE_INFINITY; + + re_parse_lazy_char (re_ctx_p); + return ECMA_VALUE_TRUE; + } + case LIT_CHAR_PLUS: + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.qmin = 1; + re_ctx_p->token.qmax = RE_INFINITY; + + re_parse_lazy_char (re_ctx_p); + return ECMA_VALUE_TRUE; + } + case LIT_CHAR_LEFT_BRACE: + { + const lit_utf8_byte_t *current_p = re_ctx_p->input_curr_p + 1; + uint32_t qmin = 0; + uint32_t qmax = RE_INFINITY; + + if (current_p >= re_ctx_p->input_end_p) + { + break; + } + + if (!lit_char_is_decimal_digit (*current_p)) + { + break; + } + + qmin = lit_parse_decimal (¤t_p, re_ctx_p->input_end_p); + + if (current_p >= re_ctx_p->input_end_p) + { + break; + } + + lit_utf8_byte_t ch = *current_p++; + if (ch == LIT_CHAR_RIGHT_BRACE) + { + qmax = qmin; + } + else if (ch == LIT_CHAR_COMMA) + { + if (current_p >= re_ctx_p->input_end_p) + { + break; + } + + if (lit_char_is_decimal_digit (*current_p)) + { + qmax = lit_parse_decimal (¤t_p, re_ctx_p->input_end_p); + } + + if (current_p >= re_ctx_p->input_end_p || *current_p++ != LIT_CHAR_RIGHT_BRACE) + { + break; + } + } + else + { + break; + } + + re_ctx_p->token.qmin = qmin; + re_ctx_p->token.qmax = qmax; + re_ctx_p->input_curr_p = current_p; + re_parse_lazy_char (re_ctx_p); + return ECMA_VALUE_TRUE; + } + default: + { + break; + } + } + } + + re_ctx_p->token.qmin = 1; + re_ctx_p->token.qmax = 1; + re_ctx_p->token.greedy = true; + + return ECMA_VALUE_FALSE; +} /* re_parse_quantifier */ + +/** + * Count the number of groups in the current pattern. + */ +static void +re_count_groups (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ +{ + bool is_char_class = 0; + re_ctx_p->groups_count = 0; + const lit_utf8_byte_t *curr_p = re_ctx_p->input_start_p; + + while (curr_p < re_ctx_p->input_end_p) + { + switch (*curr_p++) + { + case LIT_CHAR_BACKSLASH: + { + if (curr_p < re_ctx_p->input_end_p) + { + lit_utf8_incr (&curr_p); + } + break; + } + case LIT_CHAR_LEFT_SQUARE: + { + is_char_class = true; + break; + } + case LIT_CHAR_RIGHT_SQUARE: + { + is_char_class = false; + break; + } + case LIT_CHAR_LEFT_PAREN: + { + if (curr_p < re_ctx_p->input_end_p && *curr_p != LIT_CHAR_QUESTION && !is_char_class) + { + re_ctx_p->groups_count++; + } + break; + } + } + } +} /* re_count_groups */ + +/** + * Check if a code point is a Syntax character + * + * @return true, if syntax character + * false, otherwise + */ +static bool +re_is_syntax_char (lit_code_point_t cp) /**< code point */ +{ + return (cp == LIT_CHAR_CIRCUMFLEX || cp == LIT_CHAR_DOLLAR_SIGN || cp == LIT_CHAR_BACKSLASH || cp == LIT_CHAR_DOT + || cp == LIT_CHAR_ASTERISK || cp == LIT_CHAR_PLUS || cp == LIT_CHAR_QUESTION || cp == LIT_CHAR_LEFT_PAREN + || cp == LIT_CHAR_RIGHT_PAREN || cp == LIT_CHAR_LEFT_SQUARE || cp == LIT_CHAR_RIGHT_SQUARE + || cp == LIT_CHAR_LEFT_BRACE || cp == LIT_CHAR_RIGHT_BRACE || cp == LIT_CHAR_VLINE); +} /* re_is_syntax_char */ + +/** + * Parse a Character Escape or a Character Class Escape. + * + * @return ECMA_VALUE_EMPTY, if parsed successfully + * ECMA_VALUE_ERROR, otherwise + */ +static ecma_value_t +re_parse_char_escape (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ +{ + JERRY_ASSERT (re_ctx_p->input_curr_p < re_ctx_p->input_end_p); + re_ctx_p->token.type = RE_TOK_CHAR; + + if (lit_char_is_decimal_digit (*re_ctx_p->input_curr_p)) + { + /* NULL code point escape, only valid if there are no following digits. */ + if (*re_ctx_p->input_curr_p == LIT_CHAR_0 + && (re_ctx_p->input_curr_p + 1 >= re_ctx_p->input_end_p + || !lit_char_is_decimal_digit (re_ctx_p->input_curr_p[1]))) + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.value = LIT_UNICODE_CODE_POINT_NULL; + return ECMA_VALUE_EMPTY; + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_ESCAPE_SEQUENCE); + } + + /* Legacy octal escape sequence */ + if (lit_char_is_octal_digit (*re_ctx_p->input_curr_p)) + { + re_ctx_p->token.value = re_parse_octal (re_ctx_p); + return ECMA_VALUE_EMPTY; + } + + /* Identity escape */ + re_ctx_p->token.value = *re_ctx_p->input_curr_p++; + return ECMA_VALUE_EMPTY; + } + + lit_code_point_t ch = lit_cesu8_read_next (&re_ctx_p->input_curr_p); + switch (ch) + { + /* Character Class escapes */ + case LIT_CHAR_LOWERCASE_D: + { + re_ctx_p->token.type = RE_TOK_CLASS_ESCAPE; + re_ctx_p->token.value = RE_ESCAPE_DIGIT; + break; + } + case LIT_CHAR_UPPERCASE_D: + { + re_ctx_p->token.type = RE_TOK_CLASS_ESCAPE; + re_ctx_p->token.value = RE_ESCAPE_NOT_DIGIT; + break; + } + case LIT_CHAR_LOWERCASE_S: + { + re_ctx_p->token.type = RE_TOK_CLASS_ESCAPE; + re_ctx_p->token.value = RE_ESCAPE_WHITESPACE; + break; + } + case LIT_CHAR_UPPERCASE_S: + { + re_ctx_p->token.type = RE_TOK_CLASS_ESCAPE; + re_ctx_p->token.value = RE_ESCAPE_NOT_WHITESPACE; + break; + } + case LIT_CHAR_LOWERCASE_W: + { + re_ctx_p->token.type = RE_TOK_CLASS_ESCAPE; + re_ctx_p->token.value = RE_ESCAPE_WORD_CHAR; + break; + } + case LIT_CHAR_UPPERCASE_W: + { + re_ctx_p->token.type = RE_TOK_CLASS_ESCAPE; + re_ctx_p->token.value = RE_ESCAPE_NOT_WORD_CHAR; + break; + } + /* Control escapes */ + case LIT_CHAR_LOWERCASE_F: + { + re_ctx_p->token.value = LIT_CHAR_FF; + break; + } + case LIT_CHAR_LOWERCASE_N: + { + re_ctx_p->token.value = LIT_CHAR_LF; + break; + } + case LIT_CHAR_LOWERCASE_R: + { + re_ctx_p->token.value = LIT_CHAR_CR; + break; + } + case LIT_CHAR_LOWERCASE_T: + { + re_ctx_p->token.value = LIT_CHAR_TAB; + break; + } + case LIT_CHAR_LOWERCASE_V: + { + re_ctx_p->token.value = LIT_CHAR_VTAB; + break; + } + /* Control letter */ + case LIT_CHAR_LOWERCASE_C: + { + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p) + { + ch = *re_ctx_p->input_curr_p; + + if ((ch >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_END) + || (ch >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_BEGIN && ch <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_END)) + { + re_ctx_p->token.value = (ch % 32); + re_ctx_p->input_curr_p++; + + break; + } + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_CONTROL_ESCAPE_SEQUENCE); + } + + re_ctx_p->token.value = LIT_CHAR_BACKSLASH; + re_ctx_p->input_curr_p--; + + break; + } + /* Hex escape */ + case LIT_CHAR_LOWERCASE_X: + { + uint32_t hex_value = lit_char_hex_lookup (re_ctx_p->input_curr_p, re_ctx_p->input_end_p, 2); + if (hex_value != UINT32_MAX) + { + re_ctx_p->token.value = hex_value; + re_ctx_p->input_curr_p += 2; + break; + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_HEX_ESCAPE_SEQUENCE); + } + + re_ctx_p->token.value = LIT_CHAR_LOWERCASE_X; + break; + } + /* Unicode escape */ + case LIT_CHAR_LOWERCASE_U: + { + uint32_t hex_value = lit_char_hex_lookup (re_ctx_p->input_curr_p, re_ctx_p->input_end_p, 4); + if (hex_value != UINT32_MAX) + { + re_ctx_p->token.value = hex_value; + re_ctx_p->input_curr_p += 4; + + if (re_ctx_p->flags & RE_FLAG_UNICODE && lit_is_code_point_utf16_high_surrogate (re_ctx_p->token.value) + && re_ctx_p->input_curr_p + 6 <= re_ctx_p->input_end_p && re_ctx_p->input_curr_p[0] == '\\' + && re_ctx_p->input_curr_p[1] == 'u') + { + hex_value = lit_char_hex_lookup (re_ctx_p->input_curr_p + 2, re_ctx_p->input_end_p, 4); + if (lit_is_code_point_utf16_low_surrogate (hex_value)) + { + re_ctx_p->token.value = + lit_convert_surrogate_pair_to_code_point ((ecma_char_t) re_ctx_p->token.value, (ecma_char_t) hex_value); + re_ctx_p->input_curr_p += 6; + } + } + + break; + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + if (re_ctx_p->input_curr_p + 1 < re_ctx_p->input_end_p && re_ctx_p->input_curr_p[0] == LIT_CHAR_LEFT_BRACE + && lit_char_is_hex_digit (re_ctx_p->input_curr_p[1])) + { + lit_code_point_t cp = lit_char_hex_to_int (re_ctx_p->input_curr_p[1]); + re_ctx_p->input_curr_p += 2; + + while (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && lit_char_is_hex_digit (*re_ctx_p->input_curr_p)) + { + cp = cp * 16 + lit_char_hex_to_int (*re_ctx_p->input_curr_p++); + + if (JERRY_UNLIKELY (cp > LIT_UNICODE_CODE_POINT_MAX)) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE); + } + } + + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && *re_ctx_p->input_curr_p == LIT_CHAR_RIGHT_BRACE) + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.value = cp; + break; + } + } + + return ecma_raise_syntax_error (ECMA_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE); + } + + re_ctx_p->token.value = LIT_CHAR_LOWERCASE_U; + break; + } + /* Identity escape */ + default: + { + /* Must be '/', or one of SyntaxCharacter */ + if (re_ctx_p->flags & RE_FLAG_UNICODE && ch != LIT_CHAR_SLASH && !re_is_syntax_char (ch)) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_ESCAPE); + } + re_ctx_p->token.value = ch; + } + } + + return ECMA_VALUE_EMPTY; +} /* re_parse_char_escape */ + +/** + * Read the input pattern and parse the next token for the RegExp compiler + * + * @return empty ecma value - if parsed successfully + * error ecma value - otherwise + * + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +re_parse_next_token (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ +{ + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + re_ctx_p->token.type = RE_TOK_EOF; + return ECMA_VALUE_EMPTY; + } + + ecma_char_t ch = lit_cesu8_read_next (&re_ctx_p->input_curr_p); + + switch (ch) + { + case LIT_CHAR_CIRCUMFLEX: + { + re_ctx_p->token.type = RE_TOK_ASSERT_START; + return ECMA_VALUE_EMPTY; + } + case LIT_CHAR_DOLLAR_SIGN: + { + re_ctx_p->token.type = RE_TOK_ASSERT_END; + return ECMA_VALUE_EMPTY; + } + case LIT_CHAR_VLINE: + { + re_ctx_p->token.type = RE_TOK_ALTERNATIVE; + return ECMA_VALUE_EMPTY; + } + case LIT_CHAR_DOT: + { + re_ctx_p->token.type = RE_TOK_PERIOD; + /* Check quantifier */ + break; + } + case LIT_CHAR_BACKSLASH: + { + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_ESCAPE); + } + + /* DecimalEscape, Backreferences cannot start with a zero digit. */ + if (*re_ctx_p->input_curr_p > LIT_CHAR_0 && *re_ctx_p->input_curr_p <= LIT_CHAR_9) + { + const lit_utf8_byte_t *digits_p = re_ctx_p->input_curr_p; + const uint32_t value = lit_parse_decimal (&digits_p, re_ctx_p->input_end_p); + + if (re_ctx_p->groups_count < 0) + { + re_count_groups (re_ctx_p); + } + + if (value <= (uint32_t) re_ctx_p->groups_count) + { + /* Valid backreference */ + re_ctx_p->input_curr_p = digits_p; + re_ctx_p->token.type = RE_TOK_BACKREFERENCE; + re_ctx_p->token.value = value; + + /* Check quantifier */ + break; + } + } + + if (*re_ctx_p->input_curr_p == LIT_CHAR_LOWERCASE_B) + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.type = RE_TOK_ASSERT_WORD_BOUNDARY; + return ECMA_VALUE_EMPTY; + } + else if (*re_ctx_p->input_curr_p == LIT_CHAR_UPPERCASE_B) + { + re_ctx_p->input_curr_p++; + re_ctx_p->token.type = RE_TOK_ASSERT_NOT_WORD_BOUNDARY; + return ECMA_VALUE_EMPTY; + } + + const ecma_value_t parse_result = re_parse_char_escape (re_ctx_p); + + if (ECMA_IS_VALUE_ERROR (parse_result)) + { + return parse_result; + } + + /* Check quantifier */ + break; + } + case LIT_CHAR_LEFT_PAREN: + { + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + return ecma_raise_syntax_error (ECMA_ERR_UNTERMINATED_GROUP); + } + + if (*re_ctx_p->input_curr_p == LIT_CHAR_QUESTION) + { + re_ctx_p->input_curr_p++; + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_GROUP); + } + + ch = *re_ctx_p->input_curr_p++; + + if (ch == LIT_CHAR_EQUALS) + { + re_ctx_p->token.type = RE_TOK_ASSERT_LOOKAHEAD; + re_ctx_p->token.value = false; + } + else if (ch == LIT_CHAR_EXCLAMATION) + { + re_ctx_p->token.type = RE_TOK_ASSERT_LOOKAHEAD; + re_ctx_p->token.value = true; + } + else if (ch == LIT_CHAR_COLON) + { + re_ctx_p->token.type = RE_TOK_START_NON_CAPTURE_GROUP; + } + else + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_GROUP); + } + } + else + { + re_ctx_p->token.type = RE_TOK_START_CAPTURE_GROUP; + } + + return ECMA_VALUE_EMPTY; + } + case LIT_CHAR_RIGHT_PAREN: + { + re_ctx_p->token.type = RE_TOK_END_GROUP; + + return ECMA_VALUE_EMPTY; + } + case LIT_CHAR_LEFT_SQUARE: + { + re_ctx_p->token.type = RE_TOK_CHAR_CLASS; + + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + return ecma_raise_syntax_error (ECMA_ERR_UNTERMINATED_CHARACTER_CLASS); + } + + return ECMA_VALUE_EMPTY; + } + case LIT_CHAR_QUESTION: + case LIT_CHAR_ASTERISK: + case LIT_CHAR_PLUS: + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_QUANTIFIER); + } + case LIT_CHAR_LEFT_BRACE: + { + re_ctx_p->input_curr_p--; + if (ecma_is_value_true (re_parse_quantifier (re_ctx_p))) + { + return ecma_raise_syntax_error (ECMA_ERR_NOTHING_TO_REPEAT); + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + return ecma_raise_syntax_error (ECMA_ERR_LONE_QUANTIFIER_BRACKET); + } + + re_ctx_p->input_curr_p++; + re_ctx_p->token.type = RE_TOK_CHAR; + re_ctx_p->token.value = ch; + + /* Check quantifier */ + break; + } + case LIT_CHAR_RIGHT_SQUARE: + case LIT_CHAR_RIGHT_BRACE: + { + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + return ecma_raise_syntax_error (ECMA_ERR_LONE_QUANTIFIER_BRACKET); + } + + /* FALLTHRU */ + } + default: + { + re_ctx_p->token.type = RE_TOK_CHAR; + re_ctx_p->token.value = ch; + + if (re_ctx_p->flags & RE_FLAG_UNICODE && lit_is_code_point_utf16_high_surrogate (ch) + && re_ctx_p->input_curr_p < re_ctx_p->input_end_p) + { + const ecma_char_t next = lit_cesu8_peek_next (re_ctx_p->input_curr_p); + if (lit_is_code_point_utf16_low_surrogate (next)) + { + re_ctx_p->token.value = lit_convert_surrogate_pair_to_code_point (ch, next); + re_ctx_p->input_curr_p += LIT_UTF8_MAX_BYTES_IN_CODE_UNIT; + } + } + + /* Check quantifier */ + break; + } + } + + re_parse_quantifier (re_ctx_p); + return re_check_quantifier (re_ctx_p); +} /* re_parse_next_token */ + +/** + * Append a character class range to the bytecode. + */ +static void +re_class_add_range (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + lit_code_point_t start, /**< range begin */ + lit_code_point_t end) /**< range end */ +{ + if (re_ctx_p->flags & RE_FLAG_IGNORE_CASE) + { + start = ecma_regexp_canonicalize_char (start, re_ctx_p->flags & RE_FLAG_UNICODE); + end = ecma_regexp_canonicalize_char (end, re_ctx_p->flags & RE_FLAG_UNICODE); + } + + re_append_char (re_ctx_p, start); + re_append_char (re_ctx_p, end); +} /* re_class_add_range */ + +/** + * Add a single character to the character class + */ +static void +re_class_add_char (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + uint32_t class_offset, /**< character class bytecode offset*/ + lit_code_point_t cp) /**< code point */ +{ + if (re_ctx_p->flags & RE_FLAG_IGNORE_CASE) + { + cp = ecma_regexp_canonicalize_char (cp, re_ctx_p->flags & RE_FLAG_UNICODE); + } + + re_insert_char (re_ctx_p, class_offset, cp); +} /* re_class_add_char */ + +/** + * Invalid character code point + */ +#define RE_INVALID_CP 0xFFFFFFFF + +/** + * Read the input pattern and parse the range of character class + * + * @return empty ecma value - if parsed successfully + * error ecma value - otherwise + * + * Returned value must be freed with ecma_free_value + */ +static ecma_value_t +re_parse_char_class (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context */ +{ + static const uint8_t escape_flags[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20 }; + const uint32_t class_offset = re_bytecode_size (re_ctx_p); + + uint8_t found_escape_flags = 0; + uint8_t out_class_flags = 0; + + uint32_t range_count = 0; + uint32_t char_count = 0; + bool is_range = false; + + JERRY_ASSERT (re_ctx_p->input_curr_p < re_ctx_p->input_end_p); + if (*re_ctx_p->input_curr_p == LIT_CHAR_CIRCUMFLEX) + { + re_ctx_p->input_curr_p++; + out_class_flags |= RE_CLASS_INVERT; + } + + lit_code_point_t start = RE_INVALID_CP; + + while (true) + { + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + return ecma_raise_syntax_error (ECMA_ERR_UNTERMINATED_CHARACTER_CLASS); + } + + if (*re_ctx_p->input_curr_p == LIT_CHAR_RIGHT_SQUARE) + { + if (is_range) + { + if (start != RE_INVALID_CP) + { + re_class_add_char (re_ctx_p, class_offset, start); + char_count++; + } + + re_class_add_char (re_ctx_p, class_offset, LIT_CHAR_MINUS); + char_count++; + } + + re_ctx_p->input_curr_p++; + break; + } + + JERRY_ASSERT (re_ctx_p->input_curr_p < re_ctx_p->input_end_p); + lit_code_point_t current; + + if (*re_ctx_p->input_curr_p == LIT_CHAR_BACKSLASH) + { + re_ctx_p->input_curr_p++; + if (re_ctx_p->input_curr_p >= re_ctx_p->input_end_p) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_ESCAPE); + } + + if (*re_ctx_p->input_curr_p == LIT_CHAR_LOWERCASE_B) + { + re_ctx_p->input_curr_p++; + current = LIT_CHAR_BS; + } + else if (*re_ctx_p->input_curr_p == LIT_CHAR_MINUS) + { + re_ctx_p->input_curr_p++; + current = LIT_CHAR_MINUS; + } + else if ((re_ctx_p->flags & RE_FLAG_UNICODE) == 0 && *re_ctx_p->input_curr_p == LIT_CHAR_LOWERCASE_C + && re_ctx_p->input_curr_p + 1 < re_ctx_p->input_end_p + && (lit_char_is_decimal_digit (*(re_ctx_p->input_curr_p + 1)) + || *(re_ctx_p->input_curr_p + 1) == LIT_CHAR_UNDERSCORE)) + { + current = ((uint8_t) * (re_ctx_p->input_curr_p + 1) % 32); + re_ctx_p->input_curr_p += 2; + } + else + { + if (ECMA_IS_VALUE_ERROR (re_parse_char_escape (re_ctx_p))) + { + return ECMA_VALUE_ERROR; + } + + if (re_ctx_p->token.type == RE_TOK_CLASS_ESCAPE) + { + const uint8_t escape = (uint8_t) re_ctx_p->token.value; + found_escape_flags |= escape_flags[escape]; + current = RE_INVALID_CP; + } + else + { + JERRY_ASSERT (re_ctx_p->token.type == RE_TOK_CHAR); + current = re_ctx_p->token.value; + } + } + } + else if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + current = ecma_regexp_unicode_advance (&re_ctx_p->input_curr_p, re_ctx_p->input_end_p); + } + else + { + current = lit_cesu8_read_next (&re_ctx_p->input_curr_p); + } + + if (is_range) + { + is_range = false; + + if (start != RE_INVALID_CP && current != RE_INVALID_CP) + { + if (start > current) + { + return ecma_raise_syntax_error (ECMA_ERR_RANGE_OUT_OF_ORDER_IN_CHARACTER_CLASS); + } + + re_class_add_range (re_ctx_p, start, current); + range_count++; + continue; + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + return ecma_raise_syntax_error (ECMA_ERR_INVALID_CHARACTER_CLASS); + } + + if (start != RE_INVALID_CP) + { + re_class_add_char (re_ctx_p, class_offset, start); + char_count++; + } + else if (current != RE_INVALID_CP) + { + re_class_add_char (re_ctx_p, class_offset, current); + char_count++; + } + + re_class_add_char (re_ctx_p, class_offset, LIT_CHAR_MINUS); + char_count++; + continue; + } + + if (re_ctx_p->input_curr_p < re_ctx_p->input_end_p && *re_ctx_p->input_curr_p == LIT_CHAR_MINUS) + { + re_ctx_p->input_curr_p++; + start = current; + is_range = true; + continue; + } + + if (current != RE_INVALID_CP) + { + re_class_add_char (re_ctx_p, class_offset, current); + char_count++; + } + } + + uint8_t escape_count = 0; + for (ecma_class_escape_t escape = RE_ESCAPE__START; escape < RE_ESCAPE__COUNT; escape = (ecma_class_escape_t)((int) escape + 1)) + { + if (found_escape_flags & escape_flags[escape]) + { + re_insert_byte (re_ctx_p, class_offset, (uint8_t) escape); + escape_count++; + } + } + + if (range_count > 0) + { + re_insert_value (re_ctx_p, class_offset, range_count); + out_class_flags |= RE_CLASS_HAS_RANGES; + } + + if (char_count > 0) + { + re_insert_value (re_ctx_p, class_offset, char_count); + out_class_flags |= RE_CLASS_HAS_CHARS; + } + + JERRY_ASSERT (escape_count <= RE_CLASS_ESCAPE_COUNT_MASK); + out_class_flags |= escape_count; + + re_insert_byte (re_ctx_p, class_offset, out_class_flags); + re_insert_opcode (re_ctx_p, class_offset, RE_OP_CHAR_CLASS); + + re_parse_quantifier (re_ctx_p); + return re_check_quantifier (re_ctx_p); +} /* re_parse_char_class */ + +/** + * Parse alternatives + * + * @return empty ecma value - if alternative was successfully parsed + * error ecma value - otherwise + * + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +re_parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */ + bool expect_eof) /**< expect end of file */ +{ + ECMA_CHECK_STACK_USAGE (); + uint32_t alternative_offset = re_bytecode_size (re_ctx_p); + bool first_alternative = true; + + while (true) + { + ecma_value_t next_token_result = re_parse_next_token (re_ctx_p); + if (ECMA_IS_VALUE_ERROR (next_token_result)) + { + return next_token_result; + } + + JERRY_ASSERT (ecma_is_value_empty (next_token_result)); + + uint32_t atom_offset = re_bytecode_size (re_ctx_p); + + switch (re_ctx_p->token.type) + { + case RE_TOK_START_CAPTURE_GROUP: + { + const uint32_t idx = re_ctx_p->captures_count++; + const uint32_t capture_start = idx; + + ecma_value_t result = re_parse_alternative (re_ctx_p, false); + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + re_parse_quantifier (re_ctx_p); + + if (ECMA_IS_VALUE_ERROR (re_check_quantifier (re_ctx_p))) + { + return ECMA_VALUE_ERROR; + } + + re_insert_into_group (re_ctx_p, atom_offset, idx, capture_start, true); + break; + } + case RE_TOK_START_NON_CAPTURE_GROUP: + { + const uint32_t idx = re_ctx_p->non_captures_count++; + const uint32_t capture_start = re_ctx_p->captures_count; + + ecma_value_t result = re_parse_alternative (re_ctx_p, false); + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + re_parse_quantifier (re_ctx_p); + + if (ECMA_IS_VALUE_ERROR (re_check_quantifier (re_ctx_p))) + { + return ECMA_VALUE_ERROR; + } + + re_insert_into_group (re_ctx_p, atom_offset, idx, capture_start, false); + break; + } + case RE_TOK_PERIOD: + { + re_append_opcode (re_ctx_p, (re_ctx_p->flags & RE_FLAG_UNICODE) ? RE_OP_UNICODE_PERIOD : RE_OP_PERIOD); + re_insert_atom_iterator (re_ctx_p, atom_offset); + break; + } + case RE_TOK_ALTERNATIVE: + { + re_insert_value (re_ctx_p, alternative_offset, re_bytecode_size (re_ctx_p) - alternative_offset); + re_insert_opcode (re_ctx_p, + alternative_offset, + first_alternative ? RE_OP_ALTERNATIVE_START : RE_OP_ALTERNATIVE_NEXT); + + alternative_offset = re_bytecode_size (re_ctx_p); + first_alternative = false; + break; + } + case RE_TOK_ASSERT_START: + { + re_append_opcode (re_ctx_p, RE_OP_ASSERT_LINE_START); + break; + } + case RE_TOK_ASSERT_END: + { + re_append_opcode (re_ctx_p, RE_OP_ASSERT_LINE_END); + break; + } + case RE_TOK_ASSERT_WORD_BOUNDARY: + { + re_append_opcode (re_ctx_p, RE_OP_ASSERT_WORD_BOUNDARY); + break; + } + case RE_TOK_ASSERT_NOT_WORD_BOUNDARY: + { + re_append_opcode (re_ctx_p, RE_OP_ASSERT_NOT_WORD_BOUNDARY); + break; + } + case RE_TOK_ASSERT_LOOKAHEAD: + { + const uint32_t start_capture_count = re_ctx_p->captures_count; + const bool is_negative = !!re_ctx_p->token.value; + + ecma_value_t result = re_parse_alternative (re_ctx_p, false); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (re_ctx_p->flags & RE_FLAG_UNICODE) + { + re_ctx_p->token.qmin = 1; + re_ctx_p->token.qmax = 1; + re_ctx_p->token.greedy = true; + } + else + { + re_parse_quantifier (re_ctx_p); + + if (ECMA_IS_VALUE_ERROR (re_check_quantifier (re_ctx_p))) + { + return ECMA_VALUE_ERROR; + } + } + + re_insert_assertion_lookahead (re_ctx_p, atom_offset, start_capture_count, is_negative); + break; + } + case RE_TOK_BACKREFERENCE: + { + const uint32_t backref_idx = re_ctx_p->token.value; + re_append_opcode (re_ctx_p, RE_OP_BACKREFERENCE); + re_append_value (re_ctx_p, backref_idx); + + if (re_ctx_p->token.qmin != 1 || re_ctx_p->token.qmax != 1) + { + const uint32_t group_idx = re_ctx_p->non_captures_count++; + re_insert_into_group (re_ctx_p, atom_offset, group_idx, re_ctx_p->captures_count, false); + } + + break; + } + case RE_TOK_CLASS_ESCAPE: + { + const ecma_class_escape_t escape = (ecma_class_escape_t) re_ctx_p->token.value; + re_append_opcode (re_ctx_p, RE_OP_CLASS_ESCAPE); + re_append_byte (re_ctx_p, (uint8_t) escape); + + re_insert_atom_iterator (re_ctx_p, atom_offset); + break; + } + case RE_TOK_CHAR_CLASS: + { + ecma_value_t result = re_parse_char_class (re_ctx_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + re_insert_atom_iterator (re_ctx_p, atom_offset); + break; + } + case RE_TOK_END_GROUP: + { + if (expect_eof) + { + return ecma_raise_syntax_error (ECMA_ERR_UNMATCHED_CLOSE_BRACKET); + } + + if (!first_alternative) + { + re_insert_value (re_ctx_p, alternative_offset, re_bytecode_size (re_ctx_p) - alternative_offset); + re_insert_opcode (re_ctx_p, alternative_offset, RE_OP_ALTERNATIVE_NEXT); + } + + return ECMA_VALUE_EMPTY; + } + case RE_TOK_EOF: + { + if (!expect_eof) + { + return ecma_raise_syntax_error (ECMA_ERR_UNEXPECTED_END_OF_PATTERN); + } + + if (!first_alternative) + { + re_insert_value (re_ctx_p, alternative_offset, re_bytecode_size (re_ctx_p) - alternative_offset); + re_insert_opcode (re_ctx_p, alternative_offset, RE_OP_ALTERNATIVE_NEXT); + } + + re_append_opcode (re_ctx_p, RE_OP_EOF); + return ECMA_VALUE_EMPTY; + } + default: + { + JERRY_ASSERT (re_ctx_p->token.type == RE_TOK_CHAR); + + lit_code_point_t ch = re_ctx_p->token.value; + + if (ch <= LIT_UTF8_1_BYTE_CODE_POINT_MAX && (re_ctx_p->flags & RE_FLAG_IGNORE_CASE) == 0) + { + re_append_opcode (re_ctx_p, RE_OP_BYTE); + re_append_byte (re_ctx_p, (uint8_t) ch); + + re_insert_atom_iterator (re_ctx_p, atom_offset); + break; + } + + if (re_ctx_p->flags & RE_FLAG_IGNORE_CASE) + { + ch = ecma_regexp_canonicalize_char (ch, re_ctx_p->flags & RE_FLAG_UNICODE); + } + + re_append_opcode (re_ctx_p, RE_OP_CHAR); + re_append_char (re_ctx_p, ch); + + re_insert_atom_iterator (re_ctx_p, atom_offset); + break; + } + } + } + + return ECMA_VALUE_EMPTY; +} /* re_parse_alternative */ + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-parser.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-parser.h new file mode 100644 index 0000000..0c28edc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-parser.h @@ -0,0 +1,59 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RE_PARSER_H +#define RE_PARSER_H + +#include "re-compiler-context.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_parser Parser + * @{ + */ + +/** + * @} + * + * \addtogroup regexparser_parser Parser + * @{ + */ + +/** + * Value used for infinite quantifier. + */ +#define RE_INFINITY UINT32_MAX + +/** + * Maximum decimal value of an octal escape + */ +#define RE_MAX_OCTAL_VALUE 0xff + +ecma_value_t re_parse_alternative (re_compiler_ctx_t *re_ctx_p, bool expect_eof); + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ +#endif /* !RE_PARSER_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-token.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-token.h new file mode 100644 index 0000000..ad3b5df --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/parser/regexp/re-token.h @@ -0,0 +1,74 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RE_TOKEN_H +#define RE_TOKEN_H + +#include "ecma-globals.h" + +#if JERRY_BUILTIN_REGEXP + +/** \addtogroup parser Parser + * @{ + * + * \addtogroup regexparser Regular expression + * @{ + * + * \addtogroup regexparser_parser Parser + * @{ + */ + +/** + * RegExp token type definitions + */ +typedef enum +{ + RE_TOK_EOF, /**< EOF */ + RE_TOK_BACKREFERENCE, /**< "\[0..9]" */ + RE_TOK_ALTERNATIVE, /**< "|" */ + RE_TOK_ASSERT_START, /**< "^" */ + RE_TOK_ASSERT_END, /**< "$" */ + RE_TOK_PERIOD, /**< "." */ + RE_TOK_START_CAPTURE_GROUP, /**< "(" */ + RE_TOK_START_NON_CAPTURE_GROUP, /**< "(?:" */ + RE_TOK_END_GROUP, /**< ")" */ + RE_TOK_ASSERT_LOOKAHEAD, /**< "(?=" */ + RE_TOK_ASSERT_WORD_BOUNDARY, /**< "\b" */ + RE_TOK_ASSERT_NOT_WORD_BOUNDARY, /**< "\B" */ + RE_TOK_CLASS_ESCAPE, /**< "\d \D \w \W \s \S" */ + RE_TOK_CHAR_CLASS, /**< "[ ]" */ + RE_TOK_CHAR, /**< any character */ +} re_token_type_t; + +/** + * RegExp token + */ +typedef struct +{ + uint32_t value; /**< value of the token */ + uint32_t qmin; /**< minimum number of token iterations */ + uint32_t qmax; /**< maximum number of token iterations */ + re_token_type_t type; /**< type of the token */ + bool greedy; /**< type of iteration */ +} re_token_t; + +/** + * @} + * @} + * @} + */ + +#endif /* JERRY_BUILTIN_REGEXP */ +#endif /* !RE_TOKEN_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/meson.build new file mode 100644 index 0000000..b2621be --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/meson.build @@ -0,0 +1,18 @@ +source_file = [ + 'opcodes.h', + 'vm-defines.h', + 'vm-stack.h', + 'vm.h', + 'opcodes-ecma-arithmetics.cpp', + 'opcodes-ecma-bitwise.cpp', + 'opcodes-ecma-relational-equality.cpp', + 'opcodes.cpp', + 'vm-stack.cpp', + 'vm-utils.cpp', + 'vm.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-arithmetics.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-arithmetics.cpp new file mode 100644 index 0000000..d6503a4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-arithmetics.cpp @@ -0,0 +1,337 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-bigint.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "jrt-libc-includes.h" +#include "opcodes.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_opcodes Opcodes + * @{ + */ + +/** + * Perform ECMA number arithmetic operation. + * + * The algorithm of the operation is following: + * leftNum = ToNumber (leftValue); + * rightNum = ToNumber (rightValue); + * result = leftNum ArithmeticOp rightNum; + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +do_number_arithmetic (number_arithmetic_op op, /**< number arithmetic operation */ + ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /**< right value */ +{ + ecma_number_t left_number; + left_value = ecma_op_to_numeric (left_value, &left_number, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (left_value)) + { + return left_value; + } + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + +#if JERRY_BUILTIN_BIGINT + if (JERRY_LIKELY (!ecma_is_value_bigint (left_value))) + { +#endif /* JERRY_BUILTIN_BIGINT */ + + ecma_number_t right_number; + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (right_value, &right_number))) + { + return ECMA_VALUE_ERROR; + } + + ecma_number_t result = ECMA_NUMBER_ZERO; + + switch (op) + { + case NUMBER_ARITHMETIC_SUBTRACTION: + { + result = left_number - right_number; + break; + } + case NUMBER_ARITHMETIC_MULTIPLICATION: + { + result = left_number * right_number; + break; + } + case NUMBER_ARITHMETIC_DIVISION: + { + result = left_number / right_number; + break; + } + case NUMBER_ARITHMETIC_REMAINDER: + { + if (ecma_number_is_nan (left_number) || ecma_number_is_nan (right_number) + || ecma_number_is_infinity (left_number) || ecma_number_is_zero (right_number)) + { + result = ecma_number_make_nan (); + break; + } + + if (ecma_number_is_infinity (right_number) + || (ecma_number_is_zero (left_number) && !ecma_number_is_zero (right_number))) + { + result = left_number; + break; + } + + result = ecma_number_remainder (left_number, right_number); + break; + } + case NUMBER_ARITHMETIC_EXPONENTIATION: + { + result = ecma_number_pow (left_number, right_number); + break; + } + } + + ret_value = ecma_make_number_value (result); +#if JERRY_BUILTIN_BIGINT + } + else + { + bool free_right_value; + right_value = ecma_bigint_get_bigint (right_value, &free_right_value); + + if (ECMA_IS_VALUE_ERROR (right_value)) + { + ecma_free_value (left_value); + return right_value; + } + + switch (op) + { + case NUMBER_ARITHMETIC_SUBTRACTION: + { + ret_value = ecma_bigint_add_sub (left_value, right_value, false); + break; + } + case NUMBER_ARITHMETIC_MULTIPLICATION: + { + ret_value = ecma_bigint_mul (left_value, right_value); + break; + } + case NUMBER_ARITHMETIC_DIVISION: + { + ret_value = ecma_bigint_div_mod (left_value, right_value, false); + break; + } + case NUMBER_ARITHMETIC_REMAINDER: + { + ret_value = ecma_bigint_div_mod (left_value, right_value, true); + break; + } + case NUMBER_ARITHMETIC_EXPONENTIATION: + { + ret_value = ecma_bigint_pow (left_value, right_value); + break; + } + } + + ecma_free_value (left_value); + if (free_right_value) + { + ecma_free_value (right_value); + } + } +#endif /* JERRY_BUILTIN_BIGINT */ + return ret_value; +} /* do_number_arithmetic */ + +/** + * 'Addition' opcode handler. + * + * See also: ECMA-262 v5, 11.6.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +opfunc_addition (ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /**< right value */ +{ + bool free_left_value = false; + bool free_right_value = false; + + if (ecma_is_value_object (left_value)) + { + ecma_object_t *obj_p = ecma_get_object_from_value (left_value); + left_value = ecma_op_object_default_value (obj_p, ECMA_PREFERRED_TYPE_NO); + free_left_value = true; + + if (ECMA_IS_VALUE_ERROR (left_value)) + { + return left_value; + } + } + + if (ecma_is_value_object (right_value)) + { + ecma_object_t *obj_p = ecma_get_object_from_value (right_value); + right_value = ecma_op_object_default_value (obj_p, ECMA_PREFERRED_TYPE_NO); + free_right_value = true; + + if (ECMA_IS_VALUE_ERROR (right_value)) + { + if (free_left_value) + { + ecma_free_value (left_value); + } + return right_value; + } + } + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + + if (ecma_is_value_string (left_value) || ecma_is_value_string (right_value)) + { + ecma_string_t *string1_p = ecma_op_to_string (left_value); + + if (JERRY_UNLIKELY (string1_p == NULL)) + { + if (free_left_value) + { + ecma_free_value (left_value); + } + if (free_right_value) + { + ecma_free_value (right_value); + } + return ECMA_VALUE_ERROR; + } + + ecma_string_t *string2_p = ecma_op_to_string (right_value); + + if (JERRY_UNLIKELY (string2_p == NULL)) + { + if (free_right_value) + { + ecma_free_value (right_value); + } + if (free_left_value) + { + ecma_free_value (left_value); + } + ecma_deref_ecma_string (string1_p); + return ECMA_VALUE_ERROR; + } + + string1_p = ecma_concat_ecma_strings (string1_p, string2_p); + ret_value = ecma_make_string_value (string1_p); + + ecma_deref_ecma_string (string2_p); + } +#if JERRY_BUILTIN_BIGINT + else if (JERRY_UNLIKELY (ecma_is_value_bigint (left_value)) && JERRY_UNLIKELY (ecma_is_value_bigint (right_value))) + { + ret_value = ecma_bigint_add_sub (left_value, right_value, true); + } +#endif /* JERRY_BUILTIN_BIGINT */ + else + { + ecma_number_t num_left; + ecma_number_t num_right; + if (!ECMA_IS_VALUE_ERROR (ecma_op_to_number (left_value, &num_left)) + && !ECMA_IS_VALUE_ERROR (ecma_op_to_number (right_value, &num_right))) + { + ret_value = ecma_make_number_value (num_left + num_right); + } + else + { + ret_value = ECMA_VALUE_ERROR; + } + } + + if (free_left_value) + { + ecma_free_value (left_value); + } + + if (free_right_value) + { + ecma_free_value (right_value); + } + + return ret_value; +} /* opfunc_addition */ + +/** + * Unary operation opcode handler. + * + * See also: ECMA-262 v5, 11.4, 11.4.6, 11.4.7 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +opfunc_unary_operation (ecma_value_t left_value, /**< left value */ + bool is_plus) /**< unary plus flag */ +{ + ecma_number_t left_number; + left_value = ecma_op_to_numeric (left_value, &left_number, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (left_value)) + { + return left_value; + } + +#if JERRY_BUILTIN_BIGINT + if (JERRY_LIKELY (!ecma_is_value_bigint (left_value))) + { + return ecma_make_number_value (is_plus ? left_number : -left_number); + } + + ecma_value_t ret_value; + + if (is_plus) + { + ret_value = ecma_raise_type_error (ECMA_ERR_UNARY_PLUS_IS_NOT_ALLOWED_FOR_BIGINTS); + } + else + { + ret_value = left_value; + + if (left_value != ECMA_BIGINT_ZERO) + { + ret_value = ecma_bigint_negate (ecma_get_extended_primitive_from_value (left_value)); + } + } + + ecma_free_value (left_value); + return ret_value; +#else /* !JERRY_BUILTIN_BIGINT */ + return ecma_make_number_value (is_plus ? left_number : -left_number); +#endif /* JERRY_BUILTIN_BIGINT */ +} /* opfunc_unary_operation */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-bitwise.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-bitwise.cpp new file mode 100644 index 0000000..3653f7b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-bitwise.cpp @@ -0,0 +1,212 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-bigint.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "opcodes.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_opcodes Opcodes + * @{ + */ + +/** + * Perform ECMA number logic operation. + * + * The algorithm of the operation is following: + * leftNum = ToNumber (leftValue); + * rightNum = ToNumber (rightValue); + * result = leftNum BitwiseLogicOp rightNum; + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +do_number_bitwise_logic (number_bitwise_logic_op op, /**< number bitwise logic operation */ + ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /**< right value */ +{ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + ecma_number_t left_number; + left_value = ecma_op_to_numeric (left_value, &left_number, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (left_value)) + { + return left_value; + } + + ecma_value_t ret_value = ECMA_VALUE_EMPTY; + +#if JERRY_BUILTIN_BIGINT + if (JERRY_LIKELY (!ecma_is_value_bigint (left_value))) + { +#endif /* JERRY_BUILTIN_BIGINT */ + ecma_number_t right_number; + + if (ECMA_IS_VALUE_ERROR (ecma_op_to_number (right_value, &right_number))) + { + return ECMA_VALUE_ERROR; + } + + ecma_number_t result = ECMA_NUMBER_ZERO; + uint32_t right_uint32 = ecma_number_to_uint32 (right_number); + + switch (op) + { + case NUMBER_BITWISE_LOGIC_AND: + { + uint32_t left_uint32 = ecma_number_to_uint32 (left_number); + result = (ecma_number_t) ((int32_t) (left_uint32 & right_uint32)); + break; + } + case NUMBER_BITWISE_LOGIC_OR: + { + uint32_t left_uint32 = ecma_number_to_uint32 (left_number); + result = (ecma_number_t) ((int32_t) (left_uint32 | right_uint32)); + break; + } + case NUMBER_BITWISE_LOGIC_XOR: + { + uint32_t left_uint32 = ecma_number_to_uint32 (left_number); + result = (ecma_number_t) ((int32_t) (left_uint32 ^ right_uint32)); + break; + } + case NUMBER_BITWISE_SHIFT_LEFT: + { + result = (ecma_number_t) ((int32_t) ((uint32_t) ecma_number_to_int32 (left_number) << (right_uint32 & 0x1F))); + break; + } + case NUMBER_BITWISE_SHIFT_RIGHT: + { + result = (ecma_number_t) (ecma_number_to_int32 (left_number) >> (right_uint32 & 0x1F)); + break; + } + default: + { + JERRY_ASSERT (op == NUMBER_BITWISE_SHIFT_URIGHT); + + uint32_t left_uint32 = ecma_number_to_uint32 (left_number); + result = (ecma_number_t) (left_uint32 >> (right_uint32 & 0x1F)); + break; + } + } + + ret_value = ecma_make_number_value (result); + +#if JERRY_BUILTIN_BIGINT + } + else + { + bool free_right_value; + right_value = ecma_bigint_get_bigint (right_value, &free_right_value); + + if (ECMA_IS_VALUE_ERROR (right_value)) + { + ecma_free_value (left_value); + return right_value; + } + + switch (op) + { + case NUMBER_BITWISE_LOGIC_AND: + { + ret_value = ecma_bigint_and (left_value, right_value); + break; + } + case NUMBER_BITWISE_LOGIC_OR: + { + ret_value = ecma_bigint_or (left_value, right_value); + break; + } + case NUMBER_BITWISE_LOGIC_XOR: + { + ret_value = ecma_bigint_xor (left_value, right_value); + break; + } + case NUMBER_BITWISE_SHIFT_LEFT: + { + ret_value = ecma_bigint_shift (left_value, right_value, true); + break; + } + case NUMBER_BITWISE_SHIFT_RIGHT: + { + ret_value = ecma_bigint_shift (left_value, right_value, false); + break; + } + default: + { + JERRY_ASSERT (op == NUMBER_BITWISE_SHIFT_URIGHT); + + ret_value = ecma_raise_type_error (ECMA_ERR_UNSIGNED_RIGHT_SHIFT_IS_NOT_ALLOWED_FOR_BIGINTS); + break; + } + } + + ecma_free_value (left_value); + if (free_right_value) + { + ecma_free_value (right_value); + } + } +#endif /* JERRY_BUILTIN_BIGINT */ + + return ret_value; +} /* do_number_bitwise_logic */ + +/** + * Perform ECMA number bitwise not operation. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +do_number_bitwise_not (ecma_value_t value) /**< value */ +{ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (value)); + + ecma_number_t number; + value = ecma_op_to_numeric (value, &number, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return value; + } + +#if JERRY_BUILTIN_BIGINT + if (JERRY_LIKELY (!ecma_is_value_bigint (value))) + { +#endif /* JERRY_BUILTIN_BIGINT */ + return ecma_make_number_value ((ecma_number_t) ((int32_t) ~ecma_number_to_uint32 (number))); +#if JERRY_BUILTIN_BIGINT + } + + ecma_value_t ret_value = ecma_bigint_unary (value, ECMA_BIGINT_UNARY_BITWISE_NOT); + ecma_free_value (value); + return ret_value; +#endif /* JERRY_BUILTIN_BIGINT */ +} /* do_number_bitwise_not */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-relational-equality.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-relational-equality.cpp new file mode 100644 index 0000000..b3602ad --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes-ecma-relational-equality.cpp @@ -0,0 +1,173 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-comparison.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" + +#include "opcodes.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_opcodes Opcodes + * @{ + */ + +/** + * Equality opcode handler. + * + * See also: ECMA-262 v5, 11.9.1, 11.9.2 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +opfunc_equality (ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /**< right value */ +{ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + ecma_value_t compare_result = ecma_op_abstract_equality_compare (left_value, right_value); + + JERRY_ASSERT (ecma_is_value_boolean (compare_result) || ECMA_IS_VALUE_ERROR (compare_result)); + + return compare_result; +} /* opfunc_equality */ + +/** + * Relation opcode handler. + * + * See also: ECMA-262 v5, 11.8.1, 11.8.2, 11.8.3, 11.8.4 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +opfunc_relation (ecma_value_t left_value, /**< left value */ + ecma_value_t right_value, /**< right value */ + bool left_first, /**< 'LeftFirst' flag */ + bool is_invert) /**< is invert */ +{ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + ecma_value_t ret_value = ecma_op_abstract_relational_compare (left_value, right_value, left_first); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + return ret_value; + } + + if (ecma_is_value_undefined (ret_value)) + { + ret_value = ECMA_VALUE_FALSE; + } + else + { + JERRY_ASSERT (ecma_is_value_boolean (ret_value)); + + if (is_invert) + { + ret_value = ecma_invert_boolean_value (ret_value); + } + } + + return ret_value; +} /* opfunc_relation */ + +/** + * 'instanceof' opcode handler. + * + * See also: ECMA-262 v5, 11.8.6 + * + * @return ecma value + * returned value must be freed with ecma_free_value. + */ +ecma_value_t +opfunc_instanceof (ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /**< right value */ +{ + if (!ecma_is_value_object (right_value)) + { + return ecma_raise_type_error (ECMA_ERR_RIGHT_VALUE_OF_INSTANCEOF_MUST_BE_AN_OBJECT); + } + + ecma_value_t has_instance_method = ecma_op_get_method_by_symbol_id (right_value, LIT_GLOBAL_SYMBOL_HAS_INSTANCE); + if (ECMA_IS_VALUE_ERROR (has_instance_method)) + { + return has_instance_method; + } + + if (JERRY_UNLIKELY (!ecma_is_value_undefined (has_instance_method))) + { + ecma_object_t *method_obj_p = ecma_get_object_from_value (has_instance_method); + ecma_value_t has_instance_result = ecma_op_function_call (method_obj_p, right_value, &left_value, 1); + + ecma_free_value (has_instance_method); + + if (ECMA_IS_VALUE_ERROR (has_instance_result)) + { + return has_instance_result; + } + + bool has_instance = ecma_op_to_boolean (has_instance_result); + ecma_free_value (has_instance_result); + + return ecma_make_boolean_value (has_instance); + } + + ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value); + return ecma_op_object_has_instance (right_value_obj_p, left_value); +} /* opfunc_instanceof */ + +/** + * 'in' opcode handler. + * + * See also: + * * ECMA-262 v5, 11.8.7 + * * ECAM-262 v6, 12.9.3 + * + * @return ecma value + * returned value must be freed with ecma_free_value. + */ +ecma_value_t +opfunc_in (ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /**< right value */ +{ + if (!ecma_is_value_object (right_value)) + { + return ecma_raise_type_error (ECMA_ERR_RIGHT_VALUE_OF_IN_MUST_BE_AN_OBJECT); + } + + ecma_string_t *property_name_p = ecma_op_to_property_key (left_value); + + if (JERRY_UNLIKELY (property_name_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value); + ecma_value_t result = ecma_op_object_has_property (right_value_obj_p, property_name_p); + ecma_deref_ecma_string (property_name_p); + return result; +} /* opfunc_in */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes.cpp new file mode 100644 index 0000000..0445cd7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes.cpp @@ -0,0 +1,2267 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "opcodes.h" + +#include "ecma-alloc.h" +#include "ecma-array-object.h" +#include "ecma-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-lex-env.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" +#include "ecma-proxy-object.h" + +#include "jcontext.h" +#include "vm-defines.h" +#include "vm-stack.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_opcodes Opcodes + * @{ + */ + +/** + * 'typeof' opcode handler. + * + * See also: ECMA-262 v5, 11.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +opfunc_typeof (ecma_value_t left_value) /**< left value */ +{ + return ecma_make_magic_string_value (ecma_get_typeof_lit_id (left_value)); +} /* opfunc_typeof */ + +/** + * Update data property for object literals. + */ +void +opfunc_set_data_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *prop_name_p, /**< data property name */ + ecma_value_t value) /**< new value */ +{ + JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p)); + + ecma_property_t *property_p = ecma_find_named_property (object_p, prop_name_p); + ecma_property_value_t *prop_value_p; + + if (property_p == NULL) + { + prop_value_p = + ecma_create_named_data_property (object_p, prop_name_p, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, NULL); + } + else + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (!(*property_p & ECMA_PROPERTY_FLAG_DATA)) + { + *property_p |= ECMA_PROPERTY_FLAG_DATA | ECMA_PROPERTY_FLAG_WRITABLE; + prop_value_p->value = ecma_copy_value_if_not_object (value); + return; + } + } + + ecma_named_data_property_assign_value (object_p, prop_value_p, value); +} /* opfunc_set_data_property */ + +/** + * Update getter or setter for object literals. + */ +void +opfunc_set_accessor (bool is_getter, /**< is getter accessor */ + ecma_value_t object, /**< object value */ + ecma_string_t *accessor_name_p, /**< accessor name */ + ecma_value_t accessor) /**< accessor value */ +{ + ecma_object_t *object_p = ecma_get_object_from_value (object); + + JERRY_ASSERT (!ecma_op_object_is_fast_array (object_p)); + + ecma_property_t *property_p = ecma_find_named_property (object_p, accessor_name_p); + ecma_object_t *accessor_p = ecma_get_object_from_value (accessor); + + ecma_object_t *getter_func_p = NULL; + ecma_object_t *setter_func_p = NULL; + + if (is_getter) + { + getter_func_p = accessor_p; + } + else + { + setter_func_p = accessor_p; + } + + if (property_p == NULL) + { + ecma_create_named_accessor_property (object_p, + accessor_name_p, + getter_func_p, + setter_func_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE, + NULL); + } + else + { + JERRY_ASSERT (ECMA_PROPERTY_IS_RAW (*property_p)); + + ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + + if (*property_p & ECMA_PROPERTY_FLAG_DATA) + { + ecma_free_value_if_not_object (prop_value_p->value); + *property_p = (uint8_t) (*property_p & ~(ECMA_PROPERTY_FLAG_DATA | ECMA_PROPERTY_FLAG_WRITABLE)); + + ECMA_SET_POINTER (prop_value_p->getter_setter_pair.getter_cp, getter_func_p); + ECMA_SET_POINTER (prop_value_p->getter_setter_pair.setter_cp, setter_func_p); + return; + } + + if (is_getter) + { + ecma_set_named_accessor_property_getter (object_p, prop_value_p, accessor_p); + } + else + { + ecma_set_named_accessor_property_setter (object_p, prop_value_p, accessor_p); + } + } +} /* opfunc_set_accessor */ + +/** + * Deletes an object property. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +vm_op_delete_prop (ecma_value_t object, /**< base object */ + ecma_value_t property, /**< property name */ + bool is_strict) /**< strict mode */ +{ + if (!ecma_op_require_object_coercible (object)) + { + return ECMA_VALUE_ERROR; + } + + ecma_string_t *name_string_p = ecma_op_to_property_key (property); + + if (JERRY_UNLIKELY (name_string_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t obj_value = ecma_op_to_object (object); + /* The ecma_op_require_object_coercible call already checked the op_to_object error cases. */ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_value)); + JERRY_ASSERT (ecma_is_value_object (obj_value)); + ecma_object_t *obj_p = ecma_get_object_from_value (obj_value); + JERRY_ASSERT (!ecma_is_lexical_environment (obj_p)); + + ecma_value_t delete_op_ret = ecma_op_object_delete (obj_p, name_string_p, is_strict); + JERRY_ASSERT (ecma_is_value_boolean (delete_op_ret) || ECMA_IS_VALUE_ERROR (delete_op_ret)); + ecma_deref_object (obj_p); + ecma_deref_ecma_string (name_string_p); + + if (is_strict && ecma_is_value_false (delete_op_ret)) + { + return ecma_raise_type_error (ECMA_ERR_OPERATOR_DELETE_RETURNED_FALSE_IN_STRICT_MODE); + } + + return delete_op_ret; +} /* vm_op_delete_prop */ + +/** + * Deletes a variable. + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +vm_op_delete_var (ecma_value_t name_literal, /**< name literal */ + ecma_object_t *lex_env_p) /**< lexical environment */ +{ + ecma_value_t completion_value = ECMA_VALUE_EMPTY; + + ecma_string_t *var_name_str_p = ecma_get_string_from_value (name_literal); + + ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (lex_env_p, var_name_str_p); + +#if JERRY_BUILTIN_PROXY + if (JERRY_UNLIKELY (ref_base_lex_env_p == ECMA_OBJECT_POINTER_ERROR)) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ref_base_lex_env_p == NULL) + { + completion_value = ECMA_VALUE_TRUE; + } + else + { + JERRY_ASSERT (ecma_is_lexical_environment (ref_base_lex_env_p)); + + completion_value = ecma_op_delete_binding (ref_base_lex_env_p, var_name_str_p); + } + + return completion_value; +} /* vm_op_delete_var */ + +/** + * 'for-in' opcode handler + * + * Note: from ES2015 (ES6) the for-in can trigger error when + * the property names are not available (ex.: via Proxy ownKeys). + * In these cases an error must be returned. + * + * This error is returned as the `result_obj_p` and the + * function's return value is NULL. + * + * See also: + * ECMA-262 v5, 12.6.4 + * + * @return - chain list of property names + * - In case of error: NULL is returned and the `result_obj_p` + * must be checked. + */ +ecma_collection_t * +opfunc_for_in (ecma_value_t iterable_value, /**< ideally an iterable value */ + ecma_value_t *result_obj_p) /**< expression object */ +{ + /* 3. */ + if (ecma_is_value_undefined (iterable_value) || ecma_is_value_null (iterable_value)) + { + return NULL; + } + + /* 4. */ + ecma_value_t obj_expr_value = ecma_op_to_object (iterable_value); + /* ecma_op_to_object will only raise error on null/undefined values but those are handled above. */ + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_expr_value)); + ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value); + ecma_collection_t *prop_names_p = ecma_op_object_enumerate (obj_p); + + if (JERRY_UNLIKELY (prop_names_p == NULL)) + { + ecma_deref_object (obj_p); + *result_obj_p = ECMA_VALUE_ERROR; + return NULL; + } + + if (prop_names_p->item_count != 0) + { + *result_obj_p = ecma_make_object_value (obj_p); + return prop_names_p; + } + + ecma_deref_object (obj_p); + ecma_collection_destroy (prop_names_p); + + return NULL; +} /* opfunc_for_in */ + +/** + * 'VM_OC_APPEND_ARRAY' opcode handler specialized for spread objects + * + * @return ECMA_VALUE_ERROR - if the operation failed + * ECMA_VALUE_EMPTY, otherwise + */ +static ecma_value_t JERRY_ATTR_NOINLINE +opfunc_append_to_spread_array (ecma_value_t *stack_top_p, /**< current stack top */ + uint16_t values_length) /**< number of elements to set */ +{ + JERRY_ASSERT (!(values_length & OPFUNC_HAS_SPREAD_ELEMENT)); + + ecma_object_t *array_obj_p = ecma_get_object_from_value (stack_top_p[-1]); + JERRY_ASSERT (ecma_get_object_type (array_obj_p) == ECMA_OBJECT_TYPE_ARRAY); + + ecma_extended_object_t *ext_array_obj_p = (ecma_extended_object_t *) array_obj_p; + uint32_t old_length = ext_array_obj_p->u.array.length; + + for (uint32_t i = 0, idx = old_length; i < values_length; i++, idx++) + { + if (ecma_is_value_array_hole (stack_top_p[i])) + { + continue; + } + + if (stack_top_p[i] == ECMA_VALUE_SPREAD_ELEMENT) + { + i++; + ecma_value_t ret_value = ECMA_VALUE_ERROR; + ecma_value_t spread_value = stack_top_p[i]; + + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (spread_value, ECMA_VALUE_SYNC_ITERATOR, &next_method); + + if (!ECMA_IS_VALUE_ERROR (iterator)) + { + while (true) + { + ecma_value_t next_value = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (next_value)) + { + break; + } + + if (ecma_is_value_false (next_value)) + { + idx--; + ret_value = ECMA_VALUE_EMPTY; + break; + } + + ecma_value_t value = ecma_op_iterator_value (next_value); + + ecma_free_value (next_value); + + if (ECMA_IS_VALUE_ERROR (value)) + { + break; + } + + ecma_builtin_helper_def_prop_by_index (array_obj_p, idx++, value, ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_free_value (value); + } + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + ecma_free_value (spread_value); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + for (uint32_t k = i + 1; k < values_length; k++) + { + ecma_free_value (stack_top_p[k]); + } + + return ret_value; + } + } + else + { + ecma_builtin_helper_def_prop_by_index (array_obj_p, idx, stack_top_p[i], ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE); + ecma_free_value (stack_top_p[i]); + } + } + + return ECMA_VALUE_EMPTY; +} /* opfunc_append_to_spread_array */ + +/** + * Spread function call/construct arguments into an ecma-collection + * + * @return NULL - if the operation failed + * pointer to the ecma-collection with the spreaded arguments, otherwise + */ +JERRY_ATTR_NOINLINE ecma_collection_t * +opfunc_spread_arguments (ecma_value_t *stack_top_p, /**< pointer to the current stack top */ + uint8_t arguments_list_len) /**< number of arguments */ +{ + ecma_collection_t *buff_p = ecma_new_collection (); + + for (uint32_t i = 0; i < arguments_list_len; i++) + { + ecma_value_t arg = *stack_top_p++; + + if (arg != ECMA_VALUE_SPREAD_ELEMENT) + { + ecma_collection_push_back (buff_p, arg); + continue; + } + + ecma_value_t ret_value = ECMA_VALUE_ERROR; + ecma_value_t spread_value = *stack_top_p++; + i++; + + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (spread_value, ECMA_VALUE_SYNC_ITERATOR, &next_method); + + if (!ECMA_IS_VALUE_ERROR (iterator)) + { + while (true) + { + ecma_value_t next_value = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (next_value)) + { + break; + } + + if (ecma_is_value_false (next_value)) + { + ret_value = ECMA_VALUE_EMPTY; + break; + } + + ecma_value_t value = ecma_op_iterator_value (next_value); + + ecma_free_value (next_value); + + if (ECMA_IS_VALUE_ERROR (value)) + { + break; + } + + ecma_collection_push_back (buff_p, value); + } + } + + ecma_free_value (iterator); + ecma_free_value (next_method); + ecma_free_value (spread_value); + + if (ECMA_IS_VALUE_ERROR (ret_value)) + { + for (uint32_t k = i + 1; k < arguments_list_len; k++) + { + ecma_free_value (*stack_top_p++); + } + + ecma_collection_free (buff_p); + buff_p = NULL; + break; + } + } + + return buff_p; +} /* opfunc_spread_arguments */ + +/** + * 'VM_OC_APPEND_ARRAY' opcode handler, for setting array object properties + * + * @return ECMA_VALUE_ERROR - if the operation failed + * ECMA_VALUE_EMPTY, otherwise + */ +ecma_value_t JERRY_ATTR_NOINLINE +opfunc_append_array (ecma_value_t *stack_top_p, /**< current stack top */ + uint16_t values_length) /**< number of elements to set + * with potential OPFUNC_HAS_SPREAD_ELEMENT flag */ +{ + if (values_length >= OPFUNC_HAS_SPREAD_ELEMENT) + { + return opfunc_append_to_spread_array (stack_top_p, (uint16_t) (values_length & ~OPFUNC_HAS_SPREAD_ELEMENT)); + } + + ecma_object_t *array_obj_p = ecma_get_object_from_value (stack_top_p[-1]); + JERRY_ASSERT (ecma_get_object_type (array_obj_p) == ECMA_OBJECT_TYPE_ARRAY); + + ecma_extended_object_t *ext_array_obj_p = (ecma_extended_object_t *) array_obj_p; + uint32_t old_length = ext_array_obj_p->u.array.length; + + if (JERRY_LIKELY (ecma_op_array_is_fast_array (ext_array_obj_p))) + { + uint32_t filled_holes = 0; + ecma_value_t *values_p = ecma_fast_array_extend (array_obj_p, old_length + values_length); + + for (uint32_t i = 0; i < values_length; i++) + { + values_p[old_length + i] = stack_top_p[i]; + + if (!ecma_is_value_array_hole (stack_top_p[i])) + { + filled_holes++; + + ecma_deref_if_object (stack_top_p[i]); + } + } + + ext_array_obj_p->u.array.length_prop_and_hole_count -= filled_holes * ECMA_FAST_ARRAY_HOLE_ONE; + + if (JERRY_UNLIKELY ((values_length - filled_holes) > ECMA_FAST_ARRAY_MAX_NEW_HOLES_COUNT)) + { + ecma_fast_array_convert_to_normal (array_obj_p); + } + } + else + { + for (uint32_t i = 0; i < values_length; i++) + { + if (!ecma_is_value_array_hole (stack_top_p[i])) + { + ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (old_length + i); + + ecma_property_value_t *prop_value_p; + + prop_value_p = ecma_create_named_data_property (array_obj_p, + index_str_p, + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, + NULL); + + ecma_deref_ecma_string (index_str_p); + prop_value_p->value = stack_top_p[i]; + ecma_deref_if_object (stack_top_p[i]); + } + } + ext_array_obj_p->u.array.length = old_length + values_length; + } + + return ECMA_VALUE_EMPTY; +} /* opfunc_append_array */ + +/** + * Create an executable object using the current frame context + * + * @return executable object + */ +vm_executable_object_t * +opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + vm_create_executable_object_type_t type) /**< executable object type */ +{ + const ecma_compiled_code_t *bytecode_header_p = frame_ctx_p->shared_p->bytecode_header_p; + size_t size, register_end; + + ecma_bytecode_ref ((ecma_compiled_code_t *) bytecode_header_p); + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + register_end = (size_t) args_p->register_end; + size = (register_end + (size_t) args_p->stack_limit) * sizeof (ecma_value_t); + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + register_end = (size_t) args_p->register_end; + size = (register_end + (size_t) args_p->stack_limit) * sizeof (ecma_value_t); + } + + size_t total_size = JERRY_ALIGNUP (sizeof (vm_executable_object_t) + size, sizeof (uintptr_t)); + + ecma_object_t *proto_p = NULL; + /* Async function objects are not accessible, so their class_id is not relevant. */ + uint8_t class_type = ECMA_OBJECT_CLASS_GENERATOR; + + if (type == VM_CREATE_EXECUTABLE_OBJECT_GENERATOR) + { + ecma_builtin_id_t default_proto_id = ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE; + + if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) == CBC_FUNCTION_ASYNC_GENERATOR) + { + default_proto_id = ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE; + class_type = ECMA_OBJECT_CLASS_ASYNC_GENERATOR; + } + + JERRY_ASSERT (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_NON_ARROW_FUNC); + proto_p = ecma_op_get_prototype_from_constructor (frame_ctx_p->shared_p->function_object_p, default_proto_id); + } + + ecma_object_t *object_p = ecma_create_object (proto_p, total_size, ECMA_OBJECT_TYPE_CLASS); + + vm_executable_object_t *executable_object_p = (vm_executable_object_t *) object_p; + + if (type == VM_CREATE_EXECUTABLE_OBJECT_GENERATOR) + { + ecma_deref_object (proto_p); + } + + executable_object_p->extended_object.u.cls.type = class_type; + executable_object_p->extended_object.u.cls.u2.executable_obj_flags = 0; + ECMA_SET_INTERNAL_VALUE_ANY_POINTER (executable_object_p->extended_object.u.cls.u3.head, NULL); + executable_object_p->iterator = ECMA_VALUE_UNDEFINED; + + JERRY_ASSERT (!(frame_ctx_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL)); + + /* Copy shared data and frame context. */ + vm_frame_ctx_shared_t *new_shared_p = &(executable_object_p->shared); + *new_shared_p = *(frame_ctx_p->shared_p); + new_shared_p->status_flags &= (uint32_t) ~VM_FRAME_CTX_SHARED_HAS_ARG_LIST; + new_shared_p->status_flags |= VM_FRAME_CTX_SHARED_EXECUTABLE; + + vm_frame_ctx_t *new_frame_ctx_p = &(executable_object_p->frame_ctx); + *new_frame_ctx_p = *frame_ctx_p; + new_frame_ctx_p->shared_p = new_shared_p; + + /* The old register values are discarded. */ + ecma_value_t *new_registers_p = VM_GET_REGISTERS (new_frame_ctx_p); + memcpy (new_registers_p, VM_GET_REGISTERS (frame_ctx_p), size); + + size_t stack_top = (size_t) (frame_ctx_p->stack_top_p - VM_GET_REGISTERS (frame_ctx_p)); + ecma_value_t *new_stack_top_p = new_registers_p + stack_top; + + new_frame_ctx_p->stack_top_p = new_stack_top_p; + + /* Initial state is "not running", so all object references are released. */ + + if (frame_ctx_p->context_depth > 0) + { + JERRY_ASSERT (type != VM_CREATE_EXECUTABLE_OBJECT_GENERATOR); + + ecma_value_t *register_end_p = new_registers_p + register_end; + + JERRY_ASSERT (register_end_p <= new_stack_top_p); + + while (new_registers_p < register_end_p) + { + ecma_deref_if_object (*new_registers_p++); + } + + vm_ref_lex_env_chain (frame_ctx_p->lex_env_p, frame_ctx_p->context_depth, new_registers_p, false); + + new_registers_p += frame_ctx_p->context_depth; + + JERRY_ASSERT (new_registers_p <= new_stack_top_p); + } + + while (new_registers_p < new_stack_top_p) + { + ecma_deref_if_object (*new_registers_p++); + } + + JERRY_ASSERT (*VM_GET_EXECUTABLE_ITERATOR (new_frame_ctx_p) == ECMA_VALUE_UNDEFINED); + + new_frame_ctx_p->this_binding = ecma_copy_value_if_not_object (new_frame_ctx_p->this_binding); + + JERRY_CONTEXT (vm_top_context_p) = new_frame_ctx_p->prev_context_p; + + return executable_object_p; +} /* opfunc_create_executable_object */ + +/** + * Byte code which resumes an executable object with throw + */ +const uint8_t opfunc_resume_executable_object_with_throw[1] = { CBC_THROW }; + +/** + * Byte code which resumes an executable object with return + */ +const uint8_t opfunc_resume_executable_object_with_return[2] = { CBC_EXT_OPCODE, CBC_EXT_RETURN }; + +/** + * Resume the execution of an inactive executable object + * + * @return value provided by the execution + */ +ecma_value_t +opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, /**< executable object */ + ecma_value_t value) /**< value pushed onto the stack (takes the reference) */ +{ + const ecma_compiled_code_t *bytecode_header_p = executable_object_p->shared.bytecode_header_p; + ecma_value_t *register_p = VM_GET_REGISTERS (&executable_object_p->frame_ctx); + ecma_value_t *register_end_p; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + register_end_p = register_p + args_p->register_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + register_end_p = register_p + args_p->register_end; + } + + ecma_value_t *stack_top_p = executable_object_p->frame_ctx.stack_top_p; + + if (value != ECMA_VALUE_EMPTY) + { + *stack_top_p = value; + executable_object_p->frame_ctx.stack_top_p = stack_top_p + 1; + } + + if (executable_object_p->frame_ctx.context_depth > 0) + { + while (register_p < register_end_p) + { + ecma_ref_if_object (*register_p++); + } + + vm_ref_lex_env_chain (executable_object_p->frame_ctx.lex_env_p, + executable_object_p->frame_ctx.context_depth, + register_p, + true); + + register_p += executable_object_p->frame_ctx.context_depth; + } + + while (register_p < stack_top_p) + { + ecma_ref_if_object (*register_p++); + } + + ecma_ref_if_object (executable_object_p->iterator); + + JERRY_ASSERT (ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED (executable_object_p)); + + executable_object_p->extended_object.u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_RUNNING; + + executable_object_p->frame_ctx.prev_context_p = JERRY_CONTEXT (vm_top_context_p); + JERRY_CONTEXT (vm_top_context_p) = &executable_object_p->frame_ctx; + + /* inside the generators the "new.target" is always "undefined" as it can't be invoked with "new" */ + ecma_object_t *old_new_target = JERRY_CONTEXT (current_new_target_p); + JERRY_CONTEXT (current_new_target_p) = NULL; + +#if JERRY_BUILTIN_REALMS + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + JERRY_CONTEXT (global_object_p) = ecma_op_function_get_realm (bytecode_header_p); +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_value_t result = vm_execute (&executable_object_p->frame_ctx); + +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + + JERRY_CONTEXT (current_new_target_p) = old_new_target; + executable_object_p->extended_object.u.cls.u2.executable_obj_flags &= (uint8_t) ~ECMA_EXECUTABLE_OBJECT_RUNNING; + + if (executable_object_p->frame_ctx.call_operation != VM_EXEC_RETURN) + { + JERRY_ASSERT (executable_object_p->frame_ctx.call_operation == VM_NO_EXEC_OP); + + /* All resources are released. */ + executable_object_p->extended_object.u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_COMPLETED; + return result; + } + + JERRY_CONTEXT (vm_top_context_p) = executable_object_p->frame_ctx.prev_context_p; + + register_p = VM_GET_REGISTERS (&executable_object_p->frame_ctx); + stack_top_p = executable_object_p->frame_ctx.stack_top_p; + + if (executable_object_p->frame_ctx.context_depth > 0) + { + while (register_p < register_end_p) + { + ecma_deref_if_object (*register_p++); + } + + vm_ref_lex_env_chain (executable_object_p->frame_ctx.lex_env_p, + executable_object_p->frame_ctx.context_depth, + register_p, + false); + + register_p += executable_object_p->frame_ctx.context_depth; + } + + while (register_p < stack_top_p) + { + ecma_deref_if_object (*register_p++); + } + + ecma_deref_if_object (executable_object_p->iterator); + + return result; +} /* opfunc_resume_executable_object */ + +/** + * Fulfill the next promise of the async generator with the value + */ +void +opfunc_async_generator_yield (ecma_extended_object_t *async_generator_object_p, /**< async generator object */ + ecma_value_t value) /**< value (takes the reference) */ +{ + ecma_async_generator_task_t *task_p; + task_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_async_generator_task_t, async_generator_object_p->u.cls.u3.head); + + ecma_value_t iter_result = ecma_create_iter_result_object (value, ECMA_VALUE_FALSE); + ecma_fulfill_promise (task_p->promise, iter_result); + + ecma_free_value (iter_result); + ecma_free_value (value); + + ecma_value_t next = task_p->next; + async_generator_object_p->u.cls.u3.head = next; + + JERRY_ASSERT (task_p->operation_value == ECMA_VALUE_UNDEFINED); + jmem_heap_free_block (task_p, sizeof (ecma_async_generator_task_t)); + + if (!ECMA_IS_INTERNAL_VALUE_NULL (next)) + { + ecma_value_t executable_object = ecma_make_object_value ((ecma_object_t *) async_generator_object_p); + ecma_enqueue_promise_async_generator_job (executable_object); + } +} /* opfunc_async_generator_yield */ + +/** + * Creates a new executable object and awaits for the value + * + * Note: + * extra_flags can be used to set additional extra_info flags + * + * @return a new Promise object on success, error otherwise + */ +ecma_value_t +opfunc_async_create_and_await (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t value, /**< awaited value (takes reference) */ + uint16_t extra_flags) /**< extra flags */ +{ + JERRY_ASSERT ( + CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags) == CBC_FUNCTION_ASYNC + || (CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags) == CBC_FUNCTION_ASYNC_ARROW)); + + ecma_object_t *promise_p = ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE); + ecma_value_t result = ecma_promise_reject_or_resolve (ecma_make_object_value (promise_p), value, true); + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + vm_executable_object_t *executable_object_p; + executable_object_p = opfunc_create_executable_object (frame_ctx_p, VM_CREATE_EXECUTABLE_OBJECT_ASYNC); + + executable_object_p->extended_object.u.cls.u2.executable_obj_flags |= extra_flags; + + ecma_promise_async_then (result, ecma_make_object_value ((ecma_object_t *) executable_object_p)); + ecma_deref_object ((ecma_object_t *) executable_object_p); + ecma_free_value (result); + + result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, promise_p); + + JERRY_ASSERT (ecma_is_value_object (result)); + executable_object_p->iterator = result; + + return result; +} /* opfunc_async_create_and_await */ + +/** + * PrivateMethodOrAccessorAdd abstract operation. + * + * See also: ECMAScript v12, 7.3.29. + * + * @return ECMA_VALUE_ERROR - initialization fails + * ECMA_VALUE_UNDEFINED - otherwise + */ +static ecma_value_t +opfunc_private_method_or_accessor_add (ecma_object_t *class_object_p, /**< the function itself */ + ecma_object_t *this_obj_p, /**< this object */ + uint32_t static_flag) /**< static_flag */ +{ + ecma_string_t *internal_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS); + ecma_property_t *prop_p = ecma_find_named_property (class_object_p, internal_string_p); + + if (prop_p == NULL) + { + return ECMA_VALUE_UNDEFINED; + } + + ecma_value_t *collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, ECMA_PROPERTY_VALUE_PTR (prop_p)->value); + ecma_value_t *current_p = collection_p + 1; + ecma_value_t *end_p = ecma_compact_collection_end (collection_p); + + while (current_p < end_p) + { + uint32_t prop_desc = *current_p++; + ecma_private_property_kind_t kind = ECMA_PRIVATE_PROPERTY_KIND (prop_desc); + + if ((prop_desc & ECMA_PRIVATE_PROPERTY_STATIC_FLAG) != static_flag || kind == ECMA_PRIVATE_FIELD) + { + current_p += 2; + continue; + } + + ecma_string_t *prop_name_p = ecma_get_symbol_from_value (*current_p++); + ecma_value_t method = *current_p++; + + JERRY_ASSERT (prop_name_p->u.hash & ECMA_SYMBOL_FLAG_PRIVATE_INSTANCE_METHOD); + + prop_p = ecma_find_named_property (this_obj_p, prop_name_p); + ecma_object_t *method_p = ecma_get_object_from_value (method); + + if (kind == ECMA_PRIVATE_METHOD) + { + if (prop_p != NULL) + { + return ecma_raise_type_error (ECMA_ERR_CANNOT_DECLARE_SAME_PRIVATE_FIELD_TWICE); + } + + ecma_property_value_t *prop_value_p = + ecma_create_named_data_property (this_obj_p, prop_name_p, ECMA_PROPERTY_FIXED, NULL); + prop_value_p->value = method; + continue; + } + + if (prop_p == NULL) + { + ecma_object_t *getter_p = (kind == ECMA_PRIVATE_GETTER) ? method_p : NULL; + ecma_object_t *setter_p = (kind == ECMA_PRIVATE_SETTER) ? method_p : NULL; + ecma_create_named_accessor_property (this_obj_p, prop_name_p, getter_p, setter_p, ECMA_PROPERTY_FIXED, NULL); + continue; + } + + ecma_property_value_t *accessor_objs_p = ECMA_PROPERTY_VALUE_PTR (prop_p); + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (accessor_objs_p); + + if (kind == ECMA_PRIVATE_GETTER) + { + ECMA_SET_POINTER (get_set_pair_p->getter_cp, method_p); + } + else + { + JERRY_ASSERT (kind == ECMA_PRIVATE_SETTER); + ECMA_SET_POINTER (get_set_pair_p->setter_cp, method_p); + } + } + + return ECMA_VALUE_UNDEFINED; +} /* opfunc_private_method_or_accessor_add */ + +/** + * DefineField abstract operation. + * + * See also: ECMAScript v12, 7.3.32. + * + * @return ECMA_VALUE_ERROR - operation fails + * ECMA_VALUE_{TRUE/FALSE} - otherwise + */ +ecma_value_t +opfunc_define_field (ecma_value_t base, /**< base */ + ecma_value_t property, /**< property */ + ecma_value_t value) /**< value */ +{ + ecma_string_t *property_key_p = ecma_op_to_property_key (property); + + JERRY_ASSERT (property_key_p != NULL); + ecma_object_t *obj_p = ecma_get_object_from_value (base); + ecma_property_descriptor_t desc = ecma_make_empty_property_descriptor (); + desc.value = value; + desc.flags = (JERRY_PROP_IS_WRITABLE | JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE + | JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_CONFIGURABLE_DEFINED + | JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_SHOULD_THROW); + + ecma_value_t result = ecma_op_object_define_own_property (obj_p, property_key_p, &desc); + ecma_deref_ecma_string (property_key_p); + + return result; +} /* opfunc_define_field */ + +/** + * Initialize class fields. + * + * @return ECMA_VALUE_ERROR - initialization fails + * ECMA_VALUE_UNDEFINED - otherwise + */ +ecma_value_t +opfunc_init_class_fields (ecma_object_t *class_object_p, /**< the function itself */ + ecma_value_t this_val) /**< this_arg of the function */ +{ + JERRY_ASSERT (ecma_is_value_object (this_val)); + ecma_object_t *this_obj_p = ecma_get_object_from_value (this_val); + + ecma_value_t result = opfunc_private_method_or_accessor_add (class_object_p, this_obj_p, 0); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + ecma_string_t *name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_INIT); + ecma_property_t *property_p = ecma_find_named_property (class_object_p, name_p); + + if (property_p == NULL) + { + return ECMA_VALUE_UNDEFINED; + } + + vm_frame_ctx_shared_class_fields_t shared_class_fields; + shared_class_fields.header.status_flags = VM_FRAME_CTX_SHARED_HAS_CLASS_FIELDS; + shared_class_fields.computed_class_fields_p = NULL; + + name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED); + ecma_property_t *class_field_property_p = ecma_find_named_property (class_object_p, name_p); + + if (class_field_property_p != NULL) + { + ecma_value_t value = ECMA_PROPERTY_VALUE_PTR (class_field_property_p)->value; + shared_class_fields.computed_class_fields_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, value); + } + + ecma_property_value_t *property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + JERRY_ASSERT (ecma_op_is_callable (property_value_p->value)); + + ecma_extended_object_t *ext_function_p; + ext_function_p = (ecma_extended_object_t *) ecma_get_object_from_value (property_value_p->value); + shared_class_fields.header.bytecode_header_p = ecma_op_function_get_compiled_code (ext_function_p); + shared_class_fields.header.function_object_p = &ext_function_p->object; + + ecma_object_t *scope_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, ext_function_p->u.function.scope_cp); + + result = vm_run (&shared_class_fields.header, this_val, scope_p); + + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result) || result == ECMA_VALUE_UNDEFINED); + return result; +} /* opfunc_init_class_fields */ + +/** + * Initialize static class fields. + * + * @return ECMA_VALUE_ERROR - initialization fails + * ECMA_VALUE_UNDEFINED - otherwise + */ +ecma_value_t +opfunc_init_static_class_fields (ecma_value_t function_object, /**< the function itself */ + ecma_value_t this_val) /**< this_arg of the function */ +{ + JERRY_ASSERT (ecma_op_is_callable (function_object)); + JERRY_ASSERT (ecma_is_value_object (this_val)); + + ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED); + ecma_object_t *function_object_p = ecma_get_object_from_value (function_object); + ecma_property_t *class_field_property_p = ecma_find_named_property (function_object_p, name_p); + + vm_frame_ctx_shared_class_fields_t shared_class_fields; + shared_class_fields.header.function_object_p = function_object_p; + shared_class_fields.header.status_flags = VM_FRAME_CTX_SHARED_HAS_CLASS_FIELDS; + shared_class_fields.computed_class_fields_p = NULL; + + if (class_field_property_p != NULL) + { + ecma_value_t value = ECMA_PROPERTY_VALUE_PTR (class_field_property_p)->value; + shared_class_fields.computed_class_fields_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, value); + } + + ecma_extended_object_t *ext_function_p = (ecma_extended_object_t *) function_object_p; + shared_class_fields.header.bytecode_header_p = ecma_op_function_get_compiled_code (ext_function_p); + + ecma_object_t *scope_p = + ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, ext_function_p->u.function.scope_cp); + + ecma_value_t result = vm_run (&shared_class_fields.header, this_val, scope_p); + + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result) || result == ECMA_VALUE_UNDEFINED); + return result; +} /* opfunc_init_static_class_fields */ + +/** + * Add the name of a computed field to a name list + * + * @return ECMA_VALUE_ERROR - name is not a valid property name + * ECMA_VALUE_UNDEFINED - otherwise + */ +ecma_value_t +opfunc_add_computed_field (ecma_value_t class_object, /**< class object */ + ecma_value_t name) /**< name of the property */ +{ + ecma_string_t *prop_name_p = ecma_op_to_property_key (name); + + if (JERRY_UNLIKELY (prop_name_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + if (ecma_prop_name_is_symbol (prop_name_p)) + { + name = ecma_make_symbol_value (prop_name_p); + } + else + { + name = ecma_make_string_value (prop_name_p); + } + + ecma_string_t *name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED); + ecma_object_t *class_object_p = ecma_get_object_from_value (class_object); + + ecma_property_t *property_p = ecma_find_named_property (class_object_p, name_p); + ecma_value_t *compact_collection_p; + ecma_property_value_t *property_value_p; + + if (property_p == NULL) + { + ECMA_CREATE_INTERNAL_PROPERTY (class_object_p, name_p, property_p, property_value_p); + compact_collection_p = ecma_new_compact_collection (); + } + else + { + property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + compact_collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, property_value_p->value); + } + + compact_collection_p = ecma_compact_collection_push_back (compact_collection_p, name); + ECMA_SET_INTERNAL_VALUE_POINTER (property_value_p->value, compact_collection_p); + return ECMA_VALUE_UNDEFINED; +} /* opfunc_add_computed_field */ + +/** + * Create implicit class constructor + * + * See also: ECMAScript v6, 14.5.14 + * + * @return - new external function ecma-object + */ +ecma_value_t +opfunc_create_implicit_class_constructor (uint8_t opcode, /**< current cbc opcode */ + const ecma_compiled_code_t *bytecode_p) /**< current byte code */ +{ + /* 8. */ + ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value; + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + + if (JERRY_UNLIKELY (script_p->refs_and_type >= CBC_SCRIPT_REF_MAX)) + { + jerry_fatal (JERRY_FATAL_REF_COUNT_LIMIT); + } + + ecma_object_t *function_object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE), + sizeof (ecma_extended_object_t), + ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION); + + ecma_extended_object_t *constructor_object_p = (ecma_extended_object_t *) function_object_p; + + script_p->refs_and_type += CBC_SCRIPT_REF_ONE; + constructor_object_p->u.constructor_function.script_value = script_value; + constructor_object_p->u.constructor_function.flags = 0; + + /* 10.a.i */ + if (opcode == CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE) + { + constructor_object_p->u.constructor_function.flags |= ECMA_CONSTRUCTOR_FUNCTION_HAS_HERITAGE; + } + + ecma_property_value_t *prop_value_p; + prop_value_p = ecma_create_named_data_property (function_object_p, + ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH), + ECMA_PROPERTY_FLAG_CONFIGURABLE, + NULL); + prop_value_p->value = ecma_make_uint32_value (0); + + return ecma_make_object_value (function_object_p); +} /* opfunc_create_implicit_class_constructor */ + +/** + * Set the [[HomeObject]] attribute of the given function object + * + * @return void + */ +void +opfunc_set_home_object (ecma_object_t *func_p, /**< function object */ + ecma_object_t *parent_env_p) /**< parent environment */ +{ + JERRY_ASSERT (ecma_is_lexical_environment (parent_env_p)); + + if (ecma_get_object_type (func_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_p; + ECMA_SET_NON_NULL_POINTER_TAG (ext_func_p->u.function.scope_cp, + parent_env_p, + JMEM_CP_GET_POINTER_TAG_BITS (ext_func_p->u.function.scope_cp)); + } +} /* opfunc_set_home_object */ + +/** + * Make private key from descriptor + * + * @return pointer to private key + */ +ecma_string_t * +opfunc_make_private_key (ecma_value_t descriptor) /**< descriptor */ +{ + ecma_string_t *private_key_p = ecma_new_symbol_from_descriptor_string (descriptor); + private_key_p->u.hash |= ECMA_SYMBOL_FLAG_PRIVATE_KEY; + + return (ecma_string_t *) private_key_p; +} /* opfunc_make_private_key */ + +/** + * Find a private property in the private elements internal property given the key + * + * @return pointer to the private property - if it is found, + * NULL - otherwise + */ +static ecma_property_t * +opfunc_find_private_key (ecma_object_t *class_object_p, /**< class environment */ + ecma_object_t *obj_p, /**< object */ + ecma_string_t *search_key_p, /**< key */ + ecma_string_t **out_private_key_p) /**< [out] private key */ +{ + if (ecma_op_object_is_fast_array (obj_p)) + { + return NULL; + } + + ecma_string_t *internal_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS); + ecma_property_t *prop_p = ecma_find_named_property (class_object_p, internal_string_p); + + if (prop_p == NULL) + { + return NULL; + } + + ecma_value_t *collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, ECMA_PROPERTY_VALUE_PTR (prop_p)->value); + ecma_value_t *current_p = collection_p + 1; + ecma_value_t *end_p = ecma_compact_collection_end (collection_p); + + while (current_p < end_p) + { + current_p++; /* skip kind */ + ecma_string_t *private_key_p = ecma_get_prop_name_from_value (*current_p++); + current_p++; /* skip value */ + + JERRY_ASSERT (ecma_prop_name_is_symbol (private_key_p)); + + ecma_string_t *private_key_desc_p = + ecma_get_string_from_value (((ecma_extended_string_t *) private_key_p)->u.symbol_descriptor); + + if (ecma_compare_ecma_strings (private_key_desc_p, search_key_p)) + { + prop_p = ecma_find_named_property (obj_p, private_key_p); + + if (out_private_key_p) + { + *out_private_key_p = private_key_p; + } + + return prop_p; + } + } + + return NULL; +} /* opfunc_find_private_key */ + +/** + * PrivateElementFind abstract operation + * + * See also: ECMAScript v12, 7.3.27 + * + * @return - ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +static ecma_property_t * +opfunc_find_private_element (ecma_object_t *obj_p, /**< object */ + ecma_string_t *key_p, /**< key */ + ecma_string_t **private_key_p, /**< [out] private key */ + bool allow_heritage) /**< heritage flag */ +{ + JERRY_ASSERT (private_key_p != NULL); + JERRY_ASSERT (*private_key_p == NULL); + ecma_object_t *lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p; + + while (true) + { + JERRY_ASSERT (lex_env_p != NULL); + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_LEXICAL_ENV_HAS_DATA) != 0 + && !ECMA_LEX_ENV_CLASS_IS_MODULE (lex_env_p)) + { + ecma_object_t *class_object_p = ((ecma_lexical_environment_class_t *) lex_env_p)->object_p; + + ecma_property_t *prop_p = opfunc_find_private_key (class_object_p, obj_p, key_p, private_key_p); + + if (prop_p || *private_key_p != NULL) + { + /* Found non shadowed property */ + return prop_p; + } + + if (!allow_heritage) + { + return NULL; + } + } + + if (lex_env_p->u2.outer_reference_cp == JMEM_CP_NULL) + { + break; + } + + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + return NULL; +} /* opfunc_find_private_element */ + +/** + * In expression runtime evaluation in case of private identifiers + * + * See also: ECMAScript v12, 13.10.1 + * + * @return - ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_TRUE - if the property was found in the base object + * ECMA_VALUE_FALSE - otherwise + */ +ecma_value_t +opfunc_private_in (ecma_value_t base, /**< base */ + ecma_value_t property) /**< property */ +{ + if (!ecma_is_value_object (base)) + { + return ecma_raise_type_error (ECMA_ERR_RIGHT_VALUE_OF_IN_MUST_BE_AN_OBJECT); + } + + ecma_object_t *obj_p = ecma_get_object_from_value (base); + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (property); + ecma_string_t *private_key_p = NULL; + + ecma_property_t *prop_p = opfunc_find_private_element (obj_p, prop_name_p, &private_key_p, false); + + return ecma_make_boolean_value (prop_p != NULL); +} /* opfunc_private_in */ + +/** + * PrivateFieldAdd abstract operation + * + * See also: ECMAScript v12, 7.3.28 + * + * @return - ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +opfunc_private_field_add (ecma_value_t base, /**< base object */ + ecma_value_t property, /**< property name */ + ecma_value_t value) /**< ecma value */ +{ + ecma_object_t *obj_p = ecma_get_object_from_value (base); + ecma_string_t *prop_name_p = ecma_get_string_from_value (property); + ecma_string_t *private_key_p = NULL; + + ecma_property_t *prop_p = opfunc_find_private_element (obj_p, prop_name_p, &private_key_p, false); + + if (prop_p != NULL) + { + return ecma_raise_type_error (ECMA_ERR_CANNOT_DECLARE_SAME_PRIVATE_FIELD_TWICE); + } + + ecma_property_value_t *value_p = + ecma_create_named_data_property (obj_p, private_key_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL); + + value_p->value = ecma_copy_value_if_not_object (value); + + return ECMA_VALUE_EMPTY; +} /* opfunc_private_field_add */ + +/** + * PrivateSet abstract operation + * + * See also: ECMAScript v12, 7.3.31 + * + * @return - ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +opfunc_private_set (ecma_value_t base, /**< this object */ + ecma_value_t property, /**< property name */ + ecma_value_t value) /**< ecma value */ +{ + ecma_value_t base_obj = ecma_op_to_object (base); + + if (ECMA_IS_VALUE_ERROR (base_obj)) + { + return base_obj; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (base_obj); + ecma_string_t *prop_name_p = ecma_get_string_from_value (property); + ecma_string_t *private_key_p = NULL; + + ecma_property_t *prop_p = opfunc_find_private_element (obj_p, prop_name_p, &private_key_p, true); + + ecma_value_t result; + + if (prop_p == NULL) + { + result = ecma_raise_type_error (ECMA_ERR_CANNOT_WRITE_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT); + } + else if (*prop_p & ECMA_PROPERTY_FLAG_DATA) + { + JERRY_ASSERT (ecma_prop_name_is_symbol (private_key_p)); + + if (private_key_p->u.hash & ECMA_SYMBOL_FLAG_PRIVATE_INSTANCE_METHOD) + { + result = ecma_raise_type_error (ECMA_ERR_PRIVATE_METHOD_IS_NOT_WRITABLE); + } + else + { + ecma_value_assign_value (&ECMA_PROPERTY_VALUE_PTR (prop_p)->value, value); + result = ecma_copy_value (value); + } + } + else + { + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (ECMA_PROPERTY_VALUE_PTR (prop_p)); + + if (get_set_pair_p->setter_cp == JMEM_CP_NULL) + { + result = ecma_raise_type_error (ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_SETTER); + } + else + { + ecma_object_t *setter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->setter_cp); + + result = ecma_op_function_call (setter_p, base, &value, 1); + } + } + + ecma_deref_object (obj_p); + + return result; +} /* opfunc_private_set */ + +/** + * PrivateGet abstract operation + * + * See also: ECMAScript v12, 7.3.30 + * + * @return - ECMA_VALUE_ERROR - if the operation fails + * private property value - otherwise + */ +ecma_value_t +opfunc_private_get (ecma_value_t base, /**< this object */ + ecma_value_t property) /**< property name */ +{ + ecma_value_t base_obj = ecma_op_to_object (base); + + if (ECMA_IS_VALUE_ERROR (base_obj)) + { + return base_obj; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (base_obj); + ecma_string_t *prop_name_p = ecma_get_string_from_value (property); + ecma_string_t *private_key_p = NULL; + + ecma_property_t *prop_p = opfunc_find_private_element (obj_p, prop_name_p, &private_key_p, true); + + ecma_value_t result; + + if (prop_p == NULL) + { + result = ecma_raise_type_error (ECMA_ERR_CANNOT_READ_PRIVATE_MEMBER_TO_AN_OBJECT_WHOSE_CLASS_DID_NOT_DECLARE_IT); + } + else if (*prop_p & ECMA_PROPERTY_FLAG_DATA) + { + result = ecma_copy_value (ECMA_PROPERTY_VALUE_PTR (prop_p)->value); + } + else + { + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (ECMA_PROPERTY_VALUE_PTR (prop_p)); + + if (get_set_pair_p->getter_cp == JMEM_CP_NULL) + { + result = ecma_raise_type_error (ECMA_ERR_PRIVATE_FIELD_WAS_DEFINED_WITHOUT_A_GETTER); + } + else + { + ecma_object_t *getter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp); + result = ecma_op_function_call (getter_p, base, NULL, 0); + } + } + + ecma_deref_object (obj_p); + + return result; +} /* opfunc_private_get */ + +/** + * Find the private property in the object who's private key descriptor matches the given key + * + * @return pointer to private key + */ +static ecma_string_t * +opfunc_create_private_key (ecma_value_t *collection_p, /**< collection of private properties */ + ecma_value_t search_key, /**< key */ + ecma_private_property_kind_t search_kind) /**< kind of the property */ +{ + if (search_kind < ECMA_PRIVATE_GETTER) + { + return opfunc_make_private_key (search_key); + } + + ecma_string_t *search_key_p = ecma_get_string_from_value (search_key); + + ecma_value_t *current_p = collection_p + 1; + ecma_value_t *end_p = ecma_compact_collection_end (collection_p); + + while (current_p < end_p) + { + ecma_private_property_kind_t kind = ECMA_PRIVATE_PROPERTY_KIND (*current_p++); + ecma_string_t *private_key_p = ecma_get_prop_name_from_value (*current_p++); + current_p++; /* skip value */ + + if (kind < ECMA_PRIVATE_GETTER) + { + continue; + } + + JERRY_ASSERT (ecma_prop_name_is_symbol (private_key_p)); + + ecma_string_t *private_key_desc_p = + ecma_get_string_from_value (((ecma_extended_string_t *) private_key_p)->u.symbol_descriptor); + + if (ecma_compare_ecma_strings (private_key_desc_p, search_key_p)) + { + ecma_deref_ecma_string (search_key_p); + ecma_ref_ecma_string (private_key_p); + return private_key_p; + } + } + + return opfunc_make_private_key (search_key); +} /* opfunc_create_private_key */ + +/** + * Collect private members for PrivateMethodOrAccessorAdd and PrivateFieldAdd abstract operations + */ +void +opfunc_collect_private_properties (ecma_value_t constructor, /**< constructor */ + ecma_value_t prop_name, /**< property name */ + ecma_value_t value, /**< value */ + uint8_t opcode) /**< opcode */ +{ + ecma_private_property_kind_t kind = ECMA_PRIVATE_FIELD; + bool is_static = false; + + if (opcode >= CBC_EXT_COLLECT_PRIVATE_STATIC_FIELD) + { + opcode = (uint8_t) (opcode - PARSER_STATIC_PRIVATE_TO_PRIVATE_OFFSET); + is_static = true; + } + + if (opcode == CBC_EXT_COLLECT_PRIVATE_METHOD) + { + prop_name ^= value; + value ^= prop_name; + prop_name ^= value; + kind = ECMA_PRIVATE_METHOD; + } + else if (opcode == CBC_EXT_COLLECT_PRIVATE_GETTER) + { + kind = ECMA_PRIVATE_GETTER; + } + else if (opcode == CBC_EXT_COLLECT_PRIVATE_SETTER) + { + kind = ECMA_PRIVATE_SETTER; + } + + JERRY_ASSERT (ecma_is_value_object (constructor)); + JERRY_ASSERT (ecma_is_value_string (prop_name)); + JERRY_ASSERT (ecma_is_value_object (value) || ecma_is_value_undefined (value)); + + ecma_object_t *constructor_p = ecma_get_object_from_value (constructor); + ecma_string_t *internal_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS); + ecma_property_t *prop_p = ecma_find_named_property (constructor_p, internal_string_p); + ecma_value_t *collection_p; + ecma_property_value_t *prop_value_p; + + if (prop_p == NULL) + { + collection_p = ecma_new_compact_collection (); + ECMA_CREATE_INTERNAL_PROPERTY (constructor_p, internal_string_p, prop_p, prop_value_p); + ECMA_SET_INTERNAL_VALUE_POINTER (prop_value_p->value, collection_p); + } + else + { + prop_value_p = ECMA_PROPERTY_VALUE_PTR (prop_p); + collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, prop_value_p->value); + } + + ecma_string_t *key_p = opfunc_create_private_key (collection_p, prop_name, kind); + + if (kind != ECMA_PRIVATE_FIELD) + { + key_p->u.hash |= ECMA_SYMBOL_FLAG_PRIVATE_INSTANCE_METHOD; + } + + if (is_static) + { + kind = (ecma_private_property_kind_t) ((int) kind | (int) ECMA_PRIVATE_PROPERTY_STATIC_FLAG); + } + + collection_p = ecma_compact_collection_push_back (collection_p, (ecma_value_t) kind); + collection_p = ecma_compact_collection_push_back (collection_p, ecma_make_symbol_value (key_p)); + collection_p = ecma_compact_collection_push_back (collection_p, value); + +#ifndef JERRY_NDEBUG + ecma_value_t *end_p = ecma_compact_collection_end (collection_p); + ecma_value_t *current_p = collection_p + 1; + + JERRY_ASSERT ((end_p - current_p) % ECMA_PRIVATE_ELEMENT_LIST_SIZE == 0); +#endif /* !defined (JERRY_NDEBUG) */ + + ECMA_SET_INTERNAL_VALUE_POINTER (prop_value_p->value, collection_p); + + ecma_free_value (value); +} /* opfunc_collect_private_properties */ + +/** + * ClassDefinitionEvaluation environment initialization part + * + * See also: ECMAScript v6, 14.5.14 + */ +void +opfunc_push_class_environment (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t **vm_stack_top, /**< VM stack top */ + ecma_value_t class_name) /**< class name */ +{ + JERRY_ASSERT (ecma_is_value_string (class_name)); + ecma_object_t *class_env_p = ecma_create_decl_lex_env (frame_ctx_p->lex_env_p); + + /* 4.a */ + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (class_env_p, + ecma_get_string_from_value (class_name), + ECMA_PROPERTY_FLAG_ENUMERABLE, + NULL); + + property_value_p->value = ECMA_VALUE_UNINITIALIZED; + frame_ctx_p->lex_env_p = class_env_p; + + *(*vm_stack_top)++ = ECMA_VALUE_RELEASE_LEX_ENV; +} /* opfunc_push_class_environment */ + +/** + * ClassDefinitionEvaluation object initialization part + * + * See also: ECMAScript v6, 14.5.14 + * + * @return - ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +opfunc_init_class (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t *stack_top_p) /**< stack top */ +{ + /* 5.b, 6.e.ii */ + ecma_object_t *ctor_parent_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); + ecma_object_t *proto_parent_p = NULL; + bool free_proto_parent = false; + + ecma_value_t super_class = stack_top_p[-2]; + ecma_object_t *ctor_p = ecma_get_object_from_value (stack_top_p[-1]); + + bool heritage_present = !ecma_is_value_array_hole (super_class); + + /* 5. ClassHeritage opt is not present */ + if (!heritage_present) + { + /* 5.a */ + proto_parent_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + } + else if (!ecma_is_value_null (super_class)) + { + /* 6.f, 6.g.i */ + if (!ecma_is_constructor (super_class)) + { + return ecma_raise_type_error (ECMA_ERR_CLASS_EXTENDS_NOT_CONSTRUCTOR); + } + + ecma_object_t *parent_p = ecma_get_object_from_value (super_class); + + /* 6.g.ii */ + ecma_value_t proto_parent = ecma_op_object_get_by_magic_id (parent_p, LIT_MAGIC_STRING_PROTOTYPE); + + /* 6.g.iii */ + if (ECMA_IS_VALUE_ERROR (proto_parent)) + { + return proto_parent; + } + + /* 6.g.iv */ + if (ecma_is_value_object (proto_parent)) + { + proto_parent_p = ecma_get_object_from_value (proto_parent); + free_proto_parent = true; + } + else if (ecma_is_value_null (proto_parent)) + { + proto_parent_p = NULL; + } + else + { + ecma_free_value (proto_parent); + return ecma_raise_type_error (ECMA_ERR_PROPERTY_PROTOTYPE_IS_NOT_AN_OBJECT); + } + + /* 6.g.v */ + ctor_parent_p = parent_p; + } + + /* 7. */ + ecma_object_t *proto_p = ecma_create_object (proto_parent_p, 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_value_t proto = ecma_make_object_value (proto_p); + + ECMA_SET_POINTER (ctor_p->u2.prototype_cp, ctor_parent_p); + + if (free_proto_parent) + { + ecma_deref_object (proto_parent_p); + } + ecma_free_value (super_class); + + /* 16. */ + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (ctor_p, + ecma_get_magic_string (LIT_MAGIC_STRING_PROTOTYPE), + ECMA_PROPERTY_FIXED, + NULL); + property_value_p->value = proto; + + /* 18. */ + property_value_p = ecma_create_named_data_property (proto_p, + ecma_get_magic_string (LIT_MAGIC_STRING_CONSTRUCTOR), + ECMA_PROPERTY_CONFIGURABLE_WRITABLE, + NULL); + property_value_p->value = ecma_make_object_value (ctor_p); + + if (ecma_get_object_type (ctor_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + opfunc_bind_class_environment (frame_ctx_p->lex_env_p, proto_p, ctor_p, ctor_p); + + /* 15. set F’s [[ConstructorKind]] internal slot to "derived". */ + if (heritage_present) + { + ECMA_SET_THIRD_BIT_TO_POINTER_TAG (((ecma_extended_object_t *) ctor_p)->u.function.scope_cp); + } + } + + stack_top_p[-2] = stack_top_p[-1]; + stack_top_p[-1] = proto; + + return ECMA_VALUE_EMPTY; +} /* opfunc_init_class */ + +/** + * Creates a new class lexical environment and binds the bound object and the class's object + * + * @return newly created class lexical environment - if func_obj_p is not present + * NULL - otherwise, also the environment is set as the func_obj_p's scope + */ +ecma_object_t * +opfunc_bind_class_environment (ecma_object_t *lex_env_p, /**< lexical environment */ + ecma_object_t *home_object_p, /**< bound object */ + ecma_object_t *ctor_p, /**< constructor object */ + ecma_object_t *func_obj_p) /**< function object */ +{ + ecma_object_t *proto_env_p = ecma_create_lex_env_class (lex_env_p, sizeof (ecma_lexical_environment_class_t)); + ECMA_SET_NON_NULL_POINTER (proto_env_p->u1.bound_object_cp, home_object_p); + ((ecma_lexical_environment_class_t *) proto_env_p)->object_p = ctor_p; + ((ecma_lexical_environment_class_t *) proto_env_p)->type = ECMA_LEX_ENV_CLASS_TYPE_CLASS_ENV; + + if (func_obj_p) + { + JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION); + ECMA_SET_NON_NULL_POINTER_TAG (((ecma_extended_object_t *) func_obj_p)->u.function.scope_cp, proto_env_p, 0); + ecma_deref_object (proto_env_p); + return NULL; + } + + return proto_env_p; +} /* opfunc_bind_class_environment */ + +/** + * Set [[Enumerable]] and [[HomeObject]] attributes for all class method + */ +static void +opfunc_set_class_attributes (ecma_object_t *obj_p, /**< object */ + ecma_object_t *parent_env_p) /**< parent environment */ +{ + jmem_cpointer_t prop_iter_cp = obj_p->u1.property_list_cp; + +#if JERRY_PROPERTY_HASHMAP + if (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + if (prop_iter_p->types[0] == ECMA_PROPERTY_TYPE_HASHMAP) + { + prop_iter_cp = prop_iter_p->next_property_cp; + } + } +#endif /* JERRY_PROPERTY_HASHMAP */ + + while (prop_iter_cp != JMEM_CP_NULL) + { + ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp); + JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p)); + + ecma_property_pair_t *property_pair_p = (ecma_property_pair_t *) prop_iter_p; + + for (uint32_t index = 0; index < ECMA_PROPERTY_PAIR_ITEM_COUNT; index++) + { + uint8_t property = property_pair_p->header.types[index]; + + if (!ECMA_PROPERTY_IS_RAW (property)) + { + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_DELETED + || (ECMA_PROPERTY_IS_INTERNAL (property) + && LIT_INTERNAL_MAGIC_STRING_IGNORED (property_pair_p->names_cp[index]))); + continue; + } + + if (property & ECMA_PROPERTY_FLAG_DATA) + { + if (ecma_is_value_object (property_pair_p->values[index].value) && ecma_is_property_enumerable (property)) + { + property_pair_p->header.types[index] = (uint8_t) (property & ~ECMA_PROPERTY_FLAG_ENUMERABLE); + opfunc_set_home_object (ecma_get_object_from_value (property_pair_p->values[index].value), parent_env_p); + } + continue; + } + + property_pair_p->header.types[index] = (uint8_t) (property & ~ECMA_PROPERTY_FLAG_ENUMERABLE); + ecma_property_value_t *accessor_objs_p = property_pair_p->values + index; + + ecma_getter_setter_pointers_t *get_set_pair_p = ecma_get_named_accessor_property (accessor_objs_p); + + if (get_set_pair_p->getter_cp != JMEM_CP_NULL) + { + opfunc_set_home_object (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->getter_cp), parent_env_p); + } + + if (get_set_pair_p->setter_cp != JMEM_CP_NULL) + { + opfunc_set_home_object (ECMA_GET_NON_NULL_POINTER (ecma_object_t, get_set_pair_p->setter_cp), parent_env_p); + } + } + + prop_iter_cp = prop_iter_p->next_property_cp; + } +} /* opfunc_set_class_attributes */ + +/** + * Set [[HomeObject]] attributes for all class private elements + */ +static void +opfunc_set_private_instance_method_attributes (ecma_object_t *class_object_p, /**< class constructor */ + ecma_object_t *parent_env_p) /**< parent environment */ +{ + ecma_string_t *internal_string_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_PRIVATE_ELEMENTS); + ecma_property_t *prop_p = ecma_find_named_property (class_object_p, internal_string_p); + + if (prop_p == NULL) + { + return; + } + + ecma_value_t *collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, ECMA_PROPERTY_VALUE_PTR (prop_p)->value); + ecma_value_t *current_p = collection_p + 1; + ecma_value_t *end_p = ecma_compact_collection_end (collection_p); + + while (current_p < end_p) + { + current_p += 2; /* skip kind, name */ + ecma_value_t value = *current_p++; + + if (!ecma_is_value_undefined (value)) + { + opfunc_set_home_object (ecma_get_object_from_value (value), parent_env_p); + } + } +} /* opfunc_set_private_instance_method_attributes */ + +/** + * Pop the current lexical environment referenced by the frame context + */ +void +opfunc_pop_lexical_environment (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + ecma_object_t *outer_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, frame_ctx_p->lex_env_p->u2.outer_reference_cp); + ecma_deref_object (frame_ctx_p->lex_env_p); + frame_ctx_p->lex_env_p = outer_env_p; +} /* opfunc_pop_lexical_environment */ + +/** + * ClassDefinitionEvaluation finalization part + * + * See also: ECMAScript v6, 14.5.14 + */ +void +opfunc_finalize_class (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t **vm_stack_top_p, /**< current vm stack top */ + ecma_value_t class_name) /**< class name */ +{ + JERRY_ASSERT (ecma_is_value_undefined (class_name) || ecma_is_value_string (class_name)); + ecma_value_t *stack_top_p = *vm_stack_top_p; + + ecma_object_t *ctor_p = ecma_get_object_from_value (stack_top_p[-2]); + ecma_object_t *proto_p = ecma_get_object_from_value (stack_top_p[-1]); + + ecma_object_t *class_env_p = frame_ctx_p->lex_env_p; + + /* 23.a */ + if (!ecma_is_value_undefined (class_name)) + { + ecma_op_initialize_binding (class_env_p, ecma_get_string_from_value (class_name), stack_top_p[-2]); + } + + ecma_object_t *ctor_env_p = opfunc_bind_class_environment (class_env_p, ctor_p, ctor_p, NULL); + ecma_object_t *proto_env_p = opfunc_bind_class_environment (class_env_p, proto_p, ctor_p, NULL); + + opfunc_set_class_attributes (ctor_p, ctor_env_p); + opfunc_set_class_attributes (proto_p, proto_env_p); + opfunc_set_private_instance_method_attributes (ctor_p, proto_env_p); + + ecma_deref_object (proto_env_p); + ecma_deref_object (ctor_env_p); + ecma_deref_object (proto_p); + + JERRY_ASSERT ((ecma_is_value_undefined (class_name) ? stack_top_p[-3] == ECMA_VALUE_UNDEFINED + : stack_top_p[-3] == ECMA_VALUE_RELEASE_LEX_ENV)); + + /* only the current class remains on the stack */ + if (stack_top_p[-3] == ECMA_VALUE_RELEASE_LEX_ENV) + { + opfunc_pop_lexical_environment (frame_ctx_p); + } + + opfunc_private_method_or_accessor_add (ctor_p, ctor_p, ECMA_PRIVATE_PROPERTY_STATIC_FLAG); + + stack_top_p[-3] = stack_top_p[-2]; + *vm_stack_top_p -= 2; +} /* opfunc_finalize_class */ + +/** + * MakeSuperPropertyReference operation + * + * See also: ECMAScript v6, 12.3.5.3 + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +opfunc_form_super_reference (ecma_value_t **vm_stack_top_p, /**< current vm stack top */ + vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t prop_name, /**< property name to resolve */ + uint8_t opcode) /**< current cbc opcode */ +{ + ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (frame_ctx_p->lex_env_p); + + if (environment_record_p && !ecma_op_this_binding_is_initialized (environment_record_p)) + { + return ecma_raise_reference_error (ECMA_ERR_CALL_SUPER_CONSTRUCTOR_DERIVED_CLASS_BEFORE_THIS); + } + + ecma_value_t parent = ecma_op_resolve_super_base (frame_ctx_p->lex_env_p); + + if (ECMA_IS_VALUE_ERROR (parent)) + { + return ecma_raise_type_error (ECMA_ERR_INVOKE_NULLABLE_SUPER_METHOD); + } + + if (!ecma_op_require_object_coercible (parent)) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t *stack_top_p = *vm_stack_top_p; + + if (opcode >= CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE) + { + JERRY_ASSERT (opcode == CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE + || opcode == CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE); + *stack_top_p++ = parent; + *stack_top_p++ = ecma_copy_value (prop_name); + *vm_stack_top_p = stack_top_p; + + return ECMA_VALUE_EMPTY; + } + + ecma_object_t *parent_p = ecma_get_object_from_value (parent); + ecma_string_t *prop_name_p = ecma_op_to_property_key (prop_name); + + if (prop_name_p == NULL) + { + ecma_deref_object (parent_p); + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_op_object_get_with_receiver (parent_p, prop_name_p, frame_ctx_p->this_binding); + ecma_deref_ecma_string (prop_name_p); + ecma_deref_object (parent_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + if (opcode == CBC_EXT_SUPER_PROP_LITERAL_REFERENCE || opcode == CBC_EXT_SUPER_PROP_REFERENCE) + { + *stack_top_p++ = ecma_copy_value (frame_ctx_p->this_binding); + *stack_top_p++ = ECMA_VALUE_UNDEFINED; + } + + *stack_top_p++ = result; + *vm_stack_top_p = stack_top_p; + + return ECMA_VALUE_EMPTY; +} /* opfunc_form_super_reference */ + +/** + * Assignment operation for SuperRefence base + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +opfunc_assign_super_reference (ecma_value_t **vm_stack_top_p, /**< vm stack top */ + vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + uint32_t opcode_data) /**< opcode data to store the result */ +{ + ecma_value_t *stack_top_p = *vm_stack_top_p; + + ecma_value_t base_obj = ecma_op_to_object (stack_top_p[-3]); + + if (ECMA_IS_VALUE_ERROR (base_obj)) + { + return base_obj; + } + + ecma_object_t *base_obj_p = ecma_get_object_from_value (base_obj); + ecma_string_t *prop_name_p = ecma_op_to_property_key (stack_top_p[-2]); + + if (prop_name_p == NULL) + { + ecma_deref_object (base_obj_p); + return ECMA_VALUE_ERROR; + } + + bool is_strict = (frame_ctx_p->status_flags & VM_FRAME_CTX_IS_STRICT) != 0; + + ecma_value_t result = + ecma_op_object_put_with_receiver (base_obj_p, prop_name_p, stack_top_p[-1], frame_ctx_p->this_binding, is_strict); + + ecma_deref_ecma_string (prop_name_p); + ecma_deref_object (base_obj_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + return result; + } + + for (int32_t i = 1; i <= 3; i++) + { + ecma_free_value (stack_top_p[-i]); + } + + stack_top_p -= 3; + + if (opcode_data & VM_OC_PUT_STACK) + { + *stack_top_p++ = result; + } + else if (opcode_data & VM_OC_PUT_BLOCK) + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = result; + } + + *vm_stack_top_p = stack_top_p; + + return result; +} /* opfunc_assign_super_reference */ + +/** + * Copy data properties of an object + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_EMPTY - otherwise + */ +ecma_value_t +opfunc_copy_data_properties (ecma_value_t target_object, /**< target object */ + ecma_value_t source_object, /**< source object */ + ecma_value_t filter_array) /**< filter array */ +{ + bool source_to_object = false; + + if (!ecma_is_value_object (source_object)) + { + source_object = ecma_op_to_object (source_object); + + if (ECMA_IS_VALUE_ERROR (source_object)) + { + return source_object; + } + + source_to_object = true; + } + + ecma_object_t *source_object_p = ecma_get_object_from_value (source_object); + ecma_collection_t *names_p = ecma_op_object_own_property_keys (source_object_p, JERRY_PROPERTY_FILTER_ALL); + +#if JERRY_BUILTIN_PROXY + if (names_p == NULL) + { + JERRY_ASSERT (!source_to_object); + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_object_t *target_object_p = ecma_get_object_from_value (target_object); + ecma_value_t *buffer_p = names_p->buffer_p; + ecma_value_t *buffer_end_p = buffer_p + names_p->item_count; + ecma_value_t *filter_start_p = NULL; + ecma_value_t *filter_end_p = NULL; + ecma_value_t result = ECMA_VALUE_EMPTY; + + if (filter_array != ECMA_VALUE_UNDEFINED) + { + ecma_object_t *filter_array_p = ecma_get_object_from_value (filter_array); + + JERRY_ASSERT (ecma_get_object_type (filter_array_p) == ECMA_OBJECT_TYPE_ARRAY); + JERRY_ASSERT (ecma_op_object_is_fast_array (filter_array_p)); + + if (filter_array_p->u1.property_list_cp != JMEM_CP_NULL) + { + filter_start_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, filter_array_p->u1.property_list_cp); + filter_end_p = filter_start_p + ((ecma_extended_object_t *) filter_array_p)->u.array.length; + } + } + + while (buffer_p < buffer_end_p) + { + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (*buffer_p++); + + if (filter_start_p != NULL) + { + ecma_value_t *filter_p = filter_start_p; + + do + { + if (ecma_compare_ecma_strings (property_name_p, ecma_get_prop_name_from_value (*filter_p))) + { + break; + } + } while (++filter_p < filter_end_p); + + if (filter_p != filter_end_p) + { + continue; + } + } + + ecma_property_descriptor_t descriptor; + result = ecma_op_object_get_own_property_descriptor (source_object_p, property_name_p, &descriptor); + + if (ECMA_IS_VALUE_ERROR (result)) + { + break; + } + + if (result == ECMA_VALUE_FALSE) + { + continue; + } + + if (!(descriptor.flags & JERRY_PROP_IS_ENUMERABLE)) + { + ecma_free_property_descriptor (&descriptor); + continue; + } + + if ((descriptor.flags & JERRY_PROP_IS_VALUE_DEFINED) && !ECMA_OBJECT_IS_PROXY (source_object_p)) + { + result = descriptor.value; + } + else + { + ecma_free_property_descriptor (&descriptor); + + result = ecma_op_object_get (source_object_p, property_name_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + break; + } + } + + opfunc_set_data_property (target_object_p, property_name_p, result); + ecma_free_value (result); + + result = ECMA_VALUE_EMPTY; + } + + if (JERRY_UNLIKELY (source_to_object)) + { + ecma_deref_object (source_object_p); + } + + ecma_collection_free (names_p); + return result; +} /* opfunc_copy_data_properties */ + +/** + * Check whether the current lexical scope has restricted binding declaration with the given name + * + * Steps are include ES11: 8.1.1.4.14 HasRestrictedGlobalProperty abstract operation + * + * @return ECMA_VALUE_ERROR - if the operation fails + * ECMA_VALUE_TRUE - if it has restricted property binding + * ECMA_VALUE_FALSE - otherwise + */ +ecma_value_t +opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_string_t *name_p) /**< binding name */ +{ + JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + ecma_property_t *binding_p = ecma_find_named_property (lex_env_p, name_p); + + if (binding_p != NULL) + { + return ECMA_VALUE_TRUE; + } + + ecma_object_t *global_obj_p = ecma_get_object_from_value (frame_ctx_p->this_binding); + +#if JERRY_BUILTIN_REALMS + ecma_object_t *const global_scope_p = ecma_get_global_scope ((ecma_object_t *) JERRY_CONTEXT (global_object_p)); +#else /* !JERRY_BUILTIN_REALMS */ + ecma_object_t *const global_scope_p = ecma_get_global_scope (global_obj_p); +#endif /* JERRY_BUILTIN_REALMS */ + + if (global_scope_p != lex_env_p) + { + return ECMA_VALUE_FALSE; + } + +#if JERRY_BUILTIN_PROXY + if (ECMA_OBJECT_IS_PROXY (global_obj_p)) + { + ecma_property_descriptor_t prop_desc; + ecma_value_t status = ecma_proxy_object_get_own_property_descriptor (global_obj_p, name_p, &prop_desc); + + if (ecma_is_value_true (status)) + { + status = ecma_make_boolean_value ((prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE) == 0); + ecma_free_property_descriptor (&prop_desc); + } + + return status; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_property_t property = ecma_op_object_get_own_property (global_obj_p, name_p, NULL, ECMA_PROPERTY_GET_NO_OPTIONS); + + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND || ECMA_PROPERTY_IS_FOUND (property)); + + return ecma_make_boolean_value (property != ECMA_PROPERTY_TYPE_NOT_FOUND + && !ecma_is_property_configurable (property)); +} /* opfunc_lexical_scope_has_restricted_binding */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes.h new file mode 100644 index 0000000..7a964bc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/opcodes.h @@ -0,0 +1,173 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OPCODES_H +#define OPCODES_H + +#include "ecma-globals.h" + +#include "vm-defines.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_opcodes Opcodes + * @{ + */ + +/** + * Number arithmetic operations. + */ +typedef enum +{ + NUMBER_ARITHMETIC_SUBTRACTION, /**< subtraction */ + NUMBER_ARITHMETIC_MULTIPLICATION, /**< multiplication */ + NUMBER_ARITHMETIC_DIVISION, /**< division */ + NUMBER_ARITHMETIC_REMAINDER, /**< remainder calculation */ + NUMBER_ARITHMETIC_EXPONENTIATION, /**< exponentiation */ +} number_arithmetic_op; + +/** + * Number bitwise logic operations. + */ +typedef enum +{ + NUMBER_BITWISE_LOGIC_AND, /**< bitwise AND calculation */ + NUMBER_BITWISE_LOGIC_OR, /**< bitwise OR calculation */ + NUMBER_BITWISE_LOGIC_XOR, /**< bitwise XOR calculation */ + NUMBER_BITWISE_SHIFT_LEFT, /**< bitwise LEFT SHIFT calculation */ + NUMBER_BITWISE_SHIFT_RIGHT, /**< bitwise RIGHT_SHIFT calculation */ + NUMBER_BITWISE_SHIFT_URIGHT, /**< bitwise UNSIGNED RIGHT SHIFT calculation */ +} number_bitwise_logic_op; + +/** + * Types for opfunc_create_executable_object. + */ +typedef enum +{ + VM_CREATE_EXECUTABLE_OBJECT_GENERATOR, /**< create a generator function */ + VM_CREATE_EXECUTABLE_OBJECT_ASYNC, /**< create an async function */ +} vm_create_executable_object_type_t; + +/** + * The stack contains spread object during the upcoming APPEND_ARRAY operation + */ +#define OPFUNC_HAS_SPREAD_ELEMENT (1 << 8) + +ecma_value_t opfunc_equality (ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t do_number_arithmetic (number_arithmetic_op op, ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t opfunc_unary_operation (ecma_value_t left_value, bool is_plus); + +ecma_value_t do_number_bitwise_logic (number_bitwise_logic_op op, ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t do_number_bitwise_not (ecma_value_t value); + +ecma_value_t opfunc_addition (ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t opfunc_relation (ecma_value_t left_value, ecma_value_t right_value, bool left_first, bool is_invert); + +ecma_value_t opfunc_in (ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t opfunc_instanceof (ecma_value_t left_value, ecma_value_t right_value); + +ecma_value_t opfunc_typeof (ecma_value_t left_value); + +void opfunc_set_data_property (ecma_object_t *object_p, ecma_string_t *prop_name_p, ecma_value_t value); + +void opfunc_set_accessor (bool is_getter, ecma_value_t object, ecma_string_t *accessor_name_p, ecma_value_t accessor); + +ecma_value_t vm_op_delete_prop (ecma_value_t object, ecma_value_t property, bool is_strict); + +ecma_value_t vm_op_delete_var (ecma_value_t name_literal, ecma_object_t *lex_env_p); + +ecma_collection_t *opfunc_for_in (ecma_value_t left_value, ecma_value_t *result_obj_p); + +ecma_collection_t *opfunc_spread_arguments (ecma_value_t *stack_top_p, uint8_t argument_list_len); + +ecma_value_t opfunc_append_array (ecma_value_t *stack_top_p, uint16_t values_length); + +vm_executable_object_t *opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p, + vm_create_executable_object_type_t type); + +extern const uint8_t opfunc_resume_executable_object_with_throw[]; +extern const uint8_t opfunc_resume_executable_object_with_return[]; + +ecma_value_t opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, ecma_value_t value); + +void opfunc_async_generator_yield (ecma_extended_object_t *async_generator_object_p, ecma_value_t value); + +ecma_value_t opfunc_async_create_and_await (vm_frame_ctx_t *frame_ctx_p, ecma_value_t value, uint16_t extra_flags); + +ecma_value_t opfunc_init_class_fields (ecma_object_t *class_object_p, ecma_value_t this_val); + +ecma_value_t opfunc_init_static_class_fields (ecma_value_t function_object, ecma_value_t this_val); + +ecma_value_t opfunc_add_computed_field (ecma_value_t class_object, ecma_value_t name); + +ecma_value_t opfunc_create_implicit_class_constructor (uint8_t opcode, const ecma_compiled_code_t *bytecode_p); + +void opfunc_set_home_object (ecma_object_t *func_p, ecma_object_t *parent_env_p); + +ecma_value_t opfunc_define_field (ecma_value_t base, ecma_value_t property, ecma_value_t value); + +ecma_string_t *opfunc_make_private_key (ecma_value_t descriptor); + +ecma_value_t opfunc_private_in (ecma_value_t base, ecma_value_t property); + +ecma_value_t opfunc_private_field_add (ecma_value_t base, ecma_value_t property, ecma_value_t value); + +ecma_value_t opfunc_private_set (ecma_value_t base, ecma_value_t property, ecma_value_t value); + +ecma_value_t opfunc_private_get (ecma_value_t base, ecma_value_t property); + +void opfunc_collect_private_properties (ecma_value_t constructor, + ecma_value_t prop_name, + ecma_value_t method, + uint8_t opcode); + +void opfunc_push_class_environment (vm_frame_ctx_t *frame_ctx_p, ecma_value_t **vm_stack_top, ecma_value_t class_name); + +ecma_value_t opfunc_init_class (vm_frame_ctx_t *frame_context_p, ecma_value_t *stack_top_p); + +ecma_object_t *opfunc_bind_class_environment (ecma_object_t *lex_env_p, + ecma_object_t *home_object_p, + ecma_object_t *ctor_p, + ecma_object_t *func_obj_p); + +void opfunc_pop_lexical_environment (vm_frame_ctx_t *frame_ctx_p); + +void opfunc_finalize_class (vm_frame_ctx_t *frame_ctx_p, ecma_value_t **vm_stack_top_p, ecma_value_t class_name); + +ecma_value_t opfunc_form_super_reference (ecma_value_t **vm_stack_top_p, + vm_frame_ctx_t *frame_ctx_p, + ecma_value_t prop_name, + uint8_t opcode); + +ecma_value_t +opfunc_assign_super_reference (ecma_value_t **vm_stack_top_p, vm_frame_ctx_t *frame_ctx_p, uint32_t opcode_data); + +ecma_value_t +opfunc_copy_data_properties (ecma_value_t target_object, ecma_value_t source_object, ecma_value_t filter_array); + +ecma_value_t opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *vm_frame_ctx_p, ecma_string_t *name_p); + +/** + * @} + * @} + */ + +#endif /* !OPCODES_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-defines.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-defines.h new file mode 100644 index 0000000..7ca7813 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-defines.h @@ -0,0 +1,169 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef VM_DEFINES_H +#define VM_DEFINES_H + +#include "ecma-globals.h" + +#include "byte-code.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_executor Executor + * @{ + */ + +/** + * Helper for += on uint16_t values. + */ +#define VM_PLUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) + (value)) + +/** + * Helper for -= on uint16_t values. + */ +#define VM_MINUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) - (value)) + +/** + * Flag bits of vm_frame_ctx_shared_t + */ +typedef enum +{ + VM_FRAME_CTX_SHARED_HAS_ARG_LIST = (1 << 0), /**< has argument list */ + VM_FRAME_CTX_SHARED_DIRECT_EVAL = (1 << 1), /**< direct eval call */ + VM_FRAME_CTX_SHARED_FREE_THIS = (1 << 2), /**< free this binding */ + VM_FRAME_CTX_SHARED_FREE_LOCAL_ENV = (1 << 3), /**< free local environment */ + VM_FRAME_CTX_SHARED_NON_ARROW_FUNC = (1 << 4), /**< non-arrow function */ + VM_FRAME_CTX_SHARED_HERITAGE_PRESENT = (1 << 5), /**< class heritage present */ + VM_FRAME_CTX_SHARED_HAS_CLASS_FIELDS = (1 << 6), /**< has class fields */ + VM_FRAME_CTX_SHARED_EXECUTABLE = (1 << 7), /**< frame is an executable object constructed + * with opfunc_create_executable_object */ +} vm_frame_ctx_shared_flags_t; + +/** + * Shared data between the interpreter and the caller + */ +typedef struct +{ + const ecma_compiled_code_t *bytecode_header_p; /**< currently executed byte-code data */ + ecma_object_t *function_object_p; /**< function obj */ + uint32_t status_flags; /**< combination of vm_frame_ctx_shared_flags_t bits */ +} vm_frame_ctx_shared_t; + +/** + * Shared data extended with arguments + */ +typedef struct +{ + vm_frame_ctx_shared_t header; /**< shared data header */ + const ecma_value_t *arg_list_p; /**< arguments list */ + uint32_t arg_list_len; /**< arguments list length */ +} vm_frame_ctx_shared_args_t; + +/** + * Shared data extended with computed class fields + */ +typedef struct +{ + vm_frame_ctx_shared_t header; /**< shared data header */ + ecma_value_t *computed_class_fields_p; /**< names of the computed class fields */ +} vm_frame_ctx_shared_class_fields_t; + +/** + * Get the computed class field + */ +#define VM_GET_COMPUTED_CLASS_FIELDS(frame_ctx_p) \ + (((vm_frame_ctx_shared_class_fields_t *) ((frame_ctx_p)->shared_p))->computed_class_fields_p) + +/** + * Flag bits of vm_frame_ctx_t + */ +typedef enum +{ + VM_FRAME_CTX_DIRECT_EVAL = (1 << 1), /**< direct eval call */ + VM_FRAME_CTX_IS_STRICT = (1 << 2), /**< strict mode */ +} vm_frame_ctx_flags_t; + +/** + * Context of interpreter, related to a JS stack frame + */ +typedef struct vm_frame_ctx_t +{ + vm_frame_ctx_shared_t *shared_p; /**< shared information */ + const uint8_t *byte_code_p; /**< current byte code pointer */ + const uint8_t *byte_code_start_p; /**< byte code start pointer */ + ecma_value_t *stack_top_p; /**< stack top pointer */ + ecma_value_t *literal_start_p; /**< literal list start pointer */ + ecma_object_t *lex_env_p; /**< current lexical environment */ + struct vm_frame_ctx_t *prev_context_p; /**< previous context */ + ecma_value_t this_binding; /**< this binding */ + uint16_t context_depth; /**< current context depth */ + uint8_t status_flags; /**< combination of vm_frame_ctx_flags_t bits */ + uint8_t call_operation; /**< perform a call or construct operation */ + /* Registers start immediately after the frame context. */ +} vm_frame_ctx_t; + +/** + * Get register list corresponding to the frame context. + */ +#define VM_GET_REGISTERS(frame_ctx_p) ((ecma_value_t *) ((frame_ctx_p) + 1)) + +/** + * Read or write a specific register. + */ +#define VM_GET_REGISTER(frame_ctx_p, i) (((ecma_value_t *) ((frame_ctx_p) + 1))[i]) + +/** + * Calculate the executable object from a vm_executable_object frame context. + */ +#define VM_GET_EXECUTABLE_OBJECT(frame_ctx_p) \ + ((ecma_extended_object_t *) ((uintptr_t) (frame_ctx_p) - (uintptr_t) offsetof (vm_executable_object_t, frame_ctx))) + +/** + * Calculate the shared_part from a vm_executable_object frame context. + */ +#define VM_GET_EXECUTABLE_ITERATOR(frame_ctx_p) \ + ((ecma_value_t *) ((uintptr_t) (frame_ctx_p) - (uintptr_t) offsetof (vm_executable_object_t, frame_ctx) \ + + (uintptr_t) offsetof (vm_executable_object_t, iterator))) + +/** + * Generator frame context. + */ +typedef struct +{ + ecma_extended_object_t extended_object; /**< extended object part */ + vm_frame_ctx_shared_t shared; /**< shared part */ + ecma_value_t iterator; /**< executable object's iterator */ + vm_frame_ctx_t frame_ctx; /**< frame context part */ +} vm_executable_object_t; + +/** + * Real backtrace frame data passed to the jerry_backtrace_cb_t handler. + */ +struct jerry_frame_internal_t +{ + vm_frame_ctx_t *context_p; /**< context pointer */ + uint8_t frame_type; /**< frame type */ + jerry_frame_location_t location; /**< location information */ + ecma_value_t function; /**< function reference */ + ecma_value_t this_binding; /**< this binding passed to the function */ +}; + +/** + * @} + * @} + */ + +#endif /* !VM_DEFINES_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-stack.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-stack.cpp new file mode 100644 index 0000000..62f46c7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-stack.cpp @@ -0,0 +1,546 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "vm-stack.h" + +#include "ecma-alloc.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" + +#include "jcontext.h" +#include "vm-defines.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup stack VM stack + * @{ + */ + +JERRY_STATIC_ASSERT (((int)PARSER_WITH_CONTEXT_STACK_ALLOCATION == (int)PARSER_BLOCK_CONTEXT_STACK_ALLOCATION), + with_context_stack_allocation_must_be_equal_to_block_context_stack_allocation); + +JERRY_STATIC_ASSERT (((int)PARSER_WITH_CONTEXT_STACK_ALLOCATION == (int)PARSER_TRY_CONTEXT_STACK_ALLOCATION), + with_context_stack_allocation_must_be_equal_to_block_context_stack_allocation); + +JERRY_STATIC_ASSERT (((int)PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION == (int)PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION), + for_of_context_stack_allocation_must_be_equal_to_for_await_of_context_stack_allocation); + +/** + * Abort (finalize) the current variable length stack context, and remove it. + * + * @return new stack top + */ +ecma_value_t * +vm_stack_context_abort_variable_length (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t *vm_stack_top_p, /**< current stack top */ + uint32_t context_stack_allocation) /**< 0 - if all context element + * should be released + * context stack allocation - otherwise */ +{ + JERRY_ASSERT (VM_CONTEXT_IS_VARIABLE_LENGTH (VM_GET_CONTEXT_TYPE (vm_stack_top_p[-1]))); + + uint32_t context_size = VM_GET_CONTEXT_END (vm_stack_top_p[-1]); + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, context_size); + + JERRY_ASSERT (context_size > 0); + --vm_stack_top_p; + + if (context_stack_allocation == 0) + { + context_stack_allocation = context_size; + } + + for (uint32_t i = 1; i < context_stack_allocation; i++) + { + ecma_free_value (*(--vm_stack_top_p)); + } + + return vm_stack_top_p; +} /* vm_stack_context_abort_variable_length */ + +/** + * Abort (finalize) the current stack context, and remove it. + * + * @return new stack top + */ +ecma_value_t * +vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t *vm_stack_top_p) /**< current stack top */ +{ + ecma_value_t context_info = vm_stack_top_p[-1]; + + if (context_info & VM_CONTEXT_HAS_LEX_ENV) + { + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + frame_ctx_p->lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + ecma_deref_object (lex_env_p); + } + + switch (VM_GET_CONTEXT_TYPE (context_info)) + { + case VM_CONTEXT_FINALLY_THROW: + case VM_CONTEXT_FINALLY_RETURN: + { + ecma_free_value (vm_stack_top_p[-2]); + /* FALLTHRU */ + } + case VM_CONTEXT_FINALLY_JUMP: + { + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION); + vm_stack_top_p -= PARSER_FINALLY_CONTEXT_STACK_ALLOCATION; + break; + } + case VM_CONTEXT_TRY: + case VM_CONTEXT_CATCH: + case VM_CONTEXT_BLOCK: + case VM_CONTEXT_WITH: + { + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION); + vm_stack_top_p -= PARSER_WITH_CONTEXT_STACK_ALLOCATION; + break; + } + case VM_CONTEXT_ITERATOR: + case VM_CONTEXT_OBJ_INIT: + case VM_CONTEXT_OBJ_INIT_REST: + { + vm_stack_top_p = vm_stack_context_abort_variable_length (frame_ctx_p, vm_stack_top_p, 0); + break; + } + case VM_CONTEXT_FOR_OF: + case VM_CONTEXT_FOR_AWAIT_OF: + { + ecma_free_value (vm_stack_top_p[-2]); + ecma_free_value (vm_stack_top_p[-3]); + ecma_free_value (vm_stack_top_p[-4]); + + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION); + vm_stack_top_p -= PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION; + break; + } + default: + { + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (vm_stack_top_p[-1]) == VM_CONTEXT_FOR_IN); + + ecma_collection_t *collection_p; + collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, vm_stack_top_p[-2]); + + ecma_value_t *buffer_p = collection_p->buffer_p; + + for (uint32_t index = vm_stack_top_p[-3]; index < collection_p->item_count; index++) + { + ecma_free_value (buffer_p[index]); + } + + ecma_collection_destroy (collection_p); + + ecma_free_value (vm_stack_top_p[-4]); + + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION); + vm_stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION; + break; + } + } + + return vm_stack_top_p; +} /* vm_stack_context_abort */ + +/** + * Decode branch offset. + * + * @return branch offset + */ +static uint32_t +vm_decode_branch_offset (const uint8_t *branch_offset_p, /**< start offset of byte code */ + uint32_t length) /**< length of the branch */ +{ + uint32_t branch_offset = *branch_offset_p; + + JERRY_ASSERT (length >= 1 && length <= 3); + + switch (length) + { + case 3: + { + branch_offset <<= 8; + branch_offset |= *(++branch_offset_p); + /* FALLTHRU */ + } + case 2: + { + branch_offset <<= 8; + branch_offset |= *(++branch_offset_p); + break; + } + } + + return branch_offset; +} /* vm_decode_branch_offset */ + +/** + * Byte code which resumes an executable object with throw + */ +static const uint8_t vm_stack_resume_executable_object_with_context_end[1] = { CBC_CONTEXT_END }; + +/** + * Find a finally up to the end position. + * + * @return value specified in vm_stack_found_type + */ +vm_stack_found_type +vm_stack_find_finally (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t *stack_top_p, /**< current stack top */ + vm_stack_context_type_t finally_type, /**< searching this finally */ + uint32_t search_limit) /**< search up-to this byte code */ +{ + JERRY_ASSERT (finally_type <= VM_CONTEXT_FINALLY_RETURN); + + if (finally_type != VM_CONTEXT_FINALLY_JUMP) + { + search_limit = 0xffffffffu; + } + + while (frame_ctx_p->context_depth > 0) + { + vm_stack_context_type_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]); + uint32_t context_end = VM_GET_CONTEXT_END (stack_top_p[-1]); + JERRY_ASSERT (!VM_CONTEXT_IS_VARIABLE_LENGTH (context_type) || finally_type != VM_CONTEXT_FINALLY_JUMP); + + if (!VM_CONTEXT_IS_VARIABLE_LENGTH (context_type) && search_limit < context_end) + { + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_EXPECTED; + } + + if (context_type == VM_CONTEXT_TRY || context_type == VM_CONTEXT_CATCH) + { + const uint8_t *byte_code_p; + uint32_t branch_offset_length; + uint32_t branch_offset; + + if (search_limit == context_end) + { + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_EXPECTED; + } + + if (stack_top_p[-1] & VM_CONTEXT_HAS_LEX_ENV) + { + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + frame_ctx_p->lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + ecma_deref_object (lex_env_p); + } + + byte_code_p = frame_ctx_p->byte_code_start_p + context_end; + + if (context_type == VM_CONTEXT_TRY) + { + JERRY_ASSERT (byte_code_p[0] == CBC_EXT_OPCODE); + + if (byte_code_p[1] >= CBC_EXT_CATCH && byte_code_p[1] <= CBC_EXT_CATCH_3) + { + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (byte_code_p[1]); + branch_offset = vm_decode_branch_offset (byte_code_p + 2, branch_offset_length); + + if (finally_type == VM_CONTEXT_FINALLY_THROW) + { + branch_offset += (uint32_t) (byte_code_p - frame_ctx_p->byte_code_start_p); + + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_CATCH, branch_offset); + + byte_code_p += 2 + branch_offset_length; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_FINALLY; + } + + byte_code_p += branch_offset; + + if (*byte_code_p == CBC_CONTEXT_END) + { + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); + stack_top_p -= PARSER_TRY_CONTEXT_STACK_ALLOCATION; + continue; + } + } + } + else + { + JERRY_ASSERT (context_type == VM_CONTEXT_CATCH); + + if (byte_code_p[0] == CBC_CONTEXT_END) + { + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); + stack_top_p -= PARSER_TRY_CONTEXT_STACK_ALLOCATION; + continue; + } + } + + JERRY_ASSERT (byte_code_p[0] == CBC_EXT_OPCODE); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION); + stack_top_p += PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION; + + if (JERRY_UNLIKELY (byte_code_p[1] == CBC_EXT_ASYNC_EXIT)) + { + branch_offset = (uint32_t) (byte_code_p - frame_ctx_p->byte_code_start_p); + stack_top_p[-1] = VM_CREATE_CONTEXT ((uint32_t) finally_type, branch_offset); + + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_FINALLY; + } + + JERRY_ASSERT (byte_code_p[1] >= CBC_EXT_FINALLY && byte_code_p[1] <= CBC_EXT_FINALLY_3); + + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (byte_code_p[1]); + branch_offset = vm_decode_branch_offset (byte_code_p + 2, branch_offset_length); + + branch_offset += (uint32_t) (byte_code_p - frame_ctx_p->byte_code_start_p); + + stack_top_p[-1] = VM_CREATE_CONTEXT ((uint32_t) finally_type, branch_offset); + + byte_code_p += 2 + branch_offset_length; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_FINALLY; + } + else if (stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR) + { + JERRY_ASSERT (context_type == VM_CONTEXT_FOR_OF || context_type == VM_CONTEXT_FOR_AWAIT_OF + || context_type == VM_CONTEXT_ITERATOR); + JERRY_ASSERT (finally_type == VM_CONTEXT_FINALLY_THROW || !jcontext_has_pending_exception ()); + + ecma_value_t exception = ECMA_VALUE_UNDEFINED; + if (finally_type == VM_CONTEXT_FINALLY_THROW) + { + exception = jcontext_take_exception (); + } + + ecma_value_t result; + + if (context_type == VM_CONTEXT_ITERATOR) + { + result = ecma_op_iterator_close (stack_top_p[-2]); + } + else + { + ecma_value_t iterator = stack_top_p[-3]; + result = ecma_op_get_method_by_magic_id (iterator, LIT_MAGIC_STRING_RETURN); + + if (!ECMA_IS_VALUE_ERROR (result) && !ecma_is_value_undefined (result)) + { + ecma_object_t *return_obj_p = ecma_get_object_from_value (result); + result = ecma_op_function_validated_call (result, iterator, NULL, 0); + ecma_deref_object (return_obj_p); + + if (context_type == VM_CONTEXT_FOR_AWAIT_OF && !ECMA_IS_VALUE_ERROR (result)) + { + ecma_extended_object_t *async_generator_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p); + + result = ecma_promise_async_await (async_generator_object_p, result); + + if (!ECMA_IS_VALUE_ERROR (result)) + { + uint16_t extra_flags = + (ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD | (ECMA_AWAIT_FOR_CLOSE << ECMA_AWAIT_STATE_SHIFT)); + async_generator_object_p->u.cls.u2.executable_obj_flags |= extra_flags; + + stack_top_p = vm_stack_context_abort (frame_ctx_p, stack_top_p); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_FINALLY_CONTEXT_STACK_ALLOCATION; + + stack_top_p[-1] = VM_CREATE_CONTEXT ((uint32_t) finally_type, context_end); + if (finally_type == VM_CONTEXT_FINALLY_THROW) + { + stack_top_p[-2] = exception; + } + + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = vm_stack_resume_executable_object_with_context_end; + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_AWAIT; + } + } + + if (!ECMA_IS_VALUE_ERROR (result)) + { + bool is_object = ecma_is_value_object (result); + + ecma_free_value (result); + result = ECMA_VALUE_UNDEFINED; + + if (!is_object) + { + result = ecma_raise_type_error (ECMA_ERR_ITERATOR_RETURN_RESULT_IS_NOT_OBJECT); + } + } + } + } + + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result) || result == ECMA_VALUE_UNDEFINED); + + if (ECMA_IS_VALUE_ERROR (result)) + { + if (finally_type != VM_CONTEXT_FINALLY_THROW) + { + frame_ctx_p->stack_top_p = vm_stack_context_abort (frame_ctx_p, stack_top_p); + return VM_CONTEXT_FOUND_ERROR; + } + + ecma_free_value (jcontext_take_exception ()); + jcontext_raise_exception (exception); + } + else if (finally_type == VM_CONTEXT_FINALLY_THROW) + { + jcontext_raise_exception (exception); + } + } + + stack_top_p = vm_stack_context_abort (frame_ctx_p, stack_top_p); + } + + frame_ctx_p->stack_top_p = stack_top_p; + return VM_CONTEXT_FOUND_EXPECTED; +} /* vm_stack_find_finally */ + +/** + * Get the offsets of ecma values corresponding to the passed context. + * + * @return array of offsets, last item represents the size of the context item + */ +uint32_t +vm_get_context_value_offsets (ecma_value_t *context_item_p) /**< any item of a context */ +{ + switch (VM_GET_CONTEXT_TYPE (context_item_p[-1])) + { + case VM_CONTEXT_FINALLY_THROW: + case VM_CONTEXT_FINALLY_RETURN: + { + return (PARSER_FINALLY_CONTEXT_STACK_ALLOCATION << VM_CONTEXT_OFFSET_SHIFT) | 2; + } + case VM_CONTEXT_FINALLY_JUMP: + { + return PARSER_FINALLY_CONTEXT_STACK_ALLOCATION; + } + case VM_CONTEXT_TRY: + case VM_CONTEXT_CATCH: + case VM_CONTEXT_BLOCK: + case VM_CONTEXT_WITH: + { + return PARSER_WITH_CONTEXT_STACK_ALLOCATION; + } + case VM_CONTEXT_FOR_IN: + { + return (PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION << VM_CONTEXT_OFFSET_SHIFT) | 4; + } + default: + { + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (context_item_p[-1]) == VM_CONTEXT_FOR_OF + || VM_GET_CONTEXT_TYPE (context_item_p[-1]) == VM_CONTEXT_FOR_AWAIT_OF); + + return ((PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION << (VM_CONTEXT_OFFSET_SHIFT * 3)) + | (4 << (VM_CONTEXT_OFFSET_SHIFT * 2)) | (3 << VM_CONTEXT_OFFSET_SHIFT) | 2); + } + } +} /* vm_get_context_value_offsets */ + +/** + * Ref / deref lexical environments in the chain using the current context. + */ +void +vm_ref_lex_env_chain (ecma_object_t *lex_env_p, /**< top of lexical environment */ + uint16_t context_depth, /**< depth of function context */ + ecma_value_t *context_end_p, /**< end of function context */ + bool do_ref) /**< ref or deref lexical environments */ +{ + ecma_value_t *context_top_p = context_end_p + context_depth; + JERRY_ASSERT (context_top_p > context_end_p); + + do + { + if (context_top_p[-1] & VM_CONTEXT_HAS_LEX_ENV) + { + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + ecma_object_t *next_lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + + if (do_ref) + { + ecma_ref_object (lex_env_p); + } + else + { + ecma_deref_object (lex_env_p); + } + + lex_env_p = next_lex_env_p; + } + + if (VM_CONTEXT_IS_VARIABLE_LENGTH (VM_GET_CONTEXT_TYPE (context_top_p[-1]))) + { + ecma_value_t *last_item_p = context_top_p - VM_GET_CONTEXT_END (context_top_p[-1]); + JERRY_ASSERT (last_item_p >= context_end_p); + context_top_p--; + + do + { + if (do_ref) + { + ecma_ref_if_object (*(--context_top_p)); + } + else + { + ecma_deref_if_object (*(--context_top_p)); + } + } while (context_top_p > last_item_p); + + continue; + } + + uint32_t offsets = vm_get_context_value_offsets (context_top_p); + + while (VM_CONTEXT_HAS_NEXT_OFFSET (offsets)) + { + int32_t offset = VM_CONTEXT_GET_NEXT_OFFSET (offsets); + + if (do_ref) + { + ecma_ref_if_object (context_top_p[offset]); + } + else + { + ecma_deref_if_object (context_top_p[offset]); + } + + offsets >>= VM_CONTEXT_OFFSET_SHIFT; + } + + JERRY_ASSERT (context_top_p >= context_end_p + offsets); + context_top_p -= offsets; + } while (context_top_p > context_end_p); +} /* vm_ref_lex_env_chain */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-stack.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-stack.h new file mode 100644 index 0000000..37fd815 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-stack.h @@ -0,0 +1,140 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VM_STACK_H +#define VM_STACK_H + +#include "ecma-globals.h" + +#include "vm-defines.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup stack VM stack + * @{ + */ + +/** + * Create context on the vm stack. + */ +#define VM_CREATE_CONTEXT(type, end_offset) ((ecma_value_t) ((type) | ((end_offset) << 7))) + +/** + * Create context on the vm stack with environment. + */ +#define VM_CREATE_CONTEXT_WITH_ENV(type, end_offset) (VM_CREATE_CONTEXT ((type), (end_offset)) | VM_CONTEXT_HAS_LEX_ENV) + +/** + * Get type of a vm context. + */ +#define VM_GET_CONTEXT_TYPE(value) ((vm_stack_context_type_t) ((value) &0x1f)) + +/** + * Get the end position of a vm context. + */ +#define VM_GET_CONTEXT_END(value) ((value) >> 7) + +/** + * This flag is set if the context has a lexical environment. + */ +#define VM_CONTEXT_HAS_LEX_ENV 0x20 + +/** + * This flag is set if the iterator close operation should be invoked during a for-of context break. + */ +#define VM_CONTEXT_CLOSE_ITERATOR 0x40 + +/** + * Context types for the vm stack. + */ +typedef enum +{ + /* Update VM_CONTEXT_IS_FINALLY macro if the following three values are changed. */ + VM_CONTEXT_FINALLY_JUMP, /**< finally context with a jump */ + VM_CONTEXT_FINALLY_THROW, /**< finally context with a throw */ + VM_CONTEXT_FINALLY_RETURN, /**< finally context with a return */ + VM_CONTEXT_TRY, /**< try context */ + VM_CONTEXT_CATCH, /**< catch context */ + VM_CONTEXT_BLOCK, /**< block context */ + VM_CONTEXT_WITH, /**< with context */ + VM_CONTEXT_FOR_IN, /**< for-in context */ + VM_CONTEXT_FOR_OF, /**< for-of context */ + VM_CONTEXT_FOR_AWAIT_OF, /**< for-await-of context */ + + /* contexts with variable length */ + VM_CONTEXT_ITERATOR, /**< iterator context */ + VM_CONTEXT_OBJ_INIT, /**< object-initializer context */ + VM_CONTEXT_OBJ_INIT_REST, /**< object-initializer-rest context */ +} vm_stack_context_type_t; + +/** + * Return types for vm_stack_find_finally. + */ +typedef enum +{ + VM_CONTEXT_FOUND_FINALLY, /**< found finally */ + VM_CONTEXT_FOUND_ERROR, /**< found an error */ + VM_CONTEXT_FOUND_AWAIT, /**< found an await operation */ + VM_CONTEXT_FOUND_EXPECTED, /**< found the type specified in finally_type */ +} vm_stack_found_type; + +/** + * Checks whether the context has variable context size + * + * Layout: + * - [context descriptor] + * - [JS values belong to the context] + * - [previous JS values stored by the VM stack] + */ +#define VM_CONTEXT_IS_VARIABLE_LENGTH(context_type) ((context_type) >= VM_CONTEXT_ITERATOR) + +/** + * Checks whether the context type is a finally type. + */ +#define VM_CONTEXT_IS_FINALLY(context_type) ((context_type) <= VM_CONTEXT_FINALLY_RETURN) + +/** + * Shift needs to be applied to get the next item of the offset array. + */ +#define VM_CONTEXT_OFFSET_SHIFT 4 + +/** + * Checks whether an offset is available. + */ +#define VM_CONTEXT_HAS_NEXT_OFFSET(offsets) ((offsets) >= (1 << VM_CONTEXT_OFFSET_SHIFT)) + +/** + * Get the next offset from the offset array. + */ +#define VM_CONTEXT_GET_NEXT_OFFSET(offsets) (-((int32_t) ((offsets) & ((1 << VM_CONTEXT_OFFSET_SHIFT) - 1)))) + +ecma_value_t *vm_stack_context_abort_variable_length (vm_frame_ctx_t *frame_ctx_p, + ecma_value_t *vm_stack_top_p, + uint32_t context_stack_allocation); +ecma_value_t *vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, ecma_value_t *vm_stack_top_p); +vm_stack_found_type vm_stack_find_finally (vm_frame_ctx_t *frame_ctx_p, + ecma_value_t *stack_top_p, + vm_stack_context_type_t finally_type, + uint32_t search_limit); +uint32_t vm_get_context_value_offsets (ecma_value_t *context_item_p); +void vm_ref_lex_env_chain (ecma_object_t *lex_env_p, uint16_t context_depth, ecma_value_t *context_end_p, bool do_ref); + +/** + * @} + * @} + */ + +#endif /* !VM_STACK_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-utils.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-utils.cpp new file mode 100644 index 0000000..7f469ef --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm-utils.cpp @@ -0,0 +1,67 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-array-object.h" +#include "ecma-helpers.h" +#include "jcontext.h" +#include "lit-char-helpers.h" +#include "vm.h" + +/** + * Check whether currently executed code is strict mode code + * + * @return true - current code is executed in strict mode, + * false - otherwise + */ +bool +vm_is_strict_mode (void) +{ + JERRY_ASSERT (JERRY_CONTEXT (vm_top_context_p) != NULL); + + return JERRY_CONTEXT (vm_top_context_p)->status_flags & VM_FRAME_CTX_IS_STRICT; +} /* vm_is_strict_mode */ + +/** + * Check whether currently performed call (on top of call-stack) is performed in form, + * meeting conditions of 'Direct Call to Eval' (see also: ECMA-262 v5, 15.1.2.1.1) + * + * Warning: + * the function should only be called from implementation + * of built-in 'eval' routine of Global object + * + * @return true - currently performed call is performed through 'eval' identifier, + * without 'this' argument, + * false - otherwise + */ +bool +vm_is_direct_eval_form_call (void) +{ + return (JERRY_CONTEXT (status_flags) & ECMA_STATUS_DIRECT_EVAL) != 0; +} /* vm_is_direct_eval_form_call */ + +/** + * Get backtrace. The backtrace is an array of strings where + * each string contains the position of the corresponding frame. + * The array length is zero if the backtrace is not available. + * + * @return array ecma value + */ +ecma_value_t +vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimited */ +{ + JERRY_UNUSED (max_depth); + + return ecma_make_object_value (ecma_op_new_array_object (0)); +} /* vm_get_backtrace */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm.cpp b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm.cpp new file mode 100644 index 0000000..7544e81 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm.cpp @@ -0,0 +1,5155 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "vm.h" + +#include "ecma-alloc.h" +#include "ecma-arguments-object.h" +#include "ecma-array-object.h" +#include "ecma-bigint.h" +#include "ecma-builtin-object.h" +#include "ecma-builtins.h" +#include "ecma-comparison.h" +#include "ecma-conversion.h" +#include "ecma-errors.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "ecma-helpers.h" +#include "ecma-iterator-object.h" +#include "ecma-lcache.h" +#include "ecma-lex-env.h" +#include "ecma-objects-general.h" +#include "ecma-objects.h" +#include "ecma-promise-object.h" +#include "ecma-regexp-object.h" + +#include "common.h" +#include "jcontext.h" +#include "opcodes.h" +#include "vm-stack.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_executor Executor + * @{ + */ + +JERRY_STATIC_ASSERT ((sizeof (vm_frame_ctx_t) % sizeof (ecma_value_t)) == 0, + sizeof_vm_frame_ctx_must_be_sizeof_ecma_value_t_aligned); + +/** + * Get the value of object[property]. + * + * @return ecma value + */ +static ecma_value_t +vm_op_get_value (ecma_value_t object, /**< base object */ + ecma_value_t property) /**< property name */ +{ + if (ecma_is_value_object (object)) + { + ecma_object_t *object_p = ecma_get_object_from_value (object); + ecma_string_t *property_name_p = NULL; + + if (ecma_is_value_integer_number (property)) + { + ecma_integer_value_t int_value = ecma_get_integer_from_value (property); + + if (int_value >= 0 && int_value <= ECMA_DIRECT_STRING_MAX_IMM) + { + if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_ARRAY) + { + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + + if (JERRY_LIKELY (ecma_op_array_is_fast_array (ext_object_p) + && (uint32_t) int_value < ext_object_p->u.array.length)) + { + ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp); + + if (JERRY_LIKELY (!ecma_is_value_array_hole (values_p[int_value]))) + { + return ecma_fast_copy_value (values_p[int_value]); + } + } + } + + property_name_p = (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) int_value); + } + } + else if (ecma_is_value_string (property)) + { + property_name_p = ecma_get_string_from_value (property); + } + + if (ecma_is_value_symbol (property)) + { + property_name_p = ecma_get_symbol_from_value (property); + } + + if (property_name_p != NULL) + { +#if JERRY_LCACHE + ecma_property_t *property_p = ecma_lcache_lookup (object_p, property_name_p); + + if (property_p != NULL && (*property_p & ECMA_PROPERTY_FLAG_DATA)) + { + JERRY_ASSERT (!ECMA_PROPERTY_IS_INTERNAL (*property_p)); + return ecma_fast_copy_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value); + } +#endif /* JERRY_LCACHE */ + + /* There is no need to free the name. */ + return ecma_op_object_get (object_p, property_name_p); + } + } + + if (JERRY_UNLIKELY (ecma_is_value_undefined (object) || ecma_is_value_null (object))) + { +#if JERRY_ERROR_MESSAGES + ecma_value_t error_value = + ecma_raise_standard_error_with_format (JERRY_ERROR_TYPE, "Cannot read property '%' of %", property, object); +#else /* !JERRY_ERROR_MESSAGES */ + ecma_value_t error_value = ecma_raise_type_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + return error_value; + } + + ecma_string_t *property_name_p = ecma_op_to_property_key (property); + + if (property_name_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t get_value_result = ecma_op_get_value_object_base (object, property_name_p); + + ecma_deref_ecma_string (property_name_p); + return get_value_result; +} /* vm_op_get_value */ + +/** + * Set the value of object[property]. + * + * Note: + * this function frees its object and property arguments + * + * @return an ecma value which contains an error + * if the property setting is unsuccessful + */ +static ecma_value_t +vm_op_set_value (ecma_value_t base, /**< base object */ + ecma_value_t property, /**< property name */ + ecma_value_t value, /**< ecma value */ + bool is_strict) /**< strict mode */ +{ + ecma_value_t result = ECMA_VALUE_EMPTY; + ecma_object_t *object_p; + ecma_string_t *property_p; + + if (JERRY_UNLIKELY (!ecma_is_value_object (base))) + { + if (JERRY_UNLIKELY (ecma_is_value_null (base) || ecma_is_value_undefined (base))) + { +#if JERRY_ERROR_MESSAGES + result = ecma_raise_standard_error_with_format (JERRY_ERROR_TYPE, "Cannot set property '%' of %", property, base); +#else /* !JERRY_ERROR_MESSAGES */ + result = ecma_raise_type_error (ECMA_ERR_EMPTY); +#endif /* JERRY_ERROR_MESSAGES */ + ecma_free_value (property); + return result; + } + + if (JERRY_UNLIKELY (!ecma_is_value_prop_name (property))) + { + property_p = ecma_op_to_string (property); + ecma_fast_free_value (property); + + if (JERRY_UNLIKELY (property_p == NULL)) + { + ecma_free_value (base); + return ECMA_VALUE_ERROR; + } + } + else + { + property_p = ecma_get_prop_name_from_value (property); + } + + ecma_value_t object = ecma_op_to_object (base); + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (object)); + + object_p = ecma_get_object_from_value (object); + ecma_op_ordinary_object_prevent_extensions (object_p); + + result = ecma_op_object_put_with_receiver (object_p, property_p, value, base, is_strict); + + ecma_free_value (base); + } + else + { + object_p = ecma_get_object_from_value (base); + + if (JERRY_UNLIKELY (!ecma_is_value_prop_name (property))) + { + property_p = ecma_op_to_string (property); + ecma_fast_free_value (property); + + if (JERRY_UNLIKELY (property_p == NULL)) + { + ecma_deref_object (object_p); + return ECMA_VALUE_ERROR; + } + } + else + { + property_p = ecma_get_prop_name_from_value (property); + } + + if (!ecma_is_lexical_environment (object_p)) + { + result = ecma_op_object_put_with_receiver (object_p, property_p, value, base, is_strict); + } + else + { + result = ecma_op_set_mutable_binding (object_p, property_p, value, is_strict); + } + } + + ecma_deref_object (object_p); + ecma_deref_ecma_string (property_p); + return result; +} /* vm_op_set_value */ + +/** Compact bytecode define */ +#define CBC_OPCODE(arg1, arg2, arg3, arg4) arg4, + +/** + * Decode table for both opcodes and extended opcodes. + */ +static const uint16_t vm_decode_table[] JERRY_ATTR_CONST_DATA = { CBC_OPCODE_LIST CBC_EXT_OPCODE_LIST }; + +#undef CBC_OPCODE + +/** + * Run global code + * + * Note: + * returned value must be freed with ecma_free_value, when it is no longer needed. + * + * @return ecma value + */ +ecma_value_t +vm_run_global (const ecma_compiled_code_t *bytecode_p, /**< pointer to bytecode to run */ + ecma_object_t *function_object_p) /**< function object if available */ +{ +#if JERRY_BUILTIN_REALMS + ecma_object_t *global_obj_p = (ecma_object_t *) ecma_op_function_get_realm (bytecode_p); +#else /* !JERRY_BUILTIN_REALMS */ + ecma_object_t *global_obj_p = ecma_builtin_get_global (); +#endif /* JERRY_BUILTIN_REALMS */ + + if (bytecode_p->status_flags & CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED) + { + ecma_create_global_lexical_block (global_obj_p); + } + + ecma_object_t *const global_scope_p = ecma_get_global_scope (global_obj_p); + + vm_frame_ctx_shared_t shared; + shared.bytecode_header_p = bytecode_p; + shared.function_object_p = function_object_p; + shared.status_flags = 0; + +#if JERRY_BUILTIN_REALMS + ecma_value_t this_binding = ((ecma_global_object_t *) global_obj_p)->this_binding; + + ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p); + JERRY_CONTEXT (global_object_p) = (ecma_global_object_t *) global_obj_p; +#else /* !JERRY_BUILTIN_REALMS */ + ecma_value_t this_binding = ecma_make_object_value (global_obj_p); +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_value_t result = vm_run (&shared, this_binding, global_scope_p); + +#if JERRY_BUILTIN_REALMS + JERRY_CONTEXT (global_object_p) = saved_global_object_p; +#endif /* JERRY_BUILTIN_REALMS */ + + return result; +} /* vm_run_global */ + +/** + * Run specified eval-mode bytecode + * + * @return ecma value + */ +ecma_value_t +vm_run_eval (ecma_compiled_code_t *bytecode_data_p, /**< byte-code data */ + uint32_t parse_opts) /**< ecma_parse_opts_t option bits */ +{ + ecma_value_t this_binding; + ecma_object_t *lex_env_p; + + /* ECMA-262 v5, 10.4.2 */ + if (parse_opts & ECMA_PARSE_DIRECT_EVAL) + { + this_binding = ecma_copy_value (JERRY_CONTEXT (vm_top_context_p)->this_binding); + lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p; + } + else + { +#if JERRY_BUILTIN_REALMS + ecma_object_t *global_obj_p = (ecma_object_t *) ecma_op_function_get_realm (bytecode_data_p); + this_binding = ((ecma_global_object_t *) global_obj_p)->this_binding; + ecma_ref_object (ecma_get_object_from_value (this_binding)); +#else /* !JERRY_BUILTIN_REALMS */ + ecma_object_t *global_obj_p = ecma_builtin_get_global (); + ecma_ref_object (global_obj_p); + this_binding = ecma_make_object_value (global_obj_p); +#endif /* JERRY_BUILTIN_REALMS */ + lex_env_p = ecma_get_global_scope (global_obj_p); + } + + ecma_ref_object (lex_env_p); + + if ((bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) != 0) + { + ecma_object_t *strict_lex_env_p = ecma_create_decl_lex_env (lex_env_p); + + ecma_deref_object (lex_env_p); + lex_env_p = strict_lex_env_p; + } + + if ((bytecode_data_p->status_flags & CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED) != 0) + { + ecma_object_t *lex_block_p = ecma_create_decl_lex_env (lex_env_p); + lex_block_p->type_flags_refs |= ECMA_OBJECT_FLAG_BLOCK; + + ecma_deref_object (lex_env_p); + lex_env_p = lex_block_p; + } + + vm_frame_ctx_shared_t shared; + shared.bytecode_header_p = bytecode_data_p; + shared.function_object_p = NULL; + shared.status_flags = (parse_opts & ECMA_PARSE_DIRECT_EVAL) ? VM_FRAME_CTX_SHARED_DIRECT_EVAL : 0; + + ecma_value_t completion_value = vm_run (&shared, this_binding, lex_env_p); + + ecma_deref_object (lex_env_p); + ecma_free_value (this_binding); + +#if JERRY_SNAPSHOT_EXEC + if (!(bytecode_data_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)) + { + ecma_bytecode_deref (bytecode_data_p); + } +#else /* !JERRY_SNAPSHOT_EXEC */ + ecma_bytecode_deref (bytecode_data_p); +#endif /* JERRY_SNAPSHOT_EXEC */ + + return completion_value; +} /* vm_run_eval */ + +#if JERRY_MODULE_SYSTEM + +/** + * Run module code + * + * Note: + * returned value must be freed with ecma_free_value, when it is no longer needed. + * + * @return ecma value + */ +ecma_value_t +vm_run_module (ecma_module_t *module_p) /**< module to be executed */ +{ + const ecma_value_t module_init_result = ecma_module_initialize (module_p); + + if (ECMA_IS_VALUE_ERROR (module_init_result)) + { + return module_init_result; + } + + vm_frame_ctx_shared_t shared; + shared.bytecode_header_p = module_p->u.compiled_code_p; + shared.function_object_p = &module_p->header.object; + shared.status_flags = 0; + + return vm_run (&shared, ECMA_VALUE_UNDEFINED, module_p->scope_p); +} /* vm_run_module */ + +#endif /* JERRY_MODULE_SYSTEM */ + +/** + * Construct object + * + * @return object value + */ +static ecma_value_t +vm_construct_literal_object (vm_frame_ctx_t *frame_ctx_p, /**< frame context */ + ecma_value_t lit_value) /**< literal */ +{ + ecma_compiled_code_t *bytecode_p; + +#if JERRY_SNAPSHOT_EXEC + if (JERRY_LIKELY (!(frame_ctx_p->shared_p->bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))) + { +#endif /* JERRY_SNAPSHOT_EXEC */ + bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, lit_value); +#if JERRY_SNAPSHOT_EXEC + } + else + { + uint8_t *byte_p = ((uint8_t *) frame_ctx_p->shared_p->bytecode_header_p) + lit_value; + bytecode_p = (ecma_compiled_code_t *) byte_p; + } +#endif /* JERRY_SNAPSHOT_EXEC */ + +#if JERRY_BUILTIN_REGEXP + if (JERRY_UNLIKELY (!CBC_IS_FUNCTION (bytecode_p->status_flags))) + { + ecma_object_t *regexp_obj_p = ecma_op_regexp_alloc (NULL); + + if (JERRY_UNLIKELY (regexp_obj_p == NULL)) + { + return ECMA_VALUE_ERROR; + } + + return ecma_op_create_regexp_from_bytecode (regexp_obj_p, (re_compiled_code_t *) bytecode_p); + } +#else /* !JERRY_BUILTIN_REGEXP */ + JERRY_ASSERT (CBC_IS_FUNCTION (bytecode_p->status_flags)); +#endif /* JERRY_BUILTIN_REGEXP */ + + ecma_object_t *func_obj_p; + + if (JERRY_UNLIKELY (CBC_FUNCTION_IS_ARROW (bytecode_p->status_flags))) + { + func_obj_p = ecma_op_create_arrow_function_object (frame_ctx_p->lex_env_p, bytecode_p, frame_ctx_p->this_binding); + } + else + { + func_obj_p = ecma_op_create_any_function_object (frame_ctx_p->lex_env_p, bytecode_p); + } + + return ecma_make_object_value (func_obj_p); +} /* vm_construct_literal_object */ + +/** + * Get implicit this value + * + * @return true - if the implicit 'this' value is updated, + * false - otherwise + */ +static inline bool +vm_get_implicit_this_value (ecma_value_t *this_value_p) /**< [in,out] this value */ +{ + if (ecma_is_value_object (*this_value_p)) + { + ecma_object_t *this_obj_p = ecma_get_object_from_value (*this_value_p); + + if (ecma_is_lexical_environment (this_obj_p)) + { + ecma_value_t completion_value = ecma_op_implicit_this_value (this_obj_p); + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (completion_value)); + + *this_value_p = completion_value; + return true; + } + } + return false; +} /* vm_get_implicit_this_value */ + +/** + * Special bytecode sequence for error handling while the vm_loop + * is preserved for an execute operation + */ +static const uint8_t vm_error_byte_code_p[] = { CBC_EXT_OPCODE, CBC_EXT_ERROR }; + +/** + * Get class function object + * + * @return the pointer to the object + */ +static ecma_object_t * +vm_get_class_function (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + JERRY_ASSERT (frame_ctx_p != NULL); + + if (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_NON_ARROW_FUNC) + { + return frame_ctx_p->shared_p->function_object_p; + } + + ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (frame_ctx_p->lex_env_p); + + JERRY_ASSERT (environment_record_p != NULL); + return ecma_get_object_from_value (environment_record_p->function_object); +} /* vm_get_class_function */ + +/** + * 'super(...)' function call handler. + */ +static void +vm_super_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + JERRY_ASSERT (frame_ctx_p->call_operation == VM_EXEC_SUPER_CALL); + JERRY_ASSERT (frame_ctx_p->byte_code_p[0] == CBC_EXT_OPCODE); + + const uint8_t *byte_code_p = frame_ctx_p->byte_code_p + 3; + uint8_t opcode = byte_code_p[-2]; + uint32_t arguments_list_len; + + bool spread_arguments = opcode >= CBC_EXT_SPREAD_SUPER_CALL; + + ecma_collection_t *collection_p = NULL; + ecma_value_t *arguments_p; + + if (spread_arguments) + { + ecma_value_t collection = *(--frame_ctx_p->stack_top_p); + collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, collection); + arguments_p = collection_p->buffer_p; + arguments_list_len = collection_p->item_count; + } + else + { + arguments_list_len = byte_code_p[-1]; + arguments_p = frame_ctx_p->stack_top_p; + } + + ecma_value_t func_value = *(--frame_ctx_p->stack_top_p); + ecma_value_t completion_value; + + ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (frame_ctx_p->lex_env_p); + JERRY_ASSERT (environment_record_p); + + if (!ecma_is_constructor (func_value)) + { + completion_value = ecma_raise_type_error (ECMA_ERR_VALUE_FOR_CLASS_HERITAGE_IS_NOT_A_CONSTRUCTOR); + } + else + { + ecma_object_t *func_obj_p = ecma_get_object_from_value (func_value); + completion_value = + ecma_op_function_construct (func_obj_p, JERRY_CONTEXT (current_new_target_p), arguments_p, arguments_list_len); + + if (!ECMA_IS_VALUE_ERROR (completion_value) && ecma_op_this_binding_is_initialized (environment_record_p)) + { + ecma_free_value (completion_value); + completion_value = ecma_raise_reference_error (ECMA_ERR_SUPER_CONSTRUCTOR_MAY_ONLY_BE_CALLED_ONCE); + } + } + + /* Free registers. */ + for (uint32_t i = 0; i < arguments_list_len; i++) + { + ecma_fast_free_value (arguments_p[i]); + } + + if (collection_p != NULL) + { + ecma_collection_destroy (collection_p); + } + + if (ecma_is_value_object (completion_value)) + { + ecma_op_bind_this_value (environment_record_p, completion_value); + frame_ctx_p->this_binding = completion_value; + + ecma_value_t fields_value = opfunc_init_class_fields (vm_get_class_function (frame_ctx_p), completion_value); + + if (ECMA_IS_VALUE_ERROR (fields_value)) + { + ecma_free_value (completion_value); + completion_value = ECMA_VALUE_ERROR; + } + } + + ecma_free_value (func_value); + + if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (completion_value))) + { + frame_ctx_p->byte_code_p = (uint8_t *) vm_error_byte_code_p; + } + else + { + frame_ctx_p->byte_code_p = byte_code_p; + uint32_t opcode_data = vm_decode_table[(CBC_END + 1) + opcode]; + + if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))) + { + ecma_fast_free_value (completion_value); + } + else if (opcode_data & VM_OC_PUT_STACK) + { + *frame_ctx_p->stack_top_p++ = completion_value; + } + else + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = completion_value; + } + } +} /* vm_super_call */ + +/** + * Perform one of the following call/construct operation with spread argument list + * - f(...args) + * - o.f(...args) + * - new O(...args) + */ +static void +vm_spread_operation (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + JERRY_ASSERT (frame_ctx_p->byte_code_p[0] == CBC_EXT_OPCODE); + + uint8_t opcode = frame_ctx_p->byte_code_p[1]; + ecma_value_t completion_value; + ecma_value_t collection = *(--frame_ctx_p->stack_top_p); + + ecma_collection_t *collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, collection); + ecma_value_t func_value = *(--frame_ctx_p->stack_top_p); + bool is_call_prop = opcode >= CBC_EXT_SPREAD_CALL_PROP; + + if (frame_ctx_p->byte_code_p[1] == CBC_EXT_SPREAD_NEW) + { + ecma_error_msg_t constructor_message_id = ecma_check_constructor (func_value); + if (constructor_message_id != ECMA_IS_VALID_CONSTRUCTOR) + { + completion_value = ecma_raise_type_error (constructor_message_id); + } + else + { + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (func_value); + + completion_value = ecma_op_function_construct (constructor_obj_p, + constructor_obj_p, + collection_p->buffer_p, + collection_p->item_count); + } + } + else + { + ecma_value_t this_value = is_call_prop ? frame_ctx_p->stack_top_p[-2] : ECMA_VALUE_UNDEFINED; + + if (!ecma_is_value_object (func_value) || !ecma_op_object_is_callable (ecma_get_object_from_value (func_value))) + { + completion_value = ecma_raise_type_error (ECMA_ERR_EXPECTED_A_FUNCTION); + } + else + { + ecma_object_t *func_obj_p = ecma_get_object_from_value (func_value); + + completion_value = + ecma_op_function_call (func_obj_p, this_value, collection_p->buffer_p, collection_p->item_count); + } + + if (is_call_prop) + { + ecma_free_value (*(--frame_ctx_p->stack_top_p)); + ecma_free_value (*(--frame_ctx_p->stack_top_p)); + } + } + + ecma_collection_free (collection_p); + ecma_free_value (func_value); + + if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (completion_value))) + { + frame_ctx_p->byte_code_p = (uint8_t *) vm_error_byte_code_p; + } + else + { + uint32_t opcode_data = vm_decode_table[(CBC_END + 1) + opcode]; + + if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))) + { + ecma_fast_free_value (completion_value); + } + else if (opcode_data & VM_OC_PUT_STACK) + { + *frame_ctx_p->stack_top_p++ = completion_value; + } + else + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = completion_value; + } + + /* EXT_OPCODE, SPREAD_OPCODE, BYTE_ARG */ + frame_ctx_p->byte_code_p += 3; + } +} /* vm_spread_operation */ + +/** + * 'Function call' opcode handler. + * + * See also: ECMA-262 v5, 11.2.3 + */ +static void +opfunc_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + const uint8_t *byte_code_p = frame_ctx_p->byte_code_p + 1; + uint8_t opcode = byte_code_p[-1]; + uint32_t arguments_list_len; + + if (opcode >= CBC_CALL0) + { + arguments_list_len = (unsigned int) ((opcode - CBC_CALL0) / 6); + } + else + { + arguments_list_len = *byte_code_p++; + } + + bool is_call_prop = ((opcode - CBC_CALL) % 6) >= 3; + + ecma_value_t *stack_top_p = frame_ctx_p->stack_top_p - arguments_list_len; + ecma_value_t this_value = is_call_prop ? stack_top_p[-3] : ECMA_VALUE_UNDEFINED; + ecma_value_t func_value = stack_top_p[-1]; + + ecma_value_t completion_value = + ecma_op_function_validated_call (func_value, this_value, stack_top_p, arguments_list_len); + + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_DIRECT_EVAL; + + /* Free registers. */ + for (uint32_t i = 0; i < arguments_list_len; i++) + { + ecma_fast_free_value (stack_top_p[i]); + } + + if (is_call_prop) + { + ecma_free_value (*(--stack_top_p)); + ecma_free_value (*(--stack_top_p)); + } + + if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (completion_value))) + { + frame_ctx_p->byte_code_p = (uint8_t *) vm_error_byte_code_p; + } + else + { + frame_ctx_p->byte_code_p = byte_code_p; + ecma_free_value (*(--stack_top_p)); + uint32_t opcode_data = vm_decode_table[opcode]; + + if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))) + { + ecma_fast_free_value (completion_value); + } + else if (opcode_data & VM_OC_PUT_STACK) + { + *stack_top_p++ = completion_value; + } + else + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = completion_value; + } + } + + frame_ctx_p->stack_top_p = stack_top_p; +} /* opfunc_call */ + +/** + * 'Constructor call' opcode handler. + * + * See also: ECMA-262 v5, 11.2.2 + */ +static void +opfunc_construct (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + const uint8_t *byte_code_p = frame_ctx_p->byte_code_p + 1; + uint8_t opcode = byte_code_p[-1]; + unsigned int arguments_list_len; + + if (opcode >= CBC_NEW0) + { + arguments_list_len = (unsigned int) (opcode - CBC_NEW0); + } + else + { + arguments_list_len = *byte_code_p++; + } + + ecma_value_t *stack_top_p = frame_ctx_p->stack_top_p - arguments_list_len; + ecma_value_t constructor_value = stack_top_p[-1]; + ecma_value_t completion_value; + + ecma_error_msg_t constructor_message_id = ecma_check_constructor (constructor_value); + if (constructor_message_id != ECMA_IS_VALID_CONSTRUCTOR) + { + completion_value = ecma_raise_type_error (constructor_message_id); + } + else + { + ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor_value); + + completion_value = + ecma_op_function_construct (constructor_obj_p, constructor_obj_p, stack_top_p, arguments_list_len); + } + + /* Free registers. */ + for (uint32_t i = 0; i < arguments_list_len; i++) + { + ecma_fast_free_value (stack_top_p[i]); + } + + if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (completion_value))) + { + frame_ctx_p->byte_code_p = (uint8_t *) vm_error_byte_code_p; + } + else + { + ecma_free_value (stack_top_p[-1]); + frame_ctx_p->byte_code_p = byte_code_p; + stack_top_p[-1] = completion_value; + } + + frame_ctx_p->stack_top_p = stack_top_p; +} /* opfunc_construct */ + +/** + * Read literal index from the byte code stream into destination. + * + * @param destination destination + */ +#define READ_LITERAL_INDEX(destination) \ + do \ + { \ + (destination) = *byte_code_p++; \ + if ((destination) >= encoding_limit) \ + { \ + (destination) = (uint16_t) ((((destination) << 8) | *byte_code_p++) - encoding_delta); \ + } \ + } while (0) + +/** + * Get literal value by literal index. + * + * @param literal_index literal index + * @param target_value target value + * + * TODO: For performance reasons, we define this as a macro. + * When we are able to construct a function with similar speed, + * we can remove this macro. + */ +#define READ_LITERAL(literal_index, target_value) \ + do \ + { \ + if ((literal_index) < ident_end) \ + { \ + if ((literal_index) < register_end) \ + { \ + /* Note: There should be no specialization for arguments. */ \ + (target_value) = ecma_fast_copy_value (VM_GET_REGISTER (frame_ctx_p, literal_index)); \ + } \ + else \ + { \ + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); \ + \ + result = ecma_op_resolve_reference_value (frame_ctx_p->lex_env_p, name_p); \ + \ + if (ECMA_IS_VALUE_ERROR (result)) \ + { \ + goto error; \ + } \ + (target_value) = result; \ + } \ + } \ + else if (literal_index < const_literal_end) \ + { \ + (target_value) = ecma_fast_copy_value (literal_start_p[literal_index]); \ + } \ + else \ + { \ + /* Object construction. */ \ + (target_value) = vm_construct_literal_object (frame_ctx_p, literal_start_p[literal_index]); \ + } \ + } while (0) + +/** + * Store the original value for post increase/decrease operators + * + * @param value original value + */ +#define POST_INCREASE_DECREASE_PUT_RESULT(value) \ + if (opcode_data & VM_OC_PUT_STACK) \ + { \ + if (opcode_flags & VM_OC_IDENT_INCR_DECR_OPERATOR_FLAG) \ + { \ + JERRY_ASSERT (opcode == CBC_POST_INCR_IDENT_PUSH_RESULT || opcode == CBC_POST_DECR_IDENT_PUSH_RESULT); \ + *stack_top_p++ = (value); \ + } \ + else \ + { \ + /* The parser ensures there is enough space for the \ + * extra value on the stack. See js-parser-expr.c. */ \ + JERRY_ASSERT (opcode == CBC_POST_INCR_PUSH_RESULT || opcode == CBC_POST_DECR_PUSH_RESULT); \ + stack_top_p++; \ + stack_top_p[-1] = stack_top_p[-2]; \ + stack_top_p[-2] = stack_top_p[-3]; \ + stack_top_p[-3] = (value); \ + } \ + opcode_data &= (uint32_t) ~VM_OC_PUT_STACK; \ + } \ + else \ + { \ + JERRY_ASSERT (opcode_data &VM_OC_PUT_BLOCK); \ + ecma_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); \ + VM_GET_REGISTERS (frame_ctx_p)[0] = (value); \ + opcode_data &= (uint32_t) ~VM_OC_PUT_BLOCK; \ + } + +/** + * Get the end of the existing topmost context + */ +#define VM_LAST_CONTEXT_END() (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth) + +/** + * Run generic byte code. + * + * @return ecma value + */ +static ecma_value_t JERRY_ATTR_NOINLINE +vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + const ecma_compiled_code_t *bytecode_header_p = frame_ctx_p->shared_p->bytecode_header_p; + const uint8_t *byte_code_p = frame_ctx_p->byte_code_p; + ecma_value_t *literal_start_p = frame_ctx_p->literal_start_p; + + ecma_value_t *stack_top_p; + uint16_t encoding_limit; + uint16_t encoding_delta; + uint16_t register_end; + uint16_t ident_end; + uint16_t const_literal_end; + int32_t branch_offset = 0; + uint8_t branch_offset_length = 0; + ecma_value_t left_value; + ecma_value_t right_value; + ecma_value_t result = ECMA_VALUE_EMPTY; + bool is_strict = ((bytecode_header_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) != 0); + + /* Prepare for byte code execution. */ + if (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING)) + { + encoding_limit = CBC_SMALL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_SMALL_LITERAL_ENCODING_DELTA; + } + else + { + encoding_limit = CBC_FULL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_FULL_LITERAL_ENCODING_DELTA; + } + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) (bytecode_header_p); + register_end = args_p->register_end; + ident_end = args_p->ident_end; + const_literal_end = args_p->const_literal_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) (bytecode_header_p); + register_end = args_p->register_end; + ident_end = args_p->ident_end; + const_literal_end = args_p->const_literal_end; + } + + stack_top_p = frame_ctx_p->stack_top_p; + + /* Outer loop for exception handling. */ + while (true) + { + /* Internal loop for byte code execution. */ + while (true) + { + const uint8_t *byte_code_start_p = byte_code_p; + uint8_t opcode = *byte_code_p++; + uint32_t opcode_data = opcode; + + if (opcode == CBC_EXT_OPCODE) + { + opcode = *byte_code_p++; + opcode_data = (uint32_t) ((CBC_END + 1) + opcode); + } + + opcode_data = vm_decode_table[opcode_data]; + + left_value = ECMA_VALUE_UNDEFINED; + right_value = ECMA_VALUE_UNDEFINED; + + uint32_t operands = VM_OC_GET_ARGS_INDEX (opcode_data); + + if (operands >= VM_OC_GET_LITERAL) + { + uint16_t literal_index; + READ_LITERAL_INDEX (literal_index); + READ_LITERAL (literal_index, left_value); + + if (operands != VM_OC_GET_LITERAL) + { + switch (operands) + { + case VM_OC_GET_LITERAL_LITERAL: + { + uint16_t second_literal_index; + READ_LITERAL_INDEX (second_literal_index); + READ_LITERAL (second_literal_index, right_value); + break; + } + case VM_OC_GET_STACK_LITERAL: + { + JERRY_ASSERT (stack_top_p > VM_GET_REGISTERS (frame_ctx_p) + register_end); + right_value = left_value; + left_value = *(--stack_top_p); + break; + } + default: + { + JERRY_ASSERT (operands == VM_OC_GET_THIS_LITERAL); + + right_value = left_value; + left_value = ecma_copy_value (frame_ctx_p->this_binding); + break; + } + } + } + } + else if (operands >= VM_OC_GET_STACK) + { + JERRY_ASSERT (operands == VM_OC_GET_STACK || operands == VM_OC_GET_STACK_STACK); + + JERRY_ASSERT (stack_top_p > VM_GET_REGISTERS (frame_ctx_p) + register_end); + left_value = *(--stack_top_p); + + if (operands == VM_OC_GET_STACK_STACK) + { + JERRY_ASSERT (stack_top_p > VM_GET_REGISTERS (frame_ctx_p) + register_end); + right_value = left_value; + left_value = *(--stack_top_p); + } + } + else if (operands == VM_OC_GET_BRANCH) + { + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (opcode); + JERRY_ASSERT (branch_offset_length >= 1 && branch_offset_length <= 3); + + branch_offset = *(byte_code_p++); + + if (JERRY_UNLIKELY (branch_offset_length != 1)) + { + branch_offset <<= 8; + branch_offset |= *(byte_code_p++); + + if (JERRY_UNLIKELY (branch_offset_length == 3)) + { + branch_offset <<= 8; + branch_offset |= *(byte_code_p++); + } + } + + if (opcode_data & VM_OC_BACKWARD_BRANCH) + { +#if JERRY_VM_HALT + if (JERRY_CONTEXT (vm_exec_stop_cb) != NULL && --JERRY_CONTEXT (vm_exec_stop_counter) == 0) + { + result = JERRY_CONTEXT (vm_exec_stop_cb) (JERRY_CONTEXT (vm_exec_stop_user_p)); + + if (ecma_is_value_undefined (result)) + { + JERRY_CONTEXT (vm_exec_stop_counter) = JERRY_CONTEXT (vm_exec_stop_frequency); + } + else + { + JERRY_CONTEXT (vm_exec_stop_counter) = 1; + + if (ecma_is_value_exception (result)) + { + ecma_throw_exception (result); + } + else + { + jcontext_raise_exception (result); + } + + JERRY_ASSERT (jcontext_has_pending_exception ()); + jcontext_set_abort_flag (true); + result = ECMA_VALUE_ERROR; + goto error; + } + } +#endif /* JERRY_VM_HALT */ + + branch_offset = -branch_offset; + } + } + + switch (VM_OC_GROUP_GET_INDEX (opcode_data)) + { + case VM_OC_POP: + { + JERRY_ASSERT (stack_top_p > VM_GET_REGISTERS (frame_ctx_p) + register_end); + ecma_free_value (*(--stack_top_p)); + continue; + } + case VM_OC_POP_BLOCK: + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = *(--stack_top_p); + continue; + } + case VM_OC_PUSH: + { + *stack_top_p++ = left_value; + continue; + } + case VM_OC_PUSH_TWO: + { + *stack_top_p++ = left_value; + *stack_top_p++ = right_value; + continue; + } + case VM_OC_PUSH_THREE: + { + uint16_t literal_index; + + *stack_top_p++ = left_value; + left_value = ECMA_VALUE_UNDEFINED; + + READ_LITERAL_INDEX (literal_index); + READ_LITERAL (literal_index, left_value); + + *stack_top_p++ = right_value; + *stack_top_p++ = left_value; + continue; + } + case VM_OC_PUSH_UNDEFINED: + { + *stack_top_p++ = ECMA_VALUE_UNDEFINED; + continue; + } + case VM_OC_PUSH_TRUE: + { + *stack_top_p++ = ECMA_VALUE_TRUE; + continue; + } + case VM_OC_PUSH_FALSE: + { + *stack_top_p++ = ECMA_VALUE_FALSE; + continue; + } + case VM_OC_PUSH_NULL: + { + *stack_top_p++ = ECMA_VALUE_NULL; + continue; + } + case VM_OC_PUSH_THIS: + { + *stack_top_p++ = ecma_copy_value (frame_ctx_p->this_binding); + continue; + } + case VM_OC_PUSH_0: + { + *stack_top_p++ = ecma_make_integer_value (0); + continue; + } + case VM_OC_PUSH_POS_BYTE: + { + ecma_integer_value_t number = *byte_code_p++; + *stack_top_p++ = ecma_make_integer_value (number + 1); + continue; + } + case VM_OC_PUSH_NEG_BYTE: + { + ecma_integer_value_t number = *byte_code_p++; + *stack_top_p++ = ecma_make_integer_value (-(number + 1)); + continue; + } + case VM_OC_PUSH_LIT_0: + { + stack_top_p[0] = left_value; + stack_top_p[1] = ecma_make_integer_value (0); + stack_top_p += 2; + continue; + } + case VM_OC_PUSH_LIT_POS_BYTE: + { + ecma_integer_value_t number = *byte_code_p++; + stack_top_p[0] = left_value; + stack_top_p[1] = ecma_make_integer_value (number + 1); + stack_top_p += 2; + continue; + } + case VM_OC_PUSH_LIT_NEG_BYTE: + { + ecma_integer_value_t number = *byte_code_p++; + stack_top_p[0] = left_value; + stack_top_p[1] = ecma_make_integer_value (-(number + 1)); + stack_top_p += 2; + continue; + } + case VM_OC_PUSH_OBJECT: + { + ecma_object_t *obj_p = + ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), 0, ECMA_OBJECT_TYPE_GENERAL); + + *stack_top_p++ = ecma_make_object_value (obj_p); + continue; + } + case VM_OC_PUSH_NAMED_FUNC_EXPR: + { + ecma_object_t *func_p = ecma_get_object_from_value (left_value); + + JERRY_ASSERT (ecma_get_object_type (func_p) == ECMA_OBJECT_TYPE_FUNCTION); + + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_p; + + JERRY_ASSERT (frame_ctx_p->lex_env_p + == ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, ext_func_p->u.function.scope_cp)); + + ecma_object_t *name_lex_env = ecma_create_decl_lex_env (frame_ctx_p->lex_env_p); + + ecma_op_create_immutable_binding (name_lex_env, ecma_get_string_from_value (right_value), left_value); + + ECMA_SET_NON_NULL_POINTER_TAG (ext_func_p->u.function.scope_cp, name_lex_env, 0); + + ecma_free_value (right_value); + ecma_deref_object (name_lex_env); + *stack_top_p++ = left_value; + continue; + } + case VM_OC_CREATE_BINDING: + { + uint32_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + JERRY_ASSERT (ecma_find_named_property (frame_ctx_p->lex_env_p, name_p) == NULL); + + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_WRITABLE; + + if (opcode == CBC_CREATE_LET) + { + prop_attributes = ECMA_PROPERTY_ENUMERABLE_WRITABLE; + } + else if (opcode == CBC_CREATE_CONST) + { + prop_attributes = ECMA_PROPERTY_FLAG_ENUMERABLE; + } + + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (frame_ctx_p->lex_env_p, name_p, prop_attributes, NULL); + + if (opcode != CBC_CREATE_VAR) + { + property_value_p->value = ECMA_VALUE_UNINITIALIZED; + } + + continue; + } + case VM_OC_VAR_EVAL: + { + uint32_t literal_index; + ecma_value_t lit_value = ECMA_VALUE_UNDEFINED; + + if (opcode == CBC_CREATE_VAR_FUNC_EVAL) + { + uint32_t value_index; + READ_LITERAL_INDEX (value_index); + JERRY_ASSERT (value_index >= const_literal_end); + + lit_value = vm_construct_literal_object (frame_ctx_p, literal_start_p[value_index]); + } + + READ_LITERAL_INDEX (literal_index); + JERRY_ASSERT (literal_index >= register_end); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + + while (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + { +#if !(defined JERRY_NDEBUG) + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + JERRY_ASSERT (property_p == NULL || !(*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE)); + } +#endif /* !JERRY_NDEBUG */ + + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + +#if !(defined JERRY_NDEBUG) + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + JERRY_ASSERT (property_p == NULL || !(*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE)); + } +#endif /* !JERRY_NDEBUG */ + + /* 'Variable declaration' */ + result = ecma_op_has_binding (lex_env_p, name_p); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } +#endif /* JERRY_BUILTIN_PROXY */ + + ecma_property_t *prop_p = NULL; + + if (ecma_is_value_false (result)) + { + bool is_configurable = (frame_ctx_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL) != 0; + prop_p = ecma_op_create_mutable_binding (lex_env_p, name_p, is_configurable); + + if (JERRY_UNLIKELY (prop_p == ECMA_PROPERTY_POINTER_ERROR)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + } + + if (lit_value != ECMA_VALUE_UNDEFINED) + { + JERRY_ASSERT (ecma_is_value_object (lit_value)); + + if (prop_p != NULL) + { + JERRY_ASSERT (ecma_is_value_undefined (ECMA_PROPERTY_VALUE_PTR (prop_p)->value)); + JERRY_ASSERT (ecma_is_property_writable (*prop_p)); + ECMA_PROPERTY_VALUE_PTR (prop_p)->value = lit_value; + ecma_free_object (lit_value); + } + else + { + result = ecma_op_put_value_lex_env_base (lex_env_p, name_p, is_strict, lit_value); + ecma_free_object (lit_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + } + } + continue; + } + case VM_OC_EXT_VAR_EVAL: + { + uint32_t literal_index; + ecma_value_t lit_value = ECMA_VALUE_UNDEFINED; + + JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE); + + if (opcode == CBC_EXT_CREATE_VAR_FUNC_EVAL) + { + uint32_t value_index; + READ_LITERAL_INDEX (value_index); + JERRY_ASSERT (value_index >= const_literal_end); + + lit_value = vm_construct_literal_object (frame_ctx_p, literal_start_p[value_index]); + } + + READ_LITERAL_INDEX (literal_index); + JERRY_ASSERT (literal_index >= register_end); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + ecma_object_t *prev_lex_env_p = NULL; + + while (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + { +#if !(defined JERRY_NDEBUG) + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + JERRY_ASSERT (property_p == NULL || !(*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE)); + } +#endif /* !JERRY_NDEBUG */ + + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + prev_lex_env_p = lex_env_p; + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + JERRY_ASSERT (prev_lex_env_p != NULL + && ecma_get_lex_env_type (prev_lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + + ecma_property_t *property_p = ecma_find_named_property (prev_lex_env_p, name_p); + ecma_property_value_t *property_value_p; + + if (property_p == NULL) + { + property_value_p = + ecma_create_named_data_property (prev_lex_env_p, name_p, ECMA_PROPERTY_CONFIGURABLE_WRITABLE, NULL); + + if (lit_value == ECMA_VALUE_UNDEFINED) + { + continue; + } + } + else + { + if (lit_value == ECMA_VALUE_UNDEFINED) + { + continue; + } + + property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + ecma_free_value_if_not_object (property_value_p->value); + } + + property_value_p->value = lit_value; + ecma_deref_object (ecma_get_object_from_value (lit_value)); + continue; + } + case VM_OC_CREATE_ARGUMENTS: + { + uint32_t literal_index; + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_HAS_ARG_LIST); + + result = ecma_op_create_arguments_object ((vm_frame_ctx_shared_args_t *) (frame_ctx_p->shared_p), + frame_ctx_p->lex_env_p); + + if (literal_index < register_end) + { + JERRY_ASSERT (VM_GET_REGISTER (frame_ctx_p, literal_index) == ECMA_VALUE_UNDEFINED); + VM_GET_REGISTER (frame_ctx_p, literal_index) = result; + continue; + } + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + JERRY_ASSERT (ecma_find_named_property (frame_ctx_p->lex_env_p, name_p) == NULL); + + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_WRITABLE; + ecma_property_value_t *property_value_p; + + property_value_p = ecma_create_named_data_property (frame_ctx_p->lex_env_p, name_p, prop_attributes, NULL); + property_value_p->value = result; + + ecma_deref_object (ecma_get_object_from_value (result)); + continue; + } +#if JERRY_SNAPSHOT_EXEC + case VM_OC_SET_BYTECODE_PTR: + { + memcpy (&byte_code_p, byte_code_p++, sizeof (uintptr_t)); + frame_ctx_p->byte_code_start_p = byte_code_p; + continue; + } +#endif /* JERRY_SNAPSHOT_EXEC */ + case VM_OC_INIT_ARG_OR_FUNC: + { + uint32_t literal_index, value_index; + ecma_value_t lit_value; + bool release = false; + + READ_LITERAL_INDEX (value_index); + + if (value_index < register_end) + { + /* Take (not copy) the reference. */ + lit_value = ecma_copy_value_if_not_object (VM_GET_REGISTER (frame_ctx_p, value_index)); + } + else + { + lit_value = vm_construct_literal_object (frame_ctx_p, literal_start_p[value_index]); + release = true; + } + + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (value_index != literal_index); + JERRY_ASSERT (value_index >= register_end || literal_index >= register_end); + + if (literal_index < register_end) + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, literal_index)); + JERRY_ASSERT (release); + VM_GET_REGISTER (frame_ctx_p, literal_index) = lit_value; + continue; + } + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + JERRY_ASSERT (ecma_find_named_property (frame_ctx_p->lex_env_p, name_p) == NULL); + + ecma_property_value_t *property_value_p; + property_value_p = + ecma_create_named_data_property (frame_ctx_p->lex_env_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL); + + JERRY_ASSERT (property_value_p->value == ECMA_VALUE_UNDEFINED); + property_value_p->value = lit_value; + + if (release) + { + ecma_deref_object (ecma_get_object_from_value (lit_value)); + } + continue; + } + case VM_OC_CHECK_VAR: + { + JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags) + == CBC_FUNCTION_SCRIPT); + + uint32_t literal_index; + READ_LITERAL_INDEX (literal_index); + + if ((frame_ctx_p->lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) == 0) + { + continue; + } + + ecma_string_t *const literal_name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_property_t *const binding_p = ecma_find_named_property (frame_ctx_p->lex_env_p, literal_name_p); + + if (binding_p != NULL) + { + result = ecma_raise_syntax_error (ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED); + goto error; + } + + continue; + } + case VM_OC_CHECK_LET: + { + JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags) + == CBC_FUNCTION_SCRIPT); + + uint32_t literal_index; + READ_LITERAL_INDEX (literal_index); + + ecma_string_t *literal_name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + + if (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + { + result = opfunc_lexical_scope_has_restricted_binding (frame_ctx_p, literal_name_p); + + if (!ecma_is_value_false (result)) + { + if (ecma_is_value_true (result)) + { + result = ecma_raise_syntax_error (ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED); + } + + JERRY_ASSERT (ECMA_IS_VALUE_ERROR (result)); + goto error; + } + + continue; + } + + result = ecma_op_has_binding (lex_env_p, literal_name_p); + +#if JERRY_BUILTIN_PROXY + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } +#endif /* JERRY_BUILTIN_PROXY */ + + if (ecma_is_value_true (result)) + { + result = ecma_raise_syntax_error (ECMA_ERR_LOCAL_VARIABLE_IS_REDECLARED); + goto error; + } + + continue; + } + case VM_OC_ASSIGN_LET_CONST: + { + uint32_t literal_index; + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (literal_index >= register_end); + JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE + || (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_CLASS + && ECMA_LEX_ENV_CLASS_IS_MODULE (frame_ctx_p->lex_env_p))); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_property_t *property_p = ecma_find_named_property (frame_ctx_p->lex_env_p, name_p); + + JERRY_ASSERT (property_p != NULL && ECMA_PROPERTY_IS_RAW_DATA (*property_p) + && (*property_p & ECMA_PROPERTY_FLAG_DATA)); + JERRY_ASSERT (ECMA_PROPERTY_VALUE_PTR (property_p)->value == ECMA_VALUE_UNINITIALIZED); + + ECMA_PROPERTY_VALUE_PTR (property_p)->value = left_value; + + if (ecma_is_value_object (left_value)) + { + ecma_deref_object (ecma_get_object_from_value (left_value)); + } + continue; + } + case VM_OC_INIT_BINDING: + { + uint32_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (literal_index >= register_end); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + JERRY_ASSERT (ecma_find_named_property (frame_ctx_p->lex_env_p, name_p) == NULL); + + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_WRITABLE; + + if (opcode == CBC_INIT_LET) + { + prop_attributes = ECMA_PROPERTY_ENUMERABLE_WRITABLE; + } + else if (opcode == CBC_INIT_CONST) + { + prop_attributes = ECMA_PROPERTY_FLAG_ENUMERABLE; + } + + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (frame_ctx_p->lex_env_p, name_p, prop_attributes, NULL); + + JERRY_ASSERT (property_value_p->value == ECMA_VALUE_UNDEFINED); + + ecma_value_t value = *(--stack_top_p); + + property_value_p->value = value; + ecma_deref_if_object (value); + continue; + } + case VM_OC_THROW_CONST_ERROR: + { + result = ecma_raise_type_error (ECMA_ERR_CONSTANT_BINDINGS_CANNOT_BE_REASSIGNED); + goto error; + } + case VM_OC_COPY_TO_GLOBAL: + { + uint32_t literal_index; + READ_LITERAL_INDEX (literal_index); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + + while (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + { +#ifndef JERRY_NDEBUG + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + + JERRY_ASSERT (property_p == NULL || !(*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE)); + } +#endif /* !JERRY_NDEBUG */ + + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + } + + if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE) + { + ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p); + ecma_property_value_t *prop_value_p; + + if (property_p == NULL) + { + prop_value_p = ecma_create_named_data_property (lex_env_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL); + } + else + { +#ifndef JERRY_NDEBUG + JERRY_ASSERT (!(*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE)); +#endif /* !JERRY_NDEBUG */ + prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + } + + ecma_named_data_property_assign_value (lex_env_p, prop_value_p, left_value); + } + else + { + result = ecma_op_set_mutable_binding (lex_env_p, name_p, left_value, is_strict); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + } + + goto free_left_value; + } + case VM_OC_COPY_FROM_ARG: + { + uint32_t literal_index; + READ_LITERAL_INDEX (literal_index); + JERRY_ASSERT (literal_index >= register_end); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + ecma_object_t *arg_lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + + JERRY_ASSERT ((lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + && ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + JERRY_ASSERT (arg_lex_env_p != NULL && !(arg_lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK) + && ecma_get_lex_env_type (arg_lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); + + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (lex_env_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL); + + ecma_property_t *property_p = ecma_find_named_property (arg_lex_env_p, name_p); + JERRY_ASSERT (property_p != NULL); + + ecma_property_value_t *arg_prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + property_value_p->value = ecma_copy_value_if_not_object (arg_prop_value_p->value); + continue; + } + case VM_OC_CLONE_CONTEXT: + { + JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE); + + bool copy_values = (byte_code_start_p[1] == CBC_EXT_CLONE_FULL_CONTEXT); + frame_ctx_p->lex_env_p = ecma_clone_decl_lexical_environment (frame_ctx_p->lex_env_p, copy_values); + continue; + } + case VM_OC_SET__PROTO__: + { + result = ecma_builtin_object_object_set_proto (stack_top_p[-1], left_value); + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + goto free_left_value; + } + case VM_OC_CLASS_CALL_STATIC_BLOCK: + { + result = ecma_op_function_call (ecma_get_object_from_value (left_value), frame_ctx_p->this_binding, NULL, 0); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + goto free_left_value; + } + case VM_OC_PUSH_STATIC_FIELD_FUNC: + { + JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE + && (byte_code_start_p[1] == CBC_EXT_PUSH_STATIC_FIELD_FUNC + || byte_code_start_p[1] == CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC)); + + bool push_computed = (byte_code_start_p[1] == CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC); + ecma_value_t value = stack_top_p[-1]; + + if (!push_computed) + { + stack_top_p++; + } + + memmove (stack_top_p - 3, stack_top_p - 4, 3 * sizeof (ecma_value_t)); + stack_top_p[-4] = left_value; + + ecma_object_t *class_object_p = ecma_get_object_from_value (stack_top_p[-2]); + ecma_object_t *initializer_func_p = ecma_get_object_from_value (left_value); + opfunc_bind_class_environment (frame_ctx_p->lex_env_p, class_object_p, class_object_p, initializer_func_p); + + if (!push_computed) + { + continue; + } + + left_value = value; + /* FALLTHRU */ + } + case VM_OC_ADD_COMPUTED_FIELD: + { + JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE + && (byte_code_start_p[1] == CBC_EXT_PUSH_STATIC_COMPUTED_FIELD_FUNC + || byte_code_start_p[1] == CBC_EXT_ADD_COMPUTED_FIELD + || byte_code_start_p[1] == CBC_EXT_ADD_STATIC_COMPUTED_FIELD)); + + int index = (byte_code_start_p[1] == CBC_EXT_ADD_COMPUTED_FIELD) ? -2 : -4; + result = opfunc_add_computed_field (stack_top_p[index], left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + goto free_left_value; + } + case VM_OC_COPY_DATA_PROPERTIES: + { + left_value = *(--stack_top_p); + + if (ecma_is_value_undefined (left_value) || ecma_is_value_null (left_value)) + { + continue; + } + + result = opfunc_copy_data_properties (stack_top_p[-1], left_value, ECMA_VALUE_UNDEFINED); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + goto free_left_value; + } + case VM_OC_SET_COMPUTED_PROPERTY: + { + /* Swap values. */ + left_value ^= right_value; + right_value ^= left_value; + left_value ^= right_value; + /* FALLTHRU */ + } + case VM_OC_SET_PROPERTY: + { + JERRY_STATIC_ASSERT ((VM_OC_NON_STATIC_FLAG == VM_OC_BACKWARD_BRANCH), + vm_oc_non_static_flag_must_be_equal_to_vm_oc_backward_branch); + + JERRY_ASSERT ((opcode_data >> VM_OC_NON_STATIC_SHIFT) <= 0x1); + + ecma_string_t *prop_name_p = ecma_op_to_property_key (right_value); + + if (JERRY_UNLIKELY (prop_name_p == NULL)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + if (JERRY_UNLIKELY (ecma_compare_ecma_string_to_magic_id (prop_name_p, LIT_MAGIC_STRING_PROTOTYPE)) + && !(opcode_data & VM_OC_NON_STATIC_FLAG)) + { + result = ecma_raise_type_error (ECMA_ERR_CLASS_IS_NON_CONFIGURABLE); + goto error; + } + + const int index = (int) (opcode_data >> VM_OC_NON_STATIC_SHIFT) - 2; + + ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[index]); + + opfunc_set_data_property (object_p, prop_name_p, left_value); + ecma_deref_ecma_string (prop_name_p); + + goto free_both_values; + } + case VM_OC_SET_GETTER: + case VM_OC_SET_SETTER: + { + JERRY_ASSERT ((opcode_data >> VM_OC_NON_STATIC_SHIFT) <= 0x1); + + ecma_string_t *prop_name_p = ecma_op_to_property_key (left_value); + + if (JERRY_UNLIKELY (prop_name_p == NULL)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + if (JERRY_UNLIKELY (ecma_compare_ecma_string_to_magic_id (prop_name_p, LIT_MAGIC_STRING_PROTOTYPE)) + && !(opcode_data & VM_OC_NON_STATIC_FLAG)) + { + result = ecma_raise_type_error (ECMA_ERR_CLASS_IS_NON_CONFIGURABLE); + goto error; + } + + const int index = (int) (opcode_data >> VM_OC_NON_STATIC_SHIFT) - 2; + opfunc_set_accessor (VM_OC_GROUP_GET_INDEX (opcode_data) == VM_OC_SET_GETTER, + stack_top_p[index], + prop_name_p, + right_value); + + ecma_deref_ecma_string (prop_name_p); + + goto free_both_values; + } + case VM_OC_PUSH_ARRAY: + { + /* Note: this operation cannot throw an exception */ + *stack_top_p++ = ecma_make_object_value (ecma_op_new_array_object (0)); + continue; + } + case VM_OC_LOCAL_EVAL: + { + ECMA_CLEAR_LOCAL_PARSE_OPTS (); + uint8_t parse_opts = *byte_code_p++; + ECMA_SET_LOCAL_PARSE_OPTS (parse_opts); + continue; + } + case VM_OC_SUPER_CALL: + { + uint8_t arguments_list_len = *byte_code_p++; + + if (opcode >= CBC_EXT_SPREAD_SUPER_CALL) + { + stack_top_p -= arguments_list_len; + ecma_collection_t *arguments_p = opfunc_spread_arguments (stack_top_p, arguments_list_len); + + if (JERRY_UNLIKELY (arguments_p == NULL)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + stack_top_p++; + ECMA_SET_INTERNAL_VALUE_POINTER (stack_top_p[-1], arguments_p); + } + else + { + stack_top_p -= arguments_list_len; + } + + frame_ctx_p->call_operation = VM_EXEC_SUPER_CALL; + frame_ctx_p->byte_code_p = byte_code_start_p; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_PUSH_CLASS_ENVIRONMENT: + { + uint16_t literal_index; + + READ_LITERAL_INDEX (literal_index); + opfunc_push_class_environment (frame_ctx_p, &stack_top_p, literal_start_p[literal_index]); + continue; + } + case VM_OC_PUSH_IMPLICIT_CTOR: + { + *stack_top_p++ = opfunc_create_implicit_class_constructor (opcode, frame_ctx_p->shared_p->bytecode_header_p); + continue; + } + case VM_OC_DEFINE_FIELD: + { + result = opfunc_define_field (frame_ctx_p->this_binding, right_value, left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + goto free_both_values; + } + case VM_OC_ASSIGN_PRIVATE: + { + result = opfunc_private_set (stack_top_p[-3], stack_top_p[-2], stack_top_p[-1]); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_free_value (stack_top_p[-3]); + ecma_free_value (stack_top_p[-2]); + ecma_free_value (stack_top_p[-1]); + stack_top_p -= 3; + + if (opcode_data & VM_OC_PUT_STACK) + { + *stack_top_p++ = result; + } + else if (opcode_data & VM_OC_PUT_BLOCK) + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = result; + } + else + { + ecma_free_value (result); + } + + goto free_both_values; + } + case VM_OC_PRIVATE_FIELD_ADD: + { + result = opfunc_private_field_add (frame_ctx_p->this_binding, right_value, left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + goto free_both_values; + } + case VM_OC_PRIVATE_PROP_GET: + { + result = opfunc_private_get (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_PRIVATE_PROP_REFERENCE: + { + result = opfunc_private_get (stack_top_p[-1], left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = left_value; + *stack_top_p++ = result; + continue; + } + case VM_OC_PRIVATE_IN: + { + result = opfunc_private_in (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_COLLECT_PRIVATE_PROPERTY: + { + opfunc_collect_private_properties (stack_top_p[-2], left_value, right_value, opcode); + continue; + } + case VM_OC_INIT_CLASS: + { + result = opfunc_init_class (frame_ctx_p, stack_top_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + continue; + } + case VM_OC_FINALIZE_CLASS: + { + JERRY_ASSERT (opcode == CBC_EXT_FINALIZE_NAMED_CLASS || opcode == CBC_EXT_FINALIZE_ANONYMOUS_CLASS); + + if (opcode == CBC_EXT_FINALIZE_NAMED_CLASS) + { + uint16_t literal_index; + READ_LITERAL_INDEX (literal_index); + left_value = literal_start_p[literal_index]; + } + + opfunc_finalize_class (frame_ctx_p, &stack_top_p, left_value); + continue; + } + case VM_OC_SET_FIELD_INIT: + { + ecma_string_t *property_name_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_INIT); + ecma_object_t *proto_object_p = ecma_get_object_from_value (stack_top_p[-1]); + ecma_object_t *class_object_p = ecma_get_object_from_value (stack_top_p[-2]); + ecma_object_t *initializer_func_p = ecma_get_object_from_value (left_value); + + opfunc_bind_class_environment (frame_ctx_p->lex_env_p, proto_object_p, class_object_p, initializer_func_p); + + ecma_property_value_t *property_value_p = + ecma_create_named_data_property (class_object_p, property_name_p, ECMA_PROPERTY_FIXED, NULL); + property_value_p->value = left_value; + + property_name_p = ecma_get_internal_string (LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED); + ecma_property_t *property_p = ecma_find_named_property (class_object_p, property_name_p); + + if (property_p != NULL) + { + property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); + ecma_value_t *compact_collection_p = + ECMA_GET_INTERNAL_VALUE_POINTER (ecma_value_t, property_value_p->value); + compact_collection_p = ecma_compact_collection_shrink (compact_collection_p); + ECMA_SET_INTERNAL_VALUE_POINTER (property_value_p->value, compact_collection_p); + } + + goto free_left_value; + } + case VM_OC_RUN_FIELD_INIT: + { + JERRY_ASSERT (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_NON_ARROW_FUNC); + result = opfunc_init_class_fields (frame_ctx_p->shared_p->function_object_p, frame_ctx_p->this_binding); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + continue; + } + case VM_OC_RUN_STATIC_FIELD_INIT: + { + left_value = stack_top_p[-2]; + stack_top_p[-2] = stack_top_p[-1]; + stack_top_p--; + + result = opfunc_init_static_class_fields (left_value, stack_top_p[-1]); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + goto free_left_value; + } + case VM_OC_SET_NEXT_COMPUTED_FIELD: + { + ecma_integer_value_t next_index = ecma_get_integer_from_value (stack_top_p[-2]) + 1; + stack_top_p[-2] = ecma_make_integer_value (next_index); + + JERRY_ASSERT (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_HAS_CLASS_FIELDS); + + ecma_value_t *computed_class_fields_p = VM_GET_COMPUTED_CLASS_FIELDS (frame_ctx_p); + JERRY_ASSERT ((ecma_value_t) next_index < ECMA_COMPACT_COLLECTION_GET_SIZE (computed_class_fields_p)); + ecma_value_t prop_name = computed_class_fields_p[next_index]; + + if (opcode == CBC_EXT_SET_NEXT_COMPUTED_FIELD_ANONYMOUS_FUNC) + { + ecma_object_t *func_obj_p = ecma_get_object_from_value (stack_top_p[-1]); + + JERRY_ASSERT (ecma_find_named_property (func_obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_NAME)) == NULL); + ecma_property_value_t *value_p; + value_p = ecma_create_named_data_property (func_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_NAME), + ECMA_PROPERTY_FLAG_CONFIGURABLE, + NULL); + + if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + ECMA_SET_SECOND_BIT_TO_POINTER_TAG (((ecma_extended_object_t *) func_obj_p)->u.function.scope_cp); + } + + value_p->value = ecma_copy_value (prop_name); + } + + result = opfunc_define_field (frame_ctx_p->this_binding, prop_name, stack_top_p[-1]); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_free_value (*(--stack_top_p)); + continue; + } + case VM_OC_PUSH_SUPER_CONSTRUCTOR: + { + result = ecma_op_function_get_super_constructor (vm_get_class_function (frame_ctx_p)); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + continue; + } + case VM_OC_RESOLVE_LEXICAL_THIS: + { + result = ecma_op_get_this_binding (frame_ctx_p->lex_env_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + continue; + } + case VM_OC_OBJECT_LITERAL_HOME_ENV: + { + if (opcode == CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT) + { + ecma_value_t obj_value = stack_top_p[-1]; + ecma_object_t *obj_env_p = ecma_create_lex_env_class (frame_ctx_p->lex_env_p, 0); + + ECMA_SET_NON_NULL_POINTER (obj_env_p->u1.bound_object_cp, ecma_get_object_from_value (obj_value)); + stack_top_p[-1] = ecma_make_object_value (obj_env_p); + *stack_top_p++ = obj_value; + } + else + { + JERRY_ASSERT (opcode == CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT); + ecma_deref_object (ecma_get_object_from_value (stack_top_p[-2])); + stack_top_p[-2] = stack_top_p[-1]; + stack_top_p--; + } + continue; + } + case VM_OC_SET_HOME_OBJECT: + { + int offset = opcode == CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED ? -1 : 0; + opfunc_set_home_object (ecma_get_object_from_value (stack_top_p[-1]), + ecma_get_object_from_value (stack_top_p[-3 + offset])); + continue; + } + case VM_OC_SUPER_REFERENCE: + { + result = opfunc_form_super_reference (&stack_top_p, frame_ctx_p, left_value, opcode); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + goto free_left_value; + } + case VM_OC_SET_FUNCTION_NAME: + { + const char *prefix_p = NULL; + lit_utf8_size_t prefix_size = 0; + + if (opcode != CBC_EXT_SET_FUNCTION_NAME) + { + ecma_value_t prop_name_value; + + if (opcode == CBC_EXT_SET_CLASS_NAME) + { + uint16_t literal_index; + READ_LITERAL_INDEX (literal_index); + prop_name_value = literal_start_p[literal_index]; + } + else + { + prop_name_value = stack_top_p[-2]; + } + + ecma_string_t *prop_name_p = ecma_op_to_property_key (prop_name_value); + + if (JERRY_UNLIKELY (prop_name_p == NULL)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + left_value = ecma_make_prop_name_value (prop_name_p); + + if (opcode != CBC_EXT_SET_CLASS_NAME) + { + ecma_ref_ecma_string (prop_name_p); + ecma_free_value (stack_top_p[-2]); + stack_top_p[-2] = left_value; + } + + if (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME || opcode == CBC_EXT_SET_COMPUTED_SETTER_NAME) + { + prefix_p = (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME) ? "get " : "set "; + prefix_size = 4; + } + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (stack_top_p[-1]); + + if (ecma_find_named_property (func_obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_NAME)) != NULL) + { + ecma_free_value (left_value); + continue; + } + + ecma_property_value_t *value_p; + value_p = ecma_create_named_data_property (func_obj_p, + ecma_get_magic_string (LIT_MAGIC_STRING_NAME), + ECMA_PROPERTY_FLAG_CONFIGURABLE, + NULL); + + if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION) + { + ECMA_SET_SECOND_BIT_TO_POINTER_TAG (((ecma_extended_object_t *) func_obj_p)->u.function.scope_cp); + } + + value_p->value = + ecma_op_function_form_name (ecma_get_prop_name_from_value (left_value), (char*) prefix_p, prefix_size); + ecma_free_value (left_value); + continue; + } + case VM_OC_PUSH_SPREAD_ELEMENT: + { + *stack_top_p++ = ECMA_VALUE_SPREAD_ELEMENT; + continue; + } + case VM_OC_PUSH_REST_OBJECT: + { + vm_frame_ctx_shared_t *shared_p = frame_ctx_p->shared_p; + + JERRY_ASSERT (shared_p->status_flags & VM_FRAME_CTX_SHARED_HAS_ARG_LIST); + + const ecma_value_t *arg_list_p = ((vm_frame_ctx_shared_args_t *) shared_p)->arg_list_p; + uint32_t arg_list_len = ((vm_frame_ctx_shared_args_t *) shared_p)->arg_list_len; + uint16_t argument_end; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + argument_end = ((cbc_uint16_arguments_t *) bytecode_header_p)->argument_end; + } + else + { + argument_end = ((cbc_uint8_arguments_t *) bytecode_header_p)->argument_end; + } + + if (arg_list_len < argument_end) + { + arg_list_len = argument_end; + } + + result = ecma_op_new_array_object_from_buffer (arg_list_p + argument_end, arg_list_len - argument_end); + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (result)); + *stack_top_p++ = result; + continue; + } + case VM_OC_ITERATOR_CONTEXT_CREATE: + { + result = ecma_op_get_iterator (stack_top_p[-1], ECMA_VALUE_SYNC_ITERATOR, &left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + uint32_t context_size = + (uint32_t) (stack_top_p + PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION - VM_LAST_CONTEXT_END ()); + stack_top_p += PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION; + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, context_size); + + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_ITERATOR, context_size) | VM_CONTEXT_CLOSE_ITERATOR; + stack_top_p[-2] = result; + stack_top_p[-3] = left_value; + + continue; + } + case VM_OC_ITERATOR_STEP: + { + ecma_value_t *last_context_end_p = VM_LAST_CONTEXT_END (); + + ecma_value_t iterator = last_context_end_p[-2]; + ecma_value_t next_method = last_context_end_p[-3]; + + result = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + last_context_end_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + goto error; + } + + ecma_value_t value = ECMA_VALUE_UNDEFINED; + + if (!ecma_is_value_false (result)) + { + value = ecma_op_iterator_value (result); + ecma_free_value (result); + + if (ECMA_IS_VALUE_ERROR (value)) + { + last_context_end_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + result = value; + goto error; + } + } + else + { + last_context_end_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + } + + *stack_top_p++ = value; + continue; + } + case VM_OC_ITERATOR_CONTEXT_END: + { + JERRY_ASSERT (VM_LAST_CONTEXT_END () == stack_top_p); + + if (stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR) + { + stack_top_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + result = ecma_op_iterator_close (stack_top_p[-2]); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + } + + stack_top_p = + vm_stack_context_abort_variable_length (frame_ctx_p, stack_top_p, PARSER_ITERATOR_CONTEXT_STACK_ALLOCATION); + continue; + } + case VM_OC_DEFAULT_INITIALIZER: + { + JERRY_ASSERT (stack_top_p > VM_GET_REGISTERS (frame_ctx_p) + register_end); + + if (stack_top_p[-1] != ECMA_VALUE_UNDEFINED) + { + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + + stack_top_p--; + continue; + } + case VM_OC_REST_INITIALIZER: + { + ecma_object_t *array_p = ecma_op_new_array_object (0); + JERRY_ASSERT (ecma_op_object_is_fast_array (array_p)); + + ecma_value_t *last_context_end_p = VM_LAST_CONTEXT_END (); + ecma_value_t iterator = last_context_end_p[-2]; + ecma_value_t next_method = last_context_end_p[-3]; + uint32_t index = 0; + + while (true) + { + result = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + last_context_end_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + ecma_deref_object (array_p); + goto error; + } + + if (ecma_is_value_false (result)) + { + last_context_end_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + break; + } + + ecma_value_t value = ecma_op_iterator_value (result); + ecma_free_value (result); + + if (ECMA_IS_VALUE_ERROR (value)) + { + ecma_deref_object (array_p); + result = value; + goto error; + } + + ecma_fast_array_set_property (array_p, index++, value); + ecma_free_value (value); + } + + *stack_top_p++ = ecma_make_object_value (array_p); + continue; + } + case VM_OC_OBJ_INIT_CONTEXT_CREATE: + { + left_value = stack_top_p[-1]; + vm_stack_context_type_t context_type = VM_CONTEXT_OBJ_INIT; + uint32_t context_stack_allocation = PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION; + + if (opcode == CBC_EXT_OBJ_INIT_REST_CONTEXT_CREATE) + { + context_type = VM_CONTEXT_OBJ_INIT_REST; + context_stack_allocation = PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION; + } + + uint32_t context_size = (uint32_t) (stack_top_p + context_stack_allocation - VM_LAST_CONTEXT_END ()); + stack_top_p += context_stack_allocation; + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, context_size); + + stack_top_p[-1] = VM_CREATE_CONTEXT (context_type, context_size); + stack_top_p[-2] = left_value; + + if (context_type == VM_CONTEXT_OBJ_INIT_REST) + { + stack_top_p[-3] = ecma_make_object_value (ecma_op_new_array_object (0)); + } + continue; + } + case VM_OC_OBJ_INIT_CONTEXT_END: + { + JERRY_ASSERT (stack_top_p == VM_LAST_CONTEXT_END ()); + + uint32_t context_stack_allocation = PARSER_OBJ_INIT_CONTEXT_STACK_ALLOCATION; + + if (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_OBJ_INIT_REST) + { + context_stack_allocation = PARSER_OBJ_INIT_REST_CONTEXT_STACK_ALLOCATION; + } + + stack_top_p = vm_stack_context_abort_variable_length (frame_ctx_p, stack_top_p, context_stack_allocation); + continue; + } + case VM_OC_OBJ_INIT_PUSH_REST: + { + ecma_value_t *last_context_end_p = VM_LAST_CONTEXT_END (); + if (!ecma_op_require_object_coercible (last_context_end_p[-2])) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + ecma_object_t *prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); + ecma_object_t *result_object_p = ecma_create_object (prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL); + + left_value = ecma_make_object_value (result_object_p); + result = opfunc_copy_data_properties (left_value, last_context_end_p[-2], last_context_end_p[-3]); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_free_value (last_context_end_p[-3]); + last_context_end_p[-3] = last_context_end_p[-2]; + last_context_end_p[-2] = ECMA_VALUE_UNDEFINED; + + *stack_top_p++ = left_value; + continue; + } + case VM_OC_INITIALIZER_PUSH_NAME: + { + if (JERRY_UNLIKELY (!ecma_is_value_prop_name (left_value))) + { + ecma_string_t *property_key = ecma_op_to_property_key (left_value); + + if (property_key == NULL) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + ecma_free_value (left_value); + left_value = ecma_make_string_value (property_key); + } + + ecma_value_t *last_context_end_p = VM_LAST_CONTEXT_END (); + ecma_object_t *array_obj_p = ecma_get_object_from_value (last_context_end_p[-3]); + JERRY_ASSERT (ecma_get_object_type (array_obj_p) == ECMA_OBJECT_TYPE_ARRAY); + + ecma_extended_object_t *ext_array_obj_p = (ecma_extended_object_t *) array_obj_p; + ecma_fast_array_set_property (array_obj_p, ext_array_obj_p->u.array.length, left_value); + /* FALLTHRU */ + } + case VM_OC_INITIALIZER_PUSH_PROP: + { + ecma_value_t *last_context_end_p = VM_LAST_CONTEXT_END (); + ecma_value_t base = last_context_end_p[-2]; + + if (opcode == CBC_EXT_INITIALIZER_PUSH_PROP) + { + left_value = *last_context_end_p++; + while (last_context_end_p < stack_top_p) + { + last_context_end_p[-1] = *last_context_end_p; + last_context_end_p++; + } + stack_top_p--; + } + + result = vm_op_get_value (base, left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_left_value; + } + case VM_OC_SPREAD_ARGUMENTS: + { + uint8_t arguments_list_len = *byte_code_p++; + stack_top_p -= arguments_list_len; + + ecma_collection_t *arguments_p = opfunc_spread_arguments (stack_top_p, arguments_list_len); + + if (JERRY_UNLIKELY (arguments_p == NULL)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + + stack_top_p++; + ECMA_SET_INTERNAL_VALUE_POINTER (stack_top_p[-1], arguments_p); + + frame_ctx_p->call_operation = VM_EXEC_SPREAD_OP; + frame_ctx_p->byte_code_p = byte_code_start_p; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_CREATE_GENERATOR: + { + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + + vm_executable_object_t *executable_object_p; + executable_object_p = opfunc_create_executable_object (frame_ctx_p, VM_CREATE_EXECUTABLE_OBJECT_GENERATOR); + + return ecma_make_object_value ((ecma_object_t *) executable_object_p); + } + case VM_OC_YIELD: + { + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = --stack_top_p; + return *stack_top_p; + } + case VM_OC_ASYNC_YIELD: + { + ecma_extended_object_t *async_generator_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p); + + opfunc_async_generator_yield (async_generator_object_p, stack_top_p[-1]); + + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = --stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_ASYNC_YIELD_ITERATOR: + { + ecma_extended_object_t *async_generator_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p); + + JERRY_ASSERT ( + !(async_generator_object_p->u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD)); + + /* Byte code is executed at the first time. */ + left_value = stack_top_p[-1]; + result = ecma_op_get_iterator (left_value, ECMA_VALUE_ASYNC_ITERATOR, stack_top_p - 1); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_free_value (left_value); + left_value = result; + result = ecma_op_iterator_next (left_value, stack_top_p[-1], ECMA_VALUE_UNDEFINED); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + result = ecma_promise_async_await (async_generator_object_p, result); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + async_generator_object_p->u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD; + *VM_GET_EXECUTABLE_ITERATOR (frame_ctx_p) = left_value; + + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_AWAIT: + { + if (JERRY_UNLIKELY (!(frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_EXECUTABLE))) + { + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = --stack_top_p; + + result = opfunc_async_create_and_await (frame_ctx_p, *stack_top_p, 0); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + return result; + } + /* FALLTHRU */ + } + case VM_OC_GENERATOR_AWAIT: + { + ecma_extended_object_t *async_generator_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p); + + result = ecma_promise_async_await (async_generator_object_p, *(--stack_top_p)); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_EXT_RETURN: + { + result = left_value; + left_value = ECMA_VALUE_UNDEFINED; + + ecma_value_t *stack_bottom_p = VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth; + + while (stack_top_p > stack_bottom_p) + { + ecma_fast_free_value (*(--stack_top_p)); + } + + goto error; + } + case VM_OC_ASYNC_EXIT: + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + if (!(frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_EXECUTABLE)) + { + result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL); + } + else + { + result = *VM_GET_EXECUTABLE_ITERATOR (frame_ctx_p); + *VM_GET_EXECUTABLE_ITERATOR (frame_ctx_p) = ECMA_VALUE_UNDEFINED; + } + + vm_stack_context_type_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]); + + if (context_type == VM_CONTEXT_TRY) + { + JERRY_ASSERT (frame_ctx_p->context_depth == PARSER_TRY_CONTEXT_STACK_ALLOCATION); + left_value = ECMA_VALUE_UNDEFINED; + } + else + { + JERRY_ASSERT (frame_ctx_p->context_depth == PARSER_FINALLY_CONTEXT_STACK_ALLOCATION); + left_value = stack_top_p[-2]; + } + + if (context_type == VM_CONTEXT_FINALLY_THROW) + { + ecma_reject_promise (result, left_value); + } + else + { + JERRY_ASSERT (context_type == VM_CONTEXT_TRY || context_type == VM_CONTEXT_FINALLY_RETURN); + ecma_fulfill_promise (result, left_value); + } + + ecma_free_value (left_value); + + frame_ctx_p->context_depth = 0; + frame_ctx_p->call_operation = VM_NO_EXEC_OP; + return result; + } + case VM_OC_STRING_CONCAT: + { + ecma_string_t *left_str_p = ecma_op_to_string (left_value); + + if (JERRY_UNLIKELY (left_str_p == NULL)) + { + result = ECMA_VALUE_ERROR; + goto error; + } + ecma_string_t *right_str_p = ecma_op_to_string (right_value); + + if (JERRY_UNLIKELY (right_str_p == NULL)) + { + ecma_deref_ecma_string (left_str_p); + result = ECMA_VALUE_ERROR; + goto error; + } + + ecma_string_t *result_str_p = ecma_concat_ecma_strings (left_str_p, right_str_p); + ecma_deref_ecma_string (right_str_p); + + *stack_top_p++ = ecma_make_string_value (result_str_p); + goto free_both_values; + } + case VM_OC_GET_TEMPLATE_OBJECT: + { + uint8_t tagged_idx = *byte_code_p++; + ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (bytecode_header_p); + JERRY_ASSERT (tagged_idx < collection_p->item_count); + + *stack_top_p++ = ecma_copy_value (collection_p->buffer_p[tagged_idx]); + continue; + } + case VM_OC_PUSH_NEW_TARGET: + { + ecma_object_t *new_target_object_p = JERRY_CONTEXT (current_new_target_p); + if (new_target_object_p == NULL) + { + *stack_top_p++ = ECMA_VALUE_UNDEFINED; + } + else + { + ecma_ref_object (new_target_object_p); + *stack_top_p++ = ecma_make_object_value (new_target_object_p); + } + continue; + } + case VM_OC_REQUIRE_OBJECT_COERCIBLE: + { + if (!ecma_op_require_object_coercible (stack_top_p[-1])) + { + result = ECMA_VALUE_ERROR; + goto error; + } + continue; + } + case VM_OC_ASSIGN_SUPER: + { + result = opfunc_assign_super_reference (&stack_top_p, frame_ctx_p, opcode_data); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + continue; + } + case VM_OC_PUSH_ELISON: + { + *stack_top_p++ = ECMA_VALUE_ARRAY_HOLE; + continue; + } + case VM_OC_APPEND_ARRAY: + { + uint16_t values_length = *byte_code_p++; + stack_top_p -= values_length; + + if (*byte_code_start_p == CBC_EXT_OPCODE) + { + values_length = (uint16_t) (values_length | OPFUNC_HAS_SPREAD_ELEMENT); + } + result = opfunc_append_array (stack_top_p, values_length); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + continue; + } + case VM_OC_IDENT_REFERENCE: + { + uint16_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (literal_index < ident_end); + + if (literal_index < register_end) + { + *stack_top_p++ = ECMA_VALUE_REGISTER_REF; + *stack_top_p++ = ecma_make_integer_value (literal_index); + *stack_top_p++ = ecma_fast_copy_value (VM_GET_REGISTER (frame_ctx_p, literal_index)); + } + else + { + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + ecma_object_t *ref_base_lex_env_p; + + result = ecma_op_get_value_lex_env_base (frame_ctx_p->lex_env_p, &ref_base_lex_env_p, name_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_ref_object (ref_base_lex_env_p); + ecma_ref_ecma_string (name_p); + *stack_top_p++ = ecma_make_object_value (ref_base_lex_env_p); + *stack_top_p++ = ecma_make_string_value (name_p); + *stack_top_p++ = result; + } + continue; + } + case VM_OC_PROP_GET: + { + result = vm_op_get_value (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_PROP_REFERENCE: + { + /* Forms with reference requires preserving the base and offset. */ + + if (opcode == CBC_PUSH_PROP_REFERENCE) + { + left_value = stack_top_p[-2]; + right_value = stack_top_p[-1]; + } + else if (opcode == CBC_PUSH_PROP_LITERAL_REFERENCE) + { + *stack_top_p++ = left_value; + right_value = left_value; + left_value = stack_top_p[-2]; + } + else + { + JERRY_ASSERT (opcode == CBC_PUSH_PROP_LITERAL_LITERAL_REFERENCE + || opcode == CBC_PUSH_PROP_THIS_LITERAL_REFERENCE); + *stack_top_p++ = left_value; + *stack_top_p++ = right_value; + } + /* FALLTHRU */ + } + case VM_OC_PROP_PRE_INCR: + case VM_OC_PROP_PRE_DECR: + case VM_OC_PROP_POST_INCR: + case VM_OC_PROP_POST_DECR: + { + result = vm_op_get_value (left_value, right_value); + + if (opcode < CBC_PRE_INCR) + { + left_value = ECMA_VALUE_UNDEFINED; + right_value = ECMA_VALUE_UNDEFINED; + } + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + if (opcode < CBC_PRE_INCR) + { + break; + } + + stack_top_p += 2; + left_value = result; + right_value = ECMA_VALUE_UNDEFINED; + /* FALLTHRU */ + } + case VM_OC_PRE_INCR: + case VM_OC_PRE_DECR: + case VM_OC_POST_INCR: + case VM_OC_POST_DECR: + { + uint32_t opcode_flags = VM_OC_GROUP_GET_INDEX (opcode_data) - VM_OC_PROP_PRE_INCR; + ecma_number_t result_number; + + byte_code_p = byte_code_start_p + 1; + + if (ecma_is_value_integer_number (left_value)) + { + result = left_value; + left_value = ECMA_VALUE_UNDEFINED; + + ecma_integer_value_t int_value = (ecma_integer_value_t) result; + ecma_integer_value_t int_increase = 0; + + if (opcode_flags & VM_OC_DECREMENT_OPERATOR_FLAG) + { + if (int_value > ECMA_INTEGER_NUMBER_MIN_SHIFTED) + { + int_increase = -(1 << ECMA_DIRECT_SHIFT); + } + } + else if (int_value < ECMA_INTEGER_NUMBER_MAX_SHIFTED) + { + int_increase = 1 << ECMA_DIRECT_SHIFT; + } + + if (JERRY_LIKELY (int_increase != 0)) + { + /* Postfix operators require the unmodified number value. */ + if (opcode_flags & VM_OC_POST_INCR_DECR_OPERATOR_FLAG) + { + POST_INCREASE_DECREASE_PUT_RESULT (result); + } + + result = (ecma_value_t) (int_value + int_increase); + break; + } + result_number = (ecma_number_t) ecma_get_integer_from_value (result); + } + else if (ecma_is_value_float_number (left_value)) + { + result = left_value; + left_value = ECMA_VALUE_UNDEFINED; + result_number = ecma_get_number_from_value (result); + } + else + { + result = ecma_op_to_numeric (left_value, &result_number, ECMA_TO_NUMERIC_ALLOW_BIGINT); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_free_value (left_value); + left_value = ECMA_VALUE_UNDEFINED; + +#if JERRY_BUILTIN_BIGINT + if (JERRY_UNLIKELY (ecma_is_value_bigint (result))) + { + ecma_bigint_unary_operation_type operation_type = ECMA_BIGINT_UNARY_INCREASE; + + if (opcode_flags & VM_OC_DECREMENT_OPERATOR_FLAG) + { + operation_type = ECMA_BIGINT_UNARY_DECREASE; + } + + /* Postfix operators require the unmodified number value. */ + if (opcode_flags & VM_OC_POST_INCR_DECR_OPERATOR_FLAG) + { + POST_INCREASE_DECREASE_PUT_RESULT (result); + + result = ecma_bigint_unary (result, operation_type); + } + else + { + ecma_value_t original_value = result; + result = ecma_bigint_unary (original_value, operation_type); + ecma_free_value (original_value); + } + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + break; + } +#endif /* JERRY_BUILTIN_BIGINT */ + + result = ecma_make_number_value (result_number); + } + + ecma_number_t increase = ECMA_NUMBER_ONE; + + if (opcode_flags & VM_OC_DECREMENT_OPERATOR_FLAG) + { + /* For decrement operators */ + increase = ECMA_NUMBER_MINUS_ONE; + } + + /* Postfix operators require the unmodified number value. */ + if (opcode_flags & VM_OC_POST_INCR_DECR_OPERATOR_FLAG) + { + POST_INCREASE_DECREASE_PUT_RESULT (result); + + result = ecma_make_number_value (result_number + increase); + break; + } + + if (ecma_is_value_integer_number (result)) + { + result = ecma_make_number_value (result_number + increase); + } + else + { + result = ecma_update_float_number (result, result_number + increase); + } + break; + } + case VM_OC_ASSIGN: + { + result = left_value; + left_value = ECMA_VALUE_UNDEFINED; + break; + } + case VM_OC_MOV_IDENT: + { + uint32_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (literal_index < register_end); + JERRY_ASSERT (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))); + + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, literal_index)); + VM_GET_REGISTER (frame_ctx_p, literal_index) = left_value; + continue; + } + case VM_OC_ASSIGN_PROP: + { + result = stack_top_p[-1]; + stack_top_p[-1] = left_value; + left_value = ECMA_VALUE_UNDEFINED; + break; + } + case VM_OC_ASSIGN_PROP_THIS: + { + result = stack_top_p[-1]; + stack_top_p[-1] = ecma_copy_value (frame_ctx_p->this_binding); + *stack_top_p++ = left_value; + left_value = ECMA_VALUE_UNDEFINED; + break; + } + case VM_OC_RETURN_FUNCTION_END: + { + if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) == CBC_FUNCTION_SCRIPT) + { + result = VM_GET_REGISTER (frame_ctx_p, 0); + VM_GET_REGISTERS (frame_ctx_p)[0] = ECMA_VALUE_UNDEFINED; + } + else + { + result = ECMA_VALUE_UNDEFINED; + } + + goto error; + } + case VM_OC_RETURN: + { + JERRY_ASSERT (opcode == CBC_RETURN || opcode == CBC_RETURN_WITH_LITERAL); + + result = left_value; + left_value = ECMA_VALUE_UNDEFINED; + goto error; + } + case VM_OC_THROW: + { + jcontext_raise_exception (left_value); + + result = ECMA_VALUE_ERROR; + left_value = ECMA_VALUE_UNDEFINED; + goto error; + } + case VM_OC_THROW_REFERENCE_ERROR: + { + result = ecma_raise_reference_error (ECMA_ERR_UNDEFINED_REFERENCE); + goto error; + } + case VM_OC_EVAL: + { + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_DIRECT_EVAL; + JERRY_ASSERT ((*byte_code_p >= CBC_CALL && *byte_code_p <= CBC_CALL2_PROP_BLOCK) + || (*byte_code_p == CBC_EXT_OPCODE && byte_code_p[1] >= CBC_EXT_SPREAD_CALL + && byte_code_p[1] <= CBC_EXT_SPREAD_CALL_PROP_BLOCK)); + continue; + } + case VM_OC_CALL: + { + frame_ctx_p->call_operation = VM_EXEC_CALL; + frame_ctx_p->byte_code_p = byte_code_start_p; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_NEW: + { + frame_ctx_p->call_operation = VM_EXEC_CONSTRUCT; + frame_ctx_p->byte_code_p = byte_code_start_p; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_ERROR: + { + JERRY_ASSERT (frame_ctx_p->byte_code_p[1] == CBC_EXT_ERROR); + + result = ECMA_VALUE_ERROR; + goto error; + } + case VM_OC_RESOLVE_BASE_FOR_CALL: + { + ecma_value_t this_value = stack_top_p[-3]; + + if (this_value == ECMA_VALUE_REGISTER_REF) + { + /* Lexical environment cannot be 'this' value. */ + stack_top_p[-2] = ECMA_VALUE_UNDEFINED; + stack_top_p[-3] = ECMA_VALUE_UNDEFINED; + } + else if (vm_get_implicit_this_value (&this_value)) + { + ecma_free_value (stack_top_p[-3]); + stack_top_p[-3] = this_value; + } + + continue; + } + case VM_OC_PROP_DELETE: + { + result = vm_op_delete_prop (left_value, right_value, is_strict); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + JERRY_ASSERT (ecma_is_value_boolean (result)); + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_DELETE: + { + uint16_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + if (literal_index < register_end) + { + *stack_top_p++ = ECMA_VALUE_FALSE; + continue; + } + + result = vm_op_delete_var (literal_start_p[literal_index], frame_ctx_p->lex_env_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + JERRY_ASSERT (ecma_is_value_boolean (result)); + + *stack_top_p++ = result; + continue; + } + case VM_OC_JUMP: + { + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + case VM_OC_BRANCH_IF_STRICT_EQUAL: + { + ecma_value_t value = *(--stack_top_p); + + JERRY_ASSERT (stack_top_p > VM_GET_REGISTERS (frame_ctx_p) + register_end); + + if (ecma_op_strict_equality_compare (value, stack_top_p[-1])) + { + byte_code_p = byte_code_start_p + branch_offset; + ecma_free_value (*--stack_top_p); + } + ecma_free_value (value); + continue; + } + case VM_OC_BRANCH_IF_TRUE: + case VM_OC_BRANCH_IF_FALSE: + case VM_OC_BRANCH_IF_LOGICAL_TRUE: + case VM_OC_BRANCH_IF_LOGICAL_FALSE: + { + uint32_t opcode_flags = VM_OC_GROUP_GET_INDEX (opcode_data) - VM_OC_BRANCH_IF_TRUE; + ecma_value_t value = *(--stack_top_p); + + bool boolean_value = ecma_op_to_boolean (value); + + if (opcode_flags & VM_OC_BRANCH_IF_FALSE_FLAG) + { + boolean_value = !boolean_value; + } + + if (boolean_value) + { + byte_code_p = byte_code_start_p + branch_offset; + if (opcode_flags & VM_OC_LOGICAL_BRANCH_FLAG) + { + /* "Push" the value back to the stack. */ + ++stack_top_p; + continue; + } + } + + ecma_fast_free_value (value); + continue; + } + case VM_OC_POP_REFERENCE: + { + ecma_free_value (stack_top_p[-2]); + ecma_free_value (stack_top_p[-3]); + stack_top_p[-3] = stack_top_p[-1]; + stack_top_p -= 2; + continue; + } + case VM_OC_BRANCH_IF_NULLISH: + { + left_value = stack_top_p[-1]; + + if (!ecma_is_value_null (left_value) && !ecma_is_value_undefined (left_value)) + { + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + --stack_top_p; + continue; + } + case VM_OC_PLUS: + case VM_OC_MINUS: + { + result = opfunc_unary_operation (left_value, VM_OC_GROUP_GET_INDEX (opcode_data) == VM_OC_PLUS); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_left_value; + } + case VM_OC_NOT: + { + *stack_top_p++ = ecma_make_boolean_value (!ecma_op_to_boolean (left_value)); + JERRY_ASSERT (ecma_is_value_boolean (stack_top_p[-1])); + goto free_left_value; + } + case VM_OC_BIT_NOT: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_is_value_integer_number (left_value)) + { + *stack_top_p++ = (~ECMA_DIRECT_TYPE_MASK) ^ left_value; + goto free_left_value; + } + + result = do_number_bitwise_not (left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_left_value; + } + case VM_OC_VOID: + { + *stack_top_p++ = ECMA_VALUE_UNDEFINED; + goto free_left_value; + } + case VM_OC_TYPEOF_IDENT: + { + uint16_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + JERRY_ASSERT (literal_index < ident_end); + + if (literal_index < register_end) + { + left_value = ecma_copy_value (VM_GET_REGISTER (frame_ctx_p, literal_index)); + } + else + { + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + ecma_object_t *ref_base_lex_env_p; + + result = ecma_op_get_value_lex_env_base (frame_ctx_p->lex_env_p, &ref_base_lex_env_p, name_p); + + if (ref_base_lex_env_p == NULL) + { + jcontext_release_exception (); + result = ECMA_VALUE_UNDEFINED; + } + else if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + left_value = result; + } + /* FALLTHRU */ + } + case VM_OC_TYPEOF: + { + result = opfunc_typeof (left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_left_value; + } + case VM_OC_ADD: + { + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + *stack_top_p++ = ecma_make_int32_value ((int32_t) (left_integer + right_integer)); + continue; + } + + if (ecma_is_value_float_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t new_value = + (ecma_get_float_from_value (left_value) + ecma_get_number_from_value (right_value)); + + *stack_top_p++ = ecma_update_float_number (left_value, new_value); + ecma_free_number (right_value); + continue; + } + + if (ecma_is_value_float_number (right_value) && ecma_is_value_integer_number (left_value)) + { + ecma_number_t new_value = + ((ecma_number_t) ecma_get_integer_from_value (left_value) + ecma_get_float_from_value (right_value)); + + *stack_top_p++ = ecma_update_float_number (right_value, new_value); + continue; + } + + result = opfunc_addition (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_SUB: + { + JERRY_STATIC_ASSERT (ECMA_INTEGER_NUMBER_MAX * 2 <= INT32_MAX && ECMA_INTEGER_NUMBER_MIN * 2 >= INT32_MIN, + doubled_ecma_numbers_must_fit_into_int32_range); + + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + *stack_top_p++ = ecma_make_int32_value ((int32_t) (left_integer - right_integer)); + continue; + } + + if (ecma_is_value_float_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t new_value = + (ecma_get_float_from_value (left_value) - ecma_get_number_from_value (right_value)); + + *stack_top_p++ = ecma_update_float_number (left_value, new_value); + ecma_free_number (right_value); + continue; + } + + if (ecma_is_value_float_number (right_value) && ecma_is_value_integer_number (left_value)) + { + ecma_number_t new_value = + ((ecma_number_t) ecma_get_integer_from_value (left_value) - ecma_get_float_from_value (right_value)); + + *stack_top_p++ = ecma_update_float_number (right_value, new_value); + continue; + } + + result = do_number_arithmetic (NUMBER_ARITHMETIC_SUBTRACTION, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_MUL: + { + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + JERRY_STATIC_ASSERT (ECMA_INTEGER_MULTIPLY_MAX * ECMA_INTEGER_MULTIPLY_MAX <= ECMA_INTEGER_NUMBER_MAX + && -(ECMA_INTEGER_MULTIPLY_MAX * ECMA_INTEGER_MULTIPLY_MAX) >= ECMA_INTEGER_NUMBER_MIN, + square_of_integer_multiply_max_must_fit_into_integer_value_range); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + + if (-ECMA_INTEGER_MULTIPLY_MAX <= left_integer && left_integer <= ECMA_INTEGER_MULTIPLY_MAX + && -ECMA_INTEGER_MULTIPLY_MAX <= right_integer && right_integer <= ECMA_INTEGER_MULTIPLY_MAX + && left_integer != 0 && right_integer != 0) + { + *stack_top_p++ = ecma_integer_multiply (left_integer, right_integer); + continue; + } + + ecma_number_t multiply = (ecma_number_t) left_integer * (ecma_number_t) right_integer; + *stack_top_p++ = ecma_make_number_value (multiply); + continue; + } + + if (ecma_is_value_float_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t new_value = + (ecma_get_float_from_value (left_value) * ecma_get_number_from_value (right_value)); + + *stack_top_p++ = ecma_update_float_number (left_value, new_value); + ecma_free_number (right_value); + continue; + } + + if (ecma_is_value_float_number (right_value) && ecma_is_value_integer_number (left_value)) + { + ecma_number_t new_value = + ((ecma_number_t) ecma_get_integer_from_value (left_value) * ecma_get_float_from_value (right_value)); + + *stack_top_p++ = ecma_update_float_number (right_value, new_value); + continue; + } + + result = do_number_arithmetic (NUMBER_ARITHMETIC_MULTIPLICATION, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_DIV: + { + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + result = do_number_arithmetic (NUMBER_ARITHMETIC_DIVISION, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_MOD: + { + JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (left_value) && !ECMA_IS_VALUE_ERROR (right_value)); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + + if (right_integer != 0) + { + ecma_integer_value_t mod_result = left_integer % right_integer; + + if (mod_result != 0 || left_integer >= 0) + { + *stack_top_p++ = ecma_make_integer_value (mod_result); + continue; + } + } + } + + result = do_number_arithmetic (NUMBER_ARITHMETIC_REMAINDER, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_EXP: + { + result = do_number_arithmetic (NUMBER_ARITHMETIC_EXPONENTIATION, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_EQUAL: + { + result = opfunc_equality (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_NOT_EQUAL: + { + result = opfunc_equality (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = ecma_invert_boolean_value (result); + goto free_both_values; + } + case VM_OC_STRICT_EQUAL: + { + bool is_equal = ecma_op_strict_equality_compare (left_value, right_value); + + result = ecma_make_boolean_value (is_equal); + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_STRICT_NOT_EQUAL: + { + bool is_equal = ecma_op_strict_equality_compare (left_value, right_value); + + result = ecma_make_boolean_value (!is_equal); + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_BIT_OR: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + *stack_top_p++ = left_value | right_value; + continue; + } + + result = do_number_bitwise_logic (NUMBER_BITWISE_LOGIC_OR, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_BIT_XOR: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + *stack_top_p++ = left_value ^ right_value; + continue; + } + + result = do_number_bitwise_logic (NUMBER_BITWISE_LOGIC_XOR, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_BIT_AND: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + *stack_top_p++ = left_value & right_value; + continue; + } + + result = do_number_bitwise_logic (NUMBER_BITWISE_LOGIC_AND, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_LEFT_SHIFT: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + + *stack_top_p++ = ecma_make_int32_value ((int32_t) ((uint32_t) left_integer << (right_integer & 0x1f))); + continue; + } + + result = do_number_bitwise_logic (NUMBER_BITWISE_SHIFT_LEFT, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_RIGHT_SHIFT: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + *stack_top_p++ = ecma_make_integer_value (left_integer >> (right_integer & 0x1f)); + continue; + } + + result = do_number_bitwise_logic (NUMBER_BITWISE_SHIFT_RIGHT, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_UNS_RIGHT_SHIFT: + { + JERRY_STATIC_ASSERT ((ECMA_DIRECT_TYPE_MASK == ((1 << ECMA_DIRECT_SHIFT) - 1)), + direct_type_mask_must_fill_all_bits_before_the_value_starts); + + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + uint32_t left_uint32 = (uint32_t) ecma_get_integer_from_value (left_value); + ecma_integer_value_t right_integer = ecma_get_integer_from_value (right_value); + *stack_top_p++ = ecma_make_uint32_value (left_uint32 >> (right_integer & 0x1f)); + continue; + } + + result = do_number_bitwise_logic (NUMBER_BITWISE_SHIFT_URIGHT, left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_LESS: + { + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + bool is_less = (ecma_integer_value_t) left_value < (ecma_integer_value_t) right_value; +#if !JERRY_VM_HALT + /* This is a lookahead to the next opcode to improve performance. + * If it is CBC_BRANCH_IF_TRUE_BACKWARD, execute it. */ + if (*byte_code_p <= CBC_BRANCH_IF_TRUE_BACKWARD_3 && *byte_code_p >= CBC_BRANCH_IF_TRUE_BACKWARD) + { + byte_code_start_p = byte_code_p++; + branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (*byte_code_start_p); + JERRY_ASSERT (branch_offset_length >= 1 && branch_offset_length <= 3); + + if (is_less) + { + branch_offset = *(byte_code_p++); + + if (JERRY_UNLIKELY (branch_offset_length != 1)) + { + branch_offset <<= 8; + branch_offset |= *(byte_code_p++); + if (JERRY_UNLIKELY (branch_offset_length == 3)) + { + branch_offset <<= 8; + branch_offset |= *(byte_code_p++); + } + } + + /* Note: The opcode is a backward branch. */ + byte_code_p = byte_code_start_p - branch_offset; + } + else + { + byte_code_p += branch_offset_length; + } + + continue; + } +#endif /* !JERRY_VM_HALT */ + *stack_top_p++ = ecma_make_boolean_value (is_less); + continue; + } + + if (ecma_is_value_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t left_number = ecma_get_number_from_value (left_value); + ecma_number_t right_number = ecma_get_number_from_value (right_value); + + *stack_top_p++ = ecma_make_boolean_value (left_number < right_number); + goto free_both_values; + } + + result = opfunc_relation (left_value, right_value, true, false); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_GREATER: + { + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = (ecma_integer_value_t) left_value; + ecma_integer_value_t right_integer = (ecma_integer_value_t) right_value; + + *stack_top_p++ = ecma_make_boolean_value (left_integer > right_integer); + continue; + } + + if (ecma_is_value_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t left_number = ecma_get_number_from_value (left_value); + ecma_number_t right_number = ecma_get_number_from_value (right_value); + + *stack_top_p++ = ecma_make_boolean_value (left_number > right_number); + goto free_both_values; + } + + result = opfunc_relation (left_value, right_value, false, false); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_LESS_EQUAL: + { + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = (ecma_integer_value_t) left_value; + ecma_integer_value_t right_integer = (ecma_integer_value_t) right_value; + + *stack_top_p++ = ecma_make_boolean_value (left_integer <= right_integer); + continue; + } + + if (ecma_is_value_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t left_number = ecma_get_number_from_value (left_value); + ecma_number_t right_number = ecma_get_number_from_value (right_value); + + *stack_top_p++ = ecma_make_boolean_value (left_number <= right_number); + goto free_both_values; + } + + result = opfunc_relation (left_value, right_value, false, true); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_GREATER_EQUAL: + { + if (ecma_are_values_integer_numbers (left_value, right_value)) + { + ecma_integer_value_t left_integer = (ecma_integer_value_t) left_value; + ecma_integer_value_t right_integer = (ecma_integer_value_t) right_value; + + *stack_top_p++ = ecma_make_boolean_value (left_integer >= right_integer); + continue; + } + + if (ecma_is_value_number (left_value) && ecma_is_value_number (right_value)) + { + ecma_number_t left_number = ecma_get_number_from_value (left_value); + ecma_number_t right_number = ecma_get_number_from_value (right_value); + + *stack_top_p++ = ecma_make_boolean_value (left_number >= right_number); + goto free_both_values; + } + + result = opfunc_relation (left_value, right_value, true, true); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_IN: + { + result = opfunc_in (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_INSTANCEOF: + { + result = opfunc_instanceof (left_value, right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + goto free_both_values; + } + case VM_OC_BLOCK_CREATE_CONTEXT: + { + ecma_value_t *stack_context_top_p; + stack_context_top_p = VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth; + + JERRY_ASSERT (stack_context_top_p == stack_top_p || stack_context_top_p == stack_top_p - 1); + + if (byte_code_start_p[0] != CBC_EXT_OPCODE) + { + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + if (stack_context_top_p != stack_top_p) + { + /* Preserve the value of switch statement. */ + stack_context_top_p[1] = stack_context_top_p[0]; + } + + stack_context_top_p[0] = VM_CREATE_CONTEXT_WITH_ENV (VM_CONTEXT_BLOCK, branch_offset); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_BLOCK_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_BLOCK_CONTEXT_STACK_ALLOCATION; + } + else + { + JERRY_ASSERT (byte_code_start_p[1] == CBC_EXT_TRY_CREATE_ENV); + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_context_top_p[-1]) == VM_CONTEXT_TRY + || VM_GET_CONTEXT_TYPE (stack_context_top_p[-1]) == VM_CONTEXT_CATCH + || VM_GET_CONTEXT_TYPE (stack_context_top_p[-1]) == VM_CONTEXT_FINALLY_JUMP + || VM_GET_CONTEXT_TYPE (stack_context_top_p[-1]) == VM_CONTEXT_FINALLY_THROW + || VM_GET_CONTEXT_TYPE (stack_context_top_p[-1]) == VM_CONTEXT_FINALLY_RETURN); + + JERRY_ASSERT (!(stack_context_top_p[-1] & VM_CONTEXT_HAS_LEX_ENV)); + + stack_context_top_p[-1] |= VM_CONTEXT_HAS_LEX_ENV; + } + + frame_ctx_p->lex_env_p = ecma_create_decl_lex_env (frame_ctx_p->lex_env_p); + frame_ctx_p->lex_env_p->type_flags_refs |= ECMA_OBJECT_FLAG_BLOCK; + + continue; + } + case VM_OC_WITH: + { + ecma_value_t value = *(--stack_top_p); + ecma_object_t *object_p; + ecma_object_t *with_env_p; + + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + result = ecma_op_to_object (value); + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + object_p = ecma_get_object_from_value (result); + + with_env_p = ecma_create_object_lex_env (frame_ctx_p->lex_env_p, object_p); + ecma_deref_object (object_p); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_WITH_CONTEXT_STACK_ALLOCATION; + + stack_top_p[-1] = VM_CREATE_CONTEXT_WITH_ENV (VM_CONTEXT_WITH, branch_offset); + + with_env_p->type_flags_refs |= ECMA_OBJECT_FLAG_BLOCK; + frame_ctx_p->lex_env_p = with_env_p; + continue; + } + case VM_OC_FOR_IN_INIT: + { + ecma_value_t value = *(--stack_top_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + ecma_value_t expr_obj_value = ECMA_VALUE_UNDEFINED; + ecma_collection_t *prop_names_p = opfunc_for_in (value, &expr_obj_value); + ecma_free_value (value); + + if (prop_names_p == NULL) + { + if (JERRY_UNLIKELY (ECMA_IS_VALUE_ERROR (expr_obj_value))) + { + result = expr_obj_value; + goto error; + } + + /* The collection is already released */ + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION; + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_FOR_IN, branch_offset); + ECMA_SET_INTERNAL_VALUE_ANY_POINTER (stack_top_p[-2], prop_names_p); + stack_top_p[-3] = 0; + stack_top_p[-4] = expr_obj_value; + + if (byte_code_p[0] == CBC_EXT_OPCODE && byte_code_p[1] == CBC_EXT_CLONE_CONTEXT) + { + /* No need to duplicate the first context. */ + byte_code_p += 2; + } + + continue; + } + case VM_OC_FOR_IN_GET_NEXT: + { + ecma_value_t *context_top_p = VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth; + + ecma_collection_t *collection_p; + collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, context_top_p[-2]); + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (context_top_p[-1]) == VM_CONTEXT_FOR_IN); + + uint32_t index = context_top_p[-3]; + ecma_value_t *buffer_p = collection_p->buffer_p; + + *stack_top_p++ = buffer_p[index]; + context_top_p[-3]++; + continue; + } + case VM_OC_FOR_IN_HAS_NEXT: + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + ecma_collection_t *collection_p; + collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, stack_top_p[-2]); + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FOR_IN); + + ecma_value_t *buffer_p = collection_p->buffer_p; + ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[-4]); + uint32_t index = stack_top_p[-3]; + + while (index < collection_p->item_count) + { + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (buffer_p[index]); + + result = ecma_op_object_has_property (object_p, prop_name_p); + + if (ECMA_IS_VALUE_ERROR (result)) + { + stack_top_p[-3] = index; + goto error; + } + + if (JERRY_LIKELY (ecma_is_value_true (result))) + { + byte_code_p = byte_code_start_p + branch_offset; + break; + } + + ecma_deref_ecma_string (prop_name_p); + index++; + } + + if (index == collection_p->item_count) + { + ecma_deref_object (object_p); + ecma_collection_destroy (collection_p); + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION); + stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION; + } + else + { + stack_top_p[-3] = index; + } + continue; + } + case VM_OC_FOR_OF_INIT: + { + ecma_value_t value = *(--stack_top_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + ecma_value_t next_method; + ecma_value_t iterator = ecma_op_get_iterator (value, ECMA_VALUE_SYNC_ITERATOR, &next_method); + + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (iterator)) + { + result = iterator; + goto error; + } + + result = ecma_op_iterator_step (iterator, next_method); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_free_value (iterator); + ecma_free_value (next_method); + goto error; + } + + if (ecma_is_value_false (result)) + { + ecma_free_value (iterator); + ecma_free_value (next_method); + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + + ecma_value_t next_value = ecma_op_iterator_value (result); + ecma_free_value (result); + + if (ECMA_IS_VALUE_ERROR (next_value)) + { + result = next_value; + ecma_free_value (iterator); + ecma_free_value (next_method); + goto error; + } + + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION; + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_FOR_OF, branch_offset) | VM_CONTEXT_CLOSE_ITERATOR; + stack_top_p[-2] = next_value; + stack_top_p[-3] = iterator; + stack_top_p[-4] = next_method; + + if (byte_code_p[0] == CBC_EXT_OPCODE && byte_code_p[1] == CBC_EXT_CLONE_CONTEXT) + { + /* No need to duplicate the first context. */ + byte_code_p += 2; + } + continue; + } + case VM_OC_FOR_OF_GET_NEXT: + { + ecma_value_t *context_top_p = VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth; + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (context_top_p[-1]) == VM_CONTEXT_FOR_OF + || VM_GET_CONTEXT_TYPE (context_top_p[-1]) == VM_CONTEXT_FOR_AWAIT_OF); + JERRY_ASSERT (context_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR); + + *stack_top_p++ = context_top_p[-2]; + context_top_p[-2] = ECMA_VALUE_UNDEFINED; + continue; + } + case VM_OC_FOR_OF_HAS_NEXT: + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FOR_OF); + JERRY_ASSERT (stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR); + + stack_top_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + result = ecma_op_iterator_step (stack_top_p[-3], stack_top_p[-4]); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + if (ecma_is_value_false (result)) + { + ecma_free_value (stack_top_p[-2]); + ecma_free_value (stack_top_p[-3]); + ecma_free_value (stack_top_p[-4]); + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION); + stack_top_p -= PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION; + continue; + } + + ecma_value_t next_value = ecma_op_iterator_value (result); + ecma_free_value (result); + + if (ECMA_IS_VALUE_ERROR (next_value)) + { + result = next_value; + goto error; + } + + JERRY_ASSERT (stack_top_p[-2] == ECMA_VALUE_UNDEFINED); + stack_top_p[-1] |= VM_CONTEXT_CLOSE_ITERATOR; + stack_top_p[-2] = next_value; + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + case VM_OC_FOR_AWAIT_OF_INIT: + { + ecma_value_t value = *(--stack_top_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + ecma_value_t next_method; + result = ecma_op_get_iterator (value, ECMA_VALUE_ASYNC_ITERATOR, &next_method); + + ecma_free_value (value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_value_t iterator = result; + result = ecma_op_iterator_next (result, next_method, ECMA_VALUE_EMPTY); + + if (ECMA_IS_VALUE_ERROR (result)) + { + ecma_free_value (iterator); + ecma_free_value (next_method); + goto error; + } + + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_FOR_AWAIT_OF_CONTEXT_STACK_ALLOCATION; + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_FOR_AWAIT_OF, branch_offset); + stack_top_p[-2] = ECMA_VALUE_UNDEFINED; + stack_top_p[-3] = iterator; + stack_top_p[-4] = next_method; + + if (byte_code_p[0] == CBC_EXT_OPCODE && byte_code_p[1] == CBC_EXT_CLONE_CONTEXT) + { + /* No need to duplicate the first context. */ + byte_code_p += 2; + } + + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_p; + frame_ctx_p->stack_top_p = stack_top_p; + + uint16_t extra_flags = + (ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD | (ECMA_AWAIT_FOR_NEXT << ECMA_AWAIT_STATE_SHIFT)); + + if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) == CBC_FUNCTION_ASYNC_GENERATOR + || (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_EXECUTABLE)) + { + ecma_extended_object_t *executable_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p); + result = ecma_promise_async_await (executable_object_p, result); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + executable_object_p->u.cls.u2.executable_obj_flags |= extra_flags; + return ECMA_VALUE_UNDEFINED; + } + + result = opfunc_async_create_and_await (frame_ctx_p, result, extra_flags); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + return result; + } + case VM_OC_FOR_AWAIT_OF_HAS_NEXT: + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FOR_AWAIT_OF); + JERRY_ASSERT (stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR); + + stack_top_p[-1] &= (uint32_t) ~VM_CONTEXT_CLOSE_ITERATOR; + result = ecma_op_iterator_next (stack_top_p[-3], stack_top_p[-4], ECMA_VALUE_EMPTY); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + ecma_extended_object_t *executable_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p); + result = ecma_promise_async_await (executable_object_p, result); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + uint16_t extra_flags = + (ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD | (ECMA_AWAIT_FOR_NEXT << ECMA_AWAIT_STATE_SHIFT)); + executable_object_p->u.cls.u2.executable_obj_flags |= extra_flags; + + frame_ctx_p->call_operation = VM_EXEC_RETURN; + frame_ctx_p->byte_code_p = byte_code_start_p + branch_offset; + frame_ctx_p->stack_top_p = stack_top_p; + return ECMA_VALUE_UNDEFINED; + } + case VM_OC_TRY: + { + /* Try opcode simply creates the try context. */ + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION); + stack_top_p += PARSER_TRY_CONTEXT_STACK_ALLOCATION; + + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_TRY, branch_offset); + continue; + } + case VM_OC_CATCH: + { + /* Catches are ignored and turned to jumps. */ + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_TRY); + + byte_code_p = byte_code_start_p + branch_offset; + continue; + } + case VM_OC_FINALLY: + { + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_TRY + || VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_CATCH); + + if (stack_top_p[-1] & VM_CONTEXT_HAS_LEX_ENV) + { + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + frame_ctx_p->lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + ecma_deref_object (lex_env_p); + } + + VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION); + stack_top_p += PARSER_FINALLY_CONTEXT_EXTRA_STACK_ALLOCATION; + + stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_FINALLY_JUMP, branch_offset); + stack_top_p[-2] = (ecma_value_t) branch_offset; + continue; + } + case VM_OC_CONTEXT_END: + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + JERRY_ASSERT (!(stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR)); + + ecma_value_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]); + + if (!VM_CONTEXT_IS_FINALLY (context_type)) + { + stack_top_p = vm_stack_context_abort (frame_ctx_p, stack_top_p); + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + continue; + } + + if (stack_top_p[-1] & VM_CONTEXT_HAS_LEX_ENV) + { + ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p; + JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL); + frame_ctx_p->lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp); + ecma_deref_object (lex_env_p); + } + + VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FINALLY_CONTEXT_STACK_ALLOCATION); + stack_top_p -= PARSER_FINALLY_CONTEXT_STACK_ALLOCATION; + + if (context_type == VM_CONTEXT_FINALLY_RETURN) + { + result = *stack_top_p; + goto error; + } + + if (context_type == VM_CONTEXT_FINALLY_THROW) + { + jcontext_raise_exception (*stack_top_p); +#if JERRY_VM_THROW + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_ERROR_THROWN; +#endif /* JERRY_VM_THROW */ + result = ECMA_VALUE_ERROR; + goto error; + } + + JERRY_ASSERT (context_type == VM_CONTEXT_FINALLY_JUMP); + + uint32_t jump_target = *stack_top_p; + + vm_stack_found_type type = + vm_stack_find_finally (frame_ctx_p, stack_top_p, VM_CONTEXT_FINALLY_JUMP, jump_target); + stack_top_p = frame_ctx_p->stack_top_p; + switch (type) + { + case VM_CONTEXT_FOUND_FINALLY: + { + byte_code_p = frame_ctx_p->byte_code_p; + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_JUMP); + stack_top_p[-2] = jump_target; + break; + } + case VM_CONTEXT_FOUND_ERROR: + { + JERRY_ASSERT (jcontext_has_pending_exception ()); + result = ECMA_VALUE_ERROR; + goto error; + } + case VM_CONTEXT_FOUND_AWAIT: + { + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_JUMP); + stack_top_p[-2] = jump_target; + return ECMA_VALUE_UNDEFINED; + } + default: + { + byte_code_p = frame_ctx_p->byte_code_start_p + jump_target; + break; + } + } + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + continue; + } + case VM_OC_JUMP_AND_EXIT_CONTEXT: + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + JERRY_ASSERT (!jcontext_has_pending_exception ()); + + branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p); + + vm_stack_found_type type = + vm_stack_find_finally (frame_ctx_p, stack_top_p, VM_CONTEXT_FINALLY_JUMP, (uint32_t) branch_offset); + stack_top_p = frame_ctx_p->stack_top_p; + switch (type) + { + case VM_CONTEXT_FOUND_FINALLY: + { + byte_code_p = frame_ctx_p->byte_code_p; + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_JUMP); + stack_top_p[-2] = (uint32_t) branch_offset; + break; + } + case VM_CONTEXT_FOUND_ERROR: + { + JERRY_ASSERT (jcontext_has_pending_exception ()); + result = ECMA_VALUE_ERROR; + goto error; + } + case VM_CONTEXT_FOUND_AWAIT: + { + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_JUMP); + stack_top_p[-2] = (uint32_t) branch_offset; + return ECMA_VALUE_UNDEFINED; + } + default: + { + byte_code_p = frame_ctx_p->byte_code_start_p + branch_offset; + break; + } + } + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + continue; + } +#if JERRY_MODULE_SYSTEM + case VM_OC_MODULE_IMPORT: + { + left_value = *(--stack_top_p); + + ecma_value_t user_value = ECMA_VALUE_UNDEFINED; + ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value; + +#if JERRY_SNAPSHOT_EXEC + if (JERRY_UNLIKELY (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))) + { +#endif /* JERRY_SNAPSHOT_EXEC */ + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + + if (script_p->refs_and_type & CBC_SCRIPT_HAS_USER_VALUE) + { + user_value = CBC_SCRIPT_GET_USER_VALUE (script_p); + } +#if JERRY_SNAPSHOT_EXEC + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + result = ecma_module_import (left_value, user_value); + ecma_free_value (left_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + goto error; + } + + *stack_top_p++ = result; + continue; + } + case VM_OC_MODULE_IMPORT_META: + { + ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value; + cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); + + JERRY_ASSERT (script_p->refs_and_type & CBC_SCRIPT_HAS_IMPORT_META); + + ecma_value_t import_meta = CBC_SCRIPT_GET_IMPORT_META (script_p, script_p->refs_and_type); + ecma_object_t *import_meta_object_p = ecma_get_object_from_value (import_meta); + + if (ecma_get_object_type (import_meta_object_p) != ECMA_OBJECT_TYPE_GENERAL) + { + JERRY_ASSERT (ecma_object_class_is (import_meta_object_p, ECMA_OBJECT_CLASS_MODULE)); + + ecma_value_t module = import_meta; + import_meta_object_p = ecma_create_object (NULL, 0, ECMA_OBJECT_TYPE_GENERAL); + import_meta = ecma_make_object_value (import_meta_object_p); + + if (JERRY_CONTEXT (module_import_meta_callback_p) != NULL) + { + void *user_p = JERRY_CONTEXT (module_import_meta_callback_user_p); + JERRY_CONTEXT (module_import_meta_callback_p) (module, import_meta, user_p); + } + + CBC_SCRIPT_GET_IMPORT_META (script_p, script_p->refs_and_type) = import_meta; + } + else + { + ecma_ref_object (import_meta_object_p); + } + + *stack_top_p++ = import_meta; + continue; + } +#endif /* JERRY_MODULE_SYSTEM */ + case VM_OC_NONE: + default: + { + JERRY_ASSERT (VM_OC_GROUP_GET_INDEX (opcode_data) == VM_OC_NONE); + + jerry_fatal (JERRY_FATAL_DISABLED_BYTE_CODE); + } + } + + JERRY_ASSERT (VM_OC_HAS_PUT_RESULT (opcode_data)); + + if (opcode_data & VM_OC_PUT_IDENT) + { + uint16_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + if (literal_index < register_end) + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, literal_index)); + VM_GET_REGISTER (frame_ctx_p, literal_index) = result; + + if (opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK)) + { + result = ecma_fast_copy_value (result); + } + } + else + { + ecma_string_t *var_name_str_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + ecma_value_t put_value_result = + ecma_op_put_value_lex_env_base (frame_ctx_p->lex_env_p, var_name_str_p, is_strict, result); + + if (ECMA_IS_VALUE_ERROR (put_value_result)) + { + ecma_free_value (result); + result = put_value_result; + goto error; + } + + if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))) + { + ecma_fast_free_value (result); + } + } + } + else if (opcode_data & VM_OC_PUT_REFERENCE) + { + ecma_value_t property = *(--stack_top_p); + ecma_value_t base = *(--stack_top_p); + + if (base == ECMA_VALUE_REGISTER_REF) + { + property = (ecma_value_t) ecma_get_integer_from_value (property); + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, property)); + VM_GET_REGISTER (frame_ctx_p, property) = result; + + if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))) + { + goto free_both_values; + } + result = ecma_fast_copy_value (result); + } + else + { + ecma_value_t set_value_result = vm_op_set_value (base, property, result, is_strict); + + if (ECMA_IS_VALUE_ERROR (set_value_result)) + { + ecma_free_value (result); + result = set_value_result; + goto error; + } + + if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK))) + { + ecma_fast_free_value (result); + goto free_both_values; + } + } + } + + if (opcode_data & VM_OC_PUT_STACK) + { + *stack_top_p++ = result; + } + else if (opcode_data & VM_OC_PUT_BLOCK) + { + ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); + VM_GET_REGISTERS (frame_ctx_p)[0] = result; + } + +free_both_values: + ecma_fast_free_value (right_value); +free_left_value: + ecma_fast_free_value (left_value); + } + +error: + ecma_fast_free_value (left_value); + ecma_fast_free_value (right_value); + + if (ECMA_IS_VALUE_ERROR (result)) + { + JERRY_ASSERT (jcontext_has_pending_exception ()); + ecma_value_t *stack_bottom_p = VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth; + + while (stack_top_p > stack_bottom_p) + { + ecma_value_t stack_item = *(--stack_top_p); + if (stack_item == ECMA_VALUE_RELEASE_LEX_ENV) + { + opfunc_pop_lexical_environment (frame_ctx_p); + continue; + } + + ecma_fast_free_value (stack_item); + } + +#if JERRY_VM_THROW + if (!(JERRY_CONTEXT (status_flags) & ECMA_STATUS_ERROR_THROWN)) + { + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_ERROR_THROWN; + + jerry_throw_cb_t vm_throw_callback_p = JERRY_CONTEXT (vm_throw_callback_p); + + if (vm_throw_callback_p != NULL) + { + vm_throw_callback_p (JERRY_CONTEXT (error_value), JERRY_CONTEXT (vm_throw_callback_user_p)); + } + } +#endif /* JERRY_VM_THROW */ + } + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + if (frame_ctx_p->context_depth == 0) + { + /* In most cases there is no context. */ + frame_ctx_p->call_operation = VM_NO_EXEC_OP; + return result; + } + + if (!ECMA_IS_VALUE_ERROR (result)) + { + switch (vm_stack_find_finally (frame_ctx_p, stack_top_p, VM_CONTEXT_FINALLY_RETURN, 0)) + { + case VM_CONTEXT_FOUND_FINALLY: + { + stack_top_p = frame_ctx_p->stack_top_p; + byte_code_p = frame_ctx_p->byte_code_p; + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_RETURN); + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + stack_top_p[-2] = result; + continue; + } + case VM_CONTEXT_FOUND_ERROR: + { + JERRY_ASSERT (jcontext_has_pending_exception ()); + + ecma_free_value (result); + stack_top_p = frame_ctx_p->stack_top_p; + result = ECMA_VALUE_ERROR; + break; + } + case VM_CONTEXT_FOUND_AWAIT: + { + stack_top_p = frame_ctx_p->stack_top_p; + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_RETURN); + stack_top_p[-2] = result; + return ECMA_VALUE_UNDEFINED; + } + default: + { + goto finish; + } + } + } + + JERRY_ASSERT (jcontext_has_pending_exception ()); + + if (!jcontext_has_pending_abort ()) + { + switch (vm_stack_find_finally (frame_ctx_p, stack_top_p, VM_CONTEXT_FINALLY_THROW, 0)) + { + case VM_CONTEXT_FOUND_FINALLY: + { + stack_top_p = frame_ctx_p->stack_top_p; + byte_code_p = frame_ctx_p->byte_code_p; + + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + JERRY_ASSERT (!(stack_top_p[-1] & VM_CONTEXT_HAS_LEX_ENV)); + + result = jcontext_take_exception (); + + if (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_THROW) + { + stack_top_p[-2] = result; + continue; + } + + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_CATCH); + + *stack_top_p++ = result; + continue; + } + case VM_CONTEXT_FOUND_AWAIT: + { + JERRY_ASSERT (VM_GET_CONTEXT_TYPE (frame_ctx_p->stack_top_p[-1]) == VM_CONTEXT_FINALLY_THROW); + return ECMA_VALUE_UNDEFINED; + } + default: + { + break; + } + } + } + else + { + do + { + JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p); + + stack_top_p = vm_stack_context_abort (frame_ctx_p, stack_top_p); + } while (frame_ctx_p->context_depth > 0); + } + +finish: + frame_ctx_p->call_operation = VM_NO_EXEC_OP; + return result; + } +} /* vm_loop */ + +#if JERRY_MODULE_SYSTEM + +/** + * Create and initialize module scope with all data properties + * + * @return ECMA_VALUE_EMPTY on success, + * ECMA_VALUE_ERROR on failure + */ +ecma_value_t +vm_init_module_scope (ecma_module_t *module_p) /**< module without scope */ +{ + ecma_object_t *global_object_p; +#if JERRY_BUILTIN_REALMS + global_object_p = (ecma_object_t *) ecma_op_function_get_realm (module_p->u.compiled_code_p); +#else /* !JERRY_BUILTIN_REALMS */ + global_object_p = ecma_builtin_get_global (); +#endif /* JERRY_BUILTIN_REALMS */ + + ecma_object_t *scope_p = ecma_create_lex_env_class (ecma_get_global_environment (global_object_p), + sizeof (ecma_lexical_environment_class_t)); + const ecma_compiled_code_t *compiled_code_p = module_p->u.compiled_code_p; + ecma_value_t *literal_start_p; + uint8_t *byte_code_p; + uint16_t encoding_limit; + uint16_t encoding_delta; + + ((ecma_lexical_environment_class_t *) scope_p)->object_p = (ecma_object_t *) module_p; + ((ecma_lexical_environment_class_t *) scope_p)->type = ECMA_LEX_ENV_CLASS_TYPE_MODULE; + + module_p->scope_p = scope_p; + ecma_deref_object (scope_p); + + if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p; + + literal_start_p = (ecma_value_t *) (args_p + 1); + literal_start_p -= args_p->register_end; + byte_code_p = (uint8_t *) (literal_start_p + args_p->literal_end); + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p; + + literal_start_p = (ecma_value_t *) (args_p + 1); + literal_start_p -= args_p->register_end; + byte_code_p = (uint8_t *) (literal_start_p + args_p->literal_end); + } + + /* Prepare for byte code execution. */ + if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING)) + { + encoding_limit = CBC_SMALL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_SMALL_LITERAL_ENCODING_DELTA; + } + else + { + encoding_limit = CBC_FULL_LITERAL_ENCODING_LIMIT; + encoding_delta = CBC_FULL_LITERAL_ENCODING_DELTA; + } + + JERRY_ASSERT (*byte_code_p >= CBC_JUMP_FORWARD && *byte_code_p <= CBC_JUMP_FORWARD_3); + + byte_code_p += 1 + CBC_BRANCH_OFFSET_LENGTH (*byte_code_p); + + while (true) + { + uint8_t opcode = *byte_code_p++; + + switch (opcode) + { + case CBC_CREATE_VAR: + case CBC_CREATE_LET: + case CBC_CREATE_CONST: + { + uint32_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + JERRY_ASSERT (ecma_find_named_property (scope_p, name_p) == NULL); + + uint8_t prop_attributes = ECMA_PROPERTY_FLAG_WRITABLE; + + if (opcode == CBC_CREATE_LET) + { + prop_attributes = ECMA_PROPERTY_ENUMERABLE_WRITABLE; + } + else if (opcode == CBC_CREATE_CONST) + { + prop_attributes = ECMA_PROPERTY_FLAG_ENUMERABLE; + } + + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (scope_p, name_p, prop_attributes, NULL); + + if (opcode != CBC_CREATE_VAR) + { + property_value_p->value = ECMA_VALUE_UNINITIALIZED; + } + break; + } + case CBC_INIT_ARG_OR_FUNC: + { + uint32_t literal_index; + + READ_LITERAL_INDEX (literal_index); + + ecma_compiled_code_t *function_bytecode_p; +#if JERRY_SNAPSHOT_EXEC + if (JERRY_LIKELY (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))) + { +#endif /* JERRY_SNAPSHOT_EXEC */ + function_bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, literal_start_p[literal_index]); +#if JERRY_SNAPSHOT_EXEC + } + else + { + uint8_t *byte_p = ((uint8_t *) compiled_code_p) + literal_start_p[literal_index]; + function_bytecode_p = (ecma_compiled_code_t *) byte_p; + } +#endif /* JERRY_SNAPSHOT_EXEC */ + + JERRY_ASSERT (CBC_IS_FUNCTION (function_bytecode_p->status_flags)); + + ecma_object_t *function_obj_p; + + if (JERRY_UNLIKELY (CBC_FUNCTION_IS_ARROW (function_bytecode_p->status_flags))) + { + function_obj_p = ecma_op_create_arrow_function_object (scope_p, function_bytecode_p, ECMA_VALUE_UNDEFINED); + } + else + { + function_obj_p = ecma_op_create_any_function_object (scope_p, function_bytecode_p); + } + + READ_LITERAL_INDEX (literal_index); + ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]); + + JERRY_ASSERT (ecma_find_named_property (scope_p, name_p) == NULL); + + ecma_property_value_t *property_value_p; + property_value_p = ecma_create_named_data_property (scope_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL); + + JERRY_ASSERT (property_value_p->value == ECMA_VALUE_UNDEFINED); + property_value_p->value = ecma_make_object_value (function_obj_p); + ecma_deref_object (function_obj_p); + break; + } + default: + { + JERRY_ASSERT (opcode == CBC_RETURN_FUNCTION_END); + return ECMA_VALUE_EMPTY; + } + } + } +} /* vm_init_module_scope */ + +#endif /* JERRY_MODULE_SYSTEM */ + +#undef READ_LITERAL +#undef READ_LITERAL_INDEX + +JERRY_STATIC_ASSERT (((int)VM_FRAME_CTX_SHARED_DIRECT_EVAL == (int)VM_FRAME_CTX_DIRECT_EVAL), + vm_frame_ctx_shared_direct_eval_must_be_equal_to_frame_ctx_direct_eval); + +JERRY_STATIC_ASSERT (((int)CBC_CODE_FLAGS_STRICT_MODE == (int)VM_FRAME_CTX_IS_STRICT), + cbc_code_flags_strict_mode_must_be_equal_to_vm_frame_ctx_is_strict); + +/** + * Initialize code block execution + * + * @return ECMA_VALUE_ERROR - if the initialization fails + * ECMA_VALUE_EMPTY - otherwise + */ +static void JERRY_ATTR_NOINLINE +vm_init_exec (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + vm_frame_ctx_shared_t *shared_p = frame_ctx_p->shared_p; + const ecma_compiled_code_t *bytecode_header_p = shared_p->bytecode_header_p; + + frame_ctx_p->prev_context_p = JERRY_CONTEXT (vm_top_context_p); + frame_ctx_p->context_depth = 0; + frame_ctx_p->status_flags = (uint8_t) ((shared_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL) + | (bytecode_header_p->status_flags & VM_FRAME_CTX_IS_STRICT)); + + uint16_t argument_end, register_end; + ecma_value_t *literal_p; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + + argument_end = args_p->argument_end; + register_end = args_p->register_end; + + literal_p = (ecma_value_t *) (args_p + 1); + literal_p -= register_end; + frame_ctx_p->literal_start_p = literal_p; + literal_p += args_p->literal_end; + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + + argument_end = args_p->argument_end; + register_end = args_p->register_end; + + literal_p = (ecma_value_t *) (args_p + 1); + literal_p -= register_end; + frame_ctx_p->literal_start_p = literal_p; + literal_p += args_p->literal_end; + } + + frame_ctx_p->byte_code_p = (uint8_t *) literal_p; + frame_ctx_p->byte_code_start_p = (uint8_t *) literal_p; + frame_ctx_p->stack_top_p = VM_GET_REGISTERS (frame_ctx_p) + register_end; + + uint32_t arg_list_len = 0; + + if (argument_end > 0) + { + JERRY_ASSERT (shared_p->status_flags & VM_FRAME_CTX_SHARED_HAS_ARG_LIST); + + const ecma_value_t *arg_list_p = ((vm_frame_ctx_shared_args_t *) shared_p)->arg_list_p; + arg_list_len = ((vm_frame_ctx_shared_args_t *) shared_p)->arg_list_len; + + if (arg_list_len > argument_end) + { + arg_list_len = argument_end; + } + + for (uint32_t i = 0; i < arg_list_len; i++) + { + VM_GET_REGISTER (frame_ctx_p, i) = ecma_fast_copy_value (arg_list_p[i]); + } + } + + /* The arg_list_len contains the end of the copied arguments. + * Fill everything else with undefined. */ + if (register_end > arg_list_len) + { + ecma_value_t *stack_p = VM_GET_REGISTERS (frame_ctx_p) + arg_list_len; + + for (uint32_t i = arg_list_len; i < register_end; i++) + { + *stack_p++ = ECMA_VALUE_UNDEFINED; + } + } + + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_DIRECT_EVAL; + JERRY_CONTEXT (vm_top_context_p) = frame_ctx_p; +} /* vm_init_exec */ + +/** + * Resume execution of a code block. + * + * @return ecma value + */ +ecma_value_t JERRY_ATTR_NOINLINE +vm_execute (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ +{ + while (true) + { + ecma_value_t completion_value = vm_loop (frame_ctx_p); + + switch (frame_ctx_p->call_operation) + { + case VM_EXEC_CALL: + { + opfunc_call (frame_ctx_p); + break; + } + case VM_EXEC_SUPER_CALL: + { + vm_super_call (frame_ctx_p); + break; + } + case VM_EXEC_SPREAD_OP: + { + vm_spread_operation (frame_ctx_p); + break; + } + case VM_EXEC_RETURN: + { + return completion_value; + } + case VM_EXEC_CONSTRUCT: + { + opfunc_construct (frame_ctx_p); + break; + } + default: + { + JERRY_ASSERT (frame_ctx_p->call_operation == VM_NO_EXEC_OP); + + const ecma_compiled_code_t *bytecode_header_p = frame_ctx_p->shared_p->bytecode_header_p; + uint32_t register_end; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + register_end = ((cbc_uint16_arguments_t *) bytecode_header_p)->register_end; + } + else + { + register_end = ((cbc_uint8_arguments_t *) bytecode_header_p)->register_end; + } + + /* Free arguments and registers */ + ecma_value_t *registers_p = VM_GET_REGISTERS (frame_ctx_p); + for (uint32_t i = 0; i < register_end; i++) + { + ecma_fast_free_value (registers_p[i]); + } + JERRY_CONTEXT (vm_top_context_p) = frame_ctx_p->prev_context_p; + return completion_value; + } + } + } +} /* vm_execute */ + +/** + * Run the code. + * + * @return ecma value + */ +ecma_value_t +vm_run (vm_frame_ctx_shared_t *shared_p, /**< shared data */ + ecma_value_t this_binding_value, /**< value of 'ThisBinding' */ + ecma_object_t *lex_env_p) /**< lexical environment to use */ +{ + const ecma_compiled_code_t *bytecode_header_p = shared_p->bytecode_header_p; + vm_frame_ctx_t *frame_ctx_p; + size_t frame_size; + + if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS) + { + cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p; + frame_size = (size_t) (args_p->register_end + args_p->stack_limit); + } + else + { + cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p; + frame_size = (size_t) (args_p->register_end + args_p->stack_limit); + } + + JERRY_VLA (ecma_value_t, stack, frame_size + (sizeof (vm_frame_ctx_t) / sizeof (ecma_value_t))); + + frame_ctx_p = (vm_frame_ctx_t *) stack; + + frame_ctx_p->shared_p = shared_p; + frame_ctx_p->lex_env_p = lex_env_p; + frame_ctx_p->this_binding = this_binding_value; + + vm_init_exec (frame_ctx_p); + return vm_execute (frame_ctx_p); +} /* vm_run */ + +/** + * @} + * @} + */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm.h b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm.h new file mode 100644 index 0000000..c3f9a5b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/jerry-core/vm/vm.h @@ -0,0 +1,426 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VM_H +#define VM_H + +#include "ecma-globals.h" +#include "ecma-module.h" + +#include "jrt.h" +#include "vm-defines.h" + +/** \addtogroup vm Virtual machine + * @{ + * + * \addtogroup vm_executor Executor + * @{ + */ + +/** + * Each CBC opcode is transformed to three vm opcodes: + * + * - first opcode is a "get arguments" opcode which specifies + * the type (register, literal, stack, etc.) and number + * (from 0 to 2) of input arguments + * - second opcode is a "group" opcode which specifies + * the actual operation (add, increment, call, etc.) + * - third opcode is a "put result" opcode which specifies + * the destination where the result is stored (register, + * stack, etc.) + */ + +/** + * If VM_OC_GET_ARGS_INDEX(opcode) == VM_OC_GET_BRANCH, + * this flag signals that the branch is a backward branch. + */ +#define VM_OC_BACKWARD_BRANCH (1 << 15) + +/** + * Position of "get arguments" opcode. + */ +#define VM_OC_GET_ARGS_SHIFT 8 + +/** + * Mask of "get arguments" opcode. + */ +#define VM_OC_GET_ARGS_MASK 0x7 + +/** + * Generate the binary representation of a "get arguments" opcode. + */ +#define VM_OC_GET_ARGS_CREATE_INDEX(V) (((V) &VM_OC_GET_ARGS_MASK) << VM_OC_GET_ARGS_SHIFT) + +/** + * Extract the "get arguments" opcode. + */ +#define VM_OC_GET_ARGS_INDEX(O) ((O) & (VM_OC_GET_ARGS_MASK << VM_OC_GET_ARGS_SHIFT)) + +/** + * Checks whether the result is stored somewhere. + */ +#define VM_OC_HAS_GET_ARGS(V) ((V) & (VM_OC_GET_ARGS_MASK << VM_OC_GET_ARGS_SHIFT)) + +/** + * Argument getters that are part of the opcodes. + */ +typedef enum +{ + VM_OC_GET_NONE = VM_OC_GET_ARGS_CREATE_INDEX (0), /**< do nothing */ + VM_OC_GET_BRANCH = VM_OC_GET_ARGS_CREATE_INDEX (1), /**< branch argument */ + VM_OC_GET_STACK = VM_OC_GET_ARGS_CREATE_INDEX (2), /**< pop one element from the stack */ + VM_OC_GET_STACK_STACK = VM_OC_GET_ARGS_CREATE_INDEX (3), /**< pop two elements from the stack */ + + VM_OC_GET_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (4), /**< resolve literal */ + VM_OC_GET_LITERAL_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (5), /**< resolve two literals */ + VM_OC_GET_STACK_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (6), /**< pop one element from the stack + * and resolve a literal */ + VM_OC_GET_THIS_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (7), /**< get this and resolve a literal */ +} vm_oc_get_types; + +/** + * Mask of "group" opcode. + */ +#define VM_OC_GROUP_MASK 0xff + +/** + * Extract the "group" opcode. + */ +#define VM_OC_GROUP_GET_INDEX(O) ((O) &VM_OC_GROUP_MASK) + +/** + * Opcodes. + */ +typedef enum +{ + VM_OC_POP, /**< pop from stack */ + VM_OC_POP_BLOCK, /**< pop block */ + VM_OC_PUSH, /**< push one literal */ + VM_OC_PUSH_TWO, /**< push two literals */ + VM_OC_PUSH_THREE, /**< push three literals */ + VM_OC_PUSH_UNDEFINED, /**< push undefined value */ + VM_OC_PUSH_TRUE, /**< push true value */ + VM_OC_PUSH_FALSE, /**< push false value */ + VM_OC_PUSH_NULL, /**< push null value */ + VM_OC_PUSH_THIS, /**< push this */ + VM_OC_PUSH_0, /**< push number zero */ + VM_OC_PUSH_POS_BYTE, /**< push number between 1 and 256 */ + VM_OC_PUSH_NEG_BYTE, /**< push number between -1 and -256 */ + VM_OC_PUSH_LIT_0, /**< push literal and number zero */ + VM_OC_PUSH_LIT_POS_BYTE, /**< push literal and number between 1 and 256 */ + VM_OC_PUSH_LIT_NEG_BYTE, /**< push literal and number between -1 and -256 */ + VM_OC_PUSH_OBJECT, /**< push object */ + VM_OC_PUSH_NAMED_FUNC_EXPR, /**< push named function expression */ + VM_OC_SET_PROPERTY, /**< set property */ + + VM_OC_SET_GETTER, /**< set getter */ + VM_OC_SET_SETTER, /**< set setter */ + VM_OC_PUSH_ARRAY, /**< push array */ + VM_OC_PUSH_ELISON, /**< push elison */ + VM_OC_APPEND_ARRAY, /**< append array */ + VM_OC_IDENT_REFERENCE, /**< ident reference */ + VM_OC_PROP_REFERENCE, /**< prop reference */ + VM_OC_PROP_GET, /**< prop get */ + + /* These eight opcodes must be in this order. */ + VM_OC_PROP_PRE_INCR, /**< prefix increment of a property */ + VM_OC_PROP_PRE_DECR, /**< prop prefix decrement of a property */ + VM_OC_PROP_POST_INCR, /**< prop postfix increment of a property */ + VM_OC_PROP_POST_DECR, /**< prop postfix decrement of a property */ + VM_OC_PRE_INCR, /**< prefix increment */ + VM_OC_PRE_DECR, /**< prefix decrement */ + VM_OC_POST_INCR, /**< postfix increment */ + VM_OC_POST_DECR, /**< postfix decrement */ + + VM_OC_PROP_DELETE, /**< delete property */ + VM_OC_DELETE, /**< delete */ + + VM_OC_MOV_IDENT, /**< move identifier register reference */ + VM_OC_ASSIGN, /**< assign */ + VM_OC_ASSIGN_PROP, /**< assign property */ + VM_OC_ASSIGN_PROP_THIS, /**< assign prop this */ + + VM_OC_RETURN, /**< return */ + VM_OC_RETURN_FUNCTION_END, /**< return at the end of a function/script */ + VM_OC_THROW, /**< throw */ + VM_OC_THROW_REFERENCE_ERROR, /**< throw reference error */ + + VM_OC_EVAL, /**< eval */ + VM_OC_CALL, /**< call */ + VM_OC_NEW, /**< new */ + VM_OC_RESOLVE_BASE_FOR_CALL, /**< resolve base value before call */ + VM_OC_ERROR, /**< error while the vm_loop is suspended */ + + VM_OC_JUMP, /**< jump */ + VM_OC_BRANCH_IF_NULLISH, /** branch if undefined or null */ + VM_OC_POP_REFERENCE, /** prop identifier or property reference from the stack */ + VM_OC_BRANCH_IF_STRICT_EQUAL, /**< branch if strict equal */ + + /* These four opcodes must be in this order. */ + VM_OC_BRANCH_IF_TRUE, /**< branch if true */ + VM_OC_BRANCH_IF_FALSE, /**< branch if false */ + VM_OC_BRANCH_IF_LOGICAL_TRUE, /**< branch if logical true */ + VM_OC_BRANCH_IF_LOGICAL_FALSE, /**< branch if logical false */ + + VM_OC_PLUS, /**< unary plus */ + VM_OC_MINUS, /**< unary minus */ + VM_OC_NOT, /**< not */ + VM_OC_BIT_NOT, /**< bitwise not */ + VM_OC_VOID, /**< void */ + VM_OC_TYPEOF_IDENT, /**< typeof identifier */ + VM_OC_TYPEOF, /**< typeof */ + + VM_OC_ADD, /**< binary add */ + VM_OC_SUB, /**< binary sub */ + VM_OC_MUL, /**< mul */ + VM_OC_DIV, /**< div */ + VM_OC_MOD, /**< mod */ + VM_OC_EXP, /**< exponentiation */ + + VM_OC_EQUAL, /**< equal */ + VM_OC_NOT_EQUAL, /**< not equal */ + VM_OC_STRICT_EQUAL, /**< strict equal */ + VM_OC_STRICT_NOT_EQUAL, /**< strict not equal */ + VM_OC_LESS, /**< less */ + VM_OC_GREATER, /**< greater */ + VM_OC_LESS_EQUAL, /**< less equal */ + VM_OC_GREATER_EQUAL, /**< greater equal */ + VM_OC_IN, /**< in */ + VM_OC_INSTANCEOF, /**< instanceof */ + + VM_OC_BIT_OR, /**< bitwise or */ + VM_OC_BIT_XOR, /**< bitwise xor */ + VM_OC_BIT_AND, /**< bitwise and */ + VM_OC_LEFT_SHIFT, /**< left shift */ + VM_OC_RIGHT_SHIFT, /**< right shift */ + VM_OC_UNS_RIGHT_SHIFT, /**< unsigned right shift */ + + VM_OC_BLOCK_CREATE_CONTEXT, /**< create lexical environment for blocks enclosed in braces */ + VM_OC_WITH, /**< with */ + VM_OC_FOR_IN_INIT, /**< for-in init context */ + VM_OC_FOR_IN_GET_NEXT, /**< get next */ + VM_OC_FOR_IN_HAS_NEXT, /**< has next */ + + VM_OC_TRY, /**< try */ + VM_OC_CATCH, /**< catch */ + VM_OC_FINALLY, /**< finally */ + VM_OC_CONTEXT_END, /**< context end */ + VM_OC_JUMP_AND_EXIT_CONTEXT, /**< jump and exit context */ + + VM_OC_CREATE_BINDING, /**< create variables */ + VM_OC_CREATE_ARGUMENTS, /**< create arguments object */ + VM_OC_SET_BYTECODE_PTR, /**< setting bytecode pointer */ + VM_OC_VAR_EVAL, /**< variable and function evaluation */ + VM_OC_EXT_VAR_EVAL, /**< variable and function evaluation for + * functions with separate argument context */ + VM_OC_INIT_ARG_OR_FUNC, /**< create and init a function or argument binding */ + + VM_OC_CLASS_CALL_STATIC_BLOCK, /**< call the class static block */ + VM_OC_DEFINE_FIELD, /**< define class field */ + VM_OC_PRIVATE_PROP_REFERENCE, /**< reference to class private method */ + VM_OC_ASSIGN_PRIVATE, /**< assign to private field */ + VM_OC_PRIVATE_FIELD_ADD, /**< add private field */ + VM_OC_PRIVATE_PROP_GET, /**< get private field */ + VM_OC_PRIVATE_IN, /**< 'in' opcode handler for private identifiers */ + VM_OC_COLLECT_PRIVATE_PROPERTY, /**< collect private properties */ + VM_OC_CHECK_VAR, /**< check redeclared vars in the global scope */ + VM_OC_CHECK_LET, /**< check redeclared lets in the global scope */ + VM_OC_ASSIGN_LET_CONST, /**< assign values to let/const declarations */ + VM_OC_INIT_BINDING, /**< create and initialize a binding */ + VM_OC_THROW_CONST_ERROR, /**< throw invalid assignment to const variable error */ + VM_OC_COPY_TO_GLOBAL, /**< copy value to global lex env */ + VM_OC_COPY_FROM_ARG, /**< copy value from arg lex env */ + VM_OC_CLONE_CONTEXT, /**< clone lexical environment with let/const declarations */ + VM_OC_COPY_DATA_PROPERTIES, /**< copy data properties of an object */ + VM_OC_SET_COMPUTED_PROPERTY, /**< set computed property */ + + VM_OC_FOR_OF_INIT, /**< for-of init context */ + VM_OC_FOR_OF_GET_NEXT, /**< for-of get next */ + VM_OC_FOR_OF_HAS_NEXT, /**< for-of has next */ + VM_OC_FOR_AWAIT_OF_INIT, /**< for-await-of init context */ + VM_OC_FOR_AWAIT_OF_HAS_NEXT, /**< for-await-of has next */ + + VM_OC_LOCAL_EVAL, /**< eval in local context */ + VM_OC_SUPER_CALL, /**< call the 'super' constructor */ + VM_OC_PUSH_CLASS_ENVIRONMENT, /**< push class environment */ + VM_OC_PUSH_IMPLICIT_CTOR, /**< create implicit class constructor */ + VM_OC_INIT_CLASS, /**< initialize class */ + VM_OC_FINALIZE_CLASS, /**< finalize class */ + VM_OC_SET_FIELD_INIT, /**< store the class field initializer function */ + VM_OC_SET_STATIC_FIELD_INIT, /**< store the static class field initializer function */ + VM_OC_RUN_FIELD_INIT, /**< run the class field initializer function */ + VM_OC_RUN_STATIC_FIELD_INIT, /**< run the static class field initializer function */ + VM_OC_SET_NEXT_COMPUTED_FIELD, /**< set the next computed field of a class */ + VM_OC_PUSH_SUPER_CONSTRUCTOR, /**< getSuperConstructor operation */ + VM_OC_RESOLVE_LEXICAL_THIS, /**< resolve this_binding from the lexical environment */ + VM_OC_SUPER_REFERENCE, /**< push super reference */ + VM_OC_SET_HOME_OBJECT, /**< set the [[HomeObject]] environment in an object literal */ + VM_OC_OBJECT_LITERAL_HOME_ENV, /**< create/destroy [[HomeObject]] environment of an object literal */ + VM_OC_SET_FUNCTION_NAME, /**< set function name property */ + + VM_OC_PUSH_SPREAD_ELEMENT, /**< push spread element */ + VM_OC_PUSH_REST_OBJECT, /**< push rest object */ + VM_OC_ITERATOR_CONTEXT_CREATE, /**< create iterator context */ + VM_OC_ITERATOR_CONTEXT_END, /**< finalize iterator context */ + VM_OC_ITERATOR_STEP, /**< IteratorStep abstract operation */ + VM_OC_OBJ_INIT_CONTEXT_CREATE, /**< create object initializer context */ + VM_OC_OBJ_INIT_CONTEXT_END, /**< finalize object initializer context */ + VM_OC_OBJ_INIT_PUSH_REST, /**< push the object with the rest properties */ + VM_OC_INITIALIZER_PUSH_NAME, /**< append string to name list array and push the string */ + VM_OC_DEFAULT_INITIALIZER, /**< default initializer inside a pattern */ + VM_OC_REST_INITIALIZER, /**< create rest object inside an array pattern */ + VM_OC_INITIALIZER_PUSH_PROP, /**< push property for object initializer */ + VM_OC_SPREAD_ARGUMENTS, /**< perform function call/construct with spread arguments */ + VM_OC_CREATE_GENERATOR, /**< create a generator object */ + VM_OC_YIELD, /**< yield operation */ + VM_OC_ASYNC_YIELD, /**< async yield operation */ + VM_OC_ASYNC_YIELD_ITERATOR, /**< async yield iterator operation */ + VM_OC_AWAIT, /**< await operation */ + VM_OC_GENERATOR_AWAIT, /**< generator await operation */ + VM_OC_EXT_RETURN, /**< return which also clears the stack */ + VM_OC_ASYNC_EXIT, /**< return from async function */ + VM_OC_STRING_CONCAT, /**< string concatenation */ + VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */ + VM_OC_PUSH_NEW_TARGET, /**< push new.target onto the stack */ + VM_OC_REQUIRE_OBJECT_COERCIBLE, /**< RequireObjectCoercible operation */ + VM_OC_ASSIGN_SUPER, /**< assign super reference */ + VM_OC_SET__PROTO__, /**< set prototype when __proto__: form is used */ + VM_OC_PUSH_STATIC_FIELD_FUNC, /**< push static field initializer function */ + VM_OC_ADD_COMPUTED_FIELD, /**< add computed field name */ +#if JERRY_MODULE_SYSTEM + VM_OC_MODULE_IMPORT, /**< module dynamic import */ + VM_OC_MODULE_IMPORT_META, /**< module import.meta */ +#endif /* JERRY_MODULE_SYSTEM */ + + VM_OC_NONE, /**< a special opcode for unsupported byte codes */ +} vm_oc_types; + +/** + * Unused opcodes, but required by byte-code types. + */ +typedef enum +{ +#if !JERRY_MODULE_SYSTEM + VM_OC_MODULE_IMPORT = VM_OC_NONE, /**< module dynamic import */ + VM_OC_MODULE_IMPORT_META = VM_OC_NONE, /**< module import.meta */ +#endif /* JERRY_MODULE_SYSTEM */ + + VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */ +} vm_oc_unused_types; + +/** + * Decrement operator. + */ +#define VM_OC_DECREMENT_OPERATOR_FLAG 0x1 + +/** + * Postfix increment/decrement operator. + */ +#define VM_OC_POST_INCR_DECR_OPERATOR_FLAG 0x2 + +/** + * An named variable is updated by the increment/decrement operator. + */ +#define VM_OC_IDENT_INCR_DECR_OPERATOR_FLAG 0x4 + +/** + * Jump to target offset if input value is logical false. + */ +#define VM_OC_BRANCH_IF_FALSE_FLAG 0x1 + +/** + * Branch optimized for logical and/or opcodes. + */ +#define VM_OC_LOGICAL_BRANCH_FLAG 0x2 + +/** + * Bit index shift for non-static property initializers. + */ +#define VM_OC_NON_STATIC_SHIFT 15 + +/** + * This flag is set for static property initializers. + */ +#define VM_OC_NON_STATIC_FLAG (0x1 << VM_OC_NON_STATIC_SHIFT) + +/** + * Position of "put result" opcode. + */ +#define VM_OC_PUT_RESULT_SHIFT 11 + +/** + * Mask of "put result" opcode. + */ +#define VM_OC_PUT_RESULT_MASK 0xf + +/** + * Generate a "put result" opcode flag bit. + */ +#define VM_OC_PUT_RESULT_CREATE_FLAG(V) (((V) &VM_OC_PUT_RESULT_MASK) << VM_OC_PUT_RESULT_SHIFT) + +/** + * Checks whether the result is stored somewhere. + */ +#define VM_OC_HAS_PUT_RESULT(V) ((V) & (VM_OC_PUT_RESULT_MASK << VM_OC_PUT_RESULT_SHIFT)) + +/** + * Specify where the result is stored + */ +typedef enum +{ + VM_OC_PUT_IDENT = VM_OC_PUT_RESULT_CREATE_FLAG (0x1), + VM_OC_PUT_REFERENCE = VM_OC_PUT_RESULT_CREATE_FLAG (0x2), + VM_OC_PUT_STACK = VM_OC_PUT_RESULT_CREATE_FLAG (0x4), + VM_OC_PUT_BLOCK = VM_OC_PUT_RESULT_CREATE_FLAG (0x8), +} vm_oc_put_types; + +/** + * Non-recursive vm_loop: the vm_loop can be suspended + * to execute a call /construct operation. These return + * types of the vm_loop tells whether a call operation + * is in progress or the vm_loop is finished. + */ +typedef enum +{ + VM_NO_EXEC_OP, /**< do nothing */ + VM_EXEC_CALL, /**< invoke a function */ + VM_EXEC_SUPER_CALL, /**< invoke a function through 'super' keyword */ + VM_EXEC_SPREAD_OP, /**< call/construct operation with spread argument list */ + VM_EXEC_RETURN, /**< return with the completion value without freeing registers */ + VM_EXEC_CONSTRUCT, /**< construct a new object */ +} vm_call_operation; + +ecma_value_t vm_run_global (const ecma_compiled_code_t *bytecode_p, ecma_object_t *function_object_p); +ecma_value_t vm_run_eval (ecma_compiled_code_t *bytecode_data_p, uint32_t parse_opts); + +#if JERRY_MODULE_SYSTEM +ecma_value_t vm_run_module (ecma_module_t *module_p); +ecma_value_t vm_init_module_scope (ecma_module_t *module_p); +#endif /* JERRY_MODULE_SYSTEM */ + +ecma_value_t vm_run (vm_frame_ctx_shared_t *shared_p, ecma_value_t this_binding_value, ecma_object_t *lex_env_p); +ecma_value_t vm_execute (vm_frame_ctx_t *frame_ctx_p); + +bool vm_is_strict_mode (void); +bool vm_is_direct_eval_form_call (void); + +ecma_value_t vm_get_backtrace (uint32_t max_depth); + +/** + * @} + * @} + */ + +#endif /* !VM_H */ diff --git a/components/thorvg-main/src/loaders/lottie/jerryscript/meson.build b/components/thorvg-main/src/loaders/lottie/jerryscript/meson.build new file mode 100644 index 0000000..a8e063b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/jerryscript/meson.build @@ -0,0 +1 @@ +subdir('jerry-core') diff --git a/components/thorvg-main/src/loaders/lottie/meson.build b/components/thorvg-main/src/loaders/lottie/meson.build new file mode 100644 index 0000000..d6c077f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/meson.build @@ -0,0 +1,34 @@ +if lottie_exp + subdir('jerryscript') +endif + +source_file = [ + 'tvgLottieBuilder.h', + 'tvgLottieData.h', + 'tvgLottieExpressions.h', + 'tvgLottieInterpolator.h', + 'tvgLottieLoader.h', + 'tvgLottieModel.h', + 'tvgLottieModifier.h', + 'tvgLottieParser.h', + 'tvgLottieParserHandler.h', + 'tvgLottieProperty.h', + 'tvgLottieRenderPooler.h', + 'tvgLottieAnimation.cpp', + 'tvgLottieBuilder.cpp', + 'tvgLottieExpressions.cpp', + 'tvgLottieInterpolator.cpp', + 'tvgLottieLoader.cpp', + 'tvgLottieModel.cpp', + 'tvgLottieModifier.cpp', + 'tvgLottieParserHandler.cpp', + 'tvgLottieParser.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] + +install_headers('thorvg_lottie.h', subdir: 'thorvg-' + vmaj) +headers += include_directories('.') diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/allocators.h b/components/thorvg-main/src/loaders/lottie/rapidjson/allocators.h new file mode 100644 index 0000000..35650af --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/allocators.h @@ -0,0 +1,693 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ALLOCATORS_H_ +#define RAPIDJSON_ALLOCATORS_H_ + +#include "rapidjson.h" +#include "internal/meta.h" + +#include +#include + +#if RAPIDJSON_HAS_CXX11 +#include +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// Allocator + +/*! \class rapidjson::Allocator + \brief Concept for allocating, resizing and freeing memory block. + + Note that Malloc() and Realloc() are non-static but Free() is static. + + So if an allocator need to support Free(), it needs to put its pointer in + the header of memory block. + +\code +concept Allocator { + static const bool kNeedFree; //!< Whether this allocator needs to call Free(). + + // Allocate a memory block. + // \param size of the memory block in bytes. + // \returns pointer to the memory block. + void* Malloc(size_t size); + + // Resize a memory block. + // \param originalPtr The pointer to current memory block. Null pointer is permitted. + // \param originalSize The current size in bytes. (Design issue: since some allocator may not book-keep this, explicitly pass to it can save memory.) + // \param newSize the new size in bytes. + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize); + + // Free a memory block. + // \param pointer to the memory block. Null pointer is permitted. + static void Free(void *ptr); +}; +\endcode +*/ + + +/*! \def RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY + \ingroup RAPIDJSON_CONFIG + \brief User-defined kDefaultChunkCapacity definition. + + User can define this as any \c size that is a power of 2. +*/ + +#ifndef RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY +#define RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY (64 * 1024) +#endif + + +/////////////////////////////////////////////////////////////////////////////// +// CrtAllocator + +//! C-runtime library allocator. +/*! This class is just wrapper for standard C library memory routines. + \note implements Allocator concept +*/ +class CrtAllocator { +public: + static const bool kNeedFree = true; + void* Malloc(size_t size) { + if (size) // behavior of malloc(0) is implementation defined. + return RAPIDJSON_MALLOC(size); + else + return NULL; // standardize to returning NULL. + } + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { + (void)originalSize; + if (newSize == 0) { + RAPIDJSON_FREE(originalPtr); + return NULL; + } + return RAPIDJSON_REALLOC(originalPtr, newSize); + } + static void Free(void *ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); } + + bool operator==(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { + return true; + } + bool operator!=(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { + return false; + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// MemoryPoolAllocator + +//! Default memory allocator used by the parser and DOM. +/*! This allocator allocate memory blocks from pre-allocated memory chunks. + + It does not free memory blocks. And Realloc() only allocate new memory. + + The memory chunks are allocated by BaseAllocator, which is CrtAllocator by default. + + User may also supply a buffer as the first chunk. + + If the user-buffer is full then additional chunks are allocated by BaseAllocator. + + The user-buffer is not deallocated by this allocator. + + \tparam BaseAllocator the allocator type for allocating memory chunks. Default is CrtAllocator. + \note implements Allocator concept +*/ +template +class MemoryPoolAllocator { + //! Chunk header for perpending to each chunk. + /*! Chunks are stored as a singly linked list. + */ + struct ChunkHeader { + size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). + size_t size; //!< Current size of allocated memory in bytes. + ChunkHeader *next; //!< Next chunk in the linked list. + }; + + struct SharedData { + ChunkHeader *chunkHead; //!< Head of the chunk linked-list. Only the head chunk serves allocation. + BaseAllocator* ownBaseAllocator; //!< base allocator created by this object. + size_t refcount; + bool ownBuffer; + }; + + static const size_t SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData)); + static const size_t SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader)); + + static inline ChunkHeader *GetChunkHead(SharedData *shared) + { + return reinterpret_cast(reinterpret_cast(shared) + SIZEOF_SHARED_DATA); + } + static inline uint8_t *GetChunkBuffer(SharedData *shared) + { + return reinterpret_cast(shared->chunkHead) + SIZEOF_CHUNK_HEADER; + } + + static const size_t kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity. + +public: + static const bool kNeedFree = false; //!< Tell users that no need to call Free() with this allocator. (concept Allocator) + static const bool kRefCounted = true; //!< Tell users that this allocator is reference counted on copy + + //! Constructor with chunkSize. + /*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. + \param baseAllocator The allocator for allocating memory chunks. + */ + explicit + MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : + chunk_capacity_(chunkSize), + baseAllocator_(baseAllocator ? baseAllocator : RAPIDJSON_NEW(BaseAllocator)()), + shared_(static_cast(baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER) : 0)) + { + RAPIDJSON_ASSERT(baseAllocator_ != 0); + RAPIDJSON_ASSERT(shared_ != 0); + if (baseAllocator) { + shared_->ownBaseAllocator = 0; + } + else { + shared_->ownBaseAllocator = baseAllocator_; + } + shared_->chunkHead = GetChunkHead(shared_); + shared_->chunkHead->capacity = 0; + shared_->chunkHead->size = 0; + shared_->chunkHead->next = 0; + shared_->ownBuffer = true; + shared_->refcount = 1; + } + + //! Constructor with user-supplied buffer. + /*! The user buffer will be used firstly. When it is full, memory pool allocates new chunk with chunk size. + + The user buffer will not be deallocated when this allocator is destructed. + + \param buffer User supplied buffer. + \param size Size of the buffer in bytes. It must at least larger than sizeof(ChunkHeader). + \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. + \param baseAllocator The allocator for allocating memory chunks. + */ + MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : + chunk_capacity_(chunkSize), + baseAllocator_(baseAllocator), + shared_(static_cast(AlignBuffer(buffer, size))) + { + RAPIDJSON_ASSERT(size >= SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER); + shared_->chunkHead = GetChunkHead(shared_); + shared_->chunkHead->capacity = size - SIZEOF_SHARED_DATA - SIZEOF_CHUNK_HEADER; + shared_->chunkHead->size = 0; + shared_->chunkHead->next = 0; + shared_->ownBaseAllocator = 0; + shared_->ownBuffer = false; + shared_->refcount = 1; + } + + MemoryPoolAllocator(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT : + chunk_capacity_(rhs.chunk_capacity_), + baseAllocator_(rhs.baseAllocator_), + shared_(rhs.shared_) + { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + ++shared_->refcount; + } + MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + ++rhs.shared_->refcount; + this->~MemoryPoolAllocator(); + baseAllocator_ = rhs.baseAllocator_; + chunk_capacity_ = rhs.chunk_capacity_; + shared_ = rhs.shared_; + return *this; + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + MemoryPoolAllocator(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT : + chunk_capacity_(rhs.chunk_capacity_), + baseAllocator_(rhs.baseAllocator_), + shared_(rhs.shared_) + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + rhs.shared_ = 0; + } + MemoryPoolAllocator& operator=(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT + { + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + this->~MemoryPoolAllocator(); + baseAllocator_ = rhs.baseAllocator_; + chunk_capacity_ = rhs.chunk_capacity_; + shared_ = rhs.shared_; + rhs.shared_ = 0; + return *this; + } +#endif + + //! Destructor. + /*! This deallocates all memory chunks, excluding the user-supplied buffer. + */ + ~MemoryPoolAllocator() RAPIDJSON_NOEXCEPT { + if (!shared_) { + // do nothing if moved + return; + } + if (shared_->refcount > 1) { + --shared_->refcount; + return; + } + Clear(); + BaseAllocator *a = shared_->ownBaseAllocator; + if (shared_->ownBuffer) { + baseAllocator_->Free(shared_); + } + RAPIDJSON_DELETE(a); + } + + //! Deallocates all memory chunks, excluding the first/user one. + void Clear() RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + for (;;) { + ChunkHeader* c = shared_->chunkHead; + if (!c->next) { + break; + } + shared_->chunkHead = c->next; + baseAllocator_->Free(c); + } + shared_->chunkHead->size = 0; + } + + //! Computes the total capacity of allocated memory chunks. + /*! \return total capacity in bytes. + */ + size_t Capacity() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + size_t capacity = 0; + for (ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next) + capacity += c->capacity; + return capacity; + } + + //! Computes the memory blocks allocated. + /*! \return total used bytes. + */ + size_t Size() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + size_t size = 0; + for (ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next) + size += c->size; + return size; + } + + //! Whether the allocator is shared. + /*! \return true or false. + */ + bool Shared() const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + return shared_->refcount > 1; + } + + //! Allocates a memory block. (concept Allocator) + void* Malloc(size_t size) { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + if (!size) + return NULL; + + size = RAPIDJSON_ALIGN(size); + if (RAPIDJSON_UNLIKELY(shared_->chunkHead->size + size > shared_->chunkHead->capacity)) + if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size)) + return NULL; + + void *buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size; + shared_->chunkHead->size += size; + return buffer; + } + + //! Resizes a memory block (concept Allocator) + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { + if (originalPtr == 0) + return Malloc(newSize); + + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + if (newSize == 0) + return NULL; + + originalSize = RAPIDJSON_ALIGN(originalSize); + newSize = RAPIDJSON_ALIGN(newSize); + + // Do not shrink if new size is smaller than original + if (originalSize >= newSize) + return originalPtr; + + // Simply expand it if it is the last allocation and there is sufficient space + if (originalPtr == GetChunkBuffer(shared_) + shared_->chunkHead->size - originalSize) { + size_t increment = static_cast(newSize - originalSize); + if (shared_->chunkHead->size + increment <= shared_->chunkHead->capacity) { + shared_->chunkHead->size += increment; + return originalPtr; + } + } + + // Realloc process: allocate and copy memory, do not free original buffer. + if (void* newBuffer = Malloc(newSize)) { + if (originalSize) + std::memcpy(newBuffer, originalPtr, originalSize); + return newBuffer; + } + else + return NULL; + } + + //! Frees a memory block (concept Allocator) + static void Free(void *ptr) RAPIDJSON_NOEXCEPT { (void)ptr; } // Do nothing + + //! Compare (equality) with another MemoryPoolAllocator + bool operator==(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT { + RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0); + RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0); + return shared_ == rhs.shared_; + } + //! Compare (inequality) with another MemoryPoolAllocator + bool operator!=(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT { + return !operator==(rhs); + } + +private: + //! Creates a new chunk. + /*! \param capacity Capacity of the chunk in bytes. + \return true if success. + */ + bool AddChunk(size_t capacity) { + if (!baseAllocator_) + shared_->ownBaseAllocator = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); + if (ChunkHeader* chunk = static_cast(baseAllocator_->Malloc(SIZEOF_CHUNK_HEADER + capacity))) { + chunk->capacity = capacity; + chunk->size = 0; + chunk->next = shared_->chunkHead; + shared_->chunkHead = chunk; + return true; + } + else + return false; + } + + static inline void* AlignBuffer(void* buf, size_t &size) + { + RAPIDJSON_NOEXCEPT_ASSERT(buf != 0); + const uintptr_t mask = sizeof(void*) - 1; + const uintptr_t ubuf = reinterpret_cast(buf); + if (RAPIDJSON_UNLIKELY(ubuf & mask)) { + const uintptr_t abuf = (ubuf + mask) & ~mask; + RAPIDJSON_ASSERT(size >= abuf - ubuf); + buf = reinterpret_cast(abuf); + size -= abuf - ubuf; + } + return buf; + } + + size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated. + BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks. + SharedData *shared_; //!< The shared data of the allocator +}; + +namespace internal { + template + struct IsRefCounted : + public FalseType + { }; + template + struct IsRefCounted::Type> : + public TrueType + { }; +} + +template +inline T* Realloc(A& a, T* old_p, size_t old_n, size_t new_n) +{ + RAPIDJSON_NOEXCEPT_ASSERT(old_n <= (std::numeric_limits::max)() / sizeof(T) && new_n <= (std::numeric_limits::max)() / sizeof(T)); + return static_cast(a.Realloc(old_p, old_n * sizeof(T), new_n * sizeof(T))); +} + +template +inline T *Malloc(A& a, size_t n = 1) +{ + return Realloc(a, NULL, 0, n); +} + +template +inline void Free(A& a, T *p, size_t n = 1) +{ + static_cast(Realloc(a, p, n, 0)); +} + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) // std::allocator can safely be inherited +#endif + +template +class StdAllocator : + public std::allocator +{ + typedef std::allocator allocator_type; +#if RAPIDJSON_HAS_CXX11 + typedef std::allocator_traits traits_type; +#else + typedef allocator_type traits_type; +#endif + +public: + typedef BaseAllocator BaseAllocatorType; + + StdAllocator() RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_() + { } + + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + template + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + StdAllocator(StdAllocator&& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(std::move(rhs)), + baseAllocator_(std::move(rhs.baseAllocator_)) + { } +#endif +#if RAPIDJSON_HAS_CXX11 + using propagate_on_container_move_assignment = std::true_type; + using propagate_on_container_swap = std::true_type; +#endif + + /* implicit */ + StdAllocator(const BaseAllocator& allocator) RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_(allocator) + { } + + ~StdAllocator() RAPIDJSON_NOEXCEPT + { } + + template + struct rebind { + typedef StdAllocator other; + }; + + typedef typename traits_type::size_type size_type; + typedef typename traits_type::difference_type difference_type; + + typedef typename traits_type::value_type value_type; + typedef typename traits_type::pointer pointer; + typedef typename traits_type::const_pointer const_pointer; + +#if RAPIDJSON_HAS_CXX11 + + typedef typename std::add_lvalue_reference::type &reference; + typedef typename std::add_lvalue_reference::type>::type &const_reference; + + pointer address(reference r) const RAPIDJSON_NOEXCEPT + { + return std::addressof(r); + } + const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT + { + return std::addressof(r); + } + + size_type max_size() const RAPIDJSON_NOEXCEPT + { + return traits_type::max_size(*this); + } + + template + void construct(pointer p, Args&&... args) + { + traits_type::construct(*this, p, std::forward(args)...); + } + void destroy(pointer p) + { + traits_type::destroy(*this, p); + } + +#else // !RAPIDJSON_HAS_CXX11 + + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + + pointer address(reference r) const RAPIDJSON_NOEXCEPT + { + return allocator_type::address(r); + } + const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT + { + return allocator_type::address(r); + } + + size_type max_size() const RAPIDJSON_NOEXCEPT + { + return allocator_type::max_size(); + } + + void construct(pointer p, const_reference r) + { + allocator_type::construct(p, r); + } + void destroy(pointer p) + { + allocator_type::destroy(p); + } + +#endif // !RAPIDJSON_HAS_CXX11 + + template + U* allocate(size_type n = 1, const void* = 0) + { + return RAPIDJSON_NAMESPACE::Malloc(baseAllocator_, n); + } + template + void deallocate(U* p, size_type n = 1) + { + RAPIDJSON_NAMESPACE::Free(baseAllocator_, p, n); + } + + pointer allocate(size_type n = 1, const void* = 0) + { + return allocate(n); + } + void deallocate(pointer p, size_type n = 1) + { + deallocate(p, n); + } + +#if RAPIDJSON_HAS_CXX11 + using is_always_equal = std::is_empty; +#endif + + template + bool operator==(const StdAllocator& rhs) const RAPIDJSON_NOEXCEPT + { + return baseAllocator_ == rhs.baseAllocator_; + } + template + bool operator!=(const StdAllocator& rhs) const RAPIDJSON_NOEXCEPT + { + return !operator==(rhs); + } + + //! rapidjson Allocator concept + static const bool kNeedFree = BaseAllocator::kNeedFree; + static const bool kRefCounted = internal::IsRefCounted::Value; + void* Malloc(size_t size) + { + return baseAllocator_.Malloc(size); + } + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) + { + return baseAllocator_.Realloc(originalPtr, originalSize, newSize); + } + static void Free(void *ptr) RAPIDJSON_NOEXCEPT + { + BaseAllocator::Free(ptr); + } + +private: + template + friend class StdAllocator; // access to StdAllocator.* + + BaseAllocator baseAllocator_; +}; + +#if !RAPIDJSON_HAS_CXX17 // std::allocator deprecated in C++17 +template +class StdAllocator : + public std::allocator +{ + typedef std::allocator allocator_type; + +public: + typedef BaseAllocator BaseAllocatorType; + + StdAllocator() RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_() + { } + + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + template + StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : + allocator_type(rhs), + baseAllocator_(rhs.baseAllocator_) + { } + + /* implicit */ + StdAllocator(const BaseAllocator& baseAllocator) RAPIDJSON_NOEXCEPT : + allocator_type(), + baseAllocator_(baseAllocator) + { } + + ~StdAllocator() RAPIDJSON_NOEXCEPT + { } + + template + struct rebind { + typedef StdAllocator other; + }; + + typedef typename allocator_type::value_type value_type; + +private: + template + friend class StdAllocator; // access to StdAllocator.* + + BaseAllocator baseAllocator_; +}; +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_ENCODINGS_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/cursorstreamwrapper.h b/components/thorvg-main/src/loaders/lottie/rapidjson/cursorstreamwrapper.h new file mode 100644 index 0000000..fd6513d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/cursorstreamwrapper.h @@ -0,0 +1,78 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ +#define RAPIDJSON_CURSORSTREAMWRAPPER_H_ + +#include "stream.h" + +#if defined(__GNUC__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#if defined(_MSC_VER) && _MSC_VER <= 1800 +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4702) // unreachable code +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +RAPIDJSON_NAMESPACE_BEGIN + + +//! Cursor stream wrapper for counting line and column number if error exists. +/*! + \tparam InputStream Any stream that implements Stream Concept +*/ +template > +class CursorStreamWrapper : public GenericStreamWrapper { +public: + typedef typename Encoding::Ch Ch; + + CursorStreamWrapper(InputStream& is): + GenericStreamWrapper(is), line_(1), col_(0) {} + + // counting line and column number + Ch Take() { + Ch ch = this->is_.Take(); + if(ch == '\n') { + line_ ++; + col_ = 0; + } else { + col_ ++; + } + return ch; + } + + //! Get the error line number, if error exists. + size_t GetLine() const { return line_; } + //! Get the error column number, if error exists. + size_t GetColumn() const { return col_; } + +private: + size_t line_; //!< Current Line + size_t col_; //!< Current Column +}; + +#if defined(_MSC_VER) && _MSC_VER <= 1800 +RAPIDJSON_DIAG_POP +#endif + +#if defined(__GNUC__) +RAPIDJSON_DIAG_POP +#endif + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/document.h b/components/thorvg-main/src/loaders/lottie/rapidjson/document.h new file mode 100644 index 0000000..1edb547 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/document.h @@ -0,0 +1,3043 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_DOCUMENT_H_ +#define RAPIDJSON_DOCUMENT_H_ + +/*! \file document.h */ + +#include "reader.h" +#include "internal/meta.h" +#include "internal/strfunc.h" +#include "memorystream.h" +#include "encodedstream.h" +#include // placement new +#include +#ifdef __cpp_lib_three_way_comparison +#include +#endif + +RAPIDJSON_DIAG_PUSH +#ifdef __clang__ +RAPIDJSON_DIAG_OFF(padded) +RAPIDJSON_DIAG_OFF(switch-enum) +RAPIDJSON_DIAG_OFF(c++98-compat) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant +RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_OFF(effc++) +#endif // __GNUC__ + +#ifdef GetObject +// see https://github.com/Tencent/rapidjson/issues/1448 +// a former included windows.h might have defined a macro called GetObject, which affects +// GetObject defined here. This ensures the macro does not get applied +#pragma push_macro("GetObject") +#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#undef GetObject +#endif + +#ifndef RAPIDJSON_NOMEMBERITERATORCLASS +#include // std::random_access_iterator_tag +#endif + +#if RAPIDJSON_USE_MEMBERSMAP +#include // std::multimap +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +// Forward declaration. +template +class GenericValue; + +template +class GenericDocument; + +/*! \def RAPIDJSON_DEFAULT_ALLOCATOR + \ingroup RAPIDJSON_CONFIG + \brief Allows to choose default allocator. + + User can define this to use CrtAllocator or MemoryPoolAllocator. +*/ +#ifndef RAPIDJSON_DEFAULT_ALLOCATOR +#define RAPIDJSON_DEFAULT_ALLOCATOR ::RAPIDJSON_NAMESPACE::MemoryPoolAllocator<::RAPIDJSON_NAMESPACE::CrtAllocator> +#endif + +/*! \def RAPIDJSON_DEFAULT_STACK_ALLOCATOR + \ingroup RAPIDJSON_CONFIG + \brief Allows to choose default stack allocator for Document. + + User can define this to use CrtAllocator or MemoryPoolAllocator. +*/ +#ifndef RAPIDJSON_DEFAULT_STACK_ALLOCATOR +#define RAPIDJSON_DEFAULT_STACK_ALLOCATOR ::RAPIDJSON_NAMESPACE::CrtAllocator +#endif + +/*! \def RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY + \ingroup RAPIDJSON_CONFIG + \brief User defined kDefaultObjectCapacity value. + + User can define this as any natural number. +*/ +#ifndef RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY +// number of objects that rapidjson::Value allocates memory for by default +#define RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY 16 +#endif + +/*! \def RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY + \ingroup RAPIDJSON_CONFIG + \brief User defined kDefaultArrayCapacity value. + + User can define this as any natural number. +*/ +#ifndef RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY +// number of array elements that rapidjson::Value allocates memory for by default +#define RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY 16 +#endif + +//! Name-value pair in a JSON object value. +/*! + This class was internal to GenericValue. It used to be a inner struct. + But a compiler (IBM XL C/C++ for AIX) have reported to have problem with that so it moved as a namespace scope struct. + https://code.google.com/p/rapidjson/issues/detail?id=64 +*/ +template +class GenericMember { +public: + GenericValue name; //!< name of member (must be a string) + GenericValue value; //!< value of member. + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move constructor in C++11 + GenericMember(GenericMember&& rhs) RAPIDJSON_NOEXCEPT + : name(std::move(rhs.name)), + value(std::move(rhs.value)) + { + } + + //! Move assignment in C++11 + GenericMember& operator=(GenericMember&& rhs) RAPIDJSON_NOEXCEPT { + return *this = static_cast(rhs); + } +#endif + + //! Assignment with move semantics. + /*! \param rhs Source of the assignment. Its name and value will become a null value after assignment. + */ + GenericMember& operator=(GenericMember& rhs) RAPIDJSON_NOEXCEPT { + if (RAPIDJSON_LIKELY(this != &rhs)) { + name = rhs.name; + value = rhs.value; + } + return *this; + } + + // swap() for std::sort() and other potential use in STL. + friend inline void swap(GenericMember& a, GenericMember& b) RAPIDJSON_NOEXCEPT { + a.name.Swap(b.name); + a.value.Swap(b.value); + } + +private: + //! Copy constructor is not permitted. + GenericMember(const GenericMember& rhs); +}; + +/////////////////////////////////////////////////////////////////////////////// +// GenericMemberIterator + +#ifndef RAPIDJSON_NOMEMBERITERATORCLASS + +//! (Constant) member iterator for a JSON object value +/*! + \tparam Const Is this a constant iterator? + \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document) + \tparam Allocator Allocator type for allocating memory of object, array and string. + + This class implements a Random Access Iterator for GenericMember elements + of a GenericValue, see ISO/IEC 14882:2003(E) C++ standard, 24.1 [lib.iterator.requirements]. + + \note This iterator implementation is mainly intended to avoid implicit + conversions from iterator values to \c NULL, + e.g. from GenericValue::FindMember. + + \note Define \c RAPIDJSON_NOMEMBERITERATORCLASS to fall back to a + pointer-based implementation, if your platform doesn't provide + the C++ header. + + \see GenericMember, GenericValue::MemberIterator, GenericValue::ConstMemberIterator + */ +template +class GenericMemberIterator { + + friend class GenericValue; + template friend class GenericMemberIterator; + + typedef GenericMember PlainType; + typedef typename internal::MaybeAddConst::Type ValueType; + +public: + //! Iterator type itself + typedef GenericMemberIterator Iterator; + //! Constant iterator type + typedef GenericMemberIterator ConstIterator; + //! Non-constant iterator type + typedef GenericMemberIterator NonConstIterator; + + /** \name std::iterator_traits support */ + //@{ + typedef ValueType value_type; + typedef ValueType * pointer; + typedef ValueType & reference; + typedef std::ptrdiff_t difference_type; + typedef std::random_access_iterator_tag iterator_category; + //@} + + //! Pointer to (const) GenericMember + typedef pointer Pointer; + //! Reference to (const) GenericMember + typedef reference Reference; + //! Signed integer type (e.g. \c ptrdiff_t) + typedef difference_type DifferenceType; + + //! Default constructor (singular value) + /*! Creates an iterator pointing to no element. + \note All operations, except for comparisons, are undefined on such values. + */ + GenericMemberIterator() : ptr_() {} + + //! Iterator conversions to more const + /*! + \param it (Non-const) iterator to copy from + + Allows the creation of an iterator from another GenericMemberIterator + that is "less const". Especially, creating a non-constant iterator + from a constant iterator are disabled: + \li const -> non-const (not ok) + \li const -> const (ok) + \li non-const -> const (ok) + \li non-const -> non-const (ok) + + \note If the \c Const template parameter is already \c false, this + constructor effectively defines a regular copy-constructor. + Otherwise, the copy constructor is implicitly defined. + */ + GenericMemberIterator(const NonConstIterator & it) : ptr_(it.ptr_) {} + Iterator& operator=(const NonConstIterator & it) { ptr_ = it.ptr_; return *this; } + + //! @name stepping + //@{ + Iterator& operator++(){ ++ptr_; return *this; } + Iterator& operator--(){ --ptr_; return *this; } + Iterator operator++(int){ Iterator old(*this); ++ptr_; return old; } + Iterator operator--(int){ Iterator old(*this); --ptr_; return old; } + //@} + + //! @name increment/decrement + //@{ + Iterator operator+(DifferenceType n) const { return Iterator(ptr_+n); } + Iterator operator-(DifferenceType n) const { return Iterator(ptr_-n); } + + Iterator& operator+=(DifferenceType n) { ptr_+=n; return *this; } + Iterator& operator-=(DifferenceType n) { ptr_-=n; return *this; } + //@} + + //! @name relations + //@{ + template bool operator==(const GenericMemberIterator& that) const { return ptr_ == that.ptr_; } + template bool operator!=(const GenericMemberIterator& that) const { return ptr_ != that.ptr_; } + template bool operator<=(const GenericMemberIterator& that) const { return ptr_ <= that.ptr_; } + template bool operator>=(const GenericMemberIterator& that) const { return ptr_ >= that.ptr_; } + template bool operator< (const GenericMemberIterator& that) const { return ptr_ < that.ptr_; } + template bool operator> (const GenericMemberIterator& that) const { return ptr_ > that.ptr_; } + +#ifdef __cpp_lib_three_way_comparison + template std::strong_ordering operator<=>(const GenericMemberIterator& that) const { return ptr_ <=> that.ptr_; } +#endif + //@} + + //! @name dereference + //@{ + Reference operator*() const { return *ptr_; } + Pointer operator->() const { return ptr_; } + Reference operator[](DifferenceType n) const { return ptr_[n]; } + //@} + + //! Distance + DifferenceType operator-(ConstIterator that) const { return ptr_-that.ptr_; } + +private: + //! Internal constructor from plain pointer + explicit GenericMemberIterator(Pointer p) : ptr_(p) {} + + Pointer ptr_; //!< raw pointer +}; + +#else // RAPIDJSON_NOMEMBERITERATORCLASS + +// class-based member iterator implementation disabled, use plain pointers + +template +class GenericMemberIterator; + +//! non-const GenericMemberIterator +template +class GenericMemberIterator { +public: + //! use plain pointer as iterator type + typedef GenericMember* Iterator; +}; +//! const GenericMemberIterator +template +class GenericMemberIterator { +public: + //! use plain const pointer as iterator type + typedef const GenericMember* Iterator; +}; + +#endif // RAPIDJSON_NOMEMBERITERATORCLASS + +/////////////////////////////////////////////////////////////////////////////// +// GenericStringRef + +//! Reference to a constant string (not taking a copy) +/*! + \tparam CharType character type of the string + + This helper class is used to automatically infer constant string + references for string literals, especially from \c const \b (!) + character arrays. + + The main use is for creating JSON string values without copying the + source string via an \ref Allocator. This requires that the referenced + string pointers have a sufficient lifetime, which exceeds the lifetime + of the associated GenericValue. + + \b Example + \code + Value v("foo"); // ok, no need to copy & calculate length + const char foo[] = "foo"; + v.SetString(foo); // ok + + const char* bar = foo; + // Value x(bar); // not ok, can't rely on bar's lifetime + Value x(StringRef(bar)); // lifetime explicitly guaranteed by user + Value y(StringRef(bar, 3)); // ok, explicitly pass length + \endcode + + \see StringRef, GenericValue::SetString +*/ +template +struct GenericStringRef { + typedef CharType Ch; //!< character type of the string + + //! Create string reference from \c const character array +#ifndef __clang__ // -Wdocumentation + /*! + This constructor implicitly creates a constant string reference from + a \c const character array. It has better performance than + \ref StringRef(const CharType*) by inferring the string \ref length + from the array length, and also supports strings containing null + characters. + + \tparam N length of the string, automatically inferred + + \param str Constant character array, lifetime assumed to be longer + than the use of the string in e.g. a GenericValue + + \post \ref s == str + + \note Constant complexity. + \note There is a hidden, private overload to disallow references to + non-const character arrays to be created via this constructor. + By this, e.g. function-scope arrays used to be filled via + \c snprintf are excluded from consideration. + In such cases, the referenced string should be \b copied to the + GenericValue instead. + */ +#endif + template + GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT + : s(str), length(N-1) {} + + //! Explicitly create string reference from \c const character pointer +#ifndef __clang__ // -Wdocumentation + /*! + This constructor can be used to \b explicitly create a reference to + a constant string pointer. + + \see StringRef(const CharType*) + + \param str Constant character pointer, lifetime assumed to be longer + than the use of the string in e.g. a GenericValue + + \post \ref s == str + + \note There is a hidden, private overload to disallow references to + non-const character arrays to be created via this constructor. + By this, e.g. function-scope arrays used to be filled via + \c snprintf are excluded from consideration. + In such cases, the referenced string should be \b copied to the + GenericValue instead. + */ +#endif + explicit GenericStringRef(const CharType* str) + : s(str), length(NotNullStrLen(str)) {} + + //! Create constant string reference from pointer and length +#ifndef __clang__ // -Wdocumentation + /*! \param str constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue + \param len length of the string, excluding the trailing NULL terminator + + \post \ref s == str && \ref length == len + \note Constant complexity. + */ +#endif + GenericStringRef(const CharType* str, SizeType len) + : s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) { RAPIDJSON_ASSERT(str != 0 || len == 0u); } + + GenericStringRef(const GenericStringRef& rhs) : s(rhs.s), length(rhs.length) {} + + //! implicit conversion to plain CharType pointer + operator const Ch *() const { return s; } + + const Ch* const s; //!< plain CharType pointer + const SizeType length; //!< length of the string (excluding the trailing NULL terminator) + +private: + SizeType NotNullStrLen(const CharType* str) { + RAPIDJSON_ASSERT(str != 0); + return internal::StrLen(str); + } + + /// Empty string - used when passing in a NULL pointer + static const Ch emptyString[]; + + //! Disallow construction from non-const array + template + GenericStringRef(CharType (&str)[N]) /* = delete */; + //! Copy assignment operator not permitted - immutable type + GenericStringRef& operator=(const GenericStringRef& rhs) /* = delete */; +}; + +template +const CharType GenericStringRef::emptyString[] = { CharType() }; + +//! Mark a character pointer as constant string +/*! Mark a plain character pointer as a "string literal". This function + can be used to avoid copying a character string to be referenced as a + value in a JSON GenericValue object, if the string's lifetime is known + to be valid long enough. + \tparam CharType Character type of the string + \param str Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue + \return GenericStringRef string reference object + \relatesalso GenericStringRef + + \see GenericValue::GenericValue(StringRefType), GenericValue::operator=(StringRefType), GenericValue::SetString(StringRefType), GenericValue::PushBack(StringRefType, Allocator&), GenericValue::AddMember +*/ +template +inline GenericStringRef StringRef(const CharType* str) { + return GenericStringRef(str); +} + +//! Mark a character pointer as constant string +/*! Mark a plain character pointer as a "string literal". This function + can be used to avoid copying a character string to be referenced as a + value in a JSON GenericValue object, if the string's lifetime is known + to be valid long enough. + + This version has better performance with supplied length, and also + supports string containing null characters. + + \tparam CharType character type of the string + \param str Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue + \param length The length of source string. + \return GenericStringRef string reference object + \relatesalso GenericStringRef +*/ +template +inline GenericStringRef StringRef(const CharType* str, size_t length) { + return GenericStringRef(str, SizeType(length)); +} + +#if RAPIDJSON_HAS_STDSTRING +//! Mark a string object as constant string +/*! Mark a string object (e.g. \c std::string) as a "string literal". + This function can be used to avoid copying a string to be referenced as a + value in a JSON GenericValue object, if the string's lifetime is known + to be valid long enough. + + \tparam CharType character type of the string + \param str Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue + \return GenericStringRef string reference object + \relatesalso GenericStringRef + \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING. +*/ +template +inline GenericStringRef StringRef(const std::basic_string& str) { + return GenericStringRef(str.data(), SizeType(str.size())); +} +#endif + +/////////////////////////////////////////////////////////////////////////////// +// GenericValue type traits +namespace internal { + +template +struct IsGenericValueImpl : FalseType {}; + +// select candidates according to nested encoding and allocator types +template struct IsGenericValueImpl::Type, typename Void::Type> + : IsBaseOf, T>::Type {}; + +// helper to match arbitrary GenericValue instantiations, including derived classes +template struct IsGenericValue : IsGenericValueImpl::Type {}; + +} // namespace internal + +/////////////////////////////////////////////////////////////////////////////// +// TypeHelper + +namespace internal { + +template +struct TypeHelper {}; + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsBool(); } + static bool Get(const ValueType& v) { return v.GetBool(); } + static ValueType& Set(ValueType& v, bool data) { return v.SetBool(data); } + static ValueType& Set(ValueType& v, bool data, typename ValueType::AllocatorType&) { return v.SetBool(data); } +}; + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsInt(); } + static int Get(const ValueType& v) { return v.GetInt(); } + static ValueType& Set(ValueType& v, int data) { return v.SetInt(data); } + static ValueType& Set(ValueType& v, int data, typename ValueType::AllocatorType&) { return v.SetInt(data); } +}; + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsUint(); } + static unsigned Get(const ValueType& v) { return v.GetUint(); } + static ValueType& Set(ValueType& v, unsigned data) { return v.SetUint(data); } + static ValueType& Set(ValueType& v, unsigned data, typename ValueType::AllocatorType&) { return v.SetUint(data); } +}; + +#ifdef _MSC_VER +RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int)); +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsInt(); } + static long Get(const ValueType& v) { return v.GetInt(); } + static ValueType& Set(ValueType& v, long data) { return v.SetInt(data); } + static ValueType& Set(ValueType& v, long data, typename ValueType::AllocatorType&) { return v.SetInt(data); } +}; + +RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned)); +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsUint(); } + static unsigned long Get(const ValueType& v) { return v.GetUint(); } + static ValueType& Set(ValueType& v, unsigned long data) { return v.SetUint(data); } + static ValueType& Set(ValueType& v, unsigned long data, typename ValueType::AllocatorType&) { return v.SetUint(data); } +}; +#endif + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsInt64(); } + static int64_t Get(const ValueType& v) { return v.GetInt64(); } + static ValueType& Set(ValueType& v, int64_t data) { return v.SetInt64(data); } + static ValueType& Set(ValueType& v, int64_t data, typename ValueType::AllocatorType&) { return v.SetInt64(data); } +}; + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsUint64(); } + static uint64_t Get(const ValueType& v) { return v.GetUint64(); } + static ValueType& Set(ValueType& v, uint64_t data) { return v.SetUint64(data); } + static ValueType& Set(ValueType& v, uint64_t data, typename ValueType::AllocatorType&) { return v.SetUint64(data); } +}; + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsDouble(); } + static double Get(const ValueType& v) { return v.GetDouble(); } + static ValueType& Set(ValueType& v, double data) { return v.SetDouble(data); } + static ValueType& Set(ValueType& v, double data, typename ValueType::AllocatorType&) { return v.SetDouble(data); } +}; + +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsFloat(); } + static float Get(const ValueType& v) { return v.GetFloat(); } + static ValueType& Set(ValueType& v, float data) { return v.SetFloat(data); } + static ValueType& Set(ValueType& v, float data, typename ValueType::AllocatorType&) { return v.SetFloat(data); } +}; + +template +struct TypeHelper { + typedef const typename ValueType::Ch* StringType; + static bool Is(const ValueType& v) { return v.IsString(); } + static StringType Get(const ValueType& v) { return v.GetString(); } + static ValueType& Set(ValueType& v, const StringType data) { return v.SetString(typename ValueType::StringRefType(data)); } + static ValueType& Set(ValueType& v, const StringType data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); } +}; + +#if RAPIDJSON_HAS_STDSTRING +template +struct TypeHelper > { + typedef std::basic_string StringType; + static bool Is(const ValueType& v) { return v.IsString(); } + static StringType Get(const ValueType& v) { return StringType(v.GetString(), v.GetStringLength()); } + static ValueType& Set(ValueType& v, const StringType& data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); } +}; +#endif + +template +struct TypeHelper { + typedef typename ValueType::Array ArrayType; + static bool Is(const ValueType& v) { return v.IsArray(); } + static ArrayType Get(ValueType& v) { return v.GetArray(); } + static ValueType& Set(ValueType& v, ArrayType data) { return v = data; } + static ValueType& Set(ValueType& v, ArrayType data, typename ValueType::AllocatorType&) { return v = data; } +}; + +template +struct TypeHelper { + typedef typename ValueType::ConstArray ArrayType; + static bool Is(const ValueType& v) { return v.IsArray(); } + static ArrayType Get(const ValueType& v) { return v.GetArray(); } +}; + +template +struct TypeHelper { + typedef typename ValueType::Object ObjectType; + static bool Is(const ValueType& v) { return v.IsObject(); } + static ObjectType Get(ValueType& v) { return v.GetObject(); } + static ValueType& Set(ValueType& v, ObjectType data) { return v = data; } + static ValueType& Set(ValueType& v, ObjectType data, typename ValueType::AllocatorType&) { return v = data; } +}; + +template +struct TypeHelper { + typedef typename ValueType::ConstObject ObjectType; + static bool Is(const ValueType& v) { return v.IsObject(); } + static ObjectType Get(const ValueType& v) { return v.GetObject(); } +}; + +} // namespace internal + +// Forward declarations +template class GenericArray; +template class GenericObject; + +/////////////////////////////////////////////////////////////////////////////// +// GenericValue + +//! Represents a JSON value. Use Value for UTF8 encoding and default allocator. +/*! + A JSON value can be one of 7 types. This class is a variant type supporting + these types. + + Use the Value if UTF8 and default allocator + + \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document) + \tparam Allocator Allocator type for allocating memory of object, array and string. +*/ +template +class GenericValue { +public: + //! Name-value pair in an object. + typedef GenericMember Member; + typedef Encoding EncodingType; //!< Encoding type from template parameter. + typedef Allocator AllocatorType; //!< Allocator type from template parameter. + typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding. + typedef GenericStringRef StringRefType; //!< Reference to a constant string + typedef typename GenericMemberIterator::Iterator MemberIterator; //!< Member iterator for iterating in object. + typedef typename GenericMemberIterator::Iterator ConstMemberIterator; //!< Constant member iterator for iterating in object. + typedef GenericValue* ValueIterator; //!< Value iterator for iterating in array. + typedef const GenericValue* ConstValueIterator; //!< Constant value iterator for iterating in array. + typedef GenericValue ValueType; //!< Value type of itself. + typedef GenericArray Array; + typedef GenericArray ConstArray; + typedef GenericObject Object; + typedef GenericObject ConstObject; + + //!@name Constructors and destructor. + //@{ + + //! Default constructor creates a null value. + GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move constructor in C++11 + GenericValue(GenericValue&& rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) { + rhs.data_.f.flags = kNullFlag; // give up contents + } +#endif + +private: + //! Copy constructor is not permitted. + GenericValue(const GenericValue& rhs); + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Moving from a GenericDocument is not permitted. + template + GenericValue(GenericDocument&& rhs); + + //! Move assignment from a GenericDocument is not permitted. + template + GenericValue& operator=(GenericDocument&& rhs); +#endif + +public: + + //! Constructor with JSON value type. + /*! This creates a Value of specified type with default content. + \param type Type of the value. + \note Default content for number is zero. + */ + explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() { + static const uint16_t defaultFlags[] = { + kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag, + kNumberAnyFlag + }; + RAPIDJSON_NOEXCEPT_ASSERT(type >= kNullType && type <= kNumberType); + data_.f.flags = defaultFlags[type]; + + // Use ShortString to store empty string. + if (type == kStringType) + data_.ss.SetLength(0); + } + + //! Explicit copy constructor (with allocator) + /*! Creates a copy of a Value by using the given Allocator + \tparam SourceAllocator allocator of \c rhs + \param rhs Value to copy from (read-only) + \param allocator Allocator for allocating copied elements and buffers. Commonly use GenericDocument::GetAllocator(). + \param copyConstStrings Force copying of constant strings (e.g. referencing an in-situ buffer) + \see CopyFrom() + */ + template + GenericValue(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings = false) { + switch (rhs.GetType()) { + case kObjectType: + DoCopyMembers(rhs, allocator, copyConstStrings); + break; + case kArrayType: { + SizeType count = rhs.data_.a.size; + GenericValue* le = reinterpret_cast(allocator.Malloc(count * sizeof(GenericValue))); + const GenericValue* re = rhs.GetElementsPointer(); + for (SizeType i = 0; i < count; i++) + new (&le[i]) GenericValue(re[i], allocator, copyConstStrings); + data_.f.flags = kArrayFlag; + data_.a.size = data_.a.capacity = count; + SetElementsPointer(le); + } + break; + case kStringType: + if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) { + data_.f.flags = rhs.data_.f.flags; + data_ = *reinterpret_cast(&rhs.data_); + } + else + SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator); + break; + default: + data_.f.flags = rhs.data_.f.flags; + data_ = *reinterpret_cast(&rhs.data_); + break; + } + } + + //! Constructor for boolean value. + /*! \param b Boolean value + \note This constructor is limited to \em real boolean values and rejects + implicitly converted types like arbitrary pointers. Use an explicit cast + to \c bool, if you want to construct a boolean JSON value in such cases. + */ +#ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen + template + explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame))) RAPIDJSON_NOEXCEPT // See #472 +#else + explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT +#endif + : data_() { + // safe-guard against failing SFINAE + RAPIDJSON_STATIC_ASSERT((internal::IsSame::Value)); + data_.f.flags = b ? kTrueFlag : kFalseFlag; + } + + //! Constructor for int value. + explicit GenericValue(int i) RAPIDJSON_NOEXCEPT : data_() { + data_.n.i64 = i; + data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag; + } + + //! Constructor for unsigned value. + explicit GenericValue(unsigned u) RAPIDJSON_NOEXCEPT : data_() { + data_.n.u64 = u; + data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag); + } + + //! Constructor for int64_t value. + explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_() { + data_.n.i64 = i64; + data_.f.flags = kNumberInt64Flag; + if (i64 >= 0) { + data_.f.flags |= kNumberUint64Flag; + if (!(static_cast(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000))) + data_.f.flags |= kUintFlag; + if (!(static_cast(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000))) + data_.f.flags |= kIntFlag; + } + else if (i64 >= static_cast(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000))) + data_.f.flags |= kIntFlag; + } + + //! Constructor for uint64_t value. + explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_() { + data_.n.u64 = u64; + data_.f.flags = kNumberUint64Flag; + if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000))) + data_.f.flags |= kInt64Flag; + if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000))) + data_.f.flags |= kUintFlag; + if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000))) + data_.f.flags |= kIntFlag; + } + + //! Constructor for double value. + explicit GenericValue(double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; } + + //! Constructor for float value. + explicit GenericValue(float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = static_cast(f); data_.f.flags = kNumberDoubleFlag; } + + //! Constructor for constant string (i.e. do not make a copy of string) + GenericValue(const Ch* s, SizeType length) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(StringRef(s, length)); } + + //! Constructor for constant string (i.e. do not make a copy of string) + explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(s); } + + //! Constructor for copy-string (i.e. do make a copy of string) + GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_() { SetStringRaw(StringRef(s, length), allocator); } + + //! Constructor for copy-string (i.e. do make a copy of string) + GenericValue(const Ch*s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); } + +#if RAPIDJSON_HAS_STDSTRING + //! Constructor for copy-string from a string object (i.e. do make a copy of string) + /*! \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING. + */ + GenericValue(const std::basic_string& s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); } +#endif + + //! Constructor for Array. + /*! + \param a An array obtained by \c GetArray(). + \note \c Array is always pass-by-value. + \note the source array is moved into this value and the source array becomes empty. + */ + GenericValue(Array a) RAPIDJSON_NOEXCEPT : data_(a.value_.data_) { + a.value_.data_ = Data(); + a.value_.data_.f.flags = kArrayFlag; + } + + //! Constructor for Object. + /*! + \param o An object obtained by \c GetObject(). + \note \c Object is always pass-by-value. + \note the source object is moved into this value and the source object becomes empty. + */ + GenericValue(Object o) RAPIDJSON_NOEXCEPT : data_(o.value_.data_) { + o.value_.data_ = Data(); + o.value_.data_.f.flags = kObjectFlag; + } + + //! Destructor. + /*! Need to destruct elements of array, members of object, or copy-string. + */ + ~GenericValue() { + // With RAPIDJSON_USE_MEMBERSMAP, the maps need to be destroyed to release + // their Allocator if it's refcounted (e.g. MemoryPoolAllocator). + if (Allocator::kNeedFree || (RAPIDJSON_USE_MEMBERSMAP+0 && + internal::IsRefCounted::Value)) { + switch(data_.f.flags) { + case kArrayFlag: + { + GenericValue* e = GetElementsPointer(); + for (GenericValue* v = e; v != e + data_.a.size; ++v) + v->~GenericValue(); + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Allocator::Free(e); + } + } + break; + + case kObjectFlag: + DoFreeMembers(); + break; + + case kCopyStringFlag: + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Allocator::Free(const_cast(GetStringPointer())); + } + break; + + default: + break; // Do nothing for other types. + } + } + } + + //@} + + //!@name Assignment operators + //@{ + + //! Assignment with move semantics. + /*! \param rhs Source of the assignment. It will become a null value after assignment. + */ + GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT { + if (RAPIDJSON_LIKELY(this != &rhs)) { + // Can't destroy "this" before assigning "rhs", otherwise "rhs" + // could be used after free if it's an sub-Value of "this", + // hence the temporary dance. + GenericValue temp; + temp.RawAssign(rhs); + this->~GenericValue(); + RawAssign(temp); + } + return *this; + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move assignment in C++11 + GenericValue& operator=(GenericValue&& rhs) RAPIDJSON_NOEXCEPT { + return *this = rhs.Move(); + } +#endif + + //! Assignment of constant string reference (no copy) + /*! \param str Constant string reference to be assigned + \note This overload is needed to avoid clashes with the generic primitive type assignment overload below. + \see GenericStringRef, operator=(T) + */ + GenericValue& operator=(StringRefType str) RAPIDJSON_NOEXCEPT { + GenericValue s(str); + return *this = s; + } + + //! Assignment with primitive types. + /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t + \param value The value to be assigned. + + \note The source type \c T explicitly disallows all pointer types, + especially (\c const) \ref Ch*. This helps avoiding implicitly + referencing character strings with insufficient lifetime, use + \ref SetString(const Ch*, Allocator&) (for copying) or + \ref StringRef() (to explicitly mark the pointer as constant) instead. + All other pointer types would implicitly convert to \c bool, + use \ref SetBool() instead. + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer), (GenericValue&)) + operator=(T value) { + GenericValue v(value); + return *this = v; + } + + //! Deep-copy assignment from Value + /*! Assigns a \b copy of the Value to the current Value object + \tparam SourceAllocator Allocator type of \c rhs + \param rhs Value to copy from (read-only) + \param allocator Allocator to use for copying + \param copyConstStrings Force copying of constant strings (e.g. referencing an in-situ buffer) + */ + template + GenericValue& CopyFrom(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings = false) { + RAPIDJSON_ASSERT(static_cast(this) != static_cast(&rhs)); + this->~GenericValue(); + new (this) GenericValue(rhs, allocator, copyConstStrings); + return *this; + } + + //! Exchange the contents of this value with those of other. + /*! + \param other Another value. + \note Constant complexity. + */ + GenericValue& Swap(GenericValue& other) RAPIDJSON_NOEXCEPT { + GenericValue temp; + temp.RawAssign(*this); + RawAssign(other); + other.RawAssign(temp); + return *this; + } + + //! free-standing swap function helper + /*! + Helper function to enable support for common swap implementation pattern based on \c std::swap: + \code + void swap(MyClass& a, MyClass& b) { + using std::swap; + swap(a.value, b.value); + // ... + } + \endcode + \see Swap() + */ + friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } + + //! Prepare Value for move semantics + /*! \return *this */ + GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; } + //@} + + //!@name Equal-to and not-equal-to operators + //@{ + //! Equal-to operator + /*! + \note If an object contains duplicated named member, comparing equality with any object is always \c false. + \note Complexity is quadratic in Object's member number and linear for the rest (number of all values in the subtree and total lengths of all strings). + */ + template + bool operator==(const GenericValue& rhs) const { + typedef GenericValue RhsType; + if (GetType() != rhs.GetType()) + return false; + + switch (GetType()) { + case kObjectType: // Warning: O(n^2) inner-loop + if (data_.o.size != rhs.data_.o.size) + return false; + for (ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) { + typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name); + if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value) + return false; + } + return true; + + case kArrayType: + if (data_.a.size != rhs.data_.a.size) + return false; + for (SizeType i = 0; i < data_.a.size; i++) + if ((*this)[i] != rhs[i]) + return false; + return true; + + case kStringType: + return StringEqual(rhs); + + case kNumberType: + if (IsDouble() || rhs.IsDouble()) { + double a = GetDouble(); // May convert from integer to double. + double b = rhs.GetDouble(); // Ditto + return a >= b && a <= b; // Prevent -Wfloat-equal + } + else + return data_.n.u64 == rhs.data_.n.u64; + + default: + return true; + } + } + + //! Equal-to operator with const C-string pointer + bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); } + +#if RAPIDJSON_HAS_STDSTRING + //! Equal-to operator with string object + /*! \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING. + */ + bool operator==(const std::basic_string& rhs) const { return *this == GenericValue(StringRef(rhs)); } +#endif + + //! Equal-to operator with primitive types + /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c double, \c true, \c false + */ + template RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr,internal::IsGenericValue >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); } + +#ifndef __cpp_impl_three_way_comparison + //! Not-equal-to operator + /*! \return !(*this == rhs) + */ + template + bool operator!=(const GenericValue& rhs) const { return !(*this == rhs); } + + //! Not-equal-to operator with const C-string pointer + bool operator!=(const Ch* rhs) const { return !(*this == rhs); } + + //! Not-equal-to operator with arbitrary types + /*! \return !(*this == rhs) + */ + template RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue), (bool)) operator!=(const T& rhs) const { return !(*this == rhs); } + + //! Equal-to operator with arbitrary types (symmetric version) + /*! \return (rhs == lhs) + */ + template friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue), (bool)) operator==(const T& lhs, const GenericValue& rhs) { return rhs == lhs; } + + //! Not-Equal-to operator with arbitrary types (symmetric version) + /*! \return !(rhs == lhs) + */ + template friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); } + //@} +#endif + + //!@name Type + //@{ + + Type GetType() const { return static_cast(data_.f.flags & kTypeMask); } + bool IsNull() const { return data_.f.flags == kNullFlag; } + bool IsFalse() const { return data_.f.flags == kFalseFlag; } + bool IsTrue() const { return data_.f.flags == kTrueFlag; } + bool IsBool() const { return (data_.f.flags & kBoolFlag) != 0; } + bool IsObject() const { return data_.f.flags == kObjectFlag; } + bool IsArray() const { return data_.f.flags == kArrayFlag; } + bool IsNumber() const { return (data_.f.flags & kNumberFlag) != 0; } + bool IsInt() const { return (data_.f.flags & kIntFlag) != 0; } + bool IsUint() const { return (data_.f.flags & kUintFlag) != 0; } + bool IsInt64() const { return (data_.f.flags & kInt64Flag) != 0; } + bool IsUint64() const { return (data_.f.flags & kUint64Flag) != 0; } + bool IsDouble() const { return (data_.f.flags & kDoubleFlag) != 0; } + bool IsString() const { return (data_.f.flags & kStringFlag) != 0; } + + // Checks whether a number can be losslessly converted to a double. + bool IsLosslessDouble() const { + if (!IsNumber()) return false; + if (IsUint64()) { + uint64_t u = GetUint64(); + volatile double d = static_cast(u); + return (d >= 0.0) + && (d < static_cast((std::numeric_limits::max)())) + && (u == static_cast(d)); + } + if (IsInt64()) { + int64_t i = GetInt64(); + volatile double d = static_cast(i); + return (d >= static_cast((std::numeric_limits::min)())) + && (d < static_cast((std::numeric_limits::max)())) + && (i == static_cast(d)); + } + return true; // double, int, uint are always lossless + } + + // Checks whether a number is a float (possible lossy). + bool IsFloat() const { + if ((data_.f.flags & kDoubleFlag) == 0) + return false; + double d = GetDouble(); + return d >= -3.4028234e38 && d <= 3.4028234e38; + } + // Checks whether a number can be losslessly converted to a float. + bool IsLosslessFloat() const { + if (!IsNumber()) return false; + double a = GetDouble(); + if (a < static_cast(-(std::numeric_limits::max)()) + || a > static_cast((std::numeric_limits::max)())) + return false; + double b = static_cast(static_cast(a)); + return a >= b && a <= b; // Prevent -Wfloat-equal + } + + //@} + + //!@name Null + //@{ + + GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; } + + //@} + + //!@name Bool + //@{ + + bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return data_.f.flags == kTrueFlag; } + //!< Set boolean value + /*! \post IsBool() == true */ + GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; } + + //@} + + //!@name Object + //@{ + + //! Set this value as an empty object. + /*! \post IsObject() == true */ + GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; } + + //! Get the number of members in the object. + SizeType MemberCount() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size; } + + //! Get the capacity of object. + SizeType MemberCapacity() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.capacity; } + + //! Check whether the object is empty. + bool ObjectEmpty() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size == 0; } + + //! Get a value from an object associated with the name. + /*! \pre IsObject() == true + \tparam T Either \c Ch or \c const \c Ch (template used for disambiguation with \ref operator[](SizeType)) + \note In version 0.1x, if the member is not found, this function returns a null value. This makes issue 7. + Since 0.2, if the name is not correct, it will assert. + If user is unsure whether a member exists, user should use HasMember() first. + A better approach is to use FindMember(). + \note Linear time complexity. + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr::Type, Ch> >),(GenericValue&)) operator[](T* name) { + GenericValue n(StringRef(name)); + return (*this)[n]; + } + template + RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr::Type, Ch> >),(const GenericValue&)) operator[](T* name) const { return const_cast(*this)[name]; } + + //! Get a value from an object associated with the name. + /*! \pre IsObject() == true + \tparam SourceAllocator Allocator of the \c name value + + \note Compared to \ref operator[](T*), this version is faster because it does not need a StrLen(). + And it can also handle strings with embedded null characters. + + \note Linear time complexity. + */ + template + GenericValue& operator[](const GenericValue& name) { + MemberIterator member = FindMember(name); + if (member != MemberEnd()) + return member->value; + else { + RAPIDJSON_ASSERT(false); // see above note + +#if RAPIDJSON_HAS_CXX11 + // Use thread-local storage to prevent races between threads. + // Use static buffer and placement-new to prevent destruction, with + // alignas() to ensure proper alignment. + alignas(GenericValue) thread_local static char buffer[sizeof(GenericValue)]; + return *new (buffer) GenericValue(); +#elif defined(_MSC_VER) && _MSC_VER < 1900 + // There's no way to solve both thread locality and proper alignment + // simultaneously. + __declspec(thread) static char buffer[sizeof(GenericValue)]; + return *new (buffer) GenericValue(); +#elif defined(__GNUC__) || defined(__clang__) + // This will generate -Wexit-time-destructors in clang, but that's + // better than having under-alignment. + __thread static GenericValue buffer; + return buffer; +#else + // Don't know what compiler this is, so don't know how to ensure + // thread-locality. + static GenericValue buffer; + return buffer; +#endif + } + } + template + const GenericValue& operator[](const GenericValue& name) const { return const_cast(*this)[name]; } + +#if RAPIDJSON_HAS_STDSTRING + //! Get a value from an object associated with name (string object). + GenericValue& operator[](const std::basic_string& name) { return (*this)[GenericValue(StringRef(name))]; } + const GenericValue& operator[](const std::basic_string& name) const { return (*this)[GenericValue(StringRef(name))]; } +#endif + + //! Const member iterator + /*! \pre IsObject() == true */ + ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer()); } + //! Const \em past-the-end member iterator + /*! \pre IsObject() == true */ + ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer() + data_.o.size); } + //! Member iterator + /*! \pre IsObject() == true */ + MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer()); } + //! \em Past-the-end member iterator + /*! \pre IsObject() == true */ + MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer() + data_.o.size); } + + //! Request the object to have enough capacity to store members. + /*! \param newCapacity The capacity that the object at least need to have. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \note Linear time complexity. + */ + GenericValue& MemberReserve(SizeType newCapacity, Allocator &allocator) { + RAPIDJSON_ASSERT(IsObject()); + DoReserveMembers(newCapacity, allocator); + return *this; + } + + //! Check whether a member exists in the object. + /*! + \param name Member name to be searched. + \pre IsObject() == true + \return Whether a member with that name exists. + \note It is better to use FindMember() directly if you need the obtain the value as well. + \note Linear time complexity. + */ + bool HasMember(const Ch* name) const { return FindMember(name) != MemberEnd(); } + +#if RAPIDJSON_HAS_STDSTRING + //! Check whether a member exists in the object with string object. + /*! + \param name Member name to be searched. + \pre IsObject() == true + \return Whether a member with that name exists. + \note It is better to use FindMember() directly if you need the obtain the value as well. + \note Linear time complexity. + */ + bool HasMember(const std::basic_string& name) const { return FindMember(name) != MemberEnd(); } +#endif + + //! Check whether a member exists in the object with GenericValue name. + /*! + This version is faster because it does not need a StrLen(). It can also handle string with null character. + \param name Member name to be searched. + \pre IsObject() == true + \return Whether a member with that name exists. + \note It is better to use FindMember() directly if you need the obtain the value as well. + \note Linear time complexity. + */ + template + bool HasMember(const GenericValue& name) const { return FindMember(name) != MemberEnd(); } + + //! Find member by name. + /*! + \param name Member name to be searched. + \pre IsObject() == true + \return Iterator to member, if it exists. + Otherwise returns \ref MemberEnd(). + + \note Earlier versions of Rapidjson returned a \c NULL pointer, in case + the requested member doesn't exist. For consistency with e.g. + \c std::map, this has been changed to MemberEnd() now. + \note Linear time complexity. + */ + MemberIterator FindMember(const Ch* name) { + GenericValue n(StringRef(name)); + return FindMember(n); + } + + ConstMemberIterator FindMember(const Ch* name) const { return const_cast(*this).FindMember(name); } + + //! Find member by name. + /*! + This version is faster because it does not need a StrLen(). It can also handle string with null character. + \param name Member name to be searched. + \pre IsObject() == true + \return Iterator to member, if it exists. + Otherwise returns \ref MemberEnd(). + + \note Earlier versions of Rapidjson returned a \c NULL pointer, in case + the requested member doesn't exist. For consistency with e.g. + \c std::map, this has been changed to MemberEnd() now. + \note Linear time complexity. + */ + template + MemberIterator FindMember(const GenericValue& name) { + RAPIDJSON_ASSERT(IsObject()); + RAPIDJSON_ASSERT(name.IsString()); + return DoFindMember(name); + } + template ConstMemberIterator FindMember(const GenericValue& name) const { return const_cast(*this).FindMember(name); } + +#if RAPIDJSON_HAS_STDSTRING + //! Find member by string object name. + /*! + \param name Member name to be searched. + \pre IsObject() == true + \return Iterator to member, if it exists. + Otherwise returns \ref MemberEnd(). + */ + MemberIterator FindMember(const std::basic_string& name) { return FindMember(GenericValue(StringRef(name))); } + ConstMemberIterator FindMember(const std::basic_string& name) const { return FindMember(GenericValue(StringRef(name))); } +#endif + + //! Add a member (name-value pair) to the object. + /*! \param name A string value as name of member. + \param value Value of any type. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \note The ownership of \c name and \c value will be transferred to this object on success. + \pre IsObject() && name.IsString() + \post name.IsNull() && value.IsNull() + \note Amortized Constant time complexity. + */ + GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) { + RAPIDJSON_ASSERT(IsObject()); + RAPIDJSON_ASSERT(name.IsString()); + DoAddMember(name, value, allocator); + return *this; + } + + //! Add a constant string value as member (name-value pair) to the object. + /*! \param name A string value as name of member. + \param value constant string reference as value of member. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \pre IsObject() + \note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below. + \note Amortized Constant time complexity. + */ + GenericValue& AddMember(GenericValue& name, StringRefType value, Allocator& allocator) { + GenericValue v(value); + return AddMember(name, v, allocator); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Add a string object as member (name-value pair) to the object. + /*! \param name A string value as name of member. + \param value constant string reference as value of member. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \pre IsObject() + \note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below. + \note Amortized Constant time complexity. + */ + GenericValue& AddMember(GenericValue& name, std::basic_string& value, Allocator& allocator) { + GenericValue v(value, allocator); + return AddMember(name, v, allocator); + } +#endif + + //! Add any primitive value as member (name-value pair) to the object. + /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t + \param name A string value as name of member. + \param value Value of primitive type \c T as value of member + \param allocator Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \pre IsObject() + + \note The source type \c T explicitly disallows all pointer types, + especially (\c const) \ref Ch*. This helps avoiding implicitly + referencing character strings with insufficient lifetime, use + \ref AddMember(StringRefType, GenericValue&, Allocator&) or \ref + AddMember(StringRefType, StringRefType, Allocator&). + All other pointer types would implicitly convert to \c bool, + use an explicit cast instead, if needed. + \note Amortized Constant time complexity. + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (GenericValue&)) + AddMember(GenericValue& name, T value, Allocator& allocator) { + GenericValue v(value); + return AddMember(name, v, allocator); + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericValue& AddMember(GenericValue&& name, GenericValue&& value, Allocator& allocator) { + return AddMember(name, value, allocator); + } + GenericValue& AddMember(GenericValue&& name, GenericValue& value, Allocator& allocator) { + return AddMember(name, value, allocator); + } + GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) { + return AddMember(name, value, allocator); + } + GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) { + GenericValue n(name); + return AddMember(n, value, allocator); + } +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + + + //! Add a member (name-value pair) to the object. + /*! \param name A constant string reference as name of member. + \param value Value of any type. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \note The ownership of \c value will be transferred to this object on success. + \pre IsObject() + \post value.IsNull() + \note Amortized Constant time complexity. + */ + GenericValue& AddMember(StringRefType name, GenericValue& value, Allocator& allocator) { + GenericValue n(name); + return AddMember(n, value, allocator); + } + + //! Add a constant string value as member (name-value pair) to the object. + /*! \param name A constant string reference as name of member. + \param value constant string reference as value of member. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \pre IsObject() + \note This overload is needed to avoid clashes with the generic primitive type AddMember(StringRefType,T,Allocator&) overload below. + \note Amortized Constant time complexity. + */ + GenericValue& AddMember(StringRefType name, StringRefType value, Allocator& allocator) { + GenericValue v(value); + return AddMember(name, v, allocator); + } + + //! Add any primitive value as member (name-value pair) to the object. + /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t + \param name A constant string reference as name of member. + \param value Value of primitive type \c T as value of member + \param allocator Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \pre IsObject() + + \note The source type \c T explicitly disallows all pointer types, + especially (\c const) \ref Ch*. This helps avoiding implicitly + referencing character strings with insufficient lifetime, use + \ref AddMember(StringRefType, GenericValue&, Allocator&) or \ref + AddMember(StringRefType, StringRefType, Allocator&). + All other pointer types would implicitly convert to \c bool, + use an explicit cast instead, if needed. + \note Amortized Constant time complexity. + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (GenericValue&)) + AddMember(StringRefType name, T value, Allocator& allocator) { + GenericValue n(name); + return AddMember(n, value, allocator); + } + + //! Remove all members in the object. + /*! This function do not deallocate memory in the object, i.e. the capacity is unchanged. + \note Linear time complexity. + */ + void RemoveAllMembers() { + RAPIDJSON_ASSERT(IsObject()); + DoClearMembers(); + } + + //! Remove a member in object by its name. + /*! \param name Name of member to be removed. + \return Whether the member existed. + \note This function may reorder the object members. Use \ref + EraseMember(ConstMemberIterator) if you need to preserve the + relative order of the remaining members. + \note Linear time complexity. + */ + bool RemoveMember(const Ch* name) { + GenericValue n(StringRef(name)); + return RemoveMember(n); + } + +#if RAPIDJSON_HAS_STDSTRING + bool RemoveMember(const std::basic_string& name) { return RemoveMember(GenericValue(StringRef(name))); } +#endif + + template + bool RemoveMember(const GenericValue& name) { + MemberIterator m = FindMember(name); + if (m != MemberEnd()) { + RemoveMember(m); + return true; + } + else + return false; + } + + //! Remove a member in object by iterator. + /*! \param m member iterator (obtained by FindMember() or MemberBegin()). + \return the new iterator after removal. + \note This function may reorder the object members. Use \ref + EraseMember(ConstMemberIterator) if you need to preserve the + relative order of the remaining members. + \note Constant time complexity. + */ + MemberIterator RemoveMember(MemberIterator m) { + RAPIDJSON_ASSERT(IsObject()); + RAPIDJSON_ASSERT(data_.o.size > 0); + RAPIDJSON_ASSERT(GetMembersPointer() != 0); + RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd()); + return DoRemoveMember(m); + } + + //! Remove a member from an object by iterator. + /*! \param pos iterator to the member to remove + \pre IsObject() == true && \ref MemberBegin() <= \c pos < \ref MemberEnd() + \return Iterator following the removed element. + If the iterator \c pos refers to the last element, the \ref MemberEnd() iterator is returned. + \note This function preserves the relative order of the remaining object + members. If you do not need this, use the more efficient \ref RemoveMember(MemberIterator). + \note Linear time complexity. + */ + MemberIterator EraseMember(ConstMemberIterator pos) { + return EraseMember(pos, pos +1); + } + + //! Remove members in the range [first, last) from an object. + /*! \param first iterator to the first member to remove + \param last iterator following the last member to remove + \pre IsObject() == true && \ref MemberBegin() <= \c first <= \c last <= \ref MemberEnd() + \return Iterator following the last removed element. + \note This function preserves the relative order of the remaining object + members. + \note Linear time complexity. + */ + MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) { + RAPIDJSON_ASSERT(IsObject()); + RAPIDJSON_ASSERT(data_.o.size > 0); + RAPIDJSON_ASSERT(GetMembersPointer() != 0); + RAPIDJSON_ASSERT(first >= MemberBegin()); + RAPIDJSON_ASSERT(first <= last); + RAPIDJSON_ASSERT(last <= MemberEnd()); + return DoEraseMembers(first, last); + } + + //! Erase a member in object by its name. + /*! \param name Name of member to be removed. + \return Whether the member existed. + \note Linear time complexity. + */ + bool EraseMember(const Ch* name) { + GenericValue n(StringRef(name)); + return EraseMember(n); + } + +#if RAPIDJSON_HAS_STDSTRING + bool EraseMember(const std::basic_string& name) { return EraseMember(GenericValue(StringRef(name))); } +#endif + + template + bool EraseMember(const GenericValue& name) { + MemberIterator m = FindMember(name); + if (m != MemberEnd()) { + EraseMember(m); + return true; + } + else + return false; + } + + Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } + Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); } + ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } + ConstObject GetObj() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); } + + //@} + + //!@name Array + //@{ + + //! Set this value as an empty array. + /*! \post IsArray == true */ + GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; } + + //! Get the number of elements in array. + SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; } + + //! Get the capacity of array. + SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; } + + //! Check whether the array is empty. + bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; } + + //! Remove all elements in the array. + /*! This function do not deallocate memory in the array, i.e. the capacity is unchanged. + \note Linear time complexity. + */ + void Clear() { + RAPIDJSON_ASSERT(IsArray()); + GenericValue* e = GetElementsPointer(); + for (GenericValue* v = e; v != e + data_.a.size; ++v) + v->~GenericValue(); + data_.a.size = 0; + } + + //! Get an element from array by index. + /*! \pre IsArray() == true + \param index Zero-based index of element. + \see operator[](T*) + */ + GenericValue& operator[](SizeType index) { + RAPIDJSON_ASSERT(IsArray()); + RAPIDJSON_ASSERT(index < data_.a.size); + return GetElementsPointer()[index]; + } + const GenericValue& operator[](SizeType index) const { return const_cast(*this)[index]; } + + //! Element iterator + /*! \pre IsArray() == true */ + ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer(); } + //! \em Past-the-end element iterator + /*! \pre IsArray() == true */ + ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer() + data_.a.size; } + //! Constant element iterator + /*! \pre IsArray() == true */ + ConstValueIterator Begin() const { return const_cast(*this).Begin(); } + //! Constant \em past-the-end element iterator + /*! \pre IsArray() == true */ + ConstValueIterator End() const { return const_cast(*this).End(); } + + //! Request the array to have enough capacity to store elements. + /*! \param newCapacity The capacity that the array at least need to have. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \note Linear time complexity. + */ + GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) { + RAPIDJSON_ASSERT(IsArray()); + if (newCapacity > data_.a.capacity) { + SetElementsPointer(reinterpret_cast(allocator.Realloc(GetElementsPointer(), data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue)))); + data_.a.capacity = newCapacity; + } + return *this; + } + + //! Append a GenericValue at the end of the array. + /*! \param value Value to be appended. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \pre IsArray() == true + \post value.IsNull() == true + \return The value itself for fluent API. + \note The ownership of \c value will be transferred to this array on success. + \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient. + \note Amortized constant time complexity. + */ + GenericValue& PushBack(GenericValue& value, Allocator& allocator) { + RAPIDJSON_ASSERT(IsArray()); + if (data_.a.size >= data_.a.capacity) + Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator); + GetElementsPointer()[data_.a.size++].RawAssign(value); + return *this; + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericValue& PushBack(GenericValue&& value, Allocator& allocator) { + return PushBack(value, allocator); + } +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + + //! Append a constant string reference at the end of the array. + /*! \param value Constant string reference to be appended. + \param allocator Allocator for reallocating memory. It must be the same one used previously. Commonly use GenericDocument::GetAllocator(). + \pre IsArray() == true + \return The value itself for fluent API. + \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient. + \note Amortized constant time complexity. + \see GenericStringRef + */ + GenericValue& PushBack(StringRefType value, Allocator& allocator) { + return (*this).template PushBack(value, allocator); + } + + //! Append a primitive value at the end of the array. + /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t + \param value Value of primitive type T to be appended. + \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). + \pre IsArray() == true + \return The value itself for fluent API. + \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient. + + \note The source type \c T explicitly disallows all pointer types, + especially (\c const) \ref Ch*. This helps avoiding implicitly + referencing character strings with insufficient lifetime, use + \ref PushBack(GenericValue&, Allocator&) or \ref + PushBack(StringRefType, Allocator&). + All other pointer types would implicitly convert to \c bool, + use an explicit cast instead, if needed. + \note Amortized constant time complexity. + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (GenericValue&)) + PushBack(T value, Allocator& allocator) { + GenericValue v(value); + return PushBack(v, allocator); + } + + //! Remove the last element in the array. + /*! + \note Constant time complexity. + */ + GenericValue& PopBack() { + RAPIDJSON_ASSERT(IsArray()); + RAPIDJSON_ASSERT(!Empty()); + GetElementsPointer()[--data_.a.size].~GenericValue(); + return *this; + } + + //! Remove an element of array by iterator. + /*! + \param pos iterator to the element to remove + \pre IsArray() == true && \ref Begin() <= \c pos < \ref End() + \return Iterator following the removed element. If the iterator pos refers to the last element, the End() iterator is returned. + \note Linear time complexity. + */ + ValueIterator Erase(ConstValueIterator pos) { + return Erase(pos, pos + 1); + } + + //! Remove elements in the range [first, last) of the array. + /*! + \param first iterator to the first element to remove + \param last iterator following the last element to remove + \pre IsArray() == true && \ref Begin() <= \c first <= \c last <= \ref End() + \return Iterator following the last removed element. + \note Linear time complexity. + */ + ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) { + RAPIDJSON_ASSERT(IsArray()); + RAPIDJSON_ASSERT(data_.a.size > 0); + RAPIDJSON_ASSERT(GetElementsPointer() != 0); + RAPIDJSON_ASSERT(first >= Begin()); + RAPIDJSON_ASSERT(first <= last); + RAPIDJSON_ASSERT(last <= End()); + ValueIterator pos = Begin() + (first - Begin()); + for (ValueIterator itr = pos; itr != last; ++itr) + itr->~GenericValue(); + std::memmove(static_cast(pos), last, static_cast(End() - last) * sizeof(GenericValue)); + data_.a.size -= static_cast(last - first); + return pos; + } + + Array GetArray() { RAPIDJSON_ASSERT(IsArray()); return Array(*this); } + ConstArray GetArray() const { RAPIDJSON_ASSERT(IsArray()); return ConstArray(*this); } + + //@} + + //!@name Number + //@{ + + int GetInt() const { RAPIDJSON_ASSERT(data_.f.flags & kIntFlag); return data_.n.i.i; } + unsigned GetUint() const { RAPIDJSON_ASSERT(data_.f.flags & kUintFlag); return data_.n.u.u; } + int64_t GetInt64() const { RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag); return data_.n.i64; } + uint64_t GetUint64() const { RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag); return data_.n.u64; } + + //! Get the value as double type. + /*! \note If the value is 64-bit integer type, it may lose precision. Use \c IsLosslessDouble() to check whether the conversion is lossless. + */ + double GetDouble() const { + RAPIDJSON_ASSERT(IsNumber()); + if ((data_.f.flags & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion. + if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double + if ((data_.f.flags & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double + if ((data_.f.flags & kInt64Flag) != 0) return static_cast(data_.n.i64); // int64_t -> double (may lose precision) + RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0); return static_cast(data_.n.u64); // uint64_t -> double (may lose precision) + } + + //! Get the value as float type. + /*! \note If the value is 64-bit integer type, it may lose precision. Use \c IsLosslessFloat() to check whether the conversion is lossless. + */ + float GetFloat() const { + return static_cast(GetDouble()); + } + + GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; } + GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; } + GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; } + GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; } + GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; } + GenericValue& SetFloat(float f) { this->~GenericValue(); new (this) GenericValue(static_cast(f)); return *this; } + + //@} + + //!@name String + //@{ + + const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return DataString(data_); } + + //! Get the length of string. + /*! Since rapidjson permits "\\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength(). + */ + SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return DataStringLength(data_); } + + //! Set this value as a string without copying source string. + /*! This version has better performance with supplied length, and also support string containing null character. + \param s source string pointer. + \param length The length of source string, excluding the trailing null terminator. + \return The value itself for fluent API. + \post IsString() == true && GetString() == s && GetStringLength() == length + \see SetString(StringRefType) + */ + GenericValue& SetString(const Ch* s, SizeType length) { return SetString(StringRef(s, length)); } + + //! Set this value as a string without copying source string. + /*! \param s source string reference + \return The value itself for fluent API. + \post IsString() == true && GetString() == s && GetStringLength() == s.length + */ + GenericValue& SetString(StringRefType s) { this->~GenericValue(); SetStringRaw(s); return *this; } + + //! Set this value as a string by copying from source string. + /*! This version has better performance with supplied length, and also support string containing null character. + \param s source string. + \param length The length of source string, excluding the trailing null terminator. + \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \post IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length + */ + GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { return SetString(StringRef(s, length), allocator); } + + //! Set this value as a string by copying from source string. + /*! \param s source string. + \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \post IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length + */ + GenericValue& SetString(const Ch* s, Allocator& allocator) { return SetString(StringRef(s), allocator); } + + //! Set this value as a string by copying from source string. + /*! \param s source string reference + \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \post IsString() == true && GetString() != s.s && strcmp(GetString(),s) == 0 && GetStringLength() == length + */ + GenericValue& SetString(StringRefType s, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, allocator); return *this; } + +#if RAPIDJSON_HAS_STDSTRING + //! Set this value as a string by copying from source string. + /*! \param s source string. + \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). + \return The value itself for fluent API. + \post IsString() == true && GetString() != s.data() && strcmp(GetString(),s.data() == 0 && GetStringLength() == s.size() + \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING. + */ + GenericValue& SetString(const std::basic_string& s, Allocator& allocator) { return SetString(StringRef(s), allocator); } +#endif + + //@} + + //!@name Array + //@{ + + //! Templated version for checking whether this value is type T. + /*! + \tparam T Either \c bool, \c int, \c unsigned, \c int64_t, \c uint64_t, \c double, \c float, \c const \c char*, \c std::basic_string + */ + template + bool Is() const { return internal::TypeHelper::Is(*this); } + + template + T Get() const { return internal::TypeHelper::Get(*this); } + + template + T Get() { return internal::TypeHelper::Get(*this); } + + template + ValueType& Set(const T& data) { return internal::TypeHelper::Set(*this, data); } + + template + ValueType& Set(const T& data, AllocatorType& allocator) { return internal::TypeHelper::Set(*this, data, allocator); } + + //@} + + //! Generate events of this value to a Handler. + /*! This function adopts the GoF visitor pattern. + Typical usage is to output this JSON value as JSON text via Writer, which is a Handler. + It can also be used to deep clone this value via GenericDocument, which is also a Handler. + \tparam Handler type of handler. + \param handler An object implementing concept Handler. + */ + template + bool Accept(Handler& handler) const { + switch(GetType()) { + case kNullType: return handler.Null(); + case kFalseType: return handler.Bool(false); + case kTrueType: return handler.Bool(true); + + case kObjectType: + if (RAPIDJSON_UNLIKELY(!handler.StartObject())) + return false; + for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) { + RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of name by MemberIterator. + if (RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0))) + return false; + if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler))) + return false; + } + return handler.EndObject(data_.o.size); + + case kArrayType: + if (RAPIDJSON_UNLIKELY(!handler.StartArray())) + return false; + for (ConstValueIterator v = Begin(); v != End(); ++v) + if (RAPIDJSON_UNLIKELY(!v->Accept(handler))) + return false; + return handler.EndArray(data_.a.size); + + case kStringType: + return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0); + + default: + RAPIDJSON_ASSERT(GetType() == kNumberType); + if (IsDouble()) return handler.Double(data_.n.d); + else if (IsInt()) return handler.Int(data_.n.i.i); + else if (IsUint()) return handler.Uint(data_.n.u.u); + else if (IsInt64()) return handler.Int64(data_.n.i64); + else return handler.Uint64(data_.n.u64); + } + } + +private: + template friend class GenericValue; + template friend class GenericDocument; + + enum { + kBoolFlag = 0x0008, + kNumberFlag = 0x0010, + kIntFlag = 0x0020, + kUintFlag = 0x0040, + kInt64Flag = 0x0080, + kUint64Flag = 0x0100, + kDoubleFlag = 0x0200, + kStringFlag = 0x0400, + kCopyFlag = 0x0800, + kInlineStrFlag = 0x1000, + + // Initial flags of different types. + kNullFlag = kNullType, + // These casts are added to suppress the warning on MSVC about bitwise operations between enums of different types. + kTrueFlag = static_cast(kTrueType) | static_cast(kBoolFlag), + kFalseFlag = static_cast(kFalseType) | static_cast(kBoolFlag), + kNumberIntFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kIntFlag | kInt64Flag), + kNumberUintFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag), + kNumberInt64Flag = static_cast(kNumberType) | static_cast(kNumberFlag | kInt64Flag), + kNumberUint64Flag = static_cast(kNumberType) | static_cast(kNumberFlag | kUint64Flag), + kNumberDoubleFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kDoubleFlag), + kNumberAnyFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag), + kConstStringFlag = static_cast(kStringType) | static_cast(kStringFlag), + kCopyStringFlag = static_cast(kStringType) | static_cast(kStringFlag | kCopyFlag), + kShortStringFlag = static_cast(kStringType) | static_cast(kStringFlag | kCopyFlag | kInlineStrFlag), + kObjectFlag = kObjectType, + kArrayFlag = kArrayType, + + kTypeMask = 0x07 + }; + + static const SizeType kDefaultArrayCapacity = RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY; + static const SizeType kDefaultObjectCapacity = RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY; + + struct Flag { +#if RAPIDJSON_48BITPOINTER_OPTIMIZATION + char payload[sizeof(SizeType) * 2 + 6]; // 2 x SizeType + lower 48-bit pointer +#elif RAPIDJSON_64BIT + char payload[sizeof(SizeType) * 2 + sizeof(void*) + 6]; // 6 padding bytes +#else + char payload[sizeof(SizeType) * 2 + sizeof(void*) + 2]; // 2 padding bytes +#endif + uint16_t flags; + }; + + struct String { + SizeType length; + SizeType hashcode; //!< reserved + const Ch* str; + }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode + + // implementation detail: ShortString can represent zero-terminated strings up to MaxSize chars + // (excluding the terminating zero) and store a value to determine the length of the contained + // string in the last character str[LenPos] by storing "MaxSize - length" there. If the string + // to store has the maximal length of MaxSize then str[LenPos] will be 0 and therefore act as + // the string terminator as well. For getting the string length back from that value just use + // "MaxSize - str[LenPos]". + // This allows to store 13-chars strings in 32-bit mode, 21-chars strings in 64-bit mode, + // 13-chars strings for RAPIDJSON_48BITPOINTER_OPTIMIZATION=1 inline (for `UTF8`-encoded strings). + struct ShortString { + enum { MaxChars = sizeof(static_cast(0)->payload) / sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize }; + Ch str[MaxChars]; + + inline static bool Usable(SizeType len) { return (MaxSize >= len); } + inline void SetLength(SizeType len) { str[LenPos] = static_cast(MaxSize - len); } + inline SizeType GetLength() const { return static_cast(MaxSize - str[LenPos]); } + }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode + + // By using proper binary layout, retrieval of different integer types do not need conversions. + union Number { +#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN + struct I { + int i; + char padding[4]; + }i; + struct U { + unsigned u; + char padding2[4]; + }u; +#else + struct I { + char padding[4]; + int i; + }i; + struct U { + char padding2[4]; + unsigned u; + }u; +#endif + int64_t i64; + uint64_t u64; + double d; + }; // 8 bytes + + struct ObjectData { + SizeType size; + SizeType capacity; + Member* members; + }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode + + struct ArrayData { + SizeType size; + SizeType capacity; + GenericValue* elements; + }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode + + union Data { + String s; + ShortString ss; + Number n; + ObjectData o; + ArrayData a; + Flag f; + }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION + + static RAPIDJSON_FORCEINLINE const Ch* DataString(const Data& data) { + return (data.f.flags & kInlineStrFlag) ? data.ss.str : RAPIDJSON_GETPOINTER(Ch, data.s.str); + } + static RAPIDJSON_FORCEINLINE SizeType DataStringLength(const Data& data) { + return (data.f.flags & kInlineStrFlag) ? data.ss.GetLength() : data.s.length; + } + + RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); } + RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); } + RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer() const { return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); } + RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); } + RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); } + RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); } + +#if RAPIDJSON_USE_MEMBERSMAP + + struct MapTraits { + struct Less { + bool operator()(const Data& s1, const Data& s2) const { + SizeType n1 = DataStringLength(s1), n2 = DataStringLength(s2); + int cmp = std::memcmp(DataString(s1), DataString(s2), sizeof(Ch) * (n1 < n2 ? n1 : n2)); + return cmp < 0 || (cmp == 0 && n1 < n2); + } + }; + typedef std::pair Pair; + typedef std::multimap > Map; + typedef typename Map::iterator Iterator; + }; + typedef typename MapTraits::Map Map; + typedef typename MapTraits::Less MapLess; + typedef typename MapTraits::Pair MapPair; + typedef typename MapTraits::Iterator MapIterator; + + // + // Layout of the members' map/array, re(al)located according to the needed capacity: + // + // {Map*}<>{capacity}<>{Member[capacity]}<>{MapIterator[capacity]} + // + // (where <> stands for the RAPIDJSON_ALIGN-ment, if needed) + // + + static RAPIDJSON_FORCEINLINE size_t GetMapLayoutSize(SizeType capacity) { + return RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType)) + + RAPIDJSON_ALIGN(capacity * sizeof(Member)) + + capacity * sizeof(MapIterator); + } + + static RAPIDJSON_FORCEINLINE SizeType &GetMapCapacity(Map* &map) { + return *reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*))); + } + + static RAPIDJSON_FORCEINLINE Member* GetMapMembers(Map* &map) { + return reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType))); + } + + static RAPIDJSON_FORCEINLINE MapIterator* GetMapIterators(Map* &map) { + return reinterpret_cast(reinterpret_cast(&map) + + RAPIDJSON_ALIGN(sizeof(Map*)) + + RAPIDJSON_ALIGN(sizeof(SizeType)) + + RAPIDJSON_ALIGN(GetMapCapacity(map) * sizeof(Member))); + } + + static RAPIDJSON_FORCEINLINE Map* &GetMap(Member* members) { + RAPIDJSON_ASSERT(members != 0); + return *reinterpret_cast(reinterpret_cast(members) - + RAPIDJSON_ALIGN(sizeof(SizeType)) - + RAPIDJSON_ALIGN(sizeof(Map*))); + } + + // Some compilers' debug mechanisms want all iterators to be destroyed, for their accounting.. + RAPIDJSON_FORCEINLINE MapIterator DropMapIterator(MapIterator& rhs) { +#if RAPIDJSON_HAS_CXX11 + MapIterator ret = std::move(rhs); +#else + MapIterator ret = rhs; +#endif + rhs.~MapIterator(); + return ret; + } + + Map* &DoReallocMap(Map** oldMap, SizeType newCapacity, Allocator& allocator) { + Map **newMap = static_cast(allocator.Malloc(GetMapLayoutSize(newCapacity))); + GetMapCapacity(*newMap) = newCapacity; + if (!oldMap) { + *newMap = new (allocator.Malloc(sizeof(Map))) Map(MapLess(), allocator); + } + else { + *newMap = *oldMap; + size_t count = (*oldMap)->size(); + std::memcpy(static_cast(GetMapMembers(*newMap)), + static_cast(GetMapMembers(*oldMap)), + count * sizeof(Member)); + MapIterator *oldIt = GetMapIterators(*oldMap), + *newIt = GetMapIterators(*newMap); + while (count--) { + new (&newIt[count]) MapIterator(DropMapIterator(oldIt[count])); + } + Allocator::Free(oldMap); + } + return *newMap; + } + + RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity, Allocator& allocator) { + return GetMapMembers(DoReallocMap(0, capacity, allocator)); + } + + void DoReserveMembers(SizeType newCapacity, Allocator& allocator) { + ObjectData& o = data_.o; + if (newCapacity > o.capacity) { + Member* oldMembers = GetMembersPointer(); + Map **oldMap = oldMembers ? &GetMap(oldMembers) : 0, + *&newMap = DoReallocMap(oldMap, newCapacity, allocator); + RAPIDJSON_SETPOINTER(Member, o.members, GetMapMembers(newMap)); + o.capacity = newCapacity; + } + } + + template + MemberIterator DoFindMember(const GenericValue& name) { + if (Member* members = GetMembersPointer()) { + Map* &map = GetMap(members); + MapIterator mit = map->find(reinterpret_cast(name.data_)); + if (mit != map->end()) { + return MemberIterator(&members[mit->second]); + } + } + return MemberEnd(); + } + + void DoClearMembers() { + if (Member* members = GetMembersPointer()) { + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + for (SizeType i = 0; i < data_.o.size; i++) { + map->erase(DropMapIterator(mit[i])); + members[i].~Member(); + } + data_.o.size = 0; + } + } + + void DoFreeMembers() { + if (Member* members = GetMembersPointer()) { + GetMap(members)->~Map(); + for (SizeType i = 0; i < data_.o.size; i++) { + members[i].~Member(); + } + if (Allocator::kNeedFree) { // Shortcut by Allocator's trait + Map** map = &GetMap(members); + Allocator::Free(*map); + Allocator::Free(map); + } + } + } + +#else // !RAPIDJSON_USE_MEMBERSMAP + + RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity, Allocator& allocator) { + return Malloc(allocator, capacity); + } + + void DoReserveMembers(SizeType newCapacity, Allocator& allocator) { + ObjectData& o = data_.o; + if (newCapacity > o.capacity) { + Member* newMembers = Realloc(allocator, GetMembersPointer(), o.capacity, newCapacity); + RAPIDJSON_SETPOINTER(Member, o.members, newMembers); + o.capacity = newCapacity; + } + } + + template + MemberIterator DoFindMember(const GenericValue& name) { + MemberIterator member = MemberBegin(); + for ( ; member != MemberEnd(); ++member) + if (name.StringEqual(member->name)) + break; + return member; + } + + void DoClearMembers() { + for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) + m->~Member(); + data_.o.size = 0; + } + + void DoFreeMembers() { + for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) + m->~Member(); + Allocator::Free(GetMembersPointer()); + } + +#endif // !RAPIDJSON_USE_MEMBERSMAP + + void DoAddMember(GenericValue& name, GenericValue& value, Allocator& allocator) { + ObjectData& o = data_.o; + if (o.size >= o.capacity) + DoReserveMembers(o.capacity ? (o.capacity + (o.capacity + 1) / 2) : kDefaultObjectCapacity, allocator); + Member* members = GetMembersPointer(); + Member* m = members + o.size; + m->name.RawAssign(name); + m->value.RawAssign(value); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + new (&mit[o.size]) MapIterator(map->insert(MapPair(m->name.data_, o.size))); +#endif + ++o.size; + } + + MemberIterator DoRemoveMember(MemberIterator m) { + ObjectData& o = data_.o; + Member* members = GetMembersPointer(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(members); + MapIterator* mit = GetMapIterators(map); + SizeType mpos = static_cast(&*m - members); + map->erase(DropMapIterator(mit[mpos])); +#endif + MemberIterator last(members + (o.size - 1)); + if (o.size > 1 && m != last) { +#if RAPIDJSON_USE_MEMBERSMAP + new (&mit[mpos]) MapIterator(DropMapIterator(mit[&*last - members])); + mit[mpos]->second = mpos; +#endif + *m = *last; // Move the last one to this place + } + else { + m->~Member(); // Only one left, just destroy + } + --o.size; + return m; + } + + MemberIterator DoEraseMembers(ConstMemberIterator first, ConstMemberIterator last) { + ObjectData& o = data_.o; + MemberIterator beg = MemberBegin(), + pos = beg + (first - beg), + end = MemberEnd(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(GetMembersPointer()); + MapIterator* mit = GetMapIterators(map); +#endif + for (MemberIterator itr = pos; itr != last; ++itr) { +#if RAPIDJSON_USE_MEMBERSMAP + map->erase(DropMapIterator(mit[itr - beg])); +#endif + itr->~Member(); + } +#if RAPIDJSON_USE_MEMBERSMAP + if (first != last) { + // Move remaining members/iterators + MemberIterator next = pos + (last - first); + for (MemberIterator itr = pos; next != end; ++itr, ++next) { + std::memcpy(static_cast(&*itr), &*next, sizeof(Member)); + SizeType mpos = static_cast(itr - beg); + new (&mit[mpos]) MapIterator(DropMapIterator(mit[next - beg])); + mit[mpos]->second = mpos; + } + } +#else + std::memmove(static_cast(&*pos), &*last, + static_cast(end - last) * sizeof(Member)); +#endif + o.size -= static_cast(last - first); + return pos; + } + + template + void DoCopyMembers(const GenericValue& rhs, Allocator& allocator, bool copyConstStrings) { + RAPIDJSON_ASSERT(rhs.GetType() == kObjectType); + + data_.f.flags = kObjectFlag; + SizeType count = rhs.data_.o.size; + Member* lm = DoAllocMembers(count, allocator); + const typename GenericValue::Member* rm = rhs.GetMembersPointer(); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(lm); + MapIterator* mit = GetMapIterators(map); +#endif + for (SizeType i = 0; i < count; i++) { + new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings); + new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings); +#if RAPIDJSON_USE_MEMBERSMAP + new (&mit[i]) MapIterator(map->insert(MapPair(lm[i].name.data_, i))); +#endif + } + data_.o.size = data_.o.capacity = count; + SetMembersPointer(lm); + } + + // Initialize this value as array with initial data, without calling destructor. + void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) { + data_.f.flags = kArrayFlag; + if (count) { + GenericValue* e = static_cast(allocator.Malloc(count * sizeof(GenericValue))); + SetElementsPointer(e); + std::memcpy(static_cast(e), values, count * sizeof(GenericValue)); + } + else + SetElementsPointer(0); + data_.a.size = data_.a.capacity = count; + } + + //! Initialize this value as object with initial data, without calling destructor. + void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) { + data_.f.flags = kObjectFlag; + if (count) { + Member* m = DoAllocMembers(count, allocator); + SetMembersPointer(m); + std::memcpy(static_cast(m), members, count * sizeof(Member)); +#if RAPIDJSON_USE_MEMBERSMAP + Map* &map = GetMap(m); + MapIterator* mit = GetMapIterators(map); + for (SizeType i = 0; i < count; i++) { + new (&mit[i]) MapIterator(map->insert(MapPair(m[i].name.data_, i))); + } +#endif + } + else + SetMembersPointer(0); + data_.o.size = data_.o.capacity = count; + } + + //! Initialize this value as constant string, without calling destructor. + void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT { + data_.f.flags = kConstStringFlag; + SetStringPointer(s); + data_.s.length = s.length; + } + + //! Initialize this value as copy string with initial data, without calling destructor. + void SetStringRaw(StringRefType s, Allocator& allocator) { + Ch* str = 0; + if (ShortString::Usable(s.length)) { + data_.f.flags = kShortStringFlag; + data_.ss.SetLength(s.length); + str = data_.ss.str; + } else { + data_.f.flags = kCopyStringFlag; + data_.s.length = s.length; + str = static_cast(allocator.Malloc((s.length + 1) * sizeof(Ch))); + SetStringPointer(str); + } + std::memcpy(str, s, s.length * sizeof(Ch)); + str[s.length] = '\0'; + } + + //! Assignment without calling destructor + void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT { + data_ = rhs.data_; + // data_.f.flags = rhs.data_.f.flags; + rhs.data_.f.flags = kNullFlag; + } + + template + bool StringEqual(const GenericValue& rhs) const { + RAPIDJSON_ASSERT(IsString()); + RAPIDJSON_ASSERT(rhs.IsString()); + + const SizeType len1 = GetStringLength(); + const SizeType len2 = rhs.GetStringLength(); + if(len1 != len2) { return false; } + + const Ch* const str1 = GetString(); + const Ch* const str2 = rhs.GetString(); + if(str1 == str2) { return true; } // fast path for constant string + + return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0); + } + + Data data_; +}; + +//! GenericValue with UTF8 encoding +typedef GenericValue > Value; + +/////////////////////////////////////////////////////////////////////////////// +// GenericDocument + +//! A document for parsing JSON text as DOM. +/*! + \note implements Handler concept + \tparam Encoding Encoding for both parsing and string storage. + \tparam Allocator Allocator for allocating memory for the DOM + \tparam StackAllocator Allocator for allocating memory for stack during parsing. + \warning Although GenericDocument inherits from GenericValue, the API does \b not provide any virtual functions, especially no virtual destructor. To avoid memory leaks, do not \c delete a GenericDocument object via a pointer to a GenericValue. +*/ +template +class GenericDocument : public GenericValue { +public: + typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding. + typedef GenericValue ValueType; //!< Value type of the document. + typedef Allocator AllocatorType; //!< Allocator type from template parameter. + typedef StackAllocator StackAllocatorType; //!< StackAllocator type from template parameter. + + //! Constructor + /*! Creates an empty document of specified type. + \param type Mandatory type of object to create. + \param allocator Optional allocator for allocating memory. + \param stackCapacity Optional initial capacity of stack in bytes. + \param stackAllocator Optional allocator for allocating memory for stack. + */ + explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : + GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() + { + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + } + + //! Constructor + /*! Creates an empty document which type is Null. + \param allocator Optional allocator for allocating memory. + \param stackCapacity Optional initial capacity of stack in bytes. + \param stackAllocator Optional allocator for allocating memory for stack. + */ + GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : + allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() + { + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move constructor in C++11 + GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT + : ValueType(std::forward(rhs)), // explicit cast to avoid prohibited move from Document + allocator_(rhs.allocator_), + ownAllocator_(rhs.ownAllocator_), + stack_(std::move(rhs.stack_)), + parseResult_(rhs.parseResult_) + { + rhs.allocator_ = 0; + rhs.ownAllocator_ = 0; + rhs.parseResult_ = ParseResult(); + } +#endif + + ~GenericDocument() { + // Clear the ::ValueType before ownAllocator is destroyed, ~ValueType() + // runs last and may access its elements or members which would be freed + // with an allocator like MemoryPoolAllocator (CrtAllocator does not + // free its data when destroyed, but MemoryPoolAllocator does). + if (ownAllocator_) { + ValueType::SetNull(); + } + Destroy(); + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move assignment in C++11 + GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT + { + // The cast to ValueType is necessary here, because otherwise it would + // attempt to call GenericValue's templated assignment operator. + ValueType::operator=(std::forward(rhs)); + + // Calling the destructor here would prematurely call stack_'s destructor + Destroy(); + + allocator_ = rhs.allocator_; + ownAllocator_ = rhs.ownAllocator_; + stack_ = std::move(rhs.stack_); + parseResult_ = rhs.parseResult_; + + rhs.allocator_ = 0; + rhs.ownAllocator_ = 0; + rhs.parseResult_ = ParseResult(); + + return *this; + } +#endif + + //! Exchange the contents of this document with those of another. + /*! + \param rhs Another document. + \note Constant complexity. + \see GenericValue::Swap + */ + GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT { + ValueType::Swap(rhs); + stack_.Swap(rhs.stack_); + internal::Swap(allocator_, rhs.allocator_); + internal::Swap(ownAllocator_, rhs.ownAllocator_); + internal::Swap(parseResult_, rhs.parseResult_); + return *this; + } + + // Allow Swap with ValueType. + // Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names. + using ValueType::Swap; + + //! free-standing swap function helper + /*! + Helper function to enable support for common swap implementation pattern based on \c std::swap: + \code + void swap(MyClass& a, MyClass& b) { + using std::swap; + swap(a.doc, b.doc); + // ... + } + \endcode + \see Swap() + */ + friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } + + //! Populate this document by a generator which produces SAX events. + /*! \tparam Generator A functor with bool f(Handler) prototype. + \param g Generator functor which sends SAX events to the parameter. + \return The document itself for fluent API. + */ + template + GenericDocument& Populate(Generator& g) { + ClearStackOnExit scope(*this); + if (g(*this)) { + RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object + ValueType::operator=(*stack_.template Pop(1));// Move value from stack to document + } + return *this; + } + + //!@name Parse from stream + //!@{ + + //! Parse JSON text from an input stream (with Encoding conversion) + /*! \tparam parseFlags Combination of \ref ParseFlag. + \tparam SourceEncoding Encoding of input stream + \tparam InputStream Type of input stream, implementing Stream concept + \param is Input stream to be parsed. + \return The document itself for fluent API. + */ + template + GenericDocument& ParseStream(InputStream& is) { + GenericReader reader( + stack_.HasAllocator() ? &stack_.GetAllocator() : 0); + ClearStackOnExit scope(*this); + parseResult_ = reader.template Parse(is, *this); + if (parseResult_) { + RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object + ValueType::operator=(*stack_.template Pop(1));// Move value from stack to document + } + return *this; + } + + //! Parse JSON text from an input stream + /*! \tparam parseFlags Combination of \ref ParseFlag. + \tparam InputStream Type of input stream, implementing Stream concept + \param is Input stream to be parsed. + \return The document itself for fluent API. + */ + template + GenericDocument& ParseStream(InputStream& is) { + return ParseStream(is); + } + + //! Parse JSON text from an input stream (with \ref kParseDefaultFlags) + /*! \tparam InputStream Type of input stream, implementing Stream concept + \param is Input stream to be parsed. + \return The document itself for fluent API. + */ + template + GenericDocument& ParseStream(InputStream& is) { + return ParseStream(is); + } + //!@} + + //!@name Parse in-place from mutable string + //!@{ + + //! Parse JSON text from a mutable string + /*! \tparam parseFlags Combination of \ref ParseFlag. + \param str Mutable zero-terminated string to be parsed. + \return The document itself for fluent API. + */ + template + GenericDocument& ParseInsitu(Ch* str) { + GenericInsituStringStream s(str); + return ParseStream(s); + } + + //! Parse JSON text from a mutable string (with \ref kParseDefaultFlags) + /*! \param str Mutable zero-terminated string to be parsed. + \return The document itself for fluent API. + */ + GenericDocument& ParseInsitu(Ch* str) { + return ParseInsitu(str); + } + //!@} + + //!@name Parse from read-only string + //!@{ + + //! Parse JSON text from a read-only string (with Encoding conversion) + /*! \tparam parseFlags Combination of \ref ParseFlag (must not contain \ref kParseInsituFlag). + \tparam SourceEncoding Transcoding from input Encoding + \param str Read-only zero-terminated string to be parsed. + */ + template + GenericDocument& Parse(const typename SourceEncoding::Ch* str) { + RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag)); + GenericStringStream s(str); + return ParseStream(s); + } + + //! Parse JSON text from a read-only string + /*! \tparam parseFlags Combination of \ref ParseFlag (must not contain \ref kParseInsituFlag). + \param str Read-only zero-terminated string to be parsed. + */ + template + GenericDocument& Parse(const Ch* str) { + return Parse(str); + } + + //! Parse JSON text from a read-only string (with \ref kParseDefaultFlags) + /*! \param str Read-only zero-terminated string to be parsed. + */ + GenericDocument& Parse(const Ch* str) { + return Parse(str); + } + + template + GenericDocument& Parse(const typename SourceEncoding::Ch* str, size_t length) { + RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag)); + MemoryStream ms(reinterpret_cast(str), length * sizeof(typename SourceEncoding::Ch)); + EncodedInputStream is(ms); + ParseStream(is); + return *this; + } + + template + GenericDocument& Parse(const Ch* str, size_t length) { + return Parse(str, length); + } + + GenericDocument& Parse(const Ch* str, size_t length) { + return Parse(str, length); + } + +#if RAPIDJSON_HAS_STDSTRING + template + GenericDocument& Parse(const std::basic_string& str) { + // c_str() is constant complexity according to standard. Should be faster than Parse(const char*, size_t) + return Parse(str.c_str()); + } + + template + GenericDocument& Parse(const std::basic_string& str) { + return Parse(str.c_str()); + } + + GenericDocument& Parse(const std::basic_string& str) { + return Parse(str); + } +#endif // RAPIDJSON_HAS_STDSTRING + + //!@} + + //!@name Handling parse errors + //!@{ + + //! Whether a parse error has occurred in the last parsing. + bool HasParseError() const { return parseResult_.IsError(); } + + //! Get the \ref ParseErrorCode of last parsing. + ParseErrorCode GetParseError() const { return parseResult_.Code(); } + + //! Get the position of last parsing error in input, 0 otherwise. + size_t GetErrorOffset() const { return parseResult_.Offset(); } + + //! Implicit conversion to get the last parse result +#ifndef __clang // -Wdocumentation + /*! \return \ref ParseResult of the last parse operation + + \code + Document doc; + ParseResult ok = doc.Parse(json); + if (!ok) + printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset()); + \endcode + */ +#endif + operator ParseResult() const { return parseResult_; } + //!@} + + //! Get the allocator of this document. + Allocator& GetAllocator() { + RAPIDJSON_ASSERT(allocator_); + return *allocator_; + } + + //! Get the capacity of stack in bytes. + size_t GetStackCapacity() const { return stack_.GetCapacity(); } + +private: + // clear stack on any exit from ParseStream, e.g. due to exception + struct ClearStackOnExit { + explicit ClearStackOnExit(GenericDocument& d) : d_(d) {} + ~ClearStackOnExit() { d_.ClearStack(); } + private: + ClearStackOnExit(const ClearStackOnExit&); + ClearStackOnExit& operator=(const ClearStackOnExit&); + GenericDocument& d_; + }; + + // callers of the following private Handler functions + // template friend class GenericReader; // for parsing + template friend class GenericValue; // for deep copying + +public: + // Implementation of Handler + bool Null() { new (stack_.template Push()) ValueType(); return true; } + bool Bool(bool b) { new (stack_.template Push()) ValueType(b); return true; } + bool Int(int i) { new (stack_.template Push()) ValueType(i); return true; } + bool Uint(unsigned i) { new (stack_.template Push()) ValueType(i); return true; } + bool Int64(int64_t i) { new (stack_.template Push()) ValueType(i); return true; } + bool Uint64(uint64_t i) { new (stack_.template Push()) ValueType(i); return true; } + bool Double(double d) { new (stack_.template Push()) ValueType(d); return true; } + + bool RawNumber(const Ch* str, SizeType length, bool copy) { + if (copy) + new (stack_.template Push()) ValueType(str, length, GetAllocator()); + else + new (stack_.template Push()) ValueType(str, length); + return true; + } + + bool String(const Ch* str, SizeType length, bool copy) { + if (copy) + new (stack_.template Push()) ValueType(str, length, GetAllocator()); + else + new (stack_.template Push()) ValueType(str, length); + return true; + } + + bool StartObject() { new (stack_.template Push()) ValueType(kObjectType); return true; } + + bool Key(const Ch* str, SizeType length, bool copy) { return String(str, length, copy); } + + bool EndObject(SizeType memberCount) { + typename ValueType::Member* members = stack_.template Pop(memberCount); + stack_.template Top()->SetObjectRaw(members, memberCount, GetAllocator()); + return true; + } + + bool StartArray() { new (stack_.template Push()) ValueType(kArrayType); return true; } + + bool EndArray(SizeType elementCount) { + ValueType* elements = stack_.template Pop(elementCount); + stack_.template Top()->SetArrayRaw(elements, elementCount, GetAllocator()); + return true; + } + +private: + //! Prohibit copying + GenericDocument(const GenericDocument&); + //! Prohibit assignment + GenericDocument& operator=(const GenericDocument&); + + void ClearStack() { + if (Allocator::kNeedFree) + while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects) + (stack_.template Pop(1))->~ValueType(); + else + stack_.Clear(); + stack_.ShrinkToFit(); + } + + void Destroy() { + RAPIDJSON_DELETE(ownAllocator_); + } + + static const size_t kDefaultStackCapacity = 1024; + Allocator* allocator_; + Allocator* ownAllocator_; + internal::Stack stack_; + ParseResult parseResult_; +}; + +//! GenericDocument with UTF8 encoding +typedef GenericDocument > Document; + + +//! Helper class for accessing Value of array type. +/*! + Instance of this helper class is obtained by \c GenericValue::GetArray(). + In addition to all APIs for array type, it provides range-based for loop if \c RAPIDJSON_HAS_CXX11_RANGE_FOR=1. +*/ +template +class GenericArray { +public: + typedef GenericArray ConstArray; + typedef GenericArray Array; + typedef ValueT PlainType; + typedef typename internal::MaybeAddConst::Type ValueType; + typedef ValueType* ValueIterator; // This may be const or non-const iterator + typedef const ValueT* ConstValueIterator; + typedef typename ValueType::AllocatorType AllocatorType; + typedef typename ValueType::StringRefType StringRefType; + + template + friend class GenericValue; + + GenericArray(const GenericArray& rhs) : value_(rhs.value_) {} + GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; } + ~GenericArray() {} + + operator ValueType&() const { return value_; } + SizeType Size() const { return value_.Size(); } + SizeType Capacity() const { return value_.Capacity(); } + bool Empty() const { return value_.Empty(); } + void Clear() const { value_.Clear(); } + ValueType& operator[](SizeType index) const { return value_[index]; } + ValueIterator Begin() const { return value_.Begin(); } + ValueIterator End() const { return value_.End(); } + GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const { value_.Reserve(newCapacity, allocator); return *this; } + GenericArray PushBack(ValueType& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; } +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericArray PushBack(ValueType&& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; } +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericArray PushBack(StringRefType value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; } + template RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (const GenericArray&)) PushBack(T value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; } + GenericArray PopBack() const { value_.PopBack(); return *this; } + ValueIterator Erase(ConstValueIterator pos) const { return value_.Erase(pos); } + ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const { return value_.Erase(first, last); } + +#if RAPIDJSON_HAS_CXX11_RANGE_FOR + ValueIterator begin() const { return value_.Begin(); } + ValueIterator end() const { return value_.End(); } +#endif + +private: + GenericArray(); + GenericArray(ValueType& value) : value_(value) {} + ValueType& value_; +}; + +//! Helper class for accessing Value of object type. +/*! + Instance of this helper class is obtained by \c GenericValue::GetObject(). + In addition to all APIs for array type, it provides range-based for loop if \c RAPIDJSON_HAS_CXX11_RANGE_FOR=1. +*/ +template +class GenericObject { +public: + typedef GenericObject ConstObject; + typedef GenericObject Object; + typedef ValueT PlainType; + typedef typename internal::MaybeAddConst::Type ValueType; + typedef GenericMemberIterator MemberIterator; // This may be const or non-const iterator + typedef GenericMemberIterator ConstMemberIterator; + typedef typename ValueType::AllocatorType AllocatorType; + typedef typename ValueType::StringRefType StringRefType; + typedef typename ValueType::EncodingType EncodingType; + typedef typename ValueType::Ch Ch; + + template + friend class GenericValue; + + GenericObject(const GenericObject& rhs) : value_(rhs.value_) {} + GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; } + ~GenericObject() {} + + operator ValueType&() const { return value_; } + SizeType MemberCount() const { return value_.MemberCount(); } + SizeType MemberCapacity() const { return value_.MemberCapacity(); } + bool ObjectEmpty() const { return value_.ObjectEmpty(); } + template ValueType& operator[](T* name) const { return value_[name]; } + template ValueType& operator[](const GenericValue& name) const { return value_[name]; } +#if RAPIDJSON_HAS_STDSTRING + ValueType& operator[](const std::basic_string& name) const { return value_[name]; } +#endif + MemberIterator MemberBegin() const { return value_.MemberBegin(); } + MemberIterator MemberEnd() const { return value_.MemberEnd(); } + GenericObject MemberReserve(SizeType newCapacity, AllocatorType &allocator) const { value_.MemberReserve(newCapacity, allocator); return *this; } + bool HasMember(const Ch* name) const { return value_.HasMember(name); } +#if RAPIDJSON_HAS_STDSTRING + bool HasMember(const std::basic_string& name) const { return value_.HasMember(name); } +#endif + template bool HasMember(const GenericValue& name) const { return value_.HasMember(name); } + MemberIterator FindMember(const Ch* name) const { return value_.FindMember(name); } + template MemberIterator FindMember(const GenericValue& name) const { return value_.FindMember(name); } +#if RAPIDJSON_HAS_STDSTRING + MemberIterator FindMember(const std::basic_string& name) const { return value_.FindMember(name); } +#endif + GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } +#if RAPIDJSON_HAS_STDSTRING + GenericObject AddMember(ValueType& name, std::basic_string& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } +#endif + template RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (ValueType&)) AddMember(ValueType& name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + template RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (GenericObject)) AddMember(StringRefType name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; } + void RemoveAllMembers() { value_.RemoveAllMembers(); } + bool RemoveMember(const Ch* name) const { return value_.RemoveMember(name); } +#if RAPIDJSON_HAS_STDSTRING + bool RemoveMember(const std::basic_string& name) const { return value_.RemoveMember(name); } +#endif + template bool RemoveMember(const GenericValue& name) const { return value_.RemoveMember(name); } + MemberIterator RemoveMember(MemberIterator m) const { return value_.RemoveMember(m); } + MemberIterator EraseMember(ConstMemberIterator pos) const { return value_.EraseMember(pos); } + MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const { return value_.EraseMember(first, last); } + bool EraseMember(const Ch* name) const { return value_.EraseMember(name); } +#if RAPIDJSON_HAS_STDSTRING + bool EraseMember(const std::basic_string& name) const { return EraseMember(ValueType(StringRef(name))); } +#endif + template bool EraseMember(const GenericValue& name) const { return value_.EraseMember(name); } + +#if RAPIDJSON_HAS_CXX11_RANGE_FOR + MemberIterator begin() const { return value_.MemberBegin(); } + MemberIterator end() const { return value_.MemberEnd(); } +#endif + +private: + GenericObject(); + GenericObject(ValueType& value) : value_(value) {} + ValueType& value_; +}; + +RAPIDJSON_NAMESPACE_END +RAPIDJSON_DIAG_POP + +#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#pragma pop_macro("GetObject") +#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED +#endif + +#endif // RAPIDJSON_DOCUMENT_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/encodedstream.h b/components/thorvg-main/src/loaders/lottie/rapidjson/encodedstream.h new file mode 100644 index 0000000..cf046b8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/encodedstream.h @@ -0,0 +1,299 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ENCODEDSTREAM_H_ +#define RAPIDJSON_ENCODEDSTREAM_H_ + +#include "stream.h" +#include "memorystream.h" + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Input byte stream wrapper with a statically bound encoding. +/*! + \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE. + \tparam InputByteStream Type of input byte stream. For example, FileReadStream. +*/ +template +class EncodedInputStream { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); +public: + typedef typename Encoding::Ch Ch; + + EncodedInputStream(InputByteStream& is) : is_(is) { + current_ = Encoding::TakeBOM(is_); + } + + Ch Peek() const { return current_; } + Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; } + size_t Tell() const { return is_.Tell(); } + + // Not implemented + void Put(Ch) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + EncodedInputStream(const EncodedInputStream&); + EncodedInputStream& operator=(const EncodedInputStream&); + + InputByteStream& is_; + Ch current_; +}; + +//! Specialized for UTF8 MemoryStream. +template <> +class EncodedInputStream, MemoryStream> { +public: + typedef UTF8<>::Ch Ch; + + EncodedInputStream(MemoryStream& is) : is_(is) { + if (static_cast(is_.Peek()) == 0xEFu) is_.Take(); + if (static_cast(is_.Peek()) == 0xBBu) is_.Take(); + if (static_cast(is_.Peek()) == 0xBFu) is_.Take(); + } + Ch Peek() const { return is_.Peek(); } + Ch Take() { return is_.Take(); } + size_t Tell() const { return is_.Tell(); } + + // Not implemented + void Put(Ch) {} + void Flush() {} + Ch* PutBegin() { return 0; } + size_t PutEnd(Ch*) { return 0; } + + MemoryStream& is_; + +private: + EncodedInputStream(const EncodedInputStream&); + EncodedInputStream& operator=(const EncodedInputStream&); +}; + +//! Output byte stream wrapper with statically bound encoding. +/*! + \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE. + \tparam OutputByteStream Type of input byte stream. For example, FileWriteStream. +*/ +template +class EncodedOutputStream { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); +public: + typedef typename Encoding::Ch Ch; + + EncodedOutputStream(OutputByteStream& os, bool putBOM = true) : os_(os) { + if (putBOM) + Encoding::PutBOM(os_); + } + + void Put(Ch c) { Encoding::Put(os_, c); } + void Flush() { os_.Flush(); } + + // Not implemented + Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;} + Ch Take() { RAPIDJSON_ASSERT(false); return 0;} + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + EncodedOutputStream(const EncodedOutputStream&); + EncodedOutputStream& operator=(const EncodedOutputStream&); + + OutputByteStream& os_; +}; + +#define RAPIDJSON_ENCODINGS_FUNC(x) UTF8::x, UTF16LE::x, UTF16BE::x, UTF32LE::x, UTF32BE::x + +//! Input stream wrapper with dynamically bound encoding and automatic encoding detection. +/*! + \tparam CharType Type of character for reading. + \tparam InputByteStream type of input byte stream to be wrapped. +*/ +template +class AutoUTFInputStream { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); +public: + typedef CharType Ch; + + //! Constructor. + /*! + \param is input stream to be wrapped. + \param type UTF encoding type if it is not detected from the stream. + */ + AutoUTFInputStream(InputByteStream& is, UTFType type = kUTF8) : is_(&is), type_(type), hasBOM_(false) { + RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); + DetectType(); + static const TakeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Take) }; + takeFunc_ = f[type_]; + current_ = takeFunc_(*is_); + } + + UTFType GetType() const { return type_; } + bool HasBOM() const { return hasBOM_; } + + Ch Peek() const { return current_; } + Ch Take() { Ch c = current_; current_ = takeFunc_(*is_); return c; } + size_t Tell() const { return is_->Tell(); } + + // Not implemented + void Put(Ch) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + AutoUTFInputStream(const AutoUTFInputStream&); + AutoUTFInputStream& operator=(const AutoUTFInputStream&); + + // Detect encoding type with BOM or RFC 4627 + void DetectType() { + // BOM (Byte Order Mark): + // 00 00 FE FF UTF-32BE + // FF FE 00 00 UTF-32LE + // FE FF UTF-16BE + // FF FE UTF-16LE + // EF BB BF UTF-8 + + const unsigned char* c = reinterpret_cast(is_->Peek4()); + if (!c) + return; + + unsigned bom = static_cast(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24)); + hasBOM_ = false; + if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); } + else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); } + else if ((bom & 0xFFFF) == 0xFFFE) { type_ = kUTF16BE; hasBOM_ = true; is_->Take(); is_->Take(); } + else if ((bom & 0xFFFF) == 0xFEFF) { type_ = kUTF16LE; hasBOM_ = true; is_->Take(); is_->Take(); } + else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ = kUTF8; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); } + + // RFC 4627: Section 3 + // "Since the first two characters of a JSON text will always be ASCII + // characters [RFC0020], it is possible to determine whether an octet + // stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking + // at the pattern of nulls in the first four octets." + // 00 00 00 xx UTF-32BE + // 00 xx 00 xx UTF-16BE + // xx 00 00 00 UTF-32LE + // xx 00 xx 00 UTF-16LE + // xx xx xx xx UTF-8 + + if (!hasBOM_) { + int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0); + switch (pattern) { + case 0x08: type_ = kUTF32BE; break; + case 0x0A: type_ = kUTF16BE; break; + case 0x01: type_ = kUTF32LE; break; + case 0x05: type_ = kUTF16LE; break; + case 0x0F: type_ = kUTF8; break; + default: break; // Use type defined by user. + } + } + + // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. + if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); + if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); + } + + typedef Ch (*TakeFunc)(InputByteStream& is); + InputByteStream* is_; + UTFType type_; + Ch current_; + TakeFunc takeFunc_; + bool hasBOM_; +}; + +//! Output stream wrapper with dynamically bound encoding and automatic encoding detection. +/*! + \tparam CharType Type of character for writing. + \tparam OutputByteStream type of output byte stream to be wrapped. +*/ +template +class AutoUTFOutputStream { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); +public: + typedef CharType Ch; + + //! Constructor. + /*! + \param os output stream to be wrapped. + \param type UTF encoding type. + \param putBOM Whether to write BOM at the beginning of the stream. + */ + AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) { + RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); + + // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. + if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); + if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); + + static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; + putFunc_ = f[type_]; + + if (putBOM) + PutBOM(); + } + + UTFType GetType() const { return type_; } + + void Put(Ch c) { putFunc_(*os_, c); } + void Flush() { os_->Flush(); } + + // Not implemented + Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;} + Ch Take() { RAPIDJSON_ASSERT(false); return 0;} + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + AutoUTFOutputStream(const AutoUTFOutputStream&); + AutoUTFOutputStream& operator=(const AutoUTFOutputStream&); + + void PutBOM() { + typedef void (*PutBOMFunc)(OutputByteStream&); + static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) }; + f[type_](*os_); + } + + typedef void (*PutFunc)(OutputByteStream&, Ch); + + OutputByteStream* os_; + UTFType type_; + PutFunc putFunc_; +}; + +#undef RAPIDJSON_ENCODINGS_FUNC + +RAPIDJSON_NAMESPACE_END + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_FILESTREAM_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/encodings.h b/components/thorvg-main/src/loaders/lottie/rapidjson/encodings.h new file mode 100644 index 0000000..dbb0a4e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/encodings.h @@ -0,0 +1,716 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ENCODINGS_H_ +#define RAPIDJSON_ENCODINGS_H_ + +#include "rapidjson.h" + +#if defined(_MSC_VER) && !defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data +RAPIDJSON_DIAG_OFF(4702) // unreachable code +#elif defined(__GNUC__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +RAPIDJSON_DIAG_OFF(overflow) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// Encoding + +/*! \class rapidjson::Encoding + \brief Concept for encoding of Unicode characters. + +\code +concept Encoding { + typename Ch; //! Type of character. A "character" is actually a code unit in unicode's definition. + + enum { supportUnicode = 1 }; // or 0 if not supporting unicode + + //! \brief Encode a Unicode codepoint to an output stream. + //! \param os Output stream. + //! \param codepoint An unicode codepoint, ranging from 0x0 to 0x10FFFF inclusively. + template + static void Encode(OutputStream& os, unsigned codepoint); + + //! \brief Decode a Unicode codepoint from an input stream. + //! \param is Input stream. + //! \param codepoint Output of the unicode codepoint. + //! \return true if a valid codepoint can be decoded from the stream. + template + static bool Decode(InputStream& is, unsigned* codepoint); + + //! \brief Validate one Unicode codepoint from an encoded stream. + //! \param is Input stream to obtain codepoint. + //! \param os Output for copying one codepoint. + //! \return true if it is valid. + //! \note This function just validating and copying the codepoint without actually decode it. + template + static bool Validate(InputStream& is, OutputStream& os); + + // The following functions are deal with byte streams. + + //! Take a character from input byte stream, skip BOM if exist. + template + static CharType TakeBOM(InputByteStream& is); + + //! Take a character from input byte stream. + template + static Ch Take(InputByteStream& is); + + //! Put BOM to output byte stream. + template + static void PutBOM(OutputByteStream& os); + + //! Put a character to output byte stream. + template + static void Put(OutputByteStream& os, Ch c); +}; +\endcode +*/ + +/////////////////////////////////////////////////////////////////////////////// +// UTF8 + +//! UTF-8 encoding. +/*! http://en.wikipedia.org/wiki/UTF-8 + http://tools.ietf.org/html/rfc3629 + \tparam CharType Code unit for storing 8-bit UTF-8 data. Default is char. + \note implements Encoding concept +*/ +template +struct UTF8 { + typedef CharType Ch; + + enum { supportUnicode = 1 }; + + template + static void Encode(OutputStream& os, unsigned codepoint) { + if (codepoint <= 0x7F) + os.Put(static_cast(codepoint & 0xFF)); + else if (codepoint <= 0x7FF) { + os.Put(static_cast(0xC0 | ((codepoint >> 6) & 0xFF))); + os.Put(static_cast(0x80 | ((codepoint & 0x3F)))); + } + else if (codepoint <= 0xFFFF) { + os.Put(static_cast(0xE0 | ((codepoint >> 12) & 0xFF))); + os.Put(static_cast(0x80 | ((codepoint >> 6) & 0x3F))); + os.Put(static_cast(0x80 | (codepoint & 0x3F))); + } + else { + RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); + os.Put(static_cast(0xF0 | ((codepoint >> 18) & 0xFF))); + os.Put(static_cast(0x80 | ((codepoint >> 12) & 0x3F))); + os.Put(static_cast(0x80 | ((codepoint >> 6) & 0x3F))); + os.Put(static_cast(0x80 | (codepoint & 0x3F))); + } + } + + template + static void EncodeUnsafe(OutputStream& os, unsigned codepoint) { + if (codepoint <= 0x7F) + PutUnsafe(os, static_cast(codepoint & 0xFF)); + else if (codepoint <= 0x7FF) { + PutUnsafe(os, static_cast(0xC0 | ((codepoint >> 6) & 0xFF))); + PutUnsafe(os, static_cast(0x80 | ((codepoint & 0x3F)))); + } + else if (codepoint <= 0xFFFF) { + PutUnsafe(os, static_cast(0xE0 | ((codepoint >> 12) & 0xFF))); + PutUnsafe(os, static_cast(0x80 | ((codepoint >> 6) & 0x3F))); + PutUnsafe(os, static_cast(0x80 | (codepoint & 0x3F))); + } + else { + RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); + PutUnsafe(os, static_cast(0xF0 | ((codepoint >> 18) & 0xFF))); + PutUnsafe(os, static_cast(0x80 | ((codepoint >> 12) & 0x3F))); + PutUnsafe(os, static_cast(0x80 | ((codepoint >> 6) & 0x3F))); + PutUnsafe(os, static_cast(0x80 | (codepoint & 0x3F))); + } + } + + template + static bool Decode(InputStream& is, unsigned* codepoint) { +#define RAPIDJSON_COPY() c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast(c) & 0x3Fu) +#define RAPIDJSON_TRANS(mask) result &= ((GetRange(static_cast(c)) & mask) != 0) +#define RAPIDJSON_TAIL() RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70) + typename InputStream::Ch c = is.Take(); + if (!(c & 0x80)) { + *codepoint = static_cast(c); + return true; + } + + unsigned char type = GetRange(static_cast(c)); + if (type >= 32) { + *codepoint = 0; + } else { + *codepoint = (0xFFu >> type) & static_cast(c); + } + bool result = true; + switch (type) { + case 2: RAPIDJSON_TAIL(); return result; + case 3: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + case 4: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x50); RAPIDJSON_TAIL(); return result; + case 5: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x10); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + case 6: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + case 10: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x20); RAPIDJSON_TAIL(); return result; + case 11: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x60); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + default: return false; + } +#undef RAPIDJSON_COPY +#undef RAPIDJSON_TRANS +#undef RAPIDJSON_TAIL + } + + template + static bool Validate(InputStream& is, OutputStream& os) { +#define RAPIDJSON_COPY() os.Put(c = is.Take()) +#define RAPIDJSON_TRANS(mask) result &= ((GetRange(static_cast(c)) & mask) != 0) +#define RAPIDJSON_TAIL() RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70) + Ch c; + RAPIDJSON_COPY(); + if (!(c & 0x80)) + return true; + + bool result = true; + switch (GetRange(static_cast(c))) { + case 2: RAPIDJSON_TAIL(); return result; + case 3: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + case 4: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x50); RAPIDJSON_TAIL(); return result; + case 5: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x10); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + case 6: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + case 10: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x20); RAPIDJSON_TAIL(); return result; + case 11: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x60); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result; + default: return false; + } +#undef RAPIDJSON_COPY +#undef RAPIDJSON_TRANS +#undef RAPIDJSON_TAIL + } + + static unsigned char GetRange(unsigned char c) { + // Referring to DFA of http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ + // With new mapping 1 -> 0x10, 7 -> 0x20, 9 -> 0x40, such that AND operation can test multiple types. + static const unsigned char type[] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8, + }; + return type[c]; + } + + template + static CharType TakeBOM(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + typename InputByteStream::Ch c = Take(is); + if (static_cast(c) != 0xEFu) return c; + c = is.Take(); + if (static_cast(c) != 0xBBu) return c; + c = is.Take(); + if (static_cast(c) != 0xBFu) return c; + c = is.Take(); + return c; + } + + template + static Ch Take(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + return static_cast(is.Take()); + } + + template + static void PutBOM(OutputByteStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(0xEFu)); + os.Put(static_cast(0xBBu)); + os.Put(static_cast(0xBFu)); + } + + template + static void Put(OutputByteStream& os, Ch c) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(c)); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// UTF16 + +//! UTF-16 encoding. +/*! http://en.wikipedia.org/wiki/UTF-16 + http://tools.ietf.org/html/rfc2781 + \tparam CharType Type for storing 16-bit UTF-16 data. Default is wchar_t. C++11 may use char16_t instead. + \note implements Encoding concept + + \note For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness. + For streaming, use UTF16LE and UTF16BE, which handle endianness. +*/ +template +struct UTF16 { + typedef CharType Ch; + RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 2); + + enum { supportUnicode = 1 }; + + template + static void Encode(OutputStream& os, unsigned codepoint) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2); + if (codepoint <= 0xFFFF) { + RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair + os.Put(static_cast(codepoint)); + } + else { + RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); + unsigned v = codepoint - 0x10000; + os.Put(static_cast((v >> 10) | 0xD800)); + os.Put(static_cast((v & 0x3FF) | 0xDC00)); + } + } + + + template + static void EncodeUnsafe(OutputStream& os, unsigned codepoint) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2); + if (codepoint <= 0xFFFF) { + RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair + PutUnsafe(os, static_cast(codepoint)); + } + else { + RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); + unsigned v = codepoint - 0x10000; + PutUnsafe(os, static_cast((v >> 10) | 0xD800)); + PutUnsafe(os, static_cast((v & 0x3FF) | 0xDC00)); + } + } + + template + static bool Decode(InputStream& is, unsigned* codepoint) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2); + typename InputStream::Ch c = is.Take(); + if (c < 0xD800 || c > 0xDFFF) { + *codepoint = static_cast(c); + return true; + } + else if (c <= 0xDBFF) { + *codepoint = (static_cast(c) & 0x3FF) << 10; + c = is.Take(); + *codepoint |= (static_cast(c) & 0x3FF); + *codepoint += 0x10000; + return c >= 0xDC00 && c <= 0xDFFF; + } + return false; + } + + template + static bool Validate(InputStream& is, OutputStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2); + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2); + typename InputStream::Ch c; + os.Put(static_cast(c = is.Take())); + if (c < 0xD800 || c > 0xDFFF) + return true; + else if (c <= 0xDBFF) { + os.Put(c = is.Take()); + return c >= 0xDC00 && c <= 0xDFFF; + } + return false; + } +}; + +//! UTF-16 little endian encoding. +template +struct UTF16LE : UTF16 { + template + static CharType TakeBOM(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + CharType c = Take(is); + return static_cast(c) == 0xFEFFu ? Take(is) : c; + } + + template + static CharType Take(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + unsigned c = static_cast(is.Take()); + c |= static_cast(static_cast(is.Take())) << 8; + return static_cast(c); + } + + template + static void PutBOM(OutputByteStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(0xFFu)); + os.Put(static_cast(0xFEu)); + } + + template + static void Put(OutputByteStream& os, CharType c) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(static_cast(c) & 0xFFu)); + os.Put(static_cast((static_cast(c) >> 8) & 0xFFu)); + } +}; + +//! UTF-16 big endian encoding. +template +struct UTF16BE : UTF16 { + template + static CharType TakeBOM(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + CharType c = Take(is); + return static_cast(c) == 0xFEFFu ? Take(is) : c; + } + + template + static CharType Take(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + unsigned c = static_cast(static_cast(is.Take())) << 8; + c |= static_cast(static_cast(is.Take())); + return static_cast(c); + } + + template + static void PutBOM(OutputByteStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(0xFEu)); + os.Put(static_cast(0xFFu)); + } + + template + static void Put(OutputByteStream& os, CharType c) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast((static_cast(c) >> 8) & 0xFFu)); + os.Put(static_cast(static_cast(c) & 0xFFu)); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// UTF32 + +//! UTF-32 encoding. +/*! http://en.wikipedia.org/wiki/UTF-32 + \tparam CharType Type for storing 32-bit UTF-32 data. Default is unsigned. C++11 may use char32_t instead. + \note implements Encoding concept + + \note For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness. + For streaming, use UTF32LE and UTF32BE, which handle endianness. +*/ +template +struct UTF32 { + typedef CharType Ch; + RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 4); + + enum { supportUnicode = 1 }; + + template + static void Encode(OutputStream& os, unsigned codepoint) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4); + RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); + os.Put(codepoint); + } + + template + static void EncodeUnsafe(OutputStream& os, unsigned codepoint) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4); + RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); + PutUnsafe(os, codepoint); + } + + template + static bool Decode(InputStream& is, unsigned* codepoint) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 4); + Ch c = is.Take(); + *codepoint = c; + return c <= 0x10FFFF; + } + + template + static bool Validate(InputStream& is, OutputStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 4); + Ch c; + os.Put(c = is.Take()); + return c <= 0x10FFFF; + } +}; + +//! UTF-32 little endian encoding. +template +struct UTF32LE : UTF32 { + template + static CharType TakeBOM(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + CharType c = Take(is); + return static_cast(c) == 0x0000FEFFu ? Take(is) : c; + } + + template + static CharType Take(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + unsigned c = static_cast(is.Take()); + c |= static_cast(static_cast(is.Take())) << 8; + c |= static_cast(static_cast(is.Take())) << 16; + c |= static_cast(static_cast(is.Take())) << 24; + return static_cast(c); + } + + template + static void PutBOM(OutputByteStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(0xFFu)); + os.Put(static_cast(0xFEu)); + os.Put(static_cast(0x00u)); + os.Put(static_cast(0x00u)); + } + + template + static void Put(OutputByteStream& os, CharType c) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(c & 0xFFu)); + os.Put(static_cast((c >> 8) & 0xFFu)); + os.Put(static_cast((c >> 16) & 0xFFu)); + os.Put(static_cast((c >> 24) & 0xFFu)); + } +}; + +//! UTF-32 big endian encoding. +template +struct UTF32BE : UTF32 { + template + static CharType TakeBOM(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + CharType c = Take(is); + return static_cast(c) == 0x0000FEFFu ? Take(is) : c; + } + + template + static CharType Take(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + unsigned c = static_cast(static_cast(is.Take())) << 24; + c |= static_cast(static_cast(is.Take())) << 16; + c |= static_cast(static_cast(is.Take())) << 8; + c |= static_cast(static_cast(is.Take())); + return static_cast(c); + } + + template + static void PutBOM(OutputByteStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(0x00u)); + os.Put(static_cast(0x00u)); + os.Put(static_cast(0xFEu)); + os.Put(static_cast(0xFFu)); + } + + template + static void Put(OutputByteStream& os, CharType c) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast((c >> 24) & 0xFFu)); + os.Put(static_cast((c >> 16) & 0xFFu)); + os.Put(static_cast((c >> 8) & 0xFFu)); + os.Put(static_cast(c & 0xFFu)); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// ASCII + +//! ASCII encoding. +/*! http://en.wikipedia.org/wiki/ASCII + \tparam CharType Code unit for storing 7-bit ASCII data. Default is char. + \note implements Encoding concept +*/ +template +struct ASCII { + typedef CharType Ch; + + enum { supportUnicode = 0 }; + + template + static void Encode(OutputStream& os, unsigned codepoint) { + RAPIDJSON_ASSERT(codepoint <= 0x7F); + os.Put(static_cast(codepoint & 0xFF)); + } + + template + static void EncodeUnsafe(OutputStream& os, unsigned codepoint) { + RAPIDJSON_ASSERT(codepoint <= 0x7F); + PutUnsafe(os, static_cast(codepoint & 0xFF)); + } + + template + static bool Decode(InputStream& is, unsigned* codepoint) { + uint8_t c = static_cast(is.Take()); + *codepoint = c; + return c <= 0X7F; + } + + template + static bool Validate(InputStream& is, OutputStream& os) { + uint8_t c = static_cast(is.Take()); + os.Put(static_cast(c)); + return c <= 0x7F; + } + + template + static CharType TakeBOM(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + uint8_t c = static_cast(Take(is)); + return static_cast(c); + } + + template + static Ch Take(InputByteStream& is) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); + return static_cast(is.Take()); + } + + template + static void PutBOM(OutputByteStream& os) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + (void)os; + } + + template + static void Put(OutputByteStream& os, Ch c) { + RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); + os.Put(static_cast(c)); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// AutoUTF + +//! Runtime-specified UTF encoding type of a stream. +enum UTFType { + kUTF8 = 0, //!< UTF-8. + kUTF16LE = 1, //!< UTF-16 little endian. + kUTF16BE = 2, //!< UTF-16 big endian. + kUTF32LE = 3, //!< UTF-32 little endian. + kUTF32BE = 4 //!< UTF-32 big endian. +}; + +//! Dynamically select encoding according to stream's runtime-specified UTF encoding type. +/*! \note This class can be used with AutoUTFInputStream and AutoUTFOutputStream, which provides GetType(). +*/ +template +struct AutoUTF { + typedef CharType Ch; + + enum { supportUnicode = 1 }; + +#define RAPIDJSON_ENCODINGS_FUNC(x) UTF8::x, UTF16LE::x, UTF16BE::x, UTF32LE::x, UTF32BE::x + + template + static RAPIDJSON_FORCEINLINE void Encode(OutputStream& os, unsigned codepoint) { + typedef void (*EncodeFunc)(OutputStream&, unsigned); + static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Encode) }; + (*f[os.GetType()])(os, codepoint); + } + + template + static RAPIDJSON_FORCEINLINE void EncodeUnsafe(OutputStream& os, unsigned codepoint) { + typedef void (*EncodeFunc)(OutputStream&, unsigned); + static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(EncodeUnsafe) }; + (*f[os.GetType()])(os, codepoint); + } + + template + static RAPIDJSON_FORCEINLINE bool Decode(InputStream& is, unsigned* codepoint) { + typedef bool (*DecodeFunc)(InputStream&, unsigned*); + static const DecodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Decode) }; + return (*f[is.GetType()])(is, codepoint); + } + + template + static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) { + typedef bool (*ValidateFunc)(InputStream&, OutputStream&); + static const ValidateFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Validate) }; + return (*f[is.GetType()])(is, os); + } + +#undef RAPIDJSON_ENCODINGS_FUNC +}; + +/////////////////////////////////////////////////////////////////////////////// +// Transcoder + +//! Encoding conversion. +template +struct Transcoder { + //! Take one Unicode codepoint from source encoding, convert it to target encoding and put it to the output stream. + template + static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) { + unsigned codepoint; + if (!SourceEncoding::Decode(is, &codepoint)) + return false; + TargetEncoding::Encode(os, codepoint); + return true; + } + + template + static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) { + unsigned codepoint; + if (!SourceEncoding::Decode(is, &codepoint)) + return false; + TargetEncoding::EncodeUnsafe(os, codepoint); + return true; + } + + //! Validate one Unicode codepoint from an encoded stream. + template + static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) { + return Transcode(is, os); // Since source/target encoding is different, must transcode. + } +}; + +// Forward declaration. +template +inline void PutUnsafe(Stream& stream, typename Stream::Ch c); + +//! Specialization of Transcoder with same source and target encoding. +template +struct Transcoder { + template + static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) { + os.Put(is.Take()); // Just copy one code unit. This semantic is different from primary template class. + return true; + } + + template + static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) { + PutUnsafe(os, is.Take()); // Just copy one code unit. This semantic is different from primary template class. + return true; + } + + template + static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) { + return Encoding::Validate(is, os); // source/target encoding are the same + } +}; + +RAPIDJSON_NAMESPACE_END + +#if defined(__GNUC__) || (defined(_MSC_VER) && !defined(__clang__)) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_ENCODINGS_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/error/en.h b/components/thorvg-main/src/loaders/lottie/rapidjson/error/en.h new file mode 100644 index 0000000..c87b04e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/error/en.h @@ -0,0 +1,176 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ERROR_EN_H_ +#define RAPIDJSON_ERROR_EN_H_ + +#include "error.h" + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(switch-enum) +RAPIDJSON_DIAG_OFF(covered-switch-default) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Maps error code of parsing into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param parseErrorCode Error code obtained in parsing. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ +inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { + switch (parseErrorCode) { + case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); + case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); + + case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); + + case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); + case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); + case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); + + case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); + + case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); + case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); + case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string."); + case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); + case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string."); + + case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); + case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); + case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); + + case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); + case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } +} + +//! Maps error code of validation into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param validateErrorCode Error code obtained from validator. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ +inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode validateErrorCode) { + switch (validateErrorCode) { + case kValidateErrors: return RAPIDJSON_ERROR_STRING("One or more validation errors have occurred"); + case kValidateErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kValidateErrorMultipleOf: return RAPIDJSON_ERROR_STRING("Number '%actual' is not a multiple of the 'multipleOf' value '%expected'."); + case kValidateErrorMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than the 'maximum' value '%expected'."); + case kValidateErrorExclusiveMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than or equal to the 'exclusiveMaximum' value '%expected'."); + case kValidateErrorMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than the 'minimum' value '%expected'."); + case kValidateErrorExclusiveMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than or equal to the 'exclusiveMinimum' value '%expected'."); + + case kValidateErrorMaxLength: return RAPIDJSON_ERROR_STRING("String '%actual' is longer than the 'maxLength' value '%expected'."); + case kValidateErrorMinLength: return RAPIDJSON_ERROR_STRING("String '%actual' is shorter than the 'minLength' value '%expected'."); + case kValidateErrorPattern: return RAPIDJSON_ERROR_STRING("String '%actual' does not match the 'pattern' regular expression."); + + case kValidateErrorMaxItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is longer than the 'maxItems' value '%expected'."); + case kValidateErrorMinItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is shorter than the 'minItems' value '%expected'."); + case kValidateErrorUniqueItems: return RAPIDJSON_ERROR_STRING("Array has duplicate items at indices '%duplicates' but 'uniqueItems' is true."); + case kValidateErrorAdditionalItems: return RAPIDJSON_ERROR_STRING("Array has an additional item at index '%disallowed' that is not allowed by the schema."); + + case kValidateErrorMaxProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is more than 'maxProperties' value '%expected'."); + case kValidateErrorMinProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is less than 'minProperties' value '%expected'."); + case kValidateErrorRequired: return RAPIDJSON_ERROR_STRING("Object is missing the following members required by the schema: '%missing'."); + case kValidateErrorAdditionalProperties: return RAPIDJSON_ERROR_STRING("Object has an additional member '%disallowed' that is not allowed by the schema."); + case kValidateErrorPatternProperties: return RAPIDJSON_ERROR_STRING("Object has 'patternProperties' that are not allowed by the schema."); + case kValidateErrorDependencies: return RAPIDJSON_ERROR_STRING("Object has missing property or schema dependencies, refer to following errors."); + + case kValidateErrorEnum: return RAPIDJSON_ERROR_STRING("Property has a value that is not one of its allowed enumerated values."); + case kValidateErrorType: return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'."); + + case kValidateErrorOneOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors."); + case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf', indices '%matches'."); + case kValidateErrorAllOf: return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors."); + case kValidateErrorAnyOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors."); + case kValidateErrorNot: return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'."); + + case kValidateErrorReadOnly: return RAPIDJSON_ERROR_STRING("Property is read-only but has been provided when validation is for writing."); + case kValidateErrorWriteOnly: return RAPIDJSON_ERROR_STRING("Property is write-only but has been provided when validation is for reading."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } +} + +//! Maps error code of schema document compilation into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param schemaErrorCode Error code obtained from compiling the schema document. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ + inline const RAPIDJSON_ERROR_CHARTYPE* GetSchemaError_En(SchemaErrorCode schemaErrorCode) { + switch (schemaErrorCode) { + case kSchemaErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kSchemaErrorStartUnknown: return RAPIDJSON_ERROR_STRING("Pointer '%value' to start of schema does not resolve to a location in the document."); + case kSchemaErrorRefPlainName: return RAPIDJSON_ERROR_STRING("$ref fragment '%value' must be a JSON pointer."); + case kSchemaErrorRefInvalid: return RAPIDJSON_ERROR_STRING("$ref must not be an empty string."); + case kSchemaErrorRefPointerInvalid: return RAPIDJSON_ERROR_STRING("$ref fragment '%value' is not a valid JSON pointer at offset '%offset'."); + case kSchemaErrorRefUnknown: return RAPIDJSON_ERROR_STRING("$ref '%value' does not resolve to a location in the target document."); + case kSchemaErrorRefCyclical: return RAPIDJSON_ERROR_STRING("$ref '%value' is cyclical."); + case kSchemaErrorRefNoRemoteProvider: return RAPIDJSON_ERROR_STRING("$ref is remote but there is no remote provider."); + case kSchemaErrorRefNoRemoteSchema: return RAPIDJSON_ERROR_STRING("$ref '%value' is remote but the remote provider did not return a schema."); + case kSchemaErrorRegexInvalid: return RAPIDJSON_ERROR_STRING("Invalid regular expression '%value' in 'pattern' or 'patternProperties'."); + case kSchemaErrorSpecUnknown: return RAPIDJSON_ERROR_STRING("JSON schema draft or OpenAPI version is not recognized."); + case kSchemaErrorSpecUnsupported: return RAPIDJSON_ERROR_STRING("JSON schema draft or OpenAPI version is not supported."); + case kSchemaErrorSpecIllegal: return RAPIDJSON_ERROR_STRING("Both JSON schema draft and OpenAPI version found in document."); + case kSchemaErrorReadOnlyAndWriteOnly: return RAPIDJSON_ERROR_STRING("Property must not be both 'readOnly' and 'writeOnly'."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } + } + +//! Maps error code of pointer parse into error message. +/*! + \ingroup RAPIDJSON_ERRORS + \param pointerParseErrorCode Error code obtained from pointer parse. + \return the error message. + \note User can make a copy of this function for localization. + Using switch-case is safer for future modification of error codes. +*/ +inline const RAPIDJSON_ERROR_CHARTYPE* GetPointerParseError_En(PointerParseErrorCode pointerParseErrorCode) { + switch (pointerParseErrorCode) { + case kPointerParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); + + case kPointerParseErrorTokenMustBeginWithSolidus: return RAPIDJSON_ERROR_STRING("A token must begin with a '/'."); + case kPointerParseErrorInvalidEscape: return RAPIDJSON_ERROR_STRING("Invalid escape."); + case kPointerParseErrorInvalidPercentEncoding: return RAPIDJSON_ERROR_STRING("Invalid percent encoding in URI fragment."); + case kPointerParseErrorCharacterMustPercentEncode: return RAPIDJSON_ERROR_STRING("A character must be percent encoded in a URI fragment."); + + default: return RAPIDJSON_ERROR_STRING("Unknown error."); + } +} + +RAPIDJSON_NAMESPACE_END + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_ERROR_EN_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/error/error.h b/components/thorvg-main/src/loaders/lottie/rapidjson/error/error.h new file mode 100644 index 0000000..cae345d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/error/error.h @@ -0,0 +1,285 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ERROR_ERROR_H_ +#define RAPIDJSON_ERROR_ERROR_H_ + +#include "../rapidjson.h" + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +#endif + +/*! \file error.h */ + +/*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_ERROR_CHARTYPE + +//! Character type of error messages. +/*! \ingroup RAPIDJSON_ERRORS + The default character type is \c char. + On Windows, user can define this macro as \c TCHAR for supporting both + unicode/non-unicode settings. +*/ +#ifndef RAPIDJSON_ERROR_CHARTYPE +#define RAPIDJSON_ERROR_CHARTYPE char +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_ERROR_STRING + +//! Macro for converting string literal to \ref RAPIDJSON_ERROR_CHARTYPE[]. +/*! \ingroup RAPIDJSON_ERRORS + By default this conversion macro does nothing. + On Windows, user can define this macro as \c _T(x) for supporting both + unicode/non-unicode settings. +*/ +#ifndef RAPIDJSON_ERROR_STRING +#define RAPIDJSON_ERROR_STRING(x) x +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// ParseErrorCode + +//! Error code of parsing. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericReader::Parse, GenericReader::GetParseErrorCode +*/ +enum ParseErrorCode { + kParseErrorNone = 0, //!< No error. + + kParseErrorDocumentEmpty, //!< The document is empty. + kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. + + kParseErrorValueInvalid, //!< Invalid value. + + kParseErrorObjectMissName, //!< Missing a name for object member. + kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. + kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. + + kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. + + kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. + kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. + kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. + kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. + kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. + + kParseErrorNumberTooBig, //!< Number too big to be stored in double. + kParseErrorNumberMissFraction, //!< Miss fraction part in number. + kParseErrorNumberMissExponent, //!< Miss exponent in number. + + kParseErrorTermination, //!< Parsing was terminated. + kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. +}; + +//! Result of parsing (wraps ParseErrorCode) +/*! + \ingroup RAPIDJSON_ERRORS + \code + Document doc; + ParseResult ok = doc.Parse("[42]"); + if (!ok) { + fprintf(stderr, "JSON parse error: %s (%u)", + GetParseError_En(ok.Code()), ok.Offset()); + exit(EXIT_FAILURE); + } + \endcode + \see GenericReader::Parse, GenericDocument::Parse +*/ +struct ParseResult { + //!! Unspecified boolean type + typedef bool (ParseResult::*BooleanType)() const; +public: + //! Default constructor, no error. + ParseResult() : code_(kParseErrorNone), offset_(0) {} + //! Constructor to set an error. + ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} + + //! Get the error code. + ParseErrorCode Code() const { return code_; } + //! Get the error offset, if \ref IsError(), 0 otherwise. + size_t Offset() const { return offset_; } + + //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). + operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } + //! Whether the result is an error. + bool IsError() const { return code_ != kParseErrorNone; } + + bool operator==(const ParseResult& that) const { return code_ == that.code_; } + bool operator==(ParseErrorCode code) const { return code_ == code; } + friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } + + bool operator!=(const ParseResult& that) const { return !(*this == that); } + bool operator!=(ParseErrorCode code) const { return !(*this == code); } + friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; } + + //! Reset error code. + void Clear() { Set(kParseErrorNone); } + //! Update error code and offset. + void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } + +private: + ParseErrorCode code_; + size_t offset_; +}; + +//! Function pointer type of GetParseError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetParseError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetParseErrorFunc GetParseError = GetParseError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); + +/////////////////////////////////////////////////////////////////////////////// +// ValidateErrorCode + +//! Error codes when validating. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericSchemaValidator +*/ +enum ValidateErrorCode { + kValidateErrors = -1, //!< Top level error code when kValidateContinueOnErrorsFlag set. + kValidateErrorNone = 0, //!< No error. + + kValidateErrorMultipleOf, //!< Number is not a multiple of the 'multipleOf' value. + kValidateErrorMaximum, //!< Number is greater than the 'maximum' value. + kValidateErrorExclusiveMaximum, //!< Number is greater than or equal to the 'maximum' value. + kValidateErrorMinimum, //!< Number is less than the 'minimum' value. + kValidateErrorExclusiveMinimum, //!< Number is less than or equal to the 'minimum' value. + + kValidateErrorMaxLength, //!< String is longer than the 'maxLength' value. + kValidateErrorMinLength, //!< String is longer than the 'maxLength' value. + kValidateErrorPattern, //!< String does not match the 'pattern' regular expression. + + kValidateErrorMaxItems, //!< Array is longer than the 'maxItems' value. + kValidateErrorMinItems, //!< Array is shorter than the 'minItems' value. + kValidateErrorUniqueItems, //!< Array has duplicate items but 'uniqueItems' is true. + kValidateErrorAdditionalItems, //!< Array has additional items that are not allowed by the schema. + + kValidateErrorMaxProperties, //!< Object has more members than 'maxProperties' value. + kValidateErrorMinProperties, //!< Object has less members than 'minProperties' value. + kValidateErrorRequired, //!< Object is missing one or more members required by the schema. + kValidateErrorAdditionalProperties, //!< Object has additional members that are not allowed by the schema. + kValidateErrorPatternProperties, //!< See other errors. + kValidateErrorDependencies, //!< Object has missing property or schema dependencies. + + kValidateErrorEnum, //!< Property has a value that is not one of its allowed enumerated values. + kValidateErrorType, //!< Property has a type that is not allowed by the schema. + + kValidateErrorOneOf, //!< Property did not match any of the sub-schemas specified by 'oneOf'. + kValidateErrorOneOfMatch, //!< Property matched more than one of the sub-schemas specified by 'oneOf'. + kValidateErrorAllOf, //!< Property did not match all of the sub-schemas specified by 'allOf'. + kValidateErrorAnyOf, //!< Property did not match any of the sub-schemas specified by 'anyOf'. + kValidateErrorNot, //!< Property matched the sub-schema specified by 'not'. + + kValidateErrorReadOnly, //!< Property is read-only but has been provided when validation is for writing + kValidateErrorWriteOnly //!< Property is write-only but has been provided when validation is for reading +}; + +//! Function pointer type of GetValidateError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetValidateError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetValidateErrorFunc GetValidateError = GetValidateError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetValidateError(validator.GetInvalidSchemaCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetValidateErrorFunc)(ValidateErrorCode); + +/////////////////////////////////////////////////////////////////////////////// +// SchemaErrorCode + +//! Error codes when validating. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericSchemaValidator +*/ +enum SchemaErrorCode { + kSchemaErrorNone = 0, //!< No error. + + kSchemaErrorStartUnknown, //!< Pointer to start of schema does not resolve to a location in the document + kSchemaErrorRefPlainName, //!< $ref fragment must be a JSON pointer + kSchemaErrorRefInvalid, //!< $ref must not be an empty string + kSchemaErrorRefPointerInvalid, //!< $ref fragment is not a valid JSON pointer at offset + kSchemaErrorRefUnknown, //!< $ref does not resolve to a location in the target document + kSchemaErrorRefCyclical, //!< $ref is cyclical + kSchemaErrorRefNoRemoteProvider, //!< $ref is remote but there is no remote provider + kSchemaErrorRefNoRemoteSchema, //!< $ref is remote but the remote provider did not return a schema + kSchemaErrorRegexInvalid, //!< Invalid regular expression in 'pattern' or 'patternProperties' + kSchemaErrorSpecUnknown, //!< JSON schema draft or OpenAPI version is not recognized + kSchemaErrorSpecUnsupported, //!< JSON schema draft or OpenAPI version is not supported + kSchemaErrorSpecIllegal, //!< Both JSON schema draft and OpenAPI version found in document + kSchemaErrorReadOnlyAndWriteOnly //!< Property must not be both 'readOnly' and 'writeOnly' +}; + +//! Function pointer type of GetSchemaError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetSchemaError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetSchemaErrorFunc GetSchemaError = GetSchemaError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetSchemaError(validator.GetInvalidSchemaCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetSchemaErrorFunc)(SchemaErrorCode); + +/////////////////////////////////////////////////////////////////////////////// +// PointerParseErrorCode + +//! Error code of JSON pointer parsing. +/*! \ingroup RAPIDJSON_ERRORS + \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode +*/ +enum PointerParseErrorCode { + kPointerParseErrorNone = 0, //!< The parse is successful + + kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/' + kPointerParseErrorInvalidEscape, //!< Invalid escape + kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment + kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment +}; + +//! Function pointer type of GetPointerParseError(). +/*! \ingroup RAPIDJSON_ERRORS + + This is the prototype for \c GetPointerParseError_X(), where \c X is a locale. + User can dynamically change locale in runtime, e.g.: +\code + GetPointerParseErrorFunc GetPointerParseError = GetPointerParseError_En; // or whatever + const RAPIDJSON_ERROR_CHARTYPE* s = GetPointerParseError(pointer.GetParseErrorCode()); +\endcode +*/ +typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetPointerParseErrorFunc)(PointerParseErrorCode); + + +RAPIDJSON_NAMESPACE_END + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_ERROR_ERROR_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/filereadstream.h b/components/thorvg-main/src/loaders/lottie/rapidjson/filereadstream.h new file mode 100644 index 0000000..f8bb43c --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/filereadstream.h @@ -0,0 +1,99 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_FILEREADSTREAM_H_ +#define RAPIDJSON_FILEREADSTREAM_H_ + +#include "stream.h" +#include + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +RAPIDJSON_DIAG_OFF(unreachable-code) +RAPIDJSON_DIAG_OFF(missing-noreturn) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! File byte stream for input using fread(). +/*! + \note implements Stream concept +*/ +class FileReadStream { +public: + typedef char Ch; //!< Character type (byte). + + //! Constructor. + /*! + \param fp File pointer opened for read. + \param buffer user-supplied buffer. + \param bufferSize size of buffer in bytes. Must >=4 bytes. + */ + FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { + RAPIDJSON_ASSERT(fp_ != 0); + RAPIDJSON_ASSERT(bufferSize >= 4); + Read(); + } + + Ch Peek() const { return *current_; } + Ch Take() { Ch c = *current_; Read(); return c; } + size_t Tell() const { return count_ + static_cast(current_ - buffer_); } + + // Not implemented + void Put(Ch) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + + // For encoding detection only. + const Ch* Peek4() const { + return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; + } + +private: + void Read() { + if (current_ < bufferLast_) + ++current_; + else if (!eof_) { + count_ += readCount_; + readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); + bufferLast_ = buffer_ + readCount_ - 1; + current_ = buffer_; + + if (readCount_ < bufferSize_) { + buffer_[readCount_] = '\0'; + ++bufferLast_; + eof_ = true; + } + } + } + + std::FILE* fp_; + Ch *buffer_; + size_t bufferSize_; + Ch *bufferLast_; + Ch *current_; + size_t readCount_; + size_t count_; //!< Number of characters read + bool eof_; +}; + +RAPIDJSON_NAMESPACE_END + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_FILESTREAM_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/filewritestream.h b/components/thorvg-main/src/loaders/lottie/rapidjson/filewritestream.h new file mode 100644 index 0000000..5d89588 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/filewritestream.h @@ -0,0 +1,104 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_FILEWRITESTREAM_H_ +#define RAPIDJSON_FILEWRITESTREAM_H_ + +#include "stream.h" +#include + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(unreachable-code) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Wrapper of C file stream for output using fwrite(). +/*! + \note implements Stream concept +*/ +class FileWriteStream { +public: + typedef char Ch; //!< Character type. Only support char. + + FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { + RAPIDJSON_ASSERT(fp_ != 0); + } + + void Put(char c) { + if (current_ >= bufferEnd_) + Flush(); + + *current_++ = c; + } + + void PutN(char c, size_t n) { + size_t avail = static_cast(bufferEnd_ - current_); + while (n > avail) { + std::memset(current_, c, avail); + current_ += avail; + Flush(); + n -= avail; + avail = static_cast(bufferEnd_ - current_); + } + + if (n > 0) { + std::memset(current_, c, n); + current_ += n; + } + } + + void Flush() { + if (current_ != buffer_) { + size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); + if (result < static_cast(current_ - buffer_)) { + // failure deliberately ignored at this time + // added to avoid warn_unused_result build errors + } + current_ = buffer_; + } + } + + // Not implemented + char Peek() const { RAPIDJSON_ASSERT(false); return 0; } + char Take() { RAPIDJSON_ASSERT(false); return 0; } + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } + char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + // Prohibit copy constructor & assignment operator. + FileWriteStream(const FileWriteStream&); + FileWriteStream& operator=(const FileWriteStream&); + + std::FILE* fp_; + char *buffer_; + char *bufferEnd_; + char *current_; +}; + +//! Implement specialized version of PutN() with memset() for better performance. +template<> +inline void PutN(FileWriteStream& stream, char c, size_t n) { + stream.PutN(c, n); +} + +RAPIDJSON_NAMESPACE_END + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_FILESTREAM_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/fwd.h b/components/thorvg-main/src/loaders/lottie/rapidjson/fwd.h new file mode 100644 index 0000000..d62f77f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/fwd.h @@ -0,0 +1,151 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_FWD_H_ +#define RAPIDJSON_FWD_H_ + +#include "rapidjson.h" + +RAPIDJSON_NAMESPACE_BEGIN + +// encodings.h + +template struct UTF8; +template struct UTF16; +template struct UTF16BE; +template struct UTF16LE; +template struct UTF32; +template struct UTF32BE; +template struct UTF32LE; +template struct ASCII; +template struct AutoUTF; + +template +struct Transcoder; + +// allocators.h + +class CrtAllocator; + +template +class MemoryPoolAllocator; + +// stream.h + +template +struct GenericStringStream; + +typedef GenericStringStream > StringStream; + +template +struct GenericInsituStringStream; + +typedef GenericInsituStringStream > InsituStringStream; + +// stringbuffer.h + +template +class GenericStringBuffer; + +typedef GenericStringBuffer, CrtAllocator> StringBuffer; + +// filereadstream.h + +class FileReadStream; + +// filewritestream.h + +class FileWriteStream; + +// memorybuffer.h + +template +struct GenericMemoryBuffer; + +typedef GenericMemoryBuffer MemoryBuffer; + +// memorystream.h + +struct MemoryStream; + +// reader.h + +template +struct BaseReaderHandler; + +template +class GenericReader; + +typedef GenericReader, UTF8, CrtAllocator> Reader; + +// writer.h + +template +class Writer; + +// prettywriter.h + +template +class PrettyWriter; + +// document.h + +template +class GenericMember; + +template +class GenericMemberIterator; + +template +struct GenericStringRef; + +template +class GenericValue; + +typedef GenericValue, MemoryPoolAllocator > Value; + +template +class GenericDocument; + +typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; + +// pointer.h + +template +class GenericPointer; + +typedef GenericPointer Pointer; + +// schema.h + +template +class IGenericRemoteSchemaDocumentProvider; + +template +class GenericSchemaDocument; + +typedef GenericSchemaDocument SchemaDocument; +typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; + +template < + typename SchemaDocumentType, + typename OutputHandler, + typename StateAllocator> +class GenericSchemaValidator; + +typedef GenericSchemaValidator, void>, CrtAllocator> SchemaValidator; + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_RAPIDJSONFWD_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/biginteger.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/biginteger.h new file mode 100644 index 0000000..4930043 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/biginteger.h @@ -0,0 +1,297 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_BIGINTEGER_H_ +#define RAPIDJSON_BIGINTEGER_H_ + +#include "../rapidjson.h" + +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_M_AMD64) +#include // for _umul128 +#if !defined(_ARM64EC_) +#pragma intrinsic(_umul128) +#else +#pragma comment(lib,"softintrin") +#endif +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +class BigInteger { +public: + typedef uint64_t Type; + + BigInteger(const BigInteger& rhs) : count_(rhs.count_) { + std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); + } + + explicit BigInteger(uint64_t u) : count_(1) { + digits_[0] = u; + } + + template + BigInteger(const Ch* decimals, size_t length) : count_(1) { + RAPIDJSON_ASSERT(length > 0); + digits_[0] = 0; + size_t i = 0; + const size_t kMaxDigitPerIteration = 19; // 2^64 = 18446744073709551616 > 10^19 + while (length >= kMaxDigitPerIteration) { + AppendDecimal64(decimals + i, decimals + i + kMaxDigitPerIteration); + length -= kMaxDigitPerIteration; + i += kMaxDigitPerIteration; + } + + if (length > 0) + AppendDecimal64(decimals + i, decimals + i + length); + } + + BigInteger& operator=(const BigInteger &rhs) + { + if (this != &rhs) { + count_ = rhs.count_; + std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); + } + return *this; + } + + BigInteger& operator=(uint64_t u) { + digits_[0] = u; + count_ = 1; + return *this; + } + + BigInteger& operator+=(uint64_t u) { + Type backup = digits_[0]; + digits_[0] += u; + for (size_t i = 0; i < count_ - 1; i++) { + if (digits_[i] >= backup) + return *this; // no carry + backup = digits_[i + 1]; + digits_[i + 1] += 1; + } + + // Last carry + if (digits_[count_ - 1] < backup) + PushBack(1); + + return *this; + } + + BigInteger& operator*=(uint64_t u) { + if (u == 0) return *this = 0; + if (u == 1) return *this; + if (*this == 1) return *this = u; + + uint64_t k = 0; + for (size_t i = 0; i < count_; i++) { + uint64_t hi; + digits_[i] = MulAdd64(digits_[i], u, k, &hi); + k = hi; + } + + if (k > 0) + PushBack(k); + + return *this; + } + + BigInteger& operator*=(uint32_t u) { + if (u == 0) return *this = 0; + if (u == 1) return *this; + if (*this == 1) return *this = u; + + uint64_t k = 0; + for (size_t i = 0; i < count_; i++) { + const uint64_t c = digits_[i] >> 32; + const uint64_t d = digits_[i] & 0xFFFFFFFF; + const uint64_t uc = u * c; + const uint64_t ud = u * d; + const uint64_t p0 = ud + k; + const uint64_t p1 = uc + (p0 >> 32); + digits_[i] = (p0 & 0xFFFFFFFF) | (p1 << 32); + k = p1 >> 32; + } + + if (k > 0) + PushBack(k); + + return *this; + } + + BigInteger& operator<<=(size_t shift) { + if (IsZero() || shift == 0) return *this; + + size_t offset = shift / kTypeBit; + size_t interShift = shift % kTypeBit; + RAPIDJSON_ASSERT(count_ + offset <= kCapacity); + + if (interShift == 0) { + std::memmove(digits_ + offset, digits_, count_ * sizeof(Type)); + count_ += offset; + } + else { + digits_[count_] = 0; + for (size_t i = count_; i > 0; i--) + digits_[i + offset] = (digits_[i] << interShift) | (digits_[i - 1] >> (kTypeBit - interShift)); + digits_[offset] = digits_[0] << interShift; + count_ += offset; + if (digits_[count_]) + count_++; + } + + std::memset(digits_, 0, offset * sizeof(Type)); + + return *this; + } + + bool operator==(const BigInteger& rhs) const { + return count_ == rhs.count_ && std::memcmp(digits_, rhs.digits_, count_ * sizeof(Type)) == 0; + } + + bool operator==(const Type rhs) const { + return count_ == 1 && digits_[0] == rhs; + } + + BigInteger& MultiplyPow5(unsigned exp) { + static const uint32_t kPow5[12] = { + 5, + 5 * 5, + 5 * 5 * 5, + 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 + }; + if (exp == 0) return *this; + for (; exp >= 27; exp -= 27) *this *= RAPIDJSON_UINT64_C2(0X6765C793, 0XFA10079D); // 5^27 + for (; exp >= 13; exp -= 13) *this *= static_cast(1220703125u); // 5^13 + if (exp > 0) *this *= kPow5[exp - 1]; + return *this; + } + + // Compute absolute difference of this and rhs. + // Assume this != rhs + bool Difference(const BigInteger& rhs, BigInteger* out) const { + int cmp = Compare(rhs); + RAPIDJSON_ASSERT(cmp != 0); + const BigInteger *a, *b; // Makes a > b + bool ret; + if (cmp < 0) { a = &rhs; b = this; ret = true; } + else { a = this; b = &rhs; ret = false; } + + Type borrow = 0; + for (size_t i = 0; i < a->count_; i++) { + Type d = a->digits_[i] - borrow; + if (i < b->count_) + d -= b->digits_[i]; + borrow = (d > a->digits_[i]) ? 1 : 0; + out->digits_[i] = d; + if (d != 0) + out->count_ = i + 1; + } + + return ret; + } + + int Compare(const BigInteger& rhs) const { + if (count_ != rhs.count_) + return count_ < rhs.count_ ? -1 : 1; + + for (size_t i = count_; i-- > 0;) + if (digits_[i] != rhs.digits_[i]) + return digits_[i] < rhs.digits_[i] ? -1 : 1; + + return 0; + } + + size_t GetCount() const { return count_; } + Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; } + bool IsZero() const { return count_ == 1 && digits_[0] == 0; } + +private: + template + void AppendDecimal64(const Ch* begin, const Ch* end) { + uint64_t u = ParseUint64(begin, end); + if (IsZero()) + *this = u; + else { + unsigned exp = static_cast(end - begin); + (MultiplyPow5(exp) <<= exp) += u; // *this = *this * 10^exp + u + } + } + + void PushBack(Type digit) { + RAPIDJSON_ASSERT(count_ < kCapacity); + digits_[count_++] = digit; + } + + template + static uint64_t ParseUint64(const Ch* begin, const Ch* end) { + uint64_t r = 0; + for (const Ch* p = begin; p != end; ++p) { + RAPIDJSON_ASSERT(*p >= Ch('0') && *p <= Ch('9')); + r = r * 10u + static_cast(*p - Ch('0')); + } + return r; + } + + // Assume a * b + k < 2^128 + static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t* outHigh) { +#if defined(_MSC_VER) && defined(_M_AMD64) + uint64_t low = _umul128(a, b, outHigh) + k; + if (low < k) + (*outHigh)++; + return low; +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) + __extension__ typedef unsigned __int128 uint128; + uint128 p = static_cast(a) * static_cast(b); + p += k; + *outHigh = static_cast(p >> 64); + return static_cast(p); +#else + const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32; + uint64_t x0 = a0 * b0, x1 = a0 * b1, x2 = a1 * b0, x3 = a1 * b1; + x1 += (x0 >> 32); // can't give carry + x1 += x2; + if (x1 < x2) + x3 += (static_cast(1) << 32); + uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF); + uint64_t hi = x3 + (x1 >> 32); + + lo += k; + if (lo < k) + hi++; + *outHigh = hi; + return lo; +#endif + } + + static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000 + static const size_t kCapacity = kBitCount / sizeof(Type); + static const size_t kTypeBit = sizeof(Type) * 8; + + Type digits_[kCapacity]; + size_t count_; +}; + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_BIGINTEGER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/clzll.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/clzll.h new file mode 100644 index 0000000..8fc5118 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/clzll.h @@ -0,0 +1,71 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_CLZLL_H_ +#define RAPIDJSON_CLZLL_H_ + +#include "../rapidjson.h" + +#if defined(_MSC_VER) && !defined(UNDER_CE) +#include +#if defined(_WIN64) +#pragma intrinsic(_BitScanReverse64) +#else +#pragma intrinsic(_BitScanReverse) +#endif +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +inline uint32_t clzll(uint64_t x) { + // Passing 0 to __builtin_clzll is UB in GCC and results in an + // infinite loop in the software implementation. + RAPIDJSON_ASSERT(x != 0); + +#if defined(_MSC_VER) && !defined(UNDER_CE) + unsigned long r = 0; +#if defined(_WIN64) + _BitScanReverse64(&r, x); +#else + // Scan the high 32 bits. + if (_BitScanReverse(&r, static_cast(x >> 32))) + return 63 - (r + 32); + + // Scan the low 32 bits. + _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); +#endif // _WIN64 + + return 63 - r; +#elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) + // __builtin_clzll wrapper + return static_cast(__builtin_clzll(x)); +#else + // naive version + uint32_t r = 0; + while (!(x & (static_cast(1) << 63))) { + x <<= 1; + ++r; + } + + return r; +#endif // _MSC_VER +} + +#define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_CLZLL_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/diyfp.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/diyfp.h new file mode 100644 index 0000000..1f60fb6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/diyfp.h @@ -0,0 +1,261 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +// This is a C++ header-only implementation of Grisu2 algorithm from the publication: +// Loitsch, Florian. "Printing floating-point numbers quickly and accurately with +// integers." ACM Sigplan Notices 45.6 (2010): 233-243. + +#ifndef RAPIDJSON_DIYFP_H_ +#define RAPIDJSON_DIYFP_H_ + +#include "../rapidjson.h" +#include "clzll.h" +#include + +#if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER) +#include +#if !defined(_ARM64EC_) +#pragma intrinsic(_umul128) +#else +#pragma comment(lib,"softintrin") +#endif +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +#endif + +struct DiyFp { + DiyFp() : f(), e() {} + + DiyFp(uint64_t fp, int exp) : f(fp), e(exp) {} + + explicit DiyFp(double d) { + union { + double d; + uint64_t u64; + } u = { d }; + + int biased_e = static_cast((u.u64 & kDpExponentMask) >> kDpSignificandSize); + uint64_t significand = (u.u64 & kDpSignificandMask); + if (biased_e != 0) { + f = significand + kDpHiddenBit; + e = biased_e - kDpExponentBias; + } + else { + f = significand; + e = kDpMinExponent + 1; + } + } + + DiyFp operator-(const DiyFp& rhs) const { + return DiyFp(f - rhs.f, e); + } + + DiyFp operator*(const DiyFp& rhs) const { +#if defined(_MSC_VER) && defined(_M_AMD64) + uint64_t h; + uint64_t l = _umul128(f, rhs.f, &h); + if (l & (uint64_t(1) << 63)) // rounding + h++; + return DiyFp(h, e + rhs.e + 64); +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) + __extension__ typedef unsigned __int128 uint128; + uint128 p = static_cast(f) * static_cast(rhs.f); + uint64_t h = static_cast(p >> 64); + uint64_t l = static_cast(p); + if (l & (uint64_t(1) << 63)) // rounding + h++; + return DiyFp(h, e + rhs.e + 64); +#else + const uint64_t M32 = 0xFFFFFFFF; + const uint64_t a = f >> 32; + const uint64_t b = f & M32; + const uint64_t c = rhs.f >> 32; + const uint64_t d = rhs.f & M32; + const uint64_t ac = a * c; + const uint64_t bc = b * c; + const uint64_t ad = a * d; + const uint64_t bd = b * d; + uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32); + tmp += 1U << 31; /// mult_round + return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64); +#endif + } + + DiyFp Normalize() const { + int s = static_cast(clzll(f)); + return DiyFp(f << s, e - s); + } + + DiyFp NormalizeBoundary() const { + DiyFp res = *this; + while (!(res.f & (kDpHiddenBit << 1))) { + res.f <<= 1; + res.e--; + } + res.f <<= (kDiySignificandSize - kDpSignificandSize - 2); + res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2); + return res; + } + + void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const { + DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary(); + DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1); + mi.f <<= mi.e - pl.e; + mi.e = pl.e; + *plus = pl; + *minus = mi; + } + + double ToDouble() const { + union { + double d; + uint64_t u64; + }u; + RAPIDJSON_ASSERT(f <= kDpHiddenBit + kDpSignificandMask); + if (e < kDpDenormalExponent) { + // Underflow. + return 0.0; + } + if (e >= kDpMaxExponent) { + // Overflow. + return std::numeric_limits::infinity(); + } + const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : + static_cast(e + kDpExponentBias); + u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize); + return u.d; + } + + static const int kDiySignificandSize = 64; + static const int kDpSignificandSize = 52; + static const int kDpExponentBias = 0x3FF + kDpSignificandSize; + static const int kDpMaxExponent = 0x7FF - kDpExponentBias; + static const int kDpMinExponent = -kDpExponentBias; + static const int kDpDenormalExponent = -kDpExponentBias + 1; + static const uint64_t kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); + static const uint64_t kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); + static const uint64_t kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); + + uint64_t f; + int e; +}; + +inline DiyFp GetCachedPowerByIndex(size_t index) { + // 10^-348, 10^-340, ..., 10^340 + static const uint64_t kCachedPowers_F[] = { + RAPIDJSON_UINT64_C2(0xfa8fd5a0, 0x081c0288), RAPIDJSON_UINT64_C2(0xbaaee17f, 0xa23ebf76), + RAPIDJSON_UINT64_C2(0x8b16fb20, 0x3055ac76), RAPIDJSON_UINT64_C2(0xcf42894a, 0x5dce35ea), + RAPIDJSON_UINT64_C2(0x9a6bb0aa, 0x55653b2d), RAPIDJSON_UINT64_C2(0xe61acf03, 0x3d1a45df), + RAPIDJSON_UINT64_C2(0xab70fe17, 0xc79ac6ca), RAPIDJSON_UINT64_C2(0xff77b1fc, 0xbebcdc4f), + RAPIDJSON_UINT64_C2(0xbe5691ef, 0x416bd60c), RAPIDJSON_UINT64_C2(0x8dd01fad, 0x907ffc3c), + RAPIDJSON_UINT64_C2(0xd3515c28, 0x31559a83), RAPIDJSON_UINT64_C2(0x9d71ac8f, 0xada6c9b5), + RAPIDJSON_UINT64_C2(0xea9c2277, 0x23ee8bcb), RAPIDJSON_UINT64_C2(0xaecc4991, 0x4078536d), + RAPIDJSON_UINT64_C2(0x823c1279, 0x5db6ce57), RAPIDJSON_UINT64_C2(0xc2109436, 0x4dfb5637), + RAPIDJSON_UINT64_C2(0x9096ea6f, 0x3848984f), RAPIDJSON_UINT64_C2(0xd77485cb, 0x25823ac7), + RAPIDJSON_UINT64_C2(0xa086cfcd, 0x97bf97f4), RAPIDJSON_UINT64_C2(0xef340a98, 0x172aace5), + RAPIDJSON_UINT64_C2(0xb23867fb, 0x2a35b28e), RAPIDJSON_UINT64_C2(0x84c8d4df, 0xd2c63f3b), + RAPIDJSON_UINT64_C2(0xc5dd4427, 0x1ad3cdba), RAPIDJSON_UINT64_C2(0x936b9fce, 0xbb25c996), + RAPIDJSON_UINT64_C2(0xdbac6c24, 0x7d62a584), RAPIDJSON_UINT64_C2(0xa3ab6658, 0x0d5fdaf6), + RAPIDJSON_UINT64_C2(0xf3e2f893, 0xdec3f126), RAPIDJSON_UINT64_C2(0xb5b5ada8, 0xaaff80b8), + RAPIDJSON_UINT64_C2(0x87625f05, 0x6c7c4a8b), RAPIDJSON_UINT64_C2(0xc9bcff60, 0x34c13053), + RAPIDJSON_UINT64_C2(0x964e858c, 0x91ba2655), RAPIDJSON_UINT64_C2(0xdff97724, 0x70297ebd), + RAPIDJSON_UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), RAPIDJSON_UINT64_C2(0xf8a95fcf, 0x88747d94), + RAPIDJSON_UINT64_C2(0xb9447093, 0x8fa89bcf), RAPIDJSON_UINT64_C2(0x8a08f0f8, 0xbf0f156b), + RAPIDJSON_UINT64_C2(0xcdb02555, 0x653131b6), RAPIDJSON_UINT64_C2(0x993fe2c6, 0xd07b7fac), + RAPIDJSON_UINT64_C2(0xe45c10c4, 0x2a2b3b06), RAPIDJSON_UINT64_C2(0xaa242499, 0x697392d3), + RAPIDJSON_UINT64_C2(0xfd87b5f2, 0x8300ca0e), RAPIDJSON_UINT64_C2(0xbce50864, 0x92111aeb), + RAPIDJSON_UINT64_C2(0x8cbccc09, 0x6f5088cc), RAPIDJSON_UINT64_C2(0xd1b71758, 0xe219652c), + RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), RAPIDJSON_UINT64_C2(0xe8d4a510, 0x00000000), + RAPIDJSON_UINT64_C2(0xad78ebc5, 0xac620000), RAPIDJSON_UINT64_C2(0x813f3978, 0xf8940984), + RAPIDJSON_UINT64_C2(0xc097ce7b, 0xc90715b3), RAPIDJSON_UINT64_C2(0x8f7e32ce, 0x7bea5c70), + RAPIDJSON_UINT64_C2(0xd5d238a4, 0xabe98068), RAPIDJSON_UINT64_C2(0x9f4f2726, 0x179a2245), + RAPIDJSON_UINT64_C2(0xed63a231, 0xd4c4fb27), RAPIDJSON_UINT64_C2(0xb0de6538, 0x8cc8ada8), + RAPIDJSON_UINT64_C2(0x83c7088e, 0x1aab65db), RAPIDJSON_UINT64_C2(0xc45d1df9, 0x42711d9a), + RAPIDJSON_UINT64_C2(0x924d692c, 0xa61be758), RAPIDJSON_UINT64_C2(0xda01ee64, 0x1a708dea), + RAPIDJSON_UINT64_C2(0xa26da399, 0x9aef774a), RAPIDJSON_UINT64_C2(0xf209787b, 0xb47d6b85), + RAPIDJSON_UINT64_C2(0xb454e4a1, 0x79dd1877), RAPIDJSON_UINT64_C2(0x865b8692, 0x5b9bc5c2), + RAPIDJSON_UINT64_C2(0xc83553c5, 0xc8965d3d), RAPIDJSON_UINT64_C2(0x952ab45c, 0xfa97a0b3), + RAPIDJSON_UINT64_C2(0xde469fbd, 0x99a05fe3), RAPIDJSON_UINT64_C2(0xa59bc234, 0xdb398c25), + RAPIDJSON_UINT64_C2(0xf6c69a72, 0xa3989f5c), RAPIDJSON_UINT64_C2(0xb7dcbf53, 0x54e9bece), + RAPIDJSON_UINT64_C2(0x88fcf317, 0xf22241e2), RAPIDJSON_UINT64_C2(0xcc20ce9b, 0xd35c78a5), + RAPIDJSON_UINT64_C2(0x98165af3, 0x7b2153df), RAPIDJSON_UINT64_C2(0xe2a0b5dc, 0x971f303a), + RAPIDJSON_UINT64_C2(0xa8d9d153, 0x5ce3b396), RAPIDJSON_UINT64_C2(0xfb9b7cd9, 0xa4a7443c), + RAPIDJSON_UINT64_C2(0xbb764c4c, 0xa7a44410), RAPIDJSON_UINT64_C2(0x8bab8eef, 0xb6409c1a), + RAPIDJSON_UINT64_C2(0xd01fef10, 0xa657842c), RAPIDJSON_UINT64_C2(0x9b10a4e5, 0xe9913129), + RAPIDJSON_UINT64_C2(0xe7109bfb, 0xa19c0c9d), RAPIDJSON_UINT64_C2(0xac2820d9, 0x623bf429), + RAPIDJSON_UINT64_C2(0x80444b5e, 0x7aa7cf85), RAPIDJSON_UINT64_C2(0xbf21e440, 0x03acdd2d), + RAPIDJSON_UINT64_C2(0x8e679c2f, 0x5e44ff8f), RAPIDJSON_UINT64_C2(0xd433179d, 0x9c8cb841), + RAPIDJSON_UINT64_C2(0x9e19db92, 0xb4e31ba9), RAPIDJSON_UINT64_C2(0xeb96bf6e, 0xbadf77d9), + RAPIDJSON_UINT64_C2(0xaf87023b, 0x9bf0ee6b) + }; + static const int16_t kCachedPowers_E[] = { + -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, + -954, -927, -901, -874, -847, -821, -794, -768, -741, -715, + -688, -661, -635, -608, -582, -555, -529, -502, -475, -449, + -422, -396, -369, -343, -316, -289, -263, -236, -210, -183, + -157, -130, -103, -77, -50, -24, 3, 30, 56, 83, + 109, 136, 162, 189, 216, 242, 269, 295, 322, 348, + 375, 402, 428, 455, 481, 508, 534, 561, 588, 614, + 641, 667, 694, 720, 747, 774, 800, 827, 853, 880, + 907, 933, 960, 986, 1013, 1039, 1066 + }; + RAPIDJSON_ASSERT(index < 87); + return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]); +} + +inline DiyFp GetCachedPower(int e, int* K) { + + //int k = static_cast(ceil((-61 - e) * 0.30102999566398114)) + 374; + double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive + int k = static_cast(dk); + if (dk - k > 0.0) + k++; + + unsigned index = static_cast((k >> 3) + 1); + *K = -(-348 + static_cast(index << 3)); // decimal exponent no need lookup table + + return GetCachedPowerByIndex(index); +} + +inline DiyFp GetCachedPower10(int exp, int *outExp) { + RAPIDJSON_ASSERT(exp >= -348); + unsigned index = static_cast(exp + 348) / 8u; + *outExp = -348 + static_cast(index) * 8; + return GetCachedPowerByIndex(index); +} + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +RAPIDJSON_DIAG_OFF(padded) +#endif + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_DIYFP_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/dtoa.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/dtoa.h new file mode 100644 index 0000000..cd45672 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/dtoa.h @@ -0,0 +1,249 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +// This is a C++ header-only implementation of Grisu2 algorithm from the publication: +// Loitsch, Florian. "Printing floating-point numbers quickly and accurately with +// integers." ACM Sigplan Notices 45.6 (2010): 233-243. + +#ifndef RAPIDJSON_DTOA_ +#define RAPIDJSON_DTOA_ + +#include "itoa.h" // GetDigitsLut() +#include "diyfp.h" +#include "ieee754.h" + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124 +#endif + +inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) { + while (rest < wp_w && delta - rest >= ten_kappa && + (rest + ten_kappa < wp_w || /// closer + wp_w - rest > rest + ten_kappa - wp_w)) { + buffer[len - 1]--; + rest += ten_kappa; + } +} + +inline int CountDecimalDigit32(uint32_t n) { + // Simple pure C++ implementation was faster than __builtin_clz version in this situation. + if (n < 10) return 1; + if (n < 100) return 2; + if (n < 1000) return 3; + if (n < 10000) return 4; + if (n < 100000) return 5; + if (n < 1000000) return 6; + if (n < 10000000) return 7; + if (n < 100000000) return 8; + // Will not reach 10 digits in DigitGen() + //if (n < 1000000000) return 9; + //return 10; + return 9; +} + +inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { + static const uint64_t kPow10[] = { 1ULL, 10ULL, 100ULL, 1000ULL, 10000ULL, 100000ULL, 1000000ULL, 10000000ULL, 100000000ULL, + 1000000000ULL, 10000000000ULL, 100000000000ULL, 1000000000000ULL, + 10000000000000ULL, 100000000000000ULL, 1000000000000000ULL, + 10000000000000000ULL, 100000000000000000ULL, 1000000000000000000ULL, + 10000000000000000000ULL }; + const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); + const DiyFp wp_w = Mp - W; + uint32_t p1 = static_cast(Mp.f >> -one.e); + uint64_t p2 = Mp.f & (one.f - 1); + int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] + *len = 0; + + while (kappa > 0) { + uint32_t d = 0; + switch (kappa) { + case 9: d = p1 / 100000000; p1 %= 100000000; break; + case 8: d = p1 / 10000000; p1 %= 10000000; break; + case 7: d = p1 / 1000000; p1 %= 1000000; break; + case 6: d = p1 / 100000; p1 %= 100000; break; + case 5: d = p1 / 10000; p1 %= 10000; break; + case 4: d = p1 / 1000; p1 %= 1000; break; + case 3: d = p1 / 100; p1 %= 100; break; + case 2: d = p1 / 10; p1 %= 10; break; + case 1: d = p1; p1 = 0; break; + default:; + } + if (d || *len) + buffer[(*len)++] = static_cast('0' + static_cast(d)); + kappa--; + uint64_t tmp = (static_cast(p1) << -one.e) + p2; + if (tmp <= delta) { + *K += kappa; + GrisuRound(buffer, *len, delta, tmp, kPow10[kappa] << -one.e, wp_w.f); + return; + } + } + + // kappa = 0 + for (;;) { + p2 *= 10; + delta *= 10; + char d = static_cast(p2 >> -one.e); + if (d || *len) + buffer[(*len)++] = static_cast('0' + d); + p2 &= one.f - 1; + kappa--; + if (p2 < delta) { + *K += kappa; + int index = -kappa; + GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 20 ? kPow10[index] : 0)); + return; + } + } +} + +inline void Grisu2(double value, char* buffer, int* length, int* K) { + const DiyFp v(value); + DiyFp w_m, w_p; + v.NormalizedBoundaries(&w_m, &w_p); + + const DiyFp c_mk = GetCachedPower(w_p.e, K); + const DiyFp W = v.Normalize() * c_mk; + DiyFp Wp = w_p * c_mk; + DiyFp Wm = w_m * c_mk; + Wm.f++; + Wp.f--; + DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K); +} + +inline char* WriteExponent(int K, char* buffer) { + if (K < 0) { + *buffer++ = '-'; + K = -K; + } + + if (K >= 100) { + *buffer++ = static_cast('0' + static_cast(K / 100)); + K %= 100; + const char* d = GetDigitsLut() + K * 2; + *buffer++ = d[0]; + *buffer++ = d[1]; + } + else if (K >= 10) { + const char* d = GetDigitsLut() + K * 2; + *buffer++ = d[0]; + *buffer++ = d[1]; + } + else + *buffer++ = static_cast('0' + static_cast(K)); + + return buffer; +} + +inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { + const int kk = length + k; // 10^(kk-1) <= v < 10^kk + + if (0 <= k && kk <= 21) { + // 1234e7 -> 12340000000 + for (int i = length; i < kk; i++) + buffer[i] = '0'; + buffer[kk] = '.'; + buffer[kk + 1] = '0'; + return &buffer[kk + 2]; + } + else if (0 < kk && kk <= 21) { + // 1234e-2 -> 12.34 + std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk)); + buffer[kk] = '.'; + if (0 > k + maxDecimalPlaces) { + // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1 + // Remove extra trailing zeros (at least one) after truncation. + for (int i = kk + maxDecimalPlaces; i > kk + 1; i--) + if (buffer[i] != '0') + return &buffer[i + 1]; + return &buffer[kk + 2]; // Reserve one zero + } + else + return &buffer[length + 1]; + } + else if (-6 < kk && kk <= 0) { + // 1234e-6 -> 0.001234 + const int offset = 2 - kk; + std::memmove(&buffer[offset], &buffer[0], static_cast(length)); + buffer[0] = '0'; + buffer[1] = '.'; + for (int i = 2; i < offset; i++) + buffer[i] = '0'; + if (length - kk > maxDecimalPlaces) { + // When maxDecimalPlaces = 2, 0.123 -> 0.12, 0.102 -> 0.1 + // Remove extra trailing zeros (at least one) after truncation. + for (int i = maxDecimalPlaces + 1; i > 2; i--) + if (buffer[i] != '0') + return &buffer[i + 1]; + return &buffer[3]; // Reserve one zero + } + else + return &buffer[length + offset]; + } + else if (kk < -maxDecimalPlaces) { + // Truncate to zero + buffer[0] = '0'; + buffer[1] = '.'; + buffer[2] = '0'; + return &buffer[3]; + } + else if (length == 1) { + // 1e30 + buffer[1] = 'e'; + return WriteExponent(kk - 1, &buffer[2]); + } + else { + // 1234e30 -> 1.234e33 + std::memmove(&buffer[2], &buffer[1], static_cast(length - 1)); + buffer[1] = '.'; + buffer[length + 1] = 'e'; + return WriteExponent(kk - 1, &buffer[0 + length + 2]); + } +} + +inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) { + RAPIDJSON_ASSERT(maxDecimalPlaces >= 1); + Double d(value); + if (d.IsZero()) { + if (d.Sign()) + *buffer++ = '-'; // -0.0, Issue #289 + buffer[0] = '0'; + buffer[1] = '.'; + buffer[2] = '0'; + return &buffer[3]; + } + else { + if (value < 0) { + *buffer++ = '-'; + value = -value; + } + int length, K; + Grisu2(value, buffer, &length, &K); + return Prettify(buffer, length, K, maxDecimalPlaces); + } +} + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_DTOA_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/ieee754.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/ieee754.h new file mode 100644 index 0000000..68c9e96 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/ieee754.h @@ -0,0 +1,78 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_IEEE754_ +#define RAPIDJSON_IEEE754_ + +#include "../rapidjson.h" + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +class Double { +public: + Double() {} + Double(double d) : d_(d) {} + Double(uint64_t u) : u_(u) {} + + double Value() const { return d_; } + uint64_t Uint64Value() const { return u_; } + + double NextPositiveDouble() const { + RAPIDJSON_ASSERT(!Sign()); + return Double(u_ + 1).Value(); + } + + bool Sign() const { return (u_ & kSignMask) != 0; } + uint64_t Significand() const { return u_ & kSignificandMask; } + int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } + + bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } + bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } + bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } + bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } + bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } + + uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } + int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } + uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } + + static int EffectiveSignificandSize(int order) { + if (order >= -1021) + return 53; + else if (order <= -1074) + return 0; + else + return order + 1074; + } + +private: + static const int kSignificandSize = 52; + static const int kExponentBias = 0x3FF; + static const int kDenormalExponent = 1 - kExponentBias; + static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); + static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); + static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); + static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); + + union { + double d_; + uint64_t u_; + }; +}; + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_IEEE754_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/itoa.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/itoa.h new file mode 100644 index 0000000..9fe8c93 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/itoa.h @@ -0,0 +1,308 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ITOA_ +#define RAPIDJSON_ITOA_ + +#include "../rapidjson.h" + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +inline const char* GetDigitsLut() { + static const char cDigitsLut[200] = { + '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9', + '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9', + '2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9', + '3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9', + '4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9', + '5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9', + '6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9', + '7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9', + '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9', + '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9' + }; + return cDigitsLut; +} + +inline char* u32toa(uint32_t value, char* buffer) { + RAPIDJSON_ASSERT(buffer != 0); + + const char* cDigitsLut = GetDigitsLut(); + + if (value < 10000) { + const uint32_t d1 = (value / 100) << 1; + const uint32_t d2 = (value % 100) << 1; + + if (value >= 1000) + *buffer++ = cDigitsLut[d1]; + if (value >= 100) + *buffer++ = cDigitsLut[d1 + 1]; + if (value >= 10) + *buffer++ = cDigitsLut[d2]; + *buffer++ = cDigitsLut[d2 + 1]; + } + else if (value < 100000000) { + // value = bbbbcccc + const uint32_t b = value / 10000; + const uint32_t c = value % 10000; + + const uint32_t d1 = (b / 100) << 1; + const uint32_t d2 = (b % 100) << 1; + + const uint32_t d3 = (c / 100) << 1; + const uint32_t d4 = (c % 100) << 1; + + if (value >= 10000000) + *buffer++ = cDigitsLut[d1]; + if (value >= 1000000) + *buffer++ = cDigitsLut[d1 + 1]; + if (value >= 100000) + *buffer++ = cDigitsLut[d2]; + *buffer++ = cDigitsLut[d2 + 1]; + + *buffer++ = cDigitsLut[d3]; + *buffer++ = cDigitsLut[d3 + 1]; + *buffer++ = cDigitsLut[d4]; + *buffer++ = cDigitsLut[d4 + 1]; + } + else { + // value = aabbbbcccc in decimal + + const uint32_t a = value / 100000000; // 1 to 42 + value %= 100000000; + + if (a >= 10) { + const unsigned i = a << 1; + *buffer++ = cDigitsLut[i]; + *buffer++ = cDigitsLut[i + 1]; + } + else + *buffer++ = static_cast('0' + static_cast(a)); + + const uint32_t b = value / 10000; // 0 to 9999 + const uint32_t c = value % 10000; // 0 to 9999 + + const uint32_t d1 = (b / 100) << 1; + const uint32_t d2 = (b % 100) << 1; + + const uint32_t d3 = (c / 100) << 1; + const uint32_t d4 = (c % 100) << 1; + + *buffer++ = cDigitsLut[d1]; + *buffer++ = cDigitsLut[d1 + 1]; + *buffer++ = cDigitsLut[d2]; + *buffer++ = cDigitsLut[d2 + 1]; + *buffer++ = cDigitsLut[d3]; + *buffer++ = cDigitsLut[d3 + 1]; + *buffer++ = cDigitsLut[d4]; + *buffer++ = cDigitsLut[d4 + 1]; + } + return buffer; +} + +inline char* i32toa(int32_t value, char* buffer) { + RAPIDJSON_ASSERT(buffer != 0); + uint32_t u = static_cast(value); + if (value < 0) { + *buffer++ = '-'; + u = ~u + 1; + } + + return u32toa(u, buffer); +} + +inline char* u64toa(uint64_t value, char* buffer) { + RAPIDJSON_ASSERT(buffer != 0); + const char* cDigitsLut = GetDigitsLut(); + const uint64_t kTen8 = 100000000; + const uint64_t kTen9 = kTen8 * 10; + const uint64_t kTen10 = kTen8 * 100; + const uint64_t kTen11 = kTen8 * 1000; + const uint64_t kTen12 = kTen8 * 10000; + const uint64_t kTen13 = kTen8 * 100000; + const uint64_t kTen14 = kTen8 * 1000000; + const uint64_t kTen15 = kTen8 * 10000000; + const uint64_t kTen16 = kTen8 * kTen8; + + if (value < kTen8) { + uint32_t v = static_cast(value); + if (v < 10000) { + const uint32_t d1 = (v / 100) << 1; + const uint32_t d2 = (v % 100) << 1; + + if (v >= 1000) + *buffer++ = cDigitsLut[d1]; + if (v >= 100) + *buffer++ = cDigitsLut[d1 + 1]; + if (v >= 10) + *buffer++ = cDigitsLut[d2]; + *buffer++ = cDigitsLut[d2 + 1]; + } + else { + // value = bbbbcccc + const uint32_t b = v / 10000; + const uint32_t c = v % 10000; + + const uint32_t d1 = (b / 100) << 1; + const uint32_t d2 = (b % 100) << 1; + + const uint32_t d3 = (c / 100) << 1; + const uint32_t d4 = (c % 100) << 1; + + if (value >= 10000000) + *buffer++ = cDigitsLut[d1]; + if (value >= 1000000) + *buffer++ = cDigitsLut[d1 + 1]; + if (value >= 100000) + *buffer++ = cDigitsLut[d2]; + *buffer++ = cDigitsLut[d2 + 1]; + + *buffer++ = cDigitsLut[d3]; + *buffer++ = cDigitsLut[d3 + 1]; + *buffer++ = cDigitsLut[d4]; + *buffer++ = cDigitsLut[d4 + 1]; + } + } + else if (value < kTen16) { + const uint32_t v0 = static_cast(value / kTen8); + const uint32_t v1 = static_cast(value % kTen8); + + const uint32_t b0 = v0 / 10000; + const uint32_t c0 = v0 % 10000; + + const uint32_t d1 = (b0 / 100) << 1; + const uint32_t d2 = (b0 % 100) << 1; + + const uint32_t d3 = (c0 / 100) << 1; + const uint32_t d4 = (c0 % 100) << 1; + + const uint32_t b1 = v1 / 10000; + const uint32_t c1 = v1 % 10000; + + const uint32_t d5 = (b1 / 100) << 1; + const uint32_t d6 = (b1 % 100) << 1; + + const uint32_t d7 = (c1 / 100) << 1; + const uint32_t d8 = (c1 % 100) << 1; + + if (value >= kTen15) + *buffer++ = cDigitsLut[d1]; + if (value >= kTen14) + *buffer++ = cDigitsLut[d1 + 1]; + if (value >= kTen13) + *buffer++ = cDigitsLut[d2]; + if (value >= kTen12) + *buffer++ = cDigitsLut[d2 + 1]; + if (value >= kTen11) + *buffer++ = cDigitsLut[d3]; + if (value >= kTen10) + *buffer++ = cDigitsLut[d3 + 1]; + if (value >= kTen9) + *buffer++ = cDigitsLut[d4]; + + *buffer++ = cDigitsLut[d4 + 1]; + *buffer++ = cDigitsLut[d5]; + *buffer++ = cDigitsLut[d5 + 1]; + *buffer++ = cDigitsLut[d6]; + *buffer++ = cDigitsLut[d6 + 1]; + *buffer++ = cDigitsLut[d7]; + *buffer++ = cDigitsLut[d7 + 1]; + *buffer++ = cDigitsLut[d8]; + *buffer++ = cDigitsLut[d8 + 1]; + } + else { + const uint32_t a = static_cast(value / kTen16); // 1 to 1844 + value %= kTen16; + + if (a < 10) + *buffer++ = static_cast('0' + static_cast(a)); + else if (a < 100) { + const uint32_t i = a << 1; + *buffer++ = cDigitsLut[i]; + *buffer++ = cDigitsLut[i + 1]; + } + else if (a < 1000) { + *buffer++ = static_cast('0' + static_cast(a / 100)); + + const uint32_t i = (a % 100) << 1; + *buffer++ = cDigitsLut[i]; + *buffer++ = cDigitsLut[i + 1]; + } + else { + const uint32_t i = (a / 100) << 1; + const uint32_t j = (a % 100) << 1; + *buffer++ = cDigitsLut[i]; + *buffer++ = cDigitsLut[i + 1]; + *buffer++ = cDigitsLut[j]; + *buffer++ = cDigitsLut[j + 1]; + } + + const uint32_t v0 = static_cast(value / kTen8); + const uint32_t v1 = static_cast(value % kTen8); + + const uint32_t b0 = v0 / 10000; + const uint32_t c0 = v0 % 10000; + + const uint32_t d1 = (b0 / 100) << 1; + const uint32_t d2 = (b0 % 100) << 1; + + const uint32_t d3 = (c0 / 100) << 1; + const uint32_t d4 = (c0 % 100) << 1; + + const uint32_t b1 = v1 / 10000; + const uint32_t c1 = v1 % 10000; + + const uint32_t d5 = (b1 / 100) << 1; + const uint32_t d6 = (b1 % 100) << 1; + + const uint32_t d7 = (c1 / 100) << 1; + const uint32_t d8 = (c1 % 100) << 1; + + *buffer++ = cDigitsLut[d1]; + *buffer++ = cDigitsLut[d1 + 1]; + *buffer++ = cDigitsLut[d2]; + *buffer++ = cDigitsLut[d2 + 1]; + *buffer++ = cDigitsLut[d3]; + *buffer++ = cDigitsLut[d3 + 1]; + *buffer++ = cDigitsLut[d4]; + *buffer++ = cDigitsLut[d4 + 1]; + *buffer++ = cDigitsLut[d5]; + *buffer++ = cDigitsLut[d5 + 1]; + *buffer++ = cDigitsLut[d6]; + *buffer++ = cDigitsLut[d6 + 1]; + *buffer++ = cDigitsLut[d7]; + *buffer++ = cDigitsLut[d7 + 1]; + *buffer++ = cDigitsLut[d8]; + *buffer++ = cDigitsLut[d8 + 1]; + } + + return buffer; +} + +inline char* i64toa(int64_t value, char* buffer) { + RAPIDJSON_ASSERT(buffer != 0); + uint64_t u = static_cast(value); + if (value < 0) { + *buffer++ = '-'; + u = ~u + 1; + } + + return u64toa(u, buffer); +} + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_ITOA_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/meta.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/meta.h new file mode 100644 index 0000000..27092dc --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/meta.h @@ -0,0 +1,186 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_INTERNAL_META_H_ +#define RAPIDJSON_INTERNAL_META_H_ + +#include "../rapidjson.h" + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#if defined(_MSC_VER) && !defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(6334) +#endif + +#if RAPIDJSON_HAS_CXX11_TYPETRAITS +#include +#endif + +//@cond RAPIDJSON_INTERNAL +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching +template struct Void { typedef void Type; }; + +/////////////////////////////////////////////////////////////////////////////// +// BoolType, TrueType, FalseType +// +template struct BoolType { + static const bool Value = Cond; + typedef BoolType Type; +}; +typedef BoolType TrueType; +typedef BoolType FalseType; + + +/////////////////////////////////////////////////////////////////////////////// +// SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr +// + +template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; }; +template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; }; +template struct SelectIfCond : SelectIfImpl::template Apply {}; +template struct SelectIf : SelectIfCond {}; + +template struct AndExprCond : FalseType {}; +template <> struct AndExprCond : TrueType {}; +template struct OrExprCond : TrueType {}; +template <> struct OrExprCond : FalseType {}; + +template struct BoolExpr : SelectIf::Type {}; +template struct NotExpr : SelectIf::Type {}; +template struct AndExpr : AndExprCond::Type {}; +template struct OrExpr : OrExprCond::Type {}; + + +/////////////////////////////////////////////////////////////////////////////// +// AddConst, MaybeAddConst, RemoveConst +template struct AddConst { typedef const T Type; }; +template struct MaybeAddConst : SelectIfCond {}; +template struct RemoveConst { typedef T Type; }; +template struct RemoveConst { typedef T Type; }; + + +/////////////////////////////////////////////////////////////////////////////// +// IsSame, IsConst, IsMoreConst, IsPointer +// +template struct IsSame : FalseType {}; +template struct IsSame : TrueType {}; + +template struct IsConst : FalseType {}; +template struct IsConst : TrueType {}; + +template +struct IsMoreConst + : AndExpr::Type, typename RemoveConst::Type>, + BoolType::Value >= IsConst::Value> >::Type {}; + +template struct IsPointer : FalseType {}; +template struct IsPointer : TrueType {}; + +/////////////////////////////////////////////////////////////////////////////// +// IsBaseOf +// +#if RAPIDJSON_HAS_CXX11_TYPETRAITS + +template struct IsBaseOf + : BoolType< ::std::is_base_of::value> {}; + +#else // simplified version adopted from Boost + +template struct IsBaseOfImpl { + RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0); + RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0); + + typedef char (&Yes)[1]; + typedef char (&No) [2]; + + template + static Yes Check(const D*, T); + static No Check(const B*, int); + + struct Host { + operator const B*() const; + operator const D*(); + }; + + enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) }; +}; + +template struct IsBaseOf + : OrExpr, BoolExpr > >::Type {}; + +#endif // RAPIDJSON_HAS_CXX11_TYPETRAITS + + +////////////////////////////////////////////////////////////////////////// +// EnableIf / DisableIf +// +template struct EnableIfCond { typedef T Type; }; +template struct EnableIfCond { /* empty */ }; + +template struct DisableIfCond { typedef T Type; }; +template struct DisableIfCond { /* empty */ }; + +template +struct EnableIf : EnableIfCond {}; + +template +struct DisableIf : DisableIfCond {}; + +// SFINAE helpers +struct SfinaeTag {}; +template struct RemoveSfinaeTag; +template struct RemoveSfinaeTag { typedef T Type; }; + +#define RAPIDJSON_REMOVEFPTR_(type) \ + typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ + < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type + +#define RAPIDJSON_ENABLEIF(cond) \ + typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ + ::Type * = NULL + +#define RAPIDJSON_DISABLEIF(cond) \ + typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ + ::Type * = NULL + +#define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ + typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ + ::Type + +#define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ + typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ + ::Type + +} // namespace internal +RAPIDJSON_NAMESPACE_END +//@endcond + +#if defined(_MSC_VER) && !defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_INTERNAL_META_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/pow10.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/pow10.h new file mode 100644 index 0000000..eae1a43 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/pow10.h @@ -0,0 +1,55 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_POW10_ +#define RAPIDJSON_POW10_ + +#include "../rapidjson.h" + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +//! Computes integer powers of 10 in double (10.0^n). +/*! This function uses lookup table for fast and accurate results. + \param n non-negative exponent. Must <= 308. + \return 10.0^n +*/ +inline double Pow10(int n) { + static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes + 1e+0, + 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, + 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, + 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, + 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, + 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, + 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, + 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, + 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, + 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, + 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, + 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, + 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, + 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, + 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, + 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, + 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 + }; + RAPIDJSON_ASSERT(n >= 0 && n <= 308); + return e[n]; +} + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_POW10_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/regex.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/regex.h new file mode 100644 index 0000000..6446c40 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/regex.h @@ -0,0 +1,739 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_INTERNAL_REGEX_H_ +#define RAPIDJSON_INTERNAL_REGEX_H_ + +#include "../allocators.h" +#include "../stream.h" +#include "stack.h" + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +RAPIDJSON_DIAG_OFF(switch-enum) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#ifndef RAPIDJSON_REGEX_VERBOSE +#define RAPIDJSON_REGEX_VERBOSE 0 +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +/////////////////////////////////////////////////////////////////////////////// +// DecodedStream + +template +class DecodedStream { +public: + DecodedStream(SourceStream& ss) : ss_(ss), codepoint_() { Decode(); } + unsigned Peek() { return codepoint_; } + unsigned Take() { + unsigned c = codepoint_; + if (c) // No further decoding when '\0' + Decode(); + return c; + } + +private: + void Decode() { + if (!Encoding::Decode(ss_, &codepoint_)) + codepoint_ = 0; + } + + SourceStream& ss_; + unsigned codepoint_; +}; + +/////////////////////////////////////////////////////////////////////////////// +// GenericRegex + +static const SizeType kRegexInvalidState = ~SizeType(0); //!< Represents an invalid index in GenericRegex::State::out, out1 +static const SizeType kRegexInvalidRange = ~SizeType(0); + +template +class GenericRegexSearch; + +//! Regular expression engine with subset of ECMAscript grammar. +/*! + Supported regular expression syntax: + - \c ab Concatenation + - \c a|b Alternation + - \c a? Zero or one + - \c a* Zero or more + - \c a+ One or more + - \c a{3} Exactly 3 times + - \c a{3,} At least 3 times + - \c a{3,5} 3 to 5 times + - \c (ab) Grouping + - \c ^a At the beginning + - \c a$ At the end + - \c . Any character + - \c [abc] Character classes + - \c [a-c] Character class range + - \c [a-z0-9_] Character class combination + - \c [^abc] Negated character classes + - \c [^a-c] Negated character class range + - \c [\b] Backspace (U+0008) + - \c \\| \\\\ ... Escape characters + - \c \\f Form feed (U+000C) + - \c \\n Line feed (U+000A) + - \c \\r Carriage return (U+000D) + - \c \\t Tab (U+0009) + - \c \\v Vertical tab (U+000B) + + \note This is a Thompson NFA engine, implemented with reference to + Cox, Russ. "Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby,...).", + https://swtch.com/~rsc/regexp/regexp1.html +*/ +template +class GenericRegex { +public: + typedef Encoding EncodingType; + typedef typename Encoding::Ch Ch; + template friend class GenericRegexSearch; + + GenericRegex(const Ch* source, Allocator* allocator = 0) : + ownAllocator_(allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_), + states_(allocator_, 256), ranges_(allocator_, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), + anchorBegin_(), anchorEnd_() + { + GenericStringStream ss(source); + DecodedStream, Encoding> ds(ss); + Parse(ds); + } + + ~GenericRegex() + { + RAPIDJSON_DELETE(ownAllocator_); + } + + bool IsValid() const { + return root_ != kRegexInvalidState; + } + +private: + enum Operator { + kZeroOrOne, + kZeroOrMore, + kOneOrMore, + kConcatenation, + kAlternation, + kLeftParenthesis + }; + + static const unsigned kAnyCharacterClass = 0xFFFFFFFF; //!< For '.' + static const unsigned kRangeCharacterClass = 0xFFFFFFFE; + static const unsigned kRangeNegationFlag = 0x80000000; + + struct Range { + unsigned start; // + unsigned end; + SizeType next; + }; + + struct State { + SizeType out; //!< Equals to kInvalid for matching state + SizeType out1; //!< Equals to non-kInvalid for split + SizeType rangeStart; + unsigned codepoint; + }; + + struct Frag { + Frag(SizeType s, SizeType o, SizeType m) : start(s), out(o), minIndex(m) {} + SizeType start; + SizeType out; //!< link-list of all output states + SizeType minIndex; + }; + + State& GetState(SizeType index) { + RAPIDJSON_ASSERT(index < stateCount_); + return states_.template Bottom()[index]; + } + + const State& GetState(SizeType index) const { + RAPIDJSON_ASSERT(index < stateCount_); + return states_.template Bottom()[index]; + } + + Range& GetRange(SizeType index) { + RAPIDJSON_ASSERT(index < rangeCount_); + return ranges_.template Bottom()[index]; + } + + const Range& GetRange(SizeType index) const { + RAPIDJSON_ASSERT(index < rangeCount_); + return ranges_.template Bottom()[index]; + } + + template + void Parse(DecodedStream& ds) { + Stack operandStack(allocator_, 256); // Frag + Stack operatorStack(allocator_, 256); // Operator + Stack atomCountStack(allocator_, 256); // unsigned (Atom per parenthesis) + + *atomCountStack.template Push() = 0; + + unsigned codepoint; + while (ds.Peek() != 0) { + switch (codepoint = ds.Take()) { + case '^': + anchorBegin_ = true; + break; + + case '$': + anchorEnd_ = true; + break; + + case '|': + while (!operatorStack.Empty() && *operatorStack.template Top() < kAlternation) + if (!Eval(operandStack, *operatorStack.template Pop(1))) + return; + *operatorStack.template Push() = kAlternation; + *atomCountStack.template Top() = 0; + break; + + case '(': + *operatorStack.template Push() = kLeftParenthesis; + *atomCountStack.template Push() = 0; + break; + + case ')': + while (!operatorStack.Empty() && *operatorStack.template Top() != kLeftParenthesis) + if (!Eval(operandStack, *operatorStack.template Pop(1))) + return; + if (operatorStack.Empty()) + return; + operatorStack.template Pop(1); + atomCountStack.template Pop(1); + ImplicitConcatenation(atomCountStack, operatorStack); + break; + + case '?': + if (!Eval(operandStack, kZeroOrOne)) + return; + break; + + case '*': + if (!Eval(operandStack, kZeroOrMore)) + return; + break; + + case '+': + if (!Eval(operandStack, kOneOrMore)) + return; + break; + + case '{': + { + unsigned n, m; + if (!ParseUnsigned(ds, &n)) + return; + + if (ds.Peek() == ',') { + ds.Take(); + if (ds.Peek() == '}') + m = kInfinityQuantifier; + else if (!ParseUnsigned(ds, &m) || m < n) + return; + } + else + m = n; + + if (!EvalQuantifier(operandStack, n, m) || ds.Peek() != '}') + return; + ds.Take(); + } + break; + + case '.': + PushOperand(operandStack, kAnyCharacterClass); + ImplicitConcatenation(atomCountStack, operatorStack); + break; + + case '[': + { + SizeType range; + if (!ParseRange(ds, &range)) + return; + SizeType s = NewState(kRegexInvalidState, kRegexInvalidState, kRangeCharacterClass); + GetState(s).rangeStart = range; + *operandStack.template Push() = Frag(s, s, s); + } + ImplicitConcatenation(atomCountStack, operatorStack); + break; + + case '\\': // Escape character + if (!CharacterEscape(ds, &codepoint)) + return; // Unsupported escape character + // fall through to default + RAPIDJSON_DELIBERATE_FALLTHROUGH; + + default: // Pattern character + PushOperand(operandStack, codepoint); + ImplicitConcatenation(atomCountStack, operatorStack); + } + } + + while (!operatorStack.Empty()) + if (!Eval(operandStack, *operatorStack.template Pop(1))) + return; + + // Link the operand to matching state. + if (operandStack.GetSize() == sizeof(Frag)) { + Frag* e = operandStack.template Pop(1); + Patch(e->out, NewState(kRegexInvalidState, kRegexInvalidState, 0)); + root_ = e->start; + +#if RAPIDJSON_REGEX_VERBOSE + printf("root: %d\n", root_); + for (SizeType i = 0; i < stateCount_ ; i++) { + State& s = GetState(i); + printf("[%2d] out: %2d out1: %2d c: '%c'\n", i, s.out, s.out1, (char)s.codepoint); + } + printf("\n"); +#endif + } + } + + SizeType NewState(SizeType out, SizeType out1, unsigned codepoint) { + State* s = states_.template Push(); + s->out = out; + s->out1 = out1; + s->codepoint = codepoint; + s->rangeStart = kRegexInvalidRange; + return stateCount_++; + } + + void PushOperand(Stack& operandStack, unsigned codepoint) { + SizeType s = NewState(kRegexInvalidState, kRegexInvalidState, codepoint); + *operandStack.template Push() = Frag(s, s, s); + } + + void ImplicitConcatenation(Stack& atomCountStack, Stack& operatorStack) { + if (*atomCountStack.template Top()) + *operatorStack.template Push() = kConcatenation; + (*atomCountStack.template Top())++; + } + + SizeType Append(SizeType l1, SizeType l2) { + SizeType old = l1; + while (GetState(l1).out != kRegexInvalidState) + l1 = GetState(l1).out; + GetState(l1).out = l2; + return old; + } + + void Patch(SizeType l, SizeType s) { + for (SizeType next; l != kRegexInvalidState; l = next) { + next = GetState(l).out; + GetState(l).out = s; + } + } + + bool Eval(Stack& operandStack, Operator op) { + switch (op) { + case kConcatenation: + RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag) * 2); + { + Frag e2 = *operandStack.template Pop(1); + Frag e1 = *operandStack.template Pop(1); + Patch(e1.out, e2.start); + *operandStack.template Push() = Frag(e1.start, e2.out, Min(e1.minIndex, e2.minIndex)); + } + return true; + + case kAlternation: + if (operandStack.GetSize() >= sizeof(Frag) * 2) { + Frag e2 = *operandStack.template Pop(1); + Frag e1 = *operandStack.template Pop(1); + SizeType s = NewState(e1.start, e2.start, 0); + *operandStack.template Push() = Frag(s, Append(e1.out, e2.out), Min(e1.minIndex, e2.minIndex)); + return true; + } + return false; + + case kZeroOrOne: + if (operandStack.GetSize() >= sizeof(Frag)) { + Frag e = *operandStack.template Pop(1); + SizeType s = NewState(kRegexInvalidState, e.start, 0); + *operandStack.template Push() = Frag(s, Append(e.out, s), e.minIndex); + return true; + } + return false; + + case kZeroOrMore: + if (operandStack.GetSize() >= sizeof(Frag)) { + Frag e = *operandStack.template Pop(1); + SizeType s = NewState(kRegexInvalidState, e.start, 0); + Patch(e.out, s); + *operandStack.template Push() = Frag(s, s, e.minIndex); + return true; + } + return false; + + case kOneOrMore: + if (operandStack.GetSize() >= sizeof(Frag)) { + Frag e = *operandStack.template Pop(1); + SizeType s = NewState(kRegexInvalidState, e.start, 0); + Patch(e.out, s); + *operandStack.template Push() = Frag(e.start, s, e.minIndex); + return true; + } + return false; + + default: + // syntax error (e.g. unclosed kLeftParenthesis) + return false; + } + } + + bool EvalQuantifier(Stack& operandStack, unsigned n, unsigned m) { + RAPIDJSON_ASSERT(n <= m); + RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag)); + + if (n == 0) { + if (m == 0) // a{0} not support + return false; + else if (m == kInfinityQuantifier) + Eval(operandStack, kZeroOrMore); // a{0,} -> a* + else { + Eval(operandStack, kZeroOrOne); // a{0,5} -> a? + for (unsigned i = 0; i < m - 1; i++) + CloneTopOperand(operandStack); // a{0,5} -> a? a? a? a? a? + for (unsigned i = 0; i < m - 1; i++) + Eval(operandStack, kConcatenation); // a{0,5} -> a?a?a?a?a? + } + return true; + } + + for (unsigned i = 0; i < n - 1; i++) // a{3} -> a a a + CloneTopOperand(operandStack); + + if (m == kInfinityQuantifier) + Eval(operandStack, kOneOrMore); // a{3,} -> a a a+ + else if (m > n) { + CloneTopOperand(operandStack); // a{3,5} -> a a a a + Eval(operandStack, kZeroOrOne); // a{3,5} -> a a a a? + for (unsigned i = n; i < m - 1; i++) + CloneTopOperand(operandStack); // a{3,5} -> a a a a? a? + for (unsigned i = n; i < m; i++) + Eval(operandStack, kConcatenation); // a{3,5} -> a a aa?a? + } + + for (unsigned i = 0; i < n - 1; i++) + Eval(operandStack, kConcatenation); // a{3} -> aaa, a{3,} -> aaa+, a{3.5} -> aaaa?a? + + return true; + } + + static SizeType Min(SizeType a, SizeType b) { return a < b ? a : b; } + + void CloneTopOperand(Stack& operandStack) { + const Frag src = *operandStack.template Top(); // Copy constructor to prevent invalidation + SizeType count = stateCount_ - src.minIndex; // Assumes top operand contains states in [src->minIndex, stateCount_) + State* s = states_.template Push(count); + memcpy(s, &GetState(src.minIndex), count * sizeof(State)); + for (SizeType j = 0; j < count; j++) { + if (s[j].out != kRegexInvalidState) + s[j].out += count; + if (s[j].out1 != kRegexInvalidState) + s[j].out1 += count; + } + *operandStack.template Push() = Frag(src.start + count, src.out + count, src.minIndex + count); + stateCount_ += count; + } + + template + bool ParseUnsigned(DecodedStream& ds, unsigned* u) { + unsigned r = 0; + if (ds.Peek() < '0' || ds.Peek() > '9') + return false; + while (ds.Peek() >= '0' && ds.Peek() <= '9') { + if (r >= 429496729 && ds.Peek() > '5') // 2^32 - 1 = 4294967295 + return false; // overflow + r = r * 10 + (ds.Take() - '0'); + } + *u = r; + return true; + } + + template + bool ParseRange(DecodedStream& ds, SizeType* range) { + bool isBegin = true; + bool negate = false; + int step = 0; + SizeType start = kRegexInvalidRange; + SizeType current = kRegexInvalidRange; + unsigned codepoint; + while ((codepoint = ds.Take()) != 0) { + if (isBegin) { + isBegin = false; + if (codepoint == '^') { + negate = true; + continue; + } + } + + switch (codepoint) { + case ']': + if (start == kRegexInvalidRange) + return false; // Error: nothing inside [] + if (step == 2) { // Add trailing '-' + SizeType r = NewRange('-'); + RAPIDJSON_ASSERT(current != kRegexInvalidRange); + GetRange(current).next = r; + } + if (negate) + GetRange(start).start |= kRangeNegationFlag; + *range = start; + return true; + + case '\\': + if (ds.Peek() == 'b') { + ds.Take(); + codepoint = 0x0008; // Escape backspace character + } + else if (!CharacterEscape(ds, &codepoint)) + return false; + // fall through to default + RAPIDJSON_DELIBERATE_FALLTHROUGH; + + default: + switch (step) { + case 1: + if (codepoint == '-') { + step++; + break; + } + // fall through to step 0 for other characters + RAPIDJSON_DELIBERATE_FALLTHROUGH; + + case 0: + { + SizeType r = NewRange(codepoint); + if (current != kRegexInvalidRange) + GetRange(current).next = r; + if (start == kRegexInvalidRange) + start = r; + current = r; + } + step = 1; + break; + + default: + RAPIDJSON_ASSERT(step == 2); + GetRange(current).end = codepoint; + step = 0; + } + } + } + return false; + } + + SizeType NewRange(unsigned codepoint) { + Range* r = ranges_.template Push(); + r->start = r->end = codepoint; + r->next = kRegexInvalidRange; + return rangeCount_++; + } + + template + bool CharacterEscape(DecodedStream& ds, unsigned* escapedCodepoint) { + unsigned codepoint; + switch (codepoint = ds.Take()) { + case '^': + case '$': + case '|': + case '(': + case ')': + case '?': + case '*': + case '+': + case '.': + case '[': + case ']': + case '{': + case '}': + case '\\': + *escapedCodepoint = codepoint; return true; + case 'f': *escapedCodepoint = 0x000C; return true; + case 'n': *escapedCodepoint = 0x000A; return true; + case 'r': *escapedCodepoint = 0x000D; return true; + case 't': *escapedCodepoint = 0x0009; return true; + case 'v': *escapedCodepoint = 0x000B; return true; + default: + return false; // Unsupported escape character + } + } + + Allocator* ownAllocator_; + Allocator* allocator_; + Stack states_; + Stack ranges_; + SizeType root_; + SizeType stateCount_; + SizeType rangeCount_; + + static const unsigned kInfinityQuantifier = ~0u; + + // For SearchWithAnchoring() + bool anchorBegin_; + bool anchorEnd_; +}; + +template +class GenericRegexSearch { +public: + typedef typename RegexType::EncodingType Encoding; + typedef typename Encoding::Ch Ch; + + GenericRegexSearch(const RegexType& regex, Allocator* allocator = 0) : + regex_(regex), allocator_(allocator), ownAllocator_(0), + state0_(allocator, 0), state1_(allocator, 0), stateSet_() + { + RAPIDJSON_ASSERT(regex_.IsValid()); + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + stateSet_ = static_cast(allocator_->Malloc(GetStateSetSize())); + state0_.template Reserve(regex_.stateCount_); + state1_.template Reserve(regex_.stateCount_); + } + + ~GenericRegexSearch() { + Allocator::Free(stateSet_); + RAPIDJSON_DELETE(ownAllocator_); + } + + template + bool Match(InputStream& is) { + return SearchWithAnchoring(is, true, true); + } + + bool Match(const Ch* s) { + GenericStringStream is(s); + return Match(is); + } + + template + bool Search(InputStream& is) { + return SearchWithAnchoring(is, regex_.anchorBegin_, regex_.anchorEnd_); + } + + bool Search(const Ch* s) { + GenericStringStream is(s); + return Search(is); + } + +private: + typedef typename RegexType::State State; + typedef typename RegexType::Range Range; + + template + bool SearchWithAnchoring(InputStream& is, bool anchorBegin, bool anchorEnd) { + DecodedStream ds(is); + + state0_.Clear(); + Stack *current = &state0_, *next = &state1_; + const size_t stateSetSize = GetStateSetSize(); + std::memset(stateSet_, 0, stateSetSize); + + bool matched = AddState(*current, regex_.root_); + unsigned codepoint; + while (!current->Empty() && (codepoint = ds.Take()) != 0) { + std::memset(stateSet_, 0, stateSetSize); + next->Clear(); + matched = false; + for (const SizeType* s = current->template Bottom(); s != current->template End(); ++s) { + const State& sr = regex_.GetState(*s); + if (sr.codepoint == codepoint || + sr.codepoint == RegexType::kAnyCharacterClass || + (sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint))) + { + matched = AddState(*next, sr.out) || matched; + if (!anchorEnd && matched) + return true; + } + if (!anchorBegin) + AddState(*next, regex_.root_); + } + internal::Swap(current, next); + } + + return matched; + } + + size_t GetStateSetSize() const { + return (regex_.stateCount_ + 31) / 32 * 4; + } + + // Return whether the added states is a match state + bool AddState(Stack& l, SizeType index) { + RAPIDJSON_ASSERT(index != kRegexInvalidState); + + const State& s = regex_.GetState(index); + if (s.out1 != kRegexInvalidState) { // Split + bool matched = AddState(l, s.out); + return AddState(l, s.out1) || matched; + } + else if (!(stateSet_[index >> 5] & (1u << (index & 31)))) { + stateSet_[index >> 5] |= (1u << (index & 31)); + *l.template PushUnsafe() = index; + } + return s.out == kRegexInvalidState; // by using PushUnsafe() above, we can ensure s is not validated due to reallocation. + } + + bool MatchRange(SizeType rangeIndex, unsigned codepoint) const { + bool yes = (regex_.GetRange(rangeIndex).start & RegexType::kRangeNegationFlag) == 0; + while (rangeIndex != kRegexInvalidRange) { + const Range& r = regex_.GetRange(rangeIndex); + if (codepoint >= (r.start & ~RegexType::kRangeNegationFlag) && codepoint <= r.end) + return yes; + rangeIndex = r.next; + } + return !yes; + } + + const RegexType& regex_; + Allocator* allocator_; + Allocator* ownAllocator_; + Stack state0_; + Stack state1_; + uint32_t* stateSet_; +}; + +typedef GenericRegex > Regex; +typedef GenericRegexSearch RegexSearch; + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +#if defined(__clang__) || defined(_MSC_VER) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_INTERNAL_REGEX_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/stack.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/stack.h new file mode 100644 index 0000000..73abd70 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/stack.h @@ -0,0 +1,232 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_INTERNAL_STACK_H_ +#define RAPIDJSON_INTERNAL_STACK_H_ + +#include "../allocators.h" +#include "swap.h" +#include + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +/////////////////////////////////////////////////////////////////////////////// +// Stack + +//! A type-unsafe stack for storing different types of data. +/*! \tparam Allocator Allocator for allocating stack memory. +*/ +template +class Stack { +public: + // Optimization note: Do not allocate memory for stack_ in constructor. + // Do it lazily when first Push() -> Expand() -> Resize(). + Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) { + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + Stack(Stack&& rhs) + : allocator_(rhs.allocator_), + ownAllocator_(rhs.ownAllocator_), + stack_(rhs.stack_), + stackTop_(rhs.stackTop_), + stackEnd_(rhs.stackEnd_), + initialCapacity_(rhs.initialCapacity_) + { + rhs.allocator_ = 0; + rhs.ownAllocator_ = 0; + rhs.stack_ = 0; + rhs.stackTop_ = 0; + rhs.stackEnd_ = 0; + rhs.initialCapacity_ = 0; + } +#endif + + ~Stack() { + Destroy(); + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + Stack& operator=(Stack&& rhs) { + if (&rhs != this) + { + Destroy(); + + allocator_ = rhs.allocator_; + ownAllocator_ = rhs.ownAllocator_; + stack_ = rhs.stack_; + stackTop_ = rhs.stackTop_; + stackEnd_ = rhs.stackEnd_; + initialCapacity_ = rhs.initialCapacity_; + + rhs.allocator_ = 0; + rhs.ownAllocator_ = 0; + rhs.stack_ = 0; + rhs.stackTop_ = 0; + rhs.stackEnd_ = 0; + rhs.initialCapacity_ = 0; + } + return *this; + } +#endif + + void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { + internal::Swap(allocator_, rhs.allocator_); + internal::Swap(ownAllocator_, rhs.ownAllocator_); + internal::Swap(stack_, rhs.stack_); + internal::Swap(stackTop_, rhs.stackTop_); + internal::Swap(stackEnd_, rhs.stackEnd_); + internal::Swap(initialCapacity_, rhs.initialCapacity_); + } + + void Clear() { stackTop_ = stack_; } + + void ShrinkToFit() { + if (Empty()) { + // If the stack is empty, completely deallocate the memory. + Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc) + stack_ = 0; + stackTop_ = 0; + stackEnd_ = 0; + } + else + Resize(GetSize()); + } + + // Optimization note: try to minimize the size of this function for force inline. + // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. + template + RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { + // Expand the stack if needed + if (RAPIDJSON_UNLIKELY(static_cast(sizeof(T) * count) > (stackEnd_ - stackTop_))) + Expand(count); + } + + template + RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) { + Reserve(count); + return PushUnsafe(count); + } + + template + RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { + RAPIDJSON_ASSERT(stackTop_); + RAPIDJSON_ASSERT(static_cast(sizeof(T) * count) <= (stackEnd_ - stackTop_)); + T* ret = reinterpret_cast(stackTop_); + stackTop_ += sizeof(T) * count; + return ret; + } + + template + T* Pop(size_t count) { + RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); + stackTop_ -= count * sizeof(T); + return reinterpret_cast(stackTop_); + } + + template + T* Top() { + RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); + return reinterpret_cast(stackTop_ - sizeof(T)); + } + + template + const T* Top() const { + RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); + return reinterpret_cast(stackTop_ - sizeof(T)); + } + + template + T* End() { return reinterpret_cast(stackTop_); } + + template + const T* End() const { return reinterpret_cast(stackTop_); } + + template + T* Bottom() { return reinterpret_cast(stack_); } + + template + const T* Bottom() const { return reinterpret_cast(stack_); } + + bool HasAllocator() const { + return allocator_ != 0; + } + + Allocator& GetAllocator() { + RAPIDJSON_ASSERT(allocator_); + return *allocator_; + } + + bool Empty() const { return stackTop_ == stack_; } + size_t GetSize() const { return static_cast(stackTop_ - stack_); } + size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); } + +private: + template + void Expand(size_t count) { + // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity. + size_t newCapacity; + if (stack_ == 0) { + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + newCapacity = initialCapacity_; + } else { + newCapacity = GetCapacity(); + newCapacity += (newCapacity + 1) / 2; + } + size_t newSize = GetSize() + sizeof(T) * count; + if (newCapacity < newSize) + newCapacity = newSize; + + Resize(newCapacity); + } + + void Resize(size_t newCapacity) { + const size_t size = GetSize(); // Backup the current size + stack_ = static_cast(allocator_->Realloc(stack_, GetCapacity(), newCapacity)); + stackTop_ = stack_ + size; + stackEnd_ = stack_ + newCapacity; + } + + void Destroy() { + Allocator::Free(stack_); + RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack + } + + // Prohibit copy constructor & assignment operator. + Stack(const Stack&); + Stack& operator=(const Stack&); + + Allocator* allocator_; + Allocator* ownAllocator_; + char *stack_; + char *stackTop_; + char *stackEnd_; + size_t initialCapacity_; +}; + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_STACK_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/strfunc.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/strfunc.h new file mode 100644 index 0000000..b698a8f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/strfunc.h @@ -0,0 +1,83 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ +#define RAPIDJSON_INTERNAL_STRFUNC_H_ + +#include "../stream.h" +#include + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +//! Custom strlen() which works on different character types. +/*! \tparam Ch Character type (e.g. char, wchar_t, short) + \param s Null-terminated input string. + \return Number of characters in the string. + \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. +*/ +template +inline SizeType StrLen(const Ch* s) { + RAPIDJSON_ASSERT(s != 0); + const Ch* p = s; + while (*p) ++p; + return SizeType(p - s); +} + +template <> +inline SizeType StrLen(const char* s) { + return SizeType(std::strlen(s)); +} + +template <> +inline SizeType StrLen(const wchar_t* s) { + return SizeType(std::wcslen(s)); +} + +//! Custom strcmpn() which works on different character types. +/*! \tparam Ch Character type (e.g. char, wchar_t, short) + \param s1 Null-terminated input string. + \param s2 Null-terminated input string. + \return 0 if equal +*/ +template +inline int StrCmp(const Ch* s1, const Ch* s2) { + RAPIDJSON_ASSERT(s1 != 0); + RAPIDJSON_ASSERT(s2 != 0); + while(*s1 && (*s1 == *s2)) { s1++; s2++; } + return static_cast(*s1) < static_cast(*s2) ? -1 : static_cast(*s1) > static_cast(*s2); +} + +//! Returns number of code points in a encoded string. +template +bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { + RAPIDJSON_ASSERT(s != 0); + RAPIDJSON_ASSERT(outCount != 0); + GenericStringStream is(s); + const typename Encoding::Ch* end = s + length; + SizeType count = 0; + while (is.src_ < end) { + unsigned codepoint; + if (!Encoding::Decode(is, &codepoint)) + return false; + count++; + } + *outCount = count; + return true; +} + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_INTERNAL_STRFUNC_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/strtod.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/strtod.h new file mode 100644 index 0000000..55f0e38 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/strtod.h @@ -0,0 +1,293 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_STRTOD_ +#define RAPIDJSON_STRTOD_ + +#include "ieee754.h" +#include "biginteger.h" +#include "diyfp.h" +#include "pow10.h" +#include +#include + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +inline double FastPath(double significand, int exp) { + if (exp < -308) + return 0.0; + else if (exp >= 0) + return significand * internal::Pow10(exp); + else + return significand / internal::Pow10(-exp); +} + +inline double StrtodNormalPrecision(double d, int p) { + if (p < -308) { + // Prevent expSum < -308, making Pow10(p) = 0 + d = FastPath(d, -308); + d = FastPath(d, p + 308); + } + else + d = FastPath(d, p); + return d; +} + +template +inline T Min3(T a, T b, T c) { + T m = a; + if (m > b) m = b; + if (m > c) m = c; + return m; +} + +inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { + const Double db(b); + const uint64_t bInt = db.IntegerSignificand(); + const int bExp = db.IntegerExponent(); + const int hExp = bExp - 1; + + int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0; + + // Adjust for decimal exponent + if (dExp >= 0) { + dS_Exp2 += dExp; + dS_Exp5 += dExp; + } + else { + bS_Exp2 -= dExp; + bS_Exp5 -= dExp; + hS_Exp2 -= dExp; + hS_Exp5 -= dExp; + } + + // Adjust for binary exponent + if (bExp >= 0) + bS_Exp2 += bExp; + else { + dS_Exp2 -= bExp; + hS_Exp2 -= bExp; + } + + // Adjust for half ulp exponent + if (hExp >= 0) + hS_Exp2 += hExp; + else { + dS_Exp2 -= hExp; + bS_Exp2 -= hExp; + } + + // Remove common power of two factor from all three scaled values + int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2); + dS_Exp2 -= common_Exp2; + bS_Exp2 -= common_Exp2; + hS_Exp2 -= common_Exp2; + + BigInteger dS = d; + dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2); + + BigInteger bS(bInt); + bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2); + + BigInteger hS(1); + hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2); + + BigInteger delta(0); + dS.Difference(bS, &delta); + + return delta.Compare(hS); +} + +inline bool StrtodFast(double d, int p, double* result) { + // Use fast path for string-to-double conversion if possible + // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ + if (p > 22 && p < 22 + 16) { + // Fast Path Cases In Disguise + d *= internal::Pow10(p - 22); + p = 22; + } + + if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1 + *result = FastPath(d, p); + return true; + } + else + return false; +} + +// Compute an approximation and see if it is within 1/2 ULP +template +inline bool StrtodDiyFp(const Ch* decimals, int dLen, int dExp, double* result) { + uint64_t significand = 0; + int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 + for (; i < dLen; i++) { + if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || + (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > Ch('5'))) + break; + significand = significand * 10u + static_cast(decimals[i] - Ch('0')); + } + + if (i < dLen && decimals[i] >= Ch('5')) // Rounding + significand++; + + int remaining = dLen - i; + const int kUlpShift = 3; + const int kUlp = 1 << kUlpShift; + int64_t error = (remaining == 0) ? 0 : kUlp / 2; + + DiyFp v(significand, 0); + v = v.Normalize(); + error <<= -v.e; + + dExp += remaining; + + int actualExp; + DiyFp cachedPower = GetCachedPower10(dExp, &actualExp); + if (actualExp != dExp) { + static const DiyFp kPow10[] = { + DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 0x00000000), -60), // 10^1 + DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 0x00000000), -57), // 10^2 + DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 0x00000000), -54), // 10^3 + DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), -50), // 10^4 + DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 0x00000000), -47), // 10^5 + DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 0x00000000), -44), // 10^6 + DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 0x00000000), -40) // 10^7 + }; + int adjustment = dExp - actualExp; + RAPIDJSON_ASSERT(adjustment >= 1 && adjustment < 8); + v = v * kPow10[adjustment - 1]; + if (dLen + adjustment > 19) // has more digits than decimal digits in 64-bit + error += kUlp / 2; + } + + v = v * cachedPower; + + error += kUlp + (error == 0 ? 0 : 1); + + const int oldExp = v.e; + v = v.Normalize(); + error <<= oldExp - v.e; + + const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e); + int precisionSize = 64 - effectiveSignificandSize; + if (precisionSize + kUlpShift >= 64) { + int scaleExp = (precisionSize + kUlpShift) - 63; + v.f >>= scaleExp; + v.e += scaleExp; + error = (error >> scaleExp) + 1 + kUlp; + precisionSize -= scaleExp; + } + + DiyFp rounded(v.f >> precisionSize, v.e + precisionSize); + const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp; + const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp; + if (precisionBits >= halfWay + static_cast(error)) { + rounded.f++; + if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340) + rounded.f >>= 1; + rounded.e++; + } + } + + *result = rounded.ToDouble(); + + return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); +} + +template +inline double StrtodBigInteger(double approx, const Ch* decimals, int dLen, int dExp) { + RAPIDJSON_ASSERT(dLen >= 0); + const BigInteger dInt(decimals, static_cast(dLen)); + Double a(approx); + int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp); + if (cmp < 0) + return a.Value(); // within half ULP + else if (cmp == 0) { + // Round towards even + if (a.Significand() & 1) + return a.NextPositiveDouble(); + else + return a.Value(); + } + else // adjustment + return a.NextPositiveDouble(); +} + +template +inline double StrtodFullPrecision(double d, int p, const Ch* decimals, size_t length, size_t decimalPosition, int exp) { + RAPIDJSON_ASSERT(d >= 0.0); + RAPIDJSON_ASSERT(length >= 1); + + double result = 0.0; + if (StrtodFast(d, p, &result)) + return result; + + RAPIDJSON_ASSERT(length <= INT_MAX); + int dLen = static_cast(length); + + RAPIDJSON_ASSERT(length >= decimalPosition); + RAPIDJSON_ASSERT(length - decimalPosition <= INT_MAX); + int dExpAdjust = static_cast(length - decimalPosition); + + RAPIDJSON_ASSERT(exp >= INT_MIN + dExpAdjust); + int dExp = exp - dExpAdjust; + + // Make sure length+dExp does not overflow + RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen); + + // Trim leading zeros + while (dLen > 0 && *decimals == '0') { + dLen--; + decimals++; + } + + // Trim trailing zeros + while (dLen > 0 && decimals[dLen - 1] == '0') { + dLen--; + dExp++; + } + + if (dLen == 0) { // Buffer only contains zeros. + return 0.0; + } + + // Trim right-most digits + const int kMaxDecimalDigit = 767 + 1; + if (dLen > kMaxDecimalDigit) { + dExp += dLen - kMaxDecimalDigit; + dLen = kMaxDecimalDigit; + } + + // If too small, underflow to zero. + // Any x <= 10^-324 is interpreted as zero. + if (dLen + dExp <= -324) + return 0.0; + + // If too large, overflow to infinity. + // Any x >= 10^309 is interpreted as +infinity. + if (dLen + dExp > 309) + return std::numeric_limits::infinity(); + + if (StrtodDiyFp(decimals, dLen, dExp, &result)) + return result; + + // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison + return StrtodBigInteger(result, decimals, dLen, dExp); +} + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_STRTOD_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/internal/swap.h b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/swap.h new file mode 100644 index 0000000..2cf92f9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/internal/swap.h @@ -0,0 +1,46 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_INTERNAL_SWAP_H_ +#define RAPIDJSON_INTERNAL_SWAP_H_ + +#include "../rapidjson.h" + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#endif + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +//! Custom swap() to avoid dependency on C++ header +/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. + \note This has the same semantics as std::swap(). +*/ +template +inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { + T tmp = a; + a = b; + b = tmp; +} + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_INTERNAL_SWAP_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/istreamwrapper.h b/components/thorvg-main/src/loaders/lottie/rapidjson/istreamwrapper.h new file mode 100644 index 0000000..01437ec --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/istreamwrapper.h @@ -0,0 +1,128 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_ISTREAMWRAPPER_H_ +#define RAPIDJSON_ISTREAMWRAPPER_H_ + +#include "stream.h" +#include +#include + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. +/*! + The classes can be wrapped including but not limited to: + + - \c std::istringstream + - \c std::stringstream + - \c std::wistringstream + - \c std::wstringstream + - \c std::ifstream + - \c std::fstream + - \c std::wifstream + - \c std::wfstream + + \tparam StreamType Class derived from \c std::basic_istream. +*/ + +template +class BasicIStreamWrapper { +public: + typedef typename StreamType::char_type Ch; + + //! Constructor. + /*! + \param stream stream opened for read. + */ + BasicIStreamWrapper(StreamType &stream) : stream_(stream), buffer_(peekBuffer_), bufferSize_(4), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { + Read(); + } + + //! Constructor. + /*! + \param stream stream opened for read. + \param buffer user-supplied buffer. + \param bufferSize size of buffer in bytes. Must >=4 bytes. + */ + BasicIStreamWrapper(StreamType &stream, char* buffer, size_t bufferSize) : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { + RAPIDJSON_ASSERT(bufferSize >= 4); + Read(); + } + + Ch Peek() const { return *current_; } + Ch Take() { Ch c = *current_; Read(); return c; } + size_t Tell() const { return count_ + static_cast(current_ - buffer_); } + + // Not implemented + void Put(Ch) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + + // For encoding detection only. + const Ch* Peek4() const { + return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; + } + +private: + BasicIStreamWrapper(); + BasicIStreamWrapper(const BasicIStreamWrapper&); + BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); + + void Read() { + if (current_ < bufferLast_) + ++current_; + else if (!eof_) { + count_ += readCount_; + readCount_ = bufferSize_; + bufferLast_ = buffer_ + readCount_ - 1; + current_ = buffer_; + + if (!stream_.read(buffer_, static_cast(bufferSize_))) { + readCount_ = static_cast(stream_.gcount()); + *(bufferLast_ = buffer_ + readCount_) = '\0'; + eof_ = true; + } + } + } + + StreamType &stream_; + Ch peekBuffer_[4], *buffer_; + size_t bufferSize_; + Ch *bufferLast_; + Ch *current_; + size_t readCount_; + size_t count_; //!< Number of characters read + bool eof_; +}; + +typedef BasicIStreamWrapper IStreamWrapper; +typedef BasicIStreamWrapper WIStreamWrapper; + +#if defined(__clang__) || defined(_MSC_VER) +RAPIDJSON_DIAG_POP +#endif + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_ISTREAMWRAPPER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/memorybuffer.h b/components/thorvg-main/src/loaders/lottie/rapidjson/memorybuffer.h new file mode 100644 index 0000000..ffbc41e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/memorybuffer.h @@ -0,0 +1,70 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_MEMORYBUFFER_H_ +#define RAPIDJSON_MEMORYBUFFER_H_ + +#include "stream.h" +#include "internal/stack.h" + +RAPIDJSON_NAMESPACE_BEGIN + +//! Represents an in-memory output byte stream. +/*! + This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. + + It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. + + Differences between MemoryBuffer and StringBuffer: + 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. + 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. + + \tparam Allocator type for allocating memory buffer. + \note implements Stream concept +*/ +template +struct GenericMemoryBuffer { + typedef char Ch; // byte + + GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} + + void Put(Ch c) { *stack_.template Push() = c; } + void Flush() {} + + void Clear() { stack_.Clear(); } + void ShrinkToFit() { stack_.ShrinkToFit(); } + Ch* Push(size_t count) { return stack_.template Push(count); } + void Pop(size_t count) { stack_.template Pop(count); } + + const Ch* GetBuffer() const { + return stack_.template Bottom(); + } + + size_t GetSize() const { return stack_.GetSize(); } + + static const size_t kDefaultCapacity = 256; + mutable internal::Stack stack_; +}; + +typedef GenericMemoryBuffer<> MemoryBuffer; + +//! Implement specialized version of PutN() with memset() for better performance. +template<> +inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { + std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); +} + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_MEMORYBUFFER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/memorystream.h b/components/thorvg-main/src/loaders/lottie/rapidjson/memorystream.h new file mode 100644 index 0000000..77af6c9 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/memorystream.h @@ -0,0 +1,71 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_MEMORYSTREAM_H_ +#define RAPIDJSON_MEMORYSTREAM_H_ + +#include "stream.h" + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(unreachable-code) +RAPIDJSON_DIAG_OFF(missing-noreturn) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Represents an in-memory input byte stream. +/*! + This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. + + It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. + + Differences between MemoryStream and StringStream: + 1. StringStream has encoding but MemoryStream is a byte stream. + 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. + 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). + \note implements Stream concept +*/ +struct MemoryStream { + typedef char Ch; // byte + + MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} + + Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } + Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } + size_t Tell() const { return static_cast(src_ - begin_); } + + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + void Put(Ch) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + + // For encoding detection only. + const Ch* Peek4() const { + return Tell() + 4 <= size_ ? src_ : 0; + } + + const Ch* src_; //!< Current read position. + const Ch* begin_; //!< Original head of the string. + const Ch* end_; //!< End of stream. + size_t size_; //!< Size of the stream. +}; + +RAPIDJSON_NAMESPACE_END + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_MEMORYBUFFER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/msinttypes/inttypes.h b/components/thorvg-main/src/loaders/lottie/rapidjson/msinttypes/inttypes.h new file mode 100644 index 0000000..1811128 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/msinttypes/inttypes.h @@ -0,0 +1,316 @@ +// ISO C9x compliant inttypes.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2013 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the product nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +// The above software in this distribution may have been modified by +// THL A29 Limited ("Tencent Modifications"). +// All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_INTTYPES_H_ // [ +#define _MSC_INTTYPES_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include "stdint.h" + +// miloyip: VC supports inttypes.h since VC2013 +#if _MSC_VER >= 1800 +#include +#else + +// 7.8 Format conversion of integer types + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +// 7.8.1 Macros for format specifiers + +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 + +// The fprintf macros for signed integers are: +#define PRId8 "d" +#define PRIi8 "i" +#define PRIdLEAST8 "d" +#define PRIiLEAST8 "i" +#define PRIdFAST8 "d" +#define PRIiFAST8 "i" + +#define PRId16 "hd" +#define PRIi16 "hi" +#define PRIdLEAST16 "hd" +#define PRIiLEAST16 "hi" +#define PRIdFAST16 "hd" +#define PRIiFAST16 "hi" + +#define PRId32 "I32d" +#define PRIi32 "I32i" +#define PRIdLEAST32 "I32d" +#define PRIiLEAST32 "I32i" +#define PRIdFAST32 "I32d" +#define PRIiFAST32 "I32i" + +#define PRId64 "I64d" +#define PRIi64 "I64i" +#define PRIdLEAST64 "I64d" +#define PRIiLEAST64 "I64i" +#define PRIdFAST64 "I64d" +#define PRIiFAST64 "I64i" + +#define PRIdMAX "I64d" +#define PRIiMAX "I64i" + +#define PRIdPTR "Id" +#define PRIiPTR "Ii" + +// The fprintf macros for unsigned integers are: +#define PRIo8 "o" +#define PRIu8 "u" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIoLEAST8 "o" +#define PRIuLEAST8 "u" +#define PRIxLEAST8 "x" +#define PRIXLEAST8 "X" +#define PRIoFAST8 "o" +#define PRIuFAST8 "u" +#define PRIxFAST8 "x" +#define PRIXFAST8 "X" + +#define PRIo16 "ho" +#define PRIu16 "hu" +#define PRIx16 "hx" +#define PRIX16 "hX" +#define PRIoLEAST16 "ho" +#define PRIuLEAST16 "hu" +#define PRIxLEAST16 "hx" +#define PRIXLEAST16 "hX" +#define PRIoFAST16 "ho" +#define PRIuFAST16 "hu" +#define PRIxFAST16 "hx" +#define PRIXFAST16 "hX" + +#define PRIo32 "I32o" +#define PRIu32 "I32u" +#define PRIx32 "I32x" +#define PRIX32 "I32X" +#define PRIoLEAST32 "I32o" +#define PRIuLEAST32 "I32u" +#define PRIxLEAST32 "I32x" +#define PRIXLEAST32 "I32X" +#define PRIoFAST32 "I32o" +#define PRIuFAST32 "I32u" +#define PRIxFAST32 "I32x" +#define PRIXFAST32 "I32X" + +#define PRIo64 "I64o" +#define PRIu64 "I64u" +#define PRIx64 "I64x" +#define PRIX64 "I64X" +#define PRIoLEAST64 "I64o" +#define PRIuLEAST64 "I64u" +#define PRIxLEAST64 "I64x" +#define PRIXLEAST64 "I64X" +#define PRIoFAST64 "I64o" +#define PRIuFAST64 "I64u" +#define PRIxFAST64 "I64x" +#define PRIXFAST64 "I64X" + +#define PRIoMAX "I64o" +#define PRIuMAX "I64u" +#define PRIxMAX "I64x" +#define PRIXMAX "I64X" + +#define PRIoPTR "Io" +#define PRIuPTR "Iu" +#define PRIxPTR "Ix" +#define PRIXPTR "IX" + +// The fscanf macros for signed integers are: +#define SCNd8 "d" +#define SCNi8 "i" +#define SCNdLEAST8 "d" +#define SCNiLEAST8 "i" +#define SCNdFAST8 "d" +#define SCNiFAST8 "i" + +#define SCNd16 "hd" +#define SCNi16 "hi" +#define SCNdLEAST16 "hd" +#define SCNiLEAST16 "hi" +#define SCNdFAST16 "hd" +#define SCNiFAST16 "hi" + +#define SCNd32 "ld" +#define SCNi32 "li" +#define SCNdLEAST32 "ld" +#define SCNiLEAST32 "li" +#define SCNdFAST32 "ld" +#define SCNiFAST32 "li" + +#define SCNd64 "I64d" +#define SCNi64 "I64i" +#define SCNdLEAST64 "I64d" +#define SCNiLEAST64 "I64i" +#define SCNdFAST64 "I64d" +#define SCNiFAST64 "I64i" + +#define SCNdMAX "I64d" +#define SCNiMAX "I64i" + +#ifdef _WIN64 // [ +# define SCNdPTR "I64d" +# define SCNiPTR "I64i" +#else // _WIN64 ][ +# define SCNdPTR "ld" +# define SCNiPTR "li" +#endif // _WIN64 ] + +// The fscanf macros for unsigned integers are: +#define SCNo8 "o" +#define SCNu8 "u" +#define SCNx8 "x" +#define SCNX8 "X" +#define SCNoLEAST8 "o" +#define SCNuLEAST8 "u" +#define SCNxLEAST8 "x" +#define SCNXLEAST8 "X" +#define SCNoFAST8 "o" +#define SCNuFAST8 "u" +#define SCNxFAST8 "x" +#define SCNXFAST8 "X" + +#define SCNo16 "ho" +#define SCNu16 "hu" +#define SCNx16 "hx" +#define SCNX16 "hX" +#define SCNoLEAST16 "ho" +#define SCNuLEAST16 "hu" +#define SCNxLEAST16 "hx" +#define SCNXLEAST16 "hX" +#define SCNoFAST16 "ho" +#define SCNuFAST16 "hu" +#define SCNxFAST16 "hx" +#define SCNXFAST16 "hX" + +#define SCNo32 "lo" +#define SCNu32 "lu" +#define SCNx32 "lx" +#define SCNX32 "lX" +#define SCNoLEAST32 "lo" +#define SCNuLEAST32 "lu" +#define SCNxLEAST32 "lx" +#define SCNXLEAST32 "lX" +#define SCNoFAST32 "lo" +#define SCNuFAST32 "lu" +#define SCNxFAST32 "lx" +#define SCNXFAST32 "lX" + +#define SCNo64 "I64o" +#define SCNu64 "I64u" +#define SCNx64 "I64x" +#define SCNX64 "I64X" +#define SCNoLEAST64 "I64o" +#define SCNuLEAST64 "I64u" +#define SCNxLEAST64 "I64x" +#define SCNXLEAST64 "I64X" +#define SCNoFAST64 "I64o" +#define SCNuFAST64 "I64u" +#define SCNxFAST64 "I64x" +#define SCNXFAST64 "I64X" + +#define SCNoMAX "I64o" +#define SCNuMAX "I64u" +#define SCNxMAX "I64x" +#define SCNXMAX "I64X" + +#ifdef _WIN64 // [ +# define SCNoPTR "I64o" +# define SCNuPTR "I64u" +# define SCNxPTR "I64x" +# define SCNXPTR "I64X" +#else // _WIN64 ][ +# define SCNoPTR "lo" +# define SCNuPTR "lu" +# define SCNxPTR "lx" +# define SCNXPTR "lX" +#endif // _WIN64 ] + +#endif // __STDC_FORMAT_MACROS ] + +// 7.8.2 Functions for greatest-width integer types + +// 7.8.2.1 The imaxabs function +#define imaxabs _abs64 + +// 7.8.2.2 The imaxdiv function + +// This is modified version of div() function from Microsoft's div.c found +// in %MSVC.NET%\crt\src\div.c +#ifdef STATIC_IMAXDIV // [ +static +#else // STATIC_IMAXDIV ][ +_inline +#endif // STATIC_IMAXDIV ] +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t result; + + result.quot = numer / denom; + result.rem = numer % denom; + + if (numer < 0 && result.rem > 0) { + // did division wrong; must fix up + ++result.quot; + result.rem -= denom; + } + + return result; +} + +// 7.8.2.3 The strtoimax and strtoumax functions +#define strtoimax _strtoi64 +#define strtoumax _strtoui64 + +// 7.8.2.4 The wcstoimax and wcstoumax functions +#define wcstoimax _wcstoi64 +#define wcstoumax _wcstoui64 + +#endif // _MSC_VER >= 1800 + +#endif // _MSC_INTTYPES_H_ ] diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/msinttypes/stdint.h b/components/thorvg-main/src/loaders/lottie/rapidjson/msinttypes/stdint.h new file mode 100644 index 0000000..3d4477b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/msinttypes/stdint.h @@ -0,0 +1,300 @@ +// ISO C9x compliant stdint.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2013 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the product nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +// The above software in this distribution may have been modified by +// THL A29 Limited ("Tencent Modifications"). +// All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_STDINT_H_ // [ +#define _MSC_STDINT_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +// miloyip: Originally Visual Studio 2010 uses its own stdint.h. However it generates warning with INT64_C(), so change to use this file for vs2010. +#if _MSC_VER >= 1600 // [ +#include + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 + +#undef INT8_C +#undef INT16_C +#undef INT32_C +#undef INT64_C +#undef UINT8_C +#undef UINT16_C +#undef UINT32_C +#undef UINT64_C + +// 7.18.4.1 Macros for minimum-width integer constants + +#define INT8_C(val) val##i8 +#define INT16_C(val) val##i16 +#define INT32_C(val) val##i32 +#define INT64_C(val) val##i64 + +#define UINT8_C(val) val##ui8 +#define UINT16_C(val) val##ui16 +#define UINT32_C(val) val##ui32 +#define UINT64_C(val) val##ui64 + +// 7.18.4.2 Macros for greatest-width integer constants +// These #ifndef's are needed to prevent collisions with . +// Check out Issue 9 for the details. +#ifndef INTMAX_C // [ +# define INTMAX_C INT64_C +#endif // INTMAX_C ] +#ifndef UINTMAX_C // [ +# define UINTMAX_C UINT64_C +#endif // UINTMAX_C ] + +#endif // __STDC_CONSTANT_MACROS ] + +#else // ] _MSC_VER >= 1700 [ + +#include + +// For Visual Studio 6 in C++ mode and for many Visual Studio versions when +// compiling for ARM we have to wrap include with 'extern "C++" {}' +// or compiler would give many errors like this: +// error C2733: second C linkage of overloaded function 'wmemchr' not allowed +#if defined(__cplusplus) && !defined(_M_ARM) +extern "C" { +#endif +# include +#if defined(__cplusplus) && !defined(_M_ARM) +} +#endif + +// Define _W64 macros to mark types changing their size, like intptr_t. +#ifndef _W64 +# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 +# define _W64 __w64 +# else +# define _W64 +# endif +#endif + + +// 7.18.1 Integer types + +// 7.18.1.1 Exact-width integer types + +// Visual Studio 6 and Embedded Visual C++ 4 doesn't +// realize that, e.g. char has the same size as __int8 +// so we give up on __intX for them. +#if (_MSC_VER < 1300) + typedef signed char int8_t; + typedef signed short int16_t; + typedef signed int int32_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; +#else + typedef signed __int8 int8_t; + typedef signed __int16 int16_t; + typedef signed __int32 int32_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; +#endif +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; + + +// 7.18.1.2 Minimum-width integer types +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +// 7.18.1.3 Fastest minimum-width integer types +typedef int8_t int_fast8_t; +typedef int16_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef int64_t int_fast64_t; +typedef uint8_t uint_fast8_t; +typedef uint16_t uint_fast16_t; +typedef uint32_t uint_fast32_t; +typedef uint64_t uint_fast64_t; + +// 7.18.1.4 Integer types capable of holding object pointers +#ifdef _WIN64 // [ + typedef signed __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +#else // _WIN64 ][ + typedef _W64 signed int intptr_t; + typedef _W64 unsigned int uintptr_t; +#endif // _WIN64 ] + +// 7.18.1.5 Greatest-width integer types +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; + + +// 7.18.2 Limits of specified-width integer types + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 + +// 7.18.2.1 Limits of exact-width integer types +#define INT8_MIN ((int8_t)_I8_MIN) +#define INT8_MAX _I8_MAX +#define INT16_MIN ((int16_t)_I16_MIN) +#define INT16_MAX _I16_MAX +#define INT32_MIN ((int32_t)_I32_MIN) +#define INT32_MAX _I32_MAX +#define INT64_MIN ((int64_t)_I64_MIN) +#define INT64_MAX _I64_MAX +#define UINT8_MAX _UI8_MAX +#define UINT16_MAX _UI16_MAX +#define UINT32_MAX _UI32_MAX +#define UINT64_MAX _UI64_MAX + +// 7.18.2.2 Limits of minimum-width integer types +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +// 7.18.2.3 Limits of fastest minimum-width integer types +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +// 7.18.2.4 Limits of integer types capable of holding object pointers +#ifdef _WIN64 // [ +# define INTPTR_MIN INT64_MIN +# define INTPTR_MAX INT64_MAX +# define UINTPTR_MAX UINT64_MAX +#else // _WIN64 ][ +# define INTPTR_MIN INT32_MIN +# define INTPTR_MAX INT32_MAX +# define UINTPTR_MAX UINT32_MAX +#endif // _WIN64 ] + +// 7.18.2.5 Limits of greatest-width integer types +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +// 7.18.3 Limits of other integer types + +#ifdef _WIN64 // [ +# define PTRDIFF_MIN _I64_MIN +# define PTRDIFF_MAX _I64_MAX +#else // _WIN64 ][ +# define PTRDIFF_MIN _I32_MIN +# define PTRDIFF_MAX _I32_MAX +#endif // _WIN64 ] + +#define SIG_ATOMIC_MIN INT_MIN +#define SIG_ATOMIC_MAX INT_MAX + +#ifndef SIZE_MAX // [ +# ifdef _WIN64 // [ +# define SIZE_MAX _UI64_MAX +# else // _WIN64 ][ +# define SIZE_MAX _UI32_MAX +# endif // _WIN64 ] +#endif // SIZE_MAX ] + +// WCHAR_MIN and WCHAR_MAX are also defined in +#ifndef WCHAR_MIN // [ +# define WCHAR_MIN 0 +#endif // WCHAR_MIN ] +#ifndef WCHAR_MAX // [ +# define WCHAR_MAX _UI16_MAX +#endif // WCHAR_MAX ] + +#define WINT_MIN 0 +#define WINT_MAX _UI16_MAX + +#endif // __STDC_LIMIT_MACROS ] + + +// 7.18.4 Limits of other integer types + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 + +// 7.18.4.1 Macros for minimum-width integer constants + +#define INT8_C(val) val##i8 +#define INT16_C(val) val##i16 +#define INT32_C(val) val##i32 +#define INT64_C(val) val##i64 + +#define UINT8_C(val) val##ui8 +#define UINT16_C(val) val##ui16 +#define UINT32_C(val) val##ui32 +#define UINT64_C(val) val##ui64 + +// 7.18.4.2 Macros for greatest-width integer constants +// These #ifndef's are needed to prevent collisions with . +// Check out Issue 9 for the details. +#ifndef INTMAX_C // [ +# define INTMAX_C INT64_C +#endif // INTMAX_C ] +#ifndef UINTMAX_C // [ +# define UINTMAX_C UINT64_C +#endif // UINTMAX_C ] + +#endif // __STDC_CONSTANT_MACROS ] + +#endif // _MSC_VER >= 1600 ] + +#endif // _MSC_STDINT_H_ ] diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/ostreamwrapper.h b/components/thorvg-main/src/loaders/lottie/rapidjson/ostreamwrapper.h new file mode 100644 index 0000000..11ed4d3 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/ostreamwrapper.h @@ -0,0 +1,81 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_OSTREAMWRAPPER_H_ +#define RAPIDJSON_OSTREAMWRAPPER_H_ + +#include "stream.h" +#include + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. +/*! + The classes can be wrapped including but not limited to: + + - \c std::ostringstream + - \c std::stringstream + - \c std::wpstringstream + - \c std::wstringstream + - \c std::ifstream + - \c std::fstream + - \c std::wofstream + - \c std::wfstream + + \tparam StreamType Class derived from \c std::basic_ostream. +*/ + +template +class BasicOStreamWrapper { +public: + typedef typename StreamType::char_type Ch; + BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} + + void Put(Ch c) { + stream_.put(c); + } + + void Flush() { + stream_.flush(); + } + + // Not implemented + char Peek() const { RAPIDJSON_ASSERT(false); return 0; } + char Take() { RAPIDJSON_ASSERT(false); return 0; } + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } + char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + BasicOStreamWrapper(const BasicOStreamWrapper&); + BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); + + StreamType& stream_; +}; + +typedef BasicOStreamWrapper OStreamWrapper; +typedef BasicOStreamWrapper WOStreamWrapper; + +#ifdef __clang__ +RAPIDJSON_DIAG_POP +#endif + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_OSTREAMWRAPPER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/pointer.h b/components/thorvg-main/src/loaders/lottie/rapidjson/pointer.h new file mode 100644 index 0000000..15723c6 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/pointer.h @@ -0,0 +1,1470 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_POINTER_H_ +#define RAPIDJSON_POINTER_H_ + +#include "document.h" +#include "uri.h" +#include "internal/itoa.h" +#include "error/error.h" // PointerParseErrorCode + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(switch-enum) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an invalid index in GenericPointer::Token + +/////////////////////////////////////////////////////////////////////////////// +// GenericPointer + +//! Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator. +/*! + This class implements RFC 6901 "JavaScript Object Notation (JSON) Pointer" + (https://tools.ietf.org/html/rfc6901). + + A JSON pointer is for identifying a specific value in a JSON document + (GenericDocument). It can simplify coding of DOM tree manipulation, because it + can access multiple-level depth of DOM tree with single API call. + + After it parses a string representation (e.g. "/foo/0" or URI fragment + representation (e.g. "#/foo/0") into its internal representation (tokens), + it can be used to resolve a specific value in multiple documents, or sub-tree + of documents. + + Contrary to GenericValue, Pointer can be copy constructed and copy assigned. + Apart from assignment, a Pointer cannot be modified after construction. + + Although Pointer is very convenient, please aware that constructing Pointer + involves parsing and dynamic memory allocation. A special constructor with user- + supplied tokens eliminates these. + + GenericPointer depends on GenericDocument and GenericValue. + + \tparam ValueType The value type of the DOM tree. E.g. GenericValue > + \tparam Allocator The allocator type for allocating memory for internal representation. + + \note GenericPointer uses same encoding of ValueType. + However, Allocator of GenericPointer is independent of Allocator of Value. +*/ +template +class GenericPointer { +public: + typedef typename ValueType::EncodingType EncodingType; //!< Encoding type from Value + typedef typename ValueType::Ch Ch; //!< Character type from Value + typedef GenericUri UriType; + + + //! A token is the basic units of internal representation. + /*! + A JSON pointer string representation "/foo/123" is parsed to two tokens: + "foo" and 123. 123 will be represented in both numeric form and string form. + They are resolved according to the actual value type (object or array). + + For token that are not numbers, or the numeric value is out of bound + (greater than limits of SizeType), they are only treated as string form + (i.e. the token's index will be equal to kPointerInvalidIndex). + + This struct is public so that user can create a Pointer without parsing and + allocation, using a special constructor. + */ + struct Token { + const Ch* name; //!< Name of the token. It has null character at the end but it can contain null character. + SizeType length; //!< Length of the name. + SizeType index; //!< A valid array index, if it is not equal to kPointerInvalidIndex. + }; + + //!@name Constructors and destructor. + //@{ + + //! Default constructor. + GenericPointer(Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {} + + //! Constructor that parses a string or URI fragment representation. + /*! + \param source A null-terminated, string or URI fragment representation of JSON pointer. + \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one. + */ + explicit GenericPointer(const Ch* source, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + Parse(source, internal::StrLen(source)); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Constructor that parses a string or URI fragment representation. + /*! + \param source A string or URI fragment representation of JSON pointer. + \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one. + \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING. + */ + explicit GenericPointer(const std::basic_string& source, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + Parse(source.c_str(), source.size()); + } +#endif + + //! Constructor that parses a string or URI fragment representation, with length of the source string. + /*! + \param source A string or URI fragment representation of JSON pointer. + \param length Length of source. + \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one. + \note Slightly faster than the overload without length. + */ + GenericPointer(const Ch* source, size_t length, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + Parse(source, length); + } + + //! Constructor with user-supplied tokens. + /*! + This constructor let user supplies const array of tokens. + This prevents the parsing process and eliminates allocation. + This is preferred for memory constrained environments. + + \param tokens An constant array of tokens representing the JSON pointer. + \param tokenCount Number of tokens. + + \b Example + \code + #define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex } + #define INDEX(i) { #i, sizeof(#i) - 1, i } + + static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(123) }; + static const Pointer p(kTokens, sizeof(kTokens) / sizeof(kTokens[0])); + // Equivalent to static const Pointer p("/foo/123"); + + #undef NAME + #undef INDEX + \endcode + */ + GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {} + + //! Copy constructor. + GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + *this = rhs; + } + + //! Copy constructor. + GenericPointer(const GenericPointer& rhs, Allocator* allocator) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + *this = rhs; + } + + //! Destructor. + ~GenericPointer() { + if (nameBuffer_) // If user-supplied tokens constructor is used, nameBuffer_ is nullptr and tokens_ are not deallocated. + Allocator::Free(tokens_); + RAPIDJSON_DELETE(ownAllocator_); + } + + //! Assignment operator. + GenericPointer& operator=(const GenericPointer& rhs) { + if (this != &rhs) { + // Do not delete ownAllocator + if (nameBuffer_) + Allocator::Free(tokens_); + + tokenCount_ = rhs.tokenCount_; + parseErrorOffset_ = rhs.parseErrorOffset_; + parseErrorCode_ = rhs.parseErrorCode_; + + if (rhs.nameBuffer_) + CopyFromRaw(rhs); // Normally parsed tokens. + else { + tokens_ = rhs.tokens_; // User supplied const tokens. + nameBuffer_ = 0; + } + } + return *this; + } + + //! Swap the content of this pointer with another. + /*! + \param other The pointer to swap with. + \note Constant complexity. + */ + GenericPointer& Swap(GenericPointer& other) RAPIDJSON_NOEXCEPT { + internal::Swap(allocator_, other.allocator_); + internal::Swap(ownAllocator_, other.ownAllocator_); + internal::Swap(nameBuffer_, other.nameBuffer_); + internal::Swap(tokens_, other.tokens_); + internal::Swap(tokenCount_, other.tokenCount_); + internal::Swap(parseErrorOffset_, other.parseErrorOffset_); + internal::Swap(parseErrorCode_, other.parseErrorCode_); + return *this; + } + + //! free-standing swap function helper + /*! + Helper function to enable support for common swap implementation pattern based on \c std::swap: + \code + void swap(MyClass& a, MyClass& b) { + using std::swap; + swap(a.pointer, b.pointer); + // ... + } + \endcode + \see Swap() + */ + friend inline void swap(GenericPointer& a, GenericPointer& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } + + //@} + + //!@name Append token + //@{ + + //! Append a token and return a new Pointer + /*! + \param token Token to be appended. + \param allocator Allocator for the newly return Pointer. + \return A new Pointer with appended token. + */ + GenericPointer Append(const Token& token, Allocator* allocator = 0) const { + GenericPointer r; + r.allocator_ = allocator; + Ch *p = r.CopyFromRaw(*this, 1, token.length + 1); + std::memcpy(p, token.name, (token.length + 1) * sizeof(Ch)); + r.tokens_[tokenCount_].name = p; + r.tokens_[tokenCount_].length = token.length; + r.tokens_[tokenCount_].index = token.index; + return r; + } + + //! Append a name token with length, and return a new Pointer + /*! + \param name Name to be appended. + \param length Length of name. + \param allocator Allocator for the newly return Pointer. + \return A new Pointer with appended token. + */ + GenericPointer Append(const Ch* name, SizeType length, Allocator* allocator = 0) const { + Token token = { name, length, kPointerInvalidIndex }; + return Append(token, allocator); + } + + //! Append a name token without length, and return a new Pointer + /*! + \param name Name (const Ch*) to be appended. + \param allocator Allocator for the newly return Pointer. + \return A new Pointer with appended token. + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr::Type, Ch> >), (GenericPointer)) + Append(T* name, Allocator* allocator = 0) const { + return Append(name, internal::StrLen(name), allocator); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Append a name token, and return a new Pointer + /*! + \param name Name to be appended. + \param allocator Allocator for the newly return Pointer. + \return A new Pointer with appended token. + */ + GenericPointer Append(const std::basic_string& name, Allocator* allocator = 0) const { + return Append(name.c_str(), static_cast(name.size()), allocator); + } +#endif + + //! Append a index token, and return a new Pointer + /*! + \param index Index to be appended. + \param allocator Allocator for the newly return Pointer. + \return A new Pointer with appended token. + */ + GenericPointer Append(SizeType index, Allocator* allocator = 0) const { + char buffer[21]; + char* end = sizeof(SizeType) == 4 ? internal::u32toa(index, buffer) : internal::u64toa(index, buffer); + SizeType length = static_cast(end - buffer); + buffer[length] = '\0'; + + if (sizeof(Ch) == 1) { + Token token = { reinterpret_cast(buffer), length, index }; + return Append(token, allocator); + } + else { + Ch name[21]; + for (size_t i = 0; i <= length; i++) + name[i] = static_cast(buffer[i]); + Token token = { name, length, index }; + return Append(token, allocator); + } + } + + //! Append a token by value, and return a new Pointer + /*! + \param token token to be appended. + \param allocator Allocator for the newly return Pointer. + \return A new Pointer with appended token. + */ + GenericPointer Append(const ValueType& token, Allocator* allocator = 0) const { + if (token.IsString()) + return Append(token.GetString(), token.GetStringLength(), allocator); + else { + RAPIDJSON_ASSERT(token.IsUint64()); + RAPIDJSON_ASSERT(token.GetUint64() <= SizeType(~0)); + return Append(static_cast(token.GetUint64()), allocator); + } + } + + //!@name Handling Parse Error + //@{ + + //! Check whether this is a valid pointer. + bool IsValid() const { return parseErrorCode_ == kPointerParseErrorNone; } + + //! Get the parsing error offset in code unit. + size_t GetParseErrorOffset() const { return parseErrorOffset_; } + + //! Get the parsing error code. + PointerParseErrorCode GetParseErrorCode() const { return parseErrorCode_; } + + //@} + + //! Get the allocator of this pointer. + Allocator& GetAllocator() { return *allocator_; } + + //!@name Tokens + //@{ + + //! Get the token array (const version only). + const Token* GetTokens() const { return tokens_; } + + //! Get the number of tokens. + size_t GetTokenCount() const { return tokenCount_; } + + //@} + + //!@name Equality/inequality operators + //@{ + + //! Equality operator. + /*! + \note When any pointers are invalid, always returns false. + */ + bool operator==(const GenericPointer& rhs) const { + if (!IsValid() || !rhs.IsValid() || tokenCount_ != rhs.tokenCount_) + return false; + + for (size_t i = 0; i < tokenCount_; i++) { + if (tokens_[i].index != rhs.tokens_[i].index || + tokens_[i].length != rhs.tokens_[i].length || + (tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch)* tokens_[i].length) != 0)) + { + return false; + } + } + + return true; + } + + //! Inequality operator. + /*! + \note When any pointers are invalid, always returns true. + */ + bool operator!=(const GenericPointer& rhs) const { return !(*this == rhs); } + + //! Less than operator. + /*! + \note Invalid pointers are always greater than valid ones. + */ + bool operator<(const GenericPointer& rhs) const { + if (!IsValid()) + return false; + if (!rhs.IsValid()) + return true; + + if (tokenCount_ != rhs.tokenCount_) + return tokenCount_ < rhs.tokenCount_; + + for (size_t i = 0; i < tokenCount_; i++) { + if (tokens_[i].index != rhs.tokens_[i].index) + return tokens_[i].index < rhs.tokens_[i].index; + + if (tokens_[i].length != rhs.tokens_[i].length) + return tokens_[i].length < rhs.tokens_[i].length; + + if (int cmp = std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch) * tokens_[i].length)) + return cmp < 0; + } + + return false; + } + + //@} + + //!@name Stringify + //@{ + + //! Stringify the pointer into string representation. + /*! + \tparam OutputStream Type of output stream. + \param os The output stream. + */ + template + bool Stringify(OutputStream& os) const { + return Stringify(os); + } + + //! Stringify the pointer into URI fragment representation. + /*! + \tparam OutputStream Type of output stream. + \param os The output stream. + */ + template + bool StringifyUriFragment(OutputStream& os) const { + return Stringify(os); + } + + //@} + + //!@name Create value + //@{ + + //! Create a value in a subtree. + /*! + If the value is not exist, it creates all parent values and a JSON Null value. + So it always succeed and return the newly created or existing value. + + Remind that it may change types of parents according to tokens, so it + potentially removes previously stored values. For example, if a document + was an array, and "/foo" is used to create a value, then the document + will be changed to an object, and all existing array elements are lost. + + \param root Root value of a DOM subtree to be resolved. It can be any value other than document root. + \param allocator Allocator for creating the values if the specified value or its parents are not exist. + \param alreadyExist If non-null, it stores whether the resolved value is already exist. + \return The resolved newly created (a JSON Null value), or already exists value. + */ + ValueType& Create(ValueType& root, typename ValueType::AllocatorType& allocator, bool* alreadyExist = 0) const { + RAPIDJSON_ASSERT(IsValid()); + ValueType* v = &root; + bool exist = true; + for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + if (v->IsArray() && t->name[0] == '-' && t->length == 1) { + v->PushBack(ValueType().Move(), allocator); + v = &((*v)[v->Size() - 1]); + exist = false; + } + else { + if (t->index == kPointerInvalidIndex) { // must be object name + if (!v->IsObject()) + v->SetObject(); // Change to Object + } + else { // object name or array index + if (!v->IsArray() && !v->IsObject()) + v->SetArray(); // Change to Array + } + + if (v->IsArray()) { + if (t->index >= v->Size()) { + v->Reserve(t->index + 1, allocator); + while (t->index >= v->Size()) + v->PushBack(ValueType().Move(), allocator); + exist = false; + } + v = &((*v)[t->index]); + } + else { + typename ValueType::MemberIterator m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); + if (m == v->MemberEnd()) { + v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator); + m = v->MemberEnd(); + v = &(--m)->value; // Assumes AddMember() appends at the end + exist = false; + } + else + v = &m->value; + } + } + } + + if (alreadyExist) + *alreadyExist = exist; + + return *v; + } + + //! Creates a value in a document. + /*! + \param document A document to be resolved. + \param alreadyExist If non-null, it stores whether the resolved value is already exist. + \return The resolved newly created, or already exists value. + */ + template + ValueType& Create(GenericDocument& document, bool* alreadyExist = 0) const { + return Create(document, document.GetAllocator(), alreadyExist); + } + + //@} + + //!@name Compute URI + //@{ + + //! Compute the in-scope URI for a subtree. + // For use with JSON pointers into JSON schema documents. + /*! + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param rootUri Root URI + \param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token. + \param allocator Allocator for Uris + \return Uri if it can be resolved. Otherwise null. + + \note + There are only 3 situations when a URI cannot be resolved: + 1. A value in the path is neither an array nor object. + 2. An object value does not contain the token. + 3. A token is out of range of an array value. + + Use unresolvedTokenIndex to retrieve the token index. + */ + UriType GetUri(ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const { + static const Ch kIdString[] = { 'i', 'd', '\0' }; + static const ValueType kIdValue(kIdString, 2); + UriType base = UriType(rootUri, allocator); + RAPIDJSON_ASSERT(IsValid()); + ValueType* v = &root; + for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + switch (v->GetType()) { + case kObjectType: + { + // See if we have an id, and if so resolve with the current base + typename ValueType::MemberIterator m = v->FindMember(kIdValue); + if (m != v->MemberEnd() && (m->value).IsString()) { + UriType here = UriType(m->value, allocator).Resolve(base, allocator); + base = here; + } + m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); + if (m == v->MemberEnd()) + break; + v = &m->value; + } + continue; + case kArrayType: + if (t->index == kPointerInvalidIndex || t->index >= v->Size()) + break; + v = &((*v)[t->index]); + continue; + default: + break; + } + + // Error: unresolved token + if (unresolvedTokenIndex) + *unresolvedTokenIndex = static_cast(t - tokens_); + return UriType(allocator); + } + return base; + } + + UriType GetUri(const ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const { + return GetUri(const_cast(root), rootUri, unresolvedTokenIndex, allocator); + } + + + //!@name Query value + //@{ + + //! Query a value in a subtree. + /*! + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token. + \return Pointer to the value if it can be resolved. Otherwise null. + + \note + There are only 3 situations when a value cannot be resolved: + 1. A value in the path is neither an array nor object. + 2. An object value does not contain the token. + 3. A token is out of range of an array value. + + Use unresolvedTokenIndex to retrieve the token index. + */ + ValueType* Get(ValueType& root, size_t* unresolvedTokenIndex = 0) const { + RAPIDJSON_ASSERT(IsValid()); + ValueType* v = &root; + for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + switch (v->GetType()) { + case kObjectType: + { + typename ValueType::MemberIterator m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); + if (m == v->MemberEnd()) + break; + v = &m->value; + } + continue; + case kArrayType: + if (t->index == kPointerInvalidIndex || t->index >= v->Size()) + break; + v = &((*v)[t->index]); + continue; + default: + break; + } + + // Error: unresolved token + if (unresolvedTokenIndex) + *unresolvedTokenIndex = static_cast(t - tokens_); + return 0; + } + return v; + } + + //! Query a const value in a const subtree. + /*! + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \return Pointer to the value if it can be resolved. Otherwise null. + */ + const ValueType* Get(const ValueType& root, size_t* unresolvedTokenIndex = 0) const { + return Get(const_cast(root), unresolvedTokenIndex); + } + + //@} + + //!@name Query a value with default + //@{ + + //! Query a value in a subtree with default value. + /*! + Similar to Get(), but if the specified value do not exists, it creates all parents and clone the default value. + So that this function always succeed. + + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param defaultValue Default value to be cloned if the value was not exists. + \param allocator Allocator for creating the values if the specified value or its parents are not exist. + \see Create() + */ + ValueType& GetWithDefault(ValueType& root, const ValueType& defaultValue, typename ValueType::AllocatorType& allocator) const { + bool alreadyExist; + ValueType& v = Create(root, allocator, &alreadyExist); + return alreadyExist ? v : v.CopyFrom(defaultValue, allocator); + } + + //! Query a value in a subtree with default null-terminated string. + ValueType& GetWithDefault(ValueType& root, const Ch* defaultValue, typename ValueType::AllocatorType& allocator) const { + bool alreadyExist; + ValueType& v = Create(root, allocator, &alreadyExist); + return alreadyExist ? v : v.SetString(defaultValue, allocator); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Query a value in a subtree with default std::basic_string. + ValueType& GetWithDefault(ValueType& root, const std::basic_string& defaultValue, typename ValueType::AllocatorType& allocator) const { + bool alreadyExist; + ValueType& v = Create(root, allocator, &alreadyExist); + return alreadyExist ? v : v.SetString(defaultValue, allocator); + } +#endif + + //! Query a value in a subtree with default primitive value. + /*! + \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (ValueType&)) + GetWithDefault(ValueType& root, T defaultValue, typename ValueType::AllocatorType& allocator) const { + return GetWithDefault(root, ValueType(defaultValue).Move(), allocator); + } + + //! Query a value in a document with default value. + template + ValueType& GetWithDefault(GenericDocument& document, const ValueType& defaultValue) const { + return GetWithDefault(document, defaultValue, document.GetAllocator()); + } + + //! Query a value in a document with default null-terminated string. + template + ValueType& GetWithDefault(GenericDocument& document, const Ch* defaultValue) const { + return GetWithDefault(document, defaultValue, document.GetAllocator()); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Query a value in a document with default std::basic_string. + template + ValueType& GetWithDefault(GenericDocument& document, const std::basic_string& defaultValue) const { + return GetWithDefault(document, defaultValue, document.GetAllocator()); + } +#endif + + //! Query a value in a document with default primitive value. + /*! + \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (ValueType&)) + GetWithDefault(GenericDocument& document, T defaultValue) const { + return GetWithDefault(document, defaultValue, document.GetAllocator()); + } + + //@} + + //!@name Set a value + //@{ + + //! Set a value in a subtree, with move semantics. + /*! + It creates all parents if they are not exist or types are different to the tokens. + So this function always succeeds but potentially remove existing values. + + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param value Value to be set. + \param allocator Allocator for creating the values if the specified value or its parents are not exist. + \see Create() + */ + ValueType& Set(ValueType& root, ValueType& value, typename ValueType::AllocatorType& allocator) const { + return Create(root, allocator) = value; + } + + //! Set a value in a subtree, with copy semantics. + ValueType& Set(ValueType& root, const ValueType& value, typename ValueType::AllocatorType& allocator) const { + return Create(root, allocator).CopyFrom(value, allocator); + } + + //! Set a null-terminated string in a subtree. + ValueType& Set(ValueType& root, const Ch* value, typename ValueType::AllocatorType& allocator) const { + return Create(root, allocator) = ValueType(value, allocator).Move(); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Set a std::basic_string in a subtree. + ValueType& Set(ValueType& root, const std::basic_string& value, typename ValueType::AllocatorType& allocator) const { + return Create(root, allocator) = ValueType(value, allocator).Move(); + } +#endif + + //! Set a primitive value in a subtree. + /*! + \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (ValueType&)) + Set(ValueType& root, T value, typename ValueType::AllocatorType& allocator) const { + return Create(root, allocator) = ValueType(value).Move(); + } + + //! Set a value in a document, with move semantics. + template + ValueType& Set(GenericDocument& document, ValueType& value) const { + return Create(document) = value; + } + + //! Set a value in a document, with copy semantics. + template + ValueType& Set(GenericDocument& document, const ValueType& value) const { + return Create(document).CopyFrom(value, document.GetAllocator()); + } + + //! Set a null-terminated string in a document. + template + ValueType& Set(GenericDocument& document, const Ch* value) const { + return Create(document) = ValueType(value, document.GetAllocator()).Move(); + } + +#if RAPIDJSON_HAS_STDSTRING + //! Sets a std::basic_string in a document. + template + ValueType& Set(GenericDocument& document, const std::basic_string& value) const { + return Create(document) = ValueType(value, document.GetAllocator()).Move(); + } +#endif + + //! Set a primitive value in a document. + /*! + \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool + */ + template + RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (ValueType&)) + Set(GenericDocument& document, T value) const { + return Create(document) = value; + } + + //@} + + //!@name Swap a value + //@{ + + //! Swap a value with a value in a subtree. + /*! + It creates all parents if they are not exist or types are different to the tokens. + So this function always succeeds but potentially remove existing values. + + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \param value Value to be swapped. + \param allocator Allocator for creating the values if the specified value or its parents are not exist. + \see Create() + */ + ValueType& Swap(ValueType& root, ValueType& value, typename ValueType::AllocatorType& allocator) const { + return Create(root, allocator).Swap(value); + } + + //! Swap a value with a value in a document. + template + ValueType& Swap(GenericDocument& document, ValueType& value) const { + return Create(document).Swap(value); + } + + //@} + + //! Erase a value in a subtree. + /*! + \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. + \return Whether the resolved value is found and erased. + + \note Erasing with an empty pointer \c Pointer(""), i.e. the root, always fail and return false. + */ + bool Erase(ValueType& root) const { + RAPIDJSON_ASSERT(IsValid()); + if (tokenCount_ == 0) // Cannot erase the root + return false; + + ValueType* v = &root; + const Token* last = tokens_ + (tokenCount_ - 1); + for (const Token *t = tokens_; t != last; ++t) { + switch (v->GetType()) { + case kObjectType: + { + typename ValueType::MemberIterator m = v->FindMember(GenericValue(GenericStringRef(t->name, t->length))); + if (m == v->MemberEnd()) + return false; + v = &m->value; + } + break; + case kArrayType: + if (t->index == kPointerInvalidIndex || t->index >= v->Size()) + return false; + v = &((*v)[t->index]); + break; + default: + return false; + } + } + + switch (v->GetType()) { + case kObjectType: + return v->EraseMember(GenericStringRef(last->name, last->length)); + case kArrayType: + if (last->index == kPointerInvalidIndex || last->index >= v->Size()) + return false; + v->Erase(v->Begin() + last->index); + return true; + default: + return false; + } + } + +private: + //! Clone the content from rhs to this. + /*! + \param rhs Source pointer. + \param extraToken Extra tokens to be allocated. + \param extraNameBufferSize Extra name buffer size (in number of Ch) to be allocated. + \return Start of non-occupied name buffer, for storing extra names. + */ + Ch* CopyFromRaw(const GenericPointer& rhs, size_t extraToken = 0, size_t extraNameBufferSize = 0) { + if (!allocator_) // allocator is independently owned. + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + + size_t nameBufferSize = rhs.tokenCount_; // null terminators for tokens + for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t) + nameBufferSize += t->length; + + tokenCount_ = rhs.tokenCount_ + extraToken; + tokens_ = static_cast(allocator_->Malloc(tokenCount_ * sizeof(Token) + (nameBufferSize + extraNameBufferSize) * sizeof(Ch))); + nameBuffer_ = reinterpret_cast(tokens_ + tokenCount_); + if (rhs.tokenCount_ > 0) { + std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ * sizeof(Token)); + } + if (nameBufferSize > 0) { + std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize * sizeof(Ch)); + } + + // Adjust pointers to name buffer + std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_; + for (Token *t = tokens_; t != tokens_ + rhs.tokenCount_; ++t) + t->name += diff; + + return nameBuffer_ + nameBufferSize; + } + + //! Check whether a character should be percent-encoded. + /*! + According to RFC 3986 2.3 Unreserved Characters. + \param c The character (code unit) to be tested. + */ + bool NeedPercentEncode(Ch c) const { + return !((c >= '0' && c <= '9') || (c >= 'A' && c <='Z') || (c >= 'a' && c <= 'z') || c == '-' || c == '.' || c == '_' || c =='~'); + } + + //! Parse a JSON String or its URI fragment representation into tokens. +#ifndef __clang__ // -Wdocumentation + /*! + \param source Either a JSON Pointer string, or its URI fragment representation. Not need to be null terminated. + \param length Length of the source string. + \note Source cannot be JSON String Representation of JSON Pointer, e.g. In "/\u0000", \u0000 will not be unescaped. + */ +#endif + void Parse(const Ch* source, size_t length) { + RAPIDJSON_ASSERT(source != NULL); + RAPIDJSON_ASSERT(nameBuffer_ == 0); + RAPIDJSON_ASSERT(tokens_ == 0); + + // Create own allocator if user did not supply. + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + + // Count number of '/' as tokenCount + tokenCount_ = 0; + for (const Ch* s = source; s != source + length; s++) + if (*s == '/') + tokenCount_++; + + Token* token = tokens_ = static_cast(allocator_->Malloc(tokenCount_ * sizeof(Token) + length * sizeof(Ch))); + Ch* name = nameBuffer_ = reinterpret_cast(tokens_ + tokenCount_); + size_t i = 0; + + // Detect if it is a URI fragment + bool uriFragment = false; + if (source[i] == '#') { + uriFragment = true; + i++; + } + + if (i != length && source[i] != '/') { + parseErrorCode_ = kPointerParseErrorTokenMustBeginWithSolidus; + goto error; + } + + while (i < length) { + RAPIDJSON_ASSERT(source[i] == '/'); + i++; // consumes '/' + + token->name = name; + bool isNumber = true; + + while (i < length && source[i] != '/') { + Ch c = source[i]; + if (uriFragment) { + // Decoding percent-encoding for URI fragment + if (c == '%') { + PercentDecodeStream is(&source[i], source + length); + GenericInsituStringStream os(name); + Ch* begin = os.PutBegin(); + if (!Transcoder, EncodingType>().Validate(is, os) || !is.IsValid()) { + parseErrorCode_ = kPointerParseErrorInvalidPercentEncoding; + goto error; + } + size_t len = os.PutEnd(begin); + i += is.Tell() - 1; + if (len == 1) + c = *name; + else { + name += len; + isNumber = false; + i++; + continue; + } + } + else if (NeedPercentEncode(c)) { + parseErrorCode_ = kPointerParseErrorCharacterMustPercentEncode; + goto error; + } + } + + i++; + + // Escaping "~0" -> '~', "~1" -> '/' + if (c == '~') { + if (i < length) { + c = source[i]; + if (c == '0') c = '~'; + else if (c == '1') c = '/'; + else { + parseErrorCode_ = kPointerParseErrorInvalidEscape; + goto error; + } + i++; + } + else { + parseErrorCode_ = kPointerParseErrorInvalidEscape; + goto error; + } + } + + // First check for index: all of characters are digit + if (c < '0' || c > '9') + isNumber = false; + + *name++ = c; + } + token->length = static_cast(name - token->name); + if (token->length == 0) + isNumber = false; + *name++ = '\0'; // Null terminator + + // Second check for index: more than one digit cannot have leading zero + if (isNumber && token->length > 1 && token->name[0] == '0') + isNumber = false; + + // String to SizeType conversion + SizeType n = 0; + if (isNumber) { + for (size_t j = 0; j < token->length; j++) { + SizeType m = n * 10 + static_cast(token->name[j] - '0'); + if (m < n) { // overflow detection + isNumber = false; + break; + } + n = m; + } + } + + token->index = isNumber ? n : kPointerInvalidIndex; + token++; + } + + RAPIDJSON_ASSERT(name <= nameBuffer_ + length); // Should not overflow buffer + parseErrorCode_ = kPointerParseErrorNone; + return; + + error: + Allocator::Free(tokens_); + nameBuffer_ = 0; + tokens_ = 0; + tokenCount_ = 0; + parseErrorOffset_ = i; + return; + } + + //! Stringify to string or URI fragment representation. + /*! + \tparam uriFragment True for stringifying to URI fragment representation. False for string representation. + \tparam OutputStream type of output stream. + \param os The output stream. + */ + template + bool Stringify(OutputStream& os) const { + RAPIDJSON_ASSERT(IsValid()); + + if (uriFragment) + os.Put('#'); + + for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + os.Put('/'); + for (size_t j = 0; j < t->length; j++) { + Ch c = t->name[j]; + if (c == '~') { + os.Put('~'); + os.Put('0'); + } + else if (c == '/') { + os.Put('~'); + os.Put('1'); + } + else if (uriFragment && NeedPercentEncode(c)) { + // Transcode to UTF8 sequence + GenericStringStream source(&t->name[j]); + PercentEncodeStream target(os); + if (!Transcoder >().Validate(source, target)) + return false; + j += source.Tell() - 1; + } + else + os.Put(c); + } + } + return true; + } + + //! A helper stream for decoding a percent-encoded sequence into code unit. + /*! + This stream decodes %XY triplet into code unit (0-255). + If it encounters invalid characters, it sets output code unit as 0 and + mark invalid, and to be checked by IsValid(). + */ + class PercentDecodeStream { + public: + typedef typename ValueType::Ch Ch; + + //! Constructor + /*! + \param source Start of the stream + \param end Past-the-end of the stream. + */ + PercentDecodeStream(const Ch* source, const Ch* end) : src_(source), head_(source), end_(end), valid_(true) {} + + Ch Take() { + if (*src_ != '%' || src_ + 3 > end_) { // %XY triplet + valid_ = false; + return 0; + } + src_++; + Ch c = 0; + for (int j = 0; j < 2; j++) { + c = static_cast(c << 4); + Ch h = *src_; + if (h >= '0' && h <= '9') c = static_cast(c + h - '0'); + else if (h >= 'A' && h <= 'F') c = static_cast(c + h - 'A' + 10); + else if (h >= 'a' && h <= 'f') c = static_cast(c + h - 'a' + 10); + else { + valid_ = false; + return 0; + } + src_++; + } + return c; + } + + size_t Tell() const { return static_cast(src_ - head_); } + bool IsValid() const { return valid_; } + + private: + const Ch* src_; //!< Current read position. + const Ch* head_; //!< Original head of the string. + const Ch* end_; //!< Past-the-end position. + bool valid_; //!< Whether the parsing is valid. + }; + + //! A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence. + template + class PercentEncodeStream { + public: + PercentEncodeStream(OutputStream& os) : os_(os) {} + void Put(char c) { // UTF-8 must be byte + unsigned char u = static_cast(c); + static const char hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + os_.Put('%'); + os_.Put(static_cast(hexDigits[u >> 4])); + os_.Put(static_cast(hexDigits[u & 15])); + } + private: + OutputStream& os_; + }; + + Allocator* allocator_; //!< The current allocator. It is either user-supplied or equal to ownAllocator_. + Allocator* ownAllocator_; //!< Allocator owned by this Pointer. + Ch* nameBuffer_; //!< A buffer containing all names in tokens. + Token* tokens_; //!< A list of tokens. + size_t tokenCount_; //!< Number of tokens in tokens_. + size_t parseErrorOffset_; //!< Offset in code unit when parsing fail. + PointerParseErrorCode parseErrorCode_; //!< Parsing error code. +}; + +//! GenericPointer for Value (UTF-8, default allocator). +typedef GenericPointer Pointer; + +//!@name Helper functions for GenericPointer +//@{ + +////////////////////////////////////////////////////////////////////////////// + +template +typename T::ValueType& CreateValueByPointer(T& root, const GenericPointer& pointer, typename T::AllocatorType& a) { + return pointer.Create(root, a); +} + +template +typename T::ValueType& CreateValueByPointer(T& root, const CharType(&source)[N], typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Create(root, a); +} + +// No allocator parameter + +template +typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, const GenericPointer& pointer) { + return pointer.Create(document); +} + +template +typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, const CharType(&source)[N]) { + return GenericPointer(source, N - 1).Create(document); +} + +////////////////////////////////////////////////////////////////////////////// + +template +typename T::ValueType* GetValueByPointer(T& root, const GenericPointer& pointer, size_t* unresolvedTokenIndex = 0) { + return pointer.Get(root, unresolvedTokenIndex); +} + +template +const typename T::ValueType* GetValueByPointer(const T& root, const GenericPointer& pointer, size_t* unresolvedTokenIndex = 0) { + return pointer.Get(root, unresolvedTokenIndex); +} + +template +typename T::ValueType* GetValueByPointer(T& root, const CharType (&source)[N], size_t* unresolvedTokenIndex = 0) { + return GenericPointer(source, N - 1).Get(root, unresolvedTokenIndex); +} + +template +const typename T::ValueType* GetValueByPointer(const T& root, const CharType(&source)[N], size_t* unresolvedTokenIndex = 0) { + return GenericPointer(source, N - 1).Get(root, unresolvedTokenIndex); +} + +////////////////////////////////////////////////////////////////////////////// + +template +typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointer& pointer, const typename T::ValueType& defaultValue, typename T::AllocatorType& a) { + return pointer.GetWithDefault(root, defaultValue, a); +} + +template +typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointer& pointer, const typename T::Ch* defaultValue, typename T::AllocatorType& a) { + return pointer.GetWithDefault(root, defaultValue, a); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointer& pointer, const std::basic_string& defaultValue, typename T::AllocatorType& a) { + return pointer.GetWithDefault(root, defaultValue, a); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename T::ValueType&)) +GetValueByPointerWithDefault(T& root, const GenericPointer& pointer, T2 defaultValue, typename T::AllocatorType& a) { + return pointer.GetWithDefault(root, defaultValue, a); +} + +template +typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const typename T::ValueType& defaultValue, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).GetWithDefault(root, defaultValue, a); +} + +template +typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const typename T::Ch* defaultValue, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).GetWithDefault(root, defaultValue, a); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const std::basic_string& defaultValue, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).GetWithDefault(root, defaultValue, a); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename T::ValueType&)) +GetValueByPointerWithDefault(T& root, const CharType(&source)[N], T2 defaultValue, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).GetWithDefault(root, defaultValue, a); +} + +// No allocator parameter + +template +typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const GenericPointer& pointer, const typename DocumentType::ValueType& defaultValue) { + return pointer.GetWithDefault(document, defaultValue); +} + +template +typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const GenericPointer& pointer, const typename DocumentType::Ch* defaultValue) { + return pointer.GetWithDefault(document, defaultValue); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const GenericPointer& pointer, const std::basic_string& defaultValue) { + return pointer.GetWithDefault(document, defaultValue); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename DocumentType::ValueType&)) +GetValueByPointerWithDefault(DocumentType& document, const GenericPointer& pointer, T2 defaultValue) { + return pointer.GetWithDefault(document, defaultValue); +} + +template +typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const typename DocumentType::ValueType& defaultValue) { + return GenericPointer(source, N - 1).GetWithDefault(document, defaultValue); +} + +template +typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const typename DocumentType::Ch* defaultValue) { + return GenericPointer(source, N - 1).GetWithDefault(document, defaultValue); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const std::basic_string& defaultValue) { + return GenericPointer(source, N - 1).GetWithDefault(document, defaultValue); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename DocumentType::ValueType&)) +GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], T2 defaultValue) { + return GenericPointer(source, N - 1).GetWithDefault(document, defaultValue); +} + +////////////////////////////////////////////////////////////////////////////// + +template +typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, typename T::ValueType& value, typename T::AllocatorType& a) { + return pointer.Set(root, value, a); +} + +template +typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const typename T::ValueType& value, typename T::AllocatorType& a) { + return pointer.Set(root, value, a); +} + +template +typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const typename T::Ch* value, typename T::AllocatorType& a) { + return pointer.Set(root, value, a); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const std::basic_string& value, typename T::AllocatorType& a) { + return pointer.Set(root, value, a); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename T::ValueType&)) +SetValueByPointer(T& root, const GenericPointer& pointer, T2 value, typename T::AllocatorType& a) { + return pointer.Set(root, value, a); +} + +template +typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Set(root, value, a); +} + +template +typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Set(root, value, a); +} + +template +typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Set(root, value, a); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const std::basic_string& value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Set(root, value, a); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename T::ValueType&)) +SetValueByPointer(T& root, const CharType(&source)[N], T2 value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Set(root, value, a); +} + +// No allocator parameter + +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer& pointer, typename DocumentType::ValueType& value) { + return pointer.Set(document, value); +} + +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer& pointer, const typename DocumentType::ValueType& value) { + return pointer.Set(document, value); +} + +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer& pointer, const typename DocumentType::Ch* value) { + return pointer.Set(document, value); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer& pointer, const std::basic_string& value) { + return pointer.Set(document, value); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename DocumentType::ValueType&)) +SetValueByPointer(DocumentType& document, const GenericPointer& pointer, T2 value) { + return pointer.Set(document, value); +} + +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], typename DocumentType::ValueType& value) { + return GenericPointer(source, N - 1).Set(document, value); +} + +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const typename DocumentType::ValueType& value) { + return GenericPointer(source, N - 1).Set(document, value); +} + +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const typename DocumentType::Ch* value) { + return GenericPointer(source, N - 1).Set(document, value); +} + +#if RAPIDJSON_HAS_STDSTRING +template +typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const std::basic_string& value) { + return GenericPointer(source, N - 1).Set(document, value); +} +#endif + +template +RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr, internal::IsGenericValue >), (typename DocumentType::ValueType&)) +SetValueByPointer(DocumentType& document, const CharType(&source)[N], T2 value) { + return GenericPointer(source, N - 1).Set(document, value); +} + +////////////////////////////////////////////////////////////////////////////// + +template +typename T::ValueType& SwapValueByPointer(T& root, const GenericPointer& pointer, typename T::ValueType& value, typename T::AllocatorType& a) { + return pointer.Swap(root, value, a); +} + +template +typename T::ValueType& SwapValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Swap(root, value, a); +} + +template +typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, const GenericPointer& pointer, typename DocumentType::ValueType& value) { + return pointer.Swap(document, value); +} + +template +typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, const CharType(&source)[N], typename DocumentType::ValueType& value) { + return GenericPointer(source, N - 1).Swap(document, value); +} + +////////////////////////////////////////////////////////////////////////////// + +template +bool EraseValueByPointer(T& root, const GenericPointer& pointer) { + return pointer.Erase(root); +} + +template +bool EraseValueByPointer(T& root, const CharType(&source)[N]) { + return GenericPointer(source, N - 1).Erase(root); +} + +//@} + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) || defined(_MSC_VER) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_POINTER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/prettywriter.h b/components/thorvg-main/src/loaders/lottie/rapidjson/prettywriter.h new file mode 100644 index 0000000..fe45df1 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/prettywriter.h @@ -0,0 +1,277 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_PRETTYWRITER_H_ +#define RAPIDJSON_PRETTYWRITER_H_ + +#include "writer.h" + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Combination of PrettyWriter format flags. +/*! \see PrettyWriter::SetFormatOptions + */ +enum PrettyFormatOptions { + kFormatDefault = 0, //!< Default pretty formatting. + kFormatSingleLineArray = 1 //!< Format arrays on a single line. +}; + +//! Writer with indentation and spacing. +/*! + \tparam OutputStream Type of output os. + \tparam SourceEncoding Encoding of source string. + \tparam TargetEncoding Encoding of output stream. + \tparam StackAllocator Type of allocator for allocating memory of stack. +*/ +template, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags> +class PrettyWriter : public Writer { +public: + typedef Writer Base; + typedef typename Base::Ch Ch; + + //! Constructor + /*! \param os Output stream. + \param allocator User supplied allocator. If it is null, it will create a private one. + \param levelDepth Initial capacity of stack. + */ + explicit PrettyWriter(OutputStream& os, StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : + Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {} + + + explicit PrettyWriter(StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : + Base(allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {} + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + PrettyWriter(PrettyWriter&& rhs) : + Base(std::forward(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {} +#endif + + //! Set custom indentation. + /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\\t', '\\n', '\\r'). + \param indentCharCount Number of indent characters for each indentation level. + \note The default indentation is 4 spaces. + */ + PrettyWriter& SetIndent(Ch indentChar, unsigned indentCharCount) { + RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r'); + indentChar_ = indentChar; + indentCharCount_ = indentCharCount; + return *this; + } + + //! Set pretty writer formatting options. + /*! \param options Formatting options. + */ + PrettyWriter& SetFormatOptions(PrettyFormatOptions options) { + formatOptions_ = options; + return *this; + } + + /*! @name Implementation of Handler + \see Handler + */ + //@{ + + bool Null() { PrettyPrefix(kNullType); return Base::EndValue(Base::WriteNull()); } + bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::EndValue(Base::WriteBool(b)); } + bool Int(int i) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt(i)); } + bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint(u)); } + bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt64(i64)); } + bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint64(u64)); } + bool Double(double d) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteDouble(d)); } + + bool RawNumber(const Ch* str, SizeType length, bool copy = false) { + RAPIDJSON_ASSERT(str != 0); + (void)copy; + PrettyPrefix(kNumberType); + return Base::EndValue(Base::WriteString(str, length)); + } + + bool String(const Ch* str, SizeType length, bool copy = false) { + RAPIDJSON_ASSERT(str != 0); + (void)copy; + PrettyPrefix(kStringType); + return Base::EndValue(Base::WriteString(str, length)); + } + +#if RAPIDJSON_HAS_STDSTRING + bool String(const std::basic_string& str) { + return String(str.data(), SizeType(str.size())); + } +#endif + + bool StartObject() { + PrettyPrefix(kObjectType); + new (Base::level_stack_.template Push()) typename Base::Level(false); + return Base::WriteStartObject(); + } + + bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); } + +#if RAPIDJSON_HAS_STDSTRING + bool Key(const std::basic_string& str) { + return Key(str.data(), SizeType(str.size())); + } +#endif + + bool EndObject(SizeType memberCount = 0) { + (void)memberCount; + RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); // not inside an Object + RAPIDJSON_ASSERT(!Base::level_stack_.template Top()->inArray); // currently inside an Array, not Object + RAPIDJSON_ASSERT(0 == Base::level_stack_.template Top()->valueCount % 2); // Object has a Key without a Value + + bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; + + if (!empty) { + Base::os_->Put('\n'); + WriteIndent(); + } + bool ret = Base::EndValue(Base::WriteEndObject()); + (void)ret; + RAPIDJSON_ASSERT(ret == true); + if (Base::level_stack_.Empty()) // end of json text + Base::Flush(); + return true; + } + + bool StartArray() { + PrettyPrefix(kArrayType); + new (Base::level_stack_.template Push()) typename Base::Level(true); + return Base::WriteStartArray(); + } + + bool EndArray(SizeType memberCount = 0) { + (void)memberCount; + RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); + RAPIDJSON_ASSERT(Base::level_stack_.template Top()->inArray); + bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; + + if (!empty && !(formatOptions_ & kFormatSingleLineArray)) { + Base::os_->Put('\n'); + WriteIndent(); + } + bool ret = Base::EndValue(Base::WriteEndArray()); + (void)ret; + RAPIDJSON_ASSERT(ret == true); + if (Base::level_stack_.Empty()) // end of json text + Base::Flush(); + return true; + } + + //@} + + /*! @name Convenience extensions */ + //@{ + + //! Simpler but slower overload. + bool String(const Ch* str) { return String(str, internal::StrLen(str)); } + bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); } + + //@} + + //! Write a raw JSON value. + /*! + For user to write a stringified JSON as a value. + + \param json A well-formed JSON value. It should not contain null character within [0, length - 1] range. + \param length Length of the json. + \param type Type of the root of json. + \note When using PrettyWriter::RawValue(), the result json may not be indented correctly. + */ + bool RawValue(const Ch* json, size_t length, Type type) { + RAPIDJSON_ASSERT(json != 0); + PrettyPrefix(type); + return Base::EndValue(Base::WriteRawValue(json, length)); + } + +protected: + void PrettyPrefix(Type type) { + (void)type; + if (Base::level_stack_.GetSize() != 0) { // this value is not at root + typename Base::Level* level = Base::level_stack_.template Top(); + + if (level->inArray) { + if (level->valueCount > 0) { + Base::os_->Put(','); // add comma if it is not the first element in array + if (formatOptions_ & kFormatSingleLineArray) + Base::os_->Put(' '); + } + + if (!(formatOptions_ & kFormatSingleLineArray)) { + Base::os_->Put('\n'); + WriteIndent(); + } + } + else { // in object + if (level->valueCount > 0) { + if (level->valueCount % 2 == 0) { + Base::os_->Put(','); + Base::os_->Put('\n'); + } + else { + Base::os_->Put(':'); + Base::os_->Put(' '); + } + } + else + Base::os_->Put('\n'); + + if (level->valueCount % 2 == 0) + WriteIndent(); + } + if (!level->inArray && level->valueCount % 2 == 0) + RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name + level->valueCount++; + } + else { + RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root. + Base::hasRoot_ = true; + } + } + + void WriteIndent() { + size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_; + PutN(*Base::os_, static_cast(indentChar_), count); + } + + Ch indentChar_; + unsigned indentCharCount_; + PrettyFormatOptions formatOptions_; + +private: + // Prohibit copy constructor & assignment operator. + PrettyWriter(const PrettyWriter&); + PrettyWriter& operator=(const PrettyWriter&); +}; + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_RAPIDJSON_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/rapidjson.h b/components/thorvg-main/src/loaders/lottie/rapidjson/rapidjson.h new file mode 100644 index 0000000..60d8b10 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/rapidjson.h @@ -0,0 +1,741 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_RAPIDJSON_H_ +#define RAPIDJSON_RAPIDJSON_H_ + +/*!\file rapidjson.h + \brief common definitions and configuration + + \see RAPIDJSON_CONFIG + */ + +/*! \defgroup RAPIDJSON_CONFIG RapidJSON configuration + \brief Configuration macros for library features + + Some RapidJSON features are configurable to adapt the library to a wide + variety of platforms, environments and usage scenarios. Most of the + features can be configured in terms of overridden or predefined + preprocessor macros at compile-time. + + Some additional customization is available in the \ref RAPIDJSON_ERRORS APIs. + + \note These macros should be given on the compiler command-line + (where applicable) to avoid inconsistent values when compiling + different translation units of a single application. + */ + +#include "tvgCommon.h" + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_VERSION_STRING +// +// ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt. +// + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +// token stringification +#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x) +#define RAPIDJSON_DO_STRINGIFY(x) #x + +// token concatenation +#define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y) +#define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y) +#define RAPIDJSON_DO_JOIN2(X, Y) X##Y +//!@endcond + +/*! \def RAPIDJSON_MAJOR_VERSION + \ingroup RAPIDJSON_CONFIG + \brief Major version of RapidJSON in integer. +*/ +/*! \def RAPIDJSON_MINOR_VERSION + \ingroup RAPIDJSON_CONFIG + \brief Minor version of RapidJSON in integer. +*/ +/*! \def RAPIDJSON_PATCH_VERSION + \ingroup RAPIDJSON_CONFIG + \brief Patch version of RapidJSON in integer. +*/ +/*! \def RAPIDJSON_VERSION_STRING + \ingroup RAPIDJSON_CONFIG + \brief Version of RapidJSON in ".." string format. +*/ +#define RAPIDJSON_MAJOR_VERSION 1 +#define RAPIDJSON_MINOR_VERSION 1 +#define RAPIDJSON_PATCH_VERSION 0 +#define RAPIDJSON_VERSION_STRING \ + RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION) + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_NAMESPACE_(BEGIN|END) +/*! \def RAPIDJSON_NAMESPACE + \ingroup RAPIDJSON_CONFIG + \brief provide custom rapidjson namespace + + In order to avoid symbol clashes and/or "One Definition Rule" errors + between multiple inclusions of (different versions of) RapidJSON in + a single binary, users can customize the name of the main RapidJSON + namespace. + + In case of a single nesting level, defining \c RAPIDJSON_NAMESPACE + to a custom name (e.g. \c MyRapidJSON) is sufficient. If multiple + levels are needed, both \ref RAPIDJSON_NAMESPACE_BEGIN and \ref + RAPIDJSON_NAMESPACE_END need to be defined as well: + + \code + // in some .cpp file + #define RAPIDJSON_NAMESPACE my::rapidjson + #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson { + #define RAPIDJSON_NAMESPACE_END } } + #include "rapidjson/..." + \endcode + + \see rapidjson + */ +/*! \def RAPIDJSON_NAMESPACE_BEGIN + \ingroup RAPIDJSON_CONFIG + \brief provide custom rapidjson namespace (opening expression) + \see RAPIDJSON_NAMESPACE +*/ +/*! \def RAPIDJSON_NAMESPACE_END + \ingroup RAPIDJSON_CONFIG + \brief provide custom rapidjson namespace (closing expression) + \see RAPIDJSON_NAMESPACE +*/ +#ifndef RAPIDJSON_NAMESPACE +#define RAPIDJSON_NAMESPACE rapidjson +#endif +#ifndef RAPIDJSON_NAMESPACE_BEGIN +#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE { +#endif +#ifndef RAPIDJSON_NAMESPACE_END +#define RAPIDJSON_NAMESPACE_END } +#endif + +/////////////////////////////////////////////////////////////////////////////// +// __cplusplus macro + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN + +#if defined(_MSC_VER) +#define RAPIDJSON_CPLUSPLUS _MSVC_LANG +#else +#define RAPIDJSON_CPLUSPLUS __cplusplus +#endif + +//!@endcond + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_HAS_STDSTRING + +#ifndef RAPIDJSON_HAS_STDSTRING +#ifdef RAPIDJSON_DOXYGEN_RUNNING +#define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation +#else +#define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default +#endif +/*! \def RAPIDJSON_HAS_STDSTRING + \ingroup RAPIDJSON_CONFIG + \brief Enable RapidJSON support for \c std::string + + By defining this preprocessor symbol to \c 1, several convenience functions for using + \ref rapidjson::GenericValue with \c std::string are enabled, especially + for construction and comparison. + + \hideinitializer +*/ +#endif // !defined(RAPIDJSON_HAS_STDSTRING) + +#if RAPIDJSON_HAS_STDSTRING +#include +#endif // RAPIDJSON_HAS_STDSTRING + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_USE_MEMBERSMAP + +/*! \def RAPIDJSON_USE_MEMBERSMAP + \ingroup RAPIDJSON_CONFIG + \brief Enable RapidJSON support for object members handling in a \c std::multimap + + By defining this preprocessor symbol to \c 1, \ref rapidjson::GenericValue object + members are stored in a \c std::multimap for faster lookup and deletion times, a + trade off with a slightly slower insertion time and a small object allocat(or)ed + memory overhead. + + \hideinitializer +*/ +#ifndef RAPIDJSON_USE_MEMBERSMAP +#define RAPIDJSON_USE_MEMBERSMAP 0 // not by default +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_NO_INT64DEFINE + +/*! \def RAPIDJSON_NO_INT64DEFINE + \ingroup RAPIDJSON_CONFIG + \brief Use external 64-bit integer types. + + RapidJSON requires the 64-bit integer types \c int64_t and \c uint64_t types + to be available at global scope. + + If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to + prevent RapidJSON from defining its own types. +*/ +#ifndef RAPIDJSON_NO_INT64DEFINE +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 +#include "msinttypes/stdint.h" +#include "msinttypes/inttypes.h" +#else +// Other compilers should have this. +#include +#include +#endif +//!@endcond +#ifdef RAPIDJSON_DOXYGEN_RUNNING +#define RAPIDJSON_NO_INT64DEFINE +#endif +#endif // RAPIDJSON_NO_INT64TYPEDEF + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_FORCEINLINE + +#ifndef RAPIDJSON_FORCEINLINE +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +#if defined(_MSC_VER) && defined(NDEBUG) +#define RAPIDJSON_FORCEINLINE __forceinline +#elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG) +#define RAPIDJSON_FORCEINLINE __attribute__((always_inline)) +#else +#define RAPIDJSON_FORCEINLINE +#endif +//!@endcond +#endif // RAPIDJSON_FORCEINLINE + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_ENDIAN +#define RAPIDJSON_LITTLEENDIAN 0 //!< Little endian machine +#define RAPIDJSON_BIGENDIAN 1 //!< Big endian machine + +//! Endianness of the machine. +/*! + \def RAPIDJSON_ENDIAN + \ingroup RAPIDJSON_CONFIG + + GCC 4.6 provided macro for detecting endianness of the target machine. But other + compilers may not have this. User can define RAPIDJSON_ENDIAN to either + \ref RAPIDJSON_LITTLEENDIAN or \ref RAPIDJSON_BIGENDIAN. + + Default detection implemented with reference to + \li https://gcc.gnu.org/onlinedocs/gcc-4.6.0/cpp/Common-Predefined-Macros.html + \li http://www.boost.org/doc/libs/1_42_0/boost/detail/endian.hpp +*/ +#ifndef RAPIDJSON_ENDIAN +// Detect with GCC 4.6's macro +# ifdef __BYTE_ORDER__ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN +# else +# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. +# endif // __BYTE_ORDER__ +// Detect with GLIBC's endian.h +# elif defined(__GLIBC__) +# include +# if (__BYTE_ORDER == __LITTLE_ENDIAN) +# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN +# elif (__BYTE_ORDER == __BIG_ENDIAN) +# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN +# else +# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. +# endif // __GLIBC__ +// Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro +# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) +# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN +# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) +# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN +// Detect with architecture macros +# elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__) +# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN +# elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__bfin__) +# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN +# elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) +# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN +# elif defined(RAPIDJSON_DOXYGEN_RUNNING) +# define RAPIDJSON_ENDIAN +# else +# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. +# endif +#endif // RAPIDJSON_ENDIAN + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_64BIT + +//! Whether using 64-bit architecture +#ifndef RAPIDJSON_64BIT +#if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__) +#define RAPIDJSON_64BIT 1 +#else +#define RAPIDJSON_64BIT 0 +#endif +#endif // RAPIDJSON_64BIT + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_ALIGN + +//! Data alignment of the machine. +/*! \ingroup RAPIDJSON_CONFIG + \param x pointer to align + + Some machines require strict data alignment. The default is 8 bytes. + User can customize by defining the RAPIDJSON_ALIGN function macro. +*/ +#ifndef RAPIDJSON_ALIGN +#define RAPIDJSON_ALIGN(x) (((x) + static_cast(7u)) & ~static_cast(7u)) +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_UINT64_C2 + +//! Construct a 64-bit literal by a pair of 32-bit integer. +/*! + 64-bit literal with or without ULL suffix is prone to compiler warnings. + UINT64_C() is C macro which cause compilation problems. + Use this macro to define 64-bit constants by a pair of 32-bit integer. +*/ +#ifndef RAPIDJSON_UINT64_C2 +#define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast(high32) << 32) | static_cast(low32)) +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_48BITPOINTER_OPTIMIZATION + +//! Use only lower 48-bit address for some pointers. +/*! + \ingroup RAPIDJSON_CONFIG + + This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address. + The higher 16-bit can be used for storing other data. + \c GenericValue uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture. +*/ +#ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION +#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) +#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1 +#else +#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0 +#endif +#endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION + +#if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1 +#if RAPIDJSON_64BIT != 1 +#error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1 +#endif +#define RAPIDJSON_SETPOINTER(type, p, x) (p = reinterpret_cast((reinterpret_cast(p) & static_cast(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | reinterpret_cast(reinterpret_cast(x)))) +#define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast(reinterpret_cast(p) & static_cast(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF)))) +#else +#define RAPIDJSON_SETPOINTER(type, p, x) (p = (x)) +#define RAPIDJSON_GETPOINTER(type, p) (p) +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_NEON/RAPIDJSON_SIMD + +/*! \def RAPIDJSON_SIMD + \ingroup RAPIDJSON_CONFIG + \brief Enable SSE2/SSE4.2/Neon optimization. + + RapidJSON supports optimized implementations for some parsing operations + based on the SSE2, SSE4.2 or NEon SIMD extensions on modern Intel + or ARM compatible processors. + + To enable these optimizations, three different symbols can be defined; + \code + // Enable SSE2 optimization. + #define RAPIDJSON_SSE2 + + // Enable SSE4.2 optimization. + #define RAPIDJSON_SSE42 + \endcode + + // Enable ARM Neon optimization. + #define RAPIDJSON_NEON + \endcode + + \c RAPIDJSON_SSE42 takes precedence over SSE2, if both are defined. + + If any of these symbols is defined, RapidJSON defines the macro + \c RAPIDJSON_SIMD to indicate the availability of the optimized code. +*/ +#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \ + || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING) +#define RAPIDJSON_SIMD +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_NO_SIZETYPEDEFINE + +#ifndef RAPIDJSON_NO_SIZETYPEDEFINE +/*! \def RAPIDJSON_NO_SIZETYPEDEFINE + \ingroup RAPIDJSON_CONFIG + \brief User-provided \c SizeType definition. + + In order to avoid using 32-bit size types for indexing strings and arrays, + define this preprocessor symbol and provide the type rapidjson::SizeType + before including RapidJSON: + \code + #define RAPIDJSON_NO_SIZETYPEDEFINE + namespace rapidjson { typedef ::std::size_t SizeType; } + #include "rapidjson/..." + \endcode + + \see rapidjson::SizeType +*/ +#ifdef RAPIDJSON_DOXYGEN_RUNNING +#define RAPIDJSON_NO_SIZETYPEDEFINE +#endif +RAPIDJSON_NAMESPACE_BEGIN +//! Size type (for string lengths, array sizes, etc.) +/*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms, + instead of using \c size_t. Users may override the SizeType by defining + \ref RAPIDJSON_NO_SIZETYPEDEFINE. +*/ +typedef unsigned SizeType; +RAPIDJSON_NAMESPACE_END +#endif + +// always import std::size_t to rapidjson namespace +RAPIDJSON_NAMESPACE_BEGIN +using std::size_t; +RAPIDJSON_NAMESPACE_END + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_ASSERT + +//! Assertion. +/*! \ingroup RAPIDJSON_CONFIG + By default, rapidjson uses C \c assert() for internal assertions. + User can override it by defining RAPIDJSON_ASSERT(x) macro. + + \note Parsing errors are handled and can be customized by the + \ref RAPIDJSON_ERRORS APIs. +*/ +#ifndef RAPIDJSON_ASSERT + //#include + //#define RAPIDJSON_ASSERT(x) assert(x) + #define RAPIDJSON_ASSERT(x) +#endif // RAPIDJSON_ASSERT + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_STATIC_ASSERT + +// Prefer C++11 static_assert, if available +#ifndef RAPIDJSON_STATIC_ASSERT +#if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 ) +#define RAPIDJSON_STATIC_ASSERT(x) \ + static_assert(x, RAPIDJSON_STRINGIFY(x)) +#endif // C++11 +#endif // RAPIDJSON_STATIC_ASSERT + +// Adopt C++03 implementation from boost +#ifndef RAPIDJSON_STATIC_ASSERT +#ifndef __clang__ +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +#endif +RAPIDJSON_NAMESPACE_BEGIN +template struct STATIC_ASSERTION_FAILURE; +template <> struct STATIC_ASSERTION_FAILURE { enum { value = 1 }; }; +template struct StaticAssertTest {}; +RAPIDJSON_NAMESPACE_END + +#if defined(__GNUC__) || defined(__clang__) +#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) +#else +#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE +#endif +#ifndef __clang__ +//!@endcond +#endif + +/*! \def RAPIDJSON_STATIC_ASSERT + \brief (Internal) macro to check for conditions at compile-time + \param x compile-time condition + \hideinitializer + */ +#define RAPIDJSON_STATIC_ASSERT(x) \ + typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \ + sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE)> \ + RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE +#endif // RAPIDJSON_STATIC_ASSERT + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY + +//! Compiler branching hint for expression with high probability to be true. +/*! + \ingroup RAPIDJSON_CONFIG + \param x Boolean expression likely to be true. +*/ +#ifndef RAPIDJSON_LIKELY +#if defined(__GNUC__) || defined(__clang__) +#define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1) +#else +#define RAPIDJSON_LIKELY(x) (x) +#endif +#endif + +//! Compiler branching hint for expression with low probability to be true. +/*! + \ingroup RAPIDJSON_CONFIG + \param x Boolean expression unlikely to be true. +*/ +#ifndef RAPIDJSON_UNLIKELY +#if defined(__GNUC__) || defined(__clang__) +#define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define RAPIDJSON_UNLIKELY(x) (x) +#endif +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Helpers + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN + +#define RAPIDJSON_MULTILINEMACRO_BEGIN do { +#define RAPIDJSON_MULTILINEMACRO_END \ +} while((void)0, 0) + +// adopted from Boost +#define RAPIDJSON_VERSION_CODE(x,y,z) \ + (((x)*100000) + ((y)*100) + (z)) + +#if defined(__has_builtin) +#define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x) +#else +#define RAPIDJSON_HAS_BUILTIN(x) 0 +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF + +#if defined(__GNUC__) +#define RAPIDJSON_GNUC \ + RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) +#endif + +#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0)) + +#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x)) +#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x) +#define RAPIDJSON_DIAG_OFF(x) \ + RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x))) + +// push/pop support in Clang and GCC>=4.6 +#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) +#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push) +#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop) +#else // GCC >= 4.2, < 4.6 +#define RAPIDJSON_DIAG_PUSH /* ignored */ +#define RAPIDJSON_DIAG_POP /* ignored */ +#endif + +#elif defined(_MSC_VER) + +// pragma (MSVC specific) +#define RAPIDJSON_PRAGMA(x) __pragma(x) +#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x)) + +#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x) +#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push) +#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop) + +#else + +#define RAPIDJSON_DIAG_OFF(x) /* ignored */ +#define RAPIDJSON_DIAG_PUSH /* ignored */ +#define RAPIDJSON_DIAG_POP /* ignored */ + +#endif // RAPIDJSON_DIAG_* + +/////////////////////////////////////////////////////////////////////////////// +// C++11 features + +#ifndef RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11 (RAPIDJSON_CPLUSPLUS >= 201103L) +#endif + +#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS +#if RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 +#elif defined(__clang__) +#if __has_feature(cxx_rvalue_references) && \ + (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306) +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 +#else +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0 +#endif +#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \ + (defined(_MSC_VER) && _MSC_VER >= 1600) || \ + (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__)) + +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 +#else +#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0 +#endif +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS +#include // std::move +#endif + +#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT +#if RAPIDJSON_HAS_CXX11 +#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1 +#elif defined(__clang__) +#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept) +#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \ + (defined(_MSC_VER) && _MSC_VER >= 1900) || \ + (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__)) +#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1 +#else +#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0 +#endif +#endif +#ifndef RAPIDJSON_NOEXCEPT +#if RAPIDJSON_HAS_CXX11_NOEXCEPT +#define RAPIDJSON_NOEXCEPT noexcept +#else +#define RAPIDJSON_NOEXCEPT throw() +#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT +#endif + +// no automatic detection, yet +#ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS +#if (defined(_MSC_VER) && _MSC_VER >= 1700) +#define RAPIDJSON_HAS_CXX11_TYPETRAITS 1 +#else +#define RAPIDJSON_HAS_CXX11_TYPETRAITS 0 +#endif +#endif + +#ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR +#if defined(__clang__) +#define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for) +#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \ + (defined(_MSC_VER) && _MSC_VER >= 1700) || \ + (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__)) +#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1 +#else +#define RAPIDJSON_HAS_CXX11_RANGE_FOR 0 +#endif +#endif // RAPIDJSON_HAS_CXX11_RANGE_FOR + +/////////////////////////////////////////////////////////////////////////////// +// C++17 features + +#ifndef RAPIDJSON_HAS_CXX17 +#define RAPIDJSON_HAS_CXX17 (RAPIDJSON_CPLUSPLUS >= 201703L) +#endif + +#if RAPIDJSON_HAS_CXX17 +# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]] +#elif defined(__has_cpp_attribute) +# if __has_cpp_attribute(clang::fallthrough) +# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]] +# elif __has_cpp_attribute(fallthrough) +# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough)) +# else +# define RAPIDJSON_DELIBERATE_FALLTHROUGH +# endif +#else +# define RAPIDJSON_DELIBERATE_FALLTHROUGH +#endif + +//!@endcond + +//! Assertion (in non-throwing contexts). + /*! \ingroup RAPIDJSON_CONFIG + Some functions provide a \c noexcept guarantee, if the compiler supports it. + In these cases, the \ref RAPIDJSON_ASSERT macro cannot be overridden to + throw an exception. This macro adds a separate customization point for + such cases. + + Defaults to C \c assert() (as \ref RAPIDJSON_ASSERT), if \c noexcept is + supported, and to \ref RAPIDJSON_ASSERT otherwise. + */ + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_NOEXCEPT_ASSERT + +#ifndef RAPIDJSON_NOEXCEPT_ASSERT +#ifdef RAPIDJSON_ASSERT_THROWS +#include +#define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x) +#else +#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x) +#endif // RAPIDJSON_ASSERT_THROWS +#endif // RAPIDJSON_NOEXCEPT_ASSERT + +/////////////////////////////////////////////////////////////////////////////// +// malloc/realloc/free + +#ifndef RAPIDJSON_MALLOC +///! customization point for global \c malloc +#define RAPIDJSON_MALLOC(size) tvg::malloc(size) +#endif +#ifndef RAPIDJSON_REALLOC +///! customization point for global \c realloc +#define RAPIDJSON_REALLOC(ptr, new_size) tvg::realloc(ptr, new_size) +#endif +#ifndef RAPIDJSON_FREE +///! customization point for global \c free +#define RAPIDJSON_FREE(ptr) tvg::free(ptr) +#endif + +/////////////////////////////////////////////////////////////////////////////// +// new/delete + +#ifndef RAPIDJSON_NEW +///! customization point for global \c new +#define RAPIDJSON_NEW(TypeName) new TypeName +#endif +#ifndef RAPIDJSON_DELETE +///! customization point for global \c delete +#define RAPIDJSON_DELETE(x) delete x +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Type + +/*! \namespace rapidjson + \brief main RapidJSON namespace + \see RAPIDJSON_NAMESPACE +*/ +RAPIDJSON_NAMESPACE_BEGIN + +//! Type of JSON value +enum Type { + kNullType = 0, //!< null + kFalseType = 1, //!< false + kTrueType = 2, //!< true + kObjectType = 3, //!< object + kArrayType = 4, //!< array + kStringType = 5, //!< string + kNumberType = 6 //!< number +}; + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_RAPIDJSON_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/reader.h b/components/thorvg-main/src/loaders/lottie/rapidjson/reader.h new file mode 100644 index 0000000..86c1f28 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/reader.h @@ -0,0 +1,2246 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_READER_H_ +#define RAPIDJSON_READER_H_ + +/*! \file reader.h */ + +#include "allocators.h" +#include "stream.h" +#include "encodedstream.h" +#include "internal/clzll.h" +#include "internal/meta.h" +#include "internal/stack.h" +#include "internal/strtod.h" +#include + +#if defined(RAPIDJSON_SIMD) && defined(_MSC_VER) +#include +#pragma intrinsic(_BitScanForward) +#endif +#ifdef RAPIDJSON_SSE42 +#include +#elif defined(RAPIDJSON_SSE2) +#include +#elif defined(RAPIDJSON_NEON) +#include +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(old-style-cast) +RAPIDJSON_DIAG_OFF(padded) +RAPIDJSON_DIAG_OFF(switch-enum) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant +RAPIDJSON_DIAG_OFF(4702) // unreachable code +#endif + +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +#define RAPIDJSON_NOTHING /* deliberately empty */ +#ifndef RAPIDJSON_PARSE_ERROR_EARLY_RETURN +#define RAPIDJSON_PARSE_ERROR_EARLY_RETURN(value) \ + RAPIDJSON_MULTILINEMACRO_BEGIN \ + if (RAPIDJSON_UNLIKELY(HasParseError())) { return value; } \ + RAPIDJSON_MULTILINEMACRO_END +#endif +#define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID \ + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(RAPIDJSON_NOTHING) +//!@endcond + +/*! \def RAPIDJSON_PARSE_ERROR_NORETURN + \ingroup RAPIDJSON_ERRORS + \brief Macro to indicate a parse error. + \param parseErrorCode \ref rapidjson::ParseErrorCode of the error + \param offset position of the error in JSON input (\c size_t) + + This macros can be used as a customization point for the internal + error handling mechanism of RapidJSON. + + A common usage model is to throw an exception instead of requiring the + caller to explicitly check the \ref rapidjson::GenericReader::Parse's + return value: + + \code + #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \ + throw ParseException(parseErrorCode, #parseErrorCode, offset) + + #include // std::runtime_error + #include "rapidjson/error/error.h" // rapidjson::ParseResult + + struct ParseException : std::runtime_error, rapidjson::ParseResult { + ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset) + : std::runtime_error(msg), ParseResult(code, offset) {} + }; + + #include "rapidjson/reader.h" + \endcode + + \see RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse + */ +#ifndef RAPIDJSON_PARSE_ERROR_NORETURN +#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) \ + RAPIDJSON_MULTILINEMACRO_BEGIN \ + RAPIDJSON_ASSERT(!HasParseError()); /* Error can only be assigned once */ \ + SetParseError(parseErrorCode, offset); \ + RAPIDJSON_MULTILINEMACRO_END +#endif + +/*! \def RAPIDJSON_PARSE_ERROR + \ingroup RAPIDJSON_ERRORS + \brief (Internal) macro to indicate and handle a parse error. + \param parseErrorCode \ref rapidjson::ParseErrorCode of the error + \param offset position of the error in JSON input (\c size_t) + + Invokes RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing. + + \see RAPIDJSON_PARSE_ERROR_NORETURN + \hideinitializer + */ +#ifndef RAPIDJSON_PARSE_ERROR +#define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \ + RAPIDJSON_MULTILINEMACRO_BEGIN \ + RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \ + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \ + RAPIDJSON_MULTILINEMACRO_END +#endif + +#include "error/error.h" // ParseErrorCode, ParseResult + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// ParseFlag + +/*! \def RAPIDJSON_PARSE_DEFAULT_FLAGS + \ingroup RAPIDJSON_CONFIG + \brief User-defined kParseDefaultFlags definition. + + User can define this as any \c ParseFlag combinations. +*/ +#ifndef RAPIDJSON_PARSE_DEFAULT_FLAGS +#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNoFlags +#endif + +//! Combination of parseFlags +/*! \see Reader::Parse, Document::Parse, Document::ParseInsitu, Document::ParseStream + */ +enum ParseFlag { + kParseNoFlags = 0, //!< No flags are set. + kParseInsituFlag = 1, //!< In-situ(destructive) parsing. + kParseValidateEncodingFlag = 2, //!< Validate encoding of JSON strings. + kParseIterativeFlag = 4, //!< Iterative(constant complexity in terms of function call stack size) parsing. + kParseStopWhenDoneFlag = 8, //!< After parsing a complete JSON root from stream, stop further processing the rest of stream. When this flag is used, parser will not generate kParseErrorDocumentRootNotSingular error. + kParseFullPrecisionFlag = 16, //!< Parse number in full precision (but slower). + kParseCommentsFlag = 32, //!< Allow one-line (//) and multi-line (/**/) comments. + kParseNumbersAsStringsFlag = 64, //!< Parse all numbers (ints/doubles) as strings. + kParseTrailingCommasFlag = 128, //!< Allow trailing commas at the end of objects and arrays. + kParseNanAndInfFlag = 256, //!< Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles. + kParseEscapedApostropheFlag = 512, //!< Allow escaped apostrophe in strings. + kParseDefaultFlags = RAPIDJSON_PARSE_DEFAULT_FLAGS //!< Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS +}; + +/////////////////////////////////////////////////////////////////////////////// +// Handler + +/*! \class rapidjson::Handler + \brief Concept for receiving events from GenericReader upon parsing. + The functions return true if no error occurs. If they return false, + the event publisher should terminate the process. +\code +concept Handler { + typename Ch; + + bool Null(); + bool Bool(bool b); + bool Int(int i); + bool Uint(unsigned i); + bool Int64(int64_t i); + bool Uint64(uint64_t i); + bool Double(double d); + /// enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length) + bool RawNumber(const Ch* str, SizeType length, bool copy); + bool String(const Ch* str, SizeType length, bool copy); + bool StartObject(); + bool Key(const Ch* str, SizeType length, bool copy); + bool EndObject(SizeType memberCount); + bool StartArray(); + bool EndArray(SizeType elementCount); +}; +\endcode +*/ +/////////////////////////////////////////////////////////////////////////////// +// BaseReaderHandler + +//! Default implementation of Handler. +/*! This can be used as base class of any reader handler. + \note implements Handler concept +*/ +template, typename Derived = void> +struct BaseReaderHandler { + typedef typename Encoding::Ch Ch; + + typedef typename internal::SelectIf, BaseReaderHandler, Derived>::Type Override; + + bool Default() { return true; } + bool Null() { return static_cast(*this).Default(); } + bool Bool(bool) { return static_cast(*this).Default(); } + bool Int(int) { return static_cast(*this).Default(); } + bool Uint(unsigned) { return static_cast(*this).Default(); } + bool Int64(int64_t) { return static_cast(*this).Default(); } + bool Uint64(uint64_t) { return static_cast(*this).Default(); } + bool Double(double) { return static_cast(*this).Default(); } + /// enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length) + bool RawNumber(const Ch* str, SizeType len, bool copy) { return static_cast(*this).String(str, len, copy); } + bool String(const Ch*, SizeType, bool) { return static_cast(*this).Default(); } + bool StartObject() { return static_cast(*this).Default(); } + bool Key(const Ch* str, SizeType len, bool copy) { return static_cast(*this).String(str, len, copy); } + bool EndObject(SizeType) { return static_cast(*this).Default(); } + bool StartArray() { return static_cast(*this).Default(); } + bool EndArray(SizeType) { return static_cast(*this).Default(); } +}; + +/////////////////////////////////////////////////////////////////////////////// +// StreamLocalCopy + +namespace internal { + +template::copyOptimization> +class StreamLocalCopy; + +//! Do copy optimization. +template +class StreamLocalCopy { +public: + StreamLocalCopy(Stream& original) : s(original), original_(original) {} + ~StreamLocalCopy() { original_ = s; } + + Stream s; + +private: + StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */; + + Stream& original_; +}; + +//! Keep reference. +template +class StreamLocalCopy { +public: + StreamLocalCopy(Stream& original) : s(original) {} + + Stream& s; + +private: + StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */; +}; + +} // namespace internal + +/////////////////////////////////////////////////////////////////////////////// +// SkipWhitespace + +//! Skip the JSON white spaces in a stream. +/*! \param is A input stream for skipping white spaces. + \note This function has SSE2/SSE4.2 specialization. +*/ +template +void SkipWhitespace(InputStream& is) { + internal::StreamLocalCopy copy(is); + InputStream& s(copy.s); + + typename InputStream::Ch c; + while ((c = s.Peek()) == ' ' || c == '\n' || c == '\r' || c == '\t') + s.Take(); +} + +inline const char* SkipWhitespace(const char* p, const char* end) { + while (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) + ++p; + return p; +} + +#ifdef RAPIDJSON_SSE42 +//! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once. +inline const char *SkipWhitespace_SIMD(const char* p) { + // Fast return for single non-whitespace + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; + + // 16-byte align to the next boundary + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; + + // The rest of string using SIMD + static const char whitespace[16] = " \n\r\t"; + const __m128i w = _mm_loadu_si128(reinterpret_cast(&whitespace[0])); + + for (;; p += 16) { + const __m128i s = _mm_load_si128(reinterpret_cast(p)); + const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY); + if (r != 16) // some of characters is non-whitespace + return p + r; + } +} + +inline const char *SkipWhitespace_SIMD(const char* p, const char* end) { + // Fast return for single non-whitespace + if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) + ++p; + else + return p; + + // The middle of string using SIMD + static const char whitespace[16] = " \n\r\t"; + const __m128i w = _mm_loadu_si128(reinterpret_cast(&whitespace[0])); + + for (; p <= end - 16; p += 16) { + const __m128i s = _mm_loadu_si128(reinterpret_cast(p)); + const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY); + if (r != 16) // some of characters is non-whitespace + return p + r; + } + + return SkipWhitespace(p, end); +} + +#elif defined(RAPIDJSON_SSE2) + +//! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once. +inline const char *SkipWhitespace_SIMD(const char* p) { + // Fast return for single non-whitespace + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; + + // 16-byte align to the next boundary + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; + + // The rest of string + #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } + static const char whitespaces[4][16] = { C16(' '), C16('\n'), C16('\r'), C16('\t') }; + #undef C16 + + const __m128i w0 = _mm_loadu_si128(reinterpret_cast(&whitespaces[0][0])); + const __m128i w1 = _mm_loadu_si128(reinterpret_cast(&whitespaces[1][0])); + const __m128i w2 = _mm_loadu_si128(reinterpret_cast(&whitespaces[2][0])); + const __m128i w3 = _mm_loadu_si128(reinterpret_cast(&whitespaces[3][0])); + + for (;; p += 16) { + const __m128i s = _mm_load_si128(reinterpret_cast(p)); + __m128i x = _mm_cmpeq_epi8(s, w0); + x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1)); + x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2)); + x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3)); + unsigned short r = static_cast(~_mm_movemask_epi8(x)); + if (r != 0) { // some of characters may be non-whitespace +#ifdef _MSC_VER // Find the index of first non-whitespace + unsigned long offset; + _BitScanForward(&offset, r); + return p + offset; +#else + return p + __builtin_ffs(r) - 1; +#endif + } + } +} + +inline const char *SkipWhitespace_SIMD(const char* p, const char* end) { + // Fast return for single non-whitespace + if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) + ++p; + else + return p; + + // The rest of string + #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } + static const char whitespaces[4][16] = { C16(' '), C16('\n'), C16('\r'), C16('\t') }; + #undef C16 + + const __m128i w0 = _mm_loadu_si128(reinterpret_cast(&whitespaces[0][0])); + const __m128i w1 = _mm_loadu_si128(reinterpret_cast(&whitespaces[1][0])); + const __m128i w2 = _mm_loadu_si128(reinterpret_cast(&whitespaces[2][0])); + const __m128i w3 = _mm_loadu_si128(reinterpret_cast(&whitespaces[3][0])); + + for (; p <= end - 16; p += 16) { + const __m128i s = _mm_loadu_si128(reinterpret_cast(p)); + __m128i x = _mm_cmpeq_epi8(s, w0); + x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1)); + x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2)); + x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3)); + unsigned short r = static_cast(~_mm_movemask_epi8(x)); + if (r != 0) { // some of characters may be non-whitespace +#ifdef _MSC_VER // Find the index of first non-whitespace + unsigned long offset; + _BitScanForward(&offset, r); + return p + offset; +#else + return p + __builtin_ffs(r) - 1; +#endif + } + } + + return SkipWhitespace(p, end); +} + +#elif defined(RAPIDJSON_NEON) + +//! Skip whitespace with ARM Neon instructions, testing 16 8-byte characters at once. +inline const char *SkipWhitespace_SIMD(const char* p) { + // Fast return for single non-whitespace + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; + + // 16-byte align to the next boundary + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; + + const uint8x16_t w0 = vmovq_n_u8(' '); + const uint8x16_t w1 = vmovq_n_u8('\n'); + const uint8x16_t w2 = vmovq_n_u8('\r'); + const uint8x16_t w3 = vmovq_n_u8('\t'); + + for (;; p += 16) { + const uint8x16_t s = vld1q_u8(reinterpret_cast(p)); + uint8x16_t x = vceqq_u8(s, w0); + x = vorrq_u8(x, vceqq_u8(s, w1)); + x = vorrq_u8(x, vceqq_u8(s, w2)); + x = vorrq_u8(x, vceqq_u8(s, w3)); + + x = vmvnq_u8(x); // Negate + x = vrev64q_u8(x); // Rev in 64 + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract + + if (low == 0) { + if (high != 0) { + uint32_t lz = internal::clzll(high); + return p + 8 + (lz >> 3); + } + } else { + uint32_t lz = internal::clzll(low); + return p + (lz >> 3); + } + } +} + +inline const char *SkipWhitespace_SIMD(const char* p, const char* end) { + // Fast return for single non-whitespace + if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) + ++p; + else + return p; + + const uint8x16_t w0 = vmovq_n_u8(' '); + const uint8x16_t w1 = vmovq_n_u8('\n'); + const uint8x16_t w2 = vmovq_n_u8('\r'); + const uint8x16_t w3 = vmovq_n_u8('\t'); + + for (; p <= end - 16; p += 16) { + const uint8x16_t s = vld1q_u8(reinterpret_cast(p)); + uint8x16_t x = vceqq_u8(s, w0); + x = vorrq_u8(x, vceqq_u8(s, w1)); + x = vorrq_u8(x, vceqq_u8(s, w2)); + x = vorrq_u8(x, vceqq_u8(s, w3)); + + x = vmvnq_u8(x); // Negate + x = vrev64q_u8(x); // Rev in 64 + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract + + if (low == 0) { + if (high != 0) { + uint32_t lz = internal::clzll(high); + return p + 8 + (lz >> 3); + } + } else { + uint32_t lz = internal::clzll(low); + return p + (lz >> 3); + } + } + + return SkipWhitespace(p, end); +} + +#endif // RAPIDJSON_NEON + +#ifdef RAPIDJSON_SIMD +//! Template function specialization for InsituStringStream +template<> inline void SkipWhitespace(InsituStringStream& is) { + is.src_ = const_cast(SkipWhitespace_SIMD(is.src_)); +} + +//! Template function specialization for StringStream +template<> inline void SkipWhitespace(StringStream& is) { + is.src_ = SkipWhitespace_SIMD(is.src_); +} + +template<> inline void SkipWhitespace(EncodedInputStream, MemoryStream>& is) { + is.is_.src_ = SkipWhitespace_SIMD(is.is_.src_, is.is_.end_); +} +#endif // RAPIDJSON_SIMD + +/////////////////////////////////////////////////////////////////////////////// +// GenericReader + +//! SAX-style JSON parser. Use \ref Reader for UTF8 encoding and default allocator. +/*! GenericReader parses JSON text from a stream, and send events synchronously to an + object implementing Handler concept. + + It needs to allocate a stack for storing a single decoded string during + non-destructive parsing. + + For in-situ parsing, the decoded string is directly written to the source + text string, no temporary buffer is required. + + A GenericReader object can be reused for parsing multiple JSON text. + + \tparam SourceEncoding Encoding of the input stream. + \tparam TargetEncoding Encoding of the parse output. + \tparam StackAllocator Allocator type for stack. +*/ +template +class GenericReader { +public: + typedef typename SourceEncoding::Ch Ch; //!< SourceEncoding character type + + //! Constructor. + /*! \param stackAllocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing) + \param stackCapacity stack capacity in bytes for storing a single decoded string. (Only use for non-destructive parsing) + */ + GenericReader(StackAllocator* stackAllocator = 0, size_t stackCapacity = kDefaultStackCapacity) : + stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState) {} + + //! Parse JSON text. + /*! \tparam parseFlags Combination of \ref ParseFlag. + \tparam InputStream Type of input stream, implementing Stream concept. + \tparam Handler Type of handler, implementing Handler concept. + \param is Input stream to be parsed. + \param handler The handler to receive events. + \return Whether the parsing is successful. + */ + template + ParseResult Parse(InputStream& is, Handler& handler) { + if (parseFlags & kParseIterativeFlag) + return IterativeParse(is, handler); + + parseResult_.Clear(); + + ClearStackOnExit scope(*this); + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + + if (RAPIDJSON_UNLIKELY(is.Peek() == '\0')) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorDocumentEmpty, is.Tell()); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + } + else { + ParseValue(is, handler); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + + if (!(parseFlags & kParseStopWhenDoneFlag)) { + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + + if (RAPIDJSON_UNLIKELY(is.Peek() != '\0')) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorDocumentRootNotSingular, is.Tell()); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + } + } + } + + return parseResult_; + } + + //! Parse JSON text (with \ref kParseDefaultFlags) + /*! \tparam InputStream Type of input stream, implementing Stream concept + \tparam Handler Type of handler, implementing Handler concept. + \param is Input stream to be parsed. + \param handler The handler to receive events. + \return Whether the parsing is successful. + */ + template + ParseResult Parse(InputStream& is, Handler& handler) { + return Parse(is, handler); + } + + //! Initialize JSON text token-by-token parsing + /*! + */ + void IterativeParseInit() { + parseResult_.Clear(); + state_ = IterativeParsingStartState; + } + + //! Parse one token from JSON text + /*! \tparam InputStream Type of input stream, implementing Stream concept + \tparam Handler Type of handler, implementing Handler concept. + \param is Input stream to be parsed. + \param handler The handler to receive events. + \return Whether the parsing is successful. + */ + template + bool IterativeParseNext(InputStream& is, Handler& handler) { + while (RAPIDJSON_LIKELY(is.Peek() != '\0')) { + SkipWhitespaceAndComments(is); + + Token t = Tokenize(is.Peek()); + IterativeParsingState n = Predict(state_, t); + IterativeParsingState d = Transit(state_, t, n, is, handler); + + // If we've finished or hit an error... + if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) { + // Report errors. + if (d == IterativeParsingErrorState) { + HandleError(state_, is); + return false; + } + + // Transition to the finish state. + RAPIDJSON_ASSERT(d == IterativeParsingFinishState); + state_ = d; + + // If StopWhenDone is not set... + if (!(parseFlags & kParseStopWhenDoneFlag)) { + // ... and extra non-whitespace data is found... + SkipWhitespaceAndComments(is); + if (is.Peek() != '\0') { + // ... this is considered an error. + HandleError(state_, is); + return false; + } + } + + // Success! We are done! + return true; + } + + // Transition to the new state. + state_ = d; + + // If we parsed anything other than a delimiter, we invoked the handler, so we can return true now. + if (!IsIterativeParsingDelimiterState(n)) + return true; + } + + // We reached the end of file. + stack_.Clear(); + + if (state_ != IterativeParsingFinishState) { + HandleError(state_, is); + return false; + } + + return true; + } + + //! Check if token-by-token parsing JSON text is complete + /*! \return Whether the JSON has been fully decoded. + */ + RAPIDJSON_FORCEINLINE bool IterativeParseComplete() const { + return IsIterativeParsingCompleteState(state_); + } + + //! Whether a parse error has occurred in the last parsing. + bool HasParseError() const { return parseResult_.IsError(); } + + //! Get the \ref ParseErrorCode of last parsing. + ParseErrorCode GetParseErrorCode() const { return parseResult_.Code(); } + + //! Get the position of last parsing error in input, 0 otherwise. + size_t GetErrorOffset() const { return parseResult_.Offset(); } + +protected: + void SetParseError(ParseErrorCode code, size_t offset) { parseResult_.Set(code, offset); } + +private: + // Prohibit copy constructor & assignment operator. + GenericReader(const GenericReader&); + GenericReader& operator=(const GenericReader&); + + void ClearStack() { stack_.Clear(); } + + // clear stack on any exit from ParseStream, e.g. due to exception + struct ClearStackOnExit { + explicit ClearStackOnExit(GenericReader& r) : r_(r) {} + ~ClearStackOnExit() { r_.ClearStack(); } + private: + GenericReader& r_; + ClearStackOnExit(const ClearStackOnExit&); + ClearStackOnExit& operator=(const ClearStackOnExit&); + }; + + template + void SkipWhitespaceAndComments(InputStream& is) { + SkipWhitespace(is); + + if (parseFlags & kParseCommentsFlag) { + while (RAPIDJSON_UNLIKELY(Consume(is, '/'))) { + if (Consume(is, '*')) { + while (true) { + if (RAPIDJSON_UNLIKELY(is.Peek() == '\0')) + RAPIDJSON_PARSE_ERROR(kParseErrorUnspecificSyntaxError, is.Tell()); + else if (Consume(is, '*')) { + if (Consume(is, '/')) + break; + } + else + is.Take(); + } + } + else if (RAPIDJSON_LIKELY(Consume(is, '/'))) + while (is.Peek() != '\0' && is.Take() != '\n') {} + else + RAPIDJSON_PARSE_ERROR(kParseErrorUnspecificSyntaxError, is.Tell()); + + SkipWhitespace(is); + } + } + } + + // Parse object: { string : value, ... } + template + void ParseObject(InputStream& is, Handler& handler) { + RAPIDJSON_ASSERT(is.Peek() == '{'); + is.Take(); // Skip '{' + + if (RAPIDJSON_UNLIKELY(!handler.StartObject())) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + if (Consume(is, '}')) { + if (RAPIDJSON_UNLIKELY(!handler.EndObject(0))) // empty object + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + return; + } + + for (SizeType memberCount = 0;;) { + if (RAPIDJSON_UNLIKELY(is.Peek() != '"')) + RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); + + ParseString(is, handler, true); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + if (RAPIDJSON_UNLIKELY(!Consume(is, ':'))) + RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + ParseValue(is, handler); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + ++memberCount; + + switch (is.Peek()) { + case ',': + is.Take(); + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + break; + case '}': + is.Take(); + if (RAPIDJSON_UNLIKELY(!handler.EndObject(memberCount))) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + return; + default: + RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); break; // This useless break is only for making warning and coverage happy + } + + if (parseFlags & kParseTrailingCommasFlag) { + if (is.Peek() == '}') { + if (RAPIDJSON_UNLIKELY(!handler.EndObject(memberCount))) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + is.Take(); + return; + } + } + } + } + + // Parse array: [ value, ... ] + template + void ParseArray(InputStream& is, Handler& handler) { + RAPIDJSON_ASSERT(is.Peek() == '['); + is.Take(); // Skip '[' + + if (RAPIDJSON_UNLIKELY(!handler.StartArray())) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + if (Consume(is, ']')) { + if (RAPIDJSON_UNLIKELY(!handler.EndArray(0))) // empty array + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + return; + } + + for (SizeType elementCount = 0;;) { + ParseValue(is, handler); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + ++elementCount; + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + + if (Consume(is, ',')) { + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + } + else if (Consume(is, ']')) { + if (RAPIDJSON_UNLIKELY(!handler.EndArray(elementCount))) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + return; + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell()); + + if (parseFlags & kParseTrailingCommasFlag) { + if (is.Peek() == ']') { + if (RAPIDJSON_UNLIKELY(!handler.EndArray(elementCount))) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + is.Take(); + return; + } + } + } + } + + template + void ParseNull(InputStream& is, Handler& handler) { + RAPIDJSON_ASSERT(is.Peek() == 'n'); + is.Take(); + + if (RAPIDJSON_LIKELY(Consume(is, 'u') && Consume(is, 'l') && Consume(is, 'l'))) { + if (RAPIDJSON_UNLIKELY(!handler.Null())) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); + } + + template + void ParseTrue(InputStream& is, Handler& handler) { + RAPIDJSON_ASSERT(is.Peek() == 't'); + is.Take(); + + if (RAPIDJSON_LIKELY(Consume(is, 'r') && Consume(is, 'u') && Consume(is, 'e'))) { + if (RAPIDJSON_UNLIKELY(!handler.Bool(true))) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); + } + + template + void ParseFalse(InputStream& is, Handler& handler) { + RAPIDJSON_ASSERT(is.Peek() == 'f'); + is.Take(); + + if (RAPIDJSON_LIKELY(Consume(is, 'a') && Consume(is, 'l') && Consume(is, 's') && Consume(is, 'e'))) { + if (RAPIDJSON_UNLIKELY(!handler.Bool(false))) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); + } + + template + RAPIDJSON_FORCEINLINE static bool Consume(InputStream& is, typename InputStream::Ch expect) { + if (RAPIDJSON_LIKELY(is.Peek() == expect)) { + is.Take(); + return true; + } + else + return false; + } + + // Helper function to parse four hexadecimal digits in \uXXXX in ParseString(). + template + unsigned ParseHex4(InputStream& is, size_t escapeOffset) { + unsigned codepoint = 0; + for (int i = 0; i < 4; i++) { + Ch c = is.Peek(); + codepoint <<= 4; + codepoint += static_cast(c); + if (c >= '0' && c <= '9') + codepoint -= '0'; + else if (c >= 'A' && c <= 'F') + codepoint -= 'A' - 10; + else if (c >= 'a' && c <= 'f') + codepoint -= 'a' - 10; + else { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorStringUnicodeEscapeInvalidHex, escapeOffset); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0); + } + is.Take(); + } + return codepoint; + } + + template + class StackStream { + public: + typedef CharType Ch; + + StackStream(internal::Stack& stack) : stack_(stack), length_(0) {} + RAPIDJSON_FORCEINLINE void Put(Ch c) { + *stack_.template Push() = c; + ++length_; + } + + RAPIDJSON_FORCEINLINE void* Push(SizeType count) { + length_ += count; + return stack_.template Push(count); + } + + size_t Length() const { return length_; } + + Ch* Pop() { + return stack_.template Pop(length_); + } + + private: + StackStream(const StackStream&); + StackStream& operator=(const StackStream&); + + internal::Stack& stack_; + SizeType length_; + }; + + // Parse string and generate String event. Different code paths for kParseInsituFlag. + template + void ParseString(InputStream& is, Handler& handler, bool isKey = false) { + internal::StreamLocalCopy copy(is); + InputStream& s(copy.s); + + RAPIDJSON_ASSERT(s.Peek() == '\"'); + s.Take(); // Skip '\"' + + bool success = false; + if (parseFlags & kParseInsituFlag) { + typename InputStream::Ch *head = s.PutBegin(); + ParseStringToStream(s, s); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + size_t length = s.PutEnd(head) - 1; + RAPIDJSON_ASSERT(length <= 0xFFFFFFFF); + const typename TargetEncoding::Ch* const str = reinterpret_cast(head); + success = (isKey ? handler.Key(str, SizeType(length), false) : handler.String(str, SizeType(length), false)); + } + else { + StackStream stackStream(stack_); + ParseStringToStream(s, stackStream); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + SizeType length = static_cast(stackStream.Length()) - 1; + const typename TargetEncoding::Ch* const str = stackStream.Pop(); + success = (isKey ? handler.Key(str, length, true) : handler.String(str, length, true)); + } + if (RAPIDJSON_UNLIKELY(!success)) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, s.Tell()); + } + + // Parse string to an output is + // This function handles the prefix/suffix double quotes, escaping, and optional encoding validation. + template + RAPIDJSON_FORCEINLINE void ParseStringToStream(InputStream& is, OutputStream& os) { +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + static const char escape[256] = { + Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/', + Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, + 0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0, + 0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 + }; +#undef Z16 +//!@endcond + + for (;;) { + // Scan and copy string before "\\\"" or < 0x20. This is an optional optimization. + if (!(parseFlags & kParseValidateEncodingFlag)) + ScanCopyUnescapedString(is, os); + + Ch c = is.Peek(); + if (RAPIDJSON_UNLIKELY(c == '\\')) { // Escape + size_t escapeOffset = is.Tell(); // For invalid escaping, report the initial '\\' as error offset + is.Take(); + Ch e = is.Peek(); + if ((sizeof(Ch) == 1 || unsigned(e) < 256) && RAPIDJSON_LIKELY(escape[static_cast(e)])) { + is.Take(); + os.Put(static_cast(escape[static_cast(e)])); + } + else if ((parseFlags & kParseEscapedApostropheFlag) && RAPIDJSON_LIKELY(e == '\'')) { // Allow escaped apostrophe + is.Take(); + os.Put('\''); + } + else if (RAPIDJSON_LIKELY(e == 'u')) { // Unicode + is.Take(); + unsigned codepoint = ParseHex4(is, escapeOffset); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + if (RAPIDJSON_UNLIKELY(codepoint >= 0xD800 && codepoint <= 0xDFFF)) { + // high surrogate, check if followed by valid low surrogate + if (RAPIDJSON_LIKELY(codepoint <= 0xDBFF)) { + // Handle UTF-16 surrogate pair + if (RAPIDJSON_UNLIKELY(!Consume(is, '\\') || !Consume(is, 'u'))) + RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); + unsigned codepoint2 = ParseHex4(is, escapeOffset); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; + if (RAPIDJSON_UNLIKELY(codepoint2 < 0xDC00 || codepoint2 > 0xDFFF)) + RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); + codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000; + } + // single low surrogate + else + { + RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset); + } + } + TEncoding::Encode(os, codepoint); + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorStringEscapeInvalid, escapeOffset); + } + else if (RAPIDJSON_UNLIKELY(c == '"')) { // Closing double quote + is.Take(); + os.Put('\0'); // null-terminate the string + return; + } + else if (RAPIDJSON_UNLIKELY(static_cast(c) < 0x20)) { // RFC 4627: unescaped = %x20-21 / %x23-5B / %x5D-10FFFF + if (c == '\0') + RAPIDJSON_PARSE_ERROR(kParseErrorStringMissQuotationMark, is.Tell()); + else + RAPIDJSON_PARSE_ERROR(kParseErrorStringInvalidEncoding, is.Tell()); + } + else { + size_t offset = is.Tell(); + if (RAPIDJSON_UNLIKELY((parseFlags & kParseValidateEncodingFlag ? + !Transcoder::Validate(is, os) : + !Transcoder::Transcode(is, os)))) + RAPIDJSON_PARSE_ERROR(kParseErrorStringInvalidEncoding, offset); + } + } + } + + template + static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InputStream&, OutputStream&) { + // Do nothing for generic version + } + +#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) + // StringStream -> StackStream + static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(StringStream& is, StackStream& os) { + const char* p = is.src_; + + // Scan one by one until alignment (unaligned load may cross page boundary and cause crash) + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast(*p) < 0x20)) { + is.src_ = p; + return; + } + else + os.Put(*p++); + + // The rest of string using SIMD + static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' }; + static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' }; + static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F }; + const __m128i dq = _mm_loadu_si128(reinterpret_cast(&dquote[0])); + const __m128i bs = _mm_loadu_si128(reinterpret_cast(&bslash[0])); + const __m128i sp = _mm_loadu_si128(reinterpret_cast(&space[0])); + + for (;; p += 16) { + const __m128i s = _mm_load_si128(reinterpret_cast(p)); + const __m128i t1 = _mm_cmpeq_epi8(s, dq); + const __m128i t2 = _mm_cmpeq_epi8(s, bs); + const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F + const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3); + unsigned short r = static_cast(_mm_movemask_epi8(x)); + if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped + SizeType length; + #ifdef _MSC_VER // Find the index of first escaped + unsigned long offset; + _BitScanForward(&offset, r); + length = offset; + #else + length = static_cast(__builtin_ffs(r) - 1); + #endif + if (length != 0) { + char* q = reinterpret_cast(os.Push(length)); + for (size_t i = 0; i < length; i++) + q[i] = p[i]; + + p += length; + } + break; + } + _mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s); + } + + is.src_ = p; + } + + // InsituStringStream -> InsituStringStream + static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InsituStringStream& is, InsituStringStream& os) { + RAPIDJSON_ASSERT(&is == &os); + (void)os; + + if (is.src_ == is.dst_) { + SkipUnescapedString(is); + return; + } + + char* p = is.src_; + char *q = is.dst_; + + // Scan one by one until alignment (unaligned load may cross page boundary and cause crash) + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast(*p) < 0x20)) { + is.src_ = p; + is.dst_ = q; + return; + } + else + *q++ = *p++; + + // The rest of string using SIMD + static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' }; + static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' }; + static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F }; + const __m128i dq = _mm_loadu_si128(reinterpret_cast(&dquote[0])); + const __m128i bs = _mm_loadu_si128(reinterpret_cast(&bslash[0])); + const __m128i sp = _mm_loadu_si128(reinterpret_cast(&space[0])); + + for (;; p += 16, q += 16) { + const __m128i s = _mm_load_si128(reinterpret_cast(p)); + const __m128i t1 = _mm_cmpeq_epi8(s, dq); + const __m128i t2 = _mm_cmpeq_epi8(s, bs); + const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F + const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3); + unsigned short r = static_cast(_mm_movemask_epi8(x)); + if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped + size_t length; +#ifdef _MSC_VER // Find the index of first escaped + unsigned long offset; + _BitScanForward(&offset, r); + length = offset; +#else + length = static_cast(__builtin_ffs(r) - 1); +#endif + for (const char* pend = p + length; p != pend; ) + *q++ = *p++; + break; + } + _mm_storeu_si128(reinterpret_cast<__m128i *>(q), s); + } + + is.src_ = p; + is.dst_ = q; + } + + // When read/write pointers are the same for insitu stream, just skip unescaped characters + static RAPIDJSON_FORCEINLINE void SkipUnescapedString(InsituStringStream& is) { + RAPIDJSON_ASSERT(is.src_ == is.dst_); + char* p = is.src_; + + // Scan one by one until alignment (unaligned load may cross page boundary and cause crash) + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + for (; p != nextAligned; p++) + if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast(*p) < 0x20)) { + is.src_ = is.dst_ = p; + return; + } + + // The rest of string using SIMD + static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' }; + static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' }; + static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F }; + const __m128i dq = _mm_loadu_si128(reinterpret_cast(&dquote[0])); + const __m128i bs = _mm_loadu_si128(reinterpret_cast(&bslash[0])); + const __m128i sp = _mm_loadu_si128(reinterpret_cast(&space[0])); + + for (;; p += 16) { + const __m128i s = _mm_load_si128(reinterpret_cast(p)); + const __m128i t1 = _mm_cmpeq_epi8(s, dq); + const __m128i t2 = _mm_cmpeq_epi8(s, bs); + const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F + const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3); + unsigned short r = static_cast(_mm_movemask_epi8(x)); + if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped + size_t length; +#ifdef _MSC_VER // Find the index of first escaped + unsigned long offset; + _BitScanForward(&offset, r); + length = offset; +#else + length = static_cast(__builtin_ffs(r) - 1); +#endif + p += length; + break; + } + } + + is.src_ = is.dst_ = p; + } +#elif defined(RAPIDJSON_NEON) + // StringStream -> StackStream + static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(StringStream& is, StackStream& os) { + const char* p = is.src_; + + // Scan one by one until alignment (unaligned load may cross page boundary and cause crash) + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast(*p) < 0x20)) { + is.src_ = p; + return; + } + else + os.Put(*p++); + + // The rest of string using SIMD + const uint8x16_t s0 = vmovq_n_u8('"'); + const uint8x16_t s1 = vmovq_n_u8('\\'); + const uint8x16_t s2 = vmovq_n_u8('\b'); + const uint8x16_t s3 = vmovq_n_u8(32); + + for (;; p += 16) { + const uint8x16_t s = vld1q_u8(reinterpret_cast(p)); + uint8x16_t x = vceqq_u8(s, s0); + x = vorrq_u8(x, vceqq_u8(s, s1)); + x = vorrq_u8(x, vceqq_u8(s, s2)); + x = vorrq_u8(x, vcltq_u8(s, s3)); + + x = vrev64q_u8(x); // Rev in 64 + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract + + SizeType length = 0; + bool escaped = false; + if (low == 0) { + if (high != 0) { + uint32_t lz = internal::clzll(high); + length = 8 + (lz >> 3); + escaped = true; + } + } else { + uint32_t lz = internal::clzll(low); + length = lz >> 3; + escaped = true; + } + if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped + if (length != 0) { + char* q = reinterpret_cast(os.Push(length)); + for (size_t i = 0; i < length; i++) + q[i] = p[i]; + + p += length; + } + break; + } + vst1q_u8(reinterpret_cast(os.Push(16)), s); + } + + is.src_ = p; + } + + // InsituStringStream -> InsituStringStream + static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InsituStringStream& is, InsituStringStream& os) { + RAPIDJSON_ASSERT(&is == &os); + (void)os; + + if (is.src_ == is.dst_) { + SkipUnescapedString(is); + return; + } + + char* p = is.src_; + char *q = is.dst_; + + // Scan one by one until alignment (unaligned load may cross page boundary and cause crash) + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + while (p != nextAligned) + if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast(*p) < 0x20)) { + is.src_ = p; + is.dst_ = q; + return; + } + else + *q++ = *p++; + + // The rest of string using SIMD + const uint8x16_t s0 = vmovq_n_u8('"'); + const uint8x16_t s1 = vmovq_n_u8('\\'); + const uint8x16_t s2 = vmovq_n_u8('\b'); + const uint8x16_t s3 = vmovq_n_u8(32); + + for (;; p += 16, q += 16) { + const uint8x16_t s = vld1q_u8(reinterpret_cast(p)); + uint8x16_t x = vceqq_u8(s, s0); + x = vorrq_u8(x, vceqq_u8(s, s1)); + x = vorrq_u8(x, vceqq_u8(s, s2)); + x = vorrq_u8(x, vcltq_u8(s, s3)); + + x = vrev64q_u8(x); // Rev in 64 + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract + + SizeType length = 0; + bool escaped = false; + if (low == 0) { + if (high != 0) { + uint32_t lz = internal::clzll(high); + length = 8 + (lz >> 3); + escaped = true; + } + } else { + uint32_t lz = internal::clzll(low); + length = lz >> 3; + escaped = true; + } + if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped + for (const char* pend = p + length; p != pend; ) { + *q++ = *p++; + } + break; + } + vst1q_u8(reinterpret_cast(q), s); + } + + is.src_ = p; + is.dst_ = q; + } + + // When read/write pointers are the same for insitu stream, just skip unescaped characters + static RAPIDJSON_FORCEINLINE void SkipUnescapedString(InsituStringStream& is) { + RAPIDJSON_ASSERT(is.src_ == is.dst_); + char* p = is.src_; + + // Scan one by one until alignment (unaligned load may cross page boundary and cause crash) + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + for (; p != nextAligned; p++) + if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast(*p) < 0x20)) { + is.src_ = is.dst_ = p; + return; + } + + // The rest of string using SIMD + const uint8x16_t s0 = vmovq_n_u8('"'); + const uint8x16_t s1 = vmovq_n_u8('\\'); + const uint8x16_t s2 = vmovq_n_u8('\b'); + const uint8x16_t s3 = vmovq_n_u8(32); + + for (;; p += 16) { + const uint8x16_t s = vld1q_u8(reinterpret_cast(p)); + uint8x16_t x = vceqq_u8(s, s0); + x = vorrq_u8(x, vceqq_u8(s, s1)); + x = vorrq_u8(x, vceqq_u8(s, s2)); + x = vorrq_u8(x, vcltq_u8(s, s3)); + + x = vrev64q_u8(x); // Rev in 64 + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract + + if (low == 0) { + if (high != 0) { + uint32_t lz = internal::clzll(high); + p += 8 + (lz >> 3); + break; + } + } else { + uint32_t lz = internal::clzll(low); + p += lz >> 3; + break; + } + } + + is.src_ = is.dst_ = p; + } +#endif // RAPIDJSON_NEON + + template + class NumberStream; + + template + class NumberStream { + public: + typedef typename InputStream::Ch Ch; + + NumberStream(GenericReader& reader, InputStream& s) : is(s) { (void)reader; } + + RAPIDJSON_FORCEINLINE Ch Peek() const { return is.Peek(); } + RAPIDJSON_FORCEINLINE Ch TakePush() { return is.Take(); } + RAPIDJSON_FORCEINLINE Ch Take() { return is.Take(); } + RAPIDJSON_FORCEINLINE void Push(char) {} + + size_t Tell() { return is.Tell(); } + size_t Length() { return 0; } + const StackCharacter* Pop() { return 0; } + + protected: + NumberStream& operator=(const NumberStream&); + + InputStream& is; + }; + + template + class NumberStream : public NumberStream { + typedef NumberStream Base; + public: + NumberStream(GenericReader& reader, InputStream& s) : Base(reader, s), stackStream(reader.stack_) {} + + RAPIDJSON_FORCEINLINE Ch TakePush() { + stackStream.Put(static_cast(Base::is.Peek())); + return Base::is.Take(); + } + + RAPIDJSON_FORCEINLINE void Push(StackCharacter c) { + stackStream.Put(c); + } + + size_t Length() { return stackStream.Length(); } + + const StackCharacter* Pop() { + stackStream.Put('\0'); + return stackStream.Pop(); + } + + private: + StackStream stackStream; + }; + + template + class NumberStream : public NumberStream { + typedef NumberStream Base; + public: + NumberStream(GenericReader& reader, InputStream& s) : Base(reader, s) {} + + RAPIDJSON_FORCEINLINE Ch Take() { return Base::TakePush(); } + }; + + template + void ParseNumber(InputStream& is, Handler& handler) { + typedef typename internal::SelectIf, typename TargetEncoding::Ch, char>::Type NumberCharacter; + + internal::StreamLocalCopy copy(is); + NumberStream s(*this, copy.s); + + size_t startOffset = s.Tell(); + double d = 0.0; + bool useNanOrInf = false; + + // Parse minus + bool minus = Consume(s, '-'); + + // Parse int: zero / ( digit1-9 *DIGIT ) + unsigned i = 0; + uint64_t i64 = 0; + bool use64bit = false; + int significandDigit = 0; + if (RAPIDJSON_UNLIKELY(s.Peek() == '0')) { + i = 0; + s.TakePush(); + } + else if (RAPIDJSON_LIKELY(s.Peek() >= '1' && s.Peek() <= '9')) { + i = static_cast(s.TakePush() - '0'); + + if (minus) + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + if (RAPIDJSON_UNLIKELY(i >= 214748364)) { // 2^31 = 2147483648 + if (RAPIDJSON_LIKELY(i != 214748364 || s.Peek() > '8')) { + i64 = i; + use64bit = true; + break; + } + } + i = i * 10 + static_cast(s.TakePush() - '0'); + significandDigit++; + } + else + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + if (RAPIDJSON_UNLIKELY(i >= 429496729)) { // 2^32 - 1 = 4294967295 + if (RAPIDJSON_LIKELY(i != 429496729 || s.Peek() > '5')) { + i64 = i; + use64bit = true; + break; + } + } + i = i * 10 + static_cast(s.TakePush() - '0'); + significandDigit++; + } + } + // Parse NaN or Infinity here + else if ((parseFlags & kParseNanAndInfFlag) && RAPIDJSON_LIKELY((s.Peek() == 'I' || s.Peek() == 'N'))) { + if (Consume(s, 'N')) { + if (Consume(s, 'a') && Consume(s, 'N')) { + d = std::numeric_limits::quiet_NaN(); + useNanOrInf = true; + } + } + else if (RAPIDJSON_LIKELY(Consume(s, 'I'))) { + if (Consume(s, 'n') && Consume(s, 'f')) { + d = (minus ? -std::numeric_limits::infinity() : std::numeric_limits::infinity()); + useNanOrInf = true; + + if (RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n') + && Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y')))) { + RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell()); + } + } + } + + if (RAPIDJSON_UNLIKELY(!useNanOrInf)) { + RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell()); + } + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell()); + + // Parse 64bit int + bool useDouble = false; + if (use64bit) { + if (minus) + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + if (RAPIDJSON_UNLIKELY(i64 >= RAPIDJSON_UINT64_C2(0x0CCCCCCC, 0xCCCCCCCC))) // 2^63 = 9223372036854775808 + if (RAPIDJSON_LIKELY(i64 != RAPIDJSON_UINT64_C2(0x0CCCCCCC, 0xCCCCCCCC) || s.Peek() > '8')) { + d = static_cast(i64); + useDouble = true; + break; + } + i64 = i64 * 10 + static_cast(s.TakePush() - '0'); + significandDigit++; + } + else + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + if (RAPIDJSON_UNLIKELY(i64 >= RAPIDJSON_UINT64_C2(0x19999999, 0x99999999))) // 2^64 - 1 = 18446744073709551615 + if (RAPIDJSON_LIKELY(i64 != RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || s.Peek() > '5')) { + d = static_cast(i64); + useDouble = true; + break; + } + i64 = i64 * 10 + static_cast(s.TakePush() - '0'); + significandDigit++; + } + } + + // Force double for big integer + if (useDouble) { + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + d = d * 10 + (s.TakePush() - '0'); + } + } + + // Parse frac = decimal-point 1*DIGIT + int expFrac = 0; + size_t decimalPosition; + if (Consume(s, '.')) { + decimalPosition = s.Length(); + + if (RAPIDJSON_UNLIKELY(!(s.Peek() >= '0' && s.Peek() <= '9'))) + RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissFraction, s.Tell()); + + if (!useDouble) { +#if RAPIDJSON_64BIT + // Use i64 to store significand in 64-bit architecture + if (!use64bit) + i64 = i; + + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + if (i64 > RAPIDJSON_UINT64_C2(0x1FFFFF, 0xFFFFFFFF)) // 2^53 - 1 for fast path + break; + else { + i64 = i64 * 10 + static_cast(s.TakePush() - '0'); + --expFrac; + if (i64 != 0) + significandDigit++; + } + } + + d = static_cast(i64); +#else + // Use double to store significand in 32-bit architecture + d = static_cast(use64bit ? i64 : i); +#endif + useDouble = true; + } + + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + if (significandDigit < 17) { + d = d * 10.0 + (s.TakePush() - '0'); + --expFrac; + if (RAPIDJSON_LIKELY(d > 0.0)) + significandDigit++; + } + else + s.TakePush(); + } + } + else + decimalPosition = s.Length(); // decimal position at the end of integer. + + // Parse exp = e [ minus / plus ] 1*DIGIT + int exp = 0; + if (Consume(s, 'e') || Consume(s, 'E')) { + if (!useDouble) { + d = static_cast(use64bit ? i64 : i); + useDouble = true; + } + + bool expMinus = false; + if (Consume(s, '+')) + ; + else if (Consume(s, '-')) + expMinus = true; + + if (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + exp = static_cast(s.Take() - '0'); + if (expMinus) { + // (exp + expFrac) must not underflow int => we're detecting when -exp gets + // dangerously close to INT_MIN (a pessimistic next digit 9 would push it into + // underflow territory): + // + // -(exp * 10 + 9) + expFrac >= INT_MIN + // <=> exp <= (expFrac - INT_MIN - 9) / 10 + RAPIDJSON_ASSERT(expFrac <= 0); + int maxExp = (expFrac + 2147483639) / 10; + + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + exp = exp * 10 + static_cast(s.Take() - '0'); + if (RAPIDJSON_UNLIKELY(exp > maxExp)) { + while (RAPIDJSON_UNLIKELY(s.Peek() >= '0' && s.Peek() <= '9')) // Consume the rest of exponent + s.Take(); + } + } + } + else { // positive exp + int maxExp = 308 - expFrac; + while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { + exp = exp * 10 + static_cast(s.Take() - '0'); + if (RAPIDJSON_UNLIKELY(exp > maxExp)) + RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset); + } + } + } + else + RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissExponent, s.Tell()); + + if (expMinus) + exp = -exp; + } + + // Finish parsing, call event according to the type of number. + bool cont = true; + + if (parseFlags & kParseNumbersAsStringsFlag) { + if (parseFlags & kParseInsituFlag) { + s.Pop(); // Pop stack no matter if it will be used or not. + typename InputStream::Ch* head = is.PutBegin(); + const size_t length = s.Tell() - startOffset; + RAPIDJSON_ASSERT(length <= 0xFFFFFFFF); + // unable to insert the \0 character here, it will erase the comma after this number + const typename TargetEncoding::Ch* const str = reinterpret_cast(head); + cont = handler.RawNumber(str, SizeType(length), false); + } + else { + SizeType numCharsToCopy = static_cast(s.Length()); + GenericStringStream > srcStream(s.Pop()); + StackStream dstStream(stack_); + while (numCharsToCopy--) { + Transcoder, TargetEncoding>::Transcode(srcStream, dstStream); + } + dstStream.Put('\0'); + const typename TargetEncoding::Ch* str = dstStream.Pop(); + const SizeType length = static_cast(dstStream.Length()) - 1; + cont = handler.RawNumber(str, SizeType(length), true); + } + } + else { + size_t length = s.Length(); + const NumberCharacter* decimal = s.Pop(); // Pop stack no matter if it will be used or not. + + if (useDouble) { + int p = exp + expFrac; + if (parseFlags & kParseFullPrecisionFlag) + d = internal::StrtodFullPrecision(d, p, decimal, length, decimalPosition, exp); + else + d = internal::StrtodNormalPrecision(d, p); + + // Use > max, instead of == inf, to fix bogus warning -Wfloat-equal + if (d > (std::numeric_limits::max)()) { + // Overflow + // TODO: internal::StrtodX should report overflow (or underflow) + RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset); + } + + cont = handler.Double(minus ? -d : d); + } + else if (useNanOrInf) { + cont = handler.Double(d); + } + else { + if (use64bit) { + if (minus) + cont = handler.Int64(static_cast(~i64 + 1)); + else + cont = handler.Uint64(i64); + } + else { + if (minus) + cont = handler.Int(static_cast(~i + 1)); + else + cont = handler.Uint(i); + } + } + } + if (RAPIDJSON_UNLIKELY(!cont)) + RAPIDJSON_PARSE_ERROR(kParseErrorTermination, startOffset); + } + + // Parse any JSON value + template + void ParseValue(InputStream& is, Handler& handler) { + switch (is.Peek()) { + case 'n': ParseNull (is, handler); break; + case 't': ParseTrue (is, handler); break; + case 'f': ParseFalse (is, handler); break; + case '"': ParseString(is, handler); break; + case '{': ParseObject(is, handler); break; + case '[': ParseArray (is, handler); break; + default : + ParseNumber(is, handler); + break; + + } + } + + // Iterative Parsing + + // States + enum IterativeParsingState { + IterativeParsingFinishState = 0, // sink states at top + IterativeParsingErrorState, // sink states at top + IterativeParsingStartState, + + // Object states + IterativeParsingObjectInitialState, + IterativeParsingMemberKeyState, + IterativeParsingMemberValueState, + IterativeParsingObjectFinishState, + + // Array states + IterativeParsingArrayInitialState, + IterativeParsingElementState, + IterativeParsingArrayFinishState, + + // Single value state + IterativeParsingValueState, + + // Delimiter states (at bottom) + IterativeParsingElementDelimiterState, + IterativeParsingMemberDelimiterState, + IterativeParsingKeyValueDelimiterState, + + cIterativeParsingStateCount + }; + + // Tokens + enum Token { + LeftBracketToken = 0, + RightBracketToken, + + LeftCurlyBracketToken, + RightCurlyBracketToken, + + CommaToken, + ColonToken, + + StringToken, + FalseToken, + TrueToken, + NullToken, + NumberToken, + + kTokenCount + }; + + RAPIDJSON_FORCEINLINE Token Tokenize(Ch c) const { + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +#define N NumberToken +#define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N + // Maps from ASCII to Token + static const unsigned char tokenMap[256] = { + N16, // 00~0F + N16, // 10~1F + N, N, StringToken, N, N, N, N, N, N, N, N, N, CommaToken, N, N, N, // 20~2F + N, N, N, N, N, N, N, N, N, N, ColonToken, N, N, N, N, N, // 30~3F + N16, // 40~4F + N, N, N, N, N, N, N, N, N, N, N, LeftBracketToken, N, RightBracketToken, N, N, // 50~5F + N, N, N, N, N, N, FalseToken, N, N, N, N, N, N, N, NullToken, N, // 60~6F + N, N, N, N, TrueToken, N, N, N, N, N, N, LeftCurlyBracketToken, N, RightCurlyBracketToken, N, N, // 70~7F + N16, N16, N16, N16, N16, N16, N16, N16 // 80~FF + }; +#undef N +#undef N16 +//!@endcond + + if (sizeof(Ch) == 1 || static_cast(c) < 256) + return static_cast(tokenMap[static_cast(c)]); + else + return NumberToken; + } + + RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token) const { + // current state x one lookahead token -> new state + static const char G[cIterativeParsingStateCount][kTokenCount] = { + // Finish(sink state) + { + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState + }, + // Error(sink state) + { + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState + }, + // Start + { + IterativeParsingArrayInitialState, // Left bracket + IterativeParsingErrorState, // Right bracket + IterativeParsingObjectInitialState, // Left curly bracket + IterativeParsingErrorState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingValueState, // String + IterativeParsingValueState, // False + IterativeParsingValueState, // True + IterativeParsingValueState, // Null + IterativeParsingValueState // Number + }, + // ObjectInitial + { + IterativeParsingErrorState, // Left bracket + IterativeParsingErrorState, // Right bracket + IterativeParsingErrorState, // Left curly bracket + IterativeParsingObjectFinishState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingMemberKeyState, // String + IterativeParsingErrorState, // False + IterativeParsingErrorState, // True + IterativeParsingErrorState, // Null + IterativeParsingErrorState // Number + }, + // MemberKey + { + IterativeParsingErrorState, // Left bracket + IterativeParsingErrorState, // Right bracket + IterativeParsingErrorState, // Left curly bracket + IterativeParsingErrorState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingKeyValueDelimiterState, // Colon + IterativeParsingErrorState, // String + IterativeParsingErrorState, // False + IterativeParsingErrorState, // True + IterativeParsingErrorState, // Null + IterativeParsingErrorState // Number + }, + // MemberValue + { + IterativeParsingErrorState, // Left bracket + IterativeParsingErrorState, // Right bracket + IterativeParsingErrorState, // Left curly bracket + IterativeParsingObjectFinishState, // Right curly bracket + IterativeParsingMemberDelimiterState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingErrorState, // String + IterativeParsingErrorState, // False + IterativeParsingErrorState, // True + IterativeParsingErrorState, // Null + IterativeParsingErrorState // Number + }, + // ObjectFinish(sink state) + { + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState + }, + // ArrayInitial + { + IterativeParsingArrayInitialState, // Left bracket(push Element state) + IterativeParsingArrayFinishState, // Right bracket + IterativeParsingObjectInitialState, // Left curly bracket(push Element state) + IterativeParsingErrorState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingElementState, // String + IterativeParsingElementState, // False + IterativeParsingElementState, // True + IterativeParsingElementState, // Null + IterativeParsingElementState // Number + }, + // Element + { + IterativeParsingErrorState, // Left bracket + IterativeParsingArrayFinishState, // Right bracket + IterativeParsingErrorState, // Left curly bracket + IterativeParsingErrorState, // Right curly bracket + IterativeParsingElementDelimiterState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingErrorState, // String + IterativeParsingErrorState, // False + IterativeParsingErrorState, // True + IterativeParsingErrorState, // Null + IterativeParsingErrorState // Number + }, + // ArrayFinish(sink state) + { + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState + }, + // Single Value (sink state) + { + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, + IterativeParsingErrorState + }, + // ElementDelimiter + { + IterativeParsingArrayInitialState, // Left bracket(push Element state) + IterativeParsingArrayFinishState, // Right bracket + IterativeParsingObjectInitialState, // Left curly bracket(push Element state) + IterativeParsingErrorState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingElementState, // String + IterativeParsingElementState, // False + IterativeParsingElementState, // True + IterativeParsingElementState, // Null + IterativeParsingElementState // Number + }, + // MemberDelimiter + { + IterativeParsingErrorState, // Left bracket + IterativeParsingErrorState, // Right bracket + IterativeParsingErrorState, // Left curly bracket + IterativeParsingObjectFinishState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingMemberKeyState, // String + IterativeParsingErrorState, // False + IterativeParsingErrorState, // True + IterativeParsingErrorState, // Null + IterativeParsingErrorState // Number + }, + // KeyValueDelimiter + { + IterativeParsingArrayInitialState, // Left bracket(push MemberValue state) + IterativeParsingErrorState, // Right bracket + IterativeParsingObjectInitialState, // Left curly bracket(push MemberValue state) + IterativeParsingErrorState, // Right curly bracket + IterativeParsingErrorState, // Comma + IterativeParsingErrorState, // Colon + IterativeParsingMemberValueState, // String + IterativeParsingMemberValueState, // False + IterativeParsingMemberValueState, // True + IterativeParsingMemberValueState, // Null + IterativeParsingMemberValueState // Number + }, + }; // End of G + + return static_cast(G[state][token]); + } + + // Make an advance in the token stream and state based on the candidate destination state which was returned by Transit(). + // May return a new state on state pop. + template + RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream& is, Handler& handler) { + (void)token; + + switch (dst) { + case IterativeParsingErrorState: + return dst; + + case IterativeParsingObjectInitialState: + case IterativeParsingArrayInitialState: + { + // Push the state(Element or MemberValue) if we are nested in another array or value of member. + // In this way we can get the correct state on ObjectFinish or ArrayFinish by frame pop. + IterativeParsingState n = src; + if (src == IterativeParsingArrayInitialState || src == IterativeParsingElementDelimiterState) + n = IterativeParsingElementState; + else if (src == IterativeParsingKeyValueDelimiterState) + n = IterativeParsingMemberValueState; + // Push current state. + *stack_.template Push(1) = n; + // Initialize and push the member/element count. + *stack_.template Push(1) = 0; + // Call handler + bool hr = (dst == IterativeParsingObjectInitialState) ? handler.StartObject() : handler.StartArray(); + // On handler short circuits the parsing. + if (!hr) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorTermination, is.Tell()); + return IterativeParsingErrorState; + } + else { + is.Take(); + return dst; + } + } + + case IterativeParsingMemberKeyState: + ParseString(is, handler, true); + if (HasParseError()) + return IterativeParsingErrorState; + else + return dst; + + case IterativeParsingKeyValueDelimiterState: + RAPIDJSON_ASSERT(token == ColonToken); + is.Take(); + return dst; + + case IterativeParsingMemberValueState: + // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state. + ParseValue(is, handler); + if (HasParseError()) { + return IterativeParsingErrorState; + } + return dst; + + case IterativeParsingElementState: + // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state. + ParseValue(is, handler); + if (HasParseError()) { + return IterativeParsingErrorState; + } + return dst; + + case IterativeParsingMemberDelimiterState: + case IterativeParsingElementDelimiterState: + is.Take(); + // Update member/element count. + *stack_.template Top() = *stack_.template Top() + 1; + return dst; + + case IterativeParsingObjectFinishState: + { + // Transit from delimiter is only allowed when trailing commas are enabled + if (!(parseFlags & kParseTrailingCommasFlag) && src == IterativeParsingMemberDelimiterState) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorObjectMissName, is.Tell()); + return IterativeParsingErrorState; + } + // Get member count. + SizeType c = *stack_.template Pop(1); + // If the object is not empty, count the last member. + if (src == IterativeParsingMemberValueState) + ++c; + // Restore the state. + IterativeParsingState n = static_cast(*stack_.template Pop(1)); + // Transit to Finish state if this is the topmost scope. + if (n == IterativeParsingStartState) + n = IterativeParsingFinishState; + // Call handler + bool hr = handler.EndObject(c); + // On handler short circuits the parsing. + if (!hr) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorTermination, is.Tell()); + return IterativeParsingErrorState; + } + else { + is.Take(); + return n; + } + } + + case IterativeParsingArrayFinishState: + { + // Transit from delimiter is only allowed when trailing commas are enabled + if (!(parseFlags & kParseTrailingCommasFlag) && src == IterativeParsingElementDelimiterState) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorValueInvalid, is.Tell()); + return IterativeParsingErrorState; + } + // Get element count. + SizeType c = *stack_.template Pop(1); + // If the array is not empty, count the last element. + if (src == IterativeParsingElementState) + ++c; + // Restore the state. + IterativeParsingState n = static_cast(*stack_.template Pop(1)); + // Transit to Finish state if this is the topmost scope. + if (n == IterativeParsingStartState) + n = IterativeParsingFinishState; + // Call handler + bool hr = handler.EndArray(c); + // On handler short circuits the parsing. + if (!hr) { + RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorTermination, is.Tell()); + return IterativeParsingErrorState; + } + else { + is.Take(); + return n; + } + } + + default: + // This branch is for IterativeParsingValueState actually. + // Use `default:` rather than + // `case IterativeParsingValueState:` is for code coverage. + + // The IterativeParsingStartState is not enumerated in this switch-case. + // It is impossible for that case. And it can be caught by following assertion. + + // The IterativeParsingFinishState is not enumerated in this switch-case either. + // It is a "derivative" state which cannot triggered from Predict() directly. + // Therefore it cannot happen here. And it can be caught by following assertion. + RAPIDJSON_ASSERT(dst == IterativeParsingValueState); + + // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state. + ParseValue(is, handler); + if (HasParseError()) { + return IterativeParsingErrorState; + } + return IterativeParsingFinishState; + } + } + + template + void HandleError(IterativeParsingState src, InputStream& is) { + if (HasParseError()) { + // Error flag has been set. + return; + } + + switch (src) { + case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell()); return; + case IterativeParsingFinishState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell()); return; + case IterativeParsingObjectInitialState: + case IterativeParsingMemberDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); return; + case IterativeParsingMemberKeyState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); return; + case IterativeParsingMemberValueState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); return; + case IterativeParsingKeyValueDelimiterState: + case IterativeParsingArrayInitialState: + case IterativeParsingElementDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); return; + default: RAPIDJSON_ASSERT(src == IterativeParsingElementState); RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell()); return; + } + } + + RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const { + return s >= IterativeParsingElementDelimiterState; + } + + RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) const { + return s <= IterativeParsingErrorState; + } + + template + ParseResult IterativeParse(InputStream& is, Handler& handler) { + parseResult_.Clear(); + ClearStackOnExit scope(*this); + IterativeParsingState state = IterativeParsingStartState; + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + while (is.Peek() != '\0') { + Token t = Tokenize(is.Peek()); + IterativeParsingState n = Predict(state, t); + IterativeParsingState d = Transit(state, t, n, is, handler); + + if (d == IterativeParsingErrorState) { + HandleError(state, is); + break; + } + + state = d; + + // Do not further consume streams if a root JSON has been parsed. + if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState) + break; + + SkipWhitespaceAndComments(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); + } + + // Handle the end of file. + if (state != IterativeParsingFinishState) + HandleError(state, is); + + return parseResult_; + } + + static const size_t kDefaultStackCapacity = 256; //!< Default stack capacity in bytes for storing a single decoded string. + internal::Stack stack_; //!< A stack for storing decoded string temporarily during non-destructive parsing. + ParseResult parseResult_; + IterativeParsingState state_; +}; // class GenericReader + +//! Reader with UTF8 encoding and default allocator. +typedef GenericReader, UTF8<> > Reader; + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) || defined(_MSC_VER) +RAPIDJSON_DIAG_POP +#endif + + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_READER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/schema.h b/components/thorvg-main/src/loaders/lottie/rapidjson/schema.h new file mode 100644 index 0000000..fea254e --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/schema.h @@ -0,0 +1,3262 @@ +// Tencent is pleased to support the open source community by making RapidJSON available-> +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip-> All rights reserved-> +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License-> You may obtain a copy of the License at +// +// http://opensource->org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied-> See the License for the +// specific language governing permissions and limitations under the License-> + +#ifndef RAPIDJSON_SCHEMA_H_ +#define RAPIDJSON_SCHEMA_H_ + +#include "document.h" +#include "pointer.h" +#include "stringbuffer.h" +#include "error/en.h" +#include "uri.h" +#include // abs, floor + +#if !defined(RAPIDJSON_SCHEMA_USE_INTERNALREGEX) +#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1 +#else +#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 0 +#endif + +#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) +#define RAPIDJSON_SCHEMA_USE_STDREGEX 1 +#else +#define RAPIDJSON_SCHEMA_USE_STDREGEX 0 +#endif + +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX +#include "internal/regex.h" +#elif RAPIDJSON_SCHEMA_USE_STDREGEX +#include +#endif + +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX || RAPIDJSON_SCHEMA_USE_STDREGEX +#define RAPIDJSON_SCHEMA_HAS_REGEX 1 +#else +#define RAPIDJSON_SCHEMA_HAS_REGEX 0 +#endif + +#ifndef RAPIDJSON_SCHEMA_VERBOSE +#define RAPIDJSON_SCHEMA_VERBOSE 0 +#endif + +RAPIDJSON_DIAG_PUSH + +#if defined(__GNUC__) +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_OFF(weak-vtables) +RAPIDJSON_DIAG_OFF(exit-time-destructors) +RAPIDJSON_DIAG_OFF(c++98-compat-pedantic) +RAPIDJSON_DIAG_OFF(variadic-macros) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// Verbose Utilities + +#if RAPIDJSON_SCHEMA_VERBOSE + +namespace internal { + +inline void PrintInvalidKeywordData(const char* keyword) { + printf(" Fail keyword: '%s'\n", keyword); +} + +inline void PrintInvalidKeywordData(const wchar_t* keyword) { + wprintf(L" Fail keyword: '%ls'\n", keyword); +} + +inline void PrintInvalidDocumentData(const char* document) { + printf(" Fail document: '%s'\n", document); +} + +inline void PrintInvalidDocumentData(const wchar_t* document) { + wprintf(L" Fail document: '%ls'\n", document); +} + +inline void PrintValidatorPointersData(const char* s, const char* d, unsigned depth) { + printf(" Sch: %*s'%s'\n Doc: %*s'%s'\n", depth * 4, " ", s, depth * 4, " ", d); +} + +inline void PrintValidatorPointersData(const wchar_t* s, const wchar_t* d, unsigned depth) { + wprintf(L" Sch: %*ls'%ls'\n Doc: %*ls'%ls'\n", depth * 4, L" ", s, depth * 4, L" ", d); +} + +inline void PrintSchemaIdsData(const char* base, const char* local, const char* resolved) { + printf(" Resolving id: Base: '%s', Local: '%s', Resolved: '%s'\n", base, local, resolved); +} + +inline void PrintSchemaIdsData(const wchar_t* base, const wchar_t* local, const wchar_t* resolved) { + wprintf(L" Resolving id: Base: '%ls', Local: '%ls', Resolved: '%ls'\n", base, local, resolved); +} + +inline void PrintMethodData(const char* method) { + printf("%s\n", method); +} + +inline void PrintMethodData(const char* method, bool b) { + printf("%s, Data: '%s'\n", method, b ? "true" : "false"); +} + +inline void PrintMethodData(const char* method, int64_t i) { + printf("%s, Data: '%" PRId64 "'\n", method, i); +} + +inline void PrintMethodData(const char* method, uint64_t u) { + printf("%s, Data: '%" PRIu64 "'\n", method, u); +} + +inline void PrintMethodData(const char* method, double d) { + printf("%s, Data: '%lf'\n", method, d); +} + +inline void PrintMethodData(const char* method, const char* s) { + printf("%s, Data: '%s'\n", method, s); +} + +inline void PrintMethodData(const char* method, const wchar_t* s) { + wprintf(L"%hs, Data: '%ls'\n", method, s); +} + +inline void PrintMethodData(const char* method, const char* s1, const char* s2) { + printf("%s, Data: '%s', '%s'\n", method, s1, s2); +} + +inline void PrintMethodData(const char* method, const wchar_t* s1, const wchar_t* s2) { + wprintf(L"%hs, Data: '%ls', '%ls'\n", method, s1, s2); +} + +} // namespace internal + +#endif // RAPIDJSON_SCHEMA_VERBOSE + +#ifndef RAPIDJSON_SCHEMA_PRINT +#if RAPIDJSON_SCHEMA_VERBOSE +#define RAPIDJSON_SCHEMA_PRINT(name, ...) internal::Print##name##Data(__VA_ARGS__) +#else +#define RAPIDJSON_SCHEMA_PRINT(name, ...) +#endif +#endif + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_INVALID_KEYWORD_RETURN + +#define RAPIDJSON_INVALID_KEYWORD_RETURN(code)\ +RAPIDJSON_MULTILINEMACRO_BEGIN\ + context.invalidCode = code;\ + context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString();\ + RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, context.invalidKeyword);\ + return false;\ +RAPIDJSON_MULTILINEMACRO_END + +/////////////////////////////////////////////////////////////////////////////// +// ValidateFlag + +/*! \def RAPIDJSON_VALIDATE_DEFAULT_FLAGS + \ingroup RAPIDJSON_CONFIG + \brief User-defined kValidateDefaultFlags definition. + + User can define this as any \c ValidateFlag combinations. +*/ +#ifndef RAPIDJSON_VALIDATE_DEFAULT_FLAGS +#define RAPIDJSON_VALIDATE_DEFAULT_FLAGS kValidateNoFlags +#endif + +//! Combination of validate flags +/*! \see + */ +enum ValidateFlag { + kValidateNoFlags = 0, //!< No flags are set. + kValidateContinueOnErrorFlag = 1, //!< Don't stop after first validation error. + kValidateReadFlag = 2, //!< Validation is for a read semantic. + kValidateWriteFlag = 4, //!< Validation is for a write semantic. + kValidateDefaultFlags = RAPIDJSON_VALIDATE_DEFAULT_FLAGS //!< Default validate flags. Can be customized by defining RAPIDJSON_VALIDATE_DEFAULT_FLAGS +}; + +/////////////////////////////////////////////////////////////////////////////// +// Specification +enum SchemaDraft { + kDraftUnknown = -1, + kDraftNone = 0, + kDraft03 = 3, + kDraftMin = 4, //!< Current minimum supported draft + kDraft04 = 4, + kDraft05 = 5, + kDraftMax = 5, //!< Current maximum supported draft + kDraft06 = 6, + kDraft07 = 7, + kDraft2019_09 = 8, + kDraft2020_12 = 9 +}; + +enum OpenApiVersion { + kVersionUnknown = -1, + kVersionNone = 0, + kVersionMin = 2, //!< Current minimum supported version + kVersion20 = 2, + kVersion30 = 3, + kVersionMax = 3, //!< Current maximum supported version + kVersion31 = 4, +}; + +struct Specification { + Specification(SchemaDraft d) : draft(d), oapi(kVersionNone) {} + Specification(OpenApiVersion o) : oapi(o) { + if (oapi == kVersion20) draft = kDraft04; + else if (oapi == kVersion30) draft = kDraft05; + else if (oapi == kVersion31) draft = kDraft2020_12; + else draft = kDraft04; + } + ~Specification() {} + bool IsSupported() const { + return ((draft >= kDraftMin && draft <= kDraftMax) && ((oapi == kVersionNone) || (oapi >= kVersionMin && oapi <= kVersionMax))); + } + SchemaDraft draft; + OpenApiVersion oapi; +}; + +/////////////////////////////////////////////////////////////////////////////// +// Forward declarations + +template +class GenericSchemaDocument; + +namespace internal { + +template +class Schema; + +/////////////////////////////////////////////////////////////////////////////// +// ISchemaValidator + +class ISchemaValidator { +public: + virtual ~ISchemaValidator() {} + virtual bool IsValid() const = 0; + virtual void SetValidateFlags(unsigned flags) = 0; + virtual unsigned GetValidateFlags() const = 0; +}; + +/////////////////////////////////////////////////////////////////////////////// +// ISchemaStateFactory + +template +class ISchemaStateFactory { +public: + virtual ~ISchemaStateFactory() {} + virtual ISchemaValidator* CreateSchemaValidator(const SchemaType&, const bool inheritContinueOnErrors) = 0; + virtual void DestroySchemaValidator(ISchemaValidator* validator) = 0; + virtual void* CreateHasher() = 0; + virtual uint64_t GetHashCode(void* hasher) = 0; + virtual void DestroyHasher(void* hasher) = 0; + virtual void* MallocState(size_t size) = 0; + virtual void FreeState(void* p) = 0; +}; + +/////////////////////////////////////////////////////////////////////////////// +// IValidationErrorHandler + +template +class IValidationErrorHandler { +public: + typedef typename SchemaType::Ch Ch; + typedef typename SchemaType::SValue SValue; + + virtual ~IValidationErrorHandler() {} + + virtual void NotMultipleOf(int64_t actual, const SValue& expected) = 0; + virtual void NotMultipleOf(uint64_t actual, const SValue& expected) = 0; + virtual void NotMultipleOf(double actual, const SValue& expected) = 0; + virtual void AboveMaximum(int64_t actual, const SValue& expected, bool exclusive) = 0; + virtual void AboveMaximum(uint64_t actual, const SValue& expected, bool exclusive) = 0; + virtual void AboveMaximum(double actual, const SValue& expected, bool exclusive) = 0; + virtual void BelowMinimum(int64_t actual, const SValue& expected, bool exclusive) = 0; + virtual void BelowMinimum(uint64_t actual, const SValue& expected, bool exclusive) = 0; + virtual void BelowMinimum(double actual, const SValue& expected, bool exclusive) = 0; + + virtual void TooLong(const Ch* str, SizeType length, SizeType expected) = 0; + virtual void TooShort(const Ch* str, SizeType length, SizeType expected) = 0; + virtual void DoesNotMatch(const Ch* str, SizeType length) = 0; + + virtual void DisallowedItem(SizeType index) = 0; + virtual void TooFewItems(SizeType actualCount, SizeType expectedCount) = 0; + virtual void TooManyItems(SizeType actualCount, SizeType expectedCount) = 0; + virtual void DuplicateItems(SizeType index1, SizeType index2) = 0; + + virtual void TooManyProperties(SizeType actualCount, SizeType expectedCount) = 0; + virtual void TooFewProperties(SizeType actualCount, SizeType expectedCount) = 0; + virtual void StartMissingProperties() = 0; + virtual void AddMissingProperty(const SValue& name) = 0; + virtual bool EndMissingProperties() = 0; + virtual void PropertyViolations(ISchemaValidator** subvalidators, SizeType count) = 0; + virtual void DisallowedProperty(const Ch* name, SizeType length) = 0; + + virtual void StartDependencyErrors() = 0; + virtual void StartMissingDependentProperties() = 0; + virtual void AddMissingDependentProperty(const SValue& targetName) = 0; + virtual void EndMissingDependentProperties(const SValue& sourceName) = 0; + virtual void AddDependencySchemaError(const SValue& sourceName, ISchemaValidator* subvalidator) = 0; + virtual bool EndDependencyErrors() = 0; + + virtual void DisallowedValue(const ValidateErrorCode code) = 0; + virtual void StartDisallowedType() = 0; + virtual void AddExpectedType(const typename SchemaType::ValueType& expectedType) = 0; + virtual void EndDisallowedType(const typename SchemaType::ValueType& actualType) = 0; + virtual void NotAllOf(ISchemaValidator** subvalidators, SizeType count) = 0; + virtual void NoneOf(ISchemaValidator** subvalidators, SizeType count) = 0; + virtual void NotOneOf(ISchemaValidator** subvalidators, SizeType count) = 0; + virtual void MultipleOneOf(SizeType index1, SizeType index2) = 0; + virtual void Disallowed() = 0; + virtual void DisallowedWhenWriting() = 0; + virtual void DisallowedWhenReading() = 0; +}; + + +/////////////////////////////////////////////////////////////////////////////// +// Hasher + +// For comparison of compound value +template +class Hasher { +public: + typedef typename Encoding::Ch Ch; + + Hasher(Allocator* allocator = 0, size_t stackCapacity = kDefaultSize) : stack_(allocator, stackCapacity) {} + + bool Null() { return WriteType(kNullType); } + bool Bool(bool b) { return WriteType(b ? kTrueType : kFalseType); } + bool Int(int i) { Number n; n.u.i = i; n.d = static_cast(i); return WriteNumber(n); } + bool Uint(unsigned u) { Number n; n.u.u = u; n.d = static_cast(u); return WriteNumber(n); } + bool Int64(int64_t i) { Number n; n.u.i = i; n.d = static_cast(i); return WriteNumber(n); } + bool Uint64(uint64_t u) { Number n; n.u.u = u; n.d = static_cast(u); return WriteNumber(n); } + bool Double(double d) { + Number n; + if (d < 0) n.u.i = static_cast(d); + else n.u.u = static_cast(d); + n.d = d; + return WriteNumber(n); + } + + bool RawNumber(const Ch* str, SizeType len, bool) { + WriteBuffer(kNumberType, str, len * sizeof(Ch)); + return true; + } + + bool String(const Ch* str, SizeType len, bool) { + WriteBuffer(kStringType, str, len * sizeof(Ch)); + return true; + } + + bool StartObject() { return true; } + bool Key(const Ch* str, SizeType len, bool copy) { return String(str, len, copy); } + bool EndObject(SizeType memberCount) { + uint64_t h = Hash(0, kObjectType); + uint64_t* kv = stack_.template Pop(memberCount * 2); + for (SizeType i = 0; i < memberCount; i++) + h ^= Hash(kv[i * 2], kv[i * 2 + 1]); // Use xor to achieve member order insensitive + *stack_.template Push() = h; + return true; + } + + bool StartArray() { return true; } + bool EndArray(SizeType elementCount) { + uint64_t h = Hash(0, kArrayType); + uint64_t* e = stack_.template Pop(elementCount); + for (SizeType i = 0; i < elementCount; i++) + h = Hash(h, e[i]); // Use hash to achieve element order sensitive + *stack_.template Push() = h; + return true; + } + + bool IsValid() const { return stack_.GetSize() == sizeof(uint64_t); } + + uint64_t GetHashCode() const { + RAPIDJSON_ASSERT(IsValid()); + return *stack_.template Top(); + } + +private: + static const size_t kDefaultSize = 256; + struct Number { + union U { + uint64_t u; + int64_t i; + }u; + double d; + }; + + bool WriteType(Type type) { return WriteBuffer(type, 0, 0); } + + bool WriteNumber(const Number& n) { return WriteBuffer(kNumberType, &n, sizeof(n)); } + + bool WriteBuffer(Type type, const void* data, size_t len) { + // FNV-1a from http://isthe.com/chongo/tech/comp/fnv/ + uint64_t h = Hash(RAPIDJSON_UINT64_C2(0x84222325, 0xcbf29ce4), type); + const unsigned char* d = static_cast(data); + for (size_t i = 0; i < len; i++) + h = Hash(h, d[i]); + *stack_.template Push() = h; + return true; + } + + static uint64_t Hash(uint64_t h, uint64_t d) { + static const uint64_t kPrime = RAPIDJSON_UINT64_C2(0x00000100, 0x000001b3); + h ^= d; + h *= kPrime; + return h; + } + + Stack stack_; +}; + +/////////////////////////////////////////////////////////////////////////////// +// SchemaValidationContext + +template +struct SchemaValidationContext { + typedef Schema SchemaType; + typedef ISchemaStateFactory SchemaValidatorFactoryType; + typedef IValidationErrorHandler ErrorHandlerType; + typedef typename SchemaType::ValueType ValueType; + typedef typename ValueType::Ch Ch; + + enum PatternValidatorType { + kPatternValidatorOnly, + kPatternValidatorWithProperty, + kPatternValidatorWithAdditionalProperty + }; + + SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s, unsigned fl = 0) : + factory(f), + error_handler(eh), + schema(s), + flags(fl), + valueSchema(), + invalidKeyword(), + invalidCode(), + hasher(), + arrayElementHashCodes(), + validators(), + validatorCount(), + patternPropertiesValidators(), + patternPropertiesValidatorCount(), + patternPropertiesSchemas(), + patternPropertiesSchemaCount(), + valuePatternValidatorType(kPatternValidatorOnly), + propertyExist(), + inArray(false), + valueUniqueness(false), + arrayUniqueness(false) + { + } + + ~SchemaValidationContext() { + if (hasher) + factory.DestroyHasher(hasher); + if (validators) { + for (SizeType i = 0; i < validatorCount; i++) { + if (validators[i]) { + factory.DestroySchemaValidator(validators[i]); + } + } + factory.FreeState(validators); + } + if (patternPropertiesValidators) { + for (SizeType i = 0; i < patternPropertiesValidatorCount; i++) { + if (patternPropertiesValidators[i]) { + factory.DestroySchemaValidator(patternPropertiesValidators[i]); + } + } + factory.FreeState(patternPropertiesValidators); + } + if (patternPropertiesSchemas) + factory.FreeState(patternPropertiesSchemas); + if (propertyExist) + factory.FreeState(propertyExist); + } + + SchemaValidatorFactoryType& factory; + ErrorHandlerType& error_handler; + const SchemaType* schema; + unsigned flags; + const SchemaType* valueSchema; + const Ch* invalidKeyword; + ValidateErrorCode invalidCode; + void* hasher; // Only validator access + void* arrayElementHashCodes; // Only validator access this + ISchemaValidator** validators; + SizeType validatorCount; + ISchemaValidator** patternPropertiesValidators; + SizeType patternPropertiesValidatorCount; + const SchemaType** patternPropertiesSchemas; + SizeType patternPropertiesSchemaCount; + PatternValidatorType valuePatternValidatorType; + PatternValidatorType objectPatternValidatorType; + SizeType arrayElementIndex; + bool* propertyExist; + bool inArray; + bool valueUniqueness; + bool arrayUniqueness; +}; + +/////////////////////////////////////////////////////////////////////////////// +// Schema + +template +class Schema { +public: + typedef typename SchemaDocumentType::ValueType ValueType; + typedef typename SchemaDocumentType::AllocatorType AllocatorType; + typedef typename SchemaDocumentType::PointerType PointerType; + typedef typename ValueType::EncodingType EncodingType; + typedef typename EncodingType::Ch Ch; + typedef SchemaValidationContext Context; + typedef Schema SchemaType; + typedef GenericValue SValue; + typedef IValidationErrorHandler ErrorHandler; + typedef GenericUri UriType; + friend class GenericSchemaDocument; + + Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator, const UriType& id = UriType()) : + allocator_(allocator), + uri_(schemaDocument->GetURI(), *allocator), + id_(id, allocator), + spec_(schemaDocument->GetSpecification()), + pointer_(p, allocator), + typeless_(schemaDocument->GetTypeless()), + enum_(), + enumCount_(), + not_(), + type_((1 << kTotalSchemaType) - 1), // typeless + validatorCount_(), + notValidatorIndex_(), + properties_(), + additionalPropertiesSchema_(), + patternProperties_(), + patternPropertyCount_(), + propertyCount_(), + minProperties_(), + maxProperties_(SizeType(~0)), + additionalProperties_(true), + hasDependencies_(), + hasRequired_(), + hasSchemaDependencies_(), + additionalItemsSchema_(), + itemsList_(), + itemsTuple_(), + itemsTupleCount_(), + minItems_(), + maxItems_(SizeType(~0)), + additionalItems_(true), + uniqueItems_(false), + pattern_(), + minLength_(0), + maxLength_(~SizeType(0)), + exclusiveMinimum_(false), + exclusiveMaximum_(false), + defaultValueLength_(0), + readOnly_(false), + writeOnly_(false), + nullable_(false) + { + GenericStringBuffer sb; + p.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Schema", sb.GetString(), id.GetString()); + + typedef typename ValueType::ConstValueIterator ConstValueIterator; + typedef typename ValueType::ConstMemberIterator ConstMemberIterator; + + // PR #1393 + // Early add this Schema and its $ref(s) in schemaDocument's map to avoid infinite + // recursion (with recursive schemas), since schemaDocument->getSchema() is always + // checked before creating a new one. Don't cache typeless_, though. + if (this != typeless_) { + typedef typename SchemaDocumentType::SchemaEntry SchemaEntry; + SchemaEntry *entry = schemaDocument->schemaMap_.template Push(); + new (entry) SchemaEntry(pointer_, this, true, allocator_); + schemaDocument->AddSchemaRefs(this); + } + + if (!value.IsObject()) + return; + + // If we have an id property, resolve it with the in-scope id + // Not supported for open api 2.0 or 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (const ValueType* v = GetMember(value, GetIdString())) { + if (v->IsString()) { + UriType local(*v, allocator); + id_ = local.Resolve(id_, allocator); + RAPIDJSON_SCHEMA_PRINT(SchemaIds, id.GetString(), v->GetString(), id_.GetString()); + } + } + + if (const ValueType* v = GetMember(value, GetTypeString())) { + type_ = 0; + if (v->IsString()) + AddType(*v); + else if (v->IsArray()) + for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) + AddType(*itr); + } + + if (const ValueType* v = GetMember(value, GetEnumString())) { + if (v->IsArray() && v->Size() > 0) { + enum_ = static_cast(allocator_->Malloc(sizeof(uint64_t) * v->Size())); + for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) { + typedef Hasher > EnumHasherType; + char buffer[256u + 24]; + MemoryPoolAllocator hasherAllocator(buffer, sizeof(buffer)); + EnumHasherType h(&hasherAllocator, 256); + itr->Accept(h); + enum_[enumCount_++] = h.GetHashCode(); + } + } + } + + if (schemaDocument) + AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document); + + // AnyOf, OneOf, Not not supported for open api 2.0 + if (schemaDocument && spec_.oapi != kVersion20) { + AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document); + AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document); + + if (const ValueType* v = GetMember(value, GetNotString())) { + schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document, id_); + notValidatorIndex_ = validatorCount_; + validatorCount_++; + } + } + + // Object + + const ValueType* properties = GetMember(value, GetPropertiesString()); + const ValueType* required = GetMember(value, GetRequiredString()); + const ValueType* dependencies = GetMember(value, GetDependenciesString()); + { + // Gather properties from properties/required/dependencies + SValue allProperties(kArrayType); + + if (properties && properties->IsObject()) + for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) + AddUniqueElement(allProperties, itr->name); + + if (required && required->IsArray()) + for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr) + if (itr->IsString()) + AddUniqueElement(allProperties, *itr); + + // Dependencies not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (dependencies && dependencies->IsObject()) + for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) { + AddUniqueElement(allProperties, itr->name); + if (itr->value.IsArray()) + for (ConstValueIterator i = itr->value.Begin(); i != itr->value.End(); ++i) + if (i->IsString()) + AddUniqueElement(allProperties, *i); + } + + if (allProperties.Size() > 0) { + propertyCount_ = allProperties.Size(); + properties_ = static_cast(allocator_->Malloc(sizeof(Property) * propertyCount_)); + for (SizeType i = 0; i < propertyCount_; i++) { + new (&properties_[i]) Property(); + properties_[i].name = allProperties[i]; + properties_[i].schema = typeless_; + } + } + } + + if (properties && properties->IsObject()) { + PointerType q = p.Append(GetPropertiesString(), allocator_); + for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) { + SizeType index; + if (FindPropertyIndex(itr->name, &index)) + schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document, id_); + } + } + + // PatternProperties not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (const ValueType* v = GetMember(value, GetPatternPropertiesString())) { + PointerType q = p.Append(GetPatternPropertiesString(), allocator_); + patternProperties_ = static_cast(allocator_->Malloc(sizeof(PatternProperty) * v->MemberCount())); + patternPropertyCount_ = 0; + + for (ConstMemberIterator itr = v->MemberBegin(); itr != v->MemberEnd(); ++itr) { + new (&patternProperties_[patternPropertyCount_]) PatternProperty(); + PointerType r = q.Append(itr->name, allocator_); + patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name, schemaDocument, r); + schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, r, itr->value, document, id_); + patternPropertyCount_++; + } + } + + if (required && required->IsArray()) + for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr) + if (itr->IsString()) { + SizeType index; + if (FindPropertyIndex(*itr, &index)) { + properties_[index].required = true; + hasRequired_ = true; + } + } + + // Dependencies not supported for open api 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (dependencies && dependencies->IsObject()) { + PointerType q = p.Append(GetDependenciesString(), allocator_); + hasDependencies_ = true; + for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) { + SizeType sourceIndex; + if (FindPropertyIndex(itr->name, &sourceIndex)) { + if (itr->value.IsArray()) { + properties_[sourceIndex].dependencies = static_cast(allocator_->Malloc(sizeof(bool) * propertyCount_)); + std::memset(properties_[sourceIndex].dependencies, 0, sizeof(bool)* propertyCount_); + for (ConstValueIterator targetItr = itr->value.Begin(); targetItr != itr->value.End(); ++targetItr) { + SizeType targetIndex; + if (FindPropertyIndex(*targetItr, &targetIndex)) + properties_[sourceIndex].dependencies[targetIndex] = true; + } + } + else if (itr->value.IsObject()) { + hasSchemaDependencies_ = true; + schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document, id_); + properties_[sourceIndex].dependenciesValidatorIndex = validatorCount_; + validatorCount_++; + } + } + } + } + + if (const ValueType* v = GetMember(value, GetAdditionalPropertiesString())) { + if (v->IsBool()) + additionalProperties_ = v->GetBool(); + else if (v->IsObject()) + schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document, id_); + } + + AssignIfExist(minProperties_, value, GetMinPropertiesString()); + AssignIfExist(maxProperties_, value, GetMaxPropertiesString()); + + // Array + if (const ValueType* v = GetMember(value, GetItemsString())) { + PointerType q = p.Append(GetItemsString(), allocator_); + if (v->IsObject()) // List validation + schemaDocument->CreateSchema(&itemsList_, q, *v, document, id_); + else if (v->IsArray()) { // Tuple validation + itemsTuple_ = static_cast(allocator_->Malloc(sizeof(const Schema*) * v->Size())); + SizeType index = 0; + for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr, index++) + schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document, id_); + } + } + + AssignIfExist(minItems_, value, GetMinItemsString()); + AssignIfExist(maxItems_, value, GetMaxItemsString()); + + // AdditionalItems not supported for openapi 2.0 and 3.0 + if (spec_.oapi != kVersion20 && spec_.oapi != kVersion30) + if (const ValueType* v = GetMember(value, GetAdditionalItemsString())) { + if (v->IsBool()) + additionalItems_ = v->GetBool(); + else if (v->IsObject()) + schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document, id_); + } + + AssignIfExist(uniqueItems_, value, GetUniqueItemsString()); + + // String + AssignIfExist(minLength_, value, GetMinLengthString()); + AssignIfExist(maxLength_, value, GetMaxLengthString()); + + if (const ValueType* v = GetMember(value, GetPatternString())) + pattern_ = CreatePattern(*v, schemaDocument, p.Append(GetPatternString(), allocator_)); + + // Number + if (const ValueType* v = GetMember(value, GetMinimumString())) + if (v->IsNumber()) + minimum_.CopyFrom(*v, *allocator_); + + if (const ValueType* v = GetMember(value, GetMaximumString())) + if (v->IsNumber()) + maximum_.CopyFrom(*v, *allocator_); + + AssignIfExist(exclusiveMinimum_, value, GetExclusiveMinimumString()); + AssignIfExist(exclusiveMaximum_, value, GetExclusiveMaximumString()); + + if (const ValueType* v = GetMember(value, GetMultipleOfString())) + if (v->IsNumber() && v->GetDouble() > 0.0) + multipleOf_.CopyFrom(*v, *allocator_); + + // Default + if (const ValueType* v = GetMember(value, GetDefaultValueString())) + if (v->IsString()) + defaultValueLength_ = v->GetStringLength(); + + // ReadOnly - open api only (until draft 7 supported) + // WriteOnly - open api 3 only (until draft 7 supported) + // Both can't be true + if (spec_.oapi != kVersionNone) + AssignIfExist(readOnly_, value, GetReadOnlyString()); + if (spec_.oapi >= kVersion30) + AssignIfExist(writeOnly_, value, GetWriteOnlyString()); + if (readOnly_ && writeOnly_) + schemaDocument->SchemaError(kSchemaErrorReadOnlyAndWriteOnly, p); + + // Nullable - open api 3 only + // If true add 'null' as allowable type + if (spec_.oapi >= kVersion30) { + AssignIfExist(nullable_, value, GetNullableString()); + if (nullable_) + AddType(GetNullString()); + } + } + + ~Schema() { + AllocatorType::Free(enum_); + if (properties_) { + for (SizeType i = 0; i < propertyCount_; i++) + properties_[i].~Property(); + AllocatorType::Free(properties_); + } + if (patternProperties_) { + for (SizeType i = 0; i < patternPropertyCount_; i++) + patternProperties_[i].~PatternProperty(); + AllocatorType::Free(patternProperties_); + } + AllocatorType::Free(itemsTuple_); +#if RAPIDJSON_SCHEMA_HAS_REGEX + if (pattern_) { + pattern_->~RegexType(); + AllocatorType::Free(pattern_); + } +#endif + } + + const SValue& GetURI() const { + return uri_; + } + + const UriType& GetId() const { + return id_; + } + + const Specification& GetSpecification() const { + return spec_; + } + + const PointerType& GetPointer() const { + return pointer_; + } + + bool BeginValue(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::BeginValue"); + if (context.inArray) { + if (uniqueItems_) + context.valueUniqueness = true; + + if (itemsList_) + context.valueSchema = itemsList_; + else if (itemsTuple_) { + if (context.arrayElementIndex < itemsTupleCount_) + context.valueSchema = itemsTuple_[context.arrayElementIndex]; + else if (additionalItemsSchema_) + context.valueSchema = additionalItemsSchema_; + else if (additionalItems_) + context.valueSchema = typeless_; + else { + context.error_handler.DisallowedItem(context.arrayElementIndex); + // Must set valueSchema for when kValidateContinueOnErrorFlag is set, else reports spurious type error + context.valueSchema = typeless_; + // Must bump arrayElementIndex for when kValidateContinueOnErrorFlag is set + context.arrayElementIndex++; + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAdditionalItems); + } + } + else + context.valueSchema = typeless_; + + context.arrayElementIndex++; + } + return true; + } + + RAPIDJSON_FORCEINLINE bool EndValue(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndValue"); + // Only check pattern properties if we have validators + if (context.patternPropertiesValidatorCount > 0) { + bool otherValid = false; + SizeType count = context.patternPropertiesValidatorCount; + if (context.objectPatternValidatorType != Context::kPatternValidatorOnly) + otherValid = context.patternPropertiesValidators[--count]->IsValid(); + + bool patternValid = true; + for (SizeType i = 0; i < count; i++) + if (!context.patternPropertiesValidators[i]->IsValid()) { + patternValid = false; + break; + } + + if (context.objectPatternValidatorType == Context::kPatternValidatorOnly) { + if (!patternValid) { + context.error_handler.PropertyViolations(context.patternPropertiesValidators, count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPatternProperties); + } + } + else if (context.objectPatternValidatorType == Context::kPatternValidatorWithProperty) { + if (!patternValid || !otherValid) { + context.error_handler.PropertyViolations(context.patternPropertiesValidators, count + 1); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPatternProperties); + } + } + else if (!patternValid && !otherValid) { // kPatternValidatorWithAdditionalProperty) + context.error_handler.PropertyViolations(context.patternPropertiesValidators, count + 1); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPatternProperties); + } + } + + // For enums only check if we have a hasher + if (enum_ && context.hasher) { + const uint64_t h = context.factory.GetHashCode(context.hasher); + for (SizeType i = 0; i < enumCount_; i++) + if (enum_[i] == h) + goto foundEnum; + context.error_handler.DisallowedValue(kValidateErrorEnum); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorEnum); + foundEnum:; + } + + // Only check allOf etc if we have validators + if (context.validatorCount > 0) { + if (allOf_.schemas) + for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++) + if (!context.validators[i]->IsValid()) { + context.error_handler.NotAllOf(&context.validators[allOf_.begin], allOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAllOf); + } + + if (anyOf_.schemas) { + for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++) + if (context.validators[i]->IsValid()) + goto foundAny; + context.error_handler.NoneOf(&context.validators[anyOf_.begin], anyOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAnyOf); + foundAny:; + } + + if (oneOf_.schemas) { + bool oneValid = false; + SizeType firstMatch = 0; + for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++) + if (context.validators[i]->IsValid()) { + if (oneValid) { + context.error_handler.MultipleOneOf(firstMatch, i - oneOf_.begin); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOfMatch); + } else { + oneValid = true; + firstMatch = i - oneOf_.begin; + } + } + if (!oneValid) { + context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOf); + } + } + + if (not_ && context.validators[notValidatorIndex_]->IsValid()) { + context.error_handler.Disallowed(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorNot); + } + } + + return true; + } + + bool Null(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Null"); + if (!(type_ & (1 << kNullSchemaType))) { + DisallowedType(context, GetNullString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + return CreateParallelValidator(context); + } + + bool Bool(Context& context, bool b) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Bool", b); + if (!CheckBool(context, b)) + return false; + return CreateParallelValidator(context); + } + + bool Int(Context& context, int i) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Int", (int64_t)i); + if (!CheckInt(context, i)) + return false; + return CreateParallelValidator(context); + } + + bool Uint(Context& context, unsigned u) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Uint", (uint64_t)u); + if (!CheckUint(context, u)) + return false; + return CreateParallelValidator(context); + } + + bool Int64(Context& context, int64_t i) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Int64", i); + if (!CheckInt(context, i)) + return false; + return CreateParallelValidator(context); + } + + bool Uint64(Context& context, uint64_t u) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Uint64", u); + if (!CheckUint(context, u)) + return false; + return CreateParallelValidator(context); + } + + bool Double(Context& context, double d) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Double", d); + if (!(type_ & (1 << kNumberSchemaType))) { + DisallowedType(context, GetNumberString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + + if (!minimum_.IsNull() && !CheckDoubleMinimum(context, d)) + return false; + + if (!maximum_.IsNull() && !CheckDoubleMaximum(context, d)) + return false; + + if (!multipleOf_.IsNull() && !CheckDoubleMultipleOf(context, d)) + return false; + + return CreateParallelValidator(context); + } + + bool String(Context& context, const Ch* str, SizeType length, bool) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::String", str); + if (!(type_ & (1 << kStringSchemaType))) { + DisallowedType(context, GetStringString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + + if (minLength_ != 0 || maxLength_ != SizeType(~0)) { + SizeType count; + if (internal::CountStringCodePoint(str, length, &count)) { + if (count < minLength_) { + context.error_handler.TooShort(str, length, minLength_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinLength); + } + if (count > maxLength_) { + context.error_handler.TooLong(str, length, maxLength_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxLength); + } + } + } + + if (pattern_ && !IsPatternMatch(pattern_, str, length)) { + context.error_handler.DoesNotMatch(str, length); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorPattern); + } + + return CreateParallelValidator(context); + } + + bool StartObject(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::StartObject"); + if (!(type_ & (1 << kObjectSchemaType))) { + DisallowedType(context, GetObjectString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + + if (hasDependencies_ || hasRequired_) { + context.propertyExist = static_cast(context.factory.MallocState(sizeof(bool) * propertyCount_)); + std::memset(context.propertyExist, 0, sizeof(bool) * propertyCount_); + } + + if (patternProperties_) { // pre-allocate schema array + SizeType count = patternPropertyCount_ + 1; // extra for valuePatternValidatorType + context.patternPropertiesSchemas = static_cast(context.factory.MallocState(sizeof(const SchemaType*) * count)); + context.patternPropertiesSchemaCount = 0; + std::memset(context.patternPropertiesSchemas, 0, sizeof(SchemaType*) * count); + } + + return CreateParallelValidator(context); + } + + bool Key(Context& context, const Ch* str, SizeType len, bool) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::Key", str); + + if (patternProperties_) { + context.patternPropertiesSchemaCount = 0; + for (SizeType i = 0; i < patternPropertyCount_; i++) + if (patternProperties_[i].pattern && IsPatternMatch(patternProperties_[i].pattern, str, len)) { + context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = patternProperties_[i].schema; + context.valueSchema = typeless_; + } + } + + SizeType index = 0; + if (FindPropertyIndex(ValueType(str, len).Move(), &index)) { + if (context.patternPropertiesSchemaCount > 0) { + context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = properties_[index].schema; + context.valueSchema = typeless_; + context.valuePatternValidatorType = Context::kPatternValidatorWithProperty; + } + else + context.valueSchema = properties_[index].schema; + + if (context.propertyExist) + context.propertyExist[index] = true; + + return true; + } + + if (additionalPropertiesSchema_) { + if (context.patternPropertiesSchemaCount > 0) { + context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = additionalPropertiesSchema_; + context.valueSchema = typeless_; + context.valuePatternValidatorType = Context::kPatternValidatorWithAdditionalProperty; + } + else + context.valueSchema = additionalPropertiesSchema_; + return true; + } + else if (additionalProperties_) { + context.valueSchema = typeless_; + return true; + } + + if (context.patternPropertiesSchemaCount == 0) { // patternProperties are not additional properties + // Must set valueSchema for when kValidateContinueOnErrorFlag is set, else reports spurious type error + context.valueSchema = typeless_; + context.error_handler.DisallowedProperty(str, len); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorAdditionalProperties); + } + + return true; + } + + bool EndObject(Context& context, SizeType memberCount) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndObject"); + if (hasRequired_) { + context.error_handler.StartMissingProperties(); + for (SizeType index = 0; index < propertyCount_; index++) + if (properties_[index].required && !context.propertyExist[index]) + if (properties_[index].schema->defaultValueLength_ == 0 ) + context.error_handler.AddMissingProperty(properties_[index].name); + if (context.error_handler.EndMissingProperties()) + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorRequired); + } + + if (memberCount < minProperties_) { + context.error_handler.TooFewProperties(memberCount, minProperties_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinProperties); + } + + if (memberCount > maxProperties_) { + context.error_handler.TooManyProperties(memberCount, maxProperties_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxProperties); + } + + if (hasDependencies_) { + context.error_handler.StartDependencyErrors(); + for (SizeType sourceIndex = 0; sourceIndex < propertyCount_; sourceIndex++) { + const Property& source = properties_[sourceIndex]; + if (context.propertyExist[sourceIndex]) { + if (source.dependencies) { + context.error_handler.StartMissingDependentProperties(); + for (SizeType targetIndex = 0; targetIndex < propertyCount_; targetIndex++) + if (source.dependencies[targetIndex] && !context.propertyExist[targetIndex]) + context.error_handler.AddMissingDependentProperty(properties_[targetIndex].name); + context.error_handler.EndMissingDependentProperties(source.name); + } + else if (source.dependenciesSchema) { + ISchemaValidator* dependenciesValidator = context.validators[source.dependenciesValidatorIndex]; + if (!dependenciesValidator->IsValid()) + context.error_handler.AddDependencySchemaError(source.name, dependenciesValidator); + } + } + } + if (context.error_handler.EndDependencyErrors()) + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorDependencies); + } + + return true; + } + + bool StartArray(Context& context) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::StartArray"); + context.arrayElementIndex = 0; + context.inArray = true; // Ensure we note that we are in an array + + if (!(type_ & (1 << kArraySchemaType))) { + DisallowedType(context, GetArrayString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + + return CreateParallelValidator(context); + } + + bool EndArray(Context& context, SizeType elementCount) const { + RAPIDJSON_SCHEMA_PRINT(Method, "Schema::EndArray"); + context.inArray = false; + + if (elementCount < minItems_) { + context.error_handler.TooFewItems(elementCount, minItems_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMinItems); + } + + if (elementCount > maxItems_) { + context.error_handler.TooManyItems(elementCount, maxItems_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMaxItems); + } + + return true; + } + + static const ValueType& GetValidateErrorKeyword(ValidateErrorCode validateErrorCode) { + switch (validateErrorCode) { + case kValidateErrorMultipleOf: return GetMultipleOfString(); + case kValidateErrorMaximum: return GetMaximumString(); + case kValidateErrorExclusiveMaximum: return GetMaximumString(); // Same + case kValidateErrorMinimum: return GetMinimumString(); + case kValidateErrorExclusiveMinimum: return GetMinimumString(); // Same + + case kValidateErrorMaxLength: return GetMaxLengthString(); + case kValidateErrorMinLength: return GetMinLengthString(); + case kValidateErrorPattern: return GetPatternString(); + + case kValidateErrorMaxItems: return GetMaxItemsString(); + case kValidateErrorMinItems: return GetMinItemsString(); + case kValidateErrorUniqueItems: return GetUniqueItemsString(); + case kValidateErrorAdditionalItems: return GetAdditionalItemsString(); + + case kValidateErrorMaxProperties: return GetMaxPropertiesString(); + case kValidateErrorMinProperties: return GetMinPropertiesString(); + case kValidateErrorRequired: return GetRequiredString(); + case kValidateErrorAdditionalProperties: return GetAdditionalPropertiesString(); + case kValidateErrorPatternProperties: return GetPatternPropertiesString(); + case kValidateErrorDependencies: return GetDependenciesString(); + + case kValidateErrorEnum: return GetEnumString(); + case kValidateErrorType: return GetTypeString(); + + case kValidateErrorOneOf: return GetOneOfString(); + case kValidateErrorOneOfMatch: return GetOneOfString(); // Same + case kValidateErrorAllOf: return GetAllOfString(); + case kValidateErrorAnyOf: return GetAnyOfString(); + case kValidateErrorNot: return GetNotString(); + + case kValidateErrorReadOnly: return GetReadOnlyString(); + case kValidateErrorWriteOnly: return GetWriteOnlyString(); + + default: return GetNullString(); + } + } + + + // Generate functions for string literal according to Ch +#define RAPIDJSON_STRING_(name, ...) \ + static const ValueType& Get##name##String() {\ + static const Ch s[] = { __VA_ARGS__, '\0' };\ + static const ValueType v(s, static_cast(sizeof(s) / sizeof(Ch) - 1));\ + return v;\ + } + + RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l') + RAPIDJSON_STRING_(Boolean, 'b', 'o', 'o', 'l', 'e', 'a', 'n') + RAPIDJSON_STRING_(Object, 'o', 'b', 'j', 'e', 'c', 't') + RAPIDJSON_STRING_(Array, 'a', 'r', 'r', 'a', 'y') + RAPIDJSON_STRING_(String, 's', 't', 'r', 'i', 'n', 'g') + RAPIDJSON_STRING_(Number, 'n', 'u', 'm', 'b', 'e', 'r') + RAPIDJSON_STRING_(Integer, 'i', 'n', 't', 'e', 'g', 'e', 'r') + RAPIDJSON_STRING_(Type, 't', 'y', 'p', 'e') + RAPIDJSON_STRING_(Enum, 'e', 'n', 'u', 'm') + RAPIDJSON_STRING_(AllOf, 'a', 'l', 'l', 'O', 'f') + RAPIDJSON_STRING_(AnyOf, 'a', 'n', 'y', 'O', 'f') + RAPIDJSON_STRING_(OneOf, 'o', 'n', 'e', 'O', 'f') + RAPIDJSON_STRING_(Not, 'n', 'o', 't') + RAPIDJSON_STRING_(Properties, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's') + RAPIDJSON_STRING_(Required, 'r', 'e', 'q', 'u', 'i', 'r', 'e', 'd') + RAPIDJSON_STRING_(Dependencies, 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'i', 'e', 's') + RAPIDJSON_STRING_(PatternProperties, 'p', 'a', 't', 't', 'e', 'r', 'n', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's') + RAPIDJSON_STRING_(AdditionalProperties, 'a', 'd', 'd', 'i', 't', 'i', 'o', 'n', 'a', 'l', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's') + RAPIDJSON_STRING_(MinProperties, 'm', 'i', 'n', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's') + RAPIDJSON_STRING_(MaxProperties, 'm', 'a', 'x', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's') + RAPIDJSON_STRING_(Items, 'i', 't', 'e', 'm', 's') + RAPIDJSON_STRING_(MinItems, 'm', 'i', 'n', 'I', 't', 'e', 'm', 's') + RAPIDJSON_STRING_(MaxItems, 'm', 'a', 'x', 'I', 't', 'e', 'm', 's') + RAPIDJSON_STRING_(AdditionalItems, 'a', 'd', 'd', 'i', 't', 'i', 'o', 'n', 'a', 'l', 'I', 't', 'e', 'm', 's') + RAPIDJSON_STRING_(UniqueItems, 'u', 'n', 'i', 'q', 'u', 'e', 'I', 't', 'e', 'm', 's') + RAPIDJSON_STRING_(MinLength, 'm', 'i', 'n', 'L', 'e', 'n', 'g', 't', 'h') + RAPIDJSON_STRING_(MaxLength, 'm', 'a', 'x', 'L', 'e', 'n', 'g', 't', 'h') + RAPIDJSON_STRING_(Pattern, 'p', 'a', 't', 't', 'e', 'r', 'n') + RAPIDJSON_STRING_(Minimum, 'm', 'i', 'n', 'i', 'm', 'u', 'm') + RAPIDJSON_STRING_(Maximum, 'm', 'a', 'x', 'i', 'm', 'u', 'm') + RAPIDJSON_STRING_(ExclusiveMinimum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'i', 'n', 'i', 'm', 'u', 'm') + RAPIDJSON_STRING_(ExclusiveMaximum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'a', 'x', 'i', 'm', 'u', 'm') + RAPIDJSON_STRING_(MultipleOf, 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'O', 'f') + RAPIDJSON_STRING_(DefaultValue, 'd', 'e', 'f', 'a', 'u', 'l', 't') + RAPIDJSON_STRING_(Schema, '$', 's', 'c', 'h', 'e', 'm', 'a') + RAPIDJSON_STRING_(Ref, '$', 'r', 'e', 'f') + RAPIDJSON_STRING_(Id, 'i', 'd') + RAPIDJSON_STRING_(Swagger, 's', 'w', 'a', 'g', 'g', 'e', 'r') + RAPIDJSON_STRING_(OpenApi, 'o', 'p', 'e', 'n', 'a', 'p', 'i') + RAPIDJSON_STRING_(ReadOnly, 'r', 'e', 'a', 'd', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(WriteOnly, 'w', 'r', 'i', 't', 'e', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(Nullable, 'n', 'u', 'l', 'l', 'a', 'b', 'l', 'e') + +#undef RAPIDJSON_STRING_ + +private: + enum SchemaValueType { + kNullSchemaType, + kBooleanSchemaType, + kObjectSchemaType, + kArraySchemaType, + kStringSchemaType, + kNumberSchemaType, + kIntegerSchemaType, + kTotalSchemaType + }; + +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX + typedef internal::GenericRegex RegexType; +#elif RAPIDJSON_SCHEMA_USE_STDREGEX + typedef std::basic_regex RegexType; +#else + typedef char RegexType; +#endif + + struct SchemaArray { + SchemaArray() : schemas(), count() {} + ~SchemaArray() { AllocatorType::Free(schemas); } + const SchemaType** schemas; + SizeType begin; // begin index of context.validators + SizeType count; + }; + + template + void AddUniqueElement(V1& a, const V2& v) { + for (typename V1::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) + if (*itr == v) + return; + V1 c(v, *allocator_); + a.PushBack(c, *allocator_); + } + + static const ValueType* GetMember(const ValueType& value, const ValueType& name) { + typename ValueType::ConstMemberIterator itr = value.FindMember(name); + return itr != value.MemberEnd() ? &(itr->value) : 0; + } + + static void AssignIfExist(bool& out, const ValueType& value, const ValueType& name) { + if (const ValueType* v = GetMember(value, name)) + if (v->IsBool()) + out = v->GetBool(); + } + + static void AssignIfExist(SizeType& out, const ValueType& value, const ValueType& name) { + if (const ValueType* v = GetMember(value, name)) + if (v->IsUint64() && v->GetUint64() <= SizeType(~0)) + out = static_cast(v->GetUint64()); + } + + void AssignIfExist(SchemaArray& out, SchemaDocumentType& schemaDocument, const PointerType& p, const ValueType& value, const ValueType& name, const ValueType& document) { + if (const ValueType* v = GetMember(value, name)) { + if (v->IsArray() && v->Size() > 0) { + PointerType q = p.Append(name, allocator_); + out.count = v->Size(); + out.schemas = static_cast(allocator_->Malloc(out.count * sizeof(const Schema*))); + memset(out.schemas, 0, sizeof(Schema*)* out.count); + for (SizeType i = 0; i < out.count; i++) + schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document, id_); + out.begin = validatorCount_; + validatorCount_ += out.count; + } + } + } + +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX + template + RegexType* CreatePattern(const ValueType& value, SchemaDocumentType* sd, const PointerType& p) { + if (value.IsString()) { + RegexType* r = new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), allocator_); + if (!r->IsValid()) { + sd->SchemaErrorValue(kSchemaErrorRegexInvalid, p, value.GetString(), value.GetStringLength()); + r->~RegexType(); + AllocatorType::Free(r); + r = 0; + } + return r; + } + return 0; + } + + static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType) { + GenericRegexSearch rs(*pattern); + return rs.Search(str); + } +#elif RAPIDJSON_SCHEMA_USE_STDREGEX + template + RegexType* CreatePattern(const ValueType& value, SchemaDocumentType* sd, const PointerType& p) { + if (value.IsString()) { + RegexType *r = static_cast(allocator_->Malloc(sizeof(RegexType))); + try { + return new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); + } + catch (const std::regex_error& e) { + sd->SchemaErrorValue(kSchemaErrorRegexInvalid, p, value.GetString(), value.GetStringLength()); + AllocatorType::Free(r); + } + } + return 0; + } + + static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType length) { + std::match_results r; + return std::regex_search(str, str + length, r, *pattern); + } +#else + template + RegexType* CreatePattern(const ValueType&) { + return 0; + } + + static bool IsPatternMatch(const RegexType*, const Ch *, SizeType) { return true; } +#endif // RAPIDJSON_SCHEMA_USE_STDREGEX + + void AddType(const ValueType& type) { + if (type == GetNullString() ) type_ |= 1 << kNullSchemaType; + else if (type == GetBooleanString()) type_ |= 1 << kBooleanSchemaType; + else if (type == GetObjectString() ) type_ |= 1 << kObjectSchemaType; + else if (type == GetArrayString() ) type_ |= 1 << kArraySchemaType; + else if (type == GetStringString() ) type_ |= 1 << kStringSchemaType; + else if (type == GetIntegerString()) type_ |= 1 << kIntegerSchemaType; + else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType); + } + + // Creates parallel validators for allOf, anyOf, oneOf, not and schema dependencies, if required. + // Also creates a hasher for enums and array uniqueness, if required. + // Also a useful place to add type-independent error checks. + bool CreateParallelValidator(Context& context) const { + if (enum_ || context.arrayUniqueness) + context.hasher = context.factory.CreateHasher(); + + if (validatorCount_) { + RAPIDJSON_ASSERT(context.validators == 0); + context.validators = static_cast(context.factory.MallocState(sizeof(ISchemaValidator*) * validatorCount_)); + std::memset(context.validators, 0, sizeof(ISchemaValidator*) * validatorCount_); + context.validatorCount = validatorCount_; + + // Always return after first failure for these sub-validators + if (allOf_.schemas) + CreateSchemaValidators(context, allOf_, false); + + if (anyOf_.schemas) + CreateSchemaValidators(context, anyOf_, false); + + if (oneOf_.schemas) + CreateSchemaValidators(context, oneOf_, false); + + if (not_) + context.validators[notValidatorIndex_] = context.factory.CreateSchemaValidator(*not_, false); + + if (hasSchemaDependencies_) { + for (SizeType i = 0; i < propertyCount_; i++) + if (properties_[i].dependenciesSchema) + context.validators[properties_[i].dependenciesValidatorIndex] = context.factory.CreateSchemaValidator(*properties_[i].dependenciesSchema, false); + } + } + + // Add any other type-independent checks here + if (readOnly_ && (context.flags & kValidateWriteFlag)) { + context.error_handler.DisallowedWhenWriting(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorReadOnly); + } + if (writeOnly_ && (context.flags & kValidateReadFlag)) { + context.error_handler.DisallowedWhenReading(); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorWriteOnly); + } + + return true; + } + + void CreateSchemaValidators(Context& context, const SchemaArray& schemas, const bool inheritContinueOnErrors) const { + for (SizeType i = 0; i < schemas.count; i++) + context.validators[schemas.begin + i] = context.factory.CreateSchemaValidator(*schemas.schemas[i], inheritContinueOnErrors); + } + + // O(n) + bool FindPropertyIndex(const ValueType& name, SizeType* outIndex) const { + SizeType len = name.GetStringLength(); + const Ch* str = name.GetString(); + for (SizeType index = 0; index < propertyCount_; index++) + if (properties_[index].name.GetStringLength() == len && + (std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0)) + { + *outIndex = index; + return true; + } + return false; + } + + bool CheckBool(Context& context, bool) const { + if (!(type_ & (1 << kBooleanSchemaType))) { + DisallowedType(context, GetBooleanString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + return true; + } + + bool CheckInt(Context& context, int64_t i) const { + if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) { + DisallowedType(context, GetIntegerString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + + if (!minimum_.IsNull()) { + if (minimum_.IsInt64()) { + if (exclusiveMinimum_ ? i <= minimum_.GetInt64() : i < minimum_.GetInt64()) { + context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); + } + } + else if (minimum_.IsUint64()) { + context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); // i <= max(int64_t) < minimum.GetUint64() + } + else if (!CheckDoubleMinimum(context, static_cast(i))) + return false; + } + + if (!maximum_.IsNull()) { + if (maximum_.IsInt64()) { + if (exclusiveMaximum_ ? i >= maximum_.GetInt64() : i > maximum_.GetInt64()) { + context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); + } + } + else if (maximum_.IsUint64()) { } + /* do nothing */ // i <= max(int64_t) < maximum_.GetUint64() + else if (!CheckDoubleMaximum(context, static_cast(i))) + return false; + } + + if (!multipleOf_.IsNull()) { + if (multipleOf_.IsUint64()) { + if (static_cast(i >= 0 ? i : -i) % multipleOf_.GetUint64() != 0) { + context.error_handler.NotMultipleOf(i, multipleOf_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); + } + } + else if (!CheckDoubleMultipleOf(context, static_cast(i))) + return false; + } + + return true; + } + + bool CheckUint(Context& context, uint64_t i) const { + if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) { + DisallowedType(context, GetIntegerString()); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorType); + } + + if (!minimum_.IsNull()) { + if (minimum_.IsUint64()) { + if (exclusiveMinimum_ ? i <= minimum_.GetUint64() : i < minimum_.GetUint64()) { + context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); + } + } + else if (minimum_.IsInt64()) + /* do nothing */; // i >= 0 > minimum.Getint64() + else if (!CheckDoubleMinimum(context, static_cast(i))) + return false; + } + + if (!maximum_.IsNull()) { + if (maximum_.IsUint64()) { + if (exclusiveMaximum_ ? i >= maximum_.GetUint64() : i > maximum_.GetUint64()) { + context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); + } + } + else if (maximum_.IsInt64()) { + context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); // i >= 0 > maximum_ + } + else if (!CheckDoubleMaximum(context, static_cast(i))) + return false; + } + + if (!multipleOf_.IsNull()) { + if (multipleOf_.IsUint64()) { + if (i % multipleOf_.GetUint64() != 0) { + context.error_handler.NotMultipleOf(i, multipleOf_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); + } + } + else if (!CheckDoubleMultipleOf(context, static_cast(i))) + return false; + } + + return true; + } + + bool CheckDoubleMinimum(Context& context, double d) const { + if (exclusiveMinimum_ ? d <= minimum_.GetDouble() : d < minimum_.GetDouble()) { + context.error_handler.BelowMinimum(d, minimum_, exclusiveMinimum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMinimum_ ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum); + } + return true; + } + + bool CheckDoubleMaximum(Context& context, double d) const { + if (exclusiveMaximum_ ? d >= maximum_.GetDouble() : d > maximum_.GetDouble()) { + context.error_handler.AboveMaximum(d, maximum_, exclusiveMaximum_); + RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum); + } + return true; + } + + bool CheckDoubleMultipleOf(Context& context, double d) const { + double a = std::abs(d), b = std::abs(multipleOf_.GetDouble()); + double q = std::floor(a / b); + double r = a - q * b; + if (r > 0.0) { + context.error_handler.NotMultipleOf(d, multipleOf_); + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorMultipleOf); + } + return true; + } + + void DisallowedType(Context& context, const ValueType& actualType) const { + ErrorHandler& eh = context.error_handler; + eh.StartDisallowedType(); + + if (type_ & (1 << kNullSchemaType)) eh.AddExpectedType(GetNullString()); + if (type_ & (1 << kBooleanSchemaType)) eh.AddExpectedType(GetBooleanString()); + if (type_ & (1 << kObjectSchemaType)) eh.AddExpectedType(GetObjectString()); + if (type_ & (1 << kArraySchemaType)) eh.AddExpectedType(GetArrayString()); + if (type_ & (1 << kStringSchemaType)) eh.AddExpectedType(GetStringString()); + + if (type_ & (1 << kNumberSchemaType)) eh.AddExpectedType(GetNumberString()); + else if (type_ & (1 << kIntegerSchemaType)) eh.AddExpectedType(GetIntegerString()); + + eh.EndDisallowedType(actualType); + } + + struct Property { + Property() : schema(), dependenciesSchema(), dependenciesValidatorIndex(), dependencies(), required(false) {} + ~Property() { AllocatorType::Free(dependencies); } + SValue name; + const SchemaType* schema; + const SchemaType* dependenciesSchema; + SizeType dependenciesValidatorIndex; + bool* dependencies; + bool required; + }; + + struct PatternProperty { + PatternProperty() : schema(), pattern() {} + ~PatternProperty() { + if (pattern) { + pattern->~RegexType(); + AllocatorType::Free(pattern); + } + } + const SchemaType* schema; + RegexType* pattern; + }; + + AllocatorType* allocator_; + SValue uri_; + UriType id_; + Specification spec_; + PointerType pointer_; + const SchemaType* typeless_; + uint64_t* enum_; + SizeType enumCount_; + SchemaArray allOf_; + SchemaArray anyOf_; + SchemaArray oneOf_; + const SchemaType* not_; + unsigned type_; // bitmask of kSchemaType + SizeType validatorCount_; + SizeType notValidatorIndex_; + + Property* properties_; + const SchemaType* additionalPropertiesSchema_; + PatternProperty* patternProperties_; + SizeType patternPropertyCount_; + SizeType propertyCount_; + SizeType minProperties_; + SizeType maxProperties_; + bool additionalProperties_; + bool hasDependencies_; + bool hasRequired_; + bool hasSchemaDependencies_; + + const SchemaType* additionalItemsSchema_; + const SchemaType* itemsList_; + const SchemaType** itemsTuple_; + SizeType itemsTupleCount_; + SizeType minItems_; + SizeType maxItems_; + bool additionalItems_; + bool uniqueItems_; + + RegexType* pattern_; + SizeType minLength_; + SizeType maxLength_; + + SValue minimum_; + SValue maximum_; + SValue multipleOf_; + bool exclusiveMinimum_; + bool exclusiveMaximum_; + + SizeType defaultValueLength_; + + bool readOnly_; + bool writeOnly_; + bool nullable_; +}; + +template +struct TokenHelper { + RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) { + *documentStack.template Push() = '/'; + char buffer[21]; + size_t length = static_cast((sizeof(SizeType) == 4 ? u32toa(index, buffer) : u64toa(index, buffer)) - buffer); + for (size_t i = 0; i < length; i++) + *documentStack.template Push() = static_cast(buffer[i]); + } +}; + +// Partial specialized version for char to prevent buffer copying. +template +struct TokenHelper { + RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) { + if (sizeof(SizeType) == 4) { + char *buffer = documentStack.template Push(1 + 10); // '/' + uint + *buffer++ = '/'; + const char* end = internal::u32toa(index, buffer); + documentStack.template Pop(static_cast(10 - (end - buffer))); + } + else { + char *buffer = documentStack.template Push(1 + 20); // '/' + uint64 + *buffer++ = '/'; + const char* end = internal::u64toa(index, buffer); + documentStack.template Pop(static_cast(20 - (end - buffer))); + } + } +}; + +} // namespace internal + +/////////////////////////////////////////////////////////////////////////////// +// IGenericRemoteSchemaDocumentProvider + +template +class IGenericRemoteSchemaDocumentProvider { +public: + typedef typename SchemaDocumentType::Ch Ch; + typedef typename SchemaDocumentType::ValueType ValueType; + typedef typename SchemaDocumentType::AllocatorType AllocatorType; + + virtual ~IGenericRemoteSchemaDocumentProvider() {} + virtual const SchemaDocumentType* GetRemoteDocument(const Ch* uri, SizeType length) = 0; + virtual const SchemaDocumentType* GetRemoteDocument(const GenericUri uri, Specification& spec) { + // Default implementation just calls through for compatibility + // Following line suppresses unused parameter warning + (void)spec; + // printf("GetRemoteDocument: %d %d\n", spec.draft, spec.oapi); + return GetRemoteDocument(uri.GetBaseString(), uri.GetBaseStringLength()); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// GenericSchemaDocument + +//! JSON schema document. +/*! + A JSON schema document is a compiled version of a JSON schema. + It is basically a tree of internal::Schema. + + \note This is an immutable class (i.e. its instance cannot be modified after construction). + \tparam ValueT Type of JSON value (e.g. \c Value ), which also determine the encoding. + \tparam Allocator Allocator type for allocating memory of this document. +*/ +template +class GenericSchemaDocument { +public: + typedef ValueT ValueType; + typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProviderType; + typedef Allocator AllocatorType; + typedef typename ValueType::EncodingType EncodingType; + typedef typename EncodingType::Ch Ch; + typedef internal::Schema SchemaType; + typedef GenericPointer PointerType; + typedef GenericValue GValue; + typedef GenericUri UriType; + typedef GenericStringRef StringRefType; + friend class internal::Schema; + template + friend class GenericSchemaValidator; + + //! Constructor. + /*! + Compile a JSON document into schema document. + + \param document A JSON document as source. + \param uri The base URI of this schema document for purposes of violation reporting. + \param uriLength Length of \c name, in code points. + \param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null. + \param allocator An optional allocator instance for allocating memory. Can be null. + \param pointer An optional JSON pointer to the start of the schema document + \param spec Optional schema draft or OpenAPI version. Used if no specification in document. Defaults to draft-04. + */ + explicit GenericSchemaDocument(const ValueType& document, const Ch* uri = 0, SizeType uriLength = 0, + IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0, + const PointerType& pointer = PointerType(), // PR #1393 + const Specification& spec = Specification(kDraft04)) : + remoteProvider_(remoteProvider), + allocator_(allocator), + ownAllocator_(), + root_(), + typeless_(), + schemaMap_(allocator, kInitialSchemaMapSize), + schemaRef_(allocator, kInitialSchemaRefSize), + spec_(spec), + error_(kObjectType), + currentError_() + { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::GenericSchemaDocument"); + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + + Ch noUri[1] = {0}; + uri_.SetString(uri ? uri : noUri, uriLength, *allocator_); + docId_ = UriType(uri_, allocator_); + + typeless_ = static_cast(allocator_->Malloc(sizeof(SchemaType))); + new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_, docId_); + + // Establish the schema draft or open api version. + // We only ever look for '$schema' or 'swagger' or 'openapi' at the root of the document. + SetSchemaSpecification(document); + + // Generate root schema, it will call CreateSchema() to create sub-schemas, + // And call HandleRefSchema() if there are $ref. + // PR #1393 use input pointer if supplied + root_ = typeless_; + if (pointer.GetTokenCount() == 0) { + CreateSchemaRecursive(&root_, pointer, document, document, docId_); + } + else if (const ValueType* v = pointer.Get(document)) { + CreateSchema(&root_, pointer, *v, document, docId_); + } + else { + GenericStringBuffer sb; + pointer.StringifyUriFragment(sb); + SchemaErrorValue(kSchemaErrorStartUnknown, PointerType(), sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch))); + } + + RAPIDJSON_ASSERT(root_ != 0); + + schemaRef_.ShrinkToFit(); // Deallocate all memory for ref + } + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Move constructor in C++11 + GenericSchemaDocument(GenericSchemaDocument&& rhs) RAPIDJSON_NOEXCEPT : + remoteProvider_(rhs.remoteProvider_), + allocator_(rhs.allocator_), + ownAllocator_(rhs.ownAllocator_), + root_(rhs.root_), + typeless_(rhs.typeless_), + schemaMap_(std::move(rhs.schemaMap_)), + schemaRef_(std::move(rhs.schemaRef_)), + uri_(std::move(rhs.uri_)), + docId_(std::move(rhs.docId_)), + spec_(rhs.spec_), + error_(std::move(rhs.error_)), + currentError_(std::move(rhs.currentError_)) + { + rhs.remoteProvider_ = 0; + rhs.allocator_ = 0; + rhs.ownAllocator_ = 0; + rhs.typeless_ = 0; + } +#endif + + //! Destructor + ~GenericSchemaDocument() { + while (!schemaMap_.Empty()) + schemaMap_.template Pop(1)->~SchemaEntry(); + + if (typeless_) { + typeless_->~SchemaType(); + Allocator::Free(typeless_); + } + + // these may contain some allocator data so clear before deleting ownAllocator_ + uri_.SetNull(); + error_.SetNull(); + currentError_.SetNull(); + + RAPIDJSON_DELETE(ownAllocator_); + } + + const GValue& GetURI() const { return uri_; } + + const Specification& GetSpecification() const { return spec_; } + bool IsSupportedSpecification() const { return spec_.IsSupported(); } + + //! Static method to get the specification of any schema document + // Returns kDraftNone if document is silent + static const Specification GetSpecification(const ValueType& document) { + SchemaDraft draft = GetSchemaDraft(document); + if (draft != kDraftNone) + return Specification(draft); + else { + OpenApiVersion oapi = GetOpenApiVersion(document); + if (oapi != kVersionNone) + return Specification(oapi); + } + return Specification(kDraftNone); + } + + //! Get the root schema. + const SchemaType& GetRoot() const { return *root_; } + + //! Gets the error object. + GValue& GetError() { return error_; } + const GValue& GetError() const { return error_; } + + static const StringRefType& GetSchemaErrorKeyword(SchemaErrorCode schemaErrorCode) { + switch (schemaErrorCode) { + case kSchemaErrorStartUnknown: return GetStartUnknownString(); + case kSchemaErrorRefPlainName: return GetRefPlainNameString(); + case kSchemaErrorRefInvalid: return GetRefInvalidString(); + case kSchemaErrorRefPointerInvalid: return GetRefPointerInvalidString(); + case kSchemaErrorRefUnknown: return GetRefUnknownString(); + case kSchemaErrorRefCyclical: return GetRefCyclicalString(); + case kSchemaErrorRefNoRemoteProvider: return GetRefNoRemoteProviderString(); + case kSchemaErrorRefNoRemoteSchema: return GetRefNoRemoteSchemaString(); + case kSchemaErrorRegexInvalid: return GetRegexInvalidString(); + case kSchemaErrorSpecUnknown: return GetSpecUnknownString(); + case kSchemaErrorSpecUnsupported: return GetSpecUnsupportedString(); + case kSchemaErrorSpecIllegal: return GetSpecIllegalString(); + case kSchemaErrorReadOnlyAndWriteOnly: return GetReadOnlyAndWriteOnlyString(); + default: return GetNullString(); + } + } + + //! Default error method + void SchemaError(const SchemaErrorCode code, const PointerType& location) { + currentError_ = GValue(kObjectType); + AddCurrentError(code, location); + } + + //! Method for error with single string value insert + void SchemaErrorValue(const SchemaErrorCode code, const PointerType& location, const Ch* value, SizeType length) { + currentError_ = GValue(kObjectType); + currentError_.AddMember(GetValueString(), GValue(value, length, *allocator_).Move(), *allocator_); + AddCurrentError(code, location); + } + + //! Method for error with invalid pointer + void SchemaErrorPointer(const SchemaErrorCode code, const PointerType& location, const Ch* value, SizeType length, const PointerType& pointer) { + currentError_ = GValue(kObjectType); + currentError_.AddMember(GetValueString(), GValue(value, length, *allocator_).Move(), *allocator_); + currentError_.AddMember(GetOffsetString(), static_cast(pointer.GetParseErrorOffset() / sizeof(Ch)), *allocator_); + AddCurrentError(code, location); + } + + private: + //! Prohibit copying + GenericSchemaDocument(const GenericSchemaDocument&); + //! Prohibit assignment + GenericSchemaDocument& operator=(const GenericSchemaDocument&); + + typedef const PointerType* SchemaRefPtr; // PR #1393 + + struct SchemaEntry { + SchemaEntry(const PointerType& p, SchemaType* s, bool o, Allocator* allocator) : pointer(p, allocator), schema(s), owned(o) {} + ~SchemaEntry() { + if (owned) { + schema->~SchemaType(); + Allocator::Free(schema); + } + } + PointerType pointer; + SchemaType* schema; + bool owned; + }; + + void AddErrorInstanceLocation(GValue& result, const PointerType& location) { + GenericStringBuffer sb; + location.StringifyUriFragment(sb); + GValue instanceRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), *allocator_); + result.AddMember(GetInstanceRefString(), instanceRef, *allocator_); + } + + void AddError(GValue& keyword, GValue& error) { + typename GValue::MemberIterator member = error_.FindMember(keyword); + if (member == error_.MemberEnd()) + error_.AddMember(keyword, error, *allocator_); + else { + if (member->value.IsObject()) { + GValue errors(kArrayType); + errors.PushBack(member->value, *allocator_); + member->value = errors; + } + member->value.PushBack(error, *allocator_); + } + } + + void AddCurrentError(const SchemaErrorCode code, const PointerType& location) { + RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, GetSchemaErrorKeyword(code)); + currentError_.AddMember(GetErrorCodeString(), code, *allocator_); + AddErrorInstanceLocation(currentError_, location); + AddError(GValue(GetSchemaErrorKeyword(code)).Move(), currentError_); + } + +#define RAPIDJSON_STRING_(name, ...) \ + static const StringRefType& Get##name##String() {\ + static const Ch s[] = { __VA_ARGS__, '\0' };\ + static const StringRefType v(s, static_cast(sizeof(s) / sizeof(Ch) - 1)); \ + return v;\ + } + + RAPIDJSON_STRING_(InstanceRef, 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 'R', 'e', 'f') + RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e') + RAPIDJSON_STRING_(Value, 'v', 'a', 'l', 'u', 'e') + RAPIDJSON_STRING_(Offset, 'o', 'f', 'f', 's', 'e', 't') + + RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l') + RAPIDJSON_STRING_(SpecUnknown, 'S', 'p', 'e', 'c', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(SpecUnsupported, 'S', 'p', 'e', 'c', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd') + RAPIDJSON_STRING_(SpecIllegal, 'S', 'p', 'e', 'c', 'I', 'l', 'l', 'e', 'g', 'a', 'l') + RAPIDJSON_STRING_(StartUnknown, 'S', 't', 'a', 'r', 't', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(RefPlainName, 'R', 'e', 'f', 'P', 'l', 'a', 'i', 'n', 'N', 'a', 'm', 'e') + RAPIDJSON_STRING_(RefInvalid, 'R', 'e', 'f', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + RAPIDJSON_STRING_(RefPointerInvalid, 'R', 'e', 'f', 'P', 'o', 'i', 'n', 't', 'e', 'r', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + RAPIDJSON_STRING_(RefUnknown, 'R', 'e', 'f', 'U', 'n', 'k', 'n', 'o', 'w', 'n') + RAPIDJSON_STRING_(RefCyclical, 'R', 'e', 'f', 'C', 'y', 'c', 'l', 'i', 'c', 'a', 'l') + RAPIDJSON_STRING_(RefNoRemoteProvider, 'R', 'e', 'f', 'N', 'o', 'R', 'e', 'm', 'o', 't', 'e', 'P', 'r', 'o', 'v', 'i', 'd', 'e', 'r') + RAPIDJSON_STRING_(RefNoRemoteSchema, 'R', 'e', 'f', 'N', 'o', 'R', 'e', 'm', 'o', 't', 'e', 'S', 'c', 'h', 'e', 'm', 'a') + RAPIDJSON_STRING_(ReadOnlyAndWriteOnly, 'R', 'e', 'a', 'd', 'O', 'n', 'l', 'y', 'A', 'n', 'd', 'W', 'r', 'i', 't', 'e', 'O', 'n', 'l', 'y') + RAPIDJSON_STRING_(RegexInvalid, 'R', 'e', 'g', 'e', 'x', 'I', 'n', 'v', 'a', 'l', 'i', 'd') + +#undef RAPIDJSON_STRING_ + + // Static method to get schema draft of any schema document + static SchemaDraft GetSchemaDraft(const ValueType& document) { + static const Ch kDraft03String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '3', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft04String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '4', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft05String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '5', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft06String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '6', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft07String[] = { 'h', 't', 't', 'p', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '-', '0', '7', '/', 's', 'c', 'h', 'e', 'm', 'a', '#', '\0' }; + static const Ch kDraft2019_09String[] = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '/', '2', '0', '1', '9', '-', '0', '9', '/', 's', 'c', 'h', 'e', 'm', 'a', '\0' }; + static const Ch kDraft2020_12String[] = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'j', 's', 'o', 'n', '-', 's', 'c', 'h', 'e', 'm', 'a', '.', 'o', 'r', 'g', '/', 'd', 'r', 'a', 'f', 't', '/', '2', '0', '2', '0', '-', '1', '2', '/', 's', 'c', 'h', 'e', 'm', 'a', '\0' }; + + if (!document.IsObject()) { + return kDraftNone; + } + + // Get the schema draft from the $schema keyword at the supplied location + typename ValueType::ConstMemberIterator itr = document.FindMember(SchemaType::GetSchemaString()); + if (itr != document.MemberEnd()) { + if (!itr->value.IsString()) return kDraftUnknown; + const UriType draftUri(itr->value); + // Check base uri for match + if (draftUri.Match(UriType(kDraft04String), false)) return kDraft04; + if (draftUri.Match(UriType(kDraft05String), false)) return kDraft05; + if (draftUri.Match(UriType(kDraft06String), false)) return kDraft06; + if (draftUri.Match(UriType(kDraft07String), false)) return kDraft07; + if (draftUri.Match(UriType(kDraft03String), false)) return kDraft03; + if (draftUri.Match(UriType(kDraft2019_09String), false)) return kDraft2019_09; + if (draftUri.Match(UriType(kDraft2020_12String), false)) return kDraft2020_12; + return kDraftUnknown; + } + // $schema not found + return kDraftNone; + } + + + // Get open api version of any schema document + static OpenApiVersion GetOpenApiVersion(const ValueType& document) { + static const Ch kVersion20String[] = { '2', '.', '0', '\0' }; + static const Ch kVersion30String[] = { '3', '.', '0', '.', '\0' }; // ignore patch level + static const Ch kVersion31String[] = { '3', '.', '1', '.', '\0' }; // ignore patch level + static SizeType len = internal::StrLen(kVersion30String); + + if (!document.IsObject()) { + return kVersionNone; + } + + // Get the open api version from the swagger / openapi keyword at the supplied location + typename ValueType::ConstMemberIterator itr = document.FindMember(SchemaType::GetSwaggerString()); + if (itr == document.MemberEnd()) itr = document.FindMember(SchemaType::GetOpenApiString()); + if (itr != document.MemberEnd()) { + if (!itr->value.IsString()) return kVersionUnknown; + const ValueType kVersion20Value(kVersion20String); + if (kVersion20Value == itr->value) return kVersion20; // must match 2.0 exactly + const ValueType kVersion30Value(kVersion30String); + if (itr->value.GetStringLength() > len && kVersion30Value == ValueType(itr->value.GetString(), len)) return kVersion30; // must match 3.0.x + const ValueType kVersion31Value(kVersion31String); + if (itr->value.GetStringLength() > len && kVersion31Value == ValueType(itr->value.GetString(), len)) return kVersion31; // must match 3.1.x + return kVersionUnknown; + } + // swagger or openapi not found + return kVersionNone; + } + + // Get the draft of the schema or the open api version (which implies the draft). + // Report an error if schema draft or open api version not supported or not recognized, or both in document, and carry on. + void SetSchemaSpecification(const ValueType& document) { + // Look for '$schema', 'swagger' or 'openapi' keyword at document root + SchemaDraft docDraft = GetSchemaDraft(document); + OpenApiVersion docOapi = GetOpenApiVersion(document); + // Error if both in document + if (docDraft != kDraftNone && docOapi != kVersionNone) + SchemaError(kSchemaErrorSpecIllegal, PointerType()); + // Use document draft or open api version if present or use spec from constructor + if (docDraft != kDraftNone) + spec_ = Specification(docDraft); + else if (docOapi != kVersionNone) + spec_ = Specification(docOapi); + // Error if draft or version unknown + if (spec_.draft == kDraftUnknown || spec_.oapi == kVersionUnknown) + SchemaError(kSchemaErrorSpecUnknown, PointerType()); + else if (!spec_.IsSupported()) + SchemaError(kSchemaErrorSpecUnsupported, PointerType()); + } + + // Changed by PR #1393 + void CreateSchemaRecursive(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document, const UriType& id) { + if (v.GetType() == kObjectType) { + UriType newid = UriType(CreateSchema(schema, pointer, v, document, id), allocator_); + + for (typename ValueType::ConstMemberIterator itr = v.MemberBegin(); itr != v.MemberEnd(); ++itr) + CreateSchemaRecursive(0, pointer.Append(itr->name, allocator_), itr->value, document, newid); + } + else if (v.GetType() == kArrayType) + for (SizeType i = 0; i < v.Size(); i++) + CreateSchemaRecursive(0, pointer.Append(i, allocator_), v[i], document, id); + } + + // Changed by PR #1393 + const UriType& CreateSchema(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document, const UriType& id) { + RAPIDJSON_ASSERT(pointer.IsValid()); + GenericStringBuffer sb; + pointer.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::CreateSchema", sb.GetString(), id.GetString()); + if (v.IsObject()) { + if (const SchemaType* sc = GetSchema(pointer)) { + if (schema) + *schema = sc; + AddSchemaRefs(const_cast(sc)); + } + else if (!HandleRefSchema(pointer, schema, v, document, id)) { + // The new schema constructor adds itself and its $ref(s) to schemaMap_ + SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, document, allocator_, id); + if (schema) + *schema = s; + return s->GetId(); + } + } + else { + if (schema) + *schema = typeless_; + AddSchemaRefs(typeless_); + } + return id; + } + + // Changed by PR #1393 + // TODO should this return a UriType& ? + bool HandleRefSchema(const PointerType& source, const SchemaType** schema, const ValueType& v, const ValueType& document, const UriType& id) { + typename ValueType::ConstMemberIterator itr = v.FindMember(SchemaType::GetRefString()); + if (itr == v.MemberEnd()) + return false; + + GenericStringBuffer sb; + source.StringifyUriFragment(sb); + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::HandleRefSchema", sb.GetString(), id.GetString()); + // Resolve the source pointer to the $ref'ed schema (finally) + new (schemaRef_.template Push()) SchemaRefPtr(&source); + + if (itr->value.IsString()) { + SizeType len = itr->value.GetStringLength(); + if (len == 0) + SchemaError(kSchemaErrorRefInvalid, source); + else { + // First resolve $ref against the in-scope id + UriType scopeId = UriType(id, allocator_); + UriType ref = UriType(itr->value, allocator_).Resolve(scopeId, allocator_); + RAPIDJSON_SCHEMA_PRINT(SchemaIds, id.GetString(), itr->value.GetString(), ref.GetString()); + // See if the resolved $ref minus the fragment matches a resolved id in this document + // Search from the root. Returns the subschema in the document and its absolute JSON pointer. + PointerType basePointer = PointerType(); + const ValueType *base = FindId(document, ref, basePointer, docId_, false); + if (!base) { + // Remote reference - call the remote document provider + if (!remoteProvider_) + SchemaError(kSchemaErrorRefNoRemoteProvider, source); + else { + if (const GenericSchemaDocument* remoteDocument = remoteProvider_->GetRemoteDocument(ref, spec_)) { + const Ch* s = ref.GetFragString(); + len = ref.GetFragStringLength(); + if (len <= 1 || s[1] == '/') { + // JSON pointer fragment, absolute in the remote schema + const PointerType pointer(s, len, allocator_); + if (!pointer.IsValid()) + SchemaErrorPointer(kSchemaErrorRefPointerInvalid, source, s, len, pointer); + else { + // Get the subschema + if (const SchemaType *sc = remoteDocument->GetSchema(pointer)) { + if (schema) + *schema = sc; + AddSchemaRefs(const_cast(sc)); + return true; + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); + } + } else + // Plain name fragment, not allowed in remote schema + SchemaErrorValue(kSchemaErrorRefPlainName, source, s, len); + } else + SchemaErrorValue(kSchemaErrorRefNoRemoteSchema, source, ref.GetString(), ref.GetStringLength()); + } + } + else { // Local reference + const Ch* s = ref.GetFragString(); + len = ref.GetFragStringLength(); + if (len <= 1 || s[1] == '/') { + // JSON pointer fragment, relative to the resolved URI + const PointerType relPointer(s, len, allocator_); + if (!relPointer.IsValid()) + SchemaErrorPointer(kSchemaErrorRefPointerInvalid, source, s, len, relPointer); + else { + // Get the subschema + if (const ValueType *pv = relPointer.Get(*base)) { + // Now get the absolute JSON pointer by adding relative to base + PointerType pointer(basePointer, allocator_); + for (SizeType i = 0; i < relPointer.GetTokenCount(); i++) + pointer = pointer.Append(relPointer.GetTokens()[i], allocator_); + if (IsCyclicRef(pointer)) + SchemaErrorValue(kSchemaErrorRefCyclical, source, ref.GetString(), ref.GetStringLength()); + else { + // Call CreateSchema recursively, but first compute the in-scope id for the $ref target as we have jumped there + // TODO: cache pointer <-> id mapping + size_t unresolvedTokenIndex; + scopeId = pointer.GetUri(document, docId_, &unresolvedTokenIndex, allocator_); + CreateSchema(schema, pointer, *pv, document, scopeId); + return true; + } + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); + } + } else { + // Plain name fragment, relative to the resolved URI + // Not supported in open api 2.0 and 3.0 + PointerType pointer(allocator_); + if (spec_.oapi == kVersion20 || spec_.oapi == kVersion30) + SchemaErrorValue(kSchemaErrorRefPlainName, source, s, len); + // See if the fragment matches an id in this document. + // Search from the base we just established. Returns the subschema in the document and its absolute JSON pointer. + else if (const ValueType *pv = FindId(*base, ref, pointer, UriType(ref.GetBaseString(), ref.GetBaseStringLength(), allocator_), true, basePointer)) { + if (IsCyclicRef(pointer)) + SchemaErrorValue(kSchemaErrorRefCyclical, source, ref.GetString(), ref.GetStringLength()); + else { + // Call CreateSchema recursively, but first compute the in-scope id for the $ref target as we have jumped there + // TODO: cache pointer <-> id mapping + size_t unresolvedTokenIndex; + scopeId = pointer.GetUri(document, docId_, &unresolvedTokenIndex, allocator_); + CreateSchema(schema, pointer, *pv, document, scopeId); + return true; + } + } else + SchemaErrorValue(kSchemaErrorRefUnknown, source, ref.GetString(), ref.GetStringLength()); + } + } + } + } + + // Invalid/Unknown $ref + if (schema) + *schema = typeless_; + AddSchemaRefs(typeless_); + return true; + } + + //! Find the first subschema with a resolved 'id' that matches the specified URI. + // If full specified use all URI else ignore fragment. + // If found, return a pointer to the subschema and its JSON pointer. + // TODO cache pointer <-> id mapping + ValueType* FindId(const ValueType& doc, const UriType& finduri, PointerType& resptr, const UriType& baseuri, bool full, const PointerType& here = PointerType()) const { + SizeType i = 0; + ValueType* resval = 0; + UriType tempuri = UriType(finduri, allocator_); + UriType localuri = UriType(baseuri, allocator_); + if (doc.GetType() == kObjectType) { + // Establish the base URI of this object + typename ValueType::ConstMemberIterator m = doc.FindMember(SchemaType::GetIdString()); + if (m != doc.MemberEnd() && m->value.GetType() == kStringType) { + localuri = UriType(m->value, allocator_).Resolve(baseuri, allocator_); + } + // See if it matches + if (localuri.Match(finduri, full)) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::FindId (match)", full ? localuri.GetString() : localuri.GetBaseString()); + resval = const_cast(&doc); + resptr = here; + return resval; + } + // No match, continue looking + for (m = doc.MemberBegin(); m != doc.MemberEnd(); ++m) { + if (m->value.GetType() == kObjectType || m->value.GetType() == kArrayType) { + resval = FindId(m->value, finduri, resptr, localuri, full, here.Append(m->name.GetString(), m->name.GetStringLength(), allocator_)); + } + if (resval) break; + } + } else if (doc.GetType() == kArrayType) { + // Continue looking + for (typename ValueType::ConstValueIterator v = doc.Begin(); v != doc.End(); ++v) { + if (v->GetType() == kObjectType || v->GetType() == kArrayType) { + resval = FindId(*v, finduri, resptr, localuri, full, here.Append(i, allocator_)); + } + if (resval) break; + i++; + } + } + return resval; + } + + // Added by PR #1393 + void AddSchemaRefs(SchemaType* schema) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaDocument::AddSchemaRefs"); + while (!schemaRef_.Empty()) { + SchemaRefPtr *ref = schemaRef_.template Pop(1); + SchemaEntry *entry = schemaMap_.template Push(); + new (entry) SchemaEntry(**ref, schema, false, allocator_); + } + } + + // Added by PR #1393 + bool IsCyclicRef(const PointerType& pointer) const { + for (const SchemaRefPtr* ref = schemaRef_.template Bottom(); ref != schemaRef_.template End(); ++ref) + if (pointer == **ref) + return true; + return false; + } + + const SchemaType* GetSchema(const PointerType& pointer) const { + for (const SchemaEntry* target = schemaMap_.template Bottom(); target != schemaMap_.template End(); ++target) + if (pointer == target->pointer) + return target->schema; + return 0; + } + + PointerType GetPointer(const SchemaType* schema) const { + for (const SchemaEntry* target = schemaMap_.template Bottom(); target != schemaMap_.template End(); ++target) + if (schema == target->schema) + return target->pointer; + return PointerType(); + } + + const SchemaType* GetTypeless() const { return typeless_; } + + static const size_t kInitialSchemaMapSize = 64; + static const size_t kInitialSchemaRefSize = 64; + + IRemoteSchemaDocumentProviderType* remoteProvider_; + Allocator *allocator_; + Allocator *ownAllocator_; + const SchemaType* root_; //!< Root schema. + SchemaType* typeless_; + internal::Stack schemaMap_; // Stores created Pointer -> Schemas + internal::Stack schemaRef_; // Stores Pointer(s) from $ref(s) until resolved + GValue uri_; // Schema document URI + UriType docId_; + Specification spec_; + GValue error_; + GValue currentError_; +}; + +//! GenericSchemaDocument using Value type. +typedef GenericSchemaDocument SchemaDocument; +//! IGenericRemoteSchemaDocumentProvider using SchemaDocument. +typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; + +/////////////////////////////////////////////////////////////////////////////// +// GenericSchemaValidator + +//! JSON Schema Validator. +/*! + A SAX style JSON schema validator. + It uses a \c GenericSchemaDocument to validate SAX events. + It delegates the incoming SAX events to an output handler. + The default output handler does nothing. + It can be reused multiple times by calling \c Reset(). + + \tparam SchemaDocumentType Type of schema document. + \tparam OutputHandler Type of output handler. Default handler does nothing. + \tparam StateAllocator Allocator for storing the internal validation states. +*/ +template < + typename SchemaDocumentType, + typename OutputHandler = BaseReaderHandler, + typename StateAllocator = CrtAllocator> +class GenericSchemaValidator : + public internal::ISchemaStateFactory, + public internal::ISchemaValidator, + public internal::IValidationErrorHandler { +public: + typedef typename SchemaDocumentType::SchemaType SchemaType; + typedef typename SchemaDocumentType::PointerType PointerType; + typedef typename SchemaType::EncodingType EncodingType; + typedef typename SchemaType::SValue SValue; + typedef typename EncodingType::Ch Ch; + typedef GenericStringRef StringRefType; + typedef GenericValue ValueType; + + //! Constructor without output handler. + /*! + \param schemaDocument The schema document to conform to. + \param allocator Optional allocator for storing internal validation states. + \param schemaStackCapacity Optional initial capacity of schema path stack. + \param documentStackCapacity Optional initial capacity of document path stack. + */ + GenericSchemaValidator( + const SchemaDocumentType& schemaDocument, + StateAllocator* allocator = 0, + size_t schemaStackCapacity = kDefaultSchemaStackCapacity, + size_t documentStackCapacity = kDefaultDocumentStackCapacity) + : + schemaDocument_(&schemaDocument), + root_(schemaDocument.GetRoot()), + stateAllocator_(allocator), + ownStateAllocator_(0), + schemaStack_(allocator, schemaStackCapacity), + documentStack_(allocator, documentStackCapacity), + outputHandler_(0), + error_(kObjectType), + currentError_(), + missingDependents_(), + valid_(true), + flags_(kValidateDefaultFlags), + depth_(0) + { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator"); + } + + //! Constructor with output handler. + /*! + \param schemaDocument The schema document to conform to. + \param allocator Optional allocator for storing internal validation states. + \param schemaStackCapacity Optional initial capacity of schema path stack. + \param documentStackCapacity Optional initial capacity of document path stack. + */ + GenericSchemaValidator( + const SchemaDocumentType& schemaDocument, + OutputHandler& outputHandler, + StateAllocator* allocator = 0, + size_t schemaStackCapacity = kDefaultSchemaStackCapacity, + size_t documentStackCapacity = kDefaultDocumentStackCapacity) + : + schemaDocument_(&schemaDocument), + root_(schemaDocument.GetRoot()), + stateAllocator_(allocator), + ownStateAllocator_(0), + schemaStack_(allocator, schemaStackCapacity), + documentStack_(allocator, documentStackCapacity), + outputHandler_(&outputHandler), + error_(kObjectType), + currentError_(), + missingDependents_(), + valid_(true), + flags_(kValidateDefaultFlags), + depth_(0) + { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator (output handler)"); + } + + //! Destructor. + ~GenericSchemaValidator() { + Reset(); + RAPIDJSON_DELETE(ownStateAllocator_); + } + + //! Reset the internal states. + void Reset() { + while (!schemaStack_.Empty()) + PopSchema(); + documentStack_.Clear(); + ResetError(); + } + + //! Reset the error state. + void ResetError() { + error_.SetObject(); + currentError_.SetNull(); + missingDependents_.SetNull(); + valid_ = true; + } + + //! Implementation of ISchemaValidator + void SetValidateFlags(unsigned flags) { + flags_ = flags; + } + virtual unsigned GetValidateFlags() const { + return flags_; + } + + virtual bool IsValid() const { + if (!valid_) return false; + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return false; + return true; + } + //! End of Implementation of ISchemaValidator + + //! Gets the error object. + ValueType& GetError() { return error_; } + const ValueType& GetError() const { return error_; } + + //! Gets the JSON pointer pointed to the invalid schema. + // If reporting all errors, the stack will be empty. + PointerType GetInvalidSchemaPointer() const { + return schemaStack_.Empty() ? PointerType() : CurrentSchema().GetPointer(); + } + + //! Gets the keyword of invalid schema. + // If reporting all errors, the stack will be empty, so return "errors". + const Ch* GetInvalidSchemaKeyword() const { + if (!schemaStack_.Empty()) return CurrentContext().invalidKeyword; + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return (const Ch*)GetErrorsString(); + return 0; + } + + //! Gets the error code of invalid schema. + // If reporting all errors, the stack will be empty, so return kValidateErrors. + ValidateErrorCode GetInvalidSchemaCode() const { + if (!schemaStack_.Empty()) return CurrentContext().invalidCode; + if (GetContinueOnErrors() && !error_.ObjectEmpty()) return kValidateErrors; + return kValidateErrorNone; + } + + //! Gets the JSON pointer pointed to the invalid value. + // If reporting all errors, the stack will be empty. + PointerType GetInvalidDocumentPointer() const { + if (documentStack_.Empty()) { + return PointerType(); + } + else { + return PointerType(documentStack_.template Bottom(), documentStack_.GetSize() / sizeof(Ch)); + } + } + + void NotMultipleOf(int64_t actual, const SValue& expected) { + AddNumberError(kValidateErrorMultipleOf, ValueType(actual).Move(), expected); + } + void NotMultipleOf(uint64_t actual, const SValue& expected) { + AddNumberError(kValidateErrorMultipleOf, ValueType(actual).Move(), expected); + } + void NotMultipleOf(double actual, const SValue& expected) { + AddNumberError(kValidateErrorMultipleOf, ValueType(actual).Move(), expected); + } + void AboveMaximum(int64_t actual, const SValue& expected, bool exclusive) { + AddNumberError(exclusive ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum, ValueType(actual).Move(), expected, + exclusive ? &SchemaType::GetExclusiveMaximumString : 0); + } + void AboveMaximum(uint64_t actual, const SValue& expected, bool exclusive) { + AddNumberError(exclusive ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum, ValueType(actual).Move(), expected, + exclusive ? &SchemaType::GetExclusiveMaximumString : 0); + } + void AboveMaximum(double actual, const SValue& expected, bool exclusive) { + AddNumberError(exclusive ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum, ValueType(actual).Move(), expected, + exclusive ? &SchemaType::GetExclusiveMaximumString : 0); + } + void BelowMinimum(int64_t actual, const SValue& expected, bool exclusive) { + AddNumberError(exclusive ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum, ValueType(actual).Move(), expected, + exclusive ? &SchemaType::GetExclusiveMinimumString : 0); + } + void BelowMinimum(uint64_t actual, const SValue& expected, bool exclusive) { + AddNumberError(exclusive ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum, ValueType(actual).Move(), expected, + exclusive ? &SchemaType::GetExclusiveMinimumString : 0); + } + void BelowMinimum(double actual, const SValue& expected, bool exclusive) { + AddNumberError(exclusive ? kValidateErrorExclusiveMinimum : kValidateErrorMinimum, ValueType(actual).Move(), expected, + exclusive ? &SchemaType::GetExclusiveMinimumString : 0); + } + + void TooLong(const Ch* str, SizeType length, SizeType expected) { + AddNumberError(kValidateErrorMaxLength, + ValueType(str, length, GetStateAllocator()).Move(), SValue(expected).Move()); + } + void TooShort(const Ch* str, SizeType length, SizeType expected) { + AddNumberError(kValidateErrorMinLength, + ValueType(str, length, GetStateAllocator()).Move(), SValue(expected).Move()); + } + void DoesNotMatch(const Ch* str, SizeType length) { + currentError_.SetObject(); + currentError_.AddMember(GetActualString(), ValueType(str, length, GetStateAllocator()).Move(), GetStateAllocator()); + AddCurrentError(kValidateErrorPattern); + } + + void DisallowedItem(SizeType index) { + currentError_.SetObject(); + currentError_.AddMember(GetDisallowedString(), ValueType(index).Move(), GetStateAllocator()); + AddCurrentError(kValidateErrorAdditionalItems, true); + } + void TooFewItems(SizeType actualCount, SizeType expectedCount) { + AddNumberError(kValidateErrorMinItems, + ValueType(actualCount).Move(), SValue(expectedCount).Move()); + } + void TooManyItems(SizeType actualCount, SizeType expectedCount) { + AddNumberError(kValidateErrorMaxItems, + ValueType(actualCount).Move(), SValue(expectedCount).Move()); + } + void DuplicateItems(SizeType index1, SizeType index2) { + ValueType duplicates(kArrayType); + duplicates.PushBack(index1, GetStateAllocator()); + duplicates.PushBack(index2, GetStateAllocator()); + currentError_.SetObject(); + currentError_.AddMember(GetDuplicatesString(), duplicates, GetStateAllocator()); + AddCurrentError(kValidateErrorUniqueItems, true); + } + + void TooManyProperties(SizeType actualCount, SizeType expectedCount) { + AddNumberError(kValidateErrorMaxProperties, + ValueType(actualCount).Move(), SValue(expectedCount).Move()); + } + void TooFewProperties(SizeType actualCount, SizeType expectedCount) { + AddNumberError(kValidateErrorMinProperties, + ValueType(actualCount).Move(), SValue(expectedCount).Move()); + } + void StartMissingProperties() { + currentError_.SetArray(); + } + void AddMissingProperty(const SValue& name) { + currentError_.PushBack(ValueType(name, GetStateAllocator()).Move(), GetStateAllocator()); + } + bool EndMissingProperties() { + if (currentError_.Empty()) + return false; + ValueType error(kObjectType); + error.AddMember(GetMissingString(), currentError_, GetStateAllocator()); + currentError_ = error; + AddCurrentError(kValidateErrorRequired); + return true; + } + void PropertyViolations(ISchemaValidator** subvalidators, SizeType count) { + for (SizeType i = 0; i < count; ++i) + MergeError(static_cast(subvalidators[i])->GetError()); + } + void DisallowedProperty(const Ch* name, SizeType length) { + currentError_.SetObject(); + currentError_.AddMember(GetDisallowedString(), ValueType(name, length, GetStateAllocator()).Move(), GetStateAllocator()); + AddCurrentError(kValidateErrorAdditionalProperties, true); + } + + void StartDependencyErrors() { + currentError_.SetObject(); + } + void StartMissingDependentProperties() { + missingDependents_.SetArray(); + } + void AddMissingDependentProperty(const SValue& targetName) { + missingDependents_.PushBack(ValueType(targetName, GetStateAllocator()).Move(), GetStateAllocator()); + } + void EndMissingDependentProperties(const SValue& sourceName) { + if (!missingDependents_.Empty()) { + // Create equivalent 'required' error + ValueType error(kObjectType); + ValidateErrorCode code = kValidateErrorRequired; + error.AddMember(GetMissingString(), missingDependents_.Move(), GetStateAllocator()); + AddErrorCode(error, code); + AddErrorInstanceLocation(error, false); + // When appending to a pointer ensure its allocator is used + PointerType schemaRef = GetInvalidSchemaPointer().Append(SchemaType::GetValidateErrorKeyword(kValidateErrorDependencies), &GetInvalidSchemaPointer().GetAllocator()); + AddErrorSchemaLocation(error, schemaRef.Append(sourceName.GetString(), sourceName.GetStringLength(), &GetInvalidSchemaPointer().GetAllocator())); + ValueType wrapper(kObjectType); + wrapper.AddMember(ValueType(SchemaType::GetValidateErrorKeyword(code), GetStateAllocator()).Move(), error, GetStateAllocator()); + currentError_.AddMember(ValueType(sourceName, GetStateAllocator()).Move(), wrapper, GetStateAllocator()); + } + } + void AddDependencySchemaError(const SValue& sourceName, ISchemaValidator* subvalidator) { + currentError_.AddMember(ValueType(sourceName, GetStateAllocator()).Move(), + static_cast(subvalidator)->GetError(), GetStateAllocator()); + } + bool EndDependencyErrors() { + if (currentError_.ObjectEmpty()) + return false; + ValueType error(kObjectType); + error.AddMember(GetErrorsString(), currentError_, GetStateAllocator()); + currentError_ = error; + AddCurrentError(kValidateErrorDependencies); + return true; + } + + void DisallowedValue(const ValidateErrorCode code = kValidateErrorEnum) { + currentError_.SetObject(); + AddCurrentError(code); + } + void StartDisallowedType() { + currentError_.SetArray(); + } + void AddExpectedType(const typename SchemaType::ValueType& expectedType) { + currentError_.PushBack(ValueType(expectedType, GetStateAllocator()).Move(), GetStateAllocator()); + } + void EndDisallowedType(const typename SchemaType::ValueType& actualType) { + ValueType error(kObjectType); + error.AddMember(GetExpectedString(), currentError_, GetStateAllocator()); + error.AddMember(GetActualString(), ValueType(actualType, GetStateAllocator()).Move(), GetStateAllocator()); + currentError_ = error; + AddCurrentError(kValidateErrorType); + } + void NotAllOf(ISchemaValidator** subvalidators, SizeType count) { + // Treat allOf like oneOf and anyOf to match https://rapidjson.org/md_doc_schema.html#allOf-anyOf-oneOf + AddErrorArray(kValidateErrorAllOf, subvalidators, count); + //for (SizeType i = 0; i < count; ++i) { + // MergeError(static_cast(subvalidators[i])->GetError()); + //} + } + void NoneOf(ISchemaValidator** subvalidators, SizeType count) { + AddErrorArray(kValidateErrorAnyOf, subvalidators, count); + } + void NotOneOf(ISchemaValidator** subvalidators, SizeType count) { + AddErrorArray(kValidateErrorOneOf, subvalidators, count); + } + void MultipleOneOf(SizeType index1, SizeType index2) { + ValueType matches(kArrayType); + matches.PushBack(index1, GetStateAllocator()); + matches.PushBack(index2, GetStateAllocator()); + currentError_.SetObject(); + currentError_.AddMember(GetMatchesString(), matches, GetStateAllocator()); + AddCurrentError(kValidateErrorOneOfMatch); + } + void Disallowed() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorNot); + } + void DisallowedWhenWriting() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorReadOnly); + } + void DisallowedWhenReading() { + currentError_.SetObject(); + AddCurrentError(kValidateErrorWriteOnly); + } + +#define RAPIDJSON_STRING_(name, ...) \ + static const StringRefType& Get##name##String() {\ + static const Ch s[] = { __VA_ARGS__, '\0' };\ + static const StringRefType v(s, static_cast(sizeof(s) / sizeof(Ch) - 1)); \ + return v;\ + } + + RAPIDJSON_STRING_(InstanceRef, 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 'R', 'e', 'f') + RAPIDJSON_STRING_(SchemaRef, 's', 'c', 'h', 'e', 'm', 'a', 'R', 'e', 'f') + RAPIDJSON_STRING_(Expected, 'e', 'x', 'p', 'e', 'c', 't', 'e', 'd') + RAPIDJSON_STRING_(Actual, 'a', 'c', 't', 'u', 'a', 'l') + RAPIDJSON_STRING_(Disallowed, 'd', 'i', 's', 'a', 'l', 'l', 'o', 'w', 'e', 'd') + RAPIDJSON_STRING_(Missing, 'm', 'i', 's', 's', 'i', 'n', 'g') + RAPIDJSON_STRING_(Errors, 'e', 'r', 'r', 'o', 'r', 's') + RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e') + RAPIDJSON_STRING_(ErrorMessage, 'e', 'r', 'r', 'o', 'r', 'M', 'e', 's', 's', 'a', 'g', 'e') + RAPIDJSON_STRING_(Duplicates, 'd', 'u', 'p', 'l', 'i', 'c', 'a', 't', 'e', 's') + RAPIDJSON_STRING_(Matches, 'm', 'a', 't', 'c', 'h', 'e', 's') + +#undef RAPIDJSON_STRING_ + +#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)\ + if (!valid_) return false; \ + if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) {\ + *documentStack_.template Push() = '\0';\ + documentStack_.template Pop(1);\ + RAPIDJSON_SCHEMA_PRINT(InvalidDocument, documentStack_.template Bottom());\ + valid_ = false;\ + return valid_;\ + } + +#define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\ + for (Context* context = schemaStack_.template Bottom(); context != schemaStack_.template End(); context++) {\ + if (context->hasher)\ + static_cast(context->hasher)->method arg2;\ + if (context->validators)\ + for (SizeType i_ = 0; i_ < context->validatorCount; i_++)\ + static_cast(context->validators[i_])->method arg2;\ + if (context->patternPropertiesValidators)\ + for (SizeType i_ = 0; i_ < context->patternPropertiesValidatorCount; i_++)\ + static_cast(context->patternPropertiesValidators[i_])->method arg2;\ + } + +#define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)\ + valid_ = (EndValue() || GetContinueOnErrors()) && (!outputHandler_ || outputHandler_->method arg2);\ + return valid_; + +#define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2) \ + RAPIDJSON_SCHEMA_HANDLE_BEGIN_ (method, arg1);\ + RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2);\ + RAPIDJSON_SCHEMA_HANDLE_END_ (method, arg2) + + bool Null() { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Null, (CurrentContext()), ( )); } + bool Bool(bool b) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Bool, (CurrentContext(), b), (b)); } + bool Int(int i) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Int, (CurrentContext(), i), (i)); } + bool Uint(unsigned u) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Uint, (CurrentContext(), u), (u)); } + bool Int64(int64_t i) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Int64, (CurrentContext(), i), (i)); } + bool Uint64(uint64_t u) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Uint64, (CurrentContext(), u), (u)); } + bool Double(double d) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Double, (CurrentContext(), d), (d)); } + bool RawNumber(const Ch* str, SizeType length, bool copy) + { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); } + bool String(const Ch* str, SizeType length, bool copy) + { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); } + + bool StartObject() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::StartObject"); + RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartObject, (CurrentContext())); + RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartObject, ()); + valid_ = !outputHandler_ || outputHandler_->StartObject(); + return valid_; + } + + bool Key(const Ch* str, SizeType len, bool copy) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::Key", str); + if (!valid_) return false; + AppendToken(str, len); + if (!CurrentSchema().Key(CurrentContext(), str, len, copy) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } + RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(Key, (str, len, copy)); + valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy); + return valid_; + } + + bool EndObject(SizeType memberCount) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndObject"); + if (!valid_) return false; + RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndObject, (memberCount)); + if (!CurrentSchema().EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } + RAPIDJSON_SCHEMA_HANDLE_END_(EndObject, (memberCount)); + } + + bool StartArray() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::StartArray"); + RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartArray, (CurrentContext())); + RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartArray, ()); + valid_ = !outputHandler_ || outputHandler_->StartArray(); + return valid_; + } + + bool EndArray(SizeType elementCount) { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndArray"); + if (!valid_) return false; + RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndArray, (elementCount)); + if (!CurrentSchema().EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors()) { + valid_ = false; + return valid_; + } + RAPIDJSON_SCHEMA_HANDLE_END_(EndArray, (elementCount)); + } + +#undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_ +#undef RAPIDJSON_SCHEMA_HANDLE_PARALLEL_ +#undef RAPIDJSON_SCHEMA_HANDLE_VALUE_ + + // Implementation of ISchemaStateFactory + virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root, const bool inheritContinueOnErrors) { + *documentStack_.template Push() = '\0'; + documentStack_.template Pop(1); + ISchemaValidator* sv = new (GetStateAllocator().Malloc(sizeof(GenericSchemaValidator))) GenericSchemaValidator(*schemaDocument_, root, documentStack_.template Bottom(), documentStack_.GetSize(), + depth_ + 1, + &GetStateAllocator()); + sv->SetValidateFlags(inheritContinueOnErrors ? GetValidateFlags() : GetValidateFlags() & ~(unsigned)kValidateContinueOnErrorFlag); + return sv; + } + + virtual void DestroySchemaValidator(ISchemaValidator* validator) { + GenericSchemaValidator* v = static_cast(validator); + v->~GenericSchemaValidator(); + StateAllocator::Free(v); + } + + virtual void* CreateHasher() { + return new (GetStateAllocator().Malloc(sizeof(HasherType))) HasherType(&GetStateAllocator()); + } + + virtual uint64_t GetHashCode(void* hasher) { + return static_cast(hasher)->GetHashCode(); + } + + virtual void DestroyHasher(void* hasher) { + HasherType* h = static_cast(hasher); + h->~HasherType(); + StateAllocator::Free(h); + } + + virtual void* MallocState(size_t size) { + return GetStateAllocator().Malloc(size); + } + + virtual void FreeState(void* p) { + StateAllocator::Free(p); + } + // End of implementation of ISchemaStateFactory + +private: + typedef typename SchemaType::Context Context; + typedef GenericValue, StateAllocator> HashCodeArray; + typedef internal::Hasher HasherType; + + GenericSchemaValidator( + const SchemaDocumentType& schemaDocument, + const SchemaType& root, + const char* basePath, size_t basePathSize, + unsigned depth, + StateAllocator* allocator = 0, + size_t schemaStackCapacity = kDefaultSchemaStackCapacity, + size_t documentStackCapacity = kDefaultDocumentStackCapacity) + : + schemaDocument_(&schemaDocument), + root_(root), + stateAllocator_(allocator), + ownStateAllocator_(0), + schemaStack_(allocator, schemaStackCapacity), + documentStack_(allocator, documentStackCapacity), + outputHandler_(0), + error_(kObjectType), + currentError_(), + missingDependents_(), + valid_(true), + flags_(kValidateDefaultFlags), + depth_(depth) + { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::GenericSchemaValidator (internal)", basePath && basePathSize ? basePath : ""); + if (basePath && basePathSize) + memcpy(documentStack_.template Push(basePathSize), basePath, basePathSize); + } + + StateAllocator& GetStateAllocator() { + if (!stateAllocator_) + stateAllocator_ = ownStateAllocator_ = RAPIDJSON_NEW(StateAllocator)(); + return *stateAllocator_; + } + + bool GetContinueOnErrors() const { + return flags_ & kValidateContinueOnErrorFlag; + } + + bool BeginValue() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::BeginValue"); + if (schemaStack_.Empty()) + PushSchema(root_); + else { + if (CurrentContext().inArray) + internal::TokenHelper, Ch>::AppendIndexToken(documentStack_, CurrentContext().arrayElementIndex); + + if (!CurrentSchema().BeginValue(CurrentContext()) && !GetContinueOnErrors()) + return false; + + SizeType count = CurrentContext().patternPropertiesSchemaCount; + const SchemaType** sa = CurrentContext().patternPropertiesSchemas; + typename Context::PatternValidatorType patternValidatorType = CurrentContext().valuePatternValidatorType; + bool valueUniqueness = CurrentContext().valueUniqueness; + RAPIDJSON_ASSERT(CurrentContext().valueSchema); + PushSchema(*CurrentContext().valueSchema); + + if (count > 0) { + CurrentContext().objectPatternValidatorType = patternValidatorType; + ISchemaValidator**& va = CurrentContext().patternPropertiesValidators; + SizeType& validatorCount = CurrentContext().patternPropertiesValidatorCount; + va = static_cast(MallocState(sizeof(ISchemaValidator*) * count)); + std::memset(va, 0, sizeof(ISchemaValidator*) * count); + for (SizeType i = 0; i < count; i++) + va[validatorCount++] = CreateSchemaValidator(*sa[i], true); // Inherit continueOnError + } + + CurrentContext().arrayUniqueness = valueUniqueness; + } + return true; + } + + bool EndValue() { + RAPIDJSON_SCHEMA_PRINT(Method, "GenericSchemaValidator::EndValue"); + if (!CurrentSchema().EndValue(CurrentContext()) && !GetContinueOnErrors()) + return false; + + GenericStringBuffer sb; + schemaDocument_->GetPointer(&CurrentSchema()).StringifyUriFragment(sb); + *documentStack_.template Push() = '\0'; + documentStack_.template Pop(1); + RAPIDJSON_SCHEMA_PRINT(ValidatorPointers, sb.GetString(), documentStack_.template Bottom(), depth_); + void* hasher = CurrentContext().hasher; + uint64_t h = hasher && CurrentContext().arrayUniqueness ? static_cast(hasher)->GetHashCode() : 0; + + PopSchema(); + + if (!schemaStack_.Empty()) { + Context& context = CurrentContext(); + // Only check uniqueness if there is a hasher + if (hasher && context.valueUniqueness) { + HashCodeArray* a = static_cast(context.arrayElementHashCodes); + if (!a) + CurrentContext().arrayElementHashCodes = a = new (GetStateAllocator().Malloc(sizeof(HashCodeArray))) HashCodeArray(kArrayType); + for (typename HashCodeArray::ConstValueIterator itr = a->Begin(); itr != a->End(); ++itr) + if (itr->GetUint64() == h) { + DuplicateItems(static_cast(itr - a->Begin()), a->Size()); + // Cleanup before returning if continuing + if (GetContinueOnErrors()) { + a->PushBack(h, GetStateAllocator()); + while (!documentStack_.Empty() && *documentStack_.template Pop(1) != '/'); + } + RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorUniqueItems); + } + a->PushBack(h, GetStateAllocator()); + } + } + + // Remove the last token of document pointer + while (!documentStack_.Empty() && *documentStack_.template Pop(1) != '/') + ; + + return true; + } + + void AppendToken(const Ch* str, SizeType len) { + documentStack_.template Reserve(1 + len * 2); // worst case all characters are escaped as two characters + *documentStack_.template PushUnsafe() = '/'; + for (SizeType i = 0; i < len; i++) { + if (str[i] == '~') { + *documentStack_.template PushUnsafe() = '~'; + *documentStack_.template PushUnsafe() = '0'; + } + else if (str[i] == '/') { + *documentStack_.template PushUnsafe() = '~'; + *documentStack_.template PushUnsafe() = '1'; + } + else + *documentStack_.template PushUnsafe() = str[i]; + } + } + + RAPIDJSON_FORCEINLINE void PushSchema(const SchemaType& schema) { new (schemaStack_.template Push()) Context(*this, *this, &schema, flags_); } + + RAPIDJSON_FORCEINLINE void PopSchema() { + Context* c = schemaStack_.template Pop(1); + if (HashCodeArray* a = static_cast(c->arrayElementHashCodes)) { + a->~HashCodeArray(); + StateAllocator::Free(a); + } + c->~Context(); + } + + void AddErrorInstanceLocation(ValueType& result, bool parent) { + GenericStringBuffer sb; + PointerType instancePointer = GetInvalidDocumentPointer(); + ((parent && instancePointer.GetTokenCount() > 0) + ? PointerType(instancePointer.GetTokens(), instancePointer.GetTokenCount() - 1) + : instancePointer).StringifyUriFragment(sb); + ValueType instanceRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), + GetStateAllocator()); + result.AddMember(GetInstanceRefString(), instanceRef, GetStateAllocator()); + } + + void AddErrorSchemaLocation(ValueType& result, PointerType schema = PointerType()) { + GenericStringBuffer sb; + SizeType len = CurrentSchema().GetURI().GetStringLength(); + if (len) memcpy(sb.Push(len), CurrentSchema().GetURI().GetString(), len * sizeof(Ch)); + if (schema.GetTokenCount()) schema.StringifyUriFragment(sb); + else GetInvalidSchemaPointer().StringifyUriFragment(sb); + ValueType schemaRef(sb.GetString(), static_cast(sb.GetSize() / sizeof(Ch)), + GetStateAllocator()); + result.AddMember(GetSchemaRefString(), schemaRef, GetStateAllocator()); + } + + void AddErrorCode(ValueType& result, const ValidateErrorCode code) { + result.AddMember(GetErrorCodeString(), code, GetStateAllocator()); + } + + void AddError(ValueType& keyword, ValueType& error) { + typename ValueType::MemberIterator member = error_.FindMember(keyword); + if (member == error_.MemberEnd()) + error_.AddMember(keyword, error, GetStateAllocator()); + else { + if (member->value.IsObject()) { + ValueType errors(kArrayType); + errors.PushBack(member->value, GetStateAllocator()); + member->value = errors; + } + member->value.PushBack(error, GetStateAllocator()); + } + } + + void AddCurrentError(const ValidateErrorCode code, bool parent = false) { + AddErrorCode(currentError_, code); + AddErrorInstanceLocation(currentError_, parent); + AddErrorSchemaLocation(currentError_); + AddError(ValueType(SchemaType::GetValidateErrorKeyword(code), GetStateAllocator(), false).Move(), currentError_); + } + + void MergeError(ValueType& other) { + for (typename ValueType::MemberIterator it = other.MemberBegin(), end = other.MemberEnd(); it != end; ++it) { + AddError(it->name, it->value); + } + } + + void AddNumberError(const ValidateErrorCode code, ValueType& actual, const SValue& expected, + const typename SchemaType::ValueType& (*exclusive)() = 0) { + currentError_.SetObject(); + currentError_.AddMember(GetActualString(), actual, GetStateAllocator()); + currentError_.AddMember(GetExpectedString(), ValueType(expected, GetStateAllocator()).Move(), GetStateAllocator()); + if (exclusive) + currentError_.AddMember(ValueType(exclusive(), GetStateAllocator()).Move(), true, GetStateAllocator()); + AddCurrentError(code); + } + + void AddErrorArray(const ValidateErrorCode code, + ISchemaValidator** subvalidators, SizeType count) { + ValueType errors(kArrayType); + for (SizeType i = 0; i < count; ++i) + errors.PushBack(static_cast(subvalidators[i])->GetError(), GetStateAllocator()); + currentError_.SetObject(); + currentError_.AddMember(GetErrorsString(), errors, GetStateAllocator()); + AddCurrentError(code); + } + + const SchemaType& CurrentSchema() const { return *schemaStack_.template Top()->schema; } + Context& CurrentContext() { return *schemaStack_.template Top(); } + const Context& CurrentContext() const { return *schemaStack_.template Top(); } + + static const size_t kDefaultSchemaStackCapacity = 1024; + static const size_t kDefaultDocumentStackCapacity = 256; + const SchemaDocumentType* schemaDocument_; + const SchemaType& root_; + StateAllocator* stateAllocator_; + StateAllocator* ownStateAllocator_; + internal::Stack schemaStack_; //!< stack to store the current path of schema (BaseSchemaType *) + internal::Stack documentStack_; //!< stack to store the current path of validating document (Ch) + OutputHandler* outputHandler_; + ValueType error_; + ValueType currentError_; + ValueType missingDependents_; + bool valid_; + unsigned flags_; + unsigned depth_; +}; + +typedef GenericSchemaValidator SchemaValidator; + +/////////////////////////////////////////////////////////////////////////////// +// SchemaValidatingReader + +//! A helper class for parsing with validation. +/*! + This helper class is a functor, designed as a parameter of \ref GenericDocument::Populate(). + + \tparam parseFlags Combination of \ref ParseFlag. + \tparam InputStream Type of input stream, implementing Stream concept. + \tparam SourceEncoding Encoding of the input stream. + \tparam SchemaDocumentType Type of schema document. + \tparam StackAllocator Allocator type for stack. +*/ +template < + unsigned parseFlags, + typename InputStream, + typename SourceEncoding, + typename SchemaDocumentType = SchemaDocument, + typename StackAllocator = CrtAllocator> +class SchemaValidatingReader { +public: + typedef typename SchemaDocumentType::PointerType PointerType; + typedef typename InputStream::Ch Ch; + typedef GenericValue ValueType; + + //! Constructor + /*! + \param is Input stream. + \param sd Schema document. + */ + SchemaValidatingReader(InputStream& is, const SchemaDocumentType& sd) : is_(is), sd_(sd), invalidSchemaKeyword_(), invalidSchemaCode_(kValidateErrorNone), error_(kObjectType), isValid_(true) {} + + template + bool operator()(Handler& handler) { + GenericReader reader; + GenericSchemaValidator validator(sd_, handler); + parseResult_ = reader.template Parse(is_, validator); + + isValid_ = validator.IsValid(); + if (isValid_) { + invalidSchemaPointer_ = PointerType(); + invalidSchemaKeyword_ = 0; + invalidDocumentPointer_ = PointerType(); + error_.SetObject(); + } + else { + invalidSchemaPointer_ = validator.GetInvalidSchemaPointer(); + invalidSchemaKeyword_ = validator.GetInvalidSchemaKeyword(); + invalidSchemaCode_ = validator.GetInvalidSchemaCode(); + invalidDocumentPointer_ = validator.GetInvalidDocumentPointer(); + error_.CopyFrom(validator.GetError(), allocator_); + } + + return parseResult_; + } + + const ParseResult& GetParseResult() const { return parseResult_; } + bool IsValid() const { return isValid_; } + const PointerType& GetInvalidSchemaPointer() const { return invalidSchemaPointer_; } + const Ch* GetInvalidSchemaKeyword() const { return invalidSchemaKeyword_; } + const PointerType& GetInvalidDocumentPointer() const { return invalidDocumentPointer_; } + const ValueType& GetError() const { return error_; } + ValidateErrorCode GetInvalidSchemaCode() const { return invalidSchemaCode_; } + +private: + InputStream& is_; + const SchemaDocumentType& sd_; + + ParseResult parseResult_; + PointerType invalidSchemaPointer_; + const Ch* invalidSchemaKeyword_; + PointerType invalidDocumentPointer_; + ValidateErrorCode invalidSchemaCode_; + StackAllocator allocator_; + ValueType error_; + bool isValid_; +}; + +RAPIDJSON_NAMESPACE_END +RAPIDJSON_DIAG_POP + +#endif // RAPIDJSON_SCHEMA_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/stream.h b/components/thorvg-main/src/loaders/lottie/rapidjson/stream.h new file mode 100644 index 0000000..1fd7091 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/stream.h @@ -0,0 +1,223 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#include "rapidjson.h" + +#ifndef RAPIDJSON_STREAM_H_ +#define RAPIDJSON_STREAM_H_ + +#include "encodings.h" + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// Stream + +/*! \class rapidjson::Stream + \brief Concept for reading and writing characters. + + For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). + + For write-only stream, only need to implement Put() and Flush(). + +\code +concept Stream { + typename Ch; //!< Character type of the stream. + + //! Read the current character from stream without moving the read cursor. + Ch Peek() const; + + //! Read the current character from stream and moving the read cursor to next character. + Ch Take(); + + //! Get the current read cursor. + //! \return Number of characters read from start. + size_t Tell(); + + //! Begin writing operation at the current read pointer. + //! \return The begin writer pointer. + Ch* PutBegin(); + + //! Write a character. + void Put(Ch c); + + //! Flush the buffer. + void Flush(); + + //! End the writing operation. + //! \param begin The begin write pointer returned by PutBegin(). + //! \return Number of characters written. + size_t PutEnd(Ch* begin); +} +\endcode +*/ + +//! Provides additional information for stream. +/*! + By using traits pattern, this type provides a default configuration for stream. + For custom stream, this type can be specialized for other configuration. + See TEST(Reader, CustomStringStream) in readertest.cpp for example. +*/ +template +struct StreamTraits { + //! Whether to make local copy of stream for optimization during parsing. + /*! + By default, for safety, streams do not use local copy optimization. + Stream that can be copied fast should specialize this, like StreamTraits. + */ + enum { copyOptimization = 0 }; +}; + +//! Reserve n characters for writing to a stream. +template +inline void PutReserve(Stream& stream, size_t count) { + (void)stream; + (void)count; +} + +//! Write character to a stream, presuming buffer is reserved. +template +inline void PutUnsafe(Stream& stream, typename Stream::Ch c) { + stream.Put(c); +} + +//! Put N copies of a character to a stream. +template +inline void PutN(Stream& stream, Ch c, size_t n) { + PutReserve(stream, n); + for (size_t i = 0; i < n; i++) + PutUnsafe(stream, c); +} + +/////////////////////////////////////////////////////////////////////////////// +// GenericStreamWrapper + +//! A Stream Wrapper +/*! \tThis string stream is a wrapper for any stream by just forwarding any + \treceived message to the origin stream. + \note implements Stream concept +*/ + +#if defined(_MSC_VER) && _MSC_VER <= 1800 +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4702) // unreachable code +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +template > +class GenericStreamWrapper { +public: + typedef typename Encoding::Ch Ch; + GenericStreamWrapper(InputStream& is): is_(is) {} + + Ch Peek() const { return is_.Peek(); } + Ch Take() { return is_.Take(); } + size_t Tell() { return is_.Tell(); } + Ch* PutBegin() { return is_.PutBegin(); } + void Put(Ch ch) { is_.Put(ch); } + void Flush() { is_.Flush(); } + size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } + + // wrapper for MemoryStream + const Ch* Peek4() const { return is_.Peek4(); } + + // wrapper for AutoUTFInputStream + UTFType GetType() const { return is_.GetType(); } + bool HasBOM() const { return is_.HasBOM(); } + +protected: + InputStream& is_; +}; + +#if defined(_MSC_VER) && _MSC_VER <= 1800 +RAPIDJSON_DIAG_POP +#endif + +/////////////////////////////////////////////////////////////////////////////// +// StringStream + +//! Read-only string stream. +/*! \note implements Stream concept +*/ +template +struct GenericStringStream { + typedef typename Encoding::Ch Ch; + + GenericStringStream(const Ch *src) : src_(src), head_(src) {} + + Ch Peek() const { return *src_; } + Ch Take() { return *src_++; } + size_t Tell() const { return static_cast(src_ - head_); } + + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + void Put(Ch) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + + const Ch* src_; //!< Current read position. + const Ch* head_; //!< Original head of the string. +}; + +template +struct StreamTraits > { + enum { copyOptimization = 1 }; +}; + +//! String stream with UTF8 encoding. +typedef GenericStringStream > StringStream; + +/////////////////////////////////////////////////////////////////////////////// +// InsituStringStream + +//! A read-write string stream. +/*! This string stream is particularly designed for in-situ parsing. + \note implements Stream concept +*/ +template +struct GenericInsituStringStream { + typedef typename Encoding::Ch Ch; + + GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} + + // Read + Ch Peek() { return *src_; } + Ch Take() { return *src_++; } + size_t Tell() { return static_cast(src_ - head_); } + + // Write + void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } + + Ch* PutBegin() { return dst_ = src_; } + size_t PutEnd(Ch* begin) { return static_cast(dst_ - begin); } + void Flush() {} + + Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; } + void Pop(size_t count) { dst_ -= count; } + + Ch* src_; + Ch* dst_; + Ch* head_; +}; + +template +struct StreamTraits > { + enum { copyOptimization = 1 }; +}; + +//! Insitu string stream with UTF8 encoding. +typedef GenericInsituStringStream > InsituStringStream; + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_STREAM_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/stringbuffer.h b/components/thorvg-main/src/loaders/lottie/rapidjson/stringbuffer.h new file mode 100644 index 0000000..82ad3ca --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/stringbuffer.h @@ -0,0 +1,121 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_STRINGBUFFER_H_ +#define RAPIDJSON_STRINGBUFFER_H_ + +#include "stream.h" +#include "internal/stack.h" + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS +#include // std::move +#endif + +#include "internal/stack.h" + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +//! Represents an in-memory output stream. +/*! + \tparam Encoding Encoding of the stream. + \tparam Allocator type for allocating memory buffer. + \note implements Stream concept +*/ +template +class GenericStringBuffer { +public: + typedef typename Encoding::Ch Ch; + + GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} + GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { + if (&rhs != this) + stack_ = std::move(rhs.stack_); + return *this; + } +#endif + + void Put(Ch c) { *stack_.template Push() = c; } + void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } + void Flush() {} + + void Clear() { stack_.Clear(); } + void ShrinkToFit() { + // Push and pop a null terminator. This is safe. + *stack_.template Push() = '\0'; + stack_.ShrinkToFit(); + stack_.template Pop(1); + } + + void Reserve(size_t count) { stack_.template Reserve(count); } + Ch* Push(size_t count) { return stack_.template Push(count); } + Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } + void Pop(size_t count) { stack_.template Pop(count); } + + const Ch* GetString() const { + // Push and pop a null terminator. This is safe. + *stack_.template Push() = '\0'; + stack_.template Pop(1); + + return stack_.template Bottom(); + } + + //! Get the size of string in bytes in the string buffer. + size_t GetSize() const { return stack_.GetSize(); } + + //! Get the length of string in Ch in the string buffer. + size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); } + + static const size_t kDefaultCapacity = 256; + mutable internal::Stack stack_; + +private: + // Prohibit copy constructor & assignment operator. + GenericStringBuffer(const GenericStringBuffer&); + GenericStringBuffer& operator=(const GenericStringBuffer&); +}; + +//! String buffer with UTF8 encoding +typedef GenericStringBuffer > StringBuffer; + +template +inline void PutReserve(GenericStringBuffer& stream, size_t count) { + stream.Reserve(count); +} + +template +inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { + stream.PutUnsafe(c); +} + +//! Implement specialized version of PutN() with memset() for better performance. +template<> +inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { + std::memset(stream.stack_.Push(n), c, n * sizeof(c)); +} + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_STRINGBUFFER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/uri.h b/components/thorvg-main/src/loaders/lottie/rapidjson/uri.h new file mode 100644 index 0000000..f93e508 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/uri.h @@ -0,0 +1,481 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// (C) Copyright IBM Corporation 2021 +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_URI_H_ +#define RAPIDJSON_URI_H_ + +#include "internal/strfunc.h" + +#if defined(__clang__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(c++98-compat) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// GenericUri + +template +class GenericUri { +public: + typedef typename ValueType::Ch Ch; +#if RAPIDJSON_HAS_STDSTRING + typedef std::basic_string String; +#endif + + //! Constructors + GenericUri(Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + } + + GenericUri(const Ch* uri, SizeType len, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri, len); + } + + GenericUri(const Ch* uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri, internal::StrLen(uri)); + } + + // Use with specializations of GenericValue + template GenericUri(const T& uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + const Ch* u = uri.template Get(); // TypeHelper from document.h + Parse(u, internal::StrLen(u)); + } + +#if RAPIDJSON_HAS_STDSTRING + GenericUri(const String& uri, Allocator* allocator = 0) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + Parse(uri.c_str(), internal::StrLen(uri.c_str())); + } +#endif + + //! Copy constructor + GenericUri(const GenericUri& rhs) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(), ownAllocator_() { + *this = rhs; + } + + //! Copy constructor + GenericUri(const GenericUri& rhs, Allocator* allocator) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(allocator), ownAllocator_() { + *this = rhs; + } + + //! Destructor. + ~GenericUri() { + Free(); + RAPIDJSON_DELETE(ownAllocator_); + } + + //! Assignment operator + GenericUri& operator=(const GenericUri& rhs) { + if (this != &rhs) { + // Do not delete ownAllocator + Free(); + Allocate(rhs.GetStringLength()); + auth_ = CopyPart(scheme_, rhs.scheme_, rhs.GetSchemeStringLength()); + path_ = CopyPart(auth_, rhs.auth_, rhs.GetAuthStringLength()); + query_ = CopyPart(path_, rhs.path_, rhs.GetPathStringLength()); + frag_ = CopyPart(query_, rhs.query_, rhs.GetQueryStringLength()); + base_ = CopyPart(frag_, rhs.frag_, rhs.GetFragStringLength()); + uri_ = CopyPart(base_, rhs.base_, rhs.GetBaseStringLength()); + CopyPart(uri_, rhs.uri_, rhs.GetStringLength()); + } + return *this; + } + + //! Getters + // Use with specializations of GenericValue + template void Get(T& uri, Allocator& allocator) { + uri.template Set(this->GetString(), allocator); // TypeHelper from document.h + } + + const Ch* GetString() const { return uri_; } + SizeType GetStringLength() const { return uri_ == 0 ? 0 : internal::StrLen(uri_); } + const Ch* GetBaseString() const { return base_; } + SizeType GetBaseStringLength() const { return base_ == 0 ? 0 : internal::StrLen(base_); } + const Ch* GetSchemeString() const { return scheme_; } + SizeType GetSchemeStringLength() const { return scheme_ == 0 ? 0 : internal::StrLen(scheme_); } + const Ch* GetAuthString() const { return auth_; } + SizeType GetAuthStringLength() const { return auth_ == 0 ? 0 : internal::StrLen(auth_); } + const Ch* GetPathString() const { return path_; } + SizeType GetPathStringLength() const { return path_ == 0 ? 0 : internal::StrLen(path_); } + const Ch* GetQueryString() const { return query_; } + SizeType GetQueryStringLength() const { return query_ == 0 ? 0 : internal::StrLen(query_); } + const Ch* GetFragString() const { return frag_; } + SizeType GetFragStringLength() const { return frag_ == 0 ? 0 : internal::StrLen(frag_); } + +#if RAPIDJSON_HAS_STDSTRING + static String Get(const GenericUri& uri) { return String(uri.GetString(), uri.GetStringLength()); } + static String GetBase(const GenericUri& uri) { return String(uri.GetBaseString(), uri.GetBaseStringLength()); } + static String GetScheme(const GenericUri& uri) { return String(uri.GetSchemeString(), uri.GetSchemeStringLength()); } + static String GetAuth(const GenericUri& uri) { return String(uri.GetAuthString(), uri.GetAuthStringLength()); } + static String GetPath(const GenericUri& uri) { return String(uri.GetPathString(), uri.GetPathStringLength()); } + static String GetQuery(const GenericUri& uri) { return String(uri.GetQueryString(), uri.GetQueryStringLength()); } + static String GetFrag(const GenericUri& uri) { return String(uri.GetFragString(), uri.GetFragStringLength()); } +#endif + + //! Equality operators + bool operator==(const GenericUri& rhs) const { + return Match(rhs, true); + } + + bool operator!=(const GenericUri& rhs) const { + return !Match(rhs, true); + } + + bool Match(const GenericUri& uri, bool full = true) const { + Ch* s1; + Ch* s2; + if (full) { + s1 = uri_; + s2 = uri.uri_; + } else { + s1 = base_; + s2 = uri.base_; + } + if (s1 == s2) return true; + if (s1 == 0 || s2 == 0) return false; + return internal::StrCmp(s1, s2) == 0; + } + + //! Resolve this URI against another (base) URI in accordance with URI resolution rules. + // See https://tools.ietf.org/html/rfc3986 + // Use for resolving an id or $ref with an in-scope id. + // Returns a new GenericUri for the resolved URI. + GenericUri Resolve(const GenericUri& baseuri, Allocator* allocator = 0) { + GenericUri resuri; + resuri.allocator_ = allocator; + // Ensure enough space for combining paths + resuri.Allocate(GetStringLength() + baseuri.GetStringLength() + 1); // + 1 for joining slash + + if (!(GetSchemeStringLength() == 0)) { + // Use all of this URI + resuri.auth_ = CopyPart(resuri.scheme_, scheme_, GetSchemeStringLength()); + resuri.path_ = CopyPart(resuri.auth_, auth_, GetAuthStringLength()); + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + resuri.RemoveDotSegments(); + } else { + // Use the base scheme + resuri.auth_ = CopyPart(resuri.scheme_, baseuri.scheme_, baseuri.GetSchemeStringLength()); + if (!(GetAuthStringLength() == 0)) { + // Use this auth, path, query + resuri.path_ = CopyPart(resuri.auth_, auth_, GetAuthStringLength()); + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + resuri.RemoveDotSegments(); + } else { + // Use the base auth + resuri.path_ = CopyPart(resuri.auth_, baseuri.auth_, baseuri.GetAuthStringLength()); + if (GetPathStringLength() == 0) { + // Use the base path + resuri.query_ = CopyPart(resuri.path_, baseuri.path_, baseuri.GetPathStringLength()); + if (GetQueryStringLength() == 0) { + // Use the base query + resuri.frag_ = CopyPart(resuri.query_, baseuri.query_, baseuri.GetQueryStringLength()); + } else { + // Use this query + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + } + } else { + if (path_[0] == '/') { + // Absolute path - use all of this path + resuri.query_ = CopyPart(resuri.path_, path_, GetPathStringLength()); + resuri.RemoveDotSegments(); + } else { + // Relative path - append this path to base path after base path's last slash + size_t pos = 0; + if (!(baseuri.GetAuthStringLength() == 0) && baseuri.GetPathStringLength() == 0) { + resuri.path_[pos] = '/'; + pos++; + } + size_t lastslashpos = baseuri.GetPathStringLength(); + while (lastslashpos > 0) { + if (baseuri.path_[lastslashpos - 1] == '/') break; + lastslashpos--; + } + std::memcpy(&resuri.path_[pos], baseuri.path_, lastslashpos * sizeof(Ch)); + pos += lastslashpos; + resuri.query_ = CopyPart(&resuri.path_[pos], path_, GetPathStringLength()); + resuri.RemoveDotSegments(); + } + // Use this query + resuri.frag_ = CopyPart(resuri.query_, query_, GetQueryStringLength()); + } + } + } + // Always use this frag + resuri.base_ = CopyPart(resuri.frag_, frag_, GetFragStringLength()); + + // Re-constitute base_ and uri_ + resuri.SetBase(); + resuri.uri_ = resuri.base_ + resuri.GetBaseStringLength() + 1; + resuri.SetUri(); + return resuri; + } + + //! Get the allocator of this GenericUri. + Allocator& GetAllocator() { return *allocator_; } + +private: + // Allocate memory for a URI + // Returns total amount allocated + std::size_t Allocate(std::size_t len) { + // Create own allocator if user did not supply. + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); + + // Allocate one block containing each part of the URI (5) plus base plus full URI, all null terminated. + // Order: scheme, auth, path, query, frag, base, uri + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + size_t total = (3 * len + 7) * sizeof(Ch); + scheme_ = static_cast(allocator_->Malloc(total)); + *scheme_ = '\0'; + auth_ = scheme_; + auth_++; + *auth_ = '\0'; + path_ = auth_; + path_++; + *path_ = '\0'; + query_ = path_; + query_++; + *query_ = '\0'; + frag_ = query_; + frag_++; + *frag_ = '\0'; + base_ = frag_; + base_++; + *base_ = '\0'; + uri_ = base_; + uri_++; + *uri_ = '\0'; + return total; + } + + // Free memory for a URI + void Free() { + if (scheme_) { + Allocator::Free(scheme_); + scheme_ = 0; + } + } + + // Parse a URI into constituent scheme, authority, path, query, & fragment parts + // Supports URIs that match regex ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? as per + // https://tools.ietf.org/html/rfc3986 + void Parse(const Ch* uri, std::size_t len) { + std::size_t start = 0, pos1 = 0, pos2 = 0; + Allocate(len); + + // Look for scheme ([^:/?#]+):)? + if (start < len) { + while (pos1 < len) { + if (uri[pos1] == ':') break; + pos1++; + } + if (pos1 != len) { + while (pos2 < len) { + if (uri[pos2] == '/') break; + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + if (pos1 < pos2) { + pos1++; + std::memcpy(scheme_, &uri[start], pos1 * sizeof(Ch)); + scheme_[pos1] = '\0'; + start = pos1; + } + } + } + // Look for auth (//([^/?#]*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + auth_ = scheme_ + GetSchemeStringLength(); + auth_++; + *auth_ = '\0'; + if (start < len - 1 && uri[start] == '/' && uri[start + 1] == '/') { + pos2 = start + 2; + while (pos2 < len) { + if (uri[pos2] == '/') break; + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + std::memcpy(auth_, &uri[start], (pos2 - start) * sizeof(Ch)); + auth_[pos2 - start] = '\0'; + start = pos2; + } + // Look for path ([^?#]*) + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + path_ = auth_ + GetAuthStringLength(); + path_++; + *path_ = '\0'; + if (start < len) { + pos2 = start; + while (pos2 < len) { + if (uri[pos2] == '?') break; + if (uri[pos2] == '#') break; + pos2++; + } + if (start != pos2) { + std::memcpy(path_, &uri[start], (pos2 - start) * sizeof(Ch)); + path_[pos2 - start] = '\0'; + if (path_[0] == '/') + RemoveDotSegments(); // absolute path - normalize + start = pos2; + } + } + // Look for query (\?([^#]*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + query_ = path_ + GetPathStringLength(); + query_++; + *query_ = '\0'; + if (start < len && uri[start] == '?') { + pos2 = start + 1; + while (pos2 < len) { + if (uri[pos2] == '#') break; + pos2++; + } + if (start != pos2) { + std::memcpy(query_, &uri[start], (pos2 - start) * sizeof(Ch)); + query_[pos2 - start] = '\0'; + start = pos2; + } + } + // Look for fragment (#(.*))? + // Note need to set, increment, assign in 3 stages to avoid compiler warning bug. + frag_ = query_ + GetQueryStringLength(); + frag_++; + *frag_ = '\0'; + if (start < len && uri[start] == '#') { + std::memcpy(frag_, &uri[start], (len - start) * sizeof(Ch)); + frag_[len - start] = '\0'; + } + + // Re-constitute base_ and uri_ + base_ = frag_ + GetFragStringLength() + 1; + SetBase(); + uri_ = base_ + GetBaseStringLength() + 1; + SetUri(); + } + + // Reconstitute base + void SetBase() { + Ch* next = base_; + std::memcpy(next, scheme_, GetSchemeStringLength() * sizeof(Ch)); + next+= GetSchemeStringLength(); + std::memcpy(next, auth_, GetAuthStringLength() * sizeof(Ch)); + next+= GetAuthStringLength(); + std::memcpy(next, path_, GetPathStringLength() * sizeof(Ch)); + next+= GetPathStringLength(); + std::memcpy(next, query_, GetQueryStringLength() * sizeof(Ch)); + next+= GetQueryStringLength(); + *next = '\0'; + } + + // Reconstitute uri + void SetUri() { + Ch* next = uri_; + std::memcpy(next, base_, GetBaseStringLength() * sizeof(Ch)); + next+= GetBaseStringLength(); + std::memcpy(next, frag_, GetFragStringLength() * sizeof(Ch)); + next+= GetFragStringLength(); + *next = '\0'; + } + + // Copy a part from one GenericUri to another + // Return the pointer to the next part to be copied to + Ch* CopyPart(Ch* to, Ch* from, std::size_t len) { + RAPIDJSON_ASSERT(to != 0); + RAPIDJSON_ASSERT(from != 0); + std::memcpy(to, from, len * sizeof(Ch)); + to[len] = '\0'; + Ch* next = to + len + 1; + return next; + } + + // Remove . and .. segments from the path_ member. + // https://tools.ietf.org/html/rfc3986 + // This is done in place as we are only removing segments. + void RemoveDotSegments() { + std::size_t pathlen = GetPathStringLength(); + std::size_t pathpos = 0; // Position in path_ + std::size_t newpos = 0; // Position in new path_ + + // Loop through each segment in original path_ + while (pathpos < pathlen) { + // Get next segment, bounded by '/' or end + size_t slashpos = 0; + while ((pathpos + slashpos) < pathlen) { + if (path_[pathpos + slashpos] == '/') break; + slashpos++; + } + // Check for .. and . segments + if (slashpos == 2 && path_[pathpos] == '.' && path_[pathpos + 1] == '.') { + // Backup a .. segment in the new path_ + // We expect to find a previously added slash at the end or nothing + RAPIDJSON_ASSERT(newpos == 0 || path_[newpos - 1] == '/'); + size_t lastslashpos = newpos; + // Make sure we don't go beyond the start segment + if (lastslashpos > 1) { + // Find the next to last slash and back up to it + lastslashpos--; + while (lastslashpos > 0) { + if (path_[lastslashpos - 1] == '/') break; + lastslashpos--; + } + // Set the new path_ position + newpos = lastslashpos; + } + } else if (slashpos == 1 && path_[pathpos] == '.') { + // Discard . segment, leaves new path_ unchanged + } else { + // Move any other kind of segment to the new path_ + RAPIDJSON_ASSERT(newpos <= pathpos); + std::memmove(&path_[newpos], &path_[pathpos], slashpos * sizeof(Ch)); + newpos += slashpos; + // Add slash if not at end + if ((pathpos + slashpos) < pathlen) { + path_[newpos] = '/'; + newpos++; + } + } + // Move to next segment + pathpos += slashpos + 1; + } + path_[newpos] = '\0'; + } + + Ch* uri_; // Everything + Ch* base_; // Everything except fragment + Ch* scheme_; // Includes the : + Ch* auth_; // Includes the // + Ch* path_; // Absolute if starts with / + Ch* query_; // Includes the ? + Ch* frag_; // Includes the # + + Allocator* allocator_; //!< The current allocator. It is either user-supplied or equal to ownAllocator_. + Allocator* ownAllocator_; //!< Allocator owned by this Uri. +}; + +//! GenericUri for Value (UTF-8, default allocator). +typedef GenericUri Uri; + +RAPIDJSON_NAMESPACE_END + +#if defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_URI_H_ diff --git a/components/thorvg-main/src/loaders/lottie/rapidjson/writer.h b/components/thorvg-main/src/loaders/lottie/rapidjson/writer.h new file mode 100644 index 0000000..8b38921 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/rapidjson/writer.h @@ -0,0 +1,710 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_WRITER_H_ +#define RAPIDJSON_WRITER_H_ + +#include "stream.h" +#include "internal/clzll.h" +#include "internal/meta.h" +#include "internal/stack.h" +#include "internal/strfunc.h" +#include "internal/dtoa.h" +#include "internal/itoa.h" +#include "stringbuffer.h" +#include // placement new + +#if defined(RAPIDJSON_SIMD) && defined(_MSC_VER) +#include +#pragma intrinsic(_BitScanForward) +#endif +#ifdef RAPIDJSON_SSE42 +#include +#elif defined(RAPIDJSON_SSE2) +#include +#elif defined(RAPIDJSON_NEON) +#include +#endif + +#ifdef __clang__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(padded) +RAPIDJSON_DIAG_OFF(unreachable-code) +RAPIDJSON_DIAG_OFF(c++98-compat) +#elif defined(_MSC_VER) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant +#endif + +RAPIDJSON_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// +// WriteFlag + +/*! \def RAPIDJSON_WRITE_DEFAULT_FLAGS + \ingroup RAPIDJSON_CONFIG + \brief User-defined kWriteDefaultFlags definition. + + User can define this as any \c WriteFlag combinations. +*/ +#ifndef RAPIDJSON_WRITE_DEFAULT_FLAGS +#define RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNoFlags +#endif + +//! Combination of writeFlags +enum WriteFlag { + kWriteNoFlags = 0, //!< No flags are set. + kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings. + kWriteNanAndInfFlag = 2, //!< Allow writing of Infinity, -Infinity and NaN. + kWriteDefaultFlags = RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS +}; + +//! JSON writer +/*! Writer implements the concept Handler. + It generates JSON text by events to an output os. + + User may programmatically calls the functions of a writer to generate JSON text. + + On the other side, a writer can also be passed to objects that generates events, + + for example Reader::Parse() and Document::Accept(). + + \tparam OutputStream Type of output stream. + \tparam SourceEncoding Encoding of source string. + \tparam TargetEncoding Encoding of output stream. + \tparam StackAllocator Type of allocator for allocating memory of stack. + \note implements Handler concept +*/ +template, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags> +class Writer { +public: + typedef typename SourceEncoding::Ch Ch; + + static const int kDefaultMaxDecimalPlaces = 324; + + //! Constructor + /*! \param os Output stream. + \param stackAllocator User supplied allocator. If it is null, it will create a private one. + \param levelDepth Initial capacity of stack. + */ + explicit + Writer(OutputStream& os, StackAllocator* stackAllocator = 0, size_t levelDepth = kDefaultLevelDepth) : + os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {} + + explicit + Writer(StackAllocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) : + os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {} + +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + Writer(Writer&& rhs) : + os_(rhs.os_), level_stack_(std::move(rhs.level_stack_)), maxDecimalPlaces_(rhs.maxDecimalPlaces_), hasRoot_(rhs.hasRoot_) { + rhs.os_ = 0; + } +#endif + + //! Reset the writer with a new stream. + /*! + This function reset the writer with a new stream and default settings, + in order to make a Writer object reusable for output multiple JSONs. + + \param os New output stream. + \code + Writer writer(os1); + writer.StartObject(); + // ... + writer.EndObject(); + + writer.Reset(os2); + writer.StartObject(); + // ... + writer.EndObject(); + \endcode + */ + void Reset(OutputStream& os) { + os_ = &os; + hasRoot_ = false; + level_stack_.Clear(); + } + + //! Checks whether the output is a complete JSON. + /*! + A complete JSON has a complete root object or array. + */ + bool IsComplete() const { + return hasRoot_ && level_stack_.Empty(); + } + + int GetMaxDecimalPlaces() const { + return maxDecimalPlaces_; + } + + //! Sets the maximum number of decimal places for double output. + /*! + This setting truncates the output with specified number of decimal places. + + For example, + + \code + writer.SetMaxDecimalPlaces(3); + writer.StartArray(); + writer.Double(0.12345); // "0.123" + writer.Double(0.0001); // "0.0" + writer.Double(1.234567890123456e30); // "1.234567890123456e30" (do not truncate significand for positive exponent) + writer.Double(1.23e-4); // "0.0" (do truncate significand for negative exponent) + writer.EndArray(); + \endcode + + The default setting does not truncate any decimal places. You can restore to this setting by calling + \code + writer.SetMaxDecimalPlaces(Writer::kDefaultMaxDecimalPlaces); + \endcode + */ + void SetMaxDecimalPlaces(int maxDecimalPlaces) { + maxDecimalPlaces_ = maxDecimalPlaces; + } + + /*!@name Implementation of Handler + \see Handler + */ + //@{ + + bool Null() { Prefix(kNullType); return EndValue(WriteNull()); } + bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return EndValue(WriteBool(b)); } + bool Int(int i) { Prefix(kNumberType); return EndValue(WriteInt(i)); } + bool Uint(unsigned u) { Prefix(kNumberType); return EndValue(WriteUint(u)); } + bool Int64(int64_t i64) { Prefix(kNumberType); return EndValue(WriteInt64(i64)); } + bool Uint64(uint64_t u64) { Prefix(kNumberType); return EndValue(WriteUint64(u64)); } + + //! Writes the given \c double value to the stream + /*! + \param d The value to be written. + \return Whether it is succeed. + */ + bool Double(double d) { Prefix(kNumberType); return EndValue(WriteDouble(d)); } + + bool RawNumber(const Ch* str, SizeType length, bool copy = false) { + RAPIDJSON_ASSERT(str != 0); + (void)copy; + Prefix(kNumberType); + return EndValue(WriteString(str, length)); + } + + bool String(const Ch* str, SizeType length, bool copy = false) { + RAPIDJSON_ASSERT(str != 0); + (void)copy; + Prefix(kStringType); + return EndValue(WriteString(str, length)); + } + +#if RAPIDJSON_HAS_STDSTRING + bool String(const std::basic_string& str) { + return String(str.data(), SizeType(str.size())); + } +#endif + + bool StartObject() { + Prefix(kObjectType); + new (level_stack_.template Push()) Level(false); + return WriteStartObject(); + } + + bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); } + +#if RAPIDJSON_HAS_STDSTRING + bool Key(const std::basic_string& str) + { + return Key(str.data(), SizeType(str.size())); + } +#endif + + bool EndObject(SizeType memberCount = 0) { + (void)memberCount; + RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); // not inside an Object + RAPIDJSON_ASSERT(!level_stack_.template Top()->inArray); // currently inside an Array, not Object + RAPIDJSON_ASSERT(0 == level_stack_.template Top()->valueCount % 2); // Object has a Key without a Value + level_stack_.template Pop(1); + return EndValue(WriteEndObject()); + } + + bool StartArray() { + Prefix(kArrayType); + new (level_stack_.template Push()) Level(true); + return WriteStartArray(); + } + + bool EndArray(SizeType elementCount = 0) { + (void)elementCount; + RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); + RAPIDJSON_ASSERT(level_stack_.template Top()->inArray); + level_stack_.template Pop(1); + return EndValue(WriteEndArray()); + } + //@} + + /*! @name Convenience extensions */ + //@{ + + //! Simpler but slower overload. + bool String(const Ch* const& str) { return String(str, internal::StrLen(str)); } + bool Key(const Ch* const& str) { return Key(str, internal::StrLen(str)); } + + //@} + + //! Write a raw JSON value. + /*! + For user to write a stringified JSON as a value. + + \param json A well-formed JSON value. It should not contain null character within [0, length - 1] range. + \param length Length of the json. + \param type Type of the root of json. + */ + bool RawValue(const Ch* json, size_t length, Type type) { + RAPIDJSON_ASSERT(json != 0); + Prefix(type); + return EndValue(WriteRawValue(json, length)); + } + + //! Flush the output stream. + /*! + Allows the user to flush the output stream immediately. + */ + void Flush() { + os_->Flush(); + } + + static const size_t kDefaultLevelDepth = 32; + +protected: + //! Information for each nested level + struct Level { + Level(bool inArray_) : valueCount(0), inArray(inArray_) {} + size_t valueCount; //!< number of values in this level + bool inArray; //!< true if in array, otherwise in object + }; + + bool WriteNull() { + PutReserve(*os_, 4); + PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true; + } + + bool WriteBool(bool b) { + if (b) { + PutReserve(*os_, 4); + PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'r'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'e'); + } + else { + PutReserve(*os_, 5); + PutUnsafe(*os_, 'f'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 's'); PutUnsafe(*os_, 'e'); + } + return true; + } + + bool WriteInt(int i) { + char buffer[11]; + const char* end = internal::i32toa(i, buffer); + PutReserve(*os_, static_cast(end - buffer)); + for (const char* p = buffer; p != end; ++p) + PutUnsafe(*os_, static_cast(*p)); + return true; + } + + bool WriteUint(unsigned u) { + char buffer[10]; + const char* end = internal::u32toa(u, buffer); + PutReserve(*os_, static_cast(end - buffer)); + for (const char* p = buffer; p != end; ++p) + PutUnsafe(*os_, static_cast(*p)); + return true; + } + + bool WriteInt64(int64_t i64) { + char buffer[21]; + const char* end = internal::i64toa(i64, buffer); + PutReserve(*os_, static_cast(end - buffer)); + for (const char* p = buffer; p != end; ++p) + PutUnsafe(*os_, static_cast(*p)); + return true; + } + + bool WriteUint64(uint64_t u64) { + char buffer[20]; + char* end = internal::u64toa(u64, buffer); + PutReserve(*os_, static_cast(end - buffer)); + for (char* p = buffer; p != end; ++p) + PutUnsafe(*os_, static_cast(*p)); + return true; + } + + bool WriteDouble(double d) { + if (internal::Double(d).IsNanOrInf()) { + if (!(writeFlags & kWriteNanAndInfFlag)) + return false; + if (internal::Double(d).IsNan()) { + PutReserve(*os_, 3); + PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N'); + return true; + } + if (internal::Double(d).Sign()) { + PutReserve(*os_, 9); + PutUnsafe(*os_, '-'); + } + else + PutReserve(*os_, 8); + PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f'); + PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y'); + return true; + } + + char buffer[25]; + char* end = internal::dtoa(d, buffer, maxDecimalPlaces_); + PutReserve(*os_, static_cast(end - buffer)); + for (char* p = buffer; p != end; ++p) + PutUnsafe(*os_, static_cast(*p)); + return true; + } + + bool WriteString(const Ch* str, SizeType length) { + static const typename OutputStream::Ch hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + static const char escape[256] = { +#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + //0 1 2 3 4 5 6 7 8 9 A B C D E F + 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00 + 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10 + 0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20 + Z16, Z16, // 30~4F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50 + Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF +#undef Z16 + }; + + if (TargetEncoding::supportUnicode) + PutReserve(*os_, 2 + length * 6); // "\uxxxx..." + else + PutReserve(*os_, 2 + length * 12); // "\uxxxx\uyyyy..." + + PutUnsafe(*os_, '\"'); + GenericStringStream is(str); + while (ScanWriteUnescapedString(is, length)) { + const Ch c = is.Peek(); + if (!TargetEncoding::supportUnicode && static_cast(c) >= 0x80) { + // Unicode escaping + unsigned codepoint; + if (RAPIDJSON_UNLIKELY(!SourceEncoding::Decode(is, &codepoint))) + return false; + PutUnsafe(*os_, '\\'); + PutUnsafe(*os_, 'u'); + if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)) { + PutUnsafe(*os_, hexDigits[(codepoint >> 12) & 15]); + PutUnsafe(*os_, hexDigits[(codepoint >> 8) & 15]); + PutUnsafe(*os_, hexDigits[(codepoint >> 4) & 15]); + PutUnsafe(*os_, hexDigits[(codepoint ) & 15]); + } + else { + RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF); + // Surrogate pair + unsigned s = codepoint - 0x010000; + unsigned lead = (s >> 10) + 0xD800; + unsigned trail = (s & 0x3FF) + 0xDC00; + PutUnsafe(*os_, hexDigits[(lead >> 12) & 15]); + PutUnsafe(*os_, hexDigits[(lead >> 8) & 15]); + PutUnsafe(*os_, hexDigits[(lead >> 4) & 15]); + PutUnsafe(*os_, hexDigits[(lead ) & 15]); + PutUnsafe(*os_, '\\'); + PutUnsafe(*os_, 'u'); + PutUnsafe(*os_, hexDigits[(trail >> 12) & 15]); + PutUnsafe(*os_, hexDigits[(trail >> 8) & 15]); + PutUnsafe(*os_, hexDigits[(trail >> 4) & 15]); + PutUnsafe(*os_, hexDigits[(trail ) & 15]); + } + } + else if ((sizeof(Ch) == 1 || static_cast(c) < 256) && RAPIDJSON_UNLIKELY(escape[static_cast(c)])) { + is.Take(); + PutUnsafe(*os_, '\\'); + PutUnsafe(*os_, static_cast(escape[static_cast(c)])); + if (escape[static_cast(c)] == 'u') { + PutUnsafe(*os_, '0'); + PutUnsafe(*os_, '0'); + PutUnsafe(*os_, hexDigits[static_cast(c) >> 4]); + PutUnsafe(*os_, hexDigits[static_cast(c) & 0xF]); + } + } + else if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ? + Transcoder::Validate(is, *os_) : + Transcoder::TranscodeUnsafe(is, *os_)))) + return false; + } + PutUnsafe(*os_, '\"'); + return true; + } + + bool ScanWriteUnescapedString(GenericStringStream& is, size_t length) { + return RAPIDJSON_LIKELY(is.Tell() < length); + } + + bool WriteStartObject() { os_->Put('{'); return true; } + bool WriteEndObject() { os_->Put('}'); return true; } + bool WriteStartArray() { os_->Put('['); return true; } + bool WriteEndArray() { os_->Put(']'); return true; } + + bool WriteRawValue(const Ch* json, size_t length) { + PutReserve(*os_, length); + GenericStringStream is(json); + while (RAPIDJSON_LIKELY(is.Tell() < length)) { + RAPIDJSON_ASSERT(is.Peek() != '\0'); + if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ? + Transcoder::Validate(is, *os_) : + Transcoder::TranscodeUnsafe(is, *os_)))) + return false; + } + return true; + } + + void Prefix(Type type) { + (void)type; + if (RAPIDJSON_LIKELY(level_stack_.GetSize() != 0)) { // this value is not at root + Level* level = level_stack_.template Top(); + if (level->valueCount > 0) { + if (level->inArray) + os_->Put(','); // add comma if it is not the first element in array + else // in object + os_->Put((level->valueCount % 2 == 0) ? ',' : ':'); + } + if (!level->inArray && level->valueCount % 2 == 0) + RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name + level->valueCount++; + } + else { + RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root. + hasRoot_ = true; + } + } + + // Flush the value if it is the top level one. + bool EndValue(bool ret) { + if (RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text + Flush(); + return ret; + } + + OutputStream* os_; + internal::Stack level_stack_; + int maxDecimalPlaces_; + bool hasRoot_; + +private: + // Prohibit copy constructor & assignment operator. + Writer(const Writer&); + Writer& operator=(const Writer&); +}; + +// Full specialization for StringStream to prevent memory copying + +template<> +inline bool Writer::WriteInt(int i) { + char *buffer = os_->Push(11); + const char* end = internal::i32toa(i, buffer); + os_->Pop(static_cast(11 - (end - buffer))); + return true; +} + +template<> +inline bool Writer::WriteUint(unsigned u) { + char *buffer = os_->Push(10); + const char* end = internal::u32toa(u, buffer); + os_->Pop(static_cast(10 - (end - buffer))); + return true; +} + +template<> +inline bool Writer::WriteInt64(int64_t i64) { + char *buffer = os_->Push(21); + const char* end = internal::i64toa(i64, buffer); + os_->Pop(static_cast(21 - (end - buffer))); + return true; +} + +template<> +inline bool Writer::WriteUint64(uint64_t u) { + char *buffer = os_->Push(20); + const char* end = internal::u64toa(u, buffer); + os_->Pop(static_cast(20 - (end - buffer))); + return true; +} + +template<> +inline bool Writer::WriteDouble(double d) { + if (internal::Double(d).IsNanOrInf()) { + // Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag). + if (!(kWriteDefaultFlags & kWriteNanAndInfFlag)) + return false; + if (internal::Double(d).IsNan()) { + PutReserve(*os_, 3); + PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N'); + return true; + } + if (internal::Double(d).Sign()) { + PutReserve(*os_, 9); + PutUnsafe(*os_, '-'); + } + else + PutReserve(*os_, 8); + PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f'); + PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y'); + return true; + } + + char *buffer = os_->Push(25); + char* end = internal::dtoa(d, buffer, maxDecimalPlaces_); + os_->Pop(static_cast(25 - (end - buffer))); + return true; +} + +#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) +template<> +inline bool Writer::ScanWriteUnescapedString(StringStream& is, size_t length) { + if (length < 16) + return RAPIDJSON_LIKELY(is.Tell() < length); + + if (!RAPIDJSON_LIKELY(is.Tell() < length)) + return false; + + const char* p = is.src_; + const char* end = is.head_ + length; + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + const char* endAligned = reinterpret_cast(reinterpret_cast(end) & static_cast(~15)); + if (nextAligned > end) + return true; + + while (p != nextAligned) + if (*p < 0x20 || *p == '\"' || *p == '\\') { + is.src_ = p; + return RAPIDJSON_LIKELY(is.Tell() < length); + } + else + os_->PutUnsafe(*p++); + + // The rest of string using SIMD + static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' }; + static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' }; + static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F }; + const __m128i dq = _mm_loadu_si128(reinterpret_cast(&dquote[0])); + const __m128i bs = _mm_loadu_si128(reinterpret_cast(&bslash[0])); + const __m128i sp = _mm_loadu_si128(reinterpret_cast(&space[0])); + + for (; p != endAligned; p += 16) { + const __m128i s = _mm_load_si128(reinterpret_cast(p)); + const __m128i t1 = _mm_cmpeq_epi8(s, dq); + const __m128i t2 = _mm_cmpeq_epi8(s, bs); + const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F + const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3); + unsigned short r = static_cast(_mm_movemask_epi8(x)); + if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped + SizeType len; +#ifdef _MSC_VER // Find the index of first escaped + unsigned long offset; + _BitScanForward(&offset, r); + len = offset; +#else + len = static_cast(__builtin_ffs(r) - 1); +#endif + char* q = reinterpret_cast(os_->PushUnsafe(len)); + for (size_t i = 0; i < len; i++) + q[i] = p[i]; + + p += len; + break; + } + _mm_storeu_si128(reinterpret_cast<__m128i *>(os_->PushUnsafe(16)), s); + } + + is.src_ = p; + return RAPIDJSON_LIKELY(is.Tell() < length); +} +#elif defined(RAPIDJSON_NEON) +template<> +inline bool Writer::ScanWriteUnescapedString(StringStream& is, size_t length) { + if (length < 16) + return RAPIDJSON_LIKELY(is.Tell() < length); + + if (!RAPIDJSON_LIKELY(is.Tell() < length)) + return false; + + const char* p = is.src_; + const char* end = is.head_ + length; + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & static_cast(~15)); + const char* endAligned = reinterpret_cast(reinterpret_cast(end) & static_cast(~15)); + if (nextAligned > end) + return true; + + while (p != nextAligned) + if (*p < 0x20 || *p == '\"' || *p == '\\') { + is.src_ = p; + return RAPIDJSON_LIKELY(is.Tell() < length); + } + else + os_->PutUnsafe(*p++); + + // The rest of string using SIMD + const uint8x16_t s0 = vmovq_n_u8('"'); + const uint8x16_t s1 = vmovq_n_u8('\\'); + const uint8x16_t s2 = vmovq_n_u8('\b'); + const uint8x16_t s3 = vmovq_n_u8(32); + + for (; p != endAligned; p += 16) { + const uint8x16_t s = vld1q_u8(reinterpret_cast(p)); + uint8x16_t x = vceqq_u8(s, s0); + x = vorrq_u8(x, vceqq_u8(s, s1)); + x = vorrq_u8(x, vceqq_u8(s, s2)); + x = vorrq_u8(x, vcltq_u8(s, s3)); + + x = vrev64q_u8(x); // Rev in 64 + uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0); // extract + uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1); // extract + + SizeType len = 0; + bool escaped = false; + if (low == 0) { + if (high != 0) { + uint32_t lz = internal::clzll(high); + len = 8 + (lz >> 3); + escaped = true; + } + } else { + uint32_t lz = internal::clzll(low); + len = lz >> 3; + escaped = true; + } + if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped + char* q = reinterpret_cast(os_->PushUnsafe(len)); + for (size_t i = 0; i < len; i++) + q[i] = p[i]; + + p += len; + break; + } + vst1q_u8(reinterpret_cast(os_->PushUnsafe(16)), s); + } + + is.src_ = p; + return RAPIDJSON_LIKELY(is.Tell() < length); +} +#endif // RAPIDJSON_NEON + +RAPIDJSON_NAMESPACE_END + +#if defined(_MSC_VER) || defined(__clang__) +RAPIDJSON_DIAG_POP +#endif + +#endif // RAPIDJSON_RAPIDJSON_H_ diff --git a/components/thorvg-main/src/loaders/lottie/thorvg_lottie.h b/components/thorvg-main/src/loaders/lottie/thorvg_lottie.h new file mode 100644 index 0000000..e82d394 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/thorvg_lottie.h @@ -0,0 +1,181 @@ +#ifndef _THORVG_LOTTIE_H_ +#define _THORVG_LOTTIE_H_ + +#include "thorvg.h" + +namespace tvg +{ + +/** + * @class LottieAnimation + * + * @brief The LottieAnimation class enables control of advanced Lottie features. + * + * This class extends the Animation and has additional interfaces. + * + * @see Animation + * + * @since 0.15 + */ +class TVG_API LottieAnimation final : public Animation +{ +public: + ~LottieAnimation() override; + + /** + * @brief Specifies a segment by marker. + * + * Markers are used to control animation playback by specifying start and end points, + * eliminating the need to know the exact frame numbers. + * Generally, markers are designated at the design level, + * meaning the callers must know the marker name in advance to use it. + * + * @param[in] marker The name of the segment marker. + * + * @retval Result::InsufficientCondition If the animation is not loaded. + * @retval Result::NonSupport When it's not animatable. + * + * @note If a @c marker is specified, the previously set segment will be disregarded. + * @note Set @c nullptr to reset the specified segment. + * @see Animation::segment(float begin, float end) + * @since 1.0 + */ + Result segment(const char* marker) noexcept; + + /** + * @brief Interpolates between two frames over a specified duration. + * + * This method performs tweening, a process of generating intermediate frame + * between @p from and @p to based on the given @p progress. + * + * @param[in] from The start frame number of the interpolation. + * @param[in] to The end frame number of the interpolation. + * @param[in] progress The current progress of the interpolation (range: 0.0 to 1.0). + * + * @retval Result::InsufficientCondition In case the animation is not loaded. + * + * @since 1.0 + */ + Result tween(float from, float to, float progress) noexcept; + + /** + * @brief Gets the marker count of the animation. + * + * @retval The count of the markers, zero if there is no marker. + * + * @see LottieAnimation::marker() + * @since 1.0 + */ + uint32_t markersCnt() noexcept; + + /** + * @brief Gets the marker name by a given index. + * + * @param[in] idx The index of the animation marker, starts from 0. + * + * @retval The name of marker when succeed, @c nullptr otherwise. + * + * @see LottieAnimation::markersCnt() + * @since 1.0 + */ + const char* marker(uint32_t idx) noexcept; + + /** + * @brief Updates the value of an expression variable for a specific layer. + * + * This function sets the value of a specified expression variable within a particular layer. + * It is useful for dynamically changing the properties of a layer at runtime. + * + * @param[in] layer The name of the layer containing the variable to be updated. + * @param[in] ix The property index of the variable within the layer. + * @param[in] var The name of the variable to be updated. + * @param[in] val The new value to assign to the variable. + * + * @retval Result::InsufficientCondition If the animation is not loaded. + * @retval Result::InvalidArguments When the given parameter is invalid. + * @retval Result::NonSupport When neither the layer nor the property is found in the current animation. + * + * @note Experimental API + */ + Result assign(const char* layer, uint32_t ix, const char* var, float val); + + /** + * @brief Creates a new slot based on the given Lottie slot data. + * + * This function parses the provided JSON-formatted slot data and generates + * a new slot for animation control. The returned slot ID can be used to apply + * or delete the slot later. + * + * @param[in] slot A JSON string representing the Lottie slot data. + * + * @return A unique, non-zero slot ID on success. Returns @c 0 if the slot generation fails. + * + * @see apply(uint32_t id) + * @see del(uint32_t id) + * + * @since 1.0 + */ + uint32_t gen(const char* slot) noexcept; + + /** + * @brief Applies a previously generated slot to the animation. + * + * This function applies the animation parameters defined by a slot. + * If the provided slot ID is 0, all previously applied slots will be reset. + * + * @param[in] id The ID of the slot to apply. Use 0 to reset all slots. + * + * @retval Result::InvalidArguments If the animation is not loaded or the slot ID is invalid. + * + * @see gen(const char* slot) + * + * @since 1.0 + */ + Result apply(uint32_t id) noexcept; + + /** + * @brief Deletes a previously generated slot. + * + * This function removes a slot by its ID. + * + * @param[in] id The ID of the slot to delete. Retrieve the ID from gen(). + * + * @retval Result::InvalidArguments If the animation is not loaded or the slot ID is invalid. + * + * @note This function should be paired with gen. + * @see gen(const char* slot) + * + * @since 1.0 + */ + Result del(uint32_t id) noexcept; + + /** + * @brief Sets the quality level for Lottie effects. + * + * This function controls the rendering quality of effects like blur, shadows, etc. + * Lower values prioritize performance while higher values prioritize quality. + * + * @param[in] value The quality level (0-100). 0 represents lowest quality/best performance, + * 100 represents highest quality/lowest performance, default is 50. + * + * @retval Result::InsufficientCondition If the animation is not loaded. + * + * @since 1.0 + */ + Result quality(uint8_t value) noexcept; + + /** + * @brief Creates a new LottieAnimation object. + * + * @return A new LottieAnimation object. + * + * @since 0.15 + */ + static LottieAnimation* gen() noexcept; + + _TVG_DECLARE_PRIVATE(LottieAnimation); +}; + +} //namespace + +#endif //_THORVG_LOTTIE_H_ diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieAnimation.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieAnimation.cpp new file mode 100644 index 0000000..b949554 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieAnimation.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgCommon.h" +#include "thorvg_lottie.h" +#include "tvgLottieLoader.h" +#include "tvgAnimation.h" + + +LottieAnimation::LottieAnimation() = default; +LottieAnimation::~LottieAnimation() = default; + + +uint32_t LottieAnimation::gen(const char* slot) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return 0; + + return static_cast(loader)->gen(slot); +} + + +Result LottieAnimation::apply(uint32_t id) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + + if (static_cast(loader)->apply(id)) { + PAINT(pImpl->picture)->mark(RenderUpdateFlag::All); + return Result::Success; + } + + return Result::InvalidArguments; +} + + +Result LottieAnimation::del(uint32_t id) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + + if (static_cast(loader)->del(id)) { + PAINT(pImpl->picture)->mark(RenderUpdateFlag::All); + return Result::Success; + } + + return Result::InvalidArguments; +} + + +Result LottieAnimation::segment(const char* marker) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + + if (!marker) { + static_cast(loader)->segment(0.0f, FLT_MAX); + return Result::Success; + } + + float begin, end; + if (!static_cast(loader)->segment(marker, begin, end)) return Result::InvalidArguments; + return Animation::segment(begin, end); +} + + +Result LottieAnimation::tween(float from, float to, float progress) noexcept +{ + auto loader = tvg::to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + if (!static_cast(loader)->tween(from, to, progress)) return Result::InsufficientCondition; + PAINT(pImpl->picture)->mark(RenderUpdateFlag::All); + return Result::Success; +} + + +uint32_t LottieAnimation::markersCnt() noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return 0; + return static_cast(loader)->markersCnt(); +} + + +const char* LottieAnimation::marker(uint32_t idx) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return nullptr; + return static_cast(loader)->markers(idx); +} + + +Result LottieAnimation::assign(const char* layer, uint32_t ix, const char* var, float val) +{ + if (!layer || !var) return Result::InvalidArguments; + + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + if (static_cast(loader)->assign(layer, ix, var, val)) { + PAINT(pImpl->picture)->mark(RenderUpdateFlag::All); + return Result::Success; + } + + return Result::NonSupport; +} + + +Result LottieAnimation::quality(uint8_t value) noexcept +{ + if (value > 100) return Result::InvalidArguments; + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + if (!static_cast(loader)->quality(value)) return Result::InsufficientCondition; + return Result::Success; +} + + +LottieAnimation* LottieAnimation::gen() noexcept +{ + return new LottieAnimation; +} diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieBuilder.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieBuilder.cpp new file mode 100644 index 0000000..9cac350 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieBuilder.cpp @@ -0,0 +1,1608 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgCommon.h" +#include "tvgMath.h" +#include "tvgScene.h" +#include "tvgLoadModule.h" +#include "tvgLottieModel.h" +#include "tvgLottieBuilder.h" +#include "tvgLottieExpressions.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static bool _buildComposition(LottieComposition* comp, LottieLayer* parent); +static bool _draw(LottieGroup* parent, LottieShape* shape, RenderContext* ctx); + + +static void _rotate(LottieTransform* transform, float frameNo, Matrix& m, float angle, Tween& tween, LottieExpressions* exps) +{ + //rotation xyz + if (transform->rotationEx) { + auto radianX = deg2rad(transform->rotationEx->x(frameNo, tween, exps)); + auto radianY = deg2rad(transform->rotationEx->y(frameNo, tween, exps)); + auto radianZ = deg2rad(transform->rotation(frameNo, tween, exps)) + angle; + auto cx = cosf(radianX), sx = sinf(radianX); + auto cy = cosf(radianY), sy = sinf(radianY);; + auto cz = cosf(radianZ), sz = sinf(radianZ);; + m.e11 = cy * cz; + m.e12 = -cy * sz; + m.e21 = sx * sy * cz + cx * sz; + m.e22 = -sx * sy * sz + cx * cz; + //rotation z + } else { + auto degree = transform->rotation(frameNo, tween, exps) + angle; + if (degree == 0.0f) return; + auto radian = deg2rad(degree); + m.e11 = cosf(radian); + m.e12 = -sinf(radian); + m.e21 = sinf(radian); + m.e22 = cosf(radian); + } +} + + +static void _skew(Matrix* m, float angleDeg, float axisDeg) +{ + auto angle = -deg2rad(angleDeg); + auto tanVal = tanf(angle); + + axisDeg = fmod(axisDeg, 180.0f); + if (fabsf(axisDeg) < 0.01f || fabsf(axisDeg - 180.0f) < 0.01f || fabsf(axisDeg + 180.0f) < 0.01f) { + float cosVal = cosf(deg2rad(axisDeg)); + auto B = cosVal * cosVal * tanVal; + m->e12 += B * m->e11; + m->e22 += B * m->e21; + return; + } else if (fabsf(axisDeg - 90.0f) < 0.01f || fabsf(axisDeg + 90.0f) < 0.01f) { + float sinVal = -sinf(deg2rad(axisDeg)); + auto C = sinVal * sinVal * tanVal; + m->e11 -= C * m->e12; + m->e21 -= C * m->e22; + return; + } + + auto axis = -deg2rad(axisDeg); + auto cosVal = cosf(axis); + auto sinVal = sinf(axis); + auto A = sinVal * cosVal * tanVal; + auto B = cosVal * cosVal * tanVal; + auto C = sinVal * sinVal * tanVal; + + auto e11 = m->e11; + auto e21 = m->e21; + m->e11 = (1.0f - A) * e11 - C * m->e12; + m->e12 = B * e11 + (1.0f + A) * m->e12; + m->e21 = (1.0f - A) * e21 - C * m->e22; + m->e22 = B * e21 + (1.0f + A) * m->e22; +} + + +static bool _update(LottieTransform* transform, float frameNo, Matrix& matrix, uint8_t& opacity, bool autoOrient, Tween& tween, LottieExpressions* exps) +{ + tvg::identity(&matrix); + + if (!transform) { + opacity = 255; + return false; + } + + if (transform->coords) translate(&matrix, {transform->coords->x(frameNo, tween, exps), transform->coords->y(frameNo, tween, exps)}); + else translate(&matrix, transform->position(frameNo, tween, exps)); + + auto angle = (autoOrient) ? transform->position.angle(frameNo, tween) : 0.0f; + _rotate(transform, frameNo, matrix, angle, tween, exps); + + auto skewAngle = transform->skewAngle(frameNo, tween, exps); + if (skewAngle != 0.0f) { + // For angles where tangent explodes, the shape degenerates into an infinitely thin line. + // This is handled by zeroing out the matrix due to finite numerical precision. + skewAngle = fmod(skewAngle, 180.0f); + if (fabsf(skewAngle - 90.0f) < 0.01f || fabsf(skewAngle + 90.0f) < 0.01f) return false; + _skew(&matrix, skewAngle, transform->skewAxis(frameNo, exps)); + } + + auto scale = transform->scale(frameNo, tween, exps); + scaleR(&matrix, scale * 0.01f); + + //Lottie specific anchor transform. + translateR(&matrix, -transform->anchor(frameNo, tween, exps)); + + //invisible just in case. + if (scale.x == 0.0f || scale.y == 0.0f) opacity = 0; + else opacity = transform->opacity(frameNo, tween, exps); + + return true; +} + + +void LottieBuilder::updateTransform(LottieLayer* layer, float frameNo) +{ + if (!layer || (!tweening() && tvg::equal(layer->cache.frameNo, frameNo))) return; + + auto transform = layer->transform; + auto parent = layer->parent; + + if (parent) updateTransform(parent, frameNo); + + auto& matrix = layer->cache.matrix; + + _update(transform, frameNo, matrix, layer->cache.opacity, layer->autoOrient, tween, exps); + + if (parent) layer->cache.matrix = parent->cache.matrix * matrix; + + layer->cache.frameNo = frameNo; +} + + +void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto transform = static_cast(*child); + if (!transform) return; + + Matrix m; + uint8_t opacity; + + if (parent->mergeable()) { + if (ctx->transform) { + _update(transform, frameNo, m, opacity, false, tween, exps); + *ctx->transform *= m; + } else { + ctx->transform = new Matrix; + _update(transform, frameNo, *ctx->transform, opacity, false, tween, exps); + } + return; + } + + ctx->merging = nullptr; + + if (!_update(transform, frameNo, m, opacity, false, tween, exps)) return; + + ctx->propagator->transform(ctx->propagator->transform() * m); + ctx->propagator->opacity(MULTIPLY(opacity, PAINT(ctx->propagator)->opacity)); + + //FIXME: preserve the stroke width. too workaround, need a better design. + if (to(ctx->propagator)->rs.strokeWidth() > 0.0f) { + auto denominator = sqrtf(m.e11 * m.e11 + m.e12 * m.e12); + if (denominator > 1.0f) ctx->propagator->strokeWidth(ctx->propagator->strokeWidth() / denominator); + } +} + + +void LottieBuilder::updateGroup(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& pcontexts, RenderContext* ctx) +{ + auto group = static_cast(*child); + + if (!group->visible) return; + + //Prepare render data + if (group->blendMethod == parent->blendMethod) { + group->scene = parent->scene; + } else { + group->scene = tvg::Scene::gen(); + group->scene->blend(group->blendMethod); + parent->scene->add(group->scene); + } + + group->reqFragment |= ctx->reqFragment; + + //generate a merging shape to consolidate partial shapes into a single entity + if (group->mergeable()) _draw(group, nullptr, ctx); + + Inlist contexts; + auto propagator = group->mergeable() ? ctx->propagator : static_cast(PAINT(ctx->propagator)->duplicate(group->pooling())); + contexts.back(new RenderContext(*ctx, propagator, group->mergeable())); + + updateChildren(group, frameNo, contexts); +} + + +static void _update(LottieStroke* stroke, float frameNo, RenderContext* ctx, Tween& tween, LottieExpressions* exps) +{ + ctx->propagator->strokeWidth(stroke->width(frameNo, tween, exps)); + ctx->propagator->strokeCap(stroke->cap); + ctx->propagator->strokeJoin(stroke->join); + ctx->propagator->strokeMiterlimit(stroke->miterLimit); + + if (stroke->dashattr) { + auto dashes = tvg::malloc(stroke->dashattr->size * sizeof(float)); + for (uint8_t i = 0; i < stroke->dashattr->size; ++i) dashes[i] = stroke->dashattr->values[i](frameNo, tween, exps); + ctx->propagator->strokeDash(dashes, stroke->dashattr->size, stroke->dashattr->offset(frameNo, tween, exps)); + tvg::free(dashes); + } else { + ctx->propagator->strokeDash(nullptr, 0); + } +} + + +bool LottieBuilder::fragmented(LottieGroup* parent, LottieObject** child, Inlist& contexts, RenderContext* ctx, RenderFragment fragment) +{ + if (ctx->fragment) return true; + if (!ctx->reqFragment) return false; + + contexts.back(new RenderContext(*ctx, (Shape*)(PAINT(ctx->propagator)->duplicate(parent->pooling())))); + + contexts.tail->begin = child - 1; + ctx->fragment = fragment; + + return false; +} + + +bool LottieBuilder::updateSolidStroke(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx) +{ + auto stroke = static_cast(*child); + if (fragmented(parent, child, contexts, ctx, RenderFragment::ByStroke)) return false; + + auto opacity = stroke->opacity(frameNo, tween, exps); + if (opacity == 0) return false; + + ctx->merging = nullptr; + auto color = stroke->color(frameNo, tween, exps); + ctx->propagator->strokeFill(color.r, color.g, color.b, opacity); + _update(static_cast(stroke), frameNo, ctx, tween, exps); + + return false; +} + + +bool LottieBuilder::updateGradientStroke(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx) +{ + auto stroke = static_cast(*child); + if (fragmented(parent, child, contexts, ctx, RenderFragment::ByStroke)) return false; + + auto opacity = stroke->opacity(frameNo, tween, exps); + if (opacity == 0 && !stroke->opaque) return false; + + ctx->merging = nullptr; + if (auto val = stroke->fill(frameNo, opacity, tween, exps)) ctx->propagator->strokeFill(val); + _update(static_cast(stroke), frameNo, ctx, tween, exps); + + return false; +} + + +bool LottieBuilder::updateSolidFill(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx) +{ + auto fill = static_cast(*child); + auto opacity = fill->opacity(frameNo, tween, exps); + + //interrupted by fully opaque, stop the current rendering + if (ctx->fragment == RenderFragment::ByFill && opacity == 255) return true; + if (opacity == 0) return false; + + if (fragmented(parent, child, contexts, ctx, RenderFragment::ByFill)) return false; + + ctx->merging = nullptr; + auto color = fill->color(frameNo, tween, exps); + ctx->propagator->fill(color.r, color.g, color.b, opacity); + ctx->propagator->fillRule(fill->rule); + + if (ctx->propagator->strokeWidth() > 0) ctx->propagator->order(true); + + return false; +} + + +bool LottieBuilder::updateGradientFill(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx) +{ + auto fill = static_cast(*child); + auto opacity = fill->opacity(frameNo, tween, exps); + + //interrupted by fully opaque, stop the current rendering + if (ctx->fragment == RenderFragment::ByFill && fill->opaque && opacity == 255) return true; + + if (fragmented(parent, child, contexts, ctx, RenderFragment::ByFill)) return false; + + ctx->merging = nullptr; + + if (auto val = fill->fill(frameNo, opacity, tween, exps)) ctx->propagator->fill(val); + ctx->propagator->fillRule(fill->rule); + + if (ctx->propagator->strokeWidth() > 0) ctx->propagator->order(true); + + return false; +} + + +static bool _draw(LottieGroup* parent, LottieShape* shape, RenderContext* ctx) +{ + if (ctx->merging) return false; + + if (shape) { + ctx->merging = shape->pooling(); + PAINT(ctx->propagator)->duplicate(ctx->merging); + } else { + ctx->merging = static_cast(ctx->propagator->duplicate()); + } + + parent->scene->add(ctx->merging); + + return true; +} + + +static void _repeat(LottieGroup* parent, Shape* path, LottieRenderPooler* pooler, RenderContext* ctx) +{ + path->ref(); //prevent pooler returns the same path. + + Array propagators; + propagators.push(ctx->propagator); + Array shapes; + + ARRAY_REVERSE_FOREACH(repeater, ctx->repeaters) { + shapes.reserve(repeater->cnt); + + for (int i = 0; i < repeater->cnt; ++i) { + auto multiplier = repeater->offset + static_cast(i); + ARRAY_FOREACH(p, propagators) { + auto shape = pooler->pooling(); + shape->ref(); //prevent pooler returns the same shape + PAINT((*p))->duplicate(shape); + to(shape)->rs.path = to(path)->rs.path; + auto opacity = tvg::lerp(repeater->startOpacity, repeater->endOpacity, static_cast(i + 1) / repeater->cnt); + shape->opacity(MULTIPLY(shape->opacity(), opacity)); + + auto m = tvg::identity(); + translate(&m, repeater->position * multiplier + repeater->anchor); + scale(&m, {powf(repeater->scale.x * 0.01f, multiplier), powf(repeater->scale.y * 0.01f, multiplier)}); + rotate(&m, repeater->rotation * multiplier); + translateR(&m, -repeater->anchor); + + Matrix inv; + inverse(&repeater->transform, &inv); + shape->transform((repeater->transform * m) * (inv * shape->transform())); + shapes.push(shape); + } + } + + propagators.clear(); + propagators.reserve(shapes.count); + + //push repeat shapes in order. + if (repeater->inorder) { + ARRAY_FOREACH(p, shapes) { + parent->scene->add(*p); + (*p)->unref(); + propagators.push(*p); + } + } else if (!shapes.empty()) { + ARRAY_REVERSE_FOREACH(p, shapes) { + parent->scene->add(*p); + (*p)->unref(); + propagators.push(*p); + } + } + shapes.clear(); + } + path->unref(); +} + + +void LottieBuilder::appendRect(Shape* shape, Point& pos, Point& size, float r, bool clockwise, RenderContext* ctx) +{ + auto temp = (ctx->offset) ? Shape::gen() : shape; + auto cnt = to(temp)->rs.path.pts.count; + + temp->appendRect(pos.x, pos.y, size.x, size.y, r, r, clockwise); + + if (ctx->transform) { + for (auto i = cnt; i < to(temp)->rs.path.pts.count; ++i) { + to(temp)->rs.path.pts[i] *= *ctx->transform; + } + } + + if (ctx->offset) { + ctx->offset->modifyRect(to(temp)->rs.path, to(shape)->rs.path); + Paint::rel(temp); + } +} + + +void LottieBuilder::updateRect(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto rect = static_cast(*child); + auto size = rect->size(frameNo, tween, exps); + auto pos = rect->position(frameNo, tween, exps) - size * 0.5f; + auto r = rect->radius(frameNo, tween, exps); + + if (r == 0.0f) { + if (ctx->roundness) ctx->roundness->modifyRect(size, r); + } else { + r = std::min({r, size.x * 0.5f, size.y * 0.5f}); + } + + if (ctx->repeaters.empty()) { + _draw(parent, rect, ctx); + appendRect(ctx->merging, pos, size, r, rect->clockwise, ctx); + } else { + auto shape = rect->pooling(); + shape->reset(); + appendRect(shape, pos, size, r, rect->clockwise, ctx); + _repeat(parent, shape, rect, ctx); + } +} + + +static void _appendCircle(Shape* shape, Point& center, Point& radius, bool clockwise, RenderContext* ctx) +{ + if (ctx->offset) ctx->offset->modifyEllipse(radius); + + auto cnt = to(shape)->rs.path.pts.count; + + shape->appendCircle(center.x, center.y, radius.x, radius.y, clockwise); + + if (ctx->transform) { + for (auto i = cnt; i < to(shape)->rs.path.pts.count; ++i) { + to(shape)->rs.path.pts[i] *= *ctx->transform; + } + } +} + + +void LottieBuilder::updateEllipse(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto ellipse = static_cast(*child); + auto pos = ellipse->position(frameNo, tween, exps); + auto size = ellipse->size(frameNo, tween, exps) * 0.5f; + + if (ctx->repeaters.empty()) { + _draw(parent, ellipse, ctx); + _appendCircle(ctx->merging, pos, size, ellipse->clockwise, ctx); + } else { + auto shape = ellipse->pooling(); + shape->reset(); + _appendCircle(shape, pos, size, ellipse->clockwise, ctx); + _repeat(parent, shape, ellipse, ctx); + } +} + + +void LottieBuilder::updatePath(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto path = static_cast(*child); + + if (ctx->repeaters.empty()) { + _draw(parent, path, ctx); + if (path->pathset(frameNo, to(ctx->merging)->rs.path, ctx->transform, tween, exps, ctx->modifier)) { + PAINT(ctx->merging)->mark(RenderUpdateFlag::Path); + } + } else { + auto shape = path->pooling(); + shape->reset(); + path->pathset(frameNo, to(shape)->rs.path, ctx->transform, tween, exps, ctx->modifier); + _repeat(parent, shape, path, ctx); + } +} + + +static void _close(Array& pts, const Point& p, bool round) +{ + if (round && tvg::zero(pts.last() - pts[pts.count - 2])) pts[pts.count - 2] = p; + pts.last() = p; +} + + +void LottieBuilder::updateStar(LottiePolyStar* star, float frameNo, Matrix* transform, Shape* merging, RenderContext* ctx, Tween& tween, LottieExpressions* exps) +{ + static constexpr auto POLYSTAR_MAGIC_NUMBER = 0.47829f / 0.28f; + + auto ptsCnt = star->ptsCnt(frameNo, tween, exps); + auto innerRadius = star->innerRadius(frameNo, tween, exps); + auto outerRadius = star->outerRadius(frameNo, tween, exps); + auto innerRoundness = star->innerRoundness(frameNo, tween, exps) * 0.01f; + auto outerRoundness = star->outerRoundness(frameNo, tween, exps) * 0.01f; + + auto angle = deg2rad(-90.0f); + auto partialPointRadius = 0.0f; + auto anglePerPoint = (2.0f * MATH_PI / ptsCnt); + auto halfAnglePerPoint = anglePerPoint * 0.5f; + auto partialPointAmount = ptsCnt - floorf(ptsCnt); + auto longSegment = false; + auto numPoints = size_t(ceilf(ptsCnt) * 2); + auto direction = star->clockwise ? 1.0f : -1.0f; + auto hasRoundness = false; + bool roundedCorner = ctx->roundness && (tvg::zero(innerRoundness) || tvg::zero(outerRoundness)); + + Shape* shape; + if (roundedCorner || ctx->offset) { + shape = star->pooling(); + shape->reset(); + } else { + shape = merging; + } + + float x, y; + + if (!tvg::zero(partialPointAmount)) { + angle += halfAnglePerPoint * (1.0f - partialPointAmount) * direction; + } + + if (!tvg::zero(partialPointAmount)) { + partialPointRadius = innerRadius + partialPointAmount * (outerRadius - innerRadius); + x = partialPointRadius * cosf(angle); + y = partialPointRadius * sinf(angle); + angle += anglePerPoint * partialPointAmount * 0.5f * direction; + } else { + x = outerRadius * cosf(angle); + y = outerRadius * sinf(angle); + angle += halfAnglePerPoint * direction; + } + + if (tvg::zero(innerRoundness) && tvg::zero(outerRoundness)) { + to(shape)->rs.path.pts.reserve(numPoints + 2); + to(shape)->rs.path.cmds.reserve(numPoints + 3); + } else { + to(shape)->rs.path.pts.reserve(numPoints * 3 + 2); + to(shape)->rs.path.cmds.reserve(numPoints + 3); + hasRoundness = true; + } + + auto in = Point{x, y} * transform; + shape->moveTo(in.x, in.y); + + for (size_t i = 0; i < numPoints; i++) { + auto radius = longSegment ? outerRadius : innerRadius; + auto dTheta = halfAnglePerPoint; + if (!tvg::zero(partialPointRadius) && i == numPoints - 2) { + dTheta = anglePerPoint * partialPointAmount * 0.5f; + } + if (!tvg::zero(partialPointRadius) && i == numPoints - 1) { + radius = partialPointRadius; + } + auto previousX = x; + auto previousY = y; + x = radius * cosf(angle); + y = radius * sinf(angle); + + if (hasRoundness) { + auto cp1Theta = (tvg::atan2(previousY, previousX) - MATH_PI2 * direction); + auto cp1Dx = cosf(cp1Theta); + auto cp1Dy = sinf(cp1Theta); + auto cp2Theta = (tvg::atan2(y, x) - MATH_PI2 * direction); + auto cp2Dx = cosf(cp2Theta); + auto cp2Dy = sinf(cp2Theta); + + auto cp1Roundness = longSegment ? innerRoundness : outerRoundness; + auto cp2Roundness = longSegment ? outerRoundness : innerRoundness; + auto cp1Radius = longSegment ? innerRadius : outerRadius; + auto cp2Radius = longSegment ? outerRadius : innerRadius; + + auto cp1x = cp1Radius * cp1Roundness * POLYSTAR_MAGIC_NUMBER * cp1Dx / ptsCnt; + auto cp1y = cp1Radius * cp1Roundness * POLYSTAR_MAGIC_NUMBER * cp1Dy / ptsCnt; + auto cp2x = cp2Radius * cp2Roundness * POLYSTAR_MAGIC_NUMBER * cp2Dx / ptsCnt; + auto cp2y = cp2Radius * cp2Roundness * POLYSTAR_MAGIC_NUMBER * cp2Dy / ptsCnt; + + if (!tvg::zero(partialPointAmount) && ((i == 0) || (i == numPoints - 1))) { + cp1x *= partialPointAmount; + cp1y *= partialPointAmount; + cp2x *= partialPointAmount; + cp2y *= partialPointAmount; + } + auto in2 = Point{previousX - cp1x, previousY - cp1y} * transform; + auto in3 = Point{x + cp2x, y + cp2y} * transform; + auto in4 = Point{x, y} * transform; + shape->cubicTo(in2.x, in2.y, in3.x, in3.y, in4.x, in4.y); + } else { + auto in = Point{x, y} * transform; + shape->lineTo(in.x, in.y); + } + angle += dTheta * direction; + longSegment = !longSegment; + } + //ensure proper shape closure - important for modifiers that behave differently for degenerate (linear) vs curved cubics + _close(to(shape)->rs.path.pts, in, hasRoundness); + shape->close(); + + if (ctx->modifier) ctx->modifier->modifyPolystar(to(shape)->rs.path, to(merging)->rs.path, outerRoundness, hasRoundness); +} + + +void LottieBuilder::updatePolygon(LottieGroup* parent, LottiePolyStar* star, float frameNo, Matrix* transform, Shape* merging, RenderContext* ctx, Tween& tween, LottieExpressions* exps) +{ + static constexpr auto POLYGON_MAGIC_NUMBER = 0.25f; + + auto ptsCnt = size_t(floor(star->ptsCnt(frameNo, tween, exps))); + auto radius = star->outerRadius(frameNo, tween, exps); + auto outerRoundness = star->outerRoundness(frameNo, tween, exps) * 0.01f; + + auto angle = -MATH_PI2; + auto anglePerPoint = 2.0f * MATH_PI / float(ptsCnt); + auto direction = star->clockwise ? 1.0f : -1.0f; + auto hasRoundness = !tvg::zero(outerRoundness); + bool roundedCorner = ctx->roundness && !hasRoundness; + auto x = radius * cosf(angle); + auto y = radius * sinf(angle); + + angle += anglePerPoint * direction; + + Shape* shape; + if (roundedCorner || ctx->offset) { + shape = star->pooling(); + shape->reset(); + } else { + shape = merging; + if (hasRoundness) { + to(shape)->rs.path.pts.reserve(ptsCnt * 3 + 2); + to(shape)->rs.path.cmds.reserve(ptsCnt + 3); + } else { + to(shape)->rs.path.pts.reserve(ptsCnt + 2); + to(shape)->rs.path.cmds.reserve(ptsCnt + 3); + } + } + + auto in = Point{x, y} * transform; + shape->moveTo(in.x, in.y); + + auto coeff = anglePerPoint * radius * outerRoundness * POLYGON_MAGIC_NUMBER; + for (size_t i = 0; i < ptsCnt; i++) { + auto previousX = x; + auto previousY = y; + x = (radius * cosf(angle)); + y = (radius * sinf(angle)); + + if (hasRoundness) { + auto cp1Theta = tvg::atan2(previousY, previousX) - MATH_PI2 * direction; + auto cp1x = coeff * cosf(cp1Theta); + auto cp1y = coeff * sinf(cp1Theta); + auto cp2Theta = tvg::atan2(y, x) - MATH_PI2 * direction; + auto cp2x = coeff * cosf(cp2Theta); + auto cp2y = coeff * sinf(cp2Theta); + + auto in2 = Point{previousX - cp1x, previousY - cp1y} * transform; + auto in3 = Point{x + cp2x, y + cp2y} * transform; + auto in4 = Point{x, y} * transform; + shape->cubicTo(in2.x, in2.y, in3.x, in3.y, in4.x, in4.y); + } else { + Point in = {x, y}; + if (transform) in *= *transform; + shape->lineTo(in.x, in.y); + } + angle += anglePerPoint * direction; + } + //ensure proper shape closure - important for modifiers that behave differently for degenerate (linear) vs curved cubics + _close(to(shape)->rs.path.pts, in, hasRoundness); + shape->close(); + + if (ctx->modifier) ctx->modifier->modifyPolystar(to(shape)->rs.path, to(merging)->rs.path, 0.0f, false); +} + + +void LottieBuilder::updatePolystar(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto star = static_cast(*child); + + //Optimize: Can we skip the individual coords transform? + auto matrix = tvg::identity(); + translate(&matrix, star->position(frameNo, tween, exps)); + rotate(&matrix, star->rotation(frameNo, tween, exps)); + + if (ctx->transform) matrix = *ctx->transform * matrix; + + auto identity = tvg::identity((const Matrix*)&matrix); + + if (ctx->repeaters.empty()) { + _draw(parent, star, ctx); + if (star->type == LottiePolyStar::Star) updateStar(star, frameNo, (identity ? nullptr : &matrix), ctx->merging, ctx, tween, exps); + else updatePolygon(parent, star, frameNo, (identity ? nullptr : &matrix), ctx->merging, ctx, tween, exps); + PAINT(ctx->merging)->mark(RenderUpdateFlag::Path); + } else { + auto shape = star->pooling(); + shape->reset(); + if (star->type == LottiePolyStar::Star) updateStar(star, frameNo, (identity ? nullptr : &matrix), shape, ctx, tween, exps); + else updatePolygon(parent, star, frameNo, (identity ? nullptr : &matrix), shape, ctx, tween, exps); + _repeat(parent, shape, star, ctx); + } +} + + +void LottieBuilder::updateRoundedCorner(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto roundedCorner = static_cast(*child); + auto r = roundedCorner->radius(frameNo, tween, exps); + if (r < LottieRoundnessModifier::ROUNDNESS_EPSILON) return; + + if (!ctx->roundness) ctx->roundness = new LottieRoundnessModifier(&buffer, r); + else if (ctx->roundness->r < r) ctx->roundness->r = r; + + ctx->update(ctx->roundness); +} + + +void LottieBuilder::updateOffsetPath(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto offset = static_cast(*child); + if (!ctx->offset) ctx->offset = new LottieOffsetModifier(offset->offset(frameNo, tween, exps), offset->miterLimit(frameNo, tween, exps), offset->join); + + ctx->update(ctx->offset); +} + + +void LottieBuilder::updateRepeater(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto repeater = static_cast(*child); + + RenderRepeater r; + r.cnt = static_cast(repeater->copies(frameNo, tween, exps)); + r.transform = ctx->propagator->transform(); + r.offset = repeater->offset(frameNo, tween, exps); + r.position = repeater->position(frameNo, tween, exps); + r.anchor = repeater->anchor(frameNo, tween, exps); + r.scale = repeater->scale(frameNo, tween, exps); + r.rotation = repeater->rotation(frameNo, tween, exps); + r.startOpacity = repeater->startOpacity(frameNo, tween, exps); + r.endOpacity = repeater->endOpacity(frameNo, tween, exps); + r.inorder = repeater->inorder; + ctx->repeaters.push(r); + + ctx->merging = nullptr; +} + + +void LottieBuilder::updateTrimpath(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist& contexts, RenderContext* ctx) +{ + auto trimpath = static_cast(*child); + + float begin, end; + trimpath->segment(frameNo, begin, end, tween, exps); + + if (to(ctx->propagator)->rs.stroke) { + auto length = fabsf(begin - end); + auto tmp = begin; + begin = (length * to(ctx->propagator)->rs.stroke->trim.begin) + tmp; + end = (length * to(ctx->propagator)->rs.stroke->trim.end) + tmp; + } + + ctx->propagator->trimpath(begin, end, trimpath->type == LottieTrimpath::Type::Simultaneous); + ctx->merging = nullptr; +} + + +void LottieBuilder::updateChildren(LottieGroup* parent, float frameNo, Inlist& contexts) +{ + contexts.head->begin = parent->children.end() - 1; + + while (!contexts.empty()) { + auto ctx = contexts.front(); + ctx->reqFragment = parent->reqFragment; + auto stop = false; + for (auto child = ctx->begin; child >= parent->children.data; --child) { + //Here switch-case statements are more performant than virtual methods. + switch ((*child)->type) { + case LottieObject::Group: { + updateGroup(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Transform: { + updateTransform(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::SolidFill: { + stop = updateSolidFill(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::SolidStroke: { + stop = updateSolidStroke(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::GradientFill: { + stop = updateGradientFill(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::GradientStroke: { + stop = updateGradientStroke(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Rect: { + updateRect(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Ellipse: { + updateEllipse(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Path: { + updatePath(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Polystar: { + updatePolystar(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Trimpath: { + updateTrimpath(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::Repeater: { + updateRepeater(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::RoundedCorner: { + updateRoundedCorner(parent, child, frameNo, contexts, ctx); + break; + } + case LottieObject::OffsetPath: { + updateOffsetPath(parent, child, frameNo, contexts, ctx); + break; + } + default: break; + } + + //stop processing for those invisible contents + if (stop || ctx->propagator->opacity() == 0) break; + } + delete(ctx); + } +} + + +void LottieBuilder::updatePrecomp(LottieComposition* comp, LottieLayer* precomp, float frameNo) +{ + if (precomp->children.empty()) return; + + frameNo = precomp->remap(comp, frameNo, exps); + + ARRAY_REVERSE_FOREACH(c, precomp->children) { + auto child = static_cast(*c); + if (!child->matteSrc) updateLayer(comp, precomp->scene, child, frameNo); + } + + //clip the layer viewport + auto clipper = precomp->statical.pooling(true); + clipper->transform(precomp->cache.matrix); + precomp->scene->clip(clipper); +} + + +void LottieBuilder::updatePrecomp(LottieComposition* comp, LottieLayer* precomp, float frameNo, Tween& tween) +{ + //record & recover the tweening frame number before remapping + auto record = tween.frameNo; + tween.frameNo = precomp->remap(comp, record, exps); + + updatePrecomp(comp, precomp, frameNo); + + tween.frameNo = record; +} + + +void LottieBuilder::updateSolid(LottieLayer* layer) +{ + auto solidFill = layer->statical.pooling(true); + solidFill->opacity(layer->cache.opacity); + layer->scene->add(solidFill); +} + + +void LottieBuilder::updateImage(LottieGroup* layer) +{ + auto image = static_cast(layer->children.first()); + auto picture = image->bitmap.picture; + + //resolve an image asset if need + if (resolver && !image->resolved) { + resolver->func(picture, image->bitmap.path, resolver->data); + picture->size(image->bitmap.width, image->bitmap.height); + image->resolved = true; + } + + //LottieImage can be shared among other layers + layer->scene->add(picture->refCnt() == 1 ? picture : picture->duplicate()); +} + + +void LottieBuilder::updateURLFont( LottieLayer* layer, float frameNo, LottieText* text, const TextDocument& doc) +{ + //text load + auto paint = Text::gen(); + if (paint->font(doc.name) != Result::Success) { + if (!(text->font && resolver && resolver->func(paint, text->font->path, resolver->data))) { + paint->font(nullptr); //fallback to any available font + } + } + + //text build + auto len = strlen(doc.text); + auto buf = tvg::malloc(len + 1); + + // preprocessing text for modern systems: handle carriage return ('\r') and end-of-text ('\3') + // as line feed ('\n') only when they appear independently. + auto p = buf; + auto feed = false; + for (size_t i = 0; i < len; ++i) { + //replace the carriage return and end of text with line feed. + if (doc.text[i] == '\r' || doc.text[i] == '\3') { + if (!feed) *p = '\n'; + else continue; + } else *p = doc.text[i]; + feed = (*p == '\n') ? true : false; + ++p; + } + *p = '\0'; + + auto color = doc.color; + paint->fill(color.r, color.g, color.b); + paint->size(doc.size * 75.0f); //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75 + paint->text(buf); + paint->align(-doc.justify, 0.0f); + paint->translate(0.0f, doc.size * -100.0f); + layer->scene->add(paint); + + //outline + auto strkColor = doc.stroke.color; + if (doc.stroke.width > 0.0f) paint->outline(doc.stroke.width, strkColor.r, strkColor.g, strkColor.b); + + tvg::free(buf); + + //text range + if (text->ranges.empty()) return; + + //FIXME: it only considers a single text-range. + ARRAY_FOREACH(p, text->ranges) { + auto range = *p; + auto f = range->factor(frameNo, float(len), 0.0f); + if (tvg::zero(f)) continue; + + //fill & opacity + range->color(frameNo, color, strkColor, f, tween, exps); + paint->fill(color.r, color.g, color.b); + paint->opacity(range->style.opacity(frameNo, tween, exps)); + + //stroke + if (range->style.flags.strokeWidth) { + paint->outline(f * range->style.strokeWidth(frameNo, tween, exps), strkColor.r, strkColor.g, strkColor.b); + } + } +} + + +Shape* LottieBuilder::textShape(LottieText* text, float frameNo, const TextDocument& doc, LottieGlyph* glyph, const RenderText& ctx) +{ + auto& transform = ctx.lineScene->transform(); + auto shape = text->pooling(); + shape->reset(); + + ARRAY_FOREACH(p, glyph->children) { + auto group = static_cast(*p); + ARRAY_FOREACH(p, group->children) { + if (static_cast(*p)->pathset(frameNo, to(shape)->rs.path, nullptr, tween, exps)) { + PAINT(shape)->mark(RenderUpdateFlag::Path); + } + } + } + shape->fill(doc.color.r, doc.color.g, doc.color.b); + shape->translate(ctx.cursor.x - transform.e13, ctx.cursor.y - transform.e23); + shape->opacity(255); + + if (doc.stroke.width > 0.0f) { + shape->strokeJoin(StrokeJoin::Round); + shape->strokeWidth(doc.stroke.width / ctx.scale); + shape->strokeFill(doc.stroke.color.r, doc.stroke.color.g, doc.stroke.color.b); + shape->order(doc.stroke.below); + } + return shape; +} + + +bool LottieBuilder::updateTextRange(LottieText* text, float frameNo, Shape* shape, const TextDocument& doc, RenderText& ctx) +{ + if (text->ranges.empty()) return false; + + auto& transform = ctx.lineScene->transform(); + Point scaling = {1.0f, 1.0f}; + Point translation = {}; + auto rotation = 0.0f; + auto color = doc.color; + auto strokeColor = doc.stroke.color; + uint8_t opacity = 255, fillOpacity = 255, strokeOpacity = 255; + auto needGroup = false; + + ARRAY_FOREACH(p, text->ranges) { + auto range = *p; + auto basedIdx = ctx.idx; + + if (range->based == LottieTextRange::Based::CharsExcludingSpaces) basedIdx = ctx.idx - ctx.space; + else if (range->based == LottieTextRange::Based::Words) basedIdx = ctx.line + ctx.space; + else if (range->based == LottieTextRange::Based::Lines) basedIdx = ctx.line; + + auto f = range->factor(frameNo, float(ctx.nChars), (float)basedIdx); + if (tvg::zero(f)) continue; + + needGroup = true; + + //transform + translation = translation + f * range->style.position(frameNo, tween, exps); + scaling *= (f * (range->style.scale(frameNo, tween, exps) * 0.01f - Point{1.0f, 1.0f}) + Point{1.0f, 1.0f}); + rotation += f * range->style.rotation(frameNo, tween, exps); + + //fill & opacity + opacity = (uint8_t)(opacity - f * (opacity - range->style.opacity(frameNo, tween, exps))); + shape->opacity(opacity); + + range->color(frameNo, color, strokeColor, f, tween, exps); + fillOpacity = (uint8_t)(fillOpacity - f * (fillOpacity - range->style.fillOpacity(frameNo, tween, exps))); + shape->fill(color.r, color.g, color.b, fillOpacity); + + //stroke + if (range->style.flags.strokeWidth) shape->strokeWidth(f * range->style.strokeWidth(frameNo, tween, exps) / ctx.scale); + if (shape->strokeWidth() > 0.0f) { + strokeOpacity = (uint8_t)(strokeOpacity - f * (strokeOpacity - range->style.strokeOpacity(frameNo, tween, exps))); + shape->strokeFill(strokeColor.r, strokeColor.g, strokeColor.b, strokeOpacity); + shape->order(doc.stroke.below); + } + ctx.cursor.x += f * range->style.letterSpace(frameNo, tween, exps); + auto spacing = f * range->style.lineSpace(frameNo, tween, exps); + if (spacing > ctx.lineSpace) ctx.lineSpace = spacing; + } + // Apply line group transformation just once + if (ctx.lineScene->paints().empty() && needGroup) { + tvg::identity(&transform); + translate(&transform, ctx.cursor); + + // center pivoting + auto align = text->alignOp.anchor(frameNo, tween, exps); + transform.e13 += align.x; + transform.e23 += align.y; + rotate(&transform, rotation); + + //center pivoting + auto pivot = align * -1; + transform.e13 += (pivot.x * transform.e11 + pivot.x * transform.e12); + transform.e23 += (pivot.y * transform.e21 + pivot.y * transform.e22); + ctx.lineScene->transform(transform); + } + auto& matrix = shape->transform(); + tvg::identity(&matrix); + translate(&matrix, (translation / ctx.scale + ctx.cursor) - Point{transform.e13, transform.e23}); + tvg::scale(&matrix, scaling * ctx.capScale); + shape->transform(matrix); + + if (needGroup) ctx.lineScene->add(shape); + + return needGroup; +} + + +static void _commit(LottieGlyph* glyph, Shape* shape, const RenderText& ctx) +{ + auto& matrix = shape->transform(); + + if (ctx.follow) { + tvg::identity(&matrix); + auto angle = 0.0f; + auto width = glyph->width * 0.5f; + auto pos = ctx.follow->position(ctx.cursor.x + width + ctx.firstMargin, angle); + matrix.e11 = matrix.e22 = ctx.capScale; + matrix.e13 = pos.x - width * matrix.e11; + matrix.e23 = pos.y - width * matrix.e21; + } else { + matrix.e11 = matrix.e22 = ctx.capScale; + matrix.e13 = ctx.cursor.x; + matrix.e23 = ctx.cursor.y; + } + shape->transform(matrix); + ctx.textScene->add(shape); +} + + +void LottieBuilder::updateLocalFont(LottieLayer* layer, float frameNo, LottieText* text, const TextDocument& doc) +{ + RenderText ctx(text, doc); + ctx.follow = (text->follow && ((uint32_t)text->follow->maskIdx < layer->masks.count)) ? text->follow : nullptr; + ctx.firstMargin = ctx.follow ? ctx.follow->prepare(layer->masks[ctx.follow->maskIdx], frameNo, ctx.scale, tween, exps) : 0.0f; + auto lineWrapped = false; + + //text string + while (true) { + //new line of the cursor position + if (lineWrapped || *ctx.p == 13 || *ctx.p == 3 || *ctx.p == '\0') { + //text layout position + auto ascent = text->font->ascent * ctx.scale; + if (ascent > doc.bbox.size.y) ascent = doc.bbox.size.y; + + //horizontal alignment + Point layout = {doc.bbox.pos.x, doc.bbox.pos.y + ascent - doc.shift}; + layout.x += doc.justify * (-1.0f * doc.bbox.size.x + ctx.cursor.x * ctx.scale); + + //new text group, single scene based on text-grouping + ctx.textScene->add(ctx.lineScene); + ctx.textScene->translate(layout.x, layout.y); + ctx.textScene->scale(ctx.scale); + layer->scene->add(ctx.textScene); + + ctx.lineScene = Scene::gen(); + ctx.lineScene->translate(ctx.cursor.x, ctx.cursor.y); + + if (*ctx.p == '\0') { + ctx.textScene = nullptr; + break; + } + if (!lineWrapped) ++ctx.p; + + ctx.totalLineSpace += ctx.lineSpace; + ctx.lineSpace = 0.0f; + lineWrapped = false; + + //new text group, single scene for each line + ctx.textScene = Scene::gen(); + ctx.cursor = {0.0f, (++ctx.line * doc.height + ctx.totalLineSpace) / ctx.scale}; + continue; + } + if (*ctx.p == ' ') { + ++ctx.space; + //new text group, single scene for each word + if (text->alignOp.group == LottieText::AlignOption::Group::Word) { + ctx.textScene->add(ctx.lineScene); + ctx.lineScene = Scene::gen(); + ctx.lineScene->translate(ctx.cursor.x, ctx.cursor.y); + } + } + /* all lowercase letters are converted to uppercase in the "t" text field, making the "ca" value irrelevant, thus AllCaps is nothing to do. + So only convert lowercase letters to uppercase (for 'SmallCaps' an extra scaling factor applied) */ + ctx.capScale = 1.0f; + auto code = ctx.p; + char capCode; + if ((unsigned char)(ctx.p[0]) < 0x80 && doc.caps) { + if (*ctx.p >= 'a' && *ctx.p <= 'z') { + capCode = *ctx.p + 'A' - 'a'; + code = &capCode; + if (doc.caps == 2) ctx.capScale = 0.7f; + } + } + // text building + auto found = false; + ARRAY_FOREACH(g, text->font->chars) { + auto glyph = *g; + //draw matched glyphs + if (!strncmp(glyph->code, code, glyph->len)) { + //new text group, single scene for each characters + if (text->alignOp.group == LottieText::AlignOption::Group::Chars || text->alignOp.group == LottieText::AlignOption::Group::All) { + ctx.textScene->add(ctx.lineScene); + ctx.lineScene = Scene::gen(); + ctx.lineScene->translate(ctx.cursor.x, ctx.cursor.y); + } + auto shape = textShape(text, frameNo, doc, glyph, ctx); + if (!updateTextRange(text, frameNo, shape, doc, ctx)) _commit(glyph, shape, ctx); + if (doc.bbox.size.x > 0.0f && ctx.cursor.x * ctx.scale >= doc.bbox.size.x) lineWrapped = true; + else ctx.cursor.x += (glyph->width + doc.tracking) * ctx.capScale; + ctx.p += glyph->len; + ctx.idx += glyph->len; + found = true; + break; + } + } + if (!found) { + ++ctx.p; + ++ctx.idx; + } + } +} + + +void LottieBuilder::updateText(LottieLayer* layer, float frameNo) +{ + auto text = static_cast(layer->children.first()); + auto& doc = text->doc(frameNo, exps); + if (text->font && text->font->origin == LottieFont::Origin::Local && !text->font->chars.empty()) { + updateLocalFont(layer, frameNo, text, doc); + } else { + updateURLFont(layer, frameNo, text, doc); + } +} + + +void LottieBuilder::updateMasks(LottieLayer* layer, float frameNo) +{ + if (layer->masks.count == 0) return; + + //Introduce an intermediate scene for embracing matte + masking or precomp clipping + masking replaced by clipping + if (layer->matteTarget || layer->type == LottieLayer::Precomp) { + auto scene = Scene::gen(); + scene->add(layer->scene); + layer->scene = scene; + } + + Shape* pShape = nullptr; + MaskMethod pMethod; + uint8_t pOpacity; + + ARRAY_FOREACH(p, layer->masks) { + auto mask = *p; + if (mask->method == MaskMethod::None) continue; + + auto method = mask->method; + auto opacity = mask->opacity(frameNo); + auto expand = mask->expand(frameNo); + + //the first mask + if (!pShape) { + pShape = layer->pooling(); + to(pShape)->reset(); + auto compMethod = (method == MaskMethod::Subtract || method == MaskMethod::InvAlpha) ? MaskMethod::InvAlpha : MaskMethod::Alpha; + //Cheaper. Replace the masking with a clipper + if (layer->effects.empty() && layer->masks.count == 1 && compMethod == MaskMethod::Alpha) { + layer->scene->opacity(MULTIPLY(layer->scene->opacity(), opacity)); + layer->scene->clip(pShape); + } else { + layer->scene->mask(pShape, compMethod); + } + //Chain mask composition + } else if (pMethod != method || pOpacity != opacity || (method != MaskMethod::Subtract && method != MaskMethod::Difference)) { + auto shape = layer->pooling(); + to(shape)->reset(); + pShape->mask(shape, method); + pShape = shape; + } + + pShape->fill(255, 255, 255, opacity); + pShape->transform(layer->cache.matrix); + + //Default Masking + if (expand == 0.0f) { + mask->pathset(frameNo, to(pShape)->rs.path, nullptr, tween, exps); + //Masking with Expansion (Offset) + } else { + //TODO: Once path direction support is implemented, ensure that the direction is ignored here + auto offset = LottieOffsetModifier(expand); + mask->pathset(frameNo, to(pShape)->rs.path, nullptr, tween, exps, &offset); + } + pOpacity = opacity; + pMethod = method; + } +} + + +bool LottieBuilder::updateMatte(LottieComposition* comp, float frameNo, Scene* scene, LottieLayer* layer) +{ + auto target = layer->matteTarget; + if (!target || target->type == LottieLayer::Null) return true; + + updateLayer(comp, scene, target, frameNo); + + if (target->scene) { + layer->scene->mask(target->scene, layer->matteType); + } else if (layer->matteType == MaskMethod::Alpha || layer->matteType == MaskMethod::Luma) { + //matte target is not exist. alpha blending definitely bring an invisible result + Paint::rel(layer->scene); + layer->scene = nullptr; + return false; + } + return true; +} + + +void LottieBuilder::updateStrokeEffect(LottieLayer* layer, LottieFxStroke* effect, float frameNo) +{ + if (layer->masks.count == 0) return; + + auto shape = layer->pooling(); + shape->reset(); + + //FIXME: all mask + if (effect->allMask(frameNo)) { + ARRAY_FOREACH(p, layer->masks) { + (*p)->pathset(frameNo, to(shape)->rs.path, nullptr, tween, exps); + } + //A specific mask + } else { + auto idx = static_cast(effect->mask(frameNo) - 1); + if (idx < 0 || idx >= layer->masks.count) return; + layer->masks[idx]->pathset(frameNo, to(shape)->rs.path, nullptr, tween, exps); + } + + shape->transform(layer->cache.matrix); + shape->trimpath(effect->begin(frameNo) * 0.01f, effect->end(frameNo) * 0.01f); + shape->strokeFill(255, 255, 255, (int)(effect->opacity(frameNo) * 255.0f)); + shape->strokeJoin(StrokeJoin::Round); + shape->strokeCap(StrokeCap::Round); + + auto size = effect->size(frameNo) * 2.0f; + shape->strokeWidth(size); + + //fill the color to the layer shapes if any + auto color = effect->color(frameNo); + if (color.r != 255 || color.g != 255 || color.b != 255) { + auto accessor = tvg::Accessor::gen(); + auto stroke = (layer->type == LottieLayer::Type::Shape) ? true : false; + auto f = [color, size, stroke](const tvg::Paint* paint, void* data) -> bool { + if (paint->type() == tvg::Type::Shape) { + auto shape = (tvg::Shape*) paint; + //expand shape to fill the stroke region + if (stroke) { + shape->strokeWidth(size); + shape->strokeFill(color.r, color.g, color.b, 255); + } + shape->fill(color.r, color.g, color.b, 255); + } + return true; + }; + accessor->set(layer->scene, f, nullptr); + delete(accessor); + } + + layer->scene->mask(shape, MaskMethod::Alpha); +} + + +void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo, uint8_t quality) +{ + constexpr float BLUR_TO_SIGMA = 0.3f; + + if (layer->effects.count == 0) return; + + ARRAY_FOREACH(p, layer->effects) { + if (!(*p)->enable) continue; + switch ((*p)->type) { + case LottieEffect::Tint: { + auto effect = static_cast(*p); + auto black = effect->black(frameNo); + auto white = effect->white(frameNo); + layer->scene->add(SceneEffect::Tint, black.r, black.g, black.b, white.r, white.g, white.b, (double)effect->intensity(frameNo)); + break; + } + case LottieEffect::Fill: { + auto effect = static_cast(*p); + auto color = effect->color(frameNo); + layer->scene->add(SceneEffect::Fill, color.r, color.g, color.b, (int)(255.0f * effect->opacity(frameNo))); + break; + } + case LottieEffect::Stroke: { + auto effect = static_cast(*p); + updateStrokeEffect(layer, effect, frameNo); + break; + } + case LottieEffect::Tritone: { + auto effect = static_cast(*p); + auto dark = effect->dark(frameNo); + auto midtone = effect->midtone(frameNo); + auto bright = effect->bright(frameNo); + layer->scene->add(SceneEffect::Tritone, dark.r, dark.g, dark.b, midtone.r, midtone.g, midtone.b, bright.r, bright.g, bright.b, (int)effect->blend(frameNo)); + break; + } + case LottieEffect::DropShadow: { + auto effect = static_cast(*p); + auto color = effect->color(frameNo); + //seems the opacity range in dropshadow is 0 ~ 256 + layer->scene->add(SceneEffect::DropShadow, color.r, color.g, color.b, std::min(255, (int)effect->opacity(frameNo)), (double)effect->angle(frameNo), double(effect->distance(frameNo)), (double)(effect->blurness(frameNo) * BLUR_TO_SIGMA), quality); + break; + } + case LottieEffect::GaussianBlur: { + auto effect = static_cast(*p); + layer->scene->add(SceneEffect::GaussianBlur, (double)(effect->blurness(frameNo) * BLUR_TO_SIGMA), effect->direction(frameNo) - 1, effect->wrap(frameNo), quality); + break; + } + default: break; + } + } +} + + +void LottieBuilder::updateLayer(LottieComposition* comp, Scene* scene, LottieLayer* layer, float frameNo) +{ + layer->scene = nullptr; + + //visibility + if (frameNo < layer->inFrame || frameNo >= layer->outFrame) return; + + updateTransform(layer, frameNo); + + //full transparent scene. no need to perform + if (layer->type != LottieLayer::Null && layer->cache.opacity == 0) return; + + //Prepare render data + layer->scene = Scene::gen(); + layer->scene->id = layer->id; + + //ignore opacity when Null layer? + if (layer->type != LottieLayer::Null) layer->scene->opacity(layer->cache.opacity); + + layer->scene->transform(layer->cache.matrix); + + if (!layer->matteSrc && !updateMatte(comp, frameNo, scene, layer)) return; + + switch (layer->type) { + case LottieLayer::Precomp: { + if (!tweening()) updatePrecomp(comp, layer, frameNo); + else updatePrecomp(comp, layer, frameNo, tween); + break; + } + case LottieLayer::Solid: { + updateSolid(layer); + break; + } + case LottieLayer::Image: { + updateImage(layer); + break; + } + case LottieLayer::Text: { + updateText(layer, frameNo); + break; + } + default: { + if (!layer->children.empty()) { + Inlist contexts; + contexts.back(new RenderContext(layer->pooling())); + updateChildren(layer, frameNo, contexts); + contexts.free(); + } + break; + } + } + + updateMasks(layer, frameNo); + + layer->scene->blend(layer->blendMethod); + + updateEffect(layer, frameNo, comp->quality); + + if (!layer->matteSrc) scene->add(layer->scene); +} + + +static void _buildReference(LottieComposition* comp, LottieLayer* layer) +{ + ARRAY_FOREACH(p, comp->assets) { + if (layer->rid != (*p)->id) continue; + if (layer->type == LottieLayer::Precomp) { + auto assetLayer = static_cast(*p); + if (_buildComposition(comp, assetLayer)) { + layer->children = assetLayer->children; + layer->reqFragment = assetLayer->reqFragment; + } + } else if (layer->type == LottieLayer::Image) { + layer->children.push(*p); + } + break; + } +} + + +static void _buildHierarchy(LottieGroup* parent, LottieLayer* child) +{ + if (child->pix == -1) return; + + if (child->matteTarget && child->pix == child->matteTarget->ix) { + child->parent = child->matteTarget; + return; + } + + ARRAY_FOREACH(p, parent->children) { + auto parent = static_cast(*p); + if (child == parent) continue; + if (child->pix == parent->ix) { + child->parent = parent; + break; + } + if (parent->matteTarget && parent->matteTarget->ix == child->pix) { + child->parent = parent->matteTarget; + break; + } + } +} + + +static void _attachFont(LottieComposition* comp, LottieLayer* parent) +{ + //TODO: Consider to migrate this attachment to the frame update time. + ARRAY_FOREACH(p, parent->children) { + auto text = static_cast(*p); + auto& doc = text->doc(0); + if (!doc.name) continue; + auto len = strlen(doc.name); + for (uint32_t i = 0; i < comp->fonts.count; ++i) { + auto font = comp->fonts[i]; + auto len2 = strlen(font->name); + if (len == len2 && !strcmp(font->name, doc.name)) { + text->font = font; + break; + } + } + } +} + + +static bool _buildComposition(LottieComposition* comp, LottieLayer* parent) +{ + if (parent->children.count == 0) return false; + if (parent->buildDone) return true; + parent->buildDone = true; + + ARRAY_FOREACH(p, parent->children) { + auto child = static_cast(*p); + + //attach the precomp layer. + if (child->rid) _buildReference(comp, child); + + if (child->matteType != MaskMethod::None) { + //no index of the matte layer is provided: the layer above is used as the matte source + if (child->mix == -1) { + if (p > parent->children.begin()) { + child->matteTarget = static_cast(*(p - 1)); + } + //matte layer is specified by an index. + } else child->matteTarget = parent->layerByIdx(child->mix); + } + + if (child->matteTarget) { + child->matteTarget->matteSrc = true; + //parenting + _buildHierarchy(parent, child->matteTarget); + //precomp referencing + if (child->matteTarget->rid) _buildReference(comp, child->matteTarget); + } + _buildHierarchy(parent, child); + + //attach the necessary font data + if (child->type == LottieLayer::Text) _attachFont(comp, child); + } + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +bool LottieBuilder::update(LottieComposition* comp, float frameNo) +{ + if (comp->root->children.empty()) return false; + + comp->clamp(frameNo); + + if (tweening()) { + comp->clamp(tween.frameNo); + //tweening is not necessary. + if (equal(frameNo, tween.frameNo)) offTween(); + } + + if (exps && comp->expressions) exps->update(comp->timeAtFrame(frameNo)); + + //update children layers + ARRAY_REVERSE_FOREACH(child, comp->root->children) { + auto layer = static_cast(*child); + if (!layer->matteSrc) updateLayer(comp, comp->root->scene, layer, frameNo); + } + + return true; +} + + +void LottieBuilder::build(LottieComposition* comp) +{ + if (!comp) return; + + comp->root->scene = Scene::gen(); + + _buildComposition(comp, comp->root); + + //viewport clip + auto clip = Shape::gen(); + clip->appendRect(0, 0, comp->w, comp->h); + comp->root->scene->clip(clip); + + //turn off partial rendering for children + to(comp->root->scene)->size({comp->w, comp->h}); +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieBuilder.h b/components/thorvg-main/src/loaders/lottie/tvgLottieBuilder.h new file mode 100644 index 0000000..0bb93d8 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieBuilder.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_BUILDER_H_ +#define _TVG_LOTTIE_BUILDER_H_ + +#include "tvgCommon.h" +#include "tvgInlist.h" +#include "tvgShape.h" +#include "tvgLottieExpressions.h" +#include "tvgLottieModifier.h" + +struct LottieComposition; +struct AssetResolver; + +struct RenderRepeater +{ + int cnt; + Matrix transform; + float offset; + Point position; + Point anchor; + Point scale; + float rotation; + uint8_t startOpacity; + uint8_t endOpacity; + bool inorder; +}; + +struct RenderText +{ + Point cursor{}; + int line = 0, space = 0, idx = 0; + float lineSpace = 0.0f, totalLineSpace = 0.0f; + char *p; //current processing character + int nChars; + float scale; + Scene* textScene; + Scene* lineScene; + float capScale, firstMargin; + LottieTextFollowPath* follow; + + RenderText(LottieText* text, const TextDocument& doc) : p(doc.text), nChars(strlen(p)), scale(doc.size), textScene(Scene::gen()), lineScene(Scene::gen()) + { + } + + ~RenderText() + { + Paint::rel(textScene); + Paint::rel(lineScene); + } +}; + +enum RenderFragment : uint8_t {ByNone = 0, ByFill, ByStroke}; + +struct RenderContext +{ + INLIST_ITEM(RenderContext); + + Shape* propagator = nullptr; //for propagating the shape properties excluding paths + Shape* merging = nullptr; //merging shapes if possible (if shapes have same properties) + LottieObject** begin = nullptr; //iteration entry point + Array repeaters; + Matrix* transform = nullptr; + LottieRoundnessModifier* roundness = nullptr; + LottieOffsetModifier* offset = nullptr; + LottieModifier* modifier = nullptr; + RenderFragment fragment = ByNone; //render context has been fragmented + bool reqFragment = false; //requirement to fragment the render context + + RenderContext(Shape* propagator) + { + to(propagator)->reset(); + propagator->ref(); + this->propagator = propagator; + } + + ~RenderContext() + { + propagator->unref(false); + delete(transform); + delete(roundness); + delete(offset); + } + + RenderContext(const RenderContext& rhs, Shape* propagator, bool mergeable = false) : propagator(propagator) + { + if (mergeable) merging = rhs.merging; + propagator->ref(); + repeaters = rhs.repeaters; + fragment = rhs.fragment; + if (rhs.roundness) { + roundness = new LottieRoundnessModifier(rhs.roundness->buffer, rhs.roundness->r); + update(roundness); + } + if (rhs.offset) { + offset = new LottieOffsetModifier(rhs.offset->offset, rhs.offset->miterLimit, rhs.offset->join); + update(offset); + } + if (rhs.transform) { + transform = new Matrix; + *transform = *rhs.transform; + } + } + + void update(LottieModifier* next) + { + if (modifier) modifier = modifier->decorate(next); + else modifier = next; + } +}; + +struct LottieBuilder +{ + LottieBuilder() + { + exps = LottieExpressions::instance(); + } + + ~LottieBuilder() + { + LottieExpressions::retrieve(exps); + } + + bool expressions() + { + return exps ? true : false; + } + + void offTween() + { + if (tween.active) tween.active = false; + } + + void onTween(float to, float progress) + { + tween.frameNo = to; + tween.progress = progress; + tween.active = true; + } + + bool tweening() + { + return tween.active; + } + + bool update(LottieComposition* comp, float progress); + void build(LottieComposition* comp); + + const AssetResolver* resolver = nullptr; //do not free this + +private: + void appendRect(Shape* shape, Point& pos, Point& size, float r, bool clockwise, RenderContext* ctx); + bool fragmented(LottieGroup* parent, LottieObject** child, Inlist& contexts, RenderContext* ctx, RenderFragment fragment); + Shape* textShape(LottieText* text, float frameNo, const TextDocument& doc, LottieGlyph* glyph, const RenderText& ctx); + + void updateStrokeEffect(LottieLayer* layer, LottieFxStroke* effect, float frameNo); + void updateEffect(LottieLayer* layer, float frameNo, uint8_t quality); + void updateLayer(LottieComposition* comp, Scene* scene, LottieLayer* layer, float frameNo); + bool updateMatte(LottieComposition* comp, float frameNo, Scene* scene, LottieLayer* layer); + void updatePrecomp(LottieComposition* comp, LottieLayer* precomp, float frameNo); + void updatePrecomp(LottieComposition* comp, LottieLayer* precomp, float frameNo, Tween& tween); + void updateSolid(LottieLayer* layer); + void updateImage(LottieGroup* layer); + void updateURLFont(LottieLayer* layer, float frameNo, LottieText* text, const TextDocument& doc); + void updateLocalFont(LottieLayer* layer, float frameNo, LottieText* text, const TextDocument& doc); + bool updateTextRange(LottieText* text, float frameNo, Shape* shape, const TextDocument& doc, RenderText& ctx); + void updateText(LottieLayer* layer, float frameNo); + void updateMasks(LottieLayer* layer, float frameNo); + void updateTransform(LottieLayer* layer, float frameNo); + void updateChildren(LottieGroup* parent, float frameNo, Inlist& contexts); + void updateGroup(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& pcontexts, RenderContext* ctx); + void updateTransform(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + bool updateSolidFill(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + bool updateSolidStroke(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + bool updateGradientFill(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + bool updateGradientStroke(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updateRect(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updateEllipse(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updatePath(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updatePolystar(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updateStar(LottiePolyStar* star, float frameNo, Matrix* transform, Shape* merging, RenderContext* ctx, Tween& tween, LottieExpressions* exps); + void updatePolygon(LottieGroup* parent, LottiePolyStar* star, float frameNo, Matrix* transform, Shape* merging, RenderContext* ctx, Tween& tween, LottieExpressions* exps); + void updateTrimpath(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updateRepeater(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updateRoundedCorner(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + void updateOffsetPath(LottieGroup* parent, LottieObject** child, float frameNo, Inlist& contexts, RenderContext* ctx); + + RenderPath buffer; //reusable path + LottieExpressions* exps; + Tween tween; +}; + +#endif //_TVG_LOTTIE_BUILDER_H \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieData.h b/components/thorvg-main/src/loaders/lottie/tvgLottieData.h new file mode 100644 index 0000000..13ae354 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieData.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_COMMON_ +#define _TVG_LOTTIE_COMMON_ + +#include +#include "tvgCommon.h" +#include "tvgArray.h" + +struct PathSet +{ + Point* pts = nullptr; + PathCommand* cmds = nullptr; + uint16_t ptsCnt = 0; + uint16_t cmdsCnt = 0; +}; + + +struct RGB32 +{ + int32_t r, g, b; +}; + + +struct ColorStop +{ + Fill::ColorStop* data = nullptr; + Array* input = nullptr; + + void copy(const ColorStop& rhs, uint32_t cnt) + { + if (rhs.data) { + data = tvg::malloc(sizeof(Fill::ColorStop) * cnt); + memcpy(data, rhs.data, sizeof(Fill::ColorStop) * cnt); + } + if (rhs.input) TVGERR("LOTTIE", "Must be populated!"); + } +}; + + +struct TextDocument +{ + char* text = nullptr; + float height; + float shift; + RGB32 color; + struct { + Point pos; + Point size{}; + } bbox; + struct { + RGB32 color; + float width; + bool below = false; + } stroke; + char* name = nullptr; + float size; + float tracking = 0.0f; + float justify = 0.0f; //horizontal alignment + uint8_t caps = 0; //0: Regular, 1: AllCaps, 2: SmallCaps + + void copy(const TextDocument& rhs) + { + text = duplicate(rhs.text); + name = duplicate(rhs.name); + } +}; + + +struct Tween +{ + float frameNo = 0.0f; + float progress = 0.0f; //greater than 0 and smaller than 1 + bool active = false; +}; + + +static inline int32_t REMAP255(float val) +{ + return (int32_t)nearbyintf(val * 255.0f); +} + + +static inline RGB32 operator-(const RGB32& lhs, const RGB32& rhs) +{ + return {lhs.r - rhs.r, lhs.g - rhs.g, lhs.b - rhs.b}; +} + + +static inline RGB32 operator+(const RGB32& lhs, const RGB32& rhs) +{ + return {lhs.r + rhs.r, lhs.g + rhs.g, lhs.b + rhs.b}; +} + + +static inline RGB32 operator*(const RGB32& lhs, float rhs) +{ + return {(int32_t)nearbyintf(lhs.r * rhs), (int32_t)nearbyintf(lhs.g * rhs), (int32_t)nearbyintf(lhs.b * rhs)}; +} + + +#endif //_TVG_LOTTIE_COMMON_ diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieExpressions.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieExpressions.cpp new file mode 100644 index 0000000..6fe3a3f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieExpressions.cpp @@ -0,0 +1,1462 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "tvgMath.h" +#include "tvgCompressor.h" +#include "tvgLottieModel.h" +#include "tvgLottieExpressions.h" + +#ifdef THORVG_LOTTIE_EXPRESSIONS_SUPPORT + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct ExpContent +{ + LottieExpression* exp; + union { + LottieObject* obj; + LottieEffect* effect; + LottieProperty* property; + void *data; + }; + float frameNo; + size_t refCnt; +}; + +static jerry_value_t _content(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt); + +//reserved expressions specifiers +static const char* EXP_NAME = "name"; +static const char* EXP_CONTENT = "content"; +static const char* EXP_WIDTH = "width"; +static const char* EXP_HEIGHT = "height"; +static const char* EXP_CYCLE = "cycle"; +static const char* EXP_PINGPONG = "pingpong"; +static const char* EXP_OFFSET = "offset"; +static const char* EXP_CONTINUE = "continue"; +static const char* EXP_TIME = "time"; +static const char* EXP_VALUE = "value"; +static const char* EXP_INDEX = "index"; +static const char* EXP_EFFECT= "effect"; + +static LottieExpressions* exps = nullptr; //singleton instance engine + + +static ExpContent* _expcontent(LottieExpression* exp, float frameNo, void* data, size_t refCnt = 1) +{ + auto ret = tvg::malloc(sizeof(ExpContent)); + ret->exp = exp; + ret->frameNo = frameNo; + ret->data = data; + ret->refCnt = refCnt; + return ret; +} + + +static inline ExpContent* _expcontent(ExpContent* data) +{ + ++data->refCnt; + return data; +} + + +static float _rand() +{ + return (float)(rand() % 10000001) * 0.0000001f; +} + + +static jerry_value_t _point2d(const Point& pt) +{ + auto obj = jerry_object(); + auto v1 = jerry_number(pt.x); + auto v2 = jerry_number(pt.y); + jerry_object_set_index(obj, 0, v1); + jerry_object_set_index(obj, 1, v2); + jerry_value_free(v1); + jerry_value_free(v2); + return obj; +} + + +static jerry_value_t _color(RGB32 rgb) +{ + auto value = jerry_object(); + auto r = jerry_number((float)rgb.r); + auto g = jerry_number((float)rgb.g); + auto b = jerry_number((float)rgb.b); + jerry_object_set_index(value, 0, r); + jerry_object_set_index(value, 1, g); + jerry_object_set_index(value, 2, b); + jerry_value_free(r); + jerry_value_free(g); + jerry_value_free(b); + return value; +} + + +static Point _point2d(jerry_value_t obj) +{ + auto v1 = jerry_object_get_index(obj, 0); + auto v2 = jerry_object_get_index(obj, 1); + Point pt = {jerry_value_as_number(v1), jerry_value_as_number(v2)}; + jerry_value_free(v1); + jerry_value_free(v2); + return pt; +} + +static RGB32 _color(jerry_value_t obj) +{ + RGB32 out; + auto r = jerry_object_get_index(obj, 0); + auto g = jerry_object_get_index(obj, 1); + auto b = jerry_object_get_index(obj, 2); + out = {jerry_value_as_int32(r), jerry_value_as_int32(g), jerry_value_as_int32(b)}; + jerry_value_free(r); + jerry_value_free(g); + jerry_value_free(b); + return out; +} + + +static void contentFree(void *native_p, struct jerry_object_native_info_t *info_p) +{ + if (--static_cast(native_p)->refCnt == 0) { + tvg::free(native_p); + } +} + +static jerry_object_native_info_t freeCb {contentFree, 0, 0}; +static uint32_t engineRefCnt = 0; //Expressions Engine reference count + + +static char* _name(jerry_value_t args) +{ + auto arg0 = jerry_value_to_string(args); + auto len = jerry_string_length(arg0); + auto name = tvg::malloc(len * sizeof(jerry_char_t) + 1); + jerry_string_to_buffer(arg0, JERRY_ENCODING_UTF8, name, len); + name[len] = '\0'; + jerry_value_free(arg0); + return (char*) name; +} + + +static unsigned long _idByName(jerry_value_t args) +{ + auto name = _name(args); + auto id = djb2Encode(name); + tvg::free(name); + return id; +} + + +static jerry_value_t _toComp(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto layer = static_cast(jerry_object_get_native_ptr(info->function, nullptr)); + return _point2d(_point2d(args[0]) * layer->cache.matrix); +} + + +static jerry_value_t _point(const Point& v) +{ + auto obj = _point2d(v); + auto value = _point2d(v); + jerry_object_set_sz(obj, EXP_VALUE, value); + jerry_value_free(value); + return obj; +} + + +static jerry_value_t _buildValue(float frameNo, LottieProperty* property) +{ + switch (property->type) { + case LottieProperty::Type::Integer: return jerry_number((*static_cast(property))(frameNo)); + case LottieProperty::Type::Float: return jerry_number((*static_cast(property))(frameNo)); + case LottieProperty::Type::Scalar: return _point((*static_cast(property))(frameNo)); + case LottieProperty::Type::Vector: return _point((*static_cast(property))(frameNo)); + case LottieProperty::Type::PathSet: + { + auto obj = jerry_object(); + jerry_object_set_native_ptr(obj, nullptr, property); + return obj; + } + case LottieProperty::Type::Color: return _color((*static_cast(property))(frameNo)); + case LottieProperty::Type::Opacity: return jerry_number((*static_cast(property))(frameNo)); + default: TVGERR("LOTTIE", "Non supported type for value? = %d", (int) property->type); + } + return jerry_undefined(); +} + + +static void _buildTransform(jerry_value_t context, float frameNo, LottieTransform* transform) +{ + if (!transform) return; + + auto obj = jerry_object(); + jerry_object_set_sz(context, "transform", obj); + + auto anchorPoint = _buildValue(frameNo, &transform->anchor); + jerry_object_set_sz(obj, "anchorPoint", anchorPoint); + jerry_value_free(anchorPoint); + + auto position = _buildValue(frameNo, &transform->position); + jerry_object_set_sz(obj, "position", position); + jerry_value_free(position); + + auto scale = _buildValue(frameNo, &transform->scale); + jerry_object_set_sz(obj, "scale", scale); + jerry_value_free(scale); + + auto rotation = _buildValue(frameNo, &transform->rotation); + jerry_object_set_sz(obj, "rotation", rotation); + jerry_value_free(rotation); + + auto opacity = _buildValue(frameNo, &transform->opacity); + jerry_object_set_sz(obj, "opacity", opacity); + jerry_value_free(opacity); + + jerry_value_free(obj); +} + + +static jerry_value_t _buildGroup(LottieGroup* group, float frameNo) +{ + auto obj = jerry_function_external(_content); + + //attach a transform + ARRAY_FOREACH(p, group->children) { + if ((*p)->type == LottieObject::Type::Transform) { + _buildTransform(obj, frameNo, static_cast(*p)); + break; + } + } + jerry_object_set_native_ptr(obj, &freeCb, _expcontent(nullptr, frameNo, group)); + jerry_object_set_sz(obj, EXP_CONTENT, obj); + return obj; +} + + +static jerry_value_t _buildPolystar(LottiePolyStar* polystar, float frameNo) +{ + auto obj = jerry_object(); + auto position = jerry_object(); + jerry_object_set_native_ptr(position, nullptr, &polystar->position); + jerry_object_set_sz(obj, "position", position); + jerry_value_free(position); + auto innerRadius = jerry_number(polystar->innerRadius(frameNo)); + jerry_object_set_sz(obj, "innerRadius", innerRadius); + jerry_value_free(innerRadius); + auto outerRadius = jerry_number(polystar->outerRadius(frameNo)); + jerry_object_set_sz(obj, "outerRadius", outerRadius); + jerry_value_free(outerRadius); + auto innerRoundness = jerry_number(polystar->innerRoundness(frameNo)); + jerry_object_set_sz(obj, "innerRoundness", innerRoundness); + jerry_value_free(innerRoundness); + auto outerRoundness = jerry_number(polystar->outerRoundness(frameNo)); + jerry_object_set_sz(obj, "outerRoundness", outerRoundness); + jerry_value_free(outerRoundness); + auto rotation = jerry_number(polystar->rotation(frameNo)); + jerry_object_set_sz(obj, "rotation", rotation); + jerry_value_free(rotation); + auto ptsCnt = jerry_number(polystar->ptsCnt(frameNo)); + jerry_object_set_sz(obj, "points", ptsCnt); + jerry_value_free(ptsCnt); + + return obj; +} + + +static jerry_value_t _buildTrimpath(LottieTrimpath* trimpath, float frameNo) +{ + jerry_value_t obj = jerry_object(); + auto start = jerry_number(trimpath->start(frameNo)); + jerry_object_set_sz(obj, "start", start); + jerry_value_free(start); + auto end = jerry_number(trimpath->end(frameNo)); + jerry_object_set_sz(obj, "end", end); + jerry_value_free(end); + auto offset = jerry_number(trimpath->offset(frameNo)); + jerry_object_set_sz(obj, EXP_OFFSET, offset); + jerry_value_free(offset); + + return obj; +} + + +static jerry_value_t _effectProperty(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto name = _name(args[0]); + auto property = static_cast(data->effect)->property(name); + tvg::free(name); + + if (!property) return jerry_undefined(); + + return _buildValue(data->frameNo, property); +} + + +static jerry_value_t _effect(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto layer = static_cast(data->obj); + LottieEffect* effect = nullptr; + + //either name or index + if (jerry_value_is_string(args[0])) { + auto name = _name(args[0]); + effect = layer->effectById(djb2Encode(name)); + tvg::free(name); + } else { + effect = layer->effectByIdx((int16_t)jerry_value_as_int32(args[0])); + } + + if (!effect) return jerry_undefined(); + + //find a effect property + auto obj = jerry_function_external(_effectProperty); + jerry_object_set_native_ptr(obj, &freeCb, _expcontent(data->exp, data->frameNo, effect)); + return obj; +} + + +static void _buildLayer(jerry_value_t context, float frameNo, LottieLayer* layer, LottieLayer* comp, LottieExpression* exp) +{ + auto width = jerry_number(layer->w); + jerry_object_set_sz(context, EXP_WIDTH, width); + jerry_value_free(width); + + auto height = jerry_number(layer->h); + jerry_object_set_sz(context, EXP_HEIGHT, height); + jerry_value_free(height); + + auto index = jerry_number(layer->ix); + jerry_object_set_sz(context, EXP_INDEX, index); + jerry_value_free(index); + + auto parent = jerry_object(); + jerry_object_set_native_ptr(parent, nullptr, layer->parent); + jerry_object_set_sz(context, "parent", parent); + jerry_value_free(parent); + + auto hasParent = jerry_boolean(layer->parent ? true : false); + jerry_object_set_sz(context, "hasParent", hasParent); + jerry_value_free(hasParent); + + auto inPoint = jerry_number(layer->inFrame); + jerry_object_set_sz(context, "inPoint", inPoint); + jerry_value_free(inPoint); + + auto outPoint = jerry_number(layer->outFrame); + jerry_object_set_sz(context, "outPoint", outPoint); + jerry_value_free(outPoint); + + //TODO: Confirm exp->layer->comp->timeAtFrame() ? + auto startTime = jerry_number(exp->comp->timeAtFrame(layer->startFrame)); + jerry_object_set_sz(context, "startTime", startTime); + jerry_value_free(startTime); + + auto hasVideo = jerry_boolean(false); + jerry_object_set_sz(context, "hasVideo", hasVideo); + jerry_value_free(hasVideo); + + auto hasAudio = jerry_boolean(false); + jerry_object_set_sz(context, "hasAudio", hasAudio); + jerry_value_free(hasAudio); + + //active, #current in the animation range? + + auto enabled = jerry_boolean(!layer->hidden); + jerry_object_set_sz(context, "enabled", enabled); + jerry_value_free(enabled); + + auto audioActive = jerry_boolean(false); + jerry_object_set_sz(context, "audioActive", audioActive); + jerry_value_free(audioActive); + + //sampleImage(point, radius = [.5, .5], postEffect=true, t=time) + + _buildTransform(context, frameNo, layer->transform); + + //audioLevels, #the value of the Audio Levels property of the layer in decibels + + auto timeRemap = jerry_object(); + jerry_object_set_native_ptr(timeRemap, nullptr, &layer->timeRemap); + jerry_object_set_sz(context, "timeRemap", timeRemap); + jerry_value_free(timeRemap); + + //marker.key(index) + //marker.key(name) + //marker.nearestKey(t) + //marker.numKeys + + //FIXME: This name conflicts with the function object in _layer(). No idea. Maybe jerryscript issue. +#if 0 + if (layer->name) { + auto name = jerry_string_sz(layer->name); + jerry_object_set_sz(context, EXP_NAME, name); + jerry_value_free(name); + } +#endif + + auto toComp = jerry_function_external(_toComp); + jerry_object_set_sz(context, "toComp", toComp); + jerry_object_set_native_ptr(toComp, nullptr, layer); + jerry_value_free(toComp); + + //content("name"), #look for the named property from a layer + auto data = _expcontent(exp, frameNo, layer, 2); + + auto content = jerry_function_external(_content); + jerry_object_set_sz(context, EXP_CONTENT, content); + jerry_object_set_native_ptr(content, &freeCb, data); + jerry_value_free(content); + + auto effect = jerry_function_external(_effect); + jerry_object_set_sz(context, EXP_EFFECT, effect); + jerry_object_set_native_ptr(effect, &freeCb, data); + jerry_value_free(effect); +} + + +static jerry_value_t _addsub(const jerry_value_t args[], float addsub) +{ + //string + string + if (jerry_value_is_string(args[0]) || jerry_value_is_string(args[1])) { + auto a = _name(args[0]); + auto b = _name(args[1]); + auto ret = tvg::concat(a, b); + auto val = jerry_string_sz(ret); + tvg::free(ret); + tvg::free(a); + tvg::free(b); + return val; + } + + //number + number + auto n1 = jerry_value_is_number(args[0]); + auto n2 = jerry_value_is_number(args[1]); + + //1d + 1d + if (n1 && n2) return jerry_number(jerry_value_as_number(args[0]) + addsub * jerry_value_as_number(args[1])); + + auto pt = _point2d(args[n1 ? 1 : 0]); + + //2d + 1d + if (n1 || n2) { + auto secondary = n1 ? 0 : 1; + auto val3 = jerry_value_as_number(args[secondary]); + if (secondary == 0) pt.x = (pt.x * addsub) + val3; + else pt.x += (addsub * val3); + //2d + 2d + } else { + pt += _point2d(args[1]) * addsub; + } + + return _point2d(pt); +} + + +static jerry_value_t _muldiv(const jerry_value_t arg1, float arg2) +{ + //1d + if (jerry_value_is_number(arg1)) return jerry_number(jerry_value_as_number(arg1) * arg2); + + //2d + return _point2d(_point2d(arg1) * arg2); +} + + +static jerry_value_t _add(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return _addsub(args, 1.0f); +} + + +static jerry_value_t _sub(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return _addsub(args, -1.0f); +} + + +static jerry_value_t _mul(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return _muldiv(args[0], jerry_value_as_number(args[1])); +} + + +static jerry_value_t _div(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return _muldiv(args[0], 1.0f / jerry_value_as_number(args[1])); +} + + +static jerry_value_t _interp(float t, const jerry_value_t args[], int argsCnt) +{ + auto tMin = 0.0f; + auto tMax = 1.0f; + int idx = 0; + + tMin = jerry_value_as_number(args[1]); + tMax = jerry_value_as_number(args[2]); + idx += 2; + + t = (t - tMin) / (tMax - tMin); + if (t < 0) t = 0.0f; + else if (t > 1) t = 1.0f; + + //2d + if (jerry_value_is_object(args[idx + 1]) && jerry_value_is_object(args[idx + 2])) { + return _point2d(tvg::lerp(_point2d(args[idx + 1]), _point2d(args[idx + 2]), t)); + } + + //1d + return jerry_number(tvg::lerp(jerry_value_as_number(args[idx + 1]), jerry_value_as_number(args[idx + 2]), t)); +} + + +static jerry_value_t _linear(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto t = jerry_value_as_number(args[0]); + return _interp(t, args, jerry_value_as_uint32(argsCnt)); +} + + +static jerry_value_t _ease(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto t = jerry_value_as_number(args[0]); + t = (t < 0.5f) ? (4 * t * t * t) : (1.0f - powf(-2.0f * t + 2.0f, 3) * 0.5f); + return _interp(t, args, jerry_value_as_uint32(argsCnt)); +} + + + +static jerry_value_t _easeIn(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto t = jerry_value_as_number(args[0]); + t = t * t * t; + return _interp(t, args, jerry_value_as_uint32(argsCnt)); +} + + +static jerry_value_t _easeOut(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto t = jerry_value_as_number(args[0]); + t = 1.0f - powf(1.0f - t, 3); + return _interp(t, args, jerry_value_as_uint32(argsCnt)); +} + + +static jerry_value_t _clamp(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto num = jerry_value_as_number(args[0]); + auto limit1 = jerry_value_as_number(args[1]); + auto limit2 = jerry_value_as_number(args[2]); + + //clamping + if (num < limit1) num = limit1; + if (num > limit2) num = limit2; + + return jerry_number(num); +} + + +static jerry_value_t _dot(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return jerry_number(tvg::dot(_point2d(args[0]), _point2d(args[1]))); +} + + +static jerry_value_t _cross(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return jerry_number(tvg::cross(_point2d(args[0]), _point2d(args[1]))); +} + + +static jerry_value_t _normalize(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto pt = _point2d(args[0]); + return _point2d(pt / tvg::length(pt)); +} + + +static jerry_value_t _length(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return jerry_number(tvg::length(_point2d(args[0]))); +} + + +static jerry_value_t _random(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return jerry_number(_rand()); +} + + +static jerry_value_t _deg2rad(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return jerry_number(deg2rad(jerry_value_as_number(args[0]))); +} + + +static jerry_value_t _rad2deg(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + return jerry_number(rad2deg(jerry_value_as_number(args[0]))); +} + + +static jerry_value_t _content(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto group = static_cast(data->obj); + auto target = group->content(_idByName(args[0])); + if (!target) return jerry_undefined(); + + //find the a path property(sh) in the group layer? + switch (target->type) { + case LottieObject::Group: return _buildGroup(static_cast(target), data->frameNo); + case LottieObject::Path: { + auto obj = jerry_object(); + jerry_object_set_native_ptr(obj, nullptr, &static_cast(target)->pathset); + jerry_object_set_sz(obj, "path", obj); + return obj; + } + case LottieObject::Polystar: return _buildPolystar(static_cast(target), data->frameNo); + case LottieObject::Trimpath: return _buildTrimpath(static_cast(target), data->frameNo); + default: break; + } + return jerry_undefined(); +} + + +static jerry_value_t _points(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + /* TODO: ThorVG prebuilds the path data for performance. + It actually need to constructs the Array for points, inTangents, outTangents and then return here... */ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + + auto obj = jerry_object(); + jerry_object_set_native_ptr(obj, nullptr, data->property); + return obj; +} + + +static jerry_value_t _pointOnPath(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto pathset = static_cast(data->property); + auto progress = jerry_value_as_number(args[0]); + RenderPath out; + (*pathset)(data->frameNo, out, nullptr, nullptr); + return _point2d(out.point(progress)); +} + + +static void _buildPath(jerry_value_t context, float frameNo, LottieProperty* pathset) +{ + auto data = _expcontent(nullptr, frameNo, pathset, 2); + + //Trick for fast building path. + auto points = jerry_function_external(_points); + jerry_object_set_native_ptr(points, &freeCb, data); + jerry_object_set_sz(context, "points", points); + jerry_value_free(points); + + auto pointOnPath = jerry_function_external(_pointOnPath); + jerry_object_set_native_ptr(pointOnPath, &freeCb, data); + jerry_object_set_sz(context, "pointOnPath", pointOnPath); + jerry_value_free(pointOnPath); + + //inTangents + //outTangents + //isClosed +} + + +static jerry_value_t _layerChild(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + jerry_value_t obj = jerry_undefined(); + + //find a member by index + if (jerry_value_is_number(args[0])) { + auto idx = (uint32_t)jerry_value_as_int32(args[0]) - 1; + auto children = static_cast*>(data->data); + if (idx < children->count) { + obj = jerry_function_external(_layerChild); + jerry_object_set_native_ptr(obj, &freeCb, _expcontent(data->exp, data->frameNo, (*children)[idx])); + } + //find a member by name + } else { + auto name = _name(args[0]); + if (name) { + //for backward compatibility: reserved ADOBE keyword + if (!strcmp(name, "ADBE Root Vectors Group") || !strcmp(name, "ADBE Vectors Group")) { + auto group = static_cast(data->obj); + if (group->type == LottieObject::Type::Group || group->type == LottieObject::Type::Layer) { + obj = jerry_function_external(_layerChild); + jerry_object_set_native_ptr(obj, &freeCb, _expcontent(data->exp, data->frameNo, &group->children)); + } + } else if (!strcmp(name, "ADBE Vector Shape")) { + obj = jerry_object(); + _buildPath(obj, data->frameNo, &static_cast(data->obj)->pathset); + } + tvg::free(name); + } + } + return obj; +} + + +static jerry_value_t _layer(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto comp = static_cast(data->obj); + + //either index or name + auto layer = jerry_value_is_number(args[0]) ? comp->layerByIdx((uint16_t)jerry_value_as_int32(args[0])) : comp->layerById(_idByName(args[0])); + if (!layer) return jerry_undefined(); + + auto obj = jerry_function_external(_layerChild); + jerry_object_set_native_ptr(obj, &freeCb, _expcontent(data->exp, data->frameNo, layer)); + _buildLayer(obj, data->frameNo, layer, comp, data->exp); + + return obj; +} + + +static jerry_value_t _nearestKey(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto exp = static_cast(jerry_object_get_native_ptr(info->function, nullptr)); + auto time = jerry_value_as_number(args[0]); + auto frameNo = exp->comp->frameAtTime(time); + auto index = jerry_number((float)exp->property->nearest(frameNo)); + + auto obj = jerry_object(); + jerry_object_set_sz(obj, EXP_INDEX, index); + jerry_value_free(index); + + return obj; +} + + +static jerry_value_t _property(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto property = data->obj->property(jerry_value_as_int32(args[0])); + if (!property) return jerry_undefined(); + return _buildValue(data->frameNo, property); +} + + +static jerry_value_t _propertyGroup(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto level = jerry_value_as_int32(args[0]); + + //intermediate group + if (level == 1) { + auto group = jerry_function_external(_property); + jerry_object_set_native_ptr(group, &freeCb, _expcontent(data)); + return group; + } + + TVGLOG("LOTTIE", "propertyGroup(%d)?", level); + + return jerry_undefined(); +} + + +static jerry_value_t _valueAtTime(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto exp = static_cast(jerry_object_get_native_ptr(info->function, nullptr)); + auto time = jerry_value_as_number(args[0]); + auto frameNo = exp->comp->frameAtTime(time); + return _buildValue(frameNo, exp->property); +} + + +static jerry_value_t _velocity(Point& prv, Point& cur, float elapsed) +{ + return _point2d({(cur.x - prv.x) / elapsed, (cur.y - prv.y) / elapsed}); +} + + +static jerry_value_t _velocityAtTime(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto exp = static_cast(jerry_object_get_native_ptr(info->function, nullptr)); + auto key = exp->property->nearest(exp->comp->frameAtTime(jerry_value_as_number(args[0]))); + auto pframe = exp->property->frameNo(key - 1); + auto cframe = exp->property->frameNo(key); + auto elapsed = (cframe - pframe) / (exp->comp->frameRate); + + //compute the velocity + switch (exp->property->type) { + case LottieProperty::Type::Float: { + auto prv = (*static_cast(exp->property))(pframe); + auto cur = (*static_cast(exp->property))(cframe); + return jerry_number((cur - prv) / elapsed); + } + case LottieProperty::Type::Scalar: { + auto prv = (*static_cast(exp->property))(pframe); + auto cur = (*static_cast(exp->property))(cframe); + return _velocity(prv, cur, elapsed); + } + case LottieProperty::Type::Vector: { + auto prv = (*static_cast(exp->property))(pframe); + auto cur = (*static_cast(exp->property))(cframe); + return _velocity(prv, cur, elapsed); + } + default: TVGLOG("LOTTIE", "Non supported type for velocityAtTime?"); + } + return jerry_undefined(); +} + + +static jerry_value_t _speedAtTime(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto exp = static_cast(jerry_object_get_native_ptr(info->function, nullptr)); + auto key = exp->property->nearest(exp->comp->frameAtTime(jerry_value_as_number(args[0]))); + auto pframe = exp->property->frameNo(key - 1); + auto cframe = exp->property->frameNo(key); + + Point cur, prv; + + //compute the velocity + switch (exp->property->type) { + case LottieProperty::Type::Scalar: { + prv = (*static_cast(exp->property))(pframe); + cur = (*static_cast(exp->property))(cframe); + break; + } + case LottieProperty::Type::Vector: { + prv = (*static_cast(exp->property))(pframe); + cur = (*static_cast(exp->property))(cframe); + break; + } + default: { + TVGLOG("LOTTIE", "Non supported type for speedAtTime?"); + return jerry_undefined(); + } + } + + auto elapsed = (cframe - pframe) / (exp->comp->frameRate); + auto speed = sqrtf(pow(cur.x - prv.x, 2) + pow(cur.y - prv.y, 2)) / elapsed; + return jerry_number(speed); +} + + + +static jerry_value_t _wiggle(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto freq = jerry_value_as_number(args[0]); + auto amp = jerry_value_as_number(args[1]); + auto octaves = (argsCnt > 2) ? jerry_value_as_int32(args[2]) : 1; + auto ampm = (argsCnt > 3) ? jerry_value_as_number(args[3]) : 0.5f; + auto time = (argsCnt > 4) ? jerry_value_as_number(args[4]) : data->exp->comp->timeAtFrame(data->frameNo); + + Point result = {0.0f, 0.0f}; + auto property = data->exp->property; + + if (property->type == LottieProperty::Type::Vector) { + result = (*static_cast(property))(data->frameNo); + } else if (property->type == LottieProperty::Type::Scalar) { + result = (*static_cast(property))(data->frameNo); + } + + for (int o = 0; o < octaves; ++o) { + auto repeat = (int)ceil(time * freq); + for (int i = 0; i < repeat; ++i) { + result.x += (_rand() * 2.0f - 1.0f) * amp; + result.y += (_rand() * 2.0f - 1.0f) * amp; + } + freq *= 2.0f; + amp *= ampm; + } + return _point2d(result); +} + + +static jerry_value_t _temporalWiggle(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto freq = jerry_value_as_number(args[0]); + auto amp = jerry_value_as_number(args[1]); + auto octaves = (argsCnt > 2) ? jerry_value_as_int32(args[2]) : 1; + auto ampm = (argsCnt > 3) ? jerry_value_as_number(args[3]) : 5.0f; + auto time = (argsCnt > 4) ? jerry_value_as_number(args[4]) : data->exp->comp->timeAtFrame(data->frameNo); + auto wiggleTime = time; + + for (int o = 0; o < octaves; ++o) { + auto repeat = int(time * freq); + auto frac = (time * freq - float(repeat)); + for (int i = 0; i < repeat; ++i) { + wiggleTime += (_rand() * 2.0f - 1.0f) * amp * frac; + } + freq *= 2.0f; + amp *= ampm; + } + + return _buildValue(data->exp->comp->frameAtTime(wiggleTime), data->exp->property); +} + + +static LottieProperty::Loop _loopCommon(const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto mode = LottieProperty::Loop::InCycle; + + if (argsCnt > 0) { + auto name = _name(args[0]); + if (!strcmp(name, EXP_CYCLE)) mode = LottieProperty::Loop::InCycle; + else if (!strcmp(name, EXP_PINGPONG)) mode = LottieProperty::Loop::InPingPong; + else if (!strcmp(name, EXP_OFFSET)) mode = LottieProperty::Loop::InOffset; + else if (!strcmp(name, EXP_CONTINUE)) mode = LottieProperty::Loop::InContinue; + tvg::free(name); + } + + if (mode != LottieProperty::Loop::InCycle && mode != LottieProperty::Loop::InPingPong) { + TVGLOG("LOTTIE", "Not supported loopIn type = %d", (int) mode); + } + return mode; +} + + +#define LOOP_OUT_OFFSET 4 + +static jerry_value_t _loopOut(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto mode = static_cast((int) _loopCommon(args, argsCnt) + LOOP_OUT_OFFSET); + auto key = (argsCnt > 1) ? jerry_value_as_int32(args[1]) : 0; + return _buildValue(data->exp->property->loop(data->frameNo, key, mode, data->exp->layer->outFrame), data->exp->property); +} + + +static jerry_value_t _loopOutDuration(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto mode = static_cast((int) _loopCommon(args, argsCnt) + LOOP_OUT_OFFSET); + auto out = (argsCnt > 1) ? data->exp->comp->frameAtTime(jerry_value_as_number(args[1])) : FLT_MAX; + return _buildValue(data->exp->property->loop(data->frameNo, 0, mode, out), data->exp->property); +} + + +static jerry_value_t _loopIn(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto mode = _loopCommon(args, argsCnt); + auto key = (argsCnt > 1) ? jerry_value_as_int32(args[1]) : 0; + return _buildValue(data->exp->property->loop(data->frameNo, key, mode, data->exp->layer->outFrame), data->exp->property); +} + + +static jerry_value_t _loopInDuration(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto mode = _loopCommon(args, argsCnt); + auto in = (argsCnt > 1) ? data->exp->comp->frameAtTime(jerry_value_as_number(args[1])) : FLT_MAX; + return _buildValue(data->exp->property->loop(data->frameNo, 0, mode, in), data->exp->property); +} + + +static jerry_value_t _key(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto exp = static_cast(jerry_object_get_native_ptr(info->function, nullptr)); + auto frameNo = exp->property->frameNo(jerry_value_as_int32(args[0])); + auto time = jerry_number(exp->comp->timeAtFrame(frameNo)); + auto value = _buildValue(frameNo, exp->property); + + auto obj = jerry_object(); + jerry_object_set_sz(obj, EXP_TIME, time); + jerry_object_set_sz(obj, EXP_INDEX, args[0]); + jerry_object_set_sz(obj, EXP_VALUE, value); + + //direct access, key[0], key[1] + if (exp->property->type == LottieProperty::Type::Float) { + jerry_object_set_index(obj, 0, value); + } else if (exp->property->type == LottieProperty::Type::Scalar || exp->property->type == LottieProperty::Type::Vector) { + jerry_object_set_index(obj, 0, jerry_object_get_index(value, 0)); + jerry_object_set_index(obj, 1, jerry_object_get_index(value, 1)); + } + + jerry_value_free(time); + jerry_value_free(value); + + return obj; +} + + +static void _buildProperty(float frameNo, jerry_value_t context, LottieExpression* exp) +{ + auto value = _buildValue(frameNo, exp->property); + jerry_object_set_sz(context, EXP_VALUE, value); + jerry_value_free(value); + + auto valueAtTime = jerry_function_external(_valueAtTime); + jerry_object_set_sz(context, "valueAtTime", valueAtTime); + jerry_object_set_native_ptr(valueAtTime, nullptr, exp); + jerry_value_free(valueAtTime); + + auto velocity = jerry_number(0.0f); + jerry_object_set_sz(context, "velocity", velocity); + jerry_value_free(velocity); + + auto velocityAtTime = jerry_function_external(_velocityAtTime); + jerry_object_set_sz(context, "velocityAtTime", velocityAtTime); + jerry_object_set_native_ptr(velocityAtTime, nullptr, exp); + jerry_value_free(velocityAtTime); + + auto speed = jerry_number(0.0f); + jerry_object_set_sz(context, "speed", speed); + jerry_value_free(speed); + + auto speedAtTime = jerry_function_external(_speedAtTime); + jerry_object_set_sz(context, "speedAtTime", speedAtTime); + jerry_object_set_native_ptr(speedAtTime, nullptr, exp); + jerry_value_free(speedAtTime); + + auto propertyIndex = jerry_number(exp->property->ix); + jerry_object_set_sz(context, "propertyIndex", propertyIndex); + jerry_value_free(propertyIndex); + + { + auto data = _expcontent(exp, frameNo, exp->object, 7); + + auto wiggle = jerry_function_external(_wiggle); + jerry_object_set_sz(context, "wiggle", wiggle); + jerry_object_set_native_ptr(wiggle, &freeCb, data); + jerry_value_free(wiggle); + + auto temporalWiggle = jerry_function_external(_temporalWiggle); + jerry_object_set_sz(context, "temporalWiggle", temporalWiggle); + jerry_object_set_native_ptr(temporalWiggle, &freeCb, data); + jerry_value_free(temporalWiggle); + + auto propertyGroup = jerry_function_external(_propertyGroup); + jerry_object_set_native_ptr(propertyGroup, &freeCb, data); + jerry_object_set_sz(context, "propertyGroup", propertyGroup); + jerry_value_free(propertyGroup); + + auto loopIn = jerry_function_external(_loopIn); + jerry_object_set_sz(context, "loopIn", loopIn); + jerry_object_set_native_ptr(loopIn, &freeCb, data); + jerry_value_free(loopIn); + + auto loopOut = jerry_function_external(_loopOut); + jerry_object_set_sz(context, "loopOut", loopOut); + jerry_object_set_native_ptr(loopOut, &freeCb, data); + jerry_value_free(loopOut); + + auto loopInDuration = jerry_function_external(_loopInDuration); + jerry_object_set_sz(context, "loopInDuration", loopInDuration); + jerry_object_set_native_ptr(loopInDuration, &freeCb, data); + jerry_value_free(loopInDuration); + + auto loopOutDuration = jerry_function_external(_loopOutDuration); + jerry_object_set_sz(context, "loopOutDuration", loopOutDuration); + jerry_object_set_native_ptr(loopOutDuration, &freeCb, data); + jerry_value_free(loopOutDuration); + + } + + //smooth(width=.2, samples=5, t=time) + + auto key = jerry_function_external(_key); + jerry_object_set_sz(context, "key", key); + jerry_object_set_native_ptr(key, nullptr, exp); + jerry_value_free(key); + + //key(markerName) + + auto nearestKey = jerry_function_external(_nearestKey); + jerry_object_set_native_ptr(nearestKey, nullptr, exp); + jerry_object_set_sz(context, "nearestKey", nearestKey); + jerry_value_free(nearestKey); + + auto numKeys = jerry_number((float)exp->property->frameCnt()); + jerry_object_set_sz(context, "numKeys", numKeys); + jerry_value_free(numKeys); + + //name + + { + auto data = _expcontent(exp, frameNo, exp->layer, 2); + + //content("name"), #look for the named property from a layer + auto content = jerry_function_external(_content); + jerry_object_set_sz(context, EXP_CONTENT, content); + jerry_object_set_native_ptr(content, &freeCb, data); + jerry_value_free(content); + + auto effect = jerry_function_external(_effect); + jerry_object_set_sz(context, EXP_EFFECT, effect); + jerry_object_set_native_ptr(effect, &freeCb, data); + jerry_value_free(effect); + } + + auto effect = jerry_function_external(_effect); + jerry_object_set_sz(context, EXP_EFFECT, effect); + jerry_object_set_native_ptr(effect, &freeCb, _expcontent(exp, frameNo, exp->layer)); + jerry_value_free(effect); + + //expansions per types + if (exp->property->type == LottieProperty::Type::PathSet) _buildPath(context, frameNo, exp->property); +} + + +static jerry_value_t _comp(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) +{ + auto data = static_cast(jerry_object_get_native_ptr(info->function, &freeCb)); + auto comp = static_cast(data->obj); + auto layer = comp->layerById(_idByName(args[0])); + + if (!layer) return jerry_undefined(); + + auto obj = jerry_object(); + jerry_object_set_native_ptr(obj, nullptr, layer); + _buildLayer(obj, data->frameNo, layer, comp, data->exp); + + return obj; +} + + +static void _buildMath(jerry_value_t context) +{ + auto bm_mul = jerry_function_external(_mul); + jerry_object_set_sz(context, "$bm_mul", bm_mul); + jerry_value_free(bm_mul); + + auto bm_sum = jerry_function_external(_add); + jerry_object_set_sz(context, "$bm_sum", bm_sum); + jerry_value_free(bm_sum); + + auto bm_add = jerry_function_external(_add); + jerry_object_set_sz(context, "$bm_add", bm_add); + jerry_value_free(bm_add); + + auto bm_sub = jerry_function_external(_sub); + jerry_object_set_sz(context, "$bm_sub", bm_sub); + jerry_value_free(bm_sub); + + auto bm_div = jerry_function_external(_div); + jerry_object_set_sz(context, "$bm_div", bm_div); + jerry_value_free(bm_div); + + auto mul = jerry_function_external(_mul); + jerry_object_set_sz(context, "mul", mul); + jerry_value_free(mul); + + auto sum = jerry_function_external(_add); + jerry_object_set_sz(context, "sum", sum); + jerry_value_free(sum); + + auto add = jerry_function_external(_add); + jerry_object_set_sz(context, "add", add); + jerry_value_free(add); + + auto sub = jerry_function_external(_sub); + jerry_object_set_sz(context, "sub", sub); + jerry_value_free(sub); + + auto div = jerry_function_external(_div); + jerry_object_set_sz(context, "div", div); + jerry_value_free(div); + + auto clamp = jerry_function_external(_clamp); + jerry_object_set_sz(context, "clamp", clamp); + jerry_value_free(clamp); + + auto dot = jerry_function_external(_dot); + jerry_object_set_sz(context, "dot", dot); + jerry_value_free(dot); + + auto cross = jerry_function_external(_cross); + jerry_object_set_sz(context, "cross", cross); + jerry_value_free(cross); + + auto normalize = jerry_function_external(_normalize); + jerry_object_set_sz(context, "normalize", normalize); + jerry_value_free(normalize); + + auto length = jerry_function_external(_length); + jerry_object_set_sz(context, "length", length); + jerry_value_free(length); + + auto random = jerry_function_external(_random); + jerry_object_set_sz(context, "random", random); + jerry_value_free(random); + + auto deg2rad = jerry_function_external(_deg2rad); + jerry_object_set_sz(context, "degreesToRadians", deg2rad); + jerry_value_free(deg2rad); + + auto rad2deg = jerry_function_external(_rad2deg); + jerry_object_set_sz(context, "radiansToDegrees", rad2deg); + jerry_value_free(rad2deg); + + auto linear = jerry_function_external(_linear); + jerry_object_set_sz(context, "linear", linear); + jerry_value_free(linear); + + auto ease = jerry_function_external(_ease); + jerry_object_set_sz(context, "ease", ease); + jerry_value_free(ease); + + auto easeIn = jerry_function_external(_easeIn); + jerry_object_set_sz(context, "easeIn", easeIn); + jerry_value_free(easeIn); + + auto easeOut = jerry_function_external(_easeOut); + jerry_object_set_sz(context, "easeOut", easeOut); + jerry_value_free(easeOut); + + //lookAt +} + + +void LottieExpressions::buildGlobal(float frameNo, LottieExpression* exp) +{ + tvg::free(static_cast(jerry_object_get_native_ptr(comp, &freeCb))); + jerry_object_set_native_ptr(comp, &freeCb, _expcontent(exp, frameNo, exp->layer)); + + auto index = jerry_number(exp->layer->ix); + jerry_object_set_sz(global, EXP_INDEX, index); + jerry_value_free(index); +} + + +void LottieExpressions::buildComp(jerry_value_t context, float frameNo, LottieLayer* comp, LottieExpression* exp) +{ + //layer(index) / layer(name) / layer(otherLayer, reIndex) + auto layer = jerry_function_external(_layer); + jerry_object_set_sz(context, "layer", layer); + + jerry_object_set_native_ptr(layer, &freeCb, _expcontent(exp, frameNo, comp)); + jerry_value_free(layer); + + auto numLayers = jerry_number((float)comp->children.count); + jerry_object_set_sz(context, "numLayers", numLayers); + jerry_value_free(numLayers); +} + + +void LottieExpressions::buildComp(LottieComposition* comp, float frameNo, LottieExpression* exp) +{ + buildComp(this->comp, frameNo, comp->root, exp); + + //marker + //marker.key(index) + //marker.key(name) + //marker.nearestKey(t) + //marker.numKeys + + //activeCamera + + auto width = jerry_number(comp->w); + jerry_object_set_sz(thisComp, EXP_WIDTH, width); + jerry_value_free(width); + + auto height = jerry_number(comp->h); + jerry_object_set_sz(thisComp, EXP_HEIGHT, height); + jerry_value_free(height); + + auto duration = jerry_number(comp->duration()); + jerry_object_set_sz(thisComp, "duration", duration); + jerry_value_free(duration); + + //ntscDropFrame + //displayStartTime + + auto frameDuration = jerry_number(1.0f / comp->frameRate); + jerry_object_set_sz(thisComp, "frameDuration", frameDuration); + jerry_value_free(frameDuration); + + //shutterAngle + //shutterPhase + //bgColor + //pixelAspect + + if (comp->name) { + auto name = jerry_string_sz(comp->name); + jerry_object_set_sz(thisComp, EXP_NAME, name); + jerry_value_free(name); + } +} + + +jerry_value_t LottieExpressions::buildGlobal() +{ + global = jerry_current_realm(); + + //comp(name) + comp = jerry_function_external(_comp); + jerry_object_set_sz(global, "comp", comp); + + //footage(name) + + thisComp = jerry_object(); + jerry_object_set_sz(global, "thisComp", thisComp); + + thisLayer = jerry_object(); + jerry_object_set_sz(global, "thisLayer", thisLayer); + + thisProperty = jerry_object(); + jerry_object_set_sz(global, "thisProperty", thisProperty); + + //fromCompToSurface + //createPath + //posterizeTime(framesPerSecond) + //value + + return global; +} + + +void LottieExpressions::buildWritables(LottieExpression* exp) +{ + if (exp->writables.empty()) return; + ARRAY_FOREACH(p, exp->writables) { + auto writable = jerry_number(p->val); + jerry_object_set_sz(global, p->var, writable); + jerry_value_free(writable); + } +} + + +jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp) +{ + if (exp->disabled && exp->writables.empty()) return jerry_undefined(); + + buildGlobal(frameNo, exp); + + //main composition + buildComp(exp->comp, frameNo, exp); + + //this composition + buildComp(thisComp, frameNo, exp->layer->comp, exp); + + //update global context values + _buildProperty(frameNo, global, exp); + + //this layer + jerry_object_set_native_ptr(thisLayer, nullptr, exp->layer); + _buildLayer(thisLayer, frameNo, exp->layer, exp->comp->root, exp); + + //this property + jerry_object_set_native_ptr(thisProperty, nullptr, exp->property); + _buildProperty(frameNo, thisProperty, exp); + + //expansions per object type + if (exp->object->type == LottieObject::Transform) _buildTransform(global, frameNo, static_cast(exp->object)); + + //update writable values + buildWritables(exp); + + //evaluate the code + auto eval = jerry_eval((jerry_char_t *) exp->code, strlen(exp->code), JERRY_PARSE_NO_OPTS); + + if (jerry_value_is_exception(eval)) { + TVGERR("LOTTIE", "Failed to dispatch the expressions!"); + exp->disabled = true; + return jerry_undefined(); + } + + jerry_value_free(eval); + + return jerry_object_get_sz(global, "$bm_rt"); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +LottieExpressions::~LottieExpressions() +{ + jerry_value_free(thisProperty); + jerry_value_free(thisLayer); + jerry_value_free(thisComp); + jerry_value_free(comp); + jerry_value_free(global); + jerry_cleanup(); +} + + +LottieExpressions::LottieExpressions() +{ + jerry_init(JERRY_INIT_EMPTY); + _buildMath(buildGlobal()); +} + + +void LottieExpressions::update(float curTime) +{ + //time, #current time in seconds + auto time = jerry_number(curTime); + jerry_object_set_sz(global, EXP_TIME, time); + jerry_value_free(time); +} + + +//FIXME: Threads support +#include "tvgTaskScheduler.h" + +LottieExpressions* LottieExpressions::instance() +{ + //FIXME: Threads support + if (TaskScheduler::threads() > 0) { + TVGLOG("LOTTIE", "Lottie Expressions are not supported with tvg threads"); + return nullptr; + } + + if (!exps) exps = new LottieExpressions; + ++engineRefCnt; + return exps; +} + + +void LottieExpressions::retrieve(LottieExpressions* instance) +{ + if (--engineRefCnt == 0) { + delete(instance); + exps = nullptr; + } +} + + +Point LottieExpressions::toPoint2d(jerry_value_t obj) +{ + return _point2d(obj); +} + + +RGB32 LottieExpressions::toColor(jerry_value_t obj) +{ + return _color(obj); +} + + +#endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieExpressions.h b/components/thorvg-main/src/loaders/lottie/tvgLottieExpressions.h new file mode 100644 index 0000000..9b64dbb --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieExpressions.h @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_EXPRESSIONS_H_ +#define _TVG_LOTTIE_EXPRESSIONS_H_ + +#include "tvgCommon.h" +#include "tvgLottieData.h" + +struct LottieExpression; +struct LottieComposition; +struct LottieLayer; +struct LottieModifier; + +#ifdef THORVG_LOTTIE_EXPRESSIONS_SUPPORT + +#include "jerryscript.h" + + +struct LottieExpressions +{ + template + bool result(float frameNo, NumType& out, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (jerry_value_is_number(bm_rt)) { + out = (NumType) jerry_value_as_number(bm_rt); + } else if (auto prop = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { + out = (*prop)(frameNo); + } + jerry_value_free(bm_rt); + return true; + } + + template + bool result(float frameNo, Point& out, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (auto prop = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { + out = (*prop)(frameNo); + } else { + out = toPoint2d(bm_rt); + } + jerry_value_free(bm_rt); + return true; + } + + template + bool result(float frameNo, RGB32& out, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (auto color = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { + out = (*color)(frameNo); + } else { + out = toColor(bm_rt); + } + jerry_value_free(bm_rt); + return true; + } + + template + bool result(float frameNo, Fill* fill, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (auto colorStop = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { + (*colorStop)(frameNo, fill, this); + } + jerry_value_free(bm_rt); + return true; + } + + template + bool result(float frameNo, RenderPath& out, Matrix* transform, LottieModifier* modifier, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (auto pathset = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { + (*pathset)(frameNo, out, transform, nullptr, modifier); + } + jerry_value_free(bm_rt); + return true; + } + + bool result(float frameNo, TextDocument& doc, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (jerry_value_is_string(bm_rt)) { + auto len = jerry_string_length(bm_rt); + doc.text = tvg::realloc(doc.text, (len + 1) * sizeof(jerry_char_t)); + jerry_string_to_buffer(bm_rt, JERRY_ENCODING_UTF8, (jerry_char_t*)doc.text, len); + doc.text[len] = '\0'; + } + jerry_value_free(bm_rt); + return true; + } + + void update(float curTime); + + //singleton (no thread safety) + static LottieExpressions* instance(); + static void retrieve(LottieExpressions* instance); + +private: + LottieExpressions(); + ~LottieExpressions(); + + jerry_value_t evaluate(float frameNo, LottieExpression* exp); + jerry_value_t buildGlobal(); + + void buildComp(LottieComposition* comp, float frameNo, LottieExpression* exp); + void buildComp(jerry_value_t context, float frameNo, LottieLayer* comp, LottieExpression* exp); + void buildGlobal(float frameNo, LottieExpression* exp); + void buildWritables(LottieExpression* exp); + + Point toPoint2d(jerry_value_t obj); + RGB32 toColor(jerry_value_t obj); + + //global object, attributes, methods + jerry_value_t global; + jerry_value_t comp; + jerry_value_t thisComp; + jerry_value_t thisLayer; + jerry_value_t thisProperty; +}; + +#else + +struct LottieExpressions +{ + template bool result(TVG_UNUSED float, TVG_UNUSED NumType&, TVG_UNUSED LottieExpression*) { return false; } + template bool result(TVG_UNUSED float, TVG_UNUSED Point&, LottieExpression*) { return false; } + template bool result(TVG_UNUSED float, TVG_UNUSED RGB32&, TVG_UNUSED LottieExpression*) { return false; } + template bool result(TVG_UNUSED float, TVG_UNUSED Fill*, TVG_UNUSED LottieExpression*) { return false; } + template bool result(TVG_UNUSED float, TVG_UNUSED RenderPath&, TVG_UNUSED Matrix*, TVG_UNUSED LottieModifier*, TVG_UNUSED LottieExpression*) { return false; } + bool result(TVG_UNUSED float, TVG_UNUSED TextDocument& doc, TVG_UNUSED LottieExpression*) { return false; } + void update(TVG_UNUSED float) {} + static LottieExpressions* instance() { return nullptr; } + static void retrieve(TVG_UNUSED LottieExpressions* instance) {} +}; + +#endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT + +#endif //_TVG_LOTTIE_EXPRESSIONS_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieInterpolator.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieInterpolator.cpp new file mode 100644 index 0000000..7dbd175 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieInterpolator.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* 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/. */ + +#include "tvgStr.h" +#include "tvgMath.h" +#include "tvgLottieInterpolator.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define NEWTON_MIN_SLOPE 0.02f +#define NEWTON_ITERATIONS 4 +#define SUBDIVISION_PRECISION 0.0000001f +#define SUBDIVISION_MAX_ITERATIONS 10 + + +static inline float _constA(float aA1, float aA2) { return 1.0f - 3.0f * aA2 + 3.0f * aA1; } +static inline float _constB(float aA1, float aA2) { return 3.0f * aA2 - 6.0f * aA1; } +static inline float _constC(float aA1) { return 3.0f * aA1; } + + +static inline float _getSlope(float t, float aA1, float aA2) +{ + return 3.0f * _constA(aA1, aA2) * t * t + 2.0f * _constB(aA1, aA2) * t + _constC(aA1); +} + + +static inline float _calcBezier(float t, float aA1, float aA2) +{ + return ((_constA(aA1, aA2) * t + _constB(aA1, aA2)) * t + _constC(aA1)) * t; +} + + +float LottieInterpolator::getTForX(float aX) +{ + //Find interval where t lies + auto intervalStart = 0.0f; + auto currentSample = &samples[1]; + auto lastSample = &samples[SPLINE_TABLE_SIZE - 1]; + + for (; currentSample != lastSample && *currentSample <= aX; ++currentSample) { + intervalStart += SAMPLE_STEP_SIZE; + } + + --currentSample; // t now lies between *currentSample and *currentSample+1 + + // Interpolate to provide an initial guess for t + auto dist = (aX - *currentSample) / (*(currentSample + 1) - *currentSample); + auto guessForT = intervalStart + dist * SAMPLE_STEP_SIZE; + + // Check the slope to see what strategy to use. If the slope is too small + // Newton-Raphson iteration won't converge on a root so we use bisection + // instead. + auto initialSlope = _getSlope(guessForT, outTangent.x, inTangent.x); + if (initialSlope >= NEWTON_MIN_SLOPE) return NewtonRaphsonIterate(aX, guessForT); + else if (initialSlope == 0.0f) return guessForT; + else return binarySubdivide(aX, intervalStart, intervalStart + SAMPLE_STEP_SIZE); +} + + +float LottieInterpolator::binarySubdivide(float aX, float aA, float aB) +{ + float x, t; + int i = 0; + + do { + t = aA + (aB - aA) / 2.0f; + x = _calcBezier(t, outTangent.x, inTangent.x) - aX; + if (x > 0.0f) aB = t; + else aA = t; + } while (fabsf(x) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); + return t; +} + + +float LottieInterpolator::NewtonRaphsonIterate(float aX, float aGuessT) +{ + // Refine guess with Newton-Raphson iteration + for (int i = 0; i < NEWTON_ITERATIONS; ++i) { + // We're trying to find where f(t) = aX, + // so we're actually looking for a root for: CalcBezier(t) - aX + auto currentX = _calcBezier(aGuessT, outTangent.x, inTangent.x) - aX; + auto currentSlope = _getSlope(aGuessT, outTangent.x, inTangent.x); + if (currentSlope == 0.0f) return aGuessT; + aGuessT -= currentX / currentSlope; + } + return aGuessT; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +float LottieInterpolator::progress(float t) +{ + if (outTangent.x == outTangent.y && inTangent.x == inTangent.y) return t; + return _calcBezier(getTForX(t), outTangent.y, inTangent.y); +} + + +void LottieInterpolator::set(const char* key, Point& inTangent, Point& outTangent) +{ + if (key) this->key = duplicate(key); + this->inTangent = inTangent; + this->outTangent = outTangent; + + if (outTangent.x == outTangent.y && inTangent.x == inTangent.y) return; + + //calculates sample values + for (int i = 0; i < SPLINE_TABLE_SIZE; ++i) { + samples[i] = _calcBezier(float(i) * SAMPLE_STEP_SIZE, outTangent.x, inTangent.x); + } +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieInterpolator.h b/components/thorvg-main/src/loaders/lottie/tvgLottieInterpolator.h new file mode 100644 index 0000000..5986c81 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieInterpolator.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_INTERPOLATOR_H_ +#define _TVG_LOTTIE_INTERPOLATOR_H_ + +#define SPLINE_TABLE_SIZE 11 + +struct LottieInterpolator +{ + char* key; + Point outTangent, inTangent; + + float progress(float t); + void set(const char* key, Point& inTangent, Point& outTangent); + +private: + static constexpr float SAMPLE_STEP_SIZE = 1.0f / float(SPLINE_TABLE_SIZE - 1); + float samples[SPLINE_TABLE_SIZE]; + + float getTForX(float aX); + float binarySubdivide(float aX, float aA, float aB); + float NewtonRaphsonIterate(float aX, float aGuessT); +}; + +#endif //_TVG_LOTTIE_INTERPOLATOR_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieLoader.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieLoader.cpp new file mode 100644 index 0000000..f6a7698 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieLoader.cpp @@ -0,0 +1,532 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgStr.h" + #include "tvgLottieLoader.h" +#include "tvgLottieModel.h" +#include "tvgLottieParser.h" +#include "tvgLottieBuilder.h" +#include "tvgCompressor.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +LottieCustomSlot::~LottieCustomSlot() +{ + ARRAY_FOREACH(p, props) { + delete(p->prop); + } +} + + +bool LottieLoader::prepare() +{ + LottieParser parser(content, dirName, builder->expressions()); + if (!parser.parse()) return false; + { + ScopedLock lock(key); + comp = parser.comp; + } + if (!comp) return false; + if (parser.slots) { + auto slotcode = gen(parser.slots, true); + apply(slotcode, true); + del(slotcode, true); + parser.slots = nullptr; + } + builder->build(comp); + release(); + return true; +} + + +void LottieLoader::run(unsigned tid) +{ + if (comp) builder->update(comp, frameNo); //update frame + else if (prepare()) builder->update(comp, 0); //initial loading + build = false; +} + + +void LottieLoader::release() +{ + if (copy) { + tvg::free((char*)content); + content = nullptr; + } +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +LottieLoader::LottieLoader() : FrameModule(FileType::Lot), builder(new LottieBuilder) +{ + +} + + +LottieLoader::~LottieLoader() +{ + done(); + + release(); + + //TODO: correct position? + delete(comp); + delete(builder); + + tvg::free(dirName); +} + + +bool LottieLoader::header() +{ + //A single thread doesn't need to perform intensive tasks. + if (TaskScheduler::threads() == 0) { + LoadModule::read(); + if (prepare()) { + w = static_cast(comp->w); + h = static_cast(comp->h); + segmentEnd = frameCnt = comp->frameCnt(); + frameRate = comp->frameRate; + return true; + } + return false; + } + + //Quickly validate the given Lottie file without parsing in order to get the animation info. + auto startFrame = 0.0f; + auto endFrame = 0.0f; + uint32_t depth = 0; + + auto p = content; + + while (*p != '\0') { + if (*p == '{') { + ++depth; + ++p; + continue; + } + if (*p == '}') { + --depth; + ++p; + continue; + } + if (depth != 1) { + ++p; + continue; + } + //version + if (!strncmp(p, "\"v\":", 4)) { + p += 4; + continue; + } + + //framerate + if (!strncmp(p, "\"fr\":", 5)) { + p += 5; + auto e = strstr(p, ","); + if (!e) e = strstr(p, "}"); + frameRate = toFloat(p, nullptr); + p = e; + continue; + } + + //start frame + if (!strncmp(p, "\"ip\":", 5)) { + p += 5; + auto e = strstr(p, ","); + if (!e) e = strstr(p, "}"); + startFrame = toFloat(p, nullptr); + p = e; + continue; + } + + //end frame + if (!strncmp(p, "\"op\":", 5)) { + p += 5; + auto e = strstr(p, ","); + if (!e) e = strstr(p, "}"); + endFrame = toFloat(p, nullptr); + p = e; + continue; + } + + //width + if (!strncmp(p, "\"w\":", 4)) { + p += 4; + auto e = strstr(p, ","); + if (!e) e = strstr(p, "}"); + w = toFloat(p, nullptr); + p = e; + continue; + } + //height + if (!strncmp(p, "\"h\":", 4)) { + p += 4; + auto e = strstr(p, ","); + if (!e) e = strstr(p, "}"); + h = toFloat(p, nullptr); + p = e; + continue; + } + ++p; + } + + if (frameRate < FLOAT_EPSILON) { + TVGLOG("LOTTIE", "Not a Lottie file? Frame rate is 0!"); + return false; + } + + segmentEnd = frameCnt = (endFrame - startFrame); + + TVGLOG("LOTTIE", "info: frame rate = %f, duration = %f size = %f x %f", frameRate, frameCnt / frameRate, w, h); + + return true; +} + + +bool LottieLoader::open(const char* data, uint32_t size, const char* rpath, bool copy) +{ + if (copy) { + content = tvg::malloc(size + 1); + if (!content) return false; + memcpy((char*)content, data, size); + const_cast(content)[size] = '\0'; + } else content = data; + + this->size = size; + this->copy = copy; + + if (!rpath) this->dirName = duplicate("."); + else this->dirName = duplicate(rpath); + + return header(); +} + + +bool LottieLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + if ((content = LoadModule::open(path, size, true))) { + dirName = tvg::dirname(path); + copy = true; + return header(); + } +#endif + return false; +} + + +bool LottieLoader::resize(Paint* paint, float w, float h) +{ + if (!paint) return false; + + auto sx = w / this->w; + auto sy = h / this->h; + Matrix m = {sx, 0, 0, 0, sy, 0, 0, 0, 1}; + paint->transform(m); + + //apply the scale to the base clipper + auto clipper = PAINT(paint)->clipper; + if (clipper) clipper->transform(m); + + return true; +} + + +bool LottieLoader::read() +{ + //the loading has been already completed + if (!LoadModule::read()) return true; + + if (!content || size == 0) return false; + + TaskScheduler::request(this); + + return true; +} + + +Paint* LottieLoader::paint() +{ + sync(); + + if (!comp) return nullptr; + comp->initiated = true; + return comp->root->scene; +} + + +bool LottieLoader::apply(uint32_t slotcode, bool byDefault) +{ + if (curSlot == slotcode) return true; + + if (!ready() || comp->slots.count == 0) return false; + + auto applied = false; + + // Reset all slots if slotcode is 0 + if (slotcode == 0) { + ARRAY_FOREACH(p, comp->slots) (*p)->reset(); + applied = true; + } else { + //Find the custom slot with the slotcode + INLIST_FOREACH(this->slots, slot) { + if (slot->code != slotcode) continue; + //apply the custom slot property to the targets. + ARRAY_FOREACH(p, slot->props) { + p->target->apply(p->prop, byDefault); + } + applied = true; + break; + } + } + curSlot = slotcode; + if (applied) build = true; + return applied; +} + + +bool LottieLoader::del(uint32_t slotcode, bool byDefault) +{ + if (comp->slots.empty() || slotcode == 0 || !ready()) return false; + + // Search matching value and remove + INLIST_SAFE_FOREACH(this->slots, slot) { + if (slot->code != slotcode) continue; + if (!byDefault) { + ARRAY_FOREACH(p, slot->props) { + p->target->reset(); + } + build = true; + } + this->slots.remove(slot); + delete(slot); + break; + } + return true; +} + + +uint32_t LottieLoader::gen(const char* slots, bool byDefault) +{ + if (!slots || !ready() || comp->slots.empty()) return 0; + + //parsing slot json + auto temp = byDefault ? slots : duplicate(slots); + LottieParser parser(temp, dirName, builder->expressions()); + parser.comp = comp; + + auto idx = 0; + auto custom = new LottieCustomSlot(djb2Encode(slots)); + + //Generates list of the custom slot overriding + while (auto sid = djb2Encode(parser.sid(idx == 0))) { + //Associates the overrding target to apply for the current custom slot + auto found = false; + ARRAY_FOREACH(p, comp->slots) { + if ((*p)->sid != sid) continue; //find target + if (auto prop = parser.parse(*p)) custom->props.push({prop, *p}); + found = true; + break; + } + + if (!found) parser.skip(); //skip the value if the target slot is not found + ++idx; + } + + tvg::free((char*)temp); + + //Success, valid custom slot. + if (custom->props.count > 0) { + this->slots.back(custom); + return custom->code; + } + + delete(custom); + return 0; +} + + +float LottieLoader::shorten(float frameNo) +{ + //This ensures that the target frame number is reached. + return nearbyintf((frameNo + startFrame()) * 10000.0f) * 0.0001f; +} + + +bool LottieLoader::frame(float no) +{ + no = shorten(no); + + //Skip update if frame diff is too small. + if (!builder->tweening() && fabsf(this->frameNo - no) <= 0.0009f) return false; + + this->done(); + + this->frameNo = no; + + builder->offTween(); + + if (comp) comp->clear(); //clear synchronously + + TaskScheduler::request(this); + + return true; +} + + +float LottieLoader::startFrame() +{ + return segmentBegin; +} + + +float LottieLoader::totalFrame() +{ + return segmentEnd - segmentBegin; +} + + +float LottieLoader::curFrame() +{ + return frameNo - startFrame(); +} + + +float LottieLoader::duration() +{ + return (segmentEnd - segmentBegin) / frameRate; +} + + +void LottieLoader::sync() +{ + done(); + + if (build) run(0); +} + + +uint32_t LottieLoader::markersCnt() +{ + return ready() ? comp->markers.count : 0; +} + + +const char* LottieLoader::markers(uint32_t index) +{ + if (!ready() || index >= comp->markers.count) return nullptr; + auto marker = comp->markers.begin() + index; + return (*marker)->name; +} + + +Result LottieLoader::segment(float begin, float end) +{ + if (begin < 0.0f) begin = 0.0f; + if (end > frameCnt) end = frameCnt; + + if (begin > end) return Result::InvalidArguments; + + segmentBegin = begin; + segmentEnd = end; + + return Result::Success; +} + + +bool LottieLoader::segment(const char* marker, float& begin, float& end) +{ + if (!ready() || comp->markers.count == 0) return false; + + ARRAY_FOREACH(p, comp->markers) { + if (!strcmp(marker, (*p)->name)) { + begin = (*p)->time; + end = (*p)->time + (*p)->duration; + return true; + } + } + return false; +} + + +bool LottieLoader::ready() +{ + { + ScopedLock lock(key); + if (comp) return true; + } + done(); + if (comp) return true; + return false; +} + + +bool LottieLoader::tween(float from, float to, float progress) +{ + //tweening is not necessary + if (tvg::zero(progress)) return frame(from); + else if (tvg::equal(progress, 1.0f)) return frame(to); + + done(); + + frameNo = shorten(from); + + builder->onTween(shorten(to), progress); + + if (comp) comp->clear(); //clear synchronously + + TaskScheduler::request(this); + + return true; +} + + +bool LottieLoader::assign(const char* layer, uint32_t ix, const char* var, float val) +{ + if (!ready() || !comp->expressions) return false; + comp->root->assign(layer, ix, var, val); + + return true; +} + + +bool LottieLoader::quality(uint8_t value) +{ + if (!ready()) return false; + if (comp->quality != value) { + comp->quality = value; + build = true; + } + return true; +} + + +void LottieLoader::set(const AssetResolver* resolver) +{ + builder->resolver = resolver; +} diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieLoader.h b/components/thorvg-main/src/loaders/lottie/tvgLottieLoader.h new file mode 100644 index 0000000..554dbff --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieLoader.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_LOADER_H_ +#define _TVG_LOTTIE_LOADER_H_ + +#include "tvgCommon.h" +#include "tvgInlist.h" +#include "tvgFrameModule.h" +#include "tvgTaskScheduler.h" + +struct LottieComposition; +struct LottieBuilder; +struct LottieProperty; +struct LottieSlot; + + +struct LottieCustomSlot +{ + INLIST_ITEM(LottieCustomSlot); + + struct Pair + { + LottieProperty* prop; // New overriding property + LottieSlot* target; // Overriding target + }; + Array props; // This has a list of the overriding target(LottieSlot) with a property to apply. + uint32_t code; // Slot source-code key + + LottieCustomSlot(uint32_t code) : code(code) {} + ~LottieCustomSlot(); +}; + + +class LottieLoader : public FrameModule, public Task +{ +public: + const char* content = nullptr; //lottie file data + uint32_t size = 0; //lottie data size + float frameNo = 0.0f; //current frame number + float frameCnt = 0.0f; + float frameRate = 0.0f; + + LottieBuilder* builder; + LottieComposition* comp = nullptr; + Inlist slots; //user custom slot list + uint32_t curSlot = 0; //current applied slotcode + + Key key; + char* dirName = nullptr; //base resource directory + + bool copy = false; //"content" is owned by this loader + bool build = true; //require building the lottie scene + + LottieLoader(); + ~LottieLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool resize(Paint* paint, float w, float h) override; + bool read() override; + Paint* paint() override; + + //Slot Methods + uint32_t gen(const char* slot, bool byDefault = false); + bool apply(uint32_t slotcode, bool byDefault = false); + bool del(uint32_t slotcode, bool byDefault = false); + + //Frame Controls + bool frame(float no) override; + float totalFrame() override; + float curFrame() override; + float duration() override; + void sync() override; + + //Marker Supports + uint32_t markersCnt(); + const char* markers(uint32_t index); + bool segment(const char* marker, float& begin, float& end); + Result segment(float begin, float end) override; + + float shorten(float frameNo); //Reduce the accuracy for performance + bool tween(float from, float to, float progress); + bool assign(const char* layer, uint32_t ix, const char* var, float val); + bool quality(uint8_t value); + void set(const AssetResolver* resolver) override; + +private: + bool ready(); + bool header(); + void clear(); + float startFrame(); + void run(unsigned tid) override; + void release(); + bool prepare(); +}; + + +#endif //_TVG_LOTTIELOADER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieModel.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieModel.cpp new file mode 100644 index 0000000..d12d91d --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieModel.cpp @@ -0,0 +1,718 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgTaskScheduler.h" +#include "tvgLottieModel.h" +#include "tvgCompressor.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +Point LottieTextFollowPath::split(float dLen, float lenSearched, float& angle) +{ + switch (*cmds) { + case PathCommand::MoveTo: { + angle = 0.0f; + break; + } + case PathCommand::LineTo: { + auto dp = *pts - *(pts - 1); + angle = tvg::atan2(dp.y, dp.x); + break; + } + case PathCommand::CubicTo: { + auto bz = Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}; + float t = bz.at(lenSearched - currentLen, dLen); + angle = deg2rad(bz.angle(t)); + return bz.at(t); + } + case PathCommand::Close: { + auto dp = *start - *(pts - 1); + angle = tvg::atan2(dp.y, dp.x); + break; + } + } + return {}; +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +float LottieTextFollowPath::prepare(LottieMask* mask, float frameNo, float scale, Tween& tween, LottieExpressions* exps) +{ + this->mask = mask; + Matrix m{1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f}; + path.clear(); + mask->pathset(frameNo, path, &m, tween, exps); + + pts = path.pts.data; + cmds = path.cmds.data; + cmdsCnt = path.cmds.count; + totalLen = tvg::length(cmds, cmdsCnt, pts, path.pts.count); + currentLen = 0.0f; + start = pts; + + return firstMargin(frameNo, tween, exps) / scale; +} + +Point LottieTextFollowPath::position(float lenSearched, float& angle) +{ + //position before the start of the curve + if (lenSearched <= 0.0f) { + //shape is closed -> wrapping + if (path.cmds.last() == PathCommand::Close) { + while (lenSearched < 0.0f) lenSearched += totalLen; + pts = path.pts.data; + cmds = path.cmds.data; + cmdsCnt = path.cmds.count; + currentLen = 0.0f; + //linear interpolation + } else { + if (cmds >= path.cmds.data + path.cmds.count - 1) return *start; + switch (*(cmds + 1)) { + case PathCommand::LineTo: { + auto dp = *(pts + 1) - *pts; + angle = tvg::atan2(dp.y, dp.x); + return {pts->x + lenSearched * cos(angle), pts->y + lenSearched * sin(angle)}; + } + case PathCommand::CubicTo: { + angle = deg2rad(Bezier{*pts, *(pts + 1), *(pts + 2), *(pts + 3)}.angle(0.0001f)); + return {pts->x + lenSearched * cos(angle), pts->y + lenSearched * sin(angle)}; + } + default: + angle = 0.0f; + return *start; + } + } + } + + auto shift = [&]() -> void { + switch (*cmds) { + case PathCommand::MoveTo: start = pts; ++pts; break; + case PathCommand::LineTo: ++pts; break; + case PathCommand::CubicTo: pts += 3; break; + case PathCommand::Close: break; + } + ++cmds; + --cmdsCnt; + }; + + //position beyond the end of the curve + if (lenSearched >= totalLen) { + //shape is closed -> wrapping + if (path.cmds.last() == PathCommand::Close) { + while (lenSearched > totalLen) lenSearched -= totalLen; + pts = path.pts.data; + cmds = path.cmds.data; + cmdsCnt = path.cmds.count; + currentLen = 0.0f; + //linear interpolation + } else { + while (cmdsCnt > 1) shift(); + switch (*cmds) { + case PathCommand::MoveTo: + angle = 0.0f; + return *pts; + case PathCommand::LineTo: { + auto len = lenSearched - totalLen; + auto dp = *pts - *(pts - 1); + angle = tvg::atan2(dp.y, dp.x); + return {pts->x + len * cos(angle), pts->y + len * sin(angle)}; + } + case PathCommand::CubicTo: { + auto len = lenSearched - totalLen; + angle = deg2rad(Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}.angle(0.999f)); + return {(pts + 2)->x + len * cos(angle), (pts + 2)->y + len * sin(angle)}; + } + case PathCommand::Close: { + auto len = lenSearched - totalLen; + auto dp = *start - *(pts - 1); + angle = tvg::atan2(dp.y, dp.x); + return {(pts - 1)->x + len * cos(angle), (pts - 1)->y + len * sin(angle)}; + } + } + } + } + + //reset required if text partially crosses curve start + if (lenSearched < currentLen) { + pts = path.pts.data; + cmds = path.cmds.data; + cmdsCnt = path.cmds.count; + currentLen = 0.0f; + } + + auto length = [&]() -> float { + switch (*cmds) { + case PathCommand::MoveTo: return 0.0f; + case PathCommand::LineTo: return tvg::length(*(pts - 1), *pts); + case PathCommand::CubicTo: return Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}.length(); + case PathCommand::Close: return tvg::length(*(pts - 1), *start); + default: return 0.0f; + } + }; + + while (cmdsCnt > 0) { + auto dLen = length(); + if (currentLen + dLen < lenSearched) { + shift(); + currentLen += dLen; + continue; + } + return split(dLen, lenSearched, angle); + } + return {}; +} + + +void LottieSlot::reset() +{ + if (!overridden) return; + + ARRAY_FOREACH(pair, pairs) { + pair->obj->override(pair->prop, true); + delete(pair->prop); + pair->prop = nullptr; + } + overridden = false; +} + + +void LottieSlot::apply(LottieProperty* prop, bool byDefault) +{ + auto copy = !overridden && !byDefault; + + //apply slot object to all targets + ARRAY_FOREACH(pair, pairs) { + //backup the original properties before overwriting + switch (type) { + case LottieProperty::Type::Float: { + if (copy) pair->prop = new LottieFloat(static_cast(pair->obj)->rotation); + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::Scalar: { + if (copy) pair->prop = new LottieScalar(static_cast(pair->obj)->scale); + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::Vector: { + if (copy) pair->prop = new LottieVector(static_cast(pair->obj)->position); + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::Color: { + if (copy) pair->prop = new LottieColor(static_cast(pair->obj)->color); + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::Opacity: { + if (copy) { + if (pair->obj->type == LottieObject::Type::Transform) pair->prop = new LottieOpacity(static_cast(pair->obj)->opacity); + else pair->prop = new LottieOpacity(static_cast(pair->obj)->opacity); + } + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::ColorStop: { + if (copy) pair->prop = new LottieColorStop(static_cast(pair->obj)->colorStops); + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::TextDoc: { + if (copy) pair->prop = new LottieTextDoc(static_cast(pair->obj)->doc); + pair->obj->override(prop, !copy); + break; + } + case LottieProperty::Type::Image: { + if (copy) pair->prop = new LottieBitmap(static_cast(pair->obj)->bitmap); + pair->obj->override(prop, !copy); + break; + } + default: break; + } + } + + if (!byDefault) overridden = true; +} + + +float LottieTextRange::factor(float frameNo, float totalLen, float idx) +{ + auto offset = this->offset(frameNo); + auto start = this->start(frameNo) + offset; + auto end = this->end(frameNo) + offset; + + if (random > 0) { + auto range = end - start; + auto len = (rangeUnit == Unit::Percent) ? 100.0f : totalLen; + start = static_cast(random % int(len - range)); + end = start + range; + } + + auto divisor = (rangeUnit == Unit::Percent) ? (100.0f / totalLen) : 1.0f; + start /= divisor; + end /= divisor; + + auto f = 0.0f; + + switch (this->shape) { + case Square: { + auto smoothness = this->smoothness(frameNo); + if (tvg::zero(smoothness)) f = idx >= nearbyintf(start) && idx < nearbyintf(end) ? 1.0f : 0.0f; + else { + if (idx >= std::floor(start)) { + auto diff = idx - start; + f = diff < 0.0f ? std::min(end, 1.0f) + diff : end - idx; + } + smoothness *= 0.01f; + f = (f - (1.0f - smoothness) * 0.5f) / smoothness; + } + break; + } + case RampUp: { + f = tvg::equal(start, end) ? (idx >= end ? 1.0f : 0.0f) : (0.5f + idx - start) / (end - start); + break; + } + case RampDown: { + f = tvg::equal(start, end) ? (idx >= end ? 0.0f : 1.0f) : 1.0f - (0.5f + idx - start) / (end - start); + break; + } + case Triangle: { + f = tvg::equal(start, end) ? 0.0f : 2.0f * (0.5f + idx - start) / (end - start); + f = f < 1.0f ? f : 2.0f - f; + break; + } + case Round: { + idx = tvg::clamp(idx + (0.5f - start), 0.0f, end - start); + auto range = 0.5f * (end - start); + auto t = idx - range; + f = tvg::equal(start, end) ? 0.0f : sqrtf(1.0f - t * t / (range * range)); + break; + } + case Smooth: { + idx = tvg::clamp(idx + (0.5f - start), 0.0f, end - start); + f = tvg::equal(start, end) ? 0.0f : 0.5f * (1.0f + cosf(MATH_PI * (1.0f + 2.0f * idx / (end - start)))); + break; + } + } + f = tvg::clamp(f, 0.0f, 1.0f); + + //apply easing + auto minEase = tvg::clamp(this->minEase(frameNo), -100.0f, 100.0f); + auto maxEase = tvg::clamp(this->maxEase(frameNo), -100.0f, 100.0f); + if (!tvg::zero(minEase) || !tvg::zero(maxEase)) { + Point in{1.0f, 1.0f}; + Point out{0.0f, 0.0f}; + + if (maxEase > 0.0f) in.x = 1.0f - maxEase * 0.01f; + else in.y = 1.0f + maxEase * 0.01f; + if (minEase > 0.0f) out.x = minEase * 0.01f; + else out.y = -minEase * 0.01f; + + interpolator->set(nullptr, in, out); + f = interpolator->progress(f); + } + f = tvg::clamp(f, 0.0f, 1.0f); + + return f * this->maxAmount(frameNo) * 0.01f; +} + + +void LottieFont::prepare() +{ + if (!b64src) return; + + Text::load(name, b64src, size, "ttf", false); +} + + +void LottieImage::prepare() +{ + LottieObject::type = LottieObject::Image; + + //Prepare the Picture image + auto picture = Picture::gen(); + auto result = (bitmap.size > 0) ? picture->load((const char*)bitmap.data, bitmap.size, bitmap.mimeType) : picture->load(bitmap.path); + if (result == Result::Success) resolved = true; + picture->size(bitmap.width, bitmap.height); + bitmap.picture = picture; + picture->ref(); +} + + +void LottieTrimpath::segment(float frameNo, float& start, float& end, Tween& tween, LottieExpressions* exps) +{ + start = tvg::clamp(this->start(frameNo, tween, exps) * 0.01f, 0.0f, 1.0f); + end = tvg::clamp(this->end(frameNo, tween, exps) * 0.01f, 0.0f, 1.0f); + + auto diff = fabs(start - end); + if (tvg::zero(diff)) { + start = 0.0f; + end = 0.0f; + return; + } + + //Even if the start and end values do not cause trimming, an offset > 0 can still affect dashing starting point + auto o = fmodf(this->offset(frameNo, tween, exps), 360.0f) / 360.0f; //0 ~ 1 + if (tvg::zero(o) && diff >= 1.0f) { + start = 0.0f; + end = 1.0f; + return; + } + + if (start > end) std::swap(start, end); + start += o; + end += o; +} + + +uint32_t LottieGradient::populate(ColorStop& color, size_t count) +{ + if (!color.input) return 0; + + uint32_t alphaCnt = (color.input->count - (count * 4)) / 2; + Array output(count + alphaCnt); + uint32_t cidx = 0; //color count + uint32_t clast = count * 4; + if (clast > color.input->count) clast = color.input->count; + uint32_t aidx = clast; //alpha count + Fill::ColorStop cs; + + //merge color stops. + for (uint32_t i = 0; i < color.input->count; ++i) { + if (cidx == clast || aidx == color.input->count) break; + if ((*color.input)[cidx] == (*color.input)[aidx]) { + cs.offset = (*color.input)[cidx]; + cs.r = (uint8_t)nearbyint((*color.input)[cidx + 1] * 255.0f); + cs.g = (uint8_t)nearbyint((*color.input)[cidx + 2] * 255.0f); + cs.b = (uint8_t)nearbyint((*color.input)[cidx + 3] * 255.0f); + cs.a = (uint8_t)nearbyint((*color.input)[aidx + 1] * 255.0f); + cidx += 4; + aidx += 2; + } else if ((*color.input)[cidx] < (*color.input)[aidx]) { + cs.offset = (*color.input)[cidx]; + cs.r = (uint8_t)nearbyint((*color.input)[cidx + 1] * 255.0f); + cs.g = (uint8_t)nearbyint((*color.input)[cidx + 2] * 255.0f); + cs.b = (uint8_t)nearbyint((*color.input)[cidx + 3] * 255.0f); + //generate alpha value + if (output.count > 0) { + auto p = ((*color.input)[cidx] - output.last().offset) / ((*color.input)[aidx] - output.last().offset); + cs.a = tvg::lerp(output.last().a, (uint8_t)nearbyint((*color.input)[aidx + 1] * 255.0f), p); + } else cs.a = (uint8_t)nearbyint((*color.input)[aidx + 1] * 255.0f); + cidx += 4; + } else { + cs.offset = (*color.input)[aidx]; + cs.a = (uint8_t)nearbyint((*color.input)[aidx + 1] * 255.0f); + //generate color value + if (output.count > 0) { + auto p = ((*color.input)[aidx] - output.last().offset) / ((*color.input)[cidx] - output.last().offset); + cs.r = tvg::lerp(output.last().r, (uint8_t)nearbyint((*color.input)[cidx + 1] * 255.0f), p); + cs.g = tvg::lerp(output.last().g, (uint8_t)nearbyint((*color.input)[cidx + 2] * 255.0f), p); + cs.b = tvg::lerp(output.last().b, (uint8_t)nearbyint((*color.input)[cidx + 3] * 255.0f), p); + } else { + cs.r = (uint8_t)nearbyint((*color.input)[cidx + 1] * 255.0f); + cs.g = (uint8_t)nearbyint((*color.input)[cidx + 2] * 255.0f); + cs.b = (uint8_t)nearbyint((*color.input)[cidx + 3] * 255.0f); + } + aidx += 2; + } + if (cs.a < 255) opaque = false; + output.push(cs); + } + + //color remains + while (cidx + 3 < clast) { + cs.offset = (*color.input)[cidx]; + cs.r = (uint8_t)nearbyint((*color.input)[cidx + 1] * 255.0f); + cs.g = (uint8_t)nearbyint((*color.input)[cidx + 2] * 255.0f); + cs.b = (uint8_t)nearbyint((*color.input)[cidx + 3] * 255.0f); + cs.a = (output.count > 0) ? output.last().a : 255; + if (cs.a < 255) opaque = false; + output.push(cs); + cidx += 4; + } + + //alpha remains + while (aidx < color.input->count) { + cs.offset = (*color.input)[aidx]; + cs.a = (uint8_t)nearbyint((*color.input)[aidx + 1] * 255.0f); + if (cs.a < 255) opaque = false; + if (output.count > 0) { + cs.r = output.last().r; + cs.g = output.last().g; + cs.b = output.last().b; + } else cs.r = cs.g = cs.b = 255; + output.push(cs); + aidx += 2; + } + + color.data = output.data; + output.data = nullptr; + + color.input->reset(); + delete(color.input); + color.input = nullptr; + + return output.count; +} + + +Fill* LottieGradient::fill(float frameNo, uint8_t opacity, Tween& tween, LottieExpressions* exps) +{ + if (opacity == 0) return nullptr; + + Fill* fill; + auto s = start(frameNo, tween, exps); + auto e = end(frameNo, tween, exps); + + //Linear Graident + if (id == 1) { + fill = LinearGradient::gen(); + static_cast(fill)->linear(s.x, s.y, e.x, e.y); + //Radial Gradient + } else { + fill = RadialGradient::gen(); + auto w = fabsf(e.x - s.x); + auto h = fabsf(e.y - s.y); + auto r = (w > h) ? (w + 0.375f * h) : (h + 0.375f * w); + auto progress = this->height(frameNo, tween, exps) * 0.01f; + + if (tvg::zero(progress)) { + static_cast(fill)->radial(s.x, s.y, r, s.x, s.y, 0.0f); + } else { + auto startAngle = rad2deg(tvg::atan2(e.y - s.y, e.x - s.x)); + auto angle = deg2rad((startAngle + this->angle(frameNo, tween, exps))); + auto fx = s.x + cos(angle) * progress * r; + auto fy = s.y + sin(angle) * progress * r; + // Lottie doesn't have any focal radius concept + static_cast(fill)->radial(s.x, s.y, r, fx, fy, 0.0f); + } + } + + colorStops(frameNo, fill, tween, exps); + + //multiply the current opacity with the fill + if (opacity < 255) { + const Fill::ColorStop* colorStops; + auto cnt = fill->colorStops(&colorStops); + for (uint32_t i = 0; i < cnt; ++i) { + const_cast(&colorStops[i])->a = MULTIPLY(colorStops[i].a, opacity); + } + } + + return fill; +} + + +LottieGroup::LottieGroup() +{ + reqFragment = false; + buildDone = false; + trimpath = false; + visible = false; + allowMerge = true; +} + + +LottieProperty* LottieGroup::property(uint16_t ix) +{ + ARRAY_FOREACH(p, children) { + auto child = static_cast(*p); + if (auto property = child->property(ix)) return property; + } + + return nullptr; +} + + +void LottieGroup::prepare(LottieObject::Type type) +{ + LottieObject::type = type; + + if (children.count == 0) return; + + size_t strokeCnt = 0; + size_t fillCnt = 0; + + ARRAY_REVERSE_FOREACH(c, children) { + auto child = static_cast(*c); + + if (child->type == LottieObject::Type::Trimpath) trimpath = true; + + /* Figure out if this group is a simple path drawing. + In that case, the rendering context can be sharable with the parent's. */ + if (allowMerge && !child->mergeable()) allowMerge = false; + + //Figure out this group has visible contents + switch (child->type) { + case LottieObject::Group: { + visible |= static_cast(child)->visible; + break; + } + case LottieObject::Rect: + case LottieObject::Ellipse: + case LottieObject::Path: + case LottieObject::Polystar: + case LottieObject::Image: + case LottieObject::Text: { + visible = true; + break; + } + default: break; + } + + if (reqFragment) continue; + + /* Figure out if the rendering context should be fragmented. + Multiple stroking or grouping with a stroking would occur this. + This fragment resolves the overlapped stroke outlines. */ + if (child->type == LottieObject::Group && !child->mergeable()) { + if (strokeCnt > 0 || fillCnt > 0) reqFragment = true; + } else if (child->type == LottieObject::SolidStroke || child->type == LottieObject::GradientStroke) { + if (strokeCnt > 0) reqFragment = true; + else ++strokeCnt; + } else if (child->type == LottieObject::SolidFill || child->type == LottieObject::GradientFill) { + if (fillCnt > 0) reqFragment = true; + else ++fillCnt; + } + } + + //Reverse the drawing order if this group has a trimpath. + if (!trimpath) return; + + for (uint32_t i = 0; i < children.count - 1; ) { + auto child2 = children[i + 1]; + if (!child2->mergeable() || child2->type == LottieObject::Transform) { + i += 2; + continue; + } + auto child = children[i]; + if (!child->mergeable() || child->type == LottieObject::Transform) { + i++; + continue; + } + children[i] = child2; + children[i + 1] = child; + i++; + } +} + + +LottieLayer::~LottieLayer() +{ + //No need to free assets children because the Composition owns them. + if (rid) children.clear(); + + ARRAY_FOREACH(p, masks) delete(*p); + ARRAY_FOREACH(p, effects) delete(*p); + + delete(transform); + tvg::free(name); +} + + +LottieProperty* LottieLayer::property(uint16_t ix) +{ + if (transform) { + if (auto property = transform->property(ix)) return property; + } + + return LottieGroup::property(ix); +} + + +void LottieLayer::prepare(RGB32* color) +{ + /* if layer is hidden, only useful data is its transform matrix. + so force it to be a Null Layer and release all resource. */ + if (hidden) { + type = LottieLayer::Null; + ARRAY_FOREACH(p, children) delete(*p); + children.reset(); + return; + } + + //prepare the viewport clipper + if (type == LottieLayer::Precomp) { + auto clipper = Shape::gen(); + clipper->appendRect(0.0f, 0.0f, w, h); + clipper->ref(); + statical.pooler.push(clipper); + //prepare solid fill in advance if it is a layer type. + } else if (color && type == LottieLayer::Solid) { + auto solidFill = Shape::gen(); + solidFill->appendRect(0, 0, static_cast(w), static_cast(h)); + solidFill->fill(color->r, color->g, color->b); + solidFill->ref(); + statical.pooler.push(solidFill); + } + + LottieGroup::prepare(LottieObject::Layer); +} + + +float LottieLayer::remap(LottieComposition* comp, float frameNo, LottieExpressions* exp) +{ + if (timeRemap.frames || timeRemap.value >= 0.0f) { + return comp->frameAtTime(timeRemap(frameNo, exp)); + } + return (frameNo - startFrame) / timeStretch; +} + + +bool LottieLayer::assign(const char* layer, uint32_t ix, const char* var, float val) +{ + //find the target layer by name + auto target = layerById(djb2Encode(layer)); + if (!target) return false; + + //find the target property by ix + auto property = target->property(ix); + if (property && property->exp) return property->exp->assign(var, val); + + return false; +} + + +LottieComposition::~LottieComposition() +{ + if (!initiated && root) Paint::rel(root->scene); + + delete(root); + tvg::free(version); + tvg::free(name); + + ARRAY_FOREACH(p, interpolators) { + tvg::free((*p)->key); + tvg::free(*p); + } + + ARRAY_FOREACH(p, assets) delete(*p); + ARRAY_FOREACH(p, fonts) delete(*p); + ARRAY_FOREACH(p, slots) delete(*p); + ARRAY_FOREACH(p, markers) delete(*p); +} diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieModel.h b/components/thorvg-main/src/loaders/lottie/tvgLottieModel.h new file mode 100644 index 0000000..58d942b --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieModel.h @@ -0,0 +1,1152 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_MODEL_H_ +#define _TVG_LOTTIE_MODEL_H_ + +#include "tvgCommon.h" +#include "tvgStr.h" +#include "tvgCompressor.h" +#include "tvgInlist.h" +#include "tvgRender.h" +#include "tvgLottieProperty.h" +#include "tvgLottieRenderPooler.h" + + +struct LottieComposition; + +struct LottieStroke +{ + struct DashAttr + { + LottieFloat offset = 0.0f; + LottieFloat* values = nullptr; + uint8_t size = 0; + uint8_t allocated = 0; + }; + + virtual ~LottieStroke() + { + if (dashattr) delete[] dashattr->values; + delete(dashattr); + } + + + LottieFloat& dashValue() + { + if (!dashattr) dashattr = new DashAttr; + + if (dashattr->size + 1 > dashattr->allocated) { + dashattr->allocated = dashattr->size + 2; + auto newValues = new LottieFloat[dashattr->allocated]; + for (uint8_t i = 0; i < dashattr->size; ++i) { + newValues[i].copy(dashattr->values[i]); + } + delete[] dashattr->values; + dashattr->values = newValues; + } + + return dashattr->values[dashattr->size++]; + } + + + LottieFloat& dashOffset() + { + if (!dashattr) dashattr = new DashAttr; + return dashattr->offset; + } + + LottieFloat width = 0.0f; + DashAttr* dashattr = nullptr; + float miterLimit = 0; + StrokeCap cap = StrokeCap::Round; + StrokeJoin join = StrokeJoin::Round; +}; + +struct LottieEffect +{ + enum Type : uint8_t {Custom = 5, Tint = 20, Fill, Stroke, Tritone, DropShadow = 25, GaussianBlur = 29}; + + virtual ~LottieEffect() {} + + unsigned long nm; //encoded by djb2 + unsigned long mn; //encoded by djb2 + int16_t ix; + Type type; + bool enable = false; +}; + + +struct LottieFxCustom : LottieEffect +{ + struct Property + { + LottieProperty* property; + unsigned long nm = 0; //encoded by djb2 + unsigned long mn = 0; //encoded by djb2 + }; + + char* name = nullptr; + Array props; + + LottieFxCustom() + { + type = LottieEffect::Custom; + } + + ~LottieFxCustom() + { + ARRAY_FOREACH(p, props) delete(p->property); + } + + Property* property(int type) + { + LottieProperty* prop = nullptr; + + switch (type) { + case 0: //slider + case 1: prop = new LottieFloat; break; //angle + case 2: prop = new LottieColor; break; //color + case 3: prop = new LottieVector; break; //point + case 4: //checkbox + case 7: //dropdown + case 10: prop = new LottieInteger; break; //effect layer + case 6: TVGLOG("LOTTIE", "custom ignored?"); break; + default: + TVGLOG("LOTTIE", "missing custom property = %d\n", type); + return nullptr; + } + if (prop) { + props.push({prop, }); + return &props.last(); + } + return nullptr; + } + + LottieProperty* property(const char* name) + { + auto id = djb2Encode(name); + ARRAY_FOREACH(p, props) { + if (p->mn == id || p->nm == id) return p->property; + } + return nullptr; + } +}; + +struct LottieFxFill : LottieEffect +{ + //LottieInteger mask; + //LottieInteger allMask; + LottieColor color; + //LottieInteger invert; + //LottieSlider hFeather; + //LottieSlider vFeather; + LottieFloat opacity; + + LottieFxFill() + { + type = LottieEffect::Fill; + } +}; + +struct LottieFxStroke : LottieEffect +{ + LottieInteger mask; + LottieInteger allMask; + //LottieInteger sequential; + LottieColor color; + LottieFloat size; + //LottieFloat hardness; //should support with the blurness? + LottieFloat opacity; + LottieFloat begin; + LottieFloat end; + //LottieFloat space; + //LottieInteger style; + + LottieFxStroke() + { + type = LottieEffect::Stroke; + } +}; + +struct LottieFxTint : LottieEffect +{ + LottieColor black; + LottieColor white; + LottieFloat intensity; + + LottieFxTint() + { + type = LottieEffect::Tint; + } +}; + +struct LottieFxTritone : LottieEffect +{ + LottieColor bright; + LottieColor midtone; + LottieColor dark; + LottieOpacity blend; + + LottieFxTritone() + { + type = LottieEffect::Tritone; + } +}; + +struct LottieFxDropShadow : LottieEffect +{ + LottieColor color; + LottieFloat opacity = 0; + LottieFloat angle = 0.0f; + LottieFloat distance = 0.0f; + LottieFloat blurness = 0.0f; + + LottieFxDropShadow() + { + type = LottieEffect::DropShadow; + } +}; + +struct LottieFxGaussianBlur : LottieEffect +{ + LottieFloat blurness = 0.0f; + LottieInteger direction = 0; + LottieInteger wrap = 0; + + LottieFxGaussianBlur() + { + type = LottieEffect::GaussianBlur; + } +}; + + +struct LottieMask +{ + LottiePathSet pathset; + LottieFloat expand = 0.0f; + LottieOpacity opacity = 255; + MaskMethod method; + bool inverse = false; +}; + + +struct LottieObject +{ + enum Type : uint8_t + { + Composition = 0, + Layer, + Group, + Transform, + SolidFill, + SolidStroke, + GradientFill, + GradientStroke, + Rect, + Ellipse, + Path, + Polystar, + Image, + Trimpath, + Text, + Repeater, + RoundedCorner, + OffsetPath + }; + + virtual ~LottieObject() + { + } + + virtual void override(LottieProperty* prop, bool release) + { + TVGERR("LOTTIE", "Unsupported slot type"); + } + + virtual bool mergeable() { return false; } + virtual LottieProperty* property(uint16_t ix) { return nullptr; } + + unsigned long id = 0; //unique id by name generated by djb2 encoding + Type type; + bool hidden = false; //remove? +}; + + +struct LottieGlyph +{ + Array children; //glyph shapes. + float width; + char* code; + char* family = nullptr; + char* style = nullptr; + uint16_t size; + uint8_t len; + + void prepare() + { + len = strlen(code); + } + + ~LottieGlyph() + { + ARRAY_FOREACH(p, children) delete(*p); + tvg::free(code); + } +}; + + +struct LottieTextRange +{ + enum Based : uint8_t { Chars = 1, CharsExcludingSpaces, Words, Lines }; + enum Shape : uint8_t { Square = 1, RampUp, RampDown, Triangle, Round, Smooth }; + enum Unit : uint8_t { Percent = 1, Index }; + + LottieTextRange() + { + style.flags.fillColor = 0; + style.flags.strokeColor = 0; + style.flags.strokeWidth = 0; + } + + ~LottieTextRange() + { + tvg::free(interpolator); + } + + struct { + LottieColor fillColor = RGB32{255, 255, 255}; + LottieColor strokeColor = RGB32{255, 255, 255}; + LottieVector position = Point{0, 0}; + LottieScalar scale = Point{100, 100}; + LottieFloat letterSpace = 0.0f; + LottieFloat lineSpace = 0.0f; + LottieFloat strokeWidth = 0.0f; + LottieFloat rotation = 0.0f; + LottieOpacity fillOpacity = 255; + LottieOpacity strokeOpacity = 255; + LottieOpacity opacity = 255; + struct { + bool fillColor : 1; + bool strokeColor : 1; + bool strokeWidth : 1; + } flags; + } style; + + LottieFloat offset = 0.0f; + LottieFloat maxEase = 0.0f; + LottieFloat minEase = 0.0f; + LottieFloat maxAmount = 0.0f; + LottieFloat smoothness = 0.0f; + LottieFloat start = 0.0f; + LottieFloat end = FLT_MAX; + LottieInterpolator* interpolator = nullptr; + Based based = Chars; + Shape shape = Square; + Unit rangeUnit = Percent; + uint8_t random = 0; + bool expressible = false; + + float factor(float frameNo, float totalLen, float idx); + + void color(float frameNo, RGB32& fillColor, RGB32& strokeColor, float factor, Tween& tween, LottieExpressions* exps) + { + if (style.flags.fillColor) { + auto color = style.fillColor(frameNo, tween, exps); + fillColor.r = tvg::lerp(fillColor.r, color.r, factor); + fillColor.g = tvg::lerp(fillColor.g, color.g, factor); + fillColor.b = tvg::lerp(fillColor.b, color.b, factor); + } + if (style.flags.strokeColor) { + auto color = style.strokeColor(frameNo, tween, exps); + strokeColor.r = tvg::lerp(strokeColor.r, color.r, factor); + strokeColor.g = tvg::lerp(strokeColor.g, color.g, factor); + strokeColor.b = tvg::lerp(strokeColor.b, color.b, factor); + } + } +}; + + +struct LottieFont +{ + enum Origin : uint8_t {Local = 0, CssURL, ScriptURL, FontURL}; + + ~LottieFont() + { + ARRAY_FOREACH(p, chars) delete(*p); + tvg::free(style); + tvg::free(family); + tvg::free(name); + tvg::free(b64src); + } + + union { + char* b64src = nullptr; + char* path; + }; + + Array chars; + char* name = nullptr; + char* family = nullptr; + char* style = nullptr; + uint32_t size = 0; + float ascent = 0.0f; + Origin origin = Local; + + void prepare(); +}; + +struct LottieMarker +{ + char* name = nullptr; + float time = 0.0f; + float duration = 0.0f; + + ~LottieMarker() + { + tvg::free(name); + } +}; + + +struct LottieTextFollowPath +{ +private: + RenderPath path; + PathCommand* cmds; + uint32_t cmdsCnt; + Point* pts; + Point* start; + float totalLen; + float currentLen; + Point split(float dLen, float lenSearched, float& angle); + +public: + LottieFloat firstMargin = 0.0f; + LottieMask* mask; + int8_t maskIdx = -1; + + Point position(float lenSearched, float& angle); + float prepare(LottieMask* mask, float frameNo, float scale, Tween& tween, LottieExpressions* exps); +}; + + +struct LottieText : LottieObject, LottieRenderPooler +{ + struct AlignOption + { + enum Group : uint8_t { Chars = 1, Word = 2, Line = 3, All = 4 }; + Group group = Chars; + LottieScalar anchor{}; + } alignOp; + + LottieText() + { + LottieObject::type = LottieObject::Text; + } + + void override(LottieProperty* prop, bool release = false) override + { + if (release) doc.release(); + doc.copy(*static_cast(prop), false); + } + + LottieProperty* property(uint16_t ix) override + { + if (doc.ix == ix) return &doc; + return nullptr; + } + + LottieTextDoc doc; + LottieFont* font = nullptr; + LottieTextFollowPath* follow = nullptr; + Array ranges; + + ~LottieText() + { + ARRAY_FOREACH(p, ranges) delete(*p); + delete(follow); + } +}; + + +struct LottieTrimpath : LottieObject +{ + enum Type : uint8_t { Simultaneous = 1, Individual = 2 }; + + LottieTrimpath() + { + LottieObject::type = LottieObject::Trimpath; + } + + bool mergeable() override + { + if (!start.frames && start.value == 0.0f && !end.frames && end.value == 100.0f && !offset.frames && offset.value == 0.0f) return true; + return false; + } + + LottieProperty* property(uint16_t ix) override + { + if (start.ix == ix) return &start; + if (end.ix == ix) return &end; + if (offset.ix == ix) return &offset; + return nullptr; + } + + void segment(float frameNo, float& start, float& end, Tween& tween, LottieExpressions* exps); + + LottieFloat start = 0.0f; + LottieFloat end = 100.0f; + LottieFloat offset = 0.0f; + Type type = Simultaneous; +}; + + +struct LottieShape : LottieObject, LottieRenderPooler +{ + bool clockwise = true; //clockwise or counter-clockwise + + virtual ~LottieShape() {} + + bool mergeable() override + { + return true; + } + + LottieShape(LottieObject::Type type) + { + LottieObject::type = type; + } +}; + + +struct LottieRoundedCorner : LottieObject +{ + LottieRoundedCorner() + { + LottieObject::type = LottieObject::RoundedCorner; + } + + LottieProperty* property(uint16_t ix) override + { + if (radius.ix == ix) return &radius; + return nullptr; + } + + LottieFloat radius = 0.0f; +}; + + +struct LottiePath : LottieShape +{ + LottiePath() : LottieShape(LottieObject::Path) {} + + LottieProperty* property(uint16_t ix) override + { + if (pathset.ix == ix) return &pathset; + return nullptr; + } + + LottiePathSet pathset; +}; + + +struct LottieRect : LottieShape +{ + LottieRect() : LottieShape(LottieObject::Rect) {} + + LottieProperty* property(uint16_t ix) override + { + if (position.ix == ix) return &position; + if (size.ix == ix) return &size; + if (radius.ix == ix) return &radius; + return nullptr; + } + + LottieVector position = Point{0.0f, 0.0f}; + LottieScalar size = Point{0.0f, 0.0f}; + LottieFloat radius = 0.0f; //rounded corner radius +}; + + +struct LottiePolyStar : LottieShape +{ + enum Type : uint8_t {Star = 1, Polygon}; + + LottiePolyStar() : LottieShape(LottieObject::Polystar) {} + + LottieProperty* property(uint16_t ix) override + { + if (position.ix == ix) return &position; + if (innerRadius.ix == ix) return &innerRadius; + if (outerRadius.ix == ix) return &outerRadius; + if (innerRoundness.ix == ix) return &innerRoundness; + if (outerRoundness.ix == ix) return &outerRoundness; + if (rotation.ix == ix) return &rotation; + if (ptsCnt.ix == ix) return &ptsCnt; + return nullptr; + } + + LottieVector position = Point{0.0f, 0.0f}; + LottieFloat innerRadius = 0.0f; + LottieFloat outerRadius = 0.0f; + LottieFloat innerRoundness = 0.0f; + LottieFloat outerRoundness = 0.0f; + LottieFloat rotation = 0.0f; + LottieFloat ptsCnt = 0.0f; + Type type = Polygon; +}; + + +struct LottieEllipse : LottieShape +{ + LottieEllipse() : LottieShape(LottieObject::Ellipse) {} + + LottieProperty* property(uint16_t ix) override + { + if (position.ix == ix) return &position; + if (size.ix == ix) return &size; + return nullptr; + } + + LottieVector position = Point{0.0f, 0.0f}; + LottieScalar size = Point{0.0f, 0.0f}; +}; + + +struct LottieTransform : LottieObject +{ + struct SeparateCoord + { + LottieFloat x = 0.0f; + LottieFloat y = 0.0f; + }; + + SeparateCoord* separateCoord() + { + if (!coords) coords = new SeparateCoord; + return coords; + } + + struct RotationEx + { + LottieFloat x = 0.0f; + LottieFloat y = 0.0f; + }; + + ~LottieTransform() + { + delete(coords); + delete(rotationEx); + } + + LottieTransform() + { + LottieObject::type = LottieObject::Transform; + } + + bool mergeable() override + { + return true; + } + + LottieProperty* property(uint16_t ix) override + { + if (position.ix == ix) return &position; + if (rotation.ix == ix) return &rotation; + if (scale.ix == ix) return &scale; + if (anchor.ix == ix) return &anchor; + if (opacity.ix == ix) return &opacity; + if (skewAngle.ix == ix) return &skewAngle; + if (skewAxis.ix == ix) return &skewAxis; + if (coords) { + if (coords->x.ix == ix) return &coords->x; + if (coords->y.ix == ix) return &coords->y; + } + return nullptr; + } + + void override(LottieProperty* prop, bool release) override + { + switch (prop->type) { + case LottieProperty::Type::Float: { + if (release) rotation.release(); + rotation.copy(*static_cast(prop), false); + break; + } + case LottieProperty::Type::Scalar: { + if (release) scale.release(); + scale.copy(*static_cast(prop), false); + break; + } + case LottieProperty::Type::Vector: { + if (release) position.release(); + position.copy(*static_cast(prop), false); + break; + } + case LottieProperty::Type::Opacity: { + if (release) opacity.release(); + opacity.copy(*static_cast(prop), false); + break; + } + default: break; + } + } + + LottieVector position = Point{0.0f, 0.0f}; + LottieFloat rotation = 0.0f; //z rotation + LottieScalar scale = Point{100.0f, 100.0f}; + LottieScalar anchor = Point{0.0f, 0.0f}; + LottieOpacity opacity = 255; + LottieFloat skewAngle = 0.0f; + LottieFloat skewAxis = 0.0f; + + SeparateCoord* coords = nullptr; //either a position or separate coordinates + RotationEx* rotationEx = nullptr; //extension for 3d rotation +}; + + +struct LottieSolid : LottieObject +{ + LottieColor color = RGB32{255, 255, 255}; + LottieOpacity opacity = 255; + + LottieProperty* property(uint16_t ix) override + { + if (color.ix == ix) return &color; + if (opacity.ix == ix) return &opacity; + return nullptr; + } +}; + + +struct LottieSolidStroke : LottieSolid, LottieStroke +{ + LottieSolidStroke() + { + LottieObject::type = LottieObject::SolidStroke; + } + + LottieProperty* property(uint16_t ix) override + { + if (width.ix == ix) return &width; + if (dashattr) { + for (uint8_t i = 0; i < dashattr->size ; ++i) + if (dashattr->values[i].ix == ix) return &dashattr->values[i]; + } + return LottieSolid::property(ix); + } + + void override(LottieProperty* prop, bool release) override + { + if (release) color.release(); + color.copy(*static_cast(prop), false); + } +}; + + +struct LottieSolidFill : LottieSolid +{ + LottieSolidFill() + { + LottieObject::type = LottieObject::SolidFill; + } + + void override(LottieProperty* prop, bool release) override + { + if (prop->type == LottieProperty::Type::Color) { + if (release) color.release(); + color.copy(*static_cast(prop), false); + } else if (prop->type == LottieProperty::Type::Opacity) { + if (release) opacity.release(); + opacity.copy(*static_cast(prop), false); + } + } + + FillRule rule = FillRule::NonZero; +}; + + +struct LottieGradient : LottieObject +{ + bool prepare() + { + if (!colorStops.populated) { + auto count = colorStops.count; //colorstop count can be modified after population + if (colorStops.frames) { + ARRAY_FOREACH(v, *colorStops.frames) { + colorStops.count = populate(v->value, count); + } + } else { + colorStops.count = populate(colorStops.value, count); + } + colorStops.populated = true; + } + if (start.frames || end.frames || height.frames || angle.frames || opacity.frames || colorStops.frames) return true; + return false; + } + + LottieProperty* property(uint16_t ix) override + { + if (start.ix == ix) return &start; + if (end.ix == ix) return &end; + if (height.ix == ix) return &height; + if (angle.ix == ix) return ∠ + if (opacity.ix == ix) return &opacity; + if (colorStops.ix == ix) return &colorStops; + return nullptr; + } + + void override(LottieProperty* prop, bool release = false) override + { + if (release) colorStops.release(); + colorStops.copy(*static_cast(prop), false); + prepare(); + } + + uint32_t populate(ColorStop& color, size_t count); + Fill* fill(float frameNo, uint8_t opacity, Tween& tween, LottieExpressions* exps); + + LottieScalar start = Point{0.0f, 0.0f}; + LottieScalar end = Point{0.0f, 0.0f}; + LottieFloat height = 0.0f; + LottieFloat angle = 0.0f; + LottieOpacity opacity = 255; + LottieColorStop colorStops; + uint8_t id = 0; //1: linear, 2: radial + bool opaque = true; //fully opaque or not +}; + + +struct LottieGradientFill : LottieGradient +{ + LottieGradientFill() + { + LottieObject::type = LottieObject::GradientFill; + } + + FillRule rule = FillRule::NonZero; +}; + + +struct LottieGradientStroke : LottieGradient, LottieStroke +{ + LottieGradientStroke() + { + LottieObject::type = LottieObject::GradientStroke; + } + + LottieProperty* property(uint16_t ix) override + { + if (width.ix == ix) return &width; + if (dashattr) { + for (uint8_t i = 0; i < dashattr->size ; ++i) + if (dashattr->values[i].ix == ix) return &dashattr->values[i]; + } + return LottieGradient::property(ix); + } +}; + + +struct LottieImage : LottieObject +{ + LottieBitmap bitmap; + bool resolved = false; + + void override(LottieProperty* prop, bool release = false) override + { + if (release) bitmap.release(); + bitmap.copy(*static_cast(prop), false); + } + + void prepare(); +}; + + +struct LottieRepeater : LottieObject +{ + LottieRepeater() + { + LottieObject::type = LottieObject::Repeater; + } + + LottieProperty* property(uint16_t ix) override + { + if (copies.ix == ix) return &copies; + if (offset.ix == ix) return &offset; + if (position.ix == ix) return &position; + if (rotation.ix == ix) return &rotation; + if (scale.ix == ix) return &scale; + if (anchor.ix == ix) return &anchor; + if (startOpacity.ix == ix) return &startOpacity; + if (endOpacity.ix == ix) return &endOpacity; + return nullptr; + } + + LottieFloat copies = 0.0f; + LottieFloat offset = 0.0f; + + //Transform + LottieVector position = Point{0.0f, 0.0f}; + LottieFloat rotation = 0.0f; + LottieScalar scale = Point{100.0f, 100.0f}; + LottieScalar anchor = Point{0.0f, 0.0f}; + LottieOpacity startOpacity = 255; + LottieOpacity endOpacity = 255; + bool inorder = true; //true: higher, false: lower +}; + + +struct LottieOffsetPath : LottieObject +{ + LottieOffsetPath() + { + LottieObject::type = LottieObject::OffsetPath; + } + + LottieFloat offset = 0.0f; + LottieFloat miterLimit = 4.0f; + StrokeJoin join = StrokeJoin::Miter; +}; + + +struct LottieGroup : LottieObject, LottieRenderPooler +{ + LottieGroup(); + + virtual ~LottieGroup() + { + ARRAY_FOREACH(p, children) delete(*p); + } + + void prepare(LottieObject::Type type = LottieObject::Group); + bool mergeable() override { return allowMerge; } + LottieProperty* property(uint16_t ix) override; + + LottieObject* content(unsigned long id) + { + if (this->id == id) return this; + + //source has children, find recursively. + ARRAY_FOREACH(p, children) { + auto child = *p; + if (child->type == LottieObject::Type::Group || child->type == LottieObject::Type::Layer) { + if (auto ret = static_cast(child)->content(id)) return ret; + } else if (child->id == id) return child; + } + return nullptr; + } + + Scene* scene = nullptr; + Array children; + BlendMethod blendMethod = BlendMethod::Normal; + + bool reqFragment : 1; //requirement to fragment the render context + bool buildDone : 1; //completed in building the composition. + bool trimpath : 1; //this group has a trimpath. + bool visible : 1; //this group has visible contents. + bool allowMerge : 1; //if this group is consisted of simple (transformed) shapes. +}; + + +struct LottieLayer : LottieGroup +{ + enum Type : uint8_t {Precomp = 0, Solid, Image, Null, Shape, Text}; + + ~LottieLayer(); + + bool mergeable() override { return false; } + void prepare(RGB32* color = nullptr); + float remap(LottieComposition* comp, float frameNo, LottieExpressions* exp); + LottieProperty* property(uint16_t ix) override; + bool assign(const char* layer, uint32_t ix, const char* var, float val); + + char* name = nullptr; + LottieLayer* parent = nullptr; + LottieFloat timeRemap = -1.0f; + LottieLayer* comp = nullptr; //Precompositor, current layer is belonges. + LottieTransform* transform = nullptr; + Array masks; + Array effects; + LottieLayer* matteTarget = nullptr; + + LottieRenderPooler statical; //static pooler for solid fill and clipper + + float timeStretch = 1.0f; + float w = 0.0f, h = 0.0f; + float inFrame = 0.0f; + float outFrame = 0.0f; + float startFrame = 0.0f; + unsigned long rid = 0; //pre-composition reference id. + int16_t mix = -1; //index of the matte layer. + int16_t pix = -1; //index of the parent layer. + int16_t ix = -1; //index of the current layer. + + struct { + float frameNo = -1.0f; + Matrix matrix; + uint8_t opacity; + } cache; + + MaskMethod matteType = MaskMethod::None; + Type type = Null; + bool autoOrient = false; + bool matteSrc = false; + + LottieEffect* effectById(unsigned long id) + { + ARRAY_FOREACH(p, effects) { + if (id == (*p)->nm || id == (*p)->mn) return *p; + } + return nullptr; + } + + LottieEffect* effectByIdx(int16_t ix) + { + ARRAY_FOREACH(p, effects) { + if (ix == (*p)->ix) return *p; + } + return nullptr; + } + + + LottieLayer* layerById(unsigned long id) + { + ARRAY_FOREACH(p, children) { + if ((*p)->type != LottieObject::Type::Layer) continue; + auto layer = static_cast(*p); + if (layer->id == id) return layer; + } + return nullptr; + } + + LottieLayer* layerByIdx(int16_t ix) + { + ARRAY_FOREACH(p, children) { + if ((*p)->type != LottieObject::Type::Layer) continue; + auto layer = static_cast(*p); + if (layer->ix == ix) return layer; + } + return nullptr; + } +}; + + +struct LottieSlot +{ + struct Pair + { + LottieObject* obj; + LottieProperty* prop; + }; + + void add(uint32_t slotcode, LottieProperty* prop); + void apply(LottieProperty* prop, bool byDefault = false); + void reset(); + + LottieSlot(LottieLayer* layer, LottieObject* parent, unsigned long sid, LottieObject* obj, LottieProperty::Type type) : context{layer, parent}, sid(sid), type(type) + { + pairs.push({obj, nullptr}); + } + + ~LottieSlot() + { + if (!overridden) return; + ARRAY_FOREACH(pair, pairs) delete(pair->prop); + } + + struct { + LottieLayer* layer; + LottieObject* parent; + } context; + + unsigned long sid; // djb2 encoded + Array pairs; // object-property pairs that can be overridden by this slot + LottieProperty::Type type; + + bool overridden = false; +}; + + +struct LottieComposition +{ + ~LottieComposition(); + + void clear() + { + if (root && root->scene) root->scene->remove(); + } + + float duration() const + { + return frameCnt() / frameRate; // in second + } + + float frameAtTime(float timeInSec) const + { + auto p = timeInSec / duration(); + if (p < 0.0f) p = 0.0f; + return p * frameCnt(); + } + + float timeAtFrame(float frameNo) + { + return (frameNo - root->inFrame) / frameRate; + } + + float frameCnt() const + { + return root->outFrame - root->inFrame; + } + + LottieLayer* asset(unsigned long id) + { + ARRAY_FOREACH(p, assets) { + auto layer = static_cast(*p); + if (layer->id == id) return layer; + } + return nullptr; + } + + void clamp(float& frameNo) + { + frameNo += root->inFrame; + if (frameNo < root->inFrame) frameNo = root->inFrame; + if (frameNo >= root->outFrame) frameNo = root->outFrame - 1; + } + + LottieLayer* root = nullptr; + char* version = nullptr; + char* name = nullptr; + float w, h; + float frameRate; + Array assets; + Array interpolators; + Array fonts; + Array slots; + Array markers; + bool expressions = false; + bool initiated = false; + uint8_t quality = 50; +}; + +#endif //_TVG_LOTTIE_MODEL_H_ diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieModifier.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieModifier.cpp new file mode 100644 index 0000000..0d8d9a7 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieModifier.cpp @@ -0,0 +1,389 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgLottieModifier.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static bool _colinear(const Point* p) +{ + return tvg::zero(*p - *(p + 1)) && tvg::zero(*(p + 2) - *(p + 3)); +} + + +static Point _roundCorner(RenderPath& out, Point& prev, Point& curr, Point& next, float r) +{ + auto lenPrev = length(prev - curr); + auto rPrev = lenPrev > 0.0f ? 0.5f * std::min(lenPrev * 0.5f, r) / lenPrev : 0.0f; + auto lenNext = length(next - curr); + auto rNext = lenNext > 0.0f ? 0.5f * std::min(lenNext * 0.5f, r) / lenNext : 0.0f; + auto dPrev = rPrev * (curr - prev); + auto dNext = rNext * (curr - next); + + out.lineTo(curr - 2.0f * dPrev); + auto ret = curr - 2.0f * dNext; + out.cubicTo(curr - dPrev, curr - dNext, ret); + return ret; +} + + +static bool _intersect(Line& line1, Line& line2, Point& intersection, bool& inside) +{ + if (tvg::zero(line1.pt2 - line2.pt1)) { + intersection = line1.pt2; + inside = true; + return true; + } + + constexpr float epsilon = 1e-3f; + float denom = (line1.pt2.x - line1.pt1.x) * (line2.pt2.y - line2.pt1.y) - (line1.pt2.y - line1.pt1.y) * (line2.pt2.x - line2.pt1.x); + if (fabsf(denom) < epsilon) return false; + + float t = ((line2.pt1.x - line1.pt1.x) * (line2.pt2.y - line2.pt1.y) - (line2.pt1.y - line1.pt1.y) * (line2.pt2.x - line2.pt1.x)) / denom; + float u = ((line2.pt1.x - line1.pt1.x) * (line1.pt2.y - line1.pt1.y) - (line2.pt1.y - line1.pt1.y) * (line1.pt2.x - line1.pt1.x)) / denom; + + intersection.x = line1.pt1.x + t * (line1.pt2.x - line1.pt1.x); + intersection.y = line1.pt1.y + t * (line1.pt2.y - line1.pt1.y); + inside = t >= -epsilon && t <= 1.0f + epsilon && u >= -epsilon && u <= 1.0f + epsilon; + + return true; +} + + +static Line _offset(Point& p1, Point& p2, float offset) +{ + auto scaledNormal = normal(p1, p2) * offset; + return {p1 + scaledNormal, p2 + scaledNormal}; +} + + +static bool _clockwise(Point* pts, uint32_t n) +{ + auto area = 0.0f; + + for (uint32_t i = 0; i < n - 1; i++) { + area += cross(pts[i], pts[i + 1]); + } + area += cross(pts[n - 1], pts[0]);; + + return area < 0.0f; +} + + +void LottieOffsetModifier::corner(RenderPath& out, Line& line, Line& nextLine, uint32_t movetoOutIndex, bool nextClose) +{ + bool inside{}; + Point intersect{}; + if (_intersect(line, nextLine, intersect, inside)) { + if (inside) { + if (nextClose) out.pts[movetoOutIndex] = intersect; + out.pts.push(intersect); + } else { + out.pts.push(line.pt2); + if (join == StrokeJoin::Round) { + out.cubicTo((line.pt2 + intersect) * 0.5f, (nextLine.pt1 + intersect) * 0.5f, nextLine.pt1); + } else if (join == StrokeJoin::Miter) { + auto norm = normal(line.pt1, line.pt2); + auto nextNorm = normal(nextLine.pt1, nextLine.pt2); + auto miterDirection = (norm + nextNorm) / length(norm + nextNorm); + if (1.0f <= miterLimit * fabsf(miterDirection.x * norm.x + miterDirection.y * norm.y)) out.lineTo(intersect); + out.lineTo(nextLine.pt1); + } else out.lineTo(nextLine.pt1); + } + } else out.pts.push(line.pt2); +} + + +void LottieOffsetModifier::line(RenderPath& out, PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t& curPt, uint32_t curCmd, State& state, float offset, bool degenerated) +{ + if (tvg::zero(inPts[curPt - 1] - inPts[curPt])) { + ++curPt; + return; + } + + if (inCmds[curCmd - 1] != PathCommand::LineTo) state.line = _offset(inPts[curPt - 1], inPts[curPt], offset); + + if (state.moveto) { + state.movetoOutIndex = out.pts.count; + out.moveTo(state.line.pt1); + state.firstLine = state.line; + state.moveto = false; + } + + auto nonDegeneratedCubic = [&](uint32_t cmd, uint32_t pt) { + return inCmds[cmd] == PathCommand::CubicTo && !tvg::zero(inPts[pt] - inPts[pt + 1]) && !tvg::zero(inPts[pt + 2] - inPts[pt + 3]); + }; + + out.cmds.push(PathCommand::LineTo); + + if (curCmd + 1 == inCmdsCnt || inCmds[curCmd + 1] == PathCommand::MoveTo || nonDegeneratedCubic(curCmd + 1, curPt + degenerated)) { + out.pts.push(state.line.pt2); + ++curPt; + return; + } + + Line nextLine = state.firstLine; + if (inCmds[curCmd + 1] == PathCommand::LineTo) nextLine = _offset(inPts[curPt + degenerated], inPts[curPt + 1 + degenerated], offset); + else if (inCmds[curCmd + 1] == PathCommand::CubicTo) nextLine = _offset(inPts[curPt + 1 + degenerated], inPts[curPt + 2 + degenerated], offset); + else if (inCmds[curCmd + 1] == PathCommand::Close && !tvg::zero(inPts[curPt + degenerated] - inPts[state.movetoInIndex + degenerated])) + nextLine = _offset(inPts[curPt + degenerated], inPts[state.movetoInIndex + degenerated], offset); + + corner(out, state.line, nextLine, state.movetoOutIndex, inCmds[curCmd + 1] == PathCommand::Close); + + state.line = nextLine; + ++curPt; +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +bool LottieRoundnessModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, Matrix* transform, RenderPath& out) +{ + buffer->clear(); + + auto& path = (next) ? *buffer : out; + path.cmds.reserve(inCmdsCnt * 2); + path.pts.reserve((uint32_t)(inPtsCnt * 1.5)); + auto pivot = path.pts.count; + uint32_t startIndex = 0; + auto rounded = false; + Point roundTo; + + for (uint32_t iCmds = 0, iPts = 0; iCmds < inCmdsCnt; ++iCmds) { + switch (inCmds[iCmds]) { + case PathCommand::MoveTo: { + startIndex = path.pts.count; + path.moveTo(inPts[iPts++]); + break; + } + case PathCommand::CubicTo: { + if (iCmds < inCmdsCnt - 1 && _colinear(inPts + iPts - 1)) { + auto& prev = inPts[iPts - 1]; + auto& curr = inPts[iPts + 2]; + if (inCmds[iCmds + 1] == PathCommand::CubicTo && _colinear(inPts + iPts + 2)) { + roundTo = _roundCorner(path, prev, curr, inPts[iPts + 5], r); + iPts += 3; + rounded = true; + continue; + } else if (inCmds[iCmds + 1] == PathCommand::Close) { + roundTo = _roundCorner(path, prev, curr, inPts[2], r); + path.pts[startIndex] = path.pts.last(); + iPts += 3; + rounded = true; + continue; + } + } + path.cubicTo(rounded ? roundTo : inPts[iPts], inPts[iPts + 1], inPts[iPts + 2]); + iPts += 3; + break; + } + case PathCommand::Close: { + path.close(); + break; + } + default: break; + } + rounded = false; + } + if (transform) { + for (auto i = pivot; i < path.pts.count; ++i) { + path.pts[i] *= *transform; + } + } + + if (next) return next->modifyPath(path.cmds.data, path.cmds.count, path.pts.data, path.pts.count, transform, out); + + return true; +} + + +bool LottieRoundnessModifier::modifyPolystar(RenderPath& in, RenderPath& out, float outerRoundness, bool hasRoundness) +{ + constexpr auto ROUNDED_POLYSTAR_MAGIC_NUMBER = 0.47829f; + + buffer->clear(); + + auto& path = (next) ? *buffer : out; + + auto len = length(in.pts[1] - in.pts[2]); + auto r = len > 0.0f ? ROUNDED_POLYSTAR_MAGIC_NUMBER * std::min(len * 0.5f, this->r) / len : 0.0f; + + if (hasRoundness) { + path.cmds.grow((uint32_t)(1.5 * in.cmds.count)); + path.pts.grow((uint32_t)(4.5 * in.cmds.count)); + + int start = 3 * tvg::zero(outerRoundness); + path.moveTo(in.pts[start]); + + for (uint32_t i = 1 + start; i < in.pts.count; i += 6) { + auto& prev = in.pts[i]; + auto& curr = in.pts[i + 2]; + auto& next = (i < in.pts.count - start) ? in.pts[i + 4] : in.pts[2]; + auto& nextCtrl = (i < in.pts.count - start) ? in.pts[i + 5] : in.pts[3]; + auto dNext = r * (curr - next); + auto dPrev = r * (curr - prev); + + auto p0 = curr - 2.0f * dPrev; + auto p1 = curr - dPrev; + auto p2 = curr - dNext; + auto p3 = curr - 2.0f * dNext; + + path.cubicTo(prev, p0, p0); + path.cubicTo(p1, p2, p3); + path.cubicTo(p3, next, nextCtrl); + } + } else { + path.cmds.grow(2 * in.cmds.count); + path.pts.grow(4 * in.cmds.count); + + auto dPrev = r * (in.pts[1] - in.pts[0]); + auto p = in.pts[0] + 2.0f * dPrev; + path.moveTo(p); + + for (uint32_t i = 1; i < in.pts.count; ++i) { + auto& curr = in.pts[i]; + auto& next = (i == in.pts.count - 1) ? in.pts[1] : in.pts[i + 1]; + auto dNext = r * (curr - next); + + auto p0 = curr - 2.0f * dPrev; + auto p1 = curr - dPrev; + auto p2 = curr - dNext; + auto p3 = curr - 2.0f * dNext; + + path.lineTo(p0); + path.cubicTo(p1, p2, p3); + + dPrev = -1.0f * dNext; + } + } + path.cmds.push(PathCommand::Close); + + if (next) return next->modifyPolystar(path, out, outerRoundness, hasRoundness); + + return true; +} + + +bool LottieRoundnessModifier::modifyRect(Point& size, float& r) +{ + r = std::min(this->r, std::max(size.x, size.y) * 0.5f); + return true; +} + + +bool LottieOffsetModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, TVG_UNUSED Matrix* transform, RenderPath& out) +{ + if (next) TVGERR("LOTTIE", "Offset has a next modifier?"); + + out.cmds.reserve(inCmdsCnt * 2); + out.pts.reserve(inPtsCnt * (join == StrokeJoin::Round ? 4 : 2)); + + Array stack{5}; + State state; + auto offset = _clockwise(inPts, inPtsCnt) ? this->offset : -this->offset; + auto threshold = 1.0f / fabsf(offset) + 1.0f; + + for (uint32_t iCmd = 0, iPt = 0; iCmd < inCmdsCnt; ++iCmd) { + if (inCmds[iCmd] == PathCommand::MoveTo) { + state.moveto = true; + state.movetoInIndex = iPt++; + } else if (inCmds[iCmd] == PathCommand::LineTo) { + line(out, inCmds, inCmdsCnt, inPts, iPt, iCmd, state, offset, false); + } else if (inCmds[iCmd] == PathCommand::CubicTo) { + //cubic degenerated to a line + if (tvg::zero(inPts[iPt - 1] - inPts[iPt]) || tvg::zero(inPts[iPt + 1] - inPts[iPt + 2])) { + ++iPt; + line(out, inCmds, inCmdsCnt, inPts, iPt, iCmd, state, offset, true); + ++iPt; + continue; + } + + stack.push({inPts[iPt - 1], inPts[iPt], inPts[iPt + 1], inPts[iPt + 2]}); + while (!stack.empty()) { + auto& bezier = stack.last(); + auto len = tvg::length(bezier.start - bezier.ctrl1) + tvg::length(bezier.ctrl1 - bezier.ctrl2) + tvg::length(bezier.ctrl2 - bezier.end); + + if (len > threshold * bezier.length()) { + Bezier next; + bezier.split(0.5f, next); + stack.push(next); + continue; + } + stack.pop(); + + auto line1 = _offset(bezier.start, bezier.ctrl1, offset); + auto line2 = _offset(bezier.ctrl1, bezier.ctrl2, offset); + auto line3 = _offset(bezier.ctrl2, bezier.end, offset); + + if (state.moveto) { + state.movetoOutIndex = out.pts.count; + out.moveTo(line1.pt1); + state.firstLine = line1; + state.moveto = false; + } + + bool inside{}; + Point intersect{}; + _intersect(line1, line2, intersect, inside); + out.pts.push(intersect); + _intersect(line2, line3, intersect, inside); + out.pts.push(intersect); + out.pts.push(line3.pt2); + out.cmds.push(PathCommand::CubicTo); + } + + iPt += 3; + } + else { + if (!tvg::zero(inPts[iPt - 1] - inPts[state.movetoInIndex])) { + out.cmds.push(PathCommand::LineTo); + corner(out, state.line, state.firstLine, state.movetoOutIndex, true); + } + out.cmds.push(PathCommand::Close); + } + } + return true; +} + + +bool LottieOffsetModifier::modifyPolystar(RenderPath& in, RenderPath& out, TVG_UNUSED float, TVG_UNUSED bool) +{ + return modifyPath(in.cmds.data, in.cmds.count, in.pts.data, in.pts.count, nullptr, out); +} + + +bool LottieOffsetModifier::modifyRect(RenderPath& in, RenderPath& out) +{ + return modifyPath(in.cmds.data, in.cmds.count, in.pts.data, in.pts.count, nullptr, out); +} + + +bool LottieOffsetModifier::modifyEllipse(Point& radius) +{ + radius.x += offset; + radius.y += offset; + return true; +} diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieModifier.h b/components/thorvg-main/src/loaders/lottie/tvgLottieModifier.h new file mode 100644 index 0000000..b936743 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieModifier.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_MODIFIER_H_ +#define _TVG_LOTTIE_MODIFIER_H_ + +#include "tvgCommon.h" +#include "tvgArray.h" +#include "tvgMath.h" +#include "tvgRender.h" + + +struct LottieModifier +{ + enum Type : uint8_t {Roundness = 0, Offset}; + + LottieModifier* next = nullptr; + Type type; + + virtual ~LottieModifier() {} + + virtual bool modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, Matrix* transform, RenderPath& out) = 0; + virtual bool modifyPolystar(RenderPath& in, RenderPath& out, float outerRoundness, bool hasRoundness) = 0; + + LottieModifier* decorate(LottieModifier* next) + { + /* TODO: build the decorative chaining here. + currently we only have roundness and offset. */ + + //roundness -> offset + if (next->type == Roundness) { + next->next = this; + return next; + } + + //just in the order. + this->next = next; + return this; + } +}; + +struct LottieRoundnessModifier : LottieModifier +{ + static constexpr float ROUNDNESS_EPSILON = 1.0f; + + RenderPath* buffer; + float r; + + LottieRoundnessModifier(RenderPath* buffer, float r) : buffer(buffer), r(r) + { + type = Roundness; + } + + bool modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, Matrix* transform, RenderPath& out) override; + bool modifyPolystar(RenderPath& in, RenderPath& out, float outerRoundness, bool hasRoundness) override; + bool modifyRect(Point& size, float& r); +}; + + +struct LottieOffsetModifier : LottieModifier +{ + float offset; + float miterLimit; + StrokeJoin join; + + LottieOffsetModifier(float offset, float miter = 4.0f, StrokeJoin join = StrokeJoin::Round) : offset(offset), miterLimit(miter), join(join) + { + type = Offset; + } + + bool modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, Matrix* transform, RenderPath& out) override; + bool modifyPolystar(RenderPath& in, RenderPath& out, float outerRoundness, bool hasRoundness) override; + bool modifyRect(RenderPath& in, RenderPath& out); + bool modifyEllipse(Point& radius); + +private: + struct State + { + Line line{}; + Line firstLine{}; + bool moveto = false; + uint32_t movetoOutIndex = 0; + uint32_t movetoInIndex = 0; + }; + + void line(RenderPath& out, PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t& curPt, uint32_t curCmd, State& state, float offset, bool degenerated); + void corner(RenderPath& out, Line& line, Line& nextLine, uint32_t movetoIndex, bool nextClose); +}; + +#endif \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieParser.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieParser.cpp new file mode 100644 index 0000000..f2f68d4 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieParser.cpp @@ -0,0 +1,1749 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgStr.h" +#include "tvgCompressor.h" +#include "tvgLottieModel.h" +#include "tvgLottieParser.h" +#include "tvgLottieExpressions.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define KEY_AS(name) !strcmp(key, name) + + +static unsigned long _int2str(int num) +{ + char str[20]; + snprintf(str, 20, "%d", num); + return djb2Encode(str); +} + + +void LottieParser::getExpression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property) +{ + if (!comp->expressions) comp->expressions = true; + + auto inst = new LottieExpression; + inst->code = code; + inst->comp = comp; + inst->layer = layer; + inst->object = object; + inst->property = property; + + property->exp = inst; +} + + +LottieEffect* LottieParser::getEffect(int type) +{ + switch (type) { + case LottieEffect::Custom: return new LottieFxCustom; + case LottieEffect::Tint: return new LottieFxTint; + case LottieEffect::Fill: return new LottieFxFill; + case LottieEffect::Stroke: return new LottieFxStroke; + case LottieEffect::Tritone: return new LottieFxTritone; + case LottieEffect::DropShadow: return new LottieFxDropShadow; + case LottieEffect::GaussianBlur: return new LottieFxGaussianBlur; + default: return nullptr; + } +} + + +MaskMethod LottieParser::getMaskMethod(bool inversed) +{ + auto mode = getString(); + if (!mode) return MaskMethod::None; + + switch (mode[0]) { + case 'a': { + if (inversed) return MaskMethod::InvAlpha; + else return MaskMethod::Add; + } + case 's': { + if (inversed) return MaskMethod::Intersect; + return MaskMethod::Subtract; + } + case 'i': { + if (inversed) return MaskMethod::Difference; + return MaskMethod::Intersect; + } + case 'f': { + if (inversed) return MaskMethod::Intersect; + return MaskMethod::Difference; + } + case 'l': return MaskMethod::Lighten; + case 'd': return MaskMethod::Darken; + default: return MaskMethod::None; + } +} + + +RGB32 LottieParser::getColor(const char *str) +{ + RGB32 color = {0, 0, 0}; + + if (!str) return color; + + auto len = strlen(str); + + // some resource has empty color string, return a default color for those cases. + if (len != 7 || str[0] != '#') return color; + + char tmp[3] = {'\0', '\0', '\0'}; + tmp[0] = str[1]; + tmp[1] = str[2]; + color.r = uint8_t(strtol(tmp, nullptr, 16)); + + tmp[0] = str[3]; + tmp[1] = str[4]; + color.g = uint8_t(strtol(tmp, nullptr, 16)); + + tmp[0] = str[5]; + tmp[1] = str[6]; + color.b = uint8_t(strtol(tmp, nullptr, 16)); + + return color; +} + + +bool LottieParser::getValue(TextDocument& doc) +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("s")) doc.size = getFloat() * 0.01f; + else if (KEY_AS("f")) doc.name = getStringCopy(); + else if (KEY_AS("t")) doc.text = getStringCopy(); + else if (KEY_AS("j")) + { + auto val = getInt(); + if (val == 1) doc.justify = -1.0f; //right align + else if (val == 2) doc.justify = -0.5f; //center align + } + else if (KEY_AS("ca")) doc.caps = getInt(); + else if (KEY_AS("tr")) doc.tracking = getFloat() * 0.1f; + else if (KEY_AS("lh")) doc.height = getFloat(); + else if (KEY_AS("ls")) doc.shift = getFloat(); + else if (KEY_AS("fc")) getValue(doc.color); + else if (KEY_AS("ps")) getValue(doc.bbox.pos); + else if (KEY_AS("sz")) getValue(doc.bbox.size); + else if (KEY_AS("sc")) getValue(doc.stroke.color); + else if (KEY_AS("sw")) doc.stroke.width = getFloat(); + else if (KEY_AS("of")) doc.stroke.below = !getBool(); + else skip(); + } + return false; +} + + +bool LottieParser::getValue(PathSet& path) +{ + Array outs, ins, pts; + bool closed = false; + + /* The shape object could be wrapped by a array + if its part of the keyframe object */ + auto arrayWrapper = (peekType() == kArrayType) ? true : false; + if (arrayWrapper) enterArray(); + + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("i")) getValue(ins); + else if (KEY_AS("o")) getValue(outs); + else if (KEY_AS("v")) getValue(pts); + else if (KEY_AS("c")) closed = getBool(); + else skip(); + } + + //exit properly from the array + if (arrayWrapper) nextArrayValue(); + + //valid path data? + if (ins.empty() || outs.empty() || pts.empty()) return false; + if (ins.count != outs.count || outs.count != pts.count) return false; + + //convert path + auto out = outs.begin(); + auto in = ins.begin(); + auto pt = pts.begin(); + + //Store manipulated results + RenderPath temp; + + //Reuse the buffers + temp.pts.data = path.pts; + temp.pts.reserved = path.ptsCnt; + temp.cmds.data = path.cmds; + temp.cmds.reserved = path.cmdsCnt; + + size_t extra = closed ? 3 : 0; + temp.pts.reserve(pts.count * 3 + 1 + extra); + temp.cmds.reserve(pts.count + 2); + + temp.moveTo(*pt); + + for (++pt, ++out, ++in; pt < pts.end(); ++pt, ++out, ++in) { + temp.cubicTo(*(pt - 1) + *(out - 1), *pt + *in, *pt); + } + + if (closed) { + temp.cubicTo(pts.last() + outs.last(), pts.first() + ins.first(), pts.first()); + temp.close(); + } + + path.pts = temp.pts.data; + path.cmds = temp.cmds.data; + path.ptsCnt = temp.pts.count; + path.cmdsCnt = temp.cmds.count; + + temp.pts.data = nullptr; + temp.cmds.data = nullptr; + + return false; +} + + +bool LottieParser::getValue(ColorStop& color) +{ + if (peekType() == kArrayType) { + enterArray(); + if (!nextArrayValue()) return true; + } + + if (!color.input) color.input = new Array(static_cast(context.parent)->colorStops.count * 6); + else color.input->clear(); + + do color.input->push(getFloat()); + while (nextArrayValue()); + + return true; +} + + +bool LottieParser::getValue(Array& pts) +{ + Point pt{}; + enterArray(); + while (nextArrayValue()) { + enterArray(); + getValue(pt); + pts.push(pt); + } + return false; +} + + +bool LottieParser::getValue(int8_t& val) +{ + if (peekType() == kArrayType) { + enterArray(); + if (nextArrayValue()) val = getInt(); + //discard rest + while (nextArrayValue()) getInt(); + } else { + val = (int8_t) getFloat(); + } + return false; +} + + +bool LottieParser::getValue(uint8_t& val) +{ + if (peekType() == kArrayType) { + enterArray(); + if (nextArrayValue()) val = (uint8_t)(getFloat() * 2.55f); + //discard rest + while (nextArrayValue()) getFloat(); + } else { + val = (uint8_t)(getFloat() * 2.55f); + } + return false; +} + + +bool LottieParser::getValue(float& val) +{ + if (peekType() == kArrayType) { + enterArray(); + if (nextArrayValue()) val = getFloat(); + //discard rest + while (nextArrayValue()) getFloat(); + } else { + val = getFloat(); + } + return false; +} + + +bool LottieParser::getValue(Point& pt) +{ + if (peekType() == kNullType) return false; + if (peekType() == kArrayType) { + enterArray(); + if (!nextArrayValue()) return false; + } + + pt.x = getFloat(); + pt.y = getFloat(); + + while (nextArrayValue()) getFloat(); //drop + + return true; +} + + +bool LottieParser::getValue(RGB32& color) +{ + if (peekType() == kArrayType) { + enterArray(); + if (!nextArrayValue()) return false; + } + + color.r = REMAP255(getFloat()); + color.g = REMAP255(getFloat()); + color.b = REMAP255(getFloat()); + + while (nextArrayValue()) getFloat(); //drop + + //TODO: color filter? + + return true; +} + + +void LottieParser::getInterpolatorPoint(Point& pt) +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("x")) getValue(pt.x); + else if (KEY_AS("y")) getValue(pt.y); + } +} + + +template +void LottieParser::parseSlotProperty(T& prop) +{ + while (auto key = nextObjectKey()) { + if (KEY_AS("p")) parseProperty(prop); + else skip(); + } +} + + +template +bool LottieParser::parseTangent(const char *key, LottieVectorFrame& value) +{ + if (KEY_AS("ti") && getValue(value.inTangent)) ; + else if (KEY_AS("to") && getValue(value.outTangent)) ; + else return false; + + value.hasTangent = true; + return true; +} + + +template +bool LottieParser::parseTangent(const char *key, LottieScalarFrame& value) +{ + return false; +} + + +LottieInterpolator* LottieParser::getInterpolator(const char* key, Point& in, Point& out) +{ + char buf[20]; + + if (!key) { + snprintf(buf, sizeof(buf), "%.2f_%.2f_%.2f_%.2f", (double)in.x, (double)in.y, (double)out.x, (double)out.y); + key = buf; + } + + LottieInterpolator* interpolator = nullptr; + + //get a cached interpolator if it has any. + ARRAY_FOREACH(p, comp->interpolators) { + if (!strncmp((*p)->key, key, sizeof(buf))) interpolator = *p; + } + + //new interpolator + if (!interpolator) { + interpolator = tvg::malloc(sizeof(LottieInterpolator)); + interpolator->set(key, in, out); + comp->interpolators.push(interpolator); + } + + return interpolator; +} + + +template +void LottieParser::parseKeyFrame(T& prop) +{ + Point inTangent, outTangent; + const char* interpolatorKey = nullptr; + auto& frame = prop.newFrame(); + auto interpolator = false; + + enterObject(); + + while (auto key = nextObjectKey()) { + if (KEY_AS("i")) { + interpolator = true; + getInterpolatorPoint(inTangent); + } else if (KEY_AS("o")) { + getInterpolatorPoint(outTangent); + } else if (KEY_AS("n")) { + if (peekType() == kStringType) { + interpolatorKey = getString(); + } else { + enterArray(); + while (nextArrayValue()) { + if (!interpolatorKey) interpolatorKey = getString(); + else skip(); + } + } + } else if (KEY_AS("t")) { + frame.no = getFloat(); + } else if (KEY_AS("s")) { + getValue(frame.value); + } else if (KEY_AS("e")) { + //current end frame and the next start frame is duplicated, + //We propagate the end value to the next frame to avoid having duplicated values. + auto& frame2 = prop.nextFrame(); + getValue(frame2.value); + } else if (parseTangent(key, frame)) { + continue; + } else if (KEY_AS("h")) { + frame.hold = getInt(); + } else skip(); + } + + if (interpolator) { + frame.interpolator = getInterpolator(interpolatorKey, inTangent, outTangent); + } +} + +template +void LottieParser::parsePropertyInternal(T& prop) +{ + //single value property + if (peekType() == kNumberType) { + getValue(prop.value); + //multi value property + } else { + enterArray(); + while (nextArrayValue()) { + if (peekType() == kObjectType) parseKeyFrame(prop); //keyframes value + else if (getValue(prop.value)) break; //multi value property with no keyframes + } + prop.prepare(); + } +} + + +void LottieParser::registerSlot(LottieObject* obj, const char* sid, LottieProperty::Type type) +{ + auto val = djb2Encode(sid); + + //append object if the slot already exists. + ARRAY_FOREACH(p, comp->slots) { + if ((*p)->sid != val) continue; + (*p)->pairs.push({obj}); + return; + } + comp->slots.push(new LottieSlot(context.layer, context.parent, val, obj, type)); +} + + +template +void LottieParser::parseProperty(T& prop, LottieObject* obj) +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("k")) parsePropertyInternal(prop); + else if (parseCommon(obj, prop, key)) continue; + else skip(); + } +} + + +bool LottieParser::parseCommon(LottieObject* obj, const char* key) +{ + if (KEY_AS("nm")) { + obj->id = djb2Encode(getString()); + return true; + } else if (KEY_AS("hd")) { + obj->hidden = getBool(); + return true; + } else return false; +} + + +bool LottieParser::parseCommon(LottieObject* obj, LottieProperty& prop, const char* key) +{ + if (KEY_AS("ix")) { + prop.ix = getInt(); + return true; + } else if (KEY_AS("x") && expressions) { + getExpression(getStringCopy(), comp, context.layer, context.parent, &prop); + return true; + } else if (KEY_AS("sid")) { + registerSlot(obj, getString(), prop.type); + return true; + } else return false; +} + + +bool LottieParser::parseDirection(LottieShape* shape, const char* key) +{ + if (KEY_AS("d")) { + if (getInt() == 3) { + shape->clockwise = false; //default is true + } + return true; + } + return false; +} + + +LottieRect* LottieParser::parseRect() +{ + auto rect = new LottieRect; + + context.parent = rect; + + while (auto key = nextObjectKey()) { + if (parseCommon(rect, key)) continue; + else if (KEY_AS("s")) parseProperty(rect->size); + else if (KEY_AS("p")) parseProperty(rect->position); + else if (KEY_AS("r")) parseProperty(rect->radius); + else if (parseDirection(rect, key)) continue; + else skip(); + } + return rect; +} + + +LottieEllipse* LottieParser::parseEllipse() +{ + auto ellipse = new LottieEllipse; + + context.parent = ellipse; + + while (auto key = nextObjectKey()) { + if (parseCommon(ellipse, key)) continue; + else if (KEY_AS("p")) parseProperty(ellipse->position); + else if (KEY_AS("s")) parseProperty(ellipse->size); + else if (parseDirection(ellipse, key)) continue; + else skip(); + } + return ellipse; +} + + +LottieTransform* LottieParser::parseTransform(bool ddd) +{ + auto transform = new LottieTransform; + + context.parent = transform; + + if (ddd) { + transform->rotationEx = new LottieTransform::RotationEx; + TVGLOG("LOTTIE", "3D transform(ddd) is not totally compatible."); + } + + while (auto key = nextObjectKey()) { + if (parseCommon(transform, key)) continue; + else if (KEY_AS("p")) + { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("k")) parsePropertyInternal(transform->position); + else if (KEY_AS("x")) //must be prior to parseCommon() + { + //check separateCoord to figure out whether "x(expression)" / "x(coord)" + if (peekType() == kStringType) { + if (expressions) getExpression(getStringCopy(), comp, context.layer, context.parent, &transform->position); + else skip(); + } else parseProperty(transform->separateCoord()->x); + } + else if (KEY_AS("y")) parseProperty(transform->separateCoord()->y); + else if (parseCommon(transform, transform->position, key)) continue; + else skip(); + } + } + else if (KEY_AS("a")) parseProperty(transform->anchor); + else if (KEY_AS("s")) parseProperty(transform->scale, transform); + else if (KEY_AS("r")) parseProperty(transform->rotation, transform); + else if (KEY_AS("o")) parseProperty(transform->opacity, transform); + else if (transform->rotationEx && KEY_AS("rx")) parseProperty(transform->rotationEx->x); + else if (transform->rotationEx && KEY_AS("ry")) parseProperty(transform->rotationEx->y); + else if (transform->rotationEx && KEY_AS("rz")) parseProperty(transform->rotation); + else if (KEY_AS("sk")) parseProperty(transform->skewAngle); + else if (KEY_AS("sa")) parseProperty(transform->skewAxis); + else skip(); + } + return transform; +} + + +LottieSolidFill* LottieParser::parseSolidFill() +{ + auto fill = new LottieSolidFill; + + context.parent = fill; + + while (auto key = nextObjectKey()) { + if (parseCommon(fill, key)) continue; + else if (KEY_AS("c")) parseProperty(fill->color, fill); + else if (KEY_AS("o")) parseProperty(fill->opacity, fill); + else if (KEY_AS("fillEnabled")) fill->hidden |= !getBool(); + else if (KEY_AS("r")) fill->rule = (getInt() == 1) ? FillRule::NonZero : FillRule::EvenOdd; + else skip(); + } + return fill; +} + + +void LottieParser::parseStrokeDash(LottieStroke* stroke) +{ + enterArray(); + while (nextArrayValue()) { + enterObject(); + const char* style = nullptr; + while (auto key = nextObjectKey()) { + if (KEY_AS("n")) style = getString(); + else if (KEY_AS("v")) { + if (style && !strcmp("o", style)) parseProperty(stroke->dashOffset()); + else parseProperty(stroke->dashValue()); + } else skip(); + } + } +} + + +LottieSolidStroke* LottieParser::parseSolidStroke() +{ + auto stroke = new LottieSolidStroke; + + context.parent = stroke; + + while (auto key = nextObjectKey()) { + if (parseCommon(stroke, key)) continue; + else if (KEY_AS("c")) parseProperty(stroke->color, stroke); + else if (KEY_AS("o")) parseProperty(stroke->opacity, stroke); + else if (KEY_AS("w")) parseProperty(stroke->width, stroke); + else if (KEY_AS("lc")) stroke->cap = (StrokeCap) (getInt() - 1); + else if (KEY_AS("lj")) stroke->join = (StrokeJoin) (getInt() - 1); + else if (KEY_AS("ml")) stroke->miterLimit = getFloat(); + else if (KEY_AS("fillEnabled")) stroke->hidden |= !getBool(); + else if (KEY_AS("d")) parseStrokeDash(stroke); + else skip(); + } + return stroke; +} + + +void LottieParser::getPathSet(LottiePath* obj, LottiePathSet& path) +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("k")) + { + if (peekType() == kArrayType) { + enterArray(); + while (nextArrayValue()) parseKeyFrame(path); + } else { + getValue(path.value); + } + } + else if (parseCommon(obj, path, key)) continue; + else skip(); + } +} + + +LottiePath* LottieParser::parsePath() +{ + auto path = new LottiePath; + + while (auto key = nextObjectKey()) { + if (parseCommon(path, key)) continue; + else if (KEY_AS("ks")) getPathSet(path, path->pathset); + else if (parseDirection(path, key)) continue; + else skip(); + } + return path; +} + + +LottiePolyStar* LottieParser::parsePolyStar() +{ + auto star = new LottiePolyStar; + + context.parent = star; + + while (auto key = nextObjectKey()) { + if (parseCommon(star, key)) continue; + else if (KEY_AS("p")) parseProperty(star->position); + else if (KEY_AS("pt")) parseProperty(star->ptsCnt); + else if (KEY_AS("ir")) parseProperty(star->innerRadius); + else if (KEY_AS("is")) parseProperty(star->innerRoundness); + else if (KEY_AS("or")) parseProperty(star->outerRadius); + else if (KEY_AS("os")) parseProperty(star->outerRoundness); + else if (KEY_AS("r")) parseProperty(star->rotation); + else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt(); + else if (parseDirection(star, key)) continue; + else skip(); + } + return star; +} + + +LottieRoundedCorner* LottieParser::parseRoundedCorner() +{ + auto corner = new LottieRoundedCorner; + + context.parent = corner; + + while (auto key = nextObjectKey()) { + if (parseCommon(corner, key)) continue; + else if (KEY_AS("r")) parseProperty(corner->radius); + else skip(); + } + return corner; +} + + +void LottieParser::parseColorStop(LottieGradient* gradient) +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("p")) gradient->colorStops.count = getInt(); + else if (KEY_AS("k")) parseProperty(gradient->colorStops, gradient); + else if (parseCommon(gradient, gradient->colorStops, key)) continue; + else skip(); + } +} + + +void LottieParser::parseGradient(LottieGradient* gradient, const char* key) +{ + if (KEY_AS("t")) gradient->id = getInt(); + else if (KEY_AS("o")) parseProperty(gradient->opacity, gradient); + else if (KEY_AS("g")) parseColorStop(gradient); + else if (KEY_AS("s")) parseProperty(gradient->start, gradient); + else if (KEY_AS("e")) parseProperty(gradient->end, gradient); + else if (KEY_AS("h")) parseProperty(gradient->height, gradient); + else if (KEY_AS("a")) parseProperty(gradient->angle, gradient); + else skip(); +} + + +LottieGradientFill* LottieParser::parseGradientFill() +{ + auto fill = new LottieGradientFill; + + context.parent = fill; + + while (auto key = nextObjectKey()) { + if (parseCommon(fill, key)) continue; + else if (KEY_AS("r")) fill->rule = (getInt() == 1) ? FillRule::NonZero : FillRule::EvenOdd; + else parseGradient(fill, key); + } + + fill->prepare(); + + return fill; +} + + +LottieGradientStroke* LottieParser::parseGradientStroke() +{ + auto stroke = new LottieGradientStroke; + + context.parent = stroke; + + while (auto key = nextObjectKey()) { + if (parseCommon(stroke, key)) continue; + else if (KEY_AS("lc")) stroke->cap = (StrokeCap) (getInt() - 1); + else if (KEY_AS("lj")) stroke->join = (StrokeJoin) (getInt() - 1); + else if (KEY_AS("ml")) stroke->miterLimit = getFloat(); + else if (KEY_AS("w")) parseProperty(stroke->width); + else if (KEY_AS("d")) parseStrokeDash(stroke); + else parseGradient(stroke, key); + } + stroke->prepare(); + + return stroke; +} + + +LottieTrimpath* LottieParser::parseTrimpath() +{ + auto trim = new LottieTrimpath; + + context.parent = trim; + + while (auto key = nextObjectKey()) { + if (parseCommon(trim, key)) continue; + else if (KEY_AS("s")) parseProperty(trim->start); + else if (KEY_AS("e")) parseProperty(trim->end); + else if (KEY_AS("o")) parseProperty(trim->offset); + else if (KEY_AS("m")) trim->type = static_cast(getInt()); + else skip(); + } + return trim; +} + + +LottieRepeater* LottieParser::parseRepeater() +{ + auto repeater = new LottieRepeater; + + context.parent = repeater; + + while (auto key = nextObjectKey()) { + if (parseCommon(repeater, key)) continue; + else if (KEY_AS("c")) parseProperty(repeater->copies); + else if (KEY_AS("o")) parseProperty(repeater->offset); + else if (KEY_AS("m")) repeater->inorder = getInt() == 2; + else if (KEY_AS("tr")) + { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("a")) parseProperty(repeater->anchor); + else if (KEY_AS("p")) parseProperty(repeater->position); + else if (KEY_AS("r")) parseProperty(repeater->rotation); + else if (KEY_AS("s")) parseProperty(repeater->scale); + else if (KEY_AS("so")) parseProperty(repeater->startOpacity); + else if (KEY_AS("eo")) parseProperty(repeater->endOpacity); + else skip(); + } + } + else skip(); + } + return repeater; +} + + +LottieOffsetPath* LottieParser::parseOffsetPath() +{ + auto offsetPath = new LottieOffsetPath; + + context.parent = offsetPath; + + while (auto key = nextObjectKey()) { + if (parseCommon(offsetPath, key)) continue; + else if (KEY_AS("a")) parseProperty(offsetPath->offset); + else if (KEY_AS("lj")) offsetPath->join = (StrokeJoin) (getInt() - 1); + else if (KEY_AS("ml")) parseProperty(offsetPath->miterLimit); + else skip(); + } + return offsetPath; +} + + +LottieObject* LottieParser::parseObject(const char* type) +{ + if (!strcmp(type, "gr")) return parseGroup(); + else if (!strcmp(type, "rc")) return parseRect(); + else if (!strcmp(type, "el")) return parseEllipse(); + else if (!strcmp(type, "tr")) return parseTransform(); + else if (!strcmp(type, "fl")) return parseSolidFill(); + else if (!strcmp(type, "st")) return parseSolidStroke(); + else if (!strcmp(type, "sh")) return parsePath(); + else if (!strcmp(type, "sr")) return parsePolyStar(); + else if (!strcmp(type, "rd")) return parseRoundedCorner(); + else if (!strcmp(type, "gf")) return parseGradientFill(); + else if (!strcmp(type, "gs")) return parseGradientStroke(); + else if (!strcmp(type, "tm")) return parseTrimpath(); + else if (!strcmp(type, "rp")) return parseRepeater(); + else if (!strcmp(type, "mm")) TVGLOG("LOTTIE", "MergePath(mm) is not supported yet"); + else if (!strcmp(type, "pb")) TVGLOG("LOTTIE", "Puker/Bloat(pb) is not supported yet"); + else if (!strcmp(type, "tw")) TVGLOG("LOTTIE", "Twist(tw) is not supported yet"); + else if (!strcmp(type, "op")) return parseOffsetPath(); + else if (!strcmp(type, "zz")) TVGLOG("LOTTIE", "ZigZag(zz) is not supported yet"); + return nullptr; +} + + +//capture the type name if the upcoming type is irregularly addressed after the actual properties. +char* LottieParser::captureType() +{ + if (!isPrimitive() || !strcmp(val.GetString(), "ty")) return nullptr; + + auto level = 0; + for (auto p = getPos(); *p != '\0'; ++p) { + if (*p == '{') level++; + else if (*p == '}') { + if (--level < 0) break; + } else if (level == 0) { + if (!strncmp(p, "\"ty\"", 4)) { + p += 4; + while (*p != '\0' && (isspace(*p) || *p == '\n')) ++p; + if (*p++ != ':') return nullptr; + while (*p != '\0' && (isspace(*p) || *p == '\n')) ++p; + if (*p++ != '\"') return nullptr; + const char* start = p; + while (*p != '\0' && *p != '\"') ++p; + if (*p == '\"') return tvg::duplicate(start, p - start); + return nullptr; + } + } + } + return nullptr; +} + + +void LottieParser::parseObject(Array& parent) +{ + enterObject(); + + auto type = captureType(); + auto freeType = false; + + if (!type) { + if (auto key = nextObjectKey()) { + if (KEY_AS("ty")) type = (char*)getString(); + else skip(); + } + } else freeType = true; + + if (type) { + if (auto child = parseObject(type)) { + if (child->hidden) delete(child); + else parent.push(child); + } + } + + if (freeType) tvg::free(type); + + while(nextObjectKey()) skip(); +} + + +void LottieParser::parseImage(LottieImage* image, const char* data, const char* subPath, bool embedded, float width, float height) +{ + //embedded image resource. should start with "data:" + //header look like "data:image/png;base64," so need to skip till ','. + if (embedded && !strncmp(data, "data:", 5)) { + //figure out the mimetype + auto mimeType = data + 11; + auto needle = strstr(mimeType, ";"); + image->bitmap.mimeType = duplicate(mimeType, needle - mimeType); + //b64 data + auto b64Data = strstr(data, ",") + 1; + size_t length = strlen(data) - (b64Data - data); + image->bitmap.size = b64Decode(b64Data, length, &image->bitmap.data); + //external image resource + } else { + auto len = strlen(dirName) + strlen(subPath) + strlen(data) + 2; + image->bitmap.path = tvg::malloc(len); + snprintf(image->bitmap.path, len, "%s/%s%s", dirName, subPath, data); + } + + image->bitmap.width = width; + image->bitmap.height = height; + image->prepare(); +} + + +LottieObject* LottieParser::parseAsset() +{ + enterObject(); + + LottieObject* obj = nullptr; + unsigned long id = 0; + + //Used for Image Asset + const char* sid = nullptr; + const char* data = nullptr; + const char* subPath = nullptr; + float width = 0.0f; + float height = 0.0f; + auto embedded = false; + + while (auto key = nextObjectKey()) { + if (KEY_AS("id")) + { + if (peekType() == kStringType) { + id = djb2Encode(getString()); + } else { + id = _int2str(getInt()); + } + } + else if (KEY_AS("layers")) obj = parseLayers(comp->root); + else if (KEY_AS("u")) subPath = getString(); + else if (KEY_AS("p")) data = getString(); + else if (KEY_AS("w")) width = getFloat(); + else if (KEY_AS("h")) height = getFloat(); + else if (KEY_AS("e")) embedded = getInt(); + else if (KEY_AS("sid")) sid = getString(); + else skip(); + } + if (data) { + obj = new LottieImage; + parseImage(static_cast(obj), data, subPath, embedded, width, height); + if (sid) registerSlot(obj, sid, LottieProperty::Type::Image); + } + if (obj) obj->id = id; + return obj; +} + + +void LottieParser::parseFontData(LottieFont* font, const char* data) +{ + if (!data) return; + + //handle base64 font data + if (!strncmp(data, "data:font/", sizeof("data:font/") - 1)) { + data += sizeof("data:font/") - 1; + if (!strncmp(data, "ttf", 3)) { + data += 3; + } else { + TVGLOG("LOTTIE", "TODO: Support a new font type!"); + return; + } + data += sizeof(";base64,") - 1; + font->size = b64Decode(data, strlen(data), &font->b64src); + //external font resource + } else { + font->path = duplicate(data); + } +} + + +LottieFont* LottieParser::parseFont() +{ + enterObject(); + + auto font = new LottieFont; + + while (auto key = nextObjectKey()) { + if (KEY_AS("fName")) font->name = getStringCopy(); + else if (KEY_AS("fFamily")) font->family = getStringCopy(); + else if (KEY_AS("fStyle")) font->style = getStringCopy(); + else if (KEY_AS("fPath")) parseFontData(font, getString()); + else if (KEY_AS("ascent")) font->ascent = getFloat(); + else if (KEY_AS("origin")) font->origin = (LottieFont::Origin) getInt(); + else skip(); + } + + font->prepare(); + return font; +} + + +void LottieParser::parseAssets() +{ + enterArray(); + while (nextArrayValue()) { + auto asset = parseAsset(); + if (asset) comp->assets.push(asset); + else TVGERR("LOTTIE", "Invalid Asset!"); + } +} + +LottieMarker* LottieParser::parseMarker() +{ + enterObject(); + + auto marker = new LottieMarker; + + while (auto key = nextObjectKey()) { + if (KEY_AS("cm")) marker->name = getStringCopy(); + else if (KEY_AS("tm")) marker->time = getFloat(); + else if (KEY_AS("dr")) marker->duration = getFloat(); + else skip(); + } + + return marker; +} + +void LottieParser::parseMarkers() +{ + enterArray(); + while (nextArrayValue()) { + comp->markers.push(parseMarker()); + } +} + +void LottieParser::parseChars(Array& glyphs) +{ + enterArray(); + while (nextArrayValue()) { + enterObject(); + //a new glyph + auto glyph = new LottieGlyph; + while (auto key = nextObjectKey()) { + if (KEY_AS("ch")) glyph->code = getStringCopy(); + else if (KEY_AS("size")) glyph->size = static_cast(getFloat()); + else if (KEY_AS("style")) glyph->style = getStringCopy(); + else if (KEY_AS("w")) glyph->width = getFloat(); + else if (KEY_AS("fFamily")) glyph->family = getStringCopy(); + else if (KEY_AS("data")) + { //glyph shapes + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("shapes")) parseShapes(glyph->children); + } + } else skip(); + } + glyph->prepare(); + glyphs.push(glyph); + } +} + +void LottieParser::parseFonts() +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("list")) { + enterArray(); + while (nextArrayValue()) { + comp->fonts.push(parseFont()); + } + } else skip(); + } +} + + +LottieObject* LottieParser::parseGroup() +{ + auto group = new LottieGroup; + + while (auto key = nextObjectKey()) { + if (parseCommon(group, key)) continue; + else if (KEY_AS("it")) { + enterArray(); + while (nextArrayValue()) parseObject(group->children); + } else if (KEY_AS("bm")) { + group->blendMethod = (BlendMethod) getInt(); + } else skip(); + } + group->prepare(); + + return group; +} + + +void LottieParser::parseTimeRemap(LottieLayer* layer) +{ + parseProperty(layer->timeRemap); +} + + +void LottieParser::parseShapes(Array& parent) +{ + enterArray(); + while (nextArrayValue()) parseObject(parent); +} + + +void LottieParser::parseTextAlignmentOption(LottieText* text) +{ + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("g")) text->alignOp.group = (LottieText::AlignOption::Group) getInt(); + else if (KEY_AS("a")) parseProperty(text->alignOp.anchor); + else skip(); + } +} + + +void LottieParser::parseTextRange(LottieText* text) +{ + enterArray(); + while (nextArrayValue()) { + enterObject(); + + auto selector = new LottieTextRange; + + while (auto key = nextObjectKey()) { + if (KEY_AS("s")) { // text range selector + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("t")) selector->expressible = (bool) getInt(); + else if (KEY_AS("xe")) + { + parseProperty(selector->maxEase); + selector->interpolator = tvg::malloc(sizeof(LottieInterpolator)); + } + else if (KEY_AS("ne")) parseProperty(selector->minEase); + else if (KEY_AS("a")) parseProperty(selector->maxAmount); + else if (KEY_AS("b")) selector->based = (LottieTextRange::Based) getInt(); + else if (KEY_AS("rn")) selector->random = getInt() ? rand() : 0; + else if (KEY_AS("sh")) selector->shape = (LottieTextRange::Shape) getInt(); + else if (KEY_AS("o")) parseProperty(selector->offset); + else if (KEY_AS("r")) selector->rangeUnit = (LottieTextRange::Unit) getInt(); + else if (KEY_AS("sm")) parseProperty(selector->smoothness); + else if (KEY_AS("s")) parseProperty(selector->start); + else if (KEY_AS("e")) parseProperty(selector->end); + else skip(); + } + } else if (KEY_AS("a")) { // text style + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("t")) parseProperty(selector->style.letterSpace); + else if (KEY_AS("ls")) parseProperty(selector->style.lineSpace); + else if (KEY_AS("fc")) + { + parseProperty(selector->style.fillColor); + selector->style.flags.fillColor = true; + } + else if (KEY_AS("fo")) parseProperty(selector->style.fillOpacity); + else if (KEY_AS("sw")) + { + parseProperty(selector->style.strokeWidth); + selector->style.flags.strokeWidth = true; + } + else if (KEY_AS("sc")) + { + parseProperty(selector->style.strokeColor); + selector->style.flags.strokeColor = true; + } + else if (KEY_AS("so")) parseProperty(selector->style.strokeOpacity); + else if (KEY_AS("o")) parseProperty(selector->style.opacity); + else if (KEY_AS("p")) parseProperty(selector->style.position); + else if (KEY_AS("s")) parseProperty(selector->style.scale); + else if (KEY_AS("r")) parseProperty(selector->style.rotation); + else skip(); + } + } else skip(); + } + + text->ranges.push(selector); + } +} + + +void LottieParser::parseTextFollowPath(LottieText* text) +{ + enterObject(); + auto key = nextObjectKey(); + if (!key) return; + if (!text->follow) text->follow = new LottieTextFollowPath; + do { + if (KEY_AS("m")) text->follow->maskIdx = getInt(); + else if (KEY_AS("f")) parseProperty(text->follow->firstMargin); + else skip(); + } while ((key = nextObjectKey())); +} + + +void LottieParser::parseText(Array& parent) +{ + enterObject(); + + auto text = new LottieText; + + while (auto key = nextObjectKey()) { + if (KEY_AS("d")) parseProperty(text->doc, text); + else if (KEY_AS("a")) parseTextRange(text); + else if (KEY_AS("m")) parseTextAlignmentOption(text); + else if (KEY_AS("p")) parseTextFollowPath(text); + else skip(); + } + parent.push(text); +} + + +void LottieParser::getLayerSize(float& val) +{ + if (val == 0.0f) { + val = getFloat(); + } else { + //layer might have both w(width) & sw(solid color width) + //override one if the a new size is smaller. + auto w = getFloat(); + if (w < val) val = w; + } +} + +LottieMask* LottieParser::parseMask() +{ + auto mask = new LottieMask; + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("inv")) mask->inverse = getBool(); + else if (KEY_AS("mode")) mask->method = getMaskMethod(mask->inverse); + else if (KEY_AS("pt")) getPathSet(nullptr, mask->pathset); + else if (KEY_AS("o")) parseProperty(mask->opacity); + else if (KEY_AS("x")) parseProperty(mask->expand); + else skip(); + } + return mask; +} + + +void LottieParser::parseMasks(LottieLayer* layer) +{ + enterArray(); + while (nextArrayValue()) { + if (auto mask = parseMask()) { + layer->masks.push(mask); + } + } +} + + +bool LottieParser::parseEffect(LottieEffect* effect, void(LottieParser::*func)(LottieEffect*, int)) +{ + //custom effect expects dynamic property allocations + auto custom = (effect->type == LottieEffect::Custom) ? true : false; + LottieFxCustom::Property* property = nullptr; + + enterArray(); + int idx = 0; + while (nextArrayValue()) { + enterObject(); + while (auto key = nextObjectKey()) { + if (custom && KEY_AS("ty")) property = static_cast(effect)->property(getInt()); + else if (KEY_AS("v")) + { + if (peekType() == kObjectType) { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("k")) (this->*func)(effect, idx++); + else skip(); + } + } else (this->*func)(effect, idx++); + } + else if (property && KEY_AS("nm")) property->nm = djb2Encode(getString()); + else if (property && KEY_AS("mn")) property->mn = djb2Encode(getString()); + else skip(); + } + } + return true; +} + + +void LottieParser::parseCustom(LottieEffect* effect, int idx) +{ + if ((uint32_t)idx >= static_cast(effect)->props.count) { + TVGERR("LOTTIE", "Parsing error in Custom effect!"); + skip(); + return; + } + + auto prop = static_cast(effect)->props[idx].property; + + switch (prop->type) { + case LottieProperty::Type::Integer: { + parsePropertyInternal(*static_cast(prop)); break; + } + case LottieProperty::Type::Float: { + parsePropertyInternal(*static_cast(prop)); break; + } + case LottieProperty::Type::Vector: { + parsePropertyInternal(*static_cast(prop)); break; + } + case LottieProperty::Type::Color: { + parsePropertyInternal(*static_cast(prop)); break; + } + default: { + TVGLOG("LOTTIE", "Missing Property Type? = %d", (int) prop->type); + skip(); + } + } +} + + +void LottieParser::parseTint(LottieEffect* effect, int idx) +{ + auto tint = static_cast(effect); + + if (idx == 0) parsePropertyInternal(tint->black); + else if (idx == 1) parsePropertyInternal(tint->white); + else if (idx == 2) parsePropertyInternal(tint->intensity); + else skip(); +} + + +void LottieParser::parseTritone(LottieEffect* effect, int idx) +{ + auto tritone = static_cast(effect); + + if (idx == 0) parsePropertyInternal(tritone->bright); + else if (idx == 1) parsePropertyInternal(tritone->midtone); + else if (idx == 2) parsePropertyInternal(tritone->dark); + else if (idx == 3) parsePropertyInternal(tritone->blend); + else skip(); +} + + +void LottieParser::parseFill(LottieEffect* effect, int idx) +{ + auto fill = static_cast(effect); + + if (idx == 2) parsePropertyInternal(fill->color); + else if (idx == 6) parsePropertyInternal(fill->opacity); + else skip(); +} + + +void LottieParser::parseGaussianBlur(LottieEffect* effect, int idx) +{ + auto blur = static_cast(effect); + + if (idx == 0) parsePropertyInternal(blur->blurness); + else if (idx == 1) parsePropertyInternal(blur->direction); + else if (idx == 2) parsePropertyInternal(blur->wrap); + else skip(); +} + + +void LottieParser::parseDropShadow(LottieEffect* effect, int idx) +{ + auto shadow = static_cast(effect); + + if (idx == 0) parsePropertyInternal(shadow->color); + else if (idx == 1) parsePropertyInternal(shadow->opacity); + else if (idx == 2) parsePropertyInternal(shadow->angle); + else if (idx == 3) parsePropertyInternal(shadow->distance); + else if (idx == 4) parsePropertyInternal(shadow->blurness); + else skip(); +} + + +void LottieParser::parseStroke(LottieEffect* effect, int idx) +{ + auto stroke = static_cast(effect); + + if (idx == 0) parsePropertyInternal(stroke->mask); + else if (idx == 1) parsePropertyInternal(stroke->allMask); + else if (idx == 3) parsePropertyInternal(stroke->color); + else if (idx == 4) parsePropertyInternal(stroke->size); + else if (idx == 6) parsePropertyInternal(stroke->opacity); + else if (idx == 7) parsePropertyInternal(stroke->begin); + else if (idx == 8) parsePropertyInternal(stroke->end); + else skip(); +} + + +bool LottieParser::parseEffect(LottieEffect* effect) +{ + switch (effect->type) { + case LottieEffect::Custom: return parseEffect(effect, &LottieParser::parseCustom); + case LottieEffect::Tint: return parseEffect(effect, &LottieParser::parseTint); + case LottieEffect::Fill: return parseEffect(effect, &LottieParser::parseFill); + case LottieEffect::Stroke: return parseEffect(effect, &LottieParser::parseStroke); + case LottieEffect::Tritone: return parseEffect(effect, &LottieParser::parseTritone); + case LottieEffect::DropShadow: return parseEffect(effect, &LottieParser::parseDropShadow); + case LottieEffect::GaussianBlur: return parseEffect(effect, &LottieParser::parseGaussianBlur); + default: return false; + } +} + + +void LottieParser::parseEffects(LottieLayer* layer) +{ + enterArray(); + while (nextArrayValue()) { + LottieEffect* effect = nullptr; + auto invalid = true; + enterObject(); + while (auto key = nextObjectKey()) { + //type must be prioritized. + if (KEY_AS("ty")) + { + effect = getEffect(getInt()); + if (!effect) break; + else invalid = false; + } + else if (effect && KEY_AS("nm")) effect->nm = djb2Encode(getString()); + else if (effect && KEY_AS("mn")) effect->mn = djb2Encode(getString()); + else if (effect && KEY_AS("ix")) effect->ix = getInt(); + else if (effect && KEY_AS("en")) effect->enable = getInt(); + else if (effect && KEY_AS("ef")) parseEffect(effect); + else skip(); + } + //TODO: remove when all effects were guaranteed. + if (invalid) { + TVGLOG("LOTTIE", "Not supported Layer Effect = %d", effect ? (int)effect->type : -1); + while (nextObjectKey()) skip(); + } else layer->effects.push(effect); + } +} + + +LottieLayer* LottieParser::parseLayer(LottieLayer* precomp) +{ + auto layer = new LottieLayer; + + layer->comp = precomp; + context.layer = layer; + + auto ddd = false; + RGB32 color; + + enterObject(); + + while (auto key = nextObjectKey()) { + if (KEY_AS("nm")) + { + layer->name = getStringCopy(); + layer->id = djb2Encode(layer->name); + } + else if (KEY_AS("ddd")) ddd = getInt(); //3d layer + else if (KEY_AS("ind")) layer->ix = getInt(); + else if (KEY_AS("ty")) layer->type = (LottieLayer::Type) getInt(); + else if (KEY_AS("sr")) layer->timeStretch = getFloat(); + else if (KEY_AS("ks")) + { + enterObject(); + layer->transform = parseTransform(ddd); + } + else if (KEY_AS("ao")) layer->autoOrient = getInt(); + else if (KEY_AS("shapes")) parseShapes(layer->children); + else if (KEY_AS("ip")) layer->inFrame = getFloat(); + else if (KEY_AS("op")) layer->outFrame = getFloat(); + else if (KEY_AS("st")) layer->startFrame = getFloat(); + else if (KEY_AS("bm")) layer->blendMethod = (BlendMethod) getInt(); + else if (KEY_AS("parent")) layer->pix = getInt(); + else if (KEY_AS("tm")) parseTimeRemap(layer); + else if (KEY_AS("w") || KEY_AS("sw")) getLayerSize(layer->w); + else if (KEY_AS("h") || KEY_AS("sh")) getLayerSize(layer->h); + else if (KEY_AS("sc")) color = getColor(getString()); + else if (KEY_AS("tt")) layer->matteType = (MaskMethod) getInt(); + else if (KEY_AS("tp")) layer->mix = getInt(); + else if (KEY_AS("masksProperties")) parseMasks(layer); + else if (KEY_AS("hd")) layer->hidden = getBool(); + else if (KEY_AS("refId")) layer->rid = djb2Encode(getString()); + else if (KEY_AS("td")) layer->matteSrc = getInt(); //used for matte layer + else if (KEY_AS("t")) parseText(layer->children); + else if (KEY_AS("ef")) parseEffects(layer); + else skip(); + } + + layer->prepare(&color); + + return layer; +} + + +LottieLayer* LottieParser::parseLayers(LottieLayer* root) +{ + auto precomp = new LottieLayer; + + precomp->type = LottieLayer::Precomp; + precomp->comp = root; + + enterArray(); + while (nextArrayValue()) { + precomp->children.push(parseLayer(precomp)); + } + + precomp->prepare(); + return precomp; +} + + +void LottieParser::postProcess(Array& glyphs) +{ + //aggregate font characters + for (uint32_t g = 0; g < glyphs.count; ++g) { + auto glyph = glyphs[g]; + for (uint32_t i = 0; i < comp->fonts.count; ++i) { + auto& font = comp->fonts[i]; + if (!strcmp(font->family, glyph->family) && !strcmp(font->style, glyph->style)) { + font->chars.push(glyph); + tvg::free(glyph->family); + tvg::free(glyph->style); + break; + } + } + } +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +const char* LottieParser::sid(bool first) +{ + if (first) { + //verify json + if (!parseNext()) return nullptr; + enterObject(); + } + return nextObjectKey(); +} + + +LottieProperty* LottieParser::parse(LottieSlot* slot) +{ + enterObject(); + + LottieProperty* prop = nullptr; + context = {slot->context.layer, slot->context.parent}; + + switch (slot->type) { + case LottieProperty::Type::Float: { + prop = new LottieFloat; + parseSlotProperty(*static_cast(prop)); + break; + } + case LottieProperty::Type::Scalar: { + prop = new LottieScalar; + parseSlotProperty(*static_cast(prop)); + break; + } + case LottieProperty::Type::Vector: { + prop = new LottieVector; + parseSlotProperty(*static_cast(prop)); + break; + } + case LottieProperty::Type::Opacity: { + prop = new LottieOpacity; + parseSlotProperty(*static_cast(prop)); + break; + } + case LottieProperty::Type::Color: { + prop = new LottieColor; + parseSlotProperty(*static_cast(prop)); + break; + } + case LottieProperty::Type::ColorStop: { + auto obj = new LottieGradient; + while (auto key = nextObjectKey()) { + if (KEY_AS("p")) parseColorStop(obj); + else skip(); + } + obj->prepare(); + prop = new LottieColorStop(obj->colorStops); + delete(obj); + break; + } + case LottieProperty::Type::TextDoc: { + prop = new LottieTextDoc; + parseSlotProperty(*static_cast(prop)); + break; + } + case LottieProperty::Type::Image: { + LottieObject* obj = nullptr; + while (auto key = nextObjectKey()) { + if (KEY_AS("p")) obj = parseAsset(); + else skip(); + } + if (!obj) return nullptr; + prop = new LottieBitmap(static_cast(obj)->bitmap); + delete(obj); + break; + } + default: break; + } + return prop; +} + + +void LottieParser::captureSlots(const char* key) +{ + tvg::free(slots); + + // TODO: Replace with immediate parsing, once the slot spec is confirmed by the LAC + + auto begin = getPos(); + auto end = getPos(); + auto depth = 1; + auto invalid = true; + + //get slots string + while (++end) { + if (*end == '}') { + --depth; + if (depth == 0) { + invalid = false; + break; + } + } else if (*end == '{') { + ++depth; + } + } + + if (invalid) { + TVGERR("LOTTIE", "Invalid Slots!"); + skip(); + return; + } + + //composite '{' + slots + '}' + auto len = (end - begin + 2); + slots = tvg::malloc(sizeof(char) * len + 1); + slots[0] = '{'; + memcpy(slots + 1, begin, len); + slots[len] = '\0'; + + skip(); +} + + +bool LottieParser::parse() +{ + //verify json. + if (!parseNext()) return false; + + enterObject(); + + if (comp) delete(comp); + comp = new LottieComposition; + + Array glyphs; + + auto startFrame = 0.0f; + auto endFrame = 0.0f; + + while (auto key = nextObjectKey()) { + if (KEY_AS("v")) comp->version = getStringCopy(); + else if (KEY_AS("fr")) comp->frameRate = getFloat(); + else if (KEY_AS("ip")) startFrame = getFloat(); + else if (KEY_AS("op")) endFrame = getFloat(); + else if (KEY_AS("w")) comp->w = getFloat(); + else if (KEY_AS("h")) comp->h = getFloat(); + else if (KEY_AS("nm")) comp->name = getStringCopy(); + else if (KEY_AS("assets")) parseAssets(); + else if (KEY_AS("layers")) comp->root = parseLayers(comp->root); + else if (KEY_AS("fonts")) parseFonts(); + else if (KEY_AS("chars")) parseChars(glyphs); + else if (KEY_AS("markers")) parseMarkers(); + else if (KEY_AS("slots")) captureSlots(key); + else skip(); + } + + if (Invalid() || !comp->root) { + delete(comp); + return false; + } + + comp->root->inFrame = startFrame; + comp->root->outFrame = endFrame; + + postProcess(glyphs); + + return true; +} diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieParser.h b/components/thorvg-main/src/loaders/lottie/tvgLottieParser.h new file mode 100644 index 0000000..841bcec --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieParser.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_PARSER_H_ +#define _TVG_LOTTIE_PARSER_H_ + +#include "tvgCommon.h" +#include "tvgLottieParserHandler.h" +#include "tvgLottieProperty.h" + +struct LottieParser : LookaheadParserHandler +{ +public: + LottieParser(const char *str, const char* dirName, bool expressions) : LookaheadParserHandler(str) + { + this->dirName = dirName; + this->expressions = expressions; + } + + bool parse(); + const char* sid(bool first = false); + LottieProperty* parse(LottieSlot* slot); + + LottieComposition* comp = nullptr; + const char* dirName = nullptr; //base resource directory + char* slots = nullptr; + bool expressions = false; //support expressions? + +private: + RGB32 getColor(const char *str); + FillRule getFillRule(); + MaskMethod getMaskMethod(bool inversed); + LottieInterpolator* getInterpolator(const char* key, Point& in, Point& out); + LottieEffect* getEffect(int type); + + void getExpression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property); + void getInterpolatorPoint(Point& pt); + void getPathSet(LottiePath* obj, LottiePathSet& path); + void getLayerSize(float& val); + bool getValue(TextDocument& doc); + bool getValue(PathSet& path); + bool getValue(Array& pts); + bool getValue(ColorStop& color); + bool getValue(float& val); + bool getValue(uint8_t& val); + bool getValue(int8_t& val); + bool getValue(RGB32& color); + bool getValue(Point& pt); + + template bool parseTangent(const char *key, LottieVectorFrame& value); + template bool parseTangent(const char *key, LottieScalarFrame& value); + template void parseKeyFrame(T& prop); + template void parsePropertyInternal(T& prop); + template void parseProperty(T& prop, LottieObject* obj = nullptr); + template void parseSlotProperty(T& prop); + + LottieObject* parseObject(const char* type); + LottieObject* parseAsset(); + void parseImage(LottieImage* image, const char* data, const char* subPath, bool embedded, float width, float height); + LottieLayer* parseLayer(LottieLayer* precomp); + LottieObject* parseGroup(); + LottieRect* parseRect(); + LottieEllipse* parseEllipse(); + LottieSolidFill* parseSolidFill(); + LottieTransform* parseTransform(bool ddd = false); + LottieSolidStroke* parseSolidStroke(); + LottieGradientStroke* parseGradientStroke(); + LottiePath* parsePath(); + LottiePolyStar* parsePolyStar(); + LottieRoundedCorner* parseRoundedCorner(); + LottieGradientFill* parseGradientFill(); + LottieLayer* parseLayers(LottieLayer* root); + LottieMask* parseMask(); + LottieTrimpath* parseTrimpath(); + LottieRepeater* parseRepeater(); + LottieOffsetPath* parseOffsetPath(); + LottieFont* parseFont(); + void parseFontData(LottieFont* font, const char* data); + LottieMarker* parseMarker(); + + bool parseEffect(LottieEffect* effect, void(LottieParser::*func)(LottieEffect*, int)); + void parseCustom(LottieEffect* effect, int idx); + void parseStroke(LottieEffect* effect, int idx); + void parseTritone(LottieEffect* effect, int idx); + void parseTint(LottieEffect* effect, int idx); + void parseFill(LottieEffect* effect, int idx); + void parseGaussianBlur(LottieEffect* effect, int idx); + void parseDropShadow(LottieEffect* effect, int idx); + + bool parseDirection(LottieShape* shape, const char* key); + bool parseCommon(LottieObject* obj, const char* key); + bool parseCommon(LottieObject* obj, LottieProperty& prop, const char* key); + void parseObject(Array& parent); + void parseShapes(Array& parent); + void parseText(Array& parent); + void parseMasks(LottieLayer* layer); + void parseEffects(LottieLayer* layer); + void parseTimeRemap(LottieLayer* layer); + void parseStrokeDash(LottieStroke* stroke); + void parseGradient(LottieGradient* gradient, const char* key); + void parseColorStop(LottieGradient* gradient); + void parseTextRange(LottieText* text); + void parseTextAlignmentOption(LottieText* text); + void parseTextFollowPath(LottieText* text); + void parseAssets(); + void parseFonts(); + void parseChars(Array& glyphs); + void parseMarkers(); + bool parseEffect(LottieEffect* effect); + void postProcess(Array& glyphs); + + char* captureType(); + void captureSlots(const char* key); + void registerSlot(LottieObject* obj, const char* sid, LottieProperty::Type type); + + //Current parsing context + struct Context { + LottieLayer* layer = nullptr; + LottieObject* parent = nullptr; + } context; +}; + +#endif //_TVG_LOTTIE_PARSER_H_ diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieParserHandler.cpp b/components/thorvg-main/src/loaders/lottie/tvgLottieParserHandler.cpp new file mode 100644 index 0000000..2e1f58f --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieParserHandler.cpp @@ -0,0 +1,235 @@ + /* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgStr.h" +#include "tvgLottieParserHandler.h" + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +bool LookaheadParserHandler::enterArray() +{ + if (state == kEnteringArray) { + parseNext(); + return true; + } + Error(); + return false; +} + + +bool LookaheadParserHandler::nextArrayValue() +{ + if (state == kExitingArray) { + parseNext(); + return false; + } + //SPECIAL CASE: same as nextObjectKey() + if (state == kExitingObject) return false; + if (state == kError || state == kHasKey) { + Error(); + return false; + } + return true; +} + + +int LookaheadParserHandler::getInt() +{ + if (state == kHasNumber) { + auto result = val.GetInt(); + parseNext(); + return result; + } + Error(); + return 0; +} + + +float LookaheadParserHandler::getFloat() +{ + if (state == kHasNumber) { + auto result = val.GetFloat(); + parseNext(); + return result; + } + Error(); + return 0; +} + + +const char* LookaheadParserHandler::getString() +{ + if (state == kHasString) { + auto result = val.GetString(); + parseNext(); + return result; + } + Error(); + return nullptr; +} + + +char* LookaheadParserHandler::getStringCopy() +{ + auto str = getString(); + if (str) return duplicate(str); + return nullptr; +} + + +bool LookaheadParserHandler::getBool() +{ + if (state == kHasBool) { + auto result = val.GetBool(); + parseNext(); + return result; + } + Error(); + return false; +} + + +void LookaheadParserHandler::getNull() +{ + if (state == kHasNull) { + parseNext(); + return; + } + Error(); +} + + +bool LookaheadParserHandler::parseNext() +{ + if (reader.HasParseError() || !reader.IterativeParseNext(iss, *this)) { + Error(); + return false; + } + return true; +} + + +bool LookaheadParserHandler::enterObject() +{ + if (state == kEnteringObject) { + parseNext(); + return true; + } + Error(); + return false; +} + + +int LookaheadParserHandler::peekType() +{ + if (state >= kHasNull && state <= kHasKey) return val.GetType(); + if (state == kEnteringArray) return kArrayType; + if (state == kEnteringObject) return kObjectType; + return -1; +} + + +void LookaheadParserHandler::skipOut(int depth) +{ + do { + if (state == kEnteringArray || state == kEnteringObject) ++depth; + else if (state == kExitingArray || state == kExitingObject) --depth; + else if (state == kError) return; + parseNext(); + } while (depth > 0); +} + + +const char* LookaheadParserHandler::nextObjectKey() +{ + if (state == kHasKey) { + auto result = val.GetString(); + parseNext(); + return result; + } + + /* SPECIAL CASE: The parser works with a predefined rule that it will be only + while (nextObjectKey()) for each object but in case of our nested group + object we can call multiple time nextObjectKey() while exiting the object + so ignore those and don't put parser in the error state. */ + if (state == kExitingArray || state == kEnteringObject) return nullptr; + + if (state != kExitingObject) { + Error(); + return nullptr; + } + + parseNext(); + return nullptr; +} + + +void LookaheadParserHandler::skip() +{ + if (peekType() == kArrayType) { + enterArray(); + skipOut(1); + } else if (peekType() == kObjectType) { + enterObject(); + skipOut(1); + } else { + skipOut(0); + } +} + + +char* LookaheadParserHandler::getPos() +{ + return iss.src_; +} + + +bool LookaheadParserHandler::isPrimitive() +{ + return state >= kHasNull && state <= kHasKey; +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieParserHandler.h b/components/thorvg-main/src/loaders/lottie/tvgLottieParserHandler.h new file mode 100644 index 0000000..35ffa87 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieParserHandler.h @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_PARSER_HANDLER_H_ +#define _TVG_LOTTIE_PARSER_HANDLER_H_ + +#include "rapidjson/document.h" +#include "tvgCommon.h" + + +using namespace rapidjson; + +#define PARSE_FLAGS (kParseDefaultFlags | kParseInsituFlag) + +struct LookaheadParserHandler +{ + enum LookaheadParsingState { + kInit = 0, + kError, + kHasNull, + kHasBool, + kHasNumber, + kHasString, + kHasKey, + kEnteringObject, + kExitingObject, + kEnteringArray, + kExitingArray + }; + + Value val; + LookaheadParsingState state = kInit; + Reader reader; + InsituStringStream iss; + + LookaheadParserHandler(const char *str) : iss((char*)str) + { + reader.IterativeParseInit(); + } + + bool Null() + { + state = kHasNull; + val.SetNull(); + return true; + } + + bool Bool(bool b) + { + state = kHasBool; + val.SetBool(b); + return true; + } + + bool Int(int i) + { + state = kHasNumber; + val.SetInt(i); + return true; + } + + bool Uint(unsigned u) + { + state = kHasNumber; + val.SetUint(u); + return true; + } + + bool Int64(int64_t i) + { + state = kHasNumber; + val.SetInt64(i); + return true; + } + + bool Uint64(int64_t u) + { + state = kHasNumber; + val.SetUint64(u); + return true; + } + + bool Double(double d) + { + state = kHasNumber; + val.SetDouble(d); + return true; + } + + bool RawNumber(const char *, SizeType, TVG_UNUSED bool) + { + return false; + } + + bool String(const char *str, SizeType length, TVG_UNUSED bool) + { + state = kHasString; + val.SetString(str, length); + return true; + } + + bool StartObject() + { + state = kEnteringObject; + return true; + } + + bool Key(const char *str, SizeType length, TVG_UNUSED bool) + { + state = kHasKey; + val.SetString(str, length); + return true; + } + + bool EndObject(SizeType) + { + state = kExitingObject; + return true; + } + + bool StartArray() + { + state = kEnteringArray; + return true; + } + + bool EndArray(SizeType) + { + state = kExitingArray; + return true; + } + + void Error() + { + TVGERR("LOTTIE", "Invalid JSON: unexpected or misaligned data fields."); + state = kError; + reader.IterativeParseNext(iss, *this); //something wrong but try advancement. + } + + bool Invalid() + { + return state == kError; + } + + bool enterObject(); + bool enterArray(); + bool nextArrayValue(); + int getInt(); + float getFloat(); + const char* getString(); + char* getStringCopy(); + bool getBool(); + void getNull(); + bool parseNext(); + const char* nextObjectKey(); + void skip(); + void skipOut(int depth); + int peekType(); + bool isPrimitive(); + char* getPos(); +}; + +#endif //_TVG_LOTTIE_PARSER_HANDLER_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieProperty.h b/components/thorvg-main/src/loaders/lottie/tvgLottieProperty.h new file mode 100644 index 0000000..be840d0 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieProperty.h @@ -0,0 +1,1036 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_PROPERTY_H_ +#define _TVG_LOTTIE_PROPERTY_H_ + +#include +#include "tvgMath.h" +#include "tvgStr.h" +#include "tvgLottieData.h" +#include "tvgLottieInterpolator.h" +#include "tvgLottieExpressions.h" +#include "tvgLottieModifier.h" + + +struct LottieFont; +struct LottieLayer; +struct LottieObject; +struct LottieProperty; + + +//default keyframe updates condition (no tweening) +#define DEFAULT_COND (!tween.active || !frames || (frames->count == 1)) + + +template +struct LottieScalarFrame +{ + T value; //keyframe value + float no; //frame number + LottieInterpolator* interpolator; + bool hold = false; //do not interpolate. + + T interpolate(LottieScalarFrame* next, float frameNo) + { + auto t = (frameNo - no) / (next->no - no); + if (interpolator) t = interpolator->progress(t); + + if (hold) { + if (t < 1.0f) return value; + else return next->value; + } + return tvg::lerp(value, next->value, t); + } + + float angle(LottieScalarFrame* next, float frameNo) + { + return 0.0f; + } + + void prepare(TVG_UNUSED LottieScalarFrame* next) + { + } +}; + + +template +struct LottieVectorFrame +{ + T value; //keyframe value + float no; //frame number + LottieInterpolator* interpolator; + T outTangent, inTangent; + float length; + bool hasTangent = false; + bool hold = false; + + T interpolate(LottieVectorFrame* next, float frameNo) + { + auto t = (frameNo - no) / (next->no - no); + if (interpolator) t = interpolator->progress(t); + + if (hold) { + if (t < 1.0f) return value; + else return next->value; + } + + if (hasTangent) { + Bezier bz = {value, value + outTangent, next->value + inTangent, next->value}; + return bz.at(bz.atApprox(t * length, length)); + } else { + return tvg::lerp(value, next->value, t); + } + } + + float angle(LottieVectorFrame* next, float frameNo) + { + if (!hasTangent) { + Point dp = next->value - value; + return rad2deg(tvg::atan2(dp.y, dp.x)); + } + + auto t = (frameNo - no) / (next->no - no); + if (interpolator) t = interpolator->progress(t); + Bezier bz = {value, value + outTangent, next->value + inTangent, next->value}; + t = bz.atApprox(t * length, length); + return bz.angle(t >= 1.0f ? 0.99f : (t <= 0.0f ? 0.01f : t)); + } + + void prepare(LottieVectorFrame* next) + { + Bezier bz = {value, value + outTangent, next->value + inTangent, next->value}; + length = bz.lengthApprox(); + } +}; + + +struct LottieExpression +{ + //writable expressions variable name and value. + struct Writable { + char* var; + float val; + }; + + char* code; + LottieComposition* comp; + LottieLayer* layer; + LottieObject* object; + LottieProperty* property; + Array writables; + bool disabled = false; + + LottieExpression() {} + + LottieExpression(const LottieExpression* rhs) + { + code = strdup(rhs->code); + comp = rhs->comp; + layer = rhs->layer; + object = rhs->object; + property = rhs->property; + disabled = rhs->disabled; + } + + ~LottieExpression() + { + ARRAY_FOREACH(p, writables) { + tvg::free(p->var); + } + tvg::free(code); + } + + bool assign(const char* var, float val) + { + //overwrite the existing value + ARRAY_FOREACH(p, writables) { + if (tvg::equal(var, p->var)) { + p->val = val; + return true; + } + } + writables.push({tvg::duplicate(var), val}); + return true; + } +}; + + +//Property would have an either keyframes or single value. +struct LottieProperty +{ + enum class Type : uint8_t {Invalid = 0, Integer, Float, Scalar, Vector, PathSet, Color, Opacity, ColorStop, TextDoc, Image}; + enum class Loop : uint8_t {None = 0, InCycle = 1, InPingPong, InOffset, InContinue, OutCycle, OutPingPong, OutOffset, OutContinue}; + + LottieExpression* exp = nullptr; + Type type; + uint8_t ix; //property index + + LottieProperty(Type type = Type::Invalid) : type(type) {} + virtual ~LottieProperty() {} + + virtual uint32_t frameCnt() = 0; + virtual uint32_t nearest(float frameNo) = 0; + virtual float frameNo(int32_t key) = 0; + virtual float loop(float frameNo, uint32_t key, Loop mode, float inout) = 0; + + bool copy(LottieProperty* rhs, bool shallow) + { + type = rhs->type; + ix = rhs->ix; + + if (!rhs->exp) return false; + if (shallow) { + exp = rhs->exp; + rhs->exp = nullptr; + } else { + exp = new LottieExpression(rhs->exp); + } + exp->property = this; + return true; + } +}; + + +static void _copy(PathSet* pathset, Array& out, Matrix* transform) +{ + if (transform) { + for (int i = 0; i < pathset->ptsCnt; ++i) { + out.push(pathset->pts[i] * *transform); + } + } else { + Array in; + in.data = pathset->pts; + in.count = pathset->ptsCnt; + out.push(in); + in.data = nullptr; + } +} + + +static void _copy(PathSet* pathset, Array& out) +{ + Array in; + in.data = pathset->cmds; + in.count = pathset->cmdsCnt; + out.push(in); + in.data = nullptr; +} + + +template +uint32_t _bsearch(T* frames, float frameNo) +{ + int32_t low = 0; + int32_t high = int32_t(frames->count) - 1; + + while (low <= high) { + auto mid = low + (high - low) / 2; + auto frame = frames->data + mid; + if (frameNo < frame->no) high = mid - 1; + else low = mid + 1; + } + if (high < low) low = high; + if (low < 0) low = 0; + return low; +} + + +template +uint32_t _nearest(T* frames, float frameNo) +{ + if (frames) { + auto key = _bsearch(frames, frameNo); + if (key == frames->count - 1) return key; + return (fabsf(frames->data[key].no - frameNo) < fabsf(frames->data[key + 1].no - frameNo)) ? key : (key + 1); + } + return 0; +} + + +template +float _frameNo(T* frames, int32_t key) +{ + if (!frames) return 0.0f; + if (key < 0) key = 0; + if (key >= (int32_t) frames->count) key = (int32_t)(frames->count - 1); + return (*frames)[key].no; +} + + +//TODO: good abstract "frames" interface to remove the template method. +template +float _loop(T* frames, float frameNo, uint32_t key, LottieProperty::Loop mode, float inout) +{ + if (!frames) return frameNo; + if (mode == LottieProperty::Loop::None) return frameNo; + frameNo -= frames->first().no; + + switch (mode) { + case LottieProperty::Loop::InCycle: { + return fmodf(frameNo, inout - frames->first().no) + (*frames)[key].no; + } + case LottieProperty::Loop::InPingPong: { + auto range = inout - (*frames)[key].no; + auto forward = (static_cast(frameNo / range) % 2) == 0 ? true : false; + frameNo = fmodf(frameNo, range); + return (forward ? frameNo : (range - frameNo)) + (*frames)[key].no; + } + case LottieProperty::Loop::OutCycle: { + return fmodf(frameNo, (*frames)[frames->count - 1 - key].no - frames->first().no) + frames->first().no; + } + case LottieProperty::Loop::OutPingPong: { + auto range = (*frames)[frames->count - 1 - key].no - frames->first().no; + auto forward = (static_cast(frameNo / range) % 2) == 0 ? true : false; + frameNo = fmodf(frameNo, range); + return (forward ? frameNo : (range - frameNo)) + frames->first().no; + } + default: break; + } + return frameNo; +} + + +template +struct LottieGenericProperty : LottieProperty +{ + using MyProperty = LottieGenericProperty; + + //Property has an either keyframes or single value. + Array* frames = nullptr; + Value value; + + LottieGenericProperty(Value v) : LottieProperty(PType), value(v) {} + + LottieGenericProperty() : LottieProperty(PType) {} + + LottieGenericProperty(const MyProperty& rhs) + { + copy(const_cast(rhs)); + } + + ~LottieGenericProperty() + { + release(); + } + + void release() + { + delete(frames); + frames = nullptr; + if (exp) { + delete(exp); + exp = nullptr; + } + } + + uint32_t nearest(float frameNo) override + { + return _nearest(frames, frameNo); + } + + uint32_t frameCnt() override + { + return frames ? frames->count : 1; + } + + float frameNo(int32_t key) override + { + return _frameNo(frames, key); + } + + float loop(float frameNo, uint32_t key, Loop mode, float inout) override + { + return _loop(frames, frameNo, key, mode, inout); + } + + Frame& newFrame() + { + if (!frames) frames = new Array; + if (frames->count + 1 >= frames->reserved) { + auto old = frames->reserved; + frames->grow(frames->count + 2); + memset((void*)(frames->data + old), 0x00, sizeof(Frame) * (frames->reserved - old)); + } + ++frames->count; + return frames->last(); + } + + Frame& nextFrame() + { + return (*frames)[frames->count]; + } + + Value operator()(float frameNo, LottieExpressions* exps = nullptr) + { + //overriding with expressions + if (exps && exp) { + Value out{}; + if (exps->result(frameNo, out, exp)) return out; + } + + if (!frames) return value; + if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value; + if (frameNo >= frames->last().no) return frames->last().value; + + auto frame = frames->data + _bsearch(frames, frameNo); + if (tvg::equal(frame->no, frameNo)) return frame->value; + return frame->interpolate(frame + 1, frameNo); + } + + Value operator()(float frameNo, Tween& tween, LottieExpressions* exps) + { + if (DEFAULT_COND) return operator()(frameNo, exps); + return tvg::lerp(operator()(frameNo, exps), operator()(tween.frameNo, exps), tween.progress); + } + + void copy(MyProperty& rhs, bool shallow = true) + { + if (LottieProperty::copy(&rhs, shallow)) return; + + if (rhs.frames) { + if (shallow) { + frames = rhs.frames; + rhs.frames = nullptr; + } else { + frames = new Array; + *frames = *rhs.frames; + } + } else { + frames = nullptr; + value = rhs.value; + } + } + + float angle(float frameNo) + { + if (!frames || frames->count == 1) return 0; + + if (frameNo <= frames->first().no) return frames->first().angle(frames->data + 1, frames->first().no); + if (frameNo >= frames->last().no) { + auto frame = frames->data + frames->count - 2; + return frame->angle(frame + 1, frames->last().no); + } + + auto frame = frames->data + _bsearch(frames, frameNo); + return frame->angle(frame + 1, frameNo); + } + + float angle(float frameNo, Tween& tween) + { + if (DEFAULT_COND) return angle(frameNo); + return tvg::lerp(angle(frameNo), angle(tween.frameNo), tween.progress); + } + + void prepare() + { + if (Scalar) return; + if (!frames || frames->count < 2) return; + for (auto frame = frames->begin() + 1; frame < frames->end(); ++frame) { + (frame - 1)->prepare(frame); + } + } +}; + + +struct LottiePathSet : LottieProperty +{ + Array>* frames = nullptr; + PathSet value; + + LottiePathSet() : LottieProperty(LottieProperty::Type::PathSet) {} + + ~LottiePathSet() + { + release(); + } + + void release() + { + if (exp) { + delete(exp); + exp = nullptr; + } + + tvg::free(value.cmds); + tvg::free(value.pts); + + if (!frames) return; + + ARRAY_FOREACH(p, *frames) { + tvg::free((*p).value.cmds); + tvg::free((*p).value.pts); + } + tvg::free(frames->data); + tvg::free(frames); + } + + uint32_t nearest(float frameNo) override + { + return _nearest(frames, frameNo); + } + + uint32_t frameCnt() override + { + return frames ? frames->count : 1; + } + + float frameNo(int32_t key) override + { + return _frameNo(frames, key); + } + + float loop(float frameNo, uint32_t key, Loop mode, float inout) override + { + return _loop(frames, frameNo, key, mode, inout); + } + + LottieScalarFrame& newFrame() + { + if (!frames) { + frames = tvg::calloc>>(1, sizeof(Array>)); + } + if (frames->count + 1 >= frames->reserved) { + auto old = frames->reserved; + frames->grow(frames->count + 2); + memset((void*)(frames->data + old), 0x00, sizeof(LottieScalarFrame) * (frames->reserved - old)); + } + ++frames->count; + return frames->last(); + } + + LottieScalarFrame& nextFrame() + { + return (*frames)[frames->count]; + } + + //return false means requiring the interpolation + bool dispatch(float frameNo, PathSet*& path, LottieScalarFrame*& frame, float& t) + { + if (!frames) path = &value; + else if (frames->count == 1 || frameNo <= frames->first().no) path = &frames->first().value; + else if (frameNo >= frames->last().no) path = &frames->last().value; + else { + frame = frames->data + _bsearch(frames, frameNo); + if (tvg::equal(frame->no, frameNo)) path = &frame->value; + else if (frame->value.ptsCnt != (frame + 1)->value.ptsCnt) { + path = &frame->value; + } else { + t = (frameNo - frame->no) / ((frame + 1)->no - frame->no); + if (frame->interpolator) t = frame->interpolator->progress(t); + if (frame->hold) path = &(frame + ((t < 1.0f) ? 0 : 1))->value; + else return false; + } + } + return true; + } + + bool modifiedPath(float frameNo, RenderPath& out, Matrix* transform, LottieModifier* modifier) + { + PathSet* path; + LottieScalarFrame* frame; + RenderPath temp; + float t; + + if (dispatch(frameNo, path, frame, t)) { + if (modifier) return modifier->modifyPath(path->cmds, path->cmdsCnt, path->pts, path->ptsCnt, transform, out); + _copy(path, out.cmds); + _copy(path, out.pts, transform); + return true; + } + + //interpolate 2 frames + auto s = frame->value.pts; + auto e = (frame + 1)->value.pts; + auto interpPts = tvg::malloc(frame->value.ptsCnt * sizeof(Point)); + auto p = interpPts; + + for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e, ++p) { + *p = tvg::lerp(*s, *e, t); + if (transform) *p *= *transform; + } + + if (modifier) modifier->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, nullptr, out); + + tvg::free(interpPts); + + return true; + } + + bool defaultPath(float frameNo, RenderPath& out, Matrix* transform) + { + PathSet* path; + LottieScalarFrame* frame; + float t; + + if (dispatch(frameNo, path, frame, t)) { + _copy(path, out.cmds); + _copy(path, out.pts, transform); + return true; + } + + //interpolate 2 frames + auto s = frame->value.pts; + auto e = (frame + 1)->value.pts; + + for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e) { + auto pt = tvg::lerp(*s, *e, t); + if (transform) pt *= *transform; + out.pts.push(pt); + } + _copy(&frame->value, out.cmds); + return true; + } + + bool tweening(float frameNo, RenderPath& out, Matrix* transform, LottieModifier* modifier, Tween& tween, LottieExpressions* exps) + { + RenderPath to; //used as temp as well. + auto pivot = out.pts.count; + if (!operator()(frameNo, out, transform, exps)) return false; + if (!operator()(tween.frameNo, to, transform, exps)) return false; + + auto from = out.pts.data + pivot; + if (to.pts.count != out.pts.count - pivot) TVGLOG("LOTTIE", "Tweening has different numbers of points in consecutive frames."); + + for (uint32_t i = 0; i < std::min(to.pts.count, (out.pts.count - pivot)); ++i) { + from[i] = tvg::lerp(from[i], to.pts[i], tween.progress); + } + + if (!modifier) return true; + + //Apply modifiers + to.clear(); + return modifier->modifyPath(to.cmds.data, to.cmds.count, to.pts.data, to.pts.count, transform, out); + } + + bool operator()(float frameNo, RenderPath& out, Matrix* transform, LottieExpressions* exps, LottieModifier* modifier = nullptr) + { + //overriding with expressions + if (exps && exp) { + if (exps->result(frameNo, out, transform, modifier, exp)) return true; + } + + if (modifier) return modifiedPath(frameNo, out, transform, modifier); + else return defaultPath(frameNo, out, transform); + } + + bool operator()(float frameNo, RenderPath& out, Matrix* transform, Tween& tween, LottieExpressions* exps, LottieModifier* modifier = nullptr) + { + if (DEFAULT_COND) return operator()(frameNo, out, transform, exps, modifier); + return tweening(frameNo, out, transform, modifier, tween, exps); + } +}; + + +struct LottieColorStop : LottieProperty +{ + Array>* frames = nullptr; + ColorStop value; + uint16_t count = 0; //colorstop count + bool populated = false; + + LottieColorStop() : LottieProperty(LottieProperty::Type::ColorStop) {} + + LottieColorStop(const LottieColorStop& rhs) + { + copy(const_cast(rhs)); + } + + ~LottieColorStop() + { + release(); + } + + void release() + { + delete(exp); + exp = nullptr; + + tvg::free(value.data); + value.data = nullptr; + + delete(value.input); + value.input = nullptr; + + if (!frames) return; + + ARRAY_FOREACH(p, *frames) { + tvg::free((*p).value.data); + delete((*p).value.input); + } + tvg::free(frames->data); + tvg::free(frames); + frames = nullptr; + } + + uint32_t nearest(float frameNo) override + { + return _nearest(frames, frameNo); + } + + uint32_t frameCnt() override + { + return frames ? frames->count : 1; + } + + float frameNo(int32_t key) override + { + return _frameNo(frames, key); + } + + float loop(float frameNo, uint32_t key, Loop mode, float inout) override + { + return _loop(frames, frameNo, key, mode, inout); + } + + LottieScalarFrame& newFrame() + { + if (!frames) { + frames = tvg::calloc>>(1, sizeof(Array>)); + } + if (frames->count + 1 >= frames->reserved) { + auto old = frames->reserved; + frames->grow(frames->count + 2); + memset((void*)(frames->data + old), 0x00, sizeof(LottieScalarFrame) * (frames->reserved - old)); + } + ++frames->count; + return frames->last(); + } + + LottieScalarFrame& nextFrame() + { + return (*frames)[frames->count]; + } + + Result tweening(float frameNo, Fill* fill, Tween& tween, LottieExpressions* exps) + { + auto frame = frames->data + _bsearch(frames, frameNo); + if (tvg::equal(frame->no, frameNo)) return fill->colorStops(frame->value.data, count); + + //from + operator()(frameNo, fill, exps); + + //to + auto dup = fill->duplicate(); + operator()(tween.frameNo, dup, exps); + + //interpolate + const Fill::ColorStop* from; + auto fromCnt = fill->colorStops(&from); + + const Fill::ColorStop* to; + auto toCnt = fill->colorStops(&to); + + if (fromCnt != toCnt) TVGLOG("LOTTIE", "Tweening has different numbers of color data in consecutive frames."); + + for (uint32_t i = 0; i < std::min(fromCnt, toCnt); ++i) { + const_cast(from)->offset = tvg::lerp(from->offset, to->offset, tween.progress); + const_cast(from)->r = tvg::lerp(from->r, to->r, tween.progress); + const_cast(from)->g = tvg::lerp(from->g, to->g, tween.progress); + const_cast(from)->b = tvg::lerp(from->b, to->b, tween.progress); + const_cast(from)->a = tvg::lerp(from->a, to->a, tween.progress); + } + + return Result::Success; + } + + Result operator()(float frameNo, Fill* fill, LottieExpressions* exps = nullptr) + { + //overriding with expressions + if (exps && exp) { + if (exps->result(frameNo, fill, exp)) return Result::Success; + } + + if (!frames) return fill->colorStops(value.data, count); + + if (frames->count == 1 || frameNo <= frames->first().no) { + return fill->colorStops(frames->first().value.data, count); + } + + if (frameNo >= frames->last().no) return fill->colorStops(frames->last().value.data, count); + + auto frame = frames->data + _bsearch(frames, frameNo); + if (tvg::equal(frame->no, frameNo)) return fill->colorStops(frame->value.data, count); + + //interpolate + auto t = (frameNo - frame->no) / ((frame + 1)->no - frame->no); + if (frame->interpolator) t = frame->interpolator->progress(t); + + if (frame->hold) { + if (t < 1.0f) fill->colorStops(frame->value.data, count); + else fill->colorStops((frame + 1)->value.data, count); + } + + auto s = frame->value.data; + auto e = (frame + 1)->value.data; + + Array result; + + for (auto i = 0; i < count; ++i, ++s, ++e) { + auto offset = tvg::lerp(s->offset, e->offset, t); + auto r = tvg::lerp(s->r, e->r, t); + auto g = tvg::lerp(s->g, e->g, t); + auto b = tvg::lerp(s->b, e->b, t); + auto a = tvg::lerp(s->a, e->a, t); + result.push({offset, r, g, b, a}); + } + return fill->colorStops(result.data, count); + } + + Result operator()(float frameNo, Fill* fill, Tween& tween, LottieExpressions* exps) + { + if (DEFAULT_COND) return operator()(frameNo, fill, exps); + return tweening(frameNo, fill, tween, exps); + } + + void copy(LottieColorStop& rhs, bool shallow = true) + { + if (LottieProperty::copy(&rhs, shallow)) return; + + //the rhs colorstop is supposed be populated already. + + if (rhs.frames) { + if (shallow) { + frames = rhs.frames; + rhs.frames = nullptr; + } else { + frames = tvg::calloc>>(1, sizeof(Array>)); + *frames = *rhs.frames; + for (uint32_t i = 0; i < (*rhs.frames).count; ++i) { + (*frames)[i].value.copy((*rhs.frames)[i].value, rhs.count); + } + } + } else { + frames = nullptr; + if (shallow) { + value = rhs.value; + rhs.value = ColorStop(); + } else { + value.copy(rhs.value, rhs.count); + } + } + populated = rhs.populated; + count = rhs.count; + } + + void prepare() {} +}; + + +struct LottieTextDoc : LottieProperty +{ + Array>* frames = nullptr; + TextDocument value; + + LottieTextDoc() : LottieProperty(LottieProperty::Type::TextDoc) {} + + LottieTextDoc(const LottieTextDoc& rhs) + { + copy(const_cast(rhs)); + } + + ~LottieTextDoc() + { + release(); + } + + void release() + { + if (exp) { + delete(exp); + exp = nullptr; + } + + if (value.text) { + tvg::free(value.text); + value.text = nullptr; + } + if (value.name) { + tvg::free(value.name); + value.name = nullptr; + } + + if (!frames) return; + + ARRAY_FOREACH(p, *frames) { + tvg::free((*p).value.text); + tvg::free((*p).value.name); + } + delete(frames); + frames = nullptr; + } + + uint32_t nearest(float frameNo) override + { + return _nearest(frames, frameNo); + } + + uint32_t frameCnt() override + { + return frames ? frames->count : 1; + } + + float frameNo(int32_t key) override + { + return _frameNo(frames, key); + } + + float loop(float frameNo, uint32_t key, Loop mode, float inout) override + { + return _loop(frames, frameNo, key, mode, inout); + } + + LottieScalarFrame& newFrame() + { + if (!frames) frames = new Array>; + if (frames->count + 1 >= frames->reserved) { + auto old = frames->reserved; + frames->grow(frames->count + 2); + memset((void*)(frames->data + old), 0x00, sizeof(LottieScalarFrame) * (frames->reserved - old)); + } + ++frames->count; + return frames->last(); + } + + LottieScalarFrame& nextFrame() + { + return (*frames)[frames->count]; + } + + TextDocument& operator()(float frameNo) + { + if (!frames) return value; + if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value; + if (frameNo >= frames->last().no) return frames->last().value; + + auto frame = frames->data + _bsearch(frames, frameNo); + return frame->value; + } + + TextDocument& operator()(float frameNo, LottieExpressions* exps) + { + auto& out = operator()(frameNo); + + //overriding with expressions + if (exps && exp) exps->result(frameNo, out, exp); + + return out; + } + + void copy(LottieTextDoc& rhs, bool shallow = true) + { + if (LottieProperty::copy(&rhs, shallow)) return; + + if (rhs.frames) { + if (shallow) { + frames = rhs.frames; + rhs.frames = nullptr; + } else { + frames = new Array>; + *frames = *rhs.frames; + for (uint32_t i = 0; i < (*rhs.frames).count; ++i) { + (*frames)[i].value.copy((*rhs.frames)[i].value); + } + } + } else { + frames = nullptr; + if (shallow) { + value = rhs.value; + rhs.value.text = nullptr; + rhs.value.name = nullptr; + } else { + value.copy(rhs.value); + } + } + } + + void prepare() {} +}; + + +struct LottieBitmap : LottieProperty +{ + union { + char* data = nullptr; + char* path; + }; + Picture *picture = nullptr; + char* mimeType = nullptr; + uint32_t size = 0; + float width = 0.0f; + float height = 0.0f; + + LottieBitmap() : LottieProperty(LottieProperty::Type::Image) {} + + LottieBitmap(const LottieBitmap& rhs) + { + copy(const_cast(rhs)); + } + + ~LottieBitmap() + { + release(); + } + + void release() + { + if (picture) { + picture->unref(); + picture = nullptr; + } + + tvg::free(data); + tvg::free(mimeType); + + data = nullptr; + mimeType = nullptr; + } + + uint32_t frameCnt() override { return 0; } + uint32_t nearest(float frameNo) override { return 0; } + float frameNo(int32_t key) override { return 0; } + float loop(float frameNo, TVG_UNUSED uint32_t key, TVG_UNUSED Loop mode, TVG_UNUSED float inout) override { return frameNo; } + + void copy(LottieBitmap& rhs, bool shallow = true) + { + if (LottieProperty::copy(&rhs, shallow)) return; + + release(); + + if (rhs.picture) { + picture = rhs.picture; + picture->ref(); + } + + width = rhs.width; + height = rhs.height; + } +}; + +using LottieFloat = LottieGenericProperty, float, LottieProperty::Type::Float>; +using LottieInteger = LottieGenericProperty, int8_t, LottieProperty::Type::Integer>; +using LottieScalar = LottieGenericProperty, Point, LottieProperty::Type::Scalar>; +using LottieVector = LottieGenericProperty, Point, LottieProperty::Type::Vector, 0>; +using LottieColor = LottieGenericProperty, RGB32, LottieProperty::Type::Color>; +using LottieOpacity = LottieGenericProperty, uint8_t, LottieProperty::Type::Opacity>; + +#endif //_TVG_LOTTIE_PROPERTY_H_ diff --git a/components/thorvg-main/src/loaders/lottie/tvgLottieRenderPooler.h b/components/thorvg-main/src/loaders/lottie/tvgLottieRenderPooler.h new file mode 100644 index 0000000..03aee55 --- /dev/null +++ b/components/thorvg-main/src/loaders/lottie/tvgLottieRenderPooler.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOTTIE_RENDER_POOLER_H_ +#define _TVG_LOTTIE_RENDER_POOLER_H_ + +#include "tvgCommon.h" +#include "tvgArray.h" +#include "tvgPaint.h" + + +template +struct LottieRenderPooler +{ + Array pooler; + + ~LottieRenderPooler() + { + ARRAY_FOREACH(p, pooler) { + (*p)->unref(); + } + } + + T* pooling(bool copy = false) + { + //return available one. + ARRAY_FOREACH(p, pooler) { + if ((*p)->refCnt() == 1) return *p; + } + + //no empty, generate a new one. + auto p = copy ? static_cast(pooler[0]->duplicate()) : T::gen(); + p->ref(); + pooler.push(p); + return p; + } +}; + + +#endif //_TVG_LOTTIE_RENDER_POOLER_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/meson.build b/components/thorvg-main/src/loaders/meson.build new file mode 100644 index 0000000..0a44918 --- /dev/null +++ b/components/thorvg-main/src/loaders/meson.build @@ -0,0 +1,53 @@ +subloader_dep = [] + +if svg_loader + subdir('svg') +endif + +if ttf_loader + subdir('ttf') +endif + +if lottie_loader + subdir('lottie') +endif + +if png_loader + if get_option('static') + subdir('png') + else + subdir('external_png') + if not png_dep.found() + subdir('png') + endif + endif +endif + +if jpg_loader + if get_option('static') + subdir('jpg') + else + subdir('external_jpg') + if not jpg_dep.found() + subdir('jpg') + endif + endif +endif + +if webp_loader + if get_option('static') + subdir('webp') + else + subdir('external_webp') + if not webp_dep.found() + subdir('webp') + endif + endif +endif + +subdir('raw') + +loader_dep = declare_dependency( + dependencies: subloader_dep, + include_directories : include_directories('.'), +) diff --git a/components/thorvg-main/src/loaders/png/meson.build b/components/thorvg-main/src/loaders/png/meson.build new file mode 100644 index 0000000..aa0bf4a --- /dev/null +++ b/components/thorvg-main/src/loaders/png/meson.build @@ -0,0 +1,11 @@ +source_file = [ + 'tvgLodePng.h', + 'tvgPngLoader.h', + 'tvgLodePng.cpp', + 'tvgPngLoader.cpp', +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/png/tvgLodePng.cpp b/components/thorvg-main/src/loaders/png/tvgLodePng.cpp new file mode 100644 index 0000000..8674f24 --- /dev/null +++ b/components/thorvg-main/src/loaders/png/tvgLodePng.cpp @@ -0,0 +1,2628 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + LodePNG version 20200306 + + Copyright (c) 2005-2020 Lode Vandevenne + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any sourcedistribution. +*/ + +#include "tvgCommon.h" +#include "tvgLodePng.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#if defined(_MSC_VER) && (_MSC_VER >= 1310) /*Visual Studio: A few warning types are not desired here.*/ + #pragma warning( disable : 4244 ) /*implicit conversions: not warned by gcc -Wall -Wextra and requires too much casts*/ + #pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/ +#endif /*_MSC_VER */ + + +/* convince the compiler to inline a function, for use when this measurably improves performance */ +/* inline is not available in C90, but use it when supported by the compiler */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define LODEPNG_INLINE inline +#else + #define LODEPNG_INLINE /* not available */ +#endif + +/* restrict is not available in C90, but use it when supported by the compiler */ +#if (defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) ||\ + (defined(_MSC_VER) && (_MSC_VER >= 1400)) || \ + (defined(__WATCOMC__) && (__WATCOMC__ >= 1250) && !defined(__cplusplus)) + #define LODEPNG_RESTRICT __restrict +#else + #define LODEPNG_RESTRICT /* not available */ +#endif + +#define LODEPNG_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define LODEPNG_MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define LODEPNG_ABS(x) ((x) < 0 ? -(x) : (x)) + + +/* Replacements for C library functions such as memcpy and strlen, to support platforms +where a full C library is not available. The compiler can recognize them and compile +to something as fast. */ + +static void lodepng_memcpy(void* LODEPNG_RESTRICT dst, const void* LODEPNG_RESTRICT src, size_t size) +{ + size_t i; + for (i = 0; i < size; i++) ((char*)dst)[i] = ((const char*)src)[i]; +} + + +static void lodepng_memset(void* LODEPNG_RESTRICT dst, int value, size_t num) +{ + size_t i; + for (i = 0; i < num; i++) ((char*)dst)[i] = (char)value; +} + + +/* does not check memory out of bounds, do not use on untrusted data */ +static size_t lodepng_strlen(const char* a) +{ + const char* orig = a; + /* avoid warning about unused function in case of disabled COMPILE... macros */ + (void)(&lodepng_strlen); + while (*a) a++; + return (size_t)(a - orig); +} + + +/* Safely check if adding two integers will overflow (no undefined +behavior, compiler removing the code, etc...) and output result. */ +static int lodepng_addofl(size_t a, size_t b, size_t* result) +{ + *result = a + b; /* Unsigned addition is well defined and safe in C90 */ + return *result < a; +} + + +/* Safely check if multiplying two integers will overflow (no undefined +behavior, compiler removing the code, etc...) and output result. */ +static int lodepng_mulofl(size_t a, size_t b, size_t* result) +{ + *result = a * b; /* Unsigned multiplication is well defined and safe in C90 */ + return (a != 0 && *result / a != b); +} + + +/* Safely check if a + b > c, even if overflow could happen. */ +static int lodepng_gtofl(size_t a, size_t b, size_t c) +{ + size_t d; + if (lodepng_addofl(a, b, &d)) return 1; + return d > c; +} + + +/* + Often in case of an error a value is assigned to a variable and then it breaks + out of a loop (to go to the cleanup phase of a function). This macro does that. + It makes the error handling code shorter and more readable. + + Example: if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83); +*/ +#define CERROR_BREAK(errorvar, code){\ + errorvar = code;\ + break;\ +} + +/* version of CERROR_BREAK that assumes the common case where the error variable is named "error" */ +#define ERROR_BREAK(code) CERROR_BREAK(error, code) + +/* Set error var to the error code, and return it.*/ +#define CERROR_RETURN_ERROR(errorvar, code){\ + errorvar = code;\ + return code;\ +} + +/* Try the code, if it returns error, also return the error. */ +#define CERROR_TRY_RETURN(call){\ + unsigned error = call;\ + if(error) return error;\ +} + +/* Set error var to the error code, and return from the void function. */ +#define CERROR_RETURN(errorvar, code){\ + errorvar = code;\ + return;\ +} + + +/* dynamic vector of unsigned chars */ +struct ucvector +{ + unsigned char* data; + size_t size; /*used size*/ + size_t allocsize; /*allocated size*/ +}; + + +/* returns 1 if success, 0 if failure ==> nothing done */ +static unsigned ucvector_resize(ucvector* p, size_t size) +{ + if (size > p->allocsize) { + size_t newsize = size + (p->allocsize >> 1u); + auto data = tvg::realloc(p->data, newsize); + if(data) { + p->allocsize = newsize; + p->data = (unsigned char*)data; + } + else return 0; /*error: not enough memory*/ + } + p->size = size; + return 1; /*success*/ +} + + +static ucvector ucvector_init(unsigned char* buffer, size_t size) +{ + ucvector v; + v.data = buffer; + v.allocsize = v.size = size; + return v; +} + + +static unsigned lodepng_read32bitInt(const unsigned char* buffer) +{ + return (((unsigned)buffer[0] << 24u) | ((unsigned)buffer[1] << 16u) | ((unsigned)buffer[2] << 8u) | (unsigned)buffer[3]); +} + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* // End of common code and tools. Begin of Zlib related code. // */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +struct LodePNGBitReader +{ + const unsigned char* data; + size_t size; /*size of data in bytes*/ + size_t bitsize; /*size of data in bits, end of valid bp values, should be 8*size*/ + size_t bp; + unsigned buffer; /*buffer for reading bits. NOTE: 'unsigned' must support at least 32 bits*/ +}; + + +/* data size argument is in bytes. Returns error if size too large causing overflow */ +static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned char* data, size_t size) +{ + size_t temp; + reader->data = data; + reader->size = size; + /* size in bits, return error if overflow (if size_t is 32 bit this supports up to 500MB) */ + if (lodepng_mulofl(size, 8u, &reader->bitsize)) return 105; + /*ensure incremented bp can be compared to bitsize without overflow even when it would be incremented 32 too much and + trying to ensure 32 more bits*/ + if (lodepng_addofl(reader->bitsize, 64u, &temp)) return 105; + reader->bp = 0; + reader->buffer = 0; + return 0; /*ok*/ + } + +/* + ensureBits functions: + Ensures the reader can at least read nbits bits in one or more readBits calls, + safely even if not enough bits are available. + Returns 1 if there are enough bits available, 0 if not. +*/ + +/*See ensureBits documentation above. This one ensures exactly 1 bit */ +/*static unsigned ensureBits1(LodePNGBitReader* reader) { + if(reader->bp >= reader->bitsize) return 0; + reader->buffer = (unsigned)reader->data[reader->bp >> 3u] >> (reader->bp & 7u); + return 1; +}*/ + +/*See ensureBits documentation above. This one ensures up to 9 bits */ +static unsigned ensureBits9(LodePNGBitReader* reader, size_t nbits) +{ + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if (start + 1u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u); + reader->buffer >>= (reader->bp & 7u); + return 1; + } else { + reader->buffer = 0; + if (start + 0u < size) reader->buffer |= reader->data[start + 0]; + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + + +/*See ensureBits documentation above. This one ensures up to 17 bits */ +static unsigned ensureBits17(LodePNGBitReader* reader, size_t nbits) +{ + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if (start + 2u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | ((unsigned)reader->data[start + 2] << 16u); + reader->buffer >>= (reader->bp & 7u); + return 1; + } else { + reader->buffer = 0; + if (start + 0u < size) reader->buffer |= reader->data[start + 0]; + if (start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + + +/*See ensureBits documentation above. This one ensures up to 25 bits */ +static LODEPNG_INLINE unsigned ensureBits25(LodePNGBitReader* reader, size_t nbits) +{ + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if (start + 3u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | ((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u); + reader->buffer >>= (reader->bp & 7u); + return 1; + } else { + reader->buffer = 0; + if (start + 0u < size) reader->buffer |= reader->data[start + 0]; + if (start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); + if (start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + + +/*See ensureBits documentation above. This one ensures up to 32 bits */ +static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbits) +{ + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if(start + 4u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | ((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u); + reader->buffer >>= (reader->bp & 7u); + reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u))); + return 1; + } else { + reader->buffer = 0; + if (start + 0u < size) reader->buffer |= reader->data[start + 0]; + if (start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); + if (start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); + if (start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u); + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + + +/* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */ +static unsigned peekBits(LodePNGBitReader* reader, size_t nbits) +{ + /* The shift allows nbits to be only up to 31. */ + return reader->buffer & ((1u << nbits) - 1u); +} + + +/* Must have enough bits available with ensureBits */ +static void advanceBits(LodePNGBitReader* reader, size_t nbits) +{ + reader->buffer >>= nbits; + reader->bp += nbits; +} + + +/* Must have enough bits available with ensureBits */ +static unsigned readBits(LodePNGBitReader* reader, size_t nbits) +{ + unsigned result = peekBits(reader, nbits); + advanceBits(reader, nbits); + return result; +} + + +/* Public for testing only. steps and result must have numsteps values. */ +unsigned lode_png_test_bitreader(const unsigned char* data, size_t size, size_t numsteps, const size_t* steps, unsigned* result) +{ + size_t i; + LodePNGBitReader reader; + unsigned error = LodePNGBitReader_init(&reader, data, size); + if (error) return 0; + for (i = 0; i < numsteps; i++) { + size_t step = steps[i]; + unsigned ok; + if (step > 25) ok = ensureBits32(&reader, step); + else if (step > 17) ok = ensureBits25(&reader, step); + else if (step > 9) ok = ensureBits17(&reader, step); + else ok = ensureBits9(&reader, step); + if (!ok) return 0; + result[i] = readBits(&reader, step); + } + return 1; +} + + +static unsigned reverseBits(unsigned bits, unsigned num) +{ + /*TODO: implement faster lookup table based version when needed*/ + unsigned i, result = 0; + for (i = 0; i < num; i++) result |= ((bits >> (num - i - 1u)) & 1u) << i; + return result; +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Deflate - Huffman / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#define FIRST_LENGTH_CODE_INDEX 257 +#define LAST_LENGTH_CODE_INDEX 285 +/*256 literals, the end code, some length codes, and 2 unused codes*/ +#define NUM_DEFLATE_CODE_SYMBOLS 288 +/*the distance codes have their own symbols, 30 used, 2 unused*/ +#define NUM_DISTANCE_SYMBOLS 32 +/*the code length codes. 0-15: code lengths, 16: copy previous 3-6 times, 17: 3-10 zeros, 18: 11-138 zeros*/ +#define NUM_CODE_LENGTH_CODES 19 + +/*the base lengths represented by codes 257-285*/ +static const unsigned LENGTHBASE[29] + = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, + 67, 83, 99, 115, 131, 163, 195, 227, 258}; + +/*the extra bits used by codes 257-285 (added to base length)*/ +static const unsigned LENGTHEXTRA[29] + = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 5, 5, 5, 5, 0}; + +/*the base backwards distances (the bits of distance codes appear after length codes and use their own huffman tree)*/ +static const unsigned DISTANCEBASE[30] + = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, + 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; + +/*the extra bits of backwards distances (added to base)*/ +static const unsigned DISTANCEEXTRA[30] + = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, + 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; + +/*the order in which "code length alphabet code lengths" are stored as specified by deflate, out of this the huffman +tree of the dynamic huffman tree lengths is generated*/ +static const unsigned CLCL_ORDER[NUM_CODE_LENGTH_CODES] + = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + +/* ////////////////////////////////////////////////////////////////////////// */ + +/* +Huffman tree struct, containing multiple representations of the tree +*/ +struct HuffmanTree +{ + unsigned* codes; /*the huffman codes (bit patterns representing the symbols)*/ + unsigned* lengths; /*the lengths of the huffman codes*/ + unsigned maxbitlen; /*maximum number of bits a single code can get*/ + unsigned numcodes; /*number of symbols in the alphabet = number of codes*/ + /* for reading only */ + unsigned char* table_len; /*length of symbol from lookup table, or max length if secondary lookup needed*/ + unsigned short* table_value; /*value of symbol from lookup table, or pointer to secondary table if needed*/ +}; + + +static void HuffmanTree_init(HuffmanTree* tree) +{ + tree->codes = 0; + tree->lengths = 0; + tree->table_len = 0; + tree->table_value = 0; +} + + +static void HuffmanTree_cleanup(HuffmanTree* tree) +{ + tvg::free(tree->codes); + tvg::free(tree->lengths); + tvg::free(tree->table_len); + tvg::free(tree->table_value); +} + + +/* amount of bits for first huffman table lookup (aka root bits), see HuffmanTree_makeTable and huffmanDecodeSymbol.*/ +/* values 8u and 9u work the fastest */ +#define FIRSTBITS 9u + +/* a symbol value too big to represent any valid symbol, to indicate reading disallowed huffman bits combination, +which is possible in case of only 0 or 1 present symbols. */ +#define INVALIDSYMBOL 65535u + +/* make table for huffman decoding */ +static unsigned HuffmanTree_makeTable(HuffmanTree* tree) +{ + static const unsigned headsize = 1u << FIRSTBITS; /*size of the first table*/ + static const unsigned mask = (1u << FIRSTBITS) /*headsize*/ - 1u; + size_t i, numpresent, pointer, size; /*total table size*/ + unsigned* maxlens = tvg::malloc(headsize * sizeof(unsigned)); + if (!maxlens) return 83; /*alloc fail*/ + + /* compute maxlens: max total bit length of symbols sharing prefix in the first table*/ + lodepng_memset(maxlens, 0, headsize * sizeof(*maxlens)); + for (i = 0; i < tree->numcodes; i++) { + unsigned symbol = tree->codes[i]; + unsigned l = tree->lengths[i]; + unsigned index; + if(l <= FIRSTBITS) continue; /*symbols that fit in first table don't increase secondary table size*/ + /*get the FIRSTBITS MSBs, the MSBs of the symbol are encoded first. See later comment about the reversing*/ + index = reverseBits(symbol >> (l - FIRSTBITS), FIRSTBITS); + maxlens[index] = LODEPNG_MAX(maxlens[index], l); + } + /* compute total table size: size of first table plus all secondary tables for symbols longer than FIRSTBITS */ + size = headsize; + for (i = 0; i < headsize; ++i) { + unsigned l = maxlens[i]; + if (l > FIRSTBITS) size += (1u << (l - FIRSTBITS)); + } + tree->table_len = tvg::malloc(size * sizeof(*tree->table_len)); + tree->table_value = tvg::malloc(size * sizeof(*tree->table_value)); + if (!tree->table_len || !tree->table_value) { + tvg::free(maxlens); + /* freeing tree->table values is done at a higher scope */ + return 83; /*alloc fail*/ + } + /*initialize with an invalid length to indicate unused entries*/ + for (i = 0; i < size; ++i) tree->table_len[i] = 16; + + /*fill in the first table for long symbols: max prefix size and pointer to secondary tables*/ + pointer = headsize; + for (i = 0; i < headsize; ++i) { + unsigned l = maxlens[i]; + if(l <= FIRSTBITS) continue; + tree->table_len[i] = l; + tree->table_value[i] = pointer; + pointer += (1u << (l - FIRSTBITS)); + } + tvg::free(maxlens); + + /*fill in the first table for short symbols, or secondary table for long symbols*/ + numpresent = 0; + for (i = 0; i < tree->numcodes; ++i) { + unsigned l = tree->lengths[i]; + unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/ + /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/ + unsigned reverse = reverseBits(symbol, l); + if (l == 0) continue; + numpresent++; + + if (l <= FIRSTBITS) { + /*short symbol, fully in first table, replicated num times if l < FIRSTBITS*/ + unsigned num = 1u << (FIRSTBITS - l); + unsigned j; + for (j = 0; j < num; ++j) { + /*bit reader will read the l bits of symbol first, the remaining FIRSTBITS - l bits go to the MSB's*/ + unsigned index = reverse | (j << l); + if(tree->table_len[index] != 16) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ + tree->table_len[index] = l; + tree->table_value[index] = i; + } + } else { + /*long symbol, shares prefix with other long symbols in first lookup table, needs second lookup*/ + /*the FIRSTBITS MSBs of the symbol are the first table index*/ + unsigned index = reverse & mask; + unsigned maxlen = tree->table_len[index]; + /*log2 of secondary table length, should be >= l - FIRSTBITS*/ + unsigned tablelen = maxlen - FIRSTBITS; + unsigned start = tree->table_value[index]; /*starting index in secondary table*/ + unsigned num = 1u << (tablelen - (l - FIRSTBITS)); /*amount of entries of this symbol in secondary table*/ + unsigned j; + if (maxlen < l) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ + for (j = 0; j < num; ++j) { + unsigned reverse2 = reverse >> FIRSTBITS; /* l - FIRSTBITS bits */ + unsigned index2 = start + (reverse2 | (j << (l - FIRSTBITS))); + tree->table_len[index2] = l; + tree->table_value[index2] = i; + } + } + } + + if (numpresent < 2) { + /* In case of exactly 1 symbol, in theory the huffman symbol needs 0 bits, + but deflate uses 1 bit instead. In case of 0 symbols, no symbols can + appear at all, but such huffman tree could still exist (e.g. if distance + codes are never used). In both cases, not all symbols of the table will be + filled in. Fill them in with an invalid symbol value so returning them from + huffmanDecodeSymbol will cause error. */ + for (i = 0; i < size; ++i) { + if (tree->table_len[i] == 16) { + /* As length, use a value smaller than FIRSTBITS for the head table, + and a value larger than FIRSTBITS for the secondary table, to ensure + valid behavior for advanceBits when reading this symbol. */ + tree->table_len[i] = (i < headsize) ? 1 : (FIRSTBITS + 1); + tree->table_value[i] = INVALIDSYMBOL; + } + } + } else { + /* A good huffman tree has N * 2 - 1 nodes, of which N - 1 are internal nodes. + If that is not the case (due to too long length codes), the table will not + have been fully used, and this is an error (not all bit combinations can be + decoded): an oversubscribed huffman tree, indicated by error 55. */ + for (i = 0; i < size; ++i) { + if (tree->table_len[i] == 16) return 55; + } + } + return 0; +} + + +/* + Second step for the ...makeFromLengths and ...makeFromFrequencies functions. + numcodes, lengths and maxbitlen must already be filled in correctly. return + value is error. +*/ +static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree) +{ + unsigned* blcount; + unsigned* nextcode; + unsigned error = 0; + unsigned bits, n; + + tree->codes = tvg::malloc(tree->numcodes * sizeof(unsigned)); + blcount = tvg::malloc((tree->maxbitlen + 1) * sizeof(unsigned)); + nextcode = tvg::malloc((tree->maxbitlen + 1) * sizeof(unsigned)); + if (!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/ + + if (!error) { + for (n = 0; n != tree->maxbitlen + 1; n++) blcount[n] = nextcode[n] = 0; + /*step 1: count number of instances of each code length*/ + for (bits = 0; bits != tree->numcodes; ++bits) ++blcount[tree->lengths[bits]]; + /*step 2: generate the nextcode values*/ + for(bits = 1; bits <= tree->maxbitlen; ++bits) { + nextcode[bits] = (nextcode[bits - 1] + blcount[bits - 1]) << 1u; + } + /*step 3: generate all the codes*/ + for (n = 0; n != tree->numcodes; ++n) { + if (tree->lengths[n] != 0) { + tree->codes[n] = nextcode[tree->lengths[n]]++; + /*remove superfluous bits from the code*/ + tree->codes[n] &= ((1u << tree->lengths[n]) - 1u); + } + } + } + + tvg::free(blcount); + tvg::free(nextcode); + + if (!error) error = HuffmanTree_makeTable(tree); + return error; +} + + +/* + given the code lengths (as stored in the PNG file), generate the tree as defined + by Deflate. maxbitlen is the maximum bits that a code in the tree can have. + return value is error. +*/ +static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* bitlen, size_t numcodes, unsigned maxbitlen) +{ + unsigned i; + tree->lengths = tvg::malloc(numcodes * sizeof(unsigned)); + if (!tree->lengths) return 83; /*alloc fail*/ + for (i = 0; i != numcodes; ++i) tree->lengths[i] = bitlen[i]; + tree->numcodes = (unsigned)numcodes; /*number of symbols*/ + tree->maxbitlen = maxbitlen; + return HuffmanTree_makeFromLengths2(tree); +} + + +/*get the literal and length code tree of a deflated block with fixed tree, as per the deflate specification*/ +static unsigned generateFixedLitLenTree(HuffmanTree* tree) +{ + unsigned i, error = 0; + unsigned* bitlen = tvg::malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned)); + if (!bitlen) return 83; /*alloc fail*/ + + /*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/ + for (i = 0; i <= 143; ++i) bitlen[i] = 8; + for (i = 144; i <= 255; ++i) bitlen[i] = 9; + for (i = 256; i <= 279; ++i) bitlen[i] = 7; + for (i = 280; i <= 287; ++i) bitlen[i] = 8; + + error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DEFLATE_CODE_SYMBOLS, 15); + + tvg::free(bitlen); + return error; +} + + +/*get the distance code tree of a deflated block with fixed tree, as specified in the deflate specification*/ +static unsigned generateFixedDistanceTree(HuffmanTree* tree) +{ + unsigned i, error = 0; + unsigned* bitlen = tvg::malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned)); + if (!bitlen) return 83; /*alloc fail*/ + + /*there are 32 distance codes, but 30-31 are unused*/ + for (i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen[i] = 5; + error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DISTANCE_SYMBOLS, 15); + + tvg::free(bitlen); + return error; +} + + +/* + returns the code. The bit reader must already have been ensured at least 15 bits +*/ +static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree* codetree) +{ + unsigned short code = peekBits(reader, FIRSTBITS); + unsigned short l = codetree->table_len[code]; + unsigned short value = codetree->table_value[code]; + if (l <= FIRSTBITS) { + advanceBits(reader, l); + return value; + } else { + unsigned index2; + advanceBits(reader, FIRSTBITS); + index2 = value + peekBits(reader, l - FIRSTBITS); + advanceBits(reader, codetree->table_len[index2] - FIRSTBITS); + return codetree->table_value[index2]; + } +} + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Inflator (Decompressor) / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/*get the tree of a deflated block with fixed tree, as specified in the deflate specification +Returns error code.*/ +static unsigned getTreeInflateFixed(HuffmanTree* tree_ll, HuffmanTree* tree_d) +{ + unsigned error = generateFixedLitLenTree(tree_ll); + if (error) return error; + return generateFixedDistanceTree(tree_d); +} + + +/*get the tree of a deflated block with dynamic tree, the tree itself is also Huffman compressed with a known tree*/ +static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d, LodePNGBitReader* reader) +{ + /*make sure that length values that aren't filled in will be 0, or a wrong tree will be generated*/ + unsigned error = 0; + unsigned n, HLIT, HDIST, HCLEN, i; + + /*see comments in deflateDynamic for explanation of the context and these variables, it is analogous*/ + unsigned* bitlen_ll = 0; /*lit,len code lengths*/ + unsigned* bitlen_d = 0; /*dist code lengths*/ + /*code length code lengths ("clcl"), the bit lengths of the huffman tree used to compress bitlen_ll and bitlen_d*/ + unsigned* bitlen_cl = 0; + HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/ + + if (!ensureBits17(reader, 14)) return 49; /*error: the bit pointer is or will go past the memory*/ + + /*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/ + HLIT = readBits(reader, 5) + 257; + /*number of distance codes. Unlike the spec, the value 1 is added to it here already*/ + HDIST = readBits(reader, 5) + 1; + /*number of code length codes. Unlike the spec, the value 4 is added to it here already*/ + HCLEN = readBits(reader, 4) + 4; + + bitlen_cl = tvg::malloc(NUM_CODE_LENGTH_CODES * sizeof(unsigned)); + if(!bitlen_cl) return 83 /*alloc fail*/; + + HuffmanTree_init(&tree_cl); + + while (!error) { + /*read the code length codes out of 3 * (amount of code length codes) bits*/ + if (lodepng_gtofl(reader->bp, HCLEN * 3, reader->bitsize)) { + ERROR_BREAK(50); /*error: the bit pointer is or will go past the memory*/ + } + for (i = 0; i != HCLEN; ++i) { + ensureBits9(reader, 3); /*out of bounds already checked above */ + bitlen_cl[CLCL_ORDER[i]] = readBits(reader, 3); + } + for (i = HCLEN; i != NUM_CODE_LENGTH_CODES; ++i) { + bitlen_cl[CLCL_ORDER[i]] = 0; + } + + error = HuffmanTree_makeFromLengths(&tree_cl, bitlen_cl, NUM_CODE_LENGTH_CODES, 7); + if(error) break; + + /*now we can use this tree to read the lengths for the tree that this function will return*/ + bitlen_ll = tvg::malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned)); + bitlen_d = tvg::malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned)); + if (!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/); + lodepng_memset(bitlen_ll, 0, NUM_DEFLATE_CODE_SYMBOLS * sizeof(*bitlen_ll)); + lodepng_memset(bitlen_d, 0, NUM_DISTANCE_SYMBOLS * sizeof(*bitlen_d)); + + /*i is the current symbol we're reading in the part that contains the code lengths of lit/len and dist codes*/ + i = 0; + while (i < HLIT + HDIST) { + unsigned code; + ensureBits25(reader, 22); /* up to 15 bits for huffman code, up to 7 extra bits below*/ + code = huffmanDecodeSymbol(reader, &tree_cl); + if (code <= 15) /*a length code*/ { + if (i < HLIT) bitlen_ll[i] = code; + else bitlen_d[i - HLIT] = code; + ++i; + } else if (code == 16) /*repeat previous*/ { + unsigned replength = 3; /*read in the 2 bits that indicate repeat length (3-6)*/ + unsigned value; /*set value to the previous code*/ + + if (i == 0) ERROR_BREAK(54); /*can't repeat previous if i is 0*/ + + replength += readBits(reader, 2); + + if (i < HLIT + 1) value = bitlen_ll[i - 1]; + else value = bitlen_d[i - HLIT - 1]; + /*repeat this value in the next lengths*/ + for (n = 0; n < replength; ++n) { + if (i >= HLIT + HDIST) ERROR_BREAK(13); /*error: i is larger than the amount of codes*/ + if (i < HLIT) bitlen_ll[i] = value; + else bitlen_d[i - HLIT] = value; + ++i; + } + } else if(code == 17) /*repeat "0" 3-10 times*/ { + unsigned replength = 3; /*read in the bits that indicate repeat length*/ + replength += readBits(reader, 3); + + /*repeat this value in the next lengths*/ + for (n = 0; n < replength; ++n) { + if (i >= HLIT + HDIST) ERROR_BREAK(14); /*error: i is larger than the amount of codes*/ + + if (i < HLIT) bitlen_ll[i] = 0; + else bitlen_d[i - HLIT] = 0; + ++i; + } + } else if(code == 18) /*repeat "0" 11-138 times*/ { + unsigned replength = 11; /*read in the bits that indicate repeat length*/ + replength += readBits(reader, 7); + + /*repeat this value in the next lengths*/ + for (n = 0; n < replength; ++n) { + if(i >= HLIT + HDIST) ERROR_BREAK(15); /*error: i is larger than the amount of codes*/ + + if(i < HLIT) bitlen_ll[i] = 0; + else bitlen_d[i - HLIT] = 0; + ++i; + } + } else /*if(code == INVALIDSYMBOL)*/ { + ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ + } + /*check if any of the ensureBits above went out of bounds*/ + if (reader->bp > reader->bitsize) { + /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol + (10=no endcode, 11=wrong jump outside of tree)*/ + /* TODO: revise error codes 10,11,50: the above comment is no longer valid */ + ERROR_BREAK(50); /*error, bit pointer jumps past memory*/ + } + } + if (error) break; + + if (bitlen_ll[256] == 0) ERROR_BREAK(64); /*the length of the end code 256 must be larger than 0*/ + + /*now we've finally got HLIT and HDIST, so generate the code trees, and the function is done*/ + error = HuffmanTree_makeFromLengths(tree_ll, bitlen_ll, NUM_DEFLATE_CODE_SYMBOLS, 15); + if (error) break; + error = HuffmanTree_makeFromLengths(tree_d, bitlen_d, NUM_DISTANCE_SYMBOLS, 15); + + break; /*end of error-while*/ + } + + tvg::free(bitlen_cl); + tvg::free(bitlen_ll); + tvg::free(bitlen_d); + HuffmanTree_cleanup(&tree_cl); + + return error; +} + + +/*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/ +static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader, unsigned btype) +{ + unsigned error = 0; + HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/ + HuffmanTree tree_d; /*the huffman tree for distance codes*/ + + HuffmanTree_init(&tree_ll); + HuffmanTree_init(&tree_d); + + if (btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d); + else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader); + + while (!error) /*decode all symbols until end reached, breaks at end code*/ { + /*code_ll is literal, length or end code*/ + unsigned code_ll; + ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */ + code_ll = huffmanDecodeSymbol(reader, &tree_ll); + if (code_ll <= 255) /*literal symbol*/ { + if (!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/); + out->data[out->size - 1] = (unsigned char)code_ll; + } else if (code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ { + unsigned code_d, distance; + unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/ + size_t start, backward, length; + + /*part 1: get length base*/ + length = LENGTHBASE[code_ll - FIRST_LENGTH_CODE_INDEX]; + + /*part 2: get extra bits and add the value of that to length*/ + numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX]; + if (numextrabits_l != 0) { + /* bits already ensured above */ + length += readBits(reader, numextrabits_l); + } + + /*part 3: get distance code*/ + ensureBits32(reader, 28); /* up to 15 for the huffman symbol, up to 13 for the extra bits */ + code_d = huffmanDecodeSymbol(reader, &tree_d); + if (code_d > 29) { + if (code_d <= 31) { + ERROR_BREAK(18); /*error: invalid distance code (30-31 are never used)*/ + } else /* if(code_d == INVALIDSYMBOL) */{ + ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ + } + } + distance = DISTANCEBASE[code_d]; + + /*part 4: get extra bits from distance*/ + numextrabits_d = DISTANCEEXTRA[code_d]; + if (numextrabits_d != 0) { + /* bits already ensured above */ + distance += readBits(reader, numextrabits_d); + } + + /*part 5: fill in all the out[n] values based on the length and dist*/ + start = out->size; + if (distance > start) ERROR_BREAK(52); /*too long backward distance*/ + backward = start - distance; + + if (!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/); + if (distance < length) { + size_t forward; + lodepng_memcpy(out->data + start, out->data + backward, distance); + start += distance; + for (forward = distance; forward < length; ++forward) { + out->data[start++] = out->data[backward++]; + } + } else { + lodepng_memcpy(out->data + start, out->data + backward, length); + } + } else if (code_ll == 256) { + break; /*end code, break the loop*/ + } else /*if(code_ll == INVALIDSYMBOL)*/ { + ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ + } + /*check if any of the ensureBits above went out of bounds*/ + if (reader->bp > reader->bitsize) { + /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol + (10=no endcode, 11=wrong jump outside of tree)*/ + /* TODO: revise error codes 10,11,50: the above comment is no longer valid */ + ERROR_BREAK(51); /*error, bit pointer jumps past memory*/ + } + } + + HuffmanTree_cleanup(&tree_ll); + HuffmanTree_cleanup(&tree_d); + + return error; +} + + +static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader, const LodePNGDecompressSettings* settings) +{ + size_t bytepos; + size_t size = reader->size; + unsigned LEN, NLEN, error = 0; + + /*go to first boundary of byte*/ + bytepos = (reader->bp + 7u) >> 3u; + + /*read LEN (2 bytes) and NLEN (2 bytes)*/ + if (bytepos + 4 >= size) return 52; /*error, bit pointer will jump past memory*/ + LEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2; + NLEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2; + + /*check if 16-bit NLEN is really the one's complement of LEN*/ + if (!settings->ignore_nlen && LEN + NLEN != 65535) { + return 21; /*error: NLEN is not one's complement of LEN*/ + } + + if (!ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/ + + /*read the literal data: LEN bytes are now stored in the out buffer*/ + if (bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/ + + lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN); + bytepos += LEN; + + reader->bp = bytepos << 3u; + + return error; +} + + +static unsigned lodepng_inflatev(ucvector* out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) +{ + unsigned BFINAL = 0; + LodePNGBitReader reader; + unsigned error = LodePNGBitReader_init(&reader, in, insize); + + if (error) return error; + + while (!BFINAL) { + unsigned BTYPE; + if (!ensureBits9(&reader, 3)) return 52; /*error, bit pointer will jump past memory*/ + BFINAL = readBits(&reader, 1); + BTYPE = readBits(&reader, 2); + + if (BTYPE == 3) return 20; /*error: invalid BTYPE*/ + else if (BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/ + else error = inflateHuffmanBlock(out, &reader, BTYPE); /*compression, BTYPE 01 or 10*/ + + if (error) return error; + } + + return error; +} + + +static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) +{ + if (settings->custom_inflate) { + unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings); + out->allocsize = out->size; + return error; + } else { + return lodepng_inflatev(out, in, insize, settings); + } +} + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Adler32 / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +static unsigned update_adler32(unsigned adler, const unsigned char* data, unsigned len) +{ + unsigned s1 = adler & 0xffffu; + unsigned s2 = (adler >> 16u) & 0xffffu; + + while (len != 0u) { + unsigned i; + /*at least 5552 sums can be done before the sums overflow, saving a lot of module divisions*/ + unsigned amount = len > 5552u ? 5552u : len; + len -= amount; + for (i = 0; i != amount; ++i) { + s1 += (*data++); + s2 += s1; + } + s1 %= 65521u; + s2 %= 65521u; + } + + return (s2 << 16u) | s1; +} + +/*Return the adler32 of the bytes data[0..len-1]*/ +static unsigned adler32(const unsigned char* data, unsigned len) +{ + return update_adler32(1u, data, len); +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Zlib / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +static unsigned lodepng_zlib_decompressv(ucvector* out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) +{ + unsigned error = 0; + unsigned CM, CINFO, FDICT; + + if (insize < 2) return 53; /*error, size of zlib data too small*/ + /*read information from zlib header*/ + if ((in[0] * 256 + in[1]) % 31 != 0) { + /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/ + return 24; + } + + CM = in[0] & 15; + CINFO = (in[0] >> 4) & 15; + /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/ + FDICT = (in[1] >> 5) & 1; + /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/ + + if (CM != 8 || CINFO > 7) { + /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/ + return 25; + } + if (FDICT != 0) { + /*error: the specification of PNG says about the zlib stream: + "The additional flags shall not specify a preset dictionary."*/ + return 26; + } + + error = inflatev(out, in + 2, insize - 2, settings); + if (error) return error; + + if (!settings->ignore_adler32) { + unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]); + unsigned checksum = adler32(out->data, (unsigned)(out->size)); + if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/ + } + + return 0; /*no error*/ +} + + +/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */ +static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size, const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) +{ + if(settings->custom_zlib) { + return settings->custom_zlib(out, outsize, in, insize, settings); + } else { + unsigned error; + ucvector v = ucvector_init(*out, *outsize); + if (expected_size) { + /*reserve the memory to avoid intermediate reallocations*/ + ucvector_resize(&v, *outsize + expected_size); + v.size = *outsize; + } + error = lodepng_zlib_decompressv(&v, in, insize, settings); + *out = v.data; + *outsize = v.size; + return error; + } +} + + +static void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) +{ + settings->ignore_adler32 = 0; + settings->ignore_nlen = 0; + settings->custom_zlib = 0; + settings->custom_inflate = 0; + settings->custom_context = 0; +} + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* // End of Zlib related code. Begin of PNG related code. // */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + + +#if 0 //thorvg don't use crc +/* CRC polynomial: 0xedb88320 */ +static unsigned lodepng_crc32_table[256] = { + 0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u, + 249268274u, 2044508324u, 3772115230u, 2547177864u, 162941995u, 2125561021u, 3887607047u, 2428444049u, + 498536548u, 1789927666u, 4089016648u, 2227061214u, 450548861u, 1843258603u, 4107580753u, 2211677639u, + 325883990u, 1684777152u, 4251122042u, 2321926636u, 335633487u, 1661365465u, 4195302755u, 2366115317u, + 997073096u, 1281953886u, 3579855332u, 2724688242u, 1006888145u, 1258607687u, 3524101629u, 2768942443u, + 901097722u, 1119000684u, 3686517206u, 2898065728u, 853044451u, 1172266101u, 3705015759u, 2882616665u, + 651767980u, 1373503546u, 3369554304u, 3218104598u, 565507253u, 1454621731u, 3485111705u, 3099436303u, + 671266974u, 1594198024u, 3322730930u, 2970347812u, 795835527u, 1483230225u, 3244367275u, 3060149565u, + 1994146192u, 31158534u, 2563907772u, 4023717930u, 1907459465u, 112637215u, 2680153253u, 3904427059u, + 2013776290u, 251722036u, 2517215374u, 3775830040u, 2137656763u, 141376813u, 2439277719u, 3865271297u, + 1802195444u, 476864866u, 2238001368u, 4066508878u, 1812370925u, 453092731u, 2181625025u, 4111451223u, + 1706088902u, 314042704u, 2344532202u, 4240017532u, 1658658271u, 366619977u, 2362670323u, 4224994405u, + 1303535960u, 984961486u, 2747007092u, 3569037538u, 1256170817u, 1037604311u, 2765210733u, 3554079995u, + 1131014506u, 879679996u, 2909243462u, 3663771856u, 1141124467u, 855842277u, 2852801631u, 3708648649u, + 1342533948u, 654459306u, 3188396048u, 3373015174u, 1466479909u, 544179635u, 3110523913u, 3462522015u, + 1591671054u, 702138776u, 2966460450u, 3352799412u, 1504918807u, 783551873u, 3082640443u, 3233442989u, + 3988292384u, 2596254646u, 62317068u, 1957810842u, 3939845945u, 2647816111u, 81470997u, 1943803523u, + 3814918930u, 2489596804u, 225274430u, 2053790376u, 3826175755u, 2466906013u, 167816743u, 2097651377u, + 4027552580u, 2265490386u, 503444072u, 1762050814u, 4150417245u, 2154129355u, 426522225u, 1852507879u, + 4275313526u, 2312317920u, 282753626u, 1742555852u, 4189708143u, 2394877945u, 397917763u, 1622183637u, + 3604390888u, 2714866558u, 953729732u, 1340076626u, 3518719985u, 2797360999u, 1068828381u, 1219638859u, + 3624741850u, 2936675148u, 906185462u, 1090812512u, 3747672003u, 2825379669u, 829329135u, 1181335161u, + 3412177804u, 3160834842u, 628085408u, 1382605366u, 3423369109u, 3138078467u, 570562233u, 1426400815u, + 3317316542u, 2998733608u, 733239954u, 1555261956u, 3268935591u, 3050360625u, 752459403u, 1541320221u, + 2607071920u, 3965973030u, 1969922972u, 40735498u, 2617837225u, 3943577151u, 1913087877u, 83908371u, + 2512341634u, 3803740692u, 2075208622u, 213261112u, 2463272603u, 3855990285u, 2094854071u, 198958881u, + 2262029012u, 4057260610u, 1759359992u, 534414190u, 2176718541u, 4139329115u, 1873836001u, 414664567u, + 2282248934u, 4279200368u, 1711684554u, 285281116u, 2405801727u, 4167216745u, 1634467795u, 376229701u, + 2685067896u, 3608007406u, 1308918612u, 956543938u, 2808555105u, 3495958263u, 1231636301u, 1047427035u, + 2932959818u, 3654703836u, 1088359270u, 936918000u, 2847714899u, 3736837829u, 1202900863u, 817233897u, + 3183342108u, 3401237130u, 1404277552u, 615818150u, 3134207493u, 3453421203u, 1423857449u, 601450431u, + 3009837614u, 3294710456u, 1567103746u, 711928724u, 3020668471u, 3272380065u, 1510334235u, 755167117u +}; + + +/* Calculate CRC32 of buffer + Return the CRC of the bytes buf[0..len-1]. */ +static unsigned lodepng_crc32(const unsigned char* data, size_t length) +{ + unsigned r = 0xffffffffu; + size_t i; + for (i = 0; i < length; ++i) { + r = lodepng_crc32_table[(r ^ data[i]) & 0xffu] ^ (r >> 8u); + } + return r ^ 0xffffffffu; +} +#endif + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Reading and writing PNG color channel bits / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/* The color channel bits of less-than-8-bit pixels are read with the MSB of bytes first, +so LodePNGBitWriter and LodePNGBitReader can't be used for those. */ + +static unsigned char readBitFromReversedStream(size_t* bitpointer, const unsigned char* bitstream) +{ + unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1); + ++(*bitpointer); + return result; +} + + +/* TODO: make this faster */ +static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits) +{ + unsigned result = 0; + size_t i; + for (i = 0 ; i < nbits; ++i) { + result <<= 1u; + result |= (unsigned)readBitFromReversedStream(bitpointer, bitstream); + } + return result; +} + + +static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, unsigned char bit) +{ + /*the current bit in bitstream may be 0 or 1 for this to work*/ + if (bit == 0) bitstream[(*bitpointer) >> 3u] &= (unsigned char)(~(1u << (7u - ((*bitpointer) & 7u)))); + else bitstream[(*bitpointer) >> 3u] |= (1u << (7u - ((*bitpointer) & 7u))); + ++(*bitpointer); +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / PNG chunks / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/* + The lodepng_chunk functions are normally not needed, except to traverse the + unknown chunks stored in the LodePNGInfo struct, or add new ones to it. + It also allows traversing the chunks of an encoded PNG file yourself. + + The chunk pointer always points to the beginning of the chunk itself, that is + the first byte of the 4 length bytes. + + In the PNG file format, chunks have the following format: + -4 bytes length: length of the data of the chunk in bytes (chunk itself is 12 bytes longer) + -4 bytes chunk type (ASCII a-z,A-Z only, see below) + -length bytes of data (may be 0 bytes if length was 0) + -4 bytes of CRC, computed on chunk name + data + + The first chunk starts at the 8th byte of the PNG file, the entire rest of the file + exists out of concatenated chunks with the above format. + + PNG standard chunk ASCII naming conventions: + -First byte: uppercase = critical, lowercase = ancillary + -Second byte: uppercase = public, lowercase = private + -Third byte: must be uppercase + -Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy +*/ + + +/* + Gets the length of the data of the chunk. Total chunk length has 12 bytes more. + There must be at least 4 bytes to read from. If the result value is too large, + it may be corrupt data. +*/ +static unsigned lodepng_chunk_length(const unsigned char* chunk) +{ + return lodepng_read32bitInt(&chunk[0]); +} + + +/* check if the type is the given type */ +static unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type) +{ + if (lodepng_strlen(type) != 4) return 0; + return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]); +} + + +/* 0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard) */ +static unsigned char lodepng_chunk_ancillary(const unsigned char* chunk) +{ + return ((chunk[4] & 32) != 0); +} + + +static const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk) +{ + return &chunk[8]; +} + +#if 0 //thorvg don't use crc +/* returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!) */ +static unsigned lodepng_chunk_check_crc(const unsigned char* chunk) +{ + unsigned length = lodepng_chunk_length(chunk); + unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]); + /*the CRC is taken of the data and the 4 chunk type letters, not the length*/ + unsigned checksum = lodepng_crc32(&chunk[4], length + 4); + if (CRC != checksum) return 1; + else return 0; +} +#endif + +static const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) +{ + if (chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/ + if (chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 + && chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) { + /* Is PNG magic header at start of PNG file. Jump to first actual chunk. */ + return chunk + 8; + } else { + size_t total_chunk_length; + const unsigned char* result; + if (lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; + result = chunk + total_chunk_length; + if (result < chunk) return end; /*pointer overflow*/ + return result; + } +} + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Color types, channels, bits / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/*checks if the colortype is valid and the bitdepth bd is allowed for this colortype. +Return value is a LodePNG error code.*/ +static unsigned checkColorValidity(LodePNGColorType colortype, unsigned bd) +{ + switch(colortype) { + case LCT_GREY: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16)) return 37; break; + case LCT_RGB: if(!( bd == 8 || bd == 16)) return 37; break; + case LCT_PALETTE: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 )) return 37; break; + case LCT_GREY_ALPHA: if(!( bd == 8 || bd == 16)) return 37; break; + case LCT_RGBA: if(!( bd == 8 || bd == 16)) return 37; break; + case LCT_MAX_OCTET_VALUE: return 31; /* invalid color type */ + default: return 31; /* invalid color type */ + } + return 0; /*allowed color type / bits combination*/ +} + + +static unsigned getNumColorChannels(LodePNGColorType colortype) +{ + switch(colortype) { + case LCT_GREY: return 1; + case LCT_RGB: return 3; + case LCT_PALETTE: return 1; + case LCT_GREY_ALPHA: return 2; + case LCT_RGBA: return 4; + case LCT_MAX_OCTET_VALUE: return 0; /* invalid color type */ + default: return 0; /*invalid color type*/ + } +} + + +static unsigned lodepng_get_bpp_lct(LodePNGColorType colortype, unsigned bitdepth) +{ + /*bits per pixel is amount of channels * bits per channel*/ + return getNumColorChannels(colortype) * bitdepth; +} + + +static void lodepng_color_mode_init(LodePNGColorMode* info) +{ + info->key_defined = 0; + info->key_r = info->key_g = info->key_b = 0; + info->colortype = LCT_RGBA; + info->bitdepth = 8; + info->palette = 0; + info->palettesize = 0; +} + + +/*allocates palette memory if needed, and initializes all colors to black*/ +static void lodepng_color_mode_alloc_palette(LodePNGColorMode* info) +{ + size_t i; + /*if the palette is already allocated, it will have size 1024 so no reallocation needed in that case*/ + /*the palette must have room for up to 256 colors with 4 bytes each.*/ + if (!info->palette) info->palette = tvg::malloc(1024); + if (!info->palette) return; /*alloc fail*/ + for (i = 0; i != 256; ++i) { + /*Initialize all unused colors with black, the value used for invalid palette indices. + This is an error according to the PNG spec, but common PNG decoders make it black instead. + That makes color conversion slightly faster due to no error handling needed.*/ + info->palette[i * 4 + 0] = 0; + info->palette[i * 4 + 1] = 0; + info->palette[i * 4 + 2] = 0; + info->palette[i * 4 + 3] = 255; + } +} + +static void lodepng_palette_clear(LodePNGColorMode* info) +{ + if (info->palette) tvg::free(info->palette); + info->palette = 0; + info->palettesize = 0; +} + + +static void lodepng_color_mode_cleanup(LodePNGColorMode* info) +{ + lodepng_palette_clear(info); +} + + +/*return value is error code (0 means no error)*/ +static unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source) +{ + lodepng_color_mode_cleanup(dest); + lodepng_memcpy(dest, source, sizeof(LodePNGColorMode)); + if (source->palette) { + dest->palette = tvg::malloc(1024); + if (!dest->palette && source->palettesize) return 83; /*alloc fail*/ + lodepng_memcpy(dest->palette, source->palette, source->palettesize * 4); + } + return 0; +} + + +static int lodepng_color_mode_equal(const LodePNGColorMode* a, const LodePNGColorMode* b) +{ + size_t i; + if (a->colortype != b->colortype) return 0; + if (a->bitdepth != b->bitdepth) return 0; + if (a->key_defined != b->key_defined) return 0; + if (a->key_defined) { + if(a->key_r != b->key_r) return 0; + if(a->key_g != b->key_g) return 0; + if(a->key_b != b->key_b) return 0; + } + if (a->palettesize != b->palettesize) return 0; + for (i = 0; i != a->palettesize * 4; ++i) { + if (a->palette[i] != b->palette[i]) return 0; + } + return 1; +} + + +static size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) +{ + size_t bpp = lodepng_get_bpp_lct(colortype, bitdepth); + size_t n = (size_t)w * (size_t)h; + return ((n / 8u) * bpp) + ((n & 7u) * bpp + 7u) / 8u; +} + + +/* Returns the byte size of a raw image buffer with given width, height and color mode */ +static size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color) +{ + return lodepng_get_raw_size_lct(w, h, color->colortype, color->bitdepth); +} + + +/*in an idat chunk, each scanline is a multiple of 8 bits, unlike the lodepng output buffer, +and in addition has one extra byte per line: the filter byte. So this gives a larger +result than lodepng_get_raw_size. Set h to 1 to get the size of 1 row including filter byte. */ +static size_t lodepng_get_raw_size_idat(unsigned w, unsigned h, unsigned bpp) +{ + /* + 1 for the filter byte, and possibly plus padding bits per line. */ + /* Ignoring casts, the expression is equal to (w * bpp + 7) / 8 + 1, but avoids overflow of w * bpp */ + size_t line = ((size_t)(w / 8u) * bpp) + 1u + ((w & 7u) * bpp + 7u) / 8u; + return (size_t)h * line; +} + + +/* Safely checks whether size_t overflow can be caused due to amount of pixels. + This check is overcautious rather than precise. If this check indicates no overflow, + you can safely compute in a size_t (but not an unsigned): + -(size_t)w * (size_t)h * 8 + -amount of bytes in IDAT (including filter, padding and Adam7 bytes) + -amount of bytes in raw color model + Returns 1 if overflow possible, 0 if not. */ +static int lodepng_pixel_overflow(unsigned w, unsigned h, const LodePNGColorMode* pngcolor, const LodePNGColorMode* rawcolor) +{ + size_t bpp = LODEPNG_MAX(lodepng_get_bpp_lct(pngcolor->colortype, pngcolor->bitdepth), lodepng_get_bpp_lct(rawcolor->colortype, rawcolor->bitdepth)); + size_t numpixels, total; + size_t line; /* bytes per line in worst case */ + + if (lodepng_mulofl((size_t)w, (size_t)h, &numpixels)) return 1; + if (lodepng_mulofl(numpixels, 8, &total)) return 1; /* bit pointer with 8-bit color, or 8 bytes per channel color */ + + /* Bytes per scanline with the expression "(w / 8u) * bpp) + ((w & 7u) * bpp + 7u) / 8u" */ + if (lodepng_mulofl((size_t)(w / 8u), bpp, &line)) return 1; + if (lodepng_addofl(line, ((w & 7u) * bpp + 7u) / 8u, &line)) return 1; + + if (lodepng_addofl(line, 5, &line)) return 1; /* 5 bytes overhead per line: 1 filterbyte, 4 for Adam7 worst case */ + if (lodepng_mulofl(line, h, &total)) return 1; /* Total bytes in worst case */ + + return 0; /* no overflow */ +} + + +static void lodepng_info_init(LodePNGInfo* info) +{ + lodepng_color_mode_init(&info->color); + info->interlace_method = 0; + info->compression_method = 0; + info->filter_method = 0; +} + + +static void lodepng_info_cleanup(LodePNGInfo* info) +{ + lodepng_color_mode_cleanup(&info->color); +} + + +/* index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to */ +static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) +{ + unsigned m = bits == 1 ? 7 : bits == 2 ? 3 : 1; /*8 / bits - 1*/ + /*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for second half*/ + unsigned p = index & m; + in &= (1u << bits) - 1u; /*filter out any other bits of the input value*/ + in = in << (bits * (m - p)); + if(p == 0) out[index * bits / 8u] = in; + else out[index * bits / 8u] |= in; +} + +/* + One node of a color tree + This is the data structure used to count the number of unique colors and to get a palette + index for a color. It's like an octree, but because the alpha channel is used too, each + node has 16 instead of 8 children. +*/ +struct ColorTree +{ + ColorTree* children[16]; /* up to 16 pointers to ColorTree of next level */ + int index; /* the payload. Only has a meaningful value if this is in the last level */ +}; + +static void color_tree_init(ColorTree* tree) +{ + lodepng_memset(tree->children, 0, 16 * sizeof(*tree->children)); + tree->index = -1; +} + +static void color_tree_cleanup(ColorTree* tree) +{ + int i; + for (i = 0; i != 16; ++i) { + if(tree->children[i]) { + color_tree_cleanup(tree->children[i]); + tvg::free(tree->children[i]); + } + } +} + + +/* returns -1 if color not present, its index otherwise */ +static int color_tree_get(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + int bit = 0; + for (bit = 0; bit < 8; ++bit) { + int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1); + if (!tree->children[i]) return -1; + else tree = tree->children[i]; + } + return tree ? tree->index : -1; +} + + +/* color is not allowed to already exist. + Index should be >= 0 (it's signed to be compatible with using -1 for "doesn't exist") + Returns error code, or 0 if ok */ +static unsigned color_tree_add(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned index) +{ + int bit; + for (bit = 0; bit < 8; ++bit) { + int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1); + if (!tree->children[i]) { + tree->children[i] = tvg::malloc(sizeof(ColorTree)); + if (!tree->children[i]) return 83; /*alloc fail*/ + color_tree_init(tree->children[i]); + } + tree = tree->children[i]; + } + tree->index = (int)index; + return 0; +} + +/* put a pixel, given its RGBA color, into image of any color type */ +static unsigned rgba8ToPixel(unsigned char* out, size_t i, const LodePNGColorMode* mode, ColorTree* tree /*for palette*/, unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + if (mode->colortype == LCT_GREY) { + unsigned char gray = r; /*((unsigned short)r + g + b) / 3u;*/ + if (mode->bitdepth == 8) out[i] = gray; + else if (mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = gray; + else { + /*take the most significant bits of gray*/ + gray = ((unsigned)gray >> (8u - mode->bitdepth)) & ((1u << mode->bitdepth) - 1u); + addColorBits(out, i, mode->bitdepth, gray); + } + } else if (mode->colortype == LCT_RGB) { + if (mode->bitdepth == 8) { + out[i * 3 + 0] = r; + out[i * 3 + 1] = g; + out[i * 3 + 2] = b; + } else { + out[i * 6 + 0] = out[i * 6 + 1] = r; + out[i * 6 + 2] = out[i * 6 + 3] = g; + out[i * 6 + 4] = out[i * 6 + 5] = b; + } + } else if(mode->colortype == LCT_PALETTE) { + int index = color_tree_get(tree, r, g, b, a); + if (index < 0) return 82; /*color not in palette*/ + if (mode->bitdepth == 8) out[i] = index; + else addColorBits(out, i, mode->bitdepth, (unsigned)index); + } else if (mode->colortype == LCT_GREY_ALPHA) { + unsigned char gray = r; /*((unsigned short)r + g + b) / 3u;*/ + if (mode->bitdepth == 8) { + out[i * 2 + 0] = gray; + out[i * 2 + 1] = a; + } else if (mode->bitdepth == 16) { + out[i * 4 + 0] = out[i * 4 + 1] = gray; + out[i * 4 + 2] = out[i * 4 + 3] = a; + } + } else if (mode->colortype == LCT_RGBA) { + if (mode->bitdepth == 8) { + out[i * 4 + 0] = r; + out[i * 4 + 1] = g; + out[i * 4 + 2] = b; + out[i * 4 + 3] = a; + } else { + out[i * 8 + 0] = out[i * 8 + 1] = r; + out[i * 8 + 2] = out[i * 8 + 3] = g; + out[i * 8 + 4] = out[i * 8 + 5] = b; + out[i * 8 + 6] = out[i * 8 + 7] = a; + } + } + return 0; /*no error*/ +} + + +/* put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type */ +static void rgba16ToPixel(unsigned char* out, size_t i, const LodePNGColorMode* mode, unsigned short r, unsigned short g, unsigned short b, unsigned short a) +{ + if (mode->colortype == LCT_GREY) { + unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ + out[i * 2 + 0] = (gray >> 8) & 255; + out[i * 2 + 1] = gray & 255; + } else if (mode->colortype == LCT_RGB) { + out[i * 6 + 0] = (r >> 8) & 255; + out[i * 6 + 1] = r & 255; + out[i * 6 + 2] = (g >> 8) & 255; + out[i * 6 + 3] = g & 255; + out[i * 6 + 4] = (b >> 8) & 255; + out[i * 6 + 5] = b & 255; + } else if (mode->colortype == LCT_GREY_ALPHA) { + unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ + out[i * 4 + 0] = (gray >> 8) & 255; + out[i * 4 + 1] = gray & 255; + out[i * 4 + 2] = (a >> 8) & 255; + out[i * 4 + 3] = a & 255; + } else if (mode->colortype == LCT_RGBA) { + out[i * 8 + 0] = (r >> 8) & 255; + out[i * 8 + 1] = r & 255; + out[i * 8 + 2] = (g >> 8) & 255; + out[i * 8 + 3] = g & 255; + out[i * 8 + 4] = (b >> 8) & 255; + out[i * 8 + 5] = b & 255; + out[i * 8 + 6] = (a >> 8) & 255; + out[i * 8 + 7] = a & 255; + } +} + + +/* Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type. */ +static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a, const unsigned char* in, size_t i, const LodePNGColorMode* mode) +{ + if (mode->colortype == LCT_GREY) { + if (mode->bitdepth == 8) { + *r = *g = *b = in[i]; + if (mode->key_defined && *r == mode->key_r) *a = 0; + else *a = 255; + } else if (mode->bitdepth == 16) { + *r = *g = *b = in[i * 2 + 0]; + if (mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; + else *a = 255; + } else { + unsigned highest = ((1U << mode->bitdepth) - 1U); /* highest possible value for this bit depth */ + size_t j = i * mode->bitdepth; + unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); + *r = *g = *b = (value * 255) / highest; + if (mode->key_defined && value == mode->key_r) *a = 0; + else *a = 255; + } + } else if (mode->colortype == LCT_RGB) { + if (mode->bitdepth == 8) { + *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2]; + if (mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0; + else *a = 255; + } else { + *r = in[i * 6 + 0]; + *g = in[i * 6 + 2]; + *b = in[i * 6 + 4]; + if (mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r + && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g + && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; + else *a = 255; + } + } else if (mode->colortype == LCT_PALETTE) { + unsigned index; + if (mode->bitdepth == 8) index = in[i]; + else { + size_t j = i * mode->bitdepth; + index = readBitsFromReversedStream(&j, in, mode->bitdepth); + } + /* out of bounds of palette not checked: see lodepng_color_mode_alloc_palette. */ + *r = mode->palette[index * 4 + 0]; + *g = mode->palette[index * 4 + 1]; + *b = mode->palette[index * 4 + 2]; + *a = mode->palette[index * 4 + 3]; + } else if (mode->colortype == LCT_GREY_ALPHA) { + if (mode->bitdepth == 8) { + *r = *g = *b = in[i * 2 + 0]; + *a = in[i * 2 + 1]; + } else { + *r = *g = *b = in[i * 4 + 0]; + *a = in[i * 4 + 2]; + } + } else if (mode->colortype == LCT_RGBA) { + if (mode->bitdepth == 8) { + *r = in[i * 4 + 0]; + *g = in[i * 4 + 1]; + *b = in[i * 4 + 2]; + *a = in[i * 4 + 3]; + } else { + *r = in[i * 8 + 0]; + *g = in[i * 8 + 2]; + *b = in[i * 8 + 4]; + *a = in[i * 8 + 6]; + } + } +} + + +/* Similar to getPixelColorRGBA8, but with all the for loops inside of the color + mode test cases, optimized to convert the colors much faster, when converting + to the common case of RGBA with 8 bit per channel. buffer must be RGBA with + enough memory.*/ +static void getPixelColorsRGBA8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, const unsigned char* LODEPNG_RESTRICT in, const LodePNGColorMode* mode) +{ + unsigned num_channels = 4; + size_t i; + if (mode->colortype == LCT_GREY) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i]; + buffer[3] = 255; + } + if (mode->key_defined) { + buffer -= numpixels * num_channels; + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + if(buffer[0] == mode->key_r) buffer[3] = 0; + } + } + } else if (mode->bitdepth == 16) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2]; + buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255; + } + } else { + unsigned highest = ((1U << mode->bitdepth) - 1U); /* highest possible value for this bit depth */ + size_t j = 0; + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); + buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; + buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255; + } + } + } else if (mode->colortype == LCT_RGB) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + lodepng_memcpy(buffer, &in[i * 3], 3); + buffer[3] = 255; + } + if (mode->key_defined) { + buffer -= numpixels * num_channels; + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + if (buffer[0] == mode->key_r && buffer[1]== mode->key_g && buffer[2] == mode->key_b) buffer[3] = 0; + } + } + } else { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 6 + 0]; + buffer[1] = in[i * 6 + 2]; + buffer[2] = in[i * 6 + 4]; + buffer[3] = mode->key_defined + && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r + && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g + && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b ? 0 : 255; + } + } + } else if (mode->colortype == LCT_PALETTE) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = in[i]; + /* out of bounds of palette not checked: see lodepng_color_mode_alloc_palette. */ + lodepng_memcpy(buffer, &mode->palette[index * 4], 4); + } + } else { + size_t j = 0; + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); + /* out of bounds of palette not checked: see lodepng_color_mode_alloc_palette. */ + lodepng_memcpy(buffer, &mode->palette[index * 4], 4); + } + } + } else if (mode->colortype == LCT_GREY_ALPHA) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; + buffer[3] = in[i * 2 + 1]; + } + } else { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; + buffer[3] = in[i * 4 + 2]; + } + } + } else if (mode->colortype == LCT_RGBA) { + if (mode->bitdepth == 8) { + lodepng_memcpy(buffer, in, numpixels * 4); + } else { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 8 + 0]; + buffer[1] = in[i * 8 + 2]; + buffer[2] = in[i * 8 + 4]; + buffer[3] = in[i * 8 + 6]; + } + } + } +} + + +/* Similar to getPixelColorsRGBA8, but with 3-channel RGB output. */ +static void getPixelColorsRGB8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, const unsigned char* LODEPNG_RESTRICT in, const LodePNGColorMode* mode) +{ + const unsigned num_channels = 3; + size_t i; + if (mode->colortype == LCT_GREY) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i]; + } + } else if (mode->bitdepth == 16) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2]; + } + } else { + unsigned highest = ((1U << mode->bitdepth) - 1U); /* highest possible value for this bit depth */ + size_t j = 0; + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); + buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; + } + } + } else if (mode->colortype == LCT_RGB) { + if (mode->bitdepth == 8) { + lodepng_memcpy(buffer, in, numpixels * 3); + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 6 + 0]; + buffer[1] = in[i * 6 + 2]; + buffer[2] = in[i * 6 + 4]; + } + } + } else if (mode->colortype == LCT_PALETTE) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = in[i]; + /* out of bounds of palette not checked: see lodepng_color_mode_alloc_palette. */ + lodepng_memcpy(buffer, &mode->palette[index * 4], 3); + } + } else { + size_t j = 0; + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); + /* out of bounds of palette not checked: see lodepng_color_mode_alloc_palette. */ + lodepng_memcpy(buffer, &mode->palette[index * 4], 3); + } + } + } else if (mode->colortype == LCT_GREY_ALPHA) { + if (mode->bitdepth == 8) { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; + } + } else { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; + } + } + } else if (mode->colortype == LCT_RGBA) { + if (mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + lodepng_memcpy(buffer, &in[i * 4], 3); + } + } else { + for (i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 8 + 0]; + buffer[1] = in[i * 8 + 2]; + buffer[2] = in[i * 8 + 4]; + } + } + } +} + + +/* Get RGBA16 color of pixel with index i (y * width + x) from the raw image with + given color type, but the given color type must be 16-bit itself. */ +static void getPixelColorRGBA16(unsigned short* r, unsigned short* g, unsigned short* b, unsigned short* a, const unsigned char* in, size_t i, const LodePNGColorMode* mode) +{ + if (mode->colortype == LCT_GREY) { + *r = *g = *b = 256 * in[i * 2 + 0] + in[i * 2 + 1]; + if (mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; + else *a = 65535; + } else if (mode->colortype == LCT_RGB) { + *r = 256u * in[i * 6 + 0] + in[i * 6 + 1]; + *g = 256u * in[i * 6 + 2] + in[i * 6 + 3]; + *b = 256u * in[i * 6 + 4] + in[i * 6 + 5]; + if (mode->key_defined + && 256u * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r + && 256u * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g + && 256u * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; + else *a = 65535; + } else if (mode->colortype == LCT_GREY_ALPHA) { + *r = *g = *b = 256u * in[i * 4 + 0] + in[i * 4 + 1]; + *a = 256u * in[i * 4 + 2] + in[i * 4 + 3]; + } else if (mode->colortype == LCT_RGBA) { + *r = 256u * in[i * 8 + 0] + in[i * 8 + 1]; + *g = 256u * in[i * 8 + 2] + in[i * 8 + 3]; + *b = 256u * in[i * 8 + 4] + in[i * 8 + 5]; + *a = 256u * in[i * 8 + 6] + in[i * 8 + 7]; + } +} + +/* + Converts raw buffer from one color type to another color type, based on + LodePNGColorMode structs to describe the input and output color type. + See the reference manual at the end of this header file to see which color conversions are supported. + return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported) + The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel + of the output color type (lodepng_get_bpp). + For < 8 bpp images, there should not be padding bits at the end of scanlines. + For 16-bit per channel colors, uses big endian format like PNG does. + Return value is LodePNG error code +*/ +static unsigned lodepng_convert(unsigned char* out, const unsigned char* in, const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, unsigned w, unsigned h) +{ + size_t i; + ColorTree tree; + size_t numpixels = (size_t)w * (size_t)h; + unsigned error = 0; + + if (mode_in->colortype == LCT_PALETTE && !mode_in->palette) { + return 107; /* error: must provide palette if input mode is palette */ + } + + if (lodepng_color_mode_equal(mode_out, mode_in)) { + size_t numbytes = lodepng_get_raw_size(w, h, mode_in); + lodepng_memcpy(out, in, numbytes); + return 0; + } + + if (mode_out->colortype == LCT_PALETTE) { + size_t palettesize = mode_out->palettesize; + const unsigned char* palette = mode_out->palette; + size_t palsize = (size_t)1u << mode_out->bitdepth; + /* if the user specified output palette but did not give the values, assume + they want the values of the input color type (assuming that one is palette). + Note that we never create a new palette ourselves.*/ + if (palettesize == 0) { + palettesize = mode_in->palettesize; + palette = mode_in->palette; + /* if the input was also palette with same bitdepth, then the color types are also + equal, so copy literally. This to preserve the exact indices that were in the PNG + even in case there are duplicate colors in the palette.*/ + if (mode_in->colortype == LCT_PALETTE && mode_in->bitdepth == mode_out->bitdepth) { + size_t numbytes = lodepng_get_raw_size(w, h, mode_in); + lodepng_memcpy(out, in, numbytes); + return 0; + } + } + if (palettesize < palsize) palsize = palettesize; + color_tree_init(&tree); + for (i = 0; i != palsize; ++i) { + const unsigned char* p = &palette[i * 4]; + error = color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned)i); + if (error) break; + } + } + + if (!error) { + if (mode_in->bitdepth == 16 && mode_out->bitdepth == 16) { + for (i = 0; i != numpixels; ++i) { + unsigned short r = 0, g = 0, b = 0, a = 0; + getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); + rgba16ToPixel(out, i, mode_out, r, g, b, a); + } + } else if (mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGBA) { + getPixelColorsRGBA8(out, numpixels, in, mode_in); + } else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB) { + getPixelColorsRGB8(out, numpixels, in, mode_in); + } else { + unsigned char r = 0, g = 0, b = 0, a = 0; + for (i = 0; i != numpixels; ++i) { + getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); + error = rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a); + if (error) break; + } + } + } + + if (mode_out->colortype == LCT_PALETTE) { + color_tree_cleanup(&tree); + } + + return error; +} + + +/* Paeth predictor, used by PNG filter type 4 + The parameters are of type short, but should come from unsigned chars, the shorts + are only needed to make the paeth calculation correct. +*/ +static unsigned char paethPredictor(short a, short b, short c) +{ + short pa = LODEPNG_ABS(b - c); + short pb = LODEPNG_ABS(a - c); + short pc = LODEPNG_ABS(a + b - c - c); + /* return input value associated with smallest of pa, pb, pc (with certain priority if equal) */ + if (pb < pa) { a = b; pa = pb; } + return (pc < pa) ? c : a; +} + + +/*shared values used by multiple Adam7 related functions*/ +static const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }; /*x start values*/ +static const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }; /*y start values*/ +static const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }; /*x delta values*/ +static const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }; /*y delta values*/ + +/* Outputs various dimensions and positions in the image related to the Adam7 reduced images. + passw: output containing the width of the 7 passes + passh: output containing the height of the 7 passes + filter_passstart: output containing the index of the start and end of each + reduced image with filter bytes + padded_passstart output containing the index of the start and end of each + reduced image when without filter bytes but with padded scanlines + passstart: output containing the index of the start and end of each reduced + image without padding between scanlines, but still padding between the images + w, h: width and height of non-interlaced image + bpp: bits per pixel + "padded" is only relevant if bpp is less than 8 and a scanline or image does not + end at a full byte */ +static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp) +{ + /* the passstart values have 8 values: the 8th one indicates the byte after the end of the 7th (= last) pass */ + unsigned i; + + /* calculate width and height in pixels of each pass */ + for (i = 0; i != 7; ++i) { + passw[i] = (w + ADAM7_DX[i] - ADAM7_IX[i] - 1) / ADAM7_DX[i]; + passh[i] = (h + ADAM7_DY[i] - ADAM7_IY[i] - 1) / ADAM7_DY[i]; + if(passw[i] == 0) passh[i] = 0; + if(passh[i] == 0) passw[i] = 0; + } + + filter_passstart[0] = padded_passstart[0] = passstart[0] = 0; + for (i = 0; i != 7; ++i) { + /* if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte) */ + filter_passstart[i + 1] = filter_passstart[i] + + ((passw[i] && passh[i]) ? passh[i] * (1u + (passw[i] * bpp + 7u) / 8u) : 0); + /* bits padded if needed to fill full byte at end of each scanline */ + padded_passstart[i + 1] = padded_passstart[i] + passh[i] * ((passw[i] * bpp + 7u) / 8u); + /* only padded at end of reduced image */ + passstart[i + 1] = passstart[i] + (passh[i] * passw[i] * bpp + 7u) / 8u; + } +} + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / PNG Decoder / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, size_t bytewidth, unsigned char filterType, size_t length) +{ + /* For PNG filter method 0 + unfilter a PNG image scanline by scanline. when the pixels are smaller than 1 byte, + the filter works byte per byte (bytewidth = 1) + precon is the previous unfiltered scanline, recon the result, scanline the current one + the incoming scanlines do NOT include the filtertype byte, that one is given in the parameter filterType instead + recon and scanline MAY be the same memory address! precon must be disjoint. */ + + size_t i; + switch (filterType) { + case 0: + for (i = 0; i != length; ++i) recon[i] = scanline[i]; + break; + case 1: + for (i = 0; i != bytewidth; ++i) recon[i] = scanline[i]; + for (i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth]; + break; + case 2: + if (precon) { + for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i]; + } else { + for(i = 0; i != length; ++i) recon[i] = scanline[i]; + } + break; + case 3: + if (precon) { + for (i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u); + for (i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1u); + } else { + for (i = 0; i != bytewidth; ++i) recon[i] = scanline[i]; + for (i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1u); + } + break; + case 4: + if (precon) { + for (i = 0; i != bytewidth; ++i) { + recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/ + } + + /* Unroll independent paths of the paeth predictor. A 6x and 8x version would also be possible but that + adds too much code. Whether this actually speeds anything up at all depends on compiler and settings. */ + if (bytewidth >= 4) { + for (; i + 3 < length; i += 4) { + size_t j = i - bytewidth; + unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3]; + unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3]; + unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3]; + unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2], q3 = precon[j + 3]; + recon[i + 0] = s0 + paethPredictor(r0, p0, q0); + recon[i + 1] = s1 + paethPredictor(r1, p1, q1); + recon[i + 2] = s2 + paethPredictor(r2, p2, q2); + recon[i + 3] = s3 + paethPredictor(r3, p3, q3); + } + } else if (bytewidth >= 3) { + for (; i + 2 < length; i += 3) { + size_t j = i - bytewidth; + unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2]; + unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2]; + unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2]; + unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2]; + recon[i + 0] = s0 + paethPredictor(r0, p0, q0); + recon[i + 1] = s1 + paethPredictor(r1, p1, q1); + recon[i + 2] = s2 + paethPredictor(r2, p2, q2); + } + } else if (bytewidth >= 2) { + for (; i + 1 < length; i += 2) { + size_t j = i - bytewidth; + unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1]; + unsigned char r0 = recon[j + 0], r1 = recon[j + 1]; + unsigned char p0 = precon[i + 0], p1 = precon[i + 1]; + unsigned char q0 = precon[j + 0], q1 = precon[j + 1]; + recon[i + 0] = s0 + paethPredictor(r0, p0, q0); + recon[i + 1] = s1 + paethPredictor(r1, p1, q1); + } + } + + for (; i != length; ++i) { + recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth])); + } + } else { + for (i = 0; i != bytewidth; ++i) { + recon[i] = scanline[i]; + } + for (i = bytewidth; i < length; ++i) { + /* paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth] */ + recon[i] = (scanline[i] + recon[i - bytewidth]); + } + } + break; + default: return 36; /* error: invalid filter type given */ + } + return 0; +} + + +static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) +{ + /* For PNG filter method 0 + this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 seven times) + out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline + w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel + in and out are allowed to be the same memory address (but aren't the same size since in has the extra filter bytes) */ + + unsigned y; + unsigned char* prevline = 0; + + /* bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise */ + size_t bytewidth = (bpp + 7u) / 8u; + /* the width of a scanline in bytes, not including the filter type */ + size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u; + + for (y = 0; y < h; ++y) { + size_t outindex = linebytes * y; + size_t inindex = (1 + linebytes) * y; /* the extra filterbyte added to each row */ + unsigned char filterType = in[inindex]; + CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes)); + prevline = &out[outindex]; + } + + return 0; +} + +/* in: Adam7 interlaced image, with no padding bits between scanlines, but between + reduced images so that each reduced image starts at a byte. + out: the same pixels, but re-ordered so that they're now a non-interlaced image with size w*h + bpp: bits per pixel + out has the following size in bits: w * h * bpp. + in is possibly bigger due to padding bits between reduced images. + out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation + (because that's likely a little bit faster) + NOTE: comments about padding bits are only relevant if bpp < 8 */ +static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) +{ + unsigned passw[7], passh[7]; + size_t filter_passstart[8], padded_passstart[8], passstart[8]; + unsigned i; + + Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); + + if (bpp >= 8) { + for(i = 0; i != 7; ++i) { + unsigned x, y, b; + size_t bytewidth = bpp / 8u; + for (y = 0; y < passh[i]; ++y) + for (x = 0; x < passw[i]; ++x) { + size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth; + size_t pixeloutstart = ((ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * (size_t)w + ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bytewidth; + for (b = 0; b < bytewidth; ++b) { + out[pixeloutstart + b] = in[pixelinstart + b]; + } + } + } + } else /* bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers */ { + for (i = 0; i != 7; ++i) { + unsigned x, y, b; + unsigned ilinebits = bpp * passw[i]; + unsigned olinebits = bpp * w; + size_t obp, ibp; /* bit pointers (for out and in buffer) */ + for (y = 0; y < passh[i]; ++y) + for (x = 0; x < passw[i]; ++x) { + ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp); + obp = (ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bpp; + for (b = 0; b < bpp; ++b) { + unsigned char bit = readBitFromReversedStream(&ibp, in); + setBitOfReversedStream(&obp, out, bit); + } + } + } + } +} + + +static void removePaddingBits(unsigned char* out, const unsigned char* in, size_t olinebits, size_t ilinebits, unsigned h) +{ + /* After filtering there are still padding bits if scanlines have non multiple of 8 bit amounts. They need + to be removed (except at last scanline of (Adam7-reduced) image) before working with pure image buffers + for the Adam7 code, the color convert code and the output to the user. + in and out are allowed to be the same buffer, in may also be higher but still overlapping; in must + have >= ilinebits*h bits, out must have >= olinebits*h bits, olinebits must be <= ilinebits + also used to move bits after earlier such operations happened, e.g. in a sequence of reduced images from Adam7 + only useful if (ilinebits - olinebits) is a value in the range 1..7 */ + unsigned y; + size_t diff = ilinebits - olinebits; + size_t ibp = 0, obp = 0; /*input and output bit pointers*/ + for (y = 0; y < h; ++y) { + size_t x; + for (x = 0; x < olinebits; ++x) { + unsigned char bit = readBitFromReversedStream(&ibp, in); + setBitOfReversedStream(&obp, out, bit); + } + ibp += diff; + } +} + + +/* out must be buffer big enough to contain full image, and in must contain the full decompressed data from + the IDAT chunks (with filter index bytes and possible padding bits) + return value is error */ +static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, unsigned w, unsigned h, const LodePNGInfo* info_png) +{ + /* This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype. + Steps: + *) if no Adam7: 1) unfilter 2) remove padding bits (= possible extra bits per scanline if bpp < 8) + *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace + NOTE: the in buffer will be overwritten with intermediate data! */ + unsigned bpp = lodepng_get_bpp_lct(info_png->color.colortype, info_png->color.bitdepth); + if (bpp == 0) return 31; /* error: invalid colortype */ + + if (info_png->interlace_method == 0) { + if (bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { + CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp)); + removePaddingBits(out, in, w * bpp, ((w * bpp + 7u) / 8u) * 8u, h); + } + /* we can immediately filter into the out buffer, no other steps needed */ + else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp)); + } else /* interlace_method is 1 (Adam7) */ { + unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; + unsigned i; + + Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); + + for (i = 0; i != 7; ++i) { + CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp)); + /* TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline, + move bytes instead of bits or move not at all */ + if (bpp < 8) { + /* remove padding bits in scanlines; after this there still may be padding + bits between the different reduced images: each reduced image still starts nicely at a byte */ + removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp, ((passw[i] * bpp + 7u) / 8u) * 8u, passh[i]); + } + } + Adam7_deinterlace(out, in, w, h, bpp); + } + return 0; +} + + +static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) +{ + unsigned pos = 0, i; + color->palettesize = chunkLength / 3u; + if (color->palettesize == 0 || color->palettesize > 256) return 38; /* error: palette too small or big */ + lodepng_color_mode_alloc_palette(color); + if (!color->palette && color->palettesize) { + color->palettesize = 0; + return 83; /* alloc fail */ + } + + for (i = 0; i != color->palettesize; ++i) { + color->palette[4 * i + 0] = data[pos++]; /*R*/ + color->palette[4 * i + 1] = data[pos++]; /*G*/ + color->palette[4 * i + 2] = data[pos++]; /*B*/ + color->palette[4 * i + 3] = 255; /*alpha*/ + } + + return 0; /* OK */ +} + + +static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) +{ + unsigned i; + if (color->colortype == LCT_PALETTE) { + /* error: more alpha values given than there are palette entries */ + if (chunkLength > color->palettesize) return 39; + + for (i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i]; + } else if (color->colortype == LCT_GREY) { + /* error: this chunk must be 2 bytes for grayscale image */ + if (chunkLength != 2) return 30; + + color->key_defined = 1; + color->key_r = color->key_g = color->key_b = 256u * data[0] + data[1]; + } else if (color->colortype == LCT_RGB) { + /* error: this chunk must be 6 bytes for RGB image */ + if (chunkLength != 6) return 41; + + color->key_defined = 1; + color->key_r = 256u * data[0] + data[1]; + color->key_g = 256u * data[2] + data[3]; + color->key_b = 256u * data[4] + data[5]; + } + else return 42; /* error: tRNS chunk not allowed for other color models */ + + return 0; /* OK */ +} + + +/* read a PNG, the result will be in the same color type as the PNG (hence "generic") */ +static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize) +{ + unsigned char IEND = 0; + const unsigned char* chunk; + unsigned char* idat; /*the data from idat chunks, zlib compressed*/ + size_t idatsize = 0; + unsigned char* scanlines = 0; + size_t scanlines_size = 0, expected_size = 0; + size_t outsize = 0; + + /* safe output values in case error happens */ + *out = 0; + *w = *h = 0; + + state->error = lodepng_inspect(w, h, state, in, insize); /*reads header and resets other parameters in state->info_png*/ + if (state->error) return; + + if (lodepng_pixel_overflow(*w, *h, &state->info_png.color, &state->info_raw)) { + CERROR_RETURN(state->error, 92); /*overflow possible due to amount of pixels*/ + } + + /*the input filesize is a safe upper bound for the sum of idat chunks size*/ + idat = tvg::malloc(insize); + if (!idat) CERROR_RETURN(state->error, 83); /*alloc fail*/ + + chunk = &in[33]; /*first byte of the first chunk after the header*/ + + /*loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. + IDAT data is put at the start of the in buffer*/ + while (!IEND && !state->error) { + unsigned chunkLength; + const unsigned char* data; /*the data in the chunk*/ + + /*error: size of the in buffer too small to contain next chunk*/ + if ((size_t)((chunk - in) + 12) > insize || chunk < in) { + if (state->decoder.ignore_end) break; /*other errors may still happen though*/ + CERROR_BREAK(state->error, 30); + } + + /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/ + chunkLength = lodepng_chunk_length(chunk); + /*error: chunk length larger than the max PNG chunk size*/ + if (chunkLength > 2147483647) { + if (state->decoder.ignore_end) break; /*other errors may still happen though*/ + CERROR_BREAK(state->error, 63); + } + + if ((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) { + CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/ + } + + data = lodepng_chunk_data_const(chunk); + + /*for unknown chunk order*/ + //unsigned unknown = 0; + + /*IDAT chunk, containing compressed image data*/ + if (lodepng_chunk_type_equals(chunk, "IDAT")) { + size_t newsize; + if (lodepng_addofl(idatsize, chunkLength, &newsize)) CERROR_BREAK(state->error, 95); + if (newsize > insize) CERROR_BREAK(state->error, 95); + lodepng_memcpy(idat + idatsize, data, chunkLength); + idatsize += chunkLength; + } else if (lodepng_chunk_type_equals(chunk, "IEND")) { + /*IEND chunk*/ + IEND = 1; + } else if (lodepng_chunk_type_equals(chunk, "PLTE")) { + /*palette chunk (PLTE)*/ + state->error = readChunk_PLTE(&state->info_png.color, data, chunkLength); + if (state->error) break; + } else if (lodepng_chunk_type_equals(chunk, "tRNS")) { + /*palette transparency chunk (tRNS). Even though this one is an ancillary chunk , it is still compiled + in without 'LODEPNG_COMPILE_ANCILLARY_CHUNKS' because it contains essential color information that + affects the alpha channel of pixels. */ + state->error = readChunk_tRNS(&state->info_png.color, data, chunkLength); + if (state->error) break; + } else /*it's not an implemented chunk type, so ignore it: skip over the data*/ { + /*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/ + if (!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk)) { + CERROR_BREAK(state->error, 69); + } + //unknown = 1; + } + +#if 0 //We don't use CRC + if (!state->decoder.ignore_crc && !unknown) /*check CRC if wanted, only on known chunk types*/ { + if (lodepng_chunk_check_crc(chunk)) CERROR_BREAK(state->error, 57); /*invalid CRC*/ + } +#endif + if (!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize); + } + + if (state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) { + state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */ + } + + if (!state->error) { + /*predict output size, to allocate exact size for output buffer to avoid more dynamic allocation. + If the decompressed size does not match the prediction, the image must be corrupt.*/ + if (state->info_png.interlace_method == 0) { + size_t bpp = lodepng_get_bpp_lct(state->info_png.color.colortype, state->info_png.color.bitdepth); + expected_size = lodepng_get_raw_size_idat(*w, *h, bpp); + } else { + size_t bpp = lodepng_get_bpp_lct(state->info_png.color.colortype, state->info_png.color.bitdepth); + /*Adam-7 interlaced: expected size is the sum of the 7 sub-images sizes*/ + expected_size = 0; + expected_size += lodepng_get_raw_size_idat((*w + 7) >> 3, (*h + 7) >> 3, bpp); + if (*w > 4) expected_size += lodepng_get_raw_size_idat((*w + 3) >> 3, (*h + 7) >> 3, bpp); + expected_size += lodepng_get_raw_size_idat((*w + 3) >> 2, (*h + 3) >> 3, bpp); + if (*w > 2) expected_size += lodepng_get_raw_size_idat((*w + 1) >> 2, (*h + 3) >> 2, bpp); + expected_size += lodepng_get_raw_size_idat((*w + 1) >> 1, (*h + 1) >> 2, bpp); + if (*w > 1) expected_size += lodepng_get_raw_size_idat((*w + 0) >> 1, (*h + 1) >> 1, bpp); + expected_size += lodepng_get_raw_size_idat((*w + 0), (*h + 0) >> 1, bpp); + } + state->error = zlib_decompress(&scanlines, &scanlines_size, expected_size, idat, idatsize, &state->decoder.zlibsettings); + } + + if (!state->error && scanlines_size != expected_size) state->error = 91; /*decompressed size doesn't match prediction*/ + tvg::free(idat); + + if (!state->error) { + outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color); + *out = tvg::malloc(outsize); + if (!*out) state->error = 83; /*alloc fail*/ + } + if (!state->error) { + lodepng_memset(*out, 0, outsize); + state->error = postProcessScanlines(*out, scanlines, *w, *h, &state->info_png); + } + tvg::free(scanlines); +} + + +static void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) +{ + settings->color_convert = 1; + settings->ignore_crc = 0; + settings->ignore_critical = 0; + settings->ignore_end = 0; + lodepng_decompress_settings_init(&settings->zlibsettings); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +/*read the information from the header and store it in the LodePNGInfo. return value is error*/ +unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize) +{ + unsigned width, height; + LodePNGInfo* info = &state->info_png; + if (insize == 0 || in == 0) { + CERROR_RETURN_ERROR(state->error, 48); /*error: the given data is empty*/ + } + if (insize < 33) { + CERROR_RETURN_ERROR(state->error, 27); /*error: the data length is smaller than the length of a PNG header*/ + } + + /* when decoding a new PNG image, make sure all parameters created after previous decoding are reset */ + /* TODO: remove this. One should use a new LodePNGState for new sessions */ + lodepng_info_cleanup(info); + lodepng_info_init(info); + + if (in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) { + CERROR_RETURN_ERROR(state->error, 28); /*error: the first 8 bytes are not the correct PNG signature*/ + } + if (lodepng_chunk_length(in + 8) != 13) { + CERROR_RETURN_ERROR(state->error, 94); /*error: header size must be 13 bytes*/ + } + if (!lodepng_chunk_type_equals(in + 8, "IHDR")) { + CERROR_RETURN_ERROR(state->error, 29); /*error: it doesn't start with a IHDR chunk!*/ + } + + /*read the values given in the header*/ + width = lodepng_read32bitInt(&in[16]); + height = lodepng_read32bitInt(&in[20]); + /*TODO: remove the undocumented feature that allows to give null pointers to width or height*/ + if (w) *w = width; + if (h) *h = height; + info->color.bitdepth = in[24]; + info->color.colortype = (LodePNGColorType)in[25]; + info->compression_method = in[26]; + info->filter_method = in[27]; + info->interlace_method = in[28]; + + /*errors returned only after the parsing so other values are still output*/ + + /*error: invalid image size*/ + if (width == 0 || height == 0) CERROR_RETURN_ERROR(state->error, 93); + /*error: invalid colortype or bitdepth combination*/ + state->error = checkColorValidity(info->color.colortype, info->color.bitdepth); + if (state->error) return state->error; + /*error: only compression method 0 is allowed in the specification*/ + if (info->compression_method != 0) CERROR_RETURN_ERROR(state->error, 32); + /*error: only filter method 0 is allowed in the specification*/ + if (info->filter_method != 0) CERROR_RETURN_ERROR(state->error, 33); + /*error: only interlace methods 0 and 1 exist in the specification*/ + if (info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34); + +#if 0 //thorvg don't use crc + if (!state->decoder.ignore_crc) { + unsigned CRC = lodepng_read32bitInt(&in[29]); + unsigned checksum = lodepng_crc32(&in[12], 17); + if (CRC != checksum) { + CERROR_RETURN_ERROR(state->error, 57); /*invalid CRC*/ + } + } +#endif + return state->error; +} + + +unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize) +{ + *out = 0; + decodeGeneric(out, w, h, state, in, insize); + if (state->error) return state->error; + if (!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color)) { + /*same color type, no copying or converting of data needed*/ + /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype + the raw image has to the end user*/ + if (!state->decoder.color_convert) { + state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color); + if (state->error) return state->error; + } + } else { /*color conversion needed*/ + unsigned char* data = *out; + size_t outsize; + + /*TODO: check if this works according to the statement in the documentation: "The converter can convert + from grayscale input color type, to 8-bit grayscale or grayscale with alpha"*/ + if (!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA) && !(state->info_raw.bitdepth == 8)) { + return 56; /*unsupported color mode conversion*/ + } + + outsize = lodepng_get_raw_size(*w, *h, &state->info_raw); + *out = tvg::malloc(outsize); + if (!(*out)) { + state->error = 83; /*alloc fail*/ + } + else state->error = lodepng_convert(*out, data, &state->info_raw, &state->info_png.color, *w, *h); + tvg::free(data); + } + return state->error; +} + + +void lodepng_state_init(LodePNGState* state) +{ + lodepng_decoder_settings_init(&state->decoder); + lodepng_color_mode_init(&state->info_raw); + lodepng_info_init(&state->info_png); + state->error = 1; +} + + +void lodepng_state_cleanup(LodePNGState* state) +{ + lodepng_color_mode_cleanup(&state->info_raw); + lodepng_info_cleanup(&state->info_png); +} diff --git a/components/thorvg-main/src/loaders/png/tvgLodePng.h b/components/thorvg-main/src/loaders/png/tvgLodePng.h new file mode 100644 index 0000000..b35bad6 --- /dev/null +++ b/components/thorvg-main/src/loaders/png/tvgLodePng.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + LodePNG version 20200306 + + Copyright (c) 2005-2020 Lode Vandevenne + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + +#ifndef _TVG_LODEPNG_H_ +#define _TVG_LODEPNG_H_ + +#include + +/*The PNG color types (also used for raw image).*/ +enum LodePNGColorType +{ + LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/ + LCT_RGB = 2, /*RGB: 8,16 bit*/ + LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/ + LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/ + LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/ + /*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid + byte value from 0 to 255 that could be present in an invalid PNG file header. Do + not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use + the valid color type names above, or numeric values like 1 or 7 when checking for + particular disallowed color type byte values, or cast to integer to print it.*/ + LCT_MAX_OCTET_VALUE = 255 +}; + +/*Settings for zlib decompression*/ +struct LodePNGDecompressSettings +{ + /* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */ + unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ + unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/ + + /*use custom zlib decoder instead of built in one (default: null)*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings*); + /*use custom deflate decoder instead of built in one (default: null) if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/ + unsigned (*custom_inflate)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +/* + Color mode of an image. Contains all information required to decode the pixel + bits to RGBA colors. This information is the same as used in the PNG file + format, and is used both for PNG and raw image data in LodePNG. +*/ +struct LodePNGColorMode +{ + /*header (IHDR)*/ + LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/ + unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/ + + /* + palette (PLTE and tRNS) + + Dynamically allocated with the colors of the palette, including alpha. + This field may not be allocated directly, use lodepng_color_mode_init first, + then lodepng_palette_add per color to correctly initialize it (to ensure size + of exactly 1024 bytes). + + The alpha channels must be set as well, set them to 255 for opaque images. + + When decoding, by default you can ignore this palette, since LodePNG already + fills the palette colors in the pixels of the raw RGBA output. + + The palette is only supported for color type 3. + */ + unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/ + size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/ + + /* + transparent color key (tRNS) + + This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit. + For grayscale PNGs, r, g and b will all 3 be set to the same. + + When decoding, by default you can ignore this information, since LodePNG sets + pixels with this key to transparent already in the raw RGBA output. + + The color key is only supported for color types 0 and 2. + */ + unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/ + unsigned key_r; /*red/grayscale component of color key*/ + unsigned key_g; /*green component of color key*/ + unsigned key_b; /*blue component of color key*/ +}; + +/*Information about the PNG image, except pixels, width and height.*/ +struct LodePNGInfo +{ + /*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/ + unsigned compression_method;/*compression method of the original file. Always 0.*/ + unsigned filter_method; /*filter method of the original file*/ + unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/ + LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/ +}; + +/* + Settings for the decoder. This contains settings for the PNG and the Zlib + decoder, but not the Info settings from the Info structs. +*/ +struct LodePNGDecoderSettings +{ + LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/ + + /* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */ + unsigned ignore_crc; /*ignore CRC checksums*/ + unsigned ignore_critical; /*ignore unknown critical chunks*/ + unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/ + /* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable + errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some + strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters + in string keys, etc... */ + + unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/ +}; + +/*The settings, state and information for extended encoding and decoding.*/ +struct LodePNGState +{ + LodePNGDecoderSettings decoder; /*the decoding settings*/ + LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/ + LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ + unsigned error; +}; + +void lodepng_state_init(LodePNGState* state); +void lodepng_state_cleanup(LodePNGState* state); +unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize); +unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize); + +#endif //_TVG_LODEPNG_H_ diff --git a/components/thorvg-main/src/loaders/png/tvgPngLoader.cpp b/components/thorvg-main/src/loaders/png/tvgPngLoader.cpp new file mode 100644 index 0000000..63aa7cd --- /dev/null +++ b/components/thorvg-main/src/loaders/png/tvgPngLoader.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgLoader.h" +#include "tvgPngLoader.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void PngLoader::run(unsigned tid) +{ + auto width = static_cast(w); + auto height = static_cast(h); + + state.info_raw.colortype = LCT_RGBA; //request this image format + + if (lodepng_decode(&surface.buf8, &width, &height, &state, data, size)) { + TVGERR("PNG", "Failed to decode image"); + } + + //setup the surface + surface.stride = width; + surface.w = width; + surface.h = height; + surface.cs = ColorSpace::ABGR8888S; + surface.channelSize = sizeof(uint32_t); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +PngLoader::PngLoader() : ImageLoader(FileType::Png) +{ + lodepng_state_init(&state); +} + + +PngLoader::~PngLoader() +{ + done(); + if (freeData) tvg::free(data); + tvg::free(surface.buf8); + lodepng_state_cleanup(&state); +} + + +bool PngLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + if (!(data = (unsigned char*)LoadModule::open(path, size))) return false; + + lodepng_state_init(&state); + + unsigned int width, height; + if (lodepng_inspect(&width, &height, &state, data, size) > 0) return false; + w = static_cast(width); + h = static_cast(height); + freeData = true; + return true; +#else + return false; +#endif +} + + +bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + unsigned int width, height; + if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false; + + if (copy) { + this->data = tvg::malloc(size); + if (!this->data) return false; + memcpy((unsigned char *)this->data, data, size); + freeData = true; + } else { + this->data = (unsigned char *) data; + freeData = false; + } + + w = static_cast(width); + h = static_cast(height); + this->size = size; + + return true; +} + + +bool PngLoader::read() +{ + if (!data || w == 0 || h == 0) return false; + + if (!LoadModule::read()) return true; + + TaskScheduler::request(this); + + return true; +} + + +RenderSurface* PngLoader::bitmap() +{ + this->done(); + return ImageLoader::bitmap(); +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/png/tvgPngLoader.h b/components/thorvg-main/src/loaders/png/tvgPngLoader.h new file mode 100644 index 0000000..c7c665c --- /dev/null +++ b/components/thorvg-main/src/loaders/png/tvgPngLoader.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_PNG_LOADER_H_ +#define _TVG_PNG_LOADER_H_ + +#include "tvgLodePng.h" +#include "tvgTaskScheduler.h" + + +class PngLoader : public ImageLoader, public Task +{ +private: + LodePNGState state; + unsigned char* data = nullptr; + uint32_t size = 0; + bool freeData = false; + + void run(unsigned tid) override; + +public: + PngLoader(); + ~PngLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool read() override; + + RenderSurface* bitmap() override; +}; + +#endif //_TVG_PNG_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/raw/meson.build b/components/thorvg-main/src/loaders/raw/meson.build new file mode 100644 index 0000000..389c0cb --- /dev/null +++ b/components/thorvg-main/src/loaders/raw/meson.build @@ -0,0 +1,9 @@ +source_file = [ + 'tvgRawLoader.h', + 'tvgRawLoader.cpp', +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/raw/tvgRawLoader.cpp b/components/thorvg-main/src/loaders/raw/tvgRawLoader.cpp new file mode 100644 index 0000000..968f864 --- /dev/null +++ b/components/thorvg-main/src/loaders/raw/tvgRawLoader.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgLoader.h" +#include "tvgRawLoader.h" + + +RawLoader::RawLoader() : ImageLoader(FileType::Raw) +{ +} + + +RawLoader::~RawLoader() +{ + if (copy) tvg::free(surface.buf32); +} + + +bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy) +{ + if (!LoadModule::read()) return true; + + if (!data || w == 0 || h == 0) return false; + + this->w = (float)w; + this->h = (float)h; + this->copy = copy; + + if (copy) { + surface.buf32 = tvg::malloc(sizeof(uint32_t) * w * h); + if (!surface.buf32) return false; + memcpy((void*)surface.buf32, data, sizeof(uint32_t) * w * h); + } + else surface.buf32 = const_cast(data); + + //setup the surface + surface.stride = w; + surface.w = w; + surface.h = h; + surface.cs = cs; + surface.channelSize = sizeof(uint32_t); + surface.premultiplied = (cs == ColorSpace::ABGR8888 || cs == ColorSpace::ARGB8888) ? true : false; + + return true; +} + + +bool RawLoader::read() +{ + LoadModule::read(); + + return true; +} diff --git a/components/thorvg-main/src/loaders/raw/tvgRawLoader.h b/components/thorvg-main/src/loaders/raw/tvgRawLoader.h new file mode 100644 index 0000000..87f08ad --- /dev/null +++ b/components/thorvg-main/src/loaders/raw/tvgRawLoader.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_RAW_LOADER_H_ +#define _TVG_RAW_LOADER_H_ + +class RawLoader : public ImageLoader +{ +public: + bool copy = false; + + RawLoader(); + ~RawLoader(); + + using LoadModule::open; + bool open(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy); + bool read() override; +}; + + +#endif //_TVG_RAW_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/svg/meson.build b/components/thorvg-main/src/loaders/svg/meson.build new file mode 100644 index 0000000..8048dd1 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/meson.build @@ -0,0 +1,20 @@ +source_file = [ + 'tvgSvgCssStyle.h', + 'tvgSvgLoader.h', + 'tvgSvgLoaderCommon.h', + 'tvgSvgPath.h', + 'tvgSvgSceneBuilder.h', + 'tvgSvgUtil.h', + 'tvgXmlParser.h', + 'tvgSvgCssStyle.cpp', + 'tvgSvgLoader.cpp', + 'tvgSvgPath.cpp', + 'tvgSvgSceneBuilder.cpp', + 'tvgSvgUtil.cpp', + 'tvgXmlParser.cpp' +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgCssStyle.cpp b/components/thorvg-main/src/loaders/svg/tvgSvgCssStyle.cpp new file mode 100644 index 0000000..62f6b25 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgCssStyle.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2022 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgStr.h" +#include "tvgSvgCssStyle.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static inline bool _isImportanceApplicable(const SvgStyleFlags& toFlagsImportance, SvgStyleFlags fromFlagsImportance, SvgStyleFlags flag) +{ + return !(toFlagsImportance & flag) && (fromFlagsImportance & flag); +} + + +static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from, bool overwrite) +{ + if (!from) return; + + //Copy the properties of 'from' only if they were explicitly set (not the default ones). + if ((from->curColorSet && (overwrite || !(to->flags & SvgStyleFlags::Color))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::Color)) { + to->color = from->color; + to->curColorSet = true; + to->flags |= SvgStyleFlags::Color; + if (from->flagsImportance & SvgStyleFlags::Color) to->flagsImportance |= SvgStyleFlags::Color; + } + if (((from->flags & SvgStyleFlags::PaintOrder) && (overwrite || !(to->flags & SvgStyleFlags::PaintOrder))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::PaintOrder)) { + to->paintOrder = from->paintOrder; + to->flags |= SvgStyleFlags::PaintOrder; + if (from->flagsImportance & SvgStyleFlags::PaintOrder) to->flagsImportance |= SvgStyleFlags::PaintOrder; + } + if (((from->flags & SvgStyleFlags::Display) && (overwrite || !(to->flags & SvgStyleFlags::Display))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::Display)) { + to->display = from->display; + to->flags |= SvgStyleFlags::Display; + if (from->flagsImportance & SvgStyleFlags::Display) to->flagsImportance |= SvgStyleFlags::Display; + } + //Fill + if (((from->fill.flags & SvgFillFlags::Paint) && (overwrite || !(to->flags & SvgStyleFlags::Fill))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::Fill)) { + to->fill.paint.color = from->fill.paint.color; + to->fill.paint.none = from->fill.paint.none; + to->fill.paint.curColor = from->fill.paint.curColor; + if (from->fill.paint.url) { + if (to->fill.paint.url) tvg::free(to->fill.paint.url); + to->fill.paint.url = duplicate(from->fill.paint.url); + } + to->fill.flags |= SvgFillFlags::Paint; + to->flags |= SvgStyleFlags::Fill; + if (from->flagsImportance & SvgStyleFlags::Fill) to->flagsImportance |= SvgStyleFlags::Fill; + } + if (((from->fill.flags & SvgFillFlags::Opacity) && (overwrite || !(to->flags & SvgStyleFlags::FillOpacity))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::FillOpacity)) { + to->fill.opacity = from->fill.opacity; + to->fill.flags |= SvgFillFlags::Opacity; + to->flags |= SvgStyleFlags::FillOpacity; + if (from->flagsImportance & SvgStyleFlags::FillOpacity) to->flagsImportance |= SvgStyleFlags::FillOpacity; + } + if (((from->fill.flags & SvgFillFlags::FillRule) && (overwrite || !(to->flags & SvgStyleFlags::FillRule))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::FillRule)) { + to->fill.fillRule = from->fill.fillRule; + to->fill.flags |= SvgFillFlags::FillRule; + to->flags |= SvgStyleFlags::FillRule; + if (from->flagsImportance & SvgStyleFlags::FillRule) to->flagsImportance |= SvgStyleFlags::FillRule; + } + //Stroke + if (((from->stroke.flags & SvgStrokeFlags::Paint) && (overwrite || !(to->flags & SvgStyleFlags::Stroke))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::Stroke)) { + to->stroke.paint.color = from->stroke.paint.color; + to->stroke.paint.none = from->stroke.paint.none; + to->stroke.paint.curColor = from->stroke.paint.curColor; + if (from->stroke.paint.url) { + if (to->stroke.paint.url) tvg::free(to->stroke.paint.url); + to->stroke.paint.url = duplicate(from->stroke.paint.url); + } + to->stroke.flags |= SvgStrokeFlags::Paint; + to->flags |= SvgStyleFlags::Stroke; + if (from->flagsImportance & SvgStyleFlags::Stroke) to->flagsImportance |= SvgStyleFlags::Stroke; + } + if (((from->stroke.flags & SvgStrokeFlags::Opacity) && (overwrite || !(to->flags & SvgStyleFlags::StrokeOpacity))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::StrokeOpacity)) { + to->stroke.opacity = from->stroke.opacity; + to->stroke.flags |= SvgStrokeFlags::Opacity; + to->flags |= SvgStyleFlags::StrokeOpacity; + if (from->flagsImportance & SvgStyleFlags::StrokeOpacity) to->flagsImportance |= SvgStyleFlags::StrokeOpacity; + } + if (((from->stroke.flags & SvgStrokeFlags::Width) && (overwrite || !(to->flags & SvgStyleFlags::StrokeWidth))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::StrokeWidth)) { + to->stroke.width = from->stroke.width; + to->stroke.flags |= SvgStrokeFlags::Width; + to->flags |= SvgStyleFlags::StrokeWidth; + if (from->flagsImportance & SvgStyleFlags::StrokeWidth) to->flagsImportance |= SvgStyleFlags::StrokeWidth; + } + if (((from->stroke.flags & SvgStrokeFlags::Dash) && (overwrite || !(to->flags & SvgStyleFlags::StrokeDashArray))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::StrokeDashArray)) { + if (!from->stroke.dash.array.empty()) { + to->stroke.dash.array.clear(); + to->stroke.dash.array.reserve(from->stroke.dash.array.count); + ARRAY_FOREACH(p, from->stroke.dash.array) to->stroke.dash.array.push(*p); + to->stroke.flags |= SvgStrokeFlags::Dash; + to->flags |= SvgStyleFlags::StrokeDashArray; + if (from->flagsImportance & SvgStyleFlags::StrokeDashArray) to->flagsImportance |= SvgStyleFlags::StrokeDashArray; + } + } + if (((from->stroke.flags & SvgStrokeFlags::Cap) && (overwrite || !(to->flags & SvgStyleFlags::StrokeLineCap))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::StrokeLineCap)) { + to->stroke.cap = from->stroke.cap; + to->stroke.flags |= SvgStrokeFlags::Cap; + to->flags |= SvgStyleFlags::StrokeLineCap; + if (from->flagsImportance & SvgStyleFlags::StrokeLineCap) to->flagsImportance |= SvgStyleFlags::StrokeLineCap; + } + if (((from->stroke.flags & SvgStrokeFlags::Join) && (overwrite || !(to->flags & SvgStyleFlags::StrokeLineJoin))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::StrokeLineJoin)) { + to->stroke.join = from->stroke.join; + to->stroke.flags |= SvgStrokeFlags::Join; + to->flags |= SvgStyleFlags::StrokeLineJoin; + if (from->flagsImportance & SvgStyleFlags::StrokeLineJoin) to->flagsImportance |= SvgStyleFlags::StrokeLineJoin; + } + //Opacity + if (((from->flags & SvgStyleFlags::Opacity) && (overwrite || !(to->flags & SvgStyleFlags::Opacity))) || + _isImportanceApplicable(to->flagsImportance, from->flagsImportance, SvgStyleFlags::Opacity)) { + to->opacity = from->opacity; + to->flags |= SvgStyleFlags::Opacity; + if (from->flagsImportance & SvgStyleFlags::Opacity) to->flagsImportance |= SvgStyleFlags::Opacity; + } +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +void cssCopyStyleAttr(SvgNode* to, const SvgNode* from, bool overwrite) +{ + //Copy matrix attribute + if (from->transform && (overwrite || !(to->style->flags & SvgStyleFlags::Transform))) { + if (!to->transform) to->transform = tvg::malloc(sizeof(Matrix)); + *to->transform = *from->transform; + to->style->flags |= SvgStyleFlags::Transform; + } + //Copy style attribute + _copyStyle(to->style, from->style, overwrite); + + if (from->style->clipPath.url) { + if (to->style->clipPath.url) tvg::free(to->style->clipPath.url); + to->style->clipPath.url = duplicate(from->style->clipPath.url); + } + if (from->style->mask.url) { + if (to->style->mask.url) tvg::free(to->style->mask.url); + to->style->mask.url = duplicate(from->style->mask.url); + } +} + + +SvgNode* cssFindStyleNode(const SvgNode* style, const char* title, SvgNodeType type) +{ + if (!style) return nullptr; + ARRAY_FOREACH(p, style->child) { + if ((*p)->type == type) { + if ((!title && !(*p)->id) || (title && (*p)->id && STR_AS((*p)->id, title))) return *p; + } + } + return nullptr; +} + + +SvgNode* cssFindStyleNode(const SvgNode* style, const char* title) +{ + if (!style || !title) return nullptr; + ARRAY_FOREACH(p, style->child) { + if ((*p)->type == SvgNodeType::CssStyle) { + if ((*p)->id && STR_AS((*p)->id, title)) return *p; + } + } + return nullptr; +} + + +void cssUpdateStyle(SvgNode* doc, SvgNode* style) +{ + ARRAY_FOREACH(p, doc->child) { + if (auto cssNode = cssFindStyleNode(style, nullptr, (*p)->type)) { + cssCopyStyleAttr(*p, cssNode); + } + cssUpdateStyle(*p, style); + } +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgCssStyle.h b/components/thorvg-main/src/loaders/svg/tvgSvgCssStyle.h new file mode 100644 index 0000000..e0cbf27 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgCssStyle.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SVG_CSS_STYLE_H_ +#define _TVG_SVG_CSS_STYLE_H_ + +#include "tvgSvgLoaderCommon.h" + +SvgNode* cssFindStyleNode(const SvgNode* style, const char* title, SvgNodeType type); +SvgNode* cssFindStyleNode(const SvgNode* style, const char* title); +void cssUpdateStyle(SvgNode* doc, SvgNode* style); +void cssCopyStyleAttr(SvgNode* to, const SvgNode* from, bool overwrite = false); + +#endif //_TVG_SVG_CSS_STYLE_H_ diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgLoader.cpp b/components/thorvg-main/src/loaders/svg/tvgSvgLoader.cpp new file mode 100644 index 0000000..476f17e --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgLoader.cpp @@ -0,0 +1,4136 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgStr.h" +#include "tvgMath.h" +#include "tvgColor.h" +#include "tvgLoader.h" +#include "tvgXmlParser.h" +#include "tvgSvgLoader.h" +#include "tvgSvgSceneBuilder.h" +#include "tvgSvgCssStyle.h" +#include "tvgSvgUtil.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +/* + * According to: https://www.w3.org/TR/SVG2/coords.html#Units + * and: https://www.w3.org/TR/css-values-4/#absolute-lengths + */ +#define PX_PER_IN 96 //1 in = 96 px +#define PX_PER_PC 16 //1 pc = 1/6 in -> PX_PER_IN/6 +#define PX_PER_PT 1.333333f //1 pt = 1/72 in -> PX_PER_IN/72 +#define PX_PER_MM 3.779528f //1 in = 25.4 mm -> PX_PER_IN/25.4 +#define PX_PER_CM 37.79528f //1 in = 2.54 cm -> PX_PER_IN/2.54 + +typedef bool (*parseAttributes)(const char* buf, unsigned bufLength, xmlAttributeCb func, const void* data); +typedef SvgNode* (*FactoryMethod)(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func); +typedef SvgStyleGradient* (*GradientFactoryMethod)(SvgLoaderData* loader, const char* buf, unsigned bufLength); +static bool _parseStyleAttr(void* data, const char* key, const char* value); +static bool _parseStyleAttr(void* data, const char* key, const char* value, bool style); + + +static char* _copyId(const char* str) +{ + if (!str) return nullptr; + if (strlen(str) == 0) return nullptr; + return duplicate(str); +} + + +static bool _parseNumber(const char** content, const char** end, float* number) +{ + auto _end = end ? *end : nullptr; + + *number = toFloat(*content, (char**)&_end); + //If the start of string is not number + if ((*content) == _end) { + if (end) *end = _end; + return false; + } + //Skip comma if any + *content = svgUtilSkipWhiteSpaceAndComma(_end); + if (end) *end = _end; + + return true; +} + + +static constexpr struct +{ + AspectRatioAlign align; + const char* tag; +} alignTags[] = { + { AspectRatioAlign::XMinYMin, "xMinYMin" }, + { AspectRatioAlign::XMidYMin, "xMidYMin" }, + { AspectRatioAlign::XMaxYMin, "xMaxYMin" }, + { AspectRatioAlign::XMinYMid, "xMinYMid" }, + { AspectRatioAlign::XMidYMid, "xMidYMid" }, + { AspectRatioAlign::XMaxYMid, "xMaxYMid" }, + { AspectRatioAlign::XMinYMax, "xMinYMax" }, + { AspectRatioAlign::XMidYMax, "xMidYMax" }, + { AspectRatioAlign::XMaxYMax, "xMaxYMax" }, +}; + + +static void _parseAspectRatio(const char** content, AspectRatioAlign* align, AspectRatioMeetOrSlice* meetOrSlice) +{ + if (STR_AS(*content, "none")) { + *align = AspectRatioAlign::None; + return; + } + + for (unsigned int i = 0; i < sizeof(alignTags) / sizeof(alignTags[0]); i++) { + if (!strncmp(*content, alignTags[i].tag, 8)) { + *align = alignTags[i].align; + *content += 8; + *content = svgUtilSkipWhiteSpace(*content, nullptr); + break; + } + } + + if (STR_AS(*content, "meet")) { + *meetOrSlice = AspectRatioMeetOrSlice::Meet; + } else if (STR_AS(*content, "slice")) { + *meetOrSlice = AspectRatioMeetOrSlice::Slice; + } +} + + +// According to https://www.w3.org/TR/SVG/coords.html#Units +static float _toFloat(const SvgParser* svgParse, const char* str, SvgParserLengthType type) +{ + float parsedValue = toFloat(str, nullptr); + + if (strstr(str, "cm")) parsedValue *= PX_PER_CM; + else if (strstr(str, "mm")) parsedValue *= PX_PER_MM; + else if (strstr(str, "pt")) parsedValue *= PX_PER_PT; + else if (strstr(str, "pc")) parsedValue *= PX_PER_PC; + else if (strstr(str, "in")) parsedValue *= PX_PER_IN; + else if (strstr(str, "%")) { + if (type == SvgParserLengthType::Vertical) parsedValue = (parsedValue / 100.0f) * svgParse->global.h; + else if (type == SvgParserLengthType::Horizontal) parsedValue = (parsedValue / 100.0f) * svgParse->global.w; + else if (type == SvgParserLengthType::Diagonal) parsedValue = (sqrtf(powf(svgParse->global.w, 2) + powf(svgParse->global.h, 2)) / sqrtf(2.0f)) * (parsedValue / 100.0f); + else //if other than it's radius + { + float max = svgParse->global.w; + if (max < svgParse->global.h) + max = svgParse->global.h; + parsedValue = (parsedValue / 100.0f) * max; + } + } + //TODO: Implement 'em', 'ex' attributes + + return parsedValue; +} + + +static float _gradientToFloat(const SvgParser* svgParse, const char* str, bool& isPercentage) +{ + char* end = nullptr; + + auto parsedValue = toFloat(str, &end); + isPercentage = false; + + if (strstr(str, "%")) { + parsedValue = parsedValue / 100.0f; + isPercentage = true; + } + else if (strstr(str, "cm")) parsedValue *= PX_PER_CM; + else if (strstr(str, "mm")) parsedValue *= PX_PER_MM; + else if (strstr(str, "pt")) parsedValue *= PX_PER_PT; + else if (strstr(str, "pc")) parsedValue *= PX_PER_PC; + else if (strstr(str, "in")) parsedValue *= PX_PER_IN; + //TODO: Implement 'em', 'ex' attributes + + return parsedValue; +} + + +static float _toOffset(const char* str) +{ + char* end = nullptr; + auto strEnd = str + strlen(str); + + auto parsedValue = toFloat(str, &end); + + end = (char*)svgUtilSkipWhiteSpace(end, nullptr); + auto ptr = strstr(str, "%"); + + if (ptr) { + parsedValue = parsedValue / 100.0f; + if (end != ptr || (end + 1) != strEnd) return 0; + } else if (end != strEnd) return 0; + + return parsedValue; +} + + +static int _toOpacity(const char* str) +{ + char* end = nullptr; + auto opacity = toFloat(str, &end); + + if (end) { + if (end[0] == '%' && end[1] == '\0') return lrint(opacity * 2.55f); + else if (*end == '\0') return lrint(opacity * 255); + } + return 255; +} + + +static SvgMaskType _toMaskType(const char* str) +{ + if (STR_AS(str, "Alpha")) return SvgMaskType::Alpha; + + return SvgMaskType::Luminance; +} + + +//The default rendering order: fill, stroke, markers +//If any is omitted, will be rendered in its default order after the specified ones. +static bool _toPaintOrder(const char* str) +{ + auto position = 1; + auto strokePosition = 0; + auto fillPosition = 0; + + while (*str != '\0') { + str = svgUtilSkipWhiteSpace(str, nullptr); + if (!strncmp(str, "fill", 4)) { + fillPosition = position++; + str += 4; + } else if (!strncmp(str, "stroke", 6)) { + strokePosition = position++; + str += 6; + } else if (!strncmp(str, "markers", 7)) { + str += 7; + } else { + return _toPaintOrder("fill stroke"); + } + } + + if (fillPosition == 0) fillPosition = position++; + if (strokePosition == 0) strokePosition = position++; + + return fillPosition < strokePosition; +} + + +#define _PARSE_TAG(Type, Name, Name1, Tags_Array, Default) \ + static Type _to##Name1(const char* str) \ + { \ + unsigned int i; \ + \ + for (i = 0; i < sizeof(Tags_Array) / sizeof(Tags_Array[0]); i++) { \ + if (STR_AS(str, Tags_Array[i].tag)) return Tags_Array[i].Name; \ + } \ + return Default; \ + } + + +/* parse the line cap used during stroking a path. + * Value: butt | round | square | inherit + * Initial: butt + * https://www.w3.org/TR/SVG/painting.html + */ +static constexpr struct +{ + StrokeCap lineCap; + const char* tag; +} lineCapTags[] = { + { StrokeCap::Butt, "butt" }, + { StrokeCap::Round, "round" }, + { StrokeCap::Square, "square" } +}; + + +_PARSE_TAG(StrokeCap, lineCap, LineCap, lineCapTags, StrokeCap::Butt) + + +/* parse the line join used during stroking a path. + * Value: miter | round | bevel | inherit + * Initial: miter + * https://www.w3.org/TR/SVG/painting.html + */ +static constexpr struct +{ + StrokeJoin lineJoin; + const char* tag; +} lineJoinTags[] = { + { StrokeJoin::Miter, "miter" }, + { StrokeJoin::Round, "round" }, + { StrokeJoin::Bevel, "bevel" } +}; + + +_PARSE_TAG(StrokeJoin, lineJoin, LineJoin, lineJoinTags, StrokeJoin::Miter) + + +/* parse the fill rule used during filling a path. + * Value: nonzero | evenodd | inherit + * Initial: nonzero + * https://www.w3.org/TR/SVG/painting.html + */ +static constexpr struct +{ + FillRule fillRule; + const char* tag; +} fillRuleTags[] = { + { FillRule::EvenOdd, "evenodd" } +}; + + +_PARSE_TAG(FillRule, fillRule, FillRule, fillRuleTags, FillRule::NonZero) + + +/* parse the dash pattern used during stroking a path. + * Value: none | | inherit + * Initial: none + * https://www.w3.org/TR/SVG/painting.html + */ +static void _parseDashArray(SvgLoaderData* loader, const char *str, SvgDash* dash) +{ + if (!strncmp(str, "none", 4)) return; + + char *end = nullptr; + + while (*str) { + str = svgUtilSkipWhiteSpaceAndComma(str); + auto parsedValue = toFloat(str, &end); + if (str == end) break; + if (parsedValue < 0.0f) { + dash->array.reset(); + return; + } + if (*end == '%') { + ++end; + //Refers to the diagonal length of the viewport. + //https://www.w3.org/TR/SVG2/coords.html#Units + parsedValue = (sqrtf(powf(loader->svgParse->global.w, 2) + powf(loader->svgParse->global.h, 2)) / sqrtf(2.0f)) * (parsedValue / 100.0f); + } + dash->array.push(parsedValue); + str = end; + } +} + + +static char* _idFromUrl(const char* url) +{ + auto open = strchr(url, '('); + auto close = strchr(url, ')'); + if (!open || !close || open >= close) return nullptr; + + open = strchr(url, '#'); + if (!open || open >= close) return nullptr; + + ++open; + --close; + + //trim the rest of the spaces and the quote marks if any + while (open < close && (*close == ' ' || *close == '\'' || *close == '\"')) --close; + + //quick verification + for (auto id = open; id < close; id++) { + if (*id == ' ' || *id == '\'') return nullptr; + } + + return duplicate(open, (close - open + 1)); +} + + +static size_t _srcFromUrl(const char* url, char*& src) +{ + src = (char*)strchr(url, '('); + auto close = strchr(url, ')'); + if (!src || !close || src >= close) return 0; + + src = strchr(src, '\''); + if (!src || src >= close) return 0; + ++src; + + close = strchr(src, '\''); + if (!close || close == src) return 0; + --close; + + while (src < close && *src == ' ') ++src; + while (src < close && *close == ' ') --close; + + return close - src + 1; +} + + +static unsigned char _parseColor(const char* value, char** end) +{ + auto r = toFloat(value, end); + *end = (char*)svgUtilSkipWhiteSpace(*end, nullptr); + if (**end == '%') { + r = 255 * r / 100; + (*end)++; + } + *end = (char*)svgUtilSkipWhiteSpace(*end, nullptr); + + if (r < 0 || r > 255) { + *end = nullptr; + return 0; + } + + return lrint(r); +} + + +static constexpr struct +{ + const char* name; + unsigned int value; +} colors[] = { + { "aliceblue", 0xfff0f8ff }, + { "antiquewhite", 0xfffaebd7 }, + { "aqua", 0xff00ffff }, + { "aquamarine", 0xff7fffd4 }, + { "azure", 0xfff0ffff }, + { "beige", 0xfff5f5dc }, + { "bisque", 0xffffe4c4 }, + { "black", 0xff000000 }, + { "blanchedalmond", 0xffffebcd }, + { "blue", 0xff0000ff }, + { "blueviolet", 0xff8a2be2 }, + { "brown", 0xffa52a2a }, + { "burlywood", 0xffdeb887 }, + { "cadetblue", 0xff5f9ea0 }, + { "chartreuse", 0xff7fff00 }, + { "chocolate", 0xffd2691e }, + { "coral", 0xffff7f50 }, + { "cornflowerblue", 0xff6495ed }, + { "cornsilk", 0xfffff8dc }, + { "crimson", 0xffdc143c }, + { "cyan", 0xff00ffff }, + { "darkblue", 0xff00008b }, + { "darkcyan", 0xff008b8b }, + { "darkgoldenrod", 0xffb8860b }, + { "darkgray", 0xffa9a9a9 }, + { "darkgrey", 0xffa9a9a9 }, + { "darkgreen", 0xff006400 }, + { "darkkhaki", 0xffbdb76b }, + { "darkmagenta", 0xff8b008b }, + { "darkolivegreen", 0xff556b2f }, + { "darkorange", 0xffff8c00 }, + { "darkorchid", 0xff9932cc }, + { "darkred", 0xff8b0000 }, + { "darksalmon", 0xffe9967a }, + { "darkseagreen", 0xff8fbc8f }, + { "darkslateblue", 0xff483d8b }, + { "darkslategray", 0xff2f4f4f }, + { "darkslategrey", 0xff2f4f4f }, + { "darkturquoise", 0xff00ced1 }, + { "darkviolet", 0xff9400d3 }, + { "deeppink", 0xffff1493 }, + { "deepskyblue", 0xff00bfff }, + { "dimgray", 0xff696969 }, + { "dimgrey", 0xff696969 }, + { "dodgerblue", 0xff1e90ff }, + { "firebrick", 0xffb22222 }, + { "floralwhite", 0xfffffaf0 }, + { "forestgreen", 0xff228b22 }, + { "fuchsia", 0xffff00ff }, + { "gainsboro", 0xffdcdcdc }, + { "ghostwhite", 0xfff8f8ff }, + { "gold", 0xffffd700 }, + { "goldenrod", 0xffdaa520 }, + { "gray", 0xff808080 }, + { "grey", 0xff808080 }, + { "green", 0xff008000 }, + { "greenyellow", 0xffadff2f }, + { "honeydew", 0xfff0fff0 }, + { "hotpink", 0xffff69b4 }, + { "indianred", 0xffcd5c5c }, + { "indigo", 0xff4b0082 }, + { "ivory", 0xfffffff0 }, + { "khaki", 0xfff0e68c }, + { "lavender", 0xffe6e6fa }, + { "lavenderblush", 0xfffff0f5 }, + { "lawngreen", 0xff7cfc00 }, + { "lemonchiffon", 0xfffffacd }, + { "lightblue", 0xffadd8e6 }, + { "lightcoral", 0xfff08080 }, + { "lightcyan", 0xffe0ffff }, + { "lightgoldenrodyellow", 0xfffafad2 }, + { "lightgray", 0xffd3d3d3 }, + { "lightgrey", 0xffd3d3d3 }, + { "lightgreen", 0xff90ee90 }, + { "lightpink", 0xffffb6c1 }, + { "lightsalmon", 0xffffa07a }, + { "lightseagreen", 0xff20b2aa }, + { "lightskyblue", 0xff87cefa }, + { "lightslategray", 0xff778899 }, + { "lightslategrey", 0xff778899 }, + { "lightsteelblue", 0xffb0c4de }, + { "lightyellow", 0xffffffe0 }, + { "lime", 0xff00ff00 }, + { "limegreen", 0xff32cd32 }, + { "linen", 0xfffaf0e6 }, + { "magenta", 0xffff00ff }, + { "maroon", 0xff800000 }, + { "mediumaquamarine", 0xff66cdaa }, + { "mediumblue", 0xff0000cd }, + { "mediumorchid", 0xffba55d3 }, + { "mediumpurple", 0xff9370d8 }, + { "mediumseagreen", 0xff3cb371 }, + { "mediumslateblue", 0xff7b68ee }, + { "mediumspringgreen", 0xff00fa9a }, + { "mediumturquoise", 0xff48d1cc }, + { "mediumvioletred", 0xffc71585 }, + { "midnightblue", 0xff191970 }, + { "mintcream", 0xfff5fffa }, + { "mistyrose", 0xffffe4e1 }, + { "moccasin", 0xffffe4b5 }, + { "navajowhite", 0xffffdead }, + { "navy", 0xff000080 }, + { "oldlace", 0xfffdf5e6 }, + { "olive", 0xff808000 }, + { "olivedrab", 0xff6b8e23 }, + { "orange", 0xffffa500 }, + { "orangered", 0xffff4500 }, + { "orchid", 0xffda70d6 }, + { "palegoldenrod", 0xffeee8aa }, + { "palegreen", 0xff98fb98 }, + { "paleturquoise", 0xffafeeee }, + { "palevioletred", 0xffd87093 }, + { "papayawhip", 0xffffefd5 }, + { "peachpuff", 0xffffdab9 }, + { "peru", 0xffcd853f }, + { "pink", 0xffffc0cb }, + { "plum", 0xffdda0dd }, + { "powderblue", 0xffb0e0e6 }, + { "purple", 0xff800080 }, + { "red", 0xffff0000 }, + { "rosybrown", 0xffbc8f8f }, + { "royalblue", 0xff4169e1 }, + { "saddlebrown", 0xff8b4513 }, + { "salmon", 0xfffa8072 }, + { "sandybrown", 0xfff4a460 }, + { "seagreen", 0xff2e8b57 }, + { "seashell", 0xfffff5ee }, + { "sienna", 0xffa0522d }, + { "silver", 0xffc0c0c0 }, + { "skyblue", 0xff87ceeb }, + { "slateblue", 0xff6a5acd }, + { "slategray", 0xff708090 }, + { "slategrey", 0xff708090 }, + { "snow", 0xfffffafa }, + { "springgreen", 0xff00ff7f }, + { "steelblue", 0xff4682b4 }, + { "tan", 0xffd2b48c }, + { "teal", 0xff008080 }, + { "thistle", 0xffd8bfd8 }, + { "tomato", 0xffff6347 }, + { "turquoise", 0xff40e0d0 }, + { "violet", 0xffee82ee }, + { "wheat", 0xfff5deb3 }, + { "white", 0xffffffff }, + { "whitesmoke", 0xfff5f5f5 }, + { "yellow", 0xffffff00 }, + { "yellowgreen", 0xff9acd32 } +}; + + +static bool _toColor(const char* str, uint8_t& r, uint8_t&g, uint8_t& b, char** ref) +{ + auto len = strlen(str); + + if (len == 4 && str[0] == '#') { + //Case for "#456" should be interpreted as "#445566" + if (isxdigit(str[1]) && isxdigit(str[2]) && isxdigit(str[3])) { + char tmp[3] = { '\0', '\0', '\0' }; + tmp[0] = str[1]; + tmp[1] = str[1]; + r = strtol(tmp, nullptr, 16); + tmp[0] = str[2]; + tmp[1] = str[2]; + g = strtol(tmp, nullptr, 16); + tmp[0] = str[3]; + tmp[1] = str[3]; + b = strtol(tmp, nullptr, 16); + } + return true; + } else if (len == 7 && str[0] == '#') { + if (isxdigit(str[1]) && isxdigit(str[2]) && isxdigit(str[3]) && isxdigit(str[4]) && isxdigit(str[5]) && isxdigit(str[6])) { + char tmp[3] = { '\0', '\0', '\0' }; + tmp[0] = str[1]; + tmp[1] = str[2]; + r = strtol(tmp, nullptr, 16); + tmp[0] = str[3]; + tmp[1] = str[4]; + g = strtol(tmp, nullptr, 16); + tmp[0] = str[5]; + tmp[1] = str[6]; + b = strtol(tmp, nullptr, 16); + } + return true; + } else if (len >= 10 && (str[0] == 'r' || str[0] == 'R') && (str[1] == 'g' || str[1] == 'G') && (str[2] == 'b' || str[2] == 'B') && str[3] == '(' && str[len - 1] == ')') { + char *red, *green, *blue; + auto tr = _parseColor(str + 4, &red); + if (red && *red == ',') { + auto tg = _parseColor(red + 1, &green); + if (green && *green == ',') { + auto tb = _parseColor(green + 1, &blue); + if (blue && blue[0] == ')' && blue[1] == '\0') { + r = tr; + g = tg; + b = tb; + } + } + } + return true; + } else if (ref && len >= 3 && !strncmp(str, "url", 3)) { + tvg::free(*ref); + *ref = _idFromUrl((const char*)(str + 3)); + return true; + } else if (len >= 10 && (str[0] == 'h' || str[0] == 'H') && (str[1] == 's' || str[1] == 'S') && (str[2] == 'l' || str[2] == 'L') && str[3] == '(' && str[len - 1] == ')') { + tvg::HSL hsl; + const char* content = svgUtilSkipWhiteSpace(str + 4, nullptr); + const char* hue = nullptr; + if (_parseNumber(&content, &hue, &hsl.h) && hue) { + const char* saturation = nullptr; + hue = svgUtilSkipWhiteSpace(hue, nullptr); + hue = (char*)svgUtilSkipWhiteSpaceAndComma(hue); + hue = svgUtilSkipWhiteSpace(hue, nullptr); + if (_parseNumber(&hue, &saturation, &hsl.s) && saturation && *saturation == '%') { + const char* brightness = nullptr; + hsl.s /= 100.0f; + saturation = svgUtilSkipWhiteSpace(saturation + 1, nullptr); + saturation = (char*)svgUtilSkipWhiteSpaceAndComma(saturation); + saturation = svgUtilSkipWhiteSpace(saturation, nullptr); + if (_parseNumber(&saturation, &brightness, &hsl.l) && brightness && *brightness == '%') { + hsl.l /= 100.0f; + brightness = svgUtilSkipWhiteSpace(brightness + 1, nullptr); + if (brightness && brightness[0] == ')' && brightness[1] == '\0') { + hsl2rgb(hsl.h, tvg::clamp(hsl.s, 0.0f, 1.0f), tvg::clamp(hsl.l, 0.0f, 1.0f), r, g, b); + return true; + } + } + } + } + } else { + //Handle named color + for (unsigned int i = 0; i < (sizeof(colors) / sizeof(colors[0])); i++) { + if (!strcasecmp(colors[i].name, str)) { + r = ((uint8_t*)(&(colors[i].value)))[2]; + g = ((uint8_t*)(&(colors[i].value)))[1]; + b = ((uint8_t*)(&(colors[i].value)))[0]; + return true; + } + } + } + return false; +} + + +static char* _parseNumbersArray(char* str, float* points, int* ptCount, int len) +{ + int count = 0; + + str = (char*)svgUtilSkipWhiteSpace(str, nullptr); + while ((count < len) && (isdigit(*str) || *str == '-' || *str == '+' || *str == '.')) { + char* end = nullptr; + points[count++] = toFloat(str, &end); + str = end; + str = (char*)svgUtilSkipWhiteSpaceAndComma(str); + //Eat the rest of space + str = (char*)svgUtilSkipWhiteSpace(str, nullptr); + } + *ptCount = count; + return str; +} + + +enum class MatrixState { + Unknown, + Matrix, + Translate, + Rotate, + Scale, + SkewX, + SkewY +}; + + +#define MATRIX_DEF(Name, Value) \ + { \ +#Name, sizeof(#Name), Value \ + } + + +static constexpr struct +{ + const char* tag; + int sz; + MatrixState state; +} matrixTags[] = { + MATRIX_DEF(matrix, MatrixState::Matrix), + MATRIX_DEF(translate, MatrixState::Translate), + MATRIX_DEF(rotate, MatrixState::Rotate), + MATRIX_DEF(scale, MatrixState::Scale), + MATRIX_DEF(skewX, MatrixState::SkewX), + MATRIX_DEF(skewY, MatrixState::SkewY) +}; + + +/* parse transform attribute + * https://www.w3.org/TR/SVG/coords.html#TransformAttribute + */ +static Matrix* _parseTransformationMatrix(const char* value) +{ + const int POINT_CNT = 8; + + auto matrix = tvg::malloc(sizeof(Matrix)); + tvg::identity(matrix); + + float points[POINT_CNT]; + int ptCount = 0; + auto str = (char*)value; + auto end = str + strlen(str); + + while (str < end) { + auto state = MatrixState::Unknown; + + if (isspace(*str) || (*str == ',')) { + ++str; + continue; + } + for (unsigned int i = 0; i < sizeof(matrixTags) / sizeof(matrixTags[0]); i++) { + if (!strncmp(matrixTags[i].tag, str, matrixTags[i].sz - 1)) { + state = matrixTags[i].state; + str += (matrixTags[i].sz - 1); + break; + } + } + if (state == MatrixState::Unknown) goto error; + + str = (char*)svgUtilSkipWhiteSpace(str, end); + if (*str != '(') goto error; + ++str; + str = _parseNumbersArray(str, points, &ptCount, POINT_CNT); + if (*str != ')') goto error; + ++str; + + if (state == MatrixState::Matrix) { + if (ptCount != 6) goto error; + Matrix tmp = {points[0], points[2], points[4], points[1], points[3], points[5], 0, 0, 1}; + *matrix *= tmp; + } else if (state == MatrixState::Translate) { + if (ptCount == 1) { + Matrix tmp = {1, 0, points[0], 0, 1, 0, 0, 0, 1}; + *matrix *= tmp; + } else if (ptCount == 2) { + Matrix tmp = {1, 0, points[0], 0, 1, points[1], 0, 0, 1}; + *matrix *= tmp; + } else goto error; + } else if (state == MatrixState::Rotate) { + //Transform to signed. + points[0] = fmodf(points[0], 360.0f); + if (points[0] < 0) points[0] += 360.0f; + auto c = cosf(deg2rad(points[0])); + auto s = sinf(deg2rad(points[0])); + if (ptCount == 1) { + Matrix tmp = { c, -s, 0, s, c, 0, 0, 0, 1 }; + *matrix *= tmp; + } else if (ptCount == 3) { + Matrix tmp = { 1, 0, points[1], 0, 1, points[2], 0, 0, 1 }; + *matrix *= tmp; + tmp = { c, -s, 0, s, c, 0, 0, 0, 1 }; + *matrix *= tmp; + tmp = { 1, 0, -points[1], 0, 1, -points[2], 0, 0, 1 }; + *matrix *= tmp; + } else { + goto error; + } + } else if (state == MatrixState::Scale) { + if (ptCount < 1 || ptCount > 2) goto error; + auto sx = points[0]; + auto sy = sx; + if (ptCount == 2) sy = points[1]; + Matrix tmp = { sx, 0, 0, 0, sy, 0, 0, 0, 1 }; + *matrix *= tmp; + } else if (state == MatrixState::SkewX) { + if (ptCount != 1) goto error; + auto deg = tanf(deg2rad(points[0])); + Matrix tmp = { 1, deg, 0, 0, 1, 0, 0, 0, 1 }; + *matrix *= tmp; + } else if (state == MatrixState::SkewY) { + if (ptCount != 1) goto error; + auto deg = tanf(deg2rad(points[0])); + Matrix tmp = { 1, 0, 0, deg, 1, 0, 0, 0, 1 }; + *matrix *= tmp; + } + } + return matrix; +error: + tvg::free(matrix); + return nullptr; +} + + +#define LENGTH_DEF(Name, Value) \ + { \ +#Name, sizeof(#Name), Value \ + } + + +static bool _attrParseSvgNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgDocNode* doc = &(node->node.doc); + + if (STR_AS(key, "width")) { + doc->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal); + if (strstr(value, "%") && !(doc->viewFlag & SvgViewFlag::Viewbox)) { + doc->viewFlag = (doc->viewFlag | SvgViewFlag::WidthInPercent); + } else { + doc->viewFlag = (doc->viewFlag | SvgViewFlag::Width); + } + } else if (STR_AS(key, "height")) { + doc->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical); + if (strstr(value, "%") && !(doc->viewFlag & SvgViewFlag::Viewbox)) { + doc->viewFlag = (doc->viewFlag | SvgViewFlag::HeightInPercent); + } else { + doc->viewFlag = (doc->viewFlag | SvgViewFlag::Height); + } + } else if (STR_AS(key, "viewBox")) { + if (_parseNumber(&value, nullptr, &doc->vbox.x)) { + if (_parseNumber(&value, nullptr, &doc->vbox.y)) { + if (_parseNumber(&value, nullptr, &doc->vbox.w)) { + if (_parseNumber(&value, nullptr, &doc->vbox.h)) { + doc->viewFlag = (doc->viewFlag | SvgViewFlag::Viewbox); + loader->svgParse->global.h = doc->vbox.h; + } + loader->svgParse->global.w = doc->vbox.w; + } + loader->svgParse->global.y = doc->vbox.y; + } + loader->svgParse->global.x = doc->vbox.x; + } + if ((doc->viewFlag & SvgViewFlag::Viewbox) && (doc->vbox.w < 0.0f || doc->vbox.h < 0.0f)) { + doc->viewFlag = (SvgViewFlag)((uint32_t)doc->viewFlag & ~(uint32_t)SvgViewFlag::Viewbox); + TVGLOG("SVG", "Negative values of the width and/or height - the attribute invalidated."); + } + if (!(doc->viewFlag & SvgViewFlag::Viewbox)) { + loader->svgParse->global.x = loader->svgParse->global.y = 0.0f; + loader->svgParse->global.w = loader->svgParse->global.h = 1.0f; + } + } else if (STR_AS(key, "preserveAspectRatio")) { + _parseAspectRatio(&value, &doc->align, &doc->meetOrSlice); + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); +#ifdef THORVG_LOG_ENABLED + } else if ((STR_AS(key, "x") || STR_AS(key, "y")) && fabsf(toFloat(value, nullptr)) > FLOAT_EPSILON) { + TVGLOG("SVG", "Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]", key, value); +#endif + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +//https://www.w3.org/TR/SVGTiny12/painting.html#SpecifyingPaint +static void _handlePaintAttr(SvgPaint* paint, const char* value) +{ + if (STR_AS(value, "none")) { + //No paint property + paint->none = true; + return; + } + if (STR_AS(value, "currentColor")) { + paint->curColor = true; + paint->none = false; + return; + } + if (_toColor(value, paint->color.r, paint->color.g, paint->color.b, &paint->url)) paint->none = false; +} + + +static void _handleColorAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto style = node->style; + if (_toColor(value, style->color.r, style->color.g, style->color.b, nullptr)) { + style->curColorSet = true; + } +} + + +static void _handleFillAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto style = node->style; + style->fill.flags = (style->fill.flags | SvgFillFlags::Paint); + _handlePaintAttr(&style->fill.paint, value); +} + + +static void _handleStrokeAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto style = node->style; + style->stroke.flags = (style->stroke.flags | SvgStrokeFlags::Paint); + _handlePaintAttr(&style->stroke.paint, value); +} + + +static void _handleStrokeOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Opacity); + node->style->stroke.opacity = _toOpacity(value); +} + +static void _handleStrokeDashArrayAttr(SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Dash); + _parseDashArray(loader, value, &node->style->stroke.dash); +} + +static void _handleStrokeDashOffsetAttr(SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::DashOffset); + node->style->stroke.dash.offset = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal); +} + +static void _handleStrokeWidthAttr(SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Width); + node->style->stroke.width = _toFloat(loader->svgParse, value, SvgParserLengthType::Diagonal); +} + + +static void _handleStrokeLineCapAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Cap); + node->style->stroke.cap = _toLineCap(value); +} + + +static void _handleStrokeLineJoinAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Join); + node->style->stroke.join = _toLineJoin(value); +} + +static void _handleStrokeMiterlimitAttr(SvgLoaderData* loader, SvgNode* node, const char* value) +{ + char* end = nullptr; + const float miterlimit = toFloat(value, &end); + + // https://www.w3.org/TR/SVG2/painting.html#LineJoin + // - A negative value for stroke-miterlimit must be treated as an illegal value. + if (miterlimit < 0.0f) { + TVGERR("SVG", "A stroke-miterlimit change (%f <- %f) with a negative value is omitted.", node->style->stroke.miterlimit, miterlimit); + return; + } + + node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Miterlimit); + node->style->stroke.miterlimit = miterlimit; +} + +static void _handleFillRuleAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->fill.flags = (node->style->fill.flags | SvgFillFlags::FillRule); + node->style->fill.fillRule = _toFillRule(value); +} + + +static void _handleOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->flags = (node->style->flags | SvgStyleFlags::Opacity); + node->style->opacity = _toOpacity(value); +} + + +static void _handleFillOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->fill.flags = (node->style->fill.flags | SvgFillFlags::Opacity); + node->style->fill.opacity = _toOpacity(value); +} + + +static void _handleTransformAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->transform = _parseTransformationMatrix(value); +} + + +static void _handleClipPathAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto style = node->style; + int len = strlen(value); + if (len >= 3 && !strncmp(value, "url", 3)) { + tvg::free(style->clipPath.url); + style->clipPath.url = _idFromUrl((const char*)(value + 3)); + } +} + + +static void _handleMaskAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto style = node->style; + int len = strlen(value); + if (len >= 3 && !strncmp(value, "url", 3)) { + tvg::free(style->mask.url); + style->mask.url = _idFromUrl((const char*)(value + 3)); + } +} + + +static void _handleFilterAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto style = node->style; + int len = strlen(value); + if (len >= 3 && !strncmp(value, "url", 3)) { + if (style->filter.url) tvg::free(style->filter.url); + style->filter.url = _idFromUrl((const char*)(value + 3)); + } +} + + +static void _handleMaskTypeAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->node.mask.type = _toMaskType(value); +} + + +static void _handleDisplayAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + //TODO : The display attribute can have various values as well as "none". + // The default is "inline" which means visible and "none" means invisible. + // Depending on the type of node, additional functionality may be required. + // refer to https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/display + node->style->flags = (node->style->flags | SvgStyleFlags::Display); + if (STR_AS(value, "none")) node->style->display = false; + else node->style->display = true; +} + + +static bool _cssApplyClass(SvgNode* node, const char* classString, SvgNode* styleRoot); + +static void _handlePaintOrderAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) +{ + node->style->flags = (node->style->flags | SvgStyleFlags::PaintOrder); + node->style->paintOrder = _toPaintOrder(value); +} + + +static void _handleCssClassAttr(SvgLoaderData* loader, SvgNode* node, const char* value) +{ + auto cssClass = &node->style->cssClass; + + if (value) tvg::free(*cssClass); + *cssClass = _copyId(value); + + if (!_cssApplyClass(node, *cssClass, loader->cssStyle)) { + loader->nodesToStyle.push({node, *cssClass}); + } +} + + +typedef void (*styleMethod)(SvgLoaderData* loader, SvgNode* node, const char* value); + +#define STYLE_DEF(Name, Name1, Flag) { #Name, sizeof(#Name), _handle##Name1##Attr, Flag } + + +static constexpr struct +{ + const char* tag; + int sz; + styleMethod tagHandler; + SvgStyleFlags flag; +} styleTags[] = { + STYLE_DEF(color, Color, SvgStyleFlags::Color), + STYLE_DEF(fill, Fill, SvgStyleFlags::Fill), + STYLE_DEF(fill-rule, FillRule, SvgStyleFlags::FillRule), + STYLE_DEF(fill-opacity, FillOpacity, SvgStyleFlags::FillOpacity), + STYLE_DEF(opacity, Opacity, SvgStyleFlags::Opacity), + STYLE_DEF(stroke, Stroke, SvgStyleFlags::Stroke), + STYLE_DEF(stroke-width, StrokeWidth, SvgStyleFlags::StrokeWidth), + STYLE_DEF(stroke-linejoin, StrokeLineJoin, SvgStyleFlags::StrokeLineJoin), + STYLE_DEF(stroke-miterlimit, StrokeMiterlimit, SvgStyleFlags::StrokeMiterlimit), + STYLE_DEF(stroke-linecap, StrokeLineCap, SvgStyleFlags::StrokeLineCap), + STYLE_DEF(stroke-opacity, StrokeOpacity, SvgStyleFlags::StrokeOpacity), + STYLE_DEF(stroke-dasharray, StrokeDashArray, SvgStyleFlags::StrokeDashArray), + STYLE_DEF(stroke-dashoffset, StrokeDashOffset, SvgStyleFlags::StrokeDashOffset), + STYLE_DEF(transform, Transform, SvgStyleFlags::Transform), + STYLE_DEF(clip-path, ClipPath, SvgStyleFlags::ClipPath), + STYLE_DEF(mask, Mask, SvgStyleFlags::Mask), + STYLE_DEF(mask-type, MaskType, SvgStyleFlags::MaskType), + STYLE_DEF(display, Display, SvgStyleFlags::Display), + STYLE_DEF(paint-order, PaintOrder, SvgStyleFlags::PaintOrder), + STYLE_DEF(filter, Filter, SvgStyleFlags::Filter) +}; + + +static SvgXmlSpace _toXmlSpace(const char* str) +{ + if (STR_AS(str, "default")) return SvgXmlSpace::Default; + if (STR_AS(str, "preserve")) return SvgXmlSpace::Preserve; + return SvgXmlSpace::None; +} + + +static bool _parseStyleAttr(void* data, const char* key, const char* value, bool style) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + int sz; + if (!key || !value) return false; + + //Trim the white space + key = svgUtilSkipWhiteSpace(key, nullptr); + value = svgUtilSkipWhiteSpace(value, nullptr); + + if (!style && STR_AS(key, "xml:space")) { + node->xmlSpace = _toXmlSpace(value); + return true; + } + + sz = strlen(key); + for (unsigned int i = 0; i < sizeof(styleTags) / sizeof(styleTags[0]); i++) { + if (styleTags[i].sz - 1 == sz && !strncmp(styleTags[i].tag, key, sz)) { + bool importance = false; + if (auto ptr = strstr(value, "!important")) { + size_t size = ptr - value; + while (size > 0 && isspace(value[size - 1])) { + size--; + } + value = duplicate(value, size); + importance = true; + } + if (style) { + if (importance || !(node->style->flagsImportance & styleTags[i].flag)) { + styleTags[i].tagHandler(loader, node, value); + node->style->flags = (node->style->flags | styleTags[i].flag); + } + } else if (!(node->style->flags & styleTags[i].flag)) { + styleTags[i].tagHandler(loader, node, value); + } + if (importance) { + node->style->flagsImportance = (node->style->flags | styleTags[i].flag); + tvg::free(const_cast(value)); + } + return true; + } + } + + return false; +} + + +static bool _parseStyleAttr(void* data, const char* key, const char* value) +{ + return _parseStyleAttr(data, key, value, true); +} + + +/* parse g node + * https://www.w3.org/TR/SVG/struct.html#Groups + */ +static bool _attrParseGNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + + if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "transform")) { + node->transform = _parseTransformationMatrix(value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +/* parse clipPath node + * https://www.w3.org/TR/SVG/struct.html#Groups + */ +static bool _attrParseClipPathNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgClipNode* clip = &(node->node.clip); + + if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "transform")) { + node->transform = _parseTransformationMatrix(value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "clipPathUnits")) { + if (STR_AS(value, "objectBoundingBox")) clip->userSpace = false; + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static bool _attrParseMaskNode(void* data, const char* key, const char* value) +{ + auto loader = (SvgLoaderData*)data; + auto node = loader->svgParse->node; + auto mask = &(node->node.mask); + + if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "transform")) { + node->transform = _parseTransformationMatrix(value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "maskContentUnits")) { + if (STR_AS(value, "objectBoundingBox")) mask->userSpace = false; + } else if (STR_AS(key, "mask-type")) { + mask->type = _toMaskType(value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static bool _attrParseCssStyleNode(void* data, const char* key, const char* value) +{ + auto loader = (SvgLoaderData*)data; + auto node = loader->svgParse->node; + + if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static bool _attrParseSymbolNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgSymbolNode* symbol = &(node->node.symbol); + + if (STR_AS(key, "viewBox")) { + if (!_parseNumber(&value, nullptr, &symbol->vx) || !_parseNumber(&value, nullptr, &symbol->vy)) return false; + if (!_parseNumber(&value, nullptr, &symbol->vw) || !_parseNumber(&value, nullptr, &symbol->vh)) return false; + symbol->hasViewBox = true; + } else if (STR_AS(key, "width")) { + symbol->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal); + symbol->hasWidth = true; + } else if (STR_AS(key, "height")) { + symbol->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical); + symbol->hasHeight = true; + } else if (STR_AS(key, "preserveAspectRatio")) { + _parseAspectRatio(&value, &symbol->align, &symbol->meetOrSlice); + } else if (STR_AS(key, "overflow")) { + if (STR_AS(value, "visible")) symbol->overflowVisible = true; + } else { + return _attrParseGNode(data, key, value); + } + return true; +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} boxTags[] = { + {"x", SvgParserLengthType::Horizontal, sizeof("x"), offsetof(Box, x)}, + {"y", SvgParserLengthType::Vertical, sizeof("y"), offsetof(Box, y)}, + {"width", SvgParserLengthType::Horizontal, sizeof("width"), offsetof(Box, w)}, + {"height", SvgParserLengthType::Vertical, sizeof("height"), offsetof(Box, h)} +}; + + +static bool _parseBox(const char* key, const char* value, Box* box, bool (&isPercentage)[4]) +{ + auto array = (unsigned char*)box; + int sz = strlen(key); + for (unsigned int i = 0; i < sizeof(boxTags) / sizeof(boxTags[0]); i++) { + if (boxTags[i].sz - 1 == sz && !strncmp(boxTags[i].tag, key, sz)) { + *(float*)(array + boxTags[i].offset) = _gradientToFloat(nullptr, value, isPercentage[i]); + return true; + } + } + return false; +} + + +static void _recalcBox(const SvgLoaderData* loader, Box* box, bool (&isPercentage)[4]) +{ + auto array = (unsigned char*)box; + for (unsigned int i = 0; i < sizeof(boxTags) / sizeof(boxTags[0]); i++) { + if (!isPercentage[i]) continue; + if (boxTags[i].type == SvgParserLengthType::Horizontal) *(float*)(array + boxTags[i].offset) *= loader->svgParse->global.w; + else *(float*)(array + boxTags[i].offset) *= loader->svgParse->global.h; + } +} + + +static bool _attrParseFilterNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgFilterNode* filter = &node->node.filter; + + _parseBox(key, value, &filter->box, filter->isPercentage); + + if (STR_AS(key, "id")) { + if (node->id && value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "primitiveUnits")) { + if (STR_AS(value, "objectBoundingBox")) filter->primitiveUserSpace = false; + } else if (STR_AS(key, "filterUnits")) { + if (STR_AS(value, "userSpaceOnUse")) filter->filterUserSpace = true; + } + return true; +} + + +static void _parseGaussianBlurStdDeviation(const char** content, float* x, float* y) +{ + auto str = *content; + char* end = nullptr; + float deviation[2] = {0, 0}; + int n = 0; + + while (*str && n < 2) { + str = svgUtilSkipWhiteSpaceAndComma(str); + auto parsedValue = toFloat(str, &end); + if (parsedValue < 0.0f) break; + deviation[n++] = parsedValue; + str = end; + } + + *x = deviation[0]; + *y = n == 1 ? deviation[0] : deviation[1]; +} + + +static bool _attrParseGaussianBlurNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgGaussianBlurNode* gaussianBlur = &node->node.gaussianBlur; + + if (_parseBox(key, value, &gaussianBlur->box, gaussianBlur->isPercentage)) gaussianBlur->hasBox = true; + + if (STR_AS(key, "id")) { + if (node->id && value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "stdDeviation")) { + _parseGaussianBlurStdDeviation(&value, &gaussianBlur->stdDevX, &gaussianBlur->stdDevY); + } else if (STR_AS(key, "edgeMode")) { + if (STR_AS(value, "wrap")) gaussianBlur->edgeModeWrap = true; + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createNode(SvgNode* parent, SvgNodeType type) +{ + SvgNode* node = tvg::calloc(1, sizeof(SvgNode)); + + //Default fill property + node->style = tvg::calloc(1, sizeof(SvgStyleProperty)); + + //Set the default values other than 0/false: https://www.w3.org/TR/SVGTiny12/painting.html#SpecifyingPaint + node->style->opacity = 255; + node->style->fill.opacity = 255; + node->style->fill.fillRule = FillRule::NonZero; + node->style->stroke.paint.none = true; + node->style->stroke.opacity = 255; + node->style->stroke.width = 1; + node->style->stroke.cap = StrokeCap::Butt; + node->style->stroke.join = StrokeJoin::Miter; + node->style->stroke.miterlimit = 4.0f; + node->style->stroke.scale = 1.0; + node->style->paintOrder = _toPaintOrder("fill stroke"); + node->style->display = true; + node->parent = parent; + node->type = type; + node->xmlSpace = SvgXmlSpace::None; + + if (parent) parent->child.push(node); + return node; +} + + +static SvgNode* _createDefsNode(TVG_UNUSED SvgLoaderData* loader, TVG_UNUSED SvgNode* parent, const char* buf, unsigned bufLength, TVG_UNUSED parseAttributes func) +{ + if (loader->def && loader->doc->node.doc.defs) return loader->def; + loader->def = loader->doc->node.doc.defs = _createNode(nullptr, SvgNodeType::Defs); + return loader->def; +} + + +static SvgNode* _createGNode(TVG_UNUSED SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::G); + func(buf, bufLength, _attrParseGNode, loader); + return loader->svgParse->node; +} + + +static SvgNode* _createSvgNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Doc); + auto doc = &(loader->svgParse->node->node.doc); + + loader->svgParse->global.w = 1.0f; + loader->svgParse->global.h = 1.0f; + + doc->align = AspectRatioAlign::XMidYMid; + doc->meetOrSlice = AspectRatioMeetOrSlice::Meet; + doc->viewFlag = SvgViewFlag::None; + func(buf, bufLength, _attrParseSvgNode, loader); + + if (!(doc->viewFlag & SvgViewFlag::Viewbox)) { + if (doc->viewFlag & SvgViewFlag::Width) { + loader->svgParse->global.w = doc->w; + } + if (doc->viewFlag & SvgViewFlag::Height) { + loader->svgParse->global.h = doc->h; + } + } + return loader->svgParse->node; +} + + +static SvgNode* _createMaskNode(SvgLoaderData* loader, SvgNode* parent, TVG_UNUSED const char* buf, TVG_UNUSED unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Mask); + if (!loader->svgParse->node) return nullptr; + + loader->svgParse->node->node.mask.userSpace = true; + loader->svgParse->node->node.mask.type = SvgMaskType::Luminance; + + func(buf, bufLength, _attrParseMaskNode, loader); + + return loader->svgParse->node; +} + + +static SvgNode* _createClipPathNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::ClipPath); + if (!loader->svgParse->node) return nullptr; + + loader->svgParse->node->style->display = false; + loader->svgParse->node->node.clip.userSpace = true; + + func(buf, bufLength, _attrParseClipPathNode, loader); + + return loader->svgParse->node; +} + + +static SvgNode* _createCssStyleNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::CssStyle); + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseCssStyleNode, loader); + + return loader->svgParse->node; +} + + +static SvgNode* _createSymbolNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Symbol); + if (!loader->svgParse->node) return nullptr; + + loader->svgParse->node->node.symbol.align = AspectRatioAlign::XMidYMid; + loader->svgParse->node->node.symbol.meetOrSlice = AspectRatioMeetOrSlice::Meet; + + func(buf, bufLength, _attrParseSymbolNode, loader); + + return loader->svgParse->node; +} + + +static SvgNode* _createGaussianBlurNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::GaussianBlur); + if (!loader->svgParse->node) return nullptr; + + loader->svgParse->node->style->display = false; + loader->svgParse->node->node.gaussianBlur.box = {0.0f, 0.0f, 1.0f, 1.0f}; + + func(buf, bufLength, _attrParseGaussianBlurNode, loader); + + return loader->svgParse->node; +} + + +static SvgNode* _createFilterNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Filter); + if (!loader->svgParse->node) return nullptr; + SvgFilterNode& filter = loader->svgParse->node->node.filter; + + loader->svgParse->node->style->display = false; + filter.box = {-0.1f, -0.1f, 1.2f, 1.2f}; + filter.primitiveUserSpace = true; + + func(buf, bufLength, _attrParseFilterNode, loader); + + if (filter.filterUserSpace) _recalcBox(loader, &filter.box, filter.isPercentage); + + return loader->svgParse->node; +} + + +static bool _attrParsePathNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgPathNode* path = &(node->node.path); + + if (STR_AS(key, "d")) { + tvg::free(path->path); + //Temporary: need to copy + path->path = _copyId(value); + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createPathNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Path); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParsePathNode, loader); + + return loader->svgParse->node; +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} circleTags[] = { + {"cx", SvgParserLengthType::Horizontal, sizeof("cx"), offsetof(SvgCircleNode, cx)}, + {"cy", SvgParserLengthType::Vertical, sizeof("cy"), offsetof(SvgCircleNode, cy)}, + {"r", SvgParserLengthType::Diagonal, sizeof("r"), offsetof(SvgCircleNode, r)} +}; + + +/* parse the attributes for a circle element. + * https://www.w3.org/TR/SVG/shapes.html#CircleElement + */ +static bool _attrParseCircleNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgCircleNode* circle = &(node->node.circle); + unsigned char* array; + int sz = strlen(key); + + array = (unsigned char*)circle; + for (unsigned int i = 0; i < sizeof(circleTags) / sizeof(circleTags[0]); i++) { + if (circleTags[i].sz - 1 == sz && !strncmp(circleTags[i].tag, key, sz)) { + *((float*)(array + circleTags[i].offset)) = _toFloat(loader->svgParse, value, circleTags[i].type); + return true; + } + } + + if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createCircleNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Circle); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseCircleNode, loader); + return loader->svgParse->node; +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} ellipseTags[] = { + {"cx", SvgParserLengthType::Horizontal, sizeof("cx"), offsetof(SvgEllipseNode, cx)}, + {"cy", SvgParserLengthType::Vertical, sizeof("cy"), offsetof(SvgEllipseNode, cy)}, + {"rx", SvgParserLengthType::Horizontal, sizeof("rx"), offsetof(SvgEllipseNode, rx)}, + {"ry", SvgParserLengthType::Vertical, sizeof("ry"), offsetof(SvgEllipseNode, ry)} +}; + + +/* parse the attributes for an ellipse element. + * https://www.w3.org/TR/SVG/shapes.html#EllipseElement + */ +static bool _attrParseEllipseNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgEllipseNode* ellipse = &(node->node.ellipse); + unsigned char* array; + int sz = strlen(key); + + array = (unsigned char*)ellipse; + for (unsigned int i = 0; i < sizeof(ellipseTags) / sizeof(ellipseTags[0]); i++) { + if (ellipseTags[i].sz - 1 == sz && !strncmp(ellipseTags[i].tag, key, sz)) { + *((float*)(array + ellipseTags[i].offset)) = _toFloat(loader->svgParse, value, ellipseTags[i].type); + return true; + } + } + + if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createEllipseNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Ellipse); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseEllipseNode, loader); + return loader->svgParse->node; +} + + +static bool _attrParsePolygonPoints(const char* str, SvgPolygonNode* polygon) +{ + float num_x, num_y; + while (_parseNumber(&str, nullptr, &num_x) && _parseNumber(&str, nullptr, &num_y)) { + polygon->pts.push(num_x); + polygon->pts.push(num_y); + } + return true; +} + + +/* parse the attributes for a polygon element. + * https://www.w3.org/TR/SVG/shapes.html#PolylineElement + */ +static bool _attrParsePolygonNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgPolygonNode* polygon = nullptr; + + if (node->type == SvgNodeType::Polygon) polygon = &(node->node.polygon); + else polygon = &(node->node.polyline); + + if (STR_AS(key, "points")) { + return _attrParsePolygonPoints(value, polygon); + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createPolygonNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Polygon); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParsePolygonNode, loader); + return loader->svgParse->node; +} + + +static SvgNode* _createPolylineNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Polyline); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParsePolygonNode, loader); + return loader->svgParse->node; +} + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} rectTags[] = { + {"x", SvgParserLengthType::Horizontal, sizeof("x"), offsetof(SvgRectNode, x)}, + {"y", SvgParserLengthType::Vertical, sizeof("y"), offsetof(SvgRectNode, y)}, + {"width", SvgParserLengthType::Horizontal, sizeof("width"), offsetof(SvgRectNode, w)}, + {"height", SvgParserLengthType::Vertical, sizeof("height"), offsetof(SvgRectNode, h)}, + {"rx", SvgParserLengthType::Horizontal, sizeof("rx"), offsetof(SvgRectNode, rx)}, + {"ry", SvgParserLengthType::Vertical, sizeof("ry"), offsetof(SvgRectNode, ry)} +}; + + +/* parse the attributes for a rect element. + * https://www.w3.org/TR/SVG/shapes.html#RectElement + */ +static bool _attrParseRectNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgRectNode* rect = &(node->node.rect); + unsigned char* array; + bool ret = true; + int sz = strlen(key); + + array = (unsigned char*)rect; + for (unsigned int i = 0; i < sizeof(rectTags) / sizeof(rectTags[0]); i++) { + if (rectTags[i].sz - 1 == sz && !strncmp(rectTags[i].tag, key, sz)) { + *((float*)(array + rectTags[i].offset)) = _toFloat(loader->svgParse, value, rectTags[i].type); + + //Case if only rx or ry is declared + if (!strncmp(rectTags[i].tag, "rx", sz)) rect->hasRx = true; + if (!strncmp(rectTags[i].tag, "ry", sz)) rect->hasRy = true; + + if ((rect->rx >= FLOAT_EPSILON) && (rect->ry < FLOAT_EPSILON) && rect->hasRx && !rect->hasRy) rect->ry = rect->rx; + if ((rect->ry >= FLOAT_EPSILON) && (rect->rx < FLOAT_EPSILON) && !rect->hasRx && rect->hasRy) rect->rx = rect->ry; + return ret; + } + } + + if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "style")) { + ret = xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else { + ret = _parseStyleAttr(loader, key, value, false); + } + + return ret; +} + + +static SvgNode* _createRectNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Rect); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseRectNode, loader); + return loader->svgParse->node; +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} lineTags[] = { + {"x1", SvgParserLengthType::Horizontal, sizeof("x1"), offsetof(SvgLineNode, x1)}, + {"y1", SvgParserLengthType::Vertical, sizeof("y1"), offsetof(SvgLineNode, y1)}, + {"x2", SvgParserLengthType::Horizontal, sizeof("x2"), offsetof(SvgLineNode, x2)}, + {"y2", SvgParserLengthType::Vertical, sizeof("y2"), offsetof(SvgLineNode, y2)} +}; + + +/* parse the attributes for a line element. + * https://www.w3.org/TR/SVG/shapes.html#LineElement + */ +static bool _attrParseLineNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgLineNode* line = &(node->node.line); + unsigned char* array; + int sz = strlen(key); + + array = (unsigned char*)line; + for (unsigned int i = 0; i < sizeof(lineTags) / sizeof(lineTags[0]); i++) { + if (lineTags[i].sz - 1 == sz && !strncmp(lineTags[i].tag, key, sz)) { + *((float*)(array + lineTags[i].offset)) = _toFloat(loader->svgParse, value, lineTags[i].type); + return true; + } + } + + if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createLineNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Line); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseLineNode, loader); + return loader->svgParse->node; +} + + +static char* _idFromHref(const char* href) +{ + href = svgUtilSkipWhiteSpace(href, nullptr); + if ((*href) == '#') href++; + return duplicate(href); +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} imageTags[] = { + {"x", SvgParserLengthType::Horizontal, sizeof("x"), offsetof(SvgRectNode, x)}, + {"y", SvgParserLengthType::Vertical, sizeof("y"), offsetof(SvgRectNode, y)}, + {"width", SvgParserLengthType::Horizontal, sizeof("width"), offsetof(SvgRectNode, w)}, + {"height", SvgParserLengthType::Vertical, sizeof("height"), offsetof(SvgRectNode, h)}, +}; + + +/* parse the attributes for a image element. + * https://www.w3.org/TR/SVG/embedded.html#ImageElement + */ +static bool _attrParseImageNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgImageNode* image = &(node->node.image); + unsigned char* array; + int sz = strlen(key); + + array = (unsigned char*)image; + for (unsigned int i = 0; i < sizeof(imageTags) / sizeof(imageTags[0]); i++) { + if (imageTags[i].sz - 1 == sz && !strncmp(imageTags[i].tag, key, sz)) { + *((float*)(array + imageTags[i].offset)) = _toFloat(loader->svgParse, value, imageTags[i].type); + return true; + } + } + + if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) { + if (value) tvg::free(image->href); + image->href = _idFromHref(value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else if (STR_AS(key, "transform")) { + node->transform = _parseTransformationMatrix(value); + } else { + return _parseStyleAttr(loader, key, value); + } + return true; +} + + +static SvgNode* _createImageNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Image); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseImageNode, loader); + return loader->svgParse->node; +} + + +static char* _unquote(const char* str) +{ + auto len = str ? strlen(str) : 0; + if (len >= 2 && str[0] == '\'' && str[len - 1] == '\'') return duplicate(str + 1, len - 2); + return strdup(str); +} + + +static bool _attrParseFontFace(void* data, const char* key, const char* value) +{ + if (!key || !value) return false; + + key = svgUtilSkipWhiteSpace(key, nullptr); + value = svgUtilSkipWhiteSpace(value, nullptr); + + auto loader = (SvgLoaderData*)data; + auto& font = loader->fonts.last(); + + if (STR_AS(key, "font-family")) { + if (font.name) tvg::free(font.name); + font.name = _unquote(value); + } else if (STR_AS(key, "src")) { + font.srcLen = _srcFromUrl(value, font.src); + } + + return true; +} + + +static void _createFontFace(SvgLoaderData* loader, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->fonts.push(FontFace()); + func(buf, bufLength, _attrParseFontFace, loader); +} + + +static SvgNode* _getDefsNode(SvgNode* node) +{ + if (!node) return nullptr; + + while (node->parent) { + node = node->parent; + } + + if (node->type == SvgNodeType::Doc) return node->node.doc.defs; + if (node->type == SvgNodeType::Defs) return node; + + return nullptr; +} + + +static SvgNode* _findNodeById(SvgNode *node, const char* id) +{ + if (!node) return nullptr; + + if (node->id && STR_AS(node->id, id)) return node; + + if (node->child.count > 0) { + ARRAY_FOREACH(p, node->child) { + if (auto result = _findNodeById(*p, id)) return result; + } + } + return nullptr; +} + + +static SvgNode* _findParentById(SvgNode* node, char* id, SvgNode* doc) +{ + SvgNode *parent = node->parent; + while (parent != nullptr && parent != doc) { + if (parent->id && STR_AS(parent->id, id)) { + return parent; + } + parent = parent->parent; + } + return nullptr; +} + + +static bool _checkPostponed(SvgNode* node, SvgNode* cloneNode, int depth) +{ + if (node == cloneNode) return true; + + if (depth == 512) { + TVGERR("SVG", "Infinite recursive call - stopped after %d calls! Svg file may be incorrectly formatted.", depth); + return false; + } + + ARRAY_FOREACH(p, node->child) { + if (_checkPostponed(*p, cloneNode, depth + 1)) return true; + } + + return false; +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} useTags[] = { + {"x", SvgParserLengthType::Horizontal, sizeof("x"), offsetof(SvgUseNode, x)}, + {"y", SvgParserLengthType::Vertical, sizeof("y"), offsetof(SvgUseNode, y)}, + {"width", SvgParserLengthType::Horizontal, sizeof("width"), offsetof(SvgUseNode, w)}, + {"height", SvgParserLengthType::Vertical, sizeof("height"), offsetof(SvgUseNode, h)} +}; + + +static void _cloneNode(SvgNode* from, SvgNode* parent, int depth); +static bool _attrParseUseNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode *defs, *nodeFrom, *node = loader->svgParse->node; + char* id; + + SvgUseNode* use = &(node->node.use); + int sz = strlen(key); + unsigned char* array = (unsigned char*)use; + for (unsigned int i = 0; i < sizeof(useTags) / sizeof(useTags[0]); i++) { + if (useTags[i].sz - 1 == sz && !strncmp(useTags[i].tag, key, sz)) { + *((float*)(array + useTags[i].offset)) = _toFloat(loader->svgParse, value, useTags[i].type); + + if (useTags[i].offset == offsetof(SvgUseNode, w)) use->isWidthSet = true; + else if (useTags[i].offset == offsetof(SvgUseNode, h)) use->isHeightSet = true; + + return true; + } + } + + if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) { + id = _idFromHref(value); + defs = _getDefsNode(node); + nodeFrom = _findNodeById(defs, id); + if (nodeFrom) { + if (!_findParentById(node, id, loader->doc)) { + //Check if none of nodeFrom's children are in the cloneNodes list + auto postpone = false; + INLIST_FOREACH(loader->cloneNodes, pair) { + if (_checkPostponed(nodeFrom, pair->node, 1)) { + postpone = true; + loader->cloneNodes.back(new(tvg::malloc(sizeof(SvgNodeIdPair))) SvgNodeIdPair(node, id)); + break; + } + } + //None of the children of nodeFrom are on the cloneNodes list, so it can be cloned immediately + if (!postpone) { + _cloneNode(nodeFrom, node, 0); + if (nodeFrom->type == SvgNodeType::Symbol) use->symbol = nodeFrom; + tvg::free(id); + } + } else { + TVGLOG("SVG", "%s is ancestor element. This reference is invalid.", id); + tvg::free(id); + } + } else { + //some svg export software include element at the end of the file + //if so the 'from' element won't be found now and we have to repeat finding + //after the whole file is parsed + loader->cloneNodes.back(new(tvg::malloc(sizeof(SvgNodeIdPair))) SvgNodeIdPair(node, id)); + } + } else { + return _attrParseGNode(data, key, value); + } + return true; +} + + +static SvgNode* _createUseNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Use); + + if (!loader->svgParse->node) return nullptr; + + func(buf, bufLength, _attrParseUseNode, loader); + return loader->svgParse->node; +} + + +static constexpr struct +{ + const char* tag; + SvgParserLengthType type; + int sz; + size_t offset; +} textTags[] = { + {"x", SvgParserLengthType::Horizontal, sizeof("x"), offsetof(SvgTextNode, x)}, + {"y", SvgParserLengthType::Vertical, sizeof("y"), offsetof(SvgTextNode, y)}, + {"font-size", SvgParserLengthType::Vertical, sizeof("font-size"), offsetof(SvgTextNode, fontSize)} +}; + + +static bool _attrParseTextNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgNode* node = loader->svgParse->node; + SvgTextNode* text = &(node->node.text); + + unsigned char* array; + int sz = strlen(key); + + array = (unsigned char*)text; + for (unsigned int i = 0; i < sizeof(textTags) / sizeof(textTags[0]); i++) { + if (textTags[i].sz - 1 == sz && !strncmp(textTags[i].tag, key, sz)) { + *((float*)(array + textTags[i].offset)) = _toFloat(loader->svgParse, value, textTags[i].type); + return true; + } + } + + if (STR_AS(key, "font-family")) { + if (value) { + tvg::free(text->fontFamily); + text->fontFamily = duplicate(value); + } + } else if (STR_AS(key, "style")) { + return xmlParseW3CAttribute(value, strlen(value), _parseStyleAttr, loader); + } else if (STR_AS(key, "clip-path")) { + _handleClipPathAttr(loader, node, value); + } else if (STR_AS(key, "mask")) { + _handleMaskAttr(loader, node, value); + } else if (STR_AS(key, "filter")) { + _handleFilterAttr(loader, node, value); + } else if (STR_AS(key, "id")) { + if (value) tvg::free(node->id); + node->id = _copyId(value); + } else if (STR_AS(key, "class")) { + _handleCssClassAttr(loader, node, value); + } else { + return _parseStyleAttr(loader, key, value, false); + } + return true; +} + + +static SvgNode* _createTextNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func) +{ + loader->svgParse->node = _createNode(parent, SvgNodeType::Text); + if (!loader->svgParse->node) return nullptr; + + //TODO: support the def font and size as used in a system? + loader->svgParse->node->node.text.fontSize = 10.0f; + + func(buf, bufLength, _attrParseTextNode, loader); + + return loader->svgParse->node; +} + + +static constexpr struct +{ + const char* tag; + int sz; + FactoryMethod tagHandler; +} graphicsTags[] = { + {"use", sizeof("use"), _createUseNode}, + {"circle", sizeof("circle"), _createCircleNode}, + {"ellipse", sizeof("ellipse"), _createEllipseNode}, + {"path", sizeof("path"), _createPathNode}, + {"polygon", sizeof("polygon"), _createPolygonNode}, + {"rect", sizeof("rect"), _createRectNode}, + {"polyline", sizeof("polyline"), _createPolylineNode}, + {"line", sizeof("line"), _createLineNode}, + {"image", sizeof("image"), _createImageNode}, + {"text", sizeof("text"), _createTextNode}, + {"feGaussianBlur", sizeof("feGaussianBlur"), _createGaussianBlurNode} +}; + + +static constexpr struct +{ + const char* tag; + int sz; + FactoryMethod tagHandler; +} groupTags[] = { + {"defs", sizeof("defs"), _createDefsNode}, + {"g", sizeof("g"), _createGNode}, + {"svg", sizeof("svg"), _createSvgNode}, + {"mask", sizeof("mask"), _createMaskNode}, + {"clipPath", sizeof("clipPath"), _createClipPathNode}, + {"style", sizeof("style"), _createCssStyleNode}, + {"symbol", sizeof("symbol"), _createSymbolNode}, + {"filter", sizeof("filter"), _createFilterNode} +}; + + +#define FIND_FACTORY(Short_Name, Tags_Array) \ + static FactoryMethod \ + _find##Short_Name##Factory(const char* name) \ + { \ + unsigned int i; \ + int sz = strlen(name); \ + \ + for (i = 0; i < sizeof(Tags_Array) / sizeof(Tags_Array[0]); i++) { \ + if (Tags_Array[i].sz - 1 == sz && !strncmp(Tags_Array[i].tag, name, sz)) { \ + return Tags_Array[i].tagHandler; \ + } \ + } \ + return nullptr; \ + } + +FIND_FACTORY(Group, groupTags) +FIND_FACTORY(Graphics, graphicsTags) + + +FillSpread _parseSpreadValue(const char* value) +{ + auto spread = FillSpread::Pad; + + if (STR_AS(value, "reflect")) { + spread = FillSpread::Reflect; + } else if (STR_AS(value, "repeat")) { + spread = FillSpread::Repeat; + } + + return spread; +} + + +static void _handleRadialCxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value) +{ + radial->cx = _gradientToFloat(loader->svgParse, value, radial->isCxPercentage); + if (!loader->svgParse->gradient.parsedFx) { + radial->fx = radial->cx; + radial->isFxPercentage = radial->isCxPercentage; + } +} + + +static void _handleRadialCyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value) +{ + radial->cy = _gradientToFloat(loader->svgParse, value, radial->isCyPercentage); + if (!loader->svgParse->gradient.parsedFy) { + radial->fy = radial->cy; + radial->isFyPercentage = radial->isCyPercentage; + } +} + + +static void _handleRadialFxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value) +{ + radial->fx = _gradientToFloat(loader->svgParse, value, radial->isFxPercentage); + loader->svgParse->gradient.parsedFx = true; +} + + +static void _handleRadialFyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value) +{ + radial->fy = _gradientToFloat(loader->svgParse, value, radial->isFyPercentage); + loader->svgParse->gradient.parsedFy = true; +} + + +static void _handleRadialFrAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value) +{ + radial->fr = _gradientToFloat(loader->svgParse, value, radial->isFrPercentage); +} + + +static void _handleRadialRAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value) +{ + radial->r = _gradientToFloat(loader->svgParse, value, radial->isRPercentage); +} + + +static void _recalcRadialCxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (userSpace && !radial->isCxPercentage) radial->cx = radial->cx / loader->svgParse->global.w; +} + + +static void _recalcRadialCyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (userSpace && !radial->isCyPercentage) radial->cy = radial->cy / loader->svgParse->global.h; +} + + +static void _recalcRadialFxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (userSpace && !radial->isFxPercentage) radial->fx = radial->fx / loader->svgParse->global.w; +} + + +static void _recalcRadialFyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (userSpace && !radial->isFyPercentage) radial->fy = radial->fy / loader->svgParse->global.h; +} + + +static void _recalcRadialFrAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + // scaling factor based on the Units paragraph from : https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html + if (userSpace && !radial->isFrPercentage) radial->fr = radial->fr / (sqrtf(powf(loader->svgParse->global.h, 2) + powf(loader->svgParse->global.w, 2)) / sqrtf(2.0)); +} + + +static void _recalcRadialRAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + // scaling factor based on the Units paragraph from : https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html + if (userSpace && !radial->isRPercentage) radial->r = radial->r / (sqrtf(powf(loader->svgParse->global.h, 2) + powf(loader->svgParse->global.w, 2)) / sqrtf(2.0)); +} + + +static void _recalcInheritedRadialCxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (!radial->isCxPercentage) { + if (userSpace) radial->cx /= loader->svgParse->global.w; + else radial->cx *= loader->svgParse->global.w; + } +} + + +static void _recalcInheritedRadialCyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (!radial->isCyPercentage) { + if (userSpace) radial->cy /= loader->svgParse->global.h; + else radial->cy *= loader->svgParse->global.h; + } +} + + +static void _recalcInheritedRadialFxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (!radial->isFxPercentage) { + if (userSpace) radial->fx /= loader->svgParse->global.w; + else radial->fx *= loader->svgParse->global.w; + } +} + + +static void _recalcInheritedRadialFyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (!radial->isFyPercentage) { + if (userSpace) radial->fy /= loader->svgParse->global.h; + else radial->fy *= loader->svgParse->global.h; + } +} + + +static void _recalcInheritedRadialFrAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (!radial->isFrPercentage) { + if (userSpace) radial->fr /= sqrtf(powf(loader->svgParse->global.h, 2) + powf(loader->svgParse->global.w, 2)) / sqrtf(2.0); + else radial->fr *= sqrtf(powf(loader->svgParse->global.h, 2) + powf(loader->svgParse->global.w, 2)) / sqrtf(2.0); + } +} + + +static void _recalcInheritedRadialRAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace) +{ + if (!radial->isRPercentage) { + if (userSpace) radial->r /= sqrtf(powf(loader->svgParse->global.h, 2) + powf(loader->svgParse->global.w, 2)) / sqrtf(2.0); + else radial->r *= sqrtf(powf(loader->svgParse->global.h, 2) + powf(loader->svgParse->global.w, 2)) / sqrtf(2.0); + } +} + + +static void _inheritRadialCxAttr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->radial->cx = from->radial->cx; + to->radial->isCxPercentage = from->radial->isCxPercentage; + to->flags = (to->flags | SvgGradientFlags::Cx); +} + + +static void _inheritRadialCyAttr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->radial->cy = from->radial->cy; + to->radial->isCyPercentage = from->radial->isCyPercentage; + to->flags = (to->flags | SvgGradientFlags::Cy); +} + + +static void _inheritRadialFxAttr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->radial->fx = from->radial->fx; + to->radial->isFxPercentage = from->radial->isFxPercentage; + to->flags = (to->flags | SvgGradientFlags::Fx); +} + + +static void _inheritRadialFyAttr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->radial->fy = from->radial->fy; + to->radial->isFyPercentage = from->radial->isFyPercentage; + to->flags = (to->flags | SvgGradientFlags::Fy); +} + + +static void _inheritRadialFrAttr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->radial->fr = from->radial->fr; + to->radial->isFrPercentage = from->radial->isFrPercentage; + to->flags = (to->flags | SvgGradientFlags::Fr); +} + + +static void _inheritRadialRAttr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->radial->r = from->radial->r; + to->radial->isRPercentage = from->radial->isRPercentage; + to->flags = (to->flags | SvgGradientFlags::R); +} + + +typedef void (*radialMethod)(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value); +typedef void (*radialInheritMethod)(SvgStyleGradient* to, SvgStyleGradient* from); +typedef void (*radialMethodRecalc)(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace); + + +#define RADIAL_DEF(Name, Name1, Flag) \ + { \ +#Name, sizeof(#Name), _handleRadial##Name1##Attr, _inheritRadial##Name1##Attr, _recalcRadial##Name1##Attr, _recalcInheritedRadial##Name1##Attr, Flag \ + } + + +static constexpr struct +{ + const char* tag; + int sz; + radialMethod tagHandler; + radialInheritMethod tagInheritHandler; + radialMethodRecalc tagRecalc; + radialMethodRecalc tagInheritedRecalc; + SvgGradientFlags flag; +} radialTags[] = { + RADIAL_DEF(cx, Cx, SvgGradientFlags::Cx), + RADIAL_DEF(cy, Cy, SvgGradientFlags::Cy), + RADIAL_DEF(fx, Fx, SvgGradientFlags::Fx), + RADIAL_DEF(fy, Fy, SvgGradientFlags::Fy), + RADIAL_DEF(r, R, SvgGradientFlags::R), + RADIAL_DEF(fr, Fr, SvgGradientFlags::Fr) +}; + + +static bool _attrParseRadialGradientNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgStyleGradient* grad = loader->svgParse->styleGrad; + SvgRadialGradient* radial = grad->radial; + int sz = strlen(key); + + for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) { + if (radialTags[i].sz - 1 == sz && !strncmp(radialTags[i].tag, key, sz)) { + radialTags[i].tagHandler(loader, radial, value); + grad->flags = (grad->flags | radialTags[i].flag); + return true; + } + } + + if (STR_AS(key, "id")) { + if (value) tvg::free(grad->id); + grad->id = _copyId(value); + } else if (STR_AS(key, "spreadMethod")) { + grad->spread = _parseSpreadValue(value); + grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod); + } else if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) { + if (value) tvg::free(grad->ref); + grad->ref = _idFromHref(value); + } else if (STR_AS(key, "gradientUnits")) { + if (STR_AS(value, "userSpaceOnUse")) grad->userSpace = true; + grad->flags = (grad->flags | SvgGradientFlags::GradientUnits); + } else if (STR_AS(key, "gradientTransform")) { + grad->transform = _parseTransformationMatrix(value); + } else { + return false; + } + + return true; +} + + +static SvgStyleGradient* _createRadialGradient(SvgLoaderData* loader, const char* buf, unsigned bufLength) +{ + auto grad = tvg::calloc(1, sizeof(SvgStyleGradient)); + loader->svgParse->styleGrad = grad; + + grad->flags = SvgGradientFlags::None; + grad->type = SvgGradientType::Radial; + grad->radial = tvg::calloc(1, sizeof(SvgRadialGradient)); + if (!grad->radial) { + grad->clear(); + tvg::free(grad); + return nullptr; + } + /** + * Default values of gradient transformed into global percentage + */ + grad->radial->cx = 0.5f; + grad->radial->cy = 0.5f; + grad->radial->fx = 0.5f; + grad->radial->fy = 0.5f; + grad->radial->r = 0.5f; + grad->radial->isCxPercentage = true; + grad->radial->isCyPercentage = true; + grad->radial->isFxPercentage = true; + grad->radial->isFyPercentage = true; + grad->radial->isRPercentage = true; + grad->radial->isFrPercentage = true; + + loader->svgParse->gradient.parsedFx = false; + loader->svgParse->gradient.parsedFy = false; + xmlParseAttributes(buf, bufLength, + _attrParseRadialGradientNode, loader); + + for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) { + radialTags[i].tagRecalc(loader, grad->radial, grad->userSpace); + } + + return loader->svgParse->styleGrad; +} + + +static SvgColor* _findLatestColor(const SvgLoaderData* loader) +{ + auto parent = loader->stack.count > 0 ? loader->stack.last() : loader->doc; + + while (parent != nullptr) { + if (parent->style->curColorSet) return &parent->style->color; + parent = parent->parent; + } + return nullptr; +} + + +static bool _attrParseStopsStyle(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + auto stop = &loader->svgParse->gradStop; + + if (STR_AS(key, "stop-opacity")) { + stop->a = _toOpacity(value); + loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopOpacity); + } else if (STR_AS(key, "stop-color")) { + if (STR_AS(value, "currentColor")) { + if (auto latestColor = _findLatestColor(loader)) { + stop->r = latestColor->r; + stop->g = latestColor->g; + stop->b = latestColor->b; + } + } else if (_toColor(value, stop->r, stop->g, stop->b, nullptr)) { + loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopColor); + } + } else { + return false; + } + + return true; +} + + +static bool _attrParseStops(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + auto stop = &loader->svgParse->gradStop; + + if (STR_AS(key, "offset")) { + stop->offset = _toOffset(value); + } else if (STR_AS(key, "stop-opacity")) { + if (!(loader->svgParse->flags & SvgStopStyleFlags::StopOpacity)) { + stop->a = _toOpacity(value); + } + } else if (STR_AS(key, "stop-color")) { + if (STR_AS(value, "currentColor")) { + if (auto latestColor = _findLatestColor(loader)) { + stop->r = latestColor->r; + stop->g = latestColor->g; + stop->b = latestColor->b; + } + } else if (!(loader->svgParse->flags & SvgStopStyleFlags::StopColor)) { + _toColor(value, stop->r, stop->g, stop->b, nullptr); + } + } else if (STR_AS(key, "style")) { + xmlParseW3CAttribute(value, strlen(value), _attrParseStopsStyle, data); + } else { + return false; + } + + return true; +} + + +static void _handleLinearX1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value) +{ + linear->x1 = _gradientToFloat(loader->svgParse, value, linear->isX1Percentage); +} + + +static void _handleLinearY1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value) +{ + linear->y1 = _gradientToFloat(loader->svgParse, value, linear->isY1Percentage); +} + + +static void _handleLinearX2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value) +{ + linear->x2 = _gradientToFloat(loader->svgParse, value, linear->isX2Percentage); +} + + +static void _handleLinearY2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value) +{ + linear->y2 = _gradientToFloat(loader->svgParse, value, linear->isY2Percentage); +} + + +static void _recalcLinearX1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (userSpace && !linear->isX1Percentage) linear->x1 = linear->x1 / loader->svgParse->global.w; +} + + +static void _recalcLinearY1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (userSpace && !linear->isY1Percentage) linear->y1 = linear->y1 / loader->svgParse->global.h; +} + + +static void _recalcLinearX2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (userSpace && !linear->isX2Percentage) linear->x2 = linear->x2 / loader->svgParse->global.w; +} + + +static void _recalcLinearY2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (userSpace && !linear->isY2Percentage) linear->y2 = linear->y2 / loader->svgParse->global.h; +} + + +static void _recalcInheritedLinearX1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (!linear->isX1Percentage) { + if (userSpace) linear->x1 /= loader->svgParse->global.w; + else linear->x1 *= loader->svgParse->global.w; + } +} + + +static void _recalcInheritedLinearX2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (!linear->isX2Percentage) { + if (userSpace) linear->x2 /= loader->svgParse->global.w; + else linear->x2 *= loader->svgParse->global.w; + } +} + + +static void _recalcInheritedLinearY1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (!linear->isY1Percentage) { + if (userSpace) linear->y1 /= loader->svgParse->global.h; + else linear->y1 *= loader->svgParse->global.h; + } +} + + +static void _recalcInheritedLinearY2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace) +{ + if (!linear->isY2Percentage) { + if (userSpace) linear->y2 /= loader->svgParse->global.h; + else linear->y2 *= loader->svgParse->global.h; + } +} + + +static void _inheritLinearX1Attr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->linear->x1 = from->linear->x1; + to->linear->isX1Percentage = from->linear->isX1Percentage; + to->flags = (to->flags | SvgGradientFlags::X1); +} + + +static void _inheritLinearX2Attr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->linear->x2 = from->linear->x2; + to->linear->isX2Percentage = from->linear->isX2Percentage; + to->flags = (to->flags | SvgGradientFlags::X2); +} + + +static void _inheritLinearY1Attr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->linear->y1 = from->linear->y1; + to->linear->isY1Percentage = from->linear->isY1Percentage; + to->flags = (to->flags | SvgGradientFlags::Y1); +} + + +static void _inheritLinearY2Attr(SvgStyleGradient* to, SvgStyleGradient* from) +{ + to->linear->y2 = from->linear->y2; + to->linear->isY2Percentage = from->linear->isY2Percentage; + to->flags = (to->flags | SvgGradientFlags::Y2); +} + + +typedef void (*Linear_Method)(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value); +typedef void (*Linear_Inherit_Method)(SvgStyleGradient* to, SvgStyleGradient* from); +typedef void (*Linear_Method_Recalc)(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace); + + +#define LINEAR_DEF(Name, Name1, Flag) \ + { \ +#Name, sizeof(#Name), _handleLinear##Name1##Attr, _inheritLinear##Name1##Attr, _recalcLinear##Name1##Attr, _recalcInheritedLinear##Name1##Attr, Flag \ + } + + +static constexpr struct +{ + const char* tag; + int sz; + Linear_Method tagHandler; + Linear_Inherit_Method tagInheritHandler; + Linear_Method_Recalc tagRecalc; + Linear_Method_Recalc tagInheritedRecalc; + SvgGradientFlags flag; +} linear_tags[] = { + LINEAR_DEF(x1, X1, SvgGradientFlags::X1), + LINEAR_DEF(y1, Y1, SvgGradientFlags::Y1), + LINEAR_DEF(x2, X2, SvgGradientFlags::X2), + LINEAR_DEF(y2, Y2, SvgGradientFlags::Y2) +}; + + +static bool _attrParseLinearGradientNode(void* data, const char* key, const char* value) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + SvgStyleGradient* grad = loader->svgParse->styleGrad; + SvgLinearGradient* linear = grad->linear; + int sz = strlen(key); + + for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) { + if (linear_tags[i].sz - 1 == sz && !strncmp(linear_tags[i].tag, key, sz)) { + linear_tags[i].tagHandler(loader, linear, value); + grad->flags = (grad->flags | linear_tags[i].flag); + return true; + } + } + + if (STR_AS(key, "id")) { + if (value) tvg::free(grad->id); + grad->id = _copyId(value); + } else if (STR_AS(key, "spreadMethod")) { + grad->spread = _parseSpreadValue(value); + grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod); + } else if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) { + if (value) tvg::free(grad->ref); + grad->ref = _idFromHref(value); + } else if (STR_AS(key, "gradientUnits")) { + if (STR_AS(value, "userSpaceOnUse")) grad->userSpace = true; + grad->flags = (grad->flags | SvgGradientFlags::GradientUnits); + } else if (STR_AS(key, "gradientTransform")) { + grad->transform = _parseTransformationMatrix(value); + } else { + return false; + } + + return true; +} + + +static SvgStyleGradient* _createLinearGradient(SvgLoaderData* loader, const char* buf, unsigned bufLength) +{ + auto grad = tvg::calloc(1, sizeof(SvgStyleGradient)); + loader->svgParse->styleGrad = grad; + + grad->flags = SvgGradientFlags::None; + grad->type = SvgGradientType::Linear; + grad->linear = tvg::calloc(1, sizeof(SvgLinearGradient)); + if (!grad->linear) { + grad->clear(); + tvg::free(grad); + return nullptr; + } + /** + * Default value of x2 is 100% - transformed to the global percentage + */ + grad->linear->x2 = 1.0f; + grad->linear->isX2Percentage = true; + + xmlParseAttributes(buf, bufLength, _attrParseLinearGradientNode, loader); + + for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) { + linear_tags[i].tagRecalc(loader, grad->linear, grad->userSpace); + } + + return loader->svgParse->styleGrad; +} + + +#define GRADIENT_DEF(Name, Name1) \ + { \ +#Name, sizeof(#Name), _create##Name1 \ + } + + +/** + * In the case when the gradients lengths are given as numbers (not percentages) + * in the current user coordinate system, they are recalculated into percentages + * related to the canvas width and height. + */ +static constexpr struct +{ + const char* tag; + int sz; + GradientFactoryMethod tagHandler; +} gradientTags[] = { + GRADIENT_DEF(linearGradient, LinearGradient), + GRADIENT_DEF(radialGradient, RadialGradient) +}; + + +static GradientFactoryMethod _findGradientFactory(const char* name) +{ + int sz = strlen(name); + + for (unsigned int i = 0; i < sizeof(gradientTags) / sizeof(gradientTags[0]); i++) { + if (gradientTags[i].sz - 1 == sz && !strncmp(gradientTags[i].tag, name, sz)) { + return gradientTags[i].tagHandler; + } + } + return nullptr; +} + + +static void _cloneGradStops(Array& dst, const Array& src) +{ + ARRAY_FOREACH(p, src) { + dst.push(*p); + } +} + + +static void _inheritGradient(SvgLoaderData* loader, SvgStyleGradient* to, SvgStyleGradient* from) +{ + if (!to || !from) return; + + if (!(to->flags & SvgGradientFlags::SpreadMethod) && (from->flags & SvgGradientFlags::SpreadMethod)) { + to->spread = from->spread; + to->flags = (to->flags | SvgGradientFlags::SpreadMethod); + } + bool gradUnitSet = (to->flags & SvgGradientFlags::GradientUnits); + if (!(to->flags & SvgGradientFlags::GradientUnits) && (from->flags & SvgGradientFlags::GradientUnits)) { + to->userSpace = from->userSpace; + to->flags = (to->flags | SvgGradientFlags::GradientUnits); + } + + if (!to->transform && from->transform) { + to->transform = tvg::malloc(sizeof(Matrix)); + if (to->transform) *to->transform = *from->transform; + } + + if (to->type == SvgGradientType::Linear) { + for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) { + bool coordSet = to->flags & linear_tags[i].flag; + if (!(to->flags & linear_tags[i].flag) && (from->flags & linear_tags[i].flag)) { + linear_tags[i].tagInheritHandler(to, from); + } + + //GradUnits not set directly, coord set + if (!gradUnitSet && coordSet) { + linear_tags[i].tagRecalc(loader, to->linear, to->userSpace); + } + //GradUnits set, coord not set directly + if (to->userSpace == from->userSpace) continue; + if (gradUnitSet && !coordSet) { + linear_tags[i].tagInheritedRecalc(loader, to->linear, to->userSpace); + } + } + } else if (to->type == SvgGradientType::Radial) { + for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) { + bool coordSet = (to->flags & radialTags[i].flag); + if (!(to->flags & radialTags[i].flag) && (from->flags & radialTags[i].flag)) { + radialTags[i].tagInheritHandler(to, from); + } + + //GradUnits not set directly, coord set + if (!gradUnitSet && coordSet) { + radialTags[i].tagRecalc(loader, to->radial, to->userSpace); + //If fx and fy are not set, set cx and cy. + if (STR_AS(radialTags[i].tag, "cx") && !(to->flags & SvgGradientFlags::Fx)) to->radial->fx = to->radial->cx; + if (STR_AS(radialTags[i].tag, "cy") && !(to->flags & SvgGradientFlags::Fy)) to->radial->fy = to->radial->cy; + } + //GradUnits set, coord not set directly + if (to->userSpace == from->userSpace) continue; + if (gradUnitSet && !coordSet) { + //If fx and fx are not set, do not call recalc. + if (STR_AS(radialTags[i].tag, "fx") && !(to->flags & SvgGradientFlags::Fx)) continue; + if (STR_AS(radialTags[i].tag, "fy") && !(to->flags & SvgGradientFlags::Fy)) continue; + radialTags[i].tagInheritedRecalc(loader, to->radial, to->userSpace); + } + } + } + + if (to->stops.empty()) _cloneGradStops(to->stops, from->stops); +} + + +static SvgStyleGradient* _cloneGradient(SvgStyleGradient* from) +{ + if (!from) return nullptr; + + auto grad = tvg::calloc(1, sizeof(SvgStyleGradient)); + if (!grad) return nullptr; + + grad->type = from->type; + grad->id = from->id ? _copyId(from->id) : nullptr; + grad->ref = from->ref ? _copyId(from->ref) : nullptr; + grad->spread = from->spread; + grad->userSpace = from->userSpace; + grad->flags = from->flags; + + if (from->transform) { + grad->transform = tvg::calloc(1, sizeof(Matrix)); + if (grad->transform) *grad->transform = *from->transform; + } + + if (grad->type == SvgGradientType::Linear) { + grad->linear = tvg::calloc(1, sizeof(SvgLinearGradient)); + if (!grad->linear) goto error_grad_alloc; + memcpy(grad->linear, from->linear, sizeof(SvgLinearGradient)); + } else if (grad->type == SvgGradientType::Radial) { + grad->radial = tvg::calloc(1, sizeof(SvgRadialGradient)); + if (!grad->radial) goto error_grad_alloc; + memcpy(grad->radial, from->radial, sizeof(SvgRadialGradient)); + } + + _cloneGradStops(grad->stops, from->stops); + + return grad; + + error_grad_alloc: + if (grad) { + grad->clear(); + tvg::free(grad); + } + return nullptr; +} + + +static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* parent) +{ + if (parent == nullptr) return; + //Inherit the property of parent if not present in child. + if (!child->curColorSet) { + child->color = parent->color; + child->curColorSet = parent->curColorSet; + } + if (!(child->flags & SvgStyleFlags::PaintOrder)) { + child->paintOrder = parent->paintOrder; + } + //Fill + if (!(child->fill.flags & SvgFillFlags::Paint)) { + child->fill.paint.color = parent->fill.paint.color; + child->fill.paint.none = parent->fill.paint.none; + child->fill.paint.curColor = parent->fill.paint.curColor; + if (parent->fill.paint.url) { + tvg::free(child->fill.paint.url); + child->fill.paint.url = _copyId(parent->fill.paint.url); + } + } + if (!(child->fill.flags & SvgFillFlags::Opacity)) { + child->fill.opacity = parent->fill.opacity; + } + if (!(child->fill.flags & SvgFillFlags::FillRule)) { + child->fill.fillRule = parent->fill.fillRule; + } + //Stroke + if (!(child->stroke.flags & SvgStrokeFlags::Paint)) { + child->stroke.paint.color = parent->stroke.paint.color; + child->stroke.paint.none = parent->stroke.paint.none; + child->stroke.paint.curColor = parent->stroke.paint.curColor; + if (parent->stroke.paint.url) { + tvg::free(child->stroke.paint.url); + child->stroke.paint.url = _copyId(parent->stroke.paint.url); + } + } + if (!(child->stroke.flags & SvgStrokeFlags::Opacity)) { + child->stroke.opacity = parent->stroke.opacity; + } + if (!(child->stroke.flags & SvgStrokeFlags::Width)) { + child->stroke.width = parent->stroke.width; + } + if (!(child->stroke.flags & SvgStrokeFlags::Dash)) { + if (parent->stroke.dash.array.count > 0) { + child->stroke.dash.array.clear(); + child->stroke.dash.array.reserve(parent->stroke.dash.array.count); + ARRAY_FOREACH(p, parent->stroke.dash.array) { + child->stroke.dash.array.push(*p); + } + } + } + if (!(child->stroke.flags & SvgStrokeFlags::DashOffset)) { + child->stroke.dash.offset = parent->stroke.dash.offset; + } + if (!(child->stroke.flags & SvgStrokeFlags::Cap)) { + child->stroke.cap = parent->stroke.cap; + } + if (!(child->stroke.flags & SvgStrokeFlags::Join)) { + child->stroke.join = parent->stroke.join; + } + if (!(child->stroke.flags & SvgStrokeFlags::Miterlimit)) { + child->stroke.miterlimit = parent->stroke.miterlimit; + } +} + + +static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from) +{ + if (from == nullptr) return; + //Copy the properties of 'from' only if they were explicitly set (not the default ones). + if (from->curColorSet) { + to->color = from->color; + to->curColorSet = true; + } + if (from->flags & SvgStyleFlags::Opacity) { + to->opacity = from->opacity; + } + if (from->flags & SvgStyleFlags::PaintOrder) { + to->paintOrder = from->paintOrder; + } + if (from->flags & SvgStyleFlags::Display) { + to->display = from->display; + } + //Fill + to->fill.flags = (to->fill.flags | from->fill.flags); + if (from->fill.flags & SvgFillFlags::Paint) { + to->fill.paint.color = from->fill.paint.color; + to->fill.paint.none = from->fill.paint.none; + to->fill.paint.curColor = from->fill.paint.curColor; + if (from->fill.paint.url) { + tvg::free(to->fill.paint.url); + to->fill.paint.url = _copyId(from->fill.paint.url); + } + } + if (from->fill.flags & SvgFillFlags::Opacity) { + to->fill.opacity = from->fill.opacity; + } + if (from->fill.flags & SvgFillFlags::FillRule) { + to->fill.fillRule = from->fill.fillRule; + } + //Stroke + to->stroke.flags = (to->stroke.flags | from->stroke.flags); + if (from->stroke.flags & SvgStrokeFlags::Paint) { + to->stroke.paint.color = from->stroke.paint.color; + to->stroke.paint.none = from->stroke.paint.none; + to->stroke.paint.curColor = from->stroke.paint.curColor; + if (from->stroke.paint.url) { + tvg::free(to->stroke.paint.url); + to->stroke.paint.url = _copyId(from->stroke.paint.url); + } + } + if (from->stroke.flags & SvgStrokeFlags::Opacity) { + to->stroke.opacity = from->stroke.opacity; + } + if (from->stroke.flags & SvgStrokeFlags::Width) { + to->stroke.width = from->stroke.width; + } + if (from->stroke.flags & SvgStrokeFlags::Dash) { + if (from->stroke.dash.array.count > 0) { + to->stroke.dash.array.clear(); + to->stroke.dash.array.reserve(from->stroke.dash.array.count); + ARRAY_FOREACH(p, from->stroke.dash.array) { + to->stroke.dash.array.push(*p); + } + } + } + if (from->stroke.flags & SvgStrokeFlags::DashOffset) { + to->stroke.dash.offset = from->stroke.dash.offset; + } + if (from->stroke.flags & SvgStrokeFlags::Cap) { + to->stroke.cap = from->stroke.cap; + } + if (from->stroke.flags & SvgStrokeFlags::Join) { + to->stroke.join = from->stroke.join; + } + if (from->stroke.flags & SvgStrokeFlags::Miterlimit) { + to->stroke.miterlimit = from->stroke.miterlimit; + } +} + + +static void _copyAttr(SvgNode* to, const SvgNode* from) +{ + //Copy matrix attribute + if (from->transform) { + to->transform = tvg::malloc(sizeof(Matrix)); + if (to->transform) *to->transform = *from->transform; + } + //Copy style attribute + _styleCopy(to->style, from->style); + to->style->flags = (to->style->flags | from->style->flags); + if (from->style->clipPath.url) { + tvg::free(to->style->clipPath.url); + to->style->clipPath.url = duplicate(from->style->clipPath.url); + } + if (from->style->mask.url) { + tvg::free(to->style->mask.url); + to->style->mask.url = duplicate(from->style->mask.url); + } + if (from->style->filter.url) { + if (to->style->filter.url) tvg::free(to->style->filter.url); + to->style->filter.url = duplicate(from->style->filter.url); + } + + //Copy node attribute + switch (from->type) { + case SvgNodeType::Circle: { + to->node.circle = from->node.circle; + break; + } + case SvgNodeType::Ellipse: { + to->node.ellipse = from->node.ellipse; + break; + } + case SvgNodeType::Rect: { + to->node.rect = from->node.rect; + break; + } + case SvgNodeType::Line: { + to->node.line = from->node.line; + break; + } + case SvgNodeType::Path: { + if (from->node.path.path) { + tvg::free(to->node.path.path); + to->node.path.path = duplicate(from->node.path.path); + } + break; + } + case SvgNodeType::Polygon: { + if ((to->node.polygon.pts.count = from->node.polygon.pts.count)) { + to->node.polygon.pts = from->node.polygon.pts; + } + break; + } + case SvgNodeType::Polyline: { + if ((to->node.polyline.pts.count = from->node.polyline.pts.count)) { + to->node.polyline.pts = from->node.polyline.pts; + } + break; + } + case SvgNodeType::Image: { + to->node.image.x = from->node.image.x; + to->node.image.y = from->node.image.y; + to->node.image.w = from->node.image.w; + to->node.image.h = from->node.image.h; + if (from->node.image.href) { + tvg::free(to->node.image.href); + to->node.image.href = duplicate(from->node.image.href); + } + break; + } + case SvgNodeType::Use: { + to->node.use.x = from->node.use.x; + to->node.use.y = from->node.use.y; + to->node.use.w = from->node.use.w; + to->node.use.h = from->node.use.h; + to->node.use.isWidthSet = from->node.use.isWidthSet; + to->node.use.isHeightSet = from->node.use.isHeightSet; + to->node.use.symbol = from->node.use.symbol; + break; + } + case SvgNodeType::Text: { + to->node.text.x = from->node.text.x; + to->node.text.y = from->node.text.y; + to->node.text.fontSize = from->node.text.fontSize; + if (from->node.text.text) { + tvg::free(to->node.text.text); + to->node.text.text = duplicate(from->node.text.text); + } + if (from->node.text.fontFamily) { + tvg::free(to->node.text.fontFamily); + to->node.text.fontFamily = duplicate(from->node.text.fontFamily); + } + break; + } + default: { + break; + } + } +} + + +static void _cloneNode(SvgNode* from, SvgNode* parent, int depth) +{ + /* Exception handling: Prevent invalid SVG data input. + The size is the arbitrary value, we need an experimental size. */ + if (depth == 8192) { + TVGERR("SVG", "Infinite recursive call - stopped after %d calls! Svg file may be incorrectly formatted.", depth); + return; + } + + SvgNode* newNode; + if (!from || !parent || from == parent) return; + + newNode = _createNode(parent, from->type); + if (!newNode) return; + + _styleInherit(newNode->style, parent->style); + _copyAttr(newNode, from); + + ARRAY_FOREACH(p, from->child) { + _cloneNode(*p, newNode, depth + 1); + } +} + + +static void _clonePostponedNodes(Inlist* cloneNodes, SvgNode* doc) +{ + auto nodeIdPair = cloneNodes->front(); + while (nodeIdPair) { + if (!_findParentById(nodeIdPair->node, nodeIdPair->id, doc)) { + //Check if none of nodeFrom's children are in the cloneNodes list + auto postpone = false; + auto nodeFrom = _findNodeById(_getDefsNode(nodeIdPair->node), nodeIdPair->id); + if (!nodeFrom) nodeFrom = _findNodeById(doc, nodeIdPair->id); + if (nodeFrom) { + INLIST_FOREACH((*cloneNodes), pair) { + if (_checkPostponed(nodeFrom, pair->node, 1)) { + postpone = true; + cloneNodes->back(nodeIdPair); + break; + } + } + } + //Since none of the child nodes of nodeFrom are present in the cloneNodes list, it can be cloned immediately + if (!postpone) { + _cloneNode(nodeFrom, nodeIdPair->node, 0); + if (nodeFrom && nodeFrom->type == SvgNodeType::Symbol && nodeIdPair->node->type == SvgNodeType::Use) { + nodeIdPair->node->node.use.symbol = nodeFrom; + } + tvg::free(nodeIdPair->id); + tvg::free(nodeIdPair); + } + } else { + TVGLOG("SVG", "%s is ancestor element. This reference is invalid.", nodeIdPair->id); + tvg::free(nodeIdPair->id); + tvg::free(nodeIdPair); + } + nodeIdPair = cloneNodes->front(); + } +} + + +static void _svgLoaderParserXmlClose(SvgLoaderData* loader, const char* content, unsigned int length) +{ + const char* itr = nullptr; + int sz = length; + char tagName[20] = ""; + + content = svgUtilSkipWhiteSpace(content, nullptr); + itr = content; + while ((itr != nullptr) && *itr != '>') itr++; + + if (itr) { + sz = itr - content; + while ((sz > 0) && (isspace(content[sz - 1]))) sz--; + if ((unsigned int)sz >= sizeof(tagName)) sz = sizeof(tagName) - 1; + strncpy(tagName, content, sz); + tagName[sz] = '\0'; + } + else return; + + for (unsigned int i = 0; i < sizeof(groupTags) / sizeof(groupTags[0]); i++) { + if (!strncmp(tagName, groupTags[i].tag, sz)) { + loader->stack.pop(); + break; + } + } + + for (unsigned int i = 0; i < sizeof(gradientTags) / sizeof(gradientTags[0]); i++) { + if (!strncmp(tagName, gradientTags[i].tag, sz)) { + loader->gradientStack.pop(); + break; + } + } + + for (unsigned int i = 0; i < sizeof(graphicsTags) / sizeof(graphicsTags[0]); i++) { + if (!strncmp(tagName, graphicsTags[i].tag, sz)) { + loader->currentGraphicsNode = nullptr; + if (!strncmp(tagName, "text", 4)) loader->openedTag = OpenedTagType::Other; + loader->stack.pop(); + break; + } + } + + loader->level--; +} + + +static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content, unsigned int length, bool empty) +{ + const char* attrs = nullptr; + int attrsLength = 0; + int sz = length; + char tagName[20] = ""; + FactoryMethod method; + GradientFactoryMethod gradientMethod; + SvgNode *node = nullptr, *parent = nullptr; + loader->level++; + attrs = xmlFindAttributesTag(content, length); + + if (!attrs) { + //Parse the empty tag + attrs = content; + while ((attrs != nullptr) && *attrs != '>') attrs++; + if (empty) attrs--; + } + + if (attrs) { + //Find out the tag name starting from content till sz length + sz = attrs - content; + while ((sz > 0) && (isspace(content[sz - 1]))) sz--; + if ((unsigned)sz >= sizeof(tagName)) return; + strncpy(tagName, content, sz); + tagName[sz] = '\0'; + attrsLength = length - sz; + } + + if ((method = _findGroupFactory(tagName))) { + //Group + if (empty) return; + if (!loader->doc) { + if (!STR_AS(tagName, "svg")) return; //Not a valid svg document + node = method(loader, nullptr, attrs, attrsLength, xmlParseAttributes); + loader->doc = node; + } else { + if (STR_AS(tagName, "svg")) return; //Already loaded (SvgNodeType::Doc) tag + if (loader->stack.count > 0) parent = loader->stack.last(); + else parent = loader->doc; + if (STR_AS(tagName, "style")) { + // TODO: For now only the first style node is saved. After the css id selector + // is introduced this if condition shouldn't be necessary any more + if (!loader->cssStyle) { + node = method(loader, nullptr, attrs, attrsLength, xmlParseAttributes); + loader->cssStyle = node; + loader->doc->node.doc.style = node; + loader->openedTag = OpenedTagType::Style; + } + } else { + node = method(loader, parent, attrs, attrsLength, xmlParseAttributes); + } + } + + if (!node) return; + if (node->type != SvgNodeType::Defs || !empty) { + loader->stack.push(node); + } + } else if ((method = _findGraphicsFactory(tagName))) { + if (loader->stack.count > 0) parent = loader->stack.last(); + else parent = loader->doc; + node = method(loader, parent, attrs, attrsLength, xmlParseAttributes); + if (node && !empty) { + if (STR_AS(tagName, "text")) loader->openedTag = OpenedTagType::Text; + auto defs = _createDefsNode(loader, nullptr, nullptr, 0, nullptr); + loader->stack.push(defs); + loader->currentGraphicsNode = node; + } + } else if ((gradientMethod = _findGradientFactory(tagName))) { + SvgStyleGradient* gradient; + gradient = gradientMethod(loader, attrs, attrsLength); + //Gradients do not allow nested declarations, so only the earliest declared Gradient is valid. + if (loader->gradientStack.count == 0) { + //FIXME: The current parsing structure does not distinguish end tags. + // There is no way to know if the currently parsed gradient is in defs. + // If a gradient is declared outside of defs after defs is set, it is included in the gradients of defs. + // But finally, the loader has a gradient style list regardless of defs. + // This is only to support this when multiple gradients are declared, even if no defs are declared. + // refer to: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs + if (loader->def && loader->doc->node.doc.defs) { + loader->def->node.defs.gradients.push(gradient); + } else { + loader->gradients.push(gradient); + } + } + if (!empty) loader->gradientStack.push(gradient); + } else if (STR_AS(tagName, "stop")) { + if (loader->gradientStack.count == 0) { + TVGLOG("SVG", "Stop element is used outside of the Gradient element"); + return; + } + /* default value for opacity */ + loader->svgParse->gradStop = {0.0f, 0, 0, 0, 255}; + loader->svgParse->flags = SvgStopStyleFlags::StopDefault; + xmlParseAttributes(attrs, attrsLength, _attrParseStops, loader); + loader->gradientStack.last()->stops.push(loader->svgParse->gradStop); + } else { + if (!isIgnoreUnsupportedLogElements(tagName)) TVGLOG("SVG", "Unsupported elements used [Elements: %s]", tagName); + } +} + + +static void _svgLoaderParserText(SvgLoaderData* loader, const char* content, unsigned int length) +{ + auto& text = loader->svgParse->node->node.text; + text.text = append(text.text, content, length); +} + + +static char* _parseName(char* str, const char* delims, char** saveptr) +{ + auto pch = strtok_r(str, delims, saveptr); + + while (pch) { + while (*pch && isspace(*pch)) pch++; + + if (*pch == '\0') { + pch = strtok_r(nullptr, delims, saveptr); + continue; + } + + auto end = pch + strlen(pch) - 1; + while (end > pch && isspace(*end)) *end-- = '\0'; + + if (*pch == '\0') { + pch = strtok_r(nullptr, delims, saveptr); + continue; + } + break; + } + return pch; +} + + + +static void _free(SvgStyleProperty* style) +{ + if (!style) return; + + //style->clipPath.node/mask.node/filter.node has only the addresses of node. Therefore, node is released from _freeNode. + tvg::free(style->clipPath.url); + tvg::free(style->mask.url); + tvg::free(style->filter.url); + tvg::free(style->cssClass); + + if (style->fill.paint.gradient) { + style->fill.paint.gradient->clear(); + tvg::free(style->fill.paint.gradient); + } + if (style->stroke.paint.gradient) { + style->stroke.paint.gradient->clear(); + tvg::free(style->stroke.paint.gradient); + } + tvg::free(style->fill.paint.url); + tvg::free(style->stroke.paint.url); + style->stroke.dash.array.reset(); + tvg::free(style); +} + + +static void _free(SvgNode* node) +{ + if (!node) return; + + ARRAY_FOREACH(p, node->child) _free(*p); + node->child.reset(); + + tvg::free(node->id); + tvg::free(node->transform); + _free(node->style); + switch (node->type) { + case SvgNodeType::Path: { + tvg::free(node->node.path.path); + break; + } + case SvgNodeType::Polygon: { + tvg::free(node->node.polygon.pts.data); + break; + } + case SvgNodeType::Polyline: { + tvg::free(node->node.polyline.pts.data); + break; + } + case SvgNodeType::Doc: { + _free(node->node.doc.defs); + _free(node->node.doc.style); + break; + } + case SvgNodeType::Defs: { + ARRAY_FOREACH(p, node->node.defs.gradients) { + (*p)->clear(); + tvg::free(*p); + } + node->node.defs.gradients.reset(); + break; + } + case SvgNodeType::Image: { + tvg::free(node->node.image.href); + break; + } + case SvgNodeType::Text: { + tvg::free(node->node.text.text); + tvg::free(node->node.text.fontFamily); + break; + } + default: { + break; + } + } + tvg::free(node); +} + + +static bool _cssApplyClass(SvgNode* node, const char* classString, SvgNode* styleRoot) +{ + if (!classString || !styleRoot) return false; + + auto classes = duplicate(classString); + bool allFound = true; + + auto tempNode = tvg::calloc(1, sizeof(SvgNode)); + tempNode->style = tvg::calloc(1, sizeof(SvgStyleProperty)); + tempNode->type = node->type; + tempNode->style->opacity = 255; + tempNode->style->fill.opacity = 255; + tempNode->style->stroke.opacity = 255; + + char* tokPtr = nullptr; + auto name = _parseName(classes, " ", &tokPtr); + tvg::Array applyClasses; + + while (name) { + auto isDuplicate = false; + ARRAY_FOREACH(p, applyClasses) { + if (STR_AS(*p, name)) { + isDuplicate = true; + break; + } + } + if (isDuplicate) { + name = _parseName(nullptr, " ", &tokPtr); + continue; + } + applyClasses.push(name); + + auto found = false; + //css styling: tag.name has higher priority than .name + if (auto cssNode = cssFindStyleNode(styleRoot, name)) { + cssCopyStyleAttr(tempNode, cssNode, true); + found = true; + } + if (auto cssNode = cssFindStyleNode(styleRoot, name, node->type)) { + cssCopyStyleAttr(tempNode, cssNode, true); + found = true; + } + if (!found) allFound = false; + name = _parseName(nullptr, " ", &tokPtr); + } + + tvg::free(classes); + + //Apply the merged style to the node (without overwriting existing styles) + cssCopyStyleAttr(node, tempNode); + _free(tempNode); + + return allFound; +} + + +static void _cssApplyStyleToPostponeds(Array& postponeds, SvgNode* style) +{ + ARRAY_FOREACH(p, postponeds) { + auto nodeIdPair = *p; + _cssApplyClass(nodeIdPair.node, nodeIdPair.id, style); + } +} + + +static void _svgLoaderParserXmlCssStyle(SvgLoaderData* loader, const char* content, unsigned int length) +{ + char* tag; + char* name; + const char* attrs = nullptr; + unsigned int attrsLength = 0; + + FactoryMethod method; + GradientFactoryMethod gradientMethod; + SvgNode *node = nullptr; + + while (auto next = xmlParseCSSAttribute(content, length, &tag, &name, &attrs, &attrsLength)) { + if ((method = _findGroupFactory(tag))) { + if ((node = method(loader, loader->cssStyle, attrs, attrsLength, xmlParseW3CAttribute))) node->id = _copyId(name); + } else if ((method = _findGraphicsFactory(tag))) { + if ((node = method(loader, loader->cssStyle, attrs, attrsLength, xmlParseW3CAttribute))) node->id = _copyId(name); + } else if ((gradientMethod = _findGradientFactory(tag))) { + TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag); + } else if (STR_AS(tag, "stop")) { + TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag); + } else if (STR_AS(tag, "all")) { + char* tokPtr = nullptr; + auto id = _parseName(name, ",", &tokPtr); + + while (id) { + if (*id == '.') id++; + + if (auto cssNode = cssFindStyleNode(loader->cssStyle, id)) { + auto oldNode = loader->svgParse->node; + loader->svgParse->node = cssNode; + xmlParseW3CAttribute(attrs, attrsLength, _attrParseCssStyleNode, loader); + loader->svgParse->node = oldNode; + } else { + if ((node = _createCssStyleNode(loader, loader->cssStyle, attrs, attrsLength, xmlParseW3CAttribute))) { + node->id = _copyId(id); + } + } + id = _parseName(nullptr, ",", &tokPtr); + } + } else if (STR_AS(tag, "@font-face")) { //css at-rule specifying font + _createFontFace(loader, attrs, attrsLength, xmlParseW3CAttribute); + } else if (!isIgnoreUnsupportedLogElements(tag)) { + TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag); + } + + length -= next - content; + content = next; + + tvg::free(tag); + tvg::free(name); + } + loader->openedTag = OpenedTagType::Other; +} + + +static bool _svgLoaderParser(void* data, XMLType type, const char* content, unsigned int length) +{ + SvgLoaderData* loader = (SvgLoaderData*)data; + + switch (type) { + case XMLType::Open: { + _svgLoaderParserXmlOpen(loader, content, length, false); + break; + } + case XMLType::OpenEmpty: { + _svgLoaderParserXmlOpen(loader, content, length, true); + break; + } + case XMLType::Close: { + _svgLoaderParserXmlClose(loader, content, length); + break; + } + case XMLType::Data: + case XMLType::CData: { + if (loader->openedTag == OpenedTagType::Style) _svgLoaderParserXmlCssStyle(loader, content, length); + else if (loader->openedTag == OpenedTagType::Text) _svgLoaderParserText(loader, content, length); + break; + } + case XMLType::DoctypeChild: { + break; + } + case XMLType::Ignored: + case XMLType::Comment: + case XMLType::Doctype: { + break; + } + default: { + break; + } + } + + return true; +} + + +static void _updateStyle(SvgNode* node, SvgStyleProperty* parentStyle) +{ + _styleInherit(node->style, parentStyle); + ARRAY_FOREACH(p, node->child) { + _updateStyle(*p, node->style); + } +} + + +static void _updateGradient(SvgLoaderData* loader, SvgNode* node, Array* gradients) +{ + auto duplicate = [&](SvgLoaderData* loader, Array* gradients, const char* id) -> SvgStyleGradient* { + SvgStyleGradient* result = nullptr; + + ARRAY_FOREACH(p, *gradients) { + if ((*p)->id && STR_AS((*p)->id, id)) { + result = _cloneGradient(*p); + break; + } + } + if (result && result->ref) { + ARRAY_FOREACH(p, *gradients) { + if ((*p)->id && STR_AS((*p)->id, result->ref)) { + _inheritGradient(loader, result, *p); + break; + } + } + } + return result; + }; + + if (node->child.count > 0) { + ARRAY_FOREACH(p, node->child) { + _updateGradient(loader, *p, gradients); + } + } else { + if (node->style->fill.paint.url) { + auto newGrad = duplicate(loader, gradients, node->style->fill.paint.url); + if (newGrad) { + if (node->style->fill.paint.gradient) { + node->style->fill.paint.gradient->clear(); + tvg::free(node->style->fill.paint.gradient); + } + node->style->fill.paint.gradient = newGrad; + } + } + if (node->style->stroke.paint.url) { + auto newGrad = duplicate(loader, gradients, node->style->stroke.paint.url); + if (newGrad) { + if (node->style->stroke.paint.gradient) { + node->style->stroke.paint.gradient->clear(); + tvg::free(node->style->stroke.paint.gradient); + } + node->style->stroke.paint.gradient = newGrad; + } + } + } +} + + +static void _updateComposite(SvgNode* node, SvgNode* root) +{ + if (node->style->clipPath.url && !node->style->clipPath.node) { + SvgNode* findResult = _findNodeById(root, node->style->clipPath.url); + if (findResult) node->style->clipPath.node = findResult; + } + if (node->style->mask.url && !node->style->mask.node) { + SvgNode* findResult = _findNodeById(root, node->style->mask.url); + if (findResult) node->style->mask.node = findResult; + } + if (node->child.count > 0) { + ARRAY_FOREACH(p, node->child) { + _updateComposite(*p, root); + } + } +} + + +static void _updateFilter(SvgNode* node, SvgNode* root) +{ + if (node->style->filter.url && !node->style->filter.node) { + node->style->filter.node = _findNodeById(root, node->style->filter.url); + } + ARRAY_FOREACH(child, node->child) { + _updateFilter(*child, root); + } +} + + +static bool _svgLoaderParserForValidCheckXmlOpen(SvgLoaderData* loader, const char* content, unsigned int length) +{ + const char* attrs = nullptr; + int sz = length; + char tagName[20] = ""; + FactoryMethod method; + SvgNode *node = nullptr; + int attrsLength = 0; + loader->level++; + attrs = xmlFindAttributesTag(content, length); + + if (!attrs) { + //Parse the empty tag + attrs = content; + while ((attrs != nullptr) && *attrs != '>') attrs++; + } + + if (attrs) { + sz = attrs - content; + while ((sz > 0) && (isspace((unsigned char)content[sz - 1]))) sz--; + if ((unsigned)sz >= sizeof(tagName)) return false; + strncpy(tagName, content, sz); + tagName[sz] = '\0'; + attrsLength = length - sz; + } + + if ((method = _findGroupFactory(tagName))) { + if (!loader->doc) { + if (!STR_AS(tagName, "svg")) return true; //Not a valid svg document + node = method(loader, nullptr, attrs, attrsLength, xmlParseAttributes); + loader->doc = node; + loader->stack.push(node); + return false; + } + } + return true; +} + + +static bool _svgLoaderParserForValidCheck(void* data, XMLType type, const char* content, unsigned int length) +{ + switch (type) { + case XMLType::Open: + case XMLType::OpenEmpty: { + //If 'res' is false, it means tag is found. + return _svgLoaderParserForValidCheckXmlOpen(static_cast(data), content, length); + } + default: return true; + } +} + + +void SvgLoader::clear(bool all) +{ + //flush out the intermediate data + tvg::free(loaderData.svgParse); + loaderData.svgParse = nullptr; + + ARRAY_FOREACH(p, loaderData.gradients) { + (*p)->clear(); + tvg::free(*p); + } + loaderData.gradients.reset(); + loaderData.gradientStack.reset(); + + _free(loaderData.doc); + loaderData.doc = nullptr; + loaderData.stack.reset(); + + if (!all) return; + + ARRAY_FOREACH(p, loaderData.images) tvg::free(*p); + loaderData.images.reset(); + + ARRAY_FOREACH(p, loaderData.fonts) { + Text::unload(p->name); + tvg::free(p->decoded); + tvg::free(p->name); + } + loaderData.fonts.reset(); + + if (copy) tvg::free((char*)content); + + if (root) { + root->unref(); + root = nullptr; + } + + size = 0; + content = nullptr; + copy = false; +} + + +void SvgLoader::run(unsigned tid) +{ + //According to the SVG standard the value of the width/height of the viewbox set to 0 disables rendering + if ((viewFlag & SvgViewFlag::Viewbox) && (fabsf(vbox.w) <= FLOAT_EPSILON || fabsf(vbox.h) <= FLOAT_EPSILON)) { + TVGLOG("SVG", "The width and/or height set to 0 - rendering disabled."); + root = Scene::gen(); + } else { + if (xmlParse(content, size, true, _svgLoaderParser, &(loaderData))) { + if (loaderData.doc) { + auto defs = loaderData.doc->node.doc.defs; + + if (loaderData.nodesToStyle.count > 0) _cssApplyStyleToPostponeds(loaderData.nodesToStyle, loaderData.cssStyle); + if (loaderData.cssStyle) cssUpdateStyle(loaderData.doc, loaderData.cssStyle); + + if (!loaderData.cloneNodes.empty()) _clonePostponedNodes(&loaderData.cloneNodes, loaderData.doc); + + _updateComposite(loaderData.doc, loaderData.doc); + if (defs) _updateComposite(loaderData.doc, defs); + + _updateFilter(loaderData.doc, loaderData.doc); + if (defs) _updateFilter(loaderData.doc, defs); + + _updateStyle(loaderData.doc, nullptr); + if (defs) _updateStyle(defs, nullptr); + + if (loaderData.gradients.count > 0) _updateGradient(&loaderData, loaderData.doc, &loaderData.gradients); + if (defs) _updateGradient(&loaderData, loaderData.doc, &defs->node.defs.gradients); + + root = svgSceneBuild(loaderData, vbox, w, h, align, meetOrSlice, svgPath, viewFlag); + + //In case no viewbox and width/height data is provided the completion of loading + //has to be forced, in order to establish this data based on the whole picture. + if (!(viewFlag & SvgViewFlag::Viewbox)) { + //Override viewbox & size again after svg loading. + vbox = loaderData.doc->node.doc.vbox; + w = loaderData.doc->node.doc.w; + h = loaderData.doc->node.doc.h; + } + } + } + } + root->ref(); + clear(false); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +SvgLoader::SvgLoader() : ImageLoader(FileType::Svg) +{ +} + + +SvgLoader::~SvgLoader() +{ + done(); + clear(); +} + + +bool SvgLoader::header() +{ + //For valid check, only tag is parsed first. + //If the tag is found, the loaded file is valid and stores viewbox information. + //After that, the remaining content data is parsed in order with async. + loaderData.svgParse = tvg::malloc(sizeof(SvgParser)); + loaderData.svgParse->flags = SvgStopStyleFlags::StopDefault; + viewFlag = SvgViewFlag::None; + + xmlParse(content, size, true, _svgLoaderParserForValidCheck, &(loaderData)); + + if (!loaderData.doc || loaderData.doc->type != SvgNodeType::Doc) { + TVGLOG("SVG", "No SVG File. There is no "); + return false; + } + + viewFlag = loaderData.doc->node.doc.viewFlag; + align = loaderData.doc->node.doc.align; + meetOrSlice = loaderData.doc->node.doc.meetOrSlice; + + if (viewFlag & SvgViewFlag::Viewbox) { + vbox = loaderData.doc->node.doc.vbox; + + if (viewFlag & SvgViewFlag::Width) w = loaderData.doc->node.doc.w; + else { + w = loaderData.doc->node.doc.vbox.w; + if (viewFlag & SvgViewFlag::WidthInPercent) { + w *= loaderData.doc->node.doc.w; + viewFlag = (viewFlag ^ SvgViewFlag::WidthInPercent); + } + viewFlag = (viewFlag | SvgViewFlag::Width); + } + if (viewFlag & SvgViewFlag::Height) h = loaderData.doc->node.doc.h; + else { + h = loaderData.doc->node.doc.vbox.h; + if (viewFlag & SvgViewFlag::HeightInPercent) { + h *= loaderData.doc->node.doc.h; + viewFlag = (viewFlag ^ SvgViewFlag::HeightInPercent); + } + viewFlag = (viewFlag | SvgViewFlag::Height); + } + //In case no viewbox and width/height data is provided the completion of loading + //has to be forced, in order to establish this data based on the whole picture. + } else { + //Before loading, set default viewbox & size if they are empty + vbox.x = vbox.y = 0.0f; + if (viewFlag & SvgViewFlag::Width) { + vbox.w = w = loaderData.doc->node.doc.w; + } else { + vbox.w = 1.0f; + if (viewFlag & SvgViewFlag::WidthInPercent) { + w = loaderData.doc->node.doc.w; + } else w = 1.0f; + } + + if (viewFlag & SvgViewFlag::Height) { + vbox.h = h = loaderData.doc->node.doc.h; + } else { + vbox.h = 1.0f; + if (viewFlag & SvgViewFlag::HeightInPercent) { + h = loaderData.doc->node.doc.h; + } else h = 1.0f; + } + + run(0); + } + return true; +} + + +bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + if (copy) { + content = tvg::malloc(size + 1); + if (!content) return false; + memcpy((char*)content, data, size); + content[size] = '\0'; + } else content = (char*)data; + + this->size = size; + this->copy = copy; + + return header(); +} + + +bool SvgLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + if ((content = LoadModule::open(path, size, true))) { + copy = true; + return header(); + } +#endif + return false; +} + + +bool SvgLoader::resize(Paint* paint, float w, float h) +{ + if (!paint) return false; + + auto sx = w / this->w; + auto sy = h / this->h; + Matrix m = {sx, 0, 0, 0, sy, 0, 0, 0, 1}; + paint->transform(m); + + return true; +} + + +bool SvgLoader::read() +{ + if (!content || size == 0) return false; + + if (!LoadModule::read() || root) return true; + + TaskScheduler::request(this); + + return true; +} + + +bool SvgLoader::close() +{ + if (!LoadModule::close()) return false; + this->done(); + clear(); + return true; +} + + +Paint* SvgLoader::paint() +{ + this->done(); + if (root) { + //Primary usage: sharing the svg + if (root->refCnt() == 1) return root; + return root->duplicate(); + } + return nullptr; +} diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgLoader.h b/components/thorvg-main/src/loaders/svg/tvgSvgLoader.h new file mode 100644 index 0000000..063b718 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgLoader.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SVG_LOADER_H_ +#define _TVG_SVG_LOADER_H_ + +#include "tvgTaskScheduler.h" +#include "tvgSvgLoaderCommon.h" + +class SvgLoader : public ImageLoader, public Task +{ +public: + string svgPath = ""; + char* content = nullptr; + uint32_t size = 0; + + SvgLoaderData loaderData; + Scene* root = nullptr; + + bool copy = false; + + SvgLoader(); + ~SvgLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool resize(Paint* paint, float w, float h) override; + bool read() override; + bool close() override; + + Paint* paint() override; + +private: + SvgViewFlag viewFlag = SvgViewFlag::None; + AspectRatioAlign align = AspectRatioAlign::XMidYMid; + AspectRatioMeetOrSlice meetOrSlice = AspectRatioMeetOrSlice::Meet; + Box vbox{}; + + bool header(); + void clear(bool all = true); + void run(unsigned tid) override; +}; + + +#endif //_TVG_SVG_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgLoaderCommon.h b/components/thorvg-main/src/loaders/svg/tvgSvgLoaderCommon.h new file mode 100644 index 0000000..4ecddde --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgLoaderCommon.h @@ -0,0 +1,630 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SVG_LOADER_COMMON_H_ +#define _TVG_SVG_LOADER_COMMON_H_ + +#include "tvgCommon.h" +#include "tvgArray.h" +#include "tvgInlist.h" +#include "tvgColor.h" + +using SvgColor = tvg::RGB; + +#define STR_AS(A, B) !strcmp((A), (B)) + +struct Box +{ + float x, y, w, h; + + void intersect(const Box& box) + { + auto x1 = x + w; + auto y1 = y + h; + auto x2 = box.x + box.w; + auto y2 = box.y + box.h; + + x = x > box.x ? x : box.x; + y = y > box.y ? y : box.y; + w = (x1 < x2 ? x1 : x2) - x; + h = (y1 < y2 ? y1 : y2) - y; + + if (w < 0.0f) w = 0.0f; + if (h < 0.0f) h = 0.0f; + } +}; + +struct SvgNode; +struct SvgStyleGradient; + +//NOTE: Please update simpleXmlNodeTypeToString() as well. +enum class SvgNodeType +{ + Doc, + G, + Defs, + Animation, + Arc, + Circle, + Ellipse, + Image, + Line, + Path, + Polygon, + Polyline, + Rect, + Text, + TextArea, + Tspan, + Use, + Video, + ClipPath, + Mask, + CssStyle, + Symbol, + Filter, + GaussianBlur, + Unknown +}; + +/* +// TODO - remove? +enum class SvgLengthType +{ + Percent, + Px, + Pc, + Pt, + Mm, + Cm, + In, +}; +*/ + +enum class SvgFillFlags +{ + Paint = 0x01, + Opacity = 0x02, + Gradient = 0x04, + FillRule = 0x08, + ClipPath = 0x16 +}; + +constexpr bool operator&(SvgFillFlags a, SvgFillFlags b) +{ + return int(a) & int(b); +} + +constexpr SvgFillFlags operator|(SvgFillFlags a, SvgFillFlags b) +{ + return SvgFillFlags(int(a) | int(b)); +} + +constexpr void operator|=(SvgFillFlags& a, const SvgFillFlags b) +{ + a = SvgFillFlags(int(a) | int(b)); +} + +enum class SvgStrokeFlags +{ + Paint = 0x1, + Opacity = 0x2, + Gradient = 0x4, + Scale = 0x8, + Width = 0x10, + Cap = 0x20, + Join = 0x40, + Dash = 0x80, + Miterlimit = 0x100, + DashOffset = 0x200 +}; + +constexpr bool operator&(SvgStrokeFlags a, SvgStrokeFlags b) +{ + return int(a) & int(b); +} + +constexpr SvgStrokeFlags operator|(SvgStrokeFlags a, SvgStrokeFlags b) +{ + return SvgStrokeFlags(int(a) | int(b)); +} + +constexpr void operator|=(SvgStrokeFlags& a, const SvgStrokeFlags b) +{ + a = SvgStrokeFlags(int(a) | int(b)); +} + +enum class SvgGradientType +{ + Linear, + Radial +}; + +enum class SvgStyleFlags +{ + Color = 0x01, + Fill = 0x02, + FillRule = 0x04, + FillOpacity = 0x08, + Opacity = 0x010, + Stroke = 0x20, + StrokeWidth = 0x40, + StrokeLineJoin = 0x80, + StrokeLineCap = 0x100, + StrokeOpacity = 0x200, + StrokeDashArray = 0x400, + Transform = 0x800, + ClipPath = 0x1000, + Mask = 0x2000, + MaskType = 0x4000, + Display = 0x8000, + PaintOrder = 0x10000, + StrokeMiterlimit = 0x20000, + StrokeDashOffset = 0x40000, + Filter = 0x80000 +}; + +constexpr bool operator&(SvgStyleFlags a, SvgStyleFlags b) +{ + return int(a) & int(b); +} + +constexpr SvgStyleFlags operator|(SvgStyleFlags a, SvgStyleFlags b) +{ + return SvgStyleFlags(int(a) | int(b)); +} + +constexpr void operator|=(SvgStyleFlags& a, const SvgStyleFlags b) +{ + a = SvgStyleFlags(int(a) | int(b)); +} + +enum class SvgStopStyleFlags +{ + StopDefault = 0x0, + StopOpacity = 0x01, + StopColor = 0x02 +}; + +constexpr bool operator&(SvgStopStyleFlags a, SvgStopStyleFlags b) +{ + return int(a) & int(b); +} + +constexpr SvgStopStyleFlags operator|(SvgStopStyleFlags a, SvgStopStyleFlags b) +{ + return SvgStopStyleFlags(int(a) | int(b)); +} + +enum class SvgGradientFlags +{ + None = 0x0, + GradientUnits = 0x1, + SpreadMethod = 0x2, + X1 = 0x4, + X2 = 0x8, + Y1 = 0x10, + Y2 = 0x20, + Cx = 0x40, + Cy = 0x80, + R = 0x100, + Fx = 0x200, + Fy = 0x400, + Fr = 0x800 +}; + +constexpr bool operator &(SvgGradientFlags a, SvgGradientFlags b) +{ + return int(a) & int(b); +} + +constexpr SvgGradientFlags operator |(SvgGradientFlags a, SvgGradientFlags b) +{ + return SvgGradientFlags(int(a) | int(b)); +} + +enum class SvgMaskType +{ + Luminance = 0, + Alpha +}; + +enum class SvgXmlSpace +{ + None, + Default, + Preserve +}; + +//Length type to recalculate %, pt, pc, mm, cm etc +enum class SvgParserLengthType +{ + Vertical, + Horizontal, + Diagonal, + //In case of, for example, radius of radial gradient + Other +}; + +enum class SvgViewFlag +{ + None = 0x0, + Width = 0x01, //viewPort width + Height = 0x02, //viewPort height + Viewbox = 0x04, //viewBox x,y,w,h - used only if all 4 are correctly set + WidthInPercent = 0x08, + HeightInPercent = 0x10 +}; + +constexpr bool operator &(SvgViewFlag a, SvgViewFlag b) +{ + return static_cast(a) & static_cast(b); +} + +constexpr SvgViewFlag operator |(SvgViewFlag a, SvgViewFlag b) +{ + return SvgViewFlag(int(a) | int(b)); +} + +constexpr SvgViewFlag operator ^(SvgViewFlag a, SvgViewFlag b) +{ + return SvgViewFlag(int(a) ^ int(b)); +} + +enum class AspectRatioAlign +{ + None, + XMinYMin, + XMidYMin, + XMaxYMin, + XMinYMid, + XMidYMid, + XMaxYMid, + XMinYMax, + XMidYMax, + XMaxYMax +}; + +enum class AspectRatioMeetOrSlice +{ + Meet, + Slice +}; + +struct SvgDocNode +{ + float w, h; //unit: point or in percentage see: SvgViewFlag + Box vbox; + SvgViewFlag viewFlag; + SvgNode* defs; + SvgNode* style; + AspectRatioAlign align; + AspectRatioMeetOrSlice meetOrSlice; +}; + +struct SvgGNode +{ +}; + +struct SvgDefsNode +{ + Array gradients; +}; + +struct SvgSymbolNode +{ + float w, h; + float vx, vy, vw, vh; + AspectRatioAlign align; + AspectRatioMeetOrSlice meetOrSlice; + bool overflowVisible; + bool hasViewBox; + bool hasWidth; + bool hasHeight; +}; + +struct SvgUseNode +{ + float x, y, w, h; + bool isWidthSet; + bool isHeightSet; + SvgNode* symbol; +}; + +struct SvgEllipseNode +{ + float cx, cy, rx, ry; +}; + +struct SvgCircleNode +{ + float cx, cy, r; +}; + +struct SvgRectNode +{ + float x, y, w, h, rx, ry; + bool hasRx, hasRy; +}; + +struct SvgLineNode +{ + float x1, y1, x2, y2; +}; + +struct SvgImageNode +{ + float x, y, w, h; + char* href; +}; + +struct SvgPathNode +{ + char* path; +}; + +struct SvgPolygonNode +{ + Array pts; +}; + +struct SvgClipNode +{ + bool userSpace; +}; + +struct SvgMaskNode +{ + SvgMaskType type; + bool userSpace; +}; + +struct SvgCssStyleNode +{ +}; + +struct SvgTextNode +{ + char* text; + char* fontFamily; + float x, y; + float fontSize; +}; + +struct SvgGaussianBlurNode +{ + float stdDevX, stdDevY; + Box box; + bool isPercentage[4]; + bool hasBox; + bool edgeModeWrap; +}; + +struct SvgFilterNode +{ + Box box; + bool isPercentage[4]; + bool filterUserSpace; + bool primitiveUserSpace; +}; + +struct SvgLinearGradient +{ + float x1, y1, x2, y2; + bool isX1Percentage; + bool isY1Percentage; + bool isX2Percentage; + bool isY2Percentage; +}; + +struct SvgRadialGradient +{ + float cx, cy, fx, fy, r, fr; + bool isCxPercentage; + bool isCyPercentage; + bool isFxPercentage; + bool isFyPercentage; + bool isRPercentage; + bool isFrPercentage; +}; + +struct SvgComposite +{ + char *url; + SvgNode* node; + bool applying; //flag for checking circular dependency. +}; + +struct SvgPaint +{ + SvgStyleGradient* gradient; + char *url; + SvgColor color; + bool none; + bool curColor; +}; + +struct SvgDash +{ + Array array; + float offset; +}; + +struct SvgStyleGradient +{ + SvgGradientType type; + char* id; + char* ref; + FillSpread spread; + SvgRadialGradient* radial; + SvgLinearGradient* linear; + Matrix* transform; + Array stops; + SvgGradientFlags flags; + bool userSpace; + + void clear() + { + stops.reset(); + tvg::free(transform); + tvg::free(radial); + tvg::free(linear); + tvg::free(ref); + tvg::free(id); + } +}; + +struct SvgStyleFill +{ + SvgFillFlags flags; + SvgPaint paint; + int opacity; + FillRule fillRule; +}; + +struct SvgStyleStroke +{ + SvgStrokeFlags flags; + SvgPaint paint; + int opacity; + float scale; + float width; + float centered; + StrokeCap cap; + StrokeJoin join; + float miterlimit; + SvgDash dash; +}; + +struct SvgFilter +{ + char *url; + SvgNode* node; +}; + +struct SvgStyleProperty +{ + SvgStyleFill fill; + SvgStyleStroke stroke; + SvgComposite clipPath; + SvgComposite mask; + SvgFilter filter; + int opacity; + SvgColor color; + char* cssClass; + SvgStyleFlags flags; + SvgStyleFlags flagsImportance; //indicates the importance of the flag - if set, higher priority is applied (https://drafts.csswg.org/css-cascade-4/#importance) + bool curColorSet; + bool paintOrder; //true if default (fill, stroke), false otherwise + bool display; +}; + +struct SvgNode +{ + SvgNodeType type; + SvgNode* parent; + Array child; + char *id; + SvgStyleProperty *style; + Matrix* transform; + union { + SvgGNode g; + SvgDocNode doc; + SvgDefsNode defs; + SvgUseNode use; + SvgCircleNode circle; + SvgEllipseNode ellipse; + SvgPolygonNode polygon; + SvgPolygonNode polyline; + SvgRectNode rect; + SvgPathNode path; + SvgLineNode line; + SvgImageNode image; + SvgMaskNode mask; + SvgClipNode clip; + SvgCssStyleNode cssStyle; + SvgSymbolNode symbol; + SvgTextNode text; + SvgFilterNode filter; + SvgGaussianBlurNode gaussianBlur; + } node; + SvgXmlSpace xmlSpace = SvgXmlSpace::None; + ~SvgNode(); +}; + +struct SvgParser +{ + SvgNode* node; + SvgStyleGradient* styleGrad; + Fill::ColorStop gradStop; + SvgStopStyleFlags flags; + Box global; + struct + { + bool parsedFx; + bool parsedFy; + } gradient; +}; + +struct SvgNodeIdPair +{ + INLIST_ITEM(SvgNodeIdPair); + SvgNodeIdPair(SvgNode* n, char* i) : node{n}, id{i} {} + SvgNode* node; + char *id; +}; + +struct FontFace +{ + char* name = nullptr; + char* src = nullptr; + size_t srcLen = 0; + char* decoded = nullptr; +}; + +enum class OpenedTagType : uint8_t +{ + Other = 0, + Style, + Text +}; + +struct SvgLoaderData +{ + Array stack; + SvgNode* doc = nullptr; + SvgNode* def = nullptr; //also used to store nested graphic nodes + SvgNode* cssStyle = nullptr; + Array gradients; + Array gradientStack; //For stops + SvgParser* svgParse = nullptr; + Inlist cloneNodes; + Array nodesToStyle; + Array images; //embedded images + Array fonts; + int level = 0; + bool result = false; + OpenedTagType openedTag = OpenedTagType::Other; + SvgNode* currentGraphicsNode = nullptr; +}; + +#endif diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgPath.cpp b/components/thorvg-main/src/loaders/svg/tvgSvgPath.cpp new file mode 100644 index 0000000..422d1cd --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgPath.cpp @@ -0,0 +1,428 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _USE_MATH_DEFINES //Math Constants are not defined in Standard C/C++. + +#include +#include +#include "tvgMath.h" +#include "tvgSvgLoaderCommon.h" +#include "tvgSvgPath.h" +#include "tvgStr.h" +#include "tvgSvgUtil.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static char* _skipComma(const char* content) +{ + content = svgUtilSkipWhiteSpace(content, nullptr); + if (*content == ',') return (char*)content + 1; + return (char*)content; +} + + +static bool _parseNumber(char** content, float* number) +{ + char* end = NULL; + *number = toFloat(*content, &end); + //If the start of string is not number + if ((*content) == end) return false; + //Skip comma if any + *content = _skipComma(end); + return true; +} + + +static bool _parseFlag(char** content, int* number) +{ + char* end = NULL; + if (*(*content) != '0' && *(*content) != '1') return false; + *number = *(*content) - '0'; + *content += 1; + end = *content; + *content = _skipComma(end); + + return true; +} + + +//Some helpful stuff is available here: +//http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes +void _pathAppendArcTo(RenderPath& out, Point& cur, Point& curCtl, const Point& next, Point radius, float angle, bool largeArc, bool sweep) +{ + auto start = cur; + auto cosPhi = cosf(angle); + auto sinPhi = sinf(angle); + auto d2 = (start - next) * 0.5f; + auto x1p = cosPhi * d2.x + sinPhi * d2.y; + auto y1p = cosPhi * d2.y - sinPhi * d2.x; + auto x1p2 = x1p * x1p; + auto y1p2 = y1p * y1p; + auto radius2 = Point{radius.x * radius.x, radius.y * radius.y}; + auto lambda = (x1p2 / radius2.x) + (y1p2 / radius2.y); + + //Correction of out-of-range radii, see F6.6.2 (step 4) + if (lambda > 1.0f) { + //See F6.6.3 + radius *= sqrtf(lambda); + radius2 = {radius.x * radius.x, radius.y * radius.y}; + } + + Point cp, center; + auto c = (radius2.x * radius2.y) - (radius2.x * y1p2) - (radius2.y * x1p2); + + //Check if there is no possible solution + //(i.e. we can't do a square root of a negative value) + if (c < 0.0f) { + //Scale uniformly until we have a single solution + //(see F6.2) i.e. when c == 0.0 + radius *= sqrtf(1.0f - c / (radius2.x * radius2.y)); + radius2 = {radius.x * radius.x, radius.y * radius.y}; + //Step 2 (F6.5.2) - simplified since c == 0.0 + cp = {0.0f, 0.0f}; + //Step 3 (F6.5.3 first part) - simplified since cxp and cyp == 0.0 + center = {0.0f, 0.0f}; + } else { + //Complete c calculation + c = sqrtf(c / ((radius2.x * y1p2) + (radius2.y * x1p2))); + //Inverse sign if Fa == Fs + if (largeArc == sweep) c = -c; + //Step 2 (F6.5.2) + cp = c * Point{(radius.x * y1p / radius.y), (-radius.y * x1p / radius.x)}; + //Step 3 (F6.5.3 first part) + center = {cosPhi * cp.x - sinPhi * cp.y, sinPhi * cp.x + cosPhi * cp.y}; + } + + //Step 3 (F6.5.3 second part) we now have the center point of the ellipse + center += (start + next) * 0.5f; + + //Step 4 (F6.5.4) + //We don't use arccos (as per w3c doc), see + //http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm + //Note: atan2 (0.0, 1.0) == 0.0 + auto at = tvg::atan2(((y1p - cp.y) / radius.y), ((x1p - cp.x) / radius.x)); + auto theta1 = (at < 0.0f) ? 2.0f * MATH_PI + at : at; + auto nat = tvg::atan2(((-y1p - cp.y) / radius.y), ((-x1p - cp.x) / radius.x)); + auto deltaTheta = (nat < at) ? 2.0f * MATH_PI - at + nat : nat - at; + + if (sweep) { + //Ensure delta theta < 0 or else add 360 degrees + if (deltaTheta < 0.0f) deltaTheta += 2.0f * MATH_PI; + } else { + //Ensure delta theta > 0 or else subtract 360 degrees + if (deltaTheta > 0.0f) deltaTheta -= 2.0f * MATH_PI; + } + + //Add several cubic bezier to approximate the arc + //(smaller than 90 degrees) + //We add one extra segment because we want something + //Smaller than 90deg (i.e. not 90 itself) + auto segments = int(fabsf(deltaTheta / MATH_PI2) + 1.0f); + auto delta = deltaTheta / segments; + + //http://www.stillhq.com/ctpfaq/2001/comp.text.pdf-faq-2001-04.txt (section 2.13) + auto bcp = 4.0f / 3.0f * (1.0f - cosf(delta / 2.0f)) / sinf(delta / 2.0f); + auto cosPhiR = Point{cosPhi * radius.x, cosPhi * radius.y}; + auto sinPhiR = Point{sinPhi * radius.x, sinPhi * radius.y}; + auto cosTheta1 = cosf(theta1); + auto sinTheta1 = sinf(theta1); + + for (int i = 0; i < segments; ++i) { + //End angle (for this segment) = current + delta + auto theta2 = theta1 + delta; + auto cosTheta2 = cosf(theta2); + auto sinTheta2 = sinf(theta2); + + //First control point (based on start point sx,sy) + auto c1 = start + Point{-bcp * (cosPhiR.x * sinTheta1 + sinPhiR.y * cosTheta1), bcp * (cosPhiR.y * cosTheta1 - sinPhiR.x * sinTheta1)}; + + //End point (for this segment) + auto e = center + Point{cosPhiR.x * cosTheta2 - sinPhiR.y * sinTheta2, sinPhiR.x * cosTheta2 + cosPhiR.y * sinTheta2}; + + //Second control point (based on end point ex,ey) + curCtl = e + Point{bcp * (cosPhiR.x * sinTheta2 + sinPhiR.y * cosTheta2), bcp * (sinPhiR.x * sinTheta2 - cosPhiR.y * cosTheta2)}; + cur = e; + out.cubicTo(c1, curCtl, cur); + + //Next start point is the current end point (same for angle) + start = e; + theta1 = theta2; + //Avoid recomputations + cosTheta1 = cosTheta2; + sinTheta1 = sinTheta2; + } +} + + +static int _numberCount(char cmd) +{ + int count = 0; + switch (cmd) { + case 'M': + case 'm': + case 'L': + case 'l': + case 'T': + case 't': { + count = 2; + break; + } + case 'C': + case 'c': + case 'E': + case 'e': { + count = 6; + break; + } + case 'H': + case 'h': + case 'V': + case 'v': { + count = 1; + break; + } + case 'S': + case 's': + case 'Q': + case 'q': { + count = 4; + break; + } + case 'A': + case 'a': { + count = 7; + break; + } + default: break; + } + return count; +} + + +static bool _processCommand(RenderPath& out, char cmd, float* arr, int count, Point& cur, Point& curCtl, Point& start, bool& quadratic, bool& closed) +{ + switch (cmd) { + case 'm': + case 'l': + case 'c': + case 's': + case 'q': + case 't': { + for (int i = 0; i < count - 1; i += 2) { + arr[i] = arr[i] + cur.x; + arr[i + 1] = arr[i + 1] + cur.y; + } + break; + } + case 'h': { + arr[0] = arr[0] + cur.x; + break; + } + case 'v': { + arr[0] = arr[0] + cur.y; + break; + } + case 'a': { + arr[5] = arr[5] + cur.x; + arr[6] = arr[6] + cur.y; + break; + } + default: break; + } + + switch (cmd) { + case 'm': + case 'M': { + start = cur = {arr[0], arr[1]}; + out.moveTo(cur); + break; + } + case 'l': + case 'L': { + cur = {arr[0], arr[1]}; + out.lineTo(cur); + break; + } + case 'c': + case 'C': { + curCtl = {arr[2], arr[3]}; + cur = {arr[4], arr[5]}; + out.cubicTo({arr[0], arr[1]}, curCtl, cur); + quadratic = false; + break; + } + case 's': + case 'S': { + Point ctrl; + if ((out.cmds.count > 1) && (out.cmds.last() == PathCommand::CubicTo) && !quadratic) { + ctrl = 2 * cur - curCtl; + } else { + ctrl = cur; + } + curCtl = {arr[0], arr[1]}; + cur = {arr[2], arr[3]}; + out.cubicTo(ctrl, curCtl, cur); + quadratic = false; + break; + } + case 'q': + case 'Q': { + auto ctrl1 = (cur + 2 * Point{arr[0], arr[1]}) * (1.0f / 3.0f); + auto ctrl2 = (Point{arr[2], arr[3]} + 2 * Point{arr[0], arr[1]}) * (1.0f / 3.0f); + curCtl = {arr[0], arr[1]}; + cur = {arr[2], arr[3]}; + out.cubicTo(ctrl1, ctrl2, cur); + quadratic = true; + break; + } + case 't': + case 'T': { + Point ctrl; + if ((out.cmds.count > 1) && (out.cmds.last() == PathCommand::CubicTo) && quadratic) { + ctrl = 2 * cur - curCtl; + } else { + ctrl = cur; + } + auto ctrl1 = (cur + 2 * ctrl) * (1.0f / 3.0f); + auto ctrl2 = (Point{arr[0], arr[1]} + 2 * ctrl) * (1.0f / 3.0f); + curCtl = {ctrl.x, ctrl.y}; + cur = {arr[0], arr[1]}; + out.cubicTo(ctrl1, ctrl2, cur); + quadratic = true; + break; + } + case 'h': + case 'H': { + out.lineTo({arr[0], cur.y}); + cur.x = arr[0]; + break; + } + case 'v': + case 'V': { + out.lineTo({cur.x, arr[0]}); + cur.y = arr[0]; + break; + } + case 'z': + case 'Z': { + out.close(); + cur = start; + closed = true; + break; + } + case 'a': + case 'A': { + if (tvg::zero(arr[0]) || tvg::zero(arr[1])) { + cur = {arr[5], arr[6]}; + out.lineTo(cur); + } else if (!tvg::equal(cur.x, arr[5]) || !tvg::equal(cur.y, arr[6])) { + _pathAppendArcTo(out, cur, curCtl, {arr[5], arr[6]}, {fabsf(arr[0]), fabsf(arr[1])}, deg2rad(arr[2]), arr[3], arr[4]); + cur = curCtl = {arr[5], arr[6]}; + quadratic = false; + } + break; + } + default: return false; + } + return true; +} + + +static char* _nextCommand(char* path, char* cmd, float* arr, int* count, bool* closed) +{ + int large, sweep; + + path = _skipComma(path); + if (isalpha(*path)) { + *cmd = *path; + path++; + *count = _numberCount(*cmd); + } else { + if (*cmd == 'm') *cmd = 'l'; + else if (*cmd == 'M') *cmd = 'L'; + else { + if (*closed) return nullptr; + } + } + if (*count == 7) { + //Special case for arc command + if (_parseNumber(&path, &arr[0])) { + if (_parseNumber(&path, &arr[1])) { + if (_parseNumber(&path, &arr[2])) { + if (_parseFlag(&path, &large)) { + if (_parseFlag(&path, &sweep)) { + if (_parseNumber(&path, &arr[5])) { + if (_parseNumber(&path, &arr[6])) { + arr[3] = (float)large; + arr[4] = (float)sweep; + return path; + } + } + } + } + } + } + } + *count = 0; + return nullptr; + } + for (int i = 0; i < *count; i++) { + if (!_parseNumber(&path, &arr[i])) { + *count = 0; + return nullptr; + } + path = _skipComma(path); + } + return path; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +bool svgPathToShape(const char* svgPath, RenderPath& out) +{ + float numberArray[7]; + int numberCount = 0; + Point cur = {0, 0}; + Point curCtl = {0, 0}; + Point start = {0, 0}; + char cmd = 0; + auto path = (char*)svgPath; + auto lastCmds = out.cmds.count; + auto isQuadratic = false; + auto closed = false; + + while ((path[0] != '\0')) { + path = _nextCommand(path, &cmd, numberArray, &numberCount, &closed); + if (!path) break; + closed = false; + if (!_processCommand(out, cmd, numberArray, numberCount, cur, curCtl, start, isQuadratic, closed)) break; + } + + if (out.cmds.count > lastCmds && out.cmds[lastCmds] != PathCommand::MoveTo) return false; + return true; +} diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgPath.h b/components/thorvg-main/src/loaders/svg/tvgSvgPath.h new file mode 100644 index 0000000..9b0a938 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgPath.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SVG_PATH_H_ +#define _TVG_SVG_PATH_H_ + +#include "tvgRender.h" + +bool svgPathToShape(const char* svgPath, RenderPath& out); + +#endif //_TVG_SVG_PATH_H_ diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgSceneBuilder.cpp b/components/thorvg-main/src/loaders/svg/tvgSvgSceneBuilder.cpp new file mode 100644 index 0000000..d1dae17 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -0,0 +1,1071 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" /* to include math.h before cstring */ +#include "tvgShape.h" +#include "tvgCompressor.h" +#include "tvgFill.h" +#include "tvgStr.h" +#include "tvgShape.h" +#include "tvgSvgLoaderCommon.h" +#include "tvgSvgSceneBuilder.h" +#include "tvgSvgPath.h" +#include "tvgSvgUtil.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static bool _appendClipShape(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, const Matrix* transform); +static Scene* _sceneBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath, bool mask, int depth); + + +static inline bool _isGroupType(SvgNodeType type) +{ + if (type == SvgNodeType::Doc || type == SvgNodeType::G || type == SvgNodeType::Use || type == SvgNodeType::ClipPath || type == SvgNodeType::Symbol || type == SvgNodeType::Filter) return true; + return false; +} + + +//According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph) +//a stroke width should be ignored for bounding box calculations +static Box _bounds(Paint* paint) +{ + float x, y, w, h; + paint->bounds(&x, &y, &w, &h); + return {x, y, w, h}; +} + + +static void _transformMultiply(const Matrix* mBBox, Matrix* gradTransf) +{ + gradTransf->e13 = gradTransf->e13 * mBBox->e11 + mBBox->e13; + gradTransf->e12 *= mBBox->e11; + gradTransf->e11 *= mBBox->e11; + + gradTransf->e23 = gradTransf->e23 * mBBox->e22 + mBBox->e23; + gradTransf->e22 *= mBBox->e22; + gradTransf->e21 *= mBBox->e22; +} + + +static LinearGradient* _applyLinearGradientProperty(SvgStyleGradient* g, const Box& vBox, int opacity) +{ + Fill::ColorStop* stops; + auto fillGrad = LinearGradient::gen(); + auto isTransform = (g->transform ? true : false); + auto& finalTransform = fillGrad->transform(); + if (isTransform) finalTransform = *g->transform; + + if (g->userSpace) { + g->linear->x1 = g->linear->x1 * vBox.w; + g->linear->y1 = g->linear->y1 * vBox.h; + g->linear->x2 = g->linear->x2 * vBox.w; + g->linear->y2 = g->linear->y2 * vBox.h; + } else { + Matrix m = {vBox.w, 0, vBox.x, 0, vBox.h, vBox.y, 0, 0, 1}; + if (isTransform) _transformMultiply(&m, &finalTransform); + else finalTransform = m; + } + + fillGrad->linear(g->linear->x1, g->linear->y1, g->linear->x2, g->linear->y2); + fillGrad->spread(g->spread); + + //Update the stops + if (g->stops.count == 0) return fillGrad; + + stops = tvg::malloc(g->stops.count * sizeof(Fill::ColorStop)); + auto prevOffset = 0.0f; + for (uint32_t i = 0; i < g->stops.count; ++i) { + auto colorStop = &g->stops[i]; + //Use premultiplied color + stops[i].r = colorStop->r; + stops[i].g = colorStop->g; + stops[i].b = colorStop->b; + stops[i].a = static_cast((colorStop->a * opacity) / 255); + stops[i].offset = colorStop->offset; + //check the offset corner cases - refer to: https://svgwg.org/svg2-draft/pservers.html#StopNotes + if (colorStop->offset < prevOffset) stops[i].offset = prevOffset; + else if (colorStop->offset > 1) stops[i].offset = 1; + prevOffset = stops[i].offset; + } + fillGrad->colorStops(stops, g->stops.count); + tvg::free(stops); + return fillGrad; +} + + +static RadialGradient* _applyRadialGradientProperty(SvgStyleGradient* g, const Box& vBox, int opacity) +{ + Fill::ColorStop *stops; + auto fillGrad = RadialGradient::gen(); + auto isTransform = (g->transform ? true : false); + auto& finalTransform = fillGrad->transform(); + if (isTransform) finalTransform = *g->transform; + + if (g->userSpace) { + //The radius scaling is done according to the Units section: + //https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html + g->radial->cx = g->radial->cx * vBox.w; + g->radial->cy = g->radial->cy * vBox.h; + g->radial->r = g->radial->r * sqrtf(powf(vBox.w, 2.0f) + powf(vBox.h, 2.0f)) / sqrtf(2.0f); + g->radial->fx = g->radial->fx * vBox.w; + g->radial->fy = g->radial->fy * vBox.h; + g->radial->fr = g->radial->fr * sqrtf(powf(vBox.w, 2.0f) + powf(vBox.h, 2.0f)) / sqrtf(2.0f); + } else { + Matrix m = {vBox.w, 0, vBox.x, 0, vBox.h, vBox.y, 0, 0, 1}; + if (isTransform) _transformMultiply(&m, &finalTransform); + else finalTransform = m; + } + + fillGrad->radial(g->radial->cx, g->radial->cy, g->radial->r, g->radial->fx, g->radial->fy, g->radial->fr); + fillGrad->spread(g->spread); + + //Update the stops + if (g->stops.count == 0) return fillGrad; + + stops = tvg::malloc(g->stops.count * sizeof(Fill::ColorStop)); + auto prevOffset = 0.0f; + for (uint32_t i = 0; i < g->stops.count; ++i) { + auto colorStop = &g->stops[i]; + //Use premultiplied color + stops[i].r = colorStop->r; + stops[i].g = colorStop->g; + stops[i].b = colorStop->b; + stops[i].a = static_cast((colorStop->a * opacity) / 255); + stops[i].offset = colorStop->offset; + //check the offset corner cases - refer to: https://svgwg.org/svg2-draft/pservers.html#StopNotes + if (colorStop->offset < prevOffset) stops[i].offset = prevOffset; + else if (colorStop->offset > 1) stops[i].offset = 1; + prevOffset = stops[i].offset; + } + fillGrad->colorStops(stops, g->stops.count); + tvg::free(stops); + return fillGrad; +} + + +static void _appendRect(Shape* shape, float x, float y, float w, float h, float rx, float ry) +{ + auto halfW = w * 0.5f; + auto halfH = h * 0.5f; + + //clamping cornerRadius by minimum size + if (rx > halfW) rx = halfW; + if (ry > halfH) ry = halfH; + + if (rx == 0 && ry == 0) { + to(shape)->grow(5, 4); + shape->moveTo(x, y); + shape->lineTo(x + w, y); + shape->lineTo(x + w, y + h); + shape->lineTo(x, y + h); + shape->close(); + } else { + auto hrx = rx * PATH_KAPPA; + auto hry = ry * PATH_KAPPA; + + to(shape)->grow(10, 17); + shape->moveTo(x + rx, y); + shape->lineTo(x + w - rx, y); + shape->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry); + shape->lineTo(x + w, y + h - ry); + shape->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h); + shape->lineTo(x + rx, y + h); + shape->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry); + shape->lineTo(x, y + ry); + shape->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y); + shape->close(); + } +} + + +static void _appendCircle(Shape* shape, float cx, float cy, float rx, float ry) +{ + auto rxKappa = rx * PATH_KAPPA; + auto ryKappa = ry * PATH_KAPPA; + + to(shape)->grow(6, 13); + shape->moveTo(cx + rx, cy); + shape->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry); + shape->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy); + shape->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry); + shape->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy); + shape->close(); +} + + +static bool _appendClipChild(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath) +{ + //The SVG standard allows only for 'use' nodes that point directly to a basic shape. + if (node->type == SvgNodeType::Use) { + if (node->child.count != 1) return false; + auto child = *(node->child.data); + auto finalTransform = tvg::identity(); + if (node->transform) finalTransform = *node->transform; + if (node->node.use.x != 0.0f || node->node.use.y != 0.0f) { + finalTransform *= {1, 0, node->node.use.x, 0, 1, node->node.use.y, 0, 0, 1}; + } + if (child->transform) finalTransform *= *child->transform; + + return _appendClipShape(loaderData, child, shape, vBox, svgPath, tvg::identity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform); + } + return _appendClipShape(loaderData, node, shape, vBox, svgPath, nullptr); +} + + +static Matrix _compositionTransform(Paint* paint, const SvgNode* node, const SvgNode* compNode, SvgNodeType type) +{ + auto m = tvg::identity(); + //The initial mask transformation ignored according to the SVG standard. + if (node->transform && type != SvgNodeType::Mask) { + m = *node->transform; + } + if (compNode->transform) { + m *= *compNode->transform; + } + if (!compNode->node.clip.userSpace) { + auto bbox = _bounds(paint); + m *= {bbox.w, 0, bbox.x, 0, bbox.h, bbox.y, 0, 0, 1}; + } + return m; +} + +static bool _applyClip(SvgLoaderData& loaderData, Paint* paint, const SvgNode* node, const SvgNode* clipNode, const Box& vBox, const string& svgPath) +{ + node->style->clipPath.applying = true; + + auto clipper = Shape::gen(); + auto valid = false; //Composite only when valid shapes exist + + ARRAY_FOREACH(p, clipNode->child) { + if (_appendClipChild(loaderData, *p, clipper, vBox, svgPath)) valid = true; + } + + if (valid) { + Matrix finalTransform = _compositionTransform(paint, node, clipNode, SvgNodeType::ClipPath); + clipper->transform(finalTransform); + paint->clip(clipper); + } else { + Paint::rel(clipper); + } + + node->style->clipPath.applying = false; + return valid; +} + + +static Paint* _applyComposition(SvgLoaderData& loaderData, Paint* paint, const SvgNode* node, const Box& vBox, const string& svgPath) +{ + if (node->style->clipPath.applying || node->style->mask.applying) { + TVGLOG("SVG", "Multiple composition tried! Check out circular dependency?"); + return paint; + } + + auto clipNode = node->style->clipPath.node; + auto maskNode = node->style->mask.node; + + if (!clipNode && !maskNode) return paint; + if ((clipNode && clipNode->child.empty()) || (maskNode && maskNode->child.empty())) { + Paint::rel(paint); + return nullptr; + } + + auto scene = Scene::gen(); + scene->add(paint); + + if (clipNode) { + if (!_applyClip(loaderData, scene, node, clipNode, vBox, svgPath)) { + Paint::rel(scene); + return nullptr; + } + } + + /* Mask */ + if (maskNode) { + node->style->mask.applying = true; + + if (auto mask = _sceneBuildHelper(loaderData, maskNode, vBox, svgPath, true, 0)) { + if (!maskNode->node.mask.userSpace) { + Matrix finalTransform = _compositionTransform(paint, node, maskNode, SvgNodeType::Mask); + mask->transform(finalTransform); + } else if (node->transform) { + mask->transform(*node->transform); + } + scene->mask(mask, maskNode->node.mask.type == SvgMaskType::Luminance ? MaskMethod::Luma: MaskMethod::Alpha); + } + + node->style->mask.applying = false; + } + + return scene; +} + + +static Paint* _applyFilter(SvgLoaderData& loaderData, Paint* paint, const SvgNode* node, const Box& vBox, const string& svgPath) +{ + auto filterNode = node->style->filter.node; + if (!filterNode || filterNode->child.count == 0) return paint; + auto& filter = filterNode->node.filter; + + auto scene = Scene::gen(); + + auto bbox = _bounds(paint); + Box clipBox = filter.filterUserSpace ? filter.box : Box{bbox.x + filter.box.x * bbox.w, bbox.y + filter.box.y * bbox.h, filter.box.w * bbox.w, filter.box.h * bbox.h}; + auto primitiveUserSpace = filter.primitiveUserSpace; + auto sx = paint->transform().e11; + auto sy = paint->transform().e22; + + auto child = filterNode->child.data; + for (uint32_t i = 0; i < filterNode->child.count; ++i, ++child) { + if ((*child)->type == SvgNodeType::GaussianBlur) { + auto& gauss = (*child)->node.gaussianBlur; + + auto direction = gauss.stdDevX > 0.0f ? (gauss.stdDevY > 0.0f ? 0 : 1) : (gauss.stdDevY > 0.0f ? 2 : -1); + if (direction == -1) continue; + + auto stdDevX = gauss.stdDevX; + auto stdDevY = gauss.stdDevY; + if (gauss.hasBox) { + auto gaussBox = gauss.box; + auto isPercent = gauss.isPercentage; + if (primitiveUserSpace) { + if (isPercent[0]) gaussBox.x *= loaderData.svgParse->global.w; + if (isPercent[1]) gaussBox.y *= loaderData.svgParse->global.h; + if (isPercent[2]) gaussBox.w *= loaderData.svgParse->global.w; + if (isPercent[3]) gaussBox.h *= loaderData.svgParse->global.h; + } else { + stdDevX *= bbox.w; + stdDevY *= bbox.h; + if (isPercent[0]) gaussBox.x = bbox.x + gauss.box.x * bbox.w; + if (isPercent[1]) gaussBox.y = bbox.y + gauss.box.y * bbox.h; + if (isPercent[2]) gaussBox.w *= bbox.w; + if (isPercent[3]) gaussBox.h *= bbox.h; + } + clipBox.intersect(gaussBox); + } else if (!primitiveUserSpace) { + stdDevX *= bbox.w; + stdDevY *= bbox.h; + } + scene->add(SceneEffect::GaussianBlur, (double)(1.25f * (direction == 2 ? stdDevY * sy : stdDevX * sx)), direction, gauss.edgeModeWrap, 55); + } + } + + scene->add(paint); + + auto clip = Shape::gen(); + clip->appendRect(clipBox.x, clipBox.y, clipBox.w, clipBox.h); + scene->clip(clip); + + return scene; +} + +static Paint* _applyProperty(SvgLoaderData& loaderData, SvgNode* node, Shape* vg, const Box& vBox, const string& svgPath, bool clip) +{ + SvgStyleProperty* style = node->style; + + //Clip transformation is applied directly to the path in the _appendClipShape function + if (node->type == SvgNodeType::Doc || !node->style->display) return vg; + + //If fill property is nullptr then do nothing + if (style->fill.paint.none) { + //Do nothing + } else if (style->fill.paint.gradient) { + auto bBox = style->fill.paint.gradient->userSpace ? vBox : _bounds(vg); + if (style->fill.paint.gradient->type == SvgGradientType::Linear) { + vg->fill(_applyLinearGradientProperty(style->fill.paint.gradient, bBox, style->fill.opacity)); + } else if (style->fill.paint.gradient->type == SvgGradientType::Radial) { + vg->fill(_applyRadialGradientProperty(style->fill.paint.gradient, bBox, style->fill.opacity)); + } + } else if (style->fill.paint.url) { + TVGLOG("SVG", "The fill's url not supported."); + } else if (style->fill.paint.curColor) { + //Apply the current style color + vg->fill(style->color.r, style->color.g, style->color.b, style->fill.opacity); + } else { + //Apply the fill color + vg->fill(style->fill.paint.color.r, style->fill.paint.color.g, style->fill.paint.color.b, style->fill.opacity); + } + + vg->fillRule(style->fill.fillRule); + vg->order(!style->paintOrder); + vg->opacity(style->opacity); + + if (node->type == SvgNodeType::G || node->type == SvgNodeType::Use) return vg; + + //Apply the stroke style property + vg->strokeWidth(style->stroke.width); + vg->strokeCap(style->stroke.cap); + vg->strokeJoin(style->stroke.join); + vg->strokeMiterlimit(style->stroke.miterlimit); + vg->strokeDash(style->stroke.dash.array.data, style->stroke.dash.array.count, style->stroke.dash.offset); + + //If stroke property is nullptr then do nothing + if (style->stroke.paint.none) { + vg->strokeWidth(0.0f); + } else if (style->stroke.paint.gradient) { + auto bBox = style->stroke.paint.gradient->userSpace ? vBox : _bounds(vg); + if (style->stroke.paint.gradient->type == SvgGradientType::Linear) { + vg->strokeFill(_applyLinearGradientProperty(style->stroke.paint.gradient, bBox, style->stroke.opacity)); + } else if (style->stroke.paint.gradient->type == SvgGradientType::Radial) { + vg->strokeFill(_applyRadialGradientProperty(style->stroke.paint.gradient, bBox, style->stroke.opacity)); + } + } else if (style->stroke.paint.url) { + //TODO: Apply the color pointed by url + TVGLOG("SVG", "The stroke's url not supported."); + } else if (style->stroke.paint.curColor) { + //Apply the current style color + vg->strokeFill(style->color.r, style->color.g, style->color.b, style->stroke.opacity); + } else { + //Apply the stroke color + vg->strokeFill(style->stroke.paint.color.r, style->stroke.paint.color.g, style->stroke.paint.color.b, style->stroke.opacity); + } + + //apply transform after the local space shape bbox for gradient acquisition + if (node->transform && !clip) vg->transform(*node->transform); + + auto p = _applyFilter(loaderData, vg, node, vBox, svgPath); + return _applyComposition(loaderData, p, node, vBox, svgPath); +} + + +static bool _recognizeShape(SvgNode* node, Shape* shape) +{ + switch (node->type) { + case SvgNodeType::Path: { + if (node->node.path.path) { + if (!svgPathToShape(node->node.path.path, to(shape)->rs.path)) { + TVGERR("SVG", "Invalid path information."); + return false; + } + } + break; + } + case SvgNodeType::Ellipse: { + _appendCircle(shape, node->node.ellipse.cx, node->node.ellipse.cy, node->node.ellipse.rx, node->node.ellipse.ry); + break; + } + case SvgNodeType::Polygon: { + if (node->node.polygon.pts.count < 2) break; + auto pts = node->node.polygon.pts.begin(); + shape->moveTo(pts[0], pts[1]); + for (pts += 2; pts < node->node.polygon.pts.end(); pts += 2) { + shape->lineTo(pts[0], pts[1]); + } + shape->close(); + break; + } + case SvgNodeType::Polyline: { + if (node->node.polyline.pts.count < 2) break; + auto pts = node->node.polyline.pts.begin(); + shape->moveTo(pts[0], pts[1]); + for (pts += 2; pts < node->node.polyline.pts.end(); pts += 2) { + shape->lineTo(pts[0], pts[1]); + } + break; + } + case SvgNodeType::Circle: { + _appendCircle(shape, node->node.circle.cx, node->node.circle.cy, node->node.circle.r, node->node.circle.r); + break; + } + case SvgNodeType::Rect: { + _appendRect(shape, node->node.rect.x, node->node.rect.y, node->node.rect.w, node->node.rect.h, node->node.rect.rx, node->node.rect.ry); + break; + } + case SvgNodeType::Line: { + shape->moveTo(node->node.line.x1, node->node.line.y1); + shape->lineTo(node->node.line.x2, node->node.line.y2); + break; + } + default: { + return false; + } + } + return true; +} + + +static Paint* _shapeBuildHelper(SvgLoaderData& loaderData, SvgNode* node, const Box& vBox, const string& svgPath) +{ + auto shape = Shape::gen(); + if (!_recognizeShape(node, shape)) return nullptr; + return _applyProperty(loaderData, node, shape, vBox, svgPath, false); +} + + +static bool _appendClipShape(SvgLoaderData& loaderData, SvgNode* node, Shape* shape, const Box& vBox, const string& svgPath, const Matrix* transform) +{ + uint32_t currentPtsCnt; + shape->path(nullptr, nullptr, nullptr, ¤tPtsCnt); + + if (!_recognizeShape(node, shape)) return false; + + //The 'transform' matrix has higher priority than the node->transform, since it already contains it + auto m = transform ? transform : (node->transform ? node->transform : nullptr); + + if (m) { + const Point *pts; + uint32_t ptsCnt; + shape->path(nullptr, nullptr, &pts, &ptsCnt); + auto p = const_cast(pts) + currentPtsCnt; + while (currentPtsCnt++ < ptsCnt) { + *p *= *m; + ++p; + } + } + + //Apply Clip Chaining + if (auto clipNode = node->style->clipPath.node) { + if (clipNode->child.count == 0) return false; + if (node->style->clipPath.applying) { + TVGLOG("SVG", "Multiple composition tried! Check out circular dependency?"); + return false; + } + return _applyClip(loaderData, shape, node, clipNode, vBox, svgPath); + } + + return true; +} + + +enum class imageMimeTypeEncoding +{ + base64 = 0x1, + utf8 = 0x2 +}; + + +constexpr imageMimeTypeEncoding operator|(imageMimeTypeEncoding a, imageMimeTypeEncoding b) { + return static_cast(static_cast(a) | static_cast(b)); +} + + +constexpr bool operator&(imageMimeTypeEncoding a, imageMimeTypeEncoding b) { + return (static_cast(a) & static_cast(b)); +} + + +static constexpr struct +{ + const char* name; + int sz; + imageMimeTypeEncoding encoding; +} imageMimeTypes[] = { + {"jpeg", sizeof("jpeg"), imageMimeTypeEncoding::base64}, + {"png", sizeof("png"), imageMimeTypeEncoding::base64}, + {"webp", sizeof("webp"), imageMimeTypeEncoding::base64}, + {"svg+xml", sizeof("svg+xml"), imageMimeTypeEncoding::base64 | imageMimeTypeEncoding::utf8}, +}; + + +static bool _isValidImageMimeTypeAndEncoding(const char** href, const char** mimetype, imageMimeTypeEncoding* encoding) { + if (strncmp(*href, "image/", sizeof("image/") - 1)) return false; //not allowed mime type + *href += sizeof("image/") - 1; + + //RFC2397 data:[][;base64], + //mediatype := [ type "/" subtype ] *( ";" parameter ) + //parameter := attribute "=" value + for (unsigned int i = 0; i < sizeof(imageMimeTypes) / sizeof(imageMimeTypes[0]); i++) { + if (strncmp(*href, imageMimeTypes[i].name, imageMimeTypes[i].sz - 1)) continue; + *href += imageMimeTypes[i].sz - 1; + *mimetype = imageMimeTypes[i].name; + + while (**href && **href != ',') { + while (**href && **href != ';') ++(*href); + if (!**href) return false; + ++(*href); + + if (imageMimeTypes[i].encoding & imageMimeTypeEncoding::base64) { + if (!strncmp(*href, "base64,", sizeof("base64,") - 1)) { + *href += sizeof("base64,") - 1; + *encoding = imageMimeTypeEncoding::base64; + return true; //valid base64 + } + } + if (imageMimeTypes[i].encoding & imageMimeTypeEncoding::utf8) { + if (!strncmp(*href, "utf8,", sizeof("utf8,") - 1)) { + *href += sizeof("utf8,") - 1; + *encoding = imageMimeTypeEncoding::utf8; + return true; //valid utf8 + } + } + } + //no encoding defined + if (**href == ',' && (imageMimeTypes[i].encoding & imageMimeTypeEncoding::utf8)) { + ++(*href); + *encoding = imageMimeTypeEncoding::utf8; + return true; //allow no encoding defined if utf8 expected + } + return false; + } + return false; +} + +#include "tvgTaskScheduler.h" + +static Paint* _imageBuildHelper(SvgLoaderData& loaderData, SvgNode* node, const Box& vBox, const string& svgPath) +{ + if (!node->node.image.href || !strlen(node->node.image.href)) return nullptr; + + auto picture = Picture::gen(); + + const char* href = node->node.image.href; + if (!strncmp(href, "data:", sizeof("data:") - 1)) { + href += sizeof("data:") - 1; + const char* mimetype; + imageMimeTypeEncoding encoding; + if (!_isValidImageMimeTypeAndEncoding(&href, &mimetype, &encoding)) return nullptr; //not allowed mime type or encoding + char *decoded = nullptr; + if (encoding == imageMimeTypeEncoding::base64) { + auto size = b64Decode(href, strlen(href), &decoded); + if (picture->load(decoded, size, mimetype) != Result::Success) { + tvg::free(decoded); + return nullptr; + } + } else { + auto size = svgUtilURLDecode(href, &decoded); + if (picture->load(decoded, size, mimetype) != Result::Success) { + tvg::free(decoded); + return nullptr; + } + } + loaderData.images.push(decoded); + } else { + if (!strncmp(href, "file://", sizeof("file://") - 1)) href += sizeof("file://") - 1; + //TODO: protect against recursive svg image loading + //Temporarily disable embedded svg: + const char *dot = strrchr(href, '.'); + if (dot && STR_AS(dot, ".svg")) { + TVGLOG("SVG", "Embedded svg file is disabled."); + return nullptr; + } + string imagePath = href; + if (strncmp(href, "/", 1)) { + auto last = svgPath.find_last_of("/"); + imagePath = svgPath.substr(0, (last == string::npos ? 0 : last + 1)) + imagePath; + } + if (picture->load(imagePath.c_str()) != Result::Success) { + return nullptr; + } + } + + float w, h; + Matrix m; + if (picture->size(&w, &h) == Result::Success && w > 0 && h > 0) { + auto sx = node->node.image.w / w; + auto sy = node->node.image.h / h; + m = {sx, 0, node->node.image.x, 0, sy, node->node.image.y, 0, 0, 1}; + } else { + m = tvg::identity(); + } + if (node->transform) m = *node->transform * m; + picture->transform(m); + + auto p = _applyFilter(loaderData, picture, node, vBox, svgPath); + return _applyComposition(loaderData, p, node, vBox, svgPath); +} + + +static Matrix _calculateAspectRatioMatrix(AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, float width, float height, const Box& box) +{ + auto sx = width / box.w; + auto sy = height / box.h; + auto tvx = box.x * sx; + auto tvy = box.y * sy; + + if (align == AspectRatioAlign::None) return {sx, 0, -tvx, 0, sy, -tvy, 0, 0, 1}; + + //Scale + if (meetOrSlice == AspectRatioMeetOrSlice::Meet) { + if (sx < sy) sy = sx; + else sx = sy; + } else { + if (sx < sy) sx = sy; + else sy = sx; + } + + //Align + tvx = box.x * sx; + tvy = box.y * sy; + auto tvw = box.w * sx; + auto tvh = box.h * sy; + + switch (align) { + case AspectRatioAlign::XMinYMin: { + break; + } + case AspectRatioAlign::XMidYMin: { + tvx -= (width - tvw) * 0.5f; + break; + } + case AspectRatioAlign::XMaxYMin: { + tvx -= width - tvw; + break; + } + case AspectRatioAlign::XMinYMid: { + tvy -= (height - tvh) * 0.5f; + break; + } + case AspectRatioAlign::XMidYMid: { + tvx -= (width - tvw) * 0.5f; + tvy -= (height - tvh) * 0.5f; + break; + } + case AspectRatioAlign::XMaxYMid: { + tvx -= width - tvw; + tvy -= (height - tvh) * 0.5f; + break; + } + case AspectRatioAlign::XMinYMax: { + tvy -= height - tvh; + break; + } + case AspectRatioAlign::XMidYMax: { + tvx -= (width - tvw) * 0.5f; + tvy -= height - tvh; + break; + } + case AspectRatioAlign::XMaxYMax: { + tvx -= width - tvw; + tvy -= height - tvh; + break; + } + default: { + break; + } + } + + return {sx, 0, -tvx, 0, sy, -tvy, 0, 0, 1}; +} + + +static Scene* _useBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath, int depth) +{ + auto scene = _sceneBuildHelper(loaderData, node, vBox, svgPath, false, depth + 1); + + // mUseTransform = mUseTransform * mTranslate + auto mUseTransform = tvg::identity(); + if (node->transform) mUseTransform = *node->transform; + if (node->node.use.x != 0.0f || node->node.use.y != 0.0f) { + Matrix mTranslate = {1, 0, node->node.use.x, 0, 1, node->node.use.y, 0, 0, 1}; + mUseTransform *= mTranslate; + } + + if (node->node.use.symbol) { + auto symbol = node->node.use.symbol->node.symbol; + auto width = (symbol.hasWidth ? symbol.w : vBox.w); + if (node->node.use.isWidthSet) width = node->node.use.w; + auto height = (symbol.hasHeight ? symbol.h : vBox.h);; + if (node->node.use.isHeightSet) height = node->node.use.h; + auto vw = (symbol.hasViewBox ? symbol.vw : width); + auto vh = (symbol.hasViewBox ? symbol.vh : height); + + auto mViewBox = tvg::identity(); + if ((!tvg::equal(width, vw) || !tvg::equal(height, vh)) && vw > 0 && vh > 0) { + Box box = {symbol.vx, symbol.vy, vw, vh}; + mViewBox = _calculateAspectRatioMatrix(symbol.align, symbol.meetOrSlice, width, height, box); + } else if (!tvg::zero(symbol.vx) || !tvg::zero(symbol.vy)) { + mViewBox = {1, 0, -symbol.vx, 0, 1, -symbol.vy, 0, 0, 1}; + } + + // mSceneTransform = mUseTransform * mSymbolTransform * mViewBox + Matrix mSceneTransform = mViewBox; + if (node->node.use.symbol->transform) { + mSceneTransform = *node->node.use.symbol->transform * mViewBox; + } + mSceneTransform = mUseTransform * mSceneTransform; + scene->transform(mSceneTransform); + + if (!node->node.use.symbol->node.symbol.overflowVisible) { + auto viewBoxClip = Shape::gen(); + viewBoxClip->appendRect(0, 0, width, height); + + // mClipTransform = mUseTransform * mSymbolTransform + Matrix mClipTransform = mUseTransform; + if (node->node.use.symbol->transform) { + mClipTransform = mUseTransform * *node->node.use.symbol->transform; + } + viewBoxClip->transform(mClipTransform); + + auto clippingLayer = Scene::gen(); + clippingLayer->clip(viewBoxClip); + clippingLayer->add(scene); + return clippingLayer; + } + return scene; + } + + if (auto clipper = PAINT(scene)->clipper) { + auto& clipTransform = clipper->transform(); + Matrix inv; + if (node->transform && inverse(node->transform, &inv)) clipTransform = inv * clipTransform; + clipTransform = mUseTransform * clipTransform ; + } + + scene->transform(mUseTransform); + return scene; +} + + +static void _applyTextFill(SvgStyleProperty* style, Text* text, const Box& vBox) +{ + //If fill property is nullptr then do nothing + if (style->fill.paint.none) { + //Do nothing + } else if (style->fill.paint.gradient) { + auto bBox = style->fill.paint.gradient->userSpace ? vBox : _bounds(text); + if (style->fill.paint.gradient->type == SvgGradientType::Linear) { + text->fill(_applyLinearGradientProperty(style->fill.paint.gradient, bBox, style->fill.opacity)); + } else if (style->fill.paint.gradient->type == SvgGradientType::Radial) { + text->fill(_applyRadialGradientProperty(style->fill.paint.gradient, bBox, style->fill.opacity)); + } + } else if (style->fill.paint.url) { + //TODO: Apply the color pointed by url + TVGLOG("SVG", "The fill's url not supported."); + } else if (style->fill.paint.curColor) { + //Apply the current style color + text->fill(style->color.r, style->color.g, style->color.b); + text->opacity(style->fill.opacity); + } else { + //Apply the fill color + text->fill(style->fill.paint.color.r, style->fill.paint.color.g, style->fill.paint.color.b); + text->opacity(style->fill.opacity); + } +} + + +static char* _processText(const char* text, SvgXmlSpace space) +{ + if (!text) return nullptr; + + auto len = strlen(text); + auto processed = (char*)tvg::malloc(len + 1); + auto dst = processed; + auto src = text; + + if (space == SvgXmlSpace::Preserve) { + while (*src) { + if (*src == '\n' || *src == '\t' || *src == '\r') *dst++ = ' '; + else *dst++ = *src; + src++; + } + *dst = '\0'; + } else { + auto spaceFound = false; + src = svgUtilSkipWhiteSpace(src, nullptr); + + while (*src) { + if (isspace((unsigned char)*src)) { + if (!spaceFound) { + *dst++ = ' '; + spaceFound = true; + } + } else { + *dst++ = *src; + spaceFound = false; + } + src++; + } + dst = (char*)svgUtilUnskipWhiteSpace(dst, processed); + *dst = '\0'; + } + return processed; +} + + +static Paint* _textBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath) +{ + auto textNode = &node->node.text; + if (!textNode->text) return nullptr; + + auto text = Text::gen(); + + Matrix textTransform; + if (node->transform) textTransform = *node->transform; + else textTransform = tvg::identity(); + + translateR(&textTransform, {node->node.text.x, node->node.text.y - textNode->fontSize}); + text->transform(textTransform); + + //TODO: handle def values of font and size as used in a system? + auto size = textNode->fontSize * 0.75f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75 + if (text->font(textNode->fontFamily) != Result::Success) { + text->font(nullptr); //fallback to any available font + } + text->size(size); + + // Handle xml:space + auto xmlSpace = node->xmlSpace; + auto parent = node->parent; + while (xmlSpace == SvgXmlSpace::None && parent) { + xmlSpace = parent->xmlSpace; + parent = parent->parent; + } + if (xmlSpace == SvgXmlSpace::None) xmlSpace = SvgXmlSpace::Default; + auto processedText = _processText(textNode->text, xmlSpace); + text->text(processedText); + tvg::free(processedText); + + _applyTextFill(node->style, text, vBox); + + auto p = _applyFilter(loaderData, text, node, vBox, svgPath); + return _applyComposition(loaderData, p, node, vBox, svgPath); +} + + +static Scene* _sceneBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, const Box& vBox, const string& svgPath, bool mask, int depth) +{ + /* Exception handling: Prevent invalid SVG data input. + The size is the arbitrary value, we need an experimental size. */ + if (depth > 2192) { + TVGERR("SVG", "Infinite recursive call - stopped after %d calls! Svg file may be incorrectly formatted.", depth); + return nullptr; + } + + if (!_isGroupType(node->type) && !mask) return nullptr; + + auto scene = Scene::gen(); + // For a Symbol node, the viewBox transformation has to be applied first - see _useBuildHelper() + if (!mask && node->transform && node->type != SvgNodeType::Symbol && node->type != SvgNodeType::Use) { + scene->transform(*node->transform); + } + + if (!node->style->display || node->style->opacity == 0) return scene; + + ARRAY_FOREACH(p, node->child) { + auto child = *p; + if (_isGroupType(child->type)) { + if (child->type == SvgNodeType::Use) + scene->add(_useBuildHelper(loaderData, child, vBox, svgPath, depth + 1)); + else if (!(child->type == SvgNodeType::Symbol && node->type != SvgNodeType::Use)) + scene->add(_sceneBuildHelper(loaderData, child, vBox, svgPath, false, depth + 1)); + if (child->id) scene->id = djb2Encode(child->id); + } else { + Paint* paint = nullptr; + if (child->type == SvgNodeType::Image) paint = _imageBuildHelper(loaderData, child, vBox, svgPath); + else if (child->type == SvgNodeType::Text) paint = _textBuildHelper(loaderData, child, vBox, svgPath); + else if (child->type != SvgNodeType::Mask) paint = _shapeBuildHelper(loaderData, child, vBox, svgPath); + if (paint) { + if (child->id) paint->id = djb2Encode(child->id); + scene->add(paint); + } + } + } + scene->opacity(node->style->opacity); + + auto p = _applyFilter(loaderData, scene, node, vBox, svgPath); + return static_cast(_applyComposition(loaderData, p, node, vBox, svgPath)); +} + + +static void _updateInvalidViewSize(Scene* scene, Box& vBox, float& w, float& h, SvgViewFlag viewFlag) +{ + auto useW = (viewFlag & SvgViewFlag::Width); + auto useH = (viewFlag & SvgViewFlag::Height); + auto bbox = _bounds(scene); + + if (!useW && !useH) { + vBox = bbox; + } else { + vBox.w = useW ? w : bbox.w; + vBox.h = useH ? h : bbox.h; + } + + //the size would have 1x1 or percentage values. + if (!useW) w *= vBox.w; + if (!useH) h *= vBox.h; +} + + +static void _loadFonts(Array& fonts) +{ + if (fonts.empty()) return; + + static constexpr struct { + const char* prefix; + size_t len; + } prefixes[] = { + {"data:font/ttf;base64,", sizeof("data:font/ttf;base64,") - 1}, + {"data:application/font-ttf;base64,", sizeof("data:application/font-ttf;base64,") - 1} + }; + + + ARRAY_FOREACH(p, fonts) { + if (!p->name) continue; + + size_t shift = 0; + for (const auto& prefix : prefixes) { + if (p->srcLen > prefix.len && !memcmp(p->src, prefix.prefix, prefix.len)) { + shift = prefix.len; + break; + } + } + if (shift == 0) { + TVGLOG("SVG", "The embedded font \"%s\" data not loaded properly.", p->name); + continue; + } + + auto size = b64Decode(p->src + shift, p->srcLen - shift, &p->decoded); + + if (Text::load(p->name, p->decoded, size) != Result::Success) TVGERR("SVG", "Error while loading the ttf font named \"%s\".", p->name); + } +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +Scene* svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, float h, AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, const string& svgPath, SvgViewFlag viewFlag) +{ + //TODO: aspect ratio is valid only if viewBox was set + + if (!loaderData.doc || (loaderData.doc->type != SvgNodeType::Doc)) return nullptr; + + _loadFonts(loaderData.fonts); + + auto docNode = _sceneBuildHelper(loaderData, loaderData.doc, vBox, svgPath, false, 0); + + if (!(viewFlag & SvgViewFlag::Viewbox)) _updateInvalidViewSize(docNode, vBox, w, h, viewFlag); + + if (!tvg::equal(w, vBox.w) || !tvg::equal(h, vBox.h)) { + Matrix m = _calculateAspectRatioMatrix(align, meetOrSlice, w, h, vBox); + docNode->transform(m); + } else if (!tvg::zero(vBox.x) || !tvg::zero(vBox.y)) { + docNode->translate(-vBox.x, -vBox.y); + } + + auto viewBoxClip = Shape::gen(); + viewBoxClip->appendRect(0, 0, w, h); + + auto clippingLayer = Scene::gen(); + clippingLayer->clip(viewBoxClip); + clippingLayer->add(docNode); + + loaderData.doc->node.doc.vbox = vBox; + loaderData.doc->node.doc.w = w; + loaderData.doc->node.doc.h = h; + + auto root = Scene::gen(); + root->add(clippingLayer); + + return root; +} diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgSceneBuilder.h b/components/thorvg-main/src/loaders/svg/tvgSvgSceneBuilder.h new file mode 100644 index 0000000..17d08a1 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgSceneBuilder.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SVG_SCENE_BUILDER_H_ +#define _TVG_SVG_SCENE_BUILDER_H_ + +#include "tvgCommon.h" + +Scene* svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, float h, AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, const string& svgPath, SvgViewFlag viewFlag); + +#endif //_TVG_SVG_SCENE_BUILDER_H_ diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgUtil.cpp b/components/thorvg-main/src/loaders/svg/tvgSvgUtil.cpp new file mode 100644 index 0000000..5b9efd5 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgUtil.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgSvgUtil.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static uint8_t _hexCharToDec(const char c) +{ + if (c >= 'a') return c - 'a' + 10; + else if (c >= 'A') return c - 'A' + 10; + else return c - '0'; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +const char* svgUtilSkipWhiteSpace(const char* itr, const char* itrEnd) +{ + while ((itrEnd && itr < itrEnd) || (!itrEnd && *itr != '\0')) { + if (!isspace((unsigned char)*itr)) break; + itr++; + } + return itr; +} + + +const char* svgUtilUnskipWhiteSpace(const char* itr, const char* itrStart) +{ + for (itr--; itr > itrStart; itr--) { + if (!isspace((unsigned char)*itr)) break; + } + return itr + 1; +} + + +const char* svgUtilSkipWhiteSpaceAndComma(const char* content) +{ + content = svgUtilSkipWhiteSpace(content, nullptr); + if (*content == ',') return content + 1; + return content; +} + + +size_t svgUtilURLDecode(const char *src, char** dst) +{ + if (!src) return 0; + + auto length = strlen(src); + if (length == 0) return 0; + + char* decoded = tvg::malloc(sizeof(char) * length + 1); + + char a, b; + int idx =0; + while (*src) { + if (*src == '%' && + ((a = src[1]) && (b = src[2])) && + (isxdigit(a) && isxdigit(b))) { + decoded[idx++] = (_hexCharToDec(a) << 4) + _hexCharToDec(b); + src+=3; + } else if (*src == '+') { + decoded[idx++] = ' '; + src++; + } else { + decoded[idx++] = *src++; + } + } + decoded[idx] = '\0'; + + *dst = decoded; + return idx + 1; +} + diff --git a/components/thorvg-main/src/loaders/svg/tvgSvgUtil.h b/components/thorvg-main/src/loaders/svg/tvgSvgUtil.h new file mode 100644 index 0000000..0a34f46 --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgSvgUtil.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SVG_UTIL_H_ +#define _TVG_SVG_UTIL_H_ + +#include "tvgCommon.h" + +const char* svgUtilSkipWhiteSpace(const char* itr, const char* itrEnd); +const char* svgUtilUnskipWhiteSpace(const char* itr, const char* itrStart); +const char* svgUtilSkipWhiteSpaceAndComma(const char* content); +size_t svgUtilURLDecode(const char *src, char** dst); + +#endif //_TVG_SVG_UTIL_H_ diff --git a/components/thorvg-main/src/loaders/svg/tvgXmlParser.cpp b/components/thorvg-main/src/loaders/svg/tvgXmlParser.cpp new file mode 100644 index 0000000..f67aa0f --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgXmlParser.cpp @@ -0,0 +1,562 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgStr.h" +#include "tvgXmlParser.h" +#include "tvgSvgUtil.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +bool _unsupported(TVG_UNUSED const char* tagAttribute, TVG_UNUSED const char* tagValue) +{ +#ifdef THORVG_LOG_ENABLED + const auto attributesNum = 6; + const struct + { + const char* tag; + bool tagWildcard; //If true, it is assumed that a wildcard is used after the tag. (ex: tagName*) + const char* value; + } attributes[] = { + {"id", false, nullptr}, + {"data-name", false, nullptr}, + {"overflow", false, "visible"}, + {"version", false, nullptr}, + {"xmlns", true, nullptr}, + {"xml:space", false, nullptr}, + }; + + for (unsigned int i = 0; i < attributesNum; ++i) { + if (tvg::equal(tagAttribute, attributes[i].tag)) { + if (!attributes[i].value) return false; + if (tvg::equal(tagValue, attributes[i].value)) return false; + } + } + return true; +#endif + return false; +} + + +static const char* _xmlFindWhiteSpace(const char* itr, const char* itrEnd) +{ + for (; itr < itrEnd; itr++) { + if (isspace((unsigned char)*itr)) break; + } + return itr; +} + + +static const char* _xmlSkipXmlEntities(const char* itr, const char* itrEnd) +{ + auto p = itr; + while (itr < itrEnd && *itr == '&') { + for (int i = 0; i < NUMBER_OF_XML_ENTITIES; ++i) { + if (strncmp(itr, xmlEntity[i], xmlEntityLength[i]) == 0) { + itr += xmlEntityLength[i]; + break; + } + } + if (itr == p) break; + p = itr; + } + return itr; +} + + +static const char* _xmlUnskipXmlEntities(const char* itr, const char* itrStart) +{ + auto p = itr; + while (itr > itrStart && *(itr - 1) == ';') { + for (int i = 0; i < NUMBER_OF_XML_ENTITIES; ++i) { + if (itr - xmlEntityLength[i] > itrStart && + strncmp(itr - xmlEntityLength[i], xmlEntity[i], xmlEntityLength[i]) == 0) { + itr -= xmlEntityLength[i]; + break; + } + } + if (itr == p) break; + p = itr; + } + return itr; +} + + +static const char* _skipWhiteSpacesAndXmlEntities(const char* itr, const char* itrEnd) +{ + itr = svgUtilSkipWhiteSpace(itr, itrEnd); + auto p = itr; + while (true) { + if (p != (itr = _xmlSkipXmlEntities(itr, itrEnd))) p = itr; + else break; + if (p != (itr = svgUtilSkipWhiteSpace(itr, itrEnd))) p = itr; + else break; + } + return itr; +} + + +static const char* _unskipWhiteSpacesAndXmlEntities(const char* itr, const char* itrStart) +{ + itr = svgUtilUnskipWhiteSpace(itr, itrStart); + auto p = itr; + while (true) { + if (p != (itr = _xmlUnskipXmlEntities(itr, itrStart))) p = itr; + else break; + if (p != (itr = svgUtilUnskipWhiteSpace(itr, itrStart))) p = itr; + else break; + } + return itr; +} + + +static const char* _xmlFindStartTag(const char* itr, const char* itrEnd) +{ + return (const char*)memchr(itr, '<', itrEnd - itr); +} + + +static const char* _xmlFindEndTag(const char* itr, const char* itrEnd) +{ + bool insideQuote[2] = {false, false}; // 0: ", 1: ' + for (; itr < itrEnd; itr++) { + if (*itr == '"' && !insideQuote[1]) insideQuote[0] = !insideQuote[0]; + if (*itr == '\'' && !insideQuote[0]) insideQuote[1] = !insideQuote[1]; + if (!insideQuote[0] && !insideQuote[1]) { + if ((*itr == '>') || (*itr == '<')) + return itr; + } + } + return nullptr; +} + + +static const char* _xmlFindEndCommentTag(const char* itr, const char* itrEnd) +{ + for (; itr < itrEnd; itr++) { + if ((*itr == '-') && ((itr + 1 < itrEnd) && (*(itr + 1) == '-')) && ((itr + 2 < itrEnd) && (*(itr + 2) == '>'))) return itr + 2; + } + return nullptr; +} + + +static const char* _xmlFindEndCdataTag(const char* itr, const char* itrEnd) +{ + for (; itr < itrEnd; itr++) { + if ((*itr == ']') && ((itr + 1 < itrEnd) && (*(itr + 1) == ']')) && ((itr + 2 < itrEnd) && (*(itr + 2) == '>'))) return itr + 2; + } + return nullptr; +} + + +static const char* _xmlFindDoctypeChildEndTag(const char* itr, const char* itrEnd) +{ + for (; itr < itrEnd; itr++) { + if (*itr == '>') return itr; + } + return nullptr; +} + + +static XMLType _getXMLType(const char* itr, const char* itrEnd, size_t &toff) +{ + toff = 0; + if (itr[1] == '/') { + toff = 1; + return XMLType::Close; + } else if (itr[1] == '?') { + toff = 1; + return XMLType::Processing; + } else if (itr[1] == '!') { + if ((itr + sizeof("") - 1 < itrEnd) && (!memcmp(itr + 2, "DOCTYPE", sizeof("DOCTYPE") - 1)) && ((itr[2 + sizeof("DOCTYPE") - 1] == '>') || (isspace((unsigned char)itr[2 + sizeof("DOCTYPE") - 1])))) { + toff = sizeof("!DOCTYPE") - 1; + return XMLType::Doctype; + } else if ((itr + sizeof("") - 1 < itrEnd) && (!memcmp(itr + 2, "[CDATA[", sizeof("[CDATA[") - 1))) { + toff = sizeof("![CDATA[") - 1; + return XMLType::CData; + } else if ((itr + sizeof("") - 1 < itrEnd) && (!memcmp(itr + 2, "--", sizeof("--") - 1))) { + toff = sizeof("!--") - 1; + return XMLType::Comment; + } else if (itr + sizeof("") - 1 < itrEnd) { + toff = sizeof("!") - 1; + return XMLType::DoctypeChild; + } + return XMLType::Open; + } + return XMLType::Open; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +const char* xmlNodeTypeToString(TVG_UNUSED SvgNodeType type) +{ +#ifdef THORVG_LOG_ENABLED + static const char* TYPE_NAMES[] = { + "Svg", + "G", + "Defs", + "Animation", + "Arc", + "Circle", + "Ellipse", + "Image", + "Line", + "Path", + "Polygon", + "Polyline", + "Rect", + "Text", + "TextArea", + "Tspan", + "Use", + "Video", + "ClipPath", + "Mask", + "Symbol", + "Filter", + "GaussianBlur", + "Unknown", + }; + return TYPE_NAMES[(int) type]; +#endif + return nullptr; +} + + +bool isIgnoreUnsupportedLogElements(TVG_UNUSED const char* tagName) +{ +#ifdef THORVG_LOG_ENABLED + const auto elementsNum = 1; + const char* const elements[] = { "title" }; + + for (unsigned int i = 0; i < elementsNum; ++i) { + if (!strncmp(tagName, elements[i], strlen(tagName))) { + return true; + } + } + return false; +#else + return true; +#endif +} + + +bool xmlParseAttributes(const char* buf, unsigned bufLength, xmlAttributeCb func, const void* data) +{ + const char *itr = buf, *itrEnd = buf + bufLength; + char* tmpBuf = tvg::malloc(bufLength + 1); + + if (!buf || !func || !tmpBuf) goto error; + + while (itr < itrEnd) { + const char* p = _skipWhiteSpacesAndXmlEntities(itr, itrEnd); + const char *key, *keyEnd, *value, *valueEnd; + char* tval; + + if (p == itrEnd) goto success; + + key = p; + for (keyEnd = key; keyEnd < itrEnd; keyEnd++) { + if ((*keyEnd == '=') || (isspace((unsigned char)*keyEnd))) break; + } + if (keyEnd == itrEnd) goto error; + if (keyEnd == key) { // There is no key. This case is invalid, but explores the following syntax. + itr = keyEnd + 1; + continue; + } + + if (*keyEnd == '=') value = keyEnd + 1; + else { + value = (const char*)memchr(keyEnd, '=', itrEnd - keyEnd); + if (!value) goto error; + value++; + } + keyEnd = _xmlUnskipXmlEntities(keyEnd, key); + + value = _skipWhiteSpacesAndXmlEntities(value, itrEnd); + if (value == itrEnd) goto error; + + if ((*value == '"') || (*value == '\'')) { + valueEnd = (const char*)memchr(value + 1, *value, itrEnd - value); + if (!valueEnd) goto error; + value++; + } else { + valueEnd = _xmlFindWhiteSpace(value, itrEnd); + } + + itr = valueEnd + 1; + + value = _skipWhiteSpacesAndXmlEntities(value, itrEnd); + valueEnd = _unskipWhiteSpacesAndXmlEntities(valueEnd, value); + + memcpy(tmpBuf, key, keyEnd - key); + tmpBuf[keyEnd - key] = '\0'; + + tval = tmpBuf + (keyEnd - key) + 1; + int i = 0; + while (value < valueEnd) { + value = _xmlSkipXmlEntities(value, valueEnd); + tval[i++] = *value; + value++; + } + tval[i] = '\0'; + + if (!func((void*)data, tmpBuf, tval)) { + if (_unsupported(tmpBuf, tval)) { + TVGLOG("SVG", "Unsupported attributes used [Elements type: %s][Id : %s][Attribute: %s][Value: %s]", xmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type), ((SvgLoaderData*)data)->svgParse->node->id ? ((SvgLoaderData*)data)->svgParse->node->id : "NO_ID", tmpBuf, tval ? tval : "NONE"); + } + } + } + +success: + tvg::free(tmpBuf); + return true; + +error: + tvg::free(tmpBuf); + return false; +} + + +bool xmlParse(const char* buf, unsigned bufLength, bool strip, xmlCb func, const void* data) +{ + const char *itr = buf, *itrEnd = buf + bufLength; + + while (itr < itrEnd) { + if (itr[0] == '<') { + //Invalid case + if (itr + 1 >= itrEnd) return false; + + size_t toff = 0; + XMLType type = _getXMLType(itr, itrEnd, toff); + + const char* p; + if (type == XMLType::CData) p = _xmlFindEndCdataTag(itr + 1 + toff, itrEnd); + else if (type == XMLType::DoctypeChild) p = _xmlFindDoctypeChildEndTag(itr + 1 + toff, itrEnd); + else if (type == XMLType::Comment) p = _xmlFindEndCommentTag(itr + 1 + toff, itrEnd); + else p = _xmlFindEndTag(itr + 1 + toff, itrEnd); + + if (p) { + //Invalid case: '<' nested + if (*p == '<' && type != XMLType::Doctype) return false; + const char *start, *end; + + start = itr + 1 + toff; + end = p; + + switch (type) { + case XMLType::Open: { + if (p[-1] == '/') { + type = XMLType::OpenEmpty; + end--; + } + break; + } + case XMLType::CData: { + if (!memcmp(p - 2, "]]", 2)) end -= 2; + break; + } + case XMLType::Processing: { + if (p[-1] == '?') end--; + break; + } + case XMLType::Comment: { + if (!memcmp(p - 2, "--", 2)) end -= 2; + break; + } + default: { + break; + } + } + + if (strip && (type != XMLType::CData)) { + start = _skipWhiteSpacesAndXmlEntities(start, end); + end = _unskipWhiteSpacesAndXmlEntities(end, start); + } + + if (!func((void*)data, type, start, (unsigned int)(end - start))) return false; + + itr = p + 1; + } else { + return false; + } + } else { + const char *p, *end; + + if (strip && ((SvgLoaderData*)data)->openedTag != OpenedTagType::Text) { + p = itr; + p = _skipWhiteSpacesAndXmlEntities(p, itrEnd); + if (p) { + if (!func((void*)data, XMLType::Ignored, itr, (unsigned int)(p - itr))) return false; + itr = p; + } + } + + p = _xmlFindStartTag(itr, itrEnd); + if (!p) p = itrEnd; + + end = p; + if (strip && ((SvgLoaderData*)data)->openedTag != OpenedTagType::Text) end = _unskipWhiteSpacesAndXmlEntities(end, itr); + + if (itr != end && !func((void*)data, XMLType::Data, itr, (unsigned int)(end - itr))) return false; + + if (strip && (end < p) && !func((void*)data, XMLType::Ignored, end, (unsigned int)(p - end))) return false; + + itr = p; + } + } + return true; +} + + +bool xmlParseW3CAttribute(const char* buf, unsigned bufLength, xmlAttributeCb func, const void* data) +{ + if (!buf) return false; + + const auto end = buf + bufLength; + if (buf == end) return true; + + auto kmem = tvg::malloc(end - buf + 1); + auto vmem = tvg::malloc(end - buf + 1); + auto key = kmem; + auto val = vmem; + + do { + auto sep = (char*)strchr(buf, ':'); + auto next = (char*)strchr(buf, ';'); + + if (auto src = strstr(buf, "src")) {//src tag from css font-face contains extra semicolon + if (src < sep) { + if (next + 1 < end) next = (char*)strchr(next + 1, ';'); + else break; + } + } + + if (sep >= end) next = sep = nullptr; + if (next >= end) next = nullptr; + + key[0] = '\0'; + val[0] = '\0'; + + if (sep != nullptr && next == nullptr) { + memcpy(key, buf, sep - buf); + key[sep - buf] = '\0'; + + memcpy(val, sep + 1, end - sep - 1); + val[end - sep - 1] = '\0'; + } else if (sep != nullptr && sep < next) { + memcpy(key, buf, sep - buf); + key[sep - buf] = '\0'; + + memcpy(val, sep + 1, next - sep - 1); + val[next - sep - 1] = '\0'; + } else if (next) { + memcpy(key, buf, next - buf); + key[next - buf] = '\0'; + } + if (key[0]) { + key = const_cast(svgUtilSkipWhiteSpace(key, key + strlen(key))); + key[svgUtilUnskipWhiteSpace(key + strlen(key) , key) - key] = '\0'; + val = const_cast(svgUtilSkipWhiteSpace(val, val + strlen(val))); + val[svgUtilUnskipWhiteSpace(val + strlen(val) , val) - val] = '\0'; + + if (!func((void*)data, key, val)) { + if (!_unsupported(key, val)) { + TVGLOG("SVG", "Unsupported attributes used [Elements type: %s][Id : %s][Attribute: %s][Value: %s]", xmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type), ((SvgLoaderData*)data)->svgParse->node->id ? ((SvgLoaderData*)data)->svgParse->node->id : "NO_ID", key, val ? val : "NONE"); + } + } + } + if (!next) break; + buf = next + 1; + } while (true); + + tvg::free(kmem); + tvg::free(vmem); + + return true; +} + + +/* + * Supported formats: + * tag {}, .name {}, tag.name{} + */ +const char* xmlParseCSSAttribute(const char* buf, unsigned bufLength, char** tag, char** name, const char** attrs, unsigned* attrsLength) +{ + if (!buf) return nullptr; + + *tag = *name = nullptr; + *attrsLength = 0; + + auto itr = svgUtilSkipWhiteSpace(buf, buf + bufLength); + auto itrEnd = (const char*)memchr(buf, '{', bufLength); + + if (!itrEnd || itr == itrEnd) return nullptr; + + auto nextElement = (const char*)memchr(itrEnd, '}', bufLength - (itrEnd - buf)); + if (!nextElement) return nullptr; + + *attrs = itrEnd + 1; + *attrsLength = nextElement - *attrs; + + const char *p; + + itrEnd = svgUtilUnskipWhiteSpace(itrEnd, itr); + if (*(itrEnd - 1) == '.') return nullptr; + + for (p = itr; p < itrEnd; p++) { + if (*p == '.') break; + } + + if (p == itr) *tag = duplicate("all"); + else *tag = duplicate(itr, p - itr); + + if (p == itrEnd) *name = nullptr; + else *name = duplicate(p + 1, itrEnd - p - 1); + + return (nextElement ? nextElement + 1 : nullptr); +} + + +const char* xmlFindAttributesTag(const char* buf, unsigned bufLength) +{ + const char *itr = buf, *itrEnd = buf + bufLength; + + for (; itr < itrEnd; itr++) { + if (!isspace((unsigned char)*itr)) { + //User skip tagname and already gave it the attributes. + if (*itr == '=') return buf; + } else { + itr = _xmlUnskipXmlEntities(itr, buf); + if (itr == itrEnd) return nullptr; + return itr; + } + } + + return nullptr; +} diff --git a/components/thorvg-main/src/loaders/svg/tvgXmlParser.h b/components/thorvg-main/src/loaders/svg/tvgXmlParser.h new file mode 100644 index 0000000..c85431b --- /dev/null +++ b/components/thorvg-main/src/loaders/svg/tvgXmlParser.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_XML_PARSER_H_ +#define _TVG_XML_PARSER_H_ + +#include "tvgSvgLoaderCommon.h" + +#define NUMBER_OF_XML_ENTITIES 9 +const char* const xmlEntity[] = {" ", """, " ", "'", "&", "<", ">", "#", "'"}; +const int xmlEntityLength[] = {5, 6, 6, 6, 5, 4, 4, 6, 6}; + +enum class XMLType +{ + Open = 0, //!< \ + OpenEmpty, //!< \ + Close, //!< \ + Data, //!< tag text data + CData, //!< \ + Error, //!< error contents + Processing, //!< \ \ + Doctype, //!< \ + Ignored, //!< whatever is ignored by parser, like whitespace + DoctypeChild //!< \ + #include + #include + #include +#endif + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define SPACE_GLYPH_IDX 1 +#define LINE_FEED_GLYPH_IDX 10 +#define DOT_GLYPH_IDX 46 + + +#ifdef THORVG_FILE_IO_SUPPORT + +#if defined(_WIN32) && (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) + +static bool _map(TtfLoader* loader, const string& path) +{ + auto& reader = loader->reader; + + auto file = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (file == INVALID_HANDLE_VALUE) return false; + + DWORD high; + auto low = GetFileSize(file, &high); + if (low == INVALID_FILE_SIZE) { + CloseHandle(file); + return false; + } + + reader.size = (uint32_t)((size_t)high << (8 * sizeof(DWORD)) | low); + + loader->mapping = (uint8_t*)CreateFileMapping(file, NULL, PAGE_READONLY, high, low, NULL); + + CloseHandle(file); + + if (!loader->mapping) return false; + + loader->reader.data = (uint8_t*) MapViewOfFile(loader->mapping, FILE_MAP_READ, 0, 0, 0); + if (!loader->reader.data) { + CloseHandle(loader->mapping); + loader->mapping = nullptr; + return false; + } + return true; +} + +static void _unmap(TtfLoader* loader) +{ + auto& reader = loader->reader; + + if (reader.data) { + UnmapViewOfFile(reader.data); + reader.data = nullptr; + } + if (loader->mapping) { + CloseHandle(loader->mapping); + loader->mapping = nullptr; + } +} + +#elif defined(__linux__) + +static bool _map(TtfLoader* loader, const char* path) +{ + auto& reader = loader->reader; + + auto fd = open(path, O_RDONLY); + if (fd < 0) return false; + + struct stat info; + if (fstat(fd, &info) < 0) { + close(fd); + return false; + } + + reader.data = (uint8_t*)mmap(NULL, (size_t) info.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (reader.data == (uint8_t*)-1) return false; + reader.size = (uint32_t) info.st_size; + close(fd); + + return true; +} + + +static void _unmap(TtfLoader* loader) +{ + auto& reader = loader->reader; + if (reader.data == (uint8_t*) -1) return; + munmap((void *) reader.data, reader.size); + reader.data = (uint8_t*)-1; + reader.size = 0; +} +#else +static bool _map(TtfLoader* loader, const char* path) +{ + auto& reader = loader->reader; + + auto f = fopen(path, "rb"); + if (!f) return false; + + fseek(f, 0, SEEK_END); + + reader.size = ftell(f); + if (reader.size == 0) { + fclose(f); + return false; + } + + reader.data = tvg::malloc(reader.size); + + fseek(f, 0, SEEK_SET); + auto ret = fread(reader.data, sizeof(char), reader.size, f); + if (ret < reader.size) { + fclose(f); + return false; + } + + fclose(f); + + return true; +} + + +static void _unmap(TtfLoader* loader) +{ + auto& reader = loader->reader; + tvg::free(reader.data); + reader.data = nullptr; + reader.size = 0; +} +#endif + +#endif //THORVG_FILE_IO_SUPPORT + + +static size_t _codepoints(char** utf8) +{ + auto p = *utf8; + + if (!(*p & 0x80U)) { + (*utf8) += 1; + return *p; + } else if ((*p & 0xe0U) == 0xc0U) { + (*utf8) += 2; + return ((*p & 0x1fU) << 6) + (*(p + 1) & 0x3fU); + } else if ((*p & 0xf0U) == 0xe0U) { + (*utf8) += 3; + return ((*p & 0x0fU) << 12) + ((*(p + 1) & 0x3fU) << 6) + (*(p + 2) & 0x3fU); + } else if ((*p & 0xf8U) == 0xf0U) { + (*utf8) += 4; + return ((*p & 0x07U) << 18) + ((*(p + 1) & 0x3fU) << 12) + ((*(p + 2) & 0x3fU) << 6) + (*(p + 3) & 0x3fU); + } + //error case + (*utf8) += 1; + return 0; +} + + +static void _build(const RenderPath& in, const Point& cursor, const Point& kerning, RenderPath& out) +{ + out.cmds.push(in.cmds); + out.pts.grow(in.pts.count); + ARRAY_FOREACH(p, in.pts) { + out.pts.push(*p + cursor + kerning); + } +} + + +static void _align(const Point& align, const Point& box, const Point& cursor, uint32_t begin, uint32_t end, RenderPath& out) +{ + if (align.x > 0.0f || align.y > 0.0f) { + auto shift = (box - cursor) * align; + for (auto p = out.pts.data + begin; p < out.pts.data + end; p++) { + *p += shift; + } + } +} + + +static void _alignX(float align, float box, float x, uint32_t begin, uint32_t end, RenderPath& out) +{ + if (align > 0.0f) { + auto shift = (box - x) * align; + for (auto p = out.pts.data + begin; p < out.pts.data + end; p++) { + p->x += shift; + } + } +} + + +static void _alignY(float align, float box, float y, uint32_t begin, uint32_t end, RenderPath& out) +{ + if (align > 0.0f) { + auto shift = (box - y) * align; + for (auto p = out.pts.data + begin; p < out.pts.data + end; p++) { + p->y += shift; + } + } +} + + +uint32_t TtfLoader::feedLine(FontMetrics& fm, float box, float x, uint32_t begin, uint32_t end, Point& cursor, uint32_t& loc, RenderPath& out) +{ + _alignX(fm.align.x, box, x, begin, end, out); //align the given line + cursor.x = 0.0f; + cursor.y += reader.metrics.hhea.advance * fm.spacing.y; + ++loc; + return out.pts.count; +} + + +void TtfLoader::clear() +{ + if (nomap) { + if (freeData) tvg::free(reader.data); + reader.data = nullptr; + reader.size = 0; + freeData = false; + nomap = false; + } else { +#ifdef THORVG_FILE_IO_SUPPORT + _unmap(this); +#endif + } + + tvg::free(name); + name = nullptr; +} + + +TtfGlyphMetrics* TtfLoader::request(uint32_t code) +{ + if (code == 0) return nullptr; + + auto it = glyphs.find(code); + if (it == glyphs.end()) { + auto it = glyphs.emplace(code, TtfGlyphMetrics{}).first; + auto rtgm = &it->second; + if (!reader.convert(rtgm->path, *rtgm, reader.glyph(code, rtgm), {0.0f, 0.0f}, 1U)) { + TVGERR("TTF", "invalid glyph id, codepoint(0x%x)", code); + glyphs.erase(it); + return nullptr; + } + return rtgm; + } + return &it->second; +} + + +void TtfLoader::wrapNone(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out) +{ + TtfGlyphMetrics* ltgm = nullptr; //left side glyph between the two adjacent glyphs + Point cursor = {}; + uint32_t line = 0; //the begin pos of the last line among path + uint32_t loc = 1; //line counter + + while (*utf8) { + auto code = _codepoints(&utf8); + if (code == LINE_FEED_GLYPH_IDX) { + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + continue; + } + auto rtgm = request(code); //right side glyph between the two adjacent glyphs + if (!rtgm) continue; + + Point kerning{}; + if (ltgm) reader.kerning(ltgm->idx, rtgm->idx, kerning); + + _build(rtgm->path, cursor, kerning, out); + cursor.x += (rtgm->advance + kerning.x) * fm.spacing.x; + + if (cursor.x > fm.size.x) fm.size.x = cursor.x; //text horizontal size + + //store the base glyph width for italic transform + if (!ltgm && rtgm->w > 0.0f) static_cast(fm.engine)->baseWidth = rtgm->w; + ltgm = rtgm; + + } + fm.size.y = height(loc, fm.spacing.y); + _alignY(fm.align.y, box.y, fm.size.y, 0, line, out); //before the last line + _align(fm.align, box, {cursor.x, fm.size.y}, line, out.pts.count, out); //last line +} + + +void TtfLoader::wrapChar(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out) +{ + TtfGlyphMetrics* ltgm = nullptr; //left side glyph between the two adjacent glyphs + uint32_t line = 0; //the begin pos of the last line among path + uint32_t loc = 1; //line counter + Point cursor = {}; + + while (*utf8) { + auto code = _codepoints(&utf8); + if (code == LINE_FEED_GLYPH_IDX) { + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + continue; + } + auto rtgm = request(code); //right side glyph between the two adjacent glyphs + if (!rtgm) continue; + + Point kerning{}; + if (ltgm) reader.kerning(ltgm->idx, rtgm->idx, kerning); + + auto xadv = (rtgm->advance + kerning.x) * fm.spacing.x; + + //normal scenario + if (xadv < box.x) { + if (cursor.x + xadv > box.x) { + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + } + _build(rtgm->path, cursor, kerning, out); + cursor.x += xadv; + //not enough layout space, force pushing + } else { + _build(rtgm->path, cursor, kerning, out); + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + } + + if (cursor.x > fm.size.x) fm.size.x = cursor.x; //text horizontal size + + //store the base glyph width for italic transform + if (!ltgm && rtgm->w > 0.0f) static_cast(fm.engine)->baseWidth = rtgm->w; + ltgm = rtgm; + } + fm.size.y = height(loc, fm.spacing.y); + _alignY(fm.align.y, box.y, fm.size.y, 0, line, out); //before the last line + _align(fm.align, box, {cursor.x, fm.size.y}, line, out.pts.count, out); //last line +} + + +void TtfLoader::wrapWord(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out, bool smart) +{ + TtfGlyphMetrics* ltgm = nullptr; //left side glyph between the two adjacent glyphs + auto line = 0; //the begin pos of the last line among path + auto word = 0; //the begin pos of the last word among path + auto wadv = 0.0f; //word advance size + auto hadv = reader.metrics.hhea.advance * fm.spacing.y; //line advance size + uint32_t loc = 1; //line counter + Point cursor = {}; + + while (*utf8) { + auto code = _codepoints(&utf8); + if (code == LINE_FEED_GLYPH_IDX) { + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + continue; + } + auto rtgm = request(code); //right side glyph between the two adjacent glyphs + if (!rtgm) continue; + + Point kerning{}; + if (ltgm) reader.kerning(ltgm->idx, rtgm->idx, kerning); + + auto xadv = (rtgm->advance + kerning.x) * fm.spacing.x; + + //try line-wrap + if (cursor.x + xadv > box.x) { + //wrapping only if enough space for the current word + if ((cursor.x - wadv) + xadv < box.x) { + _alignX(fm.align.x, box.x, wadv, line, word, out); //align the current line + //shift the wrapping word to the next line + for (auto p = out.pts.begin() + word; p < out.pts.end(); p++) { + p->x -= wadv; + p->y += hadv; + } + cursor.x -= wadv; + cursor.y += hadv; + line = word; + wadv = 0; + ++loc; + //not enough space, line wrap by character + } else if (smart) { + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + } + } + _build(rtgm->path, cursor, kerning, out); + cursor.x += xadv; + + //capture the word start + if (rtgm->idx == SPACE_GLYPH_IDX) { + word = out.pts.count; + wadv = cursor.x; + } + + if (cursor.x > fm.size.x) fm.size.x = cursor.x; //text horizontal size + + //store the base glyph width for italic transform + if (!ltgm && rtgm->w > 0.0f) static_cast(fm.engine)->baseWidth = rtgm->w; + ltgm = rtgm; + } + fm.size.y = height(loc, fm.spacing.y); + _alignY(fm.align.y, box.y, fm.size.y, 0, line, out); //before the last line + _align(fm.align, box, {cursor.x, fm.size.y}, line, out.pts.count, out); //last line +} + + +void TtfLoader::wrapEllipsis(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out) +{ + TtfGlyphMetrics* ltgm = nullptr; //left side glyph between the two adjacent glyphs + auto line = 0; //the begin pos of the last line among path + Point cursor = {}; + struct { + uint32_t pts = 0; + uint32_t cmds = 0; + float xadv = 0.0f; + } capture; //the last path for reverting the last character if the ... space is not enough + uint32_t loc = 1; //line counter + auto stop = false; + + while (*utf8) { + auto code = _codepoints(&utf8); + if (code == LINE_FEED_GLYPH_IDX) { + line = feedLine(fm, box.x, cursor.x, line, out.pts.count, cursor, loc, out); + continue; + } + auto rtgm = request(code); //right side glyph between the two adjacent glyphs + if (!rtgm) continue; + + Point kerning{}; + if (ltgm) reader.kerning(ltgm->idx, rtgm->idx, kerning); + + auto xadv = (rtgm->advance + kerning.x) * fm.spacing.x; + + //normal case + if (cursor.x + xadv < box.x) { + capture = {out.pts.count, out.cmds.count, xadv}; + _build(rtgm->path, cursor, kerning, out); + cursor.x += xadv; + //ellipsis + } else { + rtgm = request(DOT_GLYPH_IDX); //right side glyph between the two adjacent glyphs + if (!rtgm) { + TVGERR("TTF", "Cannot support ... since no glyph data"); + return; + } + kerning = {}; + reader.kerning(rtgm->idx, rtgm->idx, kerning); + //not enough space, revert one character back + if (cursor.x + (rtgm->advance + kerning.x) * 3 > box.x) { + out.pts.count = capture.pts; + out.cmds.count = capture.cmds; + cursor.x -= capture.xadv; + } + //append ... + auto tmp = (rtgm->advance + kerning.x) * fm.spacing.x; + for (int i = 0; i < 3; ++i) { + _build(rtgm->path, cursor, kerning, out); + cursor.x += tmp; + } + stop = true; + } + + if (cursor.x > fm.size.x) fm.size.x = cursor.x; //text horizontal size + + //store the base glyph width for italic transform + if (!ltgm && rtgm->w > 0.0f) static_cast(fm.engine)->baseWidth = rtgm->w; + + if (stop) break; //stop the process if the ellipsis is applied + + ltgm = rtgm; + } + fm.size.y = height(loc, fm.spacing.y); + _alignY(fm.align.y, box.y, fm.size.y, 0, line, out); //before the last line + _align(fm.align, box, {cursor.x, fm.size.y}, line, out.pts.count, out); //last line +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +void TtfLoader::transform(Paint* paint, FontMetrics& fm, float italicShear) +{ + auto scale = 1.0f / fm.scale; + Matrix m = {scale, -italicShear * scale, italicShear * static_cast(fm.engine)->baseWidth * scale, 0, scale, reader.metrics.hhea.ascent * scale, 0, 0, 1}; + paint->transform(m); +} + + +TtfLoader::TtfLoader() : FontLoader(FileType::Ttf) +{ +} + + +TtfLoader::~TtfLoader() +{ + clear(); +} + + +bool TtfLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + clear(); + if (!_map(this, path)) return false; + + name = tvg::filename(path); + + return reader.header(); +#else + return false; +#endif +} + + +bool TtfLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + reader.size = size; + nomap = true; + + if (copy) { + reader.data = tvg::malloc(size); + if (!reader.data) return false; + memcpy((char*)reader.data, data, reader.size); + freeData = true; + } else reader.data = (uint8_t*)data; + + return reader.header(); +} + + +bool TtfLoader::get(FontMetrics& fm, char* text, RenderPath& out) +{ + constexpr const auto DPI = 96.0f / 72.0f; //dpi base? + + out.clear(); + + if (!text || fm.fontSize == 0.0f) return false; + + fm.scale = reader.metrics.unitsPerEm / (fm.fontSize * DPI); + fm.size = {}; + if (!fm.engine) fm.engine = tvg::calloc(1, sizeof(TtfMetrics)); + + auto box = fm.box * fm.scale; + + if (fm.wrap == TextWrap::None || fm.box.x == 0.0f) wrapNone(fm, box, text, out); + else if (fm.wrap == TextWrap::Character) wrapChar(fm, box, text, out); + else if (fm.wrap == TextWrap::Word) wrapWord(fm, box, text, out, false); + else if (fm.wrap == TextWrap::Smart) wrapWord(fm, box, text, out, true); + else if (fm.wrap == TextWrap::Ellipsis) wrapEllipsis(fm, box, text, out); + else return false; + + return true; +} + + +void TtfLoader::release(FontMetrics& fm) +{ + tvg::free(fm.engine); + fm.engine = nullptr; +} + + +void TtfLoader::copy(const FontMetrics& in, FontMetrics& out) +{ + release(out); + out = in; + if (in.engine) out.engine = tvg::calloc(1, sizeof(TtfMetrics)); + *static_cast(out.engine) = *static_cast(in.engine); +} diff --git a/components/thorvg-main/src/loaders/ttf/tvgTtfLoader.h b/components/thorvg-main/src/loaders/ttf/tvgTtfLoader.h new file mode 100644 index 0000000..20f1db5 --- /dev/null +++ b/components/thorvg-main/src/loaders/ttf/tvgTtfLoader.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef _TVG_TTF_LOADER_H_ +#define _TVG_TTF_LOADER_H_ + +#include +#include "tvgLoader.h" +#include "tvgTaskScheduler.h" +#include "tvgTtfReader.h" + +using namespace std; + + +struct TtfMetrics : FontMetrics +{ + float baseWidth; //Use as the reference glyph width for italic transform +}; + + +struct TtfLoader : public FontLoader +{ +#if defined(_WIN32) && (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) + void* mapping = nullptr; +#endif + TtfReader reader; + unordered_map glyphs; //glypha cache. key: codepoint + char* text = nullptr; + bool nomap = false; + bool freeData = false; + + TtfLoader(); + ~TtfLoader(); + + using FontLoader::open; + using FontLoader::read; + + bool open(const char* path) override; + bool open(const char *data, uint32_t size, const char* rpath, bool copy) override; + void transform(Paint* paint, FontMetrics& fm, float italicShear) override; + bool get(FontMetrics& fm, char* text, RenderPath& out) override; + void copy(const FontMetrics& in, FontMetrics& out) override; + void release(FontMetrics& fm) override; + +private: + float height(uint32_t loc, float spacing) + { + return (reader.metrics.hhea.advance * loc - reader.metrics.hhea.lineGap) * spacing; + } + + uint32_t feedLine(FontMetrics& fm, float box, float x, uint32_t begin, uint32_t end, Point& cursor, uint32_t& loc, RenderPath& out); + void wrapNone(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out); + void wrapChar(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out); + void wrapWord(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out, bool smart); + void wrapEllipsis(FontMetrics& fm, const Point& box, char* utf8, RenderPath& out); + TtfGlyphMetrics* request(uint32_t code); + void clear(); +}; + +#endif //_TVG_PNG_LOADER_H_ diff --git a/components/thorvg-main/src/loaders/ttf/tvgTtfReader.cpp b/components/thorvg-main/src/loaders/ttf/tvgTtfReader.cpp new file mode 100644 index 0000000..a11efe2 --- /dev/null +++ b/components/thorvg-main/src/loaders/ttf/tvgTtfReader.cpp @@ -0,0 +1,625 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgTtfReader.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + + +static inline uint32_t _u32(uint8_t* data, uint32_t offset) +{ + auto base = data + offset; + return (base[0] << 24 | base[1] << 16 | base[2] << 8 | base[3]); +} + + +static inline uint16_t _u16(uint8_t* data, uint32_t offset) +{ + auto base = data + offset; + return (base[0] << 8 | base[1]); +} + + +static inline int16_t _i16(uint8_t* data, uint32_t offset) +{ + return (int16_t) _u16(data, offset); +} + + +static inline uint8_t _u8(uint8_t* data, uint32_t offset) +{ + return *(data + offset); +} + + +static inline int8_t _i8(uint8_t* data, uint32_t offset) +{ + return (int8_t) _u8(data, offset); +} + + +static int _cmpu32(const void *a, const void *b) +{ + return memcmp(a, b, 4); +} + + +bool TtfReader::validate(uint32_t offset, uint32_t margin) const +{ + if ((offset > size) || (size - offset < margin)) { + TVGERR("TTF", "Invalidate data"); + return false; + } + return true; +} + + +uint32_t TtfReader::table(const char* tag) +{ + auto tableCnt = _u16(data, 4); + if (!validate(12, (uint32_t) tableCnt * 16)) return 0; + + auto match = bsearch(tag, data + 12, tableCnt, 16, _cmpu32); + if (!match) { + TVGLOG("TTF", "No searching table = %s", tag); + return 0; + } + + return _u32(data, (uint32_t) ((uint8_t*) match - data + 8)); +} + + +uint32_t TtfReader::cmap_12_13(uint32_t table, uint32_t codepoint, int fmt) const +{ + //A minimal header is 16 bytes + auto len = _u32(data, table + 4); + if (len < 16) return -1; + + if (!validate(table, len)) return -1; + + auto entryCnt = _u32(data, table + 12); + + for (uint32_t i = 0; i < entryCnt; ++i) { + auto firstCode = _u32(data, table + (i * 12) + 16); + auto lastCode = _u32(data, table + (i * 12) + 16 + 4); + if (codepoint < firstCode || codepoint > lastCode) continue; + auto glyphOffset = _u32(data, table + (i * 12) + 16 + 8); + if (fmt == 12) return (codepoint - firstCode) + glyphOffset; + else return glyphOffset; + } + return -1; +} + + +uint32_t TtfReader::cmap_4(uint32_t table, uint32_t codepoint) const +{ + //cmap format 4 only supports the Unicode BMP. + if (codepoint > 0xffff) return -1; + + auto shortCode = static_cast(codepoint); + + if (!validate(table, 8)) return -1; + + auto segmentCnt = _u16(data, table); + if ((segmentCnt & 1) || segmentCnt == 0) return -1; + + //find starting positions of the relevant arrays. + auto endCodes = table + 8; + auto startCodes = endCodes + segmentCnt + 2; + auto idDeltas = startCodes + segmentCnt; + auto idRangeOffsets = idDeltas + segmentCnt; + + if (!validate(idRangeOffsets, segmentCnt)) return -1; + + //find the segment that contains shortCode by binary searching over the highest codes in the segments. + //binary search, but returns the next highest element if key could not be found. + uint8_t* segment = nullptr; + auto n = segmentCnt / 2; + if (n > 0) { + uint8_t key[2] = {(uint8_t)(codepoint >> 8), (uint8_t)codepoint}; + auto bytes = data + endCodes; + auto low = 0; + auto high = n - 1; + while (low != high) { + auto mid = low + (high - low) / 2; + auto sample = bytes + mid * 2; + if (memcmp(key, sample, 2) > 0) { + low = mid + 1; + } else { + high = mid; + } + } + segment = (bytes + low * 2); + } + + auto segmentIdx = static_cast(segment - (data + endCodes)); + + //look up segment info from the arrays & short circuit if the spec requires. + auto startCode = _u16(data, startCodes + segmentIdx); + if (startCode > shortCode) return 0; + + auto delta = _u16(data, idDeltas + segmentIdx); + auto idRangeOffset = _u16(data, idRangeOffsets + segmentIdx); + //intentional integer under- and overflow. + if (idRangeOffset == 0) return (shortCode + delta) & 0xffff; + + //calculate offset into glyph array and determine ultimate value. + auto offset = idRangeOffsets + segmentIdx + idRangeOffset + 2U * (unsigned int)(shortCode - startCode); + if (!validate(offset, 2)) return -1; + + auto id = _u16(data, offset); + //intentional integer under- and overflow. + if (id > 0) return (id + delta) & 0xffff; + + return 0; +} + + +uint32_t TtfReader::cmap_6(uint32_t table, uint32_t codepoint) const +{ + //cmap format 6 only supports the Unicode BMP. + if (codepoint > 0xFFFF) return 0; + + auto firstCode = _u16(data, table); + auto entryCnt = _u16(data, table + 2); + if (!validate(table, 4 + 2 * entryCnt)) return -1; + + if (codepoint < firstCode) return -1; + codepoint -= firstCode; + if (codepoint >= entryCnt) return -1; + return _u16(data, table + 4 + 2 * codepoint); +} + + +//Returns the offset into the font that the glyph's outline is stored at +uint32_t TtfReader::outlineOffset(uint32_t glyph) +{ + uint32_t cur, next; + + auto loca = this->loca.load(); + if (loca == 0) this->loca = loca = table("loca"); + + auto glyf = this->glyf.load(); + if (glyf == 0) this->glyf = glyf = table("glyf"); + + if (metrics.locaFormat == 0) { + auto base = loca + 2 * glyph; + if (!validate(base, 4)) { + TVGERR("TTF", "invalid outline offset"); + return 0; + } + cur = 2U * (uint32_t) _u16(data, base); + next = 2U * (uint32_t) _u16(data, base + 2); + } else { + auto base = loca + 4 * glyph; + if (!validate(base, 8)) return 0; + cur = _u32(data, base); + next = _u32(data, base + 4); + } + if (cur == next) return 0; + return glyf + cur; +} + + +bool TtfReader::points(uint32_t outline, uint8_t* flags, Point* pts, uint32_t ptsCnt, const Point& offset) +{ + #define X_CHANGE_IS_SMALL 0x02 + #define X_CHANGE_IS_POSITIVE 0x10 + #define X_CHANGE_IS_ZERO 0x10 + #define Y_CHANGE_IS_SMALL 0x04 + #define Y_CHANGE_IS_ZERO 0x20 + #define Y_CHANGE_IS_POSITIVE 0x20 + + long accum = 0L; + + for (uint32_t i = 0; i < ptsCnt; ++i) { + if (flags[i] & X_CHANGE_IS_SMALL) { + if (!validate(outline, 1)) { + return false; + } + auto value = (long) _u8(data, outline++); + auto bit = (uint8_t)!!(flags[i] & X_CHANGE_IS_POSITIVE); + accum -= (value ^ -bit) + bit; + } else if (!(flags[i] & X_CHANGE_IS_ZERO)) { + if (!validate(outline, 2)) return false; + accum += _i16(data, outline); + outline += 2; + } + pts[i].x = offset.x + (float) accum; + } + + accum = 0L; + + for (uint32_t i = 0; i < ptsCnt; ++i) { + if (flags[i] & Y_CHANGE_IS_SMALL) { + if (!validate(outline, 1)) return false; + auto value = (long) _u8(data, outline++); + auto bit = (uint8_t)!!(flags[i] & Y_CHANGE_IS_POSITIVE); + accum -= (value ^ -bit) + bit; + } else if (!(flags[i] & Y_CHANGE_IS_ZERO)) { + if (!validate(outline, 2)) return false; + accum += _i16(data, outline); + outline += 2; + } + pts[i].y = offset.y - (float) accum; + } + return true; +} + + +bool TtfReader::flags(uint32_t *outline, uint8_t* flags, uint32_t flagsCnt) +{ + #define REPEAT_FLAG 0x08 + + auto offset = *outline; + uint8_t value = 0; + uint8_t repeat = 0; + + for (uint32_t i = 0; i < flagsCnt; ++i) { + if (repeat) { + --repeat; + } else { + if (!validate(offset, 1)) return false; + value = _u8(data, offset++); + if (value & REPEAT_FLAG) { + if (!validate(offset, 1)) return false; + repeat = _u8(data, offset++); + } + } + flags[i] = value; + } + *outline = offset; + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +bool TtfReader::header() +{ + if (!validate(0, 12)) return false; + + //verify ttf(scalable font) + auto type = _u32(data, 0); + if (type != 0x00010000 && type != 0x74727565) return false; + + //header + auto head = table("head"); + if (!validate(head, 54)) return false; + + metrics.unitsPerEm = _u16(data, head + 18); + metrics.locaFormat = _u16(data, head + 50); + + //horizontal metrics + auto hhea = table("hhea"); + if (!validate(hhea, 36)) return false; + + metrics.hhea.ascent = _i16(data, hhea + 4); + metrics.hhea.descent = _i16(data, hhea + 6); + metrics.hhea.lineGap = _i16(data, hhea + 8); + metrics.hhea.advance = metrics.hhea.ascent - metrics.hhea.descent + metrics.hhea.lineGap; + metrics.numHmtx = _u16(data, hhea + 34); + + //kerning + auto kern = this->kern = table("kern"); + if (kern) { + if (!validate(kern, 4)) return false; + if (_u16(data, kern) != 0) return false; + } + + return true; +} + + +uint32_t TtfReader::glyph(uint32_t codepoint) +{ + auto cmap = this->cmap.load(); + if (cmap == 0) { + this->cmap = cmap = table("cmap"); + if (!validate(cmap, 4)) return -1; + } + + auto entryCnt = _u16(data, cmap + 2); + if (!validate(cmap, 4 + entryCnt * 8)) return -1; + + //full repertory (non-BMP map). + for (auto idx = 0; idx < entryCnt; ++idx) { + auto entry = cmap + 4 + idx * 8; + auto type = _u16(data, entry) * 0100 + _u16(data, entry + 2); + //unicode map + if (type == 0004 || type == 0312) { + auto table = cmap + _u32(data, entry + 4); + if (!validate(table, 8)) return -1; + //dispatch based on cmap format. + auto format = _u16(data, table); + switch (format) { + case 12: return cmap_12_13(table, codepoint, 12); + default: return -1; + } + } + } + + //Try looking for a BMP map. + for (auto idx = 0; idx < entryCnt; ++idx) { + auto entry = cmap + 4 + idx * 8; + auto type = _u16(data, entry) * 0100 + _u16(data, entry + 2); + //Unicode BMP + if (type == 0003 || type == 0301) { + auto table = cmap + _u32(data, entry + 4); + if (!validate(table, 6)) return -1; + //Dispatch based on cmap format. + switch (_u16(data, table)) { + case 4: return cmap_4(table + 6, codepoint); + case 6: return cmap_6(table + 6, codepoint); + default: return -1; + } + } + } + return -1; +} + + +uint32_t TtfReader::glyph(uint32_t codepoint, TtfGlyphMetrics* tgm) +{ + tgm->idx = glyph(codepoint); + if (tgm->idx == INVALID_GLYPH) return 0; + return glyphMetrics(*tgm); +} + + +uint32_t TtfReader::glyphMetrics(TtfGlyph& glyph) +{ + //horizontal metrics + auto hmtx = this->hmtx.load(); + if (hmtx == 0) this->hmtx = hmtx = table("hmtx"); + + //glyph is inside long metrics segment. + if (glyph.idx < metrics.numHmtx) { + auto offset = hmtx + 4 * glyph.idx; + if (!validate(offset, 4)) return 0; + glyph.advance = _u16(data, offset); + glyph.lsb = _i16(data, offset + 2); + /* glyph is inside short metrics segment. */ + } else { + auto boundary = hmtx + 4U * (uint32_t) metrics.numHmtx; + if (boundary < 4) return 0; + + auto offset = boundary - 4; + if (!validate(offset, 4)) return 0; + glyph.advance = _u16(data, offset); + offset = boundary + 2 * (glyph.idx - metrics.numHmtx); + if (!validate(offset, 2)) return 0; + glyph.lsb = _i16(data, offset); + } + + auto glyphOffset = outlineOffset(glyph.idx); + // glyph without outline + if (glyphOffset == 0) { + glyph.y = glyph.w = glyph.h = 0.0f; + return 0; + } + if (!validate(glyphOffset, 10)) return 0; + + //read the bounding box from the font file verbatim. + float bbox[4]; + bbox[0] = static_cast(_i16(data, glyphOffset + 2)); + bbox[1] = static_cast(_i16(data, glyphOffset + 4)); + bbox[2] = static_cast(_i16(data, glyphOffset + 6)); + bbox[3] = static_cast(_i16(data, glyphOffset + 8)); + + glyph.w = bbox[2] - bbox[0] + 1; + glyph.h = bbox[3] - bbox[1] + 1; + glyph.y = bbox[3]; + + return glyphOffset; +} + + +bool TtfReader::convert(RenderPath& path, TtfGlyph& glyph, uint32_t glyphOffset, const Point& offset, uint16_t depth) +{ + #define ON_CURVE 0x01 + + if (glyphOffset == 0) return true; + + auto outlineCnt = _i16(data, glyphOffset); + if (outlineCnt == 0) return false; + if (outlineCnt < 0) { + uint16_t maxComponentDepth = 1U; + auto maxp = this->maxp.load(); + if (maxp == 0) this->maxp = maxp = table("maxp"); + if (validate(maxp, 32) && _u32(data, maxp) >= 0x00010000U) { // >= version 1.0 + maxComponentDepth = _u16(data, maxp + 30); + } + if (depth > maxComponentDepth) return false; + return convertComposite(path, glyph, glyphOffset, offset, depth + 1); + } + auto cntrsCnt = (uint32_t) outlineCnt; + auto outline = glyphOffset + 10; + if (!validate(outline, cntrsCnt * 2 + 2)) return false; + + auto ret = false; + auto ptsCnt = _u16(data, outline + (cntrsCnt - 1) * 2) + 1; + auto endPts = tvg::malloc(cntrsCnt * sizeof(size_t)); //the index of the contour points. + + for (uint32_t i = 0; i < cntrsCnt; ++i) { + endPts[i] = (uint32_t) _u16(data, outline); + outline += 2; + } + outline += 2U + _u16(data, outline); + + auto flags = tvg::malloc(ptsCnt * sizeof(uint8_t)); + if (this->flags(&outline, flags, ptsCnt)) { + auto pts = tvg::malloc(ptsCnt * sizeof(Point)); + if (this->points(outline, flags, pts, ptsCnt, offset)) { + //generate tvg paths + path.cmds.reserve(ptsCnt); + path.pts.reserve(ptsCnt); + uint32_t begin = 0; + for (uint32_t i = 0; i < cntrsCnt; ++i) { + //contour must start with move to + auto offCurve = !(flags[begin] & ON_CURVE); + auto ptsBegin = offCurve ? (pts[begin] + pts[endPts[i]]) * 0.5f : pts[begin]; + path.moveTo(ptsBegin); + auto cnt = endPts[i] - begin + 1; + for (uint32_t x = 1; x < cnt; ++x) { + if (flags[begin + x] & ON_CURVE) { + if (offCurve) { + path.cubicTo(path.pts.last() + (2.0f/3.0f) * (pts[begin + x - 1] - path.pts.last()), pts[begin + x] + (2.0f/3.0f) * (pts[begin + x - 1] - pts[begin + x]), pts[begin + x]); + offCurve = false; + } else { + path.lineTo(pts[begin + x]); + } + } else { + if (offCurve) { + auto end = (pts[begin + x] + pts[begin + x - 1]) * 0.5f; + path.cubicTo(path.pts.last() + (2.0f/3.0f) * (pts[begin + x - 1] - path.pts.last()), end + (2.0f/3.0f) * (pts[begin + x - 1] - end), end); + } else { + offCurve = true; + } + } + } + if (offCurve) { + path.cubicTo(path.pts.last() + (2.0f/3.0f) * (pts[begin + cnt - 1] - path.pts.last()), ptsBegin + (2.0f/3.0f) * (pts[begin + cnt - 1] - ptsBegin), ptsBegin); + } + //contour must end with close + path.close(); + begin = endPts[i] + 1; + } + ret = true; + } + tvg::free(pts); + } + tvg::free(flags); + tvg::free(endPts); + return ret; +} + + +bool TtfReader::convertComposite(RenderPath& path, TtfGlyph& glyph, uint32_t glyphOffset, const Point& offset, uint16_t depth) +{ + #define ARG_1_AND_2_ARE_WORDS 0x0001 + #define ARGS_ARE_XY_VALUES 0x0002 + #define WE_HAVE_A_SCALE 0x0008 + #define MORE_COMPONENTS 0x0020 + #define WE_HAVE_AN_X_AND_Y_SCALE 0x0040 + #define WE_HAVE_A_TWO_BY_TWO 0x0080 + + TtfGlyph compGlyph; + Point compOffset; + uint16_t flags; + auto pointer = glyphOffset + 10; + do { + if (!validate(pointer, 4)) return false; + flags = _u16(data, pointer); + compGlyph.idx = _u16(data, pointer + 2U); + if (compGlyph.idx == INVALID_GLYPH) continue; + pointer += 4U; + if (flags & ARG_1_AND_2_ARE_WORDS) { + if (!validate(pointer, 4)) return false; + // TODO: align to parent point + compOffset = (flags & ARGS_ARE_XY_VALUES) ? Point{float(_i16(data, pointer)), -float(_i16(data, pointer + 2U))} : Point{0.0f, 0.0f}; + pointer += 4U; + } else { + if (!validate(pointer, 2)) return false; + // TODO: align to parent point + compOffset = (flags & ARGS_ARE_XY_VALUES) ? Point{float(_i8(data, pointer)), -float(_i8(data, pointer + 1U))} : Point{0.0f, 0.0f}; + pointer += 2U; + } + if (flags & WE_HAVE_A_SCALE) { + if (!validate(pointer, 2)) return false; + // TODO transformation + // F2DOT14 scale; /* Format 2.14 */ + pointer += 2U; + } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) { + if (!validate(pointer, 4)) return false; + // TODO transformation + // F2DOT14 xscale; /* Format 2.14 */ + // F2DOT14 yscale; /* Format 2.14 */ + pointer += 4U; + } else if (flags & WE_HAVE_A_TWO_BY_TWO) { + if (!validate(pointer, 8)) return false; + // TODO transformation + // F2DOT14 xscale; /* Format 2.14 */ + // F2DOT14 scale01; /* Format 2.14 */ + // F2DOT14 scale10; /* Format 2.14 */ + // F2DOT14 yscale; /* Format 2.14 */ + pointer += 8U; + } + if (!convert(path, compGlyph, glyphMetrics(compGlyph), offset + compOffset, depth)) return false; + } while (flags & MORE_COMPONENTS); + return true; +} + + +bool TtfReader::kerning(uint32_t lglyph, uint32_t rglyph, Point& out) +{ + #define HORIZONTAL_KERNING 0x01 + #define MINIMUM_KERNING 0x02 + #define CROSS_STREAM_KERNING 0x04 + + if (!kern) return false; + + auto kern = this->kern.load(); + + //kern tables + auto tableCnt = _u16(data, kern + 2); + kern += 4; + + while (tableCnt > 0) { + //read subtable header. + if (!validate(kern, 6)) return false; + auto length = _u16(data, kern + 2); + auto format = _u8(data, kern + 4); + auto flags = _u8(data, kern + 5); + kern += 6; + + if (format == 0 && (flags & HORIZONTAL_KERNING) && !(flags & MINIMUM_KERNING)) { + //read format 0 header. + if (!validate(kern, 8)) return false; + auto pairCnt = _u16(data, kern); + kern += 8; + + //look up character code pair via binary search. + uint8_t key[4]; + key[0] = (lglyph >> 8) & 0xff; + key[1] = lglyph & 0xff; + key[2] = (rglyph >> 8) & 0xff; + key[3] = rglyph & 0xff; + + auto match = bsearch(key, data + kern, pairCnt, 6, _cmpu32); + + if (match) { + auto value = _i16(data, (uint32_t)((uint8_t *) match - data + 4)); + if (flags & CROSS_STREAM_KERNING) out.y += value; + else out.x += value; + } + } + kern += length; + --tableCnt; + } + + return true; +} diff --git a/components/thorvg-main/src/loaders/ttf/tvgTtfReader.h b/components/thorvg-main/src/loaders/ttf/tvgTtfReader.h new file mode 100644 index 0000000..6b730cc --- /dev/null +++ b/components/thorvg-main/src/loaders/ttf/tvgTtfReader.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_TTF_READER_H +#define _TVG_TTF_READER_H + +#include +#include "tvgRender.h" + +#define INVALID_GLYPH ((uint32_t)-1) + +struct TtfGlyph +{ + uint32_t idx; //glyph index + float advance; //advance width/height + float lsb; //left side bearing + float y; //y-offset + float w, h; //bounding box +}; + +struct TtfGlyphMetrics : TtfGlyph +{ + RenderPath path; //outline path +}; + +struct TtfReader +{ +public: + uint8_t* data = nullptr; + uint32_t size = 0; + + struct + { + //horizontal header info + struct { + float ascent, descent; + float lineGap; + float advance; + } hhea; + + uint16_t unitsPerEm; + uint16_t numHmtx; //the number of Horizontal metrics table + uint8_t locaFormat; //0 for short offsets, 1 for long + } metrics; + + bool header(); + uint32_t glyph(uint32_t codepoint, TtfGlyphMetrics* tgm); + bool kerning(uint32_t lglyph, uint32_t rglyph, Point& out); + bool convert(RenderPath& path, TtfGlyph& glyph, uint32_t glyphOffset, const Point& offset, uint16_t depth); + +private: + //table offsets + atomic cmap{}; + atomic hmtx{}; + atomic loca{}; + atomic glyf{}; + atomic kern{}; + atomic maxp{}; + + uint32_t cmap_12_13(uint32_t table, uint32_t codepoint, int which) const; + uint32_t cmap_4(uint32_t table, uint32_t codepoint) const; + uint32_t cmap_6(uint32_t table, uint32_t codepoint) const; + bool validate(uint32_t offset, uint32_t margin) const; + uint32_t table(const char* tag); + uint32_t outlineOffset(uint32_t glyph); + uint32_t glyph(uint32_t codepoint); + uint32_t glyphMetrics(TtfGlyph& glyph); + bool convertComposite(RenderPath& path, TtfGlyph& glyph, uint32_t glyphOffset, const Point& offset, uint16_t depth); + bool genPath(uint8_t* flags, uint16_t basePoint, uint16_t count); + bool points(uint32_t outline, uint8_t* flags, Point* pts, uint32_t ptsCnt, const Point& offset); + bool flags(uint32_t *outline, uint8_t* flags, uint32_t flagsCnt); +}; + +#endif //_TVG_TTF_READER_H \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/webp/dec/alpha.cpp b/components/thorvg-main/src/loaders/webp/dec/alpha.cpp new file mode 100644 index 0000000..9ac8240 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/alpha.cpp @@ -0,0 +1,167 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Alpha-plane decompression. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "tvgCommon.h" +#include "./alphai.h" +#include "./vp8i.h" +#include "./vp8li.h" +#include "../dsp/dsp.h" +#include "../utils/quant_levels_dec.h" +#include "../utils/utils.h" +#include "../webp/format_constants.h" + +//------------------------------------------------------------------------------ +// ALPHDecoder object. + +ALPHDecoder* ALPHNew(void) { + ALPHDecoder* const dec = tvg::calloc(1ULL, sizeof(*dec)); + return dec; +} + +void ALPHDelete(ALPHDecoder* const dec) { + if (dec != NULL) { + VP8LDelete(dec->vp8l_dec_); + dec->vp8l_dec_ = NULL; + tvg::free(dec); + } +} + +//------------------------------------------------------------------------------ +// Decoding. + +// Initialize alpha decoding by parsing the alpha header and decoding the image +// header for alpha data stored using lossless compression. +// Returns false in case of error in alpha header (data too short, invalid +// compression method or filter, error in lossless header data etc). +static int ALPHInit(ALPHDecoder* const dec, const uint8_t* data, + size_t data_size, int width, int height, uint8_t* output) { + int ok = 0; + const uint8_t* const alpha_data = data + ALPHA_HEADER_LEN; + const size_t alpha_data_size = data_size - ALPHA_HEADER_LEN; + int rsrv; + + assert(width > 0 && height > 0); + assert(data != NULL && output != NULL); + + dec->width_ = width; + dec->height_ = height; + + if (data_size <= ALPHA_HEADER_LEN) { + return 0; + } + + dec->method_ = (data[0] >> 0) & 0x03; + dec->filter_ = static_cast((data[0] >> 2) & 0x03); + dec->pre_processing_ = (data[0] >> 4) & 0x03; + rsrv = (data[0] >> 6) & 0x03; + if (dec->method_ < ALPHA_NO_COMPRESSION || + dec->method_ > ALPHA_LOSSLESS_COMPRESSION || + dec->filter_ >= WEBP_FILTER_LAST || + dec->pre_processing_ > ALPHA_PREPROCESSED_LEVELS || + rsrv != 0) { + return 0; + } + + if (dec->method_ == ALPHA_NO_COMPRESSION) { + const size_t alpha_decoded_size = dec->width_ * dec->height_; + ok = (alpha_data_size >= alpha_decoded_size); + } else { + assert(dec->method_ == ALPHA_LOSSLESS_COMPRESSION); + ok = VP8LDecodeAlphaHeader(dec, alpha_data, alpha_data_size, output); + } + VP8FiltersInit(); + return ok; +} + +// Decodes, unfilters and dequantizes *at least* 'num_rows' rows of alpha +// starting from row number 'row'. It assumes that rows up to (row - 1) have +// already been decoded. +// Returns false in case of bitstream error. +static int ALPHDecode(VP8Decoder* const dec, int row, int num_rows) { + ALPHDecoder* const alph_dec = dec->alph_dec_; + const int width = alph_dec->width_; + const int height = alph_dec->height_; + WebPUnfilterFunc unfilter_func = WebPUnfilters[alph_dec->filter_]; + uint8_t* const output = dec->alpha_plane_; + if (alph_dec->method_ == ALPHA_NO_COMPRESSION) { + const size_t offset = row * width; + const size_t num_pixels = num_rows * width; + assert(dec->alpha_data_size_ >= ALPHA_HEADER_LEN + offset + num_pixels); + memcpy(dec->alpha_plane_ + offset, + dec->alpha_data_ + ALPHA_HEADER_LEN + offset, num_pixels); + } else { // alph_dec->method_ == ALPHA_LOSSLESS_COMPRESSION + assert(alph_dec->vp8l_dec_ != NULL); + if (!VP8LDecodeAlphaImageStream(alph_dec, row + num_rows)) { + return 0; + } + } + + if (unfilter_func != NULL) { + unfilter_func(width, height, width, row, num_rows, output); + } + + if (row + num_rows == dec->pic_hdr_.height_) { + dec->is_alpha_decoded_ = 1; + } + return 1; +} + +//------------------------------------------------------------------------------ +// Main entry point. + +const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, + int row, int num_rows) { + const int width = dec->pic_hdr_.width_; + const int height = dec->pic_hdr_.height_; + + if (row < 0 || num_rows <= 0 || row + num_rows > height) { + return NULL; // sanity check. + } + + if (row == 0) { + // Initialize decoding. + assert(dec->alpha_plane_ != NULL); + dec->alph_dec_ = ALPHNew(); + if (dec->alph_dec_ == NULL) return NULL; + if (!ALPHInit(dec->alph_dec_, dec->alpha_data_, dec->alpha_data_size_, + width, height, dec->alpha_plane_)) { + ALPHDelete(dec->alph_dec_); + dec->alph_dec_ = NULL; + return NULL; + } + // if we allowed use of alpha dithering, check whether it's needed at all + if (dec->alph_dec_->pre_processing_ != ALPHA_PREPROCESSED_LEVELS) { + dec->alpha_dithering_ = 0; // disable dithering + } else { + num_rows = height; // decode everything in one pass + } + } + + if (!dec->is_alpha_decoded_) { + int ok = 0; + assert(dec->alph_dec_ != NULL); + ok = ALPHDecode(dec, row, num_rows); + if (ok && dec->alpha_dithering_ > 0) { + ok = WebPDequantizeLevels(dec->alpha_plane_, width, height, + dec->alpha_dithering_); + } + if (!ok || dec->is_alpha_decoded_) { + ALPHDelete(dec->alph_dec_); + dec->alph_dec_ = NULL; + } + if (!ok) return NULL; // Error. + } + + // Return a pointer to the current decoded row. + return dec->alpha_plane_ + row * width; +} diff --git a/components/thorvg-main/src/loaders/webp/dec/alphai.h b/components/thorvg-main/src/loaders/webp/dec/alphai.h new file mode 100644 index 0000000..058e883 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/alphai.h @@ -0,0 +1,55 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Alpha decoder: internal header. +// +// Author: Urvang (urvang@google.com) + +#ifndef WEBP_DEC_ALPHAI_H_ +#define WEBP_DEC_ALPHAI_H_ + +#include "./webpi.h" +#include "../dsp/dsp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct VP8LDecoder; // Defined in dec/vp8li.h. + +typedef struct ALPHDecoder ALPHDecoder; +struct ALPHDecoder { + int width_; + int height_; + int method_; + WEBP_FILTER_TYPE filter_; + int pre_processing_; + struct VP8LDecoder* vp8l_dec_; + VP8Io io_; + int use_8b_decode; // Although alpha channel requires only 1 byte per + // pixel, sometimes VP8LDecoder may need to allocate + // 4 bytes per pixel internally during decode. +}; + +//------------------------------------------------------------------------------ +// internal functions. Not public. + +// Allocates a new alpha decoder instance. +ALPHDecoder* ALPHNew(void); + +// Clears and deallocates an alpha decoder instance. +void ALPHDelete(ALPHDecoder* const dec); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_DEC_ALPHAI_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/dec/buffer.cpp b/components/thorvg-main/src/loaders/webp/dec/buffer.cpp new file mode 100644 index 0000000..fce4356 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/buffer.cpp @@ -0,0 +1,238 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Everything about WebPDecBuffer +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "tvgCommon.h" + +#include "./vp8i.h" +#include "./webpi.h" +#include "../utils/utils.h" + +//------------------------------------------------------------------------------ +// WebPDecBuffer + +// Number of bytes per pixel for the different color-spaces. +static const int kModeBpp[MODE_LAST] = { + 3, 4, 3, 4, 4, 2, 2, + 4, 4, 4, 2, // pre-multiplied modes + 1, 1 }; + +// Check that webp_csp_mode is within the bounds of WEBP_CSP_MODE. +// Convert to an integer to handle both the unsigned/signed enum cases +// without the need for casting to remove type limit warnings. +static int IsValidColorspace(int webp_csp_mode) { + return (webp_csp_mode >= MODE_RGB && webp_csp_mode < MODE_LAST); +} + +static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) { + int ok = 1; + const WEBP_CSP_MODE mode = buffer->colorspace; + const int width = buffer->width; + const int height = buffer->height; + if (!IsValidColorspace(mode)) { + ok = 0; + } else if (!WebPIsRGBMode(mode)) { // YUV checks + const WebPYUVABuffer* const buf = &buffer->u.YUVA; + const int y_stride = abs(buf->y_stride); + const int u_stride = abs(buf->u_stride); + const int v_stride = abs(buf->v_stride); + const int a_stride = abs(buf->a_stride); + const uint64_t y_size = (uint64_t)y_stride * height; + const uint64_t u_size = (uint64_t)u_stride * ((height + 1) / 2); + const uint64_t v_size = (uint64_t)v_stride * ((height + 1) / 2); + const uint64_t a_size = (uint64_t)a_stride * height; + ok &= (y_size <= buf->y_size); + ok &= (u_size <= buf->u_size); + ok &= (v_size <= buf->v_size); + ok &= (y_stride >= width); + ok &= (u_stride >= (width + 1) / 2); + ok &= (v_stride >= (width + 1) / 2); + ok &= (buf->y != NULL); + ok &= (buf->u != NULL); + ok &= (buf->v != NULL); + if (mode == MODE_YUVA) { + ok &= (a_stride >= width); + ok &= (a_size <= buf->a_size); + ok &= (buf->a != NULL); + } + } else { // RGB checks + const WebPRGBABuffer* const buf = &buffer->u.RGBA; + const int stride = abs(buf->stride); + const uint64_t size = (uint64_t)stride * height; + ok &= (size <= buf->size); + ok &= (stride >= width * kModeBpp[mode]); + ok &= (buf->rgba != NULL); + } + return ok ? VP8_STATUS_OK : VP8_STATUS_INVALID_PARAM; +} + +static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) { + const int w = buffer->width; + const int h = buffer->height; + const WEBP_CSP_MODE mode = buffer->colorspace; + + if (w <= 0 || h <= 0 || !IsValidColorspace(mode)) { + return VP8_STATUS_INVALID_PARAM; + } + + if (!buffer->is_external_memory && buffer->private_memory == NULL) { + uint8_t* output; + int uv_stride = 0, a_stride = 0; + uint64_t uv_size = 0, a_size = 0, total_size; + // We need memory and it hasn't been allocated yet. + // => initialize output buffer, now that dimensions are known. + const int stride = w * kModeBpp[mode]; + const uint64_t size = (uint64_t)stride * h; + + if (!WebPIsRGBMode(mode)) { + uv_stride = (w + 1) / 2; + uv_size = (uint64_t)uv_stride * ((h + 1) / 2); + if (mode == MODE_YUVA) { + a_stride = w; + a_size = (uint64_t)a_stride * h; + } + } + total_size = size + 2 * uv_size + a_size; + + // Security/sanity checks + output = tvg::malloc(total_size * sizeof(*output)); + if (output == NULL) { + return VP8_STATUS_OUT_OF_MEMORY; + } + buffer->private_memory = output; + + if (!WebPIsRGBMode(mode)) { // YUVA initialization + WebPYUVABuffer* const buf = &buffer->u.YUVA; + buf->y = output; + buf->y_stride = stride; + buf->y_size = (size_t)size; + buf->u = output + size; + buf->u_stride = uv_stride; + buf->u_size = (size_t)uv_size; + buf->v = output + size + uv_size; + buf->v_stride = uv_stride; + buf->v_size = (size_t)uv_size; + if (mode == MODE_YUVA) { + buf->a = output + size + 2 * uv_size; + } + buf->a_size = (size_t)a_size; + buf->a_stride = a_stride; + } else { // RGBA initialization + WebPRGBABuffer* const buf = &buffer->u.RGBA; + buf->rgba = output; + buf->stride = stride; + buf->size = (size_t)size; + } + } + return CheckDecBuffer(buffer); +} + +VP8StatusCode WebPFlipBuffer(WebPDecBuffer* const buffer) { + if (buffer == NULL) { + return VP8_STATUS_INVALID_PARAM; + } + if (WebPIsRGBMode(buffer->colorspace)) { + WebPRGBABuffer* const buf = &buffer->u.RGBA; + buf->rgba += (buffer->height - 1) * buf->stride; + buf->stride = -buf->stride; + } else { + WebPYUVABuffer* const buf = &buffer->u.YUVA; + const int H = buffer->height; + buf->y += (H - 1) * buf->y_stride; + buf->y_stride = -buf->y_stride; + buf->u += ((H - 1) >> 1) * buf->u_stride; + buf->u_stride = -buf->u_stride; + buf->v += ((H - 1) >> 1) * buf->v_stride; + buf->v_stride = -buf->v_stride; + if (buf->a != NULL) { + buf->a += (H - 1) * buf->a_stride; + buf->a_stride = -buf->a_stride; + } + } + return VP8_STATUS_OK; +} + +VP8StatusCode WebPAllocateDecBuffer(int w, int h, + const WebPDecoderOptions* const options, + WebPDecBuffer* const out) { + VP8StatusCode status; + if (out == NULL || w <= 0 || h <= 0) { + return VP8_STATUS_INVALID_PARAM; + } + if (options != NULL) { // First, apply options if there is any. + if (options->use_cropping) { + const int cw = options->crop_width; + const int ch = options->crop_height; + const int x = options->crop_left & ~1; + const int y = options->crop_top & ~1; + if (x < 0 || y < 0 || cw <= 0 || ch <= 0 || x + cw > w || y + ch > h) { + return VP8_STATUS_INVALID_PARAM; // out of frame boundary. + } + w = cw; + h = ch; + } + if (options->use_scaling) { + if (options->scaled_width <= 0 || options->scaled_height <= 0) { + return VP8_STATUS_INVALID_PARAM; + } + w = options->scaled_width; + h = options->scaled_height; + } + } + out->width = w; + out->height = h; + + // Then, allocate buffer for real. + status = AllocateBuffer(out); + if (status != VP8_STATUS_OK) return status; + + // Use the stride trick if vertical flip is needed. + if (options != NULL && options->flip) { + status = WebPFlipBuffer(out); + } + return status; +} + +//------------------------------------------------------------------------------ +// constructors / destructors + +int WebPInitDecBufferInternal(WebPDecBuffer* buffer, int version) { + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DECODER_ABI_VERSION)) { + return 0; // version mismatch + } + if (buffer == NULL) return 0; + memset(buffer, 0, sizeof(*buffer)); + return 1; +} + +void WebPFreeDecBuffer(WebPDecBuffer* buffer) { + if (buffer != NULL) { + if (!buffer->is_external_memory) { + tvg::free(buffer->private_memory); + } + buffer->private_memory = NULL; + } +} + +void WebPCopyDecBuffer(const WebPDecBuffer* const src, + WebPDecBuffer* const dst) { + if (src != NULL && dst != NULL) { + *dst = *src; + if (src->private_memory != NULL) { + dst->is_external_memory = 1; // dst buffer doesn't own the memory. + dst->private_memory = NULL; + } + } +} + +//------------------------------------------------------------------------------ + diff --git a/components/thorvg-main/src/loaders/webp/dec/common.h b/components/thorvg-main/src/loaders/webp/dec/common.h new file mode 100644 index 0000000..6961e22 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/common.h @@ -0,0 +1,54 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Definitions and macros common to encoding and decoding +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_DEC_COMMON_H_ +#define WEBP_DEC_COMMON_H_ + +// intra prediction modes +enum { B_DC_PRED = 0, // 4x4 modes + B_TM_PRED = 1, + B_VE_PRED = 2, + B_HE_PRED = 3, + B_RD_PRED = 4, + B_VR_PRED = 5, + B_LD_PRED = 6, + B_VL_PRED = 7, + B_HD_PRED = 8, + B_HU_PRED = 9, + NUM_BMODES = B_HU_PRED + 1 - B_DC_PRED, // = 10 + + // Luma16 or UV modes + DC_PRED = B_DC_PRED, V_PRED = B_VE_PRED, + H_PRED = B_HE_PRED, TM_PRED = B_TM_PRED, + B_PRED = NUM_BMODES, // refined I4x4 mode + NUM_PRED_MODES = 4, + + // special modes + B_DC_PRED_NOTOP = 4, + B_DC_PRED_NOLEFT = 5, + B_DC_PRED_NOTOPLEFT = 6, + NUM_B_DC_MODES = 7 }; + +enum { MB_FEATURE_TREE_PROBS = 3, + NUM_MB_SEGMENTS = 4, + NUM_REF_LF_DELTAS = 4, + NUM_MODE_LF_DELTAS = 4, // I4x4, ZERO, *, SPLIT + MAX_NUM_PARTITIONS = 8, + // Probabilities + NUM_TYPES = 4, // 0: i16-AC, 1: i16-DC, 2:chroma-AC, 3:i4-AC + NUM_BANDS = 8, + NUM_CTX = 3, + NUM_PROBAS = 11 + }; + +#endif // WEBP_DEC_COMMON_H_ diff --git a/components/thorvg-main/src/loaders/webp/dec/decode_vp8.h b/components/thorvg-main/src/loaders/webp/dec/decode_vp8.h new file mode 100644 index 0000000..236342f --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/decode_vp8.h @@ -0,0 +1,177 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Low-level API for VP8 decoder +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_DECODE_VP8_H_ +#define WEBP_WEBP_DECODE_VP8_H_ + +#include "../webp/decode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------------------------------------------------ +// Lower-level API +// +// These functions provide fine-grained control of the decoding process. +// The call flow should resemble: +// +// VP8Io io; +// VP8InitIo(&io); +// io.data = data; +// io.data_size = size; +// /* customize io's functions (setup()/put()/teardown()) if needed. */ +// +// VP8Decoder* dec = VP8New(); +// bool ok = VP8Decode(dec); +// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec)); +// VP8Delete(dec); +// return ok; + +// Input / Output +typedef struct VP8Io VP8Io; +typedef int (*VP8IoPutHook)(const VP8Io* io); +typedef int (*VP8IoSetupHook)(VP8Io* io); +typedef void (*VP8IoTeardownHook)(const VP8Io* io); + +struct VP8Io { + // set by VP8GetHeaders() + int width, height; // picture dimensions, in pixels (invariable). + // These are the original, uncropped dimensions. + // The actual area passed to put() is stored + // in mb_w / mb_h fields. + + // set before calling put() + int mb_y; // position of the current rows (in pixels) + int mb_w; // number of columns in the sample + int mb_h; // number of rows in the sample + const uint8_t* y, *u, *v; // rows to copy (in yuv420 format) + int y_stride; // row stride for luma + int uv_stride; // row stride for chroma + + void* opaque; // user data + + // called when fresh samples are available. Currently, samples are in + // YUV420 format, and can be up to width x 24 in size (depending on the + // in-loop filtering level, e.g.). Should return false in case of error + // or abort request. The actual size of the area to update is mb_w x mb_h + // in size, taking cropping into account. + VP8IoPutHook put; + + // called just before starting to decode the blocks. + // Must return false in case of setup error, true otherwise. If false is + // returned, teardown() will NOT be called. But if the setup succeeded + // and true is returned, then teardown() will always be called afterward. + VP8IoSetupHook setup; + + // Called just after block decoding is finished (or when an error occurred + // during put()). Is NOT called if setup() failed. + VP8IoTeardownHook teardown; + + // this is a recommendation for the user-side yuv->rgb converter. This flag + // is set when calling setup() hook and can be overwritten by it. It then + // can be taken into consideration during the put() method. + int fancy_upsampling; + + // Input buffer. + size_t data_size; + const uint8_t* data; + + // If true, in-loop filtering will not be performed even if present in the + // bitstream. Switching off filtering may speed up decoding at the expense + // of more visible blocking. Note that output will also be non-compliant + // with the VP8 specifications. + int bypass_filtering; + + // Cropping parameters. + int use_cropping; + int crop_left, crop_right, crop_top, crop_bottom; + + // Scaling parameters. + int use_scaling; + int scaled_width, scaled_height; + + // If non NULL, pointer to the alpha data (if present) corresponding to the + // start of the current row (That is: it is pre-offset by mb_y and takes + // cropping into account). + const uint8_t* a; +}; + +// Internal, version-checked, entry point +int VP8InitIoInternal(VP8Io* const, int); + + +// Main decoding object. This is an opaque structure. +typedef struct VP8Decoder VP8Decoder; + +// Create a new decoder object. +VP8Decoder* VP8New(void); + +// Must be called to make sure 'io' is initialized properly. +// Returns false in case of version mismatch. Upon such failure, no other +// decoding function should be called (VP8Decode, VP8GetHeaders, ...) +static WEBP_INLINE int VP8InitIo(VP8Io* const io) { + return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION); +} + +// Decode the VP8 frame header. Returns true if ok. +// Note: 'io->data' must be pointing to the start of the VP8 frame header. +int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io); + +// Decode a picture. Will call VP8GetHeaders() if it wasn't done already. +// Returns false in case of error. +int VP8Decode(VP8Decoder* const dec, VP8Io* const io); + +// Return current status of the decoder: +VP8StatusCode VP8Status(VP8Decoder* const dec); + +// return readable string corresponding to the last status. +const char* VP8StatusMessage(VP8Decoder* const dec); + +// Resets the decoder in its initial state, reclaiming memory. +// Not a mandatory call between calls to VP8Decode(). +void VP8Clear(VP8Decoder* const dec); + +// Destroy the decoder object. +void VP8Delete(VP8Decoder* const dec); + +//------------------------------------------------------------------------------ +// Miscellaneous VP8/VP8L bitstream probing functions. + +// Returns true if the next 3 bytes in data contain the VP8 signature. +WEBP_EXTERN(int) VP8CheckSignature(const uint8_t* const data, size_t data_size); + +// Validates the VP8 data-header and retrieves basic header information viz +// width and height. Returns 0 in case of formatting error. *width/*height +// can be passed NULL. +WEBP_EXTERN(int) VP8GetInfo( + const uint8_t* data, + size_t data_size, // data available so far + size_t chunk_size, // total data size expected in the chunk + int* const width, int* const height); + +// Returns true if the next byte(s) in data is a VP8L signature. +WEBP_EXTERN(int) VP8LCheckSignature(const uint8_t* const data, size_t size); + +// Validates the VP8L data-header and retrieves basic header information viz +// width, height and alpha. Returns 0 in case of formatting error. +// width/height/has_alpha can be passed NULL. +WEBP_EXTERN(int) VP8LGetInfo( + const uint8_t* data, size_t data_size, // data available so far + int* const width, int* const height, int* const has_alpha); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_WEBP_DECODE_VP8_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/dec/frame.cpp b/components/thorvg-main/src/loaders/webp/dec/frame.cpp new file mode 100644 index 0000000..b8a9386 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/frame.cpp @@ -0,0 +1,713 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Frame-reconstruction function. Memory allocation. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "tvgCommon.h" +#include "./vp8i.h" +#include "../utils/utils.h" + +#define ALIGN_CST (32 - 1) +#define DO_ALIGN(PTR) ((uintptr_t)((PTR) + ALIGN_CST) & ~ALIGN_CST) + +//------------------------------------------------------------------------------ +// Main reconstruction function. + +static const int kScan[16] = { + 0 + 0 * BPS, 4 + 0 * BPS, 8 + 0 * BPS, 12 + 0 * BPS, + 0 + 4 * BPS, 4 + 4 * BPS, 8 + 4 * BPS, 12 + 4 * BPS, + 0 + 8 * BPS, 4 + 8 * BPS, 8 + 8 * BPS, 12 + 8 * BPS, + 0 + 12 * BPS, 4 + 12 * BPS, 8 + 12 * BPS, 12 + 12 * BPS +}; + +static int CheckMode(int mb_x, int mb_y, int mode) { + if (mode == B_DC_PRED) { + if (mb_x == 0) { + return (mb_y == 0) ? B_DC_PRED_NOTOPLEFT : B_DC_PRED_NOLEFT; + } else { + return (mb_y == 0) ? B_DC_PRED_NOTOP : B_DC_PRED; + } + } + return mode; +} + +static void Copy32b(uint8_t* const dst, const uint8_t* const src) { + memcpy(dst, src, 4); +} + +static WEBP_INLINE void DoTransform(uint32_t bits, const int16_t* const src, + uint8_t* const dst) { + switch (bits >> 30) { + case 3: + VP8Transform(src, dst, 0); + break; + case 2: + VP8TransformAC3(src, dst); + break; + case 1: + VP8TransformDC(src, dst); + break; + default: + break; + } +} + +static void DoUVTransform(uint32_t bits, const int16_t* const src, + uint8_t* const dst) { + if (bits & 0xff) { // any non-zero coeff at all? + if (bits & 0xaa) { // any non-zero AC coefficient? + VP8TransformUV(src, dst); // note we don't use the AC3 variant for U/V + } else { + VP8TransformDCUV(src, dst); + } + } +} + +static void ReconstructRow(const VP8Decoder* const dec, + const VP8ThreadContext* ctx) { + int j; + int mb_x; + const int mb_y = ctx->mb_y_; + const int cache_id = ctx->id_; + uint8_t* const y_dst = dec->yuv_b_ + Y_OFF; + uint8_t* const u_dst = dec->yuv_b_ + U_OFF; + uint8_t* const v_dst = dec->yuv_b_ + V_OFF; + + // Initialize left-most block. + for (j = 0; j < 16; ++j) { + y_dst[j * BPS - 1] = 129; + } + for (j = 0; j < 8; ++j) { + u_dst[j * BPS - 1] = 129; + v_dst[j * BPS - 1] = 129; + } + + // Init top-left sample on left column too. + if (mb_y > 0) { + y_dst[-1 - BPS] = u_dst[-1 - BPS] = v_dst[-1 - BPS] = 129; + } else { + // we only need to do this init once at block (0,0). + // Afterward, it remains valid for the whole topmost row. + memset(y_dst - BPS - 1, 127, 16 + 4 + 1); + memset(u_dst - BPS - 1, 127, 8 + 1); + memset(v_dst - BPS - 1, 127, 8 + 1); + } + + // Reconstruct one row. + for (mb_x = 0; mb_x < dec->mb_w_; ++mb_x) { + const VP8MBData* const block = ctx->mb_data_ + mb_x; + + // Rotate in the left samples from previously decoded block. We move four + // pixels at a time for alignment reason, and because of in-loop filter. + if (mb_x > 0) { + for (j = -1; j < 16; ++j) { + Copy32b(&y_dst[j * BPS - 4], &y_dst[j * BPS + 12]); + } + for (j = -1; j < 8; ++j) { + Copy32b(&u_dst[j * BPS - 4], &u_dst[j * BPS + 4]); + Copy32b(&v_dst[j * BPS - 4], &v_dst[j * BPS + 4]); + } + } + { + // bring top samples into the cache + VP8TopSamples* const top_yuv = dec->yuv_t_ + mb_x; + const int16_t* const coeffs = block->coeffs_; + uint32_t bits = block->non_zero_y_; + int n; + + if (mb_y > 0) { + memcpy(y_dst - BPS, top_yuv[0].y, 16); + memcpy(u_dst - BPS, top_yuv[0].u, 8); + memcpy(v_dst - BPS, top_yuv[0].v, 8); + } + + // predict and add residuals + if (block->is_i4x4_) { // 4x4 + uint32_t* const top_right = (uint32_t*)(y_dst - BPS + 16); + + if (mb_y > 0) { + if (mb_x >= dec->mb_w_ - 1) { // on rightmost border + memset(top_right, top_yuv[0].y[15], sizeof(*top_right)); + } else { + memcpy(top_right, top_yuv[1].y, sizeof(*top_right)); + } + } + // replicate the top-right pixels below + top_right[BPS] = top_right[2 * BPS] = top_right[3 * BPS] = top_right[0]; + + // predict and add residuals for all 4x4 blocks in turn. + for (n = 0; n < 16; ++n, bits <<= 2) { + uint8_t* const dst = y_dst + kScan[n]; + VP8PredLuma4[block->imodes_[n]](dst); + DoTransform(bits, coeffs + n * 16, dst); + } + } else { // 16x16 + const int pred_func = CheckMode(mb_x, mb_y, block->imodes_[0]); + VP8PredLuma16[pred_func](y_dst); + if (bits != 0) { + for (n = 0; n < 16; ++n, bits <<= 2) { + DoTransform(bits, coeffs + n * 16, y_dst + kScan[n]); + } + } + } + { + // Chroma + const uint32_t bits_uv = block->non_zero_uv_; + const int pred_func = CheckMode(mb_x, mb_y, block->uvmode_); + VP8PredChroma8[pred_func](u_dst); + VP8PredChroma8[pred_func](v_dst); + DoUVTransform(bits_uv >> 0, coeffs + 16 * 16, u_dst); + DoUVTransform(bits_uv >> 8, coeffs + 20 * 16, v_dst); + } + + // stash away top samples for next block + if (mb_y < dec->mb_h_ - 1) { + memcpy(top_yuv[0].y, y_dst + 15 * BPS, 16); + memcpy(top_yuv[0].u, u_dst + 7 * BPS, 8); + memcpy(top_yuv[0].v, v_dst + 7 * BPS, 8); + } + } + // Transfer reconstructed samples from yuv_b_ cache to final destination. + { + const int y_offset = cache_id * 16 * dec->cache_y_stride_; + const int uv_offset = cache_id * 8 * dec->cache_uv_stride_; + uint8_t* const y_out = dec->cache_y_ + mb_x * 16 + y_offset; + uint8_t* const u_out = dec->cache_u_ + mb_x * 8 + uv_offset; + uint8_t* const v_out = dec->cache_v_ + mb_x * 8 + uv_offset; + for (j = 0; j < 16; ++j) { + memcpy(y_out + j * dec->cache_y_stride_, y_dst + j * BPS, 16); + } + for (j = 0; j < 8; ++j) { + memcpy(u_out + j * dec->cache_uv_stride_, u_dst + j * BPS, 8); + memcpy(v_out + j * dec->cache_uv_stride_, v_dst + j * BPS, 8); + } + } + } +} + +//------------------------------------------------------------------------------ +// Filtering + +// kFilterExtraRows[] = How many extra lines are needed on the MB boundary +// for caching, given a filtering level. +// Simple filter: up to 2 luma samples are read and 1 is written. +// Complex filter: up to 4 luma samples are read and 3 are written. Same for +// U/V, so it's 8 samples total (because of the 2x upsampling). +static const uint8_t kFilterExtraRows[3] = { 0, 2, 8 }; + +static void DoFilter(const VP8Decoder* const dec, int mb_x, int mb_y) { + const VP8ThreadContext* const ctx = &dec->thread_ctx_; + const int cache_id = ctx->id_; + const int y_bps = dec->cache_y_stride_; + const VP8FInfo* const f_info = ctx->f_info_ + mb_x; + uint8_t* const y_dst = dec->cache_y_ + cache_id * 16 * y_bps + mb_x * 16; + const int ilevel = f_info->f_ilevel_; + const int limit = f_info->f_limit_; + if (limit == 0) { + return; + } + assert(limit >= 3); + if (dec->filter_type_ == 1) { // simple + if (mb_x > 0) { + VP8SimpleHFilter16(y_dst, y_bps, limit + 4); + } + if (f_info->f_inner_) { + VP8SimpleHFilter16i(y_dst, y_bps, limit); + } + if (mb_y > 0) { + VP8SimpleVFilter16(y_dst, y_bps, limit + 4); + } + if (f_info->f_inner_) { + VP8SimpleVFilter16i(y_dst, y_bps, limit); + } + } else { // complex + const int uv_bps = dec->cache_uv_stride_; + uint8_t* const u_dst = dec->cache_u_ + cache_id * 8 * uv_bps + mb_x * 8; + uint8_t* const v_dst = dec->cache_v_ + cache_id * 8 * uv_bps + mb_x * 8; + const int hev_thresh = f_info->hev_thresh_; + if (mb_x > 0) { + VP8HFilter16(y_dst, y_bps, limit + 4, ilevel, hev_thresh); + VP8HFilter8(u_dst, v_dst, uv_bps, limit + 4, ilevel, hev_thresh); + } + if (f_info->f_inner_) { + VP8HFilter16i(y_dst, y_bps, limit, ilevel, hev_thresh); + VP8HFilter8i(u_dst, v_dst, uv_bps, limit, ilevel, hev_thresh); + } + if (mb_y > 0) { + VP8VFilter16(y_dst, y_bps, limit + 4, ilevel, hev_thresh); + VP8VFilter8(u_dst, v_dst, uv_bps, limit + 4, ilevel, hev_thresh); + } + if (f_info->f_inner_) { + VP8VFilter16i(y_dst, y_bps, limit, ilevel, hev_thresh); + VP8VFilter8i(u_dst, v_dst, uv_bps, limit, ilevel, hev_thresh); + } + } +} + +// Filter the decoded macroblock row (if needed) +static void FilterRow(const VP8Decoder* const dec) { + int mb_x; + const int mb_y = dec->thread_ctx_.mb_y_; + assert(dec->thread_ctx_.filter_row_); + for (mb_x = dec->tl_mb_x_; mb_x < dec->br_mb_x_; ++mb_x) { + DoFilter(dec, mb_x, mb_y); + } +} + +//------------------------------------------------------------------------------ +// Precompute the filtering strength for each segment and each i4x4/i16x16 mode. + +static void PrecomputeFilterStrengths(VP8Decoder* const dec) { + if (dec->filter_type_ > 0) { + int s; + const VP8FilterHeader* const hdr = &dec->filter_hdr_; + for (s = 0; s < NUM_MB_SEGMENTS; ++s) { + int i4x4; + // First, compute the initial level + int base_level; + if (dec->segment_hdr_.use_segment_) { + base_level = dec->segment_hdr_.filter_strength_[s]; + if (!dec->segment_hdr_.absolute_delta_) { + base_level += hdr->level_; + } + } else { + base_level = hdr->level_; + } + for (i4x4 = 0; i4x4 <= 1; ++i4x4) { + VP8FInfo* const info = &dec->fstrengths_[s][i4x4]; + int level = base_level; + if (hdr->use_lf_delta_) { + level += hdr->ref_lf_delta_[0]; + if (i4x4) { + level += hdr->mode_lf_delta_[0]; + } + } + level = (level < 0) ? 0 : (level > 63) ? 63 : level; + if (level > 0) { + int ilevel = level; + if (hdr->sharpness_ > 0) { + if (hdr->sharpness_ > 4) { + ilevel >>= 2; + } else { + ilevel >>= 1; + } + if (ilevel > 9 - hdr->sharpness_) { + ilevel = 9 - hdr->sharpness_; + } + } + if (ilevel < 1) ilevel = 1; + info->f_ilevel_ = ilevel; + info->f_limit_ = 2 * level + ilevel; + info->hev_thresh_ = (level >= 40) ? 2 : (level >= 15) ? 1 : 0; + } else { + info->f_limit_ = 0; // no filtering + } + info->f_inner_ = i4x4; + } + } + } +} + +//------------------------------------------------------------------------------ +// Dithering + +#define DITHER_AMP_TAB_SIZE 12 +static const int kQuantToDitherAmp[DITHER_AMP_TAB_SIZE] = { + // roughly, it's dqm->uv_mat_[1] + 8, 7, 6, 4, 4, 2, 2, 2, 1, 1, 1, 1 +}; + +void VP8InitDithering(const WebPDecoderOptions* const options, + VP8Decoder* const dec) { + assert(dec != NULL); + if (options != NULL) { + const int d = options->dithering_strength; + const int max_amp = (1 << VP8_RANDOM_DITHER_FIX) - 1; + const int f = (d < 0) ? 0 : (d > 100) ? max_amp : (d * max_amp / 100); + if (f > 0) { + int s; + int all_amp = 0; + for (s = 0; s < NUM_MB_SEGMENTS; ++s) { + VP8QuantMatrix* const dqm = &dec->dqm_[s]; + if (dqm->uv_quant_ < DITHER_AMP_TAB_SIZE) { + // TODO(skal): should we specially dither more for uv_quant_ < 0? + const int idx = (dqm->uv_quant_ < 0) ? 0 : dqm->uv_quant_; + dqm->dither_ = (f * kQuantToDitherAmp[idx]) >> 3; + } + all_amp |= dqm->dither_; + } + if (all_amp != 0) { + VP8InitRandom(&dec->dithering_rg_, 1.0f); + dec->dither_ = 1; + } + } + // potentially allow alpha dithering + dec->alpha_dithering_ = options->alpha_dithering_strength; + if (dec->alpha_dithering_ > 100) { + dec->alpha_dithering_ = 100; + } else if (dec->alpha_dithering_ < 0) { + dec->alpha_dithering_ = 0; + } + } +} + +// minimal amp that will provide a non-zero dithering effect +#define MIN_DITHER_AMP 4 +#define DITHER_DESCALE 4 +#define DITHER_DESCALE_ROUNDER (1 << (DITHER_DESCALE - 1)) +#define DITHER_AMP_BITS 8 +#define DITHER_AMP_CENTER (1 << DITHER_AMP_BITS) + +static void Dither8x8(VP8Random* const rg, uint8_t* dst, int bps, int amp) { + int i, j; + for (j = 0; j < 8; ++j) { + for (i = 0; i < 8; ++i) { + // TODO: could be made faster with SSE2 + const int bits = + VP8RandomBits2(rg, DITHER_AMP_BITS + 1, amp) - DITHER_AMP_CENTER; + // Convert to range: [-2,2] for dither=50, [-4,4] for dither=100 + const int delta = (bits + DITHER_DESCALE_ROUNDER) >> DITHER_DESCALE; + const int v = (int)dst[i] + delta; + dst[i] = (v < 0) ? 0 : (v > 255) ? 255u : (uint8_t)v; + } + dst += bps; + } +} + +static void DitherRow(VP8Decoder* const dec) { + int mb_x; + assert(dec->dither_); + for (mb_x = dec->tl_mb_x_; mb_x < dec->br_mb_x_; ++mb_x) { + const VP8ThreadContext* const ctx = &dec->thread_ctx_; + const VP8MBData* const data = ctx->mb_data_ + mb_x; + const int cache_id = ctx->id_; + const int uv_bps = dec->cache_uv_stride_; + if (data->dither_ >= MIN_DITHER_AMP) { + uint8_t* const u_dst = dec->cache_u_ + cache_id * 8 * uv_bps + mb_x * 8; + uint8_t* const v_dst = dec->cache_v_ + cache_id * 8 * uv_bps + mb_x * 8; + Dither8x8(&dec->dithering_rg_, u_dst, uv_bps, data->dither_); + Dither8x8(&dec->dithering_rg_, v_dst, uv_bps, data->dither_); + } + } +} + +//------------------------------------------------------------------------------ +// This function is called after a row of macroblocks is finished decoding. +// It also takes into account the following restrictions: +// * In case of in-loop filtering, we must hold off sending some of the bottom +// pixels as they are yet unfiltered. They will be when the next macroblock +// row is decoded. Meanwhile, we must preserve them by rotating them in the +// cache area. This doesn't hold for the very bottom row of the uncropped +// picture of course. +// * we must clip the remaining pixels against the cropping area. The VP8Io +// struct must have the following fields set correctly before calling put(): + +#define MACROBLOCK_VPOS(mb_y) ((mb_y) * 16) // vertical position of a MB + +// Finalize and transmit a complete row. Return false in case of user-abort. +static int FinishRow(VP8Decoder* const dec, VP8Io* const io) { + int ok = 1; + const VP8ThreadContext* const ctx = &dec->thread_ctx_; + const int cache_id = ctx->id_; + const int extra_y_rows = kFilterExtraRows[dec->filter_type_]; + const int ysize = extra_y_rows * dec->cache_y_stride_; + const int uvsize = (extra_y_rows / 2) * dec->cache_uv_stride_; + const int y_offset = cache_id * 16 * dec->cache_y_stride_; + const int uv_offset = cache_id * 8 * dec->cache_uv_stride_; + uint8_t* const ydst = dec->cache_y_ - ysize + y_offset; + uint8_t* const udst = dec->cache_u_ - uvsize + uv_offset; + uint8_t* const vdst = dec->cache_v_ - uvsize + uv_offset; + const int mb_y = ctx->mb_y_; + const int is_first_row = (mb_y == 0); + const int is_last_row = (mb_y >= dec->br_mb_y_ - 1); + + if (ctx->filter_row_) { + FilterRow(dec); + } + + if (dec->dither_) { + DitherRow(dec); + } + + if (io->put != NULL) { + int y_start = MACROBLOCK_VPOS(mb_y); + int y_end = MACROBLOCK_VPOS(mb_y + 1); + if (!is_first_row) { + y_start -= extra_y_rows; + io->y = ydst; + io->u = udst; + io->v = vdst; + } else { + io->y = dec->cache_y_ + y_offset; + io->u = dec->cache_u_ + uv_offset; + io->v = dec->cache_v_ + uv_offset; + } + + if (!is_last_row) { + y_end -= extra_y_rows; + } + if (y_end > io->crop_bottom) { + y_end = io->crop_bottom; // make sure we don't overflow on last row. + } + io->a = NULL; + if (dec->alpha_data_ != NULL && y_start < y_end) { + // TODO(skal): testing presence of alpha with dec->alpha_data_ is not a + // good idea. + io->a = VP8DecompressAlphaRows(dec, y_start, y_end - y_start); + if (io->a == NULL) { + return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, + "Could not decode alpha data."); + } + } + if (y_start < io->crop_top) { + const int delta_y = io->crop_top - y_start; + y_start = io->crop_top; + assert(!(delta_y & 1)); + io->y += dec->cache_y_stride_ * delta_y; + io->u += dec->cache_uv_stride_ * (delta_y >> 1); + io->v += dec->cache_uv_stride_ * (delta_y >> 1); + if (io->a != NULL) { + io->a += io->width * delta_y; + } + } + if (y_start < y_end) { + io->y += io->crop_left; + io->u += io->crop_left >> 1; + io->v += io->crop_left >> 1; + if (io->a != NULL) { + io->a += io->crop_left; + } + io->mb_y = y_start - io->crop_top; + io->mb_w = io->crop_right - io->crop_left; + io->mb_h = y_end - y_start; + ok = io->put(io); + } + } + // rotate top samples if needed + if (cache_id + 1 == dec->num_caches_) { + if (!is_last_row) { + memcpy(dec->cache_y_ - ysize, ydst + 16 * dec->cache_y_stride_, ysize); + memcpy(dec->cache_u_ - uvsize, udst + 8 * dec->cache_uv_stride_, uvsize); + memcpy(dec->cache_v_ - uvsize, vdst + 8 * dec->cache_uv_stride_, uvsize); + } + } + + return ok; +} + +#undef MACROBLOCK_VPOS + +//------------------------------------------------------------------------------ + +int VP8ProcessRow(VP8Decoder* const dec, VP8Io* const io) { + int ok = 1; + VP8ThreadContext* const ctx = &dec->thread_ctx_; + const int filter_row = + (dec->filter_type_ > 0) && + (dec->mb_y_ >= dec->tl_mb_y_) && (dec->mb_y_ <= dec->br_mb_y_); + // ctx->id_ and ctx->f_info_ are already set + ctx->mb_y_ = dec->mb_y_; + ctx->filter_row_ = filter_row; + ReconstructRow(dec, ctx); + ok = FinishRow(dec, io); + + return ok; +} + +//------------------------------------------------------------------------------ +// Finish setting up the decoding parameter once user's setup() is called. + +VP8StatusCode VP8EnterCritical(VP8Decoder* const dec, VP8Io* const io) { + // Call setup() first. This may trigger additional decoding features on 'io'. + // Note: Afterward, we must call teardown() no matter what. + if (io->setup != NULL && !io->setup(io)) { + VP8SetError(dec, VP8_STATUS_USER_ABORT, "Frame setup failed"); + return dec->status_; + } + + // Disable filtering per user request + if (io->bypass_filtering) { + dec->filter_type_ = 0; + } + // TODO(skal): filter type / strength / sharpness forcing + + // Define the area where we can skip in-loop filtering, in case of cropping. + // + // 'Simple' filter reads two luma samples outside of the macroblock + // and filters one. It doesn't filter the chroma samples. Hence, we can + // avoid doing the in-loop filtering before crop_top/crop_left position. + // For the 'Complex' filter, 3 samples are read and up to 3 are filtered. + // Means: there's a dependency chain that goes all the way up to the + // top-left corner of the picture (MB #0). We must filter all the previous + // macroblocks. + // TODO(skal): add an 'approximate_decoding' option, that won't produce + // a 1:1 bit-exactness for complex filtering? + { + const int extra_pixels = kFilterExtraRows[dec->filter_type_]; + if (dec->filter_type_ == 2) { + // For complex filter, we need to preserve the dependency chain. + dec->tl_mb_x_ = 0; + dec->tl_mb_y_ = 0; + } else { + // For simple filter, we can filter only the cropped region. + // We include 'extra_pixels' on the other side of the boundary, since + // vertical or horizontal filtering of the previous macroblock can + // modify some abutting pixels. + dec->tl_mb_x_ = (io->crop_left - extra_pixels) >> 4; + dec->tl_mb_y_ = (io->crop_top - extra_pixels) >> 4; + if (dec->tl_mb_x_ < 0) dec->tl_mb_x_ = 0; + if (dec->tl_mb_y_ < 0) dec->tl_mb_y_ = 0; + } + // We need some 'extra' pixels on the right/bottom. + dec->br_mb_y_ = (io->crop_bottom + 15 + extra_pixels) >> 4; + dec->br_mb_x_ = (io->crop_right + 15 + extra_pixels) >> 4; + if (dec->br_mb_x_ > dec->mb_w_) { + dec->br_mb_x_ = dec->mb_w_; + } + if (dec->br_mb_y_ > dec->mb_h_) { + dec->br_mb_y_ = dec->mb_h_; + } + } + PrecomputeFilterStrengths(dec); + return VP8_STATUS_OK; +} + +int VP8ExitCritical(VP8Decoder* const dec, VP8Io* const io) { + int ok = 1; + if (io->teardown != NULL) { + io->teardown(io); + } + return ok; +} + +#define ST_CACHE_LINES 1 // 1 cache row only for single-threaded case + +// Initialize multi/single-thread worker +static int InitThreadContext(VP8Decoder* const dec) { + dec->cache_id_ = 0; + dec->num_caches_ = ST_CACHE_LINES; + return 1; +} + +#undef ST_CACHE_LINES + +//------------------------------------------------------------------------------ +// Memory setup + +static int AllocateMemory(VP8Decoder* const dec) { + const int num_caches = dec->num_caches_; + const int mb_w = dec->mb_w_; + // Note: we use 'size_t' when there's no overflow risk, uint64_t otherwise. + const size_t intra_pred_mode_size = 4 * mb_w * sizeof(uint8_t); + const size_t top_size = sizeof(VP8TopSamples) * mb_w; + const size_t mb_info_size = (mb_w + 1) * sizeof(VP8MB); + const size_t f_info_size = (dec->filter_type_ > 0) ? mb_w * sizeof(VP8FInfo) : 0; + const size_t yuv_size = YUV_SIZE * sizeof(*dec->yuv_b_); + const size_t mb_data_size = mb_w * sizeof(*dec->mb_data_); + const size_t cache_height = (16 * num_caches + + kFilterExtraRows[dec->filter_type_]) * 3 / 2; + const size_t cache_size = top_size * cache_height; + // alpha_size is the only one that scales as width x height. + const uint64_t alpha_size = (dec->alpha_data_ != NULL) ? + (uint64_t)dec->pic_hdr_.width_ * dec->pic_hdr_.height_ : 0ULL; + const uint64_t needed = (uint64_t)intra_pred_mode_size + + top_size + mb_info_size + f_info_size + + yuv_size + mb_data_size + + cache_size + alpha_size + ALIGN_CST; + uint8_t* mem; + + if (needed != (size_t)needed) return 0; // check for overflow + if (needed > dec->mem_size_) { + tvg::free(dec->mem_); + dec->mem_size_ = 0; + dec->mem_ = tvg::malloc(needed * sizeof(uint8_t)); + if (dec->mem_ == NULL) { + return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY, + "no memory during frame initialization."); + } + // down-cast is ok, thanks to WebPSafeAlloc() above. + dec->mem_size_ = (size_t)needed; + } + + mem = (uint8_t*)dec->mem_; + dec->intra_t_ = (uint8_t*)mem; + mem += intra_pred_mode_size; + + dec->yuv_t_ = (VP8TopSamples*)mem; + mem += top_size; + + dec->mb_info_ = ((VP8MB*)mem) + 1; + mem += mb_info_size; + + dec->f_info_ = f_info_size ? (VP8FInfo*)mem : NULL; + mem += f_info_size; + dec->thread_ctx_.id_ = 0; + dec->thread_ctx_.f_info_ = dec->f_info_; + + mem = (uint8_t*)DO_ALIGN(mem); + assert((yuv_size & ALIGN_CST) == 0); + dec->yuv_b_ = (uint8_t*)mem; + mem += yuv_size; + + dec->mb_data_ = (VP8MBData*)mem; + dec->thread_ctx_.mb_data_ = (VP8MBData*)mem; + mem += mb_data_size; + + dec->cache_y_stride_ = 16 * mb_w; + dec->cache_uv_stride_ = 8 * mb_w; + { + const int extra_rows = kFilterExtraRows[dec->filter_type_]; + const int extra_y = extra_rows * dec->cache_y_stride_; + const int extra_uv = (extra_rows / 2) * dec->cache_uv_stride_; + dec->cache_y_ = ((uint8_t*)mem) + extra_y; + dec->cache_u_ = dec->cache_y_ + + 16 * num_caches * dec->cache_y_stride_ + extra_uv; + dec->cache_v_ = dec->cache_u_ + + 8 * num_caches * dec->cache_uv_stride_ + extra_uv; + dec->cache_id_ = 0; + } + mem += cache_size; + + // alpha plane + dec->alpha_plane_ = alpha_size ? (uint8_t*)mem : NULL; + mem += alpha_size; + assert(mem <= (uint8_t*)dec->mem_ + dec->mem_size_); + + // note: left/top-info is initialized once for all. + memset(dec->mb_info_ - 1, 0, mb_info_size); + VP8InitScanline(dec); // initialize left too. + + // initialize top + memset(dec->intra_t_, B_DC_PRED, intra_pred_mode_size); + + return 1; +} + +static void InitIo(VP8Decoder* const dec, VP8Io* io) { + // prepare 'io' + io->mb_y = 0; + io->y = dec->cache_y_; + io->u = dec->cache_u_; + io->v = dec->cache_v_; + io->y_stride = dec->cache_y_stride_; + io->uv_stride = dec->cache_uv_stride_; + io->a = NULL; +} + +int VP8InitFrame(VP8Decoder* const dec, VP8Io* io) { + if (!InitThreadContext(dec)) return 0; // call first. Sets dec->num_caches_. + if (!AllocateMemory(dec)) return 0; + InitIo(dec, io); + VP8DspInit(); // Init critical function pointers and look-up tables. + return 1; +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/dec/io.cpp b/components/thorvg-main/src/loaders/webp/dec/io.cpp new file mode 100644 index 0000000..6ad6baf --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/io.cpp @@ -0,0 +1,392 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// functions for sample output. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include +#include "tvgCommon.h" +#include "../dec/vp8i.h" +#include "./webpi.h" +#include "../dsp/dsp.h" +#include "../dsp/yuv.h" +#include "../utils/utils.h" + + +// Point-sampling U/V sampler. +static int EmitSampledRGB(const VP8Io* const io, WebPDecParams* const p) { + WebPDecBuffer* const output = p->output; + WebPRGBABuffer* const buf = &output->u.RGBA; + uint8_t* const dst = buf->rgba + io->mb_y * buf->stride; + WebPSamplerProcessPlane(io->y, io->y_stride, + io->u, io->v, io->uv_stride, + dst, buf->stride, io->mb_w, io->mb_h, + WebPSamplers[output->colorspace]); + return io->mb_h; +} + +//------------------------------------------------------------------------------ +// Fancy upsampling + +#ifdef FANCY_UPSAMPLING +static int EmitFancyRGB(const VP8Io* const io, WebPDecParams* const p) { + int num_lines_out = io->mb_h; // a priori guess + const WebPRGBABuffer* const buf = &p->output->u.RGBA; + uint8_t* dst = buf->rgba + io->mb_y * buf->stride; + WebPUpsampleLinePairFunc upsample = WebPUpsamplers[p->output->colorspace]; + const uint8_t* cur_y = io->y; + const uint8_t* cur_u = io->u; + const uint8_t* cur_v = io->v; + const uint8_t* top_u = p->tmp_u; + const uint8_t* top_v = p->tmp_v; + int y = io->mb_y; + const int y_end = io->mb_y + io->mb_h; + const int mb_w = io->mb_w; + const int uv_w = (mb_w + 1) / 2; + + if (y == 0) { + // First line is special cased. We mirror the u/v samples at boundary. + upsample(cur_y, NULL, cur_u, cur_v, cur_u, cur_v, dst, NULL, mb_w); + } else { + // We can finish the left-over line from previous call. + upsample(p->tmp_y, cur_y, top_u, top_v, cur_u, cur_v, + dst - buf->stride, dst, mb_w); + ++num_lines_out; + } + // Loop over each output pairs of row. + for (; y + 2 < y_end; y += 2) { + top_u = cur_u; + top_v = cur_v; + cur_u += io->uv_stride; + cur_v += io->uv_stride; + dst += 2 * buf->stride; + cur_y += 2 * io->y_stride; + upsample(cur_y - io->y_stride, cur_y, + top_u, top_v, cur_u, cur_v, + dst - buf->stride, dst, mb_w); + } + // move to last row + cur_y += io->y_stride; + if (io->crop_top + y_end < io->crop_bottom) { + // Save the unfinished samples for next call (as we're not done yet). + memcpy(p->tmp_y, cur_y, mb_w * sizeof(*p->tmp_y)); + memcpy(p->tmp_u, cur_u, uv_w * sizeof(*p->tmp_u)); + memcpy(p->tmp_v, cur_v, uv_w * sizeof(*p->tmp_v)); + // The fancy upsampler leaves a row unfinished behind + // (except for the very last row) + num_lines_out--; + } else { + // Process the very last row of even-sized picture + if (!(y_end & 1)) { + upsample(cur_y, NULL, cur_u, cur_v, cur_u, cur_v, + dst + buf->stride, NULL, mb_w); + } + } + return num_lines_out; +} + +#endif /* FANCY_UPSAMPLING */ + +//------------------------------------------------------------------------------ + + +static int GetAlphaSourceRow(const VP8Io* const io, + const uint8_t** alpha, int* const num_rows) { + int start_y = io->mb_y; + *num_rows = io->mb_h; + + // Compensate for the 1-line delay of the fancy upscaler. + // This is similar to EmitFancyRGB(). + if (io->fancy_upsampling) { + if (start_y == 0) { + // We don't process the last row yet. It'll be done during the next call. + --*num_rows; + } else { + --start_y; + // Fortunately, *alpha data is persistent, so we can go back + // one row and finish alpha blending, now that the fancy upscaler + // completed the YUV->RGB interpolation. + *alpha -= io->width; + } + if (io->crop_top + io->mb_y + io->mb_h == io->crop_bottom) { + // If it's the very last call, we process all the remaining rows! + *num_rows = io->crop_bottom - io->crop_top - start_y; + } + } + return start_y; +} + +static int EmitAlphaRGB(const VP8Io* const io, WebPDecParams* const p) { + const uint8_t* alpha = io->a; + if (alpha != NULL) { + const int mb_w = io->mb_w; + const WEBP_CSP_MODE colorspace = p->output->colorspace; + const int alpha_first = + (colorspace == MODE_ARGB || colorspace == MODE_Argb); + const WebPRGBABuffer* const buf = &p->output->u.RGBA; + int num_rows; + const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows); + uint8_t* const base_rgba = buf->rgba + start_y * buf->stride; + uint8_t* const dst = base_rgba + (alpha_first ? 0 : 3); + const int has_alpha = WebPDispatchAlpha(alpha, io->width, mb_w, + num_rows, dst, buf->stride); + + // has_alpha is true if there's non-trivial alpha to premultiply with. + if (has_alpha && WebPIsPremultipliedMode(colorspace)) { + WebPApplyAlphaMultiply(base_rgba, alpha_first, + mb_w, num_rows, buf->stride); + } + } + return 0; +} + + +//------------------------------------------------------------------------------ +// RGBA rescaling + +static int ExportRGB(WebPDecParams* const p, int y_pos) { + const WebPYUV444Converter convert = + WebPYUV444Converters[p->output->colorspace]; + const WebPRGBABuffer* const buf = &p->output->u.RGBA; + uint8_t* dst = buf->rgba + (p->last_y + y_pos) * buf->stride; + int num_lines_out = 0; + // For RGB rescaling, because of the YUV420, current scan position + // U/V can be +1/-1 line from the Y one. Hence the double test. + while (WebPRescalerHasPendingOutput(&p->scaler_y) && + WebPRescalerHasPendingOutput(&p->scaler_u)) { + assert(p->last_y + y_pos + num_lines_out < p->output->height); + assert(p->scaler_u.y_accum == p->scaler_v.y_accum); + WebPRescalerExportRow(&p->scaler_y, 0); + WebPRescalerExportRow(&p->scaler_u, 0); + WebPRescalerExportRow(&p->scaler_v, 0); + convert(p->scaler_y.dst, p->scaler_u.dst, p->scaler_v.dst, + dst, p->scaler_y.dst_width); + dst += buf->stride; + ++num_lines_out; + } + return num_lines_out; +} + +static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) { + const int mb_h = io->mb_h; + const int uv_mb_h = (mb_h + 1) >> 1; + int j = 0, uv_j = 0; + int num_lines_out = 0; + while (j < mb_h) { + const int y_lines_in = + WebPRescalerImport(&p->scaler_y, mb_h - j, + io->y + j * io->y_stride, io->y_stride); + const int u_lines_in = + WebPRescalerImport(&p->scaler_u, uv_mb_h - uv_j, + io->u + uv_j * io->uv_stride, io->uv_stride); + const int v_lines_in = + WebPRescalerImport(&p->scaler_v, uv_mb_h - uv_j, + io->v + uv_j * io->uv_stride, io->uv_stride); + (void)v_lines_in; // remove a gcc warning + assert(u_lines_in == v_lines_in); + j += y_lines_in; + uv_j += u_lines_in; + num_lines_out += ExportRGB(p, num_lines_out); + } + return num_lines_out; +} + +static int ExportAlpha(WebPDecParams* const p, int y_pos) { + const WebPRGBABuffer* const buf = &p->output->u.RGBA; + uint8_t* const base_rgba = buf->rgba + (p->last_y + y_pos) * buf->stride; + const WEBP_CSP_MODE colorspace = p->output->colorspace; + const int alpha_first = + (colorspace == MODE_ARGB || colorspace == MODE_Argb); + uint8_t* dst = base_rgba + (alpha_first ? 0 : 3); + int num_lines_out = 0; + const int is_premult_alpha = WebPIsPremultipliedMode(colorspace); + uint32_t alpha_mask = 0xff; + const int width = p->scaler_a.dst_width; + + while (WebPRescalerHasPendingOutput(&p->scaler_a)) { + int i; + assert(p->last_y + y_pos + num_lines_out < p->output->height); + WebPRescalerExportRow(&p->scaler_a, 0); + for (i = 0; i < width; ++i) { + const uint32_t alpha_value = p->scaler_a.dst[i]; + dst[4 * i] = alpha_value; + alpha_mask &= alpha_value; + } + dst += buf->stride; + ++num_lines_out; + } + if (is_premult_alpha && alpha_mask != 0xff) { + WebPApplyAlphaMultiply(base_rgba, alpha_first, + width, num_lines_out, buf->stride); + } + return num_lines_out; +} + +static int EmitRescaledAlphaRGB(const VP8Io* const io, WebPDecParams* const p) { + if (io->a != NULL) { + WebPRescaler* const scaler = &p->scaler_a; + int j = 0; + int pos = 0; + while (j < io->mb_h) { + j += WebPRescalerImport(scaler, io->mb_h - j, + io->a + j * io->width, io->width); + pos += p->emit_alpha_row(p, pos); + } + } + return 0; +} + +static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) { + const int has_alpha = WebPIsAlphaMode(p->output->colorspace); + const int out_width = io->scaled_width; + const int out_height = io->scaled_height; + const int uv_in_width = (io->mb_w + 1) >> 1; + const int uv_in_height = (io->mb_h + 1) >> 1; + const size_t work_size = 2 * out_width; // scratch memory for one rescaler + int32_t* work; // rescalers work area + uint8_t* tmp; // tmp storage for scaled YUV444 samples before RGB conversion + size_t tmp_size1, tmp_size2, total_size; + + tmp_size1 = 3 * work_size; + tmp_size2 = 3 * out_width; + if (has_alpha) { + tmp_size1 += work_size; + tmp_size2 += out_width; + } + total_size = tmp_size1 * sizeof(*work) + tmp_size2 * sizeof(*tmp); + p->memory = tvg::calloc(1ULL, total_size); + if (p->memory == NULL) { + return 0; // memory error + } + work = (int32_t*)p->memory; + tmp = (uint8_t*)(work + tmp_size1); + WebPRescalerInit(&p->scaler_y, io->mb_w, io->mb_h, + tmp + 0 * out_width, out_width, out_height, 0, 1, + io->mb_w, out_width, io->mb_h, out_height, + work + 0 * work_size); + WebPRescalerInit(&p->scaler_u, uv_in_width, uv_in_height, + tmp + 1 * out_width, out_width, out_height, 0, 1, + io->mb_w, 2 * out_width, io->mb_h, 2 * out_height, + work + 1 * work_size); + WebPRescalerInit(&p->scaler_v, uv_in_width, uv_in_height, + tmp + 2 * out_width, out_width, out_height, 0, 1, + io->mb_w, 2 * out_width, io->mb_h, 2 * out_height, + work + 2 * work_size); + p->emit = EmitRescaledRGB; + WebPInitYUV444Converters(); + + if (has_alpha) { + WebPRescalerInit(&p->scaler_a, io->mb_w, io->mb_h, + tmp + 3 * out_width, out_width, out_height, 0, 1, + io->mb_w, out_width, io->mb_h, out_height, + work + 3 * work_size); + p->emit_alpha = EmitRescaledAlphaRGB; + p->emit_alpha_row = ExportAlpha; + WebPInitAlphaProcessing(); + } + return 1; +} + +//------------------------------------------------------------------------------ +// Default custom functions + +static int CustomSetup(VP8Io* io) { + WebPDecParams* const p = (WebPDecParams*)io->opaque; + const WEBP_CSP_MODE colorspace = p->output->colorspace; + const int is_rgb = WebPIsRGBMode(colorspace); + const int is_alpha = WebPIsAlphaMode(colorspace); + + p->memory = NULL; + p->emit = NULL; + p->emit_alpha = NULL; + p->emit_alpha_row = NULL; + + if (!WebPIoInitFromOptions(p->options, io, is_alpha ? MODE_YUV : MODE_YUVA)) { + return 0; + } + if (is_alpha && WebPIsPremultipliedMode(colorspace)) { + WebPInitUpsamplers(); + } + if (io->use_scaling) { + const int ok = InitRGBRescaler(io, p); + if (!ok) { + return 0; // memory error + } + } else { + if (is_rgb) { + p->emit = EmitSampledRGB; // default + if (io->fancy_upsampling) { +#ifdef FANCY_UPSAMPLING + const int uv_width = (io->mb_w + 1) >> 1; + p->memory = WebPSafeMalloc(1ULL, (size_t)(io->mb_w + 2 * uv_width)); + if (p->memory == NULL) { + return 0; // memory error. + } + p->tmp_y = (uint8_t*)p->memory; + p->tmp_u = p->tmp_y + io->mb_w; + p->tmp_v = p->tmp_u + uv_width; + p->emit = EmitFancyRGB; + WebPInitUpsamplers(); +#endif + } else { + WebPInitSamplers(); + } + } + if (is_alpha) { // need transparency output + p->emit_alpha = EmitAlphaRGB; + if (is_rgb) WebPInitAlphaProcessing(); + } + } + + if (is_rgb) { + VP8YUVInit(); + } + return 1; +} + +//------------------------------------------------------------------------------ + +static int CustomPut(const VP8Io* io) { + WebPDecParams* const p = (WebPDecParams*)io->opaque; + const int mb_w = io->mb_w; + const int mb_h = io->mb_h; + int num_lines_out; + assert(!(io->mb_y & 1)); + + if (mb_w <= 0 || mb_h <= 0) { + return 0; + } + num_lines_out = p->emit(io, p); + if (p->emit_alpha != NULL) { + p->emit_alpha(io, p); + } + p->last_y += num_lines_out; + return 1; +} + +//------------------------------------------------------------------------------ + +static void CustomTeardown(const VP8Io* io) { + WebPDecParams* const p = (WebPDecParams*)io->opaque; + tvg::free(p->memory); + p->memory = NULL; +} + +//------------------------------------------------------------------------------ +// Main entry point + +void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io) { + io->put = CustomPut; + io->setup = CustomSetup; + io->teardown = CustomTeardown; + io->opaque = params; +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/dec/meson.build b/components/thorvg-main/src/loaders/webp/dec/meson.build new file mode 100644 index 0000000..7a35e28 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/meson.build @@ -0,0 +1,22 @@ +source_file = [ + 'alphai.h', + 'common.h', + 'decode_vp8.h', + 'vp8i.h', + 'vp8li.h', + 'webpi.h', + 'alpha.cpp', + 'buffer.cpp', + 'frame.cpp', + 'io.cpp', + 'quant.cpp', + 'tree.cpp', + 'vp8.cpp', + 'vp8l.cpp', + 'webp.cpp' +] + +webp_deb += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/loaders/webp/dec/quant.cpp b/components/thorvg-main/src/loaders/webp/dec/quant.cpp new file mode 100644 index 0000000..5b648f9 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/quant.cpp @@ -0,0 +1,110 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Quantizer initialization +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "./vp8i.h" + +static WEBP_INLINE int clip(int v, int M) { + return v < 0 ? 0 : v > M ? M : v; +} + +// Paragraph 14.1 +static const uint8_t kDcTable[128] = { + 4, 5, 6, 7, 8, 9, 10, 10, + 11, 12, 13, 14, 15, 16, 17, 17, + 18, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 25, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, + 37, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, + 91, 93, 95, 96, 98, 100, 101, 102, + 104, 106, 108, 110, 112, 114, 116, 118, + 122, 124, 126, 128, 130, 132, 134, 136, + 138, 140, 143, 145, 148, 151, 154, 157 +}; + +static const uint16_t kAcTable[128] = { + 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 60, + 62, 64, 66, 68, 70, 72, 74, 76, + 78, 80, 82, 84, 86, 88, 90, 92, + 94, 96, 98, 100, 102, 104, 106, 108, + 110, 112, 114, 116, 119, 122, 125, 128, + 131, 134, 137, 140, 143, 146, 149, 152, + 155, 158, 161, 164, 167, 170, 173, 177, + 181, 185, 189, 193, 197, 201, 205, 209, + 213, 217, 221, 225, 229, 234, 239, 245, + 249, 254, 259, 264, 269, 274, 279, 284 +}; + +//------------------------------------------------------------------------------ +// Paragraph 9.6 + +void VP8ParseQuant(VP8Decoder* const dec) { + VP8BitReader* const br = &dec->br_; + const int base_q0 = VP8GetValue(br, 7); + const int dqy1_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; + const int dqy2_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; + const int dqy2_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; + const int dquv_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; + const int dquv_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; + + const VP8SegmentHeader* const hdr = &dec->segment_hdr_; + int i; + + for (i = 0; i < NUM_MB_SEGMENTS; ++i) { + int q; + if (hdr->use_segment_) { + q = hdr->quantizer_[i]; + if (!hdr->absolute_delta_) { + q += base_q0; + } + } else { + if (i > 0) { + dec->dqm_[i] = dec->dqm_[0]; + continue; + } else { + q = base_q0; + } + } + { + VP8QuantMatrix* const m = &dec->dqm_[i]; + m->y1_mat_[0] = kDcTable[clip(q + dqy1_dc, 127)]; + m->y1_mat_[1] = kAcTable[clip(q + 0, 127)]; + + m->y2_mat_[0] = kDcTable[clip(q + dqy2_dc, 127)] * 2; + // For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16. + // The smallest precision for that is '(x*6349) >> 12' but 16 is a good + // word size. + m->y2_mat_[1] = (kAcTable[clip(q + dqy2_ac, 127)] * 101581) >> 16; + if (m->y2_mat_[1] < 8) m->y2_mat_[1] = 8; + + m->uv_mat_[0] = kDcTable[clip(q + dquv_dc, 117)]; + m->uv_mat_[1] = kAcTable[clip(q + dquv_ac, 127)]; + + m->uv_quant_ = q + dquv_ac; // for dithering strength evaluation + } + } +} + +//------------------------------------------------------------------------------ + diff --git a/components/thorvg-main/src/loaders/webp/dec/tree.cpp b/components/thorvg-main/src/loaders/webp/dec/tree.cpp new file mode 100644 index 0000000..c2007ea --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/tree.cpp @@ -0,0 +1,525 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Coding trees and probas +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "./vp8i.h" +#include "../utils/bit_reader_inl.h" + +#define USE_GENERIC_TREE + +#ifdef USE_GENERIC_TREE +static const int8_t kYModesIntra4[18] = { + -B_DC_PRED, 1, + -B_TM_PRED, 2, + -B_VE_PRED, 3, + 4, 6, + -B_HE_PRED, 5, + -B_RD_PRED, -B_VR_PRED, + -B_LD_PRED, 7, + -B_VL_PRED, 8, + -B_HD_PRED, -B_HU_PRED +}; +#endif + +//------------------------------------------------------------------------------ +// Default probabilities + +// Paragraph 13.5 +static const uint8_t + CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = { + { { { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } + }, + { { 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128 }, + { 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128 }, + { 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128 } + }, + { { 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128 }, + { 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128 }, + { 78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128 }, + }, + { { 1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128 }, + { 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128 }, + { 77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128 }, + }, + { { 1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128 }, + { 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128 }, + { 37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128 } + }, + { { 1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128 }, + { 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128 }, + { 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128 } + }, + { { 1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128 }, + { 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128 }, + { 80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128 } + }, + { { 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 246, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } + } + }, + { { { 198, 35, 237, 223, 193, 187, 162, 160, 145, 155, 62 }, + { 131, 45, 198, 221, 172, 176, 220, 157, 252, 221, 1 }, + { 68, 47, 146, 208, 149, 167, 221, 162, 255, 223, 128 } + }, + { { 1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128 }, + { 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128 }, + { 81, 99, 181, 242, 176, 190, 249, 202, 255, 255, 128 } + }, + { { 1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128 }, + { 99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128 }, + { 23, 91, 163, 242, 170, 187, 247, 210, 255, 255, 128 } + }, + { { 1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128 }, + { 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128 }, + { 44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128 } + }, + { { 1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128 }, + { 94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128 }, + { 22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128 } + }, + { { 1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128 }, + { 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128 }, + { 35, 77, 181, 251, 193, 211, 255, 205, 128, 128, 128 } + }, + { { 1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128 }, + { 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128 }, + { 45, 99, 188, 251, 195, 217, 255, 224, 128, 128, 128 } + }, + { { 1, 1, 251, 255, 213, 255, 128, 128, 128, 128, 128 }, + { 203, 1, 248, 255, 255, 128, 128, 128, 128, 128, 128 }, + { 137, 1, 177, 255, 224, 255, 128, 128, 128, 128, 128 } + } + }, + { { { 253, 9, 248, 251, 207, 208, 255, 192, 128, 128, 128 }, + { 175, 13, 224, 243, 193, 185, 249, 198, 255, 255, 128 }, + { 73, 17, 171, 221, 161, 179, 236, 167, 255, 234, 128 } + }, + { { 1, 95, 247, 253, 212, 183, 255, 255, 128, 128, 128 }, + { 239, 90, 244, 250, 211, 209, 255, 255, 128, 128, 128 }, + { 155, 77, 195, 248, 188, 195, 255, 255, 128, 128, 128 } + }, + { { 1, 24, 239, 251, 218, 219, 255, 205, 128, 128, 128 }, + { 201, 51, 219, 255, 196, 186, 128, 128, 128, 128, 128 }, + { 69, 46, 190, 239, 201, 218, 255, 228, 128, 128, 128 } + }, + { { 1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128 }, + { 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128 }, + { 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128 } + }, + { { 1, 16, 248, 255, 255, 128, 128, 128, 128, 128, 128 }, + { 190, 36, 230, 255, 236, 255, 128, 128, 128, 128, 128 }, + { 149, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128 } + }, + { { 1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128 } + }, + { { 1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128 }, + { 213, 62, 250, 255, 255, 128, 128, 128, 128, 128, 128 }, + { 55, 93, 255, 128, 128, 128, 128, 128, 128, 128, 128 } + }, + { { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } + } + }, + { { { 202, 24, 213, 235, 186, 191, 220, 160, 240, 175, 255 }, + { 126, 38, 182, 232, 169, 184, 228, 174, 255, 187, 128 }, + { 61, 46, 138, 219, 151, 178, 240, 170, 255, 216, 128 } + }, + { { 1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128 }, + { 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128 }, + { 39, 77, 162, 232, 172, 180, 245, 178, 255, 255, 128 } + }, + { { 1, 52, 220, 246, 198, 199, 249, 220, 255, 255, 128 }, + { 124, 74, 191, 243, 183, 193, 250, 221, 255, 255, 128 }, + { 24, 71, 130, 219, 154, 170, 243, 182, 255, 255, 128 } + }, + { { 1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128 }, + { 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128 }, + { 28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128 } + }, + { { 1, 81, 230, 252, 204, 203, 255, 192, 128, 128, 128 }, + { 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128 }, + { 20, 95, 153, 243, 164, 173, 255, 203, 128, 128, 128 } + }, + { { 1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128 }, + { 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128 }, + { 47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128 } + }, + { { 1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128 }, + { 141, 84, 213, 252, 201, 202, 255, 219, 128, 128, 128 }, + { 42, 80, 160, 240, 162, 185, 255, 205, 128, 128, 128 } + }, + { { 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128 }, + { 238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128 } + } + } +}; + +// Paragraph 11.5 +static const uint8_t kBModesProba[NUM_BMODES][NUM_BMODES][NUM_BMODES - 1] = { + { { 231, 120, 48, 89, 115, 113, 120, 152, 112 }, + { 152, 179, 64, 126, 170, 118, 46, 70, 95 }, + { 175, 69, 143, 80, 85, 82, 72, 155, 103 }, + { 56, 58, 10, 171, 218, 189, 17, 13, 152 }, + { 114, 26, 17, 163, 44, 195, 21, 10, 173 }, + { 121, 24, 80, 195, 26, 62, 44, 64, 85 }, + { 144, 71, 10, 38, 171, 213, 144, 34, 26 }, + { 170, 46, 55, 19, 136, 160, 33, 206, 71 }, + { 63, 20, 8, 114, 114, 208, 12, 9, 226 }, + { 81, 40, 11, 96, 182, 84, 29, 16, 36 } }, + { { 134, 183, 89, 137, 98, 101, 106, 165, 148 }, + { 72, 187, 100, 130, 157, 111, 32, 75, 80 }, + { 66, 102, 167, 99, 74, 62, 40, 234, 128 }, + { 41, 53, 9, 178, 241, 141, 26, 8, 107 }, + { 74, 43, 26, 146, 73, 166, 49, 23, 157 }, + { 65, 38, 105, 160, 51, 52, 31, 115, 128 }, + { 104, 79, 12, 27, 217, 255, 87, 17, 7 }, + { 87, 68, 71, 44, 114, 51, 15, 186, 23 }, + { 47, 41, 14, 110, 182, 183, 21, 17, 194 }, + { 66, 45, 25, 102, 197, 189, 23, 18, 22 } }, + { { 88, 88, 147, 150, 42, 46, 45, 196, 205 }, + { 43, 97, 183, 117, 85, 38, 35, 179, 61 }, + { 39, 53, 200, 87, 26, 21, 43, 232, 171 }, + { 56, 34, 51, 104, 114, 102, 29, 93, 77 }, + { 39, 28, 85, 171, 58, 165, 90, 98, 64 }, + { 34, 22, 116, 206, 23, 34, 43, 166, 73 }, + { 107, 54, 32, 26, 51, 1, 81, 43, 31 }, + { 68, 25, 106, 22, 64, 171, 36, 225, 114 }, + { 34, 19, 21, 102, 132, 188, 16, 76, 124 }, + { 62, 18, 78, 95, 85, 57, 50, 48, 51 } }, + { { 193, 101, 35, 159, 215, 111, 89, 46, 111 }, + { 60, 148, 31, 172, 219, 228, 21, 18, 111 }, + { 112, 113, 77, 85, 179, 255, 38, 120, 114 }, + { 40, 42, 1, 196, 245, 209, 10, 25, 109 }, + { 88, 43, 29, 140, 166, 213, 37, 43, 154 }, + { 61, 63, 30, 155, 67, 45, 68, 1, 209 }, + { 100, 80, 8, 43, 154, 1, 51, 26, 71 }, + { 142, 78, 78, 16, 255, 128, 34, 197, 171 }, + { 41, 40, 5, 102, 211, 183, 4, 1, 221 }, + { 51, 50, 17, 168, 209, 192, 23, 25, 82 } }, + { { 138, 31, 36, 171, 27, 166, 38, 44, 229 }, + { 67, 87, 58, 169, 82, 115, 26, 59, 179 }, + { 63, 59, 90, 180, 59, 166, 93, 73, 154 }, + { 40, 40, 21, 116, 143, 209, 34, 39, 175 }, + { 47, 15, 16, 183, 34, 223, 49, 45, 183 }, + { 46, 17, 33, 183, 6, 98, 15, 32, 183 }, + { 57, 46, 22, 24, 128, 1, 54, 17, 37 }, + { 65, 32, 73, 115, 28, 128, 23, 128, 205 }, + { 40, 3, 9, 115, 51, 192, 18, 6, 223 }, + { 87, 37, 9, 115, 59, 77, 64, 21, 47 } }, + { { 104, 55, 44, 218, 9, 54, 53, 130, 226 }, + { 64, 90, 70, 205, 40, 41, 23, 26, 57 }, + { 54, 57, 112, 184, 5, 41, 38, 166, 213 }, + { 30, 34, 26, 133, 152, 116, 10, 32, 134 }, + { 39, 19, 53, 221, 26, 114, 32, 73, 255 }, + { 31, 9, 65, 234, 2, 15, 1, 118, 73 }, + { 75, 32, 12, 51, 192, 255, 160, 43, 51 }, + { 88, 31, 35, 67, 102, 85, 55, 186, 85 }, + { 56, 21, 23, 111, 59, 205, 45, 37, 192 }, + { 55, 38, 70, 124, 73, 102, 1, 34, 98 } }, + { { 125, 98, 42, 88, 104, 85, 117, 175, 82 }, + { 95, 84, 53, 89, 128, 100, 113, 101, 45 }, + { 75, 79, 123, 47, 51, 128, 81, 171, 1 }, + { 57, 17, 5, 71, 102, 57, 53, 41, 49 }, + { 38, 33, 13, 121, 57, 73, 26, 1, 85 }, + { 41, 10, 67, 138, 77, 110, 90, 47, 114 }, + { 115, 21, 2, 10, 102, 255, 166, 23, 6 }, + { 101, 29, 16, 10, 85, 128, 101, 196, 26 }, + { 57, 18, 10, 102, 102, 213, 34, 20, 43 }, + { 117, 20, 15, 36, 163, 128, 68, 1, 26 } }, + { { 102, 61, 71, 37, 34, 53, 31, 243, 192 }, + { 69, 60, 71, 38, 73, 119, 28, 222, 37 }, + { 68, 45, 128, 34, 1, 47, 11, 245, 171 }, + { 62, 17, 19, 70, 146, 85, 55, 62, 70 }, + { 37, 43, 37, 154, 100, 163, 85, 160, 1 }, + { 63, 9, 92, 136, 28, 64, 32, 201, 85 }, + { 75, 15, 9, 9, 64, 255, 184, 119, 16 }, + { 86, 6, 28, 5, 64, 255, 25, 248, 1 }, + { 56, 8, 17, 132, 137, 255, 55, 116, 128 }, + { 58, 15, 20, 82, 135, 57, 26, 121, 40 } }, + { { 164, 50, 31, 137, 154, 133, 25, 35, 218 }, + { 51, 103, 44, 131, 131, 123, 31, 6, 158 }, + { 86, 40, 64, 135, 148, 224, 45, 183, 128 }, + { 22, 26, 17, 131, 240, 154, 14, 1, 209 }, + { 45, 16, 21, 91, 64, 222, 7, 1, 197 }, + { 56, 21, 39, 155, 60, 138, 23, 102, 213 }, + { 83, 12, 13, 54, 192, 255, 68, 47, 28 }, + { 85, 26, 85, 85, 128, 128, 32, 146, 171 }, + { 18, 11, 7, 63, 144, 171, 4, 4, 246 }, + { 35, 27, 10, 146, 174, 171, 12, 26, 128 } }, + { { 190, 80, 35, 99, 180, 80, 126, 54, 45 }, + { 85, 126, 47, 87, 176, 51, 41, 20, 32 }, + { 101, 75, 128, 139, 118, 146, 116, 128, 85 }, + { 56, 41, 15, 176, 236, 85, 37, 9, 62 }, + { 71, 30, 17, 119, 118, 255, 17, 18, 138 }, + { 101, 38, 60, 138, 55, 70, 43, 26, 142 }, + { 146, 36, 19, 30, 171, 255, 97, 27, 20 }, + { 138, 45, 61, 62, 219, 1, 81, 188, 64 }, + { 32, 41, 20, 117, 151, 142, 20, 21, 163 }, + { 112, 19, 12, 61, 195, 128, 48, 4, 24 } } +}; + +void VP8ResetProba(VP8Proba* const proba) { + memset(proba->segments_, 255u, sizeof(proba->segments_)); + // proba->bands_[][] is initialized later +} + +static void ParseIntraMode(VP8BitReader* const br, + VP8Decoder* const dec, int mb_x) { + uint8_t* const top = dec->intra_t_ + 4 * mb_x; + uint8_t* const left = dec->intra_l_; + VP8MBData* const block = dec->mb_data_ + mb_x; + + // Note: we don't save segment map (yet), as we don't expect + // to decode more than 1 keyframe. + if (dec->segment_hdr_.update_map_) { + // Hardcoded tree parsing + block->segment_ = !VP8GetBit(br, dec->proba_.segments_[0]) + ? VP8GetBit(br, dec->proba_.segments_[1]) + : 2 + VP8GetBit(br, dec->proba_.segments_[2]); + } else { + block->segment_ = 0; // default for intra + } + if (dec->use_skip_proba_) block->skip_ = VP8GetBit(br, dec->skip_p_); + + block->is_i4x4_ = !VP8GetBit(br, 145); // decide for B_PRED first + if (!block->is_i4x4_) { + // Hardcoded 16x16 intra-mode decision tree. + const int ymode = + VP8GetBit(br, 156) ? (VP8GetBit(br, 128) ? TM_PRED : H_PRED) + : (VP8GetBit(br, 163) ? V_PRED : DC_PRED); + block->imodes_[0] = ymode; + memset(top, ymode, 4 * sizeof(*top)); + memset(left, ymode, 4 * sizeof(*left)); + } else { + uint8_t* modes = block->imodes_; + int y; + for (y = 0; y < 4; ++y) { + int ymode = left[y]; + int x; + for (x = 0; x < 4; ++x) { + const uint8_t* const prob = kBModesProba[top[x]][ymode]; +#ifdef USE_GENERIC_TREE + // Generic tree-parsing + int i = kYModesIntra4[VP8GetBit(br, prob[0])]; + while (i > 0) { + i = kYModesIntra4[2 * i + VP8GetBit(br, prob[i])]; + } + ymode = -i; +#else + // Hardcoded tree parsing + ymode = !VP8GetBit(br, prob[0]) ? B_DC_PRED : + !VP8GetBit(br, prob[1]) ? B_TM_PRED : + !VP8GetBit(br, prob[2]) ? B_VE_PRED : + !VP8GetBit(br, prob[3]) ? + (!VP8GetBit(br, prob[4]) ? B_HE_PRED : + (!VP8GetBit(br, prob[5]) ? B_RD_PRED : B_VR_PRED)) : + (!VP8GetBit(br, prob[6]) ? B_LD_PRED : + (!VP8GetBit(br, prob[7]) ? B_VL_PRED : + (!VP8GetBit(br, prob[8]) ? B_HD_PRED : B_HU_PRED))); +#endif // USE_GENERIC_TREE + top[x] = ymode; + } + memcpy(modes, top, 4 * sizeof(*top)); + modes += 4; + left[y] = ymode; + } + } + // Hardcoded UVMode decision tree + block->uvmode_ = !VP8GetBit(br, 142) ? DC_PRED + : !VP8GetBit(br, 114) ? V_PRED + : VP8GetBit(br, 183) ? TM_PRED : H_PRED; +} + +int VP8ParseIntraModeRow(VP8BitReader* const br, VP8Decoder* const dec) { + int mb_x; + for (mb_x = 0; mb_x < dec->mb_w_; ++mb_x) { + ParseIntraMode(br, dec, mb_x); + } + return !dec->br_.eof_; +} + +//------------------------------------------------------------------------------ +// Paragraph 13 + +static const uint8_t + CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = { + { { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255 }, + { 250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + } + }, + { { { 217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255 }, + { 234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255 } + }, + { { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + } + }, + { { { 186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255 }, + { 251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255 } + }, + { { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + } + }, + { { { 248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255 }, + { 248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + }, + { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, + { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } + } + } +}; + +// Paragraph 9.9 + +static const int kBands[16 + 1] = { + 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, + 0 // extra entry as sentinel +}; + +void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec) { + VP8Proba* const proba = &dec->proba_; + int t, b, c, p; + for (t = 0; t < NUM_TYPES; ++t) { + for (b = 0; b < NUM_BANDS; ++b) { + for (c = 0; c < NUM_CTX; ++c) { + for (p = 0; p < NUM_PROBAS; ++p) { + const int v = VP8GetBit(br, CoeffsUpdateProba[t][b][c][p]) ? + VP8GetValue(br, 8) : CoeffsProba0[t][b][c][p]; + proba->bands_[t][b].probas_[c][p] = v; + } + } + } + for (b = 0; b < 16 + 1; ++b) { + proba->bands_ptr_[t][b] = &proba->bands_[t][kBands[b]]; + } + } + dec->use_skip_proba_ = VP8Get(br); + if (dec->use_skip_proba_) { + dec->skip_p_ = VP8GetValue(br, 8); + } +} + diff --git a/components/thorvg-main/src/loaders/webp/dec/vp8.cpp b/components/thorvg-main/src/loaders/webp/dec/vp8.cpp new file mode 100644 index 0000000..c0f9bd1 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/vp8.cpp @@ -0,0 +1,681 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// main entry for the decoder +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "tvgCommon.h" + +#include "./alphai.h" +#include "./vp8i.h" +#include "./vp8li.h" +#include "./webpi.h" +#include "../utils/bit_reader_inl.h" +#include "../utils/utils.h" + +//------------------------------------------------------------------------------ + +int WebPGetDecoderVersion(void) { + return (DEC_MAJ_VERSION << 16) | (DEC_MIN_VERSION << 8) | DEC_REV_VERSION; +} + +//------------------------------------------------------------------------------ +// VP8Decoder + +static void SetOk(VP8Decoder* const dec) { + dec->status_ = VP8_STATUS_OK; + dec->error_msg_ = "OK"; +} + +int VP8InitIoInternal(VP8Io* const io, int version) { + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DECODER_ABI_VERSION)) { + return 0; // mismatch error + } + if (io != NULL) { + memset(io, 0, sizeof(*io)); + } + return 1; +} + +VP8Decoder* VP8New(void) { + VP8Decoder* const dec = tvg::calloc(1ULL, sizeof(*dec)); + if (dec != NULL) { + SetOk(dec); + dec->ready_ = 0; + dec->num_parts_ = 1; + } + return dec; +} + +VP8StatusCode VP8Status(VP8Decoder* const dec) { + if (!dec) return VP8_STATUS_INVALID_PARAM; + return dec->status_; +} + +const char* VP8StatusMessage(VP8Decoder* const dec) { + if (dec == NULL) return "no object"; + if (!dec->error_msg_) return "OK"; + return dec->error_msg_; +} + +void VP8Delete(VP8Decoder* const dec) { + if (dec != NULL) { + VP8Clear(dec); + tvg::free(dec); + } +} + +int VP8SetError(VP8Decoder* const dec, + VP8StatusCode error, const char* const msg) { + // The oldest error reported takes precedence over the new one. + if (dec->status_ == VP8_STATUS_OK) { + dec->status_ = error; + dec->error_msg_ = msg; + dec->ready_ = 0; + } + return 0; +} + +//------------------------------------------------------------------------------ + +int VP8CheckSignature(const uint8_t* const data, size_t data_size) { + return (data_size >= 3 && + data[0] == 0x9d && data[1] == 0x01 && data[2] == 0x2a); +} + +int VP8GetInfo(const uint8_t* data, size_t data_size, size_t chunk_size, + int* const width, int* const height) { + if (data == NULL || data_size < VP8_FRAME_HEADER_SIZE) { + return 0; // not enough data + } + // check signature + if (!VP8CheckSignature(data + 3, data_size - 3)) { + return 0; // Wrong signature. + } else { + const uint32_t bits = data[0] | (data[1] << 8) | (data[2] << 16); + const int key_frame = !(bits & 1); + const int w = ((data[7] << 8) | data[6]) & 0x3fff; + const int h = ((data[9] << 8) | data[8]) & 0x3fff; + + if (!key_frame) { // Not a keyframe. + return 0; + } + + if (((bits >> 1) & 7) > 3) { + return 0; // unknown profile + } + if (!((bits >> 4) & 1)) { + return 0; // first frame is invisible! + } + if (((bits >> 5)) >= chunk_size) { // partition_length + return 0; // inconsistent size information. + } + if (w == 0 || h == 0) { + return 0; // We don't support both width and height to be zero. + } + + if (width) { + *width = w; + } + if (height) { + *height = h; + } + + return 1; + } +} + +//------------------------------------------------------------------------------ +// Header parsing + +static void ResetSegmentHeader(VP8SegmentHeader* const hdr) { + assert(hdr != NULL); + hdr->use_segment_ = 0; + hdr->update_map_ = 0; + hdr->absolute_delta_ = 1; + memset(hdr->quantizer_, 0, sizeof(hdr->quantizer_)); + memset(hdr->filter_strength_, 0, sizeof(hdr->filter_strength_)); +} + +// Paragraph 9.3 +static int ParseSegmentHeader(VP8BitReader* br, + VP8SegmentHeader* hdr, VP8Proba* proba) { + assert(br != NULL); + assert(hdr != NULL); + hdr->use_segment_ = VP8Get(br); + if (hdr->use_segment_) { + hdr->update_map_ = VP8Get(br); + if (VP8Get(br)) { // update data + int s; + hdr->absolute_delta_ = VP8Get(br); + for (s = 0; s < NUM_MB_SEGMENTS; ++s) { + hdr->quantizer_[s] = VP8Get(br) ? VP8GetSignedValue(br, 7) : 0; + } + for (s = 0; s < NUM_MB_SEGMENTS; ++s) { + hdr->filter_strength_[s] = VP8Get(br) ? VP8GetSignedValue(br, 6) : 0; + } + } + if (hdr->update_map_) { + int s; + for (s = 0; s < MB_FEATURE_TREE_PROBS; ++s) { + proba->segments_[s] = VP8Get(br) ? VP8GetValue(br, 8) : 255u; + } + } + } else { + hdr->update_map_ = 0; + } + return !br->eof_; +} + +// Paragraph 9.5 +// This function returns VP8_STATUS_SUSPENDED if we don't have all the +// necessary data in 'buf'. +// This case is not necessarily an error (for incremental decoding). +// Still, no bitreader is ever initialized to make it possible to read +// unavailable memory. +// If we don't even have the partitions' sizes, than VP8_STATUS_NOT_ENOUGH_DATA +// is returned, and this is an unrecoverable error. +// If the partitions were positioned ok, VP8_STATUS_OK is returned. +static VP8StatusCode ParsePartitions(VP8Decoder* const dec, + const uint8_t* buf, size_t size) { + VP8BitReader* const br = &dec->br_; + const uint8_t* sz = buf; + const uint8_t* buf_end = buf + size; + const uint8_t* part_start; + int last_part; + int p; + + dec->num_parts_ = 1 << VP8GetValue(br, 2); + last_part = dec->num_parts_ - 1; + part_start = buf + last_part * 3; + if (buf_end < part_start) { + // we can't even read the sizes with sz[]! That's a failure. + return VP8_STATUS_NOT_ENOUGH_DATA; + } + for (p = 0; p < last_part; ++p) { + const uint32_t psize = sz[0] | (sz[1] << 8) | (sz[2] << 16); + const uint8_t* part_end = part_start + psize; + if (part_end > buf_end) part_end = buf_end; + VP8InitBitReader(dec->parts_ + p, part_start, part_end); + part_start = part_end; + sz += 3; + } + VP8InitBitReader(dec->parts_ + last_part, part_start, buf_end); + return (part_start < buf_end) ? VP8_STATUS_OK : + VP8_STATUS_SUSPENDED; // Init is ok, but there's not enough data +} + +// Paragraph 9.4 +static int ParseFilterHeader(VP8BitReader* br, VP8Decoder* const dec) { + VP8FilterHeader* const hdr = &dec->filter_hdr_; + hdr->simple_ = VP8Get(br); + hdr->level_ = VP8GetValue(br, 6); + hdr->sharpness_ = VP8GetValue(br, 3); + hdr->use_lf_delta_ = VP8Get(br); + if (hdr->use_lf_delta_) { + if (VP8Get(br)) { // update lf-delta? + int i; + for (i = 0; i < NUM_REF_LF_DELTAS; ++i) { + if (VP8Get(br)) { + hdr->ref_lf_delta_[i] = VP8GetSignedValue(br, 6); + } + } + for (i = 0; i < NUM_MODE_LF_DELTAS; ++i) { + if (VP8Get(br)) { + hdr->mode_lf_delta_[i] = VP8GetSignedValue(br, 6); + } + } + } + } + dec->filter_type_ = (hdr->level_ == 0) ? 0 : hdr->simple_ ? 1 : 2; + return !br->eof_; +} + +// Topmost call +int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) { + const uint8_t* buf; + size_t buf_size; + VP8FrameHeader* frm_hdr; + VP8PictureHeader* pic_hdr; + VP8BitReader* br; + VP8StatusCode status; + + if (dec == NULL) { + return 0; + } + SetOk(dec); + if (io == NULL) { + return VP8SetError(dec, VP8_STATUS_INVALID_PARAM, + "null VP8Io passed to VP8GetHeaders()"); + } + buf = io->data; + buf_size = io->data_size; + if (buf_size < 4) { + return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA, + "Truncated header."); + } + + // Paragraph 9.1 + { + const uint32_t bits = buf[0] | (buf[1] << 8) | (buf[2] << 16); + frm_hdr = &dec->frm_hdr_; + frm_hdr->key_frame_ = !(bits & 1); + frm_hdr->profile_ = (bits >> 1) & 7; + frm_hdr->show_ = (bits >> 4) & 1; + frm_hdr->partition_length_ = (bits >> 5); + if (frm_hdr->profile_ > 3) + return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, + "Incorrect keyframe parameters."); + if (!frm_hdr->show_) + return VP8SetError(dec, VP8_STATUS_UNSUPPORTED_FEATURE, + "Frame not displayable."); + buf += 3; + buf_size -= 3; + } + + pic_hdr = &dec->pic_hdr_; + if (frm_hdr->key_frame_) { + // Paragraph 9.2 + if (buf_size < 7) { + return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA, + "cannot parse picture header"); + } + if (!VP8CheckSignature(buf, buf_size)) { + return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, + "Bad code word"); + } + pic_hdr->width_ = ((buf[4] << 8) | buf[3]) & 0x3fff; + pic_hdr->xscale_ = buf[4] >> 6; // ratio: 1, 5/4 5/3 or 2 + pic_hdr->height_ = ((buf[6] << 8) | buf[5]) & 0x3fff; + pic_hdr->yscale_ = buf[6] >> 6; + buf += 7; + buf_size -= 7; + + dec->mb_w_ = (pic_hdr->width_ + 15) >> 4; + dec->mb_h_ = (pic_hdr->height_ + 15) >> 4; + // Setup default output area (can be later modified during io->setup()) + io->width = pic_hdr->width_; + io->height = pic_hdr->height_; + io->use_scaling = 0; + io->use_cropping = 0; + io->crop_top = 0; + io->crop_left = 0; + io->crop_right = io->width; + io->crop_bottom = io->height; + io->mb_w = io->width; // sanity check + io->mb_h = io->height; // ditto + + VP8ResetProba(&dec->proba_); + ResetSegmentHeader(&dec->segment_hdr_); + } + + // Check if we have all the partition #0 available, and initialize dec->br_ + // to read this partition (and this partition only). + if (frm_hdr->partition_length_ > buf_size) { + return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA, + "bad partition length"); + } + + br = &dec->br_; + VP8InitBitReader(br, buf, buf + frm_hdr->partition_length_); + buf += frm_hdr->partition_length_; + buf_size -= frm_hdr->partition_length_; + + if (frm_hdr->key_frame_) { + pic_hdr->colorspace_ = VP8Get(br); + pic_hdr->clamp_type_ = VP8Get(br); + } + if (!ParseSegmentHeader(br, &dec->segment_hdr_, &dec->proba_)) { + return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, + "cannot parse segment header"); + } + // Filter specs + if (!ParseFilterHeader(br, dec)) { + return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, + "cannot parse filter header"); + } + status = ParsePartitions(dec, buf, buf_size); + if (status != VP8_STATUS_OK) { + return VP8SetError(dec, status, "cannot parse partitions"); + } + + // quantizer change + VP8ParseQuant(dec); + + // Frame buffer marking + if (!frm_hdr->key_frame_) { + return VP8SetError(dec, VP8_STATUS_UNSUPPORTED_FEATURE, + "Not a key frame."); + } + + VP8Get(br); // ignore the value of update_proba_ + + VP8ParseProba(br, dec); + + // sanitized state + dec->ready_ = 1; + return 1; +} + +//------------------------------------------------------------------------------ +// Residual decoding (Paragraph 13.2 / 13.3) + +static const uint8_t kCat3[] = { 173, 148, 140, 0 }; +static const uint8_t kCat4[] = { 176, 155, 140, 135, 0 }; +static const uint8_t kCat5[] = { 180, 157, 141, 134, 130, 0 }; +static const uint8_t kCat6[] = + { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 }; +static const uint8_t* const kCat3456[] = { kCat3, kCat4, kCat5, kCat6 }; +static const uint8_t kZigzag[16] = { + 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 +}; + +// See section 13-2: http://tools.ietf.org/html/rfc6386#section-13.2 +static int GetLargeValue(VP8BitReader* const br, const uint8_t* const p) { + int v; + if (!VP8GetBit(br, p[3])) { + if (!VP8GetBit(br, p[4])) { + v = 2; + } else { + v = 3 + VP8GetBit(br, p[5]); + } + } else { + if (!VP8GetBit(br, p[6])) { + if (!VP8GetBit(br, p[7])) { + v = 5 + VP8GetBit(br, 159); + } else { + v = 7 + 2 * VP8GetBit(br, 165); + v += VP8GetBit(br, 145); + } + } else { + const uint8_t* tab; + const int bit1 = VP8GetBit(br, p[8]); + const int bit0 = VP8GetBit(br, p[9 + bit1]); + const int cat = 2 * bit1 + bit0; + v = 0; + for (tab = kCat3456[cat]; *tab; ++tab) { + v += v + VP8GetBit(br, *tab); + } + v += 3 + (8 << cat); + } + } + return v; +} + +// Returns the position of the last non-zero coeff plus one +static int GetCoeffs(VP8BitReader* const br, const VP8BandProbas* const prob[], + int ctx, const quant_t dq, int n, int16_t* out) { + const uint8_t* p = prob[n]->probas_[ctx]; + for (; n < 16; ++n) { + if (!VP8GetBit(br, p[0])) { + return n; // previous coeff was last non-zero coeff + } + while (!VP8GetBit(br, p[1])) { // sequence of zero coeffs + p = prob[++n]->probas_[0]; + if (n == 16) return 16; + } + { // non zero coeff + const VP8ProbaArray* const p_ctx = &prob[n + 1]->probas_[0]; + int v; + if (!VP8GetBit(br, p[2])) { + v = 1; + p = p_ctx[1]; + } else { + v = GetLargeValue(br, p); + p = p_ctx[2]; + } + out[kZigzag[n]] = VP8GetSigned(br, v) * dq[n > 0]; + } + } + return 16; +} + +static WEBP_INLINE uint32_t NzCodeBits(uint32_t nz_coeffs, int nz, int dc_nz) { + nz_coeffs <<= 2; + nz_coeffs |= (nz > 3) ? 3 : (nz > 1) ? 2 : dc_nz; + return nz_coeffs; +} + +static void TransformWHT(const int16_t* in, int16_t* out) { + int tmp[16]; + int i; + for (i = 0; i < 4; ++i) { + const int a0 = in[0 + i] + in[12 + i]; + const int a1 = in[4 + i] + in[ 8 + i]; + const int a2 = in[4 + i] - in[ 8 + i]; + const int a3 = in[0 + i] - in[12 + i]; + tmp[0 + i] = a0 + a1; + tmp[8 + i] = a0 - a1; + tmp[4 + i] = a3 + a2; + tmp[12 + i] = a3 - a2; + } + for (i = 0; i < 4; ++i) { + const int dc = tmp[0 + i * 4] + 3; // w/ rounder + const int a0 = dc + tmp[3 + i * 4]; + const int a1 = tmp[1 + i * 4] + tmp[2 + i * 4]; + const int a2 = tmp[1 + i * 4] - tmp[2 + i * 4]; + const int a3 = dc - tmp[3 + i * 4]; + out[ 0] = (a0 + a1) >> 3; + out[16] = (a3 + a2) >> 3; + out[32] = (a0 - a1) >> 3; + out[48] = (a3 - a2) >> 3; + out += 64; + } +} + +static int ParseResiduals(VP8Decoder* const dec, + VP8MB* const mb, VP8BitReader* const token_br) { + const VP8BandProbas* (* const bands)[16 + 1] = dec->proba_.bands_ptr_; + const VP8BandProbas* const * ac_proba; + VP8MBData* const block = dec->mb_data_ + dec->mb_x_; + const VP8QuantMatrix* const q = &dec->dqm_[block->segment_]; + int16_t* dst = block->coeffs_; + VP8MB* const left_mb = dec->mb_info_ - 1; + uint8_t tnz, lnz; + uint32_t non_zero_y = 0; + uint32_t non_zero_uv = 0; + int x, y, ch; + uint32_t out_t_nz, out_l_nz; + int first; + + memset(dst, 0, 384 * sizeof(*dst)); + if (!block->is_i4x4_) { // parse DC + int16_t dc[16] = { 0 }; + const int ctx = mb->nz_dc_ + left_mb->nz_dc_; + const int nz = GetCoeffs(token_br, bands[1], ctx, q->y2_mat_, 0, dc); + mb->nz_dc_ = left_mb->nz_dc_ = (nz > 0); + if (nz > 1) { // more than just the DC -> perform the full transform + TransformWHT(dc, dst); + } else { // only DC is non-zero -> inlined simplified transform + int i; + const int dc0 = (dc[0] + 3) >> 3; + for (i = 0; i < 16 * 16; i += 16) dst[i] = dc0; + } + first = 1; + ac_proba = bands[0]; + } else { + first = 0; + ac_proba = bands[3]; + } + + tnz = mb->nz_ & 0x0f; + lnz = left_mb->nz_ & 0x0f; + for (y = 0; y < 4; ++y) { + int l = lnz & 1; + uint32_t nz_coeffs = 0; + for (x = 0; x < 4; ++x) { + const int ctx = l + (tnz & 1); + const int nz = GetCoeffs(token_br, ac_proba, ctx, q->y1_mat_, first, dst); + l = (nz > first); + tnz = (tnz >> 1) | (l << 7); + nz_coeffs = NzCodeBits(nz_coeffs, nz, dst[0] != 0); + dst += 16; + } + tnz >>= 4; + lnz = (lnz >> 1) | (l << 7); + non_zero_y = (non_zero_y << 8) | nz_coeffs; + } + out_t_nz = tnz; + out_l_nz = lnz >> 4; + + for (ch = 0; ch < 4; ch += 2) { + uint32_t nz_coeffs = 0; + tnz = mb->nz_ >> (4 + ch); + lnz = left_mb->nz_ >> (4 + ch); + for (y = 0; y < 2; ++y) { + int l = lnz & 1; + for (x = 0; x < 2; ++x) { + const int ctx = l + (tnz & 1); + const int nz = GetCoeffs(token_br, bands[2], ctx, q->uv_mat_, 0, dst); + l = (nz > 0); + tnz = (tnz >> 1) | (l << 3); + nz_coeffs = NzCodeBits(nz_coeffs, nz, dst[0] != 0); + dst += 16; + } + tnz >>= 2; + lnz = (lnz >> 1) | (l << 5); + } + // Note: we don't really need the per-4x4 details for U/V blocks. + non_zero_uv |= nz_coeffs << (4 * ch); + out_t_nz |= (tnz << 4) << ch; + out_l_nz |= (lnz & 0xf0) << ch; + } + mb->nz_ = out_t_nz; + left_mb->nz_ = out_l_nz; + + block->non_zero_y_ = non_zero_y; + block->non_zero_uv_ = non_zero_uv; + + // We look at the mode-code of each block and check if some blocks have less + // than three non-zero coeffs (code < 2). This is to avoid dithering flat and + // empty blocks. + block->dither_ = (non_zero_uv & 0xaaaa) ? 0 : q->dither_; + + return !(non_zero_y | non_zero_uv); // will be used for further optimization +} + +//------------------------------------------------------------------------------ +// Main loop + +int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br) { + VP8MB* const left = dec->mb_info_ - 1; + VP8MB* const mb = dec->mb_info_ + dec->mb_x_; + VP8MBData* const block = dec->mb_data_ + dec->mb_x_; + int skip = dec->use_skip_proba_ ? block->skip_ : 0; + + if (!skip) { + skip = ParseResiduals(dec, mb, token_br); + } else { + left->nz_ = mb->nz_ = 0; + if (!block->is_i4x4_) { + left->nz_dc_ = mb->nz_dc_ = 0; + } + block->non_zero_y_ = 0; + block->non_zero_uv_ = 0; + block->dither_ = 0; + } + + if (dec->filter_type_ > 0) { // store filter info + VP8FInfo* const finfo = dec->f_info_ + dec->mb_x_; + *finfo = dec->fstrengths_[block->segment_][block->is_i4x4_]; + finfo->f_inner_ |= !skip; + } + + return !token_br->eof_; +} + +void VP8InitScanline(VP8Decoder* const dec) { + VP8MB* const left = dec->mb_info_ - 1; + left->nz_ = 0; + left->nz_dc_ = 0; + memset(dec->intra_l_, B_DC_PRED, sizeof(dec->intra_l_)); + dec->mb_x_ = 0; +} + +static int ParseFrame(VP8Decoder* const dec, VP8Io* io) { + for (dec->mb_y_ = 0; dec->mb_y_ < dec->br_mb_y_; ++dec->mb_y_) { + // Parse bitstream for this row. + VP8BitReader* const token_br = + &dec->parts_[dec->mb_y_ & (dec->num_parts_ - 1)]; + if (!VP8ParseIntraModeRow(&dec->br_, dec)) { + return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA, + "Premature end-of-partition0 encountered."); + } + for (; dec->mb_x_ < dec->mb_w_; ++dec->mb_x_) { + if (!VP8DecodeMB(dec, token_br)) { + return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA, + "Premature end-of-file encountered."); + } + } + VP8InitScanline(dec); // Prepare for next scanline + + // Reconstruct, filter and emit the row. + if (!VP8ProcessRow(dec, io)) { + return VP8SetError(dec, VP8_STATUS_USER_ABORT, "Output aborted."); + } + } + return 1; +} + +// Main entry point +int VP8Decode(VP8Decoder* const dec, VP8Io* const io) { + int ok = 0; + if (dec == NULL) { + return 0; + } + if (io == NULL) { + return VP8SetError(dec, VP8_STATUS_INVALID_PARAM, + "NULL VP8Io parameter in VP8Decode()."); + } + + if (!dec->ready_) { + if (!VP8GetHeaders(dec, io)) { + return 0; + } + } + assert(dec->ready_); + + // Finish setting up the decoding parameter. Will call io->setup(). + ok = (VP8EnterCritical(dec, io) == VP8_STATUS_OK); + if (ok) { // good to go. + // Will allocate memory and prepare everything. + if (ok) ok = VP8InitFrame(dec, io); + + // Main decoding loop + if (ok) ok = ParseFrame(dec, io); + + // Exit. + ok &= VP8ExitCritical(dec, io); + } + + if (!ok) { + VP8Clear(dec); + return 0; + } + + dec->ready_ = 0; + return ok; +} + +void VP8Clear(VP8Decoder* const dec) { + if (dec == NULL) { + return; + } + ALPHDelete(dec->alph_dec_); + dec->alph_dec_ = NULL; + tvg::free(dec->mem_); + dec->mem_ = NULL; + dec->mem_size_ = 0; + memset(&dec->br_, 0, sizeof(dec->br_)); + dec->ready_ = 0; +} + +//------------------------------------------------------------------------------ + diff --git a/components/thorvg-main/src/loaders/webp/dec/vp8i.h b/components/thorvg-main/src/loaders/webp/dec/vp8i.h new file mode 100644 index 0000000..de2a540 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/vp8i.h @@ -0,0 +1,307 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// VP8 decoder: internal header. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_DEC_VP8I_H_ +#define WEBP_DEC_VP8I_H_ + +#include // for memcpy() +#include "./common.h" +#include "./vp8li.h" +#include "../utils/bit_reader.h" +#include "../utils/random.h" +#include "../dsp/dsp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------------------------------------------------ +// Various defines and enums + +// version numbers +#define DEC_MAJ_VERSION 0 +#define DEC_MIN_VERSION 4 +#define DEC_REV_VERSION 3 + +// YUV-cache parameters. Cache is 32-bytes wide (= one cacheline). +// Constraints are: We need to store one 16x16 block of luma samples (y), +// and two 8x8 chroma blocks (u/v). These are better be 16-bytes aligned, +// in order to be SIMD-friendly. We also need to store the top, left and +// top-left samples (from previously decoded blocks), along with four +// extra top-right samples for luma (intra4x4 prediction only). +// One possible layout is, using 32 * (17 + 9) bytes: +// +// .+------ <- only 1 pixel high +// .|yyyyt. +// .|yyyyt. +// .|yyyyt. +// .|yyyy.. +// .+--.+-- <- only 1 pixel high +// .|uu.|vv +// .|uu.|vv +// +// Every character is a 4x4 block, with legend: +// '.' = unused +// 'y' = y-samples 'u' = u-samples 'v' = u-samples +// '|' = left sample, '-' = top sample, '+' = top-left sample +// 't' = extra top-right sample for 4x4 modes +#define YUV_SIZE (BPS * 17 + BPS * 9) +#define Y_SIZE (BPS * 17) +#define Y_OFF (BPS * 1 + 8) +#define U_OFF (Y_OFF + BPS * 16 + BPS) +#define V_OFF (U_OFF + 16) + +// minimal width under which lossy multi-threading is always disabled +#define MIN_WIDTH_FOR_THREADS 512 + +//------------------------------------------------------------------------------ +// Headers + +typedef struct { + uint8_t key_frame_; + uint8_t profile_; + uint8_t show_; + uint32_t partition_length_; +} VP8FrameHeader; + +typedef struct { + uint16_t width_; + uint16_t height_; + uint8_t xscale_; + uint8_t yscale_; + uint8_t colorspace_; // 0 = YCbCr + uint8_t clamp_type_; +} VP8PictureHeader; + +// segment features +typedef struct { + int use_segment_; + int update_map_; // whether to update the segment map or not + int absolute_delta_; // absolute or delta values for quantizer and filter + int8_t quantizer_[NUM_MB_SEGMENTS]; // quantization changes + int8_t filter_strength_[NUM_MB_SEGMENTS]; // filter strength for segments +} VP8SegmentHeader; + +// probas associated to one of the contexts +typedef uint8_t VP8ProbaArray[NUM_PROBAS]; + +typedef struct { // all the probas associated to one band + VP8ProbaArray probas_[NUM_CTX]; +} VP8BandProbas; + +// Struct collecting all frame-persistent probabilities. +typedef struct { + uint8_t segments_[MB_FEATURE_TREE_PROBS]; + // Type: 0:Intra16-AC 1:Intra16-DC 2:Chroma 3:Intra4 + VP8BandProbas bands_[NUM_TYPES][NUM_BANDS]; + const VP8BandProbas* bands_ptr_[NUM_TYPES][16 + 1]; +} VP8Proba; + +// Filter parameters +typedef struct { + int simple_; // 0=complex, 1=simple + int level_; // [0..63] + int sharpness_; // [0..7] + int use_lf_delta_; + int ref_lf_delta_[NUM_REF_LF_DELTAS]; + int mode_lf_delta_[NUM_MODE_LF_DELTAS]; +} VP8FilterHeader; + +//------------------------------------------------------------------------------ +// Information about the macroblocks. + +typedef struct { // filter specs + uint8_t f_limit_; // filter limit in [3..189], or 0 if no filtering + uint8_t f_ilevel_; // inner limit in [1..63] + uint8_t f_inner_; // do inner filtering? + uint8_t hev_thresh_; // high edge variance threshold in [0..2] +} VP8FInfo; + +typedef struct { // Top/Left Contexts used for syntax-parsing + uint8_t nz_; // non-zero AC/DC coeffs (4bit for luma + 4bit for chroma) + uint8_t nz_dc_; // non-zero DC coeff (1bit) +} VP8MB; + +// Dequantization matrices +typedef int quant_t[2]; // [DC / AC]. Can be 'uint16_t[2]' too (~slower). +typedef struct { + quant_t y1_mat_, y2_mat_, uv_mat_; + + int uv_quant_; // U/V quantizer value + int dither_; // dithering amplitude (0 = off, max=255) +} VP8QuantMatrix; + +// Data needed to reconstruct a macroblock +typedef struct { + int16_t coeffs_[384]; // 384 coeffs = (16+4+4) * 4*4 + uint8_t is_i4x4_; // true if intra4x4 + uint8_t imodes_[16]; // one 16x16 mode (#0) or sixteen 4x4 modes + uint8_t uvmode_; // chroma prediction mode + // bit-wise info about the content of each sub-4x4 blocks (in decoding order). + // Each of the 4x4 blocks for y/u/v is associated with a 2b code according to: + // code=0 -> no coefficient + // code=1 -> only DC + // code=2 -> first three coefficients are non-zero + // code=3 -> more than three coefficients are non-zero + // This allows to call specialized transform functions. + uint32_t non_zero_y_; + uint32_t non_zero_uv_; + uint8_t dither_; // local dithering strength (deduced from non_zero_*) + uint8_t skip_; + uint8_t segment_; +} VP8MBData; + +// Persistent information needed by the parallel processing +typedef struct { + int id_; // cache row to process (in [0..2]) + int mb_y_; // macroblock position of the row + int filter_row_; // true if row-filtering is needed + VP8FInfo* f_info_; // filter strengths (swapped with dec->f_info_) + VP8MBData* mb_data_; // reconstruction data (swapped with dec->mb_data_) + VP8Io io_; // copy of the VP8Io to pass to put() +} VP8ThreadContext; + +// Saved top samples, per macroblock. Fits into a cache-line. +typedef struct { + uint8_t y[16], u[8], v[8]; +} VP8TopSamples; + +//------------------------------------------------------------------------------ +// VP8Decoder: the main opaque structure handed over to user + +struct VP8Decoder { + VP8StatusCode status_; + int ready_; // true if ready to decode a picture with VP8Decode() + const char* error_msg_; // set when status_ is not OK. + + // Main data source + VP8BitReader br_; + + // headers + VP8FrameHeader frm_hdr_; + VP8PictureHeader pic_hdr_; + VP8FilterHeader filter_hdr_; + VP8SegmentHeader segment_hdr_; + + int cache_id_; // current cache row + int num_caches_; // number of cached rows of 16 pixels (1, 2 or 3) + VP8ThreadContext thread_ctx_; // Thread context + + // dimension, in macroblock units. + int mb_w_, mb_h_; + + // Macroblock to process/filter, depending on cropping and filter_type. + int tl_mb_x_, tl_mb_y_; // top-left MB that must be in-loop filtered + int br_mb_x_, br_mb_y_; // last bottom-right MB that must be decoded + + // number of partitions. + int num_parts_; + // per-partition boolean decoders. + VP8BitReader parts_[MAX_NUM_PARTITIONS]; + + // Dithering strength, deduced from decoding options + int dither_; // whether to use dithering or not + VP8Random dithering_rg_; // random generator for dithering + + // dequantization (one set of DC/AC dequant factor per segment) + VP8QuantMatrix dqm_[NUM_MB_SEGMENTS]; + + // probabilities + VP8Proba proba_; + int use_skip_proba_; + uint8_t skip_p_; + + // Boundary data cache and persistent buffers. + uint8_t* intra_t_; // top intra modes values: 4 * mb_w_ + uint8_t intra_l_[4]; // left intra modes values + + VP8TopSamples* yuv_t_; // top y/u/v samples + + VP8MB* mb_info_; // contextual macroblock info (mb_w_ + 1) + VP8FInfo* f_info_; // filter strength info + uint8_t* yuv_b_; // main block for Y/U/V (size = YUV_SIZE) + + uint8_t* cache_y_; // macroblock row for storing unfiltered samples + uint8_t* cache_u_; + uint8_t* cache_v_; + int cache_y_stride_; + int cache_uv_stride_; + + // main memory chunk for the above data. Persistent. + void* mem_; + size_t mem_size_; + + // Per macroblock non-persistent infos. + int mb_x_, mb_y_; // current position, in macroblock units + VP8MBData* mb_data_; // parsed reconstruction data + + // Filtering side-info + int filter_type_; // 0=off, 1=simple, 2=complex + VP8FInfo fstrengths_[NUM_MB_SEGMENTS][2]; // precalculated per-segment/type + + // Alpha + struct ALPHDecoder* alph_dec_; // alpha-plane decoder object + const uint8_t* alpha_data_; // compressed alpha data (if present) + size_t alpha_data_size_; + int is_alpha_decoded_; // true if alpha_data_ is decoded in alpha_plane_ + uint8_t* alpha_plane_; // output. Persistent, contains the whole data. + int alpha_dithering_; // derived from decoding options (0=off, 100=full). +}; + +//------------------------------------------------------------------------------ +// internal functions. Not public. + +// in vp8.c +int VP8SetError(VP8Decoder* const dec, + VP8StatusCode error, const char* const msg); + +// in tree.c +void VP8ResetProba(VP8Proba* const proba); +void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec); +// parses one row of intra mode data in partition 0, returns !eof +int VP8ParseIntraModeRow(VP8BitReader* const br, VP8Decoder* const dec); + +// in quant.c +void VP8ParseQuant(VP8Decoder* const dec); + +// in frame.c +int VP8InitFrame(VP8Decoder* const dec, VP8Io* io); +// Call io->setup() and finish setting up scan parameters. +// After this call returns, one must always call VP8ExitCritical() with the +// same parameters. Both functions should be used in pair. Returns VP8_STATUS_OK +// if ok, otherwise sets and returns the error status on *dec. +VP8StatusCode VP8EnterCritical(VP8Decoder* const dec, VP8Io* const io); +// Must always be called in pair with VP8EnterCritical(). +// Returns false in case of error. +int VP8ExitCritical(VP8Decoder* const dec, VP8Io* const io); +// Initialize dithering post-process if needed. +void VP8InitDithering(const WebPDecoderOptions* const options, + VP8Decoder* const dec); +// Process the last decoded row (filtering + output). +int VP8ProcessRow(VP8Decoder* const dec, VP8Io* const io); +// To be called at the start of a new scanline, to initialize predictors. +void VP8InitScanline(VP8Decoder* const dec); +// Decode one macroblock. Returns false if there is not enough data. +int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br); + +// in alpha.c +const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, + int row, int num_rows); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_DEC_VP8I_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/dec/vp8l.cpp b/components/thorvg-main/src/loaders/webp/dec/vp8l.cpp new file mode 100644 index 0000000..bf68aff --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/vp8l.cpp @@ -0,0 +1,1580 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// main entry for the decoder +// +// Authors: Vikas Arora (vikaas.arora@gmail.com) +// Jyrki Alakuijala (jyrki@google.com) + +#include "tvgCommon.h" + +#include "./alphai.h" +#include "./vp8li.h" +#include "../dsp/dsp.h" +#include "../dsp/lossless.h" +#include "../dsp/yuv.h" +#include "../utils/huffman.h" +#include "../utils/utils.h" + +#define NUM_ARGB_CACHE_ROWS 16 + +static const int kCodeLengthLiterals = 16; +static const int kCodeLengthRepeatCode = 16; +static const int kCodeLengthExtraBits[3] = { 2, 3, 7 }; +static const int kCodeLengthRepeatOffsets[3] = { 3, 3, 11 }; + +// ----------------------------------------------------------------------------- +// Five Huffman codes are used at each meta code: +// 1. green + length prefix codes + color cache codes, +// 2. alpha, +// 3. red, +// 4. blue, and, +// 5. distance prefix codes. +typedef enum { + GREEN = 0, + RED = 1, + BLUE = 2, + ALPHA = 3, + DIST = 4 +} HuffIndex; + +static const uint16_t kAlphabetSize[HUFFMAN_CODES_PER_META_CODE] = { + NUM_LITERAL_CODES + NUM_LENGTH_CODES, + NUM_LITERAL_CODES, NUM_LITERAL_CODES, NUM_LITERAL_CODES, + NUM_DISTANCE_CODES +}; + +static const uint8_t kLiteralMap[HUFFMAN_CODES_PER_META_CODE] = { + 0, 1, 1, 1, 0 +}; + +#define NUM_CODE_LENGTH_CODES 19 +static const uint8_t kCodeLengthCodeOrder[NUM_CODE_LENGTH_CODES] = { + 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +}; + +#define CODE_TO_PLANE_CODES 120 +static const uint8_t kCodeToPlane[CODE_TO_PLANE_CODES] = { + 0x18, 0x07, 0x17, 0x19, 0x28, 0x06, 0x27, 0x29, 0x16, 0x1a, + 0x26, 0x2a, 0x38, 0x05, 0x37, 0x39, 0x15, 0x1b, 0x36, 0x3a, + 0x25, 0x2b, 0x48, 0x04, 0x47, 0x49, 0x14, 0x1c, 0x35, 0x3b, + 0x46, 0x4a, 0x24, 0x2c, 0x58, 0x45, 0x4b, 0x34, 0x3c, 0x03, + 0x57, 0x59, 0x13, 0x1d, 0x56, 0x5a, 0x23, 0x2d, 0x44, 0x4c, + 0x55, 0x5b, 0x33, 0x3d, 0x68, 0x02, 0x67, 0x69, 0x12, 0x1e, + 0x66, 0x6a, 0x22, 0x2e, 0x54, 0x5c, 0x43, 0x4d, 0x65, 0x6b, + 0x32, 0x3e, 0x78, 0x01, 0x77, 0x79, 0x53, 0x5d, 0x11, 0x1f, + 0x64, 0x6c, 0x42, 0x4e, 0x76, 0x7a, 0x21, 0x2f, 0x75, 0x7b, + 0x31, 0x3f, 0x63, 0x6d, 0x52, 0x5e, 0x00, 0x74, 0x7c, 0x41, + 0x4f, 0x10, 0x20, 0x62, 0x6e, 0x30, 0x73, 0x7d, 0x51, 0x5f, + 0x40, 0x72, 0x7e, 0x61, 0x6f, 0x50, 0x71, 0x7f, 0x60, 0x70 +}; + +// Memory needed for lookup tables of one Huffman tree group. Red, blue, alpha +// and distance alphabets are constant (256 for red, blue and alpha, 40 for +// distance) and lookup table sizes for them in worst case are 630 and 410 +// respectively. Size of green alphabet depends on color cache size and is equal +// to 256 (green component values) + 24 (length prefix values) +// + color_cache_size (between 0 and 2048). +// All values computed for 8-bit first level lookup with Mark Adler's tool: +// http://www.hdfgroup.org/ftp/lib-external/zlib/zlib-1.2.5/examples/enough.c +#define FIXED_TABLE_SIZE (630 * 3 + 410) +static const int kTableSize[12] = { + FIXED_TABLE_SIZE + 654, + FIXED_TABLE_SIZE + 656, + FIXED_TABLE_SIZE + 658, + FIXED_TABLE_SIZE + 662, + FIXED_TABLE_SIZE + 670, + FIXED_TABLE_SIZE + 686, + FIXED_TABLE_SIZE + 718, + FIXED_TABLE_SIZE + 782, + FIXED_TABLE_SIZE + 912, + FIXED_TABLE_SIZE + 1168, + FIXED_TABLE_SIZE + 1680, + FIXED_TABLE_SIZE + 2704 +}; + +static int DecodeImageStream(int xsize, int ysize, + int is_level0, + VP8LDecoder* const dec, + uint32_t** const decoded_data); + +//------------------------------------------------------------------------------ + +int VP8LCheckSignature(const uint8_t* const data, size_t size) { + return (size >= VP8L_FRAME_HEADER_SIZE && + data[0] == VP8L_MAGIC_BYTE && + (data[4] >> 5) == 0); // version +} + +static int ReadImageInfo(VP8LBitReader* const br, + int* const width, int* const height, + int* const has_alpha) { + if (VP8LReadBits(br, 8) != VP8L_MAGIC_BYTE) return 0; + *width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1; + *height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1; + *has_alpha = VP8LReadBits(br, 1); + if (VP8LReadBits(br, VP8L_VERSION_BITS) != 0) return 0; + return !br->eos_; +} + +int VP8LGetInfo(const uint8_t* data, size_t data_size, + int* const width, int* const height, int* const has_alpha) { + if (data == NULL || data_size < VP8L_FRAME_HEADER_SIZE) { + return 0; // not enough data + } else if (!VP8LCheckSignature(data, data_size)) { + return 0; // bad signature + } else { + int w, h, a; + VP8LBitReader br; + VP8LInitBitReader(&br, data, data_size); + if (!ReadImageInfo(&br, &w, &h, &a)) { + return 0; + } + if (width != NULL) *width = w; + if (height != NULL) *height = h; + if (has_alpha != NULL) *has_alpha = a; + return 1; + } +} + +//------------------------------------------------------------------------------ + +static WEBP_INLINE int GetCopyDistance(int distance_symbol, + VP8LBitReader* const br) { + int extra_bits, offset; + if (distance_symbol < 4) { + return distance_symbol + 1; + } + extra_bits = (distance_symbol - 2) >> 1; + offset = (2 + (distance_symbol & 1)) << extra_bits; + return offset + VP8LReadBits(br, extra_bits) + 1; +} + +static WEBP_INLINE int GetCopyLength(int length_symbol, + VP8LBitReader* const br) { + // Length and distance prefixes are encoded the same way. + return GetCopyDistance(length_symbol, br); +} + +static WEBP_INLINE int PlaneCodeToDistance(int xsize, int plane_code) { + if (plane_code > CODE_TO_PLANE_CODES) { + return plane_code - CODE_TO_PLANE_CODES; + } else { + const int dist_code = kCodeToPlane[plane_code - 1]; + const int yoffset = dist_code >> 4; + const int xoffset = 8 - (dist_code & 0xf); + const int dist = yoffset * xsize + xoffset; + return (dist >= 1) ? dist : 1; // dist<1 can happen if xsize is very small + } +} + +//------------------------------------------------------------------------------ +// Decodes the next Huffman code from bit-stream. +// FillBitWindow(br) needs to be called at minimum every second call +// to ReadSymbol, in order to pre-fetch enough bits. +static WEBP_INLINE int ReadSymbol(const HuffmanCode* table, + VP8LBitReader* const br) { + int nbits; + uint32_t val = VP8LPrefetchBits(br); + table += val & HUFFMAN_TABLE_MASK; + nbits = table->bits - HUFFMAN_TABLE_BITS; + if (nbits > 0) { + VP8LSetBitPos(br, br->bit_pos_ + HUFFMAN_TABLE_BITS); + val = VP8LPrefetchBits(br); + table += table->value; + table += val & ((1 << nbits) - 1); + } + VP8LSetBitPos(br, br->bit_pos_ + table->bits); + return table->value; +} + +static int ReadHuffmanCodeLengths( + VP8LDecoder* const dec, const int* const code_length_code_lengths, + int num_symbols, int* const code_lengths) { + int ok = 0; + VP8LBitReader* const br = &dec->br_; + int symbol; + int max_symbol; + int prev_code_len = DEFAULT_CODE_LENGTH; + HuffmanCode table[1 << LENGTHS_TABLE_BITS]; + + if (!VP8LBuildHuffmanTable(table, LENGTHS_TABLE_BITS, + code_length_code_lengths, + NUM_CODE_LENGTH_CODES)) { + goto End; + } + + if (VP8LReadBits(br, 1)) { // use length + const int length_nbits = 2 + 2 * VP8LReadBits(br, 3); + max_symbol = 2 + VP8LReadBits(br, length_nbits); + if (max_symbol > num_symbols) { + goto End; + } + } else { + max_symbol = num_symbols; + } + + symbol = 0; + while (symbol < num_symbols) { + const HuffmanCode* p; + int code_len; + if (max_symbol-- == 0) break; + VP8LFillBitWindow(br); + p = &table[VP8LPrefetchBits(br) & LENGTHS_TABLE_MASK]; + VP8LSetBitPos(br, br->bit_pos_ + p->bits); + code_len = p->value; + if (code_len < kCodeLengthLiterals) { + code_lengths[symbol++] = code_len; + if (code_len != 0) prev_code_len = code_len; + } else { + const int use_prev = (code_len == kCodeLengthRepeatCode); + const int slot = code_len - kCodeLengthLiterals; + const int extra_bits = kCodeLengthExtraBits[slot]; + const int repeat_offset = kCodeLengthRepeatOffsets[slot]; + int repeat = VP8LReadBits(br, extra_bits) + repeat_offset; + if (symbol + repeat > num_symbols) { + goto End; + } else { + const int length = use_prev ? prev_code_len : 0; + while (repeat-- > 0) code_lengths[symbol++] = length; + } + } + } + ok = 1; + + End: + if (!ok) dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + return ok; +} + +// 'code_lengths' is pre-allocated temporary buffer, used for creating Huffman +// tree. +static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec, + int* const code_lengths, HuffmanCode* const table) { + int ok = 0; + int size = 0; + VP8LBitReader* const br = &dec->br_; + const int simple_code = VP8LReadBits(br, 1); + + memset(code_lengths, 0, alphabet_size * sizeof(*code_lengths)); + + if (simple_code) { // Read symbols, codes & code lengths directly. + const int num_symbols = VP8LReadBits(br, 1) + 1; + const int first_symbol_len_code = VP8LReadBits(br, 1); + // The first code is either 1 bit or 8 bit code. + int symbol = VP8LReadBits(br, (first_symbol_len_code == 0) ? 1 : 8); + code_lengths[symbol] = 1; + // The second code (if present), is always 8 bit long. + if (num_symbols == 2) { + symbol = VP8LReadBits(br, 8); + code_lengths[symbol] = 1; + } + ok = 1; + } else { // Decode Huffman-coded code lengths. + int i; + int code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 }; + const int num_codes = VP8LReadBits(br, 4) + 4; + if (num_codes > NUM_CODE_LENGTH_CODES) { + dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + return 0; + } + + for (i = 0; i < num_codes; ++i) { + code_length_code_lengths[kCodeLengthCodeOrder[i]] = VP8LReadBits(br, 3); + } + ok = ReadHuffmanCodeLengths(dec, code_length_code_lengths, alphabet_size, + code_lengths); + } + + ok = ok && !br->eos_; + if (ok) { + size = VP8LBuildHuffmanTable(table, HUFFMAN_TABLE_BITS, + code_lengths, alphabet_size); + } + if (!ok || size == 0) { + dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + return 0; + } + return size; +} + +static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize, + int color_cache_bits, int allow_recursion) { + int i, j; + VP8LBitReader* const br = &dec->br_; + VP8LMetadata* const hdr = &dec->hdr_; + uint32_t* huffman_image = NULL; + HTreeGroup* htree_groups = NULL; + HuffmanCode* huffman_tables = NULL; + HuffmanCode* next = NULL; + int num_htree_groups = 1; + int max_alphabet_size = 0; + int* code_lengths = NULL; + const int table_size = kTableSize[color_cache_bits]; + + if (allow_recursion && VP8LReadBits(br, 1)) { + // use meta Huffman codes. + const int huffman_precision = VP8LReadBits(br, 3) + 2; + const int huffman_xsize = VP8LSubSampleSize(xsize, huffman_precision); + const int huffman_ysize = VP8LSubSampleSize(ysize, huffman_precision); + const int huffman_pixs = huffman_xsize * huffman_ysize; + if (!DecodeImageStream(huffman_xsize, huffman_ysize, 0, dec, + &huffman_image)) { + goto Error; + } + hdr->huffman_subsample_bits_ = huffman_precision; + for (i = 0; i < huffman_pixs; ++i) { + // The huffman data is stored in red and green bytes. + const int group = (huffman_image[i] >> 8) & 0xffff; + huffman_image[i] = group; + if (group >= num_htree_groups) { + num_htree_groups = group + 1; + } + } + } + + if (br->eos_) goto Error; + + // Find maximum alphabet size for the htree group. + for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) { + int alphabet_size = kAlphabetSize[j]; + if (j == 0 && color_cache_bits > 0) { + alphabet_size += 1 << color_cache_bits; + } + if (max_alphabet_size < alphabet_size) { + max_alphabet_size = alphabet_size; + } + } + + huffman_tables = tvg::malloc(num_htree_groups * table_size * sizeof(*huffman_tables)); + htree_groups = VP8LHtreeGroupsNew(num_htree_groups); + code_lengths = tvg::calloc((uint64_t)max_alphabet_size, sizeof(*code_lengths)); + + if (htree_groups == NULL || code_lengths == NULL || huffman_tables == NULL) { + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + goto Error; + } + + next = huffman_tables; + for (i = 0; i < num_htree_groups; ++i) { + HTreeGroup* const htree_group = &htree_groups[i]; + HuffmanCode** const htrees = htree_group->htrees; + int size; + int is_trivial_literal = 1; + for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) { + int alphabet_size = kAlphabetSize[j]; + htrees[j] = next; + if (j == 0 && color_cache_bits > 0) { + alphabet_size += 1 << color_cache_bits; + } + size = ReadHuffmanCode(alphabet_size, dec, code_lengths, next); + if (is_trivial_literal && kLiteralMap[j] == 1) { + is_trivial_literal = (next->bits == 0); + } + next += size; + if (size == 0) { + goto Error; + } + } + htree_group->is_trivial_literal = is_trivial_literal; + if (is_trivial_literal) { + const int red = htrees[RED][0].value; + const int blue = htrees[BLUE][0].value; + const int alpha = htrees[ALPHA][0].value; + htree_group->literal_arb = + ((uint32_t)alpha << 24) | (red << 16) | blue; + } + } + tvg::free(code_lengths); + + // All OK. Finalize pointers and return. + hdr->huffman_image_ = huffman_image; + hdr->num_htree_groups_ = num_htree_groups; + hdr->htree_groups_ = htree_groups; + hdr->huffman_tables_ = huffman_tables; + return 1; + + Error: + tvg::free(code_lengths); + tvg::free(huffman_image); + tvg::free(huffman_tables); + VP8LHtreeGroupsFree(htree_groups); + return 0; +} + +//------------------------------------------------------------------------------ +// Scaling. + +static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) { + const int num_channels = 4; + const int in_width = io->mb_w; + const int out_width = io->scaled_width; + const int in_height = io->mb_h; + const int out_height = io->scaled_height; + const uint64_t work_size = 2 * num_channels * (uint64_t)out_width; + int32_t* work; // Rescaler work area. + const uint64_t scaled_data_size = num_channels * (uint64_t)out_width; + uint32_t* scaled_data; // Temporary storage for scaled BGRA data. + const uint64_t memory_size = sizeof(*dec->rescaler) + + work_size * sizeof(*work) + + scaled_data_size * sizeof(*scaled_data); + uint8_t* memory = tvg::calloc(memory_size, sizeof(*memory)); + if (memory == NULL) { + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + return 0; + } + assert(dec->rescaler_memory == NULL); + dec->rescaler_memory = memory; + + dec->rescaler = (WebPRescaler*)memory; + memory += sizeof(*dec->rescaler); + work = (int32_t*)memory; + memory += work_size * sizeof(*work); + scaled_data = (uint32_t*)memory; + + WebPRescalerInit(dec->rescaler, in_width, in_height, (uint8_t*)scaled_data, + out_width, out_height, 0, num_channels, + in_width, out_width, in_height, out_height, work); + return 1; +} + +//------------------------------------------------------------------------------ +// Export to ARGB + +// We have special "export" function since we need to convert from BGRA +static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace, + int rgba_stride, uint8_t* const rgba) { + uint32_t* const src = (uint32_t*)rescaler->dst; + const int dst_width = rescaler->dst_width; + int num_lines_out = 0; + while (WebPRescalerHasPendingOutput(rescaler)) { + uint8_t* const dst = rgba + num_lines_out * rgba_stride; + WebPRescalerExportRow(rescaler, 0); + WebPMultARGBRow(src, dst_width, 1); + VP8LConvertFromBGRA(src, dst_width, colorspace, dst); + ++num_lines_out; + } + return num_lines_out; +} + +// Emit scaled rows. +static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec, + uint8_t* in, int in_stride, int mb_h, + uint8_t* const out, int out_stride) { + const WEBP_CSP_MODE colorspace = dec->output_->colorspace; + int num_lines_in = 0; + int num_lines_out = 0; + while (num_lines_in < mb_h) { + uint8_t* const row_in = in + num_lines_in * in_stride; + uint8_t* const row_out = out + num_lines_out * out_stride; + const int lines_left = mb_h - num_lines_in; + const int needed_lines = WebPRescaleNeededLines(dec->rescaler, lines_left); + assert(needed_lines > 0 && needed_lines <= lines_left); + WebPMultARGBRows(row_in, in_stride, + dec->rescaler->src_width, needed_lines, 0); + WebPRescalerImport(dec->rescaler, lines_left, row_in, in_stride); + num_lines_in += needed_lines; + num_lines_out += Export(dec->rescaler, colorspace, out_stride, row_out); + } + return num_lines_out; +} + +// Emit rows without any scaling. +static int EmitRows(WEBP_CSP_MODE colorspace, + const uint8_t* row_in, int in_stride, + int mb_w, int mb_h, + uint8_t* const out, int out_stride) { + int lines = mb_h; + uint8_t* row_out = out; + while (lines-- > 0) { + VP8LConvertFromBGRA((const uint32_t*)row_in, mb_w, colorspace, row_out); + row_in += in_stride; + row_out += out_stride; + } + return mb_h; // Num rows out == num rows in. +} + +//------------------------------------------------------------------------------ +// Export to YUVA + +// TODO(skal): should be in yuv.c +static void ConvertToYUVA(const uint32_t* const src, int width, int y_pos, + const WebPDecBuffer* const output) { + const WebPYUVABuffer* const buf = &output->u.YUVA; + // first, the luma plane + { + int i; + uint8_t* const y = buf->y + y_pos * buf->y_stride; + for (i = 0; i < width; ++i) { + const uint32_t p = src[i]; + y[i] = VP8RGBToY((p >> 16) & 0xff, (p >> 8) & 0xff, (p >> 0) & 0xff, + YUV_HALF); + } + } + + // then U/V planes + { + uint8_t* const u = buf->u + (y_pos >> 1) * buf->u_stride; + uint8_t* const v = buf->v + (y_pos >> 1) * buf->v_stride; + const int uv_width = width >> 1; + int i; + for (i = 0; i < uv_width; ++i) { + const uint32_t v0 = src[2 * i + 0]; + const uint32_t v1 = src[2 * i + 1]; + // VP8RGBToU/V expects four accumulated pixels. Hence we need to + // scale r/g/b value by a factor 2. We just shift v0/v1 one bit less. + const int r = ((v0 >> 15) & 0x1fe) + ((v1 >> 15) & 0x1fe); + const int g = ((v0 >> 7) & 0x1fe) + ((v1 >> 7) & 0x1fe); + const int b = ((v0 << 1) & 0x1fe) + ((v1 << 1) & 0x1fe); + if (!(y_pos & 1)) { // even lines: store values + u[i] = VP8RGBToU(r, g, b, YUV_HALF << 2); + v[i] = VP8RGBToV(r, g, b, YUV_HALF << 2); + } else { // odd lines: average with previous values + const int tmp_u = VP8RGBToU(r, g, b, YUV_HALF << 2); + const int tmp_v = VP8RGBToV(r, g, b, YUV_HALF << 2); + // Approximated average-of-four. But it's an acceptable diff. + u[i] = (u[i] + tmp_u + 1) >> 1; + v[i] = (v[i] + tmp_v + 1) >> 1; + } + } + if (width & 1) { // last pixel + const uint32_t v0 = src[2 * i + 0]; + const int r = (v0 >> 14) & 0x3fc; + const int g = (v0 >> 6) & 0x3fc; + const int b = (v0 << 2) & 0x3fc; + if (!(y_pos & 1)) { // even lines + u[i] = VP8RGBToU(r, g, b, YUV_HALF << 2); + v[i] = VP8RGBToV(r, g, b, YUV_HALF << 2); + } else { // odd lines (note: we could just skip this) + const int tmp_u = VP8RGBToU(r, g, b, YUV_HALF << 2); + const int tmp_v = VP8RGBToV(r, g, b, YUV_HALF << 2); + u[i] = (u[i] + tmp_u + 1) >> 1; + v[i] = (v[i] + tmp_v + 1) >> 1; + } + } + } + // Lastly, store alpha if needed. + if (buf->a != NULL) { + int i; + uint8_t* const a = buf->a + y_pos * buf->a_stride; + for (i = 0; i < width; ++i) a[i] = (src[i] >> 24); + } +} + +static int ExportYUVA(const VP8LDecoder* const dec, int y_pos) { + WebPRescaler* const rescaler = dec->rescaler; + uint32_t* const src = (uint32_t*)rescaler->dst; + const int dst_width = rescaler->dst_width; + int num_lines_out = 0; + while (WebPRescalerHasPendingOutput(rescaler)) { + WebPRescalerExportRow(rescaler, 0); + WebPMultARGBRow(src, dst_width, 1); + ConvertToYUVA(src, dst_width, y_pos, dec->output_); + ++y_pos; + ++num_lines_out; + } + return num_lines_out; +} + +static int EmitRescaledRowsYUVA(const VP8LDecoder* const dec, + uint8_t* in, int in_stride, int mb_h) { + int num_lines_in = 0; + int y_pos = dec->last_out_row_; + while (num_lines_in < mb_h) { + const int lines_left = mb_h - num_lines_in; + const int needed_lines = WebPRescaleNeededLines(dec->rescaler, lines_left); + WebPMultARGBRows(in, in_stride, dec->rescaler->src_width, needed_lines, 0); + WebPRescalerImport(dec->rescaler, lines_left, in, in_stride); + num_lines_in += needed_lines; + in += needed_lines * in_stride; + y_pos += ExportYUVA(dec, y_pos); + } + return y_pos; +} + +static int EmitRowsYUVA(const VP8LDecoder* const dec, + const uint8_t* in, int in_stride, + int mb_w, int num_rows) { + int y_pos = dec->last_out_row_; + while (num_rows-- > 0) { + ConvertToYUVA((const uint32_t*)in, mb_w, y_pos, dec->output_); + in += in_stride; + ++y_pos; + } + return y_pos; +} + +//------------------------------------------------------------------------------ +// Cropping. + +// Sets io->mb_y, io->mb_h & io->mb_w according to start row, end row and +// crop options. Also updates the input data pointer, so that it points to the +// start of the cropped window. Note that pixels are in ARGB format even if +// 'in_data' is uint8_t*. +// Returns true if the crop window is not empty. +static int SetCropWindow(VP8Io* const io, int y_start, int y_end, + uint8_t** const in_data, int pixel_stride) { + assert(y_start < y_end); + assert(io->crop_left < io->crop_right); + if (y_end > io->crop_bottom) { + y_end = io->crop_bottom; // make sure we don't overflow on last row. + } + if (y_start < io->crop_top) { + const int delta = io->crop_top - y_start; + y_start = io->crop_top; + *in_data += delta * pixel_stride; + } + if (y_start >= y_end) return 0; // Crop window is empty. + + *in_data += io->crop_left * sizeof(uint32_t); + + io->mb_y = y_start - io->crop_top; + io->mb_w = io->crop_right - io->crop_left; + io->mb_h = y_end - y_start; + return 1; // Non-empty crop window. +} + +//------------------------------------------------------------------------------ + +static WEBP_INLINE int GetMetaIndex( + const uint32_t* const image, int xsize, int bits, int x, int y) { + if (bits == 0) return 0; + return image[xsize * (y >> bits) + (x >> bits)]; +} + +static WEBP_INLINE HTreeGroup* GetHtreeGroupForPos(VP8LMetadata* const hdr, + int x, int y) { + const int meta_index = GetMetaIndex(hdr->huffman_image_, hdr->huffman_xsize_, + hdr->huffman_subsample_bits_, x, y); + assert(meta_index < hdr->num_htree_groups_); + return hdr->htree_groups_ + meta_index; +} + +//------------------------------------------------------------------------------ +// Main loop, with custom row-processing function + +typedef void (*ProcessRowsFunc)(VP8LDecoder* const dec, int row); + +static void ApplyInverseTransforms(VP8LDecoder* const dec, int num_rows, + const uint32_t* const rows) { + int n = dec->next_transform_; + const int cache_pixs = dec->width_ * num_rows; + const int start_row = dec->last_row_; + const int end_row = start_row + num_rows; + const uint32_t* rows_in = rows; + uint32_t* const rows_out = dec->argb_cache_; + + // Inverse transforms. + // TODO: most transforms only need to operate on the cropped region only. + memcpy(rows_out, rows_in, cache_pixs * sizeof(*rows_out)); + while (n-- > 0) { + VP8LTransform* const transform = &dec->transforms_[n]; + VP8LInverseTransform(transform, start_row, end_row, rows_in, rows_out); + rows_in = rows_out; + } +} + +// Special method for paletted alpha data. +static void ApplyInverseTransformsAlpha(VP8LDecoder* const dec, int num_rows, + const uint8_t* const rows) { + const int start_row = dec->last_row_; + const int end_row = start_row + num_rows; + const uint8_t* rows_in = rows; + uint8_t* rows_out = (uint8_t*)dec->io_->opaque + dec->io_->width * start_row; + VP8LTransform* const transform = &dec->transforms_[0]; + assert(dec->next_transform_ == 1); + assert(transform->type_ == COLOR_INDEXING_TRANSFORM); + VP8LColorIndexInverseTransformAlpha(transform, start_row, end_row, rows_in, + rows_out); +} + +// Processes (transforms, scales & color-converts) the rows decoded after the +// last call. +static void ProcessRows(VP8LDecoder* const dec, int row) { + const uint32_t* const rows = dec->pixels_ + dec->width_ * dec->last_row_; + const int num_rows = row - dec->last_row_; + + if (num_rows <= 0) return; // Nothing to be done. + ApplyInverseTransforms(dec, num_rows, rows); + + // Emit output. + { + VP8Io* const io = dec->io_; + uint8_t* rows_data = (uint8_t*)dec->argb_cache_; + const int in_stride = io->width * sizeof(uint32_t); // in unit of RGBA + if (!SetCropWindow(io, dec->last_row_, row, &rows_data, in_stride)) { + // Nothing to output (this time). + } else { + const WebPDecBuffer* const output = dec->output_; + if (output->colorspace < MODE_YUV) { // convert to RGBA + const WebPRGBABuffer* const buf = &output->u.RGBA; + uint8_t* const rgba = buf->rgba + dec->last_out_row_ * buf->stride; + const int num_rows_out = io->use_scaling ? + EmitRescaledRowsRGBA(dec, rows_data, in_stride, io->mb_h, + rgba, buf->stride) : + EmitRows(output->colorspace, rows_data, in_stride, + io->mb_w, io->mb_h, rgba, buf->stride); + // Update 'last_out_row_'. + dec->last_out_row_ += num_rows_out; + } else { // convert to YUVA + dec->last_out_row_ = io->use_scaling ? + EmitRescaledRowsYUVA(dec, rows_data, in_stride, io->mb_h) : + EmitRowsYUVA(dec, rows_data, in_stride, io->mb_w, io->mb_h); + } + assert(dec->last_out_row_ <= output->height); + } + } + + // Update 'last_row_'. + dec->last_row_ = row; + assert(dec->last_row_ <= dec->height_); +} + +// Row-processing for the special case when alpha data contains only one +// transform (color indexing), and trivial non-green literals. +static int Is8bOptimizable(const VP8LMetadata* const hdr) { + int i; + if (hdr->color_cache_size_ > 0) return 0; + // When the Huffman tree contains only one symbol, we can skip the + // call to ReadSymbol() for red/blue/alpha channels. + for (i = 0; i < hdr->num_htree_groups_; ++i) { + HuffmanCode** const htrees = hdr->htree_groups_[i].htrees; + if (htrees[RED][0].bits > 0) return 0; + if (htrees[BLUE][0].bits > 0) return 0; + if (htrees[ALPHA][0].bits > 0) return 0; + } + return 1; +} + +static void ExtractPalettedAlphaRows(VP8LDecoder* const dec, int row) { + const int num_rows = row - dec->last_row_; + const uint8_t* const in = + (uint8_t*)dec->pixels_ + dec->width_ * dec->last_row_; + if (num_rows > 0) { + ApplyInverseTransformsAlpha(dec, num_rows, in); + } + dec->last_row_ = dec->last_out_row_ = row; +} + +//------------------------------------------------------------------------------ +// Helper functions for fast pattern copy (8b and 32b) + +// cyclic rotation of pattern word +static WEBP_INLINE uint32_t Rotate8b(uint32_t V) { +#if defined(WORDS_BIGENDIAN) + return ((V & 0xff000000u) >> 24) | (V << 8); +#else + return ((V & 0xffu) << 24) | (V >> 8); +#endif +} + +// copy 1, 2 or 4-bytes pattern +static WEBP_INLINE void CopySmallPattern8b(const uint8_t* src, uint8_t* dst, + int length, uint32_t pattern) { + int i; + // align 'dst' to 4-bytes boundary. Adjust the pattern along the way. + while ((uintptr_t)dst & 3) { + *dst++ = *src++; + pattern = Rotate8b(pattern); + --length; + } + // Copy the pattern 4 bytes at a time. + for (i = 0; i < (length >> 2); ++i) { + ((uint32_t*)dst)[i] = pattern; + } + // Finish with left-overs. 'pattern' is still correctly positioned, + // so no Rotate8b() call is needed. + for (i <<= 2; i < length; ++i) { + dst[i] = src[i]; + } +} + +static WEBP_INLINE void CopyBlock8b(uint8_t* const dst, int dist, int length) { + const uint8_t* src = dst - dist; + if (length >= 8) { + uint32_t pattern = 0; + switch (dist) { + case 1: + pattern = src[0]; +#if defined(__arm__) || defined(_M_ARM) // arm doesn't like multiply that much + pattern |= pattern << 8; + pattern |= pattern << 16; +#elif defined(WEBP_USE_MIPS_DSP_R2) + __asm__ volatile ("replv.qb %0, %0" : "+r"(pattern)); +#else + pattern = 0x01010101u * pattern; +#endif + break; + case 2: + memcpy(&pattern, src, sizeof(uint16_t)); +#if defined(__arm__) || defined(_M_ARM) + pattern |= pattern << 16; +#elif defined(WEBP_USE_MIPS_DSP_R2) + __asm__ volatile ("replv.ph %0, %0" : "+r"(pattern)); +#else + pattern = 0x00010001u * pattern; +#endif + break; + case 4: + memcpy(&pattern, src, sizeof(uint32_t)); + break; + default: + goto Copy; + break; + } + CopySmallPattern8b(src, dst, length, pattern); + return; + } + Copy: + if (dist >= length) { // no overlap -> use memcpy() + memcpy(dst, src, length * sizeof(*dst)); + } else { + int i; + for (i = 0; i < length; ++i) dst[i] = src[i]; + } +} + +// copy pattern of 1 or 2 uint32_t's +static WEBP_INLINE void CopySmallPattern32b(const uint32_t* src, + uint32_t* dst, + int length, uint64_t pattern) { + int i; + if ((uintptr_t)dst & 4) { // Align 'dst' to 8-bytes boundary. + *dst++ = *src++; + pattern = (pattern >> 32) | (pattern << 32); + --length; + } + assert(0 == ((uintptr_t)dst & 7)); + for (i = 0; i < (length >> 1); ++i) { + ((uint64_t*)dst)[i] = pattern; // Copy the pattern 8 bytes at a time. + } + if (length & 1) { // Finish with left-over. + dst[i << 1] = src[i << 1]; + } +} + +static WEBP_INLINE void CopyBlock32b(uint32_t* const dst, + int dist, int length) { + const uint32_t* const src = dst - dist; + if (dist <= 2 && length >= 4 && ((uintptr_t)dst & 3) == 0) { + uint64_t pattern; + if (dist == 1) { + pattern = (uint64_t)src[0]; + pattern |= pattern << 32; + } else { + memcpy(&pattern, src, sizeof(pattern)); + } + CopySmallPattern32b(src, dst, length, pattern); + } else if (dist >= length) { // no overlap + memcpy(dst, src, length * sizeof(*dst)); + } else { + int i; + for (i = 0; i < length; ++i) dst[i] = src[i]; + } +} + +//------------------------------------------------------------------------------ + +static int DecodeAlphaData(VP8LDecoder* const dec, uint8_t* const data, + int width, int height, int last_row) { + int ok = 1; + int row = dec->last_pixel_ / width; + int col = dec->last_pixel_ % width; + VP8LBitReader* const br = &dec->br_; + VP8LMetadata* const hdr = &dec->hdr_; + const HTreeGroup* htree_group = GetHtreeGroupForPos(hdr, col, row); + int pos = dec->last_pixel_; // current position + const int end = width * height; // End of data + const int last = width * last_row; // Last pixel to decode + const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES; + const int mask = hdr->huffman_mask_; + assert(htree_group != NULL); + assert(pos < end); + assert(last_row <= height); + assert(Is8bOptimizable(hdr)); + + while (!br->eos_ && pos < last) { + int code; + // Only update when changing tile. + if ((col & mask) == 0) { + htree_group = GetHtreeGroupForPos(hdr, col, row); + } + VP8LFillBitWindow(br); + code = ReadSymbol(htree_group->htrees[GREEN], br); + if (code < NUM_LITERAL_CODES) { // Literal + data[pos] = code; + ++pos; + ++col; + if (col >= width) { + col = 0; + ++row; + if (row % NUM_ARGB_CACHE_ROWS == 0) { + ExtractPalettedAlphaRows(dec, row); + } + } + } else if (code < len_code_limit) { // Backward reference + int dist_code, dist; + const int length_sym = code - NUM_LITERAL_CODES; + const int length = GetCopyLength(length_sym, br); + const int dist_symbol = ReadSymbol(htree_group->htrees[DIST], br); + VP8LFillBitWindow(br); + dist_code = GetCopyDistance(dist_symbol, br); + dist = PlaneCodeToDistance(width, dist_code); + if (pos >= dist && end - pos >= length) { + CopyBlock8b(data + pos, dist, length); + } else { + ok = 0; + goto End; + } + pos += length; + col += length; + while (col >= width) { + col -= width; + ++row; + if (row % NUM_ARGB_CACHE_ROWS == 0) { + ExtractPalettedAlphaRows(dec, row); + } + } + if (pos < last && (col & mask)) { + htree_group = GetHtreeGroupForPos(hdr, col, row); + } + } else { // Not reached + ok = 0; + goto End; + } + assert(br->eos_ == VP8LIsEndOfStream(br)); + } + // Process the remaining rows corresponding to last row-block. + ExtractPalettedAlphaRows(dec, row); + + End: + if (!ok || (br->eos_ && pos < end)) { + ok = 0; + dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED + : VP8_STATUS_BITSTREAM_ERROR; + } else { + dec->last_pixel_ = (int)pos; + } + return ok; +} + +static void SaveState(VP8LDecoder* const dec, int last_pixel) { + assert(dec->incremental_); + dec->saved_br_ = dec->br_; + dec->saved_last_pixel_ = last_pixel; + if (dec->hdr_.color_cache_size_ > 0) { + VP8LColorCacheCopy(&dec->hdr_.color_cache_, &dec->hdr_.saved_color_cache_); + } +} + +static void RestoreState(VP8LDecoder* const dec) { + assert(dec->br_.eos_); + dec->status_ = VP8_STATUS_SUSPENDED; + dec->br_ = dec->saved_br_; + dec->last_pixel_ = dec->saved_last_pixel_; + if (dec->hdr_.color_cache_size_ > 0) { + VP8LColorCacheCopy(&dec->hdr_.saved_color_cache_, &dec->hdr_.color_cache_); + } +} + +#define SYNC_EVERY_N_ROWS 8 // minimum number of rows between check-points +static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data, + int width, int height, int last_row, + ProcessRowsFunc process_func) { + int row = dec->last_pixel_ / width; + int col = dec->last_pixel_ % width; + VP8LBitReader* const br = &dec->br_; + VP8LMetadata* const hdr = &dec->hdr_; + HTreeGroup* htree_group = GetHtreeGroupForPos(hdr, col, row); + uint32_t* src = data + dec->last_pixel_; + uint32_t* last_cached = src; + uint32_t* const src_end = data + width * height; // End of data + uint32_t* const src_last = data + width * last_row; // Last pixel to decode + const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES; + const int color_cache_limit = len_code_limit + hdr->color_cache_size_; + int next_sync_row = dec->incremental_ ? row : 1 << 24; + VP8LColorCache* const color_cache = + (hdr->color_cache_size_ > 0) ? &hdr->color_cache_ : NULL; + const int mask = hdr->huffman_mask_; + assert(htree_group != NULL); + assert(src < src_end); + assert(src_last <= src_end); + + while (src < src_last) { + int code; + if (row >= next_sync_row) { + SaveState(dec, (int)(src - data)); + next_sync_row = row + SYNC_EVERY_N_ROWS; + } + // Only update when changing tile. Note we could use this test: + // if "((((prev_col ^ col) | prev_row ^ row)) > mask)" -> tile changed + // but that's actually slower and needs storing the previous col/row. + if ((col & mask) == 0) { + htree_group = GetHtreeGroupForPos(hdr, col, row); + } + VP8LFillBitWindow(br); + code = ReadSymbol(htree_group->htrees[GREEN], br); + if (br->eos_) break; // early out + if (code < NUM_LITERAL_CODES) { // Literal + if (htree_group->is_trivial_literal) { + *src = htree_group->literal_arb | (code << 8); + } else { + int red, blue, alpha; + red = ReadSymbol(htree_group->htrees[RED], br); + VP8LFillBitWindow(br); + blue = ReadSymbol(htree_group->htrees[BLUE], br); + alpha = ReadSymbol(htree_group->htrees[ALPHA], br); + if (br->eos_) break; + *src = ((uint32_t)alpha << 24) | (red << 16) | (code << 8) | blue; + } + AdvanceByOne: + ++src; + ++col; + if (col >= width) { + col = 0; + ++row; + if ((row % NUM_ARGB_CACHE_ROWS == 0) && (process_func != NULL)) { + process_func(dec, row); + } + if (color_cache != NULL) { + while (last_cached < src) { + VP8LColorCacheInsert(color_cache, *last_cached++); + } + } + } + } else if (code < len_code_limit) { // Backward reference + int dist_code, dist; + const int length_sym = code - NUM_LITERAL_CODES; + const int length = GetCopyLength(length_sym, br); + const int dist_symbol = ReadSymbol(htree_group->htrees[DIST], br); + VP8LFillBitWindow(br); + dist_code = GetCopyDistance(dist_symbol, br); + dist = PlaneCodeToDistance(width, dist_code); + if (br->eos_) break; + if (src - data < (ptrdiff_t)dist || src_end - src < (ptrdiff_t)length) { + goto Error; + } else { + CopyBlock32b(src, dist, length); + } + src += length; + col += length; + while (col >= width) { + col -= width; + ++row; + if ((row % NUM_ARGB_CACHE_ROWS == 0) && (process_func != NULL)) { + process_func(dec, row); + } + } + // Because of the check done above (before 'src' was incremented by + // 'length'), the following holds true. + assert(src <= src_end); + if (col & mask) htree_group = GetHtreeGroupForPos(hdr, col, row); + if (color_cache != NULL) { + while (last_cached < src) { + VP8LColorCacheInsert(color_cache, *last_cached++); + } + } + } else if (code < color_cache_limit) { // Color cache + const int key = code - len_code_limit; + assert(color_cache != NULL); + while (last_cached < src) { + VP8LColorCacheInsert(color_cache, *last_cached++); + } + *src = VP8LColorCacheLookup(color_cache, key); + goto AdvanceByOne; + } else { // Not reached + goto Error; + } + assert(br->eos_ == VP8LIsEndOfStream(br)); + } + + if (dec->incremental_ && br->eos_ && src < src_end) { + RestoreState(dec); + } else if (!br->eos_) { + // Process the remaining rows corresponding to last row-block. + if (process_func != NULL) { + process_func(dec, row); + } + dec->status_ = VP8_STATUS_OK; + dec->last_pixel_ = (int)(src - data); // end-of-scan marker + } else { + // if not incremental, and we are past the end of buffer (eos_=1), then this + // is a real bitstream error. + goto Error; + } + return 1; + + Error: + dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + return 0; +} + +// ----------------------------------------------------------------------------- +// VP8LTransform + +static void ClearTransform(VP8LTransform* const transform) { + tvg::free(transform->data_); + transform->data_ = NULL; +} + +// For security reason, we need to remap the color map to span +// the total possible bundled values, and not just the num_colors. +static int ExpandColorMap(int num_colors, VP8LTransform* const transform) { + int i; + const int final_num_colors = 1 << (8 >> transform->bits_); + uint32_t* const new_color_map = tvg::malloc((uint64_t)final_num_colors * sizeof(*new_color_map)); + if (new_color_map == NULL) { + return 0; + } else { + uint8_t* const data = (uint8_t*)transform->data_; + uint8_t* const new_data = (uint8_t*)new_color_map; + new_color_map[0] = transform->data_[0]; + for (i = 4; i < 4 * num_colors; ++i) { + // Equivalent to AddPixelEq(), on a byte-basis. + new_data[i] = (data[i] + new_data[i - 4]) & 0xff; + } + for (; i < 4 * final_num_colors; ++i) + new_data[i] = 0; // black tail. + tvg::free(transform->data_); + transform->data_ = new_color_map; + } + return 1; +} + +static int ReadTransform(int* const xsize, int const* ysize, + VP8LDecoder* const dec) { + int ok = 1; + VP8LBitReader* const br = &dec->br_; + VP8LTransform* transform = &dec->transforms_[dec->next_transform_]; + const VP8LImageTransformType type = + (VP8LImageTransformType)VP8LReadBits(br, 2); + + // Each transform type can only be present once in the stream. + if (dec->transforms_seen_ & (1U << type)) { + return 0; // Already there, let's not accept the second same transform. + } + dec->transforms_seen_ |= (1U << type); + + transform->type_ = type; + transform->xsize_ = *xsize; + transform->ysize_ = *ysize; + transform->data_ = NULL; + ++dec->next_transform_; + assert(dec->next_transform_ <= NUM_TRANSFORMS); + + switch (type) { + case PREDICTOR_TRANSFORM: + case CROSS_COLOR_TRANSFORM: + transform->bits_ = VP8LReadBits(br, 3) + 2; + ok = DecodeImageStream(VP8LSubSampleSize(transform->xsize_, + transform->bits_), + VP8LSubSampleSize(transform->ysize_, + transform->bits_), + 0, dec, &transform->data_); + break; + case COLOR_INDEXING_TRANSFORM: { + const int num_colors = VP8LReadBits(br, 8) + 1; + const int bits = (num_colors > 16) ? 0 + : (num_colors > 4) ? 1 + : (num_colors > 2) ? 2 + : 3; + *xsize = VP8LSubSampleSize(transform->xsize_, bits); + transform->bits_ = bits; + ok = DecodeImageStream(num_colors, 1, 0, dec, &transform->data_); + ok = ok && ExpandColorMap(num_colors, transform); + break; + } + case SUBTRACT_GREEN: + break; + default: + assert(0); // can't happen + break; + } + + return ok; +} + +// ----------------------------------------------------------------------------- +// VP8LMetadata + +static void InitMetadata(VP8LMetadata* const hdr) { + assert(hdr != NULL); + memset(hdr, 0, sizeof(*hdr)); +} + +static void ClearMetadata(VP8LMetadata* const hdr) { + assert(hdr != NULL); + + tvg::free(hdr->huffman_image_); + tvg::free(hdr->huffman_tables_); + VP8LHtreeGroupsFree(hdr->htree_groups_); + VP8LColorCacheClear(&hdr->color_cache_); + VP8LColorCacheClear(&hdr->saved_color_cache_); + InitMetadata(hdr); +} + +// ----------------------------------------------------------------------------- +// VP8LDecoder + +VP8LDecoder* VP8LNew(void) { + VP8LDecoder* const dec = tvg::calloc(1ULL, sizeof(*dec)); + if (dec == NULL) return NULL; + dec->status_ = VP8_STATUS_OK; + dec->state_ = READ_DIM; + + VP8LDspInit(); // Init critical function pointers. + + return dec; +} + +void VP8LClear(VP8LDecoder* const dec) { + int i; + if (dec == NULL) return; + ClearMetadata(&dec->hdr_); + + tvg::free(dec->pixels_); + dec->pixels_ = NULL; + for (i = 0; i < dec->next_transform_; ++i) { + ClearTransform(&dec->transforms_[i]); + } + dec->next_transform_ = 0; + dec->transforms_seen_ = 0; + + tvg::free(dec->rescaler_memory); + dec->rescaler_memory = NULL; + + dec->output_ = NULL; // leave no trace behind +} + +void VP8LDelete(VP8LDecoder* const dec) { + if (dec != NULL) { + VP8LClear(dec); + tvg::free(dec); + } +} + +static void UpdateDecoder(VP8LDecoder* const dec, int width, int height) { + VP8LMetadata* const hdr = &dec->hdr_; + const int num_bits = hdr->huffman_subsample_bits_; + dec->width_ = width; + dec->height_ = height; + + hdr->huffman_xsize_ = VP8LSubSampleSize(width, num_bits); + hdr->huffman_mask_ = (num_bits == 0) ? ~0 : (1 << num_bits) - 1; +} + +static int DecodeImageStream(int xsize, int ysize, + int is_level0, + VP8LDecoder* const dec, + uint32_t** const decoded_data) { + int ok = 1; + int transform_xsize = xsize; + int transform_ysize = ysize; + VP8LBitReader* const br = &dec->br_; + VP8LMetadata* const hdr = &dec->hdr_; + uint32_t* data = NULL; + int color_cache_bits = 0; + + // Read the transforms (may recurse). + if (is_level0) { + while (ok && VP8LReadBits(br, 1)) { + ok = ReadTransform(&transform_xsize, &transform_ysize, dec); + } + } + + // Color cache + if (ok && VP8LReadBits(br, 1)) { + color_cache_bits = VP8LReadBits(br, 4); + ok = (color_cache_bits >= 1 && color_cache_bits <= MAX_CACHE_BITS); + if (!ok) { + dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + goto End; + } + } + + // Read the Huffman codes (may recurse). + ok = ok && ReadHuffmanCodes(dec, transform_xsize, transform_ysize, + color_cache_bits, is_level0); + if (!ok) { + dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + goto End; + } + + // Finish setting up the color-cache + if (color_cache_bits > 0) { + hdr->color_cache_size_ = 1 << color_cache_bits; + if (!VP8LColorCacheInit(&hdr->color_cache_, color_cache_bits)) { + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + ok = 0; + goto End; + } + } else { + hdr->color_cache_size_ = 0; + } + UpdateDecoder(dec, transform_xsize, transform_ysize); + + if (is_level0) { // level 0 complete + dec->state_ = READ_HDR; + goto End; + } + + { + const uint64_t total_size = (uint64_t)transform_xsize * transform_ysize; + data = tvg::malloc(total_size * sizeof(*data)); + if (data == NULL) { + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + ok = 0; + goto End; + } + } + + // Use the Huffman trees to decode the LZ77 encoded data. + ok = DecodeImageData(dec, data, transform_xsize, transform_ysize, + transform_ysize, NULL); + ok = ok && !br->eos_; + + End: + if (!ok) { + tvg::free(data); + ClearMetadata(hdr); + } else { + if (decoded_data != NULL) { + *decoded_data = data; + } else { + // We allocate image data in this function only for transforms. At level 0 + // (that is: not the transforms), we shouldn't have allocated anything. + assert(data == NULL); + assert(is_level0); + } + dec->last_pixel_ = 0; // Reset for future DECODE_DATA_FUNC() calls. + if (!is_level0) ClearMetadata(hdr); // Clean up temporary data behind. + } + return ok; +} + +//------------------------------------------------------------------------------ +// Allocate internal buffers dec->pixels_ and dec->argb_cache_. +static int AllocateInternalBuffers32b(VP8LDecoder* const dec, int final_width) { + const uint64_t num_pixels = (uint64_t)dec->width_ * dec->height_; + // Scratch buffer corresponding to top-prediction row for transforming the + // first row in the row-blocks. Not needed for paletted alpha. + const uint64_t cache_top_pixels = (uint16_t)final_width; + // Scratch buffer for temporary BGRA storage. Not needed for paletted alpha. + const uint64_t cache_pixels = (uint64_t)final_width * NUM_ARGB_CACHE_ROWS; + const uint64_t total_num_pixels = + num_pixels + cache_top_pixels + cache_pixels; + + assert(dec->width_ <= final_width); + dec->pixels_ = tvg::malloc(total_num_pixels * sizeof(uint32_t)); + if (dec->pixels_ == NULL) { + dec->argb_cache_ = NULL; // for sanity check + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + return 0; + } + dec->argb_cache_ = dec->pixels_ + num_pixels + cache_top_pixels; + return 1; +} + +static int AllocateInternalBuffers8b(VP8LDecoder* const dec) { + const uint64_t total_num_pixels = (uint64_t)dec->width_ * dec->height_; + dec->argb_cache_ = NULL; // for sanity check + dec->pixels_ = tvg::malloc(total_num_pixels * sizeof(uint8_t)); + if (dec->pixels_ == NULL) { + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + return 0; + } + return 1; +} + +//------------------------------------------------------------------------------ + +// Special row-processing that only stores the alpha data. +static void ExtractAlphaRows(VP8LDecoder* const dec, int row) { + const int num_rows = row - dec->last_row_; + const uint32_t* const in = dec->pixels_ + dec->width_ * dec->last_row_; + + if (num_rows <= 0) return; // Nothing to be done. + ApplyInverseTransforms(dec, num_rows, in); + + // Extract alpha (which is stored in the green plane). + { + const int width = dec->io_->width; // the final width (!= dec->width_) + const int cache_pixs = width * num_rows; + uint8_t* const dst = (uint8_t*)dec->io_->opaque + width * dec->last_row_; + const uint32_t* const src = dec->argb_cache_; + int i; + for (i = 0; i < cache_pixs; ++i) dst[i] = (src[i] >> 8) & 0xff; + } + dec->last_row_ = dec->last_out_row_ = row; +} + +int VP8LDecodeAlphaHeader(ALPHDecoder* const alph_dec, + const uint8_t* const data, size_t data_size, + uint8_t* const output) { + int ok = 0; + VP8LDecoder* dec; + VP8Io* io; + assert(alph_dec != NULL); + alph_dec->vp8l_dec_ = VP8LNew(); + if (alph_dec->vp8l_dec_ == NULL) return 0; + dec = alph_dec->vp8l_dec_; + + dec->width_ = alph_dec->width_; + dec->height_ = alph_dec->height_; + dec->io_ = &alph_dec->io_; + io = dec->io_; + + VP8InitIo(io); + WebPInitCustomIo(NULL, io); // Just a sanity Init. io won't be used. + io->opaque = output; + io->width = alph_dec->width_; + io->height = alph_dec->height_; + + dec->status_ = VP8_STATUS_OK; + VP8LInitBitReader(&dec->br_, data, data_size); + + if (!DecodeImageStream(alph_dec->width_, alph_dec->height_, 1, dec, NULL)) { + goto Err; + } + + // Special case: if alpha data uses only the color indexing transform and + // doesn't use color cache (a frequent case), we will use DecodeAlphaData() + // method that only needs allocation of 1 byte per pixel (alpha channel). + if (dec->next_transform_ == 1 && + dec->transforms_[0].type_ == COLOR_INDEXING_TRANSFORM && + Is8bOptimizable(&dec->hdr_)) { + alph_dec->use_8b_decode = 1; + ok = AllocateInternalBuffers8b(dec); + } else { + // Allocate internal buffers (note that dec->width_ may have changed here). + alph_dec->use_8b_decode = 0; + ok = AllocateInternalBuffers32b(dec, alph_dec->width_); + } + + if (!ok) goto Err; + + return 1; + + Err: + VP8LDelete(alph_dec->vp8l_dec_); + alph_dec->vp8l_dec_ = NULL; + return 0; +} + +int VP8LDecodeAlphaImageStream(ALPHDecoder* const alph_dec, int last_row) { + VP8LDecoder* const dec = alph_dec->vp8l_dec_; + assert(dec != NULL); + assert(last_row <= dec->height_); + + if (dec->last_pixel_ == dec->width_ * dec->height_) { + return 1; // done + } + + // Decode (with special row processing). + return alph_dec->use_8b_decode ? + DecodeAlphaData(dec, (uint8_t*)dec->pixels_, dec->width_, dec->height_, + last_row) : + DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_, + last_row, ExtractAlphaRows); +} + +//------------------------------------------------------------------------------ + +int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io) { + int width, height, has_alpha; + + if (dec == NULL) return 0; + if (io == NULL) { + dec->status_ = VP8_STATUS_INVALID_PARAM; + return 0; + } + + dec->io_ = io; + dec->status_ = VP8_STATUS_OK; + VP8LInitBitReader(&dec->br_, io->data, io->data_size); + if (!ReadImageInfo(&dec->br_, &width, &height, &has_alpha)) { + dec->status_ = VP8_STATUS_BITSTREAM_ERROR; + goto Error; + } + dec->state_ = READ_DIM; + io->width = width; + io->height = height; + + if (!DecodeImageStream(width, height, 1, dec, NULL)) goto Error; + return 1; + + Error: + VP8LClear(dec); + assert(dec->status_ != VP8_STATUS_OK); + return 0; +} + +int VP8LDecodeImage(VP8LDecoder* const dec) { + VP8Io* io = NULL; + WebPDecParams* params = NULL; + + // Sanity checks. + if (dec == NULL) return 0; + + assert(dec->hdr_.huffman_tables_ != NULL); + assert(dec->hdr_.htree_groups_ != NULL); + assert(dec->hdr_.num_htree_groups_ > 0); + + io = dec->io_; + assert(io != NULL); + params = (WebPDecParams*)io->opaque; + assert(params != NULL); + + // Initialization. + if (dec->state_ != READ_DATA) { + dec->output_ = params->output; + assert(dec->output_ != NULL); + + if (!WebPIoInitFromOptions(params->options, io, MODE_BGRA)) { + dec->status_ = VP8_STATUS_INVALID_PARAM; + goto Err; + } + + if (!AllocateInternalBuffers32b(dec, io->width)) goto Err; + + if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err; + + if (io->use_scaling || WebPIsPremultipliedMode(dec->output_->colorspace)) { + // need the alpha-multiply functions for premultiplied output or rescaling + WebPInitAlphaProcessing(); + } + if (dec->incremental_) { + if (dec->hdr_.color_cache_size_ > 0 && + dec->hdr_.saved_color_cache_.colors_ == NULL) { + if (!VP8LColorCacheInit(&dec->hdr_.saved_color_cache_, + dec->hdr_.color_cache_.hash_bits_)) { + dec->status_ = VP8_STATUS_OUT_OF_MEMORY; + goto Err; + } + } + } + dec->state_ = READ_DATA; + } + + // Decode. + if (!DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_, + dec->height_, ProcessRows)) { + goto Err; + } + + params->last_y = dec->last_out_row_; + return 1; + + Err: + VP8LClear(dec); + assert(dec->status_ != VP8_STATUS_OK); + return 0; +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/dec/vp8li.h b/components/thorvg-main/src/loaders/webp/dec/vp8li.h new file mode 100644 index 0000000..8886e47 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/vp8li.h @@ -0,0 +1,136 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Lossless decoder: internal header. +// +// Author: Skal (pascal.massimino@gmail.com) +// Vikas Arora(vikaas.arora@gmail.com) + +#ifndef WEBP_DEC_VP8LI_H_ +#define WEBP_DEC_VP8LI_H_ + +#include // for memcpy() +#include "./webpi.h" +#include "../utils/bit_reader.h" +#include "../utils/color_cache.h" +#include "../utils/huffman.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + READ_DATA = 0, + READ_HDR = 1, + READ_DIM = 2 +} VP8LDecodeState; + +typedef struct VP8LTransform VP8LTransform; +struct VP8LTransform { + VP8LImageTransformType type_; // transform type. + int bits_; // subsampling bits defining transform window. + int xsize_; // transform window X index. + int ysize_; // transform window Y index. + uint32_t *data_; // transform data. +}; + +typedef struct { + int color_cache_size_; + VP8LColorCache color_cache_; + VP8LColorCache saved_color_cache_; // for incremental + + int huffman_mask_; + int huffman_subsample_bits_; + int huffman_xsize_; + uint32_t *huffman_image_; + int num_htree_groups_; + HTreeGroup *htree_groups_; + HuffmanCode *huffman_tables_; +} VP8LMetadata; + +typedef struct VP8LDecoder VP8LDecoder; +struct VP8LDecoder { + VP8StatusCode status_; + VP8LDecodeState state_; + VP8Io *io_; + + const WebPDecBuffer *output_; // shortcut to io->opaque->output + + uint32_t *pixels_; // Internal data: either uint8_t* for alpha + // or uint32_t* for BGRA. + uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage. + + VP8LBitReader br_; + int incremental_; // if true, incremental decoding is expected + VP8LBitReader saved_br_; // note: could be local variables too + int saved_last_pixel_; + + int width_; + int height_; + int last_row_; // last input row decoded so far. + int last_pixel_; // last pixel decoded so far. However, it may + // not be transformed, scaled and + // color-converted yet. + int last_out_row_; // last row output so far. + + VP8LMetadata hdr_; + + int next_transform_; + VP8LTransform transforms_[NUM_TRANSFORMS]; + // or'd bitset storing the transforms types. + uint32_t transforms_seen_; + + uint8_t *rescaler_memory; // Working memory for rescaling work. + WebPRescaler *rescaler; // Common rescaler for all channels. +}; + +//------------------------------------------------------------------------------ +// internal functions. Not public. + +struct ALPHDecoder; // Defined in dec/alphai.h. + +// in vp8l.c + +// Decodes image header for alpha data stored using lossless compression. +// Returns false in case of error. +int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec, + const uint8_t* const data, size_t data_size, + uint8_t* const output); + +// Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are +// already decoded in previous call(s), it will resume decoding from where it +// was paused. +// Returns false in case of bitstream error. +int VP8LDecodeAlphaImageStream(struct ALPHDecoder* const alph_dec, + int last_row); + +// Allocates and initialize a new lossless decoder instance. +VP8LDecoder* VP8LNew(void); + +// Decodes the image header. Returns false in case of error. +int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io); + +// Decodes an image. It's required to decode the lossless header before calling +// this function. Returns false in case of error, with updated dec->status_. +int VP8LDecodeImage(VP8LDecoder* const dec); + +// Resets the decoder in its initial state, reclaiming memory. +// Preserves the dec->status_ value. +void VP8LClear(VP8LDecoder* const dec); + +// Clears and deallocate a lossless decoder instance. +void VP8LDelete(VP8LDecoder* const dec); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_DEC_VP8LI_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/dec/webp.cpp b/components/thorvg-main/src/loaders/webp/dec/webp.cpp new file mode 100644 index 0000000..dd21736 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/webp.cpp @@ -0,0 +1,678 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Main decoding functions for WEBP images. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include + +#include "./vp8i.h" +#include "./vp8li.h" +#include "./webpi.h" + + +// VP8X Feature Flags. +typedef enum WebPFeatureFlags { + FRAGMENTS_FLAG = 0x00000001, + ANIMATION_FLAG = 0x00000002, + XMP_FLAG = 0x00000004, + EXIF_FLAG = 0x00000008, + ALPHA_FLAG = 0x00000010, + ICCP_FLAG = 0x00000020 +} WebPFeatureFlags; + + +//------------------------------------------------------------------------------ +// RIFF layout is: +// Offset tag +// 0...3 "RIFF" 4-byte tag +// 4...7 size of image data (including metadata) starting at offset 8 +// 8...11 "WEBP" our form-type signature +// The RIFF container (12 bytes) is followed by appropriate chunks: +// 12..15 "VP8 ": 4-bytes tags, signaling the use of VP8 video format +// 16..19 size of the raw VP8 image data, starting at offset 20 +// 20.... the VP8 bytes +// Or, +// 12..15 "VP8L": 4-bytes tags, signaling the use of VP8L lossless format +// 16..19 size of the raw VP8L image data, starting at offset 20 +// 20.... the VP8L bytes +// Or, +// 12..15 "VP8X": 4-bytes tags, describing the extended-VP8 chunk. +// 16..19 size of the VP8X chunk starting at offset 20. +// 20..23 VP8X flags bit-map corresponding to the chunk-types present. +// 24..26 Width of the Canvas Image. +// 27..29 Height of the Canvas Image. +// There can be extra chunks after the "VP8X" chunk (ICCP, FRGM, ANMF, VP8, +// VP8L, XMP, EXIF ...) +// All sizes are in little-endian order. +// Note: chunk data size must be padded to multiple of 2 when written. + +static WEBP_INLINE uint32_t get_le24(const uint8_t* const data) { + return data[0] | (data[1] << 8) | (data[2] << 16); +} + +static WEBP_INLINE uint32_t get_le32(const uint8_t* const data) { + return (uint32_t)get_le24(data) | (data[3] << 24); +} + +// Validates the RIFF container (if detected) and skips over it. +// If a RIFF container is detected, returns: +// VP8_STATUS_BITSTREAM_ERROR for invalid header, +// VP8_STATUS_NOT_ENOUGH_DATA for truncated data if have_all_data is true, +// and VP8_STATUS_OK otherwise. +// In case there are not enough bytes (partial RIFF container), return 0 for +// *riff_size. Else return the RIFF size extracted from the header. +static VP8StatusCode ParseRIFF(const uint8_t** const data, + size_t* const data_size, int have_all_data, + size_t* const riff_size) { + assert(data != NULL); + assert(data_size != NULL); + assert(riff_size != NULL); + + *riff_size = 0; // Default: no RIFF present. + if (*data_size >= RIFF_HEADER_SIZE && !memcmp(*data, "RIFF", TAG_SIZE)) { + if (memcmp(*data + 8, "WEBP", TAG_SIZE)) { + return VP8_STATUS_BITSTREAM_ERROR; // Wrong image file signature. + } else { + const uint32_t size = get_le32(*data + TAG_SIZE); + // Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn"). + if (size < TAG_SIZE + CHUNK_HEADER_SIZE) { + return VP8_STATUS_BITSTREAM_ERROR; + } + if (size > MAX_CHUNK_PAYLOAD) { + return VP8_STATUS_BITSTREAM_ERROR; + } + if (have_all_data && (size > *data_size - CHUNK_HEADER_SIZE)) { + return VP8_STATUS_NOT_ENOUGH_DATA; // Truncated bitstream. + } + // We have a RIFF container. Skip it. + *riff_size = size; + *data += RIFF_HEADER_SIZE; + *data_size -= RIFF_HEADER_SIZE; + } + } + return VP8_STATUS_OK; +} + +// Validates the VP8X header and skips over it. +// Returns VP8_STATUS_BITSTREAM_ERROR for invalid VP8X header, +// VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and +// VP8_STATUS_OK otherwise. +// If a VP8X chunk is found, found_vp8x is set to true and *width_ptr, +// *height_ptr and *flags_ptr are set to the corresponding values extracted +// from the VP8X chunk. +static VP8StatusCode ParseVP8X(const uint8_t** const data, + size_t* const data_size, + int* const found_vp8x, + int* const width_ptr, int* const height_ptr, + uint32_t* const flags_ptr) { + const uint32_t vp8x_size = CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE; + assert(data != NULL); + assert(data_size != NULL); + assert(found_vp8x != NULL); + + *found_vp8x = 0; + + if (*data_size < CHUNK_HEADER_SIZE) { + return VP8_STATUS_NOT_ENOUGH_DATA; // Insufficient data. + } + + if (!memcmp(*data, "VP8X", TAG_SIZE)) { + int width, height; + uint32_t flags; + const uint32_t chunk_size = get_le32(*data + TAG_SIZE); + if (chunk_size != VP8X_CHUNK_SIZE) { + return VP8_STATUS_BITSTREAM_ERROR; // Wrong chunk size. + } + + // Verify if enough data is available to validate the VP8X chunk. + if (*data_size < vp8x_size) { + return VP8_STATUS_NOT_ENOUGH_DATA; // Insufficient data. + } + flags = get_le32(*data + 8); + width = 1 + get_le24(*data + 12); + height = 1 + get_le24(*data + 15); + if (width * (uint64_t)height >= MAX_IMAGE_AREA) { + return VP8_STATUS_BITSTREAM_ERROR; // image is too large + } + + if (flags_ptr != NULL) *flags_ptr = flags; + if (width_ptr != NULL) *width_ptr = width; + if (height_ptr != NULL) *height_ptr = height; + // Skip over VP8X header bytes. + *data += vp8x_size; + *data_size -= vp8x_size; + *found_vp8x = 1; + } + return VP8_STATUS_OK; +} + +// Skips to the next VP8/VP8L chunk header in the data given the size of the +// RIFF chunk 'riff_size'. +// Returns VP8_STATUS_BITSTREAM_ERROR if any invalid chunk size is encountered, +// VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and +// VP8_STATUS_OK otherwise. +// If an alpha chunk is found, *alpha_data and *alpha_size are set +// appropriately. +static VP8StatusCode ParseOptionalChunks(const uint8_t** const data, + size_t* const data_size, + size_t const riff_size, + const uint8_t** const alpha_data, + size_t* const alpha_size) { + const uint8_t* buf; + size_t buf_size; + uint32_t total_size = TAG_SIZE + // "WEBP". + CHUNK_HEADER_SIZE + // "VP8Xnnnn". + VP8X_CHUNK_SIZE; // data. + assert(data != NULL); + assert(data_size != NULL); + buf = *data; + buf_size = *data_size; + + assert(alpha_data != NULL); + assert(alpha_size != NULL); + *alpha_data = NULL; + *alpha_size = 0; + + while (1) { + uint32_t chunk_size; + uint32_t disk_chunk_size; // chunk_size with padding + + *data = buf; + *data_size = buf_size; + + if (buf_size < CHUNK_HEADER_SIZE) { // Insufficient data. + return VP8_STATUS_NOT_ENOUGH_DATA; + } + + chunk_size = get_le32(buf + TAG_SIZE); + if (chunk_size > MAX_CHUNK_PAYLOAD) { + return VP8_STATUS_BITSTREAM_ERROR; // Not a valid chunk size. + } + // For odd-sized chunk-payload, there's one byte padding at the end. + disk_chunk_size = (CHUNK_HEADER_SIZE + chunk_size + 1) & ~1; + total_size += disk_chunk_size; + + // Check that total bytes skipped so far does not exceed riff_size. + if (riff_size > 0 && (total_size > riff_size)) { + return VP8_STATUS_BITSTREAM_ERROR; // Not a valid chunk size. + } + + // Start of a (possibly incomplete) VP8/VP8L chunk implies that we have + // parsed all the optional chunks. + // Note: This check must occur before the check 'buf_size < disk_chunk_size' + // below to allow incomplete VP8/VP8L chunks. + if (!memcmp(buf, "VP8 ", TAG_SIZE) || + !memcmp(buf, "VP8L", TAG_SIZE)) { + return VP8_STATUS_OK; + } + + if (buf_size < disk_chunk_size) { // Insufficient data. + return VP8_STATUS_NOT_ENOUGH_DATA; + } + + if (!memcmp(buf, "ALPH", TAG_SIZE)) { // A valid ALPH header. + *alpha_data = buf + CHUNK_HEADER_SIZE; + *alpha_size = chunk_size; + } + + // We have a full and valid chunk; skip it. + buf += disk_chunk_size; + buf_size -= disk_chunk_size; + } +} + +// Validates the VP8/VP8L Header ("VP8 nnnn" or "VP8L nnnn") and skips over it. +// Returns VP8_STATUS_BITSTREAM_ERROR for invalid (chunk larger than +// riff_size) VP8/VP8L header, +// VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and +// VP8_STATUS_OK otherwise. +// If a VP8/VP8L chunk is found, *chunk_size is set to the total number of bytes +// extracted from the VP8/VP8L chunk header. +// The flag '*is_lossless' is set to 1 in case of VP8L chunk / raw VP8L data. +static VP8StatusCode ParseVP8Header(const uint8_t** const data_ptr, + size_t* const data_size, int have_all_data, + size_t riff_size, size_t* const chunk_size, + int* const is_lossless) { + const uint8_t* const data = *data_ptr; + const int is_vp8 = !memcmp(data, "VP8 ", TAG_SIZE); + const int is_vp8l = !memcmp(data, "VP8L", TAG_SIZE); + const uint32_t minimal_size = + TAG_SIZE + CHUNK_HEADER_SIZE; // "WEBP" + "VP8 nnnn" OR + // "WEBP" + "VP8Lnnnn" + assert(data != NULL); + assert(data_size != NULL); + assert(chunk_size != NULL); + assert(is_lossless != NULL); + + if (*data_size < CHUNK_HEADER_SIZE) { + return VP8_STATUS_NOT_ENOUGH_DATA; // Insufficient data. + } + + if (is_vp8 || is_vp8l) { + // Bitstream contains VP8/VP8L header. + const uint32_t size = get_le32(data + TAG_SIZE); + if ((riff_size >= minimal_size) && (size > riff_size - minimal_size)) { + return VP8_STATUS_BITSTREAM_ERROR; // Inconsistent size information. + } + if (have_all_data && (size > *data_size - CHUNK_HEADER_SIZE)) { + return VP8_STATUS_NOT_ENOUGH_DATA; // Truncated bitstream. + } + // Skip over CHUNK_HEADER_SIZE bytes from VP8/VP8L Header. + *chunk_size = size; + *data_ptr += CHUNK_HEADER_SIZE; + *data_size -= CHUNK_HEADER_SIZE; + *is_lossless = is_vp8l; + } else { + // Raw VP8/VP8L bitstream (no header). + *is_lossless = VP8LCheckSignature(data, *data_size); + *chunk_size = *data_size; + } + + return VP8_STATUS_OK; +} + +//------------------------------------------------------------------------------ + +// Fetch '*width', '*height', '*has_alpha' and fill out 'headers' based on +// 'data'. All the output parameters may be NULL. If 'headers' is NULL only the +// minimal amount will be read to fetch the remaining parameters. +// If 'headers' is non-NULL this function will attempt to locate both alpha +// data (with or without a VP8X chunk) and the bitstream chunk (VP8/VP8L). +// Note: The following chunk sequences (before the raw VP8/VP8L data) are +// considered valid by this function: +// RIFF + VP8(L) +// RIFF + VP8X + (optional chunks) + VP8(L) +// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose. +// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose. +static VP8StatusCode ParseHeadersInternal(const uint8_t* data, + size_t data_size, + int* const width, + int* const height, + int* const has_alpha, + int* const has_animation, + int* const format, + WebPHeaderStructure* const headers) { + int canvas_width = 0; + int canvas_height = 0; + int image_width = 0; + int image_height = 0; + int found_riff = 0; + int found_vp8x = 0; + int animation_present = 0; + int fragments_present = 0; + const int have_all_data = (headers != NULL) ? headers->have_all_data : 0; + + VP8StatusCode status; + WebPHeaderStructure hdrs; + + if (data == NULL || data_size < RIFF_HEADER_SIZE) { + return VP8_STATUS_NOT_ENOUGH_DATA; + } + memset(&hdrs, 0, sizeof(hdrs)); + hdrs.data = data; + hdrs.data_size = data_size; + + // Skip over RIFF header. + status = ParseRIFF(&data, &data_size, have_all_data, &hdrs.riff_size); + if (status != VP8_STATUS_OK) { + return status; // Wrong RIFF header / insufficient data. + } + found_riff = (hdrs.riff_size > 0); + + // Skip over VP8X. + { + uint32_t flags = 0; + status = ParseVP8X(&data, &data_size, &found_vp8x, + &canvas_width, &canvas_height, &flags); + if (status != VP8_STATUS_OK) { + return status; // Wrong VP8X / insufficient data. + } + animation_present = !!(flags & ANIMATION_FLAG); + fragments_present = !!(flags & FRAGMENTS_FLAG); + if (!found_riff && found_vp8x) { + // Note: This restriction may be removed in the future, if it becomes + // necessary to send VP8X chunk to the decoder. + return VP8_STATUS_BITSTREAM_ERROR; + } + if (has_alpha != NULL) *has_alpha = !!(flags & ALPHA_FLAG); + if (has_animation != NULL) *has_animation = animation_present; + if (format != NULL) *format = 0; // default = undefined + + image_width = canvas_width; + image_height = canvas_height; + if (found_vp8x && (animation_present || fragments_present) && + headers == NULL) { + status = VP8_STATUS_OK; + goto ReturnWidthHeight; // Just return features from VP8X header. + } + } + + if (data_size < TAG_SIZE) { + status = VP8_STATUS_NOT_ENOUGH_DATA; + goto ReturnWidthHeight; + } + + // Skip over optional chunks if data started with "RIFF + VP8X" or "ALPH". + if ((found_riff && found_vp8x) || + (!found_riff && !found_vp8x && !memcmp(data, "ALPH", TAG_SIZE))) { + status = ParseOptionalChunks(&data, &data_size, hdrs.riff_size, + &hdrs.alpha_data, &hdrs.alpha_data_size); + if (status != VP8_STATUS_OK) { + goto ReturnWidthHeight; // Invalid chunk size / insufficient data. + } + } + + // Skip over VP8/VP8L header. + status = ParseVP8Header(&data, &data_size, have_all_data, hdrs.riff_size, + &hdrs.compressed_size, &hdrs.is_lossless); + if (status != VP8_STATUS_OK) { + goto ReturnWidthHeight; // Wrong VP8/VP8L chunk-header / insufficient data. + } + if (hdrs.compressed_size > MAX_CHUNK_PAYLOAD) { + return VP8_STATUS_BITSTREAM_ERROR; + } + + if (format != NULL && !(animation_present || fragments_present)) { + *format = hdrs.is_lossless ? 2 : 1; + } + + if (!hdrs.is_lossless) { + if (data_size < VP8_FRAME_HEADER_SIZE) { + status = VP8_STATUS_NOT_ENOUGH_DATA; + goto ReturnWidthHeight; + } + // Validates raw VP8 data. + if (!VP8GetInfo(data, data_size, (uint32_t)hdrs.compressed_size, + &image_width, &image_height)) { + return VP8_STATUS_BITSTREAM_ERROR; + } + } else { + if (data_size < VP8L_FRAME_HEADER_SIZE) { + status = VP8_STATUS_NOT_ENOUGH_DATA; + goto ReturnWidthHeight; + } + // Validates raw VP8L data. + if (!VP8LGetInfo(data, data_size, &image_width, &image_height, has_alpha)) { + return VP8_STATUS_BITSTREAM_ERROR; + } + } + // Validates image size coherency. + if (found_vp8x) { + if (canvas_width != image_width || canvas_height != image_height) { + return VP8_STATUS_BITSTREAM_ERROR; + } + } + if (headers != NULL) { + *headers = hdrs; + headers->offset = data - headers->data; + assert((uint64_t)(data - headers->data) < MAX_CHUNK_PAYLOAD); + assert(headers->offset == headers->data_size - data_size); + } + ReturnWidthHeight: + if (status == VP8_STATUS_OK || + (status == VP8_STATUS_NOT_ENOUGH_DATA && found_vp8x && headers == NULL)) { + if (has_alpha != NULL) { + // If the data did not contain a VP8X/VP8L chunk the only definitive way + // to set this is by looking for alpha data (from an ALPH chunk). + *has_alpha |= (hdrs.alpha_data != NULL); + } + if (width != NULL) *width = image_width; + if (height != NULL) *height = image_height; + return VP8_STATUS_OK; + } else { + return status; + } +} + +// Skips over all valid chunks prior to the first VP8/VP8L frame header. +// Returns: VP8_STATUS_OK, VP8_STATUS_BITSTREAM_ERROR (invalid header/chunk), +// VP8_STATUS_NOT_ENOUGH_DATA (partial input) or VP8_STATUS_UNSUPPORTED_FEATURE +// in the case of non-decodable features (animation for instance). +// In 'headers', compressed_size, offset, alpha_data, alpha_size, and lossless +// fields are updated appropriately upon success. +static VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers) { + VP8StatusCode status; + int has_animation = 0; + assert(headers != NULL); + // fill out headers, ignore width/height/has_alpha. + status = ParseHeadersInternal(headers->data, headers->data_size, + NULL, NULL, NULL, &has_animation, + NULL, headers); + if (status == VP8_STATUS_OK || status == VP8_STATUS_NOT_ENOUGH_DATA) { + // TODO(jzern): full support of animation frames will require API additions. + if (has_animation) { + status = VP8_STATUS_UNSUPPORTED_FEATURE; + } + } + return status; +} + +//------------------------------------------------------------------------------ +// "Into" decoding variants + +// Main flow +static VP8StatusCode DecodeInto(const uint8_t* const data, size_t data_size, + WebPDecParams* const params) { + VP8StatusCode status; + VP8Io io; + WebPHeaderStructure headers; + + headers.data = data; + headers.data_size = data_size; + headers.have_all_data = 1; + status = WebPParseHeaders(&headers); // Process Pre-VP8 chunks. + if (status != VP8_STATUS_OK) { + return status; + } + + assert(params != NULL); + VP8InitIo(&io); + io.data = headers.data + headers.offset; + io.data_size = headers.data_size - headers.offset; + WebPInitCustomIo(params, &io); // Plug the I/O functions. + + if (!headers.is_lossless) { + VP8Decoder* const dec = VP8New(); + if (dec == NULL) { + return VP8_STATUS_OUT_OF_MEMORY; + } + dec->alpha_data_ = headers.alpha_data; + dec->alpha_data_size_ = headers.alpha_data_size; + + // Decode bitstream header, update io->width/io->height. + if (!VP8GetHeaders(dec, &io)) { + status = dec->status_; // An error occurred. Grab error status. + } else { + // Allocate/check output buffers. + status = WebPAllocateDecBuffer(io.width, io.height, params->options, + params->output); + if (status == VP8_STATUS_OK) { // Decode + VP8InitDithering(params->options, dec); + if (!VP8Decode(dec, &io)) { + status = dec->status_; + } + } + } + VP8Delete(dec); + } else { + VP8LDecoder* const dec = VP8LNew(); + if (dec == NULL) { + return VP8_STATUS_OUT_OF_MEMORY; + } + if (!VP8LDecodeHeader(dec, &io)) { + status = dec->status_; // An error occurred. Grab error status. + } else { + // Allocate/check output buffers. + status = WebPAllocateDecBuffer(io.width, io.height, params->options, + params->output); + if (status == VP8_STATUS_OK) { // Decode + if (!VP8LDecodeImage(dec)) { + status = dec->status_; + } + } + } + VP8LDelete(dec); + } + + if (status != VP8_STATUS_OK) { + WebPFreeDecBuffer(params->output); + } + + if (params->options != NULL && params->options->flip) { + status = WebPFlipBuffer(params->output); + } + return status; +} + +//------------------------------------------------------------------------------ + +static uint8_t* Decode(WEBP_CSP_MODE mode, const uint8_t* const data, + size_t data_size, int* const width, int* const height, + WebPDecBuffer* const keep_info) { + WebPDecParams params; + WebPDecBuffer output; + + WebPInitDecBuffer(&output); + memset(¶ms, 0, sizeof(params)); + params.output = &output; + output.colorspace = mode; + + // Retrieve (and report back) the required dimensions from bitstream. + if (!WebPGetInfo(data, data_size, &output.width, &output.height)) { + return NULL; + } + if (width != NULL) *width = output.width; + if (height != NULL) *height = output.height; + + // Decode + if (DecodeInto(data, data_size, ¶ms) != VP8_STATUS_OK) { + return NULL; + } + if (keep_info != NULL) { // keep track of the side-info + WebPCopyDecBuffer(&output, keep_info); + } + // return decoded samples (don't clear 'output'!) + return WebPIsRGBMode(mode) ? output.u.RGBA.rgba : output.u.YUVA.y; +} + + +static void DefaultFeatures(WebPBitstreamFeatures* const features) { + assert(features != NULL); + memset(features, 0, sizeof(*features)); +} + +static VP8StatusCode GetFeatures(const uint8_t* const data, size_t data_size, + WebPBitstreamFeatures* const features) { + if (features == NULL || data == NULL) { + return VP8_STATUS_INVALID_PARAM; + } + DefaultFeatures(features); + + // Only parse enough of the data to retrieve the features. + return ParseHeadersInternal(data, data_size, + &features->width, &features->height, + &features->has_alpha, &features->has_animation, + &features->format, NULL); +} + +//------------------------------------------------------------------------------ +// Cropping and rescaling. + +int WebPIoInitFromOptions(const WebPDecoderOptions* const options, + VP8Io* const io, WEBP_CSP_MODE src_colorspace) { + const int W = io->width; + const int H = io->height; + int x = 0, y = 0, w = W, h = H; + + // Cropping + io->use_cropping = (options != NULL) && (options->use_cropping > 0); + if (io->use_cropping) { + w = options->crop_width; + h = options->crop_height; + x = options->crop_left; + y = options->crop_top; + if (!WebPIsRGBMode(src_colorspace)) { // only snap for YUV420 + x &= ~1; + y &= ~1; + } + if (x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > W || y + h > H) { + return 0; // out of frame boundary error + } + } + io->crop_left = x; + io->crop_top = y; + io->crop_right = x + w; + io->crop_bottom = y + h; + io->mb_w = w; + io->mb_h = h; + + // Scaling + io->use_scaling = (options != NULL) && (options->use_scaling > 0); + if (io->use_scaling) { + if (options->scaled_width <= 0 || options->scaled_height <= 0) { + return 0; + } + io->scaled_width = options->scaled_width; + io->scaled_height = options->scaled_height; + } + + // Filter + io->bypass_filtering = options && options->bypass_filtering; + + // Fancy upsampler +#ifdef FANCY_UPSAMPLING + io->fancy_upsampling = (options == NULL) || (!options->no_fancy_upsampling); +#endif + + if (io->use_scaling) { + // disable filter (only for large downscaling ratio). + io->bypass_filtering = (io->scaled_width < W * 3 / 4) && + (io->scaled_height < H * 3 / 4); + io->fancy_upsampling = 0; + } + return 1; +} + +//------------------------------------------------------------------------------ + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size, + int* width, int* height) { + return Decode(MODE_bgrA, data, data_size, width, height, NULL); +} + +uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size, + int* width, int* height) { + return Decode(MODE_rgbA, data, data_size, width, height, NULL); +} + +int WebPGetInfo(const uint8_t* data, size_t data_size, + int* width, int* height) { + WebPBitstreamFeatures features; + + if (GetFeatures(data, data_size, &features) != VP8_STATUS_OK) { + return 0; + } + + if (width != NULL) { + *width = features.width; + } + if (height != NULL) { + *height = features.height; + } + + return 1; +} diff --git a/components/thorvg-main/src/loaders/webp/dec/webpi.h b/components/thorvg-main/src/loaders/webp/dec/webpi.h new file mode 100644 index 0000000..aed81cb --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dec/webpi.h @@ -0,0 +1,108 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Internal header: WebP decoding parameters and custom IO on buffer +// +// Author: somnath@google.com (Somnath Banerjee) + +#ifndef WEBP_DEC_WEBPI_H_ +#define WEBP_DEC_WEBPI_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../utils/rescaler.h" +#include "./decode_vp8.h" + +//------------------------------------------------------------------------------ +// WebPDecParams: Decoding output parameters. Transient internal object. + +typedef struct WebPDecParams WebPDecParams; +typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p); +typedef int (*OutputRowFunc)(WebPDecParams* const p, int y_pos); + +struct WebPDecParams { + WebPDecBuffer* output; // output buffer. + uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler + // or used for tmp rescaling + + int last_y; // coordinate of the line that was last output + const WebPDecoderOptions* options; // if not NULL, use alt decoding features + // rescalers + WebPRescaler scaler_y, scaler_u, scaler_v, scaler_a; + void* memory; // overall scratch memory for the output work. + + OutputFunc emit; // output RGB or YUV samples + OutputFunc emit_alpha; // output alpha channel + OutputRowFunc emit_alpha_row; // output one line of rescaled alpha values +}; + + +//------------------------------------------------------------------------------ +// Header parsing helpers + +// Structure storing a description of the RIFF headers. +typedef struct { + const uint8_t* data; // input buffer + size_t data_size; // input buffer size + int have_all_data; // true if all data is known to be available + size_t offset; // offset to main data chunk (VP8 or VP8L) + const uint8_t* alpha_data; // points to alpha chunk (if present) + size_t alpha_data_size; // alpha chunk size + size_t compressed_size; // VP8/VP8L compressed data size + size_t riff_size; // size of the riff payload (or 0 if absent) + int is_lossless; // true if a VP8L chunk is present +} WebPHeaderStructure; + + +//------------------------------------------------------------------------------ +// Misc utils + +// Initializes VP8Io with custom setup, io and teardown functions. The default +// hooks will use the supplied 'params' as io->opaque handle. +void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io); + +// Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers +// to the *compressed* format, not the output one. +int WebPIoInitFromOptions(const WebPDecoderOptions* const options, + VP8Io* const io, WEBP_CSP_MODE src_colorspace); + +//------------------------------------------------------------------------------ +// Internal functions regarding WebPDecBuffer memory (in buffer.c). +// Don't really need to be externally visible for now. + +// Prepare 'buffer' with the requested initial dimensions width/height. +// If no external storage is supplied, initializes buffer by allocating output +// memory and setting up the stride information. Validate the parameters. Return +// an error code in case of problem (no memory, or invalid stride / size / +// dimension / etc.). If *options is not NULL, also verify that the options' +// parameters are valid and apply them to the width/height dimensions of the +// output buffer. This takes cropping / scaling / rotation into account. +// Also incorporates the options->flip flag to flip the buffer parameters if +// needed. +VP8StatusCode WebPAllocateDecBuffer(int width, int height, + const WebPDecoderOptions* const options, + WebPDecBuffer* const buffer); + +// Flip buffer vertically by negating the various strides. +VP8StatusCode WebPFlipBuffer(WebPDecBuffer* const buffer); + +// Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the +// memory (still held by 'src'). +void WebPCopyDecBuffer(const WebPDecBuffer* const src, + WebPDecBuffer* const dst); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_DEC_WEBPI_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/dsp/alpha_processing.cpp b/components/thorvg-main/src/loaders/webp/dsp/alpha_processing.cpp new file mode 100644 index 0000000..bef13f4 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/alpha_processing.cpp @@ -0,0 +1,377 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Utilities for processing transparent channel. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include +#include "./dsp.h" + +// Tables can be faster on some platform but incur some extra binary size (~2k). +// #define USE_TABLES_FOR_ALPHA_MULT + +// ----------------------------------------------------------------------------- + +#define MFIX 24 // 24bit fixed-point arithmetic +#define HALF ((1u << MFIX) >> 1) +#define KINV_255 ((1u << MFIX) / 255u) + +static uint32_t Mult(uint8_t x, uint32_t mult) { + const uint32_t v = (x * mult + HALF) >> MFIX; + assert(v <= 255); // <- 24bit precision is enough to ensure that. + return v; +} + +#ifdef USE_TABLES_FOR_ALPHA_MULT + +static const uint32_t kMultTables[2][256] = { + { // (255u << MFIX) / alpha + 0x00000000, 0xff000000, 0x7f800000, 0x55000000, 0x3fc00000, 0x33000000, + 0x2a800000, 0x246db6db, 0x1fe00000, 0x1c555555, 0x19800000, 0x172e8ba2, + 0x15400000, 0x139d89d8, 0x1236db6d, 0x11000000, 0x0ff00000, 0x0f000000, + 0x0e2aaaaa, 0x0d6bca1a, 0x0cc00000, 0x0c249249, 0x0b9745d1, 0x0b1642c8, + 0x0aa00000, 0x0a333333, 0x09cec4ec, 0x0971c71c, 0x091b6db6, 0x08cb08d3, + 0x08800000, 0x0839ce73, 0x07f80000, 0x07ba2e8b, 0x07800000, 0x07492492, + 0x07155555, 0x06e45306, 0x06b5e50d, 0x0689d89d, 0x06600000, 0x063831f3, + 0x06124924, 0x05ee23b8, 0x05cba2e8, 0x05aaaaaa, 0x058b2164, 0x056cefa8, + 0x05500000, 0x05343eb1, 0x05199999, 0x05000000, 0x04e76276, 0x04cfb2b7, + 0x04b8e38e, 0x04a2e8ba, 0x048db6db, 0x0479435e, 0x04658469, 0x045270d0, + 0x04400000, 0x042e29f7, 0x041ce739, 0x040c30c3, 0x03fc0000, 0x03ec4ec4, + 0x03dd1745, 0x03ce540f, 0x03c00000, 0x03b21642, 0x03a49249, 0x03976fc6, + 0x038aaaaa, 0x037e3f1f, 0x03722983, 0x03666666, 0x035af286, 0x034fcace, + 0x0344ec4e, 0x033a5440, 0x03300000, 0x0325ed09, 0x031c18f9, 0x0312818a, + 0x03092492, 0x03000000, 0x02f711dc, 0x02ee5846, 0x02e5d174, 0x02dd7baf, + 0x02d55555, 0x02cd5cd5, 0x02c590b2, 0x02bdef7b, 0x02b677d4, 0x02af286b, + 0x02a80000, 0x02a0fd5c, 0x029a1f58, 0x029364d9, 0x028ccccc, 0x0286562d, + 0x02800000, 0x0279c952, 0x0273b13b, 0x026db6db, 0x0267d95b, 0x026217ec, + 0x025c71c7, 0x0256e62a, 0x0251745d, 0x024c1bac, 0x0246db6d, 0x0241b2f9, + 0x023ca1af, 0x0237a6f4, 0x0232c234, 0x022df2df, 0x02293868, 0x02249249, + 0x02200000, 0x021b810e, 0x021714fb, 0x0212bb51, 0x020e739c, 0x020a3d70, + 0x02061861, 0x02020408, 0x01fe0000, 0x01fa0be8, 0x01f62762, 0x01f25213, + 0x01ee8ba2, 0x01ead3ba, 0x01e72a07, 0x01e38e38, 0x01e00000, 0x01dc7f10, + 0x01d90b21, 0x01d5a3e9, 0x01d24924, 0x01cefa8d, 0x01cbb7e3, 0x01c880e5, + 0x01c55555, 0x01c234f7, 0x01bf1f8f, 0x01bc14e5, 0x01b914c1, 0x01b61eed, + 0x01b33333, 0x01b05160, 0x01ad7943, 0x01aaaaaa, 0x01a7e567, 0x01a5294a, + 0x01a27627, 0x019fcbd2, 0x019d2a20, 0x019a90e7, 0x01980000, 0x01957741, + 0x0192f684, 0x01907da4, 0x018e0c7c, 0x018ba2e8, 0x018940c5, 0x0186e5f0, + 0x01849249, 0x018245ae, 0x01800000, 0x017dc11f, 0x017b88ee, 0x0179574e, + 0x01772c23, 0x01750750, 0x0172e8ba, 0x0170d045, 0x016ebdd7, 0x016cb157, + 0x016aaaaa, 0x0168a9b9, 0x0166ae6a, 0x0164b8a7, 0x0162c859, 0x0160dd67, + 0x015ef7bd, 0x015d1745, 0x015b3bea, 0x01596596, 0x01579435, 0x0155c7b4, + 0x01540000, 0x01523d03, 0x01507eae, 0x014ec4ec, 0x014d0fac, 0x014b5edc, + 0x0149b26c, 0x01480a4a, 0x01466666, 0x0144c6af, 0x01432b16, 0x0141938b, + 0x01400000, 0x013e7063, 0x013ce4a9, 0x013b5cc0, 0x0139d89d, 0x01385830, + 0x0136db6d, 0x01356246, 0x0133ecad, 0x01327a97, 0x01310bf6, 0x012fa0be, + 0x012e38e3, 0x012cd459, 0x012b7315, 0x012a150a, 0x0128ba2e, 0x01276276, + 0x01260dd6, 0x0124bc44, 0x01236db6, 0x01222222, 0x0120d97c, 0x011f93bc, + 0x011e50d7, 0x011d10c4, 0x011bd37a, 0x011a98ef, 0x0119611a, 0x01182bf2, + 0x0116f96f, 0x0115c988, 0x01149c34, 0x0113716a, 0x01124924, 0x01112358, + 0x01100000, 0x010edf12, 0x010dc087, 0x010ca458, 0x010b8a7d, 0x010a72f0, + 0x01095da8, 0x01084a9f, 0x010739ce, 0x01062b2e, 0x01051eb8, 0x01041465, + 0x01030c30, 0x01020612, 0x01010204, 0x01000000 }, + { // alpha * KINV_255 + 0x00000000, 0x00010101, 0x00020202, 0x00030303, 0x00040404, 0x00050505, + 0x00060606, 0x00070707, 0x00080808, 0x00090909, 0x000a0a0a, 0x000b0b0b, + 0x000c0c0c, 0x000d0d0d, 0x000e0e0e, 0x000f0f0f, 0x00101010, 0x00111111, + 0x00121212, 0x00131313, 0x00141414, 0x00151515, 0x00161616, 0x00171717, + 0x00181818, 0x00191919, 0x001a1a1a, 0x001b1b1b, 0x001c1c1c, 0x001d1d1d, + 0x001e1e1e, 0x001f1f1f, 0x00202020, 0x00212121, 0x00222222, 0x00232323, + 0x00242424, 0x00252525, 0x00262626, 0x00272727, 0x00282828, 0x00292929, + 0x002a2a2a, 0x002b2b2b, 0x002c2c2c, 0x002d2d2d, 0x002e2e2e, 0x002f2f2f, + 0x00303030, 0x00313131, 0x00323232, 0x00333333, 0x00343434, 0x00353535, + 0x00363636, 0x00373737, 0x00383838, 0x00393939, 0x003a3a3a, 0x003b3b3b, + 0x003c3c3c, 0x003d3d3d, 0x003e3e3e, 0x003f3f3f, 0x00404040, 0x00414141, + 0x00424242, 0x00434343, 0x00444444, 0x00454545, 0x00464646, 0x00474747, + 0x00484848, 0x00494949, 0x004a4a4a, 0x004b4b4b, 0x004c4c4c, 0x004d4d4d, + 0x004e4e4e, 0x004f4f4f, 0x00505050, 0x00515151, 0x00525252, 0x00535353, + 0x00545454, 0x00555555, 0x00565656, 0x00575757, 0x00585858, 0x00595959, + 0x005a5a5a, 0x005b5b5b, 0x005c5c5c, 0x005d5d5d, 0x005e5e5e, 0x005f5f5f, + 0x00606060, 0x00616161, 0x00626262, 0x00636363, 0x00646464, 0x00656565, + 0x00666666, 0x00676767, 0x00686868, 0x00696969, 0x006a6a6a, 0x006b6b6b, + 0x006c6c6c, 0x006d6d6d, 0x006e6e6e, 0x006f6f6f, 0x00707070, 0x00717171, + 0x00727272, 0x00737373, 0x00747474, 0x00757575, 0x00767676, 0x00777777, + 0x00787878, 0x00797979, 0x007a7a7a, 0x007b7b7b, 0x007c7c7c, 0x007d7d7d, + 0x007e7e7e, 0x007f7f7f, 0x00808080, 0x00818181, 0x00828282, 0x00838383, + 0x00848484, 0x00858585, 0x00868686, 0x00878787, 0x00888888, 0x00898989, + 0x008a8a8a, 0x008b8b8b, 0x008c8c8c, 0x008d8d8d, 0x008e8e8e, 0x008f8f8f, + 0x00909090, 0x00919191, 0x00929292, 0x00939393, 0x00949494, 0x00959595, + 0x00969696, 0x00979797, 0x00989898, 0x00999999, 0x009a9a9a, 0x009b9b9b, + 0x009c9c9c, 0x009d9d9d, 0x009e9e9e, 0x009f9f9f, 0x00a0a0a0, 0x00a1a1a1, + 0x00a2a2a2, 0x00a3a3a3, 0x00a4a4a4, 0x00a5a5a5, 0x00a6a6a6, 0x00a7a7a7, + 0x00a8a8a8, 0x00a9a9a9, 0x00aaaaaa, 0x00ababab, 0x00acacac, 0x00adadad, + 0x00aeaeae, 0x00afafaf, 0x00b0b0b0, 0x00b1b1b1, 0x00b2b2b2, 0x00b3b3b3, + 0x00b4b4b4, 0x00b5b5b5, 0x00b6b6b6, 0x00b7b7b7, 0x00b8b8b8, 0x00b9b9b9, + 0x00bababa, 0x00bbbbbb, 0x00bcbcbc, 0x00bdbdbd, 0x00bebebe, 0x00bfbfbf, + 0x00c0c0c0, 0x00c1c1c1, 0x00c2c2c2, 0x00c3c3c3, 0x00c4c4c4, 0x00c5c5c5, + 0x00c6c6c6, 0x00c7c7c7, 0x00c8c8c8, 0x00c9c9c9, 0x00cacaca, 0x00cbcbcb, + 0x00cccccc, 0x00cdcdcd, 0x00cecece, 0x00cfcfcf, 0x00d0d0d0, 0x00d1d1d1, + 0x00d2d2d2, 0x00d3d3d3, 0x00d4d4d4, 0x00d5d5d5, 0x00d6d6d6, 0x00d7d7d7, + 0x00d8d8d8, 0x00d9d9d9, 0x00dadada, 0x00dbdbdb, 0x00dcdcdc, 0x00dddddd, + 0x00dedede, 0x00dfdfdf, 0x00e0e0e0, 0x00e1e1e1, 0x00e2e2e2, 0x00e3e3e3, + 0x00e4e4e4, 0x00e5e5e5, 0x00e6e6e6, 0x00e7e7e7, 0x00e8e8e8, 0x00e9e9e9, + 0x00eaeaea, 0x00ebebeb, 0x00ececec, 0x00ededed, 0x00eeeeee, 0x00efefef, + 0x00f0f0f0, 0x00f1f1f1, 0x00f2f2f2, 0x00f3f3f3, 0x00f4f4f4, 0x00f5f5f5, + 0x00f6f6f6, 0x00f7f7f7, 0x00f8f8f8, 0x00f9f9f9, 0x00fafafa, 0x00fbfbfb, + 0x00fcfcfc, 0x00fdfdfd, 0x00fefefe, 0x00ffffff } +}; + +static WEBP_INLINE uint32_t GetScale(uint32_t a, int inverse) { + return kMultTables[!inverse][a]; +} + +#else + +static WEBP_INLINE uint32_t GetScale(uint32_t a, int inverse) { + return inverse ? (255u << MFIX) / a : a * KINV_255; +} + +#endif // USE_TABLES_FOR_ALPHA_MULT + +void WebPMultARGBRowC(uint32_t* const ptr, int width, int inverse) { + int x; + for (x = 0; x < width; ++x) { + const uint32_t argb = ptr[x]; + if (argb < 0xff000000u) { // alpha < 255 + if (argb <= 0x00ffffffu) { // alpha == 0 + ptr[x] = 0; + } else { + const uint32_t alpha = (argb >> 24) & 0xff; + const uint32_t scale = GetScale(alpha, inverse); + uint32_t out = argb & 0xff000000u; + out |= Mult(argb >> 0, scale) << 0; + out |= Mult(argb >> 8, scale) << 8; + out |= Mult(argb >> 16, scale) << 16; + ptr[x] = out; + } + } + } +} + +void WebPMultRowC(uint8_t* const ptr, const uint8_t* const alpha, + int width, int inverse) { + int x; + for (x = 0; x < width; ++x) { + const uint32_t a = alpha[x]; + if (a != 255) { + if (a == 0) { + ptr[x] = 0; + } else { + const uint32_t scale = GetScale(a, inverse); + ptr[x] = Mult(ptr[x], scale); + } + } + } +} + +#undef KINV_255 +#undef HALF +#undef MFIX + +void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse); +void (*WebPMultRow)(uint8_t* const ptr, const uint8_t* const alpha, + int width, int inverse); + +//------------------------------------------------------------------------------ +// Generic per-plane calls + +void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows, + int inverse) { + int n; + for (n = 0; n < num_rows; ++n) { + WebPMultARGBRow((uint32_t*)ptr, width, inverse); + ptr += stride; + } +} + +void WebPMultRows(uint8_t* ptr, int stride, + const uint8_t* alpha, int alpha_stride, + int width, int num_rows, int inverse) { + int n; + for (n = 0; n < num_rows; ++n) { + WebPMultRow(ptr, alpha, width, inverse); + ptr += stride; + alpha += alpha_stride; + } +} + +//------------------------------------------------------------------------------ +// Premultiplied modes + +// non dithered-modes + +// (x * a * 32897) >> 23 is bit-wise equivalent to (int)(x * a / 255.) +// for all 8bit x or a. For bit-wise equivalence to (int)(x * a / 255. + .5), +// one can use instead: (x * a * 65793 + (1 << 23)) >> 24 +#if 1 // (int)(x * a / 255.) +#define MULTIPLIER(a) ((a) * 32897U) +#define PREMULTIPLY(x, m) (((x) * (m)) >> 23) +#else // (int)(x * a / 255. + .5) +#define MULTIPLIER(a) ((a) * 65793U) +#define PREMULTIPLY(x, m) (((x) * (m) + (1U << 23)) >> 24) +#endif + +static void ApplyAlphaMultiply(uint8_t* rgba, int alpha_first, + int w, int h, int stride) { + while (h-- > 0) { + uint8_t* const rgb = rgba + (alpha_first ? 1 : 0); + const uint8_t* const alpha = rgba + (alpha_first ? 0 : 3); + int i; + for (i = 0; i < w; ++i) { + const uint32_t a = alpha[4 * i]; + if (a != 0xff) { + const uint32_t mult = MULTIPLIER(a); + rgb[4 * i + 0] = PREMULTIPLY(rgb[4 * i + 0], mult); + rgb[4 * i + 1] = PREMULTIPLY(rgb[4 * i + 1], mult); + rgb[4 * i + 2] = PREMULTIPLY(rgb[4 * i + 2], mult); + } + } + rgba += stride; + } +} +#undef MULTIPLIER +#undef PREMULTIPLY + +// rgbA4444 + +#define MULTIPLIER(a) ((a) * 0x1111) // 0x1111 ~= (1 << 16) / 15 + +static WEBP_INLINE uint8_t dither_hi(uint8_t x) { + return (x & 0xf0) | (x >> 4); +} + +static WEBP_INLINE uint8_t dither_lo(uint8_t x) { + return (x & 0x0f) | (x << 4); +} + +static WEBP_INLINE uint8_t multiply(uint8_t x, uint32_t m) { + return (x * m) >> 16; +} + +static WEBP_INLINE void ApplyAlphaMultiply4444(uint8_t* rgba4444, + int w, int h, int stride, + int rg_byte_pos /* 0 or 1 */) { + while (h-- > 0) { + int i; + for (i = 0; i < w; ++i) { + const uint32_t rg = rgba4444[2 * i + rg_byte_pos]; + const uint32_t ba = rgba4444[2 * i + (rg_byte_pos ^ 1)]; + const uint8_t a = ba & 0x0f; + const uint32_t mult = MULTIPLIER(a); + const uint8_t r = multiply(dither_hi(rg), mult); + const uint8_t g = multiply(dither_lo(rg), mult); + const uint8_t b = multiply(dither_hi(ba), mult); + rgba4444[2 * i + rg_byte_pos] = (r & 0xf0) | ((g >> 4) & 0x0f); + rgba4444[2 * i + (rg_byte_pos ^ 1)] = (b & 0xf0) | a; + } + rgba4444 += stride; + } +} +#undef MULTIPLIER + +static void ApplyAlphaMultiply_16b(uint8_t* rgba4444, + int w, int h, int stride) { +#ifdef WEBP_SWAP_16BIT_CSP + ApplyAlphaMultiply4444(rgba4444, w, h, stride, 1); +#else + ApplyAlphaMultiply4444(rgba4444, w, h, stride, 0); +#endif +} + +static int DispatchAlpha(const uint8_t* alpha, int alpha_stride, + int width, int height, + uint8_t* dst, int dst_stride) { + uint32_t alpha_mask = 0xff; + int i, j; + + for (j = 0; j < height; ++j) { + for (i = 0; i < width; ++i) { + const uint32_t alpha_value = alpha[i]; + dst[4 * i] = alpha_value; + alpha_mask &= alpha_value; + } + alpha += alpha_stride; + dst += dst_stride; + } + + return (alpha_mask != 0xff); +} + +static void DispatchAlphaToGreen(const uint8_t* alpha, int alpha_stride, + int width, int height, + uint32_t* dst, int dst_stride) { + int i, j; + for (j = 0; j < height; ++j) { + for (i = 0; i < width; ++i) { + dst[i] = alpha[i] << 8; // leave A/R/B channels zero'd. + } + alpha += alpha_stride; + dst += dst_stride; + } +} + +static int ExtractAlpha(const uint8_t* argb, int argb_stride, + int width, int height, + uint8_t* alpha, int alpha_stride) { + uint8_t alpha_mask = 0xff; + int i, j; + + for (j = 0; j < height; ++j) { + for (i = 0; i < width; ++i) { + const uint8_t alpha_value = argb[4 * i]; + alpha[i] = alpha_value; + alpha_mask &= alpha_value; + } + argb += argb_stride; + alpha += alpha_stride; + } + return (alpha_mask == 0xff); +} + +void (*WebPApplyAlphaMultiply)(uint8_t*, int, int, int, int); +void (*WebPApplyAlphaMultiply4444)(uint8_t*, int, int, int); +int (*WebPDispatchAlpha)(const uint8_t*, int, int, int, uint8_t*, int); +void (*WebPDispatchAlphaToGreen)(const uint8_t*, int, int, int, uint32_t*, int); +int (*WebPExtractAlpha)(const uint8_t*, int, int, int, uint8_t*, int); + +//------------------------------------------------------------------------------ +// Init function + +extern void WebPInitAlphaProcessingMIPSdspR2(void); +extern void WebPInitAlphaProcessingSSE2(void); + +static volatile VP8CPUInfo alpha_processing_last_cpuinfo_used = + (VP8CPUInfo)&alpha_processing_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { + if (alpha_processing_last_cpuinfo_used == VP8GetCPUInfo) return; + + WebPMultARGBRow = WebPMultARGBRowC; + WebPMultRow = WebPMultRowC; + WebPApplyAlphaMultiply = ApplyAlphaMultiply; + WebPApplyAlphaMultiply4444 = ApplyAlphaMultiply_16b; + WebPDispatchAlpha = DispatchAlpha; + WebPDispatchAlphaToGreen = DispatchAlphaToGreen; + WebPExtractAlpha = ExtractAlpha; + + // If defined, use CPUInfo() to overwrite some pointers with faster versions. + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + WebPInitAlphaProcessingSSE2(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + WebPInitAlphaProcessingMIPSdspR2(); + } +#endif + } + alpha_processing_last_cpuinfo_used = VP8GetCPUInfo; +} diff --git a/components/thorvg-main/src/loaders/webp/dsp/argb.cpp b/components/thorvg-main/src/loaders/webp/dsp/argb.cpp new file mode 100644 index 0000000..cc1f9a9 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/argb.cpp @@ -0,0 +1,68 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// ARGB making functions. +// +// Author: Djordje Pesut (djordje.pesut@imgtec.com) + +#include "./dsp.h" + +static WEBP_INLINE uint32_t MakeARGB32(int a, int r, int g, int b) { + return (((uint32_t)a << 24) | (r << 16) | (g << 8) | b); +} + +static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g, + const uint8_t* b, int len, uint32_t* out) { + int i; + for (i = 0; i < len; ++i) { + out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]); + } +} + +static void PackRGB(const uint8_t* r, const uint8_t* g, const uint8_t* b, + int len, int step, uint32_t* out) { + int i, offset = 0; + for (i = 0; i < len; ++i) { + out[i] = MakeARGB32(0xff, r[offset], g[offset], b[offset]); + offset += step; + } +} + +void (*VP8PackARGB)(const uint8_t*, const uint8_t*, const uint8_t*, + const uint8_t*, int, uint32_t*); +void (*VP8PackRGB)(const uint8_t*, const uint8_t*, const uint8_t*, + int, int, uint32_t*); + +extern void VP8EncDspARGBInitMIPSdspR2(void); +extern void VP8EncDspARGBInitSSE2(void); + +static volatile VP8CPUInfo argb_last_cpuinfo_used = + (VP8CPUInfo)&argb_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) { + if (argb_last_cpuinfo_used == VP8GetCPUInfo) return; + + VP8PackARGB = PackARGB; + VP8PackRGB = PackRGB; + + // If defined, use CPUInfo() to overwrite some pointers with faster versions. + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + VP8EncDspARGBInitSSE2(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + VP8EncDspARGBInitMIPSdspR2(); + } +#endif + } + argb_last_cpuinfo_used = VP8GetCPUInfo; +} diff --git a/components/thorvg-main/src/loaders/webp/dsp/cpu.cpp b/components/thorvg-main/src/loaders/webp/dsp/cpu.cpp new file mode 100644 index 0000000..202d312 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/cpu.cpp @@ -0,0 +1,120 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// CPU detection +// +// Author: Christian Duvivier (cduvivier@google.com) + +#include "./dsp.h" + + +//------------------------------------------------------------------------------ +// SSE2 detection. +// + +// apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC. +#if (defined(__pic__) || defined(__PIC__)) && defined(__i386__) +static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) { + __asm__ volatile ( + "mov %%ebx, %%edi\n" + "cpuid\n" + "xchg %%edi, %%ebx\n" + : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) + : "a"(info_type), "c"(0)); +} +#elif defined(__i386__) || defined(__x86_64__) +static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) { + __asm__ volatile ( + "cpuid\n" + : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) + : "a"(info_type), "c"(0)); +} +#elif (defined(_M_X64) || defined(_M_IX86)) && \ + defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 // >= VS2008 SP1 +#include +#define GetCPUInfo(info, type) __cpuidex(info, type, 0) // set ecx=0 +#elif defined(WEBP_MSC_SSE2) +#define GetCPUInfo __cpuid +#endif + +// NaCl has no support for xgetbv or the raw opcode. +#if !defined(__native_client__) && (defined(__i386__) || defined(__x86_64__)) +static WEBP_INLINE uint64_t xgetbv(void) { + const uint32_t ecx = 0; + uint32_t eax, edx; + // Use the raw opcode for xgetbv for compatibility with older toolchains. + __asm__ volatile ( + ".byte 0x0f, 0x01, 0xd0\n" + : "=a"(eax), "=d"(edx) : "c" (ecx)); + return ((uint64_t)edx << 32) | eax; +} +#elif (defined(_M_X64) || defined(_M_IX86)) && \ + defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 160040219 // >= VS2010 SP1 +#include +#define xgetbv() _xgetbv(0) +#elif defined(_MSC_VER) && defined(_M_IX86) +static WEBP_INLINE uint64_t xgetbv(void) { + uint32_t eax_, edx_; + __asm { + xor ecx, ecx // ecx = 0 + // Use the raw opcode for xgetbv for compatibility with older toolchains. + __asm _emit 0x0f __asm _emit 0x01 __asm _emit 0xd0 + mov eax_, eax + mov edx_, edx + } + return ((uint64_t)edx_ << 32) | eax_; +} +#else +#define xgetbv() 0U // no AVX for older x64 or unrecognized toolchains. +#endif + +#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2) +static int x86CPUInfo(CPUFeature feature) { + int cpu_info[4]; + GetCPUInfo(cpu_info, 1); + if (feature == kSSE2) { + return 0 != (cpu_info[3] & 0x04000000); + } + + return 0; +} +VP8CPUInfo VP8GetCPUInfo = x86CPUInfo; +#elif defined(WEBP_ANDROID_NEON) // NB: needs to be before generic NEON test. +static int AndroidCPUInfo(CPUFeature feature) { + const AndroidCpuFamily cpu_family = android_getCpuFamily(); + const uint64_t cpu_features = android_getCpuFeatures(); + if (feature == kNEON) { + return (cpu_family == ANDROID_CPU_FAMILY_ARM && + 0 != (cpu_features & ANDROID_CPU_ARM_FEATURE_NEON)); + } + return 0; +} +VP8CPUInfo VP8GetCPUInfo = AndroidCPUInfo; +#elif defined(WEBP_USE_NEON) +// define a dummy function to enable turning off NEON at runtime by setting +// VP8DecGetCPUInfo = NULL +static int armCPUInfo(CPUFeature feature) { + (void)feature; + return 1; +} +VP8CPUInfo VP8GetCPUInfo = armCPUInfo; +#elif defined(WEBP_USE_MIPS32) || defined(WEBP_USE_MIPS_DSP_R2) +static int mipsCPUInfo(CPUFeature feature) { + if ((feature == kMIPS32) || (feature == kMIPSdspR2)) { + return 1; + } else { + return 0; + } + +} +VP8CPUInfo VP8GetCPUInfo = mipsCPUInfo; +#else +VP8CPUInfo VP8GetCPUInfo = NULL; +#endif + diff --git a/components/thorvg-main/src/loaders/webp/dsp/dec.cpp b/components/thorvg-main/src/loaders/webp/dsp/dec.cpp new file mode 100644 index 0000000..adcc009 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/dec.cpp @@ -0,0 +1,767 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Speed-critical decoding functions, default plain-C implementations. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "./dsp.h" +#include "../dec/vp8i.h" + +//------------------------------------------------------------------------------ + +static WEBP_INLINE uint8_t clip_8b(int v) { + return (!(v & ~0xff)) ? v : (v < 0) ? 0 : 255; +} + +//------------------------------------------------------------------------------ +// Transforms (Paragraph 14.4) + +#define STORE(x, y, v) \ + dst[x + y * BPS] = clip_8b(dst[x + y * BPS] + ((v) >> 3)) + +#define STORE2(y, dc, d, c) do { \ + const int DC = (dc); \ + STORE(0, y, DC + (d)); \ + STORE(1, y, DC + (c)); \ + STORE(2, y, DC - (c)); \ + STORE(3, y, DC - (d)); \ +} while (0) + +static const int kC1 = 20091 + (1 << 16); +static const int kC2 = 35468; +#define MUL(a, b) (((a) * (b)) >> 16) + +static void TransformOne(const int16_t* in, uint8_t* dst) { + int C[4 * 4], *tmp; + int i; + tmp = C; + for (i = 0; i < 4; ++i) { // vertical pass + const int a = in[0] + in[8]; // [-4096, 4094] + const int b = in[0] - in[8]; // [-4095, 4095] + const int c = MUL(in[4], kC2) - MUL(in[12], kC1); // [-3783, 3783] + const int d = MUL(in[4], kC1) + MUL(in[12], kC2); // [-3785, 3781] + tmp[0] = a + d; // [-7881, 7875] + tmp[1] = b + c; // [-7878, 7878] + tmp[2] = b - c; // [-7878, 7878] + tmp[3] = a - d; // [-7877, 7879] + tmp += 4; + in++; + } + // Each pass is expanding the dynamic range by ~3.85 (upper bound). + // The exact value is (2. + (kC1 + kC2) / 65536). + // After the second pass, maximum interval is [-3794, 3794], assuming + // an input in [-2048, 2047] interval. We then need to add a dst value + // in the [0, 255] range. + // In the worst case scenario, the input to clip_8b() can be as large as + // [-60713, 60968]. + tmp = C; + for (i = 0; i < 4; ++i) { // horizontal pass + const int dc = tmp[0] + 4; + const int a = dc + tmp[8]; + const int b = dc - tmp[8]; + const int c = MUL(tmp[4], kC2) - MUL(tmp[12], kC1); + const int d = MUL(tmp[4], kC1) + MUL(tmp[12], kC2); + STORE(0, 0, a + d); + STORE(1, 0, b + c); + STORE(2, 0, b - c); + STORE(3, 0, a - d); + tmp++; + dst += BPS; + } +} + +// Simplified transform when only in[0], in[1] and in[4] are non-zero +static void TransformAC3(const int16_t* in, uint8_t* dst) { + const int a = in[0] + 4; + const int c4 = MUL(in[4], kC2); + const int d4 = MUL(in[4], kC1); + const int c1 = MUL(in[1], kC2); + const int d1 = MUL(in[1], kC1); + STORE2(0, a + d4, d1, c1); + STORE2(1, a + c4, d1, c1); + STORE2(2, a - c4, d1, c1); + STORE2(3, a - d4, d1, c1); +} +#undef MUL +#undef STORE2 + +static void TransformTwo(const int16_t* in, uint8_t* dst, int do_two) { + TransformOne(in, dst); + if (do_two) { + TransformOne(in + 16, dst + 4); + } +} + +static void TransformUV(const int16_t* in, uint8_t* dst) { + VP8Transform(in + 0 * 16, dst, 1); + VP8Transform(in + 2 * 16, dst + 4 * BPS, 1); +} + +static void TransformDC(const int16_t* in, uint8_t* dst) { + const int DC = in[0] + 4; + int i, j; + for (j = 0; j < 4; ++j) { + for (i = 0; i < 4; ++i) { + STORE(i, j, DC); + } + } +} + +static void TransformDCUV(const int16_t* in, uint8_t* dst) { + if (in[0 * 16]) VP8TransformDC(in + 0 * 16, dst); + if (in[1 * 16]) VP8TransformDC(in + 1 * 16, dst + 4); + if (in[2 * 16]) VP8TransformDC(in + 2 * 16, dst + 4 * BPS); + if (in[3 * 16]) VP8TransformDC(in + 3 * 16, dst + 4 * BPS + 4); +} + +#undef STORE + +//------------------------------------------------------------------------------ +// Paragraph 14.3 + +static void TransformWHT(const int16_t* in, int16_t* out) { + int tmp[16]; + int i; + for (i = 0; i < 4; ++i) { + const int a0 = in[0 + i] + in[12 + i]; + const int a1 = in[4 + i] + in[ 8 + i]; + const int a2 = in[4 + i] - in[ 8 + i]; + const int a3 = in[0 + i] - in[12 + i]; + tmp[0 + i] = a0 + a1; + tmp[8 + i] = a0 - a1; + tmp[4 + i] = a3 + a2; + tmp[12 + i] = a3 - a2; + } + for (i = 0; i < 4; ++i) { + const int dc = tmp[0 + i * 4] + 3; // w/ rounder + const int a0 = dc + tmp[3 + i * 4]; + const int a1 = tmp[1 + i * 4] + tmp[2 + i * 4]; + const int a2 = tmp[1 + i * 4] - tmp[2 + i * 4]; + const int a3 = dc - tmp[3 + i * 4]; + out[ 0] = (a0 + a1) >> 3; + out[16] = (a3 + a2) >> 3; + out[32] = (a0 - a1) >> 3; + out[48] = (a3 - a2) >> 3; + out += 64; + } +} + +void (*VP8TransformWHT)(const int16_t* in, int16_t* out); + +//------------------------------------------------------------------------------ +// Intra predictions + +#define DST(x, y) dst[(x) + (y) * BPS] + +static WEBP_INLINE void TrueMotion(uint8_t* dst, int size) { + const uint8_t* top = dst - BPS; + const uint8_t* const clip0 = VP8kclip1 - top[-1]; + int y; + for (y = 0; y < size; ++y) { + const uint8_t* const clip = clip0 + dst[-1]; + int x; + for (x = 0; x < size; ++x) { + dst[x] = clip[top[x]]; + } + dst += BPS; + } +} +static void TM4(uint8_t* dst) { TrueMotion(dst, 4); } +static void TM8uv(uint8_t* dst) { TrueMotion(dst, 8); } +static void TM16(uint8_t* dst) { TrueMotion(dst, 16); } + +//------------------------------------------------------------------------------ +// 16x16 + +static void VE16(uint8_t* dst) { // vertical + int j; + for (j = 0; j < 16; ++j) { + memcpy(dst + j * BPS, dst - BPS, 16); + } +} + +static void HE16(uint8_t* dst) { // horizontal + int j; + for (j = 16; j > 0; --j) { + memset(dst, dst[-1], 16); + dst += BPS; + } +} + +static WEBP_INLINE void Put16(int v, uint8_t* dst) { + int j; + for (j = 0; j < 16; ++j) { + memset(dst + j * BPS, v, 16); + } +} + +static void DC16(uint8_t* dst) { // DC + int DC = 16; + int j; + for (j = 0; j < 16; ++j) { + DC += dst[-1 + j * BPS] + dst[j - BPS]; + } + Put16(DC >> 5, dst); +} + +static void DC16NoTop(uint8_t* dst) { // DC with top samples not available + int DC = 8; + int j; + for (j = 0; j < 16; ++j) { + DC += dst[-1 + j * BPS]; + } + Put16(DC >> 4, dst); +} + +static void DC16NoLeft(uint8_t* dst) { // DC with left samples not available + int DC = 8; + int i; + for (i = 0; i < 16; ++i) { + DC += dst[i - BPS]; + } + Put16(DC >> 4, dst); +} + +static void DC16NoTopLeft(uint8_t* dst) { // DC with no top and left samples + Put16(0x80, dst); +} + +VP8PredFunc VP8PredLuma16[NUM_B_DC_MODES]; + +//------------------------------------------------------------------------------ +// 4x4 + +#define AVG3(a, b, c) ((((uint32_t)a) + 2 * (b) + (c) + 2) >> 2) +#define AVG2(a, b) (((a) + (b) + 1) >> 1) + +static void VE4(uint8_t* dst) { // vertical + if (!dst) return; + const uint8_t* top = dst - BPS; + const uint8_t vals[4] = { + (uint8_t)AVG3(top[-1], top[0], top[1]), + (uint8_t)AVG3(top[ 0], top[1], top[2]), + (uint8_t)AVG3(top[ 1], top[2], top[3]), + (uint8_t)AVG3(top[ 2], top[3], top[4]) + }; + int i; + for (i = 0; i < 4; ++i) { + memcpy(dst + i * BPS, vals, sizeof(vals)); + } +} + +static void HE4(uint8_t* dst) { // horizontal + const int A = dst[-1 - BPS]; + const int B = dst[-1]; + const int C = dst[-1 + BPS]; + const int D = dst[-1 + 2 * BPS]; + const int E = dst[-1 + 3 * BPS]; + *(uint32_t*)(dst + 0 * BPS) = 0x01010101U * AVG3(A, B, C); + *(uint32_t*)(dst + 1 * BPS) = 0x01010101U * AVG3(B, C, D); + *(uint32_t*)(dst + 2 * BPS) = 0x01010101U * AVG3(C, D, E); + *(uint32_t*)(dst + 3 * BPS) = 0x01010101U * AVG3(D, E, E); +} + +static void DC4(uint8_t* dst) { // DC + uint32_t dc = 4; + int i; + for (i = 0; i < 4; ++i) dc += dst[i - BPS] + dst[-1 + i * BPS]; + dc >>= 3; + for (i = 0; i < 4; ++i) memset(dst + i * BPS, dc, 4); +} + +static void RD4(uint8_t* dst) { // Down-right + const int I = dst[-1 + 0 * BPS]; + const int J = dst[-1 + 1 * BPS]; + const int K = dst[-1 + 2 * BPS]; + const int L = dst[-1 + 3 * BPS]; + const int X = dst[-1 - BPS]; + const int A = dst[0 - BPS]; + const int B = dst[1 - BPS]; + const int C = dst[2 - BPS]; + const int D = dst[3 - BPS]; + DST(0, 3) = AVG3(J, K, L); + DST(1, 3) = DST(0, 2) = AVG3(I, J, K); + DST(2, 3) = DST(1, 2) = DST(0, 1) = AVG3(X, I, J); + DST(3, 3) = DST(2, 2) = DST(1, 1) = DST(0, 0) = AVG3(A, X, I); + DST(3, 2) = DST(2, 1) = DST(1, 0) = AVG3(B, A, X); + DST(3, 1) = DST(2, 0) = AVG3(C, B, A); + DST(3, 0) = AVG3(D, C, B); +} + +static void LD4(uint8_t* dst) { // Down-Left + const int A = dst[0 - BPS]; + const int B = dst[1 - BPS]; + const int C = dst[2 - BPS]; + const int D = dst[3 - BPS]; + const int E = dst[4 - BPS]; + const int F = dst[5 - BPS]; + const int G = dst[6 - BPS]; + const int H = dst[7 - BPS]; + DST(0, 0) = AVG3(A, B, C); + DST(1, 0) = DST(0, 1) = AVG3(B, C, D); + DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E); + DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F); + DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G); + DST(3, 2) = DST(2, 3) = AVG3(F, G, H); + DST(3, 3) = AVG3(G, H, H); +} + +static void VR4(uint8_t* dst) { // Vertical-Right + const int I = dst[-1 + 0 * BPS]; + const int J = dst[-1 + 1 * BPS]; + const int K = dst[-1 + 2 * BPS]; + const int X = dst[-1 - BPS]; + const int A = dst[0 - BPS]; + const int B = dst[1 - BPS]; + const int C = dst[2 - BPS]; + const int D = dst[3 - BPS]; + DST(0, 0) = DST(1, 2) = AVG2(X, A); + DST(1, 0) = DST(2, 2) = AVG2(A, B); + DST(2, 0) = DST(3, 2) = AVG2(B, C); + DST(3, 0) = AVG2(C, D); + + DST(0, 3) = AVG3(K, J, I); + DST(0, 2) = AVG3(J, I, X); + DST(0, 1) = DST(1, 3) = AVG3(I, X, A); + DST(1, 1) = DST(2, 3) = AVG3(X, A, B); + DST(2, 1) = DST(3, 3) = AVG3(A, B, C); + DST(3, 1) = AVG3(B, C, D); +} + +static void VL4(uint8_t* dst) { // Vertical-Left + const int A = dst[0 - BPS]; + const int B = dst[1 - BPS]; + const int C = dst[2 - BPS]; + const int D = dst[3 - BPS]; + const int E = dst[4 - BPS]; + const int F = dst[5 - BPS]; + const int G = dst[6 - BPS]; + const int H = dst[7 - BPS]; + DST(0, 0) = AVG2(A, B); + DST(1, 0) = DST(0, 2) = AVG2(B, C); + DST(2, 0) = DST(1, 2) = AVG2(C, D); + DST(3, 0) = DST(2, 2) = AVG2(D, E); + + DST(0, 1) = AVG3(A, B, C); + DST(1, 1) = DST(0, 3) = AVG3(B, C, D); + DST(2, 1) = DST(1, 3) = AVG3(C, D, E); + DST(3, 1) = DST(2, 3) = AVG3(D, E, F); + DST(3, 2) = AVG3(E, F, G); + DST(3, 3) = AVG3(F, G, H); +} + +static void HU4(uint8_t* dst) { // Horizontal-Up + const int I = dst[-1 + 0 * BPS]; + const int J = dst[-1 + 1 * BPS]; + const int K = dst[-1 + 2 * BPS]; + const int L = dst[-1 + 3 * BPS]; + DST(0, 0) = AVG2(I, J); + DST(2, 0) = DST(0, 1) = AVG2(J, K); + DST(2, 1) = DST(0, 2) = AVG2(K, L); + DST(1, 0) = AVG3(I, J, K); + DST(3, 0) = DST(1, 1) = AVG3(J, K, L); + DST(3, 1) = DST(1, 2) = AVG3(K, L, L); + DST(3, 2) = DST(2, 2) = + DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L; +} + +static void HD4(uint8_t* dst) { // Horizontal-Down + const int I = dst[-1 + 0 * BPS]; + const int J = dst[-1 + 1 * BPS]; + const int K = dst[-1 + 2 * BPS]; + const int L = dst[-1 + 3 * BPS]; + const int X = dst[-1 - BPS]; + const int A = dst[0 - BPS]; + const int B = dst[1 - BPS]; + const int C = dst[2 - BPS]; + + DST(0, 0) = DST(2, 1) = AVG2(I, X); + DST(0, 1) = DST(2, 2) = AVG2(J, I); + DST(0, 2) = DST(2, 3) = AVG2(K, J); + DST(0, 3) = AVG2(L, K); + + DST(3, 0) = AVG3(A, B, C); + DST(2, 0) = AVG3(X, A, B); + DST(1, 0) = DST(3, 1) = AVG3(I, X, A); + DST(1, 1) = DST(3, 2) = AVG3(J, I, X); + DST(1, 2) = DST(3, 3) = AVG3(K, J, I); + DST(1, 3) = AVG3(L, K, J); +} + +#undef DST +#undef AVG3 +#undef AVG2 + +VP8PredFunc VP8PredLuma4[NUM_BMODES]; + +//------------------------------------------------------------------------------ +// Chroma + +static void VE8uv(uint8_t* dst) { // vertical + int j; + for (j = 0; j < 8; ++j) { + memcpy(dst + j * BPS, dst - BPS, 8); + } +} + +static void HE8uv(uint8_t* dst) { // horizontal + int j; + for (j = 0; j < 8; ++j) { + memset(dst, dst[-1], 8); + dst += BPS; + } +} + +// helper for chroma-DC predictions +static WEBP_INLINE void Put8x8uv(uint8_t value, uint8_t* dst) { + int j; + for (j = 0; j < 8; ++j) { + memset(dst + j * BPS, value, 8); + } +} + +static void DC8uv(uint8_t* dst) { // DC + int dc0 = 8; + int i; + for (i = 0; i < 8; ++i) { + dc0 += dst[i - BPS] + dst[-1 + i * BPS]; + } + Put8x8uv(dc0 >> 4, dst); +} + +static void DC8uvNoLeft(uint8_t* dst) { // DC with no left samples + int dc0 = 4; + int i; + for (i = 0; i < 8; ++i) { + dc0 += dst[i - BPS]; + } + Put8x8uv(dc0 >> 3, dst); +} + +static void DC8uvNoTop(uint8_t* dst) { // DC with no top samples + int dc0 = 4; + int i; + for (i = 0; i < 8; ++i) { + dc0 += dst[-1 + i * BPS]; + } + Put8x8uv(dc0 >> 3, dst); +} + +static void DC8uvNoTopLeft(uint8_t* dst) { // DC with nothing + Put8x8uv(0x80, dst); +} + +VP8PredFunc VP8PredChroma8[NUM_B_DC_MODES]; + +//------------------------------------------------------------------------------ +// Edge filtering functions + +// 4 pixels in, 2 pixels out +static WEBP_INLINE void do_filter2(uint8_t* p, int step) { + const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; + const int a = 3 * (q0 - p0) + VP8ksclip1[p1 - q1]; // in [-893,892] + const int a1 = VP8ksclip2[(a + 4) >> 3]; // in [-16,15] + const int a2 = VP8ksclip2[(a + 3) >> 3]; + p[-step] = VP8kclip1[p0 + a2]; + p[ 0] = VP8kclip1[q0 - a1]; +} + +// 4 pixels in, 4 pixels out +static WEBP_INLINE void do_filter4(uint8_t* p, int step) { + const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; + const int a = 3 * (q0 - p0); + const int a1 = VP8ksclip2[(a + 4) >> 3]; + const int a2 = VP8ksclip2[(a + 3) >> 3]; + const int a3 = (a1 + 1) >> 1; + p[-2*step] = VP8kclip1[p1 + a3]; + p[- step] = VP8kclip1[p0 + a2]; + p[ 0] = VP8kclip1[q0 - a1]; + p[ step] = VP8kclip1[q1 - a3]; +} + +// 6 pixels in, 6 pixels out +static WEBP_INLINE void do_filter6(uint8_t* p, int step) { + const int p2 = p[-3*step], p1 = p[-2*step], p0 = p[-step]; + const int q0 = p[0], q1 = p[step], q2 = p[2*step]; + const int a = VP8ksclip1[3 * (q0 - p0) + VP8ksclip1[p1 - q1]]; + // a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9] + const int a1 = (27 * a + 63) >> 7; // eq. to ((3 * a + 7) * 9) >> 7 + const int a2 = (18 * a + 63) >> 7; // eq. to ((2 * a + 7) * 9) >> 7 + const int a3 = (9 * a + 63) >> 7; // eq. to ((1 * a + 7) * 9) >> 7 + p[-3*step] = VP8kclip1[p2 + a3]; + p[-2*step] = VP8kclip1[p1 + a2]; + p[- step] = VP8kclip1[p0 + a1]; + p[ 0] = VP8kclip1[q0 - a1]; + p[ step] = VP8kclip1[q1 - a2]; + p[ 2*step] = VP8kclip1[q2 - a3]; +} + +static WEBP_INLINE int hev(const uint8_t* p, int step, int thresh) { + const int p1 = p[-2*step], p0 = p[-step], q0 = p[0], q1 = p[step]; + return (VP8kabs0[p1 - p0] > thresh) || (VP8kabs0[q1 - q0] > thresh); +} + +static WEBP_INLINE int needs_filter(const uint8_t* p, int step, int t) { + const int p1 = p[-2 * step], p0 = p[-step], q0 = p[0], q1 = p[step]; + return ((4 * VP8kabs0[p0 - q0] + VP8kabs0[p1 - q1]) <= t); +} + +static WEBP_INLINE int needs_filter2(const uint8_t* p, + int step, int t, int it) { + const int p3 = p[-4 * step], p2 = p[-3 * step], p1 = p[-2 * step]; + const int p0 = p[-step], q0 = p[0]; + const int q1 = p[step], q2 = p[2 * step], q3 = p[3 * step]; + if ((4 * VP8kabs0[p0 - q0] + VP8kabs0[p1 - q1]) > t) return 0; + return VP8kabs0[p3 - p2] <= it && VP8kabs0[p2 - p1] <= it && + VP8kabs0[p1 - p0] <= it && VP8kabs0[q3 - q2] <= it && + VP8kabs0[q2 - q1] <= it && VP8kabs0[q1 - q0] <= it; +} + +//------------------------------------------------------------------------------ +// Simple In-loop filtering (Paragraph 15.2) + +static void SimpleVFilter16(uint8_t* p, int stride, int thresh) { + int i; + const int thresh2 = 2 * thresh + 1; + for (i = 0; i < 16; ++i) { + if (needs_filter(p + i, stride, thresh2)) { + do_filter2(p + i, stride); + } + } +} + +static void SimpleHFilter16(uint8_t* p, int stride, int thresh) { + int i; + const int thresh2 = 2 * thresh + 1; + for (i = 0; i < 16; ++i) { + if (needs_filter(p + i * stride, 1, thresh2)) { + do_filter2(p + i * stride, 1); + } + } +} + +static void SimpleVFilter16i(uint8_t* p, int stride, int thresh) { + int k; + for (k = 3; k > 0; --k) { + p += 4 * stride; + SimpleVFilter16(p, stride, thresh); + } +} + +static void SimpleHFilter16i(uint8_t* p, int stride, int thresh) { + int k; + for (k = 3; k > 0; --k) { + p += 4; + SimpleHFilter16(p, stride, thresh); + } +} + +//------------------------------------------------------------------------------ +// Complex In-loop filtering (Paragraph 15.3) + +static WEBP_INLINE void FilterLoop26(uint8_t* p, + int hstride, int vstride, int size, + int thresh, int ithresh, int hev_thresh) { + const int thresh2 = 2 * thresh + 1; + while (size-- > 0) { + if (needs_filter2(p, hstride, thresh2, ithresh)) { + if (hev(p, hstride, hev_thresh)) { + do_filter2(p, hstride); + } else { + do_filter6(p, hstride); + } + } + p += vstride; + } +} + +static WEBP_INLINE void FilterLoop24(uint8_t* p, + int hstride, int vstride, int size, + int thresh, int ithresh, int hev_thresh) { + const int thresh2 = 2 * thresh + 1; + while (size-- > 0) { + if (needs_filter2(p, hstride, thresh2, ithresh)) { + if (hev(p, hstride, hev_thresh)) { + do_filter2(p, hstride); + } else { + do_filter4(p, hstride); + } + } + p += vstride; + } +} + +// on macroblock edges +static void VFilter16(uint8_t* p, int stride, + int thresh, int ithresh, int hev_thresh) { + FilterLoop26(p, stride, 1, 16, thresh, ithresh, hev_thresh); +} + +static void HFilter16(uint8_t* p, int stride, + int thresh, int ithresh, int hev_thresh) { + FilterLoop26(p, 1, stride, 16, thresh, ithresh, hev_thresh); +} + +// on three inner edges +static void VFilter16i(uint8_t* p, int stride, + int thresh, int ithresh, int hev_thresh) { + int k; + for (k = 3; k > 0; --k) { + p += 4 * stride; + FilterLoop24(p, stride, 1, 16, thresh, ithresh, hev_thresh); + } +} + +static void HFilter16i(uint8_t* p, int stride, + int thresh, int ithresh, int hev_thresh) { + int k; + for (k = 3; k > 0; --k) { + p += 4; + FilterLoop24(p, 1, stride, 16, thresh, ithresh, hev_thresh); + } +} + +// 8-pixels wide variant, for chroma filtering +static void VFilter8(uint8_t* u, uint8_t* v, int stride, + int thresh, int ithresh, int hev_thresh) { + FilterLoop26(u, stride, 1, 8, thresh, ithresh, hev_thresh); + FilterLoop26(v, stride, 1, 8, thresh, ithresh, hev_thresh); +} + +static void HFilter8(uint8_t* u, uint8_t* v, int stride, + int thresh, int ithresh, int hev_thresh) { + FilterLoop26(u, 1, stride, 8, thresh, ithresh, hev_thresh); + FilterLoop26(v, 1, stride, 8, thresh, ithresh, hev_thresh); +} + +static void VFilter8i(uint8_t* u, uint8_t* v, int stride, + int thresh, int ithresh, int hev_thresh) { + FilterLoop24(u + 4 * stride, stride, 1, 8, thresh, ithresh, hev_thresh); + FilterLoop24(v + 4 * stride, stride, 1, 8, thresh, ithresh, hev_thresh); +} + +static void HFilter8i(uint8_t* u, uint8_t* v, int stride, + int thresh, int ithresh, int hev_thresh) { + FilterLoop24(u + 4, 1, stride, 8, thresh, ithresh, hev_thresh); + FilterLoop24(v + 4, 1, stride, 8, thresh, ithresh, hev_thresh); +} + +//------------------------------------------------------------------------------ + +VP8DecIdct2 VP8Transform; +VP8DecIdct VP8TransformAC3; +VP8DecIdct VP8TransformUV; +VP8DecIdct VP8TransformDC; +VP8DecIdct VP8TransformDCUV; + +VP8LumaFilterFunc VP8VFilter16; +VP8LumaFilterFunc VP8HFilter16; +VP8ChromaFilterFunc VP8VFilter8; +VP8ChromaFilterFunc VP8HFilter8; +VP8LumaFilterFunc VP8VFilter16i; +VP8LumaFilterFunc VP8HFilter16i; +VP8ChromaFilterFunc VP8VFilter8i; +VP8ChromaFilterFunc VP8HFilter8i; +VP8SimpleFilterFunc VP8SimpleVFilter16; +VP8SimpleFilterFunc VP8SimpleHFilter16; +VP8SimpleFilterFunc VP8SimpleVFilter16i; +VP8SimpleFilterFunc VP8SimpleHFilter16i; + +extern void VP8DspInitSSE2(void); +extern void VP8DspInitSSE41(void); +extern void VP8DspInitNEON(void); +extern void VP8DspInitMIPS32(void); +extern void VP8DspInitMIPSdspR2(void); + +static volatile VP8CPUInfo dec_last_cpuinfo_used = + (VP8CPUInfo)&dec_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) { + if (dec_last_cpuinfo_used == VP8GetCPUInfo) return; + + VP8InitClipTables(); + + VP8TransformWHT = TransformWHT; + VP8Transform = TransformTwo; + VP8TransformUV = TransformUV; + VP8TransformDC = TransformDC; + VP8TransformDCUV = TransformDCUV; + VP8TransformAC3 = TransformAC3; + + VP8VFilter16 = VFilter16; + VP8HFilter16 = HFilter16; + VP8VFilter8 = VFilter8; + VP8HFilter8 = HFilter8; + VP8VFilter16i = VFilter16i; + VP8HFilter16i = HFilter16i; + VP8VFilter8i = VFilter8i; + VP8HFilter8i = HFilter8i; + VP8SimpleVFilter16 = SimpleVFilter16; + VP8SimpleHFilter16 = SimpleHFilter16; + VP8SimpleVFilter16i = SimpleVFilter16i; + VP8SimpleHFilter16i = SimpleHFilter16i; + + VP8PredLuma4[0] = DC4; + VP8PredLuma4[1] = TM4; + VP8PredLuma4[2] = VE4; + VP8PredLuma4[3] = HE4; + VP8PredLuma4[4] = RD4; + VP8PredLuma4[5] = VR4; + VP8PredLuma4[6] = LD4; + VP8PredLuma4[7] = VL4; + VP8PredLuma4[8] = HD4; + VP8PredLuma4[9] = HU4; + + VP8PredLuma16[0] = DC16; + VP8PredLuma16[1] = TM16; + VP8PredLuma16[2] = VE16; + VP8PredLuma16[3] = HE16; + VP8PredLuma16[4] = DC16NoTop; + VP8PredLuma16[5] = DC16NoLeft; + VP8PredLuma16[6] = DC16NoTopLeft; + + VP8PredChroma8[0] = DC8uv; + VP8PredChroma8[1] = TM8uv; + VP8PredChroma8[2] = VE8uv; + VP8PredChroma8[3] = HE8uv; + VP8PredChroma8[4] = DC8uvNoTop; + VP8PredChroma8[5] = DC8uvNoLeft; + VP8PredChroma8[6] = DC8uvNoTopLeft; + + // If defined, use CPUInfo() to overwrite some pointers with faster versions. + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + VP8DspInitSSE2(); +#if defined(WEBP_USE_SSE41) + if (VP8GetCPUInfo(kSSE4_1)) { + VP8DspInitSSE41(); + } +#endif + } +#endif +#if defined(WEBP_USE_NEON) + if (VP8GetCPUInfo(kNEON)) { + VP8DspInitNEON(); + } +#endif +#if defined(WEBP_USE_MIPS32) + if (VP8GetCPUInfo(kMIPS32)) { + VP8DspInitMIPS32(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + VP8DspInitMIPSdspR2(); + } +#endif + } + dec_last_cpuinfo_used = VP8GetCPUInfo; +} diff --git a/components/thorvg-main/src/loaders/webp/dsp/dec_clip_tables.cpp b/components/thorvg-main/src/loaders/webp/dsp/dec_clip_tables.cpp new file mode 100644 index 0000000..edfffd0 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/dec_clip_tables.cpp @@ -0,0 +1,366 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Clipping tables for filtering +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "./dsp.h" + +//#define USE_STATIC_TABLES // undefine to have run-time table initialization + +#ifdef USE_STATIC_TABLES + +static const uint8_t abs0[255 + 255 + 1] = { + (uint8_t)0xff, (uint8_t)0xfe, (uint8_t)0xfd, (uint8_t)0xfc, (uint8_t)0xfb, (uint8_t)0xfa, (uint8_t)0xf9, (uint8_t)0xf8, (uint8_t)0xf7, (uint8_t)0xf6, (uint8_t)0xf5, (uint8_t)0xf4, + (uint8_t)0xf3, (uint8_t)0xf2, (uint8_t)0xf1, (uint8_t)0xf0, (uint8_t)0xef, (uint8_t)0xee, (uint8_t)0xed, (uint8_t)0xec, (uint8_t)0xeb, (uint8_t)0xea, (uint8_t)0xe9, (uint8_t)0xe8, + (uint8_t)0xe7, (uint8_t)0xe6, (uint8_t)0xe5, (uint8_t)0xe4, (uint8_t)0xe3, (uint8_t)0xe2, (uint8_t)0xe1, (uint8_t)0xe0, (uint8_t)0xdf, (uint8_t)0xde, (uint8_t)0xdd, (uint8_t)0xdc, + (uint8_t)0xdb, (uint8_t)0xda, (uint8_t)0xd9, (uint8_t)0xd8, (uint8_t)0xd7, (uint8_t)0xd6, (uint8_t)0xd5, (uint8_t)0xd4, (uint8_t)0xd3, (uint8_t)0xd2, (uint8_t)0xd1, (uint8_t)0xd0, + (uint8_t)0xcf, (uint8_t)0xce, (uint8_t)0xcd, (uint8_t)0xcc, (uint8_t)0xcb, (uint8_t)0xca, (uint8_t)0xc9, (uint8_t)0xc8, (uint8_t)0xc7, (uint8_t)0xc6, (uint8_t)0xc5, (uint8_t)0xc4, + (uint8_t)0xc3, (uint8_t)0xc2, (uint8_t)0xc1, (uint8_t)0xc0, (uint8_t)0xbf, (uint8_t)0xbe, (uint8_t)0xbd, (uint8_t)0xbc, (uint8_t)0xbb, (uint8_t)0xba, (uint8_t)0xb9, (uint8_t)0xb8, + (uint8_t)0xb7, (uint8_t)0xb6, (uint8_t)0xb5, (uint8_t)0xb4, (uint8_t)0xb3, (uint8_t)0xb2, (uint8_t)0xb1, (uint8_t)0xb0, (uint8_t)0xaf, (uint8_t)0xae, (uint8_t)0xad, (uint8_t)0xac, + (uint8_t)0xab, (uint8_t)0xaa, (uint8_t)0xa9, (uint8_t)0xa8, (uint8_t)0xa7, (uint8_t)0xa6, (uint8_t)0xa5, (uint8_t)0xa4, (uint8_t)0xa3, (uint8_t)0xa2, (uint8_t)0xa1, (uint8_t)0xa0, + (uint8_t)0x9f, (uint8_t)0x9e, (uint8_t)0x9d, (uint8_t)0x9c, (uint8_t)0x9b, (uint8_t)0x9a, (uint8_t)0x99, (uint8_t)0x98, (uint8_t)0x97, (uint8_t)0x96, (uint8_t)0x95, (uint8_t)0x94, + (uint8_t)0x93, (uint8_t)0x92, (uint8_t)0x91, (uint8_t)0x90, (uint8_t)0x8f, (uint8_t)0x8e, (uint8_t)0x8d, (uint8_t)0x8c, (uint8_t)0x8b, (uint8_t)0x8a, (uint8_t)0x89, (uint8_t)0x88, + (uint8_t)0x87, (uint8_t)0x86, (uint8_t)0x85, (uint8_t)0x84, (uint8_t)0x83, (uint8_t)0x82, (uint8_t)0x81, (uint8_t)0x80, (uint8_t)0x7f, (uint8_t)0x7e, (uint8_t)0x7d, (uint8_t)0x7c, + (uint8_t)0x7b, (uint8_t)0x7a, (uint8_t)0x79, (uint8_t)0x78, (uint8_t)0x77, (uint8_t)0x76, (uint8_t)0x75, (uint8_t)0x74, (uint8_t)0x73, (uint8_t)0x72, (uint8_t)0x71, (uint8_t)0x70, + (uint8_t)0x6f, (uint8_t)0x6e, (uint8_t)0x6d, (uint8_t)0x6c, (uint8_t)0x6b, (uint8_t)0x6a, (uint8_t)0x69, (uint8_t)0x68, (uint8_t)0x67, (uint8_t)0x66, (uint8_t)0x65, (uint8_t)0x64, + (uint8_t)0x63, (uint8_t)0x62, (uint8_t)0x61, (uint8_t)0x60, (uint8_t)0x5f, (uint8_t)0x5e, (uint8_t)0x5d, (uint8_t)0x5c, (uint8_t)0x5b, (uint8_t)0x5a, (uint8_t)0x59, (uint8_t)0x58, + (uint8_t)0x57, (uint8_t)0x56, (uint8_t)0x55, (uint8_t)0x54, (uint8_t)0x53, (uint8_t)0x52, (uint8_t)0x51, (uint8_t)0x50, (uint8_t)0x4f, (uint8_t)0x4e, (uint8_t)0x4d, (uint8_t)0x4c, + (uint8_t)0x4b, (uint8_t)0x4a, (uint8_t)0x49, (uint8_t)0x48, (uint8_t)0x47, (uint8_t)0x46, (uint8_t)0x45, (uint8_t)0x44, (uint8_t)0x43, (uint8_t)0x42, (uint8_t)0x41, (uint8_t)0x40, + (uint8_t)0x3f, (uint8_t)0x3e, (uint8_t)0x3d, (uint8_t)0x3c, (uint8_t)0x3b, (uint8_t)0x3a, (uint8_t)0x39, (uint8_t)0x38, (uint8_t)0x37, (uint8_t)0x36, (uint8_t)0x35, (uint8_t)0x34, + (uint8_t)0x33, (uint8_t)0x32, (uint8_t)0x31, (uint8_t)0x30, (uint8_t)0x2f, (uint8_t)0x2e, (uint8_t)0x2d, (uint8_t)0x2c, (uint8_t)0x2b, (uint8_t)0x2a, (uint8_t)0x29, (uint8_t)0x28, + (uint8_t)0x27, (uint8_t)0x26, (uint8_t)0x25, (uint8_t)0x24, (uint8_t)0x23, (uint8_t)0x22, (uint8_t)0x21, (uint8_t)0x20, (uint8_t)0x1f, (uint8_t)0x1e, (uint8_t)0x1d, (uint8_t)0x1c, + (uint8_t)0x1b, (uint8_t)0x1a, (uint8_t)0x19, (uint8_t)0x18, (uint8_t)0x17, (uint8_t)0x16, (uint8_t)0x15, (uint8_t)0x14, (uint8_t)0x13, (uint8_t)0x12, (uint8_t)0x11, (uint8_t)0x10, + (uint8_t)0x0f, (uint8_t)0x0e, (uint8_t)0x0d, (uint8_t)0x0c, (uint8_t)0x0b, (uint8_t)0x0a, (uint8_t)0x09, (uint8_t)0x08, (uint8_t)0x07, (uint8_t)0x06, (uint8_t)0x05, (uint8_t)0x04, + (uint8_t)0x03, (uint8_t)0x02, (uint8_t)0x01, (uint8_t)0x00, (uint8_t)0x01, (uint8_t)0x02, (uint8_t)0x03, (uint8_t)0x04, (uint8_t)0x05, (uint8_t)0x06, (uint8_t)0x07, (uint8_t)0x08, + (uint8_t)0x09, (uint8_t)0x0a, (uint8_t)0x0b, (uint8_t)0x0c, (uint8_t)0x0d, (uint8_t)0x0e, (uint8_t)0x0f, (uint8_t)0x10, (uint8_t)0x11, (uint8_t)0x12, (uint8_t)0x13, (uint8_t)0x14, + (uint8_t)0x15, (uint8_t)0x16, (uint8_t)0x17, (uint8_t)0x18, (uint8_t)0x19, (uint8_t)0x1a, (uint8_t)0x1b, (uint8_t)0x1c, (uint8_t)0x1d, (uint8_t)0x1e, (uint8_t)0x1f, (uint8_t)0x20, + (uint8_t)0x21, (uint8_t)0x22, (uint8_t)0x23, (uint8_t)0x24, (uint8_t)0x25, (uint8_t)0x26, (uint8_t)0x27, (uint8_t)0x28, (uint8_t)0x29, (uint8_t)0x2a, (uint8_t)0x2b, (uint8_t)0x2c, + (uint8_t)0x2d, (uint8_t)0x2e, (uint8_t)0x2f, (uint8_t)0x30, (uint8_t)0x31, (uint8_t)0x32, (uint8_t)0x33, (uint8_t)0x34, (uint8_t)0x35, (uint8_t)0x36, (uint8_t)0x37, (uint8_t)0x38, + (uint8_t)0x39, (uint8_t)0x3a, (uint8_t)0x3b, (uint8_t)0x3c, (uint8_t)0x3d, (uint8_t)0x3e, (uint8_t)0x3f, (uint8_t)0x40, (uint8_t)0x41, (uint8_t)0x42, (uint8_t)0x43, (uint8_t)0x44, + (uint8_t)0x45, (uint8_t)0x46, (uint8_t)0x47, (uint8_t)0x48, (uint8_t)0x49, (uint8_t)0x4a, (uint8_t)0x4b, (uint8_t)0x4c, (uint8_t)0x4d, (uint8_t)0x4e, (uint8_t)0x4f, (uint8_t)0x50, + (uint8_t)0x51, (uint8_t)0x52, (uint8_t)0x53, (uint8_t)0x54, (uint8_t)0x55, (uint8_t)0x56, (uint8_t)0x57, (uint8_t)0x58, (uint8_t)0x59, (uint8_t)0x5a, (uint8_t)0x5b, (uint8_t)0x5c, + (uint8_t)0x5d, (uint8_t)0x5e, (uint8_t)0x5f, (uint8_t)0x60, (uint8_t)0x61, (uint8_t)0x62, (uint8_t)0x63, (uint8_t)0x64, (uint8_t)0x65, (uint8_t)0x66, (uint8_t)0x67, (uint8_t)0x68, + (uint8_t)0x69, (uint8_t)0x6a, (uint8_t)0x6b, (uint8_t)0x6c, (uint8_t)0x6d, (uint8_t)0x6e, (uint8_t)0x6f, (uint8_t)0x70, (uint8_t)0x71, (uint8_t)0x72, (uint8_t)0x73, (uint8_t)0x74, + (uint8_t)0x75, (uint8_t)0x76, (uint8_t)0x77, (uint8_t)0x78, (uint8_t)0x79, (uint8_t)0x7a, (uint8_t)0x7b, (uint8_t)0x7c, (uint8_t)0x7d, (uint8_t)0x7e, (uint8_t)0x7f, (uint8_t)0x80, + (uint8_t)0x81, (uint8_t)0x82, (uint8_t)0x83, (uint8_t)0x84, (uint8_t)0x85, (uint8_t)0x86, (uint8_t)0x87, (uint8_t)0x88, (uint8_t)0x89, (uint8_t)0x8a, (uint8_t)0x8b, (uint8_t)0x8c, + (uint8_t)0x8d, (uint8_t)0x8e, (uint8_t)0x8f, (uint8_t)0x90, (uint8_t)0x91, (uint8_t)0x92, (uint8_t)0x93, (uint8_t)0x94, (uint8_t)0x95, (uint8_t)0x96, (uint8_t)0x97, (uint8_t)0x98, + (uint8_t)0x99, (uint8_t)0x9a, (uint8_t)0x9b, (uint8_t)0x9c, (uint8_t)0x9d, (uint8_t)0x9e, (uint8_t)0x9f, (uint8_t)0xa0, (uint8_t)0xa1, (uint8_t)0xa2, (uint8_t)0xa3, (uint8_t)0xa4, + (uint8_t)0xa5, (uint8_t)0xa6, (uint8_t)0xa7, (uint8_t)0xa8, (uint8_t)0xa9, (uint8_t)0xaa, (uint8_t)0xab, (uint8_t)0xac, (uint8_t)0xad, (uint8_t)0xae, (uint8_t)0xaf, (uint8_t)0xb0, + (uint8_t)0xb1, (uint8_t)0xb2, (uint8_t)0xb3, (uint8_t)0xb4, (uint8_t)0xb5, (uint8_t)0xb6, (uint8_t)0xb7, (uint8_t)0xb8, (uint8_t)0xb9, (uint8_t)0xba, (uint8_t)0xbb, (uint8_t)0xbc, + (uint8_t)0xbd, (uint8_t)0xbe, (uint8_t)0xbf, (uint8_t)0xc0, (uint8_t)0xc1, (uint8_t)0xc2, (uint8_t)0xc3, (uint8_t)0xc4, (uint8_t)0xc5, (uint8_t)0xc6, (uint8_t)0xc7, (uint8_t)0xc8, + (uint8_t)0xc9, (uint8_t)0xca, (uint8_t)0xcb, (uint8_t)0xcc, (uint8_t)0xcd, (uint8_t)0xce, (uint8_t)0xcf, (uint8_t)0xd0, (uint8_t)0xd1, (uint8_t)0xd2, (uint8_t)0xd3, (uint8_t)0xd4, + (uint8_t)0xd5, (uint8_t)0xd6, (uint8_t)0xd7, (uint8_t)0xd8, (uint8_t)0xd9, (uint8_t)0xda, (uint8_t)0xdb, (uint8_t)0xdc, (uint8_t)0xdd, (uint8_t)0xde, (uint8_t)0xdf, (uint8_t)0xe0, + (uint8_t)0xe1, (uint8_t)0xe2, (uint8_t)0xe3, (uint8_t)0xe4, (uint8_t)0xe5, (uint8_t)0xe6, (uint8_t)0xe7, (uint8_t)0xe8, (uint8_t)0xe9, (uint8_t)0xea, (uint8_t)0xeb, (uint8_t)0xec, + (uint8_t)0xed, (uint8_t)0xee, (uint8_t)0xef, (uint8_t)0xf0, (uint8_t)0xf1, (uint8_t)0xf2, (uint8_t)0xf3, (uint8_t)0xf4, (uint8_t)0xf5, (uint8_t)0xf6, (uint8_t)0xf7, (uint8_t)0xf8, + (uint8_t)0xf9, (uint8_t)0xfa, (uint8_t)0xfb, (uint8_t)0xfc, (uint8_t)0xfd, (uint8_t)0xfe, (uint8_t)0xff +}; + +static const int8_t sclip1[1020 + 1020 + 1] = { + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, + (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x80, (int8_t)0x81, (int8_t)0x82, (int8_t)0x83, (int8_t)0x84, (int8_t)0x85, (int8_t)0x86, (int8_t)0x87, + (int8_t)0x88, (int8_t)0x89, (int8_t)0x8a, (int8_t)0x8b, (int8_t)0x8c, (int8_t)0x8d, (int8_t)0x8e, (int8_t)0x8f, (int8_t)0x90, (int8_t)0x91, (int8_t)0x92, (int8_t)0x93, + (int8_t)0x94, (int8_t)0x95, (int8_t)0x96, (int8_t)0x97, (int8_t)0x98, (int8_t)0x99, (int8_t)0x9a, (int8_t)0x9b, (int8_t)0x9c, (int8_t)0x9d, (int8_t)0x9e, (int8_t)0x9f, + (int8_t)0xa0, (int8_t)0xa1, (int8_t)0xa2, (int8_t)0xa3, (int8_t)0xa4, (int8_t)0xa5, (int8_t)0xa6, (int8_t)0xa7, (int8_t)0xa8, (int8_t)0xa9, (int8_t)0xaa, (int8_t)0xab, + (int8_t)0xac, (int8_t)0xad, (int8_t)0xae, (int8_t)0xaf, (int8_t)0xb0, (int8_t)0xb1, (int8_t)0xb2, (int8_t)0xb3, (int8_t)0xb4, (int8_t)0xb5, (int8_t)0xb6, (int8_t)0xb7, + (int8_t)0xb8, (int8_t)0xb9, (int8_t)0xba, (int8_t)0xbb, (int8_t)0xbc, (int8_t)0xbd, (int8_t)0xbe, (int8_t)0xbf, (int8_t)0xc0, (int8_t)0xc1, (int8_t)0xc2, (int8_t)0xc3, + (int8_t)0xc4, (int8_t)0xc5, (int8_t)0xc6, (int8_t)0xc7, (int8_t)0xc8, (int8_t)0xc9, (int8_t)0xca, (int8_t)0xcb, (int8_t)0xcc, (int8_t)0xcd, (int8_t)0xce, (int8_t)0xcf, + (int8_t)0xd0, (int8_t)0xd1, (int8_t)0xd2, (int8_t)0xd3, (int8_t)0xd4, (int8_t)0xd5, (int8_t)0xd6, (int8_t)0xd7, (int8_t)0xd8, (int8_t)0xd9, (int8_t)0xda, (int8_t)0xdb, + (int8_t)0xdc, (int8_t)0xdd, (int8_t)0xde, (int8_t)0xdf, (int8_t)0xe0, (int8_t)0xe1, (int8_t)0xe2, (int8_t)0xe3, (int8_t)0xe4, (int8_t)0xe5, (int8_t)0xe6, (int8_t)0xe7, + (int8_t)0xe8, (int8_t)0xe9, (int8_t)0xea, (int8_t)0xeb, (int8_t)0xec, (int8_t)0xed, (int8_t)0xee, (int8_t)0xef, (int8_t)0xf0, (int8_t)0xf1, (int8_t)0xf2, (int8_t)0xf3, + (int8_t)0xf4, (int8_t)0xf5, (int8_t)0xf6, (int8_t)0xf7, (int8_t)0xf8, (int8_t)0xf9, (int8_t)0xfa, (int8_t)0xfb, (int8_t)0xfc, (int8_t)0xfd, (int8_t)0xfe, (int8_t)0xff, + (int8_t)0x00, (int8_t)0x01, (int8_t)0x02, (int8_t)0x03, (int8_t)0x04, (int8_t)0x05, (int8_t)0x06, (int8_t)0x07, (int8_t)0x08, (int8_t)0x09, (int8_t)0x0a, (int8_t)0x0b, + (int8_t)0x0c, (int8_t)0x0d, (int8_t)0x0e, (int8_t)0x0f, (int8_t)0x10, (int8_t)0x11, (int8_t)0x12, (int8_t)0x13, (int8_t)0x14, (int8_t)0x15, (int8_t)0x16, (int8_t)0x17, + (int8_t)0x18, (int8_t)0x19, (int8_t)0x1a, (int8_t)0x1b, (int8_t)0x1c, (int8_t)0x1d, (int8_t)0x1e, (int8_t)0x1f, (int8_t)0x20, (int8_t)0x21, (int8_t)0x22, (int8_t)0x23, + (int8_t)0x24, (int8_t)0x25, (int8_t)0x26, (int8_t)0x27, (int8_t)0x28, (int8_t)0x29, (int8_t)0x2a, (int8_t)0x2b, (int8_t)0x2c, (int8_t)0x2d, (int8_t)0x2e, (int8_t)0x2f, + (int8_t)0x30, (int8_t)0x31, (int8_t)0x32, (int8_t)0x33, (int8_t)0x34, (int8_t)0x35, (int8_t)0x36, (int8_t)0x37, (int8_t)0x38, (int8_t)0x39, (int8_t)0x3a, (int8_t)0x3b, + (int8_t)0x3c, (int8_t)0x3d, (int8_t)0x3e, (int8_t)0x3f, (int8_t)0x40, (int8_t)0x41, (int8_t)0x42, (int8_t)0x43, (int8_t)0x44, (int8_t)0x45, (int8_t)0x46, (int8_t)0x47, + (int8_t)0x48, (int8_t)0x49, (int8_t)0x4a, (int8_t)0x4b, (int8_t)0x4c, (int8_t)0x4d, (int8_t)0x4e, (int8_t)0x4f, (int8_t)0x50, (int8_t)0x51, (int8_t)0x52, (int8_t)0x53, + (int8_t)0x54, (int8_t)0x55, (int8_t)0x56, (int8_t)0x57, (int8_t)0x58, (int8_t)0x59, (int8_t)0x5a, (int8_t)0x5b, (int8_t)0x5c, (int8_t)0x5d, (int8_t)0x5e, (int8_t)0x5f, + (int8_t)0x60, (int8_t)0x61, (int8_t)0x62, (int8_t)0x63, (int8_t)0x64, (int8_t)0x65, (int8_t)0x66, (int8_t)0x67, (int8_t)0x68, (int8_t)0x69, (int8_t)0x6a, (int8_t)0x6b, + (int8_t)0x6c, (int8_t)0x6d, (int8_t)0x6e, (int8_t)0x6f, (int8_t)0x70, (int8_t)0x71, (int8_t)0x72, (int8_t)0x73, (int8_t)0x74, (int8_t)0x75, (int8_t)0x76, (int8_t)0x77, + (int8_t)0x78, (int8_t)0x79, (int8_t)0x7a, (int8_t)0x7b, (int8_t)0x7c, (int8_t)0x7d, (int8_t)0x7e, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, + (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f, (int8_t)0x7f +}; + +static const int8_t sclip2[112 + 112 + 1] = { + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, (int8_t)0xf0, + (int8_t)0xf0, (int8_t)0xf1, (int8_t)0xf2, (int8_t)0xf3, (int8_t)0xf4, (int8_t)0xf5, (int8_t)0xf6, (int8_t)0xf7, (int8_t)0xf8, (int8_t)0xf9, (int8_t)0xfa, (int8_t)0xfb, + (int8_t)0xfc, (int8_t)0xfd, (int8_t)0xfe, (int8_t)0xff, (int8_t)0x00, (int8_t)0x01, (int8_t)0x02, (int8_t)0x03, (int8_t)0x04, (int8_t)0x05, (int8_t)0x06, (int8_t)0x07, + (int8_t)0x08, (int8_t)0x09, (int8_t)0x0a, (int8_t)0x0b, (int8_t)0x0c, (int8_t)0x0d, (int8_t)0x0e, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, + (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f, (int8_t)0x0f +}; + +static const uint8_t clip1[255 + 511 + 1] = { + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, + (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x00, (uint8_t)0x01, (uint8_t)0x02, (uint8_t)0x03, (uint8_t)0x04, (uint8_t)0x05, (uint8_t)0x06, (uint8_t)0x07, (uint8_t)0x08, + (uint8_t)0x09, (uint8_t)0x0a, (uint8_t)0x0b, (uint8_t)0x0c, (uint8_t)0x0d, (uint8_t)0x0e, (uint8_t)0x0f, (uint8_t)0x10, (uint8_t)0x11, (uint8_t)0x12, (uint8_t)0x13, (uint8_t)0x14, + (uint8_t)0x15, (uint8_t)0x16, (uint8_t)0x17, (uint8_t)0x18, (uint8_t)0x19, (uint8_t)0x1a, (uint8_t)0x1b, (uint8_t)0x1c, (uint8_t)0x1d, (uint8_t)0x1e, (uint8_t)0x1f, (uint8_t)0x20, + (uint8_t)0x21, (uint8_t)0x22, (uint8_t)0x23, (uint8_t)0x24, (uint8_t)0x25, (uint8_t)0x26, (uint8_t)0x27, (uint8_t)0x28, (uint8_t)0x29, (uint8_t)0x2a, (uint8_t)0x2b, (uint8_t)0x2c, + (uint8_t)0x2d, (uint8_t)0x2e, (uint8_t)0x2f, (uint8_t)0x30, (uint8_t)0x31, (uint8_t)0x32, (uint8_t)0x33, (uint8_t)0x34, (uint8_t)0x35, (uint8_t)0x36, (uint8_t)0x37, (uint8_t)0x38, + (uint8_t)0x39, (uint8_t)0x3a, (uint8_t)0x3b, (uint8_t)0x3c, (uint8_t)0x3d, (uint8_t)0x3e, (uint8_t)0x3f, (uint8_t)0x40, (uint8_t)0x41, (uint8_t)0x42, (uint8_t)0x43, (uint8_t)0x44, + (uint8_t)0x45, (uint8_t)0x46, (uint8_t)0x47, (uint8_t)0x48, (uint8_t)0x49, (uint8_t)0x4a, (uint8_t)0x4b, (uint8_t)0x4c, (uint8_t)0x4d, (uint8_t)0x4e, (uint8_t)0x4f, (uint8_t)0x50, + (uint8_t)0x51, (uint8_t)0x52, (uint8_t)0x53, (uint8_t)0x54, (uint8_t)0x55, (uint8_t)0x56, (uint8_t)0x57, (uint8_t)0x58, (uint8_t)0x59, (uint8_t)0x5a, (uint8_t)0x5b, (uint8_t)0x5c, + (uint8_t)0x5d, (uint8_t)0x5e, (uint8_t)0x5f, (uint8_t)0x60, (uint8_t)0x61, (uint8_t)0x62, (uint8_t)0x63, (uint8_t)0x64, (uint8_t)0x65, (uint8_t)0x66, (uint8_t)0x67, (uint8_t)0x68, + (uint8_t)0x69, (uint8_t)0x6a, (uint8_t)0x6b, (uint8_t)0x6c, (uint8_t)0x6d, (uint8_t)0x6e, (uint8_t)0x6f, (uint8_t)0x70, (uint8_t)0x71, (uint8_t)0x72, (uint8_t)0x73, (uint8_t)0x74, + (uint8_t)0x75, (uint8_t)0x76, (uint8_t)0x77, (uint8_t)0x78, (uint8_t)0x79, (uint8_t)0x7a, (uint8_t)0x7b, (uint8_t)0x7c, (uint8_t)0x7d, (uint8_t)0x7e, (uint8_t)0x7f, (uint8_t)0x80, + (uint8_t)0x81, (uint8_t)0x82, (uint8_t)0x83, (uint8_t)0x84, (uint8_t)0x85, (uint8_t)0x86, (uint8_t)0x87, (uint8_t)0x88, (uint8_t)0x89, (uint8_t)0x8a, (uint8_t)0x8b, (uint8_t)0x8c, + (uint8_t)0x8d, (uint8_t)0x8e, (uint8_t)0x8f, (uint8_t)0x90, (uint8_t)0x91, (uint8_t)0x92, (uint8_t)0x93, (uint8_t)0x94, (uint8_t)0x95, (uint8_t)0x96, (uint8_t)0x97, (uint8_t)0x98, + (uint8_t)0x99, (uint8_t)0x9a, (uint8_t)0x9b, (uint8_t)0x9c, (uint8_t)0x9d, (uint8_t)0x9e, (uint8_t)0x9f, (uint8_t)0xa0, (uint8_t)0xa1, (uint8_t)0xa2, (uint8_t)0xa3, (uint8_t)0xa4, + (uint8_t)0xa5, (uint8_t)0xa6, (uint8_t)0xa7, (uint8_t)0xa8, (uint8_t)0xa9, (uint8_t)0xaa, (uint8_t)0xab, (uint8_t)0xac, (uint8_t)0xad, (uint8_t)0xae, (uint8_t)0xaf, (uint8_t)0xb0, + (uint8_t)0xb1, (uint8_t)0xb2, (uint8_t)0xb3, (uint8_t)0xb4, (uint8_t)0xb5, (uint8_t)0xb6, (uint8_t)0xb7, (uint8_t)0xb8, (uint8_t)0xb9, (uint8_t)0xba, (uint8_t)0xbb, (uint8_t)0xbc, + (uint8_t)0xbd, (uint8_t)0xbe, (uint8_t)0xbf, (uint8_t)0xc0, (uint8_t)0xc1, (uint8_t)0xc2, (uint8_t)0xc3, (uint8_t)0xc4, (uint8_t)0xc5, (uint8_t)0xc6, (uint8_t)0xc7, (uint8_t)0xc8, + (uint8_t)0xc9, (uint8_t)0xca, (uint8_t)0xcb, (uint8_t)0xcc, (uint8_t)0xcd, (uint8_t)0xce, (uint8_t)0xcf, (uint8_t)0xd0, (uint8_t)0xd1, (uint8_t)0xd2, (uint8_t)0xd3, (uint8_t)0xd4, + (uint8_t)0xd5, (uint8_t)0xd6, (uint8_t)0xd7, (uint8_t)0xd8, (uint8_t)0xd9, (uint8_t)0xda, (uint8_t)0xdb, (uint8_t)0xdc, (uint8_t)0xdd, (uint8_t)0xde, (uint8_t)0xdf, (uint8_t)0xe0, + (uint8_t)0xe1, (uint8_t)0xe2, (uint8_t)0xe3, (uint8_t)0xe4, (uint8_t)0xe5, (uint8_t)0xe6, (uint8_t)0xe7, (uint8_t)0xe8, (uint8_t)0xe9, (uint8_t)0xea, (uint8_t)0xeb, (uint8_t)0xec, + (uint8_t)0xed, (uint8_t)0xee, (uint8_t)0xef, (uint8_t)0xf0, (uint8_t)0xf1, (uint8_t)0xf2, (uint8_t)0xf3, (uint8_t)0xf4, (uint8_t)0xf5, (uint8_t)0xf6, (uint8_t)0xf7, (uint8_t)0xf8, + (uint8_t)0xf9, (uint8_t)0xfa, (uint8_t)0xfb, (uint8_t)0xfc, (uint8_t)0xfd, (uint8_t)0xfe, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, + (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff, (uint8_t)0xff +}; + +#else + +// uninitialized tables +static uint8_t abs0[255 + 255 + 1]; +static int8_t sclip1[1020 + 1020 + 1]; +static int8_t sclip2[112 + 112 + 1]; +static uint8_t clip1[255 + 511 + 1]; + +// We declare this variable 'volatile' to prevent instruction reordering +// and make sure it's set to true _last_ (so as to be thread-safe) +static volatile int tables_ok = 0; + +#endif + +const int8_t* const VP8ksclip1 = &sclip1[1020]; +const int8_t* const VP8ksclip2 = &sclip2[112]; +const uint8_t* const VP8kclip1 = &clip1[255]; +const uint8_t* const VP8kabs0 = &abs0[255]; + +WEBP_TSAN_IGNORE_FUNCTION void VP8InitClipTables(void) { +#if !defined(USE_STATIC_TABLES) + int i; + if (!tables_ok) { + for (i = -255; i <= 255; ++i) { + abs0[255 + i] = (i < 0) ? -i : i; + } + for (i = -1020; i <= 1020; ++i) { + sclip1[1020 + i] = (i < -128) ? -128 : (i > 127) ? 127 : i; + } + for (i = -112; i <= 112; ++i) { + sclip2[112 + i] = (i < -16) ? -16 : (i > 15) ? 15 : i; + } + for (i = -255; i <= 255 + 255; ++i) { + clip1[255 + i] = (i < 0) ? 0 : (i > 255) ? 255 : i; + } + tables_ok = 1; + } +#endif // USE_STATIC_TABLES +} diff --git a/components/thorvg-main/src/loaders/webp/dsp/dsp.h b/components/thorvg-main/src/loaders/webp/dsp/dsp.h new file mode 100644 index 0000000..4446102 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/dsp.h @@ -0,0 +1,319 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Speed-critical functions. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_DSP_DSP_H_ +#define WEBP_DSP_DSP_H_ + +#ifdef HAVE_CONFIG_H +#include "../webp/config.h" +#endif + +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BPS 32 // this is the common stride for enc/dec + +//------------------------------------------------------------------------------ +// CPU detection + +#if defined(__GNUC__) +# define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__) +# define LOCAL_GCC_PREREQ(maj, min) \ + (LOCAL_GCC_VERSION >= (((maj) << 8) | (min))) +#else +# define LOCAL_GCC_VERSION 0 +# define LOCAL_GCC_PREREQ(maj, min) 0 +#endif + +#ifdef __clang__ +# define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__) +# define LOCAL_CLANG_PREREQ(maj, min) \ + (LOCAL_CLANG_VERSION >= (((maj) << 8) | (min))) +#else +# define LOCAL_CLANG_VERSION 0 +# define LOCAL_CLANG_PREREQ(maj, min) 0 +#endif // __clang__ + +#if defined(_MSC_VER) && _MSC_VER > 1310 && \ + (defined(_M_X64) || defined(_M_IX86)) +#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets +#endif + +// WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp +// files without intrinsics, allowing the corresponding Init() to be called. +// Files containing intrinsics will need to be built targeting the instruction +// set so should succeed on one of the earlier tests. +#if defined(__SSE2__) || defined(WEBP_MSC_SSE2) || defined(WEBP_HAVE_SSE2) +//#define WEBP_USE_SSE2 +#endif + +// This macro prevents thread_sanitizer from reporting known concurrent writes. +#define WEBP_TSAN_IGNORE_FUNCTION +#if defined(__has_feature) +#if __has_feature(thread_sanitizer) +#undef WEBP_TSAN_IGNORE_FUNCTION +#define WEBP_TSAN_IGNORE_FUNCTION __attribute__((no_sanitize_thread)) +#endif +#endif + +typedef enum { + kSSE2, +} CPUFeature; +// returns true if the CPU supports the feature. +typedef int (*VP8CPUInfo)(CPUFeature feature); +WEBP_EXTERN(VP8CPUInfo) VP8GetCPUInfo; + +//------------------------------------------------------------------------------ +// Init stub generator + +// Defines an init function stub to ensure each module exposes a symbol, +// avoiding a compiler warning. +#define WEBP_DSP_INIT_STUB(func) \ + extern void func(void); \ + WEBP_TSAN_IGNORE_FUNCTION void func(void) {} + +//------------------------------------------------------------------------------ +// Decoding + +typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst); +// when doing two transforms, coeffs is actually int16_t[2][16]. +typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two); +extern VP8DecIdct2 VP8Transform; +extern VP8DecIdct VP8TransformAC3; +extern VP8DecIdct VP8TransformUV; +extern VP8DecIdct VP8TransformDC; +extern VP8DecIdct VP8TransformDCUV; + +// *dst is the destination block, with stride BPS. Boundary samples are +// assumed accessible when needed. +typedef void (*VP8PredFunc)(uint8_t* dst); +extern VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */]; +extern VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */]; +extern VP8PredFunc VP8PredLuma4[/* NUM_BMODES */]; + +// clipping tables (for filtering) +extern const int8_t* const VP8ksclip1; // clips [-1020, 1020] to [-128, 127] +extern const int8_t* const VP8ksclip2; // clips [-112, 112] to [-16, 15] +extern const uint8_t* const VP8kclip1; // clips [-255,511] to [0,255] +extern const uint8_t* const VP8kabs0; // abs(x) for x in [-255,255] +// must be called first +void VP8InitClipTables(void); + +// simple filter (only for luma) +typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh); +extern VP8SimpleFilterFunc VP8SimpleVFilter16; +extern VP8SimpleFilterFunc VP8SimpleHFilter16; +extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges +extern VP8SimpleFilterFunc VP8SimpleHFilter16i; + +// regular filter (on both macroblock edges and inner edges) +typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride, + int thresh, int ithresh, int hev_t); +typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride, + int thresh, int ithresh, int hev_t); +// on outer edge +extern VP8LumaFilterFunc VP8VFilter16; +extern VP8LumaFilterFunc VP8HFilter16; +extern VP8ChromaFilterFunc VP8VFilter8; +extern VP8ChromaFilterFunc VP8HFilter8; + +// on inner edge +extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether +extern VP8LumaFilterFunc VP8HFilter16i; +extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether +extern VP8ChromaFilterFunc VP8HFilter8i; + +// must be called before anything using the above +void VP8DspInit(void); + +//------------------------------------------------------------------------------ +// WebP I/O + +//#define FANCY_UPSAMPLING // undefined to remove fancy upsampling support + +// Convert a pair of y/u/v lines together to the output rgb/a colorspace. +// bottom_y can be NULL if only one line of output is needed (at top/bottom). +typedef void (*WebPUpsampleLinePairFunc)( + const uint8_t* top_y, const uint8_t* bottom_y, + const uint8_t* top_u, const uint8_t* top_v, + const uint8_t* cur_u, const uint8_t* cur_v, + uint8_t* top_dst, uint8_t* bottom_dst, int len); + +#ifdef FANCY_UPSAMPLING + +// Fancy upsampling functions to convert YUV to RGB(A) modes +extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; + +#endif // FANCY_UPSAMPLING + +// Per-row point-sampling methods. +typedef void (*WebPSamplerRowFunc)(const uint8_t* y, + const uint8_t* u, const uint8_t* v, + uint8_t* dst, int len); +// Generic function to apply 'WebPSamplerRowFunc' to the whole plane: +void WebPSamplerProcessPlane(const uint8_t* y, int y_stride, + const uint8_t* u, const uint8_t* v, int uv_stride, + uint8_t* dst, int dst_stride, + int width, int height, WebPSamplerRowFunc func); + +// Sampling functions to convert rows of YUV to RGB(A) +extern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */]; + +// General function for converting two lines of ARGB or RGBA. +// 'alpha_is_last' should be true if 0xff000000 is stored in memory as +// as 0x00, 0x00, 0x00, 0xff (little endian). +WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last); + +// YUV444->RGB converters +typedef void (*WebPYUV444Converter)(const uint8_t* y, + const uint8_t* u, const uint8_t* v, + uint8_t* dst, int len); + +extern WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */]; + +// Must be called before using the WebPUpsamplers[] (and for premultiplied +// colorspaces like rgbA, rgbA4444, etc) +void WebPInitUpsamplers(void); +// Must be called before using WebPSamplers[] +void WebPInitSamplers(void); +// Must be called before using WebPYUV444Converters[] +void WebPInitYUV444Converters(void); + +//------------------------------------------------------------------------------ +// Rescaler + +struct WebPRescaler; + +// Import a row of data and save its contribution in the rescaler. +// 'channel' denotes the channel number to be imported. +extern void (*WebPRescalerImportRow)(struct WebPRescaler* const wrk, + const uint8_t* const src, int channel); + +// Export one row (starting at x_out position) from rescaler. +extern void (*WebPRescalerExportRow)(struct WebPRescaler* const wrk, int x_out); + +// Plain-C implementation, as fall-back. +extern void WebPRescalerExportRowC(struct WebPRescaler* const wrk, int x_out); + +// Must be called first before using the above. +void WebPRescalerDspInit(void); + +//------------------------------------------------------------------------------ +// Utilities for processing transparent channel. + +// Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h. +// alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last). +extern void (*WebPApplyAlphaMultiply)( + uint8_t* rgba, int alpha_first, int w, int h, int stride); + +// Same, buf specifically for RGBA4444 format +extern void (*WebPApplyAlphaMultiply4444)( + uint8_t* rgba4444, int w, int h, int stride); + +// Dispatch the values from alpha[] plane to the ARGB destination 'dst'. +// Returns true if alpha[] plane has non-trivial values different from 0xff. +extern int (*WebPDispatchAlpha)(const uint8_t* alpha, int alpha_stride, + int width, int height, + uint8_t* dst, int dst_stride); + +// Transfer packed 8b alpha[] values to green channel in dst[], zero'ing the +// A/R/B values. 'dst_stride' is the stride for dst[] in uint32_t units. +extern void (*WebPDispatchAlphaToGreen)(const uint8_t* alpha, int alpha_stride, + int width, int height, + uint32_t* dst, int dst_stride); + +// Extract the alpha values from 32b values in argb[] and pack them into alpha[] +// (this is the opposite of WebPDispatchAlpha). +// Returns true if there's only trivial 0xff alpha values. +extern int (*WebPExtractAlpha)(const uint8_t* argb, int argb_stride, + int width, int height, + uint8_t* alpha, int alpha_stride); + +// Pre-Multiply operation transforms x into x * A / 255 (where x=Y,R,G or B). +// Un-Multiply operation transforms x into x * 255 / A. + +// Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row. +extern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse); + +// Same a WebPMultARGBRow(), but for several rows. +void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows, + int inverse); + +// Same for a row of single values, with side alpha values. +extern void (*WebPMultRow)(uint8_t* const ptr, const uint8_t* const alpha, + int width, int inverse); + +// Same a WebPMultRow(), but for several 'num_rows' rows. +void WebPMultRows(uint8_t* ptr, int stride, + const uint8_t* alpha, int alpha_stride, + int width, int num_rows, int inverse); + +// Plain-C versions, used as fallback by some implementations. +void WebPMultRowC(uint8_t* const ptr, const uint8_t* const alpha, + int width, int inverse); +void WebPMultARGBRowC(uint32_t* const ptr, int width, int inverse); + +// To be called first before using the above. +void WebPInitAlphaProcessing(void); + +// ARGB packing function: a/r/g/b input is rgba or bgra order. +extern void (*VP8PackARGB)(const uint8_t* a, const uint8_t* r, + const uint8_t* g, const uint8_t* b, int len, + uint32_t* out); + +// RGB packing function. 'step' can be 3 or 4. r/g/b input is rgb or bgr order. +extern void (*VP8PackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b, + int len, int step, uint32_t* out); + + +//------------------------------------------------------------------------------ +// Filter functions + +typedef enum { // Filter types. + WEBP_FILTER_NONE = 0, + WEBP_FILTER_HORIZONTAL, + WEBP_FILTER_VERTICAL, + WEBP_FILTER_GRADIENT, + WEBP_FILTER_LAST = WEBP_FILTER_GRADIENT + 1, // end marker + WEBP_FILTER_BEST, // meta-types + WEBP_FILTER_FAST +} WEBP_FILTER_TYPE; + +typedef void (*WebPFilterFunc)(const uint8_t* in, int width, int height, + int stride, uint8_t* out); +typedef void (*WebPUnfilterFunc)(int width, int height, int stride, + int row, int num_rows, uint8_t* data); + +// Filter the given data using the given predictor. +// 'in' corresponds to a 2-dimensional pixel array of size (stride * height) +// in raster order. +// 'stride' is number of bytes per scan line (with possible padding). +// 'out' should be pre-allocated. +extern WebPFilterFunc WebPFilters[WEBP_FILTER_LAST]; + +// In-place reconstruct the original data from the given filtered data. +// The reconstruction will be done for 'num_rows' rows starting from 'row' +// (assuming rows upto 'row - 1' are already reconstructed). +extern WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST]; + +// To be called first before using the above. +void VP8FiltersInit(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_DSP_DSP_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/dsp/filters.cpp b/components/thorvg-main/src/loaders/webp/dsp/filters.cpp new file mode 100644 index 0000000..5c30f2e --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/filters.cpp @@ -0,0 +1,240 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Spatial prediction using various filters +// +// Author: Urvang (urvang@google.com) + +#include "./dsp.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Helpful macro. + +# define SANITY_CHECK(in, out) \ + assert(in != NULL); \ + assert(out != NULL); \ + assert(width > 0); \ + assert(height > 0); \ + assert(stride >= width); \ + assert(row >= 0 && num_rows > 0 && row + num_rows <= height); \ + (void)height; // Silence unused warning. + +static WEBP_INLINE void PredictLine(const uint8_t* src, const uint8_t* pred, + uint8_t* dst, int length, int inverse) { + int i; + if (inverse) { + for (i = 0; i < length; ++i) dst[i] = src[i] + pred[i]; + } else { + for (i = 0; i < length; ++i) dst[i] = src[i] - pred[i]; + } +} + +//------------------------------------------------------------------------------ +// Horizontal filter. + +static WEBP_INLINE void DoHorizontalFilter(const uint8_t* in, + int width, int height, int stride, + int row, int num_rows, + int inverse, uint8_t* out) { + const uint8_t* preds; + const size_t start_offset = row * stride; + const int last_row = row + num_rows; + SANITY_CHECK(in, out); + in += start_offset; + out += start_offset; + preds = inverse ? out : in; + + if (row == 0) { + // Leftmost pixel is the same as input for topmost scanline. + out[0] = in[0]; + PredictLine(in + 1, preds, out + 1, width - 1, inverse); + row = 1; + preds += stride; + in += stride; + out += stride; + } + + // Filter line-by-line. + while (row < last_row) { + // Leftmost pixel is predicted from above. + PredictLine(in, preds - stride, out, 1, inverse); + PredictLine(in + 1, preds, out + 1, width - 1, inverse); + ++row; + preds += stride; + in += stride; + out += stride; + } +} + +//------------------------------------------------------------------------------ +// Vertical filter. + +static WEBP_INLINE void DoVerticalFilter(const uint8_t* in, + int width, int height, int stride, + int row, int num_rows, + int inverse, uint8_t* out) { + const uint8_t* preds; + const size_t start_offset = row * stride; + const int last_row = row + num_rows; + SANITY_CHECK(in, out); + in += start_offset; + out += start_offset; + preds = inverse ? out : in; + + if (row == 0) { + // Very first top-left pixel is copied. + out[0] = in[0]; + // Rest of top scan-line is left-predicted. + PredictLine(in + 1, preds, out + 1, width - 1, inverse); + row = 1; + in += stride; + out += stride; + } else { + // We are starting from in-between. Make sure 'preds' points to prev row. + preds -= stride; + } + + // Filter line-by-line. + while (row < last_row) { + PredictLine(in, preds, out, width, inverse); + ++row; + preds += stride; + in += stride; + out += stride; + } +} + +//------------------------------------------------------------------------------ +// Gradient filter. + +static WEBP_INLINE int GradientPredictor(uint8_t a, uint8_t b, uint8_t c) { + const int g = a + b - c; + return ((g & ~0xff) == 0) ? g : (g < 0) ? 0 : 255; // clip to 8bit +} + +static WEBP_INLINE void DoGradientFilter(const uint8_t* in, + int width, int height, int stride, + int row, int num_rows, + int inverse, uint8_t* out) { + const uint8_t* preds; + const size_t start_offset = row * stride; + const int last_row = row + num_rows; + SANITY_CHECK(in, out); + in += start_offset; + out += start_offset; + preds = inverse ? out : in; + + // left prediction for top scan-line + if (row == 0) { + out[0] = in[0]; + PredictLine(in + 1, preds, out + 1, width - 1, inverse); + row = 1; + preds += stride; + in += stride; + out += stride; + } + + // Filter line-by-line. + while (row < last_row) { + int w; + // leftmost pixel: predict from above. + PredictLine(in, preds - stride, out, 1, inverse); + for (w = 1; w < width; ++w) { + const int pred = GradientPredictor(preds[w - 1], + preds[w - stride], + preds[w - stride - 1]); + out[w] = in[w] + (inverse ? pred : -pred); + } + ++row; + preds += stride; + in += stride; + out += stride; + } +} + +#undef SANITY_CHECK + +//------------------------------------------------------------------------------ + +static void HorizontalFilter(const uint8_t* data, int width, int height, + int stride, uint8_t* filtered_data) { + DoHorizontalFilter(data, width, height, stride, 0, height, 0, filtered_data); +} + +static void VerticalFilter(const uint8_t* data, int width, int height, + int stride, uint8_t* filtered_data) { + DoVerticalFilter(data, width, height, stride, 0, height, 0, filtered_data); +} + + +static void GradientFilter(const uint8_t* data, int width, int height, + int stride, uint8_t* filtered_data) { + DoGradientFilter(data, width, height, stride, 0, height, 0, filtered_data); +} + + +//------------------------------------------------------------------------------ + +static void VerticalUnfilter(int width, int height, int stride, int row, + int num_rows, uint8_t* data) { + DoVerticalFilter(data, width, height, stride, row, num_rows, 1, data); +} + +static void HorizontalUnfilter(int width, int height, int stride, int row, + int num_rows, uint8_t* data) { + DoHorizontalFilter(data, width, height, stride, row, num_rows, 1, data); +} + +static void GradientUnfilter(int width, int height, int stride, int row, + int num_rows, uint8_t* data) { + DoGradientFilter(data, width, height, stride, row, num_rows, 1, data); +} + +//------------------------------------------------------------------------------ +// Init function + +WebPFilterFunc WebPFilters[WEBP_FILTER_LAST]; +WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST]; + +extern void VP8FiltersInitMIPSdspR2(void); +extern void VP8FiltersInitSSE2(void); + +static volatile VP8CPUInfo filters_last_cpuinfo_used = + (VP8CPUInfo)&filters_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void VP8FiltersInit(void) { + if (filters_last_cpuinfo_used == VP8GetCPUInfo) return; + + WebPUnfilters[WEBP_FILTER_NONE] = NULL; + WebPUnfilters[WEBP_FILTER_HORIZONTAL] = HorizontalUnfilter; + WebPUnfilters[WEBP_FILTER_VERTICAL] = VerticalUnfilter; + WebPUnfilters[WEBP_FILTER_GRADIENT] = GradientUnfilter; + + WebPFilters[WEBP_FILTER_NONE] = NULL; + WebPFilters[WEBP_FILTER_HORIZONTAL] = HorizontalFilter; + WebPFilters[WEBP_FILTER_VERTICAL] = VerticalFilter; + WebPFilters[WEBP_FILTER_GRADIENT] = GradientFilter; + + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + VP8FiltersInitSSE2(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + VP8FiltersInitMIPSdspR2(); + } +#endif + } + filters_last_cpuinfo_used = VP8GetCPUInfo; +} diff --git a/components/thorvg-main/src/loaders/webp/dsp/lossless.cpp b/components/thorvg-main/src/loaders/webp/dsp/lossless.cpp new file mode 100644 index 0000000..5ca7759 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/lossless.cpp @@ -0,0 +1,636 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Image transforms and color space conversion methods for lossless decoder. +// +// Authors: Vikas Arora (vikaas.arora@gmail.com) +// Jyrki Alakuijala (jyrki@google.com) +// Urvang Joshi (urvang@google.com) + +#include "./dsp.h" + +#include +#include +#include "../dec/vp8li.h" +#include "../utils/endian_inl.h" +#include "./lossless.h" +#include "./yuv.h" + +#define MAX_DIFF_COST (1e30f) + +//------------------------------------------------------------------------------ +// Image transforms. + +// In-place sum of each component with mod 256. +static WEBP_INLINE void AddPixelsEq(uint32_t* a, uint32_t b) { + const uint32_t alpha_and_green = (*a & 0xff00ff00u) + (b & 0xff00ff00u); + const uint32_t red_and_blue = (*a & 0x00ff00ffu) + (b & 0x00ff00ffu); + *a = (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); +} + +static WEBP_INLINE uint32_t Average2(uint32_t a0, uint32_t a1) { + return (((a0 ^ a1) & 0xfefefefeL) >> 1) + (a0 & a1); +} + +static WEBP_INLINE uint32_t Average3(uint32_t a0, uint32_t a1, uint32_t a2) { + return Average2(Average2(a0, a2), a1); +} + +static WEBP_INLINE uint32_t Average4(uint32_t a0, uint32_t a1, + uint32_t a2, uint32_t a3) { + return Average2(Average2(a0, a1), Average2(a2, a3)); +} + +static WEBP_INLINE uint32_t Clip255(uint32_t a) { + if (a < 256) { + return a; + } + // return 0, when a is a negative integer. + // return 255, when a is positive. + return ~a >> 24; +} + +static WEBP_INLINE int AddSubtractComponentFull(int a, int b, int c) { + return Clip255(a + b - c); +} + +static WEBP_INLINE uint32_t ClampedAddSubtractFull(uint32_t c0, uint32_t c1, + uint32_t c2) { + const int a = AddSubtractComponentFull(c0 >> 24, c1 >> 24, c2 >> 24); + const int r = AddSubtractComponentFull((c0 >> 16) & 0xff, + (c1 >> 16) & 0xff, + (c2 >> 16) & 0xff); + const int g = AddSubtractComponentFull((c0 >> 8) & 0xff, + (c1 >> 8) & 0xff, + (c2 >> 8) & 0xff); + const int b = AddSubtractComponentFull(c0 & 0xff, c1 & 0xff, c2 & 0xff); + return ((uint32_t)a << 24) | (r << 16) | (g << 8) | b; +} + +static WEBP_INLINE int AddSubtractComponentHalf(int a, int b) { + return Clip255(a + (a - b) / 2); +} + +static WEBP_INLINE uint32_t ClampedAddSubtractHalf(uint32_t c0, uint32_t c1, + uint32_t c2) { + const uint32_t ave = Average2(c0, c1); + const int a = AddSubtractComponentHalf(ave >> 24, c2 >> 24); + const int r = AddSubtractComponentHalf((ave >> 16) & 0xff, (c2 >> 16) & 0xff); + const int g = AddSubtractComponentHalf((ave >> 8) & 0xff, (c2 >> 8) & 0xff); + const int b = AddSubtractComponentHalf((ave >> 0) & 0xff, (c2 >> 0) & 0xff); + return ((uint32_t)a << 24) | (r << 16) | (g << 8) | b; +} + +// gcc-4.9 on ARM generates incorrect code in Select() when Sub3() is inlined. +#if defined(__arm__) && LOCAL_GCC_VERSION == 0x409 +# define LOCAL_INLINE __attribute__ ((noinline)) +#else +# define LOCAL_INLINE WEBP_INLINE +#endif + +static LOCAL_INLINE int Sub3(int a, int b, int c) { + const int pb = b - c; + const int pa = a - c; + return abs(pb) - abs(pa); +} + +#undef LOCAL_INLINE + +static WEBP_INLINE uint32_t Select(uint32_t a, uint32_t b, uint32_t c) { + const int pa_minus_pb = + Sub3((a >> 24) , (b >> 24) , (c >> 24) ) + + Sub3((a >> 16) & 0xff, (b >> 16) & 0xff, (c >> 16) & 0xff) + + Sub3((a >> 8) & 0xff, (b >> 8) & 0xff, (c >> 8) & 0xff) + + Sub3((a ) & 0xff, (b ) & 0xff, (c ) & 0xff); + return (pa_minus_pb <= 0) ? a : b; +} + +//------------------------------------------------------------------------------ +// Predictors + +static uint32_t Predictor0(uint32_t left, const uint32_t* const top) { + (void)top; + (void)left; + return ARGB_BLACK; +} +static uint32_t Predictor1(uint32_t left, const uint32_t* const top) { + (void)top; + return left; +} +static uint32_t Predictor2(uint32_t left, const uint32_t* const top) { + (void)left; + return top[0]; +} +static uint32_t Predictor3(uint32_t left, const uint32_t* const top) { + (void)left; + return top[1]; +} +static uint32_t Predictor4(uint32_t left, const uint32_t* const top) { + (void)left; + return top[-1]; +} +static uint32_t Predictor5(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Average3(left, top[0], top[1]); + return pred; +} +static uint32_t Predictor6(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Average2(left, top[-1]); + return pred; +} +static uint32_t Predictor7(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Average2(left, top[0]); + return pred; +} +static uint32_t Predictor8(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Average2(top[-1], top[0]); + (void)left; + return pred; +} +static uint32_t Predictor9(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Average2(top[0], top[1]); + (void)left; + return pred; +} +static uint32_t Predictor10(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Average4(left, top[-1], top[0], top[1]); + return pred; +} +static uint32_t Predictor11(uint32_t left, const uint32_t* const top) { + const uint32_t pred = Select(top[0], left, top[-1]); + return pred; +} +static uint32_t Predictor12(uint32_t left, const uint32_t* const top) { + const uint32_t pred = ClampedAddSubtractFull(left, top[0], top[-1]); + return pred; +} +static uint32_t Predictor13(uint32_t left, const uint32_t* const top) { + const uint32_t pred = ClampedAddSubtractHalf(left, top[0], top[-1]); + return pred; +} + +//------------------------------------------------------------------------------ + +// Inverse prediction. +static void PredictorInverseTransform(const VP8LTransform* const transform, + int y_start, int y_end, uint32_t* data) { + const int width = transform->xsize_; + if (y_start == 0) { // First Row follows the L (mode=1) mode. + int x; + const uint32_t pred0 = Predictor0(data[-1], NULL); + AddPixelsEq(data, pred0); + for (x = 1; x < width; ++x) { + const uint32_t pred1 = Predictor1(data[x - 1], NULL); + AddPixelsEq(data + x, pred1); + } + data += width; + ++y_start; + } + + { + int y = y_start; + const int tile_width = 1 << transform->bits_; + const int mask = tile_width - 1; + const int safe_width = width & ~mask; + const int tiles_per_row = VP8LSubSampleSize(width, transform->bits_); + const uint32_t* pred_mode_base = + transform->data_ + (y >> transform->bits_) * tiles_per_row; + + while (y < y_end) { + const uint32_t pred2 = Predictor2(data[-1], data - width); + const uint32_t* pred_mode_src = pred_mode_base; + VP8LPredictorFunc pred_func; + int x = 1; + int t = 1; + // First pixel follows the T (mode=2) mode. + AddPixelsEq(data, pred2); + // .. the rest: + while (x < safe_width) { + pred_func = VP8LPredictors[((*pred_mode_src++) >> 8) & 0xf]; + for (; t < tile_width; ++t, ++x) { + const uint32_t pred = pred_func(data[x - 1], data + x - width); + AddPixelsEq(data + x, pred); + } + t = 0; + } + if (x < width) { + pred_func = VP8LPredictors[((*pred_mode_src++) >> 8) & 0xf]; + for (; x < width; ++x) { + const uint32_t pred = pred_func(data[x - 1], data + x - width); + AddPixelsEq(data + x, pred); + } + } + data += width; + ++y; + if ((y & mask) == 0) { // Use the same mask, since tiles are squares. + pred_mode_base += tiles_per_row; + } + } + } +} + +// Add green to blue and red channels (i.e. perform the inverse transform of +// 'subtract green'). +void VP8LAddGreenToBlueAndRed_C(uint32_t* data, int num_pixels) { + int i; + for (i = 0; i < num_pixels; ++i) { + const uint32_t argb = data[i]; + const uint32_t green = ((argb >> 8) & 0xff); + uint32_t red_blue = (argb & 0x00ff00ffu); + red_blue += (green << 16) | green; + red_blue &= 0x00ff00ffu; + data[i] = (argb & 0xff00ff00u) | red_blue; + } +} + +static WEBP_INLINE uint32_t ColorTransformDelta(int8_t color_pred, + int8_t color) { + return (uint32_t)((int)(color_pred) * color) >> 5; +} + +static WEBP_INLINE void ColorCodeToMultipliers(uint32_t color_code, + VP8LMultipliers* const m) { + m->green_to_red_ = (color_code >> 0) & 0xff; + m->green_to_blue_ = (color_code >> 8) & 0xff; + m->red_to_blue_ = (color_code >> 16) & 0xff; +} + +void VP8LTransformColorInverse_C(const VP8LMultipliers* const m, uint32_t* data, + int num_pixels) { + int i; + for (i = 0; i < num_pixels; ++i) { + const uint32_t argb = data[i]; + const uint32_t green = argb >> 8; + const uint32_t red = argb >> 16; + uint32_t new_red = red; + uint32_t new_blue = argb; + new_red += ColorTransformDelta(m->green_to_red_, green); + new_red &= 0xff; + new_blue += ColorTransformDelta(m->green_to_blue_, green); + new_blue += ColorTransformDelta(m->red_to_blue_, new_red); + new_blue &= 0xff; + data[i] = (argb & 0xff00ff00u) | (new_red << 16) | (new_blue); + } +} + +// Color space inverse transform. +static void ColorSpaceInverseTransform(const VP8LTransform* const transform, + int y_start, int y_end, uint32_t* data) { + const int width = transform->xsize_; + const int tile_width = 1 << transform->bits_; + const int mask = tile_width - 1; + const int safe_width = width & ~mask; + const int remaining_width = width - safe_width; + const int tiles_per_row = VP8LSubSampleSize(width, transform->bits_); + int y = y_start; + const uint32_t* pred_row = + transform->data_ + (y >> transform->bits_) * tiles_per_row; + + while (y < y_end) { + const uint32_t* pred = pred_row; + VP8LMultipliers m = { 0, 0, 0 }; + const uint32_t* const data_safe_end = data + safe_width; + const uint32_t* const data_end = data + width; + while (data < data_safe_end) { + ColorCodeToMultipliers(*pred++, &m); + VP8LTransformColorInverse(&m, data, tile_width); + data += tile_width; + } + if (data < data_end) { // Left-overs using C-version. + ColorCodeToMultipliers(*pred++, &m); + VP8LTransformColorInverse(&m, data, remaining_width); + data += remaining_width; + } + ++y; + if ((y & mask) == 0) pred_row += tiles_per_row; + } +} + +// Separate out pixels packed together using pixel-bundling. +// We define two methods for ARGB data (uint32_t) and alpha-only data (uint8_t). +#define COLOR_INDEX_INVERSE(FUNC_NAME, F_NAME, STATIC_DECL, TYPE, BIT_SUFFIX, \ + GET_INDEX, GET_VALUE) \ +static void F_NAME(const TYPE* src, const uint32_t* const color_map, \ + TYPE* dst, int y_start, int y_end, int width) { \ + int y; \ + for (y = y_start; y < y_end; ++y) { \ + int x; \ + for (x = 0; x < width; ++x) { \ + *dst++ = GET_VALUE(color_map[GET_INDEX(*src++)]); \ + } \ + } \ +} \ +STATIC_DECL void FUNC_NAME(const VP8LTransform* const transform, \ + int y_start, int y_end, const TYPE* src, \ + TYPE* dst) { \ + int y; \ + const int bits_per_pixel = 8 >> transform->bits_; \ + const int width = transform->xsize_; \ + const uint32_t* const color_map = transform->data_; \ + if (bits_per_pixel < 8) { \ + const int pixels_per_byte = 1 << transform->bits_; \ + const int count_mask = pixels_per_byte - 1; \ + const uint32_t bit_mask = (1 << bits_per_pixel) - 1; \ + for (y = y_start; y < y_end; ++y) { \ + uint32_t packed_pixels = 0; \ + int x; \ + for (x = 0; x < width; ++x) { \ + /* We need to load fresh 'packed_pixels' once every */ \ + /* 'pixels_per_byte' increments of x. Fortunately, pixels_per_byte */ \ + /* is a power of 2, so can just use a mask for that, instead of */ \ + /* decrementing a counter. */ \ + if ((x & count_mask) == 0) packed_pixels = GET_INDEX(*src++); \ + *dst++ = GET_VALUE(color_map[packed_pixels & bit_mask]); \ + packed_pixels >>= bits_per_pixel; \ + } \ + } \ + } else { \ + VP8LMapColor##BIT_SUFFIX(src, color_map, dst, y_start, y_end, width); \ + } \ +} + +COLOR_INDEX_INVERSE(ColorIndexInverseTransform, MapARGB, static, uint32_t, 32b, + VP8GetARGBIndex, VP8GetARGBValue) +COLOR_INDEX_INVERSE(VP8LColorIndexInverseTransformAlpha, MapAlpha, , uint8_t, + 8b, VP8GetAlphaIndex, VP8GetAlphaValue) + +#undef COLOR_INDEX_INVERSE + +void VP8LInverseTransform(const VP8LTransform* const transform, + int row_start, int row_end, + const uint32_t* const in, uint32_t* const out) { + const int width = transform->xsize_; + assert(row_start < row_end); + assert(row_end <= transform->ysize_); + switch (transform->type_) { + case SUBTRACT_GREEN: + VP8LAddGreenToBlueAndRed(out, (row_end - row_start) * width); + break; + case PREDICTOR_TRANSFORM: + PredictorInverseTransform(transform, row_start, row_end, out); + if (row_end != transform->ysize_) { + // The last predicted row in this iteration will be the top-pred row + // for the first row in next iteration. + memcpy(out - width, out + (row_end - row_start - 1) * width, + width * sizeof(*out)); + } + break; + case CROSS_COLOR_TRANSFORM: + ColorSpaceInverseTransform(transform, row_start, row_end, out); + break; + case COLOR_INDEXING_TRANSFORM: + if (in == out && transform->bits_ > 0) { + // Move packed pixels to the end of unpacked region, so that unpacking + // can occur seamlessly. + // Also, note that this is the only transform that applies on + // the effective width of VP8LSubSampleSize(xsize_, bits_). All other + // transforms work on effective width of xsize_. + const int out_stride = (row_end - row_start) * width; + const int in_stride = (row_end - row_start) * + VP8LSubSampleSize(transform->xsize_, transform->bits_); + uint32_t* const src = out + out_stride - in_stride; + memmove(src, out, in_stride * sizeof(*src)); + ColorIndexInverseTransform(transform, row_start, row_end, src, out); + } else { + ColorIndexInverseTransform(transform, row_start, row_end, in, out); + } + break; + } +} + +//------------------------------------------------------------------------------ +// Color space conversion. + +static int is_big_endian(void) { + static const union { + uint16_t w; + uint8_t b[2]; + } tmp = { 1 }; + return (tmp.b[0] != 1); +} + +void VP8LConvertBGRAToRGB_C(const uint32_t* src, + int num_pixels, uint8_t* dst) { + const uint32_t* const src_end = src + num_pixels; + while (src < src_end) { + const uint32_t argb = *src++; + *dst++ = (argb >> 16) & 0xff; + *dst++ = (argb >> 8) & 0xff; + *dst++ = (argb >> 0) & 0xff; + } +} + +void VP8LConvertBGRAToRGBA_C(const uint32_t* src, + int num_pixels, uint8_t* dst) { + const uint32_t* const src_end = src + num_pixels; + while (src < src_end) { + const uint32_t argb = *src++; + *dst++ = (argb >> 16) & 0xff; + *dst++ = (argb >> 8) & 0xff; + *dst++ = (argb >> 0) & 0xff; + *dst++ = (argb >> 24) & 0xff; + } +} + +void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src, + int num_pixels, uint8_t* dst) { + const uint32_t* const src_end = src + num_pixels; + while (src < src_end) { + const uint32_t argb = *src++; + const uint8_t rg = ((argb >> 16) & 0xf0) | ((argb >> 12) & 0xf); + const uint8_t ba = ((argb >> 0) & 0xf0) | ((argb >> 28) & 0xf); +#ifdef WEBP_SWAP_16BIT_CSP + *dst++ = ba; + *dst++ = rg; +#else + *dst++ = rg; + *dst++ = ba; +#endif + } +} + +void VP8LConvertBGRAToRGB565_C(const uint32_t* src, + int num_pixels, uint8_t* dst) { + const uint32_t* const src_end = src + num_pixels; + while (src < src_end) { + const uint32_t argb = *src++; + const uint8_t rg = ((argb >> 16) & 0xf8) | ((argb >> 13) & 0x7); + const uint8_t gb = ((argb >> 5) & 0xe0) | ((argb >> 3) & 0x1f); +#ifdef WEBP_SWAP_16BIT_CSP + *dst++ = gb; + *dst++ = rg; +#else + *dst++ = rg; + *dst++ = gb; +#endif + } +} + +void VP8LConvertBGRAToBGR_C(const uint32_t* src, + int num_pixels, uint8_t* dst) { + const uint32_t* const src_end = src + num_pixels; + while (src < src_end) { + const uint32_t argb = *src++; + *dst++ = (argb >> 0) & 0xff; + *dst++ = (argb >> 8) & 0xff; + *dst++ = (argb >> 16) & 0xff; + } +} + +static void CopyOrSwap(const uint32_t* src, int num_pixels, uint8_t* dst, + int swap_on_big_endian) { + if (is_big_endian() == swap_on_big_endian) { + const uint32_t* const src_end = src + num_pixels; + while (src < src_end) { + const uint32_t argb = *src++; + +#if !defined(WORDS_BIGENDIAN) +#if !defined(WEBP_REFERENCE_IMPLEMENTATION) + *(uint32_t*)dst = BSwap32(argb); +#else // WEBP_REFERENCE_IMPLEMENTATION + dst[0] = (argb >> 24) & 0xff; + dst[1] = (argb >> 16) & 0xff; + dst[2] = (argb >> 8) & 0xff; + dst[3] = (argb >> 0) & 0xff; +#endif +#else // WORDS_BIGENDIAN + dst[0] = (argb >> 0) & 0xff; + dst[1] = (argb >> 8) & 0xff; + dst[2] = (argb >> 16) & 0xff; + dst[3] = (argb >> 24) & 0xff; +#endif + dst += sizeof(argb); + } + } else { + memcpy(dst, src, num_pixels * sizeof(*src)); + } +} + +void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels, + WEBP_CSP_MODE out_colorspace, uint8_t* const rgba) { + switch (out_colorspace) { + case MODE_RGB: + VP8LConvertBGRAToRGB(in_data, num_pixels, rgba); + break; + case MODE_RGBA: + VP8LConvertBGRAToRGBA(in_data, num_pixels, rgba); + break; + case MODE_rgbA: + VP8LConvertBGRAToRGBA(in_data, num_pixels, rgba); + WebPApplyAlphaMultiply(rgba, 0, num_pixels, 1, 0); + break; + case MODE_BGR: + VP8LConvertBGRAToBGR(in_data, num_pixels, rgba); + break; + case MODE_BGRA: + CopyOrSwap(in_data, num_pixels, rgba, 1); + break; + case MODE_bgrA: + CopyOrSwap(in_data, num_pixels, rgba, 1); + WebPApplyAlphaMultiply(rgba, 0, num_pixels, 1, 0); + break; + case MODE_ARGB: + CopyOrSwap(in_data, num_pixels, rgba, 0); + break; + case MODE_Argb: + CopyOrSwap(in_data, num_pixels, rgba, 0); + WebPApplyAlphaMultiply(rgba, 1, num_pixels, 1, 0); + break; + case MODE_RGBA_4444: + VP8LConvertBGRAToRGBA4444(in_data, num_pixels, rgba); + break; + case MODE_rgbA_4444: + VP8LConvertBGRAToRGBA4444(in_data, num_pixels, rgba); + WebPApplyAlphaMultiply4444(rgba, num_pixels, 1, 0); + break; + case MODE_RGB_565: + VP8LConvertBGRAToRGB565(in_data, num_pixels, rgba); + break; + default: + assert(0); // Code flow should not reach here. + } +} + +//------------------------------------------------------------------------------ + +VP8LProcessBlueAndRedFunc VP8LAddGreenToBlueAndRed; +VP8LPredictorFunc VP8LPredictors[16]; + +VP8LTransformColorFunc VP8LTransformColorInverse; + +VP8LConvertFunc VP8LConvertBGRAToRGB; +VP8LConvertFunc VP8LConvertBGRAToRGBA; +VP8LConvertFunc VP8LConvertBGRAToRGBA4444; +VP8LConvertFunc VP8LConvertBGRAToRGB565; +VP8LConvertFunc VP8LConvertBGRAToBGR; + +VP8LMapARGBFunc VP8LMapColor32b; +VP8LMapAlphaFunc VP8LMapColor8b; + +extern void VP8LDspInitSSE2(void); +extern void VP8LDspInitNEON(void); +extern void VP8LDspInitMIPSdspR2(void); + +static volatile VP8CPUInfo lossless_last_cpuinfo_used = + (VP8CPUInfo)&lossless_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) { + if (lossless_last_cpuinfo_used == VP8GetCPUInfo) return; + + VP8LPredictors[0] = Predictor0; + VP8LPredictors[1] = Predictor1; + VP8LPredictors[2] = Predictor2; + VP8LPredictors[3] = Predictor3; + VP8LPredictors[4] = Predictor4; + VP8LPredictors[5] = Predictor5; + VP8LPredictors[6] = Predictor6; + VP8LPredictors[7] = Predictor7; + VP8LPredictors[8] = Predictor8; + VP8LPredictors[9] = Predictor9; + VP8LPredictors[10] = Predictor10; + VP8LPredictors[11] = Predictor11; + VP8LPredictors[12] = Predictor12; + VP8LPredictors[13] = Predictor13; + VP8LPredictors[14] = Predictor0; // <- padding security sentinels + VP8LPredictors[15] = Predictor0; + + VP8LAddGreenToBlueAndRed = VP8LAddGreenToBlueAndRed_C; + + VP8LTransformColorInverse = VP8LTransformColorInverse_C; + + VP8LConvertBGRAToRGB = VP8LConvertBGRAToRGB_C; + VP8LConvertBGRAToRGBA = VP8LConvertBGRAToRGBA_C; + VP8LConvertBGRAToRGBA4444 = VP8LConvertBGRAToRGBA4444_C; + VP8LConvertBGRAToRGB565 = VP8LConvertBGRAToRGB565_C; + VP8LConvertBGRAToBGR = VP8LConvertBGRAToBGR_C; + + VP8LMapColor32b = MapARGB; + VP8LMapColor8b = MapAlpha; + + // If defined, use CPUInfo() to overwrite some pointers with faster versions. + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + VP8LDspInitSSE2(); + } +#endif +#if defined(WEBP_USE_NEON) + if (VP8GetCPUInfo(kNEON)) { + VP8LDspInitNEON(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + VP8LDspInitMIPSdspR2(); + } +#endif + } + lossless_last_cpuinfo_used = VP8GetCPUInfo; +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/dsp/lossless.h b/components/thorvg-main/src/loaders/webp/dsp/lossless.h new file mode 100644 index 0000000..48b360e --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/lossless.h @@ -0,0 +1,303 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Image transforms and color space conversion methods for lossless decoder. +// +// Authors: Vikas Arora (vikaas.arora@gmail.com) +// Jyrki Alakuijala (jyrki@google.com) + +#ifndef WEBP_DSP_LOSSLESS_H_ +#define WEBP_DSP_LOSSLESS_H_ + +#include "../webp/types.h" +#include "../webp/decode.h" + +// #include "../enc/histogram.h" +#include "../utils/utils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Not a trivial literal symbol. +#define VP8L_NON_TRIVIAL_SYM (0xffffffff) + +//------------------------------------------------------------------------------ +// Decoding + +typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top); +extern VP8LPredictorFunc VP8LPredictors[16]; + +typedef void (*VP8LProcessBlueAndRedFunc)(uint32_t* argb_data, int num_pixels); +extern VP8LProcessBlueAndRedFunc VP8LAddGreenToBlueAndRed; + +typedef struct { + // Note: the members are uint8_t, so that any negative values are + // automatically converted to "mod 256" values. + uint8_t green_to_red_; + uint8_t green_to_blue_; + uint8_t red_to_blue_; +} VP8LMultipliers; +typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m, + uint32_t* argb_data, int num_pixels); +extern VP8LTransformColorFunc VP8LTransformColorInverse; + +struct VP8LTransform; // Defined in dec/vp8li.h. + +// Performs inverse transform of data given transform information, start and end +// rows. Transform will be applied to rows [row_start, row_end[. +// The *in and *out pointers refer to source and destination data respectively +// corresponding to the intermediate row (row_start). +void VP8LInverseTransform(const struct VP8LTransform* const transform, + int row_start, int row_end, + const uint32_t* const in, uint32_t* const out); + +// Color space conversion. +typedef void (*VP8LConvertFunc)(const uint32_t* src, int num_pixels, + uint8_t* dst); +extern VP8LConvertFunc VP8LConvertBGRAToRGB; +extern VP8LConvertFunc VP8LConvertBGRAToRGBA; +extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444; +extern VP8LConvertFunc VP8LConvertBGRAToRGB565; +extern VP8LConvertFunc VP8LConvertBGRAToBGR; + +// Converts from BGRA to other color spaces. +void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels, + WEBP_CSP_MODE out_colorspace, uint8_t* const rgba); + +// color mapping related functions. +static WEBP_INLINE uint32_t VP8GetARGBIndex(uint32_t idx) { + return (idx >> 8) & 0xff; +} + +static WEBP_INLINE uint8_t VP8GetAlphaIndex(uint8_t idx) { + return idx; +} + +static WEBP_INLINE uint32_t VP8GetARGBValue(uint32_t val) { + return val; +} + +static WEBP_INLINE uint8_t VP8GetAlphaValue(uint32_t val) { + return (val >> 8) & 0xff; +} + +typedef void (*VP8LMapARGBFunc)(const uint32_t* src, + const uint32_t* const color_map, + uint32_t* dst, int y_start, + int y_end, int width); +typedef void (*VP8LMapAlphaFunc)(const uint8_t* src, + const uint32_t* const color_map, + uint8_t* dst, int y_start, + int y_end, int width); + +extern VP8LMapARGBFunc VP8LMapColor32b; +extern VP8LMapAlphaFunc VP8LMapColor8b; + +// Similar to the static method ColorIndexInverseTransform() that is part of +// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than +// uint32_t) arguments for 'src' and 'dst'. +void VP8LColorIndexInverseTransformAlpha( + const struct VP8LTransform* const transform, int y_start, int y_end, + const uint8_t* src, uint8_t* dst); + +// Expose some C-only fallback functions +void VP8LTransformColorInverse_C(const VP8LMultipliers* const m, + uint32_t* data, int num_pixels); + +void VP8LConvertBGRAToRGB_C(const uint32_t* src, int num_pixels, uint8_t* dst); +void VP8LConvertBGRAToRGBA_C(const uint32_t* src, int num_pixels, uint8_t* dst); +void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src, + int num_pixels, uint8_t* dst); +void VP8LConvertBGRAToRGB565_C(const uint32_t* src, + int num_pixels, uint8_t* dst); +void VP8LConvertBGRAToBGR_C(const uint32_t* src, int num_pixels, uint8_t* dst); +void VP8LAddGreenToBlueAndRed_C(uint32_t* data, int num_pixels); + +// Must be called before calling any of the above methods. +void VP8LDspInit(void); + +//------------------------------------------------------------------------------ +// Encoding + +extern VP8LProcessBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed; +extern VP8LTransformColorFunc VP8LTransformColor; +typedef void (*VP8LCollectColorBlueTransformsFunc)( + const uint32_t* argb, int stride, + int tile_width, int tile_height, + int green_to_blue, int red_to_blue, int histo[]); +extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms; + +typedef void (*VP8LCollectColorRedTransformsFunc)( + const uint32_t* argb, int stride, + int tile_width, int tile_height, + int green_to_red, int histo[]); +extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms; + +// Expose some C-only fallback functions +void VP8LTransformColor_C(const VP8LMultipliers* const m, + uint32_t* data, int num_pixels); +void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels); + +//------------------------------------------------------------------------------ +// Image transforms. + +void VP8LResidualImage(int width, int height, int bits, int low_effort, + uint32_t* const argb, uint32_t* const argb_scratch, + uint32_t* const image); + +void VP8LColorSpaceTransform(int width, int height, int bits, int quality, + uint32_t* const argb, uint32_t* image); + +//------------------------------------------------------------------------------ +// Misc methods. + +// Computes sampled size of 'size' when sampling using 'sampling bits'. +static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size, + uint32_t sampling_bits) { + return (size + (1 << sampling_bits) - 1) >> sampling_bits; +} + +// ----------------------------------------------------------------------------- +// Faster logarithm for integers. Small values use a look-up table. +#define LOG_LOOKUP_IDX_MAX 256 +extern const float kLog2Table[LOG_LOOKUP_IDX_MAX]; +extern const float kSLog2Table[LOG_LOOKUP_IDX_MAX]; +typedef float (*VP8LFastLog2SlowFunc)(uint32_t v); + +extern VP8LFastLog2SlowFunc VP8LFastLog2Slow; +extern VP8LFastLog2SlowFunc VP8LFastSLog2Slow; + +static WEBP_INLINE float VP8LFastLog2(uint32_t v) { + return (v < LOG_LOOKUP_IDX_MAX) ? kLog2Table[v] : VP8LFastLog2Slow(v); +} +// Fast calculation of v * log2(v) for integer input. +static WEBP_INLINE float VP8LFastSLog2(uint32_t v) { + return (v < LOG_LOOKUP_IDX_MAX) ? kSLog2Table[v] : VP8LFastSLog2Slow(v); +} + +// ----------------------------------------------------------------------------- +// Huffman-cost related functions. + +typedef double (*VP8LCostFunc)(const uint32_t* population, int length); +typedef double (*VP8LCostCombinedFunc)(const uint32_t* X, const uint32_t* Y, + int length); + +extern VP8LCostFunc VP8LExtraCost; +extern VP8LCostCombinedFunc VP8LExtraCostCombined; + +typedef struct { // small struct to hold counters + int counts[2]; // index: 0=zero steak, 1=non-zero streak + int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3] +} VP8LStreaks; + +typedef VP8LStreaks (*VP8LCostCountFunc)(const uint32_t* population, + int length); +typedef VP8LStreaks (*VP8LCostCombinedCountFunc)(const uint32_t* X, + const uint32_t* Y, int length); + +extern VP8LCostCountFunc VP8LHuffmanCostCount; +extern VP8LCostCombinedCountFunc VP8LHuffmanCostCombinedCount; + +// Get the symbol entropy for the distribution 'population'. +// Set 'trivial_sym', if there's only one symbol present in the distribution. +double VP8LPopulationCost(const uint32_t* const population, int length, + uint32_t* const trivial_sym); + +// Get the combined symbol entropy for the distributions 'X' and 'Y'. +double VP8LGetCombinedEntropy(const uint32_t* const X, + const uint32_t* const Y, int length); + +// ----------------------------------------------------------------------------- +// PrefixEncode() + +static WEBP_INLINE int VP8LBitsLog2Ceiling(uint32_t n) { + const int log_floor = BitsLog2Floor(n); + if (n == (n & ~(n - 1))) // zero or a power of two. + return log_floor; + else + return log_floor + 1; +} + +// Splitting of distance and length codes into prefixes and +// extra bits. The prefixes are encoded with an entropy code +// while the extra bits are stored just as normal bits. +static WEBP_INLINE void VP8LPrefixEncodeBitsNoLUT(int distance, int* const code, + int* const extra_bits) { + const int highest_bit = BitsLog2Floor(--distance); + const int second_highest_bit = (distance >> (highest_bit - 1)) & 1; + *extra_bits = highest_bit - 1; + *code = 2 * highest_bit + second_highest_bit; +} + +static WEBP_INLINE void VP8LPrefixEncodeNoLUT(int distance, int* const code, + int* const extra_bits, + int* const extra_bits_value) { + const int highest_bit = BitsLog2Floor(--distance); + const int second_highest_bit = (distance >> (highest_bit - 1)) & 1; + *extra_bits = highest_bit - 1; + *extra_bits_value = distance & ((1 << *extra_bits) - 1); + *code = 2 * highest_bit + second_highest_bit; +} + +#define PREFIX_LOOKUP_IDX_MAX 512 +typedef struct { + int8_t code_; + int8_t extra_bits_; +} VP8LPrefixCode; + +// These tables are derived using VP8LPrefixEncodeNoLUT. +extern const VP8LPrefixCode kPrefixEncodeCode[PREFIX_LOOKUP_IDX_MAX]; +extern const uint8_t kPrefixEncodeExtraBitsValue[PREFIX_LOOKUP_IDX_MAX]; +static WEBP_INLINE void VP8LPrefixEncodeBits(int distance, int* const code, + int* const extra_bits) { + if (distance < PREFIX_LOOKUP_IDX_MAX) { + const VP8LPrefixCode prefix_code = kPrefixEncodeCode[distance]; + *code = prefix_code.code_; + *extra_bits = prefix_code.extra_bits_; + } else { + VP8LPrefixEncodeBitsNoLUT(distance, code, extra_bits); + } +} + +static WEBP_INLINE void VP8LPrefixEncode(int distance, int* const code, + int* const extra_bits, + int* const extra_bits_value) { + if (distance < PREFIX_LOOKUP_IDX_MAX) { + const VP8LPrefixCode prefix_code = kPrefixEncodeCode[distance]; + *code = prefix_code.code_; + *extra_bits = prefix_code.extra_bits_; + *extra_bits_value = kPrefixEncodeExtraBitsValue[distance]; + } else { + VP8LPrefixEncodeNoLUT(distance, code, extra_bits, extra_bits_value); + } +} + +// In-place difference of each component with mod 256. +static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { + const uint32_t alpha_and_green = + 0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u); + const uint32_t red_and_blue = + 0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu); + return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); +} + +void VP8LBundleColorMap(const uint8_t* const row, int width, + int xbits, uint32_t* const dst); + +// Must be called before calling any of the above methods. +void VP8LEncDspInit(void); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_DSP_LOSSLESS_H_ diff --git a/components/thorvg-main/src/loaders/webp/dsp/meson.build b/components/thorvg-main/src/loaders/webp/dsp/meson.build new file mode 100644 index 0000000..9f9eb59 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/meson.build @@ -0,0 +1,20 @@ +source_file = [ + 'yuv.h', + 'dsp.h', + 'lossless.h', + 'alpha_processing.cpp', + 'argb.cpp', + 'cpu.cpp', + 'dec.cpp', + 'dec_clip_tables.cpp', + 'filters.cpp', + 'lossless.cpp', + 'rescaler.cpp', + 'upsampling.cpp', + 'yuv.cpp' +] + +webp_deb += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/webp/dsp/rescaler.cpp b/components/thorvg-main/src/loaders/webp/dsp/rescaler.cpp new file mode 100644 index 0000000..640b462 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/rescaler.cpp @@ -0,0 +1,115 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Rescaling functions + +#include "./dsp.h" +#include "../utils/rescaler.h" + +//------------------------------------------------------------------------------ +// Implementations of critical functions ImportRow / ExportRow + +#define ROUNDER (1 << (WEBP_RESCALER_RFIX - 1)) +#define MULT_FIX(x, y) (((int64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX) + +static void RescalerImportRowC(WebPRescaler* const wrk, + const uint8_t* const src, int channel) { + const int x_stride = wrk->num_channels; + const int x_out_max = wrk->dst_width * wrk->num_channels; + int x_in = channel; + int x_out; + int accum = 0; + if (!wrk->x_expand) { + int sum = 0; + for (x_out = channel; x_out < x_out_max; x_out += x_stride) { + accum += wrk->x_add; + for (; accum > 0; accum -= wrk->x_sub) { + sum += src[x_in]; + x_in += x_stride; + } + { // Emit next horizontal pixel. + const int32_t base = src[x_in]; + const int32_t frac = base * (-accum); + x_in += x_stride; + wrk->frow[x_out] = (sum + base) * wrk->x_sub - frac; + // fresh fractional start for next pixel + sum = (int)MULT_FIX(frac, wrk->fx_scale); + } + } + } else { // simple bilinear interpolation + int left = src[channel], right = src[channel]; + for (x_out = channel; x_out < x_out_max; x_out += x_stride) { + if (accum < 0) { + left = right; + x_in += x_stride; + right = src[x_in]; + accum += wrk->x_add; + } + wrk->frow[x_out] = right * wrk->x_add + (left - right) * accum; + accum -= wrk->x_sub; + } + } + // Accumulate the contribution of the new row. + for (x_out = channel; x_out < x_out_max; x_out += x_stride) { + wrk->irow[x_out] += wrk->frow[x_out]; + } +} + +void WebPRescalerExportRowC(WebPRescaler* const wrk, int x_out) { + if (wrk->y_accum <= 0) { + uint8_t* const dst = wrk->dst; + int32_t* const irow = wrk->irow; + const int32_t* const frow = wrk->frow; + const int yscale = wrk->fy_scale * (-wrk->y_accum); + const int x_out_max = wrk->dst_width * wrk->num_channels; + for (; x_out < x_out_max; ++x_out) { + const int frac = (int)MULT_FIX(frow[x_out], yscale); + const int v = (int)MULT_FIX(irow[x_out] - frac, wrk->fxy_scale); + dst[x_out] = (!(v & ~0xff)) ? v : (v < 0) ? 0 : 255; + irow[x_out] = frac; // new fractional start + } + wrk->y_accum += wrk->y_add; + wrk->dst += wrk->dst_stride; + } +} + +#undef MULT_FIX +#undef ROUNDER + +//------------------------------------------------------------------------------ + +void (*WebPRescalerImportRow)(struct WebPRescaler* const wrk, + const uint8_t* const src, int channel); +void (*WebPRescalerExportRow)(struct WebPRescaler* const wrk, int x_out); + +extern void WebPRescalerDspInitMIPS32(void); +extern void WebPRescalerDspInitMIPSdspR2(void); + +static volatile VP8CPUInfo rescaler_last_cpuinfo_used = + (VP8CPUInfo)&rescaler_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) { + if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return; + + WebPRescalerImportRow = RescalerImportRowC; + WebPRescalerExportRow = WebPRescalerExportRowC; + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_MIPS32) + if (VP8GetCPUInfo(kMIPS32)) { + WebPRescalerDspInitMIPS32(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + WebPRescalerDspInitMIPSdspR2(); + } +#endif + } + rescaler_last_cpuinfo_used = VP8GetCPUInfo; +} diff --git a/components/thorvg-main/src/loaders/webp/dsp/upsampling.cpp b/components/thorvg-main/src/loaders/webp/dsp/upsampling.cpp new file mode 100644 index 0000000..151a32e --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/upsampling.cpp @@ -0,0 +1,252 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// YUV to RGB upsampling functions. +// +// Author: somnath@google.com (Somnath Banerjee) + +#include "./dsp.h" +#include "./yuv.h" + +#include + +//------------------------------------------------------------------------------ +// Fancy upsampler + +#ifdef FANCY_UPSAMPLING + +// Fancy upsampling functions to convert YUV to RGB +WebPUpsampleLinePairFunc WebPUpsamplers[MODE_LAST]; + +// Given samples laid out in a square as: +// [a b] +// [c d] +// we interpolate u/v as: +// ([9*a + 3*b + 3*c + d 3*a + 9*b + 3*c + d] + [8 8]) / 16 +// ([3*a + b + 9*c + 3*d a + 3*b + 3*c + 9*d] [8 8]) / 16 + +// We process u and v together stashed into 32bit (16bit each). +#define LOAD_UV(u, v) ((u) | ((v) << 16)) + +#define UPSAMPLE_FUNC(FUNC_NAME, FUNC, XSTEP) \ +static void FUNC_NAME(const uint8_t* top_y, const uint8_t* bottom_y, \ + const uint8_t* top_u, const uint8_t* top_v, \ + const uint8_t* cur_u, const uint8_t* cur_v, \ + uint8_t* top_dst, uint8_t* bottom_dst, int len) { \ + int x; \ + const int last_pixel_pair = (len - 1) >> 1; \ + uint32_t tl_uv = LOAD_UV(top_u[0], top_v[0]); /* top-left sample */ \ + uint32_t l_uv = LOAD_UV(cur_u[0], cur_v[0]); /* left-sample */ \ + assert(top_y != NULL); \ + { \ + const uint32_t uv0 = (3 * tl_uv + l_uv + 0x00020002u) >> 2; \ + FUNC(top_y[0], uv0 & 0xff, (uv0 >> 16), top_dst); \ + } \ + if (bottom_y != NULL) { \ + const uint32_t uv0 = (3 * l_uv + tl_uv + 0x00020002u) >> 2; \ + FUNC(bottom_y[0], uv0 & 0xff, (uv0 >> 16), bottom_dst); \ + } \ + for (x = 1; x <= last_pixel_pair; ++x) { \ + const uint32_t t_uv = LOAD_UV(top_u[x], top_v[x]); /* top sample */ \ + const uint32_t uv = LOAD_UV(cur_u[x], cur_v[x]); /* sample */ \ + /* precompute invariant values associated with first and second diagonals*/\ + const uint32_t avg = tl_uv + t_uv + l_uv + uv + 0x00080008u; \ + const uint32_t diag_12 = (avg + 2 * (t_uv + l_uv)) >> 3; \ + const uint32_t diag_03 = (avg + 2 * (tl_uv + uv)) >> 3; \ + { \ + const uint32_t uv0 = (diag_12 + tl_uv) >> 1; \ + const uint32_t uv1 = (diag_03 + t_uv) >> 1; \ + FUNC(top_y[2 * x - 1], uv0 & 0xff, (uv0 >> 16), \ + top_dst + (2 * x - 1) * XSTEP); \ + FUNC(top_y[2 * x - 0], uv1 & 0xff, (uv1 >> 16), \ + top_dst + (2 * x - 0) * XSTEP); \ + } \ + if (bottom_y != NULL) { \ + const uint32_t uv0 = (diag_03 + l_uv) >> 1; \ + const uint32_t uv1 = (diag_12 + uv) >> 1; \ + FUNC(bottom_y[2 * x - 1], uv0 & 0xff, (uv0 >> 16), \ + bottom_dst + (2 * x - 1) * XSTEP); \ + FUNC(bottom_y[2 * x + 0], uv1 & 0xff, (uv1 >> 16), \ + bottom_dst + (2 * x + 0) * XSTEP); \ + } \ + tl_uv = t_uv; \ + l_uv = uv; \ + } \ + if (!(len & 1)) { \ + { \ + const uint32_t uv0 = (3 * tl_uv + l_uv + 0x00020002u) >> 2; \ + FUNC(top_y[len - 1], uv0 & 0xff, (uv0 >> 16), \ + top_dst + (len - 1) * XSTEP); \ + } \ + if (bottom_y != NULL) { \ + const uint32_t uv0 = (3 * l_uv + tl_uv + 0x00020002u) >> 2; \ + FUNC(bottom_y[len - 1], uv0 & 0xff, (uv0 >> 16), \ + bottom_dst + (len - 1) * XSTEP); \ + } \ + } \ +} + +// All variants implemented. +UPSAMPLE_FUNC(UpsampleRgbLinePair, VP8YuvToRgb, 3) +UPSAMPLE_FUNC(UpsampleBgrLinePair, VP8YuvToBgr, 3) +UPSAMPLE_FUNC(UpsampleRgbaLinePair, VP8YuvToRgba, 4) +UPSAMPLE_FUNC(UpsampleBgraLinePair, VP8YuvToBgra, 4) +UPSAMPLE_FUNC(UpsampleArgbLinePair, VP8YuvToArgb, 4) +UPSAMPLE_FUNC(UpsampleRgba4444LinePair, VP8YuvToRgba4444, 2) +UPSAMPLE_FUNC(UpsampleRgb565LinePair, VP8YuvToRgb565, 2) + +#undef LOAD_UV +#undef UPSAMPLE_FUNC + +#endif // FANCY_UPSAMPLING + +//------------------------------------------------------------------------------ + +#if !defined(FANCY_UPSAMPLING) +#define DUAL_SAMPLE_FUNC(FUNC_NAME, FUNC) \ +static void FUNC_NAME(const uint8_t* top_y, const uint8_t* bot_y, \ + const uint8_t* top_u, const uint8_t* top_v, \ + const uint8_t* bot_u, const uint8_t* bot_v, \ + uint8_t* top_dst, uint8_t* bot_dst, int len) { \ + const int half_len = len >> 1; \ + int x; \ + assert(top_dst != NULL); \ + { \ + for (x = 0; x < half_len; ++x) { \ + FUNC(top_y[2 * x + 0], top_u[x], top_v[x], top_dst + 8 * x + 0); \ + FUNC(top_y[2 * x + 1], top_u[x], top_v[x], top_dst + 8 * x + 4); \ + } \ + if (len & 1) FUNC(top_y[2 * x + 0], top_u[x], top_v[x], top_dst + 8 * x); \ + } \ + if (bot_dst != NULL) { \ + for (x = 0; x < half_len; ++x) { \ + FUNC(bot_y[2 * x + 0], bot_u[x], bot_v[x], bot_dst + 8 * x + 0); \ + FUNC(bot_y[2 * x + 1], bot_u[x], bot_v[x], bot_dst + 8 * x + 4); \ + } \ + if (len & 1) FUNC(bot_y[2 * x + 0], bot_u[x], bot_v[x], bot_dst + 8 * x); \ + } \ +} + +DUAL_SAMPLE_FUNC(DualLineSamplerBGRA, VP8YuvToBgra) +DUAL_SAMPLE_FUNC(DualLineSamplerARGB, VP8YuvToArgb) +#undef DUAL_SAMPLE_FUNC + +#endif // !FANCY_UPSAMPLING + +WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last) { + WebPInitUpsamplers(); + VP8YUVInit(); +#ifdef FANCY_UPSAMPLING + return WebPUpsamplers[alpha_is_last ? MODE_BGRA : MODE_ARGB]; +#else + return (alpha_is_last ? DualLineSamplerBGRA : DualLineSamplerARGB); +#endif +} + +//------------------------------------------------------------------------------ +// YUV444 converter + +#define YUV444_FUNC(FUNC_NAME, FUNC, XSTEP) \ +static void FUNC_NAME(const uint8_t* y, const uint8_t* u, const uint8_t* v, \ + uint8_t* dst, int len) { \ + int i; \ + for (i = 0; i < len; ++i) FUNC(y[i], u[i], v[i], &dst[i * XSTEP]); \ +} + +YUV444_FUNC(Yuv444ToRgb, VP8YuvToRgb, 3) +YUV444_FUNC(Yuv444ToBgr, VP8YuvToBgr, 3) +YUV444_FUNC(Yuv444ToRgba, VP8YuvToRgba, 4) +YUV444_FUNC(Yuv444ToBgra, VP8YuvToBgra, 4) +YUV444_FUNC(Yuv444ToArgb, VP8YuvToArgb, 4) +YUV444_FUNC(Yuv444ToRgba4444, VP8YuvToRgba4444, 2) +YUV444_FUNC(Yuv444ToRgb565, VP8YuvToRgb565, 2) + +#undef YUV444_FUNC + +WebPYUV444Converter WebPYUV444Converters[MODE_LAST]; + +extern void WebPInitYUV444ConvertersMIPSdspR2(void); + +static volatile VP8CPUInfo upsampling_last_cpuinfo_used1 = + (VP8CPUInfo)&upsampling_last_cpuinfo_used1; + +WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444Converters(void) { + if (upsampling_last_cpuinfo_used1 == VP8GetCPUInfo) return; + + WebPYUV444Converters[MODE_RGB] = Yuv444ToRgb; + WebPYUV444Converters[MODE_RGBA] = Yuv444ToRgba; + WebPYUV444Converters[MODE_BGR] = Yuv444ToBgr; + WebPYUV444Converters[MODE_BGRA] = Yuv444ToBgra; + WebPYUV444Converters[MODE_ARGB] = Yuv444ToArgb; + WebPYUV444Converters[MODE_RGBA_4444] = Yuv444ToRgba4444; + WebPYUV444Converters[MODE_RGB_565] = Yuv444ToRgb565; + WebPYUV444Converters[MODE_rgbA] = Yuv444ToRgba; + WebPYUV444Converters[MODE_bgrA] = Yuv444ToBgra; + WebPYUV444Converters[MODE_Argb] = Yuv444ToArgb; + WebPYUV444Converters[MODE_rgbA_4444] = Yuv444ToRgba4444; + + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + WebPInitYUV444ConvertersMIPSdspR2(); + } +#endif + } + upsampling_last_cpuinfo_used1 = VP8GetCPUInfo; +} + +//------------------------------------------------------------------------------ +// Main calls + +extern void WebPInitUpsamplersSSE2(void); +extern void WebPInitUpsamplersNEON(void); +extern void WebPInitUpsamplersMIPSdspR2(void); + +static volatile VP8CPUInfo upsampling_last_cpuinfo_used2 = + (VP8CPUInfo)&upsampling_last_cpuinfo_used2; + +WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplers(void) { + if (upsampling_last_cpuinfo_used2 == VP8GetCPUInfo) return; + +#ifdef FANCY_UPSAMPLING + WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; + WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; + WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair; + WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair; + WebPUpsamplers[MODE_ARGB] = UpsampleArgbLinePair; + WebPUpsamplers[MODE_RGBA_4444] = UpsampleRgba4444LinePair; + WebPUpsamplers[MODE_RGB_565] = UpsampleRgb565LinePair; + WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair; + WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair; + WebPUpsamplers[MODE_Argb] = UpsampleArgbLinePair; + WebPUpsamplers[MODE_rgbA_4444] = UpsampleRgba4444LinePair; + + // If defined, use CPUInfo() to overwrite some pointers with faster versions. + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + WebPInitUpsamplersSSE2(); + } +#endif +#if defined(WEBP_USE_NEON) + if (VP8GetCPUInfo(kNEON)) { + WebPInitUpsamplersNEON(); + } +#endif +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + WebPInitUpsamplersMIPSdspR2(); + } +#endif + } +#endif // FANCY_UPSAMPLING + upsampling_last_cpuinfo_used2 = VP8GetCPUInfo; +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/dsp/yuv.cpp b/components/thorvg-main/src/loaders/webp/dsp/yuv.cpp new file mode 100644 index 0000000..086a925 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/yuv.cpp @@ -0,0 +1,166 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// YUV->RGB conversion functions +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "./yuv.h" + +#if defined(WEBP_YUV_USE_TABLE) + +static int done = 0; + +static WEBP_INLINE uint8_t clip(int v, int max_value) { + return v < 0 ? 0 : v > max_value ? max_value : v; +} + +int16_t VP8kVToR[256], VP8kUToB[256]; +int32_t VP8kVToG[256], VP8kUToG[256]; +uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN]; +uint8_t VP8kClip4Bits[YUV_RANGE_MAX - YUV_RANGE_MIN]; + +WEBP_TSAN_IGNORE_FUNCTION void VP8YUVInit(void) { + int i; + if (done) { + return; + } +#ifndef USE_YUVj + for (i = 0; i < 256; ++i) { + VP8kVToR[i] = (89858 * (i - 128) + YUV_HALF) >> YUV_FIX; + VP8kUToG[i] = -22014 * (i - 128) + YUV_HALF; + VP8kVToG[i] = -45773 * (i - 128); + VP8kUToB[i] = (113618 * (i - 128) + YUV_HALF) >> YUV_FIX; + } + for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) { + const int k = ((i - 16) * 76283 + YUV_HALF) >> YUV_FIX; + VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255); + VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15); + } +#else + for (i = 0; i < 256; ++i) { + VP8kVToR[i] = (91881 * (i - 128) + YUV_HALF) >> YUV_FIX; + VP8kUToG[i] = -22554 * (i - 128) + YUV_HALF; + VP8kVToG[i] = -46802 * (i - 128); + VP8kUToB[i] = (116130 * (i - 128) + YUV_HALF) >> YUV_FIX; + } + for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) { + const int k = i; + VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255); + VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15); + } +#endif + + done = 1; +} + +#else + +WEBP_TSAN_IGNORE_FUNCTION void VP8YUVInit(void) {} + +#endif // WEBP_YUV_USE_TABLE + +//----------------------------------------------------------------------------- +// Plain-C version + +#define ROW_FUNC(FUNC_NAME, FUNC, XSTEP) \ +static void FUNC_NAME(const uint8_t* y, \ + const uint8_t* u, const uint8_t* v, \ + uint8_t* dst, int len) { \ + const uint8_t* const end = dst + (len & ~1) * XSTEP; \ + while (dst != end) { \ + FUNC(y[0], u[0], v[0], dst); \ + FUNC(y[1], u[0], v[0], dst + XSTEP); \ + y += 2; \ + ++u; \ + ++v; \ + dst += 2 * XSTEP; \ + } \ + if (len & 1) { \ + FUNC(y[0], u[0], v[0], dst); \ + } \ +} \ + +// All variants implemented. +ROW_FUNC(YuvToRgbRow, VP8YuvToRgb, 3) +ROW_FUNC(YuvToBgrRow, VP8YuvToBgr, 3) +ROW_FUNC(YuvToRgbaRow, VP8YuvToRgba, 4) +ROW_FUNC(YuvToBgraRow, VP8YuvToBgra, 4) +ROW_FUNC(YuvToArgbRow, VP8YuvToArgb, 4) +ROW_FUNC(YuvToRgba4444Row, VP8YuvToRgba4444, 2) +ROW_FUNC(YuvToRgb565Row, VP8YuvToRgb565, 2) + +#undef ROW_FUNC + +// Main call for processing a plane with a WebPSamplerRowFunc function: +void WebPSamplerProcessPlane(const uint8_t* y, int y_stride, + const uint8_t* u, const uint8_t* v, int uv_stride, + uint8_t* dst, int dst_stride, + int width, int height, WebPSamplerRowFunc func) { + int j; + for (j = 0; j < height; ++j) { + func(y, u, v, dst, width); + y += y_stride; + if (j & 1) { + u += uv_stride; + v += uv_stride; + } + dst += dst_stride; + } +} + +//----------------------------------------------------------------------------- +// Main call + +WebPSamplerRowFunc WebPSamplers[MODE_LAST]; + +extern void WebPInitSamplersSSE2(void); +extern void WebPInitSamplersMIPS32(void); +extern void WebPInitSamplersMIPSdspR2(void); + +static volatile VP8CPUInfo yuv_last_cpuinfo_used = + (VP8CPUInfo)&yuv_last_cpuinfo_used; + +WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplers(void) { + if (yuv_last_cpuinfo_used == VP8GetCPUInfo) return; + + WebPSamplers[MODE_RGB] = YuvToRgbRow; + WebPSamplers[MODE_RGBA] = YuvToRgbaRow; + WebPSamplers[MODE_BGR] = YuvToBgrRow; + WebPSamplers[MODE_BGRA] = YuvToBgraRow; + WebPSamplers[MODE_ARGB] = YuvToArgbRow; + WebPSamplers[MODE_RGBA_4444] = YuvToRgba4444Row; + WebPSamplers[MODE_RGB_565] = YuvToRgb565Row; + WebPSamplers[MODE_rgbA] = YuvToRgbaRow; + WebPSamplers[MODE_bgrA] = YuvToBgraRow; + WebPSamplers[MODE_Argb] = YuvToArgbRow; + WebPSamplers[MODE_rgbA_4444] = YuvToRgba4444Row; + + // If defined, use CPUInfo() to overwrite some pointers with faster versions. + if (VP8GetCPUInfo != NULL) { +#if defined(WEBP_USE_SSE2) + if (VP8GetCPUInfo(kSSE2)) { + WebPInitSamplersSSE2(); + } +#endif // WEBP_USE_SSE2 +#if defined(WEBP_USE_MIPS32) + if (VP8GetCPUInfo(kMIPS32)) { + WebPInitSamplersMIPS32(); + } +#endif // WEBP_USE_MIPS32 +#if defined(WEBP_USE_MIPS_DSP_R2) + if (VP8GetCPUInfo(kMIPSdspR2)) { + WebPInitSamplersMIPSdspR2(); + } +#endif // WEBP_USE_MIPS_DSP_R2 + } + yuv_last_cpuinfo_used = VP8GetCPUInfo; +} + +//----------------------------------------------------------------------------- diff --git a/components/thorvg-main/src/loaders/webp/dsp/yuv.h b/components/thorvg-main/src/loaders/webp/dsp/yuv.h new file mode 100644 index 0000000..8a47edd --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/dsp/yuv.h @@ -0,0 +1,321 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// inline YUV<->RGB conversion function +// +// The exact naming is Y'CbCr, following the ITU-R BT.601 standard. +// More information at: http://en.wikipedia.org/wiki/YCbCr +// Y = 0.2569 * R + 0.5044 * G + 0.0979 * B + 16 +// U = -0.1483 * R - 0.2911 * G + 0.4394 * B + 128 +// V = 0.4394 * R - 0.3679 * G - 0.0715 * B + 128 +// We use 16bit fixed point operations for RGB->YUV conversion (YUV_FIX). +// +// For the Y'CbCr to RGB conversion, the BT.601 specification reads: +// R = 1.164 * (Y-16) + 1.596 * (V-128) +// G = 1.164 * (Y-16) - 0.813 * (V-128) - 0.391 * (U-128) +// B = 1.164 * (Y-16) + 2.018 * (U-128) +// where Y is in the [16,235] range, and U/V in the [16,240] range. +// In the table-lookup version (WEBP_YUV_USE_TABLE), the common factor +// "1.164 * (Y-16)" can be handled as an offset in the VP8kClip[] table. +// So in this case the formulae should read: +// R = 1.164 * [Y + 1.371 * (V-128) ] - 18.624 +// G = 1.164 * [Y - 0.698 * (V-128) - 0.336 * (U-128)] - 18.624 +// B = 1.164 * [Y + 1.733 * (U-128)] - 18.624 +// once factorized. +// For YUV->RGB conversion, only 14bit fixed precision is used (YUV_FIX2). +// That's the maximum possible for a convenient ARM implementation. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_DSP_YUV_H_ +#define WEBP_DSP_YUV_H_ + +#include "./dsp.h" +#include "../dec/decode_vp8.h" + +// Define the following to use the LUT-based code: +// #define WEBP_YUV_USE_TABLE + +#if defined(WEBP_EXPERIMENTAL_FEATURES) +// Do NOT activate this feature for real compression. This is only experimental! +// This flag is for comparison purpose against JPEG's "YUVj" natural colorspace. +// This colorspace is close to Rec.601's Y'CbCr model with the notable +// difference of allowing larger range for luma/chroma. +// See http://en.wikipedia.org/wiki/YCbCr#JPEG_conversion paragraph, and its +// difference with http://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion +// #define USE_YUVj +#endif + +//------------------------------------------------------------------------------ +// YUV -> RGB conversion + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + YUV_FIX = 16, // fixed-point precision for RGB->YUV + YUV_HALF = 1 << (YUV_FIX - 1), + YUV_MASK = (256 << YUV_FIX) - 1, + YUV_RANGE_MIN = -227, // min value of r/g/b output + YUV_RANGE_MAX = 256 + 226, // max value of r/g/b output + + YUV_FIX2 = 14, // fixed-point precision for YUV->RGB + YUV_HALF2 = 1 << (YUV_FIX2 - 1), + YUV_MASK2 = (256 << YUV_FIX2) - 1 +}; + +// These constants are 14b fixed-point version of ITU-R BT.601 constants. +#define kYScale 19077 // 1.164 = 255 / 219 +#define kVToR 26149 // 1.596 = 255 / 112 * 0.701 +#define kUToG 6419 // 0.391 = 255 / 112 * 0.886 * 0.114 / 0.587 +#define kVToG 13320 // 0.813 = 255 / 112 * 0.701 * 0.299 / 0.587 +#define kUToB 33050 // 2.018 = 255 / 112 * 0.886 +#define kRCst (-kYScale * 16 - kVToR * 128 + YUV_HALF2) +#define kGCst (-kYScale * 16 + kUToG * 128 + kVToG * 128 + YUV_HALF2) +#define kBCst (-kYScale * 16 - kUToB * 128 + YUV_HALF2) + +//------------------------------------------------------------------------------ + +#if !defined(WEBP_YUV_USE_TABLE) + +// slower on x86 by ~7-8%, but bit-exact with the SSE2 version + +static WEBP_INLINE int VP8Clip8(int v) { + return ((v & ~YUV_MASK2) == 0) ? (v >> YUV_FIX2) : (v < 0) ? 0 : 255; +} + +static WEBP_INLINE int VP8YUVToR(int y, int v) { + return VP8Clip8(kYScale * y + kVToR * v + kRCst); +} + +static WEBP_INLINE int VP8YUVToG(int y, int u, int v) { + return VP8Clip8(kYScale * y - kUToG * u - kVToG * v + kGCst); +} + +static WEBP_INLINE int VP8YUVToB(int y, int u) { + return VP8Clip8(kYScale * y + kUToB * u + kBCst); +} + +static WEBP_INLINE void VP8YuvToRgb(int y, int u, int v, + uint8_t* const rgb) { + rgb[0] = VP8YUVToR(y, v); + rgb[1] = VP8YUVToG(y, u, v); + rgb[2] = VP8YUVToB(y, u); +} + +static WEBP_INLINE void VP8YuvToBgr(int y, int u, int v, + uint8_t* const bgr) { + bgr[0] = VP8YUVToB(y, u); + bgr[1] = VP8YUVToG(y, u, v); + bgr[2] = VP8YUVToR(y, v); +} + +static WEBP_INLINE void VP8YuvToRgb565(int y, int u, int v, + uint8_t* const rgb) { + const int r = VP8YUVToR(y, v); // 5 usable bits + const int g = VP8YUVToG(y, u, v); // 6 usable bits + const int b = VP8YUVToB(y, u); // 5 usable bits + const int rg = (r & 0xf8) | (g >> 5); + const int gb = ((g << 3) & 0xe0) | (b >> 3); +#ifdef WEBP_SWAP_16BIT_CSP + rgb[0] = gb; + rgb[1] = rg; +#else + rgb[0] = rg; + rgb[1] = gb; +#endif +} + +static WEBP_INLINE void VP8YuvToRgba4444(int y, int u, int v, + uint8_t* const argb) { + const int r = VP8YUVToR(y, v); // 4 usable bits + const int g = VP8YUVToG(y, u, v); // 4 usable bits + const int b = VP8YUVToB(y, u); // 4 usable bits + const int rg = (r & 0xf0) | (g >> 4); + const int ba = (b & 0xf0) | 0x0f; // overwrite the lower 4 bits +#ifdef WEBP_SWAP_16BIT_CSP + argb[0] = ba; + argb[1] = rg; +#else + argb[0] = rg; + argb[1] = ba; +#endif +} + +#else + +// Table-based version, not totally equivalent to the SSE2 version. +// Rounding diff is only +/-1 though. + +extern int16_t VP8kVToR[256], VP8kUToB[256]; +extern int32_t VP8kVToG[256], VP8kUToG[256]; +extern uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN]; +extern uint8_t VP8kClip4Bits[YUV_RANGE_MAX - YUV_RANGE_MIN]; + +static WEBP_INLINE void VP8YuvToRgb(int y, int u, int v, + uint8_t* const rgb) { + const int r_off = VP8kVToR[v]; + const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX; + const int b_off = VP8kUToB[u]; + rgb[0] = VP8kClip[y + r_off - YUV_RANGE_MIN]; + rgb[1] = VP8kClip[y + g_off - YUV_RANGE_MIN]; + rgb[2] = VP8kClip[y + b_off - YUV_RANGE_MIN]; +} + +static WEBP_INLINE void VP8YuvToBgr(int y, int u, int v, + uint8_t* const bgr) { + const int r_off = VP8kVToR[v]; + const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX; + const int b_off = VP8kUToB[u]; + bgr[0] = VP8kClip[y + b_off - YUV_RANGE_MIN]; + bgr[1] = VP8kClip[y + g_off - YUV_RANGE_MIN]; + bgr[2] = VP8kClip[y + r_off - YUV_RANGE_MIN]; +} + +static WEBP_INLINE void VP8YuvToRgb565(int y, int u, int v, + uint8_t* const rgb) { + const int r_off = VP8kVToR[v]; + const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX; + const int b_off = VP8kUToB[u]; + const int rg = ((VP8kClip[y + r_off - YUV_RANGE_MIN] & 0xf8) | + (VP8kClip[y + g_off - YUV_RANGE_MIN] >> 5)); + const int gb = (((VP8kClip[y + g_off - YUV_RANGE_MIN] << 3) & 0xe0) | + (VP8kClip[y + b_off - YUV_RANGE_MIN] >> 3)); +#ifdef WEBP_SWAP_16BIT_CSP + rgb[0] = gb; + rgb[1] = rg; +#else + rgb[0] = rg; + rgb[1] = gb; +#endif +} + +static WEBP_INLINE void VP8YuvToRgba4444(int y, int u, int v, + uint8_t* const argb) { + const int r_off = VP8kVToR[v]; + const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX; + const int b_off = VP8kUToB[u]; + const int rg = ((VP8kClip4Bits[y + r_off - YUV_RANGE_MIN] << 4) | + VP8kClip4Bits[y + g_off - YUV_RANGE_MIN]); + const int ba = (VP8kClip4Bits[y + b_off - YUV_RANGE_MIN] << 4) | 0x0f; +#ifdef WEBP_SWAP_16BIT_CSP + argb[0] = ba; + argb[1] = rg; +#else + argb[0] = rg; + argb[1] = ba; +#endif +} + +#endif // WEBP_YUV_USE_TABLE + +//----------------------------------------------------------------------------- +// Alpha handling variants + +static WEBP_INLINE void VP8YuvToArgb(uint8_t y, uint8_t u, uint8_t v, + uint8_t* const argb) { + argb[0] = 0xff; + VP8YuvToRgb(y, u, v, argb + 1); +} + +static WEBP_INLINE void VP8YuvToBgra(uint8_t y, uint8_t u, uint8_t v, + uint8_t* const bgra) { + VP8YuvToBgr(y, u, v, bgra); + bgra[3] = 0xff; +} + +static WEBP_INLINE void VP8YuvToRgba(uint8_t y, uint8_t u, uint8_t v, + uint8_t* const rgba) { + VP8YuvToRgb(y, u, v, rgba); + rgba[3] = 0xff; +} + +// Must be called before everything, to initialize the tables. +void VP8YUVInit(void); + +//----------------------------------------------------------------------------- +// SSE2 extra functions (mostly for upsampling_sse2.c) + +#if defined(WEBP_USE_SSE2) + +// When the following is defined, tables are initialized statically, adding ~12k +// to the binary size. Otherwise, they are initialized at run-time (small cost). +#define WEBP_YUV_USE_SSE2_TABLES + +#if defined(FANCY_UPSAMPLING) +// Process 32 pixels and store the result (24b or 32b per pixel) in *dst. +void VP8YuvToRgba32(const uint8_t* y, const uint8_t* u, const uint8_t* v, + uint8_t* dst); +void VP8YuvToRgb32(const uint8_t* y, const uint8_t* u, const uint8_t* v, + uint8_t* dst); +void VP8YuvToBgra32(const uint8_t* y, const uint8_t* u, const uint8_t* v, + uint8_t* dst); +void VP8YuvToBgr32(const uint8_t* y, const uint8_t* u, const uint8_t* v, + uint8_t* dst); +#endif // FANCY_UPSAMPLING + +// Must be called to initialize tables before using the functions. +void VP8YUVInitSSE2(void); + +#endif // WEBP_USE_SSE2 + +//------------------------------------------------------------------------------ +// RGB -> YUV conversion + +// Stub functions that can be called with various rounding values: +static WEBP_INLINE int VP8ClipUV(int uv, int rounding) { + uv = (uv + rounding + (128 << (YUV_FIX + 2))) >> (YUV_FIX + 2); + return ((uv & ~0xff) == 0) ? uv : (uv < 0) ? 0 : 255; +} + +#ifndef USE_YUVj + +static WEBP_INLINE int VP8RGBToY(int r, int g, int b, int rounding) { + const int luma = 16839 * r + 33059 * g + 6420 * b; + return (luma + rounding + (16 << YUV_FIX)) >> YUV_FIX; // no need to clip +} + +static WEBP_INLINE int VP8RGBToU(int r, int g, int b, int rounding) { + const int u = -9719 * r - 19081 * g + 28800 * b; + return VP8ClipUV(u, rounding); +} + +static WEBP_INLINE int VP8RGBToV(int r, int g, int b, int rounding) { + const int v = +28800 * r - 24116 * g - 4684 * b; + return VP8ClipUV(v, rounding); +} + +#else + +// This JPEG-YUV colorspace, only for comparison! +// These are also 16bit precision coefficients from Rec.601, but with full +// [0..255] output range. +static WEBP_INLINE int VP8RGBToY(int r, int g, int b, int rounding) { + const int luma = 19595 * r + 38470 * g + 7471 * b; + return (luma + rounding) >> YUV_FIX; // no need to clip +} + +static WEBP_INLINE int VP8RGBToU(int r, int g, int b, int rounding) { + const int u = -11058 * r - 21710 * g + 32768 * b; + return VP8ClipUV(u, rounding); +} + +static WEBP_INLINE int VP8RGBToV(int r, int g, int b, int rounding) { + const int v = 32768 * r - 27439 * g - 5329 * b; + return VP8ClipUV(v, rounding); +} + +#endif // USE_YUVj + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_DSP_YUV_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/meson.build b/components/thorvg-main/src/loaders/webp/meson.build new file mode 100644 index 0000000..5b069da --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/meson.build @@ -0,0 +1,17 @@ +webp_deb = [] + +subdir('dec') +subdir('dsp') +subdir('utils') +subdir('webp') + +source_file = [ + 'tvgWebpLoader.h', + 'tvgWebpLoader.cpp', +] + +subloader_dep += [declare_dependency( + include_directories : include_directories('.'), + dependencies : webp_deb, + sources : source_file + )] diff --git a/components/thorvg-main/src/loaders/webp/tvgWebpLoader.cpp b/components/thorvg-main/src/loaders/webp/tvgWebpLoader.cpp new file mode 100644 index 0000000..b87a099 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/tvgWebpLoader.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "webp/decode.h" +#include "tvgWebpLoader.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void WebpLoader::clear() +{ + if (freeData) tvg::free(data); + data = nullptr; + freeData = false; +} + + +void WebpLoader::run(unsigned tid) +{ + if (surface.cs == ColorSpace::ARGB8888 || surface.cs == ColorSpace::ARGB8888S) { + surface.buf8 = WebPDecodeBGRA(data, size, nullptr, nullptr); + surface.cs = ColorSpace::ARGB8888; + } else { + surface.buf8 = WebPDecodeRGBA(data, size, nullptr, nullptr); + surface.cs = ColorSpace::ABGR8888; + } + + surface.stride = static_cast(w); + surface.w = static_cast(w); + surface.h = static_cast(h); + surface.channelSize = sizeof(uint32_t); + surface.premultiplied = true; + + clear(); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +WebpLoader::WebpLoader() : ImageLoader(FileType::Webp) +{ +} + + +WebpLoader::~WebpLoader() +{ + done(); + clear(); + tvg::free(surface.buf8); +} + + +bool WebpLoader::open(const char* path) +{ +#ifdef THORVG_FILE_IO_SUPPORT + if (!(data = (uint8_t*)LoadModule::open(path, size))) return false; + + int width, height; + if (!WebPGetInfo(data, size, &width, &height)) return false; + w = static_cast(width); + h = static_cast(height); + freeData = true; + return true; +#else + return false; +#endif +} + + +bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy) +{ + if (copy) { + this->data = tvg::malloc(size); + if (!this->data) return false; + memcpy((uint8_t*)this->data, data, size); + freeData = true; + } else { + this->data = (uint8_t*) data; + freeData = false; + } + + int width, height; + if (!WebPGetInfo(this->data, size, &width, &height)) return false; + + w = static_cast(width); + h = static_cast(height); + this->size = size; + + return true; +} + + +bool WebpLoader::read() +{ + if (!LoadModule::read()) return true; + + if (!data || w == 0 || h == 0) return false; + + surface.cs = ImageLoader::cs; + + TaskScheduler::request(this); + + return true; +} + + +bool WebpLoader::close() +{ + if (!LoadModule::close()) return false; + this->done(); + return true; +} + + +RenderSurface* WebpLoader::bitmap() +{ + this->done(); + + return ImageLoader::bitmap(); +} \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/webp/tvgWebpLoader.h b/components/thorvg-main/src/loaders/webp/tvgWebpLoader.h new file mode 100644 index 0000000..305fa15 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/tvgWebpLoader.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WEBP_LOADER_H_ +#define _TVG_WEBP_LOADER_H_ + +#include "tvgLoader.h" +#include "tvgTaskScheduler.h" + +class WebpLoader : public ImageLoader, public Task +{ +private: + uint8_t* data = nullptr; + uint32_t size = 0; + bool freeData = false; + + void clear(); + void run(unsigned tid) override; + +public: + WebpLoader(); + ~WebpLoader(); + + bool open(const char* path) override; + bool open(const char* data, uint32_t size, const char* rpath, bool copy) override; + bool read() override; + bool close() override; + + RenderSurface* bitmap() override; +}; + +#endif //_TVG_WEBP_LOADER_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/webp/utils/bit_reader.cpp b/components/thorvg-main/src/loaders/webp/utils/bit_reader.cpp new file mode 100644 index 0000000..84c5c46 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/bit_reader.cpp @@ -0,0 +1,216 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Boolean decoder non-inlined methods +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifdef HAVE_CONFIG_H +#include "../webp/config.h" +#endif + +#include "./bit_reader_inl.h" +#include "./utils.h" + +//------------------------------------------------------------------------------ +// VP8BitReader + +void VP8InitBitReader(VP8BitReader* const br, + const uint8_t* const start, const uint8_t* const end) { + assert(br != NULL); + assert(start != NULL); + assert(start <= end); + br->range_ = 255 - 1; + br->buf_ = start; + br->buf_end_ = end; + br->value_ = 0; + br->bits_ = -8; // to load the very first 8bits + br->eof_ = 0; + VP8LoadNewBytes(br); +} + +void VP8RemapBitReader(VP8BitReader* const br, ptrdiff_t offset) { + if (br->buf_ != NULL) { + br->buf_ += offset; + br->buf_end_ += offset; + } +} + +const uint8_t kVP8Log2Range[128] = { + 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0 +}; + +// range = ((range - 1) << kVP8Log2Range[range]) + 1 +const uint8_t kVP8NewRange[128] = { + 127, 127, 191, 127, 159, 191, 223, 127, + 143, 159, 175, 191, 207, 223, 239, 127, + 135, 143, 151, 159, 167, 175, 183, 191, + 199, 207, 215, 223, 231, 239, 247, 127, + 131, 135, 139, 143, 147, 151, 155, 159, + 163, 167, 171, 175, 179, 183, 187, 191, + 195, 199, 203, 207, 211, 215, 219, 223, + 227, 231, 235, 239, 243, 247, 251, 127, + 129, 131, 133, 135, 137, 139, 141, 143, + 145, 147, 149, 151, 153, 155, 157, 159, + 161, 163, 165, 167, 169, 171, 173, 175, + 177, 179, 181, 183, 185, 187, 189, 191, + 193, 195, 197, 199, 201, 203, 205, 207, + 209, 211, 213, 215, 217, 219, 221, 223, + 225, 227, 229, 231, 233, 235, 237, 239, + 241, 243, 245, 247, 249, 251, 253, 127 +}; + +void VP8LoadFinalBytes(VP8BitReader* const br) { + assert(br != NULL && br->buf_ != NULL); + // Only read 8bits at a time + if (br->buf_ < br->buf_end_) { + br->bits_ += 8; + br->value_ = (bit_t)(*br->buf_++) | (br->value_ << 8); + } else if (!br->eof_) { + br->value_ <<= 8; + br->bits_ += 8; + br->eof_ = 1; + } else { + br->bits_ = 0; // This is to avoid undefined behaviour with shifts. + } +} + +//------------------------------------------------------------------------------ +// Higher-level calls + +uint32_t VP8GetValue(VP8BitReader* const br, int bits) { + uint32_t v = 0; + while (bits-- > 0) { + v |= VP8GetBit(br, 0x80) << bits; + } + return v; +} + +int32_t VP8GetSignedValue(VP8BitReader* const br, int bits) { + const int value = VP8GetValue(br, bits); + return VP8Get(br) ? -value : value; +} + +//------------------------------------------------------------------------------ +// VP8LBitReader + +#define VP8L_LOG8_WBITS 4 // Number of bytes needed to store VP8L_WBITS bits. + +#if (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || \ + defined(__i386__) || defined(_M_IX86) || \ + defined(__x86_64__) || defined(_M_X64)) +#define VP8L_USE_FAST_LOAD +#endif + +static const uint32_t kBitMask[VP8L_MAX_NUM_BIT_READ + 1] = { + 0, + 0x000001, 0x000003, 0x000007, 0x00000f, + 0x00001f, 0x00003f, 0x00007f, 0x0000ff, + 0x0001ff, 0x0003ff, 0x0007ff, 0x000fff, + 0x001fff, 0x003fff, 0x007fff, 0x00ffff, + 0x01ffff, 0x03ffff, 0x07ffff, 0x0fffff, + 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff +}; + +void VP8LInitBitReader(VP8LBitReader* const br, const uint8_t* const start, + size_t length) { + size_t i; + vp8l_val_t value = 0; + assert(br != NULL); + assert(start != NULL); + assert(length < 0xfffffff8u); // can't happen with a RIFF chunk. + + br->len_ = length; + br->val_ = 0; + br->bit_pos_ = 0; + br->eos_ = 0; + + if (length > sizeof(br->val_)) { + length = sizeof(br->val_); + } + for (i = 0; i < length; ++i) { + value |= (vp8l_val_t)start[i] << (8 * i); + } + br->val_ = value; + br->pos_ = length; + br->buf_ = start; +} + +void VP8LBitReaderSetBuffer(VP8LBitReader* const br, + const uint8_t* const buf, size_t len) { + assert(br != NULL); + assert(buf != NULL); + assert(len < 0xfffffff8u); // can't happen with a RIFF chunk. + br->buf_ = buf; + br->len_ = len; + // pos_ > len_ should be considered a param error. + br->eos_ = (br->pos_ > br->len_) || VP8LIsEndOfStream(br); +} + +static void VP8LSetEndOfStream(VP8LBitReader* const br) { + br->eos_ = 1; + br->bit_pos_ = 0; // To avoid undefined behaviour with shifts. +} + +// If not at EOS, reload up to VP8L_LBITS byte-by-byte +static void ShiftBytes(VP8LBitReader* const br) { + while (br->bit_pos_ >= 8 && br->pos_ < br->len_) { + br->val_ >>= 8; + br->val_ |= ((vp8l_val_t)br->buf_[br->pos_]) << (VP8L_LBITS - 8); + ++br->pos_; + br->bit_pos_ -= 8; + } + if (VP8LIsEndOfStream(br)) { + VP8LSetEndOfStream(br); + } +} + +void VP8LDoFillBitWindow(VP8LBitReader* const br) { + assert(br->bit_pos_ >= VP8L_WBITS); + // TODO(jzern): given the fixed read size it may be possible to force + // alignment in this block. +#if defined(VP8L_USE_FAST_LOAD) + if (br->pos_ + sizeof(br->val_) < br->len_) { + br->val_ >>= VP8L_WBITS; + br->bit_pos_ -= VP8L_WBITS; + // The expression below needs a little-endian arch to work correctly. + // This gives a large speedup for decoding speed. + br->val_ |= (vp8l_val_t)HToLE32(WebPMemToUint32(br->buf_ + br->pos_)) << + (VP8L_LBITS - VP8L_WBITS); + br->pos_ += VP8L_LOG8_WBITS; + return; + } +#endif + ShiftBytes(br); // Slow path. +} + +uint32_t VP8LReadBits(VP8LBitReader* const br, int n_bits) { + assert(n_bits >= 0); + // Flag an error if end_of_stream or n_bits is more than allowed limit. + if (!br->eos_ && n_bits <= VP8L_MAX_NUM_BIT_READ) { + const uint32_t val = VP8LPrefetchBits(br) & kBitMask[n_bits]; + const int new_bits = br->bit_pos_ + n_bits; + br->bit_pos_ = new_bits; + ShiftBytes(br); + return val; + } else { + VP8LSetEndOfStream(br); + return 0; + } +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/utils/bit_reader.h b/components/thorvg-main/src/loaders/webp/utils/bit_reader.h new file mode 100644 index 0000000..4ebbe53 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/bit_reader.h @@ -0,0 +1,168 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Boolean decoder +// +// Author: Skal (pascal.massimino@gmail.com) +// Vikas Arora (vikaas.arora@gmail.com) + +#ifndef WEBP_UTILS_BIT_READER_H_ +#define WEBP_UTILS_BIT_READER_H_ + +#include +#ifdef _MSC_VER +#include // _byteswap_ulong +#endif +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// The Boolean decoder needs to maintain infinite precision on the value_ field. +// However, since range_ is only 8bit, we only need an active window of 8 bits +// for value_. Left bits (MSB) gets zeroed and shifted away when value_ falls +// below 128, range_ is updated, and fresh bits read from the bitstream are +// brought in as LSB. To avoid reading the fresh bits one by one (slow), we +// cache BITS of them ahead. The total of (BITS + 8) bits must fit into a +// natural register (with type bit_t). To fetch BITS bits from bitstream we +// use a type lbit_t. +// +// BITS can be any multiple of 8 from 8 to 56 (inclusive). +// Pick values that fit natural register size. + +#if defined(__i386__) || defined(_M_IX86) // x86 32bit +#define BITS 24 +#elif defined(__x86_64__) || defined(_M_X64) // x86 64bit +#define BITS 56 +#elif defined(__arm__) || defined(_M_ARM) // ARM +#define BITS 24 +#elif defined(__mips__) // MIPS +#define BITS 24 +#else // reasonable default +#define BITS 24 // TODO(skal): test aarch64 and find the proper BITS value. +#endif + +//------------------------------------------------------------------------------ +// Derived types and constants: +// bit_t = natural register type for storing 'value_' (which is BITS+8 bits) +// range_t = register for 'range_' (which is 8bits only) + +#if (BITS > 24) +typedef uint64_t bit_t; +#else +typedef uint32_t bit_t; +#endif + +typedef uint32_t range_t; + +//------------------------------------------------------------------------------ +// Bitreader + +typedef struct VP8BitReader VP8BitReader; +struct VP8BitReader { + // boolean decoder (keep the field ordering as is!) + bit_t value_; // current value + range_t range_; // current range minus 1. In [127, 254] interval. + int bits_; // number of valid bits left + // read buffer + const uint8_t* buf_; // next byte to be read + const uint8_t* buf_end_; // end of read buffer + int eof_; // true if input is exhausted +}; + +// Initialize the bit reader and the boolean decoder. +void VP8InitBitReader(VP8BitReader* const br, + const uint8_t* const start, const uint8_t* const end); + +// Update internal pointers to displace the byte buffer by the +// relative offset 'offset'. +void VP8RemapBitReader(VP8BitReader* const br, ptrdiff_t offset); + +// return the next value made of 'num_bits' bits +uint32_t VP8GetValue(VP8BitReader* const br, int num_bits); +static WEBP_INLINE uint32_t VP8Get(VP8BitReader* const br) { + return VP8GetValue(br, 1); +} + +// return the next value with sign-extension. +int32_t VP8GetSignedValue(VP8BitReader* const br, int num_bits); + +// bit_reader_inl.h will implement the following methods: +// static WEBP_INLINE int VP8GetBit(VP8BitReader* const br, int prob) +// static WEBP_INLINE int VP8GetSigned(VP8BitReader* const br, int v) +// and should be included by the .c files that actually need them. +// This is to avoid recompiling the whole library whenever this file is touched, +// and also allowing platform-specific ad-hoc hacks. + +// ----------------------------------------------------------------------------- +// Bitreader for lossless format + +// maximum number of bits (inclusive) the bit-reader can handle: +#define VP8L_MAX_NUM_BIT_READ 24 + +#define VP8L_LBITS 64 // Number of bits prefetched (= bit-size of vp8l_val_t). +#define VP8L_WBITS 32 // Minimum number of bytes ready after VP8LFillBitWindow. + +typedef uint64_t vp8l_val_t; // right now, this bit-reader can only use 64bit. + +typedef struct { + vp8l_val_t val_; // pre-fetched bits + const uint8_t* buf_; // input byte buffer + size_t len_; // buffer length + size_t pos_; // byte position in buf_ + int bit_pos_; // current bit-reading position in val_ + int eos_; // true if a bit was read past the end of buffer +} VP8LBitReader; + +void VP8LInitBitReader(VP8LBitReader* const br, + const uint8_t* const start, + size_t length); + +// Sets a new data buffer. +void VP8LBitReaderSetBuffer(VP8LBitReader* const br, + const uint8_t* const buffer, size_t length); + +// Reads the specified number of bits from read buffer. +// Flags an error in case end_of_stream or n_bits is more than the allowed limit +// of VP8L_MAX_NUM_BIT_READ (inclusive). +// Flags eos_ if this read attempt is going to cross the read buffer. +uint32_t VP8LReadBits(VP8LBitReader* const br, int n_bits); + +// Return the prefetched bits, so they can be looked up. +static WEBP_INLINE uint32_t VP8LPrefetchBits(VP8LBitReader* const br) { + return (uint32_t)(br->val_ >> (br->bit_pos_ & (VP8L_LBITS - 1))); +} + +// Returns true if there was an attempt at reading bit past the end of +// the buffer. Doesn't set br->eos_ flag. +static WEBP_INLINE int VP8LIsEndOfStream(const VP8LBitReader* const br) { + assert(br->pos_ <= br->len_); + return br->eos_ || ((br->pos_ == br->len_) && (br->bit_pos_ > VP8L_LBITS)); +} + +// For jumping over a number of bits in the bit stream when accessed with +// VP8LPrefetchBits and VP8LFillBitWindow. +static WEBP_INLINE void VP8LSetBitPos(VP8LBitReader* const br, int val) { + br->bit_pos_ = val; + br->eos_ = VP8LIsEndOfStream(br); +} + +// Advances the read buffer by 4 bytes to make room for reading next 32 bits. +// Speed critical, but infrequent part of the code can be non-inlined. +extern void VP8LDoFillBitWindow(VP8LBitReader* const br); +static WEBP_INLINE void VP8LFillBitWindow(VP8LBitReader* const br) { + if (br->bit_pos_ >= VP8L_WBITS) VP8LDoFillBitWindow(br); +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_UTILS_BIT_READER_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/utils/bit_reader_inl.h b/components/thorvg-main/src/loaders/webp/utils/bit_reader_inl.h new file mode 100644 index 0000000..aa31711 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/bit_reader_inl.h @@ -0,0 +1,168 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Specific inlined methods for boolean decoder [VP8GetBit() ...] +// This file should be included by the .c sources that actually need to call +// these methods. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_UTILS_BIT_READER_INL_H_ +#define WEBP_UTILS_BIT_READER_INL_H_ + +#ifdef HAVE_CONFIG_H +#include "../webp/config.h" +#endif + +#include // memcpy + +#include "../dsp/dsp.h" +#include "./bit_reader.h" +#include "./endian_inl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------------------------------------------------ +// Derived type lbit_t = natural type for memory I/O + +#if (BITS > 32) +typedef uint64_t lbit_t; +#elif (BITS > 16) +typedef uint32_t lbit_t; +#elif (BITS > 8) +typedef uint16_t lbit_t; +#else +typedef uint8_t lbit_t; +#endif + +extern const uint8_t kVP8Log2Range[128]; +extern const uint8_t kVP8NewRange[128]; + +// special case for the tail byte-reading +void VP8LoadFinalBytes(VP8BitReader* const br); + +//------------------------------------------------------------------------------ +// Inlined critical functions + +// makes sure br->value_ has at least BITS bits worth of data +static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) { + assert(br != NULL && br->buf_ != NULL); + // Read 'BITS' bits at a time if possible. + if (br->buf_ + sizeof(lbit_t) <= br->buf_end_) { + // convert memory type to register type (with some zero'ing!) + bit_t bits; +#if defined(WEBP_USE_MIPS32) + // This is needed because of un-aligned read. + lbit_t in_bits; + lbit_t* p_buf_ = (lbit_t*)br->buf_; + __asm__ volatile( + ".set push \n\t" + ".set at \n\t" + ".set macro \n\t" + "ulw %[in_bits], 0(%[p_buf_]) \n\t" + ".set pop \n\t" + : [in_bits]"=r"(in_bits) + : [p_buf_]"r"(p_buf_) + : "memory", "at" + ); +#else + lbit_t in_bits; + memcpy(&in_bits, br->buf_, sizeof(in_bits)); +#endif + br->buf_ += BITS >> 3; +#if !defined(WORDS_BIGENDIAN) +#if (BITS > 32) + bits = BSwap64(in_bits); + bits >>= 64 - BITS; +#elif (BITS >= 24) + bits = BSwap32(in_bits); + bits >>= (32 - BITS); +#elif (BITS == 16) + bits = BSwap16(in_bits); +#else // BITS == 8 + bits = (bit_t)in_bits; +#endif // BITS > 32 +#else // WORDS_BIGENDIAN + bits = (bit_t)in_bits; + if (BITS != 8 * sizeof(bit_t)) bits >>= (8 * sizeof(bit_t) - BITS); +#endif + br->value_ = bits | (br->value_ << BITS); + br->bits_ += BITS; + } else { + VP8LoadFinalBytes(br); // no need to be inlined + } +} + +// Read a bit with proba 'prob'. Speed-critical function! +static WEBP_INLINE int VP8GetBit(VP8BitReader* const br, int prob) { + // Don't move this declaration! It makes a big speed difference to store + // 'range' *before* calling VP8LoadNewBytes(), even if this function doesn't + // alter br->range_ value. + range_t range = br->range_; + if (br->bits_ < 0) { + VP8LoadNewBytes(br); + } + { + const int pos = br->bits_; + const range_t split = (range * prob) >> 8; + const range_t value = (range_t)(br->value_ >> pos); +#if defined(__arm__) || defined(_M_ARM) // ARM-specific + const int bit = ((int)(split - value) >> 31) & 1; + if (value > split) { + range -= split + 1; + br->value_ -= (bit_t)(split + 1) << pos; + } else { + range = split; + } +#else // faster version on x86 + int bit; // Don't use 'const int bit = (value > split);", it's slower. + if (value > split) { + range -= split + 1; + br->value_ -= (bit_t)(split + 1) << pos; + bit = 1; + } else { + range = split; + bit = 0; + } +#endif + if (range <= (range_t)0x7e) { + const int shift = kVP8Log2Range[range]; + range = kVP8NewRange[range]; + br->bits_ -= shift; + } + br->range_ = range; + return bit; + } +} + +// simplified version of VP8GetBit() for prob=0x80 (note shift is always 1 here) +static WEBP_INLINE int VP8GetSigned(VP8BitReader* const br, int v) { + if (br->bits_ < 0) { + VP8LoadNewBytes(br); + } + { + const int pos = br->bits_; + const range_t split = br->range_ >> 1; + const range_t value = (range_t)(br->value_ >> pos); + const int32_t mask = (int32_t)(split - value) >> 31; // -1 or 0 + br->bits_ -= 1; + br->range_ += mask; + br->range_ |= 1; + br->value_ -= (bit_t)((split + 1) & mask) << pos; + return (v ^ mask) - mask; + } +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_UTILS_BIT_READER_INL_H_ diff --git a/components/thorvg-main/src/loaders/webp/utils/color_cache.cpp b/components/thorvg-main/src/loaders/webp/utils/color_cache.cpp new file mode 100644 index 0000000..131cd12 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/color_cache.cpp @@ -0,0 +1,47 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Color Cache for WebP Lossless +// +// Author: Jyrki Alakuijala (jyrki@google.com) + +#include +#include "tvgCommon.h" +#include "./color_cache.h" +#include "../utils/utils.h" + +//------------------------------------------------------------------------------ +// VP8LColorCache. + +int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) { + const int hash_size = 1 << hash_bits; + assert(cc != NULL); + assert(hash_bits > 0); + cc->colors_ = tvg::calloc((uint64_t)hash_size, sizeof(*cc->colors_)); + if (cc->colors_ == NULL) return 0; + cc->hash_shift_ = 32 - hash_bits; + cc->hash_bits_ = hash_bits; + return 1; +} + +void VP8LColorCacheClear(VP8LColorCache* const cc) { + if (cc != NULL) { + tvg::free(cc->colors_); + cc->colors_ = NULL; + } +} + +void VP8LColorCacheCopy(const VP8LColorCache* const src, + VP8LColorCache* const dst) { + assert(src != NULL); + assert(dst != NULL); + assert(src->hash_bits_ == dst->hash_bits_); + memcpy(dst->colors_, src->colors_, + ((size_t)1u << dst->hash_bits_) * sizeof(*dst->colors_)); +} diff --git a/components/thorvg-main/src/loaders/webp/utils/color_cache.h b/components/thorvg-main/src/loaders/webp/utils/color_cache.h new file mode 100644 index 0000000..a1c4b3a --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/color_cache.h @@ -0,0 +1,74 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Color Cache for WebP Lossless +// +// Authors: Jyrki Alakuijala (jyrki@google.com) +// Urvang Joshi (urvang@google.com) + +#ifndef WEBP_UTILS_COLOR_CACHE_H_ +#define WEBP_UTILS_COLOR_CACHE_H_ + +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Main color cache struct. +typedef struct { + uint32_t *colors_; // color entries + int hash_shift_; // Hash shift: 32 - hash_bits_. + int hash_bits_; +} VP8LColorCache; + +static const uint32_t kHashMul = 0x1e35a7bd; + +static WEBP_INLINE uint32_t VP8LColorCacheLookup( + const VP8LColorCache* const cc, uint32_t key) { + assert(key <= (~0U >> cc->hash_shift_)); + return cc->colors_[key]; +} + +static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc, + uint32_t argb) { + const uint32_t key = (kHashMul * argb) >> cc->hash_shift_; + cc->colors_[key] = argb; +} + +static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc, + uint32_t argb) { + return (kHashMul * argb) >> cc->hash_shift_; +} + +static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc, + uint32_t argb) { + const uint32_t key = (kHashMul * argb) >> cc->hash_shift_; + return cc->colors_[key] == argb; +} + +//------------------------------------------------------------------------------ + +// Initializes the color cache with 'hash_bits' bits for the keys. +// Returns false in case of memory error. +int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits); + +void VP8LColorCacheCopy(const VP8LColorCache* const src, + VP8LColorCache* const dst); + +// Delete the memory associated to color cache. +void VP8LColorCacheClear(VP8LColorCache* const color_cache); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} +#endif + +#endif // WEBP_UTILS_COLOR_CACHE_H_ diff --git a/components/thorvg-main/src/loaders/webp/utils/endian_inl.h b/components/thorvg-main/src/loaders/webp/utils/endian_inl.h new file mode 100644 index 0000000..cd56c37 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/endian_inl.h @@ -0,0 +1,100 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Endian related functions. + +#ifndef WEBP_UTILS_ENDIAN_INL_H_ +#define WEBP_UTILS_ENDIAN_INL_H_ + +#ifdef HAVE_CONFIG_H +#include "../webp/config.h" +#endif + +#include "../dsp/dsp.h" +#include "../webp/types.h" + +// some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__) +#if !defined(WORDS_BIGENDIAN) && \ + (defined(__BIG_ENDIAN__) || defined(_M_PPC) || \ + (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) +#define WORDS_BIGENDIAN +#endif + +#if defined(WORDS_BIGENDIAN) +#define HToLE32 BSwap32 +#define HToLE16 BSwap16 +#else +#define HToLE32(x) (x) +#define HToLE16(x) (x) +#endif + +#if !defined(HAVE_CONFIG_H) +// clang-3.3 and gcc-4.3 have builtin functions for swap32/swap64 +#if LOCAL_GCC_PREREQ(4,3) || LOCAL_CLANG_PREREQ(3,3) +#define HAVE_BUILTIN_BSWAP32 +#define HAVE_BUILTIN_BSWAP64 +#endif +// clang-3.3 and gcc-4.8 have a builtin function for swap16 +#if LOCAL_GCC_PREREQ(4,8) || LOCAL_CLANG_PREREQ(3,3) +#define HAVE_BUILTIN_BSWAP16 +#endif +#endif // !HAVE_CONFIG_H + +static WEBP_INLINE uint16_t BSwap16(uint16_t x) { +#if defined(HAVE_BUILTIN_BSWAP16) + return __builtin_bswap16(x); +#elif defined(_MSC_VER) + return _byteswap_ushort(x); +#else + // gcc will recognize a 'rorw $8, ...' here: + return (x >> 8) | ((x & 0xff) << 8); +#endif // HAVE_BUILTIN_BSWAP16 +} + +static WEBP_INLINE uint32_t BSwap32(uint32_t x) { +#if defined(WEBP_USE_MIPS32_R2) + uint32_t ret; + __asm__ volatile ( + "wsbh %[ret], %[x] \n\t" + "rotr %[ret], %[ret], 16 \n\t" + : [ret]"=r"(ret) + : [x]"r"(x) + ); + return ret; +#elif defined(HAVE_BUILTIN_BSWAP32) + return __builtin_bswap32(x); +#elif defined(__i386__) || defined(__x86_64__) + uint32_t swapped_bytes; + __asm__ volatile("bswap %0" : "=r"(swapped_bytes) : "0"(x)); + return swapped_bytes; +#elif defined(_MSC_VER) + return (uint32_t)_byteswap_ulong(x); +#else + return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); +#endif // HAVE_BUILTIN_BSWAP32 +} + +static WEBP_INLINE uint64_t BSwap64(uint64_t x) { +#if defined(HAVE_BUILTIN_BSWAP64) + return __builtin_bswap64(x); +#elif defined(__x86_64__) + uint64_t swapped_bytes; + __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x)); + return swapped_bytes; +#elif defined(_MSC_VER) + return (uint64_t)_byteswap_uint64(x); +#else // generic code for swapping 64-bit values (suggested by bdb@) + x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); + x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); + x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); + return x; +#endif // HAVE_BUILTIN_BSWAP64 +} + +#endif // WEBP_UTILS_ENDIAN_INL_H_ diff --git a/components/thorvg-main/src/loaders/webp/utils/huffman.cpp b/components/thorvg-main/src/loaders/webp/utils/huffman.cpp new file mode 100644 index 0000000..da4b862 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/huffman.cpp @@ -0,0 +1,203 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Utilities for building and looking up Huffman trees. +// +// Author: Urvang Joshi (urvang@google.com) + +#include +#include "tvgCommon.h" +#include "./huffman.h" +#include "../utils/utils.h" +#include "../webp/format_constants.h" + +// Huffman data read via DecodeImageStream is represented in two (red and green) +// bytes. +#define MAX_HTREE_GROUPS 0x10000 + +HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups) { + HTreeGroup* const htree_groups = tvg::malloc(num_htree_groups * sizeof(*htree_groups)); + if (htree_groups == NULL) { + return NULL; + } + assert(num_htree_groups <= MAX_HTREE_GROUPS); + return htree_groups; +} + +void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups) { + if (htree_groups != NULL) { + tvg::free(htree_groups); + } +} + +// Returns reverse(reverse(key, len) + 1, len), where reverse(key, len) is the +// bit-wise reversal of the len least significant bits of key. +static WEBP_INLINE uint32_t GetNextKey(uint32_t key, int len) { + uint32_t step = 1 << (len - 1); + while (key & step) { + step >>= 1; + } + return (key & (step - 1)) + step; +} + +// Stores code in table[0], table[step], table[2*step], ..., table[end]. +// Assumes that end is an integer multiple of step. +static WEBP_INLINE void ReplicateValue(HuffmanCode* table, + int step, int end, + HuffmanCode code) { + assert(end % step == 0); + do { + end -= step; + table[end] = code; + } while (end > 0); +} + +// Returns the table width of the next 2nd level table. count is the histogram +// of bit lengths for the remaining symbols, len is the code length of the next +// processed symbol +static WEBP_INLINE int NextTableBitSize(const int* const count, + int len, int root_bits) { + int left = 1 << (len - root_bits); + while (len < MAX_ALLOWED_CODE_LENGTH) { + left -= count[len]; + if (left <= 0) break; + ++len; + left <<= 1; + } + return len - root_bits; +} + +int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits, + const int code_lengths[], int code_lengths_size) { + HuffmanCode* table = root_table; // next available space in table + int total_size = 1 << root_bits; // total size root table + 2nd level table + int* sorted = NULL; // symbols sorted by code length + int len; // current code length + int symbol; // symbol index in original or sorted table + // number of codes of each length: + int count[MAX_ALLOWED_CODE_LENGTH + 1] = { 0 }; + // offsets in sorted table for each length: + int offset[MAX_ALLOWED_CODE_LENGTH + 1]; + + assert(code_lengths_size != 0); + assert(code_lengths != NULL); + assert(root_table != NULL); + assert(root_bits > 0); + + // Build histogram of code lengths. + for (symbol = 0; symbol < code_lengths_size; ++symbol) { + if (code_lengths[symbol] > MAX_ALLOWED_CODE_LENGTH) { + return 0; + } + ++count[code_lengths[symbol]]; + } + + // Error, all code lengths are zeros. + if (count[0] == code_lengths_size) { + return 0; + } + + // Generate offsets into sorted symbol table by code length. + offset[1] = 0; + for (len = 1; len < MAX_ALLOWED_CODE_LENGTH; ++len) { + if (count[len] > (1 << len)) { + return 0; + } + offset[len + 1] = offset[len] + count[len]; + } + + sorted = tvg::malloc(code_lengths_size * sizeof(*sorted)); + if (sorted == NULL) { + return 0; + } + + // Sort symbols by length, by symbol order within each length. + for (symbol = 0; symbol < code_lengths_size; ++symbol) { + const int symbol_code_length = code_lengths[symbol]; + if (code_lengths[symbol] > 0) { + sorted[offset[symbol_code_length]++] = symbol; + } + } + + // Special case code with only one value. + if (offset[MAX_ALLOWED_CODE_LENGTH] == 1) { + HuffmanCode code; + code.bits = 0; + code.value = (uint16_t)sorted[0]; + ReplicateValue(table, 1, total_size, code); + tvg::free(sorted); + return total_size; + } + + { + int step; // step size to replicate values in current table + uint32_t low = -1; // low bits for current root entry + uint32_t mask = total_size - 1; // mask for low bits + uint32_t key = 0; // reversed prefix code + int num_nodes = 1; // number of Huffman tree nodes + int num_open = 1; // number of open branches in current tree level + int table_bits = root_bits; // key length of current table + int table_size = 1 << table_bits; // size of current table + symbol = 0; + // Fill in root table. + for (len = 1, step = 2; len <= root_bits; ++len, step <<= 1) { + num_open <<= 1; + num_nodes += num_open; + num_open -= count[len]; + if (num_open < 0) { + tvg::free(sorted); + return 0; + } + for (; count[len] > 0; --count[len]) { + HuffmanCode code; + code.bits = (uint8_t)len; + code.value = (uint16_t)sorted[symbol++]; + ReplicateValue(&table[key], step, table_size, code); + key = GetNextKey(key, len); + } + } + + // Fill in 2nd level tables and add pointers to root table. + for (len = root_bits + 1, step = 2; len <= MAX_ALLOWED_CODE_LENGTH; + ++len, step <<= 1) { + num_open <<= 1; + num_nodes += num_open; + num_open -= count[len]; + if (num_open < 0) { + tvg::free(sorted); + return 0; + } + for (; count[len] > 0; --count[len]) { + HuffmanCode code; + if ((key & mask) != low) { + table += table_size; + table_bits = NextTableBitSize(count, len, root_bits); + table_size = 1 << table_bits; + total_size += table_size; + low = key & mask; + root_table[low].bits = (uint8_t)(table_bits + root_bits); + root_table[low].value = (uint16_t)((table - root_table) - low); + } + code.bits = (uint8_t)(len - root_bits); + code.value = (uint16_t)sorted[symbol++]; + ReplicateValue(&table[key >> root_bits], step, table_size, code); + key = GetNextKey(key, len); + } + } + + // Check if tree is full. + if (num_nodes != 2 * offset[MAX_ALLOWED_CODE_LENGTH] - 1) { + tvg::free(sorted); + return 0; + } + } + + tvg::free(sorted); + return total_size; +} diff --git a/components/thorvg-main/src/loaders/webp/utils/huffman.h b/components/thorvg-main/src/loaders/webp/utils/huffman.h new file mode 100644 index 0000000..8b34da8 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/huffman.h @@ -0,0 +1,67 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Utilities for building and looking up Huffman trees. +// +// Author: Urvang Joshi (urvang@google.com) + +#ifndef WEBP_UTILS_HUFFMAN_H_ +#define WEBP_UTILS_HUFFMAN_H_ + +#include +#include "../webp/format_constants.h" +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define HUFFMAN_TABLE_BITS 8 +#define HUFFMAN_TABLE_MASK ((1 << HUFFMAN_TABLE_BITS) - 1) + +#define LENGTHS_TABLE_BITS 7 +#define LENGTHS_TABLE_MASK ((1 << LENGTHS_TABLE_BITS) - 1) + + +// Huffman lookup table entry +typedef struct { + uint8_t bits; // number of bits used for this symbol + uint16_t value; // symbol value or table offset +} HuffmanCode; + +// Huffman table group. +typedef struct HTreeGroup HTreeGroup; +struct HTreeGroup { + HuffmanCode* htrees[HUFFMAN_CODES_PER_META_CODE]; + int is_trivial_literal; // True, if huffman trees for Red, Blue & Alpha + // Symbols are trivial (have a single code). + uint32_t literal_arb; // If is_trivial_literal is true, this is the + // ARGB value of the pixel, with Green channel + // being set to zero. +}; + +// Creates the instance of HTreeGroup with specified number of tree-groups. +HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups); + +// Releases the memory allocated for HTreeGroup. +void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups); + +// Builds Huffman lookup table assuming code lengths are in symbol order. +// The 'code_lengths' is pre-allocated temporary memory buffer used for creating +// the huffman table. +// Returns built table size or 0 in case of error (invalid tree or +// memory error). +int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits, + const int code_lengths[], int code_lengths_size); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBP_UTILS_HUFFMAN_H_ diff --git a/components/thorvg-main/src/loaders/webp/utils/meson.build b/components/thorvg-main/src/loaders/webp/utils/meson.build new file mode 100644 index 0000000..69f05f4 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/meson.build @@ -0,0 +1,22 @@ +source_file = [ + 'bit_reader.h', + 'bit_reader_inl.h', + 'color_cache.h', + 'endian_inl.h', + 'huffman.h', + 'quant_levels_dec.h', + 'random.h', + 'rescaler.h', + 'utils.h', + 'bit_reader.cpp', + 'color_cache.cpp', + 'huffman.cpp', + 'quant_levels_dec.cpp', + 'random.cpp', + 'rescaler.cpp' +] + +webp_deb += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/webp/utils/quant_levels_dec.cpp b/components/thorvg-main/src/loaders/webp/utils/quant_levels_dec.cpp new file mode 100644 index 0000000..1c97f17 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/quant_levels_dec.cpp @@ -0,0 +1,276 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Implement gradient smoothing: we replace a current alpha value by its +// surrounding average if it's close enough (that is: the change will be less +// than the minimum distance between two quantized level). +// We use sliding window for computing the 2d moving average. +// +// Author: Skal (pascal.massimino@gmail.com) + +#include "tvgCommon.h" +#include "./quant_levels_dec.h" +#include "./utils.h" + +// #define USE_DITHERING // uncomment to enable ordered dithering (not vital) + +#define FIX 16 // fix-point precision for averaging +#define LFIX 2 // extra precision for look-up table +#define LUT_SIZE ((1 << (8 + LFIX)) - 1) // look-up table size + +#if defined(USE_DITHERING) + +#define DFIX 4 // extra precision for ordered dithering +#define DSIZE 4 // dithering size (must be a power of two) +// cf. http://en.wikipedia.org/wiki/Ordered_dithering +static const uint8_t kOrderedDither[DSIZE][DSIZE] = { + { 0, 8, 2, 10 }, // coefficients are in DFIX fixed-point precision + { 12, 4, 14, 6 }, + { 3, 11, 1, 9 }, + { 15, 7, 13, 5 } +}; + +#else +#define DFIX 0 +#endif + +typedef struct { + int width_, height_; // dimension + int row_; // current input row being processed + uint8_t* src_; // input pointer + uint8_t* dst_; // output pointer + + int radius_; // filter radius (=delay) + int scale_; // normalization factor, in FIX bits precision + + void* mem_; // all memory + + // various scratch buffers + uint16_t* start_; + uint16_t* cur_; + uint16_t* end_; + uint16_t* top_; + uint16_t* average_; + + // input levels distribution + int num_levels_; // number of quantized levels + int min_, max_; // min and max level values + int min_level_dist_; // smallest distance between two consecutive levels + + int16_t* correction_; // size = 1 + 2*LUT_SIZE -> ~4k memory +} SmoothParams; + +//------------------------------------------------------------------------------ + +static WEBP_INLINE uint8_t clip_8b(int v) { + return (!(v & (int)(~0U << (8 + DFIX)))) ? (uint8_t)(v >> DFIX) : (v < 0) ? 0u : 255u; +} + +// vertical accumulation +static void VFilter(SmoothParams* const p) { + const uint8_t* src = p->src_; + const int w = p->width_; + uint16_t* const cur = p->cur_; + const uint16_t* const top = p->top_; + uint16_t* const out = p->end_; + uint16_t sum = 0; // all arithmetic is modulo 16bit + int x; + + for (x = 0; x < w; ++x) { + uint16_t new_value; + sum += src[x]; + new_value = top[x] + sum; + out[x] = new_value - cur[x]; // vertical sum of 'r' pixels. + cur[x] = new_value; + } + // move input pointers one row down + p->top_ = p->cur_; + p->cur_ += w; + if (p->cur_ == p->end_) p->cur_ = p->start_; // roll-over + // We replicate edges, as it's somewhat easier as a boundary condition. + // That's why we don't update the 'src' pointer on top/bottom area: + if (p->row_ >= 0 && p->row_ < p->height_ - 1) { + p->src_ += p->width_; + } +} + +// horizontal accumulation. We use mirror replication of missing pixels, as it's +// a little easier to implement (surprisingly). +static void HFilter(SmoothParams* const p) { + const uint16_t* const in = p->end_; + uint16_t* const out = p->average_; + const uint32_t scale = p->scale_; + const int w = p->width_; + const int r = p->radius_; + + int x; + for (x = 0; x <= r; ++x) { // left mirroring + const uint16_t delta = in[x + r - 1] + in[r - x]; + out[x] = (delta * scale) >> FIX; + } + for (; x < w - r; ++x) { // bulk middle run + const uint16_t delta = in[x + r] - in[x - r - 1]; + out[x] = (delta * scale) >> FIX; + } + for (; x < w; ++x) { // right mirroring + const uint16_t delta = + 2 * in[w - 1] - in[2 * w - 2 - r - x] - in[x - r - 1]; + out[x] = (delta * scale) >> FIX; + } +} + +// emit one filtered output row +static void ApplyFilter(SmoothParams* const p) { + const uint16_t* const average = p->average_; + const int w = p->width_; + const int16_t* const correction = p->correction_; +#if defined(USE_DITHERING) + const uint8_t* const dither = kOrderedDither[p->row_ % DSIZE]; +#endif + uint8_t* const dst = p->dst_; + int x; + for (x = 0; x < w; ++x) { + const int v = dst[x]; + if (v < p->max_ && v > p->min_) { + const int c = (v << DFIX) + correction[average[x] - (v << LFIX)]; +#if defined(USE_DITHERING) + dst[x] = clip_8b(c + dither[x % DSIZE]); +#else + dst[x] = clip_8b(c); +#endif + } + } + p->dst_ += w; // advance output pointer +} + +//------------------------------------------------------------------------------ +// Initialize correction table + +static void InitCorrectionLUT(int16_t* const lut, int min_dist) { + // The correction curve is: + // f(x) = x for x <= threshold2 + // f(x) = 0 for x >= threshold1 + // and a linear interpolation for range x=[threshold2, threshold1] + // (along with f(-x) = -f(x) symmetry). + // Note that: threshold2 = 3/4 * threshold1 + const int threshold1 = min_dist << LFIX; + const int threshold2 = (3 * threshold1) >> 2; + const int max_threshold = threshold2 << DFIX; + const int delta = threshold1 - threshold2; + int i; + for (i = 1; i <= LUT_SIZE; ++i) { + int c = (i <= threshold2) ? (i << DFIX) + : (i < threshold1) ? max_threshold * (threshold1 - i) / delta + : 0; + c >>= LFIX; + lut[+i] = +c; + lut[-i] = -c; + } + lut[0] = 0; +} + +static void CountLevels(const uint8_t* const data, int size, + SmoothParams* const p) { + int i, last_level; + uint8_t used_levels[256] = { 0 }; + p->min_ = 255; + p->max_ = 0; + for (i = 0; i < size; ++i) { + const int v = data[i]; + if (v < p->min_) p->min_ = v; + if (v > p->max_) p->max_ = v; + used_levels[v] = 1; + } + // Compute the minimum distance between two non-zero levels. + p->min_level_dist_ = p->max_ - p->min_; + last_level = -1; + for (i = 0; i < 256; ++i) { + if (used_levels[i]) { + ++p->num_levels_; + if (last_level >= 0) { + const int level_dist = i - last_level; + if (level_dist < p->min_level_dist_) { + p->min_level_dist_ = level_dist; + } + } + last_level = i; + } + } +} + +// Initialize all params. +static int InitParams(uint8_t* const data, int width, int height, + int radius, SmoothParams* const p) { + const int R = 2 * radius + 1; // total size of the kernel + + const size_t size_scratch_m = (R + 1) * width * sizeof(*p->start_); + const size_t size_m = width * sizeof(*p->average_); + const size_t size_lut = (1 + 2 * LUT_SIZE) * sizeof(*p->correction_); + const size_t total_size = size_scratch_m + size_m + size_lut; + uint8_t* mem = tvg::malloc(1U * total_size); + + if (mem == NULL) return 0; + p->mem_ = (void*)mem; + + p->start_ = (uint16_t*)mem; + p->cur_ = p->start_; + p->end_ = p->start_ + R * width; + p->top_ = p->end_ - width; + memset(p->top_, 0, width * sizeof(*p->top_)); + mem += size_scratch_m; + + p->average_ = (uint16_t*)mem; + mem += size_m; + + p->width_ = width; + p->height_ = height; + p->src_ = data; + p->dst_ = data; + p->radius_ = radius; + p->scale_ = (1 << (FIX + LFIX)) / (R * R); // normalization constant + p->row_ = -radius; + + // analyze the input distribution so we can best-fit the threshold + CountLevels(data, width * height, p); + + // correction table + p->correction_ = ((int16_t*)mem) + LUT_SIZE; + InitCorrectionLUT(p->correction_, p->min_level_dist_); + + return 1; +} + +static void CleanupParams(SmoothParams* const p) { + tvg::free(p->mem_); +} + +int WebPDequantizeLevels(uint8_t* const data, int width, int height, + int strength) { + const int radius = 4 * strength / 100; + if (strength < 0 || strength > 100) return 0; + if (data == NULL || width <= 0 || height <= 0) return 0; // bad params + if (radius > 0) { + SmoothParams p; + memset(&p, 0, sizeof(p)); + if (!InitParams(data, width, height, radius, &p)) return 0; + if (p.num_levels_ > 2) { + for (; p.row_ < p.height_; ++p.row_) { + VFilter(&p); // accumulate average of input + // Need to wait few rows in order to prime the filter, + // before emitting some output. + if (p.row_ >= p.radius_) { + HFilter(&p); + ApplyFilter(&p); + } + } + } + CleanupParams(&p); + } + return 1; +} diff --git a/components/thorvg-main/src/loaders/webp/utils/quant_levels_dec.h b/components/thorvg-main/src/loaders/webp/utils/quant_levels_dec.h new file mode 100644 index 0000000..9aab068 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/quant_levels_dec.h @@ -0,0 +1,35 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Alpha plane de-quantization utility +// +// Author: Vikas Arora (vikasa@google.com) + +#ifndef WEBP_UTILS_QUANT_LEVELS_DEC_H_ +#define WEBP_UTILS_QUANT_LEVELS_DEC_H_ + +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Apply post-processing to input 'data' of size 'width'x'height' assuming that +// the source was quantized to a reduced number of levels. +// Strength is in [0..100] and controls the amount of dithering applied. +// Returns false in case of error (data is NULL, invalid parameters, +// malloc failure, ...). +int WebPDequantizeLevels(uint8_t* const data, int width, int height, + int strength); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_UTILS_QUANT_LEVELS_DEC_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/utils/random.cpp b/components/thorvg-main/src/loaders/webp/utils/random.cpp new file mode 100644 index 0000000..fac43c5 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/random.cpp @@ -0,0 +1,43 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Pseudo-random utilities +// +// Author: Skal (pascal.massimino@gmail.com) + +#include +#include "./random.h" + +//------------------------------------------------------------------------------ + +// 31b-range values +static const uint32_t kRandomTable[VP8_RANDOM_TABLE_SIZE] = { + 0x0de15230, 0x03b31886, 0x775faccb, 0x1c88626a, 0x68385c55, 0x14b3b828, + 0x4a85fef8, 0x49ddb84b, 0x64fcf397, 0x5c550289, 0x4a290000, 0x0d7ec1da, + 0x5940b7ab, 0x5492577d, 0x4e19ca72, 0x38d38c69, 0x0c01ee65, 0x32a1755f, + 0x5437f652, 0x5abb2c32, 0x0faa57b1, 0x73f533e7, 0x685feeda, 0x7563cce2, + 0x6e990e83, 0x4730a7ed, 0x4fc0d9c6, 0x496b153c, 0x4f1403fa, 0x541afb0c, + 0x73990b32, 0x26d7cb1c, 0x6fcc3706, 0x2cbb77d8, 0x75762f2a, 0x6425ccdd, + 0x24b35461, 0x0a7d8715, 0x220414a8, 0x141ebf67, 0x56b41583, 0x73e502e3, + 0x44cab16f, 0x28264d42, 0x73baaefb, 0x0a50ebed, 0x1d6ab6fb, 0x0d3ad40b, + 0x35db3b68, 0x2b081e83, 0x77ce6b95, 0x5181e5f0, 0x78853bbc, 0x009f9494, + 0x27e5ed3c +}; + +void VP8InitRandom(VP8Random* const rg, float dithering) { + memcpy(rg->tab_, kRandomTable, sizeof(rg->tab_)); + rg->index1_ = 0; + rg->index2_ = 31; + rg->amp_ = (dithering < 0.0f) ? 0 + : (dithering > 1.0f) ? (1 << VP8_RANDOM_DITHER_FIX) + : (uint32_t)((1 << VP8_RANDOM_DITHER_FIX) * dithering); +} + +//------------------------------------------------------------------------------ + diff --git a/components/thorvg-main/src/loaders/webp/utils/random.h b/components/thorvg-main/src/loaders/webp/utils/random.h new file mode 100644 index 0000000..c392a61 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/random.h @@ -0,0 +1,63 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Pseudo-random utilities +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_UTILS_RANDOM_H_ +#define WEBP_UTILS_RANDOM_H_ + +#include +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define VP8_RANDOM_DITHER_FIX 8 // fixed-point precision for dithering +#define VP8_RANDOM_TABLE_SIZE 55 + +typedef struct { + int index1_, index2_; + uint32_t tab_[VP8_RANDOM_TABLE_SIZE]; + int amp_; +} VP8Random; + +// Initializes random generator with an amplitude 'dithering' in range [0..1]. +void VP8InitRandom(VP8Random* const rg, float dithering); + +// Returns a centered pseudo-random number with 'num_bits' amplitude. +// (uses D.Knuth's Difference-based random generator). +// 'amp' is in VP8_RANDOM_DITHER_FIX fixed-point precision. +static WEBP_INLINE int VP8RandomBits2(VP8Random* const rg, int num_bits, + int amp) { + int diff; + assert(num_bits + VP8_RANDOM_DITHER_FIX <= 31); + diff = rg->tab_[rg->index1_] - rg->tab_[rg->index2_]; + if (diff < 0) diff += (1u << 31); + rg->tab_[rg->index1_] = diff; + if (++rg->index1_ == VP8_RANDOM_TABLE_SIZE) rg->index1_ = 0; + if (++rg->index2_ == VP8_RANDOM_TABLE_SIZE) rg->index2_ = 0; + // sign-extend, 0-center + diff = (int)((uint32_t)diff << 1) >> (32 - num_bits); + diff = (diff * amp) >> VP8_RANDOM_DITHER_FIX; // restrict range + diff += 1 << (num_bits - 1); // shift back to 0.5-center + return diff; +} + +static WEBP_INLINE int VP8RandomBits(VP8Random* const rg, int num_bits) { + return VP8RandomBits2(rg, num_bits, rg->amp_); +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_UTILS_RANDOM_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/utils/rescaler.cpp b/components/thorvg-main/src/loaders/webp/utils/rescaler.cpp new file mode 100644 index 0000000..cd45ae8 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/rescaler.cpp @@ -0,0 +1,82 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Rescaling functions +// +// Author: Skal (pascal.massimino@gmail.com) + +#include +#include +#include "../dsp/dsp.h" +#include "./rescaler.h" + +//------------------------------------------------------------------------------ + +void WebPRescalerInit(WebPRescaler* const wrk, int src_width, int src_height, + uint8_t* const dst, int dst_width, int dst_height, + int dst_stride, int num_channels, int x_add, int x_sub, + int y_add, int y_sub, int32_t* const work) { + wrk->x_expand = (src_width < dst_width); + wrk->src_width = src_width; + wrk->src_height = src_height; + wrk->dst_width = dst_width; + wrk->dst_height = dst_height; + wrk->dst = dst; + wrk->dst_stride = dst_stride; + wrk->num_channels = num_channels; + // for 'x_expand', we use bilinear interpolation + wrk->x_add = wrk->x_expand ? (x_sub - 1) : x_add - x_sub; + wrk->x_sub = wrk->x_expand ? (x_add - 1) : x_sub; + wrk->y_accum = y_add; + wrk->y_add = y_add; + wrk->y_sub = y_sub; + wrk->fx_scale = (1 << WEBP_RESCALER_RFIX) / x_sub; + wrk->fy_scale = (1 << WEBP_RESCALER_RFIX) / y_sub; + wrk->fxy_scale = wrk->x_expand ? + ((int64_t)dst_height << WEBP_RESCALER_RFIX) / (x_sub * src_height) : + ((int64_t)dst_height << WEBP_RESCALER_RFIX) / (x_add * src_height); + wrk->irow = work; + wrk->frow = work + num_channels * dst_width; + + WebPRescalerDspInit(); +} + +//------------------------------------------------------------------------------ +// all-in-one calls + +int WebPRescaleNeededLines(const WebPRescaler* const wrk, int max_num_lines) { + const int num_lines = (wrk->y_accum + wrk->y_sub - 1) / wrk->y_sub; + return (num_lines > max_num_lines) ? max_num_lines : num_lines; +} + +int WebPRescalerImport(WebPRescaler* const wrk, int num_lines, + const uint8_t* src, int src_stride) { + int total_imported = 0; + while (total_imported < num_lines && wrk->y_accum > 0) { + int channel; + for (channel = 0; channel < wrk->num_channels; ++channel) { + WebPRescalerImportRow(wrk, src, channel); + } + src += src_stride; + ++total_imported; + wrk->y_accum -= wrk->y_sub; + } + return total_imported; +} + +int WebPRescalerExport(WebPRescaler* const rescaler) { + int total_exported = 0; + while (WebPRescalerHasPendingOutput(rescaler)) { + WebPRescalerExportRow(rescaler, 0); + ++total_exported; + } + return total_exported; +} + +//------------------------------------------------------------------------------ diff --git a/components/thorvg-main/src/loaders/webp/utils/rescaler.h b/components/thorvg-main/src/loaders/webp/utils/rescaler.h new file mode 100644 index 0000000..dd138b1 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/rescaler.h @@ -0,0 +1,78 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Rescaling functions +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_UTILS_RESCALER_H_ +#define WEBP_UTILS_RESCALER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../webp/types.h" + +#define WEBP_RESCALER_RFIX 30 // fixed-point precision for multiplies + +// Structure used for on-the-fly rescaling +typedef struct WebPRescaler WebPRescaler; +struct WebPRescaler { + int x_expand; // true if we're expanding in the x direction + int num_channels; // bytes to jump between pixels + int fy_scale, fx_scale; // fixed-point scaling factor + int64_t fxy_scale; // '' + // we need hpel-precise add/sub increments, for the downsampled U/V planes. + int y_accum; // vertical accumulator + int y_add, y_sub; // vertical increments (add ~= src, sub ~= dst) + int x_add, x_sub; // horizontal increments (add ~= src, sub ~= dst) + int src_width, src_height; // source dimensions + int dst_width, dst_height; // destination dimensions + uint8_t* dst; + int dst_stride; + int32_t* irow, *frow; // work buffer +}; + +// Initialize a rescaler given scratch area 'work' and dimensions of src & dst. +void WebPRescalerInit(WebPRescaler* const rescaler, + int src_width, int src_height, + uint8_t* const dst, + int dst_width, int dst_height, int dst_stride, + int num_channels, + int x_add, int x_sub, + int y_add, int y_sub, + int32_t* const work); + +// Returns the number of input lines needed next to produce one output line, +// considering that the maximum available input lines are 'max_num_lines'. +int WebPRescaleNeededLines(const WebPRescaler* const rescaler, + int max_num_lines); + +// Import multiple rows over all channels, until at least one row is ready to +// be exported. Returns the actual number of lines that were imported. +int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows, + const uint8_t* src, int src_stride); + +// Return true if there is pending output rows ready. +static WEBP_INLINE +int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) { + return (rescaler->y_accum <= 0); +} + +// Export as many rows as possible. Return the numbers of rows written. +int WebPRescalerExport(WebPRescaler* const rescaler); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_UTILS_RESCALER_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/utils/utils.h b/components/thorvg-main/src/loaders/webp/utils/utils.h new file mode 100644 index 0000000..29331d2 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/utils/utils.h @@ -0,0 +1,80 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Misc. common utility functions +// +// Authors: Skal (pascal.massimino@gmail.com) +// Urvang (urvang@google.com) + +#ifndef WEBP_UTILS_UTILS_H_ +#define WEBP_UTILS_UTILS_H_ + +#include + +#include "../webp/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------------------------------------------------ +// Returns (int)floor(log2(n)). n must be > 0. +// use GNU builtins where available. +#if defined(__GNUC__) && \ + ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) +static WEBP_INLINE int BitsLog2Floor(uint32_t n) { + return 31 ^ __builtin_clz(n); +} +#elif defined(_MSC_VER) && _MSC_VER > 1310 && \ + (defined(_M_X64) || defined(_M_IX86)) +#include +#pragma intrinsic(_BitScanReverse) + +static WEBP_INLINE int BitsLog2Floor(uint32_t n) { + uint32_t first_set_bit; + _BitScanReverse((unsigned long*)&first_set_bit, n); + return first_set_bit; +} +#else +static WEBP_INLINE int BitsLog2Floor(uint32_t n) { + int log = 0; + uint32_t value = n; + int i; + + for (i = 4; i >= 0; --i) { + const int shift = (1 << i); + const uint32_t x = value >> shift; + if (x != 0) { + value = x; + log += shift; + } + } + return log; +} +#endif + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Alignment + +#include +// memcpy() is the safe way of moving potentially unaligned 32b memory. +static WEBP_INLINE uint32_t WebPMemToUint32(const uint8_t* const ptr) { + uint32_t A; + memcpy(&A, ptr, sizeof(A)); + return A; +} + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_UTILS_UTILS_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/webp/decode.h b/components/thorvg-main/src/loaders/webp/webp/decode.h new file mode 100644 index 0000000..0cf2b80 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/webp/decode.h @@ -0,0 +1,245 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Main decoding functions for WebP images. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_DECODE_H_ +#define WEBP_WEBP_DECODE_H_ + +#include "./types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_DECODER_ABI_VERSION 0x0205 // MAJOR(8b) + MINOR(8b) + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum VP8StatusCode VP8StatusCode; +// typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; +typedef struct WebPRGBABuffer WebPRGBABuffer; +typedef struct WebPYUVABuffer WebPYUVABuffer; +typedef struct WebPDecBuffer WebPDecBuffer; +typedef struct WebPIDecoder WebPIDecoder; +typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; +typedef struct WebPDecoderOptions WebPDecoderOptions; +typedef struct WebPDecoderConfig WebPDecoderConfig; + +// Return the decoder's version number, packed in hexadecimal using 8bits for +// each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN(int) WebPGetDecoderVersion(void); + +// Retrieve basic header information: width, height. +// This function will also validate the header and return 0 in +// case of formatting error. +// Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. +WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Decodes WebP images pointed to by 'data' and returns RGBA samples, along +// with the dimensions in *width and *height. The ordering of samples in +// memory is R, G, B, A, R, G, B, A... in scan order (endian-independent). +// The returned pointer should be deleted calling free(). +// Returns NULL in case of error. +WEBP_EXTERN(uint8_t*) WebPDecodeRGBA(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data. +WEBP_EXTERN(uint8_t*) WebPDecodeBGRA(const uint8_t* data, size_t data_size, + int* width, int* height); + + +//------------------------------------------------------------------------------ +// Output colorspaces and buffer + +// Colorspaces +// Note: the naming describes the byte-ordering of packed samples in memory. +// For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... +// Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. +// RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: +// RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... +// RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... +// In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for +// these two modes: +// RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... +// RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... + +typedef enum WEBP_CSP_MODE { + MODE_RGB = 0, MODE_RGBA = 1, + MODE_BGR = 2, MODE_BGRA = 3, + MODE_ARGB = 4, MODE_RGBA_4444 = 5, + MODE_RGB_565 = 6, + // RGB-premultiplied transparent modes (alpha value is preserved) + MODE_rgbA = 7, + MODE_bgrA = 8, + MODE_Argb = 9, + MODE_rgbA_4444 = 10, + // YUV modes must come after RGB ones. + MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 + MODE_LAST = 13 +} WEBP_CSP_MODE; + +// Some useful macros: +static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { + return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || + mode == MODE_rgbA_4444); +} + +static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { + return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || + mode == MODE_RGBA_4444 || mode == MODE_YUVA || + WebPIsPremultipliedMode(mode)); +} + +static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { + return (mode < MODE_YUV); +} + +//------------------------------------------------------------------------------ +// WebPDecBuffer: Generic structure for describing the output sample buffer. + +struct WebPRGBABuffer { // view as RGBA + uint8_t* rgba; // pointer to RGBA samples + int stride; // stride in bytes from one scanline to the next. + size_t size; // total size of the *rgba buffer. +}; + +struct WebPYUVABuffer { // view as YUVA + uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples + int y_stride; // luma stride + int u_stride, v_stride; // chroma strides + int a_stride; // alpha stride + size_t y_size; // luma plane size + size_t u_size, v_size; // chroma planes size + size_t a_size; // alpha-plane size +}; + +// Output buffer +struct WebPDecBuffer { + WEBP_CSP_MODE colorspace; // Colorspace. + int width, height; // Dimensions. + int is_external_memory; // If true, 'internal_memory' pointer is not used. + union { + WebPRGBABuffer RGBA; + WebPYUVABuffer YUVA; + } u; // Nameless union of buffer parameters. + uint32_t pad[4]; // padding for later use + + uint8_t* private_memory; // Internally allocated memory (only when + // is_external_memory is false). Should not be used + // externally, but accessed via the buffer union. +}; + +// Internal, version-checked, entry point +WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer*, int); + +// Initialize the structure as empty. Must be called before any other use. +// Returns false in case of version mismatch +static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { + return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); +} + +// Free any memory associated with the buffer. Must always be called last. +// Note: doesn't free the 'buffer' structure itself. +WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); + +//------------------------------------------------------------------------------ +// Enumeration of the status codes + +typedef enum VP8StatusCode { + VP8_STATUS_OK = 0, + VP8_STATUS_OUT_OF_MEMORY, + VP8_STATUS_INVALID_PARAM, + VP8_STATUS_BITSTREAM_ERROR, + VP8_STATUS_UNSUPPORTED_FEATURE, + VP8_STATUS_SUSPENDED, + VP8_STATUS_USER_ABORT, + VP8_STATUS_NOT_ENOUGH_DATA +} VP8StatusCode; + +//------------------------------------------------------------------------------ +// Advanced decoding parametrization +// +// Code sample for using the advanced decoding API +/* + // A) Init a configuration object + WebPDecoderConfig config; + CHECK(WebPInitDecoderConfig(&config)); + + // B) optional: retrieve the bitstream's features. + CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); + + // C) Adjust 'config', if needed + config.no_fancy_upsampling = 1; + config.output.colorspace = MODE_BGRA; + // etc. + + // Note that you can also make config.output point to an externally + // supplied memory buffer, provided it's big enough to store the decoded + // picture. Otherwise, config.output will just be used to allocate memory + // and store the decoded picture. + + // D) Decode! + CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); + + // E) Decoded image is now in config.output (and config.output.u.RGBA) + + // F) Reclaim memory allocated in config's object. It's safe to call + // this function even if the memory is external and wasn't allocated + // by WebPDecode(). + WebPFreeDecBuffer(&config.output); +*/ + +// Features gathered from the bitstream +struct WebPBitstreamFeatures { + int width; // Width in pixels, as read from the bitstream. + int height; // Height in pixels, as read from the bitstream. + int has_alpha; // True if the bitstream contains an alpha channel. + int has_animation; // True if the bitstream is an animation. + int format; // 0 = undefined (/mixed), 1 = lossy, 2 = lossless + + // Unused for now: + int no_incremental_decoding; // if true, using incremental decoding is not + // recommended. + int rotate; // TODO(later) + int uv_sampling; // should be 0 for now. TODO(later) + uint32_t pad[2]; // padding for later use +}; + +// Decoding options +struct WebPDecoderOptions { + int bypass_filtering; // if true, skip the in-loop filtering + int no_fancy_upsampling; // if true, use faster pointwise upsampler + int use_cropping; // if true, cropping is applied _first_ + int crop_left, crop_top; // top-left position for cropping. + // Will be snapped to even values. + int crop_width, crop_height; // dimension of the cropping area + int use_scaling; // if true, scaling is applied _afterward_ + int scaled_width, scaled_height; // final resolution + int use_threads; // if true, use multi-threaded decoding + int dithering_strength; // dithering strength (0=Off, 100=full) + int flip; // flip output vertically + int alpha_dithering_strength; // alpha dithering strength in [0..100] + + // Unused for now: + int force_rotation; // forced rotation (to be applied _last_) + int no_enhancement; // if true, discard enhancement layer + uint32_t pad[3]; // padding for later use +}; + + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_WEBP_DECODE_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/webp/format_constants.h b/components/thorvg-main/src/loaders/webp/webp/format_constants.h new file mode 100644 index 0000000..4c04b50 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/webp/format_constants.h @@ -0,0 +1,88 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Internal header for constants related to WebP file format. +// +// Author: Urvang (urvang@google.com) + +#ifndef WEBP_WEBP_FORMAT_CONSTANTS_H_ +#define WEBP_WEBP_FORMAT_CONSTANTS_H_ + +// Create fourcc of the chunk from the chunk tag characters. +#define MKFOURCC(a, b, c, d) ((uint32_t)(a) | (b) << 8 | (c) << 16 | (d) << 24) + +// VP8 related constants. +#define VP8_SIGNATURE 0x9d012a // Signature in VP8 data. +#define VP8_MAX_PARTITION0_SIZE (1 << 19) // max size of mode partition +#define VP8_MAX_PARTITION_SIZE (1 << 24) // max size for token partition +#define VP8_FRAME_HEADER_SIZE 10 // Size of the frame header within VP8 data. + +// VP8L related constants. +#define VP8L_SIGNATURE_SIZE 1 // VP8L signature size. +#define VP8L_MAGIC_BYTE 0x2f // VP8L signature byte. +#define VP8L_IMAGE_SIZE_BITS 14 // Number of bits used to store + // width and height. +#define VP8L_VERSION_BITS 3 // 3 bits reserved for version. +#define VP8L_VERSION 0 // version 0 +#define VP8L_FRAME_HEADER_SIZE 5 // Size of the VP8L frame header. + +#define MAX_PALETTE_SIZE 256 +#define MAX_CACHE_BITS 11 +#define HUFFMAN_CODES_PER_META_CODE 5 +#define ARGB_BLACK 0xff000000 + +#define DEFAULT_CODE_LENGTH 8 +#define MAX_ALLOWED_CODE_LENGTH 15 + +#define NUM_LITERAL_CODES 256 +#define NUM_LENGTH_CODES 24 +#define NUM_DISTANCE_CODES 40 +#define CODE_LENGTH_CODES 19 + +#define MIN_HUFFMAN_BITS 2 // min number of Huffman bits +#define MAX_HUFFMAN_BITS 9 // max number of Huffman bits + +#define TRANSFORM_PRESENT 1 // The bit to be written when next data + // to be read is a transform. +#define NUM_TRANSFORMS 4 // Maximum number of allowed transform + // in a bitstream. +typedef enum { + PREDICTOR_TRANSFORM = 0, + CROSS_COLOR_TRANSFORM = 1, + SUBTRACT_GREEN = 2, + COLOR_INDEXING_TRANSFORM = 3 +} VP8LImageTransformType; + +// Alpha related constants. +#define ALPHA_HEADER_LEN 1 +#define ALPHA_NO_COMPRESSION 0 +#define ALPHA_LOSSLESS_COMPRESSION 1 +#define ALPHA_PREPROCESSED_LEVELS 1 + +// Mux related constants. +#define TAG_SIZE 4 // Size of a chunk tag (e.g. "VP8L"). +#define CHUNK_SIZE_BYTES 4 // Size needed to store chunk's size. +#define CHUNK_HEADER_SIZE 8 // Size of a chunk header. +#define RIFF_HEADER_SIZE 12 // Size of the RIFF header ("RIFFnnnnWEBP"). +#define ANMF_CHUNK_SIZE 16 // Size of an ANMF chunk. +#define ANIM_CHUNK_SIZE 6 // Size of an ANIM chunk. +#define FRGM_CHUNK_SIZE 6 // Size of a FRGM chunk. +#define VP8X_CHUNK_SIZE 10 // Size of a VP8X chunk. + +#define MAX_CANVAS_SIZE (1 << 24) // 24-bit max for VP8X width/height. +#define MAX_IMAGE_AREA (1ULL << 32) // 32-bit max for width x height. +#define MAX_LOOP_COUNT (1 << 16) // maximum value for loop-count +#define MAX_DURATION (1 << 24) // maximum duration +#define MAX_POSITION_OFFSET (1 << 24) // maximum frame/fragment x/y offset + +// Maximum chunk payload is such that adding the header and padding won't +// overflow a uint32_t. +#define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1) + +#endif /* WEBP_WEBP_FORMAT_CONSTANTS_H_ */ diff --git a/components/thorvg-main/src/loaders/webp/webp/meson.build b/components/thorvg-main/src/loaders/webp/webp/meson.build new file mode 100644 index 0000000..cbdcd4b --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/webp/meson.build @@ -0,0 +1,10 @@ +source_file = [ + 'decode.h', + 'format_constants.h', + 'types.h' +] + +webp_deb += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] \ No newline at end of file diff --git a/components/thorvg-main/src/loaders/webp/webp/types.h b/components/thorvg-main/src/loaders/webp/webp/types.h new file mode 100644 index 0000000..edac198 --- /dev/null +++ b/components/thorvg-main/src/loaders/webp/webp/types.h @@ -0,0 +1,46 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Common types +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_TYPES_H_ +#define WEBP_WEBP_TYPES_H_ + +#include // for size_t + +#ifndef _MSC_VER +#include +#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +#define WEBP_INLINE inline +#else +#define WEBP_INLINE +#endif +#else +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; +typedef long long int int64_t; +#define WEBP_INLINE __forceinline +#endif /* _MSC_VER */ + +#ifndef WEBP_EXTERN +# define WEBP_EXTERN(type) extern type +#endif /* WEBP_EXTERN */ + +// Macro to check ABI compatibility (same major revision number) +#define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) + +#endif /* WEBP_WEBP_TYPES_H_ */ diff --git a/components/thorvg-main/src/meson.build b/components/thorvg-main/src/meson.build new file mode 100644 index 0000000..da4d38e --- /dev/null +++ b/components/thorvg-main/src/meson.build @@ -0,0 +1,95 @@ +compiler_flags = [] +override_options = [] + +lib_type = get_option('default_library') + +if lib_type == 'shared' + compiler_flags += ['-DTVG_EXPORT', '-DTVG_BUILD'] +else + compiler_flags += ['-DTVG_STATIC'] +endif + +cc = meson.get_compiler('cpp') +if cc.get_id() == 'clang-cl' + if simd_type == 'avx' + compiler_flags += ['/clang:-mavx'] + endif + if simd_type == 'neon-arm' + compiler_flags += ['/clang:-mfpu=neon'] + endif + compiler_flags += ['/clang:-Wno-unknown-pragmas'] + + if logging == false + compiler_flags += ['/clang:-Wdouble-promotion'] + endif + + if get_option('b_sanitize') == 'none' + override_options += ['cpp_eh=none','cpp_rtti=false'] + compiler_flags += ['/clang:-fno-math-errno', '/clang:-Woverloaded-virtual', + '/clang:-fno-stack-protector', '/clang:-fno-unwind-tables' , + '/clang:-fno-asynchronous-unwind-tables'] + endif +elif (cc.get_id() == 'msvc') + compiler_flags += ['-DNOMINMAX'] +else + if simd_type == 'avx' + compiler_flags += ['-mavx'] + endif + if simd_type == 'neon-arm' + compiler_flags += ['-mfpu=neon'] + endif + compiler_flags += ['-Wno-unknown-pragmas'] + + if logging == false + compiler_flags += ['-Wdouble-promotion'] + endif + + if get_option('b_sanitize') == 'none' + compiler_flags += ['-fno-exceptions', '-fno-rtti', '-fno-stack-protector', '-fno-math-errno', + '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-Woverloaded-virtual'] + endif +endif + +subdir('common') +subdir('renderer') +subdir('loaders') +subdir('savers') + +thorvg_lib_dep = [common_dep, utils_dep, loader_dep, saver_dep] + +if get_option('threads') and host_machine.system() != 'windows' and host_machine.system() != 'android' + thread_dep = meson.get_compiler('cpp').find_library('pthread') + thorvg_lib_dep += [thread_dep] +endif + +subdir('bindings') + +thorvg_lib = library( + 'thorvg-' + vmaj, + include_directories : headers, + version : meson.project_version(), + soversion : host_machine.system() != 'windows' ? vmaj : '', + dependencies : thorvg_lib_dep, + install : true, + cpp_args : compiler_flags, + gnu_symbol_visibility : 'hidden', + override_options : override_options +) + +thorvg_dep = declare_dependency( + compile_args: (lib_type == 'static') ? ['-DTVG_STATIC'] : [], + include_directories: thorvg_inc, + link_with: thorvg_lib, +) +meson.override_dependency('thorvg-' + vmaj, thorvg_dep) + +pkg_mod = import('pkgconfig') + +pkg_mod.generate( + libraries : thorvg_lib, + version : meson.project_version(), + name : 'libthorvg', + filebase : 'thorvg-' + vmaj, + subdirs : 'thorvg-' + vmaj, + description : 'A Thor library for rendering vector graphics' +) diff --git a/components/thorvg-main/src/renderer/gl_engine/meson.build b/components/thorvg-main/src/renderer/gl_engine/meson.build new file mode 100644 index 0000000..c3c825d --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/meson.build @@ -0,0 +1,42 @@ +source_file = [ + 'tvgGl.h', + 'tvgGlCommon.h', + 'tvgGlEffect.h', + 'tvgGlGpuBuffer.h', + 'tvgGlProgram.h', + 'tvgGlRenderer.h', + 'tvgGlRenderPass.h', + 'tvgGlRenderTarget.h', + 'tvgGlRenderTask.h', + 'tvgGlShader.h', + 'tvgGlShaderSrc.h', + 'tvgGl.cpp', + 'tvgGlEffect.cpp', + 'tvgGlGeometry.cpp', + 'tvgGlGpuBuffer.cpp', + 'tvgGlProgram.cpp', + 'tvgGlRenderer.cpp', + 'tvgGlRenderPass.cpp', + 'tvgGlRenderTarget.cpp', + 'tvgGlRenderTask.cpp', + 'tvgGlShader.cpp', + 'tvgGlShaderSrc.cpp', + 'tvgGlTessellator.cpp', + 'tvgGlTessellator.h', +] + +#force to use gles +if cc.get_id() == 'emscripten' + gl_variant = 'OpenGL ES' +endif + +if gl_variant == 'OpenGL ES' + compiler_flags += ['-DTHORVG_GL_TARGET_GLES=1'] +else + compiler_flags += ['-DTHORVG_GL_TARGET_GL=1'] +endif + +engine_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file, +)] diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGl.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGl.cpp new file mode 100644 index 0000000..fc427e0 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGl.cpp @@ -0,0 +1,901 @@ +/* + * Copyright (c) 2025 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGl.h" +#include "tvgCommon.h" + +#ifdef __EMSCRIPTEN__ + +bool glInit() +{ + return true; +} + + +bool glTerm() +{ + return true; +} + +#else //__EMSCRIPTEN__ + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#ifdef THORVG_GL_TARGET_GL + typedef PROC(WINAPI *PFNGLGETPROCADDRESSPROC)(LPCSTR); + static PFNGLGETPROCADDRESSPROC glGetProcAddress = NULL; +#endif + +static HMODULE _libGL = NULL; +#ifdef THORVG_GL_TARGET_GLES + static HMODULE _libEGL = NULL; +#endif + +static bool _glLoad() +{ +#ifdef THORVG_GL_TARGET_GL + _libGL = LoadLibraryW(L"opengl32.dll"); + if (!_libGL) { + TVGERR("GL_ENGINE", "Cannot find the gl library."); + return false; + } + if (!glGetProcAddress) glGetProcAddress = (PFNGLGETPROCADDRESSPROC)GetProcAddress(_libGL, "wglGetProcAddress"); + if (!glGetProcAddress) glGetProcAddress = (PFNGLGETPROCADDRESSPROC)GetProcAddress(_libGL, "wglGetProcAddressARB"); + if (!glGetProcAddress) return false; +#else + if (!_libGL) _libGL = LoadLibraryW(L"GLESv2.dll"); + if (!_libGL) _libGL = LoadLibraryW(L"libGLESv2.dll"); + if (!_libGL) { + TVGERR("GL_ENGINE", "Cannot find gles library."); + return false; + } +#endif + return true; +} + +// load opengl proc address from dll or from wglGetProcAddress +static PROC _getProcAddress(const char* procName) +{ + auto procHandle = GetProcAddress(_libGL, procName); +#ifdef THORVG_GL_TARGET_GL + if (!procHandle) procHandle = glGetProcAddress(procName); +#endif + return procHandle; +} + +#elif defined(__linux__) + +#include + +#ifdef THORVG_GL_TARGET_GL + typedef void* (*PFNGLGETPROCADDRESSPROC)(const char*); + static PFNGLGETPROCADDRESSPROC glGetProcAddress = nullptr; +#endif + +static void* _libGL = nullptr; +#ifdef THORVG_GL_TARGET_GLES + static void* _libEGL = nullptr; +#endif + +static bool _glLoad() +{ +#ifdef THORVG_GL_TARGET_GL + _libGL = dlopen("libGL.so", RTLD_LAZY); + if (!_libGL) _libGL = dlopen("libGL.so.4", RTLD_LAZY); + if (!_libGL) _libGL = dlopen("libGL.so.3", RTLD_LAZY); + if (!_libGL) { + TVGERR("GL_ENGINE", "Cannot find the gl library."); + return false; + } + if (!glGetProcAddress) glGetProcAddress = (PFNGLGETPROCADDRESSPROC)dlsym(_libGL, "glXGetProcAddress"); + if (!glGetProcAddress) glGetProcAddress = (PFNGLGETPROCADDRESSPROC)dlsym(_libGL, "glXGetProcAddressARB"); + if (!glGetProcAddress) return false; +#else + if (!_libGL) _libGL = dlopen("libGLESv2.so", RTLD_LAZY); + if (!_libGL) _libGL = dlopen("libGLESv2.so.2.0", RTLD_LAZY); // sometimes used in Mesa + if (!_libGL) _libGL = dlopen("libGLESv2.so.2", RTLD_LAZY); + if (!_libGL) { + TVGERR("GL_ENGINE", "Cannot find the gles library."); + return false; + } +#endif + return true; +} + + +static void* _getProcAddress(const char* procName) +{ +#ifdef THORVG_GL_TARGET_GL + return glGetProcAddress(procName); +#else + return dlsym(_libGL, procName); +#endif +} + +#elif defined(__APPLE__) || defined(__MACH__) + +#include + +static void* _libGL = nullptr; +#ifdef THORVG_GL_TARGET_GLES + static void* _libEGL = nullptr; +#endif + +static bool _glLoad() +{ + if (!_libGL) _libGL = dlopen("/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY); + if (!_libGL) _libGL = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY); + if (_libGL) return true; + TVGERR("GL_ENGINE", "Cannot find gl library."); + return false; +} + + +static void* _getProcAddress(const char* procName) +{ + return dlsym(_libGL, procName); +} + +#endif + +#define GL_FUNCTION_FETCH(procName, procType) \ + procName = (procType)_getProcAddress(#procName); \ + if (!procName) { \ + TVGERR("GL_ENGINE", "%s is not supported.", #procName); \ + return false; \ + } + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +//GL_VERSION_1_0 +PFNGLCULLFACEPROC glCullFace; +PFNGLFRONTFACEPROC glFrontFace; +PFNGLSCISSORPROC glScissor; +PFNGLTEXPARAMETERIPROC glTexParameteri; +PFNGLTEXIMAGE2DPROC glTexImage2D; +PFNGLDRAWBUFFERPROC glDrawBuffer; +PFNGLCLEARPROC glClear; +PFNGLCLEARCOLORPROC glClearColor; +PFNGLCLEARSTENCILPROC glClearStencil; +PFNGLCLEARDEPTHPROC glClearDepth; +PFNGLCLEARDEPTHFPROC glClearDepthf; // GLES +PFNGLCOLORMASKPROC glColorMask; +PFNGLDEPTHMASKPROC glDepthMask; +PFNGLDISABLEPROC glDisable; +PFNGLENABLEPROC glEnable; +PFNGLBLENDFUNCPROC glBlendFunc; +PFNGLSTENCILFUNCPROC glStencilFunc; +PFNGLSTENCILOPPROC glStencilOp; +PFNGLDEPTHFUNCPROC glDepthFunc; +PFNGLGETERRORPROC glGetError; +PFNGLGETINTEGERVPROC glGetIntegerv; +PFNGLGETSTRINGPROC glGetString; +PFNGLVIEWPORTPROC glViewport; +//PFNGLHINTPROC glHint; +//PFNGLLINEWIDTHPROC glLineWidth; +//PFNGLPOINTSIZEPROC glPointSize; +//PFNGLPOLYGONMODEPROC glPolygonMode; +//PFNGLTEXPARAMETERFPROC glTexParameterf; +//PFNGLTEXPARAMETERFVPROC glTexParameterfv; +//PFNGLTEXPARAMETERIVPROC glTexParameteriv; +//PFNGLTEXIMAGE1DPROC glTexImage1D; +//PFNGLSTENCILMASKPROC glStencilMask; +//PFNGLFINISHPROC glFinish; +//PFNGLFLUSHPROC glFlush; +//PFNGLLOGICOPPROC glLogicOp = nullptr +//PFNGLPIXELSTOREFPROC glPixelStoref; +//PFNGLPIXELSTOREIPROC glPixelStorei; +//PFNGLREADBUFFERPROC glReadBuffer; +//PFNGLREADPIXELSPROC glReadPixels; +//PFNGLGETBOOLEANVPROC glGetBooleanv; +//PFNGLGETDOUBLEVPROC glGetDoublev; +//PFNGLGETFLOATVPROC glGetFloatv; +//PFNGLGETTEXIMAGEPROC glGetTexImage; +//PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; +//PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; +//PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; +//PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; +//PFNGLISENABLEDPROC glIsEnabled; +//PFNGLDEPTHRANGEPROC glDepthRange; + +//GL_VERSION_1_1 +PFNGLDRAWELEMENTSPROC glDrawElements; +PFNGLBINDTEXTUREPROC glBindTexture; +PFNGLDELETETEXTURESPROC glDeleteTextures; +PFNGLGENTEXTURESPROC glGenTextures; +//PFNGLDRAWARRAYSPROC glDrawArrays; +//PFNGLGETPOINTERVPROC glGetPointerv; +//PFNGLPOLYGONOFFSETPROC glPolygonOffset; +//PFNGLCOPYTEXIMAGE1DPROC glCopyTexImage1D; +//PFNGLCOPYTEXIMAGE2DPROC glCopyTexImage2D; +//PFNGLCOPYTEXSUBIMAGE1DPROC glCopyTexSubImage1D; +//PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; +//PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; +//PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; +//PFNGLISTEXTUREPROC glIsTexture; + +//GL_VERSION_1_2 +//PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements; +//PFNGLTEXIMAGE3DPROC glTexImage3D; +//PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; +//PFNGLCOPYTEXSUBIMAGE3DPROC glCopyTexSubImage3D; + +//GL_VERSION_1_3 +PFNGLACTIVETEXTUREPROC glActiveTexture; +//PFNGLSAMPLECOVERAGEPROC glSampleCoverage; +//PFNGLCOMPRESSEDTEXIMAGE3DPROC glCompressedTexImage3D; +//PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D; +//PFNGLCOMPRESSEDTEXIMAGE1DPROC glCompressedTexImage1D; +//PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D; +//PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D; +//PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D; +//PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage; + +//GL_VERSION_1_4 +PFNGLBLENDEQUATIONPROC glBlendEquation; +//PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate; +//PFNGLMULTIDRAWARRAYSPROC glMultiDrawArrays; +//PFNGLMULTIDRAWELEMENTSPROC glMultiDrawElements; +//PFNGLPOINTPARAMETERFPROC glPointParameterf; +//PFNGLPOINTPARAMETERFVPROC glPointParameterfv; +//PFNGLPOINTPARAMETERIPROC glPointParameteri; +//PFNGLPOINTPARAMETERIVPROC glPointParameteriv; +//PFNGLBLENDCOLORPROC glBlendColor; + +//GL_VERSION_1_5 +PFNGLBINDBUFFERPROC glBindBuffer; +PFNGLDELETEBUFFERSPROC glDeleteBuffers; +PFNGLGENBUFFERSPROC glGenBuffers; +PFNGLBUFFERDATAPROC glBufferData; +//PFNGLGENQUERIESPROC glGenQueries; +//PFNGLDELETEQUERIESPROC glDeleteQueries; +//PFNGLISQUERYPROC glIsQuery; +//PFNGLBEGINQUERYPROC glBeginQuery; +//PFNGLENDQUERYPROC glEndQuery; +//PFNGLGETQUERYIVPROC glGetQueryiv; +//PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; +//PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; +//PFNGLISBUFFERPROC glIsBuffer; +//PFNGLBUFFERSUBDATAPROC glBufferSubData; +//PFNGLGETBUFFERSUBDATAPROC glGetBufferSubData; +//PFNGLMAPBUFFERPROC glMapBuffer; +//PFNGLUNMAPBUFFERPROC glUnmapBuffer; +//PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; +//PFNGLGETBUFFERPOINTERVPROC glGetBufferPointerv; + +//GL_VERSION_2_0 +PFNGLDRAWBUFFERSPROC glDrawBuffers; +PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate; +PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate; +PFNGLATTACHSHADERPROC glAttachShader; +PFNGLCOMPILESHADERPROC glCompileShader; +PFNGLCREATEPROGRAMPROC glCreateProgram; +PFNGLCREATESHADERPROC glCreateShader; +PFNGLDELETEPROGRAMPROC glDeleteProgram; +PFNGLDELETESHADERPROC glDeleteShader; +PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; +PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; +PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; +PFNGLGETPROGRAMIVPROC glGetProgramiv; +PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; +PFNGLGETSHADERIVPROC glGetShaderiv; +PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; +PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; +PFNGLLINKPROGRAMPROC glLinkProgram; +PFNGLSHADERSOURCEPROC glShaderSource; +PFNGLUSEPROGRAMPROC glUseProgram; +PFNGLUNIFORM1FPROC glUniform1f; +PFNGLUNIFORM1FVPROC glUniform1fv; +PFNGLUNIFORM2FVPROC glUniform2fv; +PFNGLUNIFORM3FVPROC glUniform3fv; +PFNGLUNIFORM4FVPROC glUniform4fv; +PFNGLUNIFORM1IVPROC glUniform1iv; +PFNGLUNIFORM2IVPROC glUniform2iv; +PFNGLUNIFORM3IVPROC glUniform3iv; +PFNGLUNIFORM4IVPROC glUniform4iv; +PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; +PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; +//PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate; +//PFNGLSTENCILMASKSEPARATEPROC glStencilMaskSeparate; +//PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; +//PFNGLDETACHSHADERPROC glDetachShader; +//PFNGLGETACTIVEATTRIBPROC glGetActiveAttrib; +//PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform; +//PFNGLGETATTACHEDSHADERSPROC glGetAttachedShaders; +//PFNGLGETSHADERSOURCEPROC glGetShaderSource; +//PFNGLGETUNIFORMFVPROC glGetUniformfv; +//PFNGLGETUNIFORMIVPROC glGetUniformiv; +//PFNGLGETVERTEXATTRIBDVPROC glGetVertexAttribdv; +//PFNGLGETVERTEXATTRIBFVPROC glGetVertexAttribfv; +//PFNGLGETVERTEXATTRIBIVPROC glGetVertexAttribiv; +//PFNGLGETVERTEXATTRIBPOINTERVPROC glGetVertexAttribPointerv; +//PFNGLISPROGRAMPROC glIsProgram; +//PFNGLISSHADERPROC glIsShader; +//PFNGLUNIFORM2FPROC glUniform2f; +//PFNGLUNIFORM3FPROC glUniform3f; +//PFNGLUNIFORM4FPROC glUniform4f; +//PFNGLUNIFORM1IPROC glUniform1i; +//PFNGLUNIFORM2IPROC glUniform2i; +//PFNGLUNIFORM3IPROC glUniform3i; +//PFNGLUNIFORM4IPROC glUniform4i; +//PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fv; +//PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv; +//PFNGLVALIDATEPROGRAMPROC glValidateProgram; +//PFNGLVERTEXATTRIB1DPROC glVertexAttrib1d; +//PFNGLVERTEXATTRIB1DVPROC glVertexAttrib1dv; +//PFNGLVERTEXATTRIB1FPROC glVertexAttrib1f; +//PFNGLVERTEXATTRIB1FVPROC glVertexAttrib1fv; +//PFNGLVERTEXATTRIB1SPROC glVertexAttrib1s; +//PFNGLVERTEXATTRIB1SVPROC glVertexAttrib1sv; +//PFNGLVERTEXATTRIB2DPROC glVertexAttrib2d; +//PFNGLVERTEXATTRIB2DVPROC glVertexAttrib2dv; +//PFNGLVERTEXATTRIB2FPROC glVertexAttrib2f; +//PFNGLVERTEXATTRIB2FVPROC glVertexAttrib2fv; +//PFNGLVERTEXATTRIB2SPROC glVertexAttrib2s; +//PFNGLVERTEXATTRIB2SVPROC glVertexAttrib2sv; +//PFNGLVERTEXATTRIB3DPROC glVertexAttrib3d; +//PFNGLVERTEXATTRIB3DVPROC glVertexAttrib3dv; +//PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f; +//PFNGLVERTEXATTRIB3FVPROC glVertexAttrib3fv; +//PFNGLVERTEXATTRIB3SPROC glVertexAttrib3s; +//PFNGLVERTEXATTRIB3SVPROC glVertexAttrib3sv; +//PFNGLVERTEXATTRIB4NBVPROC glVertexAttrib4Nbv; +//PFNGLVERTEXATTRIB4NIVPROC glVertexAttrib4Niv; +//PFNGLVERTEXATTRIB4NSVPROC glVertexAttrib4Nsv; +//PFNGLVERTEXATTRIB4NUBPROC glVertexAttrib4Nub; +//PFNGLVERTEXATTRIB4NUBVPROC glVertexAttrib4Nubv; +//PFNGLVERTEXATTRIB4NUIVPROC glVertexAttrib4Nuiv; +//PFNGLVERTEXATTRIB4NUSVPROC glVertexAttrib4Nusv; +//PFNGLVERTEXATTRIB4BVPROC glVertexAttrib4bv; +//PFNGLVERTEXATTRIB4DPROC glVertexAttrib4d; +//PFNGLVERTEXATTRIB4DVPROC glVertexAttrib4dv; +//PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; +//PFNGLVERTEXATTRIB4FVPROC glVertexAttrib4fv; +//PFNGLVERTEXATTRIB4IVPROC glVertexAttrib4iv; +//PFNGLVERTEXATTRIB4SPROC glVertexAttrib4s; +//PFNGLVERTEXATTRIB4SVPROC glVertexAttrib4sv; +//PFNGLVERTEXATTRIB4UBVPROC glVertexAttrib4ubv; +//PFNGLVERTEXATTRIB4UIVPROC glVertexAttrib4uiv; +//PFNGLVERTEXATTRIB4USVPROC glVertexAttrib4usv; + +//GL_VERSION_2_1 +//PFNGLUNIFORMMATRIX2X3FVPROC glUniformMatrix2x3fv; +//PFNGLUNIFORMMATRIX3X2FVPROC glUniformMatrix3x2fv; +//PFNGLUNIFORMMATRIX2X4FVPROC glUniformMatrix2x4fv; +//PFNGLUNIFORMMATRIX4X2FVPROC glUniformMatrix4x2fv; +//PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv; +//PFNGLUNIFORMMATRIX4X3FVPROC glUniformMatrix4x3fv; + +//GL_VERSION_3_0 +PFNGLBINDBUFFERRANGEPROC glBindBufferRange; +PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; +PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; +PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; +PFNGLINVALIDATEFRAMEBUFFERPROC glInvalidateFramebuffer; +PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; +PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; +PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; +PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample; +PFNGLBINDVERTEXARRAYPROC glBindVertexArray; +PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; +PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; +//PFNGLCOLORMASKIPROC glColorMaski; +//PFNGLGETBOOLEANI_VPROC glGetBooleani_v; +//PFNGLGETINTEGERI_VPROC glGetIntegeri_v; +//PFNGLENABLEIPROC glEnablei; +//PFNGLDISABLEIPROC glDisablei; +//PFNGLISENABLEDIPROC glIsEnabledi; +//PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback; +//PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback; +//PFNGLBINDBUFFERBASEPROC glBindBufferBase; +//PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings; +//PFNGLGETTRANSFORMFEEDBACKVARYINGPROC glGetTransformFeedbackVarying; +//PFNGLCLAMPCOLORPROC glClampColor; +//PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender; +//PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender; +//PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; +//PFNGLGETVERTEXATTRIBIIVPROC glGetVertexAttribIiv; +//PFNGLGETVERTEXATTRIBIUIVPROC glGetVertexAttribIuiv; +//PFNGLVERTEXATTRIBI1IPROC glVertexAttribI1i; +//PFNGLVERTEXATTRIBI2IPROC glVertexAttribI2i; +//PFNGLVERTEXATTRIBI3IPROC glVertexAttribI3i; +//PFNGLVERTEXATTRIBI4IPROC glVertexAttribI4i; +//PFNGLVERTEXATTRIBI1UIPROC glVertexAttribI1ui; +//PFNGLVERTEXATTRIBI2UIPROC glVertexAttribI2ui; +//PFNGLVERTEXATTRIBI3UIPROC glVertexAttribI3ui; +//PFNGLVERTEXATTRIBI4UIPROC glVertexAttribI4ui; +//PFNGLVERTEXATTRIBI1IVPROC glVertexAttribI1iv; +//PFNGLVERTEXATTRIBI2IVPROC glVertexAttribI2iv; +//PFNGLVERTEXATTRIBI3IVPROC glVertexAttribI3iv; +//PFNGLVERTEXATTRIBI4IVPROC glVertexAttribI4iv; +//PFNGLVERTEXATTRIBI1UIVPROC glVertexAttribI1uiv; +//PFNGLVERTEXATTRIBI2UIVPROC glVertexAttribI2uiv; +//PFNGLVERTEXATTRIBI3UIVPROC glVertexAttribI3uiv; +//PFNGLVERTEXATTRIBI4UIVPROC glVertexAttribI4uiv; +//PFNGLVERTEXATTRIBI4BVPROC glVertexAttribI4bv; +//PFNGLVERTEXATTRIBI4SVPROC glVertexAttribI4sv; +//PFNGLVERTEXATTRIBI4UBVPROC glVertexAttribI4ubv; +//PFNGLVERTEXATTRIBI4USVPROC glVertexAttribI4usv; +//PFNGLGETUNIFORMUIVPROC glGetUniformuiv; +//PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; +//PFNGLGETFRAGDATALOCATIONPROC glGetFragDataLocation; +//PFNGLUNIFORM1UIPROC glUniform1ui; +//PFNGLUNIFORM2UIPROC glUniform2ui; +//PFNGLUNIFORM3UIPROC glUniform3ui; +//PFNGLUNIFORM4UIPROC glUniform4ui; +//PFNGLUNIFORM1UIVPROC glUniform1uiv; +//PFNGLUNIFORM2UIVPROC glUniform2uiv; +//PFNGLUNIFORM3UIVPROC glUniform3uiv; +//PFNGLUNIFORM4UIVPROC glUniform4uiv; +//PFNGLTEXPARAMETERIIVPROC glTexParameterIiv; +//PFNGLTEXPARAMETERIUIVPROC glTexParameterIuiv; +//PFNGLGETTEXPARAMETERIIVPROC glGetTexParameterIiv; +//PFNGLGETTEXPARAMETERIUIVPROC glGetTexParameterIuiv; +//PFNGLCLEARBUFFERIVPROC glClearBufferiv; +//PFNGLCLEARBUFFERUIVPROC glClearBufferuiv; +//PFNGLCLEARBUFFERFVPROC glClearBufferfv; +//PFNGLCLEARBUFFERFIPROC glClearBufferfi; +//PFNGLGETSTRINGIPROC glGetStringi; +//PFNGLISRENDERBUFFERPROC glIsRenderbuffer; +//PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; +//PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv; +//PFNGLISFRAMEBUFFERPROC glIsFramebuffer; +//PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; +//PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; +//PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; +//PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv; +//PFNGLGENERATEMIPMAPPROC glGenerateMipmap; +//PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; +//PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +//PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange; +//PFNGLISVERTEXARRAYPROC glIsVertexArray; + +//GL_VERSION_3_1 +PFNGLGETUNIFORMBLOCKINDEXPROC glGetUniformBlockIndex; +PFNGLUNIFORMBLOCKBINDINGPROC glUniformBlockBinding; +//PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; +//PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; +//PFNGLTEXBUFFERPROC glTexBuffer; +//PFNGLPRIMITIVERESTARTINDEXPROC glPrimitiveRestartIndex; +//PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData; +//PFNGLGETUNIFORMINDICESPROC glGetUniformIndices; +//PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv; +//PFNGLGETACTIVEUNIFORMNAMEPROC glGetActiveUniformName; +//PFNGLGETACTIVEUNIFORMBLOCKIVPROC glGetActiveUniformBlockiv; +//PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glGetActiveUniformBlockName; + +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(THORVG_GL_TARGET_GL) + PFNWGLGETCURRENTCONTEXTPROC tvgWglGetCurrentContext; + PFNWGLMAKECURRENTPROC tvgWglMakeCurrent; +#endif + +#if defined(THORVG_GL_TARGET_GLES) + PFNEGLGETCURRENTCONTEXTPROC tvgEglGetCurrentContext; + PFNEGLMAKECURRENTPROC tvgEglMakeCurrent; +#endif + +bool glInit() +{ + if (!_glLoad()) return false; + + // GL_VERSION_1_0 + GL_FUNCTION_FETCH(glCullFace, PFNGLCULLFACEPROC); + GL_FUNCTION_FETCH(glFrontFace, PFNGLFRONTFACEPROC); + // GL_FUNCTION_FETCH(glHint, PFNGLHINTPROC); + // GL_FUNCTION_FETCH(glLineWidth, PFNGLLINEWIDTHPROC); + // GL_FUNCTION_FETCH(glPointSize, PFNGLPOINTSIZEPROC); + // GL_FUNCTION_FETCH(glPolygonMode, PFNGLPOLYGONMODEPROC); + GL_FUNCTION_FETCH(glScissor, PFNGLSCISSORPROC); + // GL_FUNCTION_FETCH(glTexParameterf, PFNGLTEXPARAMETERFPROC); + // GL_FUNCTION_FETCH(glTexParameterfv, PFNGLTEXPARAMETERFVPROC); + GL_FUNCTION_FETCH(glTexParameteri, PFNGLTEXPARAMETERIPROC); + // GL_FUNCTION_FETCH(glTexParameteriv, PFNGLTEXPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glTexImage1D, PFNGLTEXIMAGE1DPROC); + GL_FUNCTION_FETCH(glTexImage2D, PFNGLTEXIMAGE2DPROC); +#if !defined(THORVG_GL_TARGET_GLES) + GL_FUNCTION_FETCH(glDrawBuffer, PFNGLDRAWBUFFERPROC); +#endif + GL_FUNCTION_FETCH(glClear, PFNGLCLEARPROC); + GL_FUNCTION_FETCH(glClearColor, PFNGLCLEARCOLORPROC); + GL_FUNCTION_FETCH(glClearStencil, PFNGLCLEARSTENCILPROC); +#if defined(THORVG_GL_TARGET_GLES) + GL_FUNCTION_FETCH(glClearDepthf, PFNGLCLEARDEPTHFPROC); +#else + GL_FUNCTION_FETCH(glClearDepth, PFNGLCLEARDEPTHPROC); +#endif + // GL_FUNCTION_FETCH(glStencilMask, PFNGLSTENCILMASKPROC); + GL_FUNCTION_FETCH(glColorMask, PFNGLCOLORMASKPROC); + GL_FUNCTION_FETCH(glDepthMask, PFNGLDEPTHMASKPROC); + GL_FUNCTION_FETCH(glDisable, PFNGLDISABLEPROC); + GL_FUNCTION_FETCH(glEnable, PFNGLENABLEPROC); + // GL_FUNCTION_FETCH(glFinish, PFNGLFINISHPROC); + // GL_FUNCTION_FETCH(glFlush, PFNGLFLUSHPROC); + GL_FUNCTION_FETCH(glBlendFunc, PFNGLBLENDFUNCPROC); + // GL_FUNCTION_FETCH(glLogicOp, PFNGLLOGICOPPROC); + GL_FUNCTION_FETCH(glStencilFunc, PFNGLSTENCILFUNCPROC); + GL_FUNCTION_FETCH(glStencilOp, PFNGLSTENCILOPPROC); + GL_FUNCTION_FETCH(glDepthFunc, PFNGLDEPTHFUNCPROC); + // GL_FUNCTION_FETCH(glPixelStoref, PFNGLPIXELSTOREFPROC); + // GL_FUNCTION_FETCH(glPixelStorei, PFNGLPIXELSTOREIPROC); + // GL_FUNCTION_FETCH(glReadBuffer, PFNGLREADBUFFERPROC); + // GL_FUNCTION_FETCH(glReadPixels, PFNGLREADPIXELSPROC); + // GL_FUNCTION_FETCH(glGetBooleanv, PFNGLGETBOOLEANVPROC); + // GL_FUNCTION_FETCH(glGetDoublev, PFNGLGETDOUBLEVPROC); + GL_FUNCTION_FETCH(glGetError, PFNGLGETERRORPROC); + // GL_FUNCTION_FETCH(glGetFloatv, PFNGLGETFLOATVPROC); + GL_FUNCTION_FETCH(glGetIntegerv, PFNGLGETINTEGERVPROC); + GL_FUNCTION_FETCH(glGetString, PFNGLGETSTRINGPROC); + // GL_FUNCTION_FETCH(glGetTexImage, PFNGLGETTEXIMAGEPROC); + // GL_FUNCTION_FETCH(glGetTexParameterfv, PFNGLGETTEXPARAMETERFVPROC); + // GL_FUNCTION_FETCH(glGetTexParameteriv, PFNGLGETTEXPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glGetTexLevelParameterfv, PFNGLGETTEXLEVELPARAMETERFVPROC); + // GL_FUNCTION_FETCH(glGetTexLevelParameteriv, PFNGLGETTEXLEVELPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glIsEnabled, PFNGLISENABLEDPROC); + // GL_FUNCTION_FETCH(glDepthRange, PFNGLDEPTHRANGEPROC); + GL_FUNCTION_FETCH(glViewport, PFNGLVIEWPORTPROC); + + // GL_VERSION_1_1 + // GL_FUNCTION_FETCH(glDrawArrays, PFNGLDRAWARRAYSPROC); + GL_FUNCTION_FETCH(glDrawElements, PFNGLDRAWELEMENTSPROC); + // GL_FUNCTION_FETCH(glGetPointerv, PFNGLGETPOINTERVPROC); + // GL_FUNCTION_FETCH(glPolygonOffset, PFNGLPOLYGONOFFSETPROC); + // GL_FUNCTION_FETCH(glCopyTexImage1D, PFNGLCOPYTEXIMAGE1DPROC); + // GL_FUNCTION_FETCH(glCopyTexImage2D, PFNGLCOPYTEXIMAGE2DPROC); + // GL_FUNCTION_FETCH(glCopyTexSubImage1D, PFNGLCOPYTEXSUBIMAGE1DPROC); + // GL_FUNCTION_FETCH(glCopyTexSubImage2D, PFNGLCOPYTEXSUBIMAGE2DPROC); + // GL_FUNCTION_FETCH(glTexSubImage1D, PFNGLTEXSUBIMAGE1DPROC); + // GL_FUNCTION_FETCH(glTexSubImage2D, PFNGLTEXSUBIMAGE2DPROC); + GL_FUNCTION_FETCH(glBindTexture, PFNGLBINDTEXTUREPROC); + GL_FUNCTION_FETCH(glDeleteTextures, PFNGLDELETETEXTURESPROC); + GL_FUNCTION_FETCH(glGenTextures, PFNGLGENTEXTURESPROC); + // GL_FUNCTION_FETCH(glIsTexture, PFNGLISTEXTUREPROC); + + // // GL_VERSION_1_2 + // GL_FUNCTION_FETCH(glDrawRangeElements, PFNGLDRAWRANGEELEMENTSPROC); + // GL_FUNCTION_FETCH(glTexImage3D, PFNGLTEXIMAGE3DPROC); + // GL_FUNCTION_FETCH(glTexSubImage3D, PFNGLTEXSUBIMAGE3DPROC); + // GL_FUNCTION_FETCH(glCopyTexSubImage3D, PFNGLCOPYTEXSUBIMAGE3DPROC); + + // // GL_VERSION_1_3 + GL_FUNCTION_FETCH(glActiveTexture, PFNGLACTIVETEXTUREPROC); + // GL_FUNCTION_FETCH(glSampleCoverage, PFNGLSAMPLECOVERAGEPROC); + // GL_FUNCTION_FETCH(glCompressedTexImage3D, PFNGLCOMPRESSEDTEXIMAGE3DPROC); + // GL_FUNCTION_FETCH(glCompressedTexImage2D, PFNGLCOMPRESSEDTEXIMAGE2DPROC); + // GL_FUNCTION_FETCH(glCompressedTexImage1D, PFNGLCOMPRESSEDTEXIMAGE1DPROC); + // GL_FUNCTION_FETCH(glCompressedTexSubImage3D, PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC); + // GL_FUNCTION_FETCH(glCompressedTexSubImage2D, PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC); + // GL_FUNCTION_FETCH(glCompressedTexSubImage1D, PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC); + // GL_FUNCTION_FETCH(glGetCompressedTexImage, PFNGLGETCOMPRESSEDTEXIMAGEPROC); + + // // GL_VERSION_1_4 + // GL_FUNCTION_FETCH(glBlendFuncSeparate, PFNGLBLENDFUNCSEPARATEPROC); + // GL_FUNCTION_FETCH(glMultiDrawArrays, PFNGLMULTIDRAWARRAYSPROC); + // GL_FUNCTION_FETCH(glMultiDrawElements, PFNGLMULTIDRAWELEMENTSPROC); + // GL_FUNCTION_FETCH(glPointParameterf, PFNGLPOINTPARAMETERFPROC); + // GL_FUNCTION_FETCH(glPointParameterfv, PFNGLPOINTPARAMETERFVPROC); + // GL_FUNCTION_FETCH(glPointParameteri, PFNGLPOINTPARAMETERIPROC); + // GL_FUNCTION_FETCH(glPointParameteriv, PFNGLPOINTPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glBlendColor, PFNGLBLENDCOLORPROC); + GL_FUNCTION_FETCH(glBlendEquation, PFNGLBLENDEQUATIONPROC); + + // GL_VERSION_1_5 + // GL_FUNCTION_FETCH(glGenQueries, PFNGLGENQUERIESPROC); + // GL_FUNCTION_FETCH(glDeleteQueries, PFNGLDELETEQUERIESPROC); + // GL_FUNCTION_FETCH(glIsQuery, PFNGLISQUERYPROC); + // GL_FUNCTION_FETCH(glBeginQuery, PFNGLBEGINQUERYPROC); + // GL_FUNCTION_FETCH(glEndQuery, PFNGLENDQUERYPROC); + // GL_FUNCTION_FETCH(glGetQueryiv, PFNGLGETQUERYIVPROC); + // GL_FUNCTION_FETCH(glGetQueryObjectiv, PFNGLGETQUERYOBJECTIVPROC); + // GL_FUNCTION_FETCH(glGetQueryObjectuiv, PFNGLGETQUERYOBJECTUIVPROC); + GL_FUNCTION_FETCH(glBindBuffer, PFNGLBINDBUFFERPROC); + GL_FUNCTION_FETCH(glDeleteBuffers, PFNGLDELETEBUFFERSPROC); + GL_FUNCTION_FETCH(glGenBuffers, PFNGLGENBUFFERSPROC); + // GL_FUNCTION_FETCH(glIsBuffer, PFNGLISBUFFERPROC); + GL_FUNCTION_FETCH(glBufferData, PFNGLBUFFERDATAPROC); + // GL_FUNCTION_FETCH(glBufferSubData, PFNGLBUFFERSUBDATAPROC); + // GL_FUNCTION_FETCH(glGetBufferSubData, PFNGLGETBUFFERSUBDATAPROC); + // GL_FUNCTION_FETCH(glMapBuffer, PFNGLMAPBUFFERPROC); + // GL_FUNCTION_FETCH(glUnmapBuffer, PFNGLUNMAPBUFFERPROC); + // GL_FUNCTION_FETCH(glGetBufferParameteriv, PFNGLGETBUFFERPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glGetBufferPointerv, PFNGLGETBUFFERPOINTERVPROC); + + // GL_VERSION_2_0 + // GL_FUNCTION_FETCH(glBlendEquationSeparate, PFNGLBLENDEQUATIONSEPARATEPROC); +#if defined(THORVG_GL_TARGET_GLES) + GL_FUNCTION_FETCH(glDrawBuffers, PFNGLDRAWBUFFERSPROC); +#endif + GL_FUNCTION_FETCH(glStencilOpSeparate, PFNGLSTENCILOPSEPARATEPROC); + GL_FUNCTION_FETCH(glStencilFuncSeparate, PFNGLSTENCILFUNCSEPARATEPROC); + // GL_FUNCTION_FETCH(glStencilMaskSeparate, PFNGLSTENCILMASKSEPARATEPROC); + GL_FUNCTION_FETCH(glAttachShader, PFNGLATTACHSHADERPROC); + // GL_FUNCTION_FETCH(glBindAttribLocation, PFNGLBINDATTRIBLOCATIONPROC); + GL_FUNCTION_FETCH(glCompileShader, PFNGLCOMPILESHADERPROC); + GL_FUNCTION_FETCH(glCreateProgram, PFNGLCREATEPROGRAMPROC); + GL_FUNCTION_FETCH(glCreateShader, PFNGLCREATESHADERPROC); + GL_FUNCTION_FETCH(glDeleteProgram, PFNGLDELETEPROGRAMPROC); + GL_FUNCTION_FETCH(glDeleteShader, PFNGLDELETESHADERPROC); + // GL_FUNCTION_FETCH(glDetachShader, PFNGLDETACHSHADERPROC); + GL_FUNCTION_FETCH(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC); + GL_FUNCTION_FETCH(glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC); + // GL_FUNCTION_FETCH(glGetActiveAttrib, PFNGLGETACTIVEATTRIBPROC); + // GL_FUNCTION_FETCH(glGetActiveUniform, PFNGLGETACTIVEUNIFORMPROC); + // GL_FUNCTION_FETCH(glGetAttachedShaders, PFNGLGETATTACHEDSHADERSPROC); + GL_FUNCTION_FETCH(glGetAttribLocation, PFNGLGETATTRIBLOCATIONPROC); + GL_FUNCTION_FETCH(glGetProgramiv, PFNGLGETPROGRAMIVPROC); + GL_FUNCTION_FETCH(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC); + GL_FUNCTION_FETCH(glGetShaderiv, PFNGLGETSHADERIVPROC); + GL_FUNCTION_FETCH(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC); + // GL_FUNCTION_FETCH(glGetShaderSource, PFNGLGETSHADERSOURCEPROC); + GL_FUNCTION_FETCH(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC); + // GL_FUNCTION_FETCH(glGetUniformfv, PFNGLGETUNIFORMFVPROC); + // GL_FUNCTION_FETCH(glGetUniformiv, PFNGLGETUNIFORMIVPROC); + // GL_FUNCTION_FETCH(glGetVertexAttribdv, PFNGLGETVERTEXATTRIBDVPROC); + // GL_FUNCTION_FETCH(glGetVertexAttribfv, PFNGLGETVERTEXATTRIBFVPROC); + // GL_FUNCTION_FETCH(glGetVertexAttribiv, PFNGLGETVERTEXATTRIBIVPROC); + // GL_FUNCTION_FETCH(glGetVertexAttribPointerv, PFNGLGETVERTEXATTRIBPOINTERVPROC); + // GL_FUNCTION_FETCH(glIsProgram, PFNGLISPROGRAMPROC); + // GL_FUNCTION_FETCH(glIsShader, PFNGLISSHADERPROC); + GL_FUNCTION_FETCH(glLinkProgram, PFNGLLINKPROGRAMPROC); + GL_FUNCTION_FETCH(glShaderSource, PFNGLSHADERSOURCEPROC); + GL_FUNCTION_FETCH(glUseProgram, PFNGLUSEPROGRAMPROC); + GL_FUNCTION_FETCH(glUniform1f, PFNGLUNIFORM1FPROC); + // GL_FUNCTION_FETCH(glUniform2f, PFNGLUNIFORM2FPROC); + // GL_FUNCTION_FETCH(glUniform3f, PFNGLUNIFORM3FPROC); + // GL_FUNCTION_FETCH(glUniform4f, PFNGLUNIFORM4FPROC); + // GL_FUNCTION_FETCH(glUniform1i, PFNGLUNIFORM1IPROC); + // GL_FUNCTION_FETCH(glUniform2i, PFNGLUNIFORM2IPROC); + // GL_FUNCTION_FETCH(glUniform3i, PFNGLUNIFORM3IPROC); + // GL_FUNCTION_FETCH(glUniform4i, PFNGLUNIFORM4IPROC); + GL_FUNCTION_FETCH(glUniform1fv, PFNGLUNIFORM1FVPROC); + GL_FUNCTION_FETCH(glUniform2fv, PFNGLUNIFORM2FVPROC); + GL_FUNCTION_FETCH(glUniform3fv, PFNGLUNIFORM3FVPROC); + GL_FUNCTION_FETCH(glUniform4fv, PFNGLUNIFORM4FVPROC); + GL_FUNCTION_FETCH(glUniform1iv, PFNGLUNIFORM1IVPROC); + GL_FUNCTION_FETCH(glUniform2iv, PFNGLUNIFORM2IVPROC); + GL_FUNCTION_FETCH(glUniform3iv, PFNGLUNIFORM3IVPROC); + GL_FUNCTION_FETCH(glUniform4iv, PFNGLUNIFORM4IVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix2fv, PFNGLUNIFORMMATRIX2FVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix3fv, PFNGLUNIFORMMATRIX3FVPROC); + GL_FUNCTION_FETCH(glUniformMatrix4fv, PFNGLUNIFORMMATRIX4FVPROC); + // GL_FUNCTION_FETCH(glValidateProgram, PFNGLVALIDATEPROGRAMPROC); + // GL_FUNCTION_FETCH(glVertexAttrib1d, PFNGLVERTEXATTRIB1DPROC); + // GL_FUNCTION_FETCH(glVertexAttrib1dv, PFNGLVERTEXATTRIB1DVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib1f, PFNGLVERTEXATTRIB1FPROC); + // GL_FUNCTION_FETCH(glVertexAttrib1fv, PFNGLVERTEXATTRIB1FVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib1s, PFNGLVERTEXATTRIB1SPROC); + // GL_FUNCTION_FETCH(glVertexAttrib1sv, PFNGLVERTEXATTRIB1SVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib2d, PFNGLVERTEXATTRIB2DPROC); + // GL_FUNCTION_FETCH(glVertexAttrib2dv, PFNGLVERTEXATTRIB2DVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib2f, PFNGLVERTEXATTRIB2FPROC); + // GL_FUNCTION_FETCH(glVertexAttrib2fv, PFNGLVERTEXATTRIB2FVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib2s, PFNGLVERTEXATTRIB2SPROC); + // GL_FUNCTION_FETCH(glVertexAttrib2sv, PFNGLVERTEXATTRIB2SVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib3d, PFNGLVERTEXATTRIB3DPROC); + // GL_FUNCTION_FETCH(glVertexAttrib3dv, PFNGLVERTEXATTRIB3DVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib3f, PFNGLVERTEXATTRIB3FPROC); + // GL_FUNCTION_FETCH(glVertexAttrib3fv, PFNGLVERTEXATTRIB3FVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib3s, PFNGLVERTEXATTRIB3SPROC); + // GL_FUNCTION_FETCH(glVertexAttrib3sv, PFNGLVERTEXATTRIB3SVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Nbv, PFNGLVERTEXATTRIB4NBVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Niv, PFNGLVERTEXATTRIB4NIVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Nsv, PFNGLVERTEXATTRIB4NSVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Nub, PFNGLVERTEXATTRIB4NUBPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Nubv, PFNGLVERTEXATTRIB4NUBVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Nuiv, PFNGLVERTEXATTRIB4NUIVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4Nusv, PFNGLVERTEXATTRIB4NUSVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4bv, PFNGLVERTEXATTRIB4BVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4d, PFNGLVERTEXATTRIB4DPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4dv, PFNGLVERTEXATTRIB4DVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4f, PFNGLVERTEXATTRIB4FPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4fv, PFNGLVERTEXATTRIB4FVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4iv, PFNGLVERTEXATTRIB4IVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4s, PFNGLVERTEXATTRIB4SPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4sv, PFNGLVERTEXATTRIB4SVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4ubv, PFNGLVERTEXATTRIB4UBVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4uiv, PFNGLVERTEXATTRIB4UIVPROC); + // GL_FUNCTION_FETCH(glVertexAttrib4usv, PFNGLVERTEXATTRIB4USVPROC); + GL_FUNCTION_FETCH(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC); + + // // GL_VERSION_2_1 + // GL_FUNCTION_FETCH(glUniformMatrix2x3fv, PFNGLUNIFORMMATRIX2X3FVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix3x2fv, PFNGLUNIFORMMATRIX3X2FVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix2x4fv, PFNGLUNIFORMMATRIX2X4FVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix4x2fv, PFNGLUNIFORMMATRIX4X2FVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix3x4fv, PFNGLUNIFORMMATRIX3X4FVPROC); + // GL_FUNCTION_FETCH(glUniformMatrix4x3fv, PFNGLUNIFORMMATRIX4X3FVPROC); + + // GL_VERSION_3_0 + // GL_FUNCTION_FETCH(glColorMaski, PFNGLCOLORMASKIPROC); + // GL_FUNCTION_FETCH(glGetBooleani_v, PFNGLGETBOOLEANI_VPROC); + // GL_FUNCTION_FETCH(glGetIntegeri_v, PFNGLGETINTEGERI_VPROC); + // GL_FUNCTION_FETCH(glEnablei, PFNGLENABLEIPROC); + // GL_FUNCTION_FETCH(glDisablei, PFNGLDISABLEIPROC); + // GL_FUNCTION_FETCH(glIsEnabledi, PFNGLISENABLEDIPROC); + // GL_FUNCTION_FETCH(glBeginTransformFeedback, PFNGLBEGINTRANSFORMFEEDBACKPROC); + // GL_FUNCTION_FETCH(glEndTransformFeedback, PFNGLENDTRANSFORMFEEDBACKPROC); + GL_FUNCTION_FETCH(glBindBufferRange, PFNGLBINDBUFFERRANGEPROC); + // GL_FUNCTION_FETCH(glBindBufferBase, PFNGLBINDBUFFERBASEPROC); + // GL_FUNCTION_FETCH(glTransformFeedbackVaryings, PFNGLTRANSFORMFEEDBACKVARYINGSPROC); + // GL_FUNCTION_FETCH(glGetTransformFeedbackVarying, PFNGLGETTRANSFORMFEEDBACKVARYINGPROC); + // GL_FUNCTION_FETCH(glClampColor, PFNGLCLAMPCOLORPROC); + // GL_FUNCTION_FETCH(glBeginConditionalRender, PFNGLBEGINCONDITIONALRENDERPROC); + // GL_FUNCTION_FETCH(glEndConditionalRender, PFNGLENDCONDITIONALRENDERPROC); + // GL_FUNCTION_FETCH(glVertexAttribIPointer, PFNGLVERTEXATTRIBIPOINTERPROC); + // GL_FUNCTION_FETCH(glGetVertexAttribIiv, PFNGLGETVERTEXATTRIBIIVPROC); + // GL_FUNCTION_FETCH(glGetVertexAttribIuiv, PFNGLGETVERTEXATTRIBIUIVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI1i, PFNGLVERTEXATTRIBI1IPROC); + // GL_FUNCTION_FETCH(glVertexAttribI2i, PFNGLVERTEXATTRIBI2IPROC); + // GL_FUNCTION_FETCH(glVertexAttribI3i, PFNGLVERTEXATTRIBI3IPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4i, PFNGLVERTEXATTRIBI4IPROC); + // GL_FUNCTION_FETCH(glVertexAttribI1ui, PFNGLVERTEXATTRIBI1UIPROC); + // GL_FUNCTION_FETCH(glVertexAttribI2ui, PFNGLVERTEXATTRIBI2UIPROC); + // GL_FUNCTION_FETCH(glVertexAttribI3ui, PFNGLVERTEXATTRIBI3UIPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4ui, PFNGLVERTEXATTRIBI4UIPROC); + // GL_FUNCTION_FETCH(glVertexAttribI1iv, PFNGLVERTEXATTRIBI1IVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI2iv, PFNGLVERTEXATTRIBI2IVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI3iv, PFNGLVERTEXATTRIBI3IVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4iv, PFNGLVERTEXATTRIBI4IVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI1uiv, PFNGLVERTEXATTRIBI1UIVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI2uiv, PFNGLVERTEXATTRIBI2UIVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI3uiv, PFNGLVERTEXATTRIBI3UIVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4uiv, PFNGLVERTEXATTRIBI4UIVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4bv, PFNGLVERTEXATTRIBI4BVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4sv, PFNGLVERTEXATTRIBI4SVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4ubv, PFNGLVERTEXATTRIBI4UBVPROC); + // GL_FUNCTION_FETCH(glVertexAttribI4usv, PFNGLVERTEXATTRIBI4USVPROC); + // GL_FUNCTION_FETCH(glGetUniformuiv, PFNGLGETUNIFORMUIVPROC); + // GL_FUNCTION_FETCH(glBindFragDataLocation, PFNGLBINDFRAGDATALOCATIONPROC); + // GL_FUNCTION_FETCH(glGetFragDataLocation, PFNGLGETFRAGDATALOCATIONPROC); + // GL_FUNCTION_FETCH(glUniform1ui, PFNGLUNIFORM1UIPROC); + // GL_FUNCTION_FETCH(glUniform2ui, PFNGLUNIFORM2UIPROC); + // GL_FUNCTION_FETCH(glUniform3ui, PFNGLUNIFORM3UIPROC); + // GL_FUNCTION_FETCH(glUniform4ui, PFNGLUNIFORM4UIPROC); + // GL_FUNCTION_FETCH(glUniform1uiv, PFNGLUNIFORM1UIVPROC); + // GL_FUNCTION_FETCH(glUniform2uiv, PFNGLUNIFORM2UIVPROC); + // GL_FUNCTION_FETCH(glUniform3uiv, PFNGLUNIFORM3UIVPROC); + // GL_FUNCTION_FETCH(glUniform4uiv, PFNGLUNIFORM4UIVPROC); + // GL_FUNCTION_FETCH(glTexParameterIiv, PFNGLTEXPARAMETERIIVPROC); + // GL_FUNCTION_FETCH(glTexParameterIuiv, PFNGLTEXPARAMETERIUIVPROC); + // GL_FUNCTION_FETCH(glGetTexParameterIiv, PFNGLGETTEXPARAMETERIIVPROC); + // GL_FUNCTION_FETCH(glGetTexParameterIuiv, PFNGLGETTEXPARAMETERIUIVPROC); + // GL_FUNCTION_FETCH(glClearBufferiv, PFNGLCLEARBUFFERIVPROC); + // GL_FUNCTION_FETCH(glClearBufferuiv, PFNGLCLEARBUFFERUIVPROC); + // GL_FUNCTION_FETCH(glClearBufferfv, PFNGLCLEARBUFFERFVPROC); + // GL_FUNCTION_FETCH(glClearBufferfi, PFNGLCLEARBUFFERFIPROC); + // GL_FUNCTION_FETCH(glGetStringi, PFNGLGETSTRINGIPROC); + // GL_FUNCTION_FETCH(glIsRenderbuffer, PFNGLISRENDERBUFFERPROC); + GL_FUNCTION_FETCH(glBindRenderbuffer, PFNGLBINDRENDERBUFFERPROC); + GL_FUNCTION_FETCH(glDeleteRenderbuffers, PFNGLDELETERENDERBUFFERSPROC); + GL_FUNCTION_FETCH(glGenRenderbuffers, PFNGLGENRENDERBUFFERSPROC); + // GL_FUNCTION_FETCH(glRenderbufferStorage, PFNGLRENDERBUFFERSTORAGEPROC); + // GL_FUNCTION_FETCH(glGetRenderbufferParameteriv, PFNGLGETRENDERBUFFERPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glIsFramebuffer, PFNGLISFRAMEBUFFERPROC); +#if defined(THORVG_GL_TARGET_GLES) + GL_FUNCTION_FETCH(glInvalidateFramebuffer, PFNGLINVALIDATEFRAMEBUFFERPROC); +#endif + GL_FUNCTION_FETCH(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC); + GL_FUNCTION_FETCH(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC); + GL_FUNCTION_FETCH(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC); + // GL_FUNCTION_FETCH(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC); + // GL_FUNCTION_FETCH(glFramebufferTexture1D, PFNGLFRAMEBUFFERTEXTURE1DPROC); + GL_FUNCTION_FETCH(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC); + // GL_FUNCTION_FETCH(glFramebufferTexture3D, PFNGLFRAMEBUFFERTEXTURE3DPROC); + GL_FUNCTION_FETCH(glFramebufferRenderbuffer, PFNGLFRAMEBUFFERRENDERBUFFERPROC); + // GL_FUNCTION_FETCH(glGetFramebufferAttachmentParameteriv, PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC); + // GL_FUNCTION_FETCH(glGenerateMipmap, PFNGLGENERATEMIPMAPPROC); + GL_FUNCTION_FETCH(glBlitFramebuffer, PFNGLBLITFRAMEBUFFERPROC); + GL_FUNCTION_FETCH(glRenderbufferStorageMultisample, PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC); + // GL_FUNCTION_FETCH(glFramebufferTextureLayer, PFNGLFRAMEBUFFERTEXTURELAYERPROC); + // GL_FUNCTION_FETCH(glMapBufferRange, PFNGLMAPBUFFERRANGEPROC); + // GL_FUNCTION_FETCH(glFlushMappedBufferRange, PFNGLFLUSHMAPPEDBUFFERRANGEPROC); + GL_FUNCTION_FETCH(glBindVertexArray, PFNGLBINDVERTEXARRAYPROC); + GL_FUNCTION_FETCH(glDeleteVertexArrays, PFNGLDELETEVERTEXARRAYSPROC); + GL_FUNCTION_FETCH(glGenVertexArrays, PFNGLGENVERTEXARRAYSPROC); + // GL_FUNCTION_FETCH(glIsVertexArray, PFNGLISVERTEXARRAYPROC); + + // GL_VERSION_3_1 + // GL_FUNCTION_FETCH(glDrawArraysInstanced, PFNGLDRAWARRAYSINSTANCEDPROC); + // GL_FUNCTION_FETCH(glDrawElementsInstanced, PFNGLDRAWELEMENTSINSTANCEDPROC); + // GL_FUNCTION_FETCH(glTexBuffer, PFNGLTEXBUFFERPROC); + // GL_FUNCTION_FETCH(glPrimitiveRestartIndex, PFNGLPRIMITIVERESTARTINDEXPROC); + // GL_FUNCTION_FETCH(glCopyBufferSubData, PFNGLCOPYBUFFERSUBDATAPROC); + // GL_FUNCTION_FETCH(glGetUniformIndices, PFNGLGETUNIFORMINDICESPROC); + // GL_FUNCTION_FETCH(glGetActiveUniformsiv, PFNGLGETACTIVEUNIFORMSIVPROC); + // GL_FUNCTION_FETCH(glGetActiveUniformName, PFNGLGETACTIVEUNIFORMNAMEPROC); + GL_FUNCTION_FETCH(glGetUniformBlockIndex, PFNGLGETUNIFORMBLOCKINDEXPROC); + // GL_FUNCTION_FETCH(glGetActiveUniformBlockiv, PFNGLGETACTIVEUNIFORMBLOCKIVPROC); + // GL_FUNCTION_FETCH(glGetActiveUniformBlockName, PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC); + GL_FUNCTION_FETCH(glUniformBlockBinding, PFNGLUNIFORMBLOCKBINDINGPROC); + +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(THORVG_GL_TARGET_GL) + tvgWglGetCurrentContext = (PFNWGLGETCURRENTCONTEXTPROC)GetProcAddress(_libGL, "wglGetCurrentContext"); + tvgWglMakeCurrent = (PFNWGLMAKECURRENTPROC)GetProcAddress(_libGL, "wglMakeCurrent"); + if (!tvgWglGetCurrentContext || !tvgWglMakeCurrent) { + TVGERR("GL_ENGINE", "Failed to load WGL context management functions."); + return false; + } +#endif + +#if defined(THORVG_GL_TARGET_GLES) + #if defined(_WIN32) && !defined(__CYGWIN__) + if (!_libEGL) _libEGL = LoadLibraryW(L"libEGL.dll"); + if (!_libEGL) _libEGL = LoadLibraryW(L"EGL.dll"); + if (!_libEGL) { + TVGERR("GL_ENGINE", "Cannot find EGL library."); + return false; + } + tvgEglGetCurrentContext = (PFNEGLGETCURRENTCONTEXTPROC)GetProcAddress(_libEGL, "eglGetCurrentContext"); + tvgEglMakeCurrent = (PFNEGLMAKECURRENTPROC)GetProcAddress(_libEGL, "eglMakeCurrent"); + #else + if (!_libEGL) _libEGL = dlopen("libEGL.so.1", RTLD_LAZY); + if (!_libEGL) _libEGL = dlopen("libEGL.so", RTLD_LAZY); + if (!_libEGL) { + TVGERR("GL_ENGINE", "Cannot find EGL library."); + return false; + } + tvgEglGetCurrentContext = (PFNEGLGETCURRENTCONTEXTPROC)dlsym(_libEGL, "eglGetCurrentContext"); + tvgEglMakeCurrent = (PFNEGLMAKECURRENTPROC)dlsym(_libEGL, "eglMakeCurrent"); + #endif + if (!tvgEglGetCurrentContext || !tvgEglMakeCurrent) { + TVGERR("GL_ENGINE", "Failed to load EGL context management functions."); + return false; + } +#endif + + //Confirm the version + GLint vMajor, vMinor; + glGetIntegerv(GL_MAJOR_VERSION, &vMajor); + glGetIntegerv(GL_MINOR_VERSION, &vMinor); + if (vMajor < TVG_REQUIRE_GL_MAJOR_VER || (vMajor == TVG_REQUIRE_GL_MAJOR_VER && vMinor < TVG_REQUIRE_GL_MINOR_VER)) { + TVGERR("GL_ENGINE", "OpenGL/ES version is not satisfied. Current: v%d.%d, Required: v%d.%d", vMajor, vMinor, TVG_REQUIRE_GL_MAJOR_VER, TVG_REQUIRE_GL_MINOR_VER); + return false; + } + + TVGLOG("GL_ENGINE", "OpenGL/ES version = v%d.%d", vMajor, vMinor); + + return true; +}; + + +bool glTerm() +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + if (_libGL) FreeLibrary(_libGL); + #if defined(THORVG_GL_TARGET_GLES) + if (_libEGL) FreeLibrary(_libEGL); + #endif +#else + if (_libGL) dlclose(_libGL); + #if defined(THORVG_GL_TARGET_GLES) + if (_libEGL) dlclose(_libEGL); + #endif +#endif + + return true; +} + +#endif // __EMSCRIPTEN__ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGl.h b/components/thorvg-main/src/renderer/gl_engine/tvgGl.h new file mode 100644 index 0000000..46b5f2f --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGl.h @@ -0,0 +1,1517 @@ +/* + * Copyright (c) 2025 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + #ifndef _TVG_GL_H_ + #define _TVG_GL_H_ + +#ifdef __EMSCRIPTEN__ + #include + #include + #define GL_CHECK(stmt) stmt +#else //__EMSCRIPTEN__ + #if defined (THORVG_GL_TARGET_GLES) + #define TVG_REQUIRE_GL_MAJOR_VER 3 + #define TVG_REQUIRE_GL_MINOR_VER 0 + #else + #define TVG_REQUIRE_GL_MAJOR_VER 3 + #define TVG_REQUIRE_GL_MINOR_VER 3 + #endif + + #include "tvgCommon.h" + + #ifdef _DEBUG + #define GL_CHECK(stmt) stmt; assert(glGetError() == GL_NO_ERROR); + #else + #define GL_CHECK(stmt) stmt + #endif + + #ifdef _WIN64 + typedef signed long long int khronos_intptr_t; + typedef unsigned long long int khronos_uintptr_t; + typedef signed long long int khronos_ssize_t; + typedef unsigned long long int khronos_usize_t; + #else + typedef signed long int khronos_intptr_t; + typedef unsigned long int khronos_uintptr_t; + typedef signed long int khronos_ssize_t; + typedef unsigned long int khronos_usize_t; + #endif + + typedef signed char khronos_int8_t; + typedef unsigned char khronos_uint8_t; + typedef signed short int khronos_int16_t; + typedef unsigned short int khronos_uint16_t; + typedef float khronos_float_t; + typedef khronos_intptr_t GLintptr; + typedef khronos_ssize_t GLsizeiptr; + + #ifndef GL_VERSION_1_0 + #define GL_VERSION_1_0 1 + typedef void GLvoid; + typedef unsigned int GLenum; + typedef khronos_float_t GLfloat; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLbitfield; + typedef double GLdouble; + typedef unsigned int GLuint; + typedef unsigned char GLboolean; + typedef khronos_uint8_t GLubyte; + #define GL_DEPTH_BUFFER_BIT 0x00000100 + #define GL_STENCIL_BUFFER_BIT 0x00000400 + #define GL_COLOR_BUFFER_BIT 0x00004000 + #define GL_FALSE 0 + #define GL_TRUE 1 + #define GL_POINTS 0x0000 + #define GL_LINES 0x0001 + #define GL_LINE_LOOP 0x0002 + #define GL_LINE_STRIP 0x0003 + #define GL_TRIANGLES 0x0004 + #define GL_TRIANGLE_STRIP 0x0005 + #define GL_TRIANGLE_FAN 0x0006 + #define GL_QUADS 0x0007 + #define GL_NEVER 0x0200 + #define GL_LESS 0x0201 + #define GL_EQUAL 0x0202 + #define GL_LEQUAL 0x0203 + #define GL_GREATER 0x0204 + #define GL_NOTEQUAL 0x0205 + #define GL_GEQUAL 0x0206 + #define GL_ALWAYS 0x0207 + #define GL_ZERO 0 + #define GL_ONE 1 + #define GL_SRC_COLOR 0x0300 + #define GL_ONE_MINUS_SRC_COLOR 0x0301 + #define GL_SRC_ALPHA 0x0302 + #define GL_ONE_MINUS_SRC_ALPHA 0x0303 + #define GL_DST_ALPHA 0x0304 + #define GL_ONE_MINUS_DST_ALPHA 0x0305 + #define GL_DST_COLOR 0x0306 + #define GL_ONE_MINUS_DST_COLOR 0x0307 + #define GL_SRC_ALPHA_SATURATE 0x0308 + #define GL_NONE 0 + #define GL_FRONT_LEFT 0x0400 + #define GL_FRONT_RIGHT 0x0401 + #define GL_BACK_LEFT 0x0402 + #define GL_BACK_RIGHT 0x0403 + #define GL_FRONT 0x0404 + #define GL_BACK 0x0405 + #define GL_LEFT 0x0406 + #define GL_RIGHT 0x0407 + #define GL_FRONT_AND_BACK 0x0408 + #define GL_NO_ERROR 0 + #define GL_INVALID_ENUM 0x0500 + #define GL_INVALID_VALUE 0x0501 + #define GL_INVALID_OPERATION 0x0502 + #define GL_OUT_OF_MEMORY 0x0505 + #define GL_CW 0x0900 + #define GL_CCW 0x0901 + #define GL_POINT_SIZE 0x0B11 + #define GL_POINT_SIZE_RANGE 0x0B12 + #define GL_POINT_SIZE_GRANULARITY 0x0B13 + #define GL_LINE_SMOOTH 0x0B20 + #define GL_LINE_WIDTH 0x0B21 + #define GL_LINE_WIDTH_RANGE 0x0B22 + #define GL_LINE_WIDTH_GRANULARITY 0x0B23 + #define GL_POLYGON_MODE 0x0B40 + #define GL_POLYGON_SMOOTH 0x0B41 + #define GL_CULL_FACE 0x0B44 + #define GL_CULL_FACE_MODE 0x0B45 + #define GL_FRONT_FACE 0x0B46 + #define GL_DEPTH_RANGE 0x0B70 + #define GL_DEPTH_TEST 0x0B71 + #define GL_DEPTH_WRITEMASK 0x0B72 + #define GL_DEPTH_CLEAR_VALUE 0x0B73 + #define GL_DEPTH_FUNC 0x0B74 + #define GL_STENCIL_TEST 0x0B90 + #define GL_STENCIL_CLEAR_VALUE 0x0B91 + #define GL_STENCIL_FUNC 0x0B92 + #define GL_STENCIL_VALUE_MASK 0x0B93 + #define GL_STENCIL_FAIL 0x0B94 + #define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 + #define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 + #define GL_STENCIL_REF 0x0B97 + #define GL_STENCIL_WRITEMASK 0x0B98 + #define GL_VIEWPORT 0x0BA2 + #define GL_DITHER 0x0BD0 + #define GL_BLEND_DST 0x0BE0 + #define GL_BLEND_SRC 0x0BE1 + #define GL_BLEND 0x0BE2 + #define GL_LOGIC_OP_MODE 0x0BF0 + #define GL_DRAW_BUFFER 0x0C01 + #define GL_READ_BUFFER 0x0C02 + #define GL_SCISSOR_BOX 0x0C10 + #define GL_SCISSOR_TEST 0x0C11 + #define GL_COLOR_CLEAR_VALUE 0x0C22 + #define GL_COLOR_WRITEMASK 0x0C23 + #define GL_DOUBLEBUFFER 0x0C32 + #define GL_STEREO 0x0C33 + #define GL_LINE_SMOOTH_HINT 0x0C52 + #define GL_POLYGON_SMOOTH_HINT 0x0C53 + #define GL_UNPACK_SWAP_BYTES 0x0CF0 + #define GL_UNPACK_LSB_FIRST 0x0CF1 + #define GL_UNPACK_ROW_LENGTH 0x0CF2 + #define GL_UNPACK_SKIP_ROWS 0x0CF3 + #define GL_UNPACK_SKIP_PIXELS 0x0CF4 + #define GL_UNPACK_ALIGNMENT 0x0CF5 + #define GL_PACK_SWAP_BYTES 0x0D00 + #define GL_PACK_LSB_FIRST 0x0D01 + #define GL_PACK_ROW_LENGTH 0x0D02 + #define GL_PACK_SKIP_ROWS 0x0D03 + #define GL_PACK_SKIP_PIXELS 0x0D04 + #define GL_PACK_ALIGNMENT 0x0D05 + #define GL_MAX_TEXTURE_SIZE 0x0D33 + #define GL_MAX_VIEWPORT_DIMS 0x0D3A + #define GL_SUBPIXEL_BITS 0x0D50 + #define GL_TEXTURE_1D 0x0DE0 + #define GL_TEXTURE_2D 0x0DE1 + #define GL_TEXTURE_WIDTH 0x1000 + #define GL_TEXTURE_HEIGHT 0x1001 + #define GL_TEXTURE_BORDER_COLOR 0x1004 + #define GL_DONT_CARE 0x1100 + #define GL_FASTEST 0x1101 + #define GL_NICEST 0x1102 + #define GL_BYTE 0x1400 + #define GL_UNSIGNED_BYTE 0x1401 + #define GL_SHORT 0x1402 + #define GL_UNSIGNED_SHORT 0x1403 + #define GL_INT 0x1404 + #define GL_UNSIGNED_INT 0x1405 + #define GL_FLOAT 0x1406 + #define GL_STACK_OVERFLOW 0x0503 + #define GL_STACK_UNDERFLOW 0x0504 + #define GL_CLEAR 0x1500 + #define GL_AND 0x1501 + #define GL_AND_REVERSE 0x1502 + #define GL_COPY 0x1503 + #define GL_AND_INVERTED 0x1504 + #define GL_NOOP 0x1505 + #define GL_XOR 0x1506 + #define GL_OR 0x1507 + #define GL_NOR 0x1508 + #define GL_EQUIV 0x1509 + #define GL_INVERT 0x150A + #define GL_OR_REVERSE 0x150B + #define GL_COPY_INVERTED 0x150C + #define GL_OR_INVERTED 0x150D + #define GL_NAND 0x150E + #define GL_SET 0x150F + #define GL_TEXTURE 0x1702 + #define GL_COLOR 0x1800 + #define GL_DEPTH 0x1801 + #define GL_STENCIL 0x1802 + #define GL_STENCIL_INDEX 0x1901 + #define GL_DEPTH_COMPONENT 0x1902 + #define GL_RED 0x1903 + #define GL_GREEN 0x1904 + #define GL_BLUE 0x1905 + #define GL_ALPHA 0x1906 + #define GL_RGB 0x1907 + #define GL_RGBA 0x1908 + #define GL_POINT 0x1B00 + #define GL_LINE 0x1B01 + #define GL_FILL 0x1B02 + #define GL_KEEP 0x1E00 + #define GL_REPLACE 0x1E01 + #define GL_INCR 0x1E02 + #define GL_DECR 0x1E03 + #define GL_VENDOR 0x1F00 + #define GL_RENDERER 0x1F01 + #define GL_VERSION 0x1F02 + #define GL_EXTENSIONS 0x1F03 + #define GL_NEAREST 0x2600 + #define GL_LINEAR 0x2601 + #define GL_NEAREST_MIPMAP_NEAREST 0x2700 + #define GL_LINEAR_MIPMAP_NEAREST 0x2701 + #define GL_NEAREST_MIPMAP_LINEAR 0x2702 + #define GL_LINEAR_MIPMAP_LINEAR 0x2703 + #define GL_TEXTURE_MAG_FILTER 0x2800 + #define GL_TEXTURE_MIN_FILTER 0x2801 + #define GL_TEXTURE_WRAP_S 0x2802 + #define GL_TEXTURE_WRAP_T 0x2803 + #define GL_REPEAT 0x2901 + typedef void (*PFNGLCULLFACEPROC)(GLenum mode); + typedef void (*PFNGLFRONTFACEPROC)(GLenum mode); + typedef void (*PFNGLSCISSORPROC)(GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (*PFNGLTEXPARAMETERIPROC)(GLenum target, GLenum pname, GLint param); + typedef void (*PFNGLTEXIMAGE2DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); + typedef void (*PFNGLDRAWBUFFERPROC)(GLenum buf); + typedef void (*PFNGLCLEARPROC)(GLbitfield mask); + typedef void (*PFNGLCLEARCOLORPROC)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + typedef void (*PFNGLCLEARSTENCILPROC)(GLint s); + typedef void (*PFNGLCLEARDEPTHPROC)(GLdouble depth); + typedef void (*PFNGLCLEARDEPTHFPROC)(GLdouble depth); // GLES + typedef void (*PFNGLCOLORMASKPROC)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + typedef void (*PFNGLDEPTHMASKPROC)(GLboolean flag); + typedef void (*PFNGLDISABLEPROC)(GLenum cap); + typedef void (*PFNGLENABLEPROC)(GLenum cap); + typedef void (*PFNGLBLENDFUNCPROC)(GLenum sfactor, GLenum dfactor); + typedef void (*PFNGLSTENCILFUNCPROC)(GLenum func, GLint ref, GLuint mask); + typedef void (*PFNGLSTENCILOPPROC)(GLenum fail, GLenum zfail, GLenum zpass); + typedef void (*PFNGLDEPTHFUNCPROC)(GLenum func); + typedef GLenum (*PFNGLGETERRORPROC)(void); + typedef void (*PFNGLGETINTEGERVPROC)(GLenum pname, GLint *data); + typedef const GLubyte *(*PFNGLGETSTRINGPROC) (GLenum name); + typedef void (*PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); + //typedef void (*PFNGLHINTPROC)(GLenum target, GLenum mode); + //typedef void (*PFNGLLINEWIDTHPROC)(GLfloat width); + //typedef void (*PFNGLPOINTSIZEPROC)(GLfloat size); + //typedef void (*PFNGLPOLYGONMODEPROC)(GLenum face, GLenum mode); + //typedef void (*PFNGLTEXPARAMETERFPROC)(GLenum target, GLenum pname, GLfloat param); + //typedef void (*PFNGLTEXPARAMETERFVPROC)(GLenum target, GLenum pname, const GLfloat *params); + //typedef void (*PFNGLTEXPARAMETERIVPROC)(GLenum target, GLenum pname, const GLint *params); + //typedef void (*PFNGLTEXIMAGE1DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels); + //typedef void (*PFNGLSTENCILMASKPROC) (GLuint mask); + //typedef void (*PFNGLFINISHPROC)(void); + //typedef void (*PFNGLFLUSHPROC)(void); + //typedef void (*PFNGLLOGICOPPROC)(GLenum opcode); + //typedef void (*PFNGLPIXELSTOREFPROC)(GLenum pname, GLfloat param); + //typedef void (*PFNGLPIXELSTOREIPROC)(GLenum pname, GLint param); + //typedef void (*PFNGLREADBUFFERPROC)(GLenum src); + //typedef void (*PFNGLREADPIXELSPROC)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); + //typedef void (*PFNGLGETBOOLEANVPROC)(GLenum pname, GLboolean *data); + //typedef void (*PFNGLGETDOUBLEVPROC)(GLenum pname, GLdouble *data); + //typedef void (*PFNGLGETFLOATVPROC)(GLenum pname, GLfloat *data); + //typedef void (*PFNGLGETTEXIMAGEPROC)(GLenum target, GLint level, GLenum format, GLenum type, void *pixels); + //typedef void (*PFNGLGETTEXPARAMETERFVPROC)(GLenum target, GLenum pname, GLfloat *params); + //typedef void (*PFNGLGETTEXPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params); + //typedef void (*PFNGLGETTEXLEVELPARAMETERFVPROC)(GLenum target, GLint level, GLenum pname, GLfloat *params); + //typedef void (*PFNGLGETTEXLEVELPARAMETERIVPROC)(GLenum target, GLint level, GLenum pname, GLint *params); + //typedef GLboolean (*PFNGLISENABLEDPROC)(GLenum cap); + //typedef void (*PFNGLDEPTHRANGEPROC)(GLdouble n, GLdouble f); + #endif /* GL_VERSION_1_0 */ + + #ifndef GL_VERSION_1_1 + #define GL_VERSION_1_1 1 + typedef khronos_float_t GLclampf; + typedef double GLclampd; + #define GL_COLOR_LOGIC_OP 0x0BF2 + #define GL_POLYGON_OFFSET_UNITS 0x2A00 + #define GL_POLYGON_OFFSET_POINT 0x2A01 + #define GL_POLYGON_OFFSET_LINE 0x2A02 + #define GL_POLYGON_OFFSET_FILL 0x8037 + #define GL_POLYGON_OFFSET_FACTOR 0x8038 + #define GL_TEXTURE_BINDING_1D 0x8068 + #define GL_TEXTURE_BINDING_2D 0x8069 + #define GL_TEXTURE_INTERNAL_FORMAT 0x1003 + #define GL_TEXTURE_RED_SIZE 0x805C + #define GL_TEXTURE_GREEN_SIZE 0x805D + #define GL_TEXTURE_BLUE_SIZE 0x805E + #define GL_TEXTURE_ALPHA_SIZE 0x805F + #define GL_DOUBLE 0x140A + #define GL_PROXY_TEXTURE_1D 0x8063 + #define GL_PROXY_TEXTURE_2D 0x8064 + #define GL_R3_G3_B2 0x2A10 + #define GL_RGB4 0x804F + #define GL_RGB5 0x8050 + #define GL_RGB8 0x8051 + #define GL_RGB10 0x8052 + #define GL_RGB12 0x8053 + #define GL_RGB16 0x8054 + #define GL_RGBA2 0x8055 + #define GL_RGBA4 0x8056 + #define GL_RGB5_A1 0x8057 + #define GL_RGBA8 0x8058 + #define GL_RGB10_A2 0x8059 + #define GL_RGBA12 0x805A + #define GL_RGBA16 0x805B + #define GL_VERTEX_ARRAY 0x8074 + typedef void (*PFNGLDRAWELEMENTSPROC)(GLenum mode, GLsizei count, GLenum type, const void *indices); + typedef void (*PFNGLBINDTEXTUREPROC)(GLenum target, GLuint texture); + typedef void (*PFNGLDELETETEXTURESPROC)(GLsizei n, const GLuint *textures); + typedef void (*PFNGLGENTEXTURESPROC)(GLsizei n, GLuint *textures); + //typedef void (*PFNGLDRAWARRAYSPROC)(GLenum mode, GLint first, GLsizei count); + //typedef void (*PFNGLGETPOINTERVPROC)(GLenum pname, void **params); + //typedef void (*PFNGLPOLYGONOFFSETPROC)(GLfloat factor, GLfloat units); + //typedef void (*PFNGLCOPYTEXIMAGE1DPROC)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); + //typedef void (*PFNGLCOPYTEXIMAGE2DPROC)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + //typedef void (*PFNGLCOPYTEXSUBIMAGE1DPROC)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); + //typedef void (*PFNGLCOPYTEXSUBIMAGE2DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + //typedef void (*PFNGLTEXSUBIMAGE1DPROC)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); + //typedef void (*PFNGLTEXSUBIMAGE2DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); + //typedef GLboolean (*PFNGLISTEXTUREPROC)(GLuint texture); + #endif /* GL_VERSION_1_1 */ + + #ifndef GL_VERSION_1_2 + #define GL_VERSION_1_2 1 + #define GL_UNSIGNED_BYTE_3_3_2 0x8032 + #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 + #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 + #define GL_UNSIGNED_INT_8_8_8_8 0x8035 + #define GL_UNSIGNED_INT_10_10_10_2 0x8036 + #define GL_TEXTURE_BINDING_3D 0x806A + #define GL_PACK_SKIP_IMAGES 0x806B + #define GL_PACK_IMAGE_HEIGHT 0x806C + #define GL_UNPACK_SKIP_IMAGES 0x806D + #define GL_UNPACK_IMAGE_HEIGHT 0x806E + #define GL_TEXTURE_3D 0x806F + #define GL_PROXY_TEXTURE_3D 0x8070 + #define GL_TEXTURE_DEPTH 0x8071 + #define GL_TEXTURE_WRAP_R 0x8072 + #define GL_MAX_3D_TEXTURE_SIZE 0x8073 + #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 + #define GL_UNSIGNED_SHORT_5_6_5 0x8363 + #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 + #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 + #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 + #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 + #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 + #define GL_BGR 0x80E0 + #define GL_BGRA 0x80E1 + #define GL_MAX_ELEMENTS_VERTICES 0x80E8 + #define GL_MAX_ELEMENTS_INDICES 0x80E9 + #define GL_CLAMP_TO_EDGE 0x812F + #define GL_TEXTURE_MIN_LOD 0x813A + #define GL_TEXTURE_MAX_LOD 0x813B + #define GL_TEXTURE_BASE_LEVEL 0x813C + #define GL_TEXTURE_MAX_LEVEL 0x813D + #define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 + #define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 + #define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 + #define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 + #define GL_ALIASED_LINE_WIDTH_RANGE 0x846E + //typedef void (*PFNGLDRAWRANGEELEMENTSPROC)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices); + //typedef void (*PFNGLTEXIMAGE3DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); + //typedef void (*PFNGLTEXSUBIMAGE3DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); + //typedef void (*PFNGLCOPYTEXSUBIMAGE3DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + #endif /* GL_VERSION_1_2 */ + + #ifndef GL_VERSION_1_3 + #define GL_VERSION_1_3 1 + #define GL_TEXTURE0 0x84C0 + #define GL_TEXTURE1 0x84C1 + #define GL_TEXTURE2 0x84C2 + #define GL_TEXTURE3 0x84C3 + #define GL_TEXTURE4 0x84C4 + #define GL_TEXTURE5 0x84C5 + #define GL_TEXTURE6 0x84C6 + #define GL_TEXTURE7 0x84C7 + #define GL_TEXTURE8 0x84C8 + #define GL_TEXTURE9 0x84C9 + #define GL_TEXTURE10 0x84CA + #define GL_TEXTURE11 0x84CB + #define GL_TEXTURE12 0x84CC + #define GL_TEXTURE13 0x84CD + #define GL_TEXTURE14 0x84CE + #define GL_TEXTURE15 0x84CF + #define GL_TEXTURE16 0x84D0 + #define GL_TEXTURE17 0x84D1 + #define GL_TEXTURE18 0x84D2 + #define GL_TEXTURE19 0x84D3 + #define GL_TEXTURE20 0x84D4 + #define GL_TEXTURE21 0x84D5 + #define GL_TEXTURE22 0x84D6 + #define GL_TEXTURE23 0x84D7 + #define GL_TEXTURE24 0x84D8 + #define GL_TEXTURE25 0x84D9 + #define GL_TEXTURE26 0x84DA + #define GL_TEXTURE27 0x84DB + #define GL_TEXTURE28 0x84DC + #define GL_TEXTURE29 0x84DD + #define GL_TEXTURE30 0x84DE + #define GL_TEXTURE31 0x84DF + #define GL_ACTIVE_TEXTURE 0x84E0 + #define GL_MULTISAMPLE 0x809D + #define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E + #define GL_SAMPLE_ALPHA_TO_ONE 0x809F + #define GL_SAMPLE_COVERAGE 0x80A0 + #define GL_SAMPLE_BUFFERS 0x80A8 + #define GL_SAMPLES 0x80A9 + #define GL_SAMPLE_COVERAGE_VALUE 0x80AA + #define GL_SAMPLE_COVERAGE_INVERT 0x80AB + #define GL_TEXTURE_CUBE_MAP 0x8513 + #define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 + #define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 + #define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 + #define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 + #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 + #define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 + #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A + #define GL_PROXY_TEXTURE_CUBE_MAP 0x851B + #define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + #define GL_COMPRESSED_RGB 0x84ED + #define GL_COMPRESSED_RGBA 0x84EE + #define GL_TEXTURE_COMPRESSION_HINT 0x84EF + #define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 + #define GL_TEXTURE_COMPRESSED 0x86A1 + #define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 + #define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + #define GL_CLAMP_TO_BORDER 0x812D + typedef void (*PFNGLACTIVETEXTUREPROC)(GLenum texture); + //typedef void (*PFNGLSAMPLECOVERAGEPROC)(GLfloat value, GLboolean invert); + //typedef void (*PFNGLCOMPRESSEDTEXIMAGE3DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); + //typedef void (*PFNGLCOMPRESSEDTEXIMAGE2DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); + //typedef void (*PFNGLCOMPRESSEDTEXIMAGE1DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data); + //typedef void (*PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); + //typedef void (*PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); + //typedef void (*PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); + //typedef void (*PFNGLGETCOMPRESSEDTEXIMAGEPROC)(GLenum target, GLint level, void *img); + #endif /* GL_VERSION_1_3 */ + + #ifndef GL_VERSION_1_4 + #define GL_VERSION_1_4 1 + #define GL_BLEND_DST_RGB 0x80C8 + #define GL_BLEND_SRC_RGB 0x80C9 + #define GL_BLEND_DST_ALPHA 0x80CA + #define GL_BLEND_SRC_ALPHA 0x80CB + #define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 + #define GL_DEPTH_COMPONENT16 0x81A5 + #define GL_DEPTH_COMPONENT24 0x81A6 + #define GL_DEPTH_COMPONENT32 0x81A7 + #define GL_MIRRORED_REPEAT 0x8370 + #define GL_MAX_TEXTURE_LOD_BIAS 0x84FD + #define GL_TEXTURE_LOD_BIAS 0x8501 + #define GL_INCR_WRAP 0x8507 + #define GL_DECR_WRAP 0x8508 + #define GL_TEXTURE_DEPTH_SIZE 0x884A + #define GL_TEXTURE_COMPARE_MODE 0x884C + #define GL_TEXTURE_COMPARE_FUNC 0x884D + #define GL_BLEND_COLOR 0x8005 + #define GL_BLEND_EQUATION 0x8009 + #define GL_CONSTANT_COLOR 0x8001 + #define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 + #define GL_CONSTANT_ALPHA 0x8003 + #define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 + #define GL_FUNC_ADD 0x8006 + #define GL_FUNC_REVERSE_SUBTRACT 0x800B + #define GL_FUNC_SUBTRACT 0x800A + #define GL_MIN 0x8007 + #define GL_MAX 0x8008 + typedef void (*PFNGLBLENDEQUATIONPROC)(GLenum mode); + //typedef void (*PFNGLBLENDFUNCSEPARATEPROC)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); + //typedef void (*PFNGLMULTIDRAWARRAYSPROC)(GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); + //typedef void (*PFNGLMULTIDRAWELEMENTSPROC)(GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount); + //typedef void (*PFNGLPOINTPARAMETERFPROC)(GLenum pname, GLfloat param); + //typedef void (*PFNGLPOINTPARAMETERFVPROC)(GLenum pname, const GLfloat *params); + //typedef void (*PFNGLPOINTPARAMETERIPROC)(GLenum pname, GLint param); + //typedef void (*PFNGLPOINTPARAMETERIVPROC)(GLenum pname, const GLint *params); + //typedef void (*PFNGLBLENDCOLORPROC)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + #endif /* GL_VERSION_1_4 */ + + #ifndef GL_VERSION_1_5 + #define GL_VERSION_1_5 1 + typedef khronos_ssize_t GLsizeiptr; + typedef khronos_intptr_t GLintptr; + #define GL_BUFFER_SIZE 0x8764 + #define GL_BUFFER_USAGE 0x8765 + #define GL_QUERY_COUNTER_BITS 0x8864 + #define GL_CURRENT_QUERY 0x8865 + #define GL_QUERY_RESULT 0x8866 + #define GL_QUERY_RESULT_AVAILABLE 0x8867 + #define GL_ARRAY_BUFFER 0x8892 + #define GL_ELEMENT_ARRAY_BUFFER 0x8893 + #define GL_ARRAY_BUFFER_BINDING 0x8894 + #define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 + #define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + #define GL_READ_ONLY 0x88B8 + #define GL_WRITE_ONLY 0x88B9 + #define GL_READ_WRITE 0x88BA + #define GL_BUFFER_ACCESS 0x88BB + #define GL_BUFFER_MAPPED 0x88BC + #define GL_BUFFER_MAP_POINTER 0x88BD + #define GL_STREAM_DRAW 0x88E0 + #define GL_STREAM_READ 0x88E1 + #define GL_STREAM_COPY 0x88E2 + #define GL_STATIC_DRAW 0x88E4 + #define GL_STATIC_READ 0x88E5 + #define GL_STATIC_COPY 0x88E6 + #define GL_DYNAMIC_DRAW 0x88E8 + #define GL_DYNAMIC_READ 0x88E9 + #define GL_DYNAMIC_COPY 0x88EA + #define GL_SAMPLES_PASSED 0x8914 + #define GL_SRC1_ALPHA 0x8589 + typedef void (*PFNGLBINDBUFFERPROC)(GLenum target, GLuint buffer); + typedef void (*PFNGLDELETEBUFFERSPROC)(GLsizei n, const GLuint *buffers); + typedef void (*PFNGLGENBUFFERSPROC)(GLsizei n, GLuint *buffers); + typedef void (*PFNGLBUFFERDATAPROC)(GLenum target, GLsizeiptr size, const void *data, GLenum usage); + //typedef void (*PFNGLGENQUERIESPROC)(GLsizei n, GLuint *ids); + //typedef void (*PFNGLDELETEQUERIESPROC)(GLsizei n, const GLuint *ids); + //typedef GLboolean (*PFNGLISQUERYPROC)(GLuint id); + //typedef void (*PFNGLBEGINQUERYPROC)(GLenum target, GLuint id); + //typedef void (*PFNGLENDQUERYPROC)(GLenum target); + //typedef void (*PFNGLGETQUERYIVPROC)(GLenum target, GLenum pname, GLint *params); + //typedef void (*PFNGLGETQUERYOBJECTIVPROC)(GLuint id, GLenum pname, GLint *params); + //typedef void (*PFNGLGETQUERYOBJECTUIVPROC)(GLuint id, GLenum pname, GLuint *params); + //typedef GLboolean (*PFNGLISBUFFERPROC)(GLuint buffer); + //typedef void (*PFNGLBUFFERSUBDATAPROC)(GLenum target, GLintptr offset, GLsizeiptr size, const void *data); + //typedef void (*PFNGLGETBUFFERSUBDATAPROC)(GLenum target, GLintptr offset, GLsizeiptr size, void *data); + //typedef void *(*PFNGLMAPBUFFERPROC)(GLenum target, GLenum access); + //typedef GLboolean (*PFNGLUNMAPBUFFERPROC)(GLenum target); + //typedef void (*PFNGLGETBUFFERPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params); + //typedef void (*PFNGLGETBUFFERPOINTERVPROC)(GLenum target, GLenum pname, void **params); + #endif /* GL_VERSION_1_5 */ + + #ifndef GL_VERSION_2_0 + #define GL_VERSION_2_0 1 + typedef char GLchar; + typedef khronos_int16_t GLshort; + typedef khronos_int8_t GLbyte; + typedef khronos_uint16_t GLushort; + #define GL_BLEND_EQUATION_RGB 0x8009 + #define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 + #define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 + #define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 + #define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 + #define GL_CURRENT_VERTEX_ATTRIB 0x8626 + #define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 + #define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 + #define GL_STENCIL_BACK_FUNC 0x8800 + #define GL_STENCIL_BACK_FAIL 0x8801 + #define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 + #define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 + #define GL_MAX_DRAW_BUFFERS 0x8824 + #define GL_DRAW_BUFFER0 0x8825 + #define GL_DRAW_BUFFER1 0x8826 + #define GL_DRAW_BUFFER2 0x8827 + #define GL_DRAW_BUFFER3 0x8828 + #define GL_DRAW_BUFFER4 0x8829 + #define GL_DRAW_BUFFER5 0x882A + #define GL_DRAW_BUFFER6 0x882B + #define GL_DRAW_BUFFER7 0x882C + #define GL_DRAW_BUFFER8 0x882D + #define GL_DRAW_BUFFER9 0x882E + #define GL_DRAW_BUFFER10 0x882F + #define GL_DRAW_BUFFER11 0x8830 + #define GL_DRAW_BUFFER12 0x8831 + #define GL_DRAW_BUFFER13 0x8832 + #define GL_DRAW_BUFFER14 0x8833 + #define GL_DRAW_BUFFER15 0x8834 + #define GL_BLEND_EQUATION_ALPHA 0x883D + #define GL_MAX_VERTEX_ATTRIBS 0x8869 + #define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A + #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 + #define GL_FRAGMENT_SHADER 0x8B30 + #define GL_VERTEX_SHADER 0x8B31 + #define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 + #define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A + #define GL_MAX_VARYING_FLOATS 0x8B4B + #define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C + #define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D + #define GL_SHADER_TYPE 0x8B4F + #define GL_FLOAT_VEC2 0x8B50 + #define GL_FLOAT_VEC3 0x8B51 + #define GL_FLOAT_VEC4 0x8B52 + #define GL_INT_VEC2 0x8B53 + #define GL_INT_VEC3 0x8B54 + #define GL_INT_VEC4 0x8B55 + #define GL_BOOL 0x8B56 + #define GL_BOOL_VEC2 0x8B57 + #define GL_BOOL_VEC3 0x8B58 + #define GL_BOOL_VEC4 0x8B59 + #define GL_FLOAT_MAT2 0x8B5A + #define GL_FLOAT_MAT3 0x8B5B + #define GL_FLOAT_MAT4 0x8B5C + #define GL_SAMPLER_1D 0x8B5D + #define GL_SAMPLER_2D 0x8B5E + #define GL_SAMPLER_3D 0x8B5F + #define GL_SAMPLER_CUBE 0x8B60 + #define GL_SAMPLER_1D_SHADOW 0x8B61 + #define GL_SAMPLER_2D_SHADOW 0x8B62 + #define GL_DELETE_STATUS 0x8B80 + #define GL_COMPILE_STATUS 0x8B81 + #define GL_LINK_STATUS 0x8B82 + #define GL_VALIDATE_STATUS 0x8B83 + #define GL_INFO_LOG_LENGTH 0x8B84 + #define GL_ATTACHED_SHADERS 0x8B85 + #define GL_ACTIVE_UNIFORMS 0x8B86 + #define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 + #define GL_SHADER_SOURCE_LENGTH 0x8B88 + #define GL_ACTIVE_ATTRIBUTES 0x8B89 + #define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A + #define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B + #define GL_SHADING_LANGUAGE_VERSION 0x8B8C + #define GL_CURRENT_PROGRAM 0x8B8D + #define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 + #define GL_LOWER_LEFT 0x8CA1 + #define GL_UPPER_LEFT 0x8CA2 + #define GL_STENCIL_BACK_REF 0x8CA3 + #define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 + #define GL_STENCIL_BACK_WRITEMASK 0x8CA5 + typedef void (*PFNGLDRAWBUFFERSPROC)(GLsizei n, const GLenum *bufs); + typedef void (*PFNGLSTENCILOPSEPARATEPROC)(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); + typedef void (*PFNGLSTENCILFUNCSEPARATEPROC)(GLenum face, GLenum func, GLint ref, GLuint mask); + typedef void (*PFNGLATTACHSHADERPROC)(GLuint program, GLuint shader); + typedef void (*PFNGLCOMPILESHADERPROC)(GLuint shader); + typedef GLuint (*PFNGLCREATEPROGRAMPROC)(void); + typedef GLuint (*PFNGLCREATESHADERPROC)(GLenum type); + typedef void (*PFNGLDELETEPROGRAMPROC)(GLuint program); + typedef void (*PFNGLDELETESHADERPROC)(GLuint shader); + typedef void (*PFNGLDISABLEVERTEXATTRIBARRAYPROC)(GLuint index); + typedef void (*PFNGLENABLEVERTEXATTRIBARRAYPROC)(GLuint index); + typedef GLint (*PFNGLGETATTRIBLOCATIONPROC)(GLuint program, const GLchar *name); + typedef void (*PFNGLGETPROGRAMIVPROC)(GLuint program, GLenum pname, GLint *params); + typedef void (*PFNGLGETPROGRAMINFOLOGPROC)(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); + typedef void (*PFNGLGETSHADERIVPROC)(GLuint shader, GLenum pname, GLint *params); + typedef void (*PFNGLGETSHADERINFOLOGPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); + typedef GLint (*PFNGLGETUNIFORMLOCATIONPROC)(GLuint program, const GLchar *name); + typedef void (*PFNGLLINKPROGRAMPROC)(GLuint program); + typedef void (*PFNGLSHADERSOURCEPROC)(GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); + typedef void (*PFNGLUSEPROGRAMPROC)(GLuint program); + typedef void (*PFNGLUNIFORM1FPROC)(GLint location, GLfloat v0); + typedef void (*PFNGLUNIFORM1FVPROC)(GLint location, GLsizei count, const GLfloat *value); + typedef void (*PFNGLUNIFORM2FVPROC)(GLint location, GLsizei count, const GLfloat *value); + typedef void (*PFNGLUNIFORM3FVPROC)(GLint location, GLsizei count, const GLfloat *value); + typedef void (*PFNGLUNIFORM4FVPROC)(GLint location, GLsizei count, const GLfloat *value); + typedef void (*PFNGLUNIFORM1IVPROC)(GLint location, GLsizei count, const GLint *value); + typedef void (*PFNGLUNIFORM2IVPROC)(GLint location, GLsizei count, const GLint *value); + typedef void (*PFNGLUNIFORM3IVPROC)(GLint location, GLsizei count, const GLint *value); + typedef void (*PFNGLUNIFORM4IVPROC)(GLint location, GLsizei count, const GLint *value); + typedef void (*PFNGLUNIFORMMATRIX4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + typedef void (*PFNGLVERTEXATTRIBPOINTERPROC)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); + //typedef void (*PFNGLBLENDEQUATIONSEPARATEPROC)(GLenum modeRGB, GLenum modeAlpha); + //typedef void (*PFNGLSTENCILMASKSEPARATEPROC)(GLenum face, GLuint mask); + //typedef void (*PFNGLBINDATTRIBLOCATIONPROC)(GLuint program, GLuint index, const GLchar *name); + //typedef void (*PFNGLDETACHSHADERPROC)(GLuint program, GLuint shader); + //typedef void (*PFNGLGETACTIVEATTRIBPROC)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); + //typedef void (*PFNGLGETACTIVEUNIFORMPROC)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); + //typedef void (*PFNGLGETATTACHEDSHADERSPROC)(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders); + //typedef void (*PFNGLGETSHADERSOURCEPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); + //typedef void (*PFNGLGETUNIFORMFVPROC)(GLuint program, GLint location, GLfloat *params); + //typedef void (*PFNGLGETUNIFORMIVPROC)(GLuint program, GLint location, GLint *params); + //typedef void (*PFNGLGETVERTEXATTRIBDVPROC)(GLuint index, GLenum pname, GLdouble *params); + //typedef void (*PFNGLGETVERTEXATTRIBFVPROC)(GLuint index, GLenum pname, GLfloat *params); + //typedef void (*PFNGLGETVERTEXATTRIBIVPROC)(GLuint index, GLenum pname, GLint *params); + //typedef void (*PFNGLGETVERTEXATTRIBPOINTERVPROC)(GLuint index, GLenum pname, void **pointer); + //typedef GLboolean (*PFNGLISPROGRAMPROC)(GLuint program); + //typedef GLboolean (*PFNGLISSHADERPROC)(GLuint shader); + //typedef void (*PFNGLUNIFORM2FPROC)(GLint location, GLfloat v0, GLfloat v1); + //typedef void (*PFNGLUNIFORM3FPROC)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); + //typedef void (*PFNGLUNIFORM4FPROC)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); + //typedef void (*PFNGLUNIFORM1IPROC)(GLint location, GLint v0); + //typedef void (*PFNGLUNIFORM2IPROC)(GLint location, GLint v0, GLint v1); + //typedef void (*PFNGLUNIFORM3IPROC)(GLint location, GLint v0, GLint v1, GLint v2); + //typedef void (*PFNGLUNIFORM4IPROC)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3); + //typedef void (*PFNGLUNIFORMMATRIX2FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLUNIFORMMATRIX3FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLVALIDATEPROGRAMPROC)(GLuint program); + //typedef void (*PFNGLVERTEXATTRIB1DPROC)(GLuint index, GLdouble x); + //typedef void (*PFNGLVERTEXATTRIB1DVPROC)(GLuint index, const GLdouble *v); + //typedef void (*PFNGLVERTEXATTRIB1FPROC)(GLuint index, GLfloat x); + //typedef void (*PFNGLVERTEXATTRIB1FVPROC)(GLuint index, const GLfloat *v); + //typedef void (*PFNGLVERTEXATTRIB1SPROC)(GLuint index, GLshort x); + //typedef void (*PFNGLVERTEXATTRIB1SVPROC)(GLuint index, const GLshort *v); + //typedef void (*PFNGLVERTEXATTRIB2DPROC)(GLuint index, GLdouble x, GLdouble y); + //typedef void (*PFNGLVERTEXATTRIB2DVPROC)(GLuint index, const GLdouble *v); + //typedef void (*PFNGLVERTEXATTRIB2FPROC)(GLuint index, GLfloat x, GLfloat y); + //typedef void (*PFNGLVERTEXATTRIB2FVPROC)(GLuint index, const GLfloat *v); + //typedef void (*PFNGLVERTEXATTRIB2SPROC)(GLuint index, GLshort x, GLshort y); + //typedef void (*PFNGLVERTEXATTRIB2SVPROC)(GLuint index, const GLshort *v); + //typedef void (*PFNGLVERTEXATTRIB3DPROC)(GLuint index, GLdouble x, GLdouble y, GLdouble z); + //typedef void (*PFNGLVERTEXATTRIB3DVPROC)(GLuint index, const GLdouble *v); + //typedef void (*PFNGLVERTEXATTRIB3FPROC)(GLuint index, GLfloat x, GLfloat y, GLfloat z); + //typedef void (*PFNGLVERTEXATTRIB3FVPROC)(GLuint index, const GLfloat *v); + //typedef void (*PFNGLVERTEXATTRIB3SPROC)(GLuint index, GLshort x, GLshort y, GLshort z); + //typedef void (*PFNGLVERTEXATTRIB3SVPROC)(GLuint index, const GLshort *v); + //typedef void (*PFNGLVERTEXATTRIB4NBVPROC)(GLuint index, const GLbyte *v); + //typedef void (*PFNGLVERTEXATTRIB4NIVPROC)(GLuint index, const GLint *v); + //typedef void (*PFNGLVERTEXATTRIB4NSVPROC)(GLuint index, const GLshort *v); + //typedef void (*PFNGLVERTEXATTRIB4NUBPROC)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); + //typedef void (*PFNGLVERTEXATTRIB4NUBVPROC)(GLuint index, const GLubyte *v); + //typedef void (*PFNGLVERTEXATTRIB4NUIVPROC)(GLuint index, const GLuint *v); + //typedef void (*PFNGLVERTEXATTRIB4NUSVPROC)(GLuint index, const GLushort *v); + //typedef void (*PFNGLVERTEXATTRIB4BVPROC)(GLuint index, const GLbyte *v); + //typedef void (*PFNGLVERTEXATTRIB4DPROC)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); + //typedef void (*PFNGLVERTEXATTRIB4DVPROC)(GLuint index, const GLdouble *v); + //typedef void (*PFNGLVERTEXATTRIB4FPROC)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + //typedef void (*PFNGLVERTEXATTRIB4FVPROC)(GLuint index, const GLfloat *v); + //typedef void (*PFNGLVERTEXATTRIB4IVPROC)(GLuint index, const GLint *v); + //typedef void (*PFNGLVERTEXATTRIB4SPROC)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); + //typedef void (*PFNGLVERTEXATTRIB4SVPROC)(GLuint index, const GLshort *v); + //typedef void (*PFNGLVERTEXATTRIB4UBVPROC)(GLuint index, const GLubyte *v); + //typedef void (*PFNGLVERTEXATTRIB4UIVPROC)(GLuint index, const GLuint *v); + //typedef void (*PFNGLVERTEXATTRIB4USVPROC)(GLuint index, const GLushort *v); + #endif /* GL_VERSION_2_0 */ + + #ifndef GL_VERSION_2_1 + #define GL_VERSION_2_1 1 + #define GL_PIXEL_PACK_BUFFER 0x88EB + #define GL_PIXEL_UNPACK_BUFFER 0x88EC + #define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED + #define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF + #define GL_FLOAT_MAT2x3 0x8B65 + #define GL_FLOAT_MAT2x4 0x8B66 + #define GL_FLOAT_MAT3x2 0x8B67 + #define GL_FLOAT_MAT3x4 0x8B68 + #define GL_FLOAT_MAT4x2 0x8B69 + #define GL_FLOAT_MAT4x3 0x8B6A + #define GL_SRGB 0x8C40 + #define GL_SRGB8 0x8C41 + #define GL_SRGB_ALPHA 0x8C42 + #define GL_SRGB8_ALPHA8 0x8C43 + #define GL_COMPRESSED_SRGB 0x8C48 + #define GL_COMPRESSED_SRGB_ALPHA 0x8C49 + //typedef void (*PFNGLUNIFORMMATRIX2X3FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLUNIFORMMATRIX3X2FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLUNIFORMMATRIX2X4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLUNIFORMMATRIX4X2FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLUNIFORMMATRIX3X4FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + //typedef void (*PFNGLUNIFORMMATRIX4X3FVPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + #endif /* GL_VERSION_2_1 */ + + #ifndef GL_VERSION_3_0 + #define GL_VERSION_3_0 1 + typedef khronos_uint16_t GLhalf; + #define GL_COMPARE_REF_TO_TEXTURE 0x884E + #define GL_CLIP_DISTANCE0 0x3000 + #define GL_CLIP_DISTANCE1 0x3001 + #define GL_CLIP_DISTANCE2 0x3002 + #define GL_CLIP_DISTANCE3 0x3003 + #define GL_CLIP_DISTANCE4 0x3004 + #define GL_CLIP_DISTANCE5 0x3005 + #define GL_CLIP_DISTANCE6 0x3006 + #define GL_CLIP_DISTANCE7 0x3007 + #define GL_MAX_CLIP_DISTANCES 0x0D32 + #define GL_MAJOR_VERSION 0x821B + #define GL_MINOR_VERSION 0x821C + #define GL_NUM_EXTENSIONS 0x821D + #define GL_CONTEXT_FLAGS 0x821E + #define GL_COMPRESSED_RED 0x8225 + #define GL_COMPRESSED_RG 0x8226 + #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001 + #define GL_RGBA32F 0x8814 + #define GL_RGB32F 0x8815 + #define GL_RGBA16F 0x881A + #define GL_RGB16F 0x881B + #define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD + #define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF + #define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 + #define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 + #define GL_CLAMP_READ_COLOR 0x891C + #define GL_FIXED_ONLY 0x891D + #define GL_MAX_VARYING_COMPONENTS 0x8B4B + #define GL_TEXTURE_1D_ARRAY 0x8C18 + #define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 + #define GL_TEXTURE_2D_ARRAY 0x8C1A + #define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B + #define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C + #define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D + #define GL_R11F_G11F_B10F 0x8C3A + #define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B + #define GL_RGB9_E5 0x8C3D + #define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E + #define GL_TEXTURE_SHARED_SIZE 0x8C3F + #define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 + #define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F + #define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 + #define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 + #define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 + #define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 + #define GL_PRIMITIVES_GENERATED 0x8C87 + #define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 + #define GL_RASTERIZER_DISCARD 0x8C89 + #define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A + #define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B + #define GL_INTERLEAVED_ATTRIBS 0x8C8C + #define GL_SEPARATE_ATTRIBS 0x8C8D + #define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E + #define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F + #define GL_RGBA32UI 0x8D70 + #define GL_RGB32UI 0x8D71 + #define GL_RGBA16UI 0x8D76 + #define GL_RGB16UI 0x8D77 + #define GL_RGBA8UI 0x8D7C + #define GL_RGB8UI 0x8D7D + #define GL_RGBA32I 0x8D82 + #define GL_RGB32I 0x8D83 + #define GL_RGBA16I 0x8D88 + #define GL_RGB16I 0x8D89 + #define GL_RGBA8I 0x8D8E + #define GL_RGB8I 0x8D8F + #define GL_RED_INTEGER 0x8D94 + #define GL_GREEN_INTEGER 0x8D95 + #define GL_BLUE_INTEGER 0x8D96 + #define GL_RGB_INTEGER 0x8D98 + #define GL_RGBA_INTEGER 0x8D99 + #define GL_BGR_INTEGER 0x8D9A + #define GL_BGRA_INTEGER 0x8D9B + #define GL_SAMPLER_1D_ARRAY 0x8DC0 + #define GL_SAMPLER_2D_ARRAY 0x8DC1 + #define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 + #define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 + #define GL_SAMPLER_CUBE_SHADOW 0x8DC5 + #define GL_UNSIGNED_INT_VEC2 0x8DC6 + #define GL_UNSIGNED_INT_VEC3 0x8DC7 + #define GL_UNSIGNED_INT_VEC4 0x8DC8 + #define GL_INT_SAMPLER_1D 0x8DC9 + #define GL_INT_SAMPLER_2D 0x8DCA + #define GL_INT_SAMPLER_3D 0x8DCB + #define GL_INT_SAMPLER_CUBE 0x8DCC + #define GL_INT_SAMPLER_1D_ARRAY 0x8DCE + #define GL_INT_SAMPLER_2D_ARRAY 0x8DCF + #define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 + #define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 + #define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 + #define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 + #define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 + #define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 + #define GL_QUERY_WAIT 0x8E13 + #define GL_QUERY_NO_WAIT 0x8E14 + #define GL_QUERY_BY_REGION_WAIT 0x8E15 + #define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 + #define GL_BUFFER_ACCESS_FLAGS 0x911F + #define GL_BUFFER_MAP_LENGTH 0x9120 + #define GL_BUFFER_MAP_OFFSET 0x9121 + #define GL_DEPTH_COMPONENT32F 0x8CAC + #define GL_DEPTH32F_STENCIL8 0x8CAD + #define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD + #define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 + #define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 + #define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 + #define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 + #define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 + #define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 + #define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 + #define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 + #define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 + #define GL_FRAMEBUFFER_DEFAULT 0x8218 + #define GL_FRAMEBUFFER_UNDEFINED 0x8219 + #define GL_DEPTH_STENCIL_ATTACHMENT 0x821A + #define GL_MAX_RENDERBUFFER_SIZE 0x84E8 + #define GL_DEPTH_STENCIL 0x84F9 + #define GL_UNSIGNED_INT_24_8 0x84FA + #define GL_DEPTH24_STENCIL8 0x88F0 + #define GL_TEXTURE_STENCIL_SIZE 0x88F1 + #define GL_TEXTURE_RED_TYPE 0x8C10 + #define GL_TEXTURE_GREEN_TYPE 0x8C11 + #define GL_TEXTURE_BLUE_TYPE 0x8C12 + #define GL_TEXTURE_ALPHA_TYPE 0x8C13 + #define GL_TEXTURE_DEPTH_TYPE 0x8C16 + #define GL_UNSIGNED_NORMALIZED 0x8C17 + #define GL_FRAMEBUFFER_BINDING 0x8CA6 + #define GL_DRAW_FRAMEBUFFER_BINDING 0x8CA6 + #define GL_RENDERBUFFER_BINDING 0x8CA7 + #define GL_READ_FRAMEBUFFER 0x8CA8 + #define GL_DRAW_FRAMEBUFFER 0x8CA9 + #define GL_READ_FRAMEBUFFER_BINDING 0x8CAA + #define GL_RENDERBUFFER_SAMPLES 0x8CAB + #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 + #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 + #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 + #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 + #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 + #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 + #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 + #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 + #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB + #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC + #define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + #define GL_MAX_COLOR_ATTACHMENTS 0x8CDF + #define GL_COLOR_ATTACHMENT0 0x8CE0 + #define GL_COLOR_ATTACHMENT1 0x8CE1 + #define GL_COLOR_ATTACHMENT2 0x8CE2 + #define GL_COLOR_ATTACHMENT3 0x8CE3 + #define GL_COLOR_ATTACHMENT4 0x8CE4 + #define GL_COLOR_ATTACHMENT5 0x8CE5 + #define GL_COLOR_ATTACHMENT6 0x8CE6 + #define GL_COLOR_ATTACHMENT7 0x8CE7 + #define GL_COLOR_ATTACHMENT8 0x8CE8 + #define GL_COLOR_ATTACHMENT9 0x8CE9 + #define GL_COLOR_ATTACHMENT10 0x8CEA + #define GL_COLOR_ATTACHMENT11 0x8CEB + #define GL_COLOR_ATTACHMENT12 0x8CEC + #define GL_COLOR_ATTACHMENT13 0x8CED + #define GL_COLOR_ATTACHMENT14 0x8CEE + #define GL_COLOR_ATTACHMENT15 0x8CEF + #define GL_COLOR_ATTACHMENT16 0x8CF0 + #define GL_COLOR_ATTACHMENT17 0x8CF1 + #define GL_COLOR_ATTACHMENT18 0x8CF2 + #define GL_COLOR_ATTACHMENT19 0x8CF3 + #define GL_COLOR_ATTACHMENT20 0x8CF4 + #define GL_COLOR_ATTACHMENT21 0x8CF5 + #define GL_COLOR_ATTACHMENT22 0x8CF6 + #define GL_COLOR_ATTACHMENT23 0x8CF7 + #define GL_COLOR_ATTACHMENT24 0x8CF8 + #define GL_COLOR_ATTACHMENT25 0x8CF9 + #define GL_COLOR_ATTACHMENT26 0x8CFA + #define GL_COLOR_ATTACHMENT27 0x8CFB + #define GL_COLOR_ATTACHMENT28 0x8CFC + #define GL_COLOR_ATTACHMENT29 0x8CFD + #define GL_COLOR_ATTACHMENT30 0x8CFE + #define GL_COLOR_ATTACHMENT31 0x8CFF + #define GL_DEPTH_ATTACHMENT 0x8D00 + #define GL_STENCIL_ATTACHMENT 0x8D20 + #define GL_FRAMEBUFFER 0x8D40 + #define GL_RENDERBUFFER 0x8D41 + #define GL_RENDERBUFFER_WIDTH 0x8D42 + #define GL_RENDERBUFFER_HEIGHT 0x8D43 + #define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 + #define GL_STENCIL_INDEX1 0x8D46 + #define GL_STENCIL_INDEX4 0x8D47 + #define GL_STENCIL_INDEX8 0x8D48 + #define GL_STENCIL_INDEX16 0x8D49 + #define GL_RENDERBUFFER_RED_SIZE 0x8D50 + #define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 + #define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 + #define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 + #define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 + #define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 + #define GL_MAX_SAMPLES 0x8D57 + #define GL_FRAMEBUFFER_SRGB 0x8DB9 + #define GL_HALF_FLOAT 0x140B + #define GL_MAP_READ_BIT 0x0001 + #define GL_MAP_WRITE_BIT 0x0002 + #define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 + #define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 + #define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 + #define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 + #define GL_COMPRESSED_RED_RGTC1 0x8DBB + #define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC + #define GL_COMPRESSED_RG_RGTC2 0x8DBD + #define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE + #define GL_RG 0x8227 + #define GL_RG_INTEGER 0x8228 + #define GL_R8 0x8229 + #define GL_R16 0x822A + #define GL_RG8 0x822B + #define GL_RG16 0x822C + #define GL_R16F 0x822D + #define GL_R32F 0x822E + #define GL_RG16F 0x822F + #define GL_RG32F 0x8230 + #define GL_R8I 0x8231 + #define GL_R8UI 0x8232 + #define GL_R16I 0x8233 + #define GL_R16UI 0x8234 + #define GL_R32I 0x8235 + #define GL_R32UI 0x8236 + #define GL_RG8I 0x8237 + #define GL_RG8UI 0x8238 + #define GL_RG16I 0x8239 + #define GL_RG16UI 0x823A + #define GL_RG32I 0x823B + #define GL_RG32UI 0x823C + #define GL_VERTEX_ARRAY_BINDING 0x85B5 + typedef void (*PFNGLBINDBUFFERRANGEPROC)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); + typedef void (*PFNGLBINDRENDERBUFFERPROC)(GLenum target, GLuint renderbuffer); + typedef void (*PFNGLDELETERENDERBUFFERSPROC)(GLsizei n, const GLuint *renderbuffers); + typedef void (*PFNGLGENRENDERBUFFERSPROC)(GLsizei n, GLuint *renderbuffers); + typedef void (*PFNGLINVALIDATEFRAMEBUFFERPROC)(GLenum target, GLsizei numAttachments, const GLenum *attachments); // GLES + typedef void (*PFNGLBINDFRAMEBUFFERPROC)(GLenum target, GLuint framebuffer); + typedef void (*PFNGLDELETEFRAMEBUFFERSPROC)(GLsizei n, const GLuint *framebuffers); + typedef void (*PFNGLGENFRAMEBUFFERSPROC)(GLsizei n, GLuint *framebuffers); + typedef void (*PFNGLFRAMEBUFFERTEXTURE2DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + typedef void (*PFNGLFRAMEBUFFERRENDERBUFFERPROC)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + typedef void (*PFNGLBLITFRAMEBUFFERPROC)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); + typedef void (*PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (*PFNGLBINDVERTEXARRAYPROC)(GLuint array); + typedef void (*PFNGLDELETEVERTEXARRAYSPROC)(GLsizei n, const GLuint *arrays); + typedef void (*PFNGLGENVERTEXARRAYSPROC)(GLsizei n, GLuint *arrays); + //typedef void (*PFNGLCOLORMASKIPROC)(GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); + //typedef void (*PFNGLGETBOOLEANI_VPROC)(GLenum target, GLuint index, GLboolean *data); + //typedef void (*PFNGLGETINTEGERI_VPROC)(GLenum target, GLuint index, GLint *data); + //typedef void (*PFNGLENABLEIPROC)(GLenum target, GLuint index); + //typedef void (*PFNGLDISABLEIPROC)(GLenum target, GLuint index); + //typedef GLboolean (*PFNGLISENABLEDIPROC)(GLenum target, GLuint index); + //typedef void (*PFNGLBEGINTRANSFORMFEEDBACKPROC)(GLenum primitiveMode); + //typedef void (*PFNGLENDTRANSFORMFEEDBACKPROC)(void); + //typedef void (*PFNGLBINDBUFFERBASEPROC)(GLenum target, GLuint index, GLuint buffer); + //typedef void (*PFNGLTRANSFORMFEEDBACKVARYINGSPROC)(GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode); + //typedef void (*PFNGLGETTRANSFORMFEEDBACKVARYINGPROC)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); + //typedef void (*PFNGLCLAMPCOLORPROC)(GLenum target, GLenum clamp); + //typedef void (*PFNGLBEGINCONDITIONALRENDERPROC)(GLuint id, GLenum mode); + //typedef void (*PFNGLENDCONDITIONALRENDERPROC)(void); + //typedef void (*PFNGLVERTEXATTRIBIPOINTERPROC)(GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); + //typedef void (*PFNGLGETVERTEXATTRIBIIVPROC)(GLuint index, GLenum pname, GLint *params); + //typedef void (*PFNGLGETVERTEXATTRIBIUIVPROC)(GLuint index, GLenum pname, GLuint *params); + //typedef void (*PFNGLVERTEXATTRIBI1IPROC)(GLuint index, GLint x); + //typedef void (*PFNGLVERTEXATTRIBI2IPROC)(GLuint index, GLint x, GLint y); + //typedef void (*PFNGLVERTEXATTRIBI3IPROC)(GLuint index, GLint x, GLint y, GLint z); + //typedef void (*PFNGLVERTEXATTRIBI4IPROC)(GLuint index, GLint x, GLint y, GLint z, GLint w); + //typedef void (*PFNGLVERTEXATTRIBI1UIPROC)(GLuint index, GLuint x); + //typedef void (*PFNGLVERTEXATTRIBI2UIPROC)(GLuint index, GLuint x, GLuint y); + //typedef void (*PFNGLVERTEXATTRIBI3UIPROC)(GLuint index, GLuint x, GLuint y, GLuint z); + //typedef void (*PFNGLVERTEXATTRIBI4UIPROC)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); + //typedef void (*PFNGLVERTEXATTRIBI1IVPROC)(GLuint index, const GLint *v); + //typedef void (*PFNGLVERTEXATTRIBI2IVPROC)(GLuint index, const GLint *v); + //typedef void (*PFNGLVERTEXATTRIBI3IVPROC)(GLuint index, const GLint *v); + //typedef void (*PFNGLVERTEXATTRIBI4IVPROC)(GLuint index, const GLint *v); + //typedef void (*PFNGLVERTEXATTRIBI1UIVPROC)(GLuint index, const GLuint *v); + //typedef void (*PFNGLVERTEXATTRIBI2UIVPROC)(GLuint index, const GLuint *v); + //typedef void (*PFNGLVERTEXATTRIBI3UIVPROC)(GLuint index, const GLuint *v); + //typedef void (*PFNGLVERTEXATTRIBI4UIVPROC)(GLuint index, const GLuint *v); + //typedef void (*PFNGLVERTEXATTRIBI4BVPROC)(GLuint index, const GLbyte *v); + //typedef void (*PFNGLVERTEXATTRIBI4SVPROC)(GLuint index, const GLshort *v); + //typedef void (*PFNGLVERTEXATTRIBI4UBVPROC)(GLuint index, const GLubyte *v); + //typedef void (*PFNGLVERTEXATTRIBI4USVPROC)(GLuint index, const GLushort *v); + //typedef void (*PFNGLGETUNIFORMUIVPROC)(GLuint program, GLint location, GLuint *params); + //typedef void (*PFNGLBINDFRAGDATALOCATIONPROC)(GLuint program, GLuint color, const GLchar *name); + //typedef GLint (*PFNGLGETFRAGDATALOCATIONPROC)(GLuint program, const GLchar *name); + //typedef void (*PFNGLUNIFORM1UIPROC)(GLint location, GLuint v0); + //typedef void (*PFNGLUNIFORM2UIPROC)(GLint location, GLuint v0, GLuint v1); + //typedef void (*PFNGLUNIFORM3UIPROC)(GLint location, GLuint v0, GLuint v1, GLuint v2); + //typedef void (*PFNGLUNIFORM4UIPROC)(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + //typedef void (*PFNGLUNIFORM1UIVPROC)(GLint location, GLsizei count, const GLuint *value); + //typedef void (*PFNGLUNIFORM2UIVPROC)(GLint location, GLsizei count, const GLuint *value); + //typedef void (*PFNGLUNIFORM3UIVPROC)(GLint location, GLsizei count, const GLuint *value); + //typedef void (*PFNGLUNIFORM4UIVPROC)(GLint location, GLsizei count, const GLuint *value); + //typedef void (*PFNGLTEXPARAMETERIIVPROC)(GLenum target, GLenum pname, const GLint *params); + //typedef void (*PFNGLTEXPARAMETERIUIVPROC)(GLenum target, GLenum pname, const GLuint *params); + //typedef void (*PFNGLGETTEXPARAMETERIIVPROC)(GLenum target, GLenum pname, GLint *params); + //typedef void (*PFNGLGETTEXPARAMETERIUIVPROC)(GLenum target, GLenum pname, GLuint *params); + //typedef void (*PFNGLCLEARBUFFERIVPROC)(GLenum buffer, GLint drawbuffer, const GLint *value); + //typedef void (*PFNGLCLEARBUFFERUIVPROC)(GLenum buffer, GLint drawbuffer, const GLuint *value); + //typedef void (*PFNGLCLEARBUFFERFVPROC)(GLenum buffer, GLint drawbuffer, const GLfloat *value); + //typedef void (*PFNGLCLEARBUFFERFIPROC)(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); + //typedef const GLubyte *(*PFNGLGETSTRINGIPROC)(GLenum name, GLuint index); + //typedef GLboolean (*PFNGLISRENDERBUFFERPROC)(GLuint renderbuffer); + //typedef void (*PFNGLRENDERBUFFERSTORAGEPROC)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + //typedef void (*PFNGLGETRENDERBUFFERPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params); + //typedef GLboolean (*PFNGLISFRAMEBUFFERPROC)(GLuint framebuffer); + //typedef GLenum (*PFNGLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target); + //typedef void (*PFNGLFRAMEBUFFERTEXTURE1DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + //typedef void (*PFNGLFRAMEBUFFERTEXTURE3DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); + //typedef void (*PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)(GLenum target, GLenum attachment, GLenum pname, GLint *params); + //typedef void (*PFNGLGENERATEMIPMAPPROC)(GLenum target); + //typedef void (*PFNGLFRAMEBUFFERTEXTURELAYERPROC)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); + //typedef void *(*PFNGLMAPBUFFERRANGEPROC)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); + //typedef void (*PFNGLFLUSHMAPPEDBUFFERRANGEPROC)(GLenum target, GLintptr offset, GLsizeiptr length); + //typedef GLboolean (*PFNGLISVERTEXARRAYPROC)(GLuint array); + #endif /* GL_VERSION_3_0 */ + + #ifndef GL_VERSION_3_1 + #define GL_VERSION_3_1 1 + #define GL_SAMPLER_2D_RECT 0x8B63 + #define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 + #define GL_SAMPLER_BUFFER 0x8DC2 + #define GL_INT_SAMPLER_2D_RECT 0x8DCD + #define GL_INT_SAMPLER_BUFFER 0x8DD0 + #define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 + #define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 + #define GL_TEXTURE_BUFFER 0x8C2A + #define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B + #define GL_TEXTURE_BINDING_BUFFER 0x8C2C + #define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D + #define GL_TEXTURE_RECTANGLE 0x84F5 + #define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 + #define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 + #define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 + #define GL_R8_SNORM 0x8F94 + #define GL_RG8_SNORM 0x8F95 + #define GL_RGB8_SNORM 0x8F96 + #define GL_RGBA8_SNORM 0x8F97 + #define GL_R16_SNORM 0x8F98 + #define GL_RG16_SNORM 0x8F99 + #define GL_RGB16_SNORM 0x8F9A + #define GL_RGBA16_SNORM 0x8F9B + #define GL_SIGNED_NORMALIZED 0x8F9C + #define GL_PRIMITIVE_RESTART 0x8F9D + #define GL_PRIMITIVE_RESTART_INDEX 0x8F9E + #define GL_COPY_READ_BUFFER 0x8F36 + #define GL_COPY_WRITE_BUFFER 0x8F37 + #define GL_UNIFORM_BUFFER 0x8A11 + #define GL_UNIFORM_BUFFER_BINDING 0x8A28 + #define GL_UNIFORM_BUFFER_START 0x8A29 + #define GL_UNIFORM_BUFFER_SIZE 0x8A2A + #define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B + #define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C + #define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D + #define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E + #define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F + #define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 + #define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 + #define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 + #define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 + #define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 + #define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 + #define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 + #define GL_UNIFORM_TYPE 0x8A37 + #define GL_UNIFORM_SIZE 0x8A38 + #define GL_UNIFORM_NAME_LENGTH 0x8A39 + #define GL_UNIFORM_BLOCK_INDEX 0x8A3A + #define GL_UNIFORM_OFFSET 0x8A3B + #define GL_UNIFORM_ARRAY_STRIDE 0x8A3C + #define GL_UNIFORM_MATRIX_STRIDE 0x8A3D + #define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E + #define GL_UNIFORM_BLOCK_BINDING 0x8A3F + #define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 + #define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 + #define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 + #define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 + #define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 + #define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 + #define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 + #define GL_INVALID_INDEX 0xFFFFFFFFu + typedef GLuint (*PFNGLGETUNIFORMBLOCKINDEXPROC)(GLuint program, const GLchar *uniformBlockName); + typedef void (*PFNGLUNIFORMBLOCKBINDINGPROC)(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); + //typedef void (*PFNGLDRAWARRAYSINSTANCEDPROC)(GLenum mode, GLint first, GLsizei count, GLsizei instancecount); + //typedef void (*PFNGLDRAWELEMENTSINSTANCEDPROC)(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount); + //typedef void (*PFNGLTEXBUFFERPROC)(GLenum target, GLenum internalformat, GLuint buffer); + //typedef void (*PFNGLPRIMITIVERESTARTINDEXPROC)(GLuint index); + //typedef void (*PFNGLCOPYBUFFERSUBDATAPROC)(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + //typedef void (*PFNGLGETUNIFORMINDICESPROC)(GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices); + //typedef void (*PFNGLGETACTIVEUNIFORMSIVPROC)(GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); + //typedef void (*PFNGLGETACTIVEUNIFORMNAMEPROC)(GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); + //typedef void (*PFNGLGETACTIVEUNIFORMBLOCKIVPROC)(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); + //typedef void (*PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC)(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); + #endif /* GL_VERSION_3_1 */ + + #if defined(_WIN32) && !defined(__CYGWIN__) && defined(THORVG_GL_TARGET_GL) + typedef HGLRC (WINAPI *PFNWGLGETCURRENTCONTEXTPROC)(void); + typedef BOOL (WINAPI *PFNWGLMAKECURRENTPROC)(HDC, HGLRC); + #endif + + #if defined(THORVG_GL_TARGET_GLES) + typedef void* EGLDisplay; + typedef void* EGLSurface; + typedef void* EGLContext; + typedef EGLContext (*PFNEGLGETCURRENTCONTEXTPROC)(void); + typedef unsigned int (*PFNEGLMAKECURRENTPROC)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); + #endif + + //GL_VERSION_1_0 + extern PFNGLCULLFACEPROC glCullFace; + extern PFNGLFRONTFACEPROC glFrontFace; + extern PFNGLSCISSORPROC glScissor; + extern PFNGLTEXPARAMETERIPROC glTexParameteri; + extern PFNGLTEXIMAGE2DPROC glTexImage2D; + extern PFNGLDRAWBUFFERPROC glDrawBuffer; + extern PFNGLDRAWBUFFERSPROC glDrawBuffers; + extern PFNGLCLEARPROC glClear; + extern PFNGLCLEARCOLORPROC glClearColor; + extern PFNGLCLEARSTENCILPROC glClearStencil; + extern PFNGLCLEARDEPTHPROC glClearDepth; + extern PFNGLCLEARDEPTHFPROC glClearDepthf; // GLES + extern PFNGLCOLORMASKPROC glColorMask; + extern PFNGLDEPTHMASKPROC glDepthMask; + extern PFNGLDISABLEPROC glDisable; + extern PFNGLENABLEPROC glEnable; + extern PFNGLBLENDFUNCPROC glBlendFunc; + extern PFNGLSTENCILFUNCPROC glStencilFunc; + extern PFNGLSTENCILOPPROC glStencilOp; + extern PFNGLDEPTHFUNCPROC glDepthFunc; + extern PFNGLGETERRORPROC glGetError; + extern PFNGLGETINTEGERVPROC glGetIntegerv; + extern PFNGLGETSTRINGPROC glGetString; + extern PFNGLVIEWPORTPROC glViewport; + //extern PFNGLHINTPROC glHint; + //extern PFNGLLINEWIDTHPROC glLineWidth; + //extern PFNGLPOINTSIZEPROC glPointSize; + //extern PFNGLPOLYGONMODEPROC glPolygonMode; + //extern PFNGLTEXPARAMETERFPROC glTexParameterf; + //extern PFNGLTEXPARAMETERFVPROC glTexParameterfv; + //extern PFNGLTEXPARAMETERIVPROC glTexParameteriv; + //extern PFNGLTEXIMAGE1DPROC glTexImage1D; + //extern PFNGLSTENCILMASKPROC glStencilMask; + //extern PFNGLFINISHPROC glFinish; + //extern PFNGLFLUSHPROC glFlush; + //extern PFNGLLOGICOPPROC glLogicOp; + //extern PFNGLPIXELSTOREFPROC glPixelStoref; + //extern PFNGLPIXELSTOREIPROC glPixelStorei; + //extern PFNGLREADBUFFERPROC glReadBuffer; + //extern PFNGLREADPIXELSPROC glReadPixels; + //extern PFNGLGETBOOLEANVPROC glGetBooleanv; + //extern PFNGLGETDOUBLEVPROC glGetDoublev; + //extern PFNGLGETFLOATVPROC glGetFloatv; + //extern PFNGLGETTEXIMAGEPROC glGetTexImage; + //extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; + //extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; + //extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; + //extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; + //extern PFNGLISENABLEDPROC glIsEnabled; + //extern PFNGLDEPTHRANGEPROC glDepthRange; + + //GL_VERSION_1_1 + extern PFNGLDRAWELEMENTSPROC glDrawElements; + extern PFNGLBINDTEXTUREPROC glBindTexture; + extern PFNGLDELETETEXTURESPROC glDeleteTextures; + extern PFNGLGENTEXTURESPROC glGenTextures; + //extern PFNGLDRAWARRAYSPROC glDrawArrays; + //extern PFNGLGETPOINTERVPROC glGetPointerv; + //extern PFNGLPOLYGONOFFSETPROC glPolygonOffset; + //extern PFNGLCOPYTEXIMAGE1DPROC glCopyTexImage1D; + //extern PFNGLCOPYTEXIMAGE2DPROC glCopyTexImage2D; + //extern PFNGLCOPYTEXSUBIMAGE1DPROC glCopyTexSubImage1D; + //extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; + //extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; + //extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; + //extern PFNGLISTEXTUREPROC glIsTexture; + + //GL_VERSION_1_2 + //extern PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements; + //extern PFNGLTEXIMAGE3DPROC glTexImage3D; + //extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; + //extern PFNGLCOPYTEXSUBIMAGE3DPROC glCopyTexSubImage3D; + + //GL_VERSION_1_3 + extern PFNGLACTIVETEXTUREPROC glActiveTexture; + //extern PFNGLSAMPLECOVERAGEPROC glSampleCoverage; + //extern PFNGLCOMPRESSEDTEXIMAGE3DPROC glCompressedTexImage3D; + //extern PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D; + //extern PFNGLCOMPRESSEDTEXIMAGE1DPROC glCompressedTexImage1D; + //extern PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D; + //extern PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D; + //extern PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D; + //extern PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage; + + //GL_VERSION_1_4 + extern PFNGLBLENDEQUATIONPROC glBlendEquation; + //extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate; + //extern PFNGLMULTIDRAWARRAYSPROC glMultiDrawArrays; + //extern PFNGLMULTIDRAWELEMENTSPROC glMultiDrawElements; + //extern PFNGLPOINTPARAMETERFPROC glPointParameterf; + //extern PFNGLPOINTPARAMETERFVPROC glPointParameterfv; + //extern PFNGLPOINTPARAMETERIPROC glPointParameteri; + //extern PFNGLPOINTPARAMETERIVPROC glPointParameteriv; + //extern PFNGLBLENDCOLORPROC glBlendColor; + + //GL_VERSION_1_5 + extern PFNGLBINDBUFFERPROC glBindBuffer; + extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; + extern PFNGLGENBUFFERSPROC glGenBuffers; + extern PFNGLBUFFERDATAPROC glBufferData; + //extern PFNGLGENQUERIESPROC glGenQueries; + //extern PFNGLDELETEQUERIESPROC glDeleteQueries; + //extern PFNGLISQUERYPROC glIsQuery; + //extern PFNGLBEGINQUERYPROC glBeginQuery; + //extern PFNGLENDQUERYPROC glEndQuery; + //extern PFNGLGETQUERYIVPROC glGetQueryiv; + //extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; + //extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; + //extern PFNGLISBUFFERPROC glIsBuffer; + //extern PFNGLBUFFERSUBDATAPROC glBufferSubData; + //extern PFNGLGETBUFFERSUBDATAPROC glGetBufferSubData; + //extern PFNGLMAPBUFFERPROC glMapBuffer; + //extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; + //extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; + //extern PFNGLGETBUFFERPOINTERVPROC glGetBufferPointerv; + + // GL_VERSION_2_0 + extern PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate; + extern PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate; + extern PFNGLATTACHSHADERPROC glAttachShader; + extern PFNGLCOMPILESHADERPROC glCompileShader; + extern PFNGLCREATEPROGRAMPROC glCreateProgram; + extern PFNGLCREATESHADERPROC glCreateShader; + extern PFNGLDELETEPROGRAMPROC glDeleteProgram; + extern PFNGLDELETESHADERPROC glDeleteShader; + extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; + extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; + extern PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; + extern PFNGLGETPROGRAMIVPROC glGetProgramiv; + extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; + extern PFNGLGETSHADERIVPROC glGetShaderiv; + extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; + extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; + extern PFNGLLINKPROGRAMPROC glLinkProgram; + extern PFNGLSHADERSOURCEPROC glShaderSource; + extern PFNGLUSEPROGRAMPROC glUseProgram; + extern PFNGLUNIFORM1FPROC glUniform1f; + extern PFNGLUNIFORM1FVPROC glUniform1fv; + extern PFNGLUNIFORM2FVPROC glUniform2fv; + extern PFNGLUNIFORM3FVPROC glUniform3fv; + extern PFNGLUNIFORM4FVPROC glUniform4fv; + extern PFNGLUNIFORM1IVPROC glUniform1iv; + extern PFNGLUNIFORM2IVPROC glUniform2iv; + extern PFNGLUNIFORM3IVPROC glUniform3iv; + extern PFNGLUNIFORM4IVPROC glUniform4iv; + extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; + extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; + //extern PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate; + //extern PFNGLDRAWBUFFERSPROC glDrawBuffers; + //extern PFNGLSTENCILMASKSEPARATEPROC glStencilMaskSeparate; + //extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; + //extern PFNGLDETACHSHADERPROC glDetachShader; + //extern PFNGLGETACTIVEATTRIBPROC glGetActiveAttrib; + //extern PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform; + //extern PFNGLGETATTACHEDSHADERSPROC glGetAttachedShaders; + //extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; + //extern PFNGLGETUNIFORMFVPROC glGetUniformfv; + //extern PFNGLGETUNIFORMIVPROC glGetUniformiv; + //extern PFNGLGETVERTEXATTRIBDVPROC glGetVertexAttribdv; + //extern PFNGLGETVERTEXATTRIBFVPROC glGetVertexAttribfv; + //extern PFNGLGETVERTEXATTRIBIVPROC glGetVertexAttribiv; + //extern PFNGLGETVERTEXATTRIBPOINTERVPROC glGetVertexAttribPointerv; + //extern PFNGLISPROGRAMPROC glIsProgram; + //extern PFNGLISSHADERPROC glIsShader; + //extern PFNGLUNIFORM2FPROC glUniform2f; + //extern PFNGLUNIFORM3FPROC glUniform3f; + //extern PFNGLUNIFORM4FPROC glUniform4f; + //extern PFNGLUNIFORM1IPROC glUniform1i; + //extern PFNGLUNIFORM2IPROC glUniform2i; + //extern PFNGLUNIFORM3IPROC glUniform3i; + //extern PFNGLUNIFORM4IPROC glUniform4i; + //extern PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fv; + //extern PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv; + //extern PFNGLVALIDATEPROGRAMPROC glValidateProgram; + //extern PFNGLVERTEXATTRIB1DPROC glVertexAttrib1d; + //extern PFNGLVERTEXATTRIB1DVPROC glVertexAttrib1dv; + //extern PFNGLVERTEXATTRIB1FPROC glVertexAttrib1f; + //extern PFNGLVERTEXATTRIB1FVPROC glVertexAttrib1fv; + //extern PFNGLVERTEXATTRIB1SPROC glVertexAttrib1s; + //extern PFNGLVERTEXATTRIB1SVPROC glVertexAttrib1sv; + //extern PFNGLVERTEXATTRIB2DPROC glVertexAttrib2d; + //extern PFNGLVERTEXATTRIB2DVPROC glVertexAttrib2dv; + //extern PFNGLVERTEXATTRIB2FPROC glVertexAttrib2f; + //extern PFNGLVERTEXATTRIB2FVPROC glVertexAttrib2fv; + //extern PFNGLVERTEXATTRIB2SPROC glVertexAttrib2s; + //extern PFNGLVERTEXATTRIB2SVPROC glVertexAttrib2sv; + //extern PFNGLVERTEXATTRIB3DPROC glVertexAttrib3d; + //extern PFNGLVERTEXATTRIB3DVPROC glVertexAttrib3dv; + //extern PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f; + //extern PFNGLVERTEXATTRIB3FVPROC glVertexAttrib3fv; + //extern PFNGLVERTEXATTRIB3SPROC glVertexAttrib3s; + //extern PFNGLVERTEXATTRIB3SVPROC glVertexAttrib3sv; + //extern PFNGLVERTEXATTRIB4NBVPROC glVertexAttrib4Nbv; + //extern PFNGLVERTEXATTRIB4NIVPROC glVertexAttrib4Niv; + //extern PFNGLVERTEXATTRIB4NSVPROC glVertexAttrib4Nsv; + //extern PFNGLVERTEXATTRIB4NUBPROC glVertexAttrib4Nub; + //extern PFNGLVERTEXATTRIB4NUBVPROC glVertexAttrib4Nubv; + //extern PFNGLVERTEXATTRIB4NUIVPROC glVertexAttrib4Nuiv; + //extern PFNGLVERTEXATTRIB4NUSVPROC glVertexAttrib4Nusv; + //extern PFNGLVERTEXATTRIB4BVPROC glVertexAttrib4bv; + //extern PFNGLVERTEXATTRIB4DPROC glVertexAttrib4d; + //extern PFNGLVERTEXATTRIB4DVPROC glVertexAttrib4dv; + //extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; + //extern PFNGLVERTEXATTRIB4FVPROC glVertexAttrib4fv; + //extern PFNGLVERTEXATTRIB4IVPROC glVertexAttrib4iv; + //extern PFNGLVERTEXATTRIB4SPROC glVertexAttrib4s; + //extern PFNGLVERTEXATTRIB4SVPROC glVertexAttrib4sv; + //extern PFNGLVERTEXATTRIB4UBVPROC glVertexAttrib4ubv; + //extern PFNGLVERTEXATTRIB4UIVPROC glVertexAttrib4uiv; + //extern PFNGLVERTEXATTRIB4USVPROC glVertexAttrib4usv; + + //GL_VERSION_2_1 + //extern PFNGLUNIFORMMATRIX2X3FVPROC glUniformMatrix2x3fv; + //extern PFNGLUNIFORMMATRIX3X2FVPROC glUniformMatrix3x2fv; + //extern PFNGLUNIFORMMATRIX2X4FVPROC glUniformMatrix2x4fv; + //extern PFNGLUNIFORMMATRIX4X2FVPROC glUniformMatrix4x2fv; + //extern PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv; + //extern PFNGLUNIFORMMATRIX4X3FVPROC glUniformMatrix4x3fv; + + //GL_VERSION_3_0 + extern PFNGLBINDBUFFERRANGEPROC glBindBufferRange; + extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; + extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; + extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; + extern PFNGLINVALIDATEFRAMEBUFFERPROC glInvalidateFramebuffer; + extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; + extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; + extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; + extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; + extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; + extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; + extern PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample; + extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; + extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; + extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; + //extern PFNGLCOLORMASKIPROC glColorMaski; + //extern PFNGLGETBOOLEANI_VPROC glGetBooleani_v; + //extern PFNGLGETINTEGERI_VPROC glGetIntegeri_v; + //extern PFNGLENABLEIPROC glEnablei; + //extern PFNGLDISABLEIPROC glDisablei; + //extern PFNGLISENABLEDIPROC glIsEnabledi; + //extern PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback; + //extern PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback; + //extern PFNGLBINDBUFFERBASEPROC glBindBufferBase; + //extern PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings; + //extern PFNGLGETTRANSFORMFEEDBACKVARYINGPROC glGetTransformFeedbackVarying; + //extern PFNGLCLAMPCOLORPROC glClampColor; + //extern PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender; + //extern PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender; + //extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; + //extern PFNGLGETVERTEXATTRIBIIVPROC glGetVertexAttribIiv; + //extern PFNGLGETVERTEXATTRIBIUIVPROC glGetVertexAttribIuiv; + //extern PFNGLVERTEXATTRIBI1IPROC glVertexAttribI1i; + //extern PFNGLVERTEXATTRIBI2IPROC glVertexAttribI2i; + //extern PFNGLVERTEXATTRIBI3IPROC glVertexAttribI3i; + //extern PFNGLVERTEXATTRIBI4IPROC glVertexAttribI4i; + //extern PFNGLVERTEXATTRIBI1UIPROC glVertexAttribI1ui; + //extern PFNGLVERTEXATTRIBI2UIPROC glVertexAttribI2ui; + //extern PFNGLVERTEXATTRIBI3UIPROC glVertexAttribI3ui; + //extern PFNGLVERTEXATTRIBI4UIPROC glVertexAttribI4ui; + //extern PFNGLVERTEXATTRIBI1IVPROC glVertexAttribI1iv; + //extern PFNGLVERTEXATTRIBI2IVPROC glVertexAttribI2iv; + //extern PFNGLVERTEXATTRIBI3IVPROC glVertexAttribI3iv; + //extern PFNGLVERTEXATTRIBI4IVPROC glVertexAttribI4iv; + //extern PFNGLVERTEXATTRIBI1UIVPROC glVertexAttribI1uiv; + //extern PFNGLVERTEXATTRIBI2UIVPROC glVertexAttribI2uiv; + //extern PFNGLVERTEXATTRIBI3UIVPROC glVertexAttribI3uiv; + //extern PFNGLVERTEXATTRIBI4UIVPROC glVertexAttribI4uiv; + //extern PFNGLVERTEXATTRIBI4BVPROC glVertexAttribI4bv; + //extern PFNGLVERTEXATTRIBI4SVPROC glVertexAttribI4sv; + //extern PFNGLVERTEXATTRIBI4UBVPROC glVertexAttribI4ubv; + //extern PFNGLVERTEXATTRIBI4USVPROC glVertexAttribI4usv; + //extern PFNGLGETUNIFORMUIVPROC glGetUniformuiv; + //extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; + //extern PFNGLGETFRAGDATALOCATIONPROC glGetFragDataLocation; + //extern PFNGLUNIFORM1UIPROC glUniform1ui; + //extern PFNGLUNIFORM2UIPROC glUniform2ui; + //extern PFNGLUNIFORM3UIPROC glUniform3ui; + //extern PFNGLUNIFORM4UIPROC glUniform4ui; + //extern PFNGLUNIFORM1UIVPROC glUniform1uiv; + //extern PFNGLUNIFORM2UIVPROC glUniform2uiv; + //extern PFNGLUNIFORM3UIVPROC glUniform3uiv; + //extern PFNGLUNIFORM4UIVPROC glUniform4uiv; + //extern PFNGLTEXPARAMETERIIVPROC glTexParameterIiv; + //extern PFNGLTEXPARAMETERIUIVPROC glTexParameterIuiv; + //extern PFNGLGETTEXPARAMETERIIVPROC glGetTexParameterIiv; + //extern PFNGLGETTEXPARAMETERIUIVPROC glGetTexParameterIuiv; + //extern PFNGLCLEARBUFFERIVPROC glClearBufferiv; + //extern PFNGLCLEARBUFFERUIVPROC glClearBufferuiv; + //extern PFNGLCLEARBUFFERFVPROC glClearBufferfv; + //extern PFNGLCLEARBUFFERFIPROC glClearBufferfi; + //extern PFNGLGETSTRINGIPROC glGetStringi; + //extern PFNGLISRENDERBUFFERPROC glIsRenderbuffer; + //extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; + //extern PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv; + //extern PFNGLISFRAMEBUFFERPROC glIsFramebuffer; + //extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; + //extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; + //extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; + //extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv; + //extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; + //extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; + //extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; + //extern PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange; + //extern PFNGLISVERTEXARRAYPROC glIsVertexArray; + + //GL_VERSION_3_1 + extern PFNGLGETUNIFORMBLOCKINDEXPROC glGetUniformBlockIndex; + extern PFNGLUNIFORMBLOCKBINDINGPROC glUniformBlockBinding; + //extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; + //extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; + //extern PFNGLTEXBUFFERPROC glTexBuffer; + //extern PFNGLPRIMITIVERESTARTINDEXPROC glPrimitiveRestartIndex; + //extern PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData; + //extern PFNGLGETUNIFORMINDICESPROC glGetUniformIndices; + //extern PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv; + //extern PFNGLGETACTIVEUNIFORMNAMEPROC glGetActiveUniformName; + //extern PFNGLGETACTIVEUNIFORMBLOCKIVPROC glGetActiveUniformBlockiv; + //extern PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glGetActiveUniformBlockName; + + #if defined(_WIN32) && !defined(__CYGWIN__) && defined(THORVG_GL_TARGET_GL) + extern PFNWGLGETCURRENTCONTEXTPROC tvgWglGetCurrentContext; + extern PFNWGLMAKECURRENTPROC tvgWglMakeCurrent; + #endif + + #if defined(THORVG_GL_TARGET_GLES) + extern PFNEGLGETCURRENTCONTEXTPROC tvgEglGetCurrentContext; + extern PFNEGLMAKECURRENTPROC tvgEglMakeCurrent; + #endif + +#endif // __EMSCRIPTEN__ + +bool glInit(); +bool glTerm(); + +#endif // _TVG_GL_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlCommon.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlCommon.h new file mode 100644 index 0000000..cdb1ce2 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlCommon.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_COMMON_H_ +#define _TVG_GL_COMMON_H_ + +#include +#include "tvgGl.h" +#include "tvgRender.h" +#include "tvgMath.h" + +constexpr float MIN_GL_STROKE_WIDTH = 1.0f; +constexpr float MIN_GL_STROKE_ALPHA = 0.25f; + +constexpr uint32_t GL_MAT3_STD140_SIZE = 12; // mat3 is 3 vec4 columns in std140 +constexpr uint32_t GL_MAT3_STD140_BYTES = GL_MAT3_STD140_SIZE * sizeof(float); + +// All GPU matrices use column major order. std140 mat3 packs each column into a vec4 stride. +static inline void getMatrix3Std140(const Matrix& mat3, float* matOut) +{ + matOut[0] = mat3.e11; + matOut[1] = mat3.e21; + matOut[2] = mat3.e31; + matOut[3] = 0.0f; + matOut[4] = mat3.e12; + matOut[5] = mat3.e22; + matOut[6] = mat3.e32; + matOut[7] = 0.0f; + matOut[8] = mat3.e13; + matOut[9] = mat3.e23; + matOut[10] = mat3.e33; + matOut[11] = 0.0f; +} + + + +enum class GlStencilMode { + None, + FillNonZero, + FillEvenOdd, + Stroke, +}; + + +class GlStageBuffer; +class GlRenderTask; + +struct GlGeometryBuffer { + Array vertex; + Array index; + + void clear() + { + vertex.clear(); + index.clear(); + } + +}; + +struct GlGeometry +{ + void prepare(const RenderShape& rshape); + bool tesselateShape(const RenderShape& rshape, float* opacityMultiplier = nullptr); + bool tesselateStroke(const RenderShape& rshape); + bool tesselateLine(const RenderPath& path); + void tesselateImage(const RenderSurface* image); + bool draw(GlRenderTask* task, GlStageBuffer* gpuBuffer, RenderUpdateFlag flag); + GlStencilMode getStencilMode(RenderUpdateFlag flag); + RenderRegion getBounds() const; + + GlGeometryBuffer fill, stroke; + Matrix matrix = {}; + RenderRegion viewport = {}; + RenderRegion bounds = {}; + FillRule fillRule = FillRule::NonZero; + RenderPath optPath; //optimal path + bool convex; +}; + + +struct GlShape +{ + const RenderShape* rshape = nullptr; + float viewWd; + float viewHt; + uint32_t opacity = 0; + GLuint texId = 0; + uint32_t texFlipY = 0; + ColorSpace texColorSpace = ColorSpace::ABGR8888; + GlGeometry geometry; + Array clips; + bool validFill = false; + bool validStroke = false; +}; + +struct GlIntersector +{ + bool isPointInTriangle(const Point& p, const Point& a, const Point& b, const Point& c); + bool isPointInImage(const Point& p, const GlGeometryBuffer& mesh, const Matrix& tr); + bool isPointInTris(const Point& p, const GlGeometryBuffer& mesh, const Matrix& tr); + bool isPointInMesh(const Point& p, const GlGeometryBuffer& mesh, const Matrix& tr); + bool intersectClips(const Point& pt, const tvg::Array& clips); + bool intersectShape(const RenderRegion region, const GlShape* shape); + bool intersectImage(const RenderRegion region, const GlShape* image); +}; + +#define MAX_GRADIENT_STOPS 16 + +struct GlLinearGradientBlock +{ + alignas(16) float nStops[4] = {}; + alignas(16) float startPos[2] = {}; + alignas(8) float stopPos[2] = {}; + alignas(8) float stopPoints[MAX_GRADIENT_STOPS] = {}; + alignas(16) float stopColors[4 * MAX_GRADIENT_STOPS] = {}; +}; + +struct GlRadialGradientBlock +{ + alignas(16) float nStops[4] = {}; + alignas(16) float centerPos[4] = {}; + alignas(16) float radius[2] = {}; + alignas(16) float stopPoints[MAX_GRADIENT_STOPS] = {}; + alignas(16) float stopColors[4 * MAX_GRADIENT_STOPS] = {}; +}; + +struct GlCompositor : RenderCompositor +{ + RenderRegion bbox; + CompositionFlag flags; + BlendMethod blendMethod = BlendMethod::Normal; + + GlCompositor(const RenderRegion& box, CompositionFlag flags) : bbox(box), flags(flags) {} +}; + + +#endif /* _TVG_GL_COMMON_H_ */ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlEffect.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlEffect.cpp new file mode 100644 index 0000000..93a82c9 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlEffect.cpp @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgGlRenderTask.h" +#include "tvgGlGpuBuffer.h" +#include "tvgGlRenderPass.h" +#include "tvgGlShaderSrc.h" +#include "tvgGlEffect.h" + + +/************************************************************************/ +/* Gaussian Blur */ +/************************************************************************/ + +struct GlGaussianBlur { + float sigma{}; + float scale{}; + float extend{}; + float dummy0{}; +}; + + +bool GlEffect::region(RenderEffectGaussianBlur* effect) +{ + auto gaussianBlur = (GlGaussianBlur*)effect->rd; + if (effect->direction != 2) { + effect->extend.min.x = -gaussianBlur->extend; + effect->extend.max.x = +gaussianBlur->extend; + } + if (effect->direction != 1) { + effect->extend.min.y = -gaussianBlur->extend; + effect->extend.max.y = +gaussianBlur->extend; + } + return true; +}; + + +void GlEffect::update(RenderEffectGaussianBlur* effect, const Matrix& transform) +{ + GlGaussianBlur* blur = (GlGaussianBlur*)effect->rd; + if (!blur) blur = tvg::malloc(sizeof(GlGaussianBlur)); + blur->sigma = effect->sigma; + blur->scale = std::sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12); + blur->extend = 2 * blur->sigma * blur->scale; + effect->rd = blur; + effect->valid = (blur->extend > 0); +} + + +GlRenderTask* GlEffect::render(RenderEffectGaussianBlur* effect, GlRenderTarget* dstFbo, Array& blendPool, const RenderRegion& vp, uint32_t voffset, uint32_t ioffset) +{ + if (!pBlurV) pBlurV = new GlProgram(EFFECT_VERTEX, GAUSSIAN_VERTICAL); + if (!pBlurH) pBlurH = new GlProgram(EFFECT_VERTEX, GAUSSIAN_HORIZONTAL); + + // get current and intermediate framebuffers + auto dstCopyFbo0 = blendPool[0]->getRenderTarget(vp); + auto dstCopyFbo1 = blendPool[1]->getRenderTarget(vp); + + // add uniform data + float viewport[4] {(float)vp.min.x, (float)vp.min.y, (float)vp.max.x, (float)vp.max.y}; + auto blurOffset = gpuBuffer->push((GlGaussianBlur*)(effect->rd), sizeof(GlGaussianBlur), true); + auto viewportOffset = gpuBuffer->push(viewport, sizeof(viewport), true); + + // create gaussian blur tasks + auto task = new GlGaussianBlurTask(dstFbo, dstCopyFbo0, dstCopyFbo1); + task->effect = effect; + task->setViewport({{0, 0}, {vp.sw(), vp.sh()}}); + // horizontal blur task and geometry + task->horzTask = new GlRenderTask(pBlurH); + task->horzTask->addBindResource(GlBindingResource{0, pBlurH->getUniformBlockIndex("Gaussian"), gpuBuffer->getBufferId(), blurOffset, sizeof(GlGaussianBlur)}); + task->horzTask->addBindResource(GlBindingResource{1, pBlurH->getUniformBlockIndex("Viewport"), gpuBuffer->getBufferId(), viewportOffset, sizeof(viewport)}); + task->horzTask->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), voffset}); + task->horzTask->setDrawRange(ioffset, 6); + // vertical blur task and geometry + task->vertTask = new GlRenderTask(pBlurV); + task->vertTask->addBindResource(GlBindingResource{0, pBlurV->getUniformBlockIndex("Gaussian"), gpuBuffer->getBufferId(), blurOffset, sizeof(GlGaussianBlur)}); + task->vertTask->addBindResource(GlBindingResource{1, pBlurV->getUniformBlockIndex("Viewport"), gpuBuffer->getBufferId(), viewportOffset, sizeof(viewport)}); + task->vertTask->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), voffset}); + task->vertTask->setDrawRange(ioffset, 6); + + return task; +} + + +/************************************************************************/ +/* DropShadow */ +/************************************************************************/ + +struct GlDropShadow: GlGaussianBlur { + float color[4]; + float offset[2]; +}; + + +bool GlEffect::region(RenderEffectDropShadow* effect) +{ + auto gaussianBlur = (GlDropShadow*)effect->rd; + effect->extend.min.x = -gaussianBlur->extend; + effect->extend.max.x = +gaussianBlur->extend; + effect->extend.min.y = -gaussianBlur->extend; + effect->extend.max.y = +gaussianBlur->extend; + return true; +}; + + +void GlEffect::update(RenderEffectDropShadow* effect, const Matrix& transform) +{ + GlDropShadow* dropShadow = (GlDropShadow*)effect->rd; + if (!dropShadow) dropShadow = tvg::malloc(sizeof(GlDropShadow)); + const auto scale = std::sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12); + const auto radian = tvg::deg2rad(90.0f - effect->angle) - tvg::radian(transform); + const Point offset = {-effect->distance * cosf(radian) * scale, -effect->distance * sinf(radian) * scale}; + + dropShadow->sigma = effect->sigma; + dropShadow->scale = scale; + dropShadow->color[3] = effect->color[3] / 255.0f; + //Drop shadow effect applies blending in the shader (GL_BLEND disabled), so the color should be premultiplied: + dropShadow->color[0] = effect->color[0] / 255.0f * dropShadow->color[3]; + dropShadow->color[1] = effect->color[1] / 255.0f * dropShadow->color[3]; + dropShadow->color[2] = effect->color[2] / 255.0f * dropShadow->color[3]; + dropShadow->offset[0] = offset.x; + dropShadow->offset[1] = offset.y; + dropShadow->extend = 2 * std::max(effect->sigma * scale + std::abs(offset.x), effect->sigma * scale + std::abs(offset.y)); + effect->rd = dropShadow; + effect->valid = (dropShadow->extend >= 0); +} + + +GlRenderTask* GlEffect::render(RenderEffectDropShadow* effect, GlRenderTarget* dstFbo, Array& blendPool, const RenderRegion& vp, uint32_t voffset, uint32_t ioffset) +{ + if (!pBlurV) pBlurV = new GlProgram(EFFECT_VERTEX, GAUSSIAN_VERTICAL); + if (!pBlurH) pBlurH = new GlProgram(EFFECT_VERTEX, GAUSSIAN_HORIZONTAL); + if (!pDropShadow) pDropShadow = new GlProgram(EFFECT_VERTEX, EFFECT_DROPSHADOW); + + // get current and intermediate framebuffers + auto dstCopyFbo0 = blendPool[0]->getRenderTarget(vp); + auto dstCopyFbo1 = blendPool[1]->getRenderTarget(vp); + + // add uniform data + float viewport[4] {(float)vp.min.x, (float)vp.min.y, (float)vp.max.x, (float)vp.max.y}; + GlDropShadow* params = (GlDropShadow*)(effect->rd); + auto paramsOffset = gpuBuffer->push(params, sizeof(GlDropShadow), true); + auto viewportOffset = gpuBuffer->push(viewport, sizeof(viewport), true); + + // create gaussian blur tasks + auto task = new GlEffectDropShadowTask(pDropShadow, dstFbo, dstCopyFbo0, dstCopyFbo1); + task->effect = (RenderEffectDropShadow*)effect; + task->setViewport({{0, 0}, {vp.sw(), vp.sh()}}); + task->addBindResource(GlBindingResource{0, pDropShadow->getUniformBlockIndex("DropShadow"), gpuBuffer->getBufferId(), paramsOffset, sizeof(GlDropShadow)}); + task->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), voffset}); + task->setDrawRange(ioffset, 6); + + // horizontal blur task and geometry + task->horzTask = new GlRenderTask(pBlurH); + task->horzTask->addBindResource(GlBindingResource{0, pBlurH->getUniformBlockIndex("Gaussian"), gpuBuffer->getBufferId(), paramsOffset, sizeof(GlGaussianBlur)}); + task->horzTask->addBindResource(GlBindingResource{1, pBlurH->getUniformBlockIndex("Viewport"), gpuBuffer->getBufferId(), viewportOffset, sizeof(viewport)}); + task->horzTask->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), voffset}); + task->horzTask->setDrawRange(ioffset, 6); + + // vertical blur task and geometry + task->vertTask = new GlRenderTask(pBlurV); + task->vertTask->addBindResource(GlBindingResource{0, pBlurV->getUniformBlockIndex("Gaussian"), gpuBuffer->getBufferId(), paramsOffset, sizeof(GlGaussianBlur)}); + task->vertTask->addBindResource(GlBindingResource{1, pBlurV->getUniformBlockIndex("Viewport"), gpuBuffer->getBufferId(), viewportOffset, sizeof(viewport)}); + task->vertTask->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), voffset}); + task->vertTask->setDrawRange(ioffset, 6); + + return task; +} + + +/************************************************************************/ +/* ColorReplacement */ +/************************************************************************/ + +struct GlEffectParams { + // fill: [0..3]: color + // tint: [0..2]: black, [4..6]: white, [8]: intensity + // tritone: [0..2]: shadow, [4..6]: midtone, [8..10]: highlight [11]: blender + float params[4+4+4]; +}; + + +void GlEffect::update(RenderEffectFill* effect, const Matrix& transform) +{ + auto params = (GlEffectParams*)effect->rd; + if (!params) params = tvg::malloc(sizeof(GlEffectParams)); + params->params[0] = effect->color[0] / 255.0f; + params->params[1] = effect->color[1] / 255.0f; + params->params[2] = effect->color[2] / 255.0f; + params->params[3] = effect->color[3] / 255.0f; + effect->rd = params; + effect->valid = true; +} + + +void GlEffect::update(RenderEffectTint* effect, const Matrix& transform) +{ + effect->valid = (effect->intensity > 0); + if (!effect->valid) return; + + auto params = (GlEffectParams*)effect->rd; + if (!params) params = tvg::malloc(sizeof(GlEffectParams)); + params->params[0] = effect->black[0] / 255.0f; + params->params[1] = effect->black[1] / 255.0f; + params->params[2] = effect->black[2] / 255.0f; + params->params[3] = 0.0f; + params->params[4] = effect->white[0] / 255.0f; + params->params[5] = effect->white[1] / 255.0f; + params->params[6] = effect->white[2] / 255.0f; + params->params[7] = 0.0f; + params->params[8] = effect->intensity / 255.0f; + effect->rd = params; +} + + +void GlEffect::update(RenderEffectTritone* effect, const Matrix& transform) +{ + effect->valid = (effect->blender < 255); + if (!effect->valid) return; + + auto params = (GlEffectParams*)effect->rd; + if (!params) params = tvg::malloc(sizeof(GlEffectParams)); + params->params[0] = effect->shadow[0] / 255.0f; + params->params[1] = effect->shadow[1] / 255.0f; + params->params[2] = effect->shadow[2] / 255.0f; + params->params[3] = 0.0f; + params->params[4] = effect->midtone[0] / 255.0f; + params->params[5] = effect->midtone[1] / 255.0f; + params->params[6] = effect->midtone[2] / 255.0f; + params->params[7] = 0.0f; + params->params[8] = effect->highlight[0] / 255.0f; + params->params[9] = effect->highlight[1] / 255.0f; + params->params[10] = effect->highlight[2] / 255.0f; + params->params[11] = effect->blender / 255.0f; + effect->rd = params; +} + + +GlRenderTask* GlEffect::render(RenderEffect* effect, GlRenderTarget* dstFbo, Array& blendPool, const RenderRegion& vp, uint32_t voffset, uint32_t ioffset) +{ + //common color replacement effects + GlProgram* program = nullptr; + if (effect->type == SceneEffect::Fill) { + if (!pFill) pFill = new GlProgram(EFFECT_VERTEX, EFFECT_FILL); + program = pFill; + } else if (effect->type == SceneEffect::Tint) { + if (!pTint) pTint = new GlProgram(EFFECT_VERTEX, EFFECT_TINT); + program = pTint; + } else if (effect->type == SceneEffect::Tritone) { + if (!pTritone) pTritone = new GlProgram(EFFECT_VERTEX, EFFECT_TRITONE); + program = pTritone; + } else return nullptr; + + // get current and intermediate framebuffers + auto dstCopyFbo = blendPool[0]->getRenderTarget(vp); + + // add uniform data + auto params = (GlEffectParams*)(effect->rd); + auto paramsOffset = gpuBuffer->push(params, sizeof(GlEffectParams), true); + + // create and setup task + auto task = new GlEffectColorTransformTask(program, dstFbo, dstCopyFbo); + task->setViewport({{0, 0}, {vp.sw(), vp.sh()}}); + task->addBindResource(GlBindingResource{0, program->getUniformBlockIndex("Params"), gpuBuffer->getBufferId(), paramsOffset, sizeof(GlEffectParams)}); + task->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), voffset}); + task->setDrawRange(ioffset, 6); + + return task; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +void GlEffect::update(RenderEffect* effect, const Matrix& transform) +{ + switch (effect->type) { + case SceneEffect::GaussianBlur: update(static_cast(effect), transform); break; + case SceneEffect::DropShadow : update(static_cast(effect), transform); break; + case SceneEffect::Fill: update(static_cast(effect), transform); break; + case SceneEffect::Tint: update(static_cast(effect), transform); break; + case SceneEffect::Tritone: update(static_cast(effect), transform); break; + default: break; + } +} + + +bool GlEffect::region(RenderEffect* effect) +{ + switch (effect->type) { + case SceneEffect::GaussianBlur: return region(static_cast(effect)); + case SceneEffect::DropShadow : return region(static_cast(effect)); + default: return false; + } +} + + +bool GlEffect::render(RenderEffect* effect, GlRenderPass* pass, Array& blendPool) +{ + if (pass->isEmpty()) return false; + auto vp = pass->getViewport(); + + // add render geometry + const float vdata[] = {-1.0f, +1.0f, +1.0f, +1.0f, +1.0f, -1.0f, -1.0f, -1.0f}; + const uint32_t idata[] = { 0, 1, 2, 0, 2, 3 }; + auto voffset = gpuBuffer->push((void*)vdata, sizeof(vdata)); + auto ioffset = gpuBuffer->pushIndex((void*)idata, sizeof(idata)); + GlRenderTask* output = nullptr; + + if (effect->type == SceneEffect::GaussianBlur) { + output = render(static_cast(effect), pass->getFbo(), blendPool, vp, voffset, ioffset); + } else if (effect->type == SceneEffect::DropShadow) { + output = render(static_cast(effect), pass->getFbo(), blendPool, vp, voffset, ioffset); + } else { + output = render(effect, pass->getFbo(), blendPool, vp, voffset, ioffset); + } + + if (!output) return false; + + pass->addRenderTask(output); + return true; +} + + +GlEffect::GlEffect(GlStageBuffer* buffer) : gpuBuffer(buffer) +{ +} + + +GlEffect::~GlEffect() +{ + delete(pBlurV); + delete(pBlurH); + delete(pDropShadow); + delete(pFill); + delete(pTint); + delete(pTritone); +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlEffect.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlEffect.h new file mode 100644 index 0000000..cdcae4d --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlEffect.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_EFFECT_H_ +#define _TVG_GL_EFFECT_H_ + +#include "tvgRender.h" +#include "tvgGlProgram.h" + + +class GlEffect +{ +private: + GlStageBuffer* gpuBuffer; //shared resource with GlRenderer + + GlProgram* pBlurV{}; + GlProgram* pBlurH{}; + GlProgram* pDropShadow{}; + GlProgram* pFill{}; + GlProgram* pTint{}; + GlProgram* pTritone{}; + + void update(RenderEffectGaussianBlur* effect, const Matrix& transform); + void update(RenderEffectDropShadow* effect, const Matrix& transform); + void update(RenderEffectFill* effect, const Matrix& transform); + void update(RenderEffectTint* effect, const Matrix& transform); + void update(RenderEffectTritone* effect, const Matrix& transform); + + bool region(RenderEffectGaussianBlur* effect); + bool region(RenderEffectDropShadow* effect); + + GlRenderTask* render(RenderEffectGaussianBlur* effect, GlRenderTarget* dstFbo, Array& blendPool, const RenderRegion& vp, uint32_t voffset, uint32_t ioffset); + GlRenderTask* render(RenderEffectDropShadow* effect, GlRenderTarget* dstFbo, Array& blendPool, const RenderRegion& vp, uint32_t voffset, uint32_t ioffset); + GlRenderTask* render(RenderEffect* effect, GlRenderTarget* dstFbo, Array& blendPool, const RenderRegion& vp, uint32_t voffset, uint32_t ioffset); + +public: + GlEffect(GlStageBuffer* buffer); + ~GlEffect(); + + void update(RenderEffect* effect, const Matrix& transform); + bool region(RenderEffect* effect); + bool render(RenderEffect* effect, GlRenderPass* pass, Array& blendPool); +}; + +#endif /* _TVG_GL_EFFECT_H_ */ diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlGeometry.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlGeometry.cpp new file mode 100644 index 0000000..e107822 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlGeometry.cpp @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlCommon.h" +#include "tvgGlGpuBuffer.h" +#include "tvgGlRenderTask.h" +#include "tvgGlTessellator.h" + +bool GlIntersector::isPointInTriangle(const Point& p, const Point& a, const Point& b, const Point& c) +{ + auto d1 = tvg::cross(p - a, p - b); + auto d2 = tvg::cross(p - b, p - c); + auto d3 = tvg::cross(p - c, p - a); + auto has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0); + auto has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0); + return !(has_neg && has_pos); +} + +bool GlIntersector::isPointInImage(const Point& p, const GlGeometryBuffer& mesh, const Matrix& tr) +{ + for (uint32_t i = 0; i < mesh.index.count; i += 3) { + auto p0 = Point{mesh.vertex[mesh.index[i+0]*4+0], mesh.vertex[mesh.index[i+0]*4+1]} * tr; + auto p1 = Point{mesh.vertex[mesh.index[i+1]*4+0], mesh.vertex[mesh.index[i+1]*4+1]} * tr; + auto p2 = Point{mesh.vertex[mesh.index[i+2]*4+0], mesh.vertex[mesh.index[i+2]*4+1]} * tr; + if (isPointInTriangle(p, p0, p1, p2)) return true; + } + return false; +} + + +// triangle list +bool GlIntersector::isPointInTris(const Point& p, const GlGeometryBuffer& mesh, const Matrix& tr) +{ + for (uint32_t i = 0; i < mesh.index.count; i += 3) { + auto p0 = Point{mesh.vertex[mesh.index[i+0]*2+0], mesh.vertex[mesh.index[i+0]*2+1]} * tr; + auto p1 = Point{mesh.vertex[mesh.index[i+1]*2+0], mesh.vertex[mesh.index[i+1]*2+1]} * tr; + auto p2 = Point{mesh.vertex[mesh.index[i+2]*2+0], mesh.vertex[mesh.index[i+2]*2+1]} * tr; + if (isPointInTriangle(p, p0, p1, p2)) return true; + } + return false; +} + + +// even-odd triangle list +bool GlIntersector::isPointInMesh(const Point& p, const GlGeometryBuffer& mesh, const Matrix& tr) +{ + uint32_t crossings = 0; + for (uint32_t i = 0; i < mesh.index.count; i += 3) { + Point triangle[3] = { + Point{mesh.vertex[mesh.index[i+0]*2+0], mesh.vertex[mesh.index[i+0]*2+1]} * tr, + Point{mesh.vertex[mesh.index[i+1]*2+0], mesh.vertex[mesh.index[i+1]*2+1]} * tr, + Point{mesh.vertex[mesh.index[i+2]*2+0], mesh.vertex[mesh.index[i+2]*2+1]} * tr + }; + for (uint32_t j = 0; j < 3; j++) { + auto p1 = triangle[j]; + auto p2 = triangle[(j + 1) % 3]; + if (p1.y == p2.y) continue; + if (p1.y > p2.y) std::swap(p1, p2); + if ((p.y > p1.y) && (p.y <= p2.y)) { + auto intersectionX = (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x; + if (intersectionX > p.x) crossings++; + } + } + } + return (crossings % 2) == 1; +} + + +bool GlIntersector::intersectClips(const Point& pt, const tvg::Array& clips) +{ + for (uint32_t i = 0; i < clips.count; i++) { + auto clip = (GlShape*)clips[i]; + if (!isPointInMesh(pt, clip->geometry.fill, clip->geometry.matrix)) return false; + } + return true; +} + + +bool GlIntersector::intersectShape(const RenderRegion region, const GlShape* shape) +{ + if (!shape || ((shape->geometry.fill.index.count == 0) && (shape->geometry.stroke.index.count == 0))) return false; + auto sizeX = region.sw(); + auto sizeY = region.sh(); + + for (int32_t y = 0; y <= sizeY; y++) { + for (int32_t x = 0; x <= sizeX; x++) { + Point pt{(float)x + region.min.x, (float)y + region.min.y}; + if (y % 2 == 1) pt.y = (float)sizeY - y - sizeY % 2 + region.min.y; + if (intersectClips(pt, shape->clips)) { + if (shape->validFill && isPointInMesh(pt, shape->geometry.fill, shape->geometry.matrix)) return true; + if (shape->validStroke && isPointInTris(pt, shape->geometry.stroke, shape->geometry.matrix)) return true; + } + } + } + return false; +} + + +bool GlIntersector::intersectImage(const RenderRegion region, const GlShape* image) +{ + if (image) { + auto sizeX = region.sw(); + auto sizeY = region.sh(); + for (int32_t y = 0; y <= sizeY; y++) { + for (int32_t x = 0; x <= sizeX; x++) { + Point pt{(float) x + region.min.x, (float) y + region.min.y}; + if (y % 2 == 1) pt.y = (float) sizeY - y - sizeY % 2 + region.min.y; + if (intersectClips(pt, image->clips)) { + if (isPointInImage(pt, image->geometry.fill, image->geometry.matrix)) return true; + } + } + } + } + return false; +} + + +void GlGeometry::prepare(const RenderShape& rshape) +{ + if (rshape.trimpath()) { + RenderPath trimmedPath; + if (rshape.stroke->trim.trim(rshape.path, trimmedPath)) { + trimmedPath.optimize(optPath, matrix); + } else { + optPath.clear(); + } + } else rshape.path.optimize(optPath, matrix); +} + + +bool GlGeometry::tesselateShape(const RenderShape& rshape, float* opacityMultiplier) +{ + fill.clear(); + convex = false; + + // When the CTM scales a filled path so small that its device-space + // World: [========] // normal-sized filled path + // After CTM: [.] // thinner than 1 px in device space + // Handling: two points // collapse to a 2-point handle for stability + if (optPath.pts.count == 2 && tvg::zero(rshape.strokeWidth())) { + if (tesselateLine(optPath)) { + // The time spent is similar to substituting buffers in tessellation, so we just move the buffers to keep the code simple. + stroke.index.move(fill.index); + stroke.vertex.move(fill.vertex); + if (opacityMultiplier) *opacityMultiplier = MIN_GL_STROKE_ALPHA; + fillRule = rshape.rule; + return true; + } + return false; + } + + // Handle normal shapes with more than 2 points + BWTessellator bwTess{&fill}; + bwTess.tessellate(optPath, matrix); + fillRule = rshape.rule; + bounds = bwTess.bounds(); + convex = bwTess.convex; + if (opacityMultiplier) *opacityMultiplier = 1.0f; + return true; +} + + +bool GlGeometry::tesselateLine(const RenderPath& path) +{ + stroke.clear(); + if (path.pts.count != 2) return false; + Stroker stroker(&stroke, MIN_GL_STROKE_WIDTH / scaling(matrix), StrokeCap::Butt, StrokeJoin::Bevel); + stroker.run(path, matrix); + bounds = stroker.bounds(); + return true; +} + + +bool GlGeometry::tesselateStroke(const RenderShape& rshape) +{ + stroke.clear(); + auto strokeWidth = 0.0f; + if (isinf(matrix.e11)) { + strokeWidth = rshape.strokeWidth() * scaling(matrix); + if (strokeWidth <= MIN_GL_STROKE_WIDTH) strokeWidth = MIN_GL_STROKE_WIDTH; + strokeWidth = strokeWidth / matrix.e11; + } else { + strokeWidth = rshape.strokeWidth(); + } + //run stroking only if it's valid + if (!tvg::zero(strokeWidth)) { + Stroker stroker(&stroke, strokeWidth, rshape.strokeCap(), rshape.strokeJoin()); + stroker.run(rshape, optPath, matrix); + bounds = stroker.bounds(); + return true; + } + return false; +} + + +void GlGeometry::tesselateImage(const RenderSurface* image) +{ + fill.clear(); + fill.vertex.reserve(5 * 4); + fill.index.reserve(6); + + auto left = 0.f; + auto top = 0.f; + auto right = float(image->w); + auto bottom = float(image->h); + + // left top point + fill.vertex.push(left); + fill.vertex.push(top); + + fill.vertex.push(0.f); + fill.vertex.push(1.f); + // left bottom point + fill.vertex.push(left); + fill.vertex.push(bottom); + + fill.vertex.push(0.f); + fill.vertex.push(0.f); + // right top point + fill.vertex.push(right); + fill.vertex.push(top); + + fill.vertex.push(1.f); + fill.vertex.push(1.f); + // right bottom point + fill.vertex.push(right); + fill.vertex.push(bottom); + + fill.vertex.push(1.f); + fill.vertex.push(0.f); + + fill.index.push(0); + fill.index.push(1); + fill.index.push(2); + + fill.index.push(2); + fill.index.push(1); + fill.index.push(3); + + bounds = {{0, 0}, {int32_t(image->w), int32_t(image->h)}}; +} + + +bool GlGeometry::draw(GlRenderTask* task, GlStageBuffer* gpuBuffer, RenderUpdateFlag flag) +{ + if (flag == RenderUpdateFlag::None) return false; + + auto buffer = ((flag & RenderUpdateFlag::Stroke) || (flag & RenderUpdateFlag::GradientStroke)) ? &stroke : &fill; + if (buffer->index.empty()) return false; + + auto vertexOffset = gpuBuffer->push(buffer->vertex.data, buffer->vertex.count * sizeof(float)); + auto indexOffset = gpuBuffer->pushIndex(buffer->index.data, buffer->index.count * sizeof(uint32_t)); + + // vertex layout + if (flag & RenderUpdateFlag::Image) { + // image has two attribute: [pos, uv] + task->addVertexLayout(GlVertexLayout{0, 2, 4 * sizeof(float), vertexOffset}); + task->addVertexLayout(GlVertexLayout{1, 2, 4 * sizeof(float), vertexOffset + 2 * sizeof(float)}); + } else { + task->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), vertexOffset}); + } + task->setDrawRange(indexOffset, buffer->index.count); + return true; +} + + +GlStencilMode GlGeometry::getStencilMode(RenderUpdateFlag flag) +{ + if (flag & RenderUpdateFlag::Stroke) return GlStencilMode::Stroke; + if (flag & RenderUpdateFlag::GradientStroke) return GlStencilMode::Stroke; + if (flag & RenderUpdateFlag::Image) return GlStencilMode::None; + + if (convex) return GlStencilMode::None; + if (fillRule == FillRule::NonZero) return GlStencilMode::FillNonZero; + if (fillRule == FillRule::EvenOdd) return GlStencilMode::FillEvenOdd; + + return GlStencilMode::None; +} + + +RenderRegion GlGeometry::getBounds() const +{ + if (tvg::identity(&matrix)) return bounds; + + auto lt = Point{float(bounds.min.x), float(bounds.min.y)} * matrix; + auto lb = Point{float(bounds.min.x), float(bounds.max.y)} * matrix; + auto rt = Point{float(bounds.max.x), float(bounds.min.y)} * matrix; + auto rb = Point{float(bounds.max.x), float(bounds.max.y)} * matrix; + + auto left = min(min(lt.x, lb.x), min(rt.x, rb.x)); + auto top = min(min(lt.y, lb.y), min(rt.y, rb.y)); + auto right = max(max(lt.x, lb.x), max(rt.x, rb.x)); + auto bottom = max(max(lt.y, lb.y), max(rt.y, rb.y)); + + auto bounds = RenderRegion {{int32_t(floor(left)), int32_t(floor(top))}, {int32_t(ceil(right)), int32_t(ceil(bottom))}}; + if (bounds.valid()) return bounds; + return this->bounds; + +} diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlGpuBuffer.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlGpuBuffer.cpp new file mode 100644 index 0000000..62378e4 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlGpuBuffer.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlGpuBuffer.h" + +#include +#include + +/************************************************************************/ +/* GlGpuBuffer Implementation */ +/************************************************************************/ + +static GLint _getGpuBufferAlign() +{ + static GLint offset = 0; + + if (!offset) + { + GL_CHECK(glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &offset)); + } + + return offset; +} + + +void GlGpuBuffer::updateBufferData(Target target, uint32_t size, const void* data) +{ + GL_CHECK(glBufferData(static_cast(target), size, data, GL_STATIC_DRAW)); +} + + +void GlGpuBuffer::bind(Target target) +{ + GL_CHECK(glBindBuffer(static_cast(target), mGlBufferId)); +} + + +void GlGpuBuffer::unbind(Target target) +{ + GL_CHECK(glBindBuffer(static_cast(target), 0)); +} + + +GlGpuBuffer::GlGpuBuffer() +{ + GL_CHECK(glGenBuffers(1, &mGlBufferId)); + assert(mGlBufferId != 0); +} + + +GlGpuBuffer::~GlGpuBuffer() +{ + if (mGlBufferId) + { + GL_CHECK(glDeleteBuffers(1, &mGlBufferId)); + } +} + +/************************************************************************/ +/* GlStageBuffer Implementation */ +/************************************************************************/ + +GlStageBuffer::GlStageBuffer() : mVao(0), mGpuBuffer(), mGpuIndexBuffer() +{ + GL_CHECK(glGenVertexArrays(1, &mVao)); +} + + +GlStageBuffer::~GlStageBuffer() +{ + if (mVao) { + glDeleteVertexArrays(1, &mVao); + mVao = 0; + } +} + + +uint32_t GlStageBuffer::push(void *data, uint32_t size, bool alignGpuOffset) +{ + if (alignGpuOffset) alignOffset(size); + + uint32_t offset = mStageBuffer.count; + + if (this->mStageBuffer.reserved - this->mStageBuffer.count < size) { + this->mStageBuffer.grow(max(size, this->mStageBuffer.reserved)); + } + + memcpy(this->mStageBuffer.data + offset, data, size); + + this->mStageBuffer.count += size; + + return offset; +} + + +uint32_t GlStageBuffer::pushIndex(void *data, uint32_t size) +{ + uint32_t offset = mIndexBuffer.count; + + if (this->mIndexBuffer.reserved - this->mIndexBuffer.count < size) { + this->mIndexBuffer.grow(max(size, this->mIndexBuffer.reserved)); + } + + memcpy(this->mIndexBuffer.data + offset, data, size); + + this->mIndexBuffer.count += size; + + return offset; +} + + +bool GlStageBuffer::flushToGPU() +{ + if (mStageBuffer.empty() || mIndexBuffer.empty()) { + mStageBuffer.clear(); + mIndexBuffer.clear(); + return false; + } + + + mGpuBuffer.bind(GlGpuBuffer::Target::ARRAY_BUFFER); + mGpuBuffer.updateBufferData(GlGpuBuffer::Target::ARRAY_BUFFER, mStageBuffer.count, mStageBuffer.data); + mGpuBuffer.unbind(GlGpuBuffer::Target::ARRAY_BUFFER); + + mGpuIndexBuffer.bind(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER); + mGpuIndexBuffer.updateBufferData(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER, mIndexBuffer.count, mIndexBuffer.data); + mGpuIndexBuffer.unbind(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER); + + mStageBuffer.clear(); + mIndexBuffer.clear(); + + return true; +} + + +void GlStageBuffer::bind() +{ + glBindVertexArray(mVao); + mGpuBuffer.bind(GlGpuBuffer::Target::ARRAY_BUFFER); + mGpuBuffer.bind(GlGpuBuffer::Target::UNIFORM_BUFFER); + mGpuIndexBuffer.bind(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER); +} + + +void GlStageBuffer::unbind() +{ + glBindVertexArray(0); + mGpuBuffer.unbind(GlGpuBuffer::Target::ARRAY_BUFFER); + mGpuBuffer.unbind(GlGpuBuffer::Target::UNIFORM_BUFFER); + mGpuIndexBuffer.unbind(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER); +} + + +GLuint GlStageBuffer::getBufferId() +{ + return mGpuBuffer.getBufferId(); +} + + +void GlStageBuffer::alignOffset(uint32_t size) +{ + + uint32_t alignment = _getGpuBufferAlign(); + + if (mStageBuffer.count % alignment == 0) return; + + + uint32_t offset = alignment - mStageBuffer.count % alignment; + + if (mStageBuffer.count + offset + size > mStageBuffer.reserved) { + mStageBuffer.grow(max(offset + size, mStageBuffer.reserved)); + } + + mStageBuffer.count += offset; +} diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlGpuBuffer.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlGpuBuffer.h new file mode 100644 index 0000000..dea798a --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlGpuBuffer.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_GPU_BUFFER_H_ +#define _TVG_GL_GPU_BUFFER_H_ + +#include "tvgGlCommon.h" + +class GlGpuBuffer +{ +public: + enum class Target + { + ARRAY_BUFFER = GL_ARRAY_BUFFER, + ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER, + UNIFORM_BUFFER = GL_UNIFORM_BUFFER, + }; + + GlGpuBuffer(); + ~GlGpuBuffer(); + void updateBufferData(Target target, uint32_t size, const void* data); + void bind(Target target); + void unbind(Target target); + uint32_t getBufferId() { return mGlBufferId; } + +private: + uint32_t mGlBufferId = 0; + +}; + +class GlStageBuffer { +public: + GlStageBuffer(); + ~GlStageBuffer(); + + uint32_t push(void* data, uint32_t size, bool alignGpuOffset = false); + uint32_t pushIndex(void* data, uint32_t size); + bool flushToGPU(); + void bind(); + void unbind(); + GLuint getBufferId(); + +private: + void alignOffset(uint32_t size); + + GLuint mVao = 0; + GlGpuBuffer mGpuBuffer = {}; + GlGpuBuffer mGpuIndexBuffer = {}; + Array mStageBuffer = {}; + Array mIndexBuffer = {}; +}; + +#endif /* _TVG_GL_GPU_BUFFER_H_ */ + diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlProgram.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlProgram.cpp new file mode 100644 index 0000000..0ba2317 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlProgram.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlProgram.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +uint32_t GlProgram::mCurrentProgram = 0; + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +GlProgram::GlProgram(const char* vertSrc, const char* fragSrc) +{ + auto shader = GlShader(vertSrc, fragSrc); + + // Create the program object + uint32_t progObj = glCreateProgram(); + assert(progObj); + + glAttachShader(progObj, shader.getVertexShader()); + glAttachShader(progObj, shader.getFragmentShader()); + + // Link the program + glLinkProgram(progObj); + + // Check the link status + GLint linked; + glGetProgramiv(progObj, GL_LINK_STATUS, &linked); + + if (!linked) { + GLint infoLen = 0; + glGetProgramiv(progObj, GL_INFO_LOG_LENGTH, &infoLen); + if (infoLen > 0) + { + auto infoLog = tvg::malloc(sizeof(char) * infoLen); + glGetProgramInfoLog(progObj, infoLen, NULL, infoLog); + TVGERR("GL_ENGINE", "Error linking shader: %s", infoLog); + tvg::free(infoLog); + + } + glDeleteProgram(progObj); + progObj = 0; + assert(0); + } + mProgramObj = progObj; +} + + +GlProgram::~GlProgram() +{ + if (mCurrentProgram == mProgramObj) unload(); + glDeleteProgram(mProgramObj); +} + + +void GlProgram::load() +{ + if (mCurrentProgram == mProgramObj) return; + mCurrentProgram = mProgramObj; + GL_CHECK(glUseProgram(mProgramObj)); + +} + + +void GlProgram::unload() +{ + mCurrentProgram = 0; +} + + +int32_t GlProgram::getAttributeLocation(const char* name) +{ + GL_CHECK(int32_t location = glGetAttribLocation(mCurrentProgram, name)); + return location; +} + + +int32_t GlProgram::getUniformLocation(const char* name) +{ + GL_CHECK(int32_t location = glGetUniformLocation(mProgramObj, name)); + return location; +} + +int32_t GlProgram::getUniformBlockIndex(const char* name) +{ + GL_CHECK(int32_t index = glGetUniformBlockIndex(mProgramObj, name)); + return index; +} + +uint32_t GlProgram::getProgramId() +{ + return mProgramObj; +} + +void GlProgram::setUniform1Value(int32_t location, int count, const int* values) +{ + GL_CHECK(glUniform1iv(location, count, values)); +} + + +void GlProgram::setUniform2Value(int32_t location, int count, const int* values) +{ + GL_CHECK(glUniform2iv(location, count, values)); +} + + +void GlProgram::setUniform3Value(int32_t location, int count, const int* values) +{ + GL_CHECK(glUniform3iv(location, count, values)); +} + + +void GlProgram::setUniform4Value(int32_t location, int count, const int* values) +{ + GL_CHECK(glUniform4iv(location, count, values)); +} + + +void GlProgram::setUniform1Value(int32_t location, int count, const float* values) +{ + GL_CHECK(glUniform1fv(location, count, values)); +} + + +void GlProgram::setUniform2Value(int32_t location, int count, const float* values) +{ + GL_CHECK(glUniform2fv(location, count, values)); +} + + +void GlProgram::setUniform3Value(int32_t location, int count, const float* values) +{ + GL_CHECK(glUniform3fv(location, count, values)); +} + + +void GlProgram::setUniform4Value(int32_t location, int count, const float* values) +{ + GL_CHECK(glUniform4fv(location, count, values)); +} + +void GlProgram::setUniform4x4Value(int32_t location, int count, const float* values) +{ + GL_CHECK(glUniformMatrix4fv(location, count, GL_FALSE, &values[0])); +} diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlProgram.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlProgram.h new file mode 100644 index 0000000..01be21b --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlProgram.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_PROGRAM_H_ +#define _TVG_GL_PROGRAM_H_ + +#include "tvgGlShader.h" + +class GlProgram +{ +public: + GlProgram(const char* vertSrc, const char* fragSrc); + ~GlProgram(); + + void load(); + static void unload(); + int32_t getAttributeLocation(const char* name); + int32_t getUniformLocation(const char* name); + int32_t getUniformBlockIndex(const char* name); + uint32_t getProgramId(); + void setUniform1Value(int32_t location, int count, const int* values); + void setUniform2Value(int32_t location, int count, const int* values); + void setUniform3Value(int32_t location, int count, const int* values); + void setUniform4Value(int32_t location, int count, const int* values); + void setUniform1Value(int32_t location, int count, const float* values); + void setUniform2Value(int32_t location, int count, const float* values); + void setUniform3Value(int32_t location, int count, const float* values); + void setUniform4Value(int32_t location, int count, const float* values); + void setUniform4x4Value(int32_t location, int count, const float* values); + +private: + uint32_t mProgramObj; + static uint32_t mCurrentProgram; +}; + +#endif /* _TVG_GL_PROGRAM_H_ */ diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderPass.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderPass.cpp new file mode 100644 index 0000000..d30d7ff --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderPass.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlCommon.h" +#include "tvgGlRenderPass.h" +#include "tvgGlRenderTask.h" + +GlRenderPass::GlRenderPass(GlRenderTarget* fbo): mFbo(fbo), mTasks(), mDrawDepth(0) {} + +GlRenderPass::GlRenderPass(GlRenderPass&& other): mFbo(other.mFbo), mTasks(), mDrawDepth(0) +{ + mTasks.push(other.mTasks); + + other.mTasks.clear(); + + mDrawDepth = other.mDrawDepth; +} + +GlRenderPass::~GlRenderPass() +{ + if (mTasks.empty()) return; + + ARRAY_FOREACH(p, mTasks) delete(*p); + + mTasks.clear(); +} + +void GlRenderPass::addRenderTask(GlRenderTask* task) +{ + mTasks.push(task); +} + +void GlRenderPass::getMatrix(float *dst, const Matrix &matrix) const +{ + Matrix postMatrix{}; + tvg::identity(&postMatrix); + + const auto& vp = getViewport(); + translate(&postMatrix, {(float)-vp.sx(), (float)-vp.sy()}); + + auto modelMatrix = postMatrix * matrix; + + Matrix mvp = tvg::identity(); + mvp.e11 = 2.f / vp.w(); + mvp.e22 = -2.f / vp.h(); + mvp.e13 = -1.f; + mvp.e23 = 1.f; + + auto mvpModel = mvp * modelMatrix; + + getMatrix3Std140(mvpModel, dst); +} diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderPass.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderPass.h new file mode 100644 index 0000000..8f7fe6b --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderPass.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_RENDER_PASS_H_ +#define _TVG_GL_RENDER_PASS_H_ + +#include "tvgGlCommon.h" +#include "tvgGlRenderTask.h" +#include "tvgGlRenderTarget.h" + +class GlProgram; + +class GlRenderPass +{ +public: + GlRenderPass(GlRenderTarget* fbo); + GlRenderPass(GlRenderPass&& other); + + ~GlRenderPass(); + + bool isEmpty() const { return mFbo == nullptr; } + + void addRenderTask(GlRenderTask* task); + + GLuint getFboId() { return mFbo->fbo; } + + GLuint getTextureId() { return mFbo->colorTex; } + + const RenderRegion& getViewport() const { return mFbo->viewport; } + + uint32_t getFboWidth() const { return mFbo->width; } + + uint32_t getFboHeight() const { return mFbo->height; } + + void getMatrix(float dst[GL_MAT3_STD140_SIZE], const Matrix& matrix) const; + + template + T* endRenderPass(GlProgram* program, GLuint targetFbo) { + int32_t maxDepth = mDrawDepth + 1; + + for (uint32_t i = 0; i < mTasks.count; i++) { + mTasks[i]->normalizeDrawDepth(maxDepth); + } + + auto task = new T(program, targetFbo, mFbo, std::move(mTasks)); + task->setRenderSize(mFbo->viewport.w(), mFbo->viewport.h()); + + return task; + } + + int nextDrawDepth() { return ++mDrawDepth; } + + void setDrawDepth(int32_t depth) { mDrawDepth = depth; } + + GlRenderTarget* getFbo() { return mFbo; } +private: + GlRenderTarget* mFbo; + Array mTasks = {}; + int32_t mDrawDepth = 0; +}; + + +#endif // _TVG_GL_RENDER_PASS_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTarget.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTarget.cpp new file mode 100644 index 0000000..bc0a18e --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTarget.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlRenderTarget.h" + +GlRenderTarget::GlRenderTarget() {} + +GlRenderTarget::~GlRenderTarget() +{ + reset(); +} + +void GlRenderTarget::init(uint32_t width, uint32_t height, GLint resolveId) +{ + if (width == 0 || height == 0) return; + + this->width = width; + this->height = height; + + //TODO: fbo is used. maybe we can consider the direct rendering with resolveId as well. + GL_CHECK(glGenFramebuffers(1, &fbo)); + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo)); + + GL_CHECK(glGenRenderbuffers(1, &colorBuffer)); + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer)); + GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, width, height)); + + GL_CHECK(glGenRenderbuffers(1, &depthStencilBuffer)); + + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer)); + + GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height)); + + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0)); + + GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer)); + GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilBuffer)); + + // resolve target + GL_CHECK(glGenTextures(1, &colorTex)); + + GL_CHECK(glBindTexture(GL_TEXTURE_2D, colorTex)); + GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr)); + + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + + GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0)); + + GL_CHECK(glGenFramebuffers(1, &resolvedFbo)); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, resolvedFbo)); + GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0)); + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, resolveId)); +} + +void GlRenderTarget::reset() +{ + if (fbo == 0) return; + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); + GL_CHECK(glDeleteFramebuffers(1, &fbo)); + GL_CHECK(glDeleteRenderbuffers(1, &colorBuffer)); + GL_CHECK(glDeleteRenderbuffers(1, &depthStencilBuffer)); + GL_CHECK(glDeleteFramebuffers(1, &resolvedFbo)); + GL_CHECK(glDeleteTextures(1, &colorTex)); + + fbo = colorBuffer = depthStencilBuffer = resolvedFbo = colorTex = 0; +} + +GlRenderTargetPool::GlRenderTargetPool(uint32_t maxWidth, uint32_t maxHeight): maxWidth(maxWidth), maxHeight(maxHeight), pool() {} + +GlRenderTargetPool::~GlRenderTargetPool() +{ + for (uint32_t i = 0; i < pool.count; i++) { + delete pool[i]; + } +} + +uint32_t alignPow2(uint32_t value) +{ + uint32_t ret = 1; + while (ret < value) { + ret <<= 1; + } + return ret; +} + +GlRenderTarget* GlRenderTargetPool::getRenderTarget(const RenderRegion& vp, GLuint resolveId) +{ + auto width = vp.w(); + auto height = vp.h(); + + // pow2 align width and height + if (width >= maxWidth) width = maxWidth; + else width = alignPow2(width); + if (width >= maxWidth) width = maxWidth; + + if (height >= maxHeight) height = maxHeight; + else height = alignPow2(height); + if (height >= maxHeight) height = maxHeight; + + for (uint32_t i = 0; i < pool.count; i++) { + auto rt = pool[i]; + if (rt->width == width && rt->height == height) { + rt->viewport = vp; + return rt; + } + } + + auto rt = new GlRenderTarget(); + rt->init(width, height, resolveId); + rt->viewport = vp; + pool.push(rt); + return rt; +} diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTarget.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTarget.h new file mode 100644 index 0000000..e5b1eaf --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTarget.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_RENDER_RENDER_TARGET_H_ +#define _TVG_GL_RENDER_RENDER_TARGET_H_ + +#include "tvgGlCommon.h" + +struct GlRenderTarget +{ + GlRenderTarget(); + ~GlRenderTarget(); + + void init(uint32_t width, uint32_t height, GLint resolveId); + void reset(); + + bool invalid() const { return fbo == 0; } + + RenderRegion viewport{}; + uint32_t width = 0, height = 0; + GLuint resolvedFbo = 0, fbo = 0, colorTex = 0; + +private: + GLuint colorBuffer = 0; + GLuint depthStencilBuffer = 0; +}; + + +struct GlRenderTargetPool +{ + GlRenderTargetPool(uint32_t maxWidth, uint32_t maxHeight); + ~GlRenderTargetPool(); + GlRenderTarget* getRenderTarget(const RenderRegion& vp, GLuint resolveId = 0); +private: + uint32_t maxWidth = 0; + uint32_t maxHeight = 0; + Array pool; +}; + +#endif //_TVG_GL_RENDER_RENDER_TARGET_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTask.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTask.cpp new file mode 100644 index 0000000..09d7a79 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTask.cpp @@ -0,0 +1,670 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlRenderTask.h" +#include "tvgGlProgram.h" +#include "tvgGlRenderPass.h" + +/************************************************************************/ +/* GlRenderTask Class Implementation */ +/************************************************************************/ + +GlRenderTask::GlRenderTask(GlProgram* program, GlRenderTask* other): mProgram(program) +{ + mVertexLayout.push(other->mVertexLayout); + mViewport = other->mViewport; + mIndexOffset = other->mIndexOffset; + mIndexCount = other->mIndexCount; +} + + +void GlRenderTask::run() +{ + // bind shader + mProgram->load(); + + int32_t dLoc = mProgram->getUniformLocation("uDepth"); + if (dLoc >= 0) { + // fixme: prevent compiler warning: macro expands to multiple statements [-Wmultistatement-macros] + GL_CHECK(glUniform1f(dLoc, mDrawDepth)); + } + + // setup scissor rect + GL_CHECK(glScissor(mViewport.sx(), mViewport.sy(), mViewport.sw(), mViewport.sh())); + + // setup attribute layout + for (uint32_t i = 0; i < mVertexLayout.count; i++) { + const auto &layout = mVertexLayout[i]; + GL_CHECK(glEnableVertexAttribArray(layout.index)); + GL_CHECK(glVertexAttribPointer(layout.index, layout.size, GL_FLOAT, + GL_FALSE, layout.stride, + reinterpret_cast(layout.offset))); + } + + // binding uniforms + for (uint32_t i = 0; i < mBindingResources.count; i++) { + const auto& binding = mBindingResources[i]; + if (binding.type == GlBindingType::kTexture) { + GL_CHECK(glActiveTexture(GL_TEXTURE0 + binding.bindPoint)); + GL_CHECK(glBindTexture(GL_TEXTURE_2D, binding.gBufferId)); + + mProgram->setUniform1Value(binding.location, 1, (int32_t*)&binding.bindPoint); + } else if (binding.type == GlBindingType::kUniformBuffer) { + + GL_CHECK(glUniformBlockBinding(mProgram->getProgramId(), binding.location, binding.bindPoint)); + GL_CHECK(glBindBufferRange(GL_UNIFORM_BUFFER, binding.bindPoint, binding.gBufferId, + binding.bufferOffset, binding.bufferRange)); + } + } + + GL_CHECK(glDrawElements(GL_TRIANGLES, mIndexCount, GL_UNSIGNED_INT, reinterpret_cast(mIndexOffset))); + + // setup attribute layout + for (uint32_t i = 0; i < mVertexLayout.count; i++) { + const auto &layout = mVertexLayout[i]; + GL_CHECK(glDisableVertexAttribArray(layout.index)); + } +} + + +void GlRenderTask::addVertexLayout(const GlVertexLayout &layout) +{ + mVertexLayout.push(layout); +} + + +void GlRenderTask::addBindResource(const GlBindingResource &binding) +{ + mBindingResources.push(binding); +} + + +void GlRenderTask::setDrawRange(uint32_t offset, uint32_t count) +{ + mIndexOffset = offset; + mIndexCount = count; +} + + +void GlRenderTask::setViewport(const RenderRegion &viewport) +{ + mViewport = viewport; + if (mViewport.max.x < mViewport.min.x) mViewport.max.x = mViewport.min.x; + if (mViewport.max.y < mViewport.min.y) mViewport.max.y = mViewport.min.y; +} + + +/************************************************************************/ +/* GlStencilCoverTask Class Implementation */ +/************************************************************************/ + +GlStencilCoverTask::GlStencilCoverTask(GlRenderTask* stencil, GlRenderTask* cover, GlStencilMode mode) + :GlRenderTask(nullptr), mStencilTask(stencil), mCoverTask(cover), mStencilMode(mode) + { + + } + + +GlStencilCoverTask::~GlStencilCoverTask() +{ + delete mStencilTask; + delete mCoverTask; +} + + +void GlStencilCoverTask::run() +{ + GL_CHECK(glEnable(GL_STENCIL_TEST)); + + if (mStencilMode == GlStencilMode::Stroke) { + GL_CHECK(glStencilFunc(GL_NOTEQUAL, 0x1, 0xFF)); + GL_CHECK(glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)); + } else { + GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0x0, 0xFF)); + GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP)); + + GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0x0, 0xFF)); + GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP)); + } + GL_CHECK(glColorMask(0, 0, 0, 0)); + + mStencilTask->run(); + + if (mStencilMode == GlStencilMode::FillEvenOdd) { + GL_CHECK(glStencilFunc(GL_NOTEQUAL, 0x00, 0x01)); + GL_CHECK(glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE)); + } else { + GL_CHECK(glStencilFunc(GL_NOTEQUAL, 0x0, 0xFF)); + GL_CHECK(glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)); + } + + GL_CHECK(glColorMask(1, 1, 1, 1)); + + mCoverTask->run(); + + GL_CHECK(glDisable(GL_STENCIL_TEST)); +} + + +void GlStencilCoverTask::normalizeDrawDepth(int32_t maxDepth) +{ + mCoverTask->normalizeDrawDepth(maxDepth); + mStencilTask->normalizeDrawDepth(maxDepth); +} + + +/************************************************************************/ +/* GlComposeTask Class Implementation */ +/************************************************************************/ + +GlComposeTask::GlComposeTask(GlProgram* program, GLuint target, GlRenderTarget* fbo, Array&& tasks) + :GlRenderTask(program) ,mTargetFbo(target), mFbo(fbo), mTasks() +{ + mTasks.push(tasks); + tasks.clear(); +} + + +GlComposeTask::~GlComposeTask() +{ + ARRAY_FOREACH(p, mTasks) delete(*p); + mTasks.clear(); +} + + +void GlComposeTask::run() +{ + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, getSelfFbo())); + + // we must clear all area of fbo + GL_CHECK(glViewport(0, 0, mFbo->width, mFbo->height)); + GL_CHECK(glScissor(0, 0, mFbo->width, mFbo->height)); + GL_CHECK(glClearColor(0, 0, 0, 0)); + GL_CHECK(glClearStencil(0)); +#ifdef THORVG_GL_TARGET_GLES + GL_CHECK(glClearDepthf(0.0)); +#else + GL_CHECK(glClearDepth(0.0)); +#endif + GL_CHECK(glDepthMask(1)); + + GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); + GL_CHECK(glDepthMask(0)); + + GL_CHECK(glViewport(0, 0, mRenderWidth, mRenderHeight)); + GL_CHECK(glScissor(0, 0, mRenderWidth, mRenderHeight)); + + ARRAY_FOREACH(p, mTasks) { + (*p)->run(); + } + +#if defined(THORVG_GL_TARGET_GLES) + // only OpenGLES has tiled base framebuffer and discard function + GLenum attachments[2] = {GL_STENCIL_ATTACHMENT, GL_DEPTH_ATTACHMENT }; + GL_CHECK(glInvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments)); +#endif + // reset scissor box + GL_CHECK(glScissor(0, 0, mFbo->width, mFbo->height)); + onResolve(); +} + + +GLuint GlComposeTask::getSelfFbo() +{ + return mFbo->fbo; +} + + +GLuint GlComposeTask::getResolveFboId() +{ + return mFbo->resolvedFbo; +} + + +void GlComposeTask::onResolve() +{ + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, getSelfFbo())); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, getResolveFboId())); + GL_CHECK(glBlitFramebuffer(0, 0, mRenderWidth, mRenderHeight, 0, 0, mRenderWidth, mRenderHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST)); +} + + +/************************************************************************/ +/* GlBlitTask Class Implementation */ +/************************************************************************/ + +GlBlitTask::GlBlitTask(GlProgram* program, GLuint target, GlRenderTarget* fbo, Array&& tasks) + : GlComposeTask(program, target, fbo, std::move(tasks)), mColorTex(fbo->colorTex) +{ +} + + +void GlBlitTask::run() +{ + GlComposeTask::run(); + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, getTargetFbo())); + GL_CHECK(glViewport(mTargetViewport.x(), mTargetViewport.y(), mTargetViewport.w(), mTargetViewport.h())); + + if (mClearBuffer) { + GL_CHECK(glClearColor(0, 0, 0, 0)); + GL_CHECK(glClear(GL_COLOR_BUFFER_BIT)); + } + + GL_CHECK(glDisable(GL_DEPTH_TEST)); + // make sure the blending is correct + GL_CHECK(glEnable(GL_BLEND)); + GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + + GlRenderTask::run(); +} + + +/************************************************************************/ +/* GlDrawBlitTask Class Implementation */ +/************************************************************************/ + + +GlDrawBlitTask::GlDrawBlitTask(GlProgram* program, GLuint target, GlRenderTarget* fbo, Array&& tasks) + : GlComposeTask(program, target, fbo, std::move(tasks)) +{ +} + + +GlDrawBlitTask::~GlDrawBlitTask() +{ + if (mPrevTask) delete mPrevTask; +} + + +void GlDrawBlitTask::run() +{ + if (mPrevTask) mPrevTask->run(); + + GlComposeTask::run(); + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, getTargetFbo())); + + GL_CHECK(glViewport(0, 0, mParentWidth, mParentHeight)); + GL_CHECK(glScissor(0, 0, mParentWidth, mParentHeight)); + GlRenderTask::run(); +} + + +/************************************************************************/ +/* GlSceneBlendTask Class Implementation */ +/************************************************************************/ + + +GlSceneBlendTask::GlSceneBlendTask(GlProgram* program, GLuint target, GlRenderTarget* fbo, Array&& tasks) + : GlComposeTask(program, target, fbo, std::move(tasks)) +{ +} + + +GlSceneBlendTask::~GlSceneBlendTask() +{ +} + + +void GlSceneBlendTask::run() +{ + GlComposeTask::run(); + + const auto& vp = getViewport(); + const auto width = mSrcFbo->width; + const auto height = mSrcFbo->height; + if (width <= 0 || height <= 0) return; + + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mSrcFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo->resolvedFbo)); + +#if defined(THORVG_GL_TARGET_GL) + const auto& srcVp = mSrcFbo->viewport; + // Copy current target into dstCopyFbo for blending. + GL_CHECK(glViewport(0, 0, srcVp.w(), srcVp.h())); + GL_CHECK(glScissor(0, 0, srcVp.w(), srcVp.h())); + GL_CHECK(glBlitFramebuffer(vp.min.x, vp.min.y, vp.max.x, vp.max.y, 0, 0, vp.w(), vp.h(), GL_COLOR_BUFFER_BIT, GL_LINEAR)); +#else // TODO: create partial buffer when MSAA is disabled + GL_CHECK(glViewport(0, 0, width, height)); + GL_CHECK(glScissor(vp.min.x, vp.min.y, vp.w(), vp.h())); + GL_CHECK(glBlitFramebuffer(vp.min.x, vp.min.y, vp.max.x, vp.max.y, vp.min.x, vp.min.y, vp.max.x, vp.max.y, GL_COLOR_BUFFER_BIT, GL_NEAREST)); +#endif + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, getTargetFbo())); + GL_CHECK(glViewport(0, 0, mParentWidth, mParentHeight)); + GL_CHECK(glScissor(0, 0, mParentWidth, mParentHeight)); + + GL_CHECK(glDisable(GL_DEPTH_TEST)); + GL_CHECK(glBlendFunc(GL_ONE, GL_ZERO)); + GlRenderTask::run(); + GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + GL_CHECK(glEnable(GL_DEPTH_TEST)); +} + + +/************************************************************************/ +/* GlClipTask Class Implementation */ +/************************************************************************/ + +GlClipTask::GlClipTask(GlRenderTask* clip, GlRenderTask* mask) + :GlRenderTask(nullptr), mClipTask(clip), mMaskTask(mask) {} + + +GlClipTask::~GlClipTask() +{ + delete mClipTask; + delete mMaskTask; +} + + +void GlClipTask::run() +{ + GL_CHECK(glEnable(GL_STENCIL_TEST)); + GL_CHECK(glColorMask(0, 0, 0, 0)); + // draw clip path as normal stencil mask + GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0x1, 0xFF)); + GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP)); + + GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0x1, 0xFF)); + GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP)); + + mClipTask->run(); + + + // draw clip mask + GL_CHECK(glDepthMask(1)); + GL_CHECK(glStencilFunc(GL_EQUAL, 0x0, 0xFF)); + GL_CHECK(glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE)); + + mMaskTask->run(); + + GL_CHECK(glColorMask(1, 1, 1, 1)); + GL_CHECK(glDepthMask(0)); + GL_CHECK(glDisable(GL_STENCIL_TEST)); +} + + +void GlClipTask::normalizeDrawDepth(int32_t maxDepth) +{ + mClipTask->normalizeDrawDepth(maxDepth); + mMaskTask->normalizeDrawDepth(maxDepth); +} + +/************************************************************************/ +/* GlDirectBlendTask Class Implementation */ +/************************************************************************/ + +GlDirectBlendTask::GlDirectBlendTask(GlProgram* program, GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo, const RenderRegion& copyRegion) + : GlRenderTask(program), mDstFbo(dstFbo), mDstCopyFbo(dstCopyFbo), mCopyRegion(copyRegion) +{ +} + + +void GlDirectBlendTask::run() +{ + auto width = mCopyRegion.w(); + auto height = mCopyRegion.h(); + if (width <= 0 || height <= 0) return; + auto x = mCopyRegion.sx(); + auto y = mCopyRegion.sy(); + const auto fboW = mDstFbo->width; + const auto fboH = mDstFbo->height; + if (fboW <= 0 || fboH <= 0) return; + + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo->resolvedFbo)); + +#if defined(THORVG_GL_TARGET_GL) + GL_CHECK(glViewport(0, 0, width, height)); + GL_CHECK(glScissor(0, 0, width, height)); + GL_CHECK(glBlitFramebuffer(x, y, x + width, y + height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR)); +#else // TODO: create partial buffer when MSAA is disabled + GL_CHECK(glViewport(0, 0, fboW, fboH)); + GL_CHECK(glScissor(x, y, width, height)); + GL_CHECK(glBlitFramebuffer(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); +#endif + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstFbo->fbo)); + const auto& dstVp = mDstFbo->viewport; + GL_CHECK(glViewport(0, 0, dstVp.w(), dstVp.h())); + + GL_CHECK(glBlendFunc(GL_ONE, GL_ZERO)); + GlRenderTask::run(); + GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); +} + + +/************************************************************************/ +/* GlComplexBlendTask Class Implementation */ +/************************************************************************/ + + +GlComplexBlendTask::GlComplexBlendTask(GlProgram* program, GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo, GlRenderTask* stencilTask, GlComposeTask* composeTask) + : GlRenderTask(program), mDstFbo(dstFbo), mDstCopyFbo(dstCopyFbo), mStencilTask(stencilTask), mComposeTask(composeTask) + { + } + + +GlComplexBlendTask::~GlComplexBlendTask() +{ + delete mStencilTask; + delete mComposeTask; +} + + +void GlComplexBlendTask::run() +{ + mComposeTask->run(); + + const auto& vp = getViewport(); + const auto width = mDstFbo->width; + const auto height = mDstFbo->height; + if (width <= 0 || height <= 0) return; + + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo->resolvedFbo)); + +#if defined(THORVG_GL_TARGET_GL) + const auto& dstVp = mDstFbo->viewport; + // copy the current fbo to the dstCopyFbo + GL_CHECK(glViewport(0, 0, dstVp.w(), dstVp.h())); + GL_CHECK(glScissor(0, 0, dstVp.w(), dstVp.h())); + GL_CHECK(glBlitFramebuffer(vp.min.x, vp.min.y, vp.max.x, vp.max.y, 0, 0, vp.w(), vp.h(), GL_COLOR_BUFFER_BIT, GL_LINEAR)); +#else // TODO: create partial buffer when MSAA is disabled + GL_CHECK(glViewport(0, 0, width, height)); + GL_CHECK(glScissor(vp.min.x, vp.min.y, vp.w(), vp.h())); + GL_CHECK(glBlitFramebuffer(vp.min.x, vp.min.y, vp.max.x, vp.max.y, vp.min.x, vp.min.y, vp.max.x, vp.max.y, GL_COLOR_BUFFER_BIT, GL_NEAREST)); +#endif + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstFbo->fbo)); + + GL_CHECK(glEnable(GL_STENCIL_TEST)); + GL_CHECK(glColorMask(0, 0, 0, 0)); + GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0x0, 0xFF)); + GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP)); + + GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0x0, 0xFF)); + GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP)); + + + mStencilTask->run(); + + GL_CHECK(glColorMask(1, 1, 1, 1)); + GL_CHECK(glStencilFunc(GL_NOTEQUAL, 0x0, 0xFF)); + GL_CHECK(glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE)); + + GL_CHECK(glBlendFunc(GL_ONE, GL_ZERO)); + + GlRenderTask::run(); + + GL_CHECK(glDisable(GL_STENCIL_TEST)); + GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); +} + + +void GlComplexBlendTask::normalizeDrawDepth(int32_t maxDepth) +{ + mStencilTask->normalizeDrawDepth(maxDepth); + GlRenderTask::normalizeDrawDepth(maxDepth); +} + +/************************************************************************/ +/* GlGaussianBlurTask Class Implementation */ +/************************************************************************/ + +void GlGaussianBlurTask::run() +{ + const auto vp = getViewport(); + const auto width = mDstFbo->width; + const auto height = mDstFbo->height; + + // get targets handles + GLuint dstCopyTexId0 = mDstCopyFbo0->colorTex; + GLuint dstCopyTexId1 = mDstCopyFbo1->colorTex; + // get programs properties + GlProgram* programHorz = horzTask->getProgram(); + GlProgram* programVert = vertTask->getProgram(); + GLint horzSrcTextureLoc = programHorz->getUniformLocation("uSrcTexture"); + GLint vertSrcTextureLoc = programVert->getUniformLocation("uSrcTexture"); + + GL_CHECK(glViewport(0, 0, width, height)); + GL_CHECK(glScissor(0, 0, width, height)); + // we need to make a full copy of dst to intermediate buffers to be sure that they don’t contain prev data. + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo0->resolvedFbo)); + GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstFbo->fbo)); + + GL_CHECK(glDisable(GL_BLEND)); + if (effect->direction == 0) { + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo1->resolvedFbo)); + GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + // horizontal blur + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstCopyFbo1->resolvedFbo)); + horzTask->setViewport(vp); + horzTask->addBindResource({ 0, dstCopyTexId0, horzSrcTextureLoc }); + horzTask->run(); + // vertical blur + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstFbo->fbo)); + vertTask->setViewport(vp); + vertTask->addBindResource({ 0, dstCopyTexId1, vertSrcTextureLoc }); + vertTask->run(); + } // horizontal + else if (effect->direction == 1) { + horzTask->setViewport(vp); + horzTask->addBindResource({ 0, dstCopyTexId0, horzSrcTextureLoc }); + horzTask->run(); + } // vertical + else if (effect->direction == 2) { + vertTask->setViewport(vp); + vertTask->addBindResource({ 0, dstCopyTexId0, vertSrcTextureLoc }); + vertTask->run(); + } + GL_CHECK(glEnable(GL_BLEND)); +} + +/************************************************************************/ +/* GlEffectDropShadowTask Class Implementation */ +/************************************************************************/ + +void GlEffectDropShadowTask::run() +{ + const auto vp = getViewport(); + const auto width = mDstFbo->width; + const auto height = mDstFbo->height; + + // get targets handles + GLuint dstCopyTexId0 = mDstCopyFbo0->colorTex; + GLuint dstCopyTexId1 = mDstCopyFbo1->colorTex; + // get programs properties + GlProgram* programHorz = horzTask->getProgram(); + GlProgram* programVert = vertTask->getProgram(); + GLint horzSrcTextureLoc = programHorz->getUniformLocation("uSrcTexture"); + GLint vertSrcTextureLoc = programVert->getUniformLocation("uSrcTexture"); + + GLint srcTextureLoc = getProgram()->getUniformLocation("uSrcTexture"); + GLint blrTextureLoc = getProgram()->getUniformLocation("uBlrTexture"); + addBindResource({ 0, dstCopyTexId0, srcTextureLoc }); + addBindResource({ 1, dstCopyTexId1, blrTextureLoc }); + + GL_CHECK(glViewport(0, 0, width, height)); + GL_CHECK(glScissor(0, 0, width, height)); + + // we need to make a full copy of dst to intermediate buffers to be sure that they don’t contain prev data. + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo0->resolvedFbo)); + GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo1->resolvedFbo)); + GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + + GL_CHECK(glDisable(GL_BLEND)); + // when sigma is 0, no blur is applied, and the original image is used directly as the shadow. + if (!tvg::zero(effect->sigma)) { + // horizontal blur + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstCopyFbo0->resolvedFbo)); + horzTask->setViewport(vp); + horzTask->addBindResource({ 0, dstCopyTexId1, horzSrcTextureLoc }); + horzTask->run(); + // vertical blur + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstCopyFbo1->resolvedFbo)); + vertTask->setViewport(vp); + vertTask->addBindResource({ 0, dstCopyTexId0, vertSrcTextureLoc }); + vertTask->run(); + // copy original image to intermediate buffer + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo0->resolvedFbo)); + GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + } + // run drop shadow effect + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstFbo->fbo)); + GlRenderTask::run(); + GL_CHECK(glEnable(GL_BLEND)); +} + +/************************************************************************/ +/* GlEffectColorTransformTask Class Implementation */ +/************************************************************************/ + +void GlEffectColorTransformTask::run() +{ + const auto width = mDstFbo->width; + const auto height = mDstFbo->height; + // get targets handles and pass to shader + GLuint dstCopyTexId = mDstCopyFbo->colorTex; + GLint srcTextureLoc = getProgram()->getUniformLocation("uSrcTexture"); + addBindResource({ 0, dstCopyTexId, srcTextureLoc }); + + GL_CHECK(glViewport(0, 0, width, height)); + GL_CHECK(glScissor(0, 0, width, height)); + // we need to make a full copy of dst to intermediate buffers to be sure that they don’t contain prev data. + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, mDstFbo->fbo)); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDstCopyFbo->resolvedFbo)); + GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, mDstFbo->fbo)); + + // run transform + GL_CHECK(glDisable(GL_BLEND)); + GlRenderTask::run(); + GL_CHECK(glEnable(GL_BLEND)); +} diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTask.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTask.h new file mode 100644 index 0000000..4dd2817 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderTask.h @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_RENDER_TASK_H_ +#define _TVG_GL_RENDER_TASK_H_ + +#include "tvgGlCommon.h" +#include "tvgGlProgram.h" + + +struct GlVertexLayout +{ + uint32_t index; + uint32_t size; + uint32_t stride; + size_t offset; +}; + +enum class GlBindingType +{ + kUniformBuffer, + kTexture, +}; + + +struct GlBindingResource +{ + GlBindingType type; + /** + * Binding point index. + * Can be a uniform location for a texture + * Can be a uniform buffer binding index for a uniform block + */ + uint32_t bindPoint = 0; + GLint location = 0; + GLuint gBufferId = 0; + uint32_t bufferOffset = 0; + uint32_t bufferRange = 0; + + GlBindingResource() = default; + + GlBindingResource(uint32_t index, GLint location, GLuint bufferId, uint32_t offset, uint32_t range) + : type(GlBindingType::kUniformBuffer), bindPoint(index), location(location), gBufferId(bufferId), bufferOffset(offset), bufferRange(range) + { + } + + GlBindingResource(uint32_t bindPoint, GLuint texId, GLint location) + : type(GlBindingType::kTexture), bindPoint(bindPoint), location(location), gBufferId(texId) + { + } +}; + +class GlRenderTask +{ +public: + GlRenderTask(GlProgram* program): mProgram(program) {} + GlRenderTask(GlProgram* program, GlRenderTask* other); + + virtual ~GlRenderTask() = default; + + virtual void run(); + + void addVertexLayout(const GlVertexLayout& layout); + void addBindResource(const GlBindingResource& binding); + void setDrawRange(uint32_t offset, uint32_t count); + void setViewport(const RenderRegion& viewport); + void setDrawDepth(int32_t depth) { mDrawDepth = static_cast(depth); } + virtual void normalizeDrawDepth(int32_t maxDepth) { mDrawDepth /= static_cast(maxDepth); } + + GlProgram* getProgram() { return mProgram; } + const RenderRegion& getViewport() const { return mViewport; } + float getDrawDepth() const { return mDrawDepth; } +private: + GlProgram* mProgram; + RenderRegion mViewport = {}; + uint32_t mIndexOffset = {}; + uint32_t mIndexCount = {}; + Array mVertexLayout = {}; + Array mBindingResources = {}; + float mDrawDepth = 0.f; +}; + +class GlStencilCoverTask : public GlRenderTask +{ +public: + GlStencilCoverTask(GlRenderTask* stencil, GlRenderTask* cover, GlStencilMode mode); + ~GlStencilCoverTask() override; + + void run() override; + + void normalizeDrawDepth(int32_t maxDepth) override; +private: + GlRenderTask* mStencilTask; + GlRenderTask* mCoverTask; + GlStencilMode mStencilMode; +}; + +class GlRenderTarget; + +class GlComposeTask : public GlRenderTask +{ +public: + GlComposeTask(GlProgram* program, GLuint target, GlRenderTarget* fbo, Array&& tasks); + ~GlComposeTask() override; + + void run() override; + + void setRenderSize(uint32_t width, uint32_t height) { mRenderWidth = width; mRenderHeight = height; } + + bool mClearBuffer = true; + +protected: + GLuint getTargetFbo() { return mTargetFbo; } + GLuint getSelfFbo(); + GLuint getResolveFboId(); + void onResolve(); + +private: + GLuint mTargetFbo; + GlRenderTarget* mFbo; + Array mTasks; + uint32_t mRenderWidth = 0; + uint32_t mRenderHeight = 0; +}; + +class GlBlitTask : public GlComposeTask +{ +public: + GlBlitTask(GlProgram*, GLuint target, GlRenderTarget* fbo, Array&& tasks); + ~GlBlitTask() override = default; + + void run() override; + + GLuint getColorTexture() const { return mColorTex; } + + void setTargetViewport(const RenderRegion& vp) { mTargetViewport = vp; } +private: + GLuint mColorTex = 0; + RenderRegion mTargetViewport = {}; +}; + +class GlDrawBlitTask : public GlComposeTask +{ +public: + GlDrawBlitTask(GlProgram*, GLuint target, GlRenderTarget* fbo, Array&& tasks); + ~GlDrawBlitTask() override; + + void setPrevTask(GlRenderTask* task) { mPrevTask = task; } + + void setParentSize(uint32_t width, uint32_t height) { mParentWidth = width; mParentHeight = height; } + + void run() override; + +private: + GlRenderTask* mPrevTask = nullptr; + uint32_t mParentWidth = 0; + uint32_t mParentHeight = 0; +}; + +class GlSceneBlendTask : public GlComposeTask +{ +public: + GlSceneBlendTask(GlProgram*, GLuint target, GlRenderTarget* fbo, Array&& tasks); + ~GlSceneBlendTask() override; + + void setParentSize(uint32_t width, uint32_t height) { mParentWidth = width; mParentHeight = height; } + void setSrcTarget(GlRenderTarget* srcFbo) { mSrcFbo = srcFbo; } + void setDstCopy(GlRenderTarget* dstCopyFbo) { mDstCopyFbo = dstCopyFbo; } + + void run() override; + +private: + GlRenderTarget* mSrcFbo = nullptr; + GlRenderTarget* mDstCopyFbo = nullptr; + uint32_t mParentWidth = 0; + uint32_t mParentHeight = 0; +}; + +class GlClipTask : public GlRenderTask +{ +public: + GlClipTask(GlRenderTask* clip, GlRenderTask* mask); + ~GlClipTask() override; + + void run() override; + + void normalizeDrawDepth(int32_t maxDepth) override; +private: + GlRenderTask* mClipTask; + GlRenderTask* mMaskTask; +}; + +class GlDirectBlendTask : public GlRenderTask +{ +public: + GlDirectBlendTask(GlProgram* program, GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo, const RenderRegion& copyRegion); + ~GlDirectBlendTask() override = default; + + void run() override; +private: + GlRenderTarget* mDstFbo = nullptr; + GlRenderTarget* mDstCopyFbo = nullptr; + RenderRegion mCopyRegion{}; +}; + +class GlComplexBlendTask: public GlRenderTask +{ +public: + GlComplexBlendTask(GlProgram* program, GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo, GlRenderTask* stencilTask, GlComposeTask* composeTask); + ~GlComplexBlendTask() override; + + void run() override; + + void normalizeDrawDepth(int32_t maxDepth) override; +private: + GlRenderTarget* mDstFbo; + GlRenderTarget* mDstCopyFbo; + GlRenderTask* mStencilTask; + GlComposeTask* mComposeTask; +}; + +class GlGaussianBlurTask: public GlRenderTask +{ +public: + GlGaussianBlurTask(GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo0, GlRenderTarget* dstCopyFbo1): + GlRenderTask(nullptr), mDstFbo(dstFbo), mDstCopyFbo0(dstCopyFbo0), mDstCopyFbo1(dstCopyFbo1) {}; + ~GlGaussianBlurTask(){ delete horzTask; delete vertTask; }; + + void run() override; + + GlRenderTask* horzTask; + GlRenderTask* vertTask; + RenderEffectGaussianBlur* effect; +private: + GlRenderTarget* mDstFbo; + GlRenderTarget* mDstCopyFbo0; + GlRenderTarget* mDstCopyFbo1; +}; + +class GlEffectDropShadowTask: public GlRenderTask +{ +public: + GlEffectDropShadowTask(GlProgram* program, GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo0, GlRenderTarget* dstCopyFbo1): + GlRenderTask(program), mDstFbo(dstFbo), mDstCopyFbo0(dstCopyFbo0), mDstCopyFbo1(dstCopyFbo1) {}; + ~GlEffectDropShadowTask(){ delete horzTask; delete vertTask; }; + + void run() override; + + GlRenderTask* horzTask; + GlRenderTask* vertTask; + RenderEffectDropShadow* effect; +private: + GlRenderTarget* mDstFbo; + GlRenderTarget* mDstCopyFbo0; + GlRenderTarget* mDstCopyFbo1; +}; + +class GlEffectColorTransformTask: public GlRenderTask +{ +public: + GlEffectColorTransformTask(GlProgram* program, GlRenderTarget* dstFbo, GlRenderTarget* dstCopyFbo): + GlRenderTask(program), mDstFbo(dstFbo), mDstCopyFbo(dstCopyFbo) {}; + ~GlEffectColorTransformTask() {}; + + void run() override; +private: + GlRenderTarget* mDstFbo; + GlRenderTarget* mDstCopyFbo; +}; + +#endif /* _TVG_GL_RENDER_TASK_H_ */ diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderer.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderer.cpp new file mode 100644 index 0000000..7536d86 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderer.cpp @@ -0,0 +1,1506 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgFill.h" +#include "tvgGlCommon.h" +#include "tvgGlRenderer.h" +#include "tvgGlGpuBuffer.h" +#include "tvgGlRenderTask.h" +#include "tvgGlProgram.h" +#include "tvgGlShaderSrc.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define NOISE_LEVEL 0.5f + +static atomic rendererCnt{-1}; + +void GlRenderer::clearDisposes() +{ + if (mDisposed.textures.count > 0) { + glDeleteTextures(mDisposed.textures.count, mDisposed.textures.data); + mDisposed.textures.clear(); + } + + ARRAY_FOREACH(p, mRenderPassStack) delete(*p); + mRenderPassStack.clear(); +} + + +void GlRenderer::flush() +{ + clearDisposes(); + + mRootTarget.reset(); + + ARRAY_FOREACH(p, mComposePool) delete(*p); + mComposePool.clear(); + + ARRAY_FOREACH(p, mBlendPool) delete(*p); + mBlendPool.clear(); + + ARRAY_FOREACH(p, mComposeStack) delete(*p); + mComposeStack.clear(); +} + + +bool GlRenderer::currentContext() +{ +#if defined(__EMSCRIPTEN__) + const auto targetContext = reinterpret_cast(mContext); + if (emscripten_webgl_get_current_context() == targetContext) return true; + return emscripten_webgl_make_context_current(targetContext) == 0; +#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(THORVG_GL_TARGET_GL) + if (tvgWglGetCurrentContext() == static_cast(mContext)) return true; + return (bool) tvgWglMakeCurrent((HDC)mSurface, static_cast(mContext)); +#elif defined(THORVG_GL_TARGET_GLES) + if (tvgEglGetCurrentContext() == static_cast(mContext)) return true; + if (mDisplay && mSurface) return (bool) tvgEglMakeCurrent((EGLDisplay)mDisplay, (EGLSurface)mSurface, (EGLSurface)mSurface, (EGLContext)mContext); +#endif + TVGLOG("GL_ENGINE", "Maybe missing currentContext()?"); + return true; +} + + +GlRenderer::GlRenderer() : mEffect(GlEffect(&mGpuBuffer)) +{ + ++rendererCnt; +} + + +GlRenderer::~GlRenderer() +{ + --rendererCnt; + + flush(); + + ARRAY_FOREACH(p, mPrograms) delete(*p); +} + + +void GlRenderer::initShaders() +{ + mPrograms.reserve((int)RT_None); + +#if 1 //for optimization + #define LINEAR_TOTAL_LENGTH 2831 + #define RADIAL_TOTAL_LENGTH 5315 + #define BLEND_TOTAL_LENGTH 5500 +#else + #define COMMON_TOTAL_LENGTH strlen(STR_GRADIENT_FRAG_COMMON_VARIABLES) + strlen(STR_GRADIENT_FRAG_COMMON_FUNCTIONS) + 1 + #define LINEAR_TOTAL_LENGTH strlen(STR_LINEAR_GRADIENT_VARIABLES) + strlen(STR_LINEAR_GRADIENT_FUNCTIONS) + strlen(STR_LINEAR_GRADIENT_MAIN) + COMMON_TOTAL_LENGTH + #define RADIAL_TOTAL_LENGTH strlen(STR_RADIAL_GRADIENT_VARIABLES) + strlen(STR_RADIAL_GRADIENT_FUNCTIONS) + strlen(STR_RADIAL_GRADIENT_MAIN) + COMMON_TOTAL_LENGTH + #define BLEND_TOTAL_LENGTH strlen(BLEND_SCENE_FRAG_HEADER) + strlen(BLEND_FRAG_HSL) + strlen(COLOR_BURN_BLEND_FRAG) + 1 +#endif + + char linearGradientFragShader[LINEAR_TOTAL_LENGTH]; + snprintf(linearGradientFragShader, LINEAR_TOTAL_LENGTH, "%s%s%s%s%s", + STR_GRADIENT_FRAG_COMMON_VARIABLES, + STR_LINEAR_GRADIENT_VARIABLES, + STR_GRADIENT_FRAG_COMMON_FUNCTIONS, + STR_LINEAR_GRADIENT_FUNCTIONS, + STR_LINEAR_GRADIENT_MAIN + ); + + char radialGradientFragShader[RADIAL_TOTAL_LENGTH]; + snprintf(radialGradientFragShader, RADIAL_TOTAL_LENGTH, "%s%s%s%s%s", + STR_GRADIENT_FRAG_COMMON_VARIABLES, + STR_RADIAL_GRADIENT_VARIABLES, + STR_GRADIENT_FRAG_COMMON_FUNCTIONS, + STR_RADIAL_GRADIENT_FUNCTIONS, + STR_RADIAL_GRADIENT_MAIN + ); + + mPrograms.push(new GlProgram(COLOR_VERT_SHADER, COLOR_FRAG_SHADER)); + mPrograms.push(new GlProgram(GRADIENT_VERT_SHADER, linearGradientFragShader)); + mPrograms.push(new GlProgram(GRADIENT_VERT_SHADER, radialGradientFragShader)); + mPrograms.push(new GlProgram(IMAGE_VERT_SHADER, IMAGE_FRAG_SHADER)); + + // compose Renderer + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_ALPHA_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_INV_ALPHA_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_LUMA_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_INV_LUMA_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_ADD_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_SUB_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_INTERSECT_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_DIFF_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_LIGHTEN_FRAG_SHADER)); + mPrograms.push(new GlProgram(MASK_VERT_SHADER, MASK_DARKEN_FRAG_SHADER)); + + // stencil Renderer + mPrograms.push(new GlProgram(STENCIL_VERT_SHADER, STENCIL_FRAG_SHADER)); + + // blit Renderer + mPrograms.push(new GlProgram(BLIT_VERT_SHADER, BLIT_FRAG_SHADER)); + + // blend programs: image (17) + scene (17) + shape solid (17) + shape linear (17) + shape radial (17) + for (uint32_t i = 0; i < 85; ++i) mPrograms.push(nullptr); +} + + +void GlRenderer::drawPrimitive(GlShape& sdata, const RenderColor& c, RenderUpdateFlag flag, int32_t depth) +{ + auto blendShape = (mBlendMethod != BlendMethod::Normal); + auto vp = currentPass()->getViewport(); + auto bbox = blendShape? sdata.geometry.getBounds() : sdata.geometry.viewport; + + bbox.intersect(vp); + if (bbox.invalid()) return; + + auto x = bbox.sx() - vp.sx(); + auto y = bbox.sy() - vp.sy(); + auto w = bbox.sw(); + auto h = bbox.sh(); + auto yGl = vp.sh() - y - h; + RenderRegion viewRegion = {{x, yGl}, {x + w, yGl + h}}; + + GlRenderTask* task = nullptr; + GlRenderTarget* dstCopyFbo = nullptr; + + if (blendShape) { + if (mBlendPool.empty()) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); +#if defined(THORVG_GL_TARGET_GL) + dstCopyFbo = mBlendPool[0]->getRenderTarget(viewRegion); +#else // TODO: create partial buffer when MSAA is disabled + dstCopyFbo = mBlendPool[0]->getRenderTarget(currentPass()->getViewport()); +#endif + auto program = getBlendProgram(mBlendMethod, BlendSource::Solid); + task = new GlDirectBlendTask(program, currentPass()->getFbo(), dstCopyFbo, viewRegion); + } else { + task = new GlRenderTask(mPrograms[RT_Color]); + } + + task->setDrawDepth(depth); + + if (!sdata.geometry.draw(task, &mGpuBuffer, flag)) { + delete task; + return; + } + + task->setViewport(viewRegion); + + GlRenderTask* stencilTask = nullptr; + + GlStencilMode stencilMode = sdata.geometry.getStencilMode(flag); + if (stencilMode != GlStencilMode::None) { + stencilTask = new GlRenderTask(mPrograms[RT_Stencil], task); + stencilTask->setDrawDepth(depth); + } + + auto a = MULTIPLY(c.a, sdata.opacity); + + if (flag & RenderUpdateFlag::Stroke) { + float strokeWidth = sdata.rshape->strokeWidth() * scaling(sdata.geometry.matrix); + if (strokeWidth < MIN_GL_STROKE_WIDTH) { + float alpha = strokeWidth / MIN_GL_STROKE_WIDTH; + a = MULTIPLY(a, static_cast(alpha * 255)); + } + } + + // matrix buffer + float matrix3STD140[GL_MAT3_STD140_SIZE]; + currentPass()->getMatrix(matrix3STD140, sdata.geometry.matrix); + auto viewOffset = mGpuBuffer.push(matrix3STD140, GL_MAT3_STD140_BYTES, true); + + task->addBindResource(GlBindingResource{ + 0, + task->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + viewOffset, + GL_MAT3_STD140_BYTES, + }); + + if (stencilTask) { + stencilTask->addBindResource(GlBindingResource{ + 0, + stencilTask->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + viewOffset, + GL_MAT3_STD140_BYTES, + }); + } + + // color + float color[] = {c.r / 255.f, c.g / 255.f, c.b / 255.f, a / 255.f}; + + task->addBindResource(GlBindingResource{ + 1, + task->getProgram()->getUniformBlockIndex("ColorInfo"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(color, 4 * sizeof(float), true), + 4 * sizeof(float), + }); + + if (blendShape && dstCopyFbo) { +#if defined(THORVG_GL_TARGET_GL) + float region[] = {float(viewRegion.sx()), float(viewRegion.sy()), float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#else // TODO: create partial buffer when MSAA is disabled + float region[] = {0.0f, 0.0f, float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#endif + task->addBindResource(GlBindingResource{ + 2, + task->getProgram()->getUniformBlockIndex("BlendRegion"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(region, 4 * sizeof(float), true), + 4 * sizeof(float), + }); + + task->addBindResource(GlBindingResource{0, dstCopyFbo->colorTex, task->getProgram()->getUniformLocation("uDstTexture")}); + } + + if (stencilTask) currentPass()->addRenderTask(new GlStencilCoverTask(stencilTask, task, stencilMode)); + else currentPass()->addRenderTask(task); +} + + +void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFlag flag, int32_t depth) +{ + auto blendShape = (mBlendMethod != BlendMethod::Normal); + auto vp = currentPass()->getViewport(); + auto bbox = blendShape ? sdata.geometry.getBounds() : sdata.geometry.viewport; + bbox.intersect(vp); + if (bbox.invalid()) return; + + const Fill::ColorStop* stops = nullptr; + auto stopCnt = min(fill->colorStops(&stops), static_cast(MAX_GRADIENT_STOPS)); + if (stopCnt < 2) return; + + GlRenderTask* task = nullptr; + GlRenderTarget* dstCopyFbo = nullptr; + auto radial = fill->type() == Type::RadialGradient; + + auto x = bbox.sx() - vp.sx(); + auto y = bbox.sy() - vp.sy(); + auto w = bbox.sw(); + auto h = bbox.sh(); + auto yGl = vp.sh() - y - h; + RenderRegion viewRegion = {{x, yGl}, {x + w, yGl + h}}; + + if (blendShape) { + if (mBlendPool.empty()) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); +#if defined(THORVG_GL_TARGET_GL) + dstCopyFbo = mBlendPool[0]->getRenderTarget(viewRegion); +#else // TODO: create partial buffer when MSAA is disabled + dstCopyFbo = mBlendPool[0]->getRenderTarget(currentPass()->getViewport()); +#endif + auto program = getBlendProgram(mBlendMethod, radial ? BlendSource::RadialGradient : BlendSource::LinearGradient); + task = new GlDirectBlendTask(program, currentPass()->getFbo(), dstCopyFbo, viewRegion); + } else if (fill->type() == Type::LinearGradient) task = new GlRenderTask(mPrograms[RT_LinGradient]); + else if (fill->type() == Type::RadialGradient) task = new GlRenderTask(mPrograms[RT_RadGradient]); + else return; + + task->setDrawDepth(depth); + + if (!sdata.geometry.draw(task, &mGpuBuffer, flag)) { + delete task; + return; + } + + task->setViewport(viewRegion); + + GlRenderTask* stencilTask = nullptr; + GlStencilMode stencilMode = sdata.geometry.getStencilMode(flag); + if (stencilMode != GlStencilMode::None) { + stencilTask = new GlRenderTask(mPrograms[RT_Stencil], task); + stencilTask->setDrawDepth(depth); + } + + // matrix buffer + float invMat3[GL_MAT3_STD140_SIZE]; + Matrix inv; + inverse(&fill->transform(), &inv); + getMatrix3Std140(inv, invMat3); + + float matrix3STD140[GL_MAT3_STD140_SIZE]; + currentPass()->getMatrix(matrix3STD140, sdata.geometry.matrix); + + auto viewOffset = mGpuBuffer.push(matrix3STD140, GL_MAT3_STD140_BYTES, true); + + task->addBindResource(GlBindingResource{ + 0, + task->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + viewOffset, + GL_MAT3_STD140_BYTES, + }); + + if (stencilTask) { + stencilTask->addBindResource(GlBindingResource{ + 0, + stencilTask->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + viewOffset, + GL_MAT3_STD140_BYTES, + }); + } + + viewOffset = mGpuBuffer.push(invMat3, GL_MAT3_STD140_BYTES, true); + + task->addBindResource(GlBindingResource{ + 1, + task->getProgram()->getUniformBlockIndex("InvMatrix"), + mGpuBuffer.getBufferId(), + viewOffset, + GL_MAT3_STD140_BYTES, + }); + + auto alpha = sdata.opacity / 255.f; + + if (flag & RenderUpdateFlag::GradientStroke) { + auto strokeWidth = sdata.rshape->strokeWidth(); + if (strokeWidth < MIN_GL_STROKE_WIDTH) { + alpha = strokeWidth / MIN_GL_STROKE_WIDTH; + } + } + + // gradient block + GlBindingResource gradientBinding{}; + auto loc = task->getProgram()->getUniformBlockIndex("GradientInfo"); + + if (fill->type() == Type::LinearGradient) { + auto linearFill = static_cast(fill); + + GlLinearGradientBlock gradientBlock; + + gradientBlock.nStops[1] = NOISE_LEVEL; + gradientBlock.nStops[2] = static_cast(fill->spread()) * 1.f; + uint32_t nStops = 0; + for (uint32_t i = 0; i < stopCnt; ++i) { + if (i > 0 && gradientBlock.stopPoints[nStops - 1] > stops[i].offset) continue; + + gradientBlock.stopPoints[i] = stops[i].offset; + gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f; + gradientBlock.stopColors[i * 4 + 1] = stops[i].g / 255.f; + gradientBlock.stopColors[i * 4 + 2] = stops[i].b / 255.f; + gradientBlock.stopColors[i * 4 + 3] = stops[i].a / 255.f * alpha; + nStops++; + } + gradientBlock.nStops[0] = nStops * 1.f; + + float x1, x2, y1, y2; + linearFill->linear(&x1, &y1, &x2, &y2); + + gradientBlock.startPos[0] = x1; + gradientBlock.startPos[1] = y1; + gradientBlock.stopPos[0] = x2; + gradientBlock.stopPos[1] = y2; + + gradientBinding = GlBindingResource{ + 2, + loc, + mGpuBuffer.getBufferId(), + mGpuBuffer.push(&gradientBlock, sizeof(GlLinearGradientBlock), true), + sizeof(GlLinearGradientBlock), + }; + } else { + auto radialFill = static_cast(fill); + + GlRadialGradientBlock gradientBlock; + + gradientBlock.nStops[1] = NOISE_LEVEL; + gradientBlock.nStops[2] = static_cast(fill->spread()) * 1.f; + + uint32_t nStops = 0; + for (uint32_t i = 0; i < stopCnt; ++i) { + if (i > 0 && gradientBlock.stopPoints[nStops - 1] > stops[i].offset) continue; + + gradientBlock.stopPoints[i] = stops[i].offset; + gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f; + gradientBlock.stopColors[i * 4 + 1] = stops[i].g / 255.f; + gradientBlock.stopColors[i * 4 + 2] = stops[i].b / 255.f; + gradientBlock.stopColors[i * 4 + 3] = stops[i].a / 255.f * alpha; + nStops++; + } + gradientBlock.nStops[0] = nStops * 1.f; + + float x, y, r, fx, fy, fr; + radialFill->radial(&x, &y, &r, &fx, &fy, &fr); + CONST_RADIAL(radialFill)->correct(fx, fy, fr); + + gradientBlock.centerPos[0] = fx; + gradientBlock.centerPos[1] = fy; + gradientBlock.centerPos[2] = x; + gradientBlock.centerPos[3] = y; + gradientBlock.radius[0] = fr; + gradientBlock.radius[1] = r; + + gradientBinding = GlBindingResource{ + 2, + loc, + mGpuBuffer.getBufferId(), + mGpuBuffer.push(&gradientBlock, sizeof(GlRadialGradientBlock), true), + sizeof(GlRadialGradientBlock), + }; + } + + task->addBindResource(gradientBinding); + + if (blendShape && dstCopyFbo) { +#if defined(THORVG_GL_TARGET_GL) + float region[] = {float(viewRegion.sx()), float(viewRegion.sy()), float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#else // TODO: create partial buffer when MSAA is disabled + float region[] = {0.0f, 0.0f, float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#endif + task->addBindResource(GlBindingResource{ + 3, + task->getProgram()->getUniformBlockIndex("BlendRegion"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(region, 4 * sizeof(float), true), + 4 * sizeof(float), + }); + task->addBindResource(GlBindingResource{0, dstCopyFbo->colorTex, task->getProgram()->getUniformLocation("uDstTexture")}); + } + + if (stencilTask) { + currentPass()->addRenderTask(new GlStencilCoverTask(stencilTask, task, stencilMode)); + } else { + currentPass()->addRenderTask(task); + } +} + + +void GlRenderer::drawClip(Array& clips) +{ + Array identityVertex(4 * 2); + float left = -1.f; + float top = 1.f; + float right = 1.f; + float bottom = -1.f; + + identityVertex.push(left); + identityVertex.push(top); + identityVertex.push(left); + identityVertex.push(bottom); + identityVertex.push(right); + identityVertex.push(top); + identityVertex.push(right); + identityVertex.push(bottom); + + Array identityIndex(6); + identityIndex.push(0); + identityIndex.push(1); + identityIndex.push(2); + identityIndex.push(2); + identityIndex.push(1); + identityIndex.push(3); + + float mat3Identity[GL_MAT3_STD140_SIZE]; + auto identityMatrix = tvg::identity(); + getMatrix3Std140(identityMatrix, mat3Identity); + + auto identityVertexOffset = mGpuBuffer.push(identityVertex.data, 8 * sizeof(float)); + auto identityIndexOffset = mGpuBuffer.pushIndex(identityIndex.data, 6 * sizeof(uint32_t)); + auto mat3Offset = mGpuBuffer.push(mat3Identity, GL_MAT3_STD140_BYTES, true); + + Array clipDepths(clips.count); + clipDepths.count = clips.count; + + for (int32_t i = clips.count - 1; i >= 0; i--) { + clipDepths[i] = currentPass()->nextDrawDepth(); + } + + const auto& vp = currentPass()->getViewport(); + + for (uint32_t i = 0; i < clips.count; ++i) { + auto sdata = static_cast(clips[i]); + auto clipTask = new GlRenderTask(mPrograms[RT_Stencil]); + clipTask->setDrawDepth(clipDepths[i]); + + auto flag = (sdata->geometry.stroke.vertex.count > 0) ? RenderUpdateFlag::Stroke : RenderUpdateFlag::Path; + sdata->geometry.draw(clipTask, &mGpuBuffer, flag); + + auto bbox = sdata->geometry.viewport; + bbox.intersect(vp); + + auto x = bbox.sx() - vp.sx(); + auto y = vp.sh() - (bbox.sy() - vp.sy()) - bbox.sh(); + clipTask->setViewport({{x, y}, {x + bbox.sw(), y + bbox.sh()}}); + + float matrix3STD140[GL_MAT3_STD140_SIZE]; + currentPass()->getMatrix(matrix3STD140, sdata->geometry.matrix); + + auto loc = clipTask->getProgram()->getUniformBlockIndex("Matrix"); + auto viewOffset = mGpuBuffer.push(matrix3STD140, GL_MAT3_STD140_BYTES, true); + + clipTask->addBindResource(GlBindingResource{0, loc, mGpuBuffer.getBufferId(), viewOffset, GL_MAT3_STD140_BYTES, }); + + auto maskTask = new GlRenderTask(mPrograms[RT_Stencil]); + + maskTask->setDrawDepth(clipDepths[i]); + maskTask->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), identityVertexOffset}); + maskTask->addBindResource(GlBindingResource{0, loc, mGpuBuffer.getBufferId(), mat3Offset, GL_MAT3_STD140_BYTES, }); + maskTask->setDrawRange(identityIndexOffset, 6); + maskTask->setViewport({{0, 0}, {vp.sw(), vp.sh()}}); + + currentPass()->addRenderTask(new GlClipTask(clipTask, maskTask)); + } +} + +GlRenderPass* GlRenderer::currentPass() +{ + if (mRenderPassStack.empty()) return nullptr; + return mRenderPassStack.last(); +} + +bool GlRenderer::beginComplexBlending(const RenderRegion& vp, RenderRegion bounds) +{ + if (vp.invalid()) return false; + + bounds.intersect(vp); + if (bounds.invalid()) return false; + + if (mBlendMethod == BlendMethod::Normal) return false; + + if (mBlendPool.empty()) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); + + auto blendFbo = mBlendPool[0]->getRenderTarget(bounds); + + mRenderPassStack.push(new GlRenderPass(blendFbo)); + + return true; +} + +void GlRenderer::endBlendingCompose(GlRenderTask* stencilTask, const Matrix& matrix) +{ + auto blendPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + + blendPass->setDrawDepth(currentPass()->nextDrawDepth()); + + auto composeTask = blendPass->endRenderPass(nullptr, currentPass()->getFboId()); + + const auto& vp = blendPass->getViewport(); + if (mBlendPool.count < 2) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); +#if defined(THORVG_GL_TARGET_GL) + auto dstCopyFbo = mBlendPool[1]->getRenderTarget(vp); +#else // TODO: create partial buffer when MSAA is disabled + auto dstCopyFbo = mBlendPool[1]->getRenderTarget(currentPass()->getViewport()); +#endif + + auto x = vp.sx(); + auto y = currentPass()->getViewport().sh() - vp.sy() - vp.sh(); + stencilTask->setViewport({{x, y}, {x + vp.sw(), y + vp.sh()}}); + + stencilTask->setDrawDepth(currentPass()->nextDrawDepth()); + + // set view matrix + float matrix3STD140[GL_MAT3_STD140_SIZE]; + currentPass()->getMatrix(matrix3STD140, matrix); + uint32_t viewOffset = mGpuBuffer.push(matrix3STD140, GL_MAT3_STD140_BYTES, true); + stencilTask->addBindResource(GlBindingResource{ + 0, + stencilTask->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + viewOffset, + GL_MAT3_STD140_BYTES, + }); + + auto program = getBlendProgram(mBlendMethod, BlendSource::Image); + auto task = new GlComplexBlendTask(program, currentPass()->getFbo(), dstCopyFbo, stencilTask, composeTask); + prepareCmpTask(task, vp, blendPass->getFboWidth(), blendPass->getFboHeight()); + task->setDrawDepth(currentPass()->nextDrawDepth()); + +#if defined(THORVG_GL_TARGET_GL) + const auto& taskVp = task->getViewport(); + float region[] = {float(taskVp.sx()), float(taskVp.sy()), float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#else // TODO: create partial buffer when MSAA is disabled + float region[] = {0.0f, 0.0f, float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#endif + task->addBindResource(GlBindingResource{ + 0, + task->getProgram()->getUniformBlockIndex("BlendRegion"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(region, 4 * sizeof(float), true), + 4 * sizeof(float), + }); + + // src and dst texture + task->addBindResource(GlBindingResource{1, blendPass->getFbo()->colorTex, task->getProgram()->getUniformLocation("uSrcTexture")}); + task->addBindResource(GlBindingResource{2, dstCopyFbo->colorTex, task->getProgram()->getUniformLocation("uDstTexture")}); + + currentPass()->addRenderTask(task); + + delete(blendPass); +} + + +GlProgram* GlRenderer::getBlendProgram(BlendMethod method, BlendSource source) +{ + // custom blend shaders + static const char* shaderFunc[17] { + NORMAL_BLEND_FRAG, + MULTIPLY_BLEND_FRAG, + SCREEN_BLEND_FRAG, + OVERLAY_BLEND_FRAG, + DARKEN_BLEND_FRAG, + LIGHTEN_BLEND_FRAG, + COLOR_DODGE_BLEND_FRAG, + COLOR_BURN_BLEND_FRAG, + HARD_LIGHT_BLEND_FRAG, + SOFT_LIGHT_BLEND_FRAG, + DIFFERENCE_BLEND_FRAG, + EXCLUSION_BLEND_FRAG, + HUE_BLEND_FRAG, + SATURATION_BLEND_FRAG, + COLOR_BLEND_FRAG, + LUMINOSITY_BLEND_FRAG, + ADD_BLEND_FRAG + }; + + uint32_t methodInd = (uint32_t)method; + uint32_t shaderInd = methodInd; + + switch (source) { + case BlendSource::Scene: shaderInd += (uint32_t)RT_Blend_Scene_Normal; break; + case BlendSource::Image: shaderInd += (uint32_t)RT_Blend_Image_Normal; break; + case BlendSource::Solid: shaderInd += (uint32_t)RT_ShapeBlend_Solid_Normal; break; + case BlendSource::LinearGradient: shaderInd += (uint32_t)RT_ShapeBlend_Linear_Normal; break; + case BlendSource::RadialGradient: shaderInd += (uint32_t)RT_ShapeBlend_Radial_Normal; break; + } + + if (mPrograms[shaderInd]) return mPrograms[shaderInd]; + + const char* helpers = ""; + if ((method == BlendMethod::Hue) || + (method == BlendMethod::Saturation) || + (method == BlendMethod::Color) || + (method == BlendMethod::Luminosity)) + helpers = BLEND_FRAG_HSL; + + const char* vertShader; + char fragShader[BLEND_TOTAL_LENGTH]; + + if (source == BlendSource::Scene || source == BlendSource::Image) { + vertShader = BLIT_VERT_SHADER; + const char* header = (source == BlendSource::Scene) ? BLEND_SCENE_FRAG_HEADER : BLEND_IMAGE_FRAG_HEADER; + snprintf(fragShader, BLEND_TOTAL_LENGTH, "%s%s%s", header, helpers, shaderFunc[methodInd]); + mPrograms[shaderInd] = new GlProgram(vertShader, fragShader); + return mPrograms[shaderInd]; + } + + vertShader = (source == BlendSource::Solid) ? COLOR_VERT_SHADER : GRADIENT_VERT_SHADER; + switch (source) { + case BlendSource::Solid: + snprintf(fragShader, BLEND_TOTAL_LENGTH, "%s%s%s", + BLEND_SHAPE_SOLID_FRAG_HEADER, + helpers, + shaderFunc[methodInd]); + break; + case BlendSource::LinearGradient: + snprintf(fragShader, BLEND_TOTAL_LENGTH, "%s%s%s%s%s%s%s", + STR_GRADIENT_FRAG_COMMON_VARIABLES, + STR_LINEAR_GRADIENT_VARIABLES, + STR_GRADIENT_FRAG_COMMON_FUNCTIONS, + STR_LINEAR_GRADIENT_FUNCTIONS, + BLEND_SHAPE_LINEAR_FRAG_HEADER, + helpers, + shaderFunc[methodInd]); + break; + case BlendSource::RadialGradient: + snprintf(fragShader, BLEND_TOTAL_LENGTH, "%s%s%s%s%s%s%s", + STR_GRADIENT_FRAG_COMMON_VARIABLES, + STR_RADIAL_GRADIENT_VARIABLES, + STR_GRADIENT_FRAG_COMMON_FUNCTIONS, + STR_RADIAL_GRADIENT_FUNCTIONS, + BLEND_SHAPE_RADIAL_FRAG_HEADER, + helpers, + shaderFunc[methodInd]); + break; + default: + TVGERR("RENDERER", "Unsupported blend source! = %d", (int)source); + break; + } + + mPrograms[shaderInd] = new GlProgram(vertShader, fragShader); + return mPrograms[shaderInd]; +} + + +void GlRenderer::prepareBlitTask(GlBlitTask* task) +{ + prepareCmpTask(task, {{0, 0}, {int32_t(surface.w), int32_t(surface.h)}}, surface.w, surface.h); + task->addBindResource(GlBindingResource{0, task->getColorTexture(), task->getProgram()->getUniformLocation("uSrcTexture")}); +} + + +void GlRenderer::prepareCmpTask(GlRenderTask* task, const RenderRegion& vp, uint32_t cmpWidth, uint32_t cmpHeight) +{ + const auto& passVp = currentPass()->getViewport(); + + auto taskVp = vp; + taskVp.intersect(passVp); + + auto x = taskVp.sx() - passVp.sx(); + auto y = taskVp.sy() - passVp.sy(); + auto w = taskVp.sw(); + auto h = taskVp.sh(); + + float rw = static_cast(passVp.w()); + float rh = static_cast(passVp.h()); + + float l = static_cast(x); + float t = static_cast(rh - y); + float r = static_cast(x + w); + float b = static_cast(rh - y - h); + + // map vp ltrp to -1:1 + float left = (l / rw) * 2.f - 1.f; + float top = (t / rh) * 2.f - 1.f; + float right = (r / rw) * 2.f - 1.f; + float bottom = (b / rh) * 2.f - 1.f; + + float uw = static_cast(w) / static_cast(cmpWidth); + float uh = static_cast(h) / static_cast(cmpHeight); + + float vertices[4*4] { + left, top, 0.f, uh, // left top point + left, bottom, 0.f, 0.f, // left bottom point + right, top, uw, uh, // right top point + right, bottom, uw, 0.f // right bottom point + }; + uint32_t indices[6]{0, 1, 2, 2, 1, 3}; + uint32_t vertexOffset = mGpuBuffer.push(vertices, sizeof(vertices)); + uint32_t indexOffset = mGpuBuffer.pushIndex(indices, sizeof(indices)); + + task->addVertexLayout(GlVertexLayout{0, 2, 4 * sizeof(float), vertexOffset}); + task->addVertexLayout(GlVertexLayout{1, 2, 4 * sizeof(float), vertexOffset + 2 * sizeof(float)}); + task->setDrawRange(indexOffset, 6); + y = (passVp.sh() - y - h); + task->setViewport({{x, y}, {x + w, y + h}}); +} + + +void GlRenderer::endRenderPass(RenderCompositor* cmp) +{ + auto glCmp = static_cast(cmp); + + // setup masking and blending render pass configurations + if ((glCmp->flags & (tvg::Blending | tvg::Masking)) == (tvg::Blending | tvg::Masking)) { + // rearrange render tree + auto selfPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + auto prevPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + auto maskPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + mRenderPassStack.push(prevPass); + mRenderPassStack.push(maskPass); + mRenderPassStack.push(selfPass); + // setup composition properties + auto prevCompose = mComposeStack.last(); + auto opacity = glCmp->opacity; + auto blendMethod = glCmp->blendMethod; + // self scene task must be masked but not blended + glCmp->method = prevCompose->method; + glCmp->opacity = 255; + glCmp->blendMethod = BlendMethod::Normal; + // prev scene task must be blended but not masked + prevCompose->method = MaskMethod::None; + prevCompose->opacity = opacity; + prevCompose->blendMethod = blendMethod; + }; + + if (cmp->method != MaskMethod::None) { + auto selfPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + + // mask is pushed first + auto maskPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + + GlProgram* program = nullptr; + switch(cmp->method) { + case MaskMethod::Alpha: program = mPrograms[RT_MaskAlpha]; break; + case MaskMethod::InvAlpha: program = mPrograms[RT_MaskAlphaInv]; break; + case MaskMethod::Luma: program = mPrograms[RT_MaskLuma]; break; + case MaskMethod::InvLuma: program = mPrograms[RT_MaskLumaInv]; break; + case MaskMethod::Add: program = mPrograms[RT_MaskAdd]; break; + case MaskMethod::Subtract: program = mPrograms[RT_MaskSub]; break; + case MaskMethod::Intersect: program = mPrograms[RT_MaskIntersect]; break; + case MaskMethod::Difference: program = mPrograms[RT_MaskDifference]; break; + case MaskMethod::Lighten: program = mPrograms[RT_MaskLighten]; break; + case MaskMethod::Darken: program = mPrograms[RT_MaskDarken]; break; + default: break; + } + if (program && !selfPass->isEmpty() && !maskPass->isEmpty()) { + auto prev_task = maskPass->endRenderPass(nullptr, currentPass()->getFboId()); + prev_task->setDrawDepth(currentPass()->nextDrawDepth()); + prev_task->setRenderSize(glCmp->bbox.w(), glCmp->bbox.h()); + prev_task->setViewport(glCmp->bbox); + + auto compose_task = selfPass->endRenderPass(program, currentPass()->getFboId()); + compose_task->setRenderSize(glCmp->bbox.w(), glCmp->bbox.h()); + compose_task->setPrevTask(prev_task); + + prepareCmpTask(compose_task, glCmp->bbox, selfPass->getFboWidth(), selfPass->getFboHeight()); + + compose_task->addBindResource(GlBindingResource{0, selfPass->getTextureId(), program->getUniformLocation("uSrcTexture")}); + compose_task->addBindResource(GlBindingResource{1, maskPass->getTextureId(), program->getUniformLocation("uMaskTexture")}); + + compose_task->setDrawDepth(currentPass()->nextDrawDepth()); + compose_task->setParentSize(currentPass()->getViewport().w(), currentPass()->getViewport().h()); + currentPass()->addRenderTask(compose_task); + } + delete(selfPass); + delete(maskPass); + } else if (glCmp->blendMethod != BlendMethod::Normal) { + auto renderPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + + if (!renderPass->isEmpty()) { + if (mBlendPool.count < 1) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); + if (mBlendPool.count < 2) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); +#if defined(THORVG_GL_TARGET_GL) + auto dstCopyFbo = mBlendPool[1]->getRenderTarget(renderPass->getViewport()); +#else // TODO: create partial buffer when MSAA is disabled + auto dstCopyFbo = mBlendPool[1]->getRenderTarget(currentPass()->getViewport()); +#endif + // image info + uint32_t info[4] = {(uint32_t)ColorSpace::ABGR8888, 0, cmp->opacity, 0}; + + auto program = getBlendProgram(glCmp->blendMethod, BlendSource::Scene); + auto task = renderPass->endRenderPass(program, currentPass()->getFboId()); + task->setSrcTarget(currentPass()->getFbo()); + task->setDstCopy(dstCopyFbo); + task->setRenderSize(glCmp->bbox.w(), glCmp->bbox.h()); + prepareCmpTask(task, glCmp->bbox, renderPass->getFboWidth(), renderPass->getFboHeight()); + task->setDrawDepth(currentPass()->nextDrawDepth()); +#if defined(THORVG_GL_TARGET_GL) + const auto& taskVp = task->getViewport(); + float region[] = {float(taskVp.sx()), float(taskVp.sy()), float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#else // TODO: create partial buffer when MSAA is disabled + float region[] = {0.0f, 0.0f, float(dstCopyFbo->width), float(dstCopyFbo->height)}; +#endif + task->addBindResource(GlBindingResource{ + 1, + task->getProgram()->getUniformBlockIndex("BlendRegion"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(region, 4 * sizeof(float), true), + 4 * sizeof(float), + }); + // info + task->addBindResource(GlBindingResource{0, task->getProgram()->getUniformBlockIndex("ColorInfo"), mGpuBuffer.getBufferId(), mGpuBuffer.push(info, sizeof(info), true), sizeof(info)}); + // textures + task->addBindResource(GlBindingResource{0, renderPass->getTextureId(), task->getProgram()->getUniformLocation("uSrcTexture")}); + task->addBindResource(GlBindingResource{1, dstCopyFbo->colorTex, task->getProgram()->getUniformLocation("uDstTexture")}); + task->setParentSize(currentPass()->getViewport().w(), currentPass()->getViewport().h()); + currentPass()->addRenderTask(std::move(task)); + } + delete(renderPass); + } else { + auto renderPass = mRenderPassStack.last(); + mRenderPassStack.pop(); + + if (!renderPass->isEmpty()) { + auto task = renderPass->endRenderPass(mPrograms[RT_Image], currentPass()->getFboId()); + task->setRenderSize(glCmp->bbox.w(), glCmp->bbox.h()); + prepareCmpTask(task, glCmp->bbox, renderPass->getFboWidth(), renderPass->getFboHeight()); + task->setDrawDepth(currentPass()->nextDrawDepth()); + + // matrix buffer + float matrix[GL_MAT3_STD140_SIZE]; + auto identityMatrix = tvg::identity(); + getMatrix3Std140(identityMatrix, matrix); + + task->addBindResource(GlBindingResource{ + 0, + task->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(matrix, GL_MAT3_STD140_BYTES, true), + GL_MAT3_STD140_BYTES, + }); + + // image info + uint32_t info[4] = {(uint32_t)ColorSpace::ABGR8888, 0, cmp->opacity, 0}; + + task->addBindResource(GlBindingResource{ + 1, + task->getProgram()->getUniformBlockIndex("ColorInfo"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(info, 4 * sizeof(uint32_t), true), + 4 * sizeof(uint32_t), + }); + + // texture id + task->addBindResource(GlBindingResource{0, renderPass->getTextureId(), task->getProgram()->getUniformLocation("uTexture")}); + task->setParentSize(currentPass()->getViewport().w(), currentPass()->getViewport().h()); + currentPass()->addRenderTask(std::move(task)); + } + delete(renderPass); + } +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +bool GlRenderer::clear() +{ + if (mRootTarget.invalid()) return false; + + mClearBuffer = true; + return true; +} + + +bool GlRenderer::target(void* display, void* surface, void* context, int32_t id, uint32_t w, uint32_t h, ColorSpace cs) +{ + //assume the context zero is invalid + if (!context || w == 0 || h == 0) return false; + + if (mContext) currentContext(); + + flush(); + + this->surface.stride = w; + this->surface.w = w; + this->surface.h = h; + this->surface.cs = cs; + + mDisplay = display; + mSurface = surface; + mContext = context; + mTargetFboId = static_cast(id); + + auto ret = currentContext(); + + mRootTarget.viewport = {{0, 0}, {int32_t(this->surface.w), int32_t(this->surface.h)}}; + mRootTarget.init(this->surface.w, this->surface.h, mTargetFboId); + + return ret; +} + + +bool GlRenderer::sync() +{ + //nothing to be done. + if (mRenderPassStack.empty()) return true; + + currentContext(); + + // Blend function for straight alpha + GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + GL_CHECK(glEnable(GL_BLEND)); + GL_CHECK(glEnable(GL_SCISSOR_TEST)); + GL_CHECK(glCullFace(GL_FRONT_AND_BACK)); + GL_CHECK(glFrontFace(GL_CCW)); + GL_CHECK(glEnable(GL_DEPTH_TEST)); + GL_CHECK(glDepthFunc(GL_GREATER)); + + auto task = mRenderPassStack.first()->endRenderPass(mPrograms[RT_Blit], mTargetFboId); + + prepareBlitTask(task); + + task->mClearBuffer = mClearBuffer; + task->setTargetViewport({{0, 0}, {int32_t(surface.w), int32_t(surface.h)}}); + + if (mGpuBuffer.flushToGPU()) { + mGpuBuffer.bind(); + task->run(); + } + + mGpuBuffer.unbind(); + + GL_CHECK(glDisable(GL_SCISSOR_TEST)); + + clearDisposes(); + + // Reset clear buffer flag to default (false) after use. + mClearBuffer = false; + + delete task; + + return true; +} + + +bool GlRenderer::bounds(RenderData data, Point* pt4, const Matrix& m) +{ + if (data) { + auto sdata = static_cast(data); + if (sdata->validStroke) { + tvg::BBox bbox; + bbox.init(); + auto& vertexes = sdata->geometry.stroke.vertex; + for (uint32_t i = 0; i < vertexes.count / 2; i++) { + Point vert = Point{vertexes[i*2+0], vertexes[i*2+1]} * m; + bbox.min = min(bbox.min, vert); + bbox.max = max(bbox.max, vert); + } + pt4[0] = bbox.min; + pt4[1] = {bbox.max.x, bbox.min.y}; + pt4[2] = bbox.max; + pt4[3] = {bbox.min.x, bbox.max.y}; + return true; + } + } + return false; +} + + +RenderRegion GlRenderer::region(RenderData data) +{ + if (!data) return {}; + auto shape = reinterpret_cast(data); + return shape->geometry.getBounds(); +} + + +bool GlRenderer::preRender() +{ + if (mRootTarget.invalid()) return false; + + currentContext(); + if (mPrograms.empty()) initShaders(); + mRenderPassStack.push(new GlRenderPass(&mRootTarget)); + + return true; +} + + +bool GlRenderer::postRender() +{ + return true; +} + + +RenderCompositor* GlRenderer::target(const RenderRegion& region, TVG_UNUSED ColorSpace cs, TVG_UNUSED CompositionFlag flags) +{ + auto vp = region; + if (currentPass()->isEmpty()) return nullptr; + + vp.intersect(currentPass()->getViewport()); + + mComposeStack.push(new GlCompositor(vp, flags)); + return mComposeStack.last(); +} + + +bool GlRenderer::beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) +{ + if (!cmp) return false; + + auto glCmp = static_cast(cmp); + glCmp->method = method; + glCmp->opacity = opacity; + glCmp->blendMethod = mBlendMethod; + + uint32_t index = mRenderPassStack.count - 1; + if (index >= mComposePool.count) mComposePool.push( new GlRenderTargetPool(surface.w, surface.h)); + + if (glCmp->bbox.valid()) mRenderPassStack.push(new GlRenderPass(mComposePool[index]->getRenderTarget(glCmp->bbox))); + else mRenderPassStack.push(new GlRenderPass(nullptr)); + + return true; +} + + +bool GlRenderer::endComposite(RenderCompositor* cmp) +{ + if (mComposeStack.empty()) return false; + if (mComposeStack.last() != cmp) return false; + + // end current render pass; + auto curCmp = mComposeStack.last(); + mComposeStack.pop(); + + assert(cmp == curCmp); + + endRenderPass(curCmp); + + delete(curCmp); + + return true; +} + + +void GlRenderer::prepare(RenderEffect* effect, const Matrix& transform) +{ + // we must be sure, that we have intermediate FBOs + if (mBlendPool.count < 1) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); + if (mBlendPool.count < 2) mBlendPool.push(new GlRenderTargetPool(surface.w, surface.h)); + + mEffect.update(effect, transform); +} + + +bool GlRenderer::region(RenderEffect* effect) +{ + return mEffect.region(effect); +} + + +bool GlRenderer::render(TVG_UNUSED RenderCompositor* cmp, const RenderEffect* effect, TVG_UNUSED bool direct) +{ + return mEffect.render(const_cast(effect), currentPass(), mBlendPool); +} + + +void GlRenderer::dispose(RenderEffect* effect) +{ + tvg::free(effect->rd); + effect->rd = nullptr; +} + + +ColorSpace GlRenderer::colorSpace() +{ + return surface.cs; +} + + +const RenderSurface* GlRenderer::mainSurface() +{ + return &surface; +} + + +bool GlRenderer::blend(BlendMethod method) +{ + if (method == mBlendMethod) return true; + + mBlendMethod = (method == BlendMethod::Composition ? BlendMethod::Normal : method); + + return true; +} + + +bool GlRenderer::renderImage(void* data) +{ + auto sdata = static_cast(data); + if (!sdata) return false; + + if (currentPass()->isEmpty() || !sdata->validFill) return true; + + auto vp = currentPass()->getViewport(); + auto bbox = sdata->geometry.viewport; + bbox.intersect(vp); + if (bbox.invalid()) return true; + + auto x = bbox.sx() - vp.sx(); + auto y = bbox.sy() - vp.sy(); + auto drawDepth = currentPass()->nextDrawDepth(); + + if (!sdata->clips.empty()) drawClip(sdata->clips); + + auto task = new GlRenderTask(mPrograms[RT_Image]); + task->setDrawDepth(drawDepth); + + if (!sdata->geometry.draw(task, &mGpuBuffer, RenderUpdateFlag::Image)) { + delete task; + return true; + } + + bool complexBlend = beginComplexBlending(bbox, sdata->geometry.getBounds()); + if (complexBlend) vp = currentPass()->getViewport(); + + // matrix buffer + float matrix3STD140[GL_MAT3_STD140_SIZE]; + currentPass()->getMatrix(matrix3STD140, sdata->geometry.matrix); + + task->addBindResource(GlBindingResource{ + 0, + task->getProgram()->getUniformBlockIndex("Matrix"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(matrix3STD140, GL_MAT3_STD140_BYTES, true), + GL_MAT3_STD140_BYTES, + }); + + // image info + uint32_t info[4] = {(uint32_t)sdata->texColorSpace, sdata->texFlipY, sdata->opacity, 0}; + + task->addBindResource(GlBindingResource{ + 1, + task->getProgram()->getUniformBlockIndex("ColorInfo"), + mGpuBuffer.getBufferId(), + mGpuBuffer.push(info, 4 * sizeof(uint32_t), true), + 4 * sizeof(uint32_t), + }); + + // texture id + task->addBindResource(GlBindingResource{0, sdata->texId, task->getProgram()->getUniformLocation("uTexture")}); + + y = vp.sh() - y - bbox.sh(); + auto x2 = x + bbox.sw(); + auto y2 = y + bbox.sh(); + + task->setViewport({{x, y}, {x2, y2}}); + + currentPass()->addRenderTask(task); + + if (complexBlend) { + auto task = new GlRenderTask(mPrograms[RT_Stencil]); + sdata->geometry.draw(task, &mGpuBuffer, RenderUpdateFlag::Image); + endBlendingCompose(task, sdata->geometry.matrix); + } + + return true; +} + + +bool GlRenderer::renderShape(RenderData data) +{ + auto sdata = static_cast(data); + if (currentPass()->isEmpty() || (!sdata->validFill && !sdata->validStroke)) return true; + + auto bbox = sdata->geometry.viewport; + bbox.intersect(currentPass()->getViewport()); + if (bbox.invalid()) return true; + + int32_t drawDepth1 = 0, drawDepth2 = 0; + if (sdata->validFill) drawDepth1 = currentPass()->nextDrawDepth(); + if (sdata->validStroke) drawDepth2 = currentPass()->nextDrawDepth(); + + if (!sdata->clips.empty()) drawClip(sdata->clips); + + auto processFill = [&]() { + if (sdata->validFill) { + if (const auto& gradient = sdata->rshape->fill) { + drawPrimitive(*sdata, gradient, RenderUpdateFlag::Gradient, drawDepth1); + } else if (sdata->rshape->color.a > 0) { + drawPrimitive(*sdata, sdata->rshape->color, RenderUpdateFlag::Color, drawDepth1); + } + } + }; + + auto processStroke = [&]() { + if (sdata->validStroke) { + if (const auto& gradient = sdata->rshape->strokeFill()) { + drawPrimitive(*sdata, gradient, RenderUpdateFlag::GradientStroke, drawDepth2); + } else if (sdata->rshape->stroke->color.a > 0) { + drawPrimitive(*sdata, sdata->rshape->stroke->color, RenderUpdateFlag::Stroke, drawDepth2); + } + } + }; + + if (sdata->rshape->strokeFirst()) { + processStroke(); + processFill(); + } else { + processFill(); + processStroke(); + } + + return true; +} + + +void GlRenderer::dispose(RenderData data) +{ + auto sdata = static_cast(data); + + //dispose the non thread-safety resources on clearDisposes() call + if (sdata->texId) { + ScopedLock lock(mDisposed.key); + mDisposed.textures.push(sdata->texId); + } + + delete sdata; +} + +static GLuint _genTexture(RenderSurface* image) +{ + GLuint tex = 0; + + GL_CHECK(glGenTextures(1, &tex)); + + GL_CHECK(glBindTexture(GL_TEXTURE_2D, tex)); + GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->data)); + + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + + GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0)); + + return tex; +} + + +RenderData GlRenderer::prepare(RenderSurface* image, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) +{ + //TODO: redefine GlImage. + auto sdata = static_cast(data); + if (!sdata) sdata = new GlShape; + sdata->validFill = false; + + if (opacity == 0 || flags == RenderUpdateFlag::None) return data; + + sdata->viewWd = static_cast(surface.w); + sdata->viewHt = static_cast(surface.h); + + if (sdata->texId == 0) { + sdata->texId = _genTexture(image); + sdata->texColorSpace = image->cs; + sdata->texFlipY = 1; + sdata->geometry = GlGeometry(); + } + + sdata->opacity = opacity; + sdata->geometry.matrix = transform; + sdata->geometry.viewport = vport; + sdata->geometry.tesselateImage(image); + sdata->validFill = true; + + if (flags & RenderUpdateFlag::Clip) { + sdata->clips.clear(); + sdata->clips.push(clips); + } + + return sdata; +} + + +RenderData GlRenderer::prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) +{ + auto sdata = static_cast(data); + if (!sdata) { + sdata = new GlShape; + sdata->rshape = &rshape; + flags = RenderUpdateFlag::All; + } + + if ((opacity == 0 && !clipper) || flags == RenderUpdateFlag::None) return sdata; + + sdata->viewWd = static_cast(surface.w); + sdata->viewHt = static_cast(surface.h); + sdata->opacity = opacity; + + if (flags & RenderUpdateFlag::Path) sdata->geometry = GlGeometry(); + + sdata->geometry.matrix = transform; + sdata->geometry.viewport = vport; + if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Transform)) sdata->geometry.prepare(rshape); + + //TODO: Please precisely update tessellation not to update only if the color is changed. + if (flags & (RenderUpdateFlag::Color | RenderUpdateFlag::Gradient | RenderUpdateFlag::Transform | RenderUpdateFlag::Path)) { + sdata->validFill = false; + float opacityMultiplier = 1.0f; + if (sdata->geometry.tesselateShape(*(sdata->rshape), &opacityMultiplier)) { + sdata->opacity *= opacityMultiplier; + sdata->validFill = true; + } + } + + //TODO: Please precisely update tessellation not to update only if the color is changed. + if (flags & (RenderUpdateFlag::Color | RenderUpdateFlag::Stroke | RenderUpdateFlag::GradientStroke | RenderUpdateFlag::Transform | RenderUpdateFlag::Path)) { + sdata->validStroke = false; + if (sdata->geometry.tesselateStroke(*(sdata->rshape))) sdata->validStroke = true; + } + + if (flags & RenderUpdateFlag::Clip) { + sdata->clips.clear(); + sdata->clips.push(clips); + } + + return sdata; +} + + +bool GlRenderer::preUpdate() +{ + if (mRootTarget.invalid()) return false; + + currentContext(); + return true; +} + + +bool GlRenderer::postUpdate() +{ + return true; +} + + +void GlRenderer::damage(TVG_UNUSED RenderData rd, TVG_UNUSED const RenderRegion& region) +{ + //TODO +} + + +bool GlRenderer::partial(bool disable) +{ + //TODO + return false; +} + + +bool GlRenderer::intersectsShape(RenderData data, TVG_UNUSED const RenderRegion& region) +{ + if (!data) return false; + auto shape = (GlShape*)data; + const auto& bbox = shape->geometry.getBounds(); + if (region.intersected(bbox)) { + if (region.contained(bbox)) return true; + GlIntersector intersector; + return intersector.intersectShape(RenderRegion::intersect(region, bbox), shape); + } + return false; +} + + +bool GlRenderer::intersectsImage(RenderData data, TVG_UNUSED const RenderRegion& region) +{ + if (!data) return false; + auto shape = (GlShape*)data; + const auto& bbox = shape->geometry.getBounds(); + if (region.intersected(bbox)) { + if (region.contained(bbox)) return true; + GlIntersector intersector; + if (intersector.intersectImage(RenderRegion::intersect(region, bbox), shape)) return true; + } + return false; +} + + +bool GlRenderer::term() +{ + if (rendererCnt > 0) return false; + + glTerm(); + + rendererCnt = -1; + + return true; +} + + +GlRenderer* GlRenderer::gen(TVG_UNUSED uint32_t threads) +{ + //initialize engine + if (rendererCnt == -1) { + if (!glInit()) { + TVGERR("GL_ENGINE", "Failed GL initialization!"); + return nullptr; + } + rendererCnt = 0; + } + + return new GlRenderer; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderer.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderer.h new file mode 100644 index 0000000..b42dec3 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlRenderer.h @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_RENDERER_H_ +#define _TVG_GL_RENDERER_H_ + +#include "tvgArray.h" +#include "tvgGlRenderTarget.h" +#include "tvgGlRenderTask.h" +#include "tvgGlGpuBuffer.h" +#include "tvgGlRenderPass.h" +#include "tvgGlEffect.h" + +struct GlRenderer : RenderMethod +{ + enum RenderTypes + { + RT_Color = 0, + RT_LinGradient, + RT_RadGradient, + RT_Image, + RT_MaskAlpha, + RT_MaskAlphaInv, + RT_MaskLuma, + RT_MaskLumaInv, + RT_MaskAdd, + RT_MaskSub, + RT_MaskIntersect, + RT_MaskDifference, + RT_MaskLighten, + RT_MaskDarken, + RT_Stencil, + RT_Blit, + // blends (image) + RT_Blend_Image_Normal, + RT_Blend_Image_Multiply, + RT_Blend_Image_Screen, + RT_Blend_Image_Overlay, + RT_Blend_Image_Darken, + RT_Blend_Image_Lighten, + RT_Blend_Image_ColorDodge, + RT_Blend_Image_ColorBurn, + RT_Blend_Image_HardLight, + RT_Blend_Image_SoftLight, + RT_Blend_Image_Difference, + RT_Blend_Image_Exclusion, + RT_Blend_Image_Hue, + RT_Blend_Image_Saturation, + RT_Blend_Image_Color, + RT_Blend_Image_Luminosity, + RT_Blend_Image_Add, + // blends (scene) + RT_Blend_Scene_Normal, + RT_Blend_Scene_Multiply, + RT_Blend_Scene_Screen, + RT_Blend_Scene_Overlay, + RT_Blend_Scene_Darken, + RT_Blend_Scene_Lighten, + RT_Blend_Scene_ColorDodge, + RT_Blend_Scene_ColorBurn, + RT_Blend_Scene_HardLight, + RT_Blend_Scene_SoftLight, + RT_Blend_Scene_Difference, + RT_Blend_Scene_Exclusion, + RT_Blend_Scene_Hue, + RT_Blend_Scene_Saturation, + RT_Blend_Scene_Color, + RT_Blend_Scene_Luminosity, + RT_Blend_Scene_Add, + // shape blends (solid) + RT_ShapeBlend_Solid_Normal, + RT_ShapeBlend_Solid_Multiply, + RT_ShapeBlend_Solid_Screen, + RT_ShapeBlend_Solid_Overlay, + RT_ShapeBlend_Solid_Darken, + RT_ShapeBlend_Solid_Lighten, + RT_ShapeBlend_Solid_ColorDodge, + RT_ShapeBlend_Solid_ColorBurn, + RT_ShapeBlend_Solid_HardLight, + RT_ShapeBlend_Solid_SoftLight, + RT_ShapeBlend_Solid_Difference, + RT_ShapeBlend_Solid_Exclusion, + RT_ShapeBlend_Solid_Hue, + RT_ShapeBlend_Solid_Saturation, + RT_ShapeBlend_Solid_Color, + RT_ShapeBlend_Solid_Luminosity, + RT_ShapeBlend_Solid_Add, + // shape blends (linear gradient) + RT_ShapeBlend_Linear_Normal, + RT_ShapeBlend_Linear_Multiply, + RT_ShapeBlend_Linear_Screen, + RT_ShapeBlend_Linear_Overlay, + RT_ShapeBlend_Linear_Darken, + RT_ShapeBlend_Linear_Lighten, + RT_ShapeBlend_Linear_ColorDodge, + RT_ShapeBlend_Linear_ColorBurn, + RT_ShapeBlend_Linear_HardLight, + RT_ShapeBlend_Linear_SoftLight, + RT_ShapeBlend_Linear_Difference, + RT_ShapeBlend_Linear_Exclusion, + RT_ShapeBlend_Linear_Hue, + RT_ShapeBlend_Linear_Saturation, + RT_ShapeBlend_Linear_Color, + RT_ShapeBlend_Linear_Luminosity, + RT_ShapeBlend_Linear_Add, + // shape blends (radial gradient) + RT_ShapeBlend_Radial_Normal, + RT_ShapeBlend_Radial_Multiply, + RT_ShapeBlend_Radial_Screen, + RT_ShapeBlend_Radial_Overlay, + RT_ShapeBlend_Radial_Darken, + RT_ShapeBlend_Radial_Lighten, + RT_ShapeBlend_Radial_ColorDodge, + RT_ShapeBlend_Radial_ColorBurn, + RT_ShapeBlend_Radial_HardLight, + RT_ShapeBlend_Radial_SoftLight, + RT_ShapeBlend_Radial_Difference, + RT_ShapeBlend_Radial_Exclusion, + RT_ShapeBlend_Radial_Hue, + RT_ShapeBlend_Radial_Saturation, + RT_ShapeBlend_Radial_Color, + RT_ShapeBlend_Radial_Luminosity, + RT_ShapeBlend_Radial_Add, + RT_None + }; + + //main features + bool preUpdate() override; + RenderData prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) override; + RenderData prepare(RenderSurface* surface, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) override; + bool postUpdate() override; + bool preRender() override; + bool renderShape(RenderData data) override; + bool renderImage(RenderData data) override; + bool postRender() override; + void dispose(RenderData data) override;; + RenderRegion region(RenderData data) override; + bool bounds(RenderData data, Point* pt4, const Matrix& m) override; + bool blend(BlendMethod method) override; + ColorSpace colorSpace() override; + const RenderSurface* mainSurface() override; + bool sync() override; + bool clear() override; + bool intersectsShape(RenderData data, const RenderRegion& region) override; + bool intersectsImage(RenderData data, const RenderRegion& region) override; + bool target(void* display, void* surface, void* context, int32_t id, uint32_t w, uint32_t h, ColorSpace cs); + + //composition + RenderCompositor* target(const RenderRegion& region, ColorSpace cs, CompositionFlag flags) override; + bool beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) override; + bool endComposite(RenderCompositor* cmp) override; + + //post effects + void prepare(RenderEffect* effect, const Matrix& transform) override; + bool region(RenderEffect* effect) override; + bool render(RenderCompositor* cmp, const RenderEffect* effect, bool direct) override; + void dispose(RenderEffect* effect) override; + + //partial rendering + void damage(RenderData rd, const RenderRegion& region) override; + bool partial(bool disable) override; + + static GlRenderer* gen(uint32_t threads); + static bool term(); + +private: + enum class BlendSource { Image, Scene, Solid, LinearGradient, RadialGradient }; + + GlRenderer(); + ~GlRenderer(); + + void initShaders(); + void drawPrimitive(GlShape& sdata, const RenderColor& c, RenderUpdateFlag flag, int32_t depth); + void drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFlag flag, int32_t depth); + void drawClip(Array& clips); + + GlRenderPass* currentPass(); + + bool beginComplexBlending(const RenderRegion& vp, RenderRegion bounds); + void endBlendingCompose(GlRenderTask* stencilTask, const Matrix& matrix); + GlProgram* getBlendProgram(BlendMethod method, BlendSource source); + + void prepareBlitTask(GlBlitTask* task); + void prepareCmpTask(GlRenderTask* task, const RenderRegion& vp, uint32_t cmpWidth, uint32_t cmpHeight); + void endRenderPass(RenderCompositor* cmp); + + void flush(); + void clearDisposes(); + bool currentContext(); + + void* mDisplay = nullptr; // EGLDisplay for EGL; unused for other app-managed contexts. + void* mSurface = nullptr; // EGLSurface for EGL, HDC for WGL; unused for other app-managed contexts. + void* mContext = nullptr; + + RenderSurface surface; + GLint mTargetFboId = 0; + GlStageBuffer mGpuBuffer; + GlRenderTarget mRootTarget; + GlEffect mEffect; + Array mPrograms; + + Array mComposePool; + Array mBlendPool; + Array mRenderPassStack; + Array mComposeStack; + + //Disposed resources. They should be released on synced call. + struct { + Array textures; + Key key; + } mDisposed; + + BlendMethod mBlendMethod = BlendMethod::Normal; + bool mClearBuffer = false; +}; + +#endif /* _TVG_GL_RENDERER_H_ */ diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlShader.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlShader.cpp new file mode 100644 index 0000000..16d05a7 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlShader.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlShader.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +uint32_t GlShader::compileShader(uint32_t type, char* shaderSrc) +{ + GLuint shader; + GLint compiled; + + // Create the shader object + shader = glCreateShader(type); + + /** + * [0] shader version string + * [1] precision declaration + * [2] shader source + */ + const char* shaderPack[3]; + // but in general All Desktop GPU should use OpenGL version ( #version 330 core ) +#if defined (THORVG_GL_TARGET_GLES) + shaderPack[0] ="#version 300 es\n"; +#else + shaderPack[0] ="#version 330 core\n"; +#endif + shaderPack[1] = "precision highp float;\n precision highp int;\n"; + shaderPack[2] = shaderSrc; + + // Load the shader source + glShaderSource(shader, 3, shaderPack, NULL); + + // Compile the shader + glCompileShader(shader); + + // Check the compile status + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + + if (!compiled) + { + GLint infoLen = 0; + + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); + + if (infoLen > 0) + { + auto infoLog = tvg::malloc(sizeof(char)*infoLen); + glGetShaderInfoLog(shader, infoLen, NULL, infoLog); + TVGERR("GL_ENGINE", "Error compiling shader: %s", infoLog); + tvg::free(infoLog); + } + glDeleteShader(shader); + } + + return shader; +} + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +GlShader::GlShader(const char* vertSrc, const char* fragSrc) +{ + mVtShader = compileShader(GL_VERTEX_SHADER, const_cast(vertSrc)); + mFrShader = compileShader(GL_FRAGMENT_SHADER, const_cast(fragSrc)); +} + + +GlShader::~GlShader() +{ + glDeleteShader(mVtShader); + glDeleteShader(mFrShader); +} + +uint32_t GlShader::getVertexShader() +{ + return mVtShader; +} + + +uint32_t GlShader::getFragmentShader() +{ + return mFrShader; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlShader.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlShader.h new file mode 100644 index 0000000..7d66ce7 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlShader.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_SHADER_H_ +#define _TVG_GL_SHADER_H_ + +#include "tvgGlCommon.h" + +class GlShader +{ +public: + GlShader(const char* vertSrc, const char* fragSrc); + ~GlShader(); + + uint32_t getVertexShader(); + uint32_t getFragmentShader(); + +private: + uint32_t compileShader(uint32_t type, char* shaderSrc); + + uint32_t mVtShader; + uint32_t mFrShader; +}; + +#endif /* _TVG_GL_SHADER_H_ */ diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlShaderSrc.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlShaderSrc.cpp new file mode 100644 index 0000000..f4664fe --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlShaderSrc.cpp @@ -0,0 +1,1199 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlShaderSrc.h" + +#define TVG_COMPOSE_SHADER(shader) #shader + +const char* COLOR_VERT_SHADER = TVG_COMPOSE_SHADER( + uniform float uDepth; \n + layout(location = 0) in vec2 aLocation; \n + layout(std140) uniform Matrix { \n + mat3 transform; \n + } uMatrix; \n + \n + void main() \n + { \n + vec3 pos = uMatrix.transform * vec3(aLocation, 1.0); \n + gl_Position = vec4(pos.xy, uDepth, 1.0); \n + } \n +); + +const char* COLOR_FRAG_SHADER = TVG_COMPOSE_SHADER( + layout(std140) uniform ColorInfo { \n + vec4 solidColor; \n + } uColorInfo; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 uColor = uColorInfo.solidColor; \n + FragColor = vec4(uColor.rgb * uColor.a, uColor.a); \n + } \n +); + +const char* GRADIENT_VERT_SHADER = TVG_COMPOSE_SHADER( + uniform float uDepth; \n + layout(location = 0) in vec2 aLocation; \n + out vec2 vPos; \n + layout(std140) uniform Matrix { \n + mat3 transform; \n + } uMatrix; \n + layout(std140) uniform InvMatrix { \n + mat3 transform; \n + } uInvMatrix; \n + \n + void main() \n + { \n + vec3 glPos = uMatrix.transform * vec3(aLocation, 1.0); \n + gl_Position = vec4(glPos.xy, uDepth, 1.0); \n + vec3 pos = uInvMatrix.transform * vec3(aLocation, 1.0); \n + vPos = pos.xy; \n + } \n +); + + +//See: GlRenderer::initShaders() +const char* STR_GRADIENT_FRAG_COMMON_VARIABLES = TVG_COMPOSE_SHADER( + const int MAX_STOP_COUNT = 16; \n + in vec2 vPos; \n +); + +//See: GlRenderer::initShaders() +const char* STR_GRADIENT_FRAG_COMMON_FUNCTIONS = TVG_COMPOSE_SHADER( + float gradientStep(float edge0, float edge1, float x) \n + { \n + // linear \n + x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); \n + return x; \n + } \n + \n + float gradientStop(int index) \n + { \n + if (index >= MAX_STOP_COUNT) index = MAX_STOP_COUNT - 1; \n + int i = index / 4; \n + int j = index % 4; \n + return uGradientInfo.stopPoints[i][j]; \n + } \n + \n + float gradientWrap(float d) \n + { \n + int spread = int(uGradientInfo.nStops[2]); \n + if (spread == 0) return clamp(d, 0.0, 1.0); \n + \n + if (spread == 1) { /* Reflect */ \n + float n = mod(d, 2.0); \n + if (n > 1.0) { \n + n = 2.0 - n; \n + } \n + return n; \n + } \n + if (spread == 2) { /* Repeat */ \n + float n = mod(d, 1.0); \n + if (n < 0.0) { \n + n += 1.0 + n; \n + } \n + return n; \n + } \n + } \n + \n + vec4 gradient(float t, float d, float l) \n + { \n + float dist = d * 2.0 / l; \n + vec4 col = vec4(0.0); \n + int i = 0; \n + int count = int(uGradientInfo.nStops[0]); \n + if (t <= gradientStop(0)) { \n + col = uGradientInfo.stopColors[0]; \n + } else if (t >= gradientStop(count - 1)) { \n + col = uGradientInfo.stopColors[count - 1]; \n + if (int(uGradientInfo.nStops[2]) == 2 && (1.0 - t) < dist) { \n + float dd = (1.0 - t) / dist; \n + float alpha = dd; \n + col *= alpha; \n + col += uGradientInfo.stopColors[0] * (1. - alpha); \n + } \n + } else { \n + for (i = 0; i < count - 1; ++i) { \n + float stopi = gradientStop(i); \n + float stopi1 = gradientStop(i + 1); \n + if (t >= stopi && t <= stopi1) { \n + col = (uGradientInfo.stopColors[i] * (1. - gradientStep(stopi, stopi1, t))); \n + col += (uGradientInfo.stopColors[i + 1] * gradientStep(stopi, stopi1, t)); \n + if (int(uGradientInfo.nStops[2]) == 2 && abs(d) > dist) { \n + if (i == 0 && (t - stopi) < dist) { \n + float dd = (t - stopi) / dist; \n + float alpha = dd; \n + col *= alpha; \n + vec4 nc = uGradientInfo.stopColors[0] * (1.0 - (t - stopi)); \n + nc += uGradientInfo.stopColors[count - 1] * (t - stopi); \n + col += nc * (1.0 - alpha); \n + } else if (i == count - 2 && (1.0 - t) < dist) { \n + float dd = (1.0 - t) / dist; \n + float alpha = dd; \n + col *= alpha; \n + col += (uGradientInfo.stopColors[0]) * (1.0 - alpha); \n + } \n + } \n + break; \n + } \n + } \n + } \n + return col; \n + } \n + \n + vec3 ScreenSpaceDither(vec2 vScreenPos) \n + { \n + vec3 vDither = vec3(dot(vec2(171.0, 231.0), vScreenPos.xy)); \n + vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0)); \n + return vDither.rgb / 255.0; \n + } \n +); + +//See: GlRenderer::initShaders() +const char* STR_LINEAR_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER( + layout(std140) uniform GradientInfo { \n + vec4 nStops; \n + vec2 gradStartPos; \n + vec2 gradEndPos; \n + vec4 stopPoints[MAX_STOP_COUNT / 4]; \n + vec4 stopColors[MAX_STOP_COUNT]; \n + } uGradientInfo; \n +); + +//See: GlRenderer::initShaders() +const char* STR_LINEAR_GRADIENT_MAIN = TVG_COMPOSE_SHADER( + out vec4 FragColor; \n + void main() \n + { \n + FragColor = linearGradientColor(vPos); \n + } \n +); + +//See: GlRenderer::initShaders() +const char* STR_LINEAR_GRADIENT_FUNCTIONS = TVG_COMPOSE_SHADER( + vec4 linearGradientColor(vec2 pos) \n + { \n + vec2 st = uGradientInfo.gradStartPos; \n + vec2 ed = uGradientInfo.gradEndPos; \n + vec2 ba = ed - st; \n + float d = dot(pos - st, ba) / dot(ba, ba); \n + float t = gradientWrap(d); \n + vec4 color = gradient(t, d, length(pos - st)); \n + return vec4(color.rgb * color.a, color.a); \n + } \n +); + +//See: GlRenderer::initShaders() +const char* STR_RADIAL_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER( + layout(std140) uniform GradientInfo { \n + vec4 nStops; \n + vec4 centerPos; \n + vec2 radius; \n + vec4 stopPoints[MAX_STOP_COUNT / 4]; \n + vec4 stopColors[MAX_STOP_COUNT]; \n + } uGradientInfo ; \n +); + +//See: GlRenderer::initShaders() +const char* STR_RADIAL_GRADIENT_MAIN = TVG_COMPOSE_SHADER( + out vec4 FragColor; \n + \n + void main() \n + { \n + FragColor = radialGradientColor(vPos); \n + } \n +); + +// TODO: Precompute radial_matrix, f, r1n, inv_r1, d_radius_sign, is_focal_on_circle, is_well_behaved, is_swapped in CPU as a uniform +//See: GlRenderer::initShaders() +const char* STR_RADIAL_GRADIENT_FUNCTIONS = TVG_COMPOSE_SHADER( + mat3 radial_matrix(vec2 p0, vec2 p1) \n + { \n + mat3 a = mat3(0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); \n + mat3 b = mat3(p1.y - p0.y, p0.x - p1.x, 0.0, p1.x - p0.x, p1.y - p0.y, 0.0, p0.x, p0.y, 1.0); \n + return a * inverse(b); \n + } \n + \n + vec2 compute_radial_t(vec2 c0, float r0, vec2 c1, float r1, vec2 pos) \n + { \n + const float scalar_nearly_zero = 2.44140625e-4; \n + float d_center = distance(c0, c1); \n + float d_radius = r1 - r0; \n + bool radial = d_center < scalar_nearly_zero; \n + bool strip = abs(d_radius) < scalar_nearly_zero; \n + \n + if (radial) { \n + if (strip) return vec2(0.0, -1.0); \n + \n + float scale = 1.0 / d_radius; \n + float scale_sign = sign(d_radius); \n + float bias = r0 / d_radius; \n + vec2 pt = (pos - c0) * scale; \n + float t = length(pt) * scale_sign - bias; \n + return vec2(t, 1.0); \n + } else if (strip) { \n + mat3 transform = radial_matrix(c0, c1); \n + float r = r0 / d_center; \n + float r_2 = r * r; \n + vec2 pt = (transform * vec3(pos.xy, 1.0)).xy; \n + float t = r_2 - pt.y * pt.y; \n + \n + if (t < 0.0) return vec2(0.0, -1.0); \n + \n + t = pt.x + sqrt(t); \n + return vec2(t, 1.0); \n + } else { \n + float f = r0 / (r0 - r1); \n + bool is_swapped = abs(f - 1.0) < scalar_nearly_zero; \n + vec2 c0p = is_swapped ? c1 : c0; \n + vec2 c1p = is_swapped ? c0 : c1; \n + float fp = is_swapped ? 0.0 : f; \n + vec2 cf = c0p * (1.0 - fp) + c1p * fp; \n + mat3 transform = radial_matrix(cf, c1p); \n + \n + float scale_x = abs(1.0 - fp); \n + float scale_y = scale_x; \n + float r1n = abs(r1 - r0) / d_center; \n + bool is_focal_on_circle = abs(r1n - 1.0) < scalar_nearly_zero; \n + if (is_focal_on_circle) { \n + scale_x *= 0.5; \n + scale_y *= 0.5; \n + } else { \n + float denom = r1n * r1n - 1.0; \n + scale_x *= r1n / denom; \n + scale_y /= sqrt(abs(denom)); \n + } \n + transform = mat3(scale_x, 0.0, 0.0, 0.0, scale_y, 0.0, 0.0, 0.0, 1.0) * transform; \n + \n + vec2 pt = (transform * vec3(pos.xy, 1.0)).xy; \n + \n + float inv_r1 = 1.0 / r1n; \n + float d_radius_sign = sign(1.0 - fp); \n + \n + float x_t = -1.0; \n + if (is_focal_on_circle) x_t = dot(pt, pt) / pt.x; \n + else if (r1n > 1.0) x_t = length(pt) - pt.x * inv_r1; \n + else { \n + float discriminant = pt.x * pt.x - pt.y * pt.y; \n + float root = sqrt(max(discriminant, 0.0)); \n + float s = (is_swapped == (d_radius_sign > 0.0)) ? 1.0 : -1.0; \n + x_t = s * root - pt.x * inv_r1; \n + if (discriminant < 0.0 || x_t < 0.0) return vec2(is_swapped ? 0.0 : 1.0, 1.0); \n + } \n + float t = fp + d_radius_sign * x_t; \n + if (is_swapped) t = 1.0 - t; \n + return vec2(t, 1.0); \n + } \n + } \n + \n + vec4 radialGradientColor(vec2 pos) \n + { \n + vec2 res = compute_radial_t(uGradientInfo.centerPos.xy, \n + uGradientInfo.radius.x, \n + uGradientInfo.centerPos.zw, \n + uGradientInfo.radius.y, \n + pos); \n + if (res.y < 0.0) return vec4(0.0, 0.0, 0.0, 0.0); \n + \n + float t = gradientWrap(res.x); \n + vec4 color = gradient(t, res.x, length(pos - uGradientInfo.centerPos.xy)); \n + return vec4(color.rgb * color.a, color.a); \n + } \n +); + +const char* IMAGE_VERT_SHADER = TVG_COMPOSE_SHADER( + uniform float uDepth; \n + layout (location = 0) in vec2 aLocation; \n + layout (location = 1) in vec2 aUV; \n + layout (std140) uniform Matrix { \n + mat3 transform; \n + } uMatrix; \n + out vec2 vUV; \n + \n + void main() \n + { \n + vUV = aUV; \n + vec3 pos = uMatrix.transform * vec3(aLocation, 1.0); \n + gl_Position = vec4(pos.xy, uDepth, 1.0); \n + } \n +); + +const char* IMAGE_FRAG_SHADER = TVG_COMPOSE_SHADER( + layout(std140) uniform ColorInfo { \n + int format; \n + int flipY; \n + int opacity; \n + int dummy; \n + } uColorInfo; \n + uniform sampler2D uTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec2 uv = vUV; \n + if (uColorInfo.flipY == 1) { uv.y = 1.0 - uv.y; } \n + vec4 color = texture(uTexture, uv); \n + vec4 result; \n + if (uColorInfo.format == 0) { /* FMT_ABGR8888 */ \n + result = color; \n + } else if (uColorInfo.format == 1) { /* FMT_ARGB8888 */ \n + result = color.bgra; \n + } else if (uColorInfo.format == 2) { /* FMT_ABGR8888S */ \n + result = vec4(color.rgb * color.a, color.a); \n + } else if (uColorInfo.format == 3) { /* FMT_ARGB8888S */ \n + result = vec4(color.bgr * color.a, color.a); \n + } \n + FragColor = result * float(uColorInfo.opacity) / 255.0; \n + } \n +); + +const char* MASK_VERT_SHADER = TVG_COMPOSE_SHADER( + uniform float uDepth; \n + layout(location = 0) in vec2 aLocation; \n + layout(location = 1) in vec2 aUV; \n + out vec2 vUV; \n + \n + void main() \n + { \n + vUV = aUV; \n + gl_Position = vec4(aLocation, uDepth, 1.0); \n + } \n +); + + +const char* MASK_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + FragColor = srcColor * maskColor.a; \n + } \n +); + +const char* MASK_INV_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + FragColor = srcColor *(1.0 - maskColor.a); \n + } \n +); + +const char* MASK_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + \n + if (maskColor.a > 0.000001) { \n + maskColor = vec4(maskColor.rgb / maskColor.a, maskColor.a); \n + } \n + \n + FragColor = srcColor * dot(maskColor.rgb, vec3(0.2125, 0.7154, 0.0721)) * maskColor.a; \n + } \n +); + +const char* MASK_INV_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + float luma = dot(maskColor.rgb, vec3(0.2125, 0.7154, 0.0721)); \n + FragColor = srcColor * (1.0 - luma); \n + } \n +); + +const char* MASK_ADD_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + vec4 color = srcColor + maskColor * (1.0 - srcColor.a); \n + FragColor = min(color, vec4(1.0, 1.0, 1.0, 1.0)) ; \n + } \n +); + +const char* MASK_SUB_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + float a = srcColor.a - maskColor.a; \n + \n + if (a < 0.0 || srcColor.a == 0.0) { \n + FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n + } else { \n + vec3 srcRgb = srcColor.rgb / srcColor.a; \n + FragColor = vec4(srcRgb * a, a); \n + } \n + } \n +); + +const char* MASK_INTERSECT_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + FragColor = maskColor * srcColor.a; \n + } \n +); + +const char* MASK_DIFF_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + float da = srcColor.a - maskColor.a; \n + if (da == 0.0) { \n + FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n + } else if (da > 0.0) { \n + FragColor = srcColor * da; \n + } else { \n + FragColor = maskColor * (-da); \n + } \n + } \n +); + +const char* MASK_DARKEN_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; \n + float alpha = min(srcColor.a, maskColor.a); \n + FragColor = vec4(srcColor.rgb * alpha, alpha); \n + } \n +); + +const char* MASK_LIGHTEN_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + uniform sampler2D uMaskTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + vec4 srcColor = texture(uSrcTexture, vUV); \n + vec4 maskColor = texture(uMaskTexture, vUV); \n + if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; \n + float alpha = max(srcColor.a, maskColor.a); \n + FragColor = vec4(srcColor.rgb * alpha, alpha); \n + } \n +); + +const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER( + uniform float uDepth; \n + layout(location = 0) in vec2 aLocation; \n + layout(std140) uniform Matrix { \n + mat3 transform; \n + } uMatrix; \n + \n + void main() \n + { \n + vec3 pos = uMatrix.transform * vec3(aLocation, 1.0); \n + gl_Position = vec4(pos.xy, uDepth, 1.0); \n + }); + +const char* STENCIL_FRAG_SHADER = TVG_COMPOSE_SHADER( + out vec4 FragColor; \n + \n + void main() \n + { \n + FragColor = vec4(0.0); \n + } \n +); + +const char* BLIT_VERT_SHADER = TVG_COMPOSE_SHADER( + layout(location = 0) in vec2 aLocation; \n + layout(location = 1) in vec2 aUV; \n + out vec2 vUV; \n + \n + void main() \n + { \n + vUV = aUV; \n + gl_Position = vec4(aLocation, 0.0, 1.0); \n + } +); + +const char* BLIT_FRAG_SHADER = TVG_COMPOSE_SHADER( + uniform sampler2D uSrcTexture; \n + in vec2 vUV; \n + out vec4 FragColor; \n + \n + void main() \n + { \n + FragColor = texture(uSrcTexture, vUV); \n + } +); + +const char* BLEND_SHAPE_SOLID_FRAG_HEADER = R"( +layout(std140) uniform ColorInfo { + vec4 solidColor; +} uColorInfo; + +layout(std140) uniform BlendRegion { + vec4 region; +} uBlendRegion; + +uniform sampler2D uDstTexture; + +out vec4 FragColor; + +vec3 One = vec3(1.0, 1.0, 1.0); +struct FragData { vec3 Sc; float Sa; float So; vec3 Dc; float Da; }; +FragData d; + +void getFragData() { + vec2 uv = (gl_FragCoord.xy - uBlendRegion.region.xy) / uBlendRegion.region.zw; + vec4 colorSrc = uColorInfo.solidColor; + vec4 colorDst = texture(uDstTexture, uv); + d.Sc = colorSrc.rgb; + d.Sa = colorSrc.a; + d.So = 1.0; + d.Dc = colorDst.rgb; + d.Da = colorDst.a; +} + +vec4 postProcess(vec4 R) { return mix(vec4(d.Dc, d.Da), R, d.Sa * d.So); } +)"; + +const char* BLEND_SHAPE_LINEAR_FRAG_HEADER = R"( +layout(std140) uniform BlendRegion { + vec4 region; +} uBlendRegion; + +uniform sampler2D uDstTexture; + +out vec4 FragColor; + +vec3 One = vec3(1.0, 1.0, 1.0); +struct FragData { vec3 Sc; float Sa; float So; vec3 Dc; float Da; }; +FragData d; + +void getFragData() { + vec4 colorSrc = linearGradientColor(vPos); + vec2 uv = (gl_FragCoord.xy - uBlendRegion.region.xy) / uBlendRegion.region.zw; + vec4 colorDst = texture(uDstTexture, uv); + + d.Sc = colorSrc.rgb; + d.Sa = colorSrc.a; + d.So = 1.0; + d.Dc = colorDst.rgb; + d.Da = colorDst.a; + if (d.Sa > 0.0) { d.Sc = d.Sc / d.Sa; } +} + +vec4 postProcess(vec4 R) { return mix(vec4(d.Dc, d.Da), R, d.Sa * d.So); } +)"; + +const char* BLEND_SHAPE_RADIAL_FRAG_HEADER = R"( +layout(std140) uniform BlendRegion { + vec4 region; +} uBlendRegion; + +uniform sampler2D uDstTexture; + +out vec4 FragColor; + +vec3 One = vec3(1.0, 1.0, 1.0); +struct FragData { vec3 Sc; float Sa; float So; vec3 Dc; float Da; }; +FragData d; + +void getFragData() { + vec4 colorSrc = radialGradientColor(vPos); + vec2 uv = (gl_FragCoord.xy - uBlendRegion.region.xy) / uBlendRegion.region.zw; + vec4 colorDst = texture(uDstTexture, uv); + + d.Sc = colorSrc.rgb; + d.Sa = colorSrc.a; + d.So = 1.0; + d.Dc = colorDst.rgb; + d.Da = colorDst.a; + if (d.Sa > 0.0) { d.Sc = d.Sc / d.Sa; } +} + +vec4 postProcess(vec4 R) { return mix(vec4(d.Dc, d.Da), R, d.Sa * d.So); } +)"; + +const char* BLEND_IMAGE_FRAG_HEADER = R"( +layout(std140) uniform BlendRegion { + vec4 region; +} uBlendRegion; + +uniform sampler2D uSrcTexture; +uniform sampler2D uDstTexture; + +in vec2 vUV; +out vec4 FragColor; + +vec3 One = vec3(1.0, 1.0, 1.0); +struct FragData { vec3 Sc; float Sa; float So; vec3 Dc; float Da; }; +FragData d; + +void getFragData() { + // get source data + vec4 colorSrc = texture(uSrcTexture, vUV); + vec2 uvDst = (gl_FragCoord.xy - uBlendRegion.region.xy) / uBlendRegion.region.zw; + vec4 colorDst = texture(uDstTexture, uvDst); + // fill fragment data + d.Sc = colorSrc.rgb; + d.Sa = colorSrc.a; + d.So = 1.0; + d.Dc = colorDst.rgb; + d.Da = colorDst.a; + if (d.Sa > 0.0) { d.Sc = d.Sc / d.Sa; } +} + +vec4 postProcess(vec4 R) { return mix(vec4(d.Dc, d.Da), R, d.Sa * d.So); } +)"; + +const char* BLEND_SCENE_FRAG_HEADER = R"( +layout(std140) uniform ColorInfo { + int format; + int flipY; + int opacity; + int dummy; +} uColorInfo; + +layout(std140) uniform BlendRegion { + vec4 region; +} uBlendRegion; + +uniform sampler2D uSrcTexture; +uniform sampler2D uDstTexture; + +in vec2 vUV; +out vec4 FragColor; + +vec3 One = vec3(1.0, 1.0, 1.0); +struct FragData { vec3 Sc; float Sa; float So; vec3 Dc; float Da; }; +FragData d; + +void getFragData() { + // get source data + vec4 colorSrc = texture(uSrcTexture, vUV); + vec2 uvDst = (gl_FragCoord.xy - uBlendRegion.region.xy) / uBlendRegion.region.zw; + vec4 colorDst = texture(uDstTexture, uvDst); + // fill fragment data + d.Sc = colorSrc.rgb; + d.Sa = colorSrc.a; + d.So = float(uColorInfo.opacity) / 255.0; + d.Dc = colorDst.rgb; + d.Da = colorDst.a; + if (d.Sa > 0.0) {d.Sc = d.Sc / d.Sa; } +} + +vec4 postProcess(vec4 R) { return mix(vec4(d.Dc, d.Da), R, d.Sa * d.So); } +)"; + +const char* BLEND_FRAG_HSL = R"( +// RGB to HSL conversion +vec3 rgbToHsl(vec3 color) { + float minVal = min(color.r, min(color.g, color.b)); + float maxVal = max(color.r, max(color.g, color.b)); + float delta = maxVal - minVal; + + float h = 0.0; + if (delta > 0.0) { + if (maxVal == color.r) { h = (color.g - color.b) / delta - trunc(h / 6.0) * 6.0; } + else if (maxVal == color.g) { h = (color.b - color.r) / delta + 2.0; + } else { h = (color.r - color.g) / delta + 4.0; } + h = h * 60.0; + if (h < 0.0) { h += 360.0; } + } + + float l = (maxVal + minVal) * 0.5; + float s = delta > 0.0 ? delta / (1.0 - abs(2.0 * l - 1.0)) : 0.0; + + return vec3(h, s, l); +} + +// HSL to RGB conversion +vec3 hslToRgb(vec3 color) { + float h = color.x; + float s = color.y; + float l = color.z; + + float C = (1.0 - abs(2.0 * l - 1.0)) * s; + float h_prime = h / 60.0; + float X = C * (1.0 - abs(h_prime - 2.0 * trunc(h_prime / 2.0) - 1.0)); + float m = l - C / 2.0; + + vec3 rgb = vec3(0.0); + if (h_prime >= 0.0 && h_prime < 1.0) { rgb = vec3(C, X, 0.0); } + else if (h_prime >= 1.0 && h_prime < 2.0) { rgb = vec3(X, C, 0.0); } + else if (h_prime >= 2.0 && h_prime < 3.0) { rgb = vec3(0.0, C, X); } + else if (h_prime >= 3.0 && h_prime < 4.0) { rgb = vec3(0.0, X, C); } + else if (h_prime >= 4.0 && h_prime < 5.0) { rgb = vec3(X, 0.0, C); } + else { rgb = vec3(C, 0.0, X); } + + return rgb + vec3(m); +} +)"; + +const char* NORMAL_BLEND_FRAG = R"( +void main() +{ + FragColor = texture(uSrcTexture, vUV); +} +)"; + +const char* MULTIPLY_BLEND_FRAG = R"( +void main() +{ + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + Rc = d.Sc * min(One, d.Dc / d.Da); + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* SCREEN_BLEND_FRAG = R"( +void main() +{ + getFragData(); + vec3 Rc = d.Sc + d.Dc - d.Sc * d.Dc; + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* OVERLAY_BLEND_FRAG = R"( +void main() +{ + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + Rc.r = Dc.r < 0.5 ? min(1.0, 2.0 * d.Sc.r * Dc.r) : 1.0 - min(1.0, 2.0 * (1.0 - d.Sc.r) * (1.0 - Dc.r)); + Rc.g = Dc.g < 0.5 ? min(1.0, 2.0 * d.Sc.g * Dc.g) : 1.0 - min(1.0, 2.0 * (1.0 - d.Sc.g) * (1.0 - Dc.g)); + Rc.b = Dc.b < 0.5 ? min(1.0, 2.0 * d.Sc.b * Dc.b) : 1.0 - min(1.0, 2.0 * (1.0 - d.Sc.b) * (1.0 - Dc.b)); + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* DARKEN_BLEND_FRAG = R"( +void main() +{ + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + Rc = min(d.Sc, min(One, d.Dc / d.Da)); + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* LIGHTEN_BLEND_FRAG = R"( +void main() +{ + getFragData(); + vec3 Rc = max(d.Sc, d.Dc); + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* COLOR_DODGE_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + Rc.r = Dc.r > 0.0 ? d.Sc.r < 1.0 ? min(1.0, Dc.r / (1.0 - d.Sc.r)) : 1.0 : 0.0; + Rc.g = Dc.g > 0.0 ? d.Sc.g < 1.0 ? min(1.0, Dc.g / (1.0 - d.Sc.g)) : 1.0 : 0.0; + Rc.b = Dc.b > 0.0 ? d.Sc.b < 1.0 ? min(1.0, Dc.b / (1.0 - d.Sc.b)) : 1.0 : 0.0; + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* COLOR_BURN_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + Rc.r = d.Sc.r > 0.0 ? 1.0 - min(1.0, (1.0 - Dc.r) / d.Sc.r) : Dc.r < 1.0 ? 0.0 : 1.0; + Rc.g = d.Sc.g > 0.0 ? 1.0 - min(1.0, (1.0 - Dc.g) / d.Sc.g) : Dc.g < 1.0 ? 0.0 : 1.0; + Rc.b = d.Sc.b > 0.0 ? 1.0 - min(1.0, (1.0 - Dc.b) / d.Sc.b) : Dc.b < 1.0 ? 0.0 : 1.0; + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* HARD_LIGHT_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + Rc.r = d.Sc.r < 0.5 ? min(1.0, 2.0 * d.Sc.r * Dc.r) : 1.0 - min(1.0, 2.0 * (1.0 - d.Sc.r) * (1.0 - Dc.r)); + Rc.g = d.Sc.g < 0.5 ? min(1.0, 2.0 * d.Sc.g * Dc.g) : 1.0 - min(1.0, 2.0 * (1.0 - d.Sc.g) * (1.0 - Dc.g)); + Rc.b = d.Sc.b < 0.5 ? min(1.0, 2.0 * d.Sc.b * Dc.b) : 1.0 - min(1.0, 2.0 * (1.0 - d.Sc.b) * (1.0 - Dc.b)); + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* SOFT_LIGHT_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + Rc = min(One, (One - 2.0 * d.Sc) * Dc * Dc + 2.0 * d.Sc * Dc); + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* DIFFERENCE_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = abs(d.Dc - d.Sc); + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* EXCLUSION_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc + d.Dc - 2.0 * d.Sc * d.Dc; + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* HUE_BLEND_FRAG = R"( +void main() +{ + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + vec3 Sc = d.Sc; + + vec3 Shsl = rgbToHsl(Sc); + vec3 Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Shsl.r, Dhsl.g, Dhsl.b)); // sh, ds, dl + + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* SATURATION_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + vec3 Sc = d.Sc; + + vec3 Shsl = rgbToHsl(Sc); + vec3 Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Dhsl.r, Shsl.g, Dhsl.b)); // dh, ss, dl + + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* COLOR_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + vec3 Sc = d.Sc; + + vec3 Shsl = rgbToHsl(Sc); + vec3 Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Shsl.r, Shsl.g, Dhsl.b)); // sh, ss, dl + + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* LUMINOSITY_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = d.Sc; + if (d.Da > 0.0) { + vec3 Dc = min(One, d.Dc / d.Da); + vec3 Sc = d.Sc; + + vec3 Shsl = rgbToHsl(Sc); + vec3 Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Dhsl.r, Dhsl.g, Shsl.b)); // dh, ds, sl + + Rc = mix(d.Sc, Rc, d.Da); + } + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* ADD_BLEND_FRAG = R"( +void main() { + getFragData(); + vec3 Rc = min(One, d.Sc + d.Dc); + FragColor = postProcess(vec4(Rc, 1.0)); +} +)"; + +const char* EFFECT_VERTEX = R"( +layout(location = 0) in vec2 aLocation; +out vec2 vUV; + +void main() +{ + vUV = aLocation * 0.5 + 0.5; + gl_Position = vec4(aLocation, 0.0, 1.0); +} +)"; + +const char* GAUSSIAN_VERTICAL = R"( +uniform sampler2D uSrcTexture; +layout(std140) uniform Gaussian { + float sigma; + float scale; + float extend; + float dummy0; +} uGaussian; + +layout(std140) uniform Viewport { + vec4 vp; +} uViewport; + +in vec2 vUV; +out vec4 FragColor; + +float gaussian(float x, float sigma) { + float exponent = -x * x / (2.0 * sigma * sigma); + return exp(exponent) / (sqrt(2.0 * 3.141592) * sigma); +} + +void main() +{ + vec2 texelSize = 1.0 / vec2(textureSize(uSrcTexture, 0)); + vec4 colorSum = vec4(0.0); + float sigma = uGaussian.sigma * uGaussian.scale; + float weightSum = 0.0; + int radius = int(uGaussian.extend); + + for (int y = -radius; y <= radius; ++y) { + vec2 offset = vec2(0.0, float(y) * texelSize.y); + vec2 coord = vUV + offset; + float pixCoord = uViewport.vp.y - coord.y / texelSize.y; + float weight = pixCoord < uViewport.vp.w ? gaussian(float(y), sigma) : 0.0; + colorSum += texture(uSrcTexture, coord) * weight; + weightSum += weight; + } + + FragColor = colorSum / weightSum; +} +)"; + +const char* GAUSSIAN_HORIZONTAL = R"( +uniform sampler2D uSrcTexture; +layout(std140) uniform Gaussian { + float sigma; + float scale; + float extend; + float dummy0; +} uGaussian; + +layout(std140) uniform Viewport { + vec4 vp; +} uViewport; + +in vec2 vUV; +out vec4 FragColor; + +float gaussian(float x, float sigma) { + float exponent = -x * x / (2.0 * sigma * sigma); + return exp(exponent) / (sqrt(2.0 * 3.141592) * sigma); +} + +void main() +{ + vec2 texelSize = 1.0 / vec2(textureSize(uSrcTexture, 0)); + vec4 colorSum = vec4(0.0); + float sigma = uGaussian.sigma * uGaussian.scale; + float weightSum = 0.0; + int radius = int(uGaussian.extend); + + for (int y = -radius; y <= radius; ++y) { + vec2 offset = vec2(float(y) * texelSize.x, 0.0); + vec2 coord = vUV + offset; + float pixCoord = uViewport.vp.x + coord.x / texelSize.x; + float weight = pixCoord < uViewport.vp.z ? gaussian(float(y), sigma) : 0.0; + colorSum += texture(uSrcTexture, coord) * weight; + weightSum += weight; + } + + FragColor = colorSum / weightSum; +} +)"; + +const char* EFFECT_DROPSHADOW = R"( +uniform sampler2D uSrcTexture; +uniform sampler2D uBlrTexture; +layout(std140) uniform DropShadow { + float sigma; + float scale; + float extend; + float dummy0; + vec4 color; + vec2 offset; +} uDropShadow; + +in vec2 vUV; +out vec4 FragColor; + +void main() +{ + vec2 texelSize = 1.0 / vec2(textureSize(uSrcTexture, 0)); + vec2 offset = uDropShadow.offset * texelSize; + vec4 orig = texture(uSrcTexture, vUV); + vec4 blur = texture(uBlrTexture, vUV + offset); + vec4 shad = uDropShadow.color * blur.a; + FragColor = orig + shad * (1.0 - orig.a); +} +)"; + +const char* EFFECT_FILL = R"( +uniform sampler2D uSrcTexture; +layout(std140) uniform Params { + vec4 params[3]; +} uParams; + +in vec2 vUV; +out vec4 FragColor; + +void main() +{ + vec4 orig = texture(uSrcTexture, vUV); + vec4 fill = uParams.params[0]; + FragColor = fill * orig.a * fill.a; +} +)"; + +const char* EFFECT_TINT = R"( +uniform sampler2D uSrcTexture; +layout(std140) uniform Params { + vec4 params[3]; +} uParams; + +in vec2 vUV; +out vec4 FragColor; + +void main() +{ + vec4 orig = texture(uSrcTexture, vUV); + float luma = dot(orig.rgb, vec3(0.2126, 0.7152, 0.0722)); + FragColor = vec4(mix(orig.rgb, mix(uParams.params[0].rgb, uParams.params[1].rgb, luma), uParams.params[2].r) * orig.a, orig.a); +} +)"; + +const char* EFFECT_TRITONE = R"( +uniform sampler2D uSrcTexture; +layout(std140) uniform Params { + vec4 params[3]; +} uParams; + +in vec2 vUV; +out vec4 FragColor; + +void main() +{ + vec4 orig = texture(uSrcTexture, vUV); + float luma = dot(orig.rgb, vec3(0.2126, 0.7152, 0.0722)); + bool isBright = luma >= 0.5f; + float t = isBright ? (luma - 0.5f) * 2.0f : luma * 2.0f; + vec3 from = isBright ? uParams.params[1].rgb : uParams.params[0].rgb; + vec3 to = isBright ? uParams.params[2].rgb : uParams.params[1].rgb; + vec4 tmp = vec4(mix(from, to, t), 1.0f); + + if (uParams.params[2].a > 0.0f) tmp = mix(tmp, orig, uParams.params[2].a); + FragColor = tmp * orig.a; +} +)"; diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlShaderSrc.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlShaderSrc.h new file mode 100644 index 0000000..3601e00 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlShaderSrc.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_SHADERSRC_H_ +#define _TVG_GL_SHADERSRC_H_ + +extern const char* COLOR_VERT_SHADER; +extern const char* COLOR_FRAG_SHADER; +extern const char* GRADIENT_VERT_SHADER; +extern const char* STR_GRADIENT_FRAG_COMMON_VARIABLES; +extern const char* STR_GRADIENT_FRAG_COMMON_FUNCTIONS; +extern const char* STR_LINEAR_GRADIENT_VARIABLES; +extern const char* STR_LINEAR_GRADIENT_FUNCTIONS; +extern const char* STR_LINEAR_GRADIENT_MAIN; +extern const char* STR_RADIAL_GRADIENT_VARIABLES; +extern const char* STR_RADIAL_GRADIENT_FUNCTIONS; +extern const char* STR_RADIAL_GRADIENT_MAIN; +extern const char* IMAGE_VERT_SHADER; +extern const char* IMAGE_FRAG_SHADER; +extern const char* MASK_VERT_SHADER; +extern const char* MASK_ALPHA_FRAG_SHADER; +extern const char* MASK_INV_ALPHA_FRAG_SHADER; +extern const char* MASK_LUMA_FRAG_SHADER; +extern const char* MASK_INV_LUMA_FRAG_SHADER; +extern const char* MASK_ADD_FRAG_SHADER; +extern const char* MASK_SUB_FRAG_SHADER; +extern const char* MASK_INTERSECT_FRAG_SHADER; +extern const char* MASK_DIFF_FRAG_SHADER; +extern const char* MASK_DARKEN_FRAG_SHADER; +extern const char* MASK_LIGHTEN_FRAG_SHADER; +extern const char* STENCIL_VERT_SHADER; +extern const char* STENCIL_FRAG_SHADER; +extern const char* BLIT_VERT_SHADER; +extern const char* BLIT_FRAG_SHADER; + +extern const char* BLEND_IMAGE_FRAG_HEADER; +extern const char* BLEND_SCENE_FRAG_HEADER; +extern const char* BLEND_SHAPE_SOLID_FRAG_HEADER; +extern const char* BLEND_SHAPE_LINEAR_FRAG_HEADER; +extern const char* BLEND_SHAPE_RADIAL_FRAG_HEADER; + +extern const char* BLEND_FRAG_HSL; + +extern const char* NORMAL_BLEND_FRAG; +extern const char* MULTIPLY_BLEND_FRAG; +extern const char* SCREEN_BLEND_FRAG; +extern const char* OVERLAY_BLEND_FRAG; +extern const char* DARKEN_BLEND_FRAG; +extern const char* LIGHTEN_BLEND_FRAG; +extern const char* COLOR_DODGE_BLEND_FRAG; +extern const char* COLOR_BURN_BLEND_FRAG; +extern const char* HARD_LIGHT_BLEND_FRAG; +extern const char* SOFT_LIGHT_BLEND_FRAG; +extern const char* DIFFERENCE_BLEND_FRAG; +extern const char* EXCLUSION_BLEND_FRAG; +extern const char* HUE_BLEND_FRAG; +extern const char* SATURATION_BLEND_FRAG; +extern const char* COLOR_BLEND_FRAG; +extern const char* LUMINOSITY_BLEND_FRAG; +extern const char* ADD_BLEND_FRAG; + +extern const char* EFFECT_VERTEX; +extern const char* GAUSSIAN_VERTICAL; +extern const char* GAUSSIAN_HORIZONTAL; +extern const char* EFFECT_DROPSHADOW; +extern const char* EFFECT_FILL; +extern const char* EFFECT_TINT; +extern const char* EFFECT_TRITONE; + +#endif /* _TVG_GL_SHADERSRC_H_ */ diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlTessellator.cpp b/components/thorvg-main/src/renderer/gl_engine/tvgGlTessellator.cpp new file mode 100644 index 0000000..dfffd2d --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlTessellator.cpp @@ -0,0 +1,545 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgGlTessellator.h" + +namespace tvg +{ + +static uint32_t _pushVertex(Array& array, float x, float y) +{ + array.push(x); + array.push(y); + return (array.count - 2) / 2; +} + + +Stroker::Stroker(GlGeometryBuffer* buffer, float width, StrokeCap cap, StrokeJoin join) : mBuffer(buffer), mWidth(width), mCap(cap), mJoin(join) +{ +} + + +void Stroker::run(const RenderShape& rshape, const RenderPath& path, const Matrix& m) +{ + mMiterLimit = rshape.strokeMiterlimit(); + + RenderPath dashed; + if (rshape.strokeDash(dashed)) run(dashed, m); + else run(path, m); +} + + +RenderRegion Stroker::bounds() const +{ + return {{int32_t(floor(mLeftTop.x)), int32_t(floor(mLeftTop.y))}, {int32_t(ceil(mRightBottom.x)), int32_t(ceil(mRightBottom.y))}}; +} + + +void Stroker::run(const RenderPath& path, const Matrix& m) +{ + mBuffer->vertex.reserve(path.pts.count * 4 + 16); + mBuffer->index.reserve(path.pts.count * 3); + mScale = tvg::scaling(m); + + auto validStrokeCap = false; + auto pts = path.pts.data; + + ARRAY_FOREACH(cmd, path.cmds) { + switch (*cmd) { + case PathCommand::MoveTo: { + if (validStrokeCap) { // check this, so we can skip if path only contains move instruction + cap(); + validStrokeCap = false; + } + mState.firstPt = *pts; + mState.firstPtDir = {0.0f, 0.0f}; + mState.prevPt = *pts; + mState.prevPtDir = {0.0f, 0.0f}; + pts++; + validStrokeCap = false; + } break; + case PathCommand::LineTo: { + validStrokeCap = true; + lineTo(*pts); + pts++; + } break; + case PathCommand::CubicTo: { + validStrokeCap = true; + cubicTo(pts[0], pts[1], pts[2], m); + pts += 3; + } break; + case PathCommand::Close: { + close(); + validStrokeCap = false; + } break; + default: + break; + } + } + if (validStrokeCap) cap(); +} + + +void Stroker::cap() +{ + if (mCap == StrokeCap::Butt) return; + + if (mCap == StrokeCap::Square) { + if (mState.firstPt == mState.prevPt) squarePoint(mState.firstPt); + else { + square(mState.firstPt, {-mState.firstPtDir.x, -mState.firstPtDir.y}); + square(mState.prevPt, mState.prevPtDir); + } + } else if (mCap == StrokeCap::Round) { + if (mState.firstPt == mState.prevPt) roundPoint(mState.firstPt); + else { + round(mState.firstPt, {-mState.firstPtDir.x, -mState.firstPtDir.y}); + round(mState.prevPt, mState.prevPtDir); + } + } +} + + +void Stroker::lineTo(const Point& curr) +{ + auto dir = (curr - mState.prevPt); + normalize(dir); + + if (dir.x == 0.f && dir.y == 0.f) return; //same point + + auto normal = Point{-dir.y, dir.x}; + auto a = mState.prevPt + normal * radius(); + auto b = mState.prevPt - normal * radius(); + auto c = curr + normal * radius(); + auto d = curr - normal * radius(); + + auto ia = _pushVertex(mBuffer->vertex, a.x, a.y); + auto ib = _pushVertex(mBuffer->vertex, b.x, b.y); + auto ic = _pushVertex(mBuffer->vertex, c.x, c.y); + auto id = _pushVertex(mBuffer->vertex, d.x, d.y); + + /** + * a --------- c + * | | + * | | + * b-----------d + */ + + mBuffer->index.push(ia); + mBuffer->index.push(ib); + mBuffer->index.push(ic); + + mBuffer->index.push(ib); + mBuffer->index.push(id); + mBuffer->index.push(ic); + + if (mState.prevPt == mState.firstPt) { + // first point after moveTo + mState.prevPt = curr; + mState.prevPtDir = dir; + mState.firstPtDir = dir; + } else { + join(dir); + mState.prevPtDir = dir; + mState.prevPt = curr; + } + + if (ia == 0) { + mRightBottom.x = mLeftTop.x = curr.x; + mRightBottom.y = mLeftTop.y = curr.y; + } + + mLeftTop.x = std::min(mLeftTop.x, std::min(std::min(a.x, b.x), std::min(c.x, d.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(std::min(a.y, b.y), std::min(c.y, d.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(std::max(a.x, b.x), std::max(c.x, d.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(std::max(a.y, b.y), std::max(c.y, d.y))); +} + + +void Stroker::cubicTo(const Point& cnt1, const Point& cnt2, const Point& end, const Matrix& m) +{ + Bezier curve{ mState.prevPt, cnt1, cnt2, end }; + + auto count = (curve * m).segments(); + auto step = 1.f / count; + + for (uint32_t i = 0; i <= count; i++) { + lineTo(curve.at(step * i)); + } +} + + +void Stroker::close() +{ + if (length(mState.prevPt - mState.firstPt) > 0.015625f) { + lineTo(mState.firstPt); + } + + // join firstPt with prevPt + join(mState.firstPtDir); +} + + +void Stroker::join(const Point& dir) +{ + auto orient = orientation(mState.prevPt - mState.prevPtDir, mState.prevPt, mState.prevPt + dir); + + if (orient == Orientation::Linear) { + if (mState.prevPtDir == dir) return; // check is same direction + if (mJoin != StrokeJoin::Round) return; // opposite direction + + auto normal = Point{-dir.y, dir.x}; + auto p1 = mState.prevPt + normal * radius(); + auto p2 = mState.prevPt - normal * radius(); + auto oc = mState.prevPt + dir * radius(); + + round(p1, oc, mState.prevPt); + round(oc, p2, mState.prevPt); + + } else { + auto normal = Point{-dir.y, dir.x}; + auto prevNormal = Point{-mState.prevPtDir.y, mState.prevPtDir.x}; + Point prevJoin, currJoin; + + if (orient == Orientation::CounterClockwise) { + prevJoin = mState.prevPt + prevNormal * radius(); + currJoin = mState.prevPt + normal * radius(); + } else { + prevJoin = mState.prevPt - prevNormal * radius(); + currJoin = mState.prevPt - normal * radius(); + } + + if (mJoin == StrokeJoin::Miter) miter(prevJoin, currJoin, mState.prevPt); + else if (mJoin == StrokeJoin::Bevel) bevel(prevJoin, currJoin, mState.prevPt); + else round(prevJoin, currJoin, mState.prevPt); + } +} + + +void Stroker::round(const Point &prev, const Point& curr, const Point& center) +{ + auto orient = orientation(prev, center, curr); + if (orient == Orientation::Linear) return; + + mLeftTop.x = std::min(mLeftTop.x, std::min(center.x, std::min(prev.x, curr.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(center.y, std::min(prev.y, curr.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(center.x, std::max(prev.x, curr.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(center.y, std::max(prev.y, curr.y))); + + auto startAngle = tvg::atan2(prev.y - center.y, prev.x - center.x); + auto endAngle = tvg::atan2(curr.y - center.y, curr.x - center.x); + + if (orient == Orientation::Clockwise) { + if (endAngle > startAngle) endAngle -= 2 * MATH_PI; + } else { + if (endAngle < startAngle) endAngle += 2 * MATH_PI; + } + + auto arcAngle = endAngle - startAngle; + auto count = arcSegmentsCnt(arcAngle, radius() * mScale); + + auto c = _pushVertex(mBuffer->vertex, center.x, center.y); + auto pi = _pushVertex(mBuffer->vertex, prev.x, prev.y); + auto step = (endAngle - startAngle) / (count - 1); + + for (uint32_t i = 1; i < static_cast(count); i++) { + auto angle = startAngle + step * i; + Point out = {center.x + cos(angle) * radius(), center.y + sin(angle) * radius()}; + auto oi = _pushVertex(mBuffer->vertex, out.x, out.y); + + mBuffer->index.push(c); + mBuffer->index.push(pi); + mBuffer->index.push(oi); + + pi = oi; + + mLeftTop.x = std::min(mLeftTop.x, out.x); + mLeftTop.y = std::min(mLeftTop.y, out.y); + mRightBottom.x = std::max(mRightBottom.x, out.x); + mRightBottom.y = std::max(mRightBottom.y, out.y); + } +} + + +void Stroker::roundPoint(const Point &p) +{ + auto count = arcSegmentsCnt(2.0f * MATH_PI, radius() * mScale); + auto c = _pushVertex(mBuffer->vertex, p.x, p.y); + auto step = 2.0f * MATH_PI / (count - 1); + + for (uint32_t i = 1; i <= static_cast(count); i++) { + float angle = i * step; + Point dir = {cos(angle), sin(angle)}; + Point out = p + dir * radius(); + auto oi = _pushVertex(mBuffer->vertex, out.x, out.y); + + if (oi > 1) { + mBuffer->index.push(c); + mBuffer->index.push(oi); + mBuffer->index.push(oi - 1); + } + } + + mLeftTop.x = std::min(mLeftTop.x, p.x - radius()); + mLeftTop.y = std::min(mLeftTop.y, p.y - radius()); + mRightBottom.x = std::max(mRightBottom.x, p.x + radius()); + mRightBottom.y = std::max(mRightBottom.y, p.y + radius()); +} + + +void Stroker::miter(const Point& prev, const Point& curr, const Point& center) +{ + auto pp1 = prev - center; + auto pp2 = curr - center; + auto out = pp1 + pp2; + auto k = 2.f * radius() * radius() / (out.x * out.x + out.y * out.y); + auto pe = out * k; + + if (length(pe) >= mMiterLimit * radius()) { + bevel(prev, curr, center); + return; + } + + auto join = center + pe; + auto c = _pushVertex(mBuffer->vertex, center.x, center.y); + auto cp1 = _pushVertex(mBuffer->vertex, prev.x, prev.y); + auto cp2 = _pushVertex(mBuffer->vertex, curr.x, curr.y); + auto e = _pushVertex(mBuffer->vertex, join.x, join.y); + + mBuffer->index.push(c); + mBuffer->index.push(cp1); + mBuffer->index.push(e); + + mBuffer->index.push(e); + mBuffer->index.push(cp2); + mBuffer->index.push(c); + + mLeftTop.x = std::min(mLeftTop.x, join.x); + mLeftTop.y = std::min(mLeftTop.y, join.y); + + mRightBottom.x = std::max(mRightBottom.x, join.x); + mRightBottom.y = std::max(mRightBottom.y, join.y); +} + + +void Stroker::bevel(const Point& prev, const Point& curr, const Point& center) +{ + auto a = _pushVertex(mBuffer->vertex, prev.x, prev.y); + auto b = _pushVertex(mBuffer->vertex, curr.x, curr.y); + auto c = _pushVertex(mBuffer->vertex, center.x, center.y); + + mBuffer->index.push(a); + mBuffer->index.push(b); + mBuffer->index.push(c); +} + + +void Stroker::square(const Point& p, const Point& outDir) +{ + auto normal = Point{-outDir.y, outDir.x}; + + auto a = p + normal * radius(); + auto b = p - normal * radius(); + auto c = a + outDir * radius(); + auto d = b + outDir * radius(); + + auto ai = _pushVertex(mBuffer->vertex, a.x, a.y); + auto bi = _pushVertex(mBuffer->vertex, b.x, b.y); + auto ci = _pushVertex(mBuffer->vertex, c.x, c.y); + auto di = _pushVertex(mBuffer->vertex, d.x, d.y); + + mBuffer->index.push(ai); + mBuffer->index.push(bi); + mBuffer->index.push(ci); + + mBuffer->index.push(ci); + mBuffer->index.push(bi); + mBuffer->index.push(di); + + mLeftTop.x = std::min(mLeftTop.x, std::min(std::min(a.x, b.x), std::min(c.x, d.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(std::min(a.y, b.y), std::min(c.y, d.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(std::max(a.x, b.x), std::max(c.x, d.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(std::max(a.y, b.y), std::max(c.y, d.y))); +} + + +void Stroker::squarePoint(const Point& p) +{ + auto offsetX = Point{radius(), 0.0f}; + auto offsetY = Point{0.0f, radius()}; + + auto a = p + offsetX + offsetY; + auto b = p - offsetX + offsetY; + auto c = p - offsetX - offsetY; + auto d = p + offsetX - offsetY; + + auto ai = _pushVertex(mBuffer->vertex, a.x, a.y); + auto bi = _pushVertex(mBuffer->vertex, b.x, b.y); + auto ci = _pushVertex(mBuffer->vertex, c.x, c.y); + auto di = _pushVertex(mBuffer->vertex, d.x, d.y); + + mBuffer->index.push(ai); + mBuffer->index.push(bi); + mBuffer->index.push(ci); + + mBuffer->index.push(ci); + mBuffer->index.push(di); + mBuffer->index.push(ai); + + mLeftTop.x = std::min(mLeftTop.x, std::min(std::min(a.x, b.x), std::min(c.x, d.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(std::min(a.y, b.y), std::min(c.y, d.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(std::max(a.x, b.x), std::max(c.x, d.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(std::max(a.y, b.y), std::max(c.y, d.y))); +} + + +void Stroker::round(const Point& p, const Point& outDir) +{ + auto normal = Point{-outDir.y, outDir.x}; + auto a = p + normal * radius(); + auto b = p - normal * radius(); + auto c = p + outDir * radius(); + + round(a, c, p); + round(c, b, p); +} + + +BWTessellator::BWTessellator(GlGeometryBuffer* buffer): mBuffer(buffer) +{ +} + + +void BWTessellator::tessellate(const RenderPath& path, const Matrix& matrix) +{ + auto cmds = path.cmds.data; + auto cmdCnt = path.cmds.count; + auto pts = path.pts.data; + auto ptsCnt = path.pts.count; + + if (ptsCnt <= 2) return; + + uint32_t firstIndex = 0; + uint32_t prevIndex = 0; + + mBuffer->vertex.reserve(ptsCnt * 2); + mBuffer->index.reserve((ptsCnt - 2) * 3); + + auto updateConvexity = [&](const Point& edge) { + if (!convex) return; + if (prevEdge.x == 0.0f && prevEdge.y == 0.0f) { prevEdge = edge; return; } + auto c = cross(prevEdge, edge); + if (zero(c)) { prevEdge = edge; return; } + auto sign = (c > 0) ? 1 : -1; + if (winding == 0) winding = sign; // The default winding is CCW, but it might be otherwise once we support unordered points. + else if (sign != winding) convex = false; + prevEdge = edge; + }; + + for (uint32_t i = 0; i < cmdCnt; i++) { + switch(cmds[i]) { + case PathCommand::MoveTo: { + firstIndex = pushVertex(pts->x, pts->y); + firstPt = prevPt = *pts; + prevEdge = {}; + prevIndex = 0; + pts++; + } break; + case PathCommand::LineTo: { + if (prevIndex == 0) { + prevIndex = pushVertex(pts->x, pts->y); + prevEdge = *pts - prevPt; + prevPt = *pts++; + } else { + updateConvexity(*pts - prevPt); + auto currIndex = pushVertex(pts->x, pts->y); + pushTriangle(firstIndex, prevIndex, currIndex); + prevIndex = currIndex; + prevPt = *pts++; + } + } break; + case PathCommand::CubicTo: { + Bezier curve{pts[-1], pts[0], pts[1], pts[2]}; + if (convex) { + auto e1 = curve.ctrl1 - curve.start; + auto e2 = curve.ctrl2 - curve.ctrl1; + auto e3 = curve.end - curve.ctrl2; + if (prevIndex != 0) updateConvexity(e1); + else prevEdge = e1; + updateConvexity(e2); + updateConvexity(e3); + } + + auto stepCount = (curve * matrix).segments(); + if (stepCount <= 1) stepCount = 2; + float step = 1.f / stepCount; + + for (uint32_t s = 1; s <= static_cast(stepCount); s++) { + auto pt = curve.at(step * s); + auto currIndex = pushVertex(pt.x, pt.y); + if (prevIndex == 0) { prevIndex = currIndex; continue; } + pushTriangle(firstIndex, prevIndex, currIndex); + prevIndex = currIndex; + } + prevPt = curve.end; + pts += 3; + } break; + case PathCommand::Close: { + if (convex && prevIndex != 0) { + updateConvexity(firstPt - prevPt); + if (convex && winding != 0) { + auto& v = mBuffer->vertex; + auto secondPt = Point{v[firstIndex * 2 + 2], v[firstIndex * 2 + 3]}; + updateConvexity(secondPt - firstPt); + } + } + } break; + default: + break; + } + } +} + + +RenderRegion BWTessellator::bounds() const +{ + return {{int32_t(floor(bbox.min.x)), int32_t(floor(bbox.min.y))}, {int32_t(ceil(bbox.max.x)), int32_t(ceil(bbox.max.y))}}; +} + + +uint32_t BWTessellator::pushVertex(float x, float y) +{ + auto index = _pushVertex(mBuffer->vertex, x, y); + if (index == 0) bbox.max = bbox.min = {x, y}; + else bbox = {{std::min(bbox.min.x, x), std::min(bbox.min.y, y)}, {std::max(bbox.max.x, x), std::max(bbox.max.y, y)}}; + return index; +} + + +void BWTessellator::pushTriangle(uint32_t a, uint32_t b, uint32_t c) +{ + mBuffer->index.push(a); + mBuffer->index.push(b); + mBuffer->index.push(c); +} + +} // namespace tvg diff --git a/components/thorvg-main/src/renderer/gl_engine/tvgGlTessellator.h b/components/thorvg-main/src/renderer/gl_engine/tvgGlTessellator.h new file mode 100644 index 0000000..0f1bef3 --- /dev/null +++ b/components/thorvg-main/src/renderer/gl_engine/tvgGlTessellator.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GL_TESSELLATOR_H_ +#define _TVG_GL_TESSELLATOR_H_ + +#include "tvgGlCommon.h" + +namespace tvg +{ + +class Stroker +{ + struct State + { + Point firstPt; + Point firstPtDir; + Point prevPt; + Point prevPtDir; + }; +public: + Stroker(GlGeometryBuffer* buffer, float strokeWidth, StrokeCap cap, StrokeJoin join); + void run(const RenderShape& rshape, const RenderPath& path, const Matrix& m); + void run(const RenderPath& path, const Matrix& m); + RenderRegion bounds() const; + +private: + + float radius() const + { + return mWidth * 0.5f; + } + + void cap(); + void lineTo(const Point& curr); + void cubicTo(const Point& cnt1, const Point& cnt2, const Point& end, const Matrix& m); + void close(); + void join(const Point& dir); + void round(const Point& prev, const Point& curr, const Point& center); + void miter(const Point& prev, const Point& curr, const Point& center); + void bevel(const Point& prev, const Point& curr, const Point& center); + void square(const Point& p, const Point& outDir); + void squarePoint(const Point& p); + void round(const Point& p, const Point& outDir); + void roundPoint(const Point& p); + + GlGeometryBuffer* mBuffer; + float mWidth = 0.0f; + float mMiterLimit = 4.f; + StrokeCap mCap = StrokeCap::Square; + StrokeJoin mJoin = StrokeJoin::Bevel; + State mState = {}; + Point mLeftTop = {0.0f, 0.0f}; + Point mRightBottom = {0.0f, 0.0f}; + float mScale; +}; + +class BWTessellator +{ +public: + BWTessellator(GlGeometryBuffer* buffer); + void tessellate(const RenderPath& path, const Matrix& matrix); + RenderRegion bounds() const; + bool convex = true; + +private: + uint32_t pushVertex(float x, float y); + void pushTriangle(uint32_t a, uint32_t b, uint32_t c); + + GlGeometryBuffer* mBuffer; + BBox bbox = {}; + Point firstPt = {}; + Point prevPt = {}; + Point prevEdge = {}; + int8_t winding = -1; //0: unknown, 1: CW, -1: CCW +}; + +} // namespace tvg + +#endif /* _TVG_GL_TESSELLATOR_H_ */ diff --git a/components/thorvg-main/src/renderer/meson.build b/components/thorvg-main/src/renderer/meson.build new file mode 100644 index 0000000..e839f98 --- /dev/null +++ b/components/thorvg-main/src/renderer/meson.build @@ -0,0 +1,50 @@ +engine_dep = [] + +if sw_engine + subdir('sw_engine') +endif + +if gl_engine + subdir('gl_engine') +endif + +if wg_engine + subdir('wg_engine') +endif + +source_file = [ + 'tvgAnimation.h', + 'tvgCanvas.h', + 'tvgFill.h', + 'tvgFrameModule.h', + 'tvgLoader.h', + 'tvgLoadModule.h', + 'tvgPicture.h', + 'tvgRender.h', + 'tvgIteratorAccessor.h', + 'tvgSaveModule.h', + 'tvgScene.h', + 'tvgShape.h', + 'tvgTaskScheduler.h', + 'tvgText.h', + 'tvgAccessor.cpp', + 'tvgAnimation.cpp', + 'tvgCanvas.cpp', + 'tvgFill.cpp', + 'tvgInitializer.cpp', + 'tvgLoader.cpp', + 'tvgPaint.cpp', + 'tvgPicture.cpp', + 'tvgRender.cpp', + 'tvgSaver.cpp', + 'tvgScene.cpp', + 'tvgShape.cpp', + 'tvgTaskScheduler.cpp', + 'tvgText.cpp' +] + +common_dep = declare_dependency( + dependencies : engine_dep, + include_directories : include_directories('.'), + sources : source_file +) diff --git a/components/thorvg-main/src/renderer/sw_engine/meson.build b/components/thorvg-main/src/renderer/sw_engine/meson.build new file mode 100644 index 0000000..bde9970 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/meson.build @@ -0,0 +1,30 @@ +source_file = [ + 'tvgSwCommon.h', + 'tvgSwRasterC.h', + 'tvgSwRasterAvx.h', + 'tvgSwRasterNeon.h', + 'tvgSwRasterTexmap.h', + 'tvgSwFill.cpp', + 'tvgSwImage.cpp', + 'tvgSwMath.cpp', + 'tvgSwMemPool.cpp', + 'tvgSwPostEffect.cpp', + 'tvgSwRenderer.h', + 'tvgSwRaster.cpp', + 'tvgSwRenderer.cpp', + 'tvgSwRle.cpp', + 'tvgSwShape.cpp', + 'tvgSwStroke.cpp', +] + +omp_dep = [] + +if openmp + omp_dep = dependency('openmp', required: false) +endif + +engine_dep += [declare_dependency( + include_directories : include_directories('.'), + dependencies : omp_dep, + sources : source_file +)] \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwCommon.h b/components/thorvg-main/src/renderer/sw_engine/tvgSwCommon.h new file mode 100644 index 0000000..fe0049c --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwCommon.h @@ -0,0 +1,737 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SW_COMMON_H_ +#define _TVG_SW_COMMON_H_ + +#include +#include "tvgCommon.h" +#include "tvgMath.h" +#include "tvgColor.h" +#include "tvgRender.h" + +#define SW_CURVE_TYPE_POINT 0 +#define SW_CURVE_TYPE_CUBIC 1 +#define SW_ANGLE_PI (180L << 16) +#define SW_ANGLE_2PI (SW_ANGLE_PI << 1) +#define SW_ANGLE_PI2 (SW_ANGLE_PI >> 1) +#define SW_COLOR_TABLE 1024 + +static inline float TO_FLOAT(int32_t val) +{ + return static_cast(val) / 64.0f; +} + +struct SwPoint +{ + int32_t x, y; + + SwPoint& operator-=(const SwPoint& rhs) + { + x -= rhs.x; + y -= rhs.y; + return *this; + } + + SwPoint& operator+=(const SwPoint& rhs) + { + x += rhs.x; + y += rhs.y; + return *this; + } + + SwPoint operator+(const SwPoint& rhs) const + { + return {x + rhs.x, y + rhs.y}; + } + + SwPoint operator-(const SwPoint& rhs) const + { + return {x - rhs.x, y - rhs.y}; + } + + bool operator==(const SwPoint& rhs) const + { + return (x == rhs.x && y == rhs.y); + } + + bool operator!=(const SwPoint& rhs) const + { + return (x != rhs.x || y != rhs.y); + } + + bool zero() const + { + if (x == 0 && y == 0) return true; + else return false; + } + + bool tiny() const + { + //2 is epsilon... + if (abs(x) < 2 && abs(y) < 2) return true; + else return false; + } + + Point toPoint() const + { + return {TO_FLOAT(x), TO_FLOAT(y)}; + } +}; + +struct SwSize +{ + int32_t w, h; +}; + +struct SwOutline +{ + Array pts; //the outline's points + Array cntrs; //the contour end points + Array types; //curve type + Array closed; //opened or closed path? + FillRule fillRule; +}; + +struct SwSpan +{ + uint16_t x, y; + uint16_t len; + uint8_t coverage; + + bool fetch(const RenderRegion& bbox, int32_t& x, int32_t& len) const + { + x = std::max((int32_t)this->x, bbox.min.x); + len = std::min((int32_t)(this->x + this->len), bbox.max.x) - x; + return (len > 0) ? true : false; + } +}; + +struct SwRle +{ + Array spans; + + const SwSpan* fetch(const RenderRegion& bbox, const SwSpan** end) const + { + return fetch(bbox.min.y, bbox.max.y - 1, end); + } + + const SwSpan* fetch(int32_t min, uint32_t max, const SwSpan** end) const + { + const SwSpan* begin; + + if (min <= spans.first().y) { + begin = spans.begin(); + } else { + auto comp = [](const SwSpan& span, int y) { return span.y < y; }; + begin = lower_bound(spans.begin(), spans.end(), min, comp); + } + if (end) { + if (max >= spans.last().y) { + *end = spans.end(); + } else { + auto comp = [](int y, const SwSpan& span) { return y < span.y; }; + *end = upper_bound(spans.begin(), spans.end(), max, comp); + } + } + return begin; + } + + bool invalid() const { return spans.empty(); } + bool valid() const { return !invalid(); } + uint32_t size() const { return spans.count; } + SwSpan* data() const { return spans.data; } +}; + +using Area = long; + +struct SwCell +{ + int32_t x; + int32_t cover; + Area area; + SwCell *next; +}; + +struct SwFill +{ + struct SwLinear { + float dx, dy; + float offset; + }; + + struct SwRadial { + float a11, a12, a13; + float a21, a22, a23; + float fx, fy, fr; + float dx, dy, dr; + float invA, a; + }; + + union { + SwLinear linear; + SwRadial radial; + }; + + uint32_t ctable[SW_COLOR_TABLE]; + FillSpread spread; + + bool solid = false; //solid color fill with the last color from colorStops + bool translucent; +}; + +struct SwStrokeBorder +{ + Array pts; + uint8_t* tags = nullptr; + int32_t start = 0; //index of current sub-path start point + bool movable = false; //true: for ends of lineto borders + + ~SwStrokeBorder() + { + tvg::free(tags); + } +}; + +struct SwStroke +{ + int64_t angleIn; + int64_t angleOut; + SwPoint center; + int64_t lineLength; + int64_t subPathAngle; + SwPoint ptStartSubPath; + int64_t subPathLineLength; + int64_t width; + int64_t miterlimit; + SwFill* fill = nullptr; + SwStrokeBorder* borders[2]; + float sx, sy; + StrokeCap cap; + StrokeJoin join; + StrokeJoin joinSaved; + bool firstPt; + bool closedSubPath; + bool handleWideStrokes; +}; + +struct SwDashStroke +{ + SwOutline* outline = nullptr; + float curLen = 0; + int32_t curIdx = 0; + Point ptStart = {0, 0}; + Point ptCur = {0, 0}; + float* pattern = nullptr; + uint32_t cnt = 0; + bool curOpGap = false; + bool move = true; +}; + +struct SwShape +{ + SwOutline* outline = nullptr; + SwStroke* stroke = nullptr; + SwFill* fill = nullptr; + SwRle* rle = nullptr; + SwRle* strokeRle = nullptr; + RenderRegion bbox; //Keep it boundary without stroke region. Using for optimal filling. + bool fastTrack = false; //Fast Track: axis-aligned rectangle without any clips? +}; + +struct SwImage +{ + SwOutline* outline = nullptr; + SwRle* rle = nullptr; + union { + pixel_t* data; //system based data pointer + uint32_t* buf32; //for explicit 32bits channels + uint8_t* buf8; //for explicit 8bits grayscale + }; + uint32_t w, h, stride; + int32_t ox = 0; //offset x + int32_t oy = 0; //offset y + float scale; + uint8_t channelSize; + + bool direct = false; //draw image directly (with offset) + bool scaled = false; //draw scaled image +}; + +typedef uint8_t(*SwMask)(uint8_t s, uint8_t d, uint8_t a); //src, dst, alpha +typedef uint32_t(*SwBlender)(uint32_t s, uint32_t d); //src, dst +typedef uint32_t(*SwBlenderA)(uint32_t s, uint32_t d, uint8_t a); //src, dst, alpha +typedef uint32_t(*SwJoin)(uint8_t r, uint8_t g, uint8_t b, uint8_t a); //color channel join +typedef uint8_t(*SwAlpha)(uint8_t*); //blending alpha + +struct SwCompositor; + +struct SwSurface : RenderSurface +{ + SwJoin join; + SwAlpha alphas[4]; //Alpha:2, InvAlpha:3, Luma:4, InvLuma:5 + SwBlender blender = nullptr; //blender (optional) + SwCompositor* compositor = nullptr; //compositor (optional) + BlendMethod blendMethod = BlendMethod::Normal; + + SwAlpha alpha(MaskMethod method) + { + auto idx = (int)(method) - 1; //-1 for None + return alphas[idx > 3 ? 0 : idx]; //CompositeMethod has only four Matting methods. + } + + SwSurface() + { + } + + SwSurface(const SwSurface* rhs) : RenderSurface(rhs) + { + join = rhs->join; + memcpy(alphas, rhs->alphas, sizeof(alphas)); + blender = rhs->blender; + compositor = rhs->compositor; + blendMethod = rhs->blendMethod; + } +}; + +struct SwCompositor : RenderCompositor +{ + SwSurface* recoverSfc; //Recover surface when composition is started + SwCompositor* recoverCmp; //Recover compositor when composition is done + SwImage image; + RenderRegion bbox; + bool valid; +}; + +struct SwCellPool +{ + #define DEFAULT_POOL_SIZE 16368 + + uint32_t size; + SwCell* buffer; + + SwCellPool() : size(DEFAULT_POOL_SIZE), buffer(tvg::malloc(DEFAULT_POOL_SIZE)) {} + ~SwCellPool() { tvg::free(buffer); } +}; + +struct SwMpool +{ + SwOutline* outline; + SwStrokeBorder* leftBorder; + SwStrokeBorder* rightBorder; + SwCellPool* cellPool; + unsigned allocSize; +}; + +static inline int32_t TO_SWCOORD(float val) +{ + return int32_t(val * 64.0f); +} + +static inline uint32_t JOIN(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3) +{ + return (c0 << 24 | c1 << 16 | c2 << 8 | c3); +} + +static inline uint32_t ALPHA_BLEND(uint32_t c, uint32_t a) +{ + ++a; + return (((((c >> 8) & 0x00ff00ff) * a) & 0xff00ff00) + ((((c & 0x00ff00ff) * a) >> 8) & 0x00ff00ff)); +} + +static inline uint32_t INTERPOLATE(uint32_t s, uint32_t d, uint8_t a) +{ + return (((((((s >> 8) & 0xff00ff) - ((d >> 8) & 0xff00ff)) * a) + (d & 0xff00ff00)) & 0xff00ff00) + ((((((s & 0xff00ff) - (d & 0xff00ff)) * a) >> 8) + (d & 0xff00ff)) & 0xff00ff)); +} + +static inline uint8_t INTERPOLATE8(uint8_t s, uint8_t d, uint8_t a) +{ + return (((s) * (a) + 0xff) >> 8) + (((d) * ~(a) + 0xff) >> 8); +} + +static inline int32_t HALF_STROKE(float width) +{ + return TO_SWCOORD(width * 0.5f); +} + +static inline uint8_t A(uint32_t c) +{ + return ((c) >> 24); +} + +static inline uint8_t IA(uint32_t c) +{ + return (~(c) >> 24); +} + +static inline uint8_t C1(uint32_t c) +{ + return ((c) >> 16); +} + +static inline uint8_t C2(uint32_t c) +{ + return ((c) >> 8); +} + +static inline uint8_t C3(uint32_t c) +{ + return (c); +} + +static inline uint32_t PREMULTIPLY(uint32_t c, uint8_t a) +{ + return (c & 0xff000000) + ((((c >> 8) & 0xff) * a) & 0xff00) + ((((c & 0x00ff00ff) * a) >> 8) & 0x00ff00ff); +} + +static inline RenderColor BLEND_UPRE(uint32_t c) +{ + RenderColor o = {C1(c), C2(c), C3(c), A(c)}; + if (o.a > 0 && o.a < 255) { + o.r = std::min(o.r * 255u / o.a, 255u); + o.g = std::min(o.g * 255u / o.a, 255u); + o.b = std::min(o.b * 255u / o.a, 255u); + } + return o; +} + +static inline uint32_t BLEND_PRE(uint32_t c1, uint32_t c2, uint8_t a) +{ + if (a == 255) return c1; + return ALPHA_BLEND(c1, a) + ALPHA_BLEND(c2, 255 - a); +} + +static inline uint32_t opBlendInterp(uint32_t s, uint32_t d, uint8_t a) +{ + return INTERPOLATE(s, d, a); +} + +static inline uint32_t opBlendNormal(uint32_t s, uint32_t d, uint8_t a) +{ + auto t = ALPHA_BLEND(s, a); + return t + ALPHA_BLEND(d, IA(t)); +} + +static inline uint32_t opBlendPreNormal(uint32_t s, uint32_t d, TVG_UNUSED uint8_t a) +{ + return s + ALPHA_BLEND(d, IA(s)); +} + +static inline uint32_t opBlendSrcOver(uint32_t s, TVG_UNUSED uint32_t d, TVG_UNUSED uint8_t a) +{ + return s; +} + +static inline uint32_t opBlendDifference(uint32_t s, uint32_t d) +{ + auto f = [](uint8_t s, uint8_t d) { + return (s > d) ? (s - d) : (d - s); + }; + + return JOIN(255, f(C1(s), C1(d)), f(C2(s), C2(d)), f(C3(s), C3(d))); +} + +static inline uint32_t opBlendExclusion(uint32_t s, uint32_t d) +{ + auto f = [](uint8_t s, uint8_t d) { + return tvg::clamp(s + d - 2 * MULTIPLY(s, d), 0, 255); + }; + + return JOIN(255, f(C1(s), C1(d)), f(C2(s), C2(d)), f(C3(s), C3(d))); +} + +static inline uint32_t opBlendAdd(uint32_t s, uint32_t d) +{ + auto f = [](uint8_t s, uint8_t d) { + return std::min(s + d, 255); + }; + + return JOIN(255, f(C1(s), C1(d)), f(C2(s), C2(d)), f(C3(s), C3(d))); +} + +static inline uint32_t opBlendScreen(uint32_t s, uint32_t d) +{ + auto f = [](uint8_t s, uint8_t d) { + return s + d - MULTIPLY(s, d); + }; + + return JOIN(255, f(C1(s), C1(d)), f(C2(s), C2(d)), f(C3(s), C3(d))); +} + +static inline uint32_t opBlendMultiply(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return MULTIPLY(s, d); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + + +static inline uint32_t opBlendOverlay(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return (d < 128) ? std::min(255, 2 * MULTIPLY(s, d)) : (255 - std::min(255, 2 * MULTIPLY(255 - s, 255 - d))); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + +static inline uint32_t opBlendDarken(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return std::min(s, d); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + +static inline uint32_t opBlendLighten(uint32_t s, uint32_t d) +{ + auto f = [](uint8_t s, uint8_t d) { + return std::max(s, d); + }; + + return JOIN(255, f(C1(s), C1(d)), f(C2(s), C2(d)), f(C3(s), C3(d))); +} + +static inline uint32_t opBlendColorDodge(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return d == 0 ? 0 : (s == 255 ? 255 : std::min(d * 255 / (255 - s), 255)); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + +static inline uint32_t opBlendColorBurn(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return d == 255 ? 255 : (s == 0 ? 0 : 255 - std::min((255 - d) * 255 / s, 255)); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + +static inline uint32_t opBlendHardLight(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return (s < 128) ? std::min(255, 2 * MULTIPLY(s, d)) : (255 - std::min(255, 2 * MULTIPLY(255 - s, 255 - d))); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + +static inline uint32_t opBlendSoftLight(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + auto f = [](uint8_t s, uint8_t d) { + return MULTIPLY(255 - std::min(255, 2 * s), MULTIPLY(d, d)) + std::min(255, 2 * MULTIPLY(s, d)); + }; + + return BLEND_PRE(JOIN(255, f(C1(s), o.r), f(C2(s), o.g), f(C3(s), o.b)), s, o.a); +} + +void rasterRGB2HSL(uint8_t r, uint8_t g, uint8_t b, float* h, float* s, float* l); + +static inline uint32_t opBlendHue(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + float sh, ds, dl; + rasterRGB2HSL(C1(s), C2(s), C3(s), &sh, 0, 0); + rasterRGB2HSL(o.r, o.g, o.b, 0, &ds, &dl); + + uint8_t r, g, b; + hsl2rgb(sh, ds, dl, r, g, b); + + return BLEND_PRE(JOIN(255, r, g, b), s, o.a); +} + +static inline uint32_t opBlendSaturation(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + float dh, ss, dl; + rasterRGB2HSL(C1(s), C2(s), C3(s), 0, &ss, 0); + rasterRGB2HSL(o.r, o.g, o.b, &dh, 0, &dl); + + uint8_t r, g, b; + hsl2rgb(dh, ss, dl, r, g, b); + + return BLEND_PRE(JOIN(255, r, g, b), s, o.a); +} + +static inline uint32_t opBlendColor(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + float sh, ss, dl; + rasterRGB2HSL(C1(s), C2(s), C3(s), &sh, &ss, 0); + rasterRGB2HSL(o.r, o.g, o.b, 0, 0, &dl); + + uint8_t r, g, b; + hsl2rgb(sh, ss, dl, r, g, b); + + return BLEND_PRE(JOIN(255, r, g, b), s, o.a); +} + +static inline uint32_t opBlendLuminosity(uint32_t s, uint32_t d) +{ + auto o = BLEND_UPRE(d); + + float dh, ds, sl; + rasterRGB2HSL(C1(s), C2(s), C3(s), 0, 0, &sl); + rasterRGB2HSL(o.r, o.g, o.b, &dh, &ds, 0); + + uint8_t r, g, b; + hsl2rgb(dh, ds, sl, r, g, b); + + return BLEND_PRE(JOIN(255, r, g, b), s, o.a); +} + +int64_t mathMultiply(int64_t a, int64_t b); +int64_t mathDivide(int64_t a, int64_t b); +int64_t mathMulDiv(int64_t a, int64_t b, int64_t c); +void mathRotate(SwPoint& pt, int64_t angle); +int64_t mathTan(int64_t angle); +int64_t mathAtan(const SwPoint& pt); +int64_t mathCos(int64_t angle); +int64_t mathSin(int64_t angle); +void mathSplitCubic(SwPoint* base); +void mathSplitLine(SwPoint* base); +int64_t mathDiff(int64_t angle1, int64_t angle2); +int64_t mathLength(const SwPoint& pt); +int mathCubicAngle(const SwPoint* base, int64_t& angleIn, int64_t& angleMid, int64_t& angleOut); +int64_t mathMean(int64_t angle1, int64_t angle2); +SwPoint mathTransform(const Point* to, const Matrix& transform); +bool mathUpdateOutlineBBox(const SwOutline* outline, const RenderRegion& clipBox, RenderRegion& renderBox, bool fastTrack); + +void shapeReset(SwShape& shape); +bool shapePrepare(SwShape& shape, const RenderShape* rshape, const Matrix& transform, const RenderRegion& clipBox, RenderRegion& renderBox, SwMpool* mpool, unsigned tid, bool hasComposite); +bool shapeGenRle(SwShape& shape, const RenderRegion& bbox, SwMpool* mpool, unsigned tid, bool antiAlias); +void shapeDelOutline(SwShape& shape, SwMpool* mpool, uint32_t tid); +void shapeResetStroke(SwShape& shape, const RenderShape* rshape, const Matrix& transform, SwMpool* mpool, unsigned tid); +bool shapeGenStrokeRle(SwShape& shape, const RenderShape* rshape, const Matrix& transform, const RenderRegion& clipBox, RenderRegion& renderBox, SwMpool* mpool, unsigned tid); +void shapeFree(SwShape& shape); +void shapeDelStroke(SwShape& shape); +bool shapeGenFillColors(SwShape& shape, const Fill* fill, const Matrix& transform, SwSurface* surface, uint8_t opacity, bool ctable); +bool shapeGenStrokeFillColors(SwShape& shape, const Fill* fill, const Matrix& transform, SwSurface* surface, uint8_t opacity, bool ctable); +void shapeResetFill(SwShape& shape); +void shapeResetStrokeFill(SwShape& shape); +bool shapeStrokeBBox(SwShape& shape, const RenderShape* rshape, Point* pt4, const Matrix& m, SwMpool* mpool); +void shapeDelFill(SwShape& shape); + +void strokeReset(SwStroke* stroke, const RenderShape* shape, const Matrix& transform, SwMpool* mpool, unsigned tid); +bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline, SwMpool* mpool, unsigned tid); +SwOutline* strokeExportOutline(SwStroke* stroke, SwMpool* mpool, unsigned tid); +void strokeFree(SwStroke* stroke); + +bool imagePrepare(SwImage& image, const Matrix& transform, const RenderRegion& clipBox, RenderRegion& renderBox, SwMpool* mpool, unsigned tid); +bool imageGenRle(SwImage& image, const RenderRegion& bbox, SwMpool* mpool, unsigned tid, bool antiAlias); +void imageDelOutline(SwImage& image, SwMpool* mpool, uint32_t tid); +void imageReset(SwImage& image); +void imageFree(SwImage& image); + +bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix& transform, SwSurface* surface, uint8_t opacity, bool ctable); +const Fill::ColorStop* fillFetchSolid(const SwFill* fill, const Fill* fdata); +void fillReset(SwFill* fill); +void fillFree(SwFill* fill); + +//OPTIMIZE_ME: Skip the function pointer access +void fillLinear(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, SwMask maskOp, uint8_t opacity); //composite masking ver. +void fillLinear(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwMask maskOp, uint8_t opacity); //direct masking ver. +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, uint8_t a); //blending ver. +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, SwBlender op2, uint8_t a); //blending + BlendingMethod(op2) ver. +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity); //matting ver. + +void fillRadial(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, SwMask op, uint8_t a); //composite masking ver. +void fillRadial(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwMask op, uint8_t a) ; //direct masking ver. +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, uint8_t a); //blending ver. +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, SwBlender op2, uint8_t a); //blending + BlendingMethod(op2) ver. +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity); //matting ver. + +SwRle* rleRender(SwRle* rle, const SwOutline* outline, const RenderRegion& bbox, SwMpool* mpool, unsigned tid, bool antiAlias); +SwRle* rleRender(const RenderRegion* bbox); +void rleFree(SwRle* rle); +void rleReset(SwRle* rle); +void rleMerge(SwRle* rle, SwRle* clip1, SwRle* clip2); +bool rleClip(SwRle* rle, const SwRle* clip); +bool rleClip(SwRle* rle, const RenderRegion* clip); +bool rleIntersect(const SwRle* rle, const RenderRegion& region); + +SwMpool* mpoolInit(uint32_t threads); +void mpoolTerm(SwMpool* mpool); +SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx); +SwOutline* mpoolReqDashOutline(SwMpool* mpool, unsigned idx); +SwStrokeBorder* mpoolReqStrokeLBorder(SwMpool* mpool, unsigned idx); +SwStrokeBorder* mpoolReqStrokeRBorder(SwMpool* mpool, unsigned idx); +SwCellPool* mpoolReqCellPool(SwMpool* mpool, unsigned idx); + +bool rasterCompositor(SwSurface* surface); +bool rasterShape(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, RenderColor& c); +bool rasterTexmapPolygon(SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity); +bool rasterScaledImage(SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity); +bool rasterDirectImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity); +bool rasterScaledRleImage(SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity); +bool rasterDirectRleImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity); +bool rasterStroke(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, RenderColor& c); +bool rasterGradientShape(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, const Fill* fdata, uint8_t opacity); +bool rasterGradientStroke(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, const Fill* fdata, uint8_t opacity); +bool rasterClear(SwSurface* surface, uint32_t x, uint32_t y, uint32_t w, uint32_t h); +void rasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len); +void rasterTranslucentPixel32(uint32_t* dst, uint32_t* src, uint32_t len, uint8_t opacity); +void rasterPixel32(uint32_t* dst, uint32_t* src, uint32_t len, uint8_t opacity); +void rasterGrayscale8(uint8_t *dst, uint8_t val, uint32_t offset, int32_t len); +void rasterXYFlip(uint32_t* src, uint32_t* dst, int32_t stride, int32_t w, int32_t h, const RenderRegion& bbox, bool flipped); +void rasterUnpremultiply(RenderSurface* surface); +void rasterPremultiply(RenderSurface* surface); +bool rasterConvertCS(RenderSurface* surface, ColorSpace to); +uint32_t rasterUnpremultiply(uint32_t data); + +bool effectGaussianBlur(SwCompositor* cmp, SwSurface* surface, const RenderEffectGaussianBlur* params); +bool effectGaussianBlurRegion(RenderEffectGaussianBlur* effect); +void effectGaussianBlurUpdate(RenderEffectGaussianBlur* effect, const Matrix& transform); +bool effectDropShadow(SwCompositor* cmp, SwSurface* surfaces[2], const RenderEffectDropShadow* params, bool direct); +bool effectDropShadowRegion(RenderEffectDropShadow* effect); +void effectDropShadowUpdate(RenderEffectDropShadow* effect, const Matrix& transform); +void effectFillUpdate(RenderEffectFill* effect); +bool effectFill(SwCompositor* cmp, const RenderEffectFill* params, bool direct); +void effectTintUpdate(RenderEffectTint* effect); +bool effectTint(SwCompositor* cmp, const RenderEffectTint* params, bool direct); +void effectTritoneUpdate(RenderEffectTritone* effect); +bool effectTritone(SwCompositor* cmp, const RenderEffectTritone* params, bool direct); + +#endif /* _TVG_SW_COMMON_H_ */ diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwFill.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwFill.cpp new file mode 100644 index 0000000..26a543a --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwFill.cpp @@ -0,0 +1,812 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgSwCommon.h" +#include "tvgFill.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define RADIAL_A_THRESHOLD 0.0005f +#define FIXPT_BITS 8 +#define FIXPT_SIZE (1<radial.a + * B = 2 * (dr * fr + rx * dx + ry * dy) + * C = fr^2 - rx^2 - ry^2 + * Derivatives are computed with respect to dx. + * This procedure aims to optimize and eliminate the need to calculate all values from the beginning + * for consecutive x values with a constant y. The Taylor series expansions are computed as long as + * its terms are non-zero. + */ +static void _calculateCoefficients(const SwFill* fill, uint32_t x, uint32_t y, float& b, float& deltaB, float& det, float& deltaDet, float& deltaDeltaDet) +{ + auto radial = &fill->radial; + + auto rx = (x + 0.5f) * radial->a11 + (y + 0.5f) * radial->a12 + radial->a13 - radial->fx; + auto ry = (x + 0.5f) * radial->a21 + (y + 0.5f) * radial->a22 + radial->a23 - radial->fy; + + b = (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy) * radial->invA; + deltaB = (radial->a11 * radial->dx + radial->a21 * radial->dy) * radial->invA; + + auto rr = rx * rx + ry * ry; + auto deltaRr = 2.0f * (rx * radial->a11 + ry * radial->a21) * radial->invA; + auto deltaDeltaRr = 2.0f * (radial->a11 * radial->a11 + radial->a21 * radial->a21) * radial->invA; + + det = b * b + (rr - radial->fr * radial->fr) * radial->invA; + deltaDet = 2.0f * b * deltaB + deltaB * deltaB + deltaRr + deltaDeltaRr * 0.5f; + deltaDeltaDet = 2.0f * deltaB * deltaB + deltaDeltaRr; +} + + +static uint32_t _estimateAAMargin(const Fill* fdata) +{ + constexpr float marginScalingFactor = 800.0f; + + if (fdata->type() == Type::RadialGradient) { + auto radius = CONST_RADIAL(fdata)->r; + return tvg::zero(radius) ? 0 : static_cast(marginScalingFactor / radius); + } else { + auto grad = CONST_LINEAR(fdata); + auto len = length(grad->p1, grad->p2); + return tvg::zero(len) ? 0 : static_cast(marginScalingFactor / len); + } +} + + +static void _adjustAAMargin(uint32_t& iMargin, uint32_t index) +{ + constexpr float threshold = 0.1f; + constexpr uint32_t iMarginMax = 40; + + auto iThreshold = static_cast(index * threshold); + if (iMargin > iThreshold) iMargin = iThreshold; + if (iMargin > iMarginMax) iMargin = iMarginMax; +} + + +static inline uint32_t _alphaUnblend(uint32_t c) +{ + auto a = (c >> 24); + if (a == 255 || a == 0) return c; + auto invA = 255.0f / static_cast(a); + auto c0 = static_cast(static_cast((c >> 16) & 0xFF) * invA); + auto c1 = static_cast(static_cast((c >> 8) & 0xFF) * invA); + auto c2 = static_cast(static_cast(c & 0xFF) * invA); + + return (a << 24) | (c0 << 16) | (c1 << 8) | c2; +} + + +static void _applyAA(SwFill* fill, uint32_t begin, uint32_t end) +{ + if (begin == 0 || end == 0) return; + + auto i = SW_COLOR_TABLE - end; + auto rgbaEnd = _alphaUnblend(fill->ctable[i]); + auto rgbaBegin = _alphaUnblend(fill->ctable[begin]); + + auto dt = 1.0f / (begin + end + 1.0f); + float t = dt; + while (i != begin) { + auto dist = 255 - static_cast(255 * t); + auto color = INTERPOLATE(rgbaEnd, rgbaBegin, dist); + fill->ctable[i++] = ALPHA_BLEND((color | 0xff000000), (color >> 24)); + + if (i == SW_COLOR_TABLE) i = 0; + t += dt; + } +} + + +static bool _updateColorTable(SwFill* fill, const Fill* fdata, const SwSurface* surface, uint8_t opacity) +{ + if (fill->solid) return true; + + const Fill::ColorStop* colors; + auto cnt = fdata->colorStops(&colors); + if (cnt == 0 || !colors) return false; + + auto pColors = colors; + + auto a = MULTIPLY(pColors->a, opacity); + if (a < 255) fill->translucent = true; + + auto r = pColors->r; + auto g = pColors->g; + auto b = pColors->b; + auto rgba = surface->join(r, g, b, a); + auto inc = 1.0f / static_cast(SW_COLOR_TABLE); + auto pos = 1.5f * inc; + uint32_t i = 0; + + //If repeat is true, anti-aliasing must be applied between the last and the first colors. + auto repeat = fill->spread == FillSpread::Repeat; + uint32_t iAABegin = repeat ? _estimateAAMargin(fdata) : 0; + uint32_t iAAEnd = 0; + + fill->ctable[i++] = ALPHA_BLEND(rgba | 0xff000000, a); + + while (pos <= pColors->offset) { + fill->ctable[i] = fill->ctable[i - 1]; + ++i; + pos += inc; + } + + for (uint32_t j = 0; j < cnt - 1; ++j) { + if (repeat && j == cnt - 2 && iAAEnd == 0) { + iAAEnd = iAABegin; + _adjustAAMargin(iAAEnd, SW_COLOR_TABLE - i); + } + + auto curr = colors + j; + auto next = curr + 1; + auto div = next->offset - curr->offset; + auto delta = div != 0.0f ? (1.0f / div) : 0.0f; + auto a2 = MULTIPLY(next->a, opacity); + + if (!fill->translucent && a2 < 255) fill->translucent = true; + + auto rgba2 = surface->join(next->r, next->g, next->b, a2); + + while (pos < next->offset && i < SW_COLOR_TABLE) { + auto t = (pos - curr->offset) * delta; + auto dist = static_cast(255 * t); + auto dist2 = 255 - dist; + auto color = INTERPOLATE(rgba, rgba2, dist2); + fill->ctable[i] = ALPHA_BLEND((color | 0xff000000), (color >> 24)); + ++i; + pos += inc; + } + rgba = rgba2; + a = a2; + + if (repeat && j == 0) _adjustAAMargin(iAABegin, i - 1); + } + rgba = ALPHA_BLEND((rgba | 0xff000000), a); + + for (; i < SW_COLOR_TABLE; ++i) { + fill->ctable[i] = rgba; + } + + //For repeat fill spread apply anti-aliasing between the last and first colors, + //otherwise make sure the last color stop is represented at the end of the table. + if (repeat) _applyAA(fill, iAABegin, iAAEnd); + else fill->ctable[SW_COLOR_TABLE - 1] = rgba; + + return true; +} + + +bool _prepareLinear(SwFill* fill, const LinearGradient* linear, const Matrix& pTransform) +{ + float x1, x2, y1, y2; + linear->linear(&x1, &y1, &x2, &y2); + + fill->linear.dx = x2 - x1; + fill->linear.dy = y2 - y1; + auto len = fill->linear.dx * fill->linear.dx + fill->linear.dy * fill->linear.dy; + + if (len < FLOAT_EPSILON) { + if (tvg::zero(fill->linear.dx) && tvg::zero(fill->linear.dy)) { + fill->solid = true; + } + return true; + } + + fill->linear.dx /= len; + fill->linear.dy /= len; + fill->linear.offset = -fill->linear.dx * x1 - fill->linear.dy * y1; + + const auto& transform = pTransform * linear->transform(); + + Matrix itransform; + if (!inverse(&transform, &itransform)) return false; + + fill->linear.offset += fill->linear.dx * itransform.e13 + fill->linear.dy * itransform.e23; + + auto dx = fill->linear.dx; + fill->linear.dx = dx * itransform.e11 + fill->linear.dy * itransform.e21; + fill->linear.dy = dx * itransform.e12 + fill->linear.dy * itransform.e22; + + return true; +} + + +bool _prepareRadial(SwFill* fill, const RadialGradient* radial, const Matrix& pTransform) +{ + float cx, cy, r, fx, fy, fr; + radial->radial(&cx, &cy, &r, &fx, &fy, &fr); + if ((fill->solid = !CONST_RADIAL(radial)->correct(fx, fy, fr))) return true; + + fill->radial.dr = r - fr; + fill->radial.dx = cx - fx; + fill->radial.dy = cy - fy; + fill->radial.fr = fr; + fill->radial.fx = fx; + fill->radial.fy = fy; + fill->radial.a = fill->radial.dr * fill->radial.dr - fill->radial.dx * fill->radial.dx - fill->radial.dy * fill->radial.dy; + constexpr float precision = 0.01f; + if (fill->radial.a < precision) fill->radial.a = precision; + fill->radial.invA = 1.0f / fill->radial.a; + + const auto& transform = pTransform * radial->transform(); + + Matrix itransform; + if (!inverse(&transform, &itransform)) return false; + + fill->radial.a11 = itransform.e11; + fill->radial.a12 = itransform.e12; + fill->radial.a13 = itransform.e13; + fill->radial.a21 = itransform.e21; + fill->radial.a22 = itransform.e22; + fill->radial.a23 = itransform.e23; + + return true; +} + + +static inline uint32_t _clamp(const SwFill* fill, int32_t pos) +{ + switch (fill->spread) { + case FillSpread::Pad: { + if (pos >= SW_COLOR_TABLE) pos = SW_COLOR_TABLE - 1; + else if (pos < 0) pos = 0; + break; + } + case FillSpread::Repeat: { + pos = pos % SW_COLOR_TABLE; + if (pos < 0) pos = SW_COLOR_TABLE + pos; + break; + } + case FillSpread::Reflect: { + auto limit = SW_COLOR_TABLE * 2; + pos = pos % limit; + if (pos < 0) pos = limit + pos; + if (pos >= SW_COLOR_TABLE) pos = (limit - pos - 1); + break; + } + } + return pos; +} + + +static inline uint32_t _fixedPixel(const SwFill* fill, int32_t pos) +{ + int32_t i = (pos + (FIXPT_SIZE / 2)) >> FIXPT_BITS; + return fill->ctable[_clamp(fill, i)]; +} + + +static inline uint32_t _pixel(const SwFill* fill, float pos) +{ + auto i = static_cast(pos * (SW_COLOR_TABLE - 1) + 0.5f); + return fill->ctable[_clamp(fill, i)]; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) +{ + //edge case + if (fill->radial.a < RADIAL_A_THRESHOLD) { + auto radial = &fill->radial; + auto rx = (x + 0.5f) * radial->a11 + (y + 0.5f) * radial->a12 + radial->a13 - radial->fx; + auto ry = (x + 0.5f) * radial->a21 + (y + 0.5f) * radial->a22 + radial->a23 - radial->fy; + + if (opacity == 255) { + for (uint32_t i = 0 ; i < len ; ++i, ++dst, cmp += csize) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + *dst = opBlendNormal(_pixel(fill, x0), *dst, alpha(cmp)); + rx += radial->a11; + ry += radial->a21; + } + } else { + for (uint32_t i = 0 ; i < len ; ++i, ++dst, cmp += csize) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + *dst = opBlendNormal(_pixel(fill, x0), *dst, MULTIPLY(opacity, alpha(cmp))); + rx += radial->a11; + ry += radial->a21; + } + } + } else { + float b, deltaB, det, deltaDet, deltaDeltaDet; + _calculateCoefficients(fill, x, y, b, deltaB, det, deltaDet, deltaDeltaDet); + + if (opacity == 255) { + for (uint32_t i = 0 ; i < len ; ++i, ++dst, cmp += csize) { + *dst = opBlendNormal(_pixel(fill, sqrtf(det) - b), *dst, alpha(cmp)); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } else { + for (uint32_t i = 0 ; i < len ; ++i, ++dst, cmp += csize) { + *dst = opBlendNormal(_pixel(fill, sqrtf(det) - b), *dst, MULTIPLY(opacity, alpha(cmp))); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } + } +} + + +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, uint8_t a) +{ + if (fill->radial.a < RADIAL_A_THRESHOLD) { + auto radial = &fill->radial; + auto rx = (x + 0.5f) * radial->a11 + (y + 0.5f) * radial->a12 + radial->a13 - radial->fx; + auto ry = (x + 0.5f) * radial->a21 + (y + 0.5f) * radial->a22 + radial->a23 - radial->fy; + for (uint32_t i = 0; i < len; ++i, ++dst) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + *dst = op(_pixel(fill, x0), *dst, a); + rx += radial->a11; + ry += radial->a21; + } + } else { + float b, deltaB, det, deltaDet, deltaDeltaDet; + _calculateCoefficients(fill, x, y, b, deltaB, det, deltaDet, deltaDeltaDet); + + for (uint32_t i = 0; i < len; ++i, ++dst) { + *dst = op(_pixel(fill, sqrtf(det) - b), *dst, a); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } +} + + +void fillRadial(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, SwMask maskOp, uint8_t a) +{ + if (fill->radial.a < RADIAL_A_THRESHOLD) { + auto radial = &fill->radial; + auto rx = (x + 0.5f) * radial->a11 + (y + 0.5f) * radial->a12 + radial->a13 - radial->fx; + auto ry = (x + 0.5f) * radial->a21 + (y + 0.5f) * radial->a22 + radial->a23 - radial->fy; + for (uint32_t i = 0 ; i < len ; ++i, ++dst) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + auto src = MULTIPLY(a, A(_pixel(fill, x0))); + *dst = maskOp(src, *dst, ~src); + rx += radial->a11; + ry += radial->a21; + } + } else { + float b, deltaB, det, deltaDet, deltaDeltaDet; + _calculateCoefficients(fill, x, y, b, deltaB, det, deltaDet, deltaDeltaDet); + + for (uint32_t i = 0 ; i < len ; ++i, ++dst) { + auto src = MULTIPLY(a, A(_pixel(fill, sqrtf(det) - b))); + *dst = maskOp(src, *dst, ~src); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } +} + + +void fillRadial(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwMask maskOp, uint8_t a) +{ + if (fill->radial.a < RADIAL_A_THRESHOLD) { + auto radial = &fill->radial; + auto rx = (x + 0.5f) * radial->a11 + (y + 0.5f) * radial->a12 + radial->a13 - radial->fx; + auto ry = (x + 0.5f) * radial->a21 + (y + 0.5f) * radial->a22 + radial->a23 - radial->fy; + for (uint32_t i = 0 ; i < len ; ++i, ++dst, ++cmp) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + auto src = MULTIPLY(A(A(_pixel(fill, x0))), a); + auto tmp = maskOp(src, *cmp, 0); + *dst = tmp + MULTIPLY(*dst, ~tmp); + rx += radial->a11; + ry += radial->a21; + } + } else { + float b, deltaB, det, deltaDet, deltaDeltaDet; + _calculateCoefficients(fill, x, y, b, deltaB, det, deltaDet, deltaDeltaDet); + + for (uint32_t i = 0 ; i < len ; ++i, ++dst, ++cmp) { + auto src = MULTIPLY(A(_pixel(fill, sqrtf(det))), a); + auto tmp = maskOp(src, *cmp, 0); + *dst = tmp + MULTIPLY(*dst, ~tmp); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } +} + + +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, SwBlender op2, uint8_t a) +{ + if (fill->radial.a < RADIAL_A_THRESHOLD) { + auto radial = &fill->radial; + auto rx = (x + 0.5f) * radial->a11 + (y + 0.5f) * radial->a12 + radial->a13 - radial->fx; + auto ry = (x + 0.5f) * radial->a21 + (y + 0.5f) * radial->a22 + radial->a23 - radial->fy; + + if (a == 255) { + for (uint32_t i = 0; i < len; ++i, ++dst) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + auto tmp = op(_pixel(fill, x0), *dst, 255); + *dst = op2(tmp, *dst); + rx += radial->a11; + ry += radial->a21; + } + } else { + for (uint32_t i = 0; i < len; ++i, ++dst) { + auto x0 = 0.5f * (rx * rx + ry * ry - radial->fr * radial->fr) / (radial->dr * radial->fr + rx * radial->dx + ry * radial->dy); + auto tmp = op(_pixel(fill, x0), *dst, 255); + auto tmp2 = op2(tmp, *dst); + *dst = INTERPOLATE(tmp2, *dst, a); + rx += radial->a11; + ry += radial->a21; + } + } + } else { + float b, deltaB, det, deltaDet, deltaDeltaDet; + _calculateCoefficients(fill, x, y, b, deltaB, det, deltaDet, deltaDeltaDet); + if (a == 255) { + for (uint32_t i = 0 ; i < len ; ++i, ++dst) { + auto tmp = op(_pixel(fill, sqrtf(det) - b), *dst, 255); + *dst = op2(tmp, *dst); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } else { + for (uint32_t i = 0 ; i < len ; ++i, ++dst) { + auto tmp = op(_pixel(fill, sqrtf(det) - b), *dst, 255); + auto tmp2 = op2(tmp, *dst); + *dst = INTERPOLATE(tmp2, *dst, a); + det += deltaDet; + deltaDet += deltaDeltaDet; + b += deltaB; + } + } + } +} + + +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) +{ + //Rotation + float rx = x + 0.5f; + float ry = y + 0.5f; + float t = (fill->linear.dx * rx + fill->linear.dy * ry + fill->linear.offset) * (SW_COLOR_TABLE - 1); + float inc = (fill->linear.dx) * (SW_COLOR_TABLE - 1); + + if (opacity == 255) { + if (tvg::zero(inc)) { + auto color = _fixedPixel(fill, static_cast(t * FIXPT_SIZE)); + for (uint32_t i = 0; i < len; ++i, ++dst, cmp += csize) { + *dst = opBlendNormal(color, *dst, alpha(cmp)); + } + return; + } + + auto vMax = static_cast(INT32_MAX >> (FIXPT_BITS + 1)); + auto vMin = -vMax; + auto v = t + (inc * len); + + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst, cmp += csize) { + *dst = opBlendNormal(_fixedPixel(fill, t2), *dst, alpha(cmp)); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + *dst = opBlendNormal(_pixel(fill, t / SW_COLOR_TABLE), *dst, alpha(cmp)); + ++dst; + t += inc; + cmp += csize; + } + } + } else { + if (tvg::zero(inc)) { + auto color = _fixedPixel(fill, static_cast(t * FIXPT_SIZE)); + for (uint32_t i = 0; i < len; ++i, ++dst, cmp += csize) { + *dst = opBlendNormal(color, *dst, MULTIPLY(alpha(cmp), opacity)); + } + return; + } + + auto vMax = static_cast(INT32_MAX >> (FIXPT_BITS + 1)); + auto vMin = -vMax; + auto v = t + (inc * len); + + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst, cmp += csize) { + *dst = opBlendNormal(_fixedPixel(fill, t2), *dst, MULTIPLY(alpha(cmp), opacity)); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + *dst = opBlendNormal(_pixel(fill, t / SW_COLOR_TABLE), *dst, MULTIPLY(opacity, alpha(cmp))); + ++dst; + t += inc; + cmp += csize; + } + } + } +} + + +void fillLinear(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, SwMask maskOp, uint8_t a) +{ + //Rotation + float rx = x + 0.5f; + float ry = y + 0.5f; + float t = (fill->linear.dx * rx + fill->linear.dy * ry + fill->linear.offset) * (SW_COLOR_TABLE - 1); + float inc = (fill->linear.dx) * (SW_COLOR_TABLE - 1); + + if (tvg::zero(inc)) { + auto src = MULTIPLY(a, A(_fixedPixel(fill, static_cast(t * FIXPT_SIZE)))); + for (uint32_t i = 0; i < len; ++i, ++dst) { + *dst = maskOp(src, *dst, ~src); + } + return; + } + + auto vMax = static_cast(INT32_MAX >> (FIXPT_BITS + 1)); + auto vMin = -vMax; + auto v = t + (inc * len); + + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst) { + auto src = MULTIPLY(A(_fixedPixel(fill, t2)), a); + *dst = maskOp(src, *dst, ~src); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + auto src = MULTIPLY(A(_pixel(fill, t / SW_COLOR_TABLE)), a); + *dst = maskOp(src, *dst, ~src); + ++dst; + t += inc; + } + } +} + + +void fillLinear(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwMask maskOp, uint8_t a) +{ + //Rotation + float rx = x + 0.5f; + float ry = y + 0.5f; + float t = (fill->linear.dx * rx + fill->linear.dy * ry + fill->linear.offset) * (SW_COLOR_TABLE - 1); + float inc = (fill->linear.dx) * (SW_COLOR_TABLE - 1); + + if (tvg::zero(inc)) { + auto src = A(_fixedPixel(fill, static_cast(t * FIXPT_SIZE))); + src = MULTIPLY(src, a); + for (uint32_t i = 0; i < len; ++i, ++dst, ++cmp) { + auto tmp = maskOp(src, *cmp, 0); + *dst = tmp + MULTIPLY(*dst, ~tmp); + } + return; + } + + auto vMax = static_cast(INT32_MAX >> (FIXPT_BITS + 1)); + auto vMin = -vMax; + auto v = t + (inc * len); + + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst, ++cmp) { + auto src = MULTIPLY(a, A(_fixedPixel(fill, t2))); + auto tmp = maskOp(src, *cmp, 0); + *dst = tmp + MULTIPLY(*dst, ~tmp); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + auto src = MULTIPLY(A(_pixel(fill, t / SW_COLOR_TABLE)), a); + auto tmp = maskOp(src, *cmp, 0); + *dst = tmp + MULTIPLY(*dst, ~tmp); + ++dst; + ++cmp; + t += inc; + } + } +} + + +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, uint8_t a) +{ + //Rotation + float rx = x + 0.5f; + float ry = y + 0.5f; + float t = (fill->linear.dx * rx + fill->linear.dy * ry + fill->linear.offset) * (SW_COLOR_TABLE - 1); + float inc = (fill->linear.dx) * (SW_COLOR_TABLE - 1); + + if (tvg::zero(inc)) { + auto color = _fixedPixel(fill, static_cast(t * FIXPT_SIZE)); + for (uint32_t i = 0; i < len; ++i, ++dst) { + *dst = op(color, *dst, a); + } + return; + } + + auto vMax = static_cast(INT32_MAX >> (FIXPT_BITS + 1)); + auto vMin = -vMax; + auto v = t + (inc * len); + + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst) { + *dst = op(_fixedPixel(fill, t2), *dst, a); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + *dst = op(_pixel(fill, t / SW_COLOR_TABLE), *dst, a); + ++dst; + t += inc; + } + } +} + + +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, SwBlender op2, uint8_t a) +{ + //Rotation + float rx = x + 0.5f; + float ry = y + 0.5f; + float t = (fill->linear.dx * rx + fill->linear.dy * ry + fill->linear.offset) * (SW_COLOR_TABLE - 1); + float inc = (fill->linear.dx) * (SW_COLOR_TABLE - 1); + + if (tvg::zero(inc)) { + auto color = _fixedPixel(fill, static_cast(t * FIXPT_SIZE)); + if (a == 255) { + for (uint32_t i = 0; i < len; ++i, ++dst) { + auto tmp = op(color, *dst, a); + *dst = op2(tmp, *dst); + } + } else { + for (uint32_t i = 0; i < len; ++i, ++dst) { + auto tmp = op(color, *dst, a); + auto tmp2 = op2(tmp, *dst); + *dst = INTERPOLATE(tmp2, *dst, a); + } + } + return; + } + + auto vMax = static_cast(INT32_MAX >> (FIXPT_BITS + 1)); + auto vMin = -vMax; + auto v = t + (inc * len); + + if (a == 255) { + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst) { + auto tmp = op(_fixedPixel(fill, t2), *dst, 255); + *dst = op2(tmp, *dst); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + auto tmp = op(_pixel(fill, t / SW_COLOR_TABLE), *dst, 255); + *dst = op2(tmp, *dst); + ++dst; + t += inc; + } + } + } else { + //we can use fixed point math + if (v < vMax && v > vMin) { + auto t2 = static_cast(t * FIXPT_SIZE); + auto inc2 = static_cast(inc * FIXPT_SIZE); + for (uint32_t j = 0; j < len; ++j, ++dst) { + auto tmp = op(_fixedPixel(fill, t2), *dst, 255); + auto tmp2 = op2(tmp, *dst); + *dst = INTERPOLATE(tmp2, *dst, a); + t2 += inc2; + } + //we have to fallback to float math + } else { + uint32_t counter = 0; + while (counter++ < len) { + auto tmp = op(_pixel(fill, t / SW_COLOR_TABLE), *dst, 255); + auto tmp2 = op2(tmp, *dst); + *dst = INTERPOLATE(tmp2, *dst, a); + ++dst; + t += inc; + } + } + } +} + + +bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix& transform, SwSurface* surface, uint8_t opacity, bool ctable) +{ + if (!fill) return false; + + fill->spread = fdata->spread(); + + if (fdata->type() == Type::LinearGradient) { + if (!_prepareLinear(fill, static_cast(fdata), transform)) return false; + } else if (fdata->type() == Type::RadialGradient) { + if (!_prepareRadial(fill, static_cast(fdata), transform)) return false; + } + + if (ctable) return _updateColorTable(fill, fdata, surface, opacity); + return true; +} + + +const Fill::ColorStop* fillFetchSolid(const SwFill* fill, const Fill* fdata) +{ + if (!fill->solid) return nullptr; + + const Fill::ColorStop* colors; + auto cnt = fdata->colorStops(&colors); + if (cnt == 0 || !colors) return nullptr; + + return colors + cnt - 1; +} + + +void fillReset(SwFill* fill) +{ + fill->translucent = false; + fill->solid = false; +} + + +void fillFree(SwFill* fill) +{ + if (fill) tvg::free(fill); +} diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwImage.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwImage.cpp new file mode 100644 index 0000000..b1428d8 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwImage.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgSwCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static inline bool _onlyShifted(const Matrix& m) +{ + if (tvg::equal(m.e11, 1.0f) && tvg::equal(m.e22, 1.0f) && tvg::zero(m.e12) && tvg::zero(m.e21)) return true; + return false; +} + + +static bool _genOutline(SwImage& image, const Matrix& transform, SwMpool* mpool, unsigned tid) +{ + image.outline = mpoolReqOutline(mpool, tid); + auto outline = image.outline; + + outline->pts.reserve(5); + outline->types.reserve(5); + outline->cntrs.reserve(1); + outline->closed.reserve(1); + + Point to[4]; + auto w = static_cast(image.w); + auto h = static_cast(image.h); + to[0] = {0, 0}; + to[1] = {w, 0}; + to[2] = {w, h}; + to[3] = {0, h}; + + for (int i = 0; i < 4; i++) { + outline->pts.push(mathTransform(&to[i], transform)); + outline->types.push(SW_CURVE_TYPE_POINT); + } + + outline->pts.push(outline->pts[0]); + outline->types.push(SW_CURVE_TYPE_POINT); + outline->cntrs.push(outline->pts.count - 1); + outline->closed.push(true); + + image.outline = outline; + image.outline->fillRule = FillRule::NonZero; + + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +bool imagePrepare(SwImage& image, const Matrix& transform, const RenderRegion& clipBox, RenderRegion& renderBox, SwMpool* mpool, unsigned tid) +{ + image.direct = _onlyShifted(transform); + + //Fast track: Non-transformed image but just shifted. + if (image.direct) { + image.ox = -static_cast(nearbyint(transform.e13)); + image.oy = -static_cast(nearbyint(transform.e23)); + //Figure out the scale factor by transform matrix + } else { + auto scaleX = sqrtf((transform.e11 * transform.e11) + (transform.e21 * transform.e21)); + auto scaleY = sqrtf((transform.e22 * transform.e22) + (transform.e12 * transform.e12)); + image.scale = (fabsf(scaleX - scaleY) > 0.01f) ? 1.0f : scaleX; + + if (tvg::zero(transform.e12) && tvg::zero(transform.e21)) image.scaled = true; + else image.scaled = false; + } + + if (!_genOutline(image, transform, mpool, tid)) return false; + return mathUpdateOutlineBBox(image.outline, clipBox, renderBox, image.direct); +} + + +bool imageGenRle(SwImage& image, const RenderRegion& renderBox, SwMpool* mpool, unsigned tid, bool antiAlias) +{ + if ((image.rle = rleRender(image.rle, image.outline, renderBox, mpool, tid, antiAlias))) return true; + + return false; +} + + +void imageDelOutline(SwImage& image, SwMpool* mpool, uint32_t tid) +{ + image.outline = nullptr; +} + + +void imageReset(SwImage& image) +{ + rleReset(image.rle); +} + + +void imageFree(SwImage& image) +{ + rleFree(image.rle); + image.rle = nullptr; +} diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwMath.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwMath.cpp new file mode 100644 index 0000000..8610ef3 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwMath.cpp @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgSwCommon.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static float TO_RADIAN(int64_t angle) +{ + return (float(angle) / 65536.0f) * (MATH_PI / 180.0f); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +int64_t mathMean(int64_t angle1, int64_t angle2) +{ + return angle1 + mathDiff(angle1, angle2) / 2; +} + + +int mathCubicAngle(const SwPoint* base, int64_t& angleIn, int64_t& angleMid, int64_t& angleOut) +{ + auto d1 = base[2] - base[3]; + auto d2 = base[1] - base[2]; + auto d3 = base[0] - base[1]; + + if (d1.tiny()) { + if (d2.tiny()) { + if (d3.tiny()) { + angleIn = angleMid = angleOut = 0; + return -1; //ignoreable + } else { + angleIn = angleMid = angleOut = mathAtan(d3); + } + } else { + if (d3.tiny()) { + angleIn = angleMid = angleOut = mathAtan(d2); + } else { + angleIn = angleMid = mathAtan(d2); + angleOut = mathAtan(d3); + } + } + } else { + if (d2.tiny()) { + if (d3.tiny()) { + angleIn = angleMid = angleOut = mathAtan(d1); + } else { + angleIn = mathAtan(d1); + angleOut = mathAtan(d3); + angleMid = mathMean(angleIn, angleOut); + } + } else { + if (d3.tiny()) { + angleIn = mathAtan(d1); + angleMid = angleOut = mathAtan(d2); + } else { + angleIn = mathAtan(d1); + angleMid = mathAtan(d2); + angleOut = mathAtan(d3); + } + } + } + + auto theta1 = abs(mathDiff(angleIn, angleMid)); + auto theta2 = abs(mathDiff(angleMid, angleOut)); + + if ((theta1 < (SW_ANGLE_PI / 8)) && (theta2 < (SW_ANGLE_PI / 8))) return 0; //small size + return 1; +} + + +int64_t mathMultiply(int64_t a, int64_t b) +{ + int32_t s = 1; + + //move sign + if (a < 0) { + a = -a; + s = -s; + } + if (b < 0) { + b = -b; + s = -s; + } + int64_t c = (a * b + 0x8000L) >> 16; + return (s > 0) ? c : -c; +} + + +int64_t mathDivide(int64_t a, int64_t b) +{ + int32_t s = 1; + + //move sign + if (a < 0) { + a = -a; + s = -s; + } + if (b < 0) { + b = -b; + s = -s; + } + int64_t q = b > 0 ? ((a << 16) + (b >> 1)) / b : 0x7FFFFFFFL; + return (s < 0 ? -q : q); +} + + +int64_t mathMulDiv(int64_t a, int64_t b, int64_t c) +{ + int32_t s = 1; + + //move sign + if (a < 0) { + a = -a; + s = -s; + } + if (b < 0) { + b = -b; + s = -s; + } + if (c < 0) { + c = -c; + s = -s; + } + int64_t d = c > 0 ? (a * b + (c >> 1)) / c : 0x7FFFFFFFL; + + return (s > 0 ? d : -d); +} + + +void mathRotate(SwPoint& pt, int64_t angle) +{ + if (angle == 0 || pt.zero()) return; + + Point v = pt.toPoint(); + + auto radian = TO_RADIAN(angle); + auto cosv = cosf(radian); + auto sinv = sinf(radian); + + pt.x = int32_t(nearbyint((v.x * cosv - v.y * sinv) * 64.0f)); + pt.y = int32_t(nearbyint((v.x * sinv + v.y * cosv) * 64.0f)); +} + + +int64_t mathTan(int64_t angle) +{ + if (angle == 0) return 0; + return int64_t(tanf(TO_RADIAN(angle)) * 65536.0f); +} + + +int64_t mathAtan(const SwPoint& pt) +{ + if (pt.zero()) return 0; + return int64_t(tvg::atan2(TO_FLOAT(pt.y), TO_FLOAT(pt.x)) * (180.0f / MATH_PI) * 65536.0f); +} + + +int64_t mathSin(int64_t angle) +{ + if (angle == 0) return 0; + return mathCos(SW_ANGLE_PI2 - angle); +} + + +int64_t mathCos(int64_t angle) +{ + return int64_t(cosf(TO_RADIAN(angle)) * 65536.0f); +} + + +int64_t mathLength(const SwPoint& pt) +{ + if (pt.zero()) return 0; + + //trivial case + if (pt.x == 0) return abs(pt.y); + if (pt.y == 0) return abs(pt.x); + + auto v = pt.toPoint(); + //return static_cast(sqrtf(v.x * v.x + v.y * v.y) * 65536.0f); + + /* approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm. + With alpha = 1, beta = 3/8, giving results with the largest error less + than 7% compared to the exact value. */ + if (v.x < 0) v.x = -v.x; + if (v.y < 0) v.y = -v.y; + return static_cast((v.x > v.y) ? (v.x + v.y * 0.375f) : (v.y + v.x * 0.375f)); +} + + +void mathSplitCubic(SwPoint* base) +{ + int32_t a, b, c, d; + + base[6].x = base[3].x; + c = base[1].x; + d = base[2].x; + base[1].x = a = (base[0].x + c) >> 1; + base[5].x = b = (base[3].x + d) >> 1; + c = (c + d) >> 1; + base[2].x = a = (a + c) >> 1; + base[4].x = b = (b + c) >> 1; + base[3].x = (a + b) >> 1; + + base[6].y = base[3].y; + c = base[1].y; + d = base[2].y; + base[1].y = a = (base[0].y + c) >> 1; + base[5].y = b = (base[3].y + d) >> 1; + c = (c + d) >> 1; + base[2].y = a = (a + c) >> 1; + base[4].y = b = (b + c) >> 1; + base[3].y = (a + b) >> 1; +} + + +void mathSplitLine(SwPoint* base) +{ + base[2] = base[1]; + base[1] = {(base[0].x >> 1) + (base[1].x >> 1), (base[0].y >> 1) + (base[1].y >> 1)}; +} + + +int64_t mathDiff(int64_t angle1, int64_t angle2) +{ + auto delta = angle2 - angle1; + + delta %= SW_ANGLE_2PI; + if (delta < 0) delta += SW_ANGLE_2PI; + if (delta > SW_ANGLE_PI) delta -= SW_ANGLE_2PI; + + return delta; +} + + +SwPoint mathTransform(const Point* to, const Matrix& transform) +{ + auto tx = to->x * transform.e11 + to->y * transform.e12 + transform.e13; + auto ty = to->x * transform.e21 + to->y * transform.e22 + transform.e23; + + return {TO_SWCOORD(tx), TO_SWCOORD(ty)}; +} + + +bool mathUpdateOutlineBBox(const SwOutline* outline, const RenderRegion& clipBox, RenderRegion& renderBox, bool fastTrack) +{ + if (!outline || outline->pts.empty() || outline->cntrs.empty()) { + renderBox.reset(); + return false; + } + + auto pt = outline->pts.begin(); + + auto xMin = pt->x; + auto xMax = pt->x; + auto yMin = pt->y; + auto yMax = pt->y; + + for (++pt; pt < outline->pts.end(); ++pt) { + if (xMin > pt->x) xMin = pt->x; + if (xMax < pt->x) xMax = pt->x; + if (yMin > pt->y) yMin = pt->y; + if (yMax < pt->y) yMax = pt->y; + } + + if (fastTrack) { + renderBox.min = {int32_t(round(xMin / 64.0f)), int32_t(round(yMin / 64.0f))}; + renderBox.max = {int32_t(round(xMax / 64.0f)), int32_t(round(yMax / 64.0f))}; + } else { + renderBox.min = {xMin >> 6, yMin >> 6}; + renderBox.max = {(xMax + 63) >> 6, (yMax + 63) >> 6}; + } + + renderBox.intersect(clipBox); + return renderBox.valid(); +} diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwMemPool.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwMemPool.cpp new file mode 100644 index 0000000..6b6b4b4 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwMemPool.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgSwCommon.h" + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx) +{ + mpool->outline[idx].pts.clear(); + mpool->outline[idx].cntrs.clear(); + mpool->outline[idx].types.clear(); + mpool->outline[idx].closed.clear(); + + return &mpool->outline[idx]; +} + + +SwStrokeBorder* mpoolReqStrokeLBorder(SwMpool* mpool, unsigned idx) +{ + mpool->leftBorder[idx].pts.clear(); + mpool->leftBorder[idx].start = -1; + return &mpool->leftBorder[idx]; +} + + +SwStrokeBorder* mpoolReqStrokeRBorder(SwMpool* mpool, unsigned idx) +{ + mpool->rightBorder[idx].pts.clear(); + mpool->rightBorder[idx].start = -1; + return &mpool->rightBorder[idx]; +} + + +SwCellPool* mpoolReqCellPool(SwMpool* mpool, unsigned idx) +{ + return &mpool->cellPool[idx]; +} + + +SwMpool* mpoolInit(uint32_t threads) +{ + auto allocSize = threads + 1; + + auto mpool = tvg::malloc(sizeof(SwMpool)); + mpool->outline = new SwOutline[allocSize]; + mpool->leftBorder = new SwStrokeBorder[allocSize]; + mpool->rightBorder = new SwStrokeBorder[allocSize]; + mpool->cellPool = new SwCellPool[allocSize]; + + mpool->allocSize = allocSize; + + return mpool; +} + + +void mpoolTerm(SwMpool* mpool) +{ + if (!mpool) return; + + delete[](mpool->outline); + delete[](mpool->leftBorder); + delete[](mpool->rightBorder); + delete[](mpool->cellPool); + + tvg::free(mpool); +} diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwPostEffect.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwPostEffect.cpp new file mode 100644 index 0000000..6425681 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwPostEffect.cpp @@ -0,0 +1,660 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgSwCommon.h" + +/************************************************************************/ +/* Gaussian Blur Implementation */ +/************************************************************************/ + +struct SwGaussianBlur +{ + static constexpr int MAX_LEVEL = 3; + int level; + int kernel[MAX_LEVEL]; + int extends; +}; + + +static inline int _gaussianEdgeWrap(int end, int idx) +{ + auto r = idx % (end + 1); + return (r < 0) ? (end + 1) + r : r; +} + + +static inline int _gaussianEdgeExtend(int end, int idx) +{ + if (idx < 0) return 0; + else if (idx > end) return end; + return idx; +} + + +template +static inline int _gaussianRemap(int end, int idx) +{ + if (border == 1) return _gaussianEdgeWrap(end, idx); + return _gaussianEdgeExtend(end, idx); +} + + +//TODO: SIMD OPTIMIZATION? +template +static void _gaussianFilter(uint8_t* dst, uint8_t* src, int32_t stride, int32_t w, int32_t h, const RenderRegion& bbox, int32_t dimension, bool flipped) +{ + if (flipped) { + src += (bbox.min.x * stride + bbox.min.y) << 2; + dst += (bbox.min.x * stride + bbox.min.y) << 2; + } else { + src += (bbox.min.y * stride + bbox.min.x) << 2; + dst += (bbox.min.y * stride + bbox.min.x) << 2; + } + + auto iarr = 1.0f / (dimension + dimension + 1); + auto end = w - 1; + + #pragma omp parallel for + for (int y = 0; y < h; ++y) { + auto p = y * stride; + auto i = p * 4; //current index + auto l = -(dimension + 1); //left index + auto r = dimension; //right index + int acc[4] = {0, 0, 0, 0}; //sliding accumulator + + //initial accumulation + for (int x = l; x < r; ++x) { + auto id = (_gaussianRemap(end, x) + p) * 4; + acc[0] += src[id++]; + acc[1] += src[id++]; + acc[2] += src[id++]; + acc[3] += src[id]; + } + //perform filtering + for (int x = 0; x < w; ++x, ++r, ++l) { + auto rid = (_gaussianRemap(end, r) + p) * 4; + auto lid = (_gaussianRemap(end, l) + p) * 4; + acc[0] += src[rid++] - src[lid++]; + acc[1] += src[rid++] - src[lid++]; + acc[2] += src[rid++] - src[lid++]; + acc[3] += src[rid] - src[lid]; + //ignored rounding for the performance. It should be originally: acc[idx] * iarr + 0.5f + dst[i++] = static_cast(acc[0] * iarr); + dst[i++] = static_cast(acc[1] * iarr); + dst[i++] = static_cast(acc[2] * iarr); + dst[i++] = static_cast(acc[3] * iarr); + } + } +} + + +//Fast Almost-Gaussian Filtering Method by Peter Kovesi +static int _gaussianInit(SwGaussianBlur* data, float sigma, int quality) +{ + const auto MAX_LEVEL = SwGaussianBlur::MAX_LEVEL; + + if (tvg::zero(sigma)) return 0; + + data->level = int(SwGaussianBlur::MAX_LEVEL * ((quality - 1) * 0.01f)) + 1; + + //compute box kernel sizes + auto wl = (int) sqrt((12 * sigma / MAX_LEVEL) + 1); + if (wl % 2 == 0) --wl; + auto wu = wl + 2; + auto mi = (12 * sigma - MAX_LEVEL * wl * wl - 4 * MAX_LEVEL * wl - 3 * MAX_LEVEL) / (-4 * wl - 4); + auto m = int(mi + 0.5f); + auto extends = 0; + + for (int i = 0; i < data->level; i++) { + data->kernel[i] = ((i < m ? wl : wu) - 1) / 2; + extends += data->kernel[i]; + } + + return extends; +} + + +bool effectGaussianBlurRegion(RenderEffectGaussianBlur* params) +{ + //region expansion for feathering + auto& bbox = params->extend; + auto extra = static_cast(params->rd)->extends; + + if (params->direction != 2) { + bbox.min.x = -extra; + bbox.max.x = extra; + } + if (params->direction != 1) { + bbox.min.y = -extra; + bbox.max.y = extra; + } + + return true; +} + + +void effectGaussianBlurUpdate(RenderEffectGaussianBlur* params, const Matrix& transform) +{ + if (!params->rd) params->rd = tvg::malloc(sizeof(SwGaussianBlur)); + auto rd = static_cast(params->rd); + + //compute box kernel sizes + auto scale = sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12); + rd->extends = _gaussianInit(rd, std::pow(params->sigma * scale, 2), params->quality); + + //invalid + if (rd->extends == 0) { + params->valid = false; + return; + } + + params->valid = true; +} + + +bool effectGaussianBlur(SwCompositor* cmp, SwSurface* surface, const RenderEffectGaussianBlur* params) +{ + auto& buffer = surface->compositor->image; + auto data = static_cast(params->rd); + auto& bbox = cmp->bbox; + auto w = (bbox.max.x - bbox.min.x); + auto h = (bbox.max.y - bbox.min.y); + auto stride = cmp->image.stride; + auto front = cmp->image.buf32; + auto back = buffer.buf32; + auto swapped = false; + + TVGLOG("SW_ENGINE", "GaussianFilter region(%d, %d, %d, %d) params(%f %d %d), level(%d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->sigma, params->direction, params->border, data->level); + + /* It is best to take advantage of the Gaussian blur’s separable property + by dividing the process into two passes. horizontal and vertical. + We can expect fewer calculations. */ + + //horizontal + if (params->direction != 2) { + for (int i = 0; i < data->level; ++i) { + _gaussianFilter(reinterpret_cast(back), reinterpret_cast(front), stride, w, h, bbox, data->kernel[i], false); + std::swap(front, back); + swapped = !swapped; + } + } + + //vertical. x/y flipping and horionztal access is pretty compatible with the memory architecture. + if (params->direction != 1) { + rasterXYFlip(front, back, stride, w, h, bbox, false); + std::swap(front, back); + + for (int i = 0; i < data->level; ++i) { + _gaussianFilter(reinterpret_cast(back), reinterpret_cast(front), stride, h, w, bbox, data->kernel[i], true); + std::swap(front, back); + swapped = !swapped; + } + + rasterXYFlip(front, back, stride, h, w, bbox, true); + std::swap(front, back); + } + + if (swapped) std::swap(cmp->image.buf8, buffer.buf8); + + return true; +} + +/************************************************************************/ +/* Drop Shadow Implementation */ +/************************************************************************/ + +struct SwDropShadow : SwGaussianBlur +{ + SwPoint offset; +}; + + +//TODO: SIMD OPTIMIZATION? +static void _dropShadowFilter(uint32_t* dst, uint32_t* src, int stride, int w, int h, const RenderRegion& bbox, int32_t dimension, uint32_t color, bool flipped) +{ + if (flipped) { + src += (bbox.min.x * stride + bbox.min.y); + dst += (bbox.min.x * stride + bbox.min.y); + } else { + src += (bbox.min.y * stride + bbox.min.x); + dst += (bbox.min.y * stride + bbox.min.x); + } + auto iarr = 1.0f / (dimension + dimension + 1); + auto end = w - 1; + + #pragma omp parallel for + for (int y = 0; y < h; ++y) { + auto p = y * stride; + auto i = p; //current index + auto l = -(dimension + 1); //left index + auto r = dimension; //right index + int acc = 0; //sliding accumulator + + //initial accumulation + for (int x = l; x < r; ++x) { + auto id = _gaussianEdgeExtend(end, x) + p; + acc += A(src[id]); + } + //perform filtering + for (int x = 0; x < w; ++x, ++r, ++l) { + auto rid = _gaussianEdgeExtend(end, r) + p; + auto lid = _gaussianEdgeExtend(end, l) + p; + acc += A(src[rid]) - A(src[lid]); + //ignored rounding for the performance. It should be originally: acc * iarr + dst[i++] = ALPHA_BLEND(color, static_cast(acc * iarr)); + } + } +} + +static void _shift(uint32_t** dst, uint32_t** src, int dstride, int sstride, int wmax, int hmax, const RenderRegion& bbox, SwPoint offset, SwSize& size) +{ + size.w = bbox.max.x - bbox.min.x; + size.h = bbox.max.y - bbox.min.y; + + //shift + if (offset.x < 0) { + *src -= offset.x; + size.w += offset.x; + } else { + *dst += offset.x; + size.w -= offset.x; + } + + if (offset.y < 0) { + *src -= (offset.y * sstride); + size.h += offset.y; + } else { + *dst += (offset.y * dstride); + size.h -= offset.y; + } +} + + +static void _dropShadowNoFilter(uint32_t* dst, uint32_t* src, int dstride, int sstride, int dw, int dh, const RenderRegion& bbox, const SwPoint& offset, uint32_t color, uint8_t opacity, bool direct) +{ + src += (bbox.min.y * sstride + bbox.min.x); + dst += (bbox.min.y * dstride + bbox.min.x); + + SwSize size; + _shift(&dst, &src, dstride, sstride, dw, dh, bbox, offset, size); + + for (auto y = 0; y < size.h; ++y) { + auto s2 = src; + auto d2 = dst; + for (int x = 0; x < size.w; ++x, ++d2, ++s2) { + auto a = MULTIPLY(opacity, A(*s2)); + if (!direct || a == 255) *d2 = ALPHA_BLEND(color, a); + else *d2 = INTERPOLATE(color, *d2, a); + } + src += sstride; + dst += dstride; + } +} + + +static void _dropShadowNoFilter(SwImage* dimg, SwImage* simg, const RenderRegion& bbox, const SwPoint& offset, uint32_t color) +{ + int dstride = dimg->stride; + int sstride = simg->stride; + + //shadow image + _dropShadowNoFilter(dimg->buf32, simg->buf32, dstride, sstride, dimg->w, dimg->h, bbox, offset, color, 255, false); + + //original image + auto src = simg->buf32 + (bbox.min.y * sstride + bbox.min.x); + auto dst = dimg->buf32 + (bbox.min.y * dstride + bbox.min.x); + + for (auto y = 0; y < (bbox.max.y - bbox.min.y); ++y) { + auto s = src; + auto d = dst; + for (int x = 0; x < (bbox.max.x - bbox.min.x); ++x, ++d, ++s) { + *d = *s + ALPHA_BLEND(*d, IA(*s)); + } + src += sstride; + dst += dstride; + } +} + + +static void _dropShadowShift(uint32_t* dst, uint32_t* src, int dstride, int sstride, int dw, int dh, const RenderRegion& bbox, const SwPoint& offset, uint8_t opacity, bool direct) +{ + src += (bbox.min.y * sstride + bbox.min.x); + dst += (bbox.min.y * dstride + bbox.min.x); + + SwSize size; + _shift(&dst, &src, dstride, sstride, dw, dh, bbox, offset, size); + + for (auto y = 0; y < size.h; ++y) { + if (direct) rasterTranslucentPixel32(dst, src, size.w, opacity); + else rasterPixel32(dst, src, size.w, opacity); + src += sstride; + dst += dstride; + } +} + + +bool effectDropShadowRegion(RenderEffectDropShadow* params) +{ + //region expansion for feathering + auto& bbox = params->extend; + auto& offset = static_cast(params->rd)->offset; + auto extra = static_cast(params->rd)->extends; + + bbox.min = {-extra, -extra}; + bbox.max = {extra, extra}; + + if (offset.x < 0) bbox.min.x += (int32_t) offset.x; + else bbox.max.x += offset.x; + + if (offset.y < 0) bbox.min.y += (int32_t) offset.y; + else bbox.max.y += offset.y; + + return true; +} + + +void effectDropShadowUpdate(RenderEffectDropShadow* params, const Matrix& transform) +{ + if (!params->rd) params->rd = tvg::malloc(sizeof(SwDropShadow)); + auto rd = static_cast(params->rd); + + //compute box kernel sizes + auto scale = sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12); + rd->extends = _gaussianInit(rd, std::pow(params->sigma * scale, 2), params->quality); + + //invalid + if (params->color[3] == 0) { + params->valid = false; + return; + } + + //offset + auto radian = tvg::deg2rad(90.0f - params->angle) - tvg::radian(transform); + rd->offset = {(int32_t)((params->distance * scale) * cosf(radian)), (int32_t)(-1.0f * (params->distance * scale) * sinf(radian))}; + + params->valid = true; +} + + +//A quite same integration with effectGaussianBlur(). See it for detailed comments. +//surface[0]: the original image, to overlay it into the filtered image. +//surface[1]: temporary buffer for generating the filtered image. +bool effectDropShadow(SwCompositor* cmp, SwSurface* surface[2], const RenderEffectDropShadow* params, bool direct) +{ + //FIXME: if the body is partially visible due to clipping, the shadow also becomes partially visible. + + auto data = static_cast(params->rd); + auto& bbox = cmp->bbox; + auto w = (bbox.max.x - bbox.min.x); + auto h = (bbox.max.y - bbox.min.y); + + //outside the screen + if (abs(data->offset.x) >= w || abs(data->offset.y) >= h) return true; + + SwImage* buffer[] = {&surface[0]->compositor->image, &surface[1]->compositor->image}; + auto color = cmp->recoverSfc->join(params->color[0], params->color[1], params->color[2], 255); + auto stride = cmp->image.stride; + auto front = cmp->image.buf32; + auto back = buffer[1]->buf32; + + auto opacity = direct ? MULTIPLY(params->color[3], cmp->opacity) : params->color[3]; + + TVGLOG("SW_ENGINE", "DropShadow region(%d, %d, %d, %d) params(%f %f %f), level(%d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->angle, params->distance, params->sigma, data->level); + + //no filter required + if (data->extends == 0) { + if (direct) { + _dropShadowNoFilter(cmp->recoverSfc->buf32, cmp->image.buf32, cmp->recoverSfc->stride, cmp->image.stride, cmp->recoverSfc->w, cmp->recoverSfc->h, bbox, data->offset, color, opacity, direct); + } else { + _dropShadowNoFilter(buffer[1], &cmp->image, bbox, data->offset, color); + std::swap(cmp->image.buf32, buffer[1]->buf32); + } + return true; + } + + //saving the original image in order to overlay it into the filtered image. + _dropShadowFilter(back, front, stride, w, h, bbox, data->kernel[0], color, false); + std::swap(front, buffer[0]->buf32); + std::swap(front, back); + + //horizontal + for (int i = 1; i < data->level; ++i) { + _dropShadowFilter(back, front, stride, w, h, bbox, data->kernel[i], color, false); + std::swap(front, back); + } + + //vertical + rasterXYFlip(front, back, stride, w, h, bbox, false); + std::swap(front, back); + + for (int i = 0; i < data->level; ++i) { + _dropShadowFilter(back, front, stride, h, w, bbox, data->kernel[i], color, true); + std::swap(front, back); + } + + rasterXYFlip(front, back, stride, h, w, bbox, true); + std::swap(cmp->image.buf32, back); + + //draw to the main surface directly + if (direct) { + _dropShadowShift(cmp->recoverSfc->buf32, cmp->image.buf32, cmp->recoverSfc->stride, cmp->image.stride, cmp->recoverSfc->w, cmp->recoverSfc->h, bbox, data->offset, opacity, direct); + std::swap(cmp->image.buf32, buffer[0]->buf32); + return true; + } + + //draw to the intermediate surface + rasterClear(surface[1], bbox.min.x, bbox.min.y, w, h); + _dropShadowShift(buffer[1]->buf32, cmp->image.buf32, buffer[1]->stride, cmp->image.stride, buffer[1]->w, buffer[1]->h, bbox, data->offset, opacity, direct); + std::swap(cmp->image.buf32, buffer[1]->buf32); + + //compositing shadow and body + auto s = buffer[0]->buf32 + (bbox.min.y * buffer[0]->stride + bbox.min.x); + auto d = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + + for (auto y = 0; y < h; ++y) { + rasterTranslucentPixel32(d, s, w, 255); + s += buffer[0]->stride; + d += cmp->image.stride; + } + + return true; +} + + +/************************************************************************/ +/* Fill Implementation */ +/************************************************************************/ + +void effectFillUpdate(RenderEffectFill* params) +{ + params->valid = true; +} + + +bool effectFill(SwCompositor* cmp, const RenderEffectFill* params, bool direct) +{ + auto opacity = direct ? MULTIPLY(params->color[3], cmp->opacity) : params->color[3]; + + auto& bbox = cmp->bbox; + auto w = size_t(bbox.max.x - bbox.min.x); + auto h = size_t(bbox.max.y - bbox.min.y); + auto color = cmp->recoverSfc->join(params->color[0], params->color[1], params->color[2], 255); + + TVGLOG("SW_ENGINE", "Fill region(%d, %d, %d, %d), param(%d %d %d %d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->color[0], params->color[1], params->color[2], params->color[3]); + + if (direct) { + auto dbuffer = cmp->recoverSfc->buf32 + (bbox.min.y * cmp->recoverSfc->stride + bbox.min.x); + auto sbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + auto src = sbuffer; + for (size_t x = 0; x < w; ++x, ++dst, ++src) { + auto a = MULTIPLY(opacity, A(*src)); + auto tmp = ALPHA_BLEND(color, a); + *dst = tmp + ALPHA_BLEND(*dst, 255 - a); + } + dbuffer += cmp->image.stride; + sbuffer += cmp->recoverSfc->stride; + } + cmp->valid = true; //no need the subsequent composition + } else { + auto dbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + for (size_t x = 0; x < w; ++x, ++dst) { + *dst = ALPHA_BLEND(color, MULTIPLY(opacity, A(*dst))); + } + dbuffer += cmp->image.stride; + } + } + return true; +} + + +/************************************************************************/ +/* Tint Implementation */ +/************************************************************************/ + +void effectTintUpdate(RenderEffectTint* params) +{ + params->valid = (params->intensity > 0); +} + + +bool effectTint(SwCompositor* cmp, const RenderEffectTint* params, bool direct) +{ + auto& bbox = cmp->bbox; + auto w = size_t(bbox.max.x - bbox.min.x); + auto h = size_t(bbox.max.y - bbox.min.y); + auto black = cmp->recoverSfc->join(params->black[0], params->black[1], params->black[2], 255); + auto white = cmp->recoverSfc->join(params->white[0], params->white[1], params->white[2], 255); + auto opacity = cmp->opacity; + auto luma = cmp->recoverSfc->alphas[2]; //luma function + + TVGLOG("SW_ENGINE", "Tint region(%d, %d, %d, %d), param(%d %d %d, %d %d %d, %d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->black[0], params->black[1], params->black[2], params->white[0], params->white[1], params->white[2], params->intensity); + + if (direct) { + auto dbuffer = cmp->recoverSfc->buf32 + (bbox.min.y * cmp->recoverSfc->stride + bbox.min.x); + auto sbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + auto src = sbuffer; + for (size_t x = 0; x < w; ++x, ++dst, ++src) { + auto val = INTERPOLATE(white, black, luma((uint8_t*)src)); + if (params->intensity < 255) val = INTERPOLATE(val, *src, params->intensity); + *dst = INTERPOLATE(val, *dst, MULTIPLY(opacity, A(*src))); + } + dbuffer += cmp->image.stride; + sbuffer += cmp->recoverSfc->stride; + } + cmp->valid = true; //no need the subsequent composition + } else { + auto dbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + for (size_t x = 0; x < w; ++x, ++dst) { + auto val = INTERPOLATE(white, black, luma((uint8_t*)&dst)); + if (params->intensity < 255) val = INTERPOLATE(val, *dst, params->intensity); + *dst = ALPHA_BLEND(val, MULTIPLY(opacity, A(*dst))); + } + dbuffer += cmp->image.stride; + } + } + + return true; +} + + +/************************************************************************/ +/* Tritone Implementation */ +/************************************************************************/ + +static uint32_t _trintone(uint32_t s, uint32_t m, uint32_t h, int l) +{ + if (l < 128) { + auto a = std::min(l * 2, 255); + return ALPHA_BLEND(s, 255 - a) + ALPHA_BLEND(m, a); + } else { + auto a = 2 * std::max(0, l - 128); + return ALPHA_BLEND(m, 255 - a) + ALPHA_BLEND(h, a); + } +} + + +void effectTritoneUpdate(RenderEffectTritone* params) +{ + params->valid = (params->blender < 255); +} + + +bool effectTritone(SwCompositor* cmp, const RenderEffectTritone* params, bool direct) +{ + auto& bbox = cmp->bbox; + auto w = size_t(bbox.max.x - bbox.min.x); + auto h = size_t(bbox.max.y - bbox.min.y); + auto shadow = cmp->recoverSfc->join(params->shadow[0], params->shadow[1], params->shadow[2], 255); + auto midtone = cmp->recoverSfc->join(params->midtone[0], params->midtone[1], params->midtone[2], 255); + auto highlight = cmp->recoverSfc->join(params->highlight[0], params->highlight[1], params->highlight[2], 255); + auto opacity = cmp->opacity; + auto luma = cmp->recoverSfc->alphas[2]; //luma function + + TVGLOG("SW_ENGINE", "Tritone region(%d, %d, %d, %d), param(%d %d %d, %d %d %d, %d %d %d, %d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->shadow[0], params->shadow[1], params->shadow[2], params->midtone[0], params->midtone[1], params->midtone[2], params->highlight[0], params->highlight[1], params->highlight[2], params->blender); + + if (direct) { + auto dbuffer = cmp->recoverSfc->buf32 + (bbox.min.y * cmp->recoverSfc->stride + bbox.min.x); + auto sbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + auto src = sbuffer; + if (params->blender == 0) { + for (size_t x = 0; x < w; ++x, ++dst, ++src) { + *dst = INTERPOLATE(_trintone(shadow, midtone, highlight, luma((uint8_t*)src)), *dst, MULTIPLY(opacity, A(*src))); + } + } else { + for (size_t x = 0; x < w; ++x, ++dst, ++src) { + *dst = INTERPOLATE(INTERPOLATE(*src, _trintone(shadow, midtone, highlight, luma((uint8_t*)src)), params->blender), *dst, MULTIPLY(opacity, A(*src))); + } + } + dbuffer += cmp->image.stride; + sbuffer += cmp->recoverSfc->stride; + } + cmp->valid = true; //no need the subsequent composition + } else { + auto dbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + if (params->blender == 0) { + for (size_t x = 0; x < w; ++x, ++dst) { + *dst = ALPHA_BLEND(_trintone(shadow, midtone, highlight, luma((uint8_t*)dst)), MULTIPLY(A(*dst), opacity)); + } + } else { + for (size_t x = 0; x < w; ++x, ++dst) { + *dst = ALPHA_BLEND(INTERPOLATE(*dst, _trintone(shadow, midtone, highlight, luma((uint8_t*)dst)), params->blender), MULTIPLY(A(*dst), opacity)); + } + } + dbuffer += cmp->image.stride; + } + } + + return true; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRaster.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwRaster.cpp new file mode 100644 index 0000000..96b136b --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRaster.cpp @@ -0,0 +1,1809 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgRender.h" +#include "tvgSwCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +constexpr auto DOWN_SCALE_TOLERANCE = 0.5f; + +struct FillLinear +{ + void operator()(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, SwMask op, uint8_t a) + { + fillLinear(fill, dst, y, x, len, op, a); + } + + void operator()(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwMask op, uint8_t a) + { + fillLinear(fill, dst, y, x, len, cmp, op, a); + } + + void operator()(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, uint8_t a) + { + fillLinear(fill, dst, y, x, len, op, a); + } + + void operator()(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) + { + fillLinear(fill, dst, y, x, len, cmp, alpha, csize, opacity); + } + + void operator()(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, SwBlender op2, uint8_t a) + { + fillLinear(fill, dst, y, x, len, op, op2, a); + } + +}; + +struct FillRadial +{ + void operator()(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, SwMask op, uint8_t a) + { + fillRadial(fill, dst, y, x, len, op, a); + } + + void operator()(const SwFill* fill, uint8_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwMask op, uint8_t a) + { + fillRadial(fill, dst, y, x, len, cmp, op, a); + } + + void operator()(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, uint8_t a) + { + fillRadial(fill, dst, y, x, len, op, a); + } + + void operator()(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) + { + fillRadial(fill, dst, y, x, len, cmp, alpha, csize, opacity); + } + + void operator()(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlenderA op, SwBlender op2, uint8_t a) + { + fillRadial(fill, dst, y, x, len, op, op2, a); + } +}; + + +static inline uint8_t _alpha(uint8_t* a) +{ + return *a; +} + + +static inline uint8_t _ialpha(uint8_t* a) +{ + return ~(*a); +} + + +static inline uint8_t _abgrLuma(uint8_t* c) +{ + auto v = *(uint32_t*)c; + return ((((v&0xff)*54) + (((v>>8)&0xff)*182) + (((v>>16)&0xff)*19))) >> 8; //0.2126*R + 0.7152*G + 0.0722*B +} + + +static inline uint8_t _argbLuma(uint8_t* c) +{ + auto v = *(uint32_t*)c; + return ((((v&0xff)*19) + (((v>>8)&0xff)*182) + (((v>>16)&0xff)*54))) >> 8; //0.0722*B + 0.7152*G + 0.2126*R +} + + +static inline uint8_t _abgrInvLuma(uint8_t* c) +{ + return ~_abgrLuma(c); +} + + +static inline uint8_t _argbInvLuma(uint8_t* c) +{ + return ~_argbLuma(c); +} + + +static inline uint32_t _abgrJoin(uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + return (a << 24 | b << 16 | g << 8 | r); +} + + +static inline uint32_t _argbJoin(uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + return (a << 24 | r << 16 | g << 8 | b); +} + +static inline bool _blending(const SwSurface* surface) +{ + return (surface->blender) ? true : false; +} + + +/* OPTIMIZE_ME: Probably, we can separate masking(8bits) / composition(32bits) + This would help to enhance the performance by avoiding the unnecessary matting from the composition */ +static inline bool _compositing(const SwSurface* surface) +{ + if (!surface->compositor || surface->compositor->method == MaskMethod::None) return false; + return true; +} + + +static inline bool _matting(const SwSurface* surface) +{ + if ((int)surface->compositor->method < (int)MaskMethod::Add) return true; + else return false; +} + +static inline uint8_t _opMaskNone(uint8_t s, TVG_UNUSED uint8_t d, TVG_UNUSED uint8_t a) +{ + return s; +} + +static inline uint8_t _opMaskAdd(uint8_t s, uint8_t d, uint8_t a) +{ + return s + MULTIPLY(d, a); +} + + +static inline uint8_t _opMaskSubtract(uint8_t s, uint8_t d, TVG_UNUSED uint8_t a) +{ + return MULTIPLY(s, 255 - d); +} + + +static inline uint8_t _opMaskIntersect(uint8_t s, uint8_t d, TVG_UNUSED uint8_t a) +{ + return MULTIPLY(s, d); +} + + +static inline uint8_t _opMaskDifference(uint8_t s, uint8_t d, uint8_t a) +{ + return MULTIPLY(s, 255 - d) + MULTIPLY(d, a); +} + + +static inline uint8_t _opMaskLighten(uint8_t s, uint8_t d, uint8_t a) +{ + return (s > d) ? s : d; +} + + +static inline uint8_t _opMaskDarken(uint8_t s, uint8_t d, uint8_t a) +{ + return (s < d) ? s : d; +} + + +static inline bool _direct(MaskMethod method) +{ + if (method == MaskMethod::Subtract || method == MaskMethod::Intersect || method == MaskMethod::Darken) return true; + return false; +} + + +static inline SwMask _getMaskOp(MaskMethod method) +{ + switch (method) { + case MaskMethod::Add: return _opMaskAdd; + case MaskMethod::Subtract: return _opMaskSubtract; + case MaskMethod::Difference: return _opMaskDifference; + case MaskMethod::Intersect: return _opMaskIntersect; + case MaskMethod::Lighten: return _opMaskLighten; + case MaskMethod::Darken: return _opMaskDarken; + default: return nullptr; + } +} + + +static bool _compositeMaskImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox) +{ + auto dbuffer = &surface->buf8[bbox.min.y * surface->stride + bbox.min.x]; + auto sbuffer = image.buf8 + (bbox.min.y + image.oy) * image.stride + (bbox.min.x + image.ox); + + for (auto y = bbox.min.y; y < bbox.max.y; ++y) { + auto dst = dbuffer; + auto src = sbuffer; + for (auto x = bbox.min.x; x < bbox.max.x; x++, dst++, src++) { + *dst = *src + MULTIPLY(*dst, ~*src); + } + dbuffer += surface->stride; + sbuffer += image.stride; + } + return true; +} + + +#include "tvgSwRasterTexmap.h" +#include "tvgSwRasterC.h" +#include "tvgSwRasterAvx.h" +#include "tvgSwRasterNeon.h" + + +static inline uint32_t _sampleSize(float scale) +{ + auto sampleSize = static_cast(0.5f / scale); + if (sampleSize == 0) sampleSize = 1; + return sampleSize; +} + + +//Bilinear Interpolation +//OPTIMIZE_ME: Skip the function pointer access +static uint32_t _interpUpScaler(const uint32_t *img, TVG_UNUSED uint32_t stride, uint32_t w, uint32_t h, float sx, float sy, TVG_UNUSED int32_t miny, TVG_UNUSED int32_t maxy, TVG_UNUSED int32_t n) +{ + auto rx = (size_t)(sx); + auto ry = (size_t)(sy); + auto rx2 = rx + 1; + if (rx2 >= w) rx2 = w - 1; + auto ry2 = ry + 1; + if (ry2 >= h) ry2 = h - 1; + + auto dx = (sx > 0.0f) ? static_cast((sx - rx) * 255.0f) : 0; + auto dy = (sy > 0.0f) ? static_cast((sy - ry) * 255.0f) : 0; + + auto c1 = img[rx + ry * w]; + auto c2 = img[rx2 + ry * w]; + auto c3 = img[rx + ry2 * w]; + auto c4 = img[rx2 + ry2 * w]; + + return INTERPOLATE(INTERPOLATE(c4, c3, dx), INTERPOLATE(c2, c1, dx), dy); +} + + +//2n x 2n Mean Kernel +//OPTIMIZE_ME: Skip the function pointer access +static uint32_t _interpDownScaler(const uint32_t *img, uint32_t stride, uint32_t w, uint32_t h, float sx, TVG_UNUSED float sy, int32_t miny, int32_t maxy, int32_t n) +{ + size_t c[4] = {0, 0, 0, 0}; + + int32_t minx = (int32_t)sx - n; + if (minx < 0) minx = 0; + + int32_t maxx = (int32_t)sx + n; + if (maxx >= (int32_t)w) maxx = w; + + int32_t inc = (n / 2) + 1; + n = 0; + + auto src = img + minx + miny * stride; + + for (auto y = miny; y < maxy; y += inc) { + auto p = src; + for (auto x = minx; x < maxx; x += inc, p += inc) { + c[0] += A(*p); + c[1] += C1(*p); + c[2] += C2(*p); + c[3] += C3(*p); + ++n; + } + src += (stride * inc); + } + + c[0] /= n; + c[1] /= n; + c[2] /= n; + c[3] /= n; + + return (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; +} + + +/************************************************************************/ +/* Rect */ +/************************************************************************/ + +static bool _rasterCompositeMaskedRect(SwSurface* surface, const RenderRegion& bbox, SwMask maskOp, uint8_t a) +{ + auto cstride = surface->compositor->image.stride; + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * cstride + bbox.min.x); //compositor buffer + auto ialpha = 255 - a; + + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto cmp = cbuffer; + for (uint32_t x = 0; x < bbox.w(); ++x, ++cmp) { + *cmp = maskOp(a, *cmp, ialpha); + } + cbuffer += cstride; + } + return _compositeMaskImage(surface, surface->compositor->image, surface->compositor->bbox); +} + + +static bool _rasterDirectMaskedRect(SwSurface* surface, const RenderRegion& bbox, SwMask maskOp, uint8_t a) +{ + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * surface->compositor->image.stride + bbox.min.x); //compositor buffer + auto dbuffer = surface->buf8 + (bbox.min.y * surface->stride + bbox.min.x); //destination buffer + + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto cmp = cbuffer; + auto dst = dbuffer; + for (uint32_t x = 0; x < bbox.w(); ++x, ++cmp, ++dst) { + auto tmp = maskOp(a, *cmp, 0); //not use alpha. + *dst = tmp + MULTIPLY(*dst, ~tmp); + } + cbuffer += surface->compositor->image.stride; + dbuffer += surface->stride; + } + return true; +} + + +static bool _rasterMaskedRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + //8bit masking channels composition + if (surface->channelSize != sizeof(uint8_t)) return false; + + TVGLOG("SW_ENGINE", "Masked(%d) Rect [Region: %d %d %d %d]", (int)surface->compositor->method, bbox.min.x, bbox.min.y, bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y); + + auto maskOp = _getMaskOp(surface->compositor->method); + if (_direct(surface->compositor->method)) return _rasterDirectMaskedRect(surface, bbox, maskOp, c.a); + else return _rasterCompositeMaskedRect(surface, bbox, maskOp, c.a); + return false; +} + + +static bool _rasterMattedRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + auto csize = surface->compositor->image.channelSize; + auto cbuffer = surface->compositor->image.buf8 + ((bbox.min.y * surface->compositor->image.stride + bbox.min.x) * csize); //compositor buffer + auto alpha = surface->alpha(surface->compositor->method); + + TVGLOG("SW_ENGINE", "Matted(%d) Rect [Region: %u %u %u %u]", (int)surface->compositor->method, bbox.x(), bbox.y(), bbox.w(), bbox.h()); + + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto dst = &buffer[y * surface->stride]; + auto cmp = &cbuffer[y * surface->compositor->image.stride * csize]; + for (uint32_t x = 0; x < bbox.w(); ++x, ++dst, cmp += csize) { + auto tmp = ALPHA_BLEND(color, alpha(cmp)); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } + //8bits grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + auto buffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto dst = &buffer[y * surface->stride]; + auto cmp = &cbuffer[y * surface->compositor->image.stride * csize]; + for (uint32_t x = 0; x < bbox.w(); ++x, ++dst, cmp += csize) { + *dst = INTERPOLATE8(c.a, *dst, alpha(cmp)); + } + } + } + return true; +} + + +static bool _rasterBlendingRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + if (surface->channelSize != sizeof(uint32_t)) return false; + + auto color = surface->join(c.r, c.g, c.b, c.a); + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < bbox.w(); ++x, ++dst) { + *dst = surface->blender(color, *dst); + } + } + return true; +} + + +static bool _rasterTranslucentRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ +#if defined(THORVG_AVX_VECTOR_SUPPORT) + return avxRasterTranslucentRect(surface, bbox, c); +#elif defined(THORVG_NEON_VECTOR_SUPPORT) + return neonRasterTranslucentRect(surface, bbox, c); +#else + return cRasterTranslucentRect(surface, bbox, c); +#endif +} + + +static bool _rasterSolidRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, 255); + auto buffer = surface->buf32 + (bbox.min.y * surface->stride); + for (uint32_t y = 0; y < bbox.h(); ++y) { + rasterPixel32(buffer + y * surface->stride, color, bbox.min.x, bbox.w()); + } + return true; + } + //8bits grayscale + if (surface->channelSize == sizeof(uint8_t)) { + for (uint32_t y = 0; y < bbox.h(); ++y) { + rasterGrayscale8(surface->buf8, 255, (y + bbox.min.y) * surface->stride + bbox.min.x, bbox.w()); + } + return true; + } + return false; +} + + +static bool _rasterRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + if (_compositing(surface)) { + if (_matting(surface)) return _rasterMattedRect(surface, bbox, c); + else return _rasterMaskedRect(surface, bbox, c); + } else if (_blending(surface)) { + return _rasterBlendingRect(surface, bbox, c); + } else { + if (c.a == 255) return _rasterSolidRect(surface, bbox, c); + else return _rasterTranslucentRect(surface, bbox, c); + } + return false; +} + + +/************************************************************************/ +/* Rle */ +/************************************************************************/ + +static bool _rasterCompositeMaskedRle(SwSurface* surface, SwRle* rle, const RenderRegion& bbox, SwMask maskOp, uint8_t a) +{ + auto cbuffer = surface->compositor->image.buf8; + auto cstride = surface->compositor->image.stride; + const SwSpan* end; + int32_t x, len; + uint8_t src; + + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto cmp = &cbuffer[span->y * cstride + x]; + if (span->coverage == 255) src = a; + else src = MULTIPLY(a, span->coverage); + auto ialpha = 255 - src; + for (auto x = 0; x < len; ++x, ++cmp) { + *cmp = maskOp(src, *cmp, ialpha); + } + } + return _compositeMaskImage(surface, surface->compositor->image, surface->compositor->bbox); +} + + +static bool _rasterDirectMaskedRle(SwSurface* surface, SwRle* rle, const RenderRegion& bbox, SwMask maskOp, uint8_t a) +{ + auto cbuffer = surface->compositor->image.buf8; + auto cstride = surface->compositor->image.stride; + const SwSpan* end; + int32_t x, len; + uint8_t src; + + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto cmp = &cbuffer[span->y * cstride + x]; + auto dst = &surface->buf8[span->y * surface->stride + x]; + if (span->coverage == 255) src = a; + else src = MULTIPLY(a, span->coverage); + for (auto x = 0; x < len; ++x, ++cmp, ++dst) { + auto tmp = maskOp(src, *cmp, 0); //not use alpha + *dst = tmp + MULTIPLY(*dst, ~tmp); + } + } + return true; +} + + +static bool _rasterMaskedRle(SwSurface* surface, SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + TVGLOG("SW_ENGINE", "Masked(%d) Rle", (int)surface->compositor->method); + + //8bit masking channels composition + if (surface->channelSize != sizeof(uint8_t)) return false; + + auto maskOp = _getMaskOp(surface->compositor->method); + if (_direct(surface->compositor->method)) return _rasterDirectMaskedRle(surface, rle, bbox, maskOp, c.a); + else return _rasterCompositeMaskedRle(surface, rle, bbox, maskOp, c.a); + return false; +} + + +static bool _rasterMattedRle(SwSurface* surface, SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + TVGLOG("SW_ENGINE", "Matted(%d) Rle", (int)surface->compositor->method); + + auto cbuffer = surface->compositor->image.buf8; + auto csize = surface->compositor->image.channelSize; + auto alpha = surface->alpha(surface->compositor->method); + const SwSpan* end; + int32_t x, len; + + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + uint32_t src; + auto color = surface->join(c.r, c.g, c.b, c.a); + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + x) * csize]; + if (span->coverage == 255) src = color; + else src = ALPHA_BLEND(color, span->coverage); + for (auto x = 0; x < len; ++x, ++dst, cmp += csize) { + auto tmp = ALPHA_BLEND(src, alpha(cmp)); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + uint8_t src; + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf8[span->y * surface->stride + x]; + auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + x) * csize]; + if (span->coverage == 255) src = c.a; + else src = MULTIPLY(c.a, span->coverage); + for (auto x = 0; x < len; ++x, ++dst, cmp += csize) { + *dst = INTERPOLATE8(src, *dst, alpha(cmp)); + } + } + } + return true; +} + + +static bool _rasterBlendingRle(SwSurface* surface, const SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + if (surface->channelSize != sizeof(uint32_t)) return false; + + auto color = surface->join(c.r, c.g, c.b, c.a); + const SwSpan* end; + int32_t x, len; + + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf32[span->y * surface->stride + x]; + if (span->coverage == 255) { + for (auto x = 0; x < len; ++x, ++dst) { + *dst = surface->blender(color, *dst); + } + } else { + for (auto x = 0; x < len; ++x, ++dst) { + *dst = INTERPOLATE(surface->blender(color, *dst), *dst, span->coverage); + } + } + } + return true; +} + + +static bool _rasterTranslucentRle(SwSurface* surface, const SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ +#if defined(THORVG_AVX_VECTOR_SUPPORT) + return avxRasterTranslucentRle(surface, rle, bbox, c); +#elif defined(THORVG_NEON_VECTOR_SUPPORT) + return neonRasterTranslucentRle(surface, rle, bbox, c); +#else + return cRasterTranslucentRle(surface, rle, bbox, c); +#endif +} + + +static bool _rasterSolidRle(SwSurface* surface, const SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + const SwSpan* end; + int32_t x, len; + + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, 255); + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + if (span->coverage == 255) rasterPixel32(surface->buf32 + span->y * surface->stride, color, x, len); + else { + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto src = ALPHA_BLEND(color, span->coverage); + auto ialpha = 255 - span->coverage; + for (auto x = 0; x < len; ++x, ++dst) { + *dst = src + ALPHA_BLEND(*dst, ialpha); + } + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + if (span->coverage == 255) rasterGrayscale8(surface->buf8, span->coverage, span->y * surface->stride + x, len); + else { + auto dst = &surface->buf8[span->y * surface->stride + x]; + auto ialpha = 255 - span->coverage; + for (auto x = 0; x < len; ++x, ++dst) { + *dst = span->coverage + MULTIPLY(*dst, ialpha); + } + } + } + } + return true; +} + + +static bool _rasterRle(SwSurface* surface, SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + if (!rle || rle->invalid()) return false; + + if (_compositing(surface)) { + if (_matting(surface)) return _rasterMattedRle(surface, rle, bbox, c); + else return _rasterMaskedRle(surface, rle, bbox, c); + } else if (_blending(surface)) { + return _rasterBlendingRle(surface, rle, bbox, c); + } else { + if (c.a == 255) return _rasterSolidRle(surface, rle, bbox, c); + else return _rasterTranslucentRle(surface, rle, bbox, c); + } + return false; +} + + +/************************************************************************/ +/* RLE Scaled Image */ +/************************************************************************/ + +#define SCALED_IMAGE_RANGE_Y(y) \ + auto sy = (y) * itransform->e22 + itransform->e23 - 0.49f; \ + if (sy <= -0.5f || (uint32_t)(sy + 0.5f) >= image.h) continue; \ + if (scaleMethod == _interpDownScaler) { \ + auto my = (int32_t)nearbyint(sy); \ + miny = my - (int32_t)sampleSize; \ + if (miny < 0) miny = 0; \ + maxy = my + (int32_t)sampleSize; \ + if (maxy >= (int32_t)image.h) maxy = (int32_t)image.h; \ + } + +#define SCALED_IMAGE_RANGE_X \ + auto sx = (x) * itransform->e11 + itransform->e13 - 0.49f; \ + if (sx <= -0.5f || (uint32_t)(sx + 0.5f) >= image.w) continue; \ + +static bool _rasterScaledMaskedRleImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + TVGERR("SW_ENGINE", "Not Supported Scaled Masked(%d) Rle Image", (int)surface->compositor->method); + return false; +} + + +static bool _rasterScaledMattedRleImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + TVGLOG("SW_ENGINE", "Scaled Matted(%d) Rle Image", (int)surface->compositor->method); + + auto csize = surface->compositor->image.channelSize; + auto alpha = surface->alpha(surface->compositor->method); + auto scaleMethod = image.scale < DOWN_SCALE_TOLERANCE ? _interpDownScaler : _interpUpScaler; + auto sampleSize = _sampleSize(image.scale); + int32_t miny = 0, maxy = 0; + + ARRAY_FOREACH(span, image.rle->spans) { + SCALED_IMAGE_RANGE_Y(span->y) + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + auto cmp = &surface->compositor->image.buf8[(span->y * surface->compositor->image.stride + span->x) * csize]; + auto a = MULTIPLY(span->coverage, opacity); + for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst, cmp += csize) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + src = ALPHA_BLEND(src, (a == 255) ? alpha(cmp) : MULTIPLY(alpha(cmp), a)); + *dst = src + ALPHA_BLEND(*dst, IA(src)); + } + } + return true; +} + + +static bool _rasterScaledBlendingRleImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + auto scaleMethod = image.scale < DOWN_SCALE_TOLERANCE ? _interpDownScaler : _interpUpScaler; + auto sampleSize = _sampleSize(image.scale); + int32_t miny = 0, maxy = 0; + + ARRAY_FOREACH(span, image.rle->spans) { + SCALED_IMAGE_RANGE_Y(span->y) + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + auto alpha = MULTIPLY(span->coverage, opacity); + if (alpha == 255) { + for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + *dst = INTERPOLATE(surface->blender(rasterUnpremultiply(src), *dst), *dst, A(src)); + } + } else { + for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + *dst = INTERPOLATE(surface->blender(rasterUnpremultiply(src), *dst), *dst, MULTIPLY(alpha, A(src))); + } + } + } + return true; +} + + +static bool _rasterScaledRleImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + auto scaleMethod = image.scale < DOWN_SCALE_TOLERANCE ? _interpDownScaler : _interpUpScaler; + auto sampleSize = _sampleSize(image.scale); + int32_t miny = 0, maxy = 0; + + ARRAY_FOREACH(span, image.rle->spans) { + SCALED_IMAGE_RANGE_Y(span->y) + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + auto alpha = MULTIPLY(span->coverage, opacity); + for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + if (alpha < 255) src = ALPHA_BLEND(src, alpha); + *dst = src + ALPHA_BLEND(*dst, IA(src)); + } + } + return true; +} + + +/************************************************************************/ +/* RLE Direct Image */ +/************************************************************************/ + +static bool _rasterDirectMattedRleImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity) +{ + TVGLOG("SW_ENGINE", "Direct Matted(%d) Rle Image", (int)surface->compositor->method); + + auto csize = surface->compositor->image.channelSize; + auto cbuffer = surface->compositor->image.buf8; + auto alpha = surface->alpha(surface->compositor->method); + const SwSpan* end; + int32_t x, len; + + for (auto span = image.rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + x) * csize]; + auto img = image.buf32 + (span->y + image.oy) * image.stride + (x + image.ox); + auto a = MULTIPLY(span->coverage, opacity); + if (a == 255) { + for (auto x = 0; x < len; ++x, ++dst, ++img, cmp += csize) { + auto tmp = ALPHA_BLEND(*img, alpha(cmp)); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } else { + for (auto x = 0; x < len; ++x, ++dst, ++img, cmp += csize) { + auto tmp = ALPHA_BLEND(*img, MULTIPLY(a, alpha(cmp))); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } + } + return true; +} + + +static bool _rasterDirectBlendingRleImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity) +{ + const SwSpan* end; + int32_t x, len; + + for (auto span = image.rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto src = image.buf32 + (span->y + image.oy) * image.stride + (x + image.ox); + auto alpha = MULTIPLY(span->coverage, opacity); + if (alpha == 255) { + for (auto x = 0; x < len; ++x, ++dst, ++src) { + *dst = surface->blender(rasterUnpremultiply(*src), *dst); + } + } else { + for (auto x = 0; x < len; ++x, ++dst, ++src) { + *dst = INTERPOLATE(surface->blender(rasterUnpremultiply(*src), *dst), *dst, MULTIPLY(alpha, A(*src))); + } + } + } + return true; +} + + +static bool _rasterDirectRleImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity) +{ + const SwSpan* end; + int32_t x, len; + + for (auto span = image.rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto img = image.buf32 + (span->y + image.oy) * image.stride + (x + image.ox); + auto alpha = MULTIPLY(span->coverage, opacity); + rasterTranslucentPixel32(dst, img, len, alpha); + } + return true; +} + + +static bool _rasterDirectMaskedRleImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity) +{ + TVGERR("SW_ENGINE", "Not Supported Direct Masked(%d) Rle Image", (int)surface->compositor->method); + return false; +} + + +/************************************************************************/ +/*Scaled Image */ +/************************************************************************/ + +static bool _rasterScaledMaskedImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + TVGERR("SW_ENGINE", "Not Supported Scaled Masked Image!"); + return false; +} + + +static bool _rasterScaledMattedImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale scaled matted image!"); + return false; + } + + auto dbuffer = surface->buf32 + (bbox.min.y * surface->stride + bbox.min.x); + auto csize = surface->compositor->image.channelSize; + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * surface->compositor->image.stride + bbox.min.x) * csize; + auto alpha = surface->alpha(surface->compositor->method); + + TVGLOG("SW_ENGINE", "Scaled Matted(%d) Image [Region: %d %d %d %d]", (int)surface->compositor->method, bbox.min.x, bbox.min.y, bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y); + + auto scaleMethod = image.scale < DOWN_SCALE_TOLERANCE ? _interpDownScaler : _interpUpScaler; + auto sampleSize = _sampleSize(image.scale); + int32_t miny = 0, maxy = 0; + + for (auto y = bbox.min.y; y < bbox.max.y; ++y) { + SCALED_IMAGE_RANGE_Y(y) + auto dst = dbuffer; + auto cmp = cbuffer; + for (auto x = bbox.min.x; x < bbox.max.x; ++x, ++dst, cmp += csize) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + auto tmp = ALPHA_BLEND(src, opacity == 255 ? alpha(cmp) : MULTIPLY(opacity, alpha(cmp))); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + dbuffer += surface->stride; + cbuffer += surface->compositor->image.stride * csize; + } + return true; +} + + +static bool _rasterScaledBlendingImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale scaled blending image!"); + return false; + } + + auto dbuffer = surface->buf32 + (bbox.min.y * surface->stride + bbox.min.x); + auto scaleMethod = image.scale < DOWN_SCALE_TOLERANCE ? _interpDownScaler : _interpUpScaler; + auto sampleSize = _sampleSize(image.scale); + int32_t miny = 0, maxy = 0; + + for (auto y = bbox.min.y; y < bbox.max.y; ++y, dbuffer += surface->stride) { + SCALED_IMAGE_RANGE_Y(y) + auto dst = dbuffer; + for (auto x = bbox.min.x; x < bbox.max.x; ++x, ++dst) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + *dst = INTERPOLATE(surface->blender(rasterUnpremultiply(src), *dst), *dst, MULTIPLY(opacity, A(src))); + } + } + return true; +} + + +static bool _rasterScaledImage(SwSurface* surface, const SwImage& image, const Matrix* itransform, const RenderRegion& bbox, uint8_t opacity) +{ + auto scaleMethod = image.scale < DOWN_SCALE_TOLERANCE ? _interpDownScaler : _interpUpScaler; + auto sampleSize = _sampleSize(image.scale); + int32_t miny = 0, maxy = 0; + + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto buffer = surface->buf32 + (bbox.min.y * surface->stride + bbox.min.x); + for (auto y = bbox.min.y; y < bbox.max.y; ++y, buffer += surface->stride) { + SCALED_IMAGE_RANGE_Y(y) + auto dst = buffer; + for (auto x = bbox.min.x; x < bbox.max.x; ++x, ++dst) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + if (opacity < 255) src = ALPHA_BLEND(src, opacity); + *dst = src + ALPHA_BLEND(*dst, IA(src)); + } + } + } else if (surface->channelSize == sizeof(uint8_t)) { + auto buffer = surface->buf8 + (bbox.min.y * surface->stride + bbox.min.x); + for (auto y = bbox.min.y; y < bbox.max.y; ++y, buffer += surface->stride) { + SCALED_IMAGE_RANGE_Y(y) + auto dst = buffer; + for (auto x = bbox.min.x; x < bbox.max.x; ++x, ++dst) { + SCALED_IMAGE_RANGE_X + auto src = scaleMethod(image.buf32, image.stride, image.w, image.h, sx, sy, miny, maxy, sampleSize); + *dst = MULTIPLY(A(src), opacity); + } + } + } + return true; +} + + +/************************************************************************/ +/* Direct Image */ +/************************************************************************/ + +static bool _rasterDirectMaskedImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int32_t w, int32_t h, uint8_t opacity) +{ + TVGERR("SW_ENGINE", "Not Supported: Direct Masked Image"); + return false; +} + + +static bool _rasterDirectMattedImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int32_t w, int32_t h, uint8_t opacity) +{ + auto csize = surface->compositor->image.channelSize; + auto alpha = surface->alpha(surface->compositor->method); + auto sbuffer = image.buf32 + (bbox.min.y + image.oy) * image.stride + (bbox.min.x + image.ox); + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * surface->compositor->image.stride + bbox.min.x) * csize; //compositor buffer + + TVGLOG("SW_ENGINE", "Direct Matted(%d) Image [Region: %u %u %u %u]", (int)surface->compositor->method, bbox.x(), bbox.y(), bbox.w(), bbox.h()); + + //32 bits + if (surface->channelSize == sizeof(uint32_t)) { + auto dbuffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + for (auto y = 0; y < h; ++y, dbuffer += surface->stride, sbuffer += image.stride) { + auto cmp = cbuffer; + auto src = sbuffer; + if (opacity == 255) { + for (auto dst = dbuffer; dst < dbuffer + w; ++dst, ++src, cmp += csize) { + auto tmp = ALPHA_BLEND(*src, alpha(cmp)); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } else { + for (auto dst = dbuffer; dst < dbuffer + w; ++dst, ++src, cmp += csize) { + auto tmp = ALPHA_BLEND(*src, MULTIPLY(opacity, alpha(cmp))); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } + cbuffer += surface->compositor->image.stride * csize; + } + //8 bits + } else if (surface->channelSize == sizeof(uint8_t)) { + auto dbuffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + for (auto y = 0; y < h; ++y, dbuffer += surface->stride, sbuffer += image.stride) { + auto cmp = cbuffer; + auto src = sbuffer; + if (opacity == 255) { + for (auto dst = dbuffer; dst < dbuffer + w; ++dst, ++src, cmp += csize) { + auto tmp = MULTIPLY(A(*src), alpha(cmp)); + *dst = tmp + MULTIPLY(*dst, 255 - tmp); + } + } else { + for (auto dst = dbuffer; dst < dbuffer + w; ++dst, ++src, cmp += csize) { + auto tmp = MULTIPLY(A(*src), MULTIPLY(opacity, alpha(cmp))); + *dst = tmp + MULTIPLY(*dst, 255 - tmp); + } + } + cbuffer += surface->compositor->image.stride * csize; + } + } + return true; +} + + +static bool _rasterDirectBlendingImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int32_t w, int32_t h, uint8_t opacity) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale image!"); + return false; + } + + auto dbuffer = &surface->buf32[bbox.min.y * surface->stride + bbox.min.x]; + auto sbuffer = image.buf32 + (bbox.min.y + image.oy) * image.stride + (bbox.min.x + image.ox); + + for (auto y = 0; y < h; ++y, dbuffer += surface->stride, sbuffer += image.stride) { + auto src = sbuffer; + if (opacity == 255) { + for (auto dst = dbuffer; dst < dbuffer + w; dst++, src++) { + *dst = INTERPOLATE(surface->blender(rasterUnpremultiply(*src), *dst), *dst, A(*src)); + } + } else { + for (auto dst = dbuffer; dst < dbuffer + w; dst++, src++) { + *dst = INTERPOLATE(surface->blender(rasterUnpremultiply(*src), *dst), *dst, MULTIPLY(opacity, A(*src))); + } + } + } + return true; +} + + +static bool _rasterDirectImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int32_t w, int32_t h, uint8_t opacity) +{ + auto sbuffer = image.buf32 + (bbox.min.y + image.oy) * image.stride + (bbox.min.x + image.ox); + + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto dbuffer = &surface->buf32[bbox.min.y * surface->stride + bbox.min.x]; + for (auto y = 0; y < h; ++y, dbuffer += surface->stride, sbuffer += image.stride) { + rasterTranslucentPixel32(dbuffer, sbuffer, w, opacity); + } + //8bits grayscale + //32 -> 8 direct converting seems an avoidable stage. maybe draw to a masking image after an intermediate scene. Can get rid of this? + } else if (surface->channelSize == sizeof(uint8_t)) { + auto dbuffer = &surface->buf8[bbox.min.y * surface->stride + bbox.min.x]; + for (auto y = 0; y < h; ++y, dbuffer += surface->stride, sbuffer += image.stride) { + auto src = sbuffer; + if (opacity == 255) { + for (auto dst = dbuffer; dst < dbuffer + w; dst++, src++) { + *dst = A(*src) + MULTIPLY(*dst, IA(*src)); + } + } else { + for (auto dst = dbuffer; dst < dbuffer + w; dst++, src++) { + *dst = INTERPOLATE8(A(*src), *dst, opacity); + } + } + } + } + return true; +} + + +static bool _rasterDirectMattedBlendingImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int32_t w, int32_t h, uint8_t opacity) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale image!"); + return false; + } + + auto csize = surface->compositor->image.channelSize; + auto alpha = surface->alpha(surface->compositor->method); + auto sbuffer = image.buf32 + (bbox.min.y + image.oy) * image.stride + (bbox.min.x + image.ox); + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * surface->compositor->image.stride + bbox.min.x) * csize; //compositor buffer + auto dbuffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + + for (auto y = 0; y < h; ++y, dbuffer += surface->stride, sbuffer += image.stride) { + auto cmp = cbuffer; + auto src = sbuffer; + if (opacity == 255) { + for (auto dst = dbuffer; dst < dbuffer + w; ++dst, ++src, cmp += csize) { + *dst = INTERPOLATE(surface->blender(*src, *dst), *dst, MULTIPLY(A(*src), alpha(cmp))); + } + } else { + for (auto dst = dbuffer; dst < dbuffer + w; ++dst, ++src, cmp += csize) { + *dst = INTERPOLATE(surface->blender(*src, *dst), *dst, MULTIPLY(MULTIPLY(A(*src), alpha(cmp)), opacity)); + } + } + cbuffer += surface->compositor->image.stride * csize; + } + return true; +} + + +/************************************************************************/ +/* Rect Gradient */ +/************************************************************************/ + +template +static bool _rasterCompositeGradientMaskedRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill, SwMask maskOp) +{ + auto cstride = surface->compositor->image.stride; + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * cstride + bbox.min.x); + + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, cbuffer, bbox.min.y + y, bbox.min.x, bbox.w(), maskOp, 255); + cbuffer += surface->stride; + } + return _compositeMaskImage(surface, surface->compositor->image, surface->compositor->bbox); +} + + +template +static bool _rasterDirectGradientMaskedRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill, SwMask maskOp) +{ + auto cstride = surface->compositor->image.stride; + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * cstride + bbox.min.x); + auto dbuffer = surface->buf8 + (bbox.min.y * surface->stride + bbox.min.x); + + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, dbuffer, bbox.min.y + y, bbox.min.x, bbox.w(), cbuffer, maskOp, 255); + cbuffer += cstride; + dbuffer += surface->stride; + } + return true; +} + + +template +static bool _rasterGradientMaskedRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + auto method = surface->compositor->method; + + TVGLOG("SW_ENGINE", "Masked(%d) Gradient [Region: %d %d %d %d]", (int)method, bbox.min.x, bbox.min.y, bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y); + + auto maskOp = _getMaskOp(method); + + if (_direct(method)) return _rasterDirectGradientMaskedRect(surface, bbox, fill, maskOp); + else return _rasterCompositeGradientMaskedRect(surface, bbox, fill, maskOp); + + return false; +} + + +template +static bool _rasterGradientMattedRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + auto csize = surface->compositor->image.channelSize; + auto cbuffer = surface->compositor->image.buf8 + (bbox.min.y * surface->compositor->image.stride + bbox.min.x) * csize; + auto alpha = surface->alpha(surface->compositor->method); + + TVGLOG("SW_ENGINE", "Matted(%d) Gradient [Region: %u %u %u %u]", (int)surface->compositor->method, bbox.x(), bbox.y(), bbox.w(), bbox.h()); + + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer, bbox.min.y + y, bbox.min.x, bbox.w(), cbuffer, alpha, csize, 255); + buffer += surface->stride; + cbuffer += surface->stride * csize; + } + return true; +} + + +template +static bool _rasterBlendingGradientRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + + if (fill->translucent) { + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer + y * surface->stride, bbox.min.y + y, bbox.min.x, bbox.w(), opBlendPreNormal, surface->blender, 255); + } + } else { + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer + y * surface->stride, bbox.min.y + y, bbox.min.x, bbox.w(), opBlendSrcOver, surface->blender, 255); + } + } + return true; +} + +template +static bool _rasterTranslucentGradientRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + //32 bits + if (surface->channelSize == sizeof(uint32_t)) { + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer, bbox.min.y + y, bbox.min.x, bbox.w(), opBlendPreNormal, 255); + buffer += surface->stride; + } + //8 bits + } else if (surface->channelSize == sizeof(uint8_t)) { + auto buffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer, bbox.min.y + y, bbox.min.x, bbox.w(), _opMaskAdd, 255); + buffer += surface->stride; + } + } + return true; +} + + +template +static bool _rasterSolidGradientRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + //32 bits + if (surface->channelSize == sizeof(uint32_t)) { + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer, bbox.min.y + y, bbox.min.x, bbox.w(), opBlendSrcOver, 255); + buffer += surface->stride; + } + //8 bits + } else if (surface->channelSize == sizeof(uint8_t)) { + auto buffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + for (uint32_t y = 0; y < bbox.h(); ++y) { + fillMethod()(fill, buffer, bbox.min.y + y, bbox.min.x, bbox.w(), _opMaskNone, 255); + buffer += surface->stride; + } + } + return true; +} + + +static bool _rasterLinearGradientRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + if (_compositing(surface)) { + if (_matting(surface)) return _rasterGradientMattedRect(surface, bbox, fill); + else return _rasterGradientMaskedRect(surface, bbox, fill); + } else if (_blending(surface)) { + return _rasterBlendingGradientRect(surface, bbox, fill); + } else { + if (fill->translucent) return _rasterTranslucentGradientRect(surface, bbox, fill); + else _rasterSolidGradientRect(surface, bbox, fill); + } + return false; +} + + +static bool _rasterRadialGradientRect(SwSurface* surface, const RenderRegion& bbox, const SwFill* fill) +{ + if (_compositing(surface)) { + if (_matting(surface)) return _rasterGradientMattedRect(surface, bbox, fill); + else return _rasterGradientMaskedRect(surface, bbox, fill); + } else if (_blending(surface)) { + return _rasterBlendingGradientRect(surface, bbox, fill); + } else { + if (fill->translucent) return _rasterTranslucentGradientRect(surface, bbox, fill); + else _rasterSolidGradientRect(surface, bbox, fill); + } + return false; +} + + +/************************************************************************/ +/* Rle Gradient */ +/************************************************************************/ + +template +static bool _rasterCompositeGradientMaskedRle(SwSurface* surface, const SwRle* rle, const SwFill* fill, SwMask maskOp) +{ + auto span = rle->data(); + auto cstride = surface->compositor->image.stride; + auto cbuffer = surface->compositor->image.buf8; + + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto cmp = &cbuffer[span->y * cstride + span->x]; + fillMethod()(fill, cmp, span->y, span->x, span->len, maskOp, span->coverage); + } + return _compositeMaskImage(surface, surface->compositor->image, surface->compositor->bbox); +} + + +template +static bool _rasterDirectGradientMaskedRle(SwSurface* surface, const SwRle* rle, const SwFill* fill, SwMask maskOp) +{ + auto span = rle->data(); + auto cstride = surface->compositor->image.stride; + auto cbuffer = surface->compositor->image.buf8; + auto dbuffer = surface->buf8; + + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto cmp = &cbuffer[span->y * cstride + span->x]; + auto dst = &dbuffer[span->y * surface->stride + span->x]; + fillMethod()(fill, dst, span->y, span->x, span->len, cmp, maskOp, span->coverage); + } + return true; +} + + +template +static bool _rasterGradientMaskedRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + auto method = surface->compositor->method; + + TVGLOG("SW_ENGINE", "Masked(%d) Rle Linear Gradient", (int)method); + + auto maskOp = _getMaskOp(method); + + if (_direct(method)) return _rasterDirectGradientMaskedRle(surface, rle, fill, maskOp); + else return _rasterCompositeGradientMaskedRle(surface, rle, fill, maskOp); + return false; +} + + +template +static bool _rasterGradientMattedRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + TVGLOG("SW_ENGINE", "Matted(%d) Rle Linear Gradient", (int)surface->compositor->method); + + auto span = rle->data(); + auto csize = surface->compositor->image.channelSize; + auto cbuffer = surface->compositor->image.buf8; + auto alpha = surface->alpha(surface->compositor->method); + + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; + fillMethod()(fill, dst, span->y, span->x, span->len, cmp, alpha, csize, span->coverage); + } + return true; +} + + +template +static bool _rasterBlendingGradientRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + auto span = rle->data(); + + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + fillMethod()(fill, dst, span->y, span->x, span->len, opBlendPreNormal, surface->blender, span->coverage); + } + return true; +} + + +template +static bool _rasterTranslucentGradientRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + auto span = rle->data(); + + //32 bits + if (surface->channelSize == sizeof(uint32_t)) { + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + if (span->coverage == 255) fillMethod()(fill, dst, span->y, span->x, span->len, opBlendPreNormal, 255); + else fillMethod()(fill, dst, span->y, span->x, span->len, opBlendNormal, span->coverage); + } + //8 bits + } else if (surface->channelSize == sizeof(uint8_t)) { + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto dst = &surface->buf8[span->y * surface->stride + span->x]; + fillMethod()(fill, dst, span->y, span->x, span->len, _opMaskAdd, span->coverage); + } + } + return true; +} + + +template +static bool _rasterSolidGradientRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + auto span = rle->data(); + + //32 bits + if (surface->channelSize == sizeof(uint32_t)) { + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + if (span->coverage == 255) fillMethod()(fill, dst, span->y, span->x, span->len, opBlendSrcOver, 255); + else fillMethod()(fill, dst, span->y, span->x, span->len, opBlendInterp, span->coverage); + } + //8 bits + } else if (surface->channelSize == sizeof(uint8_t)) { + for (uint32_t i = 0; i < rle->size(); ++i, ++span) { + auto dst = &surface->buf8[span->y * surface->stride + span->x]; + if (span->coverage == 255) fillMethod()(fill, dst, span->y, span->x, span->len, _opMaskNone, 255); + else fillMethod()(fill, dst, span->y, span->x, span->len, _opMaskAdd, span->coverage); + } + } + + return true; +} + + +static bool _rasterLinearGradientRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + if (_compositing(surface)) { + if (_matting(surface)) return _rasterGradientMattedRle(surface, rle, fill); + else return _rasterGradientMaskedRle(surface, rle, fill); + } else if (_blending(surface)) { + return _rasterBlendingGradientRle(surface, rle, fill); + } else { + if (fill->translucent) return _rasterTranslucentGradientRle(surface, rle, fill); + else return _rasterSolidGradientRle(surface, rle, fill); + } + return false; +} + + +static bool _rasterRadialGradientRle(SwSurface* surface, const SwRle* rle, const SwFill* fill) +{ + if (_compositing(surface)) { + if (_matting(surface)) return _rasterGradientMattedRle(surface, rle, fill); + else return _rasterGradientMaskedRle(surface, rle, fill); + } else if (_blending(surface)) { + return _rasterBlendingGradientRle(surface, rle, fill); + } else { + if (fill->translucent) return _rasterTranslucentGradientRle(surface, rle, fill); + else return _rasterSolidGradientRle(surface, rle, fill); + } + return false; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +void rasterTranslucentPixel32(uint32_t* dst, uint32_t* src, uint32_t len, uint8_t opacity) +{ + //TODO: Support SIMD accelerations + cRasterTranslucentPixels(dst, src, len, opacity); +} + + +void rasterPixel32(uint32_t* dst, uint32_t* src, uint32_t len, uint8_t opacity) +{ + //TODO: Support SIMD accelerations + cRasterPixels(dst, src, len, opacity); +} + + +void rasterGrayscale8(uint8_t *dst, uint8_t val, uint32_t offset, int32_t len) +{ +#if defined(THORVG_AVX_VECTOR_SUPPORT) + avxRasterGrayscale8(dst, val, offset, len); +#elif defined(THORVG_NEON_VECTOR_SUPPORT) + neonRasterGrayscale8(dst, val, offset, len); +#else + cRasterPixels(dst, val, offset, len); +#endif +} + + +void rasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len) +{ +#if defined(THORVG_AVX_VECTOR_SUPPORT) + avxRasterPixel32(dst, val, offset, len); +#elif defined(THORVG_NEON_VECTOR_SUPPORT) + neonRasterPixel32(dst, val, offset, len); +#else + cRasterPixels(dst, val, offset, len); +#endif +} + + +bool rasterCompositor(SwSurface* surface) +{ + //See MaskMethod, Alpha:1, InvAlpha:2, Luma:3, InvLuma:4 + surface->alphas[0] = _alpha; + surface->alphas[1] = _ialpha; + + if (surface->cs == ColorSpace::ABGR8888 || surface->cs == ColorSpace::ABGR8888S) { + surface->join = _abgrJoin; + surface->alphas[2] = _abgrLuma; + surface->alphas[3] = _abgrInvLuma; + } else if (surface->cs == ColorSpace::ARGB8888 || surface->cs == ColorSpace::ARGB8888S) { + surface->join = _argbJoin; + surface->alphas[2] = _argbLuma; + surface->alphas[3] = _argbInvLuma; + } else { + TVGERR("SW_ENGINE", "Unsupported Colorspace(%d) is expected!", (int)surface->cs); + return false; + } + return true; +} + + +bool rasterClear(SwSurface* surface, uint32_t x, uint32_t y, uint32_t w, uint32_t h) +{ + if (!surface || !surface->buf32 || surface->stride == 0 || surface->w == 0 || surface->h == 0) return false; + + //32 bits + if (surface->channelSize == sizeof(uint32_t)) { + uint32_t val = 0; + //full clear + if (w == surface->stride) { + rasterPixel32(surface->buf32, val, surface->stride * y, w * h); + //partial clear + } else { + for (uint32_t i = 0; i < h; i++) { + rasterPixel32(surface->buf32, val, (surface->stride * y + x) + (surface->stride * i), w); + } + } + //8 bits + } else if (surface->channelSize == sizeof(uint8_t)) { + //full clear + if (w == surface->stride) { + rasterGrayscale8(surface->buf8, 0x00, surface->stride * y, w * h); + //partial clear + } else { + for (uint32_t i = 0; i < h; i++) { + rasterGrayscale8(surface->buf8, 0x00, (surface->stride * y + x) + (surface->stride * i), w); + } + } + } + return true; +} + + +uint32_t rasterUnpremultiply(uint32_t data) +{ + auto a = A(data); + if (a == 255 || a == 0) return data; + + uint8_t r = std::min(C1(data) * 255u / a, 255u); + uint8_t g = std::min(C2(data) * 255u / a, 255u); + uint8_t b = std::min(C3(data) * 255u / a, 255u); + + return JOIN(a, r, g, b); +} + + +void rasterUnpremultiply(RenderSurface* surface) +{ + if (surface->channelSize != sizeof(uint32_t)) return; + + TVGLOG("SW_ENGINE", "Unpremultiply [Size: %d x %d]", surface->w, surface->h); + + //OPTIMIZE_ME: +SIMD + for (uint32_t y = 0; y < surface->h; y++) { + auto buffer = surface->buf32 + surface->stride * y; + for (uint32_t x = 0; x < surface->w; ++x) { + buffer[x] = rasterUnpremultiply(buffer[x]); + } + } + surface->premultiplied = false; +} + + +void rasterPremultiply(RenderSurface* surface) +{ + ScopedLock lock(surface->key); + if (surface->premultiplied || (surface->channelSize != sizeof(uint32_t))) return; + surface->premultiplied = true; + + TVGLOG("SW_ENGINE", "Premultiply [Size: %d x %d]", surface->w, surface->h); + + //OPTIMIZE_ME: +SIMD + auto buffer = surface->buf32; + for (uint32_t y = 0; y < surface->h; ++y, buffer += surface->stride) { + auto dst = buffer; + for (uint32_t x = 0; x < surface->w; ++x, ++dst) { + auto c = *dst; + if (A(c) == 255) continue; + *dst = PREMULTIPLY(c, A(c)); + } + } +} + + +bool rasterScaledImage(SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity) +{ + Matrix itransform; + + if (!inverse(&transform, &itransform)) return true; + + if (_compositing(surface)) { + if (_matting(surface)) return _rasterScaledMattedImage(surface, image, &itransform, bbox, opacity); + else return _rasterScaledMaskedImage(surface, image, &itransform, bbox, opacity); + } else if (_blending(surface)) { + return _rasterScaledBlendingImage(surface, image, &itransform, bbox, opacity); + } else { + return _rasterScaledImage(surface, image, &itransform, bbox, opacity); + } + return false; +} + + +bool rasterDirectImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity) +{ + //calculate an actual drawing image size + auto w = std::min(bbox.max.x - bbox.min.x, int32_t(image.w) - (bbox.min.x + image.ox)); + auto h = std::min(bbox.max.y - bbox.min.y, int32_t(image.h) - (bbox.min.y + image.oy)); + + if (_compositing(surface)) { + if (_matting(surface)) { + if (_blending(surface)) return _rasterDirectMattedBlendingImage(surface, image, bbox, w, h, opacity); + else return _rasterDirectMattedImage(surface, image, bbox, w, h, opacity); + } else return _rasterDirectMaskedImage(surface, image, bbox, w, h, opacity); + } else if (_blending(surface)) { + return _rasterDirectBlendingImage(surface, image, bbox, w, h, opacity); + } else { + return _rasterDirectImage(surface, image, bbox, w, h, opacity); + } + return false; +} + + +bool rasterScaledRleImage(SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported scaled rle image!"); + return false; + } + + Matrix itransform; + + if (!inverse(&transform, &itransform)) return true; + + if (_compositing(surface)) { + if (_matting(surface)) return _rasterScaledMattedRleImage(surface, image, &itransform, bbox, opacity); + else return _rasterScaledMaskedRleImage(surface, image, &itransform, bbox, opacity); + } else if (_blending(surface)) { + return _rasterScaledBlendingRleImage(surface, image, &itransform, bbox, opacity); + } else { + return _rasterScaledRleImage(surface, image, &itransform, bbox, opacity); + } + return false; +} + + +bool rasterDirectRleImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, uint8_t opacity) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale rle image!"); + return false; + } + + if (_compositing(surface)) { + if (_matting(surface)) return _rasterDirectMattedRleImage(surface, image, bbox, opacity); + else return _rasterDirectMaskedRleImage(surface, image, bbox, opacity); + } else if (_blending(surface)) { + return _rasterDirectBlendingRleImage(surface, image, bbox, opacity); + } else { + return _rasterDirectRleImage(surface, image, bbox, opacity); + } + return false; +} + + +bool rasterGradientShape(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, const Fill* fdata, uint8_t opacity) +{ + if (!shape->fill) return false; + + if (auto color = fillFetchSolid(shape->fill, fdata)) { + auto a = MULTIPLY(color->a, opacity); + RenderColor c = {color->r, color->g, color->b, a}; + return a > 0 ? rasterShape(surface, shape, bbox, c) : true; + } + + auto type = fdata->type(); + if (shape->fastTrack) { + if (type == Type::LinearGradient) return _rasterLinearGradientRect(surface, bbox, shape->fill); + else if (type == Type::RadialGradient)return _rasterRadialGradientRect(surface, bbox, shape->fill); + } else if (shape->rle && shape->rle->valid()) { + if (type == Type::LinearGradient) return _rasterLinearGradientRle(surface, shape->rle, shape->fill); + else if (type == Type::RadialGradient) return _rasterRadialGradientRle(surface, shape->rle, shape->fill); + } return false; +} + + +bool rasterGradientStroke(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, const Fill* fdata, uint8_t opacity) +{ + if (!shape->stroke || !shape->stroke->fill || !shape->strokeRle || shape->strokeRle->invalid()) return false; + + if (auto color = fillFetchSolid(shape->stroke->fill, fdata)) { + RenderColor c = {color->r, color->g, color->b, color->a}; + c.a = MULTIPLY(c.a, opacity); + return c.a > 0 ? rasterStroke(surface, shape, bbox, c) : true; + } + + auto type = fdata->type(); + if (type == Type::LinearGradient) return _rasterLinearGradientRle(surface, shape->strokeRle, shape->stroke->fill); + else if (type == Type::RadialGradient) return _rasterRadialGradientRle(surface, shape->strokeRle, shape->stroke->fill); + return false; +} + + +bool rasterShape(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, RenderColor& c) +{ + if (c.a < 255) { + c.r = MULTIPLY(c.r, c.a); + c.g = MULTIPLY(c.g, c.a); + c.b = MULTIPLY(c.b, c.a); + } + if (shape->fastTrack) return _rasterRect(surface, bbox, c); + else return _rasterRle(surface, shape->rle, bbox, c); +} + + +bool rasterStroke(SwSurface* surface, SwShape* shape, const RenderRegion& bbox, RenderColor& c) +{ + if (c.a < 255) { + c.r = MULTIPLY(c.r, c.a); + c.g = MULTIPLY(c.g, c.a); + c.b = MULTIPLY(c.b, c.a); + } + + return _rasterRle(surface, shape->strokeRle, bbox, c); +} + + +bool rasterConvertCS(RenderSurface* surface, ColorSpace to) +{ + ScopedLock lock(surface->key); + if (surface->cs == to) return true; + + //TODO: Support SIMD accelerations + auto from = surface->cs; + + if (((from == ColorSpace::ABGR8888) || (from == ColorSpace::ABGR8888S)) && ((to == ColorSpace::ARGB8888) || (to == ColorSpace::ARGB8888S))) { + surface->cs = to; + return cRasterABGRtoARGB(surface); + } + if (((from == ColorSpace::ARGB8888) || (from == ColorSpace::ARGB8888S)) && ((to == ColorSpace::ABGR8888) || (to == ColorSpace::ABGR8888S))) { + surface->cs = to; + return cRasterARGBtoABGR(surface); + } + return false; +} + + +//TODO: SIMD OPTIMIZATION? +void rasterXYFlip(uint32_t* src, uint32_t* dst, int32_t stride, int32_t w, int32_t h, const RenderRegion& bbox, bool flipped) +{ + constexpr int32_t BLOCK = 8; //experimental decision + + if (flipped) { + src += ((bbox.min.x * stride) + bbox.min.y); + dst += ((bbox.min.y * stride) + bbox.min.x); + } else { + src += ((bbox.min.y * stride) + bbox.min.x); + dst += ((bbox.min.x * stride) + bbox.min.y); + } + + #pragma omp parallel for + for (int32_t x = 0; x < w; x += BLOCK) { + auto bx = std::min(w, x + BLOCK) - x; + auto in = &src[x]; + auto out = &dst[x * stride]; + for (int32_t y = 0; y < h; y += BLOCK) { + auto p = &in[y * stride]; + auto q = &out[y]; + auto by = std::min(h, y + BLOCK) - y; + for (int32_t xx = 0; xx < bx; ++xx) { + for (int32_t yy = 0; yy < by; ++yy) { + *q = *p; + p += stride; + ++q; + } + p += 1 - by * stride; + q += stride - by; + } + } + } +} + + +//TODO: can be moved in tvgColor +void rasterRGB2HSL(uint8_t r, uint8_t g, uint8_t b, float* h, float* s, float* l) +{ + auto rf = r / 255.0f; + auto gf = g / 255.0f; + auto bf = b / 255.0f; + auto maxVal = std::max(std::max(rf, gf), bf); + auto minVal = std::min(std::min(rf, gf), bf); + auto delta = maxVal - minVal; + + //lightness + float t = 0.0f; + if (l || s) { + t = (maxVal + minVal) * 0.5f; + if (l) *l = t; + } + + if (tvg::zero(delta)) { + if (h) *h = 0.0f; + if (s) *s = 0.0f; + } else { + //saturation + if (s) { + *s = (t < 0.5f) ? (delta / (maxVal + minVal)) : (delta / (2.0f - maxVal - minVal)); + } + //hue + if (h) { + if (maxVal == rf) *h = (gf - bf) / delta + (gf < bf ? 6.0f : 0.0f); + else if (maxVal == gf) *h = (bf - rf) / delta + 2.0f; + else *h = (rf - gf) / delta + 4.0f; + *h *= 60.0f; //directly convert to degrees + } + } +} diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterAvx.h b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterAvx.h new file mode 100644 index 0000000..b5c30ab --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterAvx.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef THORVG_AVX_VECTOR_SUPPORT + +#include + +#define N_32BITS_IN_128REG 4 +#define N_32BITS_IN_256REG 8 + +static inline __m128i ALPHA_BLEND(__m128i c, __m128i a) +{ + //1. set the masks for the A/G and R/B channels + auto AG = _mm_set1_epi32(0xff00ff00); + auto RB = _mm_set1_epi32(0x00ff00ff); + + //2. mask the alpha vector - originally quartet [a, a, a, a] + auto aAG = _mm_and_si128(a, AG); + auto aRB = _mm_and_si128(a, RB); + + //3. calculate the alpha blending of the 2nd and 4th channel + //- mask the color vector + //- multiply it by the masked alpha vector + //- add the correction to compensate bit shifting used instead of dividing by 255 + //- shift bits - corresponding to division by 256 + auto even = _mm_and_si128(c, RB); + even = _mm_mullo_epi16(even, aRB); + even =_mm_add_epi16(even, RB); + even = _mm_srli_epi16(even, 8); + + //4. calculate the alpha blending of the 1st and 3rd channel: + //- mask the color vector + //- multiply it by the corresponding masked alpha vector and store the high bits of the result + //- add the correction to compensate division by 256 instead of by 255 (next step) + //- remove the low 8 bits to mimic the division by 256 + auto odd = _mm_and_si128(c, AG); + odd = _mm_mulhi_epu16(odd, aAG); + odd = _mm_add_epi16(odd, RB); + odd = _mm_and_si128(odd, AG); + + //5. the final result + return _mm_or_si128(odd, even); +} + + +static void avxRasterGrayscale8(uint8_t* dst, uint8_t val, uint32_t offset, int32_t len) +{ + dst += offset; + + __m256i vecVal = _mm256_set1_epi8(val); + + int32_t i = 0; + for (; i <= len - 32; i += 32) { + _mm256_storeu_si256((__m256i*)(dst + i), vecVal); + } + + for (; i < len; ++i) { + dst[i] = val; + } +} + + +static void avxRasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len) +{ + //1. calculate how many iterations we need to cover the length + uint32_t iterations = len / N_32BITS_IN_256REG; + uint32_t avxFilled = iterations * N_32BITS_IN_256REG; + + //2. set the beginning of the array + dst += offset; + + //3. fill the octets + for (uint32_t i = 0; i < iterations; ++i, dst += N_32BITS_IN_256REG) { + _mm256_storeu_si256((__m256i*)dst, _mm256_set1_epi32(val)); + } + + //4. fill leftovers (in the first step we have to set the pointer to the place where the avx job is done) + int32_t leftovers = len - avxFilled; + while (leftovers--) *dst++ = val; +} + + +static bool avxRasterTranslucentRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + auto h = bbox.h(); + auto w = bbox.w(); + + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + + uint32_t ialpha = 255 - c.a; + + auto avxColor = _mm_set1_epi32(color); + auto avxIalpha = _mm_set1_epi8(ialpha); + + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + + //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) + auto notAligned = ((uintptr_t)dst & 0xf) / 4; + if (notAligned) { + notAligned = (N_32BITS_IN_128REG - notAligned > w ? w : N_32BITS_IN_128REG - notAligned); + for (uint32_t x = 0; x < notAligned; ++x, ++dst) { + *dst = color + ALPHA_BLEND(*dst, ialpha); + } + } + + //2. fill the aligned memory - N_32BITS_IN_128REG pixels processed at once + uint32_t iterations = (w - notAligned) / N_32BITS_IN_128REG; + uint32_t avxFilled = iterations * N_32BITS_IN_128REG; + auto avxDst = (__m128i*)dst; + for (uint32_t x = 0; x < iterations; ++x, ++avxDst) { + *avxDst = _mm_add_epi32(avxColor, ALPHA_BLEND(*avxDst, avxIalpha)); + } + + //3. fill the remaining pixels + int32_t leftovers = w - notAligned - avxFilled; + dst += avxFilled; + while (leftovers--) { + *dst = color + ALPHA_BLEND(*dst, ialpha); + dst++; + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require AVX Optimization, Channel Size = %d", surface->channelSize); + auto buffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + auto ialpha = ~c.a; + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < w; ++x, ++dst) { + *dst = c.a + MULTIPLY(*dst, ialpha); + } + } + } + return true; +} + + +static bool avxRasterTranslucentRle(SwSurface* surface, const SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + const SwSpan* end; + int32_t x, len; + + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + uint32_t src; + + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); + else src = color; + + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto ialpha = IA(src); + + //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) + int32_t notAligned = ((uintptr_t)dst & 0xf) / 4; + if (notAligned) { + notAligned = (N_32BITS_IN_128REG - notAligned > len ? len : N_32BITS_IN_128REG - notAligned); + for (auto x = 0; x < notAligned; ++x, ++dst) { + *dst = src + ALPHA_BLEND(*dst, ialpha); + } + } + + //2. fill the aligned memory using avx - N_32BITS_IN_128REG pixels processed at once + //In order to avoid unnecessary avx variables declarations a check is made whether there are any iterations at all + int32_t iterations = (len - notAligned) / N_32BITS_IN_128REG; + int32_t avxFilled = 0; + if (iterations > 0) { + auto avxSrc = _mm_set1_epi32(src); + auto avxIalpha = _mm_set1_epi8(ialpha); + + avxFilled = iterations * N_32BITS_IN_128REG; + auto avxDst = (__m128i*)dst; + for (auto x = 0; x < iterations; ++x, ++avxDst) { + *avxDst = _mm_add_epi32(avxSrc, ALPHA_BLEND(*avxDst, avxIalpha)); + } + } + + //3. fill the remaining pixels + auto leftovers = len - notAligned - avxFilled; + dst += avxFilled; + while (leftovers--) { + *dst = src + ALPHA_BLEND(*dst, ialpha); + dst++; + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require AVX Optimization, Channel Size = %d", surface->channelSize); + uint8_t src; + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf8[span->y * surface->stride + x]; + if (span->coverage < 255) src = MULTIPLY(span->coverage, c.a); + else src = c.a; + auto ialpha = ~c.a; + for (auto x = 0; x < len; ++x, ++dst) { + *dst = src + MULTIPLY(*dst, ialpha); + } + } + } + return true; +} + + +#endif diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterC.h b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterC.h new file mode 100644 index 0000000..814b62a --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterC.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +template +static void inline cRasterTranslucentPixels(PIXEL_T* dst, PIXEL_T* src, uint32_t len, uint32_t opacity) +{ + //TODO: 64bits faster? + if (opacity == 255) { + for (uint32_t x = 0; x < len; ++x, ++dst, ++src) { + *dst = *src + ALPHA_BLEND(*dst, IA(*src)); + } + } else { + for (uint32_t x = 0; x < len; ++x, ++dst, ++src) { + auto tmp = ALPHA_BLEND(*src, opacity); + *dst = tmp + ALPHA_BLEND(*dst, IA(tmp)); + } + } +} + + +template +static void inline cRasterPixels(PIXEL_T* dst, PIXEL_T* src, uint32_t len, uint32_t opacity) +{ + //TODO: 64bits faster? + if (opacity == 255) { + for (uint32_t x = 0; x < len; ++x, ++dst, ++src) { + *dst = *src; + } + } else { + cRasterTranslucentPixels(dst, src, len, opacity); + } +} + + +template +static void inline cRasterPixels(PIXEL_T* dst, PIXEL_T val, uint32_t offset, int32_t len) +{ + dst += offset; + + //fix the misaligned memory + auto alignOffset = (long long) dst % 8; + if (alignOffset > 0) { + if (sizeof(PIXEL_T) == 4) alignOffset /= 4; + else if (sizeof(PIXEL_T) == 1) alignOffset = 8 - alignOffset; + while (alignOffset > 0 && len > 0) { + *dst++ = val; + --len; + --alignOffset; + } + } + + //64bits faster clear + if ((sizeof(PIXEL_T) == 4)) { + auto val64 = (uint64_t(val) << 32) | uint64_t(val); + while (len > 1) { + *reinterpret_cast(dst) = val64; + len -= 2; + dst += 2; + } + } else if (sizeof(PIXEL_T) == 1) { + auto val32 = (uint32_t(val) << 24) | (uint32_t(val) << 16) | (uint32_t(val) << 8) | uint32_t(val); + auto val64 = (uint64_t(val32) << 32) | val32; + while (len > 7) { + *reinterpret_cast(dst) = val64; + len -= 8; + dst += 8; + } + } + + //leftovers + while (len--) *dst++ = val; +} + + +static bool inline cRasterTranslucentRle(SwSurface* surface, const SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + const SwSpan* end; + int32_t x, len; + + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + uint32_t src; + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf32[span->y * surface->stride + x]; + if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); + else src = color; + auto ialpha = IA(src); + for (auto x = 0; x < len; ++x, ++dst) { + *dst = src + ALPHA_BLEND(*dst, ialpha); + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + uint8_t src; + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf8[span->y * surface->stride + x]; + if (span->coverage < 255) src = MULTIPLY(span->coverage, c.a); + else src = c.a; + auto ialpha = ~c.a; + for (auto x = 0; x < len; ++x, ++dst) { + *dst = src + MULTIPLY(*dst, ialpha); + } + } + } + return true; +} + + +static bool inline cRasterTranslucentRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + auto ialpha = 255 - c.a; + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < bbox.w(); ++x, ++dst) { + *dst = color + ALPHA_BLEND(*dst, ialpha); + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + auto buffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + auto ialpha = ~c.a; + for (uint32_t y = 0; y < bbox.h(); ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < bbox.w(); ++x, ++dst) { + *dst = c.a + MULTIPLY(*dst, ialpha); + } + } + } + return true; +} + + +static bool inline cRasterABGRtoARGB(RenderSurface* surface) +{ + TVGLOG("SW_ENGINE", "Convert ColorSpace ABGR - ARGB [Size: %d x %d]", surface->w, surface->h); + + //64bits faster converting + if (surface->w % 2 == 0) { + auto buffer = reinterpret_cast(surface->buf32); + for (uint32_t y = 0; y < surface->h; ++y, buffer += surface->stride / 2) { + auto dst = buffer; + for (uint32_t x = 0; x < surface->w / 2; ++x, ++dst) { + auto c = *dst; + //flip Blue, Red channels + *dst = (c & 0xff000000ff000000) + ((c & 0x00ff000000ff0000) >> 16) + (c & 0x0000ff000000ff00) + ((c & 0x000000ff000000ff) << 16); + } + } + //default converting + } else { + auto buffer = surface->buf32; + for (uint32_t y = 0; y < surface->h; ++y, buffer += surface->stride) { + auto dst = buffer; + for (uint32_t x = 0; x < surface->w; ++x, ++dst) { + auto c = *dst; + //flip Blue, Red channels + *dst = (c & 0xff000000) + ((c & 0x00ff0000) >> 16) + (c & 0x0000ff00) + ((c & 0x000000ff) << 16); + } + } + } + return true; +} + + +static bool inline cRasterARGBtoABGR(RenderSurface* surface) +{ + //exactly same with ABGRtoARGB + return cRasterABGRtoARGB(surface); +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterNeon.h b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterNeon.h new file mode 100644 index 0000000..649595f --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterNeon.h @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef THORVG_NEON_VECTOR_SUPPORT + +#include + +//TODO : need to support windows ARM + +#if defined(__ARM_64BIT_STATE) || defined(_M_ARM64) +#define TVG_AARCH64 1 +#else +#define TVG_AARCH64 0 +#endif + + +static inline uint8x8_t ALPHA_BLEND(uint8x8_t c, uint8x8_t a) +{ + uint16x8_t t = vmull_u8(c, a); + return vshrn_n_u16(t, 8); +} + + +static void neonRasterGrayscale8(uint8_t* dst, uint8_t val, uint32_t offset, int32_t len) +{ + dst += offset; + + int32_t i = 0; + const uint8x16_t valVec = vdupq_n_u8(val); +#if TVG_AARCH64 + uint8x16x4_t valQuad = {valVec, valVec, valVec, valVec}; + for (; i <= len - 16 * 4; i += 16 * 4) { + vst1q_u8_x4(dst + i, valQuad); + } +#else + for (; i <= len - 16; i += 16) { + vst1q_u8(dst + i, valVec); + } +#endif + for (; i < len; i++) { + dst[i] = val; + } +} + + +static void neonRasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len) +{ + dst += offset; + + uint32x4_t vectorVal = vdupq_n_u32(val); + +#if TVG_AARCH64 + uint32_t iterations = len / 16; + uint32_t neonFilled = iterations * 16; + uint32x4x4_t valQuad = {vectorVal, vectorVal, vectorVal, vectorVal}; + for (uint32_t i = 0; i < iterations; ++i) { + vst4q_u32(dst, valQuad); + dst += 16; + } +#else + uint32_t iterations = len / 4; + uint32_t neonFilled = iterations * 4; + for (uint32_t i = 0; i < iterations; ++i) { + vst1q_u32(dst, vectorVal); + dst += 4; + } +#endif + int32_t leftovers = len - neonFilled; + while (leftovers--) *dst++ = val; +} + + +static bool neonRasterTranslucentRle(SwSurface* surface, const SwRle* rle, const RenderRegion& bbox, const RenderColor& c) +{ + const SwSpan* end; + int32_t x, len; + + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + uint32_t src; + uint8x8_t *vDst = nullptr; + int32_t align; + + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); + else src = color; + + auto dst = &surface->buf32[span->y * surface->stride + x]; + auto ialpha = IA(src); + + if ((((uintptr_t) dst) & 0x7) != 0) { + //fill not aligned byte + *dst = src + ALPHA_BLEND(*dst, ialpha); + vDst = (uint8x8_t*)(dst + 1); + align = 1; + } else { + vDst = (uint8x8_t*) dst; + align = 0; + } + + uint8x8_t vSrc = (uint8x8_t) vdup_n_u32(src); + uint8x8_t vIalpha = vdup_n_u8((uint8_t) ialpha); + + for (int32_t x = 0; x < (len - align) / 2; ++x) + vDst[x] = vadd_u8(vSrc, ALPHA_BLEND(vDst[x], vIalpha)); + + auto leftovers = (len - align) % 2; + if (leftovers > 0) dst[len - 1] = src + ALPHA_BLEND(dst[len - 1], ialpha); + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require Neon Optimization, Channel Size = %d", surface->channelSize); + uint8_t src; + for (auto span = rle->fetch(bbox, &end); span < end; ++span) { + if (!span->fetch(bbox, x, len)) continue; + auto dst = &surface->buf8[span->y * surface->stride + x]; + if (span->coverage < 255) src = MULTIPLY(span->coverage, c.a); + else src = c.a; + auto ialpha = ~c.a; + for (auto x = 0; x < len; ++x, ++dst) { + *dst = src + MULTIPLY(*dst, ialpha); + } + } + } + return true; +} + + +static bool neonRasterTranslucentRect(SwSurface* surface, const RenderRegion& bbox, const RenderColor& c) +{ + auto h = bbox.h(); + auto w = bbox.w(); + + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(c.r, c.g, c.b, c.a); + auto buffer = surface->buf32 + (bbox.min.y * surface->stride) + bbox.min.x; + auto ialpha = 255 - c.a; + + auto vColor = vdup_n_u32(color); + auto vIalpha = vdup_n_u8((uint8_t) ialpha); + + uint8x8_t* vDst = nullptr; + uint32_t align; + + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + + if ((((uintptr_t) dst) & 0x7) != 0) { + //fill not aligned byte + *dst = color + ALPHA_BLEND(*dst, ialpha); + vDst = (uint8x8_t*) (dst + 1); + align = 1; + } else { + vDst = (uint8x8_t*) dst; + align = 0; + } + + for (uint32_t x = 0; x < (w - align) / 2; ++x) + vDst[x] = vadd_u8((uint8x8_t)vColor, ALPHA_BLEND(vDst[x], vIalpha)); + + auto leftovers = (w - align) % 2; + if (leftovers > 0) dst[w - 1] = color + ALPHA_BLEND(dst[w - 1], ialpha); + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require Neon Optimization, Channel Size = %d", surface->channelSize); + auto buffer = surface->buf8 + (bbox.min.y * surface->stride) + bbox.min.x; + auto ialpha = ~c.a; + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < w; ++x, ++dst) { + *dst = c.a + MULTIPLY(*dst, ialpha); + } + } + } + return true; +} + +#endif diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterTexmap.h b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterTexmap.h new file mode 100644 index 0000000..358a0d8 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRasterTexmap.h @@ -0,0 +1,575 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +namespace tvg +{ + +struct Vertex +{ + Point pt; + Point uv; +}; + +struct Polygon +{ + Vertex vertex[3]; +}; + +//Careful! Shared resource, No support threading +static float dudx, dvdx; +static float dxdya, dxdyb, dudya, dvdya; +static float xa, xb, ua, va; + + +static inline int32_t _modf(float v) +{ + return 255 - ((int(v * 256.0f)) & 255); +} + + +static uint8_t _feathering(int iru, int irv, int ar, int ab, int sw, int sh) +{ + if (irv == 1) { + if (iru == 1) return 255 - MULTIPLY(ar, ab); + else if (iru == sw) return MULTIPLY(ar, 255 - ab); + return 255 - ab; + } else if (irv == sh) { + if (iru == 1) return MULTIPLY(255 - ar, ab); + else if (iru == sw) return MULTIPLY(ar, ab); + return ab; + } else { + if (iru == 1) return 255 - ar; + else if (iru == sw) return ar; + } + return 255; +} + + +static bool _rasterMaskedPolygonImageSegment(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int yStart, int yEnd, uint8_t opacity, bool needAA) +{ + TVGERR("SW_ENGINE", "TODO: _rasterMaskedPolygonImageSegment()"); + return false; +} + + +static void _rasterBlendingPolygonImageSegment(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int yStart, int yEnd, uint8_t opacity, bool needAA) +{ + if (surface->channelSize == sizeof(uint8_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale Textmap polygon!"); + return; + } + + auto _dudx = dudx, _dvdx = dvdx; + auto _dxdya = dxdya, _dxdyb = dxdyb, _dudya = dudya, _dvdya = dvdya; + auto _xa = xa, _xb = xb, _ua = ua, _va = va; + auto sbuf = image.buf32; + auto dbuf = surface->buf32; + auto sw = static_cast(image.w); + auto sh = static_cast(image.h); + int32_t x1, x2, x, y, ar, ab, iru, irv, px; + int32_t vv = 0, uu = 0; + float dx, u, v; + uint32_t* buf; + + if (yStart < bbox.min.y) yStart = bbox.min.y; + if (yEnd > bbox.max.y) yEnd = bbox.max.y; + + y = yStart; + + while (y < yEnd) { + x1 = std::max((int32_t)_xa, bbox.min.x); + x2 = std::min((int32_t)_xb, bbox.max.x); + + //Range allowed + if ((x2 - x1) >= 1 && (x1 < bbox.max.x) && (x2 > bbox.min.x)) { + + //Perform subtexel pre-stepping on UV + dx = 1 - (_xa - x1); + u = _ua + dx * _dudx; + v = _va + dx * _dvdx; + buf = dbuf + ((y * surface->stride) + x1); + x = x1; + + //Draw horizontal line + while (x++ < x2) { + uu = (int) u; + vv = (int) v; + + if ((uint32_t) uu >= image.w || (uint32_t) vv >= image.h) continue; + + ar = _modf(u); + ab = _modf(v); + iru = uu + 1; + irv = vv + 1; + + px = *(sbuf + (vv * image.stride) + uu); + + // horizontal interpolate + if (iru < sw) { + int px2 = *(sbuf + (vv * image.stride) + iru); + px = INTERPOLATE(px, px2, ar); + } + // vertical interpolate + if (irv < sh) { + int px2 = *(sbuf + (irv * image.stride) + uu); + // horizontal interpolate + if (iru < sw) { + int px3 = *(sbuf + (irv * image.stride) + iru); + px2 = INTERPOLATE(px2, px3, ar); + } + px = INTERPOLATE(px, px2, ab); + } + + // anti-aliasing + if (needAA) { + auto feather = _feathering(iru, irv, ar, ab, sw, sh); + if (feather < 255) px = ALPHA_BLEND(px, feather); + } + + *buf = INTERPOLATE(surface->blender(rasterUnpremultiply(px), *buf), *buf, MULTIPLY(opacity, A(px))); + ++buf; + + //Step UV horizontally + u += _dudx; + v += _dvdx; + } + } + + //Step along both edges + _xa += _dxdya; + _xb += _dxdyb; + _ua += _dudya; + _va += _dvdya; + + ++y; + } + xa = _xa; + xb = _xb; + ua = _ua; + va = _va; +} + + +static void _rasterPolygonImageSegment32(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int yStart, int yEnd, uint8_t opacity, bool matting, bool needAA) +{ + auto _dudx = dudx, _dvdx = dvdx; + auto _dxdya = dxdya, _dxdyb = dxdyb, _dudya = dudya, _dvdya = dvdya; + auto _xa = xa, _xb = xb, _ua = ua, _va = va; + auto sbuf = image.buf32; + auto dbuf = surface->buf32; + auto sw = static_cast(image.w); + auto sh = static_cast(image.h); + int32_t x1, x2, x, y, ar, ab, iru, irv, px; + int32_t vv = 0, uu = 0; + float dx, u, v; + uint32_t* buf; + auto fullOpacity = (opacity == 255); + + //for matting(composition) + auto csize = matting ? surface->compositor->image.channelSize: 0; + auto alpha = matting ? surface->alpha(surface->compositor->method) : nullptr; + uint8_t* cmp = nullptr; + + if (yStart < bbox.min.y) yStart = bbox.min.y; + if (yEnd > bbox.max.y) yEnd = bbox.max.y; + + y = yStart; + + while (y < yEnd) { + x1 = std::max((int32_t)_xa, bbox.min.x); + x2 = std::min((int32_t)_xb, bbox.max.x); + + //Range allowed + if ((x2 - x1) >= 1 && (x1 < bbox.max.x) && (x2 > bbox.min.x)) { + + //Perform subtexel pre-stepping on UV + dx = 1 - (_xa - x1); + u = _ua + dx * _dudx; + v = _va + dx * _dvdx; + buf = dbuf + ((y * surface->stride) + x1); + x = x1; + + if (matting) cmp = &surface->compositor->image.buf8[(y * surface->compositor->image.stride + x1) * csize]; + + //Draw horizontal line + while (x++ < x2) { + uu = (int) u; + vv = (int) v; + + if ((uint32_t) uu >= image.w || (uint32_t) vv >= image.h) continue; + + ar = _modf(u); + ab = _modf(v); + iru = uu + 1; + irv = vv + 1; + + px = *(sbuf + (vv * image.stride) + uu); + + // horizontal interpolate + if (iru < sw) { + int px2 = *(sbuf + (vv * image.stride) + iru); + px = INTERPOLATE(px, px2, ar); + } + // vertical interpolate + if (irv < sh) { + int px2 = *(sbuf + (irv * image.stride) + uu); + // horizontal interpolate + if (iru < sw) { + int px3 = *(sbuf + (irv * image.stride) + iru); + px2 = INTERPOLATE(px2, px3, ar); + } + px = INTERPOLATE(px, px2, ab); + } + uint32_t src; + if (matting) { + auto a = alpha(cmp); + src = fullOpacity ? ALPHA_BLEND(px, a) : ALPHA_BLEND(px, MULTIPLY(opacity, a)); + cmp += csize; + } else { + src = fullOpacity ? px : ALPHA_BLEND(px, opacity); + } + + // anti-aliasing + if (needAA) { + auto feather = _feathering(iru, irv, ar, ab, sw, sh); + if (feather < 255) src = ALPHA_BLEND(src, feather); + } + + *buf = src + ALPHA_BLEND(*buf, IA(src)); + ++buf; + + //Step UV horizontally + u += _dudx; + v += _dvdx; + } + } + + //Step along both edges + _xa += _dxdya; + _xb += _dxdyb; + _ua += _dudya; + _va += _dvdya; + + ++y; + } + xa = _xa; + xb = _xb; + ua = _ua; + va = _va; +} + +// no anti-aliasing, no interpolation for the fastest cheap masking +static void _rasterPolygonImageSegment8(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int yStart, int yEnd, uint8_t opacity, TVG_UNUSED bool needAA) +{ + auto _dudx = dudx, _dvdx = dvdx; + auto _dxdya = dxdya, _dxdyb = dxdyb, _dudya = dudya, _dvdya = dvdya; + auto _xa = xa, _xb = xb, _ua = ua, _va = va; + auto sbuf = image.buf32; + auto dbuf = surface->buf8; + int32_t x1, x2, x, y; + float dx, u, v; + uint8_t* buf; + uint8_t px; + + if (yStart < bbox.min.y) yStart = bbox.min.y; + if (yEnd > bbox.max.y) yEnd = bbox.max.y; + + y = yStart; + + while (y < yEnd) { + x1 = std::max((int32_t)_xa, bbox.min.x); + x2 = std::min((int32_t)_xb, bbox.max.x); + + //Range allowed + if ((x2 - x1) >= 1 && (x1 < bbox.max.x) && (x2 > bbox.min.x)) { + //Perform subtexel pre-stepping on UV + dx = 1 - (_xa - x1); + u = _ua + dx * _dudx; + v = _va + dx * _dvdx; + buf = dbuf + ((y * surface->stride) + x1); + x = x1; + //Draw horizontal line + while (x++ < x2) { + auto uu = (int) u; + auto vv = (int) v; + if ((uint32_t) uu >= image.w || (uint32_t) vv >= image.h) continue; + + px = A(*(sbuf + (vv * image.stride) + uu)); + *buf = MULTIPLY(px, opacity); + ++buf; + //Step UV horizontally + u += _dudx; + v += _dvdx; + } + } + //Step along both edges + _xa += _dxdya; + _xb += _dxdyb; + _ua += _dudya; + _va += _dvdya; + ++y; + } + xa = _xa; + xb = _xb; + ua = _ua; + va = _va; +} + + +static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, int yStart, int yEnd, uint8_t opacity, bool matting, bool needAA) +{ + if (surface->channelSize == sizeof(uint32_t)) _rasterPolygonImageSegment32(surface, image, bbox, yStart, yEnd, opacity, matting, needAA); + else if (surface->channelSize == sizeof(uint8_t)) _rasterPolygonImageSegment8(surface, image, bbox, yStart, yEnd, opacity, needAA); +} + + +/* This mapping algorithm is based on Mikael Kalms's. */ +static void _rasterPolygonImage(SwSurface* surface, const SwImage& image, const RenderRegion& bbox, Polygon& polygon, uint8_t opacity, bool needAA) +{ + float x[3] = {polygon.vertex[0].pt.x, polygon.vertex[1].pt.x, polygon.vertex[2].pt.x}; + float y[3] = {polygon.vertex[0].pt.y, polygon.vertex[1].pt.y, polygon.vertex[2].pt.y}; + float u[3] = {polygon.vertex[0].uv.x, polygon.vertex[1].uv.x, polygon.vertex[2].uv.x}; + float v[3] = {polygon.vertex[0].uv.y, polygon.vertex[1].uv.y, polygon.vertex[2].uv.y}; + + float off_y; + float dxdy[3] = {0.0f, 0.0f, 0.0f}; + + auto upper = false; + + //Sort the vertices in ascending Y order + if (y[0] > y[1]) { + std::swap(x[0], x[1]); + std::swap(y[0], y[1]); + std::swap(u[0], u[1]); + std::swap(v[0], v[1]); + } + if (y[0] > y[2]) { + std::swap(x[0], x[2]); + std::swap(y[0], y[2]); + std::swap(u[0], u[2]); + std::swap(v[0], v[2]); + } + if (y[1] > y[2]) { + std::swap(x[1], x[2]); + std::swap(y[1], y[2]); + std::swap(u[1], u[2]); + std::swap(v[1], v[2]); + } + + //Y indexes + int yi[3] = {(int)y[0], (int)y[1], (int)y[2]}; + + //Skip drawing if it's too thin to cover any pixels at all. + if ((yi[0] == yi[1] && yi[0] == yi[2]) || ((int) x[0] == (int) x[1] && (int) x[0] == (int) x[2])) return; + + //Calculate horizontal and vertical increments for UV axes (these calcs are certainly not optimal, although they're stable (handles any dy being 0) + auto denom = ((x[2] - x[0]) * (y[1] - y[0]) - (x[1] - x[0]) * (y[2] - y[0])); + + //Skip poly if it's an infinitely thin line + if (tvg::zero(denom)) return; + + denom = 1 / denom; //Reciprocal for speeding up + dudx = ((u[2] - u[0]) * (y[1] - y[0]) - (u[1] - u[0]) * (y[2] - y[0])) * denom; + dvdx = ((v[2] - v[0]) * (y[1] - y[0]) - (v[1] - v[0]) * (y[2] - y[0])) * denom; + auto dudy = ((u[1] - u[0]) * (x[2] - x[0]) - (u[2] - u[0]) * (x[1] - x[0])) * denom; + auto dvdy = ((v[1] - v[0]) * (x[2] - x[0]) - (v[2] - v[0]) * (x[1] - x[0])) * denom; + + //Calculate X-slopes along the edges + if (y[1] > y[0]) dxdy[0] = (x[1] - x[0]) / (y[1] - y[0]); + if (y[2] > y[0]) dxdy[1] = (x[2] - x[0]) / (y[2] - y[0]); + if (y[2] > y[1]) dxdy[2] = (x[2] - x[1]) / (y[2] - y[1]); + + //Determine which side of the polygon the longer edge is on + auto side = (dxdy[1] > dxdy[0]) ? true : false; + + if (tvg::equal(y[0], y[1])) side = x[0] > x[1]; + if (tvg::equal(y[1], y[2])) side = x[2] > x[1]; + + auto compositing = _compositing(surface); //Composition required + auto blending = _blending(surface); //Blending required + + //Longer edge is on the left side + if (!side) { + //Calculate slopes along left edge + dxdya = dxdy[1]; + dudya = dxdya * dudx + dudy; + dvdya = dxdya * dvdx + dvdy; + + //Perform subpixel pre-stepping along left edge + auto dy = 1.0f - (y[0] - yi[0]); + xa = x[0] + dy * dxdya; + ua = u[0] + dy * dudya; + va = v[0] + dy * dvdya; + + //Draw upper segment if possibly visible + if (yi[0] < yi[1]) { + off_y = y[0] < bbox.min.y ? (bbox.min.y - y[0]) : 0; + xa += (off_y * dxdya); + ua += (off_y * dudya); + va += (off_y * dvdya); + + // Set right edge X-slope and perform subpixel pre-stepping + dxdyb = dxdy[0]; + xb = x[0] + dy * dxdyb + (off_y * dxdyb); + + if (compositing) { + if (_matting(surface)) _rasterPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, true, needAA); + else _rasterMaskedPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, needAA); + } else if (blending) { + _rasterBlendingPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, needAA); + } else { + _rasterPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, false, needAA); + } + upper = true; + } + //Draw lower segment if possibly visible + if (yi[1] < yi[2]) { + off_y = y[1] < bbox.min.y ? (bbox.min.y - y[1]) : 0; + if (!upper) { + xa += (off_y * dxdya); + ua += (off_y * dudya); + va += (off_y * dvdya); + } + // Set right edge X-slope and perform subpixel pre-stepping + dxdyb = dxdy[2]; + xb = x[1] + (1 - (y[1] - yi[1])) * dxdyb + (off_y * dxdyb); + if (compositing) { + if (_matting(surface)) _rasterPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, true, needAA); + else _rasterMaskedPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, needAA); + } else if (blending) { + _rasterBlendingPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, needAA); + } else { + _rasterPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, false, needAA); + } + } + //Longer edge is on the right side + } else { + //Set right edge X-slope and perform subpixel pre-stepping + dxdyb = dxdy[1]; + auto dy = 1.0f - (y[0] - yi[0]); + xb = x[0] + dy * dxdyb; + + //Draw upper segment if possibly visible + if (yi[0] < yi[1]) { + off_y = y[0] < bbox.min.y ? (bbox.min.y - y[0]) : 0; + xb += (off_y *dxdyb); + + // Set slopes along left edge and perform subpixel pre-stepping + dxdya = dxdy[0]; + dudya = dxdya * dudx + dudy; + dvdya = dxdya * dvdx + dvdy; + + xa = x[0] + dy * dxdya + (off_y * dxdya); + ua = u[0] + dy * dudya + (off_y * dudya); + va = v[0] + dy * dvdya + (off_y * dvdya); + + if (compositing) { + if (_matting(surface)) _rasterPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, true, needAA); + else _rasterMaskedPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, needAA); + } else if (blending) { + _rasterBlendingPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, needAA); + } else { + _rasterPolygonImageSegment(surface, image, bbox, yi[0], yi[1], opacity, false, needAA); + } + upper = true; + } + //Draw lower segment if possibly visible + if (yi[1] < yi[2]) { + off_y = y[1] < bbox.min.y ? (bbox.min.y - y[1]) : 0; + if (!upper) xb += (off_y *dxdyb); + + // Set slopes along left edge and perform subpixel pre-stepping + dxdya = dxdy[2]; + dudya = dxdya * dudx + dudy; + dvdya = dxdya * dvdx + dvdy; + dy = 1 - (y[1] - yi[1]); + xa = x[1] + dy * dxdya + (off_y * dxdya); + ua = u[1] + dy * dudya + (off_y * dudya); + va = v[1] + dy * dvdya + (off_y * dvdya); + + if (compositing) { + if (_matting(surface)) _rasterPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, true, needAA); + else _rasterMaskedPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, needAA); + } else if (blending) { + _rasterBlendingPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, needAA); + } else { + _rasterPolygonImageSegment(surface, image, bbox, yi[1], yi[2], opacity, false, needAA); + } + } + } +} + +} //namespace + + +/* + 2 triangles constructs 1 mesh. + below figure illustrates vert[4] index info. + If you need better quality, please divide a mesh by more number of triangles. + + 0 -- 1 + | / | + | / | + 3 -- 2 +*/ +bool rasterTexmapPolygon(SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity) +{ + //Prepare vertices. Shift XY coordinates to match the sub-pixeling technique. + Vertex vertices[4]; + vertices[0] = {{0.0f, 0.0f}, {0.0f, 0.0f}}; + vertices[1] = {{float(image.w), 0.0f}, {float(image.w), 0.0f}}; + vertices[2] = {{float(image.w), float(image.h)}, {float(image.w), float(image.h)}}; + vertices[3] = {{0.0f, float(image.h)}, {0.0f, float(image.h)}}; + + float ys = FLT_MAX, ye = -1.0f; + for (int i = 0; i < 4; i++) { + vertices[i].pt *= transform; + if (vertices[i].pt.y < ys) ys = vertices[i].pt.y; + if (vertices[i].pt.y > ye) ye = vertices[i].pt.y; + } + + auto needAA = rightAngle(transform) ? false : true; + + tvg::Polygon polygon; + + //Draw the first polygon + polygon.vertex[0] = vertices[0]; + polygon.vertex[1] = vertices[1]; + polygon.vertex[2] = vertices[3]; + + _rasterPolygonImage(surface, image, bbox, polygon, opacity, needAA); + + //Draw the second polygon + polygon.vertex[0] = vertices[1]; + polygon.vertex[1] = vertices[2]; + polygon.vertex[2] = vertices[3]; + + _rasterPolygonImage(surface, image, bbox, polygon, opacity, needAA); + +#if 0 + if (_compositing(surface) && _masking(surface) && !_direct(surface->compositor->method)) { + _compositeMaskImage(surface, &surface->compositor->image, surface->compositor->bbox); + } +#endif + return true; +} + diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRenderer.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwRenderer.cpp new file mode 100644 index 0000000..28cc6eb --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRenderer.cpp @@ -0,0 +1,945 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include "tvgSwCommon.h" +#include "tvgTaskScheduler.h" +#include "tvgSwRenderer.h" + +#ifdef THORVG_OPENMP_SUPPORT + #include +#endif + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ +static atomic rendererCnt{-1}; +static SwMpool* globalMpool = nullptr; +static uint32_t threadsCnt = 0; + +struct SwTask : Task +{ + SwSurface* surface = nullptr; + SwMpool* mpool = nullptr; + RenderRegion clipBox; //clipping region applied to the task, may differ from curBox which is the actual rendering region + RenderRegion curBox{}; //current rendering region + RenderRegion prvBox{}; //previous rendering region + Matrix transform; + Array clips; + RenderDirtyRegion* dirtyRegion; + RenderUpdateFlag flags[2] = {RenderUpdateFlag::None, RenderUpdateFlag::None}; //cur&prv + uint8_t opacity; + bool pushed : 1; //Pushed into task list? + bool disposed : 1; //Disposed task? + bool nodirty : 1; //target for partial rendering? + bool valid : 1; + + SwTask() : pushed(false), disposed(false) {} + + const RenderRegion& bounds() + { + done(); + return curBox; + } + + void invisible() + { + curBox.reset(); + if (!nodirty) dirtyRegion->add(prvBox, curBox); + } + + bool ready(bool condition) + { + //invisible + if (condition) { + if (flags[0] & RenderUpdateFlag::Color) invisible(); + flags[1] = flags[0]; //backup + return true; + } + flags[0] |= flags[1]; //applied the previous flags if it's skipped before + flags[1] = RenderUpdateFlag::None; //reset + return false; + } + + virtual void dispose() = 0; + virtual bool clip(SwRle* target) = 0; + virtual ~SwTask() {} +}; + + +struct SwShapeTask : SwTask +{ + SwShape shape; + const RenderShape* rshape = nullptr; + bool clipper = false; + + /* We assume that if the stroke width is greater than 2, + the shape's outline beneath the stroke could be adequately covered by the stroke drawing. + Therefore, antialiasing is disabled under this condition. + Additionally, the stroke style should not be dashed. */ + bool antialiasing(float strokeWidth) + { + return strokeWidth < 2.0f || rshape->stroke->dash.count > 0 || rshape->stroke->first || rshape->trimpath() || rshape->stroke->color.a < 255; + } + + float validStrokeWidth(bool clipper) + { + if (!rshape->stroke || tvg::zero(rshape->stroke->width)) return 0.0f; + if (!clipper && (!rshape->stroke->fill && (rshape->stroke->color.a == 0))) return 0.0f; + if (tvg::zero(rshape->stroke->trim.begin - rshape->stroke->trim.end)) return 0.0f; + return (rshape->stroke->width * sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12)); + } + + bool clip(SwRle* target) override + { + if (shape.strokeRle) return rleClip(target, shape.strokeRle); + if (shape.fastTrack) return rleClip(target, &curBox); + if (shape.rle) return rleClip(target, shape.rle); + return false; + } + + void run(unsigned tid) override + { + if (ready(opacity == 0 && !clipper)) return; + + auto strokeWidth = validStrokeWidth(clipper); + auto updateShape = flags[0] & (RenderUpdateFlag::Path | RenderUpdateFlag::Transform | RenderUpdateFlag::Clip); + auto updateFill = (flags[0] & (RenderUpdateFlag::Color | RenderUpdateFlag::Gradient)); + + //Shape + if (updateShape) { + shapeReset(shape); + if (rshape->fill || rshape->color.a > 0 || clipper) { + if (shapePrepare(shape, rshape, transform, clipBox, curBox, mpool, tid, clips.count > 0 ? true : false)) { + if (!shapeGenRle(shape, curBox, mpool, tid, antialiasing(strokeWidth))) goto err; + } else { + updateFill = false; + curBox.reset(); + } + } + } + //Fill + if (updateFill) { + if (auto fill = rshape->fill) { + auto ctable = (flags[0] & RenderUpdateFlag::Gradient) ? true : false; + if (ctable) shapeResetFill(shape); + if (!shapeGenFillColors(shape, fill, transform, surface, opacity, ctable)) goto err; + } + } + //Stroke + if (updateShape || flags[0] & RenderUpdateFlag::Stroke) { + if (strokeWidth > 0.0f) { + shapeResetStroke(shape, rshape, transform, mpool, tid); + if (!shapeGenStrokeRle(shape, rshape, transform, clipBox, curBox, mpool, tid)) goto err; + if (auto fill = rshape->strokeFill()) { + auto ctable = (flags[0] & RenderUpdateFlag::GradientStroke) ? true : false; + if (ctable) shapeResetStrokeFill(shape); + if (!shapeGenStrokeFillColors(shape, fill, transform, surface, opacity, ctable)) goto err; + } + } else { + shapeDelStroke(shape); + } + } + + //Clear current task memorypool here if the clippers would use the same memory pool + shapeDelOutline(shape, mpool, tid); + + //Clip Path + ARRAY_FOREACH(p, clips) { + auto clipper = static_cast(*p); + auto clipShapeRle = shape.rle ? clipper->clip(shape.rle) : true; + auto clipStrokeRle = shape.strokeRle ? clipper->clip(shape.strokeRle) : true; + if (!clipShapeRle || !clipStrokeRle) goto err; + } + + valid = true; + if (!nodirty) dirtyRegion->add(prvBox, curBox); + return; + + err: + shapeReset(shape); + rleReset(shape.strokeRle); + shapeDelOutline(shape, mpool, tid); + invisible(); + } + + void dispose() override + { + shapeFree(shape); + } +}; + + +struct SwImageTask : SwTask +{ + SwImage image; + RenderSurface* source; //Image source + + bool clip(SwRle* target) override + { + TVGERR("SW_ENGINE", "Image is used as ClipPath?"); + return true; + } + + void run(unsigned tid) override + { + if (ready(opacity == 0)) return; + + //Convert colorspace if it's not aligned. + rasterConvertCS(source, surface->cs); + rasterPremultiply(source); + + image.data = source->data; + image.w = source->w; + image.h = source->h; + image.stride = source->stride; + image.channelSize = source->channelSize; + + auto updateImage = flags[0] & (RenderUpdateFlag::Image | RenderUpdateFlag::Clip | RenderUpdateFlag::Transform); + auto updateColor = flags[0] & (RenderUpdateFlag::Color); + + //Invisible shape turned to visible by alpha. + if ((updateImage || updateColor) && (opacity > 0)) { + if (updateImage) imageReset(image); + if (!image.data || image.w == 0 || image.h == 0) goto err; + if (!imagePrepare(image, transform, clipBox, curBox, mpool, tid)) goto err; + valid = true; + if (clips.count > 0) { + if (!imageGenRle(image, curBox, mpool, tid, false)) goto err; + if (image.rle) { + //Clear current task memorypool here if the clippers would use the same memory pool + imageDelOutline(image, mpool, tid); + ARRAY_FOREACH(p, clips) { + auto clipper = static_cast(*p); + if (!clipper->clip(image.rle)) goto err; + } + if (!nodirty) dirtyRegion->add(prvBox, curBox); + return; + } + } else imageFree(image); + } + goto end; + err: + curBox.reset(); + imageReset(image); + end: + imageDelOutline(image, mpool, tid); + if (!nodirty) dirtyRegion->add(prvBox, curBox); + } + + void dispose() override + { + imageFree(image); + } +}; + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +SwRenderer::~SwRenderer() +{ + clearCompositors(); + + delete(surface); + + if (!sharedMpool) mpoolTerm(mpool); + + --rendererCnt; +} + + +bool SwRenderer::clear() +{ + if (surface) { + fulldraw = true; + return rasterClear(surface, 0, 0, surface->w, surface->h); + } + return false; +} + + +bool SwRenderer::sync() +{ + //clear if the rendering was not triggered. + ARRAY_FOREACH(p, tasks) { + if ((*p)->disposed) delete(*p); + else { + (*p)->done(); + (*p)->pushed = false; + } + } + tasks.clear(); + + return true; +} + + +bool SwRenderer::target(pixel_t* data, uint32_t stride, uint32_t w, uint32_t h, ColorSpace cs) +{ + if (!data || stride == 0 || w == 0 || h == 0 || w > stride) return false; + + clearCompositors(); + + if (!surface) surface = new SwSurface; + + surface->data = data; + surface->stride = stride; + surface->w = w; + surface->h = h; + surface->cs = cs; + surface->channelSize = CHANNEL_SIZE(cs); + surface->premultiplied = true; + + dirtyRegion.init(w, h); + + fulldraw = true; //reset the screen + + return rasterCompositor(surface); +} + + +bool SwRenderer::preUpdate() +{ + return surface != nullptr; +} + + +bool SwRenderer::postUpdate() +{ + return true; +} + + +bool SwRenderer::preRender() +{ + if (!surface) return false; + if (fulldraw || dirtyRegion.deactivated()) return true; + + ARRAY_FOREACH(p, tasks) (*p)->done(); + + dirtyRegion.commit(); + + //clear buffer for partial regions + for (int idx = 0; idx < RenderDirtyRegion::PARTITIONING; ++idx) { + ARRAY_FOREACH(p, dirtyRegion.get(idx)) { + rasterClear(surface, p->x(), p->y(), p->w(), p->h()); + } + } + + return true; +} + + +void SwRenderer::clearCompositors() +{ + //Free Composite Caches + ARRAY_FOREACH(p, compositors) { + tvg::free((*p)->compositor->image.data); + delete((*p)->compositor); + delete(*p); + } + compositors.reset(); +} + + +bool SwRenderer::postRender() +{ + //Unmultiply alpha if needed + if (surface->cs == ColorSpace::ABGR8888S || surface->cs == ColorSpace::ARGB8888S) { + rasterUnpremultiply(surface); + } + + dirtyRegion.clear(); + fulldraw = false; + + return true; +} + + +void SwRenderer::damage(RenderData rd, const RenderRegion& region) +{ + SwTask* task = static_cast(rd); + if (dirtyRegion.deactivated() || (task && task->opacity == 0)) return; + dirtyRegion.add(region); +} + + +bool SwRenderer::partial(bool disable) +{ + return dirtyRegion.deactivate(disable); +} + + +bool SwRenderer::renderImage(RenderData data) +{ + auto task = static_cast(data); + if (!task) return false; + task->done(); + + if (task->valid) { + auto raster = [&](SwSurface* surface, const SwImage& image, const Matrix& transform, const RenderRegion& bbox, uint8_t opacity) { + if (bbox.invalid() || bbox.x() >= surface->w || bbox.y() >= surface->h) return true; + + //RLE Image + if (image.rle) { + if (image.rle->invalid()) return true; + if (image.direct) return rasterDirectRleImage(surface, image, bbox, opacity); + else if (image.scaled) return rasterScaledRleImage(surface, image, transform, bbox, opacity); + else { + //create a intermediate buffer for rle clipping + auto cmp = request(sizeof(pixel_t), false); + cmp->compositor->method = MaskMethod::None; + cmp->compositor->valid = true; + cmp->compositor->image.rle = image.rle; + rasterClear(cmp, bbox.x(), bbox.y(), bbox.w(), bbox.h()); + rasterTexmapPolygon(cmp, image, transform, bbox, 255); + return rasterDirectRleImage(surface, cmp->compositor->image, bbox, opacity); + } + //Whole Image + } else { + if (image.direct) return rasterDirectImage(surface, image, bbox, opacity); + else if (image.scaled) return rasterScaledImage(surface, image, transform, bbox, opacity); + else return rasterTexmapPolygon(surface, image, transform, bbox, opacity); + } + }; + + //full scene or partial rendering + if (fulldraw || task->nodirty || task->pushed || dirtyRegion.deactivated()) { + raster(surface, task->image, task->transform, task->curBox, task->opacity); + } else if (task->curBox.valid()) { + for (int idx = 0; idx < RenderDirtyRegion::PARTITIONING; ++idx) { + if (!dirtyRegion.partition(idx).intersected(task->curBox)) continue; + ARRAY_FOREACH(p, dirtyRegion.get(idx)) { + if (task->curBox.max.x <= p->min.x) break; //dirtyRegion is sorted in x order + if (task->curBox.intersected(*p)) { + auto bbox = RenderRegion::intersect(task->curBox, *p); + raster(surface, task->image, task->transform, bbox, task->opacity); + } + } + } + } + } + task->prvBox = task->curBox; + return true; +} + + +bool SwRenderer::renderShape(RenderData data) +{ + auto task = static_cast(data); + if (!task) return false; + task->done(); + + if (task->valid) { + auto fill = [](SwShapeTask* task, SwSurface* surface, const RenderRegion& bbox) { + if (auto fill = task->rshape->fill) { + rasterGradientShape(surface, &task->shape, bbox, fill, task->opacity); + } else { + RenderColor c; + task->rshape->fillColor(&c.r, &c.g, &c.b, &c.a); + c.a = MULTIPLY(task->opacity, c.a); + if (c.a > 0) rasterShape(surface, &task->shape, bbox, c); + } + }; + + auto stroke = [](SwShapeTask* task, SwSurface* surface, const RenderRegion& bbox) { + if (auto strokeFill = task->rshape->strokeFill()) { + rasterGradientStroke(surface, &task->shape, bbox, strokeFill, task->opacity); + } else { + RenderColor c; + if (task->rshape->strokeFill(&c.r, &c.g, &c.b, &c.a)) { + c.a = MULTIPLY(task->opacity, c.a); + if (c.a > 0) rasterStroke(surface, &task->shape, bbox, c); + } + } + }; + + //full scene or partial rendering + if (fulldraw || task->nodirty || task->pushed || dirtyRegion.deactivated()) { + if (task->rshape->strokeFirst()) { + stroke(task, surface, task->curBox); + fill(task, surface, task->shape.bbox); + } else { + fill(task, surface, task->shape.bbox); + stroke(task, surface, task->curBox); + } + } else if (task->curBox.valid()) { + for (int idx = 0; idx < RenderDirtyRegion::PARTITIONING; ++idx) { + if (!dirtyRegion.partition(idx).intersected(task->curBox)) continue; + ARRAY_FOREACH(p, dirtyRegion.get(idx)) { + if (task->curBox.max.x <= p->min.x) break; //dirtyRegion is sorted in x order + if (task->rshape->strokeFirst()) { + if (task->rshape->stroke && task->curBox.intersected(*p)) stroke(task, surface, RenderRegion::intersect(task->curBox, *p)); + if (task->shape.bbox.intersected(*p)) fill(task, surface, RenderRegion::intersect(task->shape.bbox, *p)); + } else { + if (task->shape.bbox.intersected(*p)) fill(task, surface, RenderRegion::intersect(task->shape.bbox, *p)); + if (task->rshape->stroke && task->curBox.intersected(*p)) stroke(task, surface, RenderRegion::intersect(task->curBox, *p)); + } + } + } + } + } + task->prvBox = task->curBox; + return true; +} + + +bool SwRenderer::blend(BlendMethod method) +{ + if (surface->blendMethod == method) return true; + surface->blendMethod = method; + + switch (method) { + case BlendMethod::Multiply: + surface->blender = opBlendMultiply; + break; + case BlendMethod::Screen: + surface->blender = opBlendScreen; + break; + case BlendMethod::Overlay: + surface->blender = opBlendOverlay; + break; + case BlendMethod::Darken: + surface->blender = opBlendDarken; + break; + case BlendMethod::Lighten: + surface->blender = opBlendLighten; + break; + case BlendMethod::ColorDodge: + surface->blender = opBlendColorDodge; + break; + case BlendMethod::ColorBurn: + surface->blender = opBlendColorBurn; + break; + case BlendMethod::HardLight: + surface->blender = opBlendHardLight; + break; + case BlendMethod::SoftLight: + surface->blender = opBlendSoftLight; + break; + case BlendMethod::Difference: + surface->blender = opBlendDifference; + break; + case BlendMethod::Exclusion: + surface->blender = opBlendExclusion; + break; + case BlendMethod::Hue: + surface->blender = opBlendHue; + break; + case BlendMethod::Saturation: + surface->blender = opBlendSaturation; + break; + case BlendMethod::Color: + surface->blender = opBlendColor; + break; + case BlendMethod::Luminosity: + surface->blender = opBlendLuminosity; + break; + case BlendMethod::Add: + surface->blender = opBlendAdd; + break; + default: + surface->blender = nullptr; + break; + } + return true; +} + + +RenderRegion SwRenderer::region(RenderData data) +{ + if (data) return static_cast(data)->bounds(); + return {}; +} + + +bool SwRenderer::beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) +{ + if (!cmp) return false; + auto p = static_cast(cmp); + + p->method = method; + p->opacity = opacity; + + //Current Context? + if (p->method != MaskMethod::None) { + surface = p->recoverSfc; + surface->compositor = p; + } + + return true; +} + + +const RenderSurface* SwRenderer::mainSurface() +{ + return surface; +} + + +SwSurface* SwRenderer::request(int channelSize, bool square) +{ + SwSurface* cmp = nullptr; + uint32_t w, h; + + if (square) { + //Same Dimensional Size is demanded for the Post Processing Fast Flipping + w = h = std::max(surface->w, surface->h); + } else { + w = surface->w; + h = surface->h; + } + + //Use cached data + ARRAY_FOREACH(p, compositors) { + auto cur = *p; + if (cur->compositor->valid && cur->compositor->image.channelSize == channelSize) { + if (w == cur->w && h == cur->h) { + cmp = *p; + break; + } + } + } + + //New Composition + if (!cmp) { + //Inherits attributes from main surface + cmp = new SwSurface(surface); + cmp->compositor = new SwCompositor; + cmp->compositor->image.data = tvg::malloc(channelSize * w * h); + cmp->w = cmp->compositor->image.w = w; + cmp->h = cmp->compositor->image.h = h; + cmp->stride = cmp->compositor->image.stride = w; + cmp->compositor->image.direct = true; + cmp->compositor->valid = true; + cmp->channelSize = cmp->compositor->image.channelSize = channelSize; + + compositors.push(cmp); + } + + //Sync. This may have been modified by post-processing. + cmp->data = cmp->compositor->image.data; + + return cmp; +} + + +RenderCompositor* SwRenderer::target(const RenderRegion& region, ColorSpace cs, CompositionFlag flags) +{ + auto bbox = RenderRegion::intersect(region, {{0, 0}, {int32_t(surface->w), int32_t(surface->h)}}); + if (bbox.invalid()) return nullptr; + + auto cmp = request(CHANNEL_SIZE(cs), (flags & CompositionFlag::PostProcessing)); + cmp->compositor->recoverSfc = surface; + cmp->compositor->recoverCmp = surface->compositor; + cmp->compositor->valid = false; + cmp->compositor->bbox = bbox; + + /* TODO: Currently, only blending might work. + Blending and composition must be handled together. */ + rasterClear(cmp, bbox.x(), bbox.y(), bbox.w(), bbox.h()); + + //Switch render target + surface = cmp; + + return cmp->compositor; +} + + +bool SwRenderer::endComposite(RenderCompositor* cmp) +{ + if (!cmp) return false; + + auto p = static_cast(cmp); + + //Recover Context + surface = p->recoverSfc; + surface->compositor = p->recoverCmp; + + //only invalid (currently used) surface can be composited + if (p->valid) return true; + p->valid = true; + + //Default is alpha blending + if (p->method == MaskMethod::None) { + return rasterDirectImage(surface, p->image, p->bbox, p->opacity); + } + + return true; +} + + +void SwRenderer::prepare(RenderEffect* effect, const Matrix& transform) +{ + switch (effect->type) { + case SceneEffect::GaussianBlur: effectGaussianBlurUpdate(static_cast(effect), transform); break; + case SceneEffect::DropShadow: effectDropShadowUpdate(static_cast(effect), transform); break; + case SceneEffect::Fill: effectFillUpdate(static_cast(effect)); break; + case SceneEffect::Tint: effectTintUpdate(static_cast(effect)); break; + case SceneEffect::Tritone: effectTritoneUpdate(static_cast(effect)); break; + default: break; + } +} + + +bool SwRenderer::bounds(RenderData data, Point* pt4, const Matrix& m) +{ + if (!data) return false; + + auto task = static_cast(data); + task->done(); + + return shapeStrokeBBox(task->shape, task->rshape, pt4, m, task->mpool); +} + + +bool SwRenderer::intersectsShape(RenderData data, const RenderRegion& region) +{ + auto task = static_cast(data); + task->done(); + + if (!task->valid || !task->bounds().intersected(region)) return false; + if (rleIntersect(task->shape.strokeRle, region)) return true; + return task->shape.rle ? rleIntersect(task->shape.rle, region): task->shape.fastTrack; +} + + +bool SwRenderer::intersectsImage(RenderData data, const RenderRegion& region) +{ + auto task = static_cast(data); + task->done(); + + if (!task->valid || !task->bounds().intersected(region)) return false; + + //aabb & obb transformed image intersection + auto rad = tvg::radian(task->transform); + if (rad > 0.0f && rad < MATH_PI) { + Point aabb[4]; + aabb[0] = {(float)region.min.x, (float)region.min.y}; + aabb[1] = {(float)region.max.x, (float)region.min.y}; + aabb[2] = {(float)region.max.x, (float)region.max.y}; + aabb[3] = {(float)region.min.x, (float)region.max.y}; + + Point obb[4]; + obb[0] = Point{0.0f, 0.0f} * task->transform; + obb[1] = Point{(float)task->image.w, 0.0f} * task->transform; + obb[2] = Point{(float)task->image.w, (float)task->image.h} * task->transform; + obb[3] = Point{0.0f, (float)task->image.h} * task->transform; + + auto project = [](const Point* poly, const Point& axis, float& min, float& max) { + min = max = dot(poly[0], axis); + for (int i = 1; i < 4; ++i) { + float projection = dot(poly[i], axis); + if (projection < min) min = projection; + if (projection > max) max = projection; + } + }; + + for (int i = 0; i < 4; ++i) { + auto edge = (i < 2) ? (aabb[(i+1)%4] - aabb[i]) : (obb[(i-2+1)%4] - obb[i-2]); + tvg::normalize(edge); + float minA, maxA, minB, maxB; + project(aabb, edge, minA, maxA); + project(obb, edge, minB, maxB); + if (maxA < minB || maxB < minA) return false; + } + } + return task->image.rle ? rleIntersect(task->image.rle, region) : true; +} + + +bool SwRenderer::region(RenderEffect* effect) +{ + switch (effect->type) { + case SceneEffect::GaussianBlur: return effectGaussianBlurRegion(static_cast(effect)); + case SceneEffect::DropShadow: return effectDropShadowRegion(static_cast(effect)); + default: return false; + } +} + + +bool SwRenderer::render(RenderCompositor* cmp, const RenderEffect* effect, bool direct) +{ + auto p = static_cast(cmp); + + if (p->image.channelSize != sizeof(uint32_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale Gaussian Blur!"); + return false; + } + + //TODO: Support grayscale effects. + if (p->recoverSfc->channelSize != sizeof(uint32_t)) direct = false; + + switch (effect->type) { + case SceneEffect::GaussianBlur: { + return effectGaussianBlur(p, request(surface->channelSize, true), static_cast(effect)); + } + case SceneEffect::DropShadow: { + auto cmp1 = request(surface->channelSize, true); + cmp1->compositor->valid = false; //prevent a conflict with cmp2 request. + auto cmp2 = request(surface->channelSize, true); + SwSurface* surfaces[] = {cmp1, cmp2}; + auto ret = effectDropShadow(p, surfaces, static_cast(effect), direct); + cmp1->compositor->valid = true; + return ret; + } + case SceneEffect::Fill: { + return effectFill(p, static_cast(effect), direct); + } + case SceneEffect::Tint: { + return effectTint(p, static_cast(effect), direct); + } + case SceneEffect::Tritone: { + return effectTritone(p, static_cast(effect), direct); + } + default: return false; + } +} + + +void SwRenderer::dispose(RenderEffect* effect) +{ + tvg::free(effect->rd); + effect->rd = nullptr; +} + + +ColorSpace SwRenderer::colorSpace() +{ + if (surface) return surface->cs; + else return ColorSpace::Unknown; +} + + +void SwRenderer::dispose(RenderData data) +{ + auto task = static_cast(data); + task->done(); + task->dispose(); + + if (task->pushed) task->disposed = true; + else delete(task); +} + + +void* SwRenderer::prepareCommon(SwTask* task, const Matrix& transform, const Array& clips, uint8_t opacity, RenderUpdateFlag flags) +{ + if (task->disposed) return task; + + task->surface = surface; + task->mpool = mpool; + task->clipBox = RenderRegion::intersect(vport, {{0, 0}, {int32_t(surface->w), int32_t(surface->h)}}); + task->transform = transform; + task->clips = clips; + task->dirtyRegion = &dirtyRegion; + task->opacity = opacity; + task->nodirty = dirtyRegion.deactivated(); + task->flags[0] = flags; + task->valid = false; + + if (!task->pushed) { + task->pushed = true; + tasks.push(task); + } + + //TODO: Failed threading them. It would be better if it's possible. + //See: https://github.com/thorvg/thorvg/issues/1409 + //Guarantee composition targets get ready. + ARRAY_FOREACH(p, clips) { + static_cast(*p)->done(); + } + + if (flags) TaskScheduler::request(task); + + return task; +} + + +RenderData SwRenderer::prepare(RenderSurface* surface, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) +{ + auto task = static_cast(data); + if (task) task->done(); + else { + task = new SwImageTask; + task->source = surface; + } + + return prepareCommon(task, transform, clips, opacity, flags); +} + + +RenderData SwRenderer::prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) +{ + auto task = static_cast(data); + if (task) task->done(); + else { + task = new SwShapeTask; + task->rshape = &rshape; + } + + task->clipper = clipper; + + return prepareCommon(task, transform, clips, opacity, flags); +} + + +bool SwRenderer::term() +{ + if (rendererCnt > 0) return false; + + mpoolTerm(globalMpool); + globalMpool = nullptr; + rendererCnt = -1; + + return true; +} + + +SwRenderer::SwRenderer(uint32_t threads, EngineOption op) +{ + //initialize engine + if (rendererCnt == -1) { +#ifdef THORVG_OPENMP_SUPPORT + omp_set_num_threads(threads); +#endif + //Share the memory pool among the renderer + globalMpool = mpoolInit(threads); + threadsCnt = threads; + rendererCnt = 0; + } + + if (TaskScheduler::onthread()) { + TVGLOG("SW_RENDERER", "Running on a non-dominant thread!, Renderer(%p)", this); + mpool = mpoolInit(threadsCnt); + sharedMpool = false; + } else { + mpool = globalMpool; + sharedMpool = true; + } + + if (op == EngineOption::None) dirtyRegion.support = false; + + ++rendererCnt; +} diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRenderer.h b/components/thorvg-main/src/renderer/sw_engine/tvgSwRenderer.h new file mode 100644 index 0000000..f664424 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRenderer.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SW_RENDERER_H_ +#define _TVG_SW_RENDERER_H_ + +#include "tvgRender.h" + +struct SwSurface; +struct SwTask; +struct SwCompositor; +struct SwMpool; + +namespace tvg +{ + +struct SwRenderer : RenderMethod +{ + //main features + bool preUpdate() override; + RenderData prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) override; + RenderData prepare(RenderSurface* surface, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) override; + bool postUpdate() override; + bool preRender() override; + bool renderShape(RenderData data) override; + bool renderImage(RenderData data) override; + bool postRender() override; + void dispose(RenderData data) override; + RenderRegion region(RenderData data) override; + bool bounds(RenderData data, Point* pt4, const Matrix& m) override; + bool blend(BlendMethod method) override; + ColorSpace colorSpace() override; + const RenderSurface* mainSurface() override; + bool clear() override; + bool sync() override; + bool intersectsShape(RenderData data, const RenderRegion& region) override; + bool intersectsImage(RenderData data, const RenderRegion& region) override; + bool target(pixel_t* data, uint32_t stride, uint32_t w, uint32_t h, ColorSpace cs); + + //composition + SwSurface* request(int channelSize, bool square); + RenderCompositor* target(const RenderRegion& region, ColorSpace cs, CompositionFlag flags) override; + bool beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) override; + bool endComposite(RenderCompositor* cmp) override; + void clearCompositors(); + + //post effects + void prepare(RenderEffect* effect, const Matrix& transform) override; + bool region(RenderEffect* effect) override; + bool render(RenderCompositor* cmp, const RenderEffect* effect, bool direct) override; + void dispose(RenderEffect* effect) override; + + //partial rendering + void damage(RenderData rd, const RenderRegion& region) override; + bool partial(bool disable) override; + + SwRenderer(uint32_t threads, EngineOption op); + static bool term(); + +private: + SwSurface* surface = nullptr; //active surface + Array tasks; //async task list + Array compositors; //render targets cache list + RenderDirtyRegion dirtyRegion; //partial rendering support + SwMpool* mpool; //private memory pool + bool sharedMpool; //memory-pool behavior policy + bool fulldraw = true; //buffer is cleared (need to redraw full screen) + + ~SwRenderer(); + + RenderData prepareCommon(SwTask* task, const Matrix& transform, const Array& clips, uint8_t opacity, RenderUpdateFlag flags); +}; + +} + +#endif /* _TVG_SW_RENDERER_H_ */ diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwRle.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwRle.cpp new file mode 100644 index 0000000..d4a8c8e --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwRle.cpp @@ -0,0 +1,977 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * The FreeType Project LICENSE + * ---------------------------- + + * 2006-Jan-27 + + * Copyright 1996-2002, 2006 by + * David Turner, Robert Wilhelm, and Werner Lemberg + + + + * Introduction + * ============ + + * The FreeType Project is distributed in several archive packages; + * some of them may contain, in addition to the FreeType font engine, + * various tools and contributions which rely on, or relate to, the + * FreeType Project. + + * This license applies to all files found in such packages, and + * which do not fall under their own explicit license. The license + * affects thus the FreeType font engine, the test programs, + * documentation and makefiles, at the very least. + + * This license was inspired by the BSD, Artistic, and IJG + * (Independent JPEG Group) licenses, which all encourage inclusion + * and use of free software in commercial and freeware products + * alike. As a consequence, its main points are that: + + * o We don't promise that this software works. However, we will be + * interested in any kind of bug reports. (`as is' distribution) + + * o You can use this software for whatever you want, in parts or + * full form, without having to pay us. (`royalty-free' usage) + + * o You may not pretend that you wrote this software. If you use + * it, or only parts of it, in a program, you must acknowledge + * somewhere in your documentation that you have used the + * FreeType code. (`credits') + + * We specifically permit and encourage the inclusion of this + * software, with or without modifications, in commercial products. + * We disclaim all warranties covering The FreeType Project and + * assume no liability related to The FreeType Project. + + + * Finally, many people asked us for a preferred form for a + * credit/disclaimer to use in compliance with this license. We thus + * encourage you to use the following text: + + * """ + * Portions of this software are copyright � The FreeType + * Project (www.freetype.org). All rights reserved. + * """ + + * Please replace with the value from the FreeType version you + * actually use. + +* Legal Terms +* =========== + +* 0. Definitions +* -------------- + +* Throughout this license, the terms `package', `FreeType Project', +* and `FreeType archive' refer to the set of files originally +* distributed by the authors (David Turner, Robert Wilhelm, and +* Werner Lemberg) as the `FreeType Project', be they named as alpha, +* beta or final release. + +* `You' refers to the licensee, or person using the project, where +* `using' is a generic term including compiling the project's source +* code as well as linking it to form a `program' or `executable'. +* This program is referred to as `a program using the FreeType +* engine'. + +* This license applies to all files distributed in the original +* FreeType Project, including all source code, binaries and +* documentation, unless otherwise stated in the file in its +* original, unmodified form as distributed in the original archive. +* If you are unsure whether or not a particular file is covered by +* this license, you must contact us to verify this. + +* The FreeType Project is copyright (C) 1996-2000 by David Turner, +* Robert Wilhelm, and Werner Lemberg. All rights reserved except as +* specified below. + +* 1. No Warranty +* -------------- + +* THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY +* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +* PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO +* USE, OF THE FREETYPE PROJECT. + +* 2. Redistribution +* ----------------- + +* This license grants a worldwide, royalty-free, perpetual and +* irrevocable right and license to use, execute, perform, compile, +* display, copy, create derivative works of, distribute and +* sublicense the FreeType Project (in both source and object code +* forms) and derivative works thereof for any purpose; and to +* authorize others to exercise some or all of the rights granted +* herein, subject to the following conditions: + +* o Redistribution of source code must retain this license file +* (`FTL.TXT') unaltered; any additions, deletions or changes to +* the original files must be clearly indicated in accompanying +* documentation. The copyright notices of the unaltered, +* original files must be preserved in all copies of source +* files. + +* o Redistribution in binary form must provide a disclaimer that +* states that the software is based in part of the work of the +* FreeType Team, in the distribution documentation. We also +* encourage you to put an URL to the FreeType web page in your +* documentation, though this isn't mandatory. + +* These conditions apply to any software derived from or based on +* the FreeType Project, not just the unmodified files. If you use +* our work, you must acknowledge us. However, no fee need be paid +* to us. + +* 3. Advertising +* -------------- + +* Neither the FreeType authors and contributors nor you shall use +* the name of the other for commercial, advertising, or promotional +* purposes without specific prior written permission. + +* We suggest, but do not require, that you use one or more of the +* following phrases to refer to this software in your documentation +* or advertising materials: `FreeType Project', `FreeType Engine', +* `FreeType library', or `FreeType Distribution'. + +* As you have not signed this license, you are not required to +* accept it. However, as the FreeType Project is copyrighted +* material, only this license, or another one contracted with the +* authors, grants you the right to use, distribute, and modify it. +* Therefore, by using, distributing, or modifying the FreeType +* Project, you indicate that you understand and accept all the terms +* of this license. + +* 4. Contacts +* ----------- + +* There are two mailing lists related to FreeType: + +* o freetype@nongnu.org + +* Discusses general use and applications of FreeType, as well as +* future and wanted additions to the library and distribution. +* If you are looking for support, start in this list if you +* haven't found anything to help you in the documentation. + +* o freetype-devel@nongnu.org + +* Discusses bugs, as well as engine internals, design issues, +* specific licenses, porting, etc. + +* Our home page can be found at + +* http://www.freetype.org +*/ + +#include +#include "tvgSwCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +constexpr auto PIXEL_BITS = 8; //must be at least 6 bits! +constexpr auto ONE_PIXEL = (1 << PIXEL_BITS); + +struct Band +{ + int32_t min, max; +}; + +struct RleWorker +{ + SwRle* rle; + + SwPoint cellPos; + SwPoint cellMin; + SwPoint cellMax; + int32_t cellXCnt; + int32_t cellYCnt; + + Area area; + int32_t cover; + + SwCell* cells; + ptrdiff_t maxCells; + ptrdiff_t cellsCnt; + + SwPoint pos; + + SwPoint bezStack[32 * 3 + 1]; + SwPoint lineStack[32 + 1]; + int levStack[32]; + + SwOutline* outline; + + int bandSize; + int bandShoot; + + SwCell* buffer; + uint32_t bufferSize; + + SwCell** yCells; + int32_t yCnt; + + bool invalid; + bool antiAlias; +}; + + +static inline SwPoint UPSCALE(const SwPoint& pt) +{ + return {int32_t(((unsigned long) pt.x) << (PIXEL_BITS - 6)), int32_t(((unsigned long) pt.y) << (PIXEL_BITS - 6))}; +} + + +static inline int32_t TRUNC(const int32_t x) +{ + return x >> PIXEL_BITS; +} + + +static inline SwPoint TRUNC(const SwPoint& pt) +{ + return {TRUNC(pt.x), TRUNC(pt.y)}; +} + + +static inline SwPoint FRACT(const SwPoint& pt) +{ + + return {pt.x & (ONE_PIXEL - 1), pt.y & (ONE_PIXEL - 1)}; +} + + +// Approximate sqrt(x*x+y*y) using the `alpha max plus beta min' algorithm. +// We use alpha = 1, beta = 3/8, giving us results with a largest error +// less than 7% compared to the exact value. +static inline int32_t HYPOT(SwPoint pt) +{ + if (pt.x < 0) pt.x = -pt.x; + if (pt.y < 0) pt.y = -pt.y; + return ((pt.x > pt.y) ? (pt.x + (3 * pt.y >> 3)) : (pt.y + (3 * pt.x >> 3))); +} + + +// Used to prevent integer overflow when calculating the distance between points. +// This function uses 64-bit arithmetic to safely compute the difference between coordinates. +static inline uint32_t SAFE_HYPOT(SwPoint& pt1, SwPoint& pt2) +{ + auto x = uint32_t(abs(int64_t(pt1.x) - int64_t(pt2.x))); + auto y = uint32_t(abs(int64_t(pt1.y) - int64_t(pt2.y))); + return (x > y) ? (x + (3 * y >> 3)) : (y + (3 * x >> 3)); +} + + +static void _horizLine(RleWorker& rw, int32_t x, int32_t y, int32_t area, int32_t aCount) +{ + x += rw.cellMin.x; + y += rw.cellMin.y; + + //Clip Y range + if (y < rw.cellMin.y || y >= rw.cellMax.y) return; + + /* compute the coverage line's coverage, depending on the outline fill rule */ + /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */ + auto coverage = static_cast(area >> (PIXEL_BITS * 2 + 1 - 8)); //range 0 - 255 + if (coverage < 0) coverage = -coverage; + + if (rw.outline->fillRule == FillRule::EvenOdd) { + coverage &= 511; + if (coverage > 255) coverage = 511 - coverage; + } else { + //normal non-zero winding rule + if (coverage > 255) coverage = 255; + } + + if (coverage == 0) return; + + //span has ushort coordinates. check limit overflow + if (x >= SHRT_MAX || y >= SHRT_MAX) { + TVGERR("SW_ENGINE", "XY-coordinate overflow!"); + return; + } + + auto rle = rw.rle; + + if (!rw.antiAlias) coverage = 255; + + //see whether we can add this span to the current list + if (!rle->spans.empty()) { + auto& span = rle->spans.last(); + if ((span.coverage == coverage) && (span.y == y) && (span.x + span.len == x)) { + //Clip x range + int32_t xOver = 0; + if (x + aCount >= rw.cellMax.x) xOver -= (x + aCount - rw.cellMax.x); + if (x < rw.cellMin.x) xOver -= (rw.cellMin.x - x); + span.len += (aCount + xOver); + return; + } + } + + //Clip x range + int32_t xOver = 0; + if (x + aCount >= rw.cellMax.x) xOver -= (x + aCount - rw.cellMax.x); + if (x < rw.cellMin.x) { + xOver -= (rw.cellMin.x - x); + x = rw.cellMin.x; + } + + //Nothing to draw + if (aCount + xOver <= 0) return; + + //add a span to the current list + rle->spans.next() = {(uint16_t)x, (uint16_t)y, uint16_t(aCount + xOver), (uint8_t)coverage}; +} + + +static void _sweep(RleWorker& rw) +{ + if (rw.cellsCnt == 0) return; + + for (int y = 0; y < rw.yCnt; ++y) { + auto cover = 0; + auto x = 0; + auto cell = rw.yCells[y]; + + while (cell) { + if (cell->x > x && cover != 0) _horizLine(rw, x, y, cover * (ONE_PIXEL * 2), cell->x - x); + cover += cell->cover; + auto area = cover * (ONE_PIXEL * 2) - cell->area; + if (area != 0 && cell->x >= 0) _horizLine(rw, cell->x, y, area, 1); + x = cell->x + 1; + cell = cell->next; + } + + if (cover != 0) _horizLine(rw, x, y, cover * (ONE_PIXEL * 2), rw.cellXCnt - x); + } +} + + +static SwCell* _findCell(RleWorker& rw) +{ + auto x = rw.cellPos.x; + if (x > rw.cellXCnt) x = rw.cellXCnt; + + auto pcell = &rw.yCells[rw.cellPos.y]; + + while(true) { + auto cell = *pcell; + if (!cell || cell->x > x) break; + if (cell->x == x) return cell; + pcell = &cell->next; + } + + if (rw.cellsCnt >= rw.maxCells) return nullptr; + + auto cell = rw.cells + rw.cellsCnt++; + cell->x = x; + cell->area = 0; + cell->cover = 0; + cell->next = *pcell; + *pcell = cell; + + return cell; +} + + +static bool _recordCell(RleWorker& rw) +{ + if (rw.area | rw.cover) { + auto cell = _findCell(rw); + if (!cell) return false; + cell->area += rw.area; + cell->cover += rw.cover; + } + + return true; +} + + +static bool _setCell(RleWorker& rw, SwPoint pos) +{ + /* Move the cell pointer to a new position. We set the `invalid' */ + /* flag to indicate that the cell isn't part of those we're interested */ + /* in during the render phase. This means that: */ + /* */ + /* . the new vertical position must be within min_ey..max_ey-1. */ + /* . the new horizontal position must be strictly less than max_ex */ + /* */ + /* Note that if a cell is to the left of the clipping region, it is */ + /* actually set to the (min_ex-1) horizontal position. */ + + /* All cells that are on the left of the clipping region go to the + min_ex - 1 horizontal position. */ + pos -= rw.cellMin; + + //exceptions + if (pos.x < 0) pos.x = -1; + else if (pos.x > rw.cellMax.x) pos.x = rw.cellMax.x; + + //Are we moving to a different cell? + if (pos != rw.cellPos) { + //Record the current one if it is valid + if (!rw.invalid && !_recordCell(rw)) return false; + rw.area = rw.cover = 0; + rw.cellPos = pos; + } + rw.invalid = ((unsigned)pos.y >= (unsigned)rw.cellYCnt || pos.x >= rw.cellXCnt); + + return true; +} + + +static bool _startCell(RleWorker& rw, SwPoint pos) +{ + if (pos.x > rw.cellMax.x) pos.x = rw.cellMax.x; + if (pos.x < rw.cellMin.x) pos.x = rw.cellMin.x - 1; + + rw.area = 0; + rw.cover = 0; + rw.cellPos = pos - rw.cellMin; + rw.invalid = false; + + return _setCell(rw, pos); +} + + +static bool _moveTo(RleWorker& rw, const SwPoint& to) +{ + //record current cell, if any */ + if (!rw.invalid && !_recordCell(rw)) return false; + + //start to a new position + if (!_startCell(rw, TRUNC(to))) return false; + + rw.pos = to; + + return true; +} + + +static bool _lineTo(RleWorker& rw, const SwPoint& to) +{ + auto e1 = TRUNC(rw.pos); + auto e2 = TRUNC(to); + + //vertical clipping + if ((e1.y >= rw.cellMax.y && e2.y >= rw.cellMax.y) || (e1.y < rw.cellMin.y && e2.y < rw.cellMin.y)) { + rw.pos = to; + return true; + } + + auto line = rw.lineStack; + line[0] = to; + line[1] = rw.pos; + + while (true) { + if (SAFE_HYPOT(line[0], line[1]) > SHRT_MAX) { + mathSplitLine(line); + ++line; + continue; + } + auto diff = line[0] - line[1]; + e1 = TRUNC(line[1]); + e2 = TRUNC(line[0]); + + auto f1 = FRACT(line[1]); + SwPoint f2; + + //inside one cell + if (e1 == e2) { + ; + //any horizontal line + } else if (diff.y == 0) { + e1.x = e2.x; + if (!_setCell(rw, e1)) return false; + } else if (diff.x == 0) { + //vertical line up + if (diff.y > 0) { + do { + f2.y = ONE_PIXEL; + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * f1.x * 2; + f1.y = 0; + ++e1.y; + if (!_setCell(rw, e1)) return false; + } while(e1.y != e2.y); + //vertical line down + } else { + do { + f2.y = 0; + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * f1.x * 2; + f1.y = ONE_PIXEL; + --e1.y; + if (!_setCell(rw, e1)) return false; + } while(e1.y != e2.y); + } + //any other line + } else { + #define SW_UDIV(a, b) (int32_t)((uint64_t(a) * uint64_t(b)) >> 32) + + Area prod = diff.x * f1.y - diff.y * f1.x; + + /* These macros speed up repetitive divisions by replacing them + with multiplications and right shifts. */ + auto dxr = (e1.x != e2.x) ? (int64_t)0xffffffff / diff.x : 0; + auto dyr = (e1.y != e2.y) ? (int64_t)0xffffffff / diff.y : 0; + auto px = diff.x * ONE_PIXEL; + auto py = diff.y * ONE_PIXEL; + + /* The fundamental value `prod' determines which side and the */ + /* exact coordinate where the line exits current cell. It is */ + /* also easily updated when moving from one cell to the next. */ + + do { + //left + if (prod <= 0 && prod - px > 0) { + f2 = {0, SW_UDIV(-prod, -dxr)}; + prod -= py; + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * (f1.x + f2.x); + f1 = {ONE_PIXEL, f2.y}; + --e1.x; + //up + } else if (prod - px <= 0 && prod - px + py > 0) { + prod -= px; + f2 = {SW_UDIV(-prod, dyr), ONE_PIXEL}; + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * (f1.x + f2.x); + f1 = {f2.x, 0}; + ++e1.y; + //right + } else if (prod - px + py <= 0 && prod + py >= 0) { + prod += py; + f2 = {ONE_PIXEL, SW_UDIV(prod, dxr)}; + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * (f1.x + f2.x); + f1 = {0, f2.y}; + ++e1.x; + //down + } else { + f2 = {SW_UDIV(prod, -dyr), 0}; + prod += px; + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * (f1.x + f2.x); + f1 = {f2.x, ONE_PIXEL}; + --e1.y; + } + + if (!_setCell(rw, e1)) return false; + + } while(e1 != e2); + } + + f2 = FRACT(line[0]); + rw.cover += (f2.y - f1.y); + rw.area += (f2.y - f1.y) * (f1.x + f2.x); + rw.pos = line[0]; + + if (line-- == rw.lineStack) return true; + } +} + + +static bool _cubicTo(RleWorker& rw, const SwPoint& ctrl1, const SwPoint& ctrl2, const SwPoint& to) +{ + auto arc = rw.bezStack; + arc[0] = to; + arc[1] = ctrl2; + arc[2] = ctrl1; + arc[3] = rw.pos; + + //Short-cut the arc that crosses the current band + auto min = arc[0].y; + auto max = arc[0].y; + + int32_t y; + for (auto i = 1; i < 4; ++i) { + y = arc[i].y; + if (y < min) min = y; + if (y > max) max = y; + } + + if (TRUNC(min) >= rw.cellMax.y || TRUNC(max) < rw.cellMin.y) goto draw; + + /* Decide whether to split or draw. See `Rapid Termination */ + /* Evaluation for Recursive Subdivision of Bezier Curves' by Thomas */ + /* F. Hain, at */ + /* http://www.cis.southalabama.edu/~hain/general/Publications/Bezier/Camera-ready%20CISST02%202.pdf */ + while (true) { + { + //diff is the P0 - P3 chord vector + auto diff = arc[3] - arc[0]; + auto L = HYPOT(diff); + + //avoid possible arithmetic overflow below by splitting + if (L > SHRT_MAX) goto split; + + //max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1) + auto sLimit = L * (ONE_PIXEL / 6); + + auto diff1 = arc[1] - arc[0]; + auto s = diff.y * diff1.x - diff.x * diff1.y; + if (s < 0) s = -s; + if (s > sLimit) goto split; + + //s is L * the perpendicular distance from P2 to the line P0 - P3 + auto diff2 = arc[2] - arc[0]; + s = diff.y * diff2.x - diff.x * diff2.y; + if (s < 0) s = -s; + if (s > sLimit) goto split; + + /* Split super curvy segments where the off points are so far + from the chord that the angles P0-P1-P3 or P0-P2-P3 become + acute as detected by appropriate dot products */ + if (diff1.x * (diff1.x - diff.x) + diff1.y * (diff1.y - diff.y) > 0 || + diff2.x * (diff2.x - diff.x) + diff2.y * (diff2.y - diff.y) > 0) + goto split; + + //no reason to split + goto draw; + } + split: + mathSplitCubic(arc); + arc += 3; + continue; + + draw: + if (!_lineTo(rw, arc[0])) return false; + if (arc == rw.bezStack) return true; + arc -= 3; + } +} + + +static bool _decomposeOutline(RleWorker& rw) +{ + auto outline = rw.outline; + auto first = 0; //index of first point in contour + + ARRAY_FOREACH(p, outline->cntrs) { + auto last = *p; + auto limit = outline->pts.data + last; + auto start = UPSCALE(outline->pts[first]); + auto pt = outline->pts.data + first; + auto types = outline->types.data + first; + ++types; + + if (!_moveTo(rw, UPSCALE(outline->pts[first]))) return false; + + while (pt < limit) { + //emit a single line_to + if (types[0] == SW_CURVE_TYPE_POINT) { + ++pt; + ++types; + if (!_lineTo(rw, UPSCALE(*pt))) return false; + //types cubic + } else { + pt += 3; + types += 3; + if (pt <= limit) { + if (!_cubicTo(rw, UPSCALE(pt[-2]), UPSCALE(pt[-1]), UPSCALE(pt[0]))) return false; + } else if (pt - 1 == limit) { + if (!_cubicTo(rw, UPSCALE(pt[-2]), UPSCALE(pt[-1]), start)) return false; + } + else goto close; + } + } + close: + if (!_lineTo(rw, start)) return false; + first = last + 1; + } + + return true; +} + + +static bool _genRle(RleWorker& rw) +{ + if (!_decomposeOutline(rw)) return false; + if (!rw.invalid && !_recordCell(rw)) return false; + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +SwRle* rleRender(SwRle* rle, const SwOutline* outline, const RenderRegion& bbox, SwMpool* mpool, unsigned tid, bool antiAlias) +{ + if (!outline) return nullptr; + + RleWorker rw; + auto cellPool = mpoolReqCellPool(mpool, tid); + auto reqSize = uint32_t(std::max(bbox.w(), bbox.h()) * 0.75f) * sizeof(SwCell); //experimental decision + + // grow by 1.25x and align to multiple of sizeof(SwCell) + if (reqSize > cellPool->size) { + cellPool->size = ((reqSize + (reqSize >> 2)) / sizeof(SwCell)) * sizeof(SwCell); + tvg::free(cellPool->buffer); + cellPool->buffer = tvg::malloc(cellPool->size); + } + + //Init Cells + rw.buffer = cellPool->buffer; + rw.bufferSize = cellPool->size; + rw.yCells = reinterpret_cast(cellPool->buffer); + rw.cells = nullptr; + rw.maxCells = 0; + rw.cellsCnt = 0; + rw.area = 0; + rw.cover = 0; + rw.invalid = true; + rw.cellMin = {bbox.min.x, bbox.min.y}; + rw.cellMax = {bbox.max.x, bbox.max.y}; + rw.cellXCnt = rw.cellMax.x - rw.cellMin.x; + rw.cellYCnt = rw.cellMax.y - rw.cellMin.y; + rw.outline = const_cast(outline); + rw.bandSize = rw.bufferSize / (sizeof(SwCell) * 2); + rw.bandShoot = 0; + rw.antiAlias = antiAlias; + + if (!rle) rw.rle = new SwRle; + else rw.rle = rle; + rw.rle->spans.reserve(256); + + //Generate RLE + constexpr auto BAND_SIZE = 40; + + Band bands[BAND_SIZE]; + Band* band; + + /* set up vertical bands */ + auto bandCnt = static_cast((rw.cellMax.y - rw.cellMin.y) / rw.bandSize); + if (bandCnt == 0) bandCnt = 1; + else if (bandCnt >= BAND_SIZE) bandCnt = (BAND_SIZE - 1); + + auto min = rw.cellMin.y; + auto yMax = rw.cellMax.y; + int32_t max; + + for (int n = 0; n < bandCnt; ++n, min = max) { + max = min + rw.bandSize; + if (n == bandCnt -1 || max > yMax) max = yMax; + + bands[0].min = min; + bands[0].max = max; + band = bands; + + while (band >= bands) { + rw.yCells = reinterpret_cast(rw.buffer); + rw.yCnt = band->max - band->min; + + int cellStart = sizeof(SwCell*) * (int)rw.yCnt; + int cellMod = cellStart % sizeof(SwCell); + + if (cellMod > 0) cellStart += sizeof(SwCell) - cellMod; + + auto cellsMax = reinterpret_cast((char*)rw.buffer + rw.bufferSize); + rw.cells = reinterpret_cast((char*)rw.buffer + cellStart); + + if (rw.cells >= cellsMax) goto reduce_bands; + + rw.maxCells = cellsMax - rw.cells; + if (rw.maxCells < 2) goto reduce_bands; + + for (int y = 0; y < rw.yCnt; ++y) + rw.yCells[y] = nullptr; + + rw.cellsCnt = 0; + rw.invalid = true; + rw.cellMin.y = band->min; + rw.cellMax.y = band->max; + rw.cellYCnt = band->max - band->min; + + if (_genRle(rw)) { + _sweep(rw); + --band; + continue; + } + + reduce_bands: + /* render pool overflow: we will reduce the render band by half */ + auto bottom = band->min; + auto top = band->max; + auto middle = bottom + ((top - bottom) >> 1); + + /* This is too complex for a single scanline; there must + be some problems */ + if (middle == bottom) { + rleFree(rw.rle); + return nullptr; + } + + if (bottom - top >= rw.bandSize) ++rw.bandShoot; + + band[1].min = bottom; + band[1].max = middle; + band[0].min = middle; + band[0].max = top; + ++band; + } + } + if (rw.bandShoot > 8 && rw.bandSize > 16) { + rw.bandSize = (rw.bandSize >> 1); + } + return rw.rle; +} + + +SwRle* rleRender(const RenderRegion* bbox) +{ + auto rle = tvg::calloc(sizeof(SwRle), 1); + rle->spans.reserve(bbox->h()); + rle->spans.count = bbox->h(); + + //cheaper without push() + auto x = uint16_t(bbox->min.x); + auto y = uint16_t(bbox->min.y); + auto len = uint16_t(bbox->w()); + + ARRAY_FOREACH(p, rle->spans) { + *p = {x, y++, len, 255}; + } + + return rle; +} + + +void rleReset(SwRle* rle) +{ + if (rle) rle->spans.clear(); +} + + +void rleFree(SwRle* rle) +{ + delete(rle); +} + + +bool rleClip(SwRle* rle, const SwRle *clip) +{ + if (rle->spans.empty() || clip->spans.empty()) return false; + + Array out; + out.reserve(std::max(rle->spans.count, clip->spans.count)); + + const SwSpan *end; + auto spans = rle->fetch(clip->spans.first().y, clip->spans.last().y, &end); + + if (spans >= end) { + rle->spans.clear(); + return false; + } + + const SwSpan *cend; + auto cspans = clip->fetch(spans->y, (end - 1)->y, &cend); + + while (spans < end && cspans < cend) { + //align y-coordinates. + if (cspans->y > spans->y) { + ++spans; + continue; + } + if (spans->y > cspans->y) { + ++cspans; + continue; + } + //try clipping with all clip spans which have a same y-coordinate. + auto temp = cspans; + while(temp < cend && temp->y == cspans->y) { + //span must be left(x1) to right(x2) direction. Not intersected. + if ((spans->x + spans->len) < spans->x || (temp->x + temp->len) < temp->x) { + ++temp; + continue; + } + //clip span region + auto x = std::max(spans->x, temp->x); + auto len = std::min((spans->x + spans->len), (temp->x + temp->len)) - x; + if (len > 0) out.next() = {uint16_t(x), temp->y, uint16_t(len), (uint8_t)(((spans->coverage * temp->coverage) + 0xff) >> 8)}; + ++temp; + } + ++spans; + } + out.move(rle->spans); + return true; +} + + +//Need to confirm: dead code? +bool rleClip(SwRle *rle, const RenderRegion* clip) +{ + if (rle->spans.empty() || clip->invalid()) return false; + + auto& min = clip->min; + auto& max = clip->max; + + Array out; + out.reserve(rle->spans.count); + auto data = out.data; + const SwSpan* end; + uint16_t x, len; + + for (auto p = rle->fetch(*clip, &end); p < end; ++p) { + if (p->y >= max.y) break; + if (p->y < min.y || p->x >= max.x || (p->x + p->len) <= min.x) continue; + if (p->x < min.x) { + x = min.x; + len = std::min(uint16_t(p->len - (x - p->x)), uint16_t(max.x - x)); + } else { + x = p->x; + len = std::min(p->len, uint16_t(max.x - x)); + } + if (len > 0) { + *data = {x, p->y, len, p->coverage}; + ++data; + ++out.count; + } + } + out.move(rle->spans); + return true; +} + + +bool rleIntersect(const SwRle* rle, const RenderRegion& region) +{ + if (!rle || rle->spans.empty()) return false; + + auto& min = region.min; + auto& max = region.max; + + const SwSpan* end; + for (auto p = rle->fetch(region, &end); p < end; ++p) { + if (p->y >= max.y) break; + if (p->y < min.y || p->x >= max.x || (p->x + p->len) <= min.x) continue; + return true; + } + return false; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwShape.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwShape.cpp new file mode 100644 index 0000000..85c1fc5 --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwShape.cpp @@ -0,0 +1,606 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgSwCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static bool _outlineBegin(SwOutline& outline) +{ + //Make a contour if lineTo/curveTo without calling close or moveTo beforehand. + if (outline.pts.empty()) return false; + outline.cntrs.push(outline.pts.count - 1); + outline.closed.push(false); + outline.pts.push(outline.pts[outline.cntrs.last()]); + outline.types.push(SW_CURVE_TYPE_POINT); + return false; +} + + +static bool _outlineEnd(SwOutline& outline) +{ + if (outline.pts.empty()) return false; + outline.cntrs.push(outline.pts.count - 1); + outline.closed.push(false); + return false; +} + + +static bool _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix& transform, bool closed = false) +{ + //make it a contour, if the last contour is not closed yet. + if (!closed) _outlineEnd(outline); + + outline.pts.push(mathTransform(to, transform)); + outline.types.push(SW_CURVE_TYPE_POINT); + return false; +} + + +static void _outlineLineTo(SwOutline& outline, const Point* to, const Matrix& transform) +{ + outline.pts.push(mathTransform(to, transform)); + outline.types.push(SW_CURVE_TYPE_POINT); +} + + +static void _outlineCubicTo(SwOutline& outline, const Point* ctrl1, const Point* ctrl2, const Point* to, const Matrix& transform) +{ + outline.pts.push(mathTransform(ctrl1, transform)); + outline.types.push(SW_CURVE_TYPE_CUBIC); + + outline.pts.push(mathTransform(ctrl2, transform)); + outline.types.push(SW_CURVE_TYPE_CUBIC); + + outline.pts.push(mathTransform(to, transform)); + outline.types.push(SW_CURVE_TYPE_POINT); +} + + +static bool _outlineClose(SwOutline& outline) +{ + uint32_t i; + if (outline.cntrs.count > 0) i = outline.cntrs.last() + 1; + else i = 0; + + //Make sure there is at least one point in the current path + if (outline.pts.count == i) return false; + + //Close the path + outline.pts.push(outline.pts[i]); + outline.cntrs.push(outline.pts.count - 1); + outline.types.push(SW_CURVE_TYPE_POINT); + outline.closed.push(true); + + return true; +} + + +static void _drawPoint(SwDashStroke& dash, const Point* start, const Matrix& transform) +{ + if (dash.move || dash.pattern[dash.curIdx] < FLOAT_EPSILON) { + _outlineMoveTo(*dash.outline, start, transform); + dash.move = false; + } + _outlineLineTo(*dash.outline, start, transform); +} + + +static void _dashLineTo(SwDashStroke& dash, const Point* to, const Matrix& transform, bool validPoint) +{ + Line cur = {dash.ptCur, *to}; + auto len = cur.length(); + if (tvg::zero(len)) { + _outlineMoveTo(*dash.outline, &dash.ptCur, transform); + //draw the current line fully + } else if (len <= dash.curLen) { + dash.curLen -= len; + if (!dash.curOpGap) { + if (dash.move) { + _outlineMoveTo(*dash.outline, &dash.ptCur, transform); + dash.move = false; + } + _outlineLineTo(*dash.outline, to, transform); + } + //draw the current line partially + } else { + while (len - dash.curLen > DASH_PATTERN_THRESHOLD) { + Line left, right; + if (dash.curLen > 0) { + len -= dash.curLen; + cur.split(dash.curLen, left, right); + if (!dash.curOpGap) { + if (dash.move || dash.pattern[dash.curIdx] - dash.curLen < FLOAT_EPSILON) { + _outlineMoveTo(*dash.outline, &left.pt1, transform); + dash.move = false; + } + _outlineLineTo(*dash.outline, &left.pt2, transform); + } + } else { + if (validPoint && !dash.curOpGap) _drawPoint(dash, &cur.pt1, transform); + right = cur; + } + dash.curIdx = (dash.curIdx + 1) % dash.cnt; + dash.curLen = dash.pattern[dash.curIdx]; + dash.curOpGap = !dash.curOpGap; + cur = right; + dash.ptCur = cur.pt1; + dash.move = true; + } + //leftovers + dash.curLen -= len; + if (!dash.curOpGap) { + if (dash.move) { + _outlineMoveTo(*dash.outline, &cur.pt1, transform); + dash.move = false; + } + _outlineLineTo(*dash.outline, &cur.pt2, transform); + } + if (dash.curLen < 1 && TO_SWCOORD(len) > 1) { + //move to next dash + dash.curIdx = (dash.curIdx + 1) % dash.cnt; + dash.curLen = dash.pattern[dash.curIdx]; + dash.curOpGap = !dash.curOpGap; + } + } + dash.ptCur = *to; +} + + +static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ctrl2, const Point* to, const Matrix& transform, bool validPoint) +{ + Bezier cur = {dash.ptCur, *ctrl1, *ctrl2, *to}; + auto len = cur.length(); + + //draw the current line fully + if (tvg::zero(len)) { + _outlineMoveTo(*dash.outline, &dash.ptCur, transform); + } else if (len <= dash.curLen) { + dash.curLen -= len; + if (!dash.curOpGap) { + if (dash.move) { + _outlineMoveTo(*dash.outline, &dash.ptCur, transform); + dash.move = false; + } + _outlineCubicTo(*dash.outline, ctrl1, ctrl2, to, transform); + } + //draw the current line partially + } else { + while ((len - dash.curLen) > DASH_PATTERN_THRESHOLD) { + Bezier left, right; + if (dash.curLen > 0) { + len -= dash.curLen; + cur.split(dash.curLen, left, right); + if (!dash.curOpGap) { + if (dash.move || dash.pattern[dash.curIdx] - dash.curLen < FLOAT_EPSILON) { + _outlineMoveTo(*dash.outline, &left.start, transform); + dash.move = false; + } + _outlineCubicTo(*dash.outline, &left.ctrl1, &left.ctrl2, &left.end, transform); + } + } else { + if (validPoint && !dash.curOpGap) _drawPoint(dash, &cur.start, transform); + right = cur; + } + dash.curIdx = (dash.curIdx + 1) % dash.cnt; + dash.curLen = dash.pattern[dash.curIdx]; + dash.curOpGap = !dash.curOpGap; + cur = right; + dash.ptCur = right.start; + dash.move = true; + } + //leftovers + dash.curLen -= len; + if (!dash.curOpGap) { + if (dash.move) { + _outlineMoveTo(*dash.outline, &cur.start, transform); + dash.move = false; + } + _outlineCubicTo(*dash.outline, &cur.ctrl1, &cur.ctrl2, &cur.end, transform); + } + if (dash.curLen < 0.1f && TO_SWCOORD(len) > 1) { + //move to next dash + dash.curIdx = (dash.curIdx + 1) % dash.cnt; + dash.curLen = dash.pattern[dash.curIdx]; + dash.curOpGap = !dash.curOpGap; + } + } + dash.ptCur = *to; +} + + +static void _dashClose(SwDashStroke& dash, const Matrix& transform, bool validPoint) +{ + _dashLineTo(dash, &dash.ptStart, transform, validPoint); +} + + +static void _dashMoveTo(SwDashStroke& dash, uint32_t offIdx, float offset, const Point* pts) +{ + dash.curIdx = offIdx % dash.cnt; + dash.curLen = dash.pattern[dash.curIdx] - offset; + dash.curOpGap = offIdx % 2; + dash.ptStart = dash.ptCur = *pts; + dash.move = true; +} + + +static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix& transform, SwMpool* mpool, unsigned tid, bool trimmed) +{ + PathCommand *cmds, *trimmedCmds = nullptr; + Point *pts, *trimmedPts = nullptr; + uint32_t cmdCnt, ptsCnt; + + if (trimmed) { + RenderPath trimmedPath; + if (!rshape->stroke->trim.trim(rshape->path, trimmedPath)) return nullptr; + cmds = trimmedCmds = trimmedPath.cmds.data; + cmdCnt = trimmedPath.cmds.count; + pts = trimmedPts = trimmedPath.pts.data; + ptsCnt = trimmedPath.pts.count; + + trimmedPath.cmds.data = nullptr; + trimmedPath.pts.data = nullptr; + } else { + cmds = rshape->path.cmds.data; + cmdCnt = rshape->path.cmds.count; + pts = rshape->path.pts.data; + ptsCnt = rshape->path.pts.count; + } + + //No actual shape data + if (cmdCnt == 0 || ptsCnt == 0) return nullptr; + + SwDashStroke dash; + dash.pattern = rshape->stroke->dash.pattern; + dash.cnt = rshape->stroke->dash.count; + auto offset = rshape->stroke->dash.offset; + + //offset + uint32_t offIdx = 0; + if (!tvg::zero(offset)) { + auto length = rshape->stroke->dash.length; + bool isOdd = dash.cnt % 2; + if (isOdd) length *= 2; + + offset = fmodf(offset, length); + if (offset < 0) offset += length; + + for (size_t i = 0; i < dash.cnt * (1 + (size_t)isOdd); ++i, ++offIdx) { + auto curPattern = dash.pattern[i % dash.cnt]; + if (offset < curPattern) break; + offset -= curPattern; + } + } + + dash.outline = mpoolReqOutline(mpool, tid); + + //must begin with moveTo + if (cmds[0] == PathCommand::MoveTo) { + _dashMoveTo(dash, offIdx, offset, pts); + cmds++; + pts++; + } + + //zero length segment with non-butt cap still should be rendered as a point - only the caps are visible + auto validPoint = rshape->stroke->cap != StrokeCap::Butt; + while (--cmdCnt > 0) { + switch (*cmds) { + case PathCommand::Close: { + _dashClose(dash, transform, validPoint); + break; + } + case PathCommand::MoveTo: { + _dashMoveTo(dash, offIdx, offset, pts); + ++pts; + break; + } + case PathCommand::LineTo: { + _dashLineTo(dash, pts, transform, validPoint); + ++pts; + break; + } + case PathCommand::CubicTo: { + _dashCubicTo(dash, pts, pts + 1, pts + 2, transform, validPoint); + pts += 3; + break; + } + } + ++cmds; + } + + _outlineEnd(*dash.outline); + + dash.outline->fillRule = rshape->rule; + + tvg::free(trimmedCmds); + tvg::free(trimmedPts); + + return dash.outline; +} + + +static bool _axisAlignedRect(const SwOutline* outline) +{ + //Fast Track: axis-aligned rectangle? + if (outline->pts.count != 5) return false; + if (outline->types[2] == SW_CURVE_TYPE_CUBIC) return false; + + auto pt1 = outline->pts.data + 0; + auto pt2 = outline->pts.data + 1; + auto pt3 = outline->pts.data + 2; + auto pt4 = outline->pts.data + 3; + + auto a = SwPoint{pt1->x, pt3->y}; + auto b = SwPoint{pt3->x, pt1->y}; + + if ((*pt2 == a && *pt4 == b) || (*pt2 == b && *pt4 == a)) return true; + + return false; +} + + +static SwOutline* _genOutline(SwShape& shape, const RenderShape* rshape, const Matrix& transform, SwMpool* mpool, unsigned tid, bool hasComposite, bool trimmed = false) +{ + PathCommand *cmds, *trimmedCmds = nullptr; + Point *pts, *trimmedPts = nullptr; + uint32_t cmdCnt, ptsCnt; + + if (trimmed) { + RenderPath trimmedPath; + if (!rshape->stroke->trim.trim(rshape->path, trimmedPath)) return nullptr; + cmds = trimmedCmds = trimmedPath.cmds.data; + cmdCnt = trimmedPath.cmds.count; + pts = trimmedPts = trimmedPath.pts.data; + ptsCnt = trimmedPath.pts.count; + + trimmedPath.cmds.data = nullptr; + trimmedPath.pts.data = nullptr; + } else { + cmds = rshape->path.cmds.data; + cmdCnt = rshape->path.cmds.count; + pts = rshape->path.pts.data; + ptsCnt = rshape->path.pts.count; + } + + //No actual shape data + if (cmdCnt == 0 || ptsCnt == 0) return nullptr; + + auto outline = mpoolReqOutline(mpool, tid); + auto closed = false; + + //Generate Outlines + while (cmdCnt-- > 0) { + switch (*cmds) { + case PathCommand::Close: { + if (!closed) closed = _outlineClose(*outline); + break; + } + case PathCommand::MoveTo: { + closed = _outlineMoveTo(*outline, pts, transform, closed); + ++pts; + break; + } + case PathCommand::LineTo: { + if (closed) closed = _outlineBegin(*outline); + _outlineLineTo(*outline, pts, transform); + ++pts; + break; + } + case PathCommand::CubicTo: { + if (closed) closed = _outlineBegin(*outline); + _outlineCubicTo(*outline, pts, pts + 1, pts + 2, transform); + pts += 3; + break; + } + } + ++cmds; + } + + if (!closed) _outlineEnd(*outline); + + outline->fillRule = rshape->rule; + + tvg::free(trimmedCmds); + tvg::free(trimmedPts); + + shape.fastTrack = (!hasComposite && _axisAlignedRect(outline)); + return outline; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +bool shapePrepare(SwShape& shape, const RenderShape* rshape, const Matrix& transform, const RenderRegion& clipBox, RenderRegion& renderBox, SwMpool* mpool, unsigned tid, bool hasComposite) +{ + if ((shape.outline = _genOutline(shape, rshape, transform, mpool, tid, hasComposite, rshape->trimpath()))) { + if (mathUpdateOutlineBBox(shape.outline, clipBox, renderBox, shape.fastTrack)) { + shape.bbox = renderBox; + return true; + } + } + return false; +} + + +bool shapeGenRle(SwShape& shape, const RenderRegion& bbox, SwMpool* mpool, unsigned tid, bool antiAlias) +{ + //Case A: Fast Track Rectangle Drawing + if (shape.fastTrack) return true; + + //Case B: Normal Shape RLE Drawing + if ((shape.rle = rleRender(shape.rle, shape.outline, bbox, mpool, tid, antiAlias))) return true; + + return false; +} + + +void shapeDelOutline(SwShape& shape, SwMpool* mpool, uint32_t tid) +{ + shape.outline = nullptr; +} + + +void shapeReset(SwShape& shape) +{ + rleReset(shape.rle); + shape.bbox.reset(); + shape.fastTrack = false; +} + + +void shapeFree(SwShape& shape) +{ + rleFree(shape.rle); + shape.rle = nullptr; + + shapeDelFill(shape); + + if (shape.stroke) { + rleFree(shape.strokeRle); + shape.strokeRle = nullptr; + strokeFree(shape.stroke); + shape.stroke = nullptr; + } +} + + +void shapeDelStroke(SwShape& shape) +{ + if (!shape.stroke) return; + rleFree(shape.strokeRle); + shape.strokeRle = nullptr; + strokeFree(shape.stroke); + shape.stroke = nullptr; +} + + +void shapeResetStroke(SwShape& shape, const RenderShape* rshape, const Matrix& transform, SwMpool* mpool, unsigned tid) +{ + if (!shape.stroke) shape.stroke = tvg::calloc(1, sizeof(SwStroke)); + auto stroke = shape.stroke; + strokeReset(stroke, rshape, transform, mpool, tid); + rleReset(shape.strokeRle); +} + + +bool shapeGenStrokeRle(SwShape& shape, const RenderShape* rshape, const Matrix& transform, const RenderRegion& clipBox, RenderRegion& renderBox, SwMpool* mpool, unsigned tid) +{ + SwOutline* shapeOutline = nullptr; + + //Dash style with/without trimming + if (rshape->stroke->dash.length > DASH_PATTERN_THRESHOLD) { + shapeOutline = _genDashOutline(rshape, transform, mpool, tid, rshape->trimpath()); + //Trimming & Normal style + } else { + shapeOutline = shape.outline ? shape.outline : _genOutline(shape, rshape, transform, mpool, tid, false, rshape->trimpath()); + } + + if (!shapeOutline) return false; + + if (!strokeParseOutline(shape.stroke, *shapeOutline, mpool, tid)) return false; + + auto strokeOutline = strokeExportOutline(shape.stroke, mpool, tid); + auto ret = mathUpdateOutlineBBox(strokeOutline, clipBox, renderBox, false); + if (ret) shape.strokeRle = rleRender(shape.strokeRle, strokeOutline, renderBox, mpool, tid, true); + + return ret; +} + + +bool shapeGenFillColors(SwShape& shape, const Fill* fill, const Matrix& transform, SwSurface* surface, uint8_t opacity, bool ctable) +{ + return fillGenColorTable(shape.fill, fill, transform, surface, opacity, ctable); +} + + +bool shapeGenStrokeFillColors(SwShape& shape, const Fill* fill, const Matrix& transform, SwSurface* surface, uint8_t opacity, bool ctable) +{ + return fillGenColorTable(shape.stroke->fill, fill, transform, surface, opacity, ctable); +} + + +void shapeResetFill(SwShape& shape) +{ + if (!shape.fill) { + shape.fill = tvg::calloc(1, sizeof(SwFill)); + if (!shape.fill) return; + } + fillReset(shape.fill); +} + + +void shapeResetStrokeFill(SwShape& shape) +{ + if (!shape.stroke->fill) { + shape.stroke->fill = tvg::calloc(1, sizeof(SwFill)); + if (!shape.stroke->fill) return; + } + fillReset(shape.stroke->fill); +} + + +void shapeDelFill(SwShape& shape) +{ + if (!shape.fill) return; + fillFree(shape.fill); + shape.fill = nullptr; +} + + +bool shapeStrokeBBox(SwShape& shape, const RenderShape* rshape, Point* pt4, const Matrix& m, SwMpool* mpool) +{ + auto outline = _genOutline(shape, rshape, m, mpool, 0, false, rshape->trimpath()); + if (!outline) return false; + + if (rshape->strokeWidth() > 0.0f) { + strokeReset(shape.stroke, rshape, m, mpool, 0); + strokeParseOutline(shape.stroke, *outline, mpool, 0); + + auto func = [](SwStrokeBorder* border, SwPoint& min, SwPoint& max) { + ARRAY_FOREACH(pts, border->pts) { + if (pts->x < min.x) min.x = pts->x; + if (pts->x > max.x) max.x = pts->x; + if (pts->y < min.y) min.y = pts->y; + if (pts->y > max.y) max.y = pts->y; + } + }; + + SwPoint min = {INT32_MAX, INT32_MAX}; + SwPoint max = {-INT32_MAX, -INT32_MAX}; + func(shape.stroke->borders[0], min, max); + func(shape.stroke->borders[1], min, max); + + pt4[0] = min.toPoint(); + pt4[1] = SwPoint{max.x, min.y}.toPoint(); + pt4[2] = max.toPoint(); + pt4[3] = SwPoint{min.x, max.y}.toPoint(); + } + + shapeDelOutline(shape, mpool, 0); + + return true; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/sw_engine/tvgSwStroke.cpp b/components/thorvg-main/src/renderer/sw_engine/tvgSwStroke.cpp new file mode 100644 index 0000000..228adbc --- /dev/null +++ b/components/thorvg-main/src/renderer/sw_engine/tvgSwStroke.cpp @@ -0,0 +1,810 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgSwCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define SW_STROKE_TAG_POINT 1 +#define SW_STROKE_TAG_CUBIC 2 +#define SW_STROKE_TAG_BEGIN 4 +#define SW_STROKE_TAG_END 8 + +static inline int64_t SIDE_TO_ROTATE(const int32_t s) +{ + return (SW_ANGLE_PI2 - static_cast(s) * SW_ANGLE_PI); +} + + +static inline void SCALE(const SwStroke& stroke, SwPoint& pt) +{ + pt.x = static_cast(pt.x * stroke.sx); + pt.y = static_cast(pt.y * stroke.sy); +} + + +static void _growBorder(SwStrokeBorder* border, uint32_t newPts) +{ + if (border->pts.count + newPts <= border->pts.reserved) return; + border->pts.grow(newPts * 20); + border->tags = tvg::realloc(border->tags, border->pts.reserved); //align the pts / tags memory size +} + + +static void _borderClose(SwStrokeBorder* border, bool reverse) +{ + auto start = border->start; + auto count = border->pts.count; + + //Don't record empty paths! + if (count <= start + 1U) { + border->pts.count = start; + } else { + /* Copy the last point to the start of this sub-path, + since it contains the adjusted starting coordinates */ + border->pts.count = --count; + border->pts[start] = border->pts[count]; + + if (reverse) { + //reverse the points + auto pt1 = border->pts.data + start + 1; + auto pt2 = border->pts.data + count - 1; + + while (pt1 < pt2) { + std::swap(*pt1, *pt2); + ++pt1; + --pt2; + } + + //reverse the tags + auto tag1 = border->tags + start + 1; + auto tag2 = border->tags + count - 1; + + while (tag1 < tag2) { + std::swap(*tag1, *tag2); + ++tag1; + --tag2; + } + } + + border->tags[start] |= SW_STROKE_TAG_BEGIN; + border->tags[count - 1] |= SW_STROKE_TAG_END; + } + + border->start = -1; + border->movable = false; +} + + +static void _borderCubicTo(SwStrokeBorder* border, const SwPoint& ctrl1, const SwPoint& ctrl2, const SwPoint& to) +{ + _growBorder(border, 3); + + auto tag = border->tags + border->pts.count; + + border->pts.push(ctrl1); + border->pts.push(ctrl2); + border->pts.push(to); + + tag[0] = SW_STROKE_TAG_CUBIC; + tag[1] = SW_STROKE_TAG_CUBIC; + tag[2] = SW_STROKE_TAG_POINT; + + border->movable = false; +} + + +static void _borderArcTo(SwStrokeBorder* border, const SwPoint& center, int64_t radius, int64_t angleStart, int64_t angleDiff, SwStroke& stroke) +{ + constexpr int64_t ARC_CUBIC_ANGLE = SW_ANGLE_PI / 2; + SwPoint a = {static_cast(radius), 0}; + mathRotate(a, angleStart); + SCALE(stroke, a); + a += center; + + auto total = angleDiff; + auto angle = angleStart; + auto rotate = (angleDiff >= 0) ? SW_ANGLE_PI2 : -SW_ANGLE_PI2; + + while (total != 0) { + auto step = total; + if (step > ARC_CUBIC_ANGLE) step = ARC_CUBIC_ANGLE; + else if (step < -ARC_CUBIC_ANGLE) step = -ARC_CUBIC_ANGLE; + + auto next = angle + step; + auto theta = step; + if (theta < 0) theta = -theta; + + theta >>= 1; + + //compute end point + SwPoint b = {static_cast(radius), 0}; + mathRotate(b, next); + SCALE(stroke, b); + b += center; + + //compute first and second control points + auto length = mathMulDiv(radius, mathSin(theta) * 4, (0x10000L + mathCos(theta)) * 3); + + SwPoint a2 = {static_cast(length), 0}; + mathRotate(a2, angle + rotate); + SCALE(stroke, a2); + a2 += a; + + SwPoint b2 = {static_cast(length), 0}; + mathRotate(b2, next - rotate); + SCALE(stroke, b2); + b2 += b; + + //add cubic arc + _borderCubicTo(border, a2, b2, b); + + //process the rest of the arc? + a = b; + total -= step; + angle = next; + } +} + + +static void _borderLineTo(SwStrokeBorder* border, const SwPoint& to, bool movable) +{ + if (border->movable) { + //move last point + border->pts.last() = to; + } else { + //don't add zero-length line_to + if (!border->pts.empty() && (border->pts.last() - to).tiny()) return; + _growBorder(border, 1); + border->tags[border->pts.count] = SW_STROKE_TAG_POINT; + border->pts.push(to); + } + + border->movable = movable; +} + + +static void _borderMoveTo(SwStrokeBorder* border, SwPoint& to) +{ + //close current open path if any? + if (border->start >= 0) _borderClose(border, false); + + border->start = border->pts.count; + border->movable = false; + + _borderLineTo(border, to, false); +} + + +static void _arcTo(SwStroke& stroke, int32_t side) +{ + auto border = stroke.borders[side]; + auto rotate = SIDE_TO_ROTATE(side); + auto total = mathDiff(stroke.angleIn, stroke.angleOut); + if (total == SW_ANGLE_PI) total = -rotate * 2; + + _borderArcTo(border, stroke.center, stroke.width, stroke.angleIn + rotate, total, stroke); + border->movable = false; +} + + +static void _outside(SwStroke& stroke, int32_t side, int64_t lineLength) +{ + auto border = stroke.borders[side]; + + if (stroke.join == StrokeJoin::Round) { + _arcTo(stroke, side); + } else { + //this is a mitered (pointed) or beveled (truncated) corner + auto rotate = SIDE_TO_ROTATE(side); + auto bevel = stroke.join == StrokeJoin::Bevel; + int64_t phi = 0; + int64_t thcos = 0; + + if (!bevel) { + auto theta = mathDiff(stroke.angleIn, stroke.angleOut); + if (theta == SW_ANGLE_PI) { + theta = rotate; + phi = stroke.angleIn; + } else { + theta /= 2; + phi = stroke.angleIn + theta + rotate; + } + + thcos = mathCos(theta); + auto sigma = mathMultiply(stroke.miterlimit, thcos); + + //is miter limit exceeded? + if (sigma < 0x10000L) bevel = true; + } + + //this is a bevel (broken angle) + if (bevel) { + SwPoint delta = {static_cast(stroke.width), 0}; + mathRotate(delta, stroke.angleOut + rotate); + SCALE(stroke, delta); + delta += stroke.center; + border->movable = false; + _borderLineTo(border, delta, false); + //this is a miter (intersection) + } else { + auto length = mathDivide(stroke.width, thcos); + SwPoint delta = {static_cast(length), 0}; + mathRotate(delta, phi); + SCALE(stroke, delta); + delta += stroke.center; + _borderLineTo(border, delta, false); + + /* Now add and end point + Only needed if not lineto (lineLength is zero for curves) */ + if (lineLength == 0) { + delta = {static_cast(stroke.width), 0}; + mathRotate(delta, stroke.angleOut + rotate); + SCALE(stroke, delta); + delta += stroke.center; + _borderLineTo(border, delta, false); + } + } + } +} + + +static void _inside(SwStroke& stroke, int32_t side, int64_t lineLength) +{ + auto border = stroke.borders[side]; + auto theta = mathDiff(stroke.angleIn, stroke.angleOut) / 2; + SwPoint delta; + bool intersect = false; + + /* Only intersect borders if between two line_to's and both + lines are long enough (line length is zero for curves). */ + if (border->movable && lineLength > 0) { + //compute minimum required length of lines + int64_t minLength = abs(mathMultiply(stroke.width, mathTan(theta))); + if (stroke.lineLength >= minLength && lineLength >= minLength) intersect = true; + } + + auto rotate = SIDE_TO_ROTATE(side); + + if (!intersect) { + delta = {static_cast(stroke.width), 0}; + mathRotate(delta, stroke.angleOut + rotate); + SCALE(stroke, delta); + delta += stroke.center; + border->movable = false; + } else { + //compute median angle + auto phi = stroke.angleIn + theta; + auto thcos = mathCos(theta); + delta = {static_cast(mathDivide(stroke.width, thcos)), 0}; + mathRotate(delta, phi + rotate); + SCALE(stroke, delta); + delta += stroke.center; + } + + _borderLineTo(border, delta, false); +} + + +void _processCorner(SwStroke& stroke, int64_t lineLength) +{ + auto turn = mathDiff(stroke.angleIn, stroke.angleOut); + + //no specific corner processing is required if the turn is 0 + if (turn == 0) return; + + //when we turn to the right, the inside side is 0 + int32_t inside = 0; + + //otherwise, the inside is 1 + if (turn < 0) inside = 1; + + //process the inside + _inside(stroke, inside, lineLength); + + //process the outside + _outside(stroke, 1 - inside, lineLength); +} + + +void _firstSubPath(SwStroke& stroke, int64_t startAngle, int64_t lineLength) +{ + SwPoint delta = {static_cast(stroke.width), 0}; + mathRotate(delta, startAngle + SW_ANGLE_PI2); + SCALE(stroke, delta); + + auto pt = stroke.center + delta; + _borderMoveTo(stroke.borders[0], pt); + + pt = stroke.center - delta; + _borderMoveTo(stroke.borders[1], pt); + + /* Save angle, position and line length for last join + lineLength is zero for curves */ + stroke.subPathAngle = startAngle; + stroke.firstPt = false; + stroke.subPathLineLength = lineLength; +} + + +static void _lineTo(SwStroke& stroke, const SwPoint& to) +{ + auto delta = to - stroke.center; + + //a zero-length lineto is a no-op + if (delta.zero()) { + //round and square caps are expected to be drawn as a dot even for zero-length lines + if (stroke.firstPt && stroke.cap != StrokeCap::Butt) _firstSubPath(stroke, 0, 0); + return; + } + + /* The lineLength is used to determine the intersection of strokes outlines. + The scale needs to be reverted since the stroke width has not been scaled. + An alternative option is to scale the width of the stroke properly by + calculating the mixture of the sx/sy rating on the stroke direction. */ + delta.x = static_cast(delta.x / stroke.sx); + delta.y = static_cast(delta.y / stroke.sy); + auto lineLength = mathLength(delta); + auto angle = mathAtan(delta); + + delta = {static_cast(stroke.width), 0}; + mathRotate(delta, angle + SW_ANGLE_PI2); + SCALE(stroke, delta); + + //process corner if necessary + if (stroke.firstPt) { + /* This is the first segment of a subpath. We need to add a point to each border + at their respective starting point locations. */ + _firstSubPath(stroke, angle, lineLength); + } else { + //process the current corner + stroke.angleOut = angle; + _processCorner(stroke, lineLength); + } + + //now add a line segment to both the inside and outside paths + for (int side = 0; side < 2; ++side) { + //the ends of lineto borders are movable + _borderLineTo(stroke.borders[side], to + delta, true); + delta.x = -delta.x; + delta.y = -delta.y; + } + + stroke.angleIn = angle; + stroke.center = to; + stroke.lineLength = lineLength; +} + + +static void _cubicTo(SwStroke& stroke, const SwPoint& ctrl1, const SwPoint& ctrl2, const SwPoint& to) +{ + SwPoint bezStack[37]; //TODO: static? + auto limit = bezStack + 32; + auto arc = bezStack; + auto firstArc = true; + arc[0] = to; + arc[1] = ctrl2; + arc[2] = ctrl1; + arc[3] = stroke.center; + + while (arc >= bezStack) { + int64_t angleIn, angleOut, angleMid; + + //initialize with current direction + angleIn = angleOut = angleMid = stroke.angleIn; + + auto valid = mathCubicAngle(arc, angleIn, angleMid, angleOut); + + //valid size + if (valid > 0 && arc < limit) { + if (stroke.firstPt) stroke.angleIn = angleIn; + mathSplitCubic(arc); + arc += 3; + continue; + } + + //ignoreable size + if (valid < 0 && arc == bezStack) { + stroke.center = to; + + //round and square caps are expected to be drawn as a dot even for zero-length lines + if (stroke.firstPt && stroke.cap != StrokeCap::Butt) _firstSubPath(stroke, 0, 0); + return; + } + + //small size + if (firstArc) { + firstArc = false; + //process corner if necessary + if (stroke.firstPt) { + _firstSubPath(stroke, angleIn, 0); + } else { + stroke.angleOut = angleIn; + _processCorner(stroke, 0); + } + } else if (abs(mathDiff(stroke.angleIn, angleIn)) > (SW_ANGLE_PI / 8) / 4) { + //if the deviation from one arc to the next is too great add a round corner + stroke.center = arc[3]; + stroke.angleOut = angleIn; + stroke.join = StrokeJoin::Round; + + _processCorner(stroke, 0); + + //reinstate line join style + stroke.join = stroke.joinSaved; + } + + //the arc's angle is small enough; we can add it directly to each border + auto theta1 = mathDiff(angleIn, angleMid) / 2; + auto theta2 = mathDiff(angleMid, angleOut) / 2; + auto phi1 = mathMean(angleIn, angleMid); + auto phi2 = mathMean(angleMid, angleOut); + auto length1 = mathDivide(stroke.width, mathCos(theta1)); + auto length2 = mathDivide(stroke.width, mathCos(theta2)); + int64_t alpha0 = 0; + + //compute direction of original arc + if (stroke.handleWideStrokes) { + alpha0 = mathAtan(arc[0] - arc[3]); + } + + for (int side = 0; side < 2; ++side) { + auto border = stroke.borders[side]; + auto rotate = SIDE_TO_ROTATE(side); + + //compute control points + SwPoint _ctrl1 = {static_cast(length1), 0}; + mathRotate(_ctrl1, phi1 + rotate); + SCALE(stroke, _ctrl1); + _ctrl1 += arc[2]; + + SwPoint _ctrl2 = {static_cast(length2), 0}; + mathRotate(_ctrl2, phi2 + rotate); + SCALE(stroke, _ctrl2); + _ctrl2 += arc[1]; + + //compute end point + SwPoint end = {static_cast(stroke.width), 0}; + mathRotate(end, angleOut + rotate); + SCALE(stroke, end); + end += arc[0]; + + if (stroke.handleWideStrokes) { + /* determine whether the border radius is greater than the radius of + curvature of the original arc */ + auto start = border->pts.last(); + auto alpha1 = mathAtan(end - start); + + //is the direction of the border arc opposite to that of the original arc? + if (abs(mathDiff(alpha0, alpha1)) > SW_ANGLE_PI / 2) { + + //use the sine rule to find the intersection point + auto beta = mathAtan(arc[3] - start); + auto gamma = mathAtan(arc[0] - end); + auto bvec = end - start; + auto blen = mathLength(bvec); + auto sinA = abs(mathSin(alpha1 - gamma)); + auto sinB = abs(mathSin(beta - gamma)); + auto alen = mathMulDiv(blen, sinA, sinB); + + SwPoint delta = {static_cast(alen), 0}; + mathRotate(delta, beta); + delta += start; + + //circumnavigate the negative sector backwards + border->movable = false; + _borderLineTo(border, delta, false); + _borderLineTo(border, end, false); + _borderCubicTo(border, _ctrl2, _ctrl1, start); + + //and then move to the endpoint + _borderLineTo(border, end, false); + continue; + } + } + _borderCubicTo(border, _ctrl1, _ctrl2, end); + } + arc -= 3; + stroke.angleIn = angleOut; + } + stroke.center = to; +} + + +static void _addCap(SwStroke& stroke, int64_t angle, int32_t side) +{ + if (stroke.cap == StrokeCap::Square) { + auto rotate = SIDE_TO_ROTATE(side); + auto border = stroke.borders[side]; + + SwPoint delta = {static_cast(stroke.width), 0}; + mathRotate(delta, angle); + SCALE(stroke, delta); + + SwPoint delta2 = {static_cast(stroke.width), 0}; + mathRotate(delta2, angle + rotate); + SCALE(stroke, delta2); + delta += stroke.center + delta2; + + _borderLineTo(border, delta, false); + + delta = {static_cast(stroke.width), 0}; + mathRotate(delta, angle); + SCALE(stroke, delta); + + delta2 = {static_cast(stroke.width), 0}; + mathRotate(delta2, angle - rotate); + SCALE(stroke, delta2); + delta += delta2 + stroke.center; + + _borderLineTo(border, delta, false); + } else if (stroke.cap == StrokeCap::Round) { + stroke.angleIn = angle; + stroke.angleOut = angle + SW_ANGLE_PI; + _arcTo(stroke, side); + } else { //Butt + auto rotate = SIDE_TO_ROTATE(side); + auto border = stroke.borders[side]; + + SwPoint delta = {static_cast(stroke.width), 0}; + mathRotate(delta, angle + rotate); + SCALE(stroke, delta); + delta += stroke.center; + + _borderLineTo(border, delta, false); + + delta = {static_cast(stroke.width), 0}; + mathRotate(delta, angle - rotate); + SCALE(stroke, delta); + delta += stroke.center; + + _borderLineTo(border, delta, false); + } +} + + +static void _addReverseLeft(SwStroke& stroke, bool opened) +{ + auto right = stroke.borders[0]; + auto left = stroke.borders[1]; + auto newPts = left->pts.count - left->start; + + if (newPts <= 0) return; + + _growBorder(right, newPts); + + auto dstTag = right->tags + right->pts.count; + auto srcPt = left->pts.end() - 1; + auto srcTag = left->tags + left->pts.count - 1; + + while (srcPt >= left->pts.data + left->start) { + right->pts.push(*srcPt); + *dstTag = *srcTag; + + if (opened) { + dstTag[0] &= ~(SW_STROKE_TAG_BEGIN | SW_STROKE_TAG_END); + } else { + //switch begin/end tags if necessary + auto ttag = dstTag[0] & (SW_STROKE_TAG_BEGIN | SW_STROKE_TAG_END); + if (ttag == SW_STROKE_TAG_BEGIN || ttag == SW_STROKE_TAG_END) + dstTag[0] ^= (SW_STROKE_TAG_BEGIN | SW_STROKE_TAG_END); + } + --srcPt; + --srcTag; + ++dstTag; + } + + left->pts.count = left->start; + right->movable = false; + left->movable = false; +} + + +static void _beginSubPath(SwStroke& stroke, const SwPoint& to, bool closed) +{ + /* We cannot process the first point because there is not enough + information regarding its corner/cap. Later, it will be processed + in the _endSubPath() */ + + stroke.firstPt = true; + stroke.center = to; + stroke.closedSubPath = closed; + + /* Determine if we need to check whether the border radius is greater + than the radius of curvature of a curve, to handle this case specially. + This is only required if bevel joins or butt caps may be created because + round & miter joins and round & square caps cover the negative sector + created with wide strokes. */ + if ((stroke.join != StrokeJoin::Round) || (!stroke.closedSubPath && stroke.cap == StrokeCap::Butt)) + stroke.handleWideStrokes = true; + else + stroke.handleWideStrokes = false; + + stroke.ptStartSubPath = to; + stroke.angleIn = 0; +} + + +static void _endSubPath(SwStroke& stroke) +{ + if (stroke.closedSubPath) { + //close the path if needed + if (stroke.center != stroke.ptStartSubPath) + _lineTo(stroke, stroke.ptStartSubPath); + + //process the corner + stroke.angleOut = stroke.subPathAngle; + auto turn = mathDiff(stroke.angleIn, stroke.angleOut); + + //No specific corner processing is required if the turn is 0 + if (turn != 0) { + //when we turn to the right, the inside is 0 + int32_t inside = 0; + + //otherwise, the inside is 1 + if (turn < 0) inside = 1; + + _inside(stroke, inside, stroke.subPathLineLength); //inside + _outside(stroke, 1 - inside, stroke.subPathLineLength); //outside + } + + _borderClose(stroke.borders[0], false); + _borderClose(stroke.borders[1], true); + } else { + auto right = stroke.borders[0]; + + /* all right, this is an opened path, we need to add a cap between + right & left, add the reverse of left, then add a final cap + between left & right */ + _addCap(stroke, stroke.angleIn, 0); + + //add reversed points from 'left' to 'right' + _addReverseLeft(stroke, true); + + //now add the final cap + stroke.center = stroke.ptStartSubPath; + _addCap(stroke, stroke.subPathAngle + SW_ANGLE_PI, 0); + + /* now end the right subpath accordingly. The left one is rewind + and doesn't need further processing */ + _borderClose(right, false); + } +} + + +static void _exportBorderOutline(const SwStroke& stroke, SwOutline* outline, uint32_t side) +{ + auto border = stroke.borders[side]; + if (border->pts.empty()) return; + + auto src = border->tags; + auto idx = outline->pts.count; + + ARRAY_FOREACH(pts, border->pts) { + if (*src & SW_STROKE_TAG_POINT) outline->types.push(SW_CURVE_TYPE_POINT); + else if (*src & SW_STROKE_TAG_CUBIC) outline->types.push(SW_CURVE_TYPE_CUBIC); + if (*src & SW_STROKE_TAG_END) outline->cntrs.push(idx); + ++src; + ++idx; + } + outline->pts.push(border->pts); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +void strokeFree(SwStroke* stroke) +{ + if (!stroke) return; + + fillFree(stroke->fill); + stroke->fill = nullptr; + + tvg::free(stroke); +} + + +void strokeReset(SwStroke* stroke, const RenderShape* rshape, const Matrix& transform, SwMpool* mpool, unsigned tid) +{ + stroke->sx = sqrtf(powf(transform.e11, 2.0f) + powf(transform.e21, 2.0f)); + stroke->sy = sqrtf(powf(transform.e12, 2.0f) + powf(transform.e22, 2.0f)); + stroke->width = HALF_STROKE(rshape->strokeWidth()); + stroke->cap = rshape->strokeCap(); + stroke->miterlimit = static_cast(rshape->strokeMiterlimit() * 65536.0f); + + //Save line join: it can be temporarily changed when stroking curves... + stroke->joinSaved = stroke->join = rshape->strokeJoin(); + + stroke->borders[0] = mpoolReqStrokeLBorder(mpool, tid); + stroke->borders[1] = mpoolReqStrokeRBorder(mpool, tid); +} + + +bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline, SwMpool* mpool, unsigned tid) +{ + uint32_t first = 0; + uint32_t i = 0; + + ARRAY_FOREACH(p, outline.cntrs) { + auto last = *p; //index of last point in contour + auto limit = outline.pts.data + last; + ++i; + + //Skip empty points + if (last <= first) { + first = last + 1; + continue; + } + + auto start = outline.pts[first]; + auto pt = outline.pts.data + first; + auto types = outline.types.data + first; + auto type = types[0]; + + //A contour cannot start with a cubic control point + if (type == SW_CURVE_TYPE_CUBIC) return false; + ++types; + + auto closed = outline.closed.data ? outline.closed.data[i - 1]: false; + + _beginSubPath(*stroke, start, closed); + + while (pt < limit) { + //emit a single line_to + if (types[0] == SW_CURVE_TYPE_POINT) { + ++pt; + ++types; + _lineTo(*stroke, *pt); + //types cubic + } else { + pt += 3; + types += 3; + if (pt <= limit) _cubicTo(*stroke, pt[-2], pt[-1], pt[0]); + else if (pt - 1 == limit) _cubicTo(*stroke, pt[-2], pt[-1], start); + else goto close; + } + } + close: + if (!stroke->firstPt) _endSubPath(*stroke); + first = last + 1; + } + return true; +} + + +SwOutline* strokeExportOutline(SwStroke* stroke, SwMpool* mpool, unsigned tid) +{ + auto reserve = stroke->borders[0]->pts.count + stroke->borders[1]->pts.count; + auto outline = mpoolReqOutline(mpool, tid); + outline->pts.reserve(reserve); + outline->types.reserve(reserve); + outline->fillRule = FillRule::NonZero; + + _exportBorderOutline(*stroke, outline, 0); //left + _exportBorderOutline(*stroke, outline, 1); //right + + return outline; +} diff --git a/components/thorvg-main/src/renderer/tvgAccessor.cpp b/components/thorvg-main/src/renderer/tvgAccessor.cpp new file mode 100644 index 0000000..fd67d2b --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgAccessor.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgIteratorAccessor.h" +#include "tvgCompressor.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static bool accessChildren(Iterator* it, function func, void* data) +{ + while (auto child = it->next()) { + //Access the child + if (!func(child, data)) return false; + + //Access the children of the child + if (auto it2 = IteratorAccessor::iterator(child)) { + if (!accessChildren(it2, func, data)) { + delete(it2); + return false; + } + delete(it2); + } + } + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +Result Accessor::set(Paint* paint, function func, void* data) noexcept +{ + if (!paint || !func) return Result::InvalidArguments; + + //Use the Preorder Tree-Search + + paint->ref(); + + //Root + if (!func(paint, data)) { + paint->unref(false); + return Result::Success; + } + + //Children + if (auto it = IteratorAccessor::iterator(paint)) { + accessChildren(it, func, data); + delete(it); + } + + paint->unref(false); + + return Result::Success; +} + + +uint32_t Accessor::id(const char* name) noexcept +{ + return djb2Encode(name); +} + + +Accessor::~Accessor() +{ + +} + + +Accessor::Accessor() : pImpl(nullptr) +{ + +} + + +Accessor* Accessor::gen() noexcept +{ + return new Accessor; +} diff --git a/components/thorvg-main/src/renderer/tvgAnimation.cpp b/components/thorvg-main/src/renderer/tvgAnimation.cpp new file mode 100644 index 0000000..6299895 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgAnimation.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgFrameModule.h" +#include "tvgAnimation.h" + + +Animation::~Animation() +{ + delete(pImpl); +} + + +Animation::Animation() : pImpl(new Impl) +{ +} + + +Result Animation::frame(float no) noexcept +{ + auto loader = to(pImpl->picture)->loader; + + if (!loader) return Result::InsufficientCondition; + if (!loader->animatable()) return Result::NonSupport; + + if (static_cast(loader)->frame(no)) { + PAINT(pImpl->picture)->mark(RenderUpdateFlag::All); + return Result::Success; + } + return Result::InsufficientCondition; +} + + +Picture* Animation::picture() const noexcept +{ + return pImpl->picture; +} + + +float Animation::curFrame() const noexcept +{ + auto loader = to(pImpl->picture)->loader; + + if (!loader) return 0; + if (!loader->animatable()) return 0; + + return static_cast(loader)->curFrame(); +} + + +float Animation::totalFrame() const noexcept +{ + auto loader = to(pImpl->picture)->loader; + + if (!loader) return 0; + if (!loader->animatable()) return 0; + + return static_cast(loader)->totalFrame(); +} + + +float Animation::duration() const noexcept +{ + auto loader = to(pImpl->picture)->loader; + + if (!loader) return 0; + if (!loader->animatable()) return 0; + + return static_cast(loader)->duration(); +} + + +Result Animation::segment(float begin, float end) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + if (!loader->animatable()) return Result::NonSupport; + + return static_cast(loader)->segment(begin, end); +} + + +Result Animation::segment(float *begin, float *end) noexcept +{ + auto loader = to(pImpl->picture)->loader; + if (!loader) return Result::InsufficientCondition; + if (!loader->animatable()) return Result::NonSupport; + if (!begin && !end) return Result::InvalidArguments; + + static_cast(loader)->segment(begin, end); + + return Result::Success; +} + + +Animation* Animation::gen() noexcept +{ + return new Animation; +} diff --git a/components/thorvg-main/src/renderer/tvgAnimation.h b/components/thorvg-main/src/renderer/tvgAnimation.h new file mode 100644 index 0000000..6eb5d49 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgAnimation.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_ANIMATION_H_ +#define _TVG_ANIMATION_H_ + +#include "tvgCommon.h" +#include "tvgPicture.h" + +struct Animation::Impl +{ + Picture* picture = nullptr; + + Impl() + { + picture = Picture::gen(); + picture->ref(); + } + + ~Impl() + { + picture->unref(); + } +}; + +#endif //_TVG_ANIMATION_H_ diff --git a/components/thorvg-main/src/renderer/tvgCanvas.cpp b/components/thorvg-main/src/renderer/tvgCanvas.cpp new file mode 100644 index 0000000..f79973d --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgCanvas.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgCanvas.h" +#include "tvgTaskScheduler.h" +#include "tvgLoadModule.h" + +#ifdef THORVG_SW_RASTER_SUPPORT + #include "tvgSwRenderer.h" +#endif + +#ifdef THORVG_GL_RASTER_SUPPORT + #include "tvgGlRenderer.h" +#endif + +#ifdef THORVG_WG_RASTER_SUPPORT + #include "tvgWgRenderer.h" +#endif + + +/************************************************************************/ +/* Canvas Class Implementation */ +/************************************************************************/ + +Canvas::Canvas():pImpl(new Impl) +{ +} + + +Canvas::~Canvas() +{ + delete(pImpl); +} + + +const list& Canvas::paints() const noexcept +{ + return pImpl->scene->paints(); +} + + +Result Canvas::add(Paint* target, Paint* at) noexcept +{ + if (target) return pImpl->add(target, at); + return Result::InvalidArguments; +} + + +Result Canvas::draw(bool clear) noexcept +{ + TVGLOG("RENDERER", "Draw S. -------------------------------- Canvas(%p)", this); + auto ret = pImpl->draw(clear); + TVGLOG("RENDERER", "Draw E. -------------------------------- Canvas(%p)", this); + + return ret; +} + + +Result Canvas::update() noexcept +{ + TVGLOG("RENDERER", "Update S. ------------------------------ Canvas(%p)", this); + auto ret = pImpl->update(); + TVGLOG("RENDERER", "Update E. ------------------------------ Canvas(%p)", this); + + return ret; +} + + +Result Canvas::remove(Paint* paint) noexcept +{ + return pImpl->remove(paint); +} + + +Result Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept +{ + return pImpl->viewport(x, y, w, h); +} + + +Result Canvas::sync() noexcept +{ + return pImpl->sync(); +} + + +/************************************************************************/ +/* SwCanvas Class Implementation */ +/************************************************************************/ + +SwCanvas::SwCanvas() = default; + +SwCanvas::~SwCanvas() +{ +#ifdef THORVG_SW_RASTER_SUPPORT + SwRenderer::term(); +#endif +} + + +Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, ColorSpace cs) noexcept +{ +#ifdef THORVG_SW_RASTER_SUPPORT + if (cs == ColorSpace::Unknown) return Result::InvalidArguments; + if (cs == ColorSpace::Grayscale8) return Result::NonSupport; + + if (pImpl->status == Status::Updating || pImpl->status == Status::Drawing) { + return Result::InsufficientCondition; + } + + //We know renderer type, avoid dynamic_cast for performance. + auto renderer = static_cast(pImpl->renderer); + if (!renderer) return Result::MemoryCorruption; + + if (!renderer->target(buffer, stride, w, h, cs)) return Result::InvalidArguments; + pImpl->vport = {{0, 0}, {(int32_t)w, (int32_t)h}}; + renderer->viewport(pImpl->vport); + + //FIXME: The value must be associated with an individual canvas instance. + ImageLoader::cs = static_cast(cs); + + //Paints must be updated again with this new target. + pImpl->status = Status::Damaged; + + return Result::Success; +#endif + return Result::NonSupport; +} + + +SwCanvas* SwCanvas::gen(EngineOption op) noexcept +{ +#ifdef THORVG_SW_RASTER_SUPPORT + if (engineInit > 0) { + auto renderer = new SwRenderer(TaskScheduler::threads(), op); + renderer->ref(); + auto ret = new SwCanvas; + ret->pImpl->renderer = renderer; + return ret; + } +#endif + return nullptr; +} + + +/************************************************************************/ +/* GlCanvas Class Implementation */ +/************************************************************************/ + +GlCanvas::GlCanvas() = default; + +GlCanvas::~GlCanvas() +{ +#ifdef THORVG_GL_RASTER_SUPPORT + GlRenderer::term(); +#endif +} + + +Result GlCanvas::target(void* display, void* surface, void* context, int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept +{ +#ifdef THORVG_GL_RASTER_SUPPORT + if (cs != ColorSpace::ABGR8888S) return Result::NonSupport; + + if (pImpl->status == Status::Updating || pImpl->status == Status::Drawing) { + return Result::InsufficientCondition; + } + + //We know renderer type, avoid dynamic_cast for performance. + auto renderer = static_cast(pImpl->renderer); + if (!renderer) return Result::MemoryCorruption; + + if (!renderer->target(display, surface, context, id, w, h, cs)) return Result::Unknown; + pImpl->vport = {{0, 0}, {(int32_t)w, (int32_t)h}}; + renderer->viewport(pImpl->vport); + + //Paints must be updated again with this new target. + pImpl->status = Status::Damaged; + + return Result::Success; +#endif + return Result::NonSupport; +} + + +GlCanvas* GlCanvas::gen(EngineOption op) noexcept +{ +#ifdef THORVG_GL_RASTER_SUPPORT + if (engineInit > 0) { + if (op == EngineOption::SmartRender) TVGLOG("RENDERER", "GlCanvas doesn't support Smart Rendering"); + auto renderer = GlRenderer::gen(TaskScheduler::threads()); + if (!renderer) return nullptr; + renderer->ref(); + auto ret = new GlCanvas; + ret->pImpl->renderer = renderer; + return ret; + } +#endif + return nullptr; +} + + +/************************************************************************/ +/* WgCanvas Class Implementation */ +/************************************************************************/ + +WgCanvas::WgCanvas() = default; + +WgCanvas::~WgCanvas() +{ +#ifdef THORVG_WG_RASTER_SUPPORT + auto renderer = static_cast(pImpl->renderer); + renderer->target(nullptr, nullptr, nullptr, 0, 0, ColorSpace::Unknown); + + WgRenderer::term(); +#endif +} + + +Result WgCanvas::target(void* device, void* instance, void* target, uint32_t w, uint32_t h, ColorSpace cs, int type) noexcept +{ +#ifdef THORVG_WG_RASTER_SUPPORT + if (cs != ColorSpace::ABGR8888S) return Result::NonSupport; + + if (pImpl->status == Status::Updating || pImpl->status == Status::Drawing) { + return Result::InsufficientCondition; + } + + //We know renderer type, avoid dynamic_cast for performance. + auto renderer = static_cast(pImpl->renderer); + if (!renderer) return Result::MemoryCorruption; + + if (!renderer->target((WGPUDevice)device, (WGPUInstance)instance, target, w, h, cs, type)) return Result::Unknown; + pImpl->vport = {{0, 0}, {(int32_t)w, (int32_t)h}}; + renderer->viewport(pImpl->vport); + + //Paints must be updated again with this new target. + pImpl->status = Status::Damaged; + + return Result::Success; +#endif + return Result::NonSupport; +} + + +WgCanvas* WgCanvas::gen(EngineOption op) noexcept +{ +#ifdef THORVG_WG_RASTER_SUPPORT + if (engineInit > 0) { + if (op == EngineOption::SmartRender) TVGLOG("RENDERER", "WgCanvas doesn't support Smart Rendering"); + auto renderer = WgRenderer::gen(TaskScheduler::threads()); + renderer->ref(); + auto ret = new WgCanvas; + ret->pImpl->renderer = renderer; + return ret; + } +#endif + return nullptr; +} diff --git a/components/thorvg-main/src/renderer/tvgCanvas.h b/components/thorvg-main/src/renderer/tvgCanvas.h new file mode 100644 index 0000000..a86df24 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgCanvas.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_CANVAS_H_ +#define _TVG_CANVAS_H_ + +#include "tvgPaint.h" + +enum Status : uint8_t {Synced = 0, Painting, Updating, Drawing, Damaged}; + +struct Canvas::Impl +{ + Scene* scene; + RenderMethod* renderer; + RenderRegion vport = {{0, 0}, {INT32_MAX, INT32_MAX}}; + Status status = Status::Synced; + + Impl() : scene(Scene::gen()) + { + scene->ref(); + } + + ~Impl() + { + //make it sure any deferred jobs + renderer->sync(); + scene->unref(); + if (renderer->unref() == 0) delete(renderer); + } + + Result add(Paint* target, Paint* at) + { + if (PAINT(target)->renderer && PAINT(target)->renderer != renderer) { + TVGERR("RENDERER", "Target paint(%p) is already owned by a different renderer.", target); + return Result::InsufficientCondition; + } + + //You cannot add paints during rendering. + if (status == Status::Drawing) { + TVGLOG("RENDERER", "add() was called during drawing."); + return Result::InsufficientCondition; + } + status = Status::Painting; + return scene->add(target, at); + } + + Result remove(Paint* paint) + { + if (status == Status::Drawing) { + TVGLOG("RENDERER", "remove() was called during drawing."); + return Result::InsufficientCondition; + } + status = Status::Painting; + return scene->remove(paint); + } + + Result update() + { + if (status == Status::Updating) return Result::Success; + + if (status == Status::Drawing) { + TVGLOG("RENDERER", "update() was called during drawing."); + return Result::InsufficientCondition; + } + + Array clips; + auto flag = RenderUpdateFlag::None; + + //TODO: All is too harsh, can be optimized. + if (status == Status::Damaged) flag = RenderUpdateFlag::All; + + if (!renderer->preUpdate()) return Result::InsufficientCondition; + + auto m = tvg::identity(); + PAINT(scene)->update(renderer, m, clips, 255, flag); + + if (!renderer->postUpdate()) return Result::InsufficientCondition; + + status = Status::Updating; + return Result::Success; + } + + Result draw(bool clear) + { + if (status == Status::Drawing) { + TVGLOG("RENDERER", "draw() was called multiple times."); + return Result::InsufficientCondition; + } + if (status == Status::Painting || status == Status::Damaged) update(); + if (status != Status::Updating) return Result::InsufficientCondition; + if (clear && !renderer->clear()) return Result::InsufficientCondition; + if (!renderer->preRender()) return Result::InsufficientCondition; + if (!PAINT(scene)->render(renderer) || !renderer->postRender()) return Result::InsufficientCondition; + + status = Status::Drawing; + + return Result::Success; + } + + Result sync() + { + if (status == Status::Synced) return Result::Success; + if (renderer->sync()) { + status = Status::Synced; + return Result::Success; + } + return Result::Unknown; + } + + Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) + { + if (status == Status::Synced || status == Status::Damaged) { + RenderRegion val = {{x, y}, {x + w, y + h}}; + //intersect if the target buffer is already set. + auto surface = renderer->mainSurface(); + if (surface && surface->w > 0 && surface->h > 0) { + val.intersect({{0, 0}, {(int32_t)surface->w, (int32_t)surface->h}}); + } + if (vport == val) return Result::Success; + renderer->viewport(val); + vport = val; + status = Status::Damaged; + return Result::Success; + } + TVGLOG("RENDERER", "viewport() is only allowed after sync."); + return Result::InsufficientCondition; + } +}; + +#endif /* _TVG_CANVAS_H_ */ diff --git a/components/thorvg-main/src/renderer/tvgFill.cpp b/components/thorvg-main/src/renderer/tvgFill.cpp new file mode 100644 index 0000000..ae0a4d7 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgFill.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgFill.h" + + +/************************************************************************/ +/* Fill Class Implementation */ +/************************************************************************/ + +Fill::Fill() = default; +Fill::~Fill() = default; + +Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept +{ + return pImpl->update(colorStops, cnt); +} + + +uint32_t Fill::colorStops(const ColorStop** colorStops) const noexcept +{ + if (colorStops) *colorStops = pImpl->colorStops; + return pImpl->cnt; +} + + +Result Fill::spread(FillSpread s) noexcept +{ + pImpl->spread = s; + return Result::Success; +} + + +FillSpread Fill::spread() const noexcept +{ + return pImpl->spread; +} + + +Result Fill::transform(const Matrix& m) noexcept +{ + pImpl->transform = m; + return Result::Success; +} + + +Matrix& Fill::transform() const noexcept +{ + return pImpl->transform; +} + + +Fill* Fill::duplicate() const noexcept +{ + if (type() == Type::LinearGradient) return CONST_LINEAR(this)->duplicate(); + else if (type() == Type::RadialGradient) return CONST_RADIAL(this)->duplicate(); + return nullptr; +} + + +/************************************************************************/ +/* RadialGradient Class Implementation */ +/************************************************************************/ + +RadialGradient::RadialGradient() = default; + + +Result RadialGradient::radial(float cx, float cy, float r, float fx, float fy, float fr) noexcept +{ + return RADIAL(this)->radial(cx, cy, r, fx, fy, fr); +} + + +Result RadialGradient::radial(float* cx, float* cy, float* r, float* fx, float* fy, float* fr) const noexcept +{ + return CONST_RADIAL(this)->radial(cx, cy, r, fx, fy, fr); +} + + +RadialGradient* RadialGradient::gen() noexcept +{ + return new RadialGradientImpl; +} + + +Type RadialGradient::type() const noexcept +{ + return Type::RadialGradient; +} + + +/************************************************************************/ +/* LinearGradient Class Implementation */ +/************************************************************************/ + +LinearGradient::LinearGradient() = default; + + +Result LinearGradient::linear(float x1, float y1, float x2, float y2) noexcept +{ + return LINEAR(this)->linear(x1, y1, x2, y2); +} + + +Result LinearGradient::linear(float* x1, float* y1, float* x2, float* y2) const noexcept +{ + return CONST_LINEAR(this)->linear(x1, y1, x2, y2); +} + + +LinearGradient* LinearGradient::gen() noexcept +{ + return new LinearGradientImpl; +} + + +Type LinearGradient::type() const noexcept +{ + return Type::LinearGradient; +} diff --git a/components/thorvg-main/src/renderer/tvgFill.h b/components/thorvg-main/src/renderer/tvgFill.h new file mode 100644 index 0000000..3d5d62f --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgFill.h @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_FILL_H_ +#define _TVG_FILL_H_ + +#include "tvgCommon.h" +#include "tvgMath.h" + +#define LINEAR(A) static_cast(A) +#define CONST_LINEAR(A) static_cast(A) + +#define RADIAL(A) static_cast(A) +#define CONST_RADIAL(A) static_cast(A) + +struct Fill::Impl +{ + ColorStop* colorStops = nullptr; + Matrix transform = tvg::identity(); + uint16_t cnt = 0; + FillSpread spread = FillSpread::Pad; + + virtual ~Impl() + { + tvg::free(colorStops); + } + + void copy(const Fill::Impl& dup) + { + cnt = dup.cnt; + spread = dup.spread; + colorStops = tvg::malloc(sizeof(ColorStop) * dup.cnt); + if (dup.cnt > 0) memcpy(colorStops, dup.colorStops, sizeof(ColorStop) * dup.cnt); + transform = dup.transform; + } + + Result update(const ColorStop* colorStops, uint32_t cnt) + { + if ((!colorStops && cnt > 0) || (colorStops && cnt == 0)) return Result::InvalidArguments; + + if (cnt == 0) { + if (this->colorStops) { + tvg::free(this->colorStops); + this->colorStops = nullptr; + this->cnt = 0; + } + return Result::Success; + } + + if (cnt != this->cnt) { + this->colorStops = tvg::realloc(this->colorStops, cnt * sizeof(ColorStop)); + } + + this->cnt = cnt; + memcpy(this->colorStops, colorStops, cnt * sizeof(ColorStop)); + + return Result::Success; + } +}; + + +struct RadialGradientImpl : RadialGradient +{ + Fill::Impl impl; + Point center{}, focal{}; + float r = 0.0f, fr = 0.0f; + + RadialGradientImpl() + { + Fill::pImpl = &impl; + } + + Fill* duplicate() const + { + auto ret = RadialGradient::gen(); + RADIAL(ret)->impl.copy(this->impl); + RADIAL(ret)->center = center; + RADIAL(ret)->r = r; + RADIAL(ret)->focal = focal; + RADIAL(ret)->fr = fr; + + return ret; + } + + Result radial(float cx, float cy, float r, float fx, float fy, float fr) + { + if (r < 0 || fr < 0) return Result::InvalidArguments; + + this->center = {cx, cy}; + this->r = r; + this->focal = {fx, fy}; + this->fr = fr; + + return Result::Success; + } + + Result radial(float* cx, float* cy, float* r, float* fx, float* fy, float* fr) const + { + if (cx) *cx = center.x; + if (cy) *cy = center.y; + if (r) *r = this->r; + if (fx) *fx = focal.x; + if (fy) *fy = focal.y; + if (fr) *fr = this->fr; + + return Result::Success; + } + + //TODO: remove this logic once SVG 2.0 is adopted by sw and wg engines (gl already supports it); lottie-specific handling will then be delegated entirely to the loader + //clamp focal point and shrink start circle if needed to avoid invalid gradient setup + bool correct(float& fx, float& fy, float& fr) const + { + constexpr float PRECISION = 0.01f; + if (r < PRECISION) return false; // too small, treated as solid fill + + auto dist = tvg::length(center, focal); + + // clamp focal point to inside end circle if outside + if (this->r - dist < PRECISION) { + auto diff = center - focal; + if (dist < PRECISION) dist = diff.x = PRECISION; + auto scale = this->r * (1.0f - PRECISION) / dist; + diff *= scale; + dist *= scale; // update effective dist after scaling + fx = center.x - diff.x; + fy = center.y - diff.y; + } else { + fx = focal.x; + fy = focal.y; + } + // ensure start circle radius fr doesn't exceed the difference + auto maxFr = (r - dist) * (1.0f - PRECISION); + fr = (this->fr > maxFr) ? std::max(0.0f, maxFr) : this->fr; + return true; + } +}; + + +struct LinearGradientImpl : LinearGradient +{ + Fill::Impl impl; + Point p1{}, p2{}; + + LinearGradientImpl() + { + Fill::pImpl = &impl; + } + + Fill* duplicate() const + { + auto ret = LinearGradient::gen(); + LINEAR(ret)->impl.copy(this->impl); + LINEAR(ret)->p1 = p1; + LINEAR(ret)->p2 = p2; + + return ret; + } + + Result linear(float x1, float y1, float x2, float y2) noexcept + { + p1 = {x1, y1}; + p2 = {x2, y2}; + + return Result::Success; + } + + Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept + { + if (x1) *x1 = p1.x; + if (x2) *x2 = p2.x; + if (y1) *y1 = p1.y; + if (y2) *y2 = p2.y; + + return Result::Success; + } +}; + + +#endif //_TVG_FILL_H_ diff --git a/components/thorvg-main/src/renderer/tvgFrameModule.h b/components/thorvg-main/src/renderer/tvgFrameModule.h new file mode 100644 index 0000000..b2acfe1 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgFrameModule.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_FRAME_MODULE_H_ +#define _TVG_FRAME_MODULE_H_ + +#include "tvgLoadModule.h" + +namespace tvg +{ + +class FrameModule: public ImageLoader +{ +public: + float segmentBegin = 0.0f; + float segmentEnd; //Initialize the value with the total frame number + + FrameModule(FileType type) : ImageLoader(type) {} + virtual ~FrameModule() {} + + virtual bool frame(float no) = 0; //set the current frame number + virtual float totalFrame() = 0; //return the total frame count + virtual float curFrame() = 0; //return the current frame number + virtual float duration() = 0; //return the animation duration in seconds + virtual Result segment(float begin, float end) = 0; + + void segment(float* begin, float* end) + { + if (begin) *begin = segmentBegin; + if (end) *end = segmentEnd; + } + + virtual bool animatable() override { return true; } +}; + +} + +#endif //_TVG_FRAME_MODULE_H_ diff --git a/components/thorvg-main/src/renderer/tvgInitializer.cpp b/components/thorvg-main/src/renderer/tvgInitializer.cpp new file mode 100644 index 0000000..a719113 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgInitializer.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgCommon.h" +#include "tvgTaskScheduler.h" +#include "tvgLoader.h" + +#ifdef THORVG_SW_RASTER_SUPPORT + #include "tvgSwRenderer.h" +#endif + +#ifdef THORVG_GL_RASTER_SUPPORT + #include "tvgGlRenderer.h" +#endif + +#ifdef THORVG_WG_RASTER_SUPPORT + #include "tvgWgRenderer.h" +#endif + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +namespace tvg { + int engineInit = 0; +} + +static uint16_t _version = 0; + + +static bool _buildVersionInfo(uint32_t* major, uint32_t* minor, uint32_t* micro) +{ + auto VER = THORVG_VERSION_STRING; + auto p = VER; + const char* x; + + if (!(x = strchr(p, '.'))) return false; + uint32_t majorVal = atoi(p); + p = x + 1; + + if (!(x = strchr(p, '.'))) return false; + uint32_t minorVal = atoi(p); + p = x + 1; + + uint32_t microVal = atoi(p); + + char sum[7]; + snprintf(sum, sizeof(sum), "%d%02d%02d", majorVal, minorVal, microVal); + _version = atoi(sum); + + if (major) *major = majorVal; + if (minor) *minor = minorVal; + if (micro) *micro = microVal; + + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +Result Initializer::init(uint32_t threads) noexcept +{ + if (engineInit++ > 0) return Result::Success; + + if (!_buildVersionInfo(nullptr, nullptr, nullptr)) return Result::Unknown; + + if (!LoaderMgr::init()) return Result::Unknown; + + TaskScheduler::init(threads); + + return Result::Success; +} + + +Result Initializer::term() noexcept +{ + if (engineInit == 0) return Result::InsufficientCondition; + + if (--engineInit > 0) return Result::Success; + + #ifdef THORVG_SW_RASTER_SUPPORT + if (!SwRenderer::term()) return Result::InsufficientCondition; + #endif + + #ifdef THORVG_GL_RASTER_SUPPORT + if (!GlRenderer::term()) return Result::InsufficientCondition; + #endif + + #ifdef THORVG_WG_RASTER_SUPPORT + if (!WgRenderer::term()) return Result::InsufficientCondition; + #endif + + TaskScheduler::term(); + + if (!LoaderMgr::term()) return Result::Unknown; + + return Result::Success; +} + + +const char* Initializer::version(uint32_t* major, uint32_t* minor, uint32_t* micro) noexcept +{ + if ((!major && ! minor && !micro) || _buildVersionInfo(major, minor, micro)) return THORVG_VERSION_STRING; + return nullptr; +} + + +uint16_t THORVG_VERSION_NUMBER() +{ + return _version; +} + + +void* operator new(std::size_t size) { + return tvg::malloc(size); +} + + +void operator delete(void* ptr) noexcept { + tvg::free(ptr); +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgIteratorAccessor.h b/components/thorvg-main/src/renderer/tvgIteratorAccessor.h new file mode 100644 index 0000000..01b4fa9 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgIteratorAccessor.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_ITERATOR_ACCESSOR_H_ +#define _TVG_ITERATOR_ACCESSOR_H_ + +#include "tvgPaint.h" + +namespace tvg +{ + +class IteratorAccessor +{ +public: + //Utility Method: Iterator Accessor + static Iterator* iterator(const Paint* paint) + { + return PAINT(paint)->iterator(); + } +}; + +} + +#endif //_TVG_ITERATOR_ACCESSOR_H_ diff --git a/components/thorvg-main/src/renderer/tvgLoadModule.h b/components/thorvg-main/src/renderer/tvgLoadModule.h new file mode 100644 index 0000000..17817d6 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgLoadModule.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOAD_MODULE_H_ +#define _TVG_LOAD_MODULE_H_ + +#include +#include "tvgCommon.h" +#include "tvgRender.h" +#include "tvgInlist.h" + + +struct AssetResolver +{ + std::function func; + void* data; +}; + + +namespace tvg +{ + +struct LoadModule +{ + INLIST_ITEM(LoadModule); + + //Use either hashkey(data) or hashpath(path) + uintptr_t hashkey = 0; + char* hashpath = nullptr; + + FileType type; //current loader file type + atomic sharing{}; //reference count + bool readied = false; //read done already. + bool cached = false; //cached for sharing + + LoadModule(FileType type) : type(type) {} + virtual ~LoadModule() + { + tvg::free(hashpath); + } + + void cache(uintptr_t data) + { + hashkey = data; + cached = true; + } + + void cache(char* data) + { + hashpath = data; + cached = true; + } + + virtual bool open(const char* path) { return false; } + virtual bool open(const char* data, uint32_t size, const char* rpath, bool copy) { return false; } + virtual bool resize(Paint* paint, float w, float h) { return false; } + virtual void sync() {}; //finish immediately if any async update jobs. + + virtual bool read() + { + if (readied) return false; + readied = true; + return true; + } + + virtual bool close() + { + if (sharing == 0) return true; + --sharing; + return false; + } + + char* open(const char* path, uint32_t& size, bool text = false) + { +#ifdef THORVG_FILE_IO_SUPPORT + auto f = fopen(path, text ? "r" : "rb"); + if (!f) return nullptr; + + fseek(f, 0, SEEK_END); + + size = ftell(f); + if (size == 0) { + fclose(f); + return nullptr; + } + + auto content = tvg::malloc(sizeof(char) * (text ? size + 1 : size)); + fseek(f, 0, SEEK_SET); + size = fread(content, sizeof(char), size, f); + if (text) content[size] = '\0'; + + fclose(f); + + return content; +#endif + return nullptr; + } +}; + + +struct ImageLoader : LoadModule +{ + static atomic cs; //desired value + + float w = 0, h = 0; //default image size + RenderSurface surface; + + ImageLoader(FileType type) : LoadModule(type) {} + + virtual bool animatable() { return false; } //true if this loader supports animation. + virtual Paint* paint() { return nullptr; } + virtual void set(const AssetResolver* resolver) {} + + virtual RenderSurface* bitmap() + { + if (surface.data) return &surface; + return nullptr; + } +}; + + +struct FontMetrics +{ + Point size; //text width, height + float scale; + Point align{}, box{}, spacing{1.0f, 1.0f}; + float fontSize = 0.0f; + TextWrap wrap = TextWrap::None; + + void *engine = nullptr; //engine extension + + ~FontMetrics() + { + tvg::free(engine); + } +}; + + +struct FontLoader : LoadModule +{ + char* name = nullptr; + + FontLoader(FileType type) : LoadModule(type) {} + + using LoadModule::read; + + virtual bool get(FontMetrics& fm, char* text, RenderPath& out) = 0; + virtual void transform(Paint* paint, FontMetrics& fm, float italicShear) = 0; + virtual void release(FontMetrics& fm) = 0; + virtual void copy(const FontMetrics& in, FontMetrics& out) = 0; +}; + +} + +#endif //_TVG_LOAD_MODULE_H_ diff --git a/components/thorvg-main/src/renderer/tvgLoader.cpp b/components/thorvg-main/src/renderer/tvgLoader.cpp new file mode 100644 index 0000000..537990c --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgLoader.cpp @@ -0,0 +1,453 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgInlist.h" +#include "tvgStr.h" +#include "tvgLoader.h" +#include "tvgLock.h" + +#ifdef THORVG_SVG_LOADER_SUPPORT + #include "tvgSvgLoader.h" +#endif + +#ifdef THORVG_PNG_LOADER_SUPPORT + #include "tvgPngLoader.h" +#endif + +#ifdef THORVG_JPG_LOADER_SUPPORT + #include "tvgJpgLoader.h" +#endif + +#ifdef THORVG_WEBP_LOADER_SUPPORT + #include "tvgWebpLoader.h" +#endif + +#ifdef THORVG_TTF_LOADER_SUPPORT + #include "tvgTtfLoader.h" +#endif + +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + #include "tvgLottieLoader.h" +#endif + +#include "tvgRawLoader.h" + + +uintptr_t HASH_KEY(const char* data) +{ + return reinterpret_cast(data); +} + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +//TODO: remove it. +atomic ImageLoader::cs{ColorSpace::ARGB8888}; + +static Key _key; +static Inlist _activeLoaders; + + +static tvg::LoadModule* _find(FileType type) +{ + switch(type) { + case FileType::Png: { +#ifdef THORVG_PNG_LOADER_SUPPORT + return new PngLoader; +#endif + break; + } + case FileType::Jpg: { +#ifdef THORVG_JPG_LOADER_SUPPORT + return new JpgLoader; +#endif + break; + } + case FileType::Webp: { +#ifdef THORVG_WEBP_LOADER_SUPPORT + return new WebpLoader; +#endif + break; + } + case FileType::Svg: { +#ifdef THORVG_SVG_LOADER_SUPPORT + return new SvgLoader; +#endif + break; + } + case FileType::Ttf: { +#ifdef THORVG_TTF_LOADER_SUPPORT + return new TtfLoader; +#endif + break; + } + case FileType::Lot: { +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + return new LottieLoader; +#endif + break; + } + case FileType::Raw: { + return new RawLoader; + break; + } + default: { + break; + } + } + +#ifdef THORVG_LOG_ENABLED + const char *format; + switch(type) { + case FileType::Svg: { + format = "SVG"; + break; + } + case FileType::Ttf: { + format = "TTF"; + break; + } + case FileType::Lot: { + format = "LOT"; + break; + } + case FileType::Raw: { + format = "RAW"; + break; + } + case FileType::Png: { + format = "PNG"; + break; + } + case FileType::Jpg: { + format = "JPG"; + break; + } + case FileType::Webp: { + format = "WEBP"; + break; + } + default: { + format = "???"; + break; + } + } + TVGLOG("RENDERER", "%s format is not supported", format); +#endif + return nullptr; +} + + +#ifdef THORVG_FILE_IO_SUPPORT +static tvg::LoadModule* _findByPath(const char* filename) +{ + auto ext = fileext(filename); + if (!ext) return nullptr; + + if (!strcmp(ext, "svg")) return _find(FileType::Svg); + if (!strcmp(ext, "lot") || !strcmp(ext, "json")) return _find(FileType::Lot); + if (!strcmp(ext, "png")) return _find(FileType::Png); + if (!strcmp(ext, "jpg")) return _find(FileType::Jpg); + if (!strcmp(ext, "webp")) return _find(FileType::Webp); + if (!strcmp(ext, "ttf") || !strcmp(ext, "ttc")) return _find(FileType::Ttf); + if (!strcmp(ext, "otf") || !strcmp(ext, "otc")) return _find(FileType::Ttf); + return nullptr; +} +#endif + + +static FileType _convert(const char* mimeType) +{ + if (!mimeType) return FileType::Unknown; + + auto type = FileType::Unknown; + + if (!strcmp(mimeType, "svg") || !strcmp(mimeType, "svg+xml")) type = FileType::Svg; + else if (!strcmp(mimeType, "ttf") || !strcmp(mimeType, "otf")) type = FileType::Ttf; + else if (!strcmp(mimeType, "lot") || !strcmp(mimeType, "lottie+json")) type = FileType::Lot; + else if (!strcmp(mimeType, "raw")) type = FileType::Raw; + else if (!strcmp(mimeType, "png")) type = FileType::Png; + else if (!strcmp(mimeType, "jpg") || !strcmp(mimeType, "jpeg")) type = FileType::Jpg; + else if (!strcmp(mimeType, "webp")) type = FileType::Webp; + else TVGLOG("RENDERER", "Given mimetype is unknown = \"%s\".", mimeType); + + return type; +} + + +static tvg::LoadModule* _findByType(const char* mimeType) +{ + return _find(_convert(mimeType)); +} + + +static tvg::LoadModule* _findFromCache(const char* filename) +{ + ScopedLock lock(_key); + INLIST_FOREACH(_activeLoaders, loader) { + if (loader->cached && loader->hashpath && !strcmp(loader->hashpath, filename)) { + ++loader->sharing; + return loader; + } + } + return nullptr; +} + + +static tvg::LoadModule* _findFromCache(const char* data, uint32_t size, const char* mimeType) +{ + auto type = _convert(mimeType); + if (type == FileType::Unknown) return nullptr; + + auto key = HASH_KEY(data); + + ScopedLock lock(_key); + + INLIST_FOREACH(_activeLoaders, loader) { + if (loader->type == type && loader->hashkey == key) { + ++loader->sharing; + return loader; + } + } + return nullptr; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +bool LoaderMgr::init() +{ + return true; +} + + +bool LoaderMgr::term() +{ + //clean up the remained font loaders which is globally used. + INLIST_SAFE_FOREACH(_activeLoaders, loader) { + if (loader->type != FileType::Ttf) continue; + auto ret = loader->close(); + _activeLoaders.remove(loader); + if (ret) delete(loader); + } + return true; +} + + +bool LoaderMgr::retrieve(LoadModule* loader) +{ + if (!loader) return false; + + if (loader->close()) { + if (loader->cached) { + _activeLoaders.remove(loader); + } + delete(loader); + } + return true; +} + + +tvg::LoadModule* LoaderMgr::loader(const char* filename, bool* invalid) +{ +#ifdef THORVG_FILE_IO_SUPPORT + *invalid = false; + + //TODO: make lottie sharable. + auto allowCache = true; + auto ext = fileext(filename); + if (ext && (!strcmp(ext, "json") || !strcmp(ext, "lot"))) allowCache = false; + + if (allowCache) { + if (auto loader = _findFromCache(filename)) return loader; + } + + if (auto loader = _findByPath(filename)) { + if (loader->open(filename)) { + if (allowCache) { + loader->cache(duplicate(filename)); + { + ScopedLock lock(_key); + _activeLoaders.back(loader); + } + } + return loader; + } + delete(loader); + } + //Unknown MimeType. Try with the candidates in the order + for (int i = 0; i < static_cast(FileType::Raw); i++) { + if (auto loader = _find(static_cast(i))) { + if (loader->open(filename)) { + if (allowCache) { + loader->cache(duplicate(filename)); + { + ScopedLock lock(_key); + _activeLoaders.back(loader); + } + } + return loader; + } + delete(loader); + } + } + *invalid = true; +#endif + return nullptr; +} + + +bool LoaderMgr::retrieve(const char* filename) +{ + return retrieve(_findFromCache(filename)); +} + + +tvg::LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const char* mimeType, const char* rpath, bool copy) +{ + //Note that users could use the same data pointer with the different content. + //Thus caching is only valid for shareable. + auto allowCache = !copy; + + //TODO: make lottie shareable. + if (allowCache) { + auto type = _convert(mimeType); + if (type == FileType::Lot) allowCache = false; + } + + if (allowCache) { + if (auto loader = _findFromCache(data, size, mimeType)) return loader; + } + + //Try with the given MimeType + if (mimeType) { + if (auto loader = _findByType(mimeType)) { + if (loader->open(data, size, rpath, copy)) { + if (allowCache) { + loader->cache(HASH_KEY(data)); + ScopedLock lock(_key); + _activeLoaders.back(loader); + } + return loader; + } else { + TVGLOG("LOADER", "Given mimetype \"%s\" seems incorrect or not supported.", mimeType); + delete(loader); + } + } + } + //Unknown MimeType. Try with the candidates in the order + for (int i = 0; i < static_cast(FileType::Raw); i++) { + auto loader = _find(static_cast(i)); + if (loader) { + if (loader->open(data, size, rpath, copy)) { + if (allowCache) { + loader->cache(HASH_KEY(data)); + ScopedLock lock(_key); + _activeLoaders.back(loader); + } + return loader; + } + delete(loader); + } + } + return nullptr; +} + + +tvg::LoadModule* LoaderMgr::loader(const uint32_t *data, uint32_t w, uint32_t h, ColorSpace cs, bool copy) +{ + //Note that users could use the same data pointer with the different content. + //Thus caching is only valid for shareable. + if (!copy) { + //TODO: should we check premultiplied?? + if (auto loader = _findFromCache((const char*)(data), w * h, "raw")) return loader; + } + + //function is dedicated for raw images only + auto loader = new RawLoader; + if (loader->open(data, w, h, cs, copy)) { + if (!copy) { + loader->cache(HASH_KEY((const char*)data)); + ScopedLock lock(_key); + _activeLoaders.back(loader); + } + return loader; + } + delete(loader); + return nullptr; +} + + +//loads fonts from memory - loader is cached (regardless of copy value) in order to access it while setting font +tvg::LoadModule* LoaderMgr::loader(const char* name, const char* data, uint32_t size, TVG_UNUSED const char* mimeType, bool copy) +{ +#ifdef THORVG_TTF_LOADER_SUPPORT + //TODO: add check for mimetype ? + if (auto loader = font(name)) return loader; + + //function is dedicated for ttf loader (the only supported font loader) + auto loader = new TtfLoader; + if (loader->open(data, size, "", copy)) { + loader->name = duplicate(name); + loader->cached = true; //force it. + ScopedLock lock(_key); + _activeLoaders.back(loader); + return loader; + } + + TVGLOG("LOADER", "The font data \"%s\" could not be loaded.", name); + delete(loader); +#endif + return nullptr; +} + + +tvg::LoadModule* LoaderMgr::font(const char* name) +{ + ScopedLock lock(_key); + INLIST_FOREACH(_activeLoaders, loader) { + if (loader->type != FileType::Ttf) continue; + if (loader->cached && tvg::equal(name, static_cast(loader)->name)) { + ++loader->sharing; + return loader; + } + } + return nullptr; +} + + +tvg::LoadModule* LoaderMgr::anyfont() +{ + ScopedLock lock(_key); + INLIST_FOREACH(_activeLoaders, loader) { + if (loader->cached && loader->type == FileType::Ttf) { + ++loader->sharing; + return loader; + } + } + return nullptr; +} diff --git a/components/thorvg-main/src/renderer/tvgLoader.h b/components/thorvg-main/src/renderer/tvgLoader.h new file mode 100644 index 0000000..5b345e2 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgLoader.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_LOADER_H_ +#define _TVG_LOADER_H_ + +#include "tvgLoadModule.h" + +namespace tvg +{ + +struct LoaderMgr +{ + static bool init(); + static bool term(); + static LoadModule* loader(const char* filename, bool* invalid); + static LoadModule* loader(const char* data, uint32_t size, const char* mimeType, const char* rpath, bool copy); + static LoadModule* loader(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy); + static LoadModule* loader(const char* name, const char* data, uint32_t size, const char* mimeType, bool copy); + static LoadModule* font(const char* name); + static LoadModule* anyfont(); + static bool retrieve(const char* filename); + static bool retrieve(LoadModule* loader); +}; + +} + +#endif //_TVG_LOADER_H_ diff --git a/components/thorvg-main/src/renderer/tvgPaint.cpp b/components/thorvg-main/src/renderer/tvgPaint.cpp new file mode 100644 index 0000000..50e990b --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgPaint.cpp @@ -0,0 +1,471 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgPaint.h" +#include "tvgShape.h" +#include "tvgPicture.h" +#include "tvgScene.h" +#include "tvgText.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +#define PAINT_METHOD(ret, METHOD) \ + switch (paint->type()) { \ + case Type::Shape: ret = to(paint)->METHOD; break; \ + case Type::Scene: ret = to(paint)->METHOD; break; \ + case Type::Picture: ret = to(paint)->METHOD; break; \ + case Type::Text: ret = to(paint)->METHOD; break; \ + default: ret = {}; \ + } + + +static bool _clipRect(RenderMethod* renderer, const Point* pts, const Matrix& m, RenderRegion& before) +{ + Point c[4]; //corners + for (int i = 0; i < 4; ++i) { + c[i] = pts[i] * m; + } + + //figure out if the clipper is a superset of the current viewport(before) region + auto pointInConvexQuad = [](const Point& p, const Point* quad) { + auto sign = [](const Point& p1, const Point& p2, const Point& p3) { + return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y); + }; + auto b1 = sign(p, quad[0], quad[1]) < 0.0f; + auto b2 = sign(p, quad[1], quad[2]) < 0.0f; + auto b3 = sign(p, quad[2], quad[3]) < 0.0f; + auto b4 = sign(p, quad[3], quad[0]) < 0.0f; + return ((b1 == b2) && (b2 == b3) && (b3 == b4)); + }; + + if (!pointInConvexQuad({float(before.min.x), float(before.min.y)}, c)) return false; + if (!pointInConvexQuad({float(before.max.x), float(before.min.y)}, c)) return false; + if (!pointInConvexQuad({float(before.max.x), float(before.max.y)}, c)) return false; + if (!pointInConvexQuad({float(before.min.x), float(before.max.y)}, c)) return false; + + //same viewport + return true; +} + + +static bool _compFastTrack(RenderMethod* renderer, Paint* cmpTarget, const Matrix& pm, RenderRegion& before) +{ + /* Access Shape class by Paint is bad... but it's ok still it's an internal usage. */ + auto shape = static_cast(cmpTarget); + + //Trimming likely makes the shape non-rectangular + if (to(shape)->rs.trimpath()) return false; + + //Rectangle Candidates? + const Point* pts; + uint32_t ptsCnt; + shape->path(nullptr, nullptr, &pts, &ptsCnt); + + //No rectangle format + if (ptsCnt != 4) return false; + + //No rotation and no skewing, still can try out clipping the rect region. + auto tm = pm * cmpTarget->transform(); + + //Perpendicular Rectangle? + if (rightAngle(tm) && !skewed(tm)) { + auto pt1 = pts + 0; + auto pt2 = pts + 1; + auto pt3 = pts + 2; + auto pt4 = pts + 3; + + if ((tvg::equal(pt1->x, pt2->x) && tvg::equal(pt2->y, pt3->y) && tvg::equal(pt3->x, pt4->x) && tvg::equal(pt1->y, pt4->y)) || + (tvg::equal(pt2->x, pt3->x) && tvg::equal(pt1->y, pt2->y) && tvg::equal(pt1->x, pt4->x) && tvg::equal(pt3->y, pt4->y))) { + + RenderRegion after; + + auto v1 = *pt1; + auto v2 = *pt3; + v1 *= tm; + v2 *= tm; + + //sorting + if (v1.x > v2.x) std::swap(v1.x, v2.x); + if (v1.y > v2.y) std::swap(v1.y, v2.y); + + after.min.x = static_cast(nearbyint(v1.x)); + after.min.y = static_cast(nearbyint(v1.y)); + after.max.x = static_cast(nearbyint(v2.x)); + after.max.y = static_cast(nearbyint(v2.y)); + + if (after.max.x < after.min.x) after.max.x = after.min.x; + if (after.max.y < after.min.y) after.max.y = after.min.y; + + after.intersect(before); + renderer->viewport(after); + return true; + } + } + return _clipRect(renderer, pts, tm, before); +} + + +RenderRegion Paint::Impl::bounds() +{ + RenderRegion ret; + PAINT_METHOD(ret, bounds()); + return ret; +} + + +Iterator* Paint::Impl::iterator() +{ + Iterator* ret; + PAINT_METHOD(ret, iterator()); + return ret; +} + + +Paint* Paint::Impl::duplicate(Paint* ret) +{ + if (ret) ret->mask(nullptr, MaskMethod::None); + + PAINT_METHOD(ret, duplicate(ret)); + + if (maskData) ret->mask(maskData->target->duplicate(), maskData->method); + if (clipper) ret->clip(static_cast(clipper->duplicate())); + + ret->pImpl->tr = tr; + ret->pImpl->blendMethod = blendMethod; + ret->pImpl->opacity = opacity; + ret->pImpl->hidden = hidden; + ret->pImpl->mark(RenderUpdateFlag::All); + + return ret; +} + + +bool Paint::Impl::render(RenderMethod* renderer) +{ + if (hidden || opacity == 0) return true; + + RenderCompositor* cmp = nullptr; + + //OPTIMIZE: bounds(renderer) calls could dismiss the parallelization + if (maskData && !(maskData->target->pImpl->ctxFlag & ContextFlag::FastTrack)) { + RenderRegion region; + PAINT_METHOD(region, bounds()); + + auto mData = maskData; + while (mData) { + if (MASK_REGION_MERGING(mData->method)) region.add(PAINT(mData->target)->bounds()); + if (region.invalid()) return true; + mData = PAINT(mData->target)->maskData; + } + cmp = renderer->target(region, MASK_TO_COLORSPACE(renderer, maskData->method), CompositionFlag::Masking); + if (renderer->beginComposite(cmp, MaskMethod::None, 255)) { + maskData->target->pImpl->render(renderer); + } + } + + if (cmp) renderer->beginComposite(cmp, maskData->method, maskData->target->pImpl->opacity); + + bool ret; + PAINT_METHOD(ret, render(renderer)); + + if (cmp) renderer->endComposite(cmp); + + return ret; +} + + +RenderData Paint::Impl::update(RenderMethod* renderer, const Matrix& pm, Array& clips, uint8_t opacity, RenderUpdateFlag flag, bool clipper) +{ + bool ret; + PAINT_METHOD(ret, skip((flag | renderFlag))); + + if (ret) return rd; + + cmpFlag = CompositionFlag::Invalid; //must clear after the rendering + + if (this->renderer != renderer) { + if (this->renderer) TVGERR("RENDERER", "paint's renderer has been changed!"); + renderer->ref(); + this->renderer = renderer; + } + + if (renderFlag & RenderUpdateFlag::Transform) tr.update(); + + /* 1. Composition Pre Processing */ + RenderData trd = nullptr; //composite target render data + RenderRegion viewport; + auto compFastTrack = false; + + if (maskData) { + auto target = maskData->target; + auto method = maskData->method; + PAINT(target)->ctxFlag &= ~ContextFlag::FastTrack; //reset + + /* If the transformation has no rotational factors and the Alpha(InvAlpha) Masking involves a simple rectangle, + we can optimize by using the viewport instead of the regular Alphaing sequence for improved performance. */ + if (target->type() == Type::Shape) { + auto shape = static_cast(target); + uint8_t a; + shape->fill(nullptr, nullptr, nullptr, &a); + //no gradient fill & no maskings of the masking target. + if (!shape->fill() && !(PAINT(shape)->maskData)) { + if ((method == MaskMethod::Alpha && a == 255 && PAINT(shape)->opacity == 255) || (method == MaskMethod::InvAlpha && (a == 0 || PAINT(shape)->opacity == 0))) { + viewport = renderer->viewport(); + if ((compFastTrack = _compFastTrack(renderer, target, pm, viewport))) { + PAINT(target)->ctxFlag |= ContextFlag::FastTrack; + } + } + } + } + if (!compFastTrack) { + trd = PAINT(target)->update(renderer, pm, clips, 255, flag, false); + } + } + + /* 2. Clipping */ + if (this->clipper) { + auto pclip = PAINT(this->clipper); + pclip->ctxFlag &= ~ContextFlag::FastTrack; //reset + viewport = renderer->viewport(); + if (!pclip->clipper && to(this->clipper)->rs.strokeWidth() == 0.0f && _compFastTrack(renderer, this->clipper, pm, viewport)) { + pclip->ctxFlag |= ContextFlag::FastTrack; + compFastTrack = true; + } else { + mark(RenderUpdateFlag::Clip); + trd = pclip->update(renderer, pm, clips, 255, flag, true); + clips.push(trd); + } + } + + /* 3. Main Update */ + opacity = MULTIPLY(opacity, this->opacity); + PAINT_METHOD(ret, update(renderer, pm * tr.m, clips, opacity, (flag | renderFlag), clipper)); + + /* 4. Composition Post Processing */ + if (compFastTrack) renderer->viewport(viewport); + else if (this->clipper) clips.pop(); + + renderFlag = RenderUpdateFlag::None; + + return rd; +} + + +bool Paint::Impl::bounds(Point* pt4, const Matrix* pm, bool obb) +{ + bool ret; + PAINT_METHOD(ret, bounds(pt4, pm * transform(), obb)); + return ret; +} + + +bool Paint::Impl::intersects(const RenderRegion& region) +{ + if (renderer) { + bool ret; + PAINT_METHOD(ret, intersects(region)); + return ret; + } + return false; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +Paint :: Paint() = default; +Paint :: ~Paint() = default; + + +void Paint::rel(Paint* paint) noexcept +{ + if (paint && paint->refCnt() <= 0) delete(paint); +} + + +Result Paint::rotate(float degree) noexcept +{ + if (pImpl->rotate(degree)) return Result::Success; + return Result::InsufficientCondition; +} + + +Result Paint::scale(float factor) noexcept +{ + if (pImpl->scale(factor)) return Result::Success; + return Result::InsufficientCondition; +} + + +Result Paint::translate(float x, float y) noexcept +{ + if (pImpl->translate(x, y)) return Result::Success; + return Result::InsufficientCondition; +} + + +Result Paint::transform(const Matrix& m) noexcept +{ + if (pImpl->transform(m)) return Result::Success; + return Result::InsufficientCondition; +} + + +Matrix& Paint::transform() noexcept +{ + return pImpl->transform(); +} + + +Result Paint::bounds(float* x, float* y, float* w, float* h) noexcept +{ + Point pt4[4] = {}; + const auto pm = pImpl->ptransform(); + if (pImpl->bounds(pt4, &pm, false)) { + BBox box = {{FLT_MAX, FLT_MAX}, {-FLT_MAX, -FLT_MAX}}; + for (int i = 0; i < 4; ++i) { + if (pt4[i].x < box.min.x) box.min.x = pt4[i].x; + if (pt4[i].x > box.max.x) box.max.x = pt4[i].x; + if (pt4[i].y < box.min.y) box.min.y = pt4[i].y; + if (pt4[i].y > box.max.y) box.max.y = pt4[i].y; + } + if (x) *x = box.min.x; + if (y) *y = box.min.y; + if (w) *w = box.max.x - box.min.x; + if (h) *h = box.max.y - box.min.y; + return Result::Success; + } + return Result::InsufficientCondition; +} + + +Result Paint::bounds(Point* pt4) noexcept +{ + if (!pt4) return Result::InvalidArguments; + auto pm = pImpl->ptransform(); + if (pImpl->bounds(pt4, &pm, true)) return Result::Success; + return Result::InsufficientCondition; +} + + +bool Paint::intersects(int32_t x, int32_t y, int32_t w, int32_t h) noexcept +{ + if (w <= 0 || h <= 0) return false; + return pImpl->intersects({{x, y}, {x + w, y + h}}); +} + + +Paint* Paint::duplicate() const noexcept +{ + return pImpl->duplicate(); +} + + +Result Paint::clip(Shape* clipper) noexcept +{ + return pImpl->clip(clipper); +} + + +Shape* Paint::clip() const noexcept +{ + return pImpl->clipper; +} + + +Result Paint::mask(Paint* target, MaskMethod method) noexcept +{ + if (method > MaskMethod::Darken) return Result::InvalidArguments; + return pImpl->mask(target, method); +} + + +MaskMethod Paint::mask(const Paint** target) const noexcept +{ + return pImpl->mask(target); +} + + +Result Paint::opacity(uint8_t o) noexcept +{ + if (pImpl->opacity != o) { + pImpl->opacity = o; + pImpl->mark(RenderUpdateFlag::Color); + } + return Result::Success; +} + + +uint8_t Paint::opacity() const noexcept +{ + return pImpl->opacity; +} + + +Result Paint::blend(BlendMethod method) noexcept +{ + if (method <= BlendMethod::Add || method == BlendMethod::Composition) { + pImpl->blend(method); + return Result::Success; + } + return Result::InvalidArguments; +} + + +uint16_t Paint::ref() noexcept +{ + return pImpl->ref(); +} + + +uint16_t Paint::unref(bool free) noexcept +{ + return pImpl->unrefx(free); +} + + +uint16_t Paint::refCnt() const noexcept +{ + return pImpl->refCnt; +} + + +const Paint* Paint::parent() const noexcept +{ + return pImpl->parent; +} + + +Result Paint::visible(bool on) noexcept +{ + return pImpl->visible(!on); +} + + +bool Paint::visible() const noexcept +{ + return !pImpl->hidden; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgPaint.h b/components/thorvg-main/src/renderer/tvgPaint.h new file mode 100644 index 0000000..95611c0 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgPaint.h @@ -0,0 +1,320 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_PAINT_H_ +#define _TVG_PAINT_H_ + +#include "tvgCommon.h" +#include "tvgRender.h" +#include "tvgMath.h" + + +#define PAINT(A) ((Paint::Impl*)A->pImpl) + +namespace tvg +{ +enum ContextFlag : uint8_t {Default = 0, FastTrack = 1}; + +struct Iterator +{ + virtual ~Iterator() {} + virtual const Paint* next() = 0; + virtual uint32_t count() = 0; + virtual void begin() = 0; +}; + +struct Mask +{ + Paint* target; + Paint* source; + MaskMethod method; +}; + +struct Paint::Impl +{ + Paint* paint = nullptr; + Paint* parent = nullptr; + Mask* maskData = nullptr; + Shape* clipper = nullptr; + RenderMethod* renderer = nullptr; + RenderData rd = nullptr; + + struct { + Matrix m; //input matrix + float degree; //rotation degree + float scale; //scale factor + bool overriding; //user transform? + + void update() + { + if (overriding) return; + m.e11 = 1.0f; + m.e12 = 0.0f; + m.e21 = 0.0f; + m.e22 = 1.0f; + m.e31 = 0.0f; + m.e32 = 0.0f; + m.e33 = 1.0f; + tvg::scale(&m, {scale, scale}); + tvg::rotate(&m, degree); + } + } tr; + RenderUpdateFlag renderFlag = RenderUpdateFlag::None; + CompositionFlag cmpFlag = CompositionFlag::Invalid; + BlendMethod blendMethod; + uint16_t refCnt = 0; //reference count + uint8_t ctxFlag; //See enum ContextFlag + uint8_t opacity; + bool hidden : 1; + + Impl(Paint* pnt) : paint(pnt) + { + pnt->pImpl = this; + hidden = false; + reset(); + } + + virtual ~Impl() + { + if (maskData) { + PAINT(maskData->target)->unref(); + tvg::free(maskData); + } + + if (clipper) PAINT(clipper)->unref(); + + if (renderer) { + if (rd) renderer->dispose(rd); + if (renderer->unref() == 0) delete(renderer); + } + } + + uint16_t ref() + { + return ++refCnt; + } + + uint16_t unref(bool free = true) + { + parent = nullptr; + return unrefx(free); + } + + uint16_t unrefx(bool free) + { + if (refCnt > 0) --refCnt; + + if (free && refCnt == 0) { + delete(paint); + return 0; + } + + return refCnt; + } + + void damage(const RenderRegion& vport) + { + if (renderer) renderer->damage(rd, vport); + } + + void damage() + { + if (renderer) renderer->damage(rd, bounds()); + } + + void mark(CompositionFlag flag) + { + cmpFlag = CompositionFlag(uint8_t(cmpFlag) | uint8_t(flag)); + } + + bool marked(CompositionFlag flag) + { + return (uint8_t(cmpFlag) & uint8_t(flag)) ? true : false; + } + + bool marked(RenderUpdateFlag flag) + { + return (renderFlag & flag) ? true : false; + } + + void mark(RenderUpdateFlag flag) + { + renderFlag |= flag; + } + + bool transform(const Matrix& m) + { + if (&tr.m != &m) tr.m = m; + tr.overriding = true; + mark(RenderUpdateFlag::Transform); + + return true; + } + + Matrix& transform() + { + //update transform + if (renderFlag & RenderUpdateFlag::Transform) tr.update(); + return tr.m; + } + + Matrix ptransform() + { + auto p = this; + auto tm = tvg::identity(); + while (p->parent) { + p = PAINT(p->parent); + tm = p->transform() * tm; + } + return tm; + } + + Result clip(Shape* clp) + { + if (clp && PAINT(clp)->parent) return Result::InsufficientCondition; + if (clipper) PAINT(clipper)->unref(clipper != clp); + clipper = clp; + if (clp) { + clp->ref(); + PAINT(clp)->parent = parent; + } + return Result::Success; + } + + Result mask(Paint* target, MaskMethod method) + { + if (target && PAINT(target)->parent) return Result::InsufficientCondition; + + if (maskData) { + PAINT(maskData->target)->unref(maskData->target != target); + tvg::free(maskData); + maskData = nullptr; + } + + if (method == MaskMethod::None) return (target ? Result::InvalidArguments : Result::Success); + + maskData = tvg::malloc(sizeof(Mask)); + target->ref(); + maskData->target = target; + PAINT(target)->parent = parent; + maskData->source = paint; + maskData->method = method; + return Result::Success; + } + + MaskMethod mask(const Paint** target) const + { + if (maskData) { + if (target) *target = maskData->target; + return maskData->method; + } else { + if (target) *target = nullptr; + return MaskMethod::None; + } + } + + void reset() + { + if (clipper) { + PAINT(clipper)->unref(); + clipper = nullptr; + } + + if (maskData) { + PAINT(maskData->target)->unref(); + tvg::free(maskData); + maskData = nullptr; + } + + tvg::identity(&tr.m); + tr.degree = 0.0f; + tr.scale = 1.0f; + tr.overriding = false; + + parent = nullptr; + blendMethod = BlendMethod::Normal; + renderFlag = RenderUpdateFlag::None; + ctxFlag = ContextFlag::Default; + opacity = 255; + paint->id = 0; + } + + bool rotate(float degree) + { + if (tr.overriding) return false; + if (tvg::equal(degree, tr.degree)) return true; + tr.degree = degree; + mark(RenderUpdateFlag::Transform); + + return true; + } + + bool scale(float factor) + { + if (tr.overriding) return false; + if (tvg::equal(factor, tr.scale)) return true; + tr.scale = factor; + mark(RenderUpdateFlag::Transform); + + return true; + } + + bool translate(float x, float y) + { + if (tr.overriding) return false; + if (tvg::equal(x, tr.m.e13) && tvg::equal(y, tr.m.e23)) return true; + tr.m.e13 = x; + tr.m.e23 = y; + mark(RenderUpdateFlag::Transform); + + return true; + } + + void blend(BlendMethod method) + { + if (blendMethod != method) { + blendMethod = method; + mark(RenderUpdateFlag::Blend); + } + } + + Result visible(bool hidden) + { + if (this->hidden != hidden) { + this->hidden = hidden; + damage(); + } + return Result::Success; + } + + bool intersects(const RenderRegion& region); + RenderRegion bounds(); + bool bounds(Point* pt4, const Matrix* pm, bool obb); + Iterator* iterator(); + RenderData update(RenderMethod* renderer, const Matrix& pm, Array& clips, uint8_t opacity, RenderUpdateFlag pFlag, bool clipper = false); + bool render(RenderMethod* renderer); + Paint* duplicate(Paint* ret = nullptr); +}; + +} + +#endif //_TVG_PAINT_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgPicture.cpp b/components/thorvg-main/src/renderer/tvgPicture.cpp new file mode 100644 index 0000000..e8a6c4f --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgPicture.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgPaint.h" +#include "tvgPicture.h" + +Picture::Picture() = default; + + +Picture* Picture::gen() noexcept +{ + return new PictureImpl; +} + + +Type Picture::type() const noexcept +{ + return Type::Picture; +} + + +Result Picture::load(const char* filename) noexcept +{ +#ifdef THORVG_FILE_IO_SUPPORT + if (!filename) return Result::InvalidArguments; + return to(this)->load(filename); +#else + TVGLOG("RENDERER", "FILE IO is disabled!"); + return Result::NonSupport; +#endif +} + + +Result Picture::load(const char* data, uint32_t size, const char* mimeType, const char* rpath, bool copy) noexcept +{ + return to(this)->load(data, size, mimeType, rpath, copy); +} + + +Result Picture::load(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy) noexcept +{ + return to(this)->load(data, w, h, cs, copy); +} + + +Result Picture::resolver(std::function func, void* data) noexcept +{ + return to(this)->set(func, data); +} + + +Result Picture::size(float w, float h) noexcept +{ + to(this)->size(w, h); + return Result::Success; +} + + +Result Picture::size(float* w, float* h) const noexcept +{ + return to(this)->size(w, h); +} + + +Result Picture::origin(float x, float y) noexcept +{ + to(this)->origin = {x, y}; + PAINT(this)->mark(RenderUpdateFlag::Transform); + return Result::Success; +} + + +Result Picture::origin(float* x, float* y) const noexcept +{ + if (x) *x = to(this)->origin.x; + if (y) *y = to(this)->origin.y; + return Result::Success; +} + + +const Paint* Picture::paint(uint32_t id) noexcept +{ + struct Value + { + uint32_t id; + const Paint* ret; + } value = {id, nullptr}; + + auto cb = [](const tvg::Paint* paint, void* data) -> bool + { + auto p = static_cast(data); + if (p->id == paint->id) { + p->ret = paint; + return false; + } + return true; + }; + + auto accessor = tvg::Accessor::gen(); + accessor->set(this, cb, &value); + delete(accessor); + + return value.ret; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgPicture.h b/components/thorvg-main/src/renderer/tvgPicture.h new file mode 100644 index 0000000..d2a30fc --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgPicture.h @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_PICTURE_H_ +#define _TVG_PICTURE_H_ + +#include "tvgPaint.h" +#include "tvgScene.h" +#include "tvgLoader.h" + +namespace tvg +{ + +struct PictureIterator : Iterator +{ + Paint* paint = nullptr; + Paint* ptr = nullptr; + + PictureIterator(Paint* p) : paint(p) {} + + const Paint* next() override + { + if (!ptr) ptr = paint; + else ptr = nullptr; + return ptr; + } + + uint32_t count() override + { + if (paint) return 1; + else return 0; + } + + void begin() override + { + ptr = nullptr; + } +}; + + +struct PictureImpl : Picture +{ + Paint::Impl impl; + ImageLoader* loader = nullptr; + Paint* vector = nullptr; //vector picture uses + RenderSurface* bitmap = nullptr; //bitmap picture uses + AssetResolver* resolver = nullptr; + Point origin = {}; + float w = 0, h = 0; + bool resizing = false; + + PictureImpl() : impl(Paint::Impl(this)) + { + } + + ~PictureImpl() + { + LoaderMgr::retrieve(loader); + tvg::free(resolver); + if (vector) vector->unref(); + } + + bool skip(RenderUpdateFlag flag) + { + if (flag == RenderUpdateFlag::None) return true; + return false; + } + + bool update(RenderMethod* renderer, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flag, TVG_UNUSED bool clipper) + { + load(); + + auto pivot = Point{-origin.x * float(w), -origin.y * float(h)}; + + if (bitmap) { + //Overriding Transformation by the desired image size + auto sx = w / loader->w; + auto sy = h / loader->h; + auto scale = sx < sy ? sx : sy; + auto m = transform * Matrix{scale, 0, pivot.x, 0, scale, pivot.y, 0, 0, 1}; + impl.rd = renderer->prepare(bitmap, impl.rd, m, clips, opacity, flag); + } else if (vector) { + if (resizing) { + loader->resize(vector, w, h); + resizing = false; + } + needComposition(opacity); + vector->blend(pImpl->blendMethod); //propagate blend method to nested vector scene + translateR(const_cast(&transform), pivot); + return vector->pImpl->update(renderer, transform, clips, opacity, flag, false); + } + return true; + } + + void size(float w, float h) + { + this->w = w; + this->h = h; + resizing = true; + } + + Result size(float* w, float* h) const + { + if (!loader) return Result::InsufficientCondition; + if (w) *w = this->w; + if (h) *h = this->h; + return Result::Success; + } + + bool intersects(const RenderRegion& region) + { + if (!impl.renderer) return false; + load(); + if (impl.rd) return impl.renderer->intersectsImage(impl.rd, region); + else if (vector) return to(vector)->intersects(region); + return false; + } + + bool bounds(Point* pt4, const Matrix& m, TVG_UNUSED bool obb) + { + pt4[0] = Point{0.0f, 0.0f} * m; + pt4[1] = Point{w, 0.0f} * m; + pt4[2] = Point{w, h} * m; + pt4[3] = Point{0.0f, h} * m; + return true; + } + + Result load(const char* filename) + { + if (vector || bitmap) return Result::InsufficientCondition; + + bool invalid; //Invalid Path + auto loader = static_cast(LoaderMgr::loader(filename, &invalid)); + if (!loader) { + if (invalid) return Result::InvalidArguments; + return Result::NonSupport; + } + return load(loader); + } + + Result load(const char* data, uint32_t size, const char* mimeType, const char* rpath, bool copy) + { + if (!data || size <= 0) return Result::InvalidArguments; + if (vector || bitmap) return Result::InsufficientCondition; + auto loader = static_cast(LoaderMgr::loader(data, size, mimeType, rpath, copy)); + if (!loader) return Result::NonSupport; + return load(loader); + } + + Result load(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy) + { + if (!data || w <= 0 || h <= 0 || cs == ColorSpace::Unknown) return Result::InvalidArguments; + if (vector || bitmap) return Result::InsufficientCondition; + + auto loader = static_cast(LoaderMgr::loader(data, w, h, cs, copy)); + if (!loader) return Result::FailedAllocation; + + return load(loader); + } + + Result set(std::function resolver, void* data) + { + if (loader) return Result::InsufficientCondition; + + if (!resolver) { + tvg::free(this->resolver); + this->resolver = nullptr; + return Result::Success; + } + + if (!this->resolver) this->resolver = tvg::calloc(1, sizeof(AssetResolver)); + *(this->resolver) = {resolver, data}; + return Result::Success; + } + + Paint* duplicate(Paint* ret) + { + if (ret) TVGERR("RENDERER", "TODO: duplicate()"); + + load(); + + auto picture = Picture::gen(); + auto dup = to(picture); + + if (vector) { + dup->vector = vector->duplicate(); + PAINT(dup->vector)->parent = picture; + } + + if (loader) { + dup->loader = loader; + ++dup->loader->sharing; + PAINT(picture)->mark(RenderUpdateFlag::Image); + } + + dup->bitmap = bitmap; + dup->origin = origin; + dup->w = w; + dup->h = h; + dup->resizing = resizing; + + return picture; + } + + Iterator* iterator() + { + load(); + return new PictureIterator(vector); + } + + uint32_t* data(uint32_t* w, uint32_t* h) + { + //Try it, If not loaded yet. + load(); + + if (loader) { + if (w) *w = static_cast(loader->w); + if (h) *h = static_cast(loader->h); + } else { + if (w) *w = 0; + if (h) *h = 0; + } + if (bitmap) return bitmap->buf32; + else return nullptr; + } + + void load() + { + if (loader) { + if (vector) { + loader->sync(); + } else if ((vector = loader->paint())) { + vector->ref(); + PAINT(vector)->parent = this; + if (w != loader->w || h != loader->h) { + if (!resizing) { + w = loader->w; + h = loader->h; + } + loader->resize(vector, w, h); + resizing = false; + } + } else if (!bitmap) { + bitmap = loader->bitmap(); + } + } + } + + void needComposition(uint8_t opacity) + { + impl.cmpFlag = CompositionFlag::Invalid; //must clear after the rendering + + //In this case, paint(scene) would try composition itself. + if (opacity < 255) return; + + //Composition test + const Paint* target; + PAINT(this)->mask(&target); + if (!target || target->pImpl->opacity == 255 || target->pImpl->opacity == 0) return; + impl.mark(CompositionFlag::Opacity); + } + + bool render(RenderMethod* renderer) + { + auto ret = true; + + if (bitmap) { + renderer->blend(impl.blendMethod); + return renderer->renderImage(impl.rd); + } else if (vector) { + RenderCompositor* cmp = nullptr; + if (impl.cmpFlag) { + cmp = renderer->target(bounds(), renderer->colorSpace(), impl.cmpFlag); + renderer->beginComposite(cmp, MaskMethod::None, 255); + } + ret = vector->pImpl->render(renderer); + if (cmp) renderer->endComposite(cmp); + } + return ret; + } + + RenderRegion bounds() + { + if (vector) return vector->pImpl->bounds(); + return impl.renderer->region(impl.rd); + } + + Result load(ImageLoader* loader) + { + //Same resource has been loaded. + if (this->loader == loader) { + this->loader->sharing--; //make it sure the reference counting. + return Result::Success; + } else if (this->loader) { + LoaderMgr::retrieve(this->loader); + } + + this->loader = loader; + loader->set(resolver); + if (!loader->read()) return Result::Unknown; + + this->w = loader->w; + this->h = loader->h; + + impl.mark(RenderUpdateFlag::All); + + return Result::Success; + } +}; + +} + +#endif //_TVG_PICTURE_H_ diff --git a/components/thorvg-main/src/renderer/tvgRender.cpp b/components/thorvg-main/src/renderer/tvgRender.cpp new file mode 100644 index 0000000..4f121c4 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgRender.cpp @@ -0,0 +1,920 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgRender.h" + +/************************************************************************/ +/* RenderMethod Class Implementation */ +/************************************************************************/ + +uint32_t RenderMethod::ref() +{ + ScopedLock lock(key); + return (++refCnt); +} + + +uint32_t RenderMethod::unref() +{ + ScopedLock lock(key); + return (--refCnt); +} + + +RenderRegion RenderMethod::viewport() +{ + return vport; +} + + +bool RenderMethod::viewport(const RenderRegion& vp) +{ + vport = vp; + return true; +} + + +/************************************************************************/ +/* RenderPath Class Implementation */ +/************************************************************************/ + +bool RenderPath::bounds(const Matrix* m, BBox& box) +{ + if (cmds.empty() || cmds.first() == PathCommand::CubicTo) return false; + + auto pt = pts.begin(); + auto cmd = cmds.begin(); + + auto assign = [&](const Point& pt, BBox& box) -> void { + if (pt.x < box.min.x) box.min.x = pt.x; + if (pt.y < box.min.y) box.min.y = pt.y; + if (pt.x > box.max.x) box.max.x = pt.x; + if (pt.y > box.max.y) box.max.y = pt.y; + }; + + while (cmd < cmds.end()) { + switch (*cmd) { + case PathCommand::MoveTo: { + //skip the invalid assignments + if (cmd + 1 < cmds.end()) { + auto next = *(cmd + 1); + if (next == PathCommand::LineTo || next == PathCommand::CubicTo) { + assign(*pt * m, box); + } + } + ++pt; + break; + } + case PathCommand::LineTo: { + assign(*pt * m, box); + ++pt; + break; + } + case PathCommand::CubicTo: { + Bezier::bounds(box, pt[-1] * m, pt[0] * m, pt[1] * m, pt[2] * m); + pt += 3; + break; + } + default: break; + } + ++cmd; + } + return true; +} + + +void RenderPath::optimize(RenderPath& out, const Matrix& matrix) const +{ +#if defined(THORVG_GL_RASTER_SUPPORT) || defined(THORVG_WG_RASTER_SUPPORT) + static constexpr auto PX_TOLERANCE = 0.25f; + + if (empty()) return; + + out.cmds.clear(); + out.pts.clear(); + out.cmds.reserve(cmds.count); + out.pts.reserve(pts.count); + + auto cmds = this->cmds.data; + auto cmdCnt = this->cmds.count; + auto pts = this->pts.data; + + Point lastOutT, prevOutT; // The suffix "T" indicates that the point is transformed. + uint32_t prevIdx = 0; + uint32_t prevPrevIdx = 0; + auto hasPrevPrev = false; + + //vecLen is guaranteed to be non-zero since closed points are already merged + auto point2Line = [](const Point& point, const Point& start, const Point& vec, float vecLen, float& maxDist, float& minT, float& maxT) { + Point offset = point - start; + auto dist = fabsf(tvg::cross(vec, offset)) / vecLen; + if (dist > maxDist) maxDist = dist; + auto t = tvg::dot(offset, vec) / (vecLen * vecLen); + if (t < minT) minT = t; + if (t > maxT) maxT = t; + }; + + auto validateCubic = [&point2Line](const Point& start, const Point& ctrl1, const Point& ctrl2, const Point& end, float& maxDist, float& minT, float& maxT, float& vecLen) { + auto vec = end - start; + vecLen = sqrtf(vec.x * vec.x + vec.y * vec.y); + maxDist = 0.0f; + minT = FLT_MAX; + maxT = FLT_MIN; + point2Line(ctrl1, start, vec, vecLen, maxDist, minT, maxT); + point2Line(ctrl2, start, vec, vecLen, maxDist, minT, maxT); + }; + + auto point2LineSimple = [](const Point& point, const Point& start, const Point& end, float& dist, float& t, float& vecLen) { + auto vec = end - start; + auto vecLenSq = vec.x * vec.x + vec.y * vec.y; + vecLen = sqrtf(vecLenSq); + Point offset = point - start; + dist = fabsf(tvg::cross(vec, offset)) / vecLen; + t = tvg::dot(offset, vec) / vecLenSq; + }; + + auto addLineCmd = [&](const Point& pt, const Point& ptT) { + out.cmds.push(PathCommand::LineTo); + out.pts.push(pt); + prevOutT = lastOutT; + lastOutT = ptT; + prevPrevIdx = prevIdx; + prevIdx = out.pts.count - 1; + hasPrevPrev = true; + }; + + auto processLineCollinear = [&](const Point& startT, const Point& pt, const Point& ptT) { + if (!hasPrevPrev || out.pts.count <= 1) { + addLineCmd(pt, ptT); + return; + } + + float dist, t, vecLen; + point2LineSimple(ptT, prevOutT, startT, dist, t, vecLen); + if (dist > PX_TOLERANCE) { + addLineCmd(pt, ptT); + return; + } + + auto tEps = PX_TOLERANCE / vecLen; + if (t <= -tEps) { + out.pts[prevPrevIdx] = pt; + lastOutT = ptT; + } else if (t >= 1.0f - tEps) { + out.pts[prevIdx] = pt; + lastOutT = ptT; + } + }; + + auto processCubicTo = [&](const Point* cubicPts, const Point& startT) { + auto endT = cubicPts[2] * matrix; + if (tvg::closed(startT, endT, PX_TOLERANCE)) return; + float maxDist, minT, maxT, vecLen; + validateCubic(startT, cubicPts[0] * matrix, cubicPts[1] * matrix, endT, maxDist, minT, maxT, vecLen); + auto flat = (maxDist <= PX_TOLERANCE); + auto tEps = PX_TOLERANCE / vecLen; + auto inSpan = (minT >= -tEps) && (maxT <= 1.0f + tEps); + if (flat && inSpan) { + processLineCollinear(startT, cubicPts[2], endT); + } else { + out.cmds.push(PathCommand::CubicTo); + out.pts.push(cubicPts[0]); + out.pts.push(cubicPts[1]); + out.pts.push(cubicPts[2]); + prevOutT = lastOutT; + lastOutT = endT; + prevPrevIdx = prevIdx; + prevIdx = out.pts.count - 1; + hasPrevPrev = true; + } + }; + + for (uint32_t i = 0; i < cmdCnt; i++) { + switch (cmds[i]) { + case PathCommand::MoveTo: { + out.cmds.push(PathCommand::MoveTo); + out.pts.push(*pts); + lastOutT = *pts * matrix; + prevIdx = out.pts.count - 1; + hasPrevPrev = false; + pts++; + break; + } + case PathCommand::LineTo: { + auto startT = lastOutT; + auto ptT = (*pts) * matrix; + if (tvg::closed(startT, ptT, PX_TOLERANCE)) { + pts++; + break; + } + processLineCollinear(startT, *pts, ptT); + pts++; + break; + } + case PathCommand::CubicTo: { + processCubicTo(pts, lastOutT); + pts += 3; + break; + } + case PathCommand::Close: { + out.cmds.push(PathCommand::Close); + hasPrevPrev = false; + break; + } + default: break; + } + } +#else + TVGLOG("RENDERER", "RenderPath Optimization is disabled"); +#endif +} + + +/************************************************************************/ +/* RenderRegion Class Implementation */ +/************************************************************************/ + + +void RenderRegion::intersect(const RenderRegion& rhs) +{ + if (min.x < rhs.min.x) min.x = rhs.min.x; + if (min.y < rhs.min.y) min.y = rhs.min.y; + if (max.x > rhs.max.x) max.x = rhs.max.x; + if (max.y > rhs.max.y) max.y = rhs.max.y; + + // Not intersected: collapse to zero-area region + if (max.x < min.x) max.x = min.x; + if (max.y < min.y) max.y = min.y; +} + +#ifdef THORVG_PARTIAL_RENDER_SUPPORT + +#include + +void RenderDirtyRegion::init(uint32_t w, uint32_t h) +{ + auto cnt = int(sqrt(PARTITIONING)); + auto px = int32_t(w / cnt); + auto py = int32_t(h / cnt); + auto lx = int32_t(w % cnt); + auto ly = int32_t(h % cnt); + + //space partitioning + for (int y = 0; y < cnt; ++y) { + for (int x = 0; x < cnt; ++x) { + auto& partition = partitions[y * cnt + x]; + partition.list[0].reserve(64); + auto& region = partition.region; + region.min = {x * px, y * py}; + region.max = {region.min.x + px, region.min.y + py}; + //leftovers + if (x == cnt -1) region.max.x += lx; + if (y == cnt -1) region.max.y += ly; + } + } +} + + +bool RenderDirtyRegion::add(const RenderRegion& bbox) +{ + for (int idx = 0; idx < PARTITIONING; ++idx) { + auto& partition = partitions[idx]; + if (bbox.max.y <= partition.region.min.y) break; + if (bbox.intersected(partition.region)) { + ScopedLock lock(key); + partition.list[partition.current].push(RenderRegion::intersect(bbox, partition.region)); + } + } + return true; +} + + +bool RenderDirtyRegion::add(const RenderRegion& prv, const RenderRegion& cur) +{ + if (prv == cur) return add(prv); + + for (int idx = 0; idx < PARTITIONING; ++idx) { + auto& partition = partitions[idx]; + if (prv.intersected(partition.region)) { + ScopedLock lock(key); + partition.list[partition.current].push(RenderRegion::intersect(prv, partition.region)); + } + if (cur.intersected(partition.region)) { + ScopedLock lock(key); + partition.list[partition.current].push(RenderRegion::intersect(cur, partition.region)); + } + } + return true; +} + + +void RenderDirtyRegion::clear() +{ + for (int idx = 0; idx < PARTITIONING; ++idx) { + partitions[idx].list[0].clear(); + partitions[idx].list[1].clear(); + } +} + + +void RenderDirtyRegion::subdivide(Array& targets, uint32_t idx, RenderRegion& lhs, RenderRegion& rhs) +{ + RenderRegion temp[3]; + uint32_t cnt = 0; + + //subtract top + if (rhs.min.y < lhs.min.y) { + temp[cnt++] = {{rhs.min.x, rhs.min.y}, {rhs.max.x, lhs.min.y}}; + rhs.min.y = lhs.min.y; + } + //subtract bottom + if (rhs.max.y > lhs.max.y) { + temp[cnt++] = {{rhs.min.x, lhs.max.y}, {rhs.max.x, rhs.max.y}}; + rhs.max.y = lhs.max.y; + } + //subtract right + if (rhs.max.x > lhs.max.x) { + temp[cnt++] = {{lhs.max.x, rhs.min.y}, {rhs.max.x, rhs.max.y}}; + } + + //Please reserve memory enough with targets.reserve() + if (targets.count + cnt - 1 >= targets.reserved) { + TVGERR("RENDERER", "reserved(%d), required(%d)", targets.reserved, targets.count + cnt - 1); + return; + } + + /* Shift data. Considered using a list to avoid memory shifting, + but ultimately, the array outperformed the list due to better cache locality. */ + auto src = &targets[idx + 1]; + auto dst = &targets[idx + cnt]; // <-- shift right by (cnt - 1) + auto nmove = targets.count - idx - 1; // number of tail elements + memmove(dst, src, sizeof(RenderRegion) * nmove); + memcpy(&targets[idx], temp, sizeof(RenderRegion) * cnt); + targets.count += (cnt - 1); + + //sorting by x coord again, only for the updated region + while (dst < targets.end() && dst->min.x < rhs.max.x) ++dst; + stable_sort(&targets[idx], dst, [](const RenderRegion& a, const RenderRegion& b) -> bool { + return a.min.x < b.min.x; + }); +} + + +void RenderDirtyRegion::commit() +{ + if (disabled) return; + + for (int idx = 0; idx < PARTITIONING; ++idx) { + auto current = partitions[idx].current; + auto& targets = partitions[idx].list[current]; + if (targets.empty()) continue; + + current = !current; //swapping buffers + auto& output = partitions[idx].list[current]; + + targets.reserve(targets.count * 10); //one intersection can be divided up to 3 + output.reserve(targets.count); + + partitions[idx].current = current; + + //sorting by x coord. guarantee the stable performance: O(NlogN) + stable_sort(targets.begin(), targets.end(), [](const RenderRegion& a, const RenderRegion& b) -> bool { + return a.min.x < b.min.x; + }); + + //Optimized using sweep-line algorithm: O(NlogN) + for (uint32_t i = 0; i < targets.count; ++i) { + auto& lhs = targets[i]; + if (lhs.invalid()) continue; + auto merged = false; + + for (uint32_t j = i + 1; j < targets.count; ++j) { + auto& rhs = targets[j]; + if (rhs.invalid()) continue; + if (lhs.max.x < rhs.min.x) break; //line sweeping + + //fully overlapped. drop lhs + if (rhs.contained(lhs)) { + merged = true; + break; + } + //fully overlapped. replace the lhs with rhs + if (lhs.contained(rhs)) { + rhs = {}; + continue; + } + //just merge & expand on x axis + if (lhs.min.y == rhs.min.y && lhs.max.y == rhs.max.y) { + if (lhs.max.x >= rhs.min.x) { + lhs.max.x = rhs.max.x; + rhs = {}; + j = i; //lhs dirty region has been damaged, try again. + continue; + } + } + //just merge & expand on y axis + if (lhs.min.x == rhs.min.x && lhs.max.x == rhs.max.x) { + if (lhs.min.y <= rhs.max.y && rhs.min.y <= lhs.max.y) { + rhs.min.y = std::min(lhs.min.y, rhs.min.y); + rhs.max.y = std::max(lhs.max.y, rhs.max.y); + merged = true; + break; + } + } + //subdivide regions + if (lhs.intersected(rhs)) { + subdivide(targets, j, lhs, rhs); + --j; //rhs dirty region has been damaged, try again. + } + } + if (!merged) output.push(lhs); //this region is complete isolated + lhs = {}; + } + } +} + +#endif + +/************************************************************************/ +/* RenderTrimPath Class Implementation */ +/************************************************************************/ + +#define EPSILON 1e-4f + + +static void _trimAt(const PathCommand* cmds, const Point* pts, Point& moveTo, float at1, float at2, bool start, RenderPath& out) +{ + switch (*cmds) { + case PathCommand::LineTo: { + Line tmp, left, right; + Line{*(pts - 1), *pts}.split(at1, left, tmp); + tmp.split(at2, left, right); + if (start) { + out.pts.push(left.pt1); + moveTo = left.pt1; + out.cmds.push(PathCommand::MoveTo); + } + out.pts.push(left.pt2); + out.cmds.push(PathCommand::LineTo); + break; + } + case PathCommand::CubicTo: { + Bezier tmp, left, right; + Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}.split(at1, left, tmp); + tmp.split(at2, left, right); + if (start) { + moveTo = left.start; + out.pts.push(left.start); + out.cmds.push(PathCommand::MoveTo); + } + out.pts.push(left.ctrl1); + out.pts.push(left.ctrl2); + out.pts.push(left.end); + out.cmds.push(PathCommand::CubicTo); + break; + } + case PathCommand::Close: { + Line tmp, left, right; + Line{*(pts - 1), moveTo}.split(at1, left, tmp); + tmp.split(at2, left, right); + if (start) { + moveTo = left.pt1; + out.pts.push(left.pt1); + out.cmds.push(PathCommand::MoveTo); + } + out.pts.push(left.pt2); + out.cmds.push(PathCommand::LineTo); + break; + } + default: break; + } +} + + +static void _add(const PathCommand* cmds, const Point* pts, const Point& moveTo, bool& start, RenderPath& out) +{ + switch (*cmds) { + case PathCommand::MoveTo: { + out.cmds.push(PathCommand::MoveTo); + out.pts.push(*pts); + start = false; + break; + } + case PathCommand::LineTo: { + if (start) { + out.cmds.push(PathCommand::MoveTo); + out.pts.push(*(pts - 1)); + } + out.cmds.push(PathCommand::LineTo); + out.pts.push(*pts); + start = false; + break; + } + case PathCommand::CubicTo: { + if (start) { + out.cmds.push(PathCommand::MoveTo); + out.pts.push(*(pts - 1)); + } + out.cmds.push(PathCommand::CubicTo); + out.pts.push(*pts); + out.pts.push(*(pts + 1)); + out.pts.push(*(pts + 2)); + start = false; + break; + } + case PathCommand::Close: { + if (start) { + out.cmds.push(PathCommand::MoveTo); + out.pts.push(*(pts - 1)); + } + out.cmds.push(PathCommand::LineTo); + out.pts.push(moveTo); + start = true; + break; + } + } +} + + +static void _trimPath(const PathCommand* inCmds, uint32_t inCmdsCnt, const Point* inPts, TVG_UNUSED uint32_t inPtsCnt, float trimStart, float trimEnd, RenderPath& out, bool connect = false) +{ + auto cmds = const_cast(inCmds); + auto pts = const_cast(inPts); + auto moveToTrimmed = *pts; + auto moveTo = *pts; + auto len = 0.0f; + + auto _length = [&]() -> float { + switch (*cmds) { + case PathCommand::MoveTo: return 0.0f; + case PathCommand::LineTo: return tvg::length(*(pts - 1), *pts); + case PathCommand::CubicTo: return Bezier{*(pts - 1), *pts, *(pts + 1), *(pts + 2)}.length(); + case PathCommand::Close: return tvg::length(*(pts - 1), moveTo); + } + return 0.0f; + }; + + auto _shift = [&]() -> void { + switch (*cmds) { + case PathCommand::MoveTo: + moveTo = *pts; + moveToTrimmed = *pts; + ++pts; + break; + case PathCommand::LineTo: + ++pts; + break; + case PathCommand::CubicTo: + pts += 3; + break; + case PathCommand::Close: + break; + } + ++cmds; + }; + + auto start = !connect; + + for (uint32_t i = 0; i < inCmdsCnt; ++i) { + auto dLen = _length(); + + //very short segments are skipped since due to the finite precision of Bezier curve subdivision and length calculation (1e-2), + //trimming may produce very short segments that would effectively have zero length with higher computational accuracy. + if (len <= trimStart) { + //cut the segment at the beginning and at the end + if (len + dLen > trimEnd) { + _trimAt(cmds, pts, moveToTrimmed, trimStart - len, trimEnd - trimStart, start, out); + start = false; + //cut the segment at the beginning + } else if (len + dLen > trimStart + EPSILON) { + _trimAt(cmds, pts, moveToTrimmed, trimStart - len, len + dLen - trimStart, start, out); + start = false; + } + } else if (len <= trimEnd - EPSILON) { + //cut the segment at the end + if (len + dLen > trimEnd) { + _trimAt(cmds, pts, moveTo, 0.0f, trimEnd - len, start, out); + start = true; + //add the whole segment + } else if (len + dLen > trimStart + EPSILON) _add(cmds, pts, moveTo, start, out); + } + + len += dLen; + _shift(); + } +} + + +static void _trim(const PathCommand* inCmds, uint32_t inCmdsCnt, const Point* inPts, uint32_t inPtsCnt, float begin, float end, bool connect, RenderPath& out) +{ + auto totalLength = tvg::length(inCmds, inCmdsCnt, inPts, inPtsCnt); + auto trimStart = begin * totalLength; + auto trimEnd = end * totalLength; + + if (begin >= end) { + _trimPath(inCmds, inCmdsCnt, inPts, inPtsCnt, trimStart, totalLength, out); + _trimPath(inCmds, inCmdsCnt, inPts, inPtsCnt, 0.0f, trimEnd, out, connect); + } else { + _trimPath(inCmds, inCmdsCnt, inPts, inPtsCnt, trimStart, trimEnd, out); + } +} + + +static void _get(float& begin, float& end) +{ + auto loop = true; + + if (begin > 1.0f && end > 1.0f) loop = false; + if (begin < 0.0f && end < 0.0f) loop = false; + if (begin >= 0.0f && begin <= 1.0f && end >= 0.0f && end <= 1.0f) loop = false; + + if (begin > 1.0f) begin -= 1.0f; + if (begin < 0.0f) begin += 1.0f; + if (end > 1.0f) end -= 1.0f; + if (end < 0.0f) end += 1.0f; + + if ((loop && begin < end) || (!loop && begin > end)) std::swap(begin, end); +} + + +bool RenderTrimPath::trim(const RenderPath& in, RenderPath& out) const +{ + if (in.pts.count < 2 || tvg::zero(begin - end)) return false; + + float begin = this->begin, end = this->end; + _get(begin, end); + + out.cmds.reserve(in.cmds.count * 2); + out.pts.reserve(in.pts.count * 2); + + auto pts = in.pts.data; + auto cmds = in.cmds.data; + + if (simultaneous) { + auto startCmds = cmds; + auto startPts = pts; + uint32_t i = 0; + while (i < in.cmds.count) { + switch (in.cmds[i]) { + case PathCommand::MoveTo: { + if (startCmds != cmds) _trim(startCmds, cmds - startCmds, startPts, pts - startPts, begin, end, *(cmds - 1) == PathCommand::Close, out); + startPts = pts; + startCmds = cmds; + ++pts; + ++cmds; + break; + } + case PathCommand::LineTo: { + ++pts; + ++cmds; + break; + } + case PathCommand::CubicTo: { + pts += 3; + ++cmds; + break; + } + case PathCommand::Close: { + ++cmds; + if (startCmds != cmds) _trim(startCmds, cmds - startCmds, startPts, pts - startPts, begin, end, *(cmds - 1) == PathCommand::Close, out); + startPts = pts; + startCmds = cmds; + break; + } + } + i++; + } + if (startCmds != cmds) _trim(startCmds, cmds - startCmds, startPts, pts - startPts, begin, end, *(cmds - 1) == PathCommand::Close, out); + } else { + _trim(in.cmds.data, in.cmds.count, in.pts.data, in.pts.count, begin, end, false, out); + } + + return out.pts.count >= 2; +} + +/************************************************************************/ +/* StrokeDashPath Class Implementation */ +/************************************************************************/ + +//TODO: use this common function from sw engine +#if defined(THORVG_GL_RASTER_SUPPORT) || defined(THORVG_WG_RASTER_SUPPORT) + +struct StrokeDashPath +{ +public: + StrokeDashPath(RenderStroke::Dash dash) : dash(dash) {} + bool gen(const RenderPath& in, RenderPath& out, bool drawPoint); + +private: + void lineTo(RenderPath& out, const Point& pt, bool drawPoint); + void cubicTo(RenderPath& out, const Point& pt1, const Point& pt2, const Point& pt3, bool drawPoint); + void point(RenderPath& out, const Point& p); + + template + void segment(Segment seg, float len, RenderPath& out, bool allowDot, LengthFn lengthFn, SplitFn splitFn, DrawFn drawFn, PointFn getStartPt, const Point& endPos); + + RenderStroke::Dash dash; + float curLen = 0.0f; + int32_t curIdx = 0; + Point curPos{}; + bool opGap = false; + bool move = true; +}; + + +template +void StrokeDashPath::segment(Segment seg, float len, RenderPath& out, bool allowDot, LengthFn lengthFn, SplitFn splitFn, DrawFn drawFn, PointFn getStartPt, const Point& end) +{ + #define MIN_CURR_LEN_THRESHOLD 0.1f + + if (tvg::zero(len)) { + out.moveTo(curPos); + } else if (len <= curLen) { + curLen -= len; + if (!opGap) { + if (move) { + out.moveTo(curPos); + move = false; + } + drawFn(seg); + } + } else { + Segment left, right; + while (len - curLen > DASH_PATTERN_THRESHOLD) { + if (curLen > 0.0f) { + splitFn(seg, curLen, left, right); + len -= curLen; + if (!opGap) { + if (move || dash.pattern[curIdx] - curLen < FLOAT_EPSILON) { + out.moveTo(getStartPt(left)); + move = false; + } + drawFn(left); + } + } else { + if (allowDot && !opGap) point(out, getStartPt(seg)); + right = seg; + } + + curIdx = (curIdx + 1) % dash.count; + curLen = dash.pattern[curIdx]; + opGap = !opGap; + seg = right; + curPos = getStartPt(seg); + move = true; + } + curLen -= len; + if (!opGap) { + if (move) { + out.moveTo(getStartPt(seg)); + move = false; + } + drawFn(seg); + } + if (curLen < MIN_CURR_LEN_THRESHOLD) { + curIdx = (curIdx + 1) % dash.count; + curLen = dash.pattern[curIdx]; + opGap = !opGap; + } + } + curPos = end; +} + + +//allowDot: zero length segment with non-butt cap still should be rendered as a point - only the caps are visible +bool StrokeDashPath::gen(const RenderPath& in, RenderPath& out, bool allowDot) +{ + int32_t idx = 0; + auto offset = dash.offset; + auto gap = false; + if (!tvg::zero(dash.offset)) { + auto length = (dash.count % 2) ? dash.length * 2 : dash.length; + offset = fmodf(offset, length); + if (offset < 0) offset += length; + + for (uint32_t i = 0; i < dash.count * (dash.count % 2 + 1); ++i, ++idx) { + auto curPattern = dash.pattern[i % dash.count]; + if (offset < curPattern) break; + offset -= curPattern; + gap = !gap; + } + idx = idx % dash.count; + } + + auto pts = in.pts.data; + Point start{}; + + ARRAY_FOREACH(cmd, in.cmds) { + switch (*cmd) { + case PathCommand::Close: { + lineTo(out, start, allowDot); + break; + } + case PathCommand::MoveTo: { + // reset the dash state + curIdx = idx; + curLen = dash.pattern[idx] - offset; + opGap = gap; + move = true; + start = curPos = *pts; + pts++; + break; + } + case PathCommand::LineTo: { + lineTo(out, *pts, allowDot); + pts++; + break; + } + case PathCommand::CubicTo: { + cubicTo(out, pts[0], pts[1], pts[2], allowDot); + pts += 3; + break; + } + default: break; + } + } + return true; +} + + +void StrokeDashPath::point(RenderPath& out, const Point& p) +{ + if (move || dash.pattern[curIdx] < FLOAT_EPSILON) { + out.moveTo(p); + move = false; + } + out.lineTo(p); +} + + +void StrokeDashPath::lineTo(RenderPath& out, const Point& to, bool allowDot) +{ + Line line = {curPos, to}; + auto len = length(to - curPos); + segment(line, len, out, allowDot, + [](const Line& l) { return length(l.pt2 - l.pt1); }, + [](const Line& l, float len, Line& left, Line& right) { l.split(len, left, right); }, + [&](const Line& l) { out.lineTo(l.pt2); }, + [](const Line& l) { return l.pt1; }, + to + ); +} + + +void StrokeDashPath::cubicTo(RenderPath& out, const Point& cnt1, const Point& cnt2, const Point& end, bool allowDot) +{ + Bezier curve = {curPos, cnt1, cnt2, end}; + auto len = curve.length(); + segment(curve, len, out, allowDot, + [](const Bezier& b) { return b.length(); }, + [](const Bezier& b, float len, Bezier& left, Bezier& right) { b.split(len, left, right); }, + [&](const Bezier& b) { out.cubicTo(b.ctrl1, b.ctrl2, b.end); }, + [](const Bezier& b) { return b.start; }, + end + ); +} + + +bool RenderShape::strokeDash(RenderPath& out) const +{ + if (!stroke || stroke->dash.count == 0 || stroke->dash.length < DASH_PATTERN_THRESHOLD) return false; + + out.cmds.reserve(20 * path.cmds.count); + out.pts.reserve(20 * path.pts.count); + + StrokeDashPath dash(stroke->dash); + auto allowDot = stroke->cap != StrokeCap::Butt; + + if (trimpath()) { + RenderPath tpath; + if (stroke->trim.trim(path, tpath)) return dash.gen(tpath, out, allowDot); + else return false; + } + return dash.gen(path, out, allowDot); +} +#else +bool RenderShape::strokeDash(RenderPath& out) const +{ + return false; +} +#endif \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgRender.h b/components/thorvg-main/src/renderer/tvgRender.h new file mode 100644 index 0000000..c3146e4 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgRender.h @@ -0,0 +1,699 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_RENDER_H_ +#define _TVG_RENDER_H_ + +#include +#include +#include "tvgCommon.h" +#include "tvgArray.h" +#include "tvgLock.h" +#include "tvgColor.h" +#include "tvgMath.h" + +namespace tvg +{ + +using RenderData = void*; +using RenderColor = tvg::RGBA; +using pixel_t = uint32_t; + +#define DASH_PATTERN_THRESHOLD 0.001f + +//TODO: Separate Color & Opacity for more detailed conditional check +enum RenderUpdateFlag : uint16_t {None = 0, Path = 1, Color = 2, Gradient = 4, Stroke = 8, Transform = 16, Image = 32, GradientStroke = 64, Blend = 128, Clip = 256, All = 0xffff}; +enum CompositionFlag : uint8_t {Invalid = 0, Opacity = 1, Blending = 2, Masking = 4, PostProcessing = 8}; //Composition Purpose + +static inline void operator|=(RenderUpdateFlag& a, const RenderUpdateFlag b) +{ + a = RenderUpdateFlag(uint16_t(a) | uint16_t(b)); +} + +static inline RenderUpdateFlag operator|(const RenderUpdateFlag a, const RenderUpdateFlag b) +{ + return RenderUpdateFlag(uint16_t(a) | uint16_t(b)); +} + +struct RenderSurface +{ + union { + pixel_t* data = nullptr; //system based data pointer + uint32_t* buf32; //for explicit 32bits channels + uint8_t* buf8; //for explicit 8bits grayscale + }; + Key key; //a reserved lock for the thread safety + uint32_t stride = 0; + uint32_t w = 0, h = 0; + ColorSpace cs = ColorSpace::Unknown; + uint8_t channelSize = 0; + bool premultiplied = false; //Alpha-premultiplied + + RenderSurface() + { + } + + RenderSurface(const RenderSurface* rhs) + { + data = rhs->data; + stride = rhs->stride; + w = rhs->w; + h = rhs->h; + cs = rhs->cs; + channelSize = rhs->channelSize; + premultiplied = rhs->premultiplied; + } +}; + +struct RenderCompositor +{ + MaskMethod method; + uint8_t opacity; +}; + +struct RenderRegion +{ + struct { + int32_t x, y; + } min; + + struct { + int32_t x, y; + } max; + + static constexpr RenderRegion intersect(const RenderRegion& lhs, const RenderRegion& rhs) + { + RenderRegion ret = {{std::max(lhs.min.x, rhs.min.x), std::max(lhs.min.y, rhs.min.y)}, {std::min(lhs.max.x, rhs.max.x), std::min(lhs.max.y, rhs.max.y)}}; + // Not intersected: collapse to zero-area region + if (ret.min.x > ret.max.x) ret.max.x = ret.min.x; + if (ret.min.y > ret.max.y) ret.max.y = ret.min.y; + return ret; + } + + static constexpr RenderRegion add(const RenderRegion& lhs, const RenderRegion& rhs) + { + return {{std::min(lhs.min.x, rhs.min.x), std::min(lhs.min.y, rhs.min.y)}, {std::max(lhs.max.x, rhs.max.x), std::max(lhs.max.y, rhs.max.y)}}; + } + + void intersect(const RenderRegion& rhs); + + void add(const RenderRegion& rhs) + { + if (rhs.min.x < min.x) min.x = rhs.min.x; + if (rhs.min.y < min.y) min.y = rhs.min.y; + if (rhs.max.x > max.x) max.x = rhs.max.x; + if (rhs.max.y > max.y) max.y = rhs.max.y; + } + + bool contained(const RenderRegion& rhs) const + { + return (min.x <= rhs.min.x && max.x >= rhs.max.x && min.y <= rhs.min.y && max.y >= rhs.max.y); + } + + bool intersected(const RenderRegion& rhs) const + { + return (rhs.min.x < max.x && rhs.max.x > min.x && rhs.min.y < max.y && rhs.max.y > min.y); + } + + bool operator==(const RenderRegion& rhs) const + { + return (min.x == rhs.min.x && min.y == rhs.min.y && max.x == rhs.max.x && max.y == rhs.max.y); + } + + void reset() { min.x = min.y = max.x = max.y = 0; } + bool valid() const { return (max.x > min.x && max.y > min.y); } + bool invalid() const { return !valid(); } + + int32_t sx() const { return min.x; } + int32_t sy() const { return min.y; } + int32_t sw() const { return max.x - min.x; } + int32_t sh() const { return max.y - min.y; } + + uint32_t x() const { return (uint32_t) sx(); } + uint32_t y() const { return (uint32_t) sy(); } + uint32_t w() const { return (uint32_t) sw(); } + uint32_t h() const { return (uint32_t) sh(); } +}; + + +#ifdef THORVG_PARTIAL_RENDER_SUPPORT + struct RenderDirtyRegion + { + public: + static constexpr const int PARTITIONING = 16; //must be N*N + bool support = true; + + void init(uint32_t w, uint32_t h); + void commit(); + bool add(const RenderRegion& bbox); + bool add(const RenderRegion& prv, const RenderRegion& cur); //collect the old and new dirty regions together + void clear(); + + bool deactivate(bool on) + { + std::swap(on, disabled); + return on; + } + + bool deactivated() + { + return (!support || disabled); + } + + const RenderRegion& partition(int idx) + { + return partitions[idx].region; + } + + const Array& get(int idx) + { + return partitions[idx].list[partitions[idx].current]; + } + + private: + void subdivide(Array& targets, uint32_t idx, RenderRegion& lhs, RenderRegion& rhs); + + struct Partition + { + RenderRegion region; + Array list[2]; //double buffer swapping + uint8_t current = 0; //double buffer swapping list index. 0 or 1 + }; + + Key key; + Partition partitions[PARTITIONING]; + bool disabled = false; + }; +#else + struct RenderDirtyRegion + { + static constexpr const int PARTITIONING = 16; //must be N*N + bool support = true; + + void init(uint32_t w, uint32_t h) {} + void commit() {} + bool add(TVG_UNUSED const RenderRegion& bbox) { return true; } + bool add(TVG_UNUSED const RenderRegion& prv, TVG_UNUSED const RenderRegion& cur) { return true; } + void clear() {} + bool deactivate(TVG_UNUSED bool on) { return true; } + bool deactivated() { return true; } + const RenderRegion& partition(TVG_UNUSED int idx) { static RenderRegion tmp{}; return tmp; } + const Array& get(TVG_UNUSED int idx) { static Array tmp; return tmp; } + }; +#endif + + +struct RenderPath +{ + Array cmds; + Array pts; + + bool empty() const + { + return pts.empty(); + } + + void clear() + { + pts.clear(); + cmds.clear(); + } + + void close() + { + //Don't close multiple times. + if (cmds.count > 0 && cmds.last() == PathCommand::Close) return; + cmds.push(PathCommand::Close); + } + + void moveTo(const Point& pt) + { + pts.push(pt); + cmds.push(PathCommand::MoveTo); + } + + void lineTo(const Point& pt) + { + pts.push(pt); + cmds.push(PathCommand::LineTo); + } + + void cubicTo(const Point& cnt1, const Point& cnt2, const Point& end) + { + pts.push(cnt1); + pts.push(cnt2); + pts.push(end); + cmds.push(PathCommand::CubicTo); + } + + Point point(float progress) + { + if (progress <= 0.0f) return pts.first(); + else if (progress >= 1.0f) return pts.last(); + + auto pleng = tvg::length(cmds.data, cmds.count, pts.data, pts.count) * progress; + auto cleng = 0.0f; + auto p = pts.data; + auto c = cmds.data; + Point curr{}, start{}, next{}; + + while (c < cmds.data + cmds.count) { + switch (*c) { + case PathCommand::MoveTo: { + curr = start = *p++; + break; + } + case PathCommand::LineTo: { + next = *p; + auto segLen = tvg::length(curr, next); + if (cleng + segLen >= pleng) return lerp(curr, next, (pleng - cleng) / segLen); + cleng += segLen; + curr = *p++; + break; + } + case PathCommand::CubicTo: { + Bezier bz = {curr, *p, *(p + 1), *(p + 2)}; + auto segLen = bz.length(); + if (cleng + segLen >= pleng) return bz.at((pleng - cleng) / segLen); + cleng += segLen; + curr = *(p + 2); + p += 3; + break; + } + case PathCommand::Close: { + auto segLen = tvg::length(curr, start); + if (cleng + segLen >= pleng) return lerp(curr, start, (pleng - cleng) / segLen); + cleng += segLen; + curr = start; + break; + } + } + ++c; + } + return curr; + } + + /* Optimize path in screen space with merging collinear lines, + collapsing zero length lines, and removing unnecessary cubic beziers. */ + void optimize(RenderPath& out, const Matrix& matrix) const; + bool bounds(const Matrix* m, BBox& box); +}; + +struct RenderTrimPath +{ + float begin = 0.0f; + float end = 1.0f; + bool simultaneous = true; + + bool valid() + { + if (begin != 0.0f || end != 1.0f) return true; + return false; + } + + bool trim(const RenderPath& in, RenderPath& out) const; +}; + +struct RenderStroke +{ + float width = 0.0f; + RenderColor color{}; + Fill *fill = nullptr; + struct Dash { + float* pattern = nullptr; + uint32_t count = 0; + float offset = 0.0f; + float length = 0.0f; + } dash; + float miterlimit = 4.0f; + RenderTrimPath trim; + StrokeCap cap = StrokeCap::Square; + StrokeJoin join = StrokeJoin::Bevel; + bool first = false; + + void operator=(const RenderStroke& rhs) + { + width = rhs.width; + color = rhs.color; + + delete(fill); + if (rhs.fill) fill = rhs.fill->duplicate(); + else fill = nullptr; + + tvg::free(dash.pattern); + dash = rhs.dash; + if (rhs.dash.count > 0) { + dash.pattern = tvg::malloc(sizeof(float) * rhs.dash.count); + memcpy(dash.pattern, rhs.dash.pattern, sizeof(float) * rhs.dash.count); + } + + miterlimit = rhs.miterlimit; + trim = rhs.trim; + cap = rhs.cap; + join = rhs.join; + first = rhs.first; + } + + ~RenderStroke() + { + tvg::free(dash.pattern); + delete(fill); + } +}; + +struct RenderShape +{ + RenderPath path; + Fill *fill = nullptr; + RenderColor color{}; + RenderStroke *stroke = nullptr; + FillRule rule = FillRule::NonZero; + + ~RenderShape() + { + delete(fill); + delete(stroke); + } + + void fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const + { + if (r) *r = color.r; + if (g) *g = color.g; + if (b) *b = color.b; + if (a) *a = color.a; + } + + bool trimpath() const + { + return stroke ? stroke->trim.valid() : false; + } + + bool strokeFirst() const + { + return (stroke && stroke->first) ? true : false; + } + + float strokeWidth() const + { + return stroke ? stroke->width : 0.0f; + } + + bool strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const + { + if (!stroke) return false; + + if (r) *r = stroke->color.r; + if (g) *g = stroke->color.g; + if (b) *b = stroke->color.b; + if (a) *a = stroke->color.a; + + return true; + } + + const Fill* strokeFill() const + { + return stroke ? stroke->fill : nullptr; + } + + uint32_t strokeDash(const float** dashPattern, float* offset) const + { + if (!stroke) return 0; + if (dashPattern) *dashPattern = stroke->dash.pattern; + if (offset) *offset = stroke->dash.offset; + return stroke->dash.count; + } + + StrokeCap strokeCap() const + { + return stroke ? stroke->cap : StrokeCap::Square; + } + + StrokeJoin strokeJoin() const + { + return stroke ? stroke->join : StrokeJoin::Bevel; + } + + float strokeMiterlimit() const + { + return stroke ? stroke->miterlimit : 4.0f; + } + + bool strokeDash(RenderPath& out) const; +}; + +struct RenderEffect +{ + RenderData rd = nullptr; + RenderRegion extend{}; + SceneEffect type; + bool valid = false; + + virtual ~RenderEffect() {} +}; + +struct RenderEffectGaussianBlur : RenderEffect +{ + float sigma; + uint8_t direction; //0: both, 1: horizontal, 2: vertical + uint8_t border; //0: duplicate, 1: wrap + uint8_t quality; //0 ~ 100 (optional) + + static RenderEffectGaussianBlur* gen(va_list& args) + { + auto inst = new RenderEffectGaussianBlur; + inst->sigma = std::max((float) va_arg(args, double), 0.0f); + inst->direction = tvg::clamp(va_arg(args, int), 0, 2); + inst->border = std::min(va_arg(args, int), 1); + inst->quality = std::min(va_arg(args, int), 100); + inst->type = SceneEffect::GaussianBlur; + return inst; + } +}; + +struct RenderEffectDropShadow : RenderEffect +{ + uint8_t color[4]; //rgba + float angle; + float distance; + float sigma; + uint8_t quality; //0 ~ 100 (optional) + + static RenderEffectDropShadow* gen(va_list& args) + { + auto inst = new RenderEffectDropShadow; + inst->color[0] = va_arg(args, int); + inst->color[1] = va_arg(args, int); + inst->color[2] = va_arg(args, int); + inst->color[3] = va_arg(args, int); + inst->angle = (float) va_arg(args, double); + inst->distance = (float) va_arg(args, double); + inst->sigma = std::max((float) va_arg(args, double), 0.0f); + inst->quality = std::min(va_arg(args, int), 100); + inst->type = SceneEffect::DropShadow; + return inst; + } +}; + +struct RenderEffectFill : RenderEffect +{ + uint8_t color[4]; //rgba + + static RenderEffectFill* gen(va_list& args) + { + auto inst = new RenderEffectFill; + inst->color[0] = va_arg(args, int); + inst->color[1] = va_arg(args, int); + inst->color[2] = va_arg(args, int); + inst->color[3] = va_arg(args, int); + inst->type = SceneEffect::Fill; + return inst; + } +}; + +struct RenderEffectTint : RenderEffect +{ + uint8_t black[3]; //rgb + uint8_t white[3]; //rgb + uint8_t intensity; //0 - 255 + + static RenderEffectTint* gen(va_list& args) + { + auto inst = new RenderEffectTint; + inst->black[0] = va_arg(args, int); + inst->black[1] = va_arg(args, int); + inst->black[2] = va_arg(args, int); + inst->white[0] = va_arg(args, int); + inst->white[1] = va_arg(args, int); + inst->white[2] = va_arg(args, int); + inst->intensity = (uint8_t)(static_cast(va_arg(args, double)) * 2.55f); + inst->type = SceneEffect::Tint; + return inst; + } +}; + +struct RenderEffectTritone : RenderEffect +{ + uint8_t shadow[3]; //rgb + uint8_t midtone[3]; //rgb + uint8_t highlight[3]; //rgb + uint8_t blender = 0; //0 ~ 255 + + static RenderEffectTritone* gen(va_list& args) + { + auto inst = new RenderEffectTritone; + inst->shadow[0] = va_arg(args, int); + inst->shadow[1] = va_arg(args, int); + inst->shadow[2] = va_arg(args, int); + inst->midtone[0] = va_arg(args, int); + inst->midtone[1] = va_arg(args, int); + inst->midtone[2] = va_arg(args, int); + inst->highlight[0] = va_arg(args, int); + inst->highlight[1] = va_arg(args, int); + inst->highlight[2] = va_arg(args, int); + inst->blender = va_arg(args, int); + inst->type = SceneEffect::Tritone; + return inst; + } +}; + +struct RenderMethod +{ +private: + uint32_t refCnt = 0; + Key key; + +protected: + RenderRegion vport; //viewport + +public: + //common implementation + uint32_t ref(); + uint32_t unref(); + RenderRegion viewport(); + bool viewport(const RenderRegion& vp); + + //main features + virtual ~RenderMethod() {} + virtual bool preUpdate() = 0; + virtual RenderData prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) = 0; + virtual RenderData prepare(RenderSurface* surface, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) = 0; + virtual bool postUpdate() = 0; + virtual bool preRender() = 0; + virtual bool renderShape(RenderData data) = 0; + virtual bool renderImage(RenderData data) = 0; + virtual bool postRender() = 0; + virtual void dispose(RenderData data) = 0; + virtual RenderRegion region(RenderData data) = 0; + virtual bool bounds(RenderData data, Point* pt4, const Matrix& m) = 0; + virtual bool blend(BlendMethod method) = 0; + virtual ColorSpace colorSpace() = 0; + virtual const RenderSurface* mainSurface() = 0; + virtual bool clear() = 0; + virtual bool sync() = 0; + virtual bool intersectsShape(RenderData data, const RenderRegion& region) = 0; + virtual bool intersectsImage(RenderData data, const RenderRegion& region) = 0; + + //composition + virtual RenderCompositor* target(const RenderRegion& region, ColorSpace cs, CompositionFlag flags) = 0; + virtual bool beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) = 0; + virtual bool endComposite(RenderCompositor* cmp) = 0; + + //post effects + virtual void prepare(RenderEffect* effect, const Matrix& transform) = 0; + virtual bool region(RenderEffect* effect) = 0; + virtual bool render(RenderCompositor* cmp, const RenderEffect* effect, bool direct) = 0; + virtual void dispose(RenderEffect* effect) = 0; + + //partial rendering + virtual void damage(RenderData rd, const RenderRegion& region) = 0; + virtual bool partial(bool disable) = 0; +}; + +static inline bool MASK_REGION_MERGING(MaskMethod method) +{ + switch(method) { + case MaskMethod::Alpha: + case MaskMethod::InvAlpha: + case MaskMethod::Luma: + case MaskMethod::InvLuma: + case MaskMethod::Subtract: + case MaskMethod::Intersect: + return false; + //these might expand the rendering region + case MaskMethod::Add: + case MaskMethod::Difference: + case MaskMethod::Lighten: + case MaskMethod::Darken: + return true; + default: + TVGERR("RENDERER", "Unsupported Masking Method! = %d", (int)method); + return false; + } +} + +static inline uint8_t CHANNEL_SIZE(ColorSpace cs) +{ + switch(cs) { + case ColorSpace::ABGR8888: + case ColorSpace::ABGR8888S: + case ColorSpace::ARGB8888: + case ColorSpace::ARGB8888S: + return sizeof(uint32_t); + case ColorSpace::Grayscale8: + return sizeof(uint8_t); + case ColorSpace::Unknown: + default: + TVGERR("RENDERER", "Unsupported Channel Size! = %d", (int)cs); + return 0; + } +} + +static inline ColorSpace MASK_TO_COLORSPACE(RenderMethod* renderer, MaskMethod method) +{ + switch(method) { + case MaskMethod::Alpha: + case MaskMethod::InvAlpha: + case MaskMethod::Add: + case MaskMethod::Difference: + case MaskMethod::Subtract: + case MaskMethod::Intersect: + case MaskMethod::Lighten: + case MaskMethod::Darken: + return ColorSpace::Grayscale8; + //TODO: Optimize Luma/InvLuma colorspace to Grayscale8 + case MaskMethod::Luma: + case MaskMethod::InvLuma: + return renderer->colorSpace(); + default: + TVGERR("RENDERER", "Unsupported Masking Size! = %d", (int)method); + return ColorSpace::Unknown; + } +} + +static inline uint8_t MULTIPLY(uint8_t c, uint8_t a) +{ + return (((c) * (a) + 0xff) >> 8); +} + +} + +#endif //_TVG_RENDER_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgSaveModule.h b/components/thorvg-main/src/renderer/tvgSaveModule.h new file mode 100644 index 0000000..69be432 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgSaveModule.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SAVE_MODULE_H_ +#define _TVG_SAVE_MODULE_H_ + +#include "tvgIteratorAccessor.h" + +namespace tvg +{ + +class SaveModule +{ +public: + virtual ~SaveModule() {} + + virtual bool save(Paint* paint, Paint* bg, const char* filename, uint32_t quality) = 0; + virtual bool save(Animation* animation, Paint* bg, const char* filename, uint32_t quality, uint32_t fps) = 0; + virtual bool close() = 0; +}; + +} + +#endif //_TVG_SAVE_MODULE_H_ diff --git a/components/thorvg-main/src/renderer/tvgSaver.cpp b/components/thorvg-main/src/renderer/tvgSaver.cpp new file mode 100644 index 0000000..c930edc --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgSaver.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgCommon.h" +#include "tvgStr.h" +#include "tvgSaveModule.h" + +#ifdef THORVG_GIF_SAVER_SUPPORT + #include "tvgGifSaver.h" +#endif + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +struct Saver::Impl +{ + SaveModule* saveModule = nullptr; + Paint* bg = nullptr; + + ~Impl() + { + delete(saveModule); + if (bg) bg->unref(); + } +}; + + +static SaveModule* _find(FileType type) +{ + switch(type) { + case FileType::Gif: { +#ifdef THORVG_GIF_SAVER_SUPPORT + return new GifSaver; +#endif + break; + } + default: { + break; + } + } + +#ifdef THORVG_LOG_ENABLED + const char *format; + switch(type) { + case FileType::Gif: { + format = "GIF"; + break; + } + default: { + format = "???"; + break; + } + } + TVGLOG("RENDERER", "%s format is not supported", format); +#endif + return nullptr; +} + + +static SaveModule* _find(const char* filename) +{ + auto ext = fileext(filename); + if (ext && !strcmp(ext, "gif")) return _find(FileType::Gif); + return nullptr; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +Saver::Saver() : pImpl(new Impl()) +{ +} + + +Saver::~Saver() +{ + delete(pImpl); +} + + +Result Saver::save(Paint* paint, const char* filename, uint32_t quality) noexcept +{ + if (!paint) return Result::InvalidArguments; + + //Already on saving another resource. + if (pImpl->saveModule) { + Paint::rel(paint); + return Result::InsufficientCondition; + } + + if (auto saveModule = _find(filename)) { + if (saveModule->save(paint, pImpl->bg, filename, quality)) { + pImpl->saveModule = saveModule; + return Result::Success; + } else { + Paint::rel(paint); + delete(saveModule); + return Result::Unknown; + } + } + Paint::rel(paint); + return Result::NonSupport; +} + + +Result Saver::background(Paint* paint) noexcept +{ + if (!paint) return Result::InvalidArguments; + + if (pImpl->bg) pImpl->bg->unref(); + paint->ref(); + pImpl->bg = paint; + + return Result::Success; +} + + +Result Saver::save(Animation* animation, const char* filename, uint32_t quality, uint32_t fps) noexcept +{ + if (!animation) return Result::InvalidArguments; + + //animation holds the picture, it must be 1 at the bottom. + auto remove = animation->picture()->refCnt() <= 1 ? true : false; + + if (tvg::zero(animation->totalFrame())) { + if (remove) delete(animation); + return Result::InsufficientCondition; + } + + //Already on saving another resource. + if (pImpl->saveModule) { + if (remove) delete(animation); + return Result::InsufficientCondition; + } + + if (auto saveModule = _find(filename)) { + if (saveModule->save(animation, pImpl->bg, filename, quality, fps)) { + pImpl->saveModule = saveModule; + return Result::Success; + } else { + if (remove) delete(animation); + delete(saveModule); + return Result::Unknown; + } + } + if (remove) delete(animation); + return Result::NonSupport; +} + + +Result Saver::sync() noexcept +{ + if (!pImpl->saveModule) return Result::InsufficientCondition; + pImpl->saveModule->close(); + delete(pImpl->saveModule); + pImpl->saveModule = nullptr; + + return Result::Success; +} + + +Saver* Saver::gen() noexcept +{ + return new Saver; +} diff --git a/components/thorvg-main/src/renderer/tvgScene.cpp b/components/thorvg-main/src/renderer/tvgScene.cpp new file mode 100644 index 0000000..86acc11 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgScene.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgScene.h" + + +Scene::Scene() = default; + + +Scene* Scene::gen() noexcept +{ + return new SceneImpl; +} + + +Type Scene::type() const noexcept +{ + return Type::Scene; +} + + +Result Scene::add(Paint* target, Paint* at) noexcept +{ + return to(this)->insert(target, at); +} + + +Result Scene::remove(Paint* paint) noexcept +{ + if (paint) return to(this)->remove(paint); + else return to(this)->clearPaints(); +} + + +const list& Scene::paints() const noexcept +{ + return to(this)->paints; +} + + +Result Scene::add(SceneEffect effect, ...) noexcept +{ + va_list args; + va_start(args, effect); + auto ret = to(this)->add(effect, args); + va_end(args); + return ret; +} diff --git a/components/thorvg-main/src/renderer/tvgScene.h b/components/thorvg-main/src/renderer/tvgScene.h new file mode 100644 index 0000000..675d327 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgScene.h @@ -0,0 +1,449 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SCENE_H_ +#define _TVG_SCENE_H_ + +#include +#include "tvgMath.h" +#include "tvgPaint.h" + + +struct SceneIterator : Iterator +{ + list* paints; + list::iterator itr; + + SceneIterator(list* p) : paints(p) + { + begin(); + } + + const Paint* next() override + { + if (itr == paints->end()) return nullptr; + auto paint = *itr; + ++itr; + return paint; + } + + uint32_t count() override + { + return paints->size(); + } + + void begin() override + { + itr = paints->begin(); + } +}; + +struct SceneImpl : Scene +{ + Paint::Impl impl; + list paints; //children list + RenderRegion vport = {}; + Array* effects = nullptr; + Point fsize; //fixed scene size + bool fixed = false; //true: fixed scene size, false: dynamic size + bool vdirty = false; + uint8_t opacity; //for composition + + SceneImpl() : impl(Paint::Impl(this)) + { + } + + ~SceneImpl() + { + clearPaints(); + resetEffects(false); + } + + void size(const Point& size) + { + this->fsize = size; + fixed = (size.x > 0 && size.y > 0) ? true : false; + } + + uint8_t needComposition(uint8_t opacity) + { + if (opacity == 0 || paints.empty()) return 0; + + //post effects, masking, blending may require composition + if (effects) impl.mark(CompositionFlag::PostProcessing); + if (PAINT(this)->mask(nullptr) != MaskMethod::None) impl.mark(CompositionFlag::Masking); + if (impl.blendMethod != BlendMethod::Normal) impl.mark(CompositionFlag::Blending); + + //Half translucent requires intermediate composition. + if (opacity == 255) return impl.cmpFlag; + + //Only shape or picture may not require composition. + if (paints.size() == 1) { + auto type = paints.front()->type(); + if (type == Type::Shape || type == Type::Picture) return impl.cmpFlag; + } + + impl.mark(CompositionFlag::Opacity); + + return 1; + } + + bool skip(RenderUpdateFlag flag) + { + return false; + } + + bool update(RenderMethod* renderer, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flag, TVG_UNUSED bool clipper) + { + if (paints.empty()) return true; + + if (needComposition(opacity)) { + /* Overriding opacity value. If this scene is half-translucent, + It must do intermediate composition with that opacity value. */ + this->opacity = opacity; + opacity = 255; + } + + //allow partial rendering? + auto recover = fixed ? renderer->partial(true) : false; + + for (auto paint : paints) { + PAINT(paint)->update(renderer, transform, clips, opacity, flag, false); + } + + //recover the condition + if (fixed) renderer->partial(recover); + + if (effects) { + ARRAY_FOREACH(p, *effects) { + renderer->prepare(*p, transform); + } + } + + //this viewport update is more performant than in bounds(). No idea. + vport = renderer->viewport(); + + if (fixed) { + auto pt = fsize * transform; + vport.intersect({{int32_t(round(transform.e13)), int32_t(round(transform.e23))}, {int32_t(round(pt.x)), int32_t(round(pt.y))}}); + } else { + vdirty = true; + } + + //bounds(renderer) here hinders parallelization + //TODO: we can bring the precise effects region here + if (fixed || effects) impl.damage(vport); + + return true; + } + + bool render(RenderMethod* renderer) + { + if (paints.empty()) return true; + + RenderCompositor* cmp = nullptr; + auto ret = true; + + renderer->blend(impl.blendMethod); + + if (impl.cmpFlag) { + cmp = renderer->target(bounds(), renderer->colorSpace(), impl.cmpFlag); + renderer->beginComposite(cmp, MaskMethod::None, opacity); + } + + for (auto paint : paints) { + ret &= paint->pImpl->render(renderer); + } + + if (cmp) { + //Apply post effects if any. + if (effects) { + //Notify the possibility of the direct composition of the effect result to the origin surface. + auto direct = (effects->count == 1) & (impl.marked(CompositionFlag::PostProcessing)); + ARRAY_FOREACH(p, *effects) { + if ((*p)->valid) renderer->render(cmp, *p, direct); + } + } + renderer->endComposite(cmp); + } + + return ret; + } + + RenderRegion bounds() + { + if (paints.empty()) return {}; + if (!vdirty) return vport; + vdirty = false; + + //Merge regions + RenderRegion pRegion = {{INT32_MAX, INT32_MAX}, {0, 0}}; + for (auto paint : paints) { + auto region = paint->pImpl->bounds(); + if (region.min.x < pRegion.min.x) pRegion.min.x = region.min.x; + if (pRegion.max.x < region.max.x) pRegion.max.x = region.max.x; + if (region.min.y < pRegion.min.y) pRegion.min.y = region.min.y; + if (pRegion.max.y < region.max.y) pRegion.max.y = region.max.y; + } + + //Extends the render region if post effects require + RenderRegion eRegion{}; + if (effects) { + ARRAY_FOREACH(p, *effects) { + auto effect = *p; + if (effect->valid && impl.renderer->region(effect)) eRegion.add(effect->extend); + } + } + + pRegion.min.x += eRegion.min.x; + pRegion.min.y += eRegion.min.y; + pRegion.max.x += eRegion.max.x; + pRegion.max.y += eRegion.max.y; + + vport = RenderRegion::intersect(vport, pRegion); + return vport; + } + + bool bounds(Point* pt4, const Matrix& m, bool obb) + { + if (paints.empty()) return false; + + Point min = {FLT_MAX, FLT_MAX}; + Point max = {-FLT_MAX, -FLT_MAX}; + auto ret = false; + + for (auto paint : paints) { + Point tmp[4]; + if (!PAINT(paint)->bounds(tmp, obb ? nullptr : &m, false)) continue; + //Merge regions + for (int i = 0; i < 4; ++i) { + if (tmp[i].x < min.x) min.x = tmp[i].x; + if (tmp[i].x > max.x) max.x = tmp[i].x; + if (tmp[i].y < min.y) min.y = tmp[i].y; + if (tmp[i].y > max.y) max.y = tmp[i].y; + } + ret = true; + } + pt4[0] = min; + pt4[1] = Point{max.x, min.y}; + pt4[2] = max; + pt4[3] = Point{min.x, max.y}; + + if (obb) { + pt4[0] *= m; + pt4[1] *= m; + pt4[2] *= m; + pt4[3] *= m; + } + + return ret; + } + + + bool intersects(const RenderRegion& region) + { + if (!impl.renderer) return false; + + if (this->bounds().intersected(region)) { + for (auto paint : paints) { + if (PAINT(paint)->intersects(region)) return true; + } + } + + return false; + } + + Paint* duplicate(Paint* ret) + { + if (ret) TVGERR("RENDERER", "TODO: duplicate()"); + + auto scene = Scene::gen(); + auto dup = to(scene); + + for (auto paint : paints) { + auto cdup = paint->duplicate(); + PAINT(cdup)->parent = scene; + cdup->ref(); + dup->paints.push_back(cdup); + } + + if (effects) { + dup->effects = new Array; + ARRAY_FOREACH(p, *effects) { + RenderEffect* ret = nullptr; + switch ((*p)->type) { + case SceneEffect::GaussianBlur: { + ret = new RenderEffectGaussianBlur(*(RenderEffectGaussianBlur*)(*p)); + break; + } + case SceneEffect::DropShadow: { + ret = new RenderEffectDropShadow(*(RenderEffectDropShadow*)(*p)); + break; + } + case SceneEffect::Fill: { + ret = new RenderEffectFill(*(RenderEffectFill*)(*p)); + break; + } + case SceneEffect::Tint: { + ret = new RenderEffectTint(*(RenderEffectTint*)(*p)); + break; + } + case SceneEffect::Tritone: { + ret = new RenderEffectTritone(*(RenderEffectTritone*)(*p)); + break; + } + default: break; + } + if (ret) { + ret->rd = nullptr; + ret->valid = false; + dup->effects->push(ret); + } + } + } + + if (fixed) dup->size(fsize); + + return scene; + } + + Result clearPaints() + { + if (paints.empty()) return Result::Success; + + //Don't need to damage for children + auto recover = (fixed && impl.renderer) ? impl.renderer->partial(true) : false; + auto partialDmg = !(effects || fixed || recover); + + auto itr = paints.begin(); + while (itr != paints.end()) { + auto paint = PAINT((*itr)); + //when the paint is destroyed damage will be triggered + if (paint->refCnt > 1 && partialDmg) paint->damage(); + paint->unref(); + paints.erase(itr++); + } + if (fixed && impl.renderer) impl.renderer->partial(recover); + if (effects || fixed) impl.damage(vport); //redraw scene full region + + return Result::Success; + } + + Result remove(Paint* paint) + { + if (PAINT(paint)->parent != this) return Result::InsufficientCondition; + //when the paint is destroyed damage will be triggered + if (PAINT(paint)->refCnt > 1) PAINT(paint)->damage(); + PAINT(paint)->unref(); + paints.remove(paint); + return Result::Success; + } + + Result insert(Paint* target, Paint* at) + { + if (!target) return Result::InvalidArguments; + auto timpl = PAINT(target); + + if (timpl->parent) { + TVGERR("RENDERER", "Target paint(%p) is already owned by a parent(%p)", target, timpl->parent); + return Result::InsufficientCondition; + } + + target->ref(); + + //Relocated the paint to the current scene space + timpl->mark(RenderUpdateFlag::Transform); + + if (!at) { + paints.push_back(target); + } else { + //OPTIMIZE: Remove searching? + auto itr = find_if(paints.begin(), paints.end(),[&at](const Paint* paint){ return at == paint; }); + if (itr == paints.end()) return Result::InvalidArguments; + paints.insert(itr, target); + } + timpl->parent = this; + if (timpl->clipper) PAINT(timpl->clipper)->parent = this; + if (timpl->maskData) PAINT(timpl->maskData->target)->parent = this; + return Result::Success; + } + + Iterator* iterator() + { + return new SceneIterator(&paints); + } + + Result resetEffects(bool damage = true) + { + if (effects) { + ARRAY_FOREACH(p, *effects) { + if (impl.renderer) impl.renderer->dispose(*p); + delete(*p); + } + delete(effects); + effects = nullptr; + if (damage) impl.damage(vport); + } + return Result::Success; + } + + Result add(SceneEffect effect, va_list& args) + { + if (effect == SceneEffect::Clear) return resetEffects(); + + if (!this->effects) this->effects = new Array; + + RenderEffect* re = nullptr; + + switch (effect) { + case SceneEffect::GaussianBlur: { + re = RenderEffectGaussianBlur::gen(args); + break; + } + case SceneEffect::DropShadow: { + re = RenderEffectDropShadow::gen(args); + break; + } + case SceneEffect::Fill: { + re = RenderEffectFill::gen(args); + break; + } + case SceneEffect::Tint: { + re = RenderEffectTint::gen(args); + break; + } + case SceneEffect::Tritone: { + re = RenderEffectTritone::gen(args); + break; + } + default: break; + } + + if (!re) return Result::InvalidArguments; + + this->effects->push(re); + + return Result::Success; + } +}; + +#endif //_TVG_SCENE_H_ diff --git a/components/thorvg-main/src/renderer/tvgShape.cpp b/components/thorvg-main/src/renderer/tvgShape.cpp new file mode 100644 index 0000000..77db092 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgShape.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgMath.h" +#include "tvgShape.h" + + +Shape :: Shape() = default; + + +Shape* Shape::gen() noexcept +{ + return new ShapeImpl; +} + + +Type Shape::type() const noexcept +{ + return Type::Shape; +} + + +Result Shape::reset() noexcept +{ + to(this)->resetPath(); + return Result::Success; +} + + +Result Shape::path(const PathCommand** cmds, uint32_t* cmdsCnt, const Point** pts, uint32_t* ptsCnt) const noexcept +{ + if (cmds) *cmds = to(this)->rs.path.cmds.data; + if (cmdsCnt) *cmdsCnt = to(this)->rs.path.cmds.count; + + if (pts) *pts = to(this)->rs.path.pts.data; + if (ptsCnt) *ptsCnt = to(this)->rs.path.pts.count; + + return Result::Success; +} + + +Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept +{ + return to(this)->appendPath(cmds, cmdCnt, pts, ptsCnt); +} + + +Result Shape::moveTo(float x, float y) noexcept +{ + to(this)->rs.path.moveTo({x, y}); + return Result::Success; +} + + +Result Shape::lineTo(float x, float y) noexcept +{ + to(this)->rs.path.lineTo({x, y}); + to(this)->impl.mark(RenderUpdateFlag::Path); + return Result::Success; +} + + +Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept +{ + to(this)->rs.path.cubicTo({cx1, cy1}, {cx2, cy2}, {x, y}); + to(this)->impl.mark(RenderUpdateFlag::Path); + return Result::Success; +} + + +Result Shape::close() noexcept +{ + to(this)->rs.path.close(); + to(this)->impl.mark(RenderUpdateFlag::Path); + return Result::Success; +} + + +Result Shape::appendCircle(float cx, float cy, float rx, float ry, bool cw) noexcept +{ + to(this)->appendCircle(cx, cy, rx, ry, cw); + return Result::Success; +} + + +Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry, bool cw) noexcept +{ + to(this)->appendRect(x, y, w, h, rx, ry, cw); + return Result::Success; +} + + +Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept +{ + to(this)->fill(r, g, b, a); + return Result::Success; +} + + +Result Shape::fill(Fill* f) noexcept +{ + return to(this)->fill(f); +} + + +Result Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept +{ + to(this)->rs.fillColor(r, g, b, a); + return Result::Success; +} + + +const Fill* Shape::fill() const noexcept +{ + return to(this)->rs.fill; +} + + +Result Shape::order(bool strokeFirst) noexcept +{ + to(this)->strokeFirst(strokeFirst); + return Result::Success; +} + + +Result Shape::strokeWidth(float width) noexcept +{ + if (width < 0.0f) width = 0.0f; + to(this)->strokeWidth(width); + return Result::Success; +} + + +float Shape::strokeWidth() const noexcept +{ + return to(this)->rs.strokeWidth(); +} + + +Result Shape::strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept +{ + to(this)->strokeFill(r, g, b, a); + return Result::Success; +} + + +Result Shape::strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept +{ + if (!to(this)->rs.strokeFill(r, g, b, a)) return Result::InsufficientCondition; + return Result::Success; +} + + +Result Shape::strokeFill(Fill* f) noexcept +{ + return to(this)->strokeFill(f); +} + + +const Fill* Shape::strokeFill() const noexcept +{ + return to(this)->rs.strokeFill(); +} + + +Result Shape::strokeDash(const float* dashPattern, uint32_t cnt, float offset) noexcept +{ + return to(this)->strokeDash(dashPattern, cnt, offset); +} + + +uint32_t Shape::strokeDash(const float** dashPattern, float* offset) const noexcept +{ + return to(this)->rs.strokeDash(dashPattern, offset); +} + + +Result Shape::strokeCap(StrokeCap cap) noexcept +{ + to(this)->strokeCap(cap); + return Result::Success; +} + + +Result Shape::strokeJoin(StrokeJoin join) noexcept +{ + to(this)->strokeJoin(join); + return Result::Success; +} + + +Result Shape::strokeMiterlimit(float miterlimit) noexcept +{ + return to(this)->strokeMiterlimit(miterlimit); +} + + +StrokeCap Shape::strokeCap() const noexcept +{ + return to(this)->rs.strokeCap(); +} + + +StrokeJoin Shape::strokeJoin() const noexcept +{ + return to(this)->rs.strokeJoin(); +} + + +float Shape::strokeMiterlimit() const noexcept +{ + return to(this)->rs.strokeMiterlimit(); +} + + +Result Shape::trimpath(float begin, float end, bool simultaneous) noexcept +{ + to(this)->trimpath({begin, end, simultaneous}); + return Result::Success; +} + + +Result Shape::fillRule(FillRule r) noexcept +{ + to(this)->rs.rule = r; + return Result::Success; +} + + +FillRule Shape::fillRule() const noexcept +{ + return to(this)->rs.rule; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgShape.h b/components/thorvg-main/src/renderer/tvgShape.h new file mode 100644 index 0000000..725bcfa --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgShape.h @@ -0,0 +1,523 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_SHAPE_H_ +#define _TVG_SHAPE_H_ + +#include "tvgCommon.h" +#include "tvgMath.h" +#include "tvgPaint.h" + +namespace tvg +{ + +struct ShapeImpl : Shape +{ + Paint::Impl impl; + RenderShape rs; + uint8_t opacity; //for composition + + ShapeImpl() : impl(Paint::Impl(this)) + { + } + + bool render(RenderMethod* renderer) + { + if (!impl.rd) return false; + + RenderCompositor* cmp = nullptr; + + renderer->blend(impl.blendMethod); + + if (impl.cmpFlag) { + cmp = renderer->target(bounds(), renderer->colorSpace(), impl.cmpFlag); + renderer->beginComposite(cmp, MaskMethod::None, opacity); + } + + auto ret = renderer->renderShape(impl.rd); + if (cmp) renderer->endComposite(cmp); + return ret; + } + + bool needComposition(uint8_t opacity) + { + if (opacity == 0) return false; + + //Shape composition is only necessary when stroking & fill are valid. + if (!rs.stroke || rs.stroke->width < FLOAT_EPSILON || (!rs.stroke->fill && rs.stroke->color.a == 0)) return false; + if (!rs.fill && rs.color.a == 0) return false; + + //translucent fill & stroke + if (opacity < 255) { + impl.mark(CompositionFlag::Opacity); + return true; + } + + //Composition test + const Paint* target; + auto method = PAINT(this)->mask(&target); + if (!target) return false; + + if ((target->pImpl->opacity == 255 || target->pImpl->opacity == 0) && target->type() == tvg::Type::Shape) { + auto shape = static_cast(target); + if (!shape->fill()) { + uint8_t r, g, b, a; + shape->fill(&r, &g, &b, &a); + if (a == 0 || a == 255) { + if (method == MaskMethod::Luma || method == MaskMethod::InvLuma) { + if ((r == 255 && g == 255 && b == 255) || (r == 0 && g == 0 && b == 0)) return false; + } else return false; + } + } + } + + impl.mark(CompositionFlag::Masking); + return true; + } + + bool skip(RenderUpdateFlag flag) + { + if (flag == RenderUpdateFlag::None) return true; + return false; + } + + bool update(RenderMethod* renderer, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flag, bool clipper) + { + if (needComposition(opacity)) { + /* Overriding opacity value. If this scene is half-translucent, + It must do intermediate composition with that opacity value. */ + this->opacity = opacity; + opacity = 255; + } + + impl.rd = renderer->prepare(rs, impl.rd, transform, clips, opacity, flag, clipper); + return true; + } + + RenderRegion bounds() + { + return impl.renderer->region(impl.rd); + } + + bool bounds(Point* pt4, const Matrix& m, bool obb) + { + auto fallback = true; //TODO: remove this when all backend engines support bounds() + + if (impl.renderer && rs.strokeWidth() > 0.0f) { + if (impl.renderer->bounds(impl.rd, pt4, obb ? tvg::identity() : m)) { + fallback = false; + } + } + //Keep this for legacy. loaders still depend on this logic, remove it if possible. + if (fallback) { + BBox box = {{FLT_MAX, FLT_MAX}, {-FLT_MAX, -FLT_MAX}}; + if (!rs.path.bounds(obb ? nullptr : &m, box)) return false; + if (rs.stroke) { + //Use geometric mean for feathering. + //Join, Cap wouldn't be considered. Generate stroke outline and compute bbox for accurate size? + auto sx = sqrt(m.e11 * m.e11 + m.e21 * m.e21); + auto sy = sqrt(m.e12 * m.e12 + m.e22 * m.e22); + auto feather = rs.stroke->width * sqrt(sx * sy); + box.min.x -= feather * 0.5f; + box.min.y -= feather * 0.5f; + box.max.x += feather * 0.5f; + box.max.y += feather * 0.5f; + } + pt4[0] = box.min; + pt4[1] = {box.max.x, box.min.y}; + pt4[2] = box.max; + pt4[3] = {box.min.x, box.max.y}; + } + + if (obb) { + pt4[0] *= m; + pt4[1] *= m; + pt4[2] *= m; + pt4[3] *= m; + } + + return true; + } + + void reserveCmd(uint32_t cmdCnt) + { + rs.path.cmds.reserve(cmdCnt); + } + + void reservePts(uint32_t ptsCnt) + { + rs.path.pts.reserve(ptsCnt); + } + + void grow(uint32_t cmdCnt, uint32_t ptsCnt) + { + rs.path.cmds.grow(cmdCnt); + rs.path.pts.grow(ptsCnt); + } + + void append(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) + { + memcpy(rs.path.cmds.end(), cmds, sizeof(PathCommand) * cmdCnt); + memcpy(rs.path.pts.end(), pts, sizeof(Point) * ptsCnt); + rs.path.cmds.count += cmdCnt; + rs.path.pts.count += ptsCnt; + } + + void strokeWidth(float width) + { + if (!rs.stroke) rs.stroke = new RenderStroke(); + rs.stroke->width = width; + impl.mark(RenderUpdateFlag::Stroke); + } + + void trimpath(const RenderTrimPath& trim) + { + if (!rs.stroke) { + if (trim.begin == 0.0f && trim.end == 1.0f) return; + rs.stroke = new RenderStroke(); + } + + if (tvg::equal(rs.stroke->trim.begin, trim.begin) && tvg::equal(rs.stroke->trim.end, trim.end) && rs.stroke->trim.simultaneous == trim.simultaneous) return; + + rs.stroke->trim = trim; + impl.mark(RenderUpdateFlag::Path); + } + + bool trimpath(float* begin, float* end) + { + if (rs.stroke) { + if (begin) *begin = rs.stroke->trim.begin; + if (end) *end = rs.stroke->trim.end; + return rs.stroke->trim.simultaneous; + } else { + if (begin) *begin = 0.0f; + if (end) *end = 1.0f; + return false; + } + } + + void strokeCap(StrokeCap cap) + { + if (!rs.stroke) rs.stroke = new RenderStroke(); + rs.stroke->cap = cap; + impl.mark(RenderUpdateFlag::Stroke); + } + + void strokeJoin(StrokeJoin join) + { + if (!rs.stroke) rs.stroke = new RenderStroke(); + rs.stroke->join = join; + impl.mark(RenderUpdateFlag::Stroke); + } + + Result strokeMiterlimit(float miterlimit) + { + // https://www.w3.org/TR/SVG2/painting.html#LineJoin + // - A negative value for stroke-miterlimit must be treated as an illegal value. + if (miterlimit < 0.0f) return Result::InvalidArguments; + if (!rs.stroke) rs.stroke = new RenderStroke(); + rs.stroke->miterlimit = miterlimit; + impl.mark(RenderUpdateFlag::Stroke); + + return Result::Success; + } + + bool intersects(const RenderRegion& region) + { + if (!impl.rd || !impl.renderer) return false; + return impl.renderer->intersectsShape(impl.rd, region); + } + + void strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + { + if (!rs.stroke) rs.stroke = new RenderStroke(); + if (rs.stroke->fill) { + delete(rs.stroke->fill); + rs.stroke->fill = nullptr; + impl.mark(RenderUpdateFlag::GradientStroke); + } + + rs.stroke->color = {r, g, b, a}; + + impl.mark(RenderUpdateFlag::Stroke); + } + + Result strokeFill(Fill* f) + { + if (!f) return Result::InvalidArguments; + + if (!rs.stroke) rs.stroke = new RenderStroke(); + if (rs.stroke->fill && rs.stroke->fill != f) delete(rs.stroke->fill); + rs.stroke->fill = f; + rs.stroke->color.a = 0; + + impl.mark(RenderUpdateFlag::Stroke | RenderUpdateFlag::GradientStroke); + + return Result::Success; + } + + Result strokeDash(const float* pattern, uint32_t cnt, float offset) + { + if ((!pattern && cnt > 0) || (pattern && cnt == 0)) return Result::InvalidArguments; + if (!rs.stroke) rs.stroke = new RenderStroke; + //Reset dash + auto& dash = rs.stroke->dash; + if (dash.count != cnt) { + tvg::free(dash.pattern); + dash.pattern = nullptr; + } + if (cnt > 0) { + if (!dash.pattern) dash.pattern = tvg::malloc(sizeof(float) * cnt); + dash.length = 0.0f; + for (uint32_t i = 0; i < cnt; ++i) { + dash.pattern[i] = pattern[i] < 0.0f ? 0.0f : pattern[i]; + dash.length += dash.pattern[i]; + } + } + rs.stroke->dash.count = cnt; + rs.stroke->dash.offset = offset; + impl.mark(RenderUpdateFlag::Stroke); + + return Result::Success; + } + + bool strokeFirst() + { + if (!rs.stroke) return true; + return rs.stroke->first; + } + + void strokeFirst(bool first) + { + if (!rs.stroke) rs.stroke = new RenderStroke(); + rs.stroke->first = first; + impl.mark(RenderUpdateFlag::Stroke); + } + + Result fill(Fill* f) + { + if (!f) return Result::InvalidArguments; + + if (rs.fill && rs.fill != f) delete(rs.fill); + rs.fill = f; + impl.mark(RenderUpdateFlag::Gradient); + + return Result::Success; + } + + void fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + { + if (rs.fill) { + delete(rs.fill); + rs.fill = nullptr; + impl.mark(RenderUpdateFlag::Gradient); + } + + if (r == rs.color.r && g == rs.color.g && b == rs.color.b && a == rs.color.a) return; + + rs.color = {r, g, b, a}; + impl.mark(RenderUpdateFlag::Color); + } + + void resetPath() + { + rs.path.cmds.clear(); + rs.path.pts.clear(); + impl.mark(RenderUpdateFlag::Path); + } + + Result appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) + { + if (cmdCnt == 0 || ptsCnt == 0 || !cmds || !pts) return Result::InvalidArguments; + + grow(cmdCnt, ptsCnt); + append(cmds, cmdCnt, pts, ptsCnt); + impl.mark(RenderUpdateFlag::Path); + + return Result::Success; + } + + void appendCircle(float cx, float cy, float rx, float ry, bool cw) + { + auto rxKappa = rx * PATH_KAPPA; + auto ryKappa = ry * PATH_KAPPA; + + rs.path.cmds.grow(6); + auto cmds = rs.path.cmds.end(); + + cmds[0] = PathCommand::MoveTo; + cmds[1] = PathCommand::CubicTo; + cmds[2] = PathCommand::CubicTo; + cmds[3] = PathCommand::CubicTo; + cmds[4] = PathCommand::CubicTo; + cmds[5] = PathCommand::Close; + + rs.path.cmds.count += 6; + + int table[2][13] = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, {0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12}}; + int* idx = cw ? table[0] : table[1]; + + rs.path.pts.grow(13); + auto pts = rs.path.pts.end(); + + pts[idx[0]] = {cx, cy - ry}; //moveTo + pts[idx[1]] = {cx + rxKappa, cy - ry}; pts[idx[2]] = {cx + rx, cy - ryKappa}; pts[idx[3]] = {cx + rx, cy}; //cubicTo + pts[idx[4]] = {cx + rx, cy + ryKappa}; pts[idx[5]] = {cx + rxKappa, cy + ry}; pts[idx[6]] = {cx, cy + ry}; //cubicTo + pts[idx[7]] = {cx - rxKappa, cy + ry}; pts[idx[8]] = {cx - rx, cy + ryKappa}; pts[idx[9]] = {cx - rx, cy}; //cubicTo + pts[idx[10]] = {cx - rx, cy - ryKappa}; pts[idx[11]] = {cx - rxKappa, cy - ry}; pts[idx[12]] = {cx, cy - ry}; //cubicTo + + rs.path.pts.count += 13; + + impl.mark(RenderUpdateFlag::Path); + } + + void appendRect(float x, float y, float w, float h, float rx, float ry, bool cw) + { + //sharp rect + if (tvg::zero(rx) && tvg::zero(ry)) { + rs.path.cmds.grow(5); + rs.path.pts.grow(4); + + auto cmds = rs.path.cmds.end(); + auto pts = rs.path.pts.end(); + + cmds[0] = PathCommand::MoveTo; + cmds[1] = cmds[2] = cmds[3] = PathCommand::LineTo; + cmds[4] = PathCommand::Close; + + pts[0] = {x + w, y}; + pts[2] = {x, y + h}; + if (cw) { + pts[1] = {x + w, y + h}; + pts[3] = {x, y}; + } else { + pts[1] = {x, y}; + pts[3] = {x + w, y + h}; + } + + rs.path.cmds.count += 5; + rs.path.pts.count += 4; + //round rect + } else { + auto hsize = Point{w * 0.5f, h * 0.5f}; + rx = (rx > hsize.x) ? hsize.x : rx; + ry = (ry > hsize.y) ? hsize.y : ry; + auto hr = Point{rx * PATH_KAPPA, ry * PATH_KAPPA}; + + rs.path.cmds.grow(10); + rs.path.pts.grow(17); + + auto cmds = rs.path.cmds.end(); + auto pts = rs.path.pts.end(); + + cmds[0] = PathCommand::MoveTo; + cmds[9] = PathCommand::Close; + pts[0] = {x + w, y + ry}; //move + + if (cw) { + cmds[1] = cmds[3] = cmds[5] = cmds[7] = PathCommand::LineTo; + cmds[2] = cmds[4] = cmds[6] = cmds[8] = PathCommand::CubicTo; + + pts[1] = {x + w, y + h - ry}; //line + pts[2] = {x + w, y + h - ry + hr.y}; pts[3] = {x + w - rx + hr.x, y + h}; pts[4] = {x + w - rx, y + h}; //cubic + pts[5] = {x + rx, y + h}, //line + pts[6] = {x + rx - hr.x, y + h}; pts[7] = {x, y + h - ry + hr.y}; pts[8] = {x, y + h - ry}; //cubic + pts[9] = {x, y + ry}, //line + pts[10] = {x, y + ry - hr.y}; pts[11] = {x + rx - hr.x, y}; pts[12] = {x + rx, y}; //cubic + pts[13] = {x + w - rx, y}; //line + pts[14] = {x + w - rx + hr.x, y}; pts[15] = {x + w, y + ry - hr.y}; pts[16] = {x + w, y + ry}; //cubic + } else { + cmds[1] = cmds[3] = cmds[5] = cmds[7] = PathCommand::CubicTo; + cmds[2] = cmds[4] = cmds[6] = cmds[8] = PathCommand::LineTo; + + pts[1] = {x + w, y + ry - hr.y}; pts[2] = {x + w - rx + hr.x, y}; pts[3] = {x + w - rx, y}; //cubic + pts[4] = {x + rx, y}; //line + pts[5] = {x + rx - hr.x, y}; pts[6] = {x, y + ry - hr.y}; pts[7] = {x, y + ry}; //cubic + pts[8] = {x, y + h - ry}; //line + pts[9] = {x, y + h - ry + hr.y}; pts[10] = {x + rx - hr.x, y + h}; pts[11] = {x + rx, y + h}; //cubic + pts[12] = {x + w - rx, y + h}; //line + pts[13] = {x + w - rx + hr.x, y + h}; pts[14] = {x + w, y + h - ry + hr.y}; pts[15] = {x + w, y + h - ry}; //cubic + pts[16] = {x + w, y + ry}; //line + } + + rs.path.cmds.count += 10; + rs.path.pts.count += 17; + } + impl.mark(RenderUpdateFlag::Path); + } + + Paint* duplicate(Paint* ret) + { + auto shape = static_cast(ret); + if (!shape) shape = Shape::gen(); + auto dup = to(shape); + + //Path + dup->rs.path.clear(); + dup->rs.path.cmds.push(rs.path.cmds); + dup->rs.path.pts.push(rs.path.pts); + + //Fill + delete(dup->rs.fill); + if (rs.fill) dup->rs.fill = rs.fill->duplicate(); + else dup->rs.fill = nullptr; + + //Stroke + if (rs.stroke) { + if (!dup->rs.stroke) dup->rs.stroke = new RenderStroke; + *dup->rs.stroke = *rs.stroke; + } else { + delete(dup->rs.stroke); + dup->rs.stroke = nullptr; + } + + dup->rs.color = rs.color; + dup->rs.rule = rs.rule; + + return shape; + } + + void reset() + { + PAINT(this)->reset(); + rs.path.cmds.clear(); + rs.path.pts.clear(); + + rs.color.a = 0; + rs.rule = FillRule::NonZero; + + delete(rs.stroke); + rs.stroke = nullptr; + + delete(rs.fill); + rs.fill = nullptr; + } + + Iterator* iterator() + { + return nullptr; + } +}; + +} + +#endif //_TVG_SHAPE_H_ diff --git a/components/thorvg-main/src/renderer/tvgTaskScheduler.cpp b/components/thorvg-main/src/renderer/tvgTaskScheduler.cpp new file mode 100644 index 0000000..5ea408b --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgTaskScheduler.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "tvgArray.h" +#include "tvgInlist.h" +#include "tvgTaskScheduler.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +namespace tvg { + +#ifdef THORVG_THREAD_SUPPORT + +struct TaskQueue { + Inlist taskDeque; + mutex mtx; + condition_variable ready; + bool done = false; + + bool tryPop(Task** task) + { + unique_lock lock{mtx, try_to_lock}; + if (!lock || taskDeque.empty()) return false; + *task = taskDeque.front(); + return true; + } + + bool tryPush(Task* task) + { + { + unique_lock lock{mtx, try_to_lock}; + if (!lock) return false; + taskDeque.back(task); + } + ready.notify_one(); + return true; + } + + void complete() + { + { + lock_guard lock{mtx}; + done = true; + } + ready.notify_all(); + } + + bool pop(Task** task) + { + unique_lock lock{mtx}; + + while (taskDeque.empty() && !done) { + ready.wait(lock); + } + + if (taskDeque.empty()) return false; + + *task = taskDeque.front(); + return true; + } + + void push(Task* task) + { + { + lock_guard lock{mtx}; + taskDeque.back(task); + } + ready.notify_one(); + } +}; + + +struct TaskSchedulerImpl +{ + Array threads; + Array taskQueues; + atomic idx{0}; + + TaskSchedulerImpl(uint32_t threadCnt) + { + threads.reserve(threadCnt); + taskQueues.reserve(threadCnt); + + for (uint32_t i = 0; i < threadCnt; ++i) { + taskQueues.push(new TaskQueue); + threads.push(new thread); + } + for (uint32_t i = 0; i < threadCnt; ++i) { + *threads.data[i] = thread([&, i] { run(i); }); + } + } + + ~TaskSchedulerImpl() + { + ARRAY_FOREACH(p, taskQueues) { + (*p)->complete(); + } + ARRAY_FOREACH(p, threads) { + (*p)->join(); + delete(*p); + } + ARRAY_FOREACH(p, taskQueues) { + delete(*p); + } + } + + void run(unsigned i) + { + Task* task; + + //Thread Loop + while (true) { + auto success = false; + for (uint32_t x = 0; x < threads.count * 2; ++x) { + if (taskQueues[(i + x) % threads.count]->tryPop(&task)) { + success = true; + break; + } + } + + if (!success && !taskQueues[i]->pop(&task)) break; + (*task)(i + 1); + } + } + + void request(Task* task) + { + //Async + if (threads.count > 0) { + task->prepare(); + auto i = idx++; + for (uint32_t n = 0; n < threads.count; ++n) { + if (taskQueues[(i + n) % threads.count]->tryPush(task)) return; + } + taskQueues[i % threads.count]->push(task); + //Sync + } else { + task->run(0); + } + } + + uint32_t threadCnt() + { + return threads.count; + } +}; + +#else //THORVG_THREAD_SUPPORT + +struct TaskSchedulerImpl +{ + TaskSchedulerImpl(TVG_UNUSED uint32_t threadCnt) {} + void request(Task* task) { task->run(0); } + uint32_t threadCnt() { return 0; } +}; + +#endif //THORVG_THREAD_SUPPORT + + +} //namespace + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +static TaskSchedulerImpl* _inst = nullptr; +static ThreadID _tid; //dominant thread id + +void TaskScheduler::init(uint32_t threads) +{ + if (_inst) return; + _inst = new TaskSchedulerImpl(threads); + _tid = tid(); +} + + +void TaskScheduler::term() +{ + delete(_inst); + _inst = nullptr; +} + + +void TaskScheduler::request(Task* task) +{ + if (_inst) _inst->request(task); +} + + +uint32_t TaskScheduler::threads() +{ + return _inst ? _inst->threadCnt() : 0; +} + + +bool TaskScheduler::onthread() +{ + return _tid != tid(); +} + + +ThreadID TaskScheduler::tid() +{ +#ifdef THORVG_THREAD_SUPPORT + return std::this_thread::get_id(); +#else + return 0; +#endif +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgTaskScheduler.h b/components/thorvg-main/src/renderer/tvgTaskScheduler.h new file mode 100644 index 0000000..4a3b4e8 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgTaskScheduler.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_TASK_SCHEDULER_H_ +#define _TVG_TASK_SCHEDULER_H_ + +#include "tvgCommon.h" +#include "tvgInlist.h" + +#ifdef THORVG_THREAD_SUPPORT + #include + #include + #include + #include +#endif + +namespace tvg { + + +#ifdef THORVG_THREAD_SUPPORT + +using ThreadID = std::thread::id; + +struct Task +{ +private: + mutex mtx; + condition_variable cv; + bool ready = true; + bool pending = false; + +public: + INLIST_ITEM(Task); + + virtual ~Task() = default; + + void done() + { + if (!pending) return; + + unique_lock lock(mtx); + while (!ready) cv.wait(lock); + pending = false; + } + +protected: + virtual void run(unsigned tid) = 0; + +private: + void operator()(unsigned tid) + { + run(tid); + + lock_guard lock(mtx); + ready = true; + cv.notify_one(); + } + + void prepare() + { + ready = false; + pending = true; + } + + friend struct TaskSchedulerImpl; +}; + +#else //THORVG_THREAD_SUPPORT + +using ThreadID = uint8_t; + +struct Task +{ +public: + INLIST_ITEM(Task); + + virtual ~Task() = default; + void done() {} + +protected: + virtual void run(unsigned tid) = 0; + +private: + friend struct TaskSchedulerImpl; +}; + +#endif //THORVG_THREAD_SUPPORT + + +struct TaskScheduler +{ + static uint32_t threads(); + static void init(uint32_t threads); + static void term(); + static void request(Task* task); + static bool onthread(); //figure out whether on worker thread or not + static ThreadID tid(); +}; + +} //namespace + +#endif //_TVG_TASK_SCHEDULER_H_ + \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/tvgText.cpp b/components/thorvg-main/src/renderer/tvgText.cpp new file mode 100644 index 0000000..eac9629 --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgText.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include "tvgText.h" + + +Text::Text() = default; + + +Result Text::text(const char* text) noexcept +{ + return to(this)->text(text); +} + + +Result Text::font(const char* name) noexcept +{ + return to(this)->font(name); +} + + +Result Text::size(float size) noexcept +{ + return to(this)->size(size); +} + + +Result Text::load(const char* filename) noexcept +{ +#ifdef THORVG_FILE_IO_SUPPORT + bool invalid; //invalid path + auto loader = LoaderMgr::loader(filename, &invalid); + if (loader) { + if (loader->sharing > 0) --loader->sharing; //font loading doesn't mean sharing. + return Result::Success; + } else { + if (invalid) return Result::InvalidArguments; + else return Result::NonSupport; + } +#else + TVGLOG("RENDERER", "FILE IO is disabled!"); + return Result::NonSupport; +#endif +} + + +Result Text::load(const char* name, const char* data, uint32_t size, const char* mimeType, bool copy) noexcept +{ + if (!name || (size == 0 && data)) return Result::InvalidArguments; + + //unload font + if (!data) { + if (LoaderMgr::retrieve(LoaderMgr::font(name))) return Result::Success; + return Result::InsufficientCondition; + } + + if (!LoaderMgr::loader(name, data, size, mimeType, copy)) return Result::NonSupport; + return Result::Success; +} + + +Result Text::unload(const char* filename) noexcept +{ +#ifdef THORVG_FILE_IO_SUPPORT + if (LoaderMgr::retrieve(filename)) return Result::Success; + return Result::InsufficientCondition; +#else + TVGLOG("RENDERER", "FILE IO is disabled!"); + return Result::NonSupport; +#endif +} + + +Result Text::align(float x, float y) noexcept +{ + to(this)->fm.align = {x, y}; + PAINT(this)->mark(RenderUpdateFlag::Transform); + return Result::Success; +} + + +Result Text::layout(float w, float h) noexcept +{ + to(this)->layout(w, h); + return Result::Success; +} + + +Result Text::fill(uint8_t r, uint8_t g, uint8_t b) noexcept +{ + return to(this)->shape->fill(r, g, b); +} + + +Result Text::outline(float width, uint8_t r, uint8_t g, uint8_t b) noexcept +{ + to(this)->outlineWidth = width; + to(this)->shape->strokeFill(r, g, b); + PAINT(this)->mark(RenderUpdateFlag::Stroke); + return Result::Success; +} + + +Result Text::fill(Fill* f) noexcept +{ + return to(this)->shape->fill(f); +} + + +Result Text::italic(float shear) noexcept +{ + if (shear < 0.0f) shear = 0.0f; + else if (shear > 0.5f) shear = 0.5f; + to(this)->italicShear = shear; + to(this)->updated = true; + return Result::Success; +} + + +Result Text::spacing(float letter, float line) noexcept +{ + return to(this)->spacing(letter, line); +} + + +Result Text::wrap(TextWrap mode) noexcept +{ + to(this)->wrapping(mode); + return Result::Success; +} + + +Text* Text::gen() noexcept +{ + return new TextImpl; +} + + +Type Text::type() const noexcept +{ + return Type::Text; +} diff --git a/components/thorvg-main/src/renderer/tvgText.h b/components/thorvg-main/src/renderer/tvgText.h new file mode 100644 index 0000000..1af5f3e --- /dev/null +++ b/components/thorvg-main/src/renderer/tvgText.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_TEXT_H +#define _TVG_TEXT_H + +#include "tvgStr.h" +#include "tvgMath.h" +#include "tvgShape.h" +#include "tvgFill.h" +#include "tvgLoader.h" + +namespace tvg +{ + +struct TextImpl : Text +{ + Paint::Impl impl; + Shape* shape; //text shape + FontLoader* loader = nullptr; + FontMetrics fm; + char* utf8 = nullptr; + float outlineWidth = 0.0f; + float italicShear = 0.0f; + bool updated = false; + + TextImpl() : impl(Paint::Impl(this)), shape(Shape::gen()) + { + PAINT(shape)->parent = this; + shape->strokeJoin(StrokeJoin::Round); + } + + ~TextImpl() + { + tvg::free(utf8); + if (loader) { + loader->release(fm); + LoaderMgr::retrieve(loader); + } + Paint::rel(shape); + } + + Result text(const char* utf8) + { + tvg::free(this->utf8); + if (utf8) this->utf8 = tvg::duplicate(utf8); + else this->utf8 = nullptr; + updated = true; + impl.mark(RenderUpdateFlag::Path); + + return Result::Success; + } + + Result font(const char* name) + { + auto loader = static_cast(name ? LoaderMgr::font(name) : LoaderMgr::anyfont()); + if (!loader) return Result::InsufficientCondition; + + //Same resource has been loaded. + if (this->loader == loader) { + this->loader->sharing--; //make it sure the reference counting. + return Result::Success; + } else if (this->loader) { + this->loader->release(fm); + LoaderMgr::retrieve(this->loader); + } + this->loader = loader; + updated = true; + + return Result::Success; + } + + Result size(float fontSize) + { + if (fontSize > 0.0f) { + if (fm.fontSize != fontSize) { + fm.fontSize = fontSize; + updated = true; + } + return Result::Success; + } + return Result::InvalidArguments; + } + + RenderRegion bounds() + { + if (!load()) return {}; + return to(shape)->bounds(); + } + + bool render(RenderMethod* renderer) + { + if (!loader || !fm.engine) return true; + renderer->blend(impl.blendMethod); + return PAINT(shape)->render(renderer); + } + + bool load() + { + if (!loader) return false; + if (updated) { + if (loader->get(fm, utf8, to(shape)->rs.path)) { + loader->transform(shape, fm, italicShear); + } + updated = false; + } + return true; + } + + bool skip(RenderUpdateFlag flag) + { + if (flag == RenderUpdateFlag::None) return true; + return false; + } + + void wrapping(TextWrap mode) + { + if (fm.wrap == mode) return; + fm.wrap = mode; + updated = true; + impl.mark(RenderUpdateFlag::Path); + } + + void layout(float w, float h) + { + fm.box = {w, h}; + updated = true; + } + + Result spacing(float letter, float line) + { + if (letter < 0.0f || line < 0.0f) return Result::InvalidArguments; + + fm.spacing = {letter, line}; + updated = true; + + return Result::Success; + } + + bool update(RenderMethod* renderer, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flag, TVG_UNUSED bool clipper) + { + if (!load()) return true; + + auto scale = fm.scale; + + //transform the gradient coordinates based on the final scaled font. + auto fill = to(shape)->rs.fill; + if (fill && to(shape)->impl.marked(RenderUpdateFlag::Gradient)) { + if (fill->type() == Type::LinearGradient) { + LINEAR(fill)->p1 *= scale; + LINEAR(fill)->p2 *= scale; + } else { + RADIAL(fill)->center *= scale; + RADIAL(fill)->r *= scale; + RADIAL(fill)->focal *= scale; + RADIAL(fill)->fr *= scale; + } + } + + if (outlineWidth > 0.0f && impl.marked(RenderUpdateFlag::Stroke)) shape->strokeWidth(outlineWidth * scale); + + PAINT(shape)->update(renderer, transform, clips, opacity, flag, false); + return true; + } + + bool intersects(const RenderRegion& region) + { + if (!load()) return false; + return to(shape)->intersects(region); + } + + bool bounds(Point* pt4, const Matrix& m, bool obb) + { + if (!load()) return true; + return PAINT(shape)->bounds(pt4, &const_cast(m), obb); + } + + Paint* duplicate(Paint* ret) + { + if (ret) TVGERR("RENDERER", "TODO: duplicate()"); + + load(); + + auto text = Text::gen(); + auto dup = to(text); + + to(shape)->duplicate(dup->shape); + + if (loader) { + dup->loader = loader; + ++dup->loader->sharing; + loader->copy(fm, dup->fm); + } + + dup->utf8 = tvg::duplicate(utf8); + dup->italicShear = italicShear; + dup->outlineWidth = outlineWidth; + dup->updated = true; + + return text; + } + + Iterator* iterator() + { + return nullptr; + } +}; + +} + +#endif //_TVG_TEXT_H diff --git a/components/thorvg-main/src/renderer/wg_engine/meson.build b/components/thorvg-main/src/renderer/wg_engine/meson.build new file mode 100644 index 0000000..e5aa2f2 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/meson.build @@ -0,0 +1,37 @@ +source_file = [ + 'tvgWgBindGroups.h', + 'tvgWgCommon.h', + 'tvgWgCompositor.h', + 'tvgWgGeometry.h', + 'tvgWgPipelines.h', + 'tvgWgRenderData.h', + 'tvgWgRenderer.h', + 'tvgWgRenderTarget.h', + 'tvgWgRenderTask.h', + 'tvgWgShaderSrc.h', + 'tvgWgShaderTypes.h', + 'tvgWgTessellator.h', + 'tvgWgBindGroups.cpp', + 'tvgWgCommon.cpp', + 'tvgWgCompositor.cpp', + 'tvgWgGeometry.cpp', + 'tvgWgPipelines.cpp', + 'tvgWgRenderData.cpp', + 'tvgWgRenderer.cpp', + 'tvgWgRenderTarget.cpp', + 'tvgWgRenderTask.cpp', + 'tvgWgShaderSrc.cpp', + 'tvgWgShaderTypes.cpp', + 'tvgWgTessellator.cpp' +] + +wgpu_dep = [] +if host_machine.system() != 'emscripten' + wgpu_dep = dependency('wgpu_native') +endif + +engine_dep += [declare_dependency( + dependencies : wgpu_dep, + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgBindGroups.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgBindGroups.cpp new file mode 100644 index 0000000..815e57b --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgBindGroups.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgBindGroups.h" +#include + +WGPUBindGroup WgBindGroupLayouts::createBindGroupTexSampled(WGPUSampler sampler, WGPUTextureView texView) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .sampler = sampler }, + { .binding = 1, .textureView = texView } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexSampled, .entryCount = 2, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupTexSampledBuff1Un(WGPUSampler sampler, WGPUTextureView texView, WGPUBuffer buff) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .sampler = sampler }, + { .binding = 1, .textureView = texView }, + { .binding = 2, .buffer = buff, .size = wgpuBufferGetSize(buff) } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexSampledBuff1Un, .entryCount = 3, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupTexSampledBuff2Un(WGPUSampler sampler, WGPUTextureView texView, WGPUBuffer buff0, WGPUBuffer buff1) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .sampler = sampler }, + { .binding = 1, .textureView = texView }, + { .binding = 2, .buffer = buff0, .size = wgpuBufferGetSize(buff0) }, + { .binding = 3, .buffer = buff1, .size = wgpuBufferGetSize(buff1) } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexSampledBuff2Un, .entryCount = 4, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupStrorage1WO(WGPUTextureView texView) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .textureView = texView } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexStrorage1WO, .entryCount = 1, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupStrorage1RO(WGPUTextureView texView) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .textureView = texView } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexStrorage1RO, .entryCount = 1, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupStrorage2RO(WGPUTextureView texView0, WGPUTextureView texView1) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .textureView = texView0 }, + { .binding = 1, .textureView = texView1 } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexStrorage2RO, .entryCount = 2, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupStrorage3RO(WGPUTextureView texView0, WGPUTextureView texView1, WGPUTextureView texView2) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .textureView = texView0 }, + { .binding = 1, .textureView = texView1 }, + { .binding = 2, .textureView = texView2 } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutTexStrorage3RO, .entryCount = 3, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupBuffer1Un(WGPUBuffer buff) +{ + return createBindGroupBuffer1Un(buff, 0, wgpuBufferGetSize(buff)); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupBuffer1Un(WGPUBuffer buff, uint64_t offset, uint64_t size) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .buffer = buff, .offset = offset, .size = size } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutBuffer1Un, .entryCount = 1, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupBuffer2Un(WGPUBuffer buff0, WGPUBuffer buff1) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .buffer = buff0, .size = wgpuBufferGetSize(buff0) }, + { .binding = 1, .buffer = buff1, .size = wgpuBufferGetSize(buff1) } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutBuffer2Un, .entryCount = 2, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +WGPUBindGroup WgBindGroupLayouts::createBindGroupBuffer3Un(WGPUBuffer buff0, WGPUBuffer buff1, WGPUBuffer buff2) +{ + const WGPUBindGroupEntry bindGroupEntrys[] = { + { .binding = 0, .buffer = buff0, .size = wgpuBufferGetSize(buff0) }, + { .binding = 1, .buffer = buff1, .size = wgpuBufferGetSize(buff1) }, + { .binding = 2, .buffer = buff2, .size = wgpuBufferGetSize(buff2) } + }; + const WGPUBindGroupDescriptor bindGroupDesc { .layout = layoutBuffer3Un, .entryCount = 3, .entries = bindGroupEntrys }; + return wgpuDeviceCreateBindGroup(device, &bindGroupDesc); +} + + +void WgBindGroupLayouts::releaseBindGroup(WGPUBindGroup& bindGroup) +{ + if (bindGroup) wgpuBindGroupRelease(bindGroup); + bindGroup = nullptr; +} + + +void WgBindGroupLayouts::releaseBindGroupLayout(WGPUBindGroupLayout& bindGroupLayout) +{ + if (bindGroupLayout) wgpuBindGroupLayoutRelease(bindGroupLayout); + bindGroupLayout = nullptr; +} + + +void WgBindGroupLayouts::initialize(WGPUDevice device) +{ + // store device handle + assert(device); + this->device = device; + + // common bind group settings + const WGPUShaderStage visibility_vert = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment | WGPUShaderStage_Compute; + const WGPUShaderStage visibility_frag = WGPUShaderStage_Fragment | WGPUShaderStage_Compute; + const WGPUSamplerBindingLayout sampler = { .type = WGPUSamplerBindingType_Filtering }; + const WGPUTextureBindingLayout texture = { .sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D }; + const WGPUStorageTextureBindingLayout storageTextureWO { .access = WGPUStorageTextureAccess_WriteOnly, .format = WGPUTextureFormat_RGBA8Unorm, .viewDimension = WGPUTextureViewDimension_2D }; + const WGPUBufferBindingLayout bufferUniform { .type = WGPUBufferBindingType_Uniform }; + + // bind group layout tex sampled with buffer uniforms + const WGPUBindGroupLayoutEntry entriesTexSampledBufferUniforms[] { + { .binding = 0, .visibility = visibility_frag, .sampler = sampler }, + { .binding = 1, .visibility = visibility_frag, .texture = texture }, + { .binding = 2, .visibility = visibility_vert, .buffer = bufferUniform }, + { .binding = 3, .visibility = visibility_vert, .buffer = bufferUniform } + }; + const WGPUBindGroupLayoutDescriptor layoutDescTexSambled { .entryCount = 2, .entries = entriesTexSampledBufferUniforms }; + const WGPUBindGroupLayoutDescriptor layoutDescTexSampledBuff1Un { .entryCount = 3, .entries = entriesTexSampledBufferUniforms }; + const WGPUBindGroupLayoutDescriptor layoutDescTexSampledBuff2Un { .entryCount = 4, .entries = entriesTexSampledBufferUniforms }; + layoutTexSampled = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexSambled); + layoutTexSampledBuff1Un = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexSampledBuff1Un); + layoutTexSampledBuff2Un = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexSampledBuff2Un); + assert(layoutTexSampled); + assert(layoutTexSampledBuff1Un); + assert(layoutTexSampledBuff2Un); + + // bind group layout tex storages WO + const WGPUBindGroupLayoutEntry entriesTexStoragesWO[] { + { .binding = 0, .visibility = visibility_frag, .storageTexture = storageTextureWO } + }; + const WGPUBindGroupLayoutDescriptor layoutDescTexStrorage1WO { .entryCount = 1, .entries = entriesTexStoragesWO }; + layoutTexStrorage1WO = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexStrorage1WO); + assert(layoutTexStrorage1WO); + + // bind group layout tex storages RO + const WGPUBindGroupLayoutEntry entriesTexStoragesRO[] { + { .binding = 0, .visibility = visibility_frag, .texture = texture }, + { .binding = 1, .visibility = visibility_frag, .texture = texture }, + { .binding = 2, .visibility = visibility_frag, .texture = texture } + }; + const WGPUBindGroupLayoutDescriptor layoutDescTexStorages1RO { .entryCount = 1, .entries = entriesTexStoragesRO }; + const WGPUBindGroupLayoutDescriptor layoutDescTexStorages2RO { .entryCount = 2, .entries = entriesTexStoragesRO }; + const WGPUBindGroupLayoutDescriptor layoutDescTexStorages3RO { .entryCount = 3, .entries = entriesTexStoragesRO }; + layoutTexStrorage1RO = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexStorages1RO); + layoutTexStrorage2RO = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexStorages2RO); + layoutTexStrorage3RO = wgpuDeviceCreateBindGroupLayout(device, &layoutDescTexStorages3RO); + assert(layoutTexStrorage1RO); + assert(layoutTexStrorage2RO); + assert(layoutTexStrorage3RO); + + // bind group layout buffer uniforms + const WGPUBindGroupLayoutEntry entriesBufferUniform[] { + { .binding = 0, .visibility = visibility_vert, .buffer = bufferUniform }, + { .binding = 1, .visibility = visibility_vert, .buffer = bufferUniform }, + { .binding = 2, .visibility = visibility_vert, .buffer = bufferUniform } + }; + const WGPUBindGroupLayoutDescriptor layoutDescBufferUniforms1Un { .entryCount = 1, .entries = entriesBufferUniform }; + const WGPUBindGroupLayoutDescriptor layoutDescBufferUniforms2Un { .entryCount = 2, .entries = entriesBufferUniform }; + const WGPUBindGroupLayoutDescriptor layoutDescBufferUniforms3Un { .entryCount = 3, .entries = entriesBufferUniform }; + layoutBuffer1Un = wgpuDeviceCreateBindGroupLayout(device, &layoutDescBufferUniforms1Un); + layoutBuffer2Un = wgpuDeviceCreateBindGroupLayout(device, &layoutDescBufferUniforms2Un); + layoutBuffer3Un = wgpuDeviceCreateBindGroupLayout(device, &layoutDescBufferUniforms3Un); + assert(layoutBuffer1Un); + assert(layoutBuffer2Un); + assert(layoutBuffer3Un); +} + + +void WgBindGroupLayouts::release() +{ + releaseBindGroupLayout(layoutBuffer3Un); + releaseBindGroupLayout(layoutBuffer2Un); + releaseBindGroupLayout(layoutBuffer1Un); + releaseBindGroupLayout(layoutTexStrorage3RO); + releaseBindGroupLayout(layoutTexStrorage2RO); + releaseBindGroupLayout(layoutTexStrorage1RO); + releaseBindGroupLayout(layoutTexStrorage1WO); + releaseBindGroupLayout(layoutTexSampledBuff1Un); + releaseBindGroupLayout(layoutTexSampledBuff2Un); + releaseBindGroupLayout(layoutTexSampled); + device = nullptr; +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgBindGroups.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgBindGroups.h new file mode 100644 index 0000000..dde791c --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgBindGroups.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_BIND_GROUPS_H_ +#define _TVG_WG_BIND_GROUPS_H_ + +#include + +class WgBindGroupLayouts { +private: + WGPUDevice device{}; +public: + WGPUBindGroupLayout layoutTexSampled{}; + WGPUBindGroupLayout layoutTexSampledBuff1Un{}; + WGPUBindGroupLayout layoutTexSampledBuff2Un{}; + WGPUBindGroupLayout layoutTexStrorage1WO{}; + WGPUBindGroupLayout layoutTexStrorage1RO{}; + WGPUBindGroupLayout layoutTexStrorage2RO{}; + WGPUBindGroupLayout layoutTexStrorage3RO{}; + WGPUBindGroupLayout layoutBuffer1Un{}; + WGPUBindGroupLayout layoutBuffer2Un{}; + WGPUBindGroupLayout layoutBuffer3Un{}; + + WGPUBindGroup createBindGroupTexSampled(WGPUSampler sampler, WGPUTextureView texView); + WGPUBindGroup createBindGroupTexSampledBuff1Un(WGPUSampler sampler, WGPUTextureView texView, WGPUBuffer buff); + WGPUBindGroup createBindGroupTexSampledBuff2Un(WGPUSampler sampler, WGPUTextureView texView, WGPUBuffer buff0, WGPUBuffer buff1); + WGPUBindGroup createBindGroupStrorage1WO(WGPUTextureView texView); + // for read-only access in compute shaders, use texture_2d instead of texture_storage_2d + WGPUBindGroup createBindGroupStrorage1RO(WGPUTextureView texView); + WGPUBindGroup createBindGroupStrorage2RO(WGPUTextureView texView0, WGPUTextureView texView1); + WGPUBindGroup createBindGroupStrorage3RO(WGPUTextureView texView0, WGPUTextureView texView1, WGPUTextureView texView2); + WGPUBindGroup createBindGroupBuffer1Un(WGPUBuffer buff); + WGPUBindGroup createBindGroupBuffer1Un(WGPUBuffer buff, uint64_t offset, uint64_t size); + WGPUBindGroup createBindGroupBuffer2Un(WGPUBuffer buff0, WGPUBuffer buff1); + WGPUBindGroup createBindGroupBuffer3Un(WGPUBuffer buff0, WGPUBuffer buff1, WGPUBuffer buff2); + void releaseBindGroup(WGPUBindGroup& bindGroup); + void releaseBindGroupLayout(WGPUBindGroupLayout& bindGroupLayout); + + void initialize(WGPUDevice device); + void release(); +}; + +#endif // _TVG_WG_BIND_GROUPS_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgCommon.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgCommon.cpp new file mode 100644 index 0000000..5ee2884 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgCommon.cpp @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgWgCommon.h" +#include "tvgArray.h" + +void WgContext::initialize(WGPUInstance instance, WGPUDevice device) +{ + assert(instance); + assert(device); + + // store global instance and surface + this->instance = instance; + this->device = device; + this->preferredFormat = WGPUTextureFormat_BGRA8Unorm; + + // get current queue + queue = wgpuDeviceGetQueue(device); + assert(queue); + + // create shared webgpu assets + samplerNearestRepeat = createSampler(WGPUFilterMode_Nearest, WGPUMipmapFilterMode_Nearest, WGPUAddressMode_Repeat); + samplerLinearRepeat = createSampler(WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_Repeat, 4); + samplerLinearMirror = createSampler(WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_MirrorRepeat, 4); + samplerLinearClamp = createSampler(WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_ClampToEdge, 4); + assert(samplerNearestRepeat); + assert(samplerLinearRepeat); + assert(samplerLinearMirror); + assert(samplerLinearClamp); + + // initialize bind group layouts + layouts.initialize(device); +} + + +void WgContext::release() +{ + layouts.release(); + releaseSampler(samplerLinearClamp); + releaseSampler(samplerLinearMirror); + releaseSampler(samplerLinearRepeat); + releaseSampler(samplerNearestRepeat); + releaseQueue(queue); +} + + +WGPUSampler WgContext::createSampler(WGPUFilterMode filter, WGPUMipmapFilterMode mipmapFilter, WGPUAddressMode addrMode, uint16_t anisotropy) +{ + const WGPUSamplerDescriptor samplerDesc { + .addressModeU = addrMode, .addressModeV = addrMode, .addressModeW = addrMode, + .magFilter = filter, .minFilter = filter, .mipmapFilter = mipmapFilter, + .lodMinClamp = 0.0f, .lodMaxClamp = 32.0f, .maxAnisotropy = anisotropy + }; + return wgpuDeviceCreateSampler(device, &samplerDesc); +} + + +bool WgContext::allocateTexture(WGPUTexture& texture, uint32_t width, uint32_t height, WGPUTextureFormat format, void* data) +{ + if ((texture) && (wgpuTextureGetWidth(texture) == width) && (wgpuTextureGetHeight(texture) == height)) { + // update texture data + const WGPUTexelCopyTextureInfo copyTextureInfo{ .texture = texture }; + const WGPUTexelCopyBufferLayout copyBufferLayout{ .bytesPerRow = 4 * width, .rowsPerImage = height }; + const WGPUExtent3D writeSize{ .width = width, .height = height, .depthOrArrayLayers = 1 }; + wgpuQueueWriteTexture(queue, ©TextureInfo, data, 4 * width * height, ©BufferLayout, &writeSize); + } else { + releaseTexture(texture); + texture = createTexture(width, height, format); + // update texture data + const WGPUTexelCopyTextureInfo copyTextureInfo{ .texture = texture }; + const WGPUTexelCopyBufferLayout copyBufferLayout{ .bytesPerRow = 4 * width, .rowsPerImage = height }; + const WGPUExtent3D writeSize{ .width = width, .height = height, .depthOrArrayLayers = 1 }; + wgpuQueueWriteTexture(queue, ©TextureInfo, data, 4 * width * height, ©BufferLayout, &writeSize); + return true; + } + return false; + +} + + +WGPUTexture WgContext::createTexture(uint32_t width, uint32_t height, WGPUTextureFormat format) +{ + const WGPUTextureDescriptor textureDesc { + .usage = WGPUTextureUsage_CopyDst | WGPUTextureUsage_TextureBinding, + .dimension = WGPUTextureDimension_2D, .size = { width, height, 1 }, + .format = format, .mipLevelCount = 1, .sampleCount = 1 + }; + return wgpuDeviceCreateTexture(device, &textureDesc); +} + + +WGPUTexture WgContext::createTexStorage(uint32_t width, uint32_t height, WGPUTextureFormat format) +{ + const WGPUTextureDescriptor textureDesc { + .usage = WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst | WGPUTextureUsage_TextureBinding | WGPUTextureUsage_StorageBinding | WGPUTextureUsage_RenderAttachment, + .dimension = WGPUTextureDimension_2D, .size = { width, height, 1 }, + .format = format, .mipLevelCount = 1, .sampleCount = 1 + }; + return wgpuDeviceCreateTexture(device, &textureDesc); +} + + +WGPUTexture WgContext::createTexAttachement(uint32_t width, uint32_t height, WGPUTextureFormat format, uint32_t sc) +{ + const WGPUTextureDescriptor textureDesc { + .usage = WGPUTextureUsage_RenderAttachment, + .dimension = WGPUTextureDimension_2D, .size = { width, height, 1 }, + .format = format, .mipLevelCount = 1, .sampleCount = sc + }; + return wgpuDeviceCreateTexture(device, &textureDesc); +} + + +WGPUTextureView WgContext::createTextureView(WGPUTexture texture) +{ + const WGPUTextureViewDescriptor textureViewDesc { + .format = wgpuTextureGetFormat(texture), + .dimension = WGPUTextureViewDimension_2D, + .baseMipLevel = 0, + .mipLevelCount = 1, + .baseArrayLayer = 0, + .arrayLayerCount = 1, + .aspect = WGPUTextureAspect_All + }; + return wgpuTextureCreateView(texture, &textureViewDesc); +} + + +void WgContext::releaseTextureView(WGPUTextureView& textureView) +{ + if (textureView) { + wgpuTextureViewRelease(textureView); + textureView = nullptr; + } +} + + +void WgContext::releaseTexture(WGPUTexture& texture) +{ + if (texture) { + wgpuTextureDestroy(texture); + wgpuTextureRelease(texture); + texture = nullptr; + } + +} + + +void WgContext::releaseSampler(WGPUSampler& sampler) +{ + if (sampler) { + wgpuSamplerRelease(sampler); + sampler = nullptr; + } +} + + +bool WgContext::allocateBufferUniform(WGPUBuffer& buffer, const void* data, uint64_t size) +{ + if ((buffer) && (wgpuBufferGetSize(buffer) >= size)) + wgpuQueueWriteBuffer(queue, buffer, 0, data, size); + else { + releaseBuffer(buffer); + const WGPUBufferDescriptor bufferDesc { .usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform, .size = size }; + buffer = wgpuDeviceCreateBuffer(device, &bufferDesc); + wgpuQueueWriteBuffer(queue, buffer, 0, data, size); + return true; + } + return false; +} + + +bool WgContext::allocateBufferVertex(WGPUBuffer& buffer, const float* data, uint64_t size) +{ + if ((buffer) && (wgpuBufferGetSize(buffer) >= size)) + wgpuQueueWriteBuffer(queue, buffer, 0, data, size); + else { + releaseBuffer(buffer); + const WGPUBufferDescriptor bufferDesc { .usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex, .size = size }; + buffer = wgpuDeviceCreateBuffer(device, &bufferDesc); + wgpuQueueWriteBuffer(queue, buffer, 0, data, size); + return true; + } + return false; +} + + +bool WgContext::allocateBufferIndex(WGPUBuffer& buffer, const uint32_t* data, uint64_t size) +{ + if ((buffer) && (wgpuBufferGetSize(buffer) >= size)) + wgpuQueueWriteBuffer(queue, buffer, 0, data, size); + else { + releaseBuffer(buffer); + const WGPUBufferDescriptor bufferDesc { .usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index, .size = size }; + buffer = wgpuDeviceCreateBuffer(device, &bufferDesc); + wgpuQueueWriteBuffer(queue, buffer, 0, data, size); + return true; + } + return false; +} + + +void WgContext::releaseBuffer(WGPUBuffer& buffer) +{ + if (buffer) { + wgpuBufferDestroy(buffer); + wgpuBufferRelease(buffer); + buffer = nullptr; + } +} + +void WgContext::releaseQueue(WGPUQueue& queue) +{ + if (queue) { + wgpuQueueRelease(queue); + queue = nullptr; + } +} + + +WGPUCommandEncoder WgContext::createCommandEncoder() +{ + WGPUCommandEncoderDescriptor commandEncoderDesc{}; + return wgpuDeviceCreateCommandEncoder(device, &commandEncoderDesc); +} + + +void WgContext::submitCommandEncoder(WGPUCommandEncoder commandEncoder) +{ + const WGPUCommandBufferDescriptor commandBufferDesc{}; + WGPUCommandBuffer commandsBuffer = wgpuCommandEncoderFinish(commandEncoder, &commandBufferDesc); + wgpuQueueSubmit(queue, 1, &commandsBuffer); + wgpuCommandBufferRelease(commandsBuffer); +} + + +void WgContext::releaseCommandEncoder(WGPUCommandEncoder& commandEncoder) +{ + if (commandEncoder) { + wgpuCommandEncoderRelease(commandEncoder); + commandEncoder = nullptr; + } +} + + +void WgContext::submit() +{ + wgpuQueueSubmit(queue, 0, nullptr); +} + + +bool WgContext::invalid() +{ + return !instance || !device; +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgCommon.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgCommon.h new file mode 100644 index 0000000..d10be26 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgCommon.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_COMMON_H_ +#define _TVG_WG_COMMON_H_ + +#include "tvgWgBindGroups.h" + +struct WgContext { + // external webgpu handles + WGPUInstance instance{}; + WGPUAdapter adapter{}; + WGPUDevice device{}; + // common webgpu handles + WGPUQueue queue{}; + WGPUTextureFormat preferredFormat{}; + // shared webgpu assets + WGPUSampler samplerNearestRepeat{}; + WGPUSampler samplerLinearRepeat{}; + WGPUSampler samplerLinearMirror{}; + WGPUSampler samplerLinearClamp{}; + // bind groups layouts + WgBindGroupLayouts layouts; + + void initialize(WGPUInstance instance, WGPUDevice device); + void release(); + + // create common objects + WGPUSampler createSampler(WGPUFilterMode filter, WGPUMipmapFilterMode mipmapFilter, WGPUAddressMode addrMode, uint16_t anisotropy = 1); + WGPUTexture createTexture(uint32_t width, uint32_t height, WGPUTextureFormat format); + WGPUTexture createTexStorage(uint32_t width, uint32_t height, WGPUTextureFormat format); + WGPUTexture createTexAttachement(uint32_t width, uint32_t height, WGPUTextureFormat format, uint32_t sc); + WGPUTextureView createTextureView(WGPUTexture texture); + bool allocateTexture(WGPUTexture& texture, uint32_t width, uint32_t height, WGPUTextureFormat format, void* data); + + // release common objects + void releaseTextureView(WGPUTextureView& textureView); + void releaseTexture(WGPUTexture& texture); + void releaseSampler(WGPUSampler& sampler); + void releaseQueue(WGPUQueue& queue); + + // create buffer objects (return true, if buffer handle was changed) + bool allocateBufferUniform(WGPUBuffer& buffer, const void* data, uint64_t size); + bool allocateBufferVertex(WGPUBuffer& buffer, const float* data, uint64_t size); + bool allocateBufferIndex(WGPUBuffer& buffer, const uint32_t* data, uint64_t size); + + // release buffer objects + void releaseBuffer(WGPUBuffer& buffer); + + // command encoder + WGPUCommandEncoder createCommandEncoder(); + void submitCommandEncoder(WGPUCommandEncoder encoder); + void releaseCommandEncoder(WGPUCommandEncoder& encoder); + + void submit(); + bool invalid(); +}; + +#endif // _TVG_WG_COMMON_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgCompositor.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgCompositor.cpp new file mode 100644 index 0000000..7f6bf10 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgCompositor.cpp @@ -0,0 +1,1001 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgCompositor.h" +#include "tvgWgShaderTypes.h" +#include + +void WgCompositor::initialize(WgContext& context, uint32_t width, uint32_t height) +{ + // pipelines (external handle, do not release) + pipelines.initialize(context); + stageBufferGeometry.initialize(context); + // initialize opacity pool + initPools(context); + // allocate global view matrix handles + WgShaderTypeMat4x4f viewMat(width, height); + context.allocateBufferUniform(bufferViewMat, &viewMat, sizeof(viewMat)); + bindGroupViewMat = context.layouts.createBindGroupBuffer1Un(bufferViewMat); + // create render targets handles + resize(context, width, height); + // composition and blend geometries + meshDataBlit.blitBox(); + // force stage buffers initialization + flush(context); +} + + +void WgCompositor::initPools(WgContext& context) +{ + for (uint32_t i = 0; i < 256; i++) { + float opacity = i / 255.0f; + context.allocateBufferUniform(bufferOpacities[i], &opacity, sizeof(float)); + bindGroupOpacities[i] = context.layouts.createBindGroupBuffer1Un(bufferOpacities[i]); + } +} + + +void WgCompositor::release(WgContext& context) +{ + // release render targets habdles + resize(context, 0, 0); + // release opacity pool + releasePools(context); + // release global view matrix handles + context.layouts.releaseBindGroup(bindGroupViewMat); + context.releaseBuffer(bufferViewMat); + // release stage buffer + stageBufferPaint.release(context); + stageBufferGeometry.release(context); + // release pipelines + pipelines.release(context); +} + + +void WgCompositor::releasePools(WgContext& context) +{ + // release opacity pool + for (uint32_t i = 0; i < 256; i++) { + context.layouts.releaseBindGroup(bindGroupOpacities[i]); + context.releaseBuffer(bufferOpacities[i]); + } +} + + +void WgCompositor::resize(WgContext& context, uint32_t width, uint32_t height) { + // release existig handles + if ((this->width != width) || (this->height != height)) { + context.layouts.releaseBindGroup(bindGroupStorageTemp); + // release intermediate render target + targetTemp1.release(context); + targetTemp0.release(context); + // release global stencil buffer handles + context.releaseTextureView(texViewDepthStencilMS); + context.releaseTexture(texDepthStencilMS); + context.releaseTextureView(texViewDepthStencil); + context.releaseTexture(texDepthStencil); + // store render target dimensions + this->height = height; + this->width = width; + } + + // create render targets handles + if ((width != 0) && (height != 0)) { + // store render target dimensions + this->width = width; + this->height = height; + // reallocate global view matrix handles + WgShaderTypeMat4x4f viewMat(width, height); + context.allocateBufferUniform(bufferViewMat, &viewMat, sizeof(viewMat)); + // allocate global stencil buffer handles + texDepthStencil = context.createTexAttachement(width, height, WGPUTextureFormat_Depth24PlusStencil8, 1); + texViewDepthStencil = context.createTextureView(texDepthStencil); + texDepthStencilMS = context.createTexAttachement(width, height, WGPUTextureFormat_Depth24PlusStencil8, 4); + texViewDepthStencilMS = context.createTextureView(texDepthStencilMS); + // initialize intermediate render targets + targetTemp0.initialize(context, width, height); + targetTemp1.initialize(context, width, height); + bindGroupStorageTemp = context.layouts.createBindGroupStrorage2RO(targetTemp0.texView, targetTemp1.texView); + } +} + + +RenderRegion WgCompositor::shrinkRenderRegion(const RenderRegion& rect) +{ + return { + {std::max(0, std::min((int32_t)width, rect.min.x)), std::max(0, std::min((int32_t)height, rect.min.y))}, + {std::max(0, std::min((int32_t)width, rect.max.x)), std::max(0, std::min((int32_t)height, rect.max.y))} + }; +} + + +void WgCompositor::copyTexture(const WgRenderTarget* dst, const WgRenderTarget* src) +{ + const RenderRegion region = {{0, 0}, {(int32_t)src->width, (int32_t)src->height}}; + copyTexture(dst, src, region); +} + + +void WgCompositor::copyTexture(const WgRenderTarget* dst, const WgRenderTarget* src, const RenderRegion& region) +{ + assert(dst); + assert(src); + assert(commandEncoder); + const WGPUTexelCopyTextureInfo texSrc { .texture = src->texture, .origin = { .x = (uint32_t)region.min.x, .y = (uint32_t)region.min.y } }; + const WGPUTexelCopyTextureInfo texDst { .texture = dst->texture, .origin = { .x = (uint32_t)region.min.x, .y = (uint32_t)region.min.y } }; + const WGPUExtent3D copySize { .width = region.w(), .height = region.h(), .depthOrArrayLayers = 1 }; + wgpuCommandEncoderCopyTextureToTexture(commandEncoder, &texSrc, &texDst, ©Size); +} + + +void WgCompositor::beginRenderPassMS(WGPUCommandEncoder commandEncoder, WgRenderTarget* target, bool clear, WGPUColor clearColor) +{ + assert(target); + assert(commandEncoder); + // do not start same render bass + if (target == currentTarget) return; + // we must to end render pass first + endRenderPass(); + this->currentTarget = target; + // start new render pass + this->commandEncoder = commandEncoder; + const WGPURenderPassDepthStencilAttachment depthStencilAttachment{ + .view = texViewDepthStencilMS, + .depthLoadOp = WGPULoadOp_Clear, + .depthStoreOp = WGPUStoreOp_Discard, + .depthClearValue = 1.0f, + .stencilLoadOp = WGPULoadOp_Clear, + .stencilStoreOp = WGPUStoreOp_Discard, + .stencilClearValue = 0 + }; + const WGPURenderPassColorAttachment colorAttachment{ + .view = target->texViewMS, + .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, + .resolveTarget = target->texView, + .loadOp = clear ? WGPULoadOp_Clear : WGPULoadOp_Load, + .storeOp = WGPUStoreOp_Store, + .clearValue = clearColor + }; + WGPURenderPassDescriptor renderPassDesc{ .colorAttachmentCount = 1, .colorAttachments = &colorAttachment, .depthStencilAttachment = &depthStencilAttachment }; + renderPassEncoder = wgpuCommandEncoderBeginRenderPass(commandEncoder, &renderPassDesc); + assert(renderPassEncoder); +} + + +void WgCompositor::beginRenderPass(WGPUCommandEncoder encoder, WgRenderTarget* target) +{ + assert(!renderPassEncoder); + currentTarget = target; + const WGPURenderPassDepthStencilAttachment depthStencilAttachment{ + .view = texViewDepthStencil, + .depthLoadOp = WGPULoadOp_Load, + .depthStoreOp = WGPUStoreOp_Discard, + .stencilLoadOp = WGPULoadOp_Load, + .stencilStoreOp = WGPUStoreOp_Discard + }; + const WGPURenderPassColorAttachment colorAttachment { + .view = target->texView, + .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, + .loadOp = WGPULoadOp_Load, + .storeOp = WGPUStoreOp_Store, + }; + const WGPURenderPassDescriptor renderPassDesc{ .colorAttachmentCount = 1, .colorAttachments = &colorAttachment, .depthStencilAttachment = &depthStencilAttachment }; + renderPassEncoder = wgpuCommandEncoderBeginRenderPass(encoder, &renderPassDesc); +} + + +void WgCompositor::endRenderPass() +{ + if (currentTarget) { + assert(renderPassEncoder); + wgpuRenderPassEncoderEnd(renderPassEncoder); + wgpuRenderPassEncoderRelease(renderPassEncoder); + renderPassEncoder = nullptr; + currentTarget = nullptr; + } +} + +void WgCompositor::reset(WgContext& context) +{ + stageBufferGeometry.clear(); + stageBufferPaint.clear(); +} + + +void WgCompositor::flush(WgContext& context) +{ + stageBufferGeometry.append(&meshDataBlit); + stageBufferGeometry.flush(context); + stageBufferPaint.flush(context); + context.submit(); +} + + +void WgCompositor::requestShape(WgRenderDataShape* renderData) +{ + stageBufferGeometry.append(renderData); + renderData->renderSettingsShape.bindGroupInd = stageBufferPaint.append(renderData->renderSettingsShape.settings); + renderData->renderSettingsStroke.bindGroupInd = stageBufferPaint.append(renderData->renderSettingsStroke.settings); + ARRAY_FOREACH(p, renderData->clips) + requestShape((WgRenderDataShape* )(*p)); +} + + +void WgCompositor::requestImage(WgRenderDataPicture* renderData) +{ + stageBufferGeometry.append(renderData); + renderData->renderSettings.bindGroupInd = stageBufferPaint.append(renderData->renderSettings.settings); + ARRAY_FOREACH(p, renderData->clips) + requestShape((WgRenderDataShape* )(*p)); +} + + +void WgCompositor::renderShape(WgContext& context, WgRenderDataShape* renderData, BlendMethod blendMethod) +{ + assert(renderData); + assert(renderPassEncoder); + // apply clip path if necessary + if (!renderData->clips.empty()) { + renderClipPath(context, renderData); + if (renderData->strokeFirst) { + clipStrokes(context, renderData); + clipShape(context, renderData); + } else { + clipShape(context, renderData); + clipStrokes(context, renderData); + } + clearClipPath(context, renderData); + // use custom blending + } else if (blendMethod != BlendMethod::Normal) { + if (renderData->strokeFirst) { + blendStrokes(context, renderData, blendMethod); + blendShape(context, renderData, blendMethod); + } else { + blendShape(context, renderData, blendMethod); + blendStrokes(context, renderData, blendMethod); + } + // use direct hardware blending + } else { + if (renderData->strokeFirst) { + drawStrokes(context, renderData); + drawShape(context, renderData); + } else { + drawShape(context, renderData); + drawStrokes(context, renderData); + } + } +} + + +void WgCompositor::renderImage(WgContext& context, WgRenderDataPicture* renderData, BlendMethod blendMethod) +{ + assert(renderData); + assert(renderPassEncoder); + // apply clip path if necessary + if (renderData->clips.count != 0) { + renderClipPath(context, renderData); + clipImage(context, renderData); + clearClipPath(context, renderData); + // use custom blending + } else if (blendMethod != BlendMethod::Normal) + blendImage(context, renderData, blendMethod); + // use direct hardware blending + else drawImage(context, renderData); +} + + +void WgCompositor::renderScene(WgContext& context, WgRenderTarget* scene, WgCompose* compose) +{ + assert(scene); + assert(compose); + assert(renderPassEncoder); + // use custom blending + if (compose->blend != BlendMethod::Normal) + blendScene(context, scene, compose); + // use direct hardware blending + else drawScene(context, scene, compose); +} + + +void WgCompositor::composeScene(WgContext& context, WgRenderTarget* src, WgRenderTarget* mask, WgCompose* cmp) +{ + assert(cmp); + assert(src); + assert(mask); + assert(renderPassEncoder); + RenderRegion rect = shrinkRenderRegion(cmp->aabb); + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, rect.x(), rect.y(), rect.w(), rect.h()); + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, src->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, mask->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.scene_compose[(uint32_t)cmp->method]); + drawMeshImage(context, &meshDataBlit); +} + + +void WgCompositor::blit(WgContext& context, WGPUCommandEncoder encoder, WgRenderTarget* src, WGPUTextureView dstView) +{ + assert(!renderPassEncoder); + const WGPURenderPassDepthStencilAttachment depthStencilAttachment{ + .view = texViewDepthStencil, + .depthLoadOp = WGPULoadOp_Load, + .depthStoreOp = WGPUStoreOp_Discard, + .stencilLoadOp = WGPULoadOp_Load, + .stencilStoreOp = WGPUStoreOp_Discard + }; + const WGPURenderPassColorAttachment colorAttachment { + .view = dstView, + .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, + .loadOp = WGPULoadOp_Load, + .storeOp = WGPUStoreOp_Store, + }; + const WGPURenderPassDescriptor renderPassDesc{ .colorAttachmentCount = 1, .colorAttachments = &colorAttachment, .depthStencilAttachment = &depthStencilAttachment }; + renderPassEncoder = wgpuCommandEncoderBeginRenderPass(encoder, &renderPassDesc); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, src->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.blit); + drawMeshImage(context, &meshDataBlit); + wgpuRenderPassEncoderEnd(renderPassEncoder); + wgpuRenderPassEncoderRelease(renderPassEncoder); + renderPassEncoder = nullptr; +} + + +void WgCompositor::drawMesh(WgContext& context, WgMeshData* meshData) +{ + assert(meshData); + assert(renderPassEncoder); + uint64_t icount = meshData->ibuffer.count; + uint64_t vsize = meshData->vbuffer.count * sizeof(Point); + uint64_t isize = icount * sizeof(uint32_t); + wgpuRenderPassEncoderSetVertexBuffer(renderPassEncoder, 0, stageBufferGeometry.vbuffer_gpu, meshData->voffset, vsize); + wgpuRenderPassEncoderSetIndexBuffer(renderPassEncoder, stageBufferGeometry.ibuffer_gpu, WGPUIndexFormat_Uint32, meshData->ioffset, isize); + wgpuRenderPassEncoderDrawIndexed(renderPassEncoder, icount, 1, 0, 0, 0); +}; + + +void WgCompositor::drawMeshImage(WgContext& context, WgMeshData* meshData) +{ + assert(meshData); + assert(renderPassEncoder); + uint64_t icount = meshData->ibuffer.count; + uint64_t vsize = meshData->vbuffer.count * sizeof(Point); + uint64_t isize = icount * sizeof(uint32_t); + wgpuRenderPassEncoderSetVertexBuffer(renderPassEncoder, 0, stageBufferGeometry.vbuffer_gpu, meshData->voffset, vsize); + wgpuRenderPassEncoderSetVertexBuffer(renderPassEncoder, 1, stageBufferGeometry.vbuffer_gpu, meshData->toffset, vsize); + wgpuRenderPassEncoderSetIndexBuffer(renderPassEncoder, stageBufferGeometry.ibuffer_gpu, WGPUIndexFormat_Uint32, meshData->ioffset, isize); + wgpuRenderPassEncoderDrawIndexed(renderPassEncoder, icount, 1, 0, 0, 0); +}; + + +void WgCompositor::drawShape(WgContext& context, WgRenderDataShape* renderData) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->renderSettingsShape.skip || renderData->meshShape.vbuffer.count == 0 || renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettingsShape; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // setup stencil rules + if (!renderData->convex) { + WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd; + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline); + // draw to stencil (first pass) + drawMesh(context, &renderData->meshShape); + } + // setup fill rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + if (settings.fillType == WgRenderSettingsType::Solid) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, renderData->convex ? pipelines.solid_conv : pipelines.solid); + } else if (settings.fillType == WgRenderSettingsType::Linear) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, renderData->convex ? pipelines.linear_conv : pipelines.linear); + } else if (settings.fillType == WgRenderSettingsType::Radial) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, renderData->convex ? pipelines.radial_conv : pipelines.radial); + } + // draw to color (second pass) + drawMesh(context, renderData->convex ? &renderData->meshShape : &renderData->meshBBox); +} + + +void WgCompositor::blendShape(WgContext& context, WgRenderDataShape* renderData, BlendMethod blendMethod) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->renderSettingsShape.skip || renderData->meshShape.vbuffer.count == 0 || renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettingsShape; + // copy current render target data to dst target + WgRenderTarget *target = currentTarget; + endRenderPass(); + copyTexture(&targetTemp0, target); + beginRenderPassMS(commandEncoder, target, false); + // render shape with blend settings + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // setup stencil rules + WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd; + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline); + // draw to stencil (first pass) + drawMesh(context, &renderData->meshShape); + // setup fill rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 3, targetTemp0.bindGroupTexture, 0, nullptr); + uint32_t blendMethodInd = (uint32_t)blendMethod; + if (settings.fillType == WgRenderSettingsType::Solid) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.solid_blend[blendMethodInd]); + } else if (settings.fillType == WgRenderSettingsType::Linear) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.linear_blend[blendMethodInd]); + } else if (settings.fillType == WgRenderSettingsType::Radial) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.radial_blend[blendMethodInd]); + } + // draw to color (second pass) + drawMesh(context, &renderData->meshBBox); +} + + +void WgCompositor::clipShape(WgContext& context, WgRenderDataShape* renderData) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->renderSettingsShape.skip || renderData->meshShape.vbuffer.count == 0 || renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettingsShape; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // setup stencil rules + WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd; + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline); + // draw to stencil (first pass) + drawMesh(context, &renderData->meshShape); + // merge depth and stencil buffer + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[128], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.merge_depth_stencil); + drawMesh(context, &renderData->meshBBox); + // setup fill rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + if (settings.fillType == WgRenderSettingsType::Solid) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.solid); + } else if (settings.fillType == WgRenderSettingsType::Linear) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.linear); + } else if (settings.fillType == WgRenderSettingsType::Radial) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.radial); + } + // draw to color (second pass) + drawMesh(context, &renderData->meshBBox); +} + + +void WgCompositor::drawStrokes(WgContext& context, WgRenderDataShape* renderData) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->renderSettingsStroke.skip || renderData->meshStrokes.vbuffer.count == 0 || renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettingsStroke; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // draw strokes to stencil (first pass) + // setup stencil rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + // draw to stencil (first pass) + drawMesh(context, &renderData->meshStrokes); + // setup fill rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + if (settings.fillType == WgRenderSettingsType::Solid) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.solid); + } else if (settings.fillType == WgRenderSettingsType::Linear) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.linear); + } else if (settings.fillType == WgRenderSettingsType::Radial) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.radial); + } + // draw to color (second pass) + drawMesh(context, &renderData->meshStrokesBBox); +} + + +void WgCompositor::blendStrokes(WgContext& context, WgRenderDataShape* renderData, BlendMethod blendMethod) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->renderSettingsStroke.skip || renderData->meshStrokes.vbuffer.count == 0 || renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettingsStroke; + // copy current render target data to dst target + WgRenderTarget *target = currentTarget; + endRenderPass(); + copyTexture(&targetTemp0, target); + beginRenderPassMS(commandEncoder, target, false); + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // draw strokes to stencil (first pass) + // setup stencil rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + // draw to stencil (first pass) + drawMesh(context, &renderData->meshStrokes); + // setup fill rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 3, targetTemp0.bindGroupTexture, 0, nullptr); + uint32_t blendMethodInd = (uint32_t)blendMethod; + if (settings.fillType == WgRenderSettingsType::Solid) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.solid_blend[blendMethodInd]); + } else if (settings.fillType == WgRenderSettingsType::Linear) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.linear_blend[blendMethodInd]); + } else if (settings.fillType == WgRenderSettingsType::Radial) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.radial_blend[blendMethodInd]); + } + // draw to color (second pass) + drawMesh(context, &renderData->meshStrokesBBox); +}; + + +void WgCompositor::clipStrokes(WgContext& context, WgRenderDataShape* renderData) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->renderSettingsStroke.skip || renderData->meshStrokes.vbuffer.count == 0 || renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettingsStroke; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // draw strokes to stencil (first pass) + // setup stencil rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + // draw to stencil (first pass) + drawMesh(context, &renderData->meshStrokes); + // merge depth and stencil buffer + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[128], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.merge_depth_stencil); + drawMesh(context, &renderData->meshBBox); + // setup fill rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + if (settings.fillType == WgRenderSettingsType::Solid) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.solid); + } else if (settings.fillType == WgRenderSettingsType::Linear) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.linear); + } else if (settings.fillType == WgRenderSettingsType::Radial) { + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, settings.gradientData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.radial); + } + // draw to color (second pass) + drawMesh(context, &renderData->meshStrokesBBox); +} + + +void WgCompositor::drawImage(WgContext& context, WgRenderDataPicture* renderData) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettings; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // draw stencil + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + drawMeshImage(context, &renderData->meshData); + // draw image + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, renderData->imageData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.image); + drawMeshImage(context, &renderData->meshData); +} + + +void WgCompositor::blendImage(WgContext& context, WgRenderDataPicture* renderData, BlendMethod blendMethod) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettings; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // copy current render target data to dst target + WgRenderTarget *target = currentTarget; + endRenderPass(); + copyTexture(&targetTemp0, target); + beginRenderPassMS(commandEncoder, target, false); + // setup stencil rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + drawMeshImage(context, &renderData->meshData); + // blend image + uint32_t blendMethodInd = (uint32_t)blendMethod; + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, renderData->imageData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 3, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.image_blend[blendMethodInd]); + drawMeshImage(context, &renderData->meshData); +}; + + +void WgCompositor::clipImage(WgContext& context, WgRenderDataPicture* renderData) +{ + assert(renderData); + assert(renderPassEncoder); + if (renderData->viewport.invalid()) return; + WgRenderSettings& settings = renderData->renderSettings; + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + // setup stencil rules + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + drawMeshImage(context, &renderData->meshData); + // merge depth and stencil buffer + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[128], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.merge_depth_stencil); + drawMeshImage(context, &renderData->meshData); + // draw image + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, renderData->imageData.bindGroup, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.image); + drawMeshImage(context, &renderData->meshData); +} + + +void WgCompositor::drawScene(WgContext& context, WgRenderTarget* scene, WgCompose* compose) +{ + assert(scene); + assert(compose); + assert(currentTarget); + // draw scene + RenderRegion rect = shrinkRenderRegion(compose->aabb); + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, rect.x(), rect.y(), rect.w(), rect.h()); + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, scene->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, bindGroupOpacities[compose->opacity], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.scene); + drawMeshImage(context, &meshDataBlit); +} + + +void WgCompositor::blendScene(WgContext& context, WgRenderTarget* scene, WgCompose* compose) +{ + assert(scene); + assert(compose); + assert(currentTarget); + // copy current render target data to dst target + WgRenderTarget *target = currentTarget; + endRenderPass(); + copyTexture(&targetTemp0, target); + beginRenderPassMS(commandEncoder, target, false); + // blend scene + uint32_t blendMethodInd = (uint32_t)compose->blend; + RenderRegion rect = shrinkRenderRegion(compose->aabb); + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, rect.x(), rect.y(), rect.w(), rect.h()); + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, scene->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[compose->opacity], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.scene_blend[blendMethodInd]); + drawMeshImage(context, &meshDataBlit); +} + + +void WgCompositor::markupClipPath(WgContext& context, WgRenderDataShape* renderData) +{ + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x(), renderData->viewport.y(), renderData->viewport.w(), renderData->viewport.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + // markup stencil + if (renderData->meshStrokes.vbuffer.count > 0) { + WgRenderSettings& settings = renderData->renderSettingsStroke; + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 255); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.direct); + drawMesh(context, &renderData->meshStrokes); + } else if (renderData->meshShape.vbuffer.count > 0) { + WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd; + WgRenderSettings& settings = renderData->renderSettingsShape; + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline); + drawMesh(context, &renderData->meshShape); + } +} + + +void WgCompositor::renderClipPath(WgContext& context, WgRenderDataPaint* paint) +{ + assert(paint); + assert(renderPassEncoder); + assert(paint->clips.count > 0); + // reset scissor recr to full screen + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, 0, 0, width, height); + // get render data + WgRenderDataShape* renderData0 = (WgRenderDataShape*)paint->clips[0]; + WgRenderSettings& settings0 = renderData0->renderSettingsShape; + // markup stencil + markupClipPath(context, renderData0); + // copy stencil to depth + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings0.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[128], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.copy_stencil_to_depth); + drawMesh(context, &renderData0->meshBBox); + // merge clip paths with AND logic + for (auto p = paint->clips.begin() + 1; p < paint->clips.end(); ++p) { + // get render data + WgRenderDataShape* renderData = (WgRenderDataShape*)(*p); + WgRenderSettings& settings = renderData->renderSettingsShape; + // markup stencil + markupClipPath(context, renderData); + // copy stencil to depth (clear stencil) + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[190], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.copy_stencil_to_depth_interm); + drawMesh(context, &renderData->meshBBox); + // copy depth to stencil + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 1); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[190], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.copy_depth_to_stencil); + drawMesh(context, &renderData->meshBBox); + // clear depth current (keep stencil) + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[255], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.clear_depth); + drawMesh(context, &renderData->meshBBox); + // clear depth original (keep stencil) + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings0.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[255], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.clear_depth); + drawMesh(context, &renderData0->meshBBox); + // copy stencil to depth (clear stencil) + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[128], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.copy_stencil_to_depth); + drawMesh(context, &renderData->meshBBox); + } +} + + +void WgCompositor::clearClipPath(WgContext& context, WgRenderDataPaint* paint) +{ + assert(paint); + assert(renderPassEncoder); + assert(paint->clips.count > 0); + // reset scissor recr to full screen + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, 0, 0, width, height); + // get render data + ARRAY_FOREACH(p, paint->clips) { + WgRenderDataShape* renderData = (WgRenderDataShape*)(*p); + WgRenderSettings& settings = renderData->renderSettingsShape; + // set transformations + wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, stageBufferPaint[settings.bindGroupInd], 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, bindGroupOpacities[255], 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.clear_depth); + drawMesh(context, &renderData->meshBBox); + } +} + + +bool WgCompositor::gaussianBlur(WgContext& context, WgRenderTarget* dst, const RenderEffectGaussianBlur* params, const WgCompose* compose) +{ + assert(dst); + assert(params); + assert(params->rd); + assert(!renderPassEncoder); + + auto renderDataParams = (WgRenderDataEffectParams*)params->rd; + auto aabb = shrinkRenderRegion(compose->aabb); + + copyTexture(&targetTemp0, dst); + if (params->direction == 0) { // both + beginRenderPass(commandEncoder, &targetTemp0); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, dst->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.gaussian_horz); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.gaussian_vert); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + } else if (params->direction == 1) { // horizontal + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.gaussian_horz); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + } else if (params->direction == 2) { // vertical + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.gaussian_vert); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + } + + return true; +} + + +bool WgCompositor::dropShadow(WgContext& context, WgRenderTarget* dst, const RenderEffectDropShadow* params, const WgCompose* compose) +{ + assert(dst); + assert(params); + assert(params->rd); + assert(!renderPassEncoder); + + auto renderDataParams = (WgRenderDataEffectParams*)params->rd; + auto aabb = shrinkRenderRegion(compose->aabb); + + copyTexture(&targetTemp0, dst); + copyTexture(&targetTemp1, dst); + if (!tvg::zero(params->sigma)) { + // horizontal + beginRenderPass(commandEncoder, &targetTemp0); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, dst->bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.gaussian_horz); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + // vertical + beginRenderPass(commandEncoder, &targetTemp1); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.gaussian_vert); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + } + // drop shadow + copyTexture(&targetTemp0, dst, aabb); + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, targetTemp1.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 2, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.dropshadow); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + return true; +} + + +bool WgCompositor::fillEffect(WgContext& context, WgRenderTarget* dst, const RenderEffectFill* params, const WgCompose* compose) +{ + assert(dst); + assert(params); + assert(params->rd); + assert(!renderPassEncoder); + + auto renderDataParams = (WgRenderDataEffectParams*)params->rd; + auto aabb = shrinkRenderRegion(compose->aabb); + + copyTexture(&targetTemp0, dst, aabb); + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.fill_effect); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + + return true; +} + + +bool WgCompositor::tintEffect(WgContext& context, WgRenderTarget* dst, const RenderEffectTint* params, const WgCompose* compose) +{ + assert(dst); + assert(params); + assert(params->rd); + assert(!renderPassEncoder); + + auto renderDataParams = (WgRenderDataEffectParams*)params->rd; + auto aabb = shrinkRenderRegion(compose->aabb); + + copyTexture(&targetTemp0, dst, aabb); + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.tint_effect); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + + return true; +} + +bool WgCompositor::tritoneEffect(WgContext& context, WgRenderTarget* dst, const RenderEffectTritone* params, const WgCompose* compose) +{ + assert(dst); + assert(params); + assert(params->rd); + assert(!renderPassEncoder); + + auto renderDataParams = (WgRenderDataEffectParams*)params->rd; + auto aabb = shrinkRenderRegion(compose->aabb); + + copyTexture(&targetTemp0, dst, aabb); + beginRenderPass(commandEncoder, dst); { + wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, aabb.x(), aabb.y(), aabb.w(), aabb.h()); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, targetTemp0.bindGroupTexture, 0, nullptr); + wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderDataParams->bindGroupParams, 0, nullptr); + wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines.tritone_effect); + drawMeshImage(context, &meshDataBlit); + } endRenderPass(); + + return true; +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgCompositor.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgCompositor.h new file mode 100644 index 0000000..c26d123 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgCompositor.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_COMPOSITOR_H_ +#define _TVG_WG_COMPOSITOR_H_ + +#include "tvgWgRenderTarget.h" +#include "tvgWgRenderData.h" + +struct WgCompose: RenderCompositor +{ + BlendMethod blend{}; + RenderRegion aabb{}; + CompositionFlag flags{}; + bool masked{}; // indicate if composition allocates more than one render target +}; + +class WgCompositor +{ +private: + // pipelines + WgPipelines pipelines{}; + // stage buffers + WgStageBufferGeometry stageBufferGeometry{}; + WgStageBufferUniform stageBufferPaint; + // global stencil/depth buffer handles + WGPUTexture texDepthStencil{}; + WGPUTextureView texViewDepthStencil{}; + WGPUTexture texDepthStencilMS{}; + WGPUTextureView texViewDepthStencilMS{}; + // global view matrix handles + WGPUBuffer bufferViewMat{}; + WGPUBindGroup bindGroupViewMat{}; + // opacity value pool + WGPUBuffer bufferOpacities[256]{}; + WGPUBindGroup bindGroupOpacities[256]{}; + // current render pass handles + WGPURenderPassEncoder renderPassEncoder{}; + WGPUCommandEncoder commandEncoder{}; + WgRenderTarget* currentTarget{}; + // intermediate render targets + WgRenderTarget targetTemp0; + WgRenderTarget targetTemp1; + WGPUBindGroup bindGroupStorageTemp{}; + // composition and blend geometries + WgMeshData meshDataBlit; + // render target dimensions + uint32_t width{}; + uint32_t height{}; + + // viewport utilities + RenderRegion shrinkRenderRegion(const RenderRegion& rect); + void copyTexture(const WgRenderTarget* dst, const WgRenderTarget* src); + void copyTexture(const WgRenderTarget* dst, const WgRenderTarget* src, const RenderRegion& region); + + // base meshes draw + void drawMesh(WgContext& context, WgMeshData* meshData); + void drawMeshImage(WgContext& context, WgMeshData* meshData); + + // shapes + void drawShape(WgContext& context, WgRenderDataShape* renderData); + void blendShape(WgContext& context, WgRenderDataShape* renderData, BlendMethod blendMethod); + void clipShape(WgContext& context, WgRenderDataShape* renderData); + + // strokes + void drawStrokes(WgContext& context, WgRenderDataShape* renderData); + void blendStrokes(WgContext& context, WgRenderDataShape* renderData, BlendMethod blendMethod); + void clipStrokes(WgContext& context, WgRenderDataShape* renderData); + + // images + void drawImage(WgContext& context, WgRenderDataPicture* renderData); + void blendImage(WgContext& context, WgRenderDataPicture* renderData, BlendMethod blendMethod); + void clipImage(WgContext& context, WgRenderDataPicture* renderData); + + // scenes + void drawScene(WgContext& context, WgRenderTarget* scene, WgCompose* compose); + void blendScene(WgContext& context, WgRenderTarget* src, WgCompose* compose); + + // the renderer prioritizes clipping with the stroke over the shape's fill + void markupClipPath(WgContext& context, WgRenderDataShape* renderData); + void renderClipPath(WgContext& context, WgRenderDataPaint* paint); + void clearClipPath(WgContext& context, WgRenderDataPaint* paint); +public: + void initialize(WgContext& context, uint32_t width, uint32_t height); + void initPools(WgContext& context); + void release(WgContext& context); + void releasePools(WgContext& context); + void resize(WgContext& context, uint32_t width, uint32_t height); + + // render passes workflow + void beginRenderPassMS(WGPUCommandEncoder encoder, WgRenderTarget* target, bool clear, WGPUColor clearColor = { 0.0, 0.0, 0.0, 0.0 }); + void beginRenderPass(WGPUCommandEncoder encoder, WgRenderTarget* target); + void endRenderPass(); + + // stage buffers operations + void reset(WgContext& context); + void flush(WgContext& context); + + // request shapes for drawing (staging) + void requestShape(WgRenderDataShape* renderData); + void requestImage(WgRenderDataPicture* renderData); + + // render shapes, images and scenes + void renderShape(WgContext& context, WgRenderDataShape* renderData, BlendMethod blendMethod); + void renderImage(WgContext& context, WgRenderDataPicture* renderData, BlendMethod blendMethod); + void renderScene(WgContext& context, WgRenderTarget* scene, WgCompose* compose); + void composeScene(WgContext& context, WgRenderTarget* src, WgRenderTarget* mask, WgCompose* compose); + + // blit render target to texture view (f.e. screen buffer) + void blit(WgContext& context, WGPUCommandEncoder encoder, WgRenderTarget* src, WGPUTextureView dstView); + + // effects + bool gaussianBlur(WgContext& context, WgRenderTarget* dst, const RenderEffectGaussianBlur* params, const WgCompose* compose); + bool dropShadow(WgContext& context, WgRenderTarget* dst, const RenderEffectDropShadow* params, const WgCompose* compose); + bool fillEffect(WgContext& context, WgRenderTarget* dst, const RenderEffectFill* params, const WgCompose* compose); + bool tintEffect(WgContext& context, WgRenderTarget* dst, const RenderEffectTint* params, const WgCompose* compose); + bool tritoneEffect(WgContext& context, WgRenderTarget* dst, const RenderEffectTritone* params, const WgCompose* compose); +}; + +#endif // _TVG_WG_COMPOSITOR_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgGeometry.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgGeometry.cpp new file mode 100644 index 0000000..84560b9 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgGeometry.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgGeometry.h" + +//*********************************************************************** +// WgMeshData +//*********************************************************************** + +void WgMeshData::bbox(const Point pmin, const Point pmax) +{ + const float vdata[] = {pmin.x, pmin.y, pmax.x, pmin.y, pmax.x, pmax.y, pmin.x, pmax.y}; + const uint32_t idata[] = {0, 1, 2, 0, 2, 3}; + // setup vertex data + vbuffer.reserve(4); + vbuffer.count = 4; + memcpy(vbuffer.data, vdata, sizeof(vdata)); + // setup tex coords data + tbuffer.clear(); + // setup indexes data + ibuffer.reserve(6); + ibuffer.count = 6; + memcpy(ibuffer.data, idata, sizeof(idata)); +} + + +void WgMeshData::imageBox(float w, float h) +{ + const float vdata[] = {0.0f, 0.0f, w, 0.0f, w, h, 0.0f, h}; + const float tdata[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; + const uint32_t idata[] = {0, 1, 2, 0, 2, 3}; + // setup vertex data + vbuffer.reserve(4); + vbuffer.count = 4; + memcpy(vbuffer.data, vdata, sizeof(vdata)); + // setup tex coords data + tbuffer.reserve(4); + tbuffer.count = 4; + memcpy(tbuffer.data, tdata, sizeof(tdata)); + // setup indexes data + ibuffer.reserve(6); + ibuffer.count = 6; + memcpy(ibuffer.data, idata, sizeof(idata)); +} + + +void WgMeshData::blitBox() +{ + const float vdata[] = {-1.0f, +1.0f, +1.0f, +1.0f, +1.0f, -1.0f, -1.0f, -1.0f}; + const float tdata[] = {+0.0f, +0.0f, +1.0f, +0.0f, +1.0f, +1.0f, +0.0f, +1.0f}; + const uint32_t idata[] = { 0, 1, 2, 0, 2, 3 }; + // setup vertex data + vbuffer.reserve(4); + vbuffer.count = 4; + memcpy(vbuffer.data, vdata, sizeof(vdata)); + // setup tex coords data + tbuffer.reserve(4); + tbuffer.count = 4; + memcpy(tbuffer.data, tdata, sizeof(tdata)); + // setup indexes data + ibuffer.reserve(6); + ibuffer.count = 6; + memcpy(ibuffer.data, idata, sizeof(idata)); +} + + +void WgMeshData::clear() +{ + vbuffer.clear(); + tbuffer.clear(); + ibuffer.clear(); + voffset = 0; + toffset = 0; + ioffset = 0; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgGeometry.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgGeometry.h new file mode 100644 index 0000000..d7a1bbe --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgGeometry.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_GEOMETRY_H_ +#define _TVG_WG_GEOMETRY_H_ + +#include +#include "tvgMath.h" +#include "tvgArray.h" + +struct WgMeshData { + Array vbuffer; + Array tbuffer; + Array ibuffer; + size_t voffset{}; + size_t toffset{}; + size_t ioffset{}; + + void bbox(const Point pmin, const Point pmax); + void imageBox(float w, float h); + void blitBox(); + void clear(); + + bool invalid() { return vbuffer.empty(); } +}; + +#endif // _TVG_WG_GEOMETRY_H_ \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgPipelines.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgPipelines.cpp new file mode 100644 index 0000000..7872ca9 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgPipelines.cpp @@ -0,0 +1,600 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgShaderSrc.h" +#include "tvgWgPipelines.h" +#include +#include + +WGPUShaderModule WgPipelines::createShaderModule(WGPUDevice device, const char* label, const char* code) +{ + WGPUShaderSourceWGSL shaderSourceWGSL { + .chain = { .sType = WGPUSType_ShaderSourceWGSL }, + .code = { .data = code, .length = WGPU_STRLEN } + }; + const WGPUShaderModuleDescriptor shaderModuleDesc { + .nextInChain = &shaderSourceWGSL.chain, + .label = { .data = label, .length = WGPU_STRLEN } + }; + return wgpuDeviceCreateShaderModule(device, &shaderModuleDesc); +} + + +WGPUPipelineLayout WgPipelines::createPipelineLayout(WGPUDevice device, const WGPUBindGroupLayout* bindGroupLayouts, const uint32_t bindGroupLayoutsCount) +{ + const WGPUPipelineLayoutDescriptor pipelineLayoutDesc { .bindGroupLayoutCount = bindGroupLayoutsCount, .bindGroupLayouts = bindGroupLayouts }; + return wgpuDeviceCreatePipelineLayout(device, &pipelineLayoutDesc); +} + + +WGPURenderPipeline WgPipelines::createRenderPipeline( + WGPUDevice device, const char* pipelineLabel, + const WGPUShaderModule shaderModule, const char* vsEntryPoint, const char* fsEntryPoint, + const WGPUPipelineLayout pipelineLayout, + const WGPUVertexBufferLayout *vertexBufferLayouts, const uint32_t vertexBufferLayoutsCount, + const WGPUColorWriteMask writeMask, const WGPUTextureFormat colorTargetFormat, const WGPUBlendState blendState, + const WGPUDepthStencilState depthStencilState, const WGPUMultisampleState multisampleState) +{ + const WGPUColorTargetState colorTargetState { .format = colorTargetFormat, .blend = &blendState, .writeMask = writeMask }; + const WGPUColorTargetState colorTargetStates[] { colorTargetState }; + const WGPUPrimitiveState primitiveState { .topology = WGPUPrimitiveTopology_TriangleList }; + const WGPUVertexState vertexState { .module = shaderModule, .entryPoint = { .data = vsEntryPoint, .length = WGPU_STRLEN }, .bufferCount = vertexBufferLayoutsCount, .buffers = vertexBufferLayouts }; + const WGPUFragmentState fragmentState { .module = shaderModule, .entryPoint = { .data = fsEntryPoint, .length = WGPU_STRLEN }, .targetCount = 1, .targets = colorTargetStates }; + const WGPURenderPipelineDescriptor renderPipelineDesc { + .label = { .data = pipelineLabel, .length = WGPU_STRLEN }, + .layout = pipelineLayout, + .vertex = vertexState, + .primitive = primitiveState, + .depthStencil = &depthStencilState, + .multisample = multisampleState, + .fragment = &fragmentState + }; + return wgpuDeviceCreateRenderPipeline(device, &renderPipelineDesc); +} + + +WGPUComputePipeline WgPipelines::createComputePipeline( + WGPUDevice device, const char* pipelineLabel, + const WGPUShaderModule shaderModule, const char* entryPoint, + const WGPUPipelineLayout pipelineLayout) +{ + const WGPUComputePipelineDescriptor computePipelineDesc{ + .label = { .data = pipelineLabel, .length = WGPU_STRLEN }, + .layout = pipelineLayout, + .compute = { + .module = shaderModule, + .entryPoint = { .data = entryPoint, .length = WGPU_STRLEN } + } + }; + return wgpuDeviceCreateComputePipeline(device, &computePipelineDesc); +} + + +void WgPipelines::releaseComputePipeline(WGPUComputePipeline& computePipeline) +{ + if (computePipeline) { + wgpuComputePipelineRelease(computePipeline); + computePipeline = nullptr; + } +} + + +void WgPipelines::releaseRenderPipeline(WGPURenderPipeline& renderPipeline) +{ + if (renderPipeline) { + wgpuRenderPipelineRelease(renderPipeline); + renderPipeline = nullptr; + } +} + + +void WgPipelines::releasePipelineLayout(WGPUPipelineLayout& pipelineLayout) +{ + if (pipelineLayout) { + wgpuPipelineLayoutRelease(pipelineLayout); + pipelineLayout = nullptr; + } +} + + +void WgPipelines::releaseShaderModule(WGPUShaderModule& shaderModule) +{ + if (shaderModule) { + wgpuShaderModuleRelease(shaderModule); + shaderModule = nullptr; + } +} + + +WGPUDepthStencilState WgPipelines::makeDepthStencilState( + const WGPUCompareFunction depthCompare, WGPUOptionalBool depthWriteEnabled, + const WGPUCompareFunction stencilFunction, const WGPUStencilOperation stencilOperation) +{ + return makeDepthStencilState(depthCompare, depthWriteEnabled, stencilFunction, stencilOperation, stencilFunction, stencilOperation); +} + + +WGPUDepthStencilState WgPipelines::makeDepthStencilState( + const WGPUCompareFunction depthCompare, WGPUOptionalBool depthWriteEnabled, + const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt, + const WGPUCompareFunction stencilFunctionBack, const WGPUStencilOperation stencilOperationBack) +{ + const WGPUDepthStencilState depthStencilState { + .format = WGPUTextureFormat_Depth24PlusStencil8, .depthWriteEnabled = depthWriteEnabled, .depthCompare = depthCompare, + .stencilFront = { .compare = stencilFunctionFrnt, .failOp = stencilOperationFrnt, .depthFailOp = WGPUStencilOperation_Zero, .passOp = stencilOperationFrnt }, + .stencilBack = { .compare = stencilFunctionBack, .failOp = stencilOperationBack, .depthFailOp = WGPUStencilOperation_Zero, .passOp = stencilOperationBack }, + .stencilReadMask = 0xFFFFFFFF, .stencilWriteMask = 0xFFFFFFFF + }; + return depthStencilState; +} + + +void WgPipelines::initialize(WgContext& context) +{ + // common pipeline settings + const WGPUVertexAttribute vertexAttributePos { .format = WGPUVertexFormat_Float32x2, .offset = 0, .shaderLocation = 0 }; + const WGPUVertexAttribute vertexAttributeTex { .format = WGPUVertexFormat_Float32x2, .offset = 0, .shaderLocation = 1 }; + const WGPUVertexAttribute vertexAttributesPos[] { vertexAttributePos }; + const WGPUVertexAttribute vertexAttributesTex[] { vertexAttributeTex }; + const WGPUVertexBufferLayout vertexBufferLayoutPos { .stepMode = WGPUVertexStepMode_Vertex, .arrayStride = 8, .attributeCount = 1, .attributes = vertexAttributesPos }; + const WGPUVertexBufferLayout vertexBufferLayoutTex { .stepMode = WGPUVertexStepMode_Vertex, .arrayStride = 8, .attributeCount = 1, .attributes = vertexAttributesTex }; + const WGPUVertexBufferLayout vertexBufferLayoutsShape[] { vertexBufferLayoutPos }; + const WGPUVertexBufferLayout vertexBufferLayoutsImage[] { vertexBufferLayoutPos, vertexBufferLayoutTex }; + const WGPUMultisampleState multisampleState { .count = 4, .mask = 0xFFFFFFFF, .alphaToCoverageEnabled = false }; + const WGPUMultisampleState multisampleStateX1 { .count = 1, .mask = 0xFFFFFFFF, .alphaToCoverageEnabled = false }; + const WGPUTextureFormat offscreenTargetFormat = WGPUTextureFormat_RGBA8Unorm; + + // blend states + WGPUBlendComponent blendComponentSrc { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_Zero }; + WGPUBlendComponent blendComponentNrm { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_OneMinusSrcAlpha }; + const WGPUBlendState blendStateSrc { .color = blendComponentSrc, .alpha = blendComponentSrc }; + const WGPUBlendState blendStateNrm { .color = blendComponentNrm, .alpha = blendComponentNrm }; + + const WgBindGroupLayouts& layouts = context.layouts; + // bind group layouts helpers + const WGPUBindGroupLayout bindGroupLayoutsStencil[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un }; + const WGPUBindGroupLayout bindGroupLayoutsDepth[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutBuffer1Un }; + // bind group layouts normal blend + const WGPUBindGroupLayout bindGroupLayoutsSolid[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un }; + const WGPUBindGroupLayout bindGroupLayoutsGradient[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutTexSampled }; + const WGPUBindGroupLayout bindGroupLayoutsImage[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutTexSampled }; + const WGPUBindGroupLayout bindGroupLayoutsScene[] { layouts.layoutTexSampled, layouts.layoutBuffer1Un }; + // bind group layouts custom blend + const WGPUBindGroupLayout bindGroupLayoutsSolidBlend[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutTexSampled }; + const WGPUBindGroupLayout bindGroupLayoutsGradientBlend[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutTexSampled, layouts.layoutTexSampled }; + const WGPUBindGroupLayout bindGroupLayoutsImageBlend[] { layouts.layoutBuffer1Un, layouts.layoutBuffer1Un, layouts.layoutTexSampled, layouts.layoutTexSampled }; + const WGPUBindGroupLayout bindGroupLayoutsSceneBlend[] { layouts.layoutTexSampled, layouts.layoutTexSampled, layouts.layoutBuffer1Un }; + // bind group layouts scene compose + const WGPUBindGroupLayout bindGroupLayoutsSceneCompose[] { layouts.layoutTexSampled, layouts.layoutTexSampled }; + // bind group layouts blit + const WGPUBindGroupLayout bindGroupLayoutsBlit[] { layouts.layoutTexSampled }; + // bind group layouts effects + const WGPUBindGroupLayout bindGroupLayoutsShadow[] { layouts.layoutTexSampled, layouts.layoutTexSampled, layouts.layoutBuffer1Un }; + const WGPUBindGroupLayout bindGroupLayoutsEffects[] { layouts.layoutTexSampled, layouts.layoutBuffer1Un }; + + // depth stencil state markup + const WGPUDepthStencilState depthStencilStateNonZero = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_False, WGPUCompareFunction_Always, WGPUStencilOperation_IncrementWrap, WGPUCompareFunction_Always, WGPUStencilOperation_DecrementWrap); + const WGPUDepthStencilState depthStencilStateEvenOdd = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_False, WGPUCompareFunction_Always, WGPUStencilOperation_Invert); + const WGPUDepthStencilState depthStencilStateDirect = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_False, WGPUCompareFunction_Always, WGPUStencilOperation_Replace); + // depth stencil state clip path + const WGPUDepthStencilState depthStencilStateCopyStencilToDepth = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_True, WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero); + const WGPUDepthStencilState depthStencilStateCopyStencilToDepthInt = makeDepthStencilState(WGPUCompareFunction_Greater, WGPUOptionalBool_True, WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero); + const WGPUDepthStencilState depthStencilStateCopyDepthToStencil = makeDepthStencilState(WGPUCompareFunction_Equal, WGPUOptionalBool_False, WGPUCompareFunction_Always, WGPUStencilOperation_Replace); + const WGPUDepthStencilState depthStencilStateMergeDepthStencil = makeDepthStencilState(WGPUCompareFunction_Equal, WGPUOptionalBool_True, WGPUCompareFunction_Always, WGPUStencilOperation_Keep); + const WGPUDepthStencilState depthStencilStateClearDepth = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_True, WGPUCompareFunction_Always, WGPUStencilOperation_Keep); + // depth stencil state blend, compose and blit + const WGPUDepthStencilState depthStencilStateShape = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_False, WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero); + const WGPUDepthStencilState depthStencilStateScene = makeDepthStencilState(WGPUCompareFunction_Always, WGPUOptionalBool_False, WGPUCompareFunction_Always, WGPUStencilOperation_Zero); + // shaders + char shaderSourceBuff[16384]{}; + shader_stencil = createShaderModule(context.device, "The shader stencil", cShaderSrc_Stencil); + shader_depth = createShaderModule(context.device, "The shader depth", cShaderSrc_Depth); + // shader normal blend + shader_solid = createShaderModule(context.device, "The shader solid", cShaderSrc_Solid); + shader_radial = createShaderModule(context.device, "The shader radial", cShaderSrc_Radial); + shader_linear = createShaderModule(context.device, "The shader linear", cShaderSrc_Linear); + shader_image = createShaderModule(context.device, "The shader image", cShaderSrc_Image); + shader_scene = createShaderModule(context.device, "The shader scene", cShaderSrc_Scene); + // shader custom blend + shader_solid_blend = createShaderModule(context.device, "The shader blend solid", strcat(strcpy(shaderSourceBuff, cShaderSrc_Solid_Blend), cShaderSrc_BlendFuncs)); + shader_linear_blend = createShaderModule(context.device, "The shader blend linear", strcat(strcpy(shaderSourceBuff, cShaderSrc_Linear_Blend), cShaderSrc_BlendFuncs)); + shader_radial_blend = createShaderModule(context.device, "The shader blend radial", strcat(strcpy(shaderSourceBuff, cShaderSrc_Radial_Blend), cShaderSrc_BlendFuncs)); + shader_image_blend = createShaderModule(context.device, "The shader blend image", strcat(strcpy(shaderSourceBuff, cShaderSrc_Image_Blend), cShaderSrc_BlendFuncs)); + shader_scene_blend = createShaderModule(context.device, "The shader blend scene", strcat(strcpy(shaderSourceBuff, cShaderSrc_Scene_Blend), cShaderSrc_BlendFuncs)); + // shader compose + shader_scene_compose = createShaderModule(context.device, "The shader scene composition", cShaderSrc_Scene_Compose); + // shader blit + shader_blit = createShaderModule(context.device, "The shader blit", cShaderSrc_Blit); + // shader effects + shader_shadow = createShaderModule(context.device, "The shader effects", cShaderSrc_Shadow); + shader_effects = createShaderModule(context.device, "The shader effects", cShaderSrc_Effects); + + // layouts + layout_stencil = createPipelineLayout(context.device, bindGroupLayoutsStencil, 2); + layout_depth = createPipelineLayout(context.device, bindGroupLayoutsDepth, 3); + // layouts normal blend + layout_solid = createPipelineLayout(context.device, bindGroupLayoutsSolid, 2); + layout_gradient = createPipelineLayout(context.device, bindGroupLayoutsGradient, 3); + layout_image = createPipelineLayout(context.device, bindGroupLayoutsImage, 3); + layout_scene = createPipelineLayout(context.device, bindGroupLayoutsScene, 2); + // layouts custom blend + layout_solid_blend = createPipelineLayout(context.device, bindGroupLayoutsSolidBlend, 4); + layout_gradient_blend = createPipelineLayout(context.device, bindGroupLayoutsGradientBlend, 4); + layout_image_blend = createPipelineLayout(context.device, bindGroupLayoutsImageBlend, 4); + layout_scene_blend = createPipelineLayout(context.device, bindGroupLayoutsSceneBlend, 3); + // layout compose + layout_scene_compose = createPipelineLayout(context.device, bindGroupLayoutsSceneCompose, 2); + // layout blit + layout_blit = createPipelineLayout(context.device, bindGroupLayoutsBlit, 1); + // layout effects + layout_shadow = createPipelineLayout(context.device, bindGroupLayoutsShadow, 3); + layout_effects = createPipelineLayout(context.device, bindGroupLayoutsEffects, 2); + + // render pipeline nonzero + nonzero = createRenderPipeline( + context.device, "The render pipeline nonzero", + shader_stencil, "vs_main", "fs_main", + layout_stencil, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateNonZero, multisampleState); + // render pipeline even-odd + evenodd = createRenderPipeline( + context.device, "The render pipeline even-odd", + shader_stencil, "vs_main", "fs_main", + layout_stencil, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateEvenOdd, multisampleState); + // render pipeline direct + direct = createRenderPipeline( + context.device, "The render pipeline direct", + shader_stencil, "vs_main", "fs_main", + layout_stencil, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateDirect, multisampleState); + + // render pipeline copy stencil to depth (front) + copy_stencil_to_depth = createRenderPipeline( + context.device, "The render pipeline copy stencil to depth front", + shader_depth, "vs_main", "fs_main", + layout_depth, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateCopyStencilToDepth , multisampleState); + // render pipeline copy stencil to depth (intermediate) + copy_stencil_to_depth_interm = createRenderPipeline( + context.device, "The render pipeline copy stencil to depth intermediate", + shader_depth, "vs_main", "fs_main", + layout_depth, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateCopyStencilToDepthInt, multisampleState); + // render pipeline depth to stencil + copy_depth_to_stencil = createRenderPipeline( + context.device, "The render pipeline depth to stencil", + shader_depth, "vs_main", "fs_main", + layout_depth, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateCopyDepthToStencil, multisampleState); + // render pipeline merge depth with stencil + merge_depth_stencil = createRenderPipeline( + context.device, "The render pipeline merge depth with stencil", + shader_depth, "vs_main", "fs_main", + layout_depth, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateMergeDepthStencil, multisampleState); + // render pipeline clear depth + clear_depth = createRenderPipeline( + context.device, "The render pipeline clear depth", + shader_depth, "vs_main", "fs_main", + layout_depth, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, + depthStencilStateClearDepth, multisampleState); + + // render pipeline solid + solid = createRenderPipeline( + context.device, "The render pipeline solid", + shader_solid, "vs_main", "fs_main", + layout_solid, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateShape, multisampleState); + // render pipeline radial + radial = createRenderPipeline( + context.device, "The render pipeline radial", + shader_radial, "vs_main", "fs_main", + layout_gradient, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateShape, multisampleState); + // render pipeline linear + linear = createRenderPipeline( + context.device, "The render pipeline linear", + shader_linear, "vs_main", "fs_main", + layout_gradient, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateShape, multisampleState); + // render pipeline solid (no stencil) + solid_conv = createRenderPipeline( + context.device, "The render pipeline solid", + shader_solid, "vs_main", "fs_main", + layout_solid, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateScene, multisampleState); + // render pipeline radial (no stencil) + radial_conv = createRenderPipeline( + context.device, "The render pipeline radial", + shader_radial, "vs_main", "fs_main", + layout_gradient, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateScene, multisampleState); + // render pipeline linear (no stencil) + linear_conv = createRenderPipeline( + context.device, "The render pipeline linear", + shader_linear, "vs_main", "fs_main", + layout_gradient, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateScene, multisampleState); + // render pipeline image + image = createRenderPipeline( + context.device, "The render pipeline image", + shader_image, "vs_main", "fs_main", + layout_image, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateShape, multisampleState); + // render pipeline scene + scene = createRenderPipeline( + context.device, "The render pipeline scene", + shader_scene, "vs_main", "fs_main", + layout_scene, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm, + depthStencilStateScene, multisampleState); + + // blend shader names + const char* shaderBlendNames[] { + "fs_main_Normal", + "fs_main_Multiply", + "fs_main_Screen", + "fs_main_Overlay", + "fs_main_Darken", + "fs_main_Lighten", + "fs_main_ColorDodge", + "fs_main_ColorBurn", + "fs_main_HardLight", + "fs_main_SoftLight", + "fs_main_Difference", + "fs_main_Exclusion", + "fs_main_Hue", + "fs_main_Saturation", + "fs_main_Color", + "fs_main_Luminosity", + "fs_main_Add", + "fs_main_Normal" //TODO: a padding for reserved Hardmix. + }; + + // render pipeline shape blend + for (uint32_t i = 0; i < 18; i++) { + // blend solid + solid_blend[i] = createRenderPipeline( + context.device, "The render pipeline solid blend", + shader_solid_blend, "vs_main", shaderBlendNames[i], + layout_solid_blend, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateShape, multisampleState); + // blend radial + radial_blend[i] = createRenderPipeline( + context.device, "The render pipeline radial blend", + shader_radial_blend, "vs_main", shaderBlendNames[i], + layout_gradient_blend, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateShape, multisampleState); + // blend linear + linear_blend[i] = createRenderPipeline( + context.device, "The render pipeline linear blend", + shader_linear_blend, "vs_main", shaderBlendNames[i], + layout_gradient_blend, vertexBufferLayoutsShape, 1, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateShape, multisampleState); + // blend image + image_blend[i] = createRenderPipeline( + context.device, "The render pipeline image blend", + shader_image_blend, "vs_main", shaderBlendNames[i], + layout_image_blend, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateShape, multisampleState); + // blend scene + scene_blend[i] = createRenderPipeline( + context.device, "The render pipeline scene blend", + shader_scene_blend, "vs_main", shaderBlendNames[i], + layout_scene_blend, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleState); + } + + // compose shader names + const char* shaderComposeNames[] { + "fs_main_None", + "fs_main_AlphaMask", + "fs_main_InvAlphaMask", + "fs_main_LumaMask", + "fs_main_InvLumaMask", + "fs_main_AddMask", + "fs_main_SubtractMask", + "fs_main_IntersectMask", + "fs_main_DifferenceMask", + "fs_main_LightenMask", + "fs_main_DarkenMask" + }; + + // compose shader blend states + const WGPUBlendState composeBlends[] { + blendStateNrm, // None + blendStateNrm, // AlphaMask + blendStateNrm, // InvAlphaMask + blendStateNrm, // LumaMask + blendStateNrm, // InvLumaMask + blendStateSrc, // AddMask + blendStateSrc, // SubtractMask + blendStateSrc, // IntersectMask + blendStateSrc, // DifferenceMask + blendStateSrc, // LightenMask + blendStateSrc // DarkenMask + }; + + // render pipeline scene composition + for (uint32_t i = 0; i < 11; i++) { + scene_compose[i] = createRenderPipeline( + context.device, "The render pipeline scene composition", + shader_scene_compose, "vs_main", shaderComposeNames[i], + layout_scene_compose, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, composeBlends[i], + depthStencilStateScene, multisampleState); + } + + // render pipeline blit + blit = createRenderPipeline( + context.device, "The render pipeline blit", + shader_blit, "vs_main", "fs_main", + layout_blit, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, context.preferredFormat, blendStateSrc, // must be preferred screen pixel format + depthStencilStateScene, multisampleStateX1); + + // effects + dropshadow = createRenderPipeline( + context.device, "The render pipeline drop shadow", + shader_shadow, "vs_main", "fs_main_shadow", + layout_shadow, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleStateX1); + + gaussian_vert = createRenderPipeline( + context.device, "The render pipeline gaussian vert", + shader_effects, "vs_main", "fs_main_vert", + layout_effects, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleStateX1); + + gaussian_horz = createRenderPipeline( + context.device, "The render pipeline gaussian horz", + shader_effects, "vs_main", "fs_main_horz", + layout_effects, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleStateX1); + + fill_effect = createRenderPipeline( + context.device, "The render pipeline fill effect", + shader_effects, "vs_main", "fs_main_fill", + layout_effects, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleStateX1); + + tint_effect = createRenderPipeline( + context.device, "The render pipeline tint effect", + shader_effects, "vs_main", "fs_main_tint", + layout_effects, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleStateX1); + + tritone_effect = createRenderPipeline( + context.device, "The render pipeline tritone effect", + shader_effects, "vs_main", "fs_main_tritone", + layout_effects, vertexBufferLayoutsImage, 2, + WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc, + depthStencilStateScene, multisampleStateX1); + +} + +void WgPipelines::releaseGraphicHandles(WgContext& context) +{ + // pipeline effects + releaseRenderPipeline(tritone_effect); + releaseRenderPipeline(tint_effect); + releaseRenderPipeline(fill_effect); + releaseRenderPipeline(gaussian_horz); + releaseRenderPipeline(gaussian_vert); + releaseRenderPipeline(dropshadow); + // pipeline blit + releaseRenderPipeline(blit); + // pipelines compose + for (uint32_t i = 0; i < 11; i++) + releaseRenderPipeline(scene_compose[i]); + // pipelines custom blend + for (uint32_t i = 0; i < 18; i++) { + releaseRenderPipeline(scene_blend[i]); + releaseRenderPipeline(image_blend[i]); + releaseRenderPipeline(linear_blend[i]); + releaseRenderPipeline(radial_blend[i]); + releaseRenderPipeline(solid_blend[i]); + } + // pipelines normal blend + releaseRenderPipeline(scene); + releaseRenderPipeline(image); + releaseRenderPipeline(linear_conv); + releaseRenderPipeline(radial_conv); + releaseRenderPipeline(solid_conv); + releaseRenderPipeline(linear); + releaseRenderPipeline(radial); + releaseRenderPipeline(solid); + // pipelines clip path markup + releaseRenderPipeline(clear_depth); + releaseRenderPipeline(merge_depth_stencil); + releaseRenderPipeline(copy_depth_to_stencil); + releaseRenderPipeline(copy_stencil_to_depth_interm); + releaseRenderPipeline(copy_stencil_to_depth); + // pipelines stencil markup + releaseRenderPipeline(direct); + releaseRenderPipeline(evenodd); + releaseRenderPipeline(nonzero); + // layouts + releasePipelineLayout(layout_effects); + releasePipelineLayout(layout_shadow); + releasePipelineLayout(layout_blit); + releasePipelineLayout(layout_scene_compose); + releasePipelineLayout(layout_scene_blend); + releasePipelineLayout(layout_image_blend); + releasePipelineLayout(layout_gradient_blend); + releasePipelineLayout(layout_solid_blend); + releasePipelineLayout(layout_scene); + releasePipelineLayout(layout_image); + releasePipelineLayout(layout_gradient); + releasePipelineLayout(layout_solid); + releasePipelineLayout(layout_depth); + releasePipelineLayout(layout_stencil); + // shaders + releaseShaderModule(shader_effects); + releaseShaderModule(shader_shadow); + releaseShaderModule(shader_blit); + releaseShaderModule(shader_scene_compose); + releaseShaderModule(shader_scene_blend); + releaseShaderModule(shader_image_blend); + releaseShaderModule(shader_linear_blend); + releaseShaderModule(shader_radial_blend); + releaseShaderModule(shader_solid_blend); + releaseShaderModule(shader_scene); + releaseShaderModule(shader_image); + releaseShaderModule(shader_linear); + releaseShaderModule(shader_radial); + releaseShaderModule(shader_solid); + releaseShaderModule(shader_depth); + releaseShaderModule(shader_stencil); +} + + +void WgPipelines::release(WgContext& context) +{ + releaseGraphicHandles(context); +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgPipelines.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgPipelines.h new file mode 100644 index 0000000..e579a04 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgPipelines.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_PIPELINES_H_ +#define _TVG_WG_PIPELINES_H_ + +#include "tvgWgCommon.h" + +class WgPipelines { +private: + // shaders helpers + WGPUShaderModule shader_stencil{}; + WGPUShaderModule shader_depth{}; + // shaders normal blend + WGPUShaderModule shader_solid{}; + WGPUShaderModule shader_radial{}; + WGPUShaderModule shader_linear{}; + WGPUShaderModule shader_image{}; + WGPUShaderModule shader_scene{}; + // shaders custom blend + WGPUShaderModule shader_solid_blend{}; + WGPUShaderModule shader_radial_blend{}; + WGPUShaderModule shader_linear_blend{}; + WGPUShaderModule shader_image_blend{}; + WGPUShaderModule shader_scene_blend{}; + // shader scene compose + WGPUShaderModule shader_scene_compose{}; + // shader blit + WGPUShaderModule shader_blit{}; + // shader effects + WGPUShaderModule shader_shadow; + WGPUShaderModule shader_effects; + + // layouts helpers + WGPUPipelineLayout layout_stencil{}; + WGPUPipelineLayout layout_depth{}; + // layouts normal blend + WGPUPipelineLayout layout_solid{}; + WGPUPipelineLayout layout_gradient{}; + WGPUPipelineLayout layout_image{}; + WGPUPipelineLayout layout_scene{}; + // layouts custom blend + WGPUPipelineLayout layout_solid_blend{}; + WGPUPipelineLayout layout_gradient_blend{}; + WGPUPipelineLayout layout_image_blend{}; + WGPUPipelineLayout layout_scene_blend{}; + // layouts scene compose + WGPUPipelineLayout layout_scene_compose{}; + // layouts blit + WGPUPipelineLayout layout_blit{}; + // layouts effects + WGPUPipelineLayout layout_shadow{}; + WGPUPipelineLayout layout_effects{}; +public: + // pipelines stencil markup + WGPURenderPipeline nonzero{}; + WGPURenderPipeline evenodd{}; + WGPURenderPipeline direct{}; + // pipelines clip path markup + WGPURenderPipeline copy_stencil_to_depth{}; // depth 0.50, clear stencil + WGPURenderPipeline copy_stencil_to_depth_interm{}; // depth 0.75, clear stencil + WGPURenderPipeline copy_depth_to_stencil{}; // depth 0.50 and 0.75, update stencil + WGPURenderPipeline merge_depth_stencil{}; // depth 0.75, update stencil + WGPURenderPipeline clear_depth{}; // depth 1.00, clear ctencil + // pipelines normal blend + WGPURenderPipeline solid{}; + WGPURenderPipeline radial{}; + WGPURenderPipeline linear{}; + WGPURenderPipeline solid_conv{}; // convex geometry (no stencil) + WGPURenderPipeline radial_conv{}; // convex geometry (no stencil) + WGPURenderPipeline linear_conv{}; // convex geometry (no stencil) + WGPURenderPipeline image{}; + WGPURenderPipeline scene{}; + // pipelines custom blend + WGPURenderPipeline solid_blend[18]{}; + WGPURenderPipeline radial_blend[18]{}; + WGPURenderPipeline linear_blend[18]{}; + WGPURenderPipeline image_blend[18]{}; + WGPURenderPipeline scene_blend[18]{}; + // pipelines compose + WGPURenderPipeline scene_compose[11]{}; + // pipeline blit + WGPURenderPipeline blit{}; + // effects + WGPURenderPipeline gaussian_vert{}; + WGPURenderPipeline gaussian_horz{}; + WGPURenderPipeline dropshadow{}; + WGPURenderPipeline fill_effect{}; + WGPURenderPipeline tint_effect{}; + WGPURenderPipeline tritone_effect{}; +private: + void releaseGraphicHandles(WgContext& context); + WGPUShaderModule createShaderModule(WGPUDevice device, const char* label, const char* code); + WGPUPipelineLayout createPipelineLayout(WGPUDevice device, const WGPUBindGroupLayout* bindGroupLayouts, const uint32_t bindGroupLayoutsCount); + WGPURenderPipeline createRenderPipeline( + WGPUDevice device, const char* pipelineLabel, + const WGPUShaderModule shaderModule, const char* vsEntryPoint, const char* fsEntryPoint, + const WGPUPipelineLayout pipelineLayout, + const WGPUVertexBufferLayout *vertexBufferLayouts, const uint32_t vertexBufferLayoutsCount, + const WGPUColorWriteMask writeMask, const WGPUTextureFormat colorTargetFormat, const WGPUBlendState blendState, + const WGPUDepthStencilState depthStencilState, const WGPUMultisampleState multisampleState); + WGPUComputePipeline createComputePipeline( + WGPUDevice device, const char* pipelineLabel, + const WGPUShaderModule shaderModule, const char* entryPoint, + const WGPUPipelineLayout pipelineLayout); + void releaseComputePipeline(WGPUComputePipeline& computePipeline); + void releaseRenderPipeline(WGPURenderPipeline& renderPipeline); + void releasePipelineLayout(WGPUPipelineLayout& pipelineLayout); + void releaseShaderModule(WGPUShaderModule& shaderModule); + + WGPUDepthStencilState makeDepthStencilState( + const WGPUCompareFunction depthCompare, WGPUOptionalBool depthWriteEnabled, + const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt); + WGPUDepthStencilState makeDepthStencilState( + const WGPUCompareFunction depthCompare, WGPUOptionalBool depthWriteEnabled, + const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt, + const WGPUCompareFunction stencilFunctionBack, const WGPUStencilOperation stencilOperationBack); +public: + void initialize(WgContext& context); + void release(WgContext& context); +}; + +#endif // _TVG_WG_PIPELINES_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderData.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderData.cpp new file mode 100644 index 0000000..46bee15 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderData.cpp @@ -0,0 +1,623 @@ + +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgWgTessellator.h" +#include "tvgWgRenderData.h" +#include "tvgWgShaderTypes.h" + +//*********************************************************************** +// WgImageData +//*********************************************************************** + +void WgImageData::update(WgContext& context, const RenderSurface* surface) +{ + // get appropriate texture format from color space + WGPUTextureFormat texFormat = WGPUTextureFormat_BGRA8Unorm; + if (surface->cs == ColorSpace::ABGR8888S) + texFormat = WGPUTextureFormat_RGBA8Unorm; + if (surface->cs == ColorSpace::Grayscale8) + texFormat = WGPUTextureFormat_R8Unorm; + // allocate new texture handle + bool texHandleChanged = context.allocateTexture(texture, surface->w, surface->h, texFormat, surface->data); + // update texture view of texture handle was changed + if (texHandleChanged) { + context.releaseTextureView(textureView); + textureView = context.createTextureView(texture); + // update bind group + context.layouts.releaseBindGroup(bindGroup); + bindGroup = context.layouts.createBindGroupTexSampled(context.samplerLinearClamp, textureView); + } +}; + + +void WgImageData::update(WgContext& context, const Fill* fill) +{ + // compute gradient data + WgShaderTypeGradientData gradientData; + gradientData.update(fill); + // allocate new texture handle + bool texHandleChanged = context.allocateTexture(texture, WG_TEXTURE_GRADIENT_SIZE, 1, WGPUTextureFormat_RGBA8Unorm, gradientData.data); + // update texture view of texture handle was changed + if (texHandleChanged) { + context.releaseTextureView(textureView); + textureView = context.createTextureView(texture); + // get sampler by spread type + WGPUSampler sampler = context.samplerLinearClamp; + if (fill->spread() == FillSpread::Reflect) sampler = context.samplerLinearMirror; + if (fill->spread() == FillSpread::Repeat) sampler = context.samplerLinearRepeat; + // update bind group + context.layouts.releaseBindGroup(bindGroup); + bindGroup = context.layouts.createBindGroupTexSampled(sampler, textureView); + } +}; + + +void WgImageData::release(WgContext& context) +{ + context.layouts.releaseBindGroup(bindGroup); + context.releaseTextureView(textureView); + context.releaseTexture(texture); +}; + +//*********************************************************************** +// WgRenderSettings +//*********************************************************************** + +void WgRenderSettings::update(WgContext& context, const tvg::Matrix& transform, tvg::ColorSpace cs, uint8_t opacity) +{ + //TODO: Update separately according to the RenderUpdateFlag + settings.transform.update(transform); + settings.options.update(cs, opacity * opacityMultiplier); +} + +void WgRenderSettings::update(WgContext& context, const Fill* fill) +{ + assert(fill); + settings.gradient.update(fill); + gradientData.update(context, fill); + // get gradient rasterisation settings + rasterType = WgRenderRasterType::Gradient; + if (fill->type() == Type::LinearGradient) + fillType = WgRenderSettingsType::Linear; + else if (fill->type() == Type::RadialGradient) + fillType = WgRenderSettingsType::Radial; +}; + + +void WgRenderSettings::update(WgContext& context, const RenderColor& c) +{ + settings.color.update(c); + rasterType = WgRenderRasterType::Solid; + fillType = WgRenderSettingsType::Solid; +}; + + +void WgRenderSettings::release(WgContext& context) +{ + gradientData.release(context); +}; + +//*********************************************************************** +// WgRenderDataPaint +//*********************************************************************** + +void WgRenderDataPaint::release(WgContext& context) +{ + clips.clear(); +}; + + +void WgRenderDataPaint::updateClips(tvg::Array &clips) { + this->clips.clear(); + ARRAY_FOREACH(p, clips) { + this->clips.push((WgRenderDataPaint*)(*p)); + } +} + +//*********************************************************************** +// WgRenderDataShape +//*********************************************************************** + +void WgRenderDataShape::updateBBox(BBox bb) +{ + bbox.min = tvg::min(bbox.min, bb.min); + bbox.max = tvg::max(bbox.max, bb.max); +} + + +void WgRenderDataShape::updateAABB(const Matrix& matrix) +{ + auto p0 = Point{bbox.min.x, bbox.min.y} * matrix; + auto p1 = Point{bbox.max.x, bbox.min.y} * matrix; + auto p2 = Point{bbox.min.x, bbox.max.y} * matrix; + auto p3 = Point{bbox.max.x, bbox.max.y} * matrix; + aabb.min = {std::min(std::min(p0.x, p1.x), std::min(p2.x, p3.x)), std::min(std::min(p0.y, p1.y), std::min(p2.y, p3.y))}; + aabb.max = {std::max(std::max(p0.x, p1.x), std::max(p2.x, p3.x)), std::max(std::max(p0.y, p1.y), std::max(p2.y, p3.y))}; +} + + +void WgRenderDataShape::updateVisibility(const RenderShape& rshape, uint8_t opacity) +{ + renderSettingsShape.skip = (rshape.color.a * opacity == 0) && (!rshape.fill); + renderSettingsStroke.skip = rshape.stroke ? (rshape.stroke->color.a * opacity == 0) && (!rshape.stroke->fill) : true; +} + + +void WgRenderDataShape::updateMeshes(const RenderShape &rshape, RenderUpdateFlag flag, const Matrix& matrix) +{ + releaseMeshes(); //Optimize: bad idea to reset meshes always. it could re-use the meshes if there haven't been any path changes. + + convex = false; + strokeFirst = rshape.strokeFirst(); + renderSettingsShape.opacityMultiplier = 1.0f; + renderSettingsStroke.opacityMultiplier = 1.0f; + + // optimize path + RenderPath optPath; + if (rshape.trimpath()) { + RenderPath trimmedPath; + if (rshape.stroke->trim.trim(rshape.path, trimmedPath)) { + trimmedPath.optimize(optPath, matrix); + } else { + optPath.clear(); + } + } else rshape.path.optimize(optPath, matrix); + + auto updatePath = flag & (RenderUpdateFlag::Transform | RenderUpdateFlag::Path); + + // update fill shapes + if (updatePath || (flag & (RenderUpdateFlag::Color | RenderUpdateFlag::Gradient))) { + BBox bbox; + // in a case of single line shape we must tesselate it as a single line stroke with minimal width + if (optPath.pts.count == 2 && tvg::zero(rshape.strokeWidth())) { + WgStroker stroker(&meshShape, MIN_WG_STROKE_WIDTH / scaling(matrix), StrokeCap::Butt, StrokeJoin::Bevel); + stroker.run(rshape, optPath, matrix); + bbox = stroker.getBBox(); + renderSettingsShape.opacityMultiplier = MIN_WG_STROKE_ALPHA; + } else { + WgBWTessellator bwTess{&meshShape}; + bwTess.tessellate(optPath, matrix); + convex = bwTess.convex; + bbox = bwTess.getBBox(); + } + if (meshShape.ibuffer.empty()) { + meshShape.clear(); + } else { + meshShapeBBox.bbox(bbox.min, bbox.max); + updateBBox(bbox); + } + } + // update strokes shapes + if (rshape.stroke && (updatePath || (flag & (RenderUpdateFlag::Stroke | RenderUpdateFlag::GradientStroke)))) { + auto strokeWidth = 0.0f; + if (isinf(matrix.e11)) { + strokeWidth = rshape.strokeWidth() * scaling(matrix); + if (strokeWidth <= MIN_WG_STROKE_WIDTH) strokeWidth = MIN_WG_STROKE_WIDTH; + strokeWidth = strokeWidth / matrix.e11; + } else { + strokeWidth = rshape.strokeWidth(); + } + //run stroking only if it's valid + if (!tvg::zero(strokeWidth)) { + WgStroker stroker(&meshStrokes, strokeWidth, rshape.strokeCap(), rshape.strokeJoin()); + stroker.run(rshape, optPath, matrix); + renderSettingsStroke.opacityMultiplier = 1.0f; + if (meshStrokes.ibuffer.empty()) { + meshStrokes.clear(); + } else { + auto bbox = stroker.getBBox(); + meshStrokesBBox.bbox(bbox.min, bbox.max); + updateBBox(bbox); + } + } + } + // update shapes bbox (with empty path handling) + if (!meshShape.vbuffer.empty() || !meshStrokes.vbuffer.empty()) updateAABB(matrix); + else bbox = aabb = {{0, 0}, {0, 0}}; + meshBBox.bbox(bbox.min, bbox.max); +} + + +void WgRenderDataShape::releaseMeshes() +{ + meshStrokes.clear(); + meshShape.clear(); + bbox.min = {FLT_MAX, FLT_MAX}; + bbox.max = {0.0f, 0.0f}; + aabb = {{0, 0}, {0, 0}}; + clips.clear(); +} + + +void WgRenderDataShape::release(WgContext& context) +{ + releaseMeshes(); + renderSettingsStroke.release(context); + renderSettingsShape.release(context); + WgRenderDataPaint::release(context); +}; + +//*********************************************************************** +// WgRenderDataShapePool +//*********************************************************************** + +WgRenderDataShape* WgRenderDataShapePool::allocate(WgContext& context) +{ + WgRenderDataShape* renderData{}; + if (mPool.count > 0) { + renderData = mPool.last(); + mPool.pop(); + } else { + renderData = new WgRenderDataShape(); + mList.push(renderData); + } + return renderData; +} + + +void WgRenderDataShapePool::free(WgContext& context, WgRenderDataShape* renderData) +{ + renderData->releaseMeshes(); + renderData->clips.clear(); + mPool.push(renderData); +} + + +void WgRenderDataShapePool::release(WgContext& context) +{ + ARRAY_FOREACH(p, mList) { + (*p)->release(context); + delete(*p); + } + mPool.clear(); + mList.clear(); +} + +//*********************************************************************** +// WgRenderDataPicture +//*********************************************************************** + +void WgRenderDataPicture::updateSurface(WgContext& context, const RenderSurface* surface) +{ + // upoate mesh data + meshData.imageBox(surface->w, surface->h); + // update texture data + imageData.update(context, surface); +} + + +void WgRenderDataPicture::release(WgContext& context) +{ + renderSettings.release(context); + imageData.release(context); + WgRenderDataPaint::release(context); +} + +//*********************************************************************** +// WgRenderDataPicturePool +//*********************************************************************** + +WgRenderDataPicture* WgRenderDataPicturePool::allocate(WgContext& context) +{ + WgRenderDataPicture* renderData{}; + if (mPool.count > 0) { + renderData = mPool.last(); + mPool.pop(); + } else { + renderData = new WgRenderDataPicture(); + mList.push(renderData); + } + return renderData; +} + + +void WgRenderDataPicturePool::free(WgContext& context, WgRenderDataPicture* renderData) +{ + renderData->clips.clear(); + mPool.push(renderData); +} + + +void WgRenderDataPicturePool::release(WgContext& context) +{ + ARRAY_FOREACH(p, mList) { + (*p)->release(context); + delete(*p); + } + mPool.clear(); + mList.clear(); +} + +//*********************************************************************** +// WgRenderDataEffectParams +//*********************************************************************** + +void WgRenderDataEffectParams::update(WgContext& context, WgShaderTypeEffectParams& effectParams) +{ + if (context.allocateBufferUniform(bufferParams, &effectParams.params, sizeof(effectParams.params))) { + context.layouts.releaseBindGroup(bindGroupParams); + bindGroupParams = context.layouts.createBindGroupBuffer1Un(bufferParams); + } +} + + +void WgRenderDataEffectParams::update(WgContext& context, RenderEffectGaussianBlur* gaussian, const Matrix& transform) +{ + assert(gaussian); + WgShaderTypeEffectParams effectParams; + if (!effectParams.update(gaussian, transform)) return; + update(context, effectParams); + extend = effectParams.extend; +} + + +void WgRenderDataEffectParams::update(WgContext& context, RenderEffectDropShadow* dropShadow, const Matrix& transform) +{ + assert(dropShadow); + WgShaderTypeEffectParams effectParams; + if (!effectParams.update(dropShadow, transform)) return; + update(context, effectParams); + extend = effectParams.extend; + offset = effectParams.offset; +} + + +void WgRenderDataEffectParams::update(WgContext& context, RenderEffectFill* fill) +{ + assert(fill); + WgShaderTypeEffectParams effectParams; + if (!effectParams.update(fill)) return; + update(context, effectParams); +} + + +void WgRenderDataEffectParams::update(WgContext& context, RenderEffectTint* tint) +{ + assert(tint); + WgShaderTypeEffectParams effectParams; + if (!effectParams.update(tint)) return; + update(context, effectParams); +} + + +void WgRenderDataEffectParams::update(WgContext& context, RenderEffectTritone* tritone) +{ + assert(tritone); + WgShaderTypeEffectParams effectParams; + if (!effectParams.update(tritone)) return; + update(context, effectParams); +} + + +void WgRenderDataEffectParams::release(WgContext& context) +{ + context.releaseBuffer(bufferParams); + context.layouts.releaseBindGroup(bindGroupParams); +} + +//*********************************************************************** +// WgRenderDataColorsPool +//*********************************************************************** + +WgRenderDataEffectParams* WgRenderDataEffectParamsPool::allocate(WgContext& context) +{ + WgRenderDataEffectParams* renderData{}; + if (mPool.count > 0) { + renderData = mPool.last(); + mPool.pop(); + } else { + renderData = new WgRenderDataEffectParams(); + mList.push(renderData); + } + return renderData; +} + + +void WgRenderDataEffectParamsPool::free(WgContext& context, WgRenderDataEffectParams* renderData) +{ + if (renderData) mPool.push(renderData); +} + + +void WgRenderDataEffectParamsPool::release(WgContext& context) +{ + ARRAY_FOREACH(p, mList) { + (*p)->release(context); + delete(*p); + } + mPool.clear(); + mList.clear(); +} + +//*********************************************************************** +// WgStageBufferGeometry +//*********************************************************************** + +void WgStageBufferGeometry::append(WgMeshData* meshData) +{ + assert(meshData); + uint32_t vsize = meshData->vbuffer.count * sizeof(meshData->vbuffer[0]); + uint32_t tsize = meshData->tbuffer.count * sizeof(meshData->tbuffer[0]); + uint32_t isize = meshData->ibuffer.count * sizeof(meshData->ibuffer[0]); + // append vertex data + if (vbuffer.reserved < vbuffer.count + vsize) + vbuffer.grow(std::max(vsize, vbuffer.reserved)); + if (meshData->vbuffer.count > 0) { + meshData->voffset = vbuffer.count; + memcpy(vbuffer.data + vbuffer.count, meshData->vbuffer.data, vsize); + vbuffer.count += vsize; + } + // append tex coords data + if (vbuffer.reserved < vbuffer.count + tsize) + vbuffer.grow(std::max(tsize, vbuffer.reserved)); + if (meshData->tbuffer.count > 0) { + meshData->toffset = vbuffer.count; + memcpy(vbuffer.data + vbuffer.count, meshData->tbuffer.data, tsize); + vbuffer.count += tsize; + } + // append index data + if (ibuffer.reserved < ibuffer.count + isize) + ibuffer.grow(std::max(isize, ibuffer.reserved)); + if (meshData->ibuffer.count > 0) { + meshData->ioffset = ibuffer.count; + memcpy(ibuffer.data + ibuffer.count, meshData->ibuffer.data, isize); + ibuffer.count += isize; + } +} + + +void WgStageBufferGeometry::append(WgRenderDataShape* renderDataShape) +{ + append(&renderDataShape->meshShape); + append(&renderDataShape->meshShapeBBox); + append(&renderDataShape->meshStrokes); + append(&renderDataShape->meshStrokesBBox); + append(&renderDataShape->meshBBox); +} + + +void WgStageBufferGeometry::append(WgRenderDataPicture* renderDataPicture) +{ + append(&renderDataPicture->meshData); +} + + +void WgStageBufferGeometry::release(WgContext& context) +{ + context.releaseBuffer(vbuffer_gpu); + context.releaseBuffer(ibuffer_gpu); +} + + +void WgStageBufferGeometry::clear() +{ + vbuffer.clear(); + ibuffer.clear(); +} + + +void WgStageBufferGeometry::flush(WgContext& context) +{ + context.allocateBufferVertex(vbuffer_gpu, (float *)vbuffer.data, vbuffer.count); + context.allocateBufferIndex(ibuffer_gpu, (uint32_t *)ibuffer.data, ibuffer.count); +} + +//*********************************************************************** +// WgIntersector +//*********************************************************************** + +bool WgIntersector::isPointInTriangle(const Point& p, const Point& a, const Point& b, const Point& c) +{ + auto d1 = tvg::cross(p - a, p - b); + auto d2 = tvg::cross(p - b, p - c); + auto d3 = tvg::cross(p - c, p - a); + auto has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0); + auto has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0); + return !(has_neg && has_pos); +} + + +// triangle list +bool WgIntersector::isPointInTris(const Point& p, const WgMeshData& mesh, const Matrix& tr) +{ + for (uint32_t i = 0; i < mesh.ibuffer.count; i += 3) { + auto p0 = mesh.vbuffer[mesh.ibuffer[i+0]] * tr; + auto p1 = mesh.vbuffer[mesh.ibuffer[i+1]] * tr; + auto p2 = mesh.vbuffer[mesh.ibuffer[i+2]] * tr; + if (isPointInTriangle(p, p0, p1, p2)) return true; + } + return false; +} + + +// even-odd triangle list +bool WgIntersector::isPointInMesh(const Point& p, const WgMeshData& mesh, const Matrix& tr) +{ + uint32_t crossings = 0; + for (uint32_t i = 0; i < mesh.ibuffer.count; i += 3) { + Point triangle[3] = { + mesh.vbuffer[mesh.ibuffer[i+0]] * tr, + mesh.vbuffer[mesh.ibuffer[i+1]] * tr, + mesh.vbuffer[mesh.ibuffer[i+2]] * tr + }; + for (uint32_t j = 0; j < 3; j++) { + auto p1 = triangle[j]; + auto p2 = triangle[(j + 1) % 3]; + if (p1.y == p2.y) continue; + if (p1.y > p2.y) std::swap(p1, p2); + if ((p.y > p1.y) && (p.y <= p2.y)) { + auto intersectionX = (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x; + if (intersectionX > p.x) crossings++; + } + } + } + return (crossings % 2) == 1; +} + + +bool WgIntersector::intersectClips(const Point& pt, const Array& clips) +{ + for (uint32_t i = 0; i < clips.count; i++) { + auto clip = (WgRenderDataShape*)clips[i]; + if (!isPointInMesh(pt, clip->meshShape, clip->transform)) return false; + } + return true; +} + + +bool WgIntersector::intersectShape(const RenderRegion region, const WgRenderDataShape* shape) +{ + if (!shape || ((shape->meshShape.ibuffer.count == 0) && (shape->meshStrokes.ibuffer.count == 0))) return false; + auto sizeX = region.sw(); + auto sizeY = region.sh(); + for (int32_t y = 0; y <= sizeY; y++) { + for (int32_t x = 0; x <= sizeX; x++) { + Point pt{(float)x + region.min.x, (float)y + region.min.y}; + if (y % 2 == 1) pt.y = (float) sizeY - y - sizeY % 2 + region.min.y; + if (intersectClips(pt, shape->clips)) { + if (!shape->renderSettingsShape.skip && isPointInMesh(pt, shape->meshShape, shape->transform)) return true; + if (!shape->renderSettingsStroke.skip && isPointInTris(pt, shape->meshStrokes, shape->transform)) return true; + } + } + } + return false; +} + + +bool WgIntersector::intersectImage(const RenderRegion region, const WgRenderDataPicture* image) +{ + if (!image) return false; + auto sizeX = region.sw(); + auto sizeY = region.sh(); + for (int32_t y = 0; y <= sizeY; y++) { + for (int32_t x = 0; x <= sizeX; x++) { + Point pt{(float)x + region.min.x, (float)y + region.min.y}; + if (y % 2 == 1) pt.y = (float) sizeY - y - sizeY % 2 + region.min.y; + if (intersectClips(pt, image->clips)) { + if (isPointInTris(pt, image->meshData, image->transform)) return true; + } + } + } + return false; +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderData.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderData.h new file mode 100644 index 0000000..25bc540 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderData.h @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_RENDER_DATA_H_ +#define _TVG_WG_RENDER_DATA_H_ + +#include "tvgWgPipelines.h" +#include "tvgWgGeometry.h" +#include "tvgWgShaderTypes.h" + +struct WgImageData { + WGPUTexture texture{}; + WGPUTextureView textureView{}; + WGPUBindGroup bindGroup{}; + + void update(WgContext& context, const RenderSurface* surface); + void update(WgContext& context, const Fill* fill); + void release(WgContext& context); +}; + +enum class WgRenderSettingsType { None = 0, Solid = 1, Linear = 2, Radial = 3 }; +enum class WgRenderRasterType { Solid = 0, Gradient, Image }; + +struct WgRenderSettings +{ + uint32_t bindGroupInd{}; + WgShaderTypePaintSettings settings; + WgImageData gradientData; + WgRenderSettingsType fillType{}; + WgRenderRasterType rasterType{}; + float opacityMultiplier = 1.0f; + bool skip{}; + + void update(WgContext& context, const tvg::Matrix& transform, tvg::ColorSpace cs, uint8_t opacity); + void update(WgContext& context, const Fill* fill); + void update(WgContext& context, const RenderColor& c); + void release(WgContext& context); +}; + +struct WgRenderDataPaint +{ + BBox aabb{{},{}}; + RenderRegion viewport{}; + Array clips; + Matrix transform; + + virtual ~WgRenderDataPaint() {}; + virtual void release(WgContext& context); + virtual Type type() { return Type::Undefined; }; + + void updateClips(tvg::Array &clips); +}; + +struct WgRenderDataShape: public WgRenderDataPaint +{ + WgRenderSettings renderSettingsShape{}; + WgRenderSettings renderSettingsStroke{}; + WgMeshData meshBBox{}; + WgMeshData meshShape{}; + WgMeshData meshShapeBBox{}; + WgMeshData meshStrokes{}; + WgMeshData meshStrokesBBox{}; + bool strokeFirst{}; + FillRule fillRule{}; + bool convex{}; + BBox bbox; + + void updateBBox(BBox bb); + void updateAABB(const Matrix& matrix); + void updateVisibility(const RenderShape& rshape, uint8_t opacity); + void updateMeshes(const RenderShape& rshape, RenderUpdateFlag flag, const Matrix& matrix); + void releaseMeshes(); + void release(WgContext& context) override; + Type type() override { return Type::Shape; }; +}; + +class WgRenderDataShapePool { +private: + Array mPool; + Array mList; +public: + WgRenderDataShape* allocate(WgContext& context); + void free(WgContext& context, WgRenderDataShape* renderData); + void release(WgContext& context); +}; + +struct WgRenderDataPicture: public WgRenderDataPaint +{ + WgRenderSettings renderSettings{}; + WgImageData imageData{}; + WgMeshData meshData{}; + + void updateSurface(WgContext& context, const RenderSurface* surface); + void release(WgContext& context) override; + Type type() override { return Type::Picture; }; +}; + +class WgRenderDataPicturePool { +private: + Array mPool; + Array mList; +public: + WgRenderDataPicture* allocate(WgContext& context); + void free(WgContext& context, WgRenderDataPicture* dataPicture); + void release(WgContext& context); +}; + +// gaussian blur, drop shadow, fill, tint, tritone +#define WG_GAUSSIAN_MAX_LEVEL 3 +struct WgRenderDataEffectParams +{ + WGPUBindGroup bindGroupParams{}; + WGPUBuffer bufferParams{}; + uint32_t extend{}; + Point offset{}; + + void update(WgContext& context, WgShaderTypeEffectParams& effectParams); + void update(WgContext& context, RenderEffectGaussianBlur* gaussian, const Matrix& transform); + void update(WgContext& context, RenderEffectDropShadow* dropShadow, const Matrix& transform); + void update(WgContext& context, RenderEffectFill* fill); + void update(WgContext& context, RenderEffectTint* tint); + void update(WgContext& context, RenderEffectTritone* tritone); + void release(WgContext& context); +}; + +// effect params pool +class WgRenderDataEffectParamsPool { +private: + // pool contains all created but unused render data for params + Array mPool; + // list contains all created render data for params + // to ensure that all created instances will be released + Array mList; +public: + WgRenderDataEffectParams* allocate(WgContext& context); + void free(WgContext& context, WgRenderDataEffectParams* renderData); + void release(WgContext& context); +}; + +class WgStageBufferGeometry { +private: + Array vbuffer; + Array ibuffer; +public: + WGPUBuffer vbuffer_gpu{}; + WGPUBuffer ibuffer_gpu{}; + + void append(WgMeshData* meshData); + void append(WgRenderDataShape* renderDataShape); + void append(WgRenderDataPicture* renderDataPicture); + void initialize(WgContext& context){}; + void release(WgContext& context); + void clear(); + void flush(WgContext& context); +}; + +// typed uniform stage buffer with related bind groups handling +template +class WgStageBufferUniform { +private: + Array ubuffer; + WGPUBuffer ubuffer_gpu{}; + Array bbuffer; +public: + // append uniform data to cpu staged buffer and return related bind group index + uint32_t append(const T& value) { + ubuffer.push(value); + return ubuffer.count - 1; + } + + void flush(WgContext& context) { + // flush data to gpu buffer from cpu memory including reserved data to prevent future gpu buffer reallocations + bool bufferChanged = context.allocateBufferUniform(ubuffer_gpu, (void*)ubuffer.data, ubuffer.reserved*sizeof(T)); + // if gpu buffer handle was changed we must to remove all created binding groups + if (bufferChanged) releaseBindGroups(context); + // allocate bind groups for all new data items + for (uint32_t i = bbuffer.count; i < ubuffer.count; i++) + bbuffer.push(context.layouts.createBindGroupBuffer1Un(ubuffer_gpu, i*sizeof(T), sizeof(T))); + assert(bbuffer.count >= ubuffer.count); + } + + // please, use index that was returned from append method + WGPUBindGroup operator[](const uint32_t index) const { + return bbuffer[index]; + } + + void clear() { + ubuffer.clear(); + } + + void release(WgContext& context) { + context.releaseBuffer(ubuffer_gpu); + releaseBindGroups(context); + } + + void releaseBindGroups(WgContext& context) { + ARRAY_FOREACH(p, bbuffer) + context.layouts.releaseBindGroup(*p); + bbuffer.clear(); + } +}; + + +struct WgIntersector +{ + bool isPointInTriangle(const Point& p, const Point& a, const Point& b, const Point& c); + bool isPointInTris(const Point& p, const WgMeshData& mesh, const Matrix& tr); + bool isPointInMesh(const Point& p, const WgMeshData& mesh, const Matrix& tr); + bool intersectClips(const Point& pt, const Array& clips); + bool intersectShape(const RenderRegion region, const WgRenderDataShape* shape); + bool intersectImage(const RenderRegion region, const WgRenderDataPicture* image); +}; + +#endif // _TVG_WG_RENDER_DATA_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTarget.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTarget.cpp new file mode 100644 index 0000000..7ac16f7 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTarget.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgRenderTarget.h" + +void WgRenderTarget::initialize(WgContext& context, uint32_t width, uint32_t height) +{ + this->width = width; + this->height = height; + texture = context.createTexStorage(width, height, WGPUTextureFormat_RGBA8Unorm); + textureMS = context.createTexAttachement(width, height, WGPUTextureFormat_RGBA8Unorm, 4); + texView = context.createTextureView(texture); + texViewMS = context.createTextureView(textureMS); + bindGroupRead = context.layouts.createBindGroupStrorage1RO(texView); + bindGroupWrite = context.layouts.createBindGroupStrorage1WO(texView); + bindGroupTexture = context.layouts.createBindGroupTexSampled(context.samplerNearestRepeat, texView); +} + + +void WgRenderTarget::release(WgContext& context) +{ + context.layouts.releaseBindGroup(bindGroupTexture); + context.layouts.releaseBindGroup(bindGroupWrite); + context.layouts.releaseBindGroup(bindGroupRead); + context.releaseTextureView(texViewMS); + context.releaseTexture(textureMS); + context.releaseTextureView(texView); + context.releaseTexture(texture); + height = 0; + width = 0; +} + +//***************************************************************************** +// render target pool +//***************************************************************************** + +WgRenderTarget* WgRenderTargetPool::allocate(WgContext& context) +{ + WgRenderTarget* renderTarget{}; + if (pool.count > 0) { + renderTarget = pool.last(); + pool.pop(); + } else { + renderTarget = new WgRenderTarget; + renderTarget->initialize(context, width, height); + list.push(renderTarget); + } + return renderTarget; +}; + + +void WgRenderTargetPool::free(WgContext& context, WgRenderTarget* renderTarget) +{ + pool.push(renderTarget); +}; + + +void WgRenderTargetPool::initialize(WgContext& context, uint32_t width, uint32_t height) +{ + this->width = width; + this->height = height; +} + + +void WgRenderTargetPool::release(WgContext& context) +{ + ARRAY_FOREACH(p, list) { + (*p)->release(context); + delete(*p); + } + list.clear(); + pool.clear(); + height = 0; + width = 0; +}; diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTarget.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTarget.h new file mode 100644 index 0000000..290e01a --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTarget.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_RENDER_TARGET_H_ +#define _TVG_WG_RENDER_TARGET_H_ + +#include "tvgWgPipelines.h" +#include "tvgRender.h" + +struct WgRenderTarget { + WGPUTexture texture{}; + WGPUTexture textureMS{}; + WGPUTextureView texView{}; + WGPUTextureView texViewMS{}; + WGPUBindGroup bindGroupRead{}; + WGPUBindGroup bindGroupWrite{}; + WGPUBindGroup bindGroupTexture{}; + uint32_t width{}; + uint32_t height{}; + + void initialize(WgContext& context, uint32_t width, uint32_t height); + void release(WgContext& context); +}; + + +class WgRenderTargetPool { +private: + Array list; + Array pool; + uint32_t width{}; + uint32_t height{}; +public: + WgRenderTarget* allocate(WgContext& context); + void free(WgContext& context, WgRenderTarget* renderTarget); + + void initialize(WgContext& context, uint32_t width, uint32_t height); + void release(WgContext& context); +}; +#endif // _TVG_WG_RENDER_TARGET_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTask.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTask.cpp new file mode 100644 index 0000000..0cf0280 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTask.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgRenderTask.h" +#include + +//*********************************************************************** +// WgPaintTask +//*********************************************************************** + +void WgPaintTask::run(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) +{ + if (renderData->type() == tvg::Type::Shape) + compositor.renderShape(context, (WgRenderDataShape*)renderData, blendMethod); + if (renderData->type() == tvg::Type::Picture) + compositor.renderImage(context, (WgRenderDataPicture*)renderData, blendMethod); + else assert(true); +} + +//*********************************************************************** +// WgSceneTask +//*********************************************************************** + +void WgSceneTask::run(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) +{ + // begin the render pass for the current scene and clear the target content + compositor.beginRenderPassMS(encoder, renderTarget, true); + // run all children (scenes and shapes) + runChildren(context, compositor, encoder); + // we must to end current render pass for current scene + compositor.endRenderPass(); + // we must to apply effect for current scene + if (effect) + runEffect(context, compositor, encoder); + // there's no point in continuing if the scene has no destination target (e.g., the root scene) + if (!renderTargetDst) return; + // apply scene blending + if (compose->method == MaskMethod::None) { + compositor.beginRenderPassMS(encoder, renderTargetDst, false); + compositor.renderScene(context, renderTarget, compose); + // apply scene composition (for scenes, that have a handle to mask) + } else if (renderTargetMsk) { + compositor.beginRenderPassMS(encoder, renderTargetDst, false); + compositor.composeScene(context, renderTarget, renderTargetMsk, compose); + } +} + + +void WgSceneTask::runChildren(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) +{ + ARRAY_FOREACH(task, children) { + WgRenderTask* renderTask = *task; + // we need to restore current render pass without clear + compositor.beginRenderPassMS(encoder, renderTarget, false); + // run children (shape or scene) + renderTask->run(context, compositor, encoder); + } +} + + +void WgSceneTask::runEffect(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) +{ + assert(effect); + switch (effect->type) { + case SceneEffect::GaussianBlur: compositor.gaussianBlur(context, renderTarget, (RenderEffectGaussianBlur*)effect, compose); break; + case SceneEffect::DropShadow: compositor.dropShadow(context, renderTarget, (RenderEffectDropShadow*)effect, compose); break; + case SceneEffect::Fill: compositor.fillEffect(context, renderTarget, (RenderEffectFill*)effect, compose); break; + case SceneEffect::Tint: compositor.tintEffect(context, renderTarget, (RenderEffectTint*)effect, compose); break; + case SceneEffect::Tritone : compositor.tritoneEffect(context, renderTarget, (RenderEffectTritone*)effect, compose); break; + default: break; + } +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTask.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTask.h new file mode 100644 index 0000000..0eb638a --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderTask.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_RENDER_TASK_H_ +#define _TVG_WG_RENDER_TASK_H_ + +#include "tvgWgCompositor.h" + +// base class for any renderable objects +struct WgRenderTask { + virtual ~WgRenderTask() {} + virtual void run(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) = 0; +}; + +// task for single shape rendering +struct WgPaintTask: public WgRenderTask { + // shape render properties + WgRenderDataPaint* renderData{}; + BlendMethod blendMethod{}; + + WgPaintTask(WgRenderDataPaint* renderData, BlendMethod blendMethod) : + renderData(renderData), blendMethod(blendMethod) {} + // apply shape execution, including custom blending and clipping + void run(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) override; +}; + +// task for scene rendering with blending, composition and effect +struct WgSceneTask: public WgRenderTask { +public: + // parent scene (nullptr for root scene) + WgSceneTask* parent{}; + // children can be shapes or scenes tasks + Array children; + // scene blend/compose targets + WgRenderTarget* renderTarget{}; + WgRenderTarget* renderTargetMsk{}; + WgRenderTarget* renderTargetDst{}; + // scene blend/compose properties + WgCompose* compose{}; + // scene effect properties + const RenderEffect* effect{}; + + WgSceneTask(WgRenderTarget* renderTarget, WgCompose* compose, WgSceneTask* parent) : + parent(parent), renderTarget(renderTarget), compose(compose) {} + // run all, including all shapes drawing, blending, composition and effect + void run(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder) override; +private: + void runChildren(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder); + void runEffect(WgContext& context, WgCompositor& compositor, WGPUCommandEncoder encoder); +}; + + #endif // _TVG_WG_RENDER_TASK_H_ + \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderer.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderer.cpp new file mode 100644 index 0000000..53264c7 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderer.cpp @@ -0,0 +1,657 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "tvgTaskScheduler.h" +#include "tvgWgRenderer.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +static atomic rendererCnt{-1}; + + +void WgRenderer::release() +{ + if (!mContext.queue) return; + + disposeObjects(); + + // clear render data paint pools + mRenderDataShapePool.release(mContext); + mRenderDataPicturePool.release(mContext); + mRenderDataEffectParamsPool.release(mContext); + + // clear render pool + mRenderTargetPool.release(mContext); + + // clear rendering tree stacks + mCompositorList.clear(); + mRenderTargetStack.clear(); + mRenderTargetRoot.release(mContext); + + // release context handles + mCompositor.release(mContext); + mContext.release(); + + // release gpu handles + clearTargets(); +} + + +void WgRenderer::disposeObjects() +{ + ARRAY_FOREACH(p, mDisposeRenderDatas) { + auto renderData = (WgRenderDataPaint*)(*p); + if (renderData->type() == Type::Shape) { + mRenderDataShapePool.free(mContext, (WgRenderDataShape*)renderData); + } else { + mRenderDataPicturePool.free(mContext, (WgRenderDataPicture*)renderData); + } + } + mDisposeRenderDatas.clear(); +} + + +void WgRenderer::releaseSurfaceTexture() +{ + if (surfaceTexture.texture) { + wgpuTextureRelease(surfaceTexture.texture); + surfaceTexture.texture = nullptr; + } +} + + +void WgRenderer::clearTargets() +{ + releaseSurfaceTexture(); + if (surface) wgpuSurfaceUnconfigure(surface); + targetTexture = nullptr; + surface = nullptr; + mTargetSurface.stride = 0; + mTargetSurface.w = 0; + mTargetSurface.h = 0; + +} + + +bool WgRenderer::surfaceConfigure(WGPUSurface surface, WgContext& context, uint32_t width, uint32_t height) +{ + this->surface = surface; + if (width == 0 || height == 0 || !surface) return false; + + // setup surface configuration + WGPUSurfaceConfiguration surfaceConfiguration { + .device = context.device, + .format = context.preferredFormat, + .usage = WGPUTextureUsage_RenderAttachment, + .width = width, + .height = height, + #ifdef __EMSCRIPTEN__ + .alphaMode = WGPUCompositeAlphaMode_Premultiplied, + .presentMode = WGPUPresentMode_Fifo + #elif __linux__ + #else + .presentMode = WGPUPresentMode_Immediate + #endif + }; + wgpuSurfaceConfigure(surface, &surfaceConfiguration); + return true; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +RenderData WgRenderer::prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) +{ + auto renderDataShape = data ? (WgRenderDataShape*)data : mRenderDataShapePool.allocate(mContext); + + // update geometry + if (!data || (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Stroke))) { + renderDataShape->updateMeshes(rshape, flags, transform); + } + + // update transform + if ((!data) || (flags & RenderUpdateFlag::Transform)) { + renderDataShape->transform = transform; + renderDataShape->updateAABB(transform); + } + + // update paint settings + if ((!data) || (flags & (RenderUpdateFlag::Transform | RenderUpdateFlag::Blend | RenderUpdateFlag::Color))) { + renderDataShape->renderSettingsShape.update(mContext, transform, mTargetSurface.cs, opacity); + renderDataShape->renderSettingsStroke.update(mContext, transform, mTargetSurface.cs, opacity); + renderDataShape->fillRule = rshape.rule; + } + + // setup fill settings + renderDataShape->viewport = vport; + renderDataShape->updateVisibility(rshape, opacity); + // update shape render settings + if (!renderDataShape->renderSettingsShape.skip) { + if (flags & RenderUpdateFlag::Gradient && rshape.fill) renderDataShape->renderSettingsShape.update(mContext, rshape.fill); + else if (flags & RenderUpdateFlag::Color) renderDataShape->renderSettingsShape.update(mContext, rshape.color); + } + // update strokes render settings + if (rshape.stroke && !renderDataShape->renderSettingsStroke.skip) { + if (flags & RenderUpdateFlag::GradientStroke && rshape.stroke->fill) renderDataShape->renderSettingsStroke.update(mContext, rshape.stroke->fill); + else if (flags & RenderUpdateFlag::Stroke) renderDataShape->renderSettingsStroke.update(mContext, rshape.stroke->color); + } + + if (flags & RenderUpdateFlag::Clip) renderDataShape->updateClips(clips); + + return renderDataShape; +} + + +RenderData WgRenderer::prepare(RenderSurface* surface, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) +{ + auto renderDataPicture = data ? (WgRenderDataPicture*)data : mRenderDataPicturePool.allocate(mContext); + + // update paint settings + renderDataPicture->viewport = vport; + renderDataPicture->transform = transform; + if (flags & (RenderUpdateFlag::Transform | RenderUpdateFlag::Blend | RenderUpdateFlag::Color)) { + renderDataPicture->renderSettings.update(mContext, transform, surface->cs, opacity); + } + + // update image data + if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Image)) { + renderDataPicture->updateSurface(mContext, surface); + } + + if (flags & RenderUpdateFlag::Clip) renderDataPicture->updateClips(clips); + + return renderDataPicture; +} + + +bool WgRenderer::preRender() +{ + if (mContext.invalid()) return false; + + mCompositor.reset(mContext); + + assert(mRenderTargetStack.count == 0); + mRenderTargetStack.push(&mRenderTargetRoot); + + // create root compose settings + WgCompose* compose = new WgCompose(); + compose->aabb = { { 0, 0 }, { (int32_t)mTargetSurface.w, (int32_t)mTargetSurface.h } }; + compose->blend = BlendMethod::Normal; + compose->method = MaskMethod::None; + compose->opacity = 255; + mCompositorList.push(compose); + + // create root scene + WgSceneTask* sceneTask = new WgSceneTask(&mRenderTargetRoot, compose, nullptr); + mRenderTaskList.push(sceneTask); + mSceneTaskStack.push(sceneTask); + return true; +} + + +bool WgRenderer::renderShape(RenderData data) +{ + WgPaintTask* paintTask = new WgPaintTask((WgRenderDataPaint*)data, mBlendMethod); + WgSceneTask* sceneTask = mSceneTaskStack.last(); + sceneTask->children.push(paintTask); + mRenderTaskList.push(paintTask); + mCompositor.requestShape((WgRenderDataShape*)data); + return true; +} + + +bool WgRenderer::renderImage(RenderData data) +{ + WgPaintTask* paintTask = new WgPaintTask((WgRenderDataPaint*)data, mBlendMethod); + WgSceneTask* sceneTask = mSceneTaskStack.last(); + sceneTask->children.push(paintTask); + mRenderTaskList.push(paintTask); + mCompositor.requestImage((WgRenderDataPicture*)data); + return true; +} + + +bool WgRenderer::postRender() +{ + // flush stage data to gpu + mCompositor.flush(mContext); + + // create command encoder for drawing + WGPUCommandEncoder commandEncoder = mContext.createCommandEncoder(); + + // run rendering (all the fun is here) + WgSceneTask* sceneTaskRoot = mSceneTaskStack.last(); + sceneTaskRoot->run(mContext, mCompositor, commandEncoder); + + // execute and release command encoder + mContext.submitCommandEncoder(commandEncoder); + mContext.releaseCommandEncoder(commandEncoder); + + // clear the render tasks tree + mSceneTaskStack.pop(); + assert(mSceneTaskStack.count == 0); + mRenderTargetStack.pop(); + assert(mRenderTargetStack.count == 0); + ARRAY_FOREACH(p, mRenderTaskList) { delete (*p); }; + mRenderTaskList.clear(); + ARRAY_FOREACH(p, mCompositorList) { delete (*p); }; + mCompositorList.clear(); + return true; +} + + +void WgRenderer::dispose(RenderData data) { + if (!mContext.queue) return; + ScopedLock lock(mDisposeKey); + mDisposeRenderDatas.push(data); +} + + +bool WgRenderer::bounds(RenderData data, Point* pt4, const Matrix& m) +{ + if (data) { + auto renderDataPaint = (WgRenderDataPaint*)data; + if (renderDataPaint->type() == Type::Shape) { + auto renderData = (WgRenderDataShape*)data; + if (!renderData->renderSettingsStroke.skip) { + tvg::BBox bbox; + bbox.init(); + auto& vertexes = renderData->meshStrokes.vbuffer; + for (uint32_t i = 0; i < vertexes.count; i++) { + Point vert = vertexes[i] * m; + bbox.min = min(bbox.min, vert); + bbox.max = max(bbox.max, vert); + } + pt4[0] = bbox.min; + pt4[1] = {bbox.max.x, bbox.min.y}; + pt4[2] = bbox.max; + pt4[3] = {bbox.min.x, bbox.max.y}; + return true; + } + } + } + return false; +} + +RenderRegion WgRenderer::region(RenderData data) +{ + if (!data) return {}; + auto renderData = (WgRenderDataPaint*)data; + if (renderData->type() == Type::Shape) { + auto& v1 = renderData->aabb.min; + auto& v2 = renderData->aabb.max; + return {{int32_t(nearbyint(v1.x)), int32_t(nearbyint(v1.y))}, {int32_t(nearbyint(v2.x)), int32_t(nearbyint(v2.y))}}; + } + return {{0, 0}, {(int32_t)mTargetSurface.w, (int32_t)mTargetSurface.h}}; +} + + +bool WgRenderer::blend(BlendMethod method) +{ + mBlendMethod = (method == BlendMethod::Composition ? BlendMethod::Normal : method); + + return true; +} + + +ColorSpace WgRenderer::colorSpace() +{ + return mTargetSurface.cs; +} + + +const RenderSurface* WgRenderer::mainSurface() +{ + return &mTargetSurface; +} + + +bool WgRenderer::clear() +{ + if (mContext.invalid()) return false; + + //TODO: clear the current target buffer only if clear() is called + return true; +} + + +bool WgRenderer::sync() +{ + if (mContext.invalid()) return false; + + disposeObjects(); + + // if texture buffer used + WGPUTexture dstTexture = targetTexture; + if (surface) { + releaseSurfaceTexture(); + wgpuSurfaceGetCurrentTexture(surface, &surfaceTexture); + dstTexture = surfaceTexture.texture; + } + + if (!dstTexture) return false; + + // insure that surface and offscreen target have the same size + if ((wgpuTextureGetWidth(dstTexture) == mRenderTargetRoot.width) && + (wgpuTextureGetHeight(dstTexture) == mRenderTargetRoot.height)) { + WGPUTextureView dstTextureView = mContext.createTextureView(dstTexture); + WGPUCommandEncoder commandEncoder = mContext.createCommandEncoder(); + // show root offscreen buffer + mCompositor.blit(mContext, commandEncoder, &mRenderTargetRoot, dstTextureView); + mContext.submitCommandEncoder(commandEncoder); + mContext.releaseCommandEncoder(commandEncoder); + mContext.releaseTextureView(dstTextureView); + } + + return true; +} + + +bool WgRenderer::target(WGPUDevice device, WGPUInstance instance, void* target, uint32_t w, uint32_t h, ColorSpace cs, int type) +{ + if (!instance || !device || !target) { + release(); + return true; + } + + if (w == 0 || h == 0) return false; + + // device or instance was changed, need to recreate all instances + if ((mContext.device != device) || (mContext.instance != instance)) { + release(); + mContext.initialize(instance, device); + mRenderTargetPool.initialize(mContext, w, h); + mRenderTargetRoot.initialize(mContext, w, h); + mCompositor.initialize(mContext, w, h); + + // update render targets dimensions + } else if ((mTargetSurface.w != w) || (mTargetSurface.h != h) || (type == 0 ? (surface != (WGPUSurface)target) : (targetTexture != (WGPUTexture)target))) { + mRenderTargetPool.release(mContext); + mRenderTargetRoot.release(mContext); + clearTargets(); + mRenderTargetPool.initialize(mContext, w, h); + mRenderTargetRoot.initialize(mContext, w, h); + mCompositor.resize(mContext, w, h); + } + + // configure surface (must be called after context creation) + if (type == 0) { + surface = (WGPUSurface)target; + surfaceConfigure(surface, mContext, w, h); + } else { + targetTexture = (WGPUTexture)target; + } + + mTargetSurface.stride = w; + mTargetSurface.w = w; + mTargetSurface.h = h; + mTargetSurface.cs = cs; + + return true; +} + + +WgRenderer::WgRenderer() +{ + if (TaskScheduler::onthread()) { + TVGLOG("WG_RENDERER", "Running on a non-dominant thread!, Renderer(%p)", this); + } + + ++rendererCnt; +} + + +WgRenderer::~WgRenderer() +{ + release(); + + --rendererCnt; +} + + +RenderCompositor* WgRenderer::target(const RenderRegion& region, TVG_UNUSED ColorSpace cs, TVG_UNUSED CompositionFlag flags) +{ + // create and setup compose data + WgCompose* compose = new WgCompose(); + compose->aabb = region; + compose->flags = flags; + mCompositorList.push(compose); + return compose; +} + + +// please, keep beginComposite/endComposite aligned by logic +bool WgRenderer::beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) +{ + // current composition + WgCompose* compose = (WgCompose*)cmp; + // allocate new render target and push to the render tree stack + WgRenderTarget* newRenderTarget = mRenderTargetPool.allocate(mContext); + mRenderTargetStack.push(newRenderTarget); + // current and new scenes + WgSceneTask* curSceneTask = mSceneTaskStack.last(); + WgSceneTask* newSceneTask = new WgSceneTask(newRenderTarget, compose, curSceneTask); + // setup masking and blending scenes configuration + if ((compose->flags & (tvg::Blending | tvg::Masking)) == (tvg::Blending | tvg::Masking)) { + // new scene task must be as masked but not blended + newSceneTask->compose->method = curSceneTask->compose->method; + newSceneTask->compose->opacity = 255; + newSceneTask->compose->blend = BlendMethod::Normal; + newSceneTask->renderTargetMsk = curSceneTask->renderTargetMsk; + newSceneTask->renderTargetDst = curSceneTask->renderTarget; + // cur scene task must be blended but not masked + curSceneTask->compose->method = MaskMethod::None; + curSceneTask->compose->opacity = opacity; + curSceneTask->compose->blend = mBlendMethod; + curSceneTask->renderTargetMsk = nullptr; + } else // setup masking scenes configuration + if (method != MaskMethod::None) { + // new scene task must be masked + newSceneTask->compose->masked = true; + newSceneTask->compose->method = method; + newSceneTask->compose->opacity = opacity; + newSceneTask->compose->blend = BlendMethod::Normal; + newSceneTask->renderTargetMsk = curSceneTask->renderTarget; + newSceneTask->renderTargetDst = curSceneTask->renderTargetDst; + // cur scene task must not be blended + curSceneTask->renderTargetDst = nullptr; + } else // setup blending scenes configuration + if (method == MaskMethod::None) { + // new scene task must be blended + newSceneTask->compose->method = MaskMethod::None; + newSceneTask->compose->opacity = opacity; + newSceneTask->compose->blend = mBlendMethod; + newSceneTask->renderTargetMsk = nullptr; + newSceneTask->renderTargetDst = curSceneTask->renderTarget; + } + curSceneTask->children.push(newSceneTask); + mRenderTaskList.push(newSceneTask); + mSceneTaskStack.push(newSceneTask); + + return true; +} + + +// please, keep beginComposite/endComposite aligned by logic +bool WgRenderer::endComposite(RenderCompositor* cmp) +{ + // pop targets and scenes from render tree + mRenderTargetPool.free(mContext, mRenderTargetStack.last()); + mSceneTaskStack.pop(); + mRenderTargetStack.pop(); + // in a case of masked target we must pop mask targets and scenes also + WgCompose* compose = (WgCompose*)cmp; + if (compose->masked) { + mRenderTargetPool.free(mContext, mRenderTargetStack.last()); + mSceneTaskStack.pop(); + mRenderTargetStack.pop(); + } + return true; +} + + +void WgRenderer::prepare(RenderEffect* effect, const Matrix& transform) +{ + if (!effect->rd) effect->rd = mRenderDataEffectParamsPool.allocate(mContext); + auto renderData = (WgRenderDataEffectParams*)effect->rd; + + if (effect->type == SceneEffect::GaussianBlur) { + renderData->update(mContext, (RenderEffectGaussianBlur*)effect, transform); + } else if (effect->type == SceneEffect::DropShadow) { + renderData->update(mContext, (RenderEffectDropShadow*)effect, transform); + } else if (effect->type == SceneEffect::Fill) { + renderData->update(mContext, (RenderEffectFill*)effect); + } else if (effect->type == SceneEffect::Tint) { + renderData->update(mContext, (RenderEffectTint*)effect); + } else if (effect->type == SceneEffect::Tritone) { + renderData->update(mContext, (RenderEffectTritone*)effect); + } else { + TVGERR("WG_ENGINE", "Missing effect type? = %d", (int) effect->type); + return; + } +} + + +bool WgRenderer::region(RenderEffect* effect) +{ + if (effect->type == SceneEffect::GaussianBlur) { + auto gaussian = (RenderEffectGaussianBlur*)effect; + auto renderData = (WgRenderDataEffectParams*)gaussian->rd; + if (gaussian->direction != 2) { + gaussian->extend.min.x = -renderData->extend; + gaussian->extend.max.x = +renderData->extend; + } + if (gaussian->direction != 1) { + gaussian->extend.min.y = -renderData->extend; + gaussian->extend.max.y = +renderData->extend; + } + return true; + } else if (effect->type == SceneEffect::DropShadow) { + auto dropShadow = (RenderEffectDropShadow*)effect; + auto renderData = (WgRenderDataEffectParams*)dropShadow->rd; + dropShadow->extend.min.x = -std::ceil(renderData->extend + std::abs(renderData->offset.x)); + dropShadow->extend.min.y = -std::ceil(renderData->extend + std::abs(renderData->offset.y)); + dropShadow->extend.max.x = +std::floor(renderData->extend + std::abs(renderData->offset.x)); + dropShadow->extend.max.y = +std::floor(renderData->extend + std::abs(renderData->offset.y)); + return true; + } + return false; +} + + +bool WgRenderer::render(RenderCompositor* cmp, const RenderEffect* effect, TVG_UNUSED bool direct) +{ + mSceneTaskStack.last()->effect = effect; + return true; +} + + +void WgRenderer::dispose(RenderEffect* effect) +{ + auto renderData = (WgRenderDataEffectParams*)effect->rd; + mRenderDataEffectParamsPool.free(mContext, renderData); + effect->rd = nullptr; +}; + + +bool WgRenderer::preUpdate() +{ + if (mContext.invalid()) return false; + + return true; +} + + +bool WgRenderer::postUpdate() +{ + return true; +} + + +void WgRenderer::damage(TVG_UNUSED RenderData rd, TVG_UNUSED const RenderRegion& region) +{ + //TODO +} + + +bool WgRenderer::partial(bool disable) +{ + //TODO + return false; +} + + +bool WgRenderer::intersectsShape(RenderData data, TVG_UNUSED const RenderRegion& region) +{ + if (!data) return false; + auto shape = (WgRenderDataShape*)data; + RenderRegion bbox = { + {(int32_t)shape->aabb.min.x, (int32_t)shape->aabb.min.y}, + {(int32_t)shape->aabb.max.x, (int32_t)shape->aabb.max.y} + }; + if (region.intersected(bbox)) { + if (region.contained(bbox)) return true; + WgIntersector intersector; + return intersector.intersectShape(RenderRegion::intersect(region, bbox), shape); + } + return false; +} + + +bool WgRenderer::intersectsImage(RenderData data, TVG_UNUSED const RenderRegion& region) +{ + if (!data) return false; + auto picture = (WgRenderDataPicture*)data; + WgIntersector intersector; + if (intersector.intersectImage(region, picture)) return true; + return false; +} + + +bool WgRenderer::term() +{ + if (rendererCnt > 0) return false; + + //TODO: clean up global resources + + rendererCnt = -1; + + return true; +} + + +WgRenderer* WgRenderer::gen(TVG_UNUSED uint32_t threads) +{ + //initialize engine + if (rendererCnt == -1) { + //TODO: + } + + return new WgRenderer; +} \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderer.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderer.h new file mode 100644 index 0000000..24e6220 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgRenderer.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_RENDERER_H_ +#define _TVG_WG_RENDERER_H_ + +#include "tvgWgRenderTask.h" + +struct WgRenderer : RenderMethod +{ + //main features + bool preUpdate() override; + RenderData prepare(const RenderShape& rshape, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) override; + RenderData prepare(RenderSurface* surface, RenderData data, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag flags) override; + bool postUpdate() override; + bool preRender() override; + bool renderShape(RenderData data) override; + bool renderImage(RenderData data) override; + bool postRender() override; + void dispose(RenderData data) override; + RenderRegion region(RenderData data) override; + bool bounds(RenderData data, Point* pt4, const Matrix& m) override; + bool blend(BlendMethod method) override; + ColorSpace colorSpace() override; + const RenderSurface* mainSurface() override; + bool clear() override; + bool sync() override; + bool intersectsImage(RenderData data, const RenderRegion& region) override; + bool intersectsShape(RenderData data, const RenderRegion& region) override; + bool target(WGPUDevice device, WGPUInstance instance, void* target, uint32_t w, uint32_t h, ColorSpace cs, int type = 0); + + //composition + RenderCompositor* target(const RenderRegion& region, ColorSpace cs, CompositionFlag flags) override; + bool beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_t opacity) override; + bool endComposite(RenderCompositor* cmp) override; + + //post effects + void prepare(RenderEffect* effect, const Matrix& transform) override; + bool region(RenderEffect* effect) override; + bool render(RenderCompositor* cmp, const RenderEffect* effect, bool direct) override; + void dispose(RenderEffect* effect) override; + + //partial rendering + void damage(RenderData rd, const RenderRegion& region) override; + bool partial(bool disable) override; + + static WgRenderer* gen(uint32_t threads); + static bool term(); + +private: + WgRenderer(); + ~WgRenderer(); + void release(); + void disposeObjects(); + void releaseSurfaceTexture(); + + void clearTargets(); + bool surfaceConfigure(WGPUSurface surface, WgContext& context, uint32_t width, uint32_t height); + + // render tree stacks + WgRenderTarget mRenderTargetRoot; + Array mCompositorList; + Array mRenderTargetStack; + Array mSceneTaskStack; + Array mRenderTaskList; + + // render target pool + WgRenderTargetPool mRenderTargetPool; + + // render data paint pools + WgRenderDataShapePool mRenderDataShapePool; + WgRenderDataPicturePool mRenderDataPicturePool; + WgRenderDataEffectParamsPool mRenderDataEffectParamsPool; + + // rendering context + WgContext mContext; + WgCompositor mCompositor; + + // rendering states + RenderSurface mTargetSurface; + BlendMethod mBlendMethod{}; + + // disposable data list + Array mDisposeRenderDatas{}; + Key mDisposeKey{}; + + // gpu handles + WGPUTexture targetTexture{}; // external handle + WGPUSurfaceTexture surfaceTexture{}; + WGPUSurface surface{}; // external handle +}; + +#endif /* _TVG_WG_RENDERER_H_ */ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderSrc.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderSrc.cpp new file mode 100644 index 0000000..7ffa2ff --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderSrc.cpp @@ -0,0 +1,962 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgShaderSrc.h" +#include + +//************************************************************************ +// graphics shader source: stencil +//************************************************************************ + +const char* cShaderSrc_Stencil = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f }; +struct PaintSettings { transform: mat4x4f }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + return vec4f(0.0, 0.0, 0.0, 1.0); +} +)"; + +//************************************************************************ +// graphics shader source: depth +//************************************************************************ + +const char* cShaderSrc_Depth = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f }; +struct PaintSettings { transform: mat4x4f }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uDepth : f32; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.position.z = uDepth; + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + return vec4f(1.0, 0.5, 0.0, 1.0); +} +)"; + +//************************************************************************ +// graphics shader source: solid normal blend +//************************************************************************ + +const char* cShaderSrc_Solid = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f }; +struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + let Sc = uPaintSettings.color; + let So = uPaintSettings.options.a; + return vec4f(Sc.rgb * Sc.a * So, Sc.a * So); +} +)"; + +//************************************************************************ +// graphics shader source: linear normal blend +//************************************************************************ + +const char* cShaderSrc_Linear = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position : vec4f, @location(0) vGradCoord : vec4f }; +struct GradSettings { transform: mat4x4f, coords: vec4f, focal: vec4f }; +struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f, gradient: GradSettings }; + +// uniforms +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uSamplerGrad : sampler; +@group(2) @binding(1) var uTextureGrad : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.vGradCoord = uPaintSettings.gradient.transform * vec4f(in.position.xy, 0.0, 1.0); + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + let pos = in.vGradCoord.xy; + let st = uPaintSettings.gradient.coords.xy; + let ed = uPaintSettings.gradient.coords.zw; + let ba = ed - st; + let t = dot(pos - st, ba) / dot(ba, ba); + let Sc = textureSample(uTextureGrad, uSamplerGrad, vec2f(t, 0.5)); + let So = uPaintSettings.options.a; + return vec4f(Sc.rgb * Sc.a * So, Sc.a * So); +} +)"; + +//************************************************************************ +// graphics shader source: radial normal blend +//************************************************************************ + +const char* cShaderSrc_Radial = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position : vec4f, @location(0) vGradCoord : vec4f }; +struct GradSettings { transform: mat4x4f, coords: vec4f, focal: vec4f }; +struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f, gradient: GradSettings }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uSamplerGrad : sampler; +@group(2) @binding(1) var uTextureGrad : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.vGradCoord = uPaintSettings.gradient.transform * vec4f(in.position.xy, 0.0, 1.0); + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + // original data + let d0 = in.vGradCoord.xy - uPaintSettings.gradient.coords.xy; + let d1 = uPaintSettings.gradient.coords.xy - uPaintSettings.gradient.focal.xy; + let r0 = uPaintSettings.gradient.coords.z; + let rd = uPaintSettings.gradient.focal.z - uPaintSettings.gradient.coords.z; + let a = 1.0*dot(d1, d1) - 1.0*rd*rd; + let b = 2.0*dot(d0, d1) - 2.0*r0*rd; + let c = 1.0*dot(d0, d0) - 1.0*r0*r0; + let d = b*b - 4*a*c; + var t = 0.0; + if (d >= 0) { t = min(1.0, (-b + sqrt(d))/(2*a)); } + if ((c > 0) && (t >= 1.0)) { t = 0.0; } + let Sc = textureSample(uTextureGrad, uSamplerGrad, vec2f(1.0 - t, 0.5)); + let So = uPaintSettings.options.a; + return vec4f(Sc.rgb * Sc.a * So, Sc.a * So); +} +)"; + +//************************************************************************ +// graphics shader source: image normal blend +//************************************************************************ + +const char* cShaderSrc_Image = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) vTexCoord: vec2f }; +struct PaintSettings { transform: mat4x4f, options: vec4f }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uSampler : sampler; +@group(2) @binding(1) var uTextureView : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.vTexCoord = in.texCoord; + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + var Sc: vec4f = textureSample(uTextureView, uSampler, in.vTexCoord.xy); + let So: f32 = uPaintSettings.options.a; + return vec4f(Sc.rgb * Sc.a * So, Sc.a * So); +}; +)"; + +//************************************************************************ +// graphics shader source: scene normal blend +//************************************************************************ + +const char* cShaderSrc_Scene = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) vTexCoord: vec2f }; + +@group(0) @binding(0) var uSamplerSrc : sampler; +@group(0) @binding(1) var uTextureSrc : texture_2d; +@group(1) @binding(0) var So : f32; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = vec4f(in.position.xy, 0.0, 1.0); + out.vTexCoord = in.texCoord; + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + let Sc = textureSample(uTextureSrc, uSamplerSrc, in.vTexCoord.xy); + return vec4f(Sc.rgb * So, Sc.a * So); +}; +)"; + +//************************************************************************ +// graphics shader source: custom shaders +//************************************************************************ + +const char* cShaderSrc_Solid_Blend = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(1) vScrCoord: vec2f }; +struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +// @group(2) - empty +@group(3) @binding(0) var uSamplerDst : sampler; +@group(3) @binding(1) var uTextureDst : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + let pos = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.position = pos; + out.vScrCoord = vec2f(0.5 + pos.x * 0.5, 0.5 - pos.y * 0.5); + return out; +} + +struct FragData { Sc: vec3f, Sa: f32, So: f32, Dc: vec3f, Da: f32 }; +fn getFragData(in: VertexOutput) -> FragData { + // get source data + let colorSrc = uPaintSettings.color; + let colorDst = textureSample(uTextureDst, uSamplerDst, in.vScrCoord.xy); + // fill fragment data + var data: FragData; + data.Sc = colorSrc.rgb; + data.Sa = colorSrc.a; + data.So = uPaintSettings.options.a; + data.Dc = colorDst.rgb; + data.Da = colorDst.a; + data.Sc = data.Sa * data.So * data.Sc; + data.Sa = data.Sa * data.So; + return data; +}; + +fn postProcess(d: FragData, R: vec4f) -> vec4f { return R; }; +)"; + +const char* cShaderSrc_Linear_Blend = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) vGradCoord : vec4f, @location(1) vScrCoord: vec2f }; +struct GradSettings { transform: mat4x4f, coords: vec4f, focal: vec4f }; +struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f, gradient: GradSettings }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uSamplerGrad : sampler; +@group(2) @binding(1) var uTextureGrad : texture_2d; +@group(3) @binding(0) var uSamplerDst : sampler; +@group(3) @binding(1) var uTextureDst : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + let pos = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.position = pos; + out.vGradCoord = uPaintSettings.gradient.transform * vec4f(in.position.xy, 0.0, 1.0); + out.vScrCoord = vec2f(0.5 + pos.x * 0.5, 0.5 - pos.y * 0.5); + return out; +} + +struct FragData { Sc: vec3f, Sa: f32, So: f32, Dc: vec3f, Da: f32 }; +fn getFragData(in: VertexOutput) -> FragData { + // get source data + let pos = in.vGradCoord.xy; + let st = uPaintSettings.gradient.coords.xy; + let ed = uPaintSettings.gradient.coords.zw; + let ba = ed - st; + let t = dot(pos - st, ba) / dot(ba, ba); + let colorSrc = textureSample(uTextureGrad, uSamplerGrad, vec2f(t, 0.5)); + let colorDst = textureSample(uTextureDst, uSamplerDst, in.vScrCoord.xy); + // fill fragment data + var data: FragData; + data.Sc = colorSrc.rgb; + data.Sa = colorSrc.a; + data.So = uPaintSettings.options.a; + data.Dc = colorDst.rgb; + data.Da = colorDst.a; + data.Sc = mix(data.Dc, data.Sc, data.Sa * data.So); + data.Sa = mix(data.Da, 1.0, data.Sa * data.So); + return data; +}; + +fn postProcess(d: FragData, R: vec4f) -> vec4f { return R; }; +)"; + +const char* cShaderSrc_Radial_Blend = R"( +struct VertexInput { @location(0) position: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) vGradCoord : vec4f, @location(1) vScrCoord: vec2f }; +struct GradSettings { transform: mat4x4f, coords: vec4f, focal: vec4f }; +struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f, gradient: GradSettings }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uSamplerGrad : sampler; +@group(2) @binding(1) var uTextureGrad : texture_2d; +@group(3) @binding(0) var uSamplerDst : sampler; +@group(3) @binding(1) var uTextureDst : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + let pos = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.position = pos; + out.vGradCoord = uPaintSettings.gradient.transform * vec4f(in.position.xy, 0.0, 1.0); + out.vScrCoord = vec2f(0.5 + pos.x * 0.5, 0.5 - pos.y * 0.5); + return out; +} + +struct FragData { Sc: vec3f, Sa: f32, So: f32, Dc: vec3f, Da: f32 }; +fn getFragData(in: VertexOutput) -> FragData { + let d0 = in.vGradCoord.xy - uPaintSettings.gradient.coords.xy; + let d1 = uPaintSettings.gradient.coords.xy - uPaintSettings.gradient.focal.xy; + let r0 = uPaintSettings.gradient.coords.z; + let rd = uPaintSettings.gradient.focal.z - uPaintSettings.gradient.coords.z; + let a = 1.0*dot(d1, d1) - 1.0*rd*rd; + let b = 2.0*dot(d0, d1) - 2.0*r0*rd; + let c = 1.0*dot(d0, d0) - 1.0*r0*r0; + let d = b*b - 4*a*c; + var t = 0.0; + if (d >= 0) { t = min(1.0, (-b + sqrt(d))/(2*a)); } + if ((c > 0) && (t >= 1.0)) { t = 0.0; } + let colorSrc = textureSample(uTextureGrad, uSamplerGrad, vec2f(1.0 - t, 0.5)); + let colorDst = textureSample(uTextureDst, uSamplerDst, in.vScrCoord.xy); + // fill fragment data + var data: FragData; + data.Sc = colorSrc.rgb; + data.Sa = colorSrc.a; + data.So = uPaintSettings.options.a; + data.Dc = colorDst.rgb; + data.Da = colorDst.a; + data.Sc = mix(data.Dc, data.Sc, data.Sa * data.So); + data.Sa = mix(data.Da, 1.0, data.Sa * data.So); + return data; +}; + +fn postProcess(d: FragData, R: vec4f) -> vec4f { return R; }; +)"; + +const char* cShaderSrc_Image_Blend = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) vTexCoord : vec2f, @location(1) vScrCoord: vec2f }; +struct PaintSettings { transform: mat4x4f, options: vec4f }; + +@group(0) @binding(0) var uViewMat : mat4x4f; +@group(1) @binding(0) var uPaintSettings : PaintSettings; +@group(2) @binding(0) var uSamplerSrc : sampler; +@group(2) @binding(1) var uTextureSrc : texture_2d; +@group(3) @binding(0) var uSamplerDst : sampler; +@group(3) @binding(1) var uTextureDst : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + let pos = uViewMat * uPaintSettings.transform * vec4f(in.position.xy, 0.0, 1.0); + out.position = pos; + out.vTexCoord = in.texCoord; + out.vScrCoord = vec2f(0.5 + pos.x * 0.5, 0.5 - pos.y * 0.5); + return out; +} + +struct FragData { Sc: vec3f, Sa: f32, So: f32, Dc: vec3f, Da: f32 }; +fn getFragData(in: VertexOutput) -> FragData { + // get source data + let colorSrc = textureSample(uTextureSrc, uSamplerSrc, in.vTexCoord.xy); + let colorDst = textureSample(uTextureDst, uSamplerDst, in.vScrCoord.xy); + // fill fragment data + var data: FragData; + data.Sc = colorSrc.rgb; + data.Sa = colorSrc.a; + data.So = uPaintSettings.options.a; + data.Dc = colorDst.rgb; + data.Da = colorDst.a; + data.Sc = data.Sc * data.So; + data.Sa = data.Sa * data.So; + return data; +}; + +fn postProcess(d: FragData, R: vec4f) -> vec4f { return mix(vec4(d.Dc, d.Da), R, d.Sa); }; +)"; + +const char* cShaderSrc_Scene_Blend = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) vScrCoord: vec2f }; + +@group(0) @binding(0) var uSamplerSrc : sampler; +@group(0) @binding(1) var uTextureSrc : texture_2d; +@group(1) @binding(0) var uSamplerDst : sampler; +@group(1) @binding(1) var uTextureDst : texture_2d; +@group(2) @binding(0) var So : f32; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = vec4f(in.position.xy, 0.0, 1.0); + out.vScrCoord = in.texCoord; + return out; +} + +struct FragData { Sc: vec3f, Sa: f32, So: f32, Dc: vec3f, Da: f32 }; +fn getFragData(in: VertexOutput) -> FragData { + // get source data + let colorSrc = textureSample(uTextureSrc, uSamplerSrc, in.vScrCoord.xy); + let colorDst = textureSample(uTextureDst, uSamplerDst, in.vScrCoord.xy); + // fill fragment data + var data: FragData; + data.Sc = min(vec3f(1.0, 1.0, 1.0), colorSrc.rgb / select(colorSrc.a, 1.0, (colorSrc.a == 0.0) || (colorSrc.a == 1.0))); + data.Sa = colorSrc.a; + data.Dc = colorDst.rgb; + data.Da = colorDst.a; + return data; +}; + +fn postProcess(d: FragData, R: vec4f) -> vec4f { return mix(vec4(d.Dc, d.Da), R, d.Sa * So); }; +)"; + +const char* cShaderSrc_BlendFuncs = R"( +const One = vec3f(1.0, 1.0, 1.0); + +// RGB to HSL conversion +fn rgbToHsl(color: vec3f) -> vec3f { + let minVal = min(color.r, min(color.g, color.b)); + let maxVal = max(color.r, max(color.g, color.b)); + let delta = maxVal - minVal; + + var h = 0.0; + if (delta > 0.0) { + if (maxVal == color.r) { h = (color.g - color.b) / delta - trunc(h / 6.0) * 6.0; } + else if (maxVal == color.g) { h = (color.b - color.r) / delta + 2.0; + } else { h = (color.r - color.g) / delta + 4.0; } + h = h * 60.0; + if (h < 0.0) { h += 360.0; } + } + + let l = (maxVal + minVal) * 0.5; + var s = select(0.0, delta / (1.0 - abs(2.0 * l - 1.0)), delta > 0.0); + + return vec3f(h, s, l); +}; + +// HSL to RGB conversion +fn hslToRgb(color: vec3f) -> vec3f { + let h = color.x; + let s = color.y; + let l = color.z; + + let C = (1.0 - abs(2.0 * l - 1.0)) * s; + let h_prime = h / 60.0; + let X = C * (1.0 - abs(h_prime - 2.0 * trunc(h_prime / 2.0) - 1.0)); + let m = l - C / 2.0; + + var rgb = vec3f(0.0); + if (h_prime >= 0.0 && h_prime < 1.0) { rgb = vec3f(C, X, 0.0); } + else if (h_prime >= 1.0 && h_prime < 2.0) { rgb = vec3f(X, C, 0.0); } + else if (h_prime >= 2.0 && h_prime < 3.0) { rgb = vec3f(0.0, C, X); } + else if (h_prime >= 3.0 && h_prime < 4.0) { rgb = vec3f(0.0, X, C); } + else if (h_prime >= 4.0 && h_prime < 5.0) { rgb = vec3f(X, 0.0, C); } + else { rgb = vec3f(C, 0.0, X); } + + return rgb + vec3f(m); +}; + +@fragment +fn fs_main_Normal(in: VertexOutput) -> @location(0) vec4f { + // used as debug blend method + return vec4f(1.0, 0.0, 0.0, 1.0); +} + +@fragment +fn fs_main_Multiply(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + Rc = d.Sc * min(One, d.Dc / d.Da); + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + + +@fragment +fn fs_main_Screen(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + let Rc = d.Sc + d.Dc - d.Sc * d.Dc; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Overlay(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + Rc.r = select(1.0 - min(1.0, 2 * (1 - d.Sc.r) * (1 - Dc.r)), min(1.0, 2 * d.Sc.r * Dc.r), (Dc.r < 0.5)); + Rc.g = select(1.0 - min(1.0, 2 * (1 - d.Sc.g) * (1 - Dc.g)), min(1.0, 2 * d.Sc.g * Dc.g), (Dc.g < 0.5)); + Rc.b = select(1.0 - min(1.0, 2 * (1 - d.Sc.b) * (1 - Dc.b)), min(1.0, 2 * d.Sc.b * Dc.b), (Dc.b < 0.5)); + Rc = mix(d.Sc, Rc, d.Da); + } + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Darken(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + Rc = min(d.Sc, min(One, d.Dc / d.Da)); + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Lighten(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + let Rc = max(d.Sc, d.Dc); + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_ColorDodge(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + Rc.r = select(0.0, select(1.0, min(1.0, Dc.r / (1.0 - d.Sc.r)), d.Sc.r < 1.0), Dc.r > 0.0); + Rc.g = select(0.0, select(1.0, min(1.0, Dc.g / (1.0 - d.Sc.g)), d.Sc.g < 1.0), Dc.g > 0.0); + Rc.b = select(0.0, select(1.0, min(1.0, Dc.b / (1.0 - d.Sc.b)), d.Sc.b < 1.0), Dc.b > 0.0); + Rc = mix(d.Sc, Rc, d.Da); + } + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_ColorBurn(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + Rc.r = select(select(1.0, 0.0, Dc.r < 1), 1.0 - min(1.0, (1.0 - Dc.r) / d.Sc.r), d.Sc.r > 0); + Rc.g = select(select(1.0, 0.0, Dc.g < 1), 1.0 - min(1.0, (1.0 - Dc.g) / d.Sc.g), d.Sc.g > 0); + Rc.b = select(select(1.0, 0.0, Dc.b < 1), 1.0 - min(1.0, (1.0 - Dc.b) / d.Sc.b), d.Sc.b > 0); + Rc = mix(d.Sc, Rc, d.Da); + } + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_HardLight(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + Rc.r = select(1.0 - min(1.0, 2 * (1 - d.Sc.r) * (1 - Dc.r)), min(1.0, 2 * d.Sc.r * Dc.r), (d.Sc.r < 0.5)); + Rc.g = select(1.0 - min(1.0, 2 * (1 - d.Sc.g) * (1 - Dc.g)), min(1.0, 2 * d.Sc.g * Dc.g), (d.Sc.g < 0.5)); + Rc.b = select(1.0 - min(1.0, 2 * (1 - d.Sc.b) * (1 - Dc.b)), min(1.0, 2 * d.Sc.b * Dc.b), (d.Sc.b < 0.5)); + Rc = mix(d.Sc, Rc, d.Da); + } + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_SoftLight(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + Rc = min(One, (One - 2 * d.Sc) * Dc * Dc + 2.0 * d.Sc * Dc); + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Difference(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + let Rc = abs(d.Dc - d.Sc); + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Exclusion(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + let Rc = d.Sc + d.Dc - 2 * d.Sc * d.Dc; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Hue(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + let Sc = d.Sc; + + let Shsl = rgbToHsl(Sc); + let Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Shsl.r, Dhsl.g, Dhsl.b)); // sh, ds, dl + + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Saturation(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + let Sc = d.Sc; + + let Shsl = rgbToHsl(Sc); + let Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Dhsl.r, Shsl.g, Dhsl.b)); // dh, ss, dl + + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Color(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + let Sc = d.Sc; + + let Shsl = rgbToHsl(Sc); + let Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Shsl.r, Shsl.g, Dhsl.b)); // sh, ss, dl + + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Luminosity(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + var Rc = d.Sc; + if (d.Da > 0.0) { + let Dc = min(One, d.Dc / d.Da); + let Sc = d.Sc; + + let Shsl = rgbToHsl(Sc); + let Dhsl = rgbToHsl(Dc); + Rc = hslToRgb(vec3(Dhsl.r, Dhsl.g, Shsl.b)); // dh, ds, sl + + Rc = mix(d.Sc, Rc, d.Da); + }; + return postProcess(d, vec4f(Rc, 1.0)); +} + +@fragment +fn fs_main_Add(in: VertexOutput) -> @location(0) vec4f { + let d: FragData = getFragData(in); + let Rc = min(One, d.Sc + d.Dc); + return postProcess(d, vec4f(Rc, 1.0)); +} +)"; + +//************************************************************************ +// graphics shader source: scene compose +//************************************************************************ + +const char* cShaderSrc_Scene_Compose = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) texCoord: vec2f }; + +@group(0) @binding(0) var uSamplerSrc : sampler; +@group(0) @binding(1) var uTextureSrc : texture_2d; +@group(1) @binding(0) var uSamplerMsk : sampler; +@group(1) @binding(1) var uTextureMsk : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = vec4f(in.position.xy, 0.0, 1.0); + out.texCoord = in.texCoord; + return out; +} + +@fragment +fn fs_main_None(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + return vec4f(src); +}; + +@fragment +fn fs_main_ClipPath(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src * msk.a); +}; + +@fragment +fn fs_main_AlphaMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src * msk.a); +}; + +@fragment +fn fs_main_InvAlphaMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src * (1.0 - msk.a)); +}; + +@fragment +fn fs_main_LumaMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + let luma: f32 = dot(msk.rgb, vec3f(0.2125, 0.7154, 0.0721)); + return vec4f(src * luma); +}; + +@fragment +fn fs_main_InvLumaMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + let luma: f32 = dot(msk.rgb, vec3f(0.2125, 0.7154, 0.0721)); + return vec4f(src * (1.0 - luma)); +}; + +@fragment +fn fs_main_AddMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src.rgb, src.a + msk.a * (1.0 - src.a)); +}; + +@fragment +fn fs_main_SubtractMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src.rgb, src.a * (1.0 - msk.a)); +}; + +@fragment +fn fs_main_IntersectMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src.rgb, src.a * msk.a); +}; + +@fragment +fn fs_main_DifferenceMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src.rgb, src.a * (1.0 - msk.a) + msk.a * (1.0 - src.a)); +}; + +@fragment +fn fs_main_LightenMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src.rgb, max(src.a, msk.a)); +}; + +@fragment +fn fs_main_DarkenMask(in: VertexOutput) -> @location(0) vec4f { + let src: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let msk: vec4f = textureSample(uTextureMsk, uSamplerMsk, in.texCoord.xy); + return vec4f(src.rgb, min(src.a, msk.a)); +}; +)"; + +//************************************************************************ +// graphics shader source: texture blit +//************************************************************************ + +const char* cShaderSrc_Blit = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) texCoord: vec2f }; + +@group(0) @binding(0) var uSamplerSrc : sampler; +@group(0) @binding(1) var uTextureSrc : texture_2d; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = vec4f(in.position.xy, 0.0, 1.0); + out.texCoord = in.texCoord; + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4f { + return textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); +}; +)"; + +//************************************************************************ +// shader source: effects +//************************************************************************ + +const char* cShaderSrc_Shadow = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) texCoord: vec2f }; + +@group(0) @binding(0) var uSamplerSrc : sampler; +@group(0) @binding(1) var uTextureSrc : texture_2d; +@group(1) @binding(0) var uSamplerSdw : sampler; +@group(1) @binding(1) var uTextureSdw : texture_2d; +@group(2) @binding(0) var settings: array; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = vec4f(in.position.xy, 0.0, 1.0); + out.texCoord = in.texCoord; + return out; +} + +@fragment +fn fs_main_shadow(in: VertexOutput) -> @location(0) vec4f { + let texelSize: vec2f = 1.0 / vec2f(textureDimensions(uTextureSrc)); + let offset: vec2f = settings[2].xy * texelSize; + let orig: vec4f = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let blur: vec4f = textureSample(uTextureSdw, uSamplerSdw, in.texCoord.xy - offset); + let shad: vec4f = settings[1] * blur.a; + return orig + shad * (1.0 - orig.a); +}; +)"; + +const char* cShaderSrc_Effects = R"( +struct VertexInput { @location(0) position: vec2f, @location(1) texCoord: vec2f }; +struct VertexOutput { @builtin(position) position: vec4f, @location(0) texCoord: vec2f }; + +@group(0) @binding(0) var uSamplerSrc : sampler; +@group(0) @binding(1) var uTextureSrc : texture_2d; +@group(1) @binding(0) var settings: array; + +@vertex +fn vs_main(in: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.position = vec4f(in.position.xy, 0.0, 1.0); + out.texCoord = in.texCoord; + return out; +} + +fn gaussian(x: f32, sigma: f32) -> f32 { + let exponent: f32 = -x * x / (2.0 * sigma * sigma); + return exp(exponent) * 0.39894f / sigma; +} + +@fragment +fn fs_main_vert(in: VertexOutput) -> @location(0) vec4f { + let texelSize: vec2f = 1.0 / vec2f(textureDimensions(uTextureSrc)); + var colorSum: vec4f = vec4(0.0); + let sigma: f32 = settings[0].x * settings[0].y; + var weightSum: f32 = 0.0; + let radius: i32 = i32(settings[0].z); + + for (var y: i32 = -radius; y <= radius; y++) { + let offset: vec2f = vec2f(0.0, f32(y) * texelSize.y); + let coord = in.texCoord.xy + offset; + let weight: f32 = select(0.0, gaussian(f32(y), sigma), saturate(coord.y) == coord.y); + colorSum += textureSample(uTextureSrc, uSamplerSrc, coord) * weight; + weightSum += weight; + } + + return colorSum / weightSum; +}; + +@fragment +fn fs_main_horz(in: VertexOutput) -> @location(0) vec4f { + let texelSize: vec2f = 1.0 / vec2f(textureDimensions(uTextureSrc)); + var colorSum: vec4f = vec4(0.0); + let sigma: f32 = settings[0].x * settings[0].y; + var weightSum: f32 = 0.0; + let radius: i32 = i32(settings[0].z); + + for (var y: i32 = -radius; y <= radius; y++) { + let offset: vec2f = vec2f(f32(y) * texelSize.x, 0.0); + let coord = in.texCoord.xy + offset; + let weight: f32 = select(0.0, gaussian(f32(y), sigma), saturate(coord.x) == coord.x); + colorSum += textureSample(uTextureSrc, uSamplerSrc, coord) * weight; + weightSum += weight; + } + + return colorSum / weightSum; +}; + +@fragment +fn fs_main_fill(in: VertexOutput) -> @location(0) vec4f { + let orig = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let fill = settings[0]; + return fill * orig.a * fill.a; +}; + +@fragment +fn fs_main_tint(in: VertexOutput) -> @location(0) vec4f { + let orig = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let luma: f32 = dot(orig.rgb, vec3f(0.2126, 0.7152, 0.0722)); + return vec4f(mix(orig.rgb, mix(settings[0].rgb, settings[1].rgb, luma), settings[2].r) * orig.a, orig.a); +}; + +@fragment +fn fs_main_tritone(in: VertexOutput) -> @location(0) vec4f { + let orig = textureSample(uTextureSrc, uSamplerSrc, in.texCoord.xy); + let luma: f32 = dot(orig.rgb, vec3f(0.2126, 0.7152, 0.0722)); + let isBright: bool = luma >= 0.5f; + let t = select(luma * 2.0f, (luma - 0.5) * 2.0f, isBright); + let frm: vec3f = select(settings[0].rgb, settings[1].rgb, isBright); + let to: vec3f = select(settings[1].rgb, settings[2].rgb, isBright); + var tmp: vec4f = vec4f(mix(frm, to, t), 1.0f); + + if (settings[2].a > 0.0f) { tmp = mix(tmp, orig, settings[2].a); } + return tmp * orig.a; +}; +)"; \ No newline at end of file diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderSrc.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderSrc.h new file mode 100644 index 0000000..06ddc94 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderSrc.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_SHADER_SRC_H_ +#define _TVG_WG_SHADER_SRC_H_ + +// helper shaders +extern const char* cShaderSrc_Stencil; +extern const char* cShaderSrc_Depth; +// shaders normal blend +extern const char* cShaderSrc_Solid; +extern const char* cShaderSrc_Linear; +extern const char* cShaderSrc_Radial; +extern const char* cShaderSrc_Image; +extern const char* cShaderSrc_Scene; +// shaders custrom blend +extern const char* cShaderSrc_Solid_Blend; +extern const char* cShaderSrc_Linear_Blend; +extern const char* cShaderSrc_Radial_Blend; +extern const char* cShaderSrc_Image_Blend; +extern const char* cShaderSrc_Scene_Blend; +extern const char* cShaderSrc_BlendFuncs; +// shaders scene compose +extern const char* cShaderSrc_Scene_Compose; +// shaders blit +extern const char* cShaderSrc_Blit; + +// shader sources effects +extern const char* cShaderSrc_Shadow; +extern const char* cShaderSrc_Effects; + +#endif // _TVG_WG_SHEDER_SRC_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderTypes.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderTypes.cpp new file mode 100644 index 0000000..043cb3f --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderTypes.cpp @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgShaderTypes.h" +#include +#include "tvgMath.h" +#include "tvgFill.h" + +//************************************************************************ +// WgShaderTypeMat4x4f +//************************************************************************ + +WgShaderTypeMat4x4f::WgShaderTypeMat4x4f() +{ + identity(); +} + + +WgShaderTypeMat4x4f::WgShaderTypeMat4x4f(const Matrix& transform) +{ + update(transform); +} + + +void WgShaderTypeMat4x4f::identity() +{ + mat[0] = 1.0f; mat[1] = 0.0f; mat[2] = 0.0f; mat[3] = 0.0f; + mat[4] = 0.0f; mat[5] = 1.0f; mat[6] = 0.0f; mat[7] = 0.0f; + mat[8] = 0.0f; mat[9] = 0.0f; mat[10] = 1.0f; mat[11] = 0.0f; + mat[12] = 0.0f; mat[13] = 0.0f; mat[14] = 0.0f; mat[15] = 1.0f; +} + + +WgShaderTypeMat4x4f::WgShaderTypeMat4x4f(size_t w, size_t h) +{ + update(w, h); +} + + +void WgShaderTypeMat4x4f::update(const Matrix& transform) +{ + + mat[0] = transform.e11; + mat[1] = transform.e21; + mat[2] = 0.0f; + mat[3] = transform.e31; + mat[4] = transform.e12; + mat[5] = transform.e22; + mat[6] = 0.0f; + mat[7] = transform.e32; + mat[8] = 0.0f; + mat[9] = 0.0f; + mat[10] = 1.0f; + mat[11] = 0.0f; + mat[12] = transform.e13; + mat[13] = transform.e23; + mat[14] = 0.0f; + mat[15] = transform.e33; +} + + +void WgShaderTypeMat4x4f::update(size_t w, size_t h) +{ + mat[0] = +2.0f / w; mat[1] = +0.0f; mat[2] = +0.0f; mat[3] = +0.0f; + mat[4] = +0.0f; mat[5] = -2.0f / h; mat[6] = +0.0f; mat[7] = +0.0f; + mat[8] = +0.0f; mat[9] = +0.0f; mat[10] = -1.0f; mat[11] = +0.0f; + mat[12] = -1.0f; mat[13] = +1.0f; mat[14] = +0.0f; mat[15] = +1.0f; +} + +//************************************************************************ +// WgShaderTypeVec4f +//************************************************************************ + +WgShaderTypeVec4f::WgShaderTypeVec4f(const ColorSpace colorSpace, uint8_t o) +{ + update(colorSpace, o); +} + + +WgShaderTypeVec4f::WgShaderTypeVec4f(const RenderColor& c) +{ + update(c); +} + + +void WgShaderTypeVec4f::update(const ColorSpace colorSpace, uint8_t o) +{ + vec[0] = (uint32_t)colorSpace; + vec[3] = o / 255.0f; +} + + +void WgShaderTypeVec4f::update(const RenderColor& c) +{ + vec[0] = c.r / 255.0f; // red + vec[1] = c.g / 255.0f; // green + vec[2] = c.b / 255.0f; // blue + vec[3] = c.a / 255.0f; // alpha +} + +void WgShaderTypeVec4f::update(const RenderRegion& r) +{ + vec[0] = r.min.x; + vec[1] = r.min.y; + vec[2] = r.max.x - 1; + vec[3] = r.max.y - 1; +} + +//************************************************************************ +// WgShaderTypeGradSettings +//************************************************************************ + +void WgShaderTypeGradSettings::update(const Fill* fill) +{ + assert(fill); + // update transform matrix + Matrix invTransform; + if (inverse(&fill->transform(), &invTransform)) + transform.update(invTransform); + else transform.identity(); + // update gradient base points + if (fill->type() == Type::LinearGradient) + ((LinearGradient*)fill)->linear(&coords.vec[0], &coords.vec[1], &coords.vec[2], &coords.vec[3]); + else if (fill->type() == Type::RadialGradient) { + ((RadialGradient*)fill)->radial(&coords.vec[0], &coords.vec[1], &coords.vec[2], &focal.vec[0], &focal.vec[1], &focal.vec[2]); + CONST_RADIAL(fill)->correct(focal.vec[0], focal.vec[1], focal.vec[2]); + } +} + +//************************************************************************ +// WgShaderTypeGradientData +//************************************************************************ + +void WgShaderTypeGradientData::update(const Fill* fill) +{ + if (!fill) return; + const Fill::ColorStop* stops = nullptr; + auto stopCnt = fill->colorStops(&stops); + if (stopCnt == 0) return; + static Array sstops(stopCnt); + sstops.clear(); + sstops.push(stops[0]); + // filter by increasing offset + for (uint32_t i = 1; i < stopCnt; i++) + if (sstops.last().offset < stops[i].offset) + sstops.push(stops[i]); + else if (sstops.last().offset == stops[i].offset) + sstops.last() = stops[i]; + // head + uint32_t range_s = 0; + uint32_t range_e = uint32_t(sstops[0].offset * (WG_TEXTURE_GRADIENT_SIZE-1)); + for (uint32_t ti = range_s; (ti < range_e) && (ti < WG_TEXTURE_GRADIENT_SIZE); ti++) { + data[ti * 4 + 0] = sstops[0].r; + data[ti * 4 + 1] = sstops[0].g; + data[ti * 4 + 2] = sstops[0].b; + data[ti * 4 + 3] = sstops[0].a; + } + // body + for (uint32_t di = 1; di < sstops.count; di++) { + range_s = uint32_t(sstops[di-1].offset * (WG_TEXTURE_GRADIENT_SIZE-1)); + range_e = uint32_t(sstops[di-0].offset * (WG_TEXTURE_GRADIENT_SIZE-1)); + float delta = 1.0f/(range_e - range_s); + for (uint32_t ti = range_s; (ti < range_e) && (ti < WG_TEXTURE_GRADIENT_SIZE); ti++) { + float t = (ti - range_s) * delta; + data[ti * 4 + 0] = tvg::lerp(sstops[di-1].r, sstops[di].r, t); + data[ti * 4 + 1] = tvg::lerp(sstops[di-1].g, sstops[di].g, t); + data[ti * 4 + 2] = tvg::lerp(sstops[di-1].b, sstops[di].b, t); + data[ti * 4 + 3] = tvg::lerp(sstops[di-1].a, sstops[di].a, t); + } + } + // tail + const tvg::Fill::ColorStop& colorStopLast = sstops.last(); + range_s = uint32_t(colorStopLast.offset * (WG_TEXTURE_GRADIENT_SIZE-1)); + range_e = WG_TEXTURE_GRADIENT_SIZE; + for (uint32_t ti = range_s; ti < range_e; ti++) { + data[ti * 4 + 0] = colorStopLast.r; + data[ti * 4 + 1] = colorStopLast.g; + data[ti * 4 + 2] = colorStopLast.b; + data[ti * 4 + 3] = colorStopLast.a; + } +} + +//************************************************************************ +// WgShaderTypeEffectParams +//************************************************************************ + +bool WgShaderTypeEffectParams::update(RenderEffectGaussianBlur* gaussian, const Matrix& transform) +{ + assert(gaussian); + params[0] = gaussian->sigma; + params[1] = std::sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12); + params[2] = 2 * gaussian->sigma * params[1]; + extend = params[2] * 2; // kernel + gaussian->valid = (extend > 0); + return gaussian->valid; +} + + +bool WgShaderTypeEffectParams::update(RenderEffectDropShadow* dropShadow, const Matrix& transform) +{ + assert(dropShadow); + const auto scale = std::sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12); + const auto kernel = 2 * dropShadow->sigma * scale; + const auto radian = tvg::deg2rad(90.0f - dropShadow->angle) - tvg::radian(transform); + const Point offset = {dropShadow->distance * cosf(radian) * scale, -dropShadow->distance * sinf(radian) * scale}; + params[0] = dropShadow->sigma; + params[1] = scale; + params[2] = kernel; + params[3] = 0.0f; + params[7] = dropShadow->color[3] / 255.0f; // alpha + //Color is premultiplied to avoid multiplication in the fragment shader: + params[4] = dropShadow->color[0] / 255.0f * params[7]; // red + params[5] = dropShadow->color[1] / 255.0f * params[7]; // green + params[6] = dropShadow->color[2] / 255.0f * params[7]; // blue + params[8] = offset.x; + params[9] = offset.y; + extend = 2 * std::max(dropShadow->sigma * scale + std::abs(offset.x), dropShadow->sigma * scale + std::abs(offset.y)); + + dropShadow->valid = (extend >= 0); + return dropShadow->valid; +} + + +bool WgShaderTypeEffectParams::update(RenderEffectFill* fill) +{ + params[0] = fill->color[0] / 255.0f; + params[1] = fill->color[1] / 255.0f; + params[2] = fill->color[2] / 255.0f; + params[3] = fill->color[3] / 255.0f; + + fill->valid = true; + return true; +} + + +bool WgShaderTypeEffectParams::update(RenderEffectTint* tint) +{ + params[0] = tint->black[0] / 255.0f; + params[1] = tint->black[1] / 255.0f; + params[2] = tint->black[2] / 255.0f; + params[3] = 0.0f; + params[4] = tint->white[0] / 255.0f; + params[5] = tint->white[1] / 255.0f; + params[6] = tint->white[2] / 255.0f; + params[7] = 0.0f; + params[8] = tint->intensity / 255.0f; + + tint->valid = (tint->intensity > 0); + return tint->valid; +} + + +bool WgShaderTypeEffectParams::update(RenderEffectTritone* tritone) +{ + params[0] = tritone->shadow[0] / 255.0f; + params[1] = tritone->shadow[1] / 255.0f; + params[2] = tritone->shadow[2] / 255.0f; + params[3] = 0.0f; + params[4] = tritone->midtone[0] / 255.0f; + params[5] = tritone->midtone[1] / 255.0f; + params[6] = tritone->midtone[2] / 255.0f; + params[7] = 0.0f; + params[8] = tritone->highlight[0] / 255.0f; + params[9] = tritone->highlight[1] / 255.0f; + params[10] = tritone->highlight[2] / 255.0f; + params[11] = tritone->blender / 255.0f; + + tritone->valid = tritone->blender < 255; + return true; +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderTypes.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderTypes.h new file mode 100644 index 0000000..7a450d7 --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgShaderTypes.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_SHADER_TYPES_H_ +#define _TVG_WG_SHADER_TYPES_H_ + +#include "tvgRender.h" + +/////////////////////////////////////////////////////////////////////////////// +// shader types +/////////////////////////////////////////////////////////////////////////////// + +// mat4x4f +struct WgShaderTypeMat4x4f +{ + float mat[16]{}; + + WgShaderTypeMat4x4f(); + WgShaderTypeMat4x4f(const Matrix& transform); + WgShaderTypeMat4x4f(size_t w, size_t h); + void identity(); + void update(const Matrix& transform); + void update(size_t w, size_t h); +}; + +// vec4f +struct WgShaderTypeVec4f +{ + float vec[4]{}; + + WgShaderTypeVec4f() {}; + WgShaderTypeVec4f(const ColorSpace colorSpace, uint8_t o); + WgShaderTypeVec4f(const RenderColor& c); + void update(const ColorSpace colorSpace, uint8_t o); + void update(const RenderColor& c); + void update(const RenderRegion& r); +}; + +// WGSL: struct GradSettings { transform: mat4x4f, coords: vec4f, focal: vec4f }; +struct WgShaderTypeGradSettings +{ + // gradient transform matrix + WgShaderTypeMat4x4f transform; + // linear: [0] - x1, [1] - y1, [2] - x2, [3] - y2 + // radial: [0] - cx, [1] - cy, [2] - cr + WgShaderTypeVec4f coords; + // radial: [0] - fx, [1] - fy, [2] - fr + WgShaderTypeVec4f focal; + + void update(const Fill* fill); +}; + +// WGSL: struct PaintSettings { transform: mat4x4f, options: vec4f, color: vec4f, gradient: GradSettings }; +struct WgShaderTypePaintSettings +{ + // paint transform matrix (must be at offset 0) + WgShaderTypeMat4x4f transform; + // [0] - color space, [3] - opacity + WgShaderTypeVec4f options; + // solid color + WgShaderTypeVec4f color; + // gradient settings (linear/radial) + WgShaderTypeGradSettings gradient; + // align to 256 bytes (see webgpu spec: minUniformBufferOffsetAlignment) + uint8_t _padding[256 - sizeof(transform) - sizeof(options) - sizeof(color) - sizeof(gradient)]; +}; +// see webgpu spec: 3.6.2. Limits - minUniformBufferOffsetAlignment (256) +static_assert(sizeof(WgShaderTypePaintSettings) == 256, "Uniform shader data type size must be aligned to 256 bytes"); + +// gradient color map +#define WG_TEXTURE_GRADIENT_SIZE 512 +struct WgShaderTypeGradientData +{ + uint8_t data[WG_TEXTURE_GRADIENT_SIZE * 4]; + + void update(const Fill* fill); +}; + +// gaussian params: sigma, scale, extend +#define WG_GAUSSIAN_KERNEL_SIZE_MAX (128.0f) +// gaussian blur, drop shadow, fill, tint, tritone +struct WgShaderTypeEffectParams +{ + // gaussian blur: [0]: sigma, [1]: scale, [2]: kernel size + // drop shadow: [0]: sigma, [1]: scale, [2]: kernel size, [4..7]: color, [8, 9]: offset + // fill: [0..3]: color + // tint: [0..2]: black, [4..6]: white, [8]: intensity + // tritone: [0..2]: shadow, [4..6]: midtone, [8..10]: highlight + float params[4+4+4]{}; // settings: array; + uint32_t extend{}; // gaussian blur extend + Point offset{}; // drop shadow offset + + bool update(RenderEffectGaussianBlur* gaussian, const Matrix& transform); + bool update(RenderEffectDropShadow* dropShadow, const Matrix& transform); + bool update(RenderEffectFill* fill); + bool update(RenderEffectTint* tint); + bool update(RenderEffectTritone* tritone); +}; + +#endif // _TVG_WG_SHADER_TYPES_H_ diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgTessellator.cpp b/components/thorvg-main/src/renderer/wg_engine/tvgWgTessellator.cpp new file mode 100644 index 0000000..8ccd51f --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgTessellator.cpp @@ -0,0 +1,554 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgWgTessellator.h" +#include "tvgMath.h" + + +WgStroker::WgStroker(WgMeshData* buffer, float width, StrokeCap cap, StrokeJoin join) + : mBuffer(buffer), mWidth(width), mCap(cap), mJoin(join) +{ +} + + +void WgStroker::run(const RenderShape& rshape, const RenderPath& path, const Matrix& m) +{ + mMiterLimit = rshape.strokeMiterlimit(); + mCap = rshape.strokeCap(); + mJoin = rshape.strokeJoin(); + + RenderPath dashed; + if (rshape.strokeDash(dashed)) run(dashed, m); + else run(path, m); +} + + +RenderRegion WgStroker::bounds() const +{ + return {{int32_t(floor(mLeftTop.x)), int32_t(floor(mLeftTop.y))}, {int32_t(ceil(mRightBottom.x)), int32_t(ceil(mRightBottom.y))}}; +} + + +BBox WgStroker::getBBox() const +{ + return {mLeftTop, mRightBottom}; +} + +void WgStroker::run(const RenderPath& path, const Matrix& m) +{ + mBuffer->vbuffer.reserve(path.pts.count * 4 + 16); + mBuffer->ibuffer.reserve(path.pts.count * 3); + mScale = tvg::scaling(m); + + auto validStrokeCap = false; + auto pts = path.pts.data; + + ARRAY_FOREACH(cmd, path.cmds) { + switch (*cmd) { + case PathCommand::MoveTo: { + if (validStrokeCap) { // check this, so we can skip if path only contains move instruction + cap(); + validStrokeCap = false; + } + mState.firstPt = *pts; + mState.firstPtDir = {0.0f, 0.0f}; + mState.prevPt = *pts; + mState.prevPtDir = {0.0f, 0.0f}; + pts++; + validStrokeCap = false; + } break; + case PathCommand::LineTo: { + validStrokeCap = true; + lineTo(*pts); + pts++; + } break; + case PathCommand::CubicTo: { + validStrokeCap = true; + cubicTo(pts[0], pts[1], pts[2], m); + pts += 3; + } break; + case PathCommand::Close: { + close(); + + validStrokeCap = false; + } break; + default: + break; + } + } + if (validStrokeCap) cap(); +} + + +void WgStroker::cap() +{ + if (mCap == StrokeCap::Butt) return; + + if (mCap == StrokeCap::Square) { + if (mState.firstPt == mState.prevPt) squarePoint(mState.firstPt); + else { + square(mState.firstPt, {-mState.firstPtDir.x, -mState.firstPtDir.y}); + square(mState.prevPt, mState.prevPtDir); + } + } else if (mCap == StrokeCap::Round) { + if (mState.firstPt == mState.prevPt) roundPoint(mState.firstPt); + else { + round(mState.firstPt, {-mState.firstPtDir.x, -mState.firstPtDir.y}); + round(mState.prevPt, mState.prevPtDir); + } + } +} + + +void WgStroker::lineTo(const Point& curr) +{ + auto dir = (curr - mState.prevPt); + normalize(dir); + + if (dir.x == 0.f && dir.y == 0.f) return; //same point + + auto normal = Point{-dir.y, dir.x}; + auto a = mState.prevPt + normal * radius(); + auto b = mState.prevPt - normal * radius(); + auto c = curr + normal * radius(); + auto d = curr - normal * radius(); + + auto ia = mBuffer->vbuffer.count; mBuffer->vbuffer.push(a); + auto ib = mBuffer->vbuffer.count; mBuffer->vbuffer.push(b); + auto ic = mBuffer->vbuffer.count; mBuffer->vbuffer.push(c); + auto id = mBuffer->vbuffer.count; mBuffer->vbuffer.push(d); + + /** + * a --------- c + * | | + * | | + * b-----------d + */ + + mBuffer->ibuffer.push(ia); + mBuffer->ibuffer.push(ib); + mBuffer->ibuffer.push(ic); + mBuffer->ibuffer.push(ib); + mBuffer->ibuffer.push(id); + mBuffer->ibuffer.push(ic); + + if (mState.prevPt == mState.firstPt) { + // first point after moveTo + mState.prevPt = curr; + mState.prevPtDir = dir; + mState.firstPtDir = dir; + } else { + join(dir); + mState.prevPtDir = dir; + mState.prevPt = curr; + } + + if (ia == 0) { + mRightBottom.x = mLeftTop.x = curr.x; + mRightBottom.y = mLeftTop.y = curr.y; + } + + mLeftTop.x = std::min(mLeftTop.x, std::min(std::min(a.x, b.x), std::min(c.x, d.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(std::min(a.y, b.y), std::min(c.y, d.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(std::max(a.x, b.x), std::max(c.x, d.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(std::max(a.y, b.y), std::max(c.y, d.y))); +} + + +void WgStroker::cubicTo(const Point& cnt1, const Point& cnt2, const Point& end, const Matrix& m) +{ + Bezier curve {mState.prevPt, cnt1, cnt2, end}; + + Bezier relCurve {curve.start, curve.ctrl1, curve.ctrl2, curve.end}; + relCurve.start *= m; + relCurve.ctrl1 *= m; + relCurve.ctrl2 *= m; + relCurve.end *= m; + + auto count = relCurve.segments(); + auto step = 1.f / count; + + for (uint32_t i = 0; i <= count; i++) { + lineTo(curve.at(step * i)); + } +} + + +void WgStroker::close() +{ + if (length(mState.prevPt - mState.firstPt) > 0.015625f) { + lineTo(mState.firstPt); + } + + // join firstPt with prevPt + join(mState.firstPtDir); +} + + +void WgStroker::join(const Point& dir) +{ + auto orient = orientation(mState.prevPt - mState.prevPtDir, mState.prevPt, mState.prevPt + dir); + + if (orient == Orientation::Linear) { + if (mState.prevPtDir == dir) return; // check is same direction + if (mJoin != StrokeJoin::Round) return; // opposite direction + + auto normal = Point{-dir.y, dir.x}; + auto p1 = mState.prevPt + normal * radius(); + auto p2 = mState.prevPt - normal * radius(); + auto oc = mState.prevPt + dir * radius(); + + round(p1, oc, mState.prevPt); + round(oc, p2, mState.prevPt); + + } else { + auto normal = Point{-dir.y, dir.x}; + auto prevNormal = Point{-mState.prevPtDir.y, mState.prevPtDir.x}; + Point prevJoin, currJoin; + + if (orient == Orientation::CounterClockwise) { + prevJoin = mState.prevPt + prevNormal * radius(); + currJoin = mState.prevPt + normal * radius(); + } else { + prevJoin = mState.prevPt - prevNormal * radius(); + currJoin = mState.prevPt - normal * radius(); + } + + if (mJoin == StrokeJoin::Miter) miter(prevJoin, currJoin, mState.prevPt); + else if (mJoin == StrokeJoin::Bevel) bevel(prevJoin, currJoin, mState.prevPt); + else round(prevJoin, currJoin, mState.prevPt); + } +} + + +void WgStroker::round(const Point &prev, const Point& curr, const Point& center) +{ + auto orient = orientation(prev, center, curr); + if (orient == Orientation::Linear) return; + + mLeftTop.x = std::min(mLeftTop.x, std::min(center.x, std::min(prev.x, curr.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(center.y, std::min(prev.y, curr.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(center.x, std::max(prev.x, curr.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(center.y, std::max(prev.y, curr.y))); + + auto startAngle = tvg::atan2(prev.y - center.y, prev.x - center.x); + auto endAngle = tvg::atan2(curr.y - center.y, curr.x - center.x); + + if (orient == Orientation::Clockwise) { + if (endAngle > startAngle) endAngle -= 2 * MATH_PI; + } else { + if (endAngle < startAngle) endAngle += 2 * MATH_PI; + } + + auto arcAngle = endAngle - startAngle; + auto count = tvg::arcSegmentsCnt(arcAngle, radius() * mScale); + + auto c = mBuffer->vbuffer.count; mBuffer->vbuffer.push(center); + auto pi = mBuffer->vbuffer.count; mBuffer->vbuffer.push(prev); + auto step = (endAngle - startAngle) / (count - 1); + + for (uint32_t i = 1; i < static_cast(count); i++) { + auto angle = startAngle + step * i; + Point out = {center.x + cos(angle) * radius(), center.y + sin(angle) * radius()}; + auto oi = mBuffer->vbuffer.count; mBuffer->vbuffer.push(out); + + mBuffer->ibuffer.push(c); + mBuffer->ibuffer.push(pi); + mBuffer->ibuffer.push(oi); + + pi = oi; + + mLeftTop.x = std::min(mLeftTop.x, out.x); + mLeftTop.y = std::min(mLeftTop.y, out.y); + mRightBottom.x = std::max(mRightBottom.x, out.x); + mRightBottom.y = std::max(mRightBottom.y, out.y); + } +} + + +void WgStroker::roundPoint(const Point &p) +{ + auto count = tvg::arcSegmentsCnt(2.0f * MATH_PI, radius() * mScale); + auto c = mBuffer->vbuffer.count; mBuffer->vbuffer.push(p); + auto step = 2.0f * MATH_PI / (count - 1); + + for (uint32_t i = 1; i <= static_cast(count); i++) { + float angle = i * step; + Point dir = {cos(angle), sin(angle)}; + Point out = p + dir * radius(); + auto oi = mBuffer->vbuffer.count; mBuffer->vbuffer.push(out); + + if (oi > 1) { + mBuffer->ibuffer.push(c); + mBuffer->ibuffer.push(oi); + mBuffer->ibuffer.push(oi - 1); + } + } + + mLeftTop.x = std::min(mLeftTop.x, p.x - radius()); + mLeftTop.y = std::min(mLeftTop.y, p.y - radius()); + mRightBottom.x = std::max(mRightBottom.x, p.x + radius()); + mRightBottom.y = std::max(mRightBottom.y, p.y + radius()); +} + + +void WgStroker::miter(const Point& prev, const Point& curr, const Point& center) +{ + auto pp1 = prev - center; + auto pp2 = curr - center; + auto out = pp1 + pp2; + auto k = 2.f * radius() * radius() / (out.x * out.x + out.y * out.y); + auto pe = out * k; + + if (length(pe) >= mMiterLimit * radius()) { + bevel(prev, curr, center); + return; + } + + auto join = center + pe; + auto c = mBuffer->vbuffer.count; mBuffer->vbuffer.push(center); + auto cp1 = mBuffer->vbuffer.count; mBuffer->vbuffer.push(prev); + auto cp2 = mBuffer->vbuffer.count; mBuffer->vbuffer.push(curr); + auto e = mBuffer->vbuffer.count; mBuffer->vbuffer.push(join); + + mBuffer->ibuffer.push(c); + mBuffer->ibuffer.push(cp1); + mBuffer->ibuffer.push(e); + + mBuffer->ibuffer.push(e); + mBuffer->ibuffer.push(cp2); + mBuffer->ibuffer.push(c); + + mLeftTop.x = std::min(mLeftTop.x, join.x); + mLeftTop.y = std::min(mLeftTop.y, join.y); + + mRightBottom.x = std::max(mRightBottom.x, join.x); + mRightBottom.y = std::max(mRightBottom.y, join.y); +} + + +void WgStroker::bevel(const Point& prev, const Point& curr, const Point& center) +{ + auto a = mBuffer->vbuffer.count; mBuffer->vbuffer.push(prev); + auto b = mBuffer->vbuffer.count; mBuffer->vbuffer.push(curr); + auto c = mBuffer->vbuffer.count; mBuffer->vbuffer.push(center); + + mBuffer->ibuffer.push(a); + mBuffer->ibuffer.push(b); + mBuffer->ibuffer.push(c); +} + + +void WgStroker::square(const Point& p, const Point& outDir) +{ + auto normal = Point{-outDir.y, outDir.x}; + + auto a = p + normal * radius(); + auto b = p - normal * radius(); + auto c = a + outDir * radius(); + auto d = b + outDir * radius(); + + auto ai = mBuffer->vbuffer.count; mBuffer->vbuffer.push(a); + auto bi = mBuffer->vbuffer.count; mBuffer->vbuffer.push(b); + auto ci = mBuffer->vbuffer.count; mBuffer->vbuffer.push(c); + auto di = mBuffer->vbuffer.count; mBuffer->vbuffer.push(d); + + mBuffer->ibuffer.push(ai); + mBuffer->ibuffer.push(bi); + mBuffer->ibuffer.push(ci); + + mBuffer->ibuffer.push(ci); + mBuffer->ibuffer.push(bi); + mBuffer->ibuffer.push(di); + + mLeftTop.x = std::min(mLeftTop.x, std::min(std::min(a.x, b.x), std::min(c.x, d.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(std::min(a.y, b.y), std::min(c.y, d.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(std::max(a.x, b.x), std::max(c.x, d.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(std::max(a.y, b.y), std::max(c.y, d.y))); +} + + +void WgStroker::squarePoint(const Point& p) +{ + auto offsetX = Point{radius(), 0.0f}; + auto offsetY = Point{0.0f, radius()}; + + auto a = p + offsetX + offsetY; + auto b = p - offsetX + offsetY; + auto c = p - offsetX - offsetY; + auto d = p + offsetX - offsetY; + + auto ai = mBuffer->vbuffer.count; mBuffer->vbuffer.push(a); + auto bi = mBuffer->vbuffer.count; mBuffer->vbuffer.push(b); + auto ci = mBuffer->vbuffer.count; mBuffer->vbuffer.push(c); + auto di = mBuffer->vbuffer.count; mBuffer->vbuffer.push(d); + + mBuffer->ibuffer.push(ai); + mBuffer->ibuffer.push(bi); + mBuffer->ibuffer.push(ci); + + mBuffer->ibuffer.push(ci); + mBuffer->ibuffer.push(di); + mBuffer->ibuffer.push(ai); + + mLeftTop.x = std::min(mLeftTop.x, std::min(std::min(a.x, b.x), std::min(c.x, d.x))); + mLeftTop.y = std::min(mLeftTop.y, std::min(std::min(a.y, b.y), std::min(c.y, d.y))); + mRightBottom.x = std::max(mRightBottom.x, std::max(std::max(a.x, b.x), std::max(c.x, d.x))); + mRightBottom.y = std::max(mRightBottom.y, std::max(std::max(a.y, b.y), std::max(c.y, d.y))); +} + + +void WgStroker::round(const Point& p, const Point& outDir) +{ + auto normal = Point{-outDir.y, outDir.x}; + auto a = p + normal * radius(); + auto b = p - normal * radius(); + auto c = p + outDir * radius(); + + round(a, c, p); + round(c, b, p); +} + + +WgBWTessellator::WgBWTessellator(WgMeshData* buffer): mBuffer(buffer) +{ +} + + +void WgBWTessellator::tessellate(const RenderPath& path, const Matrix& matrix) +{ + if (path.pts.count <= 2) return; + + auto cmds = path.cmds.data; + auto cmdCnt = path.cmds.count; + auto pts = path.pts.data; + auto ptsCnt = path.pts.count; + + uint32_t firstIndex = 0; + uint32_t prevIndex = 0; + + mBuffer->vbuffer.reserve(ptsCnt * 2); + mBuffer->ibuffer.reserve((ptsCnt - 2) * 3); + + auto updateConvexity = [&](const Point& edge) { + if (!convex) return; + if (prevEdge.x == 0.0f && prevEdge.y == 0.0f) { prevEdge = edge; return; } + auto c = cross(prevEdge, edge); + if (zero(c)) { prevEdge = edge; return; } + auto sign = (c > 0) ? 1 : -1; + if (winding == 0) winding = sign; // The default winding is CCW, but it might be otherwise once we support unordered points.Expand commentComment on line R453ResolvedCode has comments. Press enter to view. + else if (sign != winding) convex = false; + prevEdge = edge; + }; + + for (uint32_t i = 0; i < cmdCnt; i++) { + switch(cmds[i]) { + case PathCommand::MoveTo: { + firstIndex = pushVertex(pts->x, pts->y); + firstPt = prevPt = *pts; + prevEdge = {}; + prevIndex = 0; + pts++; + } break; + case PathCommand::LineTo: { + if (prevIndex == 0) { + prevIndex = pushVertex(pts->x, pts->y); + prevEdge = *pts - prevPt; + prevPt = *pts++; + } else { + updateConvexity(*pts - prevPt); + auto currIndex = pushVertex(pts->x, pts->y); + pushTriangle(firstIndex, prevIndex, currIndex); + prevIndex = currIndex; + prevPt = *pts++; + } + } break; + case PathCommand::CubicTo: { + Bezier curve{pts[-1], pts[0], pts[1], pts[2]}; + if (convex) { + auto e1 = curve.ctrl1 - curve.start; + auto e2 = curve.ctrl2 - curve.ctrl1; + auto e3 = curve.end - curve.ctrl2; + if (prevIndex != 0) updateConvexity(e1); + else prevEdge = e1; + updateConvexity(e2); + updateConvexity(e3); + } + + auto stepCount = (curve * matrix).segments(); + if (stepCount <= 1) stepCount = 2; + float step = 1.f / stepCount; + + for (uint32_t s = 1; s <= static_cast(stepCount); s++) { + auto pt = curve.at(step * s); + auto currIndex = pushVertex(pt.x, pt.y); + if (prevIndex == 0) { prevIndex = currIndex; continue; } + pushTriangle(firstIndex, prevIndex, currIndex); + prevIndex = currIndex; + } + prevPt = curve.end; + pts += 3; + } break; + case PathCommand::Close: { + if (convex && prevIndex != 0) { + updateConvexity(firstPt - prevPt); + if (convex && winding != 0) { + auto secondPt = mBuffer->vbuffer[firstIndex+1]; + updateConvexity(secondPt - firstPt); + } + } + } break; + default: + break; + } + } +} + + +RenderRegion WgBWTessellator::bounds() const +{ + return {{int32_t(floor(bbox.min.x)), int32_t(floor(bbox.min.y))}, {int32_t(ceil(bbox.max.x)), int32_t(ceil(bbox.max.y))}}; +} + + +BBox WgBWTessellator::getBBox() const +{ + return bbox; +} + + +uint32_t WgBWTessellator::pushVertex(float x, float y) +{ + auto index = mBuffer->vbuffer.count; + mBuffer->vbuffer.push({x, y}); + if (index == 0) bbox.max = bbox.min = {x, y}; + else bbox = {{std::min(bbox.min.x, x), std::min(bbox.min.y, y)}, {std::max(bbox.max.x, x), std::max(bbox.max.y, y)}}; + return index; +} + + +void WgBWTessellator::pushTriangle(uint32_t a, uint32_t b, uint32_t c) +{ + mBuffer->ibuffer.push(a); + mBuffer->ibuffer.push(b); + mBuffer->ibuffer.push(c); +} diff --git a/components/thorvg-main/src/renderer/wg_engine/tvgWgTessellator.h b/components/thorvg-main/src/renderer/wg_engine/tvgWgTessellator.h new file mode 100644 index 0000000..ce3d3dd --- /dev/null +++ b/components/thorvg-main/src/renderer/wg_engine/tvgWgTessellator.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_WG_TESSELLATOR_H_ +#define _TVG_WG_TESSELLATOR_H_ + +#include "tvgRender.h" +#include "tvgWgGeometry.h" + +#define MIN_WG_STROKE_WIDTH 1.0f +#define MIN_WG_STROKE_ALPHA 0.25f + +class WgStroker +{ + struct State + { + Point firstPt; + Point firstPtDir; + Point prevPt; + Point prevPtDir; + }; +public: + WgStroker(WgMeshData* buffer, float width, StrokeCap cap, StrokeJoin join = StrokeJoin::Bevel); + void run(const RenderShape& rshape, const RenderPath& path, const Matrix& m); + RenderRegion bounds() const; + BBox getBBox() const; +private: + void run(const RenderPath& path, const Matrix& m); + + float radius() const + { + return mWidth * 0.5f; + } + + void cap(); + void lineTo(const Point& curr); + void cubicTo(const Point& cnt1, const Point& cnt2, const Point& end, const Matrix& m); + void close(); + void join(const Point& dir); + void round(const Point& prev, const Point& curr, const Point& center); + void miter(const Point& prev, const Point& curr, const Point& center); + void bevel(const Point& prev, const Point& curr, const Point& center); + void square(const Point& p, const Point& outDir); + void squarePoint(const Point& p); + void round(const Point& p, const Point& outDir); + void roundPoint(const Point& p); + + WgMeshData* mBuffer; + float mWidth = 0.0f; + float mMiterLimit = 4.f; + StrokeCap mCap = StrokeCap::Square; + StrokeJoin mJoin = StrokeJoin::Bevel; + State mState = {}; + Point mLeftTop = {0.0f, 0.0f}; + Point mRightBottom = {0.0f, 0.0f}; + float mScale; +}; + +class WgBWTessellator +{ +public: + WgBWTessellator(WgMeshData* buffer); + void tessellate(const RenderPath& path, const Matrix& matrix); + RenderRegion bounds() const; + BBox getBBox() const; + bool convex = true; +private: + uint32_t pushVertex(float x, float y); + void pushTriangle(uint32_t a, uint32_t b, uint32_t c); + + WgMeshData* mBuffer; + BBox bbox = {}; + Point firstPt = {}; + Point prevPt = {}; + Point prevEdge = {}; + int8_t winding = -1; //0: unknown, 1: CW, -1: CCW +}; + +#endif /* _TVG_WG_TESSELLATOR_H_ */ \ No newline at end of file diff --git a/components/thorvg-main/src/savers/gif/meson.build b/components/thorvg-main/src/savers/gif/meson.build new file mode 100644 index 0000000..155839b --- /dev/null +++ b/components/thorvg-main/src/savers/gif/meson.build @@ -0,0 +1,11 @@ +source_file = [ + 'tvgGifEncoder.h', + 'tvgGifSaver.h', + 'tvgGifEncoder.cpp', + 'tvgGifSaver.cpp', +] + +subsaver_dep += [declare_dependency( + include_directories : include_directories('.'), + sources : source_file +)] diff --git a/components/thorvg-main/src/savers/gif/tvgGifEncoder.cpp b/components/thorvg-main/src/savers/gif/tvgGifEncoder.cpp new file mode 100644 index 0000000..52456c0 --- /dev/null +++ b/components/thorvg-main/src/savers/gif/tvgGifEncoder.cpp @@ -0,0 +1,627 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +// +// gif.h +// by Charlie Tangora +// Public domain. +// Email me : ctangora -at- gmail -dot- com +// +// This file offers a simple, very limited way to create animated GIFs directly in code. +// +// Those looking for particular cleverness are likely to be disappointed; it's pretty +// much a straight-ahead implementation of the GIF format with optional Floyd-Steinberg +// dithering. (It does at least use delta encoding - only the changed portions of each +// frame are saved.) +// +// So resulting files are often quite large. The hope is that it will be handy nonetheless +// as a quick and easily-integrated way for programs to spit out animations. +// +// Only RGBA8 is currently supported as an input format. (The alpha is ignored.) +// +// USAGE: +// Create a GifWriter struct. Pass it to GifBegin() to initialize and write the header. +// Pass subsequent frames to GifWriteFrame(). +// Finally, call GifEnd() to close the file handle and free memory. +// + +#include "tvgMath.h" +#include "tvgGifEncoder.h" + + +#define TRANSPARENT_IDX 0 +#define TRANSPARENT_THRESHOLD 127 +#define BIT_DEPTH 8 + + +// Simple structure to write out the LZW-compressed portion of the image +// one bit at a time +typedef struct +{ + uint8_t bitIndex; // how many bits in the partial byte written so far + uint8_t byte; // current partial byte + + uint32_t chunkIndex; + uint8_t chunk[256]; // bytes are written in here until we have 256 of them, then written to the file +} GifBitStatus; + + +// The LZW dictionary is a 256-ary tree constructed as the file is encoded, +// this is one node +typedef struct +{ + uint16_t m_next[256]; +} GifLzwNode; + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +// walks the k-d tree to pick the palette entry for a desired color. +// Takes as in/out parameters the current best color and its error - +// only changes them if it finds a better color in its subtree. +// this is the major hotspot in the code at the moment. +static void _getClosestPaletteColor( GifPalette* pPal, int r, int g, int b, int* bestInd, int* bestDiff, int treeRoot ) +{ + // base case, reached the bottom of the tree + if (treeRoot > (1 << BIT_DEPTH) - 1) { + int ind = treeRoot-(1 << BIT_DEPTH); + if(ind == TRANSPARENT_IDX) return; + + // check whether this color is better than the current winner + int r_err = r - ((int32_t)pPal->r[ind]); + int g_err = g - ((int32_t)pPal->g[ind]); + int b_err = b - ((int32_t)pPal->b[ind]); + int diff = abs(r_err)+ abs(g_err) + abs(b_err); + + if(diff < *bestDiff) { + *bestInd = ind; + *bestDiff = diff; + } + return; + } + + // take the appropriate color (r, g, or b) for this node of the k-d tree + int comps[3] = {r, g, b}; + + int splitComp = comps[pPal->treeSplitElt[treeRoot]]; + + int splitPos = pPal->treeSplit[treeRoot]; + if (splitPos > splitComp) { + // check the left subtree + _getClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); + if (*bestDiff > splitPos - splitComp) { + // cannot prove there's not a better value in the right subtree, check that too + _getClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); + } + } else { + _getClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); + if (*bestDiff > splitComp - splitPos) { + _getClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); + } + } +} + + +static void _swapPixels(uint8_t* image, int pixA, int pixB) +{ + uint8_t rA = image[pixA*4]; + uint8_t gA = image[pixA*4+1]; + uint8_t bA = image[pixA*4+2]; + uint8_t aA = image[pixA*4+3]; + + uint8_t rB = image[pixB*4]; + uint8_t gB = image[pixB*4+1]; + uint8_t bB = image[pixB*4+2]; + uint8_t aB = image[pixA*4+3]; + + image[pixA*4] = rB; + image[pixA*4+1] = gB; + image[pixA*4+2] = bB; + image[pixA*4+3] = aB; + + image[pixB*4] = rA; + image[pixB*4+1] = gA; + image[pixB*4+2] = bA; + image[pixB*4+3] = aA; +} + + +// just the partition operation from quicksort +static int _partition(uint8_t* image, const int left, const int right, const int elt, int pivotIndex) +{ + const int pivotValue = image[(pivotIndex)*4+elt]; + _swapPixels(image, pivotIndex, right-1); + int storeIndex = left; + bool split = 0; + + for (int ii = left; ii < right - 1; ++ii) { + int arrayVal = image[ii*4+elt]; + if(arrayVal < pivotValue) { + _swapPixels(image, ii, storeIndex); + ++storeIndex; + } else if(arrayVal == pivotValue) { + if (split) { + _swapPixels(image, ii, storeIndex); + ++storeIndex; + } + split = !split; + } + } + _swapPixels(image, storeIndex, right-1); + return storeIndex; +} + + +// Perform an incomplete sort, finding all elements above and below the desired median +static void _partitionByMedian(uint8_t* image, int left, int right, int com, int neededCenter) +{ + if (left < right-1) { + int pivotIndex = left + (right-left)/2; + pivotIndex = _partition(image, left, right, com, pivotIndex); + + // Only "sort" the section of the array that contains the median + if(pivotIndex > neededCenter) _partitionByMedian(image, left, pivotIndex, com, neededCenter); + if(pivotIndex < neededCenter) _partitionByMedian(image, pivotIndex+1, right, com, neededCenter); + } +} + + +// Builds a palette by creating a balanced k-d tree of all pixels in the image +static void _splitPalette(uint8_t* image, int numPixels, int firstElt, int lastElt, int splitElt, int splitDist, int treeNode, GifPalette* pal) +{ + if(lastElt <= firstElt || numPixels == 0) return; + + // base case, bottom of the tree + if (lastElt == firstElt + 1) { + // otherwise, take the average of all colors in this subcube + uint64_t r=0, g=0, b=0; + for(int ii=0; iir[firstElt] = (uint8_t)r; + pal->g[firstElt] = (uint8_t)g; + pal->b[firstElt] = (uint8_t)b; + return; + } + + // Find the axis with the largest range + int minR = 255, maxR = 0; + int minG = 255, maxG = 0; + int minB = 255, maxB = 0; + + for (int ii=0; ii maxR) maxR = r; + if(r < minR) minR = r; + + if(g > maxG) maxG = g; + if(g < minG) minG = g; + + if(b > maxB) maxB = b; + if(b < minB) minB = b; + } + + int rRange = maxR - minR; + int gRange = maxG - minG; + int bRange = maxB - minB; + + // and split along that axis. (incidentally, this means this isn't a "proper" k-d tree but I don't know what else to call it) + int splitCom = 1; + if (bRange > gRange) splitCom = 2; + if (rRange > bRange && rRange > gRange) splitCom = 0; + + int subPixelsA = numPixels * (splitElt - firstElt) / (lastElt - firstElt); + int subPixelsB = numPixels-subPixelsA; + + _partitionByMedian(image, 0, numPixels, splitCom, subPixelsA); + + pal->treeSplitElt[treeNode] = (uint8_t)splitCom; + pal->treeSplit[treeNode] = image[subPixelsA*4+splitCom]; + + _splitPalette(image, subPixelsA, firstElt, splitElt, splitElt-splitDist, splitDist/2, treeNode*2, pal); + _splitPalette(image+subPixelsA*4, subPixelsB, splitElt, lastElt, splitElt+splitDist, splitDist/2, treeNode*2+1, pal); +} + + +// Finds all pixels that have changed from the previous image and +// moves them to the from of the buffer. +// This allows us to build a palette optimized for the colors of the +// changed pixels only. +static int _pickChangedPixels(const uint8_t* lastFrame, uint8_t* frame, int numPixels, bool transparent) +{ + int numChanged = 0; + uint8_t* writeIter = frame; + + for (int ii=0; ii < numPixels; ++ii) { + if (frame[3] >= TRANSPARENT_THRESHOLD) { + if (transparent || (lastFrame[0] != frame[0] || lastFrame[1] != frame[1] || lastFrame[2] != frame[2])) { + writeIter[0] = frame[0]; + writeIter[1] = frame[1]; + writeIter[2] = frame[2]; + ++numChanged; + writeIter += 4; + } + } + lastFrame += 4; + frame += 4; + } + + return numChanged; +} + + +// Creates a palette by placing all the image pixels in a k-d tree and then averaging the blocks at the bottom. +// This is known as the "modified median split" technique +static void _makePalette(GifWriter* writer, const uint8_t* lastFrame, const uint8_t* nextFrame, uint32_t width, uint32_t height, int bitDepth, bool transparent) +{ + auto& pal = writer->pal; + + size_t imageSize = (size_t)(width * height * 4 * sizeof(uint8_t)); + memcpy(writer->tmpImage, nextFrame, imageSize); + + int numPixels = (int)(width * height); + if (lastFrame) numPixels = _pickChangedPixels(lastFrame, writer->tmpImage, numPixels, transparent); + + const int lastElt = 1 << bitDepth; + const int splitElt = lastElt/2; + const int splitDist = splitElt/2; + + _splitPalette(writer->tmpImage, numPixels, 1, lastElt, splitElt, splitDist, 1, &pal); + + // add the bottom node for the transparency index + pal.treeSplit[1 << (bitDepth-1)] = 0; + pal.treeSplitElt[1 << (bitDepth-1)] = 0; + pal.r[0] = pal.g[0] = pal.b[0] = 0; +} + + +void _palettizePixel(const uint8_t* nextFrame, uint8_t* outFrame, GifPalette* pPal) +{ + int32_t bestDiff = 1000000; + int32_t bestInd = 1; + _getClosestPaletteColor(pPal, nextFrame[0], nextFrame[1], nextFrame[2], &bestInd, &bestDiff, 1); + + // Write the resulting color to the output buffer + outFrame[0] = pPal->r[bestInd]; + outFrame[1] = pPal->g[bestInd]; + outFrame[2] = pPal->b[bestInd]; + outFrame[3] = (uint8_t)bestInd; +} + + +// Picks palette colors for the image using simple threshholding, no dithering +static void _thresholdImage(GifWriter* writer, const uint8_t* lastFrame, const uint8_t* nextFrame, uint32_t width, uint32_t height, bool transparent) +{ + auto outFrame = writer->oldImage; + uint32_t numPixels = width*height; + + if (transparent) { + for (uint32_t ii = 0; ii < numPixels; ++ii) { + if (nextFrame[3] < TRANSPARENT_THRESHOLD) { + outFrame[0] = 0; + outFrame[1] = 0; + outFrame[2] = 0; + outFrame[3] = TRANSPARENT_IDX; + } else { + _palettizePixel(nextFrame, outFrame, &writer->pal); + } + if (lastFrame) lastFrame += 4; + outFrame += 4; + nextFrame += 4; + } + } else { + for (uint32_t ii = 0; ii < numPixels; ++ii) { + // if a previous color is available, and it matches the current color, + // set the pixel to transparent + if(lastFrame && lastFrame[0] == nextFrame[0] && lastFrame[1] == nextFrame[1] && lastFrame[2] == nextFrame[2]) { + outFrame[0] = lastFrame[0]; + outFrame[1] = lastFrame[1]; + outFrame[2] = lastFrame[2]; + outFrame[3] = TRANSPARENT_IDX; + } else { + _palettizePixel(nextFrame, outFrame, &writer->pal); + } + if (lastFrame) lastFrame += 4; + outFrame += 4; + nextFrame += 4; + } + } +} + + +// insert a single bit +static void _writeBit(GifBitStatus* stat, uint32_t bit) +{ + bit = bit & 1; + bit = bit << stat->bitIndex; + stat->byte |= bit; + + ++stat->bitIndex; + if (stat->bitIndex > 7) { + // move the newly-finished byte to the chunk buffer + stat->chunk[stat->chunkIndex++] = stat->byte; + // and start a new byte + stat->bitIndex = 0; + stat->byte = 0; + } +} + + +// write all bytes so far to the file +static void _writeChunk(FILE* f, GifBitStatus* stat) +{ + fputc((int)stat->chunkIndex, f); + fwrite(stat->chunk, 1, stat->chunkIndex, f); + + stat->bitIndex = 0; + stat->byte = 0; + stat->chunkIndex = 0; +} + + +static void _writeCode(FILE* f, GifBitStatus* stat, uint32_t code, uint32_t length) +{ + for (uint32_t ii = 0; ii < length; ++ii) { + _writeBit(stat, code); + code = code >> 1; + if (stat->chunkIndex == 255) _writeChunk(f, stat); + } +} + + +// write a 256-color (8-bit) image palette to the file +static void _writePalette(const GifPalette* pPal, FILE* f) +{ + fputc(0, f); // first color: transparency + fputc(0, f); + fputc(0, f); + + for (int ii = 1; ii < (1 << BIT_DEPTH); ++ii) { + uint32_t r = pPal->r[ii]; + uint32_t g = pPal->g[ii]; + uint32_t b = pPal->b[ii]; + + fputc((int)r, f); + fputc((int)g, f); + fputc((int)b, f); + } +} + + +// write the image header, LZW-compress and write out the image +static void _writeLzwImage(GifWriter* writer, uint32_t width, uint32_t height, uint32_t delay, bool transparent) +{ + auto f = writer->f; + auto image = writer->oldImage; + + // graphics control extension + fputc(0x21, f); + fputc(0xf9, f); + fputc(0x04, f); + fputc((transparent ? 0x09 : 0x05), f); //clear prev frame or not. + fputc(delay & 0xff, f); + fputc((delay >> 8) & 0xff, f); + fputc(TRANSPARENT_IDX, f); // transparent color index + fputc(0, f); + + fputc(0x2c, f); // image descriptor block + + // corner of image (left, top) in canvas space + fputc(0, f); + fputc(0, f); + fputc(0, f); + fputc(0, f); + + fputc(width & 0xff, f); // width and height of image + fputc((width >> 8) & 0xff, f); + fputc(height & 0xff, f); + fputc((height >> 8) & 0xff, f); + + //fputc(0, f); // no local color table, no transparency + //fputc(0x80, f); // no local color table, but transparency + + fputc(0x80 + BIT_DEPTH - 1, f); // local color table present, 2 ^ bitDepth entries + _writePalette(&writer->pal, f); + + const int minCodeSize = BIT_DEPTH; + const uint32_t clearCode = 1 << BIT_DEPTH; + + fputc(minCodeSize, f); // min code size 8 bits + + GifLzwNode* codetree = tvg::malloc(sizeof(GifLzwNode)*4096); + + memset(codetree, 0, sizeof(GifLzwNode)*4096); + int32_t curCode = -1; + uint32_t codeSize = (uint32_t)minCodeSize + 1; + uint32_t maxCode = clearCode+1; + + GifBitStatus stat; + stat.byte = 0; + stat.bitIndex = 0; + stat.chunkIndex = 0; + + _writeCode(f, &stat, clearCode, codeSize); // start with a fresh LZW dictionary + + for (uint32_t yy = 0; yy < height; ++yy) { + for (uint32_t xx=0; xx= (1ul << codeSize)) { + // dictionary entry count has broken a size barrier, + // we need more bits for codes + codeSize++; + } + if (maxCode == 4095) { + // the dictionary is full, clear it out and begin anew + _writeCode(f, &stat, clearCode, codeSize); // clear tree + + memset(codetree, 0, sizeof(GifLzwNode)*4096); + codeSize = (uint32_t)(minCodeSize + 1); + maxCode = clearCode+1; + } + + curCode = nextValue; + } + } + } + + // compression footer + _writeCode(f, &stat, (uint32_t)curCode, codeSize); + _writeCode(f, &stat, clearCode, codeSize); + _writeCode(f, &stat, clearCode + 1, (uint32_t)minCodeSize + 1); + + // write out the last partial chunk + while (stat.bitIndex) _writeBit(&stat, 0); + if (stat.chunkIndex) _writeChunk(f, &stat); + + fputc(0, f); // image block terminator + + tvg::free(codetree); +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + +bool gifBegin(GifWriter* writer, const char* filename, uint32_t width, uint32_t height, uint32_t delay) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) + writer->f = 0; + fopen_s(&writer->f, filename, "wb"); +#else + writer->f = fopen(filename, "wb"); +#endif + if (!writer->f) return false; + + writer->firstFrame = true; + + // allocate + writer->oldImage = tvg::malloc(width*height*4); + writer->tmpImage = tvg::malloc(width*height*4); + + fputs("GIF89a", writer->f); + + // screen descriptor + fputc(width & 0xff, writer->f); + fputc((width >> 8) & 0xff, writer->f); + fputc(height & 0xff, writer->f); + fputc((height >> 8) & 0xff, writer->f); + + fputc(0xf0, writer->f); // there is an unsorted global color table of 2 entries + fputc(0, writer->f); // background color + fputc(0, writer->f); // pixels are square (we need to specify this because it's 1989) + + // now the "global" palette (really just a dummy palette) + // color 0: black + fputc(0, writer->f); + fputc(0, writer->f); + fputc(0, writer->f); + // color 1: also black + fputc(0, writer->f); + fputc(0, writer->f); + fputc(0, writer->f); + + if(delay != 0) { + // animation header + fputc(0x21, writer->f); // extension + fputc(0xff, writer->f); // application specific + fputc(11, writer->f); // length 11 + fputs("NETSCAPE2.0", writer->f); // yes, really + fputc(3, writer->f); // 3 bytes of NETSCAPE2.0 data + + fputc(1, writer->f); // JUST BECAUSE + fputc(0, writer->f); // loop infinitely (byte 0) + fputc(0, writer->f); // loop infinitely (byte 1) + + fputc(0, writer->f); // block terminator + } + + return true; +} + + +bool gifWriteFrame(GifWriter* writer, const uint8_t* image, uint32_t width, uint32_t height, uint32_t delay, bool transparent) +{ + if (!writer->f) return false; + + const uint8_t* oldImage = writer->firstFrame? NULL : writer->oldImage; + writer->firstFrame = false; + + _makePalette(writer, oldImage, image, width, height, 8, transparent); + _thresholdImage(writer, oldImage, image, width, height, transparent); + _writeLzwImage(writer, width, height, delay, transparent); + + return true; +} + + +bool gifEnd(GifWriter* writer) +{ + if (!writer->f) return false; + + fputc(0x3b, writer->f); // end of file + fclose(writer->f); + tvg::free(writer->oldImage); + tvg::free(writer->tmpImage); + + writer->f = NULL; + writer->oldImage = NULL; + + return true; +} diff --git a/components/thorvg-main/src/savers/gif/tvgGifEncoder.h b/components/thorvg-main/src/savers/gif/tvgGifEncoder.h new file mode 100644 index 0000000..311a827 --- /dev/null +++ b/components/thorvg-main/src/savers/gif/tvgGifEncoder.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#ifndef TVG_GIF_ENCODER_H +#define TVG_GIF_ENCODER_H + +#include "tvgCommon.h" + +typedef struct +{ + uint8_t r[256]; + uint8_t g[256]; + uint8_t b[256]; + + // k-d tree over RGB space, organized in heap fashion + // i.e. left child of node i is node i*2, right child is node i*2+1 + // nodes 256-511 are implicitly the leaves, containing a color + uint8_t treeSplitElt[256]; + uint8_t treeSplit[256]; +} GifPalette; + + +typedef struct +{ + FILE* f; + uint8_t* oldImage; + uint8_t* tmpImage; + GifPalette pal; + bool firstFrame; +} GifWriter; + + +// Creates a gif file. +// The input GIFWriter is assumed to be uninitialized. +// The delay value is the time between frames in hundredths of a second - note that not all viewers pay much attention to this value. +bool gifBegin(GifWriter* writer, const char* filename, uint32_t width, uint32_t height, uint32_t delay); + +// Writes out a new frame to a GIF in progress. +// The GIFWriter should have been created by GIFBegin. +// AFAIK, it is legal to use different bit depths for different frames of an image - +// this may be handy to save bits in animations that don't change much. +bool gifWriteFrame(GifWriter* writer, const uint8_t* image, uint32_t width, uint32_t height, uint32_t delay, bool transparent); + + +// Writes the EOF code, closes the file handle, and frees temp memory used by a GIF. +// Many if not most viewers will still display a GIF properly if the EOF code is missing, +// but it's still a good idea to write it out. +bool gifEnd(GifWriter* writer); + +#endif //TVG_GIF_ENCODER_H diff --git a/components/thorvg-main/src/savers/gif/tvgGifSaver.cpp b/components/thorvg-main/src/savers/gif/tvgGifSaver.cpp new file mode 100644 index 0000000..c3370f8 --- /dev/null +++ b/components/thorvg-main/src/savers/gif/tvgGifSaver.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include "tvgStr.h" +#include "tvgGifEncoder.h" +#include "tvgGifSaver.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +void GifSaver::run(unsigned tid) +{ + auto canvas = unique_ptr(SwCanvas::gen()); + if (!canvas) return; + + auto w = static_cast(vsize[0]); + auto h = static_cast(vsize[1]); + + buffer = tvg::realloc(buffer, sizeof(uint32_t) * w * h); + canvas->target(buffer, w, w, h, ColorSpace::ABGR8888S); + canvas->add(bg); + canvas->add(animation->picture()); + + //use the default fps + if (fps > 60.0f) fps = 60.0f; // just in case + else if (tvg::zero(fps) || fps < 0.0f) { + fps = (animation->totalFrame() / animation->duration()); + } + + auto delay = (1.0f / fps); + auto transparent = bg ? false : true; + + GifWriter writer; + if (!gifBegin(&writer, path, w, h, uint32_t(delay * 100.f))) { + TVGERR("GIF_SAVER", "Failed gif encoding"); + return; + } + + auto duration = animation->duration(); + + for (auto p = 0.0f; p < duration; p += delay) { + auto frameNo = animation->totalFrame() * (p / duration); + animation->frame(frameNo); + canvas->update(); + if (canvas->draw(true) == tvg::Result::Success) { + canvas->sync(); + } + if (!gifWriteFrame(&writer, reinterpret_cast(buffer), w, h, uint32_t(delay * 100.0f), transparent)) { + TVGERR("GIF_SAVER", "Failed gif encoding"); + break; + } + } + + if (!gifEnd(&writer)) TVGERR("GIF_SAVER", "Failed gif encoding"); + + if (bg) { + bg->unref(); + bg = nullptr; + } +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +GifSaver::~GifSaver() +{ + close(); +} + + +bool GifSaver::close() +{ + this->done(); + + if (bg) bg->unref(); + bg = nullptr; + + //animation holds the picture, it must be 1 at the bottom. + if (animation && animation->picture()->refCnt() <= 1) delete(animation); + animation = nullptr; + + tvg::free(path); + path = nullptr; + + tvg::free(buffer); + buffer = nullptr; + + return true; +} + + +bool GifSaver::save(TVG_UNUSED Paint* paint, TVG_UNUSED Paint* bg, TVG_UNUSED const char* filename, TVG_UNUSED uint32_t quality) +{ + TVGLOG("GIF_SAVER", "Paint is not supported."); + return false; +} + + +bool GifSaver::save(Animation* animation, Paint* bg, const char* filename, TVG_UNUSED uint32_t quality, uint32_t fps) +{ + close(); + + auto picture = animation->picture(); + auto x = 0.0f, y = 0.0f; + picture->bounds(&x, &y, &vsize[0], &vsize[1]); + + //cut off the negative space + if (x < 0) vsize[0] += x; + if (y < 0) vsize[1] += y; + + if (vsize[0] < FLOAT_EPSILON || vsize[1] < FLOAT_EPSILON) { + TVGLOG("GIF_SAVER", "Saving animation(%p) has zero view size.", animation); + return false; + } + + if (!filename) return false; + this->path = duplicate(filename); + + this->animation = animation; + + if (bg) { + bg->ref(); + this->bg = bg; + } + this->fps = static_cast(fps); + + TaskScheduler::request(this); + + return true; +} diff --git a/components/thorvg-main/src/savers/gif/tvgGifSaver.h b/components/thorvg-main/src/savers/gif/tvgGifSaver.h new file mode 100644 index 0000000..a6af729 --- /dev/null +++ b/components/thorvg-main/src/savers/gif/tvgGifSaver.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_GIFSAVER_H_ +#define _TVG_GIFSAVER_H_ + +#include "tvgSaveModule.h" +#include "tvgTaskScheduler.h" + +namespace tvg +{ + +class GifSaver : public SaveModule, public Task +{ +private: + uint32_t* buffer = nullptr; + Animation* animation = nullptr; + Paint* bg = nullptr; + char *path = nullptr; + float vsize[2] = {0.0f, 0.0f}; + float fps = 0.0f; + + void run(unsigned tid) override; + +public: + ~GifSaver(); + + bool save(Paint* paint, Paint* bg, const char* filename, uint32_t quality) override; + bool save(Animation* animation, Paint* bg, const char* filename, uint32_t quality, uint32_t fps) override; + bool close() override; +}; + +} + +#endif //_TVG_GIFSAVER_H_ diff --git a/components/thorvg-main/src/savers/meson.build b/components/thorvg-main/src/savers/meson.build new file mode 100644 index 0000000..32c348f --- /dev/null +++ b/components/thorvg-main/src/savers/meson.build @@ -0,0 +1,10 @@ +subsaver_dep = [] + +if gif_saver + subdir('gif') +endif + +saver_dep = declare_dependency( + dependencies: subsaver_dep, + include_directories : include_directories('.'), +) diff --git a/components/thorvg-main/test/catch.hpp b/components/thorvg-main/test/catch.hpp new file mode 100644 index 0000000..9b309bd --- /dev/null +++ b/components/thorvg-main/test/catch.hpp @@ -0,0 +1,17976 @@ +/* + * Catch v2.13.10 + * Generated: 2022-10-16 11:01:23.452308 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 10 + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details + +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +// See e.g.: +// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html +#ifdef __APPLE__ +# include +# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \ + (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1) +# define CATCH_PLATFORM_MAC +# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1) +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER +# endif + +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +// Only GCC compiler should be used in this block, so other compilers trying to +// mask themselves as GCC should be ignored. +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif + +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ +# endif + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif + +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) + +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING + +# endif +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#if defined(_MSC_VER) + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +# if !defined(__clang__) // Handle Clang masquerading for msvc + +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL + +// Only do this if we're not using clang on Windows, which uses `diagnostic push` & `diagnostic pop` +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) +# endif // __clang__ + +#endif // _MSC_VER + +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED +#endif + +//////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif + +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0) + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif + +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS +#endif + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC +#endif + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS +#endif + +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) +#endif + +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) +#else +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) +#endif + +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; + + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include +#include + +namespace Catch { + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { + public: + using size_type = std::size_t; + using const_iterator = const char*; + + private: + static constexpr char const* const s_empty = ""; + + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; + + StringRef( char const* rawChars ) noexcept; + + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + explicit operator std::string() const { + return std::string(m_start, m_size); + } + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); + } + + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } + + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } + + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; + + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; + + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; + + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } + + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } + }; + + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch + +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); +} + +// end catch_stringref.h +// start catch_preprocessor.hpp + + +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) + +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif + +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif + +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) + +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template(), std::true_type()); + + template + static auto test(...)->std::false_type; + + public: + static const bool value = decltype(test(0))::value; + }; + + template + std::string convertUnknownEnumToString( E e ); + + template + typename std::enable_if< + !std::is_enum::value && !std::is_base_of::value, + std::string>::type convertUnstreamable( T const& ) { + return Detail::unprintableString; + } + template + typename std::enable_if< + !std::is_enum::value && std::is_base_of::value, + std::string>::type convertUnstreamable(T const& ex) { + return ex.what(); + } + + template + typename std::enable_if< + std::is_enum::value + , std::string>::type convertUnstreamable( T const& value ) { + return convertUnknownEnumToString( value ); + } + +#if defined(_MANAGED) + //! Convert a CLR string to a utf8 std::string + template + std::string clrReferenceToString( T^ ref ) { + if (ref == nullptr) + return std::string("null"); + auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString()); + cli::pin_ptr p = &bytes[0]; + return std::string(reinterpret_cast(p), bytes->Length); + } +#endif + + } // namespace Detail + + // If we decide for C++14, change these to enable_if_ts + template + struct StringMaker { + template + static + typename std::enable_if<::Catch::Detail::IsStreamInsertable::value, std::string>::type + convert(const Fake& value) { + ReusableStringStream rss; + // NB: call using the function-like syntax to avoid ambiguity with + // user-defined templated operator<< under clang. + rss.operator<<(value); + return rss.str(); + } + + template + static + typename std::enable_if::value, std::string>::type + convert( const Fake& value ) { +#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) + return Detail::convertUnstreamable(value); +#else + return CATCH_CONFIG_FALLBACK_STRINGIFIER(value); +#endif + } + }; + + namespace Detail { + + // This function dispatches all stringification requests inside of Catch. + // Should be preferably called fully qualified, like ::Catch::Detail::stringify + template + std::string stringify(const T& e) { + return ::Catch::StringMaker::type>::type>::convert(e); + } + + template + std::string convertUnknownEnumToString( E e ) { + return ::Catch::Detail::stringify(static_cast::type>(e)); + } + +#if defined(_MANAGED) + template + std::string stringify( T^ e ) { + return ::Catch::StringMaker::convert(e); + } +#endif + + } // namespace Detail + + // Some predefined specializations + + template<> + struct StringMaker { + static std::string convert(const std::string& str); + }; + +#ifdef CATCH_CONFIG_CPP17_STRING_VIEW + template<> + struct StringMaker { + static std::string convert(std::string_view str); + }; +#endif + + template<> + struct StringMaker { + static std::string convert(char const * str); + }; + template<> + struct StringMaker { + static std::string convert(char * str); + }; + +#ifdef CATCH_CONFIG_WCHAR + template<> + struct StringMaker { + static std::string convert(const std::wstring& wstr); + }; + +# ifdef CATCH_CONFIG_CPP17_STRING_VIEW + template<> + struct StringMaker { + static std::string convert(std::wstring_view str); + }; +# endif + + template<> + struct StringMaker { + static std::string convert(wchar_t const * str); + }; + template<> + struct StringMaker { + static std::string convert(wchar_t * str); + }; +#endif + + // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer, + // while keeping string semantics? + template + struct StringMaker { + static std::string convert(char const* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + template + struct StringMaker { + static std::string convert(signed char const* str) { + return ::Catch::Detail::stringify(std::string{ reinterpret_cast(str) }); + } + }; + template + struct StringMaker { + static std::string convert(unsigned char const* str) { + return ::Catch::Detail::stringify(std::string{ reinterpret_cast(str) }); + } + }; + +#if defined(CATCH_CONFIG_CPP17_BYTE) + template<> + struct StringMaker { + static std::string convert(std::byte value); + }; +#endif // defined(CATCH_CONFIG_CPP17_BYTE) + template<> + struct StringMaker { + static std::string convert(int value); + }; + template<> + struct StringMaker { + static std::string convert(long value); + }; + template<> + struct StringMaker { + static std::string convert(long long value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned int value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned long value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned long long value); + }; + + template<> + struct StringMaker { + static std::string convert(bool b); + }; + + template<> + struct StringMaker { + static std::string convert(char c); + }; + template<> + struct StringMaker { + static std::string convert(signed char c); + }; + template<> + struct StringMaker { + static std::string convert(unsigned char c); + }; + + template<> + struct StringMaker { + static std::string convert(std::nullptr_t); + }; + + template<> + struct StringMaker { + static std::string convert(float value); + static int precision; + }; + + template<> + struct StringMaker { + static std::string convert(double value); + static int precision; + }; + + template + struct StringMaker { + template + static std::string convert(U* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } + } + }; + + template + struct StringMaker { + static std::string convert(R C::* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } + } + }; + +#if defined(_MANAGED) + template + struct StringMaker { + static std::string convert( T^ ref ) { + return ::Catch::Detail::clrReferenceToString(ref); + } + }; +#endif + + namespace Detail { + template + std::string rangeToString(InputIterator first, Sentinel last) { + ReusableStringStream rss; + rss << "{ "; + if (first != last) { + rss << ::Catch::Detail::stringify(*first); + for (++first; first != last; ++first) + rss << ", " << ::Catch::Detail::stringify(*first); + } + rss << " }"; + return rss.str(); + } + } + +#ifdef __OBJC__ + template<> + struct StringMaker { + static std::string convert(NSString * nsstring) { + if (!nsstring) + return "nil"; + return std::string("@") + [nsstring UTF8String]; + } + }; + template<> + struct StringMaker { + static std::string convert(NSObject* nsObject) { + return ::Catch::Detail::stringify([nsObject description]); + } + + }; + namespace Detail { + inline std::string stringify( NSString* nsstring ) { + return StringMaker::convert( nsstring ); + } + + } // namespace Detail +#endif // __OBJC__ + +} // namespace Catch + +////////////////////////////////////////////////////// +// Separate std-lib types stringification, so it can be selectively enabled +// This means that we do not bring in + +#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) +# define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER +# define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +# define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER +#endif + +// Separate std::pair specialization +#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER) +#include +namespace Catch { + template + struct StringMaker > { + static std::string convert(const std::pair& pair) { + ReusableStringStream rss; + rss << "{ " + << ::Catch::Detail::stringify(pair.first) + << ", " + << ::Catch::Detail::stringify(pair.second) + << " }"; + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER + +#if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL) +#include +namespace Catch { + template + struct StringMaker > { + static std::string convert(const std::optional& optional) { + ReusableStringStream rss; + if (optional.has_value()) { + rss << ::Catch::Detail::stringify(*optional); + } else { + rss << "{ }"; + } + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER + +// Separate std::tuple specialization +#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) +#include +namespace Catch { + namespace Detail { + template< + typename Tuple, + std::size_t N = 0, + bool = (N < std::tuple_size::value) + > + struct TupleElementPrinter { + static void print(const Tuple& tuple, std::ostream& os) { + os << (N ? ", " : " ") + << ::Catch::Detail::stringify(std::get(tuple)); + TupleElementPrinter::print(tuple, os); + } + }; + + template< + typename Tuple, + std::size_t N + > + struct TupleElementPrinter { + static void print(const Tuple&, std::ostream&) {} + }; + + } + + template + struct StringMaker> { + static std::string convert(const std::tuple& tuple) { + ReusableStringStream rss; + rss << '{'; + Detail::TupleElementPrinter>::print(tuple, rss.get()); + rss << " }"; + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER + +#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT) +#include +namespace Catch { + template<> + struct StringMaker { + static std::string convert(const std::monostate&) { + return "{ }"; + } + }; + + template + struct StringMaker> { + static std::string convert(const std::variant& variant) { + if (variant.valueless_by_exception()) { + return "{valueless variant}"; + } else { + return std::visit( + [](const auto& value) { + return ::Catch::Detail::stringify(value); + }, + variant + ); + } + } + }; +} +#endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER + +namespace Catch { + // Import begin/ end from std here + using std::begin; + using std::end; + + namespace detail { + template + struct void_type { + using type = void; + }; + + template + struct is_range_impl : std::false_type { + }; + + template + struct is_range_impl()))>::type> : std::true_type { + }; + } // namespace detail + + template + struct is_range : detail::is_range_impl { + }; + +#if defined(_MANAGED) // Managed types are never ranges + template + struct is_range { + static const bool value = false; + }; +#endif + + template + std::string rangeToString( Range const& range ) { + return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + } + + // Handle vector specially + template + std::string rangeToString( std::vector const& v ) { + ReusableStringStream rss; + rss << "{ "; + bool first = true; + for( bool b : v ) { + if( first ) + first = false; + else + rss << ", "; + rss << ::Catch::Detail::stringify( b ); + } + rss << " }"; + return rss.str(); + } + + template + struct StringMaker::value && !::Catch::Detail::IsStreamInsertable::value>::type> { + static std::string convert( R const& range ) { + return rangeToString( range ); + } + }; + + template + struct StringMaker { + static std::string convert(T const(&arr)[SZ]) { + return rangeToString(arr); + } + }; + +} // namespace Catch + +// Separate std::chrono::duration specialization +#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +#include +#include +#include + +namespace Catch { + +template +struct ratio_string { + static std::string symbol(); +}; + +template +std::string ratio_string::symbol() { + Catch::ReusableStringStream rss; + rss << '[' << Ratio::num << '/' + << Ratio::den << ']'; + return rss.str(); +} +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; + + //////////// + // std::chrono::duration specializations + template + struct StringMaker> { + static std::string convert(std::chrono::duration const& duration) { + ReusableStringStream rss; + rss << duration.count() << ' ' << ratio_string::symbol() << 's'; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " s"; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " m"; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " h"; + return rss.str(); + } + }; + + //////////// + // std::chrono::time_point specialization + // Generic time_point cannot be specialized, only std::chrono::time_point + template + struct StringMaker> { + static std::string convert(std::chrono::time_point const& time_point) { + return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; + } + }; + // std::chrono::time_point specialization + template + struct StringMaker> { + static std::string convert(std::chrono::time_point const& time_point) { + auto converted = std::chrono::system_clock::to_time_t(time_point); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &converted); +#else + std::tm* timeInfo = std::gmtime(&converted); +#endif + + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER + +#define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \ +namespace Catch { \ + template<> struct StringMaker { \ + static std::string convert( enumName value ) { \ + static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \ + return static_cast(enumInfo.lookup( static_cast( value ) )); \ + } \ + }; \ +} + +#define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ ) + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// end catch_tostring.h +#include + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4389) // '==' : signed/unsigned mismatch +#pragma warning(disable:4018) // more "signed/unsigned mismatch" +#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) +#pragma warning(disable:4180) // qualifier applied to function type has no meaning +#pragma warning(disable:4800) // Forcing result to true or false +#endif + +namespace Catch { + + struct ITransientExpression { + auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } + auto getResult() const -> bool { return m_result; } + virtual void streamReconstructedExpression( std::ostream &os ) const = 0; + + ITransientExpression( bool isBinaryExpression, bool result ) + : m_isBinaryExpression( isBinaryExpression ), + m_result( result ) + {} + + // We don't actually need a virtual destructor, but many static analysers + // complain if it's not here :-( + virtual ~ITransientExpression(); + + bool m_isBinaryExpression; + bool m_result; + + }; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); + + template + class BinaryExpr : public ITransientExpression { + LhsT m_lhs; + StringRef m_op; + RhsT m_rhs; + + void streamReconstructedExpression( std::ostream &os ) const override { + formatReconstructedExpression + ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) ); + } + + public: + BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) + : ITransientExpression{ true, comparisonResult }, + m_lhs( lhs ), + m_op( op ), + m_rhs( rhs ) + {} + + template + auto operator && ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator || ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator == ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator != ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator > ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator < ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator >= ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator <= ( T ) const -> BinaryExpr const { + static_assert(always_false::value, + "chained comparisons are not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + }; + + template + class UnaryExpr : public ITransientExpression { + LhsT m_lhs; + + void streamReconstructedExpression( std::ostream &os ) const override { + os << Catch::Detail::stringify( m_lhs ); + } + + public: + explicit UnaryExpr( LhsT lhs ) + : ITransientExpression{ false, static_cast(lhs) }, + m_lhs( lhs ) + {} + }; + + // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) + template + auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast(lhs == rhs); } + template + auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } + template + auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } + template + auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } + template + auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } + + template + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast(lhs != rhs); } + template + auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } + template + auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } + template + auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } + template + auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } + + template + class ExprLhs { + LhsT m_lhs; + public: + explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} + + template + auto operator == ( RhsT const& rhs ) -> BinaryExpr const { + return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs }; + } + auto operator == ( bool rhs ) -> BinaryExpr const { + return { m_lhs == rhs, m_lhs, "==", rhs }; + } + + template + auto operator != ( RhsT const& rhs ) -> BinaryExpr const { + return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs }; + } + auto operator != ( bool rhs ) -> BinaryExpr const { + return { m_lhs != rhs, m_lhs, "!=", rhs }; + } + + template + auto operator > ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs > rhs), m_lhs, ">", rhs }; + } + template + auto operator < ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs < rhs), m_lhs, "<", rhs }; + } + template + auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs >= rhs), m_lhs, ">=", rhs }; + } + template + auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs <= rhs), m_lhs, "<=", rhs }; + } + template + auto operator | (RhsT const& rhs) -> BinaryExpr const { + return { static_cast(m_lhs | rhs), m_lhs, "|", rhs }; + } + template + auto operator & (RhsT const& rhs) -> BinaryExpr const { + return { static_cast(m_lhs & rhs), m_lhs, "&", rhs }; + } + template + auto operator ^ (RhsT const& rhs) -> BinaryExpr const { + return { static_cast(m_lhs ^ rhs), m_lhs, "^", rhs }; + } + + template + auto operator && ( RhsT const& ) -> BinaryExpr const { + static_assert(always_false::value, + "operator&& is not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template + auto operator || ( RhsT const& ) -> BinaryExpr const { + static_assert(always_false::value, + "operator|| is not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + auto makeUnaryExpr() const -> UnaryExpr { + return UnaryExpr{ m_lhs }; + } + }; + + void handleExpression( ITransientExpression const& expr ); + + template + void handleExpression( ExprLhs const& expr ) { + handleExpression( expr.makeUnaryExpr() ); + } + + struct Decomposer { + template + auto operator <= ( T const& lhs ) -> ExprLhs { + return ExprLhs{ lhs }; + } + + auto operator <=( bool value ) -> ExprLhs { + return ExprLhs{ value }; + } + }; + +} // end namespace Catch + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// end catch_decomposer.h +// start catch_interfaces_capture.h + +#include +#include + +namespace Catch { + + class AssertionResult; + struct AssertionInfo; + struct SectionInfo; + struct SectionEndInfo; + struct MessageInfo; + struct MessageBuilder; + struct Counts; + struct AssertionReaction; + struct SourceLineInfo; + + struct ITransientExpression; + struct IGeneratorTracker; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + struct BenchmarkInfo; + template > + struct BenchmarkStats; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + struct IResultCapture { + + virtual ~IResultCapture(); + + virtual bool sectionStarted( SectionInfo const& sectionInfo, + Counts& assertions ) = 0; + virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; + virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; + + virtual auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + virtual void benchmarkPreparing( std::string const& name ) = 0; + virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; + virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0; + virtual void benchmarkFailed( std::string const& error ) = 0; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + virtual void pushScopedMessage( MessageInfo const& message ) = 0; + virtual void popScopedMessage( MessageInfo const& message ) = 0; + + virtual void emplaceUnscopedMessage( MessageBuilder const& builder ) = 0; + + virtual void handleFatalErrorCondition( StringRef message ) = 0; + + virtual void handleExpr + ( AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction ) = 0; + virtual void handleMessage + ( AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction ) = 0; + virtual void handleUnexpectedExceptionNotThrown + ( AssertionInfo const& info, + AssertionReaction& reaction ) = 0; + virtual void handleUnexpectedInflightException + ( AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction ) = 0; + virtual void handleIncomplete + ( AssertionInfo const& info ) = 0; + virtual void handleNonExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction ) = 0; + + virtual bool lastAssertionPassed() = 0; + virtual void assertionPassed() = 0; + + // Deprecated, do not use: + virtual std::string getCurrentTestName() const = 0; + virtual const AssertionResult* getLastResult() const = 0; + virtual void exceptionEarlyReported() = 0; + }; + + IResultCapture& getResultCapture(); +} + +// end catch_interfaces_capture.h +namespace Catch { + + struct TestFailureException{}; + struct AssertionResultData; + struct IResultCapture; + class RunContext; + + class LazyExpression { + friend class AssertionHandler; + friend struct AssertionStats; + friend class RunContext; + + ITransientExpression const* m_transientExpression = nullptr; + bool m_isNegated; + public: + LazyExpression( bool isNegated ); + LazyExpression( LazyExpression const& other ); + LazyExpression& operator = ( LazyExpression const& ) = delete; + + explicit operator bool() const; + + friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; + }; + + struct AssertionReaction { + bool shouldDebugBreak = false; + bool shouldThrow = false; + }; + + class AssertionHandler { + AssertionInfo m_assertionInfo; + AssertionReaction m_reaction; + bool m_completed = false; + IResultCapture& m_resultCapture; + + public: + AssertionHandler + ( StringRef const& macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ); + ~AssertionHandler() { + if ( !m_completed ) { + m_resultCapture.handleIncomplete( m_assertionInfo ); + } + } + + template + void handleExpr( ExprLhs const& expr ) { + handleExpr( expr.makeUnaryExpr() ); + } + void handleExpr( ITransientExpression const& expr ); + + void handleMessage(ResultWas::OfType resultType, StringRef const& message); + + void handleExceptionThrownAsExpected(); + void handleUnexpectedExceptionNotThrown(); + void handleExceptionNotThrownAsExpected(); + void handleThrowingCallSkipped(); + void handleUnexpectedInflightException(); + + void complete(); + void setCompleted(); + + // query + auto allowThrows() const -> bool; + }; + + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ); + +} // namespace Catch + +// end catch_assertionhandler.h +// start catch_message.h + +#include +#include + +namespace Catch { + + struct MessageInfo { + MessageInfo( StringRef const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + + StringRef macroName; + std::string message; + SourceLineInfo lineInfo; + ResultWas::OfType type; + unsigned int sequence; + + bool operator == ( MessageInfo const& other ) const; + bool operator < ( MessageInfo const& other ) const; + private: + static unsigned int globalCount; + }; + + struct MessageStream { + + template + MessageStream& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + ReusableStringStream m_stream; + }; + + struct MessageBuilder : MessageStream { + MessageBuilder( StringRef const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ); + + template + MessageBuilder& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + MessageInfo m_info; + }; + + class ScopedMessage { + public: + explicit ScopedMessage( MessageBuilder const& builder ); + ScopedMessage( ScopedMessage& duplicate ) = delete; + ScopedMessage( ScopedMessage&& old ); + ~ScopedMessage(); + + MessageInfo m_info; + bool m_moved; + }; + + class Capturer { + std::vector m_messages; + IResultCapture& m_resultCapture = getResultCapture(); + size_t m_captured = 0; + public: + Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); + ~Capturer(); + + void captureValue( size_t index, std::string const& value ); + + template + void captureValues( size_t index, T const& value ) { + captureValue( index, Catch::Detail::stringify( value ) ); + } + + template + void captureValues( size_t index, T const& value, Ts const&... values ) { + captureValue( index, Catch::Detail::stringify(value) ); + captureValues( index+1, values... ); + } + }; + +} // end namespace Catch + +// end catch_message.h +#if !defined(CATCH_CONFIG_DISABLE) + +#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) + #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ +#else + #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" +#endif + +#if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + +/////////////////////////////////////////////////////////////////////////////// +// Another way to speed-up compilation is to omit local try-catch for REQUIRE* +// macros. +#define INTERNAL_CATCH_TRY +#define INTERNAL_CATCH_CATCH( capturer ) + +#else // CATCH_CONFIG_FAST_COMPILE + +#define INTERNAL_CATCH_TRY try +#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); } + +#endif + +#define INTERNAL_CATCH_REACT( handler ) handler.complete(); + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ + do { \ + CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ + INTERNAL_CATCH_TRY { \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ + } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( (void)0, (false) && static_cast( !!(__VA_ARGS__) ) ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ + if( Catch::getResultCapture().lastAssertionPassed() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ + if( !Catch::getResultCapture().lastAssertionPassed() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleExceptionThrownAsExpected(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(expr); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( exceptionType const& ) { \ + catchAssertionHandler.handleExceptionThrownAsExpected(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \ + catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \ + auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \ + varName.captureValues( 0, __VA_ARGS__ ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_INFO( macroName, log ) \ + Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \ + Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) + +/////////////////////////////////////////////////////////////////////////////// +// Although this is matcher-based, it can be used with just a string +#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( ... ) { \ + Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +#endif // CATCH_CONFIG_DISABLE + +// end catch_capture.hpp +// start catch_section.h + +// start catch_section_info.h + +// start catch_totals.h + +#include + +namespace Catch { + + struct Counts { + Counts operator - ( Counts const& other ) const; + Counts& operator += ( Counts const& other ); + + std::size_t total() const; + bool allPassed() const; + bool allOk() const; + + std::size_t passed = 0; + std::size_t failed = 0; + std::size_t failedButOk = 0; + }; + + struct Totals { + + Totals operator - ( Totals const& other ) const; + Totals& operator += ( Totals const& other ); + + Totals delta( Totals const& prevTotals ) const; + + int error = 0; + Counts assertions; + Counts testCases; + }; +} + +// end catch_totals.h +#include + +namespace Catch { + + struct SectionInfo { + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name ); + + // Deprecated + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& ) : SectionInfo( _lineInfo, _name ) {} + + std::string name; + std::string description; // !Deprecated: this will always be empty + SourceLineInfo lineInfo; + }; + + struct SectionEndInfo { + SectionInfo sectionInfo; + Counts prevAssertions; + double durationInSeconds; + }; + +} // end namespace Catch + +// end catch_section_info.h +// start catch_timer.h + +#include + +namespace Catch { + + auto getCurrentNanosecondsSinceEpoch() -> uint64_t; + auto getEstimatedClockResolution() -> uint64_t; + + class Timer { + uint64_t m_nanoseconds = 0; + public: + void start(); + auto getElapsedNanoseconds() const -> uint64_t; + auto getElapsedMicroseconds() const -> uint64_t; + auto getElapsedMilliseconds() const -> unsigned int; + auto getElapsedSeconds() const -> double; + }; + +} // namespace Catch + +// end catch_timer.h +#include + +namespace Catch { + + class Section : NonCopyable { + public: + Section( SectionInfo const& info ); + ~Section(); + + // This indicates whether the section should be executed or not + explicit operator bool() const; + + private: + SectionInfo m_info; + + std::string m_name; + Counts m_assertions; + bool m_sectionIncluded; + Timer m_timer; + }; + +} // end namespace Catch + +#define INTERNAL_CATCH_SECTION( ... ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +#define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +// end catch_section.h +// start catch_interfaces_exception.h + +// start catch_interfaces_registry_hub.h + +#include +#include + +namespace Catch { + + class TestCase; + struct ITestCaseRegistry; + struct IExceptionTranslatorRegistry; + struct IExceptionTranslator; + struct IReporterRegistry; + struct IReporterFactory; + struct ITagAliasRegistry; + struct IMutableEnumValuesRegistry; + + class StartupExceptionRegistry; + + using IReporterFactoryPtr = std::shared_ptr; + + struct IRegistryHub { + virtual ~IRegistryHub(); + + virtual IReporterRegistry const& getReporterRegistry() const = 0; + virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; + virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; + virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0; + + virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0; + }; + + struct IMutableRegistryHub { + virtual ~IMutableRegistryHub(); + virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0; + virtual void registerListener( IReporterFactoryPtr const& factory ) = 0; + virtual void registerTest( TestCase const& testInfo ) = 0; + virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; + virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; + virtual void registerStartupException() noexcept = 0; + virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0; + }; + + IRegistryHub const& getRegistryHub(); + IMutableRegistryHub& getMutableRegistryHub(); + void cleanUp(); + std::string translateActiveException(); + +} + +// end catch_interfaces_registry_hub.h +#if defined(CATCH_CONFIG_DISABLE) + #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \ + static std::string translatorName( signature ) +#endif + +#include +#include +#include + +namespace Catch { + using exceptionTranslateFunction = std::string(*)(); + + struct IExceptionTranslator; + using ExceptionTranslators = std::vector>; + + struct IExceptionTranslator { + virtual ~IExceptionTranslator(); + virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; + }; + + struct IExceptionTranslatorRegistry { + virtual ~IExceptionTranslatorRegistry(); + + virtual std::string translateActiveException() const = 0; + }; + + class ExceptionTranslatorRegistrar { + template + class ExceptionTranslator : public IExceptionTranslator { + public: + + ExceptionTranslator( std::string(*translateFunction)( T& ) ) + : m_translateFunction( translateFunction ) + {} + + std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + return ""; +#else + try { + if( it == itEnd ) + std::rethrow_exception(std::current_exception()); + else + return (*it)->translate( it+1, itEnd ); + } + catch( T& ex ) { + return m_translateFunction( ex ); + } +#endif + } + + protected: + std::string(*m_translateFunction)( T& ); + }; + + public: + template + ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { + getMutableRegistryHub().registerTranslator + ( new ExceptionTranslator( translateFunction ) ); + } + }; +} + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ + static std::string translatorName( signature ); \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ + static std::string translatorName( signature ) + +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// end catch_interfaces_exception.h +// start catch_approx.h + +#include + +namespace Catch { +namespace Detail { + + class Approx { + private: + bool equalityComparisonImpl(double other) const; + // Validates the new margin (margin >= 0) + // out-of-line to avoid including stdexcept in the header + void setMargin(double margin); + // Validates the new epsilon (0 < epsilon < 1) + // out-of-line to avoid including stdexcept in the header + void setEpsilon(double epsilon); + + public: + explicit Approx ( double value ); + + static Approx custom(); + + Approx operator-() const; + + template ::value>::type> + Approx operator()( T const& value ) const { + Approx approx( static_cast(value) ); + approx.m_epsilon = m_epsilon; + approx.m_margin = m_margin; + approx.m_scale = m_scale; + return approx; + } + + template ::value>::type> + explicit Approx( T const& value ): Approx(static_cast(value)) + {} + + template ::value>::type> + friend bool operator == ( const T& lhs, Approx const& rhs ) { + auto lhs_v = static_cast(lhs); + return rhs.equalityComparisonImpl(lhs_v); + } + + template ::value>::type> + friend bool operator == ( Approx const& lhs, const T& rhs ) { + return operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator != ( T const& lhs, Approx const& rhs ) { + return !operator==( lhs, rhs ); + } + + template ::value>::type> + friend bool operator != ( Approx const& lhs, T const& rhs ) { + return !operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator <= ( T const& lhs, Approx const& rhs ) { + return static_cast(lhs) < rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator <= ( Approx const& lhs, T const& rhs ) { + return lhs.m_value < static_cast(rhs) || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( T const& lhs, Approx const& rhs ) { + return static_cast(lhs) > rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( Approx const& lhs, T const& rhs ) { + return lhs.m_value > static_cast(rhs) || lhs == rhs; + } + + template ::value>::type> + Approx& epsilon( T const& newEpsilon ) { + double epsilonAsDouble = static_cast(newEpsilon); + setEpsilon(epsilonAsDouble); + return *this; + } + + template ::value>::type> + Approx& margin( T const& newMargin ) { + double marginAsDouble = static_cast(newMargin); + setMargin(marginAsDouble); + return *this; + } + + template ::value>::type> + Approx& scale( T const& newScale ) { + m_scale = static_cast(newScale); + return *this; + } + + std::string toString() const; + + private: + double m_epsilon; + double m_margin; + double m_scale; + double m_value; + }; +} // end namespace Detail + +namespace literals { + Detail::Approx operator "" _a(long double val); + Detail::Approx operator "" _a(unsigned long long val); +} // end namespace literals + +template<> +struct StringMaker { + static std::string convert(Catch::Detail::Approx const& value); +}; + +} // end namespace Catch + +// end catch_approx.h +// start catch_string_manip.h + +#include +#include +#include + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ); + bool startsWith( std::string const& s, char prefix ); + bool endsWith( std::string const& s, std::string const& suffix ); + bool endsWith( std::string const& s, char suffix ); + bool contains( std::string const& s, std::string const& infix ); + void toLowerInPlace( std::string& s ); + std::string toLower( std::string const& s ); + //! Returns a new string without whitespace at the start/end + std::string trim( std::string const& str ); + //! Returns a substring of the original ref without whitespace. Beware lifetimes! + StringRef trim(StringRef ref); + + // !!! Be aware, returns refs into original string - make sure original string outlives them + std::vector splitStringRef( StringRef str, char delimiter ); + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); + + struct pluralise { + pluralise( std::size_t count, std::string const& label ); + + friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + + std::size_t m_count; + std::string m_label; + }; +} + +// end catch_string_manip.h +#ifndef CATCH_CONFIG_DISABLE_MATCHERS +// start catch_capture_matchers.h + +// start catch_matchers.h + +#include +#include + +namespace Catch { +namespace Matchers { + namespace Impl { + + template struct MatchAllOf; + template struct MatchAnyOf; + template struct MatchNotOf; + + class MatcherUntypedBase { + public: + MatcherUntypedBase() = default; + MatcherUntypedBase ( MatcherUntypedBase const& ) = default; + MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; + std::string toString() const; + + protected: + virtual ~MatcherUntypedBase(); + virtual std::string describe() const = 0; + mutable std::string m_cachedToString; + }; + +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wnon-virtual-dtor" +#endif + + template + struct MatcherMethod { + virtual bool match( ObjectT const& arg ) const = 0; + }; + +#if defined(__OBJC__) + // Hack to fix Catch GH issue #1661. Could use id for generic Object support. + // use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation + template<> + struct MatcherMethod { + virtual bool match( NSString* arg ) const = 0; + }; +#endif + +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + + template + struct MatcherBase : MatcherUntypedBase, MatcherMethod { + + MatchAllOf operator && ( MatcherBase const& other ) const; + MatchAnyOf operator || ( MatcherBase const& other ) const; + MatchNotOf operator ! () const; + }; + + template + struct MatchAllOf : MatcherBase { + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (!matcher->match(arg)) + return false; + } + return true; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " and "; + description += matcher->toString(); + } + description += " )"; + return description; + } + + MatchAllOf operator && ( MatcherBase const& other ) { + auto copy(*this); + copy.m_matchers.push_back( &other ); + return copy; + } + + std::vector const*> m_matchers; + }; + template + struct MatchAnyOf : MatcherBase { + + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (matcher->match(arg)) + return true; + } + return false; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " or "; + description += matcher->toString(); + } + description += " )"; + return description; + } + + MatchAnyOf operator || ( MatcherBase const& other ) { + auto copy(*this); + copy.m_matchers.push_back( &other ); + return copy; + } + + std::vector const*> m_matchers; + }; + + template + struct MatchNotOf : MatcherBase { + + MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} + + bool match( ArgT const& arg ) const override { + return !m_underlyingMatcher.match( arg ); + } + + std::string describe() const override { + return "not " + m_underlyingMatcher.toString(); + } + MatcherBase const& m_underlyingMatcher; + }; + + template + MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { + return MatchAllOf() && *this && other; + } + template + MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { + return MatchAnyOf() || *this || other; + } + template + MatchNotOf MatcherBase::operator ! () const { + return MatchNotOf( *this ); + } + + } // namespace Impl + +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch + +// end catch_matchers.h +// start catch_matchers_exception.hpp + +namespace Catch { +namespace Matchers { +namespace Exception { + +class ExceptionMessageMatcher : public MatcherBase { + std::string m_message; +public: + + ExceptionMessageMatcher(std::string const& message): + m_message(message) + {} + + bool match(std::exception const& ex) const override; + + std::string describe() const override; +}; + +} // namespace Exception + +Exception::ExceptionMessageMatcher Message(std::string const& message); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_exception.hpp +// start catch_matchers_floating.h + +namespace Catch { +namespace Matchers { + + namespace Floating { + + enum class FloatingPointKind : uint8_t; + + struct WithinAbsMatcher : MatcherBase { + WithinAbsMatcher(double target, double margin); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + double m_margin; + }; + + struct WithinUlpsMatcher : MatcherBase { + WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + uint64_t m_ulps; + FloatingPointKind m_type; + }; + + // Given IEEE-754 format for floats and doubles, we can assume + // that float -> double promotion is lossless. Given this, we can + // assume that if we do the standard relative comparison of + // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get + // the same result if we do this for floats, as if we do this for + // doubles that were promoted from floats. + struct WithinRelMatcher : MatcherBase { + WithinRelMatcher(double target, double epsilon); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + double m_epsilon; + }; + + } // namespace Floating + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff); + Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff); + Floating::WithinAbsMatcher WithinAbs(double target, double margin); + Floating::WithinRelMatcher WithinRel(double target, double eps); + // defaults epsilon to 100*numeric_limits::epsilon() + Floating::WithinRelMatcher WithinRel(double target); + Floating::WithinRelMatcher WithinRel(float target, float eps); + // defaults epsilon to 100*numeric_limits::epsilon() + Floating::WithinRelMatcher WithinRel(float target); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_floating.h +// start catch_matchers_generic.hpp + +#include +#include + +namespace Catch { +namespace Matchers { +namespace Generic { + +namespace Detail { + std::string finalizeDescription(const std::string& desc); +} + +template +class PredicateMatcher : public MatcherBase { + std::function m_predicate; + std::string m_description; +public: + + PredicateMatcher(std::function const& elem, std::string const& descr) + :m_predicate(std::move(elem)), + m_description(Detail::finalizeDescription(descr)) + {} + + bool match( T const& item ) const override { + return m_predicate(item); + } + + std::string describe() const override { + return m_description; + } +}; + +} // namespace Generic + + // The following functions create the actual matcher objects. + // The user has to explicitly specify type to the function, because + // inferring std::function is hard (but possible) and + // requires a lot of TMP. + template + Generic::PredicateMatcher Predicate(std::function const& predicate, std::string const& description = "") { + return Generic::PredicateMatcher(predicate, description); + } + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_generic.hpp +// start catch_matchers_string.h + +#include + +namespace Catch { +namespace Matchers { + + namespace StdString { + + struct CasedString + { + CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); + std::string adjustString( std::string const& str ) const; + std::string caseSensitivitySuffix() const; + + CaseSensitive::Choice m_caseSensitivity; + std::string m_str; + }; + + struct StringMatcherBase : MatcherBase { + StringMatcherBase( std::string const& operation, CasedString const& comparator ); + std::string describe() const override; + + CasedString m_comparator; + std::string m_operation; + }; + + struct EqualsMatcher : StringMatcherBase { + EqualsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct ContainsMatcher : StringMatcherBase { + ContainsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct StartsWithMatcher : StringMatcherBase { + StartsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct EndsWithMatcher : StringMatcherBase { + EndsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + + struct RegexMatcher : MatcherBase { + RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); + bool match( std::string const& matchee ) const override; + std::string describe() const override; + + private: + std::string m_regex; + CaseSensitive::Choice m_caseSensitivity; + }; + + } // namespace StdString + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_string.h +// start catch_matchers_vector.h + +#include + +namespace Catch { +namespace Matchers { + + namespace Vector { + template + struct ContainsElementMatcher : MatcherBase> { + + ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} + + bool match(std::vector const &v) const override { + for (auto const& el : v) { + if (el == m_comparator) { + return true; + } + } + return false; + } + + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } + + T const& m_comparator; + }; + + template + struct ContainsMatcher : MatcherBase> { + + ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + // !TBD: see note in EqualsMatcher + if (m_comparator.size() > v.size()) + return false; + for (auto const& comparator : m_comparator) { + auto present = false; + for (const auto& el : v) { + if (el == comparator) { + present = true; + break; + } + } + if (!present) { + return false; + } + } + return true; + } + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } + + std::vector const& m_comparator; + }; + + template + struct EqualsMatcher : MatcherBase> { + + EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + // !TBD: This currently works if all elements can be compared using != + // - a more general approach would be via a compare template that defaults + // to using !=. but could be specialised for, e.g. std::vector etc + // - then just call that directly + if (m_comparator.size() != v.size()) + return false; + for (std::size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != v[i]) + return false; + return true; + } + std::string describe() const override { + return "Equals: " + ::Catch::Detail::stringify( m_comparator ); + } + std::vector const& m_comparator; + }; + + template + struct ApproxMatcher : MatcherBase> { + + ApproxMatcher(std::vector const& comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + if (m_comparator.size() != v.size()) + return false; + for (std::size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != approx(v[i])) + return false; + return true; + } + std::string describe() const override { + return "is approx: " + ::Catch::Detail::stringify( m_comparator ); + } + template ::value>::type> + ApproxMatcher& epsilon( T const& newEpsilon ) { + approx.epsilon(newEpsilon); + return *this; + } + template ::value>::type> + ApproxMatcher& margin( T const& newMargin ) { + approx.margin(newMargin); + return *this; + } + template ::value>::type> + ApproxMatcher& scale( T const& newScale ) { + approx.scale(newScale); + return *this; + } + + std::vector const& m_comparator; + mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom(); + }; + + template + struct UnorderedEqualsMatcher : MatcherBase> { + UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} + bool match(std::vector const& vec) const override { + if (m_target.size() != vec.size()) { + return false; + } + return std::is_permutation(m_target.begin(), m_target.end(), vec.begin()); + } + + std::string describe() const override { + return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); + } + private: + std::vector const& m_target; + }; + + } // namespace Vector + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + template, typename AllocMatch = AllocComp> + Vector::ContainsMatcher Contains( std::vector const& comparator ) { + return Vector::ContainsMatcher( comparator ); + } + + template> + Vector::ContainsElementMatcher VectorContains( T const& comparator ) { + return Vector::ContainsElementMatcher( comparator ); + } + + template, typename AllocMatch = AllocComp> + Vector::EqualsMatcher Equals( std::vector const& comparator ) { + return Vector::EqualsMatcher( comparator ); + } + + template, typename AllocMatch = AllocComp> + Vector::ApproxMatcher Approx( std::vector const& comparator ) { + return Vector::ApproxMatcher( comparator ); + } + + template, typename AllocMatch = AllocComp> + Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { + return Vector::UnorderedEqualsMatcher( target ); + } + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_vector.h +namespace Catch { + + template + class MatchExpr : public ITransientExpression { + ArgT const& m_arg; + MatcherT m_matcher; + StringRef m_matcherString; + public: + MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) + : ITransientExpression{ true, matcher.match( arg ) }, + m_arg( arg ), + m_matcher( matcher ), + m_matcherString( matcherString ) + {} + + void streamReconstructedExpression( std::ostream &os ) const override { + auto matcherAsString = m_matcher.toString(); + os << Catch::Detail::stringify( m_arg ) << ' '; + if( matcherAsString == Detail::unprintableString ) + os << m_matcherString; + else + os << matcherAsString; + } + }; + + using StringMatcher = Matchers::Impl::MatcherBase; + + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ); + + template + auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr { + return MatchExpr( arg, matcher, matcherString ); + } + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + INTERNAL_CATCH_TRY { \ + catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \ + } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__ ); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( exceptionType const& ex ) { \ + catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +// end catch_capture_matchers.h +#endif +// start catch_generators.hpp + +// start catch_interfaces_generatortracker.h + + +#include + +namespace Catch { + + namespace Generators { + class GeneratorUntypedBase { + public: + GeneratorUntypedBase() = default; + virtual ~GeneratorUntypedBase(); + // Attempts to move the generator to the next element + // + // Returns true iff the move succeeded (and a valid element + // can be retrieved). + virtual bool next() = 0; + }; + using GeneratorBasePtr = std::unique_ptr; + + } // namespace Generators + + struct IGeneratorTracker { + virtual ~IGeneratorTracker(); + virtual auto hasGenerator() const -> bool = 0; + virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0; + virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0; + }; + +} // namespace Catch + +// end catch_interfaces_generatortracker.h +// start catch_enforce.h + +#include + +namespace Catch { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + template + [[noreturn]] + void throw_exception(Ex const& e) { + throw e; + } +#else // ^^ Exceptions are enabled // Exceptions are disabled vv + [[noreturn]] + void throw_exception(std::exception const& e); +#endif + + [[noreturn]] + void throw_logic_error(std::string const& msg); + [[noreturn]] + void throw_domain_error(std::string const& msg); + [[noreturn]] + void throw_runtime_error(std::string const& msg); + +} // namespace Catch; + +#define CATCH_MAKE_MSG(...) \ + (Catch::ReusableStringStream() << __VA_ARGS__).str() + +#define CATCH_INTERNAL_ERROR(...) \ + Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__)) + +#define CATCH_ERROR(...) \ + Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ )) + +#define CATCH_RUNTIME_ERROR(...) \ + Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ )) + +#define CATCH_ENFORCE( condition, ... ) \ + do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false) + +// end catch_enforce.h +#include +#include +#include + +#include +#include + +namespace Catch { + +class GeneratorException : public std::exception { + const char* const m_msg = ""; + +public: + GeneratorException(const char* msg): + m_msg(msg) + {} + + const char* what() const noexcept override final; +}; + +namespace Generators { + + // !TBD move this into its own location? + namespace pf{ + template + std::unique_ptr make_unique( Args&&... args ) { + return std::unique_ptr(new T(std::forward(args)...)); + } + } + + template + struct IGenerator : GeneratorUntypedBase { + virtual ~IGenerator() = default; + + // Returns the current element of the generator + // + // \Precondition The generator is either freshly constructed, + // or the last call to `next()` returned true + virtual T const& get() const = 0; + using type = T; + }; + + template + class SingleValueGenerator final : public IGenerator { + T m_value; + public: + SingleValueGenerator(T&& value) : m_value(std::move(value)) {} + + T const& get() const override { + return m_value; + } + bool next() override { + return false; + } + }; + + template + class FixedValuesGenerator final : public IGenerator { + static_assert(!std::is_same::value, + "FixedValuesGenerator does not support bools because of std::vector" + "specialization, use SingleValue Generator instead."); + std::vector m_values; + size_t m_idx = 0; + public: + FixedValuesGenerator( std::initializer_list values ) : m_values( values ) {} + + T const& get() const override { + return m_values[m_idx]; + } + bool next() override { + ++m_idx; + return m_idx < m_values.size(); + } + }; + + template + class GeneratorWrapper final { + std::unique_ptr> m_generator; + public: + GeneratorWrapper(std::unique_ptr> generator): + m_generator(std::move(generator)) + {} + T const& get() const { + return m_generator->get(); + } + bool next() { + return m_generator->next(); + } + }; + + template + GeneratorWrapper value(T&& value) { + return GeneratorWrapper(pf::make_unique>(std::forward(value))); + } + template + GeneratorWrapper values(std::initializer_list values) { + return GeneratorWrapper(pf::make_unique>(values)); + } + + template + class Generators : public IGenerator { + std::vector> m_generators; + size_t m_current = 0; + + void populate(GeneratorWrapper&& generator) { + m_generators.emplace_back(std::move(generator)); + } + void populate(T&& val) { + m_generators.emplace_back(value(std::forward(val))); + } + template + void populate(U&& val) { + populate(T(std::forward(val))); + } + template + void populate(U&& valueOrGenerator, Gs &&... moreGenerators) { + populate(std::forward(valueOrGenerator)); + populate(std::forward(moreGenerators)...); + } + + public: + template + Generators(Gs &&... moreGenerators) { + m_generators.reserve(sizeof...(Gs)); + populate(std::forward(moreGenerators)...); + } + + T const& get() const override { + return m_generators[m_current].get(); + } + + bool next() override { + if (m_current >= m_generators.size()) { + return false; + } + const bool current_status = m_generators[m_current].next(); + if (!current_status) { + ++m_current; + } + return m_current < m_generators.size(); + } + }; + + template + GeneratorWrapper> table( std::initializer_list::type...>> tuples ) { + return values>( tuples ); + } + + // Tag type to signal that a generator sequence should convert arguments to a specific type + template + struct as {}; + + template + auto makeGenerators( GeneratorWrapper&& generator, Gs &&... moreGenerators ) -> Generators { + return Generators(std::move(generator), std::forward(moreGenerators)...); + } + template + auto makeGenerators( GeneratorWrapper&& generator ) -> Generators { + return Generators(std::move(generator)); + } + template + auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators { + return makeGenerators( value( std::forward( val ) ), std::forward( moreGenerators )... ); + } + template + auto makeGenerators( as, U&& val, Gs &&... moreGenerators ) -> Generators { + return makeGenerators( value( T( std::forward( val ) ) ), std::forward( moreGenerators )... ); + } + + auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker&; + + template + // Note: The type after -> is weird, because VS2015 cannot parse + // the expression used in the typedef inside, when it is in + // return type. Yeah. + auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval().get()) { + using UnderlyingType = typename decltype(generatorExpression())::type; + + IGeneratorTracker& tracker = acquireGeneratorTracker( generatorName, lineInfo ); + if (!tracker.hasGenerator()) { + tracker.setGenerator(pf::make_unique>(generatorExpression())); + } + + auto const& generator = static_cast const&>( *tracker.getGenerator() ); + return generator.get(); + } + +} // namespace Generators +} // namespace Catch + +#define GENERATE( ... ) \ + Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ + CATCH_INTERNAL_LINEINFO, \ + [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) +#define GENERATE_COPY( ... ) \ + Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ + CATCH_INTERNAL_LINEINFO, \ + [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) +#define GENERATE_REF( ... ) \ + Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ + CATCH_INTERNAL_LINEINFO, \ + [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) + +// end catch_generators.hpp +// start catch_generators_generic.hpp + +namespace Catch { +namespace Generators { + + template + class TakeGenerator : public IGenerator { + GeneratorWrapper m_generator; + size_t m_returned = 0; + size_t m_target; + public: + TakeGenerator(size_t target, GeneratorWrapper&& generator): + m_generator(std::move(generator)), + m_target(target) + { + assert(target != 0 && "Empty generators are not allowed"); + } + T const& get() const override { + return m_generator.get(); + } + bool next() override { + ++m_returned; + if (m_returned >= m_target) { + return false; + } + + const auto success = m_generator.next(); + // If the underlying generator does not contain enough values + // then we cut short as well + if (!success) { + m_returned = m_target; + } + return success; + } + }; + + template + GeneratorWrapper take(size_t target, GeneratorWrapper&& generator) { + return GeneratorWrapper(pf::make_unique>(target, std::move(generator))); + } + + template + class FilterGenerator : public IGenerator { + GeneratorWrapper m_generator; + Predicate m_predicate; + public: + template + FilterGenerator(P&& pred, GeneratorWrapper&& generator): + m_generator(std::move(generator)), + m_predicate(std::forward

(pred)) + { + if (!m_predicate(m_generator.get())) { + // It might happen that there are no values that pass the + // filter. In that case we throw an exception. + auto has_initial_value = nextImpl(); + if (!has_initial_value) { + Catch::throw_exception(GeneratorException("No valid value found in filtered generator")); + } + } + } + + T const& get() const override { + return m_generator.get(); + } + + bool next() override { + return nextImpl(); + } + + private: + bool nextImpl() { + bool success = m_generator.next(); + if (!success) { + return false; + } + while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true); + return success; + } + }; + + template + GeneratorWrapper filter(Predicate&& pred, GeneratorWrapper&& generator) { + return GeneratorWrapper(std::unique_ptr>(pf::make_unique>(std::forward(pred), std::move(generator)))); + } + + template + class RepeatGenerator : public IGenerator { + static_assert(!std::is_same::value, + "RepeatGenerator currently does not support bools" + "because of std::vector specialization"); + GeneratorWrapper m_generator; + mutable std::vector m_returned; + size_t m_target_repeats; + size_t m_current_repeat = 0; + size_t m_repeat_index = 0; + public: + RepeatGenerator(size_t repeats, GeneratorWrapper&& generator): + m_generator(std::move(generator)), + m_target_repeats(repeats) + { + assert(m_target_repeats > 0 && "Repeat generator must repeat at least once"); + } + + T const& get() const override { + if (m_current_repeat == 0) { + m_returned.push_back(m_generator.get()); + return m_returned.back(); + } + return m_returned[m_repeat_index]; + } + + bool next() override { + // There are 2 basic cases: + // 1) We are still reading the generator + // 2) We are reading our own cache + + // In the first case, we need to poke the underlying generator. + // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache + if (m_current_repeat == 0) { + const auto success = m_generator.next(); + if (!success) { + ++m_current_repeat; + } + return m_current_repeat < m_target_repeats; + } + + // In the second case, we need to move indices forward and check that we haven't run up against the end + ++m_repeat_index; + if (m_repeat_index == m_returned.size()) { + m_repeat_index = 0; + ++m_current_repeat; + } + return m_current_repeat < m_target_repeats; + } + }; + + template + GeneratorWrapper repeat(size_t repeats, GeneratorWrapper&& generator) { + return GeneratorWrapper(pf::make_unique>(repeats, std::move(generator))); + } + + template + class MapGenerator : public IGenerator { + // TBD: provide static assert for mapping function, for friendly error message + GeneratorWrapper m_generator; + Func m_function; + // To avoid returning dangling reference, we have to save the values + T m_cache; + public: + template + MapGenerator(F2&& function, GeneratorWrapper&& generator) : + m_generator(std::move(generator)), + m_function(std::forward(function)), + m_cache(m_function(m_generator.get())) + {} + + T const& get() const override { + return m_cache; + } + bool next() override { + const auto success = m_generator.next(); + if (success) { + m_cache = m_function(m_generator.get()); + } + return success; + } + }; + + template > + GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { + return GeneratorWrapper( + pf::make_unique>(std::forward(function), std::move(generator)) + ); + } + + template + GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { + return GeneratorWrapper( + pf::make_unique>(std::forward(function), std::move(generator)) + ); + } + + template + class ChunkGenerator final : public IGenerator> { + std::vector m_chunk; + size_t m_chunk_size; + GeneratorWrapper m_generator; + bool m_used_up = false; + public: + ChunkGenerator(size_t size, GeneratorWrapper generator) : + m_chunk_size(size), m_generator(std::move(generator)) + { + m_chunk.reserve(m_chunk_size); + if (m_chunk_size != 0) { + m_chunk.push_back(m_generator.get()); + for (size_t i = 1; i < m_chunk_size; ++i) { + if (!m_generator.next()) { + Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); + } + m_chunk.push_back(m_generator.get()); + } + } + } + std::vector const& get() const override { + return m_chunk; + } + bool next() override { + m_chunk.clear(); + for (size_t idx = 0; idx < m_chunk_size; ++idx) { + if (!m_generator.next()) { + return false; + } + m_chunk.push_back(m_generator.get()); + } + return true; + } + }; + + template + GeneratorWrapper> chunk(size_t size, GeneratorWrapper&& generator) { + return GeneratorWrapper>( + pf::make_unique>(size, std::move(generator)) + ); + } + +} // namespace Generators +} // namespace Catch + +// end catch_generators_generic.hpp +// start catch_generators_specific.hpp + +// start catch_context.h + +#include + +namespace Catch { + + struct IResultCapture; + struct IRunner; + struct IConfig; + struct IMutableContext; + + using IConfigPtr = std::shared_ptr; + + struct IContext + { + virtual ~IContext(); + + virtual IResultCapture* getResultCapture() = 0; + virtual IRunner* getRunner() = 0; + virtual IConfigPtr const& getConfig() const = 0; + }; + + struct IMutableContext : IContext + { + virtual ~IMutableContext(); + virtual void setResultCapture( IResultCapture* resultCapture ) = 0; + virtual void setRunner( IRunner* runner ) = 0; + virtual void setConfig( IConfigPtr const& config ) = 0; + + private: + static IMutableContext *currentContext; + friend IMutableContext& getCurrentMutableContext(); + friend void cleanUpContext(); + static void createContext(); + }; + + inline IMutableContext& getCurrentMutableContext() + { + if( !IMutableContext::currentContext ) + IMutableContext::createContext(); + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return *IMutableContext::currentContext; + } + + inline IContext& getCurrentContext() + { + return getCurrentMutableContext(); + } + + void cleanUpContext(); + + class SimplePcg32; + SimplePcg32& rng(); +} + +// end catch_context.h +// start catch_interfaces_config.h + +// start catch_option.hpp + +namespace Catch { + + // An optional type + template + class Option { + public: + Option() : nullableValue( nullptr ) {} + Option( T const& _value ) + : nullableValue( new( storage ) T( _value ) ) + {} + Option( Option const& _other ) + : nullableValue( _other ? new( storage ) T( *_other ) : nullptr ) + {} + + ~Option() { + reset(); + } + + Option& operator= ( Option const& _other ) { + if( &_other != this ) { + reset(); + if( _other ) + nullableValue = new( storage ) T( *_other ); + } + return *this; + } + Option& operator = ( T const& _value ) { + reset(); + nullableValue = new( storage ) T( _value ); + return *this; + } + + void reset() { + if( nullableValue ) + nullableValue->~T(); + nullableValue = nullptr; + } + + T& operator*() { return *nullableValue; } + T const& operator*() const { return *nullableValue; } + T* operator->() { return nullableValue; } + const T* operator->() const { return nullableValue; } + + T valueOr( T const& defaultValue ) const { + return nullableValue ? *nullableValue : defaultValue; + } + + bool some() const { return nullableValue != nullptr; } + bool none() const { return nullableValue == nullptr; } + + bool operator !() const { return nullableValue == nullptr; } + explicit operator bool() const { + return some(); + } + + private: + T *nullableValue; + alignas(alignof(T)) char storage[sizeof(T)]; + }; + +} // end namespace Catch + +// end catch_option.hpp +#include +#include +#include +#include +#include + +namespace Catch { + + enum class Verbosity { + Quiet = 0, + Normal, + High + }; + + struct WarnAbout { enum What { + Nothing = 0x00, + NoAssertions = 0x01, + NoTests = 0x02 + }; }; + + struct ShowDurations { enum OrNot { + DefaultForReporter, + Always, + Never + }; }; + struct RunTests { enum InWhatOrder { + InDeclarationOrder, + InLexicographicalOrder, + InRandomOrder + }; }; + struct UseColour { enum YesOrNo { + Auto, + Yes, + No + }; }; + struct WaitForKeypress { enum When { + Never, + BeforeStart = 1, + BeforeExit = 2, + BeforeStartAndExit = BeforeStart | BeforeExit + }; }; + + class TestSpec; + + struct IConfig : NonCopyable { + + virtual ~IConfig(); + + virtual bool allowThrows() const = 0; + virtual std::ostream& stream() const = 0; + virtual std::string name() const = 0; + virtual bool includeSuccessfulResults() const = 0; + virtual bool shouldDebugBreak() const = 0; + virtual bool warnAboutMissingAssertions() const = 0; + virtual bool warnAboutNoTests() const = 0; + virtual int abortAfter() const = 0; + virtual bool showInvisibles() const = 0; + virtual ShowDurations::OrNot showDurations() const = 0; + virtual double minDuration() const = 0; + virtual TestSpec const& testSpec() const = 0; + virtual bool hasTestFilters() const = 0; + virtual std::vector const& getTestsOrTags() const = 0; + virtual RunTests::InWhatOrder runOrder() const = 0; + virtual unsigned int rngSeed() const = 0; + virtual UseColour::YesOrNo useColour() const = 0; + virtual std::vector const& getSectionsToRun() const = 0; + virtual Verbosity verbosity() const = 0; + + virtual bool benchmarkNoAnalysis() const = 0; + virtual int benchmarkSamples() const = 0; + virtual double benchmarkConfidenceInterval() const = 0; + virtual unsigned int benchmarkResamples() const = 0; + virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0; + }; + + using IConfigPtr = std::shared_ptr; +} + +// end catch_interfaces_config.h +// start catch_random_number_generator.h + +#include + +namespace Catch { + + // This is a simple implementation of C++11 Uniform Random Number + // Generator. It does not provide all operators, because Catch2 + // does not use it, but it should behave as expected inside stdlib's + // distributions. + // The implementation is based on the PCG family (http://pcg-random.org) + class SimplePcg32 { + using state_type = std::uint64_t; + public: + using result_type = std::uint32_t; + static constexpr result_type (min)() { + return 0; + } + static constexpr result_type (max)() { + return static_cast(-1); + } + + // Provide some default initial state for the default constructor + SimplePcg32():SimplePcg32(0xed743cc4U) {} + + explicit SimplePcg32(result_type seed_); + + void seed(result_type seed_); + void discard(uint64_t skip); + + result_type operator()(); + + private: + friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs); + friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs); + + // In theory we also need operator<< and operator>> + // In practice we do not use them, so we will skip them for now + + std::uint64_t m_state; + // This part of the state determines which "stream" of the numbers + // is chosen -- we take it as a constant for Catch2, so we only + // need to deal with seeding the main state. + // Picked by reading 8 bytes from `/dev/random` :-) + static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL; + }; + +} // end namespace Catch + +// end catch_random_number_generator.h +#include + +namespace Catch { +namespace Generators { + +template +class RandomFloatingGenerator final : public IGenerator { + Catch::SimplePcg32& m_rng; + std::uniform_real_distribution m_dist; + Float m_current_number; +public: + + RandomFloatingGenerator(Float a, Float b): + m_rng(rng()), + m_dist(a, b) { + static_cast(next()); + } + + Float const& get() const override { + return m_current_number; + } + bool next() override { + m_current_number = m_dist(m_rng); + return true; + } +}; + +template +class RandomIntegerGenerator final : public IGenerator { + Catch::SimplePcg32& m_rng; + std::uniform_int_distribution m_dist; + Integer m_current_number; +public: + + RandomIntegerGenerator(Integer a, Integer b): + m_rng(rng()), + m_dist(a, b) { + static_cast(next()); + } + + Integer const& get() const override { + return m_current_number; + } + bool next() override { + m_current_number = m_dist(m_rng); + return true; + } +}; + +// TODO: Ideally this would be also constrained against the various char types, +// but I don't expect users to run into that in practice. +template +typename std::enable_if::value && !std::is_same::value, +GeneratorWrapper>::type +random(T a, T b) { + return GeneratorWrapper( + pf::make_unique>(a, b) + ); +} + +template +typename std::enable_if::value, +GeneratorWrapper>::type +random(T a, T b) { + return GeneratorWrapper( + pf::make_unique>(a, b) + ); +} + +template +class RangeGenerator final : public IGenerator { + T m_current; + T m_end; + T m_step; + bool m_positive; + +public: + RangeGenerator(T const& start, T const& end, T const& step): + m_current(start), + m_end(end), + m_step(step), + m_positive(m_step > T(0)) + { + assert(m_current != m_end && "Range start and end cannot be equal"); + assert(m_step != T(0) && "Step size cannot be zero"); + assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end"); + } + + RangeGenerator(T const& start, T const& end): + RangeGenerator(start, end, (start < end) ? T(1) : T(-1)) + {} + + T const& get() const override { + return m_current; + } + + bool next() override { + m_current += m_step; + return (m_positive) ? (m_current < m_end) : (m_current > m_end); + } +}; + +template +GeneratorWrapper range(T const& start, T const& end, T const& step) { + static_assert(std::is_arithmetic::value && !std::is_same::value, "Type must be numeric"); + return GeneratorWrapper(pf::make_unique>(start, end, step)); +} + +template +GeneratorWrapper range(T const& start, T const& end) { + static_assert(std::is_integral::value && !std::is_same::value, "Type must be an integer"); + return GeneratorWrapper(pf::make_unique>(start, end)); +} + +template +class IteratorGenerator final : public IGenerator { + static_assert(!std::is_same::value, + "IteratorGenerator currently does not support bools" + "because of std::vector specialization"); + + std::vector m_elems; + size_t m_current = 0; +public: + template + IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { + if (m_elems.empty()) { + Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values")); + } + } + + T const& get() const override { + return m_elems[m_current]; + } + + bool next() override { + ++m_current; + return m_current != m_elems.size(); + } +}; + +template ::value_type> +GeneratorWrapper from_range(InputIterator from, InputSentinel to) { + return GeneratorWrapper(pf::make_unique>(from, to)); +} + +template +GeneratorWrapper from_range(Container const& cnt) { + return GeneratorWrapper(pf::make_unique>(cnt.begin(), cnt.end())); +} + +} // namespace Generators +} // namespace Catch + +// end catch_generators_specific.hpp + +// These files are included here so the single_include script doesn't put them +// in the conditionally compiled sections +// start catch_test_case_info.h + +#include +#include +#include + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +namespace Catch { + + struct ITestInvoker; + + struct TestCaseInfo { + enum SpecialProperties{ + None = 0, + IsHidden = 1 << 1, + ShouldFail = 1 << 2, + MayFail = 1 << 3, + Throws = 1 << 4, + NonPortable = 1 << 5, + Benchmark = 1 << 6 + }; + + TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::vector const& _tags, + SourceLineInfo const& _lineInfo ); + + friend void setTags( TestCaseInfo& testCaseInfo, std::vector tags ); + + bool isHidden() const; + bool throws() const; + bool okToFail() const; + bool expectedToFail() const; + + std::string tagsAsString() const; + + std::string name; + std::string className; + std::string description; + std::vector tags; + std::vector lcaseTags; + SourceLineInfo lineInfo; + SpecialProperties properties; + }; + + class TestCase : public TestCaseInfo { + public: + + TestCase( ITestInvoker* testCase, TestCaseInfo&& info ); + + TestCase withName( std::string const& _newName ) const; + + void invoke() const; + + TestCaseInfo const& getTestCaseInfo() const; + + bool operator == ( TestCase const& other ) const; + bool operator < ( TestCase const& other ) const; + + private: + std::shared_ptr test; + }; + + TestCase makeTestCase( ITestInvoker* testCase, + std::string const& className, + NameAndTags const& nameAndTags, + SourceLineInfo const& lineInfo ); +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_case_info.h +// start catch_interfaces_runner.h + +namespace Catch { + + struct IRunner { + virtual ~IRunner(); + virtual bool aborting() const = 0; + }; +} + +// end catch_interfaces_runner.h + +#ifdef __OBJC__ +// start catch_objc.hpp + +#import + +#include + +// NB. Any general catch headers included here must be included +// in catch.hpp first to make sure they are included by the single +// header for non obj-usage + +/////////////////////////////////////////////////////////////////////////////// +// This protocol is really only here for (self) documenting purposes, since +// all its methods are optional. +@protocol OcFixture + +@optional + +-(void) setUp; +-(void) tearDown; + +@end + +namespace Catch { + + class OcMethod : public ITestInvoker { + + public: + OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} + + virtual void invoke() const { + id obj = [[m_cls alloc] init]; + + performOptionalSelector( obj, @selector(setUp) ); + performOptionalSelector( obj, m_sel ); + performOptionalSelector( obj, @selector(tearDown) ); + + arcSafeRelease( obj ); + } + private: + virtual ~OcMethod() {} + + Class m_cls; + SEL m_sel; + }; + + namespace Detail{ + + inline std::string getAnnotation( Class cls, + std::string const& annotationName, + std::string const& testCaseName ) { + NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; + SEL sel = NSSelectorFromString( selStr ); + arcSafeRelease( selStr ); + id value = performOptionalSelector( cls, sel ); + if( value ) + return [(NSString*)value UTF8String]; + return ""; + } + } + + inline std::size_t registerTestMethods() { + std::size_t noTestMethods = 0; + int noClasses = objc_getClassList( nullptr, 0 ); + + Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); + objc_getClassList( classes, noClasses ); + + for( int c = 0; c < noClasses; c++ ) { + Class cls = classes[c]; + { + u_int count; + Method* methods = class_copyMethodList( cls, &count ); + for( u_int m = 0; m < count ; m++ ) { + SEL selector = method_getName(methods[m]); + std::string methodName = sel_getName(selector); + if( startsWith( methodName, "Catch_TestCase_" ) ) { + std::string testCaseName = methodName.substr( 15 ); + std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); + std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); + const char* className = class_getName( cls ); + + getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, NameAndTags( name.c_str(), desc.c_str() ), SourceLineInfo("",0) ) ); + noTestMethods++; + } + } + free(methods); + } + } + return noTestMethods; + } + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) + + namespace Matchers { + namespace Impl { + namespace NSStringMatchers { + + struct StringHolder : MatcherBase{ + StringHolder( NSString* substr ) : m_substr( [substr copy] ){} + StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} + StringHolder() { + arcSafeRelease( m_substr ); + } + + bool match( NSString* str ) const override { + return false; + } + + NSString* CATCH_ARC_STRONG m_substr; + }; + + struct Equals : StringHolder { + Equals( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str isEqualToString:m_substr]; + } + + std::string describe() const override { + return "equals string: " + Catch::Detail::stringify( m_substr ); + } + }; + + struct Contains : StringHolder { + Contains( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location != NSNotFound; + } + + std::string describe() const override { + return "contains string: " + Catch::Detail::stringify( m_substr ); + } + }; + + struct StartsWith : StringHolder { + StartsWith( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == 0; + } + + std::string describe() const override { + return "starts with: " + Catch::Detail::stringify( m_substr ); + } + }; + struct EndsWith : StringHolder { + EndsWith( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == [str length] - [m_substr length]; + } + + std::string describe() const override { + return "ends with: " + Catch::Detail::stringify( m_substr ); + } + }; + + } // namespace NSStringMatchers + } // namespace Impl + + inline Impl::NSStringMatchers::Equals + Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } + + inline Impl::NSStringMatchers::Contains + Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } + + inline Impl::NSStringMatchers::StartsWith + StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } + + inline Impl::NSStringMatchers::EndsWith + EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } + + } // namespace Matchers + + using namespace Matchers; + +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix +#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \ +{ \ +return @ name; \ +} \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \ +{ \ +return @ desc; \ +} \ +-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix ) + +#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ ) + +// end catch_objc.hpp +#endif + +// Benchmarking needs the externally-facing parts of reporters to work +#if defined(CATCH_CONFIG_EXTERNAL_INTERFACES) || defined(CATCH_CONFIG_ENABLE_BENCHMARKING) +// start catch_external_interfaces.h + +// start catch_reporter_bases.hpp + +// start catch_interfaces_reporter.h + +// start catch_config.hpp + +// start catch_test_spec_parser.h + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// start catch_test_spec.h + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// start catch_wildcard_pattern.h + +namespace Catch +{ + class WildcardPattern { + enum WildcardPosition { + NoWildcard = 0, + WildcardAtStart = 1, + WildcardAtEnd = 2, + WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd + }; + + public: + + WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ); + virtual ~WildcardPattern() = default; + virtual bool matches( std::string const& str ) const; + + private: + std::string normaliseString( std::string const& str ) const; + CaseSensitive::Choice m_caseSensitivity; + WildcardPosition m_wildcard = NoWildcard; + std::string m_pattern; + }; +} + +// end catch_wildcard_pattern.h +#include +#include +#include + +namespace Catch { + + struct IConfig; + + class TestSpec { + class Pattern { + public: + explicit Pattern( std::string const& name ); + virtual ~Pattern(); + virtual bool matches( TestCaseInfo const& testCase ) const = 0; + std::string const& name() const; + private: + std::string const m_name; + }; + using PatternPtr = std::shared_ptr; + + class NamePattern : public Pattern { + public: + explicit NamePattern( std::string const& name, std::string const& filterString ); + bool matches( TestCaseInfo const& testCase ) const override; + private: + WildcardPattern m_wildcardPattern; + }; + + class TagPattern : public Pattern { + public: + explicit TagPattern( std::string const& tag, std::string const& filterString ); + bool matches( TestCaseInfo const& testCase ) const override; + private: + std::string m_tag; + }; + + class ExcludedPattern : public Pattern { + public: + explicit ExcludedPattern( PatternPtr const& underlyingPattern ); + bool matches( TestCaseInfo const& testCase ) const override; + private: + PatternPtr m_underlyingPattern; + }; + + struct Filter { + std::vector m_patterns; + + bool matches( TestCaseInfo const& testCase ) const; + std::string name() const; + }; + + public: + struct FilterMatch { + std::string name; + std::vector tests; + }; + using Matches = std::vector; + using vectorStrings = std::vector; + + bool hasFilters() const; + bool matches( TestCaseInfo const& testCase ) const; + Matches matchesByFilter( std::vector const& testCases, IConfig const& config ) const; + const vectorStrings & getInvalidArgs() const; + + private: + std::vector m_filters; + std::vector m_invalidArgs; + friend class TestSpecParser; + }; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_spec.h +// start catch_interfaces_tag_alias_registry.h + +#include + +namespace Catch { + + struct TagAlias; + + struct ITagAliasRegistry { + virtual ~ITagAliasRegistry(); + // Nullptr if not present + virtual TagAlias const* find( std::string const& alias ) const = 0; + virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; + + static ITagAliasRegistry const& get(); + }; + +} // end namespace Catch + +// end catch_interfaces_tag_alias_registry.h +namespace Catch { + + class TestSpecParser { + enum Mode{ None, Name, QuotedName, Tag, EscapedName }; + Mode m_mode = None; + Mode lastMode = None; + bool m_exclusion = false; + std::size_t m_pos = 0; + std::size_t m_realPatternPos = 0; + std::string m_arg; + std::string m_substring; + std::string m_patternName; + std::vector m_escapeChars; + TestSpec::Filter m_currentFilter; + TestSpec m_testSpec; + ITagAliasRegistry const* m_tagAliases = nullptr; + + public: + TestSpecParser( ITagAliasRegistry const& tagAliases ); + + TestSpecParser& parse( std::string const& arg ); + TestSpec testSpec(); + + private: + bool visitChar( char c ); + void startNewMode( Mode mode ); + bool processNoneChar( char c ); + void processNameChar( char c ); + bool processOtherChar( char c ); + void endMode(); + void escape(); + bool isControlChar( char c ) const; + void saveLastMode(); + void revertBackToLastMode(); + void addFilter(); + bool separate(); + + // Handles common preprocessing of the pattern for name/tag patterns + std::string preprocessPattern(); + // Adds the current pattern as a test name + void addNamePattern(); + // Adds the current pattern as a tag + void addTagPattern(); + + inline void addCharToPattern(char c) { + m_substring += c; + m_patternName += c; + m_realPatternPos++; + } + + }; + TestSpec parseTestSpec( std::string const& arg ); + +} // namespace Catch + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_spec_parser.h +// Libstdc++ doesn't like incomplete classes for unique_ptr + +#include +#include +#include + +#ifndef CATCH_CONFIG_CONSOLE_WIDTH +#define CATCH_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { + + struct IStream; + + struct ConfigData { + bool listTests = false; + bool listTags = false; + bool listReporters = false; + bool listTestNamesOnly = false; + + bool showSuccessfulTests = false; + bool shouldDebugBreak = false; + bool noThrow = false; + bool showHelp = false; + bool showInvisibles = false; + bool filenamesAsTags = false; + bool libIdentify = false; + + int abortAfter = -1; + unsigned int rngSeed = 0; + + bool benchmarkNoAnalysis = false; + unsigned int benchmarkSamples = 100; + double benchmarkConfidenceInterval = 0.95; + unsigned int benchmarkResamples = 100000; + std::chrono::milliseconds::rep benchmarkWarmupTime = 100; + + Verbosity verbosity = Verbosity::Normal; + WarnAbout::What warnings = WarnAbout::Nothing; + ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; + double minDuration = -1; + RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; + UseColour::YesOrNo useColour = UseColour::Auto; + WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; + + std::string outputFilename; + std::string name; + std::string processName; +#ifndef CATCH_CONFIG_DEFAULT_REPORTER +#define CATCH_CONFIG_DEFAULT_REPORTER "console" +#endif + std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER; +#undef CATCH_CONFIG_DEFAULT_REPORTER + + std::vector testsOrTags; + std::vector sectionsToRun; + }; + + class Config : public IConfig { + public: + + Config() = default; + Config( ConfigData const& data ); + virtual ~Config() = default; + + std::string const& getFilename() const; + + bool listTests() const; + bool listTestNamesOnly() const; + bool listTags() const; + bool listReporters() const; + + std::string getProcessName() const; + std::string const& getReporterName() const; + + std::vector const& getTestsOrTags() const override; + std::vector const& getSectionsToRun() const override; + + TestSpec const& testSpec() const override; + bool hasTestFilters() const override; + + bool showHelp() const; + + // IConfig interface + bool allowThrows() const override; + std::ostream& stream() const override; + std::string name() const override; + bool includeSuccessfulResults() const override; + bool warnAboutMissingAssertions() const override; + bool warnAboutNoTests() const override; + ShowDurations::OrNot showDurations() const override; + double minDuration() const override; + RunTests::InWhatOrder runOrder() const override; + unsigned int rngSeed() const override; + UseColour::YesOrNo useColour() const override; + bool shouldDebugBreak() const override; + int abortAfter() const override; + bool showInvisibles() const override; + Verbosity verbosity() const override; + bool benchmarkNoAnalysis() const override; + int benchmarkSamples() const override; + double benchmarkConfidenceInterval() const override; + unsigned int benchmarkResamples() const override; + std::chrono::milliseconds benchmarkWarmupTime() const override; + + private: + + IStream const* openStream(); + ConfigData m_data; + + std::unique_ptr m_stream; + TestSpec m_testSpec; + bool m_hasTestFilters = false; + }; + +} // end namespace Catch + +// end catch_config.hpp +// start catch_assertionresult.h + +#include + +namespace Catch { + + struct AssertionResultData + { + AssertionResultData() = delete; + + AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); + + std::string message; + mutable std::string reconstructedExpression; + LazyExpression lazyExpression; + ResultWas::OfType resultType; + + std::string reconstructExpression() const; + }; + + class AssertionResult { + public: + AssertionResult() = delete; + AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); + + bool isOk() const; + bool succeeded() const; + ResultWas::OfType getResultType() const; + bool hasExpression() const; + bool hasMessage() const; + std::string getExpression() const; + std::string getExpressionInMacro() const; + bool hasExpandedExpression() const; + std::string getExpandedExpression() const; + std::string getMessage() const; + SourceLineInfo getSourceInfo() const; + StringRef getTestMacroName() const; + + //protected: + AssertionInfo m_info; + AssertionResultData m_resultData; + }; + +} // end namespace Catch + +// end catch_assertionresult.h +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) +// start catch_estimate.hpp + + // Statistics estimates + + +namespace Catch { + namespace Benchmark { + template + struct Estimate { + Duration point; + Duration lower_bound; + Duration upper_bound; + double confidence_interval; + + template + operator Estimate() const { + return { point, lower_bound, upper_bound, confidence_interval }; + } + }; + } // namespace Benchmark +} // namespace Catch + +// end catch_estimate.hpp +// start catch_outlier_classification.hpp + +// Outlier information + +namespace Catch { + namespace Benchmark { + struct OutlierClassification { + int samples_seen = 0; + int low_severe = 0; // more than 3 times IQR below Q1 + int low_mild = 0; // 1.5 to 3 times IQR below Q1 + int high_mild = 0; // 1.5 to 3 times IQR above Q3 + int high_severe = 0; // more than 3 times IQR above Q3 + + int total() const { + return low_severe + low_mild + high_mild + high_severe; + } + }; + } // namespace Benchmark +} // namespace Catch + +// end catch_outlier_classification.hpp + +#include +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + +#include +#include +#include +#include +#include +#include + +namespace Catch { + + struct ReporterConfig { + explicit ReporterConfig( IConfigPtr const& _fullConfig ); + + ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ); + + std::ostream& stream() const; + IConfigPtr fullConfig() const; + + private: + std::ostream* m_stream; + IConfigPtr m_fullConfig; + }; + + struct ReporterPreferences { + bool shouldRedirectStdOut = false; + bool shouldReportAllAssertions = false; + }; + + template + struct LazyStat : Option { + LazyStat& operator=( T const& _value ) { + Option::operator=( _value ); + used = false; + return *this; + } + void reset() { + Option::reset(); + used = false; + } + bool used = false; + }; + + struct TestRunInfo { + TestRunInfo( std::string const& _name ); + std::string name; + }; + struct GroupInfo { + GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ); + + std::string name; + std::size_t groupIndex; + std::size_t groupsCounts; + }; + + struct AssertionStats { + AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ); + + AssertionStats( AssertionStats const& ) = default; + AssertionStats( AssertionStats && ) = default; + AssertionStats& operator = ( AssertionStats const& ) = delete; + AssertionStats& operator = ( AssertionStats && ) = delete; + virtual ~AssertionStats(); + + AssertionResult assertionResult; + std::vector infoMessages; + Totals totals; + }; + + struct SectionStats { + SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ); + SectionStats( SectionStats const& ) = default; + SectionStats( SectionStats && ) = default; + SectionStats& operator = ( SectionStats const& ) = default; + SectionStats& operator = ( SectionStats && ) = default; + virtual ~SectionStats(); + + SectionInfo sectionInfo; + Counts assertions; + double durationInSeconds; + bool missingAssertions; + }; + + struct TestCaseStats { + TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ); + + TestCaseStats( TestCaseStats const& ) = default; + TestCaseStats( TestCaseStats && ) = default; + TestCaseStats& operator = ( TestCaseStats const& ) = default; + TestCaseStats& operator = ( TestCaseStats && ) = default; + virtual ~TestCaseStats(); + + TestCaseInfo testInfo; + Totals totals; + std::string stdOut; + std::string stdErr; + bool aborting; + }; + + struct TestGroupStats { + TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ); + TestGroupStats( GroupInfo const& _groupInfo ); + + TestGroupStats( TestGroupStats const& ) = default; + TestGroupStats( TestGroupStats && ) = default; + TestGroupStats& operator = ( TestGroupStats const& ) = default; + TestGroupStats& operator = ( TestGroupStats && ) = default; + virtual ~TestGroupStats(); + + GroupInfo groupInfo; + Totals totals; + bool aborting; + }; + + struct TestRunStats { + TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ); + + TestRunStats( TestRunStats const& ) = default; + TestRunStats( TestRunStats && ) = default; + TestRunStats& operator = ( TestRunStats const& ) = default; + TestRunStats& operator = ( TestRunStats && ) = default; + virtual ~TestRunStats(); + + TestRunInfo runInfo; + Totals totals; + bool aborting; + }; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + struct BenchmarkInfo { + std::string name; + double estimatedDuration; + int iterations; + int samples; + unsigned int resamples; + double clockResolution; + double clockCost; + }; + + template + struct BenchmarkStats { + BenchmarkInfo info; + + std::vector samples; + Benchmark::Estimate mean; + Benchmark::Estimate standardDeviation; + Benchmark::OutlierClassification outliers; + double outlierVariance; + + template + operator BenchmarkStats() const { + std::vector samples2; + samples2.reserve(samples.size()); + std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); }); + return { + info, + std::move(samples2), + mean, + standardDeviation, + outliers, + outlierVariance, + }; + } + }; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + struct IStreamingReporter { + virtual ~IStreamingReporter() = default; + + // Implementing class must also provide the following static methods: + // static std::string getDescription(); + // static std::set getSupportedVerbosities() + + virtual ReporterPreferences getPreferences() const = 0; + + virtual void noMatchingTestCases( std::string const& spec ) = 0; + + virtual void reportInvalidArguments(std::string const&) {} + + virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; + virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; + + virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; + virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + virtual void benchmarkPreparing( std::string const& ) {} + virtual void benchmarkStarting( BenchmarkInfo const& ) {} + virtual void benchmarkEnded( BenchmarkStats<> const& ) {} + virtual void benchmarkFailed( std::string const& ) {} +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; + + // The return value indicates if the messages buffer should be cleared: + virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; + + virtual void sectionEnded( SectionStats const& sectionStats ) = 0; + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; + virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; + + virtual void skipTest( TestCaseInfo const& testInfo ) = 0; + + // Default empty implementation provided + virtual void fatalErrorEncountered( StringRef name ); + + virtual bool isMulti() const; + }; + using IStreamingReporterPtr = std::unique_ptr; + + struct IReporterFactory { + virtual ~IReporterFactory(); + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; + virtual std::string getDescription() const = 0; + }; + using IReporterFactoryPtr = std::shared_ptr; + + struct IReporterRegistry { + using FactoryMap = std::map; + using Listeners = std::vector; + + virtual ~IReporterRegistry(); + virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; + virtual FactoryMap const& getFactories() const = 0; + virtual Listeners const& getListeners() const = 0; + }; + +} // end namespace Catch + +// end catch_interfaces_reporter.h +#include +#include +#include +#include +#include +#include +#include + +namespace Catch { + void prepareExpandedExpression(AssertionResult& result); + + // Returns double formatted as %.3f (format expected on output) + std::string getFormattedDuration( double duration ); + + //! Should the reporter show + bool shouldShowDuration( IConfig const& config, double duration ); + + std::string serializeFilters( std::vector const& container ); + + template + struct StreamingReporterBase : IStreamingReporter { + + StreamingReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) + CATCH_ERROR( "Verbosity level not supported by this reporter" ); + } + + ReporterPreferences getPreferences() const override { + return m_reporterPrefs; + } + + static std::set getSupportedVerbosities() { + return { Verbosity::Normal }; + } + + ~StreamingReporterBase() override = default; + + void noMatchingTestCases(std::string const&) override {} + + void reportInvalidArguments(std::string const&) override {} + + void testRunStarting(TestRunInfo const& _testRunInfo) override { + currentTestRunInfo = _testRunInfo; + } + + void testGroupStarting(GroupInfo const& _groupInfo) override { + currentGroupInfo = _groupInfo; + } + + void testCaseStarting(TestCaseInfo const& _testInfo) override { + currentTestCaseInfo = _testInfo; + } + void sectionStarting(SectionInfo const& _sectionInfo) override { + m_sectionStack.push_back(_sectionInfo); + } + + void sectionEnded(SectionStats const& /* _sectionStats */) override { + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { + currentTestCaseInfo.reset(); + } + void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override { + currentGroupInfo.reset(); + } + void testRunEnded(TestRunStats const& /* _testRunStats */) override { + currentTestCaseInfo.reset(); + currentGroupInfo.reset(); + currentTestRunInfo.reset(); + } + + void skipTest(TestCaseInfo const&) override { + // Don't do anything with this by default. + // It can optionally be overridden in the derived class. + } + + IConfigPtr m_config; + std::ostream& stream; + + LazyStat currentTestRunInfo; + LazyStat currentGroupInfo; + LazyStat currentTestCaseInfo; + + std::vector m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + template + struct CumulativeReporterBase : IStreamingReporter { + template + struct Node { + explicit Node( T const& _value ) : value( _value ) {} + virtual ~Node() {} + + using ChildNodes = std::vector>; + T value; + ChildNodes children; + }; + struct SectionNode { + explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} + virtual ~SectionNode() = default; + + bool operator == (SectionNode const& other) const { + return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; + } + bool operator == (std::shared_ptr const& other) const { + return operator==(*other); + } + + SectionStats stats; + using ChildSections = std::vector>; + using Assertions = std::vector; + ChildSections childSections; + Assertions assertions; + std::string stdOut; + std::string stdErr; + }; + + struct BySectionInfo { + BySectionInfo( SectionInfo const& other ) : m_other( other ) {} + BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} + bool operator() (std::shared_ptr const& node) const { + return ((node->stats.sectionInfo.name == m_other.name) && + (node->stats.sectionInfo.lineInfo == m_other.lineInfo)); + } + void operator=(BySectionInfo const&) = delete; + + private: + SectionInfo const& m_other; + }; + + using TestCaseNode = Node; + using TestGroupNode = Node; + using TestRunNode = Node; + + CumulativeReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) + CATCH_ERROR( "Verbosity level not supported by this reporter" ); + } + ~CumulativeReporterBase() override = default; + + ReporterPreferences getPreferences() const override { + return m_reporterPrefs; + } + + static std::set getSupportedVerbosities() { + return { Verbosity::Normal }; + } + + void testRunStarting( TestRunInfo const& ) override {} + void testGroupStarting( GroupInfo const& ) override {} + + void testCaseStarting( TestCaseInfo const& ) override {} + + void sectionStarting( SectionInfo const& sectionInfo ) override { + SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); + std::shared_ptr node; + if( m_sectionStack.empty() ) { + if( !m_rootSection ) + m_rootSection = std::make_shared( incompleteStats ); + node = m_rootSection; + } + else { + SectionNode& parentNode = *m_sectionStack.back(); + auto it = + std::find_if( parentNode.childSections.begin(), + parentNode.childSections.end(), + BySectionInfo( sectionInfo ) ); + if( it == parentNode.childSections.end() ) { + node = std::make_shared( incompleteStats ); + parentNode.childSections.push_back( node ); + } + else + node = *it; + } + m_sectionStack.push_back( node ); + m_deepestSection = std::move(node); + } + + void assertionStarting(AssertionInfo const&) override {} + + bool assertionEnded(AssertionStats const& assertionStats) override { + assert(!m_sectionStack.empty()); + // AssertionResult holds a pointer to a temporary DecomposedExpression, + // which getExpandedExpression() calls to build the expression string. + // Our section stack copy of the assertionResult will likely outlive the + // temporary, so it must be expanded or discarded now to avoid calling + // a destroyed object later. + prepareExpandedExpression(const_cast( assertionStats.assertionResult ) ); + SectionNode& sectionNode = *m_sectionStack.back(); + sectionNode.assertions.push_back(assertionStats); + return true; + } + void sectionEnded(SectionStats const& sectionStats) override { + assert(!m_sectionStack.empty()); + SectionNode& node = *m_sectionStack.back(); + node.stats = sectionStats; + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& testCaseStats) override { + auto node = std::make_shared(testCaseStats); + assert(m_sectionStack.size() == 0); + node->children.push_back(m_rootSection); + m_testCases.push_back(node); + m_rootSection.reset(); + + assert(m_deepestSection); + m_deepestSection->stdOut = testCaseStats.stdOut; + m_deepestSection->stdErr = testCaseStats.stdErr; + } + void testGroupEnded(TestGroupStats const& testGroupStats) override { + auto node = std::make_shared(testGroupStats); + node->children.swap(m_testCases); + m_testGroups.push_back(node); + } + void testRunEnded(TestRunStats const& testRunStats) override { + auto node = std::make_shared(testRunStats); + node->children.swap(m_testGroups); + m_testRuns.push_back(node); + testRunEndedCumulative(); + } + virtual void testRunEndedCumulative() = 0; + + void skipTest(TestCaseInfo const&) override {} + + IConfigPtr m_config; + std::ostream& stream; + std::vector m_assertions; + std::vector>> m_sections; + std::vector> m_testCases; + std::vector> m_testGroups; + + std::vector> m_testRuns; + + std::shared_ptr m_rootSection; + std::shared_ptr m_deepestSection; + std::vector> m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + template + char const* getLineOfChars() { + static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; + if( !*line ) { + std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); + line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; + } + return line; + } + + struct TestEventListenerBase : StreamingReporterBase { + TestEventListenerBase( ReporterConfig const& _config ); + + static std::set getSupportedVerbosities(); + + void assertionStarting(AssertionInfo const&) override; + bool assertionEnded(AssertionStats const&) override; + }; + +} // end namespace Catch + +// end catch_reporter_bases.hpp +// start catch_console_colour.h + +namespace Catch { + + struct Colour { + enum Code { + None = 0, + + White, + Red, + Green, + Blue, + Cyan, + Yellow, + Grey, + + Bright = 0x10, + + BrightRed = Bright | Red, + BrightGreen = Bright | Green, + LightGrey = Bright | Grey, + BrightWhite = Bright | White, + BrightYellow = Bright | Yellow, + + // By intention + FileName = LightGrey, + Warning = BrightYellow, + ResultError = BrightRed, + ResultSuccess = BrightGreen, + ResultExpectedFailure = Warning, + + Error = BrightRed, + Success = Green, + + OriginalExpression = Cyan, + ReconstructedExpression = BrightYellow, + + SecondaryText = LightGrey, + Headers = White + }; + + // Use constructed object for RAII guard + Colour( Code _colourCode ); + Colour( Colour&& other ) noexcept; + Colour& operator=( Colour&& other ) noexcept; + ~Colour(); + + // Use static method for one-shot changes + static void use( Code _colourCode ); + + private: + bool m_moved = false; + }; + + std::ostream& operator << ( std::ostream& os, Colour const& ); + +} // end namespace Catch + +// end catch_console_colour.h +// start catch_reporter_registrars.hpp + + +namespace Catch { + + template + class ReporterRegistrar { + + class ReporterFactory : public IReporterFactory { + + IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + + std::string getDescription() const override { + return T::getDescription(); + } + }; + + public: + + explicit ReporterRegistrar( std::string const& name ) { + getMutableRegistryHub().registerReporter( name, std::make_shared() ); + } + }; + + template + class ListenerRegistrar { + + class ListenerFactory : public IReporterFactory { + + IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + std::string getDescription() const override { + return std::string(); + } + }; + + public: + + ListenerRegistrar() { + getMutableRegistryHub().registerListener( std::make_shared() ); + } + }; +} + +#if !defined(CATCH_CONFIG_DISABLE) + +#define CATCH_REGISTER_REPORTER( name, reporterType ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +#define CATCH_REGISTER_LISTENER( listenerType ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ListenerRegistrar catch_internal_RegistrarFor##listenerType; } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#else // CATCH_CONFIG_DISABLE + +#define CATCH_REGISTER_REPORTER(name, reporterType) +#define CATCH_REGISTER_LISTENER(listenerType) + +#endif // CATCH_CONFIG_DISABLE + +// end catch_reporter_registrars.hpp +// Allow users to base their work off existing reporters +// start catch_reporter_compact.h + +namespace Catch { + + struct CompactReporter : StreamingReporterBase { + + using StreamingReporterBase::StreamingReporterBase; + + ~CompactReporter() override; + + static std::string getDescription(); + + void noMatchingTestCases(std::string const& spec) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& _assertionStats) override; + + void sectionEnded(SectionStats const& _sectionStats) override; + + void testRunEnded(TestRunStats const& _testRunStats) override; + + }; + +} // end namespace Catch + +// end catch_reporter_compact.h +// start catch_reporter_console.h + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + // Fwd decls + struct SummaryColumn; + class TablePrinter; + + struct ConsoleReporter : StreamingReporterBase { + std::unique_ptr m_tablePrinter; + + ConsoleReporter(ReporterConfig const& config); + ~ConsoleReporter() override; + static std::string getDescription(); + + void noMatchingTestCases(std::string const& spec) override; + + void reportInvalidArguments(std::string const&arg) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& _assertionStats) override; + + void sectionStarting(SectionInfo const& _sectionInfo) override; + void sectionEnded(SectionStats const& _sectionStats) override; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void benchmarkPreparing(std::string const& name) override; + void benchmarkStarting(BenchmarkInfo const& info) override; + void benchmarkEnded(BenchmarkStats<> const& stats) override; + void benchmarkFailed(std::string const& error) override; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + void testCaseEnded(TestCaseStats const& _testCaseStats) override; + void testGroupEnded(TestGroupStats const& _testGroupStats) override; + void testRunEnded(TestRunStats const& _testRunStats) override; + void testRunStarting(TestRunInfo const& _testRunInfo) override; + private: + + void lazyPrint(); + + void lazyPrintWithoutClosingBenchmarkTable(); + void lazyPrintRunInfo(); + void lazyPrintGroupInfo(); + void printTestCaseAndSectionHeader(); + + void printClosedHeader(std::string const& _name); + void printOpenHeader(std::string const& _name); + + // if string has a : in first line will set indent to follow it on + // subsequent lines + void printHeaderString(std::string const& _string, std::size_t indent = 0); + + void printTotals(Totals const& totals); + void printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row); + + void printTotalsDivider(Totals const& totals); + void printSummaryDivider(); + void printTestFilters(); + + private: + bool m_headerPrinted = false; + }; + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +// end catch_reporter_console.h +// start catch_reporter_junit.h + +// start catch_xmlwriter.h + +#include + +namespace Catch { + enum class XmlFormatting { + None = 0x00, + Indent = 0x01, + Newline = 0x02, + }; + + XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs); + XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs); + + class XmlEncode { + public: + enum ForWhat { ForTextNodes, ForAttributes }; + + XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ); + + void encodeTo( std::ostream& os ) const; + + friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ); + + private: + std::string m_str; + ForWhat m_forWhat; + }; + + class XmlWriter { + public: + + class ScopedElement { + public: + ScopedElement( XmlWriter* writer, XmlFormatting fmt ); + + ScopedElement( ScopedElement&& other ) noexcept; + ScopedElement& operator=( ScopedElement&& other ) noexcept; + + ~ScopedElement(); + + ScopedElement& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent ); + + template + ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { + m_writer->writeAttribute( name, attribute ); + return *this; + } + + private: + mutable XmlWriter* m_writer = nullptr; + XmlFormatting m_fmt; + }; + + XmlWriter( std::ostream& os = Catch::cout() ); + ~XmlWriter(); + + XmlWriter( XmlWriter const& ) = delete; + XmlWriter& operator=( XmlWriter const& ) = delete; + + XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); + + ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); + + XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); + + XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ); + + XmlWriter& writeAttribute( std::string const& name, bool attribute ); + + template + XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { + ReusableStringStream rss; + rss << attribute; + return writeAttribute( name, rss.str() ); + } + + XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); + + XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); + + void writeStylesheetRef( std::string const& url ); + + XmlWriter& writeBlankLine(); + + void ensureTagClosed(); + + private: + + void applyFormatting(XmlFormatting fmt); + + void writeDeclaration(); + + void newlineIfNecessary(); + + bool m_tagIsOpen = false; + bool m_needsNewline = false; + std::vector m_tags; + std::string m_indent; + std::ostream& m_os; + }; + +} + +// end catch_xmlwriter.h +namespace Catch { + + class JunitReporter : public CumulativeReporterBase { + public: + JunitReporter(ReporterConfig const& _config); + + ~JunitReporter() override; + + static std::string getDescription(); + + void noMatchingTestCases(std::string const& /*spec*/) override; + + void testRunStarting(TestRunInfo const& runInfo) override; + + void testGroupStarting(GroupInfo const& groupInfo) override; + + void testCaseStarting(TestCaseInfo const& testCaseInfo) override; + bool assertionEnded(AssertionStats const& assertionStats) override; + + void testCaseEnded(TestCaseStats const& testCaseStats) override; + + void testGroupEnded(TestGroupStats const& testGroupStats) override; + + void testRunEndedCumulative() override; + + void writeGroup(TestGroupNode const& groupNode, double suiteTime); + + void writeTestCase(TestCaseNode const& testCaseNode); + + void writeSection( std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode, + bool testOkToFail ); + + void writeAssertions(SectionNode const& sectionNode); + void writeAssertion(AssertionStats const& stats); + + XmlWriter xml; + Timer suiteTimer; + std::string stdOutForSuite; + std::string stdErrForSuite; + unsigned int unexpectedExceptions = 0; + bool m_okToFail = false; + }; + +} // end namespace Catch + +// end catch_reporter_junit.h +// start catch_reporter_xml.h + +namespace Catch { + class XmlReporter : public StreamingReporterBase { + public: + XmlReporter(ReporterConfig const& _config); + + ~XmlReporter() override; + + static std::string getDescription(); + + virtual std::string getStylesheetRef() const; + + void writeSourceInfo(SourceLineInfo const& sourceInfo); + + public: // StreamingReporterBase + + void noMatchingTestCases(std::string const& s) override; + + void testRunStarting(TestRunInfo const& testInfo) override; + + void testGroupStarting(GroupInfo const& groupInfo) override; + + void testCaseStarting(TestCaseInfo const& testInfo) override; + + void sectionStarting(SectionInfo const& sectionInfo) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& assertionStats) override; + + void sectionEnded(SectionStats const& sectionStats) override; + + void testCaseEnded(TestCaseStats const& testCaseStats) override; + + void testGroupEnded(TestGroupStats const& testGroupStats) override; + + void testRunEnded(TestRunStats const& testRunStats) override; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void benchmarkPreparing(std::string const& name) override; + void benchmarkStarting(BenchmarkInfo const&) override; + void benchmarkEnded(BenchmarkStats<> const&) override; + void benchmarkFailed(std::string const&) override; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + private: + Timer m_testCaseTimer; + XmlWriter m_xml; + int m_sectionDepth = 0; + }; + +} // end namespace Catch + +// end catch_reporter_xml.h + +// end catch_external_interfaces.h +#endif + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) +// start catch_benchmarking_all.hpp + +// A proxy header that includes all of the benchmarking headers to allow +// concise include of the benchmarking features. You should prefer the +// individual includes in standard use. + +// start catch_benchmark.hpp + + // Benchmark + +// start catch_chronometer.hpp + +// User-facing chronometer + + +// start catch_clock.hpp + +// Clocks + + +#include +#include + +namespace Catch { + namespace Benchmark { + template + using ClockDuration = typename Clock::duration; + template + using FloatDuration = std::chrono::duration; + + template + using TimePoint = typename Clock::time_point; + + using default_clock = std::chrono::steady_clock; + + template + struct now { + TimePoint operator()() const { + return Clock::now(); + } + }; + + using fp_seconds = std::chrono::duration>; + } // namespace Benchmark +} // namespace Catch + +// end catch_clock.hpp +// start catch_optimizer.hpp + + // Hinting the optimizer + + +#if defined(_MSC_VER) +# include // atomic_thread_fence +#endif + +namespace Catch { + namespace Benchmark { +#if defined(__GNUC__) || defined(__clang__) + template + inline void keep_memory(T* p) { + asm volatile("" : : "g"(p) : "memory"); + } + inline void keep_memory() { + asm volatile("" : : : "memory"); + } + + namespace Detail { + inline void optimizer_barrier() { keep_memory(); } + } // namespace Detail +#elif defined(_MSC_VER) + +#pragma optimize("", off) + template + inline void keep_memory(T* p) { + // thanks @milleniumbug + *reinterpret_cast(p) = *reinterpret_cast(p); + } + // TODO equivalent keep_memory() +#pragma optimize("", on) + + namespace Detail { + inline void optimizer_barrier() { + std::atomic_thread_fence(std::memory_order_seq_cst); + } + } // namespace Detail + +#endif + + template + inline void deoptimize_value(T&& x) { + keep_memory(&x); + } + + template + inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if::value>::type { + deoptimize_value(std::forward(fn) (std::forward(args...))); + } + + template + inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if::value>::type { + std::forward(fn) (std::forward(args...)); + } + } // namespace Benchmark +} // namespace Catch + +// end catch_optimizer.hpp +// start catch_complete_invoke.hpp + +// Invoke with a special case for void + + +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + struct CompleteType { using type = T; }; + template <> + struct CompleteType { struct type {}; }; + + template + using CompleteType_t = typename CompleteType::type; + + template + struct CompleteInvoker { + template + static Result invoke(Fun&& fun, Args&&... args) { + return std::forward(fun)(std::forward(args)...); + } + }; + template <> + struct CompleteInvoker { + template + static CompleteType_t invoke(Fun&& fun, Args&&... args) { + std::forward(fun)(std::forward(args)...); + return {}; + } + }; + + // invoke and not return void :( + template + CompleteType_t> complete_invoke(Fun&& fun, Args&&... args) { + return CompleteInvoker>::invoke(std::forward(fun), std::forward(args)...); + } + + const std::string benchmarkErrorMsg = "a benchmark failed to run successfully"; + } // namespace Detail + + template + Detail::CompleteType_t> user_code(Fun&& fun) { + CATCH_TRY{ + return Detail::complete_invoke(std::forward(fun)); + } CATCH_CATCH_ALL{ + getResultCapture().benchmarkFailed(translateActiveException()); + CATCH_RUNTIME_ERROR(Detail::benchmarkErrorMsg); + } + } + } // namespace Benchmark +} // namespace Catch + +// end catch_complete_invoke.hpp +namespace Catch { + namespace Benchmark { + namespace Detail { + struct ChronometerConcept { + virtual void start() = 0; + virtual void finish() = 0; + virtual ~ChronometerConcept() = default; + }; + template + struct ChronometerModel final : public ChronometerConcept { + void start() override { started = Clock::now(); } + void finish() override { finished = Clock::now(); } + + ClockDuration elapsed() const { return finished - started; } + + TimePoint started; + TimePoint finished; + }; + } // namespace Detail + + struct Chronometer { + public: + template + void measure(Fun&& fun) { measure(std::forward(fun), is_callable()); } + + int runs() const { return k; } + + Chronometer(Detail::ChronometerConcept& meter, int k) + : impl(&meter) + , k(k) {} + + private: + template + void measure(Fun&& fun, std::false_type) { + measure([&fun](int) { return fun(); }, std::true_type()); + } + + template + void measure(Fun&& fun, std::true_type) { + Detail::optimizer_barrier(); + impl->start(); + for (int i = 0; i < k; ++i) invoke_deoptimized(fun, i); + impl->finish(); + Detail::optimizer_barrier(); + } + + Detail::ChronometerConcept* impl; + int k; + }; + } // namespace Benchmark +} // namespace Catch + +// end catch_chronometer.hpp +// start catch_environment.hpp + +// Environment information + + +namespace Catch { + namespace Benchmark { + template + struct EnvironmentEstimate { + Duration mean; + OutlierClassification outliers; + + template + operator EnvironmentEstimate() const { + return { mean, outliers }; + } + }; + template + struct Environment { + using clock_type = Clock; + EnvironmentEstimate> clock_resolution; + EnvironmentEstimate> clock_cost; + }; + } // namespace Benchmark +} // namespace Catch + +// end catch_environment.hpp +// start catch_execution_plan.hpp + + // Execution plan + + +// start catch_benchmark_function.hpp + + // Dumb std::function implementation for consistent call overhead + + +#include +#include +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + using Decay = typename std::decay::type; + template + struct is_related + : std::is_same, Decay> {}; + + /// We need to reinvent std::function because every piece of code that might add overhead + /// in a measurement context needs to have consistent performance characteristics so that we + /// can account for it in the measurement. + /// Implementations of std::function with optimizations that aren't always applicable, like + /// small buffer optimizations, are not uncommon. + /// This is effectively an implementation of std::function without any such optimizations; + /// it may be slow, but it is consistently slow. + struct BenchmarkFunction { + private: + struct callable { + virtual void call(Chronometer meter) const = 0; + virtual callable* clone() const = 0; + virtual ~callable() = default; + }; + template + struct model : public callable { + model(Fun&& fun) : fun(std::move(fun)) {} + model(Fun const& fun) : fun(fun) {} + + model* clone() const override { return new model(*this); } + + void call(Chronometer meter) const override { + call(meter, is_callable()); + } + void call(Chronometer meter, std::true_type) const { + fun(meter); + } + void call(Chronometer meter, std::false_type) const { + meter.measure(fun); + } + + Fun fun; + }; + + struct do_nothing { void operator()() const {} }; + + template + BenchmarkFunction(model* c) : f(c) {} + + public: + BenchmarkFunction() + : f(new model{ {} }) {} + + template ::value, int>::type = 0> + BenchmarkFunction(Fun&& fun) + : f(new model::type>(std::forward(fun))) {} + + BenchmarkFunction(BenchmarkFunction&& that) + : f(std::move(that.f)) {} + + BenchmarkFunction(BenchmarkFunction const& that) + : f(that.f->clone()) {} + + BenchmarkFunction& operator=(BenchmarkFunction&& that) { + f = std::move(that.f); + return *this; + } + + BenchmarkFunction& operator=(BenchmarkFunction const& that) { + f.reset(that.f->clone()); + return *this; + } + + void operator()(Chronometer meter) const { f->call(meter); } + + private: + std::unique_ptr f; + }; + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_benchmark_function.hpp +// start catch_repeat.hpp + +// repeat algorithm + + +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + struct repeater { + void operator()(int k) const { + for (int i = 0; i < k; ++i) { + fun(); + } + } + Fun fun; + }; + template + repeater::type> repeat(Fun&& fun) { + return { std::forward(fun) }; + } + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_repeat.hpp +// start catch_run_for_at_least.hpp + +// Run a function for a minimum amount of time + + +// start catch_measure.hpp + +// Measure + + +// start catch_timing.hpp + +// Timing + + +#include +#include + +namespace Catch { + namespace Benchmark { + template + struct Timing { + Duration elapsed; + Result result; + int iterations; + }; + template + using TimingOf = Timing, Detail::CompleteType_t>>; + } // namespace Benchmark +} // namespace Catch + +// end catch_timing.hpp +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + TimingOf measure(Fun&& fun, Args&&... args) { + auto start = Clock::now(); + auto&& r = Detail::complete_invoke(fun, std::forward(args)...); + auto end = Clock::now(); + auto delta = end - start; + return { delta, std::forward(r), 1 }; + } + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_measure.hpp +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + TimingOf measure_one(Fun&& fun, int iters, std::false_type) { + return Detail::measure(fun, iters); + } + template + TimingOf measure_one(Fun&& fun, int iters, std::true_type) { + Detail::ChronometerModel meter; + auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters)); + + return { meter.elapsed(), std::move(result), iters }; + } + + template + using run_for_at_least_argument_t = typename std::conditional::value, Chronometer, int>::type; + + struct optimized_away_error : std::exception { + const char* what() const noexcept override { + return "could not measure benchmark, maybe it was optimized away"; + } + }; + + template + TimingOf> run_for_at_least(ClockDuration how_long, int seed, Fun&& fun) { + auto iters = seed; + while (iters < (1 << 30)) { + auto&& Timing = measure_one(fun, iters, is_callable()); + + if (Timing.elapsed >= how_long) { + return { Timing.elapsed, std::move(Timing.result), iters }; + } + iters *= 2; + } + Catch::throw_exception(optimized_away_error{}); + } + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_run_for_at_least.hpp +#include +#include + +namespace Catch { + namespace Benchmark { + template + struct ExecutionPlan { + int iterations_per_sample; + Duration estimated_duration; + Detail::BenchmarkFunction benchmark; + Duration warmup_time; + int warmup_iterations; + + template + operator ExecutionPlan() const { + return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations }; + } + + template + std::vector> run(const IConfig &cfg, Environment> env) const { + // warmup a bit + Detail::run_for_at_least(std::chrono::duration_cast>(warmup_time), warmup_iterations, Detail::repeat(now{})); + + std::vector> times; + times.reserve(cfg.benchmarkSamples()); + std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [this, env] { + Detail::ChronometerModel model; + this->benchmark(Chronometer(model, iterations_per_sample)); + auto sample_time = model.elapsed() - env.clock_cost.mean; + if (sample_time < FloatDuration::zero()) sample_time = FloatDuration::zero(); + return sample_time / iterations_per_sample; + }); + return times; + } + }; + } // namespace Benchmark +} // namespace Catch + +// end catch_execution_plan.hpp +// start catch_estimate_clock.hpp + + // Environment measurement + + +// start catch_stats.hpp + +// Statistical analysis tools + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + using sample = std::vector; + + double weighted_average_quantile(int k, int q, std::vector::iterator first, std::vector::iterator last); + + template + OutlierClassification classify_outliers(Iterator first, Iterator last) { + std::vector copy(first, last); + + auto q1 = weighted_average_quantile(1, 4, copy.begin(), copy.end()); + auto q3 = weighted_average_quantile(3, 4, copy.begin(), copy.end()); + auto iqr = q3 - q1; + auto los = q1 - (iqr * 3.); + auto lom = q1 - (iqr * 1.5); + auto him = q3 + (iqr * 1.5); + auto his = q3 + (iqr * 3.); + + OutlierClassification o; + for (; first != last; ++first) { + auto&& t = *first; + if (t < los) ++o.low_severe; + else if (t < lom) ++o.low_mild; + else if (t > his) ++o.high_severe; + else if (t > him) ++o.high_mild; + ++o.samples_seen; + } + return o; + } + + template + double mean(Iterator first, Iterator last) { + auto count = last - first; + double sum = std::accumulate(first, last, 0.); + return sum / count; + } + + template + sample resample(URng& rng, int resamples, Iterator first, Iterator last, Estimator& estimator) { + auto n = last - first; + std::uniform_int_distribution dist(0, n - 1); + + sample out; + out.reserve(resamples); + std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] { + std::vector resampled; + resampled.reserve(n); + std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; }); + return estimator(resampled.begin(), resampled.end()); + }); + std::sort(out.begin(), out.end()); + return out; + } + + template + sample jackknife(Estimator&& estimator, Iterator first, Iterator last) { + auto n = last - first; + auto second = std::next(first); + sample results; + results.reserve(n); + + for (auto it = first; it != last; ++it) { + std::iter_swap(it, first); + results.push_back(estimator(second, last)); + } + + return results; + } + + inline double normal_cdf(double x) { + return std::erfc(-x / std::sqrt(2.0)) / 2.0; + } + + double erfc_inv(double x); + + double normal_quantile(double p); + + template + Estimate bootstrap(double confidence_level, Iterator first, Iterator last, sample const& resample, Estimator&& estimator) { + auto n_samples = last - first; + + double point = estimator(first, last); + // Degenerate case with a single sample + if (n_samples == 1) return { point, point, point, confidence_level }; + + sample jack = jackknife(estimator, first, last); + double jack_mean = mean(jack.begin(), jack.end()); + double sum_squares, sum_cubes; + std::tie(sum_squares, sum_cubes) = std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), [jack_mean](std::pair sqcb, double x) -> std::pair { + auto d = jack_mean - x; + auto d2 = d * d; + auto d3 = d2 * d; + return { sqcb.first + d2, sqcb.second + d3 }; + }); + + double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5)); + int n = static_cast(resample.size()); + double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n; + // degenerate case with uniform samples + if (prob_n == 0) return { point, point, point, confidence_level }; + + double bias = normal_quantile(prob_n); + double z1 = normal_quantile((1. - confidence_level) / 2.); + + auto cumn = [n](double x) -> int { + return std::lround(normal_cdf(x) * n); }; + auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); }; + double b1 = bias + z1; + double b2 = bias - z1; + double a1 = a(b1); + double a2 = a(b2); + auto lo = (std::max)(cumn(a1), 0); + auto hi = (std::min)(cumn(a2), n - 1); + + return { point, resample[lo], resample[hi], confidence_level }; + } + + double outlier_variance(Estimate mean, Estimate stddev, int n); + + struct bootstrap_analysis { + Estimate mean; + Estimate standard_deviation; + double outlier_variance; + }; + + bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector::iterator first, std::vector::iterator last); + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_stats.hpp +#include +#include +#include +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + std::vector resolution(int k) { + std::vector> times; + times.reserve(k + 1); + std::generate_n(std::back_inserter(times), k + 1, now{}); + + std::vector deltas; + deltas.reserve(k); + std::transform(std::next(times.begin()), times.end(), times.begin(), + std::back_inserter(deltas), + [](TimePoint a, TimePoint b) { return static_cast((a - b).count()); }); + + return deltas; + } + + const auto warmup_iterations = 10000; + const auto warmup_time = std::chrono::milliseconds(100); + const auto minimum_ticks = 1000; + const auto warmup_seed = 10000; + const auto clock_resolution_estimation_time = std::chrono::milliseconds(500); + const auto clock_cost_estimation_time_limit = std::chrono::seconds(1); + const auto clock_cost_estimation_tick_limit = 100000; + const auto clock_cost_estimation_time = std::chrono::milliseconds(10); + const auto clock_cost_estimation_iterations = 10000; + + template + int warmup() { + return run_for_at_least(std::chrono::duration_cast>(warmup_time), warmup_seed, &resolution) + .iterations; + } + template + EnvironmentEstimate> estimate_clock_resolution(int iterations) { + auto r = run_for_at_least(std::chrono::duration_cast>(clock_resolution_estimation_time), iterations, &resolution) + .result; + return { + FloatDuration(mean(r.begin(), r.end())), + classify_outliers(r.begin(), r.end()), + }; + } + template + EnvironmentEstimate> estimate_clock_cost(FloatDuration resolution) { + auto time_limit = (std::min)( + resolution * clock_cost_estimation_tick_limit, + FloatDuration(clock_cost_estimation_time_limit)); + auto time_clock = [](int k) { + return Detail::measure([k] { + for (int i = 0; i < k; ++i) { + volatile auto ignored = Clock::now(); + (void)ignored; + } + }).elapsed; + }; + time_clock(1); + int iters = clock_cost_estimation_iterations; + auto&& r = run_for_at_least(std::chrono::duration_cast>(clock_cost_estimation_time), iters, time_clock); + std::vector times; + int nsamples = static_cast(std::ceil(time_limit / r.elapsed)); + times.reserve(nsamples); + std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] { + return static_cast((time_clock(r.iterations) / r.iterations).count()); + }); + return { + FloatDuration(mean(times.begin(), times.end())), + classify_outliers(times.begin(), times.end()), + }; + } + + template + Environment> measure_environment() { + static Environment>* env = nullptr; + if (env) { + return *env; + } + + auto iters = Detail::warmup(); + auto resolution = Detail::estimate_clock_resolution(iters); + auto cost = Detail::estimate_clock_cost(resolution.mean); + + env = new Environment>{ resolution, cost }; + return *env; + } + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_estimate_clock.hpp +// start catch_analyse.hpp + + // Run and analyse one benchmark + + +// start catch_sample_analysis.hpp + +// Benchmark results + + +#include +#include +#include +#include + +namespace Catch { + namespace Benchmark { + template + struct SampleAnalysis { + std::vector samples; + Estimate mean; + Estimate standard_deviation; + OutlierClassification outliers; + double outlier_variance; + + template + operator SampleAnalysis() const { + std::vector samples2; + samples2.reserve(samples.size()); + std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); }); + return { + std::move(samples2), + mean, + standard_deviation, + outliers, + outlier_variance, + }; + } + }; + } // namespace Benchmark +} // namespace Catch + +// end catch_sample_analysis.hpp +#include +#include +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + SampleAnalysis analyse(const IConfig &cfg, Environment, Iterator first, Iterator last) { + if (!cfg.benchmarkNoAnalysis()) { + std::vector samples; + samples.reserve(last - first); + std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); }); + + auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end()); + auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end()); + + auto wrap_estimate = [](Estimate e) { + return Estimate { + Duration(e.point), + Duration(e.lower_bound), + Duration(e.upper_bound), + e.confidence_interval, + }; + }; + std::vector samples2; + samples2.reserve(samples.size()); + std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); }); + return { + std::move(samples2), + wrap_estimate(analysis.mean), + wrap_estimate(analysis.standard_deviation), + outliers, + analysis.outlier_variance, + }; + } else { + std::vector samples; + samples.reserve(last - first); + + Duration mean = Duration(0); + int i = 0; + for (auto it = first; it < last; ++it, ++i) { + samples.push_back(Duration(*it)); + mean += Duration(*it); + } + mean /= i; + + return { + std::move(samples), + Estimate{mean, mean, mean, 0.0}, + Estimate{Duration(0), Duration(0), Duration(0), 0.0}, + OutlierClassification{}, + 0.0 + }; + } + } + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +// end catch_analyse.hpp +#include +#include +#include +#include +#include + +namespace Catch { + namespace Benchmark { + struct Benchmark { + Benchmark(std::string &&name) + : name(std::move(name)) {} + + template + Benchmark(std::string &&name, FUN &&func) + : fun(std::move(func)), name(std::move(name)) {} + + template + ExecutionPlan> prepare(const IConfig &cfg, Environment> env) const { + auto min_time = env.clock_resolution.mean * Detail::minimum_ticks; + auto run_time = std::max(min_time, std::chrono::duration_cast(cfg.benchmarkWarmupTime())); + auto&& test = Detail::run_for_at_least(std::chrono::duration_cast>(run_time), 1, fun); + int new_iters = static_cast(std::ceil(min_time * test.iterations / test.elapsed)); + return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations }; + } + + template + void run() { + IConfigPtr cfg = getCurrentContext().getConfig(); + + auto env = Detail::measure_environment(); + + getResultCapture().benchmarkPreparing(name); + CATCH_TRY{ + auto plan = user_code([&] { + return prepare(*cfg, env); + }); + + BenchmarkInfo info { + name, + plan.estimated_duration.count(), + plan.iterations_per_sample, + cfg->benchmarkSamples(), + cfg->benchmarkResamples(), + env.clock_resolution.mean.count(), + env.clock_cost.mean.count() + }; + + getResultCapture().benchmarkStarting(info); + + auto samples = user_code([&] { + return plan.template run(*cfg, env); + }); + + auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end()); + BenchmarkStats> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; + getResultCapture().benchmarkEnded(stats); + + } CATCH_CATCH_ALL{ + if (translateActiveException() != Detail::benchmarkErrorMsg) // benchmark errors have been reported, otherwise rethrow. + std::rethrow_exception(std::current_exception()); + } + } + + // sets lambda to be used in fun *and* executes benchmark! + template ::value, int>::type = 0> + Benchmark & operator=(Fun func) { + fun = Detail::BenchmarkFunction(func); + run(); + return *this; + } + + explicit operator bool() { + return true; + } + + private: + Detail::BenchmarkFunction fun; + std::string name; + }; + } +} // namespace Catch + +#define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1 +#define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2 + +#define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\ + if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ + BenchmarkName = [&](int benchmarkIndex) + +#define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\ + if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ + BenchmarkName = [&] + +// end catch_benchmark.hpp +// start catch_constructor.hpp + +// Constructor and destructor helpers + + +#include + +namespace Catch { + namespace Benchmark { + namespace Detail { + template + struct ObjectStorage + { + ObjectStorage() : data() {} + + ObjectStorage(const ObjectStorage& other) + { + new(&data) T(other.stored_object()); + } + + ObjectStorage(ObjectStorage&& other) + { + new(&data) T(std::move(other.stored_object())); + } + + ~ObjectStorage() { destruct_on_exit(); } + + template + void construct(Args&&... args) + { + new (&data) T(std::forward(args)...); + } + + template + typename std::enable_if::type destruct() + { + stored_object().~T(); + } + + private: + // If this is a constructor benchmark, destruct the underlying object + template + void destruct_on_exit(typename std::enable_if::type* = 0) { destruct(); } + // Otherwise, don't + template + void destruct_on_exit(typename std::enable_if::type* = 0) { } + + T& stored_object() { + return *static_cast(static_cast(&data)); + } + + T const& stored_object() const { + return *static_cast(static_cast(&data)); + } + + struct { alignas(T) unsigned char data[sizeof(T)]; } data; + }; + } + + template + using storage_for = Detail::ObjectStorage; + + template + using destructable_object = Detail::ObjectStorage; + } +} + +// end catch_constructor.hpp +// end catch_benchmarking_all.hpp +#endif + +#endif // ! CATCH_CONFIG_IMPL_ONLY + +#ifdef CATCH_IMPL +// start catch_impl.hpp + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + +// Keep these here for external reporters +// start catch_test_case_tracker.h + +#include +#include +#include + +namespace Catch { +namespace TestCaseTracking { + + struct NameAndLocation { + std::string name; + SourceLineInfo location; + + NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); + friend bool operator==(NameAndLocation const& lhs, NameAndLocation const& rhs) { + return lhs.name == rhs.name + && lhs.location == rhs.location; + } + }; + + class ITracker; + + using ITrackerPtr = std::shared_ptr; + + class ITracker { + NameAndLocation m_nameAndLocation; + + public: + ITracker(NameAndLocation const& nameAndLoc) : + m_nameAndLocation(nameAndLoc) + {} + + // static queries + NameAndLocation const& nameAndLocation() const { + return m_nameAndLocation; + } + + virtual ~ITracker(); + + // dynamic queries + virtual bool isComplete() const = 0; // Successfully completed or failed + virtual bool isSuccessfullyCompleted() const = 0; + virtual bool isOpen() const = 0; // Started but not complete + virtual bool hasChildren() const = 0; + virtual bool hasStarted() const = 0; + + virtual ITracker& parent() = 0; + + // actions + virtual void close() = 0; // Successfully complete + virtual void fail() = 0; + virtual void markAsNeedingAnotherRun() = 0; + + virtual void addChild( ITrackerPtr const& child ) = 0; + virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; + virtual void openChild() = 0; + + // Debug/ checking + virtual bool isSectionTracker() const = 0; + virtual bool isGeneratorTracker() const = 0; + }; + + class TrackerContext { + + enum RunState { + NotStarted, + Executing, + CompletedCycle + }; + + ITrackerPtr m_rootTracker; + ITracker* m_currentTracker = nullptr; + RunState m_runState = NotStarted; + + public: + + ITracker& startRun(); + void endRun(); + + void startCycle(); + void completeCycle(); + + bool completedCycle() const; + ITracker& currentTracker(); + void setCurrentTracker( ITracker* tracker ); + }; + + class TrackerBase : public ITracker { + protected: + enum CycleState { + NotStarted, + Executing, + ExecutingChildren, + NeedsAnotherRun, + CompletedSuccessfully, + Failed + }; + + using Children = std::vector; + TrackerContext& m_ctx; + ITracker* m_parent; + Children m_children; + CycleState m_runState = NotStarted; + + public: + TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + + bool isComplete() const override; + bool isSuccessfullyCompleted() const override; + bool isOpen() const override; + bool hasChildren() const override; + bool hasStarted() const override { + return m_runState != NotStarted; + } + + void addChild( ITrackerPtr const& child ) override; + + ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; + ITracker& parent() override; + + void openChild() override; + + bool isSectionTracker() const override; + bool isGeneratorTracker() const override; + + void open(); + + void close() override; + void fail() override; + void markAsNeedingAnotherRun() override; + + private: + void moveToParent(); + void moveToThis(); + }; + + class SectionTracker : public TrackerBase { + std::vector m_filters; + std::string m_trimmed_name; + public: + SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + + bool isSectionTracker() const override; + + bool isComplete() const override; + + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); + + void tryOpen(); + + void addInitialFilters( std::vector const& filters ); + void addNextFilters( std::vector const& filters ); + //! Returns filters active in this tracker + std::vector const& getFilters() const; + //! Returns whitespace-trimmed name of the tracked section + std::string const& trimmedName() const; + }; + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; + +} // namespace Catch + +// end catch_test_case_tracker.h + +// start catch_leak_detector.h + +namespace Catch { + + struct LeakDetector { + LeakDetector(); + ~LeakDetector(); + }; + +} +// end catch_leak_detector.h +// Cpp files will be included in the single-header file here +// start catch_stats.cpp + +// Statistical analysis tools + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + +#include +#include + +#if defined(CATCH_CONFIG_USE_ASYNC) +#include +#endif + +namespace { + double erf_inv(double x) { + // Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2 + double w, p; + + w = -log((1.0 - x) * (1.0 + x)); + + if (w < 6.250000) { + w = w - 3.125000; + p = -3.6444120640178196996e-21; + p = -1.685059138182016589e-19 + p * w; + p = 1.2858480715256400167e-18 + p * w; + p = 1.115787767802518096e-17 + p * w; + p = -1.333171662854620906e-16 + p * w; + p = 2.0972767875968561637e-17 + p * w; + p = 6.6376381343583238325e-15 + p * w; + p = -4.0545662729752068639e-14 + p * w; + p = -8.1519341976054721522e-14 + p * w; + p = 2.6335093153082322977e-12 + p * w; + p = -1.2975133253453532498e-11 + p * w; + p = -5.4154120542946279317e-11 + p * w; + p = 1.051212273321532285e-09 + p * w; + p = -4.1126339803469836976e-09 + p * w; + p = -2.9070369957882005086e-08 + p * w; + p = 4.2347877827932403518e-07 + p * w; + p = -1.3654692000834678645e-06 + p * w; + p = -1.3882523362786468719e-05 + p * w; + p = 0.0001867342080340571352 + p * w; + p = -0.00074070253416626697512 + p * w; + p = -0.0060336708714301490533 + p * w; + p = 0.24015818242558961693 + p * w; + p = 1.6536545626831027356 + p * w; + } else if (w < 16.000000) { + w = sqrt(w) - 3.250000; + p = 2.2137376921775787049e-09; + p = 9.0756561938885390979e-08 + p * w; + p = -2.7517406297064545428e-07 + p * w; + p = 1.8239629214389227755e-08 + p * w; + p = 1.5027403968909827627e-06 + p * w; + p = -4.013867526981545969e-06 + p * w; + p = 2.9234449089955446044e-06 + p * w; + p = 1.2475304481671778723e-05 + p * w; + p = -4.7318229009055733981e-05 + p * w; + p = 6.8284851459573175448e-05 + p * w; + p = 2.4031110387097893999e-05 + p * w; + p = -0.0003550375203628474796 + p * w; + p = 0.00095328937973738049703 + p * w; + p = -0.0016882755560235047313 + p * w; + p = 0.0024914420961078508066 + p * w; + p = -0.0037512085075692412107 + p * w; + p = 0.005370914553590063617 + p * w; + p = 1.0052589676941592334 + p * w; + p = 3.0838856104922207635 + p * w; + } else { + w = sqrt(w) - 5.000000; + p = -2.7109920616438573243e-11; + p = -2.5556418169965252055e-10 + p * w; + p = 1.5076572693500548083e-09 + p * w; + p = -3.7894654401267369937e-09 + p * w; + p = 7.6157012080783393804e-09 + p * w; + p = -1.4960026627149240478e-08 + p * w; + p = 2.9147953450901080826e-08 + p * w; + p = -6.7711997758452339498e-08 + p * w; + p = 2.2900482228026654717e-07 + p * w; + p = -9.9298272942317002539e-07 + p * w; + p = 4.5260625972231537039e-06 + p * w; + p = -1.9681778105531670567e-05 + p * w; + p = 7.5995277030017761139e-05 + p * w; + p = -0.00021503011930044477347 + p * w; + p = -0.00013871931833623122026 + p * w; + p = 1.0103004648645343977 + p * w; + p = 4.8499064014085844221 + p * w; + } + return p * x; + } + + double standard_deviation(std::vector::iterator first, std::vector::iterator last) { + auto m = Catch::Benchmark::Detail::mean(first, last); + double variance = std::accumulate(first, last, 0., [m](double a, double b) { + double diff = b - m; + return a + diff * diff; + }) / (last - first); + return std::sqrt(variance); + } + +} + +namespace Catch { + namespace Benchmark { + namespace Detail { + + double weighted_average_quantile(int k, int q, std::vector::iterator first, std::vector::iterator last) { + auto count = last - first; + double idx = (count - 1) * k / static_cast(q); + int j = static_cast(idx); + double g = idx - j; + std::nth_element(first, first + j, last); + auto xj = first[j]; + if (g == 0) return xj; + + auto xj1 = *std::min_element(first + (j + 1), last); + return xj + g * (xj1 - xj); + } + + double erfc_inv(double x) { + return erf_inv(1.0 - x); + } + + double normal_quantile(double p) { + static const double ROOT_TWO = std::sqrt(2.0); + + double result = 0.0; + assert(p >= 0 && p <= 1); + if (p < 0 || p > 1) { + return result; + } + + result = -erfc_inv(2.0 * p); + // result *= normal distribution standard deviation (1.0) * sqrt(2) + result *= /*sd * */ ROOT_TWO; + // result += normal disttribution mean (0) + return result; + } + + double outlier_variance(Estimate mean, Estimate stddev, int n) { + double sb = stddev.point; + double mn = mean.point / n; + double mg_min = mn / 2.; + double sg = (std::min)(mg_min / 4., sb / std::sqrt(n)); + double sg2 = sg * sg; + double sb2 = sb * sb; + + auto c_max = [n, mn, sb2, sg2](double x) -> double { + double k = mn - x; + double d = k * k; + double nd = n * d; + double k0 = -n * nd; + double k1 = sb2 - n * sg2 + nd; + double det = k1 * k1 - 4 * sg2 * k0; + return (int)(-2. * k0 / (k1 + std::sqrt(det))); + }; + + auto var_out = [n, sb2, sg2](double c) { + double nc = n - c; + return (nc / n) * (sb2 - nc * sg2); + }; + + return (std::min)(var_out(1), var_out((std::min)(c_max(0.), c_max(mg_min)))) / sb2; + } + + bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector::iterator first, std::vector::iterator last) { + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS + static std::random_device entropy; + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + + auto n = static_cast(last - first); // seriously, one can't use integral types without hell in C++ + + auto mean = &Detail::mean::iterator>; + auto stddev = &standard_deviation; + +#if defined(CATCH_CONFIG_USE_ASYNC) + auto Estimate = [=](double(*f)(std::vector::iterator, std::vector::iterator)) { + auto seed = entropy(); + return std::async(std::launch::async, [=] { + std::mt19937 rng(seed); + auto resampled = resample(rng, n_resamples, first, last, f); + return bootstrap(confidence_level, first, last, resampled, f); + }); + }; + + auto mean_future = Estimate(mean); + auto stddev_future = Estimate(stddev); + + auto mean_estimate = mean_future.get(); + auto stddev_estimate = stddev_future.get(); +#else + auto Estimate = [=](double(*f)(std::vector::iterator, std::vector::iterator)) { + auto seed = entropy(); + std::mt19937 rng(seed); + auto resampled = resample(rng, n_resamples, first, last, f); + return bootstrap(confidence_level, first, last, resampled, f); + }; + + auto mean_estimate = Estimate(mean); + auto stddev_estimate = Estimate(stddev); +#endif // CATCH_USE_ASYNC + + double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n); + + return { mean_estimate, stddev_estimate, outlier_variance }; + } + } // namespace Detail + } // namespace Benchmark +} // namespace Catch + +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING +// end catch_stats.cpp +// start catch_approx.cpp + +#include +#include + +namespace { + +// Performs equivalent check of std::fabs(lhs - rhs) <= margin +// But without the subtraction to allow for INFINITY in comparison +bool marginComparison(double lhs, double rhs, double margin) { + return (lhs + margin >= rhs) && (rhs + margin >= lhs); +} + +} + +namespace Catch { +namespace Detail { + + Approx::Approx ( double value ) + : m_epsilon( std::numeric_limits::epsilon()*100 ), + m_margin( 0.0 ), + m_scale( 0.0 ), + m_value( value ) + {} + + Approx Approx::custom() { + return Approx( 0 ); + } + + Approx Approx::operator-() const { + auto temp(*this); + temp.m_value = -temp.m_value; + return temp; + } + + std::string Approx::toString() const { + ReusableStringStream rss; + rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; + return rss.str(); + } + + bool Approx::equalityComparisonImpl(const double other) const { + // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value + // Thanks to Richard Harris for his help refining the scaled margin value + return marginComparison(m_value, other, m_margin) + || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value))); + } + + void Approx::setMargin(double newMargin) { + CATCH_ENFORCE(newMargin >= 0, + "Invalid Approx::margin: " << newMargin << '.' + << " Approx::Margin has to be non-negative."); + m_margin = newMargin; + } + + void Approx::setEpsilon(double newEpsilon) { + CATCH_ENFORCE(newEpsilon >= 0 && newEpsilon <= 1.0, + "Invalid Approx::epsilon: " << newEpsilon << '.' + << " Approx::epsilon has to be in [0, 1]"); + m_epsilon = newEpsilon; + } + +} // end namespace Detail + +namespace literals { + Detail::Approx operator "" _a(long double val) { + return Detail::Approx(val); + } + Detail::Approx operator "" _a(unsigned long long val) { + return Detail::Approx(val); + } +} // end namespace literals + +std::string StringMaker::convert(Catch::Detail::Approx const& value) { + return value.toString(); +} + +} // end namespace Catch +// end catch_approx.cpp +// start catch_assertionhandler.cpp + +// start catch_debugger.h + +namespace Catch { + bool isDebuggerActive(); +} + +#ifdef CATCH_PLATFORM_MAC + + #if defined(__i386__) || defined(__x86_64__) + #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ + #elif defined(__aarch64__) + #define CATCH_TRAP() __asm__(".inst 0xd43e0000") + #endif + +#elif defined(CATCH_PLATFORM_IPHONE) + + // use inline assembler + #if defined(__i386__) || defined(__x86_64__) + #define CATCH_TRAP() __asm__("int $3") + #elif defined(__aarch64__) + #define CATCH_TRAP() __asm__(".inst 0xd4200000") + #elif defined(__arm__) && !defined(__thumb__) + #define CATCH_TRAP() __asm__(".inst 0xe7f001f0") + #elif defined(__arm__) && defined(__thumb__) + #define CATCH_TRAP() __asm__(".inst 0xde01") + #endif + +#elif defined(CATCH_PLATFORM_LINUX) + // If we can use inline assembler, do it because this allows us to break + // directly at the location of the failing check instead of breaking inside + // raise() called from it, i.e. one stack frame below. + #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) + #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ + #else // Fall back to the generic way. + #include + + #define CATCH_TRAP() raise(SIGTRAP) + #endif +#elif defined(_MSC_VER) + #define CATCH_TRAP() __debugbreak() +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) void __stdcall DebugBreak(); + #define CATCH_TRAP() DebugBreak() +#endif + +#ifndef CATCH_BREAK_INTO_DEBUGGER + #ifdef CATCH_TRAP + #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() + #else + #define CATCH_BREAK_INTO_DEBUGGER() []{}() + #endif +#endif + +// end catch_debugger.h +// start catch_run_context.h + +// start catch_fatal_condition.h + +#include + +namespace Catch { + + // Wrapper for platform-specific fatal error (signals/SEH) handlers + // + // Tries to be cooperative with other handlers, and not step over + // other handlers. This means that unknown structured exceptions + // are passed on, previous signal handlers are called, and so on. + // + // Can only be instantiated once, and assumes that once a signal + // is caught, the binary will end up terminating. Thus, there + class FatalConditionHandler { + bool m_started = false; + + // Install/disengage implementation for specific platform. + // Should be if-defed to work on current platform, can assume + // engage-disengage 1:1 pairing. + void engage_platform(); + void disengage_platform(); + public: + // Should also have platform-specific implementations as needed + FatalConditionHandler(); + ~FatalConditionHandler(); + + void engage() { + assert(!m_started && "Handler cannot be installed twice."); + m_started = true; + engage_platform(); + } + + void disengage() { + assert(m_started && "Handler cannot be uninstalled without being installed first"); + m_started = false; + disengage_platform(); + } + }; + + //! Simple RAII guard for (dis)engaging the FatalConditionHandler + class FatalConditionHandlerGuard { + FatalConditionHandler* m_handler; + public: + FatalConditionHandlerGuard(FatalConditionHandler* handler): + m_handler(handler) { + m_handler->engage(); + } + ~FatalConditionHandlerGuard() { + m_handler->disengage(); + } + }; + +} // end namespace Catch + +// end catch_fatal_condition.h +#include + +namespace Catch { + + struct IMutableContext; + + /////////////////////////////////////////////////////////////////////////// + + class RunContext : public IResultCapture, public IRunner { + + public: + RunContext( RunContext const& ) = delete; + RunContext& operator =( RunContext const& ) = delete; + + explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter ); + + ~RunContext() override; + + void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ); + void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ); + + Totals runTest(TestCase const& testCase); + + IConfigPtr config() const; + IStreamingReporter& reporter() const; + + public: // IResultCapture + + // Assertion handlers + void handleExpr + ( AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction ) override; + void handleMessage + ( AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction ) override; + void handleUnexpectedExceptionNotThrown + ( AssertionInfo const& info, + AssertionReaction& reaction ) override; + void handleUnexpectedInflightException + ( AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction ) override; + void handleIncomplete + ( AssertionInfo const& info ) override; + void handleNonExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction ) override; + + bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; + + void sectionEnded( SectionEndInfo const& endInfo ) override; + void sectionEndedEarly( SectionEndInfo const& endInfo ) override; + + auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override; + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void benchmarkPreparing( std::string const& name ) override; + void benchmarkStarting( BenchmarkInfo const& info ) override; + void benchmarkEnded( BenchmarkStats<> const& stats ) override; + void benchmarkFailed( std::string const& error ) override; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + void pushScopedMessage( MessageInfo const& message ) override; + void popScopedMessage( MessageInfo const& message ) override; + + void emplaceUnscopedMessage( MessageBuilder const& builder ) override; + + std::string getCurrentTestName() const override; + + const AssertionResult* getLastResult() const override; + + void exceptionEarlyReported() override; + + void handleFatalErrorCondition( StringRef message ) override; + + bool lastAssertionPassed() override; + + void assertionPassed() override; + + public: + // !TBD We need to do this another way! + bool aborting() const final; + + private: + + void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ); + void invokeActiveTestCase(); + + void resetAssertionInfo(); + bool testForMissingAssertions( Counts& assertions ); + + void assertionEnded( AssertionResult const& result ); + void reportExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + ITransientExpression const *expr, + bool negated ); + + void populateReaction( AssertionReaction& reaction ); + + private: + + void handleUnfinishedSections(); + + TestRunInfo m_runInfo; + IMutableContext& m_context; + TestCase const* m_activeTestCase = nullptr; + ITracker* m_testCaseTracker = nullptr; + Option m_lastResult; + + IConfigPtr m_config; + Totals m_totals; + IStreamingReporterPtr m_reporter; + std::vector m_messages; + std::vector m_messageScopes; /* Keeps owners of so-called unscoped messages. */ + AssertionInfo m_lastAssertionInfo; + std::vector m_unfinishedSections; + std::vector m_activeSections; + TrackerContext m_trackerContext; + FatalConditionHandler m_fatalConditionhandler; + bool m_lastAssertionPassed = false; + bool m_shouldReportUnexpected = true; + bool m_includeSuccessfulResults; + }; + + void seedRng(IConfig const& config); + unsigned int rngSeed(); +} // end namespace Catch + +// end catch_run_context.h +namespace Catch { + + namespace { + auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { + expr.streamReconstructedExpression( os ); + return os; + } + } + + LazyExpression::LazyExpression( bool isNegated ) + : m_isNegated( isNegated ) + {} + + LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} + + LazyExpression::operator bool() const { + return m_transientExpression != nullptr; + } + + auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { + if( lazyExpr.m_isNegated ) + os << "!"; + + if( lazyExpr ) { + if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) + os << "(" << *lazyExpr.m_transientExpression << ")"; + else + os << *lazyExpr.m_transientExpression; + } + else { + os << "{** error - unchecked empty expression requested **}"; + } + return os; + } + + AssertionHandler::AssertionHandler + ( StringRef const& macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ) + : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }, + m_resultCapture( getResultCapture() ) + {} + + void AssertionHandler::handleExpr( ITransientExpression const& expr ) { + m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction ); + } + void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) { + m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction ); + } + + auto AssertionHandler::allowThrows() const -> bool { + return getCurrentContext().getConfig()->allowThrows(); + } + + void AssertionHandler::complete() { + setCompleted(); + if( m_reaction.shouldDebugBreak ) { + + // If you find your debugger stopping you here then go one level up on the + // call-stack for the code that caused it (typically a failed assertion) + + // (To go back to the test and change execution, jump over the throw, next) + CATCH_BREAK_INTO_DEBUGGER(); + } + if (m_reaction.shouldThrow) { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + throw Catch::TestFailureException(); +#else + CATCH_ERROR( "Test failure requires aborting test!" ); +#endif + } + } + void AssertionHandler::setCompleted() { + m_completed = true; + } + + void AssertionHandler::handleUnexpectedInflightException() { + m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction ); + } + + void AssertionHandler::handleExceptionThrownAsExpected() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + void AssertionHandler::handleExceptionNotThrownAsExpected() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + + void AssertionHandler::handleUnexpectedExceptionNotThrown() { + m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); + } + + void AssertionHandler::handleThrowingCallSkipped() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + + // This is the overload that takes a string and infers the Equals matcher from it + // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) { + handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); + } + +} // namespace Catch +// end catch_assertionhandler.cpp +// start catch_assertionresult.cpp + +namespace Catch { + AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): + lazyExpression(_lazyExpression), + resultType(_resultType) {} + + std::string AssertionResultData::reconstructExpression() const { + + if( reconstructedExpression.empty() ) { + if( lazyExpression ) { + ReusableStringStream rss; + rss << lazyExpression; + reconstructedExpression = rss.str(); + } + } + return reconstructedExpression; + } + + AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) + : m_info( info ), + m_resultData( data ) + {} + + // Result was a success + bool AssertionResult::succeeded() const { + return Catch::isOk( m_resultData.resultType ); + } + + // Result was a success, or failure is suppressed + bool AssertionResult::isOk() const { + return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); + } + + ResultWas::OfType AssertionResult::getResultType() const { + return m_resultData.resultType; + } + + bool AssertionResult::hasExpression() const { + return !m_info.capturedExpression.empty(); + } + + bool AssertionResult::hasMessage() const { + return !m_resultData.message.empty(); + } + + std::string AssertionResult::getExpression() const { + // Possibly overallocating by 3 characters should be basically free + std::string expr; expr.reserve(m_info.capturedExpression.size() + 3); + if (isFalseTest(m_info.resultDisposition)) { + expr += "!("; + } + expr += m_info.capturedExpression; + if (isFalseTest(m_info.resultDisposition)) { + expr += ')'; + } + return expr; + } + + std::string AssertionResult::getExpressionInMacro() const { + std::string expr; + if( m_info.macroName.empty() ) + expr = static_cast(m_info.capturedExpression); + else { + expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); + expr += m_info.macroName; + expr += "( "; + expr += m_info.capturedExpression; + expr += " )"; + } + return expr; + } + + bool AssertionResult::hasExpandedExpression() const { + return hasExpression() && getExpandedExpression() != getExpression(); + } + + std::string AssertionResult::getExpandedExpression() const { + std::string expr = m_resultData.reconstructExpression(); + return expr.empty() + ? getExpression() + : expr; + } + + std::string AssertionResult::getMessage() const { + return m_resultData.message; + } + SourceLineInfo AssertionResult::getSourceInfo() const { + return m_info.lineInfo; + } + + StringRef AssertionResult::getTestMacroName() const { + return m_info.macroName; + } + +} // end namespace Catch +// end catch_assertionresult.cpp +// start catch_capture_matchers.cpp + +namespace Catch { + + using StringMatcher = Matchers::Impl::MatcherBase; + + // This is the general overload that takes a any string matcher + // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers + // the Equals matcher (so the header does not mention matchers) + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) { + std::string exceptionMessage = Catch::translateActiveException(); + MatchExpr expr( exceptionMessage, matcher, matcherString ); + handler.handleExpr( expr ); + } + +} // namespace Catch +// end catch_capture_matchers.cpp +// start catch_commandline.cpp + +// start catch_commandline.h + +// start catch_clara.h + +// Use Catch's value for console width (store Clara's off to the side, if present) +#ifdef CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#endif +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wexit-time-destructors" +#pragma clang diagnostic ignored "-Wshadow" +#endif + +// start clara.hpp +// Copyright 2017 Two Blue Cubes Ltd. All rights reserved. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See https://github.com/philsquared/Clara for more details + +// Clara v1.1.5 + + +#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 +#endif + +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +#ifndef CLARA_CONFIG_OPTIONAL_TYPE +#ifdef __has_include +#if __has_include() && __cplusplus >= 201703L +#include +#define CLARA_CONFIG_OPTIONAL_TYPE std::optional +#endif +#endif +#endif + +// ----------- #included from clara_textflow.hpp ----------- + +// TextFlowCpp +// +// A single-header library for wrapping and laying out basic text, by Phil Nash +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// This project is hosted at https://github.com/philsquared/textflowcpp + + +#include +#include +#include +#include + +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { +namespace clara { +namespace TextFlow { + +inline auto isWhitespace(char c) -> bool { + static std::string chars = " \t\n\r"; + return chars.find(c) != std::string::npos; +} +inline auto isBreakableBefore(char c) -> bool { + static std::string chars = "[({<|"; + return chars.find(c) != std::string::npos; +} +inline auto isBreakableAfter(char c) -> bool { + static std::string chars = "])}>.,:;*+-=&/\\"; + return chars.find(c) != std::string::npos; +} + +class Columns; + +class Column { + std::vector m_strings; + size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; + size_t m_indent = 0; + size_t m_initialIndent = std::string::npos; + +public: + class iterator { + friend Column; + + Column const& m_column; + size_t m_stringIndex = 0; + size_t m_pos = 0; + + size_t m_len = 0; + size_t m_end = 0; + bool m_suffix = false; + + iterator(Column const& column, size_t stringIndex) + : m_column(column), + m_stringIndex(stringIndex) {} + + auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } + + auto isBoundary(size_t at) const -> bool { + assert(at > 0); + assert(at <= line().size()); + + return at == line().size() || + (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) || + isBreakableBefore(line()[at]) || + isBreakableAfter(line()[at - 1]); + } + + void calcLength() { + assert(m_stringIndex < m_column.m_strings.size()); + + m_suffix = false; + auto width = m_column.m_width - indent(); + m_end = m_pos; + if (line()[m_pos] == '\n') { + ++m_end; + } + while (m_end < line().size() && line()[m_end] != '\n') + ++m_end; + + if (m_end < m_pos + width) { + m_len = m_end - m_pos; + } else { + size_t len = width; + while (len > 0 && !isBoundary(m_pos + len)) + --len; + while (len > 0 && isWhitespace(line()[m_pos + len - 1])) + --len; + + if (len > 0) { + m_len = len; + } else { + m_suffix = true; + m_len = width - 1; + } + } + } + + auto indent() const -> size_t { + auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; + return initial == std::string::npos ? m_column.m_indent : initial; + } + + auto addIndentAndSuffix(std::string const &plain) const -> std::string { + return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain); + } + + public: + using difference_type = std::ptrdiff_t; + using value_type = std::string; + using pointer = value_type * ; + using reference = value_type & ; + using iterator_category = std::forward_iterator_tag; + + explicit iterator(Column const& column) : m_column(column) { + assert(m_column.m_width > m_column.m_indent); + assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent); + calcLength(); + if (m_len == 0) + m_stringIndex++; // Empty string + } + + auto operator *() const -> std::string { + assert(m_stringIndex < m_column.m_strings.size()); + assert(m_pos <= m_end); + return addIndentAndSuffix(line().substr(m_pos, m_len)); + } + + auto operator ++() -> iterator& { + m_pos += m_len; + if (m_pos < line().size() && line()[m_pos] == '\n') + m_pos += 1; + else + while (m_pos < line().size() && isWhitespace(line()[m_pos])) + ++m_pos; + + if (m_pos == line().size()) { + m_pos = 0; + ++m_stringIndex; + } + if (m_stringIndex < m_column.m_strings.size()) + calcLength(); + return *this; + } + auto operator ++(int) -> iterator { + iterator prev(*this); + operator++(); + return prev; + } + + auto operator ==(iterator const& other) const -> bool { + return + m_pos == other.m_pos && + m_stringIndex == other.m_stringIndex && + &m_column == &other.m_column; + } + auto operator !=(iterator const& other) const -> bool { + return !operator==(other); + } + }; + using const_iterator = iterator; + + explicit Column(std::string const& text) { m_strings.push_back(text); } + + auto width(size_t newWidth) -> Column& { + assert(newWidth > 0); + m_width = newWidth; + return *this; + } + auto indent(size_t newIndent) -> Column& { + m_indent = newIndent; + return *this; + } + auto initialIndent(size_t newIndent) -> Column& { + m_initialIndent = newIndent; + return *this; + } + + auto width() const -> size_t { return m_width; } + auto begin() const -> iterator { return iterator(*this); } + auto end() const -> iterator { return { *this, m_strings.size() }; } + + inline friend std::ostream& operator << (std::ostream& os, Column const& col) { + bool first = true; + for (auto line : col) { + if (first) + first = false; + else + os << "\n"; + os << line; + } + return os; + } + + auto operator + (Column const& other)->Columns; + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } +}; + +class Spacer : public Column { + +public: + explicit Spacer(size_t spaceWidth) : Column("") { + width(spaceWidth); + } +}; + +class Columns { + std::vector m_columns; + +public: + + class iterator { + friend Columns; + struct EndTag {}; + + std::vector const& m_columns; + std::vector m_iterators; + size_t m_activeIterators; + + iterator(Columns const& columns, EndTag) + : m_columns(columns.m_columns), + m_activeIterators(0) { + m_iterators.reserve(m_columns.size()); + + for (auto const& col : m_columns) + m_iterators.push_back(col.end()); + } + + public: + using difference_type = std::ptrdiff_t; + using value_type = std::string; + using pointer = value_type * ; + using reference = value_type & ; + using iterator_category = std::forward_iterator_tag; + + explicit iterator(Columns const& columns) + : m_columns(columns.m_columns), + m_activeIterators(m_columns.size()) { + m_iterators.reserve(m_columns.size()); + + for (auto const& col : m_columns) + m_iterators.push_back(col.begin()); + } + + auto operator ==(iterator const& other) const -> bool { + return m_iterators == other.m_iterators; + } + auto operator !=(iterator const& other) const -> bool { + return m_iterators != other.m_iterators; + } + auto operator *() const -> std::string { + std::string row, padding; + + for (size_t i = 0; i < m_columns.size(); ++i) { + auto width = m_columns[i].width(); + if (m_iterators[i] != m_columns[i].end()) { + std::string col = *m_iterators[i]; + row += padding + col; + if (col.size() < width) + padding = std::string(width - col.size(), ' '); + else + padding = ""; + } else { + padding += std::string(width, ' '); + } + } + return row; + } + auto operator ++() -> iterator& { + for (size_t i = 0; i < m_columns.size(); ++i) { + if (m_iterators[i] != m_columns[i].end()) + ++m_iterators[i]; + } + return *this; + } + auto operator ++(int) -> iterator { + iterator prev(*this); + operator++(); + return prev; + } + }; + using const_iterator = iterator; + + auto begin() const -> iterator { return iterator(*this); } + auto end() const -> iterator { return { *this, iterator::EndTag() }; } + + auto operator += (Column const& col) -> Columns& { + m_columns.push_back(col); + return *this; + } + auto operator + (Column const& col) -> Columns { + Columns combined = *this; + combined += col; + return combined; + } + + inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) { + + bool first = true; + for (auto line : cols) { + if (first) + first = false; + else + os << "\n"; + os << line; + } + return os; + } + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } +}; + +inline auto Column::operator + (Column const& other) -> Columns { + Columns cols; + cols += *this; + cols += other; + return cols; +} +} + +} +} + +// ----------- end of #include from clara_textflow.hpp ----------- +// ........... back in clara.hpp + +#include +#include +#include +#include +#include + +#if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) +#define CATCH_PLATFORM_WINDOWS +#endif + +namespace Catch { namespace clara { +namespace detail { + + // Traits for extracting arg and return type of lambdas (for single argument lambdas) + template + struct UnaryLambdaTraits : UnaryLambdaTraits {}; + + template + struct UnaryLambdaTraits { + static const bool isValid = false; + }; + + template + struct UnaryLambdaTraits { + static const bool isValid = true; + using ArgType = typename std::remove_const::type>::type; + using ReturnType = ReturnT; + }; + + class TokenStream; + + // Transport for raw args (copied from main args, or supplied via init list for testing) + class Args { + friend TokenStream; + std::string m_exeName; + std::vector m_args; + + public: + Args( int argc, char const* const* argv ) + : m_exeName(argv[0]), + m_args(argv + 1, argv + argc) {} + + Args( std::initializer_list args ) + : m_exeName( *args.begin() ), + m_args( args.begin()+1, args.end() ) + {} + + auto exeName() const -> std::string { + return m_exeName; + } + }; + + // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string + // may encode an option + its argument if the : or = form is used + enum class TokenType { + Option, Argument + }; + struct Token { + TokenType type; + std::string token; + }; + + inline auto isOptPrefix( char c ) -> bool { + return c == '-' +#ifdef CATCH_PLATFORM_WINDOWS + || c == '/' +#endif + ; + } + + // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled + class TokenStream { + using Iterator = std::vector::const_iterator; + Iterator it; + Iterator itEnd; + std::vector m_tokenBuffer; + + void loadBuffer() { + m_tokenBuffer.resize( 0 ); + + // Skip any empty strings + while( it != itEnd && it->empty() ) + ++it; + + if( it != itEnd ) { + auto const &next = *it; + if( isOptPrefix( next[0] ) ) { + auto delimiterPos = next.find_first_of( " :=" ); + if( delimiterPos != std::string::npos ) { + m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); + m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); + } else { + if( next[1] != '-' && next.size() > 2 ) { + std::string opt = "- "; + for( size_t i = 1; i < next.size(); ++i ) { + opt[1] = next[i]; + m_tokenBuffer.push_back( { TokenType::Option, opt } ); + } + } else { + m_tokenBuffer.push_back( { TokenType::Option, next } ); + } + } + } else { + m_tokenBuffer.push_back( { TokenType::Argument, next } ); + } + } + } + + public: + explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} + + TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { + loadBuffer(); + } + + explicit operator bool() const { + return !m_tokenBuffer.empty() || it != itEnd; + } + + auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } + + auto operator*() const -> Token { + assert( !m_tokenBuffer.empty() ); + return m_tokenBuffer.front(); + } + + auto operator->() const -> Token const * { + assert( !m_tokenBuffer.empty() ); + return &m_tokenBuffer.front(); + } + + auto operator++() -> TokenStream & { + if( m_tokenBuffer.size() >= 2 ) { + m_tokenBuffer.erase( m_tokenBuffer.begin() ); + } else { + if( it != itEnd ) + ++it; + loadBuffer(); + } + return *this; + } + }; + + class ResultBase { + public: + enum Type { + Ok, LogicError, RuntimeError + }; + + protected: + ResultBase( Type type ) : m_type( type ) {} + virtual ~ResultBase() = default; + + virtual void enforceOk() const = 0; + + Type m_type; + }; + + template + class ResultValueBase : public ResultBase { + public: + auto value() const -> T const & { + enforceOk(); + return m_value; + } + + protected: + ResultValueBase( Type type ) : ResultBase( type ) {} + + ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + } + + ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { + new( &m_value ) T( value ); + } + + auto operator=( ResultValueBase const &other ) -> ResultValueBase & { + if( m_type == ResultBase::Ok ) + m_value.~T(); + ResultBase::operator=(other); + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + return *this; + } + + ~ResultValueBase() override { + if( m_type == Ok ) + m_value.~T(); + } + + union { + T m_value; + }; + }; + + template<> + class ResultValueBase : public ResultBase { + protected: + using ResultBase::ResultBase; + }; + + template + class BasicResult : public ResultValueBase { + public: + template + explicit BasicResult( BasicResult const &other ) + : ResultValueBase( other.type() ), + m_errorMessage( other.errorMessage() ) + { + assert( type() != ResultBase::Ok ); + } + + template + static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } + static auto ok() -> BasicResult { return { ResultBase::Ok }; } + static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } + static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } + + explicit operator bool() const { return m_type == ResultBase::Ok; } + auto type() const -> ResultBase::Type { return m_type; } + auto errorMessage() const -> std::string { return m_errorMessage; } + + protected: + void enforceOk() const override { + + // Errors shouldn't reach this point, but if they do + // the actual error message will be in m_errorMessage + assert( m_type != ResultBase::LogicError ); + assert( m_type != ResultBase::RuntimeError ); + if( m_type != ResultBase::Ok ) + std::abort(); + } + + std::string m_errorMessage; // Only populated if resultType is an error + + BasicResult( ResultBase::Type type, std::string const &message ) + : ResultValueBase(type), + m_errorMessage(message) + { + assert( m_type != ResultBase::Ok ); + } + + using ResultValueBase::ResultValueBase; + using ResultBase::m_type; + }; + + enum class ParseResultType { + Matched, NoMatch, ShortCircuitAll, ShortCircuitSame + }; + + class ParseState { + public: + + ParseState( ParseResultType type, TokenStream const &remainingTokens ) + : m_type(type), + m_remainingTokens( remainingTokens ) + {} + + auto type() const -> ParseResultType { return m_type; } + auto remainingTokens() const -> TokenStream { return m_remainingTokens; } + + private: + ParseResultType m_type; + TokenStream m_remainingTokens; + }; + + using Result = BasicResult; + using ParserResult = BasicResult; + using InternalParseResult = BasicResult; + + struct HelpColumns { + std::string left; + std::string right; + }; + + template + inline auto convertInto( std::string const &source, T& target ) -> ParserResult { + std::stringstream ss; + ss << source; + ss >> target; + if( ss.fail() ) + return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); + else + return ParserResult::ok( ParseResultType::Matched ); + } + inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { + target = source; + return ParserResult::ok( ParseResultType::Matched ); + } + inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { + std::string srcLC = source; + std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( unsigned char c ) { return static_cast( std::tolower(c) ); } ); + if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") + target = true; + else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") + target = false; + else + return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + } +#ifdef CLARA_CONFIG_OPTIONAL_TYPE + template + inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE& target ) -> ParserResult { + T temp; + auto result = convertInto( source, temp ); + if( result ) + target = std::move(temp); + return result; + } +#endif // CLARA_CONFIG_OPTIONAL_TYPE + + struct NonCopyable { + NonCopyable() = default; + NonCopyable( NonCopyable const & ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable &operator=( NonCopyable const & ) = delete; + NonCopyable &operator=( NonCopyable && ) = delete; + }; + + struct BoundRef : NonCopyable { + virtual ~BoundRef() = default; + virtual auto isContainer() const -> bool { return false; } + virtual auto isFlag() const -> bool { return false; } + }; + struct BoundValueRefBase : BoundRef { + virtual auto setValue( std::string const &arg ) -> ParserResult = 0; + }; + struct BoundFlagRefBase : BoundRef { + virtual auto setFlag( bool flag ) -> ParserResult = 0; + virtual auto isFlag() const -> bool { return true; } + }; + + template + struct BoundValueRef : BoundValueRefBase { + T &m_ref; + + explicit BoundValueRef( T &ref ) : m_ref( ref ) {} + + auto setValue( std::string const &arg ) -> ParserResult override { + return convertInto( arg, m_ref ); + } + }; + + template + struct BoundValueRef> : BoundValueRefBase { + std::vector &m_ref; + + explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} + + auto isContainer() const -> bool override { return true; } + + auto setValue( std::string const &arg ) -> ParserResult override { + T temp; + auto result = convertInto( arg, temp ); + if( result ) + m_ref.push_back( temp ); + return result; + } + }; + + struct BoundFlagRef : BoundFlagRefBase { + bool &m_ref; + + explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} + + auto setFlag( bool flag ) -> ParserResult override { + m_ref = flag; + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + template + struct LambdaInvoker { + static_assert( std::is_same::value, "Lambda must return void or clara::ParserResult" ); + + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + return lambda( arg ); + } + }; + + template<> + struct LambdaInvoker { + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + lambda( arg ); + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + template + inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { + ArgType temp{}; + auto result = convertInto( arg, temp ); + return !result + ? result + : LambdaInvoker::ReturnType>::invoke( lambda, temp ); + } + + template + struct BoundLambda : BoundValueRefBase { + L m_lambda; + + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} + + auto setValue( std::string const &arg ) -> ParserResult override { + return invokeLambda::ArgType>( m_lambda, arg ); + } + }; + + template + struct BoundFlagLambda : BoundFlagRefBase { + L m_lambda; + + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + static_assert( std::is_same::ArgType, bool>::value, "flags must be boolean" ); + + explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} + + auto setFlag( bool flag ) -> ParserResult override { + return LambdaInvoker::ReturnType>::invoke( m_lambda, flag ); + } + }; + + enum class Optionality { Optional, Required }; + + struct Parser; + + class ParserBase { + public: + virtual ~ParserBase() = default; + virtual auto validate() const -> Result { return Result::ok(); } + virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; + virtual auto cardinality() const -> size_t { return 1; } + + auto parse( Args const &args ) const -> InternalParseResult { + return parse( args.exeName(), TokenStream( args ) ); + } + }; + + template + class ComposableParserImpl : public ParserBase { + public: + template + auto operator|( T const &other ) const -> Parser; + + template + auto operator+( T const &other ) const -> Parser; + }; + + // Common code and state for Args and Opts + template + class ParserRefImpl : public ComposableParserImpl { + protected: + Optionality m_optionality = Optionality::Optional; + std::shared_ptr m_ref; + std::string m_hint; + std::string m_description; + + explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} + + public: + template + ParserRefImpl( T &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint( hint ) + {} + + template + ParserRefImpl( LambdaT const &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint(hint) + {} + + auto operator()( std::string const &description ) -> DerivedT & { + m_description = description; + return static_cast( *this ); + } + + auto optional() -> DerivedT & { + m_optionality = Optionality::Optional; + return static_cast( *this ); + }; + + auto required() -> DerivedT & { + m_optionality = Optionality::Required; + return static_cast( *this ); + }; + + auto isOptional() const -> bool { + return m_optionality == Optionality::Optional; + } + + auto cardinality() const -> size_t override { + if( m_ref->isContainer() ) + return 0; + else + return 1; + } + + auto hint() const -> std::string { return m_hint; } + }; + + class ExeName : public ComposableParserImpl { + std::shared_ptr m_name; + std::shared_ptr m_ref; + + template + static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { + return std::make_shared>( lambda) ; + } + + public: + ExeName() : m_name( std::make_shared( "" ) ) {} + + explicit ExeName( std::string &ref ) : ExeName() { + m_ref = std::make_shared>( ref ); + } + + template + explicit ExeName( LambdaT const& lambda ) : ExeName() { + m_ref = std::make_shared>( lambda ); + } + + // The exe name is not parsed out of the normal tokens, but is handled specially + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + } + + auto name() const -> std::string { return *m_name; } + auto set( std::string const& newName ) -> ParserResult { + + auto lastSlash = newName.find_last_of( "\\/" ); + auto filename = ( lastSlash == std::string::npos ) + ? newName + : newName.substr( lastSlash+1 ); + + *m_name = filename; + if( m_ref ) + return m_ref->setValue( filename ); + else + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + class Arg : public ParserRefImpl { + public: + using ParserRefImpl::ParserRefImpl; + + auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + auto const &token = *remainingTokens; + if( token.type != TokenType::Argument ) + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + + assert( !m_ref->isFlag() ); + auto valueRef = static_cast( m_ref.get() ); + + auto result = valueRef->setValue( remainingTokens->token ); + if( !result ) + return InternalParseResult( result ); + else + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + }; + + inline auto normaliseOpt( std::string const &optName ) -> std::string { +#ifdef CATCH_PLATFORM_WINDOWS + if( optName[0] == '/' ) + return "-" + optName.substr( 1 ); + else +#endif + return optName; + } + + class Opt : public ParserRefImpl { + protected: + std::vector m_optNames; + + public: + template + explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared>( ref ) ) {} + + explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared( ref ) ) {} + + template + Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + template + Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + auto operator[]( std::string const &optName ) -> Opt & { + m_optNames.push_back( optName ); + return *this; + } + + auto getHelpColumns() const -> std::vector { + std::ostringstream oss; + bool first = true; + for( auto const &opt : m_optNames ) { + if (first) + first = false; + else + oss << ", "; + oss << opt; + } + if( !m_hint.empty() ) + oss << " <" << m_hint << ">"; + return { { oss.str(), m_description } }; + } + + auto isMatch( std::string const &optToken ) const -> bool { + auto normalisedToken = normaliseOpt( optToken ); + for( auto const &name : m_optNames ) { + if( normaliseOpt( name ) == normalisedToken ) + return true; + } + return false; + } + + using ParserBase::parse; + + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + if( remainingTokens && remainingTokens->type == TokenType::Option ) { + auto const &token = *remainingTokens; + if( isMatch(token.token ) ) { + if( m_ref->isFlag() ) { + auto flagRef = static_cast( m_ref.get() ); + auto result = flagRef->setFlag( true ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } else { + auto valueRef = static_cast( m_ref.get() ); + ++remainingTokens; + if( !remainingTokens ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto const &argToken = *remainingTokens; + if( argToken.type != TokenType::Argument ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto result = valueRef->setValue( argToken.token ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + } + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + } + + auto validate() const -> Result override { + if( m_optNames.empty() ) + return Result::logicError( "No options supplied to Opt" ); + for( auto const &name : m_optNames ) { + if( name.empty() ) + return Result::logicError( "Option name cannot be empty" ); +#ifdef CATCH_PLATFORM_WINDOWS + if( name[0] != '-' && name[0] != '/' ) + return Result::logicError( "Option name must begin with '-' or '/'" ); +#else + if( name[0] != '-' ) + return Result::logicError( "Option name must begin with '-'" ); +#endif + } + return ParserRefImpl::validate(); + } + }; + + struct Help : Opt { + Help( bool &showHelpFlag ) + : Opt([&]( bool flag ) { + showHelpFlag = flag; + return ParserResult::ok( ParseResultType::ShortCircuitAll ); + }) + { + static_cast( *this ) + ("display usage information") + ["-?"]["-h"]["--help"] + .optional(); + } + }; + + struct Parser : ParserBase { + + mutable ExeName m_exeName; + std::vector m_options; + std::vector m_args; + + auto operator|=( ExeName const &exeName ) -> Parser & { + m_exeName = exeName; + return *this; + } + + auto operator|=( Arg const &arg ) -> Parser & { + m_args.push_back(arg); + return *this; + } + + auto operator|=( Opt const &opt ) -> Parser & { + m_options.push_back(opt); + return *this; + } + + auto operator|=( Parser const &other ) -> Parser & { + m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); + m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); + return *this; + } + + template + auto operator|( T const &other ) const -> Parser { + return Parser( *this ) |= other; + } + + // Forward deprecated interface with '+' instead of '|' + template + auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } + template + auto operator+( T const &other ) const -> Parser { return operator|( other ); } + + auto getHelpColumns() const -> std::vector { + std::vector cols; + for (auto const &o : m_options) { + auto childCols = o.getHelpColumns(); + cols.insert( cols.end(), childCols.begin(), childCols.end() ); + } + return cols; + } + + void writeToStream( std::ostream &os ) const { + if (!m_exeName.name().empty()) { + os << "usage:\n" << " " << m_exeName.name() << " "; + bool required = true, first = true; + for( auto const &arg : m_args ) { + if (first) + first = false; + else + os << " "; + if( arg.isOptional() && required ) { + os << "["; + required = false; + } + os << "<" << arg.hint() << ">"; + if( arg.cardinality() == 0 ) + os << " ... "; + } + if( !required ) + os << "]"; + if( !m_options.empty() ) + os << " options"; + os << "\n\nwhere options are:" << std::endl; + } + + auto rows = getHelpColumns(); + size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; + size_t optWidth = 0; + for( auto const &cols : rows ) + optWidth = (std::max)(optWidth, cols.left.size() + 2); + + optWidth = (std::min)(optWidth, consoleWidth/2); + + for( auto const &cols : rows ) { + auto row = + TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + + TextFlow::Spacer(4) + + TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); + os << row << std::endl; + } + } + + friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { + parser.writeToStream( os ); + return os; + } + + auto validate() const -> Result override { + for( auto const &opt : m_options ) { + auto result = opt.validate(); + if( !result ) + return result; + } + for( auto const &arg : m_args ) { + auto result = arg.validate(); + if( !result ) + return result; + } + return Result::ok(); + } + + using ParserBase::parse; + + auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { + + struct ParserInfo { + ParserBase const* parser = nullptr; + size_t count = 0; + }; + const size_t totalParsers = m_options.size() + m_args.size(); + assert( totalParsers < 512 ); + // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do + ParserInfo parseInfos[512]; + + { + size_t i = 0; + for (auto const &opt : m_options) parseInfos[i++].parser = &opt; + for (auto const &arg : m_args) parseInfos[i++].parser = &arg; + } + + m_exeName.set( exeName ); + + auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + while( result.value().remainingTokens() ) { + bool tokenParsed = false; + + for( size_t i = 0; i < totalParsers; ++i ) { + auto& parseInfo = parseInfos[i]; + if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { + result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); + if (!result) + return result; + if (result.value().type() != ParseResultType::NoMatch) { + tokenParsed = true; + ++parseInfo.count; + break; + } + } + } + + if( result.value().type() == ParseResultType::ShortCircuitAll ) + return result; + if( !tokenParsed ) + return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); + } + // !TBD Check missing required options + return result; + } + }; + + template + template + auto ComposableParserImpl::operator|( T const &other ) const -> Parser { + return Parser() | static_cast( *this ) | other; + } +} // namespace detail + +// A Combined parser +using detail::Parser; + +// A parser for options +using detail::Opt; + +// A parser for arguments +using detail::Arg; + +// Wrapper for argc, argv from main() +using detail::Args; + +// Specifies the name of the executable +using detail::ExeName; + +// Convenience wrapper for option parser that specifies the help option +using detail::Help; + +// enum of result types from a parse +using detail::ParseResultType; + +// Result type for parser operation +using detail::ParserResult; + +}} // namespace Catch::clara + +// end clara.hpp +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// Restore Clara's value for console width, if present +#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +// end catch_clara.h +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ); + +} // end namespace Catch + +// end catch_commandline.h +#include +#include + +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ) { + + using namespace clara; + + auto const setWarning = [&]( std::string const& warning ) { + auto warningSet = [&]() { + if( warning == "NoAssertions" ) + return WarnAbout::NoAssertions; + + if ( warning == "NoTests" ) + return WarnAbout::NoTests; + + return WarnAbout::Nothing; + }(); + + if (warningSet == WarnAbout::Nothing) + return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); + config.warnings = static_cast( config.warnings | warningSet ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const loadTestNamesFromFile = [&]( std::string const& filename ) { + std::ifstream f( filename.c_str() ); + if( !f.is_open() ) + return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); + + std::string line; + while( std::getline( f, line ) ) { + line = trim(line); + if( !line.empty() && !startsWith( line, '#' ) ) { + if( !startsWith( line, '"' ) ) + line = '"' + line + '"'; + config.testsOrTags.push_back( line ); + config.testsOrTags.emplace_back( "," ); + } + } + //Remove comma in the end + if(!config.testsOrTags.empty()) + config.testsOrTags.erase( config.testsOrTags.end()-1 ); + + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setTestOrder = [&]( std::string const& order ) { + if( startsWith( "declared", order ) ) + config.runOrder = RunTests::InDeclarationOrder; + else if( startsWith( "lexical", order ) ) + config.runOrder = RunTests::InLexicographicalOrder; + else if( startsWith( "random", order ) ) + config.runOrder = RunTests::InRandomOrder; + else + return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setRngSeed = [&]( std::string const& seed ) { + if( seed != "time" ) + return clara::detail::convertInto( seed, config.rngSeed ); + config.rngSeed = static_cast( std::time(nullptr) ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setColourUsage = [&]( std::string const& useColour ) { + auto mode = toLower( useColour ); + + if( mode == "yes" ) + config.useColour = UseColour::Yes; + else if( mode == "no" ) + config.useColour = UseColour::No; + else if( mode == "auto" ) + config.useColour = UseColour::Auto; + else + return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setWaitForKeypress = [&]( std::string const& keypress ) { + auto keypressLc = toLower( keypress ); + if (keypressLc == "never") + config.waitForKeypress = WaitForKeypress::Never; + else if( keypressLc == "start" ) + config.waitForKeypress = WaitForKeypress::BeforeStart; + else if( keypressLc == "exit" ) + config.waitForKeypress = WaitForKeypress::BeforeExit; + else if( keypressLc == "both" ) + config.waitForKeypress = WaitForKeypress::BeforeStartAndExit; + else + return ParserResult::runtimeError( "keypress argument must be one of: never, start, exit or both. '" + keypress + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setVerbosity = [&]( std::string const& verbosity ) { + auto lcVerbosity = toLower( verbosity ); + if( lcVerbosity == "quiet" ) + config.verbosity = Verbosity::Quiet; + else if( lcVerbosity == "normal" ) + config.verbosity = Verbosity::Normal; + else if( lcVerbosity == "high" ) + config.verbosity = Verbosity::High; + else + return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setReporter = [&]( std::string const& reporter ) { + IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); + + auto lcReporter = toLower( reporter ); + auto result = factories.find( lcReporter ); + + if( factories.end() != result ) + config.reporterName = lcReporter; + else + return ParserResult::runtimeError( "Unrecognized reporter, '" + reporter + "'. Check available with --list-reporters" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + + auto cli + = ExeName( config.processName ) + | Help( config.showHelp ) + | Opt( config.listTests ) + ["-l"]["--list-tests"] + ( "list all/matching test cases" ) + | Opt( config.listTags ) + ["-t"]["--list-tags"] + ( "list all/matching tags" ) + | Opt( config.showSuccessfulTests ) + ["-s"]["--success"] + ( "include successful tests in output" ) + | Opt( config.shouldDebugBreak ) + ["-b"]["--break"] + ( "break into debugger on failure" ) + | Opt( config.noThrow ) + ["-e"]["--nothrow"] + ( "skip exception tests" ) + | Opt( config.showInvisibles ) + ["-i"]["--invisibles"] + ( "show invisibles (tabs, newlines)" ) + | Opt( config.outputFilename, "filename" ) + ["-o"]["--out"] + ( "output filename" ) + | Opt( setReporter, "name" ) + ["-r"]["--reporter"] + ( "reporter to use (defaults to console)" ) + | Opt( config.name, "name" ) + ["-n"]["--name"] + ( "suite name" ) + | Opt( [&]( bool ){ config.abortAfter = 1; } ) + ["-a"]["--abort"] + ( "abort at first failure" ) + | Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) + ["-x"]["--abortx"] + ( "abort after x failures" ) + | Opt( setWarning, "warning name" ) + ["-w"]["--warn"] + ( "enable warnings" ) + | Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" ) + ["-d"]["--durations"] + ( "show test durations" ) + | Opt( config.minDuration, "seconds" ) + ["-D"]["--min-duration"] + ( "show test durations for tests taking at least the given number of seconds" ) + | Opt( loadTestNamesFromFile, "filename" ) + ["-f"]["--input-file"] + ( "load test names to run from a file" ) + | Opt( config.filenamesAsTags ) + ["-#"]["--filenames-as-tags"] + ( "adds a tag for the filename" ) + | Opt( config.sectionsToRun, "section name" ) + ["-c"]["--section"] + ( "specify section to run" ) + | Opt( setVerbosity, "quiet|normal|high" ) + ["-v"]["--verbosity"] + ( "set output verbosity" ) + | Opt( config.listTestNamesOnly ) + ["--list-test-names-only"] + ( "list all/matching test cases names only" ) + | Opt( config.listReporters ) + ["--list-reporters"] + ( "list all reporters" ) + | Opt( setTestOrder, "decl|lex|rand" ) + ["--order"] + ( "test case order (defaults to decl)" ) + | Opt( setRngSeed, "'time'|number" ) + ["--rng-seed"] + ( "set a specific seed for random numbers" ) + | Opt( setColourUsage, "yes|no" ) + ["--use-colour"] + ( "should output be colourised" ) + | Opt( config.libIdentify ) + ["--libidentify"] + ( "report name and version according to libidentify standard" ) + | Opt( setWaitForKeypress, "never|start|exit|both" ) + ["--wait-for-keypress"] + ( "waits for a keypress before exiting" ) + | Opt( config.benchmarkSamples, "samples" ) + ["--benchmark-samples"] + ( "number of samples to collect (default: 100)" ) + | Opt( config.benchmarkResamples, "resamples" ) + ["--benchmark-resamples"] + ( "number of resamples for the bootstrap (default: 100000)" ) + | Opt( config.benchmarkConfidenceInterval, "confidence interval" ) + ["--benchmark-confidence-interval"] + ( "confidence interval for the bootstrap (between 0 and 1, default: 0.95)" ) + | Opt( config.benchmarkNoAnalysis ) + ["--benchmark-no-analysis"] + ( "perform only measurements; do not perform any analysis" ) + | Opt( config.benchmarkWarmupTime, "benchmarkWarmupTime" ) + ["--benchmark-warmup-time"] + ( "amount of time in milliseconds spent on warming up each test (default: 100)" ) + | Arg( config.testsOrTags, "test name|pattern|tags" ) + ( "which test or tests to use" ); + + return cli; + } + +} // end namespace Catch +// end catch_commandline.cpp +// start catch_common.cpp + +#include +#include + +namespace Catch { + + bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept { + return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); + } + bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { + // We can assume that the same file will usually have the same pointer. + // Thus, if the pointers are the same, there is no point in calling the strcmp + return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0)); + } + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { +#ifndef __GNUG__ + os << info.file << '(' << info.line << ')'; +#else + os << info.file << ':' << info.line; +#endif + return os; + } + + std::string StreamEndStop::operator+() const { + return std::string(); + } + + NonCopyable::NonCopyable() = default; + NonCopyable::~NonCopyable() = default; + +} +// end catch_common.cpp +// start catch_config.cpp + +namespace Catch { + + Config::Config( ConfigData const& data ) + : m_data( data ), + m_stream( openStream() ) + { + // We need to trim filter specs to avoid trouble with superfluous + // whitespace (esp. important for bdd macros, as those are manually + // aligned with whitespace). + + for (auto& elem : m_data.testsOrTags) { + elem = trim(elem); + } + for (auto& elem : m_data.sectionsToRun) { + elem = trim(elem); + } + + TestSpecParser parser(ITagAliasRegistry::get()); + if (!m_data.testsOrTags.empty()) { + m_hasTestFilters = true; + for (auto const& testOrTags : m_data.testsOrTags) { + parser.parse(testOrTags); + } + } + m_testSpec = parser.testSpec(); + } + + std::string const& Config::getFilename() const { + return m_data.outputFilename ; + } + + bool Config::listTests() const { return m_data.listTests; } + bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; } + bool Config::listTags() const { return m_data.listTags; } + bool Config::listReporters() const { return m_data.listReporters; } + + std::string Config::getProcessName() const { return m_data.processName; } + std::string const& Config::getReporterName() const { return m_data.reporterName; } + + std::vector const& Config::getTestsOrTags() const { return m_data.testsOrTags; } + std::vector const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } + + TestSpec const& Config::testSpec() const { return m_testSpec; } + bool Config::hasTestFilters() const { return m_hasTestFilters; } + + bool Config::showHelp() const { return m_data.showHelp; } + + // IConfig interface + bool Config::allowThrows() const { return !m_data.noThrow; } + std::ostream& Config::stream() const { return m_stream->stream(); } + std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } + bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; } + bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); } + bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); } + ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } + double Config::minDuration() const { return m_data.minDuration; } + RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } + unsigned int Config::rngSeed() const { return m_data.rngSeed; } + UseColour::YesOrNo Config::useColour() const { return m_data.useColour; } + bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; } + int Config::abortAfter() const { return m_data.abortAfter; } + bool Config::showInvisibles() const { return m_data.showInvisibles; } + Verbosity Config::verbosity() const { return m_data.verbosity; } + + bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; } + int Config::benchmarkSamples() const { return m_data.benchmarkSamples; } + double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; } + unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; } + std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); } + + IStream const* Config::openStream() { + return Catch::makeStream(m_data.outputFilename); + } + +} // end namespace Catch +// end catch_config.cpp +// start catch_console_colour.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +// start catch_errno_guard.h + +namespace Catch { + + class ErrnoGuard { + public: + ErrnoGuard(); + ~ErrnoGuard(); + private: + int m_oldErrno; + }; + +} + +// end catch_errno_guard.h +// start catch_windows_h_proxy.h + + +#if defined(CATCH_PLATFORM_WINDOWS) + +#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINED_NOMINMAX +# define NOMINMAX +#endif +#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __AFXDLL +#include +#else +#include +#endif + +#ifdef CATCH_DEFINED_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + +#endif // defined(CATCH_PLATFORM_WINDOWS) + +// end catch_windows_h_proxy.h +#include + +namespace Catch { + namespace { + + struct IColourImpl { + virtual ~IColourImpl() = default; + virtual void use( Colour::Code _colourCode ) = 0; + }; + + struct NoColourImpl : IColourImpl { + void use( Colour::Code ) override {} + + static IColourImpl* instance() { + static NoColourImpl s_instance; + return &s_instance; + } + }; + + } // anon namespace +} // namespace Catch + +#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) +# ifdef CATCH_PLATFORM_WINDOWS +# define CATCH_CONFIG_COLOUR_WINDOWS +# else +# define CATCH_CONFIG_COLOUR_ANSI +# endif +#endif + +#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// + +namespace Catch { +namespace { + + class Win32ColourImpl : public IColourImpl { + public: + Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) + { + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); + originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); + originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); + } + + void use( Colour::Code _colourCode ) override { + switch( _colourCode ) { + case Colour::None: return setTextAttribute( originalForegroundAttributes ); + case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::Red: return setTextAttribute( FOREGROUND_RED ); + case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); + case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); + case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); + case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); + case Colour::Grey: return setTextAttribute( 0 ); + + case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); + case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); + case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); + case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::BrightYellow: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN ); + + case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + + default: + CATCH_ERROR( "Unknown colour requested" ); + } + } + + private: + void setTextAttribute( WORD _textAttribute ) { + SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); + } + HANDLE stdoutHandle; + WORD originalForegroundAttributes; + WORD originalBackgroundAttributes; + }; + + IColourImpl* platformColourInstance() { + static Win32ColourImpl s_instance; + + IConfigPtr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = UseColour::Yes; + return colourMode == UseColour::Yes + ? &s_instance + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// + +#include + +namespace Catch { +namespace { + + // use POSIX/ ANSI console terminal codes + // Thanks to Adam Strzelecki for original contribution + // (http://github.com/nanoant) + // https://github.com/philsquared/Catch/pull/131 + class PosixColourImpl : public IColourImpl { + public: + void use( Colour::Code _colourCode ) override { + switch( _colourCode ) { + case Colour::None: + case Colour::White: return setColour( "[0m" ); + case Colour::Red: return setColour( "[0;31m" ); + case Colour::Green: return setColour( "[0;32m" ); + case Colour::Blue: return setColour( "[0;34m" ); + case Colour::Cyan: return setColour( "[0;36m" ); + case Colour::Yellow: return setColour( "[0;33m" ); + case Colour::Grey: return setColour( "[1;30m" ); + + case Colour::LightGrey: return setColour( "[0;37m" ); + case Colour::BrightRed: return setColour( "[1;31m" ); + case Colour::BrightGreen: return setColour( "[1;32m" ); + case Colour::BrightWhite: return setColour( "[1;37m" ); + case Colour::BrightYellow: return setColour( "[1;33m" ); + + case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + default: CATCH_INTERNAL_ERROR( "Unknown colour requested" ); + } + } + static IColourImpl* instance() { + static PosixColourImpl s_instance; + return &s_instance; + } + + private: + void setColour( const char* _escapeCode ) { + getCurrentContext().getConfig()->stream() + << '\033' << _escapeCode; + } + }; + + bool useColourOnPlatform() { + return +#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE) + !isDebuggerActive() && +#endif +#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__)) + isatty(STDOUT_FILENO) +#else + false +#endif + ; + } + IColourImpl* platformColourInstance() { + ErrnoGuard guard; + IConfigPtr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = useColourOnPlatform() + ? UseColour::Yes + : UseColour::No; + return colourMode == UseColour::Yes + ? PosixColourImpl::instance() + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#else // not Windows or ANSI /////////////////////////////////////////////// + +namespace Catch { + + static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } + +} // end namespace Catch + +#endif // Windows/ ANSI/ None + +namespace Catch { + + Colour::Colour( Code _colourCode ) { use( _colourCode ); } + Colour::Colour( Colour&& other ) noexcept { + m_moved = other.m_moved; + other.m_moved = true; + } + Colour& Colour::operator=( Colour&& other ) noexcept { + m_moved = other.m_moved; + other.m_moved = true; + return *this; + } + + Colour::~Colour(){ if( !m_moved ) use( None ); } + + void Colour::use( Code _colourCode ) { + static IColourImpl* impl = platformColourInstance(); + // Strictly speaking, this cannot possibly happen. + // However, under some conditions it does happen (see #1626), + // and this change is small enough that we can let practicality + // triumph over purity in this case. + if (impl != nullptr) { + impl->use( _colourCode ); + } + } + + std::ostream& operator << ( std::ostream& os, Colour const& ) { + return os; + } + +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +// end catch_console_colour.cpp +// start catch_context.cpp + +namespace Catch { + + class Context : public IMutableContext, NonCopyable { + + public: // IContext + IResultCapture* getResultCapture() override { + return m_resultCapture; + } + IRunner* getRunner() override { + return m_runner; + } + + IConfigPtr const& getConfig() const override { + return m_config; + } + + ~Context() override; + + public: // IMutableContext + void setResultCapture( IResultCapture* resultCapture ) override { + m_resultCapture = resultCapture; + } + void setRunner( IRunner* runner ) override { + m_runner = runner; + } + void setConfig( IConfigPtr const& config ) override { + m_config = config; + } + + friend IMutableContext& getCurrentMutableContext(); + + private: + IConfigPtr m_config; + IRunner* m_runner = nullptr; + IResultCapture* m_resultCapture = nullptr; + }; + + IMutableContext *IMutableContext::currentContext = nullptr; + + void IMutableContext::createContext() + { + currentContext = new Context(); + } + + void cleanUpContext() { + delete IMutableContext::currentContext; + IMutableContext::currentContext = nullptr; + } + IContext::~IContext() = default; + IMutableContext::~IMutableContext() = default; + Context::~Context() = default; + + SimplePcg32& rng() { + static SimplePcg32 s_rng; + return s_rng; + } + +} +// end catch_context.cpp +// start catch_debug_console.cpp + +// start catch_debug_console.h + +#include + +namespace Catch { + void writeToDebugConsole( std::string const& text ); +} + +// end catch_debug_console.h +#if defined(CATCH_CONFIG_ANDROID_LOGWRITE) +#include + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + __android_log_write( ANDROID_LOG_DEBUG, "Catch", text.c_str() ); + } + } + +#elif defined(CATCH_PLATFORM_WINDOWS) + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + ::OutputDebugStringA( text.c_str() ); + } + } + +#else + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + // !TBD: Need a version for Mac/ XCode and other IDEs + Catch::cout() << text; + } + } + +#endif // Platform +// end catch_debug_console.cpp +// start catch_debugger.cpp + +#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE) + +# include +# include +# include +# include +# include + +#ifdef __apple_build_version__ + // These headers will only compile with AppleClang (XCode) + // For other compilers (Clang, GCC, ... ) we need to exclude them +# include +#endif + + namespace Catch { + #ifdef __apple_build_version__ + // The following function is taken directly from the following technical note: + // https://developer.apple.com/library/archive/qa/qa1361/_index.html + + // Returns true if the current process is being debugged (either + // running under the debugger or has a debugger attached post facto). + bool isDebuggerActive(){ + int mib[4]; + struct kinfo_proc info; + std::size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + + size = sizeof(info); + if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) { + Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; + return false; + } + + // We're being debugged if the P_TRACED flag is set. + + return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); + } + #else + bool isDebuggerActive() { + // We need to find another way to determine this for non-appleclang compilers on macOS + return false; + } + #endif + } // namespace Catch + +#elif defined(CATCH_PLATFORM_LINUX) + #include + #include + + namespace Catch{ + // The standard POSIX way of detecting a debugger is to attempt to + // ptrace() the process, but this needs to be done from a child and not + // this process itself to still allow attaching to this process later + // if wanted, so is rather heavy. Under Linux we have the PID of the + // "debugger" (which doesn't need to be gdb, of course, it could also + // be strace, for example) in /proc/$PID/status, so just get it from + // there instead. + bool isDebuggerActive(){ + // Libstdc++ has a bug, where std::ifstream sets errno to 0 + // This way our users can properly assert over errno values + ErrnoGuard guard; + std::ifstream in("/proc/self/status"); + for( std::string line; std::getline(in, line); ) { + static const int PREFIX_LEN = 11; + if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { + // We're traced if the PID is not 0 and no other PID starts + // with 0 digit, so it's enough to check for just a single + // character. + return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; + } + } + + return false; + } + } // namespace Catch +#elif defined(_MSC_VER) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#else + namespace Catch { + bool isDebuggerActive() { return false; } + } +#endif // Platform +// end catch_debugger.cpp +// start catch_decomposer.cpp + +namespace Catch { + + ITransientExpression::~ITransientExpression() = default; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { + if( lhs.size() + rhs.size() < 40 && + lhs.find('\n') == std::string::npos && + rhs.find('\n') == std::string::npos ) + os << lhs << " " << op << " " << rhs; + else + os << lhs << "\n" << op << "\n" << rhs; + } +} +// end catch_decomposer.cpp +// start catch_enforce.cpp + +#include + +namespace Catch { +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER) + [[noreturn]] + void throw_exception(std::exception const& e) { + Catch::cerr() << "Catch will terminate because it needed to throw an exception.\n" + << "The message was: " << e.what() << '\n'; + std::terminate(); + } +#endif + + [[noreturn]] + void throw_logic_error(std::string const& msg) { + throw_exception(std::logic_error(msg)); + } + + [[noreturn]] + void throw_domain_error(std::string const& msg) { + throw_exception(std::domain_error(msg)); + } + + [[noreturn]] + void throw_runtime_error(std::string const& msg) { + throw_exception(std::runtime_error(msg)); + } + +} // namespace Catch; +// end catch_enforce.cpp +// start catch_enum_values_registry.cpp +// start catch_enum_values_registry.h + +#include +#include + +namespace Catch { + + namespace Detail { + + std::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ); + + class EnumValuesRegistry : public IMutableEnumValuesRegistry { + + std::vector> m_enumInfos; + + EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector const& values) override; + }; + + std::vector parseEnums( StringRef enums ); + + } // Detail + +} // Catch + +// end catch_enum_values_registry.h + +#include +#include + +namespace Catch { + + IMutableEnumValuesRegistry::~IMutableEnumValuesRegistry() {} + + namespace Detail { + + namespace { + // Extracts the actual name part of an enum instance + // In other words, it returns the Blue part of Bikeshed::Colour::Blue + StringRef extractInstanceName(StringRef enumInstance) { + // Find last occurrence of ":" + size_t name_start = enumInstance.size(); + while (name_start > 0 && enumInstance[name_start - 1] != ':') { + --name_start; + } + return enumInstance.substr(name_start, enumInstance.size() - name_start); + } + } + + std::vector parseEnums( StringRef enums ) { + auto enumValues = splitStringRef( enums, ',' ); + std::vector parsed; + parsed.reserve( enumValues.size() ); + for( auto const& enumValue : enumValues ) { + parsed.push_back(trim(extractInstanceName(enumValue))); + } + return parsed; + } + + EnumInfo::~EnumInfo() {} + + StringRef EnumInfo::lookup( int value ) const { + for( auto const& valueToName : m_values ) { + if( valueToName.first == value ) + return valueToName.second; + } + return "{** unexpected enum value **}"_sr; + } + + std::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ) { + std::unique_ptr enumInfo( new EnumInfo ); + enumInfo->m_name = enumName; + enumInfo->m_values.reserve( values.size() ); + + const auto valueNames = Catch::Detail::parseEnums( allValueNames ); + assert( valueNames.size() == values.size() ); + std::size_t i = 0; + for( auto value : values ) + enumInfo->m_values.emplace_back(value, valueNames[i++]); + + return enumInfo; + } + + EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector const& values ) { + m_enumInfos.push_back(makeEnumInfo(enumName, allValueNames, values)); + return *m_enumInfos.back(); + } + + } // Detail +} // Catch + +// end catch_enum_values_registry.cpp +// start catch_errno_guard.cpp + +#include + +namespace Catch { + ErrnoGuard::ErrnoGuard():m_oldErrno(errno){} + ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; } +} +// end catch_errno_guard.cpp +// start catch_exception_translator_registry.cpp + +// start catch_exception_translator_registry.h + +#include +#include +#include + +namespace Catch { + + class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { + public: + ~ExceptionTranslatorRegistry(); + virtual void registerTranslator( const IExceptionTranslator* translator ); + std::string translateActiveException() const override; + std::string tryTranslators() const; + + private: + std::vector> m_translators; + }; +} + +// end catch_exception_translator_registry.h +#ifdef __OBJC__ +#import "Foundation/Foundation.h" +#endif + +namespace Catch { + + ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { + } + + void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { + m_translators.push_back( std::unique_ptr( translator ) ); + } + +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + std::string ExceptionTranslatorRegistry::translateActiveException() const { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + return tryTranslators(); + } + @catch (NSException *exception) { + return Catch::Detail::stringify( [exception description] ); + } +#else + // Compiling a mixed mode project with MSVC means that CLR + // exceptions will be caught in (...) as well. However, these + // do not fill-in std::current_exception and thus lead to crash + // when attempting rethrow. + // /EHa switch also causes structured exceptions to be caught + // here, but they fill-in current_exception properly, so + // at worst the output should be a little weird, instead of + // causing a crash. + if (std::current_exception() == nullptr) { + return "Non C++ exception. Possibly a CLR exception."; + } + return tryTranslators(); +#endif + } + catch( TestFailureException& ) { + std::rethrow_exception(std::current_exception()); + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return "Unknown exception"; + } + } + + std::string ExceptionTranslatorRegistry::tryTranslators() const { + if (m_translators.empty()) { + std::rethrow_exception(std::current_exception()); + } else { + return m_translators[0]->translate(m_translators.begin() + 1, m_translators.end()); + } + } + +#else // ^^ Exceptions are enabled // Exceptions are disabled vv + std::string ExceptionTranslatorRegistry::translateActiveException() const { + CATCH_INTERNAL_ERROR("Attempted to translate active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); + } + + std::string ExceptionTranslatorRegistry::tryTranslators() const { + CATCH_INTERNAL_ERROR("Attempted to use exception translators under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); + } +#endif + +} +// end catch_exception_translator_registry.cpp +// start catch_fatal_condition.cpp + +#include + +#if !defined( CATCH_CONFIG_WINDOWS_SEH ) && !defined( CATCH_CONFIG_POSIX_SIGNALS ) + +namespace Catch { + + // If neither SEH nor signal handling is required, the handler impls + // do not have to do anything, and can be empty. + void FatalConditionHandler::engage_platform() {} + void FatalConditionHandler::disengage_platform() {} + FatalConditionHandler::FatalConditionHandler() = default; + FatalConditionHandler::~FatalConditionHandler() = default; + +} // end namespace Catch + +#endif // !CATCH_CONFIG_WINDOWS_SEH && !CATCH_CONFIG_POSIX_SIGNALS + +#if defined( CATCH_CONFIG_WINDOWS_SEH ) && defined( CATCH_CONFIG_POSIX_SIGNALS ) +#error "Inconsistent configuration: Windows' SEH handling and POSIX signals cannot be enabled at the same time" +#endif // CATCH_CONFIG_WINDOWS_SEH && CATCH_CONFIG_POSIX_SIGNALS + +#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS ) + +namespace { + //! Signals fatal error message to the run context + void reportFatal( char const * const message ) { + Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); + } + + //! Minimal size Catch2 needs for its own fatal error handling. + //! Picked anecdotally, so it might not be sufficient on all + //! platforms, and for all configurations. + constexpr std::size_t minStackSizeForErrors = 32 * 1024; +} // end unnamed namespace + +#endif // CATCH_CONFIG_WINDOWS_SEH || CATCH_CONFIG_POSIX_SIGNALS + +#if defined( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + + struct SignalDefs { DWORD id; const char* name; }; + + // There is no 1-1 mapping between signals and windows exceptions. + // Windows can easily distinguish between SO and SigSegV, + // but SigInt, SigTerm, etc are handled differently. + static SignalDefs signalDefs[] = { + { static_cast(EXCEPTION_ILLEGAL_INSTRUCTION), "SIGILL - Illegal instruction signal" }, + { static_cast(EXCEPTION_STACK_OVERFLOW), "SIGSEGV - Stack overflow" }, + { static_cast(EXCEPTION_ACCESS_VIOLATION), "SIGSEGV - Segmentation violation signal" }, + { static_cast(EXCEPTION_INT_DIVIDE_BY_ZERO), "Divide by zero error" }, + }; + + static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { + for (auto const& def : signalDefs) { + if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { + reportFatal(def.name); + } + } + // If its not an exception we care about, pass it along. + // This stops us from eating debugger breaks etc. + return EXCEPTION_CONTINUE_SEARCH; + } + + // Since we do not support multiple instantiations, we put these + // into global variables and rely on cleaning them up in outlined + // constructors/destructors + static PVOID exceptionHandlerHandle = nullptr; + + // For MSVC, we reserve part of the stack memory for handling + // memory overflow structured exception. + FatalConditionHandler::FatalConditionHandler() { + ULONG guaranteeSize = static_cast(minStackSizeForErrors); + if (!SetThreadStackGuarantee(&guaranteeSize)) { + // We do not want to fully error out, because needing + // the stack reserve should be rare enough anyway. + Catch::cerr() + << "Failed to reserve piece of stack." + << " Stack overflows will not be reported successfully."; + } + } + + // We do not attempt to unset the stack guarantee, because + // Windows does not support lowering the stack size guarantee. + FatalConditionHandler::~FatalConditionHandler() = default; + + void FatalConditionHandler::engage_platform() { + // Register as first handler in current chain + exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); + if (!exceptionHandlerHandle) { + CATCH_RUNTIME_ERROR("Could not register vectored exception handler"); + } + } + + void FatalConditionHandler::disengage_platform() { + if (!RemoveVectoredExceptionHandler(exceptionHandlerHandle)) { + CATCH_RUNTIME_ERROR("Could not unregister vectored exception handler"); + } + exceptionHandlerHandle = nullptr; + } + +} // end namespace Catch + +#endif // CATCH_CONFIG_WINDOWS_SEH + +#if defined( CATCH_CONFIG_POSIX_SIGNALS ) + +#include + +namespace Catch { + + struct SignalDefs { + int id; + const char* name; + }; + + static SignalDefs signalDefs[] = { + { SIGINT, "SIGINT - Terminal interrupt signal" }, + { SIGILL, "SIGILL - Illegal instruction signal" }, + { SIGFPE, "SIGFPE - Floating point error signal" }, + { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, + { SIGTERM, "SIGTERM - Termination request signal" }, + { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } + }; + +// Older GCCs trigger -Wmissing-field-initializers for T foo = {} +// which is zero initialization, but not explicit. We want to avoid +// that. +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + + static char* altStackMem = nullptr; + static std::size_t altStackSize = 0; + static stack_t oldSigStack{}; + static struct sigaction oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)]{}; + + static void restorePreviousSignalHandlers() { + // We set signal handlers back to the previous ones. Hopefully + // nobody overwrote them in the meantime, and doesn't expect + // their signal handlers to live past ours given that they + // installed them after ours.. + for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { + sigaction(signalDefs[i].id, &oldSigActions[i], nullptr); + } + // Return the old stack + sigaltstack(&oldSigStack, nullptr); + } + + static void handleSignal( int sig ) { + char const * name = ""; + for (auto const& def : signalDefs) { + if (sig == def.id) { + name = def.name; + break; + } + } + // We need to restore previous signal handlers and let them do + // their thing, so that the users can have the debugger break + // when a signal is raised, and so on. + restorePreviousSignalHandlers(); + reportFatal( name ); + raise( sig ); + } + + FatalConditionHandler::FatalConditionHandler() { + assert(!altStackMem && "Cannot initialize POSIX signal handler when one already exists"); + if (altStackSize == 0) { + altStackSize = std::max(static_cast(SIGSTKSZ), minStackSizeForErrors); + } + altStackMem = new char[altStackSize](); + } + + FatalConditionHandler::~FatalConditionHandler() { + delete[] altStackMem; + // We signal that another instance can be constructed by zeroing + // out the pointer. + altStackMem = nullptr; + } + + void FatalConditionHandler::engage_platform() { + stack_t sigStack; + sigStack.ss_sp = altStackMem; + sigStack.ss_size = altStackSize; + sigStack.ss_flags = 0; + sigaltstack(&sigStack, &oldSigStack); + struct sigaction sa = { }; + + sa.sa_handler = handleSignal; + sa.sa_flags = SA_ONSTACK; + for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { + sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); + } + } + +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif + + void FatalConditionHandler::disengage_platform() { + restorePreviousSignalHandlers(); + } + +} // end namespace Catch + +#endif // CATCH_CONFIG_POSIX_SIGNALS +// end catch_fatal_condition.cpp +// start catch_generators.cpp + +#include +#include + +namespace Catch { + +IGeneratorTracker::~IGeneratorTracker() {} + +const char* GeneratorException::what() const noexcept { + return m_msg; +} + +namespace Generators { + + GeneratorUntypedBase::~GeneratorUntypedBase() {} + + auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { + return getResultCapture().acquireGeneratorTracker( generatorName, lineInfo ); + } + +} // namespace Generators +} // namespace Catch +// end catch_generators.cpp +// start catch_interfaces_capture.cpp + +namespace Catch { + IResultCapture::~IResultCapture() = default; +} +// end catch_interfaces_capture.cpp +// start catch_interfaces_config.cpp + +namespace Catch { + IConfig::~IConfig() = default; +} +// end catch_interfaces_config.cpp +// start catch_interfaces_exception.cpp + +namespace Catch { + IExceptionTranslator::~IExceptionTranslator() = default; + IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; +} +// end catch_interfaces_exception.cpp +// start catch_interfaces_registry_hub.cpp + +namespace Catch { + IRegistryHub::~IRegistryHub() = default; + IMutableRegistryHub::~IMutableRegistryHub() = default; +} +// end catch_interfaces_registry_hub.cpp +// start catch_interfaces_reporter.cpp + +// start catch_reporter_listening.h + +namespace Catch { + + class ListeningReporter : public IStreamingReporter { + using Reporters = std::vector; + Reporters m_listeners; + IStreamingReporterPtr m_reporter = nullptr; + ReporterPreferences m_preferences; + + public: + ListeningReporter(); + + void addListener( IStreamingReporterPtr&& listener ); + void addReporter( IStreamingReporterPtr&& reporter ); + + public: // IStreamingReporter + + ReporterPreferences getPreferences() const override; + + void noMatchingTestCases( std::string const& spec ) override; + + void reportInvalidArguments(std::string const&arg) override; + + static std::set getSupportedVerbosities(); + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void benchmarkPreparing(std::string const& name) override; + void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; + void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override; + void benchmarkFailed(std::string const&) override; +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + void testRunStarting( TestRunInfo const& testRunInfo ) override; + void testGroupStarting( GroupInfo const& groupInfo ) override; + void testCaseStarting( TestCaseInfo const& testInfo ) override; + void sectionStarting( SectionInfo const& sectionInfo ) override; + void assertionStarting( AssertionInfo const& assertionInfo ) override; + + // The return value indicates if the messages buffer should be cleared: + bool assertionEnded( AssertionStats const& assertionStats ) override; + void sectionEnded( SectionStats const& sectionStats ) override; + void testCaseEnded( TestCaseStats const& testCaseStats ) override; + void testGroupEnded( TestGroupStats const& testGroupStats ) override; + void testRunEnded( TestRunStats const& testRunStats ) override; + + void skipTest( TestCaseInfo const& testInfo ) override; + bool isMulti() const override; + + }; + +} // end namespace Catch + +// end catch_reporter_listening.h +namespace Catch { + + ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig ) + : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} + + ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ) + : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} + + std::ostream& ReporterConfig::stream() const { return *m_stream; } + IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; } + + TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {} + + GroupInfo::GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ) + : name( _name ), + groupIndex( _groupIndex ), + groupsCounts( _groupsCount ) + {} + + AssertionStats::AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ) + : assertionResult( _assertionResult ), + infoMessages( _infoMessages ), + totals( _totals ) + { + assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression; + + if( assertionResult.hasMessage() ) { + // Copy message into messages list. + // !TBD This should have been done earlier, somewhere + MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); + builder << assertionResult.getMessage(); + builder.m_info.message = builder.m_stream.str(); + + infoMessages.push_back( builder.m_info ); + } + } + + AssertionStats::~AssertionStats() = default; + + SectionStats::SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ) + : sectionInfo( _sectionInfo ), + assertions( _assertions ), + durationInSeconds( _durationInSeconds ), + missingAssertions( _missingAssertions ) + {} + + SectionStats::~SectionStats() = default; + + TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ) + : testInfo( _testInfo ), + totals( _totals ), + stdOut( _stdOut ), + stdErr( _stdErr ), + aborting( _aborting ) + {} + + TestCaseStats::~TestCaseStats() = default; + + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ) + : groupInfo( _groupInfo ), + totals( _totals ), + aborting( _aborting ) + {} + + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo ) + : groupInfo( _groupInfo ), + aborting( false ) + {} + + TestGroupStats::~TestGroupStats() = default; + + TestRunStats::TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ) + : runInfo( _runInfo ), + totals( _totals ), + aborting( _aborting ) + {} + + TestRunStats::~TestRunStats() = default; + + void IStreamingReporter::fatalErrorEncountered( StringRef ) {} + bool IStreamingReporter::isMulti() const { return false; } + + IReporterFactory::~IReporterFactory() = default; + IReporterRegistry::~IReporterRegistry() = default; + +} // end namespace Catch +// end catch_interfaces_reporter.cpp +// start catch_interfaces_runner.cpp + +namespace Catch { + IRunner::~IRunner() = default; +} +// end catch_interfaces_runner.cpp +// start catch_interfaces_testcase.cpp + +namespace Catch { + ITestInvoker::~ITestInvoker() = default; + ITestCaseRegistry::~ITestCaseRegistry() = default; +} +// end catch_interfaces_testcase.cpp +// start catch_leak_detector.cpp + +#ifdef CATCH_CONFIG_WINDOWS_CRTDBG +#include + +namespace Catch { + + LeakDetector::LeakDetector() { + int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + flag |= _CRTDBG_LEAK_CHECK_DF; + flag |= _CRTDBG_ALLOC_MEM_DF; + _CrtSetDbgFlag(flag); + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + // Change this to leaking allocation's number to break there + _CrtSetBreakAlloc(-1); + } +} + +#else + + Catch::LeakDetector::LeakDetector() {} + +#endif + +Catch::LeakDetector::~LeakDetector() { + Catch::cleanUp(); +} +// end catch_leak_detector.cpp +// start catch_list.cpp + +// start catch_list.h + +#include + +namespace Catch { + + std::size_t listTests( Config const& config ); + + std::size_t listTestsNamesOnly( Config const& config ); + + struct TagInfo { + void add( std::string const& spelling ); + std::string all() const; + + std::set spellings; + std::size_t count = 0; + }; + + std::size_t listTags( Config const& config ); + + std::size_t listReporters(); + + Option list( std::shared_ptr const& config ); + +} // end namespace Catch + +// end catch_list.h +// start catch_text.h + +namespace Catch { + using namespace clara::TextFlow; +} + +// end catch_text.h +#include +#include +#include + +namespace Catch { + + std::size_t listTests( Config const& config ) { + TestSpec const& testSpec = config.testSpec(); + if( config.hasTestFilters() ) + Catch::cout() << "Matching test cases:\n"; + else { + Catch::cout() << "All available test cases:\n"; + } + + auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCaseInfo : matchedTestCases ) { + Colour::Code colour = testCaseInfo.isHidden() + ? Colour::SecondaryText + : Colour::None; + Colour colourGuard( colour ); + + Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n"; + if( config.verbosity() >= Verbosity::High ) { + Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl; + std::string description = testCaseInfo.description; + if( description.empty() ) + description = "(NO DESCRIPTION)"; + Catch::cout() << Column( description ).indent(4) << std::endl; + } + if( !testCaseInfo.tags.empty() ) + Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; + } + + if( !config.hasTestFilters() ) + Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; + else + Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; + return matchedTestCases.size(); + } + + std::size_t listTestsNamesOnly( Config const& config ) { + TestSpec const& testSpec = config.testSpec(); + std::size_t matchedTests = 0; + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCaseInfo : matchedTestCases ) { + matchedTests++; + if( startsWith( testCaseInfo.name, '#' ) ) + Catch::cout() << '"' << testCaseInfo.name << '"'; + else + Catch::cout() << testCaseInfo.name; + if ( config.verbosity() >= Verbosity::High ) + Catch::cout() << "\t@" << testCaseInfo.lineInfo; + Catch::cout() << std::endl; + } + return matchedTests; + } + + void TagInfo::add( std::string const& spelling ) { + ++count; + spellings.insert( spelling ); + } + + std::string TagInfo::all() const { + size_t size = 0; + for (auto const& spelling : spellings) { + // Add 2 for the brackes + size += spelling.size() + 2; + } + + std::string out; out.reserve(size); + for (auto const& spelling : spellings) { + out += '['; + out += spelling; + out += ']'; + } + return out; + } + + std::size_t listTags( Config const& config ) { + TestSpec const& testSpec = config.testSpec(); + if( config.hasTestFilters() ) + Catch::cout() << "Tags for matching test cases:\n"; + else { + Catch::cout() << "All available tags:\n"; + } + + std::map tagCounts; + + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCase : matchedTestCases ) { + for( auto const& tagName : testCase.getTestCaseInfo().tags ) { + std::string lcaseTagName = toLower( tagName ); + auto countIt = tagCounts.find( lcaseTagName ); + if( countIt == tagCounts.end() ) + countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; + countIt->second.add( tagName ); + } + } + + for( auto const& tagCount : tagCounts ) { + ReusableStringStream rss; + rss << " " << std::setw(2) << tagCount.second.count << " "; + auto str = rss.str(); + auto wrapper = Column( tagCount.second.all() ) + .initialIndent( 0 ) + .indent( str.size() ) + .width( CATCH_CONFIG_CONSOLE_WIDTH-10 ); + Catch::cout() << str << wrapper << '\n'; + } + Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; + return tagCounts.size(); + } + + std::size_t listReporters() { + Catch::cout() << "Available reporters:\n"; + IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); + std::size_t maxNameLen = 0; + for( auto const& factoryKvp : factories ) + maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() ); + + for( auto const& factoryKvp : factories ) { + Catch::cout() + << Column( factoryKvp.first + ":" ) + .indent(2) + .width( 5+maxNameLen ) + + Column( factoryKvp.second->getDescription() ) + .initialIndent(0) + .indent(2) + .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) + << "\n"; + } + Catch::cout() << std::endl; + return factories.size(); + } + + Option list( std::shared_ptr const& config ) { + Option listedCount; + getCurrentMutableContext().setConfig( config ); + if( config->listTests() ) + listedCount = listedCount.valueOr(0) + listTests( *config ); + if( config->listTestNamesOnly() ) + listedCount = listedCount.valueOr(0) + listTestsNamesOnly( *config ); + if( config->listTags() ) + listedCount = listedCount.valueOr(0) + listTags( *config ); + if( config->listReporters() ) + listedCount = listedCount.valueOr(0) + listReporters(); + return listedCount; + } + +} // end namespace Catch +// end catch_list.cpp +// start catch_matchers.cpp + +namespace Catch { +namespace Matchers { + namespace Impl { + + std::string MatcherUntypedBase::toString() const { + if( m_cachedToString.empty() ) + m_cachedToString = describe(); + return m_cachedToString; + } + + MatcherUntypedBase::~MatcherUntypedBase() = default; + + } // namespace Impl +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch +// end catch_matchers.cpp +// start catch_matchers_exception.cpp + +namespace Catch { +namespace Matchers { +namespace Exception { + +bool ExceptionMessageMatcher::match(std::exception const& ex) const { + return ex.what() == m_message; +} + +std::string ExceptionMessageMatcher::describe() const { + return "exception message matches \"" + m_message + "\""; +} + +} +Exception::ExceptionMessageMatcher Message(std::string const& message) { + return Exception::ExceptionMessageMatcher(message); +} + +// namespace Exception +} // namespace Matchers +} // namespace Catch +// end catch_matchers_exception.cpp +// start catch_matchers_floating.cpp + +// start catch_polyfills.hpp + +namespace Catch { + bool isnan(float f); + bool isnan(double d); +} + +// end catch_polyfills.hpp +// start catch_to_string.hpp + +#include + +namespace Catch { + template + std::string to_string(T const& t) { +#if defined(CATCH_CONFIG_CPP11_TO_STRING) + return std::to_string(t); +#else + ReusableStringStream rss; + rss << t; + return rss.str(); +#endif + } +} // end namespace Catch + +// end catch_to_string.hpp +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Catch { +namespace { + + int32_t convert(float f) { + static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated"); + int32_t i; + std::memcpy(&i, &f, sizeof(f)); + return i; + } + + int64_t convert(double d) { + static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated"); + int64_t i; + std::memcpy(&i, &d, sizeof(d)); + return i; + } + + template + bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) { + // Comparison with NaN should always be false. + // This way we can rule it out before getting into the ugly details + if (Catch::isnan(lhs) || Catch::isnan(rhs)) { + return false; + } + + auto lc = convert(lhs); + auto rc = convert(rhs); + + if ((lc < 0) != (rc < 0)) { + // Potentially we can have +0 and -0 + return lhs == rhs; + } + + // static cast as a workaround for IBM XLC + auto ulpDiff = std::abs(static_cast(lc - rc)); + return static_cast(ulpDiff) <= maxUlpDiff; + } + +#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) + + float nextafter(float x, float y) { + return ::nextafterf(x, y); + } + + double nextafter(double x, double y) { + return ::nextafter(x, y); + } + +#endif // ^^^ CATCH_CONFIG_GLOBAL_NEXTAFTER ^^^ + +template +FP step(FP start, FP direction, uint64_t steps) { + for (uint64_t i = 0; i < steps; ++i) { +#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) + start = Catch::nextafter(start, direction); +#else + start = std::nextafter(start, direction); +#endif + } + return start; +} + +// Performs equivalent check of std::fabs(lhs - rhs) <= margin +// But without the subtraction to allow for INFINITY in comparison +bool marginComparison(double lhs, double rhs, double margin) { + return (lhs + margin >= rhs) && (rhs + margin >= lhs); +} + +template +void write(std::ostream& out, FloatingPoint num) { + out << std::scientific + << std::setprecision(std::numeric_limits::max_digits10 - 1) + << num; +} + +} // end anonymous namespace + +namespace Matchers { +namespace Floating { + + enum class FloatingPointKind : uint8_t { + Float, + Double + }; + + WithinAbsMatcher::WithinAbsMatcher(double target, double margin) + :m_target{ target }, m_margin{ margin } { + CATCH_ENFORCE(margin >= 0, "Invalid margin: " << margin << '.' + << " Margin has to be non-negative."); + } + + // Performs equivalent check of std::fabs(lhs - rhs) <= margin + // But without the subtraction to allow for INFINITY in comparison + bool WithinAbsMatcher::match(double const& matchee) const { + return (matchee + m_margin >= m_target) && (m_target + m_margin >= matchee); + } + + std::string WithinAbsMatcher::describe() const { + return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target); + } + + WithinUlpsMatcher::WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType) + :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } { + CATCH_ENFORCE(m_type == FloatingPointKind::Double + || m_ulps < (std::numeric_limits::max)(), + "Provided ULP is impossibly large for a float comparison."); + } + +#if defined(__clang__) +#pragma clang diagnostic push +// Clang <3.5 reports on the default branch in the switch below +#pragma clang diagnostic ignored "-Wunreachable-code" +#endif + + bool WithinUlpsMatcher::match(double const& matchee) const { + switch (m_type) { + case FloatingPointKind::Float: + return almostEqualUlps(static_cast(matchee), static_cast(m_target), m_ulps); + case FloatingPointKind::Double: + return almostEqualUlps(matchee, m_target, m_ulps); + default: + CATCH_INTERNAL_ERROR( "Unknown FloatingPointKind value" ); + } + } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + + std::string WithinUlpsMatcher::describe() const { + std::stringstream ret; + + ret << "is within " << m_ulps << " ULPs of "; + + if (m_type == FloatingPointKind::Float) { + write(ret, static_cast(m_target)); + ret << 'f'; + } else { + write(ret, m_target); + } + + ret << " (["; + if (m_type == FloatingPointKind::Double) { + write(ret, step(m_target, static_cast(-INFINITY), m_ulps)); + ret << ", "; + write(ret, step(m_target, static_cast( INFINITY), m_ulps)); + } else { + // We have to cast INFINITY to float because of MinGW, see #1782 + write(ret, step(static_cast(m_target), static_cast(-INFINITY), m_ulps)); + ret << ", "; + write(ret, step(static_cast(m_target), static_cast( INFINITY), m_ulps)); + } + ret << "])"; + + return ret.str(); + } + + WithinRelMatcher::WithinRelMatcher(double target, double epsilon): + m_target(target), + m_epsilon(epsilon){ + CATCH_ENFORCE(m_epsilon >= 0., "Relative comparison with epsilon < 0 does not make sense."); + CATCH_ENFORCE(m_epsilon < 1., "Relative comparison with epsilon >= 1 does not make sense."); + } + + bool WithinRelMatcher::match(double const& matchee) const { + const auto relMargin = m_epsilon * (std::max)(std::fabs(matchee), std::fabs(m_target)); + return marginComparison(matchee, m_target, + std::isinf(relMargin)? 0 : relMargin); + } + + std::string WithinRelMatcher::describe() const { + Catch::ReusableStringStream sstr; + sstr << "and " << m_target << " are within " << m_epsilon * 100. << "% of each other"; + return sstr.str(); + } + +}// namespace Floating + +Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff) { + return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double); +} + +Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff) { + return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float); +} + +Floating::WithinAbsMatcher WithinAbs(double target, double margin) { + return Floating::WithinAbsMatcher(target, margin); +} + +Floating::WithinRelMatcher WithinRel(double target, double eps) { + return Floating::WithinRelMatcher(target, eps); +} + +Floating::WithinRelMatcher WithinRel(double target) { + return Floating::WithinRelMatcher(target, std::numeric_limits::epsilon() * 100); +} + +Floating::WithinRelMatcher WithinRel(float target, float eps) { + return Floating::WithinRelMatcher(target, eps); +} + +Floating::WithinRelMatcher WithinRel(float target) { + return Floating::WithinRelMatcher(target, std::numeric_limits::epsilon() * 100); +} + +} // namespace Matchers +} // namespace Catch +// end catch_matchers_floating.cpp +// start catch_matchers_generic.cpp + +std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) { + if (desc.empty()) { + return "matches undescribed predicate"; + } else { + return "matches predicate: \"" + desc + '"'; + } +} +// end catch_matchers_generic.cpp +// start catch_matchers_string.cpp + +#include + +namespace Catch { +namespace Matchers { + + namespace StdString { + + CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_str( adjustString( str ) ) + {} + std::string CasedString::adjustString( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No + ? toLower( str ) + : str; + } + std::string CasedString::caseSensitivitySuffix() const { + return m_caseSensitivity == CaseSensitive::No + ? " (case insensitive)" + : std::string(); + } + + StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) + : m_comparator( comparator ), + m_operation( operation ) { + } + + std::string StringMatcherBase::describe() const { + std::string description; + description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + + m_comparator.caseSensitivitySuffix().size()); + description += m_operation; + description += ": \""; + description += m_comparator.m_str; + description += "\""; + description += m_comparator.caseSensitivitySuffix(); + return description; + } + + EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} + + bool EqualsMatcher::match( std::string const& source ) const { + return m_comparator.adjustString( source ) == m_comparator.m_str; + } + + ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} + + bool ContainsMatcher::match( std::string const& source ) const { + return contains( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} + + bool StartsWithMatcher::match( std::string const& source ) const { + return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} + + bool EndsWithMatcher::match( std::string const& source ) const { + return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} + + bool RegexMatcher::match(std::string const& matchee) const { + auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway + if (m_caseSensitivity == CaseSensitive::Choice::No) { + flags |= std::regex::icase; + } + auto reg = std::regex(m_regex, flags); + return std::regex_match(matchee, reg); + } + + std::string RegexMatcher::describe() const { + return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); + } + + } // namespace StdString + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + + StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { + return StdString::RegexMatcher(regex, caseSensitivity); + } + +} // namespace Matchers +} // namespace Catch +// end catch_matchers_string.cpp +// start catch_message.cpp + +// start catch_uncaught_exceptions.h + +namespace Catch { + bool uncaught_exceptions(); +} // end namespace Catch + +// end catch_uncaught_exceptions.h +#include +#include + +namespace Catch { + + MessageInfo::MessageInfo( StringRef const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + type( _type ), + sequence( ++globalCount ) + {} + + bool MessageInfo::operator==( MessageInfo const& other ) const { + return sequence == other.sequence; + } + + bool MessageInfo::operator<( MessageInfo const& other ) const { + return sequence < other.sequence; + } + + // This may need protecting if threading support is added + unsigned int MessageInfo::globalCount = 0; + + //////////////////////////////////////////////////////////////////////////// + + Catch::MessageBuilder::MessageBuilder( StringRef const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ) + :m_info(macroName, lineInfo, type) {} + + //////////////////////////////////////////////////////////////////////////// + + ScopedMessage::ScopedMessage( MessageBuilder const& builder ) + : m_info( builder.m_info ), m_moved() + { + m_info.message = builder.m_stream.str(); + getResultCapture().pushScopedMessage( m_info ); + } + + ScopedMessage::ScopedMessage( ScopedMessage&& old ) + : m_info( old.m_info ), m_moved() + { + old.m_moved = true; + } + + ScopedMessage::~ScopedMessage() { + if ( !uncaught_exceptions() && !m_moved ){ + getResultCapture().popScopedMessage(m_info); + } + } + + Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ) { + auto trimmed = [&] (size_t start, size_t end) { + while (names[start] == ',' || isspace(static_cast(names[start]))) { + ++start; + } + while (names[end] == ',' || isspace(static_cast(names[end]))) { + --end; + } + return names.substr(start, end - start + 1); + }; + auto skipq = [&] (size_t start, char quote) { + for (auto i = start + 1; i < names.size() ; ++i) { + if (names[i] == quote) + return i; + if (names[i] == '\\') + ++i; + } + CATCH_INTERNAL_ERROR("CAPTURE parsing encountered unmatched quote"); + }; + + size_t start = 0; + std::stack openings; + for (size_t pos = 0; pos < names.size(); ++pos) { + char c = names[pos]; + switch (c) { + case '[': + case '{': + case '(': + // It is basically impossible to disambiguate between + // comparison and start of template args in this context +// case '<': + openings.push(c); + break; + case ']': + case '}': + case ')': +// case '>': + openings.pop(); + break; + case '"': + case '\'': + pos = skipq(pos, c); + break; + case ',': + if (start != pos && openings.empty()) { + m_messages.emplace_back(macroName, lineInfo, resultType); + m_messages.back().message = static_cast(trimmed(start, pos)); + m_messages.back().message += " := "; + start = pos; + } + } + } + assert(openings.empty() && "Mismatched openings"); + m_messages.emplace_back(macroName, lineInfo, resultType); + m_messages.back().message = static_cast(trimmed(start, names.size() - 1)); + m_messages.back().message += " := "; + } + Capturer::~Capturer() { + if ( !uncaught_exceptions() ){ + assert( m_captured == m_messages.size() ); + for( size_t i = 0; i < m_captured; ++i ) + m_resultCapture.popScopedMessage( m_messages[i] ); + } + } + + void Capturer::captureValue( size_t index, std::string const& value ) { + assert( index < m_messages.size() ); + m_messages[index].message += value; + m_resultCapture.pushScopedMessage( m_messages[index] ); + m_captured++; + } + +} // end namespace Catch +// end catch_message.cpp +// start catch_output_redirect.cpp + +// start catch_output_redirect.h +#ifndef TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H +#define TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H + +#include +#include +#include + +namespace Catch { + + class RedirectedStream { + std::ostream& m_originalStream; + std::ostream& m_redirectionStream; + std::streambuf* m_prevBuf; + + public: + RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ); + ~RedirectedStream(); + }; + + class RedirectedStdOut { + ReusableStringStream m_rss; + RedirectedStream m_cout; + public: + RedirectedStdOut(); + auto str() const -> std::string; + }; + + // StdErr has two constituent streams in C++, std::cerr and std::clog + // This means that we need to redirect 2 streams into 1 to keep proper + // order of writes + class RedirectedStdErr { + ReusableStringStream m_rss; + RedirectedStream m_cerr; + RedirectedStream m_clog; + public: + RedirectedStdErr(); + auto str() const -> std::string; + }; + + class RedirectedStreams { + public: + RedirectedStreams(RedirectedStreams const&) = delete; + RedirectedStreams& operator=(RedirectedStreams const&) = delete; + RedirectedStreams(RedirectedStreams&&) = delete; + RedirectedStreams& operator=(RedirectedStreams&&) = delete; + + RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr); + ~RedirectedStreams(); + private: + std::string& m_redirectedCout; + std::string& m_redirectedCerr; + RedirectedStdOut m_redirectedStdOut; + RedirectedStdErr m_redirectedStdErr; + }; + +#if defined(CATCH_CONFIG_NEW_CAPTURE) + + // Windows's implementation of std::tmpfile is terrible (it tries + // to create a file inside system folder, thus requiring elevated + // privileges for the binary), so we have to use tmpnam(_s) and + // create the file ourselves there. + class TempFile { + public: + TempFile(TempFile const&) = delete; + TempFile& operator=(TempFile const&) = delete; + TempFile(TempFile&&) = delete; + TempFile& operator=(TempFile&&) = delete; + + TempFile(); + ~TempFile(); + + std::FILE* getFile(); + std::string getContents(); + + private: + std::FILE* m_file = nullptr; + #if defined(_MSC_VER) + char m_buffer[L_tmpnam] = { 0 }; + #endif + }; + + class OutputRedirect { + public: + OutputRedirect(OutputRedirect const&) = delete; + OutputRedirect& operator=(OutputRedirect const&) = delete; + OutputRedirect(OutputRedirect&&) = delete; + OutputRedirect& operator=(OutputRedirect&&) = delete; + + OutputRedirect(std::string& stdout_dest, std::string& stderr_dest); + ~OutputRedirect(); + + private: + int m_originalStdout = -1; + int m_originalStderr = -1; + TempFile m_stdoutFile; + TempFile m_stderrFile; + std::string& m_stdoutDest; + std::string& m_stderrDest; + }; + +#endif + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H +// end catch_output_redirect.h +#include +#include +#include +#include +#include + +#if defined(CATCH_CONFIG_NEW_CAPTURE) + #if defined(_MSC_VER) + #include //_dup and _dup2 + #define dup _dup + #define dup2 _dup2 + #define fileno _fileno + #else + #include // dup and dup2 + #endif +#endif + +namespace Catch { + + RedirectedStream::RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ) + : m_originalStream( originalStream ), + m_redirectionStream( redirectionStream ), + m_prevBuf( m_originalStream.rdbuf() ) + { + m_originalStream.rdbuf( m_redirectionStream.rdbuf() ); + } + + RedirectedStream::~RedirectedStream() { + m_originalStream.rdbuf( m_prevBuf ); + } + + RedirectedStdOut::RedirectedStdOut() : m_cout( Catch::cout(), m_rss.get() ) {} + auto RedirectedStdOut::str() const -> std::string { return m_rss.str(); } + + RedirectedStdErr::RedirectedStdErr() + : m_cerr( Catch::cerr(), m_rss.get() ), + m_clog( Catch::clog(), m_rss.get() ) + {} + auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); } + + RedirectedStreams::RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr) + : m_redirectedCout(redirectedCout), + m_redirectedCerr(redirectedCerr) + {} + + RedirectedStreams::~RedirectedStreams() { + m_redirectedCout += m_redirectedStdOut.str(); + m_redirectedCerr += m_redirectedStdErr.str(); + } + +#if defined(CATCH_CONFIG_NEW_CAPTURE) + +#if defined(_MSC_VER) + TempFile::TempFile() { + if (tmpnam_s(m_buffer)) { + CATCH_RUNTIME_ERROR("Could not get a temp filename"); + } + if (fopen_s(&m_file, m_buffer, "w+")) { + char buffer[100]; + if (strerror_s(buffer, errno)) { + CATCH_RUNTIME_ERROR("Could not translate errno to a string"); + } + CATCH_RUNTIME_ERROR("Could not open the temp file: '" << m_buffer << "' because: " << buffer); + } + } +#else + TempFile::TempFile() { + m_file = std::tmpfile(); + if (!m_file) { + CATCH_RUNTIME_ERROR("Could not create a temp file."); + } + } + +#endif + + TempFile::~TempFile() { + // TBD: What to do about errors here? + std::fclose(m_file); + // We manually create the file on Windows only, on Linux + // it will be autodeleted +#if defined(_MSC_VER) + std::remove(m_buffer); +#endif + } + + FILE* TempFile::getFile() { + return m_file; + } + + std::string TempFile::getContents() { + std::stringstream sstr; + char buffer[100] = {}; + std::rewind(m_file); + while (std::fgets(buffer, sizeof(buffer), m_file)) { + sstr << buffer; + } + return sstr.str(); + } + + OutputRedirect::OutputRedirect(std::string& stdout_dest, std::string& stderr_dest) : + m_originalStdout(dup(1)), + m_originalStderr(dup(2)), + m_stdoutDest(stdout_dest), + m_stderrDest(stderr_dest) { + dup2(fileno(m_stdoutFile.getFile()), 1); + dup2(fileno(m_stderrFile.getFile()), 2); + } + + OutputRedirect::~OutputRedirect() { + Catch::cout() << std::flush; + fflush(stdout); + // Since we support overriding these streams, we flush cerr + // even though std::cerr is unbuffered + Catch::cerr() << std::flush; + Catch::clog() << std::flush; + fflush(stderr); + + dup2(m_originalStdout, 1); + dup2(m_originalStderr, 2); + + m_stdoutDest += m_stdoutFile.getContents(); + m_stderrDest += m_stderrFile.getContents(); + } + +#endif // CATCH_CONFIG_NEW_CAPTURE + +} // namespace Catch + +#if defined(CATCH_CONFIG_NEW_CAPTURE) + #if defined(_MSC_VER) + #undef dup + #undef dup2 + #undef fileno + #endif +#endif +// end catch_output_redirect.cpp +// start catch_polyfills.cpp + +#include + +namespace Catch { + +#if !defined(CATCH_CONFIG_POLYFILL_ISNAN) + bool isnan(float f) { + return std::isnan(f); + } + bool isnan(double d) { + return std::isnan(d); + } +#else + // For now we only use this for embarcadero + bool isnan(float f) { + return std::_isnan(f); + } + bool isnan(double d) { + return std::_isnan(d); + } +#endif + +} // end namespace Catch +// end catch_polyfills.cpp +// start catch_random_number_generator.cpp + +namespace Catch { + +namespace { + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4146) // we negate uint32 during the rotate +#endif + // Safe rotr implementation thanks to John Regehr + uint32_t rotate_right(uint32_t val, uint32_t count) { + const uint32_t mask = 31; + count &= mask; + return (val >> count) | (val << (-count & mask)); + } + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +} + + SimplePcg32::SimplePcg32(result_type seed_) { + seed(seed_); + } + + void SimplePcg32::seed(result_type seed_) { + m_state = 0; + (*this)(); + m_state += seed_; + (*this)(); + } + + void SimplePcg32::discard(uint64_t skip) { + // We could implement this to run in O(log n) steps, but this + // should suffice for our use case. + for (uint64_t s = 0; s < skip; ++s) { + static_cast((*this)()); + } + } + + SimplePcg32::result_type SimplePcg32::operator()() { + // prepare the output value + const uint32_t xorshifted = static_cast(((m_state >> 18u) ^ m_state) >> 27u); + const auto output = rotate_right(xorshifted, m_state >> 59u); + + // advance state + m_state = m_state * 6364136223846793005ULL + s_inc; + + return output; + } + + bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs) { + return lhs.m_state == rhs.m_state; + } + + bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs) { + return lhs.m_state != rhs.m_state; + } +} +// end catch_random_number_generator.cpp +// start catch_registry_hub.cpp + +// start catch_test_case_registry_impl.h + +#include +#include +#include +#include + +namespace Catch { + + class TestCase; + struct IConfig; + + std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ); + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + + void enforceNoDuplicateTestCases( std::vector const& functions ); + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + + class TestRegistry : public ITestCaseRegistry { + public: + virtual ~TestRegistry() = default; + + virtual void registerTest( TestCase const& testCase ); + + std::vector const& getAllTests() const override; + std::vector const& getAllTestsSorted( IConfig const& config ) const override; + + private: + std::vector m_functions; + mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; + mutable std::vector m_sortedFunctions; + std::size_t m_unnamedCount = 0; + std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised + }; + + /////////////////////////////////////////////////////////////////////////// + + class TestInvokerAsFunction : public ITestInvoker { + void(*m_testAsFunction)(); + public: + TestInvokerAsFunction( void(*testAsFunction)() ) noexcept; + + void invoke() const override; + }; + + std::string extractClassName( StringRef const& classOrQualifiedMethodName ); + + /////////////////////////////////////////////////////////////////////////// + +} // end namespace Catch + +// end catch_test_case_registry_impl.h +// start catch_reporter_registry.h + +#include + +namespace Catch { + + class ReporterRegistry : public IReporterRegistry { + + public: + + ~ReporterRegistry() override; + + IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override; + + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ); + void registerListener( IReporterFactoryPtr const& factory ); + + FactoryMap const& getFactories() const override; + Listeners const& getListeners() const override; + + private: + FactoryMap m_factories; + Listeners m_listeners; + }; +} + +// end catch_reporter_registry.h +// start catch_tag_alias_registry.h + +// start catch_tag_alias.h + +#include + +namespace Catch { + + struct TagAlias { + TagAlias(std::string const& _tag, SourceLineInfo _lineInfo); + + std::string tag; + SourceLineInfo lineInfo; + }; + +} // end namespace Catch + +// end catch_tag_alias.h +#include + +namespace Catch { + + class TagAliasRegistry : public ITagAliasRegistry { + public: + ~TagAliasRegistry() override; + TagAlias const* find( std::string const& alias ) const override; + std::string expandAliases( std::string const& unexpandedTestSpec ) const override; + void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); + + private: + std::map m_registry; + }; + +} // end namespace Catch + +// end catch_tag_alias_registry.h +// start catch_startup_exception_registry.h + +#include +#include + +namespace Catch { + + class StartupExceptionRegistry { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + public: + void add(std::exception_ptr const& exception) noexcept; + std::vector const& getExceptions() const noexcept; + private: + std::vector m_exceptions; +#endif + }; + +} // end namespace Catch + +// end catch_startup_exception_registry.h +// start catch_singletons.hpp + +namespace Catch { + + struct ISingleton { + virtual ~ISingleton(); + }; + + void addSingleton( ISingleton* singleton ); + void cleanupSingletons(); + + template + class Singleton : SingletonImplT, public ISingleton { + + static auto getInternal() -> Singleton* { + static Singleton* s_instance = nullptr; + if( !s_instance ) { + s_instance = new Singleton; + addSingleton( s_instance ); + } + return s_instance; + } + + public: + static auto get() -> InterfaceT const& { + return *getInternal(); + } + static auto getMutable() -> MutableInterfaceT& { + return *getInternal(); + } + }; + +} // namespace Catch + +// end catch_singletons.hpp +namespace Catch { + + namespace { + + class RegistryHub : public IRegistryHub, public IMutableRegistryHub, + private NonCopyable { + + public: // IRegistryHub + RegistryHub() = default; + IReporterRegistry const& getReporterRegistry() const override { + return m_reporterRegistry; + } + ITestCaseRegistry const& getTestCaseRegistry() const override { + return m_testCaseRegistry; + } + IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override { + return m_exceptionTranslatorRegistry; + } + ITagAliasRegistry const& getTagAliasRegistry() const override { + return m_tagAliasRegistry; + } + StartupExceptionRegistry const& getStartupExceptionRegistry() const override { + return m_exceptionRegistry; + } + + public: // IMutableRegistryHub + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerReporter( name, factory ); + } + void registerListener( IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerListener( factory ); + } + void registerTest( TestCase const& testInfo ) override { + m_testCaseRegistry.registerTest( testInfo ); + } + void registerTranslator( const IExceptionTranslator* translator ) override { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { + m_tagAliasRegistry.add( alias, tag, lineInfo ); + } + void registerStartupException() noexcept override { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + m_exceptionRegistry.add(std::current_exception()); +#else + CATCH_INTERNAL_ERROR("Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); +#endif + } + IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override { + return m_enumValuesRegistry; + } + + private: + TestRegistry m_testCaseRegistry; + ReporterRegistry m_reporterRegistry; + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + TagAliasRegistry m_tagAliasRegistry; + StartupExceptionRegistry m_exceptionRegistry; + Detail::EnumValuesRegistry m_enumValuesRegistry; + }; + } + + using RegistryHubSingleton = Singleton; + + IRegistryHub const& getRegistryHub() { + return RegistryHubSingleton::get(); + } + IMutableRegistryHub& getMutableRegistryHub() { + return RegistryHubSingleton::getMutable(); + } + void cleanUp() { + cleanupSingletons(); + cleanUpContext(); + } + std::string translateActiveException() { + return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); + } + +} // end namespace Catch +// end catch_registry_hub.cpp +// start catch_reporter_registry.cpp + +namespace Catch { + + ReporterRegistry::~ReporterRegistry() = default; + + IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { + auto it = m_factories.find( name ); + if( it == m_factories.end() ) + return nullptr; + return it->second->create( ReporterConfig( config ) ); + } + + void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { + m_factories.emplace(name, factory); + } + void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) { + m_listeners.push_back( factory ); + } + + IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const { + return m_factories; + } + IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { + return m_listeners; + } + +} +// end catch_reporter_registry.cpp +// start catch_result_type.cpp + +namespace Catch { + + bool isOk( ResultWas::OfType resultType ) { + return ( resultType & ResultWas::FailureBit ) == 0; + } + bool isJustInfo( int flags ) { + return flags == ResultWas::Info; + } + + ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { + return static_cast( static_cast( lhs ) | static_cast( rhs ) ); + } + + bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } + bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } + +} // end namespace Catch +// end catch_result_type.cpp +// start catch_run_context.cpp + +#include +#include +#include + +namespace Catch { + + namespace Generators { + struct GeneratorTracker : TestCaseTracking::TrackerBase, IGeneratorTracker { + GeneratorBasePtr m_generator; + + GeneratorTracker( TestCaseTracking::NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : TrackerBase( nameAndLocation, ctx, parent ) + {} + ~GeneratorTracker(); + + static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) { + std::shared_ptr tracker; + + ITracker& currentTracker = ctx.currentTracker(); + // Under specific circumstances, the generator we want + // to acquire is also the current tracker. If this is + // the case, we have to avoid looking through current + // tracker's children, and instead return the current + // tracker. + // A case where this check is important is e.g. + // for (int i = 0; i < 5; ++i) { + // int n = GENERATE(1, 2); + // } + // + // without it, the code above creates 5 nested generators. + if (currentTracker.nameAndLocation() == nameAndLocation) { + auto thisTracker = currentTracker.parent().findChild(nameAndLocation); + assert(thisTracker); + assert(thisTracker->isGeneratorTracker()); + tracker = std::static_pointer_cast(thisTracker); + } else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isGeneratorTracker() ); + tracker = std::static_pointer_cast( childTracker ); + } else { + tracker = std::make_shared( nameAndLocation, ctx, ¤tTracker ); + currentTracker.addChild( tracker ); + } + + if( !tracker->isComplete() ) { + tracker->open(); + } + + return *tracker; + } + + // TrackerBase interface + bool isGeneratorTracker() const override { return true; } + auto hasGenerator() const -> bool override { + return !!m_generator; + } + void close() override { + TrackerBase::close(); + // If a generator has a child (it is followed by a section) + // and none of its children have started, then we must wait + // until later to start consuming its values. + // This catches cases where `GENERATE` is placed between two + // `SECTION`s. + // **The check for m_children.empty cannot be removed**. + // doing so would break `GENERATE` _not_ followed by `SECTION`s. + const bool should_wait_for_child = [&]() { + // No children -> nobody to wait for + if ( m_children.empty() ) { + return false; + } + // If at least one child started executing, don't wait + if ( std::find_if( + m_children.begin(), + m_children.end(), + []( TestCaseTracking::ITrackerPtr tracker ) { + return tracker->hasStarted(); + } ) != m_children.end() ) { + return false; + } + + // No children have started. We need to check if they _can_ + // start, and thus we should wait for them, or they cannot + // start (due to filters), and we shouldn't wait for them + auto* parent = m_parent; + // This is safe: there is always at least one section + // tracker in a test case tracking tree + while ( !parent->isSectionTracker() ) { + parent = &( parent->parent() ); + } + assert( parent && + "Missing root (test case) level section" ); + + auto const& parentSection = + static_cast( *parent ); + auto const& filters = parentSection.getFilters(); + // No filters -> no restrictions on running sections + if ( filters.empty() ) { + return true; + } + + for ( auto const& child : m_children ) { + if ( child->isSectionTracker() && + std::find( filters.begin(), + filters.end(), + static_cast( *child ) + .trimmedName() ) != + filters.end() ) { + return true; + } + } + return false; + }(); + + // This check is a bit tricky, because m_generator->next() + // has a side-effect, where it consumes generator's current + // value, but we do not want to invoke the side-effect if + // this generator is still waiting for any child to start. + if ( should_wait_for_child || + ( m_runState == CompletedSuccessfully && + m_generator->next() ) ) { + m_children.clear(); + m_runState = Executing; + } + } + + // IGeneratorTracker interface + auto getGenerator() const -> GeneratorBasePtr const& override { + return m_generator; + } + void setGenerator( GeneratorBasePtr&& generator ) override { + m_generator = std::move( generator ); + } + }; + GeneratorTracker::~GeneratorTracker() {} + } + + RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter) + : m_runInfo(_config->name()), + m_context(getCurrentMutableContext()), + m_config(_config), + m_reporter(std::move(reporter)), + m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, + m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ) + { + m_context.setRunner(this); + m_context.setConfig(m_config); + m_context.setResultCapture(this); + m_reporter->testRunStarting(m_runInfo); + } + + RunContext::~RunContext() { + m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); + } + + void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) { + m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount)); + } + + void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) { + m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting())); + } + + Totals RunContext::runTest(TestCase const& testCase) { + Totals prevTotals = m_totals; + + std::string redirectedCout; + std::string redirectedCerr; + + auto const& testInfo = testCase.getTestCaseInfo(); + + m_reporter->testCaseStarting(testInfo); + + m_activeTestCase = &testCase; + + ITracker& rootTracker = m_trackerContext.startRun(); + assert(rootTracker.isSectionTracker()); + static_cast(rootTracker).addInitialFilters(m_config->getSectionsToRun()); + do { + m_trackerContext.startCycle(); + m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo)); + runCurrentTest(redirectedCout, redirectedCerr); + } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting()); + + Totals deltaTotals = m_totals.delta(prevTotals); + if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) { + deltaTotals.assertions.failed++; + deltaTotals.testCases.passed--; + deltaTotals.testCases.failed++; + } + m_totals.testCases += deltaTotals.testCases; + m_reporter->testCaseEnded(TestCaseStats(testInfo, + deltaTotals, + redirectedCout, + redirectedCerr, + aborting())); + + m_activeTestCase = nullptr; + m_testCaseTracker = nullptr; + + return deltaTotals; + } + + IConfigPtr RunContext::config() const { + return m_config; + } + + IStreamingReporter& RunContext::reporter() const { + return *m_reporter; + } + + void RunContext::assertionEnded(AssertionResult const & result) { + if (result.getResultType() == ResultWas::Ok) { + m_totals.assertions.passed++; + m_lastAssertionPassed = true; + } else if (!result.isOk()) { + m_lastAssertionPassed = false; + if( m_activeTestCase->getTestCaseInfo().okToFail() ) + m_totals.assertions.failedButOk++; + else + m_totals.assertions.failed++; + } + else { + m_lastAssertionPassed = true; + } + + // We have no use for the return value (whether messages should be cleared), because messages were made scoped + // and should be let to clear themselves out. + static_cast(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals))); + + if (result.getResultType() != ResultWas::Warning) + m_messageScopes.clear(); + + // Reset working state + resetAssertionInfo(); + m_lastResult = result; + } + void RunContext::resetAssertionInfo() { + m_lastAssertionInfo.macroName = StringRef(); + m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; + } + + bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) { + ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo)); + if (!sectionTracker.isOpen()) + return false; + m_activeSections.push_back(§ionTracker); + + m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; + + m_reporter->sectionStarting(sectionInfo); + + assertions = m_totals.assertions; + + return true; + } + auto RunContext::acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { + using namespace Generators; + GeneratorTracker& tracker = GeneratorTracker::acquire(m_trackerContext, + TestCaseTracking::NameAndLocation( static_cast(generatorName), lineInfo ) ); + m_lastAssertionInfo.lineInfo = lineInfo; + return tracker; + } + + bool RunContext::testForMissingAssertions(Counts& assertions) { + if (assertions.total() != 0) + return false; + if (!m_config->warnAboutMissingAssertions()) + return false; + if (m_trackerContext.currentTracker().hasChildren()) + return false; + m_totals.assertions.failed++; + assertions.failed++; + return true; + } + + void RunContext::sectionEnded(SectionEndInfo const & endInfo) { + Counts assertions = m_totals.assertions - endInfo.prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + + if (!m_activeSections.empty()) { + m_activeSections.back()->close(); + m_activeSections.pop_back(); + } + + m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions)); + m_messages.clear(); + m_messageScopes.clear(); + } + + void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) { + if (m_unfinishedSections.empty()) + m_activeSections.back()->fail(); + else + m_activeSections.back()->close(); + m_activeSections.pop_back(); + + m_unfinishedSections.push_back(endInfo); + } + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void RunContext::benchmarkPreparing(std::string const& name) { + m_reporter->benchmarkPreparing(name); + } + void RunContext::benchmarkStarting( BenchmarkInfo const& info ) { + m_reporter->benchmarkStarting( info ); + } + void RunContext::benchmarkEnded( BenchmarkStats<> const& stats ) { + m_reporter->benchmarkEnded( stats ); + } + void RunContext::benchmarkFailed(std::string const & error) { + m_reporter->benchmarkFailed(error); + } +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + void RunContext::pushScopedMessage(MessageInfo const & message) { + m_messages.push_back(message); + } + + void RunContext::popScopedMessage(MessageInfo const & message) { + m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); + } + + void RunContext::emplaceUnscopedMessage( MessageBuilder const& builder ) { + m_messageScopes.emplace_back( builder ); + } + + std::string RunContext::getCurrentTestName() const { + return m_activeTestCase + ? m_activeTestCase->getTestCaseInfo().name + : std::string(); + } + + const AssertionResult * RunContext::getLastResult() const { + return &(*m_lastResult); + } + + void RunContext::exceptionEarlyReported() { + m_shouldReportUnexpected = false; + } + + void RunContext::handleFatalErrorCondition( StringRef message ) { + // First notify reporter that bad things happened + m_reporter->fatalErrorEncountered(message); + + // Don't rebuild the result -- the stringification itself can cause more fatal errors + // Instead, fake a result data. + AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); + tempResult.message = static_cast(message); + AssertionResult result(m_lastAssertionInfo, tempResult); + + assertionEnded(result); + + handleUnfinishedSections(); + + // Recreate section for test case (as we will lose the one that was in scope) + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); + + Counts assertions; + assertions.failed = 1; + SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false); + m_reporter->sectionEnded(testCaseSectionStats); + + auto const& testInfo = m_activeTestCase->getTestCaseInfo(); + + Totals deltaTotals; + deltaTotals.testCases.failed = 1; + deltaTotals.assertions.failed = 1; + m_reporter->testCaseEnded(TestCaseStats(testInfo, + deltaTotals, + std::string(), + std::string(), + false)); + m_totals.testCases.failed++; + testGroupEnded(std::string(), m_totals, 1, 1); + m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); + } + + bool RunContext::lastAssertionPassed() { + return m_lastAssertionPassed; + } + + void RunContext::assertionPassed() { + m_lastAssertionPassed = true; + ++m_totals.assertions.passed; + resetAssertionInfo(); + m_messageScopes.clear(); + } + + bool RunContext::aborting() const { + return m_totals.assertions.failed >= static_cast(m_config->abortAfter()); + } + + void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); + m_reporter->sectionStarting(testCaseSection); + Counts prevAssertions = m_totals.assertions; + double duration = 0; + m_shouldReportUnexpected = true; + m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; + + seedRng(*m_config); + + Timer timer; + CATCH_TRY { + if (m_reporter->getPreferences().shouldRedirectStdOut) { +#if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) + RedirectedStreams redirectedStreams(redirectedCout, redirectedCerr); + + timer.start(); + invokeActiveTestCase(); +#else + OutputRedirect r(redirectedCout, redirectedCerr); + timer.start(); + invokeActiveTestCase(); +#endif + } else { + timer.start(); + invokeActiveTestCase(); + } + duration = timer.getElapsedSeconds(); + } CATCH_CATCH_ANON (TestFailureException&) { + // This just means the test was aborted due to failure + } CATCH_CATCH_ALL { + // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions + // are reported without translation at the point of origin. + if( m_shouldReportUnexpected ) { + AssertionReaction dummyReaction; + handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); + } + } + Counts assertions = m_totals.assertions - prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + + m_testCaseTracker->close(); + handleUnfinishedSections(); + m_messages.clear(); + m_messageScopes.clear(); + + SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); + m_reporter->sectionEnded(testCaseSectionStats); + } + + void RunContext::invokeActiveTestCase() { + FatalConditionHandlerGuard _(&m_fatalConditionhandler); + m_activeTestCase->invoke(); + } + + void RunContext::handleUnfinishedSections() { + // If sections ended prematurely due to an exception we stored their + // infos here so we can tear them down outside the unwind process. + for (auto it = m_unfinishedSections.rbegin(), + itEnd = m_unfinishedSections.rend(); + it != itEnd; + ++it) + sectionEnded(*it); + m_unfinishedSections.clear(); + } + + void RunContext::handleExpr( + AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction + ) { + m_reporter->assertionStarting( info ); + + bool negated = isFalseTest( info.resultDisposition ); + bool result = expr.getResult() != negated; + + if( result ) { + if (!m_includeSuccessfulResults) { + assertionPassed(); + } + else { + reportExpr(info, ResultWas::Ok, &expr, negated); + } + } + else { + reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); + populateReaction( reaction ); + } + } + void RunContext::reportExpr( + AssertionInfo const &info, + ResultWas::OfType resultType, + ITransientExpression const *expr, + bool negated ) { + + m_lastAssertionInfo = info; + AssertionResultData data( resultType, LazyExpression( negated ) ); + + AssertionResult assertionResult{ info, data }; + assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; + + assertionEnded( assertionResult ); + } + + void RunContext::handleMessage( + AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction + ) { + m_reporter->assertionStarting( info ); + + m_lastAssertionInfo = info; + + AssertionResultData data( resultType, LazyExpression( false ) ); + data.message = static_cast(message); + AssertionResult assertionResult{ m_lastAssertionInfo, data }; + assertionEnded( assertionResult ); + if( !assertionResult.isOk() ) + populateReaction( reaction ); + } + void RunContext::handleUnexpectedExceptionNotThrown( + AssertionInfo const& info, + AssertionReaction& reaction + ) { + handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction); + } + + void RunContext::handleUnexpectedInflightException( + AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); + data.message = message; + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + populateReaction( reaction ); + } + + void RunContext::populateReaction( AssertionReaction& reaction ) { + reaction.shouldDebugBreak = m_config->shouldDebugBreak(); + reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); + } + + void RunContext::handleIncomplete( + AssertionInfo const& info + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); + data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"; + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + } + void RunContext::handleNonExpr( + AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( resultType, LazyExpression( false ) ); + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + + if( !assertionResult.isOk() ) + populateReaction( reaction ); + } + + IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) + return *capture; + else + CATCH_INTERNAL_ERROR("No result capture instance"); + } + + void seedRng(IConfig const& config) { + if (config.rngSeed() != 0) { + std::srand(config.rngSeed()); + rng().seed(config.rngSeed()); + } + } + + unsigned int rngSeed() { + return getCurrentContext().getConfig()->rngSeed(); + } + +} +// end catch_run_context.cpp +// start catch_section.cpp + +namespace Catch { + + Section::Section( SectionInfo const& info ) + : m_info( info ), + m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) + { + m_timer.start(); + } + + Section::~Section() { + if( m_sectionIncluded ) { + SectionEndInfo endInfo{ m_info, m_assertions, m_timer.getElapsedSeconds() }; + if( uncaught_exceptions() ) + getResultCapture().sectionEndedEarly( endInfo ); + else + getResultCapture().sectionEnded( endInfo ); + } + } + + // This indicates whether the section should be executed or not + Section::operator bool() const { + return m_sectionIncluded; + } + +} // end namespace Catch +// end catch_section.cpp +// start catch_section_info.cpp + +namespace Catch { + + SectionInfo::SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name ) + : name( _name ), + lineInfo( _lineInfo ) + {} + +} // end namespace Catch +// end catch_section_info.cpp +// start catch_session.cpp + +// start catch_session.h + +#include + +namespace Catch { + + class Session : NonCopyable { + public: + + Session(); + ~Session() override; + + void showHelp() const; + void libIdentify(); + + int applyCommandLine( int argc, char const * const * argv ); + #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE) + int applyCommandLine( int argc, wchar_t const * const * argv ); + #endif + + void useConfigData( ConfigData const& configData ); + + template + int run(int argc, CharT const * const argv[]) { + if (m_startupExceptions) + return 1; + int returnCode = applyCommandLine(argc, argv); + if (returnCode == 0) + returnCode = run(); + return returnCode; + } + + int run(); + + clara::Parser const& cli() const; + void cli( clara::Parser const& newParser ); + ConfigData& configData(); + Config& config(); + private: + int runInternal(); + + clara::Parser m_cli; + ConfigData m_configData; + std::shared_ptr m_config; + bool m_startupExceptions = false; + }; + +} // end namespace Catch + +// end catch_session.h +// start catch_version.h + +#include + +namespace Catch { + + // Versioning information + struct Version { + Version( Version const& ) = delete; + Version& operator=( Version const& ) = delete; + Version( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ); + + unsigned int const majorVersion; + unsigned int const minorVersion; + unsigned int const patchNumber; + + // buildNumber is only used if branchName is not null + char const * const branchName; + unsigned int const buildNumber; + + friend std::ostream& operator << ( std::ostream& os, Version const& version ); + }; + + Version const& libraryVersion(); +} + +// end catch_version.h +#include +#include +#include +#include + +namespace Catch { + + namespace { + const int MaxExitCode = 255; + + IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) { + auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); + CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'"); + + return reporter; + } + + IStreamingReporterPtr makeReporter(std::shared_ptr const& config) { + if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) { + return createReporter(config->getReporterName(), config); + } + + // On older platforms, returning std::unique_ptr + // when the return type is std::unique_ptr + // doesn't compile without a std::move call. However, this causes + // a warning on newer platforms. Thus, we have to work around + // it a bit and downcast the pointer manually. + auto ret = std::unique_ptr(new ListeningReporter); + auto& multi = static_cast(*ret); + auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); + for (auto const& listener : listeners) { + multi.addListener(listener->create(Catch::ReporterConfig(config))); + } + multi.addReporter(createReporter(config->getReporterName(), config)); + return ret; + } + + class TestGroup { + public: + explicit TestGroup(std::shared_ptr const& config) + : m_config{config} + , m_context{config, makeReporter(config)} + { + auto const& allTestCases = getAllTestCasesSorted(*m_config); + m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config); + auto const& invalidArgs = m_config->testSpec().getInvalidArgs(); + + if (m_matches.empty() && invalidArgs.empty()) { + for (auto const& test : allTestCases) + if (!test.isHidden()) + m_tests.emplace(&test); + } else { + for (auto const& match : m_matches) + m_tests.insert(match.tests.begin(), match.tests.end()); + } + } + + Totals execute() { + auto const& invalidArgs = m_config->testSpec().getInvalidArgs(); + Totals totals; + m_context.testGroupStarting(m_config->name(), 1, 1); + for (auto const& testCase : m_tests) { + if (!m_context.aborting()) + totals += m_context.runTest(*testCase); + else + m_context.reporter().skipTest(*testCase); + } + + for (auto const& match : m_matches) { + if (match.tests.empty()) { + m_context.reporter().noMatchingTestCases(match.name); + totals.error = -1; + } + } + + if (!invalidArgs.empty()) { + for (auto const& invalidArg: invalidArgs) + m_context.reporter().reportInvalidArguments(invalidArg); + } + + m_context.testGroupEnded(m_config->name(), totals, 1, 1); + return totals; + } + + private: + using Tests = std::set; + + std::shared_ptr m_config; + RunContext m_context; + Tests m_tests; + TestSpec::Matches m_matches; + }; + + void applyFilenamesAsTags(Catch::IConfig const& config) { + auto& tests = const_cast&>(getAllTestCasesSorted(config)); + for (auto& testCase : tests) { + auto tags = testCase.tags; + + std::string filename = testCase.lineInfo.file; + auto lastSlash = filename.find_last_of("\\/"); + if (lastSlash != std::string::npos) { + filename.erase(0, lastSlash); + filename[0] = '#'; + } + else + { + filename.insert(0, "#"); + } + + auto lastDot = filename.find_last_of('.'); + if (lastDot != std::string::npos) { + filename.erase(lastDot); + } + + tags.push_back(std::move(filename)); + setTags(testCase, tags); + } + } + + } // anon namespace + + Session::Session() { + static bool alreadyInstantiated = false; + if( alreadyInstantiated ) { + CATCH_TRY { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); } + CATCH_CATCH_ALL { getMutableRegistryHub().registerStartupException(); } + } + + // There cannot be exceptions at startup in no-exception mode. +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); + if ( !exceptions.empty() ) { + config(); + getCurrentMutableContext().setConfig(m_config); + + m_startupExceptions = true; + Colour colourGuard( Colour::Red ); + Catch::cerr() << "Errors occurred during startup!" << '\n'; + // iterate over all exceptions and notify user + for ( const auto& ex_ptr : exceptions ) { + try { + std::rethrow_exception(ex_ptr); + } catch ( std::exception const& ex ) { + Catch::cerr() << Column( ex.what() ).indent(2) << '\n'; + } + } + } +#endif + + alreadyInstantiated = true; + m_cli = makeCommandLineParser( m_configData ); + } + Session::~Session() { + Catch::cleanUp(); + } + + void Session::showHelp() const { + Catch::cout() + << "\nCatch v" << libraryVersion() << "\n" + << m_cli << std::endl + << "For more detailed usage please see the project docs\n" << std::endl; + } + void Session::libIdentify() { + Catch::cout() + << std::left << std::setw(16) << "description: " << "A Catch2 test executable\n" + << std::left << std::setw(16) << "category: " << "testframework\n" + << std::left << std::setw(16) << "framework: " << "Catch Test\n" + << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; + } + + int Session::applyCommandLine( int argc, char const * const * argv ) { + if( m_startupExceptions ) + return 1; + + auto result = m_cli.parse( clara::Args( argc, argv ) ); + if( !result ) { + config(); + getCurrentMutableContext().setConfig(m_config); + Catch::cerr() + << Colour( Colour::Red ) + << "\nError(s) in input:\n" + << Column( result.errorMessage() ).indent( 2 ) + << "\n\n"; + Catch::cerr() << "Run with -? for usage\n" << std::endl; + return MaxExitCode; + } + + if( m_configData.showHelp ) + showHelp(); + if( m_configData.libIdentify ) + libIdentify(); + m_config.reset(); + return 0; + } + +#if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE) + int Session::applyCommandLine( int argc, wchar_t const * const * argv ) { + + char **utf8Argv = new char *[ argc ]; + + for ( int i = 0; i < argc; ++i ) { + int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, nullptr, 0, nullptr, nullptr ); + + utf8Argv[ i ] = new char[ bufSize ]; + + WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, nullptr, nullptr ); + } + + int returnCode = applyCommandLine( argc, utf8Argv ); + + for ( int i = 0; i < argc; ++i ) + delete [] utf8Argv[ i ]; + + delete [] utf8Argv; + + return returnCode; + } +#endif + + void Session::useConfigData( ConfigData const& configData ) { + m_configData = configData; + m_config.reset(); + } + + int Session::run() { + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before starting" << std::endl; + static_cast(std::getchar()); + } + int exitCode = runInternal(); + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; + static_cast(std::getchar()); + } + return exitCode; + } + + clara::Parser const& Session::cli() const { + return m_cli; + } + void Session::cli( clara::Parser const& newParser ) { + m_cli = newParser; + } + ConfigData& Session::configData() { + return m_configData; + } + Config& Session::config() { + if( !m_config ) + m_config = std::make_shared( m_configData ); + return *m_config; + } + + int Session::runInternal() { + if( m_startupExceptions ) + return 1; + + if (m_configData.showHelp || m_configData.libIdentify) { + return 0; + } + + CATCH_TRY { + config(); // Force config to be constructed + + seedRng( *m_config ); + + if( m_configData.filenamesAsTags ) + applyFilenamesAsTags( *m_config ); + + // Handle list request + if( Option listed = list( m_config ) ) + return (std::min) (MaxExitCode, static_cast(*listed)); + + TestGroup tests { m_config }; + auto const totals = tests.execute(); + + if( m_config->warnAboutNoTests() && totals.error == -1 ) + return 2; + + // Note that on unices only the lower 8 bits are usually used, clamping + // the return value to 255 prevents false negative when some multiple + // of 256 tests has failed + return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast(totals.assertions.failed))); + } +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + catch( std::exception& ex ) { + Catch::cerr() << ex.what() << std::endl; + return MaxExitCode; + } +#endif + } + +} // end namespace Catch +// end catch_session.cpp +// start catch_singletons.cpp + +#include + +namespace Catch { + + namespace { + static auto getSingletons() -> std::vector*& { + static std::vector* g_singletons = nullptr; + if( !g_singletons ) + g_singletons = new std::vector(); + return g_singletons; + } + } + + ISingleton::~ISingleton() {} + + void addSingleton(ISingleton* singleton ) { + getSingletons()->push_back( singleton ); + } + void cleanupSingletons() { + auto& singletons = getSingletons(); + for( auto singleton : *singletons ) + delete singleton; + delete singletons; + singletons = nullptr; + } + +} // namespace Catch +// end catch_singletons.cpp +// start catch_startup_exception_registry.cpp + +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +namespace Catch { +void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { + CATCH_TRY { + m_exceptions.push_back(exception); + } CATCH_CATCH_ALL { + // If we run out of memory during start-up there's really not a lot more we can do about it + std::terminate(); + } + } + + std::vector const& StartupExceptionRegistry::getExceptions() const noexcept { + return m_exceptions; + } + +} // end namespace Catch +#endif +// end catch_startup_exception_registry.cpp +// start catch_stream.cpp + +#include +#include +#include +#include +#include +#include + +namespace Catch { + + Catch::IStream::~IStream() = default; + + namespace Detail { namespace { + template + class StreamBufImpl : public std::streambuf { + char data[bufferSize]; + WriterF m_writer; + + public: + StreamBufImpl() { + setp( data, data + sizeof(data) ); + } + + ~StreamBufImpl() noexcept { + StreamBufImpl::sync(); + } + + private: + int overflow( int c ) override { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast( c ) ) ); + else + sputc( static_cast( c ) ); + } + return 0; + } + + int sync() override { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); + } + return 0; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + struct OutputDebugWriter { + + void operator()( std::string const&str ) { + writeToDebugConsole( str ); + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class FileStream : public IStream { + mutable std::ofstream m_ofs; + public: + FileStream( StringRef filename ) { + m_ofs.open( filename.c_str() ); + CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" ); + } + ~FileStream() override = default; + public: // IStream + std::ostream& stream() const override { + return m_ofs; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class CoutStream : public IStream { + mutable std::ostream m_os; + public: + // Store the streambuf from cout up-front because + // cout may get redirected when running tests + CoutStream() : m_os( Catch::cout().rdbuf() ) {} + ~CoutStream() override = default; + + public: // IStream + std::ostream& stream() const override { return m_os; } + }; + + /////////////////////////////////////////////////////////////////////////// + + class DebugOutStream : public IStream { + std::unique_ptr> m_streamBuf; + mutable std::ostream m_os; + public: + DebugOutStream() + : m_streamBuf( new StreamBufImpl() ), + m_os( m_streamBuf.get() ) + {} + + ~DebugOutStream() override = default; + + public: // IStream + std::ostream& stream() const override { return m_os; } + }; + + }} // namespace anon::detail + + /////////////////////////////////////////////////////////////////////////// + + auto makeStream( StringRef const &filename ) -> IStream const* { + if( filename.empty() ) + return new Detail::CoutStream(); + else if( filename[0] == '%' ) { + if( filename == "%debug" ) + return new Detail::DebugOutStream(); + else + CATCH_ERROR( "Unrecognised stream: '" << filename << "'" ); + } + else + return new Detail::FileStream( filename ); + } + + // This class encapsulates the idea of a pool of ostringstreams that can be reused. + struct StringStreams { + std::vector> m_streams; + std::vector m_unused; + std::ostringstream m_referenceStream; // Used for copy state/ flags from + + auto add() -> std::size_t { + if( m_unused.empty() ) { + m_streams.push_back( std::unique_ptr( new std::ostringstream ) ); + return m_streams.size()-1; + } + else { + auto index = m_unused.back(); + m_unused.pop_back(); + return index; + } + } + + void release( std::size_t index ) { + m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state + m_unused.push_back(index); + } + }; + + ReusableStringStream::ReusableStringStream() + : m_index( Singleton::getMutable().add() ), + m_oss( Singleton::getMutable().m_streams[m_index].get() ) + {} + + ReusableStringStream::~ReusableStringStream() { + static_cast( m_oss )->str(""); + m_oss->clear(); + Singleton::getMutable().release( m_index ); + } + + auto ReusableStringStream::str() const -> std::string { + return static_cast( m_oss )->str(); + } + + /////////////////////////////////////////////////////////////////////////// + +#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions + std::ostream& cout() { return std::cout; } + std::ostream& cerr() { return std::cerr; } + std::ostream& clog() { return std::clog; } +#endif +} +// end catch_stream.cpp +// start catch_string_manip.cpp + +#include +#include +#include +#include +#include + +namespace Catch { + + namespace { + char toLowerCh(char c) { + return static_cast( std::tolower( static_cast(c) ) ); + } + } + + bool startsWith( std::string const& s, std::string const& prefix ) { + return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); + } + bool startsWith( std::string const& s, char prefix ) { + return !s.empty() && s[0] == prefix; + } + bool endsWith( std::string const& s, std::string const& suffix ) { + return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); + } + bool endsWith( std::string const& s, char suffix ) { + return !s.empty() && s[s.size()-1] == suffix; + } + bool contains( std::string const& s, std::string const& infix ) { + return s.find( infix ) != std::string::npos; + } + void toLowerInPlace( std::string& s ) { + std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); + } + std::string toLower( std::string const& s ) { + std::string lc = s; + toLowerInPlace( lc ); + return lc; + } + std::string trim( std::string const& str ) { + static char const* whitespaceChars = "\n\r\t "; + std::string::size_type start = str.find_first_not_of( whitespaceChars ); + std::string::size_type end = str.find_last_not_of( whitespaceChars ); + + return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); + } + + StringRef trim(StringRef ref) { + const auto is_ws = [](char c) { + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; + }; + size_t real_begin = 0; + while (real_begin < ref.size() && is_ws(ref[real_begin])) { ++real_begin; } + size_t real_end = ref.size(); + while (real_end > real_begin && is_ws(ref[real_end - 1])) { --real_end; } + + return ref.substr(real_begin, real_end - real_begin); + } + + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { + bool replaced = false; + std::size_t i = str.find( replaceThis ); + while( i != std::string::npos ) { + replaced = true; + str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); + if( i < str.size()-withThis.size() ) + i = str.find( replaceThis, i+withThis.size() ); + else + i = std::string::npos; + } + return replaced; + } + + std::vector splitStringRef( StringRef str, char delimiter ) { + std::vector subStrings; + std::size_t start = 0; + for(std::size_t pos = 0; pos < str.size(); ++pos ) { + if( str[pos] == delimiter ) { + if( pos - start > 1 ) + subStrings.push_back( str.substr( start, pos-start ) ); + start = pos+1; + } + } + if( start < str.size() ) + subStrings.push_back( str.substr( start, str.size()-start ) ); + return subStrings; + } + + pluralise::pluralise( std::size_t count, std::string const& label ) + : m_count( count ), + m_label( label ) + {} + + std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { + os << pluraliser.m_count << ' ' << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << 's'; + return os; + } + +} +// end catch_string_manip.cpp +// start catch_stringref.cpp + +#include +#include +#include +#include + +namespace Catch { + StringRef::StringRef( char const* rawChars ) noexcept + : StringRef( rawChars, static_cast(std::strlen(rawChars) ) ) + {} + + auto StringRef::c_str() const -> char const* { + CATCH_ENFORCE(isNullTerminated(), "Called StringRef::c_str() on a non-null-terminated instance"); + return m_start; + } + auto StringRef::data() const noexcept -> char const* { + return m_start; + } + + auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { + if (start < m_size) { + return StringRef(m_start + start, (std::min)(m_size - start, size)); + } else { + return StringRef(); + } + } + auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool { + return m_size == other.m_size + && (std::memcmp( m_start, other.m_start, m_size ) == 0); + } + + auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { + return os.write(str.data(), str.size()); + } + + auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { + lhs.append(rhs.data(), rhs.size()); + return lhs; + } + +} // namespace Catch +// end catch_stringref.cpp +// start catch_tag_alias.cpp + +namespace Catch { + TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {} +} +// end catch_tag_alias.cpp +// start catch_tag_alias_autoregistrar.cpp + +namespace Catch { + + RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) { + CATCH_TRY { + getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo); + } CATCH_CATCH_ALL { + // Do not throw when constructing global objects, instead register the exception to be processed later + getMutableRegistryHub().registerStartupException(); + } + } + +} +// end catch_tag_alias_autoregistrar.cpp +// start catch_tag_alias_registry.cpp + +#include + +namespace Catch { + + TagAliasRegistry::~TagAliasRegistry() {} + + TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { + auto it = m_registry.find( alias ); + if( it != m_registry.end() ) + return &(it->second); + else + return nullptr; + } + + std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { + std::string expandedTestSpec = unexpandedTestSpec; + for( auto const& registryKvp : m_registry ) { + std::size_t pos = expandedTestSpec.find( registryKvp.first ); + if( pos != std::string::npos ) { + expandedTestSpec = expandedTestSpec.substr( 0, pos ) + + registryKvp.second.tag + + expandedTestSpec.substr( pos + registryKvp.first.size() ); + } + } + return expandedTestSpec; + } + + void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { + CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'), + "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo ); + + CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, + "error: tag alias, '" << alias << "' already registered.\n" + << "\tFirst seen at: " << find(alias)->lineInfo << "\n" + << "\tRedefined at: " << lineInfo ); + } + + ITagAliasRegistry::~ITagAliasRegistry() {} + + ITagAliasRegistry const& ITagAliasRegistry::get() { + return getRegistryHub().getTagAliasRegistry(); + } + +} // end namespace Catch +// end catch_tag_alias_registry.cpp +// start catch_test_case_info.cpp + +#include +#include +#include +#include + +namespace Catch { + + namespace { + TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { + if( startsWith( tag, '.' ) || + tag == "!hide" ) + return TestCaseInfo::IsHidden; + else if( tag == "!throws" ) + return TestCaseInfo::Throws; + else if( tag == "!shouldfail" ) + return TestCaseInfo::ShouldFail; + else if( tag == "!mayfail" ) + return TestCaseInfo::MayFail; + else if( tag == "!nonportable" ) + return TestCaseInfo::NonPortable; + else if( tag == "!benchmark" ) + return static_cast( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden ); + else + return TestCaseInfo::None; + } + bool isReservedTag( std::string const& tag ) { + return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( static_cast(tag[0]) ); + } + void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { + CATCH_ENFORCE( !isReservedTag(tag), + "Tag name: [" << tag << "] is not allowed.\n" + << "Tag names starting with non alphanumeric characters are reserved\n" + << _lineInfo ); + } + } + + TestCase makeTestCase( ITestInvoker* _testCase, + std::string const& _className, + NameAndTags const& nameAndTags, + SourceLineInfo const& _lineInfo ) + { + bool isHidden = false; + + // Parse out tags + std::vector tags; + std::string desc, tag; + bool inTag = false; + for (char c : nameAndTags.tags) { + if( !inTag ) { + if( c == '[' ) + inTag = true; + else + desc += c; + } + else { + if( c == ']' ) { + TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); + if( ( prop & TestCaseInfo::IsHidden ) != 0 ) + isHidden = true; + else if( prop == TestCaseInfo::None ) + enforceNotReservedTag( tag, _lineInfo ); + + // Merged hide tags like `[.approvals]` should be added as + // `[.][approvals]`. The `[.]` is added at later point, so + // we only strip the prefix + if (startsWith(tag, '.') && tag.size() > 1) { + tag.erase(0, 1); + } + tags.push_back( tag ); + tag.clear(); + inTag = false; + } + else + tag += c; + } + } + if( isHidden ) { + // Add all "hidden" tags to make them behave identically + tags.insert( tags.end(), { ".", "!hide" } ); + } + + TestCaseInfo info( static_cast(nameAndTags.name), _className, desc, tags, _lineInfo ); + return TestCase( _testCase, std::move(info) ); + } + + void setTags( TestCaseInfo& testCaseInfo, std::vector tags ) { + std::sort(begin(tags), end(tags)); + tags.erase(std::unique(begin(tags), end(tags)), end(tags)); + testCaseInfo.lcaseTags.clear(); + + for( auto const& tag : tags ) { + std::string lcaseTag = toLower( tag ); + testCaseInfo.properties = static_cast( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); + testCaseInfo.lcaseTags.push_back( lcaseTag ); + } + testCaseInfo.tags = std::move(tags); + } + + TestCaseInfo::TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::vector const& _tags, + SourceLineInfo const& _lineInfo ) + : name( _name ), + className( _className ), + description( _description ), + lineInfo( _lineInfo ), + properties( None ) + { + setTags( *this, _tags ); + } + + bool TestCaseInfo::isHidden() const { + return ( properties & IsHidden ) != 0; + } + bool TestCaseInfo::throws() const { + return ( properties & Throws ) != 0; + } + bool TestCaseInfo::okToFail() const { + return ( properties & (ShouldFail | MayFail ) ) != 0; + } + bool TestCaseInfo::expectedToFail() const { + return ( properties & (ShouldFail ) ) != 0; + } + + std::string TestCaseInfo::tagsAsString() const { + std::string ret; + // '[' and ']' per tag + std::size_t full_size = 2 * tags.size(); + for (const auto& tag : tags) { + full_size += tag.size(); + } + ret.reserve(full_size); + for (const auto& tag : tags) { + ret.push_back('['); + ret.append(tag); + ret.push_back(']'); + } + + return ret; + } + + TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {} + + TestCase TestCase::withName( std::string const& _newName ) const { + TestCase other( *this ); + other.name = _newName; + return other; + } + + void TestCase::invoke() const { + test->invoke(); + } + + bool TestCase::operator == ( TestCase const& other ) const { + return test.get() == other.test.get() && + name == other.name && + className == other.className; + } + + bool TestCase::operator < ( TestCase const& other ) const { + return name < other.name; + } + + TestCaseInfo const& TestCase::getTestCaseInfo() const + { + return *this; + } + +} // end namespace Catch +// end catch_test_case_info.cpp +// start catch_test_case_registry_impl.cpp + +#include +#include + +namespace Catch { + + namespace { + struct TestHasher { + using hash_t = uint64_t; + + explicit TestHasher( hash_t hashSuffix ): + m_hashSuffix{ hashSuffix } {} + + uint32_t operator()( TestCase const& t ) const { + // FNV-1a hash with multiplication fold. + const hash_t prime = 1099511628211u; + hash_t hash = 14695981039346656037u; + for ( const char c : t.name ) { + hash ^= c; + hash *= prime; + } + hash ^= m_hashSuffix; + hash *= prime; + const uint32_t low{ static_cast( hash ) }; + const uint32_t high{ static_cast( hash >> 32 ) }; + return low * high; + } + + private: + hash_t m_hashSuffix; + }; + } // end unnamed namespace + + std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ) { + switch( config.runOrder() ) { + case RunTests::InDeclarationOrder: + // already in declaration order + break; + + case RunTests::InLexicographicalOrder: { + std::vector sorted = unsortedTestCases; + std::sort( sorted.begin(), sorted.end() ); + return sorted; + } + + case RunTests::InRandomOrder: { + seedRng( config ); + TestHasher h{ config.rngSeed() }; + + using hashedTest = std::pair; + std::vector indexed_tests; + indexed_tests.reserve( unsortedTestCases.size() ); + + for (auto const& testCase : unsortedTestCases) { + indexed_tests.emplace_back(h(testCase), &testCase); + } + + std::sort(indexed_tests.begin(), indexed_tests.end(), + [](hashedTest const& lhs, hashedTest const& rhs) { + if (lhs.first == rhs.first) { + return lhs.second->name < rhs.second->name; + } + return lhs.first < rhs.first; + }); + + std::vector sorted; + sorted.reserve( indexed_tests.size() ); + + for (auto const& hashed : indexed_tests) { + sorted.emplace_back(*hashed.second); + } + + return sorted; + } + } + return unsortedTestCases; + } + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ) { + return !testCase.throws() || config.allowThrows(); + } + + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { + return testSpec.matches( testCase ) && isThrowSafe( testCase, config ); + } + + void enforceNoDuplicateTestCases( std::vector const& functions ) { + std::set seenFunctions; + for( auto const& function : functions ) { + auto prev = seenFunctions.insert( function ); + CATCH_ENFORCE( prev.second, + "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n" + << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" + << "\tRedefined at " << function.getTestCaseInfo().lineInfo ); + } + } + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ) { + std::vector filtered; + filtered.reserve( testCases.size() ); + for (auto const& testCase : testCases) { + if ((!testSpec.hasFilters() && !testCase.isHidden()) || + (testSpec.hasFilters() && matchTest(testCase, testSpec, config))) { + filtered.push_back(testCase); + } + } + return filtered; + } + std::vector const& getAllTestCasesSorted( IConfig const& config ) { + return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); + } + + void TestRegistry::registerTest( TestCase const& testCase ) { + std::string name = testCase.getTestCaseInfo().name; + if( name.empty() ) { + ReusableStringStream rss; + rss << "Anonymous test case " << ++m_unnamedCount; + return registerTest( testCase.withName( rss.str() ) ); + } + m_functions.push_back( testCase ); + } + + std::vector const& TestRegistry::getAllTests() const { + return m_functions; + } + std::vector const& TestRegistry::getAllTestsSorted( IConfig const& config ) const { + if( m_sortedFunctions.empty() ) + enforceNoDuplicateTestCases( m_functions ); + + if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { + m_sortedFunctions = sortTests( config, m_functions ); + m_currentSortOrder = config.runOrder(); + } + return m_sortedFunctions; + } + + /////////////////////////////////////////////////////////////////////////// + TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {} + + void TestInvokerAsFunction::invoke() const { + m_testAsFunction(); + } + + std::string extractClassName( StringRef const& classOrQualifiedMethodName ) { + std::string className(classOrQualifiedMethodName); + if( startsWith( className, '&' ) ) + { + std::size_t lastColons = className.rfind( "::" ); + std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); + if( penultimateColons == std::string::npos ) + penultimateColons = 1; + className = className.substr( penultimateColons, lastColons-penultimateColons ); + } + return className; + } + +} // end namespace Catch +// end catch_test_case_registry_impl.cpp +// start catch_test_case_tracker.cpp + +#include +#include +#include +#include +#include + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +namespace Catch { +namespace TestCaseTracking { + + NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) + : name( _name ), + location( _location ) + {} + + ITracker::~ITracker() = default; + + ITracker& TrackerContext::startRun() { + m_rootTracker = std::make_shared( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr ); + m_currentTracker = nullptr; + m_runState = Executing; + return *m_rootTracker; + } + + void TrackerContext::endRun() { + m_rootTracker.reset(); + m_currentTracker = nullptr; + m_runState = NotStarted; + } + + void TrackerContext::startCycle() { + m_currentTracker = m_rootTracker.get(); + m_runState = Executing; + } + void TrackerContext::completeCycle() { + m_runState = CompletedCycle; + } + + bool TrackerContext::completedCycle() const { + return m_runState == CompletedCycle; + } + ITracker& TrackerContext::currentTracker() { + return *m_currentTracker; + } + void TrackerContext::setCurrentTracker( ITracker* tracker ) { + m_currentTracker = tracker; + } + + TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ): + ITracker(nameAndLocation), + m_ctx( ctx ), + m_parent( parent ) + {} + + bool TrackerBase::isComplete() const { + return m_runState == CompletedSuccessfully || m_runState == Failed; + } + bool TrackerBase::isSuccessfullyCompleted() const { + return m_runState == CompletedSuccessfully; + } + bool TrackerBase::isOpen() const { + return m_runState != NotStarted && !isComplete(); + } + bool TrackerBase::hasChildren() const { + return !m_children.empty(); + } + + void TrackerBase::addChild( ITrackerPtr const& child ) { + m_children.push_back( child ); + } + + ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) { + auto it = std::find_if( m_children.begin(), m_children.end(), + [&nameAndLocation]( ITrackerPtr const& tracker ){ + return + tracker->nameAndLocation().location == nameAndLocation.location && + tracker->nameAndLocation().name == nameAndLocation.name; + } ); + return( it != m_children.end() ) + ? *it + : nullptr; + } + ITracker& TrackerBase::parent() { + assert( m_parent ); // Should always be non-null except for root + return *m_parent; + } + + void TrackerBase::openChild() { + if( m_runState != ExecutingChildren ) { + m_runState = ExecutingChildren; + if( m_parent ) + m_parent->openChild(); + } + } + + bool TrackerBase::isSectionTracker() const { return false; } + bool TrackerBase::isGeneratorTracker() const { return false; } + + void TrackerBase::open() { + m_runState = Executing; + moveToThis(); + if( m_parent ) + m_parent->openChild(); + } + + void TrackerBase::close() { + + // Close any still open children (e.g. generators) + while( &m_ctx.currentTracker() != this ) + m_ctx.currentTracker().close(); + + switch( m_runState ) { + case NeedsAnotherRun: + break; + + case Executing: + m_runState = CompletedSuccessfully; + break; + case ExecutingChildren: + if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr const& t){ return t->isComplete(); }) ) + m_runState = CompletedSuccessfully; + break; + + case NotStarted: + case CompletedSuccessfully: + case Failed: + CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState ); + + default: + CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState ); + } + moveToParent(); + m_ctx.completeCycle(); + } + void TrackerBase::fail() { + m_runState = Failed; + if( m_parent ) + m_parent->markAsNeedingAnotherRun(); + moveToParent(); + m_ctx.completeCycle(); + } + void TrackerBase::markAsNeedingAnotherRun() { + m_runState = NeedsAnotherRun; + } + + void TrackerBase::moveToParent() { + assert( m_parent ); + m_ctx.setCurrentTracker( m_parent ); + } + void TrackerBase::moveToThis() { + m_ctx.setCurrentTracker( this ); + } + + SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : TrackerBase( nameAndLocation, ctx, parent ), + m_trimmed_name(trim(nameAndLocation.name)) + { + if( parent ) { + while( !parent->isSectionTracker() ) + parent = &parent->parent(); + + SectionTracker& parentSection = static_cast( *parent ); + addNextFilters( parentSection.m_filters ); + } + } + + bool SectionTracker::isComplete() const { + bool complete = true; + + if (m_filters.empty() + || m_filters[0] == "" + || std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) { + complete = TrackerBase::isComplete(); + } + return complete; + } + + bool SectionTracker::isSectionTracker() const { return true; } + + SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { + std::shared_ptr section; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isSectionTracker() ); + section = std::static_pointer_cast( childTracker ); + } + else { + section = std::make_shared( nameAndLocation, ctx, ¤tTracker ); + currentTracker.addChild( section ); + } + if( !ctx.completedCycle() ) + section->tryOpen(); + return *section; + } + + void SectionTracker::tryOpen() { + if( !isComplete() ) + open(); + } + + void SectionTracker::addInitialFilters( std::vector const& filters ) { + if( !filters.empty() ) { + m_filters.reserve( m_filters.size() + filters.size() + 2 ); + m_filters.emplace_back(""); // Root - should never be consulted + m_filters.emplace_back(""); // Test Case - not a section filter + m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); + } + } + void SectionTracker::addNextFilters( std::vector const& filters ) { + if( filters.size() > 1 ) + m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() ); + } + + std::vector const& SectionTracker::getFilters() const { + return m_filters; + } + + std::string const& SectionTracker::trimmedName() const { + return m_trimmed_name; + } + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; + +} // namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_test_case_tracker.cpp +// start catch_test_registry.cpp + +namespace Catch { + + auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* { + return new(std::nothrow) TestInvokerAsFunction( testAsFunction ); + } + + NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {} + + AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { + CATCH_TRY { + getMutableRegistryHub() + .registerTest( + makeTestCase( + invoker, + extractClassName( classOrMethod ), + nameAndTags, + lineInfo)); + } CATCH_CATCH_ALL { + // Do not throw when constructing global objects, instead register the exception to be processed later + getMutableRegistryHub().registerStartupException(); + } + } + + AutoReg::~AutoReg() = default; +} +// end catch_test_registry.cpp +// start catch_test_spec.cpp + +#include +#include +#include +#include + +namespace Catch { + + TestSpec::Pattern::Pattern( std::string const& name ) + : m_name( name ) + {} + + TestSpec::Pattern::~Pattern() = default; + + std::string const& TestSpec::Pattern::name() const { + return m_name; + } + + TestSpec::NamePattern::NamePattern( std::string const& name, std::string const& filterString ) + : Pattern( filterString ) + , m_wildcardPattern( toLower( name ), CaseSensitive::No ) + {} + + bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { + return m_wildcardPattern.matches( testCase.name ); + } + + TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString ) + : Pattern( filterString ) + , m_tag( toLower( tag ) ) + {} + + bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { + return std::find(begin(testCase.lcaseTags), + end(testCase.lcaseTags), + m_tag) != end(testCase.lcaseTags); + } + + TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) + : Pattern( underlyingPattern->name() ) + , m_underlyingPattern( underlyingPattern ) + {} + + bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { + return !m_underlyingPattern->matches( testCase ); + } + + bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { + return std::all_of( m_patterns.begin(), m_patterns.end(), [&]( PatternPtr const& p ){ return p->matches( testCase ); } ); + } + + std::string TestSpec::Filter::name() const { + std::string name; + for( auto const& p : m_patterns ) + name += p->name(); + return name; + } + + bool TestSpec::hasFilters() const { + return !m_filters.empty(); + } + + bool TestSpec::matches( TestCaseInfo const& testCase ) const { + return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } ); + } + + TestSpec::Matches TestSpec::matchesByFilter( std::vector const& testCases, IConfig const& config ) const + { + Matches matches( m_filters.size() ); + std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter const& filter ){ + std::vector currentMatches; + for( auto const& test : testCases ) + if( isThrowSafe( test, config ) && filter.matches( test ) ) + currentMatches.emplace_back( &test ); + return FilterMatch{ filter.name(), currentMatches }; + } ); + return matches; + } + + const TestSpec::vectorStrings& TestSpec::getInvalidArgs() const{ + return (m_invalidArgs); + } + +} +// end catch_test_spec.cpp +// start catch_test_spec_parser.cpp + +namespace Catch { + + TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} + + TestSpecParser& TestSpecParser::parse( std::string const& arg ) { + m_mode = None; + m_exclusion = false; + m_arg = m_tagAliases->expandAliases( arg ); + m_escapeChars.clear(); + m_substring.reserve(m_arg.size()); + m_patternName.reserve(m_arg.size()); + m_realPatternPos = 0; + + for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) + //if visitChar fails + if( !visitChar( m_arg[m_pos] ) ){ + m_testSpec.m_invalidArgs.push_back(arg); + break; + } + endMode(); + return *this; + } + TestSpec TestSpecParser::testSpec() { + addFilter(); + return m_testSpec; + } + bool TestSpecParser::visitChar( char c ) { + if( (m_mode != EscapedName) && (c == '\\') ) { + escape(); + addCharToPattern(c); + return true; + }else if((m_mode != EscapedName) && (c == ',') ) { + return separate(); + } + + switch( m_mode ) { + case None: + if( processNoneChar( c ) ) + return true; + break; + case Name: + processNameChar( c ); + break; + case EscapedName: + endMode(); + addCharToPattern(c); + return true; + default: + case Tag: + case QuotedName: + if( processOtherChar( c ) ) + return true; + break; + } + + m_substring += c; + if( !isControlChar( c ) ) { + m_patternName += c; + m_realPatternPos++; + } + return true; + } + // Two of the processing methods return true to signal the caller to return + // without adding the given character to the current pattern strings + bool TestSpecParser::processNoneChar( char c ) { + switch( c ) { + case ' ': + return true; + case '~': + m_exclusion = true; + return false; + case '[': + startNewMode( Tag ); + return false; + case '"': + startNewMode( QuotedName ); + return false; + default: + startNewMode( Name ); + return false; + } + } + void TestSpecParser::processNameChar( char c ) { + if( c == '[' ) { + if( m_substring == "exclude:" ) + m_exclusion = true; + else + endMode(); + startNewMode( Tag ); + } + } + bool TestSpecParser::processOtherChar( char c ) { + if( !isControlChar( c ) ) + return false; + m_substring += c; + endMode(); + return true; + } + void TestSpecParser::startNewMode( Mode mode ) { + m_mode = mode; + } + void TestSpecParser::endMode() { + switch( m_mode ) { + case Name: + case QuotedName: + return addNamePattern(); + case Tag: + return addTagPattern(); + case EscapedName: + revertBackToLastMode(); + return; + case None: + default: + return startNewMode( None ); + } + } + void TestSpecParser::escape() { + saveLastMode(); + m_mode = EscapedName; + m_escapeChars.push_back(m_realPatternPos); + } + bool TestSpecParser::isControlChar( char c ) const { + switch( m_mode ) { + default: + return false; + case None: + return c == '~'; + case Name: + return c == '['; + case EscapedName: + return true; + case QuotedName: + return c == '"'; + case Tag: + return c == '[' || c == ']'; + } + } + + void TestSpecParser::addFilter() { + if( !m_currentFilter.m_patterns.empty() ) { + m_testSpec.m_filters.push_back( m_currentFilter ); + m_currentFilter = TestSpec::Filter(); + } + } + + void TestSpecParser::saveLastMode() { + lastMode = m_mode; + } + + void TestSpecParser::revertBackToLastMode() { + m_mode = lastMode; + } + + bool TestSpecParser::separate() { + if( (m_mode==QuotedName) || (m_mode==Tag) ){ + //invalid argument, signal failure to previous scope. + m_mode = None; + m_pos = m_arg.size(); + m_substring.clear(); + m_patternName.clear(); + m_realPatternPos = 0; + return false; + } + endMode(); + addFilter(); + return true; //success + } + + std::string TestSpecParser::preprocessPattern() { + std::string token = m_patternName; + for (std::size_t i = 0; i < m_escapeChars.size(); ++i) + token = token.substr(0, m_escapeChars[i] - i) + token.substr(m_escapeChars[i] - i + 1); + m_escapeChars.clear(); + if (startsWith(token, "exclude:")) { + m_exclusion = true; + token = token.substr(8); + } + + m_patternName.clear(); + m_realPatternPos = 0; + + return token; + } + + void TestSpecParser::addNamePattern() { + auto token = preprocessPattern(); + + if (!token.empty()) { + TestSpec::PatternPtr pattern = std::make_shared(token, m_substring); + if (m_exclusion) + pattern = std::make_shared(pattern); + m_currentFilter.m_patterns.push_back(pattern); + } + m_substring.clear(); + m_exclusion = false; + m_mode = None; + } + + void TestSpecParser::addTagPattern() { + auto token = preprocessPattern(); + + if (!token.empty()) { + // If the tag pattern is the "hide and tag" shorthand (e.g. [.foo]) + // we have to create a separate hide tag and shorten the real one + if (token.size() > 1 && token[0] == '.') { + token.erase(token.begin()); + TestSpec::PatternPtr pattern = std::make_shared(".", m_substring); + if (m_exclusion) { + pattern = std::make_shared(pattern); + } + m_currentFilter.m_patterns.push_back(pattern); + } + + TestSpec::PatternPtr pattern = std::make_shared(token, m_substring); + + if (m_exclusion) { + pattern = std::make_shared(pattern); + } + m_currentFilter.m_patterns.push_back(pattern); + } + m_substring.clear(); + m_exclusion = false; + m_mode = None; + } + + TestSpec parseTestSpec( std::string const& arg ) { + return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); + } + +} // namespace Catch +// end catch_test_spec_parser.cpp +// start catch_timer.cpp + +#include + +static const uint64_t nanosecondsInSecond = 1000000000; + +namespace Catch { + + auto getCurrentNanosecondsSinceEpoch() -> uint64_t { + return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); + } + + namespace { + auto estimateClockResolution() -> uint64_t { + uint64_t sum = 0; + static const uint64_t iterations = 1000000; + + auto startTime = getCurrentNanosecondsSinceEpoch(); + + for( std::size_t i = 0; i < iterations; ++i ) { + + uint64_t ticks; + uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); + do { + ticks = getCurrentNanosecondsSinceEpoch(); + } while( ticks == baseTicks ); + + auto delta = ticks - baseTicks; + sum += delta; + + // If we have been calibrating for over 3 seconds -- the clock + // is terrible and we should move on. + // TBD: How to signal that the measured resolution is probably wrong? + if (ticks > startTime + 3 * nanosecondsInSecond) { + return sum / ( i + 1u ); + } + } + + // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers + // - and potentially do more iterations if there's a high variance. + return sum/iterations; + } + } + auto getEstimatedClockResolution() -> uint64_t { + static auto s_resolution = estimateClockResolution(); + return s_resolution; + } + + void Timer::start() { + m_nanoseconds = getCurrentNanosecondsSinceEpoch(); + } + auto Timer::getElapsedNanoseconds() const -> uint64_t { + return getCurrentNanosecondsSinceEpoch() - m_nanoseconds; + } + auto Timer::getElapsedMicroseconds() const -> uint64_t { + return getElapsedNanoseconds()/1000; + } + auto Timer::getElapsedMilliseconds() const -> unsigned int { + return static_cast(getElapsedMicroseconds()/1000); + } + auto Timer::getElapsedSeconds() const -> double { + return getElapsedMicroseconds()/1000000.0; + } + +} // namespace Catch +// end catch_timer.cpp +// start catch_tostring.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +# pragma clang diagnostic ignored "-Wglobal-constructors" +#endif + +// Enable specific decls locally +#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +#include +#include + +namespace Catch { + +namespace Detail { + + const std::string unprintableString = "{?}"; + + namespace { + const int hexThreshold = 255; + + struct Endianness { + enum Arch { Big, Little }; + + static Arch which() { + int one = 1; + // If the lowest byte we read is non-zero, we can assume + // that little endian format is used. + auto value = *reinterpret_cast(&one); + return value ? Little : Big; + } + }; + } + + std::string rawMemoryToString( const void *object, std::size_t size ) { + // Reverse order for little endian architectures + int i = 0, end = static_cast( size ), inc = 1; + if( Endianness::which() == Endianness::Little ) { + i = end-1; + end = inc = -1; + } + + unsigned char const *bytes = static_cast(object); + ReusableStringStream rss; + rss << "0x" << std::setfill('0') << std::hex; + for( ; i != end; i += inc ) + rss << std::setw(2) << static_cast(bytes[i]); + return rss.str(); + } +} + +template +std::string fpToString( T value, int precision ) { + if (Catch::isnan(value)) { + return "nan"; + } + + ReusableStringStream rss; + rss << std::setprecision( precision ) + << std::fixed + << value; + std::string d = rss.str(); + std::size_t i = d.find_last_not_of( '0' ); + if( i != std::string::npos && i != d.size()-1 ) { + if( d[i] == '.' ) + i++; + d = d.substr( 0, i+1 ); + } + return d; +} + +//// ======================================================= //// +// +// Out-of-line defs for full specialization of StringMaker +// +//// ======================================================= //// + +std::string StringMaker::convert(const std::string& str) { + if (!getCurrentContext().getConfig()->showInvisibles()) { + return '"' + str + '"'; + } + + std::string s("\""); + for (char c : str) { + switch (c) { + case '\n': + s.append("\\n"); + break; + case '\t': + s.append("\\t"); + break; + default: + s.push_back(c); + break; + } + } + s.append("\""); + return s; +} + +#ifdef CATCH_CONFIG_CPP17_STRING_VIEW +std::string StringMaker::convert(std::string_view str) { + return ::Catch::Detail::stringify(std::string{ str }); +} +#endif + +std::string StringMaker::convert(char const* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(char* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } +} + +#ifdef CATCH_CONFIG_WCHAR +std::string StringMaker::convert(const std::wstring& wstr) { + std::string s; + s.reserve(wstr.size()); + for (auto c : wstr) { + s += (c <= 0xff) ? static_cast(c) : '?'; + } + return ::Catch::Detail::stringify(s); +} + +# ifdef CATCH_CONFIG_CPP17_STRING_VIEW +std::string StringMaker::convert(std::wstring_view str) { + return StringMaker::convert(std::wstring(str)); +} +# endif + +std::string StringMaker::convert(wchar_t const * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(wchar_t * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } +} +#endif + +#if defined(CATCH_CONFIG_CPP17_BYTE) +#include +std::string StringMaker::convert(std::byte value) { + return ::Catch::Detail::stringify(std::to_integer(value)); +} +#endif // defined(CATCH_CONFIG_CPP17_BYTE) + +std::string StringMaker::convert(int value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(long value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(long long value) { + ReusableStringStream rss; + rss << value; + if (value > Detail::hexThreshold) { + rss << " (0x" << std::hex << value << ')'; + } + return rss.str(); +} + +std::string StringMaker::convert(unsigned int value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(unsigned long value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(unsigned long long value) { + ReusableStringStream rss; + rss << value; + if (value > Detail::hexThreshold) { + rss << " (0x" << std::hex << value << ')'; + } + return rss.str(); +} + +std::string StringMaker::convert(bool b) { + return b ? "true" : "false"; +} + +std::string StringMaker::convert(signed char value) { + if (value == '\r') { + return "'\\r'"; + } else if (value == '\f') { + return "'\\f'"; + } else if (value == '\n') { + return "'\\n'"; + } else if (value == '\t') { + return "'\\t'"; + } else if ('\0' <= value && value < ' ') { + return ::Catch::Detail::stringify(static_cast(value)); + } else { + char chstr[] = "' '"; + chstr[1] = value; + return chstr; + } +} +std::string StringMaker::convert(char c) { + return ::Catch::Detail::stringify(static_cast(c)); +} +std::string StringMaker::convert(unsigned char c) { + return ::Catch::Detail::stringify(static_cast(c)); +} + +std::string StringMaker::convert(std::nullptr_t) { + return "nullptr"; +} + +int StringMaker::precision = 5; + +std::string StringMaker::convert(float value) { + return fpToString(value, precision) + 'f'; +} + +int StringMaker::precision = 10; + +std::string StringMaker::convert(double value) { + return fpToString(value, precision); +} + +std::string ratio_string::symbol() { return "a"; } +std::string ratio_string::symbol() { return "f"; } +std::string ratio_string::symbol() { return "p"; } +std::string ratio_string::symbol() { return "n"; } +std::string ratio_string::symbol() { return "u"; } +std::string ratio_string::symbol() { return "m"; } + +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +// end catch_tostring.cpp +// start catch_totals.cpp + +namespace Catch { + + Counts Counts::operator - ( Counts const& other ) const { + Counts diff; + diff.passed = passed - other.passed; + diff.failed = failed - other.failed; + diff.failedButOk = failedButOk - other.failedButOk; + return diff; + } + + Counts& Counts::operator += ( Counts const& other ) { + passed += other.passed; + failed += other.failed; + failedButOk += other.failedButOk; + return *this; + } + + std::size_t Counts::total() const { + return passed + failed + failedButOk; + } + bool Counts::allPassed() const { + return failed == 0 && failedButOk == 0; + } + bool Counts::allOk() const { + return failed == 0; + } + + Totals Totals::operator - ( Totals const& other ) const { + Totals diff; + diff.assertions = assertions - other.assertions; + diff.testCases = testCases - other.testCases; + return diff; + } + + Totals& Totals::operator += ( Totals const& other ) { + assertions += other.assertions; + testCases += other.testCases; + return *this; + } + + Totals Totals::delta( Totals const& prevTotals ) const { + Totals diff = *this - prevTotals; + if( diff.assertions.failed > 0 ) + ++diff.testCases.failed; + else if( diff.assertions.failedButOk > 0 ) + ++diff.testCases.failedButOk; + else + ++diff.testCases.passed; + return diff; + } + +} +// end catch_totals.cpp +// start catch_uncaught_exceptions.cpp + +// start catch_config_uncaught_exceptions.hpp + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP +#define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP + +#if defined(_MSC_VER) +# if _MSC_VER >= 1900 // Visual Studio 2015 or newer +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +# endif +#endif + +#include + +#if defined(__cpp_lib_uncaught_exceptions) \ + && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif // __cpp_lib_uncaught_exceptions + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \ + && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \ + && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + +# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif + +#endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP +// end catch_config_uncaught_exceptions.hpp +#include + +namespace Catch { + bool uncaught_exceptions() { +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + return false; +#elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + return std::uncaught_exceptions() > 0; +#else + return std::uncaught_exception(); +#endif + } +} // end namespace Catch +// end catch_uncaught_exceptions.cpp +// start catch_version.cpp + +#include + +namespace Catch { + + Version::Version + ( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ) + : majorVersion( _majorVersion ), + minorVersion( _minorVersion ), + patchNumber( _patchNumber ), + branchName( _branchName ), + buildNumber( _buildNumber ) + {} + + std::ostream& operator << ( std::ostream& os, Version const& version ) { + os << version.majorVersion << '.' + << version.minorVersion << '.' + << version.patchNumber; + // branchName is never null -> 0th char is \0 if it is empty + if (version.branchName[0]) { + os << '-' << version.branchName + << '.' << version.buildNumber; + } + return os; + } + + Version const& libraryVersion() { + static Version version( 2, 13, 10, "", 0 ); + return version; + } + +} +// end catch_version.cpp +// start catch_wildcard_pattern.cpp + +namespace Catch { + + WildcardPattern::WildcardPattern( std::string const& pattern, + CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_pattern( normaliseString( pattern ) ) + { + if( startsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 1 ); + m_wildcard = WildcardAtStart; + } + if( endsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); + m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); + } + } + + bool WildcardPattern::matches( std::string const& str ) const { + switch( m_wildcard ) { + case NoWildcard: + return m_pattern == normaliseString( str ); + case WildcardAtStart: + return endsWith( normaliseString( str ), m_pattern ); + case WildcardAtEnd: + return startsWith( normaliseString( str ), m_pattern ); + case WildcardAtBothEnds: + return contains( normaliseString( str ), m_pattern ); + default: + CATCH_INTERNAL_ERROR( "Unknown enum" ); + } + } + + std::string WildcardPattern::normaliseString( std::string const& str ) const { + return trim( m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str ); + } +} +// end catch_wildcard_pattern.cpp +// start catch_xmlwriter.cpp + +#include +#include + +namespace Catch { + +namespace { + + size_t trailingBytes(unsigned char c) { + if ((c & 0xE0) == 0xC0) { + return 2; + } + if ((c & 0xF0) == 0xE0) { + return 3; + } + if ((c & 0xF8) == 0xF0) { + return 4; + } + CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); + } + + uint32_t headerValue(unsigned char c) { + if ((c & 0xE0) == 0xC0) { + return c & 0x1F; + } + if ((c & 0xF0) == 0xE0) { + return c & 0x0F; + } + if ((c & 0xF8) == 0xF0) { + return c & 0x07; + } + CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); + } + + void hexEscapeChar(std::ostream& os, unsigned char c) { + std::ios_base::fmtflags f(os.flags()); + os << "\\x" + << std::uppercase << std::hex << std::setfill('0') << std::setw(2) + << static_cast(c); + os.flags(f); + } + + bool shouldNewline(XmlFormatting fmt) { + return !!(static_cast::type>(fmt & XmlFormatting::Newline)); + } + + bool shouldIndent(XmlFormatting fmt) { + return !!(static_cast::type>(fmt & XmlFormatting::Indent)); + } + +} // anonymous namespace + + XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs) { + return static_cast( + static_cast::type>(lhs) | + static_cast::type>(rhs) + ); + } + + XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs) { + return static_cast( + static_cast::type>(lhs) & + static_cast::type>(rhs) + ); + } + + XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat ) + : m_str( str ), + m_forWhat( forWhat ) + {} + + void XmlEncode::encodeTo( std::ostream& os ) const { + // Apostrophe escaping not necessary if we always use " to write attributes + // (see: http://www.w3.org/TR/xml/#syntax) + + for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { + unsigned char c = m_str[idx]; + switch (c) { + case '<': os << "<"; break; + case '&': os << "&"; break; + + case '>': + // See: http://www.w3.org/TR/xml/#syntax + if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']') + os << ">"; + else + os << c; + break; + + case '\"': + if (m_forWhat == ForAttributes) + os << """; + else + os << c; + break; + + default: + // Check for control characters and invalid utf-8 + + // Escape control characters in standard ascii + // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) { + hexEscapeChar(os, c); + break; + } + + // Plain ASCII: Write it to stream + if (c < 0x7F) { + os << c; + break; + } + + // UTF-8 territory + // Check if the encoding is valid and if it is not, hex escape bytes. + // Important: We do not check the exact decoded values for validity, only the encoding format + // First check that this bytes is a valid lead byte: + // This means that it is not encoded as 1111 1XXX + // Or as 10XX XXXX + if (c < 0xC0 || + c >= 0xF8) { + hexEscapeChar(os, c); + break; + } + + auto encBytes = trailingBytes(c); + // Are there enough bytes left to avoid accessing out-of-bounds memory? + if (idx + encBytes - 1 >= m_str.size()) { + hexEscapeChar(os, c); + break; + } + // The header is valid, check data + // The next encBytes bytes must together be a valid utf-8 + // This means: bitpattern 10XX XXXX and the extracted value is sane (ish) + bool valid = true; + uint32_t value = headerValue(c); + for (std::size_t n = 1; n < encBytes; ++n) { + unsigned char nc = m_str[idx + n]; + valid &= ((nc & 0xC0) == 0x80); + value = (value << 6) | (nc & 0x3F); + } + + if ( + // Wrong bit pattern of following bytes + (!valid) || + // Overlong encodings + (value < 0x80) || + (0x80 <= value && value < 0x800 && encBytes > 2) || + (0x800 < value && value < 0x10000 && encBytes > 3) || + // Encoded value out of range + (value >= 0x110000) + ) { + hexEscapeChar(os, c); + break; + } + + // If we got here, this is in fact a valid(ish) utf-8 sequence + for (std::size_t n = 0; n < encBytes; ++n) { + os << m_str[idx + n]; + } + idx += encBytes - 1; + break; + } + } + } + + std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { + xmlEncode.encodeTo( os ); + return os; + } + + XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer, XmlFormatting fmt ) + : m_writer( writer ), + m_fmt(fmt) + {} + + XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept + : m_writer( other.m_writer ), + m_fmt(other.m_fmt) + { + other.m_writer = nullptr; + other.m_fmt = XmlFormatting::None; + } + XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { + if ( m_writer ) { + m_writer->endElement(); + } + m_writer = other.m_writer; + other.m_writer = nullptr; + m_fmt = other.m_fmt; + other.m_fmt = XmlFormatting::None; + return *this; + } + + XmlWriter::ScopedElement::~ScopedElement() { + if (m_writer) { + m_writer->endElement(m_fmt); + } + } + + XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, XmlFormatting fmt ) { + m_writer->writeText( text, fmt ); + return *this; + } + + XmlWriter::XmlWriter( std::ostream& os ) : m_os( os ) + { + writeDeclaration(); + } + + XmlWriter::~XmlWriter() { + while (!m_tags.empty()) { + endElement(); + } + newlineIfNecessary(); + } + + XmlWriter& XmlWriter::startElement( std::string const& name, XmlFormatting fmt ) { + ensureTagClosed(); + newlineIfNecessary(); + if (shouldIndent(fmt)) { + m_os << m_indent; + m_indent += " "; + } + m_os << '<' << name; + m_tags.push_back( name ); + m_tagIsOpen = true; + applyFormatting(fmt); + return *this; + } + + XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name, XmlFormatting fmt ) { + ScopedElement scoped( this, fmt ); + startElement( name, fmt ); + return scoped; + } + + XmlWriter& XmlWriter::endElement(XmlFormatting fmt) { + m_indent = m_indent.substr(0, m_indent.size() - 2); + + if( m_tagIsOpen ) { + m_os << "/>"; + m_tagIsOpen = false; + } else { + newlineIfNecessary(); + if (shouldIndent(fmt)) { + m_os << m_indent; + } + m_os << ""; + } + m_os << std::flush; + applyFormatting(fmt); + m_tags.pop_back(); + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) { + if( !name.empty() && !attribute.empty() ) + m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) { + m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; + return *this; + } + + XmlWriter& XmlWriter::writeText( std::string const& text, XmlFormatting fmt) { + if( !text.empty() ){ + bool tagWasOpen = m_tagIsOpen; + ensureTagClosed(); + if (tagWasOpen && shouldIndent(fmt)) { + m_os << m_indent; + } + m_os << XmlEncode( text ); + applyFormatting(fmt); + } + return *this; + } + + XmlWriter& XmlWriter::writeComment( std::string const& text, XmlFormatting fmt) { + ensureTagClosed(); + if (shouldIndent(fmt)) { + m_os << m_indent; + } + m_os << ""; + applyFormatting(fmt); + return *this; + } + + void XmlWriter::writeStylesheetRef( std::string const& url ) { + m_os << "\n"; + } + + XmlWriter& XmlWriter::writeBlankLine() { + ensureTagClosed(); + m_os << '\n'; + return *this; + } + + void XmlWriter::ensureTagClosed() { + if( m_tagIsOpen ) { + m_os << '>' << std::flush; + newlineIfNecessary(); + m_tagIsOpen = false; + } + } + + void XmlWriter::applyFormatting(XmlFormatting fmt) { + m_needsNewline = shouldNewline(fmt); + } + + void XmlWriter::writeDeclaration() { + m_os << "\n"; + } + + void XmlWriter::newlineIfNecessary() { + if( m_needsNewline ) { + m_os << std::endl; + m_needsNewline = false; + } + } +} +// end catch_xmlwriter.cpp +// start catch_reporter_bases.cpp + +#include +#include +#include +#include +#include + +namespace Catch { + void prepareExpandedExpression(AssertionResult& result) { + result.getExpandedExpression(); + } + + // Because formatting using c++ streams is stateful, drop down to C is required + // Alternatively we could use stringstream, but its performance is... not good. + std::string getFormattedDuration( double duration ) { + // Max exponent + 1 is required to represent the whole part + // + 1 for decimal point + // + 3 for the 3 decimal places + // + 1 for null terminator + const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; + char buffer[maxDoubleSize]; + + // Save previous errno, to prevent sprintf from overwriting it + ErrnoGuard guard; +#ifdef _MSC_VER + sprintf_s(buffer, "%.3f", duration); +#else + std::sprintf(buffer, "%.3f", duration); +#endif + return std::string(buffer); + } + + bool shouldShowDuration( IConfig const& config, double duration ) { + if ( config.showDurations() == ShowDurations::Always ) { + return true; + } + if ( config.showDurations() == ShowDurations::Never ) { + return false; + } + const double min = config.minDuration(); + return min >= 0 && duration >= min; + } + + std::string serializeFilters( std::vector const& container ) { + ReusableStringStream oss; + bool first = true; + for (auto&& filter : container) + { + if (!first) + oss << ' '; + else + first = false; + + oss << filter; + } + return oss.str(); + } + + TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) + :StreamingReporterBase(_config) {} + + std::set TestEventListenerBase::getSupportedVerbosities() { + return { Verbosity::Quiet, Verbosity::Normal, Verbosity::High }; + } + + void TestEventListenerBase::assertionStarting(AssertionInfo const &) {} + + bool TestEventListenerBase::assertionEnded(AssertionStats const &) { + return false; + } + +} // end namespace Catch +// end catch_reporter_bases.cpp +// start catch_reporter_compact.cpp + +namespace { + +#ifdef CATCH_PLATFORM_MAC + const char* failedString() { return "FAILED"; } + const char* passedString() { return "PASSED"; } +#else + const char* failedString() { return "failed"; } + const char* passedString() { return "passed"; } +#endif + + // Colour::LightGrey + Catch::Colour::Code dimColour() { return Catch::Colour::FileName; } + + std::string bothOrAll( std::size_t count ) { + return count == 1 ? std::string() : + count == 2 ? "both " : "all " ; + } + +} // anon namespace + +namespace Catch { +namespace { +// Colour, message variants: +// - white: No tests ran. +// - red: Failed [both/all] N test cases, failed [both/all] M assertions. +// - white: Passed [both/all] N test cases (no assertions). +// - red: Failed N tests cases, failed M assertions. +// - green: Passed [both/all] N tests cases with M assertions. +void printTotals(std::ostream& out, const Totals& totals) { + if (totals.testCases.total() == 0) { + out << "No tests ran."; + } else if (totals.testCases.failed == totals.testCases.total()) { + Colour colour(Colour::ResultError); + const std::string qualify_assertions_failed = + totals.assertions.failed == totals.assertions.total() ? + bothOrAll(totals.assertions.failed) : std::string(); + out << + "Failed " << bothOrAll(totals.testCases.failed) + << pluralise(totals.testCases.failed, "test case") << ", " + "failed " << qualify_assertions_failed << + pluralise(totals.assertions.failed, "assertion") << '.'; + } else if (totals.assertions.total() == 0) { + out << + "Passed " << bothOrAll(totals.testCases.total()) + << pluralise(totals.testCases.total(), "test case") + << " (no assertions)."; + } else if (totals.assertions.failed) { + Colour colour(Colour::ResultError); + out << + "Failed " << pluralise(totals.testCases.failed, "test case") << ", " + "failed " << pluralise(totals.assertions.failed, "assertion") << '.'; + } else { + Colour colour(Colour::ResultSuccess); + out << + "Passed " << bothOrAll(totals.testCases.passed) + << pluralise(totals.testCases.passed, "test case") << + " with " << pluralise(totals.assertions.passed, "assertion") << '.'; + } +} + +// Implementation of CompactReporter formatting +class AssertionPrinter { +public: + AssertionPrinter& operator= (AssertionPrinter const&) = delete; + AssertionPrinter(AssertionPrinter const&) = delete; + AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) + : stream(_stream) + , result(_stats.assertionResult) + , messages(_stats.infoMessages) + , itMessage(_stats.infoMessages.begin()) + , printInfoMessages(_printInfoMessages) {} + + void print() { + printSourceInfo(); + + itMessage = messages.begin(); + + switch (result.getResultType()) { + case ResultWas::Ok: + printResultType(Colour::ResultSuccess, passedString()); + printOriginalExpression(); + printReconstructedExpression(); + if (!result.hasExpression()) + printRemainingMessages(Colour::None); + else + printRemainingMessages(); + break; + case ResultWas::ExpressionFailed: + if (result.isOk()) + printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok")); + else + printResultType(Colour::Error, failedString()); + printOriginalExpression(); + printReconstructedExpression(); + printRemainingMessages(); + break; + case ResultWas::ThrewException: + printResultType(Colour::Error, failedString()); + printIssue("unexpected exception with message:"); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::FatalErrorCondition: + printResultType(Colour::Error, failedString()); + printIssue("fatal error condition with message:"); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::DidntThrowException: + printResultType(Colour::Error, failedString()); + printIssue("expected exception, got none"); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::Info: + printResultType(Colour::None, "info"); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::Warning: + printResultType(Colour::None, "warning"); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::ExplicitFailure: + printResultType(Colour::Error, failedString()); + printIssue("explicitly"); + printRemainingMessages(Colour::None); + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + printResultType(Colour::Error, "** internal error **"); + break; + } + } + +private: + void printSourceInfo() const { + Colour colourGuard(Colour::FileName); + stream << result.getSourceInfo() << ':'; + } + + void printResultType(Colour::Code colour, std::string const& passOrFail) const { + if (!passOrFail.empty()) { + { + Colour colourGuard(colour); + stream << ' ' << passOrFail; + } + stream << ':'; + } + } + + void printIssue(std::string const& issue) const { + stream << ' ' << issue; + } + + void printExpressionWas() { + if (result.hasExpression()) { + stream << ';'; + { + Colour colour(dimColour()); + stream << " expression was:"; + } + printOriginalExpression(); + } + } + + void printOriginalExpression() const { + if (result.hasExpression()) { + stream << ' ' << result.getExpression(); + } + } + + void printReconstructedExpression() const { + if (result.hasExpandedExpression()) { + { + Colour colour(dimColour()); + stream << " for: "; + } + stream << result.getExpandedExpression(); + } + } + + void printMessage() { + if (itMessage != messages.end()) { + stream << " '" << itMessage->message << '\''; + ++itMessage; + } + } + + void printRemainingMessages(Colour::Code colour = dimColour()) { + if (itMessage == messages.end()) + return; + + const auto itEnd = messages.cend(); + const auto N = static_cast(std::distance(itMessage, itEnd)); + + { + Colour colourGuard(colour); + stream << " with " << pluralise(N, "message") << ':'; + } + + while (itMessage != itEnd) { + // If this assertion is a warning ignore any INFO messages + if (printInfoMessages || itMessage->type != ResultWas::Info) { + printMessage(); + if (itMessage != itEnd) { + Colour colourGuard(dimColour()); + stream << " and"; + } + continue; + } + ++itMessage; + } + } + +private: + std::ostream& stream; + AssertionResult const& result; + std::vector messages; + std::vector::const_iterator itMessage; + bool printInfoMessages; +}; + +} // anon namespace + + std::string CompactReporter::getDescription() { + return "Reports test results on a single line, suitable for IDEs"; + } + + void CompactReporter::noMatchingTestCases( std::string const& spec ) { + stream << "No test cases matched '" << spec << '\'' << std::endl; + } + + void CompactReporter::assertionStarting( AssertionInfo const& ) {} + + bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool printInfoMessages = true; + + // Drop out if result was successful and we're not printing those + if( !m_config->includeSuccessfulResults() && result.isOk() ) { + if( result.getResultType() != ResultWas::Warning ) + return false; + printInfoMessages = false; + } + + AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); + printer.print(); + + stream << std::endl; + return true; + } + + void CompactReporter::sectionEnded(SectionStats const& _sectionStats) { + double dur = _sectionStats.durationInSeconds; + if ( shouldShowDuration( *m_config, dur ) ) { + stream << getFormattedDuration( dur ) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + } + + void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) { + printTotals( stream, _testRunStats.totals ); + stream << '\n' << std::endl; + StreamingReporterBase::testRunEnded( _testRunStats ); + } + + CompactReporter::~CompactReporter() {} + + CATCH_REGISTER_REPORTER( "compact", CompactReporter ) + +} // end namespace Catch +// end catch_reporter_compact.cpp +// start catch_reporter_console.cpp + +#include +#include + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled and default is missing) is enabled +#endif + +#if defined(__clang__) +# pragma clang diagnostic push +// For simplicity, benchmarking-only helpers are always enabled +# pragma clang diagnostic ignored "-Wunused-function" +#endif + +namespace Catch { + +namespace { + +// Formatter impl for ConsoleReporter +class ConsoleAssertionPrinter { +public: + ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter const&) = delete; + ConsoleAssertionPrinter(ConsoleAssertionPrinter const&) = delete; + ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) + : stream(_stream), + stats(_stats), + result(_stats.assertionResult), + colour(Colour::None), + message(result.getMessage()), + messages(_stats.infoMessages), + printInfoMessages(_printInfoMessages) { + switch (result.getResultType()) { + case ResultWas::Ok: + colour = Colour::Success; + passOrFail = "PASSED"; + //if( result.hasMessage() ) + if (_stats.infoMessages.size() == 1) + messageLabel = "with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "with messages"; + break; + case ResultWas::ExpressionFailed: + if (result.isOk()) { + colour = Colour::Success; + passOrFail = "FAILED - but was ok"; + } else { + colour = Colour::Error; + passOrFail = "FAILED"; + } + if (_stats.infoMessages.size() == 1) + messageLabel = "with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "with messages"; + break; + case ResultWas::ThrewException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to unexpected exception with "; + if (_stats.infoMessages.size() == 1) + messageLabel += "message"; + if (_stats.infoMessages.size() > 1) + messageLabel += "messages"; + break; + case ResultWas::FatalErrorCondition: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to a fatal error condition"; + break; + case ResultWas::DidntThrowException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "because no exception was thrown where one was expected"; + break; + case ResultWas::Info: + messageLabel = "info"; + break; + case ResultWas::Warning: + messageLabel = "warning"; + break; + case ResultWas::ExplicitFailure: + passOrFail = "FAILED"; + colour = Colour::Error; + if (_stats.infoMessages.size() == 1) + messageLabel = "explicitly with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "explicitly with messages"; + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + passOrFail = "** internal error **"; + colour = Colour::Error; + break; + } + } + + void print() const { + printSourceInfo(); + if (stats.totals.assertions.total() > 0) { + printResultType(); + printOriginalExpression(); + printReconstructedExpression(); + } else { + stream << '\n'; + } + printMessage(); + } + +private: + void printResultType() const { + if (!passOrFail.empty()) { + Colour colourGuard(colour); + stream << passOrFail << ":\n"; + } + } + void printOriginalExpression() const { + if (result.hasExpression()) { + Colour colourGuard(Colour::OriginalExpression); + stream << " "; + stream << result.getExpressionInMacro(); + stream << '\n'; + } + } + void printReconstructedExpression() const { + if (result.hasExpandedExpression()) { + stream << "with expansion:\n"; + Colour colourGuard(Colour::ReconstructedExpression); + stream << Column(result.getExpandedExpression()).indent(2) << '\n'; + } + } + void printMessage() const { + if (!messageLabel.empty()) + stream << messageLabel << ':' << '\n'; + for (auto const& msg : messages) { + // If this assertion is a warning ignore any INFO messages + if (printInfoMessages || msg.type != ResultWas::Info) + stream << Column(msg.message).indent(2) << '\n'; + } + } + void printSourceInfo() const { + Colour colourGuard(Colour::FileName); + stream << result.getSourceInfo() << ": "; + } + + std::ostream& stream; + AssertionStats const& stats; + AssertionResult const& result; + Colour::Code colour; + std::string passOrFail; + std::string messageLabel; + std::string message; + std::vector messages; + bool printInfoMessages; +}; + +std::size_t makeRatio(std::size_t number, std::size_t total) { + std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0; + return (ratio == 0 && number > 0) ? 1 : ratio; +} + +std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) { + if (i > j && i > k) + return i; + else if (j > k) + return j; + else + return k; +} + +struct ColumnInfo { + enum Justification { Left, Right }; + std::string name; + int width; + Justification justification; +}; +struct ColumnBreak {}; +struct RowBreak {}; + +class Duration { + enum class Unit { + Auto, + Nanoseconds, + Microseconds, + Milliseconds, + Seconds, + Minutes + }; + static const uint64_t s_nanosecondsInAMicrosecond = 1000; + static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond; + static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond; + static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond; + + double m_inNanoseconds; + Unit m_units; + +public: + explicit Duration(double inNanoseconds, Unit units = Unit::Auto) + : m_inNanoseconds(inNanoseconds), + m_units(units) { + if (m_units == Unit::Auto) { + if (m_inNanoseconds < s_nanosecondsInAMicrosecond) + m_units = Unit::Nanoseconds; + else if (m_inNanoseconds < s_nanosecondsInAMillisecond) + m_units = Unit::Microseconds; + else if (m_inNanoseconds < s_nanosecondsInASecond) + m_units = Unit::Milliseconds; + else if (m_inNanoseconds < s_nanosecondsInAMinute) + m_units = Unit::Seconds; + else + m_units = Unit::Minutes; + } + + } + + auto value() const -> double { + switch (m_units) { + case Unit::Microseconds: + return m_inNanoseconds / static_cast(s_nanosecondsInAMicrosecond); + case Unit::Milliseconds: + return m_inNanoseconds / static_cast(s_nanosecondsInAMillisecond); + case Unit::Seconds: + return m_inNanoseconds / static_cast(s_nanosecondsInASecond); + case Unit::Minutes: + return m_inNanoseconds / static_cast(s_nanosecondsInAMinute); + default: + return m_inNanoseconds; + } + } + auto unitsAsString() const -> std::string { + switch (m_units) { + case Unit::Nanoseconds: + return "ns"; + case Unit::Microseconds: + return "us"; + case Unit::Milliseconds: + return "ms"; + case Unit::Seconds: + return "s"; + case Unit::Minutes: + return "m"; + default: + return "** internal error **"; + } + + } + friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& { + return os << duration.value() << ' ' << duration.unitsAsString(); + } +}; +} // end anon namespace + +class TablePrinter { + std::ostream& m_os; + std::vector m_columnInfos; + std::ostringstream m_oss; + int m_currentColumn = -1; + bool m_isOpen = false; + +public: + TablePrinter( std::ostream& os, std::vector columnInfos ) + : m_os( os ), + m_columnInfos( std::move( columnInfos ) ) {} + + auto columnInfos() const -> std::vector const& { + return m_columnInfos; + } + + void open() { + if (!m_isOpen) { + m_isOpen = true; + *this << RowBreak(); + + Columns headerCols; + Spacer spacer(2); + for (auto const& info : m_columnInfos) { + headerCols += Column(info.name).width(static_cast(info.width - 2)); + headerCols += spacer; + } + m_os << headerCols << '\n'; + + m_os << Catch::getLineOfChars<'-'>() << '\n'; + } + } + void close() { + if (m_isOpen) { + *this << RowBreak(); + m_os << std::endl; + m_isOpen = false; + } + } + + template + friend TablePrinter& operator << (TablePrinter& tp, T const& value) { + tp.m_oss << value; + return tp; + } + + friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) { + auto colStr = tp.m_oss.str(); + const auto strSize = colStr.size(); + tp.m_oss.str(""); + tp.open(); + if (tp.m_currentColumn == static_cast(tp.m_columnInfos.size() - 1)) { + tp.m_currentColumn = -1; + tp.m_os << '\n'; + } + tp.m_currentColumn++; + + auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; + auto padding = (strSize + 1 < static_cast(colInfo.width)) + ? std::string(colInfo.width - (strSize + 1), ' ') + : std::string(); + if (colInfo.justification == ColumnInfo::Left) + tp.m_os << colStr << padding << ' '; + else + tp.m_os << padding << colStr << ' '; + return tp; + } + + friend TablePrinter& operator << (TablePrinter& tp, RowBreak) { + if (tp.m_currentColumn > 0) { + tp.m_os << '\n'; + tp.m_currentColumn = -1; + } + return tp; + } +}; + +ConsoleReporter::ConsoleReporter(ReporterConfig const& config) + : StreamingReporterBase(config), + m_tablePrinter(new TablePrinter(config.stream(), + [&config]() -> std::vector { + if (config.fullConfig()->benchmarkNoAnalysis()) + { + return{ + { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left }, + { " samples", 14, ColumnInfo::Right }, + { " iterations", 14, ColumnInfo::Right }, + { " mean", 14, ColumnInfo::Right } + }; + } + else + { + return{ + { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left }, + { "samples mean std dev", 14, ColumnInfo::Right }, + { "iterations low mean low std dev", 14, ColumnInfo::Right }, + { "estimated high mean high std dev", 14, ColumnInfo::Right } + }; + } + }())) {} +ConsoleReporter::~ConsoleReporter() = default; + +std::string ConsoleReporter::getDescription() { + return "Reports test results as plain lines of text"; +} + +void ConsoleReporter::noMatchingTestCases(std::string const& spec) { + stream << "No test cases matched '" << spec << '\'' << std::endl; +} + +void ConsoleReporter::reportInvalidArguments(std::string const&arg){ + stream << "Invalid Filter: " << arg << std::endl; +} + +void ConsoleReporter::assertionStarting(AssertionInfo const&) {} + +bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + // Drop out if result was successful but we're not printing them. + if (!includeResults && result.getResultType() != ResultWas::Warning) + return false; + + lazyPrint(); + + ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults); + printer.print(); + stream << std::endl; + return true; +} + +void ConsoleReporter::sectionStarting(SectionInfo const& _sectionInfo) { + m_tablePrinter->close(); + m_headerPrinted = false; + StreamingReporterBase::sectionStarting(_sectionInfo); +} +void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) { + m_tablePrinter->close(); + if (_sectionStats.missingAssertions) { + lazyPrint(); + Colour colour(Colour::ResultError); + if (m_sectionStack.size() > 1) + stream << "\nNo assertions in section"; + else + stream << "\nNo assertions in test case"; + stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; + } + double dur = _sectionStats.durationInSeconds; + if (shouldShowDuration(*m_config, dur)) { + stream << getFormattedDuration(dur) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + if (m_headerPrinted) { + m_headerPrinted = false; + } + StreamingReporterBase::sectionEnded(_sectionStats); +} + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) +void ConsoleReporter::benchmarkPreparing(std::string const& name) { + lazyPrintWithoutClosingBenchmarkTable(); + + auto nameCol = Column(name).width(static_cast(m_tablePrinter->columnInfos()[0].width - 2)); + + bool firstLine = true; + for (auto line : nameCol) { + if (!firstLine) + (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak(); + else + firstLine = false; + + (*m_tablePrinter) << line << ColumnBreak(); + } +} + +void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) { + (*m_tablePrinter) << info.samples << ColumnBreak() + << info.iterations << ColumnBreak(); + if (!m_config->benchmarkNoAnalysis()) + (*m_tablePrinter) << Duration(info.estimatedDuration) << ColumnBreak(); +} +void ConsoleReporter::benchmarkEnded(BenchmarkStats<> const& stats) { + if (m_config->benchmarkNoAnalysis()) + { + (*m_tablePrinter) << Duration(stats.mean.point.count()) << ColumnBreak(); + } + else + { + (*m_tablePrinter) << ColumnBreak() + << Duration(stats.mean.point.count()) << ColumnBreak() + << Duration(stats.mean.lower_bound.count()) << ColumnBreak() + << Duration(stats.mean.upper_bound.count()) << ColumnBreak() << ColumnBreak() + << Duration(stats.standardDeviation.point.count()) << ColumnBreak() + << Duration(stats.standardDeviation.lower_bound.count()) << ColumnBreak() + << Duration(stats.standardDeviation.upper_bound.count()) << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak(); + } +} + +void ConsoleReporter::benchmarkFailed(std::string const& error) { + Colour colour(Colour::Red); + (*m_tablePrinter) + << "Benchmark failed (" << error << ')' + << ColumnBreak() << RowBreak(); +} +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + +void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { + m_tablePrinter->close(); + StreamingReporterBase::testCaseEnded(_testCaseStats); + m_headerPrinted = false; +} +void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) { + if (currentGroupInfo.used) { + printSummaryDivider(); + stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; + printTotals(_testGroupStats.totals); + stream << '\n' << std::endl; + } + StreamingReporterBase::testGroupEnded(_testGroupStats); +} +void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) { + printTotalsDivider(_testRunStats.totals); + printTotals(_testRunStats.totals); + stream << std::endl; + StreamingReporterBase::testRunEnded(_testRunStats); +} +void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) { + StreamingReporterBase::testRunStarting(_testInfo); + printTestFilters(); +} + +void ConsoleReporter::lazyPrint() { + + m_tablePrinter->close(); + lazyPrintWithoutClosingBenchmarkTable(); +} + +void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() { + + if (!currentTestRunInfo.used) + lazyPrintRunInfo(); + if (!currentGroupInfo.used) + lazyPrintGroupInfo(); + + if (!m_headerPrinted) { + printTestCaseAndSectionHeader(); + m_headerPrinted = true; + } +} +void ConsoleReporter::lazyPrintRunInfo() { + stream << '\n' << getLineOfChars<'~'>() << '\n'; + Colour colour(Colour::SecondaryText); + stream << currentTestRunInfo->name + << " is a Catch v" << libraryVersion() << " host application.\n" + << "Run with -? for options\n\n"; + + if (m_config->rngSeed() != 0) + stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; + + currentTestRunInfo.used = true; +} +void ConsoleReporter::lazyPrintGroupInfo() { + if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) { + printClosedHeader("Group: " + currentGroupInfo->name); + currentGroupInfo.used = true; + } +} +void ConsoleReporter::printTestCaseAndSectionHeader() { + assert(!m_sectionStack.empty()); + printOpenHeader(currentTestCaseInfo->name); + + if (m_sectionStack.size() > 1) { + Colour colourGuard(Colour::Headers); + + auto + it = m_sectionStack.begin() + 1, // Skip first section (test case) + itEnd = m_sectionStack.end(); + for (; it != itEnd; ++it) + printHeaderString(it->name, 2); + } + + SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; + + stream << getLineOfChars<'-'>() << '\n'; + Colour colourGuard(Colour::FileName); + stream << lineInfo << '\n'; + stream << getLineOfChars<'.'>() << '\n' << std::endl; +} + +void ConsoleReporter::printClosedHeader(std::string const& _name) { + printOpenHeader(_name); + stream << getLineOfChars<'.'>() << '\n'; +} +void ConsoleReporter::printOpenHeader(std::string const& _name) { + stream << getLineOfChars<'-'>() << '\n'; + { + Colour colourGuard(Colour::Headers); + printHeaderString(_name); + } +} + +// if string has a : in first line will set indent to follow it on +// subsequent lines +void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) { + std::size_t i = _string.find(": "); + if (i != std::string::npos) + i += 2; + else + i = 0; + stream << Column(_string).indent(indent + i).initialIndent(indent) << '\n'; +} + +struct SummaryColumn { + + SummaryColumn( std::string _label, Colour::Code _colour ) + : label( std::move( _label ) ), + colour( _colour ) {} + SummaryColumn addRow( std::size_t count ) { + ReusableStringStream rss; + rss << count; + std::string row = rss.str(); + for (auto& oldRow : rows) { + while (oldRow.size() < row.size()) + oldRow = ' ' + oldRow; + while (oldRow.size() > row.size()) + row = ' ' + row; + } + rows.push_back(row); + return *this; + } + + std::string label; + Colour::Code colour; + std::vector rows; + +}; + +void ConsoleReporter::printTotals( Totals const& totals ) { + if (totals.testCases.total() == 0) { + stream << Colour(Colour::Warning) << "No tests ran\n"; + } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) { + stream << Colour(Colour::ResultSuccess) << "All tests passed"; + stream << " (" + << pluralise(totals.assertions.passed, "assertion") << " in " + << pluralise(totals.testCases.passed, "test case") << ')' + << '\n'; + } else { + + std::vector columns; + columns.push_back(SummaryColumn("", Colour::None) + .addRow(totals.testCases.total()) + .addRow(totals.assertions.total())); + columns.push_back(SummaryColumn("passed", Colour::Success) + .addRow(totals.testCases.passed) + .addRow(totals.assertions.passed)); + columns.push_back(SummaryColumn("failed", Colour::ResultError) + .addRow(totals.testCases.failed) + .addRow(totals.assertions.failed)); + columns.push_back(SummaryColumn("failed as expected", Colour::ResultExpectedFailure) + .addRow(totals.testCases.failedButOk) + .addRow(totals.assertions.failedButOk)); + + printSummaryRow("test cases", columns, 0); + printSummaryRow("assertions", columns, 1); + } +} +void ConsoleReporter::printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row) { + for (auto col : cols) { + std::string value = col.rows[row]; + if (col.label.empty()) { + stream << label << ": "; + if (value != "0") + stream << value; + else + stream << Colour(Colour::Warning) << "- none -"; + } else if (value != "0") { + stream << Colour(Colour::LightGrey) << " | "; + stream << Colour(col.colour) + << value << ' ' << col.label; + } + } + stream << '\n'; +} + +void ConsoleReporter::printTotalsDivider(Totals const& totals) { + if (totals.testCases.total() > 0) { + std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total()); + std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total()); + std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total()); + while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1) + findMax(failedRatio, failedButOkRatio, passedRatio)++; + while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1) + findMax(failedRatio, failedButOkRatio, passedRatio)--; + + stream << Colour(Colour::Error) << std::string(failedRatio, '='); + stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '='); + if (totals.testCases.allPassed()) + stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '='); + else + stream << Colour(Colour::Success) << std::string(passedRatio, '='); + } else { + stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '='); + } + stream << '\n'; +} +void ConsoleReporter::printSummaryDivider() { + stream << getLineOfChars<'-'>() << '\n'; +} + +void ConsoleReporter::printTestFilters() { + if (m_config->testSpec().hasFilters()) { + Colour guard(Colour::BrightYellow); + stream << "Filters: " << serializeFilters(m_config->getTestsOrTags()) << '\n'; + } +} + +CATCH_REGISTER_REPORTER("console", ConsoleReporter) + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_reporter_console.cpp +// start catch_reporter_junit.cpp + +#include +#include +#include +#include +#include + +namespace Catch { + + namespace { + std::string getCurrentTimestamp() { + // Beware, this is not reentrant because of backward compatibility issues + // Also, UTC only, again because of backward compatibility (%z is C++11) + time_t rawtime; + std::time(&rawtime); + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &rawtime); +#else + std::tm* timeInfo; + timeInfo = std::gmtime(&rawtime); +#endif + + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp, timeStampSize-1); + } + + std::string fileNameTag(const std::vector &tags) { + auto it = std::find_if(begin(tags), + end(tags), + [] (std::string const& tag) {return tag.front() == '#'; }); + if (it != tags.end()) + return it->substr(1); + return std::string(); + } + + // Formats the duration in seconds to 3 decimal places. + // This is done because some genius defined Maven Surefire schema + // in a way that only accepts 3 decimal places, and tools like + // Jenkins use that schema for validation JUnit reporter output. + std::string formatDuration( double seconds ) { + ReusableStringStream rss; + rss << std::fixed << std::setprecision( 3 ) << seconds; + return rss.str(); + } + + } // anonymous namespace + + JunitReporter::JunitReporter( ReporterConfig const& _config ) + : CumulativeReporterBase( _config ), + xml( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = true; + m_reporterPrefs.shouldReportAllAssertions = true; + } + + JunitReporter::~JunitReporter() {} + + std::string JunitReporter::getDescription() { + return "Reports test results in an XML format that looks like Ant's junitreport target"; + } + + void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {} + + void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { + CumulativeReporterBase::testRunStarting( runInfo ); + xml.startElement( "testsuites" ); + } + + void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) { + suiteTimer.start(); + stdOutForSuite.clear(); + stdErrForSuite.clear(); + unexpectedExceptions = 0; + CumulativeReporterBase::testGroupStarting( groupInfo ); + } + + void JunitReporter::testCaseStarting( TestCaseInfo const& testCaseInfo ) { + m_okToFail = testCaseInfo.okToFail(); + } + + bool JunitReporter::assertionEnded( AssertionStats const& assertionStats ) { + if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail ) + unexpectedExceptions++; + return CumulativeReporterBase::assertionEnded( assertionStats ); + } + + void JunitReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + stdOutForSuite += testCaseStats.stdOut; + stdErrForSuite += testCaseStats.stdErr; + CumulativeReporterBase::testCaseEnded( testCaseStats ); + } + + void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + double suiteTime = suiteTimer.getElapsedSeconds(); + CumulativeReporterBase::testGroupEnded( testGroupStats ); + writeGroup( *m_testGroups.back(), suiteTime ); + } + + void JunitReporter::testRunEndedCumulative() { + xml.endElement(); + } + + void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); + + TestGroupStats const& stats = groupNode.value; + xml.writeAttribute( "name", stats.groupInfo.name ); + xml.writeAttribute( "errors", unexpectedExceptions ); + xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); + xml.writeAttribute( "tests", stats.totals.assertions.total() ); + xml.writeAttribute( "hostname", "tbd" ); // !TBD + if( m_config->showDurations() == ShowDurations::Never ) + xml.writeAttribute( "time", "" ); + else + xml.writeAttribute( "time", formatDuration( suiteTime ) ); + xml.writeAttribute( "timestamp", getCurrentTimestamp() ); + + // Write properties if there are any + if (m_config->hasTestFilters() || m_config->rngSeed() != 0) { + auto properties = xml.scopedElement("properties"); + if (m_config->hasTestFilters()) { + xml.scopedElement("property") + .writeAttribute("name", "filters") + .writeAttribute("value", serializeFilters(m_config->getTestsOrTags())); + } + if (m_config->rngSeed() != 0) { + xml.scopedElement("property") + .writeAttribute("name", "random-seed") + .writeAttribute("value", m_config->rngSeed()); + } + } + + // Write test cases + for( auto const& child : groupNode.children ) + writeTestCase( *child ); + + xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), XmlFormatting::Newline ); + xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), XmlFormatting::Newline ); + } + + void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) { + TestCaseStats const& stats = testCaseNode.value; + + // All test cases have exactly one section - which represents the + // test case itself. That section may have 0-n nested sections + assert( testCaseNode.children.size() == 1 ); + SectionNode const& rootSection = *testCaseNode.children.front(); + + std::string className = stats.testInfo.className; + + if( className.empty() ) { + className = fileNameTag(stats.testInfo.tags); + if ( className.empty() ) + className = "global"; + } + + if ( !m_config->name().empty() ) + className = m_config->name() + "." + className; + + writeSection( className, "", rootSection, stats.testInfo.okToFail() ); + } + + void JunitReporter::writeSection( std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode, + bool testOkToFail) { + std::string name = trim( sectionNode.stats.sectionInfo.name ); + if( !rootName.empty() ) + name = rootName + '/' + name; + + if( !sectionNode.assertions.empty() || + !sectionNode.stdOut.empty() || + !sectionNode.stdErr.empty() ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); + if( className.empty() ) { + xml.writeAttribute( "classname", name ); + xml.writeAttribute( "name", "root" ); + } + else { + xml.writeAttribute( "classname", className ); + xml.writeAttribute( "name", name ); + } + xml.writeAttribute( "time", formatDuration( sectionNode.stats.durationInSeconds ) ); + // This is not ideal, but it should be enough to mimic gtest's + // junit output. + // Ideally the JUnit reporter would also handle `skipTest` + // events and write those out appropriately. + xml.writeAttribute( "status", "run" ); + + if (sectionNode.stats.assertions.failedButOk) { + xml.scopedElement("skipped") + .writeAttribute("message", "TEST_CASE tagged with !mayfail"); + } + + writeAssertions( sectionNode ); + + if( !sectionNode.stdOut.empty() ) + xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), XmlFormatting::Newline ); + if( !sectionNode.stdErr.empty() ) + xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), XmlFormatting::Newline ); + } + for( auto const& childNode : sectionNode.childSections ) + if( className.empty() ) + writeSection( name, "", *childNode, testOkToFail ); + else + writeSection( className, name, *childNode, testOkToFail ); + } + + void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { + for( auto const& assertion : sectionNode.assertions ) + writeAssertion( assertion ); + } + + void JunitReporter::writeAssertion( AssertionStats const& stats ) { + AssertionResult const& result = stats.assertionResult; + if( !result.isOk() ) { + std::string elementName; + switch( result.getResultType() ) { + case ResultWas::ThrewException: + case ResultWas::FatalErrorCondition: + elementName = "error"; + break; + case ResultWas::ExplicitFailure: + case ResultWas::ExpressionFailed: + case ResultWas::DidntThrowException: + elementName = "failure"; + break; + + // We should never see these here: + case ResultWas::Info: + case ResultWas::Warning: + case ResultWas::Ok: + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + elementName = "internalError"; + break; + } + + XmlWriter::ScopedElement e = xml.scopedElement( elementName ); + + xml.writeAttribute( "message", result.getExpression() ); + xml.writeAttribute( "type", result.getTestMacroName() ); + + ReusableStringStream rss; + if (stats.totals.assertions.total() > 0) { + rss << "FAILED" << ":\n"; + if (result.hasExpression()) { + rss << " "; + rss << result.getExpressionInMacro(); + rss << '\n'; + } + if (result.hasExpandedExpression()) { + rss << "with expansion:\n"; + rss << Column(result.getExpandedExpression()).indent(2) << '\n'; + } + } else { + rss << '\n'; + } + + if( !result.getMessage().empty() ) + rss << result.getMessage() << '\n'; + for( auto const& msg : stats.infoMessages ) + if( msg.type == ResultWas::Info ) + rss << msg.message << '\n'; + + rss << "at " << result.getSourceInfo(); + xml.writeText( rss.str(), XmlFormatting::Newline ); + } + } + + CATCH_REGISTER_REPORTER( "junit", JunitReporter ) + +} // end namespace Catch +// end catch_reporter_junit.cpp +// start catch_reporter_listening.cpp + +#include + +namespace Catch { + + ListeningReporter::ListeningReporter() { + // We will assume that listeners will always want all assertions + m_preferences.shouldReportAllAssertions = true; + } + + void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) { + m_listeners.push_back( std::move( listener ) ); + } + + void ListeningReporter::addReporter(IStreamingReporterPtr&& reporter) { + assert(!m_reporter && "Listening reporter can wrap only 1 real reporter"); + m_reporter = std::move( reporter ); + m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut; + } + + ReporterPreferences ListeningReporter::getPreferences() const { + return m_preferences; + } + + std::set ListeningReporter::getSupportedVerbosities() { + return std::set{ }; + } + + void ListeningReporter::noMatchingTestCases( std::string const& spec ) { + for ( auto const& listener : m_listeners ) { + listener->noMatchingTestCases( spec ); + } + m_reporter->noMatchingTestCases( spec ); + } + + void ListeningReporter::reportInvalidArguments(std::string const&arg){ + for ( auto const& listener : m_listeners ) { + listener->reportInvalidArguments( arg ); + } + m_reporter->reportInvalidArguments( arg ); + } + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void ListeningReporter::benchmarkPreparing( std::string const& name ) { + for (auto const& listener : m_listeners) { + listener->benchmarkPreparing(name); + } + m_reporter->benchmarkPreparing(name); + } + void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { + for ( auto const& listener : m_listeners ) { + listener->benchmarkStarting( benchmarkInfo ); + } + m_reporter->benchmarkStarting( benchmarkInfo ); + } + void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) { + for ( auto const& listener : m_listeners ) { + listener->benchmarkEnded( benchmarkStats ); + } + m_reporter->benchmarkEnded( benchmarkStats ); + } + + void ListeningReporter::benchmarkFailed( std::string const& error ) { + for (auto const& listener : m_listeners) { + listener->benchmarkFailed(error); + } + m_reporter->benchmarkFailed(error); + } +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) { + for ( auto const& listener : m_listeners ) { + listener->testRunStarting( testRunInfo ); + } + m_reporter->testRunStarting( testRunInfo ); + } + + void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) { + for ( auto const& listener : m_listeners ) { + listener->testGroupStarting( groupInfo ); + } + m_reporter->testGroupStarting( groupInfo ); + } + + void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) { + for ( auto const& listener : m_listeners ) { + listener->testCaseStarting( testInfo ); + } + m_reporter->testCaseStarting( testInfo ); + } + + void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) { + for ( auto const& listener : m_listeners ) { + listener->sectionStarting( sectionInfo ); + } + m_reporter->sectionStarting( sectionInfo ); + } + + void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) { + for ( auto const& listener : m_listeners ) { + listener->assertionStarting( assertionInfo ); + } + m_reporter->assertionStarting( assertionInfo ); + } + + // The return value indicates if the messages buffer should be cleared: + bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) { + for( auto const& listener : m_listeners ) { + static_cast( listener->assertionEnded( assertionStats ) ); + } + return m_reporter->assertionEnded( assertionStats ); + } + + void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) { + for ( auto const& listener : m_listeners ) { + listener->sectionEnded( sectionStats ); + } + m_reporter->sectionEnded( sectionStats ); + } + + void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + for ( auto const& listener : m_listeners ) { + listener->testCaseEnded( testCaseStats ); + } + m_reporter->testCaseEnded( testCaseStats ); + } + + void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + for ( auto const& listener : m_listeners ) { + listener->testGroupEnded( testGroupStats ); + } + m_reporter->testGroupEnded( testGroupStats ); + } + + void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) { + for ( auto const& listener : m_listeners ) { + listener->testRunEnded( testRunStats ); + } + m_reporter->testRunEnded( testRunStats ); + } + + void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) { + for ( auto const& listener : m_listeners ) { + listener->skipTest( testInfo ); + } + m_reporter->skipTest( testInfo ); + } + + bool ListeningReporter::isMulti() const { + return true; + } + +} // end namespace Catch +// end catch_reporter_listening.cpp +// start catch_reporter_xml.cpp + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + XmlReporter::XmlReporter( ReporterConfig const& _config ) + : StreamingReporterBase( _config ), + m_xml(_config.stream()) + { + m_reporterPrefs.shouldRedirectStdOut = true; + m_reporterPrefs.shouldReportAllAssertions = true; + } + + XmlReporter::~XmlReporter() = default; + + std::string XmlReporter::getDescription() { + return "Reports test results as an XML document"; + } + + std::string XmlReporter::getStylesheetRef() const { + return std::string(); + } + + void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) { + m_xml + .writeAttribute( "filename", sourceInfo.file ) + .writeAttribute( "line", sourceInfo.line ); + } + + void XmlReporter::noMatchingTestCases( std::string const& s ) { + StreamingReporterBase::noMatchingTestCases( s ); + } + + void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) { + StreamingReporterBase::testRunStarting( testInfo ); + std::string stylesheetRef = getStylesheetRef(); + if( !stylesheetRef.empty() ) + m_xml.writeStylesheetRef( stylesheetRef ); + m_xml.startElement( "Catch" ); + if( !m_config->name().empty() ) + m_xml.writeAttribute( "name", m_config->name() ); + if (m_config->testSpec().hasFilters()) + m_xml.writeAttribute( "filters", serializeFilters( m_config->getTestsOrTags() ) ); + if( m_config->rngSeed() != 0 ) + m_xml.scopedElement( "Randomness" ) + .writeAttribute( "seed", m_config->rngSeed() ); + } + + void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) { + StreamingReporterBase::testGroupStarting( groupInfo ); + m_xml.startElement( "Group" ) + .writeAttribute( "name", groupInfo.name ); + } + + void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) { + StreamingReporterBase::testCaseStarting(testInfo); + m_xml.startElement( "TestCase" ) + .writeAttribute( "name", trim( testInfo.name ) ) + .writeAttribute( "description", testInfo.description ) + .writeAttribute( "tags", testInfo.tagsAsString() ); + + writeSourceInfo( testInfo.lineInfo ); + + if ( m_config->showDurations() == ShowDurations::Always ) + m_testCaseTimer.start(); + m_xml.ensureTagClosed(); + } + + void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) { + StreamingReporterBase::sectionStarting( sectionInfo ); + if( m_sectionDepth++ > 0 ) { + m_xml.startElement( "Section" ) + .writeAttribute( "name", trim( sectionInfo.name ) ); + writeSourceInfo( sectionInfo.lineInfo ); + m_xml.ensureTagClosed(); + } + } + + void XmlReporter::assertionStarting( AssertionInfo const& ) { } + + bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { + + AssertionResult const& result = assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + if( includeResults || result.getResultType() == ResultWas::Warning ) { + // Print any info messages in tags. + for( auto const& msg : assertionStats.infoMessages ) { + if( msg.type == ResultWas::Info && includeResults ) { + m_xml.scopedElement( "Info" ) + .writeText( msg.message ); + } else if ( msg.type == ResultWas::Warning ) { + m_xml.scopedElement( "Warning" ) + .writeText( msg.message ); + } + } + } + + // Drop out if result was successful but we're not printing them. + if( !includeResults && result.getResultType() != ResultWas::Warning ) + return true; + + // Print the expression if there is one. + if( result.hasExpression() ) { + m_xml.startElement( "Expression" ) + .writeAttribute( "success", result.succeeded() ) + .writeAttribute( "type", result.getTestMacroName() ); + + writeSourceInfo( result.getSourceInfo() ); + + m_xml.scopedElement( "Original" ) + .writeText( result.getExpression() ); + m_xml.scopedElement( "Expanded" ) + .writeText( result.getExpandedExpression() ); + } + + // And... Print a result applicable to each result type. + switch( result.getResultType() ) { + case ResultWas::ThrewException: + m_xml.startElement( "Exception" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::FatalErrorCondition: + m_xml.startElement( "FatalErrorCondition" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::Info: + m_xml.scopedElement( "Info" ) + .writeText( result.getMessage() ); + break; + case ResultWas::Warning: + // Warning will already have been written + break; + case ResultWas::ExplicitFailure: + m_xml.startElement( "Failure" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + default: + break; + } + + if( result.hasExpression() ) + m_xml.endElement(); + + return true; + } + + void XmlReporter::sectionEnded( SectionStats const& sectionStats ) { + StreamingReporterBase::sectionEnded( sectionStats ); + if( --m_sectionDepth > 0 ) { + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); + e.writeAttribute( "successes", sectionStats.assertions.passed ); + e.writeAttribute( "failures", sectionStats.assertions.failed ); + e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); + + m_xml.endElement(); + } + } + + void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + StreamingReporterBase::testCaseEnded( testCaseStats ); + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); + e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); + + if( !testCaseStats.stdOut.empty() ) + m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), XmlFormatting::Newline ); + if( !testCaseStats.stdErr.empty() ) + m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), XmlFormatting::Newline ); + + m_xml.endElement(); + } + + void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + StreamingReporterBase::testGroupEnded( testGroupStats ); + // TODO: Check testGroupStats.aborting and act accordingly. + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) + .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); + m_xml.scopedElement( "OverallResultsCases") + .writeAttribute( "successes", testGroupStats.totals.testCases.passed ) + .writeAttribute( "failures", testGroupStats.totals.testCases.failed ) + .writeAttribute( "expectedFailures", testGroupStats.totals.testCases.failedButOk ); + m_xml.endElement(); + } + + void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) { + StreamingReporterBase::testRunEnded( testRunStats ); + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testRunStats.totals.assertions.passed ) + .writeAttribute( "failures", testRunStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); + m_xml.scopedElement( "OverallResultsCases") + .writeAttribute( "successes", testRunStats.totals.testCases.passed ) + .writeAttribute( "failures", testRunStats.totals.testCases.failed ) + .writeAttribute( "expectedFailures", testRunStats.totals.testCases.failedButOk ); + m_xml.endElement(); + } + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) + void XmlReporter::benchmarkPreparing(std::string const& name) { + m_xml.startElement("BenchmarkResults") + .writeAttribute("name", name); + } + + void XmlReporter::benchmarkStarting(BenchmarkInfo const &info) { + m_xml.writeAttribute("samples", info.samples) + .writeAttribute("resamples", info.resamples) + .writeAttribute("iterations", info.iterations) + .writeAttribute("clockResolution", info.clockResolution) + .writeAttribute("estimatedDuration", info.estimatedDuration) + .writeComment("All values in nano seconds"); + } + + void XmlReporter::benchmarkEnded(BenchmarkStats<> const& benchmarkStats) { + m_xml.startElement("mean") + .writeAttribute("value", benchmarkStats.mean.point.count()) + .writeAttribute("lowerBound", benchmarkStats.mean.lower_bound.count()) + .writeAttribute("upperBound", benchmarkStats.mean.upper_bound.count()) + .writeAttribute("ci", benchmarkStats.mean.confidence_interval); + m_xml.endElement(); + m_xml.startElement("standardDeviation") + .writeAttribute("value", benchmarkStats.standardDeviation.point.count()) + .writeAttribute("lowerBound", benchmarkStats.standardDeviation.lower_bound.count()) + .writeAttribute("upperBound", benchmarkStats.standardDeviation.upper_bound.count()) + .writeAttribute("ci", benchmarkStats.standardDeviation.confidence_interval); + m_xml.endElement(); + m_xml.startElement("outliers") + .writeAttribute("variance", benchmarkStats.outlierVariance) + .writeAttribute("lowMild", benchmarkStats.outliers.low_mild) + .writeAttribute("lowSevere", benchmarkStats.outliers.low_severe) + .writeAttribute("highMild", benchmarkStats.outliers.high_mild) + .writeAttribute("highSevere", benchmarkStats.outliers.high_severe); + m_xml.endElement(); + m_xml.endElement(); + } + + void XmlReporter::benchmarkFailed(std::string const &error) { + m_xml.scopedElement("failed"). + writeAttribute("message", error); + m_xml.endElement(); + } +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + + CATCH_REGISTER_REPORTER( "xml", XmlReporter ) + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +// end catch_reporter_xml.cpp + +namespace Catch { + LeakDetector leakDetector; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_impl.hpp +#endif + +#ifdef CATCH_CONFIG_MAIN +// start catch_default_main.hpp + +#ifndef __OBJC__ + +#ifndef CATCH_INTERNAL_CDECL +#ifdef _MSC_VER +#define CATCH_INTERNAL_CDECL __cdecl +#else +#define CATCH_INTERNAL_CDECL +#endif +#endif + +#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) +// Standard C/C++ Win32 Unicode wmain entry point +extern "C" int CATCH_INTERNAL_CDECL wmain (int argc, wchar_t * argv[], wchar_t * []) { +#else +// Standard C/C++ main entry point +int CATCH_INTERNAL_CDECL main (int argc, char * argv[]) { +#endif + + return Catch::Session().run( argc, argv ); +} + +#else // __OBJC__ + +// Objective-C entry point +int main (int argc, char * const argv[]) { +#if !CATCH_ARC_ENABLED + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif + + Catch::registerTestMethods(); + int result = Catch::Session().run( argc, (char**)argv ); + +#if !CATCH_ARC_ENABLED + [pool drain]; +#endif + + return result; +} + +#endif // __OBJC__ + +// end catch_default_main.hpp +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) + +#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED +# undef CLARA_CONFIG_MAIN +#endif + +#if !defined(CATCH_CONFIG_DISABLE) +////// +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) + +#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif// CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) + +#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) +#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) + +#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) +#define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg ) +#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE",__VA_ARGS__ ) + +#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) +#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) +#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) +#else +#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) +#endif + +#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) +#define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ ) +#define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ ) +#else +#define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ ) +#define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ ) +#endif + +// "BDD-style" convenience wrappers +#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) +#define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) +#define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc ) +#define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) +#define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc ) +#define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) +#define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) +#define CATCH_BENCHMARK(...) \ + INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) +#define CATCH_BENCHMARK_ADVANCED(name) \ + INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), name) +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) + +#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) + +#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) +#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) + +#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) +#define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg ) +#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE",__VA_ARGS__ ) + +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) +#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) +#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) +#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__) +#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#else +#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) ) +#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) ) +#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) +#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) +#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) ) +#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) +#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) ) +#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) +#endif + +#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) +#define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ ) +#define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" ) +#else +#define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ ) +#define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ ) +#endif + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) + +// "BDD-style" convenience wrappers +#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) + +#define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) +#define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc ) +#define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) +#define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc ) +#define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) +#define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) + +#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) +#define BENCHMARK(...) \ + INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) +#define BENCHMARK_ADVANCED(name) \ + INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(C_A_T_C_H_B_E_N_C_H_), name) +#endif // CATCH_CONFIG_ENABLE_BENCHMARKING + +using Catch::Detail::Approx; + +#else // CATCH_CONFIG_DISABLE + +////// +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#define CATCH_REQUIRE( ... ) (void)(0) +#define CATCH_REQUIRE_FALSE( ... ) (void)(0) + +#define CATCH_REQUIRE_THROWS( ... ) (void)(0) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif// CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0) + +#define CATCH_CHECK( ... ) (void)(0) +#define CATCH_CHECK_FALSE( ... ) (void)(0) +#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__) +#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) +#define CATCH_CHECK_NOFAIL( ... ) (void)(0) + +#define CATCH_CHECK_THROWS( ... ) (void)(0) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_CHECK_NOTHROW( ... ) (void)(0) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THAT( arg, matcher ) (void)(0) + +#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define CATCH_INFO( msg ) (void)(0) +#define CATCH_UNSCOPED_INFO( msg ) (void)(0) +#define CATCH_WARN( msg ) (void)(0) +#define CATCH_CAPTURE( msg ) (void)(0) + +#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) +#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) +#define CATCH_METHOD_AS_TEST_CASE( method, ... ) +#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) +#define CATCH_SECTION( ... ) +#define CATCH_DYNAMIC_SECTION( ... ) +#define CATCH_FAIL( ... ) (void)(0) +#define CATCH_FAIL_CHECK( ... ) (void)(0) +#define CATCH_SUCCEED( ... ) (void)(0) + +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) +#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) +#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__) +#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#else +#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) ) +#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) ) +#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#endif + +// "BDD-style" convenience wrappers +#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), className ) +#define CATCH_GIVEN( desc ) +#define CATCH_AND_GIVEN( desc ) +#define CATCH_WHEN( desc ) +#define CATCH_AND_WHEN( desc ) +#define CATCH_THEN( desc ) +#define CATCH_AND_THEN( desc ) + +#define CATCH_STATIC_REQUIRE( ... ) (void)(0) +#define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0) + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#define REQUIRE( ... ) (void)(0) +#define REQUIRE_FALSE( ... ) (void)(0) + +#define REQUIRE_THROWS( ... ) (void)(0) +#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) +#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define REQUIRE_NOTHROW( ... ) (void)(0) + +#define CHECK( ... ) (void)(0) +#define CHECK_FALSE( ... ) (void)(0) +#define CHECKED_IF( ... ) if (__VA_ARGS__) +#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) +#define CHECK_NOFAIL( ... ) (void)(0) + +#define CHECK_THROWS( ... ) (void)(0) +#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0) +#define CHECK_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CHECK_NOTHROW( ... ) (void)(0) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THAT( arg, matcher ) (void)(0) + +#define REQUIRE_THAT( arg, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define INFO( msg ) (void)(0) +#define UNSCOPED_INFO( msg ) (void)(0) +#define WARN( msg ) (void)(0) +#define CAPTURE( ... ) (void)(0) + +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) +#define METHOD_AS_TEST_CASE( method, ... ) +#define REGISTER_TEST_CASE( Function, ... ) (void)(0) +#define SECTION( ... ) +#define DYNAMIC_SECTION( ... ) +#define FAIL( ... ) (void)(0) +#define FAIL_CHECK( ... ) (void)(0) +#define SUCCEED( ... ) (void)(0) +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ )) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) +#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) +#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__) +#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#else +#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) ) +#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) ) +#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) ) +#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) ) +#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#endif + +#define STATIC_REQUIRE( ... ) (void)(0) +#define STATIC_REQUIRE_FALSE( ... ) (void)(0) + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// "BDD-style" convenience wrappers +#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ) ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), className ) + +#define GIVEN( desc ) +#define AND_GIVEN( desc ) +#define WHEN( desc ) +#define AND_WHEN( desc ) +#define THEN( desc ) +#define AND_THEN( desc ) + +using Catch::Detail::Approx; + +#endif + +#endif // ! CATCH_CONFIG_IMPL_ONLY + +// start catch_reenable_warnings.h + + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(pop) +# else +# pragma clang diagnostic pop +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic pop +#endif + +// end catch_reenable_warnings.h +// end catch.hpp +#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED + diff --git a/components/thorvg-main/test/meson.build b/components/thorvg-main/test/meson.build new file mode 100644 index 0000000..936a8fe --- /dev/null +++ b/components/thorvg-main/test/meson.build @@ -0,0 +1,36 @@ +test_compiler_flags = compiler_flags + +if lib_type == 'static' + test_compiler_flags += ['-DTVG_STATIC'] +endif + +test_dep = [] +if host_machine.system() == 'darwin' + test_dep += declare_dependency(link_args: ['-framework', 'Cocoa', '-framework', 'IOKit']) +endif + +test_file = [ + 'testAccessor.cpp', + 'testAnimation.cpp', + 'testFill.cpp', + 'testInitializer.cpp', + 'testLottie.cpp', + 'testMain.cpp', + 'testPaint.cpp', + 'testPicture.cpp', + 'testSavers.cpp', + 'testScene.cpp', + 'testShape.cpp', + 'testSwCanvas.cpp', + 'testSwEngine.cpp', + 'testText.cpp' +] + +tests = executable('tvgUnitTests', + test_file, + include_directories : headers, + link_with : thorvg_lib, + cpp_args : test_compiler_flags, + dependencies : test_dep) + +test('Unit Tests', tests, args : ['--success']) diff --git a/components/thorvg-main/test/regression/check_same_image_size.py b/components/thorvg-main/test/regression/check_same_image_size.py new file mode 100644 index 0000000..e343069 --- /dev/null +++ b/components/thorvg-main/test/regression/check_same_image_size.py @@ -0,0 +1,43 @@ +import os +import subprocess +import sys + +if ( + len(sys.argv) != 5 + or not sys.argv[1].endswith(".svg") + or not os.path.isfile(sys.argv[1]) + or not os.path.isfile(sys.argv[2]) +): + print('Proper usage "python app.py AA.svg /path/to/svg2png 400 100"') + print('Proper usage "python app.py SVG_FILE SVG_PNG_PATH SIZE_IMAGE NUMBER_OF_TRIES"') + raise ValueError( + "POSSIBLE_PROBLEM - Missing or invalid input file or missing path to svg2png" + ) + +try_number = int(sys.argv[4]) +image_size = sys.argv[3] +svg2png_path = sys.argv[2] +image_input = sys.argv[1] +image_output = image_input.replace(".svg", ".png") + +args = [svg2png_path, image_input, "-r", f"{image_size}x{image_size}"] +sizes: dict = {} +for i in range(try_number + 1): + # if i % 100 == 0: + # print(f"{i + 1}/{try_number + 1}") + subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + new_size = os.path.getsize(image_output) + if new_size in sizes: + sizes[new_size] += 1 + else: + sizes[new_size] = 1 + +sizes = dict(sorted(sizes.items(), key=lambda item: item[1], reverse=True)) + +if len(sizes) == 1: + print(f"Not found problem with generating images, sizes - {str(sizes)}") +else: + print( + f"POSSIBLE_PROBLEM - Converting svg to png is not reproducible - file sizes {str(sizes)}", + file=sys.stderr, + ) diff --git a/components/thorvg-main/test/regression/settings_comparison.toml b/components/thorvg-main/test/regression/settings_comparison.toml new file mode 100644 index 0000000..6ebdf9a --- /dev/null +++ b/components/thorvg-main/test/regression/settings_comparison.toml @@ -0,0 +1,38 @@ +[general] +folder_with_files_to_check = "FilesToTest" +problematic_files_path = "ProblematicSVG" # Where to store problematic files, in which conversion failed(e.g. due program crash) +output_folder = "BrokenSVG" # Place where to save files(Input and output that show differences) +ignored_files_path = "IgnoredSVG" # Place where to save ignored files +timeout = 120 +limit_threads = 0 # 0 will use all available threads +px_size_of_generated_file = 400 +ignore_conversion_step = false # Ignore step with conversion files from svg to png, just compare files +ignore_similarity_checking_step = false # Useful to finding problems with generating files +ignore_thorvg_not_supported_items = true # Thorvg not supports files with text, filters +max_difference = 5 # Bigger similarity will show only broken files that are completely different, looks that 0-100 is quite reasonable range +limit_files = 0 # Limit checked files, useful if you are just wanting to check how app works, 0 will remove limit of checked files +remove_files_from_output_folder_at_start = true # Useful if you run app with different settings and you don't want to remove files one by one +debug_show_always_output = false # Allows to find broken files +return_error_when_finding_invalid_files = false # When finding invalid files(broken or problematic) app will close with status 1 +remove_problematic_files_after_copying = false # Remove from output folder problematic svg files +remove_broken_files_after_copying = false # Remove from output folder broken svg files +remove_ignored_files_after_copying = false # Removes not supported folders after copying +remove_generated_png_files_at_end = false # Remove all png from output folder at end +lottie_path = "" +lottie_broken_files_path = "" +lottie_test = false +thorvg_path = "" +thorvg_broken_files_path = "" +thorvg_test = false + +[first_tool] +name = "thorvg_pr" +path = "./build/src/tools/svg2png/svg2png" +png_name_ending = "_thorvg_pr.png" +arguments = "{FILE} -r {SIZE}x{SIZE} -b ffffff" + +[other_tool] +name = "thorvg_develop" +path = "./thorvg_develop/build/src/tools/svg2png/svg2png" +png_name_ending = "_thorvg_develop.png" +arguments = "{FILE} -r {SIZE}x{SIZE} -b ffffff" diff --git a/components/thorvg-main/test/regression/settings_crash_leak.toml b/components/thorvg-main/test/regression/settings_crash_leak.toml new file mode 100644 index 0000000..836106d --- /dev/null +++ b/components/thorvg-main/test/regression/settings_crash_leak.toml @@ -0,0 +1,39 @@ +[general] +folder_with_files_to_check = "FilesToTest" +problematic_files_path = "ProblematicSVG" # Where to store problematic files, in which conversion failed(e.g. due program crash) +output_folder = "BrokenSVG" # Place where to save files(Input and output that show differences) +ignored_files_path = "IgnoredSVG" # Place where to save ignored files +timeout = 120 +limit_threads = 0 # 0 will use all available threads +px_size_of_generated_file = 400 +ignore_conversion_step = false # Ignore step with conversion files from svg to png, just compare files +ignore_similarity_checking_step = false # Useful to finding problems with generating files +ignore_thorvg_not_supported_items = true # Thorvg not supports files with text, filters +max_difference = 5 # Bigger similarity will show only broken files that are completely different, looks that 0-100 is quite reasonable range +limit_files = 0 # Limit checked files, useful if you are just wanting to check how app works, 0 will remove limit of checked files +remove_files_from_output_folder_at_start = true # Useful if you run app with different settings and you don't want to remove files one by one +debug_show_always_output = false # Allows to find broken files +return_error_when_finding_invalid_files = false # When finding invalid files(broken or problematic) app will close with status 1 +remove_problematic_files_after_copying = false # Remove from output folder problematic svg files +remove_broken_files_after_copying = false # Remove from output folder broken svg files +remove_ignored_files_after_copying = false # Removes not supported folders after copying +remove_generated_png_files_at_end = false # Remove all png from output folder at end +lottie_path = "" +lottie_broken_files_path = "" +lottie_test = false +thorvg_path = "./build/src/tools/svg2png/svg2png" +thorvg_broken_files_path = "BrokenFILES" +thorvg_test = true + +[first_tool] +name = "thorvg_pr" +path = "./build/src/tools/svg2png/svg2png" +png_name_ending = "_thorvg_pr.png" +arguments = "{FILE} -r {SIZE}x{SIZE} -b ffffff" + +[other_tool] +name = "thorvg_develop" +path = "./thorvg_develop/build/src/tools/svg2png/svg2png" +png_name_ending = "_thorvg_develop.png" +arguments = "{FILE} -r {SIZE}x{SIZE} -b ffffff" + diff --git a/components/thorvg-main/test/resources/Arial.ttf b/components/thorvg-main/test/resources/Arial.ttf new file mode 100644 index 0000000..7ff88f2 Binary files /dev/null and b/components/thorvg-main/test/resources/Arial.ttf differ diff --git a/components/thorvg-main/test/resources/NanumGothicCoding.ttf b/components/thorvg-main/test/resources/NanumGothicCoding.ttf new file mode 100644 index 0000000..d1cbe11 Binary files /dev/null and b/components/thorvg-main/test/resources/NanumGothicCoding.ttf differ diff --git a/components/thorvg-main/test/resources/rawimage_200x300.raw b/components/thorvg-main/test/resources/rawimage_200x300.raw new file mode 100644 index 0000000..83958db --- /dev/null +++ b/components/thorvg-main/test/resources/rawimage_200x300.raw @@ -0,0 +1,110 @@ +›k�ÿœkÿ l~ÿ l}ÿ¡l{ÿ¡kyÿ¡lxÿŸjtÿ¡jrÿ jsÿžjtÿ jzÿžj|ÿ�j|ÿŸk}ÿžk}ÿ�k{ÿ�jzÿžj{ÿ�iyÿœhuÿœgsÿšfpÿ›fpÿ™enÿ™emÿ™foÿ™epÿ™eqÿ›erÿ›gtÿœhuÿœivÿžiwÿ�iwÿžjzÿži|ÿ�i{ÿžk}ÿžk}ÿ�k~ÿžkÿŸl�ÿžkÿžk~ÿžk~ÿ�kÿžl€ÿŸk~ÿŸk|ÿŸkzÿ jxÿ kwÿ isÿ¡iqÿ¢ioÿ¡ipÿ iqÿ isÿŸirÿŸirÿ iqÿ ipÿ¡hpÿ¢hnÿ¡hkÿ£ggÿ¥hfÿ¥heÿ¥heÿ¦hdÿ¦hcÿ¦ibÿ¥icÿ¥jbÿ§jbÿ§i`ÿ§j`ÿ¦i_ÿ¨h]ÿ¦h]ÿ¨i]ÿ¦h\ÿ§h]ÿ§h\ÿ§gZÿ¦hYÿ¦h[ÿ¦h\ÿ§h[ÿ¦gYÿ¦gYÿ¦fXÿ¦gWÿ¦fWÿ§fVÿ¦eTÿ¥eTÿ§fUÿ¥eTÿ¦eUÿ¥eTÿ¥eTÿ¥eSÿ¥dSÿ¥eTÿ¦fXÿ¨iZÿ§hZÿ¨i\ÿ¨h]ÿ¦h^ÿ§g_ÿ¦haÿ¦h_ÿ¤e^ÿ£d]ÿ¢c]ÿ¢c]ÿ¡b\ÿ a\ÿ a\ÿ¡b`ÿŸbcÿŸepÿžetÿ�duÿ�ewÿ�ezÿœe|ÿ›e{ÿ›dwÿšcsÿšapÿšaoÿšaoÿ™anÿ™amÿ™apÿ™`nÿ˜_lÿ—^iÿ—^hÿ—^mÿ—`qÿ”`sÿ’_sÿ’a{ÿ“b�ÿ’`{ÿ’_tÿ’^rÿ’^rÿ‘^uÿ�_uÿ‘]sÿ‘\rÿ�\pÿ�[kÿ�ZjÿŽZjÿŽYgÿ�Xbÿ‹W`ÿ�Xcÿ�YiÿŒZkÿ�YkÿŒXjÿ‹XjÿŠYpÿ‹\{ÿŠ]~ÿ‹\}ÿŠ[yÿŒ[vÿ‹YoÿŒWgÿŒWgÿŒWgÿ�XiÿŒYkÿ‹Xjÿ‹Xiÿ‹Xjÿ‰Wjÿ‹Wjÿ‰ViÿˆWlÿ‰XpÿˆWqÿˆXrÿˆWsÿˆYvÿ‡XuÿˆVnÿˆVkÿ‡VlÿˆUjÿˆSdÿœk�ÿ�kÿŸl}ÿŸl{ÿ lzÿ¡myÿ¡kvÿ¡ktÿ¢ktÿ¡lrÿ juÿ kzÿŸl~ÿžmÿ l|ÿ kwÿ¡kwÿ kxÿ kyÿŸjvÿžhtÿžirÿžirÿœhrÿœgpÿ›foÿšfpÿšepÿ›erÿ›grÿ�huÿœhvÿœiwÿ�iyÿ�iyÿ�j{ÿ�j|ÿœj|ÿ�j}ÿžk~ÿ�l€ÿŸlƒÿŸlƒÿŸm�ÿŸlÿžlÿŸlÿŸm€ÿ m~ÿ l|ÿ kzÿ¡lyÿ¡lyÿ¢kvÿ¢jrÿ¢jpÿ¤jpÿ¤jqÿ¢jrÿ¡iqÿ jsÿ¡jrÿ jsÿ¢jsÿ¡iqÿ¢ipÿ£ikÿ¥hjÿ¤ihÿ¦ifÿ¦icÿ¦ibÿ§jbÿ¦jcÿ§jcÿ§jcÿ§ibÿ¨k`ÿ§j`ÿ§j`ÿ¨j^ÿ¨i^ÿ©i]ÿ¨i[ÿ¨h[ÿ©iYÿ§iYÿ§iYÿ§h[ÿ¨hZÿ§hZÿ¨h[ÿ§hZÿ§gXÿ©hXÿ§gXÿ§gWÿ§hXÿ§gWÿ¦fVÿ§fVÿ§fVÿ¦fUÿ¦fUÿ¦eVÿ§fWÿ¦gXÿ§h\ÿªj]ÿ©j^ÿ¦g_ÿ¦f_ÿ¦faÿ¨hdÿ¨idÿ¦hbÿ¥fbÿ¢c_ÿ¡c_ÿ¡b`ÿ¡b`ÿ¡b`ÿ¡a`ÿ cfÿ fqÿ gvÿŸgyÿžg|ÿžg€ÿ›h‚ÿšg�ÿ›f}ÿšdzÿšcuÿ›brÿš`lÿš_hÿ›_gÿš_hÿš_iÿ˜`jÿ™_jÿ˜^fÿ—^gÿ–^lÿ–asÿ“_tÿ“azÿ“a}ÿ”`xÿ’^qÿ’^oÿ“^nÿ“^rÿ‘^sÿ‘]rÿ‘\oÿ�\mÿ�[jÿ�Zjÿ�ZhÿŽYdÿ�YcÿŽYcÿŽXcÿŽYeÿŒYeÿ�Xgÿ�Ygÿ�Yiÿ‹YlÿŒ\vÿ‹\|ÿŒ\{ÿ�\zÿŒ\wÿ�ZrÿŽYlÿ�Xjÿ�XjÿŒYmÿ�YnÿŒYlÿŒXlÿ‹Xoÿ‹YoÿŠXmÿ‹Wmÿ‰Xoÿ‰XqÿˆXsÿˆXsÿˆXuÿˆYuÿˆXrÿˆVlÿˆUfÿˆUeÿˆUeÿ‰Tcÿœkƒÿ�k‚ÿžm�ÿŸm€ÿ¡n€ÿ¢nÿ£mzÿ£mwÿ¢lvÿ¡kuÿ¢lwÿ£n}ÿ¢o€ÿ¡n€ÿ¡lzÿ¡ktÿ£ktÿ£lvÿ¢lxÿ¢juÿ¡jtÿŸirÿ jtÿŸktÿžisÿ�hsÿœhqÿ›frÿ›gqÿœgrÿ�huÿžiwÿ�iyÿžk|ÿžj}ÿœj|ÿœj~ÿ�j~ÿžk~ÿžk€ÿžl‚ÿžl„ÿžm„ÿžlƒÿ m‚ÿ l€ÿŸm€ÿ l€ÿ¡mÿ¢m~ÿ¢l{ÿ¡lxÿ¢lyÿ¢lwÿ£ltÿ£kqÿ¥lpÿ¦kqÿ¥kpÿ¤kqÿ¤jqÿ£jrÿ¢ksÿ¡ktÿ¡kuÿ¢ktÿ¢kqÿ£jmÿ¤jlÿ¥ihÿ¦jfÿ§jeÿ§ieÿ§idÿ¨ieÿ©keÿ§iaÿ©jcÿ¨jbÿ©jbÿ¨jbÿ¨i_ÿ¨i\ÿªj]ÿ©j\ÿªj[ÿ©iYÿ¨iYÿ¨j[ÿ¨i[ÿ©j\ÿ¨i[ÿ©h[ÿ©hXÿ©hXÿ§iYÿ¨hZÿ§hYÿ§hYÿ¨gWÿ§gVÿ§fUÿ§fVÿ§fVÿ§fXÿ¦gYÿ§g\ÿ§i^ÿ©jaÿ©i`ÿ©icÿ§icÿ©ifÿ©ihÿ§hdÿ§hdÿ§gfÿ¥geÿ¢ecÿ¢edÿ¢deÿ¢deÿ¡deÿ dhÿ eqÿžgxÿŸg}ÿŸh€ÿ�h‚ÿšh‚ÿšg�ÿ™f~ÿšf}ÿœeyÿšcsÿ›`jÿ›`iÿš_hÿ™_hÿ™`jÿ˜`lÿš`lÿ™^fÿ˜]cÿ—^gÿ–`nÿ–`qÿ–`sÿ•`sÿ”_nÿ”\jÿ”[iÿ”\hÿ’]kÿ“]oÿ’]nÿ’\kÿ‘[hÿ�Zhÿ�Yfÿ�ZdÿŽXbÿŽXaÿ�W`ÿ�X^ÿ�W_ÿ�XaÿŽXdÿ�XeÿŽYhÿŒZjÿ‹[qÿ�]yÿŒ[xÿŒ\xÿ�\wÿŽ[sÿ�[pÿŽZlÿ�ZnÿŽZqÿŽZqÿŒYoÿŒZrÿ‹ZsÿŒZrÿ‹Zqÿ‹YqÿŠZsÿŠZtÿ‰Xsÿ‰YsÿˆXsÿˆXrÿ‰Xoÿ‰Vgÿ‰T`ÿ‰T`ÿ‰T_ÿˆS^ÿ�m…ÿ›l„ÿ�m…ÿžm„ÿŸn‚ÿ¡n€ÿ¢m|ÿ¢nzÿ£mzÿ¢myÿ¢m{ÿ£o~ÿ¢o�ÿ¡nÿ¡lyÿ¢ksÿ¢lsÿ¤luÿ£luÿ¢ktÿ¢ktÿ¢ltÿ¡jsÿ kvÿ kuÿžisÿ�irÿ�hrÿ›hqÿœhsÿœiuÿœiwÿ�i{ÿžk}ÿ�j~ÿžkÿ�k~ÿ�kÿžk�ÿ�k�ÿœl„ÿ�m…ÿžm…ÿžmƒÿžm‚ÿŸm�ÿŸl€ÿŸm€ÿ m€ÿ¢mÿ£m{ÿ£mzÿ¢mxÿ¢lvÿ¤luÿ¥lsÿ¥mqÿ¥loÿ¥loÿ¥loÿ¥lpÿ¤kpÿ£krÿ£ktÿ¢lvÿ¡kuÿ¢jtÿ£ksÿ¤kpÿ¤jlÿ¤jkÿ¥kiÿ¦jgÿ¦ifÿ¦ieÿ§keÿ¨jdÿ§jdÿ©keÿ©jdÿ©jbÿ©lbÿªkaÿ¨k^ÿ©k\ÿªj[ÿ©jYÿ©jZÿ©j[ÿ©j[ÿ©j]ÿ©i\ÿ©iZÿ§iXÿ©iXÿ©iZÿ¨jZÿ¨iZÿ¨iXÿ§gUÿ¨gWÿ¨gVÿ§gWÿ¨gXÿ§hYÿ¥h\ÿ§h]ÿ§h_ÿ§iaÿ¨gcÿªkfÿªkgÿ©lgÿ¨ifÿ¥fbÿ¦gcÿ¦fdÿ¥fdÿ£eeÿ£efÿ¢efÿ¢egÿ¢fjÿ emÿ gtÿŸh{ÿžh}ÿ�g�ÿžg�ÿœgÿšhÿ™f~ÿ™e}ÿšdzÿœcrÿ›ajÿšaiÿ›ajÿš`iÿ˜`jÿš`nÿ™`kÿ™_hÿ˜^eÿ–]fÿ–^iÿ—_mÿ—`pÿ–_lÿ•^hÿ•]gÿ”\eÿ”\eÿ“\hÿ’]jÿ’]kÿ�Zeÿ�Ybÿ�Xaÿ�Xaÿ�Yaÿ�X`ÿ�X`ÿ�W]ÿ�W\ÿ�W]ÿŽW_ÿŽXaÿ�Xdÿ�Yfÿ‹Yjÿ�[rÿŒ[tÿŒ\vÿ�\wÿ�\wÿŽ[rÿ�[mÿ�[kÿŽ[pÿŽ[rÿ�Zqÿ‹Zpÿ�[vÿŒ[wÿ‹Ztÿ‹ZsÿŠZtÿŠZtÿŠZsÿŠXrÿˆXpÿ‰Woÿ‰Woÿ‰VkÿŠVdÿŠT^ÿˆS\ÿ‰S[ÿŠSZÿžpˆÿžo‡ÿ�m‡ÿœl…ÿ�mƒÿŸmƒÿ mÿ¡m|ÿ¢m|ÿ£n}ÿ£o~ÿ¤p�ÿ£o�ÿ£n~ÿ£mxÿ£ltÿ¥ltÿ¤msÿ¤msÿ¥mrÿ¤lrÿ¤lsÿ£lsÿ¢kuÿ¢kvÿ¡ksÿ irÿžiqÿžirÿ�irÿ�iuÿ�jxÿžj{ÿžk}ÿžlÿŸl€ÿžm�ÿžm‚ÿžmƒÿžn„ÿ�m…ÿžm†ÿŸn…ÿžn„ÿžm‚ÿ m�ÿ m�ÿ n€ÿ¢n€ÿ£n€ÿ£o~ÿ£o|ÿ£nyÿ¥nwÿ¦nvÿ¦mtÿ¥lqÿ¦npÿ§moÿ¥moÿ§lpÿ¦lpÿ¦lpÿ¥ltÿ¤luÿ¤mvÿ¤lvÿ£kuÿ¤lrÿ¥kpÿ¥knÿ¥klÿ§kkÿ§kjÿ¨liÿ§lhÿ¨kfÿ¨kgÿ¨kfÿ©kfÿ©jeÿªldÿªlbÿ©l`ÿªl_ÿ«l]ÿªk[ÿ«k[ÿ«k\ÿªk]ÿ©k^ÿªk]ÿ©j[ÿ©jYÿ©jYÿªiZÿ¨j[ÿªk[ÿ©hXÿ©gWÿªiVÿ¨hVÿ©hXÿ©hYÿ¨i[ÿ¨i]ÿ§i^ÿ§h`ÿ¨g`ÿªidÿªjgÿªkhÿªlhÿ©kgÿ¦gcÿ¦gdÿ¦geÿ¥gdÿ¤ggÿ£fhÿ¢ghÿ¢fjÿ¡elÿ¢foÿ¡ftÿŸhyÿŸh|ÿži€ÿ�hÿœgÿ›g~ÿšg€ÿšgÿ›ezÿ›esÿ›akÿ›aiÿš`hÿ™`iÿ˜_hÿ˜_iÿ˜_jÿ˜_iÿ˜^gÿ—^gÿ—`lÿ—`nÿ–_nÿ—_jÿ—]fÿ–\eÿ•\eÿ“\fÿ“\gÿ’\iÿ’\iÿ‘[fÿ�Ycÿ�Yaÿ‘Zbÿ�Ycÿ�Yaÿ�Xaÿ�X`ÿŽX_ÿ�XaÿŽXaÿŽXaÿŽYdÿ�XfÿŽZkÿŽ[pÿ�\rÿŒ[tÿ�]xÿŽ\vÿ�[pÿ�Zjÿ�Zjÿ�\qÿŽ\sÿŽZqÿ�Zqÿ�[vÿ�[vÿŒZrÿŒZsÿ‹Ztÿ‹ZsÿŠYrÿŠYqÿ‰XqÿŠYqÿ‰Xmÿ‰Wiÿ‹Vdÿ‹T_ÿ‹R[ÿ‹SZÿ‹RYÿŸpŠÿŸoˆÿŸoˆÿžn‡ÿ�m†ÿžn…ÿžmƒÿ¡o€ÿ£o€ÿ£o�ÿ£p�ÿ¤p�ÿ¤pÿ¥o|ÿ¤nwÿ¦mvÿ¥mrÿ§nrÿ¦nqÿ§nqÿ§nqÿ§msÿ¥mtÿ¤nuÿ¤mvÿ¤mvÿ¡ksÿ jqÿ iqÿŸjsÿžitÿžjwÿžkxÿŸkzÿŸl~ÿŸm‚ÿŸn„ÿŸnƒÿžn„ÿžn†ÿŸn†ÿŸn†ÿŸn…ÿ o…ÿ nƒÿ m‚ÿ¡n‚ÿ¢o�ÿ¢o�ÿ£n€ÿ£o€ÿ¤o~ÿ¥ozÿ§oxÿ§oxÿ§nvÿ¦msÿ§nrÿ¨oqÿ§npÿ¨moÿ¨noÿ§moÿ§nqÿ§msÿ¦msÿ¦muÿ¤muÿ¦mtÿ¥mrÿ¦lpÿ§lpÿ§lnÿ§lmÿ§lmÿ§kkÿ§ljÿ¨ljÿ©kgÿ©khÿ©lgÿªlfÿªldÿªmcÿ«laÿªl^ÿªl]ÿ«l]ÿªl\ÿ«l]ÿ¬l]ÿ«l]ÿ«k\ÿ«k[ÿ©jZÿ«kZÿ«j[ÿ«j\ÿªjZÿªhWÿªiVÿ¨hVÿ©hXÿ©iZÿ©i\ÿ©i]ÿ¨i^ÿ§i_ÿ¨i`ÿ¨hcÿ©idÿªlhÿ¬miÿ«khÿ©jgÿªkhÿ¨kjÿ©kjÿ¦ikÿ¤hiÿ£giÿ¢glÿ¢goÿ¢gpÿ¢gsÿ hxÿ i}ÿŸh~ÿŸhÿ�h~ÿœg~ÿšf}ÿ›f~ÿœf|ÿœeuÿ›bnÿ›ahÿš`fÿš`hÿ˜_fÿ—_gÿ˜_jÿ–^iÿ—^gÿ˜^hÿ˜`mÿ—_nÿ–`nÿ˜^jÿ•\cÿ–\bÿ–]fÿ“]hÿ’\iÿ’\jÿ’]kÿ‘\iÿ‘\gÿ‘[fÿ‘[hÿ‘[gÿ�Zfÿ�Zeÿ�Zfÿ�Yfÿ�Zfÿ�Zfÿ�XdÿŽXcÿŽXeÿ�ZiÿŽZkÿ�\oÿ�\sÿ�\vÿ�]uÿ�[pÿ�Zkÿ�Zmÿ�\rÿ�\uÿŽ[sÿ�[rÿ�\tÿŽ[sÿŽZqÿŽZrÿ�Ztÿ‹Ysÿ‹Zuÿ‹Ztÿ‹ZuÿŠYsÿ‹Xnÿ‹Whÿ‹Veÿ‹T`ÿ‹S]ÿŒSZÿŒRXÿŸp‰ÿ qˆÿ¡qŠÿŸpŠÿžoˆÿŸoŠÿžn…ÿŸnƒÿ¡oƒÿ¢p„ÿ£qƒÿ¤q‚ÿ¥qÿ¥p{ÿ¥ozÿ¦oxÿ¨otÿ¨osÿ¨orÿ¨npÿ§nqÿ¨orÿ§osÿ¦otÿ§nwÿ¦owÿ¦lsÿ¤lqÿ¢jpÿ¡ksÿ jtÿŸjuÿ kwÿ lyÿŸl}ÿ n„ÿ n„ÿŸn‚ÿŸnƒÿ o…ÿžn…ÿ n…ÿ o†ÿ p…ÿ o„ÿ¢o„ÿ¢oƒÿ¢o‚ÿ£o�ÿ¢o€ÿ¢o€ÿ£oÿ¤o}ÿ¤ozÿ¥pzÿ¨ozÿ¨ovÿ©ouÿ¨orÿ¨noÿ©ooÿ©ooÿªnnÿ©noÿ¨noÿ¨npÿ§nqÿ§nrÿ¦mrÿ§mrÿ§mpÿ§moÿ§moÿ§mnÿ§mmÿ¨mnÿ¨llÿ¨ljÿ¨ljÿ©ljÿ©lhÿªlgÿªlfÿªmeÿ«mdÿ«mcÿªm`ÿªl^ÿ«m_ÿªl]ÿ¬l]ÿ¬l]ÿªl\ÿªl\ÿ«k[ÿ«k[ÿ«k[ÿ«k[ÿ«jZÿªjXÿªjWÿªjWÿ©jYÿªj[ÿ©jZÿ©j\ÿ©j^ÿ¨i_ÿ§i`ÿ©jbÿ©jbÿ¨jcÿªkgÿªkgÿ©jfÿ«miÿ«mkÿ¨lkÿ§jlÿ¤giÿ¢fhÿ£hnÿ£gpÿ£gqÿ£hrÿ¡huÿ hzÿŸj}ÿ iÿžh|ÿžf{ÿœg{ÿœg|ÿœf{ÿ�etÿ›clÿ›ahÿ›`eÿš`eÿ˜_fÿ˜_iÿ–_iÿ—_hÿ–_gÿ—_gÿ—_iÿ—_kÿ–`mÿ–^hÿ•]dÿ•\`ÿ“[cÿ“]kÿ�\kÿ’]kÿ‘[lÿ’]lÿ�\gÿ‘\iÿ’]nÿ‘\mÿ‘\mÿ�\kÿ�[lÿ�[mÿ�[kÿ�YgÿŽYfÿŽXdÿŽYeÿŽYfÿŽYiÿ�Zlÿ�\oÿŽ]wÿŽ]vÿ�\rÿ�\oÿ�\oÿ�\rÿ�]uÿ�]uÿ�[rÿ�[rÿ�[rÿŽ[pÿŽ[rÿ�Zsÿ‹[tÿ�[vÿ‹Yrÿ‹Zqÿ‹Ypÿ‹Xlÿ‹VgÿŒVeÿ‹U`ÿŠT\ÿ‹RZÿŒSYÿ q‹ÿ¡q‹ÿ¡rŒÿ¡rŒÿ q‹ÿŸq‹ÿŸpŠÿŸpˆÿ p‡ÿ¡pˆÿ£r†ÿ¦r„ÿ¥r‚ÿ¦qÿ§q}ÿ¦pyÿ©qwÿ©psÿ©qsÿ©qrÿ©pqÿ©pqÿ©qsÿ©ptÿ©qwÿ©qwÿ¨otÿ§nqÿ¥mqÿ¤lsÿ£ltÿ¢luÿ¡mwÿ¡myÿŸm|ÿ n�ÿ n‚ÿ o�ÿ¡n‚ÿ¡o„ÿ¡p…ÿ¢o„ÿ£p†ÿ£p†ÿ¢p…ÿ£p…ÿ£p„ÿ£p„ÿ£p„ÿ£p‚ÿ£o�ÿ¤q‚ÿ¤p€ÿ¥q€ÿ§qÿ¨q}ÿ¨pyÿªqxÿ©otÿ©orÿªpqÿ«opÿªnnÿ«onÿªonÿ«onÿªooÿ©npÿ©npÿ©npÿ©noÿ©nnÿ©noÿ©noÿ©nnÿ©nnÿ©mmÿ©mmÿ©mmÿªmmÿ©liÿªliÿªmiÿªmhÿ«mgÿªmgÿ«neÿ¬ncÿ­ncÿ¬mbÿ¬m`ÿ­m_ÿ¬m^ÿ¬m]ÿ­l\ÿ¬l[ÿ¬kZÿ¬l[ÿ«kYÿªkXÿ«kXÿªjXÿ«k[ÿ«k\ÿ«k\ÿ©j\ÿ©j^ÿ©k`ÿ¨jaÿ¨iaÿ©j`ÿ©k`ÿªldÿªkdÿ¬mfÿ­oiÿ«mjÿ©kjÿ§jjÿ¥giÿ£gjÿ£hrÿ£itÿ£isÿ£hrÿ¢htÿ hvÿ¡i{ÿ¡i~ÿŸi}ÿžhzÿ�fzÿœg{ÿ�fyÿ�fuÿœblÿ›aiÿ›agÿš`fÿ™`hÿ˜`iÿ—_jÿ–^gÿ–^gÿ—]eÿ—^fÿ—_hÿ˜_iÿ•^fÿ•]dÿ”\dÿ’\dÿ“]lÿ�]oÿ�^pÿ�]qÿ�]qÿ�\mÿ�\mÿ‘^pÿ‘^qÿ�]pÿ‘]qÿ�]rÿ�]qÿ�\nÿ�Zjÿ�Zgÿ�Zgÿ�Zgÿ�Zgÿ�ZhÿŽ[mÿ�]rÿ�^wÿŽ^xÿ�^uÿ�]sÿ�]sÿ‘^tÿ‘_wÿ‘^uÿ‘]sÿ’]qÿ‘\rÿ�\rÿ�]uÿ�\vÿŽ\vÿŽ[sÿŽYmÿ�XiÿŒXiÿŒYiÿŒWgÿŒWeÿŒVaÿŒT\ÿ‹SWÿ‹RUÿ¢r�ÿ¡r�ÿ¢rŽÿ£s�ÿ¢r‹ÿ£sŒÿ¡rŒÿ pŒÿ¡qŒÿ¡q‹ÿ¢q‰ÿ¥s‡ÿ§t†ÿ¨sƒÿ§r~ÿ©q{ÿ©qxÿ©puÿ«rvÿªruÿ«qtÿªpsÿ«qtÿ«ruÿªqvÿ«rwÿ«qvÿ©prÿ©psÿ¨puÿ¦nvÿ¤mvÿ£nwÿ¢myÿ£n{ÿ¢n~ÿ¤p�ÿ¤p�ÿ¤p‚ÿ¥r…ÿ¥q…ÿ¤q†ÿ¤q…ÿ£q„ÿ¤q…ÿ£q„ÿ¤q…ÿ¤p„ÿ£p„ÿ¤p„ÿ¤pƒÿ¤pƒÿ¥p‚ÿ¦q‚ÿ¨r�ÿ¨r€ÿªr}ÿªr|ÿ¬qwÿªptÿ«qtÿªprÿ«poÿ­pnÿ¬pmÿ¬pnÿ¬onÿ¬pnÿ«ooÿ«nnÿªnmÿ«nnÿªnmÿªnnÿ«onÿªonÿªnnÿªnnÿ«nnÿªmmÿªnmÿ«nlÿ«nlÿ«mkÿªmkÿ¬mjÿ¬miÿ¬niÿ«mfÿ¬mfÿ­neÿ­mcÿ¬m`ÿ­m_ÿ­m^ÿ­m\ÿ­l\ÿ­l\ÿ¬m[ÿ­lYÿ¬lXÿ­lZÿ¬k]ÿ«k]ÿªk]ÿ«k_ÿªk_ÿ©kaÿªj`ÿªk`ÿ©j`ÿ¨jaÿ«lcÿ¬meÿ¯ohÿ°qkÿ­niÿ©kiÿ§iiÿ¥hiÿ¤glÿ¥jvÿ¢jxÿ¤jxÿ£irÿ£hqÿ¢hsÿ¡iyÿ j}ÿ i~ÿŸh|ÿžh|ÿžh|ÿžgzÿžfxÿœcoÿœbkÿœaiÿœbkÿšajÿ™`lÿ—alÿ–_kÿ–^iÿ–^gÿ˜_hÿ–^hÿ–_hÿ•^iÿ”]iÿ“\hÿ’\jÿ’]mÿ�]qÿŽ^uÿŽ^uÿŽ]vÿŽ]uÿŽ\sÿ�]sÿ�^sÿ‘]sÿ�^uÿ�^vÿ�]sÿ�\oÿ�[kÿŽZjÿ�Yjÿ�ZkÿŽZkÿ�[lÿ�\pÿ�^vÿ�_yÿ�_zÿ�_zÿ�^wÿ’_vÿ’_vÿ“`vÿ’^vÿ“^sÿ’^qÿ“\nÿ‘[nÿ�[rÿŽ[rÿ�[qÿ�Zlÿ�Xfÿ�WaÿŒVaÿŒWaÿŒWbÿ�V`ÿ�U^ÿŒT[ÿŒSVÿŒSUÿ¡s�ÿ¢sŽÿ£s�ÿ£s�ÿ¤tŒÿ¤t�ÿ£t�ÿ¡sŽÿ£s�ÿ¡r�ÿ¡r‹ÿ¤sŠÿ¦tˆÿ©t…ÿ¨s€ÿ¨r|ÿ©r{ÿªrxÿ«rxÿ«swÿ«rwÿ¬rvÿ«ruÿ«ruÿ«rvÿªruÿ¬qvÿ«ruÿ«ruÿ«qvÿ¨qwÿ¦pxÿ¦oyÿ¤ozÿ£o{ÿ£o}ÿ¤oÿ¥p�ÿ¦q‚ÿ¦r„ÿ¥s…ÿ¥r†ÿ¥r‡ÿ¥rƒÿ¥r‚ÿ¥rƒÿ¥qƒÿ¤qƒÿ£p„ÿ£pƒÿ£p„ÿ£pƒÿ¥qƒÿ¦q‚ÿ¦q‚ÿ¨r�ÿ¨s€ÿ«sÿ«rzÿ¬pvÿ¬rwÿ«rtÿ¬qqÿ­qoÿ®roÿ®plÿ®pmÿ®pmÿ­pmÿ¬pnÿ¬ooÿ«nnÿ«onÿ«omÿ«omÿ«onÿ«ooÿªonÿªnoÿªnnÿªnmÿªnmÿ«mlÿ«nnÿªnnÿ«noÿ«nnÿ«nlÿ¬nlÿ­okÿ¬piÿ®ogÿ®ncÿ­n`ÿ¬m_ÿ­m^ÿ­m]ÿ¬l\ÿ®m\ÿ¬lZÿ­l[ÿ¬l[ÿ«l\ÿ¬l^ÿ«l^ÿªk_ÿ«kaÿªkbÿ¨kaÿ©k`ÿ©kaÿ¨j`ÿªldÿ¬nfÿ­ohÿ¬nhÿ«lhÿ§khÿ¨kkÿ¨lmÿ¦joÿ¤kvÿ¤kzÿ£kxÿ¤jqÿ¤ioÿ¢hrÿ ivÿ¡i{ÿ h{ÿ i}ÿži}ÿžg{ÿžgyÿžhwÿžcpÿ�bkÿœbkÿ›bkÿšbmÿ™bnÿ˜bpÿ—apÿ–`oÿ–`lÿ–_lÿ–_lÿ–`mÿ”`oÿ“_pÿ“_oÿ’]oÿ‘]qÿ�^uÿŽ^wÿ�^wÿ�^xÿŒ^xÿ�]yÿŽ]yÿŽ^vÿŽ]vÿ�_yÿ�_xÿŽ\rÿ�[nÿ�Zkÿ�Ziÿ�Zhÿ�ZkÿŽ[nÿ�[pÿŽ]rÿŽ^wÿ�_{ÿ�_{ÿ�_zÿ�_xÿ‘_wÿ’^tÿ”`tÿ”^qÿ“]mÿ“]mÿ’\jÿ‘[jÿ‘\nÿ�[mÿ�[kÿŽYfÿ�Waÿ�U\ÿ�UZÿŒVZÿ�U[ÿŒVZÿ�TYÿŒTWÿŒSWÿŒSUÿŸs‘ÿ¢s�ÿ¢t�ÿ¢t�ÿ¤uŽÿ¥v‘ÿ¥u�ÿ£u�ÿ£u�ÿ¡s�ÿ¡sŽÿ¢rŒÿ¥sˆÿ§s†ÿ©tƒÿ¨t�ÿ©s~ÿ©r|ÿ«t}ÿ¬t}ÿ¬t|ÿ­tzÿ¬swÿ«twÿ«swÿ¬syÿ¬szÿ­tyÿ¬txÿ­tyÿ¬szÿ«szÿ©s{ÿ¨q{ÿ¦q{ÿ¦q~ÿ¦q€ÿ¥q‚ÿ¥r„ÿ¦r†ÿ¦s‡ÿ¦sŠÿ¦sŠÿ¥tˆÿ§s†ÿ¦s…ÿ¦s…ÿ¥r„ÿ¥r„ÿ¤r…ÿ¤r„ÿ¥qƒÿ¥rƒÿ§r„ÿ§r„ÿ§rƒÿ©tƒÿ©t‚ÿªsÿ¬s}ÿ­t{ÿ¬swÿ¬qrÿ­qpÿ¯qpÿ¯roÿ¯rmÿ¯smÿ®rkÿ¯rkÿ®qlÿ®plÿ­pnÿ­pnÿ­qpÿ­ppÿ«ppÿ«ppÿ«pqÿ«ppÿ«poÿ«ooÿ«onÿªooÿªopÿ«oqÿªorÿ«pqÿ¬ooÿ¬olÿ­ojÿ­piÿ®ofÿ­odÿ­odÿ¬ncÿ­naÿ®n_ÿ®n`ÿ¬m_ÿ­m_ÿ­m_ÿ­m_ÿ­m_ÿ¬m_ÿ«laÿ«lbÿªlaÿªmbÿªkaÿ©lbÿªlbÿªlcÿ¬nfÿ¬ngÿ«lgÿ¬mhÿ«nhÿªmiÿªmlÿ©mpÿ¦luÿ¦lxÿ¥lwÿ¤joÿ¢gmÿ£gqÿ¢htÿ¢iuÿ¡j{ÿ j~ÿ i}ÿŸgyÿžfvÿŸfrÿŸdmÿžbiÿ�biÿœcnÿšbpÿ™cqÿ˜bsÿ—ctÿ—buÿ–asÿ•arÿ•arÿ•`rÿ”_sÿ’_uÿ’`uÿ�_uÿ�^uÿ�^xÿŽ_yÿŒ^yÿŒ^zÿ‹]yÿ�^zÿŽ^zÿŽ_zÿ�^zÿŽ_{ÿŽ^xÿŽ\rÿ�\oÿ�[jÿ�Zfÿ�Zfÿ�Zhÿ�\nÿŽ]rÿ�]uÿ�^xÿ�_{ÿ�_{ÿ�_{ÿ‘`|ÿ’_xÿ”_rÿ“\kÿ“\iÿ“[gÿ“[hÿ’[gÿ‘[iÿ‘[kÿ‘[jÿ�YgÿŽWcÿŽV_ÿŽU[ÿ�VYÿŽUWÿ�TVÿ�TWÿ�TXÿ�TWÿŒTXÿŒUZÿžr•ÿ u•ÿ¡u“ÿ£v”ÿ¤v”ÿ¤w”ÿ¦w”ÿ¤v’ÿ¤u‘ÿ¤u‘ÿ¤t�ÿ¢s�ÿ£sŠÿ¥s‡ÿ¦t†ÿ¨t…ÿ©t‚ÿªt�ÿªt�ÿ¬u‚ÿ¬v�ÿ®v€ÿ®u|ÿ®uzÿ­tzÿ­t}ÿ¬u~ÿ­t|ÿ®uzÿ­tzÿ­tzÿ­u|ÿ­t{ÿ¬t}ÿªs}ÿ¨r~ÿ§r€ÿ§s…ÿ¦r‡ÿ¤s‹ÿ¦s‹ÿ§u�ÿ§u�ÿ¨u�ÿ¨tŒÿ§t‰ÿ§tˆÿ¨t†ÿ§t…ÿ¨t†ÿ§s…ÿ§s…ÿ©s…ÿ©t…ÿ¨s…ÿ©s†ÿ©s…ÿªt„ÿªu„ÿ¬t�ÿ¬t|ÿ®sxÿ­suÿ­rrÿ®sqÿ¯sqÿ¯rnÿ°rmÿ°rkÿ°riÿ°rjÿ±rkÿ°skÿ¯qmÿ¯pnÿ®qoÿ¬qpÿ¬ppÿ­qrÿ«qsÿ«ptÿ¬psÿ«qrÿ«ptÿ¬quÿ¬quÿ«quÿ«otÿ«qrÿ¬poÿ®omÿ¯pkÿ¯pkÿ¯pjÿ­oiÿ®oiÿ­nfÿ­nfÿ®oeÿ­ndÿ®ndÿ­maÿ®m`ÿ­n_ÿ®m`ÿ¬maÿ¬mbÿ«mcÿ«ldÿ«ldÿªkdÿªkdÿªlcÿ«mdÿ­nfÿ­ohÿ¯qkÿ®oiÿ«miÿ©mmÿ©mnÿ¦ksÿ¨nyÿ§mvÿ¥jnÿ¤hmÿ£gpÿ£hsÿ¢huÿ¢i{ÿ¡iÿŸi~ÿŸhzÿ fsÿ dmÿŸciÿžbfÿ�bfÿ�dkÿ›dpÿ›crÿ™duÿ™dxÿ˜dwÿ—bvÿ—avÿ•auÿ•`vÿ“`vÿ’`wÿ’`xÿ‘`xÿ�`xÿ�_yÿŽ^zÿ�_zÿŒ_{ÿ�]zÿ�^yÿ�^yÿ�_zÿ�_{ÿŽ^zÿ�^yÿŽ^uÿ�]pÿ�[jÿ�Zdÿ�Zdÿ�[hÿ�\lÿ�]sÿ�]vÿ‘^yÿ�_yÿ�`zÿ‘`zÿ‘^xÿ“^sÿ’\kÿ“[eÿ“Zeÿ”[eÿ’Zdÿ“[eÿ“[fÿ‘[fÿ�Zeÿ�Xdÿ�Xcÿ�Xaÿ�V]ÿ�VYÿŽUWÿŽSVÿŽUWÿŽTXÿ�TYÿŒTYÿŒU\ÿžu›ÿ ušÿ¡ušÿ¡v—ÿ¢v—ÿ£w˜ÿ£v”ÿ¤v’ÿ¥v“ÿ¤v�ÿ¤uŽÿ¤tŽÿ¤sŒÿ¤s‰ÿ¥sˆÿ¦u‡ÿ¨u†ÿ©u…ÿ«u…ÿ¬v…ÿ¬vƒÿ®w‚ÿ®w�ÿ®u}ÿ®v~ÿ®x€ÿ­vÿ®u}ÿ®v}ÿ®v|ÿ®u}ÿ¯wÿ®wÿ¯v~ÿ­u~ÿ¬u€ÿ«u„ÿ©v‰ÿ¨vŽÿ§w‘ÿ¦w’ÿ¦v‘ÿ§w’ÿ¨x’ÿ¨w�ÿ©vŽÿ¨vŒÿ¨vŠÿªu‡ÿ©u‡ÿ©u†ÿ¨t…ÿ¨t…ÿ©t…ÿ©t†ÿ©u…ÿ©t†ÿªu‡ÿ«u†ÿ«u„ÿ­uÿ®tzÿ®suÿ®stÿ°ttÿ¯ttÿ°srÿ°snÿ°skÿ±sjÿ³tjÿ°siÿ±tjÿ±skÿ°rjÿ°rjÿ°rkÿ®qmÿ­qoÿ®qpÿ­qpÿ­qqÿ­qrÿ¬qrÿ¬qtÿ¬qvÿ¬qwÿ«rvÿ¬qvÿ«qtÿ¬pqÿ­pnÿ®pnÿ®poÿ­poÿ­poÿ­pnÿ®omÿ®ojÿ®phÿ­ogÿ®neÿ®nbÿ­n`ÿ®naÿ¬ndÿ¬nfÿ¬nfÿ«meÿ«leÿ«lfÿ«ldÿ«mdÿ¬mcÿ¬ndÿ¬mfÿ®piÿ­phÿªmiÿ©mmÿ¨llÿ§mrÿ©owÿ§msÿ¥jnÿ¤hlÿ¤hmÿ£hoÿ¢huÿ¡j{ÿ jÿ jÿŸhzÿžfpÿ ekÿŸcfÿ cdÿžcfÿ�ciÿ�dnÿ›dsÿ›dvÿšewÿšdxÿ˜dwÿ•avÿ”`wÿ“bxÿ’ayÿ’awÿ’axÿ‘axÿ�`yÿ�_yÿ�`zÿŽ_{ÿ�_{ÿŽ_zÿŽ_yÿ�_xÿ�_xÿŽ_yÿ�_{ÿ�`|ÿ�_zÿŽ^uÿ�\nÿ�Zfÿ‘[fÿ‘\hÿ‘]oÿ�]uÿ�_xÿ�_yÿ�`yÿ‘_yÿ‘_wÿ’_sÿ“]kÿ’[dÿ“[dÿ’Zcÿ’[cÿ“Zaÿ’[aÿ’Yaÿ�Y^ÿ‘Y`ÿ�Ybÿ�Ybÿ�Xbÿ�V^ÿ�V[ÿ�UYÿŽUWÿŽUXÿŽTZÿ�U[ÿ�U\ÿ�U]ÿ v�ÿŸvœÿ¡u›ÿ u˜ÿ¢u–ÿ£w–ÿ£v“ÿ£u“ÿ¤v“ÿ¥v‘ÿ¥vŽÿ¥u�ÿ¤t�ÿ£tŠÿ¤s‰ÿ¥tˆÿ¥u‡ÿ¨t‰ÿªvˆÿ­x…ÿ®x‚ÿ®x‚ÿ®z…ÿ¯w€ÿ¯w~ÿ®x€ÿ¯x~ÿ¯w|ÿ®v}ÿ¯v~ÿ¯xÿ¯y€ÿ¯x~ÿ°x|ÿ¯w}ÿ®w€ÿ®w„ÿ¬x‰ÿ«x�ÿ©x�ÿ©z•ÿ¨y˜ÿ¨y™ÿ§y—ÿ¨y”ÿ©x‘ÿ©xŽÿ¨v‹ÿ©vˆÿ©vˆÿªu‡ÿªu†ÿ©u†ÿªu†ÿªu„ÿªvƒÿ«u„ÿ¬v„ÿ«uƒÿ«uƒÿ®vƒÿ­vÿ®uzÿ¯uyÿ°uvÿ¯ttÿ°tsÿ±tpÿ²tmÿ²sjÿ³ukÿ±ujÿ±ukÿ±tjÿ²sfÿ³tfÿ³sfÿ±rgÿ±rjÿ°slÿ°rlÿ¯rnÿ¯roÿ¯roÿ®rrÿ®rsÿ­ruÿ­ruÿ­rvÿ¬quÿ¬qrÿ­qqÿ­ppÿ­prÿ­rtÿ¬qwÿ¬pvÿ¬ptÿ­opÿ­nlÿ®okÿ®nhÿ­ofÿ®oeÿ­oeÿ¬nfÿ­ohÿ­ohÿ¬nfÿ­mfÿ¬meÿ«mdÿ¬mcÿ¬mcÿ«mbÿ¬meÿ¬oeÿ¬pgÿ­pjÿ¬okÿ«nlÿªnqÿ©otÿ¦kqÿ¥knÿ¥imÿ¤hjÿ£gkÿ£gqÿ¡jzÿ¡j~ÿ j}ÿ ixÿŸgqÿ¡ekÿŸceÿŸcdÿžcgÿŸdkÿženÿžeqÿœdrÿ›dsÿšcuÿ™cuÿ—btÿ•buÿ”byÿ‘axÿ’bxÿ‘awÿ‘awÿ‘`xÿ‘`xÿ�`yÿ�_|ÿ�`{ÿ�_yÿ�_zÿ�`zÿŽ`{ÿ�_{ÿ�`~ÿ�`ÿ�`ÿ�`}ÿ�^uÿ’]kÿ’\hÿ’]kÿ‘^sÿ‘_zÿ‘`|ÿ‘`|ÿ‘a|ÿ‘`zÿ’_vÿ’_rÿ“\kÿ’[eÿ”[dÿ“[dÿ”Zbÿ”Zaÿ“Z_ÿ’Z]ÿ’Y\ÿ‘WZÿ‘X^ÿ‘Ycÿ�Xbÿ�W^ÿ�W\ÿ�W\ÿ�VZÿŽVYÿŽV\ÿŽV^ÿŽV^ÿ�U_ÿ¢v›ÿ£w�ÿ¡v›ÿ¢v›ÿ¡v™ÿ£v—ÿ¥w˜ÿ¤w—ÿ£w•ÿ¤u“ÿ¥v‘ÿ¥u�ÿ¥uŽÿ¤tŒÿ¦t‹ÿ¥t‰ÿ¥u‹ÿ¦v‹ÿ¨v‹ÿ¬x‰ÿ­w„ÿ®yƒÿ¯z†ÿ°yƒÿ°x~ÿ°x}ÿ°x}ÿ°w|ÿ°x|ÿ¯xÿ¯x�ÿ±x�ÿ±x~ÿ²y|ÿ±y}ÿ±y~ÿ¯z�ÿ¯y„ÿ®y†ÿ¬z‹ÿ¬z�ÿª{•ÿ¨zšÿ¨z›ÿ©y—ÿªy“ÿ«y�ÿ«wŒÿ«wŠÿ«wŠÿ«wŠÿªv‡ÿ«v‡ÿ¬wˆÿ¬w‡ÿ¬w…ÿ®x†ÿ­wƒÿ­v€ÿ­wƒÿ­wƒÿ®w‚ÿ®vÿ¯u}ÿ°vzÿ°uyÿ±uvÿ²urÿ³vpÿ´umÿ³ukÿ³vkÿ²ukÿ³tjÿ´thÿ³tfÿ³tfÿ³thÿ³thÿ²tiÿ²tiÿ²tkÿ²tlÿ±tlÿ±tmÿ°soÿ±rpÿ¯srÿ¯suÿ¯rsÿ®qqÿ­qqÿ®qrÿ¬qtÿ­rzÿ­s|ÿ¬s|ÿ¬s{ÿ­rwÿ¬qtÿ­ppÿ­pnÿ®plÿ®pjÿ®niÿ­niÿ­oiÿ­mhÿ­mhÿ­nhÿ¬ngÿ­neÿ¬ndÿ­mcÿ¬mdÿ¬ndÿ¬neÿ­ogÿ­ohÿ®pkÿ­plÿ«nlÿ§kmÿ¦koÿ¦joÿ¥jnÿ£hkÿ£gkÿ¢gnÿ£hrÿ£ivÿ¢iuÿ¢iuÿ¡fnÿ¡ejÿ deÿ cdÿŸbgÿždhÿŸdlÿŸenÿžcmÿœcnÿ›bpÿ™bpÿ™bqÿ—arÿ–btÿ–auÿ”avÿ“_uÿ’`vÿ‘`vÿ’`xÿ�azÿ�`|ÿ�`{ÿ�_zÿ�`{ÿ�`}ÿ�`~ÿŽ`€ÿ�`€ÿ�a‚ÿ�a�ÿ�a�ÿ‘`{ÿ’]oÿ“]jÿ“^mÿ“awÿ’a}ÿ’aÿ’aÿ’a~ÿ’a{ÿ“_uÿ’_qÿ”^nÿ”\iÿ”\fÿ”\fÿ”[cÿ”Zaÿ”Z`ÿ”[_ÿ”Y[ÿ’XXÿ“X[ÿ‘Y]ÿ�X^ÿ�W]ÿ�W\ÿŽV[ÿŽV[ÿ�V\ÿŽV^ÿŽV`ÿ�W`ÿ‹V`ÿ¢w•ÿ¢xœÿ£y�ÿ£xœÿ£wšÿ£v˜ÿ£wšÿ¤yšÿ¥x™ÿ¤x—ÿ¥w“ÿ¦w‘ÿ§w�ÿ§v�ÿ¦vŒÿ§v‹ÿ¦u�ÿ§vŽÿ©xŽÿ«yŽÿ®y‰ÿ¯y†ÿ¯y†ÿ°z†ÿ±y€ÿ¯x|ÿ±x|ÿ°w|ÿ°x}ÿ¯yÿ°x€ÿ°y€ÿ±yÿ³z}ÿ²z{ÿ²z|ÿ²y{ÿ°y}ÿ°y‚ÿ¯y†ÿ®y‰ÿ¬{�ÿ«{’ÿ«{•ÿ¬{•ÿ«y’ÿ«z‘ÿ¬zŽÿ¬yŒÿ¬y‹ÿ«y‹ÿ«y‹ÿ¬x‰ÿ¬x‰ÿ­xˆÿ­yˆÿ¯zˆÿ®x„ÿ®w�ÿ®v�ÿ®x„ÿ®x„ÿ®w„ÿ¯xƒÿ¯w€ÿ°v|ÿ±vzÿ²uvÿ²usÿ³voÿ´wmÿ³vkÿ³vkÿ³ujÿ³uiÿ³uiÿ´ujÿ³ujÿ³vjÿ³ujÿ´ujÿ´ukÿ³uiÿ³uhÿ²tiÿ²ukÿ²tlÿ²soÿ±srÿ±rqÿ°rpÿ¯rqÿ®rtÿ®syÿ­s}ÿ­tÿ¬t~ÿ­s|ÿ­rzÿ¬qxÿ¬qtÿ­prÿ­pqÿ­opÿ­olÿ®njÿ­ojÿ­oiÿ¬oiÿ­oiÿ­nhÿ­ogÿ­nfÿ¬mfÿ¬lfÿ«lfÿ¬meÿ¬nfÿ­oiÿ®qkÿ¯qkÿ¬nhÿ©khÿ§klÿ§lpÿ§lpÿ¤ikÿ¢gkÿ£gkÿ¢gmÿ¢gnÿ¢gnÿ¢gmÿ¡fkÿ¡ehÿ deÿ ddÿŸcfÿždiÿždiÿžckÿ�cjÿœbkÿšbmÿšblÿ™bkÿ˜alÿ–alÿ–aoÿ•`rÿ“_rÿ“`sÿ’`tÿ‘`wÿ‘azÿ‘a{ÿ�`{ÿ�`zÿ�a}ÿ�a€ÿ�a�ÿ�b�ÿ�a�ÿ�a‚ÿŽb„ÿ�b…ÿ‘aÿ’^qÿ“]mÿ“^pÿ“`wÿ’a}ÿ“c€ÿ“c‚ÿ”b|ÿ“`sÿ“`rÿ“_qÿ”_qÿ”^oÿ”^mÿ”]iÿ”[cÿ”\aÿ•[`ÿ”[_ÿ”YZÿ“XYÿ“XZÿ’X\ÿ‘X]ÿ�W]ÿ�W]ÿ�W\ÿŽV\ÿŽW_ÿŽWaÿ�Wdÿ�WeÿŒVcÿ£v�ÿ£x˜ÿ¤xœÿ¤xšÿ£x˜ÿ£w˜ÿ¢wšÿ£y›ÿ¤y�ÿ¥z�ÿ¥xšÿ¦y”ÿ¨x‘ÿ©yŽÿ¨x�ÿ©xŽÿ¨wŽÿ¨y‘ÿ©y’ÿ«z“ÿ®|‘ÿ¯{Œÿ¯{ˆÿ°{‡ÿ²{„ÿ°y~ÿ²y}ÿ°x~ÿ¯xÿ¯yÿ±x~ÿ°y~ÿ²zÿ²z}ÿ²z{ÿ²yzÿ³yzÿ²z|ÿ±z�ÿ±z„ÿ°{†ÿ®z‰ÿ®|�ÿ®}�ÿ®}‘ÿ®|‘ÿ­{�ÿ­{�ÿ®{�ÿ®{Žÿ®{Žÿ®{Žÿ®zŒÿ®yŠÿ®yŠÿ¯zŠÿ¯z‰ÿ¯y†ÿ¯x„ÿ¯x„ÿ¯y„ÿ¯y†ÿ¯y‡ÿ®x„ÿ¯x‚ÿ¯w€ÿ±w}ÿ±vzÿ±wwÿ²vuÿ³vqÿ³wnÿ´wlÿ´vlÿ³vkÿ´vlÿµvlÿ´vmÿ´vmÿ´wmÿ´wlÿ´vlÿ´viÿ´vhÿ´uhÿ´vkÿ³ulÿ³upÿ´vqÿ²toÿ±soÿ²srÿ¯ssÿ¯tvÿ¯u{ÿ®u}ÿ­t}ÿ­t}ÿ­t}ÿ­s{ÿ­syÿ­ryÿ¬qvÿ¬quÿ¬prÿ­onÿ­omÿ­okÿ®okÿ­ojÿ­ojÿ­niÿ¬nhÿ¬nhÿ«miÿ¬mhÿ¬mhÿ­oiÿ­pjÿ­ojÿ¬ngÿ«mgÿªkgÿ¨liÿ¨mmÿ§lpÿ¥ilÿ¢hkÿ¢glÿ¢gkÿ¢fjÿ£gjÿ¢ghÿ¢fiÿ¢fgÿ¡eeÿ¡eeÿ¡egÿ diÿžejÿžckÿœcjÿ›clÿ›bkÿ›ajÿ™`iÿ™aiÿ—`jÿ–`lÿ–aoÿ•arÿ”`sÿ“`uÿ’awÿ’ayÿ‘a{ÿ’a|ÿ‘a|ÿ�b~ÿ�a‚ÿ�bƒÿ�b€ÿ�bƒÿŽb…ÿŽb†ÿ�b‡ÿ�a�ÿ�_uÿ“_pÿ‘_tÿ‘azÿ’a}ÿ“bÿ”b~ÿ•awÿ”_mÿ”`pÿ“_rÿ“`sÿ”`vÿ”`tÿ”_nÿ”\eÿ•\dÿ•[cÿ”[_ÿ”Y]ÿ”Y\ÿ“X\ÿ“X]ÿ’X]ÿ�W_ÿ�X]ÿŽX^ÿŽX_ÿŽXaÿ�Xdÿ�Ygÿ�Wgÿ�Wgÿ¦u‹ÿ¦v‘ÿ¦x–ÿ¥x—ÿ¤x—ÿ¥x˜ÿ£x™ÿ£x›ÿ¤yžÿ¥z¢ÿ¦{Ÿÿ¦y˜ÿ©y•ÿªy“ÿ«z�ÿ«y‘ÿ«{“ÿª{•ÿ«|—ÿ¬}˜ÿ­}—ÿ¯~”ÿ°‘ÿ±~�ÿ²}‡ÿ²z‚ÿ±y€ÿ±zƒÿ°zƒÿ°y‚ÿ°z~ÿ³z|ÿ²z|ÿ³z}ÿ²z|ÿ³y{ÿ²z{ÿ´z|ÿ³yÿ³{ƒÿ²|†ÿ±|‰ÿ±}‹ÿ°|�ÿ±~Žÿ°}�ÿ°}�ÿ°|Žÿ¯|�ÿ®|�ÿ®|‘ÿ¯|‘ÿ¯|‘ÿ¯|‘ÿ¯|Žÿ¯{�ÿ°zŠÿ¯z‡ÿ¯y‡ÿ°z‡ÿ¯zˆÿ±{Šÿ±zŠÿ±z‰ÿ°z…ÿ±x‚ÿ°w€ÿ±w}ÿ²x|ÿ²xzÿ³wvÿ³wrÿ´woÿ´vnÿ´vmÿ´wnÿµwoÿµwoÿµwoÿµwoÿµwnÿ´vlÿµwkÿµviÿµvjÿ´ulÿµuoÿµurÿ´urÿµusÿ´tsÿ´tsÿ²utÿ°tuÿ±vzÿ¯u}ÿ¯t~ÿ­t}ÿ®u~ÿ­u~ÿ¬tÿ­t€ÿ¬tÿ¬s|ÿ¬rzÿ®pvÿ®prÿ­ppÿ®onÿ­pnÿ­olÿ­omÿ­nlÿ¬nmÿ¬nlÿ¬nlÿ¬onÿ­ooÿ­ooÿ­olÿ«niÿ«liÿ«liÿªmjÿ¨llÿ§koÿ¤inÿ£gmÿ¢hlÿ¢hlÿ¢gkÿ¢giÿ£fgÿ¤ghÿ¢ffÿ¡ddÿ¢efÿ¡fiÿ¡ekÿ dlÿŸdlÿždlÿœclÿ›clÿ›blÿšalÿ™alÿ™bmÿ—aoÿ—arÿ•asÿ”`rÿ”atÿ“avÿ“ayÿ’a{ÿ’a|ÿ’a{ÿ’a}ÿ‘aÿ‘a~ÿ�a}ÿŽb€ÿ�b†ÿ�bˆÿ�b‡ÿ‘a‚ÿ‘`zÿ’`xÿ’azÿ“b}ÿ’a}ÿ“b}ÿ–`xÿ•`sÿ•`pÿ•`rÿ”`rÿ”awÿ’ayÿ“ayÿ”_qÿ•]kÿ”\hÿ”\dÿ”Zaÿ”[_ÿ”Z_ÿ”Z^ÿ“Y`ÿ’Y`ÿ‘Y`ÿ‘X`ÿ�X_ÿ�X`ÿŽXbÿŽZfÿ�XiÿŒXjÿ�Xhÿ¨v‰ÿ§uŒÿ§w’ÿ¦x•ÿ¦y–ÿ¦y—ÿ¥y–ÿ¥y™ÿ¤zœÿ¥{¡ÿ¦{ ÿ¦{›ÿ¨{˜ÿ©{•ÿª|“ÿ«|•ÿª|•ÿ«}˜ÿ«~�ÿ«~Ÿÿ«~žÿ­šÿ®–ÿ±‘ÿ°}Šÿ°{‡ÿ°|‡ÿ°|ˆÿ¯{‡ÿ°z…ÿ°z‚ÿ±y~ÿ³z}ÿ³{}ÿ³{~ÿ²z|ÿ³z}ÿ²{~ÿµ|€ÿ³{�ÿ³|…ÿ²|ˆÿ²}�ÿ²~�ÿ±}�ÿ³~�ÿ³}Œÿ²}Œÿ±~Œÿ°�ÿ°~’ÿ¯}”ÿ®~”ÿ¯~•ÿ°}–ÿ±~’ÿ°}�ÿ±|�ÿ°|Žÿ¯{Žÿ±{�ÿ±zŒÿ±zŠÿ°{Šÿ±zˆÿ±z‡ÿ±y„ÿ²zƒÿ²y�ÿ³y~ÿ²xzÿ´wvÿ´wtÿ´xtÿµysÿµxrÿ¶wrÿµxrÿ¶yrÿµxqÿµwoÿµwmÿµvmÿµvmÿµvmÿµwnÿµvrÿ´wtÿµvvÿ³vvÿ³vvÿ³uuÿ²tsÿ²uuÿ±uyÿ±u|ÿ°u~ÿ¯u€ÿ¯v‚ÿ®uƒÿ­w…ÿ¬v‡ÿ¬vŠÿ«uˆÿ«t„ÿ«sÿ«rzÿ¬rwÿ¬quÿ¬ptÿ¬qsÿ­pqÿ­oqÿ¬pqÿ«oqÿ¬psÿ«osÿ«puÿ«puÿ«ppÿªnmÿªmlÿ©mkÿ¨mkÿ©lnÿ§koÿ¤ioÿ¤jqÿ¤joÿ¢hlÿ¢gkÿ¢fiÿ¢ghÿ¢ghÿ¢efÿ¢efÿ¡fhÿ¡fkÿ¡flÿ elÿŸdlÿ�dmÿœcmÿ›coÿšcoÿšcoÿ™boÿ˜brÿ–bsÿ•atÿ•asÿ•`qÿ•arÿ“`tÿ’auÿ’axÿ‘ayÿ‘`wÿ‘axÿ’ayÿ�`wÿ�_wÿ�bÿ�b„ÿŽbƒÿ�a€ÿ‘a€ÿ‘a~ÿ’a~ÿ’b~ÿ’b}ÿ“b~ÿ”azÿ•auÿ–`sÿ•`qÿ”`sÿ”`yÿ”c~ÿ”bÿ”a{ÿ”_tÿ”_pÿ”^nÿ•^kÿ”\gÿ”\fÿ”[dÿ’[bÿ’[cÿ’Zaÿ�Yaÿ�Ybÿ�Ybÿ�Ybÿ�Ybÿ�Yeÿ�Yhÿ‹XjÿŒXjÿªv‡ÿ©v‰ÿ©x�ÿ§y‘ÿ§z•ÿ§z–ÿ¥y–ÿ¦{˜ÿ¦{›ÿ¥{œÿ¥{�ÿ¦zžÿ§{›ÿ§z˜ÿª|–ÿ«|•ÿ¬}–ÿ¬~˜ÿ¬ ÿª�£ÿª€£ÿ«�£ÿ«�¡ÿ®˜ÿ®}Žÿ°}Œÿ¯}�ÿ¯}�ÿ¯}Œÿ±|ˆÿ±{…ÿ²|ƒÿ²{ÿ³{~ÿ²{}ÿ³{~ÿ³{ÿ³{€ÿµ|�ÿµ}€ÿµ}�ÿ´}…ÿ´~�ÿ³�ÿ³�ÿ³~‹ÿ³~‰ÿ³~‡ÿ´}‡ÿ²~Šÿ²~Žÿ²“ÿ°•ÿ°~’ÿ²•ÿ±€•ÿ±’ÿ°~�ÿ°}�ÿ°}‘ÿ°|‘ÿ¯|�ÿ°|�ÿ²|Œÿ²|‹ÿ²|Šÿ²z‰ÿ²{ˆÿ±{‡ÿ³{„ÿ³x€ÿ²x{ÿ´xxÿ´yvÿ´xtÿµxsÿµyrÿ¶yrÿ¶ysÿ¶xrÿµxoÿµxpÿ¶xqÿ¶xpÿ¶xrÿ·ysÿµwuÿµwvÿ´wwÿ´xxÿ´wxÿµwwÿ´usÿ³vrÿ´wtÿ²vxÿ±v}ÿ±v~ÿ°vÿ¯w„ÿ®wˆÿ­x‹ÿ«v‹ÿ¬wŒÿ«t‰ÿªt‡ÿ¬t‚ÿ¬r~ÿ¬r{ÿ¬r|ÿ¬r}ÿªr|ÿ«rzÿ¬rzÿ«rzÿ¬q{ÿ¬q{ÿ«qzÿ«qzÿ¬pvÿªpqÿªopÿ«nqÿ©opÿ¨mpÿ§lqÿ¦lpÿ¤kqÿ¤jpÿ¢hmÿ¡hlÿ glÿ¡gjÿ¢gjÿ¢fiÿ eiÿ¡fkÿ¡flÿ fmÿŸgoÿŸfnÿženÿ�doÿœdqÿ›dqÿ™crÿ™dtÿ—cuÿ•bvÿ–buÿ•arÿ–aqÿ•`qÿ”`rÿ“`rÿ’`tÿ’`uÿ‘_sÿ‘`tÿ’_rÿ’_rÿ�_tÿ‘b|ÿ�cÿ�a~ÿ‘a}ÿ‘bÿ’b€ÿ’bÿ‘b~ÿ“b}ÿ“b~ÿ•bzÿ–bxÿ–avÿ•auÿ•ayÿ”cÿ•dƒÿ”c�ÿ”b}ÿ•ayÿ•awÿ•avÿ•_rÿ”_pÿ•^nÿ”\hÿ‘[eÿ’[dÿ’[dÿ’Zdÿ�Zdÿ‘Zdÿ�Zcÿ�Zcÿ�YdÿŽYgÿ�Yjÿ�Ylÿ©v‡ÿªw‡ÿ©x�ÿ¨y�ÿ¨y“ÿ§z•ÿ§z–ÿ¦z–ÿ¦{˜ÿ¦{™ÿ¦zœÿ¥{žÿ¦z�ÿ¦z›ÿ©|šÿ©|˜ÿ¬~—ÿ®~™ÿ®�žÿ­�¢ÿ¬‚¥ÿ¬‚§ÿ¬�§ÿ­€Ÿÿ®~—ÿ®~•ÿ®€›ÿ°€šÿ²“ÿ²~‰ÿ³|„ÿ³|ƒÿ´|‚ÿ´}€ÿ´|ÿ´}ÿ³|~ÿµ}ÿ¶}~ÿµ|ÿµ~€ÿµ~„ÿµ€Œÿ¶��ÿµ€Žÿ´‹ÿµ€‹ÿ´ˆÿ´}†ÿµ~†ÿ´‡ÿ´Œÿ´€�ÿ³~�ÿ³‘ÿ³“ÿ´�“ÿ³‘ÿ³�ÿ³~�ÿ±}�ÿ°|‘ÿ¯|�ÿ°}�ÿ±|�ÿ±}�ÿ±}�ÿ²}�ÿ²|Žÿ³|Œÿ³z†ÿ´z�ÿ³x{ÿ´yyÿ³xwÿµxuÿµzuÿ¶zvÿ¶yuÿ¶xtÿ¶ytÿ¶xtÿµwtÿ¶xuÿµxvÿ¶ywÿ¶ywÿµxxÿ´xyÿµyzÿµwzÿµwwÿµvuÿµwuÿ³vtÿ³vvÿ²wzÿ²v{ÿ²v}ÿ±wƒÿ¯xˆÿ¯xŒÿ­xŽÿ­w‹ÿ­v‰ÿ¬uˆÿ«t„ÿ¬s€ÿ¬sÿ¬s€ÿªt�ÿ«t‚ÿªs�ÿ«s‚ÿ¬s�ÿ«s�ÿ«s‚ÿ¬s‚ÿ«sÿ¬r{ÿ«qvÿ«qvÿ«pvÿªotÿ¨otÿ§mqÿ§lrÿ¥krÿ¥lrÿ£iqÿ¡hrÿ¢isÿ hqÿ¡hpÿ¢gnÿ¡fnÿ¡fmÿ¡flÿ fnÿ gqÿŸfrÿŸfqÿ�dpÿ�dqÿšcqÿšcsÿ™cuÿ—cvÿ—cxÿ—cwÿ•btÿ•arÿ•`qÿ”`qÿ”`rÿ“`qÿ“`sÿ’_sÿ’_sÿ’^pÿ’^oÿ“`qÿ‘`uÿ�ayÿ‘azÿ‘a}ÿ‘b�ÿ’cƒÿ“c‚ÿ’bÿ“c€ÿ“c€ÿ”b~ÿ•b|ÿ–a{ÿ–b{ÿ•cÿ•e†ÿ•d„ÿ”c€ÿ”b~ÿ•b}ÿ•c|ÿ•bzÿ•`xÿ•`wÿ•_sÿ“]mÿ’]jÿ‘[iÿ‘[iÿ‘[hÿ‘[hÿ�Ydÿ’Ydÿ‘Zdÿ�Ydÿ�ZfÿŽYiÿ�Ykÿ¨y�ÿ©w‰ÿ¨w‹ÿ¨xŽÿ§y’ÿ§y•ÿ¦y•ÿ¦y–ÿ§z—ÿ¦z˜ÿ¦{šÿ¦{Ÿÿ¥{žÿ¥z�ÿ§{�ÿ§|›ÿª|˜ÿ¬~šÿ­€œÿ­� ÿ¬€¢ÿ«�£ÿ«�¦ÿ«�£ÿ¬›ÿ®™ÿ¯€›ÿ¯‚žÿ°‚œÿ²€”ÿ³~‰ÿ´}†ÿµ~…ÿ¶~ƒÿµ~�ÿ¶}ÿ¶}}ÿ¶~|ÿ¶}|ÿ·}}ÿµ}~ÿµ}�ÿµˆÿµ€Œÿµ€Œÿµ€Œÿ¶�Œÿ·�Šÿ·‡ÿ¶ƒÿ·„ÿ·ˆÿ¶€Šÿµ€‹ÿµŒÿ´€�ÿ´€�ÿµ�’ÿ´Žÿ´~‹ÿ´~‹ÿ²}�ÿ²}“ÿ°~“ÿ¯}“ÿ¯~”ÿ°˜ÿ°˜ÿ°~•ÿ²~’ÿ²}Žÿ³{…ÿ³z€ÿ´y~ÿ³y|ÿ³y{ÿ´y{ÿµzzÿµyzÿµyzÿ´yzÿµyzÿµz{ÿµz|ÿµz|ÿµz|ÿµyzÿµyyÿµy{ÿµz|ÿµy|ÿµwxÿµwwÿµwvÿµwwÿ´xxÿ³wyÿ²x|ÿ²xÿ²xƒÿ±x‡ÿ°yŒÿ°x‹ÿ®w‰ÿ®wˆÿ­v„ÿ®u�ÿ­t€ÿ¬t€ÿ«tƒÿ«t„ÿªtƒÿ«sƒÿªs„ÿ«t…ÿ«t…ÿ¬t„ÿ«t‚ÿ«s€ÿ«r|ÿ¬qxÿ¬rxÿ¬qyÿªpxÿ©ovÿ§ntÿ§mtÿ¦mtÿ¥ltÿ¤ktÿ¢juÿ¡juÿŸhuÿ iuÿ iuÿŸgrÿŸgpÿ foÿ gqÿŸgtÿŸgvÿŸgtÿžfsÿ�frÿ›erÿšcsÿ™cvÿ˜dxÿ—d{ÿ—cyÿ–cvÿ”btÿ•asÿ”`qÿ”`oÿ•`pÿ”`qÿ’`sÿ‘`tÿ‘`sÿ‘_qÿ’`qÿ“`sÿ‘`vÿ‘`zÿ‘a~ÿ’cƒÿ’c„ÿ’cƒÿ’b‚ÿ’c…ÿ”d„ÿ”d€ÿ”d€ÿ•d�ÿ•d‚ÿ–e„ÿ•e‡ÿ”e„ÿ•d€ÿ•cÿ•c€ÿ”c€ÿ”b}ÿ”a{ÿ”ayÿ”`xÿ”`uÿ‘]qÿ‘]oÿ‘]nÿ�\mÿ’\jÿ’Zfÿ‘Zdÿ‘Zeÿ‘[gÿ�Zhÿ�[kÿŽ[lÿ¨{—ÿ©z‘ÿªx‹ÿ©yŒÿ©y�ÿ¨y’ÿ§y•ÿ¦y•ÿ¥z—ÿ¥z˜ÿ¦{›ÿ¨| ÿ¦}Ÿÿ¤{Ÿÿ¤zžÿ¦}œÿ¨|™ÿª|™ÿ¬€œÿ¬�œÿ®��ÿ¬€Ÿÿ¬�¡ÿ«€ ÿ«œÿ¬~™ÿ­€™ÿ¯‚Ÿÿ°ƒ¡ÿ±ƒžÿ²€’ÿ³Œÿ´€‰ÿµ‡ÿ´ƒÿ¶~‚ÿ·~€ÿµ}}ÿ·}}ÿ·}~ÿµ}}ÿµ}ÿ·…ÿ·€Šÿ·‚�ÿ¹‚�ÿ¸ƒŽÿ¹ƒ�ÿ¸‚‹ÿ¸€†ÿ¸€†ÿ¸€ˆÿ·€ˆÿ¶€ˆÿ·�Œÿ¶�Žÿ¶‚�ÿ¶ƒ”ÿµ�Žÿ¶†ÿ¶ˆÿ´�ÿ³€‘ÿ²€“ÿ²‘ÿ°~”ÿ°€›ÿ±ƒ ÿ¯�žÿ®€›ÿ°–ÿ±|‹ÿ²{‡ÿ²{„ÿ²z‚ÿ³z‚ÿ³z€ÿ³y�ÿ³z‚ÿ´{‚ÿ´z‚ÿµ{ƒÿ´{„ÿ´|„ÿ´{…ÿ´zƒÿ´{�ÿµ{€ÿµz€ÿµ{€ÿµ{ÿ¶y|ÿ´x{ÿ´xyÿ´wyÿµwxÿ³xzÿ³xÿ²y‚ÿ±y„ÿ±yˆÿ±z‹ÿ°y‹ÿ°xˆÿ°v…ÿ°vÿ°u{ÿ¯t{ÿ¬s}ÿ¬t‚ÿ«u…ÿ«u„ÿ¬u„ÿ«s…ÿ«t…ÿ«t‚ÿ¬t€ÿ«s€ÿ«tÿ¬qzÿ«qxÿ«qyÿ«pxÿªpwÿ§ntÿ¨ouÿ¦nuÿ¦ltÿ¥ltÿ¤ktÿ¤jtÿ¡isÿ ivÿŸjwÿ jyÿŸhwÿŸhtÿŸgsÿŸgrÿžhuÿžhvÿžguÿžgtÿžftÿœerÿšerÿ™etÿ™dwÿ—dzÿ˜e{ÿ—dxÿ•cvÿ–btÿ•asÿ–`rÿ”asÿ“`sÿ’`vÿ’byÿ’c|ÿ’awÿ‘`rÿ“asÿ“awÿ’b{ÿ”d�ÿ“dƒÿ“eƒÿ“dƒÿ’c‚ÿ“e‡ÿ•e„ÿ•e�ÿ–f„ÿ–e†ÿ•e„ÿ•e„ÿ–d…ÿ•e…ÿ–eƒÿ•d�ÿ”d�ÿ”c€ÿ–dÿ”b{ÿ”axÿ”`yÿ’`yÿ’_wÿ’^sÿ‘]qÿ‘^pÿ“\mÿ’[hÿ‘[gÿ’\hÿ’\gÿ�[gÿ�\iÿ�[jÿ§|žÿ¨}žÿ¨{‘ÿ©yŒÿ©yŽÿ©y’ÿ¨z•ÿ¦z—ÿ¦z™ÿ¦{šÿ¦z›ÿ¦{žÿ¦| ÿ¦| ÿ¥| ÿ¦}žÿ§}œÿ©|™ÿª~šÿ¬�›ÿ®�›ÿ¯�šÿ¯�›ÿ¬€šÿ¬~šÿ¬~™ÿ®˜ÿ®�œÿ°ƒŸÿ°„¡ÿ±ƒ�ÿ²�”ÿ³€�ÿ´Œÿ´Šÿµ€†ÿµ„ÿ¶~‚ÿ·~ÿµ}~ÿ·ÿ¸ÿ¸€…ÿ¸‚‹ÿ¹„�ÿ¹„‘ÿ¹„’ÿ¹ƒ‘ÿ¹ƒŽÿ¸‚Šÿ¹‚Šÿ¹‚Šÿ¸�‰ÿ¸�Šÿ¸‚Œÿ¸‚�ÿ·‚‘ÿ·„•ÿ¸ƒ’ÿ·€†ÿ·„ÿ¶‡ÿµ€Œÿµ�‘ÿ´�’ÿ³€•ÿ²�œÿ°‚ ÿ°‚Ÿÿ°��ÿ°˜ÿ²~�ÿ³|Œÿ²{‡ÿ³z…ÿ²{†ÿ³z…ÿ³z†ÿ²|ˆÿ³|‹ÿ³|‹ÿ²{Šÿ³|‹ÿ³|Œÿ³|Œÿ³|‹ÿ³{ˆÿ³|‡ÿµ{‡ÿµ|†ÿµ{ƒÿµz�ÿ¶z€ÿµyÿ´xzÿµxzÿ³xzÿ³y€ÿ³z„ÿ²x†ÿ±zŠÿ²{‹ÿ±z‰ÿ°y‡ÿ±xƒÿ±u}ÿ±txÿ°swÿ¯t{ÿ®t~ÿ«t‚ÿ«u†ÿ¬u…ÿ«u…ÿ¬u„ÿ«t~ÿ¬s}ÿ­s}ÿ­r|ÿ«qxÿ«qyÿ¬r{ÿ«pvÿ©orÿ¨npÿ¨nrÿ¨mrÿ§msÿ§luÿ¦luÿ¤krÿ£jqÿ¡juÿ¡jxÿ iwÿ jwÿŸhtÿ hrÿ gqÿŸhtÿžhuÿžfsÿžgqÿžfqÿœeqÿ›dqÿ›esÿševÿ™eyÿ˜ezÿ˜ezÿ—dwÿ–cuÿ•btÿ”atÿ“avÿ”bxÿ”b{ÿ’c~ÿ“cÿ’byÿ’auÿ“bwÿ“czÿ”dÿ”d‚ÿ”d‚ÿ”d‚ÿ”d€ÿ•c�ÿ–d„ÿ•d‚ÿ–e�ÿ—f„ÿ—f„ÿ•e„ÿ–e†ÿ–e†ÿ•e†ÿ–d†ÿ•e…ÿ•e…ÿ–d„ÿ”c~ÿ•axÿ•`vÿ“awÿ“ayÿ“_xÿ“^rÿ’]oÿ“]pÿ’^mÿ’\kÿ’[iÿ“\iÿ‘\fÿ‘[eÿ’\hÿ�Zeÿ¨} ÿ¨~¤ÿ©}žÿªz‘ÿ©z�ÿ©z’ÿ¨{•ÿ§{˜ÿ¦{™ÿ¦|œÿ¥|žÿ¥|žÿ§|Ÿÿ¦}�ÿ¦}žÿ§}žÿ§}œÿª|™ÿª~™ÿ«~™ÿ­~–ÿ¯€–ÿ°€”ÿ±€’ÿ°€’ÿ¯€•ÿ¯€•ÿ°�™ÿ¯‚�ÿ°„¡ÿ²„¡ÿ²‚˜ÿ³�”ÿ³�“ÿµ‚�ÿ¶‚‹ÿ·‚Šÿ·�†ÿº�„ÿº�‚ÿº�€ÿº‚�ÿ»ƒ„ÿºƒ‹ÿ¹„�ÿ¹…”ÿ¹†–ÿ¹…“ÿº†’ÿº…�ÿº„Žÿ¹„Œÿ¹‚‹ÿ¹ƒŠÿºƒ‹ÿ¹ƒŒÿ¹ƒ�ÿ¹…”ÿ·„•ÿ¹‚‹ÿ¹€†ÿ¹€…ÿ·€‡ÿ·�Šÿ¶�Žÿµ�’ÿ´ƒšÿ³„Ÿÿ²ƒŸÿ²‚�ÿ²€šÿ²’ÿ³}Žÿ²}Œÿ±|‰ÿ³|‰ÿ³|‰ÿ³|‰ÿ²|Œÿ³}Žÿ²}Žÿ²|Œÿ³|Žÿ³}�ÿ³}�ÿ²}�ÿ³|Žÿ³{Šÿ´|‰ÿ´{†ÿ´z†ÿ´{†ÿ´{…ÿ¶z€ÿµy~ÿµz~ÿ´y~ÿ´y‚ÿ³zˆÿ²{‹ÿ³{‹ÿ²z‡ÿ²y…ÿ²zƒÿ²xÿ±u{ÿ±vzÿ±uyÿ°tyÿ¯u}ÿ­u€ÿ¬u…ÿ¬u†ÿ¬u„ÿ­tÿ­s{ÿ­rxÿ¬ryÿ¬qxÿ«qxÿ«q{ÿ«r|ÿªpvÿ©nqÿ©opÿ¨npÿ¨nrÿ§msÿ§mrÿ§nsÿ¥mpÿ¥jrÿ¡kvÿ¡iuÿ isÿ itÿ htÿ goÿ gnÿ gqÿŸgtÿžfpÿžfoÿžfoÿ�eoÿšcnÿ™cpÿšeuÿ›gyÿ™fzÿ™exÿšdvÿ˜bsÿ–btÿ”auÿ”byÿ”c{ÿ“c}ÿ“cÿ“cÿ’a{ÿ’bxÿ“bzÿ”d€ÿ•e‚ÿ”d„ÿ•e†ÿ•e…ÿ•eƒÿ•d�ÿ–d‚ÿ–d�ÿ–e�ÿ–f‚ÿ–e‚ÿ–f‚ÿ•e…ÿ“e‰ÿ“f�ÿ”fŒÿ“dˆÿ”e„ÿ•d�ÿ•c{ÿ–auÿ•atÿ”`tÿ”`tÿ•`tÿ”^oÿ“^mÿ’^pÿ’]pÿ“]nÿ“]lÿ’\iÿ‘[fÿ’[gÿ‘[eÿ�Ycÿ¦{œÿ§¤ÿ©€©ÿ©~Ÿÿª}•ÿ«|“ÿ«|”ÿ©|˜ÿ©}œÿ§}žÿ¦~¢ÿ§~£ÿ¦| ÿ§}Ÿÿ§}žÿ§}�ÿ¦|›ÿ©}šÿ«}˜ÿ«~—ÿ­~•ÿ­“ÿ°€“ÿ±€’ÿ²�‘ÿ²‚’ÿ³�‘ÿ²‚•ÿ±ƒ›ÿ±ƒžÿ²ƒ�ÿ³„šÿ³„˜ÿ´„–ÿµƒ’ÿ·ƒ�ÿ¹„Œÿ¹ƒˆÿ»‚…ÿ¼ƒ„ÿ»‚‚ÿº‚�ÿ»ƒ„ÿº„‰ÿ¹„Œÿº…�ÿº†”ÿ¸†“ÿ»†”ÿº…“ÿº†’ÿ»…�ÿ»„Œÿº„ˆÿ»ƒ‡ÿ»ƒˆÿºƒ‹ÿº„‘ÿº†—ÿ¹…‘ÿºƒˆÿ»‚†ÿ¹�…ÿ¸�…ÿ¸‚Šÿ·�Žÿ¶ƒ•ÿµ„�ÿ³„žÿ´‚�ÿ´�™ÿ³€‘ÿ´Žÿ´�ÿ²~Œÿ²}Œÿ³|Šÿ²|Šÿ²}�ÿ±|�ÿ±}�ÿ³}Œÿ³|�ÿ²}�ÿ±~’ÿ±}”ÿ²~‘ÿ²|�ÿ²{Šÿ³|ˆÿ²|Šÿ³}Œÿ´|‡ÿµz‚ÿµz€ÿµz€ÿ´y�ÿ´z„ÿ³z‡ÿ´{Œÿ´|Œÿ³z„ÿ³x€ÿ²w}ÿ²w{ÿ±wzÿ±v|ÿ±w|ÿ°v|ÿ°u~ÿ¯v€ÿ­vƒÿ­v…ÿ®t‚ÿ®t|ÿ®rwÿ­qvÿ¬qvÿ¬qvÿ«qyÿªpxÿªqxÿªotÿ©nrÿ©orÿ©nrÿ¨nrÿ¨nsÿ¨msÿ§mqÿ§nqÿ¦mvÿ¤lvÿ itÿ¢hrÿ hrÿŸiqÿ¡gpÿ foÿžgqÿžgqÿŸgoÿ�emÿ�enÿœdnÿœdnÿ™dpÿšetÿšfvÿ™evÿ™dvÿ™evÿ™crÿ˜csÿ—cuÿ–cyÿ•d}ÿ”d~ÿ“cÿ“c€ÿ“c~ÿ“c|ÿ“d|ÿ”d�ÿ”e„ÿ•f‡ÿ•f‡ÿ•f†ÿ—f†ÿ–f‚ÿ–e‚ÿ–fƒÿ—eƒÿ•e‚ÿ•dÿ“d}ÿ’d�ÿ“fŠÿ’f�ÿ’f�ÿ”eˆÿ“c€ÿ•b}ÿ—avÿ–`rÿ–`oÿ•_oÿ”^mÿ”^lÿ”]kÿ“^lÿ“]nÿ“]pÿ“]nÿ“]jÿ’\gÿ‘Zeÿ�Ybÿ’Yaÿ’Y`ÿ§|›ÿ¥¨ÿ¦‚²ÿ¨‚­ÿ©~žÿ¬}•ÿ¬}—ÿ«~™ÿ©~œÿ¨}Ÿÿ¨£ÿ¨¥ÿ§~¤ÿ¨~£ÿ§} ÿ§|žÿ§}œÿ¨}›ÿª}™ÿ¬}˜ÿ­~–ÿ®“ÿ¯“ÿ°’ÿ±€“ÿ³‚”ÿ´‚’ÿµƒ‘ÿ´ƒ”ÿ³„˜ÿ³„šÿ´„œÿ´…šÿ¶„™ÿ¶ƒ’ÿ¶‚‹ÿ·‚‹ÿ¹ƒ‹ÿºƒ‡ÿ»ƒ†ÿ»ƒ…ÿ»ƒ„ÿºƒ†ÿ¼„ˆÿ»…Šÿº…Œÿ»†�ÿ»†’ÿº‡•ÿ»‡˜ÿ¼‡—ÿ»†”ÿ¼†‘ÿ»…�ÿ¼„ˆÿ½ƒ‰ÿ¼ƒ‹ÿ»…‘ÿ»†•ÿ»†•ÿ»ƒŠÿ¼‚†ÿ»‚„ÿ»‚…ÿ»ƒ‰ÿ¹‚‹ÿ¸ƒ�ÿ·„˜ÿ¶…Ÿÿµƒœÿ¶‚˜ÿµ�’ÿµ€Žÿµ�ÿµŒÿ´~Šÿ³}‰ÿ³}‹ÿ²}Žÿ±}�ÿ±}�ÿ±|Žÿ³~Žÿ³~’ÿ²~”ÿ²~–ÿ³•ÿ³}�ÿ³|Œÿ²|Œÿ³}�ÿ³}�ÿ³}‹ÿµ{ƒÿ¶{�ÿ¶z€ÿµz�ÿµz‚ÿµ{†ÿ´|‹ÿ´{‰ÿ´y€ÿ´x}ÿ³w{ÿ´xzÿ²w{ÿ²w€ÿ²v€ÿ±v~ÿ°uÿ¯v�ÿ°v‚ÿ¯uÿ®t}ÿ¯tzÿ®rvÿ­rvÿ¬rwÿ¬rwÿ¬qwÿªqwÿªouÿªotÿªorÿ©orÿ©osÿ©osÿ¨nrÿ¨nqÿ©nrÿ¨msÿ¦mtÿ¥krÿ£iqÿ£ioÿ¢hoÿ¢hpÿ¡hpÿ¡hrÿŸgrÿžgqÿžfoÿ�foÿœeoÿœdoÿœdoÿšerÿ›etÿ›euÿ˜duÿ˜dvÿ˜dvÿ˜crÿ˜crÿ˜dtÿ–cwÿ–e|ÿ•e€ÿ“d‚ÿ“dƒÿ“d…ÿ”eƒÿ“d�ÿ”e…ÿ–fˆÿ•fˆÿ–g‡ÿ—f…ÿ—e†ÿ–f„ÿ–e‚ÿ–e�ÿ•d�ÿ•d�ÿ”dÿ”b}ÿ“c�ÿ“e‹ÿ’f�ÿ”f�ÿ’dƒÿ”b~ÿ•ayÿ•atÿ–_nÿ–_mÿ–_lÿ•_kÿ•^jÿ•]jÿ“]kÿ“]kÿ“^nÿ“\jÿ’[eÿ’Zdÿ‘Zcÿ’Ybÿ’Y`ÿ’Y^ÿ§}Ÿÿ¥€­ÿ¤ƒºÿ¥ƒ¸ÿ¨§ÿª�ÿ«€žÿ«€ ÿª€¡ÿ©¡ÿ©�¥ÿ¨¥ÿ¨€¥ÿ§¤ÿ¨~¢ÿ¨}Ÿÿ§}�ÿ¨}�ÿ¨}œÿª}šÿ¬~™ÿ¬~—ÿ®•ÿ®“ÿ¯€“ÿ°€“ÿ²�’ÿµ‚�ÿµ‚Žÿ¶ƒ�ÿµƒ”ÿµ…šÿµ†�ÿ¶…šÿ¶„�ÿ¶€‰ÿ·‚‰ÿ¹„Œÿº…‹ÿº…Šÿº„‰ÿ»„‰ÿ»„‰ÿ»…‰ÿ¼„‰ÿ¼„Šÿ¼†Žÿ»…�ÿ»‡“ÿ»‡šÿ»‰šÿ»ˆ—ÿ¼ˆ”ÿ»†�ÿ½…�ÿ¼„Œÿ¼…�ÿ½†�ÿ¼†’ÿ¼†“ÿ¼…�ÿ½ƒ‡ÿ½ƒ…ÿ½ƒ†ÿ»„‰ÿ»„‹ÿºƒ‹ÿº…’ÿ¸†šÿ·…šÿ¸ƒ—ÿ·ƒ’ÿ·€�ÿ¶€Šÿ¶‰ÿ¶ˆÿ¶~‡ÿµ~‰ÿ´�ÿ±~‘ÿ²�ÿ³~Žÿ³}�ÿ´‘ÿ´�“ÿµ€“ÿµ€‘ÿ´~Žÿ³}‹ÿ³}�ÿ²~�ÿ±~’ÿ³}�ÿ´|Šÿ¶{†ÿ¶|ƒÿµ{‚ÿ´{�ÿµ|‡ÿ´|Œÿ´{ƒÿµy{ÿµwxÿµwvÿ´wwÿ³x|ÿ²x�ÿ±x‚ÿ°w�ÿ°w�ÿ°v�ÿ®v€ÿ¯vÿ¯u|ÿ®tyÿ®sxÿ®sxÿ­ryÿ¬qyÿ«qyÿ©pxÿ©ovÿ©ouÿªosÿªpsÿ«puÿ©otÿ¨orÿ§nqÿ§npÿ§nrÿ§mqÿ¥joÿ¤imÿ¥jnÿ£joÿ¢hqÿ¡isÿŸhsÿŸhtÿžgtÿ�grÿ�fqÿœerÿ›drÿœesÿ›ftÿ›ftÿšdrÿ™dtÿ—cuÿ—btÿ˜bsÿ˜crÿ—bsÿ—cuÿ—dzÿ”dÿ“e„ÿ“e‡ÿ“f‹ÿ’f‡ÿ“e…ÿ”f‡ÿ•fˆÿ—g‡ÿ—f…ÿ–fƒÿ˜g†ÿ—g†ÿ–e‚ÿ•d}ÿ•d~ÿ•d€ÿ“b}ÿ”c}ÿ”d�ÿ“d†ÿ“e‰ÿ•fˆÿ•cÿ•b{ÿ•awÿ–`qÿ•_jÿ—_iÿ–_kÿ–_lÿ•_lÿ•^lÿ”^lÿ”^nÿ”^pÿ”\iÿ’[dÿ’[eÿ‘[fÿ�Zdÿ‘Xaÿ‘Y`ÿ£} ÿ£«ÿ¥„¼ÿ£„ºÿ§‚¬ÿ©�¤ÿ©‚¤ÿª‚¦ÿ«‚§ÿ©�§ÿ©‚©ÿ¨‚ªÿ¨�¨ÿ©�¥ÿª¤ÿ©~ ÿ¨~žÿ¨~Ÿÿ¨~�ÿ¨}œÿ©}œÿªœÿ¬€�ÿ®€œÿ¯�˜ÿ®€”ÿ°�“ÿ²€�ÿ´��ÿ¶‚Œÿ¶ƒ‘ÿ´„–ÿµ†žÿ´…œÿ³ƒ˜ÿµƒ’ÿ¸„Œÿ¹„Œÿº†�ÿ»†�ÿ»…‹ÿº…Œÿ»†Žÿº…�ÿ¼…�ÿ»…Œÿ»‡Žÿ»†Žÿ»†�ÿ»ˆ˜ÿº‰œÿ¼‰œÿ»ˆ˜ÿ»†”ÿ»†’ÿ¼‡‘ÿ»…Žÿ½†Žÿ¼†�ÿ¼‡‘ÿ½†Žÿ½…Šÿ½„†ÿ¾„‡ÿ½…‹ÿ»…Œÿ¼…‹ÿº„�ÿ¹…•ÿ¹…—ÿ¹…—ÿ¸„’ÿ¹�Œÿ¸€†ÿ¸€ƒÿ¸„ÿ¸‡ÿ¶~Šÿµ€�ÿµ€‘ÿ´€�ÿµŒÿµ~ŠÿµŒÿ¶€Žÿ¶€�ÿ¶€�ÿµŒÿ´~Šÿ´~‹ÿ³�ÿ²~•ÿ²~’ÿ²}Žÿ³|Šÿ´|‡ÿ³{…ÿµ|†ÿ´|‰ÿ´|Šÿµ{‚ÿµyyÿ¶xuÿ¶wtÿµwvÿ²x|ÿ³x�ÿ²xƒÿ°w‚ÿ°w‚ÿ¯w�ÿ®vÿ¯vÿ¯u~ÿ­t|ÿ­t{ÿ­s|ÿ¬s{ÿ«s{ÿªq}ÿ¨p|ÿ¨pyÿ©oyÿ©pyÿ«qwÿªpvÿªpuÿ¨nsÿ¨nrÿ¦mqÿ§mrÿ§mrÿ¥joÿ¤inÿ¥kpÿ£jqÿ¡jsÿ¡iuÿŸivÿžhwÿ�hwÿ�huÿ›ftÿ›ftÿ›ftÿšeuÿ›fvÿ›euÿšdrÿ˜csÿ–ctÿ–ctÿ–brÿ•arÿ–btÿ–bwÿ”czÿ”eÿ“e„ÿ’f‰ÿ’fŒÿ‘eˆÿ“f‡ÿ”fˆÿ•f…ÿ—f‚ÿ–f�ÿ—fÿ—eÿ—fƒÿ—e~ÿ˜dyÿ—dzÿ•c{ÿ–d|ÿ–czÿ•d|ÿ–e„ÿ•e„ÿ”cÿ•bzÿ•axÿ•atÿ–arÿ–_mÿ•_kÿ–_lÿ•^mÿ”_lÿ”_lÿ”^oÿ”_pÿ“^nÿ“\jÿ‘[eÿ‘\fÿ�[gÿ�ZdÿŽXaÿ�X_ÿ§¥ÿ¥�°ÿ¥…ºÿ¥„ºÿ§ƒ±ÿ¨‚¬ÿ©‚©ÿ«ƒ«ÿ«ƒ©ÿ¬„­ÿª„¯ÿª„²ÿª„®ÿ«ƒªÿª€¦ÿª€¡ÿªŸÿ©~Ÿÿ§}Ÿÿ¨~Ÿÿ§}Ÿÿ¨~¡ÿ¨¡ÿ«¡ÿ­€ ÿ¯‚žÿ°�šÿ±€”ÿ³€�ÿ´�Žÿ¶ƒ�ÿ¶…•ÿµ…˜ÿ´„™ÿµ…œÿµ†™ÿ¹†”ÿ¹…‘ÿº†�ÿº…Žÿ»…Œÿº…Œÿ»‡‘ÿ»‡’ÿ¼‡’ÿ»†�ÿ¼†�ÿ»‡�ÿ»‡Žÿ¼‡“ÿ½‰�ÿ¼ŠŸÿ¼Š�ÿ¼‰šÿ½ˆ˜ÿ¼‡–ÿ¼‡‘ÿ½†�ÿ¼‡‘ÿ½‡�ÿ½‡�ÿ½†Žÿ¾…Šÿ½…Šÿ½…�ÿ½†‹ÿ½…Šÿ¼…Žÿ¼†“ÿº†–ÿ¹…–ÿº…“ÿ¹‚�ÿ¹€…ÿ¹€ÿ¹€‚ÿ¸…ÿ¸€Šÿ¸��ÿ¶��ÿ¶��ÿ·Šÿ·‰ÿ·‰ÿ¸�‹ÿ·��ÿ·€Žÿ¶�Œÿ¶‰ÿ¶�ÿ´€’ÿ³”ÿ³”ÿ²~’ÿ²~‘ÿ³~Žÿ²|‹ÿ³}�ÿ´}Žÿ´|Œÿµ|†ÿµz|ÿ¶xwÿ·wuÿµxwÿ´yzÿ²xÿ³y„ÿ±x„ÿ°w„ÿ°x‚ÿ¯vÿ¯vÿ¯vÿ­u€ÿ­t€ÿ¬tÿ«tÿªs€ÿ©r�ÿ¨r€ÿ¨q~ÿ©p}ÿªqzÿªqwÿªpuÿ©otÿ¨ouÿ§nvÿ¨nuÿ§muÿ¦mtÿ¦lsÿ¥ltÿ£kuÿ¤kvÿ¢jvÿ¡jwÿŸixÿžhyÿ�gxÿ�hwÿ›gwÿ›fvÿ›evÿšewÿšfwÿ›etÿ›dsÿšesÿ˜dsÿ–brÿ–arÿ•arÿ•bvÿ”bxÿ“d}ÿ“d€ÿ’eƒÿ’eˆÿ“fŠÿ’e‡ÿ“f‡ÿ”f†ÿ•f‚ÿ–f�ÿ—eÿ˜e|ÿ˜e|ÿ—d{ÿ—cwÿ˜csÿ˜ctÿ—cuÿ—bvÿ—cxÿ˜d{ÿ•d~ÿ–e€ÿ–czÿ–bwÿ–awÿ—avÿ–asÿ•_qÿ–_oÿ•^nÿ–_oÿ–_mÿ•^nÿ“_qÿ“^sÿ’^qÿ’\lÿ‘\hÿ�Zgÿ�Zgÿ�Zeÿ�Yaÿ�W_ÿ©�§ÿ§‚°ÿ§…´ÿ¨†¶ÿ¨†¶ÿ¨…µÿ©…²ÿ©„­ÿ¨ƒ«ÿªƒ¬ÿª†±ÿ©…±ÿ¨ƒ¯ÿª„¯ÿ«ƒ©ÿ¬‚¥ÿ¬�£ÿ«�¢ÿª€¢ÿ¨€¤ÿ§~¤ÿ§¤ÿ¦¤ÿ¨¤ÿª€£ÿ«€¡ÿ®�Ÿÿ°€–ÿ²�“ÿ´ƒ‘ÿ´‚‘ÿµƒ’ÿµ„“ÿ¶„•ÿ¶„—ÿ·†™ÿ·†˜ÿ¹†•ÿ¸…�ÿ¹„Žÿ¹„�ÿº†�ÿ»ˆ“ÿº‡—ÿ»ˆ—ÿ¼ˆ•ÿ¼‡’ÿ¼‡‘ÿ¼ˆ�ÿ¼‡’ÿ¼Š�ÿ»ŠŸÿ»Šžÿ»Š�ÿ¼‰›ÿ¼‰™ÿ½‰˜ÿ½‡–ÿ½‡”ÿ½ˆ–ÿ½ˆ“ÿ½ˆ’ÿ½‡�ÿ¼…�ÿ¾†Œÿ½†ˆÿ¾†‰ÿ½…�ÿ¼‡‘ÿ¼‡”ÿº†—ÿ»†–ÿ¹ƒŽÿ¸€‡ÿ¸„ÿ¸‚ÿ·~…ÿ·€‹ÿ·‚Žÿ·��ÿ·‚‹ÿ¸�Šÿ¸€ˆÿ¹€ˆÿ¹�Šÿ¸€‹ÿ·�Œÿ·�‹ÿ¸�‹ÿ¶€Œÿµ€Žÿ´€’ÿµ“ÿ³’ÿ²~“ÿ²~”ÿ²}”ÿ²~”ÿ²}’ÿ²}�ÿ´|‹ÿ´{ƒÿ´z{ÿµxyÿ¶xxÿ´y{ÿ´y~ÿ³y‚ÿ±xƒÿ°x…ÿ°w�ÿ±w~ÿ°wÿ¯w‚ÿ¬v„ÿ¬u…ÿ«u„ÿªtƒÿ©t…ÿ¨s„ÿ¨s„ÿ¨rƒÿ¨q~ÿ¨pzÿ©pwÿªovÿ©ntÿ¨ovÿ¦nxÿ¥mwÿ¦mxÿ¦nzÿ§nyÿ¥mxÿ¤m{ÿ£lzÿ¡kzÿ¡kyÿŸjyÿžixÿžiwÿ�hxÿœgwÿšfwÿšfyÿ˜fyÿ™exÿšetÿšdrÿšdrÿ™drÿ—brÿ–arÿ•asÿ“auÿ“b{ÿ’cÿ’eƒÿ‘e‡ÿ’gŠÿ“e‡ÿ“e„ÿ”f„ÿ”d�ÿ•d€ÿ•e€ÿ–eÿ—e}ÿ™dyÿ˜dxÿ™crÿ˜bpÿ˜bqÿ˜bpÿ—apÿ˜csÿ˜cwÿ˜dzÿ˜dyÿ˜cuÿ˜bvÿ—bwÿ—bwÿ–auÿ•`tÿ”`rÿ•`rÿ•_pÿ•_oÿ“_pÿ’_tÿ‘_uÿ‘^tÿ�]oÿ�\kÿ�[jÿ�[iÿ�Zfÿ�Yaÿ�Y`ÿªƒ¨ÿª†±ÿ©†´ÿ©†·ÿ¨ˆ¼ÿªˆ»ÿ©†´ÿ©„¯ÿª„¬ÿ©„¬ÿ©„®ÿª„­ÿ©„­ÿªƒ¯ÿª„®ÿ©‚¦ÿ«„¨ÿ¬ƒ§ÿª‚¦ÿ©‚§ÿ©�¨ÿ§�©ÿ¦�©ÿ§§ÿ§¦ÿ¨€£ÿ¬�¡ÿ®‚œÿ±‚˜ÿ³ƒ—ÿµƒ•ÿµ„•ÿ¶ƒ”ÿ¶…•ÿ¶…–ÿ·†™ÿ·‡˜ÿ·†–ÿ·„‘ÿ¹„‘ÿ¸„�ÿ¹…“ÿ¸‡˜ÿ·†™ÿ¹ˆ™ÿºˆ˜ÿº‰–ÿ¼‰•ÿ½ˆ”ÿ¼ˆ•ÿ»Šœÿº‹¡ÿº‹ ÿº‹ ÿ»Š�ÿºŠžÿ»Š�ÿ¼Š›ÿ¼ˆ™ÿ¼‰™ÿ½‰›ÿ¼‰™ÿ½ˆ–ÿ¾ˆ”ÿ½‡Žÿ¼†Šÿ½†Šÿ¼‡�ÿ¼‡’ÿ¼‡•ÿº‡šÿº‡™ÿ¸„�ÿ¸‚Œÿ·�‰ÿ¶‡ÿµ}…ÿ³~‹ÿµ€�ÿ¶��ÿ·�Šÿ·‡ÿ¸…ÿ¸€„ÿº�‡ÿ¸�‰ÿ¸‚‰ÿ¸‚Šÿ¸‚Šÿ·�‰ÿ·€‰ÿ·€�ÿ´Œÿ´~Œÿ´~�ÿ²~‘ÿ°€–ÿ±™ÿ¯~—ÿ¯~•ÿ°}‘ÿ±|Œÿ²{ˆÿ³zƒÿ´yÿ´y~ÿ´zÿ²y€ÿ±y‚ÿ°yƒÿ°w€ÿ°w}ÿ±x�ÿ®w…ÿ­v†ÿ­v‡ÿªu†ÿªt…ÿªs‡ÿ¨tˆÿ§s†ÿ¦r…ÿ¦q�ÿ¥p}ÿ¦o{ÿ¦nxÿ§nvÿ§owÿ§ozÿ¤o{ÿ¤o~ÿ¥oÿ¦o|ÿ¥nzÿ¤n{ÿ£m}ÿ¡l{ÿ¡kzÿŸkyÿŸizÿži{ÿœhyÿ›hxÿ›gyÿšg|ÿ˜g~ÿ˜f}ÿ—dzÿ—dwÿ˜dwÿ—cuÿ•bsÿ•ctÿ”atÿ“auÿ’b{ÿ‘dƒÿ�c†ÿ�e‹ÿ’gŒÿ‘f‡ÿ“d�ÿ”e€ÿ”e‚ÿ”e„ÿ—f„ÿ—f€ÿ˜e|ÿ™ewÿ˜dsÿ˜cnÿ˜bmÿ—aoÿ—amÿ˜aoÿ˜boÿšcrÿšcrÿ™cqÿ˜boÿ˜cuÿ–bwÿ•bxÿ•bzÿ”`vÿ’`uÿ”`uÿ”_uÿ“`tÿ“`wÿ‘`xÿ�`wÿ�_vÿ�]tÿ�\oÿ�\lÿ�ZiÿŽZdÿ�YcÿŽXbÿ­†«ÿ­ˆ²ÿªˆ¶ÿªŠ¾ÿªŠÁÿª‰»ÿ«ˆ´ÿ«ˆ³ÿ«†¯ÿª…¬ÿ«…­ÿª„­ÿ¬„®ÿª…®ÿª„¬ÿ©„«ÿª…°ÿª‡°ÿ«…­ÿ¬…­ÿª„¬ÿ©„­ÿ¨ƒ­ÿ§�ªÿ¦€ªÿ§�¬ÿ¨�¨ÿ«�¥ÿ­‚¡ÿ°„ ÿ³„žÿµ…šÿµ…šÿ¶…šÿµ†™ÿ¶†™ÿ·‡šÿ·†™ÿ·…•ÿ·†”ÿ·…–ÿ·†šÿ¶‡žÿ¶‡žÿ·‡žÿ¸ˆžÿ¹‰›ÿ»Ššÿ½‰™ÿ¼Š™ÿ»‹žÿºŒ£ÿ»Œ¤ÿ»‹¢ÿ»Œ¢ÿ»‹¢ÿ¼‹¡ÿ¼Šžÿ¼‰šÿ¼ˆ™ÿ¼Š›ÿ¼Šžÿ¼Šžÿ¼‰›ÿ½ˆ–ÿ½ˆ“ÿ¼ˆ•ÿ¼ˆ–ÿ½ˆ˜ÿ»ˆ›ÿ»ˆœÿ»ˆ›ÿº†”ÿº„�ÿ¸ƒŽÿ·��ÿ·�Œÿµ�ÿµ�“ÿ¶€�ÿ¶€‹ÿ·†ÿ¹…ÿ¹€…ÿ¹�†ÿ¹�ˆÿ¹‚Šÿ¹‚Šÿº�Šÿ¹�‰ÿ¸€‡ÿ¸€‡ÿ¸‡ÿ¶~‰ÿ´�ÿ³€”ÿ°€™ÿ°€œÿ¯›ÿ¯~šÿ¯~—ÿ°}’ÿ°{Žÿ±{Šÿ²z†ÿ³zƒÿ´z�ÿ²y€ÿ³yƒÿ±x‚ÿ±w€ÿ±w€ÿ±x‚ÿ¯x„ÿ®w…ÿ¬v†ÿ¬vˆÿ«u†ÿªt†ÿ©t‡ÿ©s‡ÿ¦r†ÿ¥q…ÿ¥p�ÿ¥pÿ¥o|ÿ¥nyÿ¦nyÿ¦o{ÿ¥pÿ¥q‚ÿ¦q„ÿ¨r‚ÿ¦q~ÿ£m{ÿ£n}ÿ¢l}ÿ¡kzÿ kyÿžizÿ�j}ÿ›i}ÿ›h|ÿ˜f{ÿ™g€ÿ˜h„ÿ—h„ÿ–f‚ÿ–f€ÿ”d|ÿ”czÿ•cyÿ•cwÿ•btÿ”bwÿ‘c}ÿ�d…ÿ�dŠÿ�f�ÿ�f�ÿ’f‰ÿ“eƒÿ”e€ÿ“d�ÿ”e…ÿ–f�ÿ—f~ÿ™ezÿšduÿšcoÿšbkÿ™alÿ˜bnÿ˜boÿ˜bnÿšboÿ›boÿšamÿ›amÿšblÿ˜bqÿ—cxÿ•c{ÿ“b|ÿ“bzÿ”azÿ“azÿ’azÿ“a{ÿ‘a}ÿ‘a|ÿ�`{ÿ�_yÿ�^vÿ�\qÿ�\nÿ�[jÿ�[gÿ�[fÿŽYeÿ­‡®ÿ­‰³ÿ¬‹¼ÿ«�Çÿ«�Éÿ­ŒÁÿ­Š¶ÿ®‰µÿ­‰´ÿ­ˆ³ÿ¬†°ÿ¬†¯ÿ«†­ÿ«…®ÿª„¬ÿª„¬ÿ©…°ÿ©‡´ÿ«†²ÿ­‡°ÿ­†®ÿ¬…®ÿ«…¯ÿª…®ÿ©„­ÿ§ƒ®ÿ¨ƒ¬ÿ©ƒ«ÿ«ƒ©ÿ­ƒ¨ÿ¯„¥ÿ±…¢ÿ³…Ÿÿµ†œÿµ†šÿ¶…—ÿ¶†—ÿ·‡œÿ·ˆ�ÿ·ˆŸÿ¶‡ ÿ¶† ÿ´† ÿ³†¡ÿ³‡¢ÿ´ˆ£ÿ¶ˆ£ÿ¸‰Ÿÿ»Š�ÿ»‹žÿ»‹¡ÿ»Œ£ÿ¼�§ÿ»Œ¥ÿ¼Œ¤ÿ»�£ÿ¼‹¡ÿ¼‹Ÿÿ¼Šœÿ½Šœÿ»Š�ÿ»‹ ÿº‹¢ÿ»Š ÿ»‰œÿ»Š›ÿ»Šœÿ»Šœÿ»Š�ÿ¼Šžÿ»‰�ÿ¼‰™ÿ»†“ÿº†‘ÿ»…Žÿ»ƒŠÿº‚ˆÿ¸‚�ÿ¶‚“ÿ·�Žÿµˆÿ·„ÿ¹€†ÿº‚‡ÿº‚†ÿº‚‰ÿ¹ƒ‹ÿ¹�Œÿº‚‹ÿ¸�Šÿ¹€ˆÿ¹€ˆÿ·€ˆÿ·€�ÿµ�‘ÿ´‚—ÿ³�›ÿ±€›ÿ±€šÿ°€›ÿ¯˜ÿ°}”ÿ±|‘ÿ±|Žÿ°|�ÿ±{ˆÿ³zƒÿ³z‚ÿ³y�ÿ²x€ÿ²x€ÿ±x�ÿ°x‚ÿ¯v‚ÿ®wƒÿ¬v…ÿ¬v…ÿ«uƒÿ«u‚ÿªt„ÿ¨t‡ÿ§s†ÿ¦r†ÿ¦qƒÿ¤o�ÿ¤o€ÿ£o~ÿ¤o~ÿ¥pÿ¥p€ÿ¥r…ÿ¦s‡ÿ§s…ÿ§r€ÿ¥o|ÿ£m~ÿ¢m~ÿ l{ÿ jxÿžizÿ�i}ÿšiÿšh~ÿ˜gÿ—h„ÿ—h‡ÿ–i‰ÿ–i‡ÿ•h†ÿ”f‚ÿ•eÿ•e}ÿ”cyÿ•bwÿ“bxÿ�b}ÿ�dˆÿŽeŽÿ�g’ÿ’i‘ÿ’f‹ÿ’f†ÿ’eƒÿ“d�ÿ•f�ÿ—f~ÿ™evÿšdtÿšcpÿšbkÿ›bjÿšblÿ™bmÿ™bnÿ™bnÿšbnÿšamÿšamÿšbmÿ™bmÿ—boÿ—cwÿ•c}ÿ”d€ÿ”cÿ”dÿ”c€ÿ“cÿ“c€ÿ’b€ÿ‘bÿ�a}ÿ�`zÿŽ^wÿ�^uÿ�\qÿ‘\lÿ‘[eÿ‘[dÿ�[fÿ¬ˆ²ÿ®‹¹ÿ­�Äÿª�Íÿª‘Îÿ®�Áÿ¯Œµÿ¯‹µÿ®‹¸ÿ®‹¸ÿ®Š¸ÿ­‰·ÿ«‡²ÿ©†±ÿª…®ÿ©ƒ¬ÿ©…®ÿ©…°ÿ©…°ÿª†°ÿ¬†®ÿ¬„«ÿ«†®ÿ«†±ÿ«…¯ÿ©…¬ÿ©ƒ¬ÿ¨ƒ¬ÿ©„«ÿ«„­ÿ­…©ÿ®…£ÿ±…¡ÿ´‡ ÿ´†šÿ·†•ÿ·†•ÿ·‡œÿ¶‡žÿ¶‰£ÿµˆ¡ÿ´ˆ£ÿ³‡¤ÿ²‡¥ÿ°†¥ÿ²‡©ÿ²ˆ©ÿ³ˆ§ÿ·ˆ ÿ¸Š¢ÿº‹¥ÿ»Œ§ÿ»�§ÿº�¤ÿ»Œ¤ÿ»Œ¡ÿ¼‹žÿ½‹šÿ½Š›ÿ»Šœÿ¼Šžÿº‹¢ÿº‹¥ÿ»Œ¦ÿºŠ¢ÿ¹‹¢ÿ»‹¡ÿºŠŸÿºŠžÿ¼‹Ÿÿ¼‰œÿ¼‰–ÿ½‡�ÿ¿‡Œÿ½……ÿ¾„‚ÿ½…‚ÿ¼„‡ÿ»„Šÿºƒˆÿ¸�…ÿ¹€†ÿº‚‡ÿº‚‡ÿºƒ‡ÿ»ƒŠÿ¹„Œÿ¸‚Œÿ¸‚Œÿ¸‚Œÿ¸�‹ÿ¹‚‹ÿ¸‚�ÿ¶‚‘ÿµ�”ÿ´‚˜ÿ²�™ÿ³€™ÿ²�™ÿ°€—ÿ³€”ÿ²}�ÿ±~�ÿ±~�ÿ°|�ÿ°{�ÿ±{‰ÿ´z…ÿ²y‚ÿ±x�ÿ±y‚ÿ¯y‚ÿ¯x„ÿ®x…ÿ­wƒÿ­w„ÿ¬v‚ÿ¬u€ÿ«u€ÿ«u‚ÿ¨tƒÿ¨t…ÿ§r…ÿ¤q€ÿ¤o€ÿ£n€ÿ¢n�ÿ¢pƒÿ¤p„ÿ¤p†ÿ¤rˆÿ¦t‹ÿ§t‰ÿ¨s‚ÿ¦o|ÿ£n|ÿ¡m~ÿ¢m~ÿ�jzÿ›h{ÿ›h~ÿšj€ÿ—g€ÿ—g„ÿ•hŠÿ•iŽÿ–j�ÿ–j‹ÿ•iŠÿ–iˆÿ–eƒÿ•f€ÿ”d}ÿ“c{ÿ’c}ÿ�d�ÿ�eŠÿ�g”ÿ�h”ÿ‘h’ÿ‘fŒÿ’f‰ÿ’e„ÿ”e�ÿ—f|ÿšeuÿ™dqÿšdqÿšcpÿ›cnÿ›blÿ›blÿšbmÿšbmÿ›coÿ™boÿ™boÿ™bpÿ˜bpÿ˜anÿ˜boÿ—cwÿ”c}ÿ•d…ÿ”e…ÿ“cƒÿ“dƒÿ”d�ÿ”c€ÿ“c€ÿ‘b‚ÿ�a€ÿ�`|ÿŽ_zÿŽ^xÿ�^uÿ‘\mÿ�Zeÿ�Zcÿ�[fÿ°‹µÿ®�¿ÿ®�Æÿ®�Êÿ­‘Ìÿ¯Ž½ÿ²‹±ÿ²�µÿ°Œ¸ÿ°�¹ÿ¯‹¸ÿ®‹½ÿ¬‹Âÿ«‹¿ÿ«ˆµÿ«†¯ÿª…®ÿª„­ÿ©ƒ­ÿ©…°ÿª…¯ÿ«…¬ÿ¬†­ÿ«†°ÿ«†¯ÿª…¯ÿ©„­ÿªƒªÿ¨ƒ­ÿ©„°ÿ«„®ÿ¬„¨ÿ¯…¤ÿ±…¡ÿ³†Ÿÿµ†œÿ·‡šÿ·ˆ ÿ¶‰¢ÿ¶‰£ÿµˆ¢ÿ´ˆ¤ÿ´ˆ§ÿ³‰©ÿ´‰ªÿ³‰¬ÿ²‰¯ÿ°‡¬ÿ²†¨ÿ´‰§ÿ¶‹¨ÿ·Œªÿ¸‹¥ÿº‹¢ÿ»Œ£ÿ¼Œ¢ÿ¼‹�ÿ½Ššÿ¾‹šÿ¼‹œÿ»‹¢ÿºŒ¦ÿºŒ©ÿ¹Œ©ÿ¹Œ¨ÿ¹Œ¨ÿ¹Œ¦ÿº‹£ÿºŠ ÿ»Š�ÿ¼‰™ÿ½‰•ÿ½ˆ’ÿ¾‡�ÿ¿††ÿ¿…ƒÿÀ…�ÿ¾…�ÿ¾†ƒÿ½…ƒÿ½ƒƒÿ¼…‡ÿ»„‰ÿ»„Šÿ»„‹ÿ¼„�ÿ»„Žÿº„�ÿ¹„�ÿ¹ƒ�ÿ¹ƒ�ÿ¸��ÿ·‚�ÿ¶‚”ÿµ‚–ÿ´‚šÿ³��ÿ³‚žÿ²‚�ÿ²€™ÿ´~�ÿ´~Šÿ´~Žÿ´~�ÿ²|�ÿ±|�ÿ±|�ÿ±{Šÿ²z‡ÿ²y„ÿ°x…ÿ¯y‡ÿ¯x‡ÿ­x†ÿ­v…ÿ¬vƒÿ¬u�ÿ¬u€ÿ¬tÿ«tÿªtÿ¨rÿ§r€ÿ¥p€ÿ¤p€ÿ¤o‚ÿ¡o„ÿ¡o†ÿ o†ÿ¡qŠÿ£s�ÿ¥s‹ÿ§sˆÿ§s�ÿ¥p{ÿ¤n|ÿ¢m|ÿ k|ÿžj}ÿ›i~ÿ™i�ÿ˜iƒÿ—h„ÿ•h‡ÿ“iŽÿ’j“ÿ“i“ÿ”j’ÿ”j‘ÿ–kŽÿ•jŠÿ–h…ÿ”f�ÿ’e€ÿ�dƒÿ�e‰ÿ�g‘ÿŽh˜ÿ�h–ÿ�h’ÿ‘g�ÿ’f‹ÿ’e†ÿ”e�ÿ˜eyÿšdsÿœeqÿšdqÿ›dqÿšcpÿšcpÿšcoÿšcoÿ›coÿšcpÿ™cqÿ™bpÿ™boÿ˜boÿ˜bpÿ˜brÿ–cwÿ•dÿ•e‰ÿ”eˆÿ”d„ÿ”d‚ÿ”d�ÿ”b€ÿ”c‚ÿ’c‚ÿ‘a‚ÿ‘aÿ�a}ÿ�`|ÿ�^wÿ�\rÿ‘\jÿ’[fÿ’[gÿ°�¹ÿ°Ž¿ÿ¯�Áÿ°�¿ÿ¯�Àÿ²�ºÿµŒ°ÿ´Žµÿ²�¸ÿ²Ž¶ÿ²Œ±ÿ°Œ¶ÿ®ŒÀÿ­ŒÃÿ¬Œ¿ÿ­‹ºÿ­‰´ÿ¬‡®ÿ¬†­ÿ¬…®ÿ¬†®ÿ«…°ÿ«†¯ÿ«†¯ÿ«‡°ÿ«‡³ÿ«†±ÿª†¯ÿ©†°ÿª†³ÿ©†³ÿª…®ÿ¬…«ÿ®†¨ÿ°†§ÿ²‡£ÿ´‡ ÿµ‡ ÿ·‰ ÿ·‰ ÿ·ˆ¢ÿ¶‰¤ÿ´ˆ¥ÿµŠªÿµŠ¬ÿµŠ®ÿ´Š°ÿ³Š®ÿ±ˆ­ÿ±ˆ«ÿ´Š¬ÿµ‹¬ÿ¶‹¨ÿ¸Š¥ÿ¹‹¤ÿºŒ¤ÿºŒ¢ÿ¼‹žÿ½‹›ÿ¼ŒŸÿ»�¦ÿº�©ÿ¹Ž¬ÿ¹Ž¬ÿ¸Œ¬ÿ¹�¬ÿ¸Œ¨ÿºŒ¦ÿº‹£ÿ»Š�ÿ¼Š›ÿ¼‰šÿ½Š™ÿ½‰•ÿ½†�ÿ¿†Šÿ¿†…ÿ¿…ƒÿÀ…„ÿ¿†…ÿ¿†„ÿ¿…ˆÿ½†‹ÿ¼†�ÿ¼†�ÿ¼†�ÿ»…’ÿ»†“ÿº„‘ÿ¹…�ÿ¹ƒŽÿ¸ƒ�ÿ·ƒ’ÿ¶ƒ–ÿ´ƒšÿ³ƒ�ÿ³ƒ ÿ²ƒ¡ÿ±‚ ÿ³�›ÿ³“ÿ´~ŒÿµŒÿµŠÿµ}†ÿ´|†ÿ±|Šÿ°|�ÿ°|�ÿ¯z‹ÿ¯z‹ÿ®zŒÿ®z‹ÿ®yŠÿ­w„ÿ¬u�ÿ«t�ÿ¬t€ÿ«t~ÿªsÿ©s~ÿ¨sÿ¦qÿ¦pÿ¥p�ÿ¤p‚ÿ¢o„ÿ¡o†ÿ pˆÿ¡q�ÿ¢rŽÿ£qŠÿ¥q…ÿ¥r�ÿ¥p|ÿ¤n|ÿ¢m}ÿ¡l}ÿ�kÿši€ÿšj„ÿ˜i…ÿ–jˆÿ•jŒÿ’j’ÿ‘k—ÿ‘l™ÿ‘lšÿ‘k™ÿ”l—ÿ”k’ÿ–j�ÿ•h‰ÿ“g†ÿ‘e‡ÿ‘gŽÿ�i•ÿŽj™ÿ�j˜ÿ‘i•ÿ‘h�ÿ’f‹ÿ“f‰ÿ—g‚ÿ˜eyÿšeuÿœesÿ›esÿ›ftÿ›etÿšetÿšdsÿ›dsÿ™dqÿšdsÿ™ctÿ™cqÿ™cnÿ˜coÿ—boÿ˜csÿ—dxÿ–d~ÿ•e†ÿ•e†ÿ•eƒÿ•e‚ÿ”d�ÿ“c€ÿ“c€ÿ’bÿ‘a~ÿ‘a}ÿ�`|ÿ�`|ÿ�^xÿ‘^rÿ’]nÿ’\kÿ’\lÿ°�¹ÿ±�¾ÿ²�¾ÿ±Žºÿ²�¸ÿ´Ž¶ÿ´Ž²ÿ´�·ÿµ‘»ÿ´�µÿ´�­ÿµ‹©ÿ³Œ±ÿ²Œ³ÿ°�Àÿ­ŽÁÿ­�¿ÿ¯�¼ÿ¯‰°ÿ­†¬ÿ­†­ÿ¬‡²ÿ«‡²ÿ«†²ÿ¬ˆ³ÿ­‰µÿ­‰¶ÿ«‡³ÿª†±ÿª‡³ÿ©†´ÿ©†´ÿ©†´ÿª…²ÿ«…®ÿ¯†ªÿ°†¥ÿ±‡¢ÿ³‡ ÿµ‰¡ÿµˆ ÿ¶‡ ÿ´‡£ÿ´‰¦ÿ¶Š©ÿµŠ«ÿµ‹¬ÿ³Š©ÿµŠ«ÿ²‰©ÿ²‰«ÿ³‰®ÿ´‹®ÿ´Šªÿ¶Š¨ÿ·‹§ÿ¸‹§ÿº‹¤ÿºŒ¢ÿºŒ¤ÿº�©ÿ¹Ž¬ÿ¹�«ÿºŽªÿºŽªÿ¸�°ÿ¸�«ÿ¹Œ¨ÿ¸Š¦ÿºŠ ÿ»Š�ÿº‰œÿ»‰�ÿ½Š›ÿ½Š—ÿ¾‰“ÿÀ‡�ÿ¿‡ˆÿ¾‡‡ÿ¿†ˆÿÀ‡‰ÿ¾…‰ÿ¾†�ÿ¼‡�ÿ¼†“ÿ»†“ÿº…‘ÿº…’ÿº…�ÿ¹…Žÿ¹„�ÿ¹„’ÿ·„–ÿ´„šÿ´„Ÿÿ²„£ÿ²…¤ÿ±„¢ÿ²‚žÿ²‚�ÿ²€–ÿ²Žÿ´�ÿ¶‹ÿµ}†ÿ´|†ÿ´}‰ÿ±|Œÿ°{�ÿ®z�ÿ­z�ÿ¬y�ÿ®y‹ÿ­x‰ÿ¬w„ÿ¬vƒÿ«u‚ÿ©tÿ¨s~ÿ©s€ÿ©t�ÿ¨r‚ÿ§q‚ÿ¦r€ÿ¦q€ÿ¤q�ÿ¢pƒÿ¢p…ÿ p‹ÿ qŽÿ pŒÿ¡o‰ÿ£p„ÿ¤q‚ÿ¥p€ÿ¤oÿ¢mÿ m‚ÿœl„ÿ›l…ÿ›l‡ÿšlŠÿ–kŒÿ–k�ÿ”k”ÿ‘l˜ÿ’m›ÿ�l›ÿ�kšÿ’kœÿ“k™ÿ”k”ÿ•j�ÿ“h�ÿ‘fŠÿ‘i�ÿŽj–ÿ�j˜ÿŽi˜ÿ�i•ÿ‘h‘ÿ’hŒÿ•f‹ÿ—h‡ÿ—f~ÿšfzÿšfwÿ›gwÿšfwÿšfwÿšfwÿ™evÿšeuÿšftÿ™ewÿ™evÿ™dtÿšcpÿ˜bqÿ—brÿ™btÿ–cvÿ•czÿ–e‚ÿ•e„ÿ“dƒÿ“cƒÿ“c‚ÿ“d€ÿ”c|ÿ“bzÿ’azÿ’axÿ‘`zÿ�_xÿ‘`vÿ’^sÿ’^oÿ’^oÿ’^rÿ²�ºÿ³‘¾ÿ³‘½ÿ´�»ÿµ�¹ÿ´�µÿµ�´ÿ´‘¹ÿµ‘ºÿ·�²ÿ·Žªÿ¸�¨ÿ¶Œ¨ÿ¶Œ¨ÿ³�²ÿ²Žºÿ°Ž¹ÿ°‘Áÿ±�ºÿ±‹²ÿ²Š¯ÿ®‰±ÿ¬‰µÿ¬‰¶ÿ«ˆ·ÿ¬Š¸ÿ­Š·ÿ®Šµÿ­‰´ÿ¬‡³ÿª‡²ÿª‡³ÿ¨†´ÿ©†´ÿ«†²ÿ«…®ÿ­†¬ÿ®…©ÿ¯‡§ÿ²ˆ¦ÿ³ˆ£ÿ´‡¢ÿ´‡¢ÿµ‡£ÿ¶ˆ£ÿ·‰£ÿ¶Š¥ÿ¶Š§ÿ¶‹¥ÿ¶Š¦ÿµŠªÿ´Š­ÿ´‹¯ÿ´‹°ÿ´‹®ÿ´Œ®ÿ¶Œ­ÿ¸�ªÿ¸�ªÿ¹�«ÿ¸�®ÿ¸Ž°ÿº�®ÿ»Ž§ÿ»Ž©ÿ¹Ž°ÿºŽ­ÿºŒ¥ÿº‹¤ÿºŠ ÿ»‰žÿ»Šžÿ»Šžÿ¼Šœÿ½Š—ÿ¿Š–ÿ¾‰“ÿ¿ˆ�ÿ¿ˆŽÿ¿‡Žÿ½‡Žÿ½ˆŽÿ½‡�ÿ¼ˆ”ÿ¼ˆ•ÿ¼‡”ÿ»†“ÿº…’ÿ¹…�ÿº„Žÿ¹„’ÿ¸„—ÿ¶…�ÿ´…¢ÿ²†§ÿ±†¨ÿ±…¨ÿ°„¤ÿ²ƒŸÿ±‚œÿ³�–ÿ³€’ÿµ€�ÿµ�ÿ´~‹ÿµ}Šÿ³}Œÿ³}Œÿ±{Žÿ¯{Žÿ­{‘ÿ¬y�ÿ­yŒÿ­x‰ÿ­x‡ÿ¬w†ÿ«v„ÿªt‚ÿ©t‚ÿ¨t„ÿ¨s„ÿ¨sƒÿ§r„ÿ§sƒÿ§s‚ÿ¦q€ÿ¥q€ÿ£p„ÿ p‰ÿŸo�ÿžo‰ÿŸn…ÿ nƒÿ¡oƒÿ¢pƒÿ¢oƒÿ¡o…ÿŸn‡ÿžn‰ÿœnˆÿ�m‰ÿ›m‹ÿ˜mŽÿ—l‘ÿ–m•ÿ”k”ÿ“k–ÿ’k–ÿ‘k—ÿ’k™ÿ’l—ÿ“l–ÿ”k”ÿ“j’ÿ’i‘ÿ�i“ÿ�j™ÿ�j—ÿ�i—ÿ�i–ÿ‘h’ÿ“gŽÿ”hŽÿ—h‰ÿ™hƒÿ™gÿšg|ÿšg{ÿœgzÿšgyÿ™fyÿšezÿ™fzÿ™eyÿšfxÿševÿšdsÿ˜cqÿ˜csÿ—bsÿ—ctÿ—cvÿ–czÿ•eÿ”e‚ÿ“d‚ÿ’c€ÿ“cÿ”c{ÿ”avÿ”avÿ’awÿ’awÿ“awÿ’`wÿ‘_wÿ‘_uÿ’_tÿ’_sÿ’`vÿ´‘¾ÿ´‘¾ÿµ’¼ÿµ‘ºÿµ’¹ÿµ’¸ÿµ’¸ÿµ‘»ÿ¶’¸ÿ¹�±ÿ¹�¨ÿº�§ÿº�¥ÿ¹Œ¢ÿ·�¬ÿµ�µÿ´Žµÿ²‘»ÿ´�¶ÿ¶�µÿ´�²ÿ²‹±ÿ°‹³ÿ®Šµÿ­‰·ÿ¬Š¸ÿ«Š·ÿ­‰¶ÿ­Š¶ÿ­ˆ´ÿ¬‡°ÿ¬†¯ÿ¬‡³ÿ«‡´ÿ«‡³ÿ«‡²ÿ¬†¯ÿ­†®ÿ¬‡¯ÿ­†®ÿ¯†«ÿ±†§ÿ±‡¥ÿ²‡¥ÿ´ˆ¤ÿµ‰¤ÿ¶‰¦ÿ·‹¦ÿ·‹¤ÿ·Š¤ÿ¸‹§ÿ¶Œªÿ¶Œ­ÿ¶�°ÿµ�±ÿµ�²ÿµ�±ÿ·�¯ÿ·�®ÿ·Ž²ÿ·�µÿ¸�´ÿ¹Ž°ÿ»Ž¨ÿ»�§ÿ»Ž­ÿ»Ž«ÿ¼Œ£ÿ»Œ ÿ¼‹Ÿÿ¼Š›ÿ¼‹œÿ¼‹�ÿ¼Š›ÿ¾‹™ÿ¾‹™ÿ¾‹šÿ¿Š˜ÿ¾‰”ÿ¿Š–ÿ¾ˆ•ÿ¼ˆ•ÿ¼Š—ÿ¼ˆ—ÿ¼ˆ˜ÿ¼ˆ–ÿ»‡”ÿ»…”ÿº…’ÿº…’ÿ¹…–ÿ¶†žÿ´‡¤ÿ³‡«ÿ±‡­ÿ±‡­ÿ°‡«ÿ°…©ÿ°„£ÿ²‚žÿ²‚šÿ³�•ÿµ€’ÿµ€�ÿµ�ÿµ�ÿ´~�ÿ³}Žÿ±}Žÿ°|�ÿ®{�ÿ­z�ÿ­xŠÿ¬x‰ÿ«x‰ÿ©w‰ÿ©vˆÿ©u†ÿ©t‡ÿ§t‡ÿ§s„ÿ¨s„ÿ¨sƒÿ§sƒÿ¨s‚ÿ¦r�ÿ¥rƒÿ£q…ÿ¡pˆÿŸoŠÿžn‡ÿ�m„ÿŸn†ÿ�m†ÿŸn†ÿŸn…ÿ o‡ÿŸo‹ÿ�nŠÿ�n‹ÿœoŒÿ›nŽÿšm‘ÿ˜n“ÿ—l’ÿ—k‘ÿ–j�ÿ”jŽÿ“j‘ÿ”l”ÿ”l•ÿ”l•ÿ”l•ÿ”l–ÿ’j–ÿ�j–ÿŽj™ÿŽi˜ÿ�i–ÿ�i–ÿ‘i“ÿ‘i’ÿ”i’ÿ•iŒÿ™h†ÿ™hƒÿšh�ÿšh€ÿši~ÿ›f}ÿšg}ÿ˜f}ÿ˜g|ÿšfzÿ™fxÿševÿ™drÿ™cqÿ˜cqÿ—brÿ–cuÿ–cxÿ•c|ÿ”dÿ”d~ÿ“b~ÿ‘b|ÿ’bzÿ•bwÿ•buÿ”auÿ“bwÿ“awÿ’axÿ“`zÿ“`yÿ“axÿ”axÿ”`vÿ”`vÿ´’¾ÿµ“¾ÿµ‘»ÿµ’ºÿµ“¸ÿ¶“¸ÿµ’ºÿµ“½ÿ¶’¹ÿ¸’´ÿ¹�­ÿº�®ÿ¹�¬ÿ¹Ž¦ÿºŽ§ÿ¸�«ÿ¶�²ÿ¶�´ÿ·Ž­ÿ·�«ÿº‘³ÿ¸�°ÿ¶Ž±ÿ²�³ÿ¯Œµÿ­Š·ÿ­Š¸ÿ­Š¸ÿ­‹·ÿ®Š·ÿ®Š³ÿ¬‡­ÿ®ˆ¯ÿ¬‰´ÿ¬ˆ³ÿ­‰´ÿ­‡°ÿ¬†¬ÿ­‡®ÿ­‡¯ÿ¬‡¬ÿ®†ªÿ°‡ªÿ¯‡«ÿ±ˆ©ÿ³ˆ¨ÿ³‰¦ÿµŠ§ÿ·‹¥ÿ·Š¢ÿ·Œ¥ÿ·‹§ÿ¶Œ©ÿ·Žªÿ·Ž¬ÿ·Ž¬ÿ¶�­ÿ¸Ž®ÿ¶�±ÿ´�·ÿ´�ºÿµ�¸ÿ·Ž³ÿ¹Ž¬ÿ¹�§ÿº�§ÿ»�¦ÿ»‹Ÿÿ¼‹�ÿ¼‹žÿ½Œžÿ¼‹�ÿ½‹™ÿ¾Š˜ÿ½‹˜ÿ¾‹šÿ½Œœÿ¾‹™ÿ¾Ššÿ¼Š›ÿ¼‰›ÿ»Š›ÿ»Šœÿ»Š�ÿ»ˆ›ÿ»ˆ™ÿº‡—ÿ¹†—ÿº†—ÿ¸…—ÿ·…žÿµˆ¦ÿ²ˆ­ÿ±‰±ÿ°ˆ±ÿ°‡¯ÿ°‡¬ÿ±†¨ÿ±„£ÿ±ƒŸÿ²‚›ÿ³ƒ˜ÿ³€”ÿ´€’ÿµ€’ÿ´�ÿ´�ÿ²}Žÿ±}Žÿ°|�ÿ°|�ÿ®{‹ÿ­x‡ÿ¬xŠÿªx‰ÿ©wŒÿ¨vŒÿ¨u‰ÿ¨u‰ÿ§t‡ÿ¦s…ÿ¥s„ÿ§r„ÿ¦s„ÿ¦r„ÿ¦rƒÿ¥r†ÿ¢q‰ÿ¡qŠÿŸpŠÿžn‰ÿžo‰ÿžn‹ÿžnŠÿ�n‰ÿ�nˆÿžo‰ÿžo�ÿ�p�ÿšp‘ÿœp“ÿ›p“ÿ™o”ÿ™m”ÿ—l�ÿ—k‹ÿ˜l�ÿ—j‹ÿ”j‹ÿ•jŽÿ•k‘ÿ”l’ÿ“l–ÿ”l—ÿ‘l–ÿ�j—ÿ�j™ÿŽj–ÿ�j–ÿ�j–ÿ�i•ÿ’k•ÿ“k•ÿ”j�ÿ•i‹ÿ˜iˆÿ˜i…ÿ™i„ÿ›i„ÿ™h€ÿ™gÿ—gÿ™gÿ˜f|ÿ˜eyÿ˜evÿ˜duÿ˜dsÿ˜cqÿ—cqÿ–cuÿ•czÿ”d}ÿ”d~ÿ‘b{ÿ�azÿ‘a{ÿ’bxÿ“bvÿ•bvÿ•awÿ“bwÿ“byÿ“b|ÿ’b|ÿ’b|ÿ”a{ÿ”b{ÿ”bxÿ”auÿ´–Ãÿµ•Áÿ·•¾ÿ¶”»ÿ·”»ÿ¶“ºÿ¶•Àÿ¶•Áÿ·“¼ÿ·”¼ÿ¸”¼ÿ¹”·ÿ»“°ÿ¼‘«ÿ»‘ªÿº�«ÿ¹‘®ÿ¸�±ÿ¹Ž©ÿ¹Ž£ÿº�§ÿº‘«ÿº‘¬ÿ¹�®ÿ¶�²ÿ³�µÿ±�·ÿ¯Œ¹ÿ®‹¹ÿ®‹¸ÿ®‹µÿ¯Š±ÿ¯‰®ÿ¯Š²ÿ­‰´ÿ¬‰¶ÿ¬‰³ÿ­‡¯ÿ®‡¯ÿ­ˆ°ÿ®‡±ÿ®ˆ±ÿ­‰²ÿ­‡±ÿ®ˆ®ÿ±‰¬ÿ²‰«ÿ³Šªÿ´Š§ÿµŠ§ÿ¶Š§ÿ¶Š§ÿ¶Œ©ÿ·�«ÿ¸Ž«ÿ¸Žªÿ¸Žªÿ¹Ž«ÿ¸�°ÿµŽ·ÿ´�¹ÿµ�¹ÿ·�¸ÿ¸�±ÿ¹Ž«ÿº�¦ÿ»Œ£ÿ»Œ ÿ»‹Ÿÿ¼‹Ÿÿ½ŒŸÿ½Œ�ÿ½‹™ÿ¿‹˜ÿ¾Š˜ÿ¼Ššÿ½Ššÿ½‹›ÿ¼ŒŸÿ¼Œ¢ÿ»‹¡ÿ»Š ÿº‹¡ÿ»‹£ÿºŠ¡ÿ»ˆžÿº‰œÿºˆ�ÿ¸‡�ÿ¸‡ ÿµ‡§ÿ³ˆ­ÿ±ˆ²ÿ°ˆµÿ°ˆ±ÿ²ˆ­ÿ²‡§ÿ³…¢ÿ³„Ÿÿ³‚›ÿ´ƒ™ÿ´ƒšÿ³‚—ÿ³€”ÿ´€“ÿ³�ÿ´�ÿ²~�ÿ±~�ÿ±}‘ÿ²}�ÿ°{„ÿ°y„ÿ®x‡ÿ¬x‰ÿªwŒÿ©v‹ÿ©uŠÿ¨u‰ÿ§tŠÿ¥tˆÿ¥t‰ÿ¦s‰ÿ¦s‡ÿ¥s…ÿ¦s‡ÿ¥s‰ÿ¢rŒÿ¢rŽÿ qŽÿŸqŽÿ q�ÿ pŒÿ pŒÿŸo‰ÿ pŠÿžp�ÿ�p‘ÿ›p”ÿ›q™ÿšqœÿ›r›ÿ›q˜ÿšn“ÿ™lŽÿ˜kŠÿ˜kŒÿ—kŒÿ—jŠÿ–j‹ÿ”i�ÿ’j�ÿ“k”ÿ’l–ÿ“l˜ÿ’k˜ÿ‘k—ÿ�j—ÿ�k—ÿ‘j˜ÿ�k—ÿ’l˜ÿ“k–ÿ”k”ÿ–k’ÿ–kŽÿ—jŠÿ—jŠÿ™j‰ÿ˜h„ÿ˜hƒÿ™i„ÿ˜i…ÿ˜h‚ÿ™g~ÿ˜ezÿ˜ewÿ˜duÿ—csÿ—csÿ•cvÿ”byÿ’c}ÿ’b}ÿ�a|ÿ‘a|ÿ’a{ÿ’byÿ“byÿ“ayÿ“b{ÿ“b{ÿ“cÿ“d�ÿ“dÿ”d}ÿ”c~ÿ”d~ÿ”c|ÿ”b|ÿ´•Åÿ´–Ãÿ·–¿ÿ¸•½ÿ¸”¹ÿ¹•¹ÿ¸–¼ÿ·•¾ÿ¸•¾ÿ·•¾ÿ·•¾ÿ¸”¸ÿ¹“°ÿ»’­ÿ»’­ÿ»�¬ÿº‘­ÿº‘¯ÿº‘«ÿ»�¥ÿ»�¥ÿ¼‘©ÿ¼�©ÿ¼‘ªÿº‘®ÿ¹‘°ÿ·�²ÿ´�¶ÿ±Ž¸ÿ°Œ·ÿ°‹µÿ°‹´ÿ°Š°ÿ°Š°ÿ±Š³ÿ®Š´ÿ®Š´ÿ®Š´ÿ­‰²ÿ¬‰±ÿ¯‰³ÿ¯‰³ÿ®‰´ÿ­ˆ³ÿ­ˆ²ÿ®‰±ÿ°‰¯ÿ±‰­ÿ±‰«ÿ³‰¬ÿ³Š«ÿ³‰«ÿ´‹­ÿ¶Œ¯ÿ¶Œ«ÿ·Ž«ÿ¸�«ÿ·�«ÿ¸Ž­ÿ·Ž±ÿ´Ž¶ÿ´�·ÿ·�·ÿ·�³ÿ¹�¯ÿº�«ÿº�¥ÿ¼�£ÿ»Œ¢ÿºŒ£ÿ»Œ¢ÿ¼Œ ÿ½�›ÿ¾Œ™ÿ½Œ›ÿ¼‹œÿ¼‹œÿ»Š�ÿ¼�¢ÿ»Œ£ÿ»Œ£ÿ»‹¢ÿºŒ¥ÿºŒ§ÿºŠ¤ÿ¹‰ ÿº‰Ÿÿ¸ˆ ÿ¸‰£ÿ¶‰¥ÿ´‰¬ÿ²Š°ÿ²‰²ÿ±‰²ÿ²‡¬ÿ²‡©ÿ³†£ÿ³…£ÿ´…Ÿÿµƒ˜ÿ´‚—ÿ´ƒ›ÿ´ƒšÿ³‚™ÿ´�–ÿ´�“ÿ³~�ÿ²~‘ÿ°}’ÿ°}‘ÿ±}Šÿ³z„ÿ²y‚ÿ°y„ÿ®z‡ÿ«y‹ÿ«w‰ÿ«v‰ÿ©v‰ÿ§v‹ÿ§wŽÿ¦v�ÿ¦vŽÿ§uŒÿ§u‹ÿ¥tŠÿ¥tŒÿ£sŽÿ¢r�ÿ s’ÿ s”ÿ¢s’ÿ¢r�ÿ¢r‹ÿ¢rŠÿ¢s�ÿ¢t“ÿžr—ÿ�s›ÿšsŸÿšržÿšqšÿ›q—ÿ›o“ÿ™mŽÿ˜l�ÿ—kŒÿ—k�ÿ—jŒÿ–kŒÿ•jŽÿ”k‘ÿ“k”ÿ•m—ÿ”nšÿ“mšÿ’m™ÿ“n›ÿ“mšÿ”l—ÿ“l˜ÿ“l˜ÿ•l–ÿ”l–ÿ–k”ÿ•l’ÿ•k�ÿ–j�ÿ–j�ÿ—i�ÿ–i‰ÿ–i‰ÿ–jŠÿ–iˆÿ—i…ÿ–f}ÿ—ezÿ–cvÿ—cwÿ–dwÿ”cyÿ’byÿ‘ayÿ‘bzÿ�a|ÿ‘b~ÿ�b~ÿ’c|ÿ’b|ÿ’b}ÿ’c€ÿ’d‚ÿ”d†ÿ“e…ÿ•d‚ÿ•dÿ•d~ÿ•dÿ”cÿ”cƒÿ´•Ãÿ·–Àÿ¸–¿ÿ¹–¼ÿº–·ÿ»—¹ÿº–¹ÿº•·ÿ¹–»ÿ¸–Àÿ·—Áÿ¸•ºÿ¹“³ÿº’¯ÿ¼’¯ÿ»’¬ÿ»’­ÿ»’­ÿ¼’«ÿ»‘§ÿ¼�¥ÿ¼�§ÿ¼’§ÿ½’¨ÿ½“«ÿ»“­ÿ»‘«ÿº�¯ÿ¸�°ÿ¶�±ÿ´Ž°ÿ°Œ²ÿ±‹±ÿ±‹±ÿ°‹²ÿ±Œ´ÿ¯‹µÿ®‹³ÿ­Š³ÿ¯‰³ÿ­‰²ÿ®Š´ÿ¯Š²ÿ®‰°ÿ¯‰²ÿ¯Š³ÿ¯Š²ÿ°Š°ÿ±‰¯ÿ°Š°ÿ°Š±ÿ°‰²ÿ°Š²ÿ²Œ²ÿ´Œ°ÿ´Œ­ÿµŒ®ÿ¶�°ÿ¶Ž±ÿ¶Ž°ÿ·Ž³ÿµŽ´ÿµ�´ÿ·�°ÿº�°ÿ¹�°ÿºŽ¬ÿ»Ž¨ÿ»�£ÿ»�¥ÿ¼�¥ÿºŒ¡ÿ»�¡ÿ¼�£ÿ»�¡ÿ¼‹¡ÿ¼Œ¢ÿ»�¤ÿ¼�¦ÿ»�¤ÿ»Œ£ÿ»�§ÿº�©ÿ¹�¨ÿ¹Š£ÿ¹‰ ÿ¹‰Ÿÿ¹‰žÿ¸‰¢ÿ¶Š©ÿ´Š­ÿ³Š¯ÿ±Š¯ÿ±ˆ¬ÿ²‡©ÿ´‡¤ÿ³†¡ÿµ…Ÿÿ´„›ÿ´ƒ•ÿ¶„˜ÿ´„œÿ²„ ÿ´„Ÿÿ²�˜ÿ´€’ÿ³Žÿ³~�ÿ±~�ÿ³~�ÿ²|Šÿ±{ƒÿ±zƒÿ°yƒÿ°z…ÿ¯z†ÿ®x†ÿ¬w†ÿ«w‰ÿ«w‹ÿ¨x‘ÿ¦x’ÿ§v�ÿ©wŽÿ¨w�ÿ§vŽÿ¥tŒÿ¥u‘ÿ£t”ÿ¡t–ÿ¡t™ÿ¢u–ÿ¢s�ÿ¢tŽÿ¢t‘ÿ¤u”ÿ£v™ÿ¢vœÿžsœÿšrœÿ˜q›ÿ™o•ÿ™p”ÿšn�ÿšmŽÿ—l�ÿ—l�ÿ—k�ÿ—j‹ÿ˜kŒÿ–j�ÿ”k�ÿ•l•ÿ–n˜ÿ“m˜ÿ”m™ÿ“nšÿ“nšÿ”nšÿ•n˜ÿ•m–ÿ•n—ÿ–m–ÿ•m•ÿ•m–ÿ•l—ÿ–l•ÿ–l–ÿ–l•ÿ•k‘ÿ”i�ÿ–j�ÿ•j�ÿ•i‰ÿ–i‡ÿ•fƒÿ”d~ÿ”d|ÿ”d{ÿ’c}ÿ’c~ÿ�b~ÿ�b~ÿ‘a}ÿ�bÿ�cÿ‘cÿ‘cÿ�b~ÿ’d‚ÿ’dˆÿ“e‹ÿ“eŒÿ“eŠÿ”d…ÿ•e€ÿ•c}ÿ”c}ÿ•d�ÿ”eˆÿµ–Âÿ·–Àÿ¹–¾ÿº—ºÿ¼•´ÿ½•µÿ½•µÿ½–µÿ»•¸ÿ¹—½ÿ¹—Äÿº˜Äÿ¹–»ÿ»”´ÿ¼“±ÿ»”¯ÿ¼”¯ÿ½’­ÿ¼“«ÿ¾’©ÿ½‘§ÿ½’§ÿ¿‘¥ÿ½’§ÿ¾“©ÿ¾”¬ÿ¿“¨ÿ¾’¦ÿ½’©ÿ»‘¬ÿ¹�¯ÿ·�°ÿµ�±ÿ³�²ÿ²Ž³ÿ²�µÿ±�µÿ²Œ´ÿ°‹³ÿ¯‹²ÿ¯Š³ÿ®Šµÿ¯Š´ÿ°‹²ÿ°‹³ÿ°‹³ÿ¯‹´ÿ°‹³ÿ¯‹³ÿ¯Š´ÿ­‹µÿ­‹·ÿ­Š¸ÿ®‹¹ÿ¯Œ¶ÿ±Œ¶ÿ°Œ¶ÿ²�·ÿ´Ž¶ÿ´�²ÿ¶Ž¯ÿ¶Ž°ÿ´Ž²ÿ·�°ÿ¹�¯ÿ¹‘°ÿº�®ÿºŽªÿº�¦ÿ»Ž§ÿ»Ž§ÿ»Ž¦ÿ»�¨ÿ»ŽªÿºŽ©ÿ»Ž§ÿº�§ÿ»Ž©ÿ»Ž¨ÿ»�§ÿº�¥ÿ»�§ÿº�©ÿ¹Œ¦ÿºŒ¤ÿ¹‹¡ÿºŠŸÿ¹ˆ�ÿ¸ˆ¡ÿ¶‰©ÿµ‰­ÿ´Š­ÿ³‰ªÿ´ˆ¨ÿ´‡¦ÿµ†¢ÿ´†¡ÿµ„›ÿµƒ—ÿµ„–ÿ´ƒ˜ÿ´„žÿ³„£ÿ²„žÿ³‚•ÿµ€�ÿµ~Œÿ´~Œÿ´~Žÿ³}�ÿ²|Šÿ²{…ÿ±zƒÿ±z‚ÿ±y‚ÿ¯yƒÿ¯x…ÿ­x†ÿ¬w‰ÿ¬w‹ÿªx�ÿ©y’ÿ¨x‘ÿªx�ÿªx‘ÿ©wŽÿ§wŽÿ¦v‘ÿ¥u”ÿ¢v˜ÿ¡u™ÿ¢u—ÿ£u•ÿ¢u™ÿ¢w›ÿ£w�ÿ£xžÿ¢v�ÿ tœÿœsšÿ™p—ÿ™o”ÿ—n’ÿ—m�ÿ™mŽÿšm�ÿšm�ÿ™lŒÿ™lŠÿ›mŒÿ˜m�ÿ—n•ÿ•m–ÿ—n—ÿ–n—ÿ–n™ÿ–n›ÿ•nšÿ–n™ÿ˜n—ÿ—o–ÿ–n–ÿ–m”ÿ–m”ÿ–m—ÿ”mšÿ•mšÿ•m™ÿ•l—ÿ•j”ÿ”j’ÿ•k”ÿ•j�ÿ•i‹ÿ–iŠÿ”gˆÿ“f„ÿ”f„ÿ’eƒÿ’eƒÿ�d„ÿŽc…ÿŽc„ÿŽbƒÿŽcƒÿ�cƒÿ�d‚ÿ‘c‚ÿ“e„ÿ’eˆÿ’eŒÿ’g�ÿ“fŽÿ”fŒÿ”e„ÿ•dÿ–c{ÿ•d|ÿ”d~ÿ•dƒÿ¶–Âÿ¶—Áÿ¹—¿ÿº—»ÿ½—·ÿ¾—µÿ¿–³ÿ¾–µÿ½—¶ÿ¼—ºÿ¹—½ÿº˜ÃÿºšÄÿ»˜¼ÿ¼–¶ÿ¾•²ÿ¿”®ÿ¾”­ÿ¿“­ÿ½“ªÿ¾“©ÿ¾“¨ÿ¿’§ÿ¿’§ÿ¾”ªÿ¿”«ÿ¿“¨ÿ¿“¦ÿÀ“§ÿ¾“ªÿ½’¬ÿ»’®ÿ¹‘±ÿ·�²ÿ´�³ÿ´�³ÿ³Žµÿ³Ž´ÿ±Œ³ÿ²�´ÿ±Œ´ÿ°‹µÿ°‹µÿ°‹´ÿ¯‹´ÿ¯‹µÿ¯‹µÿ¯‹´ÿ°‹´ÿ¯Š´ÿ­Š¶ÿ¬‰¸ÿ«Š¼ÿ«‹½ÿ«‹½ÿ«Œ¾ÿ¬�¿ÿ­�½ÿ¯�¾ÿ²Œ·ÿµ‹­ÿµŒ®ÿ´Œ´ÿµ�³ÿµ�²ÿ¶�±ÿ¹�°ÿ¹�¬ÿºŽªÿºŽ«ÿº�ªÿºŽ«ÿº�­ÿ¹�°ÿ¹�°ÿºŽ«ÿºŽ©ÿºŽ¬ÿºŽªÿº�§ÿ»�§ÿ»�¥ÿ»�¤ÿ»Œ£ÿ»‹£ÿº‹¡ÿºŠ ÿ¹Š ÿ·‰¤ÿµŠ©ÿµŠ¨ÿµ‰¨ÿ¶‰§ÿµˆ¦ÿµ‡£ÿµ†¡ÿµ†žÿ´…™ÿµƒ—ÿ¶ƒ—ÿµ„šÿ³„Ÿÿ³„ ÿ²ƒ�ÿ´�”ÿ´€’ÿ²�ÿ²~�ÿ²~�ÿ±}Žÿ²|‰ÿ³|…ÿ³{„ÿ°z‚ÿ°y‚ÿ°xƒÿ¯x…ÿ®y‰ÿ­yŒÿ¬zŽÿ«z“ÿªz”ÿ«z”ÿ¬z’ÿªx�ÿ©x‘ÿ¨x�ÿ§w‘ÿ§x”ÿ¦x˜ÿ¥w˜ÿ£všÿ£v›ÿ¡wŸÿ¢x¢ÿ x¤ÿ¤x¡ÿ¢vœÿ¡u›ÿŸtšÿœr—ÿšo”ÿ—n‘ÿ—l‘ÿ˜m�ÿ™m�ÿ›mŽÿœm�ÿ›mŒÿšnŽÿ—o•ÿ—p™ÿ–n—ÿ˜n•ÿ—n—ÿ—pšÿ–oœÿ•nœÿ–m—ÿ™n•ÿšn•ÿ™n”ÿ—m’ÿ˜m“ÿ—m—ÿ•o�ÿ•o�ÿ“mšÿ”l—ÿ“l–ÿ“k–ÿ“k•ÿ•j‘ÿ–j�ÿ•i�ÿ”g‹ÿ“hŠÿ’g‹ÿ‘fŒÿ�e‹ÿ�eˆÿ�cˆÿŽcˆÿŽdˆÿ�d‡ÿ‘e„ÿ“e„ÿ“f…ÿ”fˆÿ”f‡ÿ“eŠÿ“f‹ÿ“f‹ÿ”f‹ÿ•eƒÿ–e~ÿ—e}ÿ–e|ÿ–e€ÿ–e�ÿ·—½ÿ¸—½ÿ¹—¾ÿº˜½ÿ¼˜ºÿ¾˜¹ÿ¿˜·ÿÀ™·ÿ¾™¹ÿ½™¹ÿ½™»ÿ»™¿ÿ»™Áÿ»šÂÿ½˜ºÿ¾–²ÿ¿–¯ÿ¿•­ÿÁ•¬ÿÀ•ªÿÀ•ªÿÀ”§ÿ¾“¥ÿ¿’§ÿÀ“§ÿ¾”©ÿ¿”©ÿ¿“¨ÿ¾“¦ÿ¿”©ÿ¿“«ÿ½”«ÿ¼”¯ÿ»“±ÿº‘²ÿ¸‘³ÿ·‘³ÿµ�´ÿ³Ž´ÿ²�´ÿ±Œ³ÿ±Œ´ÿ¯Œµÿ¯Œµÿ®‹¶ÿ®‹¶ÿ®‹´ÿ­Šµÿ®‹´ÿ­‹µÿ­Š·ÿ¬Š¹ÿ«‹¼ÿª‹¾ÿ«‹¿ÿ«Œ¿ÿ«�Áÿ¬ŽÂÿ­�Âÿ®Œ½ÿ°Œ³ÿ²Œ²ÿ²�¶ÿ³�ºÿ²�ºÿ³Ž¹ÿ´�¸ÿ¶�µÿ¸�¯ÿ¸�¯ÿ¹�¯ÿ¹�®ÿ¹�¯ÿ¹�°ÿ¹�¯ÿºŽ­ÿ»�®ÿ¹Ž®ÿºŽ«ÿ¹�¨ÿº�§ÿ»Ž§ÿ»�£ÿºŒ¢ÿº‹£ÿºŒ¤ÿ¹Š£ÿ¸Š¤ÿ·Š§ÿµ‹ªÿ´ˆ¦ÿ¶‰¦ÿµ‰¥ÿ´ˆ£ÿ¶‡¢ÿµ†Ÿÿ³…œÿ´…™ÿµ„˜ÿ´…˜ÿµ…žÿ´„ ÿ³„¡ÿ³ƒ�ÿ²�—ÿ²€•ÿ°–ÿ°•ÿ¯~“ÿ°}�ÿ²|Šÿ²|…ÿ²{ƒÿ²z„ÿ°yƒÿ°z†ÿ¯y‰ÿ®y‹ÿ¬z�ÿ¬z“ÿªz”ÿ«|–ÿ¬{•ÿ«z’ÿªy’ÿ©x“ÿ¨y’ÿ©y’ÿ¨x’ÿ¨y”ÿ¦yšÿ¥yœÿ£w›ÿ¡wŸÿ¢x¤ÿ¡z¦ÿ¢y¡ÿ£v™ÿ¢v˜ÿ t–ÿŸr–ÿ�q•ÿšo“ÿ˜n‘ÿ™o’ÿ™n‘ÿ›n‘ÿœn�ÿ›n‘ÿ™o“ÿ˜p™ÿ–pšÿ™p˜ÿ˜o–ÿ—o˜ÿ˜ošÿ–o�ÿ•nšÿ–n—ÿ™n•ÿ™o”ÿ™n“ÿ™n“ÿ™n“ÿ˜o–ÿ—ošÿ•n˜ÿ•l˜ÿ”k•ÿ“l•ÿ“k•ÿ’k–ÿ’j“ÿ”j’ÿ•i�ÿ“i�ÿ’i�ÿ‘g�ÿ�g�ÿŽe‹ÿ�eŒÿŽeŽÿŽdŽÿ�dŒÿ�fˆÿ’e†ÿ–f…ÿ•f†ÿ•g†ÿ•eƒÿ•f„ÿ”f‡ÿ”fŒÿ•f‹ÿ•f„ÿ–e€ÿ—eÿ—f€ÿ—e‚ÿ–e‚ÿ¹—»ÿº™½ÿ»š½ÿ»š½ÿ½š¼ÿ¾š»ÿ¾š»ÿ¿š»ÿ¾™ºÿ¿š»ÿ¾›¿ÿ¾œÁÿ¾›Àÿ¾›ÀÿÀ™ºÿÁ˜´ÿÀ—°ÿÁ—®ÿÁ–­ÿÁ–«ÿ–¨ÿ•¦ÿ•¤ÿ”¤ÿÁ”¥ÿ¿”§ÿ¿”ªÿ¿“ªÿ¿”ªÿ¿”«ÿ¿•­ÿ¾•®ÿ¾•°ÿ¾•±ÿ½•°ÿ¼”¯ÿº“¯ÿ¹’±ÿ·’´ÿµ�µÿ³�´ÿ±�µÿ°Œ·ÿ¯Œ¸ÿ®Œ·ÿ­‹¸ÿ¬Š·ÿ­Š¶ÿ­‰¶ÿ¬Š¶ÿ¬‰¶ÿ­‹¹ÿ­Œ¼ÿ¬‹¼ÿ­Œ¼ÿ¬�¾ÿ¬Œ¿ÿ¬ŒÀÿ­�Àÿ®Œ¼ÿ°‹¸ÿ°�·ÿ°Ž»ÿ°Ž¿ÿ°�Àÿ°�Âÿ°�¿ÿ²�½ÿ´�ºÿ¶�¹ÿ·�·ÿ¸�²ÿº�°ÿ¹�®ÿº�«ÿ¼�¬ÿ¼�­ÿº�®ÿ»�«ÿº�ªÿºŽ©ÿº�¨ÿºŒ¦ÿ¹Œ¥ÿ¹Œ¦ÿº‹¨ÿ¸Œ¨ÿ·‹©ÿ¶‹«ÿ¶Š©ÿ¶Š¦ÿ¶‰¦ÿ¶‰¤ÿ¶ˆ¢ÿ´†¡ÿ´…Ÿÿ³…Ÿÿ³„žÿµ„œÿµ…�ÿ´†¡ÿ²…£ÿ²†¦ÿ²„£ÿ±‚Ÿÿ±‚žÿ¯��ÿ®€›ÿ°~™ÿ¯~•ÿ°~‘ÿ°|Œÿ±|ˆÿ°{‰ÿ°zŠÿ¯{‹ÿ®zŒÿ¬z�ÿ«z“ÿ«|—ÿª}™ÿ«}˜ÿ«|–ÿ«z–ÿ«{–ÿª{—ÿªz–ÿªy”ÿªy’ÿ«{—ÿ©{žÿ¨zžÿ¦y›ÿ¥yœÿ¢y ÿ¢y¤ÿ£y¡ÿ£w›ÿ¡u—ÿ¢u–ÿ¡t•ÿŸs•ÿ�r•ÿ›q•ÿ›p•ÿšp”ÿ›o“ÿ›p•ÿ›q–ÿšq™ÿ™r�ÿ˜q�ÿ™qšÿ™q™ÿ™p™ÿ˜pšÿ˜p›ÿ–o˜ÿ–n–ÿ™m”ÿ™n“ÿ›n‘ÿœp’ÿœp‘ÿœp•ÿšo‘ÿ™lŒÿ˜lŽÿ—k�ÿ•k“ÿ“l–ÿ’k”ÿ’j”ÿ“j”ÿ“k“ÿ“j’ÿ’i‘ÿ�gŽÿ�fŒÿ�eŠÿ‘fŒÿ�eŽÿŽfŽÿ‘g�ÿ“gŒÿ•h‹ÿ—h‰ÿ—h‡ÿ–gƒÿ–g�ÿ—gƒÿ–f‡ÿ•g�ÿ•g‹ÿ•g†ÿ—g…ÿ—gƒÿ˜f€ÿ—e}ÿ˜e~ÿ¹˜»ÿº˜½ÿ½š½ÿ½š¾ÿ¾›½ÿ¿›¼ÿ¿œ¾ÿ¿›¼ÿÀ›»ÿÁ›»ÿÀ›¾ÿ¿œÀÿ¿œ¿ÿÀœ¾ÿ›»ÿÁ™µÿ˜±ÿ˜±ÿÁ—®ÿØ­ÿÄ—§ÿÖ¥ÿÄ–¤ÿÄ–¢ÿÕ¢ÿÕ¦ÿ–©ÿ•«ÿ–­ÿÀ•¬ÿÀ–­ÿÀ•­ÿ¾•¯ÿ¾•°ÿ¾•°ÿ¾•¯ÿ¾”­ÿ½“­ÿ»’®ÿ¹’±ÿ¸‘µÿµ�¶ÿ²�¸ÿ°Ž¹ÿ®Œ¸ÿ­Š¸ÿ¬Š¸ÿ¬‹¹ÿ¬‹·ÿ¬Š·ÿ¬‰¶ÿ­Š·ÿ®Œºÿ¯�ºÿ°�»ÿ¯�½ÿ¯Ž¾ÿ¯Ž¾ÿ®�½ÿ°�»ÿ¯�»ÿ°�»ÿ¯�¾ÿ¯�Ãÿ¯�Åÿ¯�Æÿ°�Åÿ°�Äÿ°�Ãÿ±‘Ãÿ´’Áÿ·‘»ÿ¹’¶ÿ»‘±ÿ»�­ÿ¼�«ÿ½�©ÿ¾Ž¦ÿ¼�¦ÿ»Ž©ÿº�ªÿº�ªÿ¹Ž©ÿ¹Ž«ÿ¸�¬ÿ·Ž¬ÿ·Œ«ÿ¸�¬ÿ·‹©ÿ·‹¦ÿ·‰¤ÿ¸Š¢ÿ¸‰¡ÿ¶‡¡ÿ¶‡¡ÿµ†¡ÿ³†£ÿ±†¢ÿ³†£ÿ´‡¤ÿ³†¦ÿ²‡ªÿ²‡¬ÿ±†§ÿ±…¦ÿ¯„¥ÿ®‚£ÿ­�¡ÿ®� ÿ­€žÿ®˜ÿ°}“ÿ°}Œÿ°|�ÿ¯}Žÿ®{�ÿ¬{‘ÿ­|•ÿ«{•ÿ«}šÿ«}�ÿ«}›ÿ«{—ÿª{—ÿª{™ÿ¨{šÿ©{›ÿªy–ÿªy’ÿª{—ÿª|œÿ©z™ÿ©{™ÿ§z›ÿ¦zžÿ¦z¡ÿ¥{¡ÿ¤xžÿ¡v›ÿ¢u›ÿ¢u–ÿ u•ÿžr–ÿœq–ÿ›r˜ÿœq™ÿ›q™ÿšqšÿšr›ÿ™r�ÿ™rŸÿ˜qžÿ™qœÿšqšÿšqšÿšr›ÿ˜o™ÿ˜n–ÿ˜m“ÿ™n“ÿ›o“ÿ�o�ÿ qŽÿ¡q�ÿžoŽÿ�m‰ÿœl…ÿšj…ÿšk‡ÿ™l�ÿ–m•ÿ”j“ÿ“j”ÿ“k•ÿ•l”ÿ•k’ÿ’j�ÿ‘gŒÿ‘eŠÿ‘fŠÿ‘fŠÿ‘gŒÿ’g�ÿ”iŽÿ–j�ÿ˜j�ÿ˜k�ÿ—i‡ÿ˜h„ÿ˜h„ÿ˜hˆÿ—h‹ÿ–i�ÿ•h‹ÿ•g‹ÿ•g‹ÿ•g‰ÿ•f‡ÿ—e‚ÿ–e}ÿº˜½ÿ»š¾ÿ½š¿ÿ½›¾ÿ¿œ¾ÿ¿œ¿ÿÀžÂÿÁžÀÿœ½ÿœ»ÿÁ›»ÿÁ�¿ÿÀ�¿ÿÁœ¾ÿœ½ÿÛµÿÚ±ÿÙ°ÿÙ¯ÿÙ¯ÿĘ«ÿبÿئÿÅ—¤ÿÅ–¢ÿÅ•£ÿÖ§ÿ–ªÿ–©ÿÖªÿ—©ÿשÿÁ–ªÿ¿–®ÿ¿–°ÿ¾•®ÿ¿•¬ÿ¿”«ÿ¾“ªÿ¾’«ÿº’­ÿ¸’´ÿ´�¸ÿ²Ž¸ÿ±Ž¹ÿ¯�¸ÿ­‹¹ÿ¬‹¹ÿ¬‹¸ÿ«‹·ÿ¬Šµÿ®‹¶ÿ®‹¸ÿ¯Œ¸ÿ±Žºÿ²�»ÿ²�»ÿ°Ž¼ÿ°Ž¼ÿ¯�ºÿ°�»ÿ¯Ž½ÿ¬ŽÀÿ¯�Æÿ®�Èÿ­‘Éÿ®‘Éÿ¯�Èÿ®�Èÿ¯�Êÿ¯�Éÿ²’Âÿ·’½ÿ¹‘µÿº�¬ÿ¼�ªÿ½�¨ÿ¼�§ÿ¼�¨ÿ»�ªÿº�«ÿº�«ÿ¹Ž­ÿ·Ž­ÿ·Ž±ÿ·�¯ÿ¶Œ¬ÿ·Œ«ÿ¸Œ©ÿ·‹¥ÿ¸Š£ÿ·‰¢ÿ·‰£ÿµˆ£ÿ¶ˆ¤ÿ´ˆ£ÿ²†¤ÿ²†§ÿ±‡©ÿ²‡«ÿ²ˆ¯ÿ±ˆ°ÿ±‰¯ÿ²‡¬ÿ±†ªÿ®…ªÿ°„©ÿ®‚¦ÿ«�¢ÿ¬�ÿ­~˜ÿ®~”ÿ°}�ÿ¯|�ÿ¯|’ÿ®}”ÿ­|•ÿ«|–ÿ¬}–ÿ­~šÿ«~�ÿª~œÿ«}šÿ©|™ÿ¨{™ÿ©{›ÿ¨{šÿ©z—ÿªy‘ÿ©z’ÿ©{•ÿª{•ÿ©{—ÿ¨{›ÿ¨|�ÿ§|žÿ¦{Ÿÿ¥yžÿ£wœÿ¢v›ÿ¢u›ÿ¡u˜ÿ�t˜ÿœsšÿ›s�ÿ™ržÿšrŸÿ˜ržÿ˜rœÿ™rŸÿšrŸÿ˜ržÿšržÿšržÿšrœÿšršÿšp–ÿ™o“ÿ™n’ÿšo’ÿœp‘ÿ qŒÿ¡pŠÿ q‹ÿŸoˆÿŸlƒÿ�l�ÿ›kÿ›k„ÿ™l�ÿ—m”ÿ•l•ÿ”m–ÿ”l–ÿ•k”ÿ”k‘ÿ“hŽÿ‘g�ÿ’gŽÿ’h�ÿ’h�ÿ“i�ÿ”j�ÿ•k�ÿ—l�ÿ–kŽÿ—k�ÿ—j�ÿ˜iˆÿ™i‰ÿ—i‹ÿ•iŽÿ–j�ÿ”i�ÿ”hŽÿ“h�ÿ”h�ÿ“gŒÿ•g…ÿ—e‚ÿ¼šÂÿ¼›Ãÿ½œÅÿ¾œÁÿ¾�ÀÿÁ�ÁÿÀžÁÿž¾ÿÄ�ºÿÃ�ºÿÄ�ºÿÄž½ÿÞ¾ÿÞ¼ÿÅ�ºÿÄœ¶ÿÅœ³ÿÅ›±ÿÆ›°ÿÄ›°ÿÅš°ÿÅ™¬ÿÅš¨ÿÅ™§ÿÆ™¦ÿƘ¤ÿاÿĘ«ÿĘªÿשÿשÿÄ—¨ÿÖ§ÿ—©ÿ—¬ÿÀ–­ÿÀ•ªÿ¿–«ÿ¿•«ÿ¿•¬ÿ½”­ÿº“°ÿ·’´ÿ´‘·ÿ²�·ÿ±Ž¸ÿ°Œºÿ®Œ¹ÿ¬‹¹ÿ«‹¸ÿ­‹·ÿ¯‹·ÿ¯‹·ÿ¯Œ¶ÿ±�¸ÿ²Ž¸ÿ²Ž·ÿ²Ž¹ÿ²Ž¹ÿ²Ž¹ÿ°�ºÿ±�½ÿ°’Äÿ¯‘Éÿ­’Íÿ¬“Íÿ­’Îÿ®‘Ëÿ®‘Ëÿ­’Ëÿ®‘Êÿ°�Äÿµ‘¿ÿ¹‘¶ÿº�«ÿ»�ªÿ»�­ÿ»‘¯ÿ»‘¯ÿ»‘®ÿº‘­ÿº‘¯ÿº‘²ÿ¸�³ÿ·�´ÿ¶Ž³ÿ¶�®ÿ¶Œ­ÿ¶Œ¬ÿ¶‹©ÿ·Š¦ÿ¶Š¦ÿµŠ¨ÿ´Š©ÿ³‰¨ÿ´ˆ§ÿ³‡¨ÿ²ˆ­ÿ¯‰±ÿ®‰´ÿ¯ˆµÿ°‰°ÿ°ˆ­ÿ²ˆ­ÿ±†ªÿ°…©ÿ°„©ÿ®‚¢ÿ­��ÿ®šÿ¯}•ÿ¯~”ÿ®~”ÿ®}”ÿ­}–ÿ®~˜ÿ®~šÿ­~™ÿ®~—ÿ®~˜ÿ­~šÿ¬}šÿ¬|˜ÿª|™ÿª{šÿª{™ÿ©z™ÿ©{—ÿ«{–ÿ«|–ÿ«{˜ÿª{™ÿ¨z˜ÿª{šÿ©{šÿ©|›ÿ¨}�ÿ§zžÿ¥yžÿ¢w�ÿ¢vœÿ vœÿ�u›ÿšsžÿ˜sŸÿ˜sŸÿ˜rŸÿ™r�ÿ—qžÿ˜q ÿ˜r ÿ™ržÿ˜ržÿ™ržÿšr›ÿœršÿœp–ÿ›o“ÿœo‘ÿŸq�ÿ¡q‹ÿ¢o‡ÿ¢p†ÿ¡o‡ÿŸn„ÿŸmÿŸl}ÿœlÿšl…ÿ˜k�ÿ—l“ÿ•l–ÿ•m–ÿ•k•ÿ–l”ÿ–j’ÿ“i‘ÿ”i‘ÿ“i“ÿ’k•ÿ“k•ÿ”k”ÿ•k‘ÿ–k�ÿ—k�ÿ—kŽÿ˜l‘ÿ˜l�ÿ—kŽÿ˜jŽÿ—k�ÿ–k‘ÿ•k“ÿ”j“ÿ”j’ÿ“j”ÿ“i“ÿ”h�ÿ”g‡ÿ•g†ÿ¼œÇÿ»œÆÿ¼�Çÿ½�ÇÿÀ�ÃÿÁž¾ÿž¾ÿÞ¼ÿÅž¹ÿÅž¹ÿÅž¹ÿÅž¹ÿÆŸ¹ÿÇžºÿÅ�¹ÿÆ�¶ÿÇ�´ÿÇ�³ÿÆœ°ÿÇ›®ÿÆš¯ÿÆš®ÿÆš¬ÿÆšªÿÇ™©ÿÆšªÿÆš¬ÿÅš®ÿÆ™¬ÿŘ©ÿʨÿÄ—§ÿÄ–¦ÿÖ§ÿרÿÁ—«ÿÁ–ªÿÁ•¬ÿÀ–®ÿ¾–¯ÿ¾–°ÿ½•°ÿ»”³ÿ¹”·ÿ·“ºÿ´‘»ÿ²�»ÿ°�¹ÿ®Œ¸ÿ­‹¸ÿ®‹¹ÿ®‹¹ÿ®Œ¸ÿ°�¹ÿ°�¹ÿ²Ž¹ÿ³Ž·ÿ´�¶ÿ´Ž·ÿ´�·ÿ³�¹ÿ³‘¾ÿ²”Ãÿ±•Éÿ®•Îÿ­”Òÿ­“Ðÿ­’Íÿ­’Ëÿ®‘Ëÿ¯�Éÿ¯�Ãÿ²�½ÿ·�´ÿ»�¬ÿº�«ÿº‘³ÿº‘µÿ»‘³ÿ¼’²ÿ¼’²ÿ»‘±ÿº‘´ÿ¹‘·ÿ¸�·ÿ·�³ÿ·Ž²ÿ¶�±ÿ¶�±ÿ¶Œ¯ÿµŒ«ÿµŒ¬ÿµŒ¯ÿµ‹°ÿµŠ®ÿ´Š¬ÿ³‰®ÿ±Š´ÿ®‹¹ÿ­‰»ÿ¬Š¹ÿ¯ˆ±ÿ±‡¬ÿ²‡«ÿ²‡§ÿ±„£ÿ°„¥ÿ°‚žÿ°��ÿ°�œÿ¯˜ÿ®~˜ÿ¯€˜ÿ¬~™ÿ­œÿ«�ÿ­�ÿ®~šÿ¯—ÿ®}—ÿ®šÿ¬~›ÿ«~œÿ«~œÿª|šÿª{šÿ«|šÿª{šÿª|œÿª|žÿ«|œÿª{–ÿª{•ÿ©{—ÿª|˜ÿ©}�ÿ©}Ÿÿ§|Ÿÿ¥y ÿ¢wŸÿ wŸÿŸvŸÿ�u ÿ›u¡ÿ˜r¢ÿ—r ÿ˜sžÿ˜r�ÿ˜qŸÿ–r¢ÿ—r¢ÿ—r ÿ˜ržÿ˜q�ÿšrœÿ›q›ÿœr™ÿ�q”ÿžp�ÿ p‰ÿ£q‡ÿ£p…ÿ£p‡ÿ¢p‡ÿ m‚ÿ¡m~ÿ m~ÿœl‚ÿ™lŠÿ˜l�ÿ–l‘ÿ•l”ÿ–l•ÿ—l”ÿ•l’ÿ–k•ÿ”j”ÿ”j“ÿ”j”ÿ”l–ÿ”l–ÿ•k”ÿ–l’ÿ—l�ÿ—kŽÿ™l‘ÿ˜l“ÿ˜m”ÿ˜m“ÿ—k’ÿ—k‘ÿ—l“ÿ–l•ÿ”j”ÿ•j•ÿ•j•ÿ”i“ÿ”h�ÿ”g‹ÿ’g�ÿ»žÉÿ½žÊÿ¾žÉÿ¼žÈÿ¾žÃÿÀž¿ÿÃ�¼ÿÄž»ÿÄž¹ÿÅž¹ÿÅžºÿÆž¹ÿÆŸ¸ÿÆŸ¹ÿÇž¹ÿÇž¸ÿÆžµÿÈž±ÿÉž¯ÿÈœ«ÿÈœªÿÈœ­ÿÆœ¯ÿÈœ­ÿÈœ¬ÿÈœ­ÿÇœ±ÿÆœ±ÿÇš¬ÿÅ™¨ÿƘ¨ÿʧÿʦÿÄ—¨ÿ×§ÿĘ©ÿÄ—¨ÿ–©ÿÁ–­ÿÀ–¯ÿ¾–°ÿ¾–±ÿ¼–´ÿ»•´ÿ¹•¶ÿ·“¸ÿ´’¸ÿ³�·ÿ±Ž·ÿ°Œ·ÿ¯Œ¸ÿ¯�¹ÿ­�ºÿ®Ž¼ÿ¯�¼ÿ°Ž»ÿ²Ž¹ÿ³�·ÿµ�·ÿ¶‘¶ÿ¶‘¹ÿµ’¼ÿ´”¿ÿ³”Äÿ±•Ëÿ¯–Ðÿ®”Ðÿ­“Ïÿ¬“Íÿ­’Ëÿ¯’Éÿ®�Ãÿ°�Áÿ³�»ÿ·�´ÿ¹‘´ÿº’·ÿ¹‘µÿº’³ÿ»’³ÿº’²ÿº‘±ÿº’µÿ·’¹ÿ·’¸ÿ·�µÿ¶�µÿ¶�´ÿµ�µÿ´�³ÿµ�±ÿµ‹®ÿ³‹­ÿ´‹«ÿ´Š©ÿ²Š­ÿ°Šµÿ®‹¹ÿ­‹¾ÿª‹Àÿ«‹¿ÿ®‰³ÿ°†«ÿ²‡«ÿ³‡¥ÿ²„Ÿÿ±ƒŸÿ±�œÿ°�žÿ¯��ÿ¯€šÿ­™ÿ®šÿ­~šÿ¬žÿ¬€ ÿ¬€Ÿÿ®šÿ®~–ÿ®}–ÿ®Ÿÿ¬¡ÿª~¢ÿª~ ÿª}�ÿ©}�ÿ©}�ÿ©} ÿ©}£ÿ©~¢ÿ©|™ÿ«{—ÿ«{–ÿ©{–ÿ¨|›ÿ¨| ÿ¨| ÿ¨|¢ÿ¥{¡ÿ£y¡ÿ w¡ÿžw¢ÿœu¡ÿ›t¡ÿ˜sŸÿ–ržÿ—sžÿ—q�ÿ–qžÿ—r£ÿ–r¢ÿ–ržÿ—p›ÿ˜q›ÿ™sœÿ›s�ÿœsšÿžr•ÿ rŽÿ¡q‰ÿ¢q‡ÿ¢p‡ÿ¡p†ÿ o…ÿ m�ÿ¡m~ÿŸm�ÿœl†ÿšmŒÿ—l�ÿ•l‘ÿ–l“ÿ—k’ÿ—m“ÿ—m“ÿ–m”ÿ–m•ÿ•j“ÿ•l”ÿ”l”ÿ•l“ÿ•l‘ÿ–l‘ÿ˜l‘ÿ˜m‘ÿ™m“ÿ™m–ÿ™n—ÿ˜n•ÿ™l“ÿ˜l“ÿ—m“ÿ–l•ÿ–l–ÿ”j”ÿ•j”ÿ”k•ÿ“j“ÿ“i’ÿ“i“ÿ½ŸÊÿ½ŸÊÿ¿ŸÉÿ¾ŸÉÿÀŸÆÿÁŸÃÿŸÁÿÄŸ½ÿÅžºÿÅžºÿÅž¹ÿÆŸ¹ÿÆž¸ÿÆŸ¸ÿÇŸ¹ÿÇŸ¸ÿÈŸµÿÉŸ°ÿÉ�­ÿÊ�§ÿÊœ¤ÿÊ�«ÿÈž®ÿÈž­ÿÉž®ÿÈ�¯ÿÈ�²ÿÈ�°ÿÈœ¬ÿÈš§ÿÈš§ÿÆš§ÿÆš§ÿÆšªÿÆšªÿÅšªÿÆ™¦ÿÅ™¦ÿÄ—¨ÿ׫ÿ¿—¯ÿ¾˜³ÿ¾—µÿ½–µÿ»–µÿ»•µÿ¹“µÿ·’¶ÿµ�¶ÿ³�·ÿ±Ž¸ÿ¯Žºÿ®Ž½ÿ®�¾ÿ¯Ž¼ÿ°Ž»ÿ²�ºÿ³�¹ÿ´�·ÿ¸”¸ÿ¸”¹ÿ·•ºÿ·”¼ÿ¶”Áÿ³–Êÿ±—Îÿ±•Ïÿ¯”Ïÿ®•Ïÿ®”Îÿ¯’Êÿ¯‘Åÿ¯�Äÿ°ŽÀÿ±Ž¼ÿµ‘¼ÿ¸“ºÿº’¸ÿº“¶ÿ»’³ÿ»’±ÿº‘²ÿ¹“·ÿ·“»ÿ¶’»ÿµ‘½ÿ´‘»ÿ´�»ÿ´�ºÿ´Ž·ÿ´Ž´ÿ´‹°ÿ´‹«ÿ´Š©ÿ³Š«ÿ²‹±ÿ°‹¸ÿ®Š¹ÿ«‹Àÿ¥‡Áÿ©ŠÀÿ­‰µÿ°ˆ¯ÿ±‡¬ÿ²†¥ÿ²„ ÿ²ƒŸÿ±‚�ÿ±„žÿ°‚žÿ¯‚�ÿ®� ÿ­� ÿ®€žÿ­�Ÿÿ¬�£ÿ¬€£ÿ­€žÿ­~™ÿ­œÿ¬€¢ÿ¬�¥ÿ«€¦ÿª¤ÿª£ÿ«~£ÿª~Ÿÿª¡ÿª~£ÿ©}Ÿÿ¨}�ÿª}žÿª|�ÿ©|œÿ¨}¡ÿ§|£ÿ§}¤ÿ§}¤ÿ¥{¤ÿ¤z£ÿ¢z£ÿ x¢ÿŸvžÿžtšÿžs›ÿ™s�ÿ˜qœÿ˜qœÿ—rŸÿ˜r ÿ˜ržÿ—rœÿ˜q™ÿ™q™ÿšs�ÿœtœÿžt˜ÿŸs“ÿ r�ÿ¡qŒÿ¡q‹ÿ¡pŠÿ oˆÿ o„ÿ n‚ÿ¡o‚ÿ o†ÿœo‰ÿ›n�ÿ˜m‘ÿ–m“ÿ™m”ÿ—l“ÿ™m’ÿšn’ÿ™n’ÿ—l’ÿ–l’ÿ–l’ÿ–l’ÿ˜l’ÿ˜l�ÿ˜l�ÿ™n“ÿ™n•ÿ˜n—ÿ˜n˜ÿ˜o˜ÿ—n—ÿ˜m•ÿ™m•ÿ˜o–ÿ–m—ÿ–m˜ÿ•m–ÿ•m–ÿ”k—ÿ“k–ÿ’j—ÿ‘j—ÿ½ŸÊÿ¿ŸËÿ¿¡ÌÿÀ ÊÿÁ Æÿ ÅÿàÄÿÄ ÀÿÄ ¼ÿÆŸ»ÿÆŸ¹ÿÆŸ·ÿÆŸ¶ÿÇž·ÿÇŸ·ÿÇ ¶ÿÉ µÿËŸ¯ÿËžªÿÌž¦ÿÌ�¥ÿÌž§ÿÌž§ÿË�§ÿÊŸ­ÿÊž²ÿÉž±ÿÉž°ÿÉ�«ÿÊœ¥ÿÉœ¦ÿÉœ¨ÿÉ›©ÿÈœ«ÿÈœ¬ÿÇœ¬ÿÆš©ÿÈ™¦ÿÆ™¥ÿƘ§ÿŘ«ÿÁ˜°ÿÀ˜´ÿ¾—µÿ½–¶ÿ»•µÿ»”´ÿº”³ÿ¸“´ÿ¶’¶ÿ´‘¸ÿ³�ºÿ²�½ÿ°Ž¼ÿ±Žºÿ²�»ÿ´‘ºÿ³‘ºÿµ‘¹ÿ·’·ÿ¸”·ÿ¸“¹ÿ¹–½ÿ¹—Àÿ¶™Ëÿ¶—Ëÿµ—Èÿ´—Éÿ²–Ìÿ±–Ìÿ²”Êÿ²”Éÿ±’Çÿ¯�Äÿ¯ŽÃÿ°�Ãÿµ’Àÿ¶’½ÿ¹“¹ÿ¹’¶ÿº’µÿº’µÿº’¸ÿ¸“¼ÿµ’Àÿ´“Áÿ´’Âÿ³�Àÿ³�¿ÿ³Žºÿ´�·ÿ³‹±ÿ´‹°ÿ²‹±ÿ°‹µÿ°Œ¼ÿ°�¼ÿ®‹¹ÿ‘s ÿ5"1ÿtX{ÿ®‰´ÿ¯‡°ÿ°‡«ÿ±„¤ÿ²„¡ÿ±„¡ÿ±„¡ÿ°„¡ÿ°„¡ÿ°ƒ£ÿ®ƒ¥ÿ­‚£ÿ­� ÿ­�¡ÿ­�¥ÿ­€¢ÿ¬€Ÿÿ­€ ÿ¬€£ÿ¬€¤ÿ¬€¤ÿ¬�§ÿ«�©ÿ«�©ÿª¤ÿª~žÿª~Ÿÿ«~Ÿÿª~ ÿª~¡ÿª~£ÿ©~¤ÿ¨~¦ÿ§~§ÿ§|¤ÿ§}¤ÿ¦}¤ÿ¥|¥ÿ¤{§ÿ£{¥ÿ£y£ÿ£xšÿ£v—ÿ¡u˜ÿ t˜ÿ t˜ÿœršÿœs›ÿ›s›ÿ›ršÿ›r›ÿ›r›ÿ�tœÿžsœÿŸsšÿ t—ÿ t•ÿ¢s‘ÿ¢s�ÿ¡rŽÿ q�ÿ p‰ÿŸo†ÿ¡o…ÿ o†ÿŸoŠÿœo�ÿ›p“ÿšo•ÿ™m•ÿ—m•ÿ™m•ÿšo“ÿ›n�ÿšn�ÿ˜m‘ÿ˜m’ÿ˜m’ÿ˜m“ÿ™m“ÿœo’ÿ›o”ÿšp˜ÿšq›ÿ—o�ÿ•o�ÿ”n�ÿ•n�ÿ—nšÿ˜pšÿ—n™ÿ˜n™ÿ–mšÿ•mšÿ”mšÿ•lšÿ“l›ÿ‘l›ÿ‘lžÿ½ Ìÿ½¡Íÿ¾¡Íÿ¾¡ËÿÀ ÇÿÁŸÅÿáÃÿÄ¡ÀÿÅ ¾ÿÆ ½ÿÆ ¹ÿÇŸ¸ÿÇŸ¹ÿÇ ¸ÿÇŸµÿÈŸ¶ÿÉŸ²ÿÊŸ­ÿËž¨ÿËž¥ÿÍŸ¥ÿÍž¢ÿΜŸÿÍ� ÿÍž£ÿÌŸ«ÿËŸ°ÿÊŸ¯ÿÊž«ÿÊœ¦ÿÊœ§ÿÊœ¨ÿÊœªÿÉ�¬ÿÈœ¬ÿÈœ¬ÿÈœ¨ÿÈš¥ÿÈš¥ÿÇ™¦ÿÆ™¨ÿÅ™«ÿØ®ÿÁ˜°ÿ¾—³ÿ¼—´ÿ»–³ÿ»•³ÿ»”³ÿ¹“³ÿ¸’´ÿ·’·ÿµ‘¸ÿ³�¶ÿ´�·ÿ³�¸ÿ³�¹ÿ³�¸ÿ²�¶ÿ´�µÿ¸’¶ÿ¹”»ÿ¹–¼ÿ¹—Àÿ¸™Åÿ¸˜Ãÿ¹˜Äÿ·˜Åÿµ—Æÿµ—Èÿ´–Éÿ²•Èÿ³”Çÿ²“Æÿ±“Çÿ®‘Çÿ¯�Æÿ±‘Äÿ´’¿ÿ·’»ÿ·’¸ÿ¸’·ÿ¸“·ÿµ“½ÿ´’Äÿ²“Åÿ²’Äÿ²’Äÿ³�Áÿ±�»ÿ±Ž¹ÿ±�¸ÿ°Œ·ÿ®�¾ÿ­�Âÿ¬�Ãÿ­�¿ÿ­Œ¼ÿ¡†¼ÿB-Bÿšy¨ÿ®‰µÿ­ˆ°ÿ¯†«ÿ°„¥ÿ°„¤ÿ°„¦ÿ¯„¤ÿ°…¤ÿ°…¥ÿ¯…§ÿ®„§ÿ®‚¢ÿ®‚¡ÿ¬‚¢ÿ­‚¤ÿ®�žÿ®��ÿ¬�¢ÿ­�¦ÿ¬�£ÿ¬€¡ÿ¬�¥ÿ«�¦ÿ¬�£ÿ«€ ÿ¬€�ÿ«�ÿ«~ ÿ©£ÿ©¤ÿª¨ÿ©€ªÿ¨¨ÿ©¨ÿ§}£ÿ§}¢ÿ¦}¤ÿ¦}§ÿ¥|¨ÿ¥|¥ÿ¥y ÿ¥x˜ÿ§x”ÿ¥w“ÿ¤v”ÿ£u–ÿŸu˜ÿ�s˜ÿœtšÿœsšÿœs›ÿ�u�ÿ�užÿŸu�ÿ u›ÿ t™ÿ¡t—ÿ¡s”ÿ¡r“ÿ r’ÿŸr�ÿŸp�ÿžp‹ÿŸoŠÿ p‹ÿžp�ÿœp’ÿšp–ÿ™p˜ÿ™p˜ÿ™o–ÿ™n“ÿ›n’ÿšn’ÿ™o”ÿ˜m”ÿ˜m“ÿ˜n“ÿšo“ÿ›n’ÿ›o“ÿ›p–ÿšq�ÿ—q¡ÿ•p¢ÿ“o¢ÿ”p£ÿ”p¢ÿ–q¡ÿ—pŸÿ–pšÿ–oœÿ•ožÿ”nŸÿ”n¡ÿ“m¡ÿ’m¢ÿ’m¤ÿ�l£ÿ¼ Ìÿ½ Ëÿ¾¡Îÿ¾¢Ðÿ¿¢Íÿ¢ÈÿâÄÿÄ¡ÁÿÆ¡¿ÿÆ¡¿ÿÇ¡¼ÿÇ ºÿÇ ¸ÿÇ ·ÿÈ¡·ÿÈ ¶ÿÈ µÿÉŸ¯ÿÊž¨ÿË�£ÿÌž¢ÿÍž¡ÿΞžÿÏž�ÿÏŸžÿÍž¡ÿÌžªÿÌŸ­ÿËŸ®ÿËž«ÿÌž¨ÿË�§ÿÊ�¨ÿÊ�«ÿÉ�«ÿÉ�¬ÿÉœ¨ÿÉ›¥ÿÉ›¦ÿÉ›§ÿÇ›§ÿÆš¨ÿÆš«ÿÙ«ÿ˜¬ÿÁ—­ÿ¿–®ÿ½–±ÿ¼–²ÿ»•²ÿº”³ÿº”µÿ¹“³ÿ¸’¯ÿ¸‘±ÿ¶‘µÿµ’·ÿ³�¸ÿ¯Œ·ÿ±Ž¸ÿ´‘»ÿ·•Àÿ¸—Áÿ¹˜Äÿº˜Áÿº˜Àÿ¹™Ãÿ¹™Ãÿ¸˜Âÿ·˜Æÿ¶˜Ëÿµ—Ìÿ´–Éÿ´–Éÿ³–Êÿ±’Èÿ®�Æÿ­‘Çÿ¯‘Æÿ³’Âÿ³‘¿ÿ´’¾ÿ´’½ÿ³’Âÿ°’Èÿ°’Ëÿ°‘Çÿ±‘Æÿ±�Âÿ°�¿ÿ°�¿ÿ¯Ž¿ÿ­�ÀÿªŽÇÿ©ŽÊÿ©�ÇÿªŒÆÿ©ŽÆÿ®”ÔÿI5Lÿ­‘Ðÿ«Šºÿ­ˆµÿ¯†­ÿ°†¨ÿ¯†¨ÿ°…¨ÿ°†¨ÿ°…¦ÿ±…¦ÿ°…¦ÿ®„£ÿ¯ƒ¡ÿ®‚¡ÿ­‚£ÿ®‚¡ÿ­�žÿ¬‚¡ÿ¬‚¦ÿ«‚§ÿ¬‚¤ÿ¬€¢ÿ­�¥ÿ¬�¥ÿ­�¥ÿ¬€ ÿ¬€žÿ«žÿª¡ÿ©~¤ÿ§§ÿ¨€­ÿ¨€©ÿ¨~§ÿ¨~¦ÿ§}¤ÿ¦|¢ÿ§}¥ÿ¥}¥ÿ¦|£ÿ¦{ ÿ¦zœÿ§y–ÿ¨x”ÿ¨x“ÿ¦x“ÿ¤v•ÿ u˜ÿžu›ÿœužÿžu�ÿ�t›ÿ�tœÿžvžÿ wŸÿ¡v ÿ wžÿ v™ÿ¡t˜ÿ¡s—ÿžs–ÿŸs–ÿ�q”ÿœp‘ÿžp�ÿžp�ÿœp’ÿšq–ÿ™q™ÿ˜q›ÿ˜qšÿ™p˜ÿšp–ÿ™p•ÿšo–ÿ—o˜ÿ–n—ÿ™o˜ÿ™o—ÿ›p•ÿšo”ÿ›p•ÿšq˜ÿ˜rŸÿ–q¤ÿ”r¦ÿ•r¦ÿ•r¥ÿ–r¦ÿ–r¥ÿ–q¡ÿ•pžÿ”p ÿ’p¥ÿ‘p¨ÿ‘n¨ÿ‘o¨ÿ�o¨ÿ�o¨ÿ�n¨ÿ½ Êÿ¾ Êÿ¾¡ËÿÀ¡ÌÿÀ¢ÍÿÁ¢ÉÿãÆÿÅ¢ÀÿÇ¢½ÿÇ¢¾ÿÇ¢¾ÿÇ¡»ÿÈ¡ºÿÈ¡·ÿÈ ¶ÿÉ¡³ÿÊ ²ÿÊŸ¯ÿÊŸ«ÿÌž¦ÿÌž£ÿΞ¡ÿÏž ÿÏŸžÿÏŸŸÿÏž¡ÿΞ¤ÿÍž¦ÿÌŸªÿËž©ÿËž¦ÿÌ�¥ÿËž§ÿÊž©ÿËž«ÿÊž¬ÿÊ�©ÿËœ§ÿÊ›¨ÿÈœ¨ÿÈ›©ÿÈœªÿÇ›«ÿÇš¬ÿÄ™¬ÿ˜ªÿ—«ÿÀ–¯ÿ½–°ÿ½–²ÿ¼–´ÿ»–´ÿ¼“²ÿ½“­ÿ½”­ÿ»”°ÿº“¶ÿ³�¸ÿ¯Œ¹ÿ¯�ºÿ¯�½ÿ´•Ãÿ·—Äÿ¸˜Åÿ¹˜Äÿº™Ãÿ¹™Æÿ¸™Çÿº™Æÿ·˜Åÿ·˜Éÿ¶˜Ìÿµ˜Ìÿ´—Ëÿµ—Êÿ´•Åÿ²“Çÿ¯‘Èÿ­’Ëÿ®’Ëÿ¯’Êÿ±’Çÿ¯�Áÿ®�Åÿ«‘Ìÿ«�Ïÿ­�Íÿ®‘Êÿ®‘Æÿ®�Âÿ¬ŽÃÿ¬ŽÇÿ©ŽÊÿ§�Ðÿ§ŽÏÿ§ŽÎÿ¨�Îÿ¨ŽÍÿ­”ÕÿK4Lÿ«’Ïÿ«Š½ÿ­‰¸ÿ­ˆ²ÿ¯‡­ÿ°‡«ÿ±‡©ÿ°†§ÿ°…§ÿ±†©ÿ¯„¦ÿ¯„£ÿ¯„¤ÿ¯„¦ÿ¯„£ÿ¯‚¢ÿ­‚¤ÿ¬‚¦ÿ¬‚¨ÿ«‚¨ÿ¬ƒ©ÿª‚©ÿªƒ«ÿªƒ«ÿ«‚©ÿª�¥ÿ«�¤ÿª£ÿ©~£ÿ©§ÿ¨�­ÿ§�¯ÿ¨€ªÿ¨~§ÿ¨~¦ÿ§~¦ÿ¤}¨ÿ¤|©ÿ¥|¦ÿ§|£ÿ¦{ ÿ§z›ÿ¨{™ÿ§z—ÿ¨x•ÿ§y•ÿ¦y˜ÿ£w™ÿ v�ÿžv¡ÿŸu�ÿŸu›ÿžtœÿŸw ÿ¡w¡ÿ w£ÿ w¢ÿ vžÿ¡uœÿŸtœÿŸtœÿ�užÿœs�ÿ�s˜ÿ�q•ÿ�q•ÿ›q˜ÿ™q›ÿ—q�ÿ—q›ÿ˜q›ÿ˜qšÿ™p›ÿ˜qœÿ—p›ÿ–p›ÿ˜p›ÿ˜p™ÿ™pšÿšq™ÿ›qšÿ›r›ÿ˜rŸÿ˜s¥ÿ–r§ÿ—s§ÿ˜s§ÿ—s¥ÿ–s¥ÿ—r¤ÿ–q£ÿ”p¤ÿ“q¨ÿ“q¬ÿ’r®ÿ’q­ÿ‘p«ÿ’p«ÿ‘p«ÿ�oªÿÁ¡ÉÿÀ ÇÿÁ ÈÿÁ¡ÈÿÁ¡Êÿ¢ÈÿâÄÿÄ¢¿ÿÇ¢½ÿÈ¢¼ÿÇ¢¼ÿÇ¢¼ÿÈ¡¼ÿÈ¡¹ÿÉ¡·ÿÉ¡´ÿÊ¡±ÿË ­ÿÌ ªÿÍž§ÿÍŸ¥ÿΟ¡ÿÏŸžÿРŸÿПŸÿÏŸ ÿÏŸ¡ÿÏŸ¢ÿΟ¤ÿΟ¤ÿÎ�¢ÿÍž£ÿÌž§ÿËžªÿËž¯ÿÊž­ÿË�ªÿÊ�©ÿÉ�©ÿÉ�©ÿÉž«ÿÉœ«ÿÈœ¬ÿÇ›«ÿÆ›¬ÿÅ™­ÿØ®ÿÁ˜®ÿÀ–®ÿ¿—¯ÿ¾—²ÿ¾–²ÿ½•²ÿ½•°ÿÀ–­ÿÀ–­ÿ½•±ÿ¸“¶ÿ±Ž¸ÿ®�ºÿ¬‹»ÿ´“¾ÿ·˜Âÿ¸˜Åÿ·™Æÿ¶™Èÿ·™Éÿ¶™Éÿ·˜Éÿ¶˜Éÿ¶˜Ëÿµ™Íÿ´™Îÿµ˜Ïÿµ—Íÿ´–Ëÿ²“Èÿ¯“Éÿ®”Íÿ­”Ðÿ«‘Ìÿ­�Éÿ¬�Åÿ«ŽÅÿª�Íÿ«‘Îÿª‘Íÿ¬‘Ëÿ®�Èÿ­ŽÄÿ«ŽÆÿ¨ŽÉÿ¥�Ðÿ¤�Ôÿ¥�Óÿ¦�Ðÿ¨�Ïÿ©�Íÿ®“ÓÿK5Kÿ«ŽÊÿ«‹¾ÿ¬‰¸ÿ­ˆ³ÿ¯ˆ¯ÿ°‡ªÿ±‡§ÿ²‡§ÿ°‡©ÿ¯†ªÿ®…©ÿ®…¨ÿ¯„§ÿ¯…¥ÿ²… ÿ°„¥ÿ¯„©ÿ­ƒªÿ¬„¬ÿ¬ƒ­ÿ«„®ÿ©„²ÿ©…µÿ¨…´ÿ¦ƒ°ÿ¨‚®ÿ¨‚ªÿª�§ÿª€¨ÿ©�¬ÿ¨‚¯ÿ§‚®ÿ§�¬ÿ¦©ÿ§ªÿ§©ÿ¥~ªÿ¢|«ÿ£}ªÿ¤|§ÿ§|¡ÿ¨} ÿ§|žÿ§|�ÿ§{›ÿ¦zšÿ¦yšÿ¤xšÿ£x�ÿ¡x ÿ¡w�ÿ vœÿŸvŸÿŸv¡ÿžw£ÿžw¤ÿžw¥ÿ�w¤ÿ�v¢ÿžv¢ÿ�v¤ÿ›v¦ÿ›u¤ÿ™sžÿšs›ÿ›rœÿšr�ÿ™ržÿ˜qžÿ—qŸÿ–qŸÿ—q¡ÿ–r¢ÿ–r¡ÿ•q ÿ•qŸÿ–p�ÿ™p›ÿšq›ÿšqšÿœršÿ›r›ÿ™s ÿ˜s¦ÿ˜s¤ÿ˜s¡ÿ™s¢ÿ˜s¥ÿ—s¥ÿ˜r¦ÿ–r¦ÿ•s¨ÿ•rªÿ“r¬ÿ“r«ÿ’r«ÿ’r«ÿ’q¨ÿ‘q©ÿ‘pªÿãÈÿâÆÿ¡ÃÿÁ ÃÿÀ ÃÿÁ ÄÿÁ Âÿ ¿ÿÅ¡½ÿÆ£½ÿÇ£¾ÿȤ¾ÿÆ¢¼ÿÈ¢ºÿÈ¡¸ÿÉ¢¶ÿË¢³ÿÌ¡®ÿÍ¡§ÿÏ¡¦ÿÏ¡§ÿР£ÿРŸÿР�ÿС›ÿÏ¡œÿСžÿР ÿР¢ÿÏ ¡ÿП¡ÿÏŸ¢ÿÍŸ¦ÿÌ ­ÿÍ ²ÿËŸ¯ÿÊž¬ÿÊŸªÿËž©ÿË�ªÿÉ�«ÿÉ�¬ÿÉ�¬ÿÈœªÿÇ›ªÿÆ›¬ÿÙ¯ÿ™°ÿÁ˜°ÿ¿˜¯ÿÀ˜¯ÿÀ–®ÿ¿—¯ÿ¾—°ÿÁ—¯ÿÀ–­ÿ¾•®ÿ¼•±ÿ´’µÿ¯�·ÿ°Žºÿ·–ºÿ»š¾ÿºšÄÿ¸›Éÿ¶šÏÿµ›Ñÿµ›Òÿ´šÑÿµšÑÿµ™Ïÿ³šÏÿ´šÐÿµ™Îÿ´™Íÿµ˜Îÿ´—Êÿ²–Éÿ±•Îÿ°•Îÿ¯“Éÿ¯�Åÿ®�Ãÿ­�Åÿ¬‘Ìÿ¬‘Ïÿ¬‘Ëÿ¬�Êÿ®�Æÿ­�Åÿ¬�Èÿ©�Ëÿ¤�Óÿ£�Òÿ¦�Ñÿ¨�Íÿ¨�Èÿ©�Çÿ®’ÐÿM5Jÿ¨ŽÉÿ«‹¿ÿ¬‰¶ÿ®‰³ÿ¯ˆ¯ÿ°‡©ÿ²‡§ÿ±‡§ÿ°‡«ÿ¯†­ÿ®†®ÿ­†®ÿ®…­ÿ°…¥ÿ°„¢ÿ°†§ÿ¯†¬ÿ®†¬ÿ®…¬ÿ®…­ÿ«…°ÿ©…´ÿ§…¹ÿ¥†»ÿ¥†»ÿ¦„¸ÿ¨„²ÿ©ƒ­ÿª‚­ÿ¨�­ÿ§‚­ÿ§�¬ÿ¦€­ÿ¥€¯ÿ¥€¯ÿ¤¬ÿ¤€¬ÿ¤~±ÿ£~¯ÿ¤}©ÿ§}£ÿ§}£ÿ§~¢ÿ¦{¡ÿ¦| ÿ¦z�ÿ§{›ÿ¥y›ÿ£y�ÿ¤xŸÿ¡wŸÿ wŸÿ x¢ÿŸx¤ÿžx¦ÿžx©ÿ›w«ÿ™v«ÿšv©ÿ›w©ÿœwªÿ›wªÿ›u§ÿ™u¤ÿ™u¢ÿšt£ÿ™u£ÿ™t£ÿ˜t¢ÿ–s¥ÿ—t§ÿ˜t§ÿ—t¦ÿ–t¥ÿ•r¤ÿ–r¢ÿ—r ÿ™ržÿšsœÿ›sœÿœsšÿœs›ÿ™tŸÿšs¡ÿ›sžÿ™s�ÿšs¡ÿ˜s¤ÿ˜t¦ÿ—s¦ÿ–s§ÿ•s¨ÿ–r©ÿ•r¨ÿ”r¨ÿ”r©ÿ”rªÿ’rªÿ‘r«ÿ‘q«ÿƤÆÿƤÀÿÇ¢¼ÿÆ¡¼ÿÄ¡¼ÿŸ½ÿŸÀÿŸÁÿß¿ÿÅ¡ÀÿǤ¿ÿÇ¢½ÿÈ£¼ÿÈ¢ºÿÈ¡¸ÿÉ¢¶ÿÌ¢´ÿÌ¢¯ÿÍ¡ªÿÏ¡¨ÿТ¦ÿТ¥ÿÒ£¡ÿÒ¢ ÿÑ¢�ÿÒ¢�ÿÑ¡žÿÑ¡¢ÿÑ¡¤ÿС ÿР ÿР¢ÿÏ ¢ÿΠ©ÿ΢¯ÿÌ ­ÿÌŸªÿÍŸ©ÿËŸ©ÿËžªÿÊžªÿÊž¬ÿÈ�¬ÿÉ�¬ÿÉ�ªÿÇ›ªÿÆ›­ÿÚ±ÿÁ™³ÿÀ˜²ÿ¿—±ÿÀ˜°ÿÁ˜±ÿÁ˜²ÿÁ˜±ÿÁ—¯ÿ¿–±ÿ¼•±ÿ·’´ÿ±�¶ÿ¶”ºÿº—»ÿ½›¾ÿ½šÂÿº�Êÿ·œÒÿµœÔÿ´›ÔÿµšÒÿ³šÓÿ²šÕÿ³šÖÿ³šÓÿ´™Ïÿµ™Ïÿ´™Ïÿ´˜Êÿ´—Èÿµ—Ëÿ³•Æÿ´”Âÿµ”¿ÿ´’¿ÿ²’Ãÿ°’Èÿ®�Çÿ¯�Çÿ®�Èÿ®�Æÿ¬ŽÅÿ«�Åÿ©ŽÊÿ¥‘Õÿ¥�Òÿ¦�Ðÿ§�Êÿª�Åÿª�Åÿ¯’ÎÿL7Kÿ¤‹Æÿ©‹Ãÿ«Š¿ÿ«‰¶ÿ®ˆ±ÿ²ˆ«ÿ²ˆ§ÿ²‡¨ÿ°‡«ÿ°‡­ÿ®‡°ÿ®‡²ÿ®‡±ÿ±†¨ÿ²†¤ÿ²†§ÿ±‡¨ÿ²‡©ÿ°…©ÿ¬…®ÿ«…´ÿ¨†¼ÿ¥ˆÁÿ¦‡Âÿ¤‡Ãÿ¤‡Ãÿ¦„ºÿ¨ƒ³ÿ¨‚¬ÿ¨�«ÿ§�­ÿ¦�¯ÿ¥‚²ÿ£€´ÿ¢~´ÿ¢³ÿ¤³ÿ¤€µÿ¥€³ÿ¦~«ÿ§~¦ÿ¦~¦ÿ¦}¦ÿ¦}¤ÿ¦|¡ÿ¦{Ÿÿ¦z�ÿ¥zŸÿ¤y¢ÿ¢y£ÿ¢y£ÿ¡y£ÿ x¥ÿžx§ÿžx¨ÿœy¯ÿ™x°ÿ˜w¯ÿ—v®ÿ˜w®ÿ™w¯ÿ™w­ÿšuªÿšv©ÿ™v«ÿ™v©ÿ™u¨ÿ™u§ÿ—u§ÿ–v«ÿ—v­ÿ—v«ÿ˜v«ÿ—t¨ÿ—s¦ÿ—s¥ÿ™t¥ÿ™t¢ÿšt¡ÿ›sŸÿœsœÿ›s›ÿ›sžÿ›s�ÿ›rœÿ›sŸÿ˜t¡ÿ™t¤ÿšu§ÿ™t©ÿ˜t©ÿ—tªÿ–s¨ÿ–r§ÿ•s¨ÿ•sªÿ”s«ÿ“r¬ÿ“rªÿ’rªÿǦÄÿÉ¥½ÿˤ¸ÿÊ£¶ÿÊ£µÿÈ¡µÿÆ¡¸ÿÄ ¼ÿÄ¡ÀÿÅ¡ÀÿÆ¡½ÿÇ¢ºÿÈ¢¸ÿÉ¢·ÿÉ£¶ÿÊ£³ÿÌ¢²ÿÍ¢¯ÿÍ¢­ÿ΢«ÿТ¨ÿТ¦ÿÒ£¥ÿÒ¤£ÿÒ¤¡ÿÒ¢žÿÒ¢ŸÿÑ¢£ÿÑ¢¡ÿÑ¢ŸÿÑ¡ŸÿСŸÿСŸÿÏ ¢ÿΠ©ÿÍ ªÿÍ §ÿÍŸ§ÿÌŸ¨ÿÌŸ©ÿËŸªÿËž«ÿËž¬ÿÉž¬ÿÉžªÿÊ�©ÿÈ›©ÿÅš¯ÿ™³ÿÁ˜´ÿÀ˜²ÿÁ˜³ÿÁš´ÿÁ™³ÿÁ˜±ÿÀ˜¯ÿÀ™²ÿ½–´ÿ¸“µÿµ“¹ÿ¹–ºÿ¼˜½ÿ¼œ¾ÿ¾œÀÿ¾�Äÿ¼�Çÿº�Îÿ¸œÍÿ·›Îÿ´›Õÿ±�Ýÿ°œÚÿ²›×ÿ³›Õÿ´™ÒÿµšÐÿµ™Êÿ¶—Äÿ·–Äÿ·–Âÿ·”¿ÿ¶”½ÿ¶“¿ÿ³”Áÿ±“Äÿ°’Åÿ°‘Äÿ¯�Åÿ®�Ãÿ¬ŽÂÿª�Ãÿ¨�Ëÿ¥�Òÿ¥�Ñÿ¦�Ñÿ¦ŽÌÿ§�Éÿ©ŒÇÿ¤ˆÁÿ-)ÿye”ÿª�Ìÿ¨‹ÄÿªŠ¾ÿ­‰µÿ°ˆ®ÿ²ˆªÿ²ˆ«ÿ°ˆ®ÿ®ˆ°ÿ¯ˆ¯ÿ¯‰¯ÿ®‰±ÿ±‡¨ÿ³‡¢ÿ³‡¢ÿ´† ÿ´†¡ÿ°†§ÿ¬ˆ²ÿ©‡»ÿ§‰Ãÿ¦‰Æÿ¤ˆÄÿ¤ˆÆÿ¤ˆÆÿ¦…¸ÿ¨ƒ±ÿ¦¨ÿ¨€¨ÿ§�¬ÿ¦‚³ÿ£�·ÿ¢�ºÿ ºÿ¡�¹ÿ¢�ºÿ¤�·ÿ¦�¯ÿ¨~§ÿ§~§ÿ¥}¨ÿ¥~¨ÿ¥}§ÿ¦|¢ÿ§|¡ÿ¥z¡ÿ¥z¤ÿ£{¦ÿ¡z§ÿ z¦ÿŸy©ÿžyªÿžxªÿœx¬ÿšzµÿ™y¶ÿ˜x´ÿ—v±ÿ˜w±ÿ˜w±ÿ˜w±ÿ˜x±ÿ—v®ÿ˜v®ÿ—v­ÿ–u¬ÿ—u«ÿ—w¯ÿ”w³ÿ–v±ÿ—w¯ÿ—v­ÿ—uªÿ–u©ÿ˜v¨ÿ˜u§ÿšu¦ÿšu¦ÿ›t£ÿ›t ÿ›s�ÿœsœÿœtžÿ›tŸÿšt¢ÿ™u¤ÿšu¦ÿ™t¦ÿšt¨ÿ™t©ÿ™t©ÿ–tªÿ–s©ÿ•sªÿ”s¬ÿ”s®ÿ“s¬ÿ”rªÿ”r©ÿǧÄÿɦÀÿ˦ºÿÊ¥µÿË£³ÿÌ£³ÿʤ´ÿÈ£·ÿÇ¢¹ÿÇ¢ºÿÇ¡¹ÿÇ¡ºÿÇ ·ÿÇ ¶ÿÉ¡³ÿË¢²ÿÌ£²ÿÍ£²ÿΣ°ÿΣ­ÿÏ£«ÿÑ£ªÿÑ£¨ÿÒ¤§ÿÒ¥¤ÿÔ¥¡ÿÔ¤¡ÿÓ¤¡ÿÒ¤ŸÿÓ£ŸÿÒ£ŸÿÒ¢�ÿÑ¢ŸÿÑ¢¡ÿÏ¢¨ÿΠ©ÿÏ¡§ÿΠ¦ÿÍ ¨ÿÍ ¨ÿËŸªÿËŸ­ÿÌ ®ÿÊŸ«ÿÉžªÿÉž©ÿÉž¨ÿÈœªÿÅ›¯ÿš±ÿš³ÿ™´ÿÁš´ÿÁš´ÿÁ™³ÿÁ™³ÿ¿—±ÿ¼•³ÿ·”¶ÿ·•ºÿ¸–¼ÿ¼š¾ÿ¿�ÁÿÀžÄÿÀžÄÿ¿žÅÿ½žÈÿ»�Êÿº�Íÿ·�Õÿµ�Ùÿ³�Õÿ´œÓÿ´›Ñÿ´›ÐÿµšÏÿ·™Ìÿ¶˜Äÿ¸—Áÿ¸–¿ÿ·–¾ÿ·•Àÿ´•Áÿ²”Åÿ±“Éÿ±“Èÿ°‘Åÿ¯�Áÿ¯�¿ÿ¬�Àÿª�Ãÿ©ŽÊÿ¨�Ìÿ¤�Îÿ¤�Óÿ¤�Òÿ¤�Ñÿ¥�Ðÿ˜‚¾ÿ"ÿeS€ÿ©“Öÿ¦ŽÌÿ©ŒÃÿ«Š¹ÿ­Šµÿ®ˆ±ÿ®‰±ÿ­‰´ÿ¬‰·ÿ­‰¶ÿ­‰²ÿ¯ˆ±ÿ±‡«ÿ²‡¤ÿ±†¥ÿ±†§ÿ¯†¬ÿ­‰·ÿªŠÀÿ§ŠÂÿ¥‰Æÿ¥‹Éÿ¤‹Éÿ£ˆÇÿ£…¾ÿ¦„¸ÿ§‚­ÿ§€©ÿ§¨ÿ¨€¨ÿ¦€¯ÿ¢¶ÿ¡�»ÿ ‚¾ÿ¡‚¼ÿ¡�¹ÿ¤�´ÿ¥€¬ÿ¦~§ÿ¦~¨ÿ¤}©ÿ¢}ªÿ£}©ÿ¥}§ÿ¥{¢ÿ¤{§ÿ¡{ªÿ¡{«ÿ {ªÿžzªÿ�{¯ÿ�{²ÿœz³ÿ™z´ÿ˜{ºÿ—|½ÿ—z»ÿ–x¶ÿ˜xµÿ—yµÿ—y¶ÿ—x¶ÿ•x³ÿ–x²ÿ–w³ÿ–w³ÿ–w³ÿ•wµÿ“x·ÿ•w´ÿ—x´ÿ˜w±ÿ—v­ÿ˜v«ÿ—v¬ÿ˜w«ÿšwªÿ›vªÿ›v§ÿ�t¢ÿ�tŸÿœuŸÿœu¡ÿ›v£ÿ›v¤ÿœv¥ÿ›v¦ÿ›v§ÿšv©ÿ™t©ÿ—uªÿ–t¬ÿ–t­ÿ”s¬ÿ”t¯ÿ“u±ÿ’t°ÿ”s­ÿ”s­ÿÈ©ÌÿÊ©Æÿ̧¾ÿ̦¸ÿͦ´ÿͤ²ÿ̤°ÿ̤²ÿʤµÿÉ£¸ÿÈ¢·ÿÇ¡¹ÿÈ¡¶ÿÉ¡´ÿÉ¡³ÿÊ¡³ÿË£´ÿÍ£²ÿΤ±ÿϤ®ÿϤ­ÿФ­ÿѤªÿÒ¤©ÿÔ¥§ÿÔ¦¤ÿÔ¦£ÿÔ¥¡ÿÕ¥ŸÿÔ¥ŸÿÔ¤žÿÓ£�ÿÓ£žÿÒ£¡ÿÑ¢¦ÿТ¨ÿÏ¡§ÿÏ¡§ÿÏ¡©ÿÍ ¬ÿΡ®ÿÍ ¯ÿÌ¡®ÿË «ÿËžªÿËž©ÿËž©ÿÊ�©ÿÈœ¬ÿÇœ­ÿÅš±ÿš³ÿÄ›¶ÿœ¶ÿ›¶ÿÁš¶ÿ¾˜µÿ¹”´ÿ¸”·ÿ·•ºÿ¹–¹ÿÀœ¾ÿÁžÃÿÀžÆÿÀŸÄÿÀžÆÿ¿žÈÿ½�Éÿ¼�Îÿ¸�Ñÿ¶�Óÿ·�Óÿ·�Ñÿ¶œÍÿ·›Ìÿ·›Ìÿ¶™Èÿ·—Äÿ¹—Àÿ¹—¿ÿ¹—Àÿ·–Âÿ´–Æÿ²”Ëÿ°“Ëÿ¯“Êÿ°’Çÿ¯�Ãÿ®�Ãÿ­ŽÅÿ«ŽÆÿ¨�Çÿ¨�Éÿ§ŽÎÿ£‘×ÿ£‘Ùÿ¢‘Øÿ¢’Ùÿ¡‘Üÿ&%ÿuh¡ÿ¤’Úÿ¤ŽÏÿ¦�Èÿ©Š¿ÿ«‰ºÿ«ˆ¶ÿªˆ·ÿª‰»ÿ«Šºÿ«‰¹ÿ¬‰·ÿ¬‰¶ÿ¬‡³ÿ­ˆ²ÿ«‰·ÿª‰ºÿªŠÂÿ¨ŒÊÿ§‰Âÿ¨‰Âÿ§‹Åÿ¥ŠÈÿ¤ŠÈÿ¤ˆÆÿ¤„¼ÿ¥„¹ÿ¨�­ÿ©€ªÿ¨©ÿ¦©ÿ¥­ÿ¢�·ÿ ƒÀÿŸƒÁÿ¢�ºÿ£�´ÿ£€¯ÿ¤~­ÿ¤~ªÿ¤}ªÿ¡|¬ÿ¡|­ÿ |¯ÿ£|¬ÿ¢{ªÿ |®ÿŸ{²ÿŸ|±ÿžz°ÿŸ{±ÿ�|´ÿ�}¸ÿš~¼ÿ˜~¿ÿ•}Ãÿ•}Äÿ–|Àÿ˜{½ÿ—{½ÿ—{½ÿ—z½ÿ–z¼ÿ—z»ÿ•{ºÿ”y¹ÿ”x»ÿ“xºÿ”y¼ÿ”yºÿ”w·ÿ”x¸ÿ”y»ÿ•yºÿ—w³ÿ˜w°ÿ˜x­ÿ™x­ÿšwªÿœw§ÿœv¤ÿ�w¤ÿœw¥ÿœv§ÿœwªÿ›w©ÿ›w©ÿ›xªÿœw«ÿšv­ÿ˜v®ÿ—v¯ÿ–u°ÿ•t°ÿ•t±ÿ“u²ÿ’u´ÿ’u´ÿ’t²ÿ“t°ÿȪÌÿÉ©ÇÿË©Àÿ̧ºÿΧµÿЦ±ÿÎ¥°ÿͤ°ÿͤ³ÿʤµÿÉ£´ÿÉ¢´ÿÊ¢²ÿÊ¡²ÿÉ¡²ÿÉ¢²ÿË£³ÿÌ£³ÿΤ±ÿÏ¥±ÿÏ¥°ÿÐ¥®ÿÑ¥­ÿÒ¥ªÿÓ¦©ÿÓ¦¦ÿÕ§¤ÿÔ¦¢ÿÔ¦ ÿÕ¦ŸÿÕ¥�ÿÔ¦›ÿÕ¥œÿÔ¤ ÿÓ¤¤ÿÓ¤¦ÿÑ£¥ÿТ¦ÿÏ¢¨ÿÏ¢«ÿÍ¢¬ÿÌ¡¬ÿÍ¢­ÿÍ¡ªÿÍŸ¨ÿÌŸ§ÿËž§ÿÊ�¨ÿÉž©ÿÈ�«ÿÇ�¯ÿÄœ²ÿÜ´ÿÛ¶ÿÃ�¹ÿÁœºÿ¾™¹ÿ¹•·ÿ¶“·ÿ¹•·ÿÀš¸ÿÅŸ¼ÿŸÁÿÁ ÅÿÀŸÅÿ¿ŸÉÿ¾ŸËÿ½žËÿ»žÎÿ»žÒÿ¹�Ðÿ·œÑÿ·œÐÿ¸œÏÿ¸œÎÿ·›Ëÿ·›Èÿ·™Çÿ¶˜Åÿ¶—Åÿ¶—Æÿ´–Èÿ²–Ìÿ°•Íÿ¯”Ìÿ®’Êÿ®‘Èÿ®‘Çÿ¬�Èÿ«�Éÿ©�Ëÿ©�Êÿ¨ŽÈÿ¥�Ïÿ ’Üÿ ’Ûÿ ’Üÿ ’Ýÿ˜‰Óÿ%$ÿdWŠÿ¥“Úÿ£ŽÏÿ¥ŒÊÿ¦‹Äÿ¨ŠÁÿ©‹Àÿ©‰½ÿ©‰»ÿ©Š¼ÿ©‹¾ÿª‹½ÿª‰»ÿªŠ¼ÿ«‰ºÿª‹Ãÿ¦�Ìÿ£ŽÒÿ¤ŽÑÿ§‹Åÿ¨‰¾ÿ©‰¿ÿ¦ŠÃÿ¥ŠÅÿ£‰Äÿ£†Àÿ¤…¼ÿ¦„¯ÿ§�­ÿ§�­ÿ¦€­ÿ¤�²ÿ¢‚ºÿŸ„ÁÿŸƒÂÿ¡�¹ÿ¡³ÿ ~°ÿ¡°ÿ¡³ÿ ~¶ÿŸ~·ÿž~µÿ¡~³ÿ¢}±ÿ¡~°ÿž}µÿœ}¸ÿ›{µÿ�|µÿ�}·ÿž~ºÿ›¾ÿ˜Ãÿ•€Èÿ“�Ìÿ“Ëÿ–}Áÿ—|Àÿ—|¿ÿ–{Àÿ”|Âÿ”{Âÿ”|Áÿ”|Àÿ”{¿ÿ“{Áÿ‘zÁÿ�zÀÿ‘y¾ÿ’y»ÿ“x½ÿ’z¾ÿ’zÀÿ•z¾ÿ–y·ÿ˜x²ÿ™x±ÿ™w®ÿ›wªÿ›x©ÿœxªÿœx­ÿšy¯ÿ™y°ÿšy±ÿ™w±ÿ™x°ÿ™w±ÿ˜w²ÿ—w²ÿ—v³ÿ•vµÿ•v´ÿ”wµÿ“vµÿ’v·ÿ‘u¶ÿ�u¶ÿ�uµÿÈ©ËÿȪÊÿÊ©ÆÿÌ©ÀÿΨ¹ÿЧ´ÿШ°ÿЧ¯ÿЦ±ÿͦ²ÿÌ¥³ÿ̤²ÿÊ¢²ÿÊ¢±ÿË£³ÿÊ¢²ÿÌ£±ÿͤ±ÿΤ±ÿЦ²ÿѧ°ÿЦ®ÿѦ­ÿÒ¥«ÿÓ¦©ÿÓ§§ÿÕ¦§ÿÕ§¦ÿÕ§£ÿÕ§ŸÿÕ¦›ÿÕ¥šÿÕ¥›ÿÕ¥�ÿÔ¥ ÿÔ¥£ÿÔ¥¢ÿÓ¤¢ÿÒ¤£ÿÒ£¨ÿУªÿÏ¢ªÿΡªÿΡªÿÍ §ÿΟ§ÿÌŸ§ÿÌž§ÿÊžªÿÉž©ÿÈž¬ÿÈž¯ÿÆ�±ÿÄ›²ÿÅ�µÿÄ�¸ÿÀ›¹ÿ¼–·ÿ¼—¸ÿÁ›·ÿÆžºÿÆ ¼ÿÄ¡Áÿ ÅÿÁ Çÿ¿ Ìÿ½ Ïÿ¼ŸÏÿ» Ïÿ»ŸÒÿ¹žÑÿ·žÓÿ·žÕÿ¶�Õÿµ�ÓÿµœÒÿ·œÑÿ¶œÐÿ¶šÐÿ´™Ïÿ´™Îÿ´—Íÿ²–Íÿ±–Ìÿ°”Êÿ±“Éÿ°“Èÿ¯‘Åÿ®‘Èÿª‘Íÿ¨’Ðÿ¨�Îÿ¨�Íÿ£‘×ÿ ’Ýÿ¡’Úÿ¡’Úÿ£’ÛÿœŒÒÿ'%ÿh\‘ÿ¦’×ÿ£ŽÍÿ¥ŒÊÿ¦ŒÇÿ¦‹Æÿ§‹Åÿ¨‹Ãÿ©‹Àÿ©‹¿ÿª‹Âÿ©‹ÂÿªŠ¿ÿ¬‹»ÿ¬‹¹ÿ«Œ¿ÿ¨�Ìÿ¥ŽÍÿ§�ÊÿªŠ¹ÿ¬ˆµÿ«‰¹ÿ©‰¾ÿ¦‰Ãÿ¤‰Åÿ£ˆÄÿ£†¾ÿ¦…´ÿ§„²ÿ¦ƒ±ÿ¦‚³ÿ£‚·ÿ¡„¾ÿŸ„ÂÿžƒÄÿŸ‚¿ÿ €»ÿ €·ÿ ·ÿŸ¸ÿŸ¹ÿ�~·ÿŸ}±ÿ¢}­ÿ¡~°ÿŸ}´ÿ�~¸ÿš~ºÿš}¹ÿœ}¸ÿœ|¸ÿ›~¼ÿ™Áÿ–Èÿ“�Íÿ’‚Ðÿ“€Íÿ—~Áÿ—}Àÿ—~Âÿ•~Äÿ’~Éÿ‘Ëÿ’Éÿ“~Æÿ’~Åÿ‘}Äÿ‘}Æÿ‘{Äÿ‘yÀÿ’z¾ÿ’z¾ÿ“z¿ÿ’zÀÿ”z¾ÿ•yºÿ—y·ÿ˜yµÿ™y³ÿ˜x±ÿ™x±ÿ™y²ÿ˜y²ÿ™zµÿ™zµÿ˜yµÿšy¶ÿ™yµÿ™yµÿ˜x¶ÿ–x¶ÿ”x·ÿ”x·ÿ“x·ÿ“w·ÿ’w·ÿ‘v¹ÿ�wºÿ�v»ÿ�u»ÿɪÌÿÊ«ËÿÊ«ÊÿË©ÇÿÍ©ÁÿΨ¹ÿѨ¶ÿѧ²ÿѧ±ÿѧ²ÿϦ±ÿͦ±ÿÍ¥²ÿˤ³ÿÌ£´ÿË£³ÿÌ£°ÿÍ£¯ÿΤ±ÿЦ±ÿѦ±ÿÒ¦®ÿÒ¦­ÿÒ¦«ÿÔ§©ÿÔ¨©ÿÕ§¨ÿÕ§¨ÿÖ¨¥ÿÖ§ ÿÖ¦šÿÖ¦šÿÖ¦›ÿÕ¦œÿÕ¦�ÿÖ¥ŸÿÕ¦ ÿÕ¦¢ÿÔ¥¡ÿÒ¤¤ÿÓ¥§ÿÒ£¥ÿУ¥ÿÑ¢¦ÿТ¥ÿΡ¦ÿÏ §ÿΠ¨ÿÌŸ§ÿÊŸ¨ÿÉžªÿÉž¬ÿÈž®ÿÇœ¯ÿÇ�³ÿÆžµÿÄ›¶ÿ¿˜¶ÿÛ·ÿÆž¸ÿÇ ¼ÿÇ¡¾ÿÅ¡ÂÿáÈÿÁ¡ÉÿÀ Êÿ¾¡Íÿ¼ Îÿ¼ Óÿº ×ÿ¸ŸÖÿ¸ŸØÿ·ŸÛÿ´ŸÜÿ´ŸÝÿ´žÛÿ³�Ùÿ´œ×ÿ³šÔÿ³šÔÿ²™Ñÿ²™Îÿ²˜Íÿ²–Ëÿ²“Çÿ±“Èÿ±“Ãÿ°‘Âÿ®�Åÿ©’Ðÿ¦’Óÿ¥‘Ñÿ¥‘Óÿ¤‘Øÿ£’Øÿ¤�Ôÿ¥‘Ôÿ¦‘Óÿ†p¤ÿ"ÿA2Lÿ£�Óÿ¤ŽÐÿ¥ŽÎÿ§ŽÍÿ§‹Æÿ§‹Åÿ¨‹Ãÿ©‹Âÿ©Š¾ÿ©ŠÁÿ©‹ÁÿªŠ¾ÿ¬Š½ÿ¬‹»ÿ«‹¿ÿªŒÃÿ©ŒÄÿ¨ŒÄÿ«‰¸ÿ«‰·ÿ©Šºÿ¨‰Àÿ¥ŠÅÿ£‰Æÿ¢ˆÇÿ£ˆÃÿ£†¾ÿ¤…¼ÿ¤…»ÿ¤„½ÿ£„Àÿž…Åÿ�†Éÿ�…Èÿ�ƒÄÿ �ÀÿŸ�¼ÿž�»ÿ ¹ÿŸ¸ÿŸ~¶ÿŸ|±ÿ |®ÿŸ}²ÿž}´ÿœ}µÿ›}ºÿ›}»ÿš}»ÿš}¼ÿ™~Áÿ—Åÿ”�Ìÿ“�Ïÿ“ƒÐÿ”�Ëÿ–Äÿ–Æÿ”~Æÿ•~Çÿ”€Éÿ’€Êÿ“Ìÿ‘€Íÿ“Ëÿ“Êÿ’}Çÿ’{Äÿ“|Âÿ”zÀÿ”z¾ÿ“z¾ÿ“{Àÿ•z¾ÿ–zºÿ—zºÿ˜z¹ÿ˜z·ÿ˜z·ÿ˜z¹ÿ˜z¸ÿ˜{¸ÿ™{¹ÿ˜y·ÿ˜y¶ÿ˜z¶ÿ™zµÿ™yµÿ–z¹ÿ”y»ÿ”yºÿ”y»ÿ“x¼ÿ’w¼ÿ‘w¼ÿŽw¾ÿŽwÁÿŽxÁÿ�w¿ÿǪÏÿɪÌÿË«ËÿË«ÊÿÌ«ÇÿͪÁÿϪ½ÿЩ¸ÿÑ©³ÿѨ±ÿѧ±ÿΦ²ÿΧ²ÿͦ³ÿ̦´ÿ̤³ÿ̤°ÿÌ£±ÿͤ±ÿÎ¥±ÿЦ°ÿÑ¥®ÿÓ¥¬ÿÓ¦©ÿÔ¨©ÿÔ¨§ÿÕ¨§ÿÕ¨¦ÿÖ¨£ÿÖ¨Ÿÿ×§œÿÖ¦›ÿÖ¦›ÿÖ¥›ÿצ›ÿÖ¦�ÿÕ¦žÿÕ¦ ÿÕ¥¡ÿÕ¦£ÿÕ¥£ÿÔ¦¢ÿÔ¥¡ÿÔ¤¡ÿÓ£¢ÿÒ££ÿТ¦ÿÏ¢§ÿΡ¨ÿÌŸ§ÿËŸ¨ÿÊž©ÿÉž©ÿÊžªÿËŸ«ÿÊŸ­ÿÆœ°ÿÙ±ÿÇž³ÿÈŸµÿÉ¡ºÿÇ¡¾ÿÆ¡¿ÿÅ¡ÃÿàÃÿ ÆÿÀ¡Ëÿ½¡Ðÿº Ôÿ¸¡Úÿ¶¡Üÿµ¡Üÿ³ Ýÿ²ŸÞÿ± ßÿ±žÞÿ±ŸÞÿ±�Ýÿ±�Úÿ²›Öÿ°šÔÿ°™Ôÿ°˜Òÿ±–Íÿ±“Æÿ±‘Åÿ¯‘Ãÿ®�Æÿ¬‘Ëÿ§’Òÿ¤’Öÿ¤‘Öÿ£‘Öÿ¥‘Ôÿ¦�Ïÿ¨�Ëÿ§ŽÆÿ †Àÿu^‡ÿÿ-!2ÿ’€¾ÿ£ŽÐÿ¥�Ðÿ¦ŽÌÿ¨ŒÄÿ¨ŒÄÿ¨‹Âÿ¨Š¿ÿ¨Š¾ÿ¨‹Âÿ¨ŠÁÿª‹Àÿª‹ÀÿªŠÀÿª‹Áÿ¨‹Ãÿ¨ŒÄÿ©ŒÂÿ©ŠÀÿ¨Š½ÿ¨ŠÀÿ¦‰Åÿ£ŠÈÿ¡ŠËÿ ŠÌÿŸ‰ËÿŸ‰Ëÿž‰ËÿŸˆÊÿŸˆÊÿ�ˆËÿ›‡Ïÿš‡Ðÿš†Ìÿ�„ÇÿŸƒÂÿž‚Àÿž�¾ÿž€¼ÿŸ€¼ÿŸ€»ÿŸ~·ÿŸ}µÿ�}´ÿ�}µÿœ}¸ÿš}½ÿ™~¾ÿ—~Áÿ–~Åÿ•Çÿ”€Éÿ“ƒÐÿ’ƒÑÿ’�Îÿ•�Ëÿ•�Ëÿ”‚Íÿ•�Êÿ•€Çÿ•€Èÿ”Éÿ’�Íÿ‘‚Òÿ�‚Ñÿ‘�Ïÿ“€Ëÿ”}Äÿ–{¾ÿ—|½ÿ–{»ÿ•{¼ÿ•|Àÿ”{¿ÿ–{¾ÿ–z¼ÿ—{»ÿ—{ºÿ˜{ºÿ˜|¼ÿ—{»ÿ—zºÿ˜{¹ÿ˜{·ÿ˜z¶ÿ™z¶ÿ˜yµÿ˜y·ÿ•z¼ÿ”{¿ÿ“y¿ÿ’yÀÿ‘yÂÿ�zÃÿ�yÃÿŽyÄÿŽzÅÿŽzÅÿŽzÅÿƬÓÿÇ«ÐÿȬÏÿɬÍÿË«ÊÿÍ«ÅÿΫÂÿΫ¾ÿϪ»ÿÏ©¶ÿϧ±ÿШ±ÿШ¯ÿϧ±ÿΦ²ÿÍ¥±ÿÌ¥±ÿÎ¥±ÿÍ¥±ÿÏ¥±ÿϤ°ÿÐ¥®ÿÑ¥«ÿÓ¦ªÿÔ¨ªÿÖ©¨ÿÕ©§ÿÖ¨¤ÿÖ¨ ÿרžÿרœÿ×§›ÿצ›ÿاœÿبœÿÖ¦œÿÕ¦žÿÔ¦žÿÕ¦ŸÿÖ§¡ÿÕ§ ÿÔ¦ŸÿÕ¦ŸÿÔ¥žÿÔ¥ŸÿÓ¤ ÿÒ¥¢ÿФ¤ÿУ¥ÿÏ¢¥ÿÌ¡¦ÿÍ ¨ÿË ¨ÿÊŸ¦ÿÌ ¦ÿÍ §ÿÌ ¨ÿÊŸ©ÿÍ¡«ÿÌ¡¯ÿË¢´ÿÊ¢·ÿÇ¡ºÿÇ¢¿ÿÄ¡Àÿ¡Äÿ¿¡Ìÿ¼¡Ôÿ¸¡×ÿ·¡Ûÿ´¡ßÿ± Þÿ± ßÿ°Ÿßÿ° ßÿ°Ÿàÿ°Ÿàÿ¯žÞÿ¯�Ýÿ¯œÛÿ­œÚÿ¬šÙÿ®˜Öÿ¯–Ïÿ¯“Èÿ¯’Éÿ­’Éÿ«“Îÿ§”Òÿ¤”Öÿ¤•Ùÿ¤“Øÿ¤’Õÿ¦�Ðÿ¨�Îÿ©�Êÿ�ƒ¸ÿZGjÿ:*>ÿ ÿÿM@aÿ‹y´ÿ–¼ÿ¨ŽËÿ§�Èÿ¨ŒÅÿ§‹Åÿ¥‹Äÿ¥‹Åÿ§ŒÆÿ¦‹Äÿ§‹Áÿ¨‹Âÿ§‹Æÿ§ŽÉÿ§�Éÿ¦�Çÿ¦ŒÅÿ¨ŒÅÿ¦‹Äÿ¥ŒÇÿ¢‹Êÿ ‹ÎÿžŒÒÿ�ŒÕÿšŒÔÿš‹ÔÿšŠÒÿ›ŠÓÿ›‰Óÿš‰Ôÿ˜ŠÖÿ˜‰Ôÿ™ˆÏÿœ†Çÿž„Áÿ�ƒÃÿ�‚Âÿœ�Àÿ��¾ÿœ€¾ÿœ¼ÿœ~½ÿ›~»ÿš~¼ÿ˜Ãÿ–Åÿ–€Åÿ’€Êÿ’€Ëÿ“€Ëÿ“‚Ïÿ‘„Õÿ�„Ôÿ’‚Ïÿ”‚Ìÿ”ƒÏÿ•‚Ïÿ•‚Êÿ•�Ëÿ•�Êÿ”�Ìÿ�‚ÑÿŽ„Õÿ�„Öÿ�‚Òÿ’€Ëÿ—~Âÿ›}¹ÿ›|¸ÿ™{¹ÿ–{¼ÿ•|Àÿ•|Áÿ•|Àÿ•{¼ÿ•{½ÿ–{¼ÿ–{»ÿ˜|»ÿ™|¹ÿ˜{·ÿ˜{¸ÿ—z¸ÿ–z¶ÿ—z¹ÿ•{»ÿ“{½ÿ“{Áÿ‘{Âÿ�{Ãÿ�{ÄÿŽ|ÈÿŒ{Éÿ�|ËÿŽ{ÊÿŽ{ÈÿŽzÆÿ�{ÈÿÅ«ÖÿÇ«ÕÿǬÓÿȬÑÿʬÍÿÍ«ÇÿÏ«ÃÿЫÃÿΫÃÿϪ½ÿЪ¸ÿШ¶ÿÒ¨´ÿѨ´ÿϨ´ÿϧ³ÿϧ³ÿϦ²ÿΦ²ÿÐ¥±ÿÏ¥°ÿÐ¥¯ÿÐ¥­ÿѦ­ÿÓ§¬ÿÖ©©ÿÖ©§ÿÖ©¢ÿר ÿשŸÿÖ©�ÿاœÿبœÿ×§œÿبœÿר�ÿÖ§žÿ×§žÿÖ¦ŸÿÕ§ ÿÕ¦ŸÿÖ¦ŸÿÕ§žÿÕ¦žÿÕ¥ŸÿÔ¥ŸÿÔ¥¡ÿÔ¥¡ÿÒ¤¢ÿÒ¤¤ÿѤ¥ÿÏ¡§ÿÍŸ¨ÿÌž¦ÿÍ ¦ÿТ¤ÿТ£ÿÑ¢¥ÿУ§ÿΣ¬ÿΣ°ÿÌ£³ÿÊ£·ÿÉ£½ÿÆ£¿ÿÄ¢ÄÿÁ¡Íÿ½¢Ôÿº¢Öÿ·¡Ûÿ²¢ãÿ°¢æÿ­¡æÿ® äÿ° âÿ¯Ÿâÿ¯Ÿàÿ¯�ßÿ®žßÿ­œßÿ¬œßÿ«›Ýÿ­™Øÿ®–Ðÿ®”Îÿ¬”Ïÿ«”Ðÿ¨”Òÿ¦”Ùÿ£–Üÿ¢•Ýÿ¢”Ùÿ¤’×ÿ¤‘Õÿ¥�Óÿ¤ŽÑÿaOuÿ)-ÿ"ÿÿÿ$#ÿB6Xÿwd“ÿª‘Ïÿ§�Íÿ¦�Ëÿ¦�Ëÿ¥ŽÎÿ¥�Íÿ¦�Éÿ§ŠÄÿ¨‹Âÿ§ŒÅÿ§�Êÿ§�Íÿ¥�Íÿ§�Ìÿ¦�Ëÿ¥ŒÉÿ¥‹Çÿ£ŠÉÿ¢‹ÍÿžŒÓÿœ�Öÿ™ŽÛÿ—�Üÿ˜ŒÛÿ™ŒÙÿ™‹Øÿ™Š×ÿ—ŠÙÿ—‹Ùÿ—Š×ÿ™ˆÐÿœ†Êÿœ„Æÿ™ƒÇÿ™„ÈÿšƒÆÿ™ƒÇÿš‚Èÿ™�Æÿ˜�Çÿ•€Èÿ•�Ëÿ’‚Îÿ�‚Ïÿ�‚Ñÿ�ƒÔÿ�ƒÓÿ‘ƒÒÿ�…Õÿ�†×ÿ�„Öÿ’ƒÏÿ“ƒÎÿ“ƒÑÿ”„Òÿ•‚Ïÿ•„Ïÿ”ƒÏÿ’ƒÐÿ‘„Õÿ�„Öÿ�„Öÿ‘ƒÑÿ•€Éÿ˜Âÿ™}½ÿ›~¼ÿš}½ÿ˜~Àÿ—~Áÿ—}Áÿ˜}Àÿ—{¾ÿ–|Àÿ–|Àÿ—|¾ÿ–{»ÿ˜z¸ÿ—{ºÿ•z¼ÿ•|¿ÿ•{¿ÿ“{Âÿ’{Ãÿ�{Äÿ�{Åÿ�{Åÿ�|Çÿ�|Éÿ‹|ÍÿŒ}Îÿ‹|Ìÿ�|ÊÿŽ{Çÿ�{Æÿ�zÇÿÆ«ÖÿÇ«ÖÿƬÖÿÆ«ÓÿɬÏÿˬËÿÌ«ÇÿΫÅÿΫÄÿÏ«ÀÿЪºÿÑ«ºÿѪºÿÒ©·ÿÑ©´ÿЩµÿϨ´ÿЧ³ÿϨ³ÿϧ³ÿЦ²ÿЦ±ÿЦ°ÿѧ®ÿÒ§­ÿÓ¨©ÿÖ©§ÿÖ©¥ÿÖ©¤ÿש¢ÿתŸÿת�ÿשžÿש�ÿÖ©�ÿשœÿØ©�ÿÖ©žÿÖ§žÿÖ§ŸÿÖ¨ ÿÖ§ŸÿÕ§ŸÿÕ¦�ÿÕ¦žÿÕ¦žÿÕ¦ŸÿÕ¦ŸÿÕ¦ ÿÔ¥¡ÿÓ¥¢ÿÓ¤£ÿÑ¢¥ÿΡ¦ÿÏ ¦ÿТ¥ÿÒ¢£ÿÒ££ÿÑ£¦ÿУ¨ÿÏ£­ÿΤ²ÿ̤³ÿÊ£¼ÿÇ£ÁÿÅ£ÇÿÁ£Ìÿ¿£Ðÿ¼£Óÿ¸¢Ùÿ´¢áÿ°¢äÿ¯¢çÿ®¡äÿ® âÿ® âÿ­Ÿâÿ­žâÿ­�áÿ¬�âÿ©�âÿ©›âÿ«šßÿ¬—Õÿ­–Óÿª—Öÿ¦–Úÿ¥—Üÿ¤—àÿ¢–áÿ¡•Þÿ¡”Ýÿ¢•Üÿ¢“Ûÿ¡“Ýÿ “ßÿJ;`ÿ ÿÿÿÿ ÿÿzhžÿ¨’Óÿ¤�Ðÿ¤ŽÏÿ¤ŽÏÿ£ŽÐÿ¤ŽÏÿ¦�Ìÿ§ŒÈÿ§�Èÿ§�Éÿ¦ŽËÿ§ŽÍÿ¥�Íÿ£�Ìÿ£ŒÍÿ£ŒÌÿ£‹Ëÿ¢‹ÌÿŸ‹Ðÿž‹Óÿ›ŒÖÿ™�Ûÿ—ŽÜÿ–�Üÿ–ŽÝÿ–�Ýÿ•ŒÜÿ•ŠÚÿ•‹Ûÿ”‰Øÿ—‰Öÿ—‡Óÿ—‡Ðÿ—†Ðÿ–†Ðÿ–†Ñÿ•†Òÿ•…Òÿ”…Òÿ’„Òÿ�„Óÿ�…ÕÿކÙÿ�†ÛÿŒ†ÚÿކÛÿކÙÿ�‡Úÿ�‡ÛÿއÙÿ�†×ÿ“„Ðÿ•„Îÿ’†Ôÿ’‡×ÿ“„Ôÿ“„Òÿ’„Óÿ’…Õÿ‘…Õÿ‘…Öÿ’…Õÿ“ƒÏÿ•€Èÿ—€Åÿ˜ÁÿšÀÿ™Áÿ˜€Ãÿ—Áÿš~¿ÿš~½ÿ™}»ÿ˜|½ÿ—|¿ÿ–|¿ÿ•|¿ÿ•|¿ÿ•|Àÿ“{Áÿ’{Ãÿ‘zÃÿ�|Æÿ�|ÇÿŽ{Æÿ�{Çÿ�{ÈÿŒ|ÊÿŒ}ËÿŒ}ËÿŒ|ÉÿŽ|Éÿ�{ÈÿŽ{Çÿ�{Çÿ�{ÈÿÅ«ÖÿƬÖÿŬ×ÿÅ­ÖÿȬÓÿʬÏÿʬËÿˬÉÿË«ÉÿÍ«ÄÿΫ¿ÿÏ«¼ÿÑ«»ÿѪ¸ÿÒª´ÿÑ©µÿÏ©µÿϨµÿÏ©µÿΨ´ÿШ´ÿϧ³ÿЧ²ÿѨ°ÿÒ¨­ÿÓ¨ªÿÖ©¦ÿÖª¦ÿÖ©¤ÿש¢ÿש ÿת ÿتŸÿØ©ŸÿתžÿØ©�ÿשžÿÖ©�ÿÖ©Ÿÿש¡ÿÖ¨ ÿÖ§žÿÖ§žÿÖ¨�ÿÕ¦žÿÖ¦ ÿÕ§¡ÿÕ§¡ÿÕ§¡ÿÕ¦¡ÿÔ¦¡ÿÔ¦ ÿÓ¥¡ÿÓ¤¢ÿÒ£¤ÿÑ£¥ÿÑ£¤ÿÒ£¦ÿѤ¦ÿÑ£¨ÿФ¬ÿΤ¯ÿÌ£²ÿ̤·ÿÉ£¾ÿÄ¥Åÿ¤Íÿ¿¤Òÿ¼£Ôÿº£Øÿ¶¢Üÿ³¢Þÿ³£ãÿ°¡âÿ¯¡ãÿ­Ÿãÿ« åÿ©žäÿ©�ãÿ¨�äÿ§�åÿ¨œäÿªšáÿ¬šØÿ¬™×ÿ§™Üÿ¤šâÿ£˜ãÿ¡˜åÿ ˜ãÿ¢—âÿ£–àÿ¡”Þÿ¡•àÿ ”áÿ˜�Ýÿ?6bÿÿ ÿ ÿ + ÿ ÿÿdUŽÿ§”Øÿ£�Òÿ¤�Ñÿ¤�Ðÿ£ŽÐÿ¤ŽÎÿ¤�Íÿ¥ŽÍÿ¦�Ìÿ¥�Ìÿ¥�Êÿ¥ŽÍÿ£�Ñÿ¡�Òÿ¡ŒÐÿ¢ŒÏÿ¢‹Ìÿ¢‹ÍÿŸ‹Ñÿ�‹Ñÿ�‹Òÿœ‹ÔÿšŒÖÿ˜ŽÝÿ•�âÿ”�âÿ”Žßÿ•�ßÿ“‹Üÿ‘‰Ùÿ‘ˆÙÿ’ˆÙÿ’ˆØÿ’ˆØÿ‘‰Ûÿ�ŠÝÿ‘ŠÜÿ�ˆÛÿ�ˆÛÿ�ˆÜÿ�‡Þÿ‹‡ÞÿŒˆáÿŠˆáÿ‹ˆáÿŒˆàÿŒˆßÿ�‰ßÿŽˆÝÿއÚÿ�‡Úÿ‘‡×ÿ’†Öÿ�ˆÙÿ‘‡Ùÿ‘†×ÿ�†Øÿ�‡Ùÿ�‡Ùÿ‘…Õÿ‘…Óÿ’ƒÐÿ‘‚Îÿ”�Êÿ–�Éÿ–�Æÿ—€Åÿ–€Æÿ•€Çÿ•€Åÿ—~Âÿ˜~Àÿ˜}¿ÿ˜~¿ÿ–}Áÿ“}Âÿ’}Äÿ’}Äÿ�{Äÿ‘{Äÿ�yÃÿ�zÄÿ�{Èÿ�|Èÿ�{ÈÿŒzÇÿŒ|Êÿ‹{Éÿ‹|Êÿ�{ÈÿŒ{ÅÿŒzÇÿŒ{ÉÿŒ|ÉÿŒ|Éÿ‹{ÉÿǬ×ÿŬØÿŬÙÿƬ×ÿƬÕÿȬÓÿɬÏÿɬÎÿˬËÿË«ÉÿÍ«ÆÿÏ«ÂÿЫ¾ÿÑ«»ÿѪ¹ÿÒ«¹ÿЪºÿЪ¸ÿѪ¶ÿÑ©µÿÏ©µÿЩµÿѨ´ÿѧ°ÿÒ¨­ÿÕ©«ÿÕ©§ÿÖ©¦ÿÖª§ÿת¦ÿÖ©¢ÿת¡ÿת¡ÿת ÿت ÿש ÿת¢ÿת¢ÿש£ÿש¢ÿÖ¨ ÿÖ¨ ÿר ÿÖ¨ŸÿÖ¨ŸÿÖ§ ÿ×§¡ÿÖ§¡ÿÕ§¡ÿÖ¨¡ÿÕ¦ ÿÕ¦ ÿÕ¥ŸÿÕ¦ ÿÔ¦¡ÿÔ¦¤ÿÓ¥¤ÿÓ¤¦ÿÒ¤¦ÿÒ¤¨ÿФ«ÿϤ¯ÿΤ²ÿ̤·ÿʤ¼ÿÆ¥Äÿ¤Ìÿ¿¥Óÿ¾£Õÿº¢Øÿ¸¢Üÿµ¡Þÿ´¡Þÿ²¢áÿ± ãÿ¬ äÿ« åÿªžåÿ©žåÿ§�æÿ¦�æÿ§�äÿªšàÿ«˜Øÿ¨šÞÿ£šäÿ¢›çÿ ™æÿ ™æÿž™çÿŸ˜åÿ¡–áÿ¡–áÿ¡–áÿŸ”àÿ�‡Ïÿ*+ÿÿÿÿÿÿ ÿMAfÿ¢‘×ÿ£�Óÿ¤�Ñÿ¤�Ðÿ£�Ñÿ¢ŽÏÿ¥ŽÎÿ¥ŽÎÿ¤ŽÎÿ¤ŒÍÿ¢ŽÑÿ¡ŽÕÿŸŽÕÿŸŽ×ÿ ŽÕÿ¡‹Ïÿ¢‹Ëÿ ‹Ïÿž‹ÐÿžŠÏÿ�ŠÐÿœ‹Ôÿ™ŒÙÿ–�Ýÿ•�ãÿ”Žâÿ’Žâÿ’Žãÿ‘Žäÿ�‹àÿ�‹àÿŽ‹áÿ�‹ãÿ�ŒãÿŽ�æÿ��çÿŽŒåÿ�ŒäÿŒŒäÿ‹Œåÿ‹Œäÿ‹‹ãÿ‹Šäÿ‹ŒåÿŒ�åÿ‹‹äÿŒŠåÿŒŠâÿ�‰Þÿ�‰Ýÿ�‰Þÿ�ˆÛÿ�‰Úÿ‘‰Úÿ‘‡Ùÿ‘ˆÙÿ’ˆÚÿ�‡Ûÿ�‡Ùÿ�†×ÿ�„Ôÿ’„Òÿ’ƒÑÿ’‚Îÿ•‚Ìÿ•‚Ëÿ•‚Ëÿ•�Ëÿ•‚Ìÿ”�Ëÿ“€Éÿ“Çÿ”~Åÿ•~Æÿ“~Æÿ’~Çÿ‘}Éÿ‘}Èÿ�|Çÿ�{ÄÿŽyÃÿŒzÆÿ‹{Éÿ‹{ÉÿŠ{Èÿ‹zÈÿ‹zÈÿ‹{Èÿ�zÆÿ�yÄÿ�yÄÿ�{Æÿ‹{ÈÿŒ|ÉÿŒ{ÊÿŒ{ËÿÇ­×ÿÇ­×ÿÆ­ØÿÇ®×ÿƬÕÿÇ­ÔÿǬÔÿȬÒÿʬÎÿˬËÿË«Êÿ̬ÆÿÍ«ÂÿÏ«¿ÿЫ½ÿЫ»ÿÑ«¼ÿЪ¹ÿѪ¶ÿЪµÿЩµÿЩµÿÑ©´ÿÒ©±ÿÒ¨®ÿÔ©­ÿÕª«ÿÕªªÿÖª¨ÿÖ«§ÿÖ«¦ÿת¤ÿת¤ÿת¥ÿת¥ÿت§ÿת¦ÿת¥ÿת¥ÿØ«£ÿת¢ÿש¡ÿש ÿש ÿר¡ÿש ÿÖ¨¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¡ÿÖ§¢ÿÖ§¡ÿÖ§ ÿÖ§ ÿÖ§ ÿÖ§ ÿÕ§¢ÿÔ§£ÿÓ¦¦ÿÓ¥¨ÿÐ¥«ÿÏ¥¯ÿÎ¥³ÿˤ¸ÿÉ¥¼ÿÆ¥Ãÿ¤Ìÿ¾¤Óÿ»£Öÿº£Úÿ·£Ýÿµ¢Þÿ²¢àÿ±¢âÿ°¢ãÿ¬ äÿªŸæÿ©žæÿ©žæÿ§žæÿ¦�æÿ¦›ãÿ¨šâÿ©šßÿ¦šáÿ¥šâÿ¢›åÿ¡šåÿ ™åÿžšçÿž›ëÿ�šéÿžšéÿ�˜æÿŸ–ãÿxm©ÿ(%ÿ!ÿ#ÿ#ÿ$ÿ"ÿ ÿ?/Iÿ•„Äÿ¤‘Ôÿ¤�Òÿ£‘Óÿ¢‘Õÿ¢�Óÿ¤�Òÿ¤�Òÿ£ŽÑÿ£�ÒÿŸ�Öÿ›�Ûÿš�Ûÿ›�Úÿ›�ÖÿžŒÓÿŸ‹Ðÿ�ŒÓÿœ‹Óÿ›‰ÒÿšŠÓÿ˜‹Øÿ–�Üÿ”Žßÿ“�áÿ‘Žäÿ�Žåÿ‘’éÿ�‘çÿ��åÿ��çÿ��éÿ�‘êÿ�’éÿ�‘éÿ��èÿŽ�èÿŽ‘èÿ��éÿŒ�èÿŒŒäÿ�ŠãÿŽŒäÿŒŒåÿŒ�æÿ‹ŒåÿŒŠäÿ�‰áÿ�‰ßÿ�‰Þÿ�Šßÿ�ŠÝÿ‘‰Üÿ‘ŠÛÿ‘ŠÛÿ’‰Ûÿ‘ˆÛÿ�ˆÛÿ�‡Úÿ�†×ÿ�…Õÿ�„Ôÿ‘„Óÿ’„Óÿ’„Ñÿ“„Òÿ’ƒÑÿ’ƒÐÿ’‚Ðÿ‘‚Ïÿ’€Íÿ’€Ëÿ’€Ëÿ’~Èÿ’~Éÿ�~Êÿ�~Ìÿ�~Ëÿ�|ÈÿŽ{Åÿ�{Æÿ‹|Ëÿ‰|ÍÿŠ|ÍÿŠ{ËÿŠ{Éÿ‹{Èÿ�{ÇÿŽzÅÿ�yÃÿ�zÄÿŒzÇÿŒ{ÈÿŒzÇÿŒzÇÿŒzÇÿÈ®ÖÿɯÖÿÈ­ØÿÆ®ØÿÆ®ØÿÇ­ÖÿÆ­ÔÿǬÓÿÈ­ÏÿɬÌÿɬÍÿɬÎÿɬËÿˬÈÿÏ«ÂÿÏ«¾ÿϬ¼ÿЬ¼ÿѪ¹ÿЪºÿЫ»ÿϪ¸ÿЪµÿÑ©³ÿÒ©°ÿÓ©¯ÿÔ©­ÿÕª­ÿÔ«¬ÿÕª«ÿÕªªÿÖ«¨ÿת§ÿת¨ÿÖª©ÿÖ««ÿת©ÿת¨ÿת¦ÿ׫¤ÿת¢ÿØ©¡ÿת¡ÿש ÿØ©£ÿש£ÿר£ÿÖ©£ÿÖ©£ÿÕ¨¤ÿÖ¨¢ÿÖ¨¢ÿÖ¨¡ÿÕ§ ÿר ÿÖ¨ŸÿÖ§ŸÿÖ¨¡ÿÕ§¤ÿÓ¦¨ÿÒ¦­ÿÏ¥±ÿÍ¥´ÿÌ¥ºÿʦ¿ÿÆ¥ÅÿÃ¥Ëÿ¾£Õÿº£Ùÿ·£Ýÿ¶£ßÿ´£àÿ±¢ãÿ¯¢åÿ¯¡äÿ¬¡æÿ¨ çÿ§Ÿçÿ¦Ÿæÿ¨žåÿ¦œâÿ¦›âÿ§›âÿ¦šàÿ¦™àÿ¦šáÿ¤›äÿ¢›åÿ¡œèÿŸœéÿœœëÿœžîÿ›Ÿîÿ››êÿœ—åÿma“ÿ'"ÿ%!ÿ$ ÿ% ÿ%ÿ#ÿ#ÿ/"2ÿŽ}¹ÿ£‘Ôÿ£‘Öÿ£‘Öÿ¡‘Øÿ¢‘×ÿ¢‘Öÿ¢‘×ÿ¢�Ôÿ¡ŽÔÿŸ�Öÿ›�Üÿ˜�àÿ—�Ýÿš�Ûÿ›�×ÿ�ŽÕÿœŒÕÿšŒ×ÿ˜ŒØÿ–�Üÿ”�ßÿ“�âÿ‘�äÿ’�åÿ��çÿ�‘éÿ�’êÿ�‘éÿ��èÿ��èÿ�’ëÿ�“êÿ�“ëÿ��èÿŽ�èÿ��çÿŽ�çÿŽ�çÿ��åÿŽ‹áÿ�ŠÞÿ‘‰Ýÿ�ŠáÿŒ‹äÿŒ‹âÿŽˆßÿމßÿމßÿމßÿ�Šßÿ‘ŠÝÿ‘ŠÜÿ‘ŠÛÿ�ŠÜÿ‘ŠÝÿ�ŠÜÿ�ˆÛÿ‘ˆÚÿ‘ˆÙÿ‘†×ÿ�†Öÿ�†Õÿ�…Õÿ’†Öÿ�„Ôÿ�…Ôÿ�„Õÿ�ƒÔÿ�‚Òÿ��Ñÿ�€Îÿ‘Ìÿ�~Ìÿ�Ìÿ�~ÍÿŽÍÿ�~ËÿŽ{Æÿ�|ÇÿŒ|Éÿ‰}Íÿˆ}Ñÿˆ|Íÿˆ{Ëÿ‰zÊÿŠzÇÿŒyÅÿ�yÄÿ�yÄÿ�yÅÿ‹yÅÿ‹yÅÿ‹xÃÿ‹xÄÿ‰xÄÿǯØÿǯØÿǯÚÿÆ®ÚÿÆ­ÛÿÇ­ÙÿÇ­ØÿÇ­ÖÿÈ­ÓÿÇ­ÒÿȬÓÿǬÔÿȬÕÿɬÒÿɬÌÿ̬ÈÿͬÅÿάÂÿάÀÿÏ«¿ÿЪ½ÿЫ»ÿЪºÿÒ«·ÿÒªµÿÔª´ÿÓª²ÿÔ«±ÿÕ«±ÿÕª±ÿÖ«¯ÿ׫¬ÿ׫ªÿÖ«©ÿ׫«ÿ׫¬ÿÖ««ÿÖªªÿ׫¨ÿØ«¥ÿØ«¤ÿت¢ÿت£ÿت£ÿש¤ÿת¦ÿت¦ÿת§ÿÖª¦ÿÖ©¦ÿÖ©¦ÿÖ¨£ÿÖ¨¤ÿר¢ÿר¢ÿש¡ÿר¡ÿר¢ÿר¥ÿÕ§§ÿÒ¦¬ÿЦ±ÿΦ´ÿ̦ºÿɦÀÿǦÉÿÁ¤Ðÿ½¤×ÿ¸¤Þÿµ¤àÿ´¤áÿ³£âÿ°¤äÿ¯¢æÿ®¢æÿ¬ èÿ© çÿ¦žçÿ§�äÿ©œàÿª›Þÿ©œáÿ¨œãÿ©�âÿªšßÿ§›âÿ¥›åÿ¢œçÿ¡œçÿžœèÿœ�ìÿœŸîÿ›žîÿœ›êÿŸ—äÿpd—ÿ ÿ + ÿÿÿÿÿ ÿ&%ÿ‹{¸ÿ¡‘×ÿŸ‘Øÿ �×ÿ¡‘ØÿŸ‘Ùÿž‘Úÿž‘Ùÿ�‘Úÿž�Øÿ��×ÿ›�Üÿš�Þÿ™�Ýÿ˜�Ýÿ™�Üÿœ�Úÿ›ŽÙÿ™�Úÿ—ŽÝÿ”Žâÿ‘Žåÿ‘�æÿ��æÿ�Žåÿ‘�èÿ‘“êÿ‘”ëÿ‘“ëÿ‘’éÿ‘’éÿ‘”ëÿ�’êÿ‘�çÿ‘�çÿ‘‘çÿ‘Žäÿ‘Žäÿ�Žäÿ�Œâÿ�‹áÿ‘ŠÞÿ‘ŠÞÿ�Šàÿ�‹áÿ�Šßÿ�‰Ýÿ‘ŠÞÿ�Šßÿ�‰ßÿ‘ŠÞÿ‘ŠÝÿ‘ŠÜÿ�‰Üÿ‘ŠÝÿ‘ŠÝÿ‘‰Ûÿ‘‰Ûÿ’‰Úÿ‘ˆÙÿ‘ˆÙÿ‘‡Øÿ‘‡Ùÿ‘†×ÿ‘†×ÿ�…Öÿ�…Öÿ�…×ÿŽ„ÖÿŽ„×ÿ�ƒÕÿ�‚ÔÿŽ�Òÿ��ÑÿŽ€Ñÿ�Îÿ�~Ëÿ�}Éÿ�{ÅÿŽ{ÅÿŒ|Çÿ‹}Íÿ‰|Îÿ‰|ÌÿŠ|Êÿ‹zÆÿ‹yÄÿŒyÃÿŒxÃÿ‹wÁÿ‹w¿ÿ‹vÀÿŠv¿ÿˆt½ÿˆt¼ÿ‡s½ÿǰÛÿƯÛÿƯÜÿįÝÿÅ®ÝÿƯÛÿÅ®ÛÿÆ®ÛÿÆ­ÚÿÅ®ÙÿÆ­ÙÿÆ­ØÿÆ­ÙÿÆ­ÙÿÆ­ÕÿÈ­ÒÿÉ­ÏÿÊ­ÌÿˬÉÿͬÄÿЫÀÿЫ¾ÿЫ½ÿЫ»ÿÑ«¹ÿÑ«¹ÿÓ«ºÿÓ«·ÿÓ«µÿÔ¬²ÿÕ«¯ÿÖ«®ÿ׬­ÿ׬¬ÿ׬©ÿج©ÿ׬©ÿ׬©ÿ׫¨ÿØ«§ÿ׫¦ÿØ«§ÿØ«¦ÿØ«¦ÿت§ÿת¨ÿØ«§ÿÖ«¨ÿÖª¨ÿÖª¨ÿÕ©§ÿÔ¨¦ÿÕ¨¥ÿÖ©¦ÿÖ©¥ÿש¤ÿØ©¤ÿש¤ÿש§ÿÕ¨¨ÿÕ¨ªÿÒ§®ÿϧµÿͨºÿʧÁÿƧÊÿ¦Ñÿ¾¦×ÿ¸¥Ýÿµ¥ãÿ³£âÿ±£åÿ¯£æÿ­¢çÿ­¢çÿ¬¡çÿ©Ÿçÿ¨žåÿ©œáÿ¬›Üÿ¬›Üÿªœáÿ¨œäÿ©œáÿ«›Þÿ¨›àÿ¥›ãÿ£œåÿ œçÿŸ›éÿ��ëÿœ›ìÿ›œëÿ�™çÿ ˜àÿwi›ÿÿÿ ÿ ÿ + ÿ ÿÿ%%ÿ�Áÿž‘Ûÿ�’Ýÿž’Ýÿ�‘Üÿ�’Þÿ�’Ýÿž‘Üÿœ‘Ûÿ�‘Úÿœ�Ûÿ›�Üÿ™�Üÿ—�ßÿ—‘áÿ–�Þÿ™�ßÿ™ŽÝÿ—�Ûÿ•�Þÿ“Žáÿ��åÿ‘Žæÿ‘�æÿ‘Žåÿ‘’éÿ‘”êÿ‘•êÿ‘•ëÿ’“êÿ“�æÿ“�çÿ“�æÿ“Žäÿ”Žâÿ”Žâÿ”Žßÿ”�Þÿ’�àÿ‘�âÿ�Œãÿ�‹áÿ�Šàÿ�Šßÿ�‹ßÿ‘‹Þÿ‘‹Ýÿ’ŒÞÿ’‹Ýÿ’‹Üÿ’‹Þÿ’‹Þÿ’ŒÞÿ‘‹Ýÿ‘‹Ýÿ’‹Ýÿ’‹Ýÿ’ŠÛÿ’ŠÛÿ’‹Ûÿ‘ŠÜÿ‘‰Úÿ‘ˆÚÿ’‡Ùÿ‘†×ÿ�‡Øÿ�†ÙÿކÙÿ�…Úÿ�„Ùÿ�ƒÖÿ�ƒÒÿ�‚Ðÿ�€ÎÿŽÌÿŽ~Èÿ�}Èÿ�}Çÿ�{Åÿ�zÃÿŽ{ÅÿŒ|Èÿ‹{Èÿ‹zÆÿ‹zÃÿ‹wÀÿŒxÀÿŒyÂÿ‹wÁÿ‹w¾ÿ‹tºÿ‹r·ÿ‹r¶ÿŠrµÿŠq²ÿŠo¯ÿưÝÿǯÛÿƯÜÿŰÝÿįÞÿÄ®ÞÿÅ®ÞÿÅ®ÞÿÄ­ÝÿîÝÿÄ®ÝÿÄ®ÜÿÄ­ÚÿÄ®ÝÿÅ­ÝÿÄ­ÜÿÄ­ØÿÆ­ØÿÈ®ÒÿˬÌÿͬÆÿάÂÿάÂÿÏ«ÃÿÏ«¿ÿÏ«¾ÿѬ¿ÿÑ«¼ÿЫ¹ÿÓ¬·ÿÔ¬¯ÿÕ«¯ÿÖ«¯ÿ׬­ÿÖ­«ÿ×­«ÿجªÿ׬©ÿج©ÿجªÿ׬ªÿ׬©ÿØ­©ÿÖ«¨ÿ׫¨ÿÖª©ÿÕ«©ÿÕª©ÿÖ©ªÿÔª©ÿÕ©©ÿÔ©ªÿÔ¨©ÿÕ¨©ÿÕª©ÿת§ÿÖ©¦ÿש§ÿÕ©¨ÿÔ©©ÿÔ¨ªÿѧ®ÿϨ³ÿͨ»ÿʨÂÿǧÊÿçÏÿÀ¦Õÿ»¦Üÿ¶¤Þÿ´£àÿ°£äÿ­£çÿ«¢çÿª¡çÿª¡çÿªŸæÿ¨žãÿ«œßÿ¬›Úÿ¬šÙÿ©œßÿ¨�äÿ¨œâÿ©œàÿ©›àÿ¥›áÿ¡›åÿ œèÿŸ›çÿ�›éÿ�œêÿ››éÿž˜åÿ •Þÿ�r©ÿ$ÿÿ ÿÿ ÿÿÿ(*ÿ”†Ëÿœ‘Ûÿœ‘Þÿœ’ßÿœ“ßÿ�“àÿž“ÞÿŸ“Ýÿž’Ûÿ�’Ýÿš‘Ýÿ˜�Ýÿ–�áÿ•‘âÿ•�áÿ–�áÿ•�àÿ—�Þÿ˜�Úÿ–�Úÿ”ŽÞÿ”�àÿ“�ßÿ“Žáÿ’�ãÿ‘�åÿ�‘çÿ‘”êÿ�•ëÿ”‘åÿ˜�Üÿ˜ŽÚÿ™ŽÚÿš�Úÿ™ŽÜÿ—ŽÛÿ—�Üÿ–�Üÿ•�Þÿ“�àÿ��ãÿ�‹àÿ’‹Þÿ’‹Ýÿ’‹Üÿ‘‹Þÿ‘ŒÞÿ’ŒÝÿ“‹Ýÿ“ŒÝÿ’ŒÝÿ“ŒÞÿ’Œßÿ’ŒÞÿ’ŒÞÿ“ŒÞÿ’ŒÞÿ‘‹Þÿ’Œàÿ‘‹Þÿ‘‹Þÿ’ŠÝÿ‘ŠÜÿ’ˆÚÿ’‡Øÿ‘‡Øÿ�†ØÿއÚÿŽ…ÖÿŽƒÔÿ�‚Ôÿ��Îÿ�Ìÿ�Êÿ�~Èÿ�|Åÿ‘}Åÿ�|ÄÿŽzÃÿ�{Áÿ�{Âÿ�{Äÿ�zÄÿŽyÁÿ�w½ÿŽv¹ÿŽu¶ÿ�u·ÿ�t¸ÿ�uºÿŒs·ÿŽr°ÿ�q¨ÿŽp¨ÿ�n¥ÿŒm£ÿȱÝÿDZÝÿǰÜÿưÝÿůàÿůàÿİàÿİáÿįâÿðãÿ¯áÿįàÿîßÿ®àÿ®àÿîàÿíàÿÄ­ßÿÅ­ÚÿÈ­ÓÿÉ­ÍÿË­Ëÿ̬ÉÿÌ­ÈÿͬÆÿͬÅÿάÃÿÏ«¾ÿϬ¾ÿѬ¼ÿÓ«¶ÿÔª²ÿÕ¬±ÿÖ­±ÿÖ¬¯ÿÖ­­ÿج®ÿ×­­ÿÖ¬®ÿÖ­­ÿÖ­­ÿÖ¬¬ÿ׬«ÿØ«©ÿתªÿÕ««ÿÖ«¬ÿÕª¬ÿÕª¬ÿÔª¬ÿÔ©­ÿÔ¨­ÿÔ¨­ÿÔ©­ÿÔ©¬ÿÕªªÿÖª©ÿת«ÿש«ÿÖ©«ÿÓ¨­ÿÓ¨¯ÿѨ´ÿΨºÿʨÃÿǨËÿħÏÿÁ§Ôÿ½¦Øÿ»¥Ûÿµ£ßÿ³£äÿ­¢åÿ«¡æÿª¡çÿ©Ÿæÿ©Ÿæÿ©žåÿª�áÿ«œßÿ«›Ýÿªœßÿ©�äÿ¨�äÿ©�ãÿ©œàÿ¦›âÿ¢œçÿ¡šäÿ ™åÿŸšæÿœ›éÿœšéÿž—äÿŸ•Þÿ¢•ßÿiX†ÿÿÿÿÿÿ0$<ÿr­ÿ£•Ýÿž’Ùÿœ‘Þÿ›’ßÿ›’àÿœ”áÿ�“àÿž“ÞÿŸ“Üÿž’Úÿ��Ùÿœ�Ûÿ–‘ãÿ•‘äÿ•�âÿ•�áÿ•Žàÿ•�ßÿ—ŽÝÿ—�Üÿ—ŽÞÿ•�Üÿ”�Üÿ”Žßÿ•Žàÿ•�ßÿ”Žàÿ“‘çÿ“‘æÿ˜�Úÿœ‹ÔÿœŒÒÿ�ŒÓÿ�‹Ôÿ›ŒØÿš�Ùÿ™�ÙÿšŒØÿ˜ŽÛÿ•�Þÿ•�ßÿ”ŒÚÿ•ŒÙÿ”ŠÙÿ”‹Ùÿ“ŒÚÿ”ŒÜÿ”ŒÜÿ“ŒÝÿ“ŒÞÿ“�Þÿ“ŒÞÿ“ŒÞÿ“ŒÞÿ“ŒÞÿ“�Þÿ“�Þÿ’�ßÿ‘Œàÿ‘Œàÿ�‹Þÿ‘‹Þÿ’‹Ýÿ“ŠÛÿ“ˆÙÿ‘‡×ÿ�‡Øÿ�…Õÿ‘ƒÑÿ‘‚Ïÿ‘‚Îÿ�€Ìÿ‘€Êÿ‘€Èÿ’~Æÿ’|Âÿ“|¾ÿ’{¾ÿ“z»ÿ“zºÿ“y¹ÿ“y¹ÿ‘x¹ÿ‘x¹ÿ�w¶ÿ‘t±ÿ’t«ÿ’s¨ÿ�q©ÿŽq¬ÿŽq®ÿŽp§ÿ�n¡ÿ�nžÿ�mœÿ�k›ÿʲÛÿȱÞÿDzßÿƲàÿŲáÿűâÿıâÿñãÿñäÿ¯äÿÁ¯äÿ¯äÿ¯ãÿÁ°äÿ°äÿ®âÿ®âÿ®áÿíÝÿÄ­ÚÿÇ­ÖÿǬÔÿɬÐÿË­ÎÿÊ­ÍÿÊ­ÍÿʬËÿ̬ÇÿͬÅÿϬÃÿЬ½ÿÓ¬¸ÿÔ¬¶ÿÔ¬µÿÖ¬²ÿÖ¬°ÿÖ­¯ÿÖ­¯ÿÖ­¯ÿÖ­°ÿÖ¬¯ÿÖ¬®ÿÖ«­ÿÖ¬­ÿÖ«­ÿÕ«­ÿÕª®ÿÔª¯ÿÔª¯ÿÔ©°ÿÒ¨°ÿÓ©°ÿÓ©°ÿÓ©°ÿÔ©®ÿÕª¬ÿÕª¬ÿÖª¬ÿÖª¬ÿÔ©¬ÿÓ©¯ÿÓ©²ÿÏ©µÿΩ¼ÿɨÆÿƨÍÿèÑÿ¿¦Õÿ»¦Üÿ·¥ßÿµ¥áÿ±£äÿ­¢åÿ«¢æÿ© çÿ§ çÿ¨Ÿæÿ¨žåÿ©žäÿªžãÿ«�ßÿ«�àÿ«œàÿ©žãÿ«žàÿ¬›Üÿ¨�áÿ¤œäÿ¢šäÿ¡™äÿŸ™åÿ�šèÿ�›éÿž—ãÿŸ–àÿ¢—âÿŒ|¼ÿÿÿÿ ÿÿ,1ÿ£‘Õÿ¡�Ôÿ �ÖÿŸ‘ØÿŸ‘ÚÿŸ’Ýÿž“ßÿž“ßÿž”ÞÿŸ“Ûÿ ’ÚÿŸ�Ùÿ�‘Üÿ˜’ãÿ—‘ãÿ—�áÿ–�áÿ•�áÿ”�áÿ•ŽÞÿ˜ŒÚÿ—�Úÿ—‹Ùÿ—ŠØÿ—‹×ÿ˜‹×ÿ˜ŒØÿ—ŽÝÿ—�àÿ™ŽÜÿ��ÖÿŸŽÒÿ ŒÏÿ ‹Îÿ ‹Òÿ�ŒÖÿ�ŒÔÿ›ŠÓÿ›‹Óÿ™ŒÖÿ™�Ûÿ™�ÚÿšŒÖÿšŒÔÿ™Œ×ÿ˜‹Ùÿ—ŒÙÿ•ŒØÿ”ŒÚÿ”ŒÝÿ“�Þÿ“ŒÞÿ“�ßÿ”ŒÞÿ”�Ýÿ•ŒÜÿ”ŒÜÿ“ŒÝÿ’ŒÝÿ’‹ßÿ�‹àÿ�‹ßÿ‘‹Ýÿ’‰Ûÿ”‰Ùÿ”ˆ×ÿ”ˆ×ÿ‘…Ôÿ’ƒÏÿ”‚Ëÿ“€Êÿ“€Èÿ“Çÿ“€Æÿ“~Äÿ”}Àÿ•{¼ÿ”y¸ÿ•xµÿ•x´ÿ•x°ÿ”w¯ÿ”w°ÿ’v°ÿ’u±ÿ’u®ÿ’r§ÿ’r¤ÿ“q ÿ‘ožÿ�o£ÿ�o£ÿ�nŸÿ‘lšÿ�l—ÿ�k–ÿ�j”ÿʲÚÿɲÜÿƲâÿŲâÿƲãÿIJäÿòäÿÁ±åÿÁ±æÿÀ±æÿ¿±çÿ¿°èÿ¾°çÿ¿°æÿÀ°åÿ¯ãÿÁ®âÿÀ®ãÿÀ®âÿÁ­àÿîÜÿÅ­ÚÿÅ­ØÿÇ­ÖÿÈ­ÔÿǬÒÿǬÒÿȬÐÿÊ­Ìÿ̬ÈÿΫÄÿϬ¾ÿÒ­ºÿÓ­¸ÿÔ­¸ÿÕ­µÿÖ­³ÿÕ¬²ÿ×­²ÿÖ­²ÿ×­°ÿÖ­¯ÿÖ¬°ÿÖ¬°ÿÔ«¯ÿÕ¬¯ÿÔ«°ÿÔª±ÿÓª²ÿÓ«³ÿÒ©³ÿÒ©´ÿÒª²ÿÒ©²ÿÓª±ÿÓ©¯ÿÓª­ÿÕª­ÿÕª®ÿÔ©®ÿÓ©±ÿÒªµÿϪºÿ̪ÁÿÈ©ÊÿèÐÿÁ¦Õÿ¼¥Úÿ·¦ßÿµ¦âÿ´¥ãÿ±¤äÿ­£æÿ«¢èÿ§¡èÿ¥ éÿ¦Ÿçÿ¦žåÿªžãÿªžâÿªžßÿ¬œÝÿ¬œÚÿ«�Ýÿ­œÚÿ­œÚÿ©œÝÿ¦›áÿ£šâÿ¡™ãÿž˜äÿž™æÿ�˜åÿ�—âÿž—âÿ ˜äÿŒ�Èÿ#ÿÿ"ÿÿÿ2'>ÿ ŽÔÿ �Ôÿ¡�Ñÿ¤�Ñÿ£�Òÿ¡’Òÿ¢‘Ôÿ “ÜÿŸ”ÞÿŸ“ÝÿŸ“Üÿ�’Üÿœ’áÿ™�áÿ˜�Ýÿ™�Ûÿ—�ßÿ•�áÿ•�Üÿ–‹Øÿ—ŠÕÿ•ŒÙÿ—‹Úÿ™‹Ôÿ›‹Ñÿ›‹ÓÿšŒÕÿš�Ùÿœ�Øÿž�Ôÿ ŽÒÿ¡ŽÑÿ¡�Ëÿ¡ŒÍÿ �Ñÿž�Òÿ�‹ÒÿŸ‹ÑÿžŠÐÿœŒÕÿœ�Öÿ›ŒÕÿœŒÓÿ�ŒÓÿš�Õÿ˜ŒÖÿ™�×ÿ—�Øÿ•ŒÚÿ”ŒÜÿ“�Ýÿ’�ßÿ“Žàÿ•�Ýÿ—‹Ùÿ—Š×ÿ—‹Øÿ–Š×ÿ”ŠØÿ’‹Ûÿ�‹Üÿ�ŠÜÿ’ŠÚÿ“‰Øÿ“‡Öÿ”‡Õÿ’†Òÿ“„Ïÿ“‚Ëÿ”€Æÿ•Äÿ–Ãÿ•|¾ÿ•|¼ÿ–|»ÿ•yµÿ”y´ÿ•w³ÿ“u¬ÿ“tªÿ•u©ÿ•uªÿ“t¨ÿ”s¦ÿ“s¥ÿ“r¢ÿ”qžÿ”p�ÿ’o›ÿ’oœÿ�nŸÿ�nžÿ‘nšÿ�k–ÿ�k“ÿ�i�ÿ�i�ÿ̳ÜÿʳÝÿȲÞÿȳàÿDzáÿDzâÿŲãÿòäÿÁ²æÿ¿²éÿ¾²ëÿ¾³ìÿ¾²ëÿ¾±êÿ¿°çÿÀ°åÿÀ°åÿ¿¯æÿ¿¯åÿÀ®äÿÁ®âÿ®ßÿ­ÞÿÄ®ÜÿÄ­ÙÿÆ­ØÿŬØÿÆ­×ÿȬÑÿÊ­ÌÿˬÈÿͬÅÿѬ¿ÿÑ­¼ÿÒ­¼ÿÓ®»ÿÔ­¹ÿÖ­·ÿÖ­µÿÖ­´ÿÖ¬³ÿÖ­³ÿÖ¬³ÿÖ­´ÿÕ¬³ÿÕ¬³ÿÕ«³ÿÔ«²ÿÔ«³ÿÓ«³ÿÓ«µÿѪ¶ÿѪ¶ÿÒ©´ÿÓª³ÿÔª±ÿÔª°ÿÕª¯ÿÔª°ÿÔª±ÿÓª²ÿѪ¶ÿÏ«¼ÿʪÄÿƪÎÿ©Ôÿ¾§Ùÿ¼¦Üÿ¸¥ßÿµ¦âÿ³¥ãÿ±¤ãÿ¯¤æÿ«£èÿ©¢èÿ§¡éÿ¦ éÿ¥žèÿ§žæÿ©žäÿ«žâÿ­�Ýÿ­œÚÿ®œÙÿ¯œØÿ®œØÿ«›Úÿ¨šÜÿ£˜Þÿ ˜áÿž—âÿž˜ãÿ�–áÿž•àÿž–àÿŸ–áÿœ‘Ýÿ(#ÿ ÿÿ + ÿ ÿTGmÿŸ‘Úÿ�‘Ùÿ �Ôÿ¢�Ôÿ¢‘Ôÿ¢‘ÓÿŸ‘×ÿŸ“Üÿž”ßÿ�“àÿž”àÿ›’ßÿ›’ßÿš‘Þÿš�Ûÿ™ŽÙÿ˜ŽÚÿ—�Üÿ—ŒÚÿ˜‹×ÿ—‹Öÿ•ŒÛÿ•ŒÙÿ™‹Òÿ�‹Ðÿ›ŒÓÿœ�Öÿ��ÖÿŸŽÔÿ¡ŽÓÿ¢ŽÑÿ¢�Íÿ£�Ìÿ¡�Îÿ ŒÐÿ ŒÑÿŸŒÒÿž‹ÐÿŸŒÐÿ�ŒÔÿ�ŒÔÿœŒÔÿœŒÕÿ›ŒÕÿœŒÕÿœ�Õÿ›ŒÔÿš‹Ôÿ˜ŒØÿ—ŒÚÿ–ŒÚÿ–�Ûÿ•ŒÚÿ˜Œ×ÿ˜‹Ôÿ˜ŠÓÿ™‰Ñÿš‰Ñÿ˜‰Óÿ–ŠÕÿ–‰×ÿ•‰Öÿ•‰Ôÿ–‡Ôÿ•‡Óÿ–‡Óÿ”†Ðÿ“ƒÍÿ”‚Èÿ•Ãÿ–~Àÿ—}½ÿ—{¹ÿ—zµÿ—y°ÿ—x¬ÿ•v«ÿ–vªÿ–u¦ÿ•t£ÿ–t¤ÿ”t¤ÿ“s¤ÿ“s ÿ”q›ÿ”q˜ÿ•p–ÿ–p–ÿ”o—ÿ“ošÿ’o�ÿ’n�ÿ‘m™ÿ’l“ÿ‘j�ÿ‘j�ÿ�i�ÿË´Ýÿ̳ÚÿË´ÛÿʳÜÿȳßÿdzßÿƲáÿIJãÿóåÿÁ²èÿ¿´ëÿ¾³ìÿ½³íÿ¼³ìÿ¼²ìÿ½±ëÿ½±êÿ¾°èÿ½¯èÿ½¯æÿ¿®äÿ¿¯äÿÀ¯âÿÁ®áÿ®ßÿíÝÿíÜÿÄ­ÛÿÄ­ØÿÇ­ÓÿÈ­ÏÿʬËÿÍ­ÇÿЭÂÿÒ®ÀÿÓ­¿ÿÓ¯¼ÿÓ®¼ÿÕ®ºÿÔ­¹ÿÔ­ºÿÔ­¹ÿÕ­¸ÿÕ­·ÿÕ¬¶ÿÕ­¶ÿÖ­µÿÕ¬´ÿÔ«³ÿÔ«³ÿÒ«¶ÿЫ¸ÿѪ¸ÿѪ·ÿÒ«¶ÿÔ«´ÿÕ«³ÿÔ¬±ÿÕ«²ÿÕ«´ÿÒ«¶ÿѪ¸ÿΫ¿ÿË«ÇÿǪÏÿ©Öÿ¿¨Úÿ»§Üÿ¹¦Þÿµ¥àÿ´¥âÿ³¤âÿ°¤åÿ®£çÿ¬¡åÿ© åÿ¦ çÿ¤ ëÿ¤ êÿ¥ èÿ©Ÿäÿ«�ßÿ¬œÝÿ¬œÜÿ¬›Ûÿ¬œÚÿ«›Üÿ¨™Üÿ£—Üÿ¡—Ýÿ –ßÿŸ–ßÿ •ÝÿŸ”Ûÿ ”Úÿ ”Ûÿ§›æÿ$ÿ#!ÿ ÿ ÿÿ]Q|ÿ¡–àÿ�“ÜÿŸ‘Øÿ¡‘Ôÿ¢’Ôÿ¡’Õÿ “×ÿŸ”ÛÿŸ“Þÿœ”áÿœ”áÿœ“ßÿœ‘Þÿš‘Þÿ—�Üÿ˜ŽÙÿ˜�×ÿ™�Øÿ˜�Ùÿ˜‹Øÿ—‹×ÿ”ŒÛÿ•ŒÖÿš‹Òÿ�ŒÒÿ��ÕÿžŽÖÿŸ�Ôÿ¢�Ðÿ£�Ïÿ¥ŽÍÿ¦�Ëÿ¥�Ïÿ£ŽÒÿ¡�ÐÿŸ�ÐÿŸ�ÒÿžŒÒÿ�ŒÓÿ›ŒÔÿ›ŒÕÿœŒÔÿ›ŒÔÿœŒÔÿ›�Õÿ™ŒÕÿšŒÔÿšŒÕÿš�ÖÿšŒÖÿš‹ÕÿšŒÔÿš‹Òÿœ‹Îÿ�ˆËÿŸˆÉÿ ‡Äÿ¢‡Àÿ¢‡Áÿ¡ˆÄÿŸ†Çÿž†Èÿœ‡Èÿ›†Éÿš…Èÿ˜„Èÿ—„Èÿ—‚Çÿ—�Äÿ˜€Ãÿ—~¾ÿ™~ºÿš|´ÿ™y¯ÿ˜w«ÿ˜x©ÿ–v©ÿ•u¦ÿ–t¢ÿ–s ÿ•rŸÿ“s ÿ“qŸÿ“q�ÿ“p™ÿ“p˜ÿ•o•ÿ–o•ÿ–o•ÿ•n—ÿ“pœÿ“p�ÿ’n™ÿ“m”ÿ“k‘ÿ‘k‘ÿ�k’ÿdzàÿɳÝÿÍ´ÛÿË´ÛÿË´ÝÿȳÞÿȲßÿųâÿijåÿóçÿÁ³èÿ¿´ìÿ¼³íÿº³ïÿ¹³ðÿ¸³óÿ¸²ðÿº±îÿº±íÿ»¯êÿ½¯æÿ½¯æÿ½¯åÿ¾¯äÿÀ¯äÿÀ®àÿ®ßÿÁ®àÿ­ÞÿíÛÿĬ×ÿÆ­ÕÿÈ­ÎÿÍ­ÉÿÏ®ÅÿѯÃÿÒ®ÂÿѯÀÿÒ¯¿ÿÓ®¾ÿÒ®½ÿÑ­¼ÿÒ­»ÿÓ®ºÿÒ­·ÿÔ¬·ÿÓ­¶ÿÓ¬´ÿÓ¬´ÿÓ«µÿÑ«·ÿЬ¹ÿÏ«ºÿЫºÿÑ«¸ÿÒ¬·ÿÓ¬µÿÕ¬´ÿÕ¬³ÿÔ­µÿÓ¬¹ÿЬ½ÿÌ«ÃÿÉ«ÉÿŪÐÿÁª×ÿ¿¨Úÿ¼§Üÿ¸¦Üÿ·¥ßÿ´¤àÿ³¥àÿ±¤ãÿ¯¢äÿ­¢äÿ« äÿ§Ÿæÿ£Ÿéÿ£ éÿ¥¡éÿ§¡çÿªžáÿªžßÿª�ßÿª›Üÿ¬œÜÿª›Üÿ§™Ýÿ£—Þÿ¡—ÝÿŸ—Þÿ –Ýÿ –Üÿ •Ûÿ¡–Üÿ¡•Úÿ¥šàÿ%!ÿ*/ÿ&"ÿÿ$$ÿSIoÿ¡˜äÿ�”Ýÿž“Ûÿ ’ÙÿŸ’ÖÿŸ’Õÿ¡’ØÿŸ“Úÿž”Ýÿœ”àÿœ“áÿš’Þÿ›�Úÿš�Üÿ—�Üÿ—�Þÿ™ŽÚÿ™ŒÕÿšŽÖÿ™�×ÿ˜ŒÖÿ—�×ÿ™ŒÕÿ›‹Òÿ��ÔÿŸŽÖÿŸ�Ôÿ¢�Òÿ£�Ïÿ¤�Îÿ£�Ðÿ¤�Ðÿ¥�Ðÿ£�Ñÿ¢�Óÿ �Òÿ��Óÿ��Óÿ›�ÔÿšŒÕÿ›�Öÿ›ŒÖÿšŒÔÿšŒÔÿ™ŒÔÿ˜‹Öÿ˜ŒÖÿš‹Ôÿ›ŒÒÿ�ŒÒÿ�ŒÑÿ�ŒÎÿŸŠÊÿ ‰Æÿ¡ˆÂÿ£‡¾ÿ¥†¹ÿ¦†´ÿ¨†²ÿ§†±ÿ¥…¶ÿ¤†ºÿ£ƒ¶ÿŸƒ¸ÿŸ�¸ÿ�€¸ÿœ�ºÿ›€¼ÿ›»ÿ›€¹ÿš~·ÿ›|³ÿ™z±ÿ—w¬ÿ—wªÿ•v¨ÿ”u§ÿ–u¨ÿ”s¤ÿ’r¡ÿ’q ÿ‘pŸÿ‘p�ÿ“p›ÿ“p™ÿ“p˜ÿ“o˜ÿ“o–ÿ’n–ÿ“o˜ÿ”ošÿ“p™ÿ“o—ÿ”n”ÿ’m’ÿ’l“ÿ�l•ÿÅ´æÿÆ´äÿdzáÿÊ´ÞÿÊ´ÞÿɳÞÿÈ´ßÿdzâÿÄ´åÿôæÿ´çÿÀ³éÿ½´íÿº´òÿ·µôÿµ´õÿ´µöÿµ³ôÿ¶²òÿ·²ïÿº°íÿ»°êÿ»¯éÿ»¯èÿ¼¯çÿ½®åÿ¿®äÿ¿®ãÿÀ¯ãÿ­ßÿ¬ÝÿíÜÿÄ­ÙÿÈ­ÑÿË®ÊÿήÇÿήÆÿϯÈÿϯÆÿЮÃÿЮÃÿÒ®ÁÿÑ­ÀÿÒ®¾ÿÒ­¼ÿÒ­¹ÿÓ­¹ÿÒ­¸ÿÒ¬¸ÿÒ¬¸ÿѬ¹ÿЬ¼ÿϬ¾ÿЬ¾ÿÑ­¾ÿÑ­¼ÿÓ¬ºÿÔ®·ÿÕ®·ÿÔ­¸ÿÒ®ºÿÑ­¼ÿέÃÿÊ«ÌÿÆ«ÒÿªÖÿÀ©Ûÿ¼¨Þÿ¹§àÿ·¦ßÿ¶¥àÿ´¥âÿ²¥ãÿ¯£ãÿ­¢äÿ¬¢æÿ©¢èÿ¥¡êÿ£ êÿ¤ éÿ§Ÿçÿ¨žäÿ«žâÿªžàÿ«œÜÿ«›Úÿª›Üÿ¥™Þÿ£™ßÿ¢—ßÿ¡—ßÿ —àÿ¡—Þÿ¡—Ýÿ¢—Ýÿ¢—Þÿ¢•Ûÿ**ÿÿÿ ÿ.#8ÿZNvÿ ™æÿ›”áÿ›”áÿ›”áÿœ”áÿ�”ÞÿŸ“Þÿž•Ýÿ�“Ýÿ�“ßÿœ“ßÿ›‘Üÿœ�Úÿ›�Ùÿš�Üÿ˜�áÿš�Üÿœ�Õÿœ�Õÿ›�Öÿ›ŒÕÿ›�Õÿ›�ÕÿžŽÕÿŸ�ÖÿŸ�Õÿ¡‘Õÿ¢�Ñÿ¦�Îÿ¥�Ïÿ£‘Òÿ£�Òÿ¤�Ðÿ¤�Ñÿ¢�Óÿ¡�ÓÿŸŽÓÿžŽÕÿœŽÕÿš�Õÿš�×ÿ™�×ÿ™Œ×ÿšŒÕÿš‹Õÿ™ŒÕÿ™ŒÕÿ›ŒÒÿŸ‹Îÿ ‹Ëÿ ‰Éÿ¡ˆÄÿ£‡Àÿ¤‡¾ÿ¤‡¾ÿ¦‡·ÿ¨†°ÿ¨…¬ÿ©…«ÿ§„«ÿ§„®ÿ§ƒ¯ÿ§‚¬ÿ¥�ªÿ¥€©ÿ£©ÿ¡­ÿŸ~¯ÿŸ}®ÿž{ªÿ�{ªÿœyªÿ›y«ÿšw¨ÿ™v¥ÿ—u£ÿ•u¤ÿ”t¥ÿ“s¥ÿ”s¥ÿ’q¢ÿ�p¡ÿ‘pŸÿ’o›ÿ“ošÿ“p™ÿ“p™ÿ“pšÿ“o›ÿ“o›ÿ“o˜ÿ”n•ÿ”n”ÿ”n”ÿ’n–ÿ‘m–ÿ�l•ÿĵçÿôçÿĵæÿƵäÿÈ´âÿȵáÿÈ´àÿÉ´áÿÈ´äÿÅ´äÿÄ´æÿ´èÿ¿´ìÿ»µñÿ¸´óÿµµöÿ´µøÿ³µøÿµµöÿ¶³óÿ¶²ñÿ·°ïÿ¸°îÿ¸°ìÿ¸¯ëÿº¯éÿ½¯æÿ½®äÿ½®äÿÀ®âÿÀ­Þÿ¬Þÿ­ÝÿÄ­ÙÿÈ­ÖÿÊ®ÏÿË®ÊÿÌ®ÉÿÍ®ÊÿͯÉÿϯÇÿЮÅÿЮÄÿЮÃÿÑ­ÁÿÑ®¾ÿÒ­¼ÿÒ­¼ÿÑ­½ÿÑ®¾ÿÑ­¿ÿέÀÿέÃÿÍ­ÄÿÏ®ÃÿÑ­ÂÿÒ®¿ÿÒ®ºÿÓ­ºÿÓ­¹ÿÒ­¼ÿÑ­¾ÿάÂÿÊ«ÉÿƬÐÿëÖÿÀªÛÿ½¨Þÿ¹¨áÿ·§áÿµ¦áÿµ¦ãÿ±¥äÿ°¥äÿ®¤æÿ¬¤èÿ¨£êÿ¥£ìÿ¤¢ìÿ£ êÿ¤Ÿèÿ¦Ÿæÿ©Ÿãÿ«�ßÿ¬œÞÿªœÞÿ¨›ßÿ¥šàÿ¤™áÿ¡˜àÿŸ˜áÿ ˜àÿ¢˜ßÿ¢˜Ýÿ¢—Ýÿ£—Þÿž‘Ôÿÿ')ÿ ÿÿ"ÿ@6UÿŸœíÿ™—åÿ˜–æÿ—•åÿ˜•åÿ�“àÿž”àÿ›•ãÿ›•âÿš“àÿ™’áÿ™’ßÿ›‘Üÿš‘Üÿš‘Ýÿ—�ßÿš�ÜÿœŽÕÿ�ŽÖÿž�ÖÿœŽ×ÿœŽ×ÿœŽÖÿžŽÖÿ �ÖÿŸ�×ÿ �Õÿ£�Óÿ¥�Íÿ¦‘Ðÿ£‘Òÿ¤‘Óÿ¤�Óÿ£�Òÿ¢�Òÿ¡�Óÿ¡�Ôÿ ŽÖÿž�Õÿ��Óÿ›ŒÓÿœŠÐÿ›‹Ñÿœ‹Ñÿ�‹Ðÿž‹Ïÿž‹Îÿ ŠËÿ¢ŠÉÿ¢ŠÅÿ£‰Ãÿ¤‡Àÿ¥‡¼ÿ¤†»ÿ¤…¸ÿ¥…³ÿ¦„­ÿ§ƒªÿ©ƒ¨ÿ©‚¦ÿª‚¥ÿ©�£ÿ©€¡ÿ§¡ÿ¦}Ÿÿ¤|Ÿÿ¢|¢ÿ {¥ÿ z¤ÿŸy¢ÿžx£ÿ�w¤ÿœx£ÿœw¡ÿ›v¡ÿ™v¡ÿ–t¡ÿ–t¡ÿ”s¢ÿ”r£ÿ’r¡ÿ‘q¡ÿ‘q¢ÿ’qžÿ”p�ÿ”pœÿ”qœÿ“p�ÿ“p�ÿ“p›ÿ’n˜ÿ“o—ÿ•o—ÿ”o—ÿ’n—ÿ�l–ÿ�l–ÿĶæÿ¶èÿöéÿĵåÿÅ´åÿÇ´äÿƵäÿȶäÿǵäÿƵåÿÅ´æÿõèÿÀ´ëÿ¼¶ðÿ¹µóÿ·µõÿµµöÿµµ÷ÿ´µöÿµ´ôÿ¶³óÿ´²ôÿ³²óÿµ±óÿ´±ñÿµ°ïÿ¸¯ëÿ»®çÿ¼¯äÿ¾®äÿÁ­àÿÁ¬Ýÿ­ÝÿíÝÿîÜÿÆ®ÙÿÈ®ÔÿÉ®Ïÿ̯ÍÿͯÎÿͯËÿίÉÿÏ®ÇÿϯÇÿЯÅÿÒ¯ÁÿÑ®ÀÿÑ®ÀÿÑ­ÁÿЭÂÿέÃÿÍ­ÆÿË­ÇÿÌ­ÆÿÏ®ÆÿϯÃÿÒ®ÀÿÒ®¾ÿÓ®½ÿÒ®½ÿÑ®ÀÿÏ­Âÿ̬ÅÿʬÊÿƬÑÿ«Øÿ¿ªÝÿ¼©Þÿ¸¨àÿ·¨áÿ¶§áÿµ¦âÿ´¦ãÿ°¥åÿ®¥æÿ«¥éÿ¨¤ìÿ££ìÿ¡£ìÿ£¡ëÿ¢Ÿéÿ¤ èÿ¦Ÿçÿ§�âÿ¨œáÿ§œáÿ§�ãÿ¤œãÿ¤›âÿ¢šãÿ¡šâÿ¡šâÿ£šßÿ¦šÛÿ¦šÛÿ¥™Þÿ•ˆÆÿ, 1ÿÿ#ÿÿ"#ÿ90KÿžŸñÿ—šéÿ—œìÿ—œìÿ–™éÿ—–åÿ™•åÿ˜–æÿ—–æÿ—”åÿ˜”äÿ˜”ãÿ™“áÿš“âÿ˜’àÿ™‘ßÿ›‘Ûÿœ�Øÿž�Øÿž�×ÿœ�Øÿœ�Øÿ�Ž×ÿžŽÖÿž�ÕÿŸ�×ÿž�×ÿ ‘Öÿ£�Óÿ£�Ðÿ¤�Ðÿ£‘Óÿ¢‘Ôÿ �Óÿ¡�Ôÿ �Óÿ �ÔÿŸ�ÖÿžŽÓÿž�ÒÿžŒÐÿŸŒÎÿž‹ËÿŸ‹ÌÿŸ‹ËÿžŠÈÿ ‰Åÿ¡ˆÃÿ¡ˆÁÿ¢ˆÀÿ¢†¼ÿ¡…ºÿ£„¸ÿ¢„¶ÿ£„´ÿ£‚±ÿ¦ƒ¯ÿ¥�«ÿ§€§ÿ§¤ÿ§ ÿ§~œÿ§~�ÿ¦}�ÿ¥|œÿ¥{œÿ£zœÿ¢z�ÿ£zžÿ¡yžÿ¡xŸÿ y ÿŸxžÿŸx�ÿ�w�ÿ™v�ÿ—t�ÿ–sŸÿ•sŸÿ“s ÿ“r¡ÿ‘r¢ÿ‘r¢ÿ’q¡ÿ“qžÿ“oœÿ“p�ÿ’pœÿ“q›ÿ”pšÿ“o˜ÿ“o˜ÿ‘n˜ÿ’n™ÿŽm˜ÿŒm˜ÿŒk™ÿĶèÿöèÿöêÿĶçÿƶæÿƵåÿŶæÿŶçÿÆ·çÿÆ·çÿÅ·èÿĶêÿÀ¶íÿ¼¶òÿ¸·öÿ¶·öÿ¶¶öÿ´¶ùÿ²¶ùÿ´µöÿµ´ôÿµ³ôÿ´³ôÿ³²ôÿ³²óÿ³²óÿµ°ñÿ·°íÿº¯êÿ¼¯åÿ¾®âÿÁ®Ýÿ­Üÿ­Ýÿ®Ýÿ®ÞÿÄ®ÜÿƯØÿɰÕÿ˰Óÿ˰ÑÿͰÍÿΰÊÿϰÉÿаÆÿЯÅÿѯÄÿѯÅÿЯÅÿЮÆÿήÇÿÌ®ÉÿË®ÌÿÌ®ÉÿͯÆÿЯÅÿѯÃÿÒ¯ÂÿÒ¯ÁÿЮÁÿÏ­ÄÿÍ­Æÿ̬ÉÿɬËÿÆ«Ðÿ«Øÿ¿«Ýÿ¼ªàÿº©àÿ·¨áÿ·¨áÿ¶§àÿµ¦âÿ³¦ãÿ¯¥æÿª¥éÿ¦¥ìÿ£¤îÿ¡£íÿ ¡ìÿ¡¡ëÿ¢ êÿ£ éÿ£žæÿ§žäÿ§žäÿ¦�äÿ¥�äÿ¦œãÿ¥�ãÿ¥œâÿ¥›ãÿ¥›àÿ¦šÜÿ§™Úÿ§›ßÿ�‚»ÿ%%ÿÿÿ +ÿ""ÿ7-Hÿ�Ÿñÿ–šêÿ”œìÿ”œîÿ”œíÿ•™éÿ––æÿ˜”ãÿ™•ãÿ˜•åÿ˜–çÿ™–åÿ›“ßÿ›“áÿ›”âÿ›“àÿ�“Ýÿœ‘Úÿ�‘Ùÿ�‘Úÿœ�Úÿœ�Úÿœ�Ûÿœ�Úÿ��Ùÿž‘Ùÿ�’Úÿž’Ùÿ¡�Öÿ¡‘Óÿ¢�Ñÿ¢�Ôÿ¢‘Öÿ¡‘×ÿ �Õÿ¡�Ôÿ �Õÿž�ÖÿŸ�Ôÿ �ÎÿžŒÎÿžŒÎÿŸŒÍÿŸ‹Êÿ ‰Çÿ ˆÃÿŸ†¿ÿ ‡¼ÿ¡‡¼ÿ¡†½ÿ¢…»ÿ¢…·ÿ£„´ÿ£ƒ²ÿ¤‚°ÿ¤‚°ÿ¥‚®ÿ¦�§ÿ§£ÿ¨¡ÿ¨~�ÿ¦}œÿ¥|�ÿ¥|�ÿ¥|�ÿ¥|œÿ¥|œÿ¥{›ÿ¥{šÿ¤z›ÿ¤{�ÿ¤{œÿ£zœÿ¢y�ÿŸyžÿ›wžÿ™vžÿ˜užÿ—tžÿ–s ÿ”s¢ÿ“s£ÿ’s¢ÿ”r ÿ”rŸÿ”qœÿ”qœÿ“pœÿ�o�ÿ�o�ÿ�n�ÿŽn�ÿŽm�ÿŒmžÿ‰lŸÿ‰k ÿˆj ÿǸçÿƸêÿĸéÿŸêÿŸèÿÆ·èÿĶéÿ¶ëÿÁ¶ìÿÁ¸ìÿ·ìÿ¸íÿÀ·îÿ¾¸ñÿ»·ôÿ¹·ôÿ¶¶öÿ´·ùÿ²·úÿ²¶ùÿ´µöÿµ³ôÿµ³ôÿ³³ôÿ³²ôÿ´²ôÿ³²óÿµ±òÿ·°îÿ¸°ëÿº®èÿ¼®åÿ½®ãÿ¾­áÿÀ­àÿÁ®áÿÁ®àÿïßÿůÜÿǰÚÿɯØÿʰÕÿ̱ÒÿαÎÿΰËÿΰËÿΰÊÿϰÉÿϯÈÿίÊÿίÊÿίÍÿÊ®Ðÿ˯ÐÿÌ®ÍÿίÉÿϯÈÿϯÆÿϯÆÿήÇÿÍ®ÈÿË®ÊÿÊ®ÍÿǬÏÿÄ«Ôÿ«ÙÿÀ«ßÿ»«àÿ¹ªâÿ¸©âÿ¶¨àÿ¶¨áÿ¶§âÿ²¦äÿ¯¦æÿª¦ëÿ¥¥íÿ¢¤ïÿ¡£îÿ ¡íÿ¡¡íÿ ¡ëÿ£Ÿéÿ£Ÿçÿ¥ æÿ¦Ÿåÿ§Ÿåÿ§žãÿ¨žãÿ¨žâÿ§�áÿ§�ãÿ¦œãÿ¥›âÿ£šàÿ¥œäÿˆ{¶ÿ ÿ$'ÿÿÿ+1ÿ$(ÿŸžòÿ—–æÿ—šéÿ•›ëÿ•šêÿ•˜éÿ•˜èÿ˜“áÿž“Ýÿ�“Ûÿ�•ßÿ�”àÿ�“Üÿš’Þÿœ”àÿœ’Ýÿ�“Ûÿ�’Ûÿ�’Ûÿ�“Ýÿž“Ýÿ�’Ýÿ�“Ýÿ�’ÝÿŸ’Úÿ ‘Øÿ “Úÿ “Úÿ ‘Øÿ¢’×ÿ¢‘×ÿ¢’Öÿ¡‘×ÿ¡’×ÿ¡’Öÿ¢‘Õÿ¡�Ôÿ �Ôÿ �Òÿ¡ŒÌÿŸŒÍÿ�ŒÏÿžŒÐÿ�‹Íÿž‰ÈÿŸˆÅÿŸ†Àÿž…¾ÿŸ„½ÿŸ„½ÿ ƒ»ÿ ‚·ÿ¢‚³ÿ¤�¯ÿ¤�¯ÿ¤€«ÿ¥¦ÿ¦¤ÿ¥¤ÿ¥}¡ÿ¦~žÿ¥} ÿ¥| ÿ¥}Ÿÿ¤{�ÿ¤|�ÿ¥{œÿ¤{žÿ¢{�ÿ¢zžÿ¢z�ÿ£y�ÿ£yžÿ¡yžÿžx ÿœx¡ÿšw¡ÿšv ÿ™v ÿ–u¡ÿ”s¢ÿ“s¢ÿ“s¢ÿ“s¡ÿ’q¢ÿ‘r£ÿ‘q¢ÿ‘o¢ÿŽo¢ÿ�o£ÿ‹m£ÿ‰m¥ÿ‰l¤ÿ‡k¤ÿ‡j¤ÿ…i¤ÿ…i£ÿȸçÿǹèÿǹéÿĸéÿŹëÿƸêÿŸêÿĸëÿ¸ïÿÀ¹ðÿÀ¸ðÿÀ¸ðÿÀ¹ñÿ¿¸ïÿ¾·ñÿ½¶ðÿ¹·òÿ¶¸ùÿ³·ùÿ²¶ùÿ³¶ùÿ³´øÿ²´÷ÿ³´öÿ²³õÿ²²ôÿ³²ôÿ²²óÿ±°ôÿ³°ñÿ´¯ðÿµ¯íÿ·¯ëÿº®éÿ¼®åÿ¾®äÿ¾®äÿÀ®äÿÁ¯âÿİßÿŰÜÿȰÙÿ˱Ôÿ̱Ñÿ̰Òÿ̰Òÿ̰Ñÿ̰ÏÿΰÏÿΰÍÿͰËÿͯÍÿʯÐÿÈ®ÒÿɯÔÿ̯ÏÿͰÌÿͯÊÿ̯Ëÿ̯ÌÿʯÍÿÈ®ÐÿÇ®ÔÿĬ×ÿ¬ÚÿÀ«Ûÿ¾«àÿ»«áÿ¹ªáÿ¸ªâÿ·¨áÿ¶§àÿ´§àÿ²§äÿ®¦çÿ©¥ëÿ¤¦îÿ¡¤îÿ ¤îÿ ¢íÿŸ¡ëÿ¡ êÿ£ èÿ£ çÿ¥Ÿæÿ¦Ÿåÿ¨ åÿ¨Ÿäÿ¨Ÿâÿ¨žâÿ¨žãÿ§žäÿ£žåÿ¡žæÿ¡œåÿ¢žèÿ~u«ÿ8,Hÿ(,ÿ"!ÿÿ*!5ÿ"#ÿ��îÿ˜–æÿ——åÿ˜™èÿ–˜èÿ•˜çÿ•™èÿ–“âÿœ’ÙÿŸ“ØÿŸ”Ûÿ�”Üÿ›“Üÿœ“àÿ�•Üÿž”ÚÿŸ“Úÿž”ÛÿŸ”ÜÿŸ”Ýÿž”Ýÿž“Ûÿž“Ýÿ�“ÛÿŸ’Ùÿ¡‘Ùÿ ’Ùÿ “Ùÿ¢’×ÿ¢“×ÿ¡“Öÿ¢“×ÿ ‘Öÿ¡‘Õÿ¢‘Öÿ¡’Õÿ¢�Òÿ¢�Òÿ¢�Îÿ¡�Êÿ ŒËÿž‹Êÿœ‹Êÿ�‹Ëÿ�ŠÉÿžˆÆÿŸ‡Äÿž†Âÿ�„¾ÿŸ„½ÿŸƒ»ÿŸƒ¶ÿ¡‚²ÿ¢€®ÿ¢€«ÿ£§ÿ£~¥ÿ¢~¦ÿ¡~¦ÿ¡}¦ÿ }¤ÿ¢}¢ÿ¡|¡ÿ¡{Ÿÿ¡{žÿ¢{Ÿÿ {Ÿÿ { ÿ z¢ÿ z ÿ yŸÿ¡yŸÿ¡zŸÿŸz ÿŸz¢ÿžy¡ÿ›x¡ÿ›w£ÿ˜w¢ÿ”u¢ÿ’t¦ÿ‘s¦ÿ�r§ÿŽr§ÿ�r¨ÿŽr©ÿŒq©ÿ‹p©ÿŠpªÿ‰o©ÿˆnªÿ‡mªÿ†l¨ÿ†k¦ÿ„j£ÿ„j¢ÿ…i£ÿʸåÿɹæÿʹçÿɹçÿȹéÿǸêÿƹëÿĹëÿĺîÿÁ¹ðÿÁ¹ñÿÀºòÿÀ¹óÿ¿¸òÿÀ¸ñÿ¾¸ðÿ½·ðÿ¸¸öÿµ¹ùÿ´¸øÿ³·ùÿ²¸ûÿ±¸úÿ°·úÿ¯¶øÿ¯µùÿ¯µùÿ¯³øÿ®²÷ÿ¯²öÿ°°ôÿ±°ñÿ³¯ñÿµ°ðÿ·°íÿ¹°ìÿº°êÿ¼¯èÿ¾¯æÿÁ¯ãÿıàÿƱÛÿʱÖÿ˱Ôÿ˱ÔÿʰÕÿɰÕÿʯÕÿʰÔÿʰÑÿ˯ÐÿʯÐÿɯÒÿȯÕÿÈ®ÖÿɯÓÿʯÏÿ˯ÎÿÉ®ÏÿÈ®ÐÿÈ®ÒÿÅ®Öÿ¬ÜÿÁ¬Þÿ¾«Þÿ¾«ßÿ½¬âÿ¼¬âÿº«âÿ¹ªáÿ¸¨áÿ¶§àÿµ§áÿ²§ãÿ­¦èÿ¨¦ìÿ¥¥îÿ¢¤îÿ ¥ïÿ ¤îÿ ¢ìÿ£¢êÿ¤¡èÿ¦ çÿ§ æÿ© åÿ¨ æÿ¨¡åÿ©Ÿåÿ©Ÿãÿ¨Ÿäÿ§Ÿåÿ¤ çÿ¡ éÿ¡Ÿêÿ¡¡íÿwp¥ÿ%.ÿÿÿ ÿ"&ÿ."6ÿ–—æÿ™šéÿ—šéÿ—šéÿ—›êÿ–›êÿ”˜éÿ’’ãÿ˜‘Üÿ›‘Ûÿ›‘Ùÿ›‘Úÿ™’Þÿœ”ßÿŸ“Úÿ¢’Öÿ¢“Öÿ¢”Ùÿ¡•Øÿ¢”Ùÿ¢”Ùÿ¡”Ùÿ¡”ÙÿŸ“Ùÿ “Ùÿ “Ùÿ¡“Ùÿ¢”Øÿ£”×ÿ£”×ÿ£“Öÿ¤’Öÿ¤“Õÿ¤’Óÿ¤’Óÿ¤’Ôÿ£‘Óÿ¢�Ðÿ£ŽÍÿ¢ŒÉÿ¢‹Æÿ¢‰Åÿ ˆÄÿŸ‰ÆÿžˆÅÿžˆÄÿž‡Ãÿ�†Ãÿ�…Àÿžƒ½ÿŸƒºÿ¡‚µÿ¡‚±ÿ£‚¯ÿ£€¬ÿ£�«ÿ¢€«ÿ ~«ÿŸ~­ÿž}®ÿ�|¬ÿž}©ÿžz¥ÿŸz¤ÿ�y£ÿžz£ÿ�y¢ÿ�y£ÿŸy¤ÿŸz£ÿ {¡ÿ¡|¢ÿ¡|£ÿ {£ÿ {¢ÿžz¢ÿœx¢ÿ˜v¤ÿ•v¦ÿ’t§ÿ‘t©ÿŽt«ÿŒs­ÿ‹r®ÿŠr®ÿ‰q®ÿ‰q¯ÿˆq¯ÿ‡q¯ÿ‡p¯ÿ‡o­ÿ†o¬ÿ†m«ÿ…m©ÿ„l¨ÿƒk©ÿ„k©ÿͺæÿͺåÿ̹åÿ̹äÿ˺æÿʺçÿȺêÿƺîÿÄ»ðÿúðÿºðÿ¹ñÿÀºñÿÀ¹ñÿ¿¹ñÿ¾¸òÿ¼¸óÿ¸¸öÿ¶ºùÿ´¹úÿ³¸ùÿ°¹úÿ¯¹üÿ®¹üÿ­¸üÿ¬¹ýÿ¬¸ýÿ¬¸üÿ«¶üÿ«¶ûÿ¬µúÿ®´÷ÿ¯²õÿ±±õÿ±±òÿ³±òÿµ±ðÿ¸°îÿ¼°ëÿ¿°çÿÁ°äÿıãÿŲáÿȲÞÿɱÛÿȱÙÿ˱×ÿʰÔÿʰÔÿɰÕÿɯÔÿÉ®ÓÿȯÕÿɯÖÿɰÖÿɰÕÿɰÓÿɯÑÿÉ®ÒÿÇ®ÔÿÆ­ÖÿíÙÿ­ÝÿÁ­Þÿ¾¬áÿ¼¬âÿ¼¬âÿ½«âÿ¾«àÿ½«ßÿ»©ßÿ¸¨ßÿ¶¦áÿ±¦äÿ­¦çÿ¨¦íÿ¥¦îÿ¤¦ðÿ¢¨ñÿ¡¨ñÿ£¦ðÿ££íÿ¦£ëÿ§¢éÿ©¢çÿ©¡çÿ¨¡æÿ¨¡çÿ©¡çÿ¨¡åÿ©¡æÿ§ çÿ¤ éÿ¡ ëÿžŸëÿ ¤ñÿoižÿÿ#&ÿÿ ÿ%,ÿ&/ÿ�‘Üÿ˜œêÿ—›éÿ–šéÿ—›êÿ”˜èÿ“•çÿ”‘âÿ˜‘Üÿ›’Üÿ›‘Ùÿ›‘Úÿ›’ßÿ�“Þÿ¡“Úÿ¢’Ôÿ¤“Ôÿ¤“Óÿ¤“Ôÿ¤”Ôÿ¤“Öÿ¤”Öÿ¤”Ôÿ¤”Öÿ£•Øÿ£•Øÿ£”×ÿ¥•Öÿ¦•Ôÿ¦•Ôÿ¦”Ôÿ¦“Òÿ§“Ñÿ¨“Ðÿ¨“Îÿ§’Ïÿ¥�Îÿ¥�Íÿ£ŽËÿ¢‹Çÿ¢‹Åÿ¡‰Ãÿ£ˆÁÿ¡‡Âÿ ˆÁÿ ‡ÀÿŸ‡ÀÿŸ†Àÿž„½ÿŸ„¼ÿ¡ƒ·ÿ¡ƒµÿ ‚´ÿ¡‚±ÿ¢�°ÿ �¯ÿŸ€°ÿ €¯ÿŸ®ÿ�°ÿ�~°ÿ�}­ÿ�}ªÿž}¨ÿž|§ÿ�{¦ÿžz£ÿ�y£ÿ�y£ÿžz£ÿŸ{£ÿŸ{£ÿŸ|¥ÿž{¦ÿ�z¦ÿœz§ÿ˜x«ÿ”w­ÿ’v®ÿ�v¯ÿ�v°ÿŽt±ÿ�t±ÿ‹s²ÿˆs¶ÿ‡s·ÿ…q²ÿ„p±ÿ…p±ÿ…o¯ÿ„n®ÿ…n®ÿ…n­ÿ„m«ÿ„l¬ÿ‚m¬ÿ‚m®ÿλåÿÍ»åÿÍ»æÿÌ»æÿ˺æÿʺèÿÈ»ëÿÆ»îÿƼïÿÄ»ðÿ»ñÿ»óÿÀºòÿÀºòÿ¿¹óÿ½»öÿ»»÷ÿ¸»ùÿ´½üÿ³¼ûÿ²»üÿ°»üÿ­»ýÿ«ºþÿªºþÿªºýÿ¨¹þÿ¨¹þÿ¨¹þÿ¨¹ýÿ©¸ýÿª·üÿ¬¶ûÿ¯µùÿ¯´÷ÿ¯²õÿ±±ôÿ³±óÿ¶±ïÿº°ëÿ½°èÿ¿±çÿÀ±èÿÁ²çÿIJäÿDZÞÿɱØÿ˱ÖÿʰÔÿʰÕÿɰÕÿɯÖÿǯØÿǯØÿȯÖÿȯ×ÿɰ×ÿɯ×ÿȯÖÿÇ­×ÿÄ­Úÿ¬ÜÿÀ¬ÜÿÁ¬Þÿ¿­àÿ½¬áÿ½¬áÿ½¬àÿ¾«ÝÿÀ«Üÿ¿ªÛÿ½¨Üÿ¹¨Þÿ³§ãÿ­¦çÿ¨§ìÿ¥§ïÿ¢¨ðÿ¢©ðÿ¢¨ñÿ¢§ðÿ¤¥îÿ§¤ìÿ¨£éÿ©£èÿ©¢æÿ©¢æÿ¨¡æÿ¨¡çÿ§¡çÿ¦¡çÿ§¡èÿ¥¢éÿ¢¢ìÿŸ£íÿ¡§ôÿga�ÿA:`ÿ.$;ÿ%"ÿ"&ÿ=6[ÿ%+ÿ…ŠÒÿ˜�ìÿ•™èÿ•—çÿ––æÿ””äÿ”’âÿ˜’àÿ›’Üÿ›’Úÿœ‘Ùÿ�‘Ùÿž“ÚÿŸ“Úÿ¢“Öÿ£“Õÿ¤“Óÿ¤“Òÿ¥“Ðÿ¦“Óÿ¦”Óÿ¦•Óÿ§”Òÿ§•Óÿ¦–Õÿ§–×ÿ¦–Õÿ¨–Ôÿª–Ôÿ¨–Óÿ©”Ñÿª”Ïÿª“Ìÿª’Ëÿ¨’Êÿ¨�Êÿ§�Êÿ¥�Éÿ¤�Çÿ£ŒÄÿ£ŠÃÿ¢‰Áÿ¢ˆ¿ÿ£ˆ½ÿ£ˆ½ÿ£ˆ¾ÿ¢‡¼ÿ¢‡¼ÿ¡†ºÿ¢…¹ÿ£…·ÿ¢…µÿ¢…µÿ¢„µÿ¡‚´ÿ �¶ÿž€´ÿ�€±ÿž~¯ÿœ~¯ÿ›~°ÿš|­ÿ›|«ÿ›{«ÿœ{©ÿœ{§ÿ›z¦ÿ�z¦ÿžz¨ÿž{¨ÿ�|§ÿž|©ÿœ{ªÿ›|ªÿ™z­ÿ—z¯ÿ•y±ÿ”x³ÿ’wµÿ�wµÿ�w¶ÿ�vµÿŒu´ÿŠt·ÿ†t¹ÿ…r¹ÿ…r¶ÿ…q´ÿ„p³ÿ„p³ÿ„p´ÿ‚o°ÿ„n¯ÿƒm­ÿ‚m«ÿ�l­ÿ�n¯ÿξéÿͽêÿ̽ëÿʼìÿʼìÿÊ»ìÿÈ»ìÿǼîÿȼíÿȼîÿżðÿļñÿÁ»òÿÀºóÿÀ»óÿÀºóÿ¾ºõÿ¹¼ùÿ¶¾ýÿ´¾þÿ²½þÿ®½þÿ«¼þÿ©½þÿ©¼þÿ§¼þÿ§¼þÿ¦¼þÿ¦»ýÿ§»þÿ¨¹þÿ©¹ýÿ¬·üÿ®·ûÿ®·ùÿ¯¶ùÿ¯µùÿ®²÷ÿ±²öÿµ²óÿº²íÿ½²ëÿ¿³êÿÀ³èÿ³çÿŲáÿɲÚÿ˲Öÿ̱ÕÿͱÓÿͱÓÿ˰ÕÿɱÖÿȰØÿȯØÿǰØÿȰÙÿȱÙÿɰØÿǰÙÿůÜÿïÞÿÁ®ßÿÁ­ßÿÁ­ßÿ¿­àÿ¾¬áÿ¾¬àÿÀ¬ÝÿÀ«ÙÿÁ«ÖÿÁ«Öÿ½ªØÿ·§àÿ¯¨çÿª¨íÿ¦¨ïÿ£©ñÿ¢©ñÿ£©òÿ£©ñÿ¤¨ñÿ¦¥îÿ¨¤ëÿ©¤ëÿ¨¤êÿ¨£èÿ§£èÿ§¢éÿ§£éÿ¦£éÿ¦£ëÿ¥£ëÿ££íÿ¢¤ïÿ£©õÿ_Y‚ÿD=iÿ#%ÿÿÿ(1ÿ7-Nÿ|€Ãÿ™žíÿ”˜æÿ””äÿ—“âÿ›•àÿ›•àÿ›”ßÿž•ÞÿŸ”Úÿ “Ùÿ ”Ùÿ¡”×ÿ£•×ÿ¤•×ÿ¥–×ÿ¤•Öÿ¤•Õÿ¥•Ôÿ¦”Óÿ¨•Òÿ©–Òÿª—Óÿª–Ôÿ©–Ôÿ©–Ôÿª–Òÿ«–Ïÿ¬–Ïÿ«•Îÿ¬•Ïÿ¬•Ìÿ«”Êÿ«“Éÿ©‘Èÿ©‘Èÿ¨�Æÿ¦�Äÿ¦ŒÂÿ¥‹Àÿ¤ŠÁÿ£‰¿ÿ£ˆ¼ÿ¥‰ºÿ¥ˆºÿ¤ˆ»ÿ£‡»ÿ£†»ÿ¢†¼ÿ¢…ºÿ¤†¶ÿ£…µÿ¢…µÿ¢…¶ÿ „¸ÿŸƒ¹ÿŸƒ¸ÿž�µÿž€²ÿ�±ÿ›~°ÿš|°ÿ˜z°ÿ—z¯ÿ—z­ÿ˜{­ÿ˜z¬ÿ˜y«ÿ™z®ÿ™{®ÿš}°ÿœ}±ÿš}²ÿ˜|±ÿš{³ÿ–{µÿ”{¶ÿ’z¹ÿ‘zºÿ�yºÿ�w¹ÿŽw¹ÿ‹v¸ÿ‰u¹ÿ‡t¼ÿ†t»ÿ†t»ÿ…s¸ÿ…s·ÿ„r·ÿ„qµÿ‚p´ÿ�o²ÿƒm¯ÿ�l­ÿ�l¬ÿ€k«ÿ̾íÿ̾íÿË¿îÿÌ¿ïÿ˼íÿʼìÿʼíÿɼíÿ˼ìÿʼìÿɽìÿÇ»ïÿļñÿ»òÿ»òÿºòÿ¿»óÿ»»øÿ·½üÿµ¿þÿ³¿þÿ®¿þÿ«Àþÿª¾þÿ¨½þÿ¨½þÿ¥¾þÿ¦½þÿ¦¼þÿ¨¼þÿ©ºþÿªºþÿª¸ýÿ¬·üÿ®¸ûÿ¯¸ûÿ®¸ûÿ¯¶ûÿ¯³øÿ³³öÿ¸²ðÿ¼²îÿ¿³éÿÀ³èÿÁ³çÿIJãÿȲÞÿ̳ØÿϲÑÿгÎÿгÎÿϳÒÿͳÕÿ̳×ÿʲÙÿʱÙÿȰÚÿȱÚÿȲÙÿȱÚÿǰÛÿįÝÿïßÿ®ßÿÀ­ÞÿÁ­Þÿ¿­ßÿ¿¬àÿÀ«ÝÿÀ«ÙÿêÕÿªÔÿÀªÖÿ»©Üÿ³¨çÿ¬©ìÿ§¨îÿ¥¨ïÿ£ªñÿ£ªóÿ£ªóÿ¤©ñÿ¦§îÿ§§îÿ¨¦íÿ§¥ìÿ¦¥ìÿ§£êÿ§£éÿ§£éÿ§¤êÿ¦£êÿ¦£ëÿ¤£ìÿ¢£ìÿ¦¨õÿ[Rzÿ+ 2ÿÿÿ +ÿ(3ÿ82Wÿtv³ÿ˜�ëÿ”–æÿ••åÿ™”ãÿœ–âÿš•ßÿ�–ßÿŸ–Þÿ –Úÿ¢•Øÿ£”Õÿ¤•Öÿ¥–Õÿ¦—Õÿ§—Öÿ¦–×ÿ§—Øÿ¦—×ÿ§—Ôÿª—Ôÿ«—Óÿ«˜Òÿ¬—Òÿ¬–Ñÿ¬–Îÿ­–Îÿ®–Ëÿ¯–Êÿ¯–Ëÿ®–Êÿ®”Êÿ­“Éÿ«’Èÿ«’Çÿª‘Æÿª�Äÿ¨�Âÿ¨Œ¾ÿ¨Œ¼ÿ§‹½ÿ¥Š½ÿ¦Š»ÿ¥‰¸ÿ¥ˆ¸ÿ¥ˆ¹ÿ¤ˆ¼ÿ£†¼ÿ¤†½ÿ¤‡»ÿ¥‡¸ÿ¤‡µÿ¤†¶ÿ¢…·ÿ¢„¸ÿŸƒ¹ÿŸ‚¸ÿŸ�¶ÿž€´ÿœ´ÿœ~´ÿš{³ÿ–{´ÿ–z´ÿ•{²ÿ–z±ÿ—z±ÿ–y±ÿ–z³ÿ—{´ÿ˜|µÿ˜}¶ÿ™~¸ÿš¹ÿ˜ºÿ—~»ÿ–¼ÿ’}½ÿ�{¾ÿ�{¿ÿ‹zÀÿ‹x¾ÿŠw½ÿ‰v½ÿˆv¼ÿ‡u¼ÿ‡u¼ÿ…t¼ÿ…s»ÿ…s»ÿ„r¸ÿ„p¶ÿ‚n³ÿ‚l®ÿ�l«ÿ�l©ÿ€j¦ÿʽíÿʾîÿ;íÿξíÿ;ìÿͽíÿʽìÿ˽ìÿ̼ëÿ̼êÿ˽ëÿɽîÿǽðÿżðÿļðÿ¼ðÿ¿¼ôÿ¼¼øÿ¸¿ûÿ·Àýÿ´Àþÿ¯Áþÿ¬Âþÿ¨Áþÿ¦Àþÿ¦Àýÿ¦¿ÿÿ¥¿þÿ¤¾þÿ§¼þÿ©»þÿ©ºýÿ©¹þÿª¹þÿª¸ýÿ«¹þÿ­¹ýÿ®¸ûÿ°·ùÿ´´ôÿ¹²ïÿ¼²ëÿÀ²èÿÁ³çÿ³åÿijäÿƳâÿɳÜÿͳÕÿгÍÿÑ´ËÿÑ´ÌÿÑ´ÏÿϳÔÿ̲Öÿ˲×ÿʱØÿȱÛÿDZÝÿűÞÿƱÞÿŰÞÿïÞÿ¯ßÿÀ®àÿ¿­àÿ¾¬àÿ½«àÿ¾«Þÿ¿ªÛÿÀª×ÿÁªÖÿ¿ª×ÿ¼ªÝÿµ©ãÿ¯©èÿª¨ìÿ¦§îÿ¥©ðÿ¤ªòÿ£ªòÿ¤¨ðÿ¦§îÿ§§íÿ¨§íÿ©§îÿ§¦íÿ§¥ìÿ¨¤ëÿª¥êÿ©¥éÿª¥ëÿ¨¦ëÿ§¤ëÿ¥£ëÿ§©ôÿUKnÿ/%<ÿ(-ÿ!ÿÿ* 4ÿ.%?ÿnl¦ÿ˜›ëÿ”–æÿ–—æÿ™–åÿ™–ãÿš–ãÿ›–áÿž–Ýÿ¢–Øÿ¥–Õÿ¦–Ôÿ§–Óÿ¨—Óÿ¨—Ôÿ©—Õÿ©—Ôÿ¨—Óÿ©—Ôÿª˜Ôÿ«˜Óÿ«™Òÿ¬˜Ñÿ«–Ñÿ¬—Îÿ®–Ìÿ­–Ëÿ®–Ëÿ¯–Ìÿ®•Êÿ®•Éÿ­“Èÿ¬“Èÿ¬’Çÿ«‘Æÿª�Ãÿ©�Áÿ©Ž¾ÿ©�¼ÿ¨‹¼ÿ§‹¼ÿ¦Š¼ÿ¥‰ºÿ¦‰·ÿ¦‰¶ÿ¦‰¶ÿ¦ˆ¶ÿ¥ˆ¸ÿ¤‡¹ÿ¤ˆ¹ÿ¤‡¸ÿ¤ˆ¶ÿ¥ˆ·ÿ£†¶ÿ¢„µÿ¡„¶ÿ ‚¶ÿž€µÿž€¶ÿœµÿ˜~µÿ—}¶ÿ•|·ÿ•|·ÿ•{·ÿ•{µÿ•{µÿ”{µÿ–|¸ÿ–|¸ÿ–}¸ÿ—~»ÿ—½ÿ—½ÿ–¾ÿ“~Àÿ‘~Áÿ�~ÂÿŽ|Áÿ‹zÂÿ‰zÃÿ‡xÃÿ†wÁÿ…vÁÿ…vÁÿ…vÀÿ†uÀÿ„vÀÿƒt¿ÿ„s»ÿ„q·ÿƒq´ÿƒo±ÿƒl°ÿ€l®ÿj¨ÿ~g£ÿʾïÿ˾îÿ̾îÿÍ¿ìÿοìÿÍ¿îÿÌ¿íÿ˾íÿ̾ìÿͽêÿ̽êÿ˾íÿɾïÿƽðÿĽòÿ¼óÿÁ¼ôÿ¾¾øÿº¿ûÿ·Àýÿ´Âþÿ°Âþÿ¬Âýÿ©Ãþÿ§Ãþÿ¦Âýÿ§Áþÿ§Áþÿ§¿þÿ§¾þÿ§½þÿ¦¼þÿ§¼ÿÿ¨»þÿ§»þÿ©»þÿªºþÿ­ºýÿ¯¹ûÿ²·ùÿ·µóÿ»³íÿ¿³éÿÁ³çÿóåÿÅ´ãÿÇ´áÿȳÞÿ˳ÚÿγÔÿгÏÿÑ´ÍÿÑ´ÍÿдÏÿÏ´ÒÿÍ´Ôÿ̳×ÿʲÚÿDzÞÿƲßÿűßÿŰÝÿİÝÿïàÿÁ®áÿ¾­âÿ¼­ãÿº¬ãÿº¬âÿ»ªàÿ¼ªÝÿ»©Üÿ¼©Ýÿº©Þÿ·©àÿ²¨äÿ­¨éÿ¨§ìÿ¦¨îÿ¥©ðÿ¤ªñÿ¥©ñÿ¦¨îÿ¨¨íÿª¨ëÿª§ìÿ«§ëÿ¬§êÿ¬§éÿ­¦çÿ­¦çÿ®¦éÿ¬¦éÿª¦êÿ¨¥ëÿ«ªôÿMCaÿQHxÿ"$ÿ"ÿÿ$)ÿ) 6ÿhe›ÿœžíÿ™™æÿš™çÿ›™æÿš™æÿ›™åÿœ˜ãÿ ™ßÿ¤˜Úÿ¨˜Öÿ¨˜Õÿ©—Óÿ©—Òÿ©˜Òÿ«˜Óÿ«˜Òÿ«—Ïÿ¬˜Ïÿ¬˜Ïÿ¬˜Ðÿ¬˜Ðÿ¬˜Ñÿª—Òÿ«—Ñÿ«—Ñÿ¬–Ïÿ«•Íÿ¬”Ìÿ¬”Ìÿ­”Ëÿ¬“Éÿ«“Éÿ«’Çÿ«‘Æÿ«‘Âÿ¬�Àÿ¬�¾ÿ«Ž¼ÿ¨�»ÿ¨Œ½ÿ¨‹¼ÿ§‹ºÿ§‹¸ÿ¨Š¶ÿ©‹¶ÿ©‰´ÿ©‰´ÿ¨Š¶ÿ§Š¶ÿ¦‰¶ÿ¥‰¶ÿ¦‰¶ÿ¥‡µÿ£†µÿ¢„¶ÿž‚¶ÿœ�¶ÿœ�¸ÿš€¸ÿ™€¸ÿ™€¸ÿ˜¹ÿ˜¹ÿ—~¹ÿ–~¸ÿ–}¸ÿ”}¹ÿ’|¼ÿ’}¾ÿ‘¿ÿ’Àÿ‘Àÿ�}ÀÿŽ~ÄÿŒ}ÅÿŠ|Æÿ‰|Èÿˆ{Æÿˆ{Åÿ‡zÆÿ‡yÅÿ†xÄÿ…xÅÿ…xÅÿ„wÂÿ…wÂÿ„wÂÿ„v¿ÿ…t¼ÿ…r¸ÿ‚o²ÿ�n¯ÿl®ÿ~k¯ÿ|i¬ÿzg§ÿɾñÿʾïÿË¿îÿ˾íÿÌ¿îÿÌ¿îÿÌ¿îÿÌ¿ïÿË¿ïÿÌ¿îÿÌ¿ìÿÍ¿ìÿ˾íÿȾðÿƾóÿ¾öÿÁ¾÷ÿ¿¿øÿ¼¿ûÿ»Áýÿ¶Âýÿ³Ãþÿ¯Äþÿ«Äþÿ©Åþÿ¨Äþÿ§Âýÿ¨Áþÿ¨Àþÿ¨¿þÿ§¾ÿÿ¥¾þÿ¤¾þÿ¤¼ÿÿ¤¼þÿ¥¼þÿ¦¼þÿ¨»þÿ¬¹ýÿ°¸ûÿ´¶øÿ¹´ñÿ¿´êÿóåÿŲâÿȳßÿɳÜÿÌ´ÙÿÍ´ÕÿϳÒÿгÏÿÒ´ÌÿѵÊÿÑ´ÌÿѳÌÿÏ´Ñÿ̳ÔÿʳÛÿƲßÿƱßÿƱÞÿűÞÿŰÜÿŰÜÿïßÿ¿®âÿ»®äÿ¹¬åÿ·«åÿ¶«åÿ¶ªåÿ¶©ãÿ·©áÿ¶©áÿ¶¨âÿ²¨äÿ®©èÿª§ëÿ§¦ïÿ£¨îÿ¥©ðÿ¦¨ïÿ¨¨îÿ«¨ìÿ­¨éÿ®§çÿ±¨çÿ²¨åÿ²¨åÿ³¨åÿ±§äÿ°§æÿ®§èÿ¬§êÿ©¦ëÿ®¬õÿF;VÿD>cÿ ÿÿ ÿ, 4ÿ>3Xÿda‘ÿŸ ïÿ�›çÿ�›çÿœ™åÿœ™åÿœ™åÿ�˜âÿŸ™áÿ£˜Ýÿ§šØÿ©˜ÖÿªšÕÿ«™Ôÿª˜Ôÿ«—Òÿ«˜Òÿ¬˜Ðÿ­—Ïÿ­˜Ðÿ®˜Ðÿ®˜Ðÿ«—Ðÿ«˜Ñÿ¬—Ñÿ«—Ðÿ¬–Ïÿ¬–Îÿ¬•Ìÿ¬•Ìÿ«”Ìÿ«”Ìÿª“Ëÿª’Éÿª‘Çÿ¬‘Åÿ¬�Áÿ­�Àÿ«�½ÿ«Ž¼ÿªŽºÿª�ºÿ©Œºÿ©Œ¹ÿªŒ·ÿ«‹¶ÿª‹´ÿ«‹³ÿ«‹´ÿª‹´ÿ¨Šµÿ§‰¶ÿ¥ˆ¶ÿ¤‡µÿ£†¶ÿ¡„¶ÿ�‚·ÿ�‚¸ÿ›�ºÿ™�»ÿ™€¼ÿ˜€¼ÿ˜€»ÿ˜€¼ÿ˜»ÿ˜€»ÿ—€»ÿ–½ÿ“~½ÿ’}¿ÿ�~Áÿ�ÃÿŽ~Åÿ�ÇÿŠ~Èÿ‰}Èÿ‡|Éÿ„}Íÿƒ|Íÿ„|Ìÿ„{Êÿ†zÈÿ†zÇÿ‡zÈÿ†zÇÿ†yÅÿ…xÃÿ†xÀÿ‡w½ÿ‡t»ÿ„r¹ÿ‚r¸ÿn²ÿ|j­ÿ{i®ÿyh¬ÿvd©ÿƾóÿÈ¿ñÿÊ¿ðÿÊ¿ïÿÊ¿ïÿ˾ïÿʾïÿÊ¿ðÿÊÀñÿËÀñÿÌ¿ðÿοíÿÍ¿íÿÍ¿ëÿÍ¿îÿÈ¿ñÿÅ¿ôÿ¾÷ÿ¿¿ùÿ¼Áüÿ¹ÃýÿµÃþÿ±Äýÿ®Åþÿ«Åþÿ©Äþÿ©Âÿÿ¨Âþÿ§Áþÿ¨Àþÿ¨¿þÿ¦Àþÿ¤¿ÿÿ£¾þÿ¢½ýÿ£¼þÿ¤¼þÿ¦¼þÿª»ýÿ®¹üÿ±·øÿ¶´òÿ½´ìÿ´æÿƳàÿɳÝÿÌ´ÙÿÍ´ÔÿϳÑÿÏ´ÏÿÑ´ÍÿÓ´ËÿÓ´ÉÿÑ´ÊÿÑ´ÌÿдÏÿͳÒÿ̳ØÿȱÛÿűÜÿŰÜÿƱÛÿǰÛÿȰÚÿűÛÿïÝÿÁ¯àÿ¾®áÿº¬ãÿµ«çÿ²«çÿ²ªåÿ´©äÿ´¨ãÿ´¨ãÿ³©åÿ±¨æÿ­¨èÿª§êÿ©§ìÿ§§ìÿ©¨ìÿ«¨ìÿ­¨êÿ°©èÿ²©åÿ´©ãÿµ©âÿ·©ãÿµ©âÿ´©äÿ²¨æÿ¯¨èÿ¬§éÿª¦ëÿ®¬õÿ?5Jÿ(-ÿ, 2ÿ"ÿ ÿ*!2ÿHAjÿ[U€ÿ£¡îÿŸœæÿŸ›åÿž™äÿ�˜âÿ�—ßÿ ˜ßÿ¡™àÿ¤™Üÿ¨™Øÿ©™Õÿ«™Óÿ¬šÔÿ¬šÓÿ«˜Òÿ«—Òÿª—Ñÿ«˜Òÿ«˜Òÿ«˜Ðÿ¬—Ðÿ¬˜Ðÿ«˜Ðÿ«˜Ðÿ®—Ïÿ­—Îÿ­—Íÿ­–Îÿ¬•Íÿ«•Ìÿª”Íÿª“Ëÿ©’Êÿª‘Èÿ«‘Æÿ«‘Ãÿ¬�Áÿ¬�Àÿ¬�¾ÿ¬�½ÿ«�¼ÿ«Ž»ÿ«Ž»ÿ¬Ž¹ÿ­�·ÿ­�¶ÿ­�µÿ¬Œµÿª‹µÿ¨Šµÿ¥ˆ´ÿ£†¶ÿ¢…µÿ¡…µÿŸƒ·ÿ�‚¸ÿš‚ºÿš‚½ÿ™‚½ÿ–�¿ÿ–�¿ÿ•€Àÿ•�¿ÿ•�¿ÿ•�¿ÿ–‚¾ÿ–�¿ÿ”�Áÿ“�Âÿ��ÆÿŽƒÌÿŠ‚Íÿ‰�Ïÿ‡Ñÿ…~Ñÿ„Òÿ‚€Ôÿ‚Óÿ�~Òÿ‚~Òÿ‚}Ðÿ‚{Íÿƒ{Ëÿ„zÉÿ„yÆÿ…wÃÿƒv¿ÿƒt¼ÿ‚p¸ÿo·ÿ~o¸ÿ|m³ÿ{i¬ÿxfªÿue«ÿte«ÿÄ¿ôÿÅ¿óÿÇ¿òÿÈ¿ñÿʾðÿɾïÿʾîÿʾíÿÌ¿ïÿË¿îÿËÀïÿÌÀïÿÏ¿éÿÑ¿æÿÒ¿åÿÑ¿äÿοëÿÊÀðÿÆÀôÿÀÁúÿ¼Åþÿ¸Æþÿ´Åýÿ±Åþÿ®Åþÿ©Åþÿ¨Åþÿ¨Äþÿ¦Ãþÿ¦Áþÿ¦Áÿÿ¦Áþÿ¥Áþÿ£Àþÿ¢Àýÿ¢¿þÿ£¾þÿ¦¼þÿª»þÿ®¹üÿ±¸øÿ¶´óÿ»´îÿÁ´æÿÇ´áÿʵÜÿ̶ÙÿεÔÿдÒÿÏ´ÎÿдÍÿÒ´ÌÿÓ´ÊÿÒµÊÿÒ´ËÿÑ´ÎÿÏ´ÐÿÍ´Ôÿʲ×ÿDZÙÿƱÜÿŰÛÿDZÛÿȱÚÿDZÚÿűÜÿİÞÿÁ¯àÿ½®âÿº®äÿ·«åÿ³«ãÿµªäÿ´©äÿµªãÿµ©äÿ´ªåÿ²©åÿ°¨æÿ®¨èÿ¬©éÿ¬¨êÿ¬¨éÿ¯©èÿ±ªçÿµ«æÿ¶«äÿ¸«äÿ¸ªäÿ¶ªäÿµªäÿ²©æÿ±©èÿ¯©éÿ«¨ëÿ¬¬ôÿ@5MÿZT‰ÿ-"4ÿ%"ÿ"!ÿ=4Sÿ6+FÿYPxÿ§¢ëÿ¢�áÿ£œàÿ¢šàÿ¢™ßÿ£™Ýÿ¥™Ûÿ§™Ùÿ©š×ÿª›Öÿ¬›Ôÿ­›Òÿ®›Óÿ­›Óÿ¬šÔÿ«šÕÿªšÕÿª™Ôÿ«™Ôÿª˜Òÿ«˜Ñÿ¬™Òÿ«™Ñÿ¬˜Ðÿ®˜Ðÿ®˜Ïÿ®—Îÿ­—Îÿ«–Íÿ«•Ìÿ¬”Ìÿ©”Ìÿ¨’Íÿ©’Ëÿ©’Éÿ©’Çÿ«�Åÿ¬‘Âÿ«‘Àÿ¬�Áÿ¬�¿ÿ­�¾ÿ­�¼ÿ®�»ÿ­�¸ÿ®�·ÿ­Ž·ÿ¬�·ÿ©Œ·ÿ¨Š¶ÿ¤ˆµÿ¡…¶ÿ „·ÿž„¸ÿž„ºÿ�ƒºÿ›ƒ½ÿ™‚¾ÿ–‚Àÿ”‚Âÿ“ƒÄÿ“‚Åÿ“‚Åÿ“„Åÿ”„Æÿ”„Åÿ”„Æÿ•„Çÿ“„Èÿ‘„Ëÿ�„ÑÿŠ„Óÿ‰„Ôÿ†ƒÖÿ„„Ùÿƒ†Ùÿ‚ƒÙÿ�‚×ÿ€�Öÿ‚�×ÿ�Õÿ�}Ñÿ‚|Íÿ‚zÊÿ‚xÆÿ�uÂÿr¾ÿ|p»ÿ|n¸ÿxl´ÿyk³ÿvh°ÿue¬ÿscªÿqc«ÿoc­ÿÄ¿÷ÿľóÿÅ¿óÿžóÿƾóÿǾñÿɾïÿɾîÿÊ¿îÿÌ¿ïÿË¿ïÿÌÀîÿÏÀìÿÑ¿æÿÓÀâÿÖ¿ÝÿÕ¿àÿÑ¿çÿËÀñÿÃÂùÿ¾ÅþÿºÇþÿ·Åÿÿ¶Äþÿ²Äþÿ¬Çþÿ¨Éþÿ¦Èþÿ¥Æýÿ¦Äþÿ¥Áþÿ¥Âþÿ¤Âþÿ¢Ãþÿ ÃþÿŸÃþÿŸÀþÿ¡¾þÿ¦¼þÿªºýÿ°¸úÿ¶µòÿ¾µëÿÄ´æÿȵÝÿͶÛÿÍ·ÚÿжÖÿжÓÿѵÐÿѵÎÿгÌÿÑ´ËÿÒ´ÉÿÓµÈÿÒµÊÿѵÍÿгÏÿ˳ÓÿɲØÿƲÚÿűÜÿıÝÿİÜÿƱÛÿưÛÿİÜÿ¯ßÿÁ¯âÿ¼®ãÿ¹­äÿ¸­åÿµ«åÿ¶ªäÿ·«ãÿ¸«ãÿ·«ãÿ·ªâÿ´©ãÿ³©åÿ²©çÿ°©èÿ°ªèÿ±©èÿ²ªçÿ´«çÿ·«åÿ·«äÿ·ªåÿ¶«åÿ´«çÿ²«èÿ±ªêÿ¯©ëÿ¬©ëÿª©ðÿ>3KÿC;eÿÿ!ÿÿÿ4)EÿZPzÿª¤ìÿ¨žâÿ¦œÜÿ¦›Úÿ¨›Ùÿ©›Ùÿ«œÙÿ¬�×ÿ®œÖÿ°žÕÿ°œÕÿ¯œÒÿ¯œÓÿ¯œÓÿ­œÕÿ©›Øÿ©šØÿ©š×ÿª›Õÿ«šÔÿ¬›Ôÿ«™Ôÿª˜Óÿª˜Òÿ«˜Ñÿ¬˜Òÿª–Òÿ¨–Ñÿ¨•Òÿ¨”Ñÿ§”Ïÿ¦“Ïÿ¤‘Ïÿ¤‘Îÿ¥’Ìÿ§‘Éÿ¨’Èÿª‘Åÿ«�Ãÿ«‘Ãÿ«�Áÿ­�Àÿ­�½ÿ®�¼ÿ¯�ºÿ¯�¹ÿ®�¸ÿ­Ž¹ÿ¬�¸ÿ©‹·ÿ¦‰·ÿ¢‡¸ÿŸ…ºÿŸ„»ÿ�…»ÿœ„¼ÿ�…¿ÿš„Àÿ˜„Äÿ–„Æÿ•…Éÿ’„Ëÿ‘…Îÿ‘†Ðÿ�†Ñÿ�†Òÿ‘‡Óÿ�‡Òÿ�‡Óÿ�‡Õÿ�ˆÖÿŒˆÙÿЇÚÿ‰ˆÛÿ‡ˆÛÿ††Úÿ…„Úÿƒ‚×ÿƒ€Ôÿ‚€Óÿ‚~Òÿ�|Ïÿ‚zÊÿ€xÉÿ~uÄÿ}rÀÿ{p»ÿzm¸ÿxk´ÿvh°ÿvg®ÿtd­ÿrc«ÿqc«ÿna«ÿmb®ÿÂÀ÷ÿÃÀöÿÄ¿÷ÿ¿öÿÿöÿľôÿÆ¿óÿÇ¿òÿÈ¿ñÿÉ¿ñÿÊ¿ðÿÍÀîÿοéÿÑ¿çÿÒ¿äÿÓ¿áÿÔÀáÿÓÀãÿÑÁçÿÊÁðÿÂÅûÿ¼ÇþÿºÆþÿ¸Åþÿ¶Åþÿ²Æþÿ­ÈþÿªÇþÿ§Æþÿ¦Åþÿ¥Äþÿ¥Ãþÿ£Âþÿ ÄþÿžÄþÿŸÄþÿžÃþÿ Áþÿ¢¿þÿ§¼ÿÿ¬ºüÿ²¸÷ÿ¹¶ðÿ¿µèÿǵáÿ̶ÜÿͶÙÿÏ·ÙÿзÕÿѶÒÿѵÏÿÒ¶ÍÿÒ´ÊÿÒ³ÇÿѳÇÿдÈÿÑ´ÊÿÑ´ÍÿδÑÿʳÕÿDZÙÿŰÜÿŰÞÿðßÿðÝÿİÜÿİÝÿűÞÿ°ÞÿÀ¯áÿ½®âÿ¹­ãÿ¸¬äÿ·«äÿ·¬äÿ¸«âÿ¹«áÿº«àÿº«àÿ¸«âÿµªâÿ´«åÿ³«æÿ³«èÿ²«éÿ³«èÿ´«çÿ¶¬æÿ´¬çÿ´¬èÿ²¬éÿ°«ëÿ¯«ëÿ®ªëÿ¬©ëÿ¨¥éÿ>5Mÿ3)Bÿ "ÿÿ ÿ&)ÿ@8WÿSHjÿ¬§îÿ¨ äÿ©žßÿ©�Üÿ©�Úÿ«�Úÿ¬�Øÿ­žØÿ¯Ÿ×ÿ±ŸÖÿ±ŸÕÿ±ŸÕÿ±žÕÿ¯�Öÿ­�×ÿ«œØÿ©œØÿª›×ÿªœ×ÿ¬œÕÿ­›Ôÿª™Õÿ©™Ôÿ¨˜Ôÿ§—Ôÿ§—Óÿ¥•Ôÿ¥”Óÿ¥”Òÿ¥”Òÿ¥“Òÿ£’Ðÿ¡‘Ðÿ¢‘Ïÿ¤’Íÿ¥‘Ëÿ§‘Éÿ©’Çÿª‘Åÿ«‘Äÿ¬‘Âÿ¬‘Àÿ®’¿ÿ®‘¼ÿ®‘¼ÿ¯‘»ÿ¯�¹ÿ¯�·ÿ¯Ž¶ÿ¬�·ÿ§‹·ÿ¤ˆ¹ÿ¡†»ÿŸ‡¼ÿž†½ÿž†½ÿ�†¾ÿ›†Áÿ˜†Äÿ—†Æÿ–‡Éÿ•‡Íÿ“‡Ïÿ‘ˆÑÿ�ˆÓÿŽˆÔÿ�ˆÕÿ�ˆ×ÿŒˆ×ÿŒ‰ÙÿŒ‰Ûÿ‹ŠÚÿЉÛÿˆ‰ÛÿˆŠÛÿ††Ùÿ‡ƒ×ÿ†‚Óÿ…€Ñÿ…~Ðÿ‚{Íÿ€yÊÿyÈÿ}uÅÿ|sÀÿ{p¼ÿyn¸ÿxl¶ÿvj²ÿuh°ÿuf­ÿtd¬ÿrd¬ÿpc«ÿoc­ÿmc¯ÿÀÂûÿÃÂùÿÃÁùÿÃÁøÿÃÀ÷ÿÃÀ÷ÿÃÀõÿÆ¿óÿÆ¿ñÿÆ¿òÿÆ¿òÿÈÀòÿËÀîÿÍ¿êÿÑ¿èÿÐÀèÿÐÀéÿÓÁéÿÒÂæÿÐÂêÿËÃòÿÃÅûÿ¾Åýÿ¼Äýÿ»Äþÿ¸ÃýÿµÅþÿ°Æþÿ¬Æþÿ©Åþÿ§Äþÿ¦Äýÿ¥Åþÿ¤Äÿÿ£Ãþÿ¢Äþÿ¢Ãþÿ¢Áþÿ¤Àýÿ¨¾þÿ«¼þÿ®ºüÿ´¸÷ÿ»¶ðÿ¶èÿǶâÿË·ÞÿθÙÿѸÔÿÒ¸ÐÿÓ¸ÍÿÕ¸ÉÿÕ·ÆÿÕ¶ÄÿÖµÂÿÒ³ÄÿϲÇÿϲËÿÏ´ÏÿÍ´Ñÿ̳Ôÿʳ×ÿȳØÿƲÛÿƲÜÿƱÜÿƱÛÿƱÛÿűÛÿñÜÿ°Þÿ¿°àÿ¼®ãÿ»®ãÿ¹­âÿº¬ãÿº¬áÿ¼­ßÿ½¬ßÿ¼¬àÿº¬àÿ¹«áÿ·«äÿ´¬åÿ´¬èÿ´¬éÿ´¬éÿ´¬èÿµ¬èÿ³«èÿ²«èÿ±«êÿ°ªëÿ®ªëÿ­ªêÿ§¢äÿ5+>ÿ;1Nÿ2(@ÿ$"ÿÿ3';ÿ\R�ÿM?[ÿ®¨íÿ©¢æÿª¡åÿ©Ÿâÿ©Ÿßÿ¬ŸÝÿ®ŸÜÿ¯ Ùÿ²¡Øÿµ¢Öÿµ¢Öÿ¶¢Öÿµ¡Õÿ´¡Öÿ±Ÿ×ÿ®Ÿ×ÿ®ž×ÿ®žÖÿ®žÕÿ¯�Ôÿ®�Ôÿ¬›ÔÿªšÔÿ©™Ôÿ§™Ôÿ¨—Óÿ§—Óÿ§—Óÿ¦–Ñÿ¦•Ñÿ¦”Ïÿ¦“Ïÿ¤“Îÿ¥’Íÿ¦’Íÿ¦“Ìÿ§’Êÿ©“Èÿª“Çÿ¬’Æÿ¬“Äÿ¬“Âÿ®’¿ÿ¯’¿ÿ¯’¼ÿ°’ºÿ±‘·ÿ±‘µÿ²‘µÿ±�·ÿ«Ž·ÿ¨Œºÿ¥Š¼ÿ£‰½ÿ¢‰¿ÿ¢‰¿ÿ ‰ÀÿŸˆÂÿœˆÅÿ™‡Æÿ™‰Çÿ•ˆÌÿ“ˆÐÿ�‰Ôÿ�‰ÖÿŒ‰ØÿЉÙÿŠˆÙÿ‰‰Úÿ‰‰ÚÿŠŠÜÿ‰‹Ýÿˆ‹Üÿ‰ŒÝÿˆŒÞÿ‡‰Ýÿ‡‡Úÿ†‚Ôÿ†Ðÿ„}Íÿ‚{Êÿ}wÇÿ|vÇÿ{sÄÿxo½ÿym¹ÿxkµÿvi±ÿvh®ÿuf¬ÿtfªÿscªÿsd¬ÿrd«ÿrd¬ÿpd®ÿ¾ÃýÿÁÃüÿÂÂúÿÂÂúÿÃÂùÿÂÂùÿÃÁøÿ¿øÿÃÀöÿÄÀöÿÄ¿õÿÅ¿öÿÆÀôÿÉ¿òÿÌÀîÿÎÀíÿÐÀìÿÏÁëÿÑÀêÿÑÂëÿÏÂíÿÊÂóÿÄÃúÿÀÄýÿ¾Âýÿ¼Âýÿ¹Ãýÿ¶Äýÿ³Äþÿ±Äþÿ¯Äþÿ«Åþÿ©Åþÿ§Ãþÿ¦Ãþÿ¥Ãþÿ¤Âþÿ¤Àþÿ¥¾þÿ¨¾ÿÿª¾þÿ®½þÿ²¹ùÿ¹¶òÿ¿·ëÿÅ·äÿÊ·àÿ͸ÜÿѹÖÿÒ¸ÒÿÔ¹ÏÿÖ¹Ëÿ׸Çÿ×·Äÿ×¶ÂÿÖµÂÿÔ´ÄÿÑ´ÈÿβÊÿδÏÿεÑÿδÓÿÌ´ÖÿÊ´×ÿɳÚÿȲÛÿDZÛÿƲÛÿƲÝÿűÜÿİÝÿðßÿÀ°áÿ½¯âÿ¼®ãÿ»®âÿ½­âÿ½®àÿÀ®ÞÿÀ®Þÿ¾­Ýÿ½­ßÿ»¬áÿ¹¬åÿµ­çÿ´­éÿµ¬èÿ¸­æÿ·­åÿ·¬åÿ¶¬æÿ´«çÿ²«èÿ²ªèÿ°ªèÿ¤žÛÿI<[ÿkg�ÿ/$9ÿ'(ÿ%$ÿKAbÿ8,CÿUEbÿ±¥àÿ²¤àÿ°£àÿ°¢âÿ®¢áÿ¯¡ßÿ±£Þÿ²£Ûÿ¶¤Ùÿ¹¤Øÿº¤×ÿ»¤Ôÿº¤Óÿº¤Óÿ·£Ôÿµ¡Õÿ³ Öÿ²ŸÕÿ±žÔÿ°�Ôÿ¯œÓÿ®�Ôÿ­›Ôÿ­šÓÿ¬šÒÿ¬™Óÿ«™Òÿ¨—Ñÿ©–Ñÿª–Îÿ©–Îÿ©“Îÿ¨“Íÿ§“Íÿ¨“Íÿ¦“Íÿ¦“Íÿ¨“Êÿ«“Èÿª“Èÿ¬’Çÿ«’Äÿ­’Ãÿ®’Àÿ¯“½ÿ±“ºÿ³“¸ÿ³“¶ÿ´“¶ÿ²‘¶ÿ°�¸ÿ¬�¹ÿ©�¼ÿ¦‹¾ÿ¥ŒÀÿ¤ŒÁÿ¤ŒÁÿ£‹Âÿ ŠÄÿ�‰Çÿ—ˆÊÿ“ˆÐÿ‘‰ÕÿމØÿ‹ŠÛÿŠŠÜÿ‹ŒÞÿ‹�ÞÿŠŒÞÿ‰‹Þÿ‰‹ÝÿŠŒÞÿˆŒáÿ‡‹áÿ†‹áÿ†‰Þÿ„‡Ûÿ„‚×ÿƒ|ÏÿyÈÿ|vÅÿ{uÄÿxsÄÿvqÄÿunÀÿsl½ÿsj¶ÿth±ÿrf®ÿsfªÿte«ÿse¬ÿsd«ÿteªÿrcªÿrd«ÿ»Âüÿ¿ÃüÿÂÅüÿÁÄüÿÂÃûÿÂÄüÿÁÄûÿÀÃûÿÁÁúÿÂÁùÿÃÁøÿÄÀøÿÄÁõÿÅÀóÿÉÀòÿËÀïÿÎÀëÿÐÀéÿÒÀçÿÐÁéÿÏÂìÿÎÁíÿËÂðÿÇÂõÿÂÃúÿÀÃûÿ½ÄþÿºÄþÿ¸Âýÿ·Âýÿ´Âþÿ°Ãýÿ¯Äýÿ¬ÃþÿªÃýÿ¨Ãþÿ§Âþÿ¥Áýÿ¥Àþÿ§¿þÿ¨¾þÿ«¾þÿ°¼üÿ¶º÷ÿ»¸òÿ¿·íÿÄ·äÿÉ·ÞÿÍ·ÙÿиÕÿÒ¹ÒÿÔ¸ÎÿÕ¸Éÿ׸ÅÿØ·ÃÿÖ¶ÁÿÕ¶ÁÿÔ¶ÅÿѵÈÿͳÌÿɱÑÿɱÖÿʳØÿɳÙÿɳÚÿDzÚÿDzÚÿdzÜÿƲÝÿƲßÿŲÞÿűÝÿñßÿÁ°áÿ¾¯âÿ½®ãÿ½®ãÿ¼®áÿ¾¯àÿÁ®ÝÿÁ¯Üÿ®ÛÿÁ®Üÿ¿®Ýÿ½®àÿ¼®âÿ»®ãÿ»®ãÿ½®ãÿ»­âÿ¹¬âÿ¸¬äÿµ¬åÿ³«æÿ²ªèÿ£šÔÿSÿ³¢Óÿ¸¦×ÿ¸¦Ùÿ·¦Ûÿµ¥Üÿ´¦Ýÿµ¥Ýÿ·¤Ûÿ¹¥Ùÿ»§Öÿ¾§ÓÿÀ¨ÐÿÁ¨ÎÿÀ§Îÿ¾¥Ïÿ»¤Ñÿ¸£Ñÿ·¡Ðÿ·¡Ñÿµ Ñÿ³ Ñÿ³žÒÿ±žÒÿ±�Ñÿ°œÐÿ®›Ðÿ­šÐÿ«˜Ðÿ©—Ðÿ¨–Íÿª•Ìÿª•Ëÿ¨”Ëÿ©“Ìÿ¦“Ìÿ¥’Îÿ¦“Íÿ§“Êÿ¨“Éÿª“Èÿ©’Èÿ¨’Çÿ©’Åÿ«’Âÿ®’¿ÿ¯“¼ÿ±“ºÿ²“¹ÿ³“¸ÿ³”¹ÿ²“¸ÿ°’ºÿ­�¼ÿª�½ÿ¨�Àÿ¨�Ãÿ¦�Ãÿ¦�Âÿ¥ŒÃÿ¢ŒÅÿž‹Éÿ™ŒÏÿ”‹Ôÿ�ŒØÿŽ�Üÿ�ŽÞÿŒ�ßÿ‹Žàÿ‹ŽàÿŠ�áÿˆŒáÿ†ŒàÿƒŠáÿ‚Šåÿ€‰âÿ…Ýÿ‚Úÿ}Ôÿ{{ÏÿzvÈÿxsÅÿvqÃÿsqÆÿroÅÿpnÃÿonÂÿni¹ÿpg¶ÿqg³ÿqf°ÿqe­ÿrf®ÿqe¯ÿqf¯ÿqe¯ÿpd®ÿ¾ÆýÿÀÅýÿÁÅýÿÁÆüÿÁÈþÿÀÈþÿÀÈýÿÁÇýÿÃÄúÿÆÂöÿÇÂôÿÆÂöÿÄÁõÿÅÁôÿÆÀóÿÈÁóÿÊÁðÿÍÁïÿÏÁëÿÑÁçÿÑÂçÿÐÁèÿÍÀéÿÌÁîÿÈÂóÿÆÂôÿÃÂ÷ÿ¿Áúÿ»ÁûÿºÂýÿ·Âþÿ³Âýÿ°Ãþÿ¬ÃýÿªÄýÿ«Äþÿ«Âþÿ«ÂþÿªÂþÿ©Àþÿ©Àýÿª¾þÿ­¼þÿ±»ûÿ·¹öÿ¼¸ñÿÀ¸éÿŶâÿɶÞÿË·ÙÿηÕÿÒ·ÐÿÓ¹ËÿÕ¸ÈÿÖ¶Åÿ×·ÄÿÖ·ÅÿÕ·ÆÿÓ¶ÇÿдËÿͳÎÿȱÐÿůÕÿűÙÿdzÚÿDzÙÿʳÚÿÊ´ÚÿȳÚÿÈ´ÛÿȳÛÿƲÛÿƲÝÿıÞÿ±ÞÿÁ°àÿÀ°âÿ½¯áÿ¾¯áÿÁ°ßÿ°ÜÿİÙÿŰ×ÿİØÿïÚÿ¯ÝÿÀ¯ÞÿÀ¯ßÿÀ¯ßÿ¿¯àÿ¾¯àÿ¼®àÿ»­àÿ¸«âÿ´«æÿŸ•ËÿFQÿ¯›ÄÿÁ©ÒÿªÐÿªÐÿëÐÿìÑÿĬÐÿŬÎÿÆ«ËÿÈ«ÇÿÉ«ÄÿÊ­Áÿʬ¿ÿÊ«ÀÿÈ«ÀÿǨÃÿÁ§Èÿ¾¥Ëÿ¼¤Îÿº¢Îÿº£Íÿ¸¡Ìÿ¸ Îÿ¶ŸÎÿ³žÎÿ³�Îÿ²œÍÿ°šÍÿ®˜Íÿª–Îÿ¦“Íÿ¥’Îÿ£‘Íÿ¡�Îÿ¡‘Ïÿ¡�Ïÿ¡‘Îÿ£‘Ïÿ£‘Íÿ¤‘Ìÿ¦’Éÿ©‘Çÿª“Åÿ«’Ãÿ¬’Áÿ®“Àÿ°“¾ÿ¯“¾ÿ±“¼ÿ´•»ÿ¶–ºÿ·—¹ÿ·—¹ÿ´–»ÿ¯”¾ÿ¬’Áÿ«’Ãÿ«’Âÿ«‘Áÿ¬’Áÿ©‘Ãÿ¥�Çÿ �Íÿ™�Ôÿ“�Úÿ�ŽÝÿ�Žßÿ‹�àÿˆŽâÿ„Œæÿ�‹æÿ‰æÿ}‡äÿ{†ãÿz„âÿx�ßÿv~Úÿt{ÕÿrwÒÿrvÎÿpsÉÿopÆÿnoÄÿnoÅÿnnÅÿmmÂÿkj¾ÿmi»ÿmi»ÿni¹ÿng¹ÿnh¸ÿmh»ÿnh»ÿkf¹ÿkfºÿ½Èýÿ¾Éþÿ¾Êþÿ¾ËýÿÀËþÿÂÊýÿÁÊþÿÁËþÿÀËþÿÂËþÿÂÉýÿÄÆüÿÇÆùÿÈÅöÿÈÅ÷ÿÉÄöÿÊÃôÿÍÂñÿÏÂëÿÒÁçÿÓÁãÿÓÁáÿÒÀâÿÑ¿ãÿÑ¿åÿÎÀéÿÌÁîÿÊÂòÿÉÀðÿÇÀðÿÃÀòÿ½Àùÿ·Ãýÿ²Äþÿ«Äýÿ¨Äþÿ§Ãþÿ§Ãþÿ«Âþÿ­Àþÿ¯Àþÿ°¾þÿ°¾ýÿ²¼üÿ³¼úÿµºöÿ¹¸óÿ¿¸ìÿøçÿÆ·ãÿÉ·àÿÊ·ÝÿÌ·Ùÿ϶ÒÿѶÊÿÔ·ÄÿÖ·ÃÿÕ·ÆÿÒ¶ÉÿѶÊÿдÍÿδÐÿÌ´ÓÿʳÖÿƱÖÿįÓÿDZÔÿɲ×ÿɲØÿdzÚÿDzÚÿdz×ÿʳÕÿ˳ÕÿÉ´×ÿɳÙÿɳØÿȲ×ÿdzÚÿŲÜÿıÜÿİÙÿư×ÿȱÓÿɱÑÿɱÓÿDZÔÿŰØÿ°Úÿ¯ÜÿÀ®Ýÿ¾­ßÿº¬àÿ·«âÿ´«æÿ–‹¾ÿSGgÿmc”ÿ2$6ÿ'$ÿ&%ÿOA[ÿ?0AÿcPiÿ®–¹ÿÅ­ÍÿÈ­ÌÿÈ®ËÿÉ®ÊÿÊ®ÉÿÊ®Èÿ˯ÇÿÌ®ÄÿͯÂÿͯ¿ÿή½ÿή»ÿÏ­»ÿά»ÿË«¾ÿÈ©ÁÿŨÄÿÁ¦Æÿ¾¤Èÿ¼£Éÿ¼¢Éÿ¹¡Éÿ·ŸËÿµžËÿ³�Ëÿ²œËÿ±šÌÿ¯˜Êÿ­—Ëÿ«•Êÿ§”Ìÿ¥”Îÿ¤“Ðÿ ‘Ðÿ ‘Ðÿ¡‘Ðÿ¡‘Ðÿ¡‘Îÿ£�Ëÿ¥�Çÿ§‘Æÿ©’Äÿ«“Âÿ¬’¿ÿ°”¾ÿ±”¼ÿ²•»ÿ³”»ÿ³”¹ÿ´•ºÿ¶—¹ÿ·—¹ÿµ—ºÿ´–¼ÿ²•¼ÿ²–¼ÿ±•¼ÿ±”»ÿ¯”½ÿ®“¿ÿ¨‘Åÿ �Ìÿ˜�Öÿ‘�ÞÿŽ�áÿ‹�ãÿ‡Žåÿ�Œçÿ}‹éÿ{ˆèÿx†çÿw…åÿv‚ãÿu�áÿuÞÿt|ÙÿsyÕÿrvÏÿquÍÿptÌÿorÇÿnpÆÿmpÇÿmpÅÿmoÅÿlnÃÿlmÁÿlmÁÿkmÀÿkl¿ÿlk¿ÿllÁÿklÁÿkkÂÿjlÃÿ¹ÊýÿºÊþÿ¼Êþÿ»Êþÿ¾Ëþÿ¿Ìþÿ¿ÌýÿÀÌþÿÁÌþÿÁËýÿÂËþÿÅÈüÿÆÅùÿÈÅöÿÊÆöÿËÅôÿËÄòÿÍÃñÿÎÂïÿÎÁêÿÓÁãÿÔÀàÿÓÀÝÿÔÀàÿÑÀãÿÏÁèÿÌÁìÿËÁðÿÉÁðÿÆÁóÿÄÁõÿÀÁöÿ½Áúÿ¹ÂýÿµÂýÿ±Âýÿ®Áþÿ«ÁýÿªÀþÿ«Àþÿ­¿ýÿ¯¾þÿ°½ýÿ°¾ýÿ²¾üÿ´½ûÿ´¼ûÿ¶»öÿ¼¸ðÿÁ·èÿĸãÿÉ·ßÿÉ·Ûÿ˶ÖÿζÒÿзËÿÒ¶ÈÿÒ¶ÇÿÓ·ÇÿÒµÈÿѶÉÿдÌÿÍ´ÑÿÊ´ÕÿÉ´ÖÿȳÖÿưÖÿůÔÿDZ×ÿÇ´ÚÿDzÛÿŲÛÿDzÛÿʳØÿÊ´ÔÿʳÕÿË´ÔÿË´ÒÿʳÒÿȲÔÿƱÖÿIJ×ÿƱ×ÿƱÕÿȱÕÿȱÓÿDZÔÿűÕÿİÚÿ°ÛÿÁ¯Üÿ½­ßÿ¸¬áÿµ«äÿ²ªæÿ’ˆºÿF=XÿZOwÿ, +ÿ% ÿ"ÿ$ ÿA1>ÿdPdÿ«“¯ÿÈ­ÊÿË®Éÿ˯Èÿ˯Çÿ˯ÇÿͰÆÿͰÃÿͯÂÿΰ¿ÿб½ÿа¼ÿѱ¼ÿÒ°»ÿÒ°»ÿаºÿή»ÿʪÁÿƨÅÿÁ¦Æÿ¿¥Èÿ½¤Çÿ»¢Çÿ¹ŸÇÿ¸ŸÈÿ¶�Éÿ³›Éÿ²šÉÿ°šÉÿ¯˜Çÿ®˜Êÿ«•Êÿ¦”Ìÿ¥“Ïÿ¡‘ÐÿŸ‘ÐÿŸ�Ðÿ �Ïÿ �Íÿ �Íÿ �Ëÿ¢�Èÿ¥�Åÿ©�Äÿ«“Àÿ°”½ÿ³•ºÿµ•¸ÿ¶•¶ÿ¶–¶ÿ´•µÿµ•·ÿ·–·ÿ¸˜¶ÿ¸—¶ÿ·—¶ÿ¶–µÿµ–¶ÿ´•¸ÿ²•ºÿ®”¾ÿ©’Äÿ¡’Îÿ˜‘Ùÿ�’âÿ‹’æÿ†�èÿ‚�êÿ~Œêÿ{‹ëÿy‰êÿw†çÿu„åÿu‚ãÿt€ßÿt~Ûÿt|ÖÿsyÒÿrvÍÿquÌÿosÊÿnrÉÿnqÊÿmqÉÿmqÈÿmqÉÿlqÊÿlpÇÿmoÆÿmoÅÿknÄÿknÄÿjnÅÿinÆÿinÇÿinÇÿ»Ëþÿ»Ìþÿ»Íþÿ¼Íþÿ¾Îþÿ¾Íþÿ¾Íþÿ¾Ìþÿ¾ÊþÿÀËÿÿÀÊÿÿÂÉþÿÃÇýÿÇÆúÿÈÅ÷ÿÈÄõÿÉÅõÿÌÄòÿÎÃñÿÏÄðÿÎÄïÿÏÃìÿÐÁéÿÐÁåÿÑÀäÿÐÁåÿÐÁèÿÍÁìÿÌÀïÿÉÁïÿÇÀðÿÃÀôÿ¿Áøÿ½ÂýÿºÃýÿ¸Âýÿ·Áýÿ³Àþÿ®Àþÿª¿þÿª¿ÿÿ¬¾þÿ¯½þÿ°¾ýÿ²¾ýÿ´¾þÿ´¾ûÿµ½ûÿ´»÷ÿµ¹÷ÿ»·ñÿÀ·èÿÆ·âÿʸßÿÌ·ÝÿηÙÿзÐÿÒ·ËÿÒ·ÇÿÔ·ÇÿÒ·ÇÿÒ¶ÌÿϵÎÿ͵ÒÿʳØÿÈ´ÙÿȳÙÿȳÙÿİÖÿįÕÿDZÔÿȳÕÿdzØÿDzÙÿDzÙÿDzØÿdz×ÿÊ´ÔÿÊ´ÒÿɲÓÿDZÖÿűÚÿűÛÿƲÚÿƲÙÿűØÿűÚÿűÚÿðÙÿİÛÿÁ®Ýÿ½¬àÿ¹¬áÿµ«âÿ²ªæÿŽ„³ÿB5NÿJ?[ÿ- +ÿ ÿ ÿ-(ÿbM\ÿU@Nÿª‘©ÿʯÉÿË®Èÿ̯Çÿ̰Çÿ̰Çÿ̰Çÿ̰Èÿ̰ÇÿαÅÿϱÂÿбÀÿѱ¾ÿÒ°¾ÿÒ±½ÿÒ±¼ÿÓ±¼ÿѱ¼ÿÌ­¾ÿɪÁÿħÃÿÀ¤Åÿ¿¤Ãÿ¿£Áÿ½ Áÿ¹ŸÂÿ¶œÄÿ³›Æÿ±™Çÿ¯˜Éÿ­—Ëÿª•Ëÿ©”Íÿ¥“Îÿ¢’Îÿ ‘Ðÿ �Ðÿž�Îÿ �Íÿ¡�Èÿ£�Çÿ¤�Åÿ¦�Ãÿ§�¿ÿ«�¼ÿ¯‘¸ÿ´”µÿ·–²ÿº–°ÿº˜¯ÿ¼˜¯ÿº—¯ÿ»˜¯ÿ¼™¯ÿ½š®ÿ¾™®ÿ»˜°ÿ·–±ÿµ–´ÿ±”¹ÿ­“¿ÿ¨’Æÿ ‘Ðÿ–�Üÿ�“ãÿ‰’ëÿƒ‘íÿ�îÿ|�íÿz‹ìÿxˆêÿv†éÿv…èÿtƒåÿs€àÿt~Üÿs|ØÿryÓÿqvÐÿpuÎÿnsÌÿmrËÿlqËÿlrÌÿmrËÿlpÉÿkpÉÿlpÉÿmpÈÿkoÈÿjoÈÿjoÉÿjpÊÿipÍÿhpÌÿhpÌÿÀÎþÿ¿Îþÿ½Îþÿ»ÏþÿºÏþÿ¼Ïþÿ¾Ïþÿ¾Ïþÿ¾Îþÿ¿Ìþÿ¿ÉþÿÁÈýÿÂÇýÿÄÆûÿÇÇøÿÉÆ÷ÿÊÆôÿÌÅóÿÎÅðÿÏÃîÿÐÄíÿÑÄìÿÑÄéÿÒÂæÿÑÂçÿÐÁçÿÏÁéÿÎÁêÿÌÁìÿËÁíÿÈÀïÿÅÁóÿÀÁ÷ÿ¼Âûÿ¸Äýÿ¶Ãþÿ´Ãþÿ³Âÿÿ°Àþÿ­Àþÿª¿þÿ©¾þÿ¬½þÿ®¾ýÿ²½üÿ´¾ûÿ´¾úÿµ½ùÿ¶»øÿµ»÷ÿ·ºöÿ»¹ñÿÁ¸èÿƸáÿʸßÿÌ·ÜÿηÖÿиÑÿÓ¸ÊÿÓ·ÅÿÔ·ÅÿÓ·ÇÿѶÊÿжÍÿεÐÿ˶ÖÿɵÚÿȵÜÿÈ´ÚÿűØÿ®Õÿ®ÔÿïÖÿİØÿıÛÿïÛÿ°ÜÿIJÛÿƲÚÿȳ×ÿdz×ÿűÙÿıÚÿŲÛÿƲÙÿDzÙÿƳØÿƱØÿƱØÿİÙÿïÛÿÀ¯Üÿ¼¬Þÿ¹¬áÿ·¬äÿ��­ÿ9-@ÿ:,>ÿ3$1ÿ$ÿÿÿbN^ÿt\jÿ¦ŒŸÿͱÆÿͲÆÿͱÆÿ̰Èÿ˱Ëÿ˱ÏÿɰÐÿʰÎÿ˱Ìÿ̱Êÿ̱ÉÿͱÇÿαÃÿϲÁÿѲÀÿѱ¾ÿÒ°»ÿÒ°¹ÿÏ®¹ÿʪ»ÿǨ¾ÿŦ¿ÿĤ½ÿÄ£½ÿÀ¢¾ÿ»ŸÀÿ¶œÃÿ³›Çÿ°šÈÿ®˜Êÿ­—Êÿ«–Êÿª•Êÿ©•Êÿ¦“Ëÿ£’Ëÿ¢�Ëÿ¡�Êÿ¢ŽÇÿ¤�Äÿ¦�¾ÿª�»ÿ®�¶ÿ°‘²ÿ´‘¯ÿ¶“¬ÿ¸”ªÿ¼–«ÿ½˜«ÿ¼˜«ÿ¾™«ÿ¿š¬ÿ¾›¬ÿ¼™¯ÿº˜³ÿ·–´ÿ°“·ÿ¬’»ÿ§�Âÿ¡�Éÿœ�Òÿ–�Øÿ‘‘ßÿ‹’åÿ†‘ëÿ€�îÿ}�ðÿzŽðÿxŒïÿvŠïÿuˆìÿt†ëÿs„èÿr�åÿq~áÿp|ÜÿpyØÿoxÕÿnvÔÿmuÓÿluÑÿlsÐÿlsÎÿmqÌÿlpËÿkqÊÿjqËÿkqÌÿjqÌÿkrÍÿkrÍÿkrÏÿisÑÿisÒÿirÑÿÁÑþÿÂÐþÿÃÐþÿÀÐþÿ¿Ðþÿ½ÏþÿºÏþÿ»Îþÿ½Ïþÿ¾ÎþÿÀÍýÿÃÌþÿÅÉüÿÈÇøÿÉÆøÿÈÇøÿÈÇøÿËÇöÿÎÆñÿÏÅíÿÑÄìÿÓÅêÿÔÄçÿÕÄåÿÔÃåÿÓÃåÿÓÃçÿÑÂèÿÏÃêÿÌÂìÿÌÁëÿÉÀíÿÅÀòÿ¿Âùÿ¹ÃýÿµÃýÿ²Ãýÿ²Âþÿ±Áþÿ®Àþÿ«¿þÿª¾þÿª¾ÿÿª¾þÿ¬¼þÿ­¼þÿ°¼ûÿ³¼úÿµ½ùÿ´¼øÿµ»÷ÿ·¹ôÿ»¹îÿÀ¹êÿŸäÿɸßÿ̹ÛÿθØÿиÕÿѹÍÿÓ¸ÈÿÔ¸ÆÿÓ¸ÅÿÔ¸ÈÿѶËÿ϶Ïÿ̶×ÿɶÛÿǵÜÿÆ´ÜÿŲÙÿıÖÿîÔÿÁ«Ñÿ¯ÓÿİØÿÁ¯ÛÿÀ¯ÝÿÁ±ÞÿñÞÿ±ÜÿñÜÿıÜÿ±ßÿIJÞÿƲÙÿƳÖÿȲÔÿȲÓÿƱÕÿİÙÿðÛÿÁ®ÙÿÀ¯Úÿ¾®ÝÿŽ}¢ÿ[JdÿweŠÿ9)7ÿ'#ÿ$ÿ?,9ÿOÿ’‡µÿrlšÿA6Nÿ'#ÿ5(8ÿ!ÿrg�ÿ|o—ÿ\Lgÿ–�Çÿ¡›Ûÿ¡™Õÿ¤™Ïÿ¥˜Ïÿ¤˜Ðÿ¤˜Ðÿ¥—Ïÿ§–Æÿ§”¿ÿ¨“¼ÿ©‘¸ÿ¨‘¶ÿ©‘´ÿª�°ÿª�­ÿ¬�«ÿ¬�©ÿ¬�§ÿ¬Ž¥ÿ¬Ž¤ÿ¬�¡ÿ¬� ÿ®Œ ÿ­Œ�ÿ®�œÿ°Ž�ÿ¯Žœÿ®Œšÿ°Œ›ÿ¯�™ÿ¯Œšÿ±Œšÿ°Žšÿ°Žšÿ³Ž›ÿ²Žšÿ²�™ÿ³�™ÿ³�šÿ³�›ÿ´�›ÿ³�›ÿ²�›ÿ²�šÿ°Œšÿ¯�šÿ°�œÿ²��ÿ±�žÿ±�Ÿÿ³‘¡ÿ²’¢ÿ²‘¤ÿ¯�ªÿ¦Ž²ÿ ‹´ÿ�‡µÿ—…´ÿ—ƒ³ÿ—ƒ±ÿ—‚¬ÿ—€ªÿ”|§ÿ‘y¤ÿŽw¡ÿŽvŸÿŽuœÿ�s™ÿŒr˜ÿ�t–ÿ�s•ÿ�r“ÿ�q’ÿ‹o�ÿ‹n�ÿŠo�ÿˆp—ÿ‰r ÿ‰t¦ÿŠw¨ÿ�x©ÿ’{¨ÿ•}¤ÿ˜~¡ÿ›~�ÿ™|™ÿ—y—ÿ—z—ÿ˜z™ÿ™z™ÿš|šÿ›|œÿš|›ÿ›|œÿ×ÉÜÿÙÊÙÿÛÊÖÿÜËÖÿÝËÕÿÞÌÕÿÞÌÔÿÞÌÕÿÛÊÓÿÚÉÔÿÛË×ÿÙÊÛÿØÊÜÿØÉÜÿ×ÈÛÿÖÈÛÿÖÆÚÿÖÈÚÿÖÈÛÿÖÈÚÿ×ÈÙÿÖÇÙÿÖÇÛÿÕÆÚÿÓÅÚÿÒÃÛÿÎÁÝÿÍ¿Ûÿ˼×ÿʺÕÿʺÓÿɹÓÿǸÔÿÅ·ÖÿµØÿ´Õÿ²ÒÿÁ²ÏÿÁ²ÑÿÁ²ÔÿÀ²Õÿ¾°Öÿ¾°Öÿ¿±×ÿÀ±ÖÿÀ±Öÿ¾²Úÿ½±Üÿ½±Úÿ»¯Ùÿ»¯Úÿ¹¯Þÿ¶¯ßÿ´­Þÿ³ªÚÿµ©Öÿµ¨Óÿµ¨Õÿ´¨Öÿ³¨Öÿ±§Õÿ±§Õÿ±¦Òÿ±¦Òÿ²¥Òÿ³¦Ïÿ³¥Ðÿ²¦Óÿ¯¥Õÿ°¦Øÿ®¤Öÿ¯¥×ÿ¯¥Ùÿ®¤×ÿ­£Ôÿ­£Öÿ¬£Öÿ«¤Üÿª¤Þÿ«¢Öÿ®žÌÿ±ŸÈÿ±¡Êÿ°ŸÉÿ¯žÆÿ¯žÆÿ±žÄÿ²žÃÿ³ŸÂÿ³žÁÿ´ž¿ÿ´Ÿ¾ÿ´ž¾ÿ³žÁÿ§“µÿ4#/ÿXIcÿA1Bÿ&%ÿ)$ÿ:,<ÿ ÿ/#0ÿPC`ÿ6'7ÿŠ�®ÿ¦›Öÿ¤›Öÿ¤›Ôÿ£šÒÿ£›Õÿ£š×ÿ£šÕÿ§—Êÿ©—Ãÿª”¼ÿª“¶ÿ«’±ÿ«’­ÿ¬�ªÿ¬Ž¨ÿ«�¦ÿ«Œ¤ÿ«Œ¢ÿ«Œ ÿ¬‹žÿ«Š�ÿ«Š›ÿ¬Š™ÿ«‰™ÿ­Ššÿ­Ššÿ®‹™ÿ®‹šÿ­‹šÿ­‹šÿ­‹šÿ®‹šÿ¯Œšÿ¯Œšÿ¯Œ›ÿ°�šÿ±�šÿ±Ž™ÿ±Žšÿ°�›ÿ±Žœÿ±Ž›ÿ±�›ÿ±�›ÿ±�šÿ¯Œšÿ®Œ™ÿ®‹™ÿ­‹—ÿ®‹šÿ¯�›ÿ±�žÿ²‘Ÿÿ³‘ ÿ³‘ ÿ±‘¢ÿ­�¥ÿ§Œ¨ÿ¢ˆ¬ÿž†¬ÿœ…«ÿœ„ªÿ™�§ÿ–}¥ÿ‘z¡ÿŽv�ÿ�tšÿŒs˜ÿ‹r•ÿŒr”ÿ�r“ÿ�q’ÿŽq‘ÿŽq‘ÿŽq�ÿ�qŽÿ’s�ÿ’t’ÿ�u•ÿ�u˜ÿ�v™ÿ”y›ÿ™|œÿ�›ÿ €™ÿ¡�–ÿ¤‚•ÿ£�”ÿ¢�”ÿ£€”ÿ£€•ÿ¢�–ÿ¡�˜ÿ¡�˜ÿØÉÚÿÖÆÚÿׯØÿØÈÖÿÙÈÕÿÙÉÓÿÛÊÔÿÛÊÒÿÛÊÓÿÛÊÔÿÛÊÕÿÙÊÙÿØÊÛÿ×ÉÝÿÖÉÝÿÕÈÞÿÔÈàÿÔÈáÿÔÉãÿÓÈãÿÔÇÝÿÔÆÜÿÔÅÚÿÔÄÚÿÔÄÙÿÓÄÚÿÓÄÚÿÓÃÚÿÒÃÙÿÎÀÙÿ̽ÙÿɺÙÿǺÛÿźÜÿŹÝÿĹÛÿÄ·Øÿµ×ÿÀ³×ÿ¾²Øÿ¿³Úÿ¾³Ûÿ½²Üÿ½³Ýÿ¼²Ûÿ¼±Üÿ¼³àÿ¼²ßÿ¼³àÿ»³áÿ¹²ãÿ·±áÿ¶°áÿµ°ãÿ±®âÿ±­äÿ±¬âÿ²«Þÿ´«Üÿ´ªÙÿ²©Ùÿ¯¨Üÿ­¨Þÿ­©ßÿ­¨ßÿ¯§Ùÿ­¦×ÿ­§Ûÿ«§Þÿª§áÿª§âÿª¦áÿ«§àÿª¦ßÿª¦àÿª§ãÿ¨ªæÿ©©åÿª¦ßÿ­£Öÿ­¡Óÿ®£Óÿ¯¤Õÿ¯¤Öÿ®£Öÿ« Ôÿ¬¡Óÿ­ŸÑÿ°¢Ïÿ±¢Ïÿ±¢Ïÿ±¡Ìÿ±¡Êÿ² Ìÿ™†­ÿ*$ÿA4@ÿ`Smÿ5*8ÿ(#ÿ+)ÿÿ'%ÿN?Wÿ;-=ÿ€sšÿ¨œÐÿ¦šÑÿ¥™Ïÿ¤™Íÿ£šÑÿ¢™Õÿ£šÒÿ§—Æÿª•¿ÿ«–¹ÿ¬”³ÿ®“¯ÿ­‘©ÿ­�§ÿ­�£ÿ¬Ž¡ÿ«� ÿªŒŸÿªŠ�ÿ©ˆšÿ¨‡˜ÿ©ˆ—ÿªˆ˜ÿ©ˆ—ÿ«ˆ˜ÿ¬‰˜ÿ¬‰™ÿ«Š˜ÿª‰˜ÿª‰˜ÿª‰™ÿªˆ˜ÿ«ˆ˜ÿ«ˆ˜ÿ¬Š˜ÿ­Š™ÿ®‹™ÿ­‹™ÿ®‹šÿ®‹šÿ®Œšÿ®Œ™ÿ®Œ˜ÿ¯Œ™ÿ®Œ˜ÿ®‹˜ÿ®Œ˜ÿ®Œ˜ÿ­‹—ÿ­Š˜ÿ­Š˜ÿ®Œ™ÿ¯�šÿ±Ž›ÿ²��ÿ³�Ÿÿ²‘Ÿÿ±‘ ÿ®�¡ÿ«�£ÿ¨Š¥ÿ¥ˆ¤ÿ¡†¥ÿŸƒ£ÿ›�¡ÿ–{žÿ‘v›ÿ�s˜ÿŠq–ÿŠq“ÿ‹q“ÿŒq‘ÿ�q‘ÿ�q‘ÿ’s’ÿ”v’ÿ–y’ÿ˜z”ÿš|•ÿ›}–ÿ™}—ÿ™}—ÿ�˜ÿŸ�™ÿ¡‚˜ÿ¤„˜ÿ¦…—ÿ§†–ÿ¨…–ÿ¨†—ÿ©†—ÿ§†˜ÿ¨†˜ÿ¨†™ÿÙÉÓÿÙÊÔÿÙÈÓÿ×ÇÕÿØÆÕÿׯÓÿÖÆÑÿׯÐÿÙÆÑÿׯÐÿØÇÑÿÙÇÔÿ×ÇÖÿÔÇÚÿÔÅÝÿÓÆàÿÓÇàÿÓÆÞÿÒÆÞÿÑÆßÿÓÆáÿÔÇßÿÓÆÝÿÓÅÜÿÓÄÛÿÑÃÚÿÑÃÛÿÐÂÚÿÍÀ×ÿÌ¿ÚÿɽÜÿɼÜÿȾßÿÅ»àÿúßÿùÞÿ¹ÞÿÁ¸ÝÿÁ·ÜÿÁ¶ÚÿÀ·Üÿ¿µßÿ½´ßÿ»µàÿº³Þÿ¹°Þÿ¹°Ýÿ¹±Þÿº±àÿ¹±àÿ·±áÿ¶±ãÿ¶²äÿ¶²æÿ¶²æÿ´³æÿ³³çÿ´±åÿµ°áÿ¶¯ßÿ·®Þÿ´­Þÿ²¬Þÿ°«áÿ®«âÿ­«àÿ­ªâÿ«¬æÿªªæÿ¨«çÿ§®ïÿ¥¬ðÿ¤ªéÿ¦«éÿ¦«éÿ©©äÿ«©äÿª¨ãÿ­¨àÿ®©áÿ«¨âÿª¨áÿ¨¦áÿ§¦àÿ¦£ßÿŸ�Ýÿ�™Öÿ¤œÖÿ©ŸÕÿ«ŸÕÿª¡Øÿ«¡Õÿª Ïÿ«ŸÍÿ‹y›ÿ*(ÿUF^ÿH9Nÿ, +ÿ'$ÿ$ ÿÿXÿ&"ÿC8MÿÿA5EÿŠ|¢ÿ…w™ÿbOdÿ �´ÿ­œ¿ÿ¬™»ÿ¬™ºÿ«˜¸ÿª–¶ÿ§“µÿ¨“µÿ§”µÿ§•µÿ¨’´ÿ§’³ÿ¥‘³ÿ¥�²ÿ£�±ÿ£�¯ÿ£Œ®ÿ£�®ÿ¢Œ­ÿ£‹¬ÿ¡Œ¬ÿ¢‹ªÿ¢‹ªÿ¡‹ªÿ¢‹©ÿ£‹©ÿ¤Œ¨ÿ§Ž¨ÿ©�§ÿ©�¨ÿ©�§ÿ¬‘§ÿ­’§ÿ¯“¦ÿ¯”§ÿ®“¥ÿ®“£ÿ°”¤ÿ²–¥ÿ²˜¥ÿµ™¦ÿµš¦ÿµš¦ÿµ™¦ÿµ™¦ÿµ™¥ÿ¶š§ÿµ™¦ÿµ™¥ÿµš¥ÿ¶™¥ÿµ™£ÿ·™¤ÿ¶˜¤ÿ¶™£ÿµ™£ÿ·™£ÿ¶™£ÿ·š£ÿ·š¤ÿ·™£ÿ¶™£ÿ¶™£ÿ´™£ÿ´—£ÿµ–¤ÿ´–¢ÿ³–¡ÿ²– ÿ³•¢ÿ®��ÿ­Ž›ÿ±“Ÿÿ´•¡ÿ²•¡ÿ³•¢ÿ³•¡ÿ³•¡ÿ³” ÿ³“¡ÿ³“ ÿ±“Ÿÿ°’Ÿÿ¯�žÿ­��ÿ­�œÿ®�œÿ®�œÿ­Žšÿ­Ž›ÿ­�›ÿ¬�šÿ«Œ›ÿ«Œšÿ©¥Õÿ«¦Õÿ­¥Óÿ¬¥Ñÿ¬£Îÿ­¤Ïÿ¬¤Ïÿª£Ïÿ«¤Ñÿª¦Øÿ¨¨ßÿ¨ªãÿ§ªàÿ¦¨ßÿ¦©àÿ¦©àÿ¥©âÿ£«çÿ¡­ëÿ¢«èÿ¢¬êÿ¢­ëÿ¢«êÿ¡ªéÿ£«éÿ¢©æÿ¢¨åÿ£¨ãÿ¥©ãÿ¦¬åÿ¦­çÿ¦¬çÿ©®çÿ©®çÿ©°èÿ«¯æÿ«¯æÿª°çÿ©¯èÿª°êÿ§°ëÿ§±ëÿ¨±îÿ§°íÿ¦°îÿ¦±ïÿ¥²ñÿ¥³óÿ¦´ôÿ¦´ôÿ¥´ôÿ¤³õÿ£´öÿ£´öÿ¢´÷ÿ¢µ÷ÿ¢³öÿ¢²öÿ£²õÿ£±ôÿ¢¯òÿ¢¯òÿ¡®ðÿ¢®ðÿ¢®ñÿ¢¯ñÿ¢®ðÿ£®ðÿ£®ïÿ¤¯ïÿ£¯ðÿ¡¯ñÿ ¯óÿ ¯ôÿž¯ôÿž­ôÿŸ­óÿž¬òÿœ¬òÿ�¬óÿœ¬ðÿœ«ðÿ›«òÿ™ªóÿ™«õÿ™«öÿ™ªòÿ™©ðÿš©ðÿ™ªðÿ™©ñÿš©ñÿ›ªðÿ�«óÿ++ÿux®ÿ‹“Ôÿsu«ÿ?4Hÿ'%ÿ* *ÿ ÿl`€ÿ•‰±ÿŽ�§ÿhWnÿŽ€¡ÿ«›Áÿ«š¿ÿ«š½ÿ¬š¼ÿ¬š»ÿ«™ºÿ©–¸ÿ¨•¶ÿ©–¶ÿ­˜¸ÿ¬˜µÿ¬—´ÿ¬–³ÿ¬–±ÿ«•±ÿª”¯ÿ©’®ÿ¨�®ÿ§�¬ÿ¥�¬ÿ¥Ž«ÿ¤�¬ÿ¤Œ«ÿ£�«ÿ£Œ«ÿ£‹©ÿ¥Œ©ÿ¦�ªÿ¦Žªÿ¦�¨ÿ¦Ž©ÿ§Ž©ÿ©Ž©ÿª�§ÿ¬‘§ÿ¬’¦ÿ®“¥ÿ¯•¥ÿ±–¦ÿ³™§ÿµš¨ÿµ›¨ÿµ›¨ÿµ™§ÿµš¨ÿµš§ÿµš¦ÿµš¦ÿµš¦ÿ¶›¦ÿµ™¥ÿ´˜¥ÿ³˜¤ÿ³™¤ÿ´™¥ÿµ™¥ÿµš¥ÿ¶›¦ÿ·œ¥ÿ¸�§ÿ¸�¦ÿ¹�¨ÿ¸œ§ÿ·œ¦ÿ¸œ§ÿ¸œ¥ÿ·›¤ÿ¶š¤ÿ¶˜¤ÿ°“Ÿÿ°’Ÿÿ²” ÿ¶™¤ÿµ™£ÿ¶™¤ÿ·š¤ÿ·™¤ÿ·™¤ÿ·š£ÿ·™£ÿµ—¢ÿ´• ÿ³• ÿ²”Ÿÿ´•¡ÿ³•¡ÿµ–¡ÿ³•¡ÿ´” ÿ´” ÿ²” ÿ²’ ÿ±‘Ÿÿ¥¦Üÿ¤¤Ýÿ¢¢Ûÿ¢£ßÿ£¥Þÿ¤¥Ýÿ¥§Ýÿ¦¥Øÿ¥£Ùÿ¢¤Üÿ¡¤ßÿ£¨ãÿ£¬çÿ£¬éÿ¡«êÿ¡«çÿ¡ªæÿ¢«æÿ¢ªæÿ¡ªèÿž«ìÿŸ¬ïÿž¬ïÿ ¬îÿ ¬íÿ ¬îÿŸªëÿž¨èÿ�§æÿ�¦åÿž¦æÿž§èÿ�§èÿž¨êÿŸªíÿŸ«îÿŸ«íÿŸªîÿŸ«îÿŸ«íÿ «íÿŸ«ìÿŸªëÿŸªìÿŸªìÿžªîÿ�ªðÿž«ðÿž«îÿŸ¬îÿž¬ðÿ�¬òÿ�¬ôÿš­öÿ™­÷ÿ›®÷ÿž®õÿž®ôÿŸ®óÿ ­òÿ ­ðÿ¡¬îÿ¡«êÿ¡ªéÿ¡«êÿ¢«êÿ¡­ëÿ¤­ëÿ¥®ìÿ¤®ìÿ£­ëÿ£­ìÿ£®îÿ¢¯ðÿ¡®òÿ ®òÿŸ«ñÿŸ«îÿž«ðÿ�¬ñÿ�¬óÿ›«óÿ™ªôÿ—«öÿ–ª÷ÿ—ª÷ÿ–©öÿ˜©ôÿ˜©ôÿ—©óÿ˜«ôÿ—ªôÿš«õÿ’žãÿ*+ÿ\^’ÿHCfÿ7-Bÿ. ,ÿ ÿ, )ÿ("ÿL?Uÿ>0@ÿPDYÿF8Mÿ‚s•ÿ­�ÉÿªšÄÿª™Âÿ«šÁÿ¬›Àÿ¬›¾ÿ¬›»ÿ¬™ºÿª—¸ÿ©”µÿ¬–´ÿ®˜´ÿ¯™³ÿ°™²ÿ®˜°ÿ®—°ÿ¯—®ÿ®–®ÿ®–­ÿ­•­ÿ­•¬ÿ«”¬ÿª’¬ÿª’«ÿ¨‘ªÿ§�ªÿ§�«ÿ¦�«ÿ§�«ÿ§�«ÿ§�«ÿ¦Žªÿ¦Žªÿ¥�ªÿ¤Œ¨ÿ£‹¦ÿ¥Œ¥ÿ¦Ž§ÿ¨Ž¦ÿ©Ž¦ÿ¬’§ÿ®”§ÿ¯•¥ÿ±”§ÿ±–¦ÿ²˜¦ÿ±–¥ÿ°•¤ÿ²–¥ÿ°–¦ÿ¬‘£ÿ¬�£ÿ§Œ ÿ¨Ž¢ÿ¬‘¤ÿ¯”¥ÿ±—¦ÿ²™§ÿµ™¨ÿ¶š¨ÿ·œªÿ¶œªÿ·�«ÿ·�ªÿ·�«ÿ¸žªÿ¹žªÿ¸ž©ÿ¸œ©ÿ³–£ÿ±•¢ÿ±“¡ÿ³—£ÿµ™¤ÿ¶š¥ÿ¶š¦ÿµ™¤ÿµ˜¤ÿ´˜¤ÿ´—£ÿ³”¢ÿ²“¢ÿ²•¢ÿ³•£ÿ´–¤ÿ´—¤ÿ³”£ÿ²’¡ÿ°’¡ÿ°‘ ÿ±’¡ÿ¯‘ ÿ¯� ÿ¡§ãÿŸ¨ãÿ §ãÿŸ¨ãÿž¨æÿœªìÿ—©îÿ™©îÿ�§èÿž§æÿš£áÿ›¤ãÿ˜¥çÿ˜¨íÿ™ªñÿ—ªôÿ–ªóÿ—©òÿ—¨íÿ—¨îÿ—¨îÿ˜©ðÿ—©îÿ—¨êÿ™§éÿ™¦èÿ™¦èÿ˜¨ìÿ—¨ìÿ˜¨îÿ—§îÿ–¦ìÿ—¦ìÿ—¥êÿ•¥ìÿ•§ðÿ•¦ïÿ–¦îÿ•¦îÿ•§ïÿ•¦îÿ—¦îÿ—¦ëÿ™¦êÿ™¦éÿ™¦éÿ™¦éÿ˜¥éÿš¦êÿ˜¥éÿ—¦ëÿ˜§îÿ˜§ïÿ˜©ðÿ˜©ñÿ˜©ðÿ˜¨ðÿš©ðÿš©ïÿ›©îÿœ¨ìÿžªêÿŸ¨èÿ ¨çÿ §ãÿ¡§äÿ£©åÿ£ªçÿ¡©æÿ ©çÿ¡©çÿ¡©æÿ¡ªèÿ¡ªéÿ ªéÿ «ëÿ ¬íÿŸ«íÿŸ«ìÿŸ«íÿœ«ðÿœ«òÿš«óÿ—ªóÿ–ªóÿ–¨òÿ•§òÿ•§ñÿ–§ñÿ–¨òÿ•¨óÿ—¨óÿ™«ôÿ„�Êÿ!ÿ>9WÿFEkÿEBcÿ* -ÿ#ÿMD_ÿ% ÿ$ ÿYOmÿB4Iÿ6+6ÿqd€ÿ®¡Ëÿ¬žÇÿ­�Æÿ¬œÂÿ«›¾ÿ­œ¼ÿ®œ»ÿ®œ¹ÿ¯›¶ÿ®™µÿ«–±ÿ«–°ÿ­˜±ÿ¯™°ÿ°š°ÿ²›°ÿ²›¯ÿ±š¯ÿ²š®ÿ°™­ÿ°™­ÿ±˜¬ÿ¯—«ÿ®–«ÿ®•ªÿ­•©ÿª”ªÿ©“«ÿ©‘ªÿ¨�ªÿ¨�©ÿ¦�©ÿ¦�©ÿ¤�©ÿ£Œ§ÿ¢Œ¦ÿ£Œ§ÿ¢‹¦ÿ£Š¦ÿ Š¥ÿŸˆ¤ÿž‡£ÿ�†£ÿ�‡£ÿžˆ£ÿ ˆ£ÿ�…¡ÿ›„¡ÿœ„¡ÿž…¢ÿž…¡ÿœ„ ÿœƒ¡ÿš„¡ÿ�…¢ÿž†¤ÿ ‰¤ÿ£Œ¥ÿ¦�©ÿ¨�©ÿ©�ªÿ¬”«ÿ®–«ÿ°—ªÿ°—©ÿ¯–¨ÿ¯•¨ÿ±–©ÿ°—¨ÿ¯”¦ÿ¬�¢ÿ¬‘¢ÿ¬‘¢ÿ¯“£ÿ²–¥ÿ²—¦ÿ³—§ÿ²—¦ÿ²–¤ÿ°”£ÿ°”£ÿ±•¤ÿ²–¥ÿ°•¥ÿ¯“£ÿ­‘¡ÿ­�¡ÿª�Ÿÿ¬� ÿ­� ÿªŽžÿ§‹œÿ¦Šœÿ–£çÿ˜£æÿ˜¢äÿ˜£âÿ˜¤ãÿš§èÿ™©íÿ™ªïÿš©îÿ˜§íÿ–¦ëÿ“¥íÿ‘¤ïÿ�¥ðÿ�¥òÿަôÿަóÿ�§õÿ‘§ôÿ�§ôÿ�§õÿŽ©öÿ�©÷ÿ�ªøÿ�ªùÿ�©÷ÿ‘©õÿ‘©õÿ’©õÿ’¨óÿ“¨óÿ’¨òÿ’¦òÿ�¦òÿ�¦ðÿ�¥ñÿ‘¥ñÿ�¤ñÿ�¤ðÿ�£ðÿ�£îÿ�¢ìÿ’ éÿ“ çÿ“Ÿæÿ”Ÿäÿ“Ÿãÿ”Ÿãÿ“Ÿåÿ’ æÿ’¡èÿ’ éÿ“¢ëÿ“£ëÿ”£êÿ”£êÿ•£êÿ•¤éÿ–¤éÿ—¤èÿ˜¤éÿš¤èÿš¤åÿ›¤äÿœ¢âÿœ¡àÿž¢áÿŸ¤áÿž¤âÿŸ¤âÿž£âÿž£áÿŸ¦ãÿ §äÿ¡§äÿ¡¨æÿ ªéÿ ªéÿ ªêÿ¡«ëÿ ªëÿž«ìÿœ«îÿ›«îÿšªðÿ™©ðÿ—¨ïÿ—§ïÿ—¨ðÿ—§ñÿ•¨òÿ–§ñÿ™©óÿx~¶ÿÿ=9XÿF?dÿFBcÿ))ÿÿÿÿ6-:ÿQD[ÿM@TÿOCTÿ^Qgÿ²£Èÿ­ŸÁÿ¯žÀÿ¯Ÿ½ÿ°žºÿ°œ·ÿ¯œµÿ°œ´ÿ±œ´ÿ±›³ÿ¯š±ÿ®™°ÿ­˜¯ÿ­—­ÿ®˜®ÿ±›®ÿ³œ¯ÿ³�®ÿ´œ®ÿ´œ®ÿ´œ®ÿ³›­ÿ³›¬ÿ³š«ÿ²š«ÿ±šªÿ²š«ÿ±›«ÿ±š«ÿ±˜«ÿ°˜ªÿ¯—ªÿ®—©ÿ®—©ÿ¬•©ÿ«“¨ÿ«“©ÿª’©ÿ©‘¨ÿ§�§ÿ¥Ž§ÿ¤�§ÿ£�¦ÿ¢Œ¥ÿ¡Š¤ÿ Š¥ÿ ˆ£ÿ�‡£ÿ�†¤ÿ›„¤ÿš„¤ÿ›„¥ÿ™…¥ÿ˜„¦ÿ˜…§ÿš…©ÿš†©ÿ›ˆªÿ�ˆªÿ�‰©ÿ Š©ÿ¡‹¨ÿ¢Œ§ÿ¤�§ÿ¥�§ÿ¦�¦ÿ¥Ž¦ÿ¦�¦ÿ¦Ž¥ÿ¥�¥ÿ¤‹£ÿ£Š¢ÿ¤Œ ÿ¦‹¡ÿ¨Ž¢ÿ©�¢ÿ©Ž¢ÿª�£ÿ«�¢ÿ¬‘¢ÿ¬‘¢ÿ¬‘¢ÿ«�¢ÿ©Ž¡ÿª� ÿ©� ÿ¨Œ ÿ¦‹Ÿÿ¦Š�ÿ¤‰œÿ£‡›ÿ¢†›ÿ¡†›ÿ�šâÿŽ›äÿ�›äÿŽ�æÿ�žåÿ� èÿ�¢ëÿ�¤îÿ‘¥ñÿ‘¦òÿ�§ôÿ�¨õÿ�§õÿ�¥óÿŒ¤ñÿ�£òÿŠ¡òÿˆ¡òÿˆ£õÿŠ£õÿ‹¤ôÿŠ¥õÿŒ¦öÿŒ¦÷ÿŒ§÷ÿ�¨÷ÿ�¦öÿަõÿާôÿ�¦ôÿ�¦óÿަôÿާõÿŒ¦õÿާ÷ÿŒ¦øÿ�¥÷ÿ�¤òÿ�¢íÿ‘¡êÿ‘ èÿ�Ÿçÿ‘�äÿ’œâÿ‘œâÿ‘œâÿ’�ãÿ‘�äÿ’Ÿçÿ‘Ÿèÿ‘žèÿ‘žèÿ‘ êÿ‘ éÿ‘ éÿ‘Ÿçÿ’žåÿ’�äÿ“�ãÿ”�âÿ”�âÿ”œáÿ•œßÿ”œÜÿ•›Ýÿ–›Üÿ—›Üÿ˜›Üÿ™›Üÿ™�ÝÿšžÝÿ›ŸÞÿœ ßÿ� ÞÿŸ¡ßÿŸ¢ßÿ ¤áÿ¡©åÿ¡©æÿŸ¨åÿ ¨æÿž§æÿž¨åÿŸ¨çÿ�§éÿœ§êÿ›§êÿš§êÿ™¥èÿ™¥éÿ™¥ëÿ˜¦ëÿ›ªòÿjkšÿ-#5ÿmr¦ÿmo¡ÿ�—Õÿ=3Hÿ'#ÿSKcÿÿpd‚ÿ…x•ÿ„v’ÿˆx‘ÿcScÿ²¢Âÿ±ž»ÿ±ž¹ÿ³Ÿ·ÿ´ ·ÿ³Ÿ¶ÿ³žµÿ²�³ÿ±�²ÿ²�³ÿ³�³ÿ³�²ÿ³�²ÿ°›±ÿ¯š®ÿ¯™¬ÿ°š­ÿ³œ®ÿµ�®ÿµ�°ÿµŸ®ÿµž®ÿ´�­ÿ´œ¬ÿ³œ¬ÿ´œ¬ÿ³›«ÿ³œ«ÿ²›«ÿ³šªÿ³šªÿ³›ªÿµœ¬ÿµ�¬ÿ¶�­ÿ¶ž®ÿµž­ÿ¶Ÿ®ÿ· ¯ÿ·Ÿ®ÿ¶ž®ÿ¶ ®ÿ¶Ÿ­ÿ¶Ÿ­ÿ·ž­ÿ·Ÿ¬ÿ·ž­ÿ¶ž­ÿ´œ«ÿ²š«ÿ±™«ÿ­—¬ÿ©“­ÿ¥�¯ÿŸŒ±ÿ�‹´ÿ›‰µÿ™‰µÿ–‡³ÿ•…²ÿ”„±ÿ•†¯ÿ˜‡­ÿ›‡¬ÿ›ˆ­ÿœˆ«ÿœ‡ªÿ�‡¬ÿœ‰ªÿž‰©ÿ�ˆ¨ÿ›†§ÿ›†§ÿŸˆ¥ÿ ‰¤ÿ¢Š¤ÿ¢‰£ÿ£‹£ÿ£Š£ÿ¥Š¢ÿ¥Š¡ÿ£ˆ ÿ¡‡ŸÿŸ‡žÿž„�ÿœ„œÿ›‚›ÿ™šÿ—˜ÿ–~˜ÿ–}˜ÿ–}™ÿ•}™ÿ‰–Þÿ‰•àÿ‰–âÿˆ˜âÿ‰šæÿ‰œèÿ‰›èÿˆœéÿŠœêÿŠŸíÿ‰¢ñÿŠ£óÿŠ£ñÿ‹¢ðÿŒ¢ñÿ‹£óÿŠ¥õÿŠ¥öÿˆ¤öÿ‡¡òÿ‰ ðÿˆ ïÿˆ îÿŠ îÿŠ¡íÿ‹ ìÿŒ ëÿŽ¡ëÿŽ èÿ�Ÿèÿ� èÿŽ éÿ�žéÿ�ŸéÿŒžèÿŒ�çÿ�œæÿŽœãÿ�›àÿ�šÞÿ�šÝÿ�™Þÿ‘šàÿ�šßÿ‘›àÿ�šàÿ�›áÿ‘œãÿ‘œäÿ‘œãÿ‘�âÿ‘œâÿ’œáÿ’�âÿ’�âÿ‘›àÿ’œÞÿ“›Þÿ”šÜÿ”šÛÿ”™Ùÿ•˜×ÿ•—Øÿ–—×ÿ–˜Öÿ–˜×ÿ–—×ÿ–—Öÿ——Õÿ˜˜×ÿ˜™Ùÿ˜šØÿ™›Øÿ™›Úÿš›Ûÿœ�Ûÿ›žÛÿ› Üÿ› Ýÿ› ßÿœ¡ßÿ�¡Þÿ�¢Þÿœ¡Þÿœ¢ßÿœ¢áÿ�£âÿœ£áÿœ£âÿœ£áÿœ£âÿœ£ãÿ ¨éÿ]Xzÿ<1Gÿ‡†¸ÿ•’ÅÿXMiÿ?3Fÿ/#-ÿ[Rlÿ3&1ÿM?QÿŠ{˜ÿ˜‡¤ÿ‰{’ÿiUeÿ°žºÿ±Ÿ¸ÿ²Ÿ·ÿ±ž¶ÿ²Ÿµÿ³Ÿ¶ÿ³ µÿ² µÿ³Ÿ´ÿ³ž²ÿ±ž²ÿ³Ÿ²ÿ´ ³ÿµ ²ÿ´Ÿ²ÿ²�°ÿ±›­ÿ±›­ÿ³œ¯ÿ´ž¯ÿ¶Ÿ°ÿ¶ ¯ÿ¶Ÿ®ÿ¶ ¯ÿ¶ °ÿ¶ ®ÿµŸ®ÿ¶ ¯ÿµŸ®ÿµž­ÿµž­ÿµŸ®ÿµŸ­ÿ¶ž®ÿ¶Ÿ­ÿ¶ ®ÿ¶ ®ÿ· ®ÿ·¡®ÿ¸¢°ÿ¹¢°ÿ¹£±ÿº£²ÿ¹¢±ÿ¹¢°ÿ¹¢°ÿ·¡°ÿ· ¯ÿ·¡°ÿ¸¢¯ÿ¸¢°ÿ¸¡°ÿ¸¡±ÿ·¡²ÿµ¡²ÿ³žµÿ°�µÿ®œ¸ÿ¯›¹ÿ®œ»ÿª›»ÿ¨™¼ÿ¤”»ÿ ’»ÿŸ�¼ÿ�޹ÿš�·ÿ›‹·ÿš‹¶ÿšŠ´ÿ™ˆ±ÿ–…¯ÿ”„¯ÿ•…¯ÿ”„­ÿ”„¬ÿ–‚ªÿ•‚©ÿ“�§ÿ”€¦ÿ”¤ÿ”¤ÿ“£ÿ“~£ÿ’}¡ÿ’} ÿ’|Ÿÿ’}Ÿÿ“~ ÿ”~ ÿ“~ ÿ”¢ÿ”~¢ÿ“åÿ�”åÿ‚•æÿ‚–æÿ‚–çÿƒ–åÿƒ•æÿƒ–åÿ„•æÿ…–äÿ…–ãÿˆ–ãÿˆ–áÿˆ–àÿŠ—âÿŠ™åÿ‰šçÿ‰œéÿˆœëÿˆžìÿˆžìÿ‰�êÿˆšèÿˆšèÿ‰šèÿ‰˜çÿ‰šçÿŠšæÿŒšäÿ�›âÿ�šáÿŒšàÿŒ˜ßÿŽ˜ÞÿŽ˜ÝÿŽ—ÜÿŽ–ÜÿŽ—Úÿ�—Úÿ�–Úÿ�•×ÿ�”Öÿ‘”Õÿ‘•Ôÿ�•Õÿ‘•×ÿ‘–Øÿ’˜Ûÿ”˜Úÿ’˜Øÿ”™Ùÿ”™Úÿ•™Ùÿ•™×ÿ—™Õÿ—˜Õÿ–˜Óÿ˜˜Ôÿ—˜Òÿ——Ñÿ™–Ðÿ˜•Ïÿ—•Îÿ™•Îÿ˜–Ïÿ—•Ïÿ™–Ïÿ˜•Îÿ˜•Îÿ™•Îÿ™•Ðÿ˜—Òÿ™—Ñÿ™—Òÿ™™Ðÿ›˜Òÿš™Òÿš™Ôÿ››ÕÿœšÖÿœœÖÿ›œ×ÿœœØÿž�Øÿž�ÙÿŸžÚÿž Úÿž¡ÜÿŸ¢ßÿ £àÿ ¤àÿ¡¤ßÿ§¨âÿSJcÿH>Pÿ„|žÿ^Rjÿk^zÿ5&3ÿ'#ÿ0$0ÿ.*ÿHÿ,'ÿ/ )ÿ,&ÿ*$ÿ,%ÿ*#ÿ2#.ÿ&ÿ!ÿ$ÿ+#ÿ^Qdÿ­¢Ãÿ°£Ãÿ°¤Âÿ±¤Áÿ²¤Àÿ±¥¿ÿ³¦¾ÿµ¨¿ÿµ¨Àÿ¶¨Áÿ¶¨Áÿ·ªÂÿ·ªÂÿ¸«Äÿ¸¬Äÿº®Ãÿ¼¯Ãÿ¾±Åÿ¾±Æÿ¾±Æÿ¾±Åÿ¾²Äÿ¿³ÅÿĶÈÿÄ·ÇÿÄ·ÆÿÅ·ÆÿöÄÿöÃÿ³ÁÿĵÂÿȺÇÿɹÇÿÉ»ÈÿÈ»ÈÿÉ»ÉÿÇ»ÉÿÇ»ÈÿƹÉÿǺÈÿÈ»ÉÿÉ»ÉÿÈ»ÈÿɼÈÿɼÈÿɼÇÿɼÈÿ˼ÈÿʽÉÿʼÇÿʼÇÿʼÈÿÉ»ÆÿÉ»ÇÿɺÆÿǸÄÿǸÅÿȸÄÿƸÃÿÆ·ÂÿǶÂÿƵÁÿŵÀÿij¿ÿó¾ÿ²½ÿÁ°¼ÿ¿¯»ÿ¾­ºÿ½¬¹ÿ½«¸ÿ¼«·ÿ»ª¸ÿº§¶ÿ¸¦µÿ·¥µÿ·¥µÿ¸¦µÿ·¦¶ÿ·¥¶ÿµ¤¶ÿ´£µÿ³¡µÿ²¡µÿ³ µÿ²Ÿ³ÿ°ž³ÿ®›±ÿª—­ÿ¥’«ÿ¤�ªÿ¢Ž¨ÿŒ|£ÿŒ{£ÿ‹{£ÿŒ{£ÿŒ{¢ÿ‹{¢ÿ‹{¢ÿŠ{¢ÿ‰{£ÿ‰{¤ÿ‰|¤ÿ‰{¤ÿ‹|¥ÿŒ}¥ÿ‹}¦ÿŒ}¥ÿŒ~¦ÿŒ©ÿŒªÿ�ªÿŒ¬ÿŒ€¬ÿ�€­ÿ�€«ÿ�€¬ÿŒ€­ÿŒ�®ÿŒ‚¯ÿŒƒ°ÿŒƒ²ÿ�„´ÿ�ƒ´ÿ�„´ÿŒ…¶ÿކºÿŒˆ¿ÿ‰‰ÄÿŠŒÈÿ‰�Ëÿ‰ŒÍÿˆŒÌÿˆ�Îÿ‡ŽÎÿ‡ŽÐÿ†�Ñÿ†�Òÿ†�Òÿ‡ŽÏÿ‰�ÎÿŠ�ÎÿŠŽÎÿ‹�ÎÿŠ�Ðÿ‹�ÑÿŠ�Ðÿ‹�ËÿŠ‹ÉÿŒŒÊÿ�ŽÍÿ�‘ÑÿŽ”ÔÿŽ–ØÿŽ–ÚÿŽ—Ýÿ�™àÿ‹˜âÿ‹˜áÿŠ˜áÿ‹šäÿŠœéÿŠŸíÿ‹¡îÿŒ ìÿ‹Ÿêÿ� ëÿ�¢ìÿ�¤ïÿ‘¤îÿ�£ìÿ�£ìÿ‘¤îÿ“¤ìÿ“¢éÿ•¤èÿ–¥éÿ˜¦èÿ˜¤çÿ™¥çÿ™¦çÿ›¦åÿœ¦âÿ�¤Þÿfa„ÿ,'ÿ&"ÿ%$ÿ- &ÿ7)2ÿ. +ÿ1!+ÿ5$/ÿ.'ÿ5%1ÿ$ÿ"ÿ$ÿ&ÿJ=Jÿ¯¢¼ÿ±¤¾ÿ³¤¾ÿ³¥¾ÿµ§¾ÿµ¨¿ÿ¶©¿ÿ·ªÁÿ¸¬Áÿº®Ãÿ»¯Âÿ½°Ãÿ½±Äÿ¾±Ãÿ¾°Âÿ¾²Äÿ¿²Äÿ¿³ÄÿÁ´ÅÿµÅÿÁ´ÆÿµÆÿÁ´ÅÿöÆÿÄ·ÇÿƹÈÿÇ»ÉÿɼÊÿȼÊÿǺÈÿŸÆÿÄ·ÅÿʽÊÿʾËÿÊ¿ÍÿÊ¿ÍÿÊ¿ÏÿÊ¿ÐÿÊÀÏÿÉ¿ÏÿʽËÿɾÌÿÊ¿ÌÿʾËÿË¿ÊÿʽÉÿʽÉÿʽÉÿʽÈÿʽÈÿ˽Éÿ˽ÈÿʾÉÿ˽Êÿ˽ÉÿʼÈÿʼÇÿɼÇÿɼÇÿÈ»ÆÿǹÄÿÇ·ÃÿƶÂÿƶÁÿŵÁÿóÀÿó¿ÿ²¾ÿÀ±½ÿ¾¯¼ÿ¿®»ÿ¿®»ÿ¾­ºÿ»ª¹ÿº©·ÿº©¸ÿ¸§¶ÿ¹¨·ÿ¹¨¸ÿ¸¦·ÿ·¦¶ÿ·¦¶ÿ·¥¶ÿ·¦¶ÿ·¥µÿ¸¥µÿ·¥³ÿ¶¤³ÿ¶£±ÿ¶£±ÿ¶£±ÿ·¤²ÿ‹{¡ÿ‹{¡ÿ‹{¡ÿ�{¡ÿŒ{¡ÿŒ|¡ÿŒ}¡ÿŒ}¡ÿ�|¢ÿ�}£ÿŒ}¢ÿŒ}¢ÿŒ}¢ÿ�~¢ÿ�~£ÿ�~¤ÿŽ£ÿ�¤ÿ�¤ÿ�€¤ÿ�€¤ÿ�€¥ÿ��¦ÿ��¦ÿ��¦ÿ�€¥ÿ��¥ÿŽ�¥ÿŽ€¥ÿŽ€¦ÿŽ�¦ÿ�€§ÿŽ€¨ÿŽ�ªÿ�ƒ«ÿ�ƒ­ÿ�ƒ°ÿŒ„±ÿ‹„´ÿŠ„·ÿ‹…¸ÿŠ„¹ÿŒ…»ÿŒ†½ÿ‹†¿ÿЇÀÿ‰ˆÂÿˆ‡ÂÿЇÄÿŠˆÅÿŒŒÈÿŒŒÉÿŒŽÉÿ‹ŽÊÿ‹�ÍÿŠ�Îÿ‹�ÎÿŠŽÎÿŠ�ÏÿŠ‘ÒÿŠ’Õÿ‹•ÚÿŠ–ßÿˆ–áÿˆ˜åÿˆ™æÿ‰šæÿ‹™åÿŠ›çÿŠ�ëÿ‡¡òÿ†¡òÿ‡¡ôÿ‰¡ñÿŠŸìÿ‹žëÿŽ ëÿ�ŸêÿŽ èÿ�¡éÿ� èÿ‘¡çÿ“¢æÿ“¡åÿ•¢åÿ—¢äÿ˜¡àÿ™ Ûÿš£áÿ›¥áÿ�¦âÿ ¦àÿXQlÿ/!'ÿ%ÿ$ÿÿ- (ÿ ÿÿ$ÿ ÿ,%ÿÿ"ÿ*"ÿ!ÿ;-7ÿ²¤¼ÿ¶ªÀÿ·«Àÿ¸«¿ÿ¸¬Àÿº­Áÿº¯Ãÿ¼±Ãÿ¿²Ãÿ¿²ÂÿÀ³ÄÿÁ´Äÿ¶ÆÿöÆÿÄ·ÆÿÅ·ÆÿŸÅÿŸÇÿŹÈÿǺÈÿÇ»ÈÿÇ»ÊÿÅ»ÊÿźÉÿÄ·Çÿ÷ÆÿźÈÿɽËÿɽÊÿȼÉÿȼÊÿƹÈÿÄ·ÇÿǼËÿÉ¿ÍÿÊ¿ÎÿÊÁÎÿËÁÎÿÊÀÎÿÊÀÌÿÊ¿ËÿʾËÿÊ¿ËÿÊÁÍÿÍÂÍÿÌÁÌÿÌÀËÿÌÀÌÿÌÀÌÿËÁËÿÌÀËÿËÀËÿÊ¿ÊÿʾÊÿʾÉÿʽÈÿɽÈÿʼÈÿɽÇÿȽÇÿÈ»ÆÿǺÅÿƹÄÿƸÄÿöÂÿôÁÿ´Àÿ³¿ÿÀ²¿ÿ¿±½ÿ¾¯¼ÿ½®»ÿ½®»ÿ¼­ºÿ¼¬ºÿºª¹ÿ·¦¶ÿ¸§¶ÿ¹¨·ÿ¸¨·ÿ¹©·ÿ¹©·ÿ¹¨¶ÿ¹©¶ÿ¹¨¶ÿ¹¨µÿ¸§´ÿ·¥²ÿ·¥²ÿ·¥²ÿ·¥²ÿ·¦³ÿ‹{¡ÿ‹{¡ÿŒ|¢ÿ‹|¡ÿŒ}¢ÿŽ}¢ÿŽ£ÿ�¤ÿ‘€¥ÿ�€¤ÿ�¤ÿ��¥ÿ�€¤ÿ��¤ÿ��¥ÿ�€¥ÿ�€¥ÿ��¦ÿ��¥ÿ��¤ÿ‘‚¦ÿ‘‚¦ÿ‘‚¦ÿ’�¥ÿ��¥ÿ�€£ÿ�¤ÿŽ£ÿ�~£ÿ�~£ÿŽ~£ÿ�~£ÿŽ£ÿŽ£ÿŽ£ÿޤÿ�€¤ÿ��¥ÿ�‚§ÿ�‚¨ÿ�‚¨ÿ�‚©ÿ�‚ªÿ�‚¬ÿ�ƒ­ÿ�ƒ¯ÿŽƒ±ÿ�„¶ÿ�…·ÿ‹ƒ¶ÿŠ…·ÿ�‡¼ÿŒ‡½ÿ‹‡Àÿ‹‡ÂÿЇÃÿˆˆÆÿ‡ˆÈÿ†‰Êÿ„‰Êÿ†‹Ìÿ†ŒÎÿ‡�ÔÿŠ“Úÿ‰–àÿˆ—âÿ‰˜äÿ‰˜äÿˆ™äÿŠ™åÿˆšçÿ‡›éÿ‡œìÿˆžïÿˆ ïÿ‹¢ðÿŒ¡îÿ�¡íÿޤðÿ�£ìÿ‘Ÿãÿ“ ãÿ”¡äÿ• âÿ– áÿ˜ŸÞÿš�Ôÿœ›ÏÿŸ�Ðÿ¡ ÎÿŸšÈÿ|r‘ÿE8Gÿ-%ÿ*#ÿ'%ÿ ÿ*$ÿ ÿ$ÿÿ"ÿ&ÿ!ÿ'%ÿ&ÿ%ÿ+"ÿteqÿ®¢³ÿ¹¬½ÿ»°Áÿ¾³Ãÿ¿´ÄÿÁ¶Åÿ·ÆÿøÈÿŸÆÿĹÇÿĹÇÿĺÇÿźÈÿǼÉÿǼÉÿǾÊÿȽËÿȽÉÿȽÊÿȼÊÿƼÉÿǽÊÿȽËÿÇ»ÉÿÆ»ÉÿÆ»ÉÿǽÊÿÈ¿ÌÿÊÀÌÿÉ¿ÍÿȾÌÿǼÊÿ·ÆÿøÅÿʾËÿÊ¿ÌÿÊÀÌÿÌÀÌÿɾÊÿȾÊÿȽÉÿȽÉÿȽÉÿȾÉÿɾÉÿǽÈÿȼÈÿȼÉÿǼÈÿȾÊÿÊ¿ÊÿÉ¿ËÿɾËÿʾÊÿɽÊÿȽÉÿȼÊÿǽÉÿȽÈÿȼÈÿÇ»ÇÿƺÇÿŹÆÿĸÅÿöÃÿöÄÿÁ´Âÿ¿³Áÿ¿²Àÿ¾±¿ÿ¾±¿ÿ¾°¾ÿ½¯¾ÿ¼¯½ÿ¼®½ÿ¸ª¸ÿ¶¥´ÿ»¬ºÿ¼­ºÿ¼­¹ÿ¼­¹ÿ¼¬¹ÿ»¬¸ÿº«¸ÿº©¶ÿ¹ªµÿº¨µÿº©µÿº©¶ÿº©¶ÿ¹ª¶ÿŒ{¢ÿ�|¢ÿŒ|¢ÿŒ}¡ÿ�£ÿ�£ÿ�¤ÿ�¤ÿ�€¤ÿ�€¥ÿ��¦ÿ�€¦ÿ��¦ÿ��§ÿ��¦ÿ�€§ÿ��¦ÿ��¦ÿ��§ÿ��§ÿ��¦ÿ�‚§ÿ��§ÿ�‚§ÿ��¥ÿ�€¥ÿŽ€¤ÿޤÿ�¤ÿ�~¤ÿŽ~£ÿ�~£ÿ�~£ÿ�£ÿŽ€¤ÿ�€¤ÿ��¥ÿ�‚¦ÿ�‚¦ÿ‘ƒ¦ÿ�ƒ§ÿ�‚§ÿ‘‚§ÿ’‚¨ÿ‘ƒ©ÿ�‚ªÿ‘ƒ©ÿ��ªÿ��ªÿ�«ÿ‹¬ÿ‹�¬ÿ‹�­ÿ‹�¯ÿ‹‚°ÿ‹�±ÿ‹‚²ÿŠ‚³ÿ‰…¸ÿЇ½ÿЇÀÿЇÀÿŠˆÃÿ‰‹Æÿ‰ŒÊÿŠ�ÏÿŠ‘Ñÿ‰“×ÿ‰•Üÿ‰—àÿ‰—àÿŠ™ãÿ‰›çÿ‰›èÿŒœæÿ��æÿŽ¡ëÿ�¤ïÿ�¥íÿ“¤éÿ•¥çÿ•£äÿ•£äÿ–£åÿ˜£ãÿš Üÿ�žÒÿŸŸÑÿ ŸÏÿ–�¸ÿ†{™ÿNCRÿ&ÿ)#ÿ#ÿ(&ÿ)$.ÿ&$ÿ'$ÿ;8Kÿÿ;.9ÿ=-8ÿG8DÿJ28ÿ:.4ÿ- (ÿ%ÿ"ÿ&ÿ."&ÿ,&ÿ‚|Žÿ°­Åÿ±­Äÿ±®Ãÿ°®Äÿ±¬Äÿ±«Âÿ±«Âÿ°¬Âÿ®¨Àÿ¬¦¾ÿ«¤½ÿ«£½ÿ«£¼ÿª¢»ÿ©¡ºÿ©¡ºÿª¡¹ÿ«¢ºÿ¬£»ÿ«¤¼ÿ®¤»ÿ®¥¼ÿ¯¦½ÿ®¦½ÿ¬¤ºÿ«¢¹ÿ© ¹ÿ© ·ÿª ¸ÿ«¡¹ÿ¬£ºÿ«£¹ÿ¬¤ºÿ²©¾ÿ´¬Àÿ´­Âÿ¸±ÆÿºµÈÿº¶Èÿ½¸Éÿ¾ºÊÿ¿»Ìÿ¾ºÌÿ½¹Ëÿ¾¸Êÿº¶Çÿ¼¸Êÿ½¹Êÿ½¹Êÿ½ºËÿ¿ºËÿÀºËÿ¿»Ëÿ¿»Ëÿ¿»ËÿÀ½ÍÿÀ½ÍÿÀ½ÍÿÀ¾Îÿ¿¿ÍÿÀ¿ÏÿÁÀÏÿÁ¿ÑÿÀ¿Ñÿ¾¼Ñÿ»¹Îÿº¹Îÿº·Îÿ¸µÎÿ³±Éÿ²°Éÿµ³Éÿµ´Êÿ¶µÌÿ¶´Ìÿ´²Ëÿ´²Ëÿ¶³Íÿ¸¶Îÿ¹·Ïÿµ°Éÿ¯«Âÿ³­Äÿ±«Âÿ¯¨Àÿ²¬Âÿ¸´Éÿ¼¹Ìÿ¾ºÍÿ„„½ÿ…ƒ¼ÿ…ƒ»ÿ†‚¹ÿ†‚¶ÿ…�µÿ†�´ÿ†�´ÿ†€²ÿ†�²ÿ‡�±ÿ‡€±ÿ‡€¯ÿˆ€®ÿˆ€¯ÿˆ€®ÿ‡€®ÿˆ€­ÿˆ­ÿˆ€­ÿ‡­ÿ‰€­ÿ‰€­ÿ‰€®ÿŠ€®ÿ‰€®ÿŠ�®ÿŠ�¯ÿ‰�®ÿ‰�®ÿ‰‚®ÿ‹�¯ÿ‹‚®ÿ‹ƒ®ÿ‹ƒ¯ÿ‹ƒ¯ÿŒ„°ÿ�…¯ÿކ°ÿކ°ÿ�‡±ÿ�‡±ÿ�‡²ÿ�ˆ²ÿ�‰³ÿ‘Š´ÿ“Œµÿ”�¶ÿ–�·ÿ˜“¸ÿ™”¹ÿš–»ÿ›—»ÿœ˜¼ÿ�˜¼ÿ�™¼ÿ�š½ÿž›½ÿ œ½ÿ �¿ÿ žÀÿ¢ž¿ÿ¤ Âÿ¦¤Ãÿ§¥Äÿ¨§Åÿ©§Åÿª§Åÿª§Åÿª¨Åÿª¨Æÿ«©Æÿ­«Èÿ­«Èÿ¬«Çÿ¬ªÇÿ­ªÇÿ¬ªÇÿ­©Æÿ«¨Äÿ«¦Äÿª¦Ãÿ©¥Ãÿª¦Ãÿ«¦Äÿ«§Äÿ¬¨Äÿ¬©Åÿ¬ªÅÿ‰„™ÿ4'/ÿ' ÿ/"(ÿ&ÿ"ÿ)"ÿÿA6<ÿKAGÿK@EÿI?EÿJ?DÿI>CÿC8?ÿ- &ÿÿ$ÿ0$)ÿ*#ÿ( ÿbZgÿ´²Ëÿ³±Éÿ´±Èÿ³±Èÿ³¯Çÿ³¯Çÿ´±Èÿ´±Èÿ´°Çÿ´±Æÿ²®Äÿ±­Äÿ±¬Ãÿ°ªÁÿ­§¿ÿ¬¦¾ÿ«¤¾ÿ©¢¼ÿ© »ÿ¨ ºÿ§Ÿ¹ÿ§ž¹ÿ¦�¸ÿ¦�¸ÿ§ž¸ÿ¦œ¶ÿ¤™¶ÿ£™µÿ¢˜´ÿ£—´ÿ¤™´ÿ¢˜²ÿ¡—±ÿ¥œ´ÿ¥›µÿ¥šµÿ¤š³ÿ¦�¶ÿ¨Ÿ·ÿ«£ºÿ¬¥»ÿ®§¾ÿ°¨¾ÿ°©¾ÿ±©¾ÿ±ªÀÿ²«Àÿ±«Àÿ°©¾ÿ°ª¿ÿ²¬Àÿ³­Áÿ³¬¿ÿ³­Àÿ³­Àÿ±¬¿ÿ±¬Àÿ³¯Ãÿ¶²Åÿ¶²Åÿ¶²Æÿ´²Çÿ´²Éÿ´²Êÿ´²Ëÿ³°Ëÿ³¯Éÿ³°Éÿ²®Çÿ®¨Áÿª¥¾ÿ­¨Àÿ²®Åÿ·´Éÿ¸¶Éÿ¸¶Êÿ¹µÉÿ·µÉÿ¶´Èÿ´°Æÿ¯©Àÿ¥ž·ÿ —±ÿ •°ÿ£š³ÿ«¤»ÿ´¯Âÿ·´Æÿ¹¶Èÿ€�¾ÿ�‚½ÿ‚‚½ÿ‚‚¼ÿ‚‚»ÿƒ‚¼ÿ‚‚ºÿ„�ºÿ„�¹ÿ„�¶ÿ„�µÿ…€´ÿ„€³ÿ„€²ÿ…€²ÿ…€±ÿ†€±ÿ†±ÿ‡€°ÿ†€±ÿ‡€±ÿ†€°ÿ‡�¯ÿ‡€°ÿ‡€°ÿ‡�±ÿ‡�±ÿ‰�°ÿˆ‚°ÿ‰‚±ÿŠƒ±ÿŠƒ°ÿ‹ƒ±ÿ‹ƒ°ÿ‹„±ÿ‹„±ÿŒ…±ÿŒ…±ÿ�†²ÿ�‡²ÿ�ˆ³ÿއ²ÿ�‡´ÿ�ˆ²ÿ�‰³ÿ�‰´ÿ‘гÿ’Œµÿ“�µÿ”�¶ÿ•‘¸ÿ—’¸ÿ–’¸ÿ–”ºÿš•»ÿ™•ºÿ›˜»ÿœ˜»ÿ�™»ÿ�™¼ÿ�›½ÿŸ›¾ÿ �½ÿ£žÀÿ£ Àÿ¤¢Âÿ¤¢Áÿ¥¢Áÿ¤¢Àÿ¥¢Âÿ¥¡Âÿ¥¢Áÿ¤¢Áÿ¥¢Áÿ¤¢Àÿ¦¤Ãÿ¥¥Ãÿ¥¤Ãÿ¦¤Äÿ§¤Ãÿ¦¤Ãÿ§¤Ãÿ§¤Äÿ¦¥Ãÿ¦¤Âÿ¨¤Ãÿ¦¤Ãÿ¦¤Âÿ¨¥Äÿi`sÿPESÿ!ÿ4(0ÿ"ÿ+!%ÿ+&ÿ!ÿZQ]ÿ[Saÿ\Sdÿ]TiÿYRiÿ[Uhÿ`ViÿC6Cÿ!ÿ!ÿ8*3ÿ0%+ÿ5(-ÿ>2:ÿ«¨Ãÿ«¨Âÿ¬©Ãÿ«¨Áÿ­ªÃÿ®ªÄÿ®«Ãÿ®«Äÿ¯«Äÿ­ªÄÿ«¦Àÿ¨£¼ÿ¥Ÿ»ÿ¤Ÿºÿ£ž¹ÿ¤�¹ÿ¦žºÿ¦Ÿ¹ÿ¦Ÿºÿ¦Ÿºÿ¦Ÿ»ÿ¥Ÿºÿ¥ž¸ÿ£™¶ÿž“±ÿž’°ÿ�’°ÿ�“±ÿ�“°ÿž“²ÿŸ“±ÿšŽ«ÿ™�«ÿŸ”²ÿœ”°ÿ™�¬ÿ–‰©ÿ“†¨ÿ•‡¨ÿ™Œ«ÿšŽ¬ÿ�“°ÿž•²ÿ�•°ÿŸ—±ÿ£›µÿ¦�·ÿ¤›µÿ¤›µÿ¤œµÿ¤›´ÿ¤œµÿ¥œ´ÿ¦�¶ÿ©¡ºÿ¨ »ÿ«¤½ÿ¬§¾ÿ­¨Àÿ®ªÁÿ¯©Áÿ®¨Âÿ®ªÃÿ¯«Äÿ¯«Äÿ¯ªÃÿ«¤½ÿ¥ž¹ÿ¢™²ÿ¡•±ÿ�’­ÿœ�«ÿœŽªÿœ�¨ÿ£š°ÿ®¦ºÿ°ª¾ÿ²­Àÿ±¬Àÿ¯¬¾ÿ¯ª½ÿ¯©¼ÿ®¨¼ÿ®§½ÿ¬¥ºÿª¢·ÿ¬¥¹ÿ­§»ÿ®¨»ÿ�€ºÿ€€ºÿ��ºÿ‚�¼ÿ‚�¼ÿ��¼ÿ‚�¼ÿ‚�¼ÿƒ�¼ÿ„�ºÿ„�¸ÿ„�·ÿ…�¶ÿ…€µÿ„€´ÿ…€´ÿ…€´ÿ…�´ÿ…�´ÿ…�³ÿ…€³ÿ†€´ÿ…€´ÿ…�´ÿ…€´ÿ…�µÿ…�µÿ…�´ÿ‡‚´ÿ†‚³ÿ†�³ÿ‡‚³ÿ‰ƒ²ÿ‰ƒ³ÿŠƒ³ÿŠ„³ÿŠ…³ÿŠ„³ÿ‹„³ÿŒ†³ÿŒ†´ÿއ´ÿ�‡µÿއµÿ�ˆµÿމ´ÿ�‰µÿ�еÿ’‹¶ÿ’Œ·ÿ“Ž·ÿ”�¸ÿ•�¸ÿ–‘¸ÿ•’¹ÿ˜”¹ÿš•¹ÿš–»ÿ›˜¼ÿœ™¼ÿ�™¼ÿžš½ÿŸš¾ÿŸ›½ÿ ›½ÿŸ›½ÿžš½ÿŸ›½ÿŸ›¼ÿŸœ¾ÿ œ¾ÿŸœÁÿŸœÃÿžžÆÿžžÆÿžžÈÿŸŸÉÿŸ Éÿ¡¡Çÿ¢¡Çÿ¢ Çÿ¡¡Æÿ£¡Æÿ£¢Æÿ¥¤Æÿ¦£Åÿ¦£Æÿ¥¤Åÿ¥¥ÆÿVHZÿA5@ÿMBPÿ8,9ÿ=1=ÿ>2=ÿ.!*ÿ4%-ÿ®®Óÿ©¨Ëÿ§¥Ìÿ£¥Ñÿž£ÖÿœŸÔÿ�¡ÒÿcYrÿ%ÿ%ÿ/#+ÿ@6@ÿ:.7ÿ4%0ÿ–‘«ÿ§¢¿ÿ¦¡¾ÿ§¢¾ÿ§¢¾ÿ§¢¾ÿ§¢¾ÿ§£¾ÿ¨¢½ÿ¦¡¾ÿ¥ž»ÿ¤œºÿ¥ž¼ÿ§¡¾ÿ£ž»ÿœ”³ÿ˜‹­ÿ”†©ÿ–‰¬ÿž•´ÿ¢˜¶ÿ¡—¶ÿ¢š·ÿ¦Ÿºÿ¥ž¹ÿ£š·ÿž“²ÿœ‘°ÿœ�¯ÿ—‰ªÿޤÿ‹y ÿŒ{ ÿ�‚¦ÿ•ˆ«ÿ—‰«ÿ—‹¬ÿ•ˆ«ÿ‘ƒ§ÿ“„¨ÿ—Œ­ÿ�“²ÿ¡˜¶ÿ£›·ÿ¤›·ÿ£š¶ÿž“³ÿœ‘°ÿœ’°ÿ�’±ÿš�­ÿ™�­ÿ—Œ¬ÿ™�®ÿš�°ÿœ’°ÿ�“²ÿš’±ÿš�®ÿš�®ÿ›�®ÿ�“¯ÿŸ•°ÿŸ•°ÿŸ•°ÿ¡•°ÿ –°ÿ –°ÿ¢—°ÿ¢—°ÿ¢—°ÿ¡—°ÿ¢—±ÿ¢—±ÿŸ“¬ÿ�’«ÿ�’«ÿŸ”«ÿ¢˜¯ÿ¤›²ÿ¤›±ÿ¤›±ÿ£š±ÿ¤›²ÿ¤œ³ÿ¥œ³ÿ£š±ÿ¢—®ÿ¢™®ÿ�¸ÿ�€¸ÿ‚€·ÿ‚€¶ÿ‚€¶ÿ‚€µÿ�¶ÿ‚¶ÿƒµÿ„¶ÿ„µÿ„´ÿ„€´ÿ„³ÿ…€µÿ…€µÿ…€µÿ„€µÿ…�µÿƒ�µÿ„�µÿ„€·ÿ„‚¶ÿ…�¸ÿ„‚¸ÿ„‚¹ÿ„‚¹ÿ…‚¹ÿƒƒ»ÿƒƒ»ÿ„‚ºÿ„ƒºÿ…‚¹ÿ…‚¸ÿ†‚·ÿ†ƒ·ÿ‡„¶ÿˆ…·ÿˆ…¸ÿ‰†¸ÿІ·ÿ‹†·ÿ‹†·ÿ‹‡·ÿŒ†¶ÿŒ‡¶ÿŒˆ·ÿ�ˆ·ÿ�Š·ÿ�Š·ÿ�‹·ÿ‘�¸ÿ‘ޏÿ’�·ÿ’�¸ÿ•�¹ÿ•�¸ÿ•‘¹ÿ—’¹ÿ—“¹ÿ—”¹ÿ™•ºÿ™•»ÿš–»ÿš—»ÿš—»ÿ›˜¼ÿš˜¼ÿ›˜½ÿ›˜¼ÿœ˜»ÿœ™¾ÿ›™Àÿ›šÁÿ›šÃÿ›šÇÿ™›Êÿ˜šÊÿ››Èÿ››Äÿ››Åÿ›šÅÿ›œÇÿœœÇÿ��ÈÿšžÍÿ•�Ôÿ•œÑÿ‘•Åÿ?3Bÿ4&1ÿaYoÿ=3@ÿ.#*ÿ3(/ÿ2$0ÿE;Hÿ ¢Êÿ��ÄÿžœÃÿ�œÃÿ�›Ãÿœ›Ãÿ�œÆÿme�ÿ4&0ÿ(ÿ)ÿ3'-ÿ=1<ÿ0",ÿrh~ÿ§£Âÿ¤Ÿ¾ÿ¦¡¾ÿ§£¿ÿ§¢¿ÿ¦£¿ÿ¥¡¾ÿ¦¢¿ÿ¥ ½ÿ š¸ÿ™‘±ÿ™‘²ÿœ•µÿ£ž»ÿ¦¢¾ÿ¨¢¿ÿž—¶ÿš‘²ÿ‘…©ÿŽ€¦ÿ�}¦ÿ�~¦ÿ•ˆ¬ÿ™Ž®ÿšŽ®ÿ—‹¬ÿ–‹¬ÿ•ˆ«ÿ‘ƒ§ÿ�}¤ÿŒz¢ÿ‹z¢ÿ�|¤ÿŽ}£ÿ�|¤ÿ�~¤ÿ�€¥ÿ��¦ÿŽ�¥ÿ�~¤ÿ�€¥ÿ‘‚¦ÿ’„§ÿ‘„§ÿ“†¨ÿ”‡©ÿ“†ªÿ�„¨ÿ�ƒ§ÿ�‚¦ÿ��¥ÿ�‚¦ÿ‘…©ÿ˜Ž®ÿŸ–µÿ¡˜¶ÿ¡™µÿ ™´ÿ¢›¶ÿ¢›µÿ¡˜³ÿ¡˜³ÿ¡š´ÿŸ–±ÿ›�¬ÿ—‹§ÿ—‹¨ÿ˜‹©ÿ™Œ«ÿ™�ªÿ™�ªÿ™Œ©ÿš�ªÿ›ŽªÿšŽ©ÿšŽ©ÿ›�ªÿœ�«ÿœ‘«ÿœ’«ÿ�‘«ÿœ�ªÿ�‘«ÿ�’«ÿž“¬ÿž”¬ÿŸ“¬ÿ�’¬ÿ‚�¸ÿƒ€·ÿ‚�·ÿ�€¶ÿƒ€¶ÿ‚€¶ÿ‚€µÿƒ€µÿ„µÿƒ³ÿ„€³ÿ„³ÿ„€³ÿ„€³ÿ„€´ÿ„€´ÿ…€´ÿ…�µÿ„‚¶ÿ…�µÿ…�¶ÿ„�·ÿ„�·ÿ„‚¸ÿƒ‚ºÿƒ‚ºÿ„‚½ÿƒ„¾ÿƒ„¿ÿƒ‡Ãÿ‚ˆÇÿ‚‰Èÿ‚ˆÈÿ„‡Æÿ„‡Äÿ„†Âÿ„…Àÿƒ…¾ÿ…†¼ÿ††¼ÿ…‡»ÿˆ‡¼ÿ‡†¼ÿ‡‡»ÿ‡†»ÿ‰‡ºÿ‰‡¹ÿ‹ˆ¹ÿŒ‰¹ÿŒ‰¸ÿŒ‰¸ÿ�йÿ�‹¸ÿ�Œ¹ÿ�Œºÿ��¹ÿ‘޹ÿ’�¹ÿ“�¹ÿ”�¹ÿ•‘ºÿ–‘¹ÿ–“ºÿ—“»ÿ˜•¼ÿ˜–¼ÿ˜–½ÿ™—½ÿ™˜¾ÿ›™¾ÿš˜½ÿš˜½ÿš˜¾ÿš—¿ÿ™—½ÿš˜¿ÿš˜Áÿ™™Áÿš™Âÿ›šÂÿ››Âÿ››ÅÿšœÈÿ™œÉÿ˜œÊÿ˜œÎÿ–œÎÿ˜ Óÿts�ÿ+ )ÿ5*6ÿOF]ÿ1%-ÿ-!(ÿ-(ÿ0".ÿWO`ÿŸ¡Éÿ��ÃÿžžÃÿžžÄÿŸžÄÿŸ Äÿ ¡Æÿx”ÿ6'1ÿ&ÿ-!%ÿ<07ÿ4*0ÿ=0;ÿK>Jÿ­­Ìÿ©¦Äÿ¨§Ãÿ©¨Äÿª¨Åÿ¨¨Äÿª©Åÿ©¨Åÿª¨Åÿ©©Äÿ©©Äÿ¦¤Áÿ¡�»ÿ¥ ¾ÿ§¤Áÿ§¥Âÿª§Äÿ¨§Ãÿ¦¡¿ÿ–ްÿ‘‡¬ÿ�‚¨ÿŒ¦ÿ�}¦ÿŒ~¥ÿŒ¦ÿ��§ÿ’…©ÿ”†«ÿ‘‚§ÿ�€¥ÿ�¦ÿ�|¥ÿ‹z£ÿ‹z£ÿ‹z£ÿŠz£ÿŠ{¤ÿ�~¥ÿŒ}£ÿ‹{¤ÿ‹z£ÿŠ{¢ÿŠ{£ÿŠ{£ÿŠ{¢ÿ‹|¢ÿŒ|£ÿ‹{£ÿ‹|£ÿŒ{£ÿŒ}£ÿ�~¤ÿ�ƒ§ÿ“†©ÿ“‡¨ÿ’…¦ÿ’…¥ÿ’‡§ÿ—‹«ÿ™‘®ÿŸ˜³ÿ£ž·ÿ¢�¶ÿž–±ÿž”°ÿœ‘­ÿ—�ªÿ˜‹©ÿ–Ѝÿ–Чÿ˜Œªÿ™Žªÿ™Žªÿš�«ÿ˜Œªÿ–‹¨ÿ—Œ¨ÿ™Žªÿ›�«ÿ�’­ÿ�’­ÿ›�«ÿœ�ªÿœ�¬ÿ›�«ÿœ‘¬ÿ�‘¬ÿ‚‚ºÿƒ‚¸ÿƒ�¸ÿƒ�¸ÿƒ�·ÿƒ€¶ÿƒ�¶ÿ„�¶ÿ…�¶ÿ…�¶ÿ…�µÿ„�´ÿ…‚´ÿ„�´ÿ…�³ÿ…‚´ÿ…‚´ÿ…�µÿ…�µÿ…�µÿ†�¶ÿ…‚¶ÿ…�¸ÿ„ƒ¹ÿ„ƒ»ÿ„ƒ»ÿ„ƒ¼ÿ„…¾ÿ„†ÀÿƒˆÃÿƒˆÇÿƒŠÉÿ‚ŠËÿ‚ŒÐÿ�ŒÔÿ�ŒÒÿƒ‹Îÿ„‹Éÿ„‰Æÿ…‰Åÿ„‰Åÿ…ŠÆÿ†ŠÆÿ†‰Åÿ†‰ÂÿˆˆÁÿ‰ˆÀÿЉ¾ÿЉ¼ÿŠŠ½ÿ‹‹½ÿ‹‹¼ÿ�‹½ÿ�Œ½ÿ�Œ½ÿŽŒ½ÿŽŒ¼ÿ�޼ÿ�޼ÿ’�¼ÿ“�»ÿ“�»ÿ”�»ÿ”‘»ÿ”’»ÿ”’»ÿ•’¼ÿ–“¼ÿ–”¼ÿ—”½ÿ˜•½ÿ˜”½ÿ˜•½ÿ—•½ÿ˜•½ÿ˜–½ÿ˜—¿ÿ™—¿ÿ™˜Àÿš™Áÿ™›Äÿ˜šÇÿ˜œÊÿ˜�Ìÿ˜�Ìÿ™œÊÿ™œÈÿŸ¢ÏÿRI^ÿ:/9ÿ:/:ÿPGXÿ. (ÿ7+4ÿ'!ÿ,)ÿmg~ÿ£¤Çÿ¢¤Æÿ¤¥Çÿ¤¥Çÿ¤¦Æÿ¦§Çÿ§©Éÿ��¨ÿ7)1ÿ'ÿ8-5ÿPFQÿNEQÿ0%,ÿ4%/ÿ��¸ÿ©«Èÿ©ªÇÿ©«Èÿ«¬Éÿ«­Êÿª¬Éÿ«¬Éÿ«¬Èÿ¬­Êÿ¬®Êÿ¬¯Ëÿ­¯Ëÿ¬®Êÿ¬®Êÿ©ªÇÿªªÇÿ§¦Åÿš•¶ÿ”Нÿ“‰®ÿ’ˆ­ÿ”Нÿ”Š®ÿ‘‡­ÿ�…¬ÿ‘…¬ÿ�ƒªÿ‹}§ÿŠ{¥ÿ‰y¤ÿŠz¤ÿ‹z¥ÿ‹{¤ÿ‹z¤ÿ‹z¥ÿ‹{¥ÿ‹z¥ÿ‹{¥ÿ‹|¤ÿ‰{¤ÿ‰y£ÿ‰x¢ÿˆx¢ÿ‡w¡ÿ†w¡ÿ‡v¡ÿ†v ÿ†u ÿ†v ÿ‡v ÿˆv ÿˆx ÿŠy ÿ‰y ÿŠz ÿ‹{¡ÿ‹{¡ÿŒ| ÿŒ}¡ÿŽ£ÿ‘�¤ÿ�€¢ÿ�‚¤ÿ’…¦ÿ•†§ÿ’ƒ¤ÿ��¢ÿ�€¢ÿ��¢ÿ‘‚£ÿ‘ƒ£ÿ’ƒ£ÿ”…¥ÿ•ˆ¦ÿ—‹©ÿ—�ªÿ˜�«ÿ—‹©ÿ–Ѝÿ“‡§ÿ•‰¨ÿ”ˆ§ÿ“‡¦ÿ”‡¦ÿ’†¤ÿ•‰¦ÿ™Ž«ÿ‚„»ÿ‚ƒºÿƒƒ¹ÿƒƒ¹ÿ„ƒ¹ÿ„ƒ¸ÿ„‚¸ÿƒ‚¸ÿ„‚¸ÿ„‚·ÿ„‚¶ÿ…ƒ·ÿ„‚·ÿ„ƒ·ÿ…‚¶ÿ„‚·ÿ…ƒ·ÿ…ƒ·ÿ…ƒ¸ÿ…ƒ¸ÿ„ƒ¹ÿ…ƒ¹ÿ„ƒºÿ…„»ÿ„„¼ÿ……¾ÿ„†Àÿ…‡Äÿ„ŠÉÿ„‹Êÿ„ŒÌÿ‚ŒÍÿ�ŒÏÿ��Ôÿ��Ûÿ€‘Þÿ�Üÿ��Ùÿ‚�ÖÿƒŽÓÿƒ�ÑÿƒŽÑÿ„ŽÏÿ„�Îÿ…�Íÿ†ŒËÿ‡‹Èÿˆ‹Åÿˆ‹Äÿ‰ŒÃÿ‰‹ÂÿŠ‹ÂÿŠŒÁÿŠŒÁÿŠŒÁÿŠ‹ÁÿŠŒÀÿŒŒÀÿŒ�¿ÿŒ�¿ÿ��¿ÿŽ�¾ÿ�޾ÿ��¼ÿ’�½ÿ‘�¼ÿ�Ž»ÿ�޼ÿ‘�»ÿ’Ž»ÿ“�»ÿ’�¼ÿ’�»ÿ“‘¼ÿ”’»ÿ”’¼ÿ–”½ÿ–”¾ÿ–•¾ÿ––Àÿ——Âÿ—™Æÿ–™Èÿ—›Éÿ™šÈÿš›ÆÿšœÄÿ–—¾ÿ<1?ÿbYnÿ-!(ÿ;.8ÿ("ÿ3(0ÿ/!)ÿ*%ÿ{–ÿ ¢Åÿ¡¡Äÿ ¡Äÿ  Ãÿ¡¢Äÿ¡£Äÿ¤¥Çÿœ�¼ÿ?/=ÿ#ÿ#ÿ:,4ÿ@4?ÿ90;ÿ.!)ÿ}xŽÿ¥§Çÿ¤¥Äÿ¥¥Äÿ¤¥Äÿ¥§Åÿ¥§Åÿ¥¦Åÿ¥¥Äÿ¥¥Äÿ¥¦Äÿ¥¦Äÿ¦§Åÿ¨¨Çÿ©©Çÿ©«Èÿª¬Éÿ¨©Çÿ£ Àÿžš½ÿ�˜ºÿ�™ºÿž›¼ÿŸ�¾ÿžš¼ÿœ–¸ÿ˜‘µÿ”޲ÿ’‰®ÿŽ„¬ÿŒ©ÿŒ}¨ÿ‹|¦ÿ‹{¥ÿŠ{¦ÿ‹|¦ÿŒ{¦ÿŠ{¥ÿ‹|¥ÿŠ|¥ÿŠ{¥ÿˆy¤ÿ‡x£ÿˆw£ÿ‡w¢ÿ‡w¢ÿ‡x¢ÿ†w¢ÿ‡v¡ÿ†u ÿ…u ÿ†u ÿ‡vžÿ‡uŸÿ†vŸÿ†tžÿ…tŸÿ†t�ÿ†u�ÿ†uœÿ‡u�ÿ‡u�ÿ‡uœÿ†u�ÿ†v�ÿ‡vœÿ‡vœÿ‡wœÿ‡v›ÿ‡u›ÿ‡vœÿˆwœÿˆwœÿˆxœÿ‰x�ÿŠy�ÿ�} ÿŽ€¡ÿ‘ƒ¤ÿ‘ƒ¤ÿ�‚¤ÿ�‚¤ÿ�‚¤ÿ’…¦ÿ“ˆ§ÿ’†¥ÿ‘…¥ÿ�ƒ¤ÿ‚…½ÿƒ…¼ÿ„„¼ÿ‚ƒ»ÿ‚ƒºÿƒ‚ºÿ‚‚ºÿ‚‚¹ÿ„ƒºÿƒ„¹ÿ‚ƒ¹ÿƒ‚ºÿƒ‚ºÿƒƒºÿ„„»ÿƒ„ºÿ„„»ÿ„…»ÿ„…¼ÿ„„¼ÿ„„¾ÿƒ„¾ÿƒ†Àÿ…‡ÃÿƒˆÄÿƒŠÉÿƒ�Ïÿ‚�Òÿ�ŽÒÿ�ŽÒÿ‚ŽÔÿ€ŽÓÿ‚�Óÿ‚�×ÿ€�Ùÿ��Ûÿ€�Ûÿ‘Ýÿ€“àÿ€‘Þÿ€‘Ýÿ€‘Ûÿ�‘Úÿ€‘Ûÿ‚’Ûÿƒ‘Úÿ‚�Öÿƒ�Õÿ…�Ôÿ„�Óÿ„�Òÿ†�Òÿ†�Îÿ…ŽÍÿ†ŽÌÿ‡ŽÌÿ‡ŽÊÿˆŽÊÿˆ�Éÿ‰�Èÿ‹�Çÿ‰ŽÆÿŠŽÄÿŠ�ÄÿŠŒÃÿŠ‹Áÿ‹‹ÀÿŠŠ¾ÿŠ‹¼ÿЉ½ÿ‹Š½ÿŒ‹¼ÿ�Œ½ÿŽ�¼ÿŽŽ¼ÿ�޽ÿ‘�½ÿ’�½ÿ’�¼ÿ’‘½ÿ’’¾ÿ”’¾ÿ•“¿ÿ”“¾ÿ””½ÿ•”¿ÿ•”Àÿwr”ÿA4Dÿ\TjÿG=Lÿ/ *ÿ>1<ÿC8Cÿ5(4ÿ. )ÿˆ…¦ÿš™¿ÿš™¿ÿš™½ÿšš¾ÿšš¿ÿœœ¾ÿ��Àÿ¢¤ÈÿI;Jÿ$ÿ%ÿ)%ÿC7CÿUK]ÿ907ÿ\SdÿŸŸÁÿ�ž¿ÿŸ�¾ÿž�¾ÿ�ž¾ÿ¡ Àÿ  ÁÿŸŸ¿ÿŸž¾ÿŸž¿ÿŸž¾ÿžž¾ÿŸž¿ÿŸŸ¿ÿ  Áÿ¢¢Âÿ ¢ÁÿŸ Àÿ Ÿ¿ÿžœ½ÿ�›¼ÿžœ¼ÿŸœ¾ÿ�š¼ÿ›—¹ÿš–¹ÿ˜•¸ÿ˜”¸ÿš•¹ÿ™•¹ÿ–�´ÿ’‰®ÿŽ„¬ÿ‹¨ÿŠ|¦ÿ‰{¥ÿŠ{¥ÿŠz¤ÿˆz¤ÿˆz¥ÿˆz¤ÿ†y£ÿˆw£ÿ†w¡ÿ‡v¡ÿ†w¢ÿ†w¡ÿ…v¡ÿ„uŸÿ…tŸÿ…tŸÿ„sžÿ„sžÿƒs�ÿ‚s�ÿ„s�ÿƒs�ÿƒr�ÿ†s�ÿ„s�ÿƒs›ÿƒsœÿƒsœÿ‚sœÿ„sœÿ…t�ÿ…t›ÿ‡u�ÿ‡v�ÿ‡vœÿˆvœÿ‰xžÿŠyžÿ‰xžÿ‰yžÿˆx�ÿŠzžÿŒ| ÿŒ~¡ÿŽ�£ÿ‘„¦ÿ�„¥ÿ‘‡§ÿ”‰¨ÿ“ˆ§ÿ“ˆ§ÿ‘‡¦ÿ‚†Àÿ‚…¿ÿ‚„¿ÿ‚„¾ÿ�„¾ÿ‚ƒ½ÿ‚ƒ½ÿ‚ƒ½ÿ‚ƒ½ÿ‚„½ÿ‚„½ÿ‚„¾ÿ‚„¾ÿ‚„¾ÿ�„¾ÿ‚„¾ÿ�„¾ÿ‚„¾ÿƒ…¿ÿƒ†Àÿ„†Âÿ„‡Ãÿ‚‰Çÿ‚ŒÎÿ��Öÿ€�Óÿ€�Øÿ‘Üÿ€’Ýÿ€‘Üÿ€‘Ýÿ�‘Ýÿ��Úÿ��Úÿ�’Þÿ’ßÿ€“àÿ“âÿ~–çÿ~˜êÿ}—êÿ~˜êÿ}˜ëÿ~—èÿ•åÿ~•åÿ—èÿ—éÿ–çÿ€–æÿ�•åÿ‚•âÿ‚”àÿƒ“Ýÿƒ‘Ùÿ„‘×ÿ„‘Öÿ…�Ôÿ…�Óÿ…�Òÿ†�Òÿ†�Ñÿ†�Ðÿ†�Ðÿ‡�Îÿ‡�Ëÿ‡ŽÊÿ‡�Èÿ‡ŒÅÿˆŒÃÿˆ‹Âÿˆ‹Âÿ‰‹ÃÿŠŒÂÿŠ‹Áÿ‹ŒÁÿ‹ŒÀÿ‹Œ¿ÿŒŒ¿ÿ��¿ÿ�Œ½ÿŽ�¾ÿ�޽ÿŽŽ¾ÿŽŽ½ÿ��½ÿ’‘¿ÿ\UpÿVLcÿE;LÿVKcÿ/"+ÿ- )ÿ. *ÿ9-:ÿ7*6ÿŠˆ¬ÿ˜–¿ÿ˜˜¿ÿ™˜¿ÿ™˜¿ÿ™˜¾ÿ™˜½ÿ™™¾ÿŸŸÅÿ]Sgÿ/ 'ÿ(ÿ"ÿLBRÿ?2?ÿ>2<ÿFTÿVNhÿ3&/ÿH;Mÿ+ (ÿ4'2ÿ6)3ÿ8)7ÿB8Iÿ‰†°ÿ��¼ÿ‘�¼ÿ’‘¼ÿ’�»ÿ“‘»ÿ’‘»ÿ“‘»ÿ—–¿ÿog„ÿ;*5ÿ) ÿ6*3ÿ5&/ÿ8,5ÿE9Eÿ6)5ÿˆ…¥ÿ˜–¼ÿ˜–½ÿ–”¼ÿ—”»ÿ—”»ÿ—”ºÿ˜–»ÿ™–¼ÿ˜—¼ÿš˜½ÿ›™½ÿšš¾ÿ›š¾ÿ›œ¿ÿ›œ¿ÿœœÀÿœ�Àÿ��Áÿ��Áÿœ�Àÿ�œÁÿœ�¿ÿœœ¿ÿœ�Àÿœ�¿ÿ��Àÿœ›¿ÿ›š¾ÿ™˜»ÿ˜–»ÿ–’·ÿ•�´ÿ”�´ÿ–’·ÿ•�¶ÿއ°ÿŒ‚¬ÿ‹‚«ÿ‹�ªÿŠ~©ÿŠ~©ÿŠ|§ÿˆz¦ÿˆ{¦ÿ‡y¥ÿ†x¤ÿ…x£ÿ†w£ÿ„v¢ÿ…v¢ÿ„v¡ÿƒu ÿ„u ÿ„u ÿƒu ÿ„t ÿ…u ÿ…tŸÿ…t ÿ…u ÿ„t ÿ…tŸÿ„u ÿ…u ÿ†u ÿ†u ÿ†u ÿ†v ÿ†v ÿ†vŸÿ†vŸÿ‡wŸÿˆwžÿ‡wŸÿˆwŸÿ‡x�ÿˆw�ÿˆxžÿˆyŸÿˆzŸÿ‹|¡ÿŽ€£ÿŽƒ¦ÿ�ƒ§ÿŽƒ¦ÿ�…¦ÿ€„¾ÿ€„¿ÿ�…¿ÿ�…¾ÿ€„¾ÿ€„¿ÿ€„¾ÿƒ¾ÿ‚ƒ¾ÿ€ƒ¾ÿ€„¿ÿ€„¿ÿ�…Àÿ�†Áÿ�†Ãÿ€†Ãÿ€…Ãÿ€‡Åÿ€‡Çÿ‰Éÿ�ŠÏÿ~�Õÿ~�ÛÿŽÜÿ~�Ýÿ|‘ßÿ}“äÿ}•çÿ{–ìÿy˜ïÿy—ïÿy—îÿ{–ìÿ|–ìÿz•éÿ{˜ìÿ{™ïÿ{™íÿ{˜íÿ{—ìÿz™îÿ{›óÿyœõÿ{ úÿz ùÿzžøÿzŸùÿz ùÿzžøÿy¢ûÿz¢ûÿz¡úÿy øÿzŸøÿ|žùÿ|žôÿ}›ñÿ~™ìÿ˜èÿ�—æÿ�—æÿ˜æÿ˜èÿ€™êÿ€˜èÿ€—èÿ�˜çÿ�•äÿƒ”áÿ‚”ßÿƒ”Ûÿƒ’×ÿ…�Òÿ†�Ïÿ…�Ïÿ†�Ðÿ†�Ðÿ…�Ðÿ…‘Ñÿ†�Ðÿ…ŽÏÿ†�Îÿ‡�Îÿ…ŽÍÿ†ŽÊÿ‡ŽÊÿ{~²ÿ7*;ÿ.+ÿ4(5ÿ4)5ÿ3(5ÿ7,9ÿ4'2ÿ0"-ÿIAXÿ‰ˆ¹ÿ�Œ¾ÿ��¾ÿ�Œ¼ÿŽ�¼ÿ��½ÿ�޼ÿ�޼ÿ’‘¾ÿ�}£ÿ6%/ÿ(ÿ>4CÿQGZÿKBSÿ/$+ÿ("ÿpj‡ÿ––½ÿ”“¼ÿ”’»ÿ“’ºÿ”“»ÿ•”¼ÿ–•¼ÿ•”¼ÿ–”¼ÿ––¼ÿ˜—¾ÿ˜˜¾ÿ˜˜¿ÿ™™¿ÿš™¾ÿ™™¿ÿ™š¿ÿš™¿ÿ™™¿ÿ™™¾ÿ™™¿ÿ˜™¾ÿ™š½ÿš›¾ÿšœÀÿš�Àÿ›�ÀÿšœÀÿšœ¿ÿ›œÁÿ›�Àÿ››¿ÿššÀÿ™™½ÿ–˜¼ÿ–”»ÿ“�·ÿ‘‹³ÿ�ˆ±ÿ�…¯ÿŒƒ®ÿ‹�«ÿ‰€«ÿˆ}©ÿ‡|¨ÿ‡}¨ÿ†{§ÿ†z¦ÿ†z¦ÿ…y¥ÿ†y¥ÿ…x¥ÿ„w£ÿ„v£ÿƒv¢ÿ„v£ÿƒu ÿ…u¡ÿ„u¡ÿ„u ÿ„u¡ÿ„v¢ÿ„v¡ÿ…v¢ÿ…v¡ÿ…v ÿ…v¢ÿ†w¡ÿ…w ÿ†w¡ÿ‡v ÿ…wŸÿ‡v ÿ‡x ÿ‡xŸÿˆz¡ÿŠ{¡ÿŠ{¡ÿ‰z¡ÿˆyŸÿ‰z ÿŠz ÿŒ|¢ÿ‹~¢ÿ�‚¥ÿކ¨ÿ€„¿ÿ�…¿ÿ�„¿ÿ„¿ÿ€„¿ÿƒ¾ÿ€ƒ¾ÿƒ¾ÿ€ƒ¾ÿ€‚½ÿ€ƒ½ÿ€‚¾ÿ€‚¾ÿ€ƒ¿ÿ�…Àÿ€„Áÿ€†Âÿ€‡Åÿ€‡Çÿ€‰Êÿ‰Íÿ‹ÐÿŒØÿ}�ßÿ|’åÿz“æÿz”æÿz•éÿzšòÿx›ôÿw�÷ÿwžúÿwžúÿwžùÿv�øÿwŸùÿw ùÿv øÿx ùÿw øÿw øÿxŸøÿxžøÿx ùÿx¡üÿx¢ýÿx¢ûÿy¢üÿw¡üÿw¢üÿw«þÿxªþÿxªþÿx¦ýÿy¦ýÿz£üÿzŸùÿ|œôÿ|›ñÿ}šïÿ}™ìÿ~˜êÿ}˜ëÿ~™íÿ}™íÿ~šëÿ—èÿ•åÿ~•äÿ€–åÿ€•äÿ�“ßÿ‚’Úÿƒ‘Øÿƒ’×ÿƒ�×ÿ„‘Õÿƒ�Ôÿƒ�Õÿƒ‘Õÿ„‘Öÿ„‘×ÿ„�×ÿ…‘Õÿ…�Òÿ„�Òÿik›ÿQJlÿA7Oÿ9.>ÿ<4Gÿ0#0ÿ0&3ÿ8,:ÿ*'ÿOHdÿ‰�ÅÿŠŒÄÿŠŒÂÿŠŒÁÿ‹�Àÿ‹�¾ÿŒ�¾ÿ�޾ÿŽŽ¾ÿ�޾ÿ9)3ÿ$ÿ+ %ÿ@3AÿG:Iÿ8.:ÿ'#ÿNEYÿ——Áÿ”“¾ÿ”“¾ÿ““½ÿ”“¾ÿ•”¾ÿ”“½ÿ”“¼ÿ””½ÿ”“½ÿ•”¼ÿ–•½ÿ–•½ÿ––¾ÿ••¼ÿ–”¼ÿ•”¼ÿ–”¼ÿ—–¾ÿ˜—¿ÿ˜—¿ÿ——¾ÿ——¾ÿ˜˜¾ÿ—˜¾ÿ—˜¿ÿ˜—¾ÿ—–¾ÿ––½ÿ–—½ÿ––½ÿ–•½ÿ–•¼ÿ••¼ÿ””¼ÿ“’ºÿ�Ž·ÿ�‰³ÿ�‡³ÿ�†²ÿŒ†²ÿŒ…±ÿŒ†²ÿŒ…±ÿŒ„±ÿŒ„±ÿŒ„±ÿŠƒ¯ÿ‰�¬ÿ‰«ÿˆ|ªÿˆ{©ÿ‡{©ÿ…y§ÿ…x¦ÿ…x¥ÿ…x¦ÿ…x¦ÿ…x¥ÿ…w¥ÿ†x¤ÿ…y¤ÿ†y¤ÿ†y¥ÿ‡y¥ÿ†x¤ÿ†x£ÿ†x¢ÿ†x¢ÿ‡x£ÿ†y£ÿˆy£ÿ‡y¢ÿˆz£ÿˆz¢ÿ‰z£ÿ‰{¢ÿ‰{¤ÿŠ}¤ÿŠ~¤ÿ‹¤ÿŒ�¦ÿŽ„©ÿ�†ªÿ‘‰«ÿ’‹­ÿ€†Âÿ€†Áÿ†Âÿ€†Âÿ€†Áÿ…Áÿ�…Áÿ�…Áÿ€…Áÿ�…Àÿ�…Àÿ€…¿ÿ€…Àÿ�…Àÿ�†Àÿ�…Áÿ€†Áÿ€†Áÿ�†Âÿ�†Ãÿ�‡Æÿ€‰Èÿ�‰Êÿ~ŠÏÿ~�Õÿ�×ÿ~�×ÿ�Øÿ~‘Üÿ}’ßÿ}“áÿ}•çÿ|–éÿ{–éÿz—ìÿy›ñÿz�óÿyœôÿy�óÿy õÿx¥øÿv¥ûÿuªþÿv±ÿÿv´ÿÿt±ÿÿu°þÿv¯þÿu¬þÿv«þÿw¬þÿu®þÿv¯þÿv¯þÿv«þÿx¨þÿx¦þÿx£üÿx¡üÿy¢ûÿy¡úÿy úÿyŸøÿyŸøÿ{�öÿ{œóÿ|›òÿ{›ñÿ|šñÿ|œóÿ|šïÿ}™îÿ~™íÿ~˜ëÿ~—èÿ€—æÿ€•ãÿ€•ãÿ�–ãÿ�”àÿƒ“Üÿƒ’Úÿ„“Ùÿ„’×ÿ„‘×ÿ„•ÝÿPLpÿhm£ÿ,"-ÿ5):ÿ4'8ÿB>]ÿA;Rÿ8)6ÿ.$/ÿ[X{ÿ‰�Êÿ‡�Çÿˆ�ÅÿˆŒÃÿ‰ŒÃÿ‰‹Áÿ‰ŒÁÿŠŒÀÿŠ�ÀÿŒ�ÃÿI/>ÿE9HÿH@Uÿ2$-ÿ‹Šµÿ‘‘¿ÿ�‘¾ÿ‘‘¾ÿ�‘½ÿ‘’¼ÿ’‘½ÿ’‘½ÿ’‘¼ÿ’‘½ÿ’�¼ÿ‘�»ÿ‘�»ÿ‘�»ÿ’�»ÿ‘Žºÿ�޹ÿ�޹ÿ‘�¹ÿ‘�ºÿ‘�ºÿ‘�ºÿ‘�»ÿ‘�¹ÿ‘�ºÿ’�»ÿ’‘»ÿ“‘»ÿ“‘»ÿ“’»ÿ“’¼ÿ“‘»ÿ’‘»ÿ’�»ÿ’�ºÿ��¹ÿŽŒ·ÿŽ‹¶ÿ�Š·ÿŒˆ´ÿŒˆ´ÿ�ˆ´ÿމµÿŽˆ¶ÿ�‡´ÿ‹†³ÿ‹„²ÿŠ‚°ÿ‰€­ÿˆ~­ÿ‡~¬ÿ‡~«ÿ‡}«ÿ‡}«ÿ†{ªÿ†{©ÿ‡{ªÿ…z¨ÿ…z¨ÿ…y§ÿ…z¨ÿ‡z§ÿ‡z§ÿ†z§ÿ†{¦ÿ‡z¦ÿ‡z¦ÿ‡z¥ÿ‡{¥ÿ‡{¥ÿ‡{¥ÿ‡{¥ÿˆ|¤ÿ‰~¦ÿŠ~¦ÿ‹~¦ÿ‹¦ÿ‹€§ÿ�‚©ÿ�„©ÿކªÿ�‡¬ÿ�ˆ­ÿ�‰¬ÿ�‰¬ÿ�ˆ«ÿ~†Æÿ~‡Æÿ‡Æÿ}‡Åÿ‡Åÿ†Åÿ~†Äÿ†Äÿ‡Äÿ†Åÿ€‡Åÿ€†Äÿ€†Ãÿ†Ãÿ€†Äÿ‡Äÿ†Åÿ‡Äÿ‡Äÿ‡Äÿ€ˆÅÿ�ˆÆÿ‡Åÿ�ˆÇÿ€ˆÇÿ€ˆÇÿ�‰Çÿ�‰Æÿ�‰Çÿ�ŠÈÿ‚ŠÈÿ�‹Èÿ‚‹Êÿ‚ŒÌÿ�ŽÏÿ��Îÿ�ŒÎÿ�ŒËÿ‚ŒËÿ�ŒÌÿ��Íÿ€ŽÑÿ��Øÿ}”ßÿ{™èÿ{¢ñÿx¤òÿw¨÷ÿw®ûÿv¯ûÿu±ýÿv³ýÿv±üÿv¯ýÿv¶ýÿvµýÿu²üÿv°ýÿw­üÿxªþÿx©þÿx§þÿx¥üÿy¤üÿy£ýÿy ùÿ{œôÿ{šîÿ}šîÿ~™îÿ}šîÿ~šíÿ˜êÿ˜éÿ€—æÿ€—æÿ€–äÿ‚•áÿ‚“Ýÿ„’Øÿƒ’Öÿ…’Õÿ†’Ôÿ…‘Ñÿ…‘Òÿ…‘ÑÿG1Aÿ0%2ÿy|¬ÿ‡�Çÿˆ�Èÿˆ�Èÿ‰�Êÿˆ�Êÿˆ�Éÿ‰�Éÿ‰�Çÿ‰�ÆÿŠ�Çÿpn—ÿ6&/ÿ*%ÿ6,9ÿA6HÿF=QÿD:Mÿ>1AÿL@UÿŽ‘Æÿ‹ŽÀÿ‹ŽÀÿŒ�Àÿ‹ŽÀÿŒ�Àÿ��¿ÿ�Œ¿ÿŒŒ¾ÿŒ�¾ÿ��¾ÿŒ�½ÿ�Œ½ÿ�Œ¼ÿŒ‹½ÿ‹‹»ÿ‹‹¼ÿ‹‹»ÿ‹‹»ÿŒ‹»ÿŒ‹»ÿŒ‹»ÿ�‹»ÿ�Œ»ÿ�ŒºÿŽŒ¹ÿ�‹ºÿ�Œºÿ�ŒºÿŒ‹¹ÿ�Џÿ�‹¸ÿ�ЏÿŒ‹¸ÿŒ‹¸ÿ�‹¸ÿ�Џÿ�Š·ÿŒŠ·ÿŒ‹·ÿŒ‹·ÿŒ‰¶ÿЇ´ÿ‹‡´ÿІ²ÿ‰ƒ±ÿŠƒ±ÿŠ�°ÿ‰ƒ¯ÿŠ‚¯ÿŠ�®ÿ‰€®ÿ‰€®ÿ‡�­ÿˆ­ÿˆ~¬ÿˆ¬ÿ‡}«ÿ‡}¬ÿ‡}¬ÿ‡}«ÿ‡|ªÿ‡}ªÿˆ}ªÿˆ~©ÿ‰~©ÿˆ}©ÿ‰©ÿˆ©ÿ‰ªÿŠ€©ÿ‰ªÿˆ¨ÿ‰~§ÿˆ~§ÿˆ}§ÿ‡}§ÿˆ|¦ÿ‰|¥ÿŠ|¥ÿ‰|¤ÿ‰|¥ÿŠ|¤ÿ‰|¤ÿ‰|¤ÿt›ñÿu—îÿv“êÿx�åÿy�ãÿz�Þÿ{‹Øÿ{ŒØÿ{�×ÿ{ŽÜÿ{�ßÿz�ßÿzŽÞÿz‘äÿy‘ãÿy‘äÿz’ãÿz�âÿzŽßÿz�ßÿz�àÿ{�Þÿ|�Ùÿ}�×ÿ~‹Õÿ~‹Óÿ}‹Ðÿ‹Ïÿ€ŠÏÿ‹Îÿ‹Îÿ€ŒÎÿ€‹Ïÿ€ŒÐÿ€ŒÐÿ�‹Ïÿ€ŒÏÿ€ŒÍÿ�‹Íÿ‚ŒÍÿ�ŒËÿ‚ŒËÿ‚ŒËÿ‚ŒÌÿƒŒÌÿ‚�Íÿ‚�ËÿƒŽÌÿ‚�Íÿƒ�Îÿƒ�ÍÿƒŽÍÿƒŽÌÿƒ�Ëÿƒ�Ëÿƒ�Ëÿƒ�Ìÿƒ�Ëÿ„�Êÿ„ŽËÿƒ�Íÿ„�Ïÿƒ�Óÿƒ’Øÿƒ‘Öÿ„‘Ôÿƒ�Ñÿ„�Îÿ„ŽÌÿ…�Êÿ…ŽÉÿ…ŽÈÿ…ŽÈÿ‡ŽÈÿ‡�Çÿ†�Çÿ‡�Èÿ‡�Èÿ†�Èÿ‡�Èÿ‡ŽÈÿ†�Èÿ†ŽÈÿ‡�Éÿ‹”ÑÿNC^ÿ4%2ÿ7,<ÿ9->ÿ5(6ÿ5Hÿ4)6ÿ8.?ÿ0$.ÿ.#,ÿ?4Fÿ…�Æÿ�ˆ¾ÿ‚ˆ¿ÿ‚‡¾ÿ�†¼ÿ�†»ÿ‚†ºÿ‚‡»ÿƒ‡»ÿ�„ºÿ€„·ÿxx¦ÿD6Fÿ&ÿ;0?ÿQJeÿWOnÿMD]ÿ,%ÿ7,8ÿf_€ÿŠ�Âÿ‰ŒÁÿ‰ŒÁÿ‰ŒÀÿ‰Œ¿ÿ‰Œ¿ÿŠŒ¿ÿ‰Œ¿ÿŠ�¿ÿ‹ŽÀÿ‹�ÁÿŒ�Áÿ‹�ÁÿŒ�ÁÿŒ‘ÂÿŒ‘ÂÿŒ‘ÁÿŒ’ÂÿŒ�ÁÿŒ‘ÀÿŒ’Áÿ�‘Áÿ�‘ÁÿŒ�Àÿ‹�ÀÿŠŽ¾ÿ‰Ž¾ÿ‹�½ÿ‹�¼ÿŠŒ¼ÿ‹Œ¼ÿŒŒ¼ÿ‹‹»ÿ‹‹»ÿ‹‹ºÿЉ¸ÿ‹‰¸ÿЉ¸ÿ‰ˆ·ÿЇµÿЇµÿ‰‡µÿ‰†´ÿˆ„³ÿˆ…³ÿ‰ƒ³ÿˆƒ±ÿ‡‚°ÿˆ‚±ÿˆ‚°ÿˆ‚°ÿˆ‚¯ÿ‰‚°ÿˆ‚¯ÿˆ�­ÿˆ�®ÿ‡€­ÿ‡¬ÿˆ~­ÿ‡­ÿ†­ÿ‡­ÿ†~­ÿ‡¬ÿˆ~¬ÿ‡}«ÿˆªÿ‰ªÿˆªÿˆ~©ÿˆ©ÿˆ~©ÿ‡~¨ÿˆ¨ÿˆ~©ÿ‡}§ÿ‡}§ÿ‡|§ÿ‡|¦ÿ‡{¥ÿ‡{¥ÿ‡{¤ÿ‡z¤ÿ‡z¤ÿu“îÿs—óÿtšôÿr¡øÿr›õÿušòÿu—ïÿu–íÿu•ïÿu–ñÿuš÷ÿsŸùÿrŸùÿr ùÿr£ûÿs¥ûÿr¢÷ÿs¡öÿtžôÿtœóÿu�ôÿu›óÿt›óÿuœõÿuŸøÿtžúÿs ûÿr ûÿr�ûÿs�ûÿsŸüÿr ûÿs¡ýÿr£þÿr¤þÿr£ýÿt¡üÿvœöÿv—ðÿx—îÿx–ìÿz•éÿ{”çÿ{”æÿ{“äÿ|‘ßÿ}‘Þÿ|’ßÿ~’ßÿ}�Üÿ}�Úÿ~‘Ûÿ~’Üÿ~’Üÿ~‘Þÿ~’ßÿ~“ßÿ~“ßÿ“Þÿ€’Úÿ€�Ùÿ€�Øÿ��Öÿ‚�Ôÿ‚�Òÿƒ�Ñÿƒ�Ðÿƒ�Ðÿƒ�Ðÿ„�Ðÿƒ�Ðÿ„�Ïÿƒ�Îÿ„�ÍÿƒŽÌÿ„�Ëÿ„ŽËÿƒŽËÿƒŽËÿ„ŽÌÿƒŒÉÿw|±ÿxz°ÿw{°ÿ_\�ÿ7)6ÿH?Vÿ1$-ÿ0"+ÿ1#,ÿ+%ÿ,&ÿ6)4ÿ+)ÿ3(7ÿF;QÿH=TÿH=UÿG=RÿE;OÿC7JÿD8LÿF;OÿF9MÿB4Hÿ>1EÿC6KÿC5Fÿ*%ÿ& ÿ,$ÿ1"*ÿ0"*ÿ)"ÿ.!*ÿC8Iÿe`ƒÿfb„ÿhe‰ÿ†ˆ»ÿ‰ŒÂÿŠ�ÁÿŠ�Âÿ‹�Âÿ‹�ÂÿŒ�ÂÿŒ‘Âÿ�’Ãÿ�’ÃÿŽ“Äÿ�“ÃÿŒ’Ãÿ�“ÃÿŒ’Âÿ�’ÂÿŒ’Âÿ�“ÃÿŽ“Âÿ�“Âÿ�“Áÿ�’Âÿ�’Áÿ�’ÁÿŒ‘ÁÿŒ�Àÿ‹�¿ÿŒŽ¾ÿ‹Ž¾ÿ‹�¾ÿ‹�½ÿŒ�¼ÿ‹�¼ÿ‹‹»ÿ‹‹ºÿŒŠ¹ÿ‹‰·ÿ‰ˆ¶ÿ‰‡·ÿЇ¶ÿ‰†¶ÿ‡…´ÿ‰…³ÿˆ…´ÿˆ„²ÿˆƒ²ÿ‰ƒ±ÿˆ‚±ÿˆ‚±ÿˆ‚°ÿ‰‚°ÿˆ�¯ÿˆ�¯ÿ‡�®ÿ‡€®ÿˆ€¯ÿ‡­ÿˆ€®ÿ‡­ÿ‡¬ÿ‡¬ÿˆ~­ÿˆ~¬ÿ‡~«ÿˆ~©ÿ‡}©ÿˆ~¨ÿ‡}©ÿ‡~¨ÿ‡|§ÿ‡|§ÿ‡}¦ÿ‡{¦ÿ‡|¥ÿ†z¤ÿ†z¤ÿ‡z£ÿ‡z£ÿ†z¢ÿ†z¢ÿ†z£ÿp§ýÿq«ýÿp©üÿo¨ýÿq¤üÿrŸúÿs¡üÿrŸûÿrŸüÿrŸûÿr¡ûÿq£úÿr¦üÿs ùÿsš÷ÿtšôÿu™òÿu–íÿw–íÿx•éÿw“æÿy“æÿy‘äÿy“äÿz“åÿz“åÿy”èÿx•êÿx–îÿw˜ñÿuœõÿu úÿs¢úÿs£úÿt¡ùÿs¡øÿs¤ûÿu¡ûÿuŸúÿu›öÿwšôÿx˜ñÿy˜ðÿx˜ðÿx˜ïÿw›óÿw�öÿv�÷ÿv�öÿxœöÿyšóÿx›õÿwšõÿxœ÷ÿyšòÿ{—ëÿ{—êÿz—íÿy›óÿx�ùÿw�øÿwžùÿxœöÿyšðÿ{—êÿ}–èÿ|–éÿ|—èÿ~—æÿ”âÿ€’Þÿ€”ßÿ�“Ûÿ‚’Ùÿ�’Öÿ‚‘Öÿ‚’×ÿƒ’Ôÿƒ’Ôÿƒ‘Óÿ��ÏÿJLnÿ$#ÿ(%ÿ+ )ÿ,+ÿ#ÿ+%ÿ. &ÿ/$ÿ3!(ÿ% ÿ&!ÿ3#.ÿF5KÿRCaÿPA[ÿPAWÿF8MÿULmÿPB[ÿND^ÿG4BÿL7HÿM9MÿN7Hÿ@/=ÿ?4Cÿ#ÿ2*8ÿ-#ÿ!ÿ'ÿ'ÿ)!ÿ%ÿ%!ÿÿ81Bÿƒˆ»ÿ‰�ÄÿŠ�Äÿ‰�Ãÿ‰�Ãÿ‹�Ãÿ‹�ÃÿŒ�Âÿ‹‘Âÿ‹�Âÿ‹�Âÿ‹�Âÿ‰�Àÿ‰�¿ÿ‰ŽÀÿŠŽÀÿ‹�Àÿ‹�Áÿ‹�Àÿ‹�ÀÿŒ‘ÁÿŒ�Áÿ�’ÂÿŽ’Âÿ�’Áÿ�‘Áÿ�‘Áÿ�‘Áÿ�‘Áÿ�‘Àÿ��¿ÿŒ�¾ÿŒŽ¾ÿ‹Œ¼ÿ‹ŠºÿŠŠºÿ‹‰¹ÿ‹‰·ÿ‹ˆ¸ÿЇ·ÿ‰†µÿ‰…´ÿˆ…´ÿ‡„²ÿˆ„²ÿˆ‚²ÿˆƒ±ÿˆ‚±ÿˆ�±ÿ‡�°ÿˆ‚°ÿ‰‚°ÿ‰�¯ÿˆ�®ÿ‡€®ÿˆ¯ÿˆ€®ÿˆ­ÿ‰€¬ÿˆ¬ÿ‰¬ÿˆ«ÿˆ~«ÿˆ~«ÿˆ~ªÿ‡}©ÿ‡}¨ÿ‡}§ÿ†|§ÿˆ|¦ÿ†{¦ÿ†{¥ÿ…{¥ÿ†{¥ÿ†z¤ÿ†y£ÿ‡y¢ÿ‡x¢ÿ‡x¢ÿ…x¡ÿ†x¡ÿo¦þÿp ûÿs›÷ÿsšõÿu—ðÿtšóÿtšóÿt—òÿuœ÷ÿt�÷ÿt�öÿu™òÿt�ôÿsœôÿt øÿtžöÿr¤úÿvšôÿv—ïÿu�÷ÿu™õÿužøÿt ùÿuŸûÿt�ùÿtžúÿs¡üÿsžùÿtžøÿu›øÿuœöÿu›õÿu™òÿw˜òÿw–îÿy–ëÿy”èÿy•èÿz•çÿz”äÿz”ãÿ{‘àÿ|‘ßÿ|�Ýÿ}�Ûÿ~�Úÿ}�Øÿ�Øÿ�Øÿ~�×ÿ~�×ÿ�Øÿ~’Ùÿ}“Ýÿ“àÿ~“Þÿ|•àÿ~–äÿ}•âÿ}–âÿ|—äÿ{˜èÿ|˜êÿz™ëÿzšîÿ{™ìÿ{šëÿ|˜éÿ}˜êÿ~–åÿ~•ãÿ~•àÿ~”áÿ–åÿ}—åÿ~—æÿ~˜èÿ}—æÿ~–äÿ•ãÿ~’ÝÿZb™ÿBDfÿ"ÿ% ÿ+&ÿ& ÿ6&/ÿ7&+ÿ+ ÿ/%ÿ#ÿ"ÿ3#+ÿM9JÿS=OÿP;MÿN;MÿI5GÿS;OÿR=SÿO6HÿN8KÿS,;ÿ:'5ÿ4%.ÿ,%ÿ*"ÿ&ÿ-'ÿ*$ÿ' ÿ'!ÿ/ )ÿ*$ÿ.!'ÿ7+:ÿ<4Hÿ~‡Áÿ…ŽËÿ…ŽËÿ†ŽÊÿ…�Éÿ…�Èÿ†�Çÿ†ŒÅÿ‡ŒÄÿ‡ŒÄÿ‡ŒÃÿ‡ŒÂÿ‡ŒÁÿˆ‹ÁÿˆŒÀÿˆŒÀÿ‡‹¿ÿ‡Š¿ÿ‡‰¿ÿ‡‰¾ÿ‡‰½ÿˆ‰¼ÿ‡‰¼ÿ‡‰½ÿ‡ˆ¼ÿˆ‰¼ÿ‡ˆ»ÿ‡ˆ»ÿ‡‰»ÿˆˆºÿ‰ˆ¹ÿˆˆºÿ‡ˆ¹ÿ‡ˆ¹ÿˆ‡¸ÿ‡‡·ÿ‰‡·ÿˆ†·ÿˆ†µÿˆ…µÿˆ†´ÿˆ…´ÿ‡„³ÿ‡ƒ²ÿ‡ƒ±ÿ†ƒ±ÿ‡�±ÿˆ�°ÿˆ�°ÿ‰‚¯ÿ‡�®ÿˆ�­ÿˆ€­ÿ‡€­ÿ‡€­ÿ‡¬ÿ‡~¬ÿˆªÿˆ~«ÿ‡}«ÿˆ}ªÿ†|©ÿ†}©ÿ†|¨ÿ‡}¨ÿ†|§ÿ†{¦ÿ†{¦ÿ…{¥ÿ…y¤ÿ†y¤ÿ†y¥ÿ…y£ÿ„x£ÿ„y£ÿƒx¢ÿ„w¡ÿ…v¡ÿ„v ÿ„vŸÿƒvŸÿp¯þÿo§þÿq§þÿpŸýÿr ýÿsžüÿušöÿrš÷ÿqŸûÿsžüÿr£ýÿq«ýÿr¬ýÿq¦þÿq¤ýÿq©ýÿr§þÿq¬ýÿq©þÿr§ýÿs¦þÿs¦ýÿt¦ýÿs¡ûÿt¡ûÿs�öÿtŸ÷ÿtŸøÿsŸ÷ÿt øÿsŸ÷ÿtžöÿtœõÿuœ÷ÿvšóÿušôÿu›÷ÿvœ÷ÿušôÿwœ÷ÿx–ìÿy™ïÿy–éÿ{”æÿ|•äÿ{–åÿ|–èÿ{—èÿ|—åÿ|–åÿ~•ãÿ}•àÿ~•áÿ•áÿ~•àÿ~•Þÿ”Ýÿ•ßÿ~•ßÿ€•Þÿ€•Þÿ€•Ýÿ•Ýÿ•Þÿ€•Þÿ•Þÿ€”Üÿ€”Üÿ”Úÿ�“Úÿ€“Ùÿ“Ûÿ“Ûÿ”Üÿ~•Þÿ•ßÿ}–âÿ}—æÿ|šìÿ|œîÿv’ßÿ>8Sÿ5'5ÿ5'2ÿ3%0ÿ3%/ÿ1#.ÿ1%/ÿ1#-ÿ2".ÿ1#.ÿ2$.ÿ0!,ÿ0",ÿ- 'ÿ.!)ÿ- (ÿ,&ÿ. )ÿ- 'ÿ/!)ÿ. 'ÿ,(ÿ- (ÿ-)ÿ-(ÿ. )ÿ-'ÿ0!+ÿ,'ÿ-!(ÿ+'ÿ- (ÿ*'ÿ0!*ÿ. &ÿ0"*ÿ."+ÿ, )ÿp€Æÿ€‘Ýÿ‘Üÿ�Ùÿ��×ÿ‚�Óÿ‚�Ïÿƒ�Ìÿ„�Êÿ…ŒÇÿ†ŒÇÿ†ŒÆÿ†‹Äÿ†‹Ãÿ…‹Äÿ†ŒÃÿ†‹Âÿ†‹Âÿ†ŠÁÿ‡‰Àÿ†ˆÀÿ†ˆ¾ÿ…ˆ¾ÿ†ˆ¿ÿ…‡¾ÿ†‡½ÿ††½ÿ†‡¼ÿ††»ÿ†‡ºÿ†‡»ÿ‡†¹ÿ‡†ºÿ‡†¹ÿˆ†¸ÿˆ†¸ÿˆ†·ÿˆ…¶ÿˆ„¶ÿ‡„µÿ‡„µÿ‡ƒ´ÿ‡ƒ³ÿ†ƒ³ÿ†‚²ÿ‡‚±ÿ…�¯ÿˆ€¯ÿ‡¯ÿ‡€®ÿ‡­ÿˆ­ÿ‡­ÿ‡­ÿˆ~¬ÿˆ~¬ÿ‡~«ÿ†}«ÿ†|©ÿ†{©ÿ†{©ÿ†{¨ÿ†|©ÿ†{¦ÿ…{¦ÿ…z¥ÿ†z¥ÿ…z¦ÿ…y¤ÿƒy¤ÿ„x£ÿ…w£ÿ„v¢ÿ„w¡ÿƒv ÿƒv¡ÿƒvŸÿƒužÿƒtžÿƒt�ÿƒs�ÿo©ýÿp§ýÿq§þÿq¥üÿq¥ýÿq¤üÿq¤ýÿr¤ýÿq¤ýÿq¦ýÿp¥üÿr¦þÿp¥ýÿq¦ýÿqªþÿp¨þÿq¦ýÿq©þÿr©þÿq¨ýÿs«þÿr©þÿp¦ýÿs¦þÿr¥ýÿqªþÿq§þÿr§þÿqªþÿp­ÿÿq­þÿo¬ýÿq­þÿo¯þÿp®ÿÿp¯ÿÿq®þÿp±þÿp±ÿÿq®ÿÿq«þÿq¬ÿÿq¬ÿÿr¨þÿt£úÿu ÷ÿvŸõÿvžõÿw�ôÿyœðÿyšíÿz˜êÿ{—çÿ|–åÿ|—åÿ}–ãÿ}–âÿ~–äÿ}—äÿ}—åÿ~—äÿ}˜åÿ}˜åÿ~™åÿ~˜åÿ}—äÿ~—åÿ}˜æÿ}™çÿ}™èÿ{šëÿz›ëÿ|›íÿ}œïÿ}œìÿ|œìÿ~�íÿ|œëÿ}�íÿ}œëÿz•ßÿ=;Xÿ ÿ ÿÿ!ÿÿÿÿÿÿ ÿÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ!ÿ!ÿ!ÿ!ÿ$ ÿ# ÿ3.DÿsŒÝÿx•îÿy•îÿ{•ëÿ{“êÿ|“èÿ|‘ãÿ~�ßÿ€�Ýÿ�Úÿ€�Øÿ€Ž×ÿ�ŽÕÿ‚ŒÒÿƒŒÐÿ„ŒÏÿƒŒÍÿƒ‹Ëÿ„‹Êÿ„ŠÇÿ…ŠÆÿ…‰Äÿ…‰Ãÿ…ˆÂÿ…ˆÁÿ…ˆÁÿ„‡¾ÿ…†¾ÿ„…½ÿ„†½ÿ……¼ÿ……ºÿ†…ºÿ…„¹ÿ†ƒ¸ÿ…„·ÿ…ƒ·ÿ†‚¶ÿ†ƒ´ÿ…‚³ÿ†‚´ÿ…�²ÿ„�³ÿ…�²ÿ†�²ÿ…�°ÿ†€°ÿ…€®ÿ…€¯ÿ†®ÿ…®ÿ…®ÿ‡­ÿ…~¬ÿ†~«ÿ†}«ÿ…|©ÿ„|ªÿ†|ªÿ…z¨ÿ…{¨ÿ„z¨ÿ„z§ÿ„z¦ÿ„z¥ÿ„y¥ÿ„y¤ÿƒx¤ÿƒw£ÿ‚x¢ÿƒv£ÿƒv¡ÿ‚vŸÿ‚uŸÿ�uŸÿ�vžÿƒužÿ‚t�ÿ�tœÿ�tœÿ‚sœÿlÆýÿlÃþÿmÆÿÿn½ýÿo¹þÿpµýÿp³þÿp³þÿq³þÿqµþÿq³þÿp°þÿq­þÿr¨þÿq©ýÿr§ýÿs¨þÿs¦þÿs¦þÿr§þÿs©þÿs§þÿr£ýÿr¤üÿs©þÿq®þÿr¤þÿr§þÿs¥þÿr¥ÿÿs¥ÿÿs£þÿr¥ýÿq§ÿÿr©þÿq©þÿq¨þÿr«þÿr¬ÿÿq­þÿq¯þÿq²þÿp¶ÿÿo¹þÿp¹ÿÿo»ÿÿp¼ÿÿp·þÿq°þÿr¬ÿÿr§ýÿt ûÿwœöÿxœóÿwœóÿw�ôÿvŸõÿwŸ÷ÿv¡÷ÿv¡÷ÿvŸöÿwžöÿw ÷ÿvŸ÷ÿwžöÿwŸ÷ÿy�õÿyžóÿxžôÿx ÷ÿx¢ùÿw£ùÿx¢øÿx¡÷ÿy öÿz ôÿzžòÿ{žðÿ{œîÿ|›ëÿ{šèÿOTÿ-"1ÿ) ,ÿ,".ÿ('ÿ+ +ÿ*(ÿ-!,ÿ))ÿ+!,ÿ* *ÿ,!,ÿ* +ÿ) *ÿ* (ÿ*(ÿ*(ÿ('ÿ'&ÿ&&ÿ*)ÿ'%ÿ+ +ÿ)'ÿ,"+ÿ((ÿ-!-ÿ('ÿ."-ÿ)(ÿ-",ÿ)'ÿ.$.ÿ)%ÿ/%0ÿ,!,ÿ2'3ÿF?[ÿ}‹Íÿ‘Ùÿ‘Ûÿ€‘Ùÿ’Úÿ‘Úÿ��Ùÿ€�×ÿ��Ùÿ��Øÿ€�Ùÿ€�Üÿ€ŽÙÿ��Õÿ‚�Ðÿ„ŒÎÿƒŒÍÿƒŒÌÿƒŒÌÿƒ‹Êÿƒ‹Èÿ„ŠÇÿ„ŠÆÿ„ŠÅÿ…‰Äÿ„ˆÃÿ„ˆÁÿ…ˆÁÿ„†Àÿ„†¿ÿ„…¾ÿƒ…½ÿƒ„½ÿƒ„¼ÿƒƒ»ÿƒ‚ºÿƒ‚¸ÿ„�·ÿ„�¶ÿ„�´ÿ…‚´ÿ…‚´ÿ…‚´ÿ…�´ÿ…�³ÿ…�³ÿ„�²ÿ„€±ÿ„€±ÿ‚}®ÿ„¯ÿƒ~®ÿ„}¯ÿƒ}­ÿ„|«ÿ„|«ÿ„{ªÿ…{ªÿ„zªÿ„z©ÿƒz¨ÿƒz¨ÿ„y§ÿƒy§ÿ„y§ÿ‚x¥ÿ‚w¥ÿ‚x¤ÿ‚w£ÿ�w¢ÿ‚v¡ÿ‚u¡ÿ�u ÿ�u ÿ�uŸÿ�užÿ�tžÿ‚tžÿ�sœÿ�sœÿ‚sœÿo²þÿp´þÿo²þÿq³þÿp²þÿp¯þÿp®þÿpªþÿr§þÿr¡üÿs üÿsžøÿt�öÿsœôÿs�ôÿtœõÿtŸøÿsŸøÿtŸùÿtžøÿsžúÿuŸúÿtž÷ÿt�öÿv�õÿw�öÿu�ôÿv�õÿw�õÿvœôÿv�ôÿvžõÿv�õÿv�óÿvžøÿuŸùÿvžõÿwœñÿw›ïÿxšîÿx�ñÿwžôÿw¡÷ÿv£ùÿt¨úÿq²ýÿp»þÿnÆþÿnÄþÿpÁþÿo»þÿpµþÿq³þÿs³þÿr²ýÿr°þÿt²þÿr±þÿs®þÿr­þÿs«þÿs¬þÿrªþÿs©þÿt§ýÿu¥ýÿu¤üÿv¤ûÿu¤üÿu¥ýÿu¥þÿu§þÿu¨þÿu§ýÿv¦þÿu¥ýÿv¤ýÿu¢üÿv ûÿu ùÿvžöÿMVƒÿ3'4ÿ/$0ÿ/%1ÿ/$.ÿ/#/ÿ/#.ÿ-",ÿ.".ÿ+!,ÿ)(ÿ*)ÿ)'ÿ)&ÿ(&ÿ'$ÿ%"ÿ%"ÿ$"ÿ&#ÿ$"ÿ&"ÿ& ÿ(#ÿ%"ÿ'&ÿ&#ÿ(%ÿ&"ÿ/#.ÿ,)ÿ."-ÿ+(ÿ1#,ÿ-!+ÿ0#.ÿ0$.ÿC;Qÿ~ˆÁÿƒ�Éÿ„ŽÈÿƒ�Çÿ„�Çÿ…�Æÿ„�Äÿ„ŒÅÿ„�Åÿ„‹Åÿ…ŒÅÿ„‹Æÿƒ‹Äÿ…‹Ãÿ…ŠÂÿ…ŠÁÿ…ŠÃÿ„ŠÅÿ„ŠÄÿ„ŠÃÿ…‰Ãÿ…‰Ãÿ„‰Ãÿ…‰ÂÿƒˆÁÿ…‰Ãÿ„ˆÂÿ„ˆÁÿ„‡Àÿ„‡Áÿ„†Àÿƒ…¿ÿƒ…¿ÿƒ„¾ÿ‚ƒ¾ÿ‚ƒ½ÿ‚�»ÿ‚‚ºÿ‚�¹ÿƒ‚¹ÿ„‚·ÿ„�¶ÿ…�¶ÿ…�µÿƒ�µÿ„€´ÿƒ�´ÿƒ€µÿƒ´ÿƒ~³ÿƒ~²ÿ‚}±ÿ‚|¯ÿ‚}¯ÿƒ|®ÿ‚|¬ÿ‚{«ÿ‚{¬ÿ�zªÿ‚zªÿƒzªÿ„zªÿƒy©ÿƒz©ÿ‚y¨ÿ‚y§ÿƒx§ÿ‚w¦ÿ‚w¥ÿ‚w¥ÿ�w¤ÿ�v¤ÿ�u¤ÿ€v£ÿ�u£ÿ�u¢ÿ�t ÿ�t ÿ‚tŸÿ€tžÿ�tžÿoªþÿoªþÿo¬þÿo­þÿn«ýÿoªÿÿp§þÿp¥ýÿq¤þÿq¤þÿq¢üÿr¤ýÿr¢üÿr üÿr ûÿržúÿqžùÿsœ÷ÿt›õÿvšòÿvšðÿv›ðÿvšîÿwšîÿw™íÿw™ìÿvšîÿv™íÿv™ìÿw™íÿwšíÿw˜ìÿx™ìÿw˜ìÿvšîÿu›óÿuœõÿvœñÿwœðÿw›ïÿwšíÿy™êÿx™ëÿy™ëÿx™ëÿyšîÿw˜îÿs¥÷ÿo´ýÿo²ûÿp¯üÿq¬ûÿs¨ûÿs§ùÿs¬ûÿq¬üÿp­þÿr­ýÿrªûÿr¦úÿt£÷ÿu¡õÿu ôÿu óÿu¡ôÿv¡õÿu¡÷ÿt£øÿs¤ùÿs©úÿr«ýÿr«ýÿr©üÿr¨üÿr¦ýÿr¦üÿs¤üÿs£üÿs¡ýÿs¡üÿošóÿEDiÿ1&3ÿ,!)ÿ("ÿ.!)ÿ("ÿ- +ÿ-!'ÿ9,8ÿ)'ÿ,'ÿ'$ÿ, (ÿ&!ÿ'"ÿ( ÿ&ÿ)#ÿ$ÿ*&ÿ)"ÿ("ÿ+!'ÿ( ÿ-#+ÿ,&ÿ*%ÿ*%ÿ-!)ÿ8+6ÿ0%-ÿ+$ÿ- 'ÿ+$ÿ+%ÿ,'ÿ,&ÿ3&1ÿvz¬ÿ„ŽÇÿƒŒÅÿ„ŒÅÿƒŒÅÿƒŒÃÿ„‹Äÿƒ‹Áÿ„‹Âÿ†‹Âÿ…ŠÁÿ…ŠÀÿ…ŠÀÿ„‰¿ÿ…‰¿ÿ…‰¾ÿ…‰¾ÿ„‰½ÿ„‰¾ÿ„ˆ½ÿ„ˆ½ÿ„ˆ¾ÿ„ˆ½ÿ„‡½ÿ„†½ÿ„‡¾ÿƒ†½ÿƒ†½ÿ‚‡½ÿƒ†¾ÿƒ…¾ÿƒ…¿ÿ‚…¾ÿƒ„¾ÿ‚ƒ½ÿ‚‚¼ÿ�‚»ÿ‚‚»ÿ‚‚¹ÿƒ�¹ÿ‚�¸ÿ‚�·ÿƒ€·ÿƒ�·ÿ‚�µÿ�€µÿ‚€¶ÿ‚µÿ�~´ÿ‚~³ÿ�~±ÿ�}±ÿ�{°ÿ�|°ÿ€|¯ÿ�{®ÿ�|­ÿ‚{­ÿ�{¬ÿ‚z¬ÿ‚z«ÿ‚z«ÿ‚y«ÿ‚yªÿ‚yªÿ�x©ÿ‚x¨ÿ‚x¨ÿ‚x§ÿ€w¦ÿ‚w¦ÿ�w¦ÿ�w¦ÿ�v¦ÿ�v¥ÿ€u£ÿ€u¤ÿ€u¢ÿ€t¡ÿ€t¡ÿ�t ÿoªýÿoªþÿo«ýÿn­þÿn¯ýÿn±ÿÿn±þÿn°ýÿo¬þÿn«ýÿn¨ýÿn¦þÿp¥þÿo¢ýÿp¡þÿp¡ýÿq üÿpžúÿržúÿqžùÿqŸúÿr¡úÿq ùÿr úÿr¡ùÿq¡øÿq øÿq¡úÿq úÿr ûÿq¢üÿr£ûÿr¢úÿq¢ûÿq¢üÿr¥ýÿq£ýÿp£üÿq¤ýÿr¡üÿs ûÿsŸùÿtœöÿu›ñÿvšïÿw™ðÿx˜ìÿw—êÿwšîÿw˜ëÿw–éÿx•èÿx•æÿx•æÿw–êÿv˜îÿvšñÿu˜ðÿw˜ïÿw–ëÿy•èÿx•åÿy”åÿz”ãÿz’âÿ{“áÿz“âÿz”âÿz“âÿy”äÿy•çÿx—éÿx–èÿw–èÿx–èÿx–êÿx–êÿx–ìÿw˜íÿx™ïÿcu¶ÿ4'6ÿ* +ÿ7)6ÿ-$.ÿ9-;ÿ5+:ÿ2&1ÿ-"+ÿ;.<ÿÿ3(3ÿ0(5ÿ:/>ÿ&ÿ:,5ÿ5$+ÿ3$(ÿA7KÿG@Yÿ<.?ÿ=3Eÿ3%1ÿD=Uÿ@5Iÿ/$.ÿ7+5ÿ:/?ÿ9*6ÿ4+8ÿ;/=ÿ7)4ÿ.!)ÿ&ÿ4'1ÿ2$1ÿ8+7ÿ2&3ÿ,%ÿG=Tÿ…�ÊÿƒŠÄÿ‚ŠÃÿƒŠÂÿ‚‰Áÿ„‰Áÿƒ‰Àÿ„‰Àÿ„‰¿ÿ„‰¾ÿ„‰¾ÿ…ˆ¾ÿ„ˆ½ÿ„ˆ½ÿ„‡¼ÿ„†»ÿ‚†¹ÿ‚„¹ÿ�…¹ÿ�…¸ÿƒ…¹ÿ‚„¸ÿ‚ƒ¸ÿ‚„¸ÿ‚ƒ·ÿ‚ƒ¶ÿ�ƒ·ÿ�ƒ¸ÿ€„¶ÿ�‚·ÿ‚‚¶ÿ�‚¶ÿ‚‚¶ÿ‚‚´ÿ‚€´ÿƒ€´ÿ‚€µÿ‚€´ÿ�³ÿ�³ÿ�³ÿ‚³ÿ‚²ÿ�±ÿ�~²ÿ�~²ÿ€~±ÿ�}±ÿ�|°ÿ€|®ÿ�|®ÿ�|®ÿ€{­ÿ€z­ÿz­ÿ€{¬ÿ€z«ÿ�z«ÿ�zªÿ�y©ÿ‚yªÿ�x©ÿ�x¨ÿ�x©ÿ�x¨ÿ�w§ÿ�w§ÿw§ÿ�w¦ÿ�w¦ÿ�w¦ÿ€v¥ÿ€v¦ÿ�v¦ÿu¤ÿ€v¤ÿ€u¥ÿ€u£ÿ�t£ÿ�t¢ÿo¤þÿo£þÿn£ýÿo£ýÿo£þÿn£þÿo£þÿn¤þÿn¥þÿn¥þÿn¤þÿn¤þÿo£þÿo£þÿo¢þÿp£þÿp¢ýÿo¢ýÿp¢ýÿq¡ýÿp¢üÿp£ýÿp£þÿp£ýÿp¤þÿp¦þÿo¦þÿp¦þÿo¦þÿo¥þÿo¥ýÿp£ýÿo£ýÿo üÿq üÿqŸûÿr�øÿr�÷ÿr�öÿs›òÿt›óÿuœõÿs›óÿt›óÿušðÿušîÿušðÿu˜ðÿs™óÿt›óÿt™îÿv™íÿv˜íÿv˜íÿw—ìÿw—êÿw–ëÿv•êÿw•éÿw”æÿw“äÿw’âÿx‘áÿx’áÿy‘àÿz‘àÿy‘ßÿy‘Ýÿy�Ýÿy�Üÿy�Üÿz�Üÿz�Üÿy�Ûÿz�Üÿz�Üÿz�Üÿy�Ýÿz�àÿ{’âÿD5Nÿ3#1ÿ>/Cÿ3%1ÿ8)5ÿ6+;ÿ8-;ÿ3%2ÿÿ/ (ÿH2?ÿ7'.ÿG6BÿHE^ÿE;SÿH=Uÿ2)5ÿ>2Aÿ?5Hÿ>1Dÿ@7Gÿ=3Dÿÿ=.<ÿ@2Bÿ7)2ÿ@2@ÿB3Dÿ5)4ÿ8+5ÿ8*7ÿA4Eÿ9,:ÿ8*5ÿ:.:ÿ;/=ÿ>/>ÿ<.<ÿB6Hÿ?,<ÿC2BÿB2>ÿ>.<ÿ@1@ÿA5Eÿ:-7ÿ=/>ÿ4&1ÿ?1?ÿ6(1ÿB3BÿC2Aÿ7(2ÿ;/:ÿ9+7ÿ;,8ÿ<,8ÿ=,9ÿ<,9ÿA5Hÿ€ƒ¸ÿ‚†½ÿ„ˆ¾ÿ{¨ÿue„ÿlN\ÿykŒÿƒ…½ÿƒ„»ÿ‚ƒºÿ‚�ºÿ‚‚¹ÿ��¹ÿ��·ÿ��·ÿ€�·ÿ€€¶ÿ€�¶ÿ€�´ÿ�´ÿ€€´ÿ�´ÿ‚²ÿ�²ÿ~±ÿ€~±ÿ~¯ÿ~¯ÿ€~¯ÿ�}¯ÿ�|®ÿ�|®ÿ€|­ÿ€|®ÿ€|­ÿ‚|­ÿ�|­ÿ€|­ÿ�|­ÿ€|­ÿ�|¬ÿ�|¬ÿ�|«ÿ�{«ÿ€{©ÿ€z©ÿ€z©ÿ€y¨ÿ�y¨ÿ€y§ÿ€y§ÿ€x¦ÿ�x¦ÿ€x§ÿ€x§ÿx¦ÿ€x¦ÿ€x¦ÿx¥ÿx¥ÿ€w¥ÿ€w¥ÿ€w¥ÿ€w¤ÿ€w¥ÿ€v¤ÿ€w¤ÿv¤ÿ€u£ÿu£ÿu£ÿv¤ÿ€u¤ÿu¤ÿv¥ÿv¥ÿv¥ÿ€w§ÿ�w©ÿlÇýÿlÅþÿnÂþÿn¿þÿn½þÿn¼þÿm»ýÿl¹þÿl¸þÿm¸þÿl¹ýÿm¹þÿm¹þÿl¸ýÿl¹þÿlºþÿl»ýÿm¼þÿm¼þÿl¾ýÿm¾þÿm¾þÿl¾ýÿm½þÿn»þÿmºýÿm°üÿn«üÿn°ýÿnªüÿpŸõÿp¡÷ÿs˜êÿxŽÙÿ{ˆÈÿu–ãÿršìÿm§ÿÿo£þÿn¢ýÿm¡þÿn ýÿnŸýÿm ýÿnŸüÿn üÿn¡üÿm£üÿn¢ûÿo¡ûÿo úÿoŸúÿn ùÿo¡ùÿp¡ùÿo öÿp�õÿpšôÿq—òÿr•ïÿs”ìÿs’êÿs‘èÿt�çÿu�æÿs�äÿu�äÿuŽâÿt�àÿvŒÞÿvŒÝÿv‹Ûÿw‹ÚÿwŠØÿwŠ×ÿw‹ÕÿwŠÕÿwŠÓÿq}½ÿA2Hÿ:,;ÿ:-8ÿ7(3ÿ=/;ÿ5)3ÿ<-:ÿ9+7ÿ5(3ÿ&"ÿ$ÿ%ÿ,%4ÿ8-<ÿ3$/ÿ8)4ÿ7*5ÿ3'1ÿ6)4ÿ3&0ÿ3%1ÿ8(6ÿ6(1ÿ7)5ÿ5'3ÿ3&0ÿ;.<ÿ7)3ÿ3%.ÿPNjÿA9MÿF>Rÿ#ÿ/#+ÿ;,8ÿ:,8ÿ9+8ÿ:,9ÿ<-8ÿ8,6ÿ=.:ÿ<.:ÿda…ÿ„„¼ÿ…†¾ÿzjŠÿjNWÿnR_ÿu`vÿ„…¼ÿƒ„ºÿƒ‚ºÿƒ‚¹ÿƒ�¹ÿ�€¸ÿ�€¸ÿ€�·ÿ�€·ÿ�€·ÿ�€´ÿ�€´ÿ‚€´ÿ€~³ÿ€~²ÿ�~²ÿ�~±ÿ�}°ÿ�}°ÿ€}¯ÿ|®ÿ€{®ÿ�{®ÿ€|­ÿ€|­ÿ€{­ÿ�|¬ÿ�{¬ÿ‚{¬ÿ�{ªÿ‚{«ÿ�{ªÿ‚zªÿ�{ªÿ‚z©ÿ�z©ÿ�z©ÿ�z©ÿ€z§ÿx§ÿ�x§ÿ�y¨ÿ€y¦ÿ�y§ÿy¦ÿ€y¦ÿ€x¦ÿ€w¤ÿ€x¥ÿ€x¥ÿ�w¤ÿ€w¤ÿ€w£ÿ€w¢ÿ€w¢ÿv¡ÿv¡ÿ~v¢ÿ€w£ÿv¢ÿ~u¡ÿv¢ÿu£ÿu¢ÿ€v¤ÿ€v¥ÿ€v¥ÿ€w¦ÿ€w§ÿ€w§ÿxj’ÿq_€ÿmÈÿÿkÇÿÿlÆþÿlÆþÿlÄþÿlÃþÿlÁþÿmÁþÿm¿þÿn½þÿm»þÿl¹þÿl·þÿm·þÿn·ýÿm·þÿm¶þÿl´þÿl³þÿm±þÿl°ÿÿl¯þÿk¬þÿk¬þÿk¬ýÿk®ÿÿn£öÿn›ïÿmŸ÷ÿmœóÿn¥ýÿm©þÿm¦þÿyˆÆÿ|„¾ÿ}ƒ½ÿ~}±ÿu˜Ýÿn±úÿnµþÿn´þÿn²ýÿo±þÿo­ýÿmªþÿnªýÿn©ýÿoªýÿn«ýÿm¨ýÿn§ýÿm¨ýÿm§þÿm§þÿm§þÿm¦þÿm£üÿm ùÿmŸùÿnŸøÿo�öÿoœöÿp›õÿo˜óÿp—ñÿq•ïÿq“ìÿq“ìÿr“ëÿs’êÿs�éÿs�çÿt�æÿtŽäÿt�ãÿtŽâÿtŒàÿtŒßÿY\Œÿ8+7ÿ/!+ÿ- (ÿ5'2ÿ-!*ÿ."+ÿ-*ÿB3Dÿ<.<ÿÿ'#ÿ=2Gÿ?/>ÿ>3Iÿ:*6ÿ7(2ÿ7)6ÿ7(5ÿ3$-ÿ0#-ÿ1$/ÿ2'1ÿ3&/ÿ5)6ÿ8+8ÿ>/=ÿ;-;ÿ5&/ÿ8*6ÿC0=ÿSIbÿb[}ÿ€‚·ÿ<-7ÿE5Dÿ(#ÿ!ÿ$ ÿ-&ÿ"ÿ!ÿ)%ÿI>Tÿ€¶ÿ‡ˆ¿ÿ}n�ÿnQ\ÿrU`ÿx`wÿ†…»ÿ…„»ÿ…ƒ¹ÿ…‚¸ÿ…�¶ÿ„�¶ÿƒ�·ÿ‚€¶ÿ‚€µÿƒ€µÿ„€´ÿƒ³ÿ‚~³ÿ€~³ÿ�~³ÿ‚~³ÿ�}±ÿ�}±ÿ‚|±ÿ€{¯ÿ€|¯ÿ�{®ÿ�{®ÿ�{®ÿ‚{­ÿ�|­ÿ‚{­ÿ‚{¬ÿ‚{¬ÿƒ|«ÿ�{«ÿ‚{ªÿƒ{ªÿƒz©ÿ‚z©ÿƒz©ÿ�z©ÿ‚z¨ÿ�z¨ÿ�y¨ÿ‚y¨ÿ�x§ÿ�x§ÿ�x§ÿ�x¦ÿ�x§ÿ€y¦ÿ�x¦ÿ�y¦ÿ€x¥ÿ€w¥ÿ€x¤ÿ€w¥ÿ€w¤ÿ€w¤ÿv¤ÿ€w¤ÿ€v£ÿu¢ÿv£ÿv£ÿu£ÿ€v£ÿ€v£ÿ€v£ÿ�v¤ÿ�v¤ÿ€v¥ÿ‚w¥ÿ|o—ÿcJ[ÿ`FSÿh®ýÿh­þÿg¬þÿgªþÿh«þÿh«þÿhªþÿh©þÿi§þÿi§þÿi¨þÿh§þÿh§þÿh¦þÿi¦þÿi¥þÿg¥þÿh£þÿi¢ýÿi¡ýÿi üÿi ûÿi üÿi¡ýÿi£þÿi¥ýÿj¥þÿj£ýÿj¡úÿj úÿjžøÿj ùÿjŸúÿn•ìÿw†Èÿ~x¡ÿw�ÿ€s”ÿy‚¸ÿk©øÿk®ÿÿk¯ÿÿl°þÿl°þÿk±þÿk°þÿk±þÿl°þÿl¯ýÿl®ýÿl­ýÿl¬ýÿl«ýÿl«ýÿlªüÿkªýÿj©üÿk¨üÿj¥üÿj¤üÿk£þÿk£ýÿk¢ýÿj¡ýÿk ÿÿk�ûÿlšöÿm˜ôÿm—õÿl–ôÿm—óÿl•óÿn–òÿm—ôÿn—óÿn–òÿo•òÿiˆÝÿ<4Mÿ($ÿ$#ÿ!ÿ%'ÿ'!/ÿ"ÿ& ÿ?1@ÿ('ÿ2%0ÿ:-;ÿE9QÿE9Qÿ;/@ÿ2#-ÿ(!ÿÿ&ÿ. %ÿ=2?ÿSPqÿ[Y}ÿ[Z}ÿVTvÿNJgÿC=Sÿ=5Eÿ9-;ÿ3%/ÿ6*4ÿ:,9ÿ=,=ÿWKeÿ, 'ÿ=.;ÿ,&ÿ!ÿÿÿ$ÿÿ(!ÿ*%ÿf[ÿ‚z£ÿzfÿnQ[ÿqS]ÿtXfÿwe‚ÿ{n“ÿxi‹ÿyiŠÿue�ÿue�ÿvdÿta}ÿsb}ÿwf„ÿvf…ÿud‚ÿr`zÿ|s�ÿ‚~°ÿ‚}¯ÿ‚|¯ÿ�|®ÿ‚{­ÿ�|­ÿ�{­ÿ�|­ÿ�{¬ÿ‚{¬ÿ‚{­ÿƒ{¬ÿƒz«ÿƒ{¬ÿ‚z©ÿym•ÿwl‘ÿym“ÿ{p—ÿƒ{©ÿ}sŸÿ~tžÿ�x¨ÿ‚y¨ÿ‚y§ÿ�y¦ÿ�x§ÿ‚x¦ÿ�x¦ÿ‚x¦ÿ�x¦ÿ�y¦ÿ�x¦ÿ�z¨ÿ‚z¨ÿ€w¦ÿ‚x¦ÿ€x¥ÿ�w¤ÿ€w£ÿ€w¤ÿ�w¤ÿ€x¥ÿw¤ÿ€v£ÿ�v£ÿt ÿ|o˜ÿ€t¡ÿ‚w¥ÿ‚w¥ÿ‚x¤ÿ‚v¢ÿ�uŸÿp˜ÿ}m“ÿgO`ÿeKWÿežýÿe þÿe ÿÿežÿÿf�ÿÿfœýÿg›ûÿgšùÿfšüÿg›ûÿh–÷ÿh–÷ÿg•÷ÿf—ùÿg–øÿg”öÿg“óÿi“ñÿh’ñÿi’òÿh’ñÿh“òÿi”ôÿi“ôÿi”óÿi”ôÿi”ôÿj“òÿj�ïÿl�êÿp…ÔÿkŒåÿkŽìÿmŒäÿzužÿ{q”ÿ~r“ÿ}p’ÿ}p’ÿw‚Àÿk•öÿk”óÿk”óÿk”òÿk•òÿm•óÿl”óÿk•òÿl•óÿl•òÿl•òÿm•óÿm”ñÿl”ðÿm”ðÿm“îÿm‘íÿo‘ìÿm‘ëÿm�êÿm�éÿn�êÿn�éÿmˆÜÿjqªÿk€Íÿn�çÿnŽèÿl~ÅÿmÆÿn…ÕÿmŒãÿo‹âÿn~ÆÿoƒÌÿp„Ñÿt‰×ÿOR}ÿ.$2ÿ)$ÿ2&5ÿ, )ÿ80Iÿ/'9ÿÿ9,8ÿ6)5ÿ7+7ÿ0",ÿ>.>ÿ1$2ÿ4,Aÿ/%5ÿ!ÿ>,1ÿUÿ-0Aÿ,/@ÿ+,;ÿ04FÿMPsÿ\_Œÿon¡ÿsf‰ÿqa|ÿuf†ÿu`wÿ}w¬ÿl\uÿq`}ÿlZwÿvp¢ÿvm“ÿfVoÿm]|ÿp`{ÿhXnÿcOcÿdZyÿfZyÿmdŠÿiYsÿi\~ÿsk–ÿbZ|ÿ_Lbÿh`†ÿlg‘ÿgXvÿYF`ÿWEZÿ_K_ÿcOcÿeRiÿj\wÿoa…ÿfQbÿkVhÿiTfÿo[oÿeObÿs\lÿq[lÿn[qÿr_~ÿnWlÿmVfÿkRcÿ_F[ÿeSmÿgSkÿfRcÿgRbÿbO`ÿ;,8ÿ3%.ÿ3%.ÿ:*4ÿ*'ÿ+3ÿ'(ÿ* 'ÿ8,7ÿ<.;ÿ#ÿÿ ÿB17ÿmTbÿr[nÿqZnÿjO^ÿiNZÿgLUÿeHQÿhKUÿjNZÿnTbÿnTbÿjO\ÿtZiÿqWfÿZ>DÿY=CÿhPYÿqZhÿwarÿpWgÿlQ]ÿrXfÿ`ISÿ%ÿ9,7ÿ:,7ÿ4'0ÿ'!ÿ+"ÿ2#'ÿ+$ÿ#ÿ2$*ÿ:*2ÿN;HÿjQ_ÿ^DKÿlQ\ÿpVcÿmQ[ÿlQ[ÿt[hÿjP]ÿrWfÿrWcÿgKTÿfJRÿiMVÿoUaÿhMXÿfOZÿgOYÿfOZÿbITÿ\ANÿZ@IÿZBKÿV?Lÿ\DPÿR;IÿL6DÿQ:BÿQ9BÿN8?ÿ\KXÿK7AÿU?KÿS=IÿT?Nÿ^M_ÿL=FÿbJSÿY?CÿZ@HÿZAKÿ`EQÿlSdÿnT_ÿWBOÿK6DÿO:HÿN8DÿQ>LÿI5DÿQ;HÿaHSÿiO]ÿH3=ÿB,5ÿ>*2ÿH8DÿG7CÿH7CÿXAKÿSMÿ;7Iÿ/0?ÿ&(/ÿ$")ÿ#!)ÿ#")ÿ$%/ÿ+-:ÿ#"*ÿ%!(ÿ&%.ÿ''/ÿK:Fÿ_K\ÿTATÿ`MaÿP:KÿI7HÿC0=ÿUGcÿ>/AÿA/@ÿM9LÿO)2ÿ@*1ÿD-4ÿ?).ÿD.7ÿ@.8ÿ;)4ÿI6DÿN8FÿP;IÿP;KÿK7GÿNÿnZlÿfRbÿo[mÿs]nÿiTdÿeQ_ÿbLXÿaFQÿbHUÿeMZÿbKXÿaIWÿiN_ÿdKXÿX@FÿT=EÿM6:ÿ]DKÿkR_ÿcM[ÿ\TjÿeO^ÿi[tÿWn–ÿTUmÿ!ÿ6(3ÿD5Cÿ2&,ÿ*!ÿ'ÿ."(ÿ, &ÿ%ÿ0!(ÿ;+9ÿeM^ÿ_DMÿ_FPÿ_DMÿ_EQÿ_ENÿdKUÿbHUÿaGSÿ]CMÿZAKÿT=DÿG58ÿ`KUÿ^FPÿ]ERÿ^LZÿ`P]ÿZFSÿ_N`ÿVBTÿS@QÿYFUÿYCOÿ`M^ÿWCQÿP6AÿG/6ÿZHVÿWDTÿQ=GÿU>IÿUCTÿ6-8ÿ &ÿ!!(ÿ73>ÿ,(2ÿ<1=ÿM9FÿR;EÿRGÿO>NÿI8HÿD0<ÿG2>ÿ?,2ÿ>)2ÿN8@ÿSÿL8BÿH4=ÿJ7AÿJ7BÿM9FÿS>KÿVAOÿS?OÿP;KÿR=KÿK5AÿQ=Iÿ:/<ÿ1*7ÿ+&2ÿ$!+ÿ&ÿ$)ÿ8/=ÿWHXÿZIZÿZHYÿYGXÿYG[ÿVCUÿWDRÿWCPÿTCÿS;AÿT;?ÿS7<ÿP5:ÿQ;Bÿ)!ÿ9*6ÿ6(2ÿ!ÿ%ÿ'!ÿ*%ÿ'$ÿ5'0ÿL9HÿD2@ÿYDQÿaN\ÿRDSÿSETÿJÿK8EÿI:FÿI7DÿF2=ÿD2>ÿJ:IÿO>LÿM9Iÿ>:Kÿ=:Hÿ?:Hÿ94Bÿ&",ÿÿÿÿÿÿ$&ÿ;.;ÿ[GXÿSMÿTEXÿeUlÿdQdÿcIUÿjP]ÿtXfÿmR`ÿ[BPÿP9EÿN9DÿO9CÿP:CÿO9CÿN7AÿK4=ÿO:GÿL8CÿL7CÿO:EÿM5@ÿN8AÿN9CÿPKÿR>JÿT?Jÿ=0<ÿ# ÿA3Aÿ!ÿÿ'ÿ-!&ÿ, (ÿ+%ÿO=Iÿ8)3ÿ=2?ÿ4.9ÿ/-:ÿ//;ÿ.,7ÿ1-8ÿ=6Dÿ60<ÿ($-ÿ'%-ÿ# 'ÿ'"*ÿ,'-ÿ+&*ÿ,%+ÿ0).ÿ-)/ÿ&!&ÿ "ÿÿ$ÿ"!)ÿ'&.ÿ..9ÿ/2>ÿ-5Aÿ,/;ÿ-.;ÿ'(1ÿ=5BÿJ9EÿTERÿ,(0ÿ %ÿÿÿÿ ÿÿ<18ÿB7BÿKBQÿ4,;ÿ'",ÿ"$ÿ9-9ÿ=2@ÿJ=MÿM;IÿJ:HÿH=OÿRJ`ÿODXÿD3;ÿE5@ÿ7/;ÿ*)/ÿ"$,ÿ %3ÿ$3ÿ+ÿ+ÿ+ÿ%ÿ&ÿÿÿ ÿ ÿ#$ÿ.&0ÿB4EÿE6FÿE9Hÿ$,:ÿ'0Bÿ'4Eÿ(2Cÿ!%.ÿ%ÿ#'0ÿ $.ÿ"%.ÿ*)3ÿ3*5ÿ&%ÿ%%ÿ!ÿ#"ÿ"!ÿ"#ÿ!ÿ "ÿ#$ÿ"!(ÿ$#*ÿ %ÿ)$.ÿ6-<ÿD5EÿE6DÿB2AÿJ9IÿQ>Pÿ>5Bÿ(%*ÿ*&.ÿ)&,ÿ(%*ÿ&#)ÿ$&ÿ"#ÿ#'ÿ)&0ÿ1-6ÿ>08ÿ5%,ÿ3%,ÿ4(1ÿ@2?ÿD5CÿD4DÿC3DÿK9GÿP>MÿE:Gÿ44@ÿ.0<ÿ//:ÿ--8ÿ')6ÿ!!-ÿ#ÿ  ÿÿ ÿÿÿÿÿ4-8ÿI:LÿJ5BÿPCRÿRI`ÿCB[ÿ<8Lÿ>6Kÿ6(1ÿ4$/ÿ/ (ÿ6(2ÿ1#,ÿ+%ÿ'!ÿ9-8ÿ5)3ÿ!ÿÿÿ0(+ÿ;27ÿ9.5ÿL8EÿO8Bÿ>06ÿJ6AÿVAOÿH8JÿI4Aÿ<1?ÿH=OÿPDYÿYJ^ÿUJ\ÿ;5Bÿ#ÿ(ÿ%4ÿ /ÿ+ÿ(ÿ'ÿ$ÿ#ÿ%ÿ ÿ ÿÿ  ÿ"ÿ$(ÿ/&4ÿ;1@ÿ%.ÿ&/ÿ#*4ÿ &/ÿ &/ÿ '3ÿ#)7ÿ &0ÿ"&/ÿ#(2ÿ'&/ÿ#!ÿ!ÿ!ÿ!ÿ ÿÿ! ÿ !ÿ" %ÿ%&-ÿ$&-ÿ $ÿ&#)ÿ,(2ÿ@7Dÿ*!+ÿ*!+ÿ<0<ÿ80<ÿ.*3ÿ*'-ÿ'$(ÿ" #ÿ# "ÿ$!#ÿ)#(ÿ$"ÿ"!ÿ%!&ÿ*$+ÿC4>ÿF4@ÿ>4Bÿ51?ÿ/,9ÿ0*7ÿ:.;ÿ=0Aÿ;/=ÿD4@ÿ?2;ÿ809ÿ,'-ÿ*'.ÿ(&2ÿ%$1ÿ%!,ÿ #ÿ !ÿ!#ÿ!"ÿÿÿÿÿÿ('/ÿ44@ÿ46Bÿ24Dÿ,.8ÿ51@ÿ3'3ÿ/$*ÿ+%ÿ*&ÿ,!)ÿ, 'ÿ"ÿ#ÿ9.:ÿ#ÿ$ ÿÿÿ?9Cÿ829ÿ4',ÿ8/:ÿ1%+ÿ, ÿ/$)ÿ50?ÿ74Gÿ<9Mÿ=5Eÿ:1;ÿ907ÿK>KÿWEVÿR?NÿK7EÿS@NÿSBQÿR>LÿN;GÿM;IÿVEVÿQCTÿ>6Bÿ:5Bÿ>9Hÿ?=Kÿ509ÿ.##ÿ,#(ÿÿ8+7ÿ!ÿÿ,"'ÿ'"ÿ("ÿ*$ÿ(#+ÿ%(ÿ$ ,ÿ'ÿ&ÿ#(ÿ+$*ÿ,$*ÿ'!'ÿÿÿ!ÿ #ÿ 'ÿ"*ÿ$,ÿ$ +ÿ ÿÿÿÿÿ !ÿ ÿÿÿÿÿ! ÿ#"&ÿ #ÿ53<ÿ('-ÿ!ÿÿÿÿ ÿ !#ÿ "ÿÿÿ"$ÿ!%ÿÿÿ !ÿÿ!"ÿ%$.ÿ,,:ÿ43Cÿ@:LÿI>NÿE?NÿB=Kÿ54Bÿ"$-ÿ".ÿ"1ÿ)ÿ&ÿ&ÿ%ÿ%ÿ$ÿ#ÿÿÿ ÿÿ"ÿ"ÿ $ÿ&)ÿ!&ÿÿ"ÿÿ"ÿ"ÿ %ÿÿ$ÿ'ÿ$*ÿ$ 'ÿ ÿ"ÿ"ÿ ÿÿÿÿ ÿ!ÿ##*ÿ"",ÿ%#,ÿ#!'ÿ($)ÿ$#ÿ$"ÿ.$1ÿ*)3ÿ*&,ÿ$"&ÿ""ÿ ÿÿ# ÿ% "ÿ'"$ÿ#!ÿ%%ÿ&#)ÿ85Cÿ65Hÿ+0@ÿ*,;ÿ)&3ÿ)'0ÿ*%+ÿ,&,ÿ*&-ÿ-(0ÿ-'0ÿ-&-ÿ,&+ÿ% 'ÿ"*ÿ&ÿ#ÿÿÿ $ÿ #ÿ!ÿÿÿ ÿÿÿ/09ÿ00=ÿ-,8ÿ&%.ÿ/*4ÿ.&0ÿ0%*ÿ ÿ.!*ÿ"ÿ&ÿ,%ÿ3'/ÿ1%/ÿ ÿÿÿ,(.ÿ2/6ÿ-&*ÿ*$'ÿ1-5ÿ119ÿ1/7ÿ0-5ÿ21>ÿ3/<ÿ.'-ÿ/(,ÿ2*/ÿ3*.ÿQ>IÿqWaÿfLVÿP;Cÿ[GSÿbLZÿeRZÿW@JÿQÿ20<ÿ22>ÿ13>ÿ36Bÿ/1;ÿ1/:ÿÿ,!(ÿ9*4ÿ* %ÿ#ÿ'#ÿ,")ÿ$"ÿ"ÿ"ÿÿÿÿÿ!%ÿ&&ÿ ÿÿÿÿÿ ÿÿ  ÿ#ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ "ÿÿÿÿÿÿÿÿÿÿ!ÿ !ÿÿÿÿÿ"ÿ&ÿ$%1ÿ&'3ÿ+.?ÿ*0Aÿ#(7ÿ$&/ÿ!#,ÿ%ÿ)ÿ!.ÿ)ÿ'ÿ$ÿ$ÿ!ÿ ÿÿÿÿÿÿÿÿ "ÿ#&ÿÿÿÿÿÿ#ÿ%ÿ ÿÿÿ!ÿ $*ÿ ÿ ÿ!ÿ!ÿ ÿ ÿ !ÿÿ !ÿ! )ÿ%ÿ &ÿ$ÿ$"(ÿ"#ÿ$!-ÿ*-Dÿ%):ÿ"$ÿ!ÿ ÿ!ÿÿÿ ÿ$!ÿ'!%ÿ'%.ÿ&-=ÿ"(6ÿ $2ÿ!%2ÿ$'5ÿ%",ÿ&$.ÿ'"*ÿ( (ÿ)$,ÿ)&0ÿ)%.ÿ*$.ÿ+&.ÿ%"*ÿ 'ÿ#ÿ#%ÿ!"ÿ "ÿ"ÿ ÿÿÿÿÿÿÿ))3ÿ&'3ÿ +ÿ )ÿ%ÿ!#ÿ$ ÿ*$ÿ-!'ÿ&ÿ'ÿ;,7ÿC4Cÿ$ÿÿÿÿ*$*ÿ+&0ÿ)$+ÿ+'.ÿ--5ÿ,.6ÿ,.8ÿ,*7ÿ)&-ÿ(!$ÿ+"%ÿ.%*ÿ2'-ÿ@3=ÿ[K^ÿP@JÿC6:ÿLAHÿG=FÿK@JÿK@GÿKBGÿG?DÿB69ÿ^N`ÿA6Aÿ1,7ÿ+)0ÿ+*1ÿ((1ÿ(+3ÿ$"#ÿ$ ÿÿ;.9ÿ3'0ÿ% ÿ#ÿÿ!ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ "ÿÿÿÿÿ#ÿ *ÿ!)ÿ"+ÿ (7ÿ!,ÿ$3ÿ $.ÿ&ÿ'ÿ +ÿ*ÿ'ÿ%ÿ(ÿ(ÿ'ÿ$ÿÿÿÿÿÿÿ "ÿ$&ÿ"$ÿÿÿÿÿÿÿÿÿÿÿÿ!#ÿ!ÿ ÿ"ÿÿÿ#$+ÿ%&/ÿ $ÿ$ÿ" ,ÿ!(ÿ &ÿ#$4ÿ!%5ÿ "/ÿ"%3ÿ"&5ÿ .ÿ#"+ÿ  ÿÿÿÿÿÿ"#ÿ!$ÿ&*7ÿ"+ÿ%$/ÿ"",ÿ )ÿ%&0ÿ%!+ÿ% (ÿ'#,ÿ'#+ÿ&'1ÿ(*6ÿ''3ÿ'&1ÿ%%0ÿ )ÿ %ÿ#&ÿÿÿÿÿÿ  ÿ%#%ÿÿÿÿÿ (ÿ *ÿ#ÿ ÿÿÿÿ&"ÿ"ÿ'!ÿ&ÿ;-7ÿ6(4ÿÿÿÿÿ,*2ÿ**5ÿ*)4ÿ)'1ÿ('0ÿ)(0ÿ$"(ÿ$%ÿ$ ÿ&"ÿ*!#ÿ9,5ÿH9JÿREWÿ<17ÿ835ÿ>>Cÿ=>Cÿ@?Gÿ??Gÿ?>Eÿ>?Dÿ@@Fÿ6./ÿTGZÿI=Mÿ.)1ÿ!ÿÿ!!ÿ$$+ÿ$"(ÿ&!%ÿÿ#ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ!ÿ!+ÿ'ÿÿÿ!ÿ#ÿÿÿÿ)ÿ*ÿ'ÿ (ÿÿÿ"ÿ*ÿ'ÿ&ÿ!,ÿ",ÿ#*ÿ"ÿÿÿÿÿÿÿ !ÿ  ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿ!ÿÿÿ! ÿ$ 2ÿ!"3ÿ&-Aÿ#*=ÿ#"6ÿ! -ÿ! /ÿ%'9ÿ#'8ÿ$2ÿ#/ÿ!$2ÿ$/ÿ'ÿ'ÿ ÿÿÿÿÿÿÿ"&-ÿ "*ÿ"ÿ"ÿ$ÿ$ÿ"")ÿ%#)ÿ&#)ÿ'%.ÿ&'1ÿ%&0ÿ"#-ÿ )ÿ!#-ÿ !+ÿ&ÿ$ÿÿÿÿÿÿÿ ÿÿÿÿÿÿ!ÿ"ÿÿÿÿÿÿ$"ÿ)&ÿÿ'!ÿ6'1ÿ)%ÿÿÿÿ#!ÿ%!$ÿÿÿÿÿÿ! ÿ! ÿ# ÿ/')ÿ1&&ÿD7AÿSFZÿE9Cÿ@<@ÿ>=Cÿ?KÿL@Nÿ1)1ÿ%#(ÿ $ÿ0',ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ#0ÿ'ÿ!*ÿ(ÿ ÿ!ÿ#ÿÿÿÿÿ'ÿ&ÿ$ÿÿÿÿ(ÿ%ÿ(ÿ#+ÿ$ÿ!ÿ"(ÿ&.ÿ$ÿÿÿ ÿ#$6ÿ +ÿ"ÿ!ÿÿÿÿÿÿÿÿÿ"ÿÿ#ÿÿÿÿÿ!$ÿ!ÿ(ÿ!&7ÿ (9ÿ!2ÿ$%:ÿ#$4ÿ"&6ÿ &5ÿ$0ÿ#.ÿ #/ÿ""1ÿ-ÿ+ÿ!)ÿÿÿÿÿÿÿ!#(ÿ$ÿ ÿÿÿÿ !ÿ "ÿ$ %ÿ%#+ÿ$&/ÿ%ÿ$$ÿ $ÿ%ÿ%ÿ&ÿ"ÿÿÿÿÿÿÿÿ"!$ÿ#"&ÿÿÿÿÿ $ÿ! %ÿÿÿÿÿ#ÿÿÿ3%.ÿ6)3ÿ"ÿÿÿÿ"ÿ%#ÿÿÿÿÿÿ ÿ( 'ÿ4(1ÿI;GÿRAPÿ=/4ÿ*"!ÿ610ÿ>8:ÿA;>ÿA:=ÿ@9;ÿA:>ÿA=@ÿ@>@ÿ?:>ÿ@:>ÿ,#%ÿG=FÿUFWÿI;Iÿ"$ÿÿ=3=ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ%ÿ!#*ÿ!'ÿ!$,ÿ!$,ÿ$*ÿ"&ÿ"ÿ$ÿ!ÿ ÿÿÿÿÿÿ"ÿÿÿÿÿ!*ÿ"+ÿ%.ÿ$ÿÿÿÿÿ$ÿ ÿÿ!".ÿ$7ÿ&;ÿ%8ÿ )?ÿÿÿÿÿÿÿÿÿÿÿÿ #ÿ ÿ!#ÿ!"ÿÿÿ(ÿ#1ÿ!%5ÿ%ÿ&ÿ*ÿ -ÿ!!.ÿ+ÿ "0ÿ##2ÿ%$7ÿ#"5ÿ$$4ÿ ,ÿ!*ÿ$ÿ!ÿÿ!ÿÿ! $ÿÿÿÿÿÿÿ!ÿ""ÿ%&/ÿ%(4ÿ!*ÿ 'ÿ (ÿ"/ÿ '8ÿ!)<ÿ"&9ÿ!%2ÿ &ÿÿ ÿ ÿ#%)ÿ$$(ÿ!!ÿ!!ÿ ÿÿÿ!"%ÿ"ÿ"ÿÿÿÿÿ"ÿÿ ÿ&ÿ-!)ÿ% ÿÿ*%ÿÿÿ!ÿÿ ÿ.'0ÿÿÿ*!)ÿ6*6ÿF8IÿK?Pÿ6.3ÿ&# ÿ/0/ÿ489ÿ398ÿ3:9ÿ5;;ÿ:@Bÿ;@Fÿÿ49:ÿ177ÿ#ÿ76;ÿK@RÿJ>Tÿ*#,ÿÿ?6Fÿ0(1ÿÿÿÿÿÿÿÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿ! "ÿÿ!! ÿÿ ÿ!%+ÿ "&ÿÿÿÿÿÿ ÿ"ÿ"#ÿ# %ÿ!!ÿ!"ÿ "&ÿ!ÿÿÿÿÿÿÿ"ÿÿ ÿ "ÿ"ÿÿÿÿ!ÿ!"ÿÿÿÿÿ ÿÿÿÿÿÿ %ÿ!(ÿÿÿ ÿÿÿÿÿÿ$ÿ#,ÿ &5ÿ$5ÿ$6ÿ"3ÿ 0ÿÿÿÿÿÿÿÿÿÿÿÿ!"&ÿ""%ÿ%&+ÿ&$+ÿÿ#")ÿ%&1ÿ $.ÿ#-ÿ!'ÿ !'ÿ#ÿ$ÿ'ÿ)ÿ -ÿ$&2ÿ#&4ÿ "0ÿ!"/ÿ&ÿ&ÿÿÿ!ÿ$ÿ %ÿ #(ÿ"ÿ#ÿ!#'ÿ!"'ÿ!#ÿ !ÿ""ÿ##&ÿ"%)ÿ%ÿ!(1ÿ".@ÿ&8Vÿ#4Sÿ!2Pÿ!0Kÿ .Gÿ ,Eÿ#+Cÿ $/ÿ!"%ÿ!!#ÿ ÿÿÿÿÿÿ!"$ÿ!ÿÿÿÿÿÿÿ'!ÿÿ$ÿÿ(%ÿ) $ÿÿ@6Dÿ)"ÿ-!'ÿ ÿÿ*!)ÿ>4Cÿ,$+ÿ!ÿ8,5ÿA4Cÿ>/Bÿ.&(ÿ"ÿ-.-ÿ489ÿ7=;ÿ286ÿ389ÿ?ÿ9=?ÿ68;ÿ!ÿ236ÿ;.7ÿA3Cÿ/'0ÿ%%ÿC9JÿD8Iÿ-%/ÿ$#ÿÿÿÿÿ ÿ ÿÿÿÿRENÿXGQÿ"ÿÿÿÿÿ ÿÿÿÿÿÿÿ #ÿ"ÿÿÿÿÿÿÿÿ !ÿÿ# +ÿ 'ÿ"$0ÿ!%0ÿÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿ!ÿ")ÿ%,ÿ%-ÿÿ ÿÿÿÿÿÿ ÿÿÿ!.ÿ#1ÿ!/ÿ .ÿ*ÿ$ÿÿÿÿÿÿÿÿÿÿÿÿ"ÿÿ!!ÿ $ÿ#$(ÿ"#%ÿ!#ÿ!#ÿ"%'ÿ"$'ÿ #'ÿ#%+ÿ"#*ÿ "&ÿ!"'ÿ#%,ÿ%(0ÿ$(0ÿ"&0ÿ$(/ÿ!&,ÿ$)/ÿ$&-ÿ!ÿÿ##'ÿ#(-ÿ!'-ÿ%*ÿ "&ÿ ÿÿÿÿ !ÿ #ÿ!ÿÿ!)ÿ#)@ÿ)>ÿ(>ÿ'>ÿ';ÿ$7ÿ&9ÿ%7ÿ"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2(0ÿ4*6ÿ+%ÿ,*6ÿÿÿ."(ÿ3'0ÿ* $ÿ$ÿ7)4ÿ0#+ÿ1$)ÿ7,1ÿ<0;ÿA2Aÿ8,3ÿ*!#ÿ/')ÿ302ÿ123ÿ334ÿ223ÿ757ÿQBNÿS@PÿA:Dÿ246ÿ545ÿ512ÿ404ÿ(!#ÿ4-1ÿ9+4ÿ%ÿ0$+ÿ:-7ÿ?2>ÿ=2@ÿ-$0ÿ!ÿÿÿÿÿÿÿ,%-ÿD8DÿeTeÿhQ^ÿiQ`ÿkWgÿM?Oÿ;0=ÿÿÿ&,ÿ%.ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$ÿ'ÿ #1ÿ",ÿ ÿÿÿÿÿÿÿÿÿ)?ÿ*@ÿ(ÿÿ ÿÿÿÿ##ÿ!ÿÿÿ ÿ "ÿÿ %ÿ!+ÿ$ÿÿ ÿ ÿÿÿ ÿ ÿÿÿ ÿ ÿ&ÿ-ÿ)ÿ(ÿ#ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ "ÿ!!$ÿ "ÿ ÿ #ÿ!"#ÿ!ÿ!ÿ "&ÿ!ÿ"ÿ #ÿÿÿ !$ÿ#ÿ"&ÿ $(ÿ#&ÿ!#'ÿ""'ÿ&*2ÿ#&-ÿ!&ÿ!%ÿ ÿÿÿÿÿÿÿÿÿ#-ÿ!+Bÿ*Cÿ$7ÿ /ÿ*ÿ -ÿ 1ÿ"1ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ4-6ÿ?4@ÿ-"ÿ-5Eÿÿÿ/"&ÿ5)0ÿ)$ÿ<+5ÿA0;ÿ<,5ÿ<+2ÿ<.3ÿ;.8ÿC2?ÿF6AÿM;HÿO>KÿTDRÿVFUÿWFUÿRARÿXFTÿWDTÿWETÿUEUÿWFVÿXFWÿM;GÿVFXÿVGUÿJ:Gÿ?1;ÿ7)1ÿC2=ÿM;KÿF5Bÿ2'/ÿ' #ÿ ÿ'ÿ+"'ÿ$ÿ)#ÿ ÿ%!ÿ@4@ÿ6,6ÿ70;ÿ5+6ÿ9.<ÿ1'2ÿ8,9ÿ3)2ÿÿÿ*.ÿ$ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$ÿ!.ÿ(ÿÿÿÿÿÿÿÿ ÿ+ÿ+Dÿ(?ÿ)ÿÿÿÿÿÿ $ÿ" &ÿ"!(ÿ#ÿÿÿÿ (ÿ"ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿ-ÿ /ÿ(ÿ#ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿ ÿÿÿÿ"ÿ!ÿÿ ÿÿÿ"!$ÿ!#ÿ "ÿ !ÿ !ÿ!!$ÿ!%ÿ %ÿ!%ÿ! %ÿ #ÿÿÿÿÿÿÿÿÿÿ!%8ÿ$6ÿ#4ÿ 0ÿ&ÿ.ÿ"0ÿ.ÿ*ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿ4)/ÿ'<ÿ8>Xÿ7(4ÿ:+8ÿ=0<ÿ<.8ÿ;*6ÿG4Aÿ9)/ÿ4#'ÿ8-/ÿG]WÿF:@ÿJ8EÿO>LÿQ@NÿPAOÿOAOÿN?NÿK?Gÿuo=ÿE3BÿM=LÿM>MÿN?LÿN?MÿPANÿC1<ÿI9GÿO?MÿG8EÿH7EÿK:GÿG6BÿE4@ÿF7Dÿ/!'ÿ*ÿ+"ÿ&$ÿ'*ÿ:-8ÿ<.:ÿ/",ÿ=/6ÿ.$+ÿ*"*ÿÿ' *ÿ$&ÿÿ!#ÿÿÿÿ'/ÿ"&ÿ$&ÿ "#ÿ #%ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿ ÿ'ÿ!ÿÿÿÿÿ ÿÿÿÿ!.ÿ)ÿÿÿÿÿÿ!!ÿ&"*ÿ"$ÿ "ÿ  ÿÿÿ#ÿ ÿÿÿÿÿÿÿÿÿÿ ÿ ÿÿÿ(ÿ*ÿ#ÿÿÿÿÿÿÿÿÿÿ$ÿ)!ÿ' ÿ"ÿ#ÿÿÿÿÿÿÿÿÿÿÿÿ%ÿ )3ÿ -8ÿ ,7ÿ(1ÿ&%,ÿ#ÿÿÿ !ÿ ÿÿÿÿÿÿÿÿ  ÿÿÿÿÿ ÿ ÿÿÿ'ÿ$ÿ/ÿ(ÿÿ(ÿ!)ÿ&ÿÿÿÿÿÿ$ÿ'#ÿO?IÿUBLÿYEQÿ[GQÿ\GRÿ^IVÿMBWÿ7F`ÿ;Fdÿ86Nÿ4,;ÿ- $ÿ,!"ÿ6,/ÿR>Fÿ>,5ÿ;-7ÿ9*2ÿ;.XÿjThÿdPdÿ^O]ÿ=/<ÿ@/8ÿ=+2ÿ=,4ÿ@-5ÿ;)0ÿ>-6ÿD4>ÿB3>ÿ5'2ÿA2=ÿK9FÿC3<ÿE<5ÿ3%,ÿ3&/ÿ6)4ÿ,!(ÿD6AÿC4?ÿ1 )ÿB2<ÿ>.7ÿ:(2ÿdOcÿfPbÿQ>Lÿ)ÿN>KÿB2Bÿ4'.ÿF6Fÿ/6Xÿ)Fxÿ-G{ÿ/Evÿ32Lÿ/!&ÿ&&ÿ$(ÿ+$/ÿ+$1ÿ&)ÿ'!*ÿ ")ÿ&*ÿ"-5ÿ)0ÿ %,ÿÿÿÿÿÿ.#"ÿ$ÿ$ÿ&ÿÿÿÿÿÿÿÿ ÿÿÿÿ-!#ÿ'ÿÿ ÿ #ÿ'$*ÿ&ÿ) %ÿ&$ÿ$"ÿ ÿÿÿÿÿÿÿ!!+ÿ!&ÿÿ ÿ(")ÿ1%.ÿ"ÿÿ ÿÿÿÿÿ ÿÿ ÿ ÿ ÿ ÿ ÿ ÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿ"ÿ&ÿ.$)ÿ0',ÿ)!%ÿ ÿ!ÿÿ*!$ÿ* ÿ-#ÿ&ÿÿ1*1ÿ&.ÿ#*ÿ ÿÿ%ÿ"(ÿ&/ÿ'1ÿ#$,ÿ# %ÿÿÿÿÿÿÿÿÿ) $ÿ!ÿÿÿÿÿ.$,ÿ5,2ÿ/&+ÿ7-2ÿ:,5ÿ9)0ÿA04ÿC2:ÿ<,0ÿ@06ÿ*ÿ, %ÿ#ÿ1#)ÿ'#ÿ* 'ÿ0$*ÿXCEÿ+',ÿ10:ÿ-'0ÿ8)4ÿ@0;ÿB3@ÿ?3Bÿ+(:ÿ-Jÿ*Gÿ!5ÿ( .ÿ<)3ÿM5Gÿ9>^ÿRH_ÿT;DÿH8@ÿG4@ÿN=HÿdPbÿ^J[ÿ^K[ÿ?-6ÿC19ÿF3=ÿH5=ÿM9DÿK7BÿL9CÿE9Jÿ@9KÿR=GÿjPYÿoT\ÿpT^ÿbHRÿM8CÿM:AÿK:CÿK8BÿK7AÿI8Cÿ7'.ÿ8'+ÿF49ÿI5>ÿYDSÿ\GXÿZFSÿO;FÿI27ÿN9Dÿ<*0ÿD/6ÿ$$7ÿ+Bÿ,Gÿ$<ÿ52Jÿ4'3ÿ ÿ"ÿ('ÿ&$ÿÿ'%,ÿ#)ÿ#*ÿ-7ÿ$*ÿ$ÿÿÿÿÿÿ'!ÿ&ÿ%ÿ'ÿ+"#ÿ#ÿ %1ÿ%)5ÿ&!%ÿ'%.ÿ" $ÿ"(1ÿ!$ÿ#"ÿ! ÿ ÿ"ÿ ÿ-'>ÿ!*ÿ #*ÿ)%.ÿ0+6ÿ##-ÿ#ÿÿÿ ÿÿ ÿ ÿ!&1ÿ%2ÿ%#,ÿ ÿ !)ÿ!#/ÿ$%4ÿ ,ÿ (ÿÿ ÿ ÿ ÿÿ + +ÿÿ ÿ ÿÿ ÿ + ÿ ÿ ÿÿÿÿÿÿÿ<,0ÿ5'/ÿ!ÿÿÿÿ ÿÿÿ"ÿ ÿ ÿ"ÿH59ÿK39ÿE/3ÿH5;ÿ@(/ÿH;Fÿ19Iÿ.5Eÿ$ÿÿÿ ÿ ÿÿ%ÿ&1ÿ%+<ÿ:Ofÿ6FZÿA('ÿT-+ÿ8$&ÿ6),ÿS7;ÿK7?ÿ7'+ÿVFOÿPSgÿ2$6ÿ) ÿ"ÿ) ÿ%ÿ ÿ#ÿ*ÿ)ÿ'ÿ(ÿ*ÿ&ÿ&ÿ1#'ÿ9*3ÿ."+ÿ.$,ÿ+!&ÿ) #ÿ1$)ÿH48ÿ& ÿ$!ÿ%!ÿ("ÿ*&ÿ)%ÿ+(ÿ/"+ÿ- *ÿ0"+ÿ+ &ÿ7)/ÿ9'.ÿ=,9ÿ27RÿCA\ÿZDUÿ[GUÿZGUÿH7Aÿ.!&ÿ4%.ÿO=JÿP>JÿSAMÿXDRÿL9CÿR?IÿR+3ÿ-#ÿ/#,ÿ%!ÿ'!ÿ*$ÿ.!'ÿ("ÿ)$ÿ,#(ÿ ÿ%ÿ%ÿ %ÿ %ÿ!'ÿ")ÿÿÿÿ  ÿÿÿÿ)#'ÿ."%ÿ2(-ÿ4*5ÿ20>ÿ,1Aÿ%8Pÿ$9Qÿ#4Fÿ*2@ÿ#+2ÿ&+ÿ'.5ÿ(.8ÿ1.6ÿ4*0ÿ3%)ÿÿ#5ÿÿÿ!!ÿ&"ÿ!ÿÿÿ%ÿ*"ÿ)"ÿ%ÿ !ÿ!ÿÿÿ#ÿÿ#ÿ(ÿ ÿÿ ÿÿÿÿ ÿ ÿÿ +ÿ +ÿ ÿ + +ÿ +ÿ + ÿ ÿ ÿÿÿÿÿ ÿW=HÿN6Fÿ6-7ÿ%ÿ!ÿ!ÿ#ÿ!ÿ* $ÿ$"ÿ#%ÿ]Idÿ;)=ÿ$ÿ#ÿ$ÿÿ"")ÿ!-9ÿ,8ÿ$ÿÿÿ ÿÿ ÿÿÿ%ÿ"0ÿ$4Gÿ+/:ÿD3?ÿOÿM7>ÿM9CÿG5FÿPNÿJ?NÿLBQÿJESÿIQZÿLKZÿK?NÿIÿ:*5ÿ-"*ÿ6,4ÿ@:Bÿ@4?ÿ9,4ÿ+ %ÿ& ÿ.$,ÿ)#ÿ+'ÿ& ÿ2$+ÿ( ÿ"ÿ*$ÿ/#)ÿ)#ÿ'ÿ0#+ÿ8,6ÿC2>ÿL:Eÿ\HXÿU@OÿZFUÿU@OÿRÿJ4>ÿK5?ÿM6?ÿU=IÿL5:ÿM7=ÿM6>ÿM7@ÿO;KÿB/:ÿN9DÿS>Jÿ7&/ÿSARÿ`M_ÿ^K^ÿQ?MÿNÿ +ÿ%ÿÿ ÿÿÿÿÿÿ")ÿÿÿÿÿÿÿÿ ÿ ÿ  ÿ + ÿ ÿ=6Cÿ:3>ÿÿÿ ÿÿ'ÿ$ÿ%3Aÿ"ÿ'0ÿ+2ÿÿ(ÿ+@ÿ +@ÿ ,ÿ!2Iÿ$ÿ!ÿ&9ÿ':ÿ(;ÿ,@ÿ0Dÿ"ÿ!(ÿ&-ÿÿ!ÿ!ÿÿ#ÿÿÿÿ  ÿ ÿ ÿ ÿÿÿ#ÿ"ÿ 'ÿ#ÿÿÿÿ&%+ÿ%ÿ&*1ÿ80:ÿ7+3ÿF5@ÿI9EÿG7BÿJ;EÿF=Fÿ?:BÿJ?MÿF7DÿXDPÿS@NÿH8EÿH8DÿH8GÿE8Fÿ7,3ÿ1&.ÿ8.8ÿ:0;ÿ<0;ÿC3?ÿ?/9ÿ3&.ÿ=/7ÿF9AÿB5?ÿ=/6ÿ1&,ÿ"!ÿ,")ÿ+ %ÿ.!'ÿ)#ÿ:,7ÿ.#*ÿ(#ÿ7+5ÿ5)1ÿ1#*ÿ3'.ÿ=0<ÿA1;ÿVDRÿTAOÿ^JZÿTBOÿXCQÿQ=JÿU@MÿZDbÿC.>ÿL5>ÿN7@ÿQ:CÿT>HÿS>Iÿyd{ÿzf{ÿVALÿN8AÿG5EÿG2;ÿP9DÿT?Lÿ, %ÿeRdÿ_L_ÿ^K\ÿL;JÿF7Fÿ5)1ÿ2&1ÿ+ 'ÿ%ÿ+#ÿ&ÿ- $ÿ/"'ÿ,%ÿ(!ÿ#ÿ)ÿ'ÿ#ÿ( ÿ+$ÿ5'2ÿ7*5ÿ4,4ÿ ÿÿÿÿÿ ÿ +ÿ ÿÿ!!"ÿ"ÿ&!ÿ0+7ÿ".?ÿ$/ÿ &ÿ",ÿÿ ÿÿÿ  ÿÿ$ÿ!ÿ &ÿ"&ÿ #ÿ!%ÿ!%ÿÿ !ÿ!ÿÿÿÿÿ$ÿ#ÿÿÿÿÿÿ ÿ ÿÿÿÿ"ÿ#ÿÿ ÿ ÿ + ÿÿ +ÿ ÿicyÿWL\ÿÿÿÿÿ$,ÿ$+ÿ#*ÿ!%ÿ!&ÿÿ"4ÿ!2ÿ';ÿ +Bÿ,Bÿ,Bÿ/Cÿ!0Eÿ*;ÿ#3ÿ"2ÿ!.ÿ"-?ÿ'6ÿ#,ÿ!ÿÿÿÿÿÿÿÿ  ÿ  ÿ ÿÿÿÿÿÿÿ ÿ('+ÿÿÿÿ &ÿ!ÿ %ÿ!(ÿ/)1ÿ0$*ÿ3%,ÿ4&-ÿ4'-ÿ1%+ÿ2'-ÿ9,5ÿ4&.ÿL8BÿE3<ÿ8(/ÿF5BÿL;IÿE5Bÿ3&.ÿ9+4ÿ=/:ÿB3?ÿF6CÿN/9ÿE6CÿJ:GÿQ?Mÿ_L]ÿUBSÿ[GYÿXDSÿVDQÿT@LÿW@XÿJ7NÿR:DÿQ9CÿTÿ[BLÿTÿQ;FÿWAOÿ$ÿaN`ÿaM`ÿVCSÿJ9IÿM=Oÿ?18ÿC4>ÿ?1:ÿ:-2ÿ4%,ÿ*"ÿ2")ÿ9*0ÿ4&,ÿ0#(ÿ)"ÿ*#ÿ' ÿ' ÿ%ÿ+ ÿ+!ÿ,%ÿ' &ÿÿ ÿ +ÿÿ ÿ ÿ ÿ +ÿÿÿ ÿ-!(ÿ1(2ÿ!$.ÿ"*ÿÿ"ÿ ÿÿÿÿÿÿÿÿÿ "ÿÿÿÿÿ"#ÿ-).ÿ./ÿ(%ÿ'!ÿM9AÿXBLÿZBQÿ:+4ÿ>.7ÿ>,5ÿC48ÿH7>ÿA/2ÿD29ÿD49ÿI7=ÿ=+-ÿJ6=ÿ1+3ÿÿ ÿ ÿ ÿ ÿ ÿ84@ÿi`oÿaU`ÿ/(-ÿÿÿÿ&ÿ ÿ $ÿ$ÿÿÿF?QÿYH[ÿ.0Dÿ"3ÿ$4ÿ%3ÿ'4ÿ(7ÿ&4ÿ+ÿ"1ÿ$2ÿ!+ÿ")ÿ"'ÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ$,ÿ*.>ÿ71Eÿ5*8ÿ'ÿ#ÿÿÿ%ÿ.*3ÿA5?ÿ;-8ÿ<-8ÿ7)2ÿ;,6ÿ2$)ÿ7(0ÿ4&-ÿ;,4ÿ>/6ÿ@0:ÿF5AÿM;IÿE3?ÿ8)3ÿ5(1ÿ=.9ÿA1=ÿF4AÿM:GÿK:Eÿ:,4ÿ=.7ÿ6(-ÿ&ÿ-%ÿ2$.ÿ9)1ÿ-!'ÿ.!)ÿ7)4ÿ.$1ÿC4Aÿ?1=ÿI1>ÿ>.7ÿUBSÿRAOÿT@PÿZGYÿWDTÿU@NÿWAPÿT?KÿR>PÿI8QÿH3<ÿN8CÿV?IÿT=IÿZFRÿM7AÿgO^ÿI!ÿR.#ÿW?HÿS?NÿE2BÿI5>ÿT>JÿVBOÿ)ÿbObÿaN`ÿYFWÿN=KÿG7Eÿ2%.ÿ2$.ÿ7(1ÿ5&/ÿ;+7ÿ4',ÿ<,6ÿE4?ÿC2=ÿ?/7ÿ5'-ÿ7)0ÿ5&/ÿ/#,ÿ+!)ÿ0%-ÿ2%/ÿ/$.ÿ,#+ÿÿÿ ÿ ÿÿ ÿ ÿ ÿ  ÿÿ"ÿ4*2ÿ'+;ÿ"'3ÿ (ÿ"$ÿÿÿÿ ÿÿÿ!&ÿÿÿÿÿÿÿÿÿÿ819ÿ+)4ÿ8,4ÿ2%.ÿB2:ÿgMXÿfLXÿWBNÿW@KÿVALÿVBKÿZEQÿT?FÿXEPÿ@.5ÿN>Bÿ*ÿ$ÿÿÿÿÿÿÿÿ51Hÿ7*<ÿ;.>ÿ+ ,ÿ ÿ#ÿ%,ÿ#(ÿ!&ÿÿÿÿÿ$0ÿ61?ÿ!$5ÿ)ÿ*ÿ"/ÿ'->ÿ!%2ÿ*ÿ&ÿ'ÿ#ÿÿ"ÿÿ ÿÿÿÿÿÿÿ  ÿÿÿÿÿÿ ÿÿÿÿ ÿ'ÿ%0ÿ'$.ÿÿÿÿÿÿ!#+ÿ#'1ÿ%)2ÿG;DÿQ?IÿQ>HÿI8AÿTANÿE4=ÿ6&0ÿ?.6ÿ:*5ÿF6BÿB2<ÿ9)0ÿ8*0ÿ<+3ÿ?.7ÿ@/7ÿ>.6ÿ>.5ÿ?.6ÿ3&+ÿ<-3ÿ7(/ÿ<,4ÿM=HÿcP_ÿeP`ÿdO_ÿaK\ÿXESÿ?0=ÿB1?ÿ>1?ÿM>Jÿ0$+ÿ9*4ÿK;Gÿ^J^ÿYDVÿP>MÿbOaÿVCRÿU?MÿYDQÿRGÿO=Qÿ?.9ÿH4=ÿTAMÿVBOÿ3$.ÿcObÿ`L_ÿ_L]ÿYFWÿUCSÿ[IYÿaM]ÿbN_ÿ^K[ÿS@Nÿ3$,ÿC3;ÿE4>ÿC2>ÿH6@ÿC1;ÿC3=ÿ@0:ÿ;+5ÿ9)4ÿ8*5ÿ7(2ÿ5&/ÿ1$(ÿ$#ÿÿÿ ÿ ÿ ÿ +ÿ +ÿ ÿÿ !ÿ4(/ÿ!&0ÿ*8ÿ#,ÿ "ÿÿ ÿÿ +ÿ +ÿ& &ÿ+*9ÿ)"(ÿ##ÿ"ÿ ÿ%!&ÿ$$+ÿ7/7ÿ"ÿÿ$#$ÿÿ ÿ106ÿQ=JÿT*2ÿH6@ÿG6?ÿQÿJ7=ÿG5<ÿH7>ÿ9*0ÿI8@ÿK9BÿM8AÿVAMÿ`LYÿ`LZÿaLZÿYEQÿZEOÿO;DÿJ9DÿH:Hÿ;/;ÿ:-6ÿH7DÿI6Bÿ_L_ÿYEWÿ[HWÿWDRÿWCQÿ[GUÿVAOÿN>Sÿ9((ÿG16ÿA.HÿQ:Cÿ_EPÿnS[ÿU>IÿC.9ÿ7%*ÿ$ÿ&2ÿ>+3ÿF6NÿB/8ÿK6@ÿS?KÿQ?PÿE4HÿaL^ÿ`L]ÿ\I[ÿWDVÿQ?PÿcN_ÿdM^ÿgQaÿaL[ÿS?Jÿ1!&ÿB06ÿH3;ÿH4;ÿJ6=ÿM8AÿM8AÿO:BÿQ;DÿP29ÿ2*1ÿÿ!ÿ1'+ÿ7*/ÿM;Dÿ@5@ÿM@KÿC;CÿC7AÿK=EÿQ?IÿO@Lÿ?0<ÿ61>ÿ?7Aÿÿ ÿÿÿ>-6ÿ7%*ÿP:BÿO:@ÿ:(,ÿ:)-ÿ0#$ÿ8'+ÿ*ÿE18ÿM9AÿR>HÿI16ÿL7@ÿ!ÿÿÿÿ#"ÿD8Fÿ{f|ÿN5?ÿaJTÿu^jÿ8.6ÿ.2:ÿ!-2ÿ#ÿ"$ÿÿÿÿÿÿ%4ÿ!ÿ!ÿÿ&ÿ//6ÿ)ÿ"ÿÿ&ÿÿ ÿ%ÿ$ÿ$ÿ!ÿÿÿ! 'ÿÿ ÿÿ ÿÿÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿÿ ÿ ÿÿ ÿÿÿ ÿÿÿNÿ^IWÿ^JVÿ`IVÿZBLÿsTfÿX@Nÿ_FOÿ^GSÿ`JTÿ]FOÿ`IUÿ_HTÿ[ERÿ^JVÿWCOÿF6=ÿ_JXÿSÿ?.;ÿRANÿXFVÿSBRÿV@Nÿ^L^ÿXEUÿVCPÿWCPÿ_JZÿWCOÿH=fÿo]|ÿR<_ÿ&dÿJ;pÿA,EÿeDMÿV6FÿiSiÿP=^ÿ%EÿoXkÿI?eÿ63[ÿD3DÿG2:ÿR=HÿK8AÿN?eÿ;;¡ÿaL[ÿ^K]ÿ_K^ÿYEXÿP=Oÿ_L[ÿbM\ÿcO^ÿbLZÿJ9Cÿ_JVÿ,ÿ0!%ÿ2$'ÿ5%*ÿ8(,ÿ:(,ÿ=*0ÿ@-3ÿA.5ÿA06ÿ?/4ÿH6=ÿ?,;ÿD2BÿB59ÿÿ ÿÿ5).ÿZDRÿJ6@ÿ7,2ÿK:EÿZDOÿ^GTÿ--9ÿC;GÿM>IÿZDPÿI8@ÿA09ÿI8AÿT@LÿT?KÿS>GÿE5<ÿ7)1ÿ,"(ÿ5(.ÿ3$*ÿ;)2ÿK;Iÿ6&/ÿ?/3ÿF5;ÿ!ÿ ÿ(!ÿÿ?-2ÿJ48ÿH38ÿG19ÿA,2ÿE19ÿ."ÿ3!'ÿ)ÿ=+1ÿN7BÿT1=ÿ?.7ÿ>,4ÿA.6ÿ;+2ÿ:*1ÿB07ÿS?Hÿ4%+ÿJ5;ÿ8(.ÿ:*0ÿA/7ÿC3;ÿ=-5ÿ>.6ÿ;*2ÿ4&+ÿ3'&ÿ8*/ÿ7)-ÿ9+1ÿA1:ÿO=KÿL:DÿMLÿTAPÿaO]ÿZERÿ[FTÿO?LÿC=Qÿ==Zÿ%#?ÿWNfÿ!/lÿ50kÿ! QÿUF\ÿ?:Pÿ03Kÿ;2Eÿ?3>ÿF5>ÿK7@ÿK6@ÿWBNÿG5?ÿT@RÿH5GÿaNaÿ^K]ÿ^K]ÿXFWÿP>NÿM;IÿPOÿ4%aÿVATÿ#ÿ$ÿ#ÿ#ÿ-",ÿ7+8ÿ1"+ÿ,#ÿ&ÿ ÿ$ÿ(ÿ'ÿ)"ÿ, $ÿ$ÿÿÿ$ÿ1#(ÿ1$*ÿ1$*ÿ0"&ÿ0$ÿ,#ÿ(#,ÿ2$(ÿ/!&ÿ,#ÿ( ÿÿ' ÿ'ÿ'ÿ$ÿÿ) ÿ#ÿ-!#ÿoT\ÿhMRÿ[DKÿK5;ÿM9=ÿG49ÿ0()ÿ8+.ÿD:Cÿÿ ÿ%ÿ"ÿ"ÿeÿÿ#ÿÿ ÿÿ4#,ÿE.6ÿF04ÿ`FMÿ;.<ÿ2/BÿD;Lÿ{f}ÿ~fyÿXAPÿ9%0ÿL7Aÿ‚hvÿ~drÿlP[ÿ3"+ÿ.(/ÿB=Dÿ'*-ÿ!ÿ!ÿÿÿ!$ÿ ÿÿ ÿÿ#ÿ&ÿ9:Mÿ1.:ÿ97Bÿ*(ÿ@18ÿ/.7ÿF;@ÿ0-7ÿ(&,ÿÿ'"%ÿ5+0ÿÿÿ.&(ÿÿ ÿ + ÿ ÿ8ÿ ÿÿ ÿÿÿÿÿÿÿÿ ÿ  ÿ ÿ +ÿ +ÿ + + ÿ ÿÿ ÿ,)6ÿL>Jÿ7)1ÿ<1>ÿH;Fÿ0#*ÿ8*0ÿ4(-ÿ- $ÿ/"'ÿ- &ÿ7*0ÿ?2:ÿF9BÿE8BÿD6?ÿ3(.ÿ&"ÿ5+3ÿN@OÿE8CÿTFSÿF8Bÿ@0;ÿ;+3ÿE7CÿE5=ÿC2;ÿ&ÿLKÿT>Kÿ<(2ÿK7KÿJ8BÿA8PÿF3<ÿF3<ÿK9BÿN;DÿN9CÿL8CÿM9AÿK7@ÿI6@ÿO=Iÿ6'.ÿVFUÿ[GXÿZGXÿM-8ÿ;,5ÿE4?ÿE4>ÿR@Lÿ2$,ÿ( ÿ' ÿ/#/ÿ3)5ÿ7+6ÿ8,6ÿ7+5ÿ0&.ÿ)'ÿ#ÿ.$.ÿ',ÿ%-ÿ.$+ÿ2'-ÿ)#ÿ& ÿ#ÿ1%+ÿ,!(ÿ.#+ÿ-#*ÿ%!ÿ(&ÿ7,8ÿ8+6ÿ/#+ÿ* $ÿ#ÿÿ ÿ!ÿÿ$ ÿ'!ÿ"ÿ$ÿ"ÿA05ÿ9(-ÿ?.2ÿ[EMÿnMPÿ�flÿ^FHÿ2%(ÿ,!%ÿÿÿ#ÿ'ÿ(!ÿ!ÿ>6Cÿ7/6ÿ ÿ."ÿK7=ÿO;@ÿK7;ÿ=-1ÿ<,2ÿ,!&ÿ10>ÿ62Aÿ4.;ÿ4-5ÿ'&4ÿ3)6ÿ3,9ÿ?.3ÿ+$/ÿ8*0ÿ*"*ÿ'$(ÿ! ÿÿÿÿÿÿ##%ÿÿÿ ÿ!ÿ(ÿ1-9ÿYFUÿoWiÿbVjÿU]~ÿV`ÿ"!.ÿ('7ÿ##ÿ(!ÿ%#ÿ- !ÿ+!ÿÿÿ ÿÿ ÿ ÿÿ#ÿÿÿÿÿÿÿ!ÿÿÿ$!ÿ%!ÿ7-5ÿ,#)ÿ-"(ÿ"ÿ"ÿÿÿ$"ÿ6*4ÿ0"(ÿÿÿ+%ÿ,$ÿ, &ÿ)#ÿ(#ÿ)%ÿ(&ÿ.!*ÿ8*3ÿ-(ÿ- 'ÿ, %ÿ*%ÿ&!ÿ("ÿ5&.ÿ1$-ÿ0")ÿ;+3ÿ:*2ÿ*"ÿ. %ÿ8)1ÿ<,5ÿD4?ÿTBQÿ[IYÿ[HYÿ[HZÿ[GXÿQ?Oÿ[GWÿcPaÿ`M^ÿfRfÿeSfÿ^K\ÿcRcÿ\J]ÿeSeÿU6Cÿ[HaÿUBQÿ]J\ÿWDSÿcP_ÿZFTÿaM]ÿXDQÿ_KXÿV@NÿZDTÿV@PÿWCSÿD2:ÿP=Kÿ^IZÿVDTÿL;HÿL5FÿL.6ÿ6&,ÿC2=ÿA0:ÿD3<ÿG5BÿI6BÿMÿ?07ÿ9*1ÿ7(0ÿ5',ÿ9*1ÿ9*1ÿL;FÿTCOÿXEUÿ[HYÿbNbÿ`K]ÿdQcÿgVjÿjXlÿiVkÿgSgÿeRfÿfReÿcQbÿaO`ÿdPaÿR?Kÿ_JYÿYDTÿYDTÿ[GVÿ\FWÿ^IXÿ^JZÿ_K[ÿ`K]ÿaL\ÿcN^ÿaN_ÿaM^ÿZFVÿS@OÿXEWÿZEVÿO/<ÿ=.:ÿ;*6ÿ:*5ÿ9*5ÿ:+4ÿ9+4ÿ9*4ÿ;-7ÿ<.:ÿ<-;ÿ6(4ÿC1@ÿE3AÿH7GÿI7GÿA1<ÿ/$ÿ0"&ÿC06ÿ4!%ÿ,!ÿ?.5ÿ@-4ÿG5>ÿTCQÿ[IZÿWDUÿXCTÿO=JÿL9Fÿ#"&ÿ !ÿÿ"!&ÿ6.=ÿ""'ÿ)"(ÿ9-;ÿ8,;ÿUMcÿID]ÿ1/Eÿ"ÿÿÿ ÿ +ÿÿÿÿÿÿ ÿÿÿ ÿ ÿ ÿ:*3ÿ-)ÿ9; ÿÿ,&ÿ>BTÿW�°ÿ=OiÿB>Oÿ1,8ÿ2!(ÿ3#*ÿ2#(ÿ- #ÿ) ÿ+!ÿ* ÿ2"(ÿ/!&ÿ*"ÿ- %ÿ+#ÿ+!$ÿ,#ÿ,$ÿ&ÿ-!%ÿ%#ÿ0#(ÿ1#$ÿ#ÿ(ÿ*ÿ4#'ÿ2!1ÿ9)6ÿ9(1ÿ>,5ÿA0<ÿE4AÿG7CÿI8FÿL:JÿMNÿP;JÿWARÿ[FVÿ\GWÿ]HYÿ]IZÿ`L^ÿ_K]ÿ_L\ÿ_K[ÿ_K\ÿ`L]ÿ\IXÿR?LÿZFUÿ\ETÿ[ESÿVCPÿR>KÿR?KÿQ=JÿS?KÿV@NÿYCRÿVBNÿ3%*ÿTCOÿS@KÿSBNÿS@MÿR@Kÿ`M[ÿ`N\ÿaN[ÿbM^ÿ`L]ÿ^QEÿYGMÿP=IÿI8CÿH6BÿE3?ÿC1;ÿA/8ÿC1=ÿB1<ÿB0=ÿC2@ÿE4AÿF4CÿC2AÿB1BÿD2DÿB1CÿD2EÿF3GÿF3GÿD2FÿD1FÿC2FÿE4Hÿ>/=ÿE1CÿA/?ÿC1CÿE2FÿE2FÿE0?ÿD2AÿE3@ÿG5AÿNFÿQ;DÿR=GÿH6@ÿL:IÿG4EÿXEYÿR?RÿUBUÿUATÿUAVÿUAWÿTAUÿQ>SÿOLÿS@NÿTARÿYGYÿWDWÿ_Laÿ]K_ÿ_N`ÿaNbÿeSiÿeSiÿ`Obÿ_M`ÿYGXÿ[HXÿR@Oÿ?.:ÿP=Jÿ?.<ÿL9HÿVARÿ[GWÿ^HZÿ^HYÿ^IZÿ]HXÿ]HWÿ[FUÿYETÿ]IWÿ]IXÿWBMÿJ7@ÿWBPÿV@OÿS?LÿQJÿOKÿU?LÿZESÿR=JÿG6@ÿRANÿR@NÿS@NÿM9EÿL:FÿO=LÿOJÿT?MÿT@MÿUAOÿWCQÿXDUÿXEWÿG6Eÿ-%5ÿ( ,ÿ  ÿÿÿ %ÿ#(ÿ"'ÿ/".ÿSÿP@RÿN@RÿO@TÿQBXÿP?RÿR@TÿSAUÿC3@ÿI8DÿNKÿUCQÿQ?MÿH7BÿUCRÿVCSÿXFVÿYHZÿ]J]ÿ]K^ÿ]M`ÿ_Maÿ[HZÿ[GXÿ[IZÿ\JZÿ]J\ÿ^K\ÿ_K^ÿ\J[ÿ^K^ÿ[HZÿXEZÿ\I`ÿ`J`ÿ_J]ÿ]IZÿ]IYÿ^HXÿ\HVÿ]HWÿ[GVÿ[GVÿXETÿXDPÿWBOÿUAMÿM:EÿT?MÿR>JÿPÿC1:ÿE3<ÿA/7ÿ?.9ÿD5@ÿC1:ÿC2:ÿE4=ÿE5>ÿF6?ÿO@Nÿ=.4ÿP?LÿO=JÿWDQÿYDSÿZFTÿ[GTÿR=Fÿ]GUÿZGRÿXDPÿYDQÿ]HUÿ^IWÿ_KYÿ_KXÿ_JWÿ[FRÿXCPÿWANÿWBNÿT@LÿR=IÿR=IÿQ>HÿM8AÿL8AÿVDPÿZFTÿXFSÿZFTÿQ=GÿVCPÿI9AÿN=GÿXETÿXESÿN:CÿT@NÿS?MÿTAOÿUBPÿWDRÿZGWÿ\GYÿQ>Lÿ2,=ÿ!,ÿ!+ÿ" -ÿ .ÿ" -ÿ'ÿ'ÿ8+8ÿ<-:ÿ1'3ÿJ?QÿD>MÿALÿ2&.ÿ7+2ÿ@1:ÿT?KÿZETÿXERÿYEQÿR=EÿVAKÿXCMÿZDQÿ[FSÿ[GTÿZGTÿYFTÿZFSÿYFRÿ[GTÿZEQÿYFQÿXERÿVCOÿYDPÿXDPÿUBOÿT@LÿQ>IÿG4<ÿZFSÿZGSÿXHSÿO;Fÿ]HUÿ[ITÿ[HTÿ_KYÿz_jÿZCLÿ]L\ÿ_K[ÿ_JZÿ[GVÿVCPÿS@MÿU@NÿE2?ÿ-%7ÿ ÿÿÿÿÿÿÿ-#)ÿ/%0ÿ"#ÿ:2>ÿ1,6ÿ-)3ÿ2-8ÿ5-8ÿÿÿ$#ÿ$!ÿ"ÿ!ÿÿÿÿÿ ÿO?MÿRAPÿUDVÿ\K]ÿfTgÿlZpÿm\sÿm\rÿjYoÿWCTÿiYnÿkXnÿgTiÿgTjÿkYoÿiXoÿn[sÿdShÿcOeÿn[sÿo\sÿo\rÿr_uÿs`vÿs`xÿs`yÿsbxÿuczÿvf~ÿtf~ÿvg€ÿyhƒÿzj†ÿwh‚ÿwh�ÿtd|ÿJ2>ÿ7,9ÿ^Odÿtd~ÿtc~ÿve�ÿrc~ÿtd€ÿsc~ÿra|ÿq_xÿo[uÿn\tÿr`yÿq`yÿn_vÿiWnÿkZpÿn]tÿp_wÿr_yÿn\tÿhUlÿkZpÿjXpÿl\tÿn]vÿpa{ÿrc~ÿm\uÿhVkÿVFUÿk[rÿk]uÿl]vÿq_zÿ[IZÿZGWÿm^zÿoc€ÿl_yÿk\uÿhYpÿfVmÿdRgÿcPdÿC4>ÿF5AÿB1=ÿÿK:Kÿ\Haÿ\I_ÿ^J^ÿ]I[ÿ]K[ÿ]IZÿ[GXÿWFSÿXESÿYDSÿXETÿZHWÿYGWÿZEUÿPKÿS>KÿQ=IÿR=JÿS=IÿO;FÿQOÿhVmÿiWmÿhVlÿeTiÿdRfÿbQdÿeSgÿeRhÿeSjÿgTkÿgUlÿhVkÿhVlÿhWlÿdRgÿcRfÿ`Qcÿ_Ocÿ^Pcÿ]Peÿ\Pcÿ[O_ÿWLZÿWL[ÿVN]ÿWN^ÿRLYÿOIUÿDNÿF6CÿMBSÿKCSÿEIÿBEÿB?Hÿ=9AÿIAKÿIBMÿKDNÿLCOÿMDNÿOEQÿRESÿTERÿRDQÿSDPÿTDPÿQALÿSBQÿZIXÿ]JZÿ^JZÿ`J[ÿ_JYÿ\IXÿZGVÿWETÿREVÿ:/9ÿ2*0ÿ8/9ÿ€qˆÿgqÿ„bgÿ�cpÿE29ÿUDPÿWDPÿ[GSÿ\GSÿ]GUÿ]IUÿ]IVÿ\IVÿ[ETÿ]IVÿ[HTÿ]IVÿ\FTÿ^HUÿXCPÿ]GVÿG?Aÿ<10ÿ+-ÿ-$ÿ9/-ÿ2*&ÿ.)$ÿ*#ÿ+(#ÿ2%*ÿ.#-ÿ>3Aÿ(!,ÿ0%+ÿODQÿYN`ÿQERÿ]N^ÿQGTÿLDWÿTGSÿA6AÿB>Qÿ55Bÿ88DÿHCQÿE>Nÿ;4Bÿ3.9ÿ($,ÿ$#ÿÿÿÿ ÿÿ ÿ + ÿ ÿ ÿ ÿ ÿ + ÿÿÿ ÿÿÿ ÿIH`ÿ?CTÿAEUÿ@BPÿ::Gÿ65?ÿ%#)ÿ#ÿÿ!ÿ + ÿÿ4*3ÿ[H[ÿ^K_ÿ^L^ÿ_NbÿQ@PÿB1=ÿYGXÿK:HÿG6Cÿ_L[ÿcPaÿcQcÿfReÿ^J[ÿG6BÿcPbÿeRcÿR?NÿbM]ÿaM^ÿaM`ÿ^L\ÿ[HVÿL;Hÿ8+5ÿ2'0ÿ9.;ÿ?3BÿM>NÿYGXÿaL`ÿbM`ÿ_M]ÿ^M_ÿ_N`ÿeSfÿZM_ÿUJYÿPGTÿD>Hÿ;8?ÿ46:ÿ258ÿ.37ÿ+24ÿ'00ÿ&//ÿ%./ÿ#-.ÿ!-,ÿ +*ÿ'%ÿ'$ÿ'$ÿ )&ÿ% ÿ% ÿ$ ÿ$ÿ# ÿ&"ÿ&#ÿ&$ÿ!((ÿ##ÿ&&ÿ%$ÿ&%ÿ''ÿ%&ÿ#"ÿ""ÿ$&ÿ$'ÿ#&ÿ$&ÿ$$ÿ$#ÿ##ÿ##ÿ$$ÿ#$ÿ#!ÿ ÿ!ÿ ÿ ÿÿ ÿ!ÿ"ÿ!ÿ$ÿ"ÿ&!ÿ%"ÿ&#ÿ)&ÿ+)ÿ .-ÿ"//ÿ"01ÿ'35ÿ)48ÿ,6:ÿ07;ÿ28=ÿ47>ÿAAJÿF@JÿVMZÿ\N]ÿbSgÿJ>Nÿ3+4ÿ2(0ÿ4)1ÿB7Aÿ?18ÿM9=ÿC26ÿA29ÿR@Lÿ^JZÿ_J\ÿbN^ÿYFTÿUAOÿ`L\ÿgSeÿF3?ÿcO_ÿdSaÿfQbÿgTeÿbO]ÿN>Jÿ_M\ÿ:95ÿ$"ÿ(("ÿ&ÿ&&ÿ)* ÿ@:8ÿD56ÿ5.-ÿ!ÿ !ÿ# +ÿ"!,ÿ$#ÿ1*1ÿH@NÿRKYÿ[M_ÿA5<ÿSALÿ˜ntÿS<=ÿGFPÿKI_ÿ>>Jÿ*.1ÿ/5;ÿ:>GÿHCPÿUL^ÿMANÿOIYÿC>Nÿ72?ÿ/+6ÿ!!)ÿ$ÿÿÿÿÿ#%ÿ)*ÿ +-ÿ'*,ÿ /.ÿ-,ÿ**ÿ(*ÿ75?ÿ/.4ÿ ÿÿ ÿ + +ÿ +ÿ ÿ ÿ!ÿ" ÿ3(1ÿJNÿhSfÿeRgÿfQfÿgShÿUBSÿC2@ÿ^J^ÿhTjÿI8Hÿye|ÿmZpÿbPdÿXJ^ÿDANÿ?;Cÿ.$.ÿ3'3ÿ6-9ÿA4DÿNARÿ>CLÿ2PÿF6FÿN@Oÿ:26ÿ))#ÿ,-$ÿ.*#ÿUHMÿZLXÿL?Oÿ:2@ÿ($/ÿ&&ÿ'!0ÿ!ÿ#ÿG@LÿL?Gÿ1%%ÿ"!ÿ!ÿ%/'ÿUMiÿSMiÿSNgÿMK_ÿ:>Hÿ"#ÿ)(*ÿ..1ÿHFSÿ\Wjÿ^Xnÿg`wÿaZpÿQI]ÿF>Oÿ=7Eÿ0,6ÿ(#-ÿ %ÿÿÿÿÿ!"ÿ'+ÿ&17ÿÿÿ ÿÿÿÿ+!&ÿ:,6ÿH9FÿE5Aÿ^J\ÿ`K^ÿ\I\ÿ^I]ÿ_J`ÿePfÿbOcÿcOeÿcNeÿaMdÿbNdÿcLdÿ`Kaÿ`Iaÿ_IaÿcMgÿfOiÿeNhÿaMdÿP@SÿSEWÿ@9Eÿ98Dÿ.5>ÿ%16ÿ&24ÿ.07ÿ*%,ÿ.&.ÿ<4@ÿMDTÿSL\ÿ-8>ÿ*8;ÿ,9=ÿ+9=ÿ+8<ÿ,7<ÿ-4:ÿ07<ÿ6;Cÿ#!ÿ ÿ"ÿ"ÿ#ÿ#ÿ#ÿÿÿ$ÿ' ÿ'ÿ$ÿ%ÿ' ÿ!/,ÿ,:9ÿ5@Aÿ@GKÿ@EJÿNTZÿX]fÿchrÿkn{ÿuv…ÿ}~�ÿƒ‘ÿ††™ÿ‹‰žÿ�Œ¡ÿjbmÿH;:ÿG:<ÿD78ÿG9:ÿF::ÿE8:ÿD78ÿC77ÿ?45ÿ=33ÿ<44ÿ<53ÿ:44ÿ854ÿ432ÿ//.ÿ)--ÿ+-/ÿ++.ÿ%,+ÿ+)ÿ+)ÿ&#ÿ$ÿ!ÿ ÿ$ ÿ&"ÿ&!ÿ&"ÿ'"ÿ&!ÿ)$ÿ&34ÿ1:=ÿ1;>ÿ0;<ÿ1;<ÿ.:;ÿ1>@ÿ1>?ÿ1?Aÿ0>?ÿ0=AÿTOcÿ&#,ÿ1+4ÿ/,4ÿ%)ÿ&.3ÿ-2:ÿ03<ÿ-3>ÿ*0;ÿ1/;ÿPCTÿcRjÿkXsÿlYtÿbPiÿ^Jcÿ^Lcÿ^Kcÿ_Iaÿ]H`ÿ\H_ÿ[G^ÿ[F]ÿZF\ÿ\H]ÿ^I`ÿ_Jaÿ]I^ÿXF\ÿWG[ÿJ?Kÿ410ÿ&( ÿ$(ÿA=>ÿE:BÿF0:ÿK;GÿUBQÿYGWÿWDUÿZHXÿWDVÿXDXÿ]H]ÿ`LbÿcNeÿeOfÿeOeÿePeÿePeÿdNeÿbMdÿbMdÿbLcÿaKcÿcOhÿgPlÿhRkÿ`LaÿUJ[ÿ9:Cÿ-6=ÿ$26ÿ!26ÿ!37ÿ&6;ÿ&6;ÿ$5:ÿ%8;ÿ34ÿ11ÿ10ÿ 13ÿ#47ÿ&68ÿ(:<ÿ(:;ÿ)9;ÿ(68ÿ'46ÿ&14ÿ)27ÿ.29ÿ;6DÿVSgÿCKXÿ'!ÿ&"ÿ!ÿÿÿÿ +ÿ" ÿ%21ÿ.7;ÿINWÿdfuÿz{Žÿ‡ˆ›ÿŽŽ ÿ–”¨ÿ‘‹œÿƒy‡ÿ¤ ¶ÿ¥ ·ÿ¤Ÿµÿ£Ÿµÿ£Ÿ´ÿ£ž³ÿ¢�³ÿ¡œ²ÿ ›°ÿ¡�²ÿxnwÿP?=ÿK<9ÿJ;7ÿL;5ÿK=4ÿI;3ÿK<6ÿJ;4ÿJ:5ÿJ:5ÿI:4ÿJ:4ÿJ92ÿJ;3ÿI80ÿK93ÿH82ÿG93ÿE73ÿB62ÿ=30ÿC:=ÿMENÿLFNÿ*'(ÿ +ÿÿ+44ÿ+%ÿ#ÿ&"ÿ3>EÿECNÿ--2ÿ*/2ÿ*79ÿ+9;ÿ,<=ÿ);>ÿ*>@ÿ,=@ÿ+<>ÿ*<=ÿ);<ÿ 34ÿ..ÿ00ÿ1/ÿ0/ÿ!33ÿ"11ÿ#//ÿ"/0ÿ"./ÿ%-1ÿ10<ÿ>6Cÿ^NfÿiUpÿlXtÿiVqÿdQlÿgRmÿfQlÿfPjÿdPhÿbNfÿ_Jbÿ\H^ÿ^I`ÿ_I`ÿ_H_ÿ_J`ÿbNdÿbLbÿ^K^ÿVGXÿNBPÿ>9>ÿ&'!ÿ"!ÿ(ÿ)"ÿÿ$ÿÿ'-$ÿ+&%ÿ.+.ÿ81:ÿH:CÿSMXÿ8;Cÿ4;FÿLLcÿVRpÿYVvÿ>9Kÿ?;QÿKAVÿOJeÿEC]ÿ<;Kÿ*.6ÿ**ÿ$#ÿ))ÿ(.3ÿOHVÿf\sÿ]Rgÿh^sÿeYqÿN?Nÿ_Vnÿ_WnÿRJ_ÿOJ\ÿ_JZÿdObÿ]J\ÿ[H[ÿZFZÿZF\ÿ`Kbÿ`KcÿdMeÿfPgÿfPfÿeOfÿfOgÿgOiÿfOhÿdMfÿcLeÿbKeÿbMfÿbNgÿcNiÿeRiÿ\K_ÿZNbÿ84ÿT?5ÿTA7ÿL:1ÿK:8ÿjXlÿ@6>ÿ ÿ&%ÿfVlÿm_yÿk`{ÿRK[ÿ,(.ÿÿ+(ÿ+(ÿ,*ÿ,)ÿ/+ÿ2/ÿ31ÿ42ÿ32ÿ44ÿ54ÿ64ÿ66ÿ77ÿ 88ÿ76ÿ74ÿ53ÿ 65ÿ!87ÿ 67ÿ!56ÿ32ÿ0,ÿ17<ÿUFYÿiXrÿm[xÿo]yÿbMgÿbLeÿaMeÿ`Kdÿ`Jdÿ`Jbÿ^I`ÿ]G^ÿ\G]ÿ_H_ÿ`Jaÿ_H`ÿcNdÿePfÿdPdÿbNaÿZGZÿUFYÿL>HÿH?Gÿ=05ÿ=.6ÿUHTÿXGXÿ]K\ÿ]Ocÿ%#'ÿÿ% ÿ()/ÿFBPÿABJÿ".-ÿ#13ÿ;ESÿLLfÿMMhÿG@SÿSKhÿXUsÿXTrÿXTtÿWRrÿLLeÿ5=Jÿ58>ÿ)-.ÿ!*+ÿ39AÿON\ÿ^ShÿH;HÿbZqÿbYpÿVMbÿ`WnÿYFZÿXDXÿ]I^ÿcMdÿcMeÿePfÿfPgÿgQgÿhPgÿfOgÿgOgÿeNgÿbLfÿaLfÿbLfÿdOhÿeOhÿiUnÿZL`ÿJFVÿDGSÿ3>Eÿ#59ÿ46ÿ79ÿ9;ÿ#:>ÿ8:ÿ78ÿ89ÿ78ÿ68ÿ79ÿ8:ÿ78ÿ77ÿ67ÿ54ÿ21ÿ0/ÿ,,ÿ+*ÿ*(ÿ(&ÿ'$ÿ'#ÿ%!ÿ%"ÿ&#ÿ($ÿ%"ÿ%"ÿ%#ÿÿÿQI^ÿÿÿOBRÿ_Pcÿ_Oaÿ^R_ÿ™’¦ÿŠ€Žÿ¢š°ÿ ™¯ÿ™Œ ÿ—‰œÿ—‰œÿ¤�²ÿ”��ÿ¦ ´ÿ–�¡ÿœ—¨ÿ¦¢´ÿ§£µÿ¨¥µÿ¨¥µÿ¨¤µÿ©¥µÿ¦¢±ÿeYZÿM?9ÿF91ÿH91ÿK;3ÿJ:3ÿJ;3ÿL;4ÿL;4ÿL:2ÿJ:3ÿJ:5ÿE50ÿJ83ÿI70ÿVFAÿ_KFÿaKHÿVA8ÿUA6ÿXB7ÿ\H9ÿYF9ÿXHHÿpb|ÿ(#'ÿÿÿvhƒÿ]Reÿ&(*ÿ! ÿ*'ÿ*&ÿ+'ÿ+'ÿ,'ÿ,'ÿ,'ÿ-'ÿ0,ÿ1/ÿ20ÿ41ÿ64ÿ53ÿ55ÿ66ÿ77ÿ76ÿ75ÿ75ÿ76ÿ&<<ÿ%:<ÿ77ÿ75ÿ54ÿ3/ÿ!20ÿCBMÿdRiÿo\{ÿq_}ÿiVqÿcNhÿ`KdÿbLfÿ`Kcÿ_I`ÿ^I`ÿ]G^ÿ\F^ÿ\E^ÿ\F^ÿ\F]ÿ]G^ÿ^H_ÿcMcÿePeÿdNcÿ]H\ÿdPfÿcObÿtayÿwdxÿsauÿk[pÿfUiÿ4-4ÿÿÿ ÿÿÿ34<ÿ89Aÿ079ÿ3;>ÿ2>Dÿ44<ÿFDVÿWTrÿZUuÿXSsÿWSsÿVStÿSQqÿMJeÿCAWÿ7;Iÿ*2;ÿ+-ÿ*)ÿ-*/ÿIFRÿWQbÿVPbÿbZrÿeOeÿgQhÿgOgÿgPgÿiRhÿjSjÿjRiÿiPhÿgOfÿcLeÿeOiÿcNhÿjWtÿiUrÿq_}ÿUMaÿ9AJÿ+;Aÿ$8<ÿ59ÿ89ÿ89ÿ9:ÿ8;ÿ8:ÿ88ÿ89ÿ89ÿ68ÿ78ÿ78ÿ67ÿ68ÿ56ÿ0.ÿ-,ÿ)&ÿ(%ÿ'$ÿ'%ÿ&$ÿ$!ÿ$!ÿ&#ÿ'#ÿ)%ÿ($ÿ$!ÿ#ÿ&"ÿ'#ÿÿ'$ÿÿ ÿ)#)ÿ#ÿ)"ÿXHWÿ_N[ÿ^P[ÿ™�¤ÿ¢š®ÿ‰|‹ÿ¤�±ÿ¢š°ÿ…x…ÿ{kuÿ†y‡ÿ£š¯ÿ�‡˜ÿ—��ÿ§¡³ÿ¥ ²ÿ¦ ±ÿ§¡²ÿ§¢³ÿ¨¤´ÿª¥´ÿ«¦µÿ©£²ÿ|qvÿrcdÿPB9ÿQB9ÿQA8ÿN>5ÿL=5ÿO>6ÿO?8ÿO?6ÿP@8ÿO?7ÿRB=ÿUC>ÿSA>ÿ^JJÿfMMÿbIGÿXB=ÿ\G@ÿ_IAÿ^H>ÿ_GAÿdRYÿq`wÿ'#&ÿ ÿÿtc{ÿTFUÿ%%ÿ(&ÿ&#ÿ*$ÿ*&ÿ+'ÿ+%ÿ,%ÿ-&ÿ+%ÿ*%ÿ+'ÿ-*ÿ1.ÿ41ÿ31ÿ31ÿ32ÿ53ÿ44ÿ44ÿ54ÿ54ÿ86ÿ55ÿ65ÿ54ÿ43ÿ41ÿ2.ÿ1.ÿ-47ÿYL`ÿl[wÿo^zÿp\yÿhSoÿ^IaÿaKeÿcMfÿ`Jbÿ_Jbÿ^Iaÿ\G`ÿ]F_ÿ\F^ÿ[E]ÿ[F^ÿ\F^ÿ[G\ÿ_H_ÿaIaÿ_Iaÿ]G]ÿVBXÿaOcÿp^qÿlXjÿeRcÿYHXÿE8Eÿ*!%ÿÿ ÿ + ÿ ÿÿ"$ÿ'),ÿ88@ÿ=6<ÿ+23ÿ%47ÿ7?LÿMMhÿZVxÿXUuÿWTsÿXTsÿWSrÿVRqÿSQqÿLLjÿFE\ÿ5-5ÿ106ÿ#"ÿ*)ÿ'59ÿjSjÿiSiÿmUjÿlSjÿiQiÿgOgÿeKeÿdMfÿiToÿhUpÿl[vÿaTkÿbYqÿ6>Iÿ47ÿ54ÿ77ÿ67ÿ!6:ÿ68ÿ7:ÿ8:ÿ69ÿ68ÿ78ÿ78ÿ66ÿ55ÿ34ÿ0.ÿ0-ÿ..ÿ-*ÿ)'ÿ'%ÿ(%ÿ&"ÿ'#ÿ(#ÿ(%ÿ'$ÿ%"ÿ%!ÿ&"ÿ'#ÿ(#ÿ&"ÿ$!ÿ$ÿ'#ÿ)$ÿÿ''(ÿÿ ÿ0',ÿkYiÿhTdÿ\JWÿ>14ÿ‹€“ÿ£™°ÿ¤š®ÿ‘†–ÿ¤œ±ÿ£›°ÿ¥�²ÿ¥Ÿ³ÿ§Ÿ³ÿ¦ž²ÿ£›­ÿ…}�ÿª£¶ÿ¨¢³ÿ¨¡³ÿ¨¢²ÿ«¤³ÿ«¥´ÿ¬§¶ÿ«§µÿ¬¦µÿˆ‡ÿ^QJÿQB8ÿUF=ÿSD<ÿO@7ÿRB:ÿK=3ÿL<3ÿJ;3ÿE51ÿC53ÿI99ÿVFJÿdS_ÿiUbÿjT^ÿhV]ÿm[dÿjYaÿk]gÿfTUÿdPUÿ\HTÿs^sÿ#ÿ +ÿÿwdxÿTCRÿ(&ÿ(&ÿ($ÿ($ÿ*%ÿ+'ÿ+'ÿ,'ÿ,&ÿ+%ÿ+&ÿ*&ÿ*'ÿ,(ÿ-)ÿ.*ÿ2/ÿ41ÿ44ÿ44ÿ54ÿ55ÿ55ÿ66ÿ55ÿ11ÿ9FLÿ!65ÿ20ÿ31ÿ1/ÿ-+ÿ!--ÿPFXÿfUoÿm\xÿq]{ÿoZxÿbMhÿcMhÿfPjÿcMiÿaLgÿ`Jdÿ_Idÿ`Jcÿ_Iaÿ]G_ÿ]G_ÿ]G^ÿ^G^ÿ\F^ÿ^F_ÿ^G_ÿ\E]ÿVAXÿP>Sÿ\LaÿiWjÿiVhÿfSeÿF2;ÿK=Jÿ3.5ÿÿÿ  ÿ ÿ ÿÿÿ5/9ÿCALÿ/8<ÿ,,ÿ(49ÿ>DTÿQRmÿVRpÿWSqÿXRrÿWSrÿVQqÿRMlÿ:/?ÿFD`ÿ@?Wÿ36Dÿ*-ÿmTmÿjTlÿfPhÿdMeÿcNeÿgSkÿcPgÿ]Qgÿ\Xoÿ9;Dÿ1:Bÿ!58ÿ01ÿ23ÿ46ÿ57ÿ66ÿ44ÿ33ÿ44ÿ56ÿ44ÿ43ÿ43ÿ32ÿ20ÿ1-ÿ/,ÿ+'ÿ'$ÿ$ ÿ#ÿ&"ÿ%"ÿ#ÿ"ÿ$ ÿ)$ÿ($ÿ(#ÿ&"ÿ%!ÿ&"ÿ&!ÿ'#ÿ%"ÿ$ ÿ%!ÿÿ'!ÿÿÿ&#'ÿ' %ÿÿ4)/ÿeVhÿVFSÿF8@ÿE;?ÿ›�©ÿš�¦ÿ�’¨ÿŒ~�ÿœ‘©ÿš�§ÿœ’¨ÿ�“©ÿœ“§ÿ”ŠžÿŸ–¬ÿ£™°ÿŸ—«ÿ š­ÿ¢›®ÿ¥ž®ÿ§Ÿ±ÿ§¡±ÿ¨¢³ÿ¨£³ÿ¨¢²ÿznrÿI9-ÿH:.ÿJ>5ÿG;4ÿ?1(ÿF7.ÿJ;3ÿJ;3ÿH93ÿF85ÿ>0.ÿD42ÿVDEÿ[INÿVCJÿXCKÿXBBÿdLNÿgNPÿeMMÿUBCÿO>@ÿP>Iÿs^rÿÿ +ÿÿmZoÿVDTÿ **ÿ%!ÿ%!ÿ*%ÿ+&ÿ-(ÿ.(ÿ,'ÿ+&ÿ*$ÿ,&ÿ+&ÿ+&ÿ*&ÿ+(ÿ,'ÿ,'ÿ.*ÿ1/ÿ31ÿ42ÿ42ÿ55ÿ55ÿ54ÿ32ÿ22ÿ44ÿ22ÿ32ÿ32ÿ10ÿ/.ÿ.0ÿ<ÿ^JIÿ`KHÿ[GBÿ_IEÿ]FAÿ^F?ÿ]IAÿ[GAÿ^KSÿq\mÿÿ ÿÿs^sÿO@Nÿ'01ÿ*&ÿ,'ÿ*$ÿ-(ÿ,'ÿ)$ÿ,%ÿ+#ÿ*#ÿ+$ÿ,&ÿ+$ÿ+&ÿ+&ÿ*$ÿ*%ÿ*&ÿ+'ÿ-*ÿ1/ÿ32ÿ32ÿ33ÿ33ÿ22ÿ23ÿ01ÿ/1ÿ(:=ÿ22ÿ44ÿ55ÿ33ÿ-,ÿ&16ÿQEYÿdSmÿn[wÿm\xÿn\xÿjUpÿeNjÿN;MÿiQmÿeNjÿbLdÿaKdÿ`Kdÿ`Jcÿ_Jbÿ_Iaÿ^I`ÿ_I`ÿ_Gaÿ]F^ÿ\F^ÿ\F^ÿ\F^ÿZCZÿXCZÿRATÿ]MbÿhUhÿbL]ÿ^JXÿXDUÿK:Iÿ4-6ÿ" 'ÿÿÿ  ÿ ÿ ÿ ÿ!%ÿ1.3ÿVL[ÿYL\ÿH=KÿNCTÿUI[ÿQG\ÿA6CÿVPnÿRMlÿQMlÿSMlÿaTlÿMGXÿ4=Cÿ24ÿ10ÿ32ÿ45ÿ66ÿ36ÿ#58ÿ34ÿ44ÿ33ÿ21ÿ0.ÿ0-ÿ.,ÿ-+ÿ,)ÿ,*ÿ+)ÿ+)ÿ*(ÿ*(ÿ)(ÿ(&ÿ'%ÿ($ÿ'"ÿ%ÿ% ÿ(#ÿ%!ÿ"ÿ#ÿ"ÿ"ÿ!ÿ$ÿ%ÿ' ÿ'"ÿ)"ÿ&!ÿ&!ÿ&"ÿ& ÿÿ ÿ1,3ÿÿÿÿdQ`ÿlWgÿRBMÿ@52ÿ]NRÿŸŽ§ÿ™‰¢ÿ˜ˆ ÿˆu‹ÿgNWÿeKSÿkR]ÿ“…œÿ–‰¡ÿ”ˆŸÿ•‹¢ÿ—‹¢ÿ—‹¢ÿ—Œ¤ÿ—‹¤ÿ˜�¥ÿ—�¦ÿ—�¦ÿ˜�©ÿ˜‘¯ÿ˜“±ÿ™”²ÿš•´ÿœš¹ÿž�¿ÿŸ Âÿ˜˜¹ÿcYfÿRGGÿ]UZÿI@>ÿ_U]ÿQEDÿI=6ÿOA<ÿL=8ÿXMMÿjX^ÿ~elÿz_eÿ���ÿ©¥ºÿ¨£¹ÿ«¤¸ÿ«¤µÿ¯§·ÿ‹|Œÿs^pÿÿ ÿÿwdzÿVFVÿ*14ÿ($ÿ($ÿ*%ÿ*%ÿ+&ÿ,'ÿ,$ÿ+#ÿ*$ÿ*#ÿ+$ÿ+#ÿ,#ÿ,$ÿ*$ÿ)$ÿ*$ÿ*&ÿ*&ÿ+(ÿ,*ÿ--ÿ11ÿ24ÿ23ÿ25ÿ35ÿ13ÿ#57ÿ68ÿ34ÿ34ÿ23ÿ12ÿ11ÿ,-ÿ@=Hÿ\PfÿiZvÿn\{ÿo\{ÿeRkÿ#ÿYE]ÿdNiÿdNhÿaKdÿ`Jdÿ^Hbÿ_Ibÿ^Iaÿ]H`ÿ\G_ÿ\E]ÿ\E]ÿ[E]ÿ[E]ÿ[D\ÿZC[ÿYBZÿVAYÿQ=SÿNÿh`nÿLAAÿZNRÿQCFÿ@32ÿL<:ÿL;6ÿTEAÿpdjÿ©¡¸ÿ©¢¹ÿ«¥ºÿ¬¤´ÿ­¤´ÿ®¤²ÿ°¤²ÿ¯£¯ÿ‡v„ÿn[jÿÿ ÿ ÿlXiÿ\IXÿ.15ÿ)$ÿ+'ÿ+&ÿ*&ÿ*&ÿ+$ÿ+$ÿ*"ÿ)"ÿ*#ÿ+$ÿ)"ÿ)!ÿ*#ÿ)#ÿ+&ÿ+&ÿ+&ÿ+'ÿ+'ÿ-)ÿ.-ÿ00ÿ12ÿ13ÿ04ÿ03ÿ13ÿ24ÿ46ÿ45ÿ35ÿ34ÿ22ÿ11ÿ.-ÿ*)ÿ.4:ÿPG\ÿcPkÿm\xÿcQjÿ ÿN;QÿbLhÿdMfÿeNhÿdMhÿ`Kcÿ^Ibÿ`Jcÿ_Jaÿ_Jbÿ^H`ÿ\F^ÿ\F]ÿ[F]ÿ\E]ÿ[D\ÿZC\ÿZD\ÿXC[ÿWBYÿS>TÿQ?SÿWDXÿ^J]ÿeQeÿbM_ÿS?Lÿ=-4ÿO@Mÿ<2<ÿ&!(ÿÿ ÿ ÿ ÿ ÿÿÿ)$)ÿE7EÿA/8ÿH;KÿOBUÿVH]ÿ]Pfÿ!78ÿ44ÿ33ÿ33ÿ33ÿ10ÿ0.ÿ,)ÿ+*ÿ*(ÿ)&ÿ'$ÿ'"ÿ$ÿ!ÿ!ÿ ÿ ÿ"ÿ$!ÿ%"ÿ# ÿ$ ÿ"ÿ!ÿB><ÿ!ÿ$ÿ&!ÿ&!ÿ"ÿ"ÿ"ÿ#ÿ#ÿ$ÿ"ÿ#ÿÿÿÿÿ ÿ!ÿÿÿH>Gÿÿ ÿÿcQ`ÿoXiÿ_L[ÿC5?ÿ9+-ÿxk€ÿ’ƒ ÿ“„¡ÿ”…¡ÿ‘ƒ¡ÿ�ƒ¡ÿ�ƒ£ÿ�ƒ¢ÿ�…¤ÿ�…¥ÿ�…§ÿŒ…«ÿˆ„¬ÿЇ¯ÿŒˆ±ÿ�‹µÿŽŒ¶ÿ��¸ÿ‘޹ÿ’�ºÿ’’¾ÿ’“Âÿ“–Åÿ•˜Çÿ–˜Çÿ–™Äÿ•–Ãÿ•–Åÿ�‘»ÿ‹‰±ÿŠˆ­ÿRDDÿ„~šÿQEIÿI=<ÿH;=ÿ`OVÿO><ÿTB<ÿUC?ÿ^RRÿ¡–©ÿ§œ¯ÿ¦œ¬ÿ¦œ«ÿ§œ¬ÿ§œ«ÿ©ž®ÿhW_ÿ_IXÿeQ_ÿÿÿ +ÿ_N_ÿcOaÿ/02ÿ)#ÿ&!ÿ'!ÿ*%ÿ,'ÿ)#ÿ*"ÿ)"ÿ*#ÿ)!ÿ(!ÿ( ÿ(!ÿ-%ÿ-'ÿ+'ÿ*&ÿ*%ÿ*'ÿ.)ÿ-(ÿ,(ÿ,)ÿ,)ÿ+)ÿ/.ÿ11ÿ12ÿ35ÿ23ÿ12ÿ12ÿ//ÿ00ÿ01ÿ00ÿ10ÿ--ÿ+-ÿ@=Iÿ^LdÿlYvÿ ÿ`Plÿr^{ÿePiÿ^G`ÿ`FaÿdOiÿbLeÿ`Ibÿ^H`ÿ]I`ÿ]H`ÿ\G_ÿ]H^ÿ\F]ÿ]F]ÿ]F\ÿ\E\ÿZE[ÿZE\ÿ\F]ÿ[D[ÿZDZÿU@VÿOÿ[Kbÿ2&0ÿgVqÿlZtÿp]zÿ^L`ÿE0=ÿ^IcÿbLfÿ_Iaÿ`Jcÿ^Iaÿ]I`ÿZC[ÿQÿRBBÿPA>ÿTE?ÿbNMÿfPRÿšŠ ÿ¢™²ÿ¡—­ÿ¡–«ÿ¢–ªÿ¢–ªÿ¢–«ÿ¡•©ÿk}ÿdSaÿ%"$ÿÿÿp\mÿVIWÿ:4;ÿ("ÿ(#ÿ($ÿ*$ÿ*$ÿ*%ÿ*#ÿ)"ÿ)"ÿ)$ÿ*%ÿ+$ÿ*$ÿ*%ÿ+&ÿ,'ÿ+'ÿ-(ÿ+&ÿ)%ÿ(#ÿ)%ÿ)$ÿ*&ÿ+'ÿ*)ÿ*(ÿ+)ÿ-.ÿ.,ÿ//ÿ/0ÿ-.ÿ01ÿ21ÿ00ÿ.-ÿ,*ÿ*)ÿ()ÿ"#ÿ*/7ÿ91>ÿ\LcÿgTnÿiVqÿ4%.ÿ + +ÿ_NfÿE7Fÿ7*6ÿcMfÿ\G^ÿUBWÿ)ÿ0ÿ'$ÿ_I^ÿ_J`ÿ^G_ÿ]G^ÿ]H_ÿ^H_ÿ^H_ÿ]F^ÿ^F]ÿ]F]ÿ]G^ÿ\G^ÿ[E[ÿU?TÿS?SÿXDXÿiTjÿt`uÿr\qÿp[pÿmYnÿfRfÿ[M_ÿNBRÿF9GÿH:Jÿ0!'ÿÿÿ ÿ ÿÿ!ÿ$!ÿ$"ÿ# ÿ"ÿ#ÿ"ÿ"ÿ!ÿ#ÿ$!ÿ#ÿ#ÿ"ÿ"ÿ!ÿ"ÿ!ÿ"ÿ"ÿ!ÿ"ÿ$ ÿ#ÿ*,,ÿ244ÿ!ÿ"ÿ ÿ ÿÿ ÿ ÿÿ ÿ!ÿ"ÿ#ÿ%ÿÿ ÿ[Rgÿ  ÿ ÿÿ("(ÿgUdÿmYkÿVCOÿYP_ÿA5+ÿyrŠÿ’‹µÿ‘‹µÿ�Œ¹ÿtg€ÿgNTÿfMTÿ_ELÿˆ†µÿ‹ŽÁÿŠ�Ãÿ‹�ÄÿŠ�Çÿˆ‘ÈÿŠ�ÈÿŠ�ÇÿŠ‘ÈÿŠ“Ìÿ‰•Ñÿ‡•Òÿˆ•Óÿ‰•Ñÿ‰”ÍÿŠ”Ëÿ‹•Ìÿ‹”Ëÿ‹“ÉÿŒ•ÊÿŒ•ÉÿŽ•Éÿ�•Èÿ�–Çÿ‘–Æÿ’—Çÿ††­ÿWKMÿƒ|›ÿUC@ÿ`PSÿVEBÿZKOÿXKNÿs\cÿtVYÿqPOÿ�y‹ÿ¡—±ÿ¡•«ÿ¡”«ÿ¡”ªÿ ”ªÿ��¥ÿxfwÿ[M[ÿ ÿ  ÿ ÿgTiÿaQdÿ?6?ÿ&!ÿ'"ÿ'!ÿ)$ÿ+'ÿ-(ÿ*#ÿ*"ÿ)!ÿ("ÿ*%ÿ*%ÿ*&ÿ*%ÿ*$ÿ*$ÿ*%ÿ+&ÿ)%ÿ(#ÿ(#ÿ("ÿ(#ÿ(#ÿ(#ÿ'#ÿ'$ÿ+(ÿ+)ÿ+)ÿ,)ÿ-.ÿ-/ÿ//ÿ--ÿ*+ÿ$#ÿ"!ÿ#"ÿ )/ÿ31Cÿ00Aÿ()8ÿC8NÿTBWÿcRlÿI;Nÿ!ÿdRoÿ"!ÿ ÿK9Lÿ5'2ÿMEÿNDKÿ�ЏÿULSÿ�‰µÿ�‹¹ÿ�‹¸ÿŽŠµÿ‹†°ÿ{w˜ÿ|w˜ÿ‡…­ÿŒ‹»ÿŒŒ½ÿxu¡ÿ‹Œ¾ÿ�‘ÄÿŒ‘ÅÿŒ�ÄÿŠ�ÃÿŠ�Åÿ‹”Êÿ‹•Îÿ‹•ÎÿŒ•ÍÿŒ•Ìÿ�–ËÿŽ–ÌÿŽ—Íÿ�˜Îÿ�˜Ìÿ�—Ìÿ‘˜Íÿ�˜Ìÿ‘—Éÿ’—Éÿ“˜Éÿ“˜Éÿ��¼ÿ`S`ÿTDBÿRDHÿcV]ÿUFCÿQA<ÿO?8ÿWD?ÿTD<ÿ{q�ÿ —µÿ ”°ÿ¡”®ÿ¡”«ÿ “«ÿ¡“«ÿœŽ¥ÿr_qÿcQaÿÿ ÿ!ÿcOaÿiVhÿ?4>ÿ'#ÿ)$ÿ+&ÿ+(ÿ+'ÿ*#ÿ(!ÿ(!ÿ(#ÿ("ÿ)$ÿ)%ÿ+%ÿ*#ÿ*$ÿ)$ÿ(#ÿ*$ÿ+&ÿ(#ÿ'"ÿ'"ÿ($ÿ)$ÿ($ÿ*&ÿ*'ÿ*'ÿ)&ÿ*'ÿ)'ÿ)*ÿ**ÿ*+ÿ+,ÿ-/ÿ-0ÿ+-ÿ,,ÿ++ÿ,1ÿ$/7ÿ%-7ÿ*,<ÿ30=ÿWI`ÿL=Oÿ9+;ÿlXwÿ6*9ÿÿK=Pÿÿ;.Aÿ ÿÿ +ÿB2BÿbKeÿbKcÿdNfÿcMeÿbLeÿbJbÿbKcÿaKcÿbKcÿaKbÿbJaÿaIaÿaIaÿ_H_ÿ_H_ÿ_H^ÿ`H^ÿP;OÿQ@SÿcRgÿlWnÿqZpÿoXlÿjTgÿbK_ÿ=*5ÿ9+8ÿ5+5ÿÿ ÿ!ÿ"ÿ"ÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ!ÿ!ÿ ÿ"ÿ# ÿ$ÿ#ÿ"ÿ!ÿ!ÿ!ÿ!ÿ ÿÿÿÿ ÿÿÿ ÿÿÿÿ#ÿ$+*ÿÿ +ÿ ÿ0&,ÿp]nÿ`LYÿ_KXÿ_JYÿO>Iÿ:0+ÿ`Whÿ�‹¹ÿ�‡³ÿ‘жÿ�жÿ�‰´ÿ�гÿŽŠ´ÿ�‹·ÿ�Œ·ÿ�Š·ÿŽ‹¶ÿŒ‹¶ÿxtœÿ‹Š¸ÿŒ�ÀÿŒ�Áÿ‹‘ÃÿŠ�Âÿ‹’Åÿ�”Èÿ�–Éÿ‘–Éÿ‘–Éÿ’˜Êÿ’˜Ëÿ’˜Ìÿ’™Ìÿ’™Ìÿ“˜Ìÿ“™Ëÿ“˜Êÿ“˜Éÿ”˜Éÿ”™Éÿ“˜Éÿ”˜Çÿ•—ÆÿjatÿXKUÿbXkÿQCFÿPA?ÿSC>ÿWFBÿ[IEÿVD>ÿrepÿ¡˜µÿŸ•°ÿŸ”¯ÿŸ“­ÿ¡“­ÿ™‹¢ÿ|j~ÿkWjÿXJWÿÿ ÿÿr]nÿkWiÿ:.8ÿ,)ÿ*%ÿ+&ÿ*$ÿ*$ÿ*%ÿ(!ÿ'!ÿ'"ÿ(#ÿ)#ÿ*$ÿ*#ÿ&ÿ' ÿ("ÿ)#ÿ*$ÿ(#ÿ&"ÿ'#ÿ(#ÿ)#ÿ(#ÿ($ÿ)%ÿ+&ÿ*&ÿ(%ÿ*'ÿ*(ÿ*(ÿ)(ÿ)(ÿ,+ÿ/0ÿ16ÿ@HUÿ!45ÿ--ÿ++ÿ((ÿ&'ÿ&+ÿ%.ÿ*+5ÿ82>ÿ@3Eÿ_Meÿ2'3ÿ3(5ÿ^Mgÿÿ/!1ÿ #ÿ +ÿ0#-ÿYD[ÿbLfÿ`Jbÿ`Jaÿ`JbÿaKdÿaJbÿbJbÿaJaÿ`JaÿaIaÿaI`ÿaH`ÿ`G^ÿ_F^ÿ_G^ÿ^G^ÿ_G_ÿ]G_ÿ[F]ÿQ>SÿQ>TÿSAWÿbPfÿiVkÿ_J]ÿ;)1ÿTBQÿTAPÿG7Cÿ5*5ÿÿÿ ÿÿÿ ÿ ÿÿÿ ÿ!ÿÿÿÿÿ!ÿÿ ÿ!ÿ!ÿ ÿ#ÿ"ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ !!ÿK?Lÿÿ +ÿÿÿkZjÿo\lÿbO^ÿ;-7ÿ3+3ÿ5--ÿyu•ÿމ´ÿ�гÿŽŠ´ÿ�ˆ´ÿމ¶ÿ�‰·ÿ‹‰µÿ�‹¶ÿŽ‹·ÿŽ‹·ÿ�‹¸ÿ�޹ÿ‘�ºÿ�޼ÿ��¼ÿ��½ÿ��¾ÿ�‘¿ÿ�’Áÿ�’Äÿ‘”Äÿ’•Åÿ“–Æÿ”•Æÿ”–Æÿ•–Çÿ•™Êÿ•šÊÿ•šËÿ–™Éÿ•˜Çÿ•–Åÿ•–Ãÿ•–Âÿ——Äÿ•–Áÿ––Âÿ~w•ÿVFKÿqhÿO?<ÿ^NPÿWIGÿUFFÿVFGÿTFGÿ^QVÿ£˜µÿŸ”¯ÿŸ•®ÿŸ“­ÿ ”¯ÿyn‚ÿ<.9ÿnYkÿH>Fÿÿ +ÿ + +ÿdRbÿr]pÿ9-4ÿ,*ÿ' ÿ("ÿ(!ÿ)$ÿ*#ÿ'"ÿ( ÿ)"ÿ)$ÿ("ÿ' ÿ&ÿ(!ÿ*"ÿ)"ÿ(!ÿ'!ÿ'"ÿ'"ÿ'"ÿ'"ÿ)%ÿ)#ÿ(#ÿ)$ÿ*&ÿ*%ÿ(#ÿ($ÿ(#ÿ&"ÿ%"ÿ'$ÿ)'ÿ%%ÿ "ÿ&(ÿ('ÿ+*ÿ-,ÿ+,ÿ+,ÿ*,ÿ(*ÿ$&ÿ!#ÿ;8EÿN?Sÿ;/=ÿB4Dÿ`Oiÿ6(5ÿ<,7ÿ?+Iÿ*)ÿ5&0ÿ[G`ÿaKcÿaKdÿ`Jbÿ_I`ÿ_Iaÿ_Iaÿ`JaÿbJbÿ`I`ÿ_G_ÿ_G_ÿ_I_ÿ`I`ÿ`H`ÿ`G_ÿ_H_ÿ`I`ÿ_H_ÿ]H^ÿ^H_ÿ[E]ÿWBZÿK8NÿJ:NÿZMbÿVFXÿS?Pÿ[GWÿ]HYÿYASÿÿÿ!ÿÿÿÿ ÿ ÿÿ ÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ"ÿÿ ÿ*!%ÿn^sÿ*"(ÿ!ÿ"ÿ& "ÿ^M[ÿ`KZÿ=12ÿI?MÿzŸÿPFRÿ’Š·ÿ�‹´ÿ�еÿ�‹µÿŒ‰µÿ�ˆ´ÿ�‰´ÿ�Š´ÿ�Œ¶ÿ‘�¸ÿ„€©ÿŒ‡°ÿ”�¹ÿ“Ž·ÿ“�¸ÿ“�¸ÿ”‘ºÿ”�¹ÿ“�ºÿ“‘¼ÿ“’¼ÿ“’¾ÿ“”Áÿ–•Ãÿ—•Âÿ—•Âÿ—–Äÿ—˜Çÿ—™Èÿ–™Éÿ—˜Æÿ˜—Âÿ˜•½ÿ˜“ºÿ˜“ºÿ–‘ºÿ–“»ÿ˜“ºÿ�„¥ÿYMWÿshzÿWGGÿYGFÿP@<ÿTEAÿL=<ÿO@;ÿQ@;ÿ£—³ÿ ”­ÿ¡”«ÿ “«ÿ “ªÿ’‡œÿkaoÿq\mÿ4/4ÿ ÿ +ÿÿ\KYÿxbtÿ;.6ÿ*'ÿ& ÿ(#ÿ)$ÿ("ÿ' ÿ' ÿ(ÿ'"ÿ($ÿ&"ÿ'#ÿ)#ÿ)$ÿ% ÿ'"ÿ'ÿ' ÿ(#ÿ'"ÿ(#ÿ'!ÿ%ÿ%ÿ'!ÿ)$ÿ*%ÿ*%ÿ($ÿ'"ÿ($ÿ(&ÿ-,ÿ*'ÿ*'ÿ)&ÿ)(ÿ'(ÿ)(ÿ++ÿ,-ÿ,.ÿ,.ÿ+,ÿ,-ÿ,,ÿ''ÿ!ÿ(+2ÿC:IÿI;Nÿ^MeÿG7HÿVE^ÿI6QÿC.EÿQ?QÿO;OÿWBYÿ[E]ÿ^H`ÿ^H_ÿ^H^ÿ_Iaÿ`JbÿbKbÿaKbÿaKaÿ_H_ÿ^G_ÿ^H`ÿ`H`ÿ`I`ÿ_H_ÿ_G]ÿ_G^ÿ`G^ÿ^F^ÿ]F^ÿ[D]ÿZB[ÿT>VÿI5KÿLFÿlXhÿ`P\ÿlWdÿH8AÿD:CÿL@BÿWJQÿ’�½ÿ‘Œ·ÿ‘Œ·ÿ�‰³ÿ�|˜ÿŒu�ÿŠp†ÿ‡o†ÿ“�´ÿ’‹´ÿ“Œ²ÿ”�²ÿ“ޱÿ”�±ÿ”޳ÿ”Ž´ÿ•�´ÿ–�µÿ–�µÿ–’¶ÿ—“¸ÿ—’·ÿ˜’µÿ˜’µÿ—‘µÿ•‘¶ÿ•‘·ÿ–�¹ÿ•‘¹ÿ•�µÿ”�±ÿ“Œ¯ÿ’Œ¯ÿ“�²ÿ‘�¶ÿ‘Ž·ÿ“޵ÿ“Ž´ÿ•�¶ÿ–�·ÿ–�´ÿš’µÿ|pƒÿYIGÿYIFÿ^OPÿydoÿ‡mzÿŽp€ÿ}bkÿR@8ÿ“„”ÿ¤–«ÿœŽ¡ÿ¤”¦ÿ¡’£ÿ¡‘£ÿ‘€‘ÿpYiÿ1),ÿ +ÿÿ ÿL6FÿUC[ÿ]JcÿdRjÿfRlÿfOkÿhRmÿo[sÿ^I_ÿ]F_ÿcLeÿfOgÿfPhÿeOgÿeNfÿdMeÿdMeÿdMfÿdNfÿcKcÿdKcÿbLdÿbJbÿaH`ÿaH`ÿ`H^ÿ`H`ÿ_G]ÿ_F^ÿ^F]ÿ]F\ÿ\E\ÿ^F^ÿ]F^ÿZDZÿQ9ÿU<6ÿO:6ÿL94ÿ€r}ÿ©™°ÿ|r‰ÿ¦—©ÿ¤“¥ÿ¥”¥ÿŒzŠÿoYiÿ&ÿ ÿÿ+.9ÿ;.6ÿwcuÿ:,2ÿ(-0ÿ$ÿ& ÿ%ÿ'!ÿ( ÿ' ÿ' ÿ(!ÿ'"ÿ%ÿ*$ÿ+$ÿ ÿÿ$ ÿ("ÿ(#ÿ'"ÿ'!ÿ*$ÿ)$ÿ($ÿ)$ÿ(!ÿ(#ÿ'"ÿ'#ÿ!.-ÿ]MQÿBABÿ%ÿ%!ÿ'!ÿ&"ÿ%"ÿ(%ÿ&#ÿ%"ÿ&$ÿ&#ÿ%"ÿ$!ÿ%$ÿ$"ÿ&"ÿ(&ÿ+*ÿ+,ÿ*+ÿ(.ÿ$)ÿ))1ÿXKeÿZHaÿbNjÿjUrÿiUqÿiToÿr\wÿgQjÿaJbÿaKdÿfPiÿhQkÿhRlÿfPiÿePhÿfPiÿeOhÿfNgÿeLfÿeLfÿeLeÿdKcÿcJcÿbJbÿbJaÿcJbÿbIaÿaH`ÿ`H`ÿ_F^ÿ^F^ÿ^F]ÿ`G_ÿ_E^ÿ^C\ÿ ÿ ÿÿÿ ÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿ ÿÿÿÿ ÿ ÿ ÿ ÿ ÿÿÿ ÿ ÿ!ÿ!ÿ  ÿÿ ÿbSeÿ^M]ÿB29ÿ>.2ÿ>/5ÿM>Fÿ\JWÿ>38ÿ2(#ÿh_rÿ‘Š´ÿ‹…¬ÿ�Š´ÿ�‹¶ÿ�‹µÿ�Œ¶ÿ�‹¶ÿriŠÿŠˆ¯ÿul�ÿ“‘½ÿsiŠÿ‹„ªÿ^Tlÿ‰‚§ÿv–ÿ�Œ±ÿ‘‹°ÿ“бÿ“�²ÿ”�²ÿ“Œ±ÿ•Œ²ÿ–޳ÿ–Ž´ÿ”‹³ÿ“‹±ÿ”Œ±ÿ“�±ÿ“�²ÿ’�³ÿ‘Œ±ÿ”�³ÿ–�´ÿ—�µÿ”Ž´ÿ”�´ÿ”޵ÿ”�·ÿ”�¸ÿ”�¶ÿ”�·ÿ—‘¹ÿ€x›ÿxœÿ—“½ÿ\MWÿeYgÿK>:ÿWHKÿI;5ÿM>8ÿO?9ÿR@:ÿrdkÿ¦—±ÿjfƒÿ™Ž¤ÿ¡’¨ÿ™�£ÿrh}ÿ[QeÿKCPÿÿ ÿDH`ÿR=Hÿo[lÿ:,4ÿ)+/ÿ%ÿ!ÿ% ÿ'#ÿ'!ÿ(!ÿ("ÿ)%ÿ("ÿ& ÿ(#ÿ(#ÿ"ÿÿ ÿ' ÿ' ÿ'!ÿ'!ÿ("ÿ'"ÿ)%ÿ(#ÿ&"ÿ'$ÿ($ÿ&#ÿ,)ÿ+1/ÿ#.+ÿ&!ÿ(#ÿ(#ÿ'"ÿ&"ÿ'$ÿ&#ÿ*+ÿ-/ÿ*+ÿ''ÿ''ÿ&%ÿ&&ÿ('ÿ()ÿ*,ÿ+,ÿ+,ÿ)+ÿ'*ÿ$*ÿ"'+ÿODYÿdRpÿeSoÿhTpÿhToÿgQmÿjToÿnYrÿhRkÿ]HbÿfOjÿhRmÿkTnÿjTmÿhRkÿfPiÿhQkÿiQkÿhPiÿgOiÿfNhÿdNfÿcLdÿdKdÿbJcÿcIcÿcJbÿbKbÿ`Iaÿ_G_ÿ^F^ÿ`H`ÿaGaÿ`F`ÿÿ ÿ ÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿ ÿÿ ÿ ÿÿÿÿÿJ:GÿiTdÿgQ_ÿ^HUÿbNYÿVDQÿ>06ÿ.(#ÿ6-'ÿ„�§ÿ‹ˆ¶ÿ‹‰µÿŒŠ¸ÿŒŒ¹ÿŽ�»ÿŽ�»ÿ‚~§ÿ`VsÿŽ‹µÿSH`ÿ|wœÿYOhÿtmŽÿ[Vlÿzo“ÿf`~ÿ‘�¶ÿ�Œµÿ“޵ÿ“�´ÿ–޵ÿ“�µÿ‘‹´ÿ’‹´ÿ‘гÿ�гÿ�гÿ�‹µÿ�‹´ÿ‘Œµÿ�Œ´ÿ��µÿ‘Ž·ÿ’Ž·ÿ‘Ž·ÿ’�¹ÿ‘�ºÿ’�¹ÿ“�¹ÿ“‘ºÿ“‘¹ÿ“‘ºÿ’�¼ÿƒ�¨ÿƒ€©ÿ”�¿ÿne{ÿeZhÿM?<ÿM=9ÿH93ÿL=6ÿOA:ÿP@8ÿXHHÿ~t‡ÿkcvÿ",Eÿ#0Jÿ+Cÿ6>Zÿ,4Kÿ%>ÿ%8Tÿ(8Sÿ#)6ÿjS`ÿs[jÿ6+2ÿ+,/ÿ("ÿ& ÿ'#ÿ'$ÿ'!ÿ(#ÿ)$ÿ(#ÿ%!ÿ($ÿ,&ÿ'"ÿ&!ÿ ÿ!ÿ%!ÿ%ÿ("ÿ&!ÿ& ÿ(!ÿ(#ÿ&"ÿ'#ÿ)%ÿ%!ÿ&!ÿ&"ÿ&!ÿ&#ÿ&!ÿ%!ÿ'!ÿ%"ÿ%"ÿ&"ÿ)(ÿNJZÿTBQÿQ?OÿVEWÿVGWÿXHVÿVGTÿVHVÿXIWÿUFUÿSFWÿSEWÿTEXÿWHXÿZIZÿcTmÿ‚t‘ÿ™Š¬ÿ��°ÿˆy—ÿhSoÿjSoÿgRmÿeQmÿlXsÿnXsÿ_IbÿdNgÿfPjÿhRkÿkTnÿkTnÿhRlÿkSmÿkTmÿiQkÿhOiÿfNiÿfPiÿfNiÿfMfÿcKdÿcJdÿcJdÿaKcÿbJdÿaHaÿ`H`ÿbHaÿbHaÿ()ÿ ))ÿ ')ÿ!*+ÿ")+ÿ"*+ÿ!)*ÿ&&ÿ!**ÿ#,-ÿ"+-ÿ#,+ÿÿ ÿÿÿÿÿÿÿ ÿ ÿÿÿ!ÿÿ ÿ!ÿ+*-ÿ3(/ÿÿÿÿ/&-ÿiVgÿgRcÿgRaÿN=Hÿ8*2ÿC:IÿRObÿGBLÿ‡‡·ÿ‰‹¼ÿ‹Œ½ÿŒŒ¾ÿŠ�¿ÿ‹ŽÁÿŒ‘Äÿda~ÿc[vÿ_WnÿXPeÿXL^ÿe^{ÿ[Rcÿ{t˜ÿOERÿup‘ÿ‘޽ÿ‘Ž»ÿ“�ºÿ”�ºÿ“Žºÿ’޹ÿ“�»ÿ”�»ÿ“�¹ÿ’ޏÿ“�¹ÿ”�ºÿ•‘ºÿ•‘ºÿ”‘»ÿ”’»ÿ—”½ÿ˜”½ÿ•”¿ÿ““¾ÿ”“¾ÿ’‘½ÿwr—ÿ��»ÿ““¾ÿ“”Âÿ“”Åÿ“•Æÿ’•Æÿ““Äÿ„£ÿj_pÿPB@ÿPBBÿSSVÿK==ÿK>9ÿXGHÿXHJÿn`qÿoarÿoatÿEBRÿ!+Aÿ.;[ÿ&0Mÿ 5ÿ ÿÿÿ_L[ÿv`rÿJGÿ"ÿ84Aÿz~­ÿ€…´ÿqp•ÿ‹Œ¾ÿ‹Œ¾ÿ‹Œ½ÿ‰Š½ÿ‹�ÁÿieŒÿ€}«ÿB7Cÿ1).ÿ9)1ÿ-"(ÿ:,3ÿ4*2ÿ5+1ÿ6.7ÿ:./ÿUK]ÿ„€©ÿ��Áÿ‘�¿ÿ’�½ÿ“�¾ÿ”’¾ÿ”’¿ÿ”’½ÿ—“½ÿ—”½ÿ—”½ÿ—”¾ÿ—”¿ÿ—•¿ÿ—•Àÿ˜–¿ÿ™–Àÿ—•Áÿ–•Âÿ••Äÿ”“Âÿ‘’¿ÿSOmÿd^{ÿ’—Éÿ’•Çÿ“˜Íÿ�”Éÿ�”Èÿ‘–ÉÿŠŠ¶ÿ[NUÿG96ÿQFGÿSPVÿF98ÿO@Aÿr^oÿp\oÿsawÿiWkÿPARÿ+ÿ+Gÿ .Lÿ)Fÿ(Bÿ1ÿ;6HÿRBQÿ]K[ÿ`M_ÿ_K\ÿ]L\ÿWGWÿXKYÿZM\ÿZM\ÿ\L[ÿ^N]ÿ]M]ÿ_Pbÿ`Rcÿ`Raÿ^P`ÿ]O_ÿM@Pÿ:1=ÿI@Oÿ]Qcÿ`Rdÿ^QcÿbTfÿdUhÿ`SfÿaSdÿaSeÿcVgÿeYjÿfYkÿhYmÿi\nÿfYmÿi[nÿk[nÿi]pÿl_rÿl_rÿg[oÿj\oÿi[nÿpbvÿ}j‚ÿxe|ÿxd~ÿze€ÿ}h�ÿ{gÿp_wÿeWnÿVJ[ÿ]Naÿl[qÿxe}ÿ~i�ÿ{gÿuazÿjZsÿfYvÿ‰zšÿžŽ®ÿžŽ®ÿ‡u“ÿXE^ÿbNhÿdQmÿdPlÿeQmÿkVqÿgSmÿYD]ÿ_IcÿcLgÿeNiÿiRlÿjRlÿhPjÿhPjÿiRlÿjQlÿgOhÿfNhÿgOiÿgOiÿhNiÿgOhÿfLeÿdJdÿcIdÿcJdÿdJeÿ(#/ÿ)#/ÿ("/ÿ&"/ÿ+$2ÿ,#2ÿPEXÿzi‚ÿs_tÿr\pÿ\J\ÿL?Oÿ%(+ÿ ÿ ÿ ÿ ÿ ÿÿ ÿ ÿ!ÿÿÿÿÿÿfUiÿuc{ÿRBRÿ<.7ÿ6)-ÿ<-2ÿN;EÿcQ`ÿE7>ÿ.&%ÿ0-1ÿ„‹Äÿ…�Æÿ‡�ÄÿŠ�ÄÿŒ�ÂÿŠŽ¿ÿˆ‹¾ÿˆŠ¼ÿ……µÿUKdÿ=0*ÿ9)0ÿÿ=)2ÿÿ. &ÿÿ2&,ÿ"ÿB12ÿ*ÿ^Tgÿ“”Èÿ‘’Ãÿ�‘¿ÿ’’Àÿ”“¿ÿ”’½ÿ•“¿ÿ•”Àÿ”’½ÿ“‘»ÿ•“¾ÿ““¿ÿ““Àÿ”“Àÿ””Àÿ”•Ãÿ“•Åÿ’”Äÿ“”Äÿ’”Äÿ…‰´ÿ#%ÿÿŒ‘Æÿ‹‘Äÿb`‡ÿ�“ÉÿŽ”Èÿ�•Êÿ�“Æÿ^U_ÿJ<6ÿI<7ÿK=9ÿI:6ÿgS_ÿq[mÿq^rÿ`RaÿI;Hÿ ÿ)".ÿ!+Hÿ/Mÿ*Gÿ)Cÿ2+<ÿ)ÿ/0Gÿ0)9ÿ3+8ÿ1)5ÿ/%2ÿ,#/ÿ+$1ÿ+&3ÿ-'5ÿ.)5ÿ.(5ÿ+%1ÿ,(5ÿ*&5ÿ+$2ÿ,#0ÿ*"/ÿ)".ÿ-&3ÿ.'4ÿ-%5ÿ/'5ÿ/(6ÿ.'5ÿ.'5ÿ0)7ÿ2+:ÿ/*8ÿ0(6ÿ1)7ÿ0)7ÿ0*8ÿ1)8ÿ0(5ÿ2*8ÿ3);ÿ5,;ÿ5-<ÿ7/?ÿ5,>ÿ7.@ÿ8/@ÿ:0@ÿ90Aÿ:0Bÿ:/AÿWG]ÿk„ÿk†ÿ}jƒÿs`xÿOARÿE8Fÿzjƒÿyd~ÿ€k…ÿjƒÿ~h‚ÿr`yÿk]wÿ_QoÿŒ|›ÿ›Œ¬ÿœŒ®ÿ…u’ÿ\I`ÿaLgÿfOjÿeOkÿeOkÿgSoÿp\vÿ`JcÿYE\ÿ^H`ÿ_IbÿcLeÿgQiÿfOhÿeMgÿdNgÿeNgÿdNhÿcLeÿeMfÿfMfÿfLfÿdKfÿeKeÿcJdÿbHaÿbIbÿI;HÿKAÿ?3/ÿB23ÿ:,,ÿE55ÿ0$!ÿ=,-ÿ.%#ÿB23ÿ4&&ÿ@/1ÿ8)"ÿZRfÿ“—Êÿ‘“Äÿ••Äÿ•—Ãÿ—–Âÿ•”Âÿ•–Âÿ••Äÿ••ÄÿMF]ÿ‘�¾ÿ”•Âÿ”•Åÿ“–Æÿ”—Æÿ“—Çÿ’•Çÿ’•Æÿ“•Æÿ‘•Çÿ„ˆµÿ  ÿÿ|�´ÿƒŠ¿ÿmnšÿ‡ŒÃÿ�”ËÿŽ”Ëÿ‘˜Ïÿid{ÿM?:ÿOA=ÿXHJÿiTaÿs^qÿq]qÿcQdÿK>NÿF8Fÿ6+4ÿB4=ÿ%)Aÿ .ÿ1ÿ%?ÿ@3Dÿÿ+3Mÿ@@WÿC7Fÿ>4AÿHKÿK=KÿJ=KÿG9FÿD6Cÿ5+5ÿB8DÿB7CÿD7DÿB6Bÿ@5BÿA5CÿA4Cÿ=2Aÿ?4Bÿ@5DÿK=IÿG:GÿB6Dÿ?3?ÿ?2?ÿE8FÿC7FÿC8GÿB7FÿF:IÿH;IÿK?NÿPCSÿPBRÿOBSÿL?OÿM@QÿL@Pÿ>4?ÿODSÿKAQÿMASÿOBSÿQDVÿZJ]ÿn[rÿr_wÿsawÿubyÿvb{ÿs`yÿvb{ÿq]tÿr^sÿwbyÿwbzÿs_wÿgVnÿhZqÿeXqÿ‚r�ÿ›Œ­ÿž�°ÿ�q�ÿ\HaÿbLgÿeOkÿfQlÿeQlÿgRnÿn[uÿfRkÿYD[ÿV@Xÿ[E\ÿ]G_ÿbKdÿdMgÿbKdÿ_IbÿaJdÿaJdÿaHbÿaHbÿaHbÿbHbÿaIbÿaIcÿ`G`ÿ_F_ÿXHUÿYGVÿ=/9ÿB1:ÿ?.8ÿbShÿq\uÿt_wÿjUiÿkVjÿQDSÿNBQÿ82;ÿÿ ÿ ÿ ÿ ÿ ÿ ÿÿÿÿ!"ÿ +ÿ ÿ +ÿ/'.ÿo[nÿmYjÿeQ^ÿnWdÿ\JVÿ6+-ÿ?9Eÿkj†ÿ:0,ÿ��¿ÿ�“Äÿ�”Ãÿ�“Ãÿ‘�½ÿ‘ƒ§ÿ�~œÿxe€ÿ‰u’ÿK@Oÿ(ÿ3',ÿ+!ÿ2&*ÿ)ÿ, #ÿ+ÿ,##ÿ7*)ÿB21ÿ9'(ÿB.+ÿVNdÿ–šÍÿ‘”Åÿ’”Äÿ’”Äÿ’•Äÿ“•Åÿ“•Åÿ“•Åÿ†€ªÿ!ÿ~«ÿ‘”Åÿ’–Çÿ’—Éÿ’—Éÿ’—Éÿ’–Çÿ’–Çÿ‘•Çÿ‘”Çÿ‹ŽÀÿ72Aÿÿ�—Ïÿ�•ÍÿŠ‘Çÿ�”ÌÿŽ”Ëÿ�–Êÿ”˜Ìÿ‰y—ÿvbnÿmYfÿs^qÿt`sÿlXkÿWEWÿD5GÿL?OÿJ;Gÿ4&-ÿ9*2ÿ-ÿ&ÿ'ÿ%)=ÿ_M_ÿ@4Eÿ)/Hÿ7=Wÿ)#-ÿ'!)ÿ)#,ÿ)#*ÿ+$+ÿ+$+ÿ4*2ÿI;IÿG:HÿD9FÿUFWÿM?Mÿ8,6ÿ' 'ÿ%&ÿ' )ÿ' )ÿ&(ÿ'!*ÿ,#-ÿY@KÿZBJÿJ;IÿL;IÿK;IÿI:Hÿ2(2ÿ.&-ÿ2'1ÿ;-;ÿB3BÿB4?ÿI8CÿI8EÿJ9GÿJ9GÿM>LÿMAPÿB6BÿWGUÿSCQÿL=KÿN>LÿP@LÿJ9FÿI:GÿO=LÿQ>LÿRAPÿYGVÿ^L]ÿaO`ÿN=KÿKLÿÿ +ÿ +ÿÿhWhÿdRbÿlYhÿYHSÿ6)-ÿHAKÿ–“Àÿ�Ž´ÿvrŒÿ••Áÿ””Àÿ“”Áÿ‘”Áÿoe~ÿ^?Eÿ^CHÿI4<ÿ=0)ÿ=*2ÿÿ;,7ÿÿ2$+ÿÿ.!'ÿÿ:**ÿ0#"ÿD2-ÿH31ÿ=++ÿKBVÿ—œÏÿ–šËÿ–šËÿ–šËÿ”šÊÿ•™Êÿ•™Êÿ˜œÎÿOFZÿÿqm‘ÿ‘–Çÿ”šÌÿ“šÌÿ“˜Íÿ�”Èÿ�•Èÿ‘–Çÿ�”Çÿ‘”Æÿ�”Åÿebƒÿ1(7ÿ†‰¹ÿ�°ÿ�”Êÿ�”Çÿ�’Åÿƒƒ®ÿj]uÿsYhÿt_qÿq]qÿgUgÿSBUÿ?2Bÿ?2CÿQBQÿSDLÿ;/3ÿV@JÿYBLÿC;Gÿ%ÿ&ÿ+,<ÿF4@ÿcQbÿ1ÿ!+Cÿ%&3ÿ$"-ÿ84Bÿ]RgÿaVlÿ]Thÿk^vÿyh�ÿrd{ÿl^sÿsbzÿtd~ÿtf~ÿYL`ÿWJ]ÿTI\ÿTH[ÿTI[ÿXJ_ÿWK_ÿ]Obÿsazÿk[sÿhXnÿn\rÿiXnÿm]sÿaQfÿ`Qfÿp^qÿt`tÿt`sÿt`vÿvbvÿvbwÿ{h~ÿ{h‚ÿp`vÿhYkÿxf{ÿxezÿzf}ÿydyÿzbwÿwawÿvbxÿu`tÿxdxÿ{f|ÿ|i‚ÿk…ÿzhÿn_uÿxg|ÿr`tÿ€m†ÿ�oˆÿƒp‹ÿ}j†ÿ~qŒÿ}pŒÿui†ÿ��±ÿœ�¯ÿœŒ®ÿ…t”ÿ`MjÿaLhÿePkÿfSnÿhUpÿgToÿjWrÿp\wÿoYsÿXC[ÿZD]ÿ\E^ÿ\F_ÿbLeÿbKeÿ`JcÿbIcÿcIdÿbJdÿbJcÿ`Haÿ_HaÿaHbÿbJcÿC4BÿK/2ÿ?05ÿF=Nÿ“•Åÿ”˜Êÿ•œÎÿ”›Îÿ”™Ìÿ’—Éÿ“—Éÿ“˜Ìÿ@=Qÿÿ~�¯ÿŽ”ÇÿŽ“Èÿ�“ÈÿŽ“ÇÿŽ“Çÿ�’ÅÿŽ’ÆÿŽ’Æÿ�“Æÿ�”ÇÿfdˆÿXRmÿ@9JÿG?Vÿ�|¤ÿ~s•ÿyi‚ÿJ8Cÿ ÿTDSÿ\K[ÿVEXÿD7HÿB6HÿL?RÿVGXÿQAPÿD6=ÿWFQÿYHUÿ9,8ÿA7Fÿ+ÿ +&ÿ##0ÿÿB7Eÿ!1ÿ1ÿ75Hÿ<8HÿQG[ÿ{iƒÿ‹|™ÿ�� ÿ‹z—ÿ|kƒÿ~k„ÿ{h�ÿ~k„ÿzgÿtbyÿvcyÿubyÿo]tÿkYpÿp_vÿud|ÿvd|ÿxe|ÿvdyÿvczÿwe}ÿvc{ÿr`vÿvdzÿve{ÿwf|ÿve{ÿxf}ÿyh€ÿvf}ÿwf~ÿwg~ÿwg~ÿwf~ÿyf€ÿyg€ÿxe~ÿyhÿzi�ÿyg�ÿyh€ÿwf€ÿfYnÿKDQÿA('ÿS9Mÿ>6GÿD:IÿA7GÿA9KÿB7IÿA6Gÿ@4Dÿ?4Bÿ6-:ÿxf~ÿmYkÿO>LÿO>LÿR?LÿR@MÿP=KÿP=KÿK;FÿN>JÿQ@LÿM=JÿO=JÿO=JÿN=JÿP>KÿNSÿ\M]ÿeUcÿaTaÿ^O_ÿ]K\ÿfWmÿ…€¦ÿ•–Æÿ“”Ãÿ@ÿ;2BÿF9GÿJ=Jÿo^sÿ`ShÿSHYÿYK\ÿeXhÿgZlÿgYkÿfXjÿ_RdÿXK]ÿWK^ÿTI^ÿ>=Qÿ+,>ÿ''9ÿ('8ÿ$$3ÿ$$2ÿ62CÿUK^ÿXL\ÿWK]ÿ`UgÿcWlÿgYnÿdXmÿbWjÿ`TfÿYL_ÿwe}ÿs_rÿRCPÿTERÿOAPÿM@NÿSETÿK?JÿI=GÿI=HÿOANÿL@LÿNBPÿMANÿL?NÿL?MÿJ>KÿL@MÿJ?KÿIJÿRERÿB3;ÿUDTÿVCTÿTBPÿTAPÿXEVÿWFXÿZGYÿZGZÿZFYÿWEXÿWDWÿMCYÿHFdÿh_}ÿzm‰ÿ�sŽÿ{lŠÿeTqÿhVtÿhSpÿlWtÿgTqÿfRoÿmZwÿua|ÿiUmÿ[F^ÿ[F]ÿ_HaÿbJdÿbKfÿbLgÿcLfÿbLfÿcLfÿeNgÿ\JYÿC7Cÿ^L^ÿt`vÿp\qÿYHWÿK:Fÿ\K[ÿ\L\ÿMAPÿ@7Gÿ<3Aÿ + +ÿ?3AÿUE\ÿcRiÿp_yÿtb€ÿo]vÿ  +ÿÿpaxÿn^rÿlYmÿfQbÿUAMÿJ9Dÿ4'/ÿ=1<ÿldtÿ¤›³ÿH=>ÿ…z�ÿ§ž¸ÿ¥�¸ÿ¤œ¶ÿ¢šµÿ ™¶ÿž—µÿ¡š¹ÿthÿMMÿE8Eÿ:/=ÿ6-;ÿ2+7ÿÿÿD8GÿK=KÿRBOÿR@MÿG5AÿK:EÿkXnÿXJ^ÿ5*3ÿ0$,ÿD>JÿICPÿG@OÿHBQÿHCQÿLGVÿKETÿEBRÿA@Wÿ02Dÿ./Cÿ--Aÿ)*=ÿ++=ÿ3/@ÿIBSÿUHWÿKCSÿICSÿIBTÿIBSÿJBQÿOGTÿI@KÿfZmÿm`xÿcQaÿ""ÿ'%ÿ ÿÿ.22ÿÿÿÿÿ!ÿ ÿ ÿÿ ÿÿ ÿÿÿÿÿÿ ÿ!ÿ ÿ ÿ"ÿ ÿ#ÿ#ÿ$ÿ#ÿ% ÿ ÿ ÿÿÿÿ ÿÿ!ÿ$ÿÿF9EÿP>MÿUCRÿUDSÿWDUÿXEWÿXEWÿWEXÿXEXÿVEWÿSCUÿJ>SÿCB]ÿEA\ÿ]Toÿuiƒÿ‚r�ÿ�qŒÿhYtÿQ?[ÿaMjÿiUsÿgTpÿdQnÿ_LhÿkVqÿq]vÿcNfÿ^G`ÿbKeÿbLfÿbLeÿcLfÿcLfÿcMfÿeOhÿhTiÿfSeÿk\nÿu`rÿaO`ÿaN_ÿ]IZÿZFUÿS?MÿWFUÿYHZÿSCRÿÿ5,8ÿ.&4ÿ/&3ÿ2(5ÿ7-:ÿC7Gÿ#'ÿ/)8ÿqd�ÿ~p�ÿ‹€£ÿ“‹±ÿ”‹¯ÿˆ ÿ…|šÿƒy—ÿ‰�ÿŽ™ÿ{m‚ÿ¨Ÿ¸ÿ¦�·ÿ¦�·ÿ¤›¶ÿ¢™´ÿ —µÿž˜¶ÿˆ—ÿM:=ÿF65ÿL=?ÿ;,-ÿH79ÿ<.0ÿ<.-ÿB03ÿ9*)ÿG88ÿ,ÿF23ÿ@+)ÿT76ÿG7Aÿ?)(ÿE:JÿGNÿE6Cÿ<.;ÿ8*7ÿ2'4ÿ0'5ÿ1)6ÿ6,:ÿ7-<ÿ91>ÿ?5BÿF;IÿG:Eÿÿ&$ÿUEQÿO?KÿJ8CÿI8BÿG5>ÿ`M^ÿgUiÿ\Ncÿ>1=ÿ;0:ÿ8:Iÿ6Oÿ>Rÿ//@ÿ+,<ÿ));ÿ((9ÿ+);ÿ1/Aÿ98Jÿ:;Mÿ>CUÿAFZÿCEYÿ>CTÿCUÿ9>Oÿti�ÿpc|ÿlXkÿ"#ÿÿÿÿ!ÿ!ÿ"ÿ!ÿ"ÿ"ÿ"ÿ$ÿ#ÿ!ÿ"ÿ& ÿ% ÿ% ÿ&ÿ)#ÿ%ÿ#ÿ"ÿ&!ÿ$ÿ$ÿ%ÿ%ÿ#ÿ"ÿ"ÿ!ÿÿÿ +ÿÿ ÿ ÿ ÿ +ÿ ÿÿ&),ÿE8DÿO>MÿR@PÿTARÿWDVÿWDWÿWCVÿVCWÿSATÿP>Pÿ?1Bÿ81Dÿ@=VÿD?Wÿ]Qlÿ|mˆÿ‰x“ÿ�|˜ÿƒr�ÿ`Liÿ\FdÿgQoÿgSpÿ\HeÿSB]ÿdRnÿr^{ÿpYtÿ^HaÿbLeÿdMfÿeLfÿhOiÿgPjÿfOiÿRBRÿUCTÿTAQÿUBPÿXESÿ^JZÿbNaÿB1>ÿcP`ÿXFUÿP@LÿH7Aÿ&ÿN?Lÿ@3?ÿ5*6ÿ<2>ÿ7-:ÿ5/<ÿ,&2ÿ)$1ÿ ÿ$(ÿ.$/ÿ7*9ÿF9Lÿ}r’ÿ¡šÀÿœ”»ÿ„v–ÿbQfÿB5Fÿªž¶ÿ¨ž¶ÿ¥œµÿ¥›µÿ¥œ¶ÿ¢š¶ÿ�•²ÿRITÿÿ!ÿ!ÿÿÿÿÿÿ!ÿ&ÿ5%$ÿE0/ÿ7"!ÿQ65ÿGOÿIÿ=8Gÿ;=NÿDI_ÿAG]ÿGJ`ÿ]Zsÿ]XnÿPLbÿJHZÿ00<ÿ/-:ÿ3-<ÿ1,9ÿ83AÿD=OÿPGYÿ`XlÿMJ]ÿII_ÿRPfÿOOdÿLPeÿJNbÿFK]ÿqk„ÿpf€ÿq\rÿ+'-ÿÿ ÿ"!ÿ!ÿ%!ÿ%"ÿ%#ÿ'$ÿ(%ÿ'$ÿ(&ÿ*)ÿ+*ÿ,*ÿ+)ÿ*'ÿ+'ÿ(%ÿ+'ÿ*&ÿ(%ÿ(%ÿ'$ÿ)&ÿ)%ÿ'#ÿ$!ÿ&!ÿ$ ÿ"ÿ!ÿ ÿ ÿ ÿ +ÿ ÿ ÿ ÿ ÿÿÿÿ%!#ÿMPÿF7Gÿ5*6ÿ:2DÿF@WÿKD[ÿYQjÿna|ÿ‚rŽÿŽz—ÿŠx”ÿ^LhÿXGcÿcOmÿhTqÿcPlÿVDbÿaNjÿq\xÿt^zÿcMgÿbJcÿeLeÿdLeÿfNgÿgOiÿSAQÿXETÿ_L[ÿbN_ÿiThÿq\pÿ\I\ÿ[IZÿgSeÿiUhÿdRfÿE2<ÿ+ÿ=/:ÿB4?ÿ+!)ÿ?1;ÿMÿe\xÿ�•»ÿš�´ÿ{mˆÿKATÿ=4FÿD9Kÿ¨œ´ÿ¨ž¶ÿ¦œ´ÿ¦œ´ÿ¤š³ÿ£˜²ÿdU]ÿ?11ÿ#ÿÿ$ÿ ÿ#ÿ + ÿ%ÿÿ(ÿ(ÿ3"!ÿA+-ÿJ0.ÿD//ÿG>Oÿ;.4ÿG=NÿJ3Aÿ@4BÿC6DÿF8Fÿ@3>ÿJNÿQ?PÿQ@QÿTASÿSARÿTBSÿR@RÿL2>ÿJ=IÿA5AÿE@PÿGEXÿ32BÿzmŠÿH7CÿK:GÿH7BÿE3=ÿ=-7ÿJ;Iÿ_[pÿb\sÿpf}ÿ|nƒÿl`tÿ[PcÿTJ\ÿNEWÿOEXÿODUÿPFWÿWK\ÿ]OaÿiXkÿuexÿtg~ÿŠƒ¥ÿ�ˆ®ÿ�ˆªÿ‘‰§ÿ’‡¤ÿ’ˆ¡ÿ|sŒÿwk‡ÿqbxÿ^M^ÿ""ÿ)"*ÿ,#.ÿ.$.ÿ2&0ÿ2'0ÿ4'/ÿ4(3ÿ3(4ÿ1&1ÿ3(4ÿ5*7ÿ6*7ÿ7+8ÿ6,:ÿ6-;ÿ6-9ÿ9-:ÿ8,:ÿ7+9ÿ7,:ÿ7,8ÿ7-8ÿ9.9ÿ6+6ÿJ=Kÿ„q‹ÿ€o‰ÿ�o‰ÿcYkÿ(%ÿ&"ÿ% ÿ%ÿ$ÿ$ ÿ$ÿ#ÿ"ÿ#ÿ!ÿ ÿ"ÿ$"ÿ6.6ÿJ;IÿN6JÿLE^ÿPIcÿPE_ÿaTmÿpazÿƒoŠÿ‰v’ÿ�o‰ÿWE_ÿZFbÿiTpÿlWsÿePkÿaKhÿfQmÿq\yÿr]wÿjUmÿ`G`ÿdLeÿqa|ÿud~ÿr_wÿL?QÿH9HÿN=KÿP?NÿUBQÿUBQÿP@MÿJ9HÿH8IÿRDVÿ\L`ÿcSfÿYK\ÿVEYÿhWjÿeRgÿjXlÿOAPÿ-"-ÿ8/<ÿwi‡ÿœ�·ÿ–аÿue‚ÿYI`ÿ9.>ÿ@5Fÿ>2Cÿ9.?ÿ ”ªÿ¨œ³ÿ¨�´ÿ¨œ²ÿ†w‹ÿSDRÿ?.)ÿ:*+ÿ"ÿ1$ÿ ÿ'ÿ"ÿ(ÿ. ÿ%ÿ;*)ÿ,ÿB++ÿ6)2ÿE,-ÿ<.9ÿD:Mÿ<2Dÿ^Maÿzf|ÿ“…¥ÿš�°ÿzh‚ÿJ:HÿOAOÿ,$,ÿ#%ÿ%&ÿ("*ÿH;FÿbQaÿiWiÿgSdÿq]nÿ}gzÿn\nÿ1.9ÿ!!+ÿ "+ÿ&ÿ!+ÿ !)ÿ2.7ÿ93;ÿ;3=ÿ<3=ÿ6/9ÿ!&ÿ3/=ÿŒ‚Ÿÿ�‚ ÿzs‹ÿ2+9ÿI:Hÿ9-:ÿC3Aÿ?0=ÿ6*5ÿ:/;ÿ6-:ÿ3,8ÿ:3@ÿ7/>ÿ90@ÿ;4Cÿ<4Dÿ>5Dÿ;4Bÿ<3Bÿ;2Bÿ92Aÿ92?ÿ70=ÿ;3Bÿ7/=ÿ6,:ÿ;2@ÿ>4Bÿ@4CÿA6EÿA5DÿB7Hÿ>5Eÿ?7HÿC9Hÿ<1=ÿ@4@ÿC7DÿF;IÿLBOÿOCQÿJ@MÿJ?LÿJ?KÿMAMÿQGSÿRGTÿRHVÿTJWÿWJZÿTHVÿSHWÿSHWÿVK\ÿTIYÿTGXÿRFVÿPDSÿPESÿI>Jÿ<4?ÿve|ÿ†qŒÿƒr‹ÿ„t�ÿ??Jÿ$ ÿ% ÿ%ÿ$ÿ$ÿ"ÿ"ÿ#ÿ"ÿ"ÿ"ÿ#ÿ#ÿ"!ÿF9HÿL=KÿL=LÿN=MÿO=NÿR@QÿSAQÿWEVÿUCTÿM=Kÿ@2?ÿ2'2ÿ=5GÿLE\ÿME^ÿOF^ÿSIbÿcVpÿue€ÿ‚pŒÿƒr�ÿjXsÿ`JfÿhRmÿmWsÿiSoÿaMjÿePlÿlXuÿs_{ÿs^zÿdOhÿ`TjÿTDVÿZGYÿTBRÿI8FÿD3AÿC4?ÿE4AÿE5BÿC5BÿH9IÿG9IÿK=OÿOARÿP@PÿH9IÿN3BÿA4Cÿzgzÿu`pÿƒm€ÿ|i{ÿ]K[ÿPAMÿP>DÿJ6?ÿ@17ÿA28ÿ<,0ÿ@05ÿ6&-ÿ<).ÿ>.2ÿ7')ÿG49ÿD14ÿL8:ÿSBMÿW>CÿTANÿQAQÿQBRÿlZnÿ„q‹ÿ‰z–ÿ„s�ÿRAPÿ:.8ÿ5+3ÿÿ!ÿ ÿ ÿ?3=ÿUCOÿTANÿXCOÿXFPÿN>HÿK=Fÿ !ÿÿ'%-ÿ43=ÿ74@ÿPJ[ÿSPcÿ-.:ÿ!*ÿ!)ÿ&(1ÿA=LÿicwÿŠ~—ÿ‡y’ÿ†z�ÿ+*6ÿOAQÿ5*7ÿ=1?ÿ>2?ÿ8,8ÿ4,8ÿ )ÿ'ÿ#!+ÿ'ÿ! -ÿ$"1ÿ$"/ÿ"!-ÿ!!-ÿ"!/ÿ*ÿ'ÿ'ÿ)ÿ)ÿ&ÿ(ÿ$#0ÿ%%1ÿ&'3ÿ$$2ÿ%%1ÿ%&2ÿ$$3ÿ#$2ÿ#"-ÿ)#*ÿ*$-ÿ-)2ÿ/,4ÿ307ÿ51:ÿ2.6ÿ0,4ÿ/)0ÿ5.6ÿ:3=ÿ71;ÿ84=ÿ:6@ÿ<6Aÿ?9Cÿ?8Aÿ@8Dÿ?9EÿC8Aÿ4-5ÿ607ÿm^tÿ�m†ÿƒq‹ÿ„s�ÿ|l†ÿ!*.ÿ#ÿ&ÿ$ÿ "ÿ$ÿ% ÿ$ ÿ$"ÿ"ÿ!ÿ!ÿ ÿ ÿ&*-ÿI:HÿI9IÿJ:JÿL;JÿM;KÿO=NÿQ?OÿP?NÿO=MÿI9Fÿ;-:ÿ0&1ÿ@8KÿNF_ÿUMgÿTKdÿTKdÿ_Skÿm_wÿ}l…ÿ„qŽÿta}ÿZHdÿcOjÿlVrÿkVrÿgRnÿeNkÿhRoÿpZwÿu_{ÿhXpÿdRjÿl]wÿl]vÿj[uÿn_xÿk]xÿn_|ÿm_|ÿm`{ÿm`{ÿVI]ÿo_{ÿjYqÿhXoÿhYpÿgYrÿj\tÿi[rÿiYqÿqf€ÿ–�³ÿ|t˜ÿ™�·ÿ•Œ°ÿ…{žÿŽƒ¦ÿŒ�£ÿ�£ÿ�‚¤ÿ‹�£ÿ�…©ÿŒ�¤ÿqgƒÿŠ€¢ÿ�„ªÿ‘…ªÿ”ˆ­ÿ�…©ÿ�‚¥ÿ‹�£ÿŒ‚¤ÿˆŸÿ‡|œÿ‡{™ÿqc~ÿ�{˜ÿ�x’ÿ‘{•ÿ–~˜ÿš€™ÿœƒœÿŸƒœÿ�„�ÿ›ƒ�ÿ“šÿ—…¢ÿ��­ÿœ�®ÿ�}˜ÿ?4=ÿo\tÿ]PdÿUK]ÿUHYÿTGXÿMAOÿOBOÿ^L^ÿaPaÿbQbÿaPaÿ^N]ÿRDSÿXJ[ÿrf{ÿyk„ÿyi€ÿp`vÿdSeÿzh~ÿdUgÿMDSÿLBSÿ_Sfÿrdxÿwg}ÿwf}ÿwf~ÿsbvÿ<3?ÿQBPÿ5)6ÿ:.=ÿ5+8ÿ;/<ÿ8-:ÿ ÿ ÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿ!ÿ%ÿ'ÿ*ÿ *ÿ*ÿ+ÿ+ÿ*ÿ"*ÿ#'0ÿ(+5ÿ*.:ÿ,2>ÿ.6@ÿ3:Cÿ3;Eÿ3:Eÿ5:Fÿ7Kÿ8>Kÿ5;Eÿ6Iÿ8=Iÿ8=Jÿ5MÿNÿ9.7ÿ+$+ÿ4+4ÿ2)0ÿ9/9ÿE8DÿF8DÿG8EÿH8FÿE7CÿC5BÿA6Aÿ1*2ÿ90:ÿI:GÿL=KÿN@MÿN?MÿF9GÿK:KÿI9HÿE5DÿC5Aÿ7-5ÿ1&.ÿ:/5ÿD4:ÿVBIÿWBIÿ`HQÿ[EKÿ`IPÿfNVÿZDJÿWBFÿA27ÿS>FÿL:Cÿ9-2ÿp_rÿ†tŽÿ…s�ÿ�o‰ÿyiƒÿyl…ÿ^Sdÿ>6AÿXK\ÿn`sÿl^uÿeYnÿbWmÿi^wÿl`xÿj]vÿaVmÿOH[ÿVM`ÿ;1;ÿLEUÿVN`ÿYN_ÿPHUÿPFWÿNEYÿYRhÿ[UlÿZTjÿGBQÿ-,3ÿRBQÿ=0>ÿE8Gÿ?2Aÿ?3@ÿ) (ÿ + ÿ ÿ ÿÿ ÿ ÿÿ ÿÿ +ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ#ÿ!)ÿ$)2ÿ).8ÿ-3?ÿ.7Bÿ/9Eÿ19Gÿ2;Hÿ2;Hÿ5=Kÿ7?Mÿ6>Lÿ6>Lÿ7ANÿ8CQÿ8AQÿ8@Oÿ9BPÿ;CQÿ:CQÿ8CPÿ7AOÿ8BPÿ8CQÿ7CSÿ2>Mÿ'2=ÿWTfÿg[rÿtcyÿyg�ÿ�qŒÿ‚q�ÿBCPÿ$!ÿ$ÿ%ÿ#ÿ#ÿ "ÿ !ÿ !ÿ !ÿ"ÿ ÿ ÿ!ÿÿ5,7ÿI9JÿL;JÿKLÿN=IÿP?LÿMMÿO>NÿQ@QÿS@RÿVCUÿVDVÿWCVÿXFYÿZGYÿXEWÿWDUÿVCTÿXFWÿXFXÿWEWÿYFYÿYGYÿZHYÿWFXÿZHYÿZGYÿ[GZÿWEVÿZGYÿZHYÿ[H[ÿ[J]ÿ]J\ÿ]I\ÿ\I[ÿ]K\ÿ]J\ÿ]K]ÿ]K^ÿ^L^ÿ`M_ÿ^K^ÿ_K_ÿhTeÿnWiÿ€fyÿ’vˆÿ’t†ÿ—yˆÿ¢‚’ÿ¥„•ÿ ��ÿ„etÿ…etÿƒgvÿsZiÿpWgÿy^nÿ{`oÿz`pÿsZkÿjSeÿfO_ÿaL\ÿaK\ÿaL\ÿ_KYÿ^JXÿ`L[ÿ`KZÿ_JXÿ]HWÿ[GVÿZFTÿYESÿXESÿVCRÿSAOÿP?LÿL:GÿC6Aÿÿ ÿÿ322ÿYMTÿ#"ÿÿÿÿ ÿ &ÿH@QÿF5Bÿ9*6ÿ:+6ÿ:+6ÿ?.:ÿJ8DÿF4<ÿH6<ÿÿ +ÿÿÿÿ ÿ ÿ#ÿ#ÿ$ÿ!ÿ"ÿ#ÿ ÿ ÿÿ ÿ ÿ*ÿÿ +ÿ ÿQN[ÿ†z‹ÿŠ}�ÿŒ�ÿ���ÿ�ƒ“ÿ’…”ÿ’†•ÿ”†”ÿ“‡”ÿ’†”ÿ’‡”ÿ“ˆ•ÿ’‡•ÿ”ˆ–ÿ“ˆ—ÿ“‰—ÿ•Š—ÿ–Ššÿ•‹›ÿ˜Œ�ÿšŒ�ÿ—‰šÿrdrÿ�ƒ“ÿ•‹›ÿ•Š›ÿ–‹œÿJM^ÿ^\pÿ_Ukÿn\sÿt`wÿ|j…ÿƒrŽÿGCRÿ#ÿ#ÿ$ÿ"ÿ$ÿ #ÿ$ÿ% ÿ&!ÿ$ ÿ$ÿ"ÿ!ÿ#ÿ(*.ÿ?3@ÿG7HÿJ:JÿMOÿJ:HÿL;IÿJ9GÿI7GÿD4Dÿ7+8ÿ.%1ÿIATÿPI_ÿWMhÿ\SlÿVKeÿJ?XÿgZuÿqa}ÿ|j…ÿ‡s�ÿ‡t�ÿvcÿeOkÿkUpÿoXtÿLNÿO>MÿO>MÿTARÿSARÿVDUÿXEVÿYFWÿZFXÿWCUÿYFYÿYFXÿXDVÿXEWÿYFYÿXFYÿZGYÿZHYÿYGXÿ]J]ÿ]I[ÿZGXÿWDWÿZGYÿ\I[ÿ\IZÿ[HZÿ[HZÿ\J[ÿ]J\ÿ]J\ÿ\J\ÿZHZÿTCTÿRBSÿSCUÿYFWÿ\JZÿ\I[ÿ^J\ÿ_K\ÿ^K[ÿ[IZÿ[HZÿaM]ÿ|csÿx_qÿoVhÿbJ\ÿoWiÿeP`ÿ\JYÿ_JZÿ[EVÿdN_ÿjSdÿfPaÿfPbÿbM^ÿ^JZÿ]IZÿjTfÿpYkÿ^JYÿ]IWÿ`K[ÿ]IXÿ^JYÿ\HVÿ[GTÿYFTÿWDRÿTAOÿT@NÿO=IÿK9Fÿ0-0ÿ ÿ ÿÿÿ ÿ ÿÿ ÿ ÿ ÿ ÿ ÿ5(2ÿ3'0ÿ5(2ÿ<,8ÿ8*4ÿ5(3ÿY?IÿW@Gÿ ÿ ÿÿÿ ÿ ÿ ÿÿÿÿÿÿÿÿ ÿÿ ÿ +ÿ!ÿÿ ÿÿDDNÿ‡{ˆÿ‹‹ÿŽ€Œÿ�‚Žÿ‘ƒ�ÿ‘„‘ÿ“†’ÿ”‡“ÿ“‡“ÿ“‡“ÿ“‡”ÿ”‡–ÿ”ˆ–ÿ”ˆ–ÿ”‰—ÿ”Š—ÿ”Š—ÿ•Ššÿ—‹›ÿ–ˆ™ÿˆw‰ÿ‹yŠÿZM[ÿqbsÿ—†˜ÿ—‰šÿ—‹�ÿwq‚ÿ:ARÿslƒÿaTjÿr_vÿwe~ÿ�qŒÿ„t�ÿ57>ÿ"ÿ% ÿ$ÿ& ÿ%ÿ#ÿ #ÿ #ÿ #ÿ#ÿ"ÿ!ÿ#ÿ"ÿ$#'ÿ;/<ÿF6FÿH8GÿK9JÿK:KÿJ9IÿK:JÿL9IÿH8HÿF6Eÿ@3Aÿ5)6ÿ3+7ÿIBVÿRKbÿUNfÿVMdÿVLdÿ[QjÿeXrÿn`yÿtd}ÿ�n‡ÿ†sŽÿ�mˆÿoZuÿiSoÿI:IÿN>MÿSARÿR@QÿRAQÿVDUÿXFXÿWEVÿYFWÿYEWÿVDVÿWDWÿ[I[ÿZFYÿZFYÿZFXÿZG[ÿ\H]ÿ[I]ÿXFXÿYFYÿYGYÿYFYÿWDVÿZGZÿZIZÿ\H[ÿ[GYÿ[GZÿ[I[ÿ\I\ÿ]J\ÿUCUÿM=MÿA4Eÿ@3BÿA3CÿF7GÿO>NÿYGYÿ\I\ÿ\H[ÿ[HZÿ[IZÿ\J[ÿ]J\ÿ]J[ÿ[GYÿZGXÿXEVÿ\HZÿ]I[ÿ[HYÿ[HXÿ]HYÿ]HYÿ\HYÿ_L]ÿ_L\ÿ^J[ÿ\HYÿ[HXÿZGWÿ_J\ÿ`K\ÿ[HUÿYGUÿZFUÿ[HVÿ[FVÿWCSÿWCRÿVBPÿUBPÿR?LÿQ?LÿO1>ÿoTaÿYCNÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿ ÿ38Bÿ‰{ˆÿŽ�Œÿ�‚�ÿŠ|ˆÿ}q}ÿ”†‘ÿ”‡“ÿ•ˆ“ÿ”ˆ”ÿ•‰•ÿ•‰–ÿ•‰•ÿ•‰–ÿ•‰–ÿ–‰–ÿ”Š˜ÿ•‹˜ÿ•‹™ÿ“ƒ“ÿ•|�ÿŽuˆÿŠr„ÿkXfÿ]KYÿ†o�ÿ—“ÿ–‚•ÿ‘‡˜ÿAFVÿQWiÿk`wÿsaxÿ{h€ÿ‚pŒÿ„r�ÿpe{ÿ%$ÿ"ÿ"ÿ!ÿ !ÿ"ÿ#ÿ !ÿ #ÿ"ÿ"ÿ#ÿ#ÿ!ÿÿ.(0ÿA3DÿF7GÿF7FÿE4EÿG6GÿI8HÿI7GÿI8GÿH9GÿG7Fÿ@1>ÿ4(2ÿ6-;ÿNF\ÿNH^ÿME[ÿUJdÿ_Tmÿ_Rlÿ_Smÿk]wÿtd}ÿ{j„ÿ†rŒÿ†r�ÿ~j†ÿM;IÿP>NÿTASÿT@SÿS@RÿUBUÿ[H[ÿ]J\ÿ\H[ÿ\I\ÿ[H\ÿZGZÿ[G[ÿ[I\ÿYF[ÿ[H\ÿ\I]ÿ^J_ÿYGZÿXFXÿWEXÿVDWÿVDWÿZGZÿYGZÿ\I\ÿZG[ÿZGZÿYH[ÿZJ[ÿZH[ÿZI\ÿTEWÿG:Jÿ@2BÿC5EÿP@Rÿ]K^ÿ]J\ÿ[HYÿZHYÿZGYÿ[HZÿ[HZÿ[IZÿ[IZÿ[HYÿYFXÿWETÿXEUÿ]GZÿ]HZÿ]I[ÿ[IZÿ]HYÿ\GXÿ]J[ÿ]I[ÿ_L]ÿ]J[ÿ]J[ÿZGXÿXEWÿWFUÿZHWÿXETÿVCQÿWDRÿYESÿ]I\ÿfTjÿeTgÿ]M_ÿYGWÿQ>KÿP=LÿL:HÿJ>Iÿÿ ÿ ÿ ÿ ÿÿÿ ÿ ÿ ÿ ÿ ÿ"#ÿB5BÿB5CÿA4DÿC5DÿB5Cÿ@3Cÿx`sÿWGTÿ ÿ ÿ!ÿ#ÿ"ÿ#ÿ!ÿ#ÿ#ÿ#ÿ#ÿ#ÿ#ÿ  ÿ ÿ ÿ ÿ  ÿ%ÿ 'ÿ%ÿ%ÿ%.7ÿŠ}‰ÿ’„�ÿ•†�ÿŠ{†ÿnbpÿ—‰•ÿ•‡’ÿ“‡“ÿ–‰”ÿ–ˆ•ÿ—Š–ÿ–‰—ÿ–Š–ÿ–Š—ÿ—Š˜ÿ•‹˜ÿ–‹˜ÿ•Š—ÿ|q~ÿaTeÿxevÿ…p�ÿˆqƒÿvbtÿ}kzÿwetÿdUeÿ–Š˜ÿpl{ÿ+5Fÿb^tÿj]sÿ~jƒÿ‚o‰ÿ‚qŒÿ‚q‹ÿPMZÿ!ÿ!ÿ "ÿ!ÿ"ÿ% ÿ& ÿ"ÿ ÿ ÿ!ÿ!ÿ ÿ ÿ!ÿ8-9ÿA2BÿH8HÿI9HÿJ9JÿH8GÿF6EÿE3CÿF4DÿF6DÿC4Bÿ=/<ÿ3'4ÿ6-=ÿLE\ÿKCYÿOG_ÿ_VoÿbXrÿ_Soÿ\Pkÿi[vÿtdÿygƒÿ�m‡ÿˆs�ÿP>NÿTBRÿVCUÿWDTÿWDWÿZFYÿZFYÿ\H\ÿ\I\ÿ]J]ÿ]I]ÿ[G\ÿ\H\ÿ\I\ÿ[H]ÿ[H]ÿ^K^ÿ]J]ÿ[J\ÿXEXÿUEWÿUEVÿWFYÿXFYÿYGYÿYFZÿ[H]ÿ\I^ÿ[I[ÿZI[ÿ[I[ÿ\J]ÿRATÿN?OÿWFWÿZHZÿ]K]ÿ\I\ÿZHZÿZGXÿXFWÿZHZÿZGXÿZHZÿZGXÿZGZÿZGYÿYFVÿWDTÿ\IXÿZGXÿZFXÿ[HYÿ_L]ÿcN_ÿcO`ÿaM^ÿ_J\ÿbN_ÿ]J[ÿ^J[ÿZHYÿZHWÿYGWÿYGVÿYFUÿWDSÿT@OÿUAQÿcSgÿh[rÿl^uÿj[sÿ[K]ÿR@OÿO=KÿL1@ÿ{g~ÿUHWÿÿ#)ÿ%,ÿ%.ÿ&.ÿ'/ÿ'0ÿ(1ÿ'/ÿ(0ÿ)/ÿ)/ÿ&,ÿ'.ÿ'.ÿ%-ÿ%-ÿ&.ÿ(/ÿ'0ÿ!'ÿ'0ÿ-7ÿˆ}Šÿ•ˆ“ÿ—‰”ÿˆz†ÿ_YcÿšŒ—ÿ˜‹–ÿ˜‹—ÿ˜Š–ÿ˜Š–ÿ—Œ—ÿ˜‹—ÿ—‹˜ÿ˜‹—ÿ˜Œ™ÿ‰yƒÿ��Žÿ–‹—ÿvo{ÿ%-6ÿ.1<ÿ65?ÿ96Aÿ:7@ÿ64=ÿ./8ÿ68?ÿš�—ÿ™Œ˜ÿMÿQ>MÿQAPÿQ@MÿQ@NÿP?LÿM=JÿLÿ$0;ÿ!/:ÿ.8ÿ,4ÿ)0ÿ+2ÿ+3ÿ)0ÿ*2ÿ+4ÿ+2ÿ+3ÿ(/ÿ,4ÿ*4ÿ|w‡ÿ–‹›ÿ—Œ›ÿ’‡”ÿc[gÿ˜Œ—ÿœŽ›ÿš�šÿšŽ™ÿ™Œ˜ÿ˜�˜ÿ˜�—ÿ›Œ—ÿšŒ˜ÿ™Œ˜ÿ‹y„ÿ—‰•ÿ˜‹—ÿ–Š–ÿ€y„ÿVYdÿJPZÿ2>Jÿ0;EÿFMWÿZZdÿ€yƒÿš�—ÿšŒ—ÿ€y†ÿ*5DÿjeyÿaWmÿ‰uŒÿƒp‰ÿ‚p‰ÿƒqŠÿk^qÿ ÿ ÿ ÿ#ÿ"ÿ!ÿ ÿ ÿ ÿ!ÿ!ÿ ÿ ÿ"ÿ ÿ ÿ9/;ÿA2AÿG8GÿG6EÿI8IÿI9HÿF5DÿD3DÿD4EÿF5FÿB3Bÿ9-;ÿ,%/ÿ6.;ÿNF]ÿTKgÿ[Rlÿ^RmÿdZtÿ^Snÿ[PjÿVMfÿ\OfÿdTjÿUFZÿRCTÿB3Aÿ@2@ÿF7GÿE7FÿI8IÿN@OÿI;JÿI;KÿK=LÿF8FÿRBSÿYI^ÿ[J`ÿYH\ÿUFYÿRDVÿWH]ÿVE[ÿ\MbÿYJ\ÿXI\ÿTEWÿP@SÿTEXÿVG\ÿXI^ÿ\Maÿ^OaÿXH\ÿUEYÿUF[ÿUGZÿVF[ÿYJ`ÿ[Kbÿ[Kaÿ\L`ÿZK_ÿYI\ÿ`Pcÿ_Mcÿ_McÿbPeÿYI^ÿTEWÿRASÿUFXÿVFWÿWFXÿZJ]ÿ[J\ÿ[J\ÿ^L^ÿ\J\ÿ^L_ÿ_M`ÿ]K\ÿ^K]ÿYHXÿYGWÿ]K]ÿXHXÿWGWÿYIZÿWFXÿ\I]ÿ[I]ÿ[I\ÿYJ\ÿ[I]ÿYI[ÿVGWÿSDSÿRASÿG;Iÿ$$(ÿ#(,ÿ%*.ÿ%+.ÿ&-/ÿ"),ÿ#(,ÿ'+/ÿ&+-ÿ#**ÿ%,.ÿ.14ÿ"*,ÿ018ÿO@RÿKNÿOAQÿP@Rÿ|h‚ÿVIYÿ,-7ÿ/3?ÿ03?ÿ03?ÿ05Aÿ25Cÿ5:Hÿ49Hÿ59Iÿ3:Iÿ/8Dÿ.5Bÿ.6Cÿ+4Aÿ+3?ÿ'3<ÿ&1;ÿ%0;ÿ#09ÿ#/9ÿ$19ÿ$/:ÿ$1=ÿggyÿ”‹¡ÿ”ˆœÿ“‡™ÿZKUÿˆz‡ÿ•‡–ÿ˜‹˜ÿ˜‹˜ÿ˜‹—ÿ˜‹•ÿ™‹–ÿ—‹”ÿ˜‹•ÿ™Œ—ÿ™‹—ÿ˜Š–ÿ™‹—ÿš‹˜ÿš�™ÿ—Š—ÿ™Œ™ÿ`_mÿˆ€Žÿ˜Œ˜ÿ›�˜ÿšŒ˜ÿ™‹—ÿ˜Š—ÿ•‰—ÿILZÿLNaÿoe|ÿwf}ÿ‚o‡ÿl‡ÿ€pŠÿ�p‰ÿFCNÿÿ"ÿ"ÿ"ÿ"ÿ"ÿ ÿ ÿ"ÿ"ÿ!ÿ ÿ!ÿ ÿÿ&%*ÿ:/<ÿB3BÿD2AÿF5CÿJ9HÿG7GÿE5FÿF5GÿE5FÿE5EÿB4Cÿ?0?ÿ0%1ÿ;1DÿSJdÿ[QlÿVMgÿZPjÿbXrÿcXqÿ]RkÿVJcÿTG^ÿB4Bÿ?3Aÿ?3AÿG8HÿO@RÿRCUÿN@SÿTFZÿRDYÿB7Gÿ2(3ÿ<1>ÿSFXÿZLaÿZKaÿTEYÿL>PÿE8JÿRF[ÿWI_ÿ[MdÿVJ_ÿXJaÿJSÿK=SÿQDYÿRDXÿVG\ÿ\Nbÿ_RgÿZNcÿVJ`ÿVJ_ÿ[Mbÿ[Mcÿ`RjÿbSkÿjZsÿfVnÿ\MdÿfVnÿl\tÿj[rÿeUlÿ_Pgÿ\Pfÿ\Ofÿ^PhÿbSkÿgWoÿdUlÿ_PeÿWG[ÿTFYÿSFYÿJ>OÿI>LÿGGÿB?Hÿ@=Fÿ>;Eÿ76=ÿ35<ÿ;7@ÿI>LÿM=MÿQAPÿMNÿM>OÿO?PÿWEWÿWEXÿYHZÿZJZÿXHYÿREVÿ]OdÿeWlÿcTkÿfYpÿk]vÿn^vÿiZqÿfWoÿiZqÿ9.:ÿ:/<ÿA2BÿI9JÿTCWÿ\KaÿZK_ÿUGZÿ7,8ÿ1&/ÿB3BÿPASÿYK`ÿSEWÿZJ_ÿUEYÿE8JÿVI]ÿaSiÿC6EÿA3BÿA4Dÿ=2@ÿI;LÿK=PÿNASÿK=NÿD7EÿWK^ÿXJ]ÿ[MaÿZMaÿdUnÿeTlÿ`PfÿeTjÿkZqÿiYqÿn^vÿdRjÿ`PfÿbSiÿeUkÿdShÿiXoÿrbzÿp`yÿiYsÿiXrÿ`NfÿcSjÿfVnÿp`yÿk[tÿp_yÿvd|ÿjZoÿcTjÿ`RhÿaRhÿ\NdÿaQfÿ]L^ÿ_L^ÿG;JÿP@Rÿ[KaÿPCSÿP@PÿOAQÿD7DÿF:GÿJ=Lÿ\N`ÿ_ReÿYJ\ÿYJ[ÿZL]ÿWHZÿ]Maÿ]NbÿaOfÿbShÿkZpÿcRgÿgVmÿdUlÿWH\ÿYI\ÿbPeÿ]Mbÿ_ObÿWGZÿM@PÿWI\ÿ_PcÿVHYÿQBQÿK=KÿcSgÿXGZÿXHZÿbRfÿfThÿkXpÿm\qÿm\rÿtazÿm[qÿvd{ÿlZpÿdRfÿiXmÿjXpÿeShÿ`Odÿ_NbÿZK]ÿWEXÿ^K`ÿ\K]ÿ\J[ÿp^tÿtbxÿzg~ÿ|i€ÿyf}ÿzg}ÿt`wÿkYoÿkYoÿdRfÿ^K\ÿaOaÿcQeÿ^M`ÿ^Laÿ[J]ÿVFWÿPBRÿSBTÿ^L_ÿjWkÿmZpÿgTiÿ\IZÿPAQÿN?NÿUEVÿaObÿ_L_ÿ^K]ÿPAPÿ>2@ÿTDVÿZGZÿTCRÿUFVÿRAQÿO?OÿJ2Aÿ7,9ÿ5+9ÿ=3BÿB7FÿA6DÿF8IÿB3Cÿ@1?ÿ>1?ÿK=MÿL?RÿVH\ÿTG]ÿTGZÿbRhÿgVmÿ^McÿZI^ÿ\KaÿcSiÿeTkÿbPfÿaPeÿ^Naÿ`Odÿ\LaÿQCTÿE9IÿD8IÿPBUÿNARÿG1=ÿ^PeÿdTiÿ^ObÿYH\ÿUDUÿUDUÿeRfÿn[rÿu`xÿvbyÿxczÿuaxÿq]rÿn[pÿiWlÿdTiÿr`yÿvc}ÿfVmÿ]MaÿjZmÿhWlÿ^Laÿ`Nbÿrawÿq_uÿwd{ÿubzÿ}h€ÿxf{ÿrawÿiXlÿhYkÿp_wÿp_wÿm]sÿ[K^ÿYH\ÿVH[ÿZJ^ÿcRfÿZJ]ÿ[H[ÿ^L^ÿSBRÿP?MÿiXlÿdTgÿK=LÿPAQÿI:IÿWEVÿWDVÿO>Nÿ8,8ÿ=2@ÿXGZÿYGZÿ]L^ÿTFUÿRDSÿVHYÿVH[ÿRDVÿSEVÿRCTÿZJ\ÿPBRÿM=MÿMOÿD6FÿL=NÿUEXÿ^Maÿ\L^ÿQASÿM=NÿUEWÿWFYÿXGZÿbOcÿaPdÿ\K]ÿaPaÿcQeÿcQeÿdSeÿaN`ÿ]K\ÿG8JÿJ;LÿTCVÿZG[ÿ\I\ÿ]J]ÿ`L`ÿbNbÿ\H[ÿG9JÿJNÿL>OÿH:JÿC5Dÿ6+8ÿA5CÿTDWÿVGZÿQCUÿRCVÿM?QÿI:KÿF9IÿN@QÿPDWÿJ?Pÿ9/=ÿ;0?ÿC8IÿH=MÿJ=Nÿ>3Bÿ>2Aÿ3(4ÿ?4BÿH3BÿA6FÿA5FÿNBSÿSFYÿWI_ÿbShÿdTjÿ`OfÿcQhÿcPgÿcQhÿaRhÿ]Mcÿ[K`ÿ]M`ÿ\K^ÿaPeÿ\Maÿ\K_ÿSCVÿH;LÿE:IÿE8HÿL?PÿPCSÿG:Jÿ7+8ÿC7EÿL>MÿTFWÿE8FÿTCTÿSDUÿKOÿQBTÿUEWÿNAQÿI=MÿD7GÿQATÿ[K`ÿcSfÿK=MÿNARÿVFXÿ]L`ÿUGYÿNAPÿK=LÿLQÿWFYÿTDVÿTDVÿ]M^ÿ[J\ÿVEXÿXGYÿYGYÿTCUÿaQdÿ]L_ÿUFVÿH:Hÿ@2?ÿP@QÿVDVÿM=NÿLMÿN?QÿH;Jÿ3(2ÿ7*5ÿNAQÿTEWÿN>Oÿ[J\ÿVFZÿQATÿM@QÿQDWÿNARÿJ=NÿK>PÿI4DÿH;NÿOBVÿOCVÿG:KÿD7GÿA6DÿF;JÿMAQÿD:IÿH:KÿZJ_ÿ^Ncÿ_NcÿcQfÿbPdÿdRgÿeSiÿ]L_ÿ[K^ÿeSjÿ[K^ÿIÿG;KÿREWÿO@Qÿ^MbÿgVlÿiWlÿm\tÿZLaÿXI^ÿ_OeÿZJ_ÿL=PÿTFYÿD9Jÿ?2AÿB6FÿA6DÿH;MÿK?QÿD8FÿF8IÿC8IÿE;JÿE9HÿE7GÿIMÿPCTÿOARÿQCSÿQBTÿOBSÿHOÿK=NÿQBRÿM>NÿNARÿL?NÿI;KÿKPÿPARÿN>NÿG9IÿH9JÿK:MÿO?QÿJ>QÿOCVÿF:Jÿ9,:ÿ@3Cÿ\K_ÿ`NdÿUFYÿWEWÿQ@TÿI:MÿKOÿM@QÿH;KÿM?QÿF:JÿM@RÿPCWÿGOÿ[NaÿVI\ÿQDVÿSEXÿOASÿRCTÿTDXÿUEYÿ]MaÿYI[ÿ[K]ÿXIZÿO@RÿN?PÿF9HÿC5DÿE7FÿE9IÿF9JÿI=NÿA6GÿF:KÿTGYÿP@Qÿ\K_ÿ_OdÿVEWÿ\MbÿHPÿD7GÿC8HÿHOÿPCTÿOAQÿF9Iÿ@5EÿF;KÿD8GÿHNÿOASÿQCTÿPCUÿPBUÿN?QÿJNÿE8Fÿ=1?ÿB6EÿSDTÿXI[ÿ/"-ÿB6Fÿ_OeÿTDVÿP?OÿSBSÿSBSÿQ?QÿQARÿRASÿTCTÿN>PÿSCUÿSDVÿ\Maÿ_Naÿ_L`ÿ^K`ÿ]K^ÿdQdÿaOcÿ\K^ÿXHZÿWEXÿTCTÿWEWÿP>OÿUDVÿ]M`ÿ\K_ÿZH[ÿUFWÿTDUÿTBTÿQARÿL=NÿRASÿUDUÿUEWÿQ@SÿQ@RÿP?QÿG7IÿH:LÿJ;Lÿ>3Dÿ<1BÿC4DÿRCVÿ^MaÿdQfÿcQfÿcPfÿ\K`ÿUEYÿPBUÿOATÿM?QÿJ?OÿC7EÿN?RÿTFYÿRBUÿWG[ÿTEXÿQDVÿSDXÿL=QÿL=PÿTDVÿYJ]ÿWI^ÿXH]ÿWH]ÿUFYÿVFYÿL=OÿO@SÿQBSÿK=NÿK=MÿI;LÿF:JÿF9Iÿ:.<ÿF:IÿK=NÿG;MÿOAUÿTFZÿPBTÿTFZÿ[LaÿXI\ÿUFXÿWGZÿWGYÿSDVÿXH]ÿTEXÿSDUÿYK]ÿMAQÿK?OÿSFWÿJ?NÿNCRÿQDUÿXI\ÿ[L`ÿTGXÿHOÿKNÿXGZÿWFYÿSDTÿJOÿP=NÿK:KÿP@RÿSBTÿYGZÿRASÿO@RÿJQÿSDWÿUCXÿYI^ÿWH\ÿOARÿUFZÿ\KbÿPBUÿG:IÿC7FÿF9IÿD9IÿC7GÿK>MÿK>OÿK?QÿK?QÿREXÿWH\ÿ]M`ÿ\Laÿ]Mbÿ^OdÿXJ\ÿ^NbÿbShÿYI^ÿYI^ÿ\L`ÿUEVÿTEXÿXI\ÿYJ\ÿ]N`ÿ^ObÿZJ^ÿYK^ÿXJ^ÿSEYÿ^OdÿTFYÿUHZÿXK]ÿXJZÿVGZÿ`RfÿXJ]ÿWJ[ÿ\M`ÿUHZÿZK^ÿ`QfÿfUkÿeTjÿaPfÿgWkÿiXnÿjXnÿgWnÿfVmÿbRiÿjZoÿeTiÿbQeÿdRiÿeTkÿbReÿ]N_ÿZK]ÿM?OÿB3Bÿ^NaÿYH[ÿYI[ÿ\J]ÿZJ^ÿbRfÿcQgÿ]K`ÿ[I\ÿQBSÿJ=NÿUGZÿZK]ÿ_OaÿcSeÿmYoÿkXmÿ\K^ÿRBSÿM>OÿVGZÿM>Nÿ?0=ÿ@0>ÿRCUÿRCUÿI=LÿSFVÿYJ^ÿ^NaÿYIZÿSBVÿ>1<ÿ?0<ÿXHZÿF:Iÿ7,9ÿE9GÿN>OÿWH[ÿO?PÿM>MÿN>MÿM;JÿSAQÿF6Bÿ<0:ÿE8HÿD8HÿNÿF8HÿJOÿUDVÿTDVÿSDUÿRDTÿRAUÿ_M`ÿaOcÿbOdÿ]L`ÿ]Kaÿ^K`ÿWFZÿYK^ÿTDVÿTDXÿSDYÿRDWÿWG]ÿRCVÿPBUÿPATÿTEZÿVG\ÿWF\ÿ[J`ÿ^NdÿYI^ÿVFZÿQ@VÿN?RÿUE[ÿSCXÿSCWÿTHZÿSEXÿK=OÿF7HÿE7GÿD8GÿB7GÿF;Kÿ=3BÿL>OÿUFYÿPBSÿM?QÿPCWÿJ?SÿSFZÿ[L_ÿUFXÿTEXÿQBTÿVGZÿUFYÿXI[ÿRBTÿZJ]ÿ[J`ÿXH\ÿTEYÿ`Ocÿ`M`ÿ`NbÿbPcÿ^Mcÿ[K_ÿTEYÿH;KÿTEXÿUFXÿUFWÿ_Nbÿ\LaÿYH]ÿ\K`ÿVGZÿUGZÿPCUÿRCWÿWH\ÿVEWÿ`Naÿ[J]ÿcRfÿbNdÿeShÿeTjÿhXnÿjYoÿhUjÿlZoÿfTjÿjXoÿcRgÿ_NbÿVDXÿSCVÿRBTÿSEVÿOBRÿXGYÿ[K]ÿjWiÿZI[ÿ\K`ÿYI]ÿUEYÿ_Naÿ`Pbÿ[L]ÿQCUÿ[K^ÿXI[ÿWGYÿWEWÿ]K`ÿaNbÿTBSÿQ@QÿOBSÿVGZÿUFWÿRDUÿXHZÿYI\ÿ]L^ÿXFXÿN@PÿQCSÿeTiÿeShÿaNbÿVEXÿ[J^ÿVFYÿPBRÿIOÿP@RÿN@QÿJ=MÿK?OÿL@QÿPASÿOARÿQCUÿYI^ÿdShÿaNcÿXFYÿZHZÿ]K^ÿ[I\ÿF7GÿO@QÿaQdÿcQfÿ`NdÿYI]ÿYJ]ÿUFXÿQBTÿVEWÿ\K^ÿ^NaÿaPdÿ[J]ÿ[K\ÿXFWÿXGXÿWFYÿXGYÿVHXÿSCSÿZJ\ÿ\K_ÿWFZÿ]MaÿWEWÿP?QÿQAQÿQ@QÿO@QÿTEVÿUFWÿTDXÿTCWÿUCVÿN>NÿVFYÿN?PÿWFXÿSAUÿMPÿM@QÿO@SÿVFZÿSDWÿVGYÿPBTÿTEWÿRDUÿSFXÿRFXÿUFXÿXFXÿ]K_ÿ]K_ÿfUkÿfTjÿ_Peÿ\MaÿcSiÿ\L_ÿ[K^ÿaQfÿ`NdÿYH\ÿWH\ÿYI^ÿXJ\ÿWI^ÿZK`ÿbRgÿfTiÿaPcÿ]L_ÿ_Naÿ]K_ÿ_Lbÿ\K^ÿ`NbÿaNbÿcQdÿXGXÿdRgÿgTjÿeSiÿbPdÿ_OeÿaQfÿ`NcÿbQgÿ`OdÿbPdÿ`Nbÿ]J\ÿVDVÿYH\ÿ]Mbÿ\Laÿ_Naÿ]L_ÿ[J]ÿRCTÿN?PÿVGYÿYH\ÿUDVÿ\J`ÿXFYÿL;LÿP@QÿSEVÿ^Pcÿ]Oaÿ\L_ÿYJ[ÿXGYÿ^K]ÿUCTÿI;IÿK=LÿUGXÿQCSÿZI[ÿZHZÿ_L_ÿVDVÿUDVÿZI[ÿXFXÿTETÿL;JÿM?OÿTDVÿO?PÿN>NÿF8GÿINÿIOÿJ:KÿLPÿI9IÿRBSÿSBTÿN>NÿP?RÿLPÿM?RÿTEZÿSEXÿM@SÿPBUÿG:KÿOATÿJ;NÿF:KÿRDWÿYI]ÿ\LaÿZJ^ÿWFZÿXG]ÿWG[ÿWHZÿPBSÿN@RÿXH]ÿcQgÿ]Mbÿ_Ocÿ\MaÿXJ]ÿRDVÿTG[ÿL@QÿXJ[ÿSCUÿWH[ÿVEZÿdQfÿ]M_ÿcRhÿcQfÿ]Maÿ_MbÿgVjÿaPcÿ_LaÿUDVÿ_Odÿ`OeÿXH]ÿ^McÿcQgÿeTiÿeThÿZJ\ÿUFXÿSATÿSATÿQ@SÿRCTÿ]L`ÿgTiÿfTjÿaPfÿbPgÿdRgÿdShÿeTiÿcQfÿaOdÿ\K_ÿ\K_ÿ^Maÿ`Ocÿ_Naÿ[L]ÿXGYÿ`Ocÿ]Lbÿ`Ncÿ]K_ÿ^L`ÿ[I_ÿUEYÿWH[ÿTEXÿWGZÿSEWÿ[J]ÿ]K`ÿZI^ÿaPeÿfTjÿfVkÿbPdÿYHYÿWGYÿWGYÿbNaÿgTgÿXFZÿVFWÿ]Maÿ[K^ÿVEWÿ\K]ÿaObÿbOcÿ^K_ÿaOcÿP>Pÿ;-8ÿL>LÿN>NÿH:HÿJ;JÿRDUÿPCTÿQDVÿXGZÿWGYÿRDVÿXI\ÿZI[ÿVGXÿXHYÿZH[ÿ[H[ÿ_L`ÿ_LaÿeSgÿ`MaÿbNdÿaObÿJ:KÿF7Hÿ[J_ÿ^Laÿ_Mbÿ]Mbÿ]McÿTEYÿ[K^ÿ]L_ÿ\K]ÿ[J]ÿVFWÿQASÿO>OÿH9HÿL>NÿP@QÿUFWÿWF[ÿUFZÿ[K`ÿ]K`ÿ\K`ÿZJ^ÿUEWÿRBUÿOASÿL>NÿO?OÿRBTÿTDWÿO?QÿJPÿN?QÿN?QÿJPÿF9IÿLOÿJ;LÿUFYÿUCWÿUDVÿVEWÿL1?ÿ@2?ÿLNÿ;.:ÿJ;LÿYG[ÿ\K^ÿZJ_ÿXH\ÿVGYÿ\L`ÿ]L`ÿUDUÿTCVÿWGZÿVGYÿXHZÿQCUÿSEWÿP@RÿYH\ÿVEYÿVEYÿZJ^ÿWF[ÿUEXÿSCVÿWGYÿYI]ÿSCTÿSEWÿUGXÿN?PÿL=OÿM>QÿP@SÿSCUÿP?RÿO>OÿL;LÿH8IÿC4GÿJ;KÿM>PÿG7IÿJ9IÿF6FÿF7GÿKPÿTDVÿPASÿO@RÿUEXÿZI]ÿPARÿP?QÿQARÿN>OÿQBTÿQASÿJ:HÿK=NÿQ?RÿR@RÿL:KÿSDVÿMPÿTEWÿM@Oÿ1>ÿA2BÿK=NÿSCUÿK:KÿN>PÿSCXÿWF\ÿ[J^ÿUCVÿ^K^ÿZG[ÿSARÿJ:IÿN?MÿWGUÿSBSÿVGYÿSDWÿSBTÿM>MÿSCTÿPATÿMNÿ\J]ÿZHZÿ\K^ÿP@PÿQ@RÿRBQÿOAQÿQBSÿN>OÿR@RÿeRdÿYHYÿXFXÿZI[ÿ^K]ÿ^L_ÿ\J\ÿ`Obÿ[I\ÿRAQÿN>Mÿ[JZÿUEVÿP?OÿVDUÿUBSÿTCUÿVEXÿRASÿ[H[ÿ]J]ÿ]J^ÿSCSÿQBRÿTDUÿVFWÿVEWÿXGXÿ\J]ÿ^K^ÿWEVÿUCUÿZHZÿWFYÿ_Maÿ\I^ÿYFXÿ\HZÿbNcÿ^K^ÿXFWÿRARÿUDUÿTBRÿYGYÿYGYÿUEUÿTBSÿVEVÿYHZÿ[K\ÿYGYÿRASÿR@PÿQ@QÿZJ\ÿTDUÿMPÿRCVÿQAUÿWFZÿZI]ÿWEXÿWEZÿWG\ÿN?SÿSBVÿTEYÿK=OÿL?PÿRDVÿL>NÿJ;KÿJ9KÿWFXÿZH\ÿVFXÿXI[ÿ\LaÿVEXÿN>OÿN>OÿXHZÿVEWÿSBSÿP@QÿQBSÿSCUÿTCUÿUCUÿZH\ÿ>/<ÿA1>ÿH9GÿI:HÿUFWÿSCTÿN>OÿQBSÿF8GÿG9IÿB4Dÿ@3@ÿA3@ÿL>LÿO?LÿO>LÿSBRÿN?OÿRBSÿUCVÿTDWÿSDWÿI:LÿG8FÿO?OÿM=NÿE6FÿG7FÿSASÿO@QÿL1>ÿXGYÿTCUÿUDVÿUEWÿSBTÿP@PÿJ=LÿJ=MÿI:JÿQ@Qÿ`M`ÿYGYÿJ9HÿZG[ÿSASÿ^M`ÿSBSÿYGZÿSCTÿUFWÿO@NÿK=IÿF6EÿTDUÿYFYÿUCTÿRARÿSBSÿTCUÿYH[ÿ\K\ÿWFWÿXGYÿXGYÿSCTÿQBRÿTDUÿWGYÿUEVÿO@PÿXGYÿZHZÿVEVÿQ@Pÿ^K^ÿbOaÿfQfÿdPdÿ_L_ÿZIZÿR@RÿP?QÿVEVÿSBRÿUDTÿZH[ÿK9IÿF7DÿL;KÿSARÿWGXÿZGYÿWEWÿUBTÿZF[ÿVEXÿP?PÿLOÿR@QÿO?OÿM>NÿQARÿ^L]ÿ\J\ÿYHXÿZHZÿ]J]ÿ[H[ÿ\K\ÿ]J]ÿ]J\ÿ]J^ÿ_L`ÿTASÿE4BÿC5CÿN=PÿMPÿRCTÿO?QÿRBSÿWGYÿYI[ÿZHZÿWEVÿ[HZÿVEWÿRBRÿUCVÿYGZÿTCSÿSARÿL=MÿLNÿN?QÿKOÿM>MÿJ;JÿJ;JÿVEXÿWFYÿUEYÿUEWÿUDWÿSBSÿXEXÿVEYÿJ:HÿRBSÿN>OÿG7GÿJ:IÿF6EÿF6Eÿ?0?ÿB2AÿKÿD7FÿH;Kÿ@2AÿJ;LÿQASÿVEXÿ]M_ÿO?OÿTCTÿTDTÿLMÿH8IÿTDUÿK>LÿH:IÿH9JÿN?OÿH8HÿSDVÿWGZÿUFWÿRBTÿL=LÿE8FÿN@QÿO@PÿWFXÿWFWÿ[I[ÿPAQÿUEVÿUCVÿ`OcÿYH[ÿYG[ÿUEWÿO?OÿJ9GÿM=LÿM>NÿLNÿLPÿSBSÿVGXÿZHZÿ\J\ÿ]K\ÿdQdÿ[HXÿVCTÿXCVÿWEVÿXFWÿ_L`ÿ^J^ÿ]J]ÿZG[ÿ]J[ÿG5Fÿ?.>ÿPASÿN=OÿRBVÿWFYÿUDWÿTDVÿSCTÿRASÿK:KÿN?OÿWGYÿYHZÿYGZÿWEWÿYGZÿUDVÿ[J\ÿVEUÿWEVÿXEWÿSAPÿQ@QÿSCSÿVCVÿVBUÿVDVÿTDVÿP@PÿK;KÿRCTÿL;KÿWEXÿSARÿL;MÿM=NÿH8IÿF5FÿF6Hÿ \ No newline at end of file diff --git a/components/thorvg-main/test/resources/rawimage_250x375.raw b/components/thorvg-main/test/resources/rawimage_250x375.raw new file mode 100644 index 0000000..d6946b0 --- /dev/null +++ b/components/thorvg-main/test/resources/rawimage_250x375.raw @@ -0,0 +1,127 @@ +›k�ÿœk€ÿžl~ÿ l~ÿ l}ÿ¡l{ÿ¡kzÿ¡lxÿ kwÿŸjtÿ¡jrÿ jsÿŸjsÿŸjvÿ jzÿžj|ÿ�j|ÿžk}ÿŸk}ÿžk}ÿ�k{ÿ�jzÿžjzÿžjzÿ�ixÿœhuÿœgtÿ›gqÿšfpÿ›fpÿ™enÿ™emÿ™fnÿ™foÿ™epÿ™eqÿšerÿ›fsÿ›gtÿœhuÿœivÿ�iwÿžiwÿ�ixÿžjzÿži|ÿ�i{ÿ�j|ÿžk}ÿžk}ÿ�k~ÿžkÿŸl€ÿŸl�ÿžkÿžk~ÿžk~ÿžkÿ�kÿžl€ÿŸk~ÿŸk}ÿŸk{ÿŸkyÿ jxÿ kwÿ jtÿ¡irÿ¡ipÿ¢ioÿ¡ipÿ iqÿ irÿ isÿŸirÿŸirÿ iqÿ iqÿ ipÿ¡hpÿ¢hnÿ¡hlÿ¢hiÿ¤ggÿ¥hfÿ¥heÿ¥heÿ¦heÿ¦hdÿ¦hcÿ¦ibÿ¥icÿ¥jcÿ¦jbÿ§jbÿ§i`ÿ§j`ÿ§j`ÿ§i^ÿ¨h]ÿ¦h]ÿ§i]ÿ§i]ÿ¦h\ÿ§h]ÿ§h\ÿ§g[ÿ§hYÿ¦hZÿ¦h[ÿ¦h\ÿ§h[ÿ§hZÿ¦gYÿ¦gYÿ¦fXÿ¦gWÿ¦gWÿ¦fWÿ§fVÿ¦eTÿ¥eTÿ¦fUÿ¦fUÿ¥eTÿ¦eUÿ¥eTÿ¥eTÿ¥eTÿ¥eSÿ¥dSÿ¥eTÿ¦fVÿ§gYÿ¨iZÿ§hZÿ¨i[ÿ¨i]ÿ§h]ÿ¦h^ÿ§g_ÿ¦haÿ¦h`ÿ¥g_ÿ¤e^ÿ£d]ÿ¢c]ÿ¢c]ÿ¢c]ÿ¡b\ÿ a\ÿ a\ÿ¡b^ÿ baÿŸbeÿŸenÿžesÿžeuÿ�dvÿ�exÿ�ezÿœe|ÿ›e|ÿ›ezÿ›dwÿšctÿšbqÿšapÿšaoÿšaoÿ™anÿ™amÿ™anÿ™aoÿ™`nÿ˜_lÿ—^jÿ—^hÿ—^iÿ—^mÿ—`pÿ•`rÿ“_sÿ’`uÿ’a|ÿ“b€ÿ’a}ÿ’_wÿ’_sÿ’^rÿ’^rÿ‘^tÿ‘_uÿ�^tÿ‘]sÿ‘\rÿ�\qÿ�\mÿ�[kÿ�ZjÿŽZjÿŽYhÿŽYdÿŒXaÿ‹Waÿ�Xcÿ�Ygÿ�ZjÿŒZkÿ�YkÿŒXjÿ‹Xjÿ‹XmÿŠZsÿ‹\{ÿŠ]}ÿ‹\}ÿ‹\{ÿ‹[xÿŒ[uÿ‹YpÿŒXjÿŒWgÿŒWgÿŒWgÿ�XiÿŒYkÿŒYkÿ‹Xjÿ‹Xiÿ‹XjÿŠWjÿŠWjÿŠWjÿ‰VjÿˆWlÿ‰Xoÿ‰XqÿˆWqÿˆXrÿˆWsÿˆXuÿ‡Yvÿ‡WsÿˆVnÿˆVkÿ‡Vkÿ‡VkÿˆThÿˆSdÿœk�ÿœk€ÿžk~ÿŸl}ÿŸl{ÿ lzÿ¡lyÿ¡lxÿ¡kvÿ¡ktÿ¡ksÿ¡ksÿ ksÿ jvÿ kzÿŸk}ÿžl~ÿŸl}ÿ k{ÿŸkyÿ kxÿŸkyÿŸkyÿŸjyÿžiwÿžhuÿ�hsÿ�hrÿœhqÿœgqÿ›fpÿ›foÿšfoÿšfpÿšepÿšeqÿ›frÿœgsÿœhuÿœhvÿœiwÿ�ixÿ�ixÿ�iyÿ�j{ÿ�j|ÿ�j|ÿ�j|ÿžk}ÿžk~ÿ�lÿžl�ÿŸl‚ÿŸl‚ÿŸl€ÿŸlÿžlÿžlÿžlÿŸm€ÿ l~ÿ l}ÿ k{ÿ kzÿ¡kyÿ¡lxÿ¡kvÿ¢jsÿ¢jqÿ¢jpÿ£jpÿ£jqÿ¢jrÿ¡irÿ irÿ jrÿ jrÿ jrÿ¡jrÿ¢irÿ¡ipÿ¢ioÿ¢ilÿ¤hiÿ¥hiÿ¤igÿ¥ifÿ¦idÿ¦icÿ¦ibÿ§jbÿ¦jcÿ¦jcÿ§jcÿ§jcÿ§ibÿ§j`ÿ§j`ÿ§j`ÿ§i_ÿ§i^ÿ¨i^ÿ¨i]ÿ¨i\ÿ¨i\ÿ¨h[ÿ¨hZÿ¨iYÿ§iYÿ§iZÿ§h[ÿ§h[ÿ§hZÿ§hZÿ§hZÿ§gYÿ§gXÿ§gXÿ¨gXÿ§gWÿ§fVÿ¦gWÿ§gWÿ§fVÿ¦fUÿ§fVÿ§fVÿ¦fUÿ¦fUÿ¦fTÿ¦eUÿ¦eVÿ¦fWÿ¦gYÿ¨h[ÿ©i\ÿ©j]ÿ¨i^ÿ¦g^ÿ¦g_ÿ¦f`ÿ§gbÿ§hcÿ§hbÿ¥gaÿ¤f`ÿ£d_ÿ¢c^ÿ¡c^ÿ¡b_ÿ¡b_ÿ¡b_ÿ¡a_ÿ¡baÿ cgÿ eoÿ ftÿŸfwÿžfyÿžf{ÿžf~ÿœg€ÿ›g€ÿ›f~ÿ›e{ÿšdxÿšcuÿšbrÿšapÿš`mÿš`jÿš`iÿš`jÿš`kÿ™_kÿ˜`kÿ˜_jÿ˜^hÿ—^gÿ—^iÿ–_mÿ–`qÿ”`sÿ“`vÿ“a{ÿ“a~ÿ“`{ÿ“_uÿ’^qÿ’^pÿ“^pÿ“^rÿ’^sÿ‘^sÿ‘]rÿ‘\pÿ�\oÿ�\lÿ�[jÿ�Zjÿ�ZiÿŽYfÿŽYdÿŽYcÿ�XbÿŽXcÿŽYeÿ�YgÿŒYgÿ�Xhÿ�YhÿŒYiÿŒYkÿ‹ZpÿŒ\xÿ‹\|ÿ‹\|ÿŒ\{ÿŒ\yÿŒ[vÿŒZrÿ�Ylÿ�Xjÿ�Xiÿ�XiÿŒYkÿ�YmÿŒYlÿŒXkÿŒXkÿ‹Xmÿ‹XnÿŠXmÿŠWlÿŠWlÿ‰Xnÿ‰XpÿˆXrÿˆXrÿˆXsÿˆXtÿˆYuÿˆYtÿˆWqÿˆVlÿˆUhÿˆUgÿˆUgÿˆUfÿ‰Tcÿœk‚ÿ�k�ÿžl€ÿŸm~ÿŸm}ÿ m}ÿ¡m|ÿ¢mzÿ¢lwÿ¢luÿ¢luÿ¡ktÿ¡kuÿ¡kxÿ¡m|ÿ¡mÿ nÿ m}ÿ¡lyÿ¡kvÿ¢kuÿ¢kwÿ¡lxÿ¡kxÿ juÿ itÿŸisÿŸirÿŸjsÿžisÿ�hrÿœgqÿœgqÿ›gqÿ›fqÿ›fqÿ›grÿœhsÿ�huÿ�iwÿ�ixÿ�jzÿžj{ÿ�j{ÿœj|ÿœj}ÿœj}ÿ�j}ÿžk~ÿžkÿžl�ÿžlƒÿŸl„ÿžmƒÿŸm‚ÿŸm�ÿŸl€ÿŸlÿŸm€ÿ m€ÿ mÿ¡m}ÿ¡l|ÿ¡lzÿ¡lyÿ¡lyÿ¢lwÿ¢kuÿ¢krÿ£kqÿ¤kpÿ¥kqÿ¤jqÿ£jqÿ¢jqÿ¢jrÿ¢jrÿ¡jsÿ¡ksÿ¡jsÿ¡jsÿ¢jrÿ¢jpÿ£jmÿ¤ikÿ¤ijÿ¥ihÿ¦ifÿ¦jdÿ§jcÿ§jcÿ§jcÿ§idÿ¨jdÿ¨jdÿ§ibÿ¨jaÿ¨jaÿ¨jaÿ¨jaÿ¨j`ÿ¨i_ÿ¨i]ÿ©i\ÿ©i\ÿ©i[ÿ©iZÿ©iYÿ¨iYÿ¨iYÿ¨i[ÿ¨i[ÿ¨i[ÿ¨i[ÿ¨h[ÿ¨h[ÿ¨hYÿ©hXÿ¨hXÿ§hYÿ§hYÿ§hYÿ§hXÿ§gXÿ§gWÿ§gVÿ§fVÿ§fVÿ§fUÿ§fVÿ§fWÿ§fXÿ§gYÿ§g[ÿ§i]ÿ©j_ÿ©j_ÿ¨i`ÿ§haÿ§gaÿ§gcÿ¨heÿ¨ieÿ§hdÿ§hcÿ¦gdÿ¤fcÿ¢ebÿ¡daÿ¡cbÿ¢ccÿ¢ccÿ¡cbÿ¡cdÿ dhÿ epÿŸguÿŸgyÿŸg|ÿžh~ÿžh�ÿ›h‚ÿšh‚ÿšg€ÿšf}ÿše|ÿ›dyÿ›cuÿšbpÿ›`kÿ›_iÿ›_hÿš_hÿš_hÿ™`jÿ˜`kÿ™`kÿ™_iÿ˜^eÿ—^fÿ—^iÿ–`oÿ•`rÿ•`tÿ”`wÿ”`xÿ”`uÿ”^pÿ“]mÿ“]lÿ“]kÿ“]mÿ’^pÿ’]qÿ’]pÿ‘\mÿ‘\kÿ�[jÿ�Ziÿ�Zhÿ�ZfÿŽYdÿŽXbÿ�Xbÿ�Xbÿ�Xaÿ�XbÿŽXbÿŽXdÿ�Xeÿ�Xfÿ�Yhÿ�Yjÿ‹ZnÿŒ\tÿŒ\zÿŒ\zÿŒ\yÿ�\xÿ�\vÿ�[sÿŽZpÿŽZmÿŽYkÿŽYlÿ�Yoÿ�Zoÿ�YoÿŒYnÿŒYoÿ‹Yqÿ‹Yqÿ‹Ypÿ‹Yoÿ‹XoÿŠYqÿ‰Yrÿ‰YsÿˆXsÿˆXsÿˆXtÿˆXtÿˆXrÿ‰WoÿˆViÿˆUdÿ‰Tcÿ‰UbÿˆTbÿˆTaÿœl„ÿœkƒÿ�l‚ÿžm‚ÿŸm�ÿ n�ÿ¡n€ÿ¢n}ÿ£mzÿ£mxÿ¢lwÿ¢lvÿ¢lwÿ¢mzÿ£n~ÿ¢o€ÿ¡n€ÿ¡m}ÿ¡lxÿ¡ktÿ£ktÿ£luÿ£lwÿ¢kvÿ¢juÿ¡jtÿ jsÿ jsÿ jtÿŸktÿŸjtÿžisÿ�hrÿœhrÿœgrÿ›gqÿœgrÿœhtÿ�ivÿ�iwÿ�iyÿžj|ÿžk}ÿ�j}ÿ�j}ÿœj~ÿ�j~ÿžkÿžkÿžk�ÿ�l‚ÿžl„ÿžm„ÿžm„ÿžlƒÿŸm‚ÿ m�ÿŸl€ÿŸm€ÿ l€ÿ¡mÿ¢mÿ¢m}ÿ¢lzÿ¢lyÿ¢lyÿ¢lwÿ£lvÿ£lsÿ¤krÿ¥lpÿ¦lpÿ¥kpÿ¥kpÿ¤kpÿ¤kqÿ¤jqÿ£krÿ¢ksÿ¢ktÿ¡kuÿ¢kuÿ¢ksÿ¢kqÿ£joÿ¤jmÿ¤jjÿ¥jhÿ¦jgÿ¦jfÿ§ifÿ§ieÿ§ieÿ¨jeÿ¨keÿ¨jbÿ¨jcÿ¨jcÿ©jcÿ©jcÿ¨jbÿ¨jaÿ¨j_ÿ©j]ÿ©j]ÿ©j\ÿªj[ÿªjZÿ©iYÿ¨iZÿ¨j[ÿ¨j[ÿ©j\ÿ©j\ÿ¨i[ÿ©h[ÿ©hYÿ©hXÿ©iXÿ¨iYÿ¨iZÿ¨hZÿ§hYÿ§hXÿ¨gVÿ§gVÿ§gVÿ§fVÿ§fVÿ§fWÿ§gXÿ¦gYÿ¦g[ÿ§h]ÿ§i_ÿ¨jaÿ©iaÿ©ibÿ©jdÿ¨jeÿ©jfÿ©igÿ¨heÿ¦gcÿ§hdÿ§geÿ¦geÿ¤fdÿ¢edÿ¢eeÿ¢deÿ¢dfÿ¢dfÿ¡egÿ ekÿ fqÿŸgwÿžg{ÿŸg~ÿžh€ÿ�h‚ÿ›h�ÿšh�ÿšg€ÿ™f~ÿšf}ÿ›e{ÿ›dvÿ›bpÿ›`jÿ›`iÿš`iÿš_hÿ™`iÿ™`jÿ™`lÿ™`lÿ™_iÿ™^fÿ˜]dÿ—^fÿ–_kÿ–`nÿ–`qÿ–`rÿ•`qÿ•_nÿ”^kÿ”\iÿ”[hÿ”\gÿ“\iÿ’]lÿ“]mÿ’]mÿ‘\jÿ‘[gÿ�Zfÿ�Yeÿ�Ydÿ�YcÿŽYbÿŽXaÿ�X`ÿŽW_ÿ�X^ÿ�W^ÿ�W_ÿ�XaÿŽXcÿ�Xeÿ�Ygÿ�YiÿŒZlÿŒ[rÿ�\wÿŒ\xÿŒ\xÿ�\xÿ�\vÿŽ[sÿ�[pÿ�[mÿŽZmÿ�ZoÿŽZqÿŽZqÿ�ZpÿŒZqÿŒZsÿ‹ZtÿŒZsÿ‹Zrÿ‹Zrÿ‹YrÿŠZsÿŠZtÿŠYsÿ‰Xsÿ‰YrÿˆXrÿˆXqÿ‰Xpÿ‰Wlÿ‰Veÿ‰T`ÿ‰T_ÿ‰T^ÿ‰S]ÿ‰S]ÿ�m…ÿœm…ÿœm…ÿ�m…ÿžm„ÿŸn‚ÿ n�ÿ¡m~ÿ¢m|ÿ¢nzÿ£mzÿ¢mzÿ¢mzÿ¢n|ÿ£oÿ¢o�ÿ¢n€ÿ¡m|ÿ¢lwÿ¢ksÿ¢lsÿ¤ltÿ¤luÿ£luÿ¢ktÿ¢ktÿ¢ltÿ¢ksÿ¡jtÿ kvÿ kuÿŸjtÿžirÿ�irÿ�hrÿœhqÿœhrÿœitÿœivÿœixÿ�izÿžj|ÿžk~ÿ�k~ÿžkÿ�kÿ�kÿžk€ÿžk�ÿ�l‚ÿœl„ÿ�m…ÿžm…ÿžm„ÿžmƒÿžm‚ÿŸm�ÿŸm�ÿŸl€ÿŸm€ÿ m€ÿ¢mÿ£m}ÿ£m{ÿ£mzÿ¢mxÿ¢mwÿ£lvÿ¥ltÿ¥lsÿ¥mqÿ¥lpÿ¥loÿ¥loÿ¥loÿ¥lpÿ¥kpÿ¤kqÿ£krÿ£ktÿ¢lvÿ¢luÿ¢kuÿ¢ktÿ£ksÿ¤kpÿ¤jnÿ¤jlÿ¤jkÿ¥kiÿ¦jhÿ¦jgÿ¦ifÿ§jfÿ§keÿ¨jdÿ§jdÿ¨keÿ©keÿ©jdÿ©jcÿ©kbÿªlbÿ©k`ÿ¨k^ÿ©k]ÿªk\ÿªjZÿ©jZÿ©jZÿ©j[ÿ©j[ÿ©j\ÿ©j]ÿ©i\ÿ©iZÿ¨iYÿ¨iXÿ©iYÿ©iZÿ¨jZÿ¨iZÿ¨iYÿ¨hWÿ§gVÿ¨gWÿ¨gVÿ¨gVÿ¨gWÿ¨gXÿ§hYÿ¦h[ÿ¦h]ÿ§h^ÿ§h_ÿ§iaÿ¨hbÿ©ieÿªkfÿªkgÿ©lgÿ¨jgÿ§hdÿ¥fbÿ¦gcÿ¦fdÿ¥fdÿ¤feÿ£efÿ£efÿ¢efÿ¢egÿ¢eiÿ¡fkÿ enÿ gsÿŸhyÿŸh|ÿžh~ÿ�g�ÿžg�ÿ�g€ÿ›gÿšgÿ™f~ÿ™e}ÿše{ÿ›dvÿœcpÿ›ajÿšaiÿ›aiÿš`iÿ™`iÿ˜`jÿ™`mÿ™`lÿ™_iÿ™_gÿ˜^eÿ–]fÿ–^iÿ—_lÿ—_nÿ—`oÿ–_lÿ–^iÿ•]gÿ•]fÿ”\eÿ”\eÿ“\gÿ’\iÿ’]jÿ’\jÿ�[fÿ�Ycÿ�Ybÿ�Xaÿ�Xaÿ�Yaÿ�Xaÿ�X`ÿ�X_ÿŽW^ÿ�W]ÿ�W]ÿ�W^ÿŽW`ÿŽXaÿ�Xdÿ�YeÿŒYhÿŒZmÿ�[rÿŒ[tÿŒ\uÿŒ\wÿ�\wÿ�\vÿŽ[rÿ�[nÿ�[lÿ�[lÿŽ[pÿŽ[rÿ�ZqÿŒZpÿŒZrÿ�[vÿŒ[vÿ‹Zuÿ‹Zsÿ‹ZsÿŠZtÿŠZtÿŠZsÿŠYrÿ‰XqÿˆXpÿ‰Wpÿ‰Woÿ‰Wmÿ‰ViÿŠVdÿŠT_ÿ‰S]ÿ‰S[ÿŠS[ÿŠSZÿžpˆÿžo‡ÿ�n‡ÿ�m†ÿ�l…ÿ�mƒÿŸmƒÿ m�ÿ m~ÿ¡m|ÿ¢m|ÿ£n|ÿ£n}ÿ£oÿ¤p�ÿ£o�ÿ£nÿ£m{ÿ£mwÿ£ltÿ¤ltÿ¤msÿ¤msÿ¤msÿ¥mrÿ¤lrÿ¤lsÿ£lsÿ¢ltÿ¢kuÿ¢kvÿ¡ktÿ jsÿŸirÿžiqÿžirÿ�irÿ�itÿ�ivÿ�jxÿžj{ÿžk|ÿžk~ÿžlÿŸl€ÿžm�ÿžm�ÿžm‚ÿžmƒÿžm„ÿ�m…ÿžm†ÿžm…ÿŸn…ÿžn„ÿžm‚ÿŸm�ÿ m�ÿ m�ÿ n€ÿ¢n€ÿ£n€ÿ£nÿ£o}ÿ£o{ÿ£nyÿ¤nwÿ¥nvÿ¦nuÿ¦mtÿ¥lqÿ¦mpÿ¦moÿ¦moÿ¥moÿ¦lpÿ¦lpÿ¦lpÿ¥lqÿ¥ltÿ¤luÿ¤mvÿ¤lvÿ¤luÿ£ktÿ¤lrÿ¥kpÿ¥koÿ¥kmÿ¥klÿ§kkÿ§kjÿ§kiÿ§lhÿ§lgÿ¨kfÿ¨kfÿ¨kfÿ¨kfÿ©kfÿ©jeÿªkdÿªlcÿªlaÿ©l`ÿªl_ÿ«l]ÿªk\ÿªk[ÿ«k[ÿ«k\ÿªk\ÿ©k]ÿ©k^ÿªk]ÿ©j[ÿ©jZÿ©jYÿ©jYÿªiZÿ¨j[ÿ©k[ÿ©iZÿ©hXÿ©gWÿªhVÿ©hVÿ¨hWÿ©hXÿ©hYÿ¨i[ÿ¨i\ÿ§i]ÿ§i^ÿ§h`ÿ¨h`ÿ©hcÿªieÿªjgÿªkhÿªlhÿ©kgÿ§ieÿ¦gcÿ¦gdÿ¦geÿ¥gdÿ¥gfÿ¤ggÿ£fhÿ¢ghÿ¢fiÿ¢fkÿ¡emÿ¢foÿ¡fsÿ gxÿŸh{ÿŸh}ÿži€ÿ�hÿœgÿ›gÿ›gÿšgÿšgÿ›e|ÿ›ewÿ›dqÿ›akÿ›aiÿš`hÿš`iÿ™`iÿ˜_hÿ˜_iÿ˜_jÿ˜_jÿ˜_hÿ˜^gÿ—^gÿ—_jÿ—`mÿ—`nÿ–_nÿ—_kÿ—^gÿ–]fÿ–\eÿ•\eÿ“\fÿ“\gÿ’\hÿ’\iÿ’\iÿ‘[fÿ�Zdÿ�Ybÿ�Yaÿ‘Zbÿ�Ycÿ�Ybÿ�Xaÿ�Xaÿ�X`ÿŽX_ÿ�X`ÿ�XaÿŽXaÿŽXbÿŽYdÿ�Xeÿ�YhÿŽZlÿŽ[pÿ�\rÿŒ[tÿŒ\vÿ�]wÿŽ\uÿ�[qÿ�Zlÿ�Zjÿ�[lÿ�\qÿŽ\sÿŽ[rÿ�Zqÿ�Zrÿ�[vÿ�[vÿŒZsÿŒZsÿŒZsÿ‹Ztÿ‹ZsÿŠYsÿŠYrÿŠYqÿ‰XqÿŠYqÿ‰Xnÿ‰WkÿŠWhÿ‹Vdÿ‹T_ÿ‹S\ÿ‹S[ÿ‹SZÿ‹RYÿŸp‰ÿŸoˆÿŸoˆÿžn‡ÿ�m†ÿ�m…ÿžm…ÿžmƒÿŸm�ÿ¡nÿ¢nÿ£o€ÿ£o€ÿ£p€ÿ¤p�ÿ¤p€ÿ¤o~ÿ¤nzÿ¤mwÿ¥muÿ¥msÿ¦mrÿ¦nrÿ¦nqÿ¦nqÿ¦mqÿ¦mrÿ¥msÿ¤mtÿ£muÿ£lvÿ£luÿ¢ktÿ jrÿŸjqÿŸiqÿŸirÿžisÿžiuÿžjwÿžkyÿžkzÿŸl}ÿŸlÿŸm‚ÿŸnƒÿŸnƒÿžnƒÿžn„ÿžn…ÿžn†ÿŸn†ÿŸn†ÿŸn…ÿŸo„ÿŸnƒÿ m‚ÿ m‚ÿ¡n�ÿ¡o�ÿ¢o�ÿ£n€ÿ£o€ÿ£oÿ¤o}ÿ¤ozÿ¦oxÿ§oxÿ§nwÿ§nuÿ¦msÿ¦nrÿ§nqÿ§npÿ§npÿ¨moÿ¨moÿ§moÿ§mpÿ¦mrÿ¦msÿ¦mtÿ¥muÿ¥muÿ¤luÿ¥mtÿ¥mrÿ¥lpÿ¦loÿ¦loÿ§lmÿ§llÿ§llÿ§lkÿ§kjÿ§liÿ¨liÿ¨khÿ©kgÿ©kgÿ©kgÿªlfÿªldÿªlcÿªmbÿ«laÿªl_ÿªl]ÿªl\ÿ«l\ÿªl\ÿ«l]ÿ«l]ÿ«l]ÿ«l]ÿªk\ÿªk[ÿªjZÿªjZÿ«jZÿªj[ÿ«j\ÿªj[ÿªiYÿªhWÿªiVÿ©hVÿ¨hWÿ©hYÿ©iZÿ©i\ÿ©i]ÿ¨i^ÿ§i^ÿ§i_ÿ¨h`ÿ¨hbÿ©idÿªjfÿªlhÿ«miÿ«lhÿ©jgÿ¨ifÿ©jgÿ¨jhÿ¨jhÿ§iiÿ¥hiÿ¤giÿ£giÿ¢gkÿ¢gmÿ¢foÿ¢gpÿ¢gsÿ hwÿ h{ÿŸi}ÿŸhÿžhÿ�hÿœg~ÿ›g~ÿšf~ÿ›f~ÿ›f|ÿœexÿ›drÿ›bmÿ›aiÿš`gÿš`gÿ™`hÿ˜_gÿ—_gÿ˜_iÿ—_jÿ—^hÿ—^gÿ˜^hÿ˜_kÿ—`nÿ—_nÿ–_mÿ—^jÿ–]fÿ–\cÿ–\dÿ•]fÿ“]gÿ’\hÿ’\iÿ’\jÿ’]jÿ‘\hÿ‘[fÿ‘[eÿ‘Zeÿ‘[fÿ‘Zfÿ�Zeÿ�Zdÿ�Ydÿ�Ydÿ�Ydÿ�Ydÿ�Yeÿ�Ydÿ�XcÿŽXcÿŽXeÿŽYgÿ�ZkÿŽ[mÿŽ\pÿ�\rÿ�\uÿŽ\vÿ�\uÿ�[qÿ�Zlÿ�Zkÿ�[nÿ�\rÿ�\tÿŽ[sÿŽ[rÿŽ[sÿŽ\tÿŽ[tÿ�Zrÿ�Zrÿ�ZsÿŒZtÿ‹Ysÿ‹Ztÿ‹Ztÿ‹ZsÿŠYtÿŠYrÿŠXoÿŠXkÿ‹Wgÿ‹Vdÿ‹T`ÿ‹S]ÿ‹S[ÿŒSYÿŒRXÿŸp‰ÿŸpˆÿ pˆÿ p‰ÿžoˆÿžn‡ÿžn‡ÿžn†ÿŸnƒÿ o‚ÿ¢o‚ÿ¢o‚ÿ£p‚ÿ£q‚ÿ¤p�ÿ¤pÿ¥p|ÿ¥ozÿ¥nxÿ¦nwÿ¦nsÿ§nsÿ§orÿ§nqÿ§nqÿ§nqÿ§nrÿ§nsÿ¦ntÿ¥nuÿ¥nvÿ¥nwÿ¤muÿ£krÿ¢kqÿ¡jqÿ jrÿŸjtÿŸjuÿŸjvÿŸkwÿŸkyÿŸl{ÿŸlÿŸnƒÿŸn„ÿŸnƒÿŸnƒÿŸn„ÿŸn…ÿŸn†ÿŸn†ÿŸn†ÿ o…ÿ o…ÿ o„ÿ¡nƒÿ¡nƒÿ¢o‚ÿ¢o�ÿ¢o�ÿ¢o€ÿ¢o€ÿ£o€ÿ¤o~ÿ¤o|ÿ¥ozÿ¦oyÿ¦oyÿ§nxÿ§nuÿ¨ntÿ¨osÿ¨oqÿ¨noÿ¨noÿ©noÿ©noÿ¨noÿ¨npÿ¨nqÿ§mqÿ§mrÿ¦nsÿ¦msÿ¦msÿ¦mrÿ¦mqÿ§lpÿ§moÿ§moÿ§mnÿ§mmÿ§lmÿ§llÿ§lkÿ¨ljÿ¨liÿ©kiÿ©liÿ©lhÿªlgÿªlfÿªleÿªmdÿ«mcÿ«laÿªm_ÿªl^ÿªl]ÿªl]ÿªl]ÿ«l]ÿ¬l]ÿ«l]ÿ«l\ÿªl\ÿªk[ÿªkZÿ«k[ÿ«k[ÿ«j[ÿ«j[ÿªjYÿªiWÿªiWÿ©iVÿ©iWÿ©iYÿ©iZÿ©i[ÿ©i\ÿ©j]ÿ¨i^ÿ¨i_ÿ¨i`ÿ¨ibÿ©icÿ©jdÿ©kfÿ«lhÿ«khÿªjgÿ©kgÿªliÿªljÿ©lkÿ¨kkÿ¦ikÿ¤giÿ£giÿ¢glÿ£gnÿ£gpÿ£gqÿ¢grÿ¡huÿ hyÿ i|ÿŸi~ÿŸiÿžh~ÿ�g}ÿœf|ÿ›f|ÿ›f}ÿœf|ÿœfxÿœdrÿ›bmÿ›aiÿ›`fÿš`fÿ™`fÿ˜_fÿ˜_hÿ—_iÿ—_iÿ–_hÿ—_gÿ—_hÿ˜_jÿ—_lÿ—_mÿ–`mÿ—^iÿ–]eÿ•\bÿ•\bÿ”\eÿ“]iÿ’\jÿ‘\jÿ’\kÿ’\kÿ’\jÿ‘\hÿ‘\gÿ‘\iÿ‘\kÿ‘\jÿ�[jÿ�[iÿ�[hÿ�Ziÿ�Ziÿ�Ziÿ�Zhÿ�YfÿŽXeÿŽXdÿŽXdÿŽYfÿŽYhÿŽZjÿ�[mÿŽ\pÿ�\tÿŽ]vÿ�]uÿ�\qÿ�[nÿ�[mÿ�[oÿ�\rÿ�\uÿ�\tÿ�[sÿ�[rÿ�[sÿ�[rÿŽ[qÿŽZqÿŽZrÿ�Zsÿ‹ZtÿŒZuÿŒZtÿ‹Zsÿ‹Zsÿ‹Yrÿ‹Xoÿ‹Wjÿ‹Vgÿ‹Vdÿ‹Uaÿ‹T^ÿ‹S[ÿŒRZÿŒSYÿŸpŠÿ q‰ÿ¡qŠÿ¡q‹ÿ qŠÿŸp‰ÿŸpŠÿŸo‰ÿžo†ÿŸo…ÿ o„ÿ¡p…ÿ¢q…ÿ¤q„ÿ¥q‚ÿ¥q€ÿ¥q}ÿ¥p|ÿ¦pzÿ¦oxÿ¨puÿ¨otÿ¨osÿ¨orÿ¨oqÿ¨oqÿ¨oqÿ¨prÿ§psÿ§otÿ§owÿ§owÿ§nuÿ¦msÿ¥lqÿ£kpÿ¢krÿ¡ktÿ¡ktÿ kuÿ kwÿ lxÿ l{ÿŸmÿ nƒÿ nƒÿŸn‚ÿŸn‚ÿ nƒÿ o…ÿŸo…ÿ n…ÿ¡o…ÿ¡p†ÿ¡p…ÿ¡o„ÿ¢o„ÿ¢o„ÿ¢oƒÿ¢oƒÿ£o‚ÿ£o�ÿ¢o€ÿ£o€ÿ£p€ÿ¤o~ÿ¤p|ÿ¥p|ÿ¦p{ÿ¨pzÿ¨owÿ©pvÿ©otÿ¨orÿ¨npÿ©opÿªooÿªnoÿªnnÿ©noÿ©noÿ©noÿ¨npÿ¨nqÿ¨nqÿ§mqÿ§mqÿ¨mqÿ¨moÿ¨moÿ¨moÿ¨moÿ¨mnÿ¨mnÿ¨mnÿ¨lmÿ¨lkÿ¨lkÿ©lkÿ©lkÿ©liÿªlhÿªlgÿªmgÿªmfÿ«meÿ«mdÿªmcÿªmaÿ«m`ÿ«m`ÿ«m_ÿ«l^ÿ¬l^ÿ¬l]ÿ«l]ÿ«l\ÿ«l\ÿ¬k[ÿ«k[ÿ«k[ÿ«k[ÿ«kZÿ«jYÿªjXÿªjWÿªjWÿªjXÿªjZÿªj[ÿªj[ÿ©j\ÿ©j]ÿ©j^ÿ¨j_ÿ§i`ÿ¨jaÿ©jbÿ©jbÿ©jcÿªkfÿªkfÿªkfÿªlgÿ«miÿ«mjÿ©lkÿ¨kkÿ¦ikÿ¤giÿ£fiÿ£gmÿ£hpÿ£hqÿ£hrÿ£hrÿ¢htÿ¡hwÿ izÿ j}ÿ i~ÿŸi}ÿžg{ÿ�g{ÿœg{ÿœg{ÿœf{ÿ�fwÿœerÿ›clÿ›aiÿ›`fÿ›`eÿ™`fÿ˜_gÿ˜_iÿ—_iÿ–_hÿ–_gÿ–_gÿ—^gÿ—_gÿ—_iÿ—_kÿ—_kÿ–^hÿ•]eÿ•\bÿ”\bÿ“\dÿ“]jÿ‘]lÿ�]lÿ‘]mÿ‘\mÿ‘]mÿ�\jÿ�\iÿ‘\lÿ’]nÿ‘]nÿ‘\nÿ‘\mÿ�\mÿ�\nÿ�\nÿ�[mÿ�Zjÿ�YgÿŽYfÿŽYeÿŽYeÿŽYfÿŽYgÿ�Yiÿ�ZlÿŽ\oÿŽ]tÿŽ]wÿŽ]vÿ�]sÿ�\qÿ�\pÿ�\qÿ�]sÿ�]uÿ�]uÿ�\tÿ�\rÿ�\rÿ�[rÿ�[qÿŽ\rÿŽ[sÿ�[tÿŒ[uÿ�[uÿ�ZsÿŒYpÿŒYoÿ‹Ynÿ‹Xlÿ‹WiÿŒVfÿŒVeÿ‹Uaÿ‹T]ÿ‹S[ÿ‹RYÿŒSXÿ q‹ÿ¡q‹ÿ¡rŒÿ¡rŒÿ¡rŒÿ q‹ÿ q‹ÿŸq‹ÿŸpŠÿŸpˆÿ pˆÿ¡pˆÿ¢q‡ÿ¤r†ÿ¦r„ÿ¥rƒÿ¦r€ÿ§q~ÿ§q|ÿ§pyÿ©qwÿ©ptÿ©psÿ©qsÿ©qrÿ©prÿ©pqÿ©prÿ©qsÿ©ptÿ©qvÿ©qwÿ©pvÿ¨osÿ§nqÿ¦mqÿ¥msÿ¤ltÿ£luÿ¢luÿ¡mwÿ¡mxÿ mzÿ m}ÿ n�ÿ¡n‚ÿ¡o�ÿ¡o�ÿ¡oƒÿ¢o„ÿ¡p…ÿ¢o…ÿ£p…ÿ£p†ÿ£p†ÿ¢p…ÿ£p…ÿ£p„ÿ£p„ÿ£p„ÿ£p„ÿ£pƒÿ£p‚ÿ£p‚ÿ¤q‚ÿ¤p€ÿ¥q€ÿ¦q€ÿ§qÿ¨q}ÿ¨pzÿ©qyÿªpvÿ©otÿ©orÿªpqÿ«oqÿªooÿªonÿ«onÿªonÿ«onÿ«ooÿªooÿ©npÿ©npÿ©npÿ©noÿ©noÿ©nnÿ©noÿ©noÿ©nnÿ©nnÿ©nnÿ©mmÿ©mmÿ©mmÿ©mmÿªmlÿ©ljÿªliÿªmiÿªmiÿªmhÿ«mhÿªmgÿ«mfÿ«neÿ¬ndÿ­ncÿ¬mcÿ¬mbÿ¬m`ÿ­m_ÿ¬m^ÿ¬m^ÿ­m]ÿ­l\ÿ¬l[ÿ¬kZÿ¬l[ÿ¬lZÿ«kYÿ«kXÿ«kXÿ«kXÿ«kZÿ«k\ÿ«k\ÿ«k\ÿªj\ÿ©j]ÿ©j_ÿ©k`ÿ¨jaÿ¨jaÿ©j`ÿ©j`ÿ©kaÿªlcÿªkdÿ«leÿ­ngÿ­oiÿ«mjÿªljÿ¨jjÿ¦ijÿ¥giÿ£gjÿ£hpÿ£itÿ£itÿ£isÿ£hrÿ¢hsÿ¡huÿ hwÿ¡i{ÿ¡i}ÿ i}ÿŸh|ÿžgzÿ�gzÿœg{ÿ�fzÿ�fwÿ�esÿœblÿ›ajÿ›ahÿ›agÿš`gÿ™`hÿ˜`iÿ—_jÿ–_iÿ–^hÿ–^gÿ—]fÿ—^fÿ—_gÿ—_hÿ—_iÿ•^gÿ•]eÿ”\eÿ“\dÿ’\fÿ“]kÿ‘]nÿ�]pÿ�^qÿ�]qÿ�]qÿ�\oÿ�\nÿ�]oÿ‘^pÿ‘^qÿ�]qÿ‘]qÿ‘]rÿ�]rÿ�]qÿ�\oÿ�[lÿ�Ziÿ�Zgÿ�Zgÿ�Zgÿ�Zgÿ�Zhÿ�ZiÿŽ[mÿ�]qÿ�^uÿ�^xÿŽ^xÿ�^vÿ�]tÿ�]sÿ‘]tÿ‘^uÿ‘_vÿ‘^vÿ‘]tÿ‘]rÿ’]qÿ‘\qÿ�\qÿ�\sÿŽ\uÿ�\uÿŽ\uÿŽ[sÿŽZoÿ�Ykÿ�XhÿŒXhÿŒXhÿŒXgÿŒWfÿŒWdÿŒVaÿŒU]ÿŒSYÿ‹SVÿ‹RUÿ¢r�ÿ¡r�ÿ¡r�ÿ¢r�ÿ£s�ÿ¢r‹ÿ¢sŒÿ¢rŒÿ qŒÿ pŒÿ¡q‹ÿ¡q‹ÿ¡qŠÿ£rˆÿ¥s‡ÿ§t†ÿ§sƒÿ§r€ÿ§r}ÿ©q{ÿ©qxÿ©pvÿªquÿªruÿªruÿ«qtÿªpsÿªqsÿ«qtÿ«ruÿªqvÿªrwÿ«qvÿªpuÿ©prÿ©psÿ¨ptÿ§ouÿ¥nvÿ¤mvÿ£nwÿ¢mxÿ¢mzÿ¢n|ÿ¢nÿ£o�ÿ£p�ÿ¤p�ÿ¤pƒÿ¤q…ÿ¤q…ÿ¤q†ÿ¤q†ÿ¤q…ÿ£q„ÿ¤q…ÿ£q„ÿ£q„ÿ¤q…ÿ¤p„ÿ£p„ÿ¤p„ÿ¤pƒÿ¤pƒÿ¤pƒÿ¥p‚ÿ¦q‚ÿ§q�ÿ¨r€ÿ¨rÿ©r}ÿªr|ÿ«qyÿ«pvÿªptÿ«qtÿªprÿªppÿ«poÿ­pnÿ¬pmÿ¬pnÿ¬onÿ¬onÿ¬pnÿ«ooÿ«noÿªnnÿªnnÿ«nnÿªnmÿªnnÿªnnÿªonÿªonÿªnnÿªnnÿªnnÿªnnÿªmmÿªnlÿ«nlÿ«nlÿ«nkÿ«mkÿªmkÿ«mjÿ¬miÿ¬miÿ¬nhÿ«mfÿ¬mfÿ¬neÿ­ndÿ­mbÿ¬m`ÿ­m_ÿ­m^ÿ­m]ÿ­m\ÿ­l\ÿ­l\ÿ¬l[ÿ¬lZÿ¬lYÿ¬lXÿ¬lYÿ¬k[ÿ¬k]ÿ«k]ÿªk]ÿ«k^ÿªk_ÿªk`ÿ©kaÿªj`ÿªk`ÿ©j`ÿ©j`ÿ©jaÿªlcÿ«mdÿ­nfÿ¯oiÿ¯pjÿ­niÿªliÿ¨jiÿ¦iiÿ¥hjÿ¤glÿ¤isÿ£jwÿ£jxÿ¤jwÿ£isÿ£hqÿ¢hrÿ¡huÿ¡izÿ j}ÿ i~ÿŸh}ÿŸh|ÿžh|ÿžh|ÿžgzÿžgyÿ�euÿœcnÿœbkÿœaiÿœajÿ›ajÿšajÿ™`kÿ˜alÿ—`kÿ–_jÿ–^iÿ–^gÿ—_hÿ—_hÿ–^hÿ–_hÿ•^iÿ”]iÿ”]hÿ“\hÿ’\jÿ’]mÿ‘]pÿ�^sÿŽ^tÿŽ^uÿŽ]uÿŽ]tÿŽ\sÿŽ\sÿ�]sÿ�^sÿ‘]sÿ�]tÿ�^uÿ�^uÿ�]sÿ�\pÿ�[mÿ�[jÿŽZjÿ�Yjÿ�Zjÿ�ZkÿŽZkÿ�[lÿ�\oÿ�]tÿ�^wÿ�_yÿ�_zÿ�_yÿ�^wÿ‘^vÿ’_vÿ’_vÿ“`vÿ’_vÿ’^tÿ“^rÿ’^qÿ“\oÿ‘[nÿ�[pÿ�[rÿŽ[rÿ�[qÿŽZnÿ�Yjÿ�Xeÿ�WbÿŒVbÿŒWbÿŒWbÿŒWbÿ�V`ÿ�U^ÿŒT\ÿŒSYÿŒSVÿŒSUÿ¡sŽÿ¢sŽÿ¢sŽÿ£s�ÿ£s�ÿ£sŒÿ¤tŒÿ£t�ÿ¢sŽÿ¡rŽÿ¢rŽÿ¡rŽÿ¡rŒÿ¢rŠÿ¤s‰ÿ¦tˆÿ¨t…ÿ¨s‚ÿ¨r~ÿ¨r|ÿ©rzÿ©qxÿªrwÿ«rwÿ«svÿ«rvÿ«quÿ«ruÿ«ruÿ«ruÿ«rvÿªrvÿ«rvÿ«quÿªqtÿªqtÿªquÿ©pvÿ§pwÿ¥oxÿ¥oxÿ¤nyÿ£ozÿ£o|ÿ£o}ÿ¤oÿ¥p�ÿ¥p�ÿ¦qƒÿ¦r„ÿ¥r…ÿ¥r†ÿ¥r†ÿ¥r…ÿ¤rƒÿ¥rƒÿ¤rƒÿ¥qƒÿ¥q„ÿ¤qƒÿ£p„ÿ£p„ÿ£p„ÿ£p„ÿ¤pƒÿ¥qƒÿ¦q‚ÿ¦q‚ÿ§r�ÿ¨r�ÿ©sÿªs~ÿ«r|ÿ«qxÿ«pvÿ¬qvÿ«rtÿ«qrÿ¬qpÿ­qoÿ­qnÿ­pmÿ­pmÿ­pmÿ­pmÿ­pnÿ¬onÿ¬onÿ«nnÿ«nnÿ«onÿ«omÿ«omÿ«omÿ«onÿ«ooÿªonÿªnnÿªnnÿªnnÿªnmÿªnmÿ«nlÿ«mlÿ«nmÿªnmÿ«nmÿ«nmÿ«nlÿ«nkÿ¬njÿ¬njÿ­oiÿ­ogÿ®neÿ­ncÿ­n`ÿ­m_ÿ­m^ÿ­m]ÿ­m]ÿ­l\ÿ­m\ÿ­m[ÿ¬lZÿ­lZÿ¬lZÿ¬l[ÿ«l]ÿ¬l^ÿ«l^ÿªk_ÿ«k`ÿªkaÿªkbÿ©kaÿ©k`ÿ©k`ÿ©jaÿ¨jaÿªlcÿ¬meÿ­ngÿ®ohÿ­oiÿ¬mhÿ©khÿ¨kiÿ¨kkÿ§klÿ¦inÿ¥jtÿ¤kxÿ£kyÿ£kwÿ¤jrÿ¤ipÿ£hqÿ¡htÿ iwÿ¡i{ÿ i|ÿ h|ÿŸi}ÿži}ÿžh{ÿžgzÿžgxÿžfuÿ�coÿ�blÿœbkÿœbkÿ›bkÿšblÿ™amÿ˜bnÿ—aoÿ–`nÿ–_mÿ–_kÿ–_kÿ–_kÿ–_kÿ–`lÿ•_mÿ”_nÿ“^mÿ“^mÿ’]nÿ‘]pÿ�]sÿ�^uÿŽ^vÿ�^wÿ�^wÿ�^wÿ�]wÿŽ]wÿŽ]wÿ�^uÿ�]uÿ�^vÿ�_xÿ�^wÿŽ]sÿ�\pÿ�[mÿ�Zkÿ�Ziÿ�Ziÿ�ZjÿŽZlÿŽ[nÿ�[oÿŽ]qÿ�^uÿ�_yÿ�_{ÿ�_{ÿ�_zÿ�_xÿ�_wÿ’_vÿ’_uÿ“`uÿ”_sÿ“^qÿ“]oÿ“]nÿ’\lÿ‘[kÿ‘[mÿ�[oÿ�[nÿ�[mÿŽZiÿ�Xeÿ�Waÿ�V]ÿ�U\ÿŒV\ÿŒV]ÿ�V]ÿŒV\ÿ�U[ÿŒTYÿŒSWÿŒSVÿŒSUÿ s�ÿ¡s�ÿ¢sŽÿ£sŽÿ£t�ÿ¤t�ÿ¤uŽÿ¤u�ÿ£t�ÿ¢t�ÿ£t�ÿ¢s�ÿ¡rŽÿ¢rŒÿ£s‹ÿ¥sˆÿ§t†ÿ¨t„ÿ¨s�ÿ¨s~ÿ©s}ÿ©r{ÿªrzÿ«szÿ«szÿ¬syÿ¬sxÿ¬swÿ«svÿ«svÿ«svÿ«rwÿ«rwÿ¬rxÿ¬swÿ¬swÿ¬swÿ«rxÿªryÿ¨qyÿ¨qzÿ¦pzÿ¥p{ÿ¤p|ÿ¥p~ÿ¥pÿ¥p�ÿ¥q‚ÿ¦r„ÿ¦r…ÿ¦s†ÿ¥s‡ÿ¦rˆÿ¥sˆÿ¥s…ÿ¦s„ÿ¦r„ÿ¦r„ÿ¥r„ÿ¤q„ÿ¤q„ÿ¤q„ÿ£q„ÿ¤q„ÿ¤qƒÿ¥qƒÿ¦qƒÿ¦qƒÿ§rƒÿ¨r‚ÿ¨s‚ÿªt�ÿªsÿ«r|ÿ¬rzÿ¬syÿ¬swÿ¬rsÿ¬qqÿ­qpÿ®qoÿ¯qnÿ¯qmÿ¯qmÿ®qmÿ®qlÿ­qlÿ­qmÿ­pmÿ¬omÿ¬onÿ¬onÿ¬pnÿ¬poÿ¬poÿ«ooÿ«poÿªopÿªopÿªooÿ«onÿªonÿ«nmÿ«nmÿªnnÿªnoÿ«npÿ«npÿ«opÿ«onÿ¬onÿ¬olÿ¬okÿ­piÿ®ohÿ®oeÿ­ncÿ­nbÿ¬naÿ­n`ÿ­m_ÿ­m^ÿ®m^ÿ­m]ÿ¬m]ÿ­l]ÿ­l]ÿ¬m]ÿ¬m^ÿ¬m^ÿ¬l_ÿ«l`ÿ«kaÿ«kbÿªlaÿ©laÿ©kaÿ©kaÿ©kaÿ©kaÿªlcÿ«meÿ¬ngÿ¬ngÿ«mgÿ«lhÿªlhÿ©liÿ©lkÿ©lmÿ¨loÿ¦ltÿ¥lwÿ¥lyÿ¤kwÿ¤jqÿ£inÿ£hpÿ¢hsÿ¡iuÿ¡ixÿ¡izÿ i|ÿ i}ÿŸi}ÿŸgzÿžgxÿžgvÿŸfsÿžcnÿžbkÿ�bjÿœbkÿ›bmÿšboÿ™boÿ˜bqÿ—brÿ—brÿ–arÿ–apÿ–`oÿ•`oÿ–`oÿ•`pÿ”`qÿ“_rÿ’_rÿ’_rÿ‘^rÿ�^sÿ�^vÿŽ^wÿŽ^xÿ�^xÿŒ^yÿŒ^yÿŒ^yÿ�^zÿŽ^yÿŽ^xÿŽ^xÿŽ^yÿ�_zÿŽ^wÿŽ\sÿ�\oÿ�[lÿ�Zjÿ�Zhÿ�Zgÿ�Ziÿ�[lÿŽ\oÿŽ\qÿŽ]sÿŽ^vÿ�_yÿ�_{ÿ�_{ÿ�_{ÿ�_zÿ‘_yÿ’_vÿ“^sÿ“^pÿ”]nÿ“\kÿ“\jÿ“\jÿ’\iÿ‘[iÿ‘[kÿ‘[lÿ�[kÿ�ZiÿŽYfÿŽWbÿ�V^ÿŽU[ÿŽUZÿ�UYÿ�UXÿ�UXÿ�UXÿ�TXÿ�TWÿŒTWÿŒTXÿŒTWÿŸs’ÿ¡s’ÿ¢t‘ÿ¢t�ÿ£u�ÿ¤u�ÿ¥v‘ÿ¥v’ÿ¥v‘ÿ£u‘ÿ£u�ÿ¢t�ÿ¢s�ÿ¢sŽÿ¢rŒÿ¤s‰ÿ¦s‡ÿ§t…ÿ¨tƒÿ¨t‚ÿ©s€ÿ©s~ÿªs~ÿ«t~ÿ¬t~ÿ¬u~ÿ­u|ÿ­tzÿ¬txÿ¬txÿ¬sxÿ¬szÿ¬s{ÿ¬t{ÿ­tzÿ­tyÿ­tyÿ­tzÿ¬szÿ«t{ÿªs{ÿªr{ÿ¨r|ÿ§r|ÿ§q~ÿ¦q€ÿ¦q‚ÿ¥r„ÿ¥r†ÿ¥r‡ÿ¦sˆÿ¦sŠÿ¦t‹ÿ¦tŠÿ¦t‰ÿ§sˆÿ§s‡ÿ¦s†ÿ¦s…ÿ¦s…ÿ¦s„ÿ¥s…ÿ¥r…ÿ¥r„ÿ¦r„ÿ¦r„ÿ§s„ÿ§r„ÿ§r„ÿ¨r„ÿ©t„ÿ©tƒÿªt‚ÿ«t€ÿ¬s~ÿ­t|ÿ­syÿ¬ruÿ¬rrÿ­qqÿ®rpÿ¯rpÿ¯rnÿ¯rmÿ¯smÿ¯rkÿ¯rkÿ¯rkÿ¯qkÿ¯qlÿ®qmÿ®pnÿ®poÿ®qpÿ­ppÿ¬ppÿ«ppÿ«pqÿ«pqÿ«pqÿ«pqÿ«ppÿ«opÿ«ppÿªoqÿ«pqÿ«prÿ«psÿªpsÿ«prÿ¬ppÿ¬onÿ­olÿ­ojÿ®piÿ®ohÿ®ofÿ­ofÿ­oeÿ­neÿ­ncÿ­nbÿ®naÿ­naÿ­maÿ­maÿ­m`ÿ­m_ÿ­m_ÿ­m_ÿ­m_ÿ¬m`ÿ«lbÿ«lbÿªlbÿªmbÿªlbÿªkbÿªlcÿªlcÿªlcÿ«meÿ¬nfÿ¬ngÿ¬mhÿ­niÿ¬niÿ«niÿªmjÿªmmÿ©moÿ§lsÿ¦lwÿ¦mxÿ¥lvÿ¤jpÿ£hmÿ£goÿ£grÿ¢htÿ¢iuÿ¢iyÿ¡j}ÿ i~ÿ i}ÿŸgzÿŸfvÿŸfsÿŸeoÿŸdkÿžbiÿ�bhÿ�ckÿœcnÿšcpÿšcqÿ™csÿ˜ctÿ˜cuÿ—buÿ–atÿ–asÿ•asÿ•asÿ•`sÿ”_tÿ’_uÿ’`vÿ‘`vÿ�_vÿ�_vÿ�^xÿ�^yÿ�_yÿŒ^yÿŒ^zÿŒ]zÿŒ]yÿ�^zÿŽ^zÿŽ_zÿŽ_zÿŽ^{ÿŽ^zÿŽ^xÿŽ]sÿ�\pÿ�\mÿ�[iÿ�Zfÿ�Zeÿ�Zgÿ�[kÿ�\oÿŽ]sÿ�]uÿ�^wÿ�_yÿ�_{ÿ�_{ÿ�_{ÿ‘_{ÿ’_yÿ“_uÿ“^oÿ“\jÿ“[hÿ“[gÿ“[fÿ“[gÿ’[gÿ’[hÿ‘[iÿ‘[iÿ‘Zhÿ�Yfÿ�XdÿŽWaÿŽV^ÿŽU[ÿ�VYÿŽUXÿŽTVÿ�TVÿ�TWÿ�TXÿ�TXÿŒTXÿŒTYÿŒU[ÿžs–ÿŸt–ÿ¡u•ÿ¢u”ÿ£v”ÿ¤v”ÿ¤w”ÿ¥w”ÿ¥w“ÿ¤v’ÿ¤u‘ÿ¤u‘ÿ¤u�ÿ£t�ÿ¢s�ÿ£s‹ÿ¤sˆÿ¥s‡ÿ§t†ÿ¨t…ÿ©tƒÿªt‚ÿªt�ÿ«t‚ÿ¬u‚ÿ¬v�ÿ­v€ÿ®v~ÿ®u|ÿ®uzÿ­t{ÿ­t|ÿ­u~ÿ¬u}ÿ­t|ÿ®u{ÿ­uzÿ­tzÿ­t{ÿ­u|ÿ­u|ÿ­t}ÿ«t}ÿªs}ÿ¨rÿ¨r€ÿ§s„ÿ§s‡ÿ¦s‰ÿ¥tŒÿ¦tŒÿ§u�ÿ§uŽÿ§uŽÿ¨u�ÿ¨uŒÿ§tŠÿ§t‰ÿ§tˆÿ¨t†ÿ§t…ÿ¨t†ÿ¨t†ÿ§s…ÿ§s…ÿ¨s…ÿ©t…ÿ¨t…ÿ¨s…ÿ©s†ÿ©s…ÿªt…ÿªu„ÿ«uƒÿ¬t�ÿ¬t}ÿ­syÿ®swÿ­stÿ­rrÿ®sqÿ¯sqÿ¯spÿ¯rnÿ°rmÿ°rkÿ°rjÿ°rjÿ°rjÿ±rkÿ°skÿ¯rlÿ¯qmÿ¯qnÿ®qnÿ­qoÿ¬ppÿ­qqÿ¬qrÿ«qsÿ«psÿ¬psÿ¬qrÿ«qrÿ«ptÿ¬quÿ¬quÿ¬quÿ«puÿ«ptÿ«qsÿ¬ppÿ­poÿ®omÿ¯pkÿ¯pkÿ¯pkÿ®pjÿ­ojÿ®oiÿ­ngÿ­ngÿ®ofÿ®oeÿ­ndÿ®ndÿ­mbÿ®maÿ®m`ÿ­n_ÿ®m`ÿ­maÿ¬mbÿ¬mcÿ«mcÿ«ldÿ«ldÿ«ldÿªkdÿªkdÿªlcÿ«mdÿ¬neÿ­nfÿ­ohÿ®pjÿ®piÿ¬niÿªmjÿ©mmÿ©mnÿ§lqÿ§mvÿ¨nxÿ§muÿ¥joÿ¤imÿ¤gnÿ£gpÿ£hsÿ¢huÿ¢iyÿ¡i}ÿ iÿŸi~ÿŸhzÿŸguÿ epÿ dlÿŸciÿžbfÿ�bfÿ�chÿœdlÿ›dpÿ›crÿšdtÿ™dvÿ™dxÿ˜dwÿ—bvÿ—avÿ–auÿ•auÿ”`vÿ“`vÿ’`wÿ’`wÿ’`xÿ‘`xÿ�`xÿ�_yÿ�_yÿŽ_zÿ�_zÿŒ_{ÿ�^zÿ�^yÿŽ^yÿ�^yÿ�_zÿ�_zÿŽ_zÿŽ^zÿ�^yÿŽ^vÿ�]rÿ�\nÿ�[iÿ�Zeÿ�Zeÿ�[gÿ�\jÿ�\oÿ�]sÿ�]vÿ�^xÿ�_yÿ�_yÿ�`zÿ‘`zÿ‘_xÿ’^uÿ“]pÿ’\jÿ“[fÿ“Zeÿ“[eÿ“[dÿ’Zdÿ“[dÿ“[eÿ’[eÿ‘Zeÿ�Zdÿ�Xdÿ�Xcÿ�Xbÿ�W`ÿ�V]ÿ�VZÿŽUXÿŽTWÿŽTVÿŽUWÿŽTXÿ�TYÿ�TYÿŒTZÿŒU\ÿžušÿŸušÿ¡u™ÿ¡u˜ÿ¡v—ÿ¢v—ÿ£w—ÿ£w–ÿ¤v“ÿ¤v’ÿ¥v“ÿ¤v‘ÿ¤u�ÿ¤uŽÿ¤tŽÿ¤sŒÿ¤sŠÿ¥sˆÿ¥t‡ÿ¦u‡ÿ¨u†ÿ©u…ÿªu…ÿ«u…ÿ¬v„ÿ¬vƒÿ­w‚ÿ®w�ÿ®vÿ®u}ÿ®v}ÿ®wÿ­wÿ­v~ÿ®u}ÿ®v}ÿ®v|ÿ®u|ÿ®v}ÿ¯wÿ®w~ÿ®v~ÿ®u~ÿ¬u~ÿ«u€ÿ«uƒÿ©u‡ÿ¨v‹ÿ§vŽÿ§v�ÿ¦w‘ÿ¦v‘ÿ§v‘ÿ§w’ÿ¨w‘ÿ¨w�ÿ©vŽÿ¨vŒÿ¨v‹ÿ¨v‰ÿ©u‡ÿ©u‡ÿ©u†ÿ©t†ÿ¨t…ÿ¨t…ÿ©t…ÿ©t…ÿ©t†ÿ©u…ÿ©t†ÿªu†ÿªu†ÿ«u…ÿ«uƒÿ­uÿ®t{ÿ®sxÿ®suÿ®stÿ¯ttÿ¯ttÿ¯ssÿ°spÿ°snÿ°skÿ±sjÿ²sjÿ²tjÿ°siÿ±tjÿ±skÿ°rkÿ°rjÿ°rkÿ°rkÿ®qmÿ­qnÿ­qpÿ®qpÿ­qpÿ­qqÿ­qrÿ­qrÿ¬qrÿ¬qtÿ¬quÿ¬qvÿ¬qvÿ«qvÿ¬quÿ«qtÿ¬prÿ­ppÿ­pnÿ®pnÿ®pnÿ®pnÿ­pnÿ­pnÿ­pmÿ®omÿ®okÿ®oiÿ®phÿ­ogÿ®neÿ®ncÿ®naÿ­n`ÿ®naÿ­ncÿ¬neÿ¬nfÿ¬nfÿ«meÿ«leÿ«leÿ«leÿ«ldÿ«mdÿ¬mcÿ¬mdÿ¬neÿ¬ngÿ®piÿ­phÿ¬nhÿªmjÿ©mmÿ¨lmÿ§mpÿ¨nuÿ¨nvÿ§msÿ¥joÿ¤imÿ¤hmÿ¤hnÿ£hpÿ¢htÿ¡iyÿ¡j}ÿ jÿ j~ÿŸhzÿŸgsÿŸenÿ djÿŸcfÿ ceÿžceÿ�chÿ�ckÿ�doÿ›drÿ›duÿšdvÿšewÿ™dxÿ˜dwÿ–bvÿ•avÿ”awÿ“bxÿ’axÿ’axÿ’awÿ’axÿ‘axÿ�`yÿ�_yÿ�_yÿ�`zÿŽ_{ÿ�_{ÿŽ_zÿŽ_yÿŽ_yÿ�_xÿ�_xÿŽ_yÿ�_zÿ�_{ÿ�`{ÿ�_zÿ�^vÿ�]qÿ�[kÿ�Zfÿ‘[fÿ‘\gÿ‘\kÿ‘]qÿ�]uÿ�_xÿ�_yÿ�_yÿ�`yÿ‘_yÿ‘_xÿ’_uÿ’^pÿ“\jÿ’[eÿ“[dÿ’Zdÿ’[cÿ“[cÿ“Zbÿ’[aÿ’Zbÿ‘Y`ÿ�Y_ÿ‘Yaÿ�Ybÿ�Ybÿ�Xbÿ�Waÿ�V^ÿ�V[ÿ�UYÿŽUXÿŽUWÿŽUXÿŽTZÿ�U[ÿ�U[ÿ�U\ÿ�U]ÿŸvœÿŸvœÿ u›ÿ¡ušÿ¡u˜ÿ¢u—ÿ£v—ÿ£w•ÿ£v“ÿ£u“ÿ¤v“ÿ¥v‘ÿ¥v�ÿ¥uŽÿ¥u�ÿ¤t�ÿ£t‹ÿ¤s‰ÿ¥sˆÿ¥tˆÿ¦u‡ÿ¨u‡ÿ©uˆÿ«v‡ÿ­w…ÿ­wƒÿ®x‚ÿ®xƒÿ®x‚ÿ¯wÿ¯w~ÿ®xÿ®xÿ¯w~ÿ¯v}ÿ®v}ÿ®v}ÿ¯w~ÿ¯xÿ¯xÿ¯x~ÿ¯x}ÿ¯w}ÿ®v~ÿ­v�ÿ­v„ÿ¬wˆÿ«w‹ÿªxŽÿ¨x‘ÿ¨y”ÿ¨x•ÿ¨x—ÿ¨y—ÿ§y•ÿ¨x“ÿ©x‘ÿ©w�ÿ¨w�ÿ¨vŠÿ©vˆÿ©vˆÿ©u‡ÿªu†ÿ©u†ÿ©u†ÿ©u†ÿªu…ÿªu„ÿªv„ÿªu„ÿ«u…ÿ«u„ÿ«u„ÿ«uƒÿ­v‚ÿ­vÿ®u{ÿ®txÿ¯twÿ°uvÿ¯ttÿ¯tsÿ°trÿ±toÿ±tmÿ²skÿ²tjÿ²ujÿ±tjÿ±ukÿ±tjÿ±siÿ²sgÿ²sgÿ²sgÿ±rhÿ°rjÿ°rlÿ¯rmÿ¯rmÿ¯rnÿ®roÿ®rpÿ®rpÿ­rrÿ­rtÿ­ruÿ­rvÿ¬ruÿ­rvÿ¬quÿ¬qsÿ¬qqÿ­qpÿ­ppÿ­pqÿ­qrÿ­qsÿ¬qtÿ¬ptÿ­prÿ­opÿ­omÿ­okÿ®ojÿ®nhÿ®nfÿ­odÿ®odÿ­odÿ¬neÿ¬nfÿ­ogÿ­ogÿ¬nfÿ¬mfÿ¬mfÿ«meÿ«mdÿ¬mcÿ¬mcÿ¬mcÿ«mcÿ¬meÿ­ofÿ¬pgÿ¬phÿ¬ojÿ«nlÿªnlÿ©npÿ©nsÿ¨ntÿ¦lqÿ¥knÿ¥imÿ¤hlÿ¤hkÿ£gmÿ£grÿ¡ixÿ¡j}ÿ j~ÿ j}ÿ iyÿŸgsÿ fnÿ diÿŸceÿŸcdÿžcfÿžciÿždkÿženÿ�eqÿœdsÿ›dtÿ›duÿšcvÿ™cvÿ—buÿ•auÿ”bwÿ“byÿ’axÿ’axÿ’axÿ‘awÿ‘awÿ‘`xÿ‘`xÿ�`yÿ�`zÿ�_|ÿŽ`{ÿ�_zÿ�_yÿ�_zÿ�`yÿŽ`zÿ�_zÿ�_|ÿ�`}ÿ�`~ÿ�`~ÿ�`|ÿ�^wÿ�]pÿ‘\jÿ’\hÿ’\iÿ‘]nÿ‘^tÿ‘_yÿ‘`zÿ‘`{ÿ‘`{ÿ‘`{ÿ‘`yÿ’_wÿ’_tÿ“^oÿ“\iÿ’[eÿ“[dÿ“[dÿ“Zcÿ“Zbÿ”Zaÿ“Z`ÿ’Z_ÿ’Y]ÿ‘Y\ÿ‘X\ÿ‘X_ÿ‘Ybÿ�Ycÿ�XaÿŽW^ÿ�W\ÿ�V[ÿŽVZÿ�VYÿŽVYÿŽU[ÿŽV]ÿŽV]ÿŽU^ÿ�U^ÿ¡vœÿ¡vœÿ¡vœÿ¡u›ÿ¡u™ÿ¡v˜ÿ£v—ÿ¤w–ÿ¤v•ÿ£v•ÿ£v”ÿ¤v“ÿ¥v‘ÿ¥v�ÿ¥u�ÿ¤u�ÿ¤tŒÿ¤tŠÿ¥tŠÿ¥t‰ÿ¥u‰ÿ¦uŠÿ¨uŠÿªw‰ÿ­x†ÿ­xƒÿ®x‚ÿ®y„ÿ¯y„ÿ¯x�ÿ¯x~ÿ¯x~ÿ¯x~ÿ°x}ÿ¯w|ÿ¯w|ÿ¯w~ÿ¯xÿ¯x€ÿ°x€ÿ°x~ÿ±x}ÿ±x|ÿ°x~ÿ¯xÿ¯x‚ÿ®y…ÿ­yˆÿ¬y‹ÿ«yŽÿªz’ÿ©z–ÿ¨z˜ÿ¨zšÿ¨y™ÿ¨y–ÿ©y“ÿªy‘ÿªxŽÿªw‹ÿªv‰ÿªv‰ÿªv‰ÿªvˆÿªu‡ÿªu†ÿ«v‡ÿ«v†ÿ«v…ÿ«v„ÿ¬v…ÿ­w„ÿ¬v‚ÿ¬v‚ÿ¬vƒÿ­vƒÿ®w�ÿ®vÿ®u|ÿ¯u{ÿ°uxÿ°uwÿ°tvÿ±usÿ²uqÿ²uoÿ³tlÿ³tkÿ³ukÿ²ukÿ²ukÿ²tjÿ³thÿ³tgÿ³tfÿ³tfÿ²sgÿ²shÿ²siÿ±sjÿ±sjÿ±slÿ±smÿ°smÿ°snÿ°soÿ¯sqÿ¯rrÿ¯rsÿ®rtÿ®ruÿ®ruÿ­qsÿ­qqÿ­qqÿ­qqÿ­prÿ­quÿ­rxÿ¬ryÿ¬ryÿ¬rxÿ¬qvÿ­psÿ­ppÿ­onÿ®olÿ­ojÿ®piÿ®ogÿ®ogÿ­ngÿ­ohÿ­ohÿ­nhÿ­ngÿ­mgÿ­ngÿ¬nfÿ¬ndÿ¬mdÿ¬mcÿ¬mcÿ¬mcÿ¬ndÿ¬neÿ¬ofÿ­phÿ­pjÿ­okÿ¬olÿ«nnÿ©npÿ§lpÿ¦kpÿ¦koÿ¥jnÿ¤ilÿ£hjÿ£glÿ£goÿ¢htÿ¢ixÿ¢jzÿ¡iyÿ¡iwÿ grÿ¡fmÿ¡eiÿ ceÿŸcdÿŸcfÿŸchÿŸdkÿŸemÿŸeoÿždpÿœcpÿ›cqÿšcrÿ™bsÿ˜bsÿ—bsÿ–buÿ•bwÿ”awÿ“awÿ’awÿ’`vÿ‘`wÿ‘`wÿ‘`xÿ‘`yÿ�`zÿ�`|ÿ�`{ÿ�_zÿ�_zÿ�`{ÿ�`|ÿ�`|ÿ�`}ÿ�`~ÿ�`€ÿ�`€ÿ�a€ÿ�aÿ�`|ÿ‘^uÿ’]mÿ’]jÿ“]kÿ’_qÿ’`wÿ’`|ÿ’`}ÿ’`~ÿ‘a}ÿ‘a|ÿ’`zÿ’_vÿ’_sÿ“^oÿ“\kÿ“\gÿ”[eÿ”[eÿ”[dÿ”Zbÿ”Zaÿ”Z`ÿ“Z^ÿ“Z]ÿ“Y[ÿ’XYÿ’X\ÿ‘Y_ÿ‘Y`ÿ�X_ÿ�W]ÿ�W\ÿ�W\ÿŽV[ÿŽVZÿŽV[ÿŽV]ÿŽV^ÿŽV_ÿ�V_ÿŒV_ÿ¢v™ÿ£wœÿ¢wœÿ¢wœÿ¢w›ÿ¢všÿ£v˜ÿ¤v˜ÿ¤w˜ÿ¤x˜ÿ¤w–ÿ¤v•ÿ¤v“ÿ¥v‘ÿ¥vŽÿ¦vŽÿ¥u�ÿ¥uŒÿ¦u‹ÿ¦uŠÿ¥u‹ÿ¦vŒÿ§vŒÿ©wŒÿ¬xŠÿ­x†ÿ®y„ÿ¯y…ÿ¯z…ÿ°yƒÿ°xÿ°x}ÿ°x}ÿ°x|ÿ°w|ÿ°x|ÿ¯x~ÿ¯x€ÿ°x�ÿ±x€ÿ±xÿ²y}ÿ²y|ÿ±y}ÿ±y~ÿ°zÿ¯y�ÿ¯yƒÿ®y†ÿ­zŠÿ­z�ÿ«{‘ÿª{•ÿ©z˜ÿ©z™ÿªz—ÿªy”ÿ«y’ÿ«y�ÿ«xŒÿ«x‹ÿ«xŠÿ«xŠÿ«wŠÿªwˆÿ«wˆÿ¬wˆÿ¬wˆÿ¬w‡ÿ­x†ÿ®x†ÿ®x„ÿ­w‚ÿ­v�ÿ­w‚ÿ­wƒÿ®wƒÿ®w‚ÿ®v€ÿ¯vÿ°v|ÿ°vzÿ±uyÿ±uvÿ²usÿ³vqÿ³uoÿ´umÿ³vkÿ³vkÿ²ukÿ³ujÿ³tiÿ³thÿ³tgÿ³tgÿ³thÿ³tiÿ³uiÿ²tiÿ³tiÿ³tjÿ²tkÿ²tkÿ²tkÿ±tlÿ±tmÿ±snÿ±soÿ°sqÿ°stÿ°rsÿ¯rrÿ®qqÿ®qqÿ®qsÿ­ruÿ­rxÿ­s|ÿ­s}ÿ¬s}ÿ¬s|ÿ­szÿ­rwÿ¬quÿ­prÿ­ppÿ­pnÿ®pmÿ®olÿ®njÿ­niÿ­oiÿ­oiÿ­nhÿ­nhÿ­nhÿ­nhÿ­ngÿ­nfÿ¬neÿ­mdÿ¬mdÿ¬meÿ¬meÿ¬neÿ¬nfÿ­ogÿ­oiÿ®pkÿ®plÿ¬okÿ©lkÿ§klÿ¦knÿ¦koÿ¦koÿ¤imÿ£hkÿ£gkÿ¢gmÿ£goÿ£hrÿ¢hsÿ¢hsÿ¢hrÿ¡goÿ¡ekÿ¡ehÿ deÿ cdÿŸcfÿžcgÿždiÿŸdkÿŸdmÿžclÿ�clÿœbnÿ›boÿ™boÿ™boÿ˜apÿ—aqÿ–brÿ–asÿ•atÿ”`tÿ“_tÿ’`uÿ‘`uÿ’`wÿ‘ayÿ�a{ÿ�`|ÿ�`{ÿ�_zÿ�`{ÿ�`|ÿ�`~ÿ�`ÿ�a€ÿ�`€ÿ�a�ÿ�a‚ÿ�a‚ÿ�a‚ÿ‘a€ÿ‘_yÿ’]oÿ“]lÿ“^mÿ“_rÿ“ayÿ’a}ÿ’bÿ’b€ÿ’aÿ“a|ÿ’axÿ“_uÿ“_rÿ“_pÿ”^nÿ”]kÿ”]hÿ”\gÿ”\eÿ”[bÿ”[aÿ”Z`ÿ”[_ÿ”Z]ÿ“YZÿ’XYÿ“XZÿ’X\ÿ‘X]ÿ�X]ÿ�W]ÿ�W\ÿ�V\ÿŽV[ÿŽV\ÿ�V]ÿŽV_ÿŽVaÿ�WaÿŒWaÿ‹Vaÿ¢w•ÿ¢x™ÿ£xœÿ£yœÿ£x›ÿ£wšÿ£v˜ÿ£w™ÿ£xšÿ¤yšÿ¥x™ÿ¤x˜ÿ¥x–ÿ¥w“ÿ¦w‘ÿ§w�ÿ§wŽÿ§v�ÿ§vŒÿ§vŒÿ¦u�ÿ§vŽÿ¨wŽÿªx�ÿ«yŽÿ®y‹ÿ¯yˆÿ¯y†ÿ¯z†ÿ°z…ÿ±y�ÿ°x~ÿ°x|ÿ±x|ÿ°w|ÿ°x}ÿ¯y~ÿ°xÿ°x€ÿ°y€ÿ±yÿ²z~ÿ²z|ÿ²z{ÿ²z|ÿ²y{ÿ±y|ÿ°y€ÿ°yƒÿ¯y†ÿ®y‰ÿ­zŒÿ¬{�ÿ«{“ÿ«{”ÿ¬{”ÿ¬z“ÿ«z‘ÿ¬z�ÿ¬zŽÿ¬y�ÿ¬yŒÿ¬y‹ÿ«y‹ÿ¬y‹ÿ¬xŠÿ¬x‰ÿ­x‰ÿ­xˆÿ­yˆÿ¯zˆÿ®y…ÿ®xƒÿ®w�ÿ®w‚ÿ®x„ÿ®x„ÿ®x„ÿ®w„ÿ¯xƒÿ¯w€ÿ°v~ÿ°v{ÿ±vyÿ²uvÿ²utÿ³vqÿ³voÿ´wmÿ³vkÿ³vkÿ³ukÿ³ujÿ³uiÿ³uiÿ´ujÿ³ujÿ³vjÿ³vjÿ³ujÿ´ujÿ´ukÿ´ujÿ³uiÿ³uhÿ²tiÿ²ukÿ²ulÿ²tmÿ²spÿ±srÿ±sqÿ±rpÿ°rpÿ¯rqÿ®rtÿ®swÿ®s{ÿ­t}ÿ­t~ÿ¬t~ÿ­s}ÿ­s{ÿ­rzÿ¬qxÿ¬quÿ­qsÿ­prÿ­pqÿ­opÿ­omÿ®nkÿ­ojÿ­ojÿ­oiÿ¬oiÿ­oiÿ­oiÿ­nhÿ­ogÿ­nfÿ¬mfÿ¬mfÿ¬lfÿ«lfÿ¬mfÿ¬nfÿ­ohÿ­pjÿ®qkÿ®pjÿ­oiÿªlhÿ¨kiÿ§klÿ§loÿ§lpÿ¦jnÿ£hkÿ¢gkÿ£gkÿ¢glÿ¢gmÿ¢gnÿ¢gnÿ¢gmÿ¡fkÿ¡fiÿ¡egÿ deÿ ddÿ cfÿŸdhÿždiÿždjÿžckÿ�cjÿœckÿ›blÿšbmÿšblÿ™bkÿ™akÿ˜alÿ–alÿ–aoÿ•`qÿ”`rÿ“_rÿ“`sÿ’`tÿ‘`vÿ‘axÿ‘azÿ‘a{ÿ�`{ÿ�`{ÿ�a|ÿ�a~ÿ�a€ÿ�a�ÿ�b�ÿ�b�ÿ�a‚ÿ�aƒÿŽb„ÿ�b…ÿ�b‚ÿ‘`{ÿ’^qÿ“]nÿ“^oÿ“_tÿ’`yÿ’a}ÿ“cÿ“c�ÿ”bÿ”ayÿ“`sÿ“`rÿ“_qÿ“_qÿ”_qÿ”^pÿ”^nÿ”^kÿ”\fÿ”[cÿ”\aÿ•[aÿ”[_ÿ”Z]ÿ”YZÿ“XZÿ“XZÿ’X\ÿ’X]ÿ‘X]ÿ�W]ÿ�W]ÿ�W\ÿ�W\ÿŽW]ÿŽW_ÿŽWaÿ�Wcÿ�Weÿ�WeÿŒVdÿ£v‘ÿ£w–ÿ£xšÿ¤x›ÿ¤xšÿ£x™ÿ£w˜ÿ£w™ÿ¢xšÿ£y›ÿ¤yœÿ¥yœÿ¥y›ÿ¥x˜ÿ¦y”ÿ¨x‘ÿ©x�ÿ¨x�ÿ¨x�ÿ©xŽÿ¨wŽÿ¨x�ÿ¨y‘ÿªy’ÿ«z’ÿ®{�ÿ¯{�ÿ¯{Šÿ¯{ˆÿ°{‡ÿ²{„ÿ±y€ÿ±y}ÿ±y}ÿ°x~ÿ¯xÿ¯yÿ°yÿ±x~ÿ°y~ÿ²zÿ²z~ÿ²z|ÿ²z{ÿ²yzÿ³yzÿ²z{ÿ±zÿ±z‚ÿ±z„ÿ°{†ÿ®z‰ÿ®{Œÿ®|Žÿ®}�ÿ®}‘ÿ®|‘ÿ­{‘ÿ­{�ÿ­{�ÿ®{�ÿ®{Žÿ®{Žÿ®{Žÿ®{�ÿ®zŒÿ®y‹ÿ®yŠÿ®yŠÿ¯zŠÿ¯z‰ÿ¯y‡ÿ¯x…ÿ¯x„ÿ¯x„ÿ¯y„ÿ¯y…ÿ¯y†ÿ¯y†ÿ®x„ÿ¯x‚ÿ¯w€ÿ°w~ÿ±w|ÿ±vyÿ±wwÿ²vuÿ³vsÿ³vpÿ³wnÿ´wlÿ´vlÿ³vkÿ³vkÿ´vlÿµvlÿ´vlÿ´vmÿ´vmÿ´wmÿ´wlÿ´vlÿ´vjÿ´viÿ´vhÿ´uhÿ´vjÿ³ulÿ³umÿ³upÿ³uqÿ²tpÿ±soÿ±spÿ±srÿ¯ssÿ¯tuÿ¯tyÿ¯u|ÿ®u}ÿ­t}ÿ­t}ÿ­t}ÿ­s|ÿ­szÿ­syÿ­rxÿ­qwÿ¬quÿ¬qtÿ¬prÿ­ooÿ­omÿ­olÿ­okÿ®okÿ­ojÿ­ojÿ­ojÿ­niÿ¬nhÿ¬nhÿ¬mhÿ«mhÿ¬mhÿ¬mhÿ­niÿ­oiÿ­pjÿ­ojÿ¬ohÿ¬ngÿ«lgÿ©khÿ¨ljÿ¨mmÿ§loÿ¦jnÿ¤ilÿ¢hkÿ¢glÿ¢gkÿ¢gkÿ¢fkÿ£gjÿ¢giÿ¢fiÿ¢fhÿ¢ffÿ¡eeÿ¡eeÿ¡efÿ dhÿŸdiÿžejÿžckÿ�cjÿœckÿ›clÿ›bkÿ›ajÿšajÿ™aiÿ˜ajÿ—`kÿ–`lÿ–aoÿ•aqÿ”`rÿ”`sÿ“`uÿ’avÿ’axÿ’azÿ‘a{ÿ’a|ÿ‘a|ÿ�a}ÿ�bÿ�a‚ÿ�b‚ÿ�b�ÿ�b�ÿ�bƒÿŽb…ÿŽb†ÿ�b‡ÿ�b„ÿ�`}ÿ‘_uÿ“_qÿ’_rÿ‘`wÿ’a{ÿ’a}ÿ“bÿ”bÿ”b{ÿ•auÿ”_oÿ”`pÿ“_qÿ“_rÿ“`tÿ”`uÿ”`sÿ”_oÿ”]iÿ”\eÿ•\dÿ•[cÿ”[`ÿ”Z^ÿ”Y\ÿ”Y\ÿ“X\ÿ“X]ÿ’X]ÿ‘X^ÿ�W^ÿ�X]ÿ�X^ÿŽX^ÿŽX_ÿŽXaÿ�Xcÿ�Xfÿ�Xgÿ�Wgÿ�Wgÿ¥u�ÿ¥v‘ÿ¥w–ÿ¥x˜ÿ¥x˜ÿ¤x—ÿ¤x˜ÿ¤x™ÿ£xšÿ£x›ÿ¤y�ÿ¥z ÿ¥zŸÿ¦zœÿ¦y—ÿ¨y”ÿ©y’ÿªy�ÿªy�ÿªy�ÿªz‘ÿªz“ÿª{•ÿ«{–ÿ¬|–ÿ­}•ÿ¯}“ÿ¯}�ÿ°~�ÿ±}‹ÿ²|‡ÿ²{‚ÿ±y€ÿ±y€ÿ±y�ÿ°y‚ÿ°y�ÿ°y€ÿ±y}ÿ²z}ÿ²z}ÿ²z}ÿ²z|ÿ²z{ÿ³y{ÿ²z{ÿ³z|ÿ³z~ÿ²z�ÿ²{„ÿ²|†ÿ°{ˆÿ°|Šÿ°}Œÿ°}Žÿ°}�ÿ°}�ÿ¯}�ÿ¯|�ÿ¯|�ÿ¯|�ÿ®|�ÿ®|�ÿ®|�ÿ¯|�ÿ¯{�ÿ¯{�ÿ¯{Žÿ¯{�ÿ¯{Œÿ°zŠÿ¯zˆÿ¯y†ÿ¯y†ÿ°y†ÿ¯z‡ÿ°zˆÿ°z‰ÿ°z‰ÿ°y‡ÿ°y„ÿ°x‚ÿ°w€ÿ°w~ÿ±w|ÿ²x{ÿ²xyÿ²wwÿ³wsÿ³wqÿ´wnÿ´vnÿ´vmÿ´vmÿ´wmÿµwnÿµwnÿµwnÿµwnÿµwnÿµwmÿ´vlÿ´vkÿµwjÿµviÿµviÿ´ukÿ´umÿ´uoÿ´uqÿ´urÿ´urÿ´trÿ³trÿ³tsÿ±ttÿ°tuÿ°uxÿ°v{ÿ¯u}ÿ®t~ÿ­t}ÿ­t}ÿ­u~ÿ­t}ÿ¬t}ÿ­s~ÿ­s}ÿ¬s|ÿ¬rzÿ¬qxÿ­puÿ®prÿ­ppÿ­pnÿ®omÿ­omÿ­olÿ­okÿ­olÿ­nkÿ¬nkÿ¬nkÿ¬nkÿ¬nkÿ¬nlÿ­omÿ­omÿ­omÿ­okÿ¬niÿ«mhÿ«lhÿªliÿ©mjÿ¨llÿ§lnÿ¦jnÿ¤hmÿ£glÿ¢hlÿ¢hlÿ¢gkÿ¢gjÿ¢giÿ£fhÿ£ghÿ£fgÿ¢efÿ¡deÿ¢efÿ¡fhÿ¡eiÿ ekÿŸdkÿŸdlÿždkÿ�clÿ›clÿ›clÿ›bkÿšakÿ™akÿ™akÿ˜alÿ—anÿ—apÿ–arÿ•asÿ”`sÿ”atÿ“avÿ“axÿ’azÿ’a{ÿ’a|ÿ’a|ÿ’a|ÿ‘a~ÿ‘a€ÿ�a€ÿ�a~ÿ�bÿŽb‚ÿŽb†ÿŽb‡ÿ�b‡ÿ�b…ÿ‘aÿ‘`xÿ’`vÿ’`wÿ’azÿ’a|ÿ’a}ÿ“b}ÿ•a{ÿ•`wÿ•`sÿ•`pÿ•`qÿ”`rÿ”`tÿ“awÿ“axÿ“awÿ”`sÿ”^mÿ•\hÿ”\fÿ”\dÿ”[aÿ”Z_ÿ”Z^ÿ”Z^ÿ”Y^ÿ“Y_ÿ“Y_ÿ’Y_ÿ‘X`ÿ‘X_ÿ�X_ÿ�X_ÿŽX`ÿŽXbÿŽYeÿ�Yhÿ�Xiÿ�Xiÿ�Xhÿ§uŠÿ§u�ÿ§v‘ÿ¦x•ÿ¥x–ÿ¥x–ÿ¥y—ÿ¥y—ÿ¤x˜ÿ¤yšÿ¤y�ÿ¥z ÿ¦{¡ÿ¦{žÿ¦z™ÿ¨z—ÿ©z•ÿª{“ÿ«{’ÿ«{“ÿ«{”ÿ«|–ÿ«}˜ÿ«}›ÿ¬}›ÿ¬~›ÿ­~˜ÿ¯•ÿ°’ÿ±~Žÿ±}‰ÿ±{†ÿ±z„ÿ±{„ÿ°{…ÿ°{…ÿ°z„ÿ°z‚ÿ±zÿ²z}ÿ²z|ÿ³z}ÿ³{}ÿ³z}ÿ²z|ÿ³z|ÿ³z}ÿ´z~ÿ´{€ÿ³{‚ÿ³|…ÿ²|ˆÿ²}Šÿ±}Œÿ±}�ÿ±}�ÿ±~Žÿ²}Žÿ±}�ÿ±}�ÿ°}Žÿ¯}�ÿ¯}‘ÿ¯}’ÿ¯}“ÿ¯}“ÿ¯}“ÿ¯}“ÿ°}‘ÿ°|�ÿ°|�ÿ°{‹ÿ°{Šÿ¯{‹ÿ°z‹ÿ°z‹ÿ±{‹ÿ±z‹ÿ±zŠÿ±z‰ÿ±z‡ÿ±y…ÿ±xƒÿ±x�ÿ²x€ÿ²xÿ²y}ÿ²xzÿ³wwÿ´wtÿ´wrÿ´wqÿ´wqÿµxpÿµwpÿµwpÿµwqÿµxqÿµxpÿµwpÿµwoÿµwmÿµvlÿµvlÿµvkÿµvkÿµvlÿµvoÿµvqÿµvsÿµvtÿ´utÿ´uuÿ´utÿ³utÿ²utÿ±tuÿ±uwÿ±u{ÿ°u}ÿ°u~ÿ®t~ÿ®uÿ®u€ÿ­u�ÿ­u‚ÿ¬uƒÿ¬u„ÿ¬u„ÿ¬t‚ÿ¬sÿ¬r|ÿ­qxÿ¬quÿ­qsÿ­prÿ­pqÿ¬ppÿ­poÿ­ooÿ­onÿ¬ooÿ¬ooÿ¬ooÿ¬opÿ¬opÿ¬orÿ¬orÿ¬oqÿ¬onÿ«nkÿªmkÿªljÿªmjÿ©mkÿ©lmÿ§knÿ¥joÿ¤ioÿ£ioÿ£inÿ¢hlÿ¢glÿ¢gjÿ¢giÿ¢ghÿ£ghÿ£fgÿ¢efÿ¢eeÿ¢egÿ¡fiÿ¡fkÿ¡elÿ dlÿŸdlÿždlÿ�clÿœcmÿ›cmÿ›cnÿšbnÿšbmÿ™bnÿ˜bpÿ—bqÿ–arÿ–asÿ•asÿ•`rÿ”asÿ“atÿ“avÿ’axÿ’azÿ’azÿ’azÿ’azÿ’a{ÿ‘a|ÿ‘a{ÿ�`zÿ�a}ÿ�b�ÿ�b…ÿŽb†ÿ�b„ÿ�a‚ÿ‘a€ÿ‘a|ÿ’a{ÿ’a|ÿ’b}ÿ“b}ÿ“b}ÿ“a|ÿ•axÿ–`uÿ•`rÿ•`qÿ•`rÿ”`uÿ”axÿ”b{ÿ“a|ÿ“azÿ”`uÿ”^pÿ”^mÿ”]kÿ”]hÿ”\eÿ”[cÿ”[bÿ”[aÿ“[`ÿ“Zaÿ’Zaÿ’Y`ÿ‘Yaÿ�Yaÿ�Xaÿ�Xaÿ�Xaÿ�YbÿŽYeÿ�YhÿŒXiÿŒXjÿŒXiÿ©vˆÿ¨uŠÿ¨vŽÿ§x’ÿ¦x”ÿ¦y•ÿ¦y–ÿ¦y–ÿ¥y—ÿ¥z™ÿ¥z›ÿ¥{žÿ¥{Ÿÿ¦{žÿ¦{œÿ§{™ÿ¨{—ÿ©{•ÿª|”ÿ«|•ÿ«|•ÿ«}—ÿ«~›ÿ«Ÿÿ« ÿ« ÿ¬žÿ­€›ÿ®˜ÿ°’ÿ°}Œÿ°|‰ÿ°|‰ÿ°|Šÿ°|Šÿ¯|‰ÿ°{‡ÿ°z„ÿ±z‚ÿ±zÿ²z~ÿ³{}ÿ³{}ÿ³{}ÿ²z}ÿ³z~ÿ²{~ÿ´|€ÿµ|€ÿ´|�ÿ´|ƒÿ³|†ÿ³}Šÿ³~�ÿ²~�ÿ²~�ÿ³~�ÿ³~Œÿ³}‹ÿ²}Šÿ²~‹ÿ±~�ÿ±~�ÿ°~’ÿ°~”ÿ¯~”ÿ¯~”ÿ°~•ÿ±~•ÿ±~“ÿ°~�ÿ±}�ÿ°|Žÿ°|�ÿ¯|�ÿ°{Žÿ°{Žÿ±{Œÿ±{‹ÿ±{Šÿ±{‰ÿ±{ˆÿ±z‡ÿ²z…ÿ²z„ÿ²zƒÿ³z�ÿ³y~ÿ³x{ÿ³wwÿ´wvÿ´xuÿ´ytÿµysÿµxrÿ¶xrÿµxrÿ¶yrÿ¶yrÿµxqÿµwoÿµwnÿµwnÿµwnÿµwnÿµwnÿ¶woÿµwqÿµwsÿ´wuÿµvvÿ´wwÿ³vwÿ³vvÿ³uuÿ³usÿ²utÿ²uvÿ²vyÿ±u{ÿ°u}ÿ°uÿ¯v€ÿ¯v‚ÿ®v„ÿ­w†ÿ­wˆÿ¬v‰ÿ¬vŠÿ«u‰ÿ«t†ÿ«tƒÿ«sÿ¬r|ÿ¬ryÿ¬qwÿ¬qwÿ¬qvÿ¬qvÿ¬qtÿ¬ptÿ¬ptÿ«ptÿ«ptÿ¬puÿ«pvÿ«pvÿ«pwÿ«puÿ«prÿªooÿªnmÿªmmÿ©mmÿ¨mmÿ©lnÿ¨loÿ¦koÿ¤jpÿ¤jqÿ¤joÿ£imÿ¢hlÿ¢gkÿ¡fjÿ¢giÿ¢giÿ¢fhÿ¢egÿ¡egÿ¡fiÿ¡fkÿ¡flÿ flÿ emÿŸemÿždmÿ�dmÿœcnÿ›cpÿšcpÿšcpÿ™cpÿ™cqÿ—bsÿ–btÿ•btÿ•atÿ•arÿ•`qÿ•arÿ”`sÿ“`tÿ’auÿ’awÿ‘axÿ‘`vÿ‘`vÿ‘awÿ’`wÿ‘`vÿ�_vÿ�`zÿ�b€ÿ�b‚ÿ�b‚ÿ�a€ÿ�aÿ‘aÿ‘aÿ’a~ÿ’b~ÿ’b}ÿ“b}ÿ“b}ÿ”azÿ•awÿ–auÿ–`sÿ•`sÿ”`uÿ”ayÿ”b}ÿ”c€ÿ”bÿ”a|ÿ”`wÿ”`tÿ”_rÿ”_pÿ•^nÿ”]kÿ”]iÿ”\hÿ”[eÿ’[cÿ’[cÿ’[cÿ’Zbÿ‘Ybÿ�Ybÿ�Ycÿ�Ybÿ�Ybÿ�Ycÿ�YdÿŽYgÿŒYiÿŒXjÿŒXkÿªv‡ÿ©vˆÿ©wŒÿ¨x�ÿ§y‘ÿ§z”ÿ§z–ÿ¦z–ÿ¥z—ÿ¦{˜ÿ¦{šÿ¥{›ÿ¥{œÿ¥{�ÿ¦z�ÿ§{›ÿ§z™ÿ¨{—ÿª|–ÿ«|–ÿ¬}–ÿ¬~—ÿ¬œÿ¬€¡ÿ«�£ÿª€£ÿ«�£ÿ«�£ÿ¬€Ÿÿ®˜ÿ®}�ÿ¯}Žÿ¯}�ÿ¯}‘ÿ¯}�ÿ¯}�ÿ±}‰ÿ±|†ÿ²{„ÿ²|‚ÿ²{€ÿ³{ÿ³{~ÿ³{~ÿ³{~ÿ³{ÿ³{ÿ´|€ÿµ|€ÿµ}€ÿµ}�ÿ´}„ÿ´~‰ÿ´Žÿ³�ÿ³�ÿ³~Œÿ³~Šÿ³~‰ÿ³~‡ÿ´}‡ÿ³~‰ÿ²~‹ÿ²~�ÿ²’ÿ±”ÿ°~“ÿ±~“ÿ²•ÿ±€”ÿ±’ÿ±~‘ÿ°~�ÿ°}�ÿ°}‘ÿ°|‘ÿ°|�ÿ°|�ÿ°|�ÿ²|Œÿ²|Œÿ²|‹ÿ²{Šÿ²{Šÿ²{‰ÿ±{ˆÿ²{†ÿ³zƒÿ³xÿ³x{ÿ´xyÿ´ywÿ´yuÿ´xtÿµxsÿµysÿ¶ysÿ¶ysÿ¶ysÿ¶xrÿµxpÿµxpÿµxqÿ¶xqÿ¶xqÿ¶xrÿ¶ysÿ¶xtÿµwuÿµwvÿ´wwÿ´xxÿ´xxÿ´wxÿµwvÿ´utÿ³vsÿ´vsÿ³wuÿ²vxÿ±v|ÿ±v}ÿ±v~ÿ°v€ÿ¯w„ÿ®w‡ÿ®xŠÿ¬w‹ÿ¬wŒÿ¬w‹ÿ«u‰ÿ«t‡ÿ«t„ÿ¬s�ÿ¬r~ÿ¬r|ÿ¬r|ÿ¬r}ÿ«r}ÿªr|ÿ«r{ÿ¬r{ÿ¬r{ÿ«r{ÿ¬q|ÿ¬q|ÿ«q{ÿ«q{ÿ«qyÿ¬pvÿªprÿªoqÿ«oqÿªnqÿ©opÿ¨mpÿ§lqÿ§lqÿ¥lqÿ¤kqÿ¤jpÿ£inÿ¢hmÿ¡hmÿ gmÿ¡gkÿ¢gkÿ¢gjÿ¡fjÿ ejÿ¡fkÿ¡flÿ¡flÿ fnÿŸgoÿŸfoÿženÿžeoÿ�dpÿœdqÿ›dqÿšcrÿ™csÿ˜dtÿ—cuÿ–bvÿ–bvÿ–btÿ•arÿ–aqÿ•`qÿ”`rÿ”`rÿ“`sÿ’`tÿ’`uÿ‘_tÿ‘_tÿ‘`sÿ’_rÿ’_rÿ‘_sÿ‘`wÿ�b|ÿ�b~ÿ�a~ÿ‘a}ÿ‘a~ÿ‘b€ÿ’b€ÿ’bÿ‘bÿ’b~ÿ“b~ÿ“b~ÿ•b{ÿ–byÿ–axÿ–avÿ•avÿ•ayÿ”c~ÿ•d‚ÿ•d‚ÿ”c€ÿ”b}ÿ•azÿ•axÿ•awÿ•avÿ•_sÿ”_qÿ•_pÿ•]mÿ”\hÿ’[fÿ’[eÿ’[eÿ’[eÿ’Zdÿ�Zdÿ‘Zdÿ‘Zcÿ�Zcÿ�Zcÿ�YdÿŽYfÿŽYhÿ�Yjÿ�Ylÿ©v‡ÿªw‡ÿ©wŠÿ©xŽÿ¨y�ÿ¨y“ÿ§z•ÿ§z–ÿ¦z–ÿ¦z—ÿ¦{˜ÿ¦{™ÿ¦{›ÿ¦z�ÿ¥{žÿ¦z�ÿ¦z›ÿ¨{šÿ©|™ÿª|˜ÿ¬~—ÿ­~˜ÿ®œÿ­�Ÿÿ¬�¢ÿ¬‚¤ÿ¬‚¦ÿ¬�¦ÿ¬�¤ÿ­€�ÿ®~—ÿ®~”ÿ®—ÿ¯€™ÿ°€˜ÿ±“ÿ²~Œÿ²}‡ÿ³|„ÿ³|ƒÿ´|‚ÿ´}€ÿ´|ÿ´|ÿ´}ÿ³|~ÿ´|ÿµ}ÿ¶}ÿµ|ÿµ~€ÿµ~ƒÿµˆÿµ€�ÿµ��ÿµ€Žÿ´Œÿ´‹ÿµ€Šÿ´ˆÿ´}†ÿ´~†ÿ´~‡ÿ´‰ÿ´�ÿ´€�ÿ³�ÿ³�ÿ³’ÿ³“ÿ³€“ÿ³‘ÿ³�ÿ³~�ÿ²~�ÿ±}�ÿ°|�ÿ°|�ÿ°|�ÿ°}�ÿ±|�ÿ±}�ÿ±}�ÿ±}�ÿ²}Žÿ²|�ÿ³|Œÿ³{ˆÿ³z„ÿ´z€ÿ³x|ÿ´yyÿ´yxÿ´xvÿµxuÿµzuÿ¶zuÿ¶yuÿ¶yuÿ¶xtÿ¶ytÿ¶xtÿµxtÿµxtÿ¶xuÿµxvÿ¶yvÿ¶ywÿ¶xwÿµxxÿ´xyÿµyzÿµxzÿµwyÿµwwÿµvuÿµwuÿ´wtÿ³vuÿ³vwÿ²wzÿ²v{ÿ²v|ÿ±vÿ±w„ÿ¯x‡ÿ¯x‹ÿ®x�ÿ­x�ÿ­w‹ÿ­v‰ÿ¬uˆÿ«t†ÿ¬t‚ÿ¬s€ÿ¬sÿ¬sÿ«s€ÿªt�ÿ«t�ÿªs€ÿ«s�ÿ«s�ÿ¬s€ÿ«s€ÿ«s�ÿ¬s�ÿ«s€ÿ«r}ÿ¬rzÿ«qvÿ«quÿ«puÿ«puÿªotÿ¨osÿ§mrÿ§lqÿ¦lrÿ¥krÿ¥lrÿ¤jqÿ¢hqÿ¡hrÿ¡irÿ hpÿ¡hpÿ¢gnÿ¢gnÿ¡fmÿ¡fmÿ¡flÿ fmÿ foÿ gqÿŸfqÿŸfqÿžepÿ�dpÿœdqÿ›cqÿšcrÿ™ctÿ˜cuÿ—cvÿ—cxÿ—cwÿ–buÿ•bsÿ•arÿ•`qÿ”`qÿ”`rÿ”`rÿ“`rÿ“`sÿ’_sÿ’_sÿ’_rÿ’^pÿ’^pÿ’_qÿ’`tÿ‘awÿ�azÿ‘a{ÿ‘a|ÿ‘bÿ‘b�ÿ’c‚ÿ“c‚ÿ’b€ÿ’bÿ“c€ÿ“c€ÿ”b~ÿ•b|ÿ–b{ÿ–azÿ–b{ÿ•c~ÿ•dƒÿ•d…ÿ•dƒÿ”c€ÿ”b~ÿ•b}ÿ•b|ÿ•b{ÿ•byÿ•`xÿ•`vÿ•_tÿ”^qÿ“]lÿ’]jÿ‘\iÿ‘[iÿ‘[hÿ‘[hÿ‘[gÿ�Zeÿ‘Ydÿ‘Ydÿ‘Zdÿ�Ydÿ�ZfÿŽYhÿŽYjÿ�Ykÿ¨xŒÿ©wŠÿ©wŠÿ¨xŒÿ¨x�ÿ§y’ÿ§y”ÿ§y•ÿ¦y•ÿ¦y–ÿ§z—ÿ¦z˜ÿ¦z™ÿ¦{œÿ¦{žÿ¥{žÿ¥z�ÿ¦{œÿ¨|œÿ¨|šÿª}˜ÿ¬~™ÿ­›ÿ­�žÿ­�¡ÿ¬�£ÿ¬�¤ÿ«�¥ÿ«�¥ÿ¬€¡ÿ­›ÿ®˜ÿ®™ÿ¯€œÿ¯�œÿ±�šÿ²€“ÿ³~Œÿ³}‡ÿ´}…ÿµ}„ÿµ~ƒÿµ~�ÿµ}€ÿµ}ÿµ}}ÿ¶}}ÿ¶}}ÿ¶}}ÿ¶}~ÿµ}ÿµ}�ÿµ~†ÿµ€‹ÿµ€�ÿµ€�ÿµ€Œÿµ€Œÿ¶�‹ÿ¶€‰ÿ¶‡ÿ¶…ÿ¶„ÿ¶†ÿ¶‰ÿµ€‹ÿµ€Œÿ´�ÿ´Žÿ´€�ÿ´€‘ÿ´€‘ÿ´€�ÿ´Žÿ´~�ÿ³~Œÿ²}�ÿ±}‘ÿ±}’ÿ°~’ÿ°}’ÿ°}“ÿ°~”ÿ°~–ÿ±~•ÿ±~“ÿ²}‘ÿ²}Žÿ³|‰ÿ³{ƒÿ³zÿ´y}ÿ´y{ÿ³yzÿ´yyÿ´yyÿµzyÿµzyÿµyxÿµyxÿµyxÿµyxÿµyyÿµyyÿµyzÿµyzÿµzzÿµyzÿµyyÿµyyÿµyzÿµy{ÿµy{ÿµxzÿµwxÿµwwÿµwvÿµwvÿ´wvÿ´wxÿ³wyÿ²w{ÿ²w}ÿ²w€ÿ²xƒÿ±x‡ÿ°x‹ÿ¯xŒÿ¯x‹ÿ®wŠÿ®wˆÿ­v†ÿ­u„ÿ­t�ÿ­t€ÿ¬t€ÿ¬t�ÿ«tƒÿ«tƒÿªtƒÿ«sƒÿªsƒÿ«s„ÿ«t„ÿ«t„ÿ¬t„ÿ«tƒÿ«s�ÿ«sÿ«r{ÿ¬qxÿ¬rwÿ¬qxÿ«pxÿªpwÿ©ovÿ¨ntÿ§msÿ§msÿ¦lsÿ¥lsÿ¤ksÿ£jtÿ¢jtÿ¡itÿ htÿ htÿ¡isÿ hrÿ gqÿ goÿ fnÿ foÿ gqÿŸgsÿŸguÿŸgtÿžfsÿžerÿ�erÿ›drÿšcsÿšctÿ™cvÿ˜dxÿ—dzÿ—cyÿ–cwÿ•buÿ”bsÿ•arÿ”`qÿ”`pÿ”`pÿ”`pÿ”`qÿ“`sÿ’`sÿ‘`sÿ‘_rÿ‘_qÿ’`qÿ’`rÿ’`uÿ‘`wÿ‘`zÿ‘a}ÿ‘b€ÿ’cƒÿ’c„ÿ’cƒÿ’b‚ÿ’b‚ÿ“cƒÿ”d‚ÿ”c€ÿ”cÿ•cÿ•cÿ•d€ÿ–d‚ÿ•e†ÿ•e†ÿ”dƒÿ•d€ÿ•cÿ•cÿ•cÿ”c~ÿ”b|ÿ”azÿ”ayÿ”`xÿ”`uÿ“_rÿ’]oÿ‘]nÿ‘\mÿ‘\lÿ‘\kÿ‘\jÿ‘Zgÿ‘Zeÿ‘Zdÿ‘Zeÿ‘Zfÿ�Zgÿ�ZiÿŽZkÿŽZlÿ¨z“ÿ©y�ÿ©xŒÿ©x‹ÿ¨y�ÿ¨y�ÿ¨y“ÿ§y”ÿ¦y•ÿ¦y–ÿ¦z—ÿ¦z˜ÿ¦z™ÿ¦{œÿ§|Ÿÿ¦|Ÿÿ¥{žÿ¥zžÿ¦{�ÿ§|›ÿ©|™ÿª}™ÿ¬›ÿ­€�ÿ­�žÿ­�Ÿÿ¬€¡ÿ«�¢ÿ«�£ÿ«€¡ÿ«œÿ­šÿ®™ÿ®�›ÿ¯‚žÿ°‚Ÿÿ±‚›ÿ²€“ÿ³Œÿ´~‰ÿ´‡ÿµ†ÿµƒÿµ~�ÿ¶~€ÿ¶}ÿ¶~}ÿ¶}|ÿ·}}ÿ·}}ÿµ}~ÿµ}ÿµ~ƒÿ¶ˆÿ¶€‹ÿ¶�Œÿ·��ÿ·��ÿ·‚�ÿ¸‚‹ÿ¸�‰ÿ·€†ÿ·„ÿ¸†ÿ·€ˆÿ·€‰ÿ¶€‰ÿ¶€‹ÿ¶€�ÿµ�Žÿµ��ÿµ‚’ÿµ�‘ÿµŒÿµ‰ÿµ~Šÿ´~�ÿ³~�ÿ²’ÿ±“ÿ°~’ÿ°~“ÿ°—ÿ°€›ÿ°�œÿ°€šÿ°˜ÿ°•ÿ±}�ÿ²{ˆÿ²{„ÿ³z‚ÿ³z€ÿ³zÿ³y~ÿ³y~ÿ´y~ÿ´y~ÿ´z~ÿ´z~ÿ´z~ÿµz~ÿµzÿµ{€ÿµ{€ÿµ{€ÿµz€ÿ´z~ÿµz}ÿµz}ÿµz}ÿµz~ÿµz~ÿµy|ÿµxzÿµxyÿ´wxÿµwxÿµwxÿ´wxÿ³xyÿ³x|ÿ²xÿ²y�ÿ±y„ÿ±y‡ÿ±yŠÿ°y‹ÿ°xŠÿ¯wˆÿ¯w‡ÿ¯vƒÿ¯v€ÿ¯u~ÿ®t~ÿ¬tÿ¬t�ÿ«t„ÿ«u„ÿ«t„ÿ«t„ÿ«s„ÿ«s…ÿ«t…ÿ«t„ÿ¬t‚ÿ«t�ÿ«t€ÿ«s~ÿ«r{ÿ¬qxÿ¬qxÿ¬qyÿ«pxÿªpwÿ¨ouÿ¨ouÿ§nuÿ¦mtÿ¦ltÿ¥ltÿ¤ktÿ¤ktÿ¢jtÿ¡itÿ iuÿŸivÿ jwÿ ivÿŸhtÿŸgrÿŸgqÿ gqÿŸgrÿŸguÿžgvÿŸguÿžgtÿžfsÿ�fsÿœerÿšdrÿ™dtÿ™dvÿ˜dxÿ—dzÿ—dzÿ—dyÿ–cvÿ•buÿ•btÿ•arÿ•`qÿ•`qÿ”`qÿ”`rÿ’`tÿ’`uÿ‘awÿ‘awÿ‘`tÿ‘`rÿ’`rÿ“`tÿ’awÿ’azÿ’b~ÿ“c�ÿ’dƒÿ’dƒÿ’dƒÿ’c‚ÿ’c„ÿ“d†ÿ”e„ÿ•e�ÿ•e‚ÿ•eƒÿ•e„ÿ•eƒÿ•e„ÿ–e…ÿ•e…ÿ•e„ÿ•d�ÿ•d€ÿ•c€ÿ”c€ÿ”cÿ•c~ÿ”b{ÿ”ayÿ”ayÿ”`xÿ“`wÿ’^tÿ‘^rÿ‘]pÿ‘]oÿ‘]nÿ’\lÿ’[hÿ‘Zfÿ‘[fÿ‘[gÿ‘[gÿ�[gÿ�[iÿ�[jÿ�[kÿ¨{™ÿ¨{–ÿ©z‘ÿ©yŒÿ©yŒÿ©yŽÿ©y‘ÿ¨y”ÿ§y•ÿ¦y–ÿ¥z—ÿ¥z˜ÿ¦zšÿ¦{œÿ§|Ÿÿ¦}Ÿÿ¥|Ÿÿ¤{Ÿÿ¥{žÿ¦}œÿ¨|šÿ©|™ÿ«~šÿ¬€œÿ¬�œÿ®�œÿ­��ÿ­�žÿ¬�Ÿÿ«€žÿ«œÿ¬~šÿ­™ÿ®€šÿ¯‚žÿ°ƒ ÿ°ƒ ÿ±‚šÿ²�“ÿ³€Žÿ´€Œÿ´‰ÿ´‡ÿ´…ÿ¶ƒÿ¶~�ÿ¶~ÿ¶}~ÿ·}~ÿ¶}~ÿ¶}~ÿ¶~~ÿ·~‚ÿ·€‡ÿ·�‹ÿ¸‚�ÿ¹ƒ�ÿ¹ƒ�ÿ¹ƒ�ÿ¹ƒŽÿ¸‚Œÿ¸�‰ÿ¸�‡ÿ¸�ˆÿ¸�ˆÿ·€ˆÿ·€ˆÿ·�Šÿ·��ÿ·�Žÿ¶‚�ÿ¶ƒ“ÿ¶ƒ’ÿ¶�Œÿ¶†ÿ¶‡ÿµŠÿ´€�ÿ³€�ÿ³€’ÿ³€’ÿ±“ÿ±˜ÿ±��ÿ°‚ ÿ¯�Ÿÿ¯��ÿ¯€™ÿ°~”ÿ±}Œÿ²{‰ÿ²{†ÿ²z„ÿ²zƒÿ³zƒÿ³z‚ÿ³y‚ÿ³zƒÿ³{„ÿ´{…ÿ´{…ÿ´{…ÿ´{†ÿ´|†ÿ´|‡ÿ´{‡ÿ´{†ÿ´{„ÿ´{ƒÿ´{‚ÿµz‚ÿµ{‚ÿµ{�ÿµ{ÿ¶y}ÿµy}ÿ´x{ÿ´xzÿ´wyÿµwyÿ³xzÿ³x~ÿ³y�ÿ²yƒÿ±y…ÿ±yˆÿ±zŠÿ±z‹ÿ°yŠÿ°x‡ÿ°w…ÿ°v€ÿ°u|ÿ°tzÿ¯tzÿ­s|ÿ­tÿ¬tƒÿ«u„ÿ«u…ÿ¬u„ÿ«t…ÿ«t…ÿ«t„ÿ«t�ÿ¬tÿ¬sÿ¬sÿ¬s}ÿ¬qyÿ«qxÿ«qyÿ«qyÿ«pwÿ©ouÿ¨nsÿ¨ntÿ§ntÿ§mtÿ¦ltÿ¦ltÿ¥ktÿ¤ktÿ£jsÿ¢isÿ iuÿ jwÿ jxÿ ixÿŸiwÿŸhtÿŸhsÿŸgrÿŸgsÿžhuÿžhvÿžguÿžgtÿžgsÿžfsÿœerÿ›erÿšesÿšeuÿ™dwÿ˜dyÿ˜ezÿ˜ezÿ—dxÿ–cvÿ–buÿ•btÿ•asÿ•asÿ”atÿ“auÿ“awÿ’ayÿ’c{ÿ’c|ÿ’bxÿ‘atÿ’asÿ“auÿ“bxÿ“c|ÿ”d€ÿ”d‚ÿ“dƒÿ“eƒÿ“d‚ÿ“c‚ÿ“d„ÿ”e…ÿ•eƒÿ•e�ÿ–fƒÿ–f…ÿ–e…ÿ•e„ÿ•e…ÿ–e…ÿ–e…ÿ•e…ÿ–e„ÿ•d‚ÿ•d‚ÿ”d‚ÿ•c�ÿ•c~ÿ”b{ÿ”axÿ”`xÿ“`yÿ’`yÿ’_wÿ’^tÿ’]rÿ‘]pÿ’^pÿ“]mÿ’\jÿ’[hÿ’[hÿ’\hÿ’\gÿ‘[fÿ�\hÿ�\iÿ�[iÿ§|žÿ¨}žÿ¨|™ÿ©{‘ÿ©y�ÿ©yŽÿ©y‘ÿ¨z”ÿ§z–ÿ¦z—ÿ¦z™ÿ¦{šÿ¦{›ÿ¦{œÿ¦{žÿ¦| ÿ¦| ÿ¥| ÿ¥|Ÿÿ¦}žÿ§}œÿ©|šÿª}™ÿ«šÿ¬€›ÿ®�šÿ¯�šÿ¯�šÿ®�šÿ­€™ÿ­™ÿ¬~™ÿ­˜ÿ®€™ÿ¯�œÿ°ƒžÿ°„ ÿ±„Ÿÿ±‚›ÿ²�”ÿ³€‘ÿ´€Žÿ´Œÿ´€‰ÿµ€†ÿµ…ÿ¶ƒÿ·~�ÿ·~ÿ¶~ÿ·ÿ¸ÿ¸€‚ÿ¸�‡ÿ¸‚‹ÿ¹„�ÿ¹„‘ÿ¹„’ÿ¹„’ÿ¹ƒ‘ÿ¹ƒ�ÿ¹ƒŒÿ¹‚Šÿ¹‚Šÿ¹‚Šÿ¸�‰ÿ¸�Šÿ¸‚‹ÿ¸‚�ÿ¸‚�ÿ·‚‘ÿ·„”ÿ·„”ÿ¸‚�ÿ·€‡ÿ·…ÿ·†ÿ¶€‰ÿµ€�ÿµ��ÿ´�‘ÿ³€”ÿ³�˜ÿ²‚�ÿ±‚ ÿ°‚Ÿÿ°�žÿ°€›ÿ±–ÿ²~�ÿ³|Œÿ²|‰ÿ²{†ÿ³{†ÿ²{†ÿ³z†ÿ³z†ÿ³{‡ÿ²|‰ÿ³|‹ÿ³|‹ÿ²{Šÿ³|‹ÿ³|‹ÿ³|Œÿ³|Œÿ³|Œÿ³|Šÿ³{ˆÿ³|‡ÿµ{‡ÿµ|†ÿµ{…ÿµ{ƒÿµz�ÿ¶z�ÿµyÿµy}ÿ´xzÿµxzÿ³x{ÿ³yÿ³z‚ÿ³y…ÿ²y‡ÿ±zŠÿ²{Šÿ²zŠÿ±zˆÿ°y†ÿ±xƒÿ±vÿ±u{ÿ±txÿ°sxÿ¯tzÿ®t}ÿ­t€ÿ«tƒÿ«u†ÿ¬u…ÿ«u…ÿ¬u„ÿ¬u‚ÿ«t~ÿ¬s}ÿ­s}ÿ­r|ÿ¬rzÿ«qxÿ«qyÿ¬r{ÿ«qyÿªpuÿ©orÿ¨npÿ¨nqÿ¨nrÿ¨mrÿ§msÿ§ltÿ¦luÿ¥lsÿ¤krÿ£jrÿ¡juÿ¡jwÿ iwÿ iwÿ ivÿŸhtÿ hrÿ gqÿ grÿŸhtÿžhuÿžgsÿžfrÿžgqÿžfqÿœeqÿ›dqÿ›drÿšetÿševÿ™eyÿ˜ezÿ˜ezÿ˜eyÿ—dwÿ–cuÿ•btÿ•atÿ”auÿ“avÿ”bxÿ”bzÿ“c}ÿ’c~ÿ“c~ÿ’bzÿ’avÿ’avÿ“bxÿ“c{ÿ”dÿ”d�ÿ”d‚ÿ”dƒÿ”d‚ÿ”d�ÿ•c�ÿ•d‚ÿ–dƒÿ•d‚ÿ–e�ÿ—fƒÿ—f„ÿ–f„ÿ•e„ÿ–e†ÿ–e†ÿ•e‡ÿ•e‡ÿ–d‡ÿ•e…ÿ•e…ÿ•d„ÿ•d‚ÿ”c}ÿ•axÿ•`vÿ”`vÿ“awÿ“axÿ“_wÿ“^sÿ“^pÿ’]oÿ“]pÿ’^nÿ’]lÿ’\jÿ’\iÿ“\iÿ‘\fÿ‘[fÿ‘[gÿ‘[gÿ�Zeÿ¨} ÿ¨~¢ÿ¨} ÿ©|™ÿªz‘ÿ©z�ÿ©z‘ÿ©z”ÿ¨{–ÿ§{˜ÿ¦{™ÿ¦|›ÿ¦|�ÿ¥|žÿ¥|žÿ§|Ÿÿ¦}žÿ¦}žÿ¦}žÿ§}žÿ§}œÿ©|šÿª}™ÿª~™ÿ«~™ÿ­—ÿ®€–ÿ¯€–ÿ°€”ÿ°€“ÿ°€“ÿ¯€•ÿ¯€•ÿ¯€–ÿ°�šÿ¯‚�ÿ°ƒ ÿ±„¡ÿ²ƒžÿ²‚—ÿ³�”ÿ³�“ÿ´��ÿµ‚�ÿ¶‚Šÿ·‚‰ÿ·�‡ÿ¸�„ÿº�ƒÿ¹��ÿº�€ÿº�€ÿº‚‚ÿºƒ†ÿºƒ‹ÿ¹„�ÿ¹…’ÿ¹…•ÿ¹…•ÿ¹…“ÿº…’ÿº…�ÿº„Žÿº„�ÿ¹„Œÿ¹‚‹ÿ¹‚Šÿ¹ƒŠÿºƒ‹ÿ¹ƒ�ÿ¹ƒ�ÿ¹„“ÿ¸„•ÿ¸ƒ’ÿ¹‚Šÿ¹€†ÿ¹€…ÿ¸€†ÿ·€‰ÿ·�‹ÿ¶�Žÿµ�‘ÿ´‚–ÿ³ƒœÿ³„Ÿÿ²ƒŸÿ²‚žÿ²�›ÿ²€—ÿ²‘ÿ³}Žÿ²}Œÿ²|Šÿ²|‰ÿ³|‰ÿ³|‰ÿ³|‰ÿ²|Šÿ²|Œÿ³}�ÿ²}�ÿ²|Œÿ³|�ÿ³|Žÿ³}�ÿ³}�ÿ²}�ÿ³|Žÿ³|Œÿ³{Šÿ´|‰ÿ´{‡ÿ´{†ÿ´z†ÿ´{…ÿ´{„ÿµz�ÿµyÿµy~ÿµz~ÿ´y~ÿ´y€ÿ³z…ÿ³zˆÿ²{Šÿ³{‹ÿ²z‰ÿ²z†ÿ²y…ÿ²yƒÿ²x€ÿ±v|ÿ±uzÿ±uyÿ±uyÿ°tyÿ¯u|ÿ®uÿ­u‚ÿ¬u…ÿ¬u†ÿ¬u…ÿ¬u‚ÿ­t~ÿ­s{ÿ­ryÿ¬ryÿ¬ryÿ¬qxÿ«qxÿ«qzÿ«r{ÿ«qyÿªotÿ©nqÿ©opÿ¨npÿ¨nqÿ¨nrÿ§msÿ§msÿ§msÿ¦mrÿ¥lqÿ¤jsÿ¢kuÿ¡jvÿ¡itÿ itÿ itÿ htÿ gqÿ goÿ goÿ grÿŸgtÿžfrÿžfpÿžfoÿžfoÿ�eoÿ›doÿšcoÿ™drÿšeuÿ›fxÿ™fzÿ™eyÿ™exÿ™dvÿ˜btÿ–btÿ•btÿ”avÿ”byÿ”czÿ“c|ÿ“c~ÿ“cÿ“c~ÿ’b{ÿ’byÿ“byÿ“c{ÿ”dÿ•e�ÿ”dƒÿ”d…ÿ•e…ÿ•e„ÿ•eƒÿ•d‚ÿ–d‚ÿ–d‚ÿ–d�ÿ–e�ÿ–f‚ÿ–f‚ÿ–e‚ÿ–fƒÿ•e…ÿ”eˆÿ“eŠÿ”fŒÿ”f‹ÿ“dˆÿ”e…ÿ•dƒÿ•d€ÿ•c{ÿ–avÿ•atÿ”`tÿ”`tÿ”`tÿ•`tÿ”_qÿ“^nÿ“^nÿ’^pÿ’]pÿ“]nÿ“]mÿ“]kÿ’\iÿ‘[fÿ’[fÿ’[fÿ‘Zeÿ�Ycÿ§|žÿ§~¢ÿ¨¥ÿ©~£ÿ©}šÿª|”ÿª|“ÿª|“ÿª|•ÿ¨|˜ÿ¨|›ÿ§}�ÿ¦}Ÿÿ¦}¡ÿ¦}¡ÿ¦| ÿ§}Ÿÿ§}žÿ§}žÿ§}�ÿ§|œÿ¨}šÿª}™ÿ«~˜ÿ«~—ÿ­~–ÿ­”ÿ¯€”ÿ°€“ÿ±€’ÿ±�‘ÿ±�’ÿ±�’ÿ²�“ÿ±‚—ÿ±ƒ›ÿ±ƒžÿ±ƒŸÿ²ƒ�ÿ³ƒ™ÿ³ƒ—ÿ³ƒ–ÿ´ƒ“ÿ¶ƒ�ÿ·ƒ�ÿ¸ƒ‹ÿ¸ƒ‰ÿº‚†ÿ»‚„ÿ»‚ƒÿ»‚‚ÿº‚�ÿ»ƒ‚ÿ»ƒ†ÿº„Šÿ¹„�ÿ¹…�ÿº†“ÿ¹†”ÿ¹†“ÿº†“ÿº…“ÿº…‘ÿº…�ÿº…Žÿº„Œÿº„‰ÿºƒˆÿ»ƒˆÿºƒŠÿºƒŒÿº„�ÿ¹…”ÿ¹…”ÿ¹„Žÿº‚ˆÿº‚†ÿ¹�†ÿ¸�†ÿ¸�‡ÿ·‚‹ÿ·�Žÿ¶‚“ÿµƒ™ÿ´„�ÿ³„žÿ³ƒ�ÿ³�›ÿ³€—ÿ³€‘ÿ´Žÿ´~�ÿ²~Œÿ²}‹ÿ²}‹ÿ³|Šÿ³|Šÿ²|‹ÿ²}�ÿ²|�ÿ±}�ÿ²}Œÿ³|�ÿ³|Žÿ²}�ÿ²~‘ÿ±}’ÿ²}‘ÿ²}�ÿ²|Œÿ³{Šÿ³|ˆÿ³|ˆÿ³|‰ÿ³|Šÿ´|‡ÿµ{ƒÿµz€ÿµzÿµz€ÿ´y€ÿ´y‚ÿ³z…ÿ³z‰ÿ³{Œÿ´|‹ÿ³{‡ÿ³yƒÿ²x�ÿ²xÿ²w|ÿ±w{ÿ±v{ÿ±v{ÿ±v{ÿ°v{ÿ°u}ÿ¯uÿ®v�ÿ­v„ÿ­v…ÿ­u„ÿ®t€ÿ®s{ÿ®rxÿ­qwÿ¬qwÿ¬qwÿ¬qwÿ«qyÿªpyÿªqyÿªpwÿªotÿ©nrÿ©oqÿ©nqÿ¨nrÿ¨nrÿ¨nsÿ¨msÿ§mrÿ§nqÿ¦mrÿ¥luÿ£lvÿ¡juÿ¡isÿ¡hrÿ hrÿŸirÿ hpÿ goÿ foÿŸgqÿžgrÿŸgpÿžfnÿ�enÿ�enÿœdnÿœdnÿšdoÿ™dqÿšeuÿšfwÿ™fwÿ™ewÿ™dvÿ™duÿ™csÿ˜csÿ—ctÿ–bvÿ•cyÿ•d|ÿ”d}ÿ“c~ÿ“cÿ“cÿ“b}ÿ“c{ÿ“c{ÿ“d}ÿ”d�ÿ”eƒÿ•e…ÿ•f‡ÿ•f†ÿ•f†ÿ–f…ÿ–fƒÿ–e‚ÿ–e‚ÿ–e‚ÿ—e‚ÿ–e‚ÿ•e�ÿ•dÿ”eÿ“d‚ÿ“e‡ÿ“fŒÿ’fŽÿ“fŒÿ”eˆÿ“dƒÿ”c€ÿ•b|ÿ–awÿ–asÿ–`qÿ•`qÿ”_pÿ”_oÿ”_nÿ”^mÿ”^lÿ“^mÿ“]oÿ“]pÿ“]oÿ“]lÿ“]jÿ’\gÿ‘[fÿ‘Zdÿ‘Zcÿ’Ybÿ‘Yaÿ¦|œÿ¦~£ÿ§€ªÿ¨�¬ÿ©€¥ÿ©~›ÿ«}•ÿ¬|”ÿ«}–ÿª}™ÿ©}œÿ¨}žÿ§~¡ÿ§£ÿ§~¤ÿ§}¢ÿ§}¡ÿ§} ÿ§}Ÿÿ§|�ÿ§|œÿ¨}›ÿª}™ÿ«}˜ÿ¬~—ÿ­~–ÿ­”ÿ¯“ÿ°“ÿ±€’ÿ±€’ÿ²‚“ÿ³‚’ÿ´‚’ÿ³ƒ”ÿ³ƒ—ÿ²ƒšÿ²„›ÿ³„›ÿ³„›ÿ´„™ÿµ„˜ÿµ„•ÿ¶ƒ�ÿ·ƒŒÿ¸ƒŒÿ¹ƒŠÿºƒˆÿ»ƒ†ÿ»ƒ…ÿ»ƒ„ÿ»‚ƒÿºƒ„ÿ»ƒ†ÿ»„‰ÿº„‹ÿº…�ÿº†�ÿº†’ÿº†“ÿº†”ÿ»†•ÿ»†•ÿ»†”ÿ»…’ÿ»…�ÿ»…Œÿ»„‰ÿ¼ƒˆÿ¼ƒ‰ÿ»ƒ‹ÿ»„�ÿ»…”ÿº†•ÿº…’ÿºƒŠÿ»‚‡ÿ»‚…ÿº�„ÿº‚†ÿ¹‚‰ÿ¸‚Œÿ·‚�ÿ·ƒ•ÿ¶„›ÿµ„žÿ´ƒ�ÿµ‚›ÿµ�–ÿ´€‘ÿ´€Žÿµ�ÿ´�ÿ³~Œÿ³}‹ÿ³}Šÿ³|Šÿ²}Œÿ²}Žÿ±}Žÿ±}Žÿ²}�ÿ³}�ÿ³}Žÿ²~‘ÿ²~“ÿ±~•ÿ²~”ÿ²~’ÿ²|Žÿ²|Œÿ²|Šÿ²|‹ÿ³}�ÿ³}�ÿ³}‰ÿµ{„ÿµz�ÿ¶z€ÿµz€ÿµz�ÿµz‚ÿ´z…ÿ´{ˆÿ´{‹ÿ´{Šÿ´z…ÿ´y€ÿ³x~ÿ³w|ÿ³w{ÿ²wzÿ±w|ÿ²v~ÿ±v~ÿ±v}ÿ°u~ÿ°uÿ¯v�ÿ¯v‚ÿ®v‚ÿ®t€ÿ®t}ÿ®szÿ®rvÿ­rvÿ¬qvÿ¬rvÿ¬qwÿ«qxÿªqwÿªpwÿªouÿªosÿ©orÿ©orÿ©orÿ©nrÿ¨nrÿ¨nrÿ¨nrÿ¨mrÿ¨mrÿ§msÿ¦muÿ¥ltÿ¢jsÿ¢irÿ¢hpÿ¡hpÿ¡hpÿ¡hpÿ¡gpÿ gqÿžgqÿžgqÿžgpÿžfnÿ�enÿœenÿœdnÿœdnÿ›dpÿšerÿšetÿšeuÿ™euÿ˜dvÿ™dvÿ™duÿ˜csÿ˜crÿ˜csÿ—cvÿ–cyÿ–d|ÿ•e~ÿ”d€ÿ“c�ÿ“c�ÿ“d�ÿ“d€ÿ“dÿ“d€ÿ”eƒÿ•e†ÿ•f‡ÿ•f‡ÿ–f‡ÿ–f†ÿ—f†ÿ–f„ÿ–f‚ÿ–e‚ÿ–e‚ÿ–e‚ÿ•d‚ÿ•d€ÿ”d~ÿ“c~ÿ“c�ÿ“eˆÿ’f�ÿ’fŽÿ“fŒÿ“e†ÿ“c�ÿ”b}ÿ•ayÿ–auÿ–`qÿ–_oÿ–_nÿ•_mÿ•^lÿ”^kÿ•]jÿ”]kÿ“]lÿ“]mÿ“]nÿ“]mÿ“\jÿ’\gÿ’[eÿ‘Zdÿ‘Ybÿ’Yaÿ’Y`ÿ’Y_ÿ§|�ÿ¦~¦ÿ¥�°ÿ¦‚´ÿ§‚¯ÿ©£ÿ«~šÿ¬~˜ÿ¬~šÿ«›ÿ©�ÿ©~Ÿÿ¨¢ÿ¨¤ÿ¨¥ÿ§¤ÿ¨~¤ÿ§~¢ÿ§} ÿ§|žÿ§}�ÿ¨}œÿ©}›ÿª}šÿ¬}˜ÿ­~—ÿ­~•ÿ®”ÿ¯“ÿ¯’ÿ°€“ÿ²�“ÿ³‚“ÿ´‚‘ÿµƒ‘ÿ´ƒ’ÿ´ƒ”ÿ´„—ÿ´„™ÿ´„›ÿ´…›ÿ¶…šÿ¶„•ÿ¶ƒ�ÿ¶‚‹ÿ·‚Šÿ¸ƒ‹ÿºƒŠÿº„ˆÿ»„‡ÿ»ƒ†ÿ»ƒ†ÿ»ƒ†ÿ»„‡ÿ¼„ˆÿ»…Šÿ»…‹ÿ»…�ÿ»†�ÿ»†’ÿº‡”ÿ»‡—ÿ»‡˜ÿ»‡—ÿ»‡•ÿ¼‡’ÿ»†�ÿ¼…Œÿ¼„Šÿ½ƒŠÿ¼„Œÿ¼…�ÿ»†’ÿ»†”ÿ»†“ÿ»„Œÿ¼ƒˆÿ¼‚…ÿ¼‚…ÿ¼‚†ÿ»ƒ‰ÿºƒŠÿ¹ƒ�ÿ¸ƒ‘ÿ¸„—ÿ·…œÿ¶„œÿ¶ƒšÿ¶‚–ÿ¶�’ÿ¶€Žÿµ�ÿµŒÿµ‹ÿµ~‰ÿ´}‰ÿ´}Šÿ³}Œÿ²~�ÿ±}�ÿ±~�ÿ±}Žÿ²}Žÿ³~�ÿ³~’ÿ³”ÿ³•ÿ³•ÿ´“ÿ³}�ÿ³|Œÿ²|Œÿ²}Žÿ³}�ÿ²}�ÿ³}Œÿ´|‡ÿµ{„ÿ¶{‚ÿ¶{�ÿµz�ÿµz�ÿµ{„ÿµ|ˆÿ´|‹ÿ´{‡ÿ´z�ÿ´x}ÿ´w{ÿ´wzÿ´xyÿ³w{ÿ²w~ÿ²w€ÿ²w€ÿ±vÿ°vÿ°v€ÿ¯v�ÿ¯v�ÿ¯uÿ¯u}ÿ¯t{ÿ¯syÿ®rwÿ­rwÿ­rwÿ¬rxÿ¬qxÿ«qxÿªqwÿªovÿªouÿªotÿªorÿ©orÿªosÿ©otÿ©osÿ¨nrÿ¨nqÿ¨nqÿ¨nrÿ§msÿ¦msÿ¥kqÿ¤ipÿ£ioÿ£ioÿ¢ioÿ¢hpÿ¡hqÿ¡hrÿ hrÿŸgrÿžgrÿžfpÿ�fpÿ�fpÿœepÿœdpÿœdpÿ›eqÿ›esÿ›etÿ›etÿ™duÿ˜duÿ˜dvÿ˜cuÿ˜csÿ˜crÿ˜csÿ—ctÿ–cwÿ–d{ÿ•e~ÿ”e�ÿ“dƒÿ“d…ÿ“e†ÿ“e…ÿ“eƒÿ“eƒÿ”e†ÿ•fˆÿ–fˆÿ–g‡ÿ–f†ÿ—f…ÿ—f†ÿ—f…ÿ–fƒÿ–e�ÿ–e€ÿ•d€ÿ•d�ÿ”d€ÿ”c~ÿ”b~ÿ“c�ÿ“d‡ÿ“e‹ÿ“fŒÿ”fŠÿ“dƒÿ”c~ÿ•a{ÿ•awÿ•`rÿ–_nÿ–_lÿ–_lÿ–_lÿ•_kÿ•^kÿ•^kÿ”]kÿ“]kÿ“]lÿ“^nÿ“]kÿ“[gÿ’[dÿ’Zdÿ‘Zdÿ‘Zcÿ’Yaÿ’Y`ÿ’Y_ÿ¦} ÿ¥¨ÿ¤‚´ÿ¤ƒºÿ¥ƒ¶ÿ¨€©ÿ© ÿª€žÿ«€Ÿÿ«€¡ÿª€¢ÿ©¢ÿ©€¤ÿ©�¦ÿ¨€¦ÿ¨€¥ÿ¨€¤ÿ¨£ÿ¨~¡ÿ¨}Ÿÿ§}�ÿ¨}�ÿ¨}�ÿ©}›ÿª}šÿ«~™ÿ¬~˜ÿ­—ÿ®–ÿ®”ÿ¯€”ÿ°€“ÿ±�“ÿ³�‘ÿ´‚�ÿµ‚Žÿ¶ƒ�ÿ¶ƒ‘ÿµ„–ÿµ…šÿµ†œÿµ…›ÿ¶„–ÿ¶ƒ�ÿ¶�‹ÿ·‚Šÿ¸ƒ‹ÿº…Œÿº…‹ÿº…Šÿº„‰ÿ»„‰ÿ»„‰ÿ»„Šÿ»…Šÿ¼„Šÿ¼„Šÿ¼…Œÿ¼†Žÿ»…�ÿ»‡’ÿ»‡˜ÿ»ˆšÿ»‰™ÿ»ˆ—ÿ¼ˆ•ÿ»‡’ÿ¼…�ÿ¼…�ÿ¼„�ÿ¼…�ÿ½†Žÿ¼†�ÿ¼†’ÿ¼†’ÿ¼…Žÿ½„‰ÿ½ƒ†ÿ½ƒ…ÿ½ƒ‡ÿ¼„‰ÿ»„‹ÿ»„‹ÿº„�ÿº…“ÿ¸†˜ÿ·…šÿ¸„˜ÿ¸ƒ–ÿ·ƒ’ÿ·��ÿ·€‹ÿ¶€‰ÿ¶ˆÿ¶‡ÿ¶~‡ÿµ~‰ÿµŒÿ³�ÿ²~‘ÿ²�ÿ³~Žÿ³~�ÿ´~Žÿ´�ÿ´€’ÿµ€“ÿµ€’ÿµ�ÿ´~Žÿ³}‹ÿ³}Œÿ³~Žÿ²~‘ÿ±~’ÿ³}�ÿ³|Œÿµ|ˆÿ¶{…ÿ¶|ƒÿµ{ƒÿ´{‚ÿµ|„ÿµ|‰ÿ´|Šÿ´{„ÿµz}ÿµxyÿµwwÿµwvÿ´wwÿ³xzÿ²xÿ²x�ÿ±x‚ÿ°w�ÿ°w�ÿ°w�ÿ¯v�ÿ®v€ÿ¯vÿ¯u}ÿ®t{ÿ®tyÿ®sxÿ®sxÿ­ryÿ¬ryÿ¬qyÿ«qyÿ©pyÿ©owÿ©ovÿ©ouÿªotÿªptÿ«puÿªpuÿ©otÿ¨orÿ§nqÿ§npÿ§nqÿ§nrÿ§mqÿ¥joÿ¤inÿ¤jnÿ¤joÿ£jpÿ¢iqÿ¡isÿ isÿŸhtÿŸhtÿžgtÿ�gsÿ�grÿœfrÿœerÿ›drÿœesÿ›etÿ›ftÿ›ftÿšdrÿ™dsÿ˜ctÿ—cuÿ—btÿ˜bsÿ˜crÿ—bsÿ—btÿ—cvÿ–dzÿ•d~ÿ“e‚ÿ“e…ÿ“eˆÿ“fŠÿ’fˆÿ’e†ÿ“e†ÿ”f‡ÿ•f‡ÿ–g‡ÿ—f…ÿ—f„ÿ–fƒÿ˜g…ÿ—g…ÿ—f„ÿ–e€ÿ•d}ÿ•d}ÿ•dÿ”c~ÿ”c}ÿ”c}ÿ”d€ÿ”d„ÿ“e‡ÿ”eˆÿ•e†ÿ•c€ÿ•b|ÿ•ayÿ•auÿ–`qÿ•_lÿ–_jÿ–_jÿ–_kÿ–_lÿ•_lÿ•^lÿ”^lÿ”^mÿ”^nÿ”^oÿ”]kÿ“[gÿ’[dÿ’[eÿ‘[fÿ�Zeÿ�Ybÿ‘Xaÿ‘Y`ÿ¤}¡ÿ£¨ÿ¤‚´ÿ¤„»ÿ¤„¸ÿ§‚­ÿ©�¦ÿ©�£ÿª‚¤ÿª‚¥ÿ«‚¦ÿª�¦ÿ©�¨ÿ©‚©ÿ¨‚©ÿ¨�¨ÿ©�¦ÿ©€¤ÿ©£ÿ©~ ÿ¨~žÿ¨~žÿ¨~žÿ¨~�ÿ¨}œÿ©}œÿª~œÿ«œÿ­€œÿ®€›ÿ¯�˜ÿ®€•ÿ¯�”ÿ±�’ÿ³€�ÿ´�Žÿµ‚�ÿ¶ƒ�ÿµƒ“ÿ´„—ÿµ†�ÿµ…œÿ´„™ÿ´ƒ•ÿµƒ‘ÿ¸„�ÿ¹„Œÿº…�ÿº†Žÿ»†Œÿ»…‹ÿº…‹ÿ»…�ÿ»†�ÿº…�ÿ¼…�ÿ»…Œÿ»†�ÿ»‡Žÿ»†Žÿ»†�ÿ»‡–ÿ»ˆšÿ»‰œÿ¼‰›ÿ»ˆ˜ÿ»‡•ÿ»†“ÿ¼†‘ÿ¼†�ÿ»…Žÿ¼†Žÿ½†�ÿ¼†‘ÿ¼‡‘ÿ½†Žÿ½…‹ÿ½„ˆÿ½„†ÿ¾„‡ÿ½…Šÿ¼…Œÿ»…‹ÿ»…Œÿº„�ÿ¹…•ÿ¹…—ÿ¹…—ÿ¹…–ÿ¸„‘ÿ¹��ÿ¸€ˆÿ¸€…ÿ¸€„ÿ¸…ÿ¸‡ÿ¶~‰ÿµŒÿµ€�ÿ´€‘ÿ´€�ÿ´�ÿµ~‹ÿµ~‹ÿµ�ÿ¶€Žÿ¶€�ÿ¶€�ÿ¶€ŽÿµŒÿ´~Šÿ´~‹ÿ³~Žÿ³’ÿ²~”ÿ²~’ÿ²}�ÿ³|Œÿ´|‰ÿ´|‡ÿ³{…ÿ´|…ÿ´|‡ÿ´|Šÿ´|‰ÿµ{ƒÿµz|ÿµxwÿ¶xuÿ¶wuÿµwvÿ³xzÿ²xÿ³x‚ÿ²xƒÿ°w‚ÿ°w‚ÿ°w‚ÿ¯w€ÿ®vÿ¯vÿ¯u~ÿ®u}ÿ­t{ÿ­t{ÿ­s{ÿ¬s{ÿ¬s{ÿ«r{ÿªq|ÿ¨p|ÿ¨pzÿ©oyÿ©oyÿ©pxÿ«qwÿªpvÿªpuÿ©otÿ¨nsÿ¨nrÿ§mqÿ§mrÿ§mrÿ§mrÿ¥jpÿ¤inÿ¥joÿ¤kpÿ£jqÿ¡jsÿ¡itÿ iuÿŸivÿžhwÿ�hwÿ�huÿœgtÿ›ftÿ›ftÿ›ftÿšetÿ›fuÿ›fvÿ›etÿšdrÿ™csÿ—ctÿ–ctÿ–ctÿ–brÿ–arÿ–bsÿ–buÿ–bwÿ•czÿ”d~ÿ“e‚ÿ“e…ÿ’f‰ÿ’f‹ÿ‘e‰ÿ’e‡ÿ“f‡ÿ”f‡ÿ•f†ÿ–fƒÿ—f‚ÿ–f�ÿ—f€ÿ—e€ÿ—f‚ÿ—f�ÿ—e}ÿ—dzÿ—dzÿ–c{ÿ•c|ÿ–c{ÿ–c{ÿ•d}ÿ•e‚ÿ•e…ÿ•eƒÿ”c€ÿ•b{ÿ•ayÿ•avÿ•atÿ–aqÿ–_mÿ•_kÿ–_kÿ–_lÿ•^mÿ”_lÿ”_lÿ”^mÿ”^oÿ”_pÿ“^nÿ“]kÿ’[gÿ‘[eÿ‘\fÿ�[gÿ�Zeÿ�Ycÿ�X`ÿ�X_ÿ¦~¤ÿ¥€«ÿ¥ƒµÿ¥…»ÿ¥„¹ÿ§ƒ±ÿ¨‚«ÿ©‚¨ÿª‚¨ÿ«ƒ©ÿ«ƒ©ÿ«ƒªÿªƒ¬ÿªƒ®ÿ©ƒ¯ÿ©ƒ­ÿªƒªÿª�§ÿª€¤ÿª¡ÿ©Ÿÿ©~Ÿÿ¨~Ÿÿ§}žÿ¨~žÿ¨}žÿ¨~Ÿÿ© ÿª ÿ¬Ÿÿ­€žÿ®�œÿ¯�šÿ°�–ÿ²€’ÿ³€�ÿ´�Žÿµ‚�ÿ¶„’ÿµ…–ÿµ…™ÿ´…šÿ´„›ÿ´…šÿµ…–ÿ¸…’ÿ¹…�ÿº…�ÿº†�ÿº…Žÿ»…Œÿº…Œÿº†Žÿ»‡�ÿ»†�ÿ¼†�ÿ»†�ÿ»†�ÿ»†�ÿ»‡�ÿ»‡�ÿ»‡“ÿ¼ˆ™ÿ¼‰�ÿ¼Šžÿ¼‰œÿ¼ˆ™ÿ¼ˆ—ÿ¼‡–ÿ¼‡”ÿ¼†‘ÿ½†�ÿ½†�ÿ¼‡‘ÿ½‡�ÿ½‡�ÿ½†�ÿ½…‹ÿ¾…‰ÿ½…Šÿ½…Œÿ½†Œÿ½…‹ÿ¼…‹ÿ»…�ÿ»†“ÿº†–ÿ¹…–ÿ¹…•ÿ¹„’ÿ¹‚�ÿ¹€ˆÿ¹€ƒÿ¹�ÿ¹€ƒÿ¸…ÿ¸‰ÿ·€�ÿ·��ÿ¶��ÿµ�Žÿ¶€Œÿ¶Šÿ¶‰ÿ·Šÿ·€Œÿ·��ÿ·€Žÿ¶€Žÿ¶€ŒÿµŠÿµ‹ÿµ�ÿ³’ÿ³”ÿ³“ÿ²~’ÿ²~�ÿ³}Žÿ³}Œÿ²|Šÿ³|Šÿ´}Œÿ´|Œÿ´|Šÿµ|…ÿµz~ÿ¶yyÿ¶xvÿ¶wuÿµxwÿ´xyÿ³x}ÿ²x�ÿ²y„ÿ±xƒÿ°wƒÿ°wƒÿ¯w�ÿ¯vÿ¯vÿ¯vÿ®uÿ­tÿ­t~ÿ¬t~ÿ¬t~ÿ«s~ÿªsÿ©r€ÿ¨qÿ¨q}ÿ¨p|ÿ©p{ÿªqyÿªqwÿªpvÿªpuÿ©otÿ¨otÿ§nuÿ§ntÿ§mtÿ§mtÿ¦msÿ¦lrÿ¥krÿ¤ksÿ¤ktÿ£kuÿ¢juÿ¡jvÿ iwÿŸixÿžhxÿ�gxÿ�hwÿœgvÿ›fvÿ›fuÿ›euÿševÿšfwÿ›fvÿ›etÿ›dsÿšdsÿ˜dsÿ—csÿ–bsÿ–arÿ•arÿ•atÿ•bvÿ”bxÿ“c|ÿ“dÿ“e�ÿ’e…ÿ’eˆÿ“fŠÿ’eˆÿ’e‡ÿ“f‡ÿ”f†ÿ•fƒÿ–f‚ÿ—f€ÿ—eÿ˜e}ÿ˜e}ÿ—e}ÿ—d{ÿ—dxÿ˜cuÿ˜cvÿ—cwÿ—cwÿ—cxÿ—cyÿ—d{ÿ–dÿ•e�ÿ–d€ÿ•c{ÿ–bxÿ–awÿ–avÿ–auÿ–arÿ•_pÿ–_nÿ•_nÿ•^nÿ–_nÿ•_mÿ•_mÿ”^oÿ“_qÿ“^rÿ’^pÿ’]mÿ’\iÿ‘[gÿ�[gÿ�Zgÿ�Zeÿ�Ycÿ�X`ÿ�W_ÿ¨€§ÿ§�­ÿ¦ƒ´ÿ¦…·ÿ§…·ÿ§…´ÿ¨„±ÿ¨ƒ¯ÿ©„­ÿªƒ¬ÿªƒªÿ«ƒ¬ÿ«„®ÿª…±ÿ©„±ÿ©„¯ÿª„­ÿ«ƒªÿ«�¦ÿ«�£ÿ«€¡ÿª€¡ÿ© ÿ¨¡ÿ¨¡ÿ§~¢ÿ§~¢ÿ§£ÿ¨£ÿª¢ÿ«€¢ÿ­� ÿ®�žÿ¯�šÿ±€•ÿ²€’ÿ´‚�ÿ´‚�ÿµƒ‘ÿµ„”ÿµ„•ÿµ„–ÿµ„˜ÿ¶…šÿ¶†™ÿ¸†–ÿ¹†”ÿ¹†‘ÿ¹…�ÿº…Žÿº…�ÿº…Œÿ»‡�ÿ»‡“ÿ»‡”ÿ»‡•ÿ¼‡“ÿ¼‡‘ÿ¼‡�ÿ¼‡�ÿ¼‡�ÿ¼‡‘ÿ¼ˆ˜ÿ¼Šžÿ¼ŠŸÿ¼Šžÿ¼Šœÿ¼‰›ÿ¼ˆ™ÿ¼ˆ—ÿ½ˆ•ÿ½‡“ÿ½‡“ÿ½‡“ÿ½‡“ÿ½‡‘ÿ½‡�ÿ½‡Žÿ½†Œÿ½…Œÿ½…Œÿ½†Šÿ½†‰ÿ½…‹ÿ½…Žÿ¼†‘ÿ»‡”ÿº†–ÿº†–ÿº…”ÿ¹ƒŽÿ¹�ˆÿ¹„ÿ¹‚ÿ¸‚ÿ¸…ÿ¸€‰ÿ¸��ÿ·��ÿ·�Žÿ·�Œÿ·�‹ÿ¸€‰ÿ¸€ˆÿ¸€‰ÿ¸�Šÿ¸�Œÿ·€�ÿ·��ÿ·�‹ÿ·€Šÿ¶€Œÿµ€Žÿ´€‘ÿ´“ÿ´”ÿ³“ÿ²~’ÿ²~’ÿ²~‘ÿ²}�ÿ²}�ÿ³}�ÿ³}�ÿ³|�ÿ´|‰ÿµ{‚ÿµz|ÿµyxÿ¶xwÿ¶xwÿµyyÿ³y|ÿ³y€ÿ³yƒÿ±x„ÿ°x„ÿ°xƒÿ°w�ÿ°wÿ°vÿ¯w€ÿ®v�ÿ¬u‚ÿ¬u‚ÿ¬t‚ÿ«t�ÿªt‚ÿ©sƒÿ¨s‚ÿ¨r‚ÿ¨r�ÿ¨qÿ©q|ÿ©qzÿ©pwÿªpvÿªouÿ©otÿ¨ovÿ§nwÿ§nvÿ§mvÿ¦mwÿ¦mwÿ¦mvÿ¦mvÿ¤lwÿ£lxÿ£kxÿ¢kxÿ¡kxÿ jxÿŸiyÿžhxÿžhxÿ�hwÿœhwÿ›gwÿ›fwÿšfwÿ™exÿ™exÿševÿ›etÿ›dsÿšdrÿ™drÿ˜crÿ—brÿ–arÿ•arÿ”atÿ”bwÿ“bzÿ“c~ÿ“d€ÿ’eƒÿ’e†ÿ’f‰ÿ“fˆÿ“e†ÿ“f†ÿ”f…ÿ”eƒÿ•e�ÿ•e�ÿ–e€ÿ—e~ÿ˜e|ÿ˜e{ÿ˜dzÿ˜cwÿ˜csÿ˜crÿ˜brÿ˜crÿ—bsÿ—btÿ˜cvÿ˜cyÿ—d{ÿ—d|ÿ—d{ÿ—cxÿ—bwÿ—bwÿ—bwÿ—avÿ–atÿ•`sÿ•_qÿ•_pÿ•_pÿ–_oÿ–_nÿ•_oÿ“_qÿ’_sÿ’^tÿ’^sÿ‘]oÿ‘\kÿ�\iÿ�[hÿ�Zhÿ�Zfÿ�Zcÿ�Y`ÿ�X`ÿ©‚¨ÿ¨ƒ®ÿ¨„²ÿ¨…µÿ¨†¶ÿ¨†¸ÿ¨†·ÿ©†µÿ©…±ÿ©„­ÿ©ƒ¬ÿ©ƒ¬ÿª„®ÿª…°ÿ©…°ÿ¨„¯ÿ©„¯ÿª„­ÿ«ƒ©ÿ«‚¥ÿ¬‚¥ÿ«‚¤ÿ«�£ÿ©�¤ÿ¨€¥ÿ¨¥ÿ§¥ÿ¦€¦ÿ¦¥ÿ¨¥ÿ©€¤ÿª€¢ÿ¬€¡ÿ®��ÿ°�˜ÿ±�•ÿ³ƒ“ÿ´ƒ’ÿµƒ’ÿµƒ“ÿµ„“ÿ¶„”ÿ¶„–ÿ¶…—ÿ·†™ÿ·†˜ÿ¸†–ÿ¸…’ÿ¸„�ÿ¹„�ÿ¹„Žÿ¹…Žÿº‡’ÿº‡•ÿ¹‡—ÿºˆ˜ÿ»ˆ–ÿ»ˆ•ÿ¼ˆ“ÿ¼ˆ’ÿ¼ˆ‘ÿ¼‡’ÿ¼‰˜ÿ»Šžÿ»ŠŸÿ»ŠŸÿ»Šžÿ»Š�ÿ¼‰›ÿ¼‰šÿ¼‰šÿ½ˆ˜ÿ½ˆ–ÿ½ˆ–ÿ½ˆ—ÿ½ˆ–ÿ½ˆ•ÿ½ˆ“ÿ½‡‘ÿ½†�ÿ¾†�ÿ½†Šÿ½†‰ÿ½†Šÿ½†�ÿ¼‡‘ÿ¼‡“ÿ»‡–ÿº†˜ÿº†–ÿ¹„�ÿ¸�Šÿ¸€‡ÿ¸…ÿ·„ÿ¶~…ÿ¶‰ÿ¶€�ÿ¶�Žÿ·��ÿ·‚‹ÿ·�Šÿ¸€ˆÿ¸€‡ÿ¹€‡ÿ¹�‰ÿ¸�Šÿ¸�‹ÿ·�‹ÿ·�‹ÿ¸�‹ÿ·�‹ÿ¶€Œÿµ€Žÿµ€�ÿµ‘ÿ´�ÿ³~‘ÿ²~’ÿ²~“ÿ±~”ÿ²~•ÿ±~•ÿ±}“ÿ±}�ÿ³|�ÿ³|ˆÿ³{‚ÿ´z~ÿµy|ÿµxzÿ´y{ÿ´y}ÿ´yÿ³y�ÿ±xƒÿ°x„ÿ°xƒÿ°w€ÿ±w~ÿ°wÿ¯w‚ÿ­w„ÿ¬v…ÿ¬u…ÿ«u…ÿªt„ÿªt…ÿ©t†ÿ¨s…ÿ¨s…ÿ§r„ÿ§r�ÿ§q~ÿ§p{ÿ¨pxÿ©owÿ©nvÿ¨nuÿ¨owÿ¦nxÿ¥nxÿ¥nyÿ¥nzÿ¦n{ÿ¦nzÿ¦nyÿ¤mzÿ¤m{ÿ£l{ÿ¡kzÿ¡kzÿ kyÿŸjyÿžiyÿžixÿ�hxÿœhxÿ›gwÿšfxÿšfzÿ™fzÿ˜fzÿ™exÿ™evÿ™dtÿ™dsÿ™dsÿ˜csÿ–brÿ–bsÿ•asÿ”atÿ“awÿ“b|ÿ’c€ÿ‘dƒÿ‘e†ÿ‘f‰ÿ’gŠÿ’f‡ÿ“e„ÿ”eƒÿ”e‚ÿ”d�ÿ•d�ÿ•e�ÿ–e€ÿ—eÿ—e|ÿ™dyÿ˜dwÿ˜dtÿ˜cpÿ˜boÿ˜bpÿ˜boÿ—aoÿ˜apÿ˜crÿ™cuÿ™dwÿ˜dwÿ˜cvÿ˜ctÿ˜buÿ—bwÿ—bwÿ–bwÿ–avÿ•`uÿ”`sÿ”`sÿ•`rÿ•_qÿ”_qÿ“_rÿ’_tÿ‘_uÿ‘_uÿ‘^uÿ�]rÿ�\nÿ�\lÿ�[jÿ�[iÿ�Zfÿ�Ycÿ�Yaÿ�Yaÿªƒ©ÿª…®ÿª†³ÿ©†µÿ©‡¸ÿ¨ˆ¼ÿ©ˆ»ÿª‡·ÿ©†³ÿ©…¯ÿª„­ÿ©„¬ÿ©„­ÿª„®ÿª„­ÿ©„­ÿª„®ÿª„®ÿªƒ«ÿ©ƒ§ÿ«„©ÿ«„¨ÿ«ƒ§ÿª‚§ÿ©‚¨ÿ©�¨ÿ¨�©ÿ§�©ÿ§�©ÿ§§ÿ§¦ÿ¨€¥ÿª�£ÿ¬�¡ÿ®‚�ÿ°‚šÿ²ƒ˜ÿ´ƒ—ÿµƒ–ÿµ„–ÿ¶„•ÿ¶„•ÿ¶…–ÿ¶…—ÿ·†™ÿ·‡˜ÿ·†—ÿ·…”ÿ¸„‘ÿ¹„‘ÿ¸„‘ÿ¸…“ÿ¸†–ÿ¸‡™ÿ·†šÿ¹ˆšÿºˆ™ÿºˆ˜ÿ»‰–ÿ¼‰•ÿ½ˆ•ÿ¼ˆ•ÿ¼‰™ÿ»Šžÿº‹¡ÿº‹¡ÿº‹ ÿ»‹Ÿÿ»ŠžÿºŠžÿ»Š�ÿ¼Šœÿ¼‰šÿ¼ˆ™ÿ¼‰™ÿ½‰šÿ¼‰šÿ¼‰˜ÿ½ˆ–ÿ¾ˆ”ÿ½‡�ÿ¼‡Œÿ½†‹ÿ½‡Œÿ¼‡�ÿ¼‡’ÿ¼‡•ÿ»‡˜ÿº‡šÿº‡˜ÿ¹…‘ÿ¸ƒ�ÿ¸‚‹ÿ·�‰ÿ¶ˆÿµ~†ÿ´~Šÿ´Žÿµ€�ÿ¶��ÿ·�‹ÿ·€ˆÿ¸†ÿ¸…ÿ¸€…ÿº�‡ÿ¹�ˆÿ¸�‰ÿ¸‚Šÿ¸‚Šÿ¸‚Šÿ¸�‰ÿ·€‰ÿ·€Šÿ·€ŒÿµŒÿ´~Œÿ´~Œÿ³~�ÿ²’ÿ°€–ÿ±˜ÿ°˜ÿ¯~—ÿ¯~•ÿ°}’ÿ±|Žÿ±|Šÿ²{‡ÿ³zƒÿ´y€ÿ´yÿ´zÿ³zÿ²y€ÿ±y‚ÿ°yƒÿ°x‚ÿ°wÿ°w~ÿ±x�ÿ¯w„ÿ®w…ÿ­v†ÿ¬v‡ÿ«u†ÿªt…ÿªt†ÿ©s‡ÿ¨t‡ÿ§s†ÿ¦r…ÿ¦qƒÿ¦q€ÿ¥p}ÿ¦o|ÿ¦nyÿ¦nwÿ§nwÿ§oxÿ§ozÿ¥o{ÿ¤o}ÿ¥oÿ¥oÿ¦o}ÿ¦o{ÿ¤n{ÿ¤n|ÿ£m}ÿ¡l{ÿ¡kzÿ kyÿŸjyÿŸizÿži{ÿœhzÿ›hyÿ›hyÿšgzÿšg|ÿ™g~ÿ˜g~ÿ˜f}ÿ—d{ÿ—dyÿ—dxÿ—dwÿ–cuÿ•btÿ•ctÿ”btÿ”atÿ“awÿ’b|ÿ‘d‚ÿ�c†ÿ�d‰ÿ�fŒÿ’gŒÿ‘fˆÿ’eƒÿ”e�ÿ”e�ÿ”e‚ÿ”e„ÿ–f„ÿ—f‚ÿ—fÿ˜e{ÿ™ewÿ™dtÿ˜cpÿ˜cmÿ˜bmÿ—aoÿ—anÿ˜anÿ˜aoÿ™bpÿšcqÿšcrÿšcqÿ™cpÿ˜bpÿ˜ctÿ—bvÿ–bxÿ•byÿ•bzÿ”awÿ“`vÿ“`vÿ”`vÿ”_uÿ“`uÿ“`wÿ’`xÿ‘`xÿ�`wÿ�_vÿ�^uÿ�]rÿ�\nÿ�\lÿ�Ziÿ�Zfÿ�Zdÿ�YcÿŽXbÿ­†«ÿ­‡°ÿ«ˆ´ÿªˆ¸ÿªŠ¾ÿªŠÀÿª‰½ÿªˆ¸ÿ«ˆ´ÿ«‡²ÿ«†¯ÿª…­ÿª…­ÿ«…­ÿª„­ÿ«„®ÿ«…®ÿª„­ÿª„¬ÿ©„«ÿª…®ÿª†¯ÿ«†®ÿ«…¬ÿ«…¬ÿª„¬ÿ©„¬ÿ¨ƒ­ÿ¨‚¬ÿ§�ªÿ¦€ªÿ§�ªÿ¨�©ÿ©�¦ÿ¬�¤ÿ­‚¡ÿ¯ƒŸÿ²„žÿ´„œÿµ…šÿµ…™ÿ¶…™ÿ¶…™ÿµ†™ÿ¶†™ÿ·‡™ÿ·†™ÿ·…—ÿ·…•ÿ·†”ÿ·…–ÿ·†˜ÿ·†›ÿ¶‡�ÿ¶‡�ÿ·‡�ÿ¸ˆ�ÿ¹ˆœÿº‰šÿ»Š™ÿ½‰™ÿ¼‰™ÿ»Š›ÿ»‹ŸÿºŒ£ÿ»Œ£ÿ»‹¢ÿ»‹¢ÿ»‹¡ÿ»‹¡ÿ¼‹ ÿ¼ŠŸÿ¼‰œÿ¼‰šÿ¼ˆ™ÿ¼Š›ÿ¼Š�ÿ¼Š�ÿ¼Šœÿ¼‰šÿ½ˆ–ÿ½ˆ“ÿ¼ˆ“ÿ¼ˆ”ÿ¼ˆ•ÿ½ˆ—ÿ¼ˆ™ÿ»ˆ›ÿ»ˆœÿ»ˆšÿº†”ÿº„�ÿ¹ƒŽÿ¸‚�ÿ·�Œÿ·€‹ÿµ�ÿµ€‘ÿµ�’ÿ¶€�ÿ¶€‹ÿ·‡ÿ¸…ÿ¹…ÿ¹€…ÿ¹�†ÿ¹�ˆÿ¹‚‰ÿ¹‚Šÿ¹‚Šÿº�Šÿ¹�‰ÿ¸€ˆÿ¸€‡ÿ¸€ˆÿ·ˆÿ¶~‰ÿµ~‹ÿ´�ÿ³€”ÿ±€˜ÿ°€›ÿ°›ÿ¯šÿ¯~™ÿ¯~–ÿ°}“ÿ°|�ÿ±{Œÿ±{‰ÿ²z†ÿ³zƒÿ´z‚ÿ³z�ÿ²y€ÿ³y‚ÿ±x‚ÿ±x�ÿ±w€ÿ±w€ÿ±x‚ÿ°xƒÿ®w…ÿ­w…ÿ¬v†ÿ¬v‡ÿ«u†ÿªt†ÿªt†ÿ©t‡ÿ©s‡ÿ§r†ÿ¦r…ÿ¥qƒÿ¥p€ÿ¥pÿ¥o}ÿ¥nzÿ¥nyÿ¦nyÿ¦o{ÿ¥p}ÿ¥p€ÿ¥q‚ÿ¦qƒÿ§q�ÿ¦qÿ¥o|ÿ£m|ÿ£n}ÿ¢l}ÿ¡k{ÿ kyÿŸjyÿžizÿ�j|ÿœi}ÿ›h|ÿšg{ÿ™f|ÿ™gÿ˜h‚ÿ˜hƒÿ—gƒÿ–f�ÿ–fÿ•e}ÿ”dzÿ•cyÿ•cxÿ•cwÿ•buÿ”buÿ“byÿ‘c~ÿ�d„ÿ�dˆÿ�e‹ÿ�fŽÿ‘fŽÿ’f‰ÿ“e…ÿ“e�ÿ”e€ÿ“d‚ÿ”e„ÿ–f‚ÿ—f€ÿ˜f}ÿ™ezÿšdvÿšcqÿšcmÿšblÿ™alÿ˜bnÿ˜boÿ˜bnÿ™bnÿšboÿ›boÿšbnÿšanÿšbmÿ™bmÿ˜bqÿ—cvÿ–cyÿ”c{ÿ“b|ÿ“bzÿ”azÿ“azÿ“azÿ’azÿ“azÿ’a|ÿ‘a|ÿ‘a{ÿ�`zÿ�_yÿ�^wÿ�]sÿ�\pÿ�\mÿ�[jÿ�[hÿ�[fÿ�ZeÿŽYeÿ­‡­ÿ­ˆ±ÿ¬‰¶ÿ«‹½ÿ«ŒÄÿ«ŒÆÿ¬‹Âÿ¬Šºÿ­‰µÿ­‰´ÿ¬ˆ³ÿ¬‡±ÿ¬†°ÿ¬†¯ÿ«…®ÿ«…­ÿ«…®ÿª„­ÿª„¬ÿª„¬ÿ©…°ÿ©†²ÿª†²ÿ¬†°ÿ­†¯ÿ¬†®ÿ«…®ÿ«…®ÿª„®ÿ©„­ÿ¨ƒ¬ÿ§ƒ­ÿ§‚¬ÿ¨‚ªÿª‚©ÿ«ƒ§ÿ­ƒ¦ÿ¯„¤ÿ±„¢ÿ²… ÿ³…žÿµ…œÿµ†›ÿµ†™ÿ¶…˜ÿ¶†˜ÿ·‡šÿ·‡›ÿ·‡›ÿ·‡œÿ¶‡�ÿ¶†žÿµ†Ÿÿ´† ÿ´† ÿ´‡¡ÿµˆ¡ÿ¶ˆ¡ÿ¸‰ ÿ¹‰�ÿ»Šœÿ»Šœÿ»‹žÿ»‹¡ÿ»Œ£ÿ¼�¦ÿ»Œ¥ÿ»Œ¤ÿ»Œ£ÿ»Œ£ÿ¼‹¡ÿ¼‹Ÿÿ¼Š�ÿ¼Š›ÿ¼‰›ÿ»Šœÿ»‹Ÿÿ»‹ ÿ»Š ÿ»Šžÿ¼‰›ÿ¼‰™ÿ»‰™ÿ»‰šÿ»‰šÿ¼‰›ÿ¼‰�ÿ»‰�ÿ»‰œÿ¼ˆ™ÿ»†”ÿº†‘ÿº…�ÿº„�ÿº‚‹ÿ¹‚Šÿ¸�Žÿ¶�’ÿ¶�’ÿ¶�Žÿ¶Šÿ¶†ÿ¸…ÿ¹€†ÿº�†ÿº‚†ÿº‚ˆÿ¹‚Šÿ¹‚‹ÿ¹�‹ÿº‚‹ÿ¹�Šÿ¸€‰ÿ¹€ˆÿ¹€ˆÿ¸€ˆÿ·Šÿ¶€Žÿ´�’ÿ´�–ÿ²�šÿ±€›ÿ±€›ÿ°€›ÿ°šÿ¯˜ÿ°~•ÿ°|’ÿ±|�ÿ±|�ÿ±{‹ÿ±{ˆÿ³z„ÿ³z‚ÿ³z�ÿ³y‚ÿ²x�ÿ²x€ÿ²x€ÿ±x�ÿ°x‚ÿ¯w‚ÿ¯wƒÿ­w„ÿ¬v…ÿ¬v†ÿ«u…ÿ«u„ÿªt„ÿªt…ÿ¨t‡ÿ§s†ÿ¦r†ÿ¦q…ÿ¦q‚ÿ¤p�ÿ¤oÿ¤o~ÿ¤o|ÿ¥o}ÿ¥p~ÿ¥pÿ¥q‚ÿ¥r…ÿ¦r†ÿ§s„ÿ§r�ÿ¦p}ÿ¤n|ÿ£m~ÿ¢m~ÿ¡l|ÿ kyÿŸjyÿžizÿ�i}ÿ›i~ÿši~ÿšh}ÿ˜g~ÿ˜h‚ÿ—h…ÿ—h‡ÿ–i‡ÿ–h…ÿ•g„ÿ”f�ÿ”eÿ•d}ÿ•d{ÿ”cyÿ•bwÿ”bwÿ’byÿ�c~ÿ�d†ÿŽd‹ÿ�f�ÿ�g‘ÿ‘h�ÿ’f‹ÿ’f‡ÿ’e„ÿ“e‚ÿ“d�ÿ•e‚ÿ–f€ÿ˜f|ÿ™exÿšduÿšcrÿšcnÿšbkÿšbkÿšblÿ™bmÿ™bnÿ™bnÿ™bnÿšbnÿšanÿšamÿšamÿšbmÿ™bmÿ˜boÿ—cuÿ–czÿ•c}ÿ”cÿ”c~ÿ”c}ÿ”c~ÿ“b~ÿ“b~ÿ“b~ÿ’bÿ‘bÿ‘a~ÿ�a|ÿ�`zÿ�_xÿ�^uÿ�]sÿ�\pÿ�\lÿ‘[gÿ‘[eÿ�[eÿ�Zfÿ¬ˆ°ÿ­‰´ÿ­‹»ÿ¬�Ãÿ«�Êÿ«�Ëÿ­�Åÿ®Œ»ÿ®‹µÿ®Šµÿ®Š¶ÿ®Š¶ÿ­‰µÿ­ˆ´ÿ¬‡²ÿ«‡°ÿª†¯ÿª…®ÿª„­ÿ©„¬ÿ©…¯ÿ©†±ÿ©†²ÿª†±ÿ¬†°ÿ¬†®ÿ¬…­ÿ¬…­ÿ«†¯ÿ«…¯ÿª…®ÿ©„­ÿ¨„­ÿ¨ƒ¬ÿ©ƒ«ÿªƒªÿ«ƒªÿ­„©ÿ®…¦ÿ°…¢ÿ²… ÿ´†Ÿÿµ†œÿµ†™ÿ¶†–ÿ·†–ÿ·‡šÿ·‡�ÿ·ˆŸÿ¶ˆ¡ÿ¶ˆ¡ÿµ‡¡ÿ´‡¢ÿ³†¢ÿ²†£ÿ²†¤ÿ²‡¥ÿ³ˆ¦ÿ´ˆ¥ÿ¶‰£ÿ¹‰Ÿÿ¹ŠŸÿº‹¢ÿ»‹¤ÿ»Œ¥ÿ»�§ÿ»�¥ÿ»Œ¤ÿ»Œ£ÿ»Œ¢ÿ¼‹ ÿ¼‹�ÿ½‹œÿ¼Šœÿ¼Šœÿ¼Š�ÿ»‹ ÿº‹¢ÿº‹£ÿ»‹£ÿ»Š ÿºŠŸÿº‹Ÿÿ»ŠžÿºŠžÿ»Šžÿ¼Šžÿ¼Šžÿ¼‰›ÿ¼‰—ÿ¼‡’ÿ¼‡�ÿ¼†Œÿ¼…ˆÿ¼„†ÿ¼„…ÿºƒŠÿ¹ƒ�ÿ¸ƒŽÿ¸‚‹ÿ·€‡ÿ·€…ÿ¹€†ÿº�‡ÿº‚‡ÿº‚‡ÿº‚‰ÿºƒ‹ÿ¹ƒŒÿ¹‚Œÿ¹‚‹ÿ¸‚‹ÿ¸�Šÿ¹�‰ÿ¹�Šÿ¸�‹ÿ·�Žÿ¶�‘ÿµ�”ÿ´‚˜ÿ³�šÿ²€šÿ²€šÿ±€™ÿ°€™ÿ±€–ÿ±~“ÿ±}‘ÿ±}�ÿ±}�ÿ°|Žÿ°{Œÿ±{ˆÿ³z…ÿ³zƒÿ³y‚ÿ²x�ÿ²x�ÿ±y�ÿ°x‚ÿ°xƒÿ¯wƒÿ®wƒÿ­wƒÿ¬v„ÿ¬v„ÿ¬u‚ÿ«u�ÿ«u‚ÿªtƒÿ¨t…ÿ¨t…ÿ§s†ÿ¦r„ÿ¥q‚ÿ¤o�ÿ¤o€ÿ£n€ÿ£o€ÿ£p�ÿ¤p�ÿ¥pƒÿ¥q…ÿ¥r‡ÿ¦s‰ÿ§t‡ÿ§sƒÿ§q~ÿ¥o|ÿ£m}ÿ¢m~ÿ¡m}ÿ k{ÿžjyÿ�i{ÿœi}ÿ›iÿ™iÿ˜g€ÿ—g‚ÿ–h†ÿ–hŠÿ–i‹ÿ–jŠÿ–i‰ÿ•iˆÿ•h†ÿ•fƒÿ•e€ÿ•e~ÿ”d{ÿ”czÿ“bzÿ’c|ÿ�c€ÿ�dˆÿŽf�ÿŽg’ÿ�h“ÿ‘h‘ÿ’fŒÿ’f‰ÿ’f†ÿ’eƒÿ”e�ÿ–fÿ˜f{ÿ™evÿ™dsÿšdrÿšcpÿšcmÿ›blÿ›bkÿšblÿšbmÿ™bmÿšbnÿšbnÿšbnÿ™bnÿ™anÿ™boÿ™bnÿ˜bnÿ˜boÿ—cuÿ–czÿ”cÿ”d‚ÿ”d‚ÿ”d�ÿ“d�ÿ”d�ÿ”c€ÿ“c€ÿ“c€ÿ’b€ÿ‘b€ÿ�a~ÿ�`{ÿ�_yÿŽ^xÿ�^vÿ�]rÿ‘\mÿ‘[gÿ�Zdÿ�[dÿ�[fÿ­‰³ÿ®‹¸ÿ®�Àÿ­ŽÇÿ«�Ìÿ«‘Íÿ­ŽÄÿ¯Œºÿ°Œ´ÿ°Œµÿ¯‹¸ÿ¯Œ¸ÿ®‹¸ÿ®Š¸ÿ­‰¹ÿ«ˆ·ÿªˆ¶ÿª‡³ÿª…¯ÿª„­ÿ©…®ÿ©…¯ÿ©„¯ÿ©…¯ÿª†°ÿ«†®ÿ¬…¬ÿ¬…¬ÿ«†¯ÿ«†°ÿ«…¯ÿª…­ÿ©„­ÿ©ƒ¬ÿ©ƒ«ÿ©„¬ÿª„­ÿ«„¬ÿ­…©ÿ®…¤ÿ°…¢ÿ²†¡ÿ³†žÿµ†šÿ¶†—ÿ·†—ÿ·‡›ÿ·‡žÿ¶ˆ ÿ¶‰£ÿµˆ¢ÿ´ˆ£ÿ´ˆ¤ÿ³‡¥ÿ²‡¦ÿ±‡§ÿ²‡©ÿ²ˆ«ÿ²ˆªÿ³ˆ¨ÿµ‡£ÿ¶‰£ÿ¸Š¥ÿ¹‹§ÿºŒ¨ÿºŒ¦ÿºŒ¤ÿ»Œ£ÿ»Œ£ÿ»Œ¡ÿ¼‹žÿ½‹›ÿ½Ššÿ½Š›ÿ»Šœÿ¼ŠŸÿ»‹¢ÿº‹¥ÿºŒ¦ÿºŒ¦ÿº‹¤ÿ¹‹¤ÿº‹£ÿº‹¢ÿºŠ ÿºŠŸÿ»Šžÿ¼Š�ÿ¼‰™ÿ¼‰•ÿ½ˆ‘ÿ¾‡�ÿ¾†‰ÿ¾…„ÿ¾„‚ÿ¾…‚ÿ½…„ÿ¼„‡ÿ¼„‡ÿ»ƒ†ÿº‚…ÿº‚†ÿº‚‡ÿºƒˆÿºƒˆÿºƒˆÿ»ƒŠÿ»„Œÿ¹„�ÿ¹ƒ�ÿ¸ƒ�ÿ¸‚�ÿ¸‚Œÿ¸‚Œÿ¹‚Œÿ¸‚Žÿ·‚‘ÿµ‚“ÿµ‚–ÿ´‚™ÿ³�šÿ³�šÿ³�šÿ²�™ÿ±€—ÿ³“ÿ³~�ÿ²~Žÿ²~�ÿ²~�ÿ±|�ÿ°{Žÿ±{Œÿ²{‰ÿ³z†ÿ²y„ÿ²y‚ÿ±x‚ÿ°yƒÿ¯y„ÿ¯x…ÿ®x…ÿ­w„ÿ­w„ÿ­wƒÿ¬v‚ÿ¬u€ÿ¬u€ÿ«u€ÿ«u�ÿ©t‚ÿ¨tƒÿ¨sƒÿ¦r‚ÿ¤q€ÿ¤o€ÿ¤o€ÿ¢n�ÿ¢oƒÿ¢p„ÿ£p…ÿ£p†ÿ£qˆÿ¤sŠÿ¦t‹ÿ§t‰ÿ¨s„ÿ§qÿ¥o|ÿ£n|ÿ¢m}ÿ¡m}ÿŸk|ÿ�i{ÿ›h|ÿšhÿši€ÿ˜i�ÿ—g‚ÿ–g†ÿ•h‹ÿ”iŽÿ•i�ÿ•jŽÿ•j�ÿ•iŒÿ–j‹ÿ–h‡ÿ–g„ÿ•f�ÿ”eÿ“d}ÿ’c~ÿ‘d€ÿ�d…ÿ�e‹ÿŽg“ÿ�h•ÿŽh”ÿ‘h‘ÿ‘gŽÿ’f‹ÿ’e‡ÿ“e„ÿ”e€ÿ—f|ÿ™evÿšdrÿšdqÿšdqÿšcpÿ›coÿ›cnÿ›bmÿ›bmÿšbmÿšbnÿ›cnÿšcoÿ™bpÿ™boÿ™bpÿ˜bpÿ˜boÿ˜aoÿ˜bpÿ—cuÿ•czÿ”d€ÿ•d†ÿ”e†ÿ“d„ÿ“dƒÿ”d‚ÿ”d�ÿ”c€ÿ”c€ÿ’c�ÿ‘b‚ÿ�a€ÿ�`}ÿ�`|ÿ�_zÿ�^xÿ�^uÿ�\oÿ�[iÿ�Zeÿ‘[eÿ‘[fÿ°‹¶ÿ¯Œ¼ÿ®ŽÂÿ®�Æÿ®�Éÿ­�Êÿ¯�Áÿ±�·ÿ²Œ²ÿ²�µÿ°Œ¸ÿ°�¸ÿ°Œ¸ÿ¯‹¸ÿ®‹¼ÿ¬‹Àÿ«‹Àÿ«Š»ÿ«ˆ´ÿ«‡°ÿ«†¯ÿª…®ÿª„­ÿ©„®ÿª…¯ÿª…¯ÿ«…­ÿ«…­ÿ¬†®ÿ«†°ÿ«†¯ÿª†¯ÿª…¯ÿ©„­ÿªƒ«ÿ¨ƒ­ÿ©„¯ÿª„°ÿ«„­ÿ¬„¨ÿ®…¥ÿ°…£ÿ²†¡ÿ³†Ÿÿµ†�ÿ¶‡›ÿ·ˆžÿ¶ˆ¡ÿ¶‰¢ÿ¶‰¢ÿµˆ¢ÿµˆ£ÿ´ˆ¥ÿ´ˆ§ÿ³‰©ÿ´‰ªÿ³‰¬ÿ³‰®ÿ²‰®ÿ±‡¬ÿ²‡©ÿ³ˆ¨ÿµŠ¨ÿ¶‹©ÿ·Œ©ÿ¸‹¦ÿ¹‹£ÿº‹£ÿ»Œ£ÿ¼Œ¢ÿ¼‹žÿ½Š›ÿ½‹šÿ½‹›ÿ¼‹�ÿ»‹¢ÿºŒ¥ÿºŒ¨ÿºŒ©ÿ¹Œ©ÿ¹Œ¨ÿ¹Œ¨ÿ¹Œ§ÿ¹Œ¥ÿº‹£ÿºŠ¡ÿ»Šžÿ¼Š›ÿ¼‰˜ÿ½‰–ÿ½ˆ“ÿ¾ˆ�ÿ¾‡‹ÿ¿††ÿ¿…„ÿÀ…‚ÿ¿…‚ÿ¾…‚ÿ¾†ƒÿ½…ƒÿ½„ƒÿ½„†ÿ¼…ˆÿ»„Šÿ»„Šÿ»„‹ÿ¼„�ÿ»„Žÿ»„�ÿº„�ÿ¹„�ÿ¹ƒ�ÿ¹ƒŽÿ¹‚�ÿ¸‚Žÿ·‚�ÿ¶‚“ÿµ‚•ÿµ‚˜ÿ´‚›ÿ³��ÿ³‚žÿ²‚žÿ²�œÿ²€˜ÿ´~‘ÿ´~Œÿ´~Œÿ´~Žÿ´~Žÿ³|Œÿ²|Œÿ±|Œÿ±|Œÿ±{Šÿ²zˆÿ²y†ÿ±y…ÿ°y†ÿ¯y‡ÿ¯x‡ÿ®x‡ÿ­w†ÿ­v„ÿ¬vƒÿ¬u�ÿ¬u€ÿ¬tÿ¬tÿ«tÿªtÿ©sÿ§r€ÿ¦q€ÿ¥p€ÿ¤p€ÿ¤o�ÿ£oƒÿ¡o…ÿ¡o†ÿ o†ÿ¡p‰ÿ¢rŒÿ£sŒÿ¥s‹ÿ¦sˆÿ§sƒÿ¦q~ÿ¥o{ÿ¤n|ÿ¢m|ÿ¡l|ÿŸk}ÿ�j}ÿ›iÿ™i�ÿ˜iƒÿ—i„ÿ–h…ÿ•hˆÿ“iŽÿ’j’ÿ’j”ÿ“j“ÿ”j“ÿ”j’ÿ•k�ÿ•k�ÿ•i‰ÿ–h†ÿ”fƒÿ“e�ÿ‘e‚ÿ�d…ÿ�eŠÿ�g‘ÿ�h–ÿŽh—ÿŽh•ÿ�h’ÿ‘g�ÿ’fŒÿ’f‰ÿ“e…ÿ•e€ÿ˜ezÿ™duÿ›erÿ›eqÿšdqÿ›dqÿšdqÿšcpÿšcpÿšcpÿšcoÿ›coÿšcpÿšcqÿ™cqÿ™bpÿ™boÿ™boÿ˜boÿ˜bpÿ˜brÿ—cvÿ–d{ÿ•d‚ÿ•eˆÿ”eˆÿ”d…ÿ”dƒÿ”d‚ÿ”d�ÿ”b€ÿ”c�ÿ“c‚ÿ’b‚ÿ‘a�ÿ‘aÿ�a}ÿ�`|ÿ�_zÿ�^wÿ�]rÿ‘\mÿ’\hÿ’[gÿ’[hÿ°�¹ÿ°Ž½ÿ¯ŽÀÿ¯�Áÿ°�Áÿ¯�Áÿ±�½ÿ³�µÿ´�²ÿ³Žµÿ²�¸ÿ²Ž·ÿ²�´ÿ±Œ³ÿ°Œ¸ÿ®Œ¿ÿ­ŒÁÿ¬ŒÀÿ¬‹¼ÿ­Š¸ÿ­‰´ÿ¬‡°ÿ¬†®ÿ¬…­ÿ¬…®ÿ¬†®ÿ«…¯ÿ«†¯ÿ«†¯ÿ«†¯ÿ«‡°ÿ«‡²ÿ«†²ÿ«†°ÿª†¯ÿ©†°ÿª†²ÿª†³ÿª…±ÿª…­ÿ¬…«ÿ®†¨ÿ¯†§ÿ±†¥ÿ³‡¢ÿ´‡ ÿµ‡ ÿ¶ˆ ÿ·‰ ÿ·‰¡ÿ·ˆ¢ÿ¶‰£ÿµˆ¤ÿ´‰§ÿµŠªÿµŠ«ÿµŠ­ÿ´Š¯ÿ³Š¯ÿ²‰­ÿ±ˆ¬ÿ±ˆ«ÿ³‰«ÿµŠ¬ÿµ‹«ÿ¶‹¨ÿ¸Š¦ÿ¹‹¤ÿ¹‹¤ÿºŒ¤ÿºŒ¢ÿ»‹Ÿÿ½‹œÿ½‹œÿ¼Œ ÿ»�¥ÿº�¨ÿº�ªÿ¹Ž¬ÿ¹�«ÿ¸Œ«ÿ¹�¬ÿ¹�ªÿ¹Œ§ÿºŒ¥ÿº‹£ÿ»ŠŸÿ»Šœÿ¼Ššÿ¼‰™ÿ½Š˜ÿ½‰•ÿ½‡‘ÿ¾†�ÿ¿†‰ÿ¿†…ÿ¿…ƒÿ¿…ƒÿ¿…„ÿ¿†…ÿ¿†„ÿ¿…‡ÿ¾…‰ÿ¼†‹ÿ¼†�ÿ¼†�ÿ¼†�ÿ»…�ÿ»…’ÿ»…’ÿº„‘ÿ¹…�ÿ¹„Žÿ¹ƒŽÿ¸ƒ�ÿ·ƒ’ÿ¶ƒ•ÿµƒ˜ÿ´ƒ›ÿ³ƒ�ÿ³ƒŸÿ²ƒ ÿ²‚ ÿ²‚žÿ³�šÿ³“ÿ´~Žÿ´~ŒÿµŒÿµŠÿµ}ˆÿ´|‡ÿ²|‰ÿ±|‹ÿ°|Œÿ°|Œÿ°z‹ÿ¯zŠÿ¯z‹ÿ®z‹ÿ®z‹ÿ®yŠÿ­x‡ÿ­vƒÿ¬u�ÿ«t�ÿ¬t€ÿ«tÿ«t~ÿªsÿ©s~ÿ¨sÿ§rÿ¦qÿ¦pÿ¥p�ÿ¤p‚ÿ£oƒÿ¢o…ÿ¡o†ÿ pˆÿ¡q‹ÿ¢r�ÿ¢r�ÿ£qŠÿ¥q†ÿ¥r‚ÿ¥q~ÿ¥o|ÿ¤n|ÿ¢m}ÿ¡l}ÿŸk~ÿœjÿši€ÿšjƒÿ™i…ÿ—i†ÿ–j‰ÿ•jŒÿ“j‘ÿ‘k•ÿ‘k—ÿ‘l˜ÿ‘l™ÿ’k˜ÿ“l—ÿ”k”ÿ•k�ÿ–jŒÿ•h‰ÿ“g†ÿ’f†ÿ‘e‰ÿ‘gŽÿ�i”ÿ�i˜ÿŽj˜ÿ�i—ÿ‘i”ÿ‘h�ÿ’g�ÿ’fŠÿ”f‡ÿ—f�ÿ˜ezÿ™evÿ›etÿœesÿ›esÿ›ftÿ›etÿšetÿšesÿšdsÿ›drÿšdqÿšdrÿšdsÿ™csÿ™cqÿ™coÿ™coÿ˜coÿ—bpÿ˜csÿ—dvÿ–d{ÿ–d�ÿ•e†ÿ•e†ÿ•e„ÿ•eƒÿ•e‚ÿ”d�ÿ“c€ÿ“c€ÿ“c€ÿ’bÿ‘a~ÿ‘a}ÿ�`|ÿ�`|ÿ�_{ÿ�^wÿ‘^sÿ’]oÿ’\lÿ’\kÿ’\lÿ°�¹ÿ°�½ÿ±�¿ÿ±�¾ÿ±Ž»ÿ±�ºÿ³�¸ÿ´Ž´ÿ´Ž³ÿ´�·ÿ´�¹ÿ´�·ÿ³Ž²ÿ³Œ®ÿ³‹®ÿ²Œµÿ±Œ¸ÿ°�¼ÿ®ŽÀÿ­�¿ÿ­Œ¼ÿ®‹¹ÿ®Š³ÿ®‡®ÿ­†­ÿ­†­ÿ¬†°ÿ«‡±ÿ«†±ÿ«†±ÿ¬‡²ÿ¬ˆ´ÿ¬ˆµÿ¬ˆ´ÿ«‡²ÿª†±ÿª‡²ÿ©†³ÿ©†³ÿ©†²ÿª†±ÿ«…°ÿ¬…®ÿ®†«ÿ°†¨ÿ±†¤ÿ²‡¢ÿ³‡¡ÿµˆ ÿ¶‰¡ÿ¶ˆ¡ÿ¶ˆ¡ÿµ‡¢ÿ´ˆ¥ÿµ‰¨ÿµŠªÿµŠ«ÿµŠ­ÿ´‹¬ÿ³Š«ÿ´‰«ÿ²‰ªÿ²‰ªÿ³‰¬ÿ´Š­ÿ´‹¬ÿµŠªÿ¶Š¨ÿ·‹§ÿ¸‹¦ÿ¹‹¥ÿº‹£ÿ»‹¡ÿ»Œ¡ÿ»Œ£ÿº�§ÿºŽªÿ¹Ž«ÿ¹�«ÿºŽ«ÿ¹Ž«ÿ¹Ž®ÿ¸Ž­ÿ¸Œ©ÿ¹Œ§ÿ¹‹¥ÿºŠ¡ÿ»Šžÿ»Šœÿ»‰œÿ¼‰œÿ½Ššÿ½‰—ÿ½‰“ÿ¾ˆ�ÿ¿‡‹ÿ¿†ˆÿ¿††ÿ¿††ÿ¿†‡ÿÀ‡‡ÿ¿†ˆÿ¾…‹ÿ½†�ÿ¼‡�ÿ¼†’ÿ¼†’ÿ»†’ÿº…’ÿº…’ÿº…�ÿ¹…�ÿ¹„Žÿ¹„�ÿ¸„’ÿ·„”ÿµ„˜ÿ´„›ÿ³„Ÿÿ²„¡ÿ²„£ÿ²„¢ÿ±ƒ ÿ²‚žÿ²�œÿ²€–ÿ²�ÿ³�ÿµŒÿ¶Šÿµ}‡ÿ´|†ÿ´|‡ÿ²|Šÿ±|Œÿ°{�ÿ¯z�ÿ®zŒÿ­z�ÿ­yŒÿ®y‹ÿ®yŠÿ­x‡ÿ¬wƒÿ¬v‚ÿ«u‚ÿªt€ÿ©tÿ©s~ÿ©s€ÿ©t€ÿ¨s�ÿ§r�ÿ¦q�ÿ¦q€ÿ¦q€ÿ¥q�ÿ£p‚ÿ¢p„ÿ¡p†ÿ pŠÿ q�ÿ q�ÿ¡pŒÿ¢p‰ÿ£p…ÿ¤q‚ÿ¥q€ÿ¥pÿ¤o~ÿ¢m~ÿ¡m€ÿžl‚ÿœkƒÿ›k„ÿ›k†ÿškˆÿ˜kŠÿ–kŒÿ•k�ÿ”k“ÿ’k—ÿ‘l™ÿ‘m›ÿ�l›ÿ�kšÿ’kšÿ“k™ÿ”k–ÿ•k’ÿ•jŽÿ”hŒÿ’gŠÿ‘f‹ÿ‘h�ÿ�j•ÿ�j˜ÿŽj˜ÿ�i—ÿ�i•ÿ‘h‘ÿ’h�ÿ“g‹ÿ•g‰ÿ—g„ÿ—f~ÿ™fzÿšfwÿ›fvÿ›fvÿšfvÿšfvÿšfvÿševÿ™euÿšetÿšesÿ™etÿ™evÿ™duÿ™dsÿšcpÿ™cpÿ˜bqÿ—bqÿ˜bsÿ—cvÿ–cyÿ•d~ÿ–eƒÿ•e„ÿ”e„ÿ”dƒÿ”d‚ÿ“c‚ÿ“d€ÿ“c~ÿ“c|ÿ’b{ÿ’a{ÿ’azÿ‘`zÿ�`zÿ�_xÿ‘_vÿ’^sÿ’^pÿ’^nÿ’]oÿ’]pÿ±�ºÿ²�½ÿ²�¾ÿ³�½ÿ³�ºÿ³�¹ÿ´�¶ÿ´�´ÿ´�´ÿ´‘¸ÿµ‘ºÿµ�¶ÿµ�¯ÿ¶�ªÿ¶Œ©ÿµŒ¬ÿ´Œ­ÿ³�³ÿ±Ž»ÿ¯Ž½ÿ¯Ž½ÿ¯�¾ÿ°�ºÿ°Š³ÿ¯ˆ¯ÿ¯ˆ®ÿ®ˆ°ÿ¬ˆ³ÿ«ˆ´ÿ«ˆ´ÿ¬ˆµÿ¬‰¶ÿ­Š·ÿ­‰¶ÿ¬ˆ´ÿ¬ˆ³ÿ«‡³ÿª‡³ÿ©‡³ÿ©†´ÿ©†´ÿ©†´ÿª…²ÿ¬…¯ÿ­†¬ÿ®†©ÿ¯†¦ÿ°†¤ÿ²‡£ÿ´ˆ£ÿ´ˆ¢ÿµ‡¡ÿµ‡¢ÿ´‡£ÿµˆ¥ÿ¶‰¦ÿ¶‰§ÿ¶Š¨ÿµŠ¨ÿµŠ¨ÿµŠ¨ÿµŠ¨ÿ´‰©ÿ³‰«ÿ³Š®ÿ´‹®ÿ´‹®ÿ´Š¬ÿµ‹«ÿ¶‹ªÿ·‹ªÿ¸Œ¨ÿ¹Œ¦ÿ¹�¦ÿ¹�¨ÿ¹�«ÿ¹Ž­ÿ¹�­ÿº�«ÿºŽ©ÿºŽªÿ¹Ž®ÿ¹Ž®ÿ¹�ªÿ¹Œ§ÿ¹‹¥ÿºŠ¢ÿºŠŸÿ»‰�ÿ»‰�ÿ»‰�ÿ¼Šœÿ½Š™ÿ½Š–ÿ¿‰”ÿ¿ˆ‘ÿ¿ˆ�ÿ¿ˆ‹ÿ¿‡‹ÿ¿‡‹ÿ¿‡‹ÿ¾‡‹ÿ¾†�ÿ½‡�ÿ¼‡’ÿ¼‡”ÿ¼‡”ÿ»†“ÿº…’ÿº…’ÿº…�ÿ¹…Žÿ¹„�ÿ¹„’ÿ¸„•ÿ·„™ÿµ„�ÿ³…¡ÿ³…¤ÿ²…¦ÿ±…¦ÿ±„¤ÿ±ƒ¡ÿ²‚žÿ²‚œÿ²�—ÿ²€’ÿ³�ÿµ�ÿµŒÿµ~‰ÿ´}ˆÿ´}‰ÿ³}‹ÿ²|Œÿ±{�ÿ¯{Žÿ®{Žÿ­z�ÿ¬yŽÿ­yŒÿ­xŠÿ­x‡ÿ¬w…ÿ¬v„ÿ«vƒÿªt�ÿ©t€ÿ¨s�ÿ©t‚ÿ¨s‚ÿ¨sƒÿ¨rƒÿ§rƒÿ§r‚ÿ¦r�ÿ¥q�ÿ¤q�ÿ£p‚ÿ¢p…ÿ p‰ÿ p�ÿŸpŒÿŸo‰ÿ o‡ÿ¡o„ÿ¢pƒÿ£p‚ÿ£p�ÿ£o�ÿ¢n‚ÿ n„ÿžm†ÿ�m‡ÿœm‡ÿœmˆÿ›mŠÿ™lŒÿ—lŽÿ–l‘ÿ•l”ÿ“l–ÿ’l—ÿ’l™ÿ‘k™ÿ‘k™ÿ‘kšÿ’kšÿ“l—ÿ”k•ÿ”k’ÿ“i�ÿ’hŽÿ‘h�ÿ�i’ÿ�j—ÿ�j˜ÿ�i˜ÿ�i—ÿ�i•ÿ‘h’ÿ’hŽÿ”g�ÿ•g‹ÿ—h‡ÿ˜g�ÿ™g~ÿšf{ÿšgyÿ›gyÿ›gyÿšgxÿšfxÿ™fxÿšexÿšexÿ™fwÿšfwÿ™ewÿševÿ™dtÿ™cqÿ™cqÿ˜brÿ—bsÿ˜btÿ—cuÿ–cxÿ–d|ÿ•e�ÿ•eƒÿ“dƒÿ“c‚ÿ“c�ÿ“c€ÿ“c~ÿ”bzÿ”bxÿ“axÿ’axÿ’axÿ’axÿ‘`xÿ‘_wÿ‘_vÿ‘_tÿ’^rÿ’^qÿ’_rÿ’_tÿ³�»ÿ³‘½ÿ³‘½ÿ´‘¼ÿ´�»ÿµ‘¹ÿµ‘·ÿµ‘µÿµ‘·ÿ´‘¹ÿµ‘¹ÿ·�´ÿ¸�­ÿ¸Ž©ÿ¸�¨ÿ·Œ§ÿ·Œ¦ÿ¶Œ«ÿ´�³ÿ³Ž¸ÿ±Ž¸ÿ±�½ÿ±�¼ÿ²�·ÿ³Œ³ÿ²‹°ÿ°Š±ÿ®Š³ÿ­Šµÿ¬‰¶ÿ¬ˆ·ÿ¬‰¸ÿ¬Š¸ÿ­Š¶ÿ®Šµÿ­‰µÿ­ˆ´ÿ«‡²ÿ«‡±ÿª‡²ÿ©†³ÿ©†´ÿª†³ÿ«†±ÿ«†¯ÿ¬†­ÿ­…«ÿ®†ªÿ¯‡©ÿ±‡¨ÿ²‡¦ÿ³‡¤ÿ³‡£ÿ³‡£ÿ´‡£ÿµˆ£ÿ¶‰£ÿ¶‰¤ÿ¶Š¦ÿ¶Š¦ÿ¶‹¥ÿ¶Š¥ÿ¶Š§ÿ¶Šªÿµ‹¬ÿµ‹®ÿµŒ°ÿ´Œ°ÿ´Œ¯ÿ´Œ¯ÿ¶Œ®ÿ·�¬ÿ¸�«ÿ¸�¬ÿ¸�®ÿ¸Ž°ÿ¸Ž±ÿ¹�°ÿºŽ¬ÿ»Ž¨ÿ»Ž¨ÿºŽ­ÿºŽ®ÿº�ªÿ»Œ¥ÿº‹£ÿ»‹¡ÿ»Šžÿ»Š�ÿ»Š�ÿ»Šžÿ¼Šœÿ½Ššÿ¾Š—ÿ¿Š—ÿ¾Š•ÿ¿‰“ÿ¿ˆ‘ÿ¿ˆ�ÿ¿ˆ�ÿ¾‡�ÿ½ˆ�ÿ½ˆ‘ÿ¼ˆ“ÿ¼ˆ•ÿ¼ˆ–ÿ¼ˆ•ÿ¼‡”ÿ»†“ÿº…’ÿ¹…�ÿº…�ÿº„‘ÿ¹„•ÿ·…šÿ¶…Ÿÿ´†£ÿ³†§ÿ±†©ÿ±†©ÿ±†©ÿ°…§ÿ±„£ÿ±ƒŸÿ²‚œÿ³�˜ÿ³�”ÿ´€‘ÿµ€�ÿµŽÿ´~�ÿµ~Œÿ´}Œÿ³}�ÿ³}�ÿ±|Žÿ°{Žÿ®{�ÿ­z�ÿ¬yŽÿ­yŒÿ­xŠÿ­xˆÿ¬x‡ÿ«w‡ÿªv…ÿªu„ÿ©tƒÿ©t„ÿ¨t…ÿ¨s„ÿ¨s„ÿ¨s„ÿ§s„ÿ§sƒÿ§s‚ÿ¦r�ÿ¦q€ÿ¤q‚ÿ£p…ÿ¡pˆÿŸo‹ÿžoŠÿžn‡ÿŸn…ÿŸn„ÿ n„ÿ o„ÿ¡o„ÿ¡o„ÿ¡o…ÿ o‡ÿžn‰ÿ�n‰ÿœn‰ÿ�nŠÿœm‹ÿšm�ÿ˜m�ÿ—m’ÿ–m”ÿ•l“ÿ”k”ÿ”k”ÿ’k”ÿ’k•ÿ’k—ÿ“l—ÿ“l–ÿ“l–ÿ”k”ÿ”k”ÿ“j“ÿ‘i“ÿ�i•ÿ�j˜ÿ�j˜ÿ�i—ÿ�i—ÿ�i–ÿ‘h“ÿ’h�ÿ“h�ÿ•hŽÿ—h‰ÿ™h…ÿ™h�ÿšgÿšg}ÿšg|ÿ›h{ÿ›gzÿšfzÿ™fzÿ™e{ÿ™f{ÿ™fzÿšfyÿšfwÿševÿšdsÿ™cqÿ˜crÿ˜crÿ—bsÿ—ctÿ—cvÿ–cyÿ•d|ÿ•eÿ”e�ÿ“d�ÿ’c€ÿ’c~ÿ“c}ÿ”czÿ”bwÿ”avÿ“avÿ’awÿ’awÿ“awÿ“axÿ’`xÿ’_wÿ’`vÿ’`uÿ“_uÿ“`uÿ“`vÿ´‘¾ÿ´‘¾ÿµ’½ÿµ’»ÿµ‘ºÿµ’¹ÿµ’¸ÿµ’¸ÿµ’¹ÿµ‘»ÿ¶’¸ÿ¸‘´ÿ¹�­ÿ¹�¨ÿº�¨ÿºŽ¦ÿ¹�¤ÿ¸�§ÿ·Ž®ÿµ�´ÿ´Žµÿ³�¹ÿ³�¸ÿµ�´ÿ¶�³ÿµŽ²ÿ³Œ±ÿ²‹²ÿ°‹³ÿ®Šµÿ­Š¶ÿ¬Š¸ÿ¬Š¸ÿ¬Š·ÿ­‰¶ÿ­Š¶ÿ­‰µÿ­ˆ²ÿ¬‡°ÿ¬†¯ÿ¬‡²ÿ«‡´ÿ«‡´ÿ«‡³ÿ«‡²ÿ¬†¯ÿ­†®ÿ­†®ÿ­‡®ÿ­†­ÿ¯†«ÿ°†¨ÿ±‡¦ÿ±‡¦ÿ²‡¦ÿ³ˆ¥ÿ´‰¥ÿµ‰¥ÿ¶Š¦ÿ·‹¦ÿ·‹¤ÿ·Š¤ÿ·‹¥ÿ·‹¨ÿ¶Œªÿ¶Œ¬ÿ¶�®ÿ¶�°ÿµ�°ÿµ�±ÿµ�°ÿ·�¯ÿ·�®ÿ·�°ÿ·Ž³ÿ·�µÿ·�µÿ¸�³ÿ¹Ž®ÿ»Ž©ÿ»�§ÿ»Ž«ÿ»Ž¬ÿ»�¨ÿ¼Œ¢ÿ»Œ ÿ¼‹Ÿÿ¼‹�ÿ¼Šœÿ¼‹œÿ¼‹œÿ¼Š›ÿ½Ššÿ¾‹™ÿ¾‹™ÿ¾‹šÿ¿Š™ÿ¾Š–ÿ¾‰•ÿ¾Š–ÿ¾ˆ–ÿ¼ˆ–ÿ¼‰—ÿ¼‰˜ÿ¼ˆ˜ÿ¼ˆ˜ÿ¼ˆ—ÿ»‡•ÿ»†”ÿ»…”ÿº…“ÿº…’ÿ¹…•ÿ¸…™ÿ¶†Ÿÿ´‡¤ÿ³‡ªÿ²‡­ÿ±‡­ÿ±‡­ÿ°‡«ÿ°†©ÿ°…¦ÿ±ƒ¡ÿ²‚žÿ²‚šÿ³�—ÿ´�”ÿµ€‘ÿµ€�ÿµ�ÿµ�ÿ´�ÿ´~�ÿ³}Žÿ±}Žÿ°|�ÿ¯|�ÿ®{�ÿ­z�ÿ­xŠÿ¬x‰ÿ¬x‰ÿªx‰ÿ©w‰ÿ©vˆÿ©u‡ÿ©u‡ÿ¨t‡ÿ§t†ÿ§s…ÿ§s„ÿ¨s„ÿ¨sƒÿ§sƒÿ§s‚ÿ§r‚ÿ¦r‚ÿ¤r„ÿ£q†ÿ¡pˆÿ oŠÿžo‰ÿžn‡ÿ�m…ÿŸn†ÿžm‡ÿžn†ÿŸn†ÿŸn†ÿ o‡ÿŸoŠÿžo‹ÿ�n‹ÿœnŒÿœo�ÿ›oŽÿšn�ÿ™m’ÿ˜n“ÿ—l’ÿ—k‘ÿ—k�ÿ–j�ÿ”jŽÿ“j�ÿ”k“ÿ”l”ÿ”l•ÿ”l•ÿ”l•ÿ”l–ÿ“k–ÿ‘j–ÿ�j–ÿŽj™ÿŽi˜ÿŽi—ÿ�i–ÿ�i–ÿ‘i”ÿ‘i“ÿ“i’ÿ”i‘ÿ•iŒÿ˜h‡ÿ™h„ÿ™h‚ÿšh�ÿšh€ÿšiÿ›g~ÿšg}ÿ™g}ÿ˜f}ÿ˜g|ÿ™f{ÿ™fyÿ™fxÿševÿ™dsÿ™crÿ˜cqÿ˜cqÿ—brÿ–cuÿ–cwÿ•czÿ•c}ÿ”dÿ”d~ÿ“b~ÿ’b}ÿ‘b{ÿ’bzÿ”bwÿ•bvÿ•auÿ”avÿ“bwÿ“awÿ’axÿ’ayÿ“`zÿ“`yÿ“axÿ”axÿ”awÿ”`vÿ”`vÿ´’¾ÿµ“¾ÿµ’½ÿµ‘»ÿµ’ºÿµ“¹ÿ¶“¸ÿµ’¹ÿµ’»ÿµ“¼ÿ¶’¹ÿ·’µÿ¹�°ÿ¹�­ÿº�­ÿ¹�«ÿ¹Ž§ÿ¹Ž§ÿ¹Ž©ÿ·�­ÿ¶�²ÿ¶�´ÿ¶�²ÿ·Ž­ÿ·�­ÿ¹�±ÿ¸�±ÿ¶�°ÿ´�²ÿ±�³ÿ¯Œµÿ®‹·ÿ­Š·ÿ­Š¸ÿ­Š¸ÿ­‹·ÿ®Š·ÿ®Šµÿ­‰±ÿ¬‡®ÿ­ˆ¯ÿ­‰³ÿ¬ˆ´ÿ¬ˆ³ÿ­ˆ³ÿ­‡°ÿ¬†­ÿ­‡­ÿ­‡®ÿ­‡®ÿ­‡¬ÿ®†«ÿ¯‡ªÿ°‡ªÿ°‡ªÿ±ˆ©ÿ³ˆ¨ÿ³‰§ÿ´‰¦ÿµŠ§ÿ·‹¥ÿ·Š£ÿ·‹¤ÿ·Œ¦ÿ·‹¨ÿ¶Œ©ÿ·�«ÿ·Ž¬ÿ·Ž­ÿ·Ž­ÿ¶�­ÿ·Ž®ÿ·�¯ÿ¶Ž²ÿµ�·ÿ´�¹ÿµ�¸ÿ¶�µÿ¸Ž±ÿ¹Ž«ÿ¹�¨ÿº�¨ÿ»�§ÿ»�¥ÿ»‹ ÿ¼‹žÿ¼‹žÿ¼‹žÿ½Œ�ÿ¼‹œÿ½‹šÿ¾Š™ÿ½Š˜ÿ½‹™ÿ¾‹šÿ½Œ›ÿ¾‹šÿ¾Š™ÿ½Ššÿ¼Š›ÿ¼‰šÿ»‰šÿ»Š›ÿ»Šœÿ»Šœÿ»ˆ›ÿ»ˆ™ÿ»ˆ˜ÿº‡—ÿ¹†—ÿº†—ÿ¹…—ÿ¸…šÿ·† ÿµˆ¦ÿ³ˆ«ÿ²ˆ¯ÿ±ˆ±ÿ°ˆ°ÿ°‡®ÿ°‡¬ÿ±†©ÿ±…¥ÿ±„¢ÿ±ƒžÿ²‚›ÿ³ƒ™ÿ³�–ÿ´€“ÿ´€’ÿµ€’ÿ´�ÿ´�ÿ³~�ÿ²}Žÿ±}Žÿ°|�ÿ°|�ÿ¯|Žÿ®{‹ÿ­xˆÿ¬x‰ÿ«x‰ÿªxŠÿ©w‹ÿ¨v‹ÿ¨u‰ÿ¨u‰ÿ¨uˆÿ§t‡ÿ¦s…ÿ¦s„ÿ¦s„ÿ§r„ÿ¦s„ÿ¦r„ÿ¦rƒÿ¦r„ÿ¤r‡ÿ¢q‰ÿ¡qŠÿ pŠÿŸoŠÿžn‰ÿžo‰ÿžnŠÿžnŠÿžn‰ÿ�nˆÿžnˆÿžo‰ÿžoŒÿžoŽÿœp�ÿ›p‘ÿœp’ÿ›p“ÿšo“ÿ™n”ÿ™m“ÿ—l�ÿ—k�ÿ—kŒÿ—k�ÿ–jŒÿ”jŒÿ•jŽÿ•k�ÿ•k’ÿ”l“ÿ“l•ÿ”l—ÿ“l–ÿ‘k–ÿ�j—ÿ�j™ÿŽj—ÿ�j–ÿ�j–ÿ�j–ÿ�i•ÿ‘j•ÿ“k•ÿ“j“ÿ”j�ÿ–i‹ÿ—iˆÿ˜i†ÿ˜i„ÿ™i„ÿšiƒÿšh�ÿ™gÿ™gÿ˜gÿ™gÿ˜f}ÿ˜f{ÿ˜exÿ˜evÿ˜duÿ˜dsÿ˜crÿ˜cqÿ—crÿ–cuÿ•cxÿ•c{ÿ”d}ÿ”d~ÿ’b|ÿ‘a{ÿ‘a{ÿ‘azÿ’bxÿ“bwÿ”bvÿ•avÿ”awÿ“bwÿ“byÿ“b{ÿ“b|ÿ’b|ÿ’b|ÿ”a{ÿ”b{ÿ”byÿ”awÿ”avÿ´•Áÿµ•Áÿ¶”¿ÿ¶”¼ÿ¶“»ÿ¶”ºÿ¶“ºÿ¶”¼ÿ¶”¿ÿ¶”¿ÿ·“¼ÿ·“ºÿ¸“¹ÿ¹“·ÿ¹“´ÿº’¯ÿ»‘«ÿ»�©ÿº�ªÿ¹�«ÿ¸‘¯ÿ¸�±ÿ¸�®ÿ¸Ž©ÿ¹Ž¦ÿº�ªÿº�¬ÿ¹‘­ÿ¸�®ÿ·Ž°ÿ´Ž³ÿ²�µÿ°Œ·ÿ¯Œ¸ÿ®‹¹ÿ®‹¸ÿ®‹¸ÿ®‹¶ÿ®Š³ÿ®‰°ÿ¯‰¯ÿ®‰±ÿ­‰³ÿ­‰´ÿ¬‰µÿ¬ˆ²ÿ­‡¯ÿ­‡®ÿ®‡¯ÿ­ˆ°ÿ­‡°ÿ®‡¯ÿ®ˆ¯ÿ®ˆ°ÿ®‡¯ÿ¯ˆ­ÿ±ˆ«ÿ²‰ªÿ³‰©ÿ´Š©ÿµŠ§ÿµŠ¦ÿ¶Š¦ÿ¶‹¦ÿ¶‹§ÿ¶Œ©ÿ·�ªÿ·Ž«ÿ¸Ž«ÿ¸Ž«ÿ¸Ž«ÿ¸Ž¬ÿ¸Ž®ÿ·Ž²ÿµŽ·ÿ´�¹ÿµ�¹ÿ¶�¸ÿ·�´ÿ¸�¯ÿ¹Žªÿº�§ÿ»�¥ÿ»Œ£ÿ»Œ ÿ»‹Ÿÿ¼‹Ÿÿ½ŒŸÿ½Œžÿ½Œœÿ½‹™ÿ¾‹˜ÿ¾Š˜ÿ½Š™ÿ½Ššÿ½‹›ÿ½‹šÿ½‹œÿ¼‹žÿ¼‹ ÿ»‹Ÿÿ»ŠŸÿ»ŠŸÿ»‹ ÿ»‹¡ÿºŠŸÿ»ˆ�ÿ»ˆ›ÿºˆ›ÿº‡›ÿ¹‡›ÿ¸†�ÿ·†¡ÿµ‡¦ÿ³ˆ¬ÿ²ˆ°ÿ±ˆ³ÿ°ˆ³ÿ°ˆ°ÿ±ˆ­ÿ±‡©ÿ²†¥ÿ²…¢ÿ²ƒŸÿ³‚œÿ³ƒšÿ´ƒ™ÿ³‚˜ÿ³�•ÿ³€“ÿ´€“ÿ´‘ÿ´�ÿ³�ÿ²~�ÿ±~�ÿ±}�ÿ±}�ÿ±|Œÿ¯{†ÿ¯y…ÿ®x‡ÿ¬xˆÿ«xŠÿªwŒÿ©v‹ÿ©uŠÿ¨u‰ÿ¨u‰ÿ§t‰ÿ¦t‡ÿ¥t‡ÿ¦s‡ÿ¦s‡ÿ¦s†ÿ¥s…ÿ¦s…ÿ¦s‡ÿ¤r‰ÿ¢r‹ÿ¢r�ÿ q�ÿŸp�ÿŸpŒÿŸpŒÿŸpŒÿŸoŒÿŸoŠÿŸo‰ÿŸoŠÿžpŒÿ�p�ÿœp‘ÿ›p”ÿ›q—ÿ›q™ÿ›q™ÿ›q˜ÿšp–ÿšn“ÿ™l�ÿ˜k‹ÿ˜k‹ÿ˜kŒÿ—k‹ÿ–jŠÿ–j‹ÿ•j�ÿ”j�ÿ“k‘ÿ“k”ÿ“l–ÿ’l—ÿ’l—ÿ‘k˜ÿ�k˜ÿ�j—ÿ�j—ÿ�j—ÿ‘j—ÿ�j—ÿ‘k—ÿ“k—ÿ“k•ÿ”k“ÿ•j�ÿ–j�ÿ—jŠÿ—jˆÿ˜jˆÿ™j‡ÿ™i„ÿ˜h‚ÿ˜h‚ÿ˜hƒÿ˜hƒÿ˜h�ÿ˜g~ÿ˜f{ÿ˜eyÿ˜ewÿ˜duÿ˜csÿ—crÿ—csÿ–cuÿ•cxÿ“c{ÿ“c}ÿ’b}ÿ‘a|ÿ�a{ÿ‘a{ÿ’azÿ’byÿ“bxÿ“bxÿ”ayÿ“bzÿ“bzÿ“c}ÿ“cÿ“cÿ“c~ÿ“c}ÿ”c}ÿ”c}ÿ”c|ÿ”bzÿ”bzÿ´–Äÿ´–Ãÿ¶–Àÿ·•¾ÿ·”¼ÿ·”ºÿ·”ºÿ·•¼ÿ·•¿ÿ·•¿ÿ·”¾ÿ·”½ÿ·•½ÿ¸”¼ÿ¹”·ÿº“±ÿ»’­ÿ»’¬ÿ»‘«ÿº�¬ÿº‘­ÿ¹‘¯ÿ¹�­ÿº�¨ÿº�¤ÿº�¦ÿ»�©ÿ»‘ªÿ»�«ÿº�¬ÿ¸�°ÿ·�²ÿµ�´ÿ³Ž¶ÿ±�¸ÿ°�¹ÿ¯Œ¸ÿ¯‹¶ÿ¯‹´ÿ°Š²ÿ°Š°ÿ°Š°ÿ¯Š²ÿ®‰´ÿ­‰µÿ­‰´ÿ­‰²ÿ®ˆ±ÿ­ˆ°ÿ­ˆ±ÿ®ˆ²ÿ¯ˆ²ÿ®‰³ÿ­‰³ÿ­ˆ²ÿ­ˆ°ÿ¯‰¯ÿ°‰®ÿ±‰­ÿ²‰«ÿ²‰©ÿ´‰©ÿ´Š©ÿµŠ©ÿµŠ©ÿµ‹«ÿ¶Œ¬ÿ·�¬ÿ·�«ÿ¸Žªÿ¸Žªÿ¸�«ÿ¸Ž­ÿ·Ž°ÿ¶Ž´ÿ´Ž·ÿ´�¸ÿ¶�¸ÿ·�¶ÿ¸�²ÿ¹�®ÿºŽªÿº�¦ÿ»Œ£ÿ»Œ¡ÿ»Œ¡ÿ»‹¡ÿ»Œ¡ÿ¼Œ ÿ½Œžÿ½Œšÿ¾Œ™ÿ¾‹™ÿ½‹šÿ¼Š›ÿ¼Š›ÿ¼Šœÿ¼Œžÿ¼Œ¡ÿ»Œ¢ÿ»Œ¢ÿ»‹¡ÿº‹¢ÿºŒ¤ÿº‹¥ÿºŠ£ÿº‰ ÿº‰žÿº‰žÿ¹ˆŸÿ¸ˆ ÿ·ˆ¢ÿ¶ˆ¦ÿ´ˆ«ÿ²‰¯ÿ²‰²ÿ±ˆ³ÿ±ˆ±ÿ±ˆ®ÿ²‡ªÿ²‡¦ÿ³…£ÿ³…¡ÿ´„�ÿ´ƒ™ÿ´‚˜ÿ´ƒšÿ´ƒšÿ³‚˜ÿ³�–ÿ´�•ÿ´€’ÿ´‘ÿ³~�ÿ²~�ÿ±~‘ÿ°}‘ÿ±}Žÿ²|‰ÿ²z„ÿ±yƒÿ°y…ÿ®y‡ÿ¬y‰ÿªx‹ÿªwŠÿªvŠÿ©u‰ÿ¨u‰ÿ§u‹ÿ¦u‹ÿ¦uŒÿ¦uŒÿ¦t‹ÿ¦t‰ÿ¦tˆÿ¦tˆÿ¥tŠÿ¤s‹ÿ£r�ÿ¢rŽÿ¡r�ÿ r‘ÿ r‘ÿ¡r�ÿ¡q�ÿ¡qŒÿ¡qŠÿ¡qŠÿ¡r�ÿ r�ÿžq“ÿ�q–ÿœr™ÿ›rœÿšr�ÿšrœÿ›q™ÿ›p–ÿšn“ÿ™m�ÿ˜lŒÿ˜kŒÿ—kŒÿ—kŒÿ—j‹ÿ–j‹ÿ•jŒÿ”jŽÿ“j‘ÿ“k”ÿ“l–ÿ”m˜ÿ“m™ÿ’l™ÿ’l˜ÿ’l™ÿ’l™ÿ’l˜ÿ’k˜ÿ’k˜ÿ’l˜ÿ“l—ÿ”k–ÿ”k•ÿ–k“ÿ–k‘ÿ–kŽÿ–j�ÿ—j�ÿ—jŒÿ˜iŠÿ—h‡ÿ—i†ÿ—i‡ÿ—i‡ÿ—i†ÿ˜hƒÿ˜g€ÿ—f{ÿ—eyÿ—dvÿ—cuÿ—cuÿ–cuÿ•cwÿ“bxÿ’bzÿ‘b{ÿ‘b{ÿ�a|ÿ‘a}ÿ‘a}ÿ‘b|ÿ’b{ÿ’b{ÿ’b{ÿ’b|ÿ’c~ÿ“cÿ“c‚ÿ“dƒÿ”d‚ÿ”d€ÿ•d~ÿ•d~ÿ•d~ÿ”d~ÿ”c~ÿ”c€ÿ´•Äÿµ–Ãÿ¶–Áÿ¸–¾ÿ¸•¼ÿ¹•¹ÿ¹•¹ÿ¹–ºÿ¸–»ÿ¸•¼ÿ¸•½ÿ¸•¾ÿ·•¿ÿ·•½ÿ¸”¸ÿ¹“²ÿº’®ÿ»’®ÿ»’­ÿ»‘¬ÿº‘­ÿº‘®ÿº‘­ÿ»‘©ÿ»�¦ÿ»�¥ÿ¼�§ÿ¼‘¨ÿ¼‘©ÿ¼‘ªÿ»’­ÿº’¯ÿ¹‘¯ÿ¸�±ÿ¶�´ÿ³�µÿ²�µÿ±Œ´ÿ±Œ´ÿ°‹³ÿ°Š±ÿ°Š°ÿ±Š±ÿ°Š³ÿ¯‹´ÿ®Š´ÿ®Š´ÿ­Š³ÿ­‰²ÿ­‰²ÿ®‰³ÿ¯‰³ÿ¯‰³ÿ®‰³ÿ­ˆ²ÿ®ˆ²ÿ®‰²ÿ¯‰±ÿ°‰¯ÿ±‰®ÿ±‰¬ÿ²‰­ÿ²Š­ÿ²Š­ÿ²‰­ÿ³Š®ÿ´Œ¯ÿµŒ®ÿ¶Œ¬ÿ¶�¬ÿ·�¬ÿ·�¬ÿ·�­ÿ·Ž¯ÿ·Ž±ÿµŽµÿ´Ž¶ÿµ�¶ÿ·�µÿ·�²ÿ¹�°ÿº�­ÿºŽªÿ»�¦ÿ¼�¤ÿ»Œ£ÿºŒ£ÿ»Œ£ÿ»Œ¢ÿ¼Œ ÿ¼��ÿ½�œÿ½Œœÿ¼Œ�ÿ¼‹�ÿ¼‹žÿ»‹Ÿÿ»Œ¡ÿ¼�£ÿ»Œ£ÿ»Œ£ÿ»Œ£ÿ»Œ¥ÿºŒ§ÿºŒ§ÿºŠ¤ÿ¹‰¡ÿ¹‰Ÿÿ¹‰Ÿÿ¸ˆ ÿ¸‰¢ÿ·‰¥ÿµ‰©ÿ³Š­ÿ²Š°ÿ²‰±ÿ±‰±ÿ±ˆ®ÿ²‡ªÿ³‡§ÿ³†£ÿ³…¢ÿ´… ÿ´„œÿµƒ—ÿµƒ—ÿ´ƒšÿ´ƒœÿ³ƒœÿ³‚šÿ³�—ÿ´�”ÿ´€‘ÿ³~�ÿ²~‘ÿ±}‘ÿ±}‘ÿ±}�ÿ²|ˆÿ²z„ÿ²yƒÿ±yƒÿ¯z…ÿ®z‡ÿ¬y‰ÿ¬xˆÿ¬wˆÿªvˆÿ©vŠÿ¨vŒÿ§w�ÿ¦w�ÿ¦v�ÿ§vŽÿ¨v�ÿ§vŒÿ¦uŒÿ¥tŒÿ¥t�ÿ£s�ÿ¢s�ÿ¡s’ÿ s•ÿ¡s•ÿ¢s“ÿ¢rŽÿ¢rŒÿ¢sŒÿ¢s�ÿ£t‘ÿ¢t”ÿ t—ÿžsšÿœsœÿšsžÿ™r�ÿšqšÿšq—ÿ›p•ÿ›o’ÿ™m�ÿ˜l�ÿ—l�ÿ—k�ÿ—k�ÿ—jŒÿ—kŒÿ–j�ÿ•j�ÿ”k‘ÿ”k”ÿ•m–ÿ•n˜ÿ”mšÿ“mšÿ’m™ÿ“nšÿ“nšÿ”m™ÿ”m—ÿ”l—ÿ”m˜ÿ”l—ÿ•l–ÿ•l–ÿ•l•ÿ•l”ÿ•l“ÿ–k‘ÿ–k‘ÿ–k‘ÿ–j�ÿ–i�ÿ–i‹ÿ–i‹ÿ–j‹ÿ–i‰ÿ–i‡ÿ–h„ÿ–fÿ–e|ÿ–dyÿ–cxÿ–cxÿ•dyÿ”czÿ’bzÿ‘bzÿ‘a{ÿ‘b{ÿ�a}ÿ�b~ÿ�b~ÿ‘c~ÿ’c}ÿ‘b}ÿ’b~ÿ’c�ÿ’dƒÿ’d…ÿ“d‡ÿ“e‡ÿ”e…ÿ•d‚ÿ•dÿ•d~ÿ•d~ÿ•cÿ”c�ÿ”d„ÿ´•Ãÿ¶–Áÿ¸–¿ÿ¸–¾ÿ¹–»ÿº–·ÿ»–¸ÿ»–¹ÿº–¸ÿº•¸ÿ¹–ºÿ¸–¾ÿ¸—Áÿ¸–Àÿ¸•»ÿ¹”µÿº“±ÿ»’¯ÿ¼’®ÿ»’­ÿ»’­ÿ»’­ÿ¼’¬ÿ¼’ªÿ¼‘§ÿ¼�¦ÿ¼�§ÿ¼‘§ÿ½’§ÿ½’¨ÿ½“«ÿ¼“¬ÿ»’¬ÿ»‘¬ÿº�®ÿ¹�¯ÿ·�°ÿ¶�°ÿ³Ž±ÿ±Œ²ÿ±Œ±ÿ±‹±ÿ±‹²ÿ±Œ³ÿ±Œ´ÿ¯‹µÿ¯‹´ÿ®‹³ÿ®Š³ÿ¯‰³ÿ®‰²ÿ®Š´ÿ¯Š³ÿ¯Š²ÿ®‰±ÿ¯‰²ÿ¯Š³ÿ¯Š³ÿ¯Š²ÿ°Š°ÿ±‰°ÿ°Š°ÿ°Š±ÿ°Š²ÿ°‰²ÿ°Š³ÿ±‹³ÿ³Œ²ÿ³Œ°ÿ´Œ®ÿ´Œ¯ÿµ�°ÿ¶Ž±ÿ¶Ž±ÿ¶Ž±ÿ·Ž²ÿ¶Ž³ÿµŽ´ÿ¶�³ÿ·�°ÿ¹�°ÿ¹�°ÿ¹�®ÿºŽ«ÿ»Ž¨ÿ»�¤ÿ»�¥ÿ»�¥ÿ»�¤ÿºŒ¢ÿ»�¢ÿ¼�£ÿ»�£ÿ»�¢ÿ¼Œ¢ÿ¼Œ¢ÿ»�¤ÿ»�¥ÿ¼�¦ÿ»�¤ÿ»Œ¤ÿ»�¦ÿ»�¨ÿº�©ÿ¹Œ§ÿ¹‹¤ÿ¹Š¡ÿ¹‰ ÿ¹‰Ÿÿ¹‰Ÿÿ¸‰¢ÿ·Š§ÿµŠ«ÿ´Š®ÿ³Š¯ÿ²Š®ÿ±‰­ÿ²‡ªÿ³‡§ÿ´‡¤ÿ³†¡ÿ´…Ÿÿµ„�ÿ´„™ÿ´ƒ–ÿµ„˜ÿµ„›ÿ³„žÿ³„ ÿ³„žÿ³‚˜ÿ´€“ÿ´�ÿ³Žÿ³~�ÿ²~�ÿ²~�ÿ²}�ÿ²|ˆÿ±{„ÿ±zƒÿ°yƒÿ°y„ÿ°z…ÿ¯z†ÿ®x†ÿ­w†ÿ¬wˆÿ«wŠÿ«wŒÿ©x�ÿ§x’ÿ§w‘ÿ¨w�ÿ©wŽÿ¨w�ÿ¨vŽÿ¦u�ÿ¥uŽÿ¥u‘ÿ£t“ÿ¢t•ÿ¡t˜ÿ¡t˜ÿ¢u•ÿ¢t‘ÿ¢t�ÿ¢t‘ÿ£u“ÿ¤u–ÿ£v™ÿ¢v›ÿ uœÿ�sœÿšrœÿ™q›ÿ™p—ÿ™o”ÿ™o“ÿšn�ÿšmŽÿ˜l�ÿ—l�ÿ—l�ÿ—k�ÿ—j‹ÿ˜kŒÿ—k�ÿ–kŽÿ•k‘ÿ•l•ÿ–m—ÿ•n˜ÿ”m˜ÿ”m™ÿ”nšÿ“nšÿ”nšÿ•n™ÿ•n˜ÿ•m–ÿ•n—ÿ–m–ÿ–m•ÿ•m•ÿ•m–ÿ•l—ÿ•l–ÿ–l–ÿ–l–ÿ–l•ÿ•k’ÿ•j�ÿ•i�ÿ–j�ÿ•j�ÿ•i‹ÿ–iˆÿ–h†ÿ•fƒÿ”eÿ”d}ÿ”d|ÿ“d|ÿ’c~ÿ’cÿ�bÿ�bÿ�b~ÿ�a~ÿ�bÿ�c€ÿ�cÿ‘cÿ‘cÿ‘cÿ’d�ÿ’d†ÿ’d‰ÿ“e‹ÿ“eŒÿ“e‹ÿ”eˆÿ”dƒÿ•e€ÿ•c}ÿ”c}ÿ”dÿ•dƒÿ”e‡ÿµ–Âÿ¶–Áÿ¸–¿ÿ¹–½ÿº—ºÿ¼•µÿ¼•µÿ½•¶ÿ½•µÿ¼–¶ÿ»•¸ÿº–¼ÿ¹—Àÿ¹—Ãÿº—Áÿ¹–»ÿº”¶ÿ»“²ÿ¼“°ÿ»”¯ÿ¼”¯ÿ½“®ÿ¼’¬ÿ½“ªÿ½’©ÿ½‘§ÿ½‘§ÿ¾‘¦ÿ¾‘¦ÿ½’§ÿ¾“©ÿ¾”«ÿ¾“ªÿ¾’¨ÿ½’¨ÿ½’ªÿ»‘¬ÿ¹�®ÿ¸�¯ÿ¶�°ÿµ�±ÿ³�²ÿ²�²ÿ²�³ÿ²�µÿ±�µÿ±Œ´ÿ±‹³ÿ¯‹³ÿ¯‹²ÿ¯Š³ÿ®Š´ÿ¯Š´ÿ¯Š³ÿ°‹²ÿ°‹³ÿ°‹³ÿ¯‹³ÿ¯‹³ÿ°‹³ÿ¯‹³ÿ¯Š³ÿ®Š´ÿ­‹µÿ­‹¶ÿ­Š·ÿ®‹¸ÿ¯Œ·ÿ°Œµÿ±Œµÿ±Œµÿ²�¶ÿ³Ž¶ÿ´Žµÿ´�²ÿ¶Ž°ÿ¶Ž°ÿµŽ±ÿµŽ²ÿ·Ž°ÿ¹�¯ÿ¹�°ÿ¹�¯ÿº�­ÿºŽ©ÿº�¦ÿ»Ž¦ÿ»Ž§ÿ»Ž¦ÿ»Ž¦ÿ»�§ÿ»Ž©ÿ»Ž©ÿºŽ¨ÿ»�¦ÿº�¦ÿ»Ž¨ÿ»Ž¨ÿ»Ž§ÿ»�¦ÿº�¥ÿ»�¦ÿ»�¨ÿº�¨ÿ¹Œ¦ÿºŒ¤ÿ¹‹¢ÿ¹Š ÿº‰žÿ¹ˆžÿ¸ˆ¡ÿ·‰§ÿµ‰«ÿµ‰­ÿ´Š­ÿ³‰«ÿ³ˆ©ÿ´‡§ÿ´‡¥ÿµ†¢ÿ´†¡ÿµ…�ÿµ„™ÿµƒ—ÿµ„–ÿ´ƒ˜ÿ´„œÿ³„ ÿ³„¡ÿ²„�ÿ³‚–ÿ´�‘ÿµŽÿ´~Œÿ´~�ÿ´~Žÿ³}�ÿ²}�ÿ²|ˆÿ²{…ÿ±zƒÿ±z‚ÿ±y‚ÿ°yƒÿ¯y„ÿ¯x…ÿ®x†ÿ¬wˆÿ¬wŠÿ¬wŒÿªx�ÿ©y‘ÿ¨x’ÿ©x‘ÿªx�ÿªx�ÿ©w�ÿ¨wŽÿ¦v�ÿ¦v‘ÿ¥u”ÿ£v—ÿ¢u˜ÿ¡u˜ÿ¢u—ÿ£u•ÿ¢u—ÿ¢v™ÿ¢w›ÿ£wœÿ£x�ÿ¢w�ÿ¡uœÿŸt›ÿœsšÿ™q˜ÿ™o•ÿ˜o“ÿ—n’ÿ˜m�ÿ™mŽÿ™m�ÿšm�ÿ™m�ÿ™lŒÿ™l‹ÿšl‹ÿ™mŽÿ—m‘ÿ–n”ÿ•m–ÿ–n—ÿ–n—ÿ–n˜ÿ–n™ÿ–n›ÿ•nšÿ•nšÿ–n˜ÿ—n—ÿ—o–ÿ–n–ÿ–m•ÿ–m”ÿ–m”ÿ–m—ÿ•m™ÿ•mšÿ•m™ÿ•m˜ÿ•l—ÿ•k•ÿ”j“ÿ”j’ÿ•k“ÿ•j�ÿ•iŒÿ–iŠÿ•h‰ÿ”g‡ÿ“f„ÿ”fƒÿ“eƒÿ’e‚ÿ’eƒÿ�dƒÿ�c„ÿŽc„ÿŽcƒÿŽb‚ÿŽcƒÿ�cƒÿ�d‚ÿ‘d‚ÿ‘c‚ÿ’dƒÿ’e†ÿ’e‰ÿ’e�ÿ’f�ÿ“fŽÿ”fŒÿ”eˆÿ”eƒÿ•dÿ–c|ÿ•d|ÿ•d}ÿ”d€ÿ•dƒÿ¶–Âÿ¶–Áÿ¸—Àÿ¹—¾ÿº—ºÿ¼–·ÿ½–µÿ¾–´ÿ¾–´ÿ¾–µÿ½–·ÿ»—ºÿº—½ÿ¹—Áÿº˜Ãÿº™Áÿ»—¼ÿ¼–·ÿ¼•³ÿ½•±ÿ¾”¯ÿ¾”­ÿ¾“­ÿ¾“¬ÿ½“ªÿ¾’©ÿ¾“¨ÿ¾’§ÿ¿’§ÿ¾’§ÿ¾“©ÿ¿”«ÿ¿”ªÿ¿“§ÿ¿“¦ÿ¿“§ÿ¾“ªÿ¼’¬ÿ»‘­ÿº‘¯ÿ¸‘±ÿ¶�²ÿµ�³ÿ³�³ÿ³Ž´ÿ³Žµÿ³�´ÿ²�³ÿ±Œ³ÿ±Œ³ÿ°Œ´ÿ°‹µÿ°‹µÿ°‹´ÿ°‹´ÿ¯‹´ÿ¯‹´ÿ¯‹µÿ¯‹´ÿ¯‹´ÿ°‹´ÿ¯Š´ÿ®Šµÿ­Š¶ÿ¬Š¸ÿ¬Šºÿ¬‹¼ÿ¬‹»ÿ¬Œ»ÿ­Œ¼ÿ­�¼ÿ®�¼ÿ°�¼ÿ±�ºÿ³ŒµÿµŒ¯ÿµŒ®ÿµ�±ÿ´�³ÿ¶�²ÿ¶Ž±ÿ·�±ÿ¸�°ÿ¹�®ÿ¹�«ÿºŽ©ÿºŽ©ÿºŽ©ÿºŽ©ÿºŽªÿºŽ«ÿº�­ÿ¹�®ÿº�­ÿºŽªÿºŽ©ÿºŽªÿºŽªÿºŽ©ÿº�§ÿ»�¦ÿ»�¦ÿ»�¦ÿ»�¥ÿºŒ¤ÿ»‹£ÿº‹¢ÿº‹ ÿºŠŸÿ¹‰ ÿ·‰£ÿ¶‰§ÿµŠ©ÿµŠªÿµ‰©ÿµ‰¨ÿµˆ§ÿµ‡¥ÿµ‡£ÿµ†¡ÿµ†Ÿÿ´…›ÿµ„˜ÿµƒ—ÿ¶ƒ—ÿµ„™ÿ´„�ÿ³„ ÿ³„ ÿ²ƒœÿ³‚•ÿ´€’ÿ´�ÿ³~Žÿ³~Žÿ³~�ÿ²}�ÿ²|Œÿ²|ˆÿ³|…ÿ²{„ÿ±z‚ÿ°y‚ÿ°y‚ÿ°xƒÿ¯x…ÿ®x‡ÿ­yŠÿ­yŒÿ¬yŽÿ«y‘ÿªz“ÿªz“ÿ«y“ÿ«y‘ÿªx�ÿ©x�ÿ¨x�ÿ§w�ÿ§w‘ÿ¦w”ÿ¥w—ÿ¤w˜ÿ£v™ÿ£v™ÿ£v™ÿ¢vœÿ¢wŸÿ¢x¡ÿ¡x¢ÿ£x ÿ£wžÿ¡uœÿ t›ÿžsšÿ›r—ÿšp•ÿ˜n“ÿ—m‘ÿ—l�ÿ˜m�ÿ™mŽÿšmŽÿ›m�ÿ›m�ÿ›mŒÿšm�ÿ™n�ÿ—o•ÿ—o˜ÿ–n—ÿ—n–ÿ—n–ÿ—n˜ÿ—ošÿ–o›ÿ•nœÿ•nšÿ—n—ÿ™n–ÿ™n•ÿ˜n•ÿ—m”ÿ—m“ÿ—m”ÿ—m—ÿ•n›ÿ•nœÿ•n›ÿ”m™ÿ”l—ÿ”l–ÿ“k•ÿ“k•ÿ”k”ÿ•j‘ÿ–j�ÿ–i�ÿ•hŒÿ”gŠÿ“g‰ÿ“g‰ÿ’f‰ÿ‘e‰ÿ�eˆÿ�e‡ÿ�d‡ÿŽc‡ÿŽc‡ÿŽc†ÿ�d†ÿ�d„ÿ‘e„ÿ’e„ÿ“e„ÿ”f‡ÿ”f‡ÿ“e‰ÿ“e‹ÿ“fŒÿ“fŒÿ”fŒÿ”f‡ÿ•e‚ÿ–e~ÿ—d}ÿ–e|ÿ–e~ÿ•e€ÿ–e�ÿ¶—Àÿ·—¿ÿ¸—¿ÿ¹—¾ÿº—¼ÿ¼—¹ÿ¾˜·ÿ¿—¶ÿ¿—µÿ¿˜¶ÿ¾˜·ÿ½˜¹ÿ¼˜»ÿ»˜½ÿº™Áÿº™Âÿ»™Àÿ¼˜¼ÿ½—¶ÿ¾•²ÿ¿•¯ÿ¿•­ÿ¿”­ÿÀ”¬ÿ¿”ªÿ¿”ªÿ¿”¨ÿ¿“§ÿ¿’¦ÿ¿’§ÿ¿“¨ÿ¿”ªÿ¿”©ÿ¿“¨ÿ¿“§ÿ¿“§ÿ¿“¨ÿ¾“ªÿ½“¬ÿ¼“­ÿ»“°ÿ¹’±ÿ¸‘²ÿ·�³ÿ¶�³ÿµ�´ÿ´�´ÿ³Ž´ÿ²�´ÿ²�´ÿ±Œ´ÿ±Œ´ÿ°‹µÿ°Œµÿ¯‹µÿ¯‹µÿ®‹µÿ¯‹µÿ®‹´ÿ®‹´ÿ¯‹´ÿ®‹´ÿ®Šµÿ­Š·ÿ¬Š¹ÿ«Š¼ÿ«‹½ÿ«‹¾ÿ«‹¾ÿ«Œ¿ÿ«�Àÿ¬�Àÿ­�Àÿ¯�¿ÿ°Œ¹ÿ²Œ±ÿ³Œ°ÿ³Œ²ÿ³�µÿ´�¶ÿ´�¶ÿ´Žµÿ¶�´ÿ·�³ÿ¸�°ÿ¹�­ÿ¹Ž­ÿ¹�­ÿº�¬ÿ¹�­ÿ¹�®ÿ¹�°ÿ¹�°ÿ¹�¯ÿºŽ¬ÿºŽ¬ÿºŽ­ÿºŽ¬ÿºŽªÿº�¨ÿº�§ÿ»�¦ÿ»�¥ÿ»�£ÿ»Œ¢ÿ»‹£ÿº‹£ÿº‹¢ÿ¹Š¢ÿ¸Š¢ÿ·Š¥ÿ¶Š¨ÿµŠ¨ÿµ‰§ÿµ‰§ÿµ‰¦ÿµˆ¥ÿµˆ£ÿµ‡¢ÿµ† ÿ´†�ÿ´…šÿ´„˜ÿµ„—ÿµ„˜ÿµ„›ÿ´„žÿ³„ ÿ³„Ÿÿ³ƒœÿ³�–ÿ³€”ÿ²“ÿ±“ÿ±~’ÿ±~‘ÿ°}�ÿ±|Œÿ²|ˆÿ³|…ÿ³{„ÿ²zƒÿ°yƒÿ°yƒÿ°y…ÿ¯y‡ÿ®y‰ÿ­yŒÿ¬zŽÿ¬z‘ÿ«z“ÿª{•ÿ«{•ÿ¬z”ÿ«z’ÿªy‘ÿ©x’ÿ¨x‘ÿ¨x‘ÿ¨x’ÿ¨x“ÿ§x•ÿ¦x—ÿ¥xšÿ¤w›ÿ£w›ÿ¡wžÿ¡w¡ÿ¡x¤ÿ¡y¥ÿ£x¡ÿ£wœÿ¢všÿ¡u™ÿŸt˜ÿžr—ÿœq•ÿšo“ÿ˜n’ÿ˜m‘ÿ˜n‘ÿ™n�ÿšm�ÿ›m�ÿœmŽÿ›n�ÿšn�ÿ˜o”ÿ—p˜ÿ—p™ÿ—o˜ÿ˜o–ÿ—n–ÿ—o˜ÿ—ošÿ–oœÿ•nœÿ•n™ÿ—n–ÿ™n•ÿ™n•ÿ™n”ÿ˜n“ÿ˜m“ÿ˜n“ÿ˜n–ÿ–ošÿ•o›ÿ•nšÿ”l™ÿ”l—ÿ“l–ÿ“l–ÿ“k–ÿ“k•ÿ“j’ÿ•j‘ÿ•j�ÿ•iŽÿ“h�ÿ“h�ÿ’g�ÿ‘g�ÿ�fŒÿ�e‹ÿ�eŠÿ�d‹ÿŽd‹ÿŽd‹ÿ�dŠÿ�eˆÿ‘e†ÿ“e…ÿ”f…ÿ”f†ÿ”f‡ÿ•f†ÿ”e†ÿ”fˆÿ“f‰ÿ”f‹ÿ”f‹ÿ•f‡ÿ•e‚ÿ–eÿ—e~ÿ—e~ÿ—e€ÿ–e�ÿ–e‚ÿ¸—¼ÿ¸—½ÿ¹˜½ÿº˜¾ÿ»™½ÿ¼™»ÿ½™ºÿ¾™¹ÿ¿™¸ÿ¿™¸ÿ¾™¹ÿ¾™ºÿ½™»ÿ½š½ÿ¼šÀÿ¼šÁÿ¼šÁÿ½™¾ÿ¾˜¸ÿ¿—²ÿ¿–°ÿÀ–®ÿÀ•­ÿÁ•¬ÿÀ•ªÿÁ•©ÿÁ•¨ÿÀ”¦ÿ¿“¥ÿÀ“¦ÿÀ“¦ÿ¿”¨ÿ¿”©ÿ¿”©ÿ¿“¨ÿ¾“§ÿ¿”©ÿ¿”«ÿ¾”¬ÿ½”¬ÿ½”¯ÿ¼”±ÿ»“±ÿº’²ÿ¹’²ÿ¸’²ÿ·‘³ÿµ�´ÿ´�´ÿ³Ž´ÿ²�³ÿ±Œ´ÿ°Œµÿ¯Œ¶ÿ¯Œ¶ÿ®‹¶ÿ®‹·ÿ®‹¶ÿ­Šµÿ­Šµÿ®Šµÿ­‹µÿ­Š¶ÿ­Š·ÿ¬Š¹ÿ¬‹¼ÿ«‹½ÿ«‹¾ÿ«Œ¾ÿ«Œ¿ÿ«�Àÿ¬�Áÿ¬�Âÿ­�Àÿ®Œ¼ÿ°Œ¶ÿ±Œ´ÿ±�µÿ²�¹ÿ²�»ÿ²Ž¼ÿ²Ž¼ÿ²�»ÿ³�¹ÿµ�·ÿ·�³ÿ·�²ÿ¸�²ÿ¹�±ÿ¹�¯ÿ¹�¯ÿ¹�¯ÿ¹�¯ÿº�­ÿ»Ž­ÿ»�®ÿº�®ÿºŽ­ÿºŽªÿ¹Ž©ÿº�¨ÿºŽ§ÿ»�¦ÿºŒ¤ÿºŒ£ÿº‹¤ÿºŒ¥ÿ¹‹¥ÿ¸‹¥ÿ¸Š¦ÿ·Š¨ÿ¶‹©ÿµŠ¨ÿµ‰¦ÿ¶‰¦ÿµ‰¥ÿµˆ£ÿµ‡¢ÿµ†¡ÿ´†Ÿÿ³…�ÿ³…›ÿ´„šÿµ„™ÿ´…šÿµ…žÿ´… ÿ³„¢ÿ³„¡ÿ³ƒžÿ²‚šÿ²�˜ÿ±€˜ÿ°€˜ÿ¯—ÿ¯~•ÿ°}’ÿ±}Žÿ±|‹ÿ±|‡ÿ²{…ÿ²{…ÿ±z…ÿ°z†ÿ°zˆÿ¯yŠÿ®y‹ÿ­zŽÿ¬z‘ÿ«{”ÿª{•ÿ«|–ÿ«|–ÿ¬{•ÿ«z“ÿªz“ÿªy”ÿ©y”ÿ©y“ÿ©y“ÿ©x’ÿ©y”ÿ¨z˜ÿ§zœÿ¦yœÿ¤x›ÿ£x�ÿ¢x ÿ¢y¤ÿ¡z¥ÿ¢y¡ÿ£wœÿ¢v˜ÿ¡u—ÿ¡t–ÿ s–ÿžr•ÿœq”ÿšp“ÿ™o’ÿšo“ÿ™o’ÿšn’ÿ›n’ÿœo’ÿ›o’ÿšo”ÿ™p˜ÿ˜q›ÿ—p›ÿ™p™ÿ™p—ÿ˜o˜ÿ˜o™ÿ˜ošÿ—oœÿ–ošÿ–n˜ÿ—n–ÿ™n•ÿ™o”ÿ™n“ÿšn“ÿšo“ÿšo“ÿ™o•ÿ˜o—ÿ—n–ÿ–m•ÿ–l•ÿ•k”ÿ”k”ÿ“l•ÿ“k•ÿ’k•ÿ’j”ÿ“j“ÿ”j‘ÿ”j�ÿ“i�ÿ’i�ÿ‘h�ÿ�gŽÿ�fŒÿ�e‹ÿ�eŒÿ�e�ÿŽeŽÿŽeŽÿ�eŒÿ‘fŠÿ’fˆÿ•f‡ÿ–g†ÿ–g†ÿ•g…ÿ•fƒÿ•fƒÿ•f…ÿ•fˆÿ”fŒÿ•fŒÿ•fˆÿ•f„ÿ–f�ÿ—f€ÿ—f€ÿ—f€ÿ—e�ÿ—e�ÿ¹—»ÿº˜¼ÿ»™½ÿ»š½ÿ¼š½ÿ½š¼ÿ¾š»ÿ¾š»ÿ¾š»ÿ¿š»ÿ¾™ºÿ¿š»ÿ¿›½ÿ¾›¿ÿ¾œÁÿ¾›Àÿ¾›Àÿ¿š½ÿÀ™¸ÿÁ˜´ÿÀ—±ÿÁ—¯ÿÁ—®ÿÁ–­ÿÁ–«ÿ–¨ÿ•¦ÿ•¥ÿ•¤ÿ”¤ÿÁ”¥ÿÀ”¦ÿ¿”¨ÿ¿”ªÿ¿“ªÿ¿”ªÿ¿”«ÿ¿•¬ÿ¿•­ÿ¾•®ÿ¾•°ÿ¾•±ÿ½•±ÿ½•°ÿ¼”¯ÿ»“¯ÿº’°ÿ¸’²ÿ·‘´ÿµ�´ÿ´�´ÿ²Žµÿ±�¶ÿ°Œ·ÿ¯Œ¸ÿ®Œ·ÿ­‹¸ÿ­Š¸ÿ¬Š·ÿ­Š¶ÿ­Š¶ÿ¬Š¶ÿ¬Š¶ÿ¬Š·ÿ­‹¹ÿ­Œ»ÿ­Œ¼ÿ­Œ¼ÿ­Œ½ÿ¬�¾ÿ¬Œ¿ÿ¬ŒÀÿ­�Àÿ­�¿ÿ®Œ¼ÿ°Œ¹ÿ°Œ¸ÿ°�¹ÿ°Ž½ÿ°Ž¿ÿ°�Àÿ°�Âÿ°�Áÿ±�¿ÿ²�½ÿ³�»ÿµ�ºÿ¶�¹ÿ·�·ÿ¸�³ÿº�±ÿ¹�¯ÿº�­ÿ»�¬ÿ¼�¬ÿ¼�¬ÿ»�­ÿ»�¬ÿ»�ªÿº�ªÿºŽ©ÿºŽ¨ÿº�§ÿºŒ¦ÿ¹Œ¦ÿ¹Œ§ÿ¹Œ¨ÿ¹Œ¨ÿ¸Œ©ÿ·‹©ÿ¶‹ªÿ¶Š©ÿ¶Š§ÿ¶Š¦ÿ¶‰¥ÿ¶‰¤ÿ¶ˆ¢ÿµ‡¡ÿ´† ÿ´…Ÿÿ³…Ÿÿ³…Ÿÿ´„žÿµ…�ÿµ…žÿ´†¡ÿ³…£ÿ²†¥ÿ²†¦ÿ²„£ÿ±ƒ ÿ±‚Ÿÿ°‚žÿ¯��ÿ®€›ÿ¯šÿ¯~—ÿ¯~”ÿ°}�ÿ°|Œÿ±|‰ÿ°{‰ÿ°{Šÿ°{‹ÿ¯{‹ÿ®z�ÿ­z�ÿ¬z‘ÿ«{”ÿ«|—ÿª}™ÿ«}™ÿ«|—ÿ«{–ÿ«z–ÿ«{–ÿª{—ÿª{—ÿªz–ÿªy”ÿªy“ÿ«z•ÿª{šÿ©{žÿ¨z�ÿ§y›ÿ¥yœÿ¤yžÿ£y¡ÿ£y£ÿ£y¡ÿ£x�ÿ¢v™ÿ¡u—ÿ¢u—ÿ¡t•ÿ s•ÿžs•ÿœr•ÿ›q•ÿ›p•ÿšp•ÿ›p”ÿ›o”ÿ›p–ÿ›q—ÿšq˜ÿ™r›ÿ™r�ÿ˜q�ÿ™q›ÿ™q™ÿ™q™ÿ™p™ÿ˜pšÿ˜p›ÿ—o™ÿ–n—ÿ—n•ÿ™m”ÿ™n“ÿ›n’ÿœo‘ÿ�p‘ÿ�p‘ÿœp“ÿ›o’ÿšmŽÿ™lŒÿ˜l�ÿ—kŽÿ–k‘ÿ”l”ÿ“l•ÿ’k”ÿ’j”ÿ“j”ÿ“k”ÿ“k“ÿ“j’ÿ’i‘ÿ‘h�ÿ�f�ÿ�f‹ÿ�eŠÿ‘fŒÿ�e�ÿ�fŽÿ�fŽÿ’g�ÿ“gŒÿ•hŒÿ–hŠÿ—h‰ÿ—h‡ÿ–g„ÿ–g‚ÿ—gƒÿ—g…ÿ–fˆÿ•gŒÿ•gŒÿ•g‰ÿ–g†ÿ—g…ÿ—g„ÿ—f‚ÿ—eÿ—e~ÿ˜e~ÿ¹˜»ÿº˜¼ÿ»™½ÿ½š½ÿ½š¾ÿ¾›½ÿ¿›¼ÿ¿›½ÿ¿œ½ÿ¿›¼ÿÀ›»ÿÀ›»ÿÀ›¼ÿÀ›¿ÿ¿œÀÿ¿œ¿ÿ¿œ¿ÿÁ›½ÿš¹ÿÁ™µÿ˜±ÿ˜±ÿÁ—¯ÿ—®ÿجÿÄ—¨ÿÖ¦ÿÖ¥ÿÄ–¤ÿÄ–¢ÿÕ£ÿÕ¥ÿ•¨ÿ•ªÿ•«ÿ–¬ÿÀ•¬ÿÀ•¬ÿÀ–­ÿÀ•­ÿ¾•¯ÿ¾•°ÿ¾•°ÿ¾•°ÿ¾•¯ÿ½”­ÿ½“­ÿ¼’®ÿº’¯ÿ¹’²ÿ·‘´ÿµ�µÿ³�·ÿ±Ž¸ÿ°Ž¹ÿ®Œ¸ÿ­‹¸ÿ­Š¸ÿ¬Š¸ÿ¬‹¸ÿ¬‹·ÿ¬Š·ÿ¬Š¶ÿ¬‰¶ÿ­Š¸ÿ®Œºÿ®Œºÿ¯�»ÿ¯�¼ÿ¯�½ÿ¯Ž¾ÿ¯Ž¾ÿ®�¾ÿ®�½ÿ°�»ÿ¯�»ÿ°�»ÿ°�¼ÿ¯Ž¿ÿ¯�Ãÿ¯�Äÿ¯�Åÿ¯�Åÿ°�Äÿ°�Ãÿ°�Âÿ±‘Âÿ³‘Áÿµ‘¾ÿ·‘ºÿ¹’¶ÿº‘²ÿ»�¯ÿ»�¬ÿ¼�«ÿ½�ªÿ½Ž¨ÿ½�§ÿ¼�¨ÿ»Ž©ÿº�ªÿº�ªÿºŽ©ÿ¹Ž©ÿ¹Žªÿ¸�«ÿ¸�¬ÿ·�«ÿ·Œ«ÿ¸Œ«ÿ·‹ªÿ·‹§ÿ·Š¥ÿ·‰¤ÿ¸Š¢ÿ¸‰¢ÿ¶ˆ¡ÿ¶‡¡ÿµ‡¡ÿµ†¡ÿ³†¢ÿ²†¢ÿ²†¢ÿ³†£ÿ´‡¤ÿ³†¦ÿ²‡¨ÿ²‡ªÿ²‡ªÿ±†§ÿ±…¥ÿ°„¥ÿ¯ƒ£ÿ®‚¢ÿ­� ÿ®�Ÿÿ®€�ÿ®šÿ¯~–ÿ°}‘ÿ°}�ÿ°|Œÿ°|�ÿ¯|Žÿ®{�ÿ­{�ÿ­{“ÿ¬{”ÿ«|–ÿ«}šÿ«}œÿ«}›ÿ«|™ÿ«{—ÿª{—ÿª{˜ÿ©{™ÿ©{šÿ©z™ÿªy•ÿªy“ÿªz•ÿª{šÿª{›ÿ©zšÿ©{™ÿ§z›ÿ¦z�ÿ¦zŸÿ¥z¡ÿ¥z¡ÿ¤yŸÿ¢wœÿ¡všÿ¢ušÿ¢u—ÿ¡u•ÿŸs–ÿ�r–ÿœq–ÿ›r˜ÿ›q˜ÿ›q˜ÿ›q™ÿšqšÿšršÿ™rœÿ™ržÿ™rŸÿ˜qžÿ™qœÿšq›ÿšqšÿšqšÿ™q›ÿ˜p™ÿ˜n—ÿ˜n•ÿ˜m“ÿ™n“ÿ›o“ÿœo‘ÿžp�ÿ q�ÿ q�ÿžo�ÿ�n‹ÿœmˆÿ›k†ÿšj†ÿškˆÿ™lŽÿ—l“ÿ•l•ÿ”j“ÿ“j”ÿ“k•ÿ”k”ÿ•l“ÿ”k’ÿ’j�ÿ‘h�ÿ‘f‹ÿ‘eŠÿ‘fŠÿ‘f‹ÿ‘gŒÿ‘gŽÿ’h�ÿ”iŽÿ•jŽÿ—jŽÿ˜jŽÿ˜j‹ÿ—i‡ÿ˜h„ÿ˜h„ÿ˜h†ÿ˜hˆÿ—h‹ÿ–i�ÿ•hŒÿ•g‹ÿ•gŠÿ•gŠÿ•g‰ÿ•f‡ÿ–f„ÿ—e€ÿ–e~ÿº˜¼ÿº™½ÿ¼š¾ÿ½š¾ÿ½›¾ÿ¾œ¾ÿ¿œ¾ÿ¿�ÀÿÀ�ÀÿÁ�¿ÿÁœ½ÿœ»ÿÁ›»ÿÁœ½ÿÀ�¿ÿÀ�¿ÿÀœ¾ÿÁœ½ÿ›ºÿšµÿÚ²ÿÙ°ÿÙ°ÿدÿÙ®ÿĘªÿÄ—¨ÿÅ—¦ÿÅ—¥ÿÅ—£ÿÄ–¢ÿÄ•£ÿÄ•¦ÿ–¨ÿ–ªÿ–ªÿ–«ÿ–ªÿ—ªÿ–ªÿÀ–«ÿ¿–®ÿ¿–¯ÿ¾•°ÿ¾•®ÿ¿•­ÿ¿”¬ÿ¾“«ÿ½’¬ÿ¼’­ÿº’¯ÿ¸’³ÿµ‘¶ÿ³�¸ÿ±Ž¸ÿ°�¹ÿ¯Œ¸ÿ®‹¸ÿ¬‹¹ÿ¬‹¹ÿ¬‹¸ÿ¬‹·ÿ¬Š¶ÿ­Š¶ÿ®‹·ÿ®‹¸ÿ¯Œ¹ÿ°�¹ÿ±Ž»ÿ±Ž¼ÿ±�¼ÿ°Ž¼ÿ°Ž½ÿ¯�¼ÿ¯�ºÿ°�»ÿ¯�¼ÿ®Ž¾ÿ®ŽÁÿ¯�Åÿ®�Çÿ®�Èÿ®‘Èÿ¯�Èÿ¯�Çÿ¯�Çÿ¯�Èÿ°�Èÿ±‘Åÿ´’Àÿ·’»ÿ¹‘¶ÿº�°ÿ»�¬ÿ¼�ªÿ½�¨ÿ½�§ÿ¼�§ÿ¼�¨ÿ»�ªÿº�«ÿº�«ÿºŽ«ÿ¹Ž¬ÿ¸Ž­ÿ·Ž¯ÿ·�¯ÿ·�­ÿ·Œ¬ÿ·Œ«ÿ¸Œ©ÿ·‹¦ÿ·Š¤ÿ¸Š£ÿ·‰¢ÿ·‰¢ÿ¶ˆ¢ÿ¶ˆ£ÿ¶ˆ£ÿ´‡£ÿ³†¤ÿ²†¥ÿ²†¦ÿ²‡¨ÿ³‡©ÿ²‡¬ÿ²ˆ®ÿ±ˆ®ÿ±ˆ­ÿ²‡ªÿ±†©ÿ¯…©ÿ¯„¨ÿ¯ƒ¦ÿ­‚¤ÿ¬�¢ÿ¬€Ÿÿ­›ÿ®~—ÿ¯~“ÿ°}�ÿ°|�ÿ¯|�ÿ¯|‘ÿ®|“ÿ­|”ÿ¬|•ÿ¬|–ÿ¬}—ÿ¬~šÿ«~�ÿª~œÿ«}šÿª|™ÿ©|™ÿ©{™ÿ©{šÿ¨{›ÿ©{™ÿ©z–ÿªy’ÿªz“ÿ©{•ÿ©{—ÿª{–ÿ©{˜ÿ¨{šÿ¨{œÿ§{žÿ§{Ÿÿ¦{Ÿÿ¥yŸÿ¤x�ÿ¢vœÿ¢v›ÿ¢ušÿ¡u˜ÿŸt—ÿ�s˜ÿœr™ÿ›s›ÿšrœÿšr�ÿšr�ÿ™r�ÿ™rœÿ™ržÿ™rŸÿ™rŸÿ˜ržÿ™r�ÿšr�ÿšrœÿšr›ÿšršÿ™p—ÿ™o•ÿ™n“ÿ™n’ÿšo’ÿœp’ÿžp�ÿ pŒÿ¡qŒÿ qŒÿŸoŠÿŸm†ÿžlƒÿœl‚ÿ›k�ÿ›k…ÿšlŒÿ˜m’ÿ–m”ÿ•l•ÿ”l•ÿ”l–ÿ”l•ÿ•k“ÿ”k‘ÿ“i�ÿ‘g�ÿ‘g�ÿ’g�ÿ’gŽÿ’gŽÿ’h�ÿ“i�ÿ”i�ÿ•k�ÿ–k�ÿ—k�ÿ—kŽÿ—kŽÿ—j‹ÿ˜i‡ÿ™i‡ÿ˜i‰ÿ—i‹ÿ–i�ÿ–jŽÿ•iŽÿ”h�ÿ”hŽÿ”hŽÿ”hŽÿ”gŒÿ•g‡ÿ–fƒÿ—e�ÿ»™¿ÿ»šÀÿ¼›Áÿ½›Áÿ¾œ¿ÿ¾œ¿ÿÀ�ÀÿÀ�ÁÿÀžÁÿž¿ÿÃ�¼ÿÜ»ÿœºÿܼÿÂ�¾ÿÂ�¾ÿÂ�¾ÿÃ�¼ÿÄœºÿÄ›µÿÄ›²ÿÄš±ÿÄš°ÿÄš°ÿÄš¯ÿÄ™®ÿÅ™«ÿÅ™¨ÿÅ™§ÿŘ¥ÿؤÿÆ—£ÿÅ—¥ÿÄ—¨ÿתÿתÿשÿשÿשÿרÿ–©ÿÁ–«ÿÁ—­ÿÀ–®ÿ¿•­ÿ¿•«ÿ¿•«ÿ¿•«ÿ¿”«ÿ¾“«ÿ¼“­ÿº“°ÿ·’´ÿµ‘·ÿ³�·ÿ²�¸ÿ°Ž¸ÿ¯Œ¹ÿ®‹¹ÿ­‹¹ÿ¬‹¹ÿ«‹¸ÿ¬‹·ÿ­‹¶ÿ®‹·ÿ¯‹·ÿ¯Œ·ÿ°�¸ÿ±Ž¹ÿ²�¹ÿ²�¹ÿ±Žºÿ±Ž»ÿ±Žºÿ°Žºÿ°Žºÿ°�¼ÿ¯�Àÿ®�Äÿ¯�Èÿ®‘Êÿ­’Ëÿ­’Ëÿ®‘Ëÿ®‘Êÿ®�Êÿ®‘Êÿ®‘Êÿ¯�Èÿ²‘Ãÿµ‘¿ÿ¸‘¸ÿº�°ÿº�«ÿ¼�ªÿ¼�ªÿ¼�«ÿ»�«ÿ»�¬ÿ»�¬ÿº�¬ÿº�­ÿº�®ÿ¹�°ÿ·�°ÿ·�²ÿ·Ž²ÿ¶�¯ÿ¶Œ­ÿ·Œ¬ÿ·Œªÿ·‹¨ÿ·Š¦ÿ·Š¤ÿ¶‰¤ÿ¶‰¥ÿµ‰¦ÿ´‰¦ÿ´ˆ¦ÿ´ˆ¥ÿ³‡¦ÿ²‡©ÿ±‡¬ÿ°ˆ®ÿ°ˆ°ÿ°ˆ²ÿ±ˆ±ÿ°‰¯ÿ±ˆ®ÿ²‡¬ÿ±†ªÿ°…ªÿ°…ªÿ¯ƒ¨ÿ®‚¤ÿ¬� ÿ­€�ÿ­~™ÿ®~–ÿ¯~”ÿ¯}’ÿ¯}’ÿ®|“ÿ®}•ÿ®}–ÿ®}—ÿ¬}˜ÿ¬}—ÿ­~—ÿ­~™ÿ¬~›ÿ«~›ÿ«}šÿ«|™ÿ©|™ÿ©{™ÿ©{šÿ©{šÿ©z™ÿ©z—ÿªz”ÿª{”ÿª{•ÿª{—ÿª{—ÿ©{˜ÿ©{šÿ©{›ÿ¨|œÿ¨|�ÿ§|žÿ¦zžÿ¥yžÿ£x�ÿ¢vœÿ¢vœÿ¡ušÿŸušÿœtšÿ›sœÿšsžÿ™sžÿ™rŸÿ™rŸÿ˜ržÿ˜r�ÿ˜qŸÿ™r ÿ™rŸÿ™ržÿ™ržÿ™ržÿšr�ÿšr›ÿ›r™ÿ›p–ÿšo”ÿšo’ÿ›o‘ÿ�p‘ÿžpŽÿ p‹ÿ¡p‰ÿ¡pˆÿ pˆÿŸo†ÿŸm‚ÿŸl€ÿ�lÿ›l€ÿ›l„ÿ™kŒÿ˜l’ÿ–l”ÿ•l–ÿ•m–ÿ”l–ÿ•k•ÿ•k“ÿ•j‘ÿ“i�ÿ“h�ÿ“h�ÿ’h‘ÿ’i’ÿ’j“ÿ“j’ÿ”j‘ÿ•k�ÿ–k�ÿ—k�ÿ—kŽÿ—k�ÿ—k�ÿ—kŽÿ˜jŒÿ˜j‹ÿ˜jŒÿ–jŽÿ–j�ÿ•j‘ÿ”j‘ÿ”i‘ÿ”i‘ÿ“i’ÿ“i’ÿ“h�ÿ”gŠÿ•g…ÿ–f„ÿ¼›Äÿ¼›Äÿ¼œÅÿ½œÅÿ¾œÃÿ¿�ÁÿÀ�ÀÿÁžÀÿÁž¿ÿÞ½ÿÄ�ºÿÄ�ºÿÄ�ºÿÄžºÿÄž¼ÿÄž¼ÿÄž¼ÿÅž»ÿÅ�¹ÿÅœ¶ÿÅœ´ÿÆœ²ÿÆ›±ÿÆ›°ÿÅ›°ÿÅš°ÿÅ™®ÿÅš«ÿÅš©ÿÅ™¨ÿÆ™§ÿÆ™¦ÿÆ™§ÿÅ™ªÿÄ™¬ÿŘ«ÿĘ©ÿשÿÄ—¨ÿÄ—¨ÿÖ§ÿÖ¨ÿ—ªÿ—«ÿÀ–¬ÿÀ•ªÿÀ–«ÿ¿–¬ÿ¿•¬ÿ¿•­ÿ½•®ÿ¼”¯ÿº“²ÿ·’µÿµ’·ÿ´�¸ÿ²�¹ÿ±Žºÿ°�ºÿ®Œ¹ÿ­‹¹ÿ¬‹¸ÿ¬‹¸ÿ®‹¸ÿ¯‹¸ÿ¯‹·ÿ¯Œ·ÿ°�¸ÿ±�¸ÿ²Ž¸ÿ²Ž·ÿ³Ž¸ÿ³Ž¸ÿ³Ž¸ÿ²Ž¹ÿ±�ºÿ±�¼ÿ±’Áÿ°“Åÿ¯’Éÿ®“Íÿ­“Îÿ­“Ïÿ­’Îÿ®‘Ìÿ®‘Ëÿ­’Ëÿ®‘Êÿ¯�Èÿ°�Ãÿ´�¿ÿ·‘¸ÿ¹�°ÿº�«ÿ»�«ÿ»�®ÿ»‘°ÿ»‘±ÿ»‘°ÿ»‘¯ÿ»‘¯ÿº‘¯ÿº‘±ÿº‘³ÿ¸�´ÿ·�µÿ·�´ÿ¶Ž±ÿ¶�¯ÿ¶Œ®ÿ¶Œ®ÿ¶Œ¬ÿ¶‹©ÿ¶‹¨ÿ¶‹¨ÿµ‹ªÿµŠ«ÿ´Š«ÿ´‰ªÿ´ˆ©ÿ³ˆªÿ²ˆ®ÿ°‰±ÿ®‰´ÿ®‰¶ÿ®‰¶ÿ¯‰²ÿ°ˆ®ÿ±ˆ­ÿ²ˆ¬ÿ±†ªÿ±…¨ÿ°„¨ÿ°ƒ¦ÿ¯‚¡ÿ®��ÿ®€›ÿ¯˜ÿ¯~–ÿ¯~•ÿ®~•ÿ®~•ÿ­}—ÿ­~˜ÿ­~šÿ®~›ÿ­~šÿ®~˜ÿ®~—ÿ®~˜ÿ­~šÿ¬~šÿ¬}šÿ«}™ÿª|šÿª{šÿª{™ÿª{™ÿª{™ÿª{˜ÿ«{˜ÿ«|˜ÿ«|™ÿ«{™ÿª{˜ÿ©z—ÿ©{˜ÿª{™ÿ©|šÿ©|œÿ¨}�ÿ§{žÿ¦zžÿ¤xžÿ¢wžÿ¡v�ÿ v�ÿžv�ÿœu�ÿštŸÿ˜s ÿ˜s ÿ˜sŸÿ˜ržÿ˜r�ÿ˜qžÿ—q ÿ˜r¡ÿ˜r ÿ˜rŸÿ˜ržÿ˜ržÿ™r�ÿ›r›ÿœršÿœq—ÿœp”ÿœo’ÿ�p�ÿ q�ÿ¡qŠÿ¢p‡ÿ¢p†ÿ¢p‡ÿ¡o†ÿ n„ÿŸm€ÿ m~ÿžl~ÿœl�ÿšl†ÿ˜l�ÿ—l‘ÿ–l“ÿ•l•ÿ•m–ÿ–l•ÿ–l”ÿ–k“ÿ–j“ÿ”i’ÿ”i’ÿ”i’ÿ“j”ÿ“k•ÿ“k•ÿ”k”ÿ•k“ÿ–k‘ÿ–k�ÿ—k�ÿ—k�ÿ˜l�ÿ˜l’ÿ˜l‘ÿ—l�ÿ˜k�ÿ—k�ÿ—k�ÿ–k’ÿ•k“ÿ”j“ÿ”j“ÿ”j“ÿ”j”ÿ“i“ÿ”h�ÿ”gŒÿ”gˆÿ”gˆÿ¼œÇÿ»œÇÿ¼�Çÿ¼�Çÿ½�Æÿ¿�ÃÿÁžÀÿÁž¾ÿž½ÿÞ¼ÿÅž¹ÿÅž¹ÿÅž¹ÿÅž¹ÿÅž¹ÿÆŸ¹ÿÆžºÿÆžºÿÆ�¸ÿÆ�¶ÿÇ�´ÿÇ�³ÿÇ�±ÿÇœ¯ÿÇ›®ÿÆš®ÿÆš®ÿÆš­ÿÆš¬ÿÆšªÿÇš©ÿÇšªÿÆš«ÿÆš­ÿÅš®ÿÆ™¬ÿŘªÿبÿʨÿÄ—§ÿÄ–¦ÿÖ§ÿרÿ—©ÿÁ—«ÿÁ–ªÿÁ•«ÿÁ–­ÿÀ–®ÿ¾–¯ÿ¾–°ÿ½•°ÿ¼•²ÿº”´ÿ¹”·ÿ·“¹ÿµ’ºÿ³‘»ÿ²�ºÿ°�¹ÿ¯Œ¸ÿ®‹¸ÿ®‹¸ÿ®‹¹ÿ®‹¹ÿ®Œ¸ÿ¯�¹ÿ°�¹ÿ°�¹ÿ²Ž¹ÿ³Ž¸ÿ³�·ÿ´�·ÿ´�·ÿ´�·ÿ³�¹ÿ³‘¼ÿ³“Àÿ²”Äÿ±•Éÿ¯•Íÿ®”Ðÿ­”Ñÿ­“Ïÿ­’Íÿ­’Ìÿ®‘Ëÿ®‘Êÿ¯�Çÿ¯�Ãÿ²�¾ÿµ�¸ÿ¹�±ÿº�­ÿº�­ÿº‘²ÿº‘´ÿº‘´ÿ»‘³ÿ¼’²ÿ¼’²ÿ»‘±ÿº‘²ÿº‘µÿ¹‘·ÿ¸�·ÿ·�´ÿ·�³ÿ·Ž²ÿ¶�±ÿ¶�±ÿ¶Œ°ÿµŒ­ÿµŒ¬ÿµŒ¬ÿµŒ®ÿµ‹¯ÿµŠ®ÿ´Š­ÿ´Š¬ÿ³‰¯ÿ±Š³ÿ¯‹·ÿ­Šºÿ­‰»ÿ¬Šºÿ®‰´ÿ°‡®ÿ±‡¬ÿ²‡«ÿ²‡§ÿ±…¤ÿ±„¤ÿ°ƒ¢ÿ°‚žÿ°��ÿ°�œÿ¯€šÿ¯˜ÿ®~˜ÿ¯˜ÿ­™ÿ­~šÿ¬œÿ¬�ÿ­�ÿ®~›ÿ®~˜ÿ¯~—ÿ®}—ÿ®šÿ­~œÿ«~œÿ«~�ÿ«~œÿª|›ÿª|šÿª|šÿª|šÿª{›ÿª|�ÿª|žÿª|�ÿ«|šÿª{–ÿª{•ÿ©{–ÿ©{˜ÿ©|šÿ©}�ÿ©}Ÿÿ¨|Ÿÿ¦{ ÿ¤y ÿ¢wŸÿ wŸÿŸvŸÿžv ÿœu ÿ›t¡ÿ˜s¡ÿ—r ÿ—sŸÿ˜sžÿ˜r�ÿ˜qŸÿ—r¡ÿ—r¢ÿ—r¡ÿ—rŸÿ˜ržÿ˜q�ÿ™rœÿšrœÿ›q›ÿœr™ÿ�q–ÿžq’ÿŸpŽÿ p‰ÿ¢q‡ÿ£p†ÿ£p†ÿ¢p‡ÿ¡o†ÿ m‚ÿ¡mÿ m~ÿŸm€ÿœlƒÿšl‰ÿ˜lŽÿ—l�ÿ–l’ÿ•l”ÿ–l”ÿ—l”ÿ–l“ÿ–l“ÿ–k•ÿ”j”ÿ”j“ÿ”j“ÿ”k•ÿ”l–ÿ”l•ÿ•k”ÿ•l“ÿ–l‘ÿ—l�ÿ—k�ÿ˜l�ÿ™l’ÿ˜l”ÿ˜m”ÿ˜m“ÿ˜l’ÿ—k’ÿ—k’ÿ—l“ÿ–l•ÿ•k”ÿ•j”ÿ•j•ÿ•j•ÿ”i“ÿ”i‘ÿ”hŽÿ“gŒÿ’gŽÿ»žÉÿ¼žÉÿ½žÉÿ½žÉÿ½žÇÿ¾žÄÿÀžÀÿž¾ÿÃ�¼ÿÄž»ÿÄž¹ÿÅž¹ÿÅž¹ÿÅžºÿÆž¹ÿÆŸ¸ÿÆŸ¹ÿÆž¹ÿÇž¹ÿÇž·ÿÆžµÿÇž²ÿÈž°ÿÈ�®ÿÈœ«ÿÈœ«ÿÈœ¬ÿÇœ®ÿÇœ®ÿÈœ­ÿÈœ¬ÿÈœ¬ÿÇœ¯ÿÇœ°ÿÆœ°ÿÇš­ÿÆ™©ÿبÿبÿʧÿʦÿÄ—§ÿÄ—¨ÿרÿĘ©ÿÄ—¨ÿÖ©ÿÁ–«ÿÁ–®ÿÀ–¯ÿ¾–°ÿ¾–±ÿ½–²ÿ¼–´ÿ»•µÿ¹•¶ÿ·“¸ÿµ’¸ÿ´‘¸ÿ³�·ÿ±Ž·ÿ°�·ÿ¯Œ¸ÿ¯Œ¸ÿ¯�¹ÿ­�ºÿ®Ž»ÿ¯�¼ÿ¯�»ÿ±Žºÿ²Ž¹ÿ³�·ÿ´�·ÿµ�·ÿ¶‘·ÿ¶‘¹ÿµ’»ÿ´“¾ÿ´”Áÿ³”Åÿ±•Ëÿ¯–Ïÿ®•Ðÿ®”Ðÿ­“Ïÿ¬“Íÿ­’Ìÿ®’Êÿ¯‘Çÿ¯�Ãÿ°�Áÿ²�¼ÿµ�·ÿ¸�³ÿ¹‘´ÿº’¶ÿ¹‘¶ÿº‘´ÿº’³ÿ»’³ÿº’²ÿº‘±ÿº‘³ÿ¹’¶ÿ·’¹ÿ·’¸ÿ·�¶ÿ¶�µÿ¶�µÿ¶�´ÿµ�´ÿµ�³ÿµ�±ÿµŒ°ÿµ‹®ÿ´‹­ÿ´‹¬ÿ´Š«ÿ´Š«ÿ²Š®ÿ±Š³ÿ¯‹·ÿ®‹»ÿ¬‹¾ÿª‹¿ÿ«‹¾ÿ­‰¶ÿ¯‡¯ÿ±†«ÿ²‡ªÿ³‡¦ÿ²…¡ÿ±„ ÿ±ƒŸÿ±��ÿ°�žÿ¯��ÿ¯�›ÿ®€šÿ­™ÿ®šÿ­~šÿ­œÿ¬žÿ¬€ ÿ¬€Ÿÿ­œÿ®˜ÿ®~–ÿ®}˜ÿ®�ÿ­ ÿ«¡ÿª~¡ÿª~Ÿÿª}�ÿ©}�ÿ©}�ÿ©}�ÿ©} ÿ©}¢ÿ©}¢ÿ©}žÿª|™ÿ«{—ÿ«{–ÿª{–ÿ©|™ÿ¨|œÿ¨| ÿ¨| ÿ¨|¡ÿ¦{¡ÿ¤z¡ÿ£y¡ÿ w¡ÿŸw¡ÿ�v¡ÿœu¡ÿ›t¡ÿ™sŸÿ—rŸÿ—ržÿ—ržÿ—q�ÿ–qžÿ—r¡ÿ—r¢ÿ–r¡ÿ–ržÿ—qœÿ˜q›ÿ™rœÿšsœÿ›sœÿœsšÿ�r–ÿŸr’ÿ q�ÿ¡q‰ÿ¢q‡ÿ¢p‡ÿ¢p‡ÿ¡p†ÿ o…ÿ m‚ÿ¡mÿ mÿžm‚ÿœl†ÿšm‹ÿ˜lŽÿ–l�ÿ•l’ÿ–l“ÿ—k“ÿ—l“ÿ—m“ÿ—m“ÿ–m”ÿ–l•ÿ•k”ÿ•k“ÿ•l”ÿ”l”ÿ•l“ÿ•l’ÿ–l‘ÿ—l‘ÿ˜l‘ÿ˜m‘ÿ™m’ÿ™m”ÿ™m–ÿ™n–ÿ˜n•ÿ˜m“ÿ˜l“ÿ˜l“ÿ—m“ÿ–l•ÿ–l–ÿ•k•ÿ”j”ÿ•j”ÿ”k•ÿ“j“ÿ“i’ÿ“i’ÿ“i’ÿ¼ŸÊÿ½ŸÊÿ¾ŸÊÿ¾ŸÉÿ¾ŸÈÿ¿ŸÅÿÀŸÃÿÁŸÁÿÞ¿ÿÄŸ¼ÿÅžºÿÅžºÿÅžºÿÅž¹ÿÆŸ¹ÿÆž¸ÿÆŸ¸ÿÇŸ¹ÿÇŸ¹ÿÇŸ¸ÿÇŸµÿÈŸ²ÿÉž¯ÿÉ�¬ÿÉ�¨ÿÉœ¦ÿÉœªÿÈ�­ÿÈ�®ÿÈ�­ÿÉ�­ÿÈ�®ÿÈ�°ÿÈ�±ÿÇ�°ÿÈœ¬ÿÇš©ÿÇ™§ÿÇ™§ÿÅ™§ÿÅ™§ÿÅ™©ÿÅ™©ÿÅ™©ÿÅ™©ÿÅ™§ÿاÿÄ—¨ÿתÿ—­ÿ¿—¯ÿ¾—²ÿ¾—´ÿ½–µÿ¼–µÿ»–µÿº•¶ÿ¹”¶ÿ·’¶ÿ¶‘¶ÿ´�¶ÿ³Ž·ÿ±Ž·ÿ°�¸ÿ¯Žºÿ®Ž¼ÿ®Ž½ÿ®Ž½ÿ¯Ž¼ÿ°Ž»ÿ²�ºÿ³�¹ÿ´�¸ÿµ‘·ÿ·“¸ÿ·“¹ÿ·”ºÿ¶”¼ÿ¶”¾ÿµ”Ãÿ³•Éÿ±–Íÿ°–Ïÿ°”Ïÿ®”Ïÿ­”Îÿ®”Îÿ®“Ëÿ¯’Èÿ¯�Äÿ¯�Ãÿ°ŽÀÿ²Ž¼ÿ´�ºÿ¶‘ºÿ¸’¹ÿ¹’¸ÿº’¶ÿº’´ÿ»’³ÿ»’²ÿº‘±ÿº’´ÿ¹“¸ÿ·“ºÿ¶’ºÿ¶‘ºÿµ‘ºÿµ�¹ÿµ�¹ÿ´�¸ÿ´Ž·ÿ´Žµÿ´�²ÿ´‹¯ÿ´‹¬ÿ´‹ªÿ´Šªÿ³Š¬ÿ²‹±ÿ°‹¶ÿ¯Š¹ÿ­‹¼ÿªŠÀÿ¨‰ÁÿªŠÀÿ¬Š¸ÿ¯ˆ±ÿ°‡­ÿ±‡«ÿ²†¦ÿ²…¡ÿ²ƒŸÿ²ƒžÿ±‚�ÿ±ƒžÿ°‚žÿ¯‚�ÿ¯��ÿ®€žÿ­€žÿ®€�ÿ­€žÿ¬� ÿ¬�¢ÿ¬€¢ÿ­€žÿ­šÿ­~™ÿ­›ÿ­€ ÿ¬€£ÿ«€¤ÿª¤ÿª£ÿª~¡ÿª~¡ÿª~ ÿª~Ÿÿª~¡ÿª~£ÿ©}¡ÿ©}žÿ©}œÿª|œÿª|›ÿ©|šÿ¨|�ÿ¨| ÿ§|¢ÿ§}£ÿ§}£ÿ¦|£ÿ¥{£ÿ£z¢ÿ¢y¢ÿ x¢ÿŸw¡ÿžužÿ�tœÿœsœÿ™s�ÿ˜r�ÿ˜q�ÿ˜q�ÿ—ržÿ—r ÿ˜r ÿ—ržÿ—rœÿ˜qšÿ˜q™ÿ™r›ÿšs�ÿœtœÿ�t™ÿžs•ÿŸr‘ÿ rŽÿ¡q‹ÿ¡qŠÿ¡p‰ÿ¡pˆÿ o†ÿ o„ÿ n‚ÿ¡n�ÿ nƒÿŸn†ÿœn‰ÿ›nŒÿ™m�ÿ—m‘ÿ–m“ÿ˜m“ÿ—l“ÿ˜m’ÿ™m’ÿ™n’ÿ˜n“ÿ—l“ÿ–l“ÿ–l’ÿ–l“ÿ–l“ÿ—l’ÿ—l‘ÿ—l�ÿ˜l‘ÿ™m’ÿ™n”ÿ˜n•ÿ˜n—ÿ˜n˜ÿ˜o—ÿ˜n–ÿ˜m•ÿ™m”ÿ˜m•ÿ˜n•ÿ–m–ÿ–m—ÿ•l–ÿ•l•ÿ•l•ÿ”k–ÿ“k•ÿ“j•ÿ’j–ÿ’j–ÿ½ŸÊÿ¾ŸÊÿ¿ Ëÿ¿ Êÿ¿ ÉÿÀ ÆÿÁ Åÿ ÃÿàÁÿÄŸ¾ÿÄŸ»ÿÅŸ»ÿÆžºÿÆŸ¹ÿÆŸ¸ÿÆŸ·ÿÆž·ÿÇŸ¸ÿÇŸ¸ÿÇ ·ÿÈ µÿÊŸ±ÿÊž®ÿÊ�ªÿË�¦ÿË�¥ÿË�¨ÿËžªÿÊžªÿÉž«ÿÉž­ÿÉž°ÿÉ�±ÿÈž±ÿÉ�¯ÿÉ�¬ÿÉ›¨ÿÉ›¦ÿÈ›§ÿÈ›¨ÿÈ›¨ÿÇ›ªÿÇ›«ÿÇ›«ÿÆ›«ÿÆš¨ÿÆ™¦ÿÆ™¦ÿاÿĘ©ÿ˜­ÿÀ˜°ÿ¿˜³ÿ¿—µÿ½–µÿ¼–µÿ»•µÿ»”µÿº“´ÿ¸“µÿ·’µÿµ‘¶ÿ³�·ÿ²�¹ÿ±�ºÿ°�½ÿ¯Ž½ÿ¯Ž¼ÿ°Ž»ÿ±�»ÿ³�ºÿ³�ºÿ´�¹ÿµ‘¸ÿ¸“¸ÿ¸”¸ÿ¸”¹ÿ¸•»ÿ¸•¾ÿ·–Âÿµ—Éÿ´—Ìÿ³—Ìÿ³–Ìÿ±–Ìÿ°•Íÿ°•Íÿ°”Ìÿ±“Éÿ°’Çÿ°‘Æÿ°�Ãÿ°ŽÁÿ±ŽÀÿ³�¿ÿ¶’½ÿ¸’»ÿ¹“¹ÿº“·ÿº’´ÿº’³ÿº’³ÿº’µÿ¹“¹ÿ·“¼ÿ¶’½ÿµ’¿ÿ´’¿ÿ´‘¾ÿ³�½ÿ³�½ÿ´�ºÿ´Ž·ÿ´�´ÿ´‹°ÿ´‹®ÿ³‹­ÿ²Š®ÿ±‹²ÿ±Œ·ÿ°Œ¹ÿ¯‹¹ÿ§…µÿ•x§ÿ�h•ÿ�s ÿ¦ƒ¯ÿ¯‰³ÿ°‡®ÿ±‡«ÿ±…¥ÿ²„¢ÿ²„ ÿ±ƒ ÿ±ƒŸÿ±„Ÿÿ°ƒŸÿ°ƒ ÿ¯‚¡ÿ®‚¢ÿ­‚¢ÿ­� ÿ­�Ÿÿ­�¡ÿ­�¤ÿ¬€£ÿ¬€ ÿ­�ÿ­�ÿ¬€ ÿ¬€£ÿ¬€¤ÿ¬�¦ÿ«€§ÿ«€§ÿª€¦ÿ«¥ÿª~¡ÿª~Ÿÿª~ ÿª~¡ÿª~ ÿ©}Ÿÿ©~Ÿÿª} ÿª}¡ÿ©}¡ÿ¨}£ÿ§}¤ÿ§|¤ÿ§}¤ÿ§}¤ÿ¦|¤ÿ¥{¥ÿ¤{¥ÿ£z¤ÿ¢y£ÿ¡xŸÿ¡v›ÿ u™ÿ t™ÿ�tšÿœsšÿ›ršÿšr›ÿšr�ÿšs�ÿšr�ÿ™rœÿ™r›ÿ™ršÿ›ršÿœsœÿœsœÿžt›ÿŸt˜ÿŸt•ÿ s’ÿ¡r�ÿ¡r�ÿ¡r�ÿ¡qŒÿ pŠÿ o‡ÿ o…ÿ o„ÿ¡o„ÿ o†ÿžo‰ÿœoŒÿ›o�ÿšn’ÿ˜m”ÿ˜m”ÿ˜m”ÿ˜m”ÿ™n“ÿšn’ÿšn‘ÿ™n‘ÿ˜m‘ÿ—m’ÿ—m’ÿ—l’ÿ—l’ÿ˜m’ÿšm‘ÿšm‘ÿšn“ÿšo–ÿ™o˜ÿ˜o™ÿ—nšÿ–ošÿ–nšÿ–nšÿ—n˜ÿ˜n—ÿ˜o—ÿ˜n˜ÿ—n˜ÿ–m™ÿ–m˜ÿ•m˜ÿ•m˜ÿ”l˜ÿ”k˜ÿ’k™ÿ‘k™ÿ‘kšÿ½ŸËÿ¾ Ëÿ¿ Ìÿ¿¡ÌÿÀ ÊÿÁ ÇÿÁ Åÿ ÄÿàÃÿÄ ÀÿÄ ½ÿÅ ¼ÿÆŸºÿÆŸ¸ÿÆŸ·ÿÆŸ·ÿÇŸ·ÿÇŸ·ÿÇŸ¶ÿÈ ¶ÿÉ ´ÿÊŸ°ÿËž¬ÿËž¨ÿÌž¦ÿÌž¥ÿÌž¥ÿÍž¥ÿÌ�¥ÿÌ�¦ÿËžªÿËž®ÿÊž±ÿÊž±ÿÉž¯ÿÉ�«ÿÊœ§ÿÊœ¦ÿÉœ§ÿÉœ¨ÿÉ›©ÿÉœ«ÿÈœ¬ÿÈœ¬ÿÇœ¬ÿÇ›©ÿÈš§ÿÇ™¥ÿÇ™¥ÿƘ§ÿŘªÿØ­ÿ˜°ÿÀ˜³ÿ¿—´ÿ½–µÿ¼–µÿ»•´ÿ»•´ÿº”³ÿ¹“´ÿ¸“µÿ¶’¶ÿµ‘·ÿ´�¹ÿ³�»ÿ±�»ÿ±Žºÿ²�¹ÿ²�ºÿ³�ºÿ³‘ºÿ´‘¹ÿµ‘¸ÿ¶’¶ÿ¸“·ÿ¸“¹ÿ¹•»ÿ¹–¾ÿ¹—Áÿ·™Èÿ·˜Éÿ¶—Èÿ¶—Çÿµ—Èÿ³–Êÿ²–Ëÿ²•Êÿ²•Éÿ²”Èÿ²“Çÿ°‘Åÿ°�Äÿ¯�Äÿ°�Äÿ³‘Âÿ´’Àÿ¶’½ÿ¸’ºÿ¸’·ÿ¹’¶ÿ¹’¶ÿº’¶ÿ¹“¹ÿ·“½ÿµ’Áÿ´“Âÿ³“Âÿ³’Âÿ³‘Áÿ³�Àÿ³�¼ÿ³Ž¹ÿ³�¶ÿ³Œ³ÿ³‹²ÿ±Œ´ÿ°Œ·ÿ¯Œ»ÿ¯Œ¾ÿ¯�½ÿ®Œ»ÿ£ƒ³ÿ�g�ÿM8Oÿ{_ƒÿ¢©ÿ¯‰³ÿ¯‡®ÿ°†ªÿ±„¥ÿ±„£ÿ±„¢ÿ±„¢ÿ°„¢ÿ°„¢ÿ°„¢ÿ°„£ÿ¯„¥ÿ®ƒ¥ÿ­‚£ÿ­‚¡ÿ­�¡ÿ­�¢ÿ­�¤ÿ­€¡ÿ­€Ÿÿ­€Ÿÿ­€¢ÿ¬€¤ÿ¬€¤ÿ¬€£ÿ¬€¥ÿ¬�§ÿ«�¨ÿ«�§ÿ«€¤ÿª ÿ«žÿª~žÿ«~Ÿÿª~ ÿª~¡ÿª~£ÿª~¥ÿ©¦ÿ¨~¦ÿ¨~§ÿ§~¦ÿ§|¤ÿ§}£ÿ¦}¤ÿ¦}¥ÿ¥|¦ÿ¤{§ÿ¤{¥ÿ¤z£ÿ¤xžÿ¤x˜ÿ¤w–ÿ¢v–ÿ¢u—ÿ¡t—ÿ t˜ÿ�s™ÿœsšÿœsšÿ›sšÿ›ršÿ›r›ÿœsœÿ�tœÿžt�ÿŸtœÿŸtšÿ t˜ÿ t–ÿ¡s”ÿ¢s‘ÿ¢s�ÿ¡r�ÿ rŽÿ qŒÿŸp‰ÿŸo‡ÿ o‡ÿ o‡ÿŸo‰ÿžoŒÿœo�ÿ›p“ÿšp•ÿ™o–ÿ™n–ÿ˜n•ÿ™m”ÿšn“ÿ›n’ÿšn‘ÿšn‘ÿ˜m’ÿ˜m’ÿ˜m’ÿ˜m’ÿ™n“ÿšm“ÿ›n’ÿ›o“ÿ›p–ÿšpšÿ™qœÿ—pžÿ•oŸÿ”oŸÿ”oŸÿ•ožÿ–o�ÿ—pœÿ—p›ÿ—o™ÿ—nšÿ–n›ÿ•m›ÿ•mœÿ”mœÿ”lœÿ“l�ÿ’l�ÿ‘lžÿ�lŸÿ½ Ìÿ½¡Ìÿ¾¡Íÿ¾¡Íÿ¾¡ËÿÀ ÈÿÁ Æÿ ÄÿáÂÿÄ¡ÀÿÅ ¾ÿÆ ½ÿÆ »ÿÆ ¹ÿÇŸ¸ÿÇŸ¹ÿÇ ¸ÿÇ ·ÿÇŸ¶ÿÈŸ¶ÿÉŸ³ÿÊŸ¯ÿÊŸ«ÿËž§ÿËž¥ÿÍŸ¤ÿÍž£ÿÍ�¡ÿÎ�ŸÿÍ� ÿÍž£ÿÌŸ¨ÿÌŸ­ÿËŸ¯ÿÊŸ®ÿÊž¬ÿÊ�¨ÿÊœ§ÿÊœ§ÿÊœ¨ÿÊœªÿÉ�«ÿÉ�¬ÿÈœ¬ÿÈœ«ÿÈœ¨ÿÈ›¦ÿÈš¥ÿÈš¥ÿÇ™¦ÿÆ™¨ÿÅ™ªÿÄ™¬ÿØ®ÿÁ˜°ÿ¿—²ÿ½—³ÿ¼–³ÿ»–²ÿ»•³ÿ»”³ÿº”³ÿ¹“³ÿ¸’µÿ·’·ÿ¶‘·ÿ´‘¶ÿ´�¶ÿ´�·ÿ³�¸ÿ³�¹ÿ³�¸ÿ²�·ÿ²�¶ÿ´�¶ÿ·’·ÿ¸“ºÿ¹•¼ÿ¹–¾ÿ¹—Áÿ¸™Äÿ¸˜Ãÿ¹˜Ãÿ¸˜Äÿ·˜Åÿ¶—Æÿµ—Çÿµ—Éÿ´–Éÿ³•Èÿ³”Çÿ²”Çÿ²“Çÿ°“Çÿ¯‘Çÿ¯�Æÿ°�Åÿ²’Âÿ´’¿ÿ¶’¼ÿ·’¹ÿ·’¸ÿ¸’¸ÿ·“ºÿµ“¾ÿ´’Äÿ²“Åÿ²’Åÿ²’Äÿ²’Äÿ³�Áÿ±�½ÿ±�»ÿ±Ž¹ÿ±�¹ÿ°Œ¸ÿ®�½ÿ­�Áÿ¬�Ãÿ¬�Ãÿ­�Àÿ­Œ¾ÿ©‹Àÿ�t¤ÿ\Fdÿ”u£ÿ©†´ÿ®‰´ÿ®‡¯ÿ¯†«ÿ°…¦ÿ°„¥ÿ°„¥ÿ°„¦ÿ¯„¤ÿ°…¤ÿ°…¥ÿ°…¦ÿ¯…§ÿ®„¦ÿ®‚£ÿ®‚¡ÿ­‚¡ÿ¬‚£ÿ­‚£ÿ®�Ÿÿ®�žÿ­� ÿ¬�¤ÿ­�¥ÿ¬�¤ÿ¬€¢ÿ¬€£ÿ¬�¥ÿ«�¦ÿ¬�¤ÿ«€¡ÿ¬€Ÿÿ¬€�ÿ«žÿ«~ ÿª¢ÿ©¤ÿ©¦ÿª©ÿ©€©ÿ¨¨ÿ¨¨ÿ¨~¦ÿ§}£ÿ§}¢ÿ¦}£ÿ¦}¥ÿ¦}§ÿ¥|§ÿ¥|¥ÿ¥z¡ÿ¥yœÿ¦x—ÿ§x”ÿ¥w“ÿ¤v”ÿ¤v•ÿ¢u—ÿŸu˜ÿ�t™ÿœtšÿœt›ÿœs›ÿœs›ÿ�u�ÿ�užÿžužÿŸu�ÿ u›ÿ ušÿ¡t˜ÿ¡t–ÿ¡s”ÿ¡r“ÿ r’ÿŸr‘ÿŸq�ÿžp�ÿžpŒÿŸo‹ÿ p‹ÿŸpŒÿ�p�ÿœp“ÿšp–ÿ™p˜ÿ™p˜ÿ™p˜ÿ™o–ÿ™n”ÿšn“ÿšn’ÿšn“ÿ™o”ÿ˜m”ÿ˜m”ÿ˜n”ÿ™n“ÿšo“ÿ›n’ÿ›o“ÿ›p•ÿ›p˜ÿ™q�ÿ—q¡ÿ–p¢ÿ”p¢ÿ”p£ÿ”p£ÿ”p¢ÿ–q¢ÿ—q ÿ—pžÿ–p›ÿ–oœÿ•ožÿ”oŸÿ”n¡ÿ“n¢ÿ“m¢ÿ’m¢ÿ’m£ÿ‘m¤ÿ�l¤ÿ¼ Ìÿ½ Ëÿ¾¡Ìÿ¾¡Îÿ¾¢Ïÿ¿¢ÌÿÁ¢Éÿ¢ÆÿâÃÿÄ¡ÁÿÆ¡¿ÿÆ¡¿ÿÆ¡½ÿÇ¡»ÿÇ ºÿÇ ¸ÿÇ ·ÿÇ ·ÿÈ ¶ÿÈ ¶ÿÈ ´ÿÉŸ±ÿÊŸ«ÿÊž§ÿË�£ÿÌž£ÿÍž¢ÿΞ ÿΞžÿÏžžÿÏŸŸÿÍž¡ÿÌž§ÿÌž«ÿÌŸ­ÿËŸ­ÿËž«ÿËž©ÿË�¨ÿË�§ÿÊ�¨ÿÊ�ªÿÉ�«ÿÉ�«ÿÉ�«ÿÉœ¨ÿÉ›¦ÿÉ›¥ÿÉ›¦ÿÈ›§ÿÇ›§ÿÆš¨ÿÆšªÿÅš¬ÿÙ¬ÿ˜­ÿÁ—®ÿ¿—®ÿ¾–¯ÿ½–±ÿ¼–²ÿ»•²ÿº”³ÿº”´ÿ¹”µÿ¹“´ÿ¸’±ÿ¸‘±ÿ·‘³ÿ¶‘µÿµ’·ÿ´�¸ÿ±Ž·ÿ°�·ÿ²�¸ÿ´‘ºÿ¶”¾ÿ¸–Àÿ¸—Áÿ¹˜Ãÿº˜Âÿº˜Áÿ¹˜Âÿ¹™Ãÿ¹™Ãÿ¸˜Ãÿ·˜Åÿ¶˜Éÿµ—Ëÿµ—Ëÿ´–Éÿ´–Éÿ³–Éÿ²•Éÿ°’Èÿ¯�Æÿ®‘Æÿ¯‘Æÿ±‘Äÿ³’Áÿ³‘¿ÿ´’¾ÿ´’½ÿ´’¾ÿ³’Âÿ±’Çÿ°’Êÿ°’Éÿ°‘Çÿ±‘Åÿ±�Âÿ°�Àÿ°�¾ÿ°�¾ÿ¯Ž¾ÿ­�¿ÿ«ŽÄÿªŽÈÿ©ŽÈÿ©�ÇÿªŒÆÿª�Åÿ¬‘Íÿ–~´ÿdOrÿ¡…¾ÿ¬ŒÀÿ¬‰·ÿ®‡²ÿ¯†­ÿ°†©ÿ¯†¨ÿ°…¨ÿ°…¨ÿ°†§ÿ°…¦ÿ±…¦ÿ°…¦ÿ¯…¥ÿ®„£ÿ¯ƒ¢ÿ®‚¡ÿ­‚¢ÿ­‚¢ÿ®‚¡ÿ­�Ÿÿ­‚ ÿ¬‚£ÿ¬‚¦ÿ«‚¦ÿ¬‚¤ÿ¬�£ÿ¬�¤ÿ¬�¥ÿ¬�¥ÿ­�¥ÿ¬€¢ÿ¬€Ÿÿ¬€žÿ«žÿª¡ÿ©~£ÿ¨¥ÿ¨©ÿ¨€¬ÿ¨€ªÿ¨¨ÿ¨~§ÿ¨~¦ÿ§}¤ÿ¦|£ÿ§}¤ÿ¦}¥ÿ¥}¥ÿ¦|£ÿ¦{¡ÿ¦zžÿ¦y™ÿ§y–ÿ¨x”ÿ¨x“ÿ¦x“ÿ¥w”ÿ£v–ÿ u˜ÿžušÿ�u�ÿ�u�ÿžtœÿ�t›ÿ�tœÿžužÿŸvžÿ vŸÿ¡vŸÿ vžÿ všÿ¡u˜ÿ¡t—ÿ¡s—ÿŸs–ÿŸs–ÿžr•ÿ�q“ÿ�p�ÿžp�ÿžp�ÿ�p�ÿœp“ÿšq–ÿ™q˜ÿ˜qšÿ˜qšÿ˜q™ÿ™p˜ÿšp–ÿ™p•ÿšo•ÿ™o–ÿ—o—ÿ—n—ÿ˜n—ÿ™o—ÿ™o–ÿ›p•ÿšo”ÿ›p•ÿ›p–ÿšqšÿ˜rŸÿ–q£ÿ•r¥ÿ•r¦ÿ•r¥ÿ•r¥ÿ–r¥ÿ–r¥ÿ–q£ÿ–q ÿ•pžÿ”p ÿ“p£ÿ’p¦ÿ‘o§ÿ‘n§ÿ‘o§ÿ‘o§ÿ�o§ÿ�n¨ÿ�n§ÿ½ Ëÿ½ Êÿ¾ Ëÿ¾¡Ìÿ¿¡ÍÿÀ¢ÍÿÁ¢Êÿ¢ÇÿÄ¢ÄÿÅ¢ÀÿÆ¢¾ÿÇ¢¾ÿÇ¢¾ÿÇ¡½ÿÇ¡»ÿÈ¡¹ÿÈ¡¸ÿÈ¡·ÿÈ ¶ÿÉ¡´ÿÉ ³ÿÊŸ°ÿÊŸ­ÿÊž©ÿÌž¥ÿÌž£ÿÍž¡ÿΞ ÿÏžŸÿÏŸžÿÏŸŸÿÏž ÿΞ£ÿÍž§ÿÍž©ÿÌŸ«ÿËžªÿËž¨ÿËž¦ÿÌ�¦ÿËž§ÿÊž©ÿÊžªÿÊž«ÿÊž«ÿÊ�©ÿÊœ§ÿÊ›§ÿÉ›§ÿÈœ¨ÿÈ›¨ÿÇ›©ÿÇ›ªÿÆš«ÿÆš¬ÿÄ™¬ÿ˜«ÿÁ—«ÿÁ–­ÿ¿–°ÿ½–±ÿ¼–²ÿ¼–³ÿ»•´ÿ»•´ÿ»“²ÿ»“¯ÿ¼“®ÿ»“¯ÿ¹“²ÿ¸“¶ÿµ‘¸ÿ±Ž¸ÿ¯Œ¹ÿ°Žºÿ±�¼ÿ´“Áÿ¶–Ãÿ¸—Äÿ¸˜Äÿ¹˜Ãÿº˜Âÿº™Äÿ¹™Åÿ¹™Æÿ¹™Åÿ¸˜Åÿ·˜Çÿ¶˜Êÿ¶˜Ìÿµ—Ëÿ´—Ëÿ´—Êÿ´–Éÿ³”Æÿ±’Çÿ¯‘Çÿ®‘Éÿ®’Éÿ°’Èÿ°’Çÿ±’Åÿ±‘Âÿ°�Áÿ¯�Åÿ­‘Êÿ¬‘Íÿ­�Íÿ®‘Ëÿ¯‘Èÿ¯‘Åÿ¯�Âÿ®�Áÿ­ŽÃÿ­ŽÅÿ«ŽÇÿ©ŽÌÿ¨ŽÎÿ¨ŽÍÿ¨ŽÌÿ¨ŽÌÿ¨ŽËÿ¬’Òÿ—¸ÿfQuÿ¢‰Ãÿ¬�Äÿ¬‰¹ÿ­ˆµÿ®‡°ÿ¯‡¬ÿ°‡«ÿ°‡©ÿ°†¨ÿ°†§ÿ°…§ÿ±…¨ÿ°…§ÿ¯„¥ÿ¯„£ÿ¯„£ÿ¯ƒ¤ÿ¯ƒ¤ÿ®ƒ£ÿ®‚¢ÿ­‚¢ÿ¬‚¤ÿ¬‚¦ÿ¬‚¨ÿ«‚¨ÿ¬ƒ§ÿ«‚§ÿ«‚¨ÿ«‚©ÿ«‚©ÿ«‚¨ÿ«�¥ÿ«�£ÿ«€¢ÿª¢ÿ©~¢ÿ©¥ÿ¨€©ÿ¨�¬ÿ§�®ÿ¨€ªÿ¨¨ÿ¨~¦ÿ¨~¦ÿ§~¦ÿ¥}¦ÿ¥|§ÿ¥|§ÿ¦|¥ÿ§|£ÿ¦{ ÿ¦z�ÿ§zšÿ¨z—ÿ§y–ÿ¨x•ÿ§x”ÿ¦x–ÿ¤x˜ÿ¢v™ÿ vœÿžvŸÿžuŸÿŸuœÿžu›ÿžtœÿžvžÿ w ÿ¡w¡ÿ w¢ÿ w¡ÿ vžÿ¡uœÿ¡t›ÿ tšÿŸtšÿžt›ÿ�s›ÿœr™ÿ�r–ÿ�q”ÿ�q“ÿœq•ÿ›q—ÿ™qšÿ˜q›ÿ—q›ÿ˜q›ÿ˜qšÿ˜q™ÿ™p™ÿ™qšÿ˜pšÿ—pšÿ—pšÿ—ošÿ˜p™ÿ™p™ÿ™p™ÿšq˜ÿ›p˜ÿ›q™ÿšr›ÿ˜rŸÿ˜s£ÿ–r¦ÿ–r§ÿ—s§ÿ—s¦ÿ–s¥ÿ–s¥ÿ–r¥ÿ–r£ÿ•q¢ÿ”p£ÿ“q¥ÿ“q©ÿ’q«ÿ’q¬ÿ’p«ÿ‘pªÿ‘pªÿ‘pªÿ�oªÿ�o©ÿ¿ Éÿ¿ Éÿ¿ ÉÿÀ¡ÊÿÀ¡ÊÿÁ¡ËÿÁ¢Êÿ¢ÇÿâÃÿÅ¢¿ÿÇ¢½ÿÇ¢½ÿÇ¢½ÿÇ¢½ÿÇ¡»ÿÈ¡»ÿÈ¡¹ÿÈ¡·ÿÉ¡¶ÿÉ¡³ÿÊ¡²ÿÊ ¯ÿË ¬ÿËŸ©ÿÌž¦ÿÍž¤ÿΞ¢ÿÏž ÿÏŸŸÿÏŸŸÿÏŸŸÿÏŸ ÿÏž¢ÿΞ£ÿΟ¤ÿÍŸ§ÿÍŸ§ÿÌž¥ÿÌ�¤ÿÌž¤ÿÌž§ÿËž©ÿËž«ÿËž­ÿÊž¬ÿÊ�ªÿË�¨ÿÊœ¨ÿÉœ©ÿÈ�©ÿÉ�ªÿÉœªÿÈœ«ÿÇ›¬ÿÇš¬ÿÅš¬ÿÄ™¬ÿجÿ—­ÿÀ—®ÿ¿–¯ÿ¾–°ÿ¾—²ÿ½–³ÿ½–³ÿ½”²ÿ½”°ÿ¾•®ÿ¾•­ÿ½•¯ÿ¼”³ÿ·’¶ÿ³�¸ÿ¯�¹ÿ®�ºÿ®�¼ÿ²’¿ÿ¶–Âÿ·˜Äÿ¸˜Åÿ¸˜Åÿ¸™Åÿ¸™Æÿ¸™Èÿ·™Èÿ¸™Çÿ·˜Çÿ·˜Èÿ¶˜Ëÿµ˜Ìÿµ˜Íÿ´˜Íÿµ—Ìÿµ—Êÿ´•Èÿ²“Èÿ°’Èÿ®’Êÿ­“Íÿ­“Íÿ­’Ìÿ®‘Éÿ®�Æÿ­ŽÄÿ¬�Æÿ«�Ìÿ«�Îÿ«�Îÿ¬‘Ìÿ­‘Êÿ®‘Çÿ®�Äÿ¬ŽÄÿ«ŽÆÿªŽÉÿ§�Íÿ¦�Ñÿ¦�Òÿ¦ŽÑÿ§�Ïÿ¨�Ïÿ¨�Îÿ¬’Òÿ—·ÿfPsÿ¡‡Àÿ¬�Ãÿ¬Š»ÿ­‰¶ÿ­ˆ²ÿ¯ˆ¯ÿ°‡¬ÿ±‡©ÿ±‡¨ÿ±†§ÿ°†¨ÿ°†©ÿ¯…©ÿ®„§ÿ¯„¥ÿ¯„¥ÿ¯„¦ÿ°…¤ÿ°„¢ÿ¯ƒ¤ÿ®ƒ¦ÿ­ƒ¨ÿ¬ƒ©ÿ¬ƒªÿ«ƒ«ÿ«ƒ¬ÿªƒ­ÿ©„¯ÿ©„°ÿ©„¯ÿ©ƒ­ÿ©‚ªÿ©�¨ÿª�¦ÿª€¥ÿª¦ÿ©€¨ÿ©�¬ÿ¨‚®ÿ§�®ÿ§�«ÿ§©ÿ§~¨ÿ§¨ÿ§~¨ÿ¥~©ÿ£|ªÿ£|©ÿ¤|§ÿ¦|¤ÿ¦|¡ÿ§{žÿ¨|œÿ§{›ÿ§{šÿ§z˜ÿ§y˜ÿ¦y˜ÿ¥y™ÿ£xšÿ¢w�ÿ w ÿ wŸÿ vœÿŸuœÿŸu�ÿŸv ÿŸw¡ÿŸw¢ÿŸw£ÿŸw£ÿŸw¢ÿŸv ÿŸuŸÿžuŸÿžu ÿ�u¢ÿœu¢ÿ›tŸÿ›s›ÿ›r˜ÿœr˜ÿ›q™ÿšq›ÿ™q�ÿ˜q�ÿ—q�ÿ—q�ÿ—q�ÿ—qžÿ—qžÿ—qŸÿ–qžÿ–q�ÿ–p�ÿ—pœÿ˜p›ÿ™pšÿšqšÿšqšÿ›qšÿ›r›ÿšr�ÿ˜s¢ÿ˜s¥ÿ—s¦ÿ—s¥ÿ˜s¤ÿ˜s¥ÿ—s¥ÿ—s¥ÿ—r¥ÿ—r¥ÿ–q¥ÿ”r§ÿ”r©ÿ“r«ÿ“r­ÿ’r­ÿ’r¬ÿ’q«ÿ’qªÿ’qªÿ‘pªÿ‘pªÿ¢ÉÿÁ¡ÇÿÁ ÇÿÁ ÇÿÁ¡ÇÿÁ¡ÈÿÁ¡Çÿ¡ÅÿáÂÿÄ¡¿ÿÆ¢½ÿÇ¢¼ÿÇ¢¼ÿÇ¢½ÿÇ¢½ÿÇ¡¼ÿÈ¡ºÿÈ¡¸ÿÉ¡·ÿÉ¡´ÿÊ¡²ÿË¡¯ÿÌ «ÿÍ ¨ÿΟ§ÿΟ¦ÿΟ£ÿÏŸ ÿÏŸžÿРžÿРžÿÏ žÿÏ ŸÿÏ  ÿÏŸ¢ÿÏŸ£ÿΟ£ÿΞ¢ÿΞ¢ÿÍž£ÿÌž¦ÿÌŸªÿËŸ®ÿËŸ¯ÿÊž­ÿË�«ÿÊžªÿÊ�©ÿÊ�©ÿÊ�ªÿÉž«ÿÉ�«ÿÉœ¬ÿÈœ¬ÿÇ›«ÿÆ›«ÿÆš¬ÿÄ™®ÿ˜®ÿÁ˜¯ÿÀ—¯ÿ¿—¯ÿ¿—°ÿ¿—±ÿ¾–±ÿ¾–±ÿ½–°ÿ¿–¯ÿÀ–­ÿÀ–­ÿ¾•°ÿ»”³ÿ¶‘¶ÿ±�¸ÿ®�¹ÿ®Œ»ÿ³‘¼ÿ·–¿ÿ¸™Âÿ¸™Åÿ·™Çÿ¶™Éÿ¶™Ëÿ¶šÌÿ¶™Ìÿ¶™Ìÿ¶™Ëÿ¶˜Ìÿµ™Íÿ´™Îÿ´™Îÿµ™Ïÿµ˜Îÿµ—Íÿ´–Ìÿ³•Éÿ±”Éÿ¯”Ëÿ¯”Îÿ®”Ïÿ¬’Ìÿ­�Éÿ­�Æÿ¬ŽÅÿ«�Æÿ«�Ìÿ«‘Îÿ«‘Íÿ«‘Ìÿ¬‘Êÿ®�Èÿ­�Åÿ¬ŽÅÿªŽÈÿ¨�Ëÿ¥�Ðÿ¤�Óÿ¤�Óÿ¦�Ñÿ§�Ïÿ¨�Íÿ©�Ìÿ­’Ðÿ—~µÿfPrÿ¡…½ÿ¬�Ãÿ¬Š»ÿ¬‰¶ÿ®ˆ³ÿ¯ˆ¯ÿ°‡«ÿ±‡¨ÿ±‡§ÿ±‡§ÿ°‡©ÿ¯†«ÿ®†«ÿ®…ªÿ®…ªÿ¯„©ÿ¯…¦ÿ°…£ÿ±…¢ÿ°…¦ÿ¯…©ÿ®„«ÿ­„«ÿ­„¬ÿ¬„­ÿ«„¯ÿª„±ÿ©…´ÿ¨…¶ÿ§…¶ÿ¦„´ÿ§ƒ²ÿ¨ƒ¯ÿ©‚«ÿª‚©ÿª�ªÿ©�¬ÿ¨‚­ÿ§‚®ÿ§‚­ÿ§�¬ÿ¦€«ÿ¦«ÿ¦«ÿ¦ªÿ¥«ÿ£}¬ÿ£}¬ÿ£}ªÿ¤|§ÿ§|¢ÿ¨}¡ÿ§} ÿ§|Ÿÿ§|žÿ§{�ÿ¦z›ÿ¦z›ÿ¦yšÿ¤x›ÿ£x�ÿ¢xŸÿ¡xŸÿ¡w�ÿ v�ÿŸw ÿŸw¡ÿžw£ÿžw¤ÿžw¦ÿ�w§ÿœw¦ÿœv¥ÿœv¤ÿ�v¤ÿ�v¦ÿœv§ÿ›v¦ÿšu£ÿ™t ÿštžÿšsžÿšsžÿ™sŸÿ™sŸÿ˜rŸÿ—r ÿ–r¡ÿ—r¢ÿ—r£ÿ–s£ÿ–s£ÿ•r¢ÿ•q¡ÿ•q ÿ–qžÿ˜qœÿšqœÿšr›ÿ›r›ÿœršÿœr›ÿšs�ÿ™s¡ÿ™s¤ÿ™s¢ÿ˜s ÿ™s¡ÿ™s£ÿ˜s¥ÿ—s¥ÿ˜s¦ÿ—r¦ÿ–s§ÿ•s¨ÿ•rªÿ”r«ÿ“rªÿ“rªÿ“rªÿ“r«ÿ’r©ÿ‘q©ÿ‘qªÿ‘pªÿãÈÿâÆÿâÄÿ¡Âÿ ÂÿÁ ÂÿÁ ÃÿÁ ÃÿÁ Áÿ ¿ÿÄ¡¾ÿÆ¢½ÿÆ£¾ÿÇ£¾ÿÈ£¾ÿÇ¢¼ÿÇ¢»ÿÈ¡¹ÿÈ¡·ÿÉ¢¶ÿË¢³ÿÌ¡°ÿÌ¡«ÿΡ§ÿÏ¡¦ÿÏ¡§ÿР¤ÿР¡ÿРŸÿР�ÿСœÿСœÿС�ÿСŸÿР¡ÿР¢ÿÏ ¡ÿР¡ÿП¡ÿÏŸ¢ÿÍŸ¥ÿÍ ªÿÍ ¯ÿÌ ±ÿËŸ®ÿÊž¬ÿÊŸªÿËŸ©ÿËž©ÿË�ªÿÉ�«ÿÉ�¬ÿÉ�¬ÿÉ�«ÿÈœªÿÇ›ªÿÆ›«ÿÅš­ÿÙ¯ÿ™°ÿÁ˜°ÿÀ˜°ÿ¿˜¯ÿÀ—¯ÿÀ–¯ÿ¿—¯ÿ¿—°ÿÀ—°ÿÁ—¯ÿÀ–®ÿ¾•®ÿ½•°ÿ¸“³ÿ³�¶ÿ°Ž·ÿ±�ºÿµ”ºÿ¹˜¼ÿ»šÀÿºšÄÿ¸›Éÿ·›Íÿ¶›Ðÿµ›Ñÿµ›Òÿ´šÑÿµšÑÿµ™Ðÿ´™Ðÿ³šÐÿ´šÐÿµ™Ïÿµ™Îÿ´™Îÿµ˜Íÿ´—Êÿ³–Éÿ²–Ëÿ±•Íÿ°•Ìÿ°“Éÿ°‘Åÿ¯�Ãÿ®�Ãÿ®�Æÿ­‘Ëÿ¬‘Íÿ¬‘Ìÿ¬‘Êÿ­�Éÿ®�Çÿ­�Åÿ¬�Æÿ«�Èÿ¨�Ìÿ¥�Òÿ¤�Óÿ¥�Òÿ§�Ðÿ¨�Ìÿ¨�Éÿ©ŽÇÿ­‘Íÿ˜~³ÿfPqÿŸ…¼ÿ«�Äÿ«Š»ÿ¬‰¶ÿ®‰³ÿ¯ˆ°ÿ°‡«ÿ±‡¨ÿ²‡§ÿ±‡¨ÿ°‡ªÿ¯†¬ÿ¯†®ÿ®†®ÿ­†®ÿ®…­ÿ¯…¨ÿ°…¤ÿ°…¤ÿ°†§ÿ¯†«ÿ¯†¬ÿ®…¬ÿ®…¬ÿ­…®ÿ«…°ÿ©…´ÿ¨…¸ÿ¦†»ÿ¥†¼ÿ¥†¼ÿ¦…ºÿ§„¶ÿ¨„±ÿ©ƒ®ÿª‚­ÿ©�­ÿ¨�­ÿ§‚­ÿ§�­ÿ¦€®ÿ¥€¯ÿ¥€°ÿ¤¯ÿ¤­ÿ¤€­ÿ¤°ÿ¤~±ÿ¤~®ÿ¥}©ÿ§}¤ÿ§}£ÿ§~£ÿ§}¢ÿ¦|¡ÿ¦| ÿ¦{žÿ¦zœÿ¦z›ÿ¥yœÿ£y�ÿ£xŸÿ¢x ÿ¡wŸÿ w ÿ x¢ÿŸx¤ÿžx¥ÿžx§ÿ�xªÿ›w«ÿšv«ÿ™vªÿšv©ÿ›wªÿ›wªÿ›wªÿ›v©ÿšu¦ÿ™u¤ÿ™u£ÿšt£ÿ™u¤ÿ™u£ÿ™t£ÿ˜t£ÿ—t¥ÿ–t§ÿ—t¨ÿ˜t§ÿ—t§ÿ–t¦ÿ–s¥ÿ–r¤ÿ–r¢ÿ—r¡ÿ˜rŸÿšsžÿšs�ÿ›sœÿœs›ÿœs›ÿ›s�ÿ™t ÿšs ÿ›sžÿšsžÿ™sŸÿ™s¢ÿ˜s¤ÿ˜t¦ÿ˜s¦ÿ—s§ÿ–s¨ÿ•s¨ÿ–r©ÿ•r¨ÿ•r¨ÿ”r¨ÿ”r©ÿ”rªÿ“rªÿ’rªÿ‘r«ÿ‘q«ÿƤÆÿƤÂÿÆ£¿ÿÆ¢½ÿÅ¡½ÿÄ¡½ÿà½ÿŸ¿ÿŸÀÿŸÀÿß¿ÿÅ¡¿ÿÆ£¿ÿÇ£¾ÿÇ¢½ÿÈ£¼ÿÈ¢ºÿÈ¢¹ÿÈ¡·ÿÉ¢¶ÿË¢´ÿÌ¢°ÿÌ¡¬ÿΡ©ÿÏ¡¨ÿТ¦ÿТ¥ÿÑ¢£ÿÒ¢¡ÿÒ¢ŸÿÑ¢�ÿÑ¢�ÿÑ¡�ÿÑ¡ŸÿÑ¡¢ÿÑ¡£ÿС¡ÿР ÿР¡ÿР¢ÿÏ £ÿΠ§ÿΡ¬ÿÍ¡¯ÿÌ ­ÿÌŸ«ÿÌŸ©ÿÌŸ©ÿËŸ©ÿËžªÿÊžªÿÊž«ÿÉ�¬ÿÈ�¬ÿÉ�«ÿÉ�ªÿÈœªÿÆ›¬ÿÅš®ÿÚ±ÿÁ™²ÿÀ˜²ÿÀ˜±ÿ¿—°ÿÀ˜°ÿÁ˜±ÿÁ˜±ÿÁ˜±ÿÁ˜°ÿÁ—¯ÿ¿–°ÿ½•±ÿ¹”³ÿµ‘µÿ²�·ÿµ“ºÿ¸–»ÿ»™¼ÿ½›¿ÿ¼›ÃÿºœÉÿ¸œÏÿ¶œÒÿµœÓÿ´›ÓÿµšÒÿ´šÒÿ³šÔÿ³šÕÿ³šÕÿ³šÓÿ´™Ðÿ´™Ïÿµ™Ïÿ´™Îÿ´˜Ëÿ´—Éÿ´—Êÿ´–Êÿ³•Çÿ³”Ãÿ´”Áÿ´“Àÿ³’Áÿ±’Äÿ°’Èÿ®‘Èÿ®�Èÿ®�Èÿ®�Èÿ®�Æÿ­ŽÅÿ¬ŽÅÿ«ŽÇÿ¨�Ìÿ¥�Óÿ¥�Óÿ¥�Ñÿ¦ŽÏÿ§�Êÿ©�Æÿª�Åÿ®‘Ëÿ˜~±ÿdOoÿš‚¹ÿ¨ŒÄÿª‹Áÿ«Š¼ÿ¬‰¶ÿ®ˆ±ÿ±ˆ­ÿ²ˆ©ÿ²ˆ§ÿ²‡¨ÿ°‡«ÿ°‡­ÿ¯‡®ÿ®‡°ÿ®‡±ÿ®‡°ÿ°†ªÿ±†¥ÿ²†¥ÿ²†§ÿ±‡¨ÿ±‡©ÿ±†©ÿ¯…«ÿ¬…¯ÿ«…³ÿ©†¹ÿ§‡¾ÿ¥‡Àÿ¦‡Áÿ¤‡Âÿ¤‡Âÿ¥…½ÿ§„·ÿ¨ƒ²ÿ¨‚­ÿ¨�«ÿ¨�¬ÿ§�­ÿ¦�¯ÿ¥‚±ÿ¤�³ÿ£´ÿ¢³ÿ¢²ÿ¤²ÿ¤€´ÿ¤€´ÿ¥°ÿ¦~ªÿ§~¦ÿ¦~¦ÿ¦~¦ÿ¦}¥ÿ¦}£ÿ¦|¡ÿ¦{Ÿÿ¦{žÿ¦z�ÿ¥zŸÿ¤y¡ÿ£y¢ÿ¢y£ÿ¡y£ÿ¡y£ÿ x¥ÿŸx¦ÿžx§ÿ�xªÿœy®ÿšx¯ÿ˜w¯ÿ˜v®ÿ˜v­ÿ™w®ÿ™w®ÿ™w­ÿšv«ÿšu©ÿšv©ÿ™vªÿ™v©ÿ™u¨ÿ™u§ÿ™u§ÿ—u§ÿ–u©ÿ–v¬ÿ—v¬ÿ—v«ÿ˜vªÿ—u©ÿ—s§ÿ—s¥ÿ—s¥ÿ˜t¤ÿ™t¢ÿšt¡ÿšt ÿ›sžÿœsœÿ›s›ÿ›s�ÿ›sžÿ›s�ÿ›r�ÿ›sžÿ™s ÿ˜t¢ÿ™t¤ÿšu§ÿ™t¨ÿ˜t©ÿ—t©ÿ—t©ÿ–s¨ÿ–r§ÿ•r¨ÿ•s©ÿ•sªÿ”s«ÿ“r¬ÿ“r«ÿ“rªÿ’rªÿÇ¥ÄÿÈ¥Àÿɤ»ÿÊ£¹ÿÉ¢¸ÿÈ¢·ÿÇ¡·ÿÅ ¹ÿÄ »ÿà¾ÿÄ ¿ÿÅ¡ÀÿÆ¡¿ÿÇ¢½ÿÇ¢»ÿÈ¢¹ÿÉ¢¸ÿÉ¢·ÿÉ£¶ÿÊ£´ÿÌ¢³ÿÍ¢°ÿÍ¢®ÿÍ¢¬ÿ΢ªÿТ¨ÿТ¦ÿÑ£¥ÿÒ££ÿÒ£¢ÿÒ£ ÿÒ¢žÿÒ¢žÿÑ¢ ÿÑ¢¢ÿÑ¢¢ÿÑ¢ ÿÑ¡ŸÿСŸÿС ÿС ÿÏ £ÿΠ¨ÿΠ«ÿÍ ªÿÍ ¨ÿÍŸ¨ÿÌŸ¨ÿÌŸ©ÿÌŸ©ÿËŸªÿËž«ÿÊž¬ÿÊž¬ÿÉž¬ÿÉžªÿÉ�©ÿÈœªÿÇ›¬ÿÄš°ÿ™³ÿÁ˜³ÿÀ˜³ÿÀ˜²ÿÁ˜²ÿÁ™³ÿÁ™³ÿÁ˜²ÿÁ˜°ÿÀ˜¯ÿÀ˜±ÿ¾–³ÿº”´ÿ¶’¶ÿµ’¸ÿ¸•ºÿº—¼ÿ¼š½ÿ½œ¿ÿ¾œÁÿ½�Åÿ»�Éÿ¹�Íÿ¸œÐÿ·œÏÿ¶›Ïÿ´›Óÿ²›Øÿ±œÚÿ±›Ùÿ²›Öÿ³šÔÿ´šÒÿ´™ÑÿµšÏÿµ™Ëÿµ˜Çÿ¶—Æÿ¶–Åÿ¶•Ãÿ¶”Àÿ¶”¾ÿ¶“¾ÿµ“Àÿ³“Âÿ±“Åÿ°’Åÿ°‘Åÿ¯�Åÿ¯�Æÿ®�Äÿ­ŽÃÿ«�Ãÿª�Æÿ¨�Ìÿ¥�Òÿ¥�Òÿ¦�Ñÿ¦�Ïÿ§ŽËÿ¨�Èÿ©ŒÇÿª�Çÿ�w©ÿR@\ÿ‚m�ÿ¡‡Àÿª�Çÿ©ŠÀÿ«Š»ÿ­‰µÿ°ˆ¯ÿ±ˆ«ÿ²ˆ©ÿ²ˆªÿ°ˆ­ÿ¯ˆ®ÿ¯ˆ¯ÿ¯ˆ¯ÿ¯ˆ°ÿ®ˆ±ÿ°‡«ÿ²‡¥ÿ³‡£ÿ³‡£ÿ³†£ÿ³†£ÿ²†¥ÿ¯†ªÿ¬‡²ÿª‡¸ÿ¨ˆ¿ÿ¦ˆÃÿ¥ˆÄÿ¥ˆÄÿ¤ˆÅÿ¤ˆÅÿ¥†¿ÿ§„·ÿ¨ƒ±ÿ§€ªÿ¨€©ÿ¨�«ÿ§�®ÿ¦‚²ÿ¤�µÿ£�·ÿ¡€¸ÿ¡¸ÿ¡€·ÿ¢€¸ÿ¤�·ÿ¥�´ÿ¦€®ÿ§~¨ÿ§~§ÿ¦~§ÿ¥~§ÿ¥~§ÿ¥}¦ÿ¦|¢ÿ§|¡ÿ¦{ ÿ¥z¡ÿ¥z£ÿ£z¥ÿ¢z¦ÿ¡z¥ÿ z¦ÿ y§ÿŸy¨ÿžx©ÿ�xªÿœy­ÿšy³ÿ™y´ÿ˜x³ÿ—w±ÿ—v°ÿ˜w°ÿ˜w°ÿ˜w°ÿ˜w¯ÿ˜w®ÿ˜v­ÿ˜v­ÿ˜v¬ÿ—v«ÿ—uªÿ˜uªÿ—v¬ÿ•w¯ÿ•v°ÿ—v¯ÿ—w®ÿ—v¬ÿ—uªÿ—u©ÿ—u¨ÿ˜u§ÿ˜u¦ÿ™u¥ÿšu¥ÿšt¤ÿ›t¡ÿ›tŸÿ›s�ÿ›sœÿœs�ÿœtžÿ›sžÿ›t ÿ™t¢ÿ™u¤ÿšu¥ÿ™t¦ÿšt¨ÿ™t©ÿ™t©ÿ˜t©ÿ–t©ÿ–s©ÿ–s©ÿ•sªÿ”s¬ÿ”s­ÿ“s¬ÿ“r«ÿ”rªÿ“r©ÿǦÄÿȦÀÿÊ¥¼ÿË¥¸ÿʤµÿÊ£´ÿÊ¢´ÿÉ¢µÿÇ¢·ÿÆ¢ºÿÆ¡¼ÿÆ¡½ÿÆ¡¼ÿÇ¡»ÿÇ¡ºÿÇ¡¸ÿÈ¡·ÿÈ¢µÿÉ¢´ÿË£²ÿÌ£²ÿÍ£±ÿÍ£°ÿΣ®ÿ΢¬ÿÏ¢ªÿТ¨ÿÑ£§ÿÒ£¦ÿÒ¤¥ÿÒ¤£ÿÓ¤ ÿÓ£ ÿÓ£¡ÿÒ£¢ÿÒ£ ÿÒ£ŸÿÒ¢ŸÿÑ¢ŸÿÑ¢žÿÑ¡ŸÿС¡ÿÏ¡¥ÿΡ©ÿΠ©ÿΠ§ÿΠ§ÿÍŸ§ÿÍŸ¨ÿÌŸ©ÿËŸªÿËŸ«ÿËŸ­ÿËŸ­ÿÉž«ÿÉžªÿÉž©ÿÉ�©ÿÈœªÿÆ›­ÿÄš±ÿ™²ÿÁ™³ÿÁ™³ÿÁ™´ÿÁš´ÿÁš´ÿÁ™³ÿÁ˜²ÿÀ˜±ÿÀ˜±ÿ¾–³ÿº”´ÿ·”·ÿ¶”ºÿ¸–»ÿ»˜½ÿ½›¿ÿ¾�Àÿ¿�Âÿ¿�Äÿ¾žÅÿ½žÈÿ»�Ëÿ¹œÌÿ¹œÍÿ¶œÓÿ´�Øÿ²�Úÿ²œ×ÿ³œÕÿ³›Ôÿ´›Òÿ´šÑÿµšÏÿ¶™Ëÿ¶˜Æÿ·—Ãÿ¸–Âÿ·–Àÿ·•¿ÿ·•¾ÿ¶”¿ÿ´”Áÿ²”Ãÿ±“Æÿ±“Æÿ°’Åÿ°�Äÿ¯�Ãÿ®�Áÿ­ŽÁÿ«�Âÿª�Åÿ¨�Ëÿ§�Îÿ¥�Ïÿ¥�Ñÿ¥�Ñÿ¥ŽÏÿ¥ŽÍÿ§ŽÌÿ¤ŠÇÿ‡p¢ÿ@2JÿkX„ÿ›„¿ÿ©�Îÿ¨ŒÆÿª‹Àÿ¬Š¸ÿ®‰³ÿ¯ˆ¯ÿ°ˆ®ÿ°‰®ÿ¯‰±ÿ­‰³ÿ­ˆ³ÿ®‰²ÿ®‰±ÿ¯‰±ÿ°‡¬ÿ²‡¦ÿ²‡£ÿ²†£ÿ³†£ÿ²†¥ÿ°‡ªÿ®ˆ²ÿ«‰ºÿ¨‰¾ÿ§‰Ãÿ¦ŠÆÿ¥ŠÇÿ¤‰Çÿ¤ˆÆÿ£‡Äÿ¥†½ÿ§„µÿ§‚®ÿ§€©ÿ§¨ÿ¨€©ÿ§�¬ÿ¦�²ÿ£€¶ÿ¢�¹ÿ¡�»ÿ �¼ÿ¡�»ÿ¡�ºÿ£�·ÿ¥�²ÿ¦€«ÿ§~§ÿ§~§ÿ¥}¨ÿ¤}©ÿ¤}©ÿ¤}§ÿ¥}¥ÿ¦|¢ÿ¥{£ÿ¤z¥ÿ£{§ÿ¢{¨ÿ¡{¨ÿ z¨ÿŸz©ÿžz¬ÿžz®ÿ�y®ÿœy¯ÿšy²ÿ™z·ÿ˜z¹ÿ˜y¸ÿ—xµÿ—w³ÿ˜w³ÿ˜x³ÿ—x³ÿ˜x´ÿ—x³ÿ–w°ÿ—w°ÿ—w°ÿ–v°ÿ–v¯ÿ–v¯ÿ–w²ÿ”w´ÿ”w´ÿ–w²ÿ—w±ÿ—w¯ÿ—v¬ÿ—u«ÿ—vªÿ˜vªÿ˜v©ÿ™v¨ÿšv¨ÿ›u§ÿ›u¥ÿœt¡ÿœtŸÿœtžÿœtžÿœu ÿ›u¡ÿ›u¢ÿ›u¤ÿ›v¥ÿšu¦ÿšu¦ÿšu¨ÿšt©ÿ™t©ÿ˜tªÿ–t«ÿ–t«ÿ•s«ÿ”s¬ÿ”t®ÿ”t¯ÿ“t®ÿ“s­ÿ”r«ÿ”r«ÿǨÆÿɧÃÿʧ¿ÿ˦ºÿË¥¶ÿˤ´ÿÌ£³ÿ̤³ÿʤ´ÿÉ£¶ÿÈ£¸ÿÈ¢¹ÿÇ¢¹ÿÇ¡¹ÿÇ¡¹ÿÇ ·ÿÇ ¶ÿÈ¡´ÿÊ¡³ÿË¢²ÿÌ£³ÿÍ£²ÿΣ±ÿΣ¯ÿΣ­ÿÏ£¬ÿУ«ÿÑ£ªÿÑ£¨ÿÒ¤§ÿÓ¥¥ÿÔ¥£ÿÔ¥¢ÿÔ¥¡ÿÓ¤¡ÿÓ¤ŸÿÓ¤ŸÿÓ£ŸÿÓ£žÿÒ¢�ÿÒ¢ŸÿÑ¢ ÿТ¤ÿÏ¢¨ÿÏ¡¨ÿÏ¡§ÿÏ¡¦ÿΠ§ÿÍ ©ÿÍ ©ÿÌ «ÿÌŸ­ÿÌ ®ÿË ­ÿÊŸ«ÿÊžªÿÊž©ÿÊž©ÿÉž©ÿÈœªÿÆ›®ÿÄ›¯ÿÚ±ÿÚ³ÿ™´ÿšµÿÁ›µÿÁš´ÿÁš´ÿÁ™´ÿ¿—²ÿ¼•³ÿ¹”µÿ·”·ÿ·•ºÿ¸–»ÿ¼™½ÿ¾œÀÿÀžÃÿÀžÄÿÀžÄÿÀžÅÿ¿žÇÿ½žÈÿ¼�Êÿ»�Íÿ¸�Òÿ¶�Öÿµ�Öÿ´�ÔÿµœÓÿµœÑÿµ›Ïÿµ›Ïÿ¶šÎÿ·™Ëÿ¶˜Æÿ·—Âÿ¸—Àÿ¸–¿ÿ¸–¿ÿ·–Àÿ¶•Áÿ³•Äÿ²”Çÿ±“Éÿ°“Éÿ°’Çÿ°‘Äÿ¯�Áÿ¯�Àÿ­ŽÁÿ«�ÃÿªŽÅÿ©ŽÉÿ¨�Ëÿ¦�Íÿ¤�Ñÿ¤�Ôÿ¤�Ôÿ£�Óÿ¤�Óÿ¡�Ïÿ„rªÿ=1KÿgW‡ÿ˜…Åÿ§‘Ôÿ¦ŽÊÿ¨ŒÄÿªŠ¼ÿ¬Š¸ÿ­‰´ÿ­ˆ²ÿ­‰³ÿ¬‰¶ÿ¬‰·ÿ¬‰¸ÿ¬‰¶ÿ­‰³ÿ®ˆ²ÿ¯‡¯ÿ°‡«ÿ°‡©ÿ¯‡«ÿ¯‡­ÿ®‡±ÿ­‰¸ÿ«Š¾ÿ©ŠÁÿ§ŠÂÿ¦ŠÅÿ¥ŠÇÿ¥‹Éÿ¤ŠÉÿ£ˆÇÿ£†Àÿ¤„»ÿ¦ƒµÿ§‚­ÿ¨€ªÿ§©ÿ§¨ÿ§€ªÿ¥€¯ÿ¢€µÿ¡�»ÿ ‚¾ÿ ‚¾ÿ¡‚»ÿ¢�¸ÿ£�´ÿ¤€¯ÿ¥«ÿ¥~¨ÿ¥~¨ÿ¤}©ÿ¢}ªÿ¢}«ÿ¢}«ÿ¤}©ÿ¤{¦ÿ£{§ÿ¢{ªÿ¡{¬ÿ {­ÿ {¬ÿŸz¬ÿž{­ÿ�{±ÿ�|³ÿœ{µÿš{·ÿ˜{¹ÿ—|½ÿ—|¿ÿ—{½ÿ—zºÿ—y¸ÿ˜y¸ÿ—z¸ÿ—y¸ÿ—y¸ÿ–y·ÿ–yµÿ–yµÿ•xµÿ•wµÿ•wµÿ•wµÿ•x·ÿ”x¸ÿ”x¶ÿ•wµÿ–xµÿ—x´ÿ—w²ÿ—w¯ÿ˜v­ÿ—v­ÿ˜w¬ÿ™w«ÿšwªÿ›v©ÿ›v¦ÿ�u£ÿ�u¡ÿ�u¡ÿœv¡ÿœu£ÿ›v¥ÿ›v¥ÿ›v¦ÿœv¦ÿ›w§ÿ›v¨ÿšvªÿ™uªÿ˜u«ÿ—u¬ÿ–t­ÿ–t®ÿ•t®ÿ”t®ÿ”t°ÿ“u²ÿ’u±ÿ“t°ÿ”s®ÿ”s®ÿÈ©ËÿÉ©Èÿ˨Âÿ̧¼ÿ̦¸ÿͦµÿÍ¥³ÿͤ±ÿ̤±ÿ̤²ÿʤµÿÉ£·ÿÉ£·ÿÈ¢·ÿÇ¡¸ÿÈ¡¶ÿÉ¡´ÿÉ¡³ÿÉ¡³ÿÊ¡³ÿË£´ÿÌ£³ÿÍ£²ÿΤ°ÿϤ®ÿϤ­ÿФ­ÿѤ¬ÿѤªÿÒ¤©ÿÔ¥§ÿÔ¦¥ÿÔ¦¤ÿÔ¦¢ÿÔ¥¡ÿÕ¥ŸÿÔ¥ŸÿÔ¥žÿÔ¤žÿÓ£�ÿÓ£žÿÓ£ ÿÒ££ÿÑ¢¦ÿТ¨ÿÏ¡§ÿÏ¡§ÿÏ¡¨ÿΡªÿÍ ¬ÿΡ­ÿÍ ®ÿÌ¡®ÿÌ¡­ÿË «ÿËžªÿËž©ÿËž©ÿËž©ÿÊ�©ÿÈœ«ÿÇœ­ÿÆ›¯ÿÄš±ÿÚ³ÿÛµÿܶÿœ¶ÿ›¶ÿÁš¶ÿ¾˜¶ÿ»•µÿ¸”¶ÿ·”¸ÿ¸•¹ÿº—¹ÿ¿›¼ÿÁ�ÀÿÁžÄÿÀžÅÿÀŸÄÿÀžÆÿ¿žÇÿ¾žÉÿ½�Êÿ¼�Íÿ¹�Ðÿ·�Òÿ·�Óÿ·�Óÿ·�Ñÿ¶œÎÿ·œÍÿ·›Ìÿ·›Ëÿ¶™Éÿ·˜Æÿ¸—Ãÿ¹—Àÿ¹—Àÿ¸—Áÿ·–Âÿµ–Åÿ³•Èÿ²”Ëÿ°“Ëÿ¯“Êÿ¯’Éÿ¯‘Æÿ¯�Äÿ®�Äÿ­ŽÅÿ¬ŽÆÿªŽÇÿ¨�Èÿ¨�Éÿ§ŽÍÿ¥�Óÿ£‘Øÿ£‘Ùÿ¢‘Øÿ¢’Ùÿ¢’Ûÿˆz¹ÿA6Uÿna–ÿ˜‡Êÿ¥‘Öÿ¥ŽÍÿ¦ŒÇÿ¨ŠÁÿª‰¼ÿ«‰¹ÿ«ˆ·ÿªˆ¸ÿª‰ºÿ«Šºÿ«Šºÿ«‰¹ÿ¬‰¸ÿ¬‰·ÿ¬ˆµÿ¬ˆ³ÿ¬ˆ´ÿ«‰¸ÿª‰¼ÿ©ŠÁÿ¨‹Çÿ§‹Èÿ§‰Ãÿ¨‰Âÿ§ŠÃÿ¦ŠÆÿ¥ŠÇÿ¤ŠÇÿ¤ˆÆÿ¤…¿ÿ¤„»ÿ¦ƒ¶ÿ¨�­ÿ¨€«ÿ¨€ªÿ§©ÿ¦«ÿ¥€¯ÿ¢�¶ÿ¡‚½ÿŸƒÁÿ ‚¿ÿ¢�¹ÿ£�µÿ£€±ÿ£®ÿ¤~­ÿ¤~«ÿ£}¬ÿ¢}­ÿ¡|®ÿ |®ÿ¡|¯ÿ£|­ÿ¢|«ÿ¡|­ÿŸ|°ÿŸ{²ÿŸ|±ÿž{±ÿž{±ÿž|²ÿ�|µÿ�}¸ÿ›~»ÿ™~¾ÿ—~Áÿ•}Äÿ•}Äÿ–|Áÿ—|¾ÿ˜{½ÿ—{½ÿ—{½ÿ—z½ÿ–z½ÿ–z¼ÿ–z»ÿ•{»ÿ”zºÿ”y»ÿ”x»ÿ“x»ÿ“y¼ÿ”y»ÿ”x¹ÿ”w¸ÿ”x¹ÿ”y»ÿ”y»ÿ–x·ÿ—w³ÿ˜w±ÿ˜x®ÿ™x­ÿ™w¬ÿšwªÿœw§ÿœv¥ÿ�w¥ÿœw¥ÿœw§ÿœw¨ÿœwªÿ›wªÿ›wªÿ›wªÿ›x«ÿ›w¬ÿšv­ÿ™v®ÿ˜v¯ÿ—v°ÿ–u°ÿ•u°ÿ•t±ÿ”u²ÿ“u³ÿ’u´ÿ’u´ÿ’u³ÿ’t²ÿ“t±ÿȪÌÿÉ©ÉÿÊ©Äÿ˨¾ÿ̧ºÿΧ¶ÿϦ²ÿÏ¥±ÿÎ¥°ÿͤ±ÿͤ³ÿˤµÿÉ£µÿÉ£´ÿÉ¢´ÿÊ¢³ÿÊ¡²ÿÉ¡²ÿÉ¡²ÿÉ¢²ÿË£³ÿÌ£³ÿͤ²ÿΤ±ÿÏ¥°ÿÏ¥°ÿÐ¥®ÿÐ¥­ÿÑ¥¬ÿÒ¥ªÿÓ¦©ÿÓ¦§ÿÔ¦¥ÿÕ§£ÿÔ¦¢ÿÔ¦ ÿÕ¦ŸÿÕ¥žÿÕ¥œÿÔ¥›ÿÕ¥œÿÔ¤ŸÿÓ¤¢ÿÓ¤¥ÿÒ¤¦ÿÑ£¥ÿТ¦ÿТ§ÿÏ¢©ÿÏ¢«ÿÍ¢¬ÿÍ¡¬ÿÍ¡­ÿÍ¢¬ÿÍ¡ªÿÍŸ¨ÿÌŸ¨ÿËž§ÿËž¨ÿÊ�¨ÿÉž©ÿÈ�«ÿÇ�­ÿÆœ°ÿÄœ²ÿÜ´ÿÛµÿÜ·ÿœ¹ÿÁ›¹ÿ¾™¹ÿ»–·ÿ¸”·ÿ·”·ÿº–¸ÿ¿™¸ÿÃ�»ÿß¿ÿŸÃÿÁ ÅÿÀŸÅÿ¿ŸÈÿ¿ŸÊÿ¾ŸËÿ½žËÿ»žÎÿ»žÑÿº�Ñÿ¸�Ñÿ·œÑÿ·œÐÿ·œÏÿ¸œÎÿ·œÍÿ·›Ëÿ·›Éÿ·™Çÿ·˜Æÿ¶˜Åÿ¶—Åÿ¶—Åÿµ–Çÿ³–Éÿ²–Ìÿ°•Íÿ¯”Ìÿ¯“Ëÿ®’Éÿ®‘Çÿ®‘Çÿ­�Çÿ¬�Èÿª�Êÿ©�Êÿ©�Êÿ¨ŽÉÿ¦�Íÿ£�Öÿ ’Ûÿ ’Ûÿ ’Ûÿ ’Üÿž�Úÿƒuµÿ=2OÿdW‰ÿ–…Çÿ¥‘Öÿ¤�Íÿ¥ŒÉÿ¦‹Äÿ¨ŠÁÿ©ŠÀÿ©Š¾ÿ©‰¼ÿ©‰»ÿ©Š¼ÿ©Š½ÿª‹½ÿªŠ¼ÿª‰»ÿª‰»ÿ«‰ºÿ«‰»ÿª‹Âÿ§ŒÉÿ¥�Îÿ¤ŽÐÿ¥�Ìÿ§‹Äÿ¨‰¿ÿ©‰¿ÿ§ŠÂÿ¦ŠÄÿ¥ŠÅÿ£‰Äÿ£‡Áÿ¤…¾ÿ¥…¸ÿ¦ƒ¯ÿ§�­ÿ§�­ÿ§€­ÿ¥€®ÿ¤�³ÿ¢‚¹ÿ ƒ¿ÿŸ„Âÿ ‚¿ÿ¡�¹ÿ¡€´ÿ¡±ÿ¡°ÿ¡°ÿ¡²ÿ¡~´ÿ ~µÿŸ~µÿŸ~³ÿ¡~²ÿ¢}±ÿ¡}°ÿ }²ÿž}µÿœ}·ÿœ{µÿ�|´ÿ�|µÿ�}·ÿ�~ºÿ›½ÿ™Áÿ—Åÿ•€Èÿ“€Ëÿ“Êÿ•}Äÿ—|Àÿ—|¿ÿ—|¿ÿ–{Àÿ•|Áÿ”{Âÿ”{Áÿ”|Àÿ”|Àÿ”{¿ÿ”{¿ÿ“zÀÿ‘zÀÿ‘zÀÿ‘y¾ÿ’y¼ÿ“y»ÿ“x¼ÿ’z¾ÿ’z¿ÿ”z¾ÿ–y»ÿ–y¶ÿ˜x²ÿ™x±ÿ™x¯ÿšw¬ÿ›wªÿ›x©ÿœx©ÿœx«ÿ›x­ÿšy®ÿšy¯ÿšy°ÿšx°ÿ™w°ÿ™x°ÿ™w°ÿ™w±ÿ˜w²ÿ—w²ÿ—v³ÿ•v´ÿ•v´ÿ•v´ÿ”vµÿ“vµÿ’v¶ÿ‘u¶ÿ‘u¶ÿ�uµÿ�uµÿÈ©ËÿȪÊÿÉ©ÇÿË©Âÿ̨¾ÿΨ¸ÿϧ´ÿЧ±ÿϧ°ÿϦ°ÿÏ¥±ÿÍ¥³ÿÌ¥³ÿˤ³ÿË£²ÿÊ¢²ÿÊ¢±ÿÊ¢²ÿÊ¢²ÿÊ¢²ÿË£²ÿÌ£²ÿͤ±ÿÏ¥±ÿЦ±ÿЦ°ÿЦ¯ÿЦ®ÿÑ¥¬ÿÒ¥«ÿÓ¦©ÿÓ¦§ÿÔ§¦ÿÕ¦¦ÿÕ§¤ÿÕ§¢ÿÕ§ ÿÕ¦�ÿÕ¦›ÿÕ¥šÿÕ¥›ÿÕ¥�ÿÔ¥ ÿÔ¥¢ÿÔ¥¤ÿÓ¤£ÿÒ¤£ÿÒ£¤ÿÑ£¦ÿÑ£©ÿÏ£ªÿ΢«ÿΡ«ÿΡ«ÿΡªÿÍ ¨ÿÍŸ§ÿÍŸ§ÿÌž§ÿËž¨ÿÊž©ÿÉžªÿÈž«ÿÇž®ÿÇ�°ÿÅ�²ÿÄ›³ÿÄœµÿÄ�·ÿܹÿÀ›¹ÿ¼—¸ÿº–·ÿ»—·ÿ¿š·ÿÄœ¹ÿÅŸ»ÿÅ ¾ÿàÂÿ ÅÿÁ ÆÿÀ Êÿ¾ Íÿ½ŸÎÿ¼ŸÎÿ»ŸÏÿ»ŸÑÿºžÑÿ¸žÑÿ·�Òÿ·�Óÿ·�Óÿ¶�Òÿ¶œÑÿ¶œÐÿ·œÎÿ·›Îÿ¶šÍÿ¶™Íÿµ˜Ìÿµ˜Ìÿ´—Ìÿ³–Ìÿ²–Íÿ±•Ìÿ°”Ëÿ°“Êÿ°“Éÿ¯’Çÿ¯‘Æÿ­�Èÿ«‘Ëÿ©‘Íÿ¨‘Îÿ¨�Íÿ¨�Ìÿ¥�Òÿ¢‘Ùÿ ’Üÿ¡’Ûÿ¡’Ûÿ¢’Ûÿ �Ùÿ„v³ÿ>3PÿdXŠÿ–…Æÿ¥‘Ôÿ¤�Ìÿ¥ŒÊÿ¦ŒÇÿ¦‹Åÿ§‹Äÿ¨‹Ãÿ¨ŠÁÿ©Š¿ÿ©‹¾ÿ©‹¿ÿª‹Áÿ©‹ÀÿªŠ¾ÿ«Š¼ÿ¬‹ºÿ«‹»ÿªŒÂÿ¨�Ëÿ¥ŽÎÿ¥ŽÎÿ§ŒÈÿ©Š½ÿ«‰¹ÿ«‰ºÿ©‰½ÿ§‰Áÿ¦‰Äÿ¤‰Äÿ£ˆÃÿ£‡Àÿ¤…ºÿ¦…³ÿ§ƒ±ÿ§ƒ°ÿ¦‚°ÿ¥�²ÿ£‚¶ÿ¢ƒ¼ÿ „ÀÿŸ„ÃÿŸƒÂÿ �½ÿ €¹ÿ ¶ÿ µÿ µÿ ·ÿŸ¸ÿž~¸ÿž~µÿ }±ÿ¢}¯ÿ¡~°ÿ }²ÿž~µÿœ~¸ÿ›~¹ÿš}¸ÿœ}·ÿœ|·ÿœ}¹ÿœ~¼ÿšÀÿ˜Åÿ•€Éÿ“�Íÿ’�Îÿ“€Ìÿ–~Åÿ—}Àÿ—}Àÿ—}Áÿ•}Ãÿ“}Æÿ’~Èÿ’~Èÿ“~Æÿ“}Åÿ“}Ãÿ’}Ãÿ‘|Äÿ‘|Äÿ‘{Ãÿ‘yÀÿ‘y¾ÿ’z½ÿ’y¾ÿ“z¿ÿ’zÀÿ“z¿ÿ•z½ÿ–y¹ÿ—y¶ÿ˜y´ÿ™y³ÿ™x±ÿ™x¯ÿšx¯ÿšx¯ÿšy°ÿ™y±ÿ™z³ÿ™z´ÿ™y´ÿ™y´ÿ™x´ÿ™y´ÿ™x´ÿ˜xµÿ—xµÿ–xµÿ•w¶ÿ”w¶ÿ”w¶ÿ“w¶ÿ“w¶ÿ’w·ÿ‘v¸ÿ�v¹ÿ�v¹ÿ�u¹ÿ�u¹ÿɪËÿɪËÿɪÉÿʪÇÿÌ©ÃÿÍ©¾ÿϨ¸ÿШµÿѨ²ÿѧ±ÿѧ±ÿЧ²ÿΦ²ÿÍ¥²ÿÌ¥²ÿ̤²ÿË£²ÿË£³ÿË£³ÿË£²ÿÌ£±ÿÍ£°ÿΤ°ÿÏ¥±ÿЦ±ÿѦ±ÿѦ¯ÿѦ­ÿÒ¦¬ÿÒ¦«ÿÓ¦©ÿÔ§¨ÿÔ§¨ÿÕ§§ÿÕ§§ÿÕ§¤ÿÖ§¡ÿÕ¦�ÿÕ¦šÿÖ¦šÿÕ¥›ÿÕ¦œÿÕ¦�ÿÕ¥ŸÿÕ¥¡ÿÕ¥¡ÿÔ¥¢ÿÔ¥¢ÿÓ¤£ÿÒ¤¦ÿÒ¤¨ÿÑ£¨ÿТ¨ÿÏ¢¨ÿÏ¡¨ÿÏ¡¦ÿΠ¦ÿΠ§ÿÍŸ§ÿÍŸ¨ÿËŸ¨ÿÊŸ¨ÿÉžªÿÉž¬ÿÈž®ÿÇž¯ÿÆœ°ÿÆœ²ÿÆ�µÿÅ�·ÿ›·ÿ¿˜·ÿ¾˜·ÿÁš¸ÿÄ�¸ÿÆŸ»ÿÇ ¼ÿÆ¡¿ÿÄ¡Ãÿ¡ÇÿÁ¡ÈÿÀ Êÿ¾ Íÿ½ Îÿ¼ Ïÿ¼ Ñÿ» ÓÿºŸÔÿ¸žÔÿ¸ŸÖÿ·žØÿ¶žØÿµžØÿ´žØÿµ�Öÿµ�ÕÿµœÔÿµ›Óÿ´šÒÿ³™Ñÿ³™Ðÿ³˜Îÿ³˜Íÿ²—Íÿ±–Ëÿ±”Éÿ±“Éÿ±“Çÿ°’Åÿ¯‘Äÿ®‘Æÿ«‘Ìÿ¨’Ðÿ§’Ñÿ§‘Ðÿ¦�Ðÿ¤‘Õÿ¢’Ùÿ¢’Úÿ¢‘×ÿ£‘×ÿ¤’Øÿ�ŠÌÿ|l¡ÿ8,DÿWKtÿ“�¿ÿ¥‘Óÿ¤ŽÎÿ¥�Ìÿ¦�Êÿ¦ŒÇÿ§‹Æÿ§‹Åÿ¨‹Ãÿ©‹Áÿ©‹¿ÿ©ŠÀÿ©‹Âÿ©‹ÁÿªŠ¿ÿ«Š½ÿ¬‹»ÿ¬‹»ÿ«ŒÀÿ©ŒÆÿ¨�Èÿ§�Èÿ¨ŒÃÿ«‰¸ÿ«‰¶ÿ«‰¸ÿ©‰¼ÿ¨‰Àÿ¥‰Äÿ¤‰Åÿ£ˆÆÿ£ˆÃÿ¤‡¾ÿ¥…¹ÿ¥…·ÿ¥„¶ÿ¥ƒ·ÿ¥ƒ¹ÿ£ƒ¼ÿ „Áÿž…Äÿž…Æÿž„Åÿž‚Áÿ �¾ÿ €»ÿŸ€¹ÿŸ€¹ÿŸ¹ÿŸ¸ÿž~·ÿž}´ÿ |°ÿ¡}®ÿ }±ÿŸ}³ÿ�}µÿœ~¸ÿ›}ºÿ›}ºÿ›}ºÿ›}ºÿ›}»ÿš~¿ÿ˜Ãÿ–€Èÿ”€Ìÿ“‚Ïÿ“‚Ïÿ“�Ìÿ–Åÿ—~Âÿ–~Ãÿ•~Äÿ•~Æÿ”Èÿ’Êÿ’Ëÿ’Êÿ’Êÿ’Èÿ’~Çÿ’~Çÿ’}Æÿ‘{Äÿ’{Âÿ’zÀÿ“z¿ÿ“z¾ÿ“z¿ÿ“zÀÿ“z¿ÿ•z½ÿ–zºÿ—z¹ÿ˜z¸ÿ˜z¶ÿ˜yµÿ˜y´ÿ˜yµÿ˜yµÿ˜zµÿ˜z¶ÿ™z·ÿ™z¶ÿ˜y¶ÿ˜y¶ÿ™z¶ÿ™yµÿ™yµÿ˜y·ÿ–y¸ÿ•x¹ÿ”y¹ÿ”y¹ÿ“x¹ÿ“w¹ÿ’w¹ÿ‘wºÿ�w»ÿ�w½ÿ�w¾ÿ�w¾ÿ�v½ÿȪÍÿɪÌÿÊ«ËÿË«Êÿ˪ÇÿͪÃÿÍ©¾ÿÏ©ºÿѨ·ÿѨ´ÿѨ²ÿѧ²ÿЧ±ÿϦ±ÿͦ±ÿͦ²ÿÌ¥³ÿ̤´ÿ̤´ÿË£³ÿÌ£°ÿÌ£°ÿÍ£°ÿÎ¥±ÿϦ±ÿѦ±ÿѦ¯ÿÒ¦­ÿÒ¦¬ÿÓ¦ªÿÔ§©ÿÔ¨©ÿÔ¨¨ÿÕ§¨ÿÕ§§ÿÖ¨¥ÿÖ¨¡ÿÖ§�ÿÖ¦šÿÖ¦šÿÖ¦›ÿÕ¦›ÿÕ¦œÿÖ¦�ÿÖ¥žÿÕ¦ŸÿÕ¦¡ÿÕ¦¡ÿÔ¥¢ÿÓ¥¤ÿÓ¥¥ÿÓ¤¥ÿÒ¤¤ÿÑ£¤ÿÒ£¤ÿÑ¢¤ÿТ¥ÿÏ¡¦ÿÏ¡§ÿΠ¨ÿÍ §ÿËŸ¨ÿÊŸ©ÿÊžªÿÉž«ÿÈž¬ÿÈ�­ÿÈ�¯ÿÈž±ÿÇž³ÿÅœ´ÿÁ™µÿšµÿÅ�¶ÿÇž¸ÿÇ »ÿÇ¡½ÿÆ¡ÀÿÅ¡ÃÿáÆÿ¡ÇÿÁ ÈÿÀ Ëÿ¾¡Íÿ¼ Ïÿ» Óÿº ×ÿ¸ Øÿ· Øÿ· Úÿ¶ŸÛÿ´ŸÜÿ³ŸÝÿ³ŸÝÿ³žÜÿ³žÛÿ³�Ùÿ³œ×ÿ³›Õÿ³šÔÿ²™Òÿ±™Ðÿ±™Ïÿ²—Îÿ²–Ëÿ²“Çÿ±“Çÿ±’Åÿ°’Ãÿ¯‘Äÿ®�Çÿª‘Îÿ§’Òÿ¥’Óÿ¥‘Óÿ¤‘Ôÿ¤‘Öÿ¤‘Öÿ¤‘Ôÿ¥�Ñÿ¦�Ðÿ¥�Ïÿ•¸ÿnZ„ÿ- 0ÿ@3MÿŠy²ÿ£ŽÑÿ¤ŽÐÿ¥ŽÏÿ¦ŽÍÿ§ŒÈÿ§‹Åÿ¨‹Äÿ¨‹Ãÿ©‹Áÿ©Š¿ÿ©ŠÀÿ©ŠÁÿ©‹ÁÿªŠ¿ÿ«Š¾ÿ«Š½ÿ«‹½ÿ«‹ÀÿªŒÂÿ©ŒÄÿ¨ŒÄÿ©‹Áÿª‰»ÿª‰¹ÿ©Š»ÿ¨‰¿ÿ§‰Ãÿ¤ŠÆÿ£‰Çÿ¢‰Èÿ¢ˆÇÿ¢ˆÄÿ¢‡Âÿ¢†Áÿ¢†Àÿ£†Àÿ¢…Âÿ¡…Äÿž†Èÿœ†Êÿœ†Êÿœ…Èÿ�ƒÅÿŸ‚ÁÿŸ�¾ÿž�½ÿž€»ÿŸºÿŸ¹ÿŸ¸ÿŸ~µÿŸ|²ÿ |±ÿŸ}²ÿž}´ÿ�}µÿœ}·ÿ›}»ÿš}¼ÿš}¼ÿ™}¾ÿ™~Àÿ˜~Ãÿ–Æÿ”�Ëÿ“‚Ïÿ“‚Ðÿ“‚Ïÿ”�Ëÿ•€Èÿ–€Çÿ•€Èÿ”Çÿ•Çÿ•€Èÿ“€Éÿ“€Êÿ’€Íÿ‘€Îÿ’€Íÿ’€Ìÿ’Ëÿ’~Èÿ“|Åÿ“|Âÿ”{Àÿ•{¿ÿ”z½ÿ”z½ÿ”{¿ÿ”{¿ÿ•z½ÿ–z»ÿ—z»ÿ—zºÿ˜z¹ÿ˜z¸ÿ˜z¸ÿ˜{ºÿ˜z¹ÿ˜z¹ÿ˜{¹ÿ™{¹ÿ˜z·ÿ˜y¶ÿ˜z¶ÿ˜z¶ÿ™zµÿ™y¶ÿ—z¹ÿ•z»ÿ”y¼ÿ”y¼ÿ“y¼ÿ“x½ÿ’x¾ÿ‘x¾ÿ�x¾ÿŽxÀÿŽxÂÿŽxÂÿŽxÂÿ�xÁÿǪÏÿȪÍÿÊ«ÌÿË«ËÿË«ÊÿÌ«ÇÿͪÃÿΪ¿ÿϪ¼ÿЩ¸ÿÑ©µÿѨ²ÿѨ±ÿЧ±ÿΦ²ÿΧ²ÿΦ²ÿͦ³ÿÌ¥³ÿ̤²ÿ̤±ÿ̤±ÿͤ±ÿͤ±ÿÎ¥±ÿЦ°ÿÑ¥¯ÿÒ¥­ÿÓ¥«ÿÓ¦©ÿÔ¨©ÿÔ¨¨ÿÕ¨§ÿÕ¨§ÿÕ¨¥ÿÖ¨£ÿÖ¨ ÿר�ÿ×§œÿÖ¦›ÿÖ¦›ÿÖ¦›ÿצ›ÿצœÿÖ¦�ÿÕ¦žÿÕ¦ŸÿÕ¦ ÿÕ¥¡ÿÕ¦£ÿÕ¥£ÿÔ¦¢ÿÔ¦¡ÿÔ¥¡ÿÔ¤¡ÿÓ£¢ÿÒ£¢ÿÑ£¤ÿТ¦ÿÏ¢§ÿΡ§ÿÍ §ÿÌŸ§ÿËŸ¨ÿÊž©ÿÉž©ÿÊž©ÿÊŸªÿËŸ«ÿÊŸ­ÿÇ�¯ÿÅ›°ÿÆœ±ÿÈŸ³ÿÉŸµÿÉ¡¹ÿÈ¡¼ÿÇ¡¾ÿÆ¡ÀÿÅ¡ÂÿàÃÿ ÅÿÁ¡Éÿ¿¡Íÿ½¡Ñÿº Ôÿ¸¡Øÿ·¡Ûÿµ¡Üÿ´¡Üÿ³ Ýÿ²ŸÞÿ±Ÿßÿ±Ÿßÿ±žÞÿ±ŸÞÿ±žÝÿ±�Üÿ±œÙÿ±›×ÿ°šÕÿ°™Õÿ°™Ôÿ°—Ñÿ±–Ìÿ±“Çÿ±’Æÿ°‘Åÿ®‘Åÿ­‘Èÿ¬‘Ëÿ¨’Ðÿ¥’Õÿ¤’Öÿ¤‘Öÿ£‘Öÿ¥‘Ôÿ¦�Ñÿ§�Îÿ¨�Ëÿ¥�Åÿ�„¼ÿ‡o ÿ_Kmÿ&%ÿ3';ÿxhœÿ—„Ãÿ¡ŒÍÿ£�Íÿ¦ŽÌÿ§�Çÿ¨ŒÄÿ¨ŒÄÿ¨‹Âÿ¨ŠÀÿ¨Š¿ÿ¨‹Áÿ¨‹Âÿ¨ŠÁÿ©‹Àÿª‹Àÿª‹Àÿª‹Áÿ©‹Âÿ¨‹Äÿ¨ŒÄÿ¨ŒÄÿ©‹Âÿ©ŠÀÿ¨Š¾ÿ¨ŠÀÿ§ŠÃÿ¥ŠÇÿ¢ŠÉÿ¡ŠËÿ ŠÍÿŸŠÍÿž‰Ìÿž‰Ìÿž‰ËÿžˆËÿŸˆËÿžˆËÿ�ˆÌÿ›‡Ïÿš‡Ðÿš‡Îÿ›†Ëÿ�„ÆÿŸƒÂÿž‚Áÿž‚¿ÿž�¾ÿž€¼ÿŸ€¼ÿŸ€¼ÿŸ¹ÿŸ~·ÿž}¶ÿ�}µÿ�}¶ÿœ}¸ÿ›}»ÿ™}¾ÿ™~¿ÿ—~Áÿ–~Äÿ•~Æÿ•Èÿ”€Êÿ“‚Ïÿ’ƒÑÿ’ƒÐÿ’�Îÿ”�Ìÿ•�Ëÿ•‚Ìÿ”‚Ìÿ•�Êÿ•€Èÿ•€Èÿ”€Éÿ“€Ëÿ’�Îÿ‘‚Òÿ�‚Òÿ�‚Ðÿ‘�Îÿ“€Êÿ”}Äÿ–|¿ÿ—|½ÿ—|¼ÿ–{»ÿ•{¼ÿ•|¿ÿ•|Àÿ•{¿ÿ–{¾ÿ–z¼ÿ–{»ÿ—{»ÿ—{ºÿ˜{ºÿ˜|»ÿ˜{»ÿ—{ºÿ—z¹ÿ˜{¹ÿ˜{·ÿ˜z¶ÿ˜z¶ÿ˜z¶ÿ˜y¶ÿ—y¸ÿ–z»ÿ”{¾ÿ“z¿ÿ’yÀÿ’yÀÿ‘yÂÿ�zÃÿ�zÄÿ�yÄÿŽyÅÿŽzÅÿŽzÅÿŽzÅÿŽzÅÿƬÒÿÇ«ÑÿÈ«ÏÿɬÎÿɬÌÿË«ÊÿÌ«ÆÿΫÃÿΫÀÿΫ½ÿϪºÿÏ©·ÿϨ³ÿϧ±ÿШ±ÿШ°ÿϧ±ÿΦ²ÿΦ²ÿÍ¥±ÿÌ¥±ÿÍ¥±ÿÍ¥±ÿÎ¥±ÿÏ¥±ÿϤ°ÿÐ¥¯ÿÑ¥­ÿÒ¥«ÿÓ¦ªÿÔ¨ªÿÕ©©ÿÕ©§ÿÕ©¦ÿÖ¨¤ÿÖ¨¡ÿרŸÿר�ÿרœÿ×§›ÿצ›ÿ×§œÿاœÿ×§œÿÖ¦œÿÕ¦žÿÔ¦žÿÕ¦ŸÿÕ¦ ÿÖ§¡ÿÕ§ ÿÔ¦ ÿÔ¦ŸÿÕ¦ŸÿÔ¥ŸÿÔ¥ŸÿÓ¤ ÿÒ¤¡ÿѤ£ÿФ¤ÿУ¥ÿÏ¢¥ÿÍ¡¦ÿÌ¡§ÿÌ ¨ÿË ¨ÿÊŸ§ÿËŸ§ÿÌ §ÿÌ ¨ÿË ©ÿÊŸªÿËŸ«ÿÌ¡­ÿË¡°ÿË¢´ÿÊ¢·ÿÈ¡¹ÿÇ¡¼ÿÆ¢¿ÿÄ¡ÀÿáÃÿÁ¡Èÿ¾¡Îÿ¼¡Ôÿ¹¡Öÿ·¡Úÿ¶¡Ýÿ³¡ßÿ² Þÿ± ßÿ°Ÿßÿ° ßÿ° ßÿ°Ÿàÿ°Ÿàÿ°žÞÿ¯�Ýÿ¯�Üÿ¯œÚÿ®œÙÿ­šÙÿ­™×ÿ¯—Ôÿ¯–Îÿ¯“Éÿ¯’Èÿ®’Èÿ­’Êÿ«“Íÿ¨“Ñÿ¥”Ôÿ¤”×ÿ¤”Ùÿ¤“×ÿ¤’Õÿ¥‘Òÿ§�Ðÿ¨�Íÿ§ŽÈÿ�ƒ¹ÿzd�ÿWDeÿ;,@ÿÿ$%ÿM@bÿwgšÿ�|¸ÿ™‚¿ÿ¦ŒÉÿ¨�Éÿ¨ŒÆÿ¨ŒÅÿ§‹Åÿ¦‹Äÿ¥‹Äÿ¦‹Åÿ§ŒÅÿ§‹Ãÿ§‹Áÿ¨‹Áÿ¨‹Äÿ§ŒÆÿ§�Èÿ§�Èÿ§�Çÿ¦ŒÆÿ§ŒÅÿ¨ŒÄÿ¦‹Ãÿ¦‹Åÿ¤‹Èÿ¢‹Ëÿ ‹ÎÿŸŒÑÿžŒÓÿœŒÔÿ›‹Óÿ›‹Óÿ›ŠÒÿ›ŠÒÿœ‰Òÿ›‰Òÿš‰Óÿ™‰Õÿ˜‰Ôÿ™ˆÑÿš‡Ìÿœ†Çÿž„Âÿ�ƒÂÿ�‚Âÿ�‚Áÿœ�Àÿ��¾ÿ�€¾ÿœ€½ÿœ¼ÿœ~¼ÿ›~»ÿš~»ÿ™~¿ÿ˜Ãÿ–Äÿ–€Åÿ”€Èÿ’€Êÿ“€Ëÿ“€Ëÿ“‚Îÿ’ƒÓÿ�„Ôÿ�ƒÒÿ’‚Ïÿ”‚Ìÿ”‚Îÿ”‚Ïÿ•‚Íÿ•‚Êÿ•�Ëÿ•�Êÿ•�Ëÿ“�Íÿ�‚Ñÿ�ƒÔÿ�„Õÿ�ƒÔÿ‘�Ðÿ“€Êÿ–~Ãÿ™}¼ÿš|¹ÿš|¹ÿ˜{ºÿ–{¼ÿ•|¿ÿ•|Àÿ•|Àÿ•|¿ÿ•{½ÿ•{½ÿ–{¼ÿ–{¼ÿ—{»ÿ˜|»ÿ˜|ºÿ˜{¸ÿ˜{¸ÿ˜{¸ÿ—z¸ÿ–z·ÿ—z¸ÿ—z¹ÿ•{»ÿ”{¼ÿ“{¿ÿ’{Áÿ‘{Âÿ�{Ãÿ�{Äÿ�{Æÿ�{Èÿ�{Éÿ�{ÊÿŽ{ÉÿŽ{ÈÿŽzÇÿŽzÆÿ�{ÇÿÅ«ÕÿÆ«ÔÿǬÓÿȬÑÿɬÏÿʬÌÿÌ«ÈÿΫÄÿÏ«ÂÿÏ«ÁÿΫÁÿϪ½ÿÏ©¸ÿЩµÿШ´ÿѨ³ÿѨ³ÿШ³ÿϧ³ÿΦ²ÿΦ²ÿϦ²ÿΦ²ÿÎ¥±ÿÐ¥±ÿÏ¥°ÿÐ¥¯ÿÐ¥­ÿÑ¥¬ÿÒ¦¬ÿÓ§«ÿÕ©ªÿÖ©¨ÿÖ©¦ÿÖ©¢ÿר ÿרŸÿשžÿרœÿاœÿاœÿ×§œÿبœÿبœÿ×§�ÿÖ§žÿÖ§žÿÖ¦žÿÖ¦ŸÿÕ§ ÿÕ¦ŸÿÕ¦ŸÿÕ¦ŸÿÕ¦žÿÕ¦žÿÕ¥ŸÿÔ¥ŸÿÔ¥ ÿÓ¥¡ÿÓ¥¢ÿÒ¤£ÿÑ£¤ÿУ¥ÿÏ¢¦ÿΡ§ÿÍŸ¨ÿÌŸ§ÿÌŸ¦ÿÍ ¦ÿÏ¡¥ÿÏ¡¥ÿÏ¡¦ÿÏ¢§ÿÏ¢ªÿÍ¢­ÿÍ£±ÿÌ£³ÿÊ£¶ÿÉ¢ºÿÈ£¾ÿÆ¢¿ÿÄ¢Âÿ¡Èÿ¿¡Ïÿ¼¢Ôÿº¢Öÿ¸¡Úÿµ¡ßÿ²¢âÿ°¡äÿ®¡äÿ® ãÿ¯ âÿ° áÿ¯Ÿáÿ¯Ÿàÿ¯žßÿ¯žßÿ®�Þÿ­œÞÿ¬œÞÿ¬›Üÿ¬šÚÿ®˜Õÿ®–Ðÿ®”Íÿ­“Íÿ¬“Íÿ«“Ïÿ©”Òÿ§”Öÿ¤•Ùÿ£•Ûÿ£•Ûÿ£”Øÿ¤’×ÿ¤‘Ôÿ¥�Òÿ¦�Ñÿ ‰Çÿ~i—ÿRA`ÿ0"4ÿ%"ÿÿÿ-!2ÿL?bÿkZ‰ÿ‡r§ÿ¤ŒÈÿ¨ŽÍÿ§�Êÿ§�Éÿ¦�Éÿ¥�Ëÿ¥�Ëÿ¦�Éÿ¦ŒÇÿ§ŠÄÿ¨‹Âÿ§‹Ãÿ§ŒÆÿ§�Êÿ§�Ìÿ¦�Ìÿ¦�Ëÿ¦�Êÿ¦�Éÿ¦ŒÈÿ¥‹Æÿ¤‹Èÿ£‹Êÿ¡‹ÎÿžŒÒÿ��Õÿ›�Øÿ™�Úÿ˜ŒÚÿ™ŒÙÿ™‹×ÿ™‹×ÿšŠÖÿ™ŠÖÿ˜ŠØÿ—‹Øÿ—Š×ÿ˜‰Óÿš‡Îÿœ†Éÿœ„Åÿ›ƒÅÿšƒÆÿšƒÆÿ›‚Äÿš‚Äÿ›‚Åÿš�Äÿš€Ãÿ™€Äÿ—€Äÿ—€Æÿ•�Éÿ“�Ëÿ’�Ìÿ’�Íÿ‘‚Ðÿ‘‚Ñÿ‘‚Ðÿ‘‚Ðÿ‘„Óÿ�…Öÿ�…Öÿ�„Ôÿ’ƒÏÿ“ƒÎÿ“ƒÏÿ”ƒÑÿ•ƒÐÿ•‚Îÿ•ƒÎÿ•ƒÎÿ“‚Îÿ’ƒÐÿ‘ƒÔÿ�„Õÿ�„Öÿ�ƒÔÿ’‚Ïÿ”€Éÿ—Ãÿ™~¾ÿš}»ÿ›}»ÿ™}¼ÿ˜}¾ÿ—}Àÿ–}Áÿ—}Áÿ—|Àÿ–{¾ÿ–{¿ÿ–|¿ÿ–|¾ÿ—|½ÿ—{»ÿ˜{¹ÿ˜{¹ÿ—{ºÿ–z»ÿ–{½ÿ•{¼ÿ•{¾ÿ”{Àÿ“{Áÿ‘{Âÿ‘{Ãÿ�{Äÿ�{Åÿ�|ÆÿŽ|ÇÿŒ|ÊÿŒ|ÌÿŒ|ÌÿŒ|Ìÿ�|ÊÿŽ{ÈÿŽ{ÇÿŽ{Æÿ�zÇÿÆ«ÖÿÇ«ÖÿǬÕÿǬÔÿǬÒÿɬÎÿˬÊÿÍ«ÇÿΫÅÿÏ«ÄÿΫÃÿÏ«ÀÿЪ¼ÿЪ¹ÿÑ©¸ÿÑ©·ÿÒ©¶ÿÑ©µÿШ´ÿϨ´ÿϨ´ÿϧ³ÿϧ²ÿϧ²ÿϦ²ÿЦ±ÿÐ¥°ÿÐ¥¯ÿЦ®ÿѧ­ÿÒ§­ÿÔ¨ªÿÕ©¨ÿÖ©¦ÿÖ©£ÿÖ©¢ÿש¡ÿשŸÿשžÿש�ÿר�ÿר�ÿרœÿשœÿר�ÿר�ÿרžÿÖ§žÿÖ§ŸÿÕ§ŸÿÖ§ŸÿÖ§ŸÿÖ§ŸÿÕ§žÿÕ¦žÿÕ¦žÿÕ¦žÿÕ¦ŸÿÕ¥ ÿÔ¥ ÿÔ¥¡ÿÓ¥¢ÿÓ¥£ÿÒ¤¤ÿÑ¢¥ÿÏ¡¦ÿΠ¦ÿÍ ¦ÿÏ¡¦ÿТ¤ÿÑ¢£ÿÒ¢¤ÿÑ£¥ÿУ§ÿÏ£ªÿÏ£®ÿΣ±ÿ̤´ÿË£·ÿÉ£½ÿÇ£ÀÿÅ£ÄÿâÉÿÀ¢Îÿ¾¢Òÿ»¢Ôÿ¹¢Øÿµ¢Þÿ²¢ãÿ°¢åÿ®¢æÿ®¡åÿ® ãÿ¯ âÿ®Ÿâÿ®Ÿáÿ®žáÿ®�àÿ­�àÿ¬�áÿ«œáÿª›àÿ«šÞÿ¬™Ùÿ­–Óÿ­•Ñÿ¬•Òÿª•Ôÿ¨•Öÿ¦•Øÿ¥–Üÿ£–Þÿ¢–Þÿ¡•Ýÿ¢”Ûÿ£”Úÿ£’Øÿ£’Øÿ£’Ùÿš‰ÍÿcTÿ3&<ÿÿÿÿÿÿ#(ÿM@bÿl ÿ£ŒÊÿ§�Ðÿ¥ŽÎÿ¥�Íÿ¥ŽÍÿ¤ŽÏÿ¤ŽÏÿ¥�Ìÿ¦ŒÉÿ§‹Æÿ§ŒÅÿ§ŒÆÿ§�Éÿ§ŽËÿ§�Íÿ¥�Íÿ¥�Ìÿ¥�Ìÿ¤ŒÌÿ¤ŒÊÿ¤‹Éÿ£‹Êÿ¢‹Ìÿ ‹ÐÿžŒÓÿœŒÖÿš�Úÿ˜ŽÜÿ—�Üÿ—�Üÿ—�Ûÿ˜ŒÛÿ—‹Úÿ—‹Úÿ–ŠÚÿ–‹Úÿ–ŠØÿ—‰Õÿ™ˆÒÿš†Îÿš†Ìÿ™…Ëÿ˜…Ìÿ˜…Ìÿ˜„Ìÿ—„Ìÿ—„Íÿ—ƒÍÿ–ƒÌÿ•‚Íÿ“‚Îÿ’ƒÏÿ‘„Òÿ�„ÔÿŽ„ÕÿŽ„Öÿ�„×ÿ�…×ÿ�…Öÿ�…Öÿ�†Øÿ�†Øÿ�†×ÿ‘…Ôÿ“„Ïÿ”„Îÿ“„Ñÿ“…Ôÿ“…Ôÿ”ƒÒÿ”„Ñÿ“„Ñÿ“„Òÿ’„Óÿ‘…Õÿ‘…Öÿ‘…Öÿ‘„Óÿ“‚Îÿ•€Èÿ—Äÿ˜~Àÿš~¾ÿš~¾ÿ™~¿ÿ˜Áÿ—Áÿ˜~Àÿ™~Àÿ™}¾ÿ˜|½ÿ—|¾ÿ—|¿ÿ—|¿ÿ–|¾ÿ–|½ÿ–{¼ÿ–{¼ÿ•{½ÿ”{¿ÿ”{Áÿ“{Áÿ’{Ãÿ‘|Äÿ�{Åÿ�{Åÿ�{ÆÿŽ{ÆÿŽ{Çÿ�|Éÿ�|ÊÿŒ}ÌÿŒ}ÌÿŒ|Ëÿ�|Êÿ�|ÉÿŽ{Èÿ�{ÇÿŽ{Çÿ�zÇÿÆ«ÖÿÆ«ÖÿƬÖÿƬÖÿƬÔÿȬÑÿʬÍÿˬÊÿÌ«ÈÿÍ«ÆÿÍ«ÅÿΫÃÿÏ«¾ÿЫ»ÿЫ»ÿѪºÿÒª¸ÿÒ©¶ÿÑ©´ÿЩµÿϨ´ÿϨ´ÿϨ´ÿϨ´ÿϧ³ÿЧ³ÿЦ²ÿЦ±ÿЧ°ÿѧ®ÿÒ§­ÿÓ¨ªÿÕ¨¨ÿÖ©¦ÿÖ©¥ÿÖ©¤ÿש£ÿש¡ÿתŸÿתžÿשžÿשžÿש�ÿש�ÿשœÿØ©�ÿשžÿÖ¨žÿÖ¨ŸÿÖ¨ ÿÖ¨ ÿÖ§ŸÿÖ§ŸÿÕ§žÿÕ§�ÿÕ¦žÿÕ¦žÿÕ¦ŸÿÕ¦ ÿÕ¦ ÿÕ¦ ÿÕ¦¡ÿÔ¥¡ÿÓ¥¢ÿÓ¤¢ÿÒ£¤ÿТ¥ÿС¥ÿС¥ÿТ¥ÿÑ¢¤ÿÒ£¤ÿÒ£¥ÿÑ£§ÿУ©ÿÏ£¬ÿΤ°ÿͤ²ÿ̤µÿÊ£»ÿÈ£ÀÿÆ£ÅÿãÉÿÁ£Îÿ¿£Ñÿ¼£Óÿº£×ÿ·¢Üÿ³¢àÿ±¢ãÿ°¢åÿ¯¡äÿ®¡ãÿ® âÿ® âÿ­Ÿãÿ¬žãÿ¬�âÿ¬�âÿª�ãÿ©�ãÿ©œãÿª›áÿ«™Ýÿ¬˜Öÿ¬—Õÿª—×ÿ§—Úÿ¥—Ýÿ¤—ßÿ£—áÿ¢—âÿ¡–àÿ¡•ßÿ¢•Þÿ¢•Ýÿ¢”Ýÿ¡“Ýÿ¡”àÿ•ŠÒÿYM|ÿ(2ÿ + ÿ ÿÿÿ ÿÿD8Yÿ{j¡ÿ¢�Íÿ¦‘Óÿ¤�Ðÿ¤ŽÐÿ¤ŽÏÿ£ŽÐÿ¤ŽÏÿ¥ŽÎÿ¦�Ëÿ¦�Êÿ§�Éÿ§�Êÿ¦�Êÿ¦ŽËÿ¦ŽÍÿ¥�Îÿ£�Îÿ¢ŒÎÿ¢ŒÎÿ£ŒÍÿ£‹Ìÿ¢‹Ìÿ¡‹ÎÿŸ‹Ñÿ�‹ÓÿœŒÕÿšŒØÿ™�Úÿ˜�Ûÿ—�Ýÿ–ŽÞÿ•Žßÿ•�Þÿ•ŒÜÿ•‹Üÿ”‹Ûÿ“ŠÙÿ”‰Øÿ•ˆÖÿ•‡Õÿ•‡Óÿ–‡Òÿ•‡Óÿ”‡Ôÿ”‡Õÿ”‡Õÿ”†Õÿ“†Õÿ’†Õÿ‘…Õÿ�…ÖÿŽ…×ÿކÚÿ�‡ÜÿŒ‡ÝÿŒ‡Üÿ�‡Üÿ�‡ÜÿއÛÿŽˆÜÿ�‡ÜÿއÚÿ�‡Ùÿ‘†Öÿ“…Òÿ”…Ñÿ’†Ôÿ‘‡×ÿ’†×ÿ’…Õÿ’…Ôÿ’…Õÿ‘…Öÿ‘…Öÿ‘…Õÿ‘…Õÿ’…Ôÿ’„Ñÿ“‚Íÿ•€Èÿ–€Æÿ—€Äÿ˜Âÿ™Âÿ˜Ãÿ—€Äÿ—€Ãÿ˜Áÿ™~¿ÿ™~¾ÿ™}¼ÿ˜}½ÿ—|¿ÿ–|Àÿ•|Àÿ”|Àÿ”|Áÿ”|Áÿ“{Áÿ’{Âÿ‘zÃÿ‘zÃÿ�{Åÿ�|ÇÿŽ|ÇÿŽ{Çÿ�{Çÿ�{ÈÿŒ{ÉÿŒ|ÊÿŒ}ËÿŒ}ÊÿŒ|ÉÿŒ|Èÿ�{Èÿ�{Èÿ�{ÈÿŽ{ÈÿŽ{ÈÿŒ{ÈÿÅ«ÖÿƬÖÿŬ×ÿŬ×ÿÆ­ÖÿǬÓÿɬÑÿʬÍÿʬËÿˬÊÿË«ÉÿÌ«ÆÿÍ«ÂÿΫ¿ÿÏ«½ÿÑ«»ÿѪ¹ÿѪ¶ÿÒªµÿÑ©¶ÿÏ©¶ÿϨµÿÏ©µÿÏ©µÿϨ´ÿШ´ÿϧ³ÿЧ³ÿЧ²ÿѨ°ÿÒ¨­ÿÓ¨«ÿÕ©¨ÿÖ©¦ÿÖª¦ÿÖ©¥ÿש£ÿש¡ÿש ÿת ÿتŸÿØ©ŸÿתŸÿתžÿØ©žÿשžÿÖ©žÿÖ©ŸÿÖ© ÿש¡ÿÖ¨ ÿÖ§ŸÿÖ§žÿÖ§žÿÖ¨�ÿÕ§žÿÖ¦ŸÿÖ§ ÿÕ§¡ÿÕ§¡ÿÕ§¡ÿÕ¦¡ÿÕ¦¡ÿÔ¦¡ÿÔ¦ ÿÓ¥¡ÿÓ¤¢ÿÓ¤£ÿÒ£¤ÿÑ£¥ÿÑ£¤ÿÒ£¥ÿÒ¤¦ÿѤ§ÿÑ£¨ÿФ«ÿϤ®ÿͤ±ÿÌ£´ÿ̤¸ÿÉ£½ÿƤÃÿäÉÿÁ¤Îÿ¿¤Òÿ½£Ôÿ»£×ÿ¸¢Úÿµ¢Ýÿ³¢ßÿ³¢âÿ±¢âÿ°¡âÿ¯ ãÿ­Ÿãÿ« åÿªŸäÿ©žäÿ©�ãÿ¨�äÿ§�åÿ¨œäÿ©›ãÿ«šÞÿ¬šØÿ«™Øÿ¨™Ûÿ¥šàÿ£™ãÿ¢˜ãÿ¡˜åÿ ˜äÿ¡˜ãÿ¢—âÿ¢–àÿ¡•ßÿ¡•ßÿ¡•àÿž“àÿ�†ÏÿQIyÿ%0ÿ ÿ ÿ +ÿ ÿ ÿ ÿ9.Oÿn_–ÿŸŒÏÿ¥‘Õÿ£�Ñÿ¤�Ñÿ¤�Ðÿ£ŽÐÿ£ŽÏÿ¤ŽÎÿ¤�Íÿ¥ŽÍÿ¦�Ìÿ¥�Ìÿ¥�Ëÿ¥�Ìÿ¤ŽÎÿ£�Ñÿ¡�Òÿ¡�Òÿ¡ŒÐÿ¢ŒÏÿ¢‹Ìÿ¢‹Íÿ ‹Ïÿž‹Ñÿ�‹Ñÿ�‹Òÿœ‹Ôÿ›ŒÕÿ™�Ùÿ—ŽÝÿ•�áÿ”�âÿ”Žáÿ”Žßÿ”�ßÿ“ŒÝÿ’ŠÛÿ‘‰Úÿ‘ˆÚÿ’ˆÚÿ’ˆÙÿ’ˆÙÿ‘‰Ûÿ�ŠÝÿ�ŠÞÿ�ŠÝÿ�‰Üÿ�ˆÜÿ�ˆÜÿŽˆÝÿ�ˆÞÿŒˆÞÿŒˆàÿ‹ˆáÿЉáÿ‹‰áÿŒˆáÿŒˆàÿŒˆàÿ�‰ßÿŽˆÝÿŽˆÛÿ�‡Úÿ�‡Úÿ‘‡×ÿ’‡×ÿ‘ˆØÿ‘ˆÙÿ‘‡Øÿ‘†×ÿ�†Øÿ�‡Ùÿ�‡Ùÿ�†Øÿ‘…Õÿ‘…Óÿ’„Ñÿ’ƒÐÿ’‚Íÿ”�Êÿ–�Éÿ–�Çÿ–�Æÿ—€Æÿ–€Çÿ•€Çÿ•€Æÿ–Äÿ—~Âÿ—~Áÿ—}Àÿ˜~Àÿ—~Áÿ•}Âÿ“}Ãÿ’}Äÿ’}Äÿ‘|Äÿ�{Äÿ‘{Äÿ�yÃÿ�zÄÿŽ{Æÿ�{Èÿ�|Èÿ�{ÈÿŒzÇÿŒ{ÈÿŒ{Éÿ‹{Éÿ‹|ÉÿŒ{Èÿ�{ÆÿŒ{ÆÿŒzÇÿŒ{ÉÿŒ|ÉÿŒ|ÉÿŒ|Éÿ‹{ÉÿǬ×ÿƬ×ÿŬØÿŬØÿƬ×ÿƬÕÿȬÓÿɬÑÿɬÎÿɬÍÿˬËÿË«ÉÿÌ«ÇÿΫÄÿÏ«ÁÿЫ¾ÿÑ«¼ÿѪºÿѪ¸ÿÑ«¹ÿЪ¹ÿЪ¸ÿЪ·ÿѪ¶ÿЩµÿÏ©µÿЩµÿШ´ÿѨ³ÿѧ°ÿÒ¨­ÿÔ©¬ÿÕ©©ÿÕ©§ÿÖ©¦ÿÖª§ÿת¦ÿש¤ÿÖ©¢ÿת¡ÿת¡ÿת ÿת ÿت ÿש ÿת¡ÿת¡ÿש¢ÿש¢ÿש¢ÿÖ¨ ÿÖ¨ ÿÖ¨ ÿרŸÿÖ¨ŸÿÖ¨ŸÿÖ§ ÿÖ§¡ÿÖ§¡ÿÖ§¡ÿÕ§¡ÿÖ¨¡ÿÕ§¡ÿÕ¦ ÿÕ¦ ÿÕ¥ŸÿÕ¦ ÿÔ¦¡ÿÔ¦¢ÿÔ¦¤ÿÓ¥¤ÿÓ¤¥ÿÒ¤¦ÿÒ¤§ÿÒ¤¨ÿФ«ÿϤ®ÿΤ°ÿͤ´ÿ̤¸ÿʤ¼ÿÇ¥ÂÿÄ¥ÈÿÁ¤Îÿ¿¥Óÿ¾£Õÿ»¢×ÿ¹¢Úÿ·¢Ýÿµ¡Þÿ´¡ßÿ²¢àÿ±¡âÿ¯ ãÿ¬ äÿ« åÿªŸåÿ©žåÿ¨žåÿ§�æÿ¦�æÿ§�åÿ©›âÿª™Þÿ«™Ùÿ©šÝÿ¥šáÿ£šåÿ¢šæÿ¡™æÿ ™æÿŸ™æÿŸ˜æÿ —äÿ¡–áÿ¡–áÿ¡–áÿ •áÿœ‘ÜÿˆÄÿG>aÿÿ ÿÿÿÿÿ + ÿ-#:ÿ`S�ÿš‰Ëÿ¤�Õÿ¤�Òÿ¤�Ñÿ¤�Ðÿ£�Ñÿ¢ŽÐÿ¤ŽÎÿ¥ŽÎÿ¥ŽÎÿ¤ŽÎÿ¤�Íÿ£�Ïÿ¢ŽÑÿ¡ŽÔÿ ŽÕÿŸŽÖÿ ŽÖÿ �Óÿ¡‹Ïÿ¢‹Ìÿ¡‹ÎÿŸ‹Ðÿž‹ÐÿžŠÐÿ�ŠÐÿœ‹ÓÿšŒÖÿ˜ŒÚÿ–ŽÞÿ•�âÿ”�âÿ“Žâÿ’Žâÿ’Žãÿ‘Žãÿ�Œàÿ�‹ßÿ�‹àÿ�‹àÿ�‹âÿ�‹âÿ�Œãÿ��åÿ��åÿŽŒäÿŽŒãÿ�ŒãÿŒŒãÿŒŒäÿ‹‹ãÿ‹‹ãÿ‹Šãÿ‹Šäÿ‹ŒäÿŒŒäÿ‹‹äÿŒŠäÿŒŠãÿŒŠáÿ�‰Þÿ�‰Ýÿ�‰Ýÿ�‰Ýÿ�ˆÛÿ�‰Úÿ‘‰Úÿ‘ˆÚÿ‘‡Ùÿ‘ˆÙÿ’ˆÚÿ‘‡Úÿ�‡Úÿ�‡Øÿ�†Öÿ�„Ôÿ‘„Òÿ’ƒÑÿ’ƒÐÿ“‚Îÿ•‚Ìÿ•‚Ëÿ•‚Êÿ•�Êÿ•�Ëÿ•‚Ëÿ”�Ëÿ”€Éÿ”Èÿ”Æÿ”~Åÿ•~Åÿ”~Åÿ“~Æÿ’~Çÿ‘}Èÿ‘}Èÿ‘|Çÿ�|Æÿ�{ÄÿŽyÃÿ�zÅÿŒ{Èÿ‹{Éÿ‹{Éÿ‹{Èÿ‹zÈÿ‹zÈÿ‹{Èÿ‹{Èÿ�zÇÿ�zÅÿ�yÄÿ�zÅÿ�{Æÿ‹{ÈÿŒ|ÉÿŒ|ÉÿŒ{ÊÿŒ{ËÿÇ­×ÿÇ­×ÿÆ­ØÿÆ­ØÿÇ­×ÿƬÕÿǬÔÿǬÓÿȬÒÿɬÐÿʬÎÿˬËÿË«ÊÿÌ«ÈÿͬÄÿΫÁÿÏ«¿ÿЫ½ÿЫ»ÿÑ«»ÿÑ«»ÿЪºÿѪ·ÿѪ¶ÿЪµÿЩµÿЩµÿÑ©µÿÑ©³ÿÒ¨°ÿÒ¨®ÿÔ©­ÿÕ©«ÿÕª©ÿÕª©ÿÖª¨ÿÖ«§ÿÖ«¦ÿÖª¤ÿת£ÿת£ÿת£ÿת£ÿת¤ÿت¥ÿת¥ÿת¤ÿת¤ÿת¤ÿت£ÿת¢ÿש¡ÿש ÿש ÿש ÿר ÿר ÿר¡ÿÖ¨¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¡ÿÖ§¡ÿÖ§¡ÿÖ§¡ÿÖ¦ ÿÖ§ ÿÖ§ ÿÕ§¡ÿÕ§¡ÿÕ¦¢ÿÔ¦¤ÿÓ¦¥ÿÓ¥§ÿÒ¥¨ÿÐ¥«ÿÏ¥®ÿÏ¥±ÿͤ´ÿˤ¸ÿÉ¥¼ÿÇ¥ÁÿĤÈÿÁ¤Îÿ¾¤Óÿ¼£Õÿ»£Øÿ¹£Ûÿ·¢Ýÿµ¢Þÿ³¢ßÿ²¢áÿ±¢âÿ¯¡ãÿ¬ äÿ«Ÿåÿªžæÿ©žæÿ¨žæÿ§žæÿ¦�æÿ¦œäÿ§›âÿ©šàÿ©™Þÿ§šàÿ¥šâÿ£›äÿ¢›æÿ¡šåÿ ™åÿŸ™æÿžšèÿžšèÿž™çÿŸ™æÿž˜åÿŸ—äÿ—�×ÿzp¬ÿ>4Qÿÿ ÿ!ÿ!ÿ"ÿ!ÿÿ)+ÿVHmÿ‘�¿ÿ¡�Òÿ¤�Óÿ¤�Òÿ£�Òÿ¢�Óÿ¢�Òÿ£�Ñÿ¤�Ñÿ¤�Ñÿ£ŽÐÿ£ŽÐÿ¢ŽÒÿŸ�Öÿ��Ùÿœ�Ùÿœ�ÙÿœŽØÿ��ÕÿŸŒÑÿ ‹ÏÿŸ‹Ñÿ�‹ÒÿœŠÒÿœ‰Ñÿ›ŠÒÿš‹Õÿ˜ŒÙÿ–�Üÿ•Žßÿ”Žáÿ’Žãÿ‘Žäÿ‘�åÿ‘‘çÿ��æÿ�Žäÿ�Œäÿ��åÿ��çÿ��èÿ��èÿ��èÿ��èÿ��èÿŽ�çÿŽ�çÿ��çÿŒ�èÿŒŽçÿŒŒåÿŒ‹ãÿ�‹äÿ�ŒäÿŒŒåÿŒ�æÿ‹Œåÿ‹‹åÿŒŠäÿ�‰áÿ�‰ßÿ�‰Þÿ�‰Þÿ�ŠÞÿ�‰Üÿ‘‰Üÿ‘ŠÛÿ‘‰Ûÿ‘‰Úÿ’‰Úÿ‘ˆÛÿ�ˆÛÿ�‡Úÿ�‡Ùÿ�†×ÿ�…Õÿ�„Ôÿ‘„Óÿ’„Òÿ’ƒÑÿ“ƒÐÿ“ƒÐÿ“ƒÐÿ“ƒÏÿ“‚Ïÿ“‚Ïÿ’‚Îÿ’�Íÿ’€Ëÿ’€Êÿ“Éÿ“~Èÿ“~Èÿ’~Èÿ‘~Éÿ�~Ëÿ�~Êÿ�}Éÿ�|ÇÿŽ{Åÿ�{ÅÿŒ{ÈÿŠ|ËÿŠ|ÌÿŠ|ÌÿŠ{ÊÿŠ{Éÿ‹{Èÿ‹{Èÿ�{ÇÿŽzÅÿ�yÄÿ�yÄÿ�zÅÿŒzÇÿŒ{ÈÿŒ{ÈÿŒzÈÿŒzÈÿŒzÈÿÈ®ÖÿÈ®ÖÿÈ­×ÿÇ­ØÿÆ®×ÿÆ­×ÿÇ­ÕÿÇ­ÔÿǬÔÿȬÒÿɬÏÿʬÌÿʬËÿʬËÿˬÊÿˬÇÿÌ«ÄÿΫÁÿЫ¾ÿЫ¼ÿЫ¼ÿЫ»ÿѪ¹ÿѪ·ÿЪ·ÿЪ¸ÿЪ·ÿЩµÿÑ©´ÿÒ©²ÿÒ©¯ÿÓ©®ÿÔ©­ÿÕª¬ÿÕª«ÿÕªªÿÕ«©ÿÕ«¨ÿÖ«§ÿת¦ÿת¦ÿת¦ÿת§ÿת¨ÿת©ÿת¨ÿת§ÿת¦ÿת¥ÿ׫£ÿת¢ÿש¡ÿש¡ÿש ÿש ÿש¢ÿש¢ÿר¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¢ÿÖ¨¡ÿÖ¨¡ÿÖ§ ÿÖ§ ÿÖ¨ ÿÖ§ ÿÖ§ ÿÕ§¡ÿÕ§£ÿÔ¦¦ÿÓ¦¨ÿÑ¥¬ÿÐ¥¯ÿÎ¥²ÿÍ¥µÿË¥¹ÿÊ¥½ÿÇ¥ÂÿÄ¥ÈÿÁ¤Îÿ¾£Ôÿ»£×ÿ¹£Úÿ¸£Ýÿ¶£Þÿ´¢ßÿ²¢áÿ°¢ãÿ°¢ãÿ®¡äÿ¬ åÿ© æÿ¨Ÿçÿ¨Ÿæÿ¨žæÿ§žåÿ¦�äÿ¦›ãÿ§›âÿ§šáÿ§šàÿ¦šàÿ¦šáÿ¤›ãÿ£›åÿ¡›åÿ¡›æÿŸ›èÿž›êÿ�œëÿœœìÿœœìÿœ›éÿ�™çÿ’ŠÒÿmc—ÿ9.Fÿ"ÿ$ÿ$ÿ$ÿ%ÿ$ÿ"ÿ&"ÿL>^ÿŠy´ÿŸ�Ïÿ¤‘Ôÿ£�Ôÿ£‘Õÿ¢‘Öÿ¢‘Öÿ£�Ôÿ£�Ôÿ£�Ôÿ£�Óÿ¢�Óÿ¡�Ôÿž�Øÿ›�Üÿ™�Ýÿ™�Üÿš�Úÿ›Ž×ÿ��ÕÿžŒÓÿ�ŒÔÿœŒÕÿ›‹Õÿ™‹Õÿ˜‹×ÿ—ŒÚÿ•�Ýÿ”Žàÿ“Žâÿ’Žãÿ‘Žåÿ��æÿ��èÿ�’éÿ�‘èÿ��çÿ�Žçÿ��èÿ�‘êÿ�’êÿ�“êÿ�’éÿ��èÿŽ�èÿŽ�èÿŽ�èÿŽ�èÿ��èÿ�Žæÿ�ŒãÿŽŠáÿ�Šàÿ�‹áÿ�‹ãÿŒŒåÿŒŒäÿŒŠãÿ�‰áÿ�‰àÿމßÿމßÿ�Šßÿ�ŠÞÿ‘ŠÝÿ‘ŠÜÿ‘ŠÛÿ‘ŠÛÿ‘ŠÜÿ‘‰Üÿ‘‰Üÿ�ˆÛÿ�ˆÛÿ‘‡Ùÿ‘‡Øÿ�†Öÿ�…Õÿ�…Ôÿ�…Ôÿ‘…Ôÿ’…Ôÿ’„Óÿ‘„Óÿ‘„Óÿ‘ƒÓÿ‘ƒÒÿ�‚Ñÿ��Ðÿ‘€Îÿ‘€Ìÿ‘€Ìÿ‘~Êÿ‘~Êÿ�~Ëÿ�~ÌÿŽ~Ìÿ�~Ìÿ�}ÉÿŽ{ÇÿŽ|Æÿ�|Èÿ‹|Ëÿ‰}Îÿ‰|Ïÿ‰|Íÿ‰{Ëÿ‰{ÊÿŠ{Éÿ‹zÇÿ�zÆÿ�zÅÿ�yÄÿ�yÄÿ�zÅÿŒzÆÿŒzÆÿŒyÆÿŒyÅÿ‹yÆÿ‹yÆÿÈ®×ÿȯ×ÿÈ®ØÿÇ®ÙÿÆ®ÙÿÆ®ÙÿÇ­ØÿÇ­ÖÿÇ­ÕÿǬÓÿÈ­ÑÿÈ­ÎÿɬÎÿɬÏÿȬÐÿɬÎÿʬÌÿ̬ÈÿΫÄÿΫÁÿά¿ÿϬ¾ÿЫ¼ÿЪ»ÿЪ¼ÿЫ»ÿЪºÿЪ¸ÿЪ¶ÿѪ´ÿÒ©²ÿÓ©±ÿÔ©¯ÿÔª®ÿÕª®ÿÔ«®ÿÕª­ÿÕª¬ÿÖ««ÿÖ«©ÿת¨ÿת¨ÿÖª©ÿÖ«ªÿÖ««ÿתªÿת©ÿת¨ÿ׫¦ÿ׫¤ÿת£ÿت¢ÿت¡ÿת¡ÿש¡ÿØ©£ÿש¤ÿש¤ÿש¤ÿÖ©¤ÿÖ©¤ÿÖ©¤ÿÖ¨¤ÿÖ¨£ÿÖ¨¢ÿÖ¨¢ÿÖ¨¡ÿÖ¨¡ÿר ÿÖ¨ ÿÖ§ ÿÖ¨¡ÿÖ¨£ÿÕ§¥ÿÓ¦¨ÿÒ¦¬ÿЦ°ÿÎ¥²ÿÍ¥¶ÿÌ¥»ÿʦ¿ÿǦÄÿÄ¥ÉÿÁ¤Ïÿ½£Öÿº£Úÿ·£Ýÿ¶£ßÿµ£àÿ³£áÿ±£ãÿ¯¢åÿ¯¢åÿ®¡åÿ¬¡çÿ© çÿ§Ÿçÿ¦Ÿæÿ§žåÿ¨�ãÿ§œáÿ§›áÿ§›âÿ§›âÿ§›áÿ§šàÿ§šáÿ¥›ãÿ¤›åÿ¢›æÿ¡œçÿŸœèÿ�œêÿœ�ìÿœžîÿ›Ÿîÿ›œëÿ�šéÿ‘ŠÑÿj^�ÿ5+Aÿÿ ÿ ÿ ÿ ÿÿÿ ÿE9Uÿ…u®ÿ�ŒÎÿ£‘Öÿ¢‘Öÿ¢‘×ÿ¡‘Øÿ¡‘Øÿ¡‘×ÿ¡‘×ÿ¡‘×ÿ¡�Öÿ �ÕÿŸ�Öÿ��Øÿ›�Üÿ™�ßÿ˜�Þÿ˜�Üÿš�Ûÿ›ŽØÿœŽ×ÿœ�Öÿ›Œ×ÿ™ŒØÿ—�Úÿ–�Ýÿ”�àÿ“Žâÿ’�äÿ‘�åÿ‘�åÿ‘�çÿ��èÿ�’êÿ�’êÿ�’êÿ�‘éÿ�‘èÿ�‘éÿ�“ëÿ�“êÿ�’êÿ�‘éÿ��èÿ��èÿ��æÿ��æÿ��æÿ��æÿ��äÿ�‹áÿ�Šßÿ‘ŠÝÿ‘‰Þÿ�Šáÿ�‹ãÿ�‹âÿމàÿ�‰Þÿ�‰ßÿމßÿމßÿ�‰ßÿ�ŠÞÿ‘ŠÝÿ‘ŠÜÿ‘ŠÛÿ�ŠÜÿ‘ŠÝÿ‘ŠÝÿ�ŠÜÿ�‰Ûÿ‘ˆÛÿ‘ˆÚÿ‘ˆÙÿ‘‡Øÿ‘†×ÿ�†Öÿ�†Öÿ�…Öÿ‘†Öÿ‘…Õÿ�…Õÿ�…Õÿ�„Õÿ�ƒÕÿ�ƒÔÿ�‚Óÿ��Òÿ�€Ðÿ�€Îÿ�Îÿ�ÎÿŽÎÿ�~ÍÿŽÌÿ�~Ëÿ�|ÈÿŽ{ÆÿŽ|ÇÿŒ|ÈÿŠ}Ìÿ‰}Ïÿˆ}Ïÿˆ|Íÿ‰{Ëÿ‰zÉÿŠzÈÿ‹yÆÿŒyÄÿ�yÄÿŒxÃÿŒxÃÿŒxÃÿ‹xÄÿ‹xÃÿŠwÂÿŠwÁÿŠwÂÿˆwÂÿǯØÿǯØÿǯÙÿǯÚÿÆ®ÚÿÆ­ÛÿÇ­ÚÿÇ­ÙÿÇ­ØÿÇ­ÖÿÈ­ÔÿÇ­ÓÿÇ­ÓÿȬÔÿǬÔÿȬÕÿȬÓÿɬÐÿʬÌÿ̬Éÿ̬ÆÿͬÄÿάÂÿάÁÿÏ«¿ÿЪ¾ÿЫ¼ÿЫ»ÿѪ¹ÿÒ«·ÿÒª¶ÿÓªµÿÓª´ÿÓª³ÿÔ«²ÿÕ«±ÿÕ«±ÿÕ«°ÿÖ«®ÿ׫¬ÿ׫«ÿÖ«ªÿ׫ªÿ׫«ÿ׫«ÿÖ««ÿÖ«ªÿ׫©ÿ׫§ÿØ«¥ÿØ«¤ÿت£ÿت£ÿت£ÿت£ÿש¤ÿת¦ÿت¦ÿت¦ÿת§ÿÖª¦ÿÖ©¦ÿÖ©¦ÿÖ©¥ÿÖ¨¤ÿÖ¨¤ÿר£ÿר¢ÿר¢ÿש¡ÿר¡ÿר¢ÿר¤ÿÖ¨¦ÿÕ§¨ÿÓ¦«ÿѦ¯ÿϦ²ÿΦ¶ÿ̦»ÿʦÀÿȦÆÿÄ¥ÍÿÀ¤Òÿ½¤Øÿ¹¤Ýÿ¶¤àÿ´¤áÿ´¤áÿ²£ãÿ°¤äÿ¯£æÿ®¢æÿ­¡çÿ¬ èÿ© çÿ§Ÿçÿ§�åÿ¨�âÿ©œàÿª›Þÿ©œàÿ¨œâÿ¨œãÿ©œáÿª›ßÿ¨›áÿ¦›ãÿ¤›åÿ¢œçÿ¡œçÿŸœèÿ�œêÿœ�ìÿœžîÿ›žíÿœœëÿžšèÿ“‹Ñÿla’ÿ2)?ÿÿ ÿ +ÿ +ÿ ÿ +ÿ ÿ +ÿA6Rÿ„u¯ÿ›ŒÐÿ ‘ÙÿŸ‘Øÿ �Øÿ ‘ÙÿŸ‘Ùÿž‘Úÿž‘Úÿž‘Ùÿ�‘Úÿž�Ùÿž�Øÿœ�Ùÿ›�Üÿš�Þÿ™�Ýÿ˜�Ýÿ˜�Ýÿ™�Üÿ›�Ûÿ›ŽÚÿš�Úÿ˜�Ûÿ–ŽÞÿ”Žáÿ’Žäÿ‘Žåÿ‘�æÿ��æÿ�Žåÿ‘�çÿ‘’éÿ‘“êÿ‘”ëÿ‘“ëÿ‘’êÿ‘’éÿ‘’éÿ‘“êÿ‘’éÿ‘�èÿ‘�æÿ‘�æÿ‘�æÿ‘Žäÿ‘Žãÿ‘Žãÿ��ãÿ�Œâÿ�‹áÿ�Šßÿ‘ŠÞÿ‘Šßÿ�Šàÿ�‹áÿ�Šàÿ�ŠÞÿ�ŠÝÿ‘ŠÞÿ�Šßÿ�Šßÿ‘ŠÞÿ‘ŠÞÿ‘ŠÝÿ‘ŠÜÿ�ŠÜÿ‘ŠÝÿ‘ŠÝÿ‘ŠÝÿ‘‰Üÿ‘‰Ûÿ’‰Ûÿ’‰Úÿ‘ˆÙÿ‘ˆÙÿ‘ˆÙÿ‘‡Ùÿ‘‡Øÿ‘†×ÿ‘†×ÿ�…Öÿ�…Öÿ�…×ÿ�…×ÿŽ„×ÿŽ„×ÿŽƒÖÿ�ƒÕÿ�‚ÓÿŽ�Òÿ��ÑÿŽ€ÐÿŽ€Ïÿ�Íÿ�~ËÿŽ}Éÿ�|Çÿ�{ÅÿŽ{Åÿ�|Çÿ‹}ËÿŠ|Íÿ‰|Íÿ‰|ËÿŠ|Éÿ‹zÆÿ‹yÄÿ‹yÃÿŒyÃÿŒxÃÿ‹wÁÿ‹wÀÿ‹v¿ÿ‹v¿ÿŠu¾ÿ‰t½ÿˆt¼ÿˆs»ÿˆs»ÿǰÛÿƯÛÿƯÛÿƯÜÿůÝÿÅ®ÝÿÆ®ÛÿÆ®ÛÿÆ®ÛÿÆ®ÚÿÆ­ÙÿÆ®ØÿÆ­ØÿÆ­ØÿÆ­ØÿÆ­ØÿÆ­ØÿÆ­ÖÿÇ­ÓÿÈ­ÑÿÉ­ÎÿÊ­ÌÿˬÊÿ̬ÇÿάÃÿЫÀÿЫ¾ÿЫ½ÿЫ¼ÿЫ»ÿÑ«¹ÿÑ«¹ÿÒ«¹ÿÓ«¸ÿÓ«¶ÿÓ«µÿÔ¬³ÿÕ«±ÿÕ«¯ÿÖ«®ÿ׬­ÿ׬¬ÿ׬ªÿ׬©ÿج©ÿ׬©ÿ׬©ÿ׫©ÿ׫¨ÿØ«§ÿ׫¦ÿØ«¦ÿØ«¦ÿØ«¦ÿØ«¦ÿت§ÿת§ÿת§ÿ׫§ÿÖ«¨ÿÖª¨ÿÖª¨ÿÖ©§ÿÕ©§ÿÔ¨¦ÿÕ¨¥ÿÖ©¥ÿÖ©¥ÿÖ©¤ÿש¤ÿØ©¤ÿש¤ÿש¥ÿÖ©§ÿÕ¨¨ÿÔ¨ªÿÓ§­ÿЧ²ÿΧ¶ÿͨ»ÿʧÀÿǧÇÿĦÍÿÁ¦Óÿ½¦Øÿ¹¥Üÿ¶¥áÿ´¤âÿ³£ãÿ±£åÿ¯£æÿ®¢çÿ­¢çÿ­¢çÿ¬¡çÿ©Ÿçÿ¨žæÿ¨�ãÿªœàÿ«›Ýÿ¬›Üÿªœßÿ©œãÿ¨œãÿ©œáÿª›ßÿ©›àÿ¦›âÿ¤›äÿ£œåÿ œçÿŸ›èÿžœêÿ��ëÿœœìÿ›œëÿœšéÿŸ™åÿ•ŒÏÿqd•ÿ5+Aÿ ÿ ÿ ÿ ÿ + ÿ ÿ ÿ ÿA7Uÿ…wµÿšŒÔÿž’Üÿž’Üÿž’Üÿž‘Üÿ�’Ýÿ�’Ýÿ�’Üÿž‘Üÿ�‘Ûÿ�‘Úÿ��Úÿœ�Ûÿ›�Üÿ™�Ýÿ˜�Þÿ—�àÿ—�àÿ—�Þÿ™�Þÿ™ŽÝÿ˜�Üÿ—�Üÿ•�Þÿ“Žáÿ‘�äÿ‘Žåÿ‘Žæÿ‘�æÿ‘Žåÿ‘‘èÿ‘“éÿ‘”êÿ‘•êÿ‘•ëÿ’“êÿ’‘èÿ“�æÿ“�çÿ“�æÿ“�åÿ“Žãÿ”Žâÿ”Žâÿ”Žàÿ”�ßÿ“�àÿ’�áÿ‘�âÿ�Œãÿ�‹áÿ�Šàÿ�Šßÿ�Šßÿ�‹ßÿ�‹Þÿ‘‹Þÿ‘‹Ýÿ’ŒÞÿ’‹Ýÿ’‹Ýÿ’‹Ýÿ’‹Þÿ’‹Þÿ’ŒÞÿ‘‹Ýÿ‘‹Ýÿ‘‹Ýÿ’‹Ýÿ’‹Ýÿ’ŠÜÿ’ŠÛÿ’ŠÛÿ’ŠÛÿ‘ŠÛÿ‘‰Úÿ‘ˆÚÿ‘ˆÚÿ’‡Ùÿ‘†×ÿ�‡×ÿ�†Øÿ�†ÙÿކÙÿ�…Ùÿ�„ÙÿŽƒ×ÿ�ƒÕÿ�ƒÒÿ�‚ÐÿŽ�ÏÿŽ€ÍÿŽËÿŽ~Éÿ�}Èÿ�}Èÿ�|Æÿ�{Äÿ�zÄÿŽ{Åÿ�|Èÿ‹|Éÿ‹{Èÿ‹zÆÿ‹zÄÿ‹xÂÿŒxÀÿŒxÁÿŒyÂÿ‹wÁÿ‹w¿ÿ‹v¼ÿ‹tºÿ‹s¸ÿ‹s·ÿŠr¶ÿŠr´ÿŠq²ÿŠp±ÿưÜÿǯÛÿƯÛÿƯÜÿŰÝÿįÞÿÄ®ÝÿÅ®ÝÿÅ®ÝÿÅ®ÝÿÅ­ÜÿÄ®ÜÿÄ®ÜÿÅ®ÜÿÅ®ÛÿÅ­ÚÿÅ­ÛÿÅ­ÛÿÅ­ÚÿÅ­ÙÿÆ­ÖÿÇ­ÕÿÈ­ÒÿÊ­Îÿ̬ÉÿάÅÿάÂÿϬÁÿÏ«ÁÿÏ«ÀÿЫ¾ÿЫ½ÿÑ«½ÿÒ«½ÿÒ«ºÿÑ«¸ÿÓ¬¶ÿÔ¬²ÿÕ«¯ÿÕ«¯ÿÖ«®ÿ׬­ÿ׬«ÿ×­ªÿ×­ªÿجªÿ׬©ÿ׬©ÿج©ÿج©ÿ׬©ÿ׬©ÿج¨ÿج¨ÿ׫§ÿ׫¨ÿת¨ÿÖ«©ÿÖ«¨ÿÕª©ÿÖ©©ÿÕª©ÿÕª©ÿÕ©©ÿÔ©©ÿÔ¨¨ÿÕ¨¨ÿÕ©¨ÿÖª§ÿת¦ÿש¦ÿש¦ÿÖ©§ÿÕ©¨ÿÔ©©ÿÔ¨ªÿÒ§­ÿЧ±ÿΨ¶ÿͨ»ÿʨÁÿȧÈÿŧÍÿ§Ñÿ¿¦Öÿ»¦Üÿ·¥ßÿµ¤àÿ³£âÿ°£åÿ®£æÿ¬¢çÿ«¢çÿ«¡çÿ«¡çÿªŸæÿ©žäÿ©�âÿ«œÞÿ¬›Ûÿ¬šÚÿª›Þÿ©œâÿ¨œãÿ¨œáÿ©œàÿ©›àÿ§›áÿ¤›ãÿ¢›åÿ œçÿŸ›èÿž›éÿ�œêÿœœêÿ››êÿ�™çÿ ˜ãÿ—ŒÐÿxj�ÿ:.Fÿ ÿÿ ÿÿ ÿÿÿ ÿC9Xÿ‰|¼ÿšŽ×ÿ�‘Ýÿœ’Þÿ�’Þÿœ’Þÿ�“ßÿ�“ßÿž“Ýÿž’Ýÿž’Ûÿ�’Üÿœ‘Üÿš�Ýÿ™�Ýÿ—�ßÿ–�áÿ–‘áÿ–�áÿ–�àÿ–�àÿ—�Þÿ˜ŽÜÿ—�Ûÿ•�Üÿ”ŽÞÿ“Žáÿ“�áÿ’Žâÿ’Žãÿ’�äÿ‘�åÿ‘‘çÿ�“éÿ‘”êÿ‘•ëÿ’“èÿ•�ãÿ—Žßÿ—�Þÿ—�Þÿ˜ŽÝÿ˜ŽÝÿ—ŽÞÿ–ŽÝÿ–�Ýÿ–�Ýÿ•�Þÿ”�ßÿ’�áÿ��ãÿ�Œáÿ‘‹àÿ‘‹Þÿ‘‹Þÿ‘‹Ýÿ‘‹Þÿ‘‹Þÿ‘ŒÞÿ’ŒÝÿ“‹Ýÿ“‹Ýÿ’ŒÝÿ’ŒÞÿ“ŒÞÿ’Œßÿ’ŒÞÿ’ŒÞÿ’ŒÞÿ“ŒÞÿ’ŒÞÿ’‹Ýÿ’‹Þÿ’‹Þÿ‘‹Ýÿ‘‹Ýÿ‘ŠÝÿ‘ŠÜÿ‘‰Ûÿ’ˆÙÿ’‡Øÿ‘‡Øÿ�‡Øÿ�†ÙÿކÙÿŽ…ØÿŽ„ÖÿŽƒÕÿ�‚Óÿ��Ïÿ�€Íÿ�Ìÿ�Êÿ�~Èÿ�}Æÿ�}Æÿ�}Åÿ�{Äÿ�zÃÿ�{Âÿ�{ÃÿŽ{ÅÿŽ{ÅÿŽzÄÿ�yÂÿ�x¿ÿ�w¼ÿ�vºÿ�vºÿ�v»ÿŒu»ÿŒu»ÿŒuºÿŒs¶ÿ�r²ÿŽq­ÿ�q¬ÿŒp«ÿŒn¨ÿ‹n§ÿǰÝÿǰÜÿǰÜÿưÜÿŰÝÿůßÿįßÿįßÿůßÿįàÿÄ®àÿïàÿïàÿïßÿÄ®ÞÿÄ®ÝÿîÞÿîßÿíÞÿíÞÿíÜÿÄ­ÜÿÆ­ÙÿÇ­ÔÿÊ­ÏÿË­ÊÿÌ­ÇÿͬÆÿͬÆÿάÅÿάÃÿΫÂÿϬÁÿЬÀÿЫ½ÿЫ¼ÿѬºÿÓ¬¶ÿÔ«²ÿÕ«°ÿÕ«°ÿÖ¬¯ÿÖ­®ÿÖ­­ÿ×­¬ÿج¬ÿ׬«ÿ׬«ÿ׬¬ÿ×­¬ÿ×­¬ÿÖ¬«ÿ׬ªÿ׬ªÿ׫©ÿ׫©ÿÖªªÿÕ«ªÿÕ«ªÿÕª«ÿÕª«ÿÔª«ÿÔª«ÿÔ©«ÿÔ¨«ÿÔ¨«ÿÔ¨«ÿÔ©«ÿÕªªÿÖª¨ÿÖª¨ÿש©ÿש©ÿÖ©ªÿÕ©ªÿÔ¨«ÿÒ¨®ÿѨ±ÿϨ¶ÿͨ»ÿʨÂÿȨÈÿŧÍÿçÑÿÀ¦Õÿ½¦Ùÿº¥Üÿ·¤Þÿ´£áÿ±£äÿ®£æÿ¬¢æÿª¡çÿª¡çÿª æÿ©Ÿæÿ©žåÿª�âÿ«œßÿ«›Üÿ«›Ûÿª›Þÿ©�âÿ¨�äÿ¨�ãÿ©œâÿ©œáÿ§›áÿ¤›ãÿ¡›æÿ¡›æÿ šæÿŸšçÿž›èÿœ›éÿœšéÿ�˜æÿŸ–âÿœ‘ØÿŒ½ÿ[Muÿ0#5ÿ ÿÿÿ ÿÿ ÿ=3Oÿi^Žÿ•ˆÌÿ�‘Ùÿœ‘Üÿœ‘Þÿ›’ßÿ›“àÿœ“àÿ�“àÿž“ßÿž“Ýÿž“Üÿž’Üÿœ‘Ûÿ›�Ûÿ™�Ýÿ–�áÿ•‘ãÿ•‘âÿ•�áÿ•�áÿ•�àÿ–�ßÿ—ŽÝÿ—�Ûÿ–�Ûÿ–ŽÞÿ•�Þÿ”�Þÿ“�Þÿ“Žàÿ“�áÿ“�âÿ’�ãÿ’�åÿ’’èÿ’“èÿ•�âÿ˜�ÜÿšŒ×ÿš�Öÿ›�Öÿ›Œ×ÿ›ŒØÿš�Úÿ™�Úÿ˜�Úÿ˜�Úÿ—�Ûÿ–�Ýÿ”�ßÿ“�áÿ’ŒÞÿ“‹Üÿ“‹Ûÿ“‹Ûÿ“‹Ûÿ’‹Üÿ’ŒÝÿ“ŒÝÿ“ŒÝÿ“ŒÝÿ“ŒÝÿ“ŒÞÿ“ŒÞÿ“ŒÞÿ“ŒÞÿ’ŒÞÿ’ŒÞÿ“ŒÞÿ“�Þÿ“�Þÿ’ŒÞÿ‘Œßÿ‘Œàÿ‘‹ßÿ‘‹Þÿ‘‹Þÿ’‹Ýÿ’ŠÜÿ’‰Úÿ’ˆÙÿ‘‡Øÿ�‡Øÿ�†Øÿ�†×ÿ�„Ôÿ�ƒÒÿ�‚Ñÿ�‚Ðÿ�€Íÿ�€Ëÿ�Êÿ‘Èÿ‘}Æÿ‘|Ãÿ’|Âÿ‘|Áÿ‘{Àÿ‘z¿ÿ‘z¾ÿ’z¾ÿ‘z¾ÿ‘z¿ÿ�y¾ÿ�x½ÿ�wºÿ�v¶ÿ�u³ÿ�t°ÿ�t°ÿŽs±ÿŽs³ÿ�s³ÿ�r±ÿŽq«ÿ�p¥ÿ�o£ÿ�n¢ÿŽm ÿ�lŸÿɱÜÿȱÝÿDZÝÿDZÝÿƱÞÿŰàÿŰáÿŰáÿİáÿİâÿİãÿðãÿ¯ãÿ¯âÿïáÿîàÿ¯áÿ¯áÿ®áÿîáÿíáÿíàÿÄ­ÝÿÅ­ÙÿÇ­ÕÿÈ­ÐÿÉ­ÎÿʬÌÿˬËÿÌ­Êÿ̬Èÿ̬Èÿ̬ÇÿͬÄÿΫÁÿάÀÿЬ¿ÿѬ»ÿÓ«·ÿÔ«´ÿÕ¬³ÿÕ­²ÿÖ¬±ÿÖ¬¯ÿÖ­®ÿ׬®ÿ×­®ÿÖ­®ÿÖ­®ÿÖ­®ÿÖ­®ÿÖ¬­ÿÖ¬¬ÿ׬«ÿ׫ªÿת«ÿÖ««ÿÕ«¬ÿÕª­ÿÕª­ÿÕª­ÿÔª­ÿÔ©®ÿÓ©®ÿÔ¨®ÿÔ¨®ÿÔ©®ÿÔ©­ÿÔ©¬ÿÕª«ÿÖªªÿÖª«ÿת«ÿÖ©«ÿÕ©¬ÿÓ¨­ÿÓ¨¯ÿÒ¨²ÿШ¶ÿΨ¼ÿʨÃÿȨÉÿŨÎÿçÑÿÀ§Õÿ½¦Ùÿ»¥Ûÿ·¤Þÿ´£áÿ²£äÿ®¢åÿ¬¡æÿª¡çÿ© çÿ©Ÿæÿ©Ÿæÿ©žåÿ©žäÿª�áÿ«�àÿ«œÞÿ«œßÿª�áÿ©�ãÿ©�äÿ©�âÿªœàÿ¨œàÿ¥œãÿ£œæÿ¡šäÿ¡™äÿ ™åÿžšçÿœ›éÿœšéÿ�˜åÿž–áÿ¡–àÿ��Øÿ{l£ÿF9Xÿÿÿÿÿÿ!!ÿXLuÿ�~½ÿŸ�Öÿ ’Ùÿž‘Úÿ�‘Ýÿœ’Þÿœ’ßÿœ“àÿ�“àÿ�“ßÿž“ÞÿŸ“ÜÿŸ’Úÿž‘Ùÿ��Úÿœ�Üÿ—‘âÿ–‘äÿ–‘ãÿ•�âÿ•�áÿ•�àÿ•�àÿ•�ßÿ—ŽÝÿ—�Üÿ—ŽÝÿ–�Üÿ•ŒÛÿ•ŒÛÿ•�Ýÿ–�Ýÿ–�Ýÿ•�Þÿ•�áÿ”�äÿ•�ãÿ˜ŽÜÿ›ŒÖÿ�ŒÓÿ�ŒÑÿžŒÑÿž‹Óÿ�‹Õÿ›Œ×ÿ›�×ÿšŒ×ÿšŒ×ÿ™�Øÿ˜�Ûÿ–�Ýÿ–�Ýÿ–ŒÚÿ–ŒØÿ–ŒØÿ–‹Øÿ•‹Ùÿ•ŒÙÿ”ŒÚÿ”ŒÛÿ”ŒÜÿ“ŒÝÿ“ŒÞÿ“�Þÿ“�Þÿ“ŒÞÿ“ŒÞÿ“ŒÞÿ“ŒÞÿ”ŒÝÿ“�Ýÿ“�Þÿ’�Þÿ’Œßÿ‘Œàÿ�Œàÿ�‹ßÿ‘‹Þÿ‘‹Ýÿ’ŠÜÿ“ŠÚÿ“ˆÙÿ’ˆ×ÿ‘‡×ÿ�†Öÿ‘„Óÿ’ƒÐÿ’‚Îÿ’�Íÿ‘�Ìÿ‘€Êÿ’€Éÿ’€Èÿ’Æÿ“}Ãÿ“|Àÿ“{½ÿ“z¼ÿ“zºÿ”y¸ÿ”y·ÿ“y¶ÿ“x¶ÿ’x¶ÿ‘w¶ÿ‘w¶ÿ‘v´ÿ‘t°ÿ’s«ÿ’s¨ÿ’r¦ÿ�q¦ÿ�p¨ÿŽpªÿŽp©ÿ�o¤ÿ�n ÿ�m�ÿ�m›ÿ�lšÿŽk™ÿʲÛÿɱÝÿDzßÿDzàÿƲàÿŲáÿűâÿıâÿıãÿñãÿñäÿ°äÿÁ¯äÿÁ¯äÿ¯äÿÁ¯äÿÁ°äÿÁ°äÿ¯ãÿ®âÿ®âÿ®áÿ®ßÿíÝÿÄ­ÚÿÆ­×ÿǬÕÿȬÓÿɬÐÿÊ­ÏÿÊ­ÎÿÊ­ÍÿʬÍÿʬËÿ̬ÈÿͬÆÿάÄÿϬÁÿѬ¼ÿÓ¬¹ÿÔ¬·ÿÔ¬¶ÿÕ¬´ÿÖ¬²ÿÖ¬±ÿÖ­°ÿÖ­¯ÿÖ­¯ÿÖ­°ÿÖ­°ÿÖ¬¯ÿÖ¬®ÿÖ¬®ÿÖ«­ÿÖ¬­ÿÖ«­ÿÕ«­ÿÕ«®ÿÕª¯ÿÔª¯ÿÔª¯ÿÔª°ÿÓ©°ÿÒ¨°ÿÓ©°ÿÓ©°ÿÓ©°ÿÓ©¯ÿÔ©®ÿÕª¬ÿÕª¬ÿÖª¬ÿÖª¬ÿÕª¬ÿÔ©­ÿÓ©¯ÿÓ©±ÿÑ©´ÿÏ©¸ÿÍ©¾ÿɨÅÿǨËÿĨÏÿ§Óÿ¾¦Öÿ»¦Ûÿ¸¥Þÿ¶¥àÿ´¤âÿ±£äÿ­¢åÿ¬¢æÿª¡çÿ¨ çÿ§ çÿ¨Ÿæÿ¨žåÿ¨žäÿ©žãÿªžâÿ«�ßÿ«�ßÿ«œßÿª�àÿªžâÿ«žàÿ¬œÝÿªœÞÿ§�âÿ¤œäÿ¢šäÿ¡™äÿ ™äÿž™æÿ�šèÿ�šèÿž˜åÿž–áÿ —áÿŸ”ÝÿŒ~¿ÿSGnÿÿÿÿÿÿÿdW‚ÿž�Ðÿ¡�Ôÿ �Õÿ �Öÿ ‘ØÿŸ‘ÙÿŸ’ÛÿŸ“Ýÿž“Þÿž“Þÿž”ÞÿŸ“Üÿ ’ÛÿŸ‘Úÿž‘Úÿœ‘Ýÿ™’âÿ—‘âÿ—�áÿ—�àÿ–�áÿ•�áÿ”�àÿ•Žßÿ–�Üÿ˜ŒÚÿ—�Úÿ—ŒÚÿ—‹Øÿ—‹×ÿ˜‹×ÿ˜‹×ÿ˜ŒØÿ˜�Úÿ—ŽÝÿ˜�ßÿ™ŽÜÿœ�×ÿžŽÔÿŸ�Ñÿ ŒÏÿ ‹Îÿ ‹ÑÿžŒÔÿ�ŒÕÿ�ŒÔÿœ‹Óÿ›‹Óÿš‹Ôÿ™Œ×ÿ™�Úÿ™�ÙÿšŒ×ÿšŒÕÿšŒÕÿ™Œ×ÿ˜‹Øÿ—ŒÙÿ–ŒØÿ•ŒÙÿ”ŒÚÿ”ŒÝÿ“�Þÿ“�Þÿ“ŒÞÿ“�ßÿ”ŒÞÿ”�Ýÿ•ŒÜÿ•ŒÛÿ”ŒÜÿ”ŒÜÿ“ŒÜÿ’‹Ýÿ‘‹ßÿ�‹ßÿ�‹ßÿ‘‹Ýÿ’ŠÜÿ“‰Úÿ”‰Øÿ”ˆ×ÿ”ˆÖÿ’†Õÿ‘„Òÿ’ƒÎÿ”‚Ëÿ“€Êÿ“€Èÿ“€Çÿ“Æÿ“Åÿ“~Äÿ”}Áÿ”|¾ÿ•{»ÿ”y¸ÿ”xµÿ•x´ÿ•x²ÿ•x¯ÿ”w¯ÿ”w¯ÿ“v¯ÿ’u¯ÿ’u¯ÿ’u­ÿ’s¨ÿ’r¥ÿ’r¢ÿ“q ÿ‘oŸÿ�o¡ÿ�o£ÿ�o¢ÿ�nžÿ‘lšÿ�l˜ÿ�k–ÿ�k•ÿ�j”ÿʲÚÿɲÜÿȲßÿƲâÿŲâÿƲãÿŲãÿIJäÿòäÿÁ±åÿÁ±æÿÁ±æÿÀ±æÿ¿±çÿ¿°çÿ¿°çÿ¿°æÿÀ°åÿÁ°äÿ¯ãÿÁ®âÿÀ®ãÿÀ®âÿÁ®áÿ­ßÿîÜÿÅ­ÚÿÅ­ØÿÆ­×ÿÇ­ÕÿÈ­ÓÿȬÒÿǬÑÿȬÑÿɬÏÿÊ­Ìÿ̬ÉÿͬÅÿÏ«ÁÿЬ½ÿÒ­ºÿÓ­¸ÿÔ­¸ÿÔ­·ÿÕ­´ÿÖ­³ÿÕ¬²ÿÖ­²ÿ×­²ÿÖ­²ÿ×­°ÿÖ­¯ÿÖ¬¯ÿÖ¬°ÿÖ¬°ÿÕ«¯ÿÕ¬¯ÿÕ«¯ÿÔ«°ÿÔª±ÿÓª²ÿÓ«²ÿÓª³ÿÒ©³ÿÒ©³ÿÒª²ÿÒ©²ÿÓ©±ÿÓª°ÿÓ©¯ÿÓª­ÿÕª­ÿÕª­ÿÕª®ÿÔ©®ÿÓ©±ÿÒª³ÿѪ·ÿΪ»ÿ̪ÁÿÈ©ÉÿŨÎÿ§ÒÿÀ¦Öÿ¼¥Úÿ¸¦Þÿ¶¦áÿµ¥âÿ³¥ãÿ±¤äÿ®£æÿ¬¢çÿ©¡èÿ§¡èÿ¦ èÿ¦Ÿçÿ¦žæÿ¨žäÿªžãÿªžâÿªžàÿ«�Þÿ¬œÜÿ¬œÜÿ«�Ýÿ­œÛÿ­œÚÿ«œÜÿ¨œßÿ¦›áÿ£šâÿ¢™ãÿ ˜äÿž˜åÿž™æÿ�˜åÿ�—ãÿž—âÿŸ—ãÿž•àÿ�‚ÈÿUKvÿÿÿ ÿÿÿ#$ÿeX†ÿžŒÑÿ �Ôÿ¡�Óÿ¢�Òÿ£�Òÿ¢�Óÿ¡’Ôÿ¡’Õÿ¡’ÙÿŸ“ÝÿŸ”ÞÿŸ“ÝÿŸ“Üÿž’Üÿ�’Ýÿœ’àÿ™‘áÿ˜�ßÿ˜�Ýÿ˜�Ýÿ—�ßÿ•�àÿ•ŽÞÿ•ŒÛÿ–‹Øÿ—‹Öÿ–ŒÙÿ–‹Úÿ˜‹×ÿ™‹Ôÿš‹Òÿ›‹ÓÿšŒÕÿš�Øÿš�Ùÿœ�Øÿ��ÖÿŸŽÓÿ ŽÒÿ¡ŽÏÿ¡�Ìÿ¡ŒÍÿ ŒÐÿŸ�ÒÿžŒÒÿ�‹Òÿž‹ÑÿžŠÑÿ�‹ÓÿœŒÖÿœ�Öÿ›ŒÖÿ›ŒÔÿœŒÓÿœŒÔÿš�Õÿ˜ŒÖÿ™�×ÿ˜�×ÿ–�Øÿ•ŒÚÿ”ŒÜÿ“�Ýÿ“�Þÿ“�ßÿ“Žßÿ•�Ýÿ–ŒÚÿ—‹Øÿ—‹Øÿ—‹Øÿ–ŠØÿ”ŠØÿ“‹Úÿ’‹Üÿ�‹Üÿ�ŠÜÿ‘ŠÛÿ“ŠÙÿ“ˆØÿ“‡Öÿ”‡Õÿ“‡Óÿ“…Ñÿ“„Îÿ“‚Ëÿ”€Çÿ•Åÿ•Äÿ•~Âÿ•}¿ÿ•|½ÿ•|¼ÿ•{¹ÿ•y¶ÿ”yµÿ•w³ÿ”v¯ÿ“u¬ÿ”u«ÿ•uªÿ•uªÿ”u©ÿ“t¨ÿ“s§ÿ“s¦ÿ“r¤ÿ”q ÿ”qžÿ“p�ÿ’oœÿ’oœÿ�nžÿ�nŸÿ�nžÿ‘nšÿ�l—ÿ�k”ÿ�j’ÿ�i‘ÿ�i‘ÿ˳ÛÿʳÜÿȲÞÿDzàÿdzáÿDzâÿƲâÿŲãÿIJäÿ²åÿÁ²æÿÀ²çÿ¿²éÿ¾²êÿ¾²ëÿ¾±êÿ¾±éÿ¿°èÿÀ°æÿÁ°äÿÀ¯äÿÀ¯åÿ¿¯åÿÀ®äÿÀ®ãÿÁ®áÿîÞÿíÝÿíÜÿÅ®ÚÿÅ­ØÿÆ­×ÿƬÖÿƬÖÿÇ­ÔÿȬÐÿÊ­ÌÿˬÉÿ̬ÆÿάÂÿѬ¾ÿÒ­¼ÿÒ­»ÿÓ­ºÿÔ®¹ÿÕ­·ÿÕ­¶ÿÖ­µÿÖ­´ÿÖ­³ÿÖ¬²ÿÖ­²ÿÖ­²ÿÖ¬²ÿÖ­³ÿÕ¬²ÿÕ¬²ÿÕ¬²ÿÔ«²ÿÔ«²ÿÔ«³ÿÓ«³ÿÓ«´ÿÒªµÿѪµÿѪµÿÒ©´ÿÒ©³ÿÓª²ÿÔª°ÿÔª¯ÿÕª¯ÿÕª¯ÿÔª°ÿÔª°ÿÓª²ÿÒª´ÿЪ¹ÿΫ¾ÿʪÄÿǪÌÿÄ©ÑÿÁ¨Õÿ¾¦Ùÿ»¦Üÿ¸¥ßÿ¶¦áÿ´¦ãÿ³¥ãÿ±¤äÿ¯¤æÿ¬£çÿª¢èÿ¨¡èÿ¦¡éÿ¦ èÿ¥žçÿ§žæÿ¨žåÿ©žãÿ«žáÿ¬�Þÿ­œÛÿ­œÚÿ­œÚÿ®œÙÿ®œÙÿ¬œÚÿª›Üÿ§šÞÿ¤™ßÿ¡˜áÿŸ˜âÿž˜ãÿž˜äÿ�—âÿ�–áÿž–áÿž—áÿž•áÿ–‹Õÿ]S€ÿÿÿÿ ÿ ÿ4)@ÿna”ÿ�ŽÕÿž�Øÿ �Ôÿ¢�Óÿ£�Óÿ¢‘Óÿ¢‘Óÿ¡‘Õÿ ’ÙÿŸ“Ýÿž”ßÿž“ßÿž“ßÿ�“Þÿ›’ßÿ›’àÿš‘ßÿ™�Ýÿ™�Úÿ™ŽÚÿ˜�Üÿ—ŽÝÿ–�Üÿ—ŒÙÿ—‹×ÿ—‹Öÿ•ŒÚÿ•ŒÚÿ—‹Öÿš‹Òÿœ‹Ñÿ›ŒÓÿ›ŒÕÿœ�Öÿ��ÖÿžŽÕÿ ŽÓÿ¡ŽÒÿ¢ŽÐÿ¢�Íÿ¢�Ìÿ¡�Íÿ ŒÐÿ ŒÑÿŸŒÒÿžŒÒÿž‹ÐÿŸ‹ÐÿžŒÒÿ�ŒÔÿ�ŒÔÿœŒÔÿœŒÔÿœŒÔÿœŒÕÿ›ŒÕÿ›�Õÿ›ŒÕÿšŒÕÿ™ŒÖÿ—ŒÙÿ–ŒÚÿ•ŒÛÿ•�Üÿ•�Üÿ•�Üÿ—ŒÙÿ˜‹×ÿ˜ŠÕÿ˜ŠÔÿ˜ŠÓÿ™‰Óÿ—‰Ôÿ–ŠÖÿ•Š×ÿ”ŠØÿ”‰Øÿ”‰×ÿ•ˆÖÿ•‡Õÿ•‡Ôÿ•‡Ôÿ”†Òÿ“…Ïÿ“ƒÌÿ”‚Èÿ•€Äÿ•Âÿ–~Àÿ—}¾ÿ–{ºÿ–{·ÿ—z´ÿ—y±ÿ–x®ÿ•w®ÿ–v­ÿ•u©ÿ•t¦ÿ•t¥ÿ•t¦ÿ”t¦ÿ“t¥ÿ“s¤ÿ“s¡ÿ”ržÿ”q›ÿ”q™ÿ•p˜ÿ•p˜ÿ“o™ÿ“ošÿ’o�ÿ‘nžÿ‘nœÿ‘m™ÿ‘l•ÿ‘k’ÿ‘j�ÿ�i�ÿ�i�ÿÌ´Üÿ˳ÜÿʳÜÿɳÝÿɳÞÿȳàÿDzàÿƲáÿŲâÿòäÿ²åÿÁ²èÿ¿³êÿ¾³ëÿ¾³ìÿ¾³ìÿ½²ëÿ½²êÿ¾±éÿ¿±èÿ¿°çÿ¿°çÿ¾¯çÿ¾¯æÿ¿®åÿÀ®ãÿÀ®âÿÁ®áÿÁ®àÿîÞÿîÜÿÄ­ÛÿÄ­ÚÿÄ­ÚÿÅ­ØÿÆ­ÕÿÈ­ÑÿÉ­ÍÿʬÊÿ̬ÇÿϬÄÿЭÀÿÑ­¾ÿÒ­¾ÿÓ®½ÿÓ®»ÿÔ®ºÿÕ­¹ÿÕ­·ÿÕ­·ÿÕ­·ÿÕ­¶ÿÕ­¶ÿÖ­¶ÿÕ­µÿÕ¬µÿÕ¬µÿÕ¬´ÿÕ¬´ÿÕ«³ÿÔ«³ÿÔ«³ÿÓ«´ÿÒ«¶ÿѪ·ÿѪ·ÿѪ¶ÿÒªµÿÓ«´ÿÔª²ÿÔ«²ÿÕ«°ÿÔ«°ÿÕª±ÿÔª³ÿÓª´ÿѪ¶ÿЪºÿÍ«ÀÿʪÇÿǪÎÿéÓÿÀ¨×ÿ¾§Úÿ»¦Üÿ¹¦Þÿ¶¥àÿ´¥âÿ³¥ãÿ²¤ãÿ°¤åÿ­£çÿ«¢çÿª¡çÿ¨ çÿ¦ èÿ¥Ÿéÿ¥Ÿéÿ¦Ÿçÿ§Ÿæÿªžãÿ«�ßÿ¬œÝÿ­œÛÿ­œÚÿ­œÚÿ­œÙÿ¬œÚÿª›Ûÿ§™Üÿ¤˜Ýÿ¡—Þÿ —àÿŸ—áÿŸ—áÿŸ–ßÿŸ•ÞÿŸ•ÝÿŸ•Ýÿ •ßÿŸ“ÝÿcY‡ÿÿÿÿ ÿ ÿ?4QÿuiŸÿ�‘Úÿž’ÛÿŸ‘×ÿ¡�Õÿ¢‘Ôÿ¢‘Ôÿ¢’Ôÿ ’ÖÿŸ“ÙÿŸ”Üÿž“ßÿ�”àÿ�”áÿœ“àÿœ’ßÿ›’Þÿš‘Þÿ™�Üÿ™ŽÚÿ˜ŽÙÿ˜�Ùÿ˜�Úÿ˜�Úÿ˜ŒÙÿ˜‹×ÿ—‹×ÿ•ŒÚÿ•ŒÙÿ—ŒÕÿ›‹Òÿ�ŒÑÿœŒÔÿ��Õÿ�ŽÖÿŸŽÔÿ¡�Òÿ¢�Ñÿ£ŽÐÿ¤ŽÍÿ¤ŽÌÿ¤ŽÎÿ¢ŽÐÿ¡�Ðÿ ŒÐÿŸ�ÑÿŸŒÒÿžŒÑÿžŒÑÿ�ŒÓÿœŒÔÿœŒÔÿœŒÔÿœŒÔÿ›ŒÕÿœŒÕÿ›ŒÕÿ›�Õÿ›ŒÔÿšŒÔÿšŒÕÿ™Œ×ÿ™ŒØÿ˜ŒØÿ˜ŒØÿ˜Œ×ÿ˜ŒÖÿš‹ÓÿšŠÑÿ›‰Ïÿœ‰Íÿ�ˆËÿžˆÉÿ�ˆÊÿœ‰Ìÿ›‰ÎÿšˆÏÿšˆÏÿ™ˆÏÿ˜‡Ïÿ˜†Ïÿ—†Îÿ—†Îÿ–…Íÿ•„Ëÿ•‚Éÿ–�Æÿ–€Ãÿ–~Àÿ—~½ÿ˜}ºÿ˜{¶ÿ˜z²ÿ˜x¯ÿ˜x¬ÿ—wªÿ–vªÿ–v¨ÿ–u¥ÿ–t£ÿ–s¡ÿ•s¡ÿ”s¢ÿ“r¢ÿ“r ÿ“r�ÿ“qšÿ”p˜ÿ•p–ÿ–o•ÿ–o•ÿ•o–ÿ”o˜ÿ“o›ÿ“o�ÿ’oœÿ’m˜ÿ’m”ÿ’k‘ÿ’j�ÿ‘j�ÿ�j�ÿÊ´Þÿ˳ÜÿË´ÛÿË´ÛÿʳÜÿɳÞÿȳßÿDzßÿƲáÿIJãÿóåÿ³çÿÁ³éÿ¿´ëÿ¾³ìÿ½³íÿ¼³íÿ»³íÿ»²íÿ»²íÿ¼±ìÿ¼±êÿ½°êÿ¼¯éÿ½¯çÿ¾®åÿ¾¯åÿ¿¯äÿ¿¯ãÿÀ®âÿÁ®áÿ®ßÿ­ÝÿíÝÿíÜÿíÚÿÅ­×ÿÆ­ÓÿÇ­ÐÿɬÎÿË­ÊÿέÆÿЮÃÿÒ®ÁÿÒ®ÀÿÓ¯¾ÿÒ®½ÿÓ®¼ÿÔ®»ÿÔ­»ÿÓ­»ÿÓ­ºÿÔ­¹ÿÔ­¹ÿÔ­¸ÿÔ¬¶ÿÕ­¶ÿÕ­¶ÿÕ­µÿÔ¬´ÿÔ«³ÿÔ«³ÿÓ«µÿÑ«·ÿЫ¸ÿЪ¹ÿѪ¸ÿÑ«·ÿÒ«¶ÿÓ«µÿÔ«´ÿÔ¬²ÿÕ¬²ÿÕ«³ÿÔ¬µÿÓ«·ÿÑ«¹ÿÏ«½ÿÌ«ÂÿÊ«ÈÿǪÏÿêÔÿÀ©Øÿ¾¨Ûÿ»§Üÿ¹¦Ýÿ·¥ßÿµ¥áÿ´¥áÿ³¤âÿ±¤äÿ¯£æÿ­¢åÿ¬¡åÿ© åÿ§ çÿ¤ éÿ¤ êÿ¤ éÿ¥ èÿ¨ åÿªžáÿ«�Þÿ«�Ýÿ«œÝÿ«›Üÿ¬œÛÿ«œÛÿªšÜÿ§™Üÿ¤—Ýÿ¢—Ýÿ —Þÿ –ßÿŸ–Þÿ •Ýÿ •Ûÿ ”Ûÿ ”Úÿ¡•Üÿ£—ßÿe[ˆÿÿ%$ÿ!ÿÿÿA6Tÿvl¢ÿž”Ýÿž”Ýÿž’Úÿ ‘×ÿ¡‘Õÿ¡’Õÿ¡’Õÿ ’Öÿ “ÙÿŸ”Üÿž“Þÿœ”àÿœ”áÿœ“àÿ›’Þÿ›‘Ýÿš‘Ýÿ˜�Üÿ—�Ûÿ˜ŽÚÿ˜�Øÿ™�×ÿ™�Øÿ˜ŒØÿ˜‹×ÿ—‹×ÿ•ŒÙÿ–Œ×ÿ˜‹Ôÿ›‹Òÿ�ŒÓÿž�ÕÿžŽÕÿŸ�Ôÿ¡�Òÿ¢�Ðÿ£�Ïÿ¤�Îÿ¥�Íÿ¥�Íÿ¥�Ðÿ£�Ñÿ¢ŽÑÿ �ÑÿŸ�Ñÿž�ÒÿžŒÒÿ�ŒÓÿ›ŒÔÿ›ŒÕÿ›ŒÕÿœŒÕÿ›ŒÔÿ›ŒÔÿ›ŒÔÿš�Õÿ™ŒÕÿ™ŒÕÿšŒÕÿšŒÕÿš�Õÿ›ŒÕÿ›ŒÔÿ›ŒÓÿ›ŒÒÿœ‹Ïÿ�ŠÌÿž‰ÉÿŸˆÇÿ¡‡Äÿ¢‡Àÿ£‡½ÿ¤‡¼ÿ£‡½ÿ¢‡¿ÿ¡†Âÿ †ÄÿŸ†Ãÿ�…Ãÿœ…Äÿ›„ÃÿšƒÃÿ™ƒÄÿ˜‚Äÿ˜�Ãÿ˜€Áÿ™€Àÿ˜½ÿ™~ºÿš}·ÿš{³ÿ™y¯ÿ˜w¬ÿ—wªÿ—w©ÿ•v¨ÿ•u§ÿ•t¤ÿ•s¡ÿ•r ÿ”rŸÿ“r ÿ’qŸÿ“q�ÿ“p›ÿ“p™ÿ“p˜ÿ”o—ÿ•o–ÿ•o•ÿ•o–ÿ”n—ÿ”ošÿ“pœÿ“p›ÿ’n˜ÿ“m•ÿ“l’ÿ’k‘ÿ‘k’ÿ�k“ÿdzáÿȳßÿʳÝÿÌ´ÜÿË´ÜÿË´ÝÿɳÞÿȳßÿDzàÿųâÿijåÿóæÿ³çÿÀ³éÿ¿´ìÿ½³íÿ»³ïÿ¹³ðÿ¹³ñÿ¸³óÿ¸²ñÿ¹²ïÿº±îÿº±íÿ»¯êÿ¼¯çÿ½¯çÿ½¯æÿ½¯åÿ¾¯äÿ¿¯äÿÀ®âÿÁ®àÿÁ®àÿÁ®àÿ­ßÿíÜÿìÙÿĬ×ÿÆ­ÕÿÈ­ÐÿË­ÌÿέÈÿÏ®ÅÿѯÃÿÑ®ÂÿѯÁÿѯÀÿÒ¯¿ÿÒ®¾ÿÒ®¾ÿÑ­½ÿÒ­¼ÿÒ­»ÿÓ®ºÿÒ­¸ÿÓ¬·ÿÓ­·ÿÓ­¶ÿÓ¬µÿÓ¬µÿÓ«µÿÒ«¶ÿÑ«¸ÿЬ¹ÿÏ«ºÿЫºÿÑ«ºÿѬ¸ÿÒ¬·ÿÓ¬¶ÿÔ¬µÿÕ¬´ÿÕ¬´ÿÔ­¶ÿÓ¬¹ÿѬ¼ÿάÀÿË«ÅÿÉ«ÊÿƪÐÿªÕÿÀ©Ùÿ¾¨Ûÿ¼§Üÿ¹¦Ýÿ·¥Þÿ¶¥àÿ´¤àÿ³¥áÿ±¤ãÿ°£äÿ®¢äÿ¬¡äÿ« åÿ¨ æÿ¤Ÿèÿ£ éÿ¤ éÿ¥¡éÿ§¡çÿ©Ÿãÿªžàÿªžßÿª�ßÿª›Üÿ«œÜÿ«›Üÿ©šÜÿ¦™Ýÿ£˜Þÿ¢—Þÿ —Þÿ —Þÿ –Ýÿ –Üÿ •Üÿ¡–Üÿ¡–Üÿ¢–Üÿ¡–Ûÿd[†ÿ ÿ')ÿ$ ÿÿ""ÿ>4Pÿsj ÿž•àÿ�•ßÿ�“ÜÿŸ“ÛÿŸ’ÙÿŸ’×ÿŸ’×ÿ ’Øÿ “ÚÿŸ“Ûÿž”Ýÿœ”àÿœ“áÿ›“ßÿ›‘Ýÿ›�Ûÿš�Ûÿ˜�Üÿ—�Ýÿ˜�Ýÿ™ŽÚÿ™�Öÿš�Öÿš�Öÿ™�×ÿ˜ŒÖÿ˜�×ÿ™ŒÖÿšŒÔÿœŒÓÿ��ÔÿŸŽÖÿŸ�Õÿ¡�Óÿ¢�Ñÿ£�Ïÿ¤�Îÿ£�Ðÿ£�Ðÿ¤�Ðÿ¥�Ðÿ£�Ñÿ¢�Òÿ¡ŽÒÿŸ�Òÿ��Óÿ��Óÿœ�Ôÿ›�ÕÿšŒÕÿ›�Öÿ›ŒÖÿšŒÕÿšŒÔÿšŒÔÿ™ŒÔÿ˜‹Öÿ˜ŒÖÿ™ŒÕÿ›‹ÓÿœŒÒÿ�ŒÑÿ�ŒÐÿ�ŒÏÿž‹ÌÿŸŠÉÿ ‰Æÿ¡ˆÃÿ¢‡Àÿ¤‡¼ÿ¥†¸ÿ¦†´ÿ§†²ÿ§†±ÿ¦†²ÿ¥…¶ÿ¤…¸ÿ¤„·ÿ¡ƒ¶ÿ ‚·ÿŸ�·ÿž€·ÿ��¸ÿœ€ºÿ›ºÿ›¹ÿ›¸ÿ›~¶ÿ›}´ÿ›{²ÿ™z°ÿ˜w¬ÿ—wªÿ–v¨ÿ•v§ÿ”u§ÿ•u§ÿ•t¥ÿ“s£ÿ’r¡ÿ’q ÿ‘pŸÿ‘pžÿ’pœÿ“pšÿ“p™ÿ“p˜ÿ“o˜ÿ“o—ÿ“o—ÿ’n—ÿ“o˜ÿ”o™ÿ”o™ÿ“o˜ÿ“o–ÿ”n”ÿ“m“ÿ’m“ÿ‘l”ÿ�l•ÿÅ´åÿÆ´äÿÇ´âÿȳàÿÊ´ÞÿÊ´ÞÿɳÞÿȳßÿÈ´àÿƳâÿÄ´åÿôæÿôçÿÁ´èÿÀ³êÿ½´íÿ»´ðÿ¹´óÿ·´ôÿµ´õÿµ´õÿµ³ôÿ¶²òÿ·²ñÿ¸±îÿº°ìÿ»°êÿ»¯éÿ»¯èÿ»¯èÿ¼¯çÿ½®åÿ¾®äÿ¿®ãÿ¿®ãÿÀ¯âÿÁ®àÿ¬ÝÿìÜÿíÛÿÄ­ØÿÇ­ÓÿÊ­ÍÿÌ®ÉÿήÇÿήÆÿϯÇÿϯÆÿЯÄÿЮÃÿЮÂÿÑ®ÁÿÑ­ÀÿÑ­¿ÿÒ®½ÿÒ­¼ÿÒ­ºÿÓ­¹ÿÓ­¸ÿÒ­¸ÿÒ¬¸ÿÒ¬¸ÿÒ¬¸ÿѬºÿЬ¼ÿϬ½ÿЬ¾ÿЬ¾ÿÑ­½ÿÑ­»ÿÓ¬ºÿÔ­¸ÿÕ®·ÿÕ­·ÿÔ­¸ÿÒ®ºÿÑ­¼ÿÏ­ÀÿͬÆÿÉ«ÌÿÆ«ÑÿêÕÿÁ©Ùÿ¿©Üÿ¼¨Þÿ¹§ßÿ¸¦ßÿ¶¥àÿµ¥áÿ´¥âÿ²¥ãÿ°¤ãÿ®¢äÿ­¢åÿ«¢æÿ©¢èÿ¦¡éÿ¤ êÿ£ êÿ¤ éÿ§Ÿçÿ¨žåÿªžãÿ«žáÿªžßÿ«œÝÿ«›Ûÿ«›Ûÿ©šÝÿ¥™Þÿ£™ßÿ¢˜ßÿ¡—ßÿ —ßÿ —ßÿ¡—Þÿ¡—Ýÿ¡—Ýÿ¢—Ýÿ¢—ÝÿŸ“ØÿcY„ÿ +ÿ ÿÿÿ&,ÿC8Vÿul£ÿ�–âÿœ•âÿ›”àÿ›”àÿœ”àÿœ”ßÿ�”ÝÿŸ“ÝÿŸ”Ýÿž”Ýÿ�“Ýÿ�“ßÿœ“ßÿ›’Þÿ›‘Üÿœ�Úÿ›�Úÿš�Ûÿ™�Þÿ˜�ßÿš�Ûÿ›�Öÿœ�Õÿ›�Öÿ›�Öÿ›ŒÕÿ›�Õÿ›�Õÿœ�ÕÿžŽÕÿŸ�ÖÿŸ�Õÿ �Õÿ¡�Óÿ£�Ðÿ¥�Îÿ¥�Ïÿ¤‘Ñÿ£�Òÿ£�Ñÿ¤�Ðÿ¤�Ñÿ£�Òÿ¡�Óÿ ŽÓÿŸŽÓÿžŽÕÿ�ŽÕÿ›�Õÿš�Õÿš�×ÿš�×ÿ™ŒÖÿšŒÖÿšŒÕÿš‹Õÿ™ŒÕÿ™ŒÕÿšŒÔÿœŒÑÿŸ‹Îÿ ‹Ìÿ ŠÊÿ ‰Èÿ¡ˆÄÿ£‡Áÿ£‡¿ÿ¤‡¿ÿ¥‡»ÿ¦‡¶ÿ§†±ÿ¨…®ÿ©…¬ÿ¨…¬ÿ§„­ÿ§„¯ÿ§ƒ°ÿ§‚®ÿ¥‚¬ÿ¤�«ÿ¤€«ÿ¢«ÿ¡­ÿŸ°ÿž~°ÿž}¯ÿž|¬ÿ�{¬ÿœz«ÿœy«ÿ›y«ÿšw©ÿ™v¦ÿ˜v¥ÿ–u¤ÿ•u¤ÿ”t¥ÿ”s¥ÿ“s¥ÿ“r¤ÿ’q¢ÿ�p¡ÿ‘pŸÿ’p�ÿ’o›ÿ“ošÿ“p™ÿ“p™ÿ“p™ÿ“pšÿ“ošÿ“ošÿ“o™ÿ“o—ÿ”n•ÿ”n•ÿ”n”ÿ“n•ÿ’m–ÿ‘m•ÿ�l•ÿĵçÿÄ´æÿÄ´åÿÆ´äÿǵâÿÈ´áÿÈ´àÿÈ´àÿÈ´àÿÈ´âÿÇ´äÿÅ´åÿÄ´åÿôçÿÁ´éÿ¿´ìÿ¼´ðÿ¹µòÿ·´ôÿµµöÿ´µ÷ÿ´µ÷ÿ´´öÿ¶´ôÿ¶³òÿ·²ðÿ¸°îÿ¹°íÿ¹°ìÿ¹°ëÿ¹¯êÿº¯èÿ¼¯çÿ¾®åÿ¾®äÿ¾®äÿÀ®âÿÁ­ßÿÁ­Þÿ¬ÝÿíÜÿÄ­ØÿÇ­ÕÿÊ®ÑÿË®ÌÿÌ®ÉÿÍ®ÉÿÍ®ÉÿήÈÿίÇÿϯÆÿЮÄÿЮÃÿЮÂÿÑ®ÁÿÑ­ÀÿÑ­½ÿÒ­¼ÿÒ­»ÿÒ­»ÿÑ­»ÿÑ­¼ÿÑ­½ÿЭ¾ÿÏ­¿ÿέÁÿέÂÿÏ­ÂÿЮÁÿÑ­ÀÿÒ­¾ÿÓ®ºÿÓ®¹ÿÔ­¹ÿÓ­¹ÿÒ­»ÿÑ­½ÿЭÀÿͬÅÿÊ«ËÿƬÐÿÄ«ÔÿÁªÙÿ¿©Üÿ¼¨Þÿ¹¨àÿ¸§áÿ¶¦àÿµ¦áÿ´¦ãÿ²¥äÿ°¥äÿ¯¤äÿ­£æÿ¬£èÿ©£éÿ¦£ëÿ¤¢ëÿ¤¡ëÿ¤ éÿ¥Ÿèÿ¦Ÿæÿ¨Ÿäÿªžâÿ«�ßÿ¬œÞÿ«œÝÿª›Ýÿ¨›Þÿ¥šßÿ¤™àÿ¢˜àÿ ˜àÿ ˜àÿ ˜àÿ¡˜ßÿ¢˜Þÿ¢—Ýÿ¢—Ýÿ¢–Ýÿ��Ôÿ`Vÿÿ#"ÿÿÿ""ÿ7+Cÿmg�ÿœ˜æÿ›—åÿ™–äÿ˜•äÿ˜•äÿš”ãÿ�”àÿž”ßÿ�”àÿœ•áÿœ”àÿ›“àÿš’àÿš’ßÿš‘Ýÿ›‘Ûÿš‘Ûÿš‘Üÿ™�Þÿ˜�ßÿš�ÛÿœŽÖÿ�ŽÕÿ�ŽÖÿ�ŽÖÿœ�ÖÿœŽÖÿœŽÖÿ�ŽÖÿŸ�Öÿ �ÖÿŸ�Öÿ �Õÿ¢�Ôÿ¤�Ñÿ¥�Îÿ¦‘Ïÿ¤‘Ñÿ£‘Òÿ¤�Óÿ¤�Òÿ£�Òÿ¢�Òÿ¡�Óÿ¡�Óÿ �ÔÿŸŽÕÿžŽÕÿ��Ôÿœ�Ôÿ›ŒÔÿ›‹Óÿ›‹Óÿ›‹Óÿœ‹Òÿœ‹Òÿœ‹Ñÿœ‹Ðÿ�‹ÏÿŸ‹Ìÿ¡ŠÊÿ¡ŠÇÿ¢‰Åÿ£ˆÃÿ¤‡Àÿ¤‡½ÿ¤†¼ÿ¤†ºÿ¥†·ÿ¦…²ÿ§…®ÿ§„«ÿ©„©ÿ©ƒ¨ÿ©ƒ¨ÿ©‚¨ÿ©‚§ÿ¨�¥ÿ§€¤ÿ¦£ÿ¦~¢ÿ¤}¢ÿ¢}¤ÿ¡|§ÿ |¨ÿ {§ÿŸz¥ÿžy¥ÿ�x¥ÿœx¦ÿœx¥ÿ›w£ÿ›v¢ÿ™v¢ÿ˜u¢ÿ–t¢ÿ•t¢ÿ”s£ÿ”s£ÿ“r£ÿ’r¡ÿ‘q¡ÿ‘q¡ÿ‘qŸÿ“p�ÿ”pœÿ”p›ÿ”q›ÿ“pœÿ“pœÿ“pœÿ“p›ÿ’o™ÿ“n—ÿ”o–ÿ•o–ÿ”o–ÿ“n—ÿ‘m–ÿ�l–ÿ�l–ÿĶçÿõçÿõèÿĵçÿŵåÿÆ´äÿÇ´ãÿǵâÿȵâÿȵãÿȵäÿÆ´äÿÅ´åÿÄ´çÿ´èÿÀ´ëÿ½µïÿºµòÿ¸µôÿ¶µöÿµµ÷ÿ´µ÷ÿ´µ÷ÿµµõÿ¶³óÿ¶³òÿ¶±òÿµ±ñÿ¶±ðÿ¶°ïÿ¶°îÿ·°íÿ¹¯êÿ»¯çÿ¼®åÿ½®äÿ¾®ãÿÀ®áÿÁ­ßÿ¬Þÿ­ÝÿíÜÿÄ­ÚÿÆ®ØÿÈ®ÔÿÉ®ÐÿÊ®ÍÿÌ®ÌÿͯËÿͯËÿίÉÿϯÈÿÏ®ÆÿÏ®ÅÿЮÅÿЮÃÿÑ®ÁÿÒ®¿ÿÑ­¾ÿÑ­¾ÿÑ­¿ÿÑ­ÀÿЭÁÿÏ­ÂÿÍ­ÃÿÍ­ÅÿÌ­ÅÿέÅÿÏ®ÄÿЮÂÿÒ®ÀÿÒ®½ÿÒ®¼ÿÓ­»ÿÒ­»ÿÒ­¾ÿÑ­¿ÿϬÂÿ̬ÅÿʬÊÿƬÐÿÄ«ÕÿÁ«Úÿ¿ªÝÿ¼¨Þÿ¹¨àÿ·¨áÿ¶§áÿµ¦áÿµ¦ãÿ³¦ãÿ±¥äÿ¯¥åÿ­¥çÿ«¤éÿ¨¤ëÿ¥£ìÿ££ìÿ£¢ìÿ£ êÿ£Ÿéÿ¤Ÿçÿ¦Ÿæÿ¨žäÿ©�àÿªœàÿ©œßÿ¨œàÿ§œáÿ¥›âÿ¤šâÿ¢™âÿ¡™âÿ ™áÿ¡™áÿ¢™ßÿ¤™Ýÿ¤™Üÿ¤˜Ýÿ£—Üÿ˜ŒÌÿ]S{ÿ ÿ#!ÿ!ÿÿ ÿ+1ÿhd™ÿ›šêÿ™™éÿ˜™èÿ—™éÿ—˜èÿ——æÿš•ãÿ›”âÿ›•äÿ™–åÿ™•äÿ˜”ãÿ˜“âÿ˜“âÿ™“àÿš’ßÿš’ßÿ™’ßÿ˜‘ßÿ™�Þÿ›�Ûÿœ�×ÿ��×ÿž�×ÿ��×ÿœ�×ÿœ�×ÿœŽ×ÿ�ŽÖÿžŽÖÿŸ�ÖÿŸ�×ÿŸ�Öÿ �Õÿ¢�Óÿ¤�Ðÿ¤�Ðÿ¤‘Ñÿ¤‘Òÿ£‘Óÿ£�Óÿ¢�Óÿ¡�Óÿ¡�Óÿ¡�Óÿ �Ôÿ �ÖÿžŽÕÿž�Óÿ��Òÿ�ŒÑÿ�‹Ïÿ�‹Îÿ�‹Îÿž‹Îÿž‹Íÿž‹ÌÿŸŠÊÿ ŠÈÿ¡‰Æÿ¢‰Åÿ¢‰Ãÿ¢ˆÀÿ£‡¾ÿ£†¼ÿ¤…ºÿ£…¹ÿ£…·ÿ¤„´ÿ¥ƒ±ÿ¦ƒ®ÿ¦‚«ÿ§‚¨ÿ¨�¦ÿ¨€¤ÿ¨€¢ÿ¨€ ÿ¨Ÿÿ§Ÿÿ¦~žÿ¥|�ÿ¥|�ÿ£{žÿ¢{ ÿ¡z¡ÿ¡z¡ÿ y ÿ x¡ÿŸx¡ÿžx¢ÿ�x ÿ�xŸÿœwŸÿ›vŸÿ˜uŸÿ—tŸÿ–t ÿ•s ÿ”s¡ÿ“r¡ÿ’r¡ÿ‘r¡ÿ‘q¢ÿ‘q¡ÿ’qŸÿ“p�ÿ”pœÿ”pœÿ“p�ÿ“pœÿ“pœÿ“p›ÿ“o™ÿ“o˜ÿ“o—ÿ“o˜ÿ“o˜ÿ‘n˜ÿ�m—ÿŽl—ÿŽl—ÿĶçÿöèÿöéÿöèÿĵæÿŵåÿÆ´åÿƵäÿƶåÿǶåÿǶåÿƶåÿƵæÿŵçÿõéÿÀµëÿ½¶ïÿº¶òÿ¸¶ôÿ·¶õÿµµöÿµµ÷ÿ´µ÷ÿ´µöÿµ´ôÿ¶³ôÿµ³ôÿ´²ôÿ´²óÿ´±óÿ´±òÿ´±ñÿ¶°ïÿ¸¯ìÿº¯éÿ»¯æÿ½¯åÿ¿®âÿÀ­ßÿÁ­Ýÿ­ÝÿíÝÿîÝÿîÜÿÅ®ÚÿÇ®×ÿÈ®ÓÿʯÐÿ̯Ïÿ̯Ïÿ̯ÍÿͯËÿίÉÿϯÈÿϯÇÿЯÅÿѯÃÿѯÂÿÑ®ÁÿÑ®ÂÿÑ®ÂÿЭÃÿÏ­ÄÿέÅÿÌ­ÇÿË­ÈÿÌ­ÇÿÍ®ÆÿϯÅÿЯÃÿÑ®ÁÿÒ®ÀÿÒ®¿ÿÒ®¾ÿÑ®¿ÿЮÁÿÏ­ÃÿͬÅÿˬÇÿɬËÿƬÐÿëÖÿÀ«Ûÿ¾ªÞÿ¼©ßÿ¹¨àÿ·¨áÿ·¨áÿ¶§áÿµ¦âÿ´¦ãÿ²¦äÿ°¥åÿ­¥çÿª¥éÿ¨¤ìÿ¤¤ìÿ¢£ìÿ¡¢ìÿ¢¡ëÿ¢ êÿ£ éÿ¤ èÿ¥Ÿæÿ¦�ãÿ§�âÿ§�âÿ§�ãÿ¦�ãÿ¤œãÿ¤›âÿ£›ãÿ£›ãÿ¢›âÿ¢šâÿ¤šàÿ¥šÜÿ¦šÛÿ¦šÜÿ£—Ûÿ”‡Äÿ[Pvÿÿÿ ÿÿ ÿ)-ÿfd™ÿšœìÿ˜›ëÿ–›ëÿ–œíÿ–›ìÿ–šêÿ–—çÿ˜–æÿ˜•åÿ˜–åÿ—–åÿ—•åÿ˜•åÿ˜•äÿ™”ãÿš“áÿš“âÿ™“áÿ™’àÿš’Þÿœ‘Ûÿœ�Ùÿ��Øÿž�Øÿ��Øÿœ�Ùÿœ�Ùÿœ�Øÿ�ŽØÿ��×ÿž�Öÿž�×ÿž‘Øÿž‘Øÿ ‘Öÿ¢�Ôÿ¢�Ñÿ£�Ðÿ£�Òÿ¢‘Ôÿ¢‘Õÿ¡�Ôÿ¡�Ôÿ �Ôÿ �Ôÿ �ÕÿŸ�Öÿž�ÔÿžŽÒÿž�ÐÿžŒÏÿŸŒÎÿžŒÌÿŸ‹ËÿŸ‹ËÿŸŠÉÿŸ‰ÇÿŸˆÄÿ ˆÂÿ¡ˆÀÿ¡ˆ¿ÿ¢‡¿ÿ¢†½ÿ¢…ºÿ¢…¸ÿ£„·ÿ¢„µÿ£ƒ³ÿ£ƒ²ÿ¤‚°ÿ¦‚®ÿ¥�ªÿ¦€§ÿ§¤ÿ§¢ÿ§Ÿÿ§~œÿ¦}�ÿ¦}�ÿ¥|�ÿ¥|œÿ¥{œÿ¤{œÿ£zœÿ£zœÿ£z�ÿ¢y�ÿ¢yžÿ¢yŸÿ¡yžÿ y�ÿ x�ÿžx�ÿœw�ÿ™v�ÿ˜u�ÿ—tžÿ–sŸÿ•sŸÿ”s ÿ“r¡ÿ’r¢ÿ‘r¢ÿ’r¡ÿ“q ÿ“qžÿ“pœÿ“pœÿ“pœÿ’pœÿ’p›ÿ“p›ÿ’ošÿ’o™ÿ‘n™ÿ�nšÿ�nšÿŽmšÿŒmšÿ‹l›ÿ‹k›ÿĶèÿĶèÿöéÿöéÿĶçÿƶæÿƶæÿŶæÿŶçÿŶçÿÅ·èÿÅ·èÿÅ·èÿÄ·éÿöëÿÀ¶íÿ½¶ðÿº·ôÿ¸·öÿ¶·öÿ¶¶öÿµ¶øÿ³¶ùÿ³¶øÿ´µöÿµ´õÿµ³ôÿµ³ôÿ´³ôÿ³²ôÿ³²óÿ³²óÿ´±òÿµ°ðÿ·°íÿ¹¯ëÿ»¯çÿ½¯äÿ¾®áÿÀ®ÞÿÁ­ÝÿÁ­Ýÿ­Ýÿ®Þÿ®ÞÿÄ®ÜÿůÚÿǯ×ÿɰÕÿʰÔÿ˰Òÿ̰ÏÿͰÌÿΰËÿϰÉÿаÇÿЯÆÿЯÅÿѯÅÿѯÅÿЯÅÿЮÆÿÏ®ÇÿÍ®ÈÿÌ®ÊÿË®ÌÿÌ®ËÿÌ®ÈÿίÇÿЯÅÿѯÄÿѯÃÿÒ¯ÂÿѯÂÿЮÂÿÏ­ÄÿÍ­ÆÿÌ­ÈÿˬÊÿȬÌÿÆ«ÐÿëÖÿÁ«Ûÿ¾«Þÿ¼ªàÿº©àÿ¸¨áÿ·¨áÿ·¨áÿ¶§áÿµ¦âÿ³¦ãÿ±¦åÿ­¥çÿª¥êÿ¦¥ìÿ¤¤îÿ¢£îÿ¡¢íÿ ¡ìÿ¡¡ëÿ¢ êÿ¢ êÿ£Ÿèÿ¤žæÿ¦žäÿ§žäÿ§žäÿ¦�äÿ¥�äÿ¦œãÿ¦�ãÿ¥�âÿ¥œâÿ¥›ãÿ¥›áÿ¦šÞÿ¦šÜÿ§šÝÿ¤˜Ûÿ�ƒ½ÿVLoÿ +ÿÿÿ ÿ ÿ'(ÿdb—ÿš›ìÿ—šëÿ•›ëÿ”œíÿ”œíÿ”›ìÿ•™éÿ–—çÿ—•åÿ™”ãÿ™•âÿ™•äÿ™•åÿ™–åÿš•ãÿ›“ßÿ›“àÿ›”áÿ›“áÿœ“ßÿ�“Üÿœ‘Úÿ�‘Ùÿ�‘Úÿ�‘Úÿœ�Úÿœ�Úÿœ�Ûÿœ�Ûÿ��Úÿ��Ùÿž‘Ùÿž’Úÿž’ÚÿŸ‘Øÿ¡�Öÿ¡‘Ôÿ¢�Òÿ¢�Óÿ¢‘Õÿ¢‘Öÿ¡‘×ÿ ‘Öÿ¡�Õÿ¡�Ôÿ �ÕÿŸ�ÖÿŸ�Ôÿ ŽÑÿŸ�ÎÿžŒÎÿžŒÎÿŸŒÎÿŸŒÌÿŸŠÊÿ ‰Çÿ ˆÄÿŸ‡ÁÿŸ†¾ÿ ‡¼ÿ¡‡¼ÿ¡†½ÿ¡…¼ÿ¢…¹ÿ¢„¶ÿ£„´ÿ£ƒ²ÿ¤‚±ÿ¤‚°ÿ¤‚¯ÿ¥‚¬ÿ¦�§ÿ¦€¤ÿ§¢ÿ¨ ÿ§~�ÿ¦}�ÿ¥|�ÿ¥|�ÿ¥|�ÿ¥|�ÿ¥|œÿ¥|œÿ¥{œÿ¥{›ÿ¤{›ÿ¤z›ÿ¤z�ÿ¤{�ÿ£zœÿ£zœÿ¢y�ÿ yžÿ�xžÿšwžÿ™vžÿ˜užÿ˜tžÿ—tŸÿ•s¡ÿ”s¢ÿ“s£ÿ’s¢ÿ“s¡ÿ”r ÿ”rŸÿ”q�ÿ”q�ÿ“p�ÿ’p�ÿ�ožÿ�ožÿ�nžÿŽnžÿŽnžÿ�mžÿŒmŸÿŠlŸÿ‰k ÿˆk ÿˆj ÿǸçÿƸéÿŸéÿĸéÿŸéÿŸèÿÆ·èÿŶèÿĶéÿ¶ëÿ¶ëÿ·ëÿ·ìÿ·ìÿ¸íÿÀ·îÿ¾·ðÿ¼·óÿº·ôÿ¸·ôÿ¶¶öÿµ·øÿ³·úÿ²·ùÿ³¶øÿ´µöÿµ´õÿµ³ôÿ´³ôÿ³³ôÿ³²ôÿ´²ôÿ´²óÿ´±òÿµ±ñÿ·°îÿ¸°ëÿ¹¯éÿ»®æÿ½®äÿ½®ãÿ¾­áÿ¿­àÿÀ­àÿÁ®áÿÁ®àÿïßÿįÝÿƯÛÿȰÙÿɯ×ÿʰÕÿ˰ÓÿͱÐÿαÍÿΰËÿΰÊÿΰÊÿϰÉÿϰÉÿϯÈÿϯÉÿίÊÿίÊÿͯÍÿË®Ïÿ˯Ïÿ˯ÎÿÍ®ËÿίÉÿϯÈÿϯÆÿϯÆÿϯÆÿήÇÿÍ®ÈÿÌ®ÉÿË®ËÿÉ­ÍÿǬÏÿÅ«Óÿë×ÿÁ«Üÿ¾«ßÿ»«àÿ¹ªáÿ¸©âÿ·¨áÿ¶¨àÿ¶¨áÿ¶§âÿ³¦ãÿ±¦åÿ­¦çÿ©¦ëÿ¦¥íÿ£¤îÿ¡¤îÿ¡¢îÿ ¡íÿ¡¡íÿ ¡ëÿ¢ êÿ£Ÿèÿ£Ÿçÿ¥ æÿ¦Ÿåÿ§Ÿåÿ§žäÿ§žãÿ¨žãÿ¨žâÿ§�âÿ§�âÿ§�ãÿ¦œãÿ¥›âÿ¤šàÿ¤›áÿ¢˜Þÿ‹ºÿQGkÿ +ÿ"#ÿÿÿ%)ÿ!ÿa_“ÿ›šìÿ˜˜éÿ—™èÿ–›êÿ•›ëÿ•šêÿ•˜éÿ•˜èÿ–•åÿš“àÿ�“Þÿ�“Ýÿœ•ßÿœ•àÿ�”ßÿœ“Ýÿ›’Þÿ›“àÿœ“ßÿœ’Ýÿ�“Ûÿ�’Ûÿ�’Ûÿ�’Üÿ�“Ýÿž’Ýÿ�’Ýÿ�’Ýÿ�’Ýÿ�’ÜÿŸ’Úÿ ‘Øÿ ’Ùÿ “Úÿ ’Ùÿ ‘Øÿ¢’×ÿ¢‘Öÿ¢‘Öÿ¢’Öÿ¡‘×ÿ¡’×ÿ¡’Öÿ¡‘Õÿ¢‘Õÿ¡�Ôÿ �Ôÿ �Óÿ ŽÏÿ ŒÌÿŸŒÍÿ�ŒÎÿžŒÏÿžŒÎÿžŠËÿž‰ÈÿŸˆÅÿŸ‡ÁÿŸ†¿ÿŸ…¾ÿŸ„½ÿŸ„½ÿ „¼ÿ ƒ¹ÿ¡‚¶ÿ¢‚³ÿ¤�°ÿ¤�¯ÿ¤�­ÿ¤€ªÿ¥§ÿ¦¥ÿ¥¤ÿ¥~£ÿ¦} ÿ¦~žÿ¥}Ÿÿ¥| ÿ¥|Ÿÿ¥|žÿ¤{�ÿ¤|�ÿ¥{œÿ¤{�ÿ£{�ÿ¢{�ÿ¢zžÿ¢z�ÿ£z�ÿ£y�ÿ£yžÿ¡yžÿŸxŸÿ�x ÿ›x¡ÿšw ÿšv ÿ™v ÿ—u ÿ•t¡ÿ”s¢ÿ“s¢ÿ“s¢ÿ“s¢ÿ“r¡ÿ’q¢ÿ‘r¢ÿ‘q¢ÿ‘p¡ÿ�o¡ÿŽo¢ÿ�o¢ÿŒn¢ÿ‹m£ÿŠm¤ÿ‰l£ÿˆk£ÿ‡k£ÿ†j£ÿ…i£ÿ…i£ÿȸçÿǹèÿƹéÿƸéÿĸéÿŹêÿƸêÿŸêÿÄ·êÿ÷ëÿ·îÿÁ¸ïÿÀ¸ïÿÁ¸ïÿÁ¸ïÿÀ¸ðÿ¿¸ðÿ¾¸ñÿ½·òÿ»¶òÿ¸·óÿ¶·÷ÿ´·ùÿ²·ùÿ²¶ùÿ³¶øÿ´´÷ÿ³´öÿ³´öÿ³´õÿ²³õÿ³²ôÿ³²ôÿ³²óÿ³±óÿ³°òÿ´°ðÿµ¯îÿ¶¯íÿ·¯ëÿ¹¯éÿº®çÿ¼®åÿ¾®ãÿ¿®ãÿ¿®ãÿÀ®ãÿ¯áÿïßÿŰÝÿưÛÿȰÙÿʱÖÿ̱ÒÿͱÐÿͰÐÿͰÐÿͰÏÿͰÎÿͰÍÿΰÍÿΰÌÿΰËÿͰËÿͯÍÿʯÐÿÉ®ÑÿÉ®Òÿ˯ÑÿͯÍÿͰËÿίÉÿͯÉÿͯÊÿ̯Ëÿ˯ËÿÊ®ÍÿÈ®ÐÿÇ­ÓÿŬÕÿìØÿÁ«ÚÿÀ«Ýÿ¾«àÿ»«áÿ¹ªáÿ¸ªâÿ·©áÿ¶¨áÿ¶§àÿµ§áÿ³§ãÿ°¦åÿ­¦èÿ©¥ëÿ¥¦íÿ¢¥îÿ¡¤îÿ £îÿ ¢íÿ ¡ìÿ ¡ëÿ¢ éÿ£ èÿ£ çÿ¥Ÿæÿ¦Ÿåÿ§Ÿåÿ¨Ÿåÿ¨Ÿäÿ¨Ÿâÿ¨žâÿ¨žâÿ¨žãÿ§žäÿ¤�äÿ£�åÿ¢œäÿ¢œåÿŸ™àÿ…{µÿSIoÿ(.ÿ%(ÿ!ÿÿ'.ÿÿ_]�ÿš™êÿ™—èÿ——æÿ—™èÿ—™éÿ–™èÿ•˜èÿ•™èÿ––åÿ™“ßÿ�’Úÿž“ÙÿŸ”Ûÿž”Ýÿ�”Ýÿœ“Üÿ›“ßÿœ”Þÿ�”Üÿž“Ûÿž“Úÿž“Ûÿž“Üÿž”Üÿž”Ýÿž”Ýÿž“Üÿž“Ýÿ�“Üÿž“ÛÿŸ’Ùÿ ‘Ùÿ ’Ùÿ “Ùÿ “Ùÿ¡’×ÿ¢“×ÿ¢“×ÿ¢“×ÿ¡’×ÿ ‘Öÿ¡‘Öÿ¡‘Öÿ¡’Öÿ¡‘Ôÿ¢�Óÿ¡�Òÿ¡�Ðÿ¡ŽÍÿ¡ŒËÿŸŒÌÿž‹Ìÿ�‹Ìÿ�‹Ìÿ�‹Ëÿ�ŠÈÿžˆÆÿŸ‡ÄÿŸ†Âÿž…Àÿž„¾ÿŸ„½ÿŸƒ¼ÿŸƒ¹ÿ ‚µÿ¡‚²ÿ¢�¯ÿ£€­ÿ£€ªÿ£§ÿ¤~¥ÿ£~¥ÿ£~¥ÿ¢~¥ÿ¢}¤ÿ¢}¢ÿ£}¡ÿ¢|¡ÿ¢| ÿ¢{Ÿÿ¢{žÿ¢{žÿ¢{žÿ¡{Ÿÿ¡{ ÿ¡z ÿ¡z ÿ¡yŸÿ¡yžÿ¢yžÿ¡zŸÿ zŸÿŸy¡ÿžy¡ÿ�x¡ÿ›x¡ÿ›w¢ÿ™w¢ÿ–v¡ÿ”u£ÿ“t¥ÿ’s¥ÿ‘r¥ÿ�r¥ÿ�r¥ÿ�r¦ÿ�r§ÿŽq§ÿ�p§ÿŒp§ÿ‹p¨ÿŠo§ÿ‰n¨ÿˆm¨ÿ‡m¨ÿ‡l§ÿ†k¦ÿ…j¤ÿ…j£ÿ„i£ÿ…i£ÿɸæÿȹçÿȹèÿȹèÿǹèÿƹêÿƸêÿƸêÿŹëÿĹëÿùîÿÁ¹ðÿÀ¹ðÿÀ¹ñÿÀ¹ñÿÀ¹òÿ¿¸ñÿ¿¸ñÿ¿·ñÿ½·ðÿ»·ñÿ¸¸öÿµ¸øÿ´¸ùÿ³·ùÿ³·ùÿ³¶ùÿ²¶ùÿ²¶øÿ±µøÿ±µ÷ÿ±´öÿ±³öÿ±³öÿ°²öÿ°±õÿ°±ôÿ±°óÿ²¯ñÿ³¯ïÿµ¯îÿ·¯íÿ¹¯ëÿº¯éÿ¼¯èÿ¼¯çÿ½¯æÿ¿¯åÿÀ¯ãÿðáÿİÞÿƱÛÿɱ×ÿ˱Ôÿ˱Óÿ˱Óÿ˰Óÿ˰Óÿ˰Óÿ˰Òÿ̰Òÿ̰Ðÿ̰Îÿ̯Îÿ˯ÏÿʯÑÿȯÓÿÈ®ÔÿɯÔÿ˯Ñÿ˯Îÿ̯Ìÿ˯ÌÿʯÍÿʯÎÿɯÏÿÇ®ÒÿÅ®ÖÿÄ­Ùÿ¬ÛÿÀ¬Üÿ¿«Ýÿ¾«ßÿ½¬áÿ»«âÿº«âÿ¹ªâÿ¸©áÿ·¨áÿ¶§àÿµ§áÿ³§ãÿ°§åÿ¬¦éÿ¨¦ìÿ¥¥îÿ¢¤îÿ¡¤îÿ ¤îÿ £íÿ ¢ìÿ¡¡êÿ£¡éÿ¤ èÿ¥ çÿ¦ æÿ§Ÿåÿ¨ åÿ¨ åÿ¨ äÿ¨Ÿäÿ©Ÿãÿ¨žãÿ¨žäÿ§Ÿåÿ¤Ÿæÿ¢Ÿçÿ¡žèÿ¢Ÿéÿ�šãÿx±ÿOGkÿ&,ÿ!!ÿÿÿ#)ÿ ÿ_\Žÿ——æÿ™˜èÿ—˜çÿ—™èÿ—™éÿ–™éÿ–šéÿ•™éÿ”–æÿ–’àÿš’Ûÿ�’Úÿ�’Úÿ�“Úÿ›’Üÿš“Ýÿœ“ßÿ�”ÜÿŸ”Ùÿ “Øÿ “Øÿ ”Úÿ ”Úÿ ”Ûÿ ”Ûÿ ”Ûÿ ”ÚÿŸ”ÛÿŸ“Ûÿž“Úÿ ’Ùÿ ’Ùÿ ’Ùÿ¡“Ùÿ¡“Øÿ¢“×ÿ¢“×ÿ¢“Öÿ¢“Öÿ£’Öÿ¢’Õÿ¢’Ôÿ£‘Ôÿ£’Õÿ¢’Ôÿ¢‘Òÿ¢�Ñÿ¢�Ïÿ¢ŽËÿ¡ŒÉÿ¡‹Èÿ ŠÈÿŸŠÇÿžŠÈÿžŠÈÿž‰ÇÿžˆÅÿž‡Äÿž‡Ãÿ�†Âÿ�„¿ÿž„½ÿŸƒ»ÿŸƒ¸ÿ ‚´ÿ¡‚±ÿ¢�¯ÿ£€¬ÿ£€ªÿ£€©ÿ¢¨ÿ¡~¨ÿ ~©ÿ }ªÿŸ}ªÿŸ}¨ÿ }¦ÿ |¤ÿ {¢ÿ z¡ÿŸz¡ÿ z¡ÿŸz¡ÿžz¡ÿŸz¢ÿŸz£ÿ z¢ÿ z ÿ¡z ÿ¡{¡ÿ¡{¡ÿ {¡ÿ {¢ÿŸz¢ÿ�y¡ÿ›x¢ÿšw£ÿ—w¤ÿ•v¤ÿ“t¥ÿ‘t§ÿ�t¨ÿŽsªÿ�rªÿŒr«ÿŒr«ÿŒr«ÿ‹q¬ÿŠq¬ÿ‰q¬ÿˆp­ÿˆp¬ÿˆo¬ÿ‡n«ÿ†n«ÿ†l©ÿ†l¨ÿ„k¦ÿ„k¥ÿ„j¦ÿ„j¦ÿ˹åÿʹæÿʹæÿʹæÿʹæÿɹèÿȹéÿǹêÿƹëÿŹìÿĺîÿºðÿÁ¹ðÿÁ¹ñÿÁºòÿÀ¹òÿÀ¹òÿÀ¸ñÿ¿¸ñÿ¾¸ñÿ½·ñÿ¹¸ôÿ·¹øÿµ¹ùÿ´¸ùÿ³·ùÿ²¸úÿ±¸ûÿ°¸ûÿ¯¸úÿ¯·ùÿ®¶úÿ®¶úÿ®¶úÿ®´ùÿ­³ùÿ®³øÿ®²÷ÿ¯±õÿ°±óÿ²°òÿ³°òÿ´°ðÿ¶°îÿ·°îÿ¸°ìÿº°êÿ¼¯éÿ¾¯çÿÁ¯äÿñáÿűßÿDZÛÿɱÙÿʱ×ÿʱÖÿʱÖÿɰÖÿʰÕÿʯÕÿʰÔÿʰÓÿʯÒÿʯÑÿʯÑÿɯÓÿȯÕÿȯÖÿɯÕÿɯÓÿʯÑÿʯÏÿÊ®ÏÿÉ®ÐÿÈ®ÑÿÇ®ÓÿÅ®ÖÿíÚÿ¬ÝÿÁ¬Þÿ¾«ßÿ¾«àÿ½¬áÿ½¬âÿ¼¬âÿ»«áÿ»«áÿº©àÿ¸¨àÿ¶§àÿµ§áÿ³§ãÿ¯¦åÿ«¦éÿ¨¦ìÿ¥¥îÿ£¥îÿ¢¥ïÿ ¦ïÿ ¥ïÿ¡£íÿ¢£ìÿ¤¢êÿ¥¡éÿ¦¡çÿ¨¡æÿ© æÿ© æÿ¨¡æÿ¨¡æÿ© æÿ© äÿ© äÿ¨ åÿ§Ÿæÿ¤ çÿ¢ éÿ Ÿêÿ¡ ìÿ›œåÿzu®ÿF@aÿÿÿÿ ÿ!ÿ!ÿ\Z‹ÿ’“àÿ˜šéÿ˜›éÿ—šéÿ—šéÿ—›êÿ–šêÿ”˜éÿ“”æÿ”‘áÿ˜‘Üÿ›‘Ûÿ›‘Úÿ›‘Ùÿš‘Ûÿš’Þÿœ“ßÿŸ“Üÿ¡’Øÿ¢’Õÿ£“Öÿ£”×ÿ¢”×ÿ¢”×ÿ£”Øÿ£”Øÿ¢”Øÿ¢”Øÿ¡”Øÿ¡“Øÿ¡”Ùÿ¡”Ùÿ¡“Ùÿ¢”Øÿ£”×ÿ¤”Öÿ¤”Öÿ¤”Öÿ¤“Õÿ¥“Õÿ¥“Ôÿ¥’Òÿ¥’Òÿ¥’Òÿ¥’Òÿ¤‘Ñÿ£�Ïÿ£�Íÿ¢�Êÿ¢‹Èÿ¢‹Æÿ¢‰Åÿ¡ˆÃÿ ˆÄÿŸˆÅÿŸˆÄÿŸˆÃÿž‡Âÿž‡Âÿ�†Áÿ�…¿ÿžƒ½ÿŸƒºÿ ƒ·ÿ¡‚´ÿ¡‚²ÿ¢‚°ÿ£�®ÿ¢�­ÿ¢�¬ÿ¡€¬ÿ ¬ÿŸ~­ÿž~®ÿ�}®ÿ�}­ÿž}«ÿž|¨ÿž{¦ÿž{¥ÿ�z¤ÿžz¤ÿ�z£ÿ�y£ÿ�y£ÿžy¤ÿŸz£ÿŸ{¢ÿ {¢ÿ |£ÿ |¤ÿ {¤ÿŸ{£ÿžz£ÿ�y¤ÿšx¥ÿ—w§ÿ•v¨ÿ“u©ÿ‘uªÿ�u«ÿŽt­ÿ�t®ÿŒs¯ÿ‹r°ÿ‰r°ÿˆr±ÿˆq°ÿ‡q°ÿ‡q°ÿ†q°ÿ†p¯ÿ†o®ÿ†o­ÿ†n¬ÿ†m«ÿ…mªÿ„l©ÿƒlªÿƒlªÿƒl«ÿͺæÿͺåÿ̺åÿ̹åÿ̹åÿ˺æÿʺçÿɺéÿǺëÿƺîÿÄ»ðÿúðÿºðÿºñÿ¹ñÿÀºñÿÀ¹ñÿÀ¹ñÿ¿¹òÿ¾¸óÿ¼¸óÿ¹¸öÿ·¹øÿµºúÿ´¹úÿ³¹úÿ±¹úÿ¯¹ûÿ®¹üÿ®¹üÿ­¸üÿ¬¹ýÿ¬¹ýÿ¬¸ýÿ«¸üÿ«·üÿ«¶ûÿ«¶ûÿ¬µùÿ®´÷ÿ¯³öÿ°²õÿ±±ôÿ±±òÿ³±òÿ´±ñÿ·°ïÿ¹°íÿ¼°êÿ¿°çÿÀ°åÿñäÿıâÿŲáÿDzßÿȱÜÿȱÚÿɱØÿ˱ÖÿʰÔÿʰÔÿɰÕÿɰÔÿɯÔÿÉ®ÔÿȯÕÿȯÖÿɯÖÿɰÖÿɰÕÿɰÔÿɯÒÿɯÒÿÈ®ÓÿÇ®ÔÿÆ­ÖÿÄ­Øÿ­Ûÿ­ÝÿÁ­Þÿ¾¬àÿ½¬áÿ¼¬âÿ¼¬âÿ½«áÿ¾«àÿ½«ßÿ¼ªßÿ»©ßÿ¸¨ßÿ¶§àÿ³¦ãÿ¯¦åÿ«¦éÿ¨¦íÿ¥¦îÿ¤¦ïÿ£§ðÿ¢¨ñÿ¡¨ñÿ£¦ðÿ£¤îÿ¥£ìÿ¦£êÿ§¢éÿ©¢çÿ©¡çÿ©¡æÿ¨¡æÿ¨¡çÿ©¡çÿ¨¡æÿ¨¡æÿ¨¡æÿ§ çÿ¤ éÿ¢ êÿ  ëÿŸ¢îÿš�çÿurªÿC=^ÿ#ÿ#&ÿÿÿ%.ÿ"%ÿVV…ÿŒ�Úÿ–›èÿ—›éÿ–šéÿ–šéÿ–šéÿ”˜èÿ“–çÿ”“äÿ–‘àÿ™‘Üÿ›’Üÿ›‘Úÿ›‘Ùÿ›‘Ûÿœ’Þÿ�“Ýÿ “Ûÿ¢“×ÿ£’Ôÿ¤“Ôÿ¤“Óÿ¤“Óÿ¤“Ôÿ¤”Õÿ¤“Öÿ¤”Öÿ¤”Ôÿ¤”Õÿ¤”Öÿ£•Øÿ£•Øÿ£”×ÿ¤•Öÿ¦•Õÿ¦•Ôÿ¦•Ôÿ¦”Ôÿ¦”Óÿ§“Ñÿ§“Ðÿ¨“Ïÿ¨“Îÿ§’Îÿ¦‘Îÿ¥�Îÿ¥�Íÿ¤ŽËÿ£ŒÉÿ¢‹Æÿ¢‹Åÿ¡‰Ãÿ¢ˆÁÿ¢ˆÁÿ¡‡Áÿ ˆÁÿ ‡Àÿ ‡ÀÿŸ‡ÀÿŸ†¿ÿŸ„½ÿŸ„¼ÿ¡„¹ÿ¡ƒ¶ÿ¡ƒµÿ ‚´ÿ¡‚²ÿ¢�±ÿ¡�°ÿ �°ÿŸ€°ÿŸ€¯ÿŸ®ÿž¯ÿ�°ÿ�~¯ÿ�}­ÿ�}«ÿ�}©ÿž|¨ÿž|§ÿ�{¦ÿ�z¤ÿ�z£ÿ�y¤ÿ�y¤ÿžz¤ÿŸ{¤ÿŸ{¤ÿŸ{¤ÿŸ|¦ÿž{¦ÿ�z§ÿœz§ÿšy©ÿ—x¬ÿ•w­ÿ“v®ÿ‘v¯ÿ�v°ÿ�v±ÿŽu±ÿ�t±ÿŒt²ÿŠs´ÿˆs¶ÿ‡s·ÿ†r´ÿ…q²ÿ„p±ÿ…p±ÿ…o°ÿ„o¯ÿ„n¯ÿ…n®ÿ…n­ÿ„m¬ÿ„l¬ÿƒl¬ÿ‚m­ÿ‚m®ÿλåÿÍ»åÿÍ»æÿÍ»æÿÌ»æÿ˺æÿʺçÿɺéÿÇ»ìÿÆ»îÿƼïÿÅ»ðÿûðÿ»ñÿ»òÿÀºòÿÀºòÿÀ¹òÿ¿ºôÿ½ºõÿ»»öÿ¹»øÿ¶¼úÿ´¼ûÿ³¼ûÿ²»üÿ±»üÿ¯»üÿ­»ýÿ«ºþÿ«ºþÿªºýÿ©¹ýÿ©¹þÿ¨¹þÿ¨¹þÿ¨¹ýÿ©¸ýÿª·üÿ«·ûÿ¬¶úÿ®µùÿ¯´÷ÿ¯³öÿ°²õÿ±±ôÿ³±óÿµ±ñÿ¸±îÿ»°êÿ½°èÿ¿±çÿÀ±çÿÁ±çÿ²åÿIJãÿƱßÿȱÛÿʱ×ÿ˱ÖÿʰÔÿʰÕÿʰÕÿɰÕÿɯÖÿǯ×ÿǯØÿȯ×ÿȯÖÿȯ×ÿɰ×ÿɯÖÿɯÖÿÈ®ÖÿÇ­×ÿÅ­ÙÿíÛÿÁ¬ÜÿÁ¬ÝÿÁ¬Þÿ¿­àÿ¾¬áÿ½¬áÿ½¬áÿ½¬àÿ¾«Þÿ¿«Ýÿ¿ªÜÿ¾©Üÿ¼¨Üÿ¹¨Þÿµ§âÿ°¦åÿ¬¦éÿ¨§ìÿ¥§ïÿ£§ðÿ¢¨ðÿ¢©ðÿ¢¨ñÿ¢§ðÿ£¥ïÿ¥¤íÿ§¤ëÿ¨£éÿ©£èÿ©¢çÿ©¢æÿ©¢æÿ¨¡æÿ¨¡çÿ§¡çÿ§¡çÿ§¡çÿ§¡èÿ¥¢éÿ£¢ëÿ ¢ìÿ ¤ðÿšŸéÿqn£ÿLElÿ4,Iÿ*2ÿ$"ÿ"&ÿ3,Jÿ-$=ÿRS€ÿ†‹Óÿ–šèÿ–›êÿ•˜èÿ•—çÿ––æÿ••åÿ”“ãÿ–’áÿ™’ßÿ›’Üÿ›’Úÿœ‘Ùÿœ‘Ùÿ�’Úÿž“ÛÿŸ“Úÿ¡“Øÿ¢“Öÿ£“Ôÿ¤“Óÿ¤“Òÿ¥“Ñÿ¥“Òÿ¦“Óÿ¦”Óÿ¦•Óÿ¦”Óÿ§”Óÿ¦•Ôÿ¦–Öÿ¦–×ÿ¦–Öÿ§–Õÿ¨–Ôÿ©–Ôÿ¨–Óÿ¨•Òÿ©”Ðÿª”Îÿª“Íÿª’Ìÿ©’Ëÿ¨‘Ëÿ¨�Ëÿ§�Êÿ¥�Éÿ¤ŽÈÿ£ŒÆÿ£‹Äÿ£ŠÃÿ¢‰Áÿ¢ˆÀÿ£ˆ¾ÿ£ˆ¾ÿ£ˆ¾ÿ£ˆ¾ÿ¢‡½ÿ¢‡½ÿ¡†¼ÿ¡†ºÿ¡…ºÿ¢…¸ÿ¢…¶ÿ¢…µÿ¢„µÿ¢„´ÿ¡‚´ÿ¡�´ÿŸ�µÿž€³ÿž€±ÿž°ÿ�~¯ÿœ~°ÿ›~°ÿ›|­ÿ›|¬ÿ›|«ÿœ{ªÿœ{©ÿœ{§ÿœz¦ÿœz¦ÿ�z¦ÿžz§ÿž{¨ÿ�|§ÿž|¨ÿž|©ÿœ{ªÿ›|ªÿš{«ÿ™z­ÿ—z¯ÿ•y±ÿ”x²ÿ“w´ÿ‘w´ÿ�wµÿ�wµÿ�vµÿŒu´ÿ‹tµÿ‰t·ÿ†t¹ÿ…r¹ÿ…r·ÿ…qµÿ…q³ÿ„p³ÿ„p³ÿ„p³ÿƒo²ÿƒo°ÿ„n¯ÿƒm­ÿƒm¬ÿ‚l¬ÿ�m­ÿ�n¯ÿνèÿͽèÿͼéÿ̼êÿ˼êÿÊ»êÿÊ»ëÿÉ»ëÿÈ»ìÿǼîÿǼîÿǼîÿżïÿļñÿüòÿÁ»òÿÀºóÿÀºóÿÀºóÿ¿ºôÿ½ºöÿº»øÿ·½ûÿµ¾ýÿ´½ýÿ²½ýÿ°¼ýÿ­¼þÿ«¼þÿª¼þÿ©¼þÿ¨»þÿ¨»þÿ§»þÿ§»þÿ§»ýÿ§ºþÿ¨ºþÿ©¹ýÿª¸ýÿ¬·üÿ®·ûÿ®¶ùÿ®¶øÿ¯µøÿ¯´÷ÿ¯²öÿ±²õÿ´²óÿ·±ðÿº±ìÿ½²êÿ¾²êÿÀ²éÿÀ³èÿ³æÿŲâÿDzÝÿʲØÿ˲Öÿ˱Õÿ̱Ôÿ̱Ôÿ˰ÔÿʰÕÿɰ×ÿȰØÿȯØÿȯ×ÿǰØÿȰØÿȰØÿɰØÿȰØÿǯÙÿÅ®ÛÿîÝÿ®ÞÿÁ­ÞÿÁ­ßÿÀ­ßÿ¿­àÿ¾¬áÿ¾¬áÿ¾¬àÿ¿¬ÝÿÀ«ÛÿÀ«ÙÿÀ«Øÿ¿ªØÿ¼©Úÿ¸¨ßÿ²§äÿ­§éÿ©¨íÿ¦¨ïÿ¤¨ðÿ¢©ñÿ¢©ñÿ£©òÿ£¨ñÿ¤¨ðÿ¥¦ïÿ§¤ìÿ¨¤êÿ©¤êÿ©£éÿ¨£èÿ¨£çÿ§¢èÿ§¢èÿ§¢èÿ¦¢èÿ¦¢éÿ¦¢êÿ¥£êÿ££ìÿ¢£íÿ¢¦ñÿ› éÿmjœÿMFoÿ6.Pÿ%(ÿ!ÿÿ+"9ÿ.#=ÿSQÿ�…Êÿ•šèÿ–šéÿ”—æÿ••äÿ—”ãÿ™”áÿ™”áÿ™”àÿ›”ßÿ�”Ýÿž“Úÿž“ÙÿŸ“ÙÿŸ“Ùÿ ”Øÿ¢”Øÿ£”×ÿ¤•×ÿ¤•Öÿ¤”Õÿ¤”Ôÿ¥”Óÿ¦”Óÿ¦”Óÿ§•Òÿ¨–Òÿ©–Óÿ©–Óÿ©–Ôÿ¨–Ôÿ¨–Õÿ©–Ôÿ©–Òÿ«–Ñÿ«–Ðÿª•Ðÿ«•Ðÿ«•Îÿ«”Ìÿ«”Ëÿ«“Êÿ©’Éÿ©‘Éÿ¨�Èÿ§�Çÿ¦ŽÆÿ¥�Äÿ¥ŒÂÿ¤‹Áÿ¤ŠÁÿ£‰Àÿ£ˆ¾ÿ¤ˆ¼ÿ¤ˆ»ÿ¤ˆ»ÿ¤ˆ¼ÿ£‡»ÿ£‡»ÿ¢†»ÿ¢†»ÿ¢…ºÿ£…·ÿ£…¶ÿ¢…µÿ¢…µÿ¢…¶ÿ¡„·ÿ ƒ¸ÿŸ‚¸ÿŸ‚¶ÿž�´ÿž€²ÿ�±ÿœ~°ÿ›~°ÿš|¯ÿ™{¯ÿ™z®ÿ˜z­ÿ™z¬ÿ™{«ÿ™zªÿ™zªÿšzªÿ›z¬ÿ›{¬ÿ›|­ÿœ}®ÿœ}¯ÿš|¯ÿ™|¯ÿ™{°ÿ˜{²ÿ–{´ÿ”zµÿ“z·ÿ’y¸ÿ�y¹ÿ�x¸ÿ�w¸ÿŽw¸ÿŒv·ÿŠu¸ÿˆt¹ÿ‡t»ÿ†sºÿ†sºÿ…s¸ÿ…r¶ÿ…r¶ÿ„q¶ÿ„qµÿƒp´ÿ‚o²ÿ‚o±ÿƒm¯ÿ‚m­ÿ�l¬ÿ�l¬ÿ€l¬ÿ;ëÿ;ëÿ̾ìÿ˾íÿ˽íÿʼíÿʼìÿÉ»ìÿɼíÿȼíÿɼíÿɼíÿȼíÿǼïÿżðÿûñÿÁ»òÿÁ»óÿÁ»óÿÁºóÿ¿ºôÿ»»÷ÿ¸¼ûÿ¶¾ýÿ´¾þÿ³¾þÿ¯¾þÿ¬¾þÿª¾þÿ©½þÿ©½þÿ¨¼þÿ§½þÿ¦½þÿ¦¼þÿ¦¼þÿ§¼þÿ¨»þÿ©ºþÿª¹ýÿ«¸ýÿ¬·üÿ®·ûÿ®·úÿ¯·úÿ¯·úÿ®µùÿ¯³øÿ±²öÿ´²ôÿ¸²ïÿ»²íÿ¾³ëÿ¿³éÿÀ³èÿÁ³çÿIJäÿDzßÿɲÚÿ̲×ÿͲÓÿβÑÿϲÐÿβÑÿͲÔÿ˲Õÿʲ×ÿɱØÿɱÙÿȰÙÿȰÙÿȱÚÿȱÙÿȱÙÿǰÚÿưÛÿįÝÿïÞÿ®ßÿÁ­ßÿÁ­ßÿÀ­ßÿ¿­ßÿ¿¬àÿ¿¬àÿÀ¬ÝÿÀ«ÚÿÁ«×ÿ«ÕÿÁªÕÿ¿ª×ÿ»©Üÿµ¨ãÿ¯¨éÿ«¨íÿ§¨îÿ¥¨ðÿ£©ñÿ£ªòÿ£ªòÿ£©òÿ¤©ñÿ¥§ðÿ¦¦îÿ¨¥íÿ¨¥ìÿ¨¥ëÿ§¤ëÿ§¤êÿ§£éÿ§£éÿ§£éÿ§£éÿ¦£êÿ¦£ëÿ¥£ëÿ¤£ìÿ££íÿ£¦ñÿ� èÿjf–ÿD<_ÿ-$>ÿ ÿÿÿ#)ÿ.$@ÿQP~ÿ|Àÿ”™æÿ–™èÿ”–åÿ–”äÿ˜”âÿ›•áÿ›•àÿ›•ßÿ�•ßÿŸ•ÞÿŸ•Ûÿ¡”Ùÿ¡”Øÿ¢”×ÿ£•Öÿ¤•Öÿ¥–Öÿ¦–Öÿ¦–×ÿ¥–×ÿ¥–×ÿ¥–Öÿ¦–Õÿ§–Óÿ©–Óÿª–Óÿª—Óÿ«—Óÿ«–Óÿ«–Òÿ«–Ñÿ«–Ðÿ¬–Îÿ­–Íÿ­–Ìÿ­–Ìÿ­–Ìÿ­•Ìÿ­”Ëÿ¬“Éÿ«“Éÿª’Èÿª‘Çÿ©‘Æÿ©�Åÿ§�Ãÿ§ŒÁÿ§Œ¿ÿ¦‹¾ÿ¥Š¿ÿ¤Š¾ÿ¤‰¼ÿ¥‰ºÿ¥‰¹ÿ¥ˆ¹ÿ¥ˆºÿ¤ˆ»ÿ£‡¼ÿ£†¼ÿ£†¼ÿ£†»ÿ¤†¸ÿ¤†¶ÿ£†µÿ£…¶ÿ¢…¶ÿ¡„¸ÿ „¹ÿŸƒ¹ÿŸ‚¸ÿŸ�¶ÿž€´ÿ�€³ÿœ²ÿ›~²ÿš|²ÿ˜{²ÿ—z²ÿ–z±ÿ–z°ÿ—z¯ÿ—z¯ÿ—y®ÿ—y¯ÿ—z±ÿ˜{±ÿ™|²ÿš}³ÿš}´ÿ™}µÿ™}µÿ™}¶ÿ˜}·ÿ–}¸ÿ•}¹ÿ’|»ÿ‘{¼ÿ�z¼ÿŽz½ÿ�x¼ÿ�x¼ÿ‹w»ÿŠv»ÿ‰u»ÿ‡u¼ÿ‡u¼ÿ‡u¼ÿ†t»ÿ…sºÿ…s¹ÿ…s¹ÿ„r·ÿ„q¶ÿƒp´ÿ‚n²ÿ‚m¯ÿ�l­ÿ�l«ÿ�lªÿ€k©ÿ˾íÿ˾íÿ˾îÿÌ¿îÿ̾îÿ̽íÿ˼ìÿʼìÿʼíÿʼíÿ˼ìÿ˼ëÿʽëÿɽíÿǼïÿżðÿļñÿûñÿ»ñÿ»òÿ¿»óÿ¼»÷ÿ¹¼úÿ·¾üÿµ¿þÿ³¿þÿ°Àþÿ­Àþÿ«Àþÿ©¿þÿ¨¾þÿ§¾þÿ¦¾þÿ¥¾þÿ¦½þÿ¥½þÿ§¼þÿ¨»þÿ©ºþÿªºþÿª¸ýÿ«¸ýÿ¬¸üÿ­¸üÿ®¸üÿ®¸üÿ®·ûÿ¯µúÿ°´÷ÿ´³õÿ¸²ðÿ»²îÿ¾²ëÿÀ³èÿÀ³èÿÁ³æÿóäÿƲáÿɳÞÿ˳ØÿβÓÿгÏÿгÍÿгÎÿϳÐÿγÓÿͳÕÿ̳×ÿ˲ØÿʱÙÿɰÙÿȱÚÿȱÚÿȱÛÿDZÛÿǰÜÿŰÝÿįÞÿïßÿ®ßÿÀ­ßÿÀ­ßÿÀ­ßÿ¿¬àÿ¿¬àÿ¿«ÝÿÀ«ÛÿÁª×ÿªÕÿªÕÿÀªÖÿ½ªÚÿ¸©áÿ²©çÿ¬©ëÿ¨¨íÿ¦¨îÿ¤©ðÿ¤ªñÿ£ªóÿ£ªóÿ¤©ñÿ¥¨ïÿ¦§îÿ§§îÿ¨¦íÿ¨¦íÿ§¥íÿ¦¥ìÿ§¤ëÿ§£êÿ¨£éÿ¨¤êÿ§¤êÿ§¤êÿ§¤ëÿ¥£ìÿ¤£ìÿ¥¥ðÿžŸèÿhb�ÿ;1Jÿ%)ÿ!!ÿÿÿ$,ÿ-%@ÿMKwÿwx·ÿ“—äÿ–˜èÿ”–æÿ–•åÿ™•ãÿ›–âÿš•áÿ›–àÿ�–ßÿŸ–Ýÿ –Úÿ¢–Øÿ£•Öÿ¤•Õÿ¥•Õÿ¦–Õÿ¦—Õÿ§—Õÿ§—Öÿ§–Öÿ§—Öÿ§—Öÿ§—Õÿ©—Ôÿª—Ôÿ«˜Óÿ«˜Òÿ¬—Òÿ¬—Ñÿ¬–Ðÿ­–Îÿ­–Íÿ®–Ìÿ®–Ëÿ¯–Ëÿ¯–Ëÿ®–Êÿ®•Éÿ­“Éÿ­“Éÿ¬’Èÿ«’Çÿ«‘Æÿª�Äÿ©�Ãÿ¨�Áÿ¨�¾ÿ¨Œ½ÿ¨‹¼ÿ§‹½ÿ¦Š½ÿ¦Š»ÿ¦‰¹ÿ¥‰¸ÿ¥ˆ·ÿ¥ˆ¸ÿ¥ˆºÿ¤‡»ÿ¤†»ÿ¤†¼ÿ¤‡»ÿ¤‡¹ÿ¤‡·ÿ¤‡¶ÿ¤†¶ÿ£…·ÿ¢„·ÿ¡„¸ÿ ƒ¸ÿŸ‚·ÿŸ�¶ÿž€µÿ�´ÿœ´ÿ›~´ÿ™|´ÿ—{µÿ–{µÿ•{µÿ•{³ÿ–z²ÿ–z²ÿ–z²ÿ–z³ÿ–{µÿ—{µÿ—|¶ÿ˜}·ÿ˜~¸ÿ™~ºÿ™ºÿ˜»ÿ—¼ÿ–~½ÿ”¾ÿ’}¾ÿ�|¿ÿŽ{¿ÿŒ{ÀÿŠzÁÿŠxÀÿ‰w¿ÿˆv¾ÿˆv¾ÿ‡v½ÿ‡u½ÿ‡u½ÿ†u½ÿ…t½ÿ„s¼ÿ…s»ÿ„r¹ÿ„q·ÿƒpµÿ‚n²ÿ‚l¯ÿ�l­ÿ�lªÿ€k§ÿi¥ÿʽíÿʾîÿ˾îÿ;íÿξíÿ;ìÿͽíÿ̽íÿʽìÿ˽ìÿ̼ëÿ̼êÿ̽êÿ˽ìÿɽîÿǽðÿƼðÿļðÿüðÿ¼ñÿÀ¼ôÿ½¼÷ÿº¾úÿ¸¿üÿ·Àýÿ´Àþÿ±Áþÿ®Âþÿ«Âþÿ¨Áþÿ¦Àþÿ¦Àýÿ¦Àþÿ¦¿ÿÿ¥¿þÿ¥¾þÿ¦½þÿ¨¼þÿ©»þÿ©ºýÿ©ºþÿ©¹þÿª¹ýÿª¹ýÿ«¹þÿ¬¹ýÿ®¸üÿ¯¸úÿ±¶øÿ´´ôÿ¸³ðÿ»²íÿ¾²êÿÀ²èÿÁ³çÿ³åÿijäÿųãÿdzàÿɳÛÿ̳ÖÿϳÐÿгÍÿÑ´ÌÿÑ´ÍÿÑ´ÏÿгÒÿγÕÿ̲Öÿ˲×ÿʱØÿɱÚÿȱÜÿƱÝÿűÞÿƱÞÿŰÞÿİÞÿïÞÿ¯ßÿÀ®àÿ¿­àÿ¾­àÿ½¬àÿ½«àÿ½«ßÿ¾ªÝÿ¿ªÚÿÀª×ÿÀª×ÿ¿ªØÿ½ªÛÿ¹©àÿ³©äÿ¯©èÿ«¨ëÿ§§íÿ¦¨ïÿ¥©ðÿ¤ªòÿ£ªòÿ¤©ñÿ¥¨ïÿ¦§îÿ§§íÿ¨§íÿ©§íÿ¨§íÿ¨¦ìÿ¨¥ìÿ¨¥ëÿª¥êÿª¥éÿª¥éÿª¥ëÿ©¦ëÿ¨¥ëÿ¦¤ëÿ§¦ïÿŸ æÿe_‹ÿ>4Qÿ.#;ÿ%'ÿ ÿÿ%,ÿ)4ÿGCjÿsr¯ÿ“–ãÿ–™èÿ•—æÿ——æÿ™–åÿ™–äÿš–ãÿ›–âÿœ–àÿŸ–Ýÿ¢–Ùÿ¤–Öÿ¦–Õÿ¦–Ôÿ§–Óÿ¨—Óÿ¨—Óÿ©—Ôÿ©—Õÿ©—Ôÿ©—Óÿ©—Óÿª˜Óÿª˜Óÿ«˜Óÿ«™Òÿ¬˜Ñÿ«—Ñÿ«–Ðÿ¬—Îÿ­–Íÿ­–Ìÿ­–Ëÿ®–Ëÿ®–Ìÿ®•Ëÿ®•Êÿ­”Éÿ­“Èÿ¬“Èÿ¬’Çÿ«‘Æÿ«‘Åÿª�Âÿ©�Áÿ©Ž¾ÿ©�½ÿ©Œ¼ÿ¨‹¼ÿ§‹¼ÿ¦Š¼ÿ¦Š»ÿ¦‰¹ÿ¦‰·ÿ¦‰¶ÿ¦‰¶ÿ¦ˆ¶ÿ¦ˆ·ÿ¥ˆ¸ÿ¥ˆ¹ÿ¤ˆ¹ÿ¤ˆ¸ÿ¤ˆ·ÿ¤ˆ¶ÿ¥ˆ·ÿ£†¶ÿ¢…µÿ¢„¶ÿ¡ƒ¶ÿŸ‚¶ÿž€µÿž€¶ÿ�€¶ÿ›µÿ˜~µÿ—}¶ÿ–}·ÿ•|·ÿ•|·ÿ•{·ÿ•{¶ÿ•{µÿ•{µÿ”{¶ÿ•|¸ÿ•|¹ÿ•}¹ÿ–~ºÿ–~¼ÿ–½ÿ–½ÿ•¾ÿ”~Àÿ’~Áÿ�~Âÿ�~ÂÿŽ|ÂÿŒ{ÂÿŠzÃÿ‰zÃÿ‡xÃÿ†wÂÿ†wÁÿ…vÁÿ…vÁÿ…vÀÿ†vÀÿ…vÀÿ„vÀÿƒt¾ÿ„s¼ÿ„r¸ÿ„qµÿƒp³ÿƒn±ÿ‚l°ÿ�l¯ÿk«ÿ~i§ÿ~g¤ÿʾïÿ˾îÿ˾îÿ̾íÿÍ¿ìÿοìÿÍ¿íÿÌ¿íÿ˾íÿ˾íÿ̾ìÿͽëÿ̽êÿ̽ëÿ˾íÿɾïÿǽðÿŽñÿýòÿ¼óÿÁ¼ôÿ¿½÷ÿ¼¾úÿ¹¿üÿ·Àýÿ´Áþÿ±Âþÿ®Âþÿ«Âýÿ©Ãþÿ§Ãþÿ¦Âýÿ¦Áþÿ§Áþÿ§Àþÿ§¿þÿ§¾þÿ§½þÿ§¼þÿ§¼þÿ§¼ÿÿ¨»þÿ¨»þÿ¨»þÿ©»þÿªºþÿ¬ºýÿ®¹üÿ°¸úÿ³¶øÿ·µóÿº³ïÿ½³ëÿÀ³èÿÁ³çÿóåÿÄ´äÿÆ´âÿÇ´àÿɳÝÿ˳ÙÿͳÕÿϳÑÿгÎÿÑ´ÍÿÑ´ÍÿдÏÿÏ´ÑÿδÓÿÍ´Õÿ̳×ÿʲÙÿȲÜÿDzÞÿƲßÿűßÿŰÞÿİÝÿİÞÿïàÿÁ®áÿ¿­áÿ½­âÿ¼­ãÿº¬ãÿº¬âÿ»«àÿ¼ªÞÿ¼ªÜÿ¼©Üÿ¼©Üÿ»©Ýÿ¸©ßÿµ©âÿ±¨åÿ­¨éÿ©§ëÿ§§íÿ¦¨ïÿ¥©ðÿ¤ªñÿ¥©ñÿ¥¨ïÿ§¨îÿ¨¨íÿª¨ëÿª§ìÿª§ìÿ«§ëÿ¬§êÿ¬§éÿ¬¦èÿ­¦çÿ­¦èÿ­¦éÿ¬¦éÿª¦êÿ©¥êÿ©§ïÿ¡ æÿb\†ÿKAjÿ<3Vÿ""ÿ!ÿÿ#'ÿ&.ÿD>cÿpo©ÿ–—ãÿš›éÿ™™æÿš™çÿ›™æÿš™æÿ›™åÿ›˜äÿ�˜âÿ ˜Þÿ£˜Úÿ¦˜×ÿ¨˜Õÿ¨—Ôÿ©—Óÿ©—Òÿ©˜Òÿª˜Óÿ«˜Óÿ«˜Òÿ«—Ðÿ«˜Ðÿ¬˜Ðÿ¬˜Ðÿ¬˜Ðÿ¬˜Ðÿ¬˜Ñÿ«—Ñÿª—Ñÿ«—Ñÿ«—Ðÿ¬–Ïÿ¬–Îÿ¬•Íÿ¬”Ìÿ¬”Ìÿ­”Ëÿ­”Êÿ¬“Éÿ«“Éÿ«’Çÿ«‘Æÿ«‘Äÿ«�Âÿ¬�Àÿ¬�¾ÿ«Ž½ÿ©�¼ÿ¨�¼ÿ¨Œ½ÿ¨‹¼ÿ§‹»ÿ§‹¹ÿ§Š·ÿ¨Š¶ÿ©‹¶ÿ©‰µÿ©‰´ÿ¨‰µÿ§Š¶ÿ§Š¶ÿ¦‰¶ÿ¥‰¶ÿ¥‰¶ÿ¦‰¶ÿ¥‡µÿ£†µÿ¢…¶ÿ¡ƒ¶ÿž‚¶ÿ��¶ÿœ�·ÿ›€¸ÿš€¸ÿ™€¸ÿ™€¸ÿ˜¹ÿ˜¹ÿ—~¹ÿ—~¹ÿ–~¸ÿ–}¸ÿ•}¸ÿ”}¹ÿ“|¼ÿ“}½ÿ’~¾ÿ’¿ÿ’Àÿ’Àÿ‘~Àÿ�~ÂÿŽ~ÄÿŒ}Åÿ‹|ÆÿŠ|Çÿ‰|Æÿˆ{Åÿˆ{Åÿ‡zÆÿ‡yÅÿ†xÄÿ†xÄÿ…xÅÿ…xÄÿ„wÂÿ…wÂÿ…wÂÿ„wÁÿ„v¿ÿ…t¼ÿ…r¹ÿ„qµÿ‚o²ÿ�n¯ÿ€l®ÿk¯ÿ}j­ÿ|hªÿzg§ÿɾðÿʾïÿ˾îÿË¿îÿ̾íÿÌ¿íÿÌ¿îÿÌ¿îÿÌ¿îÿÌ¿îÿË¿îÿ̾íÿ̾ìÿ̾ìÿÌ¿ìÿ˾îÿȾïÿƾñÿľôÿ½õÿÁ½öÿ¿¾÷ÿ½¿úÿ»Àüÿ¹Áýÿ¶Âýÿ³Ãþÿ°Ãþÿ­ÃþÿªÄþÿ©Äþÿ¨Äþÿ§Ãýÿ§Âýÿ¨Áþÿ¨Àþÿ¨¿þÿ§¾þÿ¦¾þÿ¥½þÿ¥½þÿ¥¼ÿÿ¥¼þÿ¥¼þÿ¦¼þÿ§»þÿ©»þÿ«ºýÿ®¹üÿ±·úÿµ¶÷ÿ¸´òÿ¼´íÿÀ³èÿóåÿIJãÿƳáÿȳßÿɳÝÿË´ÚÿÌ´×ÿγÔÿϳÑÿѳÎÿÒ´ÌÿѵËÿÑ´ÌÿÑ´ÍÿдÏÿδÒÿ̳Õÿ˳ÙÿȲÝÿƲßÿƱßÿƱÞÿűÞÿŰÝÿŰÝÿİÞÿïßÿÀ®áÿ½®ãÿ»­äÿ¹¬äÿ¸«äÿ¸«äÿ¸ªãÿ¸ªâÿ¸©áÿ¸©àÿ¸©àÿ·©áÿµ¨âÿ²¨äÿ®©èÿ«¨êÿ¨§íÿ¦§ïÿ¤¨ïÿ¥©ðÿ¥©ðÿ¦¨ïÿ¨¨îÿª¨ìÿ¬¨êÿ­§éÿ®§èÿ°¨èÿ°¨çÿ°¨æÿ±¨æÿ±§åÿ°§åÿ¯§çÿ®§èÿ¬§éÿª¦êÿ«¨ïÿ£¡æÿ_Y�ÿF>bÿ91Qÿÿÿÿ%*ÿ0%?ÿHAhÿnl£ÿ˜˜äÿ��êÿœšçÿœšçÿœ™åÿ›™åÿœ™åÿœ™äÿ�˜âÿ ™àÿ£˜Ýÿ¦™Ùÿ¨™Öÿ©˜Õÿª™Ôÿª˜Ôÿª˜Óÿª˜Óÿ«˜Òÿ«˜Òÿ¬˜Ðÿ¬—Ïÿ­˜Ïÿ­˜Ðÿ­˜Ðÿ­˜Ðÿ¬˜Ðÿ«˜Ñÿ«—Ñÿ¬—Ñÿ«—Ðÿ¬–Ïÿ¬–Îÿ¬•Íÿ¬•Ìÿ¬•Ìÿ¬”Ìÿ«”Ëÿ«“Ëÿª“Êÿª’Éÿª‘Çÿ«‘Åÿ¬‘Ãÿ¬�Áÿ­�¿ÿ¬�½ÿ«Ž¼ÿªŽ»ÿ©�»ÿ©�»ÿ©Œºÿ¨Œ¹ÿ©Œ¸ÿª‹·ÿª‹¶ÿª‹µÿªŠ´ÿªŠ´ÿª‹µÿ©‹µÿ¨Šµÿ§‰¶ÿ¦‰¶ÿ¥ˆ¶ÿ¤‡µÿ£†µÿ¢…¶ÿ ƒ¶ÿ�‚·ÿ�‚·ÿœ�¹ÿš�ºÿ™€ºÿ™€»ÿ˜€»ÿ˜€ºÿ˜€»ÿ˜»ÿ˜ºÿ—ºÿ—ºÿ–»ÿ•~¼ÿ“}½ÿ’}¿ÿ‘~Àÿ�Áÿ�Âÿ�~ÄÿŽ~ÅÿŒ~ÆÿŠ}Çÿ‰}Çÿˆ|Éÿ†}Ëÿ…|Ëÿ…|Êÿ…{Êÿ…{Éÿ†zÇÿ†yÆÿ†yÇÿ†yÇÿ†yÆÿ…yÄÿ…xÃÿ…xÂÿ†wÀÿ†v½ÿ†t¼ÿ…sºÿƒr¸ÿ�pµÿn±ÿ}k®ÿ|j®ÿ{i­ÿyg«ÿwe©ÿȾòÿɾñÿÊ¿ïÿË¿ïÿË¿îÿË¿îÿË¿ïÿ˾îÿË¿ïÿË¿ðÿË¿ðÿËÀðÿÌ¿ïÿÍ¿îÿÍ¿íÿÌ¿íÿË¿íÿÊ¿ïÿÈ¿òÿÅ¿ôÿÿöÿÁ¾÷ÿ¿¿ùÿ½Àûÿ»Áýÿ¸ÂýÿµÃþÿ²Ãþÿ¯Äþÿ¬ÅþÿªÅþÿ©Äþÿ¨Ãþÿ¨Âþÿ¨Áþÿ¨Áþÿ¨Àþÿ¨¿þÿ§¿þÿ¥¿þÿ¤¿þÿ¤½ÿÿ£½þÿ£¼þÿ¤¼þÿ¥¼þÿ¦¼þÿ©»þÿ¬ºýÿ¯¸ûÿ²·øÿ¶µôÿ»´îÿ¿´éÿóåÿųáÿȳßÿʳÜÿË´ÙÿÍ´ÖÿδÓÿϳÑÿгÏÿÑ´ÍÿÒ´ËÿÒ´ÊÿÑ´ÊÿÑ´ËÿÑ´ÍÿÏ´ÐÿͳÓÿ˳ØÿɲÛÿƱÝÿƱÝÿűÝÿƱÝÿƱÜÿưÛÿưÛÿİÝÿ¯ßÿ¿®áÿ½®âÿ»­ãÿ¹¬äÿ¶«æÿ´«æÿ´ªæÿ´©äÿµ©ãÿµ©âÿµ¨âÿ´¨ãÿ²¨åÿ°¨çÿ­¨éÿª§ëÿ¨§íÿ¦§íÿ¦¨îÿ§¨îÿ¨¨íÿª¨ìÿ¬¨ëÿ®¨éÿ°¨çÿ±¨åÿ³¨äÿ´¨ãÿ´¨äÿ´©äÿ³¨äÿ²¨åÿ±¨æÿ¯§èÿ­§éÿ«¦êÿ¬©ðÿ¤¡æÿ\V{ÿ7.Fÿ/&=ÿ$%ÿÿÿ%*ÿ8/NÿLEnÿkhœÿš™ãÿ žêÿž›æÿžšæÿ�™äÿ�™äÿœ˜ãÿ�˜áÿŸ˜áÿ ™àÿ£™Ýÿ¦™Ùÿ¨™×ÿ©™Õÿ«™Ôÿ«šÔÿ«™Ôÿ«˜Óÿ«—Òÿ«—Òÿ«—Ñÿ¬—Ðÿ¬˜Ñÿ¬˜Ñÿ­˜Ðÿ­˜Ðÿ¬—Ðÿ«˜Ðÿ«˜Ðÿ¬—Ðÿ¬—Ðÿ­—Ïÿ¬—Îÿ­–Íÿ¬•Íÿ¬•Íÿ«•Ìÿ«”Ìÿª”Ìÿª“Ëÿª’Êÿª‘Èÿ«‘Çÿ¬‘Äÿ¬�Âÿ¬�Áÿ¬�¿ÿ¬�¾ÿ«�¼ÿ«�»ÿ«Ž»ÿª�»ÿª�ºÿª�¹ÿ«�¸ÿ¬Œ·ÿ¬Œµÿ¬Œ´ÿ¬Œ´ÿ«‹´ÿª‹´ÿ©Šµÿ§‰µÿ¥ˆµÿ¤‡¶ÿ£†µÿ¢†µÿ¡…¶ÿŸƒ·ÿ�‚¸ÿœ‚¹ÿ›‚»ÿš‚¼ÿ™�¼ÿ˜�½ÿ—€½ÿ—€½ÿ—€½ÿ—€½ÿ—€½ÿ—€½ÿ—�½ÿ–�½ÿ•€¾ÿ“¿ÿ“Àÿ‘Ãÿ�€ÆÿŽ�ÈÿŒ€Éÿ‹€Ëÿ‰Ìÿˆ~Íÿ‡}Íÿ…~Îÿƒ~Ðÿƒ~Ðÿ‚}Ðÿƒ}Ïÿƒ|Îÿ„|Ìÿ„{Ëÿ…zÊÿ…zÉÿ…zÈÿ…yÆÿ…xÄÿ…wÁÿ…w¿ÿ…u¼ÿ…sºÿƒq¸ÿ�q¸ÿp·ÿ}m²ÿ|j­ÿzh¬ÿxg¬ÿvf«ÿueªÿžóÿÇ¿òÿÈ¿ñÿÉ¿ðÿÉ¿ðÿÊ¿ïÿʾïÿʾïÿʾïÿÊ¿ïÿËÀðÿËÀðÿËÀðÿÌ¿ïÿÍ¿íÿοìÿοêÿÏ¿êÿÍ¿ìÿË¿îÿÈ¿ñÿÅ¿ôÿÿöÿÀÀùÿ½ÁüÿºÃýÿ·Äþÿ´Äýÿ±Åýÿ¯Åþÿ¬ÅþÿªÅþÿ©Äþÿ©Ãþÿ¨Âþÿ§Âþÿ§Áþÿ§Àþÿ§Àþÿ¦Àþÿ¥Àÿÿ£¿þÿ¢¾ýÿ¢¾ýÿ£½þÿ¤½þÿ¥¼þÿ¨¼þÿ«ºýÿ®¹ûÿ±·øÿ´µôÿ¹´ðÿ¾´ëÿ´åÿƳáÿȳÞÿË´Ûÿ̵×ÿδÔÿϳÒÿÏ´ÏÿдÎÿÑ´ÌÿÓ´ËÿÓ´ÊÿÒ´ÊÿÑ´ËÿÑ´ÍÿдÏÿγÑÿͳÕÿʲØÿȱÚÿƱÛÿŰÜÿƱÛÿƱÛÿǰÛÿȰÚÿƱÛÿİÜÿïÞÿÁ¯àÿ¿®áÿ»­ãÿ¸¬åÿµ«æÿ³«æÿ³ªäÿ´©äÿ´©äÿ´¨ãÿ´©äÿ³©åÿ²©æÿ°¨çÿ­¨èÿ«§éÿª§ëÿ©¨ëÿ©¨ëÿ«¨ëÿ¬¨ëÿ®¨éÿ°©èÿ²ªæÿ´ªäÿµªãÿ¶ªãÿ·©ãÿ¶©ãÿµ©ãÿ´©åÿ²¨æÿ°¨èÿ®¨éÿ«§êÿ¬©ïÿ£¡æÿZTyÿ:1Nÿ5-Hÿ*.ÿ"ÿÿ+"6ÿ;2RÿIBhÿhc”ÿœ™áÿ¢Ÿèÿ œäÿ ›ãÿŸ™ãÿŸ˜áÿŸ˜ßÿ ˜Þÿ¢˜Þÿ£™Ýÿ¥™Ûÿ¨™Øÿ©šÖÿªšÔÿ¬šÓÿ¬šÔÿ¬šÓÿ¬™Óÿ«˜Óÿ«˜Óÿª˜Òÿª˜Òÿ«˜Óÿ«˜Òÿ«˜Ñÿ¬—Ðÿ¬˜Ðÿ¬˜Ðÿ«˜Ðÿ¬˜Ðÿ®—Ïÿ®—Ïÿ­—Îÿ­—Íÿ­–Îÿ¬•Íÿ«•Ìÿ«•Ìÿª”Ìÿª“Ëÿ©’Ëÿ©’Êÿª‘Èÿª‘Æÿ«‘Äÿ¬�Âÿ¬�Áÿ¬�Àÿ¬�¾ÿ¬�¾ÿ«�½ÿ¬�¼ÿ¬�¼ÿ¬�»ÿ­Ž¹ÿ­Ž¸ÿ­Ž·ÿ­�¶ÿ­�¶ÿ¬Œ¶ÿª‹¶ÿ¨Šµÿ¦‰µÿ¤‡µÿ¢†¶ÿ¡…¶ÿ …¶ÿŸ„·ÿžƒ¸ÿ�‚¹ÿ›‚»ÿš‚½ÿ™‚¾ÿ—‚¾ÿ•�Àÿ•‚Àÿ•�Áÿ”�Áÿ”�Áÿ”‚Áÿ•‚Áÿ•‚Àÿ•‚Àÿ•‚Âÿ”‚Ãÿ“‚Äÿ‘‚Æÿ�ƒËÿ�ƒÎÿŠƒÏÿ‰‚Ðÿ‡�Òÿ†€Óÿ„€Ôÿƒ�Ôÿ‚�Õÿ‚€Õÿ�Ôÿ�Óÿ‚Óÿ‚~Òÿ‚|Ïÿ‚{Íÿƒ{ËÿƒzÉÿƒyÆÿ„wÄÿƒvÁÿ‚t¾ÿ�r»ÿ€p¸ÿ~n·ÿ}n¶ÿ|mµÿzk±ÿyh­ÿwfªÿueªÿsd«ÿsd¬ÿÄ¿ôÿÅ¿óÿÆ¿òÿÇ¿òÿÈ¿ñÿɾðÿɾðÿɾïÿʾîÿʾîÿË¿ïÿË¿îÿË¿ïÿËÀïÿÌÀîÿÏ¿êÿпçÿÑ¿æÿÒ¿äÿÑ¿åÿÏ¿éÿÌÀîÿÉÀñÿÅÀöÿÀÂúÿ½Äýÿ¹Æþÿ¶Æþÿ³Åþÿ±Åþÿ¯Åþÿ«Åþÿ©Åþÿ¨Åþÿ§Äþÿ¦Ãþÿ¦Âþÿ¦Áþÿ¦Áÿÿ¦Áþÿ¥Áþÿ£Áþÿ¢Àþÿ¢Àýÿ¢¿þÿ¢¾þÿ¤½þÿ§¼þÿ«»ýÿ®¹üÿ±¸ùÿ´µôÿ¹´ðÿ½´ëÿ´æÿÆ´áÿɵÝÿ˶ÛÿͶØÿεÔÿдÒÿдÏÿдÎÿÑ´ÍÿÒ´ÌÿÓ´ÊÿÒµÊÿÒµÊÿÒ´ËÿÑ´ÎÿÏ´ÐÿδÒÿ̳Õÿɲ×ÿDZÙÿƱÛÿŰÛÿƱÛÿDZÛÿDZÚÿDZÚÿƱÛÿİÝÿðÞÿÁ¯àÿ¾®âÿ»®ãÿ¹­åÿ¶«äÿ´«äÿµªäÿ´©äÿµªãÿµªãÿµ©äÿ´ªåÿ³©åÿ±©åÿ°¨æÿ®¨èÿ­©éÿ¬¨êÿ¬¨éÿ­¨éÿ¯©èÿ±ªçÿ´«æÿµ«åÿ·«äÿ¸«äÿ¸ªäÿ·ªäÿµªäÿ´ªåÿ²©æÿ±©èÿ°©éÿ­¨êÿ¬ªïÿ¢¡äÿ[U{ÿNFrÿE>eÿ)+ÿ$!ÿ#"ÿ3*Bÿ7-IÿA7Vÿha�ÿŸšßÿ¥Ÿæÿ£œàÿ£›àÿ¢šßÿ£™Þÿ£™Ýÿ¥™Üÿ¦™Úÿ¨šÙÿ©š×ÿª›Öÿ¬›Õÿ­›Ôÿ­›Òÿ®›Óÿ®›Óÿ­›Ôÿ¬šÔÿ«šÕÿªšÕÿª™Õÿª™Ôÿ«™Ôÿª˜Òÿ«˜Òÿ¬™Òÿ«™Òÿ«™Ñÿ¬˜Ðÿ­˜Ðÿ®˜Ðÿ®—Ïÿ­—Ïÿ¬—Îÿ«–Îÿ«•Íÿ«”Íÿª”Ìÿ©”Íÿ¨’Íÿ¨’Ìÿ¨’Êÿ©’Éÿ©’Çÿª‘Åÿ«‘Ãÿ«‘Áÿ«‘Áÿ¬�Áÿ¬�¿ÿ­�¾ÿ­�½ÿ­�¼ÿ®�»ÿ­�¹ÿ®�¸ÿ®�·ÿ­Ž·ÿ¬�·ÿªŒ·ÿ©‹¶ÿ¦‰¶ÿ£‡¶ÿ¡…¶ÿ „·ÿŸ„¸ÿž„¹ÿž„ºÿ�ƒ»ÿ›ƒ½ÿšƒ¾ÿ˜‚¿ÿ–‚Áÿ”‚Ãÿ”ƒÄÿ“ƒÅÿ“‚Æÿ“ƒÆÿ“„Çÿ“„Çÿ”„Çÿ”„Çÿ”„Èÿ”„Èÿ“„Éÿ‘„Ëÿ�„ÏÿŒ…ÒÿŠ„Ôÿ‰„Õÿ‡„Öÿ…„Øÿ„…Ùÿƒ…ÙÿƒƒÙÿ‚‚Øÿ��Öÿ��Öÿ‚€Öÿ�Ôÿ�}Òÿ‚|Ïÿ‚{Ìÿ‚zÉÿ‚xÆÿ�vÃÿ€sÀÿ~q½ÿ|pºÿ|n¸ÿylµÿxk³ÿxj²ÿvg¯ÿue¬ÿtd«ÿrcªÿpc¬ÿoc­ÿÄ¿öÿľôÿÅ¿óÿÅ¿óÿžóÿƾóÿǾñÿȾðÿɾïÿɾîÿÊ¿îÿË¿ïÿË¿ïÿË¿ïÿÌÀîÿÏÀìÿпèÿÒ¿äÿÔÀáÿÕ¿ßÿÔ¿áÿÑ¿æÿÍÀíÿÈÁóÿÃÂùÿ¾Åýÿ»Æþÿ¸Æþÿ¶ÅþÿµÄþÿ²Äþÿ®ÆþÿªÈþÿ¨Èþÿ¦Çþÿ¥Æýÿ¦Äþÿ¦Âþÿ¥Áþÿ¥Âþÿ¤Âþÿ£Âþÿ¡Ãþÿ ÃþÿŸÂþÿ Àþÿ¡¾þÿ¤½þÿ¨»þÿ«ºýÿ¯¸úÿ´¶õÿºµïÿ¿µêÿÄ´åÿǵßÿ˶ÜÿͶÛÿηÙÿжÖÿжÓÿѵÑÿѵÏÿÑ´ÍÿѳÌÿÑ´ËÿÒ´ÊÿÒ´ÉÿÒµÉÿÒµËÿѵÍÿдÏÿͳÒÿʳÕÿȲØÿƲÚÿűÛÿűÜÿıÜÿŰÜÿƱÛÿưÛÿŰÜÿðÝÿ¯ßÿÁ¯âÿ½®ãÿº­äÿ¸­äÿ·¬åÿµ«åÿ¶ªäÿ¶ªäÿ·«ãÿ·«ãÿ·«ãÿ·ªãÿµ©ãÿ³©äÿ²©åÿ±©çÿ°©èÿ°©èÿ°ªèÿ±©èÿ²ªçÿ³«çÿµ«æÿ·«åÿ·«äÿ·ªåÿ¶«åÿµ«æÿ³«çÿ²«èÿ±ªêÿ°©êÿ­©ëÿ¬ªîÿ ŸâÿYSxÿA8^ÿ7/Pÿÿ!ÿÿ"ÿ+!7ÿ@6Vÿia�ÿ¡›àÿ©¡æÿ¦�ßÿ¦œÜÿ¦›Ûÿ§›Úÿ¨›Úÿ©›Ùÿ«œÙÿ¬œ×ÿ­œÖÿ¯�Õÿ¯�Õÿ¯œÔÿ¯œÒÿ¯œÓÿ¯œÓÿ®œÔÿ¬œÖÿ©›×ÿ©šØÿ©š×ÿªšÖÿªšÕÿ«šÔÿ¬šÔÿ«šÔÿ«™Óÿª˜Òÿª˜Òÿ«˜Ñÿ¬˜Ñÿ«—Òÿª–Ñÿ©–Ñÿ¨•Ñÿ¨”Ñÿ¨”Ðÿ§”Ïÿ¦“Ïÿ¥‘Ïÿ¥‘Îÿ¥’Íÿ¦’Ëÿ§‘Éÿ¨’Èÿª‘Æÿ«‘Äÿ«�Ãÿ«‘Âÿ«�Áÿ¬�Àÿ­�¾ÿ­�½ÿ®�¼ÿ¯�ºÿ¯�¹ÿ®�¸ÿ®�¸ÿ­Ž¸ÿ¬�¸ÿªŒ·ÿ§Š·ÿ¥ˆ·ÿ¢‡¸ÿ …¹ÿŸ„ºÿž…»ÿ�…»ÿœ„¼ÿ�…¾ÿ›„¿ÿ™„Âÿ—„Äÿ–„Æÿ•…Èÿ“„Êÿ’„Ìÿ‘…Íÿ‘†Ïÿ‘†Ïÿ�†Ðÿ‘†Ñÿ‘‡Ñÿ‘‡Ñÿ�‡Òÿ�‡ÓÿއÕÿ�ˆÖÿ‹‡ØÿЇÙÿ‰‡Úÿˆ‡Ûÿ†‡Úÿ…†Úÿ…„ÚÿƒƒØÿƒ�Õÿ‚€Ôÿ‚€Óÿ‚~Òÿ�}Ðÿ�{Íÿ�zÊÿ€xÈÿvÅÿ~sÁÿ}q¾ÿ{oºÿzm¸ÿylµÿwi²ÿvh°ÿvg®ÿte­ÿsc«ÿrc«ÿpb«ÿnb¬ÿmb®ÿÃÀ÷ÿÿöÿÄ¿õÿÄ¿öÿÿõÿÄ¿õÿžôÿƾòÿÇ¿ñÿÈ¿ñÿÉ¿ðÿÊ¿ðÿÊ¿ðÿË¿ïÿÍÀíÿοêÿпèÿÒ¿åÿÓ¿âÿÔ¿àÿÔÀàÿÓÀãÿÑÀçÿÍÁíÿÇÂôÿÂÅûÿ½ÆþÿºÆþÿ¹Åþÿ·ÅþÿµÅþÿ²Æþÿ®Çþÿ«Èþÿ¨Çþÿ§Æþÿ¦Åþÿ¥Äþÿ¥Ãþÿ¥Ãþÿ£Âþÿ¡ÃþÿŸÄþÿŸÄþÿŸÄþÿžÂþÿ Áþÿ¢¿þÿ¥½þÿ¨»þÿ­ºüÿ±¸÷ÿ·¶òÿ¼µìÿÁµçÿǵáÿ˶ÝÿͶÚÿζÙÿÏ·ØÿзÕÿѶÒÿѵÐÿѵÎÿѵÌÿÒ´ËÿÒ³ÈÿÒ³ÇÿÑ´ÈÿÑ´ÉÿÑ´ËÿÑ´ÍÿÏ´Ðÿ̳ÓÿɳÖÿDZÙÿűÛÿŰÝÿİÞÿðÞÿİÝÿİÜÿİÜÿİÝÿİÞÿ°ßÿÀ¯áÿ½®âÿ»­ãÿ¹­äÿ·¬äÿ·«äÿ·«äÿ·¬ãÿ¸«âÿ¸«âÿ¹«áÿ¹«áÿ¸ªáÿ¶ªãÿ´ªäÿ³ªåÿ²«æÿ²«çÿ²ªèÿ²«èÿ³«èÿ´«çÿµ«æÿ¶¬æÿµ«æÿµ¬çÿ´¬èÿ²¬éÿ±«êÿ°«ëÿ¯ªëÿ­©ëÿ¬©ìÿŸœÝÿXRvÿ7,Hÿ-$<ÿÿÿÿÿ0'>ÿC9Xÿg^Šÿ¢�àÿª¢èÿ¨žáÿ¨�Ýÿ¨œÛÿ©œÚÿªœÚÿ«�Ùÿ¬�Øÿ­žØÿ¯ž×ÿ°ŸÖÿ±žÕÿ±žÕÿ°žÔÿ°�Ôÿ¯�Õÿ®�Öÿ¬œ×ÿªœØÿ©›Øÿ©›×ÿª›×ÿªœÖÿ¬›Õÿ¬›Ôÿ«šÕÿª™Ôÿ©˜Ôÿ©˜Óÿ¨—Óÿ¨—Óÿ¨–Óÿ¦•Óÿ¦•Òÿ¦”Òÿ¦”Òÿ¦”Ñÿ¥“Ñÿ¤’Ðÿ¢‘Ðÿ¢‘Ïÿ£’Îÿ¥’Ìÿ¦‘Êÿ§‘Éÿ©’Çÿª‘Åÿ«‘Äÿ«‘Ãÿ¬‘Âÿ¬‘Áÿ­‘¿ÿ®‘¾ÿ®‘¼ÿ®‘»ÿ¯�»ÿ¯�ºÿ¯�¸ÿ®�¸ÿ®Ž·ÿ¬�·ÿ©‹·ÿ¦Š¸ÿ£ˆ¹ÿ¡†ºÿŸ†»ÿž†¼ÿž†¼ÿ�…½ÿ�†¾ÿ›…Àÿ™…Âÿ˜…Åÿ—†Æÿ–†Éÿ•†Ëÿ“†Îÿ’‡Ïÿ‘‡Ñÿ�‡Òÿ�‡Óÿ�ˆÔÿ�ˆÕÿŽˆÖÿ�ˆÖÿ�ˆ×ÿ�‰ÙÿŒ‰Úÿ‹‰ÚÿЉÛÿ‰‰Ûÿˆ‰Ûÿ‡ˆÚÿ††Ùÿ†„Øÿ†‚Õÿ…�Óÿ„€Òÿ„~Ñÿ‚|Ïÿ�{Ìÿ€zÊÿxÈÿ~vÆÿ}tÂÿ|r¾ÿ{p»ÿyn¸ÿxl¶ÿwj³ÿvi±ÿug¯ÿuf­ÿtd¬ÿrd¬ÿqc«ÿoc¬ÿnb­ÿmc¯ÿÁÁùÿÂÁøÿÃÁøÿÃÀøÿÃÀ÷ÿÃÀ÷ÿÿöÿÄ¿õÿÅ¿ôÿÇ¿òÿÇ¿ñÿÇ¿ñÿÈ¿ñÿÉ¿ñÿËÀïÿÌÀìÿοéÿпçÿÒ¿åÿÒÀåÿÒÀåÿÓÀæÿÓÁæÿÐÂèÿÌÂîÿÇÄõÿÂÅûÿ¾Æýÿ»ÅþÿºÅþÿ¹Åþÿ¶Åþÿ³Æþÿ°Çþÿ­ÆþÿªÆþÿ¨Åþÿ§Åþÿ¦Äþÿ¥Äþÿ¤Äþÿ£Äþÿ¡Äþÿ Äþÿ Äþÿ Ãþÿ¡Âþÿ¢Àþÿ¤¿þÿ¨½þÿ«»ýÿ¯ºûÿ³¸÷ÿ¸·ñÿ¾¶ëÿĶåÿȶáÿ˶ÝÿÍ·ÛÿÏ·ØÿзÕÿÑ·ÒÿÒ·ÏÿÒ·ÍÿÓ·ËÿÓ¶ÈÿÓµÆÿÔ´ÅÿÓ´ÅÿѳÆÿгÈÿгËÿÏ´ÎÿδÑÿ˳ÓÿʲÖÿȲÙÿDZÚÿƱÜÿıÝÿıÝÿűÜÿŰÜÿűÜÿűÜÿıÜÿ°ÞÿÁ°ßÿ¾¯àÿ¼®âÿº­ãÿ¹­äÿ¸­ãÿ¸¬ãÿ¹¬âÿ¹«áÿ»¬àÿ»¬ßÿ»¬àÿº«áÿ¸«áÿ·«âÿ¶«äÿµ«åÿ³¬çÿ³¬èÿ³«éÿ´«èÿ´¬èÿµ¬çÿ´¬èÿ´¬èÿ³¬èÿ±«éÿ°«ëÿ¯«ëÿ®ªëÿ­ªëÿ¬©ëÿžšÙÿUOqÿ3(?ÿ0&=ÿ(.ÿ ÿÿ')ÿA8XÿNDiÿd[„ÿ£žàÿ«¤éÿ© äÿ©Ÿáÿ©žßÿ©žÝÿ«žÜÿ¬žÛÿ­žÚÿ®ŸØÿ° Øÿ² Öÿ³¡Öÿ³¡Öÿ³ Öÿ³ Õÿ²ŸÖÿ°ž×ÿ®ž×ÿ¬�Øÿ¬�×ÿ¬�×ÿ¬�Öÿ¬�Öÿ­œÕÿ­œÔÿ¬›ÔÿªšÔÿ©™Ôÿ¨˜Ôÿ§˜Ôÿ§—Óÿ§–Óÿ¦–Óÿ¦•Óÿ¥•Òÿ¥•Òÿ¥”Ñÿ¥“Ðÿ¤’Ðÿ£’Ïÿ£’Îÿ¤’Îÿ¥’Íÿ¦’Ëÿ§’Êÿ¨’Èÿ©’Çÿª’Æÿ¬’Åÿ¬’Ãÿ¬’Âÿ­’Àÿ®’¿ÿ®’½ÿ¯’¼ÿ¯’»ÿ°‘¹ÿ°�·ÿ°�¶ÿ°�¶ÿ¯�·ÿ¬Ž·ÿ¨Œ¸ÿ¦Šºÿ£ˆ»ÿ¢ˆ¼ÿ ˆ½ÿ ‡¾ÿ ‡¾ÿŸ‡¿ÿ�‡Áÿ›‡Ãÿ™‡Åÿ˜‡Æÿ˜ˆÈÿ–ˆËÿ”ˆÎÿ’ˆÐÿ�ˆÓÿމÔÿ�‰Öÿ�ˆÖÿŒˆ×ÿ‹ˆØÿ‹ˆØÿЉÙÿ‹‰Ûÿ‹ŠÜÿŠŠÛÿ‰ŠÛÿ‰ŠÜÿˆ‹ÜÿˆŠÜÿ‡‡Ûÿ‡…Ùÿ†ƒÕÿ†�Òÿ…Ðÿ„}Îÿ‚{Ìÿ€yÉÿ~xÈÿ}wÇÿ|tÄÿzq¿ÿzo¼ÿym¸ÿxl¶ÿwj³ÿvi°ÿuh¯ÿug­ÿte«ÿsd«ÿsd¬ÿqd«ÿqd¬ÿpd­ÿod¯ÿÀÂüÿÂÂúÿÃÂúÿÃÁùÿÃÁøÿÃÁøÿÃÁøÿÃÀ÷ÿÄÀõÿÅ¿ôÿÅ¿óÿÅ¿óÿÅ¿óÿÆ¿óÿÇÀóÿÉÀðÿË¿îÿοëÿÐÀêÿÏÀêÿÐÀêÿÑÁêÿÒÁèÿÑÂèÿÐÂëÿÍÃðÿÇÄöÿÂÄûÿ¿Äýÿ½Äýÿ¼ÃþÿºÃýÿ¸ÃýÿµÅþÿ²Åþÿ¯Åþÿ¬ÅþÿªÄþÿ©Äþÿ§Äýÿ¦Åþÿ¥Äÿÿ¤Ãþÿ¤Ãþÿ£Äþÿ£Ãþÿ£Áþÿ£Àþÿ¥¿þÿ¨¾þÿª½þÿ­»ýÿ±ºúÿ¶¸öÿ»¶ðÿÀ¶êÿŶäÿÉ·áÿÌ·ÝÿθÙÿѸÕÿÒ¸ÒÿÓ¸ÏÿÔ¸ÌÿÕ¸ÉÿÖ·ÇÿÖ·ÅÿÖ¶ÃÿÕµÂÿÓ´ÄÿѳÆÿгÉÿϳÌÿδÎÿÍ´ÑÿÍ´Óÿ̳Õÿʳ×ÿɳØÿdzÚÿDzÛÿDzÜÿƱÛÿƱÛÿƱÛÿűÜÿıÜÿðÝÿ°ÞÿÀ°àÿ¾¯âÿ¼®ãÿ»®âÿº­âÿº­âÿ»¬áÿ¼­àÿ½­ßÿ¾­ßÿ½­ßÿ»¬ßÿ»¬àÿ¹«âÿ·«äÿµ¬åÿ´¬çÿ´¬éÿ´¬éÿµ¬èÿµ¬çÿµ¬çÿµ¬çÿ´«çÿ³«èÿ²«éÿ±ªêÿ°ªêÿ¯ªêÿ¬¨èÿ�—ÔÿWOrÿG?bÿB:[ÿ.#7ÿ%$ÿ! ÿ4*?ÿI?bÿPDjÿeYÿ¥�Üÿ®¥çÿ¬¢äÿ¬¡ãÿ« âÿ« àÿ¬ Þÿ® Ýÿ¯ Üÿ°¡Úÿ³¢Øÿµ¢×ÿ¶£Öÿ·£Öÿ·¢Õÿ·¢Õÿ¶¢Õÿ´¡Öÿ² Öÿ°ŸÖÿ°Ÿ×ÿ¯žÖÿ¯žÕÿ¯žÕÿ¯�Ôÿ®�Ôÿ­œÔÿ¬›Ôÿ«šÔÿª™Ôÿ©™Óÿ©˜Óÿ©˜Óÿ¨—Óÿ§—Òÿ§–Ñÿ§–Ðÿ§•Ïÿ§”Ïÿ§“Ïÿ¦“Îÿ¥“Íÿ¦’Íÿ¦“Íÿ¦“Ìÿ§’Ëÿ¨“Éÿª“Èÿ«“Çÿ«’Æÿ¬“Åÿ¬“Ãÿ­’Áÿ®’Àÿ¯’¿ÿ¯’½ÿ°’»ÿ±’¹ÿ²’·ÿ²’µÿ²’µÿ²‘¶ÿ¯�·ÿ¬Ž¸ÿ©�ºÿ§‹¼ÿ¥Š½ÿ£Š¾ÿ£Š¿ÿ¢ŠÀÿ¡ŠÀÿ¡‰ÁÿŸ‰ÃÿœˆÅÿšˆÆÿ˜ˆÈÿ–ˆÌÿ“ˆÏÿ‘ˆÓÿމÕÿ�‰×ÿŒ‰Ùÿ‹ŠÚÿŠŠÛÿŠŠÛÿ‰ŠÛÿ‰ŠÛÿ‰ŠÜÿŠ‹Ýÿ‰‹Ýÿˆ‹ÞÿˆŒÞÿˆŒßÿ‡‹Þÿ‡‰Ýÿ†‡Ûÿ†„×ÿ…€Òÿ„}Îÿ‚|Ëÿ€zÉÿ~wÇÿ|vÆÿztÆÿyrÃÿwo¿ÿwm»ÿwl¸ÿvj´ÿui±ÿug®ÿuf¬ÿtf«ÿteªÿsd«ÿsd«ÿsd«ÿrd«ÿrd¬ÿqd­ÿ¾ÃýÿÀÃüÿÁÃûÿÂÂúÿÂÂúÿÃÂùÿÂÂùÿÂÂùÿÂÁøÿÂÀøÿÃÀ÷ÿÄÀöÿÄÀöÿÄ¿öÿÅ¿öÿÆÀôÿÈ¿òÿÊÀðÿÌÀîÿÎÀíÿÏÀìÿÏÁëÿÐÀêÿÑÁêÿÑÂëÿÏÂíÿÌÂñÿÈÂöÿÄÃúÿÁÃüÿ¿Âýÿ½Âýÿ»Ãýÿ¸Äýÿ¶Äýÿ´Äþÿ²Äþÿ±Äþÿ®Äþÿ«ÅþÿªÅþÿ¨Äþÿ§Ãþÿ¦Ãþÿ¥Ãþÿ¤Âþÿ¤Áþÿ¤¿þÿ¦¾þÿ¨¾ÿÿª¾þÿ¬½þÿ°»üÿ´¹÷ÿ¹·òÿ¾·íÿ÷çÿÇ·ãÿÊ·ßÿ͸Üÿй×ÿѸÔÿÓ¸ÑÿÔ¹ÎÿÖ¹Ëÿ׸Èÿ×·Åÿ×·Ãÿ×¶ÂÿÖµÂÿÔ´ÄÿÒ´ÆÿгÉÿγËÿδÏÿÍ´ÑÿÍ´ÓÿÌ´ÕÿË´×ÿÊ´ØÿɳÚÿȲÛÿDzÛÿDZÛÿƲÛÿƲÝÿűÝÿűÝÿİÞÿðßÿÁ°áÿ¾¯âÿ½¯âÿ¼®ãÿ¼®âÿ½­âÿ½®áÿ¾®ßÿÀ®ÞÿÀ®Þÿ¾­Ýÿ¾­Þÿ½­ßÿ»¬áÿ¹¬äÿ·­æÿµ­çÿµ­èÿ·­çÿ¸­æÿ¸­åÿ¸¬åÿ·¬åÿ¶¬æÿ´«çÿ³«èÿ²ªèÿ±ªèÿ­§åÿ›•Ïÿ]Tyÿ^W†ÿRLvÿ+ 1ÿ&'ÿ&'ÿ?5OÿB7SÿB4MÿgZ|ÿ¨›Óÿ³¥àÿ²¤ßÿ±£àÿ°¢áÿ¯¢àÿ¯¢ßÿ±¢Þÿ²£Ýÿ³£Ûÿ¶¤Ùÿ¸¤Øÿº¤×ÿ»¤Öÿ»¤Óÿ»¤Óÿ»¤Òÿ¹¤Óÿ·£Ôÿµ¡Õÿ´ Õÿ³ Õÿ²ŸÔÿ±žÔÿ±�Óÿ°�Óÿ¯�Óÿ®œÔÿ­›Óÿ­šÓÿ­šÒÿ¬šÒÿ¬™Òÿª˜Òÿ©—Ñÿ©–Ñÿ©–Ïÿ©–Îÿ©•Îÿ©“Íÿ¨“Íÿ§“Íÿ§“Íÿ§“Íÿ¦“Íÿ¦“Íÿ§“Ëÿ©“Éÿª“Èÿª“Èÿ«’Çÿ«’Åÿ¬’Äÿ­’Âÿ®’Àÿ¯“¾ÿ°“»ÿ²“¹ÿ³“¸ÿ³“¶ÿ´“¶ÿ³’¶ÿ±‘·ÿ¯�¸ÿ¬�ºÿªŽ¼ÿ§Œ½ÿ¦Œ¿ÿ¥ŒÀÿ¤ŒÁÿ¤ŒÁÿ¤ŒÂÿ¢‹Ãÿ ŠÅÿ�‰Çÿ™‰Êÿ•‰Îÿ“‰Òÿ‘‰ÖÿŽŠØÿŒŠÛÿ‹ŠÜÿ‹‹Ýÿ‹�Þÿ‹�ÞÿŠŒÞÿ‰‹Þÿ‰‹Þÿ‰‹Þÿ‰ŒßÿˆŒàÿ‡‹áÿ†‹áÿ…Šàÿ…ˆÞÿ„†ÛÿƒƒØÿƒÓÿ�{Íÿ~xÈÿ|vÆÿ{uÄÿytÄÿwrÄÿvpÄÿunÁÿsm¾ÿskºÿsiµÿsh±ÿrf¯ÿsf¬ÿsf«ÿse¬ÿse¬ÿsd¬ÿse«ÿsd«ÿrd«ÿrd¬ÿ¼Âüÿ¾ÃüÿÁÄüÿÂÄüÿÁÄüÿÂÃûÿÂÄûÿÂÄûÿÁÃûÿÁÂúÿÁÁúÿÂÁùÿÃÁøÿÄÀøÿÄÀ÷ÿÄÁõÿÅÀóÿÇÀòÿÊÀñÿÌÀîÿÎÀìÿÏÀêÿÑÀéÿÑÀèÿÐÁêÿÏÂìÿÎÁíÿÌÂïÿÉÂóÿÆÂöÿÂÃúÿÀÃûÿ¾Ãüÿ¼Äþÿ¹Äþÿ¸Âýÿ·ÂýÿµÂþÿ²Ãþÿ¯Ãýÿ®Äýÿ¬ÃþÿªÃþÿ©Ãýÿ¨Ãþÿ§Âþÿ¦Áýÿ¥Àþÿ¦Àþÿ§¿þÿ¨¾þÿª¾þÿ®½ýÿ²»úÿ·¹öÿ»¸òÿ¾·îÿ·èÿÆ·âÿÊ·ÝÿÍ·ÙÿϸÖÿѸÓÿÓ¹ÑÿÔ¸ÍÿÕ¸ÉÿÖ¸Æÿ×·Äÿ×·ÂÿÖ¶ÁÿÕ¶ÂÿÔ¶ÄÿÒµÇÿдÉÿͳÍÿʲÐÿʱÔÿʲ×ÿʳØÿɳÙÿɳÚÿȲÚÿDzÚÿDzÛÿdzÜÿƲÝÿƲÞÿŲÞÿűÞÿıÞÿñßÿÁ°àÿ¿¯âÿ¾¯âÿ½®ãÿ½®ãÿ¼®áÿ½®àÿ¿¯ßÿÁ®ÝÿÁ¯ÜÿÁ®ÜÿÁ®ÜÿÀ®Ýÿ¾®Þÿ¼®àÿ»®âÿ»®ãÿº®ãÿ»®ãÿ¼®ãÿ»­ãÿº­âÿ¸¬ãÿ·¬äÿµ¬åÿ´«æÿ³«çÿ®¦ãÿš’ÉÿXNpÿTKvÿJAhÿ'(ÿ#ÿ!ÿ.#4ÿ?2HÿH9PÿfWtÿ©™Éÿ·¦Øÿ·¦Ùÿ·¦Úÿ¶¥Üÿµ¥Üÿ´¥Ýÿ´¥Ýÿµ¥Üÿ·¤Ûÿ¹¥Ùÿº¦×ÿ¼§Õÿ¾§ÒÿÀ§ÐÿÀ§ÏÿÀ§Îÿ¾¦Ïÿ¼¤Ðÿº¤Ñÿ¸£Òÿ·¡Ñÿ¶¡Ñÿ¶ Ñÿ´ Ñÿ³ŸÑÿ²žÒÿ±žÒÿ°�Òÿ°�Ñÿ°œÐÿ®›Ðÿ­šÐÿ¬™Ðÿ«˜Ðÿ©—Ðÿ¨–Îÿ©–Íÿª•Ìÿ©•Ëÿ¨”Ëÿ¨“Ìÿ§“Ìÿ¦“Íÿ¥’Îÿ¦“Íÿ§“Ëÿ¨“Êÿ©“Éÿª“Èÿ©’Èÿ©’Çÿ©’Æÿª’Äÿ¬’Áÿ®’¿ÿ¯“½ÿ°“»ÿ²“ºÿ²“¹ÿ³“¸ÿ³“¸ÿ²“¸ÿ±’¹ÿ¯‘ºÿ­�¼ÿ«�½ÿ©�¾ÿ¨�Áÿ§�Ãÿ¦�Ãÿ¦�Âÿ¥ŒÃÿ£ŒÄÿ¡ŒÆÿž‹Éÿš‹Íÿ–‹Òÿ“‹Õÿ�ŒØÿŽŒÛÿ��ÝÿŒŽÞÿŒŽßÿ‹Žàÿ‹ŽàÿŠ�àÿ‰ŒáÿˆŒàÿ†Œàÿ„ŠáÿƒŠãÿ‚Šãÿ€ˆàÿ€…Ýÿ€ƒÚÿ~€Öÿ}}Òÿ|zÍÿzvÈÿytÅÿwrÄÿuqÄÿsqÅÿroÅÿqnÃÿpnÂÿok½ÿoi¸ÿpgµÿqg³ÿqf°ÿqe®ÿre­ÿrf®ÿqe®ÿqf¯ÿqe¯ÿqe®ÿpd®ÿ½Åýÿ¿ÄýÿÁÅýÿÁÅüÿÁÆüÿÁÆýÿÁÇýÿÀÇýÿÀÇüÿÁÅüÿÂÃúÿÄÂøÿÅÂöÿÆÂöÿÅÁöÿÄÁõÿÅÁôÿÆÀóÿÇÀòÿÉÁñÿËÁïÿÍÁîÿÏÁëÿÐÁéÿÑÁèÿÐÂèÿÐÁéÿÎÁêÿÌÁíÿÊÁñÿÇÂõÿÅÂöÿÃÃøÿÀÂúÿ½ÂûÿºÁüÿ¹Âýÿ¸ÂþÿµÂþÿ²Âýÿ°Ãþÿ­Ãýÿ«ÃýÿªÄýÿªÃþÿªÂþÿ©Âþÿ©Âþÿ¨Áþÿ¨Àþÿ©¿ýÿª¾þÿ¬½þÿ¯¼üÿ³»ùÿ¸¹õÿ»¸ñÿ¿¸ìÿ÷åÿǶàÿʶÝÿÌ·ÙÿηÖÿзÓÿÓ¸ÏÿÔ¸ËÿÕ¸ÈÿÖ·Æÿ×¶Äÿ×·ÃÿÖ·ÄÿÕ·ÅÿÔ¶ÆÿѵÈÿÏ´Ìÿ̲ÏÿɱÑÿDZÔÿƱ×ÿƲÙÿdzÚÿDzÚÿȲÚÿɳÚÿÉ´ÛÿȳÛÿdzÜÿdzÜÿDzÜÿƲÜÿŲÝÿıßÿ±ßÿÀ°àÿÀ¯áÿ¿¯âÿ½¯áÿ½¯áÿ¿¯àÿÁ¯Þÿ°ÜÿðÚÿįÙÿïÙÿ¯ÚÿÁ¯ÜÿÁ¯Þÿ¿¯ßÿ¿¯àÿ¿¯àÿ¿¯àÿ¾¯àÿ½®áÿ¼®áÿ»­áÿ¹­âÿ·¬ãÿµ«åÿ¯¦àÿ˜�ÃÿYOpÿH=^ÿ<2Nÿ"!ÿÿÿ%#ÿH:SÿXGeÿjYvÿ©—Âÿ¹¦Ôÿ»¨Öÿ»§×ÿ»§Øÿº¨Ùÿ¹¨Úÿ¹¨Ûÿº§Úÿ»§Øÿ½§Õÿ¿¨ÒÿÀ©Ðÿ©ÍÿÄ©ËÿÄ©ÉÿÄ©ÉÿçÊÿÁ¦Ìÿ¾¥Îÿº¤Ðÿ¹£Ñÿ¸¢Ñÿ·¢Ñÿ¶¡Ðÿµ Ñÿ´ŸÒÿ³ŸÒÿ²žÑÿ²žÑÿ±�Ñÿ°�Ðÿ¯œÐÿ®›Ðÿ­™Ðÿ«˜Ïÿ¨–Îÿ¨”Îÿ¨“Íÿ§“Ìÿ¦“Ìÿ§’Ìÿ¦’Íÿ¤’Îÿ¥’Îÿ¦’Íÿ¦“Ìÿ§“Ìÿ¨“Ëÿ¨“Êÿ¨“Èÿ¨“Çÿ¨’Æÿª’Åÿ«‘Ãÿ«’Áÿ­’¿ÿ¯’½ÿ±“¼ÿ²“»ÿ³”»ÿ´”»ÿ³•ºÿ³”ºÿ²”»ÿ°“»ÿ®’¼ÿ¬‘½ÿª�Àÿ©�Ãÿ¨�Ãÿ§�Ãÿ¦ŽÄÿ¥ŽÄÿ£�Æÿ¡�Éÿ�ŒÌÿ™ŒÏÿ–ŒÓÿ“�Öÿ‘�Ùÿ��Üÿ�ŽÞÿŒ�ßÿ‹ŽßÿŠŽáÿˆ�âÿ†�ãÿ…Œãÿƒ‹áÿ�Šáÿˆâÿ~‡âÿ}‡àÿ|„Ýÿ{‚Úÿz×ÿx|ÓÿvyÎÿvvÊÿtrÆÿrqÄÿqpÄÿppÅÿpoÅÿnnÃÿnmÂÿnk¾ÿmiºÿnh¸ÿogµÿpf³ÿpe±ÿpf¯ÿpe°ÿpe±ÿof²ÿof³ÿoe²ÿod±ÿ¿Èþÿ¿ÇþÿÀÇýÿÁÇýÿÁÇýÿÁÈþÿÁÉþÿÀÊþÿÁÉþÿÁÈýÿÂÆüÿÄÅúÿÅÄøÿÆÄ÷ÿÆÃ÷ÿÆÂöÿÆÂõÿÆÁõÿÇÁõÿÈÂôÿÉÂòÿÌÂñÿÍÂïÿÏÁìÿÐÁêÿÐÂéÿÐÁéÿÐÀéÿÏÀêÿÍÁìÿËÁîÿÊÁïÿÉÀïÿÈÀñÿÅÀóÿÂÀöÿ¿Áùÿ»Áûÿ¸ÂüÿµÂýÿ±Ãýÿ®Ãýÿ«ÄýÿªÄýÿªÄþÿ«Âþÿ«Âþÿ¬Âþÿ¬Áÿÿ«Àþÿ«Àþÿ«¿þÿ¬½þÿ®¼ýÿ±»ûÿµ¹÷ÿ¹¸ôÿ¼¸ðÿ¿·êÿöåÿǶáÿÊ·ÜÿÌ·ÙÿηÖÿзÒÿѸÎÿÓ·ÉÿÕ·ÆÿÖ·ÄÿÖ·ÄÿÖ·ÅÿÕ·ÆÿÔ·ÇÿÒ¶ÉÿдÌÿδÍÿ˲ÏÿȱÒÿưÕÿŰ×ÿƲÙÿDzÙÿɳÚÿʳÙÿʳÙÿɳÙÿɳÙÿÉ´ÙÿȳÙÿȳÙÿDzÚÿƲÛÿıÛÿñÝÿðßÿ°àÿ¿°áÿ¾°âÿ¿°áÿÁ°ßÿ°ÞÿİÛÿŰØÿƱÖÿƱÖÿƱ×ÿİÚÿïÜÿ¯ÝÿÁ¯ÝÿÁ¯ÞÿÀ¯ßÿÀ¯ßÿ¿¯ßÿ½®ßÿ¼­àÿº¬áÿ·«äÿ¯¥Ýÿ—Œ¾ÿSIfÿ8,Aÿ4(;ÿ'*ÿÿÿ ÿG:RÿXGdÿiWrÿ§”½ÿ»¦Ñÿ¿©ÓÿÀ©ÓÿÀ©ÔÿÀªÔÿ¿ªÕÿÀªÕÿÀªÔÿÁªÒÿªÏÿĪÌÿŪÉÿÇ«ÇÿÈ«ÅÿÈ«ÃÿȪÃÿǪÄÿŨÆÿçÉÿ¾¦Ìÿ¼¤Îÿ»£Ïÿ¹£Ðÿ¸¢Ïÿ¸¢Ïÿ· Ïÿµ ÏÿµŸÐÿ´žÐÿ³žÐÿ²�Ïÿ±�Ïÿ°›Ïÿ¯šÎÿ­˜Îÿª–Îÿ§”Îÿ¦“Íÿ¥’Íÿ¤‘Íÿ¤‘Íÿ£‘Îÿ¢‘Ïÿ£‘Îÿ£‘Îÿ¤’Îÿ¥’Íÿ¥’Ìÿ¦’Ëÿ§’Éÿ¨’Çÿ©’Æÿª’Åÿ«’Ãÿ«’Áÿ­’Àÿ¯’¿ÿ°“¾ÿ°“½ÿ²“¼ÿ³•¼ÿ´•»ÿµ–ºÿµ–ºÿ´–ºÿ²•»ÿ°“½ÿ­’¿ÿ«‘Âÿª‘Ãÿ©‘Ãÿ©�Ãÿ¨�Ãÿ¨�Äÿ¦�Æÿ¢ŽÈÿŸŽÌÿ›ŽÐÿ—ŽÕÿ“�Ùÿ��Üÿ�ŽÝÿŒ�ßÿ‹Žàÿ‰Žáÿ†�äÿ„Œåÿ‚‹åÿ€Šäÿˆãÿ}‡âÿ|†âÿ{…áÿy‚Þÿx€Úÿv}×ÿtzÓÿswÐÿsvÌÿqrÈÿoqÆÿooÄÿooÄÿooÅÿnnÄÿmmÂÿmk¿ÿli¼ÿmhºÿnh¹ÿng·ÿogµÿof´ÿof´ÿnf¶ÿng·ÿmf·ÿlf¶ÿle¶ÿ¾Éþÿ¿Éþÿ¿ÉþÿÀÉýÿÀÉþÿÁÊýÿÁÊþÿÁËÿÿÁÊÿÿÁÉþÿÁÈýÿÂÈýÿÃÈýÿÄÆûÿÆÅúÿÇÅøÿÇÃöÿÇÃöÿÇÃöÿÈÃöÿÉÃôÿËÂòÿÍÂðÿÏÂíÿÐÁêÿÐÂéÿÑÁçÿÑÀçÿÑÀçÿÐÀçÿÏÀèÿÎÀéÿÍ¿êÿÌÀëÿËÀîÿÈÀñÿÄÀóÿÁÀöÿ½Áùÿ¹Âüÿ´Ãýÿ°Äýÿ¬ÄýÿªÄýÿ©Äþÿ©ÃþÿªÂþÿ¬Áþÿ­Áÿÿ­Àÿÿ®¿þÿ­¿þÿ®¾þÿ¯¼ýÿ²»ûÿ³¹øÿ¶¹öÿ¹¸óÿ½·ïÿÁ·éÿÅ·äÿÈ·àÿÊ·ÝÿÌ·ÚÿÍ·ØÿÏ·ÓÿѶÍÿÒ¶ÉÿÔ·ÅÿÕ·ÃÿÕ·ÄÿÕ·ÆÿÓ·ÈÿÒ¶ÊÿѵÌÿÏ´ÍÿÍ´Ðÿ˳ÒÿɱÔÿưÖÿű×ÿƲØÿȲØÿɳØÿʳØÿɳÙÿɳÙÿȳØÿȳØÿɳ×ÿɳÖÿɳ×ÿDzØÿƲÚÿƲÜÿűÜÿñÞÿ±àÿÁ²àÿ±ßÿðÞÿİÛÿưØÿDZÕÿȱÔÿȲÔÿDZÖÿưØÿŰÙÿïÚÿ¯ÜÿÁ¯ÞÿÁ¯Þÿ¿®Ýÿ¾®Þÿ¼­àÿ¹¬áÿ·«äÿ¯¤Üÿ”‰ºÿSHeÿF;XÿA6Rÿ.!2ÿ$#ÿÿ0%4ÿD6KÿO?UÿiWpÿ§’·ÿ½¦ÍÿëÐÿÄ«ÏÿÄ«ÎÿŬÎÿŬÎÿÆ­ÎÿÆ­ÍÿÇ­ÌÿȬÉÿɬÆÿʬÄÿË­ÂÿË­ÀÿË­¾ÿˬ¾ÿË«¾ÿÉ«¿ÿÈ©ÂÿĨÅÿÁ¦Èÿ¿¥Êÿ½¤Ìÿ»£Ìÿ»£Ìÿº¢Ëÿ¹¡Ìÿ¸ Íÿ¶ŸÍÿ´žÍÿ³�Íÿ³�Íÿ²›Ìÿ°šÍÿ®˜Ìÿ¬—Íÿ©•Íÿ§“Ìÿ¥“Íÿ¤’Íÿ¢‘Îÿ¡‘Ïÿ¡‘Ïÿ¡�Ïÿ¡‘Ïÿ¢‘Ïÿ¢‘Îÿ£‘Íÿ¤‘Ëÿ¦‘Éÿ¨‘Çÿ©’Æÿª“Äÿ«’Âÿ¬’Áÿ®“Àÿ°“¾ÿ°“½ÿ°”½ÿ±“¼ÿ³”»ÿµ•ºÿ¶–ºÿ·—¹ÿ·—¹ÿµ—ºÿ²•¼ÿ°”¾ÿ®“Àÿ­“Áÿ­“Áÿ­’Àÿ­’¿ÿ­’Àÿ«’Âÿ§�Åÿ£�Éÿž�Ïÿ˜�Õÿ“ŽÚÿ�ŽÝÿŽŽßÿŒŽáÿ‰Žâÿ†ŽãÿƒŒæÿ�‹çÿ‰çÿ}ˆæÿ{‡åÿz…ãÿy„âÿx‚áÿw€Þÿv~Úÿt{ÖÿsyÓÿrvÐÿquÍÿptÊÿoqÇÿnpÅÿnoÅÿnoÅÿnoÅÿmnÄÿllÁÿlk¿ÿmj½ÿmj½ÿmj¼ÿmi»ÿmi»ÿmi»ÿmi¼ÿmi½ÿlh¼ÿkh¼ÿkh½ÿ½Èýÿ½Éþÿ¾Êþÿ¾Êþÿ¾ËýÿÀËþÿÁËýÿÁÊþÿÁËþÿÁËþÿÀËþÿÁËþÿÂÊýÿÃÈýÿÅÆüÿÇÆùÿÈÅ÷ÿÈÅöÿÉÅ÷ÿÉÄõÿÊÃôÿÌÂòÿÎÂîÿÐÂëÿÑÁçÿÓÁäÿÓÁâÿÓÀáÿÒÀâÿÑ¿ãÿÑ¿åÿÏÀèÿÍÁëÿËÁïÿÊÁñÿÉÀðÿÇÀðÿÅÀòÿÁÀõÿ½Áùÿ¸Âüÿ´Ãýÿ°Äýÿ«Äýÿ©Äþÿ¨Ãþÿ¨Ãþÿ©Âþÿ¬Áþÿ­Àþÿ®Àþÿ¯¿þÿ°¾þÿ°½ýÿ²¼üÿ³¼úÿ´»øÿ·¹õÿº¸òÿ¾¸íÿ¸éÿÅ·åÿÇ·âÿÉ·ßÿÊ·ÝÿÌ·ÙÿζÔÿжÏÿÒ¶ÉÿÔ·ÅÿÕ·ÄÿÕ·ÅÿÓ·ÇÿÒ¶ÉÿѶÊÿдÌÿÏ´ÏÿÍ´ÑÿË´ÔÿɳÖÿDzÖÿŰÔÿưÔÿDZÕÿȲ×ÿɲØÿȳÙÿdzÚÿDzÙÿdz×ÿɳÖÿʳÖÿʳÖÿÉ´×ÿɳØÿɳØÿȲ×ÿȳØÿdzÚÿŲÛÿıÛÿİÚÿŰØÿǰÖÿȱÓÿɱÒÿɱÓÿȱÔÿƱÕÿŰØÿðÚÿ¯ÛÿÁ¯Üÿ¿®Ýÿ½­ßÿº¬àÿ¸«âÿ¶«åÿ¬¢Ûÿ�…¶ÿ_TxÿaW‚ÿSInÿ- .ÿ'$ÿ''ÿA4IÿE7KÿK:Mÿp]vÿ§�°ÿ¿§ÇÿÇ­ÍÿÈ­ËÿÈ®ËÿÉ®ÊÿÊ®ÉÿÊ®ÉÿÊ®Èÿ˯ÆÿÌ®ÄÿͯÂÿͯÀÿί¾ÿή½ÿή¼ÿÏ®»ÿÏ­»ÿά¼ÿË«¾ÿɪÀÿÆ©ÃÿçÅÿÁ¦Çÿ¾¤Èÿ½£Éÿ¼£Éÿ»¢Éÿ¹ Éÿ·ŸËÿ¶žËÿ´�Ëÿ³œËÿ²›Ëÿ±šËÿ¯˜Êÿ®—Êÿ¬–Êÿª•Ëÿ§”Ìÿ¥”Íÿ¤“Ïÿ¢’Ðÿ ‘Ðÿ ‘Ðÿ¡‘Ðÿ¡‘Ðÿ¡‘Ïÿ¡‘Íÿ£�Ëÿ¤�Èÿ¦�Çÿ§‘Åÿ©’Äÿ«’Âÿ¬’Àÿ¯“¾ÿ±”½ÿ²”»ÿ²•»ÿ³”ºÿ³”¹ÿ´•¹ÿµ–¹ÿ¶—¹ÿ·—¹ÿ¶—¹ÿµ—ºÿ´–»ÿ³•»ÿ²–»ÿ²•»ÿ±•»ÿ±”»ÿ¯”½ÿ®“¿ÿª’Ãÿ¤‘Éÿž�Ïÿ—�×ÿ’�Ýÿ��áÿŒ�ãÿ‰�äÿ†Žæÿ‚Œçÿ~‹éÿ|Šéÿzˆèÿx†çÿw…åÿvƒäÿv‚âÿu€àÿuÝÿt|ÙÿszÖÿsxÒÿrvÎÿquÍÿptÌÿorÉÿnqÇÿnpÇÿmpÇÿmpÆÿmoÅÿloÅÿlnÃÿlmÂÿlmÁÿlmÁÿkmÀÿkl¿ÿlkÀÿllÁÿklÁÿklÂÿjkÃÿjlÃÿºÊýÿºÊþÿ»Êþÿ¼Êþÿ¼Êþÿ¾Ëþÿ¿Ìþÿ¿Ìýÿ¿ÌýÿÀÌþÿÁÌþÿÁËýÿÁËþÿÃÊýÿÅÈüÿÆÆùÿÇÅ÷ÿÉÅöÿÊÆöÿËÅôÿËÄóÿÌÃñÿÎÂðÿÎÂíÿÏÁéÿÒÁäÿÓÁáÿÓÀßÿÓÀßÿÓÀáÿÑÀãÿÐÁçÿÎÁêÿÌÁíÿËÁðÿÉÁðÿÇÁòÿÅÁóÿÃÁõÿ¿Á÷ÿ½Áúÿ¹Âüÿ¶Âýÿ³Âýÿ°Âýÿ®Áþÿ¬ÁýÿªÁþÿ«Àþÿ«Àþÿ­¿ýÿ®¾þÿ°¾þÿ°½ýÿ±¾ýÿ²¾üÿ´½ûÿ´¼úÿµ»øÿ¸ºôÿ¼¸ðÿÀ·êÿ÷æÿƸâÿÉ·ßÿÉ·Ûÿ˶×ÿͶÔÿ϶ÏÿÑ·ÊÿÒ¶ÈÿÒ¶ÇÿÓ·ÇÿÓ¶ÈÿÒµÈÿѶÉÿеÌÿδÏÿÌ´ÒÿÊ´ÕÿÉ´ÖÿȳÖÿDZÖÿưÕÿưÕÿDZ×ÿdzÙÿdzÚÿƲÚÿƲÚÿDzÚÿɳØÿʳÖÿÊ´ÕÿʳÖÿÊ´ÕÿË´ÓÿʳÓÿɳÔÿDzÕÿƱ×ÿű×ÿű×ÿƱÖÿDZÕÿȱÕÿȱÔÿȱÔÿƱÕÿűÖÿİÙÿðÛÿ¯ÜÿÀ®Ýÿ½­ßÿ¹¬áÿ¶«ãÿ´«æÿª¡ÛÿŒƒ³ÿXOpÿVKqÿJ?_ÿ*(ÿ% ÿ#ÿ**ÿ8*7ÿL;Kÿp\rÿ¥�©ÿÀ¦ÄÿÊ®ÊÿË®Éÿ˯Èÿ˯Èÿ˯Çÿ̯ÇÿͰÆÿͰÄÿͯÃÿΰÁÿϰ¿ÿа½ÿа¼ÿѰ¼ÿѰ»ÿÒ°»ÿѯ»ÿϯ»ÿή¼ÿË«ÀÿÈ©ÃÿħÅÿÁ¦Æÿ¿¥Èÿ¾¤Çÿ¼£Çÿº¡Çÿ¹ŸÇÿ¸ŸÈÿ¶žÉÿ´œÉÿ³›Éÿ²šÉÿ°šÉÿ¯˜Èÿ®˜Éÿ­—Êÿª•Ëÿ§”Ìÿ¥“Îÿ£’Ðÿ ‘ÐÿŸ‘ÐÿŸ�Ðÿ �Ïÿ �Îÿ �Íÿ¡�Ìÿ¡�Êÿ¢�Èÿ¤�Æÿ§�Äÿ©‘Ãÿ«’Àÿ¯”¾ÿ±”»ÿ³•ºÿµ•¸ÿ¶•·ÿ¶–¶ÿµ•¶ÿµ•¶ÿ¶•·ÿ·–·ÿ¸—·ÿ¸—¶ÿ·—·ÿ·—¶ÿ¶–¶ÿµ–¶ÿ´•·ÿ³•¹ÿ±•»ÿ®”¾ÿª’Âÿ¥’Éÿž‘Ñÿ—‘Úÿ‘‘àÿ�’äÿ‰‘çÿ…�èÿ‚�éÿŒêÿ|‹êÿzŠêÿyˆéÿw†çÿv„åÿuƒäÿu�áÿt€Þÿt~Ûÿt|×ÿszÔÿrwÐÿrvÍÿquÌÿosËÿnrÉÿnqÉÿnqÉÿmqÉÿmqÈÿmqÈÿlqÉÿlpÈÿlpÆÿmoÅÿmoÅÿlnÄÿknÃÿknÄÿjnÅÿjnÅÿinÆÿinÇÿinÇÿºËþÿ»Ëþÿ»Ìþÿ»Ìþÿ¼Ìþÿ¾Íþÿ¾Íþÿ¾Íþÿ¾Íþÿ¿Ìþÿ¿ËþÿÀËþÿÀËÿÿÁÊþÿÃÈýÿÄÇüÿÆÆúÿÈÆøÿÉÅöÿÉÄõÿÊÅôÿËÄòÿÍÃñÿÎÃðÿÏÃîÿÏÃìÿÐÂéÿÑÁçÿÑÁåÿÑÁäÿÑÀäÿÐÁåÿÏÁèÿÎÁêÿÌÁíÿËÀïÿÉÁðÿÇÁñÿÅÀòÿÂÀõÿ¿Áøÿ½ÂüÿºÂýÿ¸Âýÿ¶Âýÿ´Áýÿ²Àþÿ¯Àþÿ¬Àþÿª¿þÿ«¿þÿ¬¾þÿ®½þÿ°½ýÿ°¾ýÿ²¾ýÿ³¾ýÿ´¾üÿ´½ûÿµ¼ùÿ¶ºöÿ¸¹óÿ»¸ðÿ¿·ëÿ÷åÿÆ·àÿÉ·ÝÿË·ÛÿÍ·ØÿÏ·ÔÿзÏÿÒ·ËÿÒ·ÈÿÓ·ÇÿÓ¶ÇÿÒ·ÈÿѶËÿеÍÿεÐÿ̵ÓÿÊ´×ÿÉ´ØÿȳØÿDzØÿDz×ÿŰÖÿŰÖÿƱÖÿDzÖÿdz×ÿdzÙÿȲÙÿȲØÿȳ×ÿȲ×ÿȳÖÿÊ´ÔÿÊ´ÒÿʳÒÿɲÓÿDZÖÿűØÿűÚÿƱÙÿƲØÿƲØÿƱ×ÿƱ×ÿűØÿűÙÿİÙÿðÚÿ¯ÜÿÀ®Þÿ½¬àÿ¹¬áÿ¶«âÿ´«åÿ© Ùÿ‰€®ÿTIhÿJ?]ÿA6Nÿ)&ÿ!ÿÿ%ÿG6BÿXDSÿjUgÿ£‹£ÿÁ§Áÿ˯ÉÿË®Èÿ̯Çÿ̰Çÿ̰Çÿ̰Çÿ̰Çÿ̰Æÿ̰ÅÿΰÄÿϱÂÿбÀÿб¿ÿѱ¾ÿÒ°½ÿÒ°½ÿÒ±¼ÿÒ±»ÿѰ¼ÿЯ½ÿÍ­¿ÿÉ«ÁÿÆ©ÃÿçÄÿÀ¥Åÿ¾¤Åÿ¾£Äÿ½¢Ãÿ¼ Ãÿ¹ŸÄÿ·�Åÿ´›Æÿ³›Çÿ±™Èÿ°˜Èÿ®˜Êÿ¬—Ëÿª•Ëÿ¨”Ìÿ¦“Îÿ£’Îÿ¡‘Ïÿ ‘Ðÿ �ÐÿŸ�ÏÿŸ�Îÿ �Ìÿ¡�Êÿ¢�Èÿ£�Çÿ¤�Åÿ¦�Ãÿ¨�Àÿ«‘¾ÿ®’»ÿ²“¸ÿµ•¶ÿ·–´ÿ¸–²ÿ¹—±ÿ¹—±ÿ¹—±ÿ¹—±ÿº—±ÿ»˜±ÿ»™±ÿ¼™°ÿ¼˜±ÿº—±ÿ·–²ÿ¶–´ÿ´•¶ÿ±”ºÿ®“¾ÿª’Ãÿ¥’Êÿž‘Óÿ–‘Üÿ�’âÿ‹’èÿ‡‘ëÿƒ�ìÿ€�íÿ}�ìÿ{ŒìÿyŠëÿxˆéÿv†èÿv…çÿuƒåÿt�âÿtÞÿt~Ûÿs|ØÿszÔÿrwÑÿqvÏÿpuÍÿosÌÿnrËÿmqËÿmqËÿlrËÿmrÊÿmqÉÿlpÉÿlpÉÿlpÈÿmpÈÿloÇÿkoÇÿjoÇÿjoÈÿjoÈÿioÊÿioËÿhoËÿhoËÿ¾Ìþÿ½Íþÿ¼Íþÿ¼Îþÿ¼Îþÿ¼Îþÿ½Îþÿ¾Îþÿ¾Îþÿ¾Íþÿ¾Ìþÿ¿Ìþÿ¿ÊÿÿÀÉþÿÁÈþÿÂÇýÿÄÆûÿÆÆùÿÈÆ÷ÿÉÅöÿÉÅõÿËÅóÿÍÄñÿÎÄðÿÏÄïÿÏÄîÿÐÄíÿÐÃëÿÑÂèÿÑÁæÿÑÁæÿÐÁæÿÐÁçÿÏÁéÿÍÁëÿÌÁíÿËÁîÿÉÀïÿÆÀñÿÃÁôÿÀÁ÷ÿ½Âûÿ»Ãýÿ¸Ãýÿ·Âýÿ¶Âþÿ´Áþÿ±Àþÿ®Àþÿ«¿þÿª¿þÿª¾þÿ¬½þÿ®½þÿ¯¾ýÿ²¾ýÿ´¾ýÿ´¾üÿ´¾úÿµ½úÿµ»øÿµº÷ÿ·¹öÿº¸òÿ¾¸ìÿøæÿǸáÿʸßÿÌ·ÝÿÍ·ÚÿÏ·ÔÿзÏÿÒ¸ËÿÓ·ÇÿÓ·ÆÿÓ·ÆÿÓ·ÈÿѶËÿеÍÿεÐÿÌ´Ôÿʵ×ÿɵÙÿÈ´ÚÿÈ´ÚÿƲØÿŰ×ÿİÕÿŰÔÿűÕÿű×ÿűØÿƱÚÿűÚÿűÚÿűÚÿƳØÿȳ×ÿȳÖÿȲÕÿDzÖÿƱÙÿűÚÿűÛÿƲÚÿƲÙÿƲÙÿƲÙÿŲÙÿűÙÿűÙÿİÚÿïÛÿÁ®Ýÿ¾­Þÿ»¬ßÿ¸¬áÿ¶¬äÿª¡×ÿ‡}©ÿOD_ÿ=1Gÿ9,?ÿ,)ÿ!ÿÿ ÿL:GÿcN\ÿr[kÿ¢‰žÿ§¾ÿ̱Èÿ̰Çÿ̰Çÿ̰Çÿ̰Éÿ̱Êÿ˰Ëÿ˰Ìÿ˰Ëÿ̱ÉÿͱÇÿαÆÿαÄÿϱÃÿбÁÿбÀÿѲ¿ÿÒ±¾ÿÒ±½ÿÒ±¼ÿа»ÿή¼ÿ̬½ÿÈ©¿ÿħÁÿÃ¥ÁÿÂ¥ÀÿÁ£¿ÿÁ¢¿ÿ¾¡ÀÿºŸÁÿ·�Ãÿ´›Åÿ²šÇÿ°™Èÿ®˜Êÿ­—Ëÿ«–Ëÿª•Ëÿ¨”Ìÿ¦”Ìÿ¥“Íÿ£’Îÿ¡‘Îÿ �Íÿ �Ìÿ¡�Êÿ¢�Çÿ£�Æÿ¥�Ãÿ¦�Àÿ©�¾ÿ«�ºÿ­�·ÿ°‘µÿ³’²ÿ¶”°ÿ¸•®ÿ»–®ÿ¼—­ÿ¼˜­ÿ¼˜­ÿ¼˜­ÿ½™­ÿ½š­ÿ½š®ÿ½™¯ÿ¼˜°ÿº—²ÿµ•³ÿ²”µÿ°”¹ÿ¬’¾ÿ¨‘Ãÿ¤‘ÊÿŸ‘Ðÿ™�×ÿ“‘ÞÿŽ’ãÿ‰’éÿ…‘ìÿ€�îÿ~�ïÿ{ŽïÿzŒîÿxŠíÿwˆìÿv‡êÿu†êÿt„çÿs‚åÿs€áÿr~Þÿr|Úÿqz×ÿqxÔÿpwÒÿouÑÿntÐÿmtÎÿlsÎÿlrÍÿlrÍÿmrÌÿlpÊÿkpÊÿkpÊÿkpÊÿlpÊÿkpÊÿjpÊÿjqËÿjqËÿjqÌÿiqÎÿirÏÿhqÏÿiqÎÿÀÏþÿÀÏþÿÀÏþÿ¾Ïþÿ¼Ïþÿ¼Ïþÿ¼Ïþÿ¼Ïþÿ½Ïþÿ½Ïþÿ¾Îþÿ¾Íþÿ¿ËþÿÀÊþÿÂÉýÿÃÈýÿÅÇûÿÆÆùÿÈÇøÿÉÆ÷ÿÉÆõÿËÆôÿÍÅòÿÎÅïÿÏÄîÿÐÄíÿÑÄìÿÒÄêÿÒÄèÿÓÃæÿÒÂæÿÑÂæÿÑÂçÿÐÂéÿÏÁêÿÍÂëÿÌÁìÿÊÁíÿÈÀïÿÆÁòÿÂÁõÿ¾Âùÿ»Ãüÿ·ÄýÿµÃþÿ´Ãþÿ³Âþÿ²Áþÿ°Àþÿ­Àþÿ«¿þÿª¾þÿª¾þÿ¬¾þÿ­¾ýÿ°½ýÿ±½üÿ²½ûÿ³½úÿµ½ùÿ¶¼øÿµ»øÿµ»÷ÿ·ºõÿº¹ñÿ¿¸ëÿøåÿƸâÿɸßÿË·Üÿ͸ØÿϸÔÿѸÐÿÒ¸ÌÿÓ¸ÇÿÔ·ÆÿÓ·ÆÿÒ·ÇÿÒ·ÉÿѶÌÿ϶ÎÿͶÒÿ˶×ÿɵÚÿȵÛÿÈ´ÛÿƳÚÿıØÿïÖÿïÕÿïÕÿîÖÿï×ÿðÙÿïÚÿ°Üÿ±ÜÿıÜÿŲÛÿƲÙÿƲÙÿűÙÿıÚÿıÛÿIJÜÿŲÛÿƲÙÿƳØÿƳ×ÿDZ×ÿDZ×ÿű×ÿİÙÿïÛÿÁ¯Üÿ¾­Ýÿ¼­Þÿ»®âÿ®¡Ôÿˆ{¤ÿTGaÿM>WÿF7Lÿ0".ÿ% ÿÿ&ÿH7CÿdO]ÿ}etÿ¥‹œÿĨ»ÿβÆÿβÅÿͱÆÿͱÈÿ̱Ëÿ˲ÎÿʱÐÿɱÑÿʰÐÿʱÏÿ˱Íÿ˱Ìÿ˱Ìÿ̱ÊÿͱÇÿαÅÿϲÃÿвÁÿб¿ÿѱ¼ÿÒ°ºÿѰ¹ÿÏ®¸ÿ̬ºÿʪ¼ÿȨ½ÿǧ½ÿÆ¥¼ÿŤ»ÿã»ÿÀ¢½ÿ¼Ÿ¿ÿ·�Âÿ´œÅÿ²›Çÿ°šÈÿ¯™Éÿ®˜Éÿ­—Éÿ¬–Éÿ«–Éÿª•Éÿ§”Éÿ¦“Éÿ¥’Éÿ¤‘Èÿ¤�Çÿ¤�Äÿ¥�Âÿ¦�¾ÿ©�ºÿ¬�·ÿ¯�´ÿ±‘°ÿ´‘®ÿ¶’«ÿ·”©ÿ¹”©ÿ»–©ÿ¼—ªÿ¼—«ÿ»˜«ÿ¼˜­ÿ½™®ÿ»™¯ÿº™±ÿ¹˜³ÿ·—¶ÿµ•·ÿ¯“¹ÿ«‘¼ÿ¦�Áÿ¢�Æÿ�ŽÌÿ™ŽÒÿ•Ž×ÿ‘�ÛÿŽ�àÿŠ�äÿ†�éÿ��ìÿ~�ïÿ|�ðÿzŽðÿxŒïÿv‹ïÿu‰îÿtˆìÿs†ëÿs„éÿr‚çÿq€äÿp~áÿo|ÝÿozÚÿoxØÿnxÖÿmvÕÿmuÔÿluÒÿltÑÿlsÐÿlsÎÿmrÍÿlqÍÿlrÌÿlrËÿkrÌÿkrÍÿkrÍÿkrÎÿkrÎÿksÎÿkrÐÿisÑÿisÓÿitÓÿisÓÿÀÑþÿÀÐþÿÁÐþÿÁÐþÿÀÐþÿ¿Ðþÿ¾Ïþÿ¼Ïþÿ»Ïþÿ»Îþÿ¼Ïþÿ½Îþÿ¿ÎþÿÁÍýÿÃÌþÿÄÊüÿÇÈúÿÈÇøÿÈÆøÿÈÇøÿÈÇøÿÊÇ÷ÿÌÆôÿÎÆðÿÏÅîÿÑÄìÿÒÅêÿÔÄèÿÔÄæÿÕÄäÿÔÃäÿÔÃåÿÓÃæÿÒÃçÿÑÂéÿÏÃêÿÍÂëÿÌÂëÿËÁëÿÉÀíÿÆÀñÿÁÁöÿ½Âûÿ¸ÃýÿµÃýÿ²Ãýÿ±Ãþÿ±Âþÿ¯Áþÿ­Àþÿ«¿þÿª¿þÿª¾þÿª¾ÿÿª¾þÿ¬¼þÿ­¼þÿ®¼üÿ°¼ûÿ³¼úÿ´¼ùÿ´¼øÿµ»÷ÿ¶ºöÿ¸¹óÿ»¹ïÿ¾¹ìÿ¹èÿƸäÿɸàÿ˹Üÿ͸Ùÿϸ×ÿиÓÿѹÎÿÒ¸ÊÿÓ¸ÈÿÓ¸ÇÿÓ¸ÇÿÓ¸ÈÿѶËÿжÎÿζÓÿ˶ØÿɶÛÿǵÜÿÆ´ÜÿųÛÿIJÙÿı×ÿïÕÿ­ÓÿÁ­Óÿ¯ÕÿïØÿÁ¯ÛÿÀ¯ÜÿÀ°ÞÿÁ±Þÿ±Þÿ±Ýÿ±ÝÿñÝÿñÝÿñßÿIJÞÿŲÛÿƲØÿƳÖÿȲÔÿȲÓÿDZÔÿűÖÿİÙÿðÚÿ¯ÙÿÁ¯ÙÿÁ¯Üÿ²¡Íÿ‹z�ÿhXtÿq_€ÿ`Okÿ3$0ÿ'#ÿ&ÿ6%0ÿF4?ÿ[FRÿ{erÿ¨Ž�ÿŪºÿгÃÿвÂÿϳÃÿβÇÿͳËÿ̲Îÿ˲ÑÿɲÒÿɱÓÿʲÓÿʲÒÿʲÒÿʱÑÿʲÐÿʱÎÿ̱ËÿͱÈÿβÅÿϱÁÿб¾ÿѰ»ÿѰ¹ÿѰ¸ÿÏ®¸ÿÏ­¹ÿͬ¹ÿ̪¹ÿ˨¸ÿʧ·ÿȦ¶ÿƤ·ÿ¢ºÿ½ ¾ÿ¹žÁÿ¶�ÄÿµœÆÿ³›Æÿ²šÇÿ±šÇÿ°™Çÿ°˜Æÿ¯—Åÿ­—Äÿ­–Äÿ­•Ãÿ¬”Áÿ«’¿ÿª‘½ÿª�¼ÿª�¸ÿ¬�µÿ°�²ÿ²�®ÿµ�«ÿ·‘¨ÿ¸“¦ÿ¹”¥ÿº•¥ÿ»•¦ÿ»–¨ÿ¹–ªÿ¸–­ÿ¸–²ÿ·–µÿ´•·ÿ²•¹ÿ±”»ÿ°”¼ÿ­“½ÿ¨�Àÿ¢ŽÄÿœ�Éÿ–ŒÎÿ‘‹ÓÿŽŒØÿŒŒÛÿŠŒÝÿ‡Œàÿ„�åÿ�Žéÿ}ŽìÿzŽïÿyŽðÿx�ñÿv‹ïÿuŠïÿs‰îÿr†íÿq„êÿqƒéÿp�èÿoæÿn~âÿn|ßÿmzÜÿmyÚÿlxØÿlw×ÿlvÕÿluÓÿltÒÿmtÑÿmtÐÿltÐÿmtÏÿmtÏÿmtÎÿltÏÿmtÐÿltÐÿltÐÿlsÑÿktÒÿjtÓÿitÔÿiuÕÿiu×ÿhvØÿ¹Ïþÿ»Ðþÿ½Ðþÿ¿ÑþÿÁÐÿÿÁÑþÿÁÐþÿÀÐþÿ¾Ïÿÿ¼Ïþÿ»Ïþÿ»Ïþÿ½ÏþÿÀÎþÿÁÍþÿÃËþÿÅÉüÿÆÈûÿÇÇùÿÆÆùÿÆÇùÿÈÇøÿÊÆõÿÍÆóÿÎÆðÿÑÅìÿÓÅéÿÔÄåÿÕÄâÿÖÄáÿÖÃáÿÖÃâÿÕÃãÿÓÃæÿÑÃéÿÏÃëÿÎÃëÿÎÂêÿÎÁêÿÌÀêÿÊÁìÿÆÀñÿÁÁ÷ÿ¼Âüÿ·Ãýÿ³Äþÿ¯Äþÿ­Ãþÿ¬Âþÿ«Áÿÿ«ÁþÿªÀþÿ©¿þÿ©¿þÿ©¾þÿª¼ýÿ«»ýÿ¬ºüÿ­ºûÿ°ºúÿ²»ùÿ´¼øÿ¶»÷ÿ·»õÿ¸ºôÿ¹ºóÿ»ºòÿ¾ºïÿÁ¹êÿŹåÿɹáÿʹÞÿ˹Üÿ͹Úÿι×ÿиÔÿÒ¹ÐÿÓ¸ÌÿÓ¸ÉÿÒ¸ÈÿÓ¶ÈÿÑ·ÌÿÏ·ÐÿÍ·ÕÿʶÚÿǵÜÿÆ´ÝÿųÞÿijÝÿIJÜÿñÛÿ°ÚÿÁ®×ÿ¿¬Öÿ¿®Øÿ¿®Ûÿ¿®Üÿ¾¯Þÿ¿°àÿ¿°âÿ¿°ãÿ¿±âÿÁ²àÿòÞÿIJÞÿijßÿIJÞÿIJÛÿƲ×ÿȳÓÿɳÑÿɲÑÿȲÓÿDzÔÿDzÔÿƱÔÿưÕÿƱÖÿ·¢Åÿ�z–ÿyh„ÿ�mŒÿhVnÿ2#-ÿ($ÿ)#ÿ2#+ÿD2<ÿXCNÿs\hÿ�ƒ’ÿç·ÿѳÂÿвÁÿгÁÿϲÃÿβÇÿͳËÿ̳Îÿ˲ÐÿʱÒÿʲÓÿʲÓÿʲÒÿʲÑÿʱÏÿ˱Íÿ̱Ìÿ̱ËÿͱÊÿͰÇÿΰÃÿΰ¿ÿϰ¼ÿЯ»ÿЮ¹ÿЮ¹ÿÏ­¹ÿά¸ÿΫ¶ÿͪ´ÿÌ©³ÿ˨³ÿɦ´ÿÆ¥¶ÿ¢ºÿ¿¡½ÿ¼ŸÀÿ¹�Âÿ·�Âÿ¶œÃÿµ›Ãÿ´šÂÿ´šÁÿ´š¿ÿµ™¾ÿµ˜¼ÿ´—ºÿ´–·ÿ´•´ÿ³”²ÿ²’°ÿ²�®ÿ´�«ÿ¶�¨ÿ·�¥ÿ¸’¤ÿ¹“£ÿº”£ÿº”£ÿ¹”¤ÿ¹”§ÿ¸•¬ÿ·–±ÿ´–¶ÿ²”¹ÿ®”¼ÿ«’½ÿ©�¾ÿ§�Àÿ¥�Âÿ¡�ÄÿœŒÇÿ–‹Ëÿ�‰Ðÿ‹‰ÖÿˆŠÚÿ†‹Ýÿ…‹àÿ„Œãÿ‚�æÿ�êÿ|�ìÿy�ïÿwŒðÿvŠïÿu‰îÿr‡îÿp†íÿp…ìÿpƒêÿp‚éÿo�èÿnæÿo~âÿn|Þÿm{ÜÿmyÙÿnxØÿnxÖÿnwÔÿnvÓÿnvÓÿnvÓÿnvÓÿnuÓÿnuÑÿmuÑÿmuÑÿmuÑÿltÑÿkuÒÿkuÓÿkuÔÿjuÕÿkvÖÿjv×ÿiu×ÿiu×ÿhuØÿ½Îþÿ½Ïþÿ½Ðþÿ½Ïþÿ½Ïþÿ¾Ïþÿ¿ÏþÿÀÏþÿÀÏþÿ¿Ïþÿ¾Ïþÿ¾Ïþÿ¿Ïþÿ¿Íþÿ¿Ëþÿ¿ÊýÿÀÈüÿÁÆûÿÁÄúÿÁÃùÿÃÄøÿÅÄöÿÈÄôÿËÄñÿÍÃïÿÏÄìÿÒÄéÿÔÄæÿÕÄãÿÕÄáÿÖÄàÿÖÄáÿÖÄáÿÕÄãÿÔÄåÿÒÃæÿÑÃçÿÑÂçÿÐÂçÿÏÁçÿÎÁçÿÌÀéÿÈÀìÿÃÀñÿ¾Áöÿ¹Âúÿ´Ãýÿ¯Ãþÿ¬Âÿÿ«Áÿÿ©Àþÿ©Àþÿ¨Àþÿ§¿þÿ§¾ÿÿ§½þÿ¨¼þÿª»ýÿ¬ºûÿ®¹ùÿ±ºøÿ³ºöÿ¶¹õÿ¸¹óÿ¹¹òÿº¹òÿ¼¹òÿ¾ºðÿÀºìÿùèÿŹäÿȹâÿɹàÿʹÞÿ˸Üÿ̹Úÿθ×ÿиÓÿÑ·ÎÿÑ·ÊÿÒ·ÈÿÒ·ÈÿÑ·ËÿζÐÿ˵ÕÿɵÙÿÇ´Ýÿųßÿóßÿóßÿ²àÿÀ²àÿ¿°ßÿ¾¯Þÿ½®Ýÿ¼­Þÿ½®Þÿ¾¯ßÿ¿°àÿ¾±áÿ¾°âÿ¾°âÿÀ±ßÿñÜÿŲÙÿƳØÿƲØÿƲÖÿȲÔÿɳÑÿʳÐÿʲÑÿɲÑÿɲÑÿȳÐÿȲÐÿɲÏÿʲÐÿº£¿ÿ‹vŒÿkYnÿvbxÿbOaÿ,%ÿ%ÿ"ÿ&ÿJ8AÿbLWÿu\iÿ …”ÿĨ¸ÿгÃÿвÁÿвÀÿвÁÿϲÄÿγÇÿͲÉÿ̲Ëÿ˲ÍÿʲÐÿʲÑÿʲÐÿ˱Îÿ˱Êÿ̱Éÿ̱Èÿ˱Êÿ˰Ëÿ̰Ëÿ˰Éÿ̯Æÿ̯ÃÿÍ®¿ÿÍ®¼ÿέ»ÿά¹ÿά¶ÿΫ´ÿΪ³ÿΪ²ÿÍ©±ÿ̨±ÿ˧±ÿɦ³ÿƤ¶ÿã¹ÿÀ¡»ÿ¾Ÿ¼ÿ¼ž½ÿ»ž½ÿº�¼ÿº�ºÿºœ¹ÿ»›¸ÿ»›¶ÿºš´ÿ»š²ÿ»™¯ÿ»™¬ÿº—ªÿº–¨ÿ»•§ÿ»•¥ÿ»”£ÿ»•£ÿ»•£ÿ»•£ÿ»•¤ÿº–¥ÿº—¨ÿ¸—®ÿµ–µÿ±•ºÿ®”¾ÿª’Àÿ¦�Âÿ£ŽÄÿŸŒÇÿ›‹Éÿ—ŠËÿ’‰ÎÿŒˆÑÿ‡‡Õÿ„‡Ùÿ‚ˆÝÿ�‰ßÿ�‰áÿ�‹ãÿ‹çÿ|‹êÿz‹ìÿx‹íÿuŠîÿsˆíÿr‡íÿp†íÿo…íÿo„ìÿoƒêÿp‚èÿp€æÿoãÿo~àÿp|Üÿp{ÚÿpzØÿpy×ÿpyÖÿpxÕÿoxÔÿowÕÿowÕÿowÔÿnvÔÿnvÓÿmvÔÿlvÕÿmvÕÿlvÕÿlvÖÿlv×ÿkv×ÿkvØÿjvØÿjvØÿjvØÿivØÿivÙÿÃÏþÿÂÏþÿÁÏþÿÀÏþÿ¾Ïþÿ½Ïþÿ¾Ðþÿ¿Ïþÿ¿ÏþÿÀÏþÿÀÏþÿÀÏþÿÀÏþÿ¿Îþÿ¿Ìþÿ¿Éýÿ¿Çüÿ¾Æüÿ¾ÄûÿÀÃúÿÂÂöÿÅÁóÿÈÁïÿËÀëÿÌÀèÿÍÀèÿÏÁæÿÐÁåÿÑÁäÿÓÂâÿÓÂàÿÓÂàÿÔÃàÿÕÃàÿÕÄàÿÔÃàÿÕÃáÿÔÃâÿÓÃäÿÒÂäÿÑÂäÿÐÁäÿÎÀåÿÊ¿çÿÇ¿ëÿÄÀïÿÀÁóÿ»Á÷ÿ¶Áúÿ±Àüÿ­ÀýÿªÀþÿ§¿þÿ¤¾þÿ¡¾þÿŸ½þÿŸ¼þÿ »ýÿ£ºüÿ§¹ûÿ¬¹ùÿ±¹öÿµ¹óÿ¸¸ñÿ»¸ðÿº¹ðÿ»¹ðÿ½¹ïÿ¿¹íÿÀ¹êÿùæÿŹäÿǹâÿǸàÿȸÞÿɸÝÿ˸ÚÿÌ·×ÿηÓÿзÍÿÑ·ÈÿÒ·ÆÿÒ·ÇÿжÊÿεÍÿ̵ÑÿÉ´×ÿÆ´ÛÿóÞÿ³ßÿÁ³áÿÀ²áÿ¿²áÿ¿±àÿ¾¯àÿ½®ßÿ½­Ýÿ¾¯Þÿ¿°Þÿ¿°Þÿ¿°ßÿ¾°àÿ¿°ßÿÁ°ÛÿıØÿűÖÿƲÖÿƲÕÿDzÓÿȳÒÿɳÑÿɲÑÿɲÑÿȲÑÿȲÑÿɲÏÿʲÍÿ̳Íÿ¼£»ÿˆs…ÿSCOÿSBOÿF6Bÿ#ÿ ÿÿÿ:,3ÿQ>GÿhR]ÿ™€�ÿÁ§·ÿϳÃÿϲÁÿϲÀÿϲÁÿβÃÿβÅÿβÅÿͲÆÿ̲Éÿ˲ËÿʲÍÿʱÌÿ̱Ëÿ̱Èÿ̱Çÿ˱ÇÿʰÉÿɯÌÿɯÌÿȯÌÿɯËÿÊ®ÇÿÊ®ÂÿÊ®¿ÿ̬¼ÿͬ¸ÿÍ«µÿͪ²ÿÍ©°ÿÍ©°ÿÍ©¯ÿÍ©¯ÿͨ®ÿ̧®ÿ˦¯ÿÉ¥±ÿÆ£³ÿâ´ÿÁ¡µÿ¡µÿÁ ´ÿÀ ³ÿÀŸ±ÿÀž°ÿ¿�¯ÿ¿�¯ÿÀ�®ÿÀ�¬ÿÀœ©ÿ¿›¦ÿ¿š¥ÿ¿š¥ÿ¾™¤ÿ½˜£ÿ½˜£ÿ½—£ÿ¼–¤ÿ»—¥ÿ»—§ÿº˜«ÿ·—±ÿ³–¸ÿ®”¾ÿ©’Áÿ¤�Äÿ¡ŽÆÿ�ŒÈÿ˜ŠÊÿ“ˆÌÿ�†Íÿ‹…Ïÿ‡„Ñÿƒ„Óÿ€„×ÿ~…Úÿ}†Ýÿ}‡àÿ|ˆäÿz‰èÿy‰êÿw‰ëÿv‰ìÿuˆìÿrˆìÿp†ìÿp…ìÿo„ìÿoƒêÿo‚çÿp€åÿpâÿqàÿq~Þÿr}Üÿr}Úÿr|Ùÿr|Øÿr{Øÿq{Øÿpz×ÿpz×ÿpy×ÿox×ÿnxÖÿnxÕÿmwÖÿmx×ÿlx×ÿlx×ÿlwØÿlwØÿkxØÿkwÙÿkwÙÿjwÚÿjwÚÿiwÛÿiwÛÿÅÑýÿÅÑþÿÅÐþÿÄÐþÿÂÑþÿÁÐþÿÀÑþÿÀÐþÿ¿Ïþÿ¿ÏýÿÀÏþÿÀÏþÿÀÎþÿÀÍþÿÁËýÿÀÉüÿÀÇüÿÀÇûÿÁÆúÿÃÅùÿÅÃõÿÈÁðÿË¿êÿ˾äÿ˼âÿ˼âÿʼâÿ˼âÿ̽âÿξâÿξàÿÏ¿ßÿÑÀÞÿÓÁßÿÔÂÞÿÔÂÝÿÕÃÝÿÕÃÞÿÔÃßÿÓÂáÿÒÁáÿÑÁâÿÏÀâÿοâÿ̾ãÿ˾åÿȾèÿžëÿÁ¾ðÿ¼¾õÿ·¾øÿ±¾úÿ«¾üÿ¥¾ýÿ ¾þÿ›½ýÿ—¼þÿ—»þÿ™¹ýÿ�¸ýÿ£¸üÿ©¸ùÿ¯·õÿ´·ñÿ¸·ïÿ¹·îÿ¹¸ïÿº¸ïÿ¼¸ïÿ¾¸ëÿÀ¹èÿ¹åÿĸãÿÅ·áÿÆ·ÞÿÇ·ÝÿÈ·ÛÿÉ·ÙÿʶÖÿ͵Ñÿ϶ËÿжÇÿѶÆÿжÆÿϵÇÿεÊÿÌ´ÏÿȳÕÿŲÙÿòÜÿÁ²ÞÿÁ²ÞÿÁ±ÞÿÀ°ÞÿÀ°Þÿ¿¯Þÿ¾®Ýÿ½­Üÿ¾®Ûÿ¿¯Úÿ¿¯Üÿ¾°ßÿ¾°ßÿ¿°ÞÿÀ¯ÜÿÁ°Úÿ°Ùÿİ×ÿűÔÿDZÒÿȱÑÿȱÐÿDZÐÿǰÑÿưÒÿDZÐÿȱÏÿʲÏÿº¢¼ÿ„p‚ÿ@2;ÿ ÿ ÿÿÿÿÿÿ)ÿNQÿI>ZÿhaŒÿZRwÿ+(ÿ&"ÿ$ÿÿXMhÿob…ÿ[LiÿTE_ÿ�}¦ÿ¦’¾ÿ©’¹ÿª‘µÿ«�³ÿ«�³ÿ¬�³ÿ«‘´ÿª’µÿª’·ÿª‘¹ÿª‘¹ÿ«‘¸ÿ¬’·ÿ¬‘µÿ«’´ÿ«’´ÿ¬“³ÿ­’±ÿ­‘®ÿ®‘«ÿ¯�¨ÿ¯�¦ÿ¯�¥ÿ¯�¤ÿ°�£ÿ°�¡ÿ°Ž ÿ°� ÿ±�¡ÿ±�¡ÿ±� ÿ²�Ÿÿ³�Ÿÿ³�Ÿÿ³�Ÿÿ³�Ÿÿ´�Ÿÿ³�Ÿÿ´‘Ÿÿ´‘Ÿÿµ’žÿµ’�ÿµ‘�ÿ¶‘�ÿ¶’œÿ¶’�ÿ¶’�ÿ¶’žÿ¶‘žÿµ‘žÿ´‘žÿµ‘žÿ·“¡ÿ·•¡ÿ¸•¡ÿ¸•¢ÿ¸•¢ÿ·•¢ÿ·•¤ÿµ”§ÿ¯“±ÿ¥‘¿ÿ›�Ìÿ”�Õÿ��Ùÿ‹�ÝÿˆŽàÿ†Œàÿ„‹ßÿ‚ŠÝÿ‚ˆÚÿ‚†Öÿ�…Óÿ�ƒÑÿ�‚Ðÿ€‚Ðÿ�Ïÿ}Íÿ|~Ìÿ||Êÿ|zÇÿ|yÆÿ}yÄÿ}xÁÿ~wÀÿ€wÀÿ€xÀÿ�yÀÿ€zÁÿ€zÄÿ{Æÿ~{Çÿ|{Éÿ}|Êÿ{|Ìÿy}Ïÿy}Ñÿy~Òÿx~Ñÿx}Ïÿy}Îÿz}Íÿ{}Ëÿ||Éÿ|Çÿ€{Åÿ�{Äÿ�{Äÿ�{Æÿ€|Èÿ~}Êÿ}~Ìÿ}~Îÿ}~Îÿ|~Îÿ}~Íÿ}~Íÿ}~ËÿÚËÙÿÚÊÚÿÙÊÜÿÙÊÞÿØÊÞÿ×ÉÞÿ×ÉÞÿÖÇÞÿÖÇßÿÕÇàÿÓÅßÿÓÄÝÿÓÄÝÿÓÄÞÿÒÅßÿÑÅßÿÒÅàÿÑÅáÿÐÄâÿÎÃäÿËÃèÿÈÂëÿÆÁìÿÆÀìÿÆ¿êÿǾèÿǾæÿȽãÿɽáÿ̽ÞÿξÛÿÏ¿Ùÿп×ÿѾÖÿÒÀÕÿÓÂÓÿÕÂÓÿÕÂÔÿÕÂÔÿÔÁÕÿÓÁÕÿÓÁ×ÿÒÀØÿÒ¿ÙÿѾÚÿϾÚÿνÙÿͼÙÿͼØÿÌ»Öÿ̺Ôÿ˸ÒÿÊ·ÒÿɶÓÿǵÓÿÅ´ÔÿųÔÿųÓÿųÒÿÄ´Ôÿô×ÿôØÿ³×ÿÁ²ØÿÀ²Ùÿ½±Ûÿ¼°Ýÿ»¯Ýÿ»°Þÿ»°Þÿ¼°Üÿ¿°ÛÿÁ°ØÿÁ°Õÿ°ÒÿðÏÿïÌÿ®ÊÿÁ®ËÿÀ®ÌÿÀ­Íÿ¿¬Îÿ½«Ïÿ»ªÎÿº¨Íÿ¸§Ìÿ·¦Ìÿ¶¥Ìÿµ£Ëÿ³¡Çÿ³ŸÃÿ³žÀÿ³�¾ÿ³�½ÿ³œ½ÿ²œ¾ÿ²›½ÿ²›¼ÿ²š»ÿ²š¹ÿ²›¹ÿ²š¸ÿ²™¶ÿ±˜µÿ°—³ÿ°–±ÿ²–±ÿ²—°ÿ³—°ÿ´—¯ÿ´˜­ÿ³—¬ÿ³–¬ÿ±•­ÿ®“­ÿ«�®ÿ«‘¯ÿª“³ÿ�|›ÿG9LÿOEdÿNEcÿ?5Kÿ,+ÿ'$ÿ$ ÿ ÿ2(6ÿOD_ÿ`SwÿSGcÿˆ}¬ÿ¡’Æÿ¥’Áÿ§‘¼ÿ¨‘ºÿ©�·ÿ©�µÿ©�µÿ©�·ÿ¨‘¹ÿ¨‘ºÿ¨‘»ÿ©‘»ÿª’¹ÿª�¶ÿ©�µÿª‘µÿ«‘´ÿ«‘²ÿ¬�¯ÿ­�«ÿ®�©ÿ®�¨ÿ®�§ÿ®�¦ÿ®�¥ÿ®�¤ÿ®�£ÿ¯Ž¢ÿ¯Ž¡ÿ¯Ž ÿ°Ž ÿ±Ž ÿ±ŽŸÿ±Žžÿ±Žžÿ²Žžÿ²�žÿ³��ÿ³��ÿ³�œÿ´�œÿ´�œÿµ‘›ÿ¶‘›ÿ¶’œÿµ’œÿµ’›ÿ¶’œÿµ’œÿµ’�ÿµ‘�ÿµ‘�ÿµ‘žÿµ“Ÿÿ¶“ ÿ¶“¡ÿ¶“¡ÿ·”¢ÿ·”¢ÿ¶”£ÿ´“¦ÿ¯’®ÿ¥�¼ÿœ�Èÿ•ŽÐÿ��Ôÿ��Öÿ‹�Øÿ‰ŒØÿ‡ŠØÿ‡ˆÕÿ‡†Òÿ‡…Íÿˆ‚Éÿˆ�ÆÿˆÃÿˆ~Àÿ†|¿ÿ„{¾ÿƒz¾ÿ‚y¼ÿ‚x»ÿƒw¹ÿƒv·ÿ„v´ÿ†u±ÿ‡v¯ÿˆv®ÿˆv¬ÿˆv¬ÿ‡v®ÿ…v±ÿƒwµÿ‚w¹ÿ€x½ÿ~yÁÿ}zÄÿ|{Èÿ{|Êÿ{|Êÿ||Éÿ}{Çÿ~zÅÿ€zÃÿ‚zÁÿ„zÀÿ…z¿ÿ…z¾ÿ…{¿ÿ…{Àÿƒ{Áÿƒ|Âÿ‚|Ãÿ‚|Äÿ‚{Ãÿƒ{Âÿƒ{Áÿƒ{¿ÿÜÌÙÿÜÌÙÿÜËÙÿÛËÚÿÛËÚÿÛËÛÿÚËÛÿÙÊÛÿÙÉÛÿØÈÜÿ×ÈÛÿ×ÇÚÿÖÆÛÿÕÇÜÿÔÇÝÿÔÆÞÿÔÆÞÿÓÅÞÿÓÅÞÿÒÅßÿÑÄßÿÏÃßÿÍÁáÿËÀâÿʾâÿȽâÿǼáÿƺàÿŹßÿƺÞÿÈ»ÝÿʼÛÿË»×ÿ̺ÔÿÍ»ÓÿϼÒÿнÒÿѾÓÿÑ¿ÔÿÑ¿ÖÿÑ¿ÖÿÐÀ×ÿпØÿпÙÿпÙÿϾÚÿνÛÿͽÛÿͼÛÿÌ»Ùÿ˹ÖÿɸÔÿÈ·ÓÿǶÓÿÅ´ÓÿijÓÿòÔÿòÔÿòÔÿ²Öÿ³ØÿÁ²ØÿÁ±×ÿÀ°Õÿ¾¯Õÿ½¯Öÿ¼®×ÿ»­Øÿ»­Øÿº­Øÿ¹­Øÿº¬Úÿ»­Úÿ¼­Ùÿ½®Öÿ¿­Ôÿ¿­Ïÿ¿­Íÿ¾¬Íÿ¾¬Íÿ½ªÌÿ¼ªÍÿ»©Îÿº§Íÿ¹§Ìÿ¸¦Íÿ·¦Îÿ¶¥Îÿ¶¤Ëÿµ¡Æÿµ¡Ãÿµ¡Âÿ´ Áÿ´ŸÂÿ´ŸÂÿ³ŸÁÿ´žÁÿ´�¿ÿ³�½ÿ³�»ÿ´�ºÿ´�¹ÿ³œ¹ÿ³›¹ÿ²›¸ÿ²™¶ÿ±˜µÿ±—³ÿ±–°ÿ±–°ÿ²—®ÿ²–­ÿ²•¬ÿ°•¬ÿ­’¬ÿª�­ÿ«’¯ÿª“´ÿ�|œÿI;QÿSIlÿog•ÿaZ�ÿ9-Aÿ)(ÿ$!ÿ ÿI?Wÿh\ÿoa‡ÿ_Rrÿ‰�µÿŸ•Ïÿ¢•Ìÿ£”Èÿ¥“Ãÿ¦“Àÿ§’½ÿ¨’»ÿ¨‘¼ÿ§’¾ÿ§’¾ÿ§’¾ÿ¨’½ÿ©‘ºÿ¨‘¸ÿ¨‘·ÿ¨‘·ÿ©‘·ÿª�´ÿ«�°ÿ­�¬ÿ­�ªÿ­�©ÿ­�¨ÿ­�¨ÿ­�§ÿ­�¦ÿ®Ž¦ÿ®�¤ÿ®�¢ÿ®�¡ÿ¯�Ÿÿ°�Ÿÿ°�žÿ°��ÿ°�œÿ°�œÿ±Žœÿ²Ž›ÿ²Žšÿ²�šÿ²�šÿ³�šÿ³�šÿµ�šÿµ�šÿ´‘šÿ´‘šÿµ‘šÿ´‘›ÿµ‘›ÿµ‘›ÿ´‘œÿ³�œÿ´‘œÿ³�œÿ³��ÿ´‘Ÿÿ¶’¡ÿ¶“¡ÿ¶“¡ÿ¶“¢ÿ´“¥ÿ°‘«ÿª‘²ÿ¦�ºÿ �Áÿ™�Çÿ”‹Ëÿ’ŠÌÿ�‰ÌÿއËÿ�…ÈÿŽ„ÄÿŽ‚¿ÿŽ�»ÿ�€¸ÿ�~µÿŽ|²ÿ�{±ÿ‹y±ÿŠx°ÿ‰w¯ÿ‰w®ÿˆu¬ÿˆu©ÿ‰t§ÿŠt¥ÿŠt£ÿŠsŸÿ‹sœÿ‹r›ÿŠrœÿŠsžÿˆs¢ÿ†s¨ÿ„t­ÿ‚u³ÿ€v¸ÿx¼ÿ�y¿ÿ‚z¿ÿƒ{¿ÿ…{¾ÿ†z¼ÿ‡{ºÿˆz¸ÿ‰yµÿŠy´ÿŠz³ÿŠy³ÿ‹y²ÿ‹z²ÿ‹{²ÿŒ{³ÿ�{²ÿ�z°ÿ�z¯ÿ�z®ÿÜÌÙÿÝÌÙÿÝÍØÿÝÌØÿÝÌ×ÿÞÍ×ÿÝÍØÿÝÌØÿÜËØÿÛÊ×ÿÛÊ×ÿÚÊØÿÙÉÙÿØÉÛÿ×ÊÝÿ×ÉÞÿÖÈÞÿÖÈÞÿÖÈÞÿÖÇÝÿÖÆÛÿÕÆÛÿÔÅÛÿÓÄÛÿÒÂÛÿÐÂÛÿοÛÿ˾ÛÿɼÛÿÇ»ÝÿÆ»ÞÿƺÜÿǹÙÿɹÕÿʹÓÿ˹Ðÿ˹Ïÿ˹Ñÿ˹ÓÿʹÔÿɹÔÿɹÕÿʺÖÿʺÕÿʺÕÿ˺ÖÿÌ»×ÿË»ØÿʺØÿʺ×ÿɹ×ÿȸÖÿÇ·ÕÿƶÔÿŵÔÿóÔÿóÕÿ³ÖÿÁ²ÖÿÀ±×ÿÀ°×ÿ¿°×ÿ¾¯Öÿ¾®Õÿ¼­Õÿ»­Öÿº¬Öÿº«Õÿº«Óÿº«Ñÿ¸ªÑÿ¸ªÔÿ·©Öÿ¶©Öÿ¸ªÖÿ¹ªÕÿºªÒÿºªÐÿ»ªÏÿ»ªÎÿº¨Ìÿ¹¨Ìÿ¸§Îÿ¸§Ïÿ·¦Îÿ·¦Ïÿ¶¦Ðÿµ¥Ïÿ´£Ìÿ³¢Éÿ´¢Çÿ´¢Çÿ´£Çÿ´¢Çÿ³¡Æÿ³ Åÿ³ Æÿ³ Æÿ²ŸÅÿ²žÂÿ²žÀÿ²ž¾ÿ³�¾ÿ²œ¾ÿ²œ½ÿ±›»ÿ±šºÿ°™·ÿ°˜µÿ°˜´ÿ±˜²ÿ±—°ÿ±—¯ÿ°–¯ÿ®”¯ÿ­•°ÿ®–²ÿ«•´ÿ�}šÿRD\ÿsi‘ÿx©ÿha‹ÿ=1Fÿ**ÿ,,ÿ#ÿVMkÿwk“ÿwi�ÿeWxÿ‰�µÿ�—Óÿ ™Õÿ¡—Ñÿ¤—Ìÿ¥–Êÿ¦–Éÿ¥•Èÿ¦•Çÿ¦•Çÿ§•Åÿ§”Áÿ§“¾ÿ¨’»ÿ¨‘¹ÿ¨‘·ÿ¨‘·ÿ©‘µÿª�³ÿª�¯ÿ¬�¬ÿ­�ªÿ­�©ÿ­Ž¨ÿ­Ž§ÿ¬Ž¦ÿ¬Ž¥ÿ­�¤ÿ­�£ÿ®�¡ÿ®�Ÿÿ®�žÿ¯��ÿ¯Ž�ÿ¯��ÿ¯Œ›ÿ°Œ›ÿ°�›ÿ°�šÿ°�™ÿ±�™ÿ±�™ÿ±Žšÿ±Žšÿ³Žšÿ³�šÿ³�™ÿ³�™ÿ³�™ÿ´�šÿ´�šÿ´�›ÿ´�›ÿ³�›ÿ³�›ÿ²�›ÿ±Ž›ÿ±Žœÿ²��ÿ³�žÿ´‘Ÿÿ´‘ ÿ³‘ ÿ³‘¡ÿ²’¤ÿ°’¨ÿ­‘­ÿ©�³ÿ¤�¸ÿžŒ¼ÿšŠ½ÿ˜ˆ¾ÿ–…¼ÿ“„ºÿ“ƒ·ÿ”‚´ÿ”�±ÿ”€®ÿ”~«ÿ’|©ÿ�z¨ÿŽx§ÿ�w¥ÿ�v¤ÿŒu¢ÿ‹t ÿ‹sžÿŒs�ÿŒsšÿŒs˜ÿŒr•ÿŒq“ÿŒq’ÿ‹p‘ÿ‹o“ÿŠp–ÿˆqœÿ†r£ÿ…s©ÿ…u®ÿ†w±ÿ‰x²ÿ‹z²ÿ�|±ÿ�|¯ÿ�|­ÿ’|ªÿ“{§ÿ’z¤ÿ’y£ÿ’y¢ÿ“y¢ÿ“y¢ÿ”z¢ÿ•{¢ÿ–{£ÿ–{¢ÿ•{¡ÿ–{¡ÿÚÊÚÿÜÌÙÿÝÌØÿÝÌ×ÿÝÌÖÿÞÌÕÿßÍÕÿÞÍÖÿÝÌÕÿÝËÕÿÜËÔÿÛÊÕÿÚÊÖÿÚÊÙÿØÊÜÿØÊÝÿØÊÞÿ×ÊÞÿ×ÉÝÿ×ÉÛÿ×ÈÚÿ×ÈÚÿ×ÈÚÿØÈÚÿ×ÇÙÿ×ÇÙÿÕÅØÿÓÄØÿÑÃÚÿÎÀÛÿ˾ÝÿɽÝÿɼÛÿÊ»ÙÿË»ÖÿʺÒÿɸÐÿÈ·ÑÿÇ·ÒÿƶÒÿĵÓÿÄ´ÔÿÄ´ÕÿõÔÿÄ´ÓÿƵÑÿƶÑÿƶÒÿƶÒÿŶÔÿŶÕÿĵÖÿôÖÿôÖÿôÖÿ³Õÿ³ÖÿÁ³×ÿÀ±Øÿ¾°Ùÿ¾°Øÿ½¯×ÿ¼¯Öÿ»®×ÿº®Ùÿ¸­Ùÿ¶¬Ùÿ¶«Øÿ·ªÔÿ¸©Ðÿ·©Ïÿ·¨Ñÿµ§Óÿ³§Ôÿ´§Õÿ´¨Õÿµ¨Õÿ¶§Òÿ¶¨Ðÿ·¨Ïÿ¶§Îÿµ¦Íÿµ¦Îÿ¶¦Ðÿµ¦Ñÿ³¥Ñÿ³¥Óÿ²¤Òÿ°¢Ðÿ°¢Ðÿ°¢Ðÿ±£Ðÿ²¤Ïÿ²£Íÿ°¢Íÿ°¡Ìÿ¯¢Ïÿ¯¢Ñÿ®¡Ñÿ¯ Ìÿ¯žÇÿ±žÄÿ±žÄÿ±žÄÿ°�Âÿ°œÀÿ±œÀÿ±œ¾ÿ°›¼ÿ±›»ÿ²›ºÿ²›¸ÿ²›·ÿ²š¶ÿ²š¶ÿ²š·ÿ±›¹ÿ­˜·ÿ�}™ÿSE[ÿ|p—ÿqh‘ÿRJkÿ4);ÿ+)ÿ4'6ÿ(&ÿJA[ÿh]�ÿl`ƒÿ[Mjÿƒz©ÿœ”Ïÿ¢›Ùÿ¢šÕÿ¤šÑÿ¤™Ðÿ¤™Ñÿ¤™Òÿ¤™Òÿ¤˜Ñÿ¦—Êÿ§–Äÿ¨”¿ÿ©“¼ÿ©’¸ÿ©‘µÿ©‘³ÿª‘±ÿ«�®ÿ«�¬ÿ«�ªÿ¬�©ÿ¬Ž§ÿ¬Ž¥ÿ¬Ž¤ÿ¬�£ÿ¬�¡ÿ¬ŒŸÿ¬Œžÿ­‹žÿ­‹œÿ­Œœÿ®Œœÿ¯�œÿ¯�›ÿ®Œšÿ¯Œšÿ¯Œšÿ®Œ™ÿ®Œšÿ°Œšÿ°�šÿ°�šÿ°�šÿ²�›ÿ²Žšÿ²Žšÿ²�™ÿ²�™ÿ²�šÿ²�›ÿ³�›ÿ³�›ÿ²�›ÿ²�›ÿ²�›ÿ±Žšÿ°�šÿ¯�šÿ¯�›ÿ°�œÿ°Žœÿ°Žœÿ°�žÿ²�Ÿÿ²‘ ÿ²‘¡ÿ²‘¤ÿ°�§ÿ«�¬ÿ§Ž®ÿ¤‹¯ÿ ‰°ÿœ‡±ÿ›…±ÿ™„°ÿ™ƒ®ÿ˜‚«ÿ˜�ªÿ–~§ÿ“{¥ÿ‘y£ÿ�w ÿŽvžÿŽuœÿ�s™ÿŒr˜ÿŒr–ÿ�s•ÿ�s”ÿ�r“ÿ�q’ÿ�q‘ÿŒp�ÿŒo�ÿŒo�ÿ‹p‘ÿ‹q—ÿŒsœÿ‹t ÿŒv£ÿ�w¤ÿ�x¤ÿ“{¤ÿ–|¢ÿ™~ ÿ›�ÿœ~šÿœ}˜ÿ›|–ÿ›|–ÿ›|—ÿ›|—ÿœ|—ÿ�}˜ÿ�}šÿ�}šÿœ}šÿ�}›ÿ×ÉÜÿØÉÚÿÚÊØÿÛÊÖÿÜËÖÿÜËÕÿÝËÕÿÝÌÔÿÞÌÔÿÝËÔÿÛÊÓÿÚÉÔÿÛÊÕÿÚËØÿÙÊÛÿØÊÜÿØÉÜÿ×ÉÜÿ×ÈÛÿÖÈÛÿÖÇÛÿÖÇÛÿÖÈÜÿÖÈÜÿÖÈÛÿÖÈÚÿÖÇÙÿÖÇÚÿÕÆÛÿÔÅÚÿÓÅÚÿÒÃÛÿÐÂÜÿÎÁÜÿοÚÿ̽×ÿË»ÖÿʺÕÿʺÔÿɹÔÿǸÕÿƸÖÿĶØÿµØÿµÕÿ³Óÿ³ÑÿÁ³ÑÿÁ²ÓÿÁ²ÕÿÀ²Öÿ¿±Öÿ¾±×ÿ¾±×ÿ¿±Øÿ¿±×ÿÀ±×ÿ¿²Ùÿ¾²Ûÿ½±Üÿ½±Ûÿ¼°Úÿ»¯Úÿº¯Üÿ¹¯Þÿ¶¯ßÿµ®ßÿ´¬Ýÿ³ªÚÿµª×ÿµ©Õÿµ¨Öÿ´¨Öÿ´¨×ÿ³¨Öÿ²§Öÿ±§Öÿ±§Õÿ±¦Ôÿ±¦Ôÿ±¦Ôÿ²¦Ñÿ²¦Ñÿ²¦Òÿ±¦Ôÿ¯¥Öÿ¯¦Øÿ®¥Øÿ®¥Øÿ®¥Øÿ®¥Ùÿ®¥Øÿ­¤Öÿ­£Öÿ­¤×ÿ¬¤Øÿ«¤Ûÿ«¤Ýÿ«¤Ûÿ¬¢Õÿ®ŸÎÿ°ŸÊÿ± Êÿ±¡Ëÿ° Êÿ¯ŸÈÿ¯žÈÿ¯žÇÿ±žÅÿ±žÅÿ²ŸÄÿ³ŸÃÿ³žÂÿ³ŸÀÿ³ŸÀÿ³žÀÿ³žÁÿ­™½ÿŽ|šÿC4EÿSE]ÿOAWÿ;/@ÿ)(ÿ+(ÿ5(6ÿ)'ÿ))ÿ?3HÿNA\ÿC5Kÿwn•ÿš�Äÿ¦›Öÿ¤›Õÿ¤›Óÿ£šÒÿ£šÓÿ£šÕÿ£šÖÿ£šÔÿ¦˜Íÿ¨—Æÿ©–Àÿª”»ÿª“¶ÿ«’²ÿ«’¯ÿ«‘¬ÿ¬�ªÿ¬Ž¨ÿ«Ž¦ÿ«�¥ÿ«Œ£ÿ«Œ¢ÿ«Œ ÿ«‹žÿ«Š�ÿ«Šœÿ«Š›ÿ¬Š™ÿ«‰™ÿ¬‰™ÿ­Ššÿ­Ššÿ®‹™ÿ®‹šÿ­‹šÿ­‹šÿ­‹šÿ­‹šÿ­‹šÿ®‹šÿ®Œšÿ¯Œšÿ¯Œšÿ¯Œšÿ°�šÿ±�šÿ±Ž™ÿ±Žšÿ°�›ÿ°�›ÿ±Ž›ÿ±Ž›ÿ±Ž›ÿ±�›ÿ±�šÿ°Žšÿ¯Œšÿ®Œ™ÿ®Œ™ÿ®‹˜ÿ­‹˜ÿ®‹šÿ¯�›ÿ°Ž�ÿ±�žÿ²�Ÿÿ³‘ ÿ²‘ ÿ±‘¢ÿ¯�¤ÿ¬Ž¦ÿ§Œ¨ÿ¤‰ªÿ¡‡«ÿŸ†«ÿ�…ªÿ�„©ÿš‚§ÿ˜¥ÿ•|£ÿ‘z ÿ�w�ÿŽu›ÿ�s™ÿ‹r—ÿ‹r•ÿŒr”ÿ�r“ÿ�q’ÿ�q‘ÿŽq‘ÿŽq‘ÿŽq�ÿ�q�ÿ‘s�ÿ’t‘ÿ’u“ÿ‘v•ÿ‘v˜ÿ‘w™ÿ’xšÿ•z›ÿ™|œÿœ~›ÿŸ€šÿ �˜ÿ¡�–ÿ£‚•ÿ£‚•ÿ£�”ÿ£�•ÿ£�•ÿ£�•ÿ£�–ÿ¢‚—ÿ¢‚˜ÿ¢‚˜ÿØÉÚÿ×ÇÚÿ×ÇÙÿØÇ×ÿÙÈÖÿÙÈÕÿÚÉÔÿÚÊÔÿÛÊÓÿÛÊÒÿÛÊÓÿÛÊÔÿÛÊÔÿÚÊÖÿÙÊÙÿØÊÛÿ×ÉÜÿ×ÉÝÿÖÈÝÿÕÈÞÿÔÈßÿÔÈàÿÔÈáÿÔÉâÿÔÈáÿÔÇÝÿÔÆÜÿÔÆÛÿÔÅÚÿÔÄÚÿÔÄÙÿÓÄÚÿÓÄÚÿÒÃÚÿÒÂÚÿÑÂÙÿÎÀÙÿ̾Øÿ˼ØÿɺÙÿǺÚÿƺÛÿŹÜÿĸÜÿĸÚÿÄ·ØÿµÖÿÁ´ÖÿÀ³×ÿ¿²Øÿ¿³Ùÿ¾³Úÿ¾²Ûÿ½²Üÿ½³Üÿ½²Ûÿ¼±Ûÿ¼²Ýÿ¼²ßÿ¼²ßÿ¼³ßÿ»²àÿº²áÿ¹±áÿ·±áÿ¶°áÿµ°âÿ³¯âÿ²­áÿ²­âÿ²¬àÿ²«Þÿ³«Üÿ´«Ûÿ´ªÙÿ²©Ùÿ°¨Úÿ¯¨Üÿ®¨Ýÿ®¨Ýÿ®¨Ýÿ¯§Úÿ¯¦×ÿ®¦Øÿ­§Ûÿ¬§Ýÿ«§ßÿ«§áÿª§áÿ«¦àÿ«§ßÿ«¦ßÿª¦Þÿª¦ßÿª§âÿ©©ãÿ©©äÿª§áÿ«¥Üÿ­£Öÿ­¡Óÿ®¢Òÿ¯£Óÿ¯¤Ôÿ¯£Õÿ®¢Ôÿ¬ Óÿ¬ Òÿ­ Ñÿ®ŸÏÿ°¡Îÿ±¡Íÿ±¡Íÿ±¡Ìÿ±¡Êÿ±¡Éÿ² Êÿ¨•¾ÿ„s”ÿ:,:ÿC6EÿVI_ÿK?Sÿ/#0ÿ)%ÿ,*ÿ# ÿ"ÿ8+=ÿK1Cÿ2%2ÿXÿ, ,ÿ%!ÿ)&ÿ% ÿ:/>ÿRF\ÿ^OgÿRCUÿG8Hÿ†v•ÿ«˜¿ÿ¤‘·ÿ£�¶ÿ£�µÿ¤�µÿ¤�µÿ¥‘¶ÿ¦’¹ÿ¦’ºÿ¦“ºÿ¦“¹ÿ¨”¹ÿ¨”¶ÿ©”µÿ©“´ÿ¨“´ÿ¨’³ÿ¨’²ÿ©‘²ÿ©‘±ÿ¨‘±ÿ§�°ÿ¦�¯ÿ¦Ž¯ÿ§�®ÿ¨�­ÿ©�«ÿª‘©ÿ¬’¨ÿ­’§ÿ®’¦ÿ¯“¦ÿ¯“¥ÿ¯“¤ÿ¯“¤ÿ°“¤ÿ°”¤ÿ±”¤ÿ±”£ÿ°“£ÿ°“£ÿ¯“¢ÿ¯“£ÿ°’¢ÿ°’¢ÿ¯’¢ÿ¯’¢ÿ¯’¢ÿ¯’¡ÿ¯’¡ÿ®’¡ÿ®’¡ÿ®‘¡ÿ®‘¡ÿ¯‘¡ÿ¯‘¡ÿ¯‘Ÿÿ¯‘ ÿ°‘ ÿ±‘ ÿ°‘Ÿÿ°‘Ÿÿ¯�Ÿÿ¯�žÿ¯��ÿ°��ÿ¯��ÿ­��ÿ­��ÿ­Žœÿ¬�›ÿ¬Œšÿ¬Œšÿ¬�šÿ¬�šÿ¬�šÿ¬Œšÿ¬Œšÿ«Œšÿ«Œšÿ¬Œ›ÿ¬�›ÿ¬�›ÿ¬Œ›ÿª‹šÿ¨‰™ÿ¦ˆ˜ÿ¥ˆ˜ÿ¦ˆ˜ÿ§‰™ÿ¨Š™ÿ¨Š™ÿ¨‰˜ÿ§‰˜ÿ§ˆ—ÿ¦‡–ÿ¦‡–ÿ¦‡•ÿ¥†•ÿ¥†•ÿ¥…”ÿ¥…”ÿ¤„”ÿ¤„”ÿ£„“ÿ¢„“ÿ¢ƒ’ÿ¡‚’ÿ¡ƒ’ÿ¢‚“ÿ¢‚“ÿ£„”ÿ£„”ÿ£„•ÿ£…–ÿ£…–ÿ£…–ÿµ§Éÿ·©Éÿ¸ªÊÿ¹«Ìÿº¬Íÿº¬Îÿ»­Ðÿº®Óÿ»°Öÿ¼²Öÿ½³×ÿ½´Øÿ¾´Ùÿ¿µÚÿ¾¶Üÿ¾·Ýÿ½·ßÿ½¸áÿ½¸áÿ¼¸áÿ½·ßÿ½¶Ýÿ¾¶Ûÿ¾µÙÿ¾µÚÿ¾¶Ýÿ¾¶Þÿ½·àÿ¾¸áÿ¿¹àÿÀ¹àÿÀ¹ßÿÀ¹ÞÿÀºÞÿÀºßÿÀºáÿÀ»âÿÀ»ãÿÀ»ãÿÀºâÿÁºàÿÀºàÿ¿¹àÿ¿¹áÿÀºáÿ¿ºáÿ¾¹âÿ¾¹äÿ½ºåÿ¼¹åÿ»¹æÿº¹çÿº¹æÿ¹¸çÿ¸¸èÿ¶¸êÿµ¸íÿ³¹ïÿ²¹ðÿ²ºðÿ³¹ðÿ³¹ïÿ²¸ïÿ°¸ðÿ®¸ñÿ«·òÿ§´ôÿ£±õÿ °õÿž®öÿ�­õÿœ¬óÿœªñÿž«ðÿŸ¬ñÿ ¬ñÿ ­ñÿ ­ñÿ¡®ñÿ£°òÿ¤°òÿ¤°ñÿ¤¯ïÿ¤®ïÿ£®ðÿ£®ðÿ¢®ñÿ¡¯òÿ¡®óÿ ­óÿŸ¬òÿŸ¬òÿž¬òÿŸ­ñÿž­ñÿž­òÿž¬òÿ�«òÿž«ñÿŸ¬ñÿŸ­ñÿ ­ñÿ ­òÿŸ¬ñÿ «ïÿ¡«íÿ¡«ìÿ¢«ëÿ¢«ëÿ¢¬íÿ¡¬ïÿ ­ðÿ ¬ïÿ ¬ïÿŸ¬ïÿŸ¬ðÿ£±÷ÿ�‰ÀÿA8Qÿ;4OÿMGlÿSKnÿB9Rÿ$"ÿ"ÿ+(ÿ#ÿ3)6ÿL?Sÿ\Mdÿ_OdÿF7Eÿ„u”ÿ­›Âÿ¨•ºÿ¦“¸ÿ¥‘·ÿ¤�¶ÿ£�¶ÿ¢�¶ÿ¤�·ÿ£�¸ÿ£�¸ÿ¤�¸ÿ¤�·ÿ£�µÿ£�´ÿ£�´ÿ¢�´ÿ¢�³ÿ¢Œ³ÿ¢Œ±ÿ£Œ±ÿ¢Œ±ÿ¢Œ±ÿ¡Œ°ÿ¢‹¯ÿ¢Œ®ÿ£Œ­ÿ£Œ«ÿ¤Œªÿ¦�©ÿ¨Ž¨ÿ©�§ÿ«‘¦ÿ¬’¥ÿ­’¥ÿ®’¥ÿ®’¥ÿ¯“¤ÿ¯“¤ÿ°“¤ÿ°”¤ÿ°”¥ÿ°•¥ÿ°•¥ÿ°”¤ÿ±”¤ÿ±”¤ÿ±”£ÿ²•¤ÿ²•£ÿ²•£ÿ²–£ÿ²•£ÿ²•£ÿ²•£ÿ²•¢ÿ³•¢ÿ³•¢ÿ³•¢ÿ³•£ÿ³•£ÿ³•¢ÿ³•¢ÿ³•£ÿ³•¢ÿ³”¢ÿ³“¡ÿ³“¡ÿ²”¡ÿ²” ÿ±“Ÿÿ±’Ÿÿ±‘žÿ°‘�ÿ°‘žÿ°�žÿ¯��ÿ¯��ÿ®��ÿ®��ÿ­��ÿ®��ÿ®��ÿ®��ÿ¯��ÿ®Ž�ÿ­Žœÿ«Œœÿ©‹šÿ¨ŠšÿªŒšÿ«�œÿ«�œÿ«�œÿ«Œœÿª‹šÿ©‹™ÿ©Š˜ÿ©Š˜ÿ©Š˜ÿ©‰—ÿ¨ˆ—ÿ¨ˆ—ÿ§‡–ÿ¦‡–ÿ¥†•ÿ¥†•ÿ¤†•ÿ¤…•ÿ¤…•ÿ¤…”ÿ£…”ÿ¤…•ÿ¤…”ÿ¤…•ÿ¤…–ÿ¤…–ÿ£…–ÿ±¥Ìÿ²¦Ìÿ²¦Ëÿ²¦Ëÿ³§Ëÿµ§Ëÿµ¨Îÿ´ªÑÿµ«Ôÿµ­Öÿ¶®×ÿ·®Øÿ¶¯Úÿ¶¯Úÿ¶¯Ûÿ¶°Ýÿµ±ßÿ³²âÿ²³äÿ±²äÿ±±ãÿ±±âÿ³²áÿ´±Þÿµ¯Ûÿ¶¯Üÿµ°Ýÿ´±ßÿ´²âÿµ³ãÿ¶³áÿ·³ßÿ¸´ßÿ¸µßÿ¸µáÿº¶ãÿº·ãÿº¸äÿº¹åÿ»¸ãÿ»·âÿ»·áÿ»·âÿ»¸äÿ»¸åÿº¸åÿº·åÿ¹·æÿ¸¸çÿ·¸èÿ·¸éÿ·¸éÿ·¸éÿ¶·êÿµ¸ëÿ³¸îÿ±¹ñÿ¯¹óÿ®ºôÿ¯ºóÿ°ºôÿ°ºòÿ¯ºòÿ®¹òÿ­¹óÿ¬¸ôÿ©¶õÿ¦µõÿ£³öÿ¢²÷ÿ ±öÿž®ôÿž­òÿŸ­ñÿ ­òÿŸ­òÿŸ­òÿŸ­òÿŸ®òÿ ®òÿ ¯óÿ ®òÿ ®ñÿ¡®ñÿ ­òÿŸ­óÿž­óÿ�­óÿ�¬óÿœ¬óÿœ«óÿ›«óÿ›«òÿœ«ñÿœ«ñÿœ«ðÿœªñÿ›ªòÿœ«òÿ�¬òÿ�¬ñÿž¬ñÿŸ¬ñÿž«ñÿž«ðÿŸªïÿŸªîÿŸªíÿŸªìÿ ªíÿŸ«îÿŸ¬ïÿŸ¬îÿŸ¬îÿŸ«ïÿž«ïÿ£°öÿ~†¼ÿ;2HÿE@_ÿWSzÿ_\„ÿNIiÿ-#1ÿ&$ÿ4(6ÿ&%ÿ*)ÿI=PÿfXsÿsdÿUFZÿ‚t’ÿ«šÀÿ«™½ÿª—»ÿª–¹ÿ¨•¸ÿ§“·ÿ¥’¶ÿ¦’¶ÿ¦’¶ÿ¦’¶ÿ¥‘¶ÿ¤‘µÿ¤�´ÿ£�´ÿ¢Ž³ÿ¡�³ÿ¡Œ³ÿ¡‹²ÿ Š°ÿ Š¯ÿ¡‹¯ÿ¡‹¯ÿ ‹¯ÿ¡Š®ÿ¡‹­ÿ¡‹¬ÿ¡Š«ÿ¡Šªÿ¡Šªÿ¢Š©ÿ¤Œ¨ÿ¥�§ÿ¨Ž¦ÿ©�¦ÿª�¦ÿ«�¥ÿ¬‘¥ÿ¬‘¦ÿ­’¦ÿ¯“¦ÿ¯”¦ÿ°”¦ÿ°•¦ÿ°”¥ÿ°”¤ÿ±•¤ÿ²•¤ÿ³–¥ÿ³–¥ÿ³—¥ÿ´˜¥ÿ´˜¥ÿ´˜¥ÿ´˜¤ÿ´˜¤ÿµ˜¤ÿµ˜¤ÿµ˜¥ÿ´˜¥ÿ´˜¤ÿ´˜¤ÿ´˜¤ÿµ˜¥ÿ´˜¤ÿµ—£ÿµ—£ÿµ—£ÿµ—¢ÿµ—¢ÿµ—¢ÿµ–¢ÿ´–¡ÿ´– ÿ´•¡ÿ´•¡ÿ³• ÿ²” ÿ²” ÿ±” ÿ±“ ÿ±’ ÿ±’ ÿ±’Ÿÿ±’Ÿÿ±’Ÿÿ±’ ÿ°‘Ÿÿ­Žœÿ«�›ÿ­Žœÿ¯�žÿ°‘žÿ¯‘Ÿÿ¯‘Ÿÿ¯‘žÿ®��ÿ®��ÿ®��ÿ®Ž�ÿ®Žœÿ­�›ÿ¬�›ÿ«Œšÿª‹™ÿ©Š™ÿ©Š™ÿ¨Š™ÿ©Š™ÿ©Š™ÿ¨Š—ÿ§‰—ÿ§‰—ÿ§‰—ÿ¨ˆ—ÿ§ˆ—ÿ§ˆ—ÿ¦ˆ—ÿ°¦Íÿ°¦Îÿ¯¥Íÿ®£Ëÿ­£Éÿ®£Éÿ¯¤Ëÿ¯¥Íÿ®¦Ïÿ¯¦Ñÿ°¨Óÿ¯¨×ÿ®©Úÿ®©Üÿ®ªÛÿ­ªÛÿ«©Üÿ«ªßÿª«áÿ¨«ãÿ§«äÿ¥®éÿ¥®ëÿ¦­éÿ©­äÿ¬¬àÿ­«àÿ¬¬áÿª­ãÿª­åÿ«­âÿ¬­àÿ­®áÿ¯¯âÿ°°ãÿ±²ãÿ±³äÿ²´æÿ²µçÿ³µæÿ´´åÿ´´äÿ´µæÿ´µçÿ´µèÿ´´èÿ³´çÿ²´çÿ±´èÿ°´éÿ¯´êÿ¯µëÿ°µìÿ°µíÿ¯µîÿ¯¶ïÿ®·òÿ«¸óÿ©·õÿ©·õÿª¸õÿ«¸ôÿ«¸ôÿª¸ôÿª·ôÿ©·öÿ§¶õÿ¦µöÿ¥µöÿ¤´÷ÿ£´öÿ£²õÿ£²ôÿ£±óÿ¢±óÿ ¯óÿ ®òÿ ­òÿ ®òÿ ¯óÿ ¯óÿ ®òÿ¡®òÿ¡¯òÿ¡®òÿ ®òÿŸ­òÿž¬òÿž¬òÿ�¬òÿ�¬ôÿ�¬ôÿœ¬ôÿ›«óÿœ«òÿœ«ñÿ›ªðÿš«òÿ›«óÿœ«òÿ›«ðÿœ«ïÿ�«ïÿœ«ðÿ›ªðÿœªðÿœªñÿœªïÿ�©íÿ�©ìÿ�ªîÿ�«îÿ�«îÿ�«îÿ�«ïÿž«ïÿ£¯õÿ|ƒ¸ÿ@9Tÿ`_‹ÿtu©ÿ€¸ÿig”ÿ=2Gÿ, -ÿ;0Cÿ,!-ÿ5*7ÿcWrÿˆzŸÿ…wšÿm]wÿƒs‘ÿ£“·ÿ¬›¾ÿ¬™¼ÿ¬™»ÿ«™¹ÿ«˜¸ÿª–·ÿ¨”¶ÿ¨“¶ÿ¨”µÿ§”µÿ§•µÿ¨“µÿ¨“´ÿ§’³ÿ¦‘³ÿ¦�²ÿ¤�±ÿ¤�°ÿ¤Ž¯ÿ¤�®ÿ¤�®ÿ£�­ÿ£Œ¬ÿ£Œ¬ÿ¢Œ«ÿ¢‹ªÿ¢‹ªÿ¢‹ªÿ¢‹ªÿ¢‹©ÿ£‹©ÿ¤Œ¨ÿ¦�¨ÿ¨Ž¨ÿ©�¨ÿ©�¨ÿ©�§ÿ«�§ÿ¬‘§ÿ­’§ÿ®“§ÿ®“§ÿ®“¦ÿ®“¤ÿ®“¤ÿ°”¤ÿ±–¥ÿ²—¥ÿ³˜¦ÿµ™¦ÿµš¦ÿµš¦ÿµš¦ÿµ™¦ÿµ™¦ÿµ™¦ÿ¶š§ÿµ™¦ÿµ™¥ÿµ™¥ÿµš¥ÿ¶™¥ÿµ™¤ÿ¶™¤ÿ¶˜¤ÿ¶˜¤ÿ¶™£ÿµ™£ÿ¶™£ÿ¶™£ÿ¶™£ÿ·š£ÿ·š¤ÿ·š¤ÿ·™£ÿ¶™£ÿ¶™£ÿµ™£ÿ´˜£ÿµ—¤ÿµ—¤ÿ´—£ÿ´—¢ÿ³–¡ÿ³–¡ÿ³”¡ÿ¯�žÿ­�œÿ¯‘�ÿ²” ÿ´•¡ÿ³•¡ÿ³•¢ÿ³•¢ÿ³•¡ÿ³•¡ÿ³•¡ÿ³”¡ÿ³”¡ÿ³“ ÿ±“Ÿÿ°’Ÿÿ°‘žÿ®�žÿ®��ÿ®��ÿ®��ÿ¯��ÿ®�œÿ®�›ÿ®Ž›ÿ®Ž›ÿ­Ž›ÿ¬�›ÿ¬�›ÿ¬�›ÿª¥Ôÿ«¦Ôÿ¬¥Óÿ¬¥Òÿ¬¤Ðÿ¬£Îÿ­¤Ïÿ­¤Ïÿ¬¤Ïÿ«¤Ðÿ«¤Òÿ«¦Öÿ©§Ûÿ©©àÿ©ªáÿ¨ªàÿ§©ßÿ§©àÿ¦©áÿ¦©áÿ¥©ãÿ¤«æÿ¢¬êÿ¢¬êÿ£«èÿ£¬èÿ¤¬éÿ£¬éÿ£«éÿ£«éÿ¤«èÿ¤ªæÿ¤©åÿ¤©äÿ¥©ãÿ¦ªãÿ§¬äÿ¨®æÿ¨®çÿ¨®çÿª¯çÿª¯çÿª°çÿ«°èÿ¬°çÿ¬°çÿ«°çÿª°èÿª°éÿª°êÿ¨°ëÿ¨±ëÿ¨²ìÿ©±îÿ¨±íÿ§±îÿ§²ïÿ¦²ñÿ¥³òÿ¥³óÿ¦´ôÿ§´ôÿ¦´ôÿ¥´ôÿ¥´õÿ¤´öÿ£´öÿ£´öÿ¢´÷ÿ¢´÷ÿ¢³öÿ¢²öÿ¢²õÿ£²ôÿ£±ôÿ¢¯òÿ¢¯òÿ¡®ñÿ¡®ðÿ¢®ðÿ¢®ñÿ¢®ñÿ¢®ðÿ¢®ðÿ£®ðÿ£®ðÿ£®ïÿ£¯ðÿ¢®ðÿ ®ñÿ ¯óÿ ¯ôÿŸ®ôÿž®ôÿž­óÿž¬óÿž¬òÿ�¬òÿœ¬òÿ�¬òÿœ¬ðÿœ«ðÿœ«ñÿ›«òÿ™ªóÿ™«ôÿ™«õÿ™ªóÿ™ªñÿš©ðÿš©ðÿšªðÿšªðÿš©ñÿ›©ñÿ›ªðÿž¬óÿv~´ÿHDdÿruªÿƒ‰Æÿ{~·ÿ^\†ÿ9-?ÿ))ÿ-#.ÿ$!ÿK@Wÿvj‹ÿ�ƒ©ÿ‹~£ÿrcÿ|m‰ÿ™‹®ÿªšÀÿ«š¿ÿ«š½ÿ«š¼ÿ¬š»ÿ¬™ºÿ«˜ºÿ©—¸ÿ¨•·ÿ¨•¶ÿ©–¶ÿ¬—·ÿ¬—¶ÿ«—´ÿ«–´ÿ«•³ÿ«•±ÿª”±ÿª”°ÿ©“¯ÿ¨‘®ÿ¨�®ÿ§�­ÿ¦�¬ÿ¥�¬ÿ¥Ž«ÿ¤�¬ÿ¤Œ«ÿ£�«ÿ£�«ÿ£Œªÿ£‹©ÿ¥Œ©ÿ¦�©ÿ¦Žªÿ¦Žªÿ¦Ž¨ÿ§Ž©ÿ§�©ÿ¨�©ÿª�¨ÿª�§ÿ¬‘§ÿ¬‘¦ÿ­’¥ÿ®“¥ÿ¯•¥ÿ°–¦ÿ²—¦ÿ³™§ÿµš¨ÿµš¨ÿµ›¨ÿµš§ÿµ™§ÿµš§ÿµš§ÿµš¦ÿµš¦ÿµš¦ÿµš¦ÿ¶š¦ÿµ™¥ÿ´˜¥ÿ´˜¤ÿ³˜¤ÿ³˜¤ÿ´™¤ÿ´™¥ÿµ™¥ÿµš¥ÿ¶›¥ÿ·›¥ÿ·œ¦ÿ¸œ¦ÿ¸œ¦ÿ¸œ§ÿ¸œ§ÿ·›¦ÿ·›¦ÿ·›¦ÿ·›¥ÿ·›¤ÿ¶š¤ÿ¶™¤ÿµ—£ÿ±“ ÿ°’Ÿÿ±“Ÿÿ³•¡ÿµ˜£ÿµ˜£ÿµ˜£ÿ¶™¤ÿ¶™¤ÿ¶˜¤ÿ¶˜£ÿ¶™£ÿ¶™£ÿ¶˜¢ÿ´–¡ÿ³• ÿ³” ÿ²”Ÿÿ²”Ÿÿ³” ÿ³” ÿ³• ÿ³” ÿ²” ÿ³“Ÿÿ³“Ÿÿ²“Ÿÿ±’Ÿÿ±‘Ÿÿ°�žÿ¦¦Úÿ¦¥Úÿ¦¤Úÿ¥£Ùÿ¥¤Ûÿ¦¤Úÿ§¥Ùÿ§¥Ùÿ§¦Øÿ§¤Õÿ§£Öÿ¥¤Ùÿ¤¥Ýÿ¤¦àÿ¤©ãÿ¤«åÿ¤«æÿ£«çÿ£ªæÿ£ªåÿ¢ªåÿ¢«æÿ¢«çÿ¢«èÿ¡ªèÿŸ«ëÿ ¬íÿŸ¬îÿŸ¬íÿ «íÿ¡¬ìÿ¡«ìÿ ªëÿ ©èÿŸ¨æÿŸ¨åÿ ¨åÿ ¨æÿ ¨çÿ ¨èÿ¡©èÿ¡ªéÿ¢«êÿ¢¬ìÿ£¬ëÿ£¬ëÿ¢¬ìÿ¢¬ìÿ¢¬ìÿ¢­ìÿ¢­ìÿ¢­ìÿ¢¬ìÿ¢¬ìÿ¡¬ìÿ¡¬íÿ¡¬îÿ ¬ïÿ ­ñÿ ­ñÿ ®ðÿ¡®ðÿ¡®ñÿ ®òÿŸ®óÿŸ®ôÿ�¯öÿœ¯÷ÿœ°÷ÿ�°÷ÿŸ°öÿŸ¯õÿ ¯ôÿ¡¯óÿ¡®òÿ¡®ñÿ¡­ðÿ¡¬îÿ¡¬ìÿ¡«ëÿ¡¬ìÿ¢¬ìÿ¢­ìÿ¢­íÿ¤­íÿ¤®íÿ¤®íÿ¤®íÿ£®íÿ¢®îÿ¢®ïÿ¢¯ñÿ¡¯òÿ ®óÿŸ­óÿŸ¬òÿŸ«ðÿž«ðÿ�¬ñÿ�¬òÿ�¬òÿœ«òÿš«óÿ™ªôÿ˜«õÿ—ªöÿ—ª÷ÿ—ªöÿ—©ôÿ˜©óÿ˜©óÿ˜©òÿ˜ªóÿ˜ªóÿ˜ªóÿšªóÿ—¥íÿow«ÿB>^ÿce˜ÿcd”ÿVT|ÿCUÿG:Oÿ?3Dÿ_Rkÿ�¢ÿ«�Èÿ«œÆÿ«›Åÿ«›Ãÿ«›Áÿ¬›¿ÿ¬›½ÿ­œ¼ÿ­›ºÿ­š¹ÿ¬™·ÿ¬—µÿ«–³ÿ¬–²ÿ­—²ÿ®™²ÿ¯™±ÿ¯™°ÿ°™°ÿ°™°ÿ°™¯ÿ°˜®ÿ°˜®ÿ¯˜­ÿ¯—­ÿ¯—¬ÿ®–¬ÿ­•¬ÿ¬”«ÿ¬”«ÿ«“ªÿª“ªÿ©’ªÿ¨‘«ÿ§‘«ÿ¨�«ÿ§�«ÿ§�ªÿ§�ªÿ¦Žªÿ¦Žªÿ¤�©ÿ£Œ¨ÿ£‹§ÿ£‹¦ÿ¤Œ¦ÿ¤Œ¦ÿ¥Œ¦ÿ¥Œ¦ÿ¥Œ¥ÿ¥�¥ÿ¦�¥ÿ¦�¤ÿ§�¤ÿ§Ž¥ÿ¨�¤ÿ©�¤ÿ¨Ž£ÿ¦�£ÿ¦�£ÿ§�£ÿ§Ž¤ÿ¦Œ£ÿ¥Š¢ÿ£‰¡ÿ¡ˆ¡ÿ¡‰¡ÿ¤Š¢ÿ¦Œ¤ÿ§Ž¥ÿ©�¥ÿ«’¦ÿ­”¨ÿ¯•©ÿ°•©ÿ°–ªÿ±˜«ÿ²™«ÿ³š«ÿ´šªÿ´šªÿ´š©ÿ´š©ÿµš©ÿµš©ÿ´™¨ÿ²–¥ÿ¯“£ÿ¯’¢ÿ¯“¢ÿ°”£ÿ²–£ÿ´˜¥ÿ´˜¦ÿ´™¦ÿ´˜¦ÿ´˜¥ÿ³—¤ÿ³–¤ÿ²•£ÿ²”£ÿ²”£ÿ²•£ÿ²•¤ÿ²•¤ÿ±•¤ÿ±”£ÿ°“¢ÿ¯‘¡ÿ®‘ ÿ®‘ ÿ®‘ ÿ®� ÿ¬�Ÿÿ«Žžÿ«�žÿž¦äÿ�¦äÿ�¦äÿž¦ãÿ�§ãÿœ§åÿœ©éÿš©ìÿ˜©îÿ™©îÿœ¨ëÿœ§éÿ›¥æÿ™¤åÿ˜¤æÿ–¥éÿ–¦íÿ–¨ðÿ•©òÿ”©ôÿ”©óÿ”©óÿ•¨ñÿ•¨ïÿ•¨ðÿ•¨ðÿ•©ñÿ•©ñÿ•©ðÿ•©îÿ–¨îÿ–§íÿ–§ìÿ–§íÿ–¨ïÿ–¨ïÿ–¨ïÿ–¨ðÿ•§ïÿ•§îÿ•¦îÿ•¥íÿ”¥íÿ“¦îÿ”¦ðÿ”¦ðÿ”¥ïÿ”¥ïÿ“¦ïÿ“¦ïÿ“¥îÿ”¥îÿ•¤ìÿ–¤êÿ—¤éÿ—¤èÿ—¤èÿ—¤çÿ—¤çÿ—£çÿ˜¤èÿ—¤èÿ–¤éÿ–¥ëÿ–¥íÿ–¥îÿ—§îÿ—§ïÿ—§ïÿ—§îÿ—§îÿ˜§îÿ™¨îÿ™¨íÿš§ìÿ›§ëÿœ¨êÿ�¨èÿž§çÿŸ§æÿŸ¦ãÿŸ¥ãÿ¡¦ãÿ¢§äÿ¢¨åÿ ¨åÿ ¨åÿ §æÿ §åÿ §åÿ ©æÿ¡©çÿ¡©çÿ ©èÿ ªêÿ «ìÿ «ìÿŸ«ìÿŸ«ìÿŸ«íÿž«îÿ�«ðÿœ«ñÿš«òÿ˜ªòÿ—ªòÿ—©òÿ–¨ñÿ–§ñÿ–§ñÿ–§ñÿ–¨ñÿ–¨òÿ•¨óÿ—¨óÿ˜©òÿ‰•Õÿ_c�ÿ) 1ÿ=8WÿDAeÿDAcÿ83Kÿ&%ÿ()ÿ>5Jÿ/%4ÿ#ÿ;1CÿRGbÿG:Pÿ?3BÿUI^ÿ…x˜ÿ­ŸÇÿ­ŸÆÿ­žÅÿ­�Ãÿ­�¿ÿ­œ½ÿ®œ»ÿ®œºÿ®œ¸ÿ¯œ·ÿ°›µÿ¯š´ÿ­˜²ÿ¬—°ÿ¬—°ÿ­˜°ÿ®˜¯ÿ¯™¯ÿ±š¯ÿ²›¯ÿ²›¯ÿ²›¯ÿ²›®ÿ²š®ÿ±š­ÿ±š­ÿ²™¬ÿ±˜¬ÿ°˜«ÿ¯—«ÿ¯—ªÿ®—©ÿ­–ªÿ¬–«ÿ«•«ÿ«”ªÿ«“ªÿ«’ªÿª’©ÿ©‘©ÿ¨‘©ÿ§�©ÿ¦�¨ÿ¥Ž§ÿ¥Ž§ÿ¥Ž§ÿ¤�§ÿ¥Œ§ÿ£Œ¦ÿ¡‹¥ÿ ‰¥ÿ ‰¤ÿŸˆ¤ÿžˆ¤ÿžˆ£ÿŸˆ£ÿŸˆ£ÿž†¢ÿœ…¡ÿ›„¢ÿœ„¢ÿœ„¢ÿœ„¢ÿœ„¢ÿ›„¢ÿ›ƒ¢ÿ™„¢ÿ›„£ÿœ…¤ÿ�†¥ÿžˆ¥ÿ Š¦ÿ¢Œ¨ÿ¤�©ÿ¥Ž©ÿ§�ªÿ©‘ªÿª“ªÿ¬”©ÿ­”©ÿ­”¨ÿ¬“§ÿ¬“§ÿ­“¨ÿ®”¨ÿ­”§ÿ¬’¦ÿª�£ÿ©�¢ÿ©�¢ÿª�¡ÿ¬‘¢ÿ®“¤ÿ¯”¤ÿ°•¥ÿ°”¥ÿ°•¥ÿ°”¤ÿ¯”£ÿ¯“£ÿ¯“£ÿ°”£ÿ°”¤ÿ¯”¤ÿ®“£ÿ­’¢ÿ¬�¡ÿ¬�¡ÿªŽ ÿ©ŽŸÿªŽŸÿªŽŸÿ©�žÿ§‹œÿ¥‰œÿ¥‰œÿ–¢æÿ–¢æÿ—¢åÿ—¢äÿ—¢ãÿ—£ãÿ˜¥çÿ˜§ëÿ˜¨íÿ˜©ïÿ™¨îÿ˜§îÿ–¦íÿ•¦ìÿ“¥îÿ‘¥ïÿ�¥ðÿ�¥ñÿ�¥òÿަôÿަóÿ�¦ôÿ�¦ôÿ�¦ôÿ�¦ôÿ�§õÿލõÿŽ©öÿ�©÷ÿ�©÷ÿ�©øÿ�©÷ÿ�©öÿ‘¨õÿ‘©õÿ’©ôÿ’¨óÿ’¨óÿ’¨óÿ’§òÿ’¦òÿ�¦òÿ�¦ñÿ�¦ñÿ�¥òÿ�¥òÿ�¤ñÿ�¤ðÿ�¤ïÿ�£ïÿ�£íÿ�¢ìÿ‘¡êÿ’ èÿ“ æÿ“Ÿæÿ”Ÿäÿ“Ÿäÿ“Ÿãÿ”Ÿäÿ“Ÿåÿ’ æÿ’ çÿ’¡èÿ’ éÿ“¢ëÿ“£ëÿ“£ëÿ”£êÿ”£êÿ•£êÿ•£éÿ•£éÿ–£èÿ—£èÿ˜£èÿ™£çÿ™£æÿš£äÿš£ãÿ›¡âÿ›¡àÿœ¡àÿž¢àÿž£áÿž£áÿž£áÿž£âÿž£áÿž£áÿŸ¥âÿŸ¦ãÿ ¦ãÿ¡§äÿ¡¨æÿ ©èÿ ªèÿ ªéÿ ªêÿ¡ªêÿ ªëÿŸªëÿ�«ìÿœ«íÿ›ªîÿšªïÿš©ïÿ˜¨ïÿ—¨îÿ—§îÿ—§ïÿ—§ðÿ–§ñÿ–§ñÿ—§ñÿ˜§ðÿƒŒÊÿWY‚ÿ.)>ÿFDgÿLHoÿTRyÿEB`ÿ((ÿ"!ÿ*".ÿ"ÿ2)5ÿK@TÿZMeÿXKaÿXL_ÿZM`ÿ€sŽÿ¯ Äÿ®ŸÂÿ¯žÀÿ¯ž¾ÿ°Ÿ¼ÿ°ž¹ÿ°�·ÿ°œ¶ÿ°œµÿ°œ´ÿ±œ´ÿ±›³ÿ°›²ÿ¯š±ÿ®™°ÿ®™¯ÿ®˜®ÿ®˜®ÿ¯š®ÿ±›®ÿ³œ¯ÿ³�®ÿ´œ®ÿ´œ®ÿ´œ®ÿ´œ®ÿ³›­ÿ³›¬ÿ³›¬ÿ³š«ÿ²š«ÿ±šªÿ²š«ÿ±š«ÿ±›«ÿ±š«ÿ±˜«ÿ°˜ªÿ°˜ªÿ¯—ªÿ¯—©ÿ¯—©ÿ®–©ÿ­•©ÿ¬”©ÿ¬”©ÿ¬”ªÿ«“©ÿª“¨ÿ©‘¨ÿ§�¨ÿ§�¨ÿ¦�§ÿ¥�¦ÿ¥Ž¦ÿ¤�¥ÿ¤�¦ÿ£Œ¥ÿ¢‹¤ÿ¡Š¥ÿ ‰¥ÿŸˆ¥ÿž‡¥ÿž‡¥ÿ�‡¦ÿ›‡¦ÿš†§ÿ™†¨ÿš†©ÿš†ªÿš‡«ÿ›ˆ«ÿœˆ«ÿœˆ«ÿ�‰ªÿŸŠªÿ ‹©ÿ¡‹¨ÿ¢Œ¨ÿ¤�¨ÿ¤�¨ÿ¥�§ÿ¤�§ÿ¥�§ÿ¥�§ÿ¥�¦ÿ¤�¦ÿ¤‹¤ÿ£Š£ÿ¢Š¢ÿ£‹¡ÿ¥‹¢ÿ§�¢ÿ¨Ž¢ÿ¨Ž¢ÿ©Ž¢ÿ©�£ÿª�£ÿ«�¢ÿ«�¢ÿ«�¢ÿ«�¢ÿª�¢ÿ©Ž¡ÿ¨� ÿ¨� ÿ¨ŒŸÿ§‹Ÿÿ¥ŠŸÿ¤‰žÿ¤‰œÿ£ˆœÿ¢†›ÿ¡…›ÿ …›ÿ …›ÿ�›ãÿ�œäÿ�œäÿ�œäÿ�žåÿ�Ÿåÿ� çÿ‘¢êÿ‘£ìÿ‘¥îÿ’¥ðÿ’¦ñÿ‘¦òÿ�§óÿ�§ôÿ�¦ôÿ�¥óÿޤòÿ�¤ñÿ�£òÿ‹¢òÿŠ¢òÿ‰£ôÿФõÿ‹¤õÿ‹¤ôÿ‹¥õÿ‹¦õÿŒ¦öÿŒ¦÷ÿŒ§÷ÿ�¨÷ÿ�§öÿަõÿަõÿ�§ôÿ�¦óÿ�¦óÿ�¦óÿ�¦óÿަôÿ�¦ôÿ�¦õÿަöÿ�¥öÿ�¥õÿ�¤óÿ�£ïÿ�¢ìÿ‘¡êÿ‘ éÿ�Ÿèÿ‘žæÿ‘�äÿ’�ãÿ‘œâÿ‘œâÿ’�ãÿ’�ãÿ’�äÿ’Ÿæÿ‘Ÿçÿ‘Ÿèÿ‘žèÿ‘žèÿ‘ éÿ‘ éÿ‘ éÿ‘ èÿ’Ÿçÿ’Ÿæÿ’žåÿ“žäÿ”žãÿ”žãÿ•žãÿ•�âÿ•�áÿ–�ßÿ•�Ýÿ–œÝÿ—œÝÿ—œÜÿ˜œÝÿ™œÜÿšœÝÿš�ÝÿšžÞÿ›ŸÞÿ› Þÿœ ßÿ�¡ßÿž¡ßÿŸ¢àÿŸ£àÿ ¥âÿ ¨äÿ¡©æÿ ©æÿŸ¨æÿ ¨æÿŸ¨çÿž¨æÿž¨æÿž¨èÿ�§éÿœ§êÿ›§êÿš§êÿš§êÿ™¦éÿ™¥êÿ™¥ëÿ˜¦ìÿ˜§íÿ™§îÿ}„½ÿPNrÿECcÿhk›ÿlmžÿ„»ÿjl™ÿ3(9ÿ/$2ÿI@Uÿ2*7ÿMCWÿqe�ÿ~q�ÿqŒÿ�r‹ÿqbvÿ�rŠÿ¯Ÿ¿ÿ±Ÿ½ÿ±žºÿ²ž¹ÿ³Ÿ¸ÿ³Ÿ·ÿ³Ÿ¶ÿ²žµÿ²�´ÿ²�³ÿ±�²ÿ²�³ÿ²�³ÿ²�²ÿ²�²ÿ²œ±ÿ°›±ÿ¯š¯ÿ¯š­ÿ°š­ÿ±›­ÿ³œ®ÿ´�®ÿµ�¯ÿµ�¯ÿµž®ÿµž®ÿ´�­ÿ´œ¬ÿ´œ¬ÿ³œ¬ÿ´œ¬ÿ³›«ÿ³œ«ÿ³œ«ÿ²›«ÿ³šªÿ³šªÿ³šªÿ³›«ÿ´œ¬ÿ´œ¬ÿ´œ¬ÿµœ­ÿ´�­ÿ´�­ÿ´�­ÿµž®ÿµž®ÿµ�­ÿ´œ­ÿ´�­ÿ´�­ÿ´�¬ÿ´œ¬ÿ´œ¬ÿ´œ«ÿ´œ¬ÿ³›¬ÿ²›«ÿ±™ªÿ¯˜ªÿ¯—ªÿ­–«ÿª”«ÿ§‘¬ÿ¤�®ÿ¡�¯ÿž‹±ÿ�‹³ÿœŠ³ÿšŠ´ÿ™‰³ÿ˜‡²ÿ—†±ÿ—†°ÿ˜‡¯ÿ™ˆ­ÿ›ˆ¬ÿ�‰¬ÿ�‰¬ÿ�‰«ÿ�ˆªÿžˆ«ÿž‰«ÿžŠªÿŸŠ©ÿž‰¨ÿ�‡§ÿœ‡§ÿ�‡¦ÿŸˆ¥ÿ ‰¤ÿ¢Š¤ÿ¢Š¤ÿ£Š£ÿ£‹£ÿ¤‹£ÿ¤‹£ÿ¥‹¢ÿ¥Š¡ÿ¤‰¡ÿ¢ˆ ÿ¡ˆŸÿ ‡žÿŸ…žÿž…�ÿ�„œÿœ‚›ÿš�šÿ™€™ÿ˜€™ÿ˜™ÿ˜~™ÿ—~šÿ—~šÿ‹—ßÿ‹—áÿŠ—âÿŠ˜ãÿŠšäÿŠ›åÿ‹�çÿ‹�èÿ‹žéÿ‹žëÿŒŸìÿŒ îÿŒ¢ðÿ‹¤óÿŒ¥ôÿŒ¤óÿŒ£ñÿŒ£ñÿŒ£òÿ‹£óÿФôÿ‰¤õÿ‰¤õÿˆ£õÿˆ¢óÿ‰¡ñÿ‰¡ñÿ‰¢ñÿŠ¢ñÿ‹¢ñÿ‹£ðÿ‹£ðÿŒ¢ïÿ�¢îÿŽ¢îÿŽ¢ìÿ�¡ìÿ�¢ìÿ�¢ìÿŽ¢íÿ�¡íÿ�¡íÿ�¡íÿŒ¡íÿŒ ìÿ�ŸìÿŽŸéÿ�žæÿ��ãÿ�œâÿ�œáÿ�›áÿ�›áÿ‘›áÿ‘›àÿ‘›áÿ�›áÿ�›áÿ‘œâÿ‘œäÿ‘�åÿ‘�åÿ‘�äÿ‘�äÿ‘�äÿ’�äÿ’žäÿ’žäÿ‘�äÿ‘œâÿ’œàÿ’œàÿ“›ßÿ”›Þÿ”›Ýÿ”šÜÿ”™Ûÿ•™Úÿ•˜Úÿ•™Ùÿ–™Øÿ–™Øÿ–™Ùÿ–˜Øÿ—˜Øÿ—˜×ÿ˜™Øÿ˜šÚÿ™›Úÿ™œÚÿšœÚÿšœÛÿ›�Üÿœ�Üÿ�ŸÜÿ� Ýÿ�¢Þÿ�£ßÿ�£àÿœ£áÿ�£áÿ�£áÿ�£àÿ�¤àÿ�£áÿœ£âÿœ¤ãÿœ¤äÿœ¤äÿ›¤äÿ›¤äÿ›¤ãÿ›¤äÿ›¤åÿ›¥æÿœ¦èÿx{­ÿKEbÿVRtÿ€€²ÿ‰‡ºÿxv¤ÿYTvÿ9-=ÿ7,:ÿSJbÿ?5FÿE9Jÿk^wÿ‰{—ÿ‘‚žÿ�~—ÿxh|ÿƒr‡ÿ®�¹ÿ±Ÿ¹ÿ±Ÿ¸ÿ²ž·ÿ²Ÿ¶ÿ³Ÿ¶ÿ³Ÿ¶ÿ³Ÿµÿ³Ÿµÿ²Ÿ´ÿ²ž³ÿ³ž²ÿ²ž²ÿ²ž²ÿ³Ÿ²ÿ´Ÿ³ÿ´Ÿ²ÿ³ž±ÿ²�°ÿ±›®ÿ±›­ÿ²›­ÿ³œ®ÿ´�¯ÿµž¯ÿ¶Ÿ¯ÿ¶Ÿ¯ÿµŸ®ÿµŸ®ÿµŸ®ÿµŸ¯ÿµŸ®ÿµž­ÿµž­ÿµž®ÿ´ž­ÿ´�¬ÿ´�¬ÿ´�¬ÿµž­ÿµž­ÿ¶ž­ÿ¶ž­ÿ¶Ÿ®ÿ¶ ®ÿ¶ ®ÿ· ®ÿ·¡®ÿ¸¡¯ÿ¸¡¯ÿ¸¡°ÿ¸¢°ÿ¹¢°ÿ¹¢°ÿ¸¡°ÿ¹¡¯ÿ¹¡¯ÿ¸¡¯ÿ· ¯ÿ· ¯ÿ¶ ®ÿ¶ ®ÿ¶ ®ÿ¶Ÿ¯ÿµž¯ÿ´�°ÿ²œ±ÿ°›²ÿ®š³ÿ¬˜µÿª—µÿ¨–·ÿ¨–·ÿ§•¸ÿ¦•¸ÿ£”¸ÿ¢“¸ÿ¡‘·ÿŸ�·ÿžŽ·ÿ��·ÿœŒµÿ›‹´ÿ›Š³ÿ›Š³ÿšŠ²ÿ›‰±ÿšˆ¯ÿ™†­ÿ—…­ÿ–…­ÿ˜†¬ÿ˜…«ÿ˜…ªÿ™…©ÿ™„¨ÿ™„§ÿ˜„¦ÿ˜ƒ¥ÿ™ƒ¤ÿ™‚£ÿ™‚£ÿ˜�¢ÿ—�¢ÿ–€¡ÿ• ÿ•Ÿÿ•~žÿ”}�ÿ”}�ÿ”~�ÿ”~�ÿ”}�ÿ”~žÿ”~Ÿÿ”}Ÿÿ„•âÿ…•âÿ…•äÿ…–äÿ…—åÿ…˜æÿ†™çÿ†™çÿ†˜çÿ†™çÿ‡™èÿ‡šéÿ‡›êÿˆœëÿ‰�ëÿ‰�êÿ‰œéÿŠ�éÿ‹�ëÿŠžíÿŠ îÿŠ¡ðÿ‰¡ñÿˆ ñÿˆ ïÿˆŸîÿˆŸíÿˆžìÿˆ�ëÿ‰�ëÿ‰�ëÿŠœêÿŠœéÿ‹�éÿŒ�èÿ��æÿŽ�åÿŽ�åÿŽ�äÿ��äÿ�›äÿ�›äÿ�›ãÿ�›âÿ�šáÿ�™áÿŽ™ßÿŽ™Þÿ�™Ýÿ�˜Üÿ�˜Úÿ�—Úÿ‘—Úÿ‘—Úÿ�˜Úÿ�˜Ûÿ�˜Ûÿ�˜Üÿ‘™Ýÿ’šßÿ’šßÿ’šÞÿ’›Þÿ’›Þÿ“›Þÿ“šÝÿ“›Ýÿ”›Üÿ”šÛÿ”šÚÿ”šÙÿ•šÙÿ•™Øÿ•™×ÿ–˜Öÿ–—Õÿ–—Óÿ––Óÿ––Óÿ—–Òÿ——Òÿ——Óÿ—–Óÿ—–Óÿ—–Òÿ—–Òÿ˜–Òÿ˜—Ôÿ˜—Õÿ˜˜Õÿ™™Õÿ™™Öÿ™™ÖÿššÖÿ››×ÿ››×ÿšœØÿ›�Ùÿ›�Úÿ›�ÛÿœžÚÿœžÚÿœŸÛÿ�ŸÛÿ�ŸÛÿ�ŸÜÿ� Ýÿž¡Þÿ�¢Þÿ�¢ßÿž¢àÿž£áÿž£áÿž£áÿŸ¤âÿ¡¥âÿvu ÿI@Wÿ^Wuÿƒ©ÿ~y¡ÿka�ÿPCYÿ5(6ÿ2'3ÿEÿ2@ÿPCUÿcTkÿbTjÿTEWÿ@2@ÿ1#-ÿ)"ÿ%ÿ( ÿ;,5ÿM=HÿWFSÿ^MYÿ[KWÿQAJÿpboÿ¤“§ÿ³¢·ÿ¶¥ºÿ¶¥ºÿ¶¦»ÿ·¦¼ÿ·¦»ÿ·¥ºÿ·¥¹ÿ·¥¹ÿ¸¥¹ÿ¹¥¹ÿ¸¥¸ÿ¸¥·ÿ·¤·ÿ¶£¶ÿ¶£µÿ¶£µÿ¶£µÿ·£¶ÿ¸¤¶ÿ¹¥·ÿ¹¥¶ÿ¹¥µÿ¸¤µÿ¸£´ÿ¸¤´ÿ¸¤´ÿ¹¥µÿ»§¶ÿ»¨·ÿ¼©·ÿ½ª¸ÿ½ª¹ÿ¾ª¹ÿ¾ª¹ÿ½ª¹ÿ¾ª¹ÿ¾«¹ÿ¾«¹ÿ¿¬¹ÿ¿¬¹ÿ¾«¹ÿ¿«¹ÿ¿«¸ÿ½ª·ÿ½ª·ÿ½ª·ÿ½©·ÿ½©¸ÿ½©¸ÿ¼©·ÿ¼©¸ÿ»¨·ÿ»¨·ÿ»¨·ÿ¼¨·ÿ»¨¹ÿ»¨¹ÿ»¨¸ÿ»¨¸ÿ»¨·ÿ»¨·ÿº§·ÿ¹¦·ÿ¹¦·ÿ¹¦¸ÿº§¸ÿº§¹ÿº§¸ÿ»§¸ÿ»¨¹ÿ»§ºÿ»§ºÿ»¨ºÿ»¨ºÿº¨¹ÿ¹¦¹ÿ·¤¹ÿ¶£¸ÿ´¡·ÿ³ ·ÿ²Ÿ¸ÿ²Ÿ¸ÿ±ž¹ÿ°ž»ÿ¯ž¼ÿ¯ž¼ÿ¯ž½ÿ®�½ÿ«œ¼ÿªš»ÿ«›»ÿ¬œ¼ÿ­�¼ÿ®�½ÿ®ž½ÿ¯�¼ÿ®�¼ÿ®�¼ÿ¯�»ÿ¯œºÿ¯œ¹ÿ¯œ·ÿ¯›µÿ¯›´ÿ¯›³ÿ®™±ÿ®š±ÿ¯š±ÿ¯š°ÿ¯š°ÿ°š¯ÿ°›¯ÿ±›¯ÿ±›­ÿƒ‚ÃÿƒƒÅÿ„„Æÿ„„Æÿƒ„Æÿƒ…Èÿ„…Éÿ„‡Ëÿ…ˆËÿ…ˆÊÿ…‡Êÿ…‡Èÿ††Çÿ††Æÿ‡…Åÿ‡…Åÿ†…Åÿ‡†Æÿ‡†Çÿ‡‡ÈÿˆˆÈÿ‰ˆÈÿˆˆÈÿˆˆÈÿ‰‰ÈÿЉÉÿ‰ŠÊÿ‰ŠÉÿ‰ŠÉÿ‰ŠÉÿˆ‹Êÿˆ‹Êÿ‰ŠÊÿˆ‹Ìÿ‡ŒÎÿ†�Ñÿ‡ŽÓÿ‡ŽÔÿ‡�Ôÿ‡�Ôÿ‡�Óÿ‡�Ôÿˆ�Ôÿ‰�Ôÿ‰�Óÿ‰�Òÿ‰�Ðÿ‰ŽÏÿ‰�Îÿ‰�ÍÿŠ�ÍÿŒŽÍÿ�ŽÍÿŽ�ÌÿŽ�ÌÿŽ�ÍÿŽ�ÏÿŽ‘Ñÿ�“Óÿ�“Ôÿ‘”Óÿ‘”Óÿ‘•Òÿ’”Ñÿ“”Ïÿ•”Ïÿ••Ðÿ––Ðÿ——Ñÿ˜˜Òÿ™˜Òÿš˜Òÿ›˜Ðÿ›˜Ïÿœ™Ïÿ�™Ðÿœ™Ñÿœ™Ñÿ�šÒÿž›Òÿ�›ÒÿžœÒÿžœÓÿžœÓÿžœÒÿžœÒÿŸœÐÿŸ›Ïÿž›Ïÿ�›ÑÿœœÒÿœœÕÿ››Õÿ›šÓÿ›™Ðÿœ˜Íÿ�˜Ëÿœ—Ëÿœ˜Ìÿ›™Ðÿš›Õÿš›×ÿ››Öÿœ›Ôÿ�›Óÿ�œÔÿŸ�Õÿ �Ôÿ œÑÿ¢�Ïÿ£�Íÿ¤�Ëÿ¦žÊÿ§žÉÿ¨žÇÿ¢—¼ÿj`xÿ5'3ÿE8GÿYK]ÿ\M_ÿZL\ÿF9Eÿ& ÿ%ÿ*!ÿ&ÿ7)1ÿO?Jÿ]KYÿYITÿRBLÿJ9Bÿj[iÿ›‹ ÿ°Ÿ¶ÿ´£ºÿ´¤»ÿµ¤»ÿµ¤»ÿµ¥¼ÿ¶¥»ÿ·¥»ÿ·¦»ÿ·¦»ÿ¹¦»ÿ¸¦ºÿ¸§ºÿ¸§ºÿ¸¦¹ÿ¸¦¹ÿ·¥¸ÿ¶¤¸ÿ¶¤¸ÿ·¤¸ÿ¸¥¹ÿ¹§¹ÿ»©ºÿ»©ºÿ»©ºÿ»¨¹ÿ»§¹ÿ»¨¹ÿ¼©ºÿ½«ºÿ¾¬»ÿ¿®½ÿÀ®½ÿÀ®½ÿÀ®½ÿÀ®¼ÿÀ­¼ÿÀ­¼ÿ¿­¼ÿ¿­»ÿÀ®¼ÿÀ®¼ÿÀ®¼ÿ¿®¼ÿ¿­»ÿ¿­»ÿ¿®¼ÿ¿­»ÿ¿­»ÿ¿­»ÿ¾­»ÿ¾­»ÿ¾¬»ÿ½¬ºÿ½¬ºÿ½«ºÿ½«ºÿ½«ºÿ¾«»ÿ¾«»ÿ¾«ºÿ½«ºÿ¼ªºÿ»¨¹ÿº§¹ÿ¹¦¸ÿ¹¦¸ÿ¹¦¸ÿ¸¦¸ÿ¸¦·ÿº§¸ÿ»§¹ÿ»¨ºÿº¨ºÿ»©ºÿ»¨¹ÿº§¸ÿ¹¦¸ÿ¹¦·ÿ¸¥·ÿ·¤¶ÿ¶£¶ÿµ¢¶ÿ´¡¶ÿ³ ·ÿ±Ÿ¸ÿ¯žºÿ®�»ÿ­œ¼ÿªœ¼ÿ¨š¼ÿ§˜¼ÿ¨˜½ÿ¨˜¿ÿ¨™Àÿ¨šÁÿ¨šÁÿ¨šÂÿ¨›Âÿ©›Âÿ©›ÁÿªœÀÿ«œÀÿ«›¿ÿ«š½ÿ«š»ÿ«™¹ÿ«š¸ÿ¬š¶ÿ­šµÿ­š³ÿ®š²ÿ®š±ÿ¯š°ÿ¯š°ÿ‰‚ºÿ‰‚ºÿ‰‚»ÿˆƒ¼ÿˆƒ¼ÿˆƒ¼ÿˆ‚½ÿˆƒ½ÿˆ„¼ÿ‰ƒ¼ÿŠƒ½ÿŠƒ¼ÿŠƒ¼ÿŠƒ¼ÿŠƒ¼ÿŠƒ¼ÿŠƒ½ÿŠ„¾ÿŠ„Àÿ‰…Áÿ‰…ÂÿІÂÿ‰…Ãÿ‰†Ãÿˆ‡Âÿ‰‡Äÿˆ‡Åÿ‡†Äÿ‡…Ãÿˆ†Äÿ‡†Äÿ‡‡Åÿ‡‡Æÿ‡ˆÉÿ†ŠÌÿ…‹Íÿ†‹Ïÿ†ŒÏÿ†‹Îÿ†‹Íÿ†ŠÎÿ†‹Ïÿ†ŒÏÿ†ŒÏÿ‡‹Îÿ‡‹Íÿ‡‹Ìÿ‡ŠÌÿ‡ŠÌÿ‡‹Íÿˆ�ÏÿˆŽÐÿ‰ŽÐÿ‰ŽÏÿŠŽÏÿ‹�Îÿ‹ŽÏÿŒ�ÑÿŒ’Óÿ�’Óÿ�“ÓÿŽ’ÒÿŽ’Ñÿ�‘Ðÿ’‘Îÿ“’Íÿ““Íÿ””Íÿ•”Îÿ–•Îÿ–•Íÿ˜–Îÿ™—Îÿš˜Ïÿ›˜Ïÿ›˜Ïÿ›™Ðÿœ™Ñÿ�›ÒÿžœÔÿ�œÕÿ�žÖÿ�ž×ÿ�ž×ÿ�žÖÿžžÔÿž�ÔÿžžÖÿ�ŸÙÿœ Úÿ›¡Üÿœ¡Þÿœ ÝÿœŸÛÿ›�Ùÿ›žØÿœžØÿ›žØÿ›žÙÿ›ŸÚÿœŸÛÿœ�×ÿ�œÔÿžœÓÿž�Ôÿž�ÖÿŸ�Õÿ¡�Òÿ¢�Íÿ¤�Ëÿ¥�Êÿ¦�Èÿ¦�Çÿ§žÇÿ§œÅÿœ‘¶ÿdZqÿ?3AÿVI]ÿh[rÿ|o‰ÿyk‚ÿYL\ÿ$ÿ&ÿ0!)ÿ(!ÿ+"ÿUHUÿxi}ÿfVgÿZIUÿTDNÿk\kÿ”„™ÿ­�¶ÿ²¢»ÿ²¢¼ÿ²£½ÿ³£½ÿ³£½ÿ´£½ÿµ¤½ÿµ¤¼ÿµ¥¼ÿ¶¥¼ÿ¶¥»ÿ¶¦¼ÿ·¦¼ÿ¸¦»ÿ¸¦»ÿ¸¦»ÿ·¦»ÿ¶¥»ÿ¶¥ºÿ·¥ºÿ¸§»ÿ¹¨»ÿ»©¼ÿ¼«¼ÿ¼«¼ÿ»ª»ÿ»ª»ÿ»ª¼ÿ¼ª¼ÿ½¬½ÿ¾­¾ÿ¿¯¿ÿÁ°Àÿ²ÁÿòÀÿijÁÿóÁÿòÀÿòÀÿòÀÿIJÀÿòÀÿ³ÁÿóÁÿóÀÿ²Àÿ²ÀÿòÀÿ±Àÿ±ÀÿÁ±ÀÿÁ°¿ÿÁ°¾ÿÁ°¾ÿÀ¯¾ÿÁ¯¾ÿÀ¯½ÿ¿®½ÿ¿®½ÿÀ®½ÿ¿®¼ÿ¿­¼ÿ¾¬¼ÿ½«»ÿ½ª»ÿ»©ºÿ»©ºÿº©ºÿº¨¸ÿ»¨¹ÿ»©¹ÿ¼©¹ÿ»©¹ÿ»©¹ÿ¼¨¸ÿ»¨¸ÿº§·ÿº§¶ÿº§¶ÿ¹¦µÿ¸¥µÿ¸¥µÿ·¥µÿ·¤¶ÿ¶¤·ÿµ¢¸ÿ³¡¹ÿ² ¹ÿ°Ÿ¹ÿ®�ºÿ¬›¹ÿª™¹ÿ©˜ºÿ§—¼ÿ¦–¾ÿ¤–¾ÿ¤–¿ÿ¥—Áÿ¥˜Âÿ¦™Áÿ§šÁÿ©›Àÿª›¿ÿªš½ÿ«›ºÿ¬›¹ÿ­›·ÿ®›¶ÿ¯›µÿ¯›´ÿ¯›³ÿ®š²ÿ¯š±ÿ¯š±ÿ�‚´ÿŒ‚µÿŒ‚µÿŒ‚¶ÿŒ‚¶ÿŒ‚¶ÿ‹‚¶ÿ‹‚¶ÿ‹‚µÿŒ‚µÿŒ�µÿ��µÿŒ�µÿŒ�µÿŒ‚µÿŒ‚¶ÿŒ‚·ÿŒƒ¹ÿ‹„ºÿ‹„¼ÿ‹„½ÿ‹„¾ÿ‹…ÀÿŠ…Âÿ‰‡Ãÿ‰‡ÅÿˆˆÇÿ‡‡Çÿ‡‡Æÿ‡‡Æÿ‡‡Æÿ‡ˆÇÿ†ˆÈÿ†‰Êÿ…ŠÍÿ…‹Íÿ…‹Íÿ…ŠÌÿ…ˆÊÿ…‡Èÿ…†Çÿ†ˆÉÿ†‰Ëÿ†‰Ëÿ†‰Ëÿ†ˆÉÿ†ˆÈÿ‡‡Èÿ‡ˆÉÿ‡ŠÌÿ‡‹Îÿ‡‹Îÿ‡‹Îÿ‡ŠÍÿˆŠÍÿ‰ŠÌÿŠ‹ÍÿŠŽÏÿ‹�ÑÿŒ‘ÑÿŒ�ÑÿŒ�Ïÿ�ŽÎÿŽ�Îÿ��Ïÿ��Ïÿ�’Ïÿ‘’Îÿ’’Îÿ““Íÿ”“Íÿ•”Îÿ—–Ðÿ˜—Òÿ™˜Òÿ™˜Òÿ™™Òÿš™ÒÿššÒÿ››Ôÿ›œÕÿ›œÖÿ›�×ÿ›�×ÿ›�×ÿ›�×ÿ›žØÿšžÚÿ™ Ýÿ™¡ßÿ™¡àÿ™¢àÿš¢àÿš¡àÿš¡àÿš£âÿš¤ãÿ›¤ãÿ›¤ãÿ›£áÿ�£Þÿž ÙÿžžÕÿž�ÔÿžžÕÿ��×ÿž�ÕÿŸ�Òÿ¡�Ðÿ£�Îÿ¤žÌÿ¥žËÿ¥žÊÿ¦ŸÊÿ¥œÇÿ•‹±ÿ^TlÿK@Rÿncÿ‚w—ÿ‰}œÿ{n‡ÿZM^ÿ3&/ÿ.!(ÿ7)4ÿ/"*ÿK?Lÿn`tÿ€q‡ÿuexÿ[LXÿXIUÿqbsÿ�–ÿ«œ·ÿ±¢¾ÿ°¡¾ÿ±¢¿ÿ±¢¾ÿ²¢¾ÿ²¢¾ÿ³£¾ÿ³£¾ÿ³£½ÿ´¤½ÿ´¤½ÿ´¤½ÿµ¥½ÿ¶¥½ÿ¶¦½ÿ¶¦½ÿ¶¦½ÿ¶¦½ÿ¶¥¼ÿ¶¥¼ÿ·¦»ÿ·§¼ÿ¹¨¼ÿºª½ÿ»¬¾ÿ¼¬¾ÿ¼«½ÿ»«½ÿ»«½ÿ¼«¾ÿ½­¾ÿ¾®¾ÿ¿¯¿ÿÁ²ÁÿÄ´ÂÿƵÃÿƵÃÿƵÃÿƵÃÿƶÃÿƵÃÿŵÃÿŶÃÿŶÄÿƶÅÿŶÅÿŶÅÿŵÄÿŵÄÿŵÄÿÄ´ÃÿÄ´ÂÿÄ´ÂÿijÁÿijÁÿóÁÿóÁÿòÀÿòÀÿ²¿ÿ±¿ÿÁ±¿ÿÁ°¿ÿÀ¯¾ÿÀ¯¾ÿ¿®½ÿ¿®¼ÿ¾­»ÿ½¬ºÿ½¬ºÿ½«ºÿ½«ºÿ½«¹ÿ½«¹ÿ½ª¹ÿ¼ª¸ÿ»©·ÿ»¨·ÿº¨¶ÿº§¶ÿº§¶ÿ¹§µÿ¹§¶ÿ¹§·ÿ¹§·ÿ¸¥¸ÿ·¤¸ÿ¶£·ÿµ¢·ÿ´¡¶ÿ²Ÿ¶ÿ°žµÿ¯œ¶ÿ­›·ÿ«š¹ÿ¨˜¹ÿ§˜ºÿ§˜¼ÿ§˜½ÿ¨™¼ÿ¨™¼ÿªš»ÿ¬›ºÿ®œ¸ÿ®œ·ÿ¯�¶ÿ°žµÿ±žµÿ²žµÿ²žµÿ±�µÿ±�´ÿ°œ²ÿ°›²ÿ�€°ÿ��±ÿ��²ÿ��²ÿ��³ÿ��³ÿŒ�³ÿŒ�²ÿŒ�²ÿŒ�±ÿŒ€±ÿŒ€±ÿŒ€±ÿŒ€±ÿŒ�±ÿŒ�³ÿŒ�´ÿŒ‚¶ÿŒ‚¶ÿŒƒ·ÿ‹ƒ¹ÿŒ„ºÿŒ„»ÿŒ…½ÿ‹…ÀÿІÂÿ‰‡ÅÿˆˆÆÿ‡‰Çÿˆ‰Éÿˆ‰Éÿ‡‰Éÿ‡‰Êÿ†ŠËÿ†‹Ìÿ…ŠÌÿ…ŠËÿ†ˆÉÿ…‡Èÿ…†Æÿ††Åÿ††Æÿ‡ˆÇÿˆˆÉÿ‡ˆÈÿ‡‡Çÿ‡†Åÿ‡†Äÿ‡†ÆÿˆˆÉÿˆ‰ËÿˆˆÊÿˆ‡Èÿˆ‡Èÿ‰‡Èÿ‰ˆÉÿ‰‰ÉÿŠ‹Ëÿ‹ŒÍÿ‹�ÍÿŠ�Ìÿ‹ŒÌÿŒŒËÿŒŒÌÿ��ÎÿŽ�Ïÿ��ÏÿŽ�Ïÿ��Ïÿ�‘Ïÿ’’Ïÿ““Ðÿ“•Òÿ”–Ôÿ–—Õÿ–˜Õÿ–™Õÿ—™Ôÿ—™Ôÿ—šÕÿ—šÖÿ—šÖÿ—š×ÿ—š×ÿ–›Ùÿ—œÛÿ—�Üÿ–�Ýÿ•žßÿ–Ÿàÿ•Ÿáÿ– áÿ–¡âÿ—¡ãÿ˜£åÿ˜¥çÿ™¦èÿ™§èÿš¦çÿš¥åÿœ¥âÿ�£Þÿ�¡Üÿ� Ûÿ� Ûÿœ Ûÿ�ŸÚÿ�ŸØÿžŸ×ÿŸŸÖÿ¡ Õÿ¢ŸÓÿ£ŸÑÿ¤ Ðÿ¢œÉÿކ­ÿXNfÿ]Toÿƒ{ŸÿŒ‚§ÿ€u”ÿdXoÿL?Oÿ>1?ÿ3&.ÿ7+6ÿ2$.ÿZL^ÿte{ÿsdyÿpatÿWIUÿZLZÿrcwÿˆz’ÿ©›¸ÿ°¡Àÿ°¡Àÿ°¡Àÿ±¡Àÿ±¢¿ÿ²¢¾ÿ³£¿ÿ³£¿ÿ²£¾ÿ³£¾ÿ³¤¾ÿ³¤¾ÿ´¥¾ÿµ¦¿ÿµ¦¿ÿµ¦¾ÿµ§¾ÿ¶§¾ÿ·§½ÿ·§½ÿ·§½ÿ·¨½ÿ¸¨½ÿ¹©½ÿ»¬¿ÿ¼­Àÿ½®Àÿ½®Àÿ½®Àÿ½®Àÿ½¯Àÿ½®¾ÿ¾®¾ÿ¿°¿ÿ³ÁÿÅ´ÂÿƶÃÿƶÄÿǶÄÿÇ·ÄÿÇ·ÅÿÆ·ÅÿÆ·ÅÿÆ·ÅÿÆ·ÆÿÆ·ÇÿÆ·ÇÿƸÆÿǸÆÿÇ·ÆÿÆ·ÅÿÆ·ÅÿÆ·ÄÿƶÄÿƶÃÿŶÃÿƶÃÿƶÄÿƶÃÿƶÃÿŵÂÿĵÁÿôÁÿôÀÿóÁÿóÀÿò¿ÿ²¾ÿÁ±½ÿÁ°½ÿÀ¯¼ÿÀ¯¼ÿÀ®»ÿÀ¯»ÿÀ®»ÿ¿®ºÿ¾¬ºÿ½¬¹ÿ¼«¹ÿ¼«¹ÿ»ª¸ÿ»ª·ÿ»©·ÿ»¨¸ÿ»¨¸ÿº§¸ÿ¹¦¸ÿ¸¦·ÿ¸¥¶ÿ·¤µÿ¶£µÿµ¢µÿµ¡´ÿ³¡´ÿ² µÿ¯ž¶ÿ­œ·ÿ­›·ÿ­œ·ÿ­œ·ÿ­œ¶ÿ®œ¶ÿ¯œµÿ±�µÿ±�´ÿ±Ÿµÿ²Ÿµÿ²Ÿµÿ²Ÿ¶ÿ²Ÿ¶ÿ²ž¶ÿ±žµÿ±�´ÿ¯œ³ÿŒ~ªÿŒ~«ÿ�¬ÿ�€­ÿ�€®ÿŒ€®ÿŒ€®ÿ‹®ÿ‹®ÿ‹®ÿ‹®ÿ‹®ÿ‹®ÿ‹®ÿ‹¯ÿŠ€°ÿŠ€±ÿŠ�´ÿ‹�µÿ‹�´ÿ‹‚´ÿŒƒµÿŒƒµÿ‹ƒµÿ‹‚·ÿŠ‚¸ÿŠƒ»ÿ‰„½ÿˆ…Àÿ‡†Äÿ‡‡Åÿ‡‡Æÿ‡ˆÇÿ‡‰Èÿ‡‰Éÿ‡‰Éÿ‡ˆÈÿ‡ˆÇÿ‡ˆÇÿ‡ˆÈÿ‡‡Çÿ‡‡Æÿ‡‡Åÿ‡ˆÆÿ‡ˆÇÿ†‡Æÿ†‡Æÿ‡†Äÿˆ†Äÿ‰‡ÆÿˆˆÇÿ‰ˆÇÿ‰ˆÆÿ‰‡ÆÿŠˆÆÿŠˆÆÿ‰‡Çÿ‰ˆÈÿ‰‰ÈÿЉÉÿ‰ŠÉÿŠŠÊÿŠŠÊÿ‹‹ÊÿŒ‹ÊÿŒ�ËÿŒŽÌÿ�ŽÎÿŽ�ÏÿŽ�Ïÿ�‘Ðÿ�’Ñÿ�“Òÿ�”Óÿ‘•Óÿ“–Ôÿ“—Ôÿ“—Õÿ“˜Öÿ”™Øÿ“šÙÿ“šÚÿ’šÛÿ’™Üÿ’šÞÿ’œßÿ’�àÿ’�âÿ’žãÿ“Ÿãÿ“ äÿ”¡åÿ”¡åÿ”¢æÿ•£èÿ•¥êÿ•¦ëÿ–¦ëÿ—¥éÿ˜¥èÿ˜¥æÿš¥åÿš¥äÿš¥äÿ›¥ãÿ›¥ãÿœ¥âÿœ¤áÿ›¤àÿ›£ßÿ�¢Þÿ�¡Üÿž¡Øÿ¡¡ÕÿžœÌÿ†€¨ÿRIaÿke…ÿˆƒ«ÿxo�ÿh]xÿG;Mÿ8-;ÿ;1@ÿ/#,ÿ,"+ÿ.!*ÿB4BÿTEWÿXJ[ÿM@MÿMBMÿXLZÿfXjÿ~p‡ÿ§š¹ÿ¯¢Âÿ¯¢Âÿ¯¢Âÿ°¢Áÿ±¢Àÿ²¤¿ÿ²¤¿ÿ³¥¿ÿ³¥¿ÿ³¥¿ÿ³¥¿ÿ´¥Àÿµ¦Àÿµ§Àÿµ§Àÿµ¨Àÿ¶©Àÿ·ªÀÿ¸ª¿ÿ¸«¿ÿ¹ª¿ÿ¹ª¿ÿº«Àÿº«Áÿ»­Áÿ¼®Âÿ½°Ãÿ¾±Äÿ¿²Äÿ¿²Ãÿ¿³ÂÿÀ²ÁÿÀ±ÀÿÀ°¿ÿÀ²¿ÿóÁÿŵÃÿÆ·ÄÿÇ·ÅÿÇ·ÅÿǸÅÿǸÆÿǸÆÿǸÆÿƹÆÿƹÇÿƹÇÿǹÇÿȹÈÿǺÇÿȹÇÿȹÇÿǹÆÿȹÅÿǹÅÿȹÅÿȹÅÿȺÆÿȺÆÿɺÇÿȺÆÿȹÅÿǸÄÿÆ·ÃÿÆ·ÃÿÆ·ÃÿƶÃÿƶÂÿŵÁÿŵÁÿÅ´Àÿij¿ÿó¿ÿó¾ÿò¾ÿò¾ÿ±¾ÿÁ°½ÿÀ¯¼ÿÀ¯»ÿ¿®»ÿ¾­ºÿ¾¬ºÿ¼«¸ÿ¼ª¸ÿ¼ª¸ÿ»©¸ÿ»¨·ÿ¹§¶ÿ¹§¶ÿ¸¦¶ÿ¸¤¶ÿ¶£¶ÿµ¢µÿ´¢µÿ´¡´ÿ³¡µÿ² µÿ³ µÿ³¡´ÿ²¡µÿ² µÿ±Ÿ´ÿ°ž´ÿ±ž´ÿ±Ÿµÿ²Ÿµÿ²žµÿ°�´ÿ¯œ³ÿ­›³ÿ­š³ÿ­š²ÿ¬š±ÿ‹|¥ÿ‹|¦ÿŒ|§ÿŒ}§ÿ‹}¨ÿ‹}©ÿ‹}©ÿ‹}©ÿŠ}©ÿ‹}ªÿŠ~¬ÿŠ~­ÿŠ~­ÿŠ~®ÿŠ~¯ÿŠ€°ÿ‰€°ÿŠ€²ÿŠ€´ÿŠ€³ÿ‹�³ÿŒ�´ÿŒ‚´ÿ‹‚´ÿŠ�´ÿ‹�µÿ‹‚¶ÿŠ‚·ÿŠ‚¹ÿ‰ƒ»ÿ‰„½ÿˆ„¾ÿˆ…¿ÿˆ†Àÿ‰†Áÿ‰‡Âÿ‰†ÂÿІÁÿ‰‡Áÿ‰ˆÂÿ‰ˆÄÿˆˆÄÿˆ‰ÆÿˆŠÉÿˆ‹Ëÿˆ‹ËÿˆŒËÿ‰‹Êÿ‰ŠÈÿЉÇÿЉÆÿ‰‰Çÿˆ‰ÇÿˆˆÈÿ‰ˆÈÿˆˆÈÿˆˆÉÿˆ‰ÊÿˆŠÊÿˆŠÊÿ‰‹Ëÿ‰‹Ëÿ‰‹ÌÿŠ‹ËÿŠŒËÿŠŒËÿŠŒËÿ‹�ËÿŒŽËÿŒŽÌÿ��ÍÿŽ‘ÏÿŽ’Ðÿ�“Ðÿ�“Ñÿ�”Ñÿ‘•Òÿ‘—Ôÿ‘˜Öÿ‘™Ùÿ‘šÜÿ‘šÞÿ�šàÿŽšáÿŽšâÿŽœãÿŽ�åÿŽžæÿ�žçÿ�Ÿèÿ� èÿ‘¡éÿ’£êÿ’£ëÿ’£ëÿ’¥ìÿ’¥ìÿ“¤ëÿ”¤ëÿ”£êÿ”£éÿ•¤çÿ–¤çÿ—¥èÿ˜¦èÿ˜¦èÿš¥çÿ›¥æÿš¦åÿš¦äÿœ¥ãÿ�¥áÿ�¤Þÿž¢Úÿ››Ïÿ|x¡ÿLC\ÿUMhÿe^~ÿH?Sÿ<1?ÿ3%0ÿ/!+ÿ.!+ÿ+&ÿ,&ÿ+%ÿ2$.ÿ6(4ÿ1%.ÿ+'ÿ-"(ÿ2&.ÿE9Fÿocyÿ¥š¹ÿ°£Ãÿ°£Âÿ°¤Âÿ±¤Áÿ²¤Àÿ²¥¿ÿ²¥¿ÿ´¦¾ÿµ¨¿ÿµ¨Àÿµ¨Áÿ¶¨Áÿ¶¨Áÿ·ªÂÿ·ªÂÿ¸«Ãÿ¸«Ãÿ¸¬Ãÿº®Ãÿ»®Ãÿ½°Äÿ½°Åÿ½°Åÿ½°Åÿ¾°Åÿ¾±Äÿ¾²ÄÿÀ´ÆÿõÇÿöÇÿöÆÿĶÅÿĶÅÿõÃÿõÃÿôÂÿôÂÿÅ·ÄÿȹÆÿɹÇÿɺÇÿÈ»ÈÿÈ»ÈÿÈ»ÉÿÇ»ÉÿÇ»ÈÿƺÉÿƺÉÿǺÈÿÈ»ÉÿÉ»ÉÿÈ»ÈÿÈ»ÈÿɼÈÿɼÈÿɼÇÿɼÇÿɼÈÿʼÈÿʼÈÿʼÇÿʼÇÿÊ»ÇÿÉ»ÇÿÉ»ÆÿɺÆÿɺÆÿȹÅÿǸÄÿǸÄÿǸÄÿÇ·ÃÿÆ·ÂÿƶÂÿƶÂÿƵÁÿŵÀÿÄ´¿ÿó¿ÿò¾ÿ²½ÿÁ±¼ÿÀ¯¼ÿ¿®»ÿ¾­ºÿ½¬¹ÿ½«¸ÿ¼«¸ÿ¼ª·ÿ»ª¸ÿº¨·ÿ¹¦¶ÿ¸¥µÿ·¥µÿ·¥µÿ·¥µÿ·¥µÿ¶¥¶ÿ¶¤¶ÿµ¤¶ÿ´£µÿ³¢µÿ³¡µÿ²¡µÿ³ µÿ²Ÿ´ÿ²Ÿ³ÿ°ž³ÿ®›±ÿ¬™¯ÿ¨•­ÿ§“¬ÿ¦’«ÿ¥‘ªÿŒ|£ÿŒ{¤ÿ‹{¤ÿ‹{¤ÿŒ{¤ÿŒ|¤ÿ‹|¤ÿ‹|¤ÿ‹|¤ÿŠ|¤ÿ‰|¦ÿ‰|§ÿ‰|§ÿ‰|§ÿ‰|¨ÿ‹}¨ÿ‹~©ÿ‹~ªÿ‹~ªÿ‹~ªÿŒªÿŒ¬ÿŒ€­ÿŒ€­ÿŒ€­ÿŒ€¯ÿŒ€¯ÿŒ�°ÿŒ�°ÿŒ�°ÿŒ�±ÿ‹�²ÿ‹‚³ÿ‹‚´ÿ‹ƒ´ÿ‹„µÿ‹„¶ÿŒ„·ÿŒ…¸ÿŒ…¸ÿŒ…¹ÿ‹†ºÿŒ‡½ÿŒˆÀÿ‹‰Äÿ‰ŠÇÿ‰ŒÉÿ‰�Êÿ‰ŒËÿ‰‹Ëÿ‰‹ËÿˆŒÌÿˆŒÌÿ‡ŒÍÿ‡ŒÎÿ‡ŒÎÿ‡ŒÏÿ†ŒÐÿ‡ŒÏÿ‡�Îÿ‰�Íÿ‰ŒÍÿŠ�ÍÿŠ�Íÿ‹ŽÍÿŠŽÎÿŠ�Ïÿ‹�Ïÿ‹ŽÍÿ‹�Ëÿ‹�ÊÿŒ�Ëÿ��ÍÿŽ�Ïÿ�’Ñÿ�“Óÿ�•Õÿ�–×ÿ�—Ùÿ�˜ÜÿŽ™ßÿ�™áÿŒ™áÿŒ™áÿ‹™âÿ‹šäÿ‹œçÿ‹�êÿ‹ŸìÿŒ ìÿ� ëÿ� êÿ�¡ëÿ�¢ëÿ�£ìÿ�¤îÿ‘¤îÿ‘¤íÿ‘£ìÿ‘£ìÿ’¤ìÿ“¤ëÿ”£êÿ”£éÿ–¥éÿ—¥éÿ˜¦èÿ™¥çÿ™¥çÿ™¥çÿš¦æÿ›¦åÿœ¥âÿ�¥àÿ˜œÓÿrp—ÿE4?ÿ4(3ÿ+%ÿ)!ÿ' ÿ("ÿ.(ÿ-&ÿ,$ÿ,$ÿ. %ÿ0#(ÿ4',ÿNBLÿ—“¢ÿÀ¾ÑÿÂÀÓÿÃÁÔÿÃÁÔÿÃÁÓÿÃÁÓÿÂÀÒÿ¿Ñÿ¾Ñÿ¾ÑÿÁ½ÑÿÁ½ÐÿÁ½ÏÿÁ¼ÏÿÁ»ÎÿÁ»ÍÿÀºÍÿÀºÍÿÀºÍÿ¿ºÍÿ¿ºÌÿ¿ºÌÿ¿¹Ìÿ¿¹Ëÿ¿¹Ëÿ¿¹ËÿÀ¹ËÿÀ¹ÊÿÀ¸Êÿ¿¸Éÿ¾¸Éÿ¾¶Çÿ½µÆÿ»³Åÿº²Ãÿº²Ãÿº³Âÿ»³Ãÿº´Ãÿ»´Äÿ¼´Åÿ¼´Åÿ½µÆÿ¾·Çÿ¿¹ÈÿÁ»Êÿ¼ËÿľÌÿľÌÿýËÿ»ÊÿÁºÉÿ¾·Çÿ¾·ÇÿºÊÿŽÌÿÅ¿ÍÿÆÀÎÿÆÁÎÿÆÁÎÿÆÁÎÿÆÂÎÿÅÁÎÿÆÁÎÿÆÁÎÿÆÀÎÿÆÀÎÿÅ¿ÍÿĽÍÿ»ÌÿÁºËÿ¿¹Êÿ¾·Èÿ¼µÆÿ¹³Åÿ¸°Åÿ¶¯Æÿµ®Æÿ³¬Æÿ°ªÆÿ®©Æÿ®¨Çÿ¯ªÈÿ°«Éÿ±­Êÿ³®Ëÿ³®Ëÿ²®Ëÿ²®Ëÿ²¯Ìÿ²¯Ìÿ²°Íÿ²°Ðÿ³±Òÿ¶³Ñÿ¸µÏÿ¹µÍÿ¹´Ëÿµ°Æÿµ¯Æÿ¸³ÉÿºµËÿº´Éÿ»µÉÿº´Èÿº´Çÿº´Çÿº³Åÿ¹²Äÿº²Äÿ¹²Ãÿ¹±Ãÿ‰«ÿ‰«ÿŠ«ÿŠ€«ÿŠ€«ÿ‹�«ÿ‹�«ÿ‹�¬ÿ‹�¬ÿŒ�«ÿ�‚«ÿŒ‚«ÿŒ‚«ÿŒ‚«ÿ�‚¬ÿ�ƒ¬ÿ�‚«ÿ�‚«ÿ�ƒ«ÿ�ƒ«ÿ�ƒ¬ÿ�ƒ¬ÿŽƒ¬ÿŽƒ«ÿŽƒ«ÿŽƒ¬ÿŽƒ«ÿŽƒ«ÿ�ƒ«ÿ�‚«ÿ�‚«ÿ�‚«ÿ�‚«ÿŽƒ«ÿŽ„¬ÿŽ„¬ÿ�…¬ÿ�„¬ÿ�„«ÿŽ„«ÿ�„«ÿ�„«ÿ�„«ÿ�„«ÿ�ƒ¬ÿŽƒ«ÿŽƒ«ÿŽ„¬ÿ�„¬ÿ�„¬ÿ�†®ÿ‘†¯ÿ‘‡¯ÿ’‡¯ÿ‘‡®ÿ’ˆ¯ÿ’‰¯ÿ“аÿ“аÿ’аÿ“‹°ÿ“Œ±ÿ”Œ±ÿ•�±ÿ–�²ÿ–�³ÿ–޳ÿ—�³ÿ—�³ÿ—�³ÿ—�³ÿ˜‘´ÿš“¶ÿœ•·ÿž˜¸ÿ šºÿ¢�¼ÿ£ž½ÿ¥Ÿ¾ÿ¥ ¿ÿ¦¡Àÿ§¢Áÿ¨£Âÿª¥Âÿ«¦Ãÿ¬§Ãÿ¬¨Äÿ­©Äÿ®ªÅÿ¯¬Æÿ°­Çÿ±®Èÿ³¯Éÿ´±Êÿµ³Ëÿ¶´Ëÿ¸¶Íÿ¹·Îÿº¸Îÿº¹Îÿ»¹Îÿ»¹Îÿ»¹Ïÿº¸Ïÿº¹Ïÿ»ºÎÿ¼»Ïÿ¼»Ðÿ½¼Ðÿ¾¼Ðÿ¾½Ðÿ¿¾Òÿš˜©ÿWMZÿ4&0ÿ3%0ÿ5'1ÿ5'1ÿ3%.ÿ0",ÿ3&/ÿ8)3ÿA5BÿE:Jÿ>1@ÿ6&1ÿ:+4ÿ7*2ÿ3&.ÿ5&0ÿ4%.ÿ2#+ÿ2#*ÿ3$,ÿ5'/ÿ:,3ÿC5?ÿ†€‘ÿ±­Âÿ¹·Ëÿ¼¹Íÿ¼¹Íÿ¼¹Íÿ¼¹Íÿ¼¹Íÿ¼¸Ìÿ¼¸Ìÿ¼¸Ìÿ½¸Ëÿ½¸Ëÿ¼¸Êÿ¼·Êÿ¼·Êÿ½·Ëÿ¼¶Êÿ»¶Êÿ»¶Éÿ»µÈÿºµÈÿºµÈÿº´Èÿ»µÈÿ¼µÈÿ¼µÈÿ¼µÈÿ¼´Çÿ»³Æÿº³Åÿ¹²Äÿ¸±Âÿ·¯Áÿ¶­Àÿµ¬¿ÿµ­¾ÿµ­¾ÿµ¬¾ÿ´¬½ÿ³«½ÿ³«¼ÿ´«½ÿµ­¿ÿ¶¯Àÿ¸²Ãÿ»µÆÿ¿¹ÉÿÀºÊÿÁ¼ÌÿÁ¼ÌÿÁ¼ÌÿÁ¼ËÿÁ»Ëÿ¿¸Èÿ¿¸ÈÿÀºÊÿ¼ËÿþÌÿÄ¿ÍÿÄÀÎÿÄÀÎÿÄÁÎÿÄÁÏÿÅÁÏÿÅÁÏÿÆÁÏÿÅÁÏÿÅÀÏÿþÍÿ½ÌÿÀ¼Ëÿ¿ºÊÿ½¸Èÿº´Æÿ·±Åÿ´®Ãÿ³¬Äÿ±ªÄÿ®¨Äÿ«¥Ãÿ©£Ãÿ§¢Äÿ¨£Åÿª¥Çÿ¬§Éÿ­©Êÿ­©Ëÿ­ªËÿ®ªËÿ®«Ëÿ®«Ëÿ°­Íÿ°®Ñÿ²°Õÿ´³×ÿ·¶Öÿ¹¸Õÿº¸Óÿ¸¶Ïÿ¶³Ìÿ´±Ëÿµ±Ìÿ·²Ìÿ¸´Ëÿ¸µËÿ¹µÊÿº¶Êÿ¼·Êÿ»·Éÿ¼·Èÿ½·Èÿ¼¸Èÿˆ€®ÿ‰€®ÿ‰€®ÿ‰€®ÿ‰€®ÿŠ�­ÿ‹�­ÿŠ�¬ÿ‹�¬ÿŒ‚­ÿ‹‚­ÿ‹‚¬ÿ‹‚¬ÿ‹‚¬ÿ‹‚¬ÿ‹�«ÿ‹�«ÿ‹�«ÿŒ‚¬ÿŒ‚«ÿ‹�«ÿ‹�«ÿŒ�«ÿŒ�«ÿŒ�ªÿŒ�«ÿŒ�«ÿ‹€«ÿ‹�ªÿ‹�«ÿ‹€«ÿŠ�ªÿ‹�ªÿ‹�«ÿŒ�¬ÿŒ‚¬ÿ�ƒ­ÿ�ƒ­ÿŽ„­ÿ�…­ÿ�…­ÿŽ…­ÿŽ…¬ÿŽ…¬ÿŽ„­ÿ�…­ÿ�…­ÿŽ„­ÿ�„­ÿ�…®ÿ�†¯ÿ�‡°ÿ’ˆ°ÿ’ˆ±ÿ’‰±ÿ’бÿ“‹²ÿ“‹²ÿ“‹±ÿ“‹±ÿ”Œ²ÿ“Œ±ÿ”�²ÿ•޳ÿ–�´ÿ–�´ÿ—�µÿ˜‘¶ÿ™“·ÿš”·ÿ›”·ÿœ–¹ÿž˜ºÿŸš»ÿ¢œ½ÿ¤ž¾ÿ¤Ÿ¿ÿ¤ ¿ÿ¥¡Àÿ¦¡Áÿ¦¢Áÿ§£Âÿ¨¤Âÿ©¥Ãÿª§Äÿ«©Äÿ¬©Åÿ­ªÆÿ¯¬Çÿ±®Èÿ²¯Êÿ³°Êÿ³±Ëÿµ²Ìÿ¶´Íÿ·¶Îÿº¸Ïÿ»ºÐÿ¼»Ñÿ¼¼Òÿ½¼Ñÿ½¼Ñÿ¼»Ñÿ»ºÐÿ»¹Ïÿ»ºÏÿ»ºÏÿ»ºÐÿ»ºÐÿ»»Ðÿ¼»Ðÿ¸·Ëÿ�‹œÿHÿF8BÿF8BÿC4?ÿ8)3ÿ4%-ÿ4%.ÿ7'1ÿ9)3ÿ:+4ÿ;.7ÿxr�ÿ¤Ÿ´ÿ´¯Äÿµ±Åÿµ±Åÿ´¯Åÿ³®Äÿ²®Äÿ³®Âÿ²­Ãÿ²­Âÿ³­Âÿ´®Ãÿ´®Ãÿ´®Ãÿµ®Äÿµ¯Äÿ¶¯Ãÿµ¯Âÿµ®Ãÿ³­Âÿ²¬Áÿ²«Àÿ²«Àÿ²«Àÿ³¬Àÿ³¬Àÿ´¬Àÿ´¬Àÿ³¬Àÿ³¬Àÿ³¬¿ÿ²ª¾ÿ±¨¼ÿ±¨¼ÿ³ª¾ÿ³«¿ÿ²©½ÿ²©¾ÿ±¨¼ÿ¯§»ÿ¯¦ºÿ²¨¼ÿµ¬¿ÿ¶¯Âÿ·±Äÿ¹³Æÿ»µÆÿ»¶Çÿ¼·Èÿ¼·Èÿ¼¸Èÿ¼¹Éÿ½¹Éÿ½¹Éÿ½¸Éÿ½¸Èÿ½¸Éÿ½¸Éÿ¿¼ËÿÁ½ÌÿÁ½ÍÿÁ¾ÍÿÁ¾ÍÿþÍÿÄ¿ÎÿÄ¿ÎÿÿÎÿ¾Íÿ¾ÍÿÁ¾ÍÿÁ¾Íÿ¾Íÿ¾Îÿ¿ÎÿÁ¾ÎÿÁ¾Îÿ¿½Îÿ¿¼Íÿ¾»Îÿ¼ºÎÿ¹¸Íÿ¶³Ëÿ±¯Êÿ¬©Èÿ¨¤Èÿ¦¢Çÿ¦¢Çÿ©¦Èÿ­«Êÿ°®Ëÿ±¯Ìÿ°®Ìÿ®¬Íÿ®«Ïÿ°®Ñÿ³³Óÿ¶¶Õÿ·¸ÖÿººÕÿº¹Óÿ·µÏÿµ²Ëÿº·Îÿ½ºÏÿ¾»Ïÿ¾¼ÐÿÀ¾ÐÿÁ¾ÐÿÀ¾ÏÿÀ½ÎÿÀ¼Íÿ¿¼Ìÿ‡�±ÿˆ�±ÿ‡�±ÿ‡€±ÿ‡€±ÿˆ�¯ÿˆ�¯ÿ‰�¯ÿŠ�¯ÿŠ�®ÿŠ�®ÿŠ‚®ÿ‹‚­ÿ‹‚­ÿ‹‚­ÿŠ�¬ÿŠ€¬ÿŠ€¬ÿŠ�¬ÿŠ�¬ÿ‰€¬ÿ‰€«ÿŠ€«ÿŠ€«ÿŠ€«ÿŠ€«ÿŠ�«ÿŠ€«ÿŠ€«ÿŠ€«ÿ‰€«ÿ‰€«ÿ‰€«ÿ‰€¬ÿŠ€¬ÿ‹�¬ÿ‹�¬ÿ‹�¬ÿŒ‚­ÿ�ƒ­ÿŽ„­ÿŽ…®ÿŽ…­ÿ�…­ÿŽ…®ÿ�…®ÿ�†¯ÿ�†¯ÿ�†°ÿ‘‡°ÿ‘‡°ÿ‘ˆ±ÿ’‰²ÿ“гÿ’гÿ’вÿ’вÿ’вÿ“‹²ÿ“‹³ÿ”‹³ÿ”�´ÿ•Ž´ÿ–�µÿ˜’¶ÿ™“·ÿ™”¸ÿš•¹ÿœ—ºÿž™»ÿŸš½ÿ œ½ÿ¢�¾ÿ£Ÿ¿ÿ¤ Àÿ¤ Àÿ¤ Àÿ¥¡Áÿ§£Âÿ©¥Äÿª§Æÿ«¨Æÿ«¨Æÿ¬©Æÿ¬ªÇÿ­ªÇÿ­ªÇÿ­«Çÿ®¬Çÿ°¬Èÿ°­Èÿ°­Èÿ°­Èÿ¯­Éÿ°®Éÿ±¯Éÿ²°Éÿ²°Êÿ³°Êÿ´±Êÿ´²Êÿ´²Ëÿµ³Ëÿµ³Ëÿµ²Ëÿµ²Ëÿµ³Ëÿ¶´Ìÿ·µÌÿ¸¶Íÿ¸¶Ìÿ®«Áÿ‚}Žÿ;-8ÿ.'ÿ0!(ÿ-%ÿ*"ÿ,&ÿ0#,ÿ+&ÿ-!'ÿ7*0ÿ=07ÿ:.5ÿ5)0ÿ;/6ÿA4<ÿA4<ÿ=08ÿ2%-ÿ,%ÿ*!ÿ+#ÿ. 'ÿ1$+ÿ0#*ÿhapÿ—’§ÿ°¬Ãÿ²®Äÿ²®Ãÿ±®Ãÿ°­Ãÿ±¬Ãÿ±«Áÿ±«Áÿ°«Áÿ°«Áÿ¯©Àÿ®¨¿ÿ­§¿ÿ­¦¿ÿ®¦¾ÿ®¦¾ÿ­¦½ÿ­¥¼ÿ¬¤¼ÿ«¤»ÿ¬¤»ÿ­¤»ÿ­¥¼ÿ­¥¼ÿ®¦¼ÿ¯¦¼ÿ¯¦¼ÿ°§½ÿ°¨¾ÿ¯§½ÿ­¥»ÿ­¤ºÿ¬£ºÿ¬£ºÿ¬¤ºÿ­£ºÿ­£ºÿ­¤ºÿ­¤ºÿ¬¤ºÿ®¦»ÿ³ª¾ÿµ­Àÿµ®Âÿ¶°Äÿ¹²ÆÿºµÇÿº¶Èÿ»·Èÿ½¸Éÿ½ºÊÿ¾ºËÿ¾ºËÿ½¹Ëÿ½¸Êÿ½¸Éÿ»·Èÿ¼¹Éÿ¾ºËÿ¾ºËÿ¾ºËÿ¾»ÌÿÀ»ÌÿÁ»ÌÿÁ¼ÌÿÀ¼ÌÿÀ¼ÌÿÀ¼ÌÿÀ½ÌÿÁ¾ÍÿÁ¾ÎÿÁ¾ÎÿÁ¿ÎÿÁÀÎÿÁÀÏÿÁÀÏÿÂÀÏÿÁÀÐÿÀ¿Ñÿ¿¾Ñÿ¼ºÐÿ¹·Íÿ¶´Ìÿ´²Ìÿ³°Ìÿ±®Ëÿ°®Éÿ±¯Éÿ³±Êÿ´²Êÿ´²Ëÿ³²Ìÿ³±Ìÿ³±Íÿ³²Íÿ´³Îÿ¶µÐÿ¸·Ñÿ¹¸Ñÿ¸¶Îÿµ±Éÿ´°Çÿ¶²Èÿ·²Èÿ¶±Çÿ¶±Æÿ·³Çÿº¶Êÿ¼¹Ìÿ¾»Íÿ¿»Íÿ†ƒ¸ÿ†‚¸ÿ†‚·ÿ†�¶ÿ‡�µÿ‡�³ÿ†�³ÿ‡�²ÿˆ�²ÿˆ�±ÿˆ�±ÿˆ�°ÿ‰‚°ÿ‰�¯ÿ‰�¯ÿ‰�®ÿ‰€­ÿ‰€­ÿ‰€­ÿ‰€­ÿˆ€­ÿˆ€¬ÿˆ€¬ÿ‰€¬ÿ‰€¬ÿˆ€¬ÿ‰€¬ÿŠ€¬ÿŠ€¬ÿŠ€¬ÿŠ€¬ÿ‰€¬ÿ‰€­ÿŠ€­ÿŠ€­ÿŠ€­ÿŠ€­ÿŠ�­ÿŠ�­ÿ‹‚®ÿŒ‚®ÿŒ„®ÿŒ„®ÿŒ„®ÿŒ„¯ÿ�„¯ÿŽ…°ÿ�†°ÿ�‡±ÿ�‡±ÿ‘‡±ÿ�ˆ±ÿ‘ˆ²ÿ‘‰³ÿ‘‰³ÿ‘‰³ÿ‘‰³ÿ’гÿ“Œ´ÿ”�µÿ•޵ÿ–�¶ÿ—‘·ÿ˜“¸ÿ™•¹ÿ›–ºÿ›—»ÿœ˜»ÿ�™¼ÿŸš½ÿŸ›¾ÿ �¾ÿ¡ž¾ÿ¢Ÿ¿ÿ£ŸÀÿ¢ Áÿ£ Àÿ¤¡Áÿ¦£Ãÿ¨¥Äÿª§Æÿª¨Çÿ«©Çÿ«©Çÿ¬©Çÿ¬©Çÿ¬ªÇÿ«ªÇÿ¬ªÇÿ­ªÇÿ®«Çÿ®«Çÿ­«Çÿ¬«Çÿ¬ªÇÿ­ªÆÿ­ªÆÿ­ªÆÿ­©Åÿ­©Åÿ­©Åÿ­©Åÿ­ªÅÿ®ªÅÿ®ªÆÿ®ªÆÿ¯«Æÿ°¬Çÿ±­Çÿ±¯Èÿ±®Çÿ œ³ÿsm~ÿ1$,ÿ*"ÿ-%ÿ)!ÿ%ÿ' ÿ+$ÿ$ÿ0&*ÿ>38ÿD8=ÿC7<ÿ>48ÿ@6:ÿC7<ÿB6;ÿ<06ÿ/")ÿ%ÿ"ÿ%ÿ*#ÿ+$ÿ)!ÿUNZÿ‹†™ÿ°®Æÿ²¯Çÿ²¯Æÿ²°Æÿ²¯Æÿ²®Æÿ²­Åÿ²®Åÿ²®Åÿ²®Åÿ±¬Ãÿ°¬Âÿ¯ªÁÿ®©Áÿ®¨Àÿ®§¿ÿ­¦¾ÿ¬¥½ÿ«¤¼ÿª£¼ÿª¢»ÿª¢»ÿª¢»ÿª¢»ÿª¢»ÿª¡ºÿª¡ºÿ«¡ºÿª¢»ÿª¡ºÿ©¡¹ÿ©Ÿ¸ÿ§�¸ÿ¦œ·ÿ¦œ¶ÿ¦œ¶ÿ§œ¶ÿ¨�·ÿ§ž¶ÿ§ž¶ÿ§Ÿ¶ÿ«¢¹ÿ­¤ºÿ­¤»ÿ­¥¼ÿ¯§½ÿ°©¿ÿ±«Àÿ³­Áÿµ¯Âÿ¶°Ãÿ·²Åÿ·²Æÿ·²Åÿ·±Åÿ¸±Äÿ¶±Äÿ·±Åÿ·²Åÿ·²Åÿ·²Äÿ·²Åÿ¸³Æÿ¹´Æÿº´Æÿ¹´Åÿ¹´Æÿ¹´Æÿ¹µÆÿ¹µÆÿ¹µÇÿº¶Èÿ»¸Éÿ»¹Éÿ»¹Êÿ»¹Ëÿ»¹Ëÿ»¹Íÿ»¹Íÿº¸Îÿ¹·Îÿ¸µÍÿ·µÌÿ·µÌÿ·´Ìÿµ²Êÿ²®Æÿ¯¬Äÿ°¬Äÿ²¯Æÿ´²Èÿ·µËÿ¸¶Ëÿ·µËÿ¶´Êÿ·´Êÿ·´Ëÿ·µËÿ·´Ëÿµ²Éÿ±¬Äÿ«¥½ÿ©¢»ÿ©¡¹ÿ¨ ¹ÿ©¡ºÿ®§¾ÿ´¯Ãÿ¸´Èÿº·Êÿ¼¸Ëÿƒƒ½ÿƒƒ½ÿ„ƒ¼ÿ„ƒ»ÿ…‚ºÿ…‚¸ÿ…‚·ÿ…�·ÿ…�¶ÿ…�¶ÿ…€´ÿ…�³ÿ†�³ÿ†�²ÿ†€²ÿ†€°ÿ‡€¯ÿ‡€°ÿ‡€°ÿ‡€¯ÿ‡€¯ÿ‡€®ÿˆ®ÿˆ€®ÿ‡€®ÿ‡®ÿˆ€®ÿˆ€®ÿˆ€®ÿ‰€¯ÿ‰€¯ÿ‰€¯ÿ‰�¯ÿ‰�¯ÿŠ�¯ÿ‰�¯ÿ‰�¯ÿ‰‚¯ÿŠ‚¯ÿ‹‚¯ÿ‹‚¯ÿ‹ƒ¯ÿ‹ƒ¯ÿ‹ƒ°ÿ‹ƒ°ÿŒ„°ÿŒ…°ÿ�†°ÿކ±ÿ�†±ÿ�‡±ÿ�‡±ÿ�‡²ÿ�‡²ÿ�ˆ²ÿ�‰³ÿ�‰´ÿ’‹´ÿ“Œµÿ”޶ÿ•�¶ÿ–‘·ÿ—“¸ÿ˜”¹ÿ™•ºÿ™•ºÿš–»ÿ›—¼ÿœ—¼ÿœ˜¼ÿœ™¼ÿ�š¼ÿž›¼ÿŸ›½ÿŸœ¾ÿŸ�¿ÿ �¿ÿ¢žÀÿ¤ Áÿ¥¢Âÿ¦£Ãÿ§¥Äÿ§¦Äÿ¨¦Äÿ¨¦Äÿ¨¦Äÿ¨¦Äÿ©¦Äÿ©¦Åÿ©§Åÿª¨Æÿ«¨Æÿª¨Åÿª¨Åÿª¨Æÿ«©Æÿª¨Æÿª¨Æÿ«§Åÿª§Äÿª¦Äÿ©¥Ãÿ©¥Ãÿ¨¥Ãÿ©¦Ãÿ©¥Ãÿª¦Äÿª¦Äÿª§Äÿª¨Äÿ©§Ãÿ�‹¢ÿe]nÿ7+4ÿ(!ÿ."(ÿ)"ÿ$ÿ& ÿ(!ÿ"ÿ>4:ÿLAIÿOEMÿODMÿNDOÿNDNÿNDNÿMCMÿI>Hÿ8+4ÿ& ÿ ÿ)!ÿ1%+ÿ- &ÿ+$ÿB8Aÿ}xŠÿ¯­Æÿ±¯Çÿ±¯Çÿ±¯Æÿ±®Æÿ±®Æÿ²®Æÿ²¯Æÿ²¯Çÿ²¯Çÿ³¯Æÿ²¯Æÿ±­Äÿ¯«Âÿ®ªÁÿ­¨Àÿ­§¿ÿ«¥¾ÿª¤½ÿª£½ÿ©¢½ÿ¨¡¼ÿ¨ »ÿ¨ ºÿ§ ºÿ§Ÿºÿ¦ž¹ÿ¦ž¸ÿ¥œ¸ÿ¥›·ÿ¤š¶ÿ¤™´ÿ¢—´ÿ¡—´ÿ¡—³ÿ¡–³ÿ¡–³ÿ¢—³ÿ¡–²ÿŸ•°ÿŸ•°ÿ£™³ÿ£™´ÿ¢—³ÿ¡–±ÿ •°ÿ –±ÿ¢—²ÿ¤š´ÿ¦�¶ÿ§Ÿ·ÿ©¡¹ÿª¢ºÿª£ºÿ«£ºÿ¬¤ºÿ­¥¼ÿ®¦½ÿ®§½ÿ­¦¼ÿ¬¥»ÿ¬¦¼ÿ­§¼ÿ®¨½ÿ¯¨½ÿ¯¨¼ÿ¯¨½ÿ°©¾ÿ¯©¾ÿ¯©¾ÿ¯ª¿ÿ±¬Áÿ³®Ãÿ´°Äÿ´°Äÿ´¯Åÿ³¯Æÿ²°Çÿ²°Èÿ³°Éÿ³°Éÿ²¯Éÿ±­Çÿ°«Åÿ®ªÃÿ­§Àÿª£½ÿ§ ºÿ§ ¹ÿ©¢»ÿ¬¥½ÿ¯©¿ÿ±­Áÿ´°Äÿ¶²Æÿ¶²Æÿ¶³Æÿµ²Æÿ´°Åÿ²­Âÿ®©¾ÿ©¢¹ÿ¥ž¶ÿ¤›´ÿ¥œ´ÿ¦ž¶ÿª£¹ÿ°ª¾ÿ³®Áÿµ±Ãÿ¶²Äÿ€�½ÿ�‚½ÿ‚‚½ÿ‚‚¼ÿ‚‚¼ÿ‚‚»ÿƒ‚¼ÿ‚‚»ÿƒ‚ºÿ„�ºÿ„�¹ÿ„�·ÿ„�¶ÿ„�µÿ…€´ÿ„€³ÿ„€³ÿ…€²ÿ…€²ÿ…€±ÿ†€±ÿ†€±ÿ†€±ÿ‡€±ÿ†€±ÿ‡€±ÿ†€±ÿ†€°ÿ‡�°ÿ‡€°ÿ‡€±ÿ‡�±ÿ‡�±ÿ‡�±ÿˆ�±ÿˆ‚±ÿˆ‚±ÿ‰‚±ÿ‰ƒ±ÿŠƒ°ÿ‹ƒ±ÿ‹ƒ±ÿ‹ƒ±ÿ‹„±ÿ‹„±ÿŒ…±ÿŒ…±ÿŒ…²ÿ�†²ÿއ²ÿ�ˆ³ÿއ²ÿ�‡³ÿ�‡´ÿ�ˆ³ÿ�‰³ÿ�‰´ÿ�‰´ÿ‘‹´ÿ’Œµÿ“�µÿ”޶ÿ”�·ÿ•‘¸ÿ—’¸ÿ–’¸ÿ–“¹ÿ˜”ºÿ™•»ÿ™•ºÿ›—»ÿœ˜»ÿœ˜»ÿ�™»ÿ�™¼ÿ�›½ÿž›¾ÿŸœ¾ÿ¡�¾ÿ¢žÀÿ£ŸÀÿ£¡Áÿ£¡Áÿ¤¡Áÿ¤¡Àÿ¤¡Àÿ¤¡Áÿ¤¡Âÿ¤¡Áÿ¤¡Áÿ¤¢Âÿ¤¢Âÿ¤¢Âÿ¤¢Âÿ¥£Äÿ¥¤Äÿ¤¤Äÿ¥¤Äÿ¦¤Äÿ¦¤Äÿ¦¤Äÿ¦¤Ãÿ¦¤Äÿ¦¤Äÿ¦¥Ãÿ¦¤Ãÿ§¤Ãÿ§¤Ãÿ¦¤Ãÿ¦¤Ãÿ¦£Âÿ€z’ÿZP`ÿD:Eÿ.$+ÿ3'/ÿ,!'ÿ+ %ÿ-"(ÿ*%ÿ+!'ÿ\Vfÿkfxÿjdxÿjdzÿjd~ÿgcÿfcÿidÿf`yÿMCTÿ0$-ÿ ÿ)#ÿ5(0ÿ3(/ÿ4(.ÿ5'-ÿnhyÿ¦£½ÿ«§Âÿ«¨Âÿ«¨Âÿ«¨Áÿ¬©Ãÿ­©Ãÿ­ªÃÿ­ªÃÿ®ªÃÿ®ªÃÿ­©Ãÿ«¦Áÿ©¤¾ÿ§¢¼ÿ¦ »ÿ¥ »ÿ¤Ÿºÿ£�¹ÿ¤œ¸ÿ¤œ¸ÿ¤œ·ÿ¤œ¸ÿ¤�¹ÿ¥žºÿ¥žºÿ¥ž¹ÿ¥ž¸ÿ¤œ·ÿ¢™µÿ •²ÿŸ”±ÿž“±ÿ�“±ÿ�“±ÿ�“°ÿ�’±ÿ�‘°ÿ›Ž­ÿ˜‹ªÿ˜Œ«ÿœ‘¯ÿœ“°ÿš�®ÿ™Œ¬ÿ–Šªÿ•ˆ©ÿ•‡©ÿ—Šªÿ™�¬ÿ›�­ÿ�“°ÿŸ–³ÿŸ—²ÿŸ—²ÿ¡™³ÿ£›µÿ¥œ·ÿ¤›¶ÿ£šµÿ£›µÿ¤›µÿ£š´ÿ£š´ÿ£›´ÿ¤›´ÿ¥œµÿ§ž¸ÿ§Ÿ¹ÿ¨ ºÿ©¢¼ÿª¤¼ÿ«¥½ÿ«¦¾ÿ¬§¿ÿ¬¦¿ÿ¬¦Àÿ¬§Àÿ­¨Áÿ­¨Âÿ­¨Áÿ­§Áÿ«¤½ÿ§ ºÿ¤œ·ÿ£™³ÿ¢—²ÿŸ”¯ÿž’­ÿž‘­ÿž‘¬ÿž’«ÿ¢˜¯ÿ¨Ÿµÿ­¥ºÿ®¨¼ÿ¯ª½ÿ¯ª¾ÿ®ª½ÿ®©¼ÿ­¨»ÿ­§ºÿ¬¦ºÿ¬¥»ÿ¬¤ºÿª£¹ÿª¢·ÿ«£¸ÿ¬¥¹ÿ¬¦ºÿ­§ºÿ�€ºÿ€€ºÿ��ºÿ��»ÿ‚�¼ÿ‚�¼ÿ‚�¼ÿ‚�¼ÿ‚�»ÿ‚�»ÿƒ�»ÿ„�ºÿ„�¸ÿ„�·ÿ„�¶ÿ…�¶ÿ…€µÿ„€´ÿ„€´ÿ…€´ÿ…€´ÿ…€´ÿ…�´ÿ…�³ÿ…�³ÿ…€³ÿ†€³ÿ†€³ÿ…€³ÿ…�´ÿ…€´ÿ…�´ÿ…�µÿ…�´ÿ†�´ÿ‡‚´ÿ‡‚³ÿ†‚³ÿ‡‚³ÿˆ‚³ÿ‰ƒ²ÿ‰ƒ³ÿŠƒ³ÿŠƒ³ÿŠ„³ÿŠ…³ÿŠ„³ÿ‹„³ÿŒ…³ÿŒ†³ÿŒ†´ÿ�‡´ÿއ´ÿ�‡µÿއµÿ�ˆµÿމ´ÿ�‰´ÿ�‰µÿ�еÿ’‹¶ÿ’Œ·ÿ“�·ÿ”�·ÿ”�¸ÿ•�¸ÿ–‘¸ÿ–’¹ÿ–“¹ÿ˜”¹ÿš•¹ÿš–ºÿ›—»ÿ›˜¼ÿœ™¼ÿ�™¼ÿžš½ÿžš½ÿŸ›¾ÿŸ›½ÿ œ½ÿ œ¾ÿŸ›¾ÿŸ›¾ÿ œ½ÿ œ½ÿ œ¾ÿ �¾ÿ �¿ÿ �Áÿ �ÂÿŸžÄÿŸžÅÿŸžÆÿŸŸÇÿ  Èÿ  Èÿ¡¡Çÿ¢¡Çÿ¢¡Æÿ¢¡Æÿ¢¡Æÿ¢¡Æÿ£¢Æÿ£¢Æÿ¥£Æÿ¦£Åÿ¦£Æÿ¥£Æÿ¥¤Åÿ¢¢Ãÿvp‰ÿK>LÿE:FÿGÿ@6>ÿ;09ÿ:,5ÿ\TdÿŸŸ»ÿª©Çÿ©¨Åÿ©¨Åÿ©©Åÿª©Æÿ©ªÆÿªªÆÿªªÆÿª©Æÿª©ÆÿªªÆÿª«ÆÿªªÆÿ¨§Äÿ¥¤Áÿ¦¤Áÿ¨¦Ãÿ¨§Äÿ¨§Äÿª¨Åÿ©§Äÿ¥£ÀÿŸ™¹ÿ•�°ÿ’ˆ­ÿ�…ªÿ�ƒ©ÿŽ‚¨ÿ��¨ÿ�€§ÿ�€§ÿ��¨ÿ�ƒ©ÿ‘„©ÿ‘ƒªÿ��§ÿŽ¥ÿ�~¥ÿ�}¥ÿŒ|¥ÿ‹{¤ÿ‹z£ÿ‹z£ÿ‹z¤ÿŠz¤ÿŠz¤ÿ‹|¥ÿŒ}¤ÿŒ|£ÿ‹{¤ÿŠz£ÿŠz¢ÿŠz¢ÿ‰z£ÿ‰z¢ÿ‰z¢ÿ‰z¢ÿŠz¢ÿŠz¢ÿŠy¢ÿ‰z¢ÿŠz¢ÿ‹z¢ÿ‹{¢ÿ‹|£ÿ�¤ÿ��¦ÿ�‚¦ÿ�ƒ¥ÿ�‚¥ÿ�‚¤ÿ�ƒ¤ÿ‘…¦ÿ”‡¨ÿ–‹«ÿ™�®ÿœ”°ÿ�–±ÿ�•°ÿ›’®ÿ›�®ÿš�¬ÿ˜Œªÿ•Ѝÿ–ˆ§ÿ•ˆ¦ÿ”ˆ¦ÿ•ˆ§ÿ–Ѝÿ—‹¨ÿ—‹¨ÿ˜Œ©ÿ˜�ªÿ˜Œªÿ—Œ©ÿ—Œ©ÿ˜�©ÿ™ŽªÿšŽªÿš�«ÿ›�¬ÿš�«ÿ™�©ÿ™�©ÿš�ªÿ™�©ÿ™Ž©ÿ›�«ÿœ�¬ÿ‚‚ºÿƒ‚¹ÿƒ‚¸ÿƒ�¸ÿƒ�¸ÿƒ�·ÿƒ�·ÿƒ�¶ÿƒ�¶ÿ„�¶ÿ…�¶ÿ…�¶ÿ…�¶ÿ…�µÿ„�´ÿ…‚´ÿ„�´ÿ„�´ÿ…�´ÿ…‚´ÿ…‚´ÿ…‚µÿ…�µÿ…�µÿ…�¶ÿ†�¶ÿ…‚¶ÿ…‚·ÿ…‚¹ÿ„ƒ¹ÿ„ƒ»ÿ„ƒ»ÿ„ƒ¼ÿ„„½ÿ„…¿ÿ„†ÁÿƒˆÃÿƒˆÆÿƒ‰ÈÿƒŠÊÿ‚ŠËÿ‚‹Ïÿ‚ŒÒÿ�ŒÔÿ�ŒÓÿ‚ŒÐÿƒ‹Ìÿ„‹Éÿ„ŠÈÿ…ŠÇÿ„ŠÆÿ…ŠÇÿ…ŠÇÿ†ŠÇÿ†ŠÆÿ†‰Äÿ‡‰ÂÿˆˆÂÿ‰‰ÀÿЉ¿ÿЉ½ÿŠŠ½ÿŠ‹¾ÿ‹‹½ÿ‹‹½ÿŒ‹½ÿ�Œ½ÿ�Œ½ÿ�Œ½ÿ�Œ½ÿŽŒ½ÿŽ�¼ÿ�޼ÿ�޼ÿ‘�¼ÿ’�¼ÿ’�»ÿ“�»ÿ”�»ÿ”‘»ÿ”’»ÿ”’»ÿ”’¼ÿ•’¼ÿ•“¼ÿ•“¼ÿ–“½ÿ—”½ÿ—”½ÿ—”½ÿ—”½ÿ—•½ÿ—•½ÿ˜•½ÿ˜–½ÿ˜–¿ÿ˜—¿ÿ™—¿ÿ™˜Àÿ™™Áÿ™šÃÿ˜šÆÿ˜›Èÿ˜œÊÿ˜�Ëÿ˜�Ëÿ™œÊÿ™œÉÿ›žÊÿ•˜Âÿ`[vÿD:Iÿ<1<ÿ@6BÿI?Oÿ4(1ÿ3'/ÿ0$,ÿ(!ÿ;2>ÿkf}ÿ–•¶ÿ£¤Çÿ¢¤Æÿ£¤Æÿ£¤Æÿ£¥Æÿ¤¦Æÿ¦§Èÿ¤¥Åÿ’’¬ÿ^Yjÿ+ÿ+#ÿ9.6ÿJ?JÿLBNÿ@6@ÿ/")ÿNFTÿ‘�©ÿ¥¦Ãÿ©ªÇÿ¨©Çÿ©ªÇÿª«Èÿª¬Éÿª¬Éÿª«Èÿª«Èÿª«Èÿ««Èÿ«¬Éÿ«­Éÿ«­Êÿ«­Êÿ«­Éÿ«­Éÿ«¬Éÿ©ªÇÿªªÇÿ¨¨Æÿ¢Ÿ¿ÿš”¶ÿ–�±ÿ•‹°ÿ”‹¯ÿ”‹°ÿ•Œ°ÿ•Œ°ÿ“Нÿ’ˆ®ÿ’‡­ÿ‘†­ÿ�„«ÿ�€¨ÿ‹}§ÿŠ{¥ÿŠz¥ÿ‹{¥ÿ‹z¥ÿ‹{¤ÿ‹{¤ÿ‹z¤ÿ‹z¥ÿ‹{¥ÿ‹z¥ÿ‹{¥ÿ‹|¥ÿ‹|¤ÿ‰{¤ÿ‰z£ÿ‰y£ÿ‰x¢ÿˆx¢ÿ‡w¡ÿ‡w¡ÿ‡w¡ÿ‡w¡ÿ†v ÿ†v ÿ†v ÿ‡v ÿ‡v ÿˆv ÿˆx ÿ‰y ÿ‰y ÿ‰y ÿŠz ÿŠz¡ÿ‹z¡ÿ‹{ ÿ‹| ÿŒ}¡ÿ�~¢ÿ�€£ÿ�€£ÿ�€£ÿ�‚¤ÿ‘ƒ¥ÿ“„¦ÿ’ƒ¥ÿ��£ÿ�€¢ÿ�¡ÿ�€¡ÿ�€¢ÿ��¢ÿ�‚¢ÿ‘‚¢ÿ’ƒ£ÿ“…¤ÿ”‡¦ÿ•‰§ÿ–‹¨ÿ–‹©ÿ–‹©ÿ–Ѝÿ•‰§ÿ“‡§ÿ”ˆ§ÿ”ˆ§ÿ“‡§ÿ“‡¦ÿ”‡¦ÿ“‡¥ÿ“‡¥ÿ–Чÿ˜Œªÿ‚„»ÿ‚ƒºÿƒƒ¹ÿƒƒ¹ÿƒƒ¹ÿ„ƒ¹ÿ„ƒ¸ÿ„‚¸ÿ„‚¸ÿƒ‚¸ÿ„‚¸ÿ„‚·ÿ„‚¶ÿ„‚¶ÿ…ƒ·ÿ„‚·ÿ„‚·ÿ„‚¶ÿ…‚¶ÿ„‚·ÿ…ƒ·ÿ…ƒ·ÿ…ƒ·ÿ…ƒ¸ÿ…ƒ¸ÿ„ƒ¹ÿ…ƒ¹ÿ…ƒ¹ÿ„ƒºÿ…„»ÿ„„¼ÿ……½ÿ„…¿ÿ„†Áÿ…‡Äÿ„‰Èÿ„ŠÉÿ„‹ÊÿƒŒÌÿ‚ŒÍÿ�ŒÏÿ��Òÿ�Ž×ÿ��Ûÿ€�Üÿ€�Úÿ��Øÿ‚�ÖÿƒŽÓÿƒŽÑÿƒŽÐÿƒŽÐÿ„ŽÏÿ„�Îÿ„�Íÿ…�Ìÿ†ŒËÿ‡‹Éÿ‡‹Çÿˆ‹Åÿˆ‹Äÿ‰ŒÃÿ‰ŒÂÿ‰‹ÂÿŠ‹ÂÿŠŒÁÿŠŒÁÿŠŒÁÿŠŒÁÿŠ‹Áÿ‹ŒÀÿŒŒÀÿŒ�¿ÿ��¿ÿ��¿ÿŽ�¿ÿŽ�¾ÿ�޾ÿ��½ÿ‘�¼ÿ’�½ÿ‘�¼ÿ‘�¼ÿ‘޼ÿ‘޼ÿ‘Ž»ÿ’Ž»ÿ“�»ÿ“�¼ÿ“�¼ÿ“�¼ÿ“‘¼ÿ”’¼ÿ”’¼ÿ•“¼ÿ–”½ÿ–”¾ÿ–•¾ÿ––¿ÿ—–Àÿ——Âÿ—˜Åÿ—™Çÿ–šÈÿ—›Éÿ˜šÈÿ™›Çÿš›Åÿ™›ÄÿŽŽ´ÿTNdÿTK]ÿKBRÿ5)2ÿ;/:ÿ."*ÿ1&.ÿ2%.ÿ+#ÿ?7Dÿws�ÿ——¸ÿ¡¢Åÿ¡¡Äÿ ¡Äÿ ¡Äÿ¡¢Äÿ¡£Äÿ¢¤Åÿ£¤Åÿšš¹ÿfavÿ.%ÿ$ÿ+$ÿ;.6ÿA5@ÿ>4?ÿ4*4ÿC;Gÿ{w�ÿœœºÿ¦§Æÿ¥¥Äÿ¥¦Äÿ¥¦Åÿ¥§Åÿ¦¨Åÿ¦§Åÿ¦§Åÿ¦¦Åÿ¦¦Åÿ¦¦Åÿ¦§Åÿ¦§Åÿ§¨Æÿ¨¨Çÿ©©Çÿ©ªÇÿ©«Èÿ©«Èÿ¨©Çÿ¥¤Ãÿ œ¾ÿ�˜»ÿœ–¹ÿœ—¸ÿœ˜¹ÿ�™»ÿ�š¼ÿœ˜ºÿ›•·ÿ™’µÿ–�³ÿ“Œ±ÿ‘ˆ®ÿ�…¬ÿ��ªÿŒ©ÿŒ}¨ÿ‹|¦ÿ‹|¥ÿ‹{¥ÿŠ{¦ÿ‹|¦ÿŒ{¦ÿ‹{¥ÿ‹{¥ÿ‹|¥ÿŠ|¥ÿŠ{¥ÿ‰z¤ÿˆy£ÿ‡x£ÿˆw£ÿ‡w¢ÿ‡w¢ÿ‡w¢ÿ‡w¢ÿ†w¢ÿ‡v¡ÿ†u ÿ†u ÿ†u ÿ†u ÿ‡vŸÿ‡vŸÿ‡vŸÿ†vŸÿ†užÿ†uŸÿ†užÿ‡u�ÿ‡v�ÿ‡v�ÿˆvžÿˆwžÿˆw�ÿˆw�ÿ‡wžÿˆxžÿ‰xžÿ‰x�ÿˆx�ÿˆx�ÿˆxœÿˆwœÿˆw�ÿ‰x�ÿ‰y�ÿ‰y�ÿŠz�ÿŠzžÿ‹{žÿŒ|ŸÿŽ¡ÿ��¢ÿ‘ƒ£ÿ’„¥ÿ‘„¤ÿ�ƒ¤ÿ�ƒ¥ÿ�ƒ¥ÿ�„¥ÿ’†¦ÿ“‡§ÿ’‡¦ÿ’†¥ÿ’…¥ÿ‘…¥ÿ‚…¼ÿ‚…¼ÿƒ„»ÿƒ„»ÿ‚ƒºÿƒƒºÿƒƒ¹ÿƒ‚¹ÿ‚‚¹ÿƒ‚¹ÿ„ƒ¹ÿ„ƒ¹ÿƒƒ¸ÿƒƒ¸ÿ„‚¹ÿƒ‚¹ÿƒƒ¹ÿ„ƒ¹ÿ„ƒ¹ÿƒƒ¹ÿ„„ºÿ„„ºÿ„„ºÿ„„»ÿ„„»ÿ„„¼ÿ„„½ÿƒ„½ÿ„…¿ÿ…†Áÿ„‡Âÿ„ˆÄÿ„ŠÈÿƒ‹Ìÿƒ‹Îÿ‚�Ïÿ‚�Ðÿ‚�Ñÿ‚�Ñÿ��Ñÿ‚�Òÿ‚ŽÕÿ��Øÿ€�Úÿ��Üÿ€�Üÿ€‘Üÿ€‘Ýÿ�‘Üÿ��Ûÿ��Úÿ��Øÿ��×ÿ‚�×ÿ��×ÿƒ�×ÿ„�Öÿ„�Ôÿ„ŽÑÿ…ŽÐÿ†ŽÏÿ†ŽÎÿ†ŽÎÿ†ŽÍÿ‡ŽÍÿ‡ŽÊÿ‡ŽÊÿ‡�Éÿ‡�Éÿˆ�Èÿˆ�Çÿ‰�Çÿ‰ŽÆÿ‰ŽÆÿŠŽÅÿ‹ŽÅÿ‹ŽÄÿ‹ŽÃÿŒŽÂÿŒ�ÁÿŒ�ÁÿŒŒÀÿŒŒ¿ÿŒŒ¾ÿŒ‹½ÿŒ‹¼ÿŒ‹¼ÿ�‹¼ÿŽŒ¼ÿŽŒ¼ÿŽ�¼ÿ�޼ÿ��¼ÿ��¼ÿ‘�½ÿ’�½ÿ“‘½ÿ“‘½ÿ“’½ÿ““¾ÿ”“¿ÿ•”Àÿ••Áÿ••Âÿ•–Áÿ––Áÿ––Áÿ——Âÿ‘�¹ÿ|yšÿNEZÿUL`ÿRI[ÿ<1=ÿ4&0ÿ8+5ÿ=2<ÿ:.8ÿ/ *ÿC;Jÿ~{™ÿ–•¹ÿœœÁÿœ›Àÿœœ¿ÿœœ¿ÿœœÀÿ��ÀÿžŸÀÿŸ ÃÿžŸÁÿlhÿ3#,ÿ#ÿ&ÿ.")ÿ=1;ÿI>MÿG=Kÿ@7Bÿe^qÿ“’°ÿ¡¢Ãÿ  Àÿ¡ŸÀÿ ŸÀÿ  Àÿ¡¢Áÿ¢¢Âÿ¡¢Âÿ¡¡Áÿ¡ Àÿ¡ Àÿ¡ Àÿ¡ Àÿ ¡Àÿ¡¡Áÿ¢¢Áÿ¢¢Âÿ£¤Ãÿ¤¥Äÿ£¥Ãÿ¡¢Âÿ ŸÀÿŸ�¾ÿž›½ÿ�›¼ÿž›¼ÿžœ½ÿŸœ¾ÿžš¼ÿœ˜ºÿš–¸ÿ™”·ÿ—“¶ÿ–‘µÿ–�µÿ–�µÿ•޳ÿ“аÿ�†¬ÿŽ‚ªÿŒ©ÿ‹}§ÿŠ|¦ÿŠ{¥ÿŠ{¥ÿŠ{¥ÿŠ{¤ÿ‰{¤ÿ‰z¥ÿˆz¤ÿ‡y£ÿ‡x£ÿˆw£ÿ‡w¢ÿ‡v¡ÿ‡w¢ÿ†w¢ÿ†w¡ÿ†v¡ÿ…u ÿ…uŸÿ…tŸÿ…tŸÿ…tžÿ…tžÿ„tžÿ„t�ÿƒs�ÿ„sžÿ„s�ÿ„s�ÿ„s�ÿ†s�ÿ…s�ÿ„sœÿ„sœÿ„sœÿ„sœÿƒtœÿ„tœÿ…tœÿ…uœÿ†u›ÿ‡uœÿ‡uœÿ‡vœÿ‡vœÿˆvœÿˆw�ÿ‰x�ÿ‰x�ÿ‰xžÿ‰yžÿ‰yžÿ‹{žÿŒ} ÿ�¡ÿŽ€¢ÿ��£ÿ�ƒ¥ÿ�ƒ¥ÿ�„¥ÿ’‡§ÿ“ˆ¨ÿ“ˆ§ÿ“‡¦ÿ’‡¦ÿ‘†¥ÿ‚…¾ÿ‚…¾ÿƒ„¾ÿƒ„½ÿ‚ƒ¼ÿ‚ƒ¼ÿ‚ƒ¼ÿ‚‚»ÿ‚‚»ÿ‚ƒ»ÿƒƒ»ÿƒ„»ÿ‚„»ÿ‚ƒ»ÿ‚ƒ¼ÿ‚ƒ¼ÿƒƒ¼ÿƒ„¼ÿ‚„¼ÿ‚„¼ÿ‚„¼ÿƒ„½ÿƒ…½ÿ„…¾ÿ„…¾ÿ„…Àÿ„…Àÿƒ†ÂÿƒˆÅÿƒŠÉÿ‚‹Íÿ‚ŒÎÿ‚�Ñÿ�ŽÕÿ��×ÿ��×ÿ��×ÿ��Øÿ��Øÿ��Øÿ�Ž×ÿ‚�Øÿ��Úÿ€‘Üÿ€‘Ýÿ€‘Ýÿ’ßÿ“âÿ•äÿ•äÿ”äÿ”ãÿ•ãÿ”âÿ”âÿ€”àÿ�“àÿ€“ßÿ�“ßÿ�“ßÿ‚“Þÿ‚’Ýÿ‚’Üÿƒ’Ûÿ„’Úÿ„’Øÿ„‘Öÿ„�Ôÿ…�Òÿ…�Ñÿ†�Ðÿ†�Ïÿ†�Ïÿ‡�Îÿ‡�Íÿˆ�Íÿˆ�Ìÿˆ�Ëÿˆ�ÊÿˆŽÊÿˆ�Éÿˆ�Çÿ‰�Åÿ‰ŒÄÿˆ‹Ãÿˆ‹Áÿ‰‹Àÿ‰ŠÀÿŠŠ¿ÿŠ‹¿ÿ‹‹ÀÿŒŒ¿ÿŒŒ¿ÿŒ�¿ÿŽ�¿ÿŽ�¾ÿŽŽ¾ÿ�޾ÿ�޽ÿ��¾ÿ��½ÿ‘�¾ÿ’�¾ÿ’�¾ÿ‘�¾ÿ‘‘½ÿ’‘½ÿ”“Àÿ‰‡°ÿic�ÿRH]ÿPFZÿQH\ÿGÿ(ÿ&ÿ'#ÿ@5BÿK@OÿGPÿJ?RÿJ>Rÿ0$.ÿ/"+ÿ0",ÿ5(3ÿ7*7ÿLDXÿƒ€¤ÿ“‘ºÿ–•¾ÿ––¾ÿ—–¾ÿ—–¾ÿ—–½ÿ—–½ÿ—–¼ÿ˜˜¾ÿššÀÿyt‘ÿMBSÿ/ 'ÿ)!ÿ*&ÿ?4@ÿB6Cÿ>1<ÿ@4?ÿG=Lÿ~{˜ÿ–”·ÿ™˜¼ÿ™—¼ÿ™—¼ÿ™—¼ÿ™—¼ÿ™˜¼ÿš˜»ÿ›™¼ÿ›™½ÿ›™½ÿœš½ÿ�›¾ÿžœ¿ÿžžÀÿžžÀÿžžÁÿžŸÀÿžŸÀÿžŸÁÿžŸÁÿŸŸÁÿŸŸÁÿžŸÀÿžžÀÿ��¿ÿœš¾ÿš—ºÿš—ºÿ›™¼ÿœ›½ÿž�¿ÿž�Àÿœ›¾ÿ™—»ÿ—”¸ÿ–’¶ÿ–‘µÿ–�µÿ–�´ÿ”�²ÿ’‹°ÿ�‰°ÿŽ…®ÿŒ�«ÿŠ©ÿ‰}§ÿ‰|§ÿ‰|¦ÿ‰{¦ÿ‰z¦ÿ‰z¦ÿ‰z¦ÿˆy¥ÿˆy¥ÿˆy¤ÿ‡x£ÿ†w£ÿ…w¢ÿ…v¢ÿ…u¡ÿ…u¡ÿ…u ÿ„u ÿ„tŸÿƒtŸÿƒtŸÿƒtŸÿ„tŸÿ„sŸÿ…tŸÿ„tŸÿ„sžÿ…sŸÿ…tŸÿ„sŸÿ„sŸÿ„sžÿƒtžÿ„tžÿ…uŸÿ†uŸÿ†uŸÿ…uŸÿ†vŸÿ†vžÿ†vžÿ‡vžÿ‡wžÿˆvžÿˆwžÿ‡wžÿˆvžÿˆwžÿˆxžÿ‰xžÿ‰xžÿ‰yŸÿ‰z ÿŠ|¡ÿŒ}¢ÿ�£ÿ�‚¤ÿ‘…¦ÿ‘…§ÿ�…§ÿ�…¦ÿ�†¦ÿ‚†Áÿ‚†Áÿ‚†Àÿ‚†Àÿ‚†Àÿ‚…Àÿ�…Àÿ�„Àÿ‚„¿ÿ‚ƒ¿ÿ‚ƒ¿ÿ‚„¿ÿ‚„¿ÿ�„Àÿ�…Àÿ‚„Àÿ�…Àÿ�…Àÿ�…Áÿ‚…Áÿ‚†Âÿ�†Âÿ�†Ãÿ�‡Åÿ�ˆÈÿ�ŠÊÿ€ŠÍÿ€‹Ðÿ€ŒÒÿ€ŒÔÿ€�Öÿ€�ÖÿŽÚÿ~‘ßÿ}“åÿ|•éÿ{–ëÿ{—ëÿ{—ëÿ}—ëÿ}–êÿ}–êÿ}•éÿ}•èÿ|–èÿ}—êÿ}—ëÿ|—ìÿ|˜ìÿ|˜ìÿ{˜íÿ|™ïÿ{™ðÿ{šñÿ{›ñÿ|›ñÿ|›ðÿ}šðÿ|›ñÿ|œòÿ|œòÿ|œóÿ}�óÿ}œðÿ~›îÿ~šìÿ~™êÿ˜éÿ€—çÿ�–åÿ�•âÿ‚•áÿ‚”ßÿƒ“Ýÿ„“Ûÿ„“Ûÿƒ“Ûÿƒ“Ûÿƒ“Ûÿ„“Ûÿ„“Ûÿ„“Ûÿ„’Ùÿ„‘×ÿ…�Õÿ…�Óÿ…�Ðÿ…�Îÿ…�Îÿ†ŽÎÿ‡ŽÌÿ‡ŽËÿ†ŽÊÿ†ŽÉÿ‡ŽÉÿˆŽÊÿ‡ŽÉÿ‡�Èÿˆ�ÈÿˆŒÆÿ‰ŒÅÿ‰ŒÄÿ‰ŒÄÿŠŒÄÿŠŒÃÿŠŒÂÿŠ�Âÿ‰‹¾ÿwv¢ÿND\ÿOF^ÿ?4Eÿ>1?ÿ@4Cÿ/$-ÿ3'2ÿ5(3ÿ6(4ÿ9+:ÿQJbÿ‚¨ÿŽŽºÿ��½ÿ‘�¼ÿ’�¼ÿ’�»ÿ’�»ÿ’‘»ÿ’‘»ÿ“’¼ÿ•”½ÿ~zœÿZPgÿ4$-ÿ,%ÿ5)3ÿ:-8ÿ;/:ÿ>2=ÿ@4?ÿ=2?ÿtp‹ÿ�ޱÿ˜–½ÿ—•½ÿ–”¼ÿ–”»ÿ—”»ÿ—”»ÿ—”»ÿ˜–»ÿ˜–¼ÿ˜–¼ÿ˜—¼ÿš˜½ÿ›™½ÿšš¾ÿšš¾ÿ››¿ÿ›œ¿ÿ›œ¿ÿœœÀÿœœÀÿœ�Àÿ��Áÿœ�Áÿœ�ÀÿœœÀÿœœÀÿ›œ¿ÿ›œ¾ÿœœ¿ÿœ�¿ÿœ�¿ÿœ�Àÿœ›¿ÿ›š¾ÿš™½ÿ™˜»ÿ˜–»ÿ—”¹ÿ–’¶ÿ•‘¶ÿ•‘¶ÿ–’·ÿ•�¶ÿ‘‹³ÿކ¯ÿ�ƒ­ÿŒƒ¬ÿŒ‚«ÿ‹€ªÿŠªÿŠ~©ÿŠ|§ÿˆ{§ÿˆ{¦ÿˆz¦ÿ‡y¥ÿ†y¤ÿ…x¤ÿ†x£ÿ…w£ÿ…v¢ÿ…v¢ÿ„v¢ÿ„v¡ÿ„u¡ÿ„u ÿ„u ÿƒu ÿ„t ÿ„u ÿ…u ÿ…tŸÿ…t ÿ…u ÿ„u ÿ„t ÿ…t ÿ„u ÿ…u ÿ…u ÿ†u ÿ†u ÿ†u ÿ†v ÿ†v ÿ†v ÿ†vŸÿ†vŸÿ‡wŸÿ‡wŸÿˆwŸÿ‡wŸÿˆwŸÿ‡xžÿˆxžÿˆxžÿˆyŸÿˆyŸÿˆzŸÿ‰{ ÿŒ}¡ÿ�€£ÿŽ‚¥ÿŽ‚¦ÿŽƒ¦ÿŽ„¦ÿ�…¦ÿ€„¿ÿ€„¿ÿ�…¿ÿ�…¿ÿ�…¿ÿ€„¿ÿ€„¿ÿ€„¿ÿ€„¾ÿ€ƒ¾ÿ‚ƒ¾ÿ�ƒ¾ÿ€„¿ÿ€„¿ÿ€„¿ÿ�…Àÿ�…Áÿ�†Âÿ�†Ãÿ€†Ãÿ€…Ãÿ€†Äÿ€‡Æÿ€ˆÇÿ€‰Êÿ�ŠÎÿŒÒÿ~Ž×ÿŽÚÿŽÛÿ~�Üÿ}�Ýÿ}‘àÿ}“äÿ}•çÿ{–ëÿz—îÿy˜ïÿy—ïÿz—îÿ{–íÿ|–ìÿ{–ëÿz–êÿ{˜ìÿ{™îÿ{™îÿ{™íÿ{˜íÿ{˜íÿz™îÿ{šñÿz›ôÿz�öÿ{ŸøÿzŸøÿzž÷ÿzž÷ÿzŸøÿzŸøÿzž÷ÿz ùÿz¡úÿz¡ùÿz øÿz ÷ÿzŸöÿ|žöÿ}�õÿ}�òÿ~›ïÿ~™ìÿ˜éÿ€—æÿ�–åÿ�—åÿ€—åÿ€—åÿ€˜çÿ€˜èÿ€—çÿ€—æÿ�—åÿ�–äÿ‚”âÿƒ“ßÿƒ“Ýÿƒ“Ûÿƒ“Øÿ„‘Õÿ…�Òÿ†�Ïÿ†�Îÿ…�Ïÿ†�Ïÿ†�Ïÿ†�Ïÿ…�Ïÿ†�Ïÿ†�Ïÿ†ŽÎÿ†ŽÍÿ‡�Íÿ‡ŽÌÿ†ŽËÿ†ŽÉÿ‡ŽÉÿƒˆ¿ÿmn›ÿ?5Jÿ7+;ÿ5)6ÿ6*7ÿ6+8ÿ3(4ÿ6*7ÿ5)4ÿ2$/ÿ7,:ÿUOkÿ‚�¯ÿ�Œ½ÿ��¾ÿ��½ÿŽ�¼ÿŽ�¼ÿ�޽ÿ�޼ÿ�޼ÿ‘�¼ÿ’�½ÿ†ƒ«ÿc\xÿ1!(ÿ, &ÿ;0>ÿI>OÿKBSÿC9Gÿ3(0ÿ1'0ÿc]vÿ‡„§ÿ––½ÿ•“¼ÿ”’»ÿ”’»ÿ”“»ÿ•“»ÿ•”¼ÿ–•¼ÿ–•¼ÿ–”¼ÿ–•¼ÿ—–¼ÿ˜—¾ÿ˜˜¾ÿ˜˜¾ÿ™™¿ÿ™™¿ÿš™¾ÿš™¿ÿ™š¿ÿšš¿ÿš™¿ÿš™¿ÿ™™¿ÿ™™¿ÿ™™¿ÿ™š¾ÿ™š½ÿš›¾ÿšœ¿ÿšœÀÿš�Àÿ›œÀÿšœÀÿš›¿ÿš›¿ÿš›Àÿš›¿ÿšš¾ÿ™™¾ÿ™˜¾ÿ˜˜¼ÿ–—»ÿ•”ºÿ“�¸ÿ‘Œ´ÿ�‰²ÿ�‡°ÿ�…¯ÿŒƒ®ÿ‹‚­ÿ‹€«ÿ‰«ÿˆ~©ÿˆ|¨ÿ‡|¨ÿ‡|¨ÿ†{§ÿ†z¦ÿ†z¦ÿ†y¥ÿ…y¥ÿ†y¥ÿ…x¥ÿ„w¤ÿ„w£ÿ„v£ÿƒv¢ÿ„v¢ÿ„u¡ÿ„u ÿ…u¡ÿ„u¡ÿ„u ÿ„u¡ÿ„u¡ÿ„v¢ÿ„v¡ÿ…v¢ÿ…v¡ÿ…v¡ÿ…v ÿ…v¡ÿ†w¡ÿ†w ÿ…w ÿ†w¡ÿ‡v ÿ†wŸÿ†wŸÿ‡w ÿ‡x ÿ‡xŸÿˆy ÿ‰z¡ÿŠz¡ÿŠz¡ÿ‰z¡ÿˆz ÿ‰z ÿŠ{ ÿ‹{¡ÿŒ}£ÿŒ£ÿŒ�¤ÿŽ„¦ÿކ¨ÿ€„¿ÿ€„¿ÿ�„¿ÿ�„¿ÿ€„¿ÿ€„¿ÿƒ¾ÿ€ƒ¾ÿ€ƒ¾ÿƒ¾ÿ€ƒ¾ÿ€‚½ÿ€ƒ½ÿ€ƒ¾ÿ€ƒ¾ÿ€ƒ¿ÿ€„¿ÿ�…Àÿ�…Áÿ€…Âÿ€†Âÿ€‡Äÿ€‡Æÿ€ˆÈÿ€‰Êÿ€‰Íÿ‹ÐÿŒÕÿ~ŽÛÿ}�ßÿ}‘âÿ{’äÿ{“åÿ{”æÿ{–êÿz˜ïÿyšòÿx›ôÿxœõÿxœöÿxœöÿxœöÿx›ôÿw›ôÿx�õÿxžöÿxžõÿxžõÿyžõÿx�õÿxžõÿyžöÿy�÷ÿxžøÿy úÿy¡ûÿy¡ûÿy¡ûÿy¡ûÿy¡ûÿx ûÿx¡ûÿx¥ýÿx¨ýÿy§ýÿx§üÿx¥üÿy¤üÿz£ûÿ{¡ùÿ{ž÷ÿ|œóÿ}›ðÿ}šîÿ~™ìÿ~˜êÿ~˜éÿ~˜éÿ~˜ëÿ~™ìÿ~™ìÿ~™ëÿ˜éÿ€—çÿ€•åÿ€•ãÿ€•ãÿ�•âÿ�”àÿ‚“Üÿƒ’Øÿ„‘Öÿ„‘Õÿ„‘Õÿ„�Õÿ„�Ôÿ„�Óÿ„�Óÿ„�Ôÿ„�Ôÿ„�Ôÿ„�Ôÿ…�Ôÿ…�Ôÿ…�Òÿ…�Ðÿ…�Ðÿ{‚¼ÿee’ÿJB`ÿ=3Iÿ9->ÿ9/?ÿ7-=ÿ1%2ÿ2'4ÿ6*7ÿ1$/ÿ7-<ÿXTtÿƒ„¸ÿ‹ŒÃÿ‹ŒÂÿ‹ŒÀÿ‹Œ¿ÿŒ�¿ÿŒ�¾ÿ��¾ÿ��½ÿŽŽ½ÿ��¾ÿ�Œ¹ÿlg‰ÿ1!(ÿ(!ÿ1'0ÿA5DÿH3Aÿ;3Bÿ>3Bÿrp‘ÿ’’½ÿ’’¾ÿ’’¾ÿ’’¾ÿ’’¾ÿ’’½ÿ““½ÿ“’½ÿ“’½ÿ“’½ÿ“’½ÿ“’½ÿ“’¼ÿ”’¼ÿ”’¼ÿ”“¼ÿ”“¼ÿ”’¼ÿ”‘»ÿ“‘»ÿ“‘ºÿ“‘»ÿ”’»ÿ”“¼ÿ•“½ÿ””¼ÿ””¼ÿ””¼ÿ””¼ÿ””¼ÿ””¼ÿ•”½ÿ•”½ÿ•”½ÿ•“¼ÿ””¼ÿ•”¼ÿ•”¼ÿ•“¼ÿ”“¼ÿ”“»ÿ“’»ÿ“’»ÿ’�ºÿ�ޏÿŽŒ¶ÿ�еÿ�‰µÿ�‡´ÿŒ‡³ÿŒ‡³ÿ�‡³ÿ�‡³ÿ�‡´ÿ�†³ÿŒ†³ÿŒ…²ÿŒ„²ÿ‹ƒ°ÿŠ‚®ÿ‰€¬ÿˆ~¬ÿˆ}«ÿˆ}ªÿ‡|ªÿ‡|ªÿ†{©ÿ†z¨ÿ…y§ÿ†z¨ÿ†y¨ÿ…y§ÿ…y§ÿ…x¦ÿ…x¦ÿ†y¦ÿ†z¦ÿ†z¦ÿ†z¦ÿ†z¦ÿ‡z¥ÿ‡y¥ÿ‡y¥ÿ†y¤ÿ‡y£ÿ‡z¤ÿ‡z¤ÿ‡z¤ÿ‡z¤ÿˆz¤ÿˆ{£ÿ‰|¤ÿ‰|¤ÿŠ|¤ÿŠ|¤ÿŠ}¤ÿŠ~¦ÿ‹¦ÿŒ�§ÿŒ‚§ÿ�ƒ¨ÿŽ…©ÿ�†«ÿ�‡«ÿ�‰«ÿ‘‰¬ÿ‘Ьÿ†Ãÿ†Ãÿ†Ãÿ†Ãÿ†Ãÿ€†Âÿ†Âÿ€…Âÿ€…Âÿ€…Âÿ€†Âÿ€…Âÿ�…Âÿ�†Áÿ€…Áÿ€…Áÿ€…Áÿ�†Áÿ�†Áÿ€†Âÿ€†Âÿ€†Âÿ€†Âÿ€†Ãÿ€†Ãÿ�‡Åÿ€ˆÇÿ€ˆÈÿ€‰ÉÿŠÍÿ‹ÐÿŒÒÿ�Òÿ�Òÿ€�ÓÿŽÕÿ~�×ÿ~�Ùÿ‘Ûÿ~’Þÿ~“àÿ}“àÿ}”âÿ|•åÿ|—çÿ|˜èÿ|˜èÿ|˜èÿ|™èÿ{›êÿ{žìÿzžîÿy ñÿy¥ôÿx©öÿw¬øÿv­ûÿv­ûÿv­ûÿv­ýÿv­ýÿv­þÿv­þÿv¯þÿu°þÿv°þÿv°þÿv¯þÿv®þÿw¬þÿwªþÿw¨ýÿw¦ýÿx¥üÿy¥üÿy¤üÿy£üÿy¢ûÿy¡úÿy¡ùÿzŸøÿzžöÿ{œôÿ{›òÿ{›ñÿ|šñÿ|›òÿ|›ñÿ|šïÿ}™îÿ~™íÿ~˜ëÿ~˜éÿ—çÿ€—æÿ€–äÿ€•ãÿ�•âÿ�•àÿ‚“Þÿƒ“Ûÿƒ’Ùÿ„’Øÿ…’×ÿ„’Õÿ„‘Öÿ…”Ùÿmu­ÿUS{ÿ_a�ÿ=8Qÿ?7Oÿ<3Kÿ7-Aÿ?9Tÿ>7Mÿ:-=ÿ2%/ÿA3Bÿ5'2ÿQIaÿusšÿ��Àÿ�޾ÿŒ�½ÿŒ�½ÿ��½ÿ��½ÿ�޽ÿ��½ÿŽ�¼ÿŽ�¼ÿ��¼ÿŒŒ»ÿ�Œ»ÿ�Œ»ÿ�‹»ÿ�‹»ÿ�‹»ÿ�‹»ÿ�Œºÿ�Œºÿ�‹¹ÿ�Œ¹ÿ�‹¹ÿ�Œ¹ÿŽŒ¹ÿŽŒ¹ÿŽ�¹ÿŽ�¹ÿŽ�ºÿŽ�ºÿŽŽ¹ÿ��¹ÿŽ�¹ÿŽ�¹ÿ�Œ¹ÿŽ�¹ÿŽ�¹ÿŽ�¹ÿŽ�¹ÿ��ºÿŽ�ºÿŽŒ¸ÿŽŒ¹ÿ�Œ¹ÿŽ�¹ÿŽŒ¸ÿŽŒ·ÿ�жÿŒŠ¶ÿŒŠ¶ÿ�‹·ÿ�жÿŒ‰µÿ‹ˆ´ÿ‹†³ÿŠ…²ÿ‰„±ÿ‰ƒ°ÿŠ‚¯ÿŠ�®ÿŠ€­ÿ‰€­ÿˆ­ÿˆ~¬ÿˆ¬ÿ‡¬ÿ‡~¬ÿ‡~«ÿ‡}«ÿ†}«ÿ†|«ÿ…{ªÿ…|ªÿ†|©ÿ†{©ÿ…z¨ÿ…z¨ÿ†|§ÿ†|§ÿ†|§ÿ‡{§ÿˆ{§ÿ‡|§ÿ‡|¦ÿ‡|¦ÿˆ}§ÿ‰}¨ÿˆ}§ÿˆ~¦ÿˆ~§ÿ‰~§ÿЍÿ‹€¨ÿ‹€©ÿ‹€¨ÿ‹€¨ÿ‹€¨ÿŒ€¨ÿ‹€§ÿ‹§ÿ‹¦ÿ‹€¦ÿ‹€¦ÿ‹€¦ÿ‹�§ÿ‹�§ÿ|ˆÌÿ}ˆÍÿ}ˆÌÿ}‡Ìÿ~‡Ëÿ}‡Ëÿ~ˆÊÿ~‡Êÿ}‡Éÿ~‡ÈÿˆÈÿ‡Èÿ‡ÉÿˆÊÿˆÊÿ~ˆÊÿˆÊÿ~ˆËÿ~ˆËÿ~‰Ìÿ~ŠÌÿ‰Ìÿ~‰Ìÿ~‰Íÿ~ŠÍÿ~‹Îÿ‹ÎÿŠÎÿŠÍÿ€‹Íÿ‹Íÿ‹Ìÿ€ŠËÿ€ŠËÿ€ŠÊÿ�‹Ëÿ�‹Ëÿ�‹Ëÿ�‹Ëÿ�‹Ëÿ�‹Ìÿ�ŒÍÿ��Îÿ��Ïÿ��Ïÿ��Îÿ‚ŒÌÿ‚‹Ëÿ‚ŒÌÿ‚ŒÌÿ‚ŒËÿ‚ŒÌÿ‚ŒÌÿ‚ŒÍÿ��Íÿ‚ŽÎÿ‚�Ïÿ‚�Ðÿ��Ñÿ�‘Ôÿ€“Øÿ•Üÿ~—àÿ~˜âÿ™ãÿ˜âÿ˜àÿ™àÿšâÿ€šâÿšáÿšâÿ~›ãÿ~œçÿ}žíÿ}Ÿðÿ|žðÿ}œïÿ}›îÿ}›îÿ~šîÿ~™êÿ~—æÿ€•âÿ€”ßÿ�“Ûÿƒ’Øÿƒ‘Öÿƒ‘Õÿƒ‘Õÿ„‘Ôÿ„�Òÿ„�Ðÿ„�Ïÿ„�Ïÿ„�Îÿ…�Íÿ…ŽÌÿ†�Ëÿ†�Êÿ…�Êÿ†�Êÿ†�Éÿ†�Éÿ†�Éÿ‡�Ëÿx|°ÿ[Y}ÿF>UÿOIgÿG>YÿVOrÿPIiÿ<3Gÿ7,<ÿ;/>ÿ=0@ÿ5'4ÿNLjÿx|¬ÿ…ŒÄÿˆ�Èÿˆ�Èÿˆ�Èÿ‰�Éÿˆ�Éÿˆ�Éÿˆ�Èÿ‰�Èÿ‰�Æÿ‰�ÆÿŠ�Æÿ~€°ÿ`\~ÿ7*6ÿ,&ÿ4)6ÿ=3CÿD:MÿG>RÿB8Jÿ=1AÿE8Jÿhdˆÿ‹ŽÁÿŒŽÁÿ‹Ž¿ÿŒ�¿ÿŒ�¿ÿ‹Ž¿ÿŒ�¿ÿ��¿ÿ��¿ÿ�Œ¾ÿŒŒ¾ÿŒ�¾ÿ��¾ÿŒ�½ÿŒŒ½ÿ�Œ½ÿ�Œ¼ÿŒ‹¼ÿŒ‹¼ÿ‹‹»ÿ‹‹¼ÿ‹‹»ÿ‹‹»ÿŒ‹»ÿŒ‹»ÿŒ‹»ÿŒ‹»ÿ�‹»ÿ�Œ»ÿ�Œ»ÿ�ŒºÿŽŒ¹ÿ�Œºÿ�Œºÿ�Œºÿ�ŒºÿŒ‹¹ÿ�‹¹ÿ�‹¸ÿ�‹¸ÿ�‹¸ÿŒ‹¸ÿŒ‹¸ÿ�‹¸ÿ�‹¸ÿ�Џÿ�Š·ÿŒŠ·ÿŒŠ·ÿŒ‹·ÿŒ‹·ÿŒ‰¶ÿ‹ˆµÿ‹‡´ÿ‹‡³ÿŠ…²ÿ‰„±ÿŠƒ±ÿŠ‚°ÿŠ‚¯ÿ‰‚¯ÿŠ‚¯ÿŠ�®ÿ‰€®ÿ‰€®ÿˆ€®ÿ‡€­ÿˆ­ÿˆ~¬ÿˆ~¬ÿˆ~¬ÿ‡}«ÿ‡}«ÿ‡}¬ÿ‡}«ÿ‡|«ÿ‡|ªÿ‡}ªÿ‡}ªÿˆ}©ÿˆ~©ÿ‰~©ÿˆ}©ÿˆ~©ÿˆ~©ÿˆ©ÿ‰ªÿ‰©ÿ‰©ÿ‰©ÿˆ¨ÿ‰~§ÿ‰~§ÿ‰~§ÿˆ~§ÿˆ~§ÿ‰}¦ÿ‰}¦ÿŠ}¥ÿŠ}¥ÿ‰|¥ÿ‰}¥ÿŠ}¥ÿŠ}¤ÿ‰}¤ÿ‰}¤ÿw•æÿw“åÿx‘ãÿyŽàÿz�Ýÿz�Üÿ{ŒÙÿ|ŠÖÿ|ŠÓÿ|ŠÓÿ|‹Óÿ|ŒÕÿ|Œ×ÿ|�Ùÿ|�Ùÿ{ŒØÿ|ŽÛÿ{ŽÜÿ{ŽÜÿ{�Ýÿ{�Üÿ|ŽÜÿ{�Ûÿ{�Úÿ{ŽÚÿ{ŽÛÿ|ŽÚÿ}�Øÿ}ŒÕÿ~ŒÔÿ~‹Óÿ~‹Ñÿ~‹Ðÿ~‹Îÿ‹Îÿ€ŠÎÿ€‹Íÿ€‹Íÿ€‹Íÿ€‹Íÿ€‹Îÿ€ŒÏÿ€ŒÏÿ�ŒÏÿ�ŒÏÿ€ŒÏÿ�ŒÍÿ�‹Ìÿ‚‹Íÿ‚ŒÍÿ�ŒËÿ‚ŒËÿ‚ŒËÿ‚ŒËÿ‚ŒËÿƒŒËÿƒŒËÿ‚ŒËÿƒŒÊÿƒ�Ìÿ‚�Îÿ‚�Ðÿ‚ŽÑÿ‚�Òÿ‚�Òÿ‚�Ñÿ‚�Ðÿ‚�Ðÿ‚�Ðÿƒ�Ñÿƒ�Ñÿ‚�Ñÿ‚�Ñÿƒ‘Òÿ‚“Õÿ�“Øÿ‚“Ùÿ‚“Úÿ�“Üÿ�”Þÿ‚”Ýÿ‚“Ûÿ‚’Øÿ‚‘Õÿƒ�Òÿƒ�Ðÿ„�Íÿ…�Ìÿ…ŽËÿ…ŽÊÿ…ŽÊÿ†ŽÉÿ‡ŽÈÿ†�Èÿ†�Èÿ†�Èÿ†ŽÈÿ†ŽÈÿ†�Èÿ‡�Èÿ†ŽÈÿ†�Èÿ†ŽÈÿ†ŽÈÿ‡�Éÿˆ�Ìÿkk˜ÿH?Wÿ:/?ÿ?6Jÿ>3GÿB8PÿB7Oÿ;/Cÿ5)8ÿ;/=ÿ?4Fÿ6*8ÿTTvÿ�‡½ÿ‡ŽÆÿ‡ŽÇÿˆ�Èÿˆ�Èÿˆ�Éÿˆ�Éÿˆ�Éÿˆ�Èÿˆ�Èÿˆ�Çÿˆ�Èÿ‰�Èÿ�…¹ÿig�ÿ=0@ÿ/!*ÿ0%1ÿ8.>ÿ>4Fÿ>4Eÿ9.=ÿ5)6ÿ7)5ÿ[Vvÿƒ„µÿŠŒÁÿ‹�ÁÿŠŽÁÿŠŽÁÿŠ�Áÿ‹�ÁÿŒ�ÀÿŒ�ÀÿŒ�¿ÿŒ�¿ÿŒ�¿ÿ‹�¿ÿ‹�¿ÿ‹�¾ÿŒ�¾ÿŒ�¾ÿ‹�¿ÿ‹Œ¾ÿ‹Œ¾ÿ‹Œ½ÿŠŒ½ÿ‹Œ½ÿŠ‹¼ÿŠ‹¼ÿ‹‹¼ÿ‹‹¼ÿ‹‹¼ÿ‹‹»ÿ‹‹»ÿ‹Œ»ÿŒŒºÿŒ‹»ÿŒ‹»ÿŒŒ»ÿŒŒ»ÿŒ‹»ÿŒ‹ºÿ�Šºÿ�ŠºÿŒŠ¹ÿŒŠ¹ÿŒŠ¹ÿ‹‰¸ÿ‹‰·ÿŒ‰·ÿŒˆ¶ÿ‹ˆ¶ÿ‹‰¶ÿ‹‰¶ÿ‹‰¶ÿ‹ˆµÿЇµÿЇ´ÿІ´ÿ‹…³ÿŠ„³ÿŠƒ²ÿ‰ƒ²ÿ‰ƒ±ÿ‰ƒ°ÿ‰ƒ°ÿ‰‚°ÿ‰‚¯ÿ‰�¯ÿ‰�¯ÿˆ�®ÿˆ€­ÿˆ€­ÿˆ¬ÿˆ¬ÿ‡~¬ÿ‡~¬ÿ‡~¬ÿ‡~¬ÿˆ~¬ÿ‡}«ÿ‡}«ÿ‡}«ÿ‡}«ÿ‡~«ÿˆ}ªÿˆ~ªÿˆ~©ÿˆ~©ÿˆ~©ÿˆ~©ÿ‰©ÿ‰©ÿˆ©ÿˆ~©ÿˆ¨ÿ‰¨ÿˆ~¨ÿˆ~¨ÿˆ~¨ÿˆ}¨ÿ‰}§ÿ‰}§ÿ‰}§ÿ‰}¦ÿ‰}¦ÿ‰|¦ÿ‰|¥ÿ‰|¥ÿˆ}¥ÿr¥÷ÿr§÷ÿr¨öÿr§õÿs¥óÿt¢òÿu�ðÿv™íÿv—ëÿw–ëÿw”éÿw“éÿw•ëÿv–îÿv—îÿv—íÿv˜ðÿu™ñÿu™ñÿv™ðÿv™ïÿv™ïÿv˜îÿv˜îÿv˜îÿw–ìÿw•êÿx”çÿy”åÿy“åÿz’äÿz’ãÿz’áÿ{‘ßÿ|�Þÿ|�Ýÿ|�Ýÿ|�Ýÿ|�Üÿ}�Ûÿ}�Ûÿ}�Úÿ~�Ùÿ~ŽØÿŽ×ÿŽÖÿŽÔÿ�Óÿ€ŒÑÿ€�Ðÿ€�Ðÿ€�Ðÿ��Ïÿ�ŒÎÿ�ŒÎÿ��Îÿ‚�Ïÿ��Îÿ��Íÿ��Íÿ‚�Íÿƒ�Îÿ‚�Íÿ‚�Íÿƒ�Íÿ‚�Ìÿ‚�Ìÿƒ�Ìÿƒ�Ìÿƒ�Ìÿƒ�Íÿ„�Ìÿ„�Ëÿ„�ÊÿƒŽÊÿƒŽÌÿ„ŽÌÿƒŽÎÿƒ�Ðÿ„�Ñÿ„�Ñÿ„�Ðÿ„�Ïÿ„�Îÿ„�Ìÿ„�Ëÿ…�Êÿ…�Êÿ…ŽÉÿ…ŽÉÿ…ŽÉÿ‡�Éÿ‡�Èÿ†�Èÿ†�Èÿ‡�Èÿ‡�Èÿ†�Èÿ†�Èÿ†ŽÈÿ†ŽÈÿ†�Éÿ†�Éÿ†�Êÿ‡�ÊÿƒŠÃÿ^\‚ÿ?3Gÿ;2Eÿ90BÿIC^ÿ@7Mÿ8,<ÿ7,<ÿ5+:ÿ6*6ÿ8-<ÿ6)7ÿZZ~ÿ„ŒÄÿ…�Åÿ…ŒÄÿ†ŒÅÿ†ŒÄÿ…ŒÃÿ…ŒÃÿ†ŒÃÿ†ŒÃÿ†ŒÂÿ†ŒÃÿ†‹Ãÿ…‹Âÿ€„¸ÿlj”ÿB5Gÿ. )ÿ2'4ÿ@7KÿJAZÿJBZÿC9Mÿ4(5ÿ0"+ÿOHbÿusžÿˆŠ¾ÿ‹ŽÃÿŠ�ÂÿŠ�ÂÿŠ�ÁÿŠ�ÀÿŠ�ÀÿŠ�¿ÿ‹Œ¿ÿ‹�¿ÿ‹�¿ÿ‹�¿ÿ‹ŽÀÿ‹ŽÀÿ‹ŽÀÿ‹ŽÀÿ‹ŽÀÿ‹�Áÿ‹�Àÿ‹�Àÿ‹�Àÿ‹�Àÿ‹Ž¿ÿ‹Ž¿ÿ‹Ž¿ÿ‹Ž¿ÿ‹�¿ÿŒŽ¾ÿŒŽ¾ÿ‹Ž¾ÿ‹�½ÿ‹�½ÿ‹�½ÿ‹�½ÿ‹Œ¼ÿ‹Œ¼ÿ‹Œ¼ÿ‹‹¼ÿŒ‹»ÿŒ‹»ÿŒŠ»ÿŒŠºÿ‹Š¹ÿЉ¸ÿ‹‰·ÿ‹ˆ·ÿŠˆ¶ÿŠˆ¶ÿŠˆ¶ÿЇµÿЇµÿЇµÿ‰‡´ÿ‰…´ÿ‰…´ÿ‰…³ÿ‰„³ÿ‰ƒ²ÿˆƒ±ÿˆ‚±ÿˆ‚±ÿˆ‚°ÿˆ‚°ÿ‰‚¯ÿ‰‚°ÿ‰‚¯ÿ‰�®ÿˆ�­ÿˆ€­ÿˆ€­ÿ‡­ÿ‡¬ÿ‡~¬ÿˆ~¬ÿ‡~­ÿ‡~­ÿ†~¬ÿ†~¬ÿ‡~¬ÿ‡~¬ÿ‡~«ÿ‡}«ÿˆ~ªÿˆ©ÿˆªÿˆ~©ÿˆ~©ÿˆ©ÿˆ©ÿˆ~©ÿˆ~¨ÿˆ¨ÿˆ©ÿˆ~¨ÿˆ~¨ÿˆ~¨ÿˆ}¨ÿˆ}§ÿˆ}§ÿˆ|¦ÿˆ|¦ÿˆ|¥ÿˆ{¥ÿˆ{¥ÿˆ|¥ÿr¥÷ÿqªùÿp®ûÿp°üÿo¯ýÿp«üÿr¥ûÿr¡ùÿrŸ÷ÿsœ÷ÿs˜õÿt—ôÿs™÷ÿsœúÿržûÿržúÿq ûÿr¡üÿr¢üÿr¢ûÿr úÿr¡ùÿr¡ùÿr ùÿsžùÿt�÷ÿt›ôÿtšóÿušòÿušóÿušôÿu›ôÿušóÿvšòÿv™ñÿu˜ñÿv˜ðÿv˜ñÿw˜ðÿw˜îÿx˜îÿx˜îÿx˜ìÿy—ëÿy—êÿz–èÿ{”åÿ{’áÿ|‘Þÿ}‘Ýÿ|‘Üÿ}�Üÿ~�Úÿ�Ùÿ~�Øÿ~�×ÿ�ÖÿŽÔÿŽÓÿŽÓÿ€ŽÔÿ�ŽÓÿ€ŽÒÿ€ŽÑÿ�ŽÒÿ€ŽÒÿ€ŽÒÿ�ŽÒÿ�ŽÓÿ��Ôÿ��Ôÿ‚�Óÿ‚�Òÿ‚�Ñÿ‚�Ïÿ‚�Ðÿ‚ŽÐÿ‚ŽÏÿƒŽÎÿƒ�Îÿ„�Íÿ„�Íÿ„�Íÿ„ŽÍÿ„�Íÿ„�Ìÿ„�Ìÿ…�Ìÿ„�Ìÿ„�Ëÿ…�Ëÿ†�Ëÿ†�Êÿ…�Êÿ…�Éÿ…�Éÿ…�Éÿ…ŽÈÿ…ŽÉÿ…ŽÊÿ„�Èÿƒ‹Äÿ‚‰Ãÿ‚ŠÄÿ�ˆÁÿuy«ÿQLlÿ@6JÿB;Qÿ90BÿMHdÿC;Rÿ5*8ÿ2'4ÿ4)7ÿ2&1ÿ.#,ÿ2&1ÿSQqÿtx©ÿtx¨ÿtw§ÿtw§ÿsv¦ÿsu¤ÿru£ÿsu¢ÿsu£ÿtv£ÿtu£ÿrs¢ÿqr ÿoo™ÿa]�ÿC6Hÿ- )ÿ1%1ÿ@7JÿJBZÿMD^ÿF=Sÿ5)6ÿ.!)ÿC9Lÿb\}ÿ|}«ÿ�‚³ÿ€�²ÿƒ…¶ÿˆ‹¾ÿ‰ŒÀÿ‰ŒÀÿŠ�ÀÿŠ�ÀÿŠ�ÀÿŠŽÀÿ‹ŽÀÿ‹�ÁÿŒ�ÁÿŒ�ÂÿŒ�ÂÿŒ‘Âÿ�‘ÂÿŒ’ÂÿŒ‘ÂÿŒ’ÂÿŒ’ÂÿŒ‘ÂÿŒ‘ÁÿŒ’ÁÿŒ’Âÿ�’Áÿ�’Áÿ�‘ÁÿŒ‘ÀÿŒ�Áÿ‹�¿ÿ‹�¿ÿ‹�¿ÿ‹Ž¾ÿ‹Ž½ÿ‹�½ÿ‹�½ÿ‹�½ÿŒŒ¼ÿ‹Œ¼ÿ‹Œ¼ÿ‹Œ»ÿ‹‹ºÿŠŠ¹ÿ‹Š¹ÿ‹Š¹ÿЉ¸ÿŠˆ·ÿŠˆ¶ÿЇµÿ‰‡¶ÿ‰‡µÿ‰†´ÿˆ…´ÿˆ…³ÿ‰„³ÿ‰„²ÿˆƒ²ÿ‡ƒ±ÿˆ‚±ÿˆ‚±ÿˆ‚°ÿˆ‚°ÿˆ‚°ÿ‰‚°ÿˆ‚°ÿˆ‚®ÿˆ�®ÿˆ�®ÿ‡€­ÿ‡€­ÿˆ­ÿˆ­ÿ‡­ÿ‡­ÿ‡­ÿ‡­ÿ†¬ÿ‡¬ÿˆ~¬ÿˆ}¬ÿ‡~«ÿˆªÿ‰ªÿˆ~ªÿˆ~©ÿˆ~©ÿˆ~©ÿˆ~©ÿ‡~¨ÿ‡~¨ÿˆ~¨ÿ‡}¨ÿ‡|§ÿ‡}¦ÿ‡|¦ÿ‡{¦ÿ‡{¥ÿ‡{¤ÿ‡{¤ÿ‡{¤ÿ‡z£ÿ‡z£ÿ‡z¤ÿt—ñÿsšôÿsœõÿsŸ÷ÿr¢ùÿrž÷ÿtœôÿušóÿu™ñÿt˜ðÿt—ñÿt—òÿu™õÿt�øÿsŸùÿr ùÿr ùÿr¡úÿr¢úÿs£úÿs¡÷ÿs õÿtžôÿtœóÿu›òÿu›òÿušñÿušñÿušñÿv›óÿv�õÿu�öÿu�÷ÿtžøÿsžøÿsœøÿtœùÿt�úÿsŸúÿs úÿs¡üÿs¢üÿs£üÿs£üÿs¢ûÿt¡ûÿvž÷ÿvšóÿw˜ðÿx—îÿx–ìÿy–êÿz•èÿ{”çÿ{”æÿ{”åÿ{“ãÿ|’áÿ|“áÿ|“âÿ}“âÿ}’àÿ}‘Þÿ}’Þÿ}’ßÿ}“ßÿ}“àÿ}“àÿ~’àÿ~“àÿ~“àÿ~“àÿ~”áÿ”àÿ“Þÿ’Ýÿ’Ýÿ’Üÿ€’Úÿ�‘Øÿ��Öÿ‚�Õÿ‚�Ôÿ‚�Ôÿ‚�Óÿ‚‘Óÿƒ‘Óÿƒ�Òÿƒ�Òÿƒ�Ñÿƒ�Ðÿ„�Ïÿƒ�Îÿƒ�Íÿ„�Íÿ„�Íÿƒ�Ìÿƒ�Ìÿƒ�Ìÿ„ŽÌÿ‚ŒÉÿx~µÿqu§ÿqt¦ÿnq¡ÿ^\�ÿC;Rÿ=2Cÿ?5Hÿ2%/ÿ2%0ÿ2$.ÿ/!)ÿ,&ÿ- (ÿ2&0ÿ/",ÿ1%2ÿ>3GÿKA[ÿLC]ÿMC]ÿKB[ÿKBZÿKB[ÿI?VÿI?VÿJ?VÿJ?UÿJ>TÿH;RÿF9OÿE9OÿE8Mÿ@2Bÿ.!*ÿ(%ÿ, 'ÿ/"*ÿ1#-ÿ0#,ÿ+%ÿ+$ÿ4(4ÿF=Rÿ]Xxÿb^ÿb_€ÿpo˜ÿ…‡ºÿ‰ŒÁÿŠ�ÂÿŠŽÂÿŠ�Âÿ‹�Âÿ‹�ÂÿŒ�ÂÿŒ�ÂÿŒ‘Âÿ�’Ãÿ�’Ãÿ�’Ãÿ�’ÃÿŒ’ÃÿŒ‘ÃÿŒ’ÂÿŒ’ÂÿŒ‘ÂÿŒ‘ÂÿŒ’Âÿ�’Âÿ�“Âÿ�“Âÿ�“Áÿ�’Áÿ�’Âÿ�’Áÿ�’Áÿ�’ÁÿŒ‘ÁÿŒ�ÀÿŒ�¿ÿŒ�¿ÿŒŽ¾ÿ‹Ž¾ÿ‹Ž¾ÿ‹�¾ÿŒ�½ÿŒ�¼ÿ‹�¼ÿ‹‹»ÿ‹‹ºÿ‹Šºÿ‹Š¹ÿ‹‰·ÿŠˆ¶ÿ‰‡·ÿЇ·ÿЇ¶ÿ‰†¶ÿˆ…´ÿˆ…³ÿˆ…³ÿˆ…³ÿˆ„²ÿˆƒ²ÿ‰ƒ±ÿˆ‚±ÿˆ‚±ÿˆ‚±ÿˆ‚°ÿ‰‚°ÿ‰‚°ÿˆ�¯ÿˆ�¯ÿ‡�®ÿ‡€®ÿˆ€®ÿˆ€®ÿ‡­ÿˆ€®ÿ‡­ÿ‡¬ÿ‡¬ÿ‡¬ÿˆ~­ÿˆ~¬ÿˆ~«ÿ‡~ªÿˆ~©ÿ‡}©ÿˆ~¨ÿ‡}¨ÿ‡}¨ÿ‡}¨ÿ‡|§ÿ‡|§ÿ‡|¦ÿ‡|¦ÿ‡{¦ÿ‡|¥ÿ†{¤ÿ†z¤ÿ†z¤ÿ‡z£ÿ‡z£ÿ†z¢ÿ†z¢ÿ†z¢ÿ†z£ÿq¤ûÿq§ûÿq§ûÿp¦ûÿp¦üÿq£ûÿrŸùÿsŸùÿsŸùÿsžùÿs�úÿsžúÿsŸúÿr¡úÿr¢úÿr¤ûÿs¡úÿsžøÿsœ÷ÿtœõÿt›óÿu™ðÿv—îÿw—íÿw–ëÿw•éÿx•éÿx”èÿx”çÿx•èÿy•éÿy•éÿx–êÿx—ìÿw—îÿw—ðÿw˜òÿv›ôÿu�÷ÿt úÿs¡úÿs¢úÿs¢úÿt¡ùÿs¡ùÿs£úÿu¡úÿuŸùÿuœ÷ÿvšôÿw™òÿx˜ðÿy—ïÿy—îÿy—îÿy—íÿx™ïÿxšñÿx›òÿw›òÿx›òÿyšòÿy™ðÿz˜ïÿy™ðÿx™ñÿyšòÿz™ñÿz˜íÿ{–éÿ{–èÿ{–êÿz˜íÿzšñÿy›ôÿy›óÿxœôÿy›óÿzšðÿ{˜ìÿ|–èÿ}•æÿ}•åÿ}•åÿ}–åÿ~–ãÿ”áÿ€“Þÿ€’Üÿ�“Üÿ�“Úÿ‚’Øÿ‚’×ÿ�‘Õÿ‚‘Õÿ‚’Öÿƒ’Ôÿƒ’Óÿƒ‘Óÿƒ‘Òÿ€�ÍÿdkœÿFFfÿ;7Oÿ;6Mÿ6/Aÿ0%3ÿ,,ÿ+*ÿ- 'ÿ. &ÿ/%ÿ1 &ÿ.%ÿ'"ÿ)$ÿ/!*ÿ<,<ÿH8PÿPA\ÿO@ZÿO@WÿJWÿRGeÿOB[ÿMAZÿJÿ'&ÿ((ÿ+(ÿ(ÿ"ÿ%ÿ#ÿ%ÿ&ÿ#ÿ$ÿ ÿ*"*ÿXXzÿ�‡»ÿˆŽÄÿ‰�Åÿ‰�Åÿ‰�Äÿ‰ŽÄÿ‰�ÄÿŠ�ÄÿŠ�ÃÿŠ�ÂÿŠ�ÁÿŠ�Âÿ‰ŽÁÿ‰ŽÁÿ‰�Àÿ‰�Àÿˆ�Àÿˆ�¿ÿˆ�¿ÿ‰�¿ÿ‰�¿ÿŠ�ÀÿŠ�¿ÿŠ�¿ÿŠ�¾ÿŠ�¾ÿŠ�¾ÿŠ�¾ÿ‹Ž¿ÿ‹Ž¾ÿ‹Ž¾ÿ‹Ž¾ÿŠŽ¾ÿ‹Ž¾ÿ‹Ž¾ÿŠŽ¾ÿŠ�½ÿŠ�½ÿŠŒ¼ÿŠ‹¼ÿŠŠºÿ‰‰¹ÿ‰ˆ¸ÿ‰ˆ¸ÿ‰ˆ¸ÿŠˆ·ÿŠˆ¸ÿЇ·ÿ‰‡¶ÿ‰†µÿ‰†µÿˆ…´ÿˆ…³ÿ‡„³ÿˆ„²ÿˆƒ±ÿ‡‚±ÿˆ‚²ÿˆ‚±ÿˆ‚±ÿˆ‚°ÿˆ�°ÿˆ‚°ÿˆ‚¯ÿˆ�¯ÿˆ�®ÿˆ€­ÿ‡€­ÿ‡€­ÿˆ€­ÿˆ€­ÿˆ¬ÿ‰¬ÿ‰¬ÿˆ«ÿˆ«ÿˆªÿ‡~ªÿ‡~ªÿ‡~ªÿ‡}©ÿ‡|¨ÿ‡|¨ÿ†|§ÿ†|§ÿ†{§ÿ‡{¦ÿ†|¦ÿ†{¥ÿ…z¤ÿ…z¤ÿ…z¤ÿ†z¤ÿ†y£ÿ…y¢ÿ†x¢ÿ†x¡ÿ†x¡ÿ†x¡ÿ…w ÿ…w ÿo®ýÿp«ýÿq¥úÿsŸøÿs›öÿu™òÿt™òÿt™òÿu™òÿu˜ñÿvœõÿuœõÿtœôÿt›ôÿušóÿu›óÿušòÿušòÿu›óÿu�õÿtžõÿvšòÿw—ïÿw˜ðÿvšòÿv™òÿvšóÿv›óÿv›óÿv›õÿvšôÿu›ôÿuœôÿu›óÿušñÿv™ñÿv™òÿv™óÿvšòÿv™ðÿw˜ïÿx—ïÿw—ïÿw—îÿx—îÿx—îÿx—íÿx—íÿy—ìÿz–éÿz•åÿ{“âÿ|’áÿ|‘ßÿ}�Ýÿ}�Üÿ}�Úÿ}�Úÿ}�Úÿ~�Úÿ~�Ùÿ~�Ùÿ~�Ùÿ~�Ùÿ‘Ùÿ~‘Ùÿ~’Úÿ’Ûÿ€’Ûÿ’Úÿ~“Ûÿ”Üÿ“Üÿ~“Ûÿ~“Ûÿ~”Ûÿ~”Ýÿ~”Þÿ~”ßÿ~•ßÿ~•áÿ~•áÿ~•áÿ~•àÿ•àÿ•âÿ•àÿ”Þÿ€“Ýÿ“Üÿ“Þÿ”àÿ–âÿ~–ãÿ~–äÿ~—åÿ}–äÿ}–äÿ~•äÿ~”âÿ|�Úÿfr¯ÿPUƒÿ??^ÿ'&ÿ% ÿ*%ÿ)#ÿ)"ÿ.'ÿ.$ÿ+!ÿ*"ÿ("ÿ% ÿ%ÿ0!)ÿ=+7ÿE3AÿH5DÿH4DÿE4CÿB1@ÿC0?ÿH3CÿH5GÿF1AÿE0@ÿG3DÿI4HÿI4GÿH3EÿA.<ÿ6(4ÿ1&3ÿ($ÿ&!ÿ)#ÿ*#ÿ&ÿ&ÿ$ÿ(!ÿ*#ÿ' ÿ*#ÿ-"+ÿ3)6ÿXY}ÿ‡¾ÿ†ŽÇÿ‡ŽÈÿ‡ŽÇÿ‡ŽÇÿ‡ŽÇÿ‡ŽÆÿ‡ŽÆÿˆ�Åÿˆ�Ãÿˆ�Ãÿˆ�Ãÿˆ�Âÿ‡ŒÁÿˆŒÁÿˆŒÀÿˆŒÀÿˆŒÀÿˆŒ¿ÿˆŒ¿ÿˆ‹¿ÿˆ‹¿ÿˆŠ¿ÿˆŠ¾ÿˆŠ¾ÿˆŠ½ÿˆŠ¼ÿˆŠ¼ÿˆŠ½ÿˆŠ½ÿ‰Š¼ÿ‰Š¼ÿˆŠ¼ÿˆŠ»ÿˆŠ»ÿˆŠ»ÿˆŠ»ÿ‰‰»ÿ‰‰ºÿˆ‰ºÿˆˆ¹ÿˆˆ¸ÿˆ‡¸ÿˆ‡·ÿˆ‡·ÿ‰‡·ÿ‰‡·ÿ‰‡¶ÿˆ†µÿˆ†´ÿˆ†´ÿˆ…´ÿ‡„³ÿ‡„²ÿˆƒ²ÿ‡ƒ±ÿ‡ƒ±ÿˆ‚±ÿˆ�±ÿˆ‚°ÿˆ‚°ÿ‰‚¯ÿˆ‚¯ÿ‡�®ÿˆ�­ÿˆ€­ÿˆ€­ÿ‡€­ÿ‡€­ÿ‡¬ÿˆ¬ÿˆ«ÿˆ«ÿˆ~«ÿˆ~«ÿˆ~ªÿ‡~ªÿ†~©ÿ†}©ÿ‡}©ÿ‡}¨ÿ‡|¨ÿ†|§ÿ†{¦ÿ†{¦ÿ†{¦ÿ†z¥ÿ†z¥ÿ†z¥ÿ…z¤ÿ…y¤ÿ…y£ÿ…y£ÿ…y£ÿ„x¢ÿ…w¡ÿ…w¡ÿ…w¡ÿ…w ÿ„w ÿ„w ÿo³ýÿo°þÿq«ýÿr¤ûÿržùÿt�÷ÿt›õÿt™ôÿu™óÿu™óÿu�öÿtœöÿtœöÿsŸöÿs¡÷ÿt öÿužõÿu›óÿuœôÿtŸöÿužöÿu�óÿv�òÿv�óÿvœòÿvœôÿvœóÿvœòÿv›ñÿv›òÿvšñÿušñÿv™ðÿv™ïÿv˜îÿw˜îÿw™ðÿv™ñÿvšñÿv™ïÿw˜ïÿw˜ðÿw˜ðÿw™ñÿv™òÿvšõÿwšôÿwšóÿwšóÿy™ðÿy–êÿz•èÿ{”æÿ|“ãÿ}’áÿ}’ßÿ|’Þÿ|’ßÿ|“àÿ|“àÿ}“ßÿ}“ßÿ}“ßÿ~“Þÿ~“Ýÿ~’Üÿ~’Üÿ’Ûÿ’Úÿ’Ùÿ’Øÿ€“Øÿ€“Ùÿ’Øÿ’×ÿ€’×ÿ�’×ÿ�‘Öÿ€’Öÿ�’Öÿ�’×ÿ�’Øÿ�’×ÿ�’×ÿ�’Øÿ€“Úÿ€“Ùÿ�’Øÿ�’Øÿ€’Ùÿ€’Úÿ€“Üÿ”Ýÿ•ßÿ~•àÿ~•áÿ}•ãÿ}–åÿ}—çÿ}–åÿy�Úÿ_k£ÿJJqÿ@ÿW]‹ÿyŠÑÿ|‘Þÿ}’áÿ~’àÿ~’ßÿ~’ßÿ~’ßÿ‘Ýÿ�Ûÿ€�Úÿ��Úÿ€�Ùÿ€�Ùÿ€�Úÿ€�Úÿ€ŽØÿ��Õÿ‚�ÒÿƒŒÏÿ„ŒÎÿƒŒÍÿƒŒÌÿƒŒÌÿƒ‹Êÿƒ‹Éÿ„‹Çÿ„ŠÆÿ„ŠÅÿ„ŠÅÿ…‰Äÿ…‰Ãÿ„ˆÂÿ„ˆÁÿ„ˆÀÿ…‡Àÿ„†¿ÿ„†¾ÿ„…¾ÿ„…½ÿ„…¼ÿ„„¼ÿ„„»ÿ„ƒºÿ„ƒºÿ„‚¹ÿ„‚¸ÿ„�·ÿ…�¶ÿ„�´ÿ…�´ÿ…‚´ÿ…‚³ÿ…‚´ÿ…�´ÿ…�³ÿ…�³ÿ…�²ÿ…�²ÿ„€±ÿ„€°ÿ„€°ÿƒ~®ÿ„®ÿ„®ÿ„~®ÿ…~®ÿ„}­ÿ„}«ÿ…|«ÿ…|«ÿ„{ªÿ…{ªÿ…{ªÿ„z©ÿ„z¨ÿ„z¨ÿƒz¨ÿ„y§ÿ„y§ÿ„y§ÿ„y¦ÿƒx¥ÿƒx¥ÿ‚x¤ÿ‚x¤ÿ‚w£ÿ�w¢ÿ‚v¢ÿ‚v¡ÿ‚u¡ÿ�u ÿ�u ÿ�uŸÿ�užÿ�užÿ‚tžÿ‚tžÿ�tœÿ�sœÿ�sœÿ‚sœÿm½þÿn½þÿn½þÿn¼þÿo¹þÿp¶þÿp´þÿp²þÿp°þÿp¯þÿq®þÿr¬ýÿr«ýÿr©üÿr§ûÿr¥úÿs£ùÿr£ùÿr£ùÿs¢ùÿt£ûÿs£ûÿs£ûÿs£ûÿs£ûÿs£üÿt£üÿt¢ûÿs úÿs¡ùÿt£úÿt¥úÿt£úÿt¡ùÿt¢úÿu¡úÿt¡úÿt¡úÿu¡úÿt¡úÿt¡ùÿt¢ùÿt£úÿt¤ûÿs¤ûÿt£úÿt£øÿu¤÷ÿu¤÷ÿu¤öÿu¦øÿt¨ùÿtªúÿs­ûÿr¯üÿr±ýÿp¶þÿpºÿÿo¾ÿÿo¿þÿo¼þÿp¹ÿÿqµþÿq°þÿr«ýÿt©ûÿu¨ùÿu¨ùÿt§ùÿt§ùÿu©úÿu©ûÿt¨ûÿt¨ûÿt§ûÿt¦ûÿu¥ûÿu¦ûÿt¥ûÿt¤ûÿu£úÿv¢úÿv¡úÿw¡øÿw¡øÿw¡øÿv¢úÿv£ûÿv¤üÿv¥üÿv¥ûÿv¤ûÿw¤úÿx£úÿx¢ùÿx¡øÿx ÷ÿxŸõÿyžôÿy�òÿwšíÿ^q®ÿ@?_ÿ/#0ÿ-#/ÿ.$0ÿ,"-ÿ-",ÿ-"-ÿ-!,ÿ-",ÿ,!,ÿ+!,ÿ+!+ÿ**ÿ+ +ÿ* *ÿ))ÿ)(ÿ)'ÿ)'ÿ(&ÿ'%ÿ&%ÿ&$ÿ&%ÿ'&ÿ'%ÿ'$ÿ)&ÿ)&ÿ)&ÿ('ÿ((ÿ*(ÿ('ÿ*(ÿ+*ÿ,!+ÿ-!+ÿ,!+ÿ,!+ÿ-!*ÿ."+ÿ.#.ÿ.#.ÿ0%/ÿ:0Aÿ[]‡ÿ}ˆÆÿ�ŽÐÿ‚�Ñÿ‚�Ñÿ‚�Ðÿ‚�Ðÿ‚�Ðÿ‚�Ïÿ‚ŽÎÿ‚ŽÏÿƒŽÏÿƒ�Ïÿƒ�Ïÿ‚ŽÑÿ‚�Ñÿ‚�ÏÿƒŒÍÿƒŒÊÿ„‹Èÿ„‹Èÿ„‹Èÿ„‹Éÿƒ‹Èÿƒ‹Çÿ„ŠÆÿ„ŠÆÿ„ŠÅÿ„ŠÅÿ„ŠÄÿ„‰Ãÿ„‰Ãÿ„‰Ãÿ„ˆÂÿ„ˆÁÿ„ˆÁÿ„‡Àÿ„†Àÿ„†¿ÿƒ…¿ÿƒ…¾ÿƒ„¾ÿƒ„½ÿƒƒ½ÿ‚ƒ¼ÿ‚‚»ÿƒ‚¹ÿƒ�¹ÿƒ�¸ÿƒ�·ÿ„‚¶ÿ„‚µÿ…‚µÿ…‚µÿ…�µÿ…�´ÿ„�´ÿ„�´ÿ„�³ÿƒ�³ÿ„€³ÿƒ²ÿƒ~±ÿƒ~±ÿƒ~°ÿƒ}¯ÿƒ}¯ÿƒ}®ÿƒ|­ÿƒ|¬ÿƒ|«ÿƒ{«ÿƒ{«ÿƒzªÿƒzªÿƒz©ÿƒz©ÿƒz©ÿ„y¨ÿƒy¨ÿƒy¨ÿƒy§ÿ‚y¦ÿ‚x¦ÿ‚w¦ÿ‚w¥ÿ‚w¤ÿ‚w¤ÿ�w£ÿ�v¢ÿ�u¢ÿ�u¢ÿ�u¢ÿ�u¡ÿ�u ÿ�u ÿ�tŸÿ�tŸÿ‚tžÿ�s�ÿ�s�ÿ�s�ÿo¯þÿp°þÿo°þÿo°þÿp±þÿp°þÿp®þÿp­þÿp«þÿp¨þÿq¦þÿr£ýÿr¡üÿs ûÿs ùÿsŸøÿs�÷ÿs�öÿs�öÿs�÷ÿsžøÿsžøÿtžøÿt�÷ÿu�öÿt�÷ÿu�÷ÿu�õÿuœôÿuœóÿvœóÿwœóÿvœòÿvœòÿvœòÿwœòÿw›òÿv›òÿvœòÿvœòÿwœòÿw›ñÿvœóÿv�öÿu�÷ÿv�õÿwœòÿw›ðÿw›ïÿxšîÿxœïÿxœðÿx�òÿwŸôÿw õÿu£õÿt©øÿs®ùÿqµúÿo½üÿn¿þÿo¾ýÿo»ýÿo¶þÿp³ýÿq°ýÿr°ýÿs°ýÿr°ýÿr¯þÿs±þÿr°þÿr¯þÿr­ýÿr«ýÿs©üÿs©üÿs¨ûÿs§ûÿt¦ûÿt¦ûÿu¤ûÿu¤ûÿu£ûÿu¤ûÿt¤ûÿt¦üÿt§ýÿt¨þÿt¨þÿt©þÿt¨ýÿt§þÿt¦þÿt¥ýÿu¤ýÿu£ýÿu¡üÿu ûÿt úÿsœóÿZp®ÿ?=Zÿ1%1ÿ.#.ÿ-#-ÿ.#,ÿ.",ÿ-!,ÿ."-ÿ-"+ÿ0$/ÿ.#.ÿ* *ÿ*(ÿ)'ÿ)'ÿ)&ÿ(%ÿ'$ÿ'#ÿ&!ÿ%!ÿ%!ÿ$ ÿ&#ÿ&"ÿ&!ÿ'!ÿ'!ÿ'!ÿ($ÿ(%ÿ(%ÿ'#ÿ($ÿ($ÿ-!+ÿ1$/ÿ-!*ÿ-!*ÿ,)ÿ. )ÿ.!)ÿ- )ÿ.!+ÿ/"+ÿ5)6ÿWW{ÿ{„ºÿ‚ŒÇÿ„�Çÿ„�Çÿƒ�Æÿ„�Æÿ„�Åÿ„ŒÄÿ„ŒÄÿ„ŒÄÿ„ŒÄÿ…‹Äÿ…‹Äÿ…‹Äÿ„‹Äÿ„‹Ãÿ…ŠÂÿ…ŠÁÿ…ŠÀÿ…ŠÀÿ…ŠÂÿ„ŠÂÿ„ŠÂÿ„ŠÂÿ„‰Áÿ…‰Áÿ…‰Áÿ„‰Áÿ„‰Áÿ„ˆÀÿ„ˆÀÿ„ˆÁÿ„ˆÁÿ„‡Àÿ„‡Àÿƒ‡¿ÿ„‡Àÿ„†Àÿƒ…¿ÿƒ…¿ÿƒ…¿ÿƒ„¾ÿ‚ƒ¾ÿ‚ƒ½ÿ‚‚¼ÿ‚�»ÿ‚‚ºÿ‚‚¹ÿ‚‚¹ÿƒ‚¹ÿƒ‚·ÿƒ�·ÿ„�¶ÿ„�¶ÿ„�¶ÿƒ�µÿƒ€´ÿƒ�µÿƒ€µÿƒµÿ‚´ÿƒ~³ÿƒ~²ÿ‚~±ÿ‚}±ÿ‚|¯ÿ‚}¯ÿ‚|¯ÿ‚|­ÿ‚|¬ÿ‚{¬ÿ‚{¬ÿ�{«ÿ�z«ÿ‚z«ÿƒzªÿƒzªÿƒyªÿƒyªÿ‚z©ÿ‚y©ÿ‚y¨ÿ‚x§ÿ‚x§ÿ‚w¦ÿ‚w¦ÿ�w¥ÿ�w¥ÿ�w¥ÿ�v¥ÿ�v¥ÿ€v¤ÿ�v¤ÿ�u£ÿ�u¢ÿ�t¡ÿ�t¡ÿ�t ÿ�tŸÿ€tŸÿ�tŸÿoªþÿoªþÿo«þÿo­þÿo­þÿn¬ýÿo«þÿoªÿÿp¨þÿp§ýÿq¦þÿq¥þÿq¤ýÿq£üÿq¤ýÿr¢üÿr¡üÿr üÿr ûÿržúÿqžùÿr�øÿsœ÷ÿt›õÿu›óÿu›òÿuœòÿuœñÿv›ðÿv›ðÿvšïÿvšîÿv›ïÿu›ðÿušïÿušïÿvšïÿv›ïÿv›ïÿvšïÿwšîÿvšîÿvšïÿuœòÿu�õÿu�öÿu�ôÿv�òÿv�òÿvœñÿw›ïÿxšíÿxšíÿxšíÿxšìÿxšìÿx›îÿxšïÿv�ðÿs¦öÿq¯úÿp°úÿq®ùÿq«ùÿr©ùÿs¦øÿt¥÷ÿt§øÿs©ùÿrªúÿqªüÿr«üÿs©úÿs§ùÿs¤øÿt¢öÿu ôÿuŸóÿvŸòÿvŸñÿvŸòÿvŸòÿvŸóÿv õÿu¡õÿt¢öÿt¥÷ÿt§ùÿs¨úÿs¨úÿs§úÿs¦ùÿs¥úÿs¤úÿs¤úÿt¢úÿt¡úÿt úÿt ûÿsŸøÿm•êÿSeŸÿ91Iÿ/$/ÿ-"+ÿ* &ÿ."*ÿ-!*ÿ+ )ÿ.!+ÿ.")ÿ6)4ÿ1&0ÿ)&ÿ, )ÿ)'ÿ-!*ÿ*'ÿ'"ÿ*%ÿ*"ÿ)!ÿ+ &ÿ,#,ÿ+",ÿ-!+ÿ,!)ÿ+'ÿ,!)ÿ/%/ÿ-!*ÿ-"*ÿ-"*ÿ-!)ÿ-!)ÿ, (ÿ-"*ÿ3'2ÿ6*4ÿ1%-ÿ, 'ÿ,%ÿ,&ÿ,'ÿ,(ÿ. *ÿ- )ÿ.&ÿLIfÿrw§ÿ‚‹Ãÿ„�ÆÿƒŒÅÿƒŒÅÿƒŒÄÿƒŒÃÿ„‹Ãÿ„‹Âÿƒ‹Áÿ„‹Âÿ…‹Âÿ…ŠÁÿ…ŠÀÿ…ŠÀÿ…ŠÀÿ„‰¿ÿ…‰¿ÿ…‰¾ÿ…‰¾ÿ…‰¾ÿ„‰½ÿ„ˆ½ÿ„ˆ½ÿ„ˆ½ÿ„ˆ½ÿ„ˆ½ÿ„ˆ½ÿ„‡½ÿ„†¼ÿ„†½ÿ„†½ÿƒ†½ÿƒ†¼ÿ‚†¼ÿ‚†½ÿƒ†½ÿƒ…½ÿƒ…½ÿƒ…¾ÿ‚„½ÿƒ„½ÿ‚ƒ¼ÿ‚‚»ÿ‚‚»ÿ�‚ºÿ‚‚ºÿ‚‚¹ÿ‚�¸ÿ‚�¸ÿ‚�·ÿ‚�·ÿƒ€¶ÿƒ€¶ÿƒ�¶ÿ‚�µÿ�€µÿ‚€µÿ‚µÿ‚´ÿ�~³ÿ‚~³ÿ�~±ÿ�}±ÿ�|°ÿ�{°ÿ�|°ÿ€|¯ÿ€{®ÿ�{­ÿ�|­ÿ‚{­ÿ�{¬ÿ�z¬ÿ‚z«ÿ‚z«ÿ‚z«ÿ‚y«ÿ‚yªÿ‚yªÿ‚yªÿ�x©ÿ‚x¨ÿ‚x¨ÿ‚x¨ÿ�x§ÿ€w¦ÿ�w¦ÿ�w¦ÿ�w¦ÿ�w¦ÿ�v¦ÿ�v¥ÿ€u¤ÿ€u£ÿ€u¤ÿ€u£ÿ€t¢ÿ€t¡ÿ€t¡ÿ�t ÿoªýÿoªþÿoªþÿo«ýÿn­þÿn®ýÿn¯þÿn¯ÿÿn¯þÿn®ýÿo«þÿoªýÿn¨ýÿn§ýÿo¦þÿp¥þÿp£ýÿp¡ýÿp¡ýÿp¡ýÿq üÿqžúÿqžúÿržùÿržøÿržùÿr ùÿr øÿrŸøÿsŸøÿs øÿr ÷ÿr ÷ÿr ÷ÿr øÿrŸøÿrŸùÿr úÿr¡úÿs¡ùÿs¡øÿr¡ùÿr¡ùÿr¢ûÿr£ûÿr¢üÿq¢ûÿq¢ûÿr¢ûÿs úÿtŸùÿtž÷ÿt�öÿu›óÿv›ðÿvšïÿw™ïÿx™îÿw˜ìÿvšíÿv�ðÿv�ïÿv›íÿvšìÿw™ëÿw˜êÿw˜éÿw™ëÿvšîÿu›ðÿuœòÿuœòÿu›ñÿvšïÿw˜íÿx—êÿx—èÿx–çÿy–çÿy•åÿy”åÿz•äÿz•äÿy•åÿy–åÿy–åÿx—æÿx˜èÿx™êÿwšëÿw™ëÿw™êÿw˜ëÿw˜ëÿw˜ìÿw˜ìÿw˜íÿw˜îÿwšðÿu–êÿf}ÃÿHMxÿ0#0ÿ/$0ÿ4'3ÿ/$.ÿ4)5ÿ6+8ÿ3(5ÿ1%0ÿ/#-ÿ7*7ÿ0$.ÿ'#ÿ1&1ÿ1(5ÿ6+9ÿ0%/ÿ- 'ÿ6(1ÿ5%,ÿ2#(ÿ8,9ÿ@7KÿB:PÿÿXVyÿ~†¾ÿ„ŒÆÿƒŠÄÿƒŠÃÿƒŠÂÿ‚ŠÁÿƒ‰Áÿƒ‰Àÿƒ‰Àÿ„‰Àÿ„‰¿ÿ„‰¿ÿ„‰¾ÿ„‰¾ÿ…ˆ¾ÿ„ˆ½ÿ„ˆ½ÿ„ˆ½ÿ„‡¼ÿ„†»ÿƒ†ºÿ‚…ºÿ‚…ºÿ�…¹ÿ‚…¹ÿƒ…¹ÿƒ…¹ÿ‚„¹ÿ‚„¹ÿ‚„¹ÿ‚„¸ÿ‚ƒ·ÿ‚ƒ·ÿ�ƒ¸ÿ�„¸ÿ�„·ÿ�ƒ¸ÿ‚‚¸ÿ‚‚·ÿ�‚·ÿ‚‚·ÿ‚‚¶ÿ‚�µÿ‚€µÿƒ€µÿ‚€µÿ‚€µÿ‚€´ÿ�´ÿ�´ÿ�³ÿ‚³ÿ‚³ÿ‚²ÿ�²ÿ�~²ÿ�~²ÿ�~²ÿ�~±ÿ�}±ÿ�|°ÿ€|¯ÿ�|®ÿ�|®ÿ�|®ÿ€{­ÿ€{­ÿ€z­ÿ€z­ÿ€{¬ÿ€z«ÿ�z«ÿ�z«ÿ�zªÿ�y©ÿ‚yªÿ�x©ÿ�x©ÿ�x¨ÿ�x©ÿ�x¨ÿ�w§ÿ�w§ÿ�w§ÿ€w§ÿ�w¦ÿ�w¦ÿ�w¦ÿ�w¦ÿ€v¥ÿ€v¦ÿ�v¦ÿ€u¥ÿu¤ÿ€v¤ÿ€u¤ÿ€u£ÿ€t£ÿ�t¢ÿ�t¢ÿo¦þÿo¥þÿo¥ýÿn¦ýÿo¦ýÿo§þÿn§þÿn§þÿn¨þÿn¨þÿn§þÿn§þÿn¦þÿn¥þÿn¤þÿo¤þÿo£þÿo¢þÿo¢þÿp¢þÿp¡ýÿp¡üÿp¡üÿq¡üÿq üÿp¡üÿp¢üÿp¢üÿp¢ýÿq¢üÿq£ýÿp¤üÿp¤üÿp¤ýÿp¥ýÿp¤ýÿp¤ýÿp¤ýÿp¤ýÿp£ýÿp£üÿp¡üÿp¡üÿq¡üÿq¡ûÿrŸúÿqŸùÿqŸùÿrŸ÷ÿs�õÿt�öÿt�öÿtœõÿt›ôÿt›òÿušðÿvšïÿvšïÿv™îÿv˜îÿu™ñÿušñÿu™îÿv˜ìÿw—ëÿw—ëÿw—ëÿw—ëÿw—ëÿw—ëÿw—ìÿv–ìÿv–ëÿw•êÿw”çÿx”åÿw“ãÿx’âÿx’âÿy’áÿy‘àÿz‘àÿz‘àÿy’ßÿy’Þÿy‘Þÿy‘Þÿy‘ßÿy‘ßÿy’àÿy’ßÿy‘ßÿy‘ßÿy‘àÿy‘àÿy‘àÿy‘áÿy’ãÿz”æÿu�ÛÿV\Žÿ<3Lÿ5&5ÿ7*:ÿ5'3ÿ5(3ÿ6*9ÿ7,;ÿ6*8ÿ4'3ÿ7*7ÿ0$/ÿ-!*ÿ.!*ÿ1&3ÿ@6Kÿ9.>ÿ8*4ÿ:*3ÿ6&/ÿA-8ÿ:)1ÿ>/9ÿG;NÿGBZÿD:PÿD:Pÿ<2Dÿ7-;ÿ@5Hÿ?5Hÿ<0Bÿ<1@ÿ=3Cÿ<2Bÿ;.>ÿ:.?ÿ5*8ÿ0%.ÿ3%/ÿ3$.ÿ1"+ÿ2$-ÿ5&0ÿ5&1ÿ5'2ÿ5'1ÿ3%/ÿ3$-ÿE=UÿnpŸÿ†½ÿ„ŠÃÿƒ‰Âÿ‚‰Áÿƒ‰Áÿƒ‰Áÿ�ƒ¹ÿ€�µÿ„†½ÿƒ‡½ÿ„ˆ½ÿ„‡½ÿ„‡½ÿ„†¼ÿƒ…¼ÿƒ…¼ÿ‚…»ÿ‚„»ÿ‚„ºÿ‚„¹ÿ�ƒ¹ÿ�„¸ÿ�„¸ÿ�ƒ¸ÿ�ƒ·ÿ�ƒ¶ÿ�ƒ¶ÿ�‚¶ÿ�‚¶ÿ‚‚¶ÿ‚‚µÿ‚‚µÿ�‚µÿ€‚µÿ��´ÿ��´ÿ��³ÿ��³ÿ��²ÿ‚€²ÿ‚€²ÿ‚€²ÿ�²ÿ‚±ÿ�~±ÿ�~±ÿ�}°ÿ€}°ÿ�~°ÿ�~°ÿ�}°ÿ�}¯ÿ�}¯ÿ�}¯ÿ�}¯ÿ�|¯ÿ€|¯ÿ�|®ÿ�|®ÿ�{­ÿ�{¬ÿ�{¬ÿ�{«ÿ€{«ÿ€z«ÿ€z«ÿ€z«ÿ€yªÿ€zªÿ�yªÿ€yªÿ�y©ÿ�y©ÿ�x¨ÿ�x¨ÿ�x§ÿ�x§ÿ�w§ÿ€w§ÿ�w§ÿ�w¦ÿ�v¥ÿ€v¥ÿ€v¥ÿ€v¥ÿ€v¥ÿ€v¥ÿ€v¥ÿ�u¤ÿ€u¤ÿ€u¤ÿ€u¤ÿ€u¤ÿ€v¥ÿ€v¥ÿ€u¥ÿ�u¤ÿ�t¤ÿ€t£ÿo¬þÿo¬þÿo«þÿnªýÿnªýÿnªýÿo©þÿo¨þÿn§þÿn§þÿn¨þÿn¨þÿn¨þÿn¨þÿn¨þÿo¨þÿo¨þÿo¨þÿo¨þÿo§þÿo¦ýÿo¦ýÿo¦ýÿp¥ýÿp¤ýÿo¥ýÿo¥ýÿo¥þÿo¦þÿo¦þÿo¦þÿp§þÿo§þÿo§ÿÿo¦þÿo¦þÿn¥þÿo¤ýÿo£üÿp úÿq�öÿq�øÿpŸüÿp ýÿp üÿpŸúÿqžøÿq�øÿq�÷ÿrœõÿsœõÿsœöÿsœöÿrœõÿs›õÿs›óÿt›òÿtšòÿtšñÿt™òÿt™óÿtšòÿs™ðÿt™îÿu™îÿu˜íÿu˜íÿu—íÿv—íÿv—ìÿv–ëÿv•ëÿv•êÿv•éÿv”çÿv”æÿw“åÿw’äÿw‘ãÿw’âÿw’âÿx‘âÿy‘áÿy�àÿy�Þÿy�Þÿy�Ýÿy�Üÿy�Üÿy�Üÿy�ÛÿyŽÚÿyŽÚÿyŽÚÿz�Ùÿz�ÙÿyŽÙÿz�ÛÿxŠÔÿiu³ÿG@_ÿ9)6ÿ:,<ÿ<,=ÿ:+8ÿ;,9ÿ;.=ÿ9-;ÿ8+7ÿ;-;ÿ>0@ÿ4'3ÿ2%/ÿ5(2ÿ5)6ÿC7Kÿ;/>ÿ:,7ÿ<-8ÿ7)4ÿ@/=ÿ=-:ÿ>/:ÿC6GÿE=RÿC6KÿE7LÿA3Dÿ<.;ÿ>0?ÿ@3Dÿ@3Eÿ?3Cÿ=2Aÿ<0@ÿ9+9ÿ<.>ÿ7*7ÿ3&/ÿ;,8ÿ=-:ÿ8(3ÿ6(2ÿ8*5ÿ8)4ÿ8)4ÿ9)4ÿ9)5ÿ8(3ÿ=0AÿVQsÿx{­ÿƒˆÀÿƒ‡¿ÿƒ‡¾ÿ�ƒ¶ÿ~|«ÿxo˜ÿwl’ÿz¨ÿ‚„ºÿƒ†½ÿƒ…¼ÿƒ„»ÿ‚ƒ»ÿ‚ƒºÿ‚ƒºÿ�‚¹ÿ�‚¸ÿ�‚¸ÿ�‚¸ÿ�‚¸ÿ�‚·ÿ�‚¶ÿ€�¶ÿ€�µÿ€�µÿ��µÿ�€µÿ�€´ÿ�€³ÿ€€³ÿ€³ÿ�²ÿ€±ÿ€±ÿ€±ÿ�°ÿ�~°ÿ�~¯ÿ�~¯ÿ�}¯ÿ�}¯ÿ€}¯ÿ�}®ÿ�}®ÿ�|®ÿ€|®ÿ€|®ÿ�|®ÿ�|®ÿ�|­ÿ�|­ÿ�|­ÿ�|­ÿ�|¬ÿ€{¬ÿ€{«ÿ�{«ÿ�zªÿ�zªÿ�zªÿ�z©ÿ€z¨ÿ€z¨ÿ€y¨ÿ€y¨ÿ�y¨ÿ€x¨ÿ€x¨ÿ€x¨ÿ€x§ÿ€y§ÿ€x§ÿ€x¦ÿ€x¦ÿ€x¦ÿ�w¦ÿ€w¦ÿ€w¥ÿ€w¥ÿ�w¥ÿ€v¤ÿ€v¤ÿ€v¤ÿ€v¤ÿ€u¤ÿ€u£ÿ€u£ÿ€u£ÿ€u£ÿ€u¤ÿ€u¤ÿ€u¤ÿ€v¥ÿv¥ÿv¥ÿ€v¥ÿ�v¦ÿ�v§ÿm»þÿmºþÿn¸þÿn·þÿmµýÿnµýÿo´þÿn²ýÿn±ýÿm¯þÿm¯þÿn¯þÿm°ýÿm°ýÿn±þÿn±þÿn±þÿn±þÿn±þÿm±þÿm°ýÿn°þÿn°þÿn¯ýÿn¯ýÿn¯þÿm¯þÿm°ýÿn°þÿn°þÿo¯þÿo®þÿn¬þÿnªþÿn©þÿn©ýÿn¨ýÿo¤ûÿp¡ùÿqžöÿs˜ìÿt—íÿs—îÿršðÿqžöÿpŸøÿo úÿo ûÿpŸûÿožúÿpžùÿp�ùÿp�ùÿp�ùÿp�ùÿq�øÿq�øÿq�÷ÿq�öÿq�öÿrœõÿrœôÿr›óÿr›òÿr›òÿr›òÿr›ñÿsšòÿsšòÿsšðÿs˜ïÿs—îÿs—îÿs–ìÿt•ëÿu”éÿu“éÿu’çÿu‘åÿu�åÿv‘äÿv‘äÿv�ãÿw�âÿx�àÿxŽßÿwŽÞÿwŽÝÿw�ÜÿxŽÛÿx�ÚÿxŒÙÿxŒØÿxŒØÿxŒÖÿx‹Öÿx‹Ôÿy‹Ôÿp|¼ÿSQwÿ>3Fÿ;-;ÿ;-;ÿ;,9ÿ>/=ÿ<-:ÿ>0>ÿ;-:ÿ9+6ÿ0@ÿ=,;ÿ?.<ÿ?/<ÿ>.;ÿ<,:ÿ<.;ÿ>2@ÿ<0=ÿ9,7ÿ;.<ÿ>5Gÿ?4Eÿ=1@ÿ:-:ÿ:*6ÿ=-:ÿ:+6ÿ9,7ÿ:-9ÿ:,8ÿ;,8ÿ<,8ÿ<,8ÿ<,9ÿ=-;ÿB7Jÿkj•ÿ~�µÿƒ†¾ÿƒ…ºÿ~x£ÿuf…ÿoViÿpWiÿylŽÿ‚�¶ÿƒ…¼ÿƒƒºÿ‚‚ºÿ‚�ºÿ‚‚¹ÿ��¹ÿ��¸ÿ��·ÿ��·ÿ€�·ÿ€€·ÿ€€¶ÿ€�µÿ€�´ÿ�€´ÿ€´ÿ€´ÿ�³ÿ‚²ÿ�²ÿ€~±ÿ€~±ÿ€~°ÿ~¯ÿ}¯ÿ€}¯ÿ�}¯ÿ�|®ÿ�|®ÿ�|®ÿ€|­ÿ€|­ÿ€|­ÿ�|­ÿ‚|­ÿ�|¬ÿ�|¬ÿ�|¬ÿ�|¬ÿ�{¬ÿ�|¬ÿ�|«ÿ�{«ÿ�{ªÿ�{ªÿ�{©ÿ€z©ÿ€z¨ÿ€y¨ÿ€y¨ÿ�y¨ÿ€y§ÿ€y§ÿ€y§ÿ€x¦ÿ€x¦ÿ€x¦ÿ€x¦ÿ€x¦ÿx¦ÿ€x¦ÿ€x¦ÿ€x¥ÿx¥ÿx¤ÿ€w¤ÿ€w¤ÿ€w¤ÿ€w¤ÿ€w£ÿw¤ÿ€w¤ÿ€v¤ÿ€w£ÿv£ÿu£ÿu£ÿu£ÿu£ÿv¤ÿ€v¤ÿ€u¤ÿv¥ÿv¥ÿv¦ÿv¦ÿu¤ÿ}s ÿ}qžÿlÆýÿlÅþÿmÃþÿnÁþÿn¿þÿn¾þÿn½þÿm¼þÿm»ýÿlºþÿl¹þÿm¸þÿm¹þÿl¹ýÿm¹þÿm¸þÿl¸ýÿl¸ýÿl¹þÿl¹þÿlºýÿmºþÿmºþÿmºþÿl»ýÿm»þÿm»þÿl»þÿl»ýÿmºþÿm¸þÿm¸þÿm³üÿm¬ûÿnªûÿn¬üÿnªûÿo¤ùÿp¡÷ÿp¡÷ÿr›îÿv’Þÿz‹ÐÿyŒÐÿv”ßÿt—æÿp¡ôÿn¥üÿo¥ýÿn¥ýÿm¤þÿn£ýÿn¢ýÿn¢ýÿn¢ýÿn¡üÿn¡üÿn¢üÿn¢üÿn£üÿn£ûÿo¢ûÿo¡úÿo¡úÿo úÿn¡ùÿo¡ùÿo¢ùÿo¡ùÿo ÷ÿpžöÿpœõÿp™ôÿq˜òÿr–ðÿr•îÿs”ìÿs“ëÿs’éÿt�éÿt�èÿs�æÿt�åÿu�åÿu�ãÿtŽâÿu�àÿv�ßÿvŒÞÿvŒÝÿwŒÜÿw‹Úÿw‹Ùÿw‹Øÿw‹×ÿw‹×ÿwŠÖÿsƒÉÿcj¡ÿC8Pÿ:,;ÿ8+7ÿ8*5ÿ8*5ÿ:,8ÿ6)4ÿ8*7ÿ:,9ÿ9+8ÿ5(3ÿ)%ÿ% ÿ($ÿ,",ÿ1(7ÿ8-=ÿ6(5ÿ6'2ÿ8)4ÿ7*5ÿ5(3ÿ5(3ÿ5'2ÿ3&0ÿ4&2ÿ7(5ÿ7(3ÿ7)3ÿ7)5ÿ6(4ÿ6(3ÿ:,:ÿ9,8ÿ6'1ÿ9-;ÿJE]ÿG@WÿG?TÿG@Vÿ<6Lÿ4)5ÿ9+6ÿ:,8ÿ7*5ÿ7)5ÿ7*6ÿ9+6ÿ8*4ÿ7*4ÿ:+6ÿÿ1$/ÿ/"+ÿ2$.ÿ3&0ÿ0#-ÿ/#,ÿ/!,ÿ9*9ÿ?1@ÿ7*7ÿ"ÿ#ÿ2(6ÿ;/Bÿ=/?ÿ=1Eÿ:,;ÿ8(3ÿ6(3ÿ6(5ÿ6'4ÿ4%0ÿ2$.ÿ2%0ÿ3'4ÿ5*7ÿ6*6ÿ6+8ÿ7,:ÿ9-:ÿ<.<ÿ<.<ÿ8*6ÿ6'1ÿ9+7ÿC5EÿMAWÿVNjÿgc‰ÿooœÿG>Tÿ@/;ÿ9*7ÿ)%ÿ&"ÿ($ÿ- (ÿ+$ÿ&ÿ'!ÿ-!+ÿD:Oÿjg‘ÿ‚‚¹ÿ…„¸ÿ}p”ÿrZmÿoR\ÿsWfÿye‚ÿƒ²ÿ…„ºÿ„ƒ¹ÿ„‚·ÿ„�¶ÿ„€µÿƒ€µÿƒ€µÿ‚€µÿ�´ÿ�´ÿ‚´ÿƒ³ÿƒ²ÿ‚~±ÿ�}±ÿ€}²ÿ€~²ÿ�~³ÿ‚~²ÿ�}±ÿ�}±ÿ�}±ÿ�|°ÿ€{¯ÿ€|¯ÿ�{®ÿ�{®ÿ�{®ÿ�{®ÿ‚{­ÿ�|­ÿ�{­ÿ‚{­ÿ‚{¬ÿ‚{¬ÿ‚{«ÿ‚{ªÿ�zªÿ‚z©ÿ‚z©ÿƒz©ÿ‚z©ÿ‚z©ÿ‚z©ÿ�z©ÿ‚z¨ÿ�z¨ÿ�z¨ÿ�y¨ÿ‚y¨ÿ�x§ÿ�x§ÿ�x§ÿ�x§ÿ�x¦ÿ�x§ÿ€y¦ÿ€y¦ÿ�x¦ÿ�y¦ÿ€x¥ÿ€w¥ÿ€w¥ÿ€x¤ÿ€w¥ÿ€w¤ÿ€w¤ÿ€w¤ÿv¤ÿ€w¤ÿ€v£ÿv£ÿv¢ÿv£ÿv£ÿu¢ÿu£ÿ€v£ÿ€v£ÿ€v£ÿ�v¤ÿ�v¤ÿ�v¤ÿ€v¥ÿ�v¤ÿ~r�ÿra‚ÿeNbÿcK\ÿj·þÿi¶þÿiµþÿi´þÿi³þÿi³þÿi³þÿi²þÿi±þÿj±þÿj¯þÿk®þÿj®þÿj®þÿi­þÿi¬þÿi¬þÿj¬þÿk«þÿj«þÿiªþÿi©þÿj¨þÿj§ýÿj¦ýÿj¥ýÿj¥üÿj¤üÿj¤ýÿj¤ýÿj¦þÿj§þÿj¦ýÿk£ûÿk¡ùÿk ùÿkŸøÿk ùÿk¡úÿk£ûÿk¡úÿo–êÿu‹Ôÿz‚½ÿ~{ªÿy¤ÿ~}ªÿz‰¿ÿsœÞÿl­ùÿl°þÿl°ÿÿl±þÿm°þÿm¯þÿl¯þÿl¯þÿl¯þÿl¯þÿm®þÿm®ýÿl­ýÿl¬ýÿm«ýÿl«ýÿlªýÿlªýÿlªýÿl©ýÿk©ýÿk¨üÿk¦üÿk¥ûÿk£ûÿk£ûÿl¢üÿl¡ûÿl¡ûÿl ûÿlŸûÿlžûÿmœùÿm™öÿn˜óÿn—òÿn–òÿn•òÿn•ñÿo•ðÿn”ðÿp”ïÿo”ïÿo”ïÿp”îÿp”îÿp’íÿn�äÿ\m¯ÿ?9Uÿ.".ÿ(%ÿ%!ÿ(%ÿ* +ÿ( ,ÿ&#ÿ'"ÿ6)5ÿ<.=ÿ/#/ÿ,!*ÿ2&1ÿ=1CÿC7NÿC6Kÿ=1Dÿ7)7ÿ1"+ÿ+&ÿ($ÿ+&ÿ. 'ÿ4'0ÿ>6HÿJEaÿPLjÿQNlÿOLiÿKGcÿG@YÿA9Mÿ=3Cÿ9.;ÿ6(4ÿ5'1ÿ:+6ÿA4DÿG;PÿULjÿ`Z}ÿ=3Dÿ;,7ÿ7(4ÿ'!ÿ!ÿ ÿ"ÿ#ÿ!ÿ ÿ'!ÿ1%0ÿWPpÿvpœÿ‚{§ÿ|kŠÿrYiÿoR[ÿsVbÿv^sÿ{n’ÿ~tžÿ}tžÿ}r›ÿ}q™ÿ{o•ÿzo”ÿzn”ÿzm“ÿyl’ÿxl’ÿzn”ÿ{o–ÿzn•ÿym“ÿxk�ÿ{sžÿ€{«ÿ‚~±ÿ‚}°ÿ‚|°ÿ�|¯ÿ‚|¯ÿ‚{®ÿ�|®ÿ�{®ÿ�|­ÿ�{­ÿ�{­ÿ‚{­ÿ‚{­ÿ‚{­ÿƒ{¬ÿƒz¬ÿƒ{¬ÿ‚zªÿ~u¡ÿ{q›ÿ{qšÿ|r›ÿ~tžÿ‚y¦ÿ�x¦ÿv¢ÿ€w£ÿ�x¨ÿ‚y¨ÿ‚y¨ÿ�y§ÿ�y§ÿ�x§ÿ‚x§ÿ�x¦ÿ�x¦ÿ‚x¦ÿ�x¦ÿ�x¦ÿ�y¦ÿ�y§ÿ�z¨ÿ‚z¨ÿ�x¦ÿ�w¦ÿ�x¦ÿ€x¥ÿ�w¤ÿ€w¤ÿ€w¤ÿ€w¤ÿ€w¤ÿ€x¥ÿ€w¤ÿv£ÿ€v£ÿ€v£ÿu¡ÿ~r�ÿ~sŸÿ�u£ÿ�w¥ÿ‚w¥ÿ‚w¤ÿ‚w£ÿ�v¢ÿ�u¡ÿ€s�ÿ~o—ÿr_}ÿdKZÿcIUÿf¦ýÿf¦þÿf¦ÿÿf¥ÿÿf¤ÿÿg¤ÿÿg¤þÿg£þÿg¢ýÿg¡üÿg¡ýÿh¡ýÿh üÿhŸûÿhŸûÿgžûÿgŸüÿgŸüÿhžûÿh�úÿgœùÿhœøÿh›øÿhšøÿišøÿh™÷ÿhš÷ÿišøÿišùÿi›ùÿiœùÿi�ùÿi�úÿi�ùÿjœøÿj™öÿk˜ôÿl•íÿl“êÿj–ðÿj—óÿl“íÿsˆÒÿz{­ÿ}u›ÿ~t˜ÿr“ÿ}t™ÿx‚¸ÿq˜áÿl¡÷ÿk£úÿk£ùÿk£ùÿk£ùÿk¤ùÿl¤ùÿl¤ùÿk¤ùÿk¤ùÿl£ùÿl£øÿl¢øÿl¢øÿl¡ùÿl¡øÿl ÷ÿl ÷ÿl ÷ÿlŸöÿkžõÿlžõÿl�õÿk›ôÿkšôÿlšôÿl›õÿlšõÿl™óÿk•ìÿj�Þÿk�ãÿl’ëÿm”ïÿm’íÿl�âÿlŒàÿm�ãÿm�èÿl‘ìÿn‘ëÿnŽäÿn�áÿnŽâÿoŽäÿp�åÿd|ÇÿLV‰ÿ1&5ÿ)&ÿ++ÿ(&ÿ+"0ÿ.'9ÿ*#2ÿ" ÿ, (ÿ6)5ÿ8+8ÿ0%0ÿ2$/ÿ:+9ÿÿTARÿc\ÿru§ÿux«ÿvx«ÿtv¨ÿrt¥ÿop¡ÿllšÿgf‘ÿa`ˆÿZWzÿMGcÿ:0@ÿ0#+ÿ5&0ÿ@1AÿD7Hÿ8+6ÿ8*4ÿ9*5ÿ0$,ÿÿ!ÿ#ÿ&ÿ(!ÿ( ÿ*"ÿ0!&ÿE7Kÿ`Snÿue€ÿt]pÿpT_ÿnPXÿoQZÿpS_ÿqXjÿq[rÿq[sÿq[qÿqZpÿoYkÿnXiÿmWhÿmUfÿmTfÿjSeÿmWkÿo[pÿp\qÿoYnÿkUgÿteƒÿv¡ÿ„~°ÿƒ}®ÿƒ|®ÿ‚|®ÿƒ|®ÿ„}®ÿ„~¯ÿ„~°ÿ„~°ÿ„~°ÿ„}¯ÿ„}¯ÿ…}®ÿ„|¬ÿ„{«ÿ„{«ÿ„{«ÿ‚x¥ÿug‰ÿm]xÿn^yÿo_zÿqa~ÿtf†ÿpbƒÿk]|ÿoaƒÿzo™ÿ�w¥ÿƒz©ÿ‚z©ÿ‚y§ÿ‚y§ÿ�w¤ÿ�w¤ÿ‚w¦ÿƒx¦ÿ‚y¦ÿ�x¤ÿtŸÿ{p™ÿxo–ÿyo—ÿv£ÿ€w£ÿ~tžÿ~tžÿ€u¡ÿ€v¡ÿ€u¡ÿ€v¡ÿ€v¡ÿ}s›ÿ|ršÿuŸÿ�v¡ÿ~q™ÿyk�ÿxf‡ÿyf‡ÿ{jŽÿ}n”ÿ}m”ÿ}o”ÿr™ÿq™ÿyi�ÿwd…ÿxe…ÿt_xÿmTeÿgN]ÿg—øÿg˜øÿg˜÷ÿf˜øÿg—øÿg–øÿh–öÿh•õÿh”ôÿh”òÿg”ôÿh”ôÿi’òÿi�ðÿi�ðÿh�ñÿh‘ñÿh�ñÿi�ðÿiŽîÿi�ëÿj�êÿj�éÿj�éÿkŒéÿkŒèÿj�èÿk�éÿkŽêÿk�éÿkŽéÿkŽêÿjŽêÿkŽêÿk�èÿl‹æÿm‰ãÿo†Ùÿo„ÕÿmˆÞÿm‰áÿnˆÜÿt~¾ÿzr˜ÿ{o‘ÿ}p‘ÿ}o‘ÿ}o�ÿ|s›ÿw»ÿn�æÿl�ìÿl�ëÿl�ëÿm�ëÿm�ëÿn�ëÿn�ëÿm�êÿm�éÿn�éÿn�éÿn�èÿn�èÿo�èÿo�çÿo�æÿoŽæÿoŽåÿo�äÿoŒãÿpŒãÿpŒãÿoŒãÿo‹âÿo‹àÿnˆÚÿn‡Øÿo…Ôÿm}Åÿkm¢ÿls±ÿn‚Ñÿp‹ãÿpˆÛÿmx¸ÿmt¯ÿow¶ÿp~Åÿp†ÖÿqƒÐÿpz¼ÿqx¶ÿr|½ÿs|¾ÿq{¼ÿY]�ÿ<7Rÿ-".ÿ-!,ÿ3'5ÿ1%1ÿ4*=ÿ6-Dÿ-%5ÿ((ÿ6)5ÿ:,9ÿ7*5ÿ6)4ÿ4&0ÿ7(5ÿ7*9ÿ3(9ÿ0'9ÿ7/Cÿ?1>ÿH4;ÿR:Aÿ[@Iÿ]AMÿbDPÿjPdÿxk‘ÿ‡‡¾ÿŠ�ÊÿŠ�Êÿ‰ŒÈÿ‰ŒÇÿˆ‹Çÿ‡‰Ãÿ„…¾ÿ��¸ÿ{{®ÿpo�ÿa^…ÿPKiÿ@7Kÿ6(4ÿ5'1ÿ:,6ÿ9*4ÿ;-8ÿ9+6ÿ'"ÿ$ÿ&ÿ*$ÿ- 'ÿ/!(ÿ-%ÿ6%,ÿ:(1ÿI5?ÿbIRÿlOVÿnPVÿmOUÿmNTÿlMSÿkLQÿgHMÿgHNÿiKPÿjKQÿiKPÿhJNÿfHLÿfGKÿfGKÿbCHÿcGNÿhNXÿlR^ÿkP[ÿdHNÿmXkÿ|n’ÿ„{©ÿ†}­ÿ„}¬ÿƒ{«ÿ‚y§ÿ�w£ÿu ÿ~tžÿ}s�ÿ}r�ÿ}r�ÿ}r›ÿ|p˜ÿtœÿƒy¤ÿ…{©ÿ…{§ÿƒvŸÿn[sÿcKVÿdMYÿeMYÿfMZÿeLXÿ^EOÿY?Gÿ^GUÿm\yÿzk�ÿ�t�ÿƒv¢ÿ‚w¤ÿ‚x¥ÿ�v¡ÿ€u ÿ€u ÿ�u ÿ‚v¢ÿ}p˜ÿvgŠÿn^{ÿhXrÿiYtÿuj�ÿwk�ÿrc„ÿsc…ÿxj�ÿzl‘ÿxjŽÿwi�ÿvhŒÿsc�ÿraÿvg‰ÿykŽÿvdƒÿp[uÿmUhÿnTdÿpWkÿr\uÿs]uÿs^vÿxe‚ÿyf†ÿq\vÿoVjÿqYoÿpYmÿiRdÿbK]ÿgƒâÿf�ßÿf€Ýÿf€Ýÿf�Ýÿg�Ýÿi‚Ýÿi‚Üÿi�Ûÿj‚ÛÿkƒÞÿkƒßÿlƒÞÿl‚Üÿk‚Üÿk‚Üÿk‚Üÿl�Ûÿm�Ùÿm€×ÿmÕÿl~Òÿl~Ñÿm~Ðÿm}Îÿn}Ìÿn}Íÿo~ÎÿpÏÿpÏÿoÎÿo~Ìÿn}Ìÿn|Ìÿn{ÉÿoyÄÿp}Éÿq}Éÿq}Èÿq~Ëÿr~Çÿt|Àÿvv­ÿxo—ÿym�ÿ{n�ÿ{mŽÿ|n�ÿ|n�ÿxpœÿr€ËÿpƒÔÿqƒÔÿqƒÔÿqƒÔÿq‚ÔÿqƒÔÿqƒÓÿr‚Òÿr�Ïÿs�Ïÿs�Ïÿt�Îÿs�Ìÿs€Éÿt�Éÿu€ÈÿuÇÿtÈÿu€Èÿt€Èÿt�Éÿs€ÉÿsÇÿtÆÿs|Âÿpr­ÿon¢ÿpnŸÿph‘ÿn[sÿob…ÿsw·ÿv„Òÿu}Ãÿoc‡ÿoZrÿqZpÿugŽÿxyµÿvq¡ÿuf…ÿvf†ÿxj�ÿxh‡ÿkYrÿM>Rÿ4)8ÿ0$1ÿ3&3ÿ6)8ÿ5(6ÿ6)<ÿ3(=ÿ+!0ÿ2&3ÿ;.;ÿ<.;ÿ7)4ÿ4&0ÿ5'0ÿ. (ÿ4)6ÿ;2Dÿ>8NÿUOmÿcPfÿgLWÿfHPÿfHPÿeEOÿeFOÿjLXÿt\qÿ�r–ÿ‡„ºÿ‡†½ÿ†…»ÿ‡†¾ÿ‰ˆÁÿ†„¹ÿ‡…»ÿˆ†½ÿ‡†½ÿ‡†½ÿˆ…»ÿ{u¢ÿ^Wvÿ?4Dÿ8*5ÿ7(3ÿ7(2ÿ:+7ÿ;,9ÿ5&2ÿ& ÿ#ÿ("ÿ- 'ÿ/!(ÿ- &ÿ3$+ÿ:)2ÿC0:ÿQ;EÿgKTÿlNVÿmNVÿmNVÿmNVÿlNUÿiKQÿiKQÿkMSÿlMTÿjKRÿiKQÿhJPÿgINÿgHMÿcDJÿbFLÿhMWÿnSaÿmS_ÿfKQÿiOYÿs^wÿ}n”ÿ„y¥ÿ„z§ÿ‚v¡ÿ|m’ÿtc€ÿn[rÿkVhÿhRdÿfPcÿgPbÿgN^ÿdL\ÿq]uÿ}n‘ÿ�uœÿ€s˜ÿp“ÿnYnÿfLXÿgNZÿgMXÿgLWÿeJSÿbHNÿaGLÿaFMÿ_GNÿjR`ÿyaxÿ€jŠÿ~n”ÿršÿq˜ÿ}n“ÿzkŽÿxi‹ÿ|m’ÿtaÿjShÿcKYÿ_FRÿ^FTÿdQgÿcOdÿ^ETÿ^ESÿePgÿjVmÿgQfÿ`I[ÿ`GXÿdJYÿbGUÿbIYÿdM`ÿfNbÿcK]ÿ^GVÿ]FRÿaGTÿeKYÿiPaÿkQ`ÿnUgÿpYoÿpXmÿoUfÿnUhÿcM_ÿVDTÿTCWÿXi´ÿSe«ÿSc¨ÿUe«ÿUf¬ÿUfªÿ\l´ÿ\k±ÿ\j­ÿfr¹ÿkwÂÿozÈÿqzÆÿpyÂÿoxÀÿpx¾ÿpyÂÿqzÅÿoxÃÿjt¼ÿmv¿ÿis¹ÿfqµÿfqµÿgq´ÿdn¯ÿgp²ÿnuºÿrzÀÿszÀÿsz¿ÿqt²ÿpo©ÿpm¤ÿoh™ÿoaˆÿrqªÿsw¶ÿsu³ÿtw·ÿuwµÿvv±ÿwt«ÿwr¥ÿwq ÿyo–ÿzn‘ÿ{n�ÿwi‰ÿqdˆÿuw´ÿu{»ÿv{¼ÿvz¹ÿtw³ÿux·ÿvz»ÿw{¼ÿux·ÿtu°ÿvy·ÿw{ºÿw{ºÿvx¶ÿuu±ÿtt¬ÿtr¦ÿuq¤ÿvs©ÿwv¯ÿwx±ÿy{·ÿvu¬ÿsm›ÿtm™ÿum˜ÿsc‚ÿp\sÿo\sÿs_tÿq[nÿsb~ÿyt§ÿ|~»ÿys¥ÿs`|ÿs[pÿt[mÿxg†ÿ}v¦ÿ{k‰ÿxcxÿxd}ÿzgƒÿwbxÿYGXÿ>/;ÿ2%1ÿ3'2ÿ5&1ÿ0#-ÿ0"0ÿ- 0ÿ%)ÿ""ÿ2&1ÿ7)5ÿ9+6ÿ6)2ÿ-!)ÿ- %ÿ+#ÿ3&*ÿOE]ÿng�ÿ}v£ÿr_}ÿhKWÿfHPÿgGOÿeELÿeFMÿhIRÿnR^ÿv^qÿyg…ÿyh‡ÿyiŠÿ€užÿˆ‚´ÿtŸÿ}ršÿ}tœÿ~uœÿs™ÿs˜ÿq”ÿ{l�ÿk[vÿJ9Cÿ8)0ÿ3&.ÿ4(1ÿ7)3ÿ6'2ÿ#ÿ ÿ&ÿ+#ÿ+%ÿ+ $ÿ.!&ÿG4<ÿO:EÿE2=ÿ]EPÿgLVÿkOYÿnQ]ÿpS_ÿoR\ÿlOXÿnPZÿqT^ÿpS^ÿkMUÿiLSÿhKQÿgIOÿfIOÿdGMÿdHOÿiMXÿnR_ÿmR^ÿfKSÿeLSÿhOYÿnXjÿwe€ÿziˆÿua|ÿoXmÿiP`ÿfMZÿlSaÿmTdÿhQ_ÿcJWÿ`GRÿdKWÿiQ`ÿnWkÿnXlÿiSdÿkTeÿgO[ÿgNZÿiP\ÿhNXÿfLUÿdKTÿbIPÿ`GMÿbIOÿ`GMÿdIQÿnOYÿrUdÿnYoÿsazÿp\sÿkUiÿfPaÿeN`ÿmYoÿmVjÿkQaÿlO]ÿmQ^ÿiN[ÿYANÿP9DÿQ9CÿR:DÿRHpÿ=CiÿFLuÿTY‹ÿqs²ÿxv²ÿskœÿrh•ÿul™ÿrq§ÿej ÿSY‰ÿHMyÿKQ|ÿGLvÿDJrÿEKsÿEJrÿCHnÿFKrÿRWƒÿ^b•ÿfj ÿop¨ÿrl›ÿrfŒÿreˆÿse†ÿt`zÿyp ÿuoŸÿpeŒÿrg�ÿpe�ÿtnŸÿwq¢ÿsk”ÿma…ÿpc…ÿseƒÿqcÿl\uÿhWqÿjc‹ÿke�ÿni–ÿpi•ÿmcŠÿnf�ÿsm�ÿpk›ÿib‹ÿh]‚ÿmg”ÿpm�ÿoi—ÿj`‰ÿcW~ÿbVyÿeWwÿhYwÿj\|ÿl_ƒÿneŠÿri”ÿob‡ÿlZsÿn\tÿn\tÿp[pÿlVgÿlUeÿs\lÿr\mÿq]tÿteˆÿuh�ÿr`ÿoZnÿnVhÿjRdÿiUnÿn`�ÿn[tÿmXkÿmXkÿmYmÿgSeÿH8Fÿ6(3ÿ2%.ÿ5'1ÿ7(2ÿ- *ÿ,/ÿ).ÿ%&ÿ(&ÿ5)4ÿ:,8ÿ4'1ÿ)$ÿ#ÿ$ÿ4&+ÿP=EÿgSeÿsbÿxg†ÿoXnÿiMZÿhKVÿgJSÿeGPÿgIRÿhKUÿlP[ÿpUcÿpWhÿnUfÿqYkÿwayÿwe‚ÿiTkÿePdÿjVjÿq]rÿuavÿxdzÿwbxÿt^tÿpYkÿfO[ÿWAJÿ:*1ÿ0#,ÿ8+6ÿ8*5ÿ/#+ÿ("ÿ( ÿ,#ÿ/!&ÿ,$ÿ( ÿ7'.ÿ@/7ÿ>.7ÿQ=IÿdKXÿgLWÿgKUÿnR^ÿpUaÿnR]ÿmQ[ÿpU`ÿrXdÿlQ\ÿnR_ÿoT_ÿlPZÿgKSÿfJQÿgKSÿkP[ÿmR_ÿjOZÿfNXÿfNWÿfNWÿfOZÿhP_ÿfOaÿcJYÿ`GRÿ^DOÿ\COÿaHUÿ^GUÿXAPÿU>JÿV>GÿX@JÿW@Jÿ]GSÿ]IUÿU>HÿZBMÿZCNÿ[DPÿ^HWÿ`LZÿXDNÿ_HQÿ_GNÿ\BHÿ]CKÿ\CLÿ`EOÿhLXÿmR`ÿkR_ÿbM\ÿYDSÿV@MÿU>JÿT=IÿYETÿWBRÿXAOÿ_FRÿgLYÿiN\ÿU=HÿF09ÿE/8ÿE19ÿI6AÿK9DÿJ8CÿM9CÿU>HÿT=HÿJ5@ÿD2<ÿA0;ÿ7*5ÿ-$.ÿ)!,ÿ-#.ÿ1&1ÿ4*5ÿ?2>ÿO?LÿSBOÿP=JÿN8EÿN9FÿL9FÿJ8GÿH8IÿH8Jÿ$)0ÿ!&,ÿ %,ÿ %-ÿ %-ÿ!'1ÿ&/=ÿ&.;ÿ$(2ÿ(*5ÿ79PÿYX‚ÿd[ƒÿbRmÿbPgÿ`SmÿZVxÿIKkÿ26Jÿ'(2ÿ)*4ÿ&'0ÿ%&0ÿ')4ÿ)*6ÿ&&/ÿ''1ÿ34Fÿ?A\ÿJKkÿ]VzÿgZxÿgVoÿfUmÿjYsÿfRiÿfZ}ÿaTtÿ]MbÿbRmÿZJcÿ]RuÿbXzÿaSoÿ\K`ÿ^Lcÿ^Lbÿ\K^ÿYFWÿVCTÿYI^ÿ[JaÿZKeÿXJcÿWFYÿXH_ÿ\OlÿYMhÿSDYÿQ@RÿTHcÿZPnÿ\NiÿYF[ÿT@SÿS?PÿT@QÿWCTÿ\GYÿ`K^ÿ^L_ÿeSkÿeQfÿcL\ÿdN^ÿ]IYÿ]K[ÿ[I[ÿ[IZÿbN]ÿdP`ÿfSeÿhUkÿiTkÿhReÿhRdÿgQcÿcM`ÿaL`ÿcPeÿeQgÿfQdÿhRbÿcO_ÿTBSÿ<-9ÿ1$-ÿ3%.ÿ7(2ÿ7(2ÿ- *ÿ,.ÿ-.ÿ2$1ÿ;-:ÿ:,8ÿ4'2ÿ(%ÿÿÿ2&-ÿRAMÿdO]ÿlVfÿpZlÿqZlÿlTdÿhP_ÿfO[ÿdLVÿdHRÿeITÿgLXÿhN[ÿhO]ÿhO\ÿiN]ÿkQ_ÿjQ]ÿcIRÿX>DÿS9<ÿZAFÿfNWÿnVcÿmWfÿiVhÿgRbÿkSbÿl[pÿ^]yÿKKbÿ72@ÿ1$-ÿ9+6ÿ<.:ÿ3&.ÿ+$ÿ+"ÿ-$ÿ- &ÿ)"ÿ)"ÿ. &ÿ7(0ÿD3@ÿ_HWÿdJVÿ`FOÿfLVÿhMXÿgLWÿfKUÿhNXÿlR^ÿgN[ÿiO\ÿjO\ÿgLWÿaGPÿ^ELÿ[CJÿbJSÿgOZÿdJUÿbKVÿcMYÿcO[ÿbMYÿ^HTÿ]GVÿZCQÿWANÿWAOÿXCPÿZCOÿYDRÿU@OÿQ;GÿP7@ÿM5=ÿQHÿJ7Cÿ9+8ÿ2(4ÿ0)5ÿ(%3ÿ$!-ÿ% +ÿ%(ÿ#&ÿ#&ÿ& *ÿ7.9ÿ;2>ÿ9.9ÿ9)3ÿ9(1ÿ?-7ÿB0<ÿ=-9ÿ7(3ÿ$)2ÿ!$,ÿ !(ÿ !)ÿ!"+ÿ!%/ÿ"(2ÿ$)4ÿ$(4ÿ#&0ÿ$&/ÿ//9ÿ?4@ÿH7DÿE7Eÿ83Bÿ..;ÿ()3ÿ%%+ÿ$!(ÿ#!'ÿ#!(ÿ##+ÿ%'1ÿ()5ÿ&%.ÿ%"*ÿ%#*ÿ%$,ÿ,(0ÿE6AÿTANÿUAPÿT@RÿYEWÿQNÿXBQÿO8DÿXCNÿYDQÿS@NÿQ?NÿF6Dÿ@2?ÿ>3@ÿ?5BÿC6CÿL=LÿYGXÿ^K]ÿ^K]ÿ_L^ÿ`M_ÿ_L`ÿ_L_ÿ_L]ÿ_K]ÿ`L^ÿaK[ÿcM\ÿ[HXÿC3Cÿ3&0ÿ+'ÿ2%.ÿ8)4ÿ4&0ÿ0",ÿ. *ÿ/!,ÿ9*7ÿC3Bÿ8*5ÿ(#ÿÿÿ-!)ÿKHÿQFÿ]ENÿdKWÿ_IUÿ\L\ÿ]L[ÿaL[ÿaUkÿX_~ÿTTnÿFGÿU@LÿYGTÿZKXÿVGTÿQAMÿTEUÿP?PÿM=NÿQAQÿUDSÿVDQÿZIZÿYIYÿTAPÿP:FÿK5@ÿSBOÿWFVÿTCRÿR?LÿU@MÿVCSÿI;Iÿ0*3ÿ!!'ÿ!!'ÿ,*3ÿ,*3ÿ,)2ÿ90;ÿE5AÿM9CÿP:CÿPJÿO?NÿH8HÿC3AÿD2>ÿG3?ÿC1:ÿB.8ÿG2;ÿL7@ÿO:DÿS?LÿP=IÿK8CÿF2;ÿC.5ÿD3>ÿG7CÿH8DÿG8CÿC6Aÿ7/;ÿ+&4ÿ#"2ÿ!$3ÿ$3ÿ "0ÿ"!,ÿ# )ÿ"%ÿ #ÿ $ÿ"'ÿ! 'ÿ% (ÿ.$+ÿ2%,ÿD3>ÿG6CÿA0<ÿ;+6ÿ!%/ÿ #*ÿ 'ÿ &ÿ&ÿ!)ÿ!$,ÿ"&.ÿ"(0ÿ#(2ÿ#%-ÿ*)3ÿ81<ÿ<1=ÿ/(2ÿ)'/ÿ&&.ÿ$$+ÿ$"'ÿ# $ÿ# %ÿ#"'ÿ##)ÿ#$+ÿ%$-ÿ('0ÿ&%-ÿ%$*ÿ%$*ÿ+(0ÿ@4@ÿF6?ÿJ5@ÿL7EÿM:GÿO:FÿP:FÿJ6@ÿA/8ÿ=,5ÿ@/9ÿC0;ÿK7CÿONÿOFÿU;BÿX?GÿZBJÿZBJÿZBKÿ[BLÿW>GÿRJÿTALÿUANÿJ9Dÿ:-4ÿ1'+ÿ+"&ÿ(#ÿ*"%ÿ.%)ÿ2'-ÿ<09ÿI=HÿI?Kÿ=7Aÿ0,5ÿ5.;ÿ2+8ÿ82>ÿB;HÿG>LÿI?MÿMCTÿOEUÿNCRÿL@OÿI;JÿL?OÿMBSÿMARÿO@PÿSBRÿWFUÿI=Iÿ1,4ÿ#"'ÿ%ÿ$ÿ$ÿ"#)ÿ+*2ÿ3-5ÿB3:ÿJ8@ÿLMÿ>2Aÿ7-:ÿ?2>ÿH6CÿG8DÿH8EÿH6BÿG4?ÿF5AÿJ:IÿN>NÿN?NÿJ9EÿD/5ÿC19ÿF5=ÿF6@ÿ>3<ÿ-+4ÿ%(3ÿ"%5ÿ $5ÿ"2ÿ!/ÿ!.ÿ+ÿ(ÿ$ÿ ÿ!ÿ !ÿ "ÿ#%ÿ*#*ÿ2(1ÿA5DÿD4CÿB0<ÿC3@ÿ#*ÿ!%,ÿ!#*ÿ 'ÿ 'ÿ&ÿ!(ÿ $,ÿ!&.ÿ"&.ÿ$%.ÿ('0ÿ1,7ÿ3+6ÿ'")ÿ%"'ÿ$!&ÿ#%ÿ""ÿ""ÿ$!%ÿ%$*ÿ%#*ÿ#!'ÿ$ 'ÿ%#*ÿ%#)ÿ#!&ÿ#!'ÿ-(2ÿ@5CÿI:GÿMÿH=OÿSBPÿT?LÿO;HÿF6Aÿ>0:ÿE6AÿP>KÿS@NÿP>KÿM;HÿP=MÿO>NÿN>LÿM6Dÿ4-9ÿ&"+ÿ $ÿ "ÿÿÿÿ "ÿ'!*ÿ9-9ÿN>MÿXDTÿT>JÿT>IÿT@MÿTBQÿTANÿRIÿM:Eÿ9-7ÿ+ )ÿ9,8ÿ3'2ÿ!ÿ ÿ&ÿ+$ÿ, 'ÿ+'ÿ3%-ÿI8DÿA0<ÿ=/;ÿ@5Aÿ<3?ÿ61>ÿ52>ÿ40<ÿ4/:ÿ81<ÿ?6Cÿ>5Aÿ4-7ÿ*%-ÿ'$+ÿ$!'ÿ%!(ÿ)$*ÿ+&+ÿ+%*ÿ.'-ÿ4,3ÿ4-4ÿ.)0ÿ'"(ÿ$ 'ÿ"$ÿ# 'ÿ'$-ÿ*'1ÿ.+4ÿ30<ÿ54@ÿ55Bÿ36Bÿ21>ÿ31>ÿ1/;ÿ50<ÿA7DÿJ:GÿRBOÿD9Dÿ)&-ÿ %ÿ!ÿÿÿÿ#ÿ" #ÿ6,2ÿ@4=ÿF:FÿH>Mÿ;2@ÿ.'4ÿ'!+ÿ.%/ÿ;.:ÿ>2@ÿF9HÿJ;IÿK9GÿI9GÿHÿE5?ÿ>2=ÿ5.7ÿ,)0ÿ$%.ÿ!%2ÿ$3ÿ!0ÿ,ÿ+ÿ+ÿ(ÿ&ÿ$ÿÿÿÿ ÿ "ÿ% &ÿ.&0ÿ=0@ÿC4EÿD5DÿD8Fÿ")6ÿ%,:ÿ%.=ÿ%/=ÿ$,:ÿ $.ÿ 'ÿ #+ÿ"&/ÿ!$.ÿ#%.ÿ((1ÿ/*5ÿ0(2ÿ& &ÿ%%ÿ#"ÿ"!ÿ""ÿ"!ÿ#$ÿ" %ÿ!$ÿ"$ÿ#%ÿ#!(ÿ$")ÿ"!'ÿ#!'ÿ,&1ÿ90>ÿD6EÿH8HÿH8GÿF6DÿH7EÿN;KÿH9Gÿ80:ÿ+(/ÿ,*2ÿ,*2ÿ+(0ÿ*'.ÿ($-ÿ%!)ÿ$&ÿ#'ÿ)%0ÿ4/<ÿ>4?ÿD5?ÿB1;ÿ:+4ÿ6)1ÿ:-7ÿD5BÿI9GÿI8GÿG7FÿH7HÿK:JÿN=KÿM=KÿE9Fÿ95Bÿ43Aÿ33@ÿ32?ÿ21=ÿ0/<ÿ+*7ÿ%#.ÿ $ÿÿÿÿÿÿÿ  ÿ%&ÿ7,8ÿF8FÿL:IÿM8DÿP?LÿREWÿPEZÿH?TÿD:LÿE:Mÿ?3Bÿ6(2ÿ5%0ÿ2#,ÿ2%.ÿ2%.ÿ2$,ÿ0#*ÿ+%ÿ0$-ÿ7+6ÿ4(3ÿ&"ÿ$ÿÿ#ÿ3*0ÿ@6?ÿC7BÿP?OÿVBRÿS?KÿM:CÿU?Jÿ^FTÿ\FTÿS@QÿO>QÿP@RÿQARÿQAQÿSBRÿWEUÿVDTÿRAPÿM9GÿI3@ÿH3?ÿG1<ÿG2=ÿH3>ÿI4?ÿL6DÿTARÿUDUÿSCSÿQBQÿQCSÿTFWÿVGYÿTDWÿK=Oÿ90<ÿ$#ÿ/$-ÿ5*4ÿ0%,ÿ%ÿ&ÿ*#ÿ/")ÿ/#*ÿ-'ÿ8)3ÿ3'/ÿ4*3ÿ5,7ÿ,'/ÿ(%.ÿ'%.ÿ(&/ÿ*'0ÿ-)3ÿ0,8ÿ.+7ÿ'$-ÿ!#ÿ!#ÿ!$ÿ"(ÿ%!,ÿ&#.ÿ'$-ÿ)$,ÿ*$*ÿ)$*ÿ&"(ÿ#%ÿ !ÿÿÿÿ"ÿ! 'ÿ$#,ÿ%%.ÿ#%.ÿ!$,ÿ!#*ÿ"#*ÿ!"(ÿ%#)ÿ0)0ÿ=/6ÿA4<ÿ5,3ÿ! $ÿ ÿÿÿÿÿÿÿ'#(ÿ-'.ÿ3,5ÿ81=ÿ0)4ÿ(",ÿ#&ÿ$%ÿ*"+ÿ-%/ÿ4,8ÿ=2>ÿB5AÿB6CÿA6EÿH>PÿNCWÿQDXÿSDUÿPDTÿB9Gÿ/*4ÿ! 'ÿ !+ÿ$2ÿ#2ÿ.ÿ*ÿ)ÿ(ÿ%ÿ$ÿ$ÿ#ÿ ÿÿÿÿ!"ÿ$'ÿ,#/ÿ3(7ÿ9.=ÿ>4Cÿ")5ÿ#+8ÿ$.<ÿ%/=ÿ$,9ÿ!'1ÿ$-ÿ!&1ÿ"'3ÿ!%/ÿ"&/ÿ%(2ÿ+)3ÿ+%.ÿ%#ÿ#"ÿ"ÿ!ÿ" ÿ!ÿ! ÿ  ÿ !ÿ!"ÿ# %ÿ##*ÿ$$,ÿ""(ÿ" &ÿ)$-ÿ1*6ÿ>3Aÿ>2?ÿ8,8ÿ9,9ÿB4BÿF7Fÿ?4Bÿ3-7ÿ*&,ÿ(%+ÿ&$(ÿ%#'ÿ%"&ÿ%"&ÿ&!'ÿ$$ÿ"#ÿ#&ÿ'#+ÿ-(0ÿ;/8ÿ@/9ÿ=-7ÿ9-8ÿ5-8ÿ7.;ÿ9/<ÿ<0>ÿ?1@ÿ@1BÿC3BÿH7EÿH9FÿA6Aÿ83=ÿ/.7ÿ,+4ÿ,+4ÿ*)5ÿ&'3ÿ#".ÿ!(ÿ"ÿ !ÿ  ÿ  ÿÿÿÿÿÿ"%ÿ/)3ÿ;2?ÿ?4AÿC;HÿD?PÿA>Rÿ99Lÿ85Gÿ81Bÿ5+8ÿ2$,ÿ/!*ÿ-(ÿ0#,ÿ0$,ÿ, 'ÿ& ÿ&!ÿ4)3ÿ4)3ÿ* &ÿ"ÿÿÿ,&,ÿ929ÿ917ÿ7,2ÿ?0;ÿB1;ÿ>,3ÿ6(-ÿ<-5ÿD5BÿC7Hÿ@7KÿC;OÿG=OÿH=LÿGMÿSEUÿWFXÿTCSÿN;JÿK6DÿL9EÿL9EÿL8DÿJ7BÿJ6BÿM:HÿVDWÿVFYÿOBSÿH>LÿH>NÿKASÿMDUÿI@Qÿ?6Dÿ3*2ÿ'$ÿ$!ÿ1&/ÿ4(2ÿ$ÿ"ÿ)"ÿ-"(ÿ-!'ÿ)$ÿ*%ÿ*!)ÿ,%-ÿ-%/ÿ&"+ÿ"(ÿ"'ÿ$ )ÿ'"+ÿ+%-ÿ+&/ÿ)%.ÿ#&ÿÿÿ!ÿ %ÿ!)ÿ",ÿ$!,ÿ&",ÿ&"+ÿ$ 'ÿ!#ÿ !ÿÿÿÿÿ ÿ"ÿ#ÿ#ÿ ÿÿÿÿ "ÿ! #ÿ&#'ÿ4-3ÿ2+1ÿ($(ÿÿÿÿÿÿ ÿ!ÿ!ÿ!ÿ!ÿ#%ÿ)#+ÿ'!*ÿ$&ÿ!"ÿ !ÿ !ÿ "ÿ$'ÿ,&/ÿ2-8ÿ60>ÿ82AÿA9JÿI?QÿNCUÿPEWÿMDUÿ@:Iÿ.,7ÿ )ÿ!,ÿ#1ÿ .ÿ*ÿ(ÿ'ÿ&ÿ%ÿ$ÿ$ÿ$ÿ ÿÿÿÿ ÿ"ÿ#ÿ$(ÿ+#/ÿ1(5ÿ$,ÿ#+ÿ%-ÿ %.ÿ#+ÿ#+ÿ$.ÿ %1ÿ %0ÿ#,ÿ #,ÿ!%.ÿ#&/ÿ$#+ÿ##ÿ!ÿ!ÿ!ÿ!ÿ ÿÿ ÿ ÿ !ÿ! $ÿ##)ÿ$%,ÿ"#*ÿ"!(ÿ&#+ÿ*&/ÿ6/9ÿ2*4ÿ((ÿ+"+ÿ6+7ÿ5.9ÿ0+5ÿ+(/ÿ(%+ÿ&#'ÿ# #ÿ!!ÿ"!ÿ$ #ÿ'"&ÿ& $ÿ$"ÿ#"ÿ%!&ÿ)$*ÿ:0:ÿB5Bÿ?4Cÿ93Aÿ30>ÿ/,9ÿ-)6ÿ0*5ÿ6,7ÿ8-;ÿ7-:ÿ:/:ÿ=0:ÿ:/8ÿ5-6ÿ/)/ÿ*&,ÿ(%-ÿ&$/ÿ$".ÿ# +ÿ"&ÿ!ÿ!ÿ!#ÿ!#ÿ ÿÿÿÿÿÿ"ÿ'%-ÿ11<ÿ34@ÿ23Aÿ.0=ÿ,,7ÿ2.;ÿ2)6ÿ1%.ÿ-"'ÿ)#ÿ+&ÿ*&ÿ*%ÿ)"ÿ&ÿ($ÿ3(2ÿ.$-ÿ"ÿ!ÿÿ ÿ1,4ÿ:4=ÿ5.4ÿ2(-ÿ4,5ÿ4,5ÿ0'-ÿ.%)ÿ/'-ÿ2.:ÿ52Bÿ63Dÿ84Dÿ92?ÿ80:ÿ7.5ÿ>3;ÿO?Lÿ^IWÿ\FTÿS>JÿO;HÿVCPÿXETÿYERÿUAMÿPÿ85Fÿ>9Jÿ@:Jÿ=9Gÿ:7Dÿ32?ÿ))4ÿ !+ÿ!-ÿ!/ÿ+ÿ(ÿ&ÿ%ÿ%ÿ$ÿ#ÿ"ÿ ÿÿÿÿÿÿ ÿ!ÿ"ÿ!%ÿ%(ÿ %ÿ!ÿ!ÿ!ÿÿ!ÿ#ÿ%ÿ$ÿ!ÿ#ÿ%ÿ!(ÿ ")ÿ# &ÿ!ÿ!ÿ"ÿ!ÿ ÿÿÿÿÿ ÿ "ÿ"!(ÿ""+ÿ"!+ÿ$"+ÿ#!(ÿ'$)ÿ'!'ÿ$#ÿ&'ÿ-%3ÿ+(5ÿ*'0ÿ($*ÿ$!%ÿ""ÿ! ÿ ÿ ÿ# ÿ$!ÿ&!#ÿ% #ÿ$#ÿ%!'ÿ'%-ÿ2/<ÿ63Dÿ22Cÿ+/>ÿ*,;ÿ)(5ÿ)&1ÿ)&/ÿ+%,ÿ,&,ÿ+&-ÿ,'/ÿ.(1ÿ-'0ÿ-&.ÿ,&,ÿ)#*ÿ$ (ÿ")ÿ 'ÿ $ÿ "ÿÿ ÿ#ÿ #ÿ!ÿÿÿÿÿÿÿ!!ÿ,-6ÿ//;ÿ--:ÿ*)4ÿ'&/ÿ,(2ÿ-&0ÿ.%,ÿ+ %ÿ%ÿ,'ÿ'!ÿ$ÿ)!ÿ/!)ÿ4'0ÿ2&/ÿ)%ÿÿÿÿ&!'ÿ/+2ÿ0,3ÿ-&+ÿ+%)ÿ/+2ÿ1/7ÿ008ÿ0.6ÿ0-5ÿ0/:ÿ1/;ÿ1,6ÿ/(.ÿ/(-ÿ1)/ÿ3*/ÿ?2;ÿVCNÿiQ[ÿeMVÿXBKÿR?HÿYFRÿ^JWÿaNWÿ[HQÿS?HÿP=GÿRALÿTBRÿIÿ13>ÿ.09ÿ.-6ÿ%!&ÿ%!ÿ0$,ÿ6(2ÿ-"(ÿ&!ÿ% ÿ($ÿ) &ÿ%#ÿ "ÿ"ÿ!ÿÿÿÿÿ ÿ!$ÿ%%ÿ"!ÿÿÿÿÿÿÿ ÿÿ ÿ"ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ!ÿ ÿÿÿÿÿÿÿÿÿÿÿÿ!ÿ !ÿÿÿÿÿÿ!ÿ$ÿ *ÿ$%0ÿ&'3ÿ),;ÿ*/?ÿ(-=ÿ%)7ÿ%'1ÿ#$.ÿ )ÿ'ÿ*ÿ -ÿ*ÿ(ÿ&ÿ%ÿ%ÿ#ÿ!ÿÿÿÿÿÿÿÿÿÿ!ÿ!$ÿ#&ÿ ÿÿÿÿÿÿ!ÿ$ÿ#ÿ ÿÿÿÿ%ÿ "'ÿ ÿ ÿ!ÿ!ÿ!ÿ ÿÿ!ÿ  ÿÿ !ÿ!'ÿ (ÿ&ÿ!'ÿ &ÿ#!(ÿ# &ÿ#&ÿ%"/ÿ)*>ÿ'*<ÿ$$0ÿ#$ÿ! ÿ ÿ!ÿ ÿÿÿ!ÿ# ÿ% #ÿ&"'ÿ'%/ÿ&*8ÿ&*9ÿ%(7ÿ$'5ÿ#'4ÿ%'5ÿ%$0ÿ&#-ÿ'$-ÿ("*ÿ(!)ÿ)#+ÿ)&.ÿ)&0ÿ*%.ÿ*%.ÿ+%.ÿ($,ÿ#!)ÿ 'ÿ$ÿ!$ÿ"#ÿ !ÿ!ÿ"ÿ!ÿÿÿÿÿÿÿÿ !ÿ((1ÿ()4ÿ%%1ÿ"!,ÿ! )ÿ!'ÿ"&ÿ$#ÿ'"ÿ)#ÿ, &ÿ(!ÿ%ÿ-'ÿ:+6ÿ?0>ÿ0$-ÿ!ÿÿÿÿ&!&ÿ,'/ÿ+'/ÿ*%,ÿ+'-ÿ-+3ÿ-.6ÿ-.7ÿ,-7ÿ,+6ÿ+(2ÿ*%,ÿ*#'ÿ,#'ÿ.%*ÿ2'.ÿ9-5ÿH:GÿWGWÿUDOÿM=DÿJ=CÿK@GÿK?IÿNALÿOCKÿNBIÿKAGÿH>CÿF:?ÿVGUÿPCRÿ<3>ÿ1-7ÿ,*3ÿ+*2ÿ**3ÿ)+4ÿ)+2ÿ&%)ÿ$ "ÿ!ÿ*'ÿ8+5ÿ2&/ÿ)$ÿ$ÿ#ÿ!ÿ!ÿÿÿÿÿÿÿÿÿÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"ÿÿÿÿÿÿ!ÿ&ÿ )ÿ!*ÿ#,ÿ!'4ÿ&4ÿ$1ÿ$2ÿ $.ÿ!)ÿ&ÿ(ÿ*ÿ*ÿ(ÿ&ÿ&ÿ(ÿ(ÿ'ÿ%ÿ!ÿÿÿÿÿÿÿÿ ÿ"#ÿ#%ÿ"$ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ!ÿ $ÿ!ÿ ÿ!ÿ!ÿÿÿ! %ÿ##*ÿ"!)ÿ "ÿ#ÿ!)ÿ!)ÿ &ÿ 'ÿ"!.ÿ"$1ÿ!"/ÿ!"-ÿ#$3ÿ$(9ÿ#%5ÿ"".ÿ"&ÿ ÿÿÿÿÿÿÿ"!ÿ##ÿ$"*ÿ&(4ÿ"&2ÿ#%1ÿ#$/ÿ "-ÿ "-ÿ$%1ÿ%#-ÿ%!*ÿ&"*ÿ'"+ÿ'"*ÿ'%.ÿ((2ÿ((4ÿ(&1ÿ(&0ÿ'%0ÿ$#-ÿ! (ÿ &ÿ!%ÿ!"ÿÿÿÿÿÿÿ  ÿ" "ÿÿÿÿÿÿ""*ÿ"#-ÿ )ÿ%ÿ"ÿÿÿÿ"ÿ'"ÿ&!ÿ& ÿ&ÿ.!(ÿ:,7ÿ:,8ÿ*&ÿÿÿÿÿ($+ÿ+)2ÿ*(3ÿ*(2ÿ*'1ÿ*(1ÿ**2ÿ))1ÿ'&.ÿ'#+ÿ& &ÿ&#ÿ' "ÿ,"&ÿ5)1ÿ?1>ÿH;JÿL?NÿG:EÿA8=ÿ?:?ÿ@=BÿB?EÿB>GÿB?GÿB?FÿB?EÿB@EÿA>Cÿ<48ÿPCRÿQCUÿ@6Dÿ/*2ÿ&"&ÿ""ÿ"#ÿ$#)ÿ%%,ÿ$#'ÿ%!$ÿ ÿ!ÿ+!'ÿ'#ÿ#ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ!ÿ'ÿ%ÿ ÿÿÿ ÿ"ÿ#ÿ"ÿ!ÿ#ÿ +ÿ!,ÿ*ÿ +ÿ!*ÿ$ÿ!ÿ#ÿ&ÿ)ÿ(ÿ&ÿ'ÿ +ÿ!+ÿ!*ÿ&ÿ ÿÿÿÿÿÿÿÿ ÿ!"ÿ!"ÿ !ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ!ÿÿ ÿ ÿ ÿ!(ÿ"!.ÿ$'5ÿ%)7ÿ"$2ÿ!!/ÿ! -ÿ!,ÿ" -ÿ##1ÿ#%5ÿ!%5ÿ $1ÿ #0ÿ!%2ÿ %2ÿ -ÿ*ÿ 'ÿÿÿÿÿÿÿÿ  ÿ!%ÿ"$,ÿ"%0ÿ (ÿ (ÿ )ÿ(ÿ (ÿ##,ÿ%#+ÿ%")ÿ&"*ÿ'$-ÿ'%.ÿ&&0ÿ%'2ÿ%&1ÿ$$/ÿ$$/ÿ#$.ÿ !+ÿ'ÿ $ÿ #ÿÿÿÿÿÿÿÿ! ÿ!ÿÿÿÿÿÿ#ÿ&ÿ#ÿ ÿÿÿÿÿÿ%"ÿ%"ÿ$ÿ$ÿ- 'ÿ7)2ÿ1$-ÿ$ÿÿÿÿ ÿ'#)ÿ&$+ÿ#!)ÿ#!(ÿ"&ÿ!$ÿ"%ÿ# %ÿ"$ÿ""ÿ# ÿ'"ÿ*"$ÿ0%(ÿ>1:ÿK=NÿNARÿH=Iÿ>7<ÿ;8<ÿ=Cÿ@>Eÿ@=Eÿ@=Dÿ@>DÿA>EÿAÿ");ÿ"#6ÿ""3ÿ"!1ÿ"#3ÿ$'8ÿ"'7ÿ %3ÿ#0ÿ#/ÿ $1ÿ #/ÿ+ÿ(ÿ'ÿ"ÿÿÿÿÿÿÿÿ &ÿ!$+ÿ!'ÿ"ÿ ÿ ÿ!ÿ"ÿ! &ÿ#!'ÿ%"'ÿ&#)ÿ&%-ÿ%&0ÿ$%.ÿ##,ÿ"!)ÿ (ÿ !*ÿ )ÿ'ÿ%ÿ#ÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿ"ÿ"ÿÿÿÿÿÿÿ$!ÿ&"ÿ!ÿ%ÿ/"*ÿ4&/ÿ)$ÿ ÿÿÿÿ!ÿ%#ÿ ÿÿÿÿÿÿÿ! ÿ#"ÿ'$ÿ1'-ÿ:/5ÿ>18ÿB5>ÿG;IÿE:Gÿ@8>ÿ@;?ÿ?@ÿ>:>ÿ<7:ÿ0(+ÿ>5<ÿMAOÿQBSÿE8Gÿ+$,ÿÿ0)1ÿ6-7ÿ" ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ%ÿ !'ÿ!&ÿ"(ÿ #*ÿ #+ÿ#)ÿ"&ÿ#ÿ"ÿ#ÿ!ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿ (ÿ!)ÿ"+ÿ"*ÿ#ÿÿÿÿÿÿ"ÿ!ÿÿ#ÿ "/ÿ$6ÿ%9ÿ%8ÿ%8ÿ'<ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ"ÿ ÿ !ÿ!"ÿ  ÿÿÿ%ÿ!-ÿ$3ÿ $3ÿ*ÿ)ÿ*ÿ,ÿ !.ÿ!!/ÿ -ÿ!.ÿ!"0ÿ##2ÿ$$5ÿ#"5ÿ#"3ÿ""1ÿ +ÿ (ÿ$ÿ!ÿÿÿÿÿ!ÿ #ÿÿÿÿÿÿÿÿ ÿ" ÿ#!&ÿ%&/ÿ$'2ÿ!#-ÿ )ÿ!)ÿ!+ÿ"/ÿ%5ÿ '9ÿ!'9ÿ!%6ÿ!$1ÿ *ÿ"ÿÿ ÿ ÿ!"%ÿ##'ÿ#"%ÿ!"ÿ!"ÿ  ÿÿÿÿ #ÿ#ÿ"ÿ!ÿÿÿÿÿÿ"ÿÿ ÿ$ÿ*%ÿ-!)ÿ&!ÿÿ$ÿ% ÿÿÿ!ÿÿÿ"!ÿ*#,ÿ ÿÿ ÿ+!*ÿ4)4ÿ?2AÿG:KÿF:Hÿ906ÿ-((ÿ-,+ÿ233ÿ588ÿ598ÿ5::ÿ7;;ÿ9=?ÿ@ÿ8;<ÿ59:ÿ255ÿ(%%ÿ415ÿDÿ@2Cÿ=1?ÿ4,2ÿ*$%ÿ+*)ÿ033ÿ599ÿ5;9ÿ297ÿ399ÿ8<>ÿ>AFÿ?BHÿ9>Cÿ7=@ÿ7>?ÿ7=>ÿ7;=ÿ257ÿ&$#ÿ..0ÿ:4<ÿB5DÿA5Fÿ1(3ÿ%&ÿ5-9ÿA7Hÿ<2@ÿ-%.ÿ#"ÿÿÿÿÿÿÿ ÿ ÿ ÿÿÿ-%(ÿF:AÿI;Cÿ1',ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ $ÿ $ÿ!ÿÿÿÿÿÿÿÿÿ !ÿ "ÿ# (ÿ!'ÿ! )ÿ"#-ÿ #+ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ#ÿ"'ÿ#)ÿ#*ÿ#ÿÿÿÿÿÿÿÿÿ ÿÿÿ&ÿ#/ÿ$2ÿ"1ÿ!1ÿ /ÿ+ÿ(ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ $ÿ "ÿ""%ÿ##'ÿ"!&ÿ $ÿ""'ÿ"$*ÿ!#*ÿ#)ÿ $*ÿ!#(ÿ "'ÿ !'ÿ 'ÿ'ÿ 'ÿ (ÿ!"*ÿ#$.ÿ$'1ÿ$'2ÿ"%1ÿ"%0ÿ"$-ÿ#*ÿ $*ÿ "(ÿ#ÿÿ ÿ %ÿ #(ÿ %*ÿ $*ÿ!&ÿ!%ÿ!$ÿ $ÿ "ÿÿÿ  ÿ"!#ÿ!"%ÿ "%ÿ"ÿ#*ÿ!(8ÿ#.Dÿ"1Kÿ!/Jÿ .Iÿ-Fÿ+Cÿ*@ÿ)@ÿ )?ÿ%5ÿ 'ÿ"ÿ ÿÿÿÿÿÿÿÿÿ!ÿÿÿÿÿÿÿÿÿÿ"ÿÿ(#ÿ+!)ÿ* (ÿ*'ÿ*$,ÿ!ÿ) 'ÿ1'0ÿ-"'ÿ/#+ÿ)#ÿ!ÿ% ÿ1&0ÿ6+7ÿ2'/ÿ-$)ÿ2'.ÿ;/9ÿ@2Aÿ=/=ÿ3(0ÿ)""ÿ)##ÿ.--ÿ134ÿ376ÿ376ÿ254ÿ568ÿB>DÿKBLÿHAKÿ<;Aÿ38:ÿ489ÿ689ÿ668ÿ214ÿ'##ÿ.+-ÿ6.4ÿ8+4ÿ4'2ÿ0&.ÿ0&.ÿ9/;ÿA6Eÿ?4Cÿ0'3ÿ&&ÿ ÿÿÿÿÿÿÿÿ!ÿ.&-ÿA6@ÿSDOÿ_LXÿaMYÿXFRÿG9Eÿ7,7ÿ,$,ÿÿÿ!ÿ!'ÿ %ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿ &ÿ'ÿ!,ÿ!$0ÿ#,ÿ ÿÿÿÿÿÿÿÿÿÿÿ -ÿ$3ÿ".ÿ#ÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿ"ÿ!(ÿ"*ÿ!(ÿ$ÿÿ ÿ ÿÿÿÿ ÿÿÿÿ ÿ ÿ"ÿ,ÿ!.ÿ,ÿ+ÿ)ÿ%ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ !ÿ !$ÿ"#&ÿ""%ÿ !#ÿ "ÿ!#ÿ!#&ÿ"#&ÿ "%ÿ!#'ÿ"#)ÿ!#(ÿ!%ÿ !%ÿ!"(ÿ"$*ÿ#%+ÿ"%+ÿ!%,ÿ"%,ÿ"%+ÿ!%+ÿ#'-ÿ#&,ÿ!"'ÿ"ÿ "ÿ#$*ÿ#'-ÿ"',ÿ %*ÿ$(ÿ!%ÿ ÿÿÿÿÿÿÿ ÿÿÿ &ÿ &7ÿ!*Aÿ)?ÿ'<ÿ%:ÿ%8ÿ$5ÿ#4ÿ$6ÿ$6ÿ ,ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-%,ÿ6,7ÿ5)4ÿ,!)ÿ,+7ÿ!%ÿÿ"ÿ."(ÿ2'.ÿ-"(ÿ+$ÿ1$,ÿ9*5ÿ5'/ÿ4&-ÿ7).ÿ9-4ÿ<0;ÿA1?ÿ>0:ÿ:-4ÿ8,3ÿ;07ÿ?6=ÿ?9?ÿ@9@ÿ@8@ÿ>7?ÿC;BÿOALÿTBQÿQ@OÿG=IÿA;CÿA:Bÿ@7>ÿ?5<ÿ@7@ÿ<2:ÿ;18ÿ/;ÿA3?ÿ?2>ÿ8.:ÿ-$.ÿ$"ÿ!ÿ!ÿ ÿÿÿÿÿ ÿ1)2ÿ=2=ÿOBPÿ[KYÿ\HUÿ^IWÿ^KZÿTDSÿD7Eÿ7,8ÿ"ÿÿ#&ÿ&-ÿ")ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ!ÿ%ÿ,ÿ"/ÿ )ÿÿÿÿÿÿÿÿÿÿÿ#ÿ%:ÿ*Aÿ':ÿ(ÿÿÿÿÿÿÿ!"ÿ !#ÿ"ÿ ÿÿÿ ÿÿÿ$ÿ (ÿ&ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ*ÿ-ÿ)ÿ'ÿ%ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ "ÿ #ÿ "ÿ!ÿ!ÿ #ÿ !"ÿ !ÿ ÿ "ÿ!%ÿ"ÿ!ÿ"ÿ"ÿÿÿ #ÿ!$ÿ $ÿ"&ÿ #'ÿ#&ÿ #&ÿ!"&ÿ""(ÿ%'/ÿ$&-ÿ!#)ÿ!&ÿ $ÿ ÿÿÿÿÿÿÿÿÿÿÿ!)ÿ '9ÿ *Aÿ(@ÿ$8ÿ!1ÿ-ÿ,ÿ .ÿ 1ÿ!1ÿ'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ+%,ÿ8/9ÿ9-7ÿ-#.ÿ.2Cÿ&$/ÿ ÿ&ÿ1%*ÿ5(0ÿ/"*ÿ5%/ÿ>-7ÿ?.8ÿ;+4ÿ;+2ÿ<26ÿ=6:ÿ>1:ÿC3?ÿF6BÿJ9EÿMKÿRBPÿSDRÿTDSÿUFQÿWHOÿUDQÿUCRÿVCSÿUDSÿTDSÿUDTÿVEUÿP?MÿM=JÿSCTÿSDRÿL=JÿD5Aÿ>0:ÿ;-6ÿB2<ÿI8FÿI8Fÿ@1=ÿ2'.ÿ)!$ÿ#ÿ$ÿ("ÿ) &ÿ(#ÿ+ %ÿ$ÿÿ,"(ÿ:/:ÿ8-8ÿ6-8ÿ7.9ÿ7,8ÿ9-:ÿ5*6ÿ5*5ÿ5*6ÿ/&.ÿ ÿÿ#&ÿ',ÿ$ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ(ÿ +ÿ&ÿÿÿÿÿÿÿÿÿÿÿ'ÿ&;ÿ)@ÿ$7ÿ&ÿÿÿÿÿÿÿ #ÿ! %ÿ" &ÿ! &ÿ#ÿÿÿÿÿ%ÿ#ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$ÿ-ÿ-ÿ(ÿ$ÿ"ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿ #ÿ"ÿ!ÿ!ÿ ÿÿÿ!!ÿ !#ÿ #ÿ "ÿ "ÿ "ÿ!#ÿ! $ÿ!%ÿ! 'ÿ!&ÿ!%ÿ $ÿ "ÿÿÿÿÿÿÿÿÿÿÿÿ .ÿ %7ÿ%7ÿ#6ÿ!1ÿ*ÿ*ÿ .ÿ!/ÿ.ÿ,ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿ!ÿ!ÿ"ÿ ÿÿÿÿÿÿÿÿÿÿ.$)ÿ3(4ÿ,%>ÿ58Pÿ5.?ÿ5&2ÿ9+8ÿ>0;ÿ=/:ÿ;,7ÿ@/;ÿB0<ÿ:*1ÿ6&+ÿ8*-ÿ?FDÿEOMÿE9@ÿH7CÿL;HÿO>KÿP?MÿO@NÿOAOÿO@OÿM?LÿZOFÿibAÿO@DÿK:JÿN>MÿN?MÿN?MÿO@NÿPAOÿK:FÿF5AÿK;JÿO?MÿJ:HÿG7EÿI8EÿI9EÿG6BÿF5AÿF6CÿA2=ÿ1#*ÿ+!ÿ+"ÿ)%ÿ'*ÿ*"1ÿ5+9ÿ9-;ÿ3'4ÿ1%-ÿ8+2ÿ2'/ÿ-$-ÿ' (ÿ%'ÿ)!+ÿ(*ÿ"#ÿ"#ÿ$ &ÿ"!ÿÿÿ"'ÿ&,ÿ"&ÿ"$ÿ!"ÿ!"ÿ ÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿ$ÿ%ÿÿÿÿÿÿÿÿÿÿÿÿ,ÿ!/ÿ(ÿÿÿÿÿÿÿ  ÿ$ 'ÿ$ 'ÿ!$ÿ #ÿ !ÿÿÿÿ"ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿÿÿ"ÿ)ÿ)ÿ%ÿ!ÿÿÿÿÿÿÿÿÿÿÿ ÿ"ÿ$ÿ#ÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ!&ÿ&/ÿ)2ÿ(2ÿ'/ÿ $+ÿ#!'ÿ"ÿ ÿÿ ÿ!ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿ'ÿ,ÿ,ÿ/ÿ+ÿ!ÿ$ÿ*ÿ!+ÿ)ÿ$ÿÿÿÿÿÿÿ ÿ* %ÿ@3;ÿG7@ÿK9CÿM;EÿN=EÿO=FÿQ>IÿJÿD6BÿJ:GÿH8DÿK@=ÿSK7ÿ>14ÿ:,7ÿ=/;ÿÿ@/:ÿO=Lÿ^J\ÿ]HYÿP=Kÿ<-6ÿ@2<ÿH8Fÿ<-:ÿ4&.ÿ;-8ÿ70Eÿ+4Vÿ*=hÿ1@lÿ3@jÿ37Yÿ3,>ÿ2%,ÿ* (ÿ&(ÿ&)ÿ(!,ÿ)".ÿ&)ÿ$&ÿ"&ÿ!'ÿ$(ÿ!(-ÿ&,ÿ%,ÿ#*ÿ"ÿ ÿÿ ÿ ÿÿ&ÿ#ÿ ÿ!ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ'#ÿ%ÿÿÿÿ ÿ"#ÿ"ÿ$ÿ%!ÿ# ÿ" ÿÿÿÿÿÿÿÿÿÿ 'ÿ"(ÿ!#ÿÿ !ÿ% &ÿ*!(ÿ&"ÿÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ ÿ ÿ ÿÿÿÿ"ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿ ÿ$ÿ&ÿ'ÿ("ÿ*!%ÿ( $ÿ"ÿÿÿÿÿ ÿ!ÿ"ÿ"ÿÿÿ%#ÿ !&ÿ!'ÿ")ÿ#+ÿ&.ÿ&/ÿ&.ÿ&-ÿ!%-ÿ!"*ÿ!%ÿ !ÿÿÿÿÿÿÿÿÿÿÿÿ!ÿÿÿÿÿÿÿ!ÿ) %ÿ+#'ÿ( $ÿ*"&ÿ-$,ÿ-$-ÿ.$-ÿ2(2ÿ3(2ÿ/$*ÿ0%+ÿ.&-ÿ$ %ÿ$%ÿ ÿ"ÿ$ÿ ÿ!ÿ$ÿ8*,ÿ=/2ÿ/(.ÿ@6@ÿE8BÿI9CÿM;FÿP>HÿQ?KÿR@MÿI,8ÿ:3FÿG>QÿQ@NÿI5=ÿC2:ÿ@09ÿB2FÿRAYÿgReÿcObÿ`N^ÿP@Mÿ>.8ÿA08ÿA/8ÿB08ÿE1:ÿF1;ÿD1:ÿE3<ÿD5BÿB6DÿA5BÿI6@ÿWBKÿ^GQÿ_HQÿ[EMÿR?DÿE2:ÿA07ÿA19ÿ?09ÿ?/8ÿF5?ÿG6Aÿ=-7ÿ6&-ÿ=,3ÿA07ÿA/7ÿR>MÿaK]ÿaK\ÿWDRÿG5?ÿE3<ÿK8CÿF4Aÿ;+3ÿB0;ÿ:1Eÿ(3Sÿ$;cÿ%HÿNKÿF4>ÿI7@ÿK8CÿJ7AÿL9BÿN:EÿM9EÿN:FÿLJÿK7@ÿI4<ÿO;Fÿ@.6ÿ>*1ÿ4'2ÿ%$5ÿ ':ÿ '=ÿ$8ÿ*(<ÿ3+=ÿ/#.ÿ$#ÿ"#ÿ%$ÿ&#ÿ%!ÿ!ÿ# &ÿ!#)ÿ"(ÿ$+ÿ)1ÿ$+ÿ#ÿÿÿÿÿÿÿÿ% ÿ(ÿ)ÿ* ÿ,"#ÿ-&+ÿ)%,ÿ$(5ÿ#->ÿ%.>ÿ%)4ÿ')4ÿ&'/ÿ"%+ÿ!'/ÿ#%+ÿ$$*ÿ&$)ÿ'#'ÿ'!$ÿ( "ÿ"ÿ% /ÿ'"6ÿ(ÿ &ÿ$")ÿ*%.ÿ*&/ÿ !)ÿ"ÿÿÿ"ÿ#ÿ#ÿ"ÿ!ÿ #ÿ#,ÿ"-ÿ!*ÿ$ÿ"ÿ&ÿ +ÿ "/ÿ -ÿ(ÿ$ÿÿÿ ÿ ÿÿÿ ÿ ÿÿ ÿ ÿ ÿ ÿ ÿ + ÿ ÿ ÿ ÿÿÿÿÿÿÿ ÿ@.4ÿ;+3ÿ0#+ÿ#ÿÿÿÿÿÿÿ ÿ"ÿ"ÿ&$ÿ-#-ÿ)&ÿ<,0ÿE15ÿD.3ÿA-1ÿB05ÿ>*0ÿ@09ÿ=8Dÿ/6Eÿ+2Aÿ%.ÿÿÿÿÿ ÿÿ ÿ&ÿ$/ÿ (7ÿ.=Pÿ6I^ÿ5ASÿ>-3ÿJ*)ÿD'(ÿ4$'ÿ8*-ÿK38ÿJ5<ÿ?-4ÿ@17ÿPCMÿKJ[ÿ;5Eÿ- +ÿ) ÿ%ÿ) ÿ)ÿ&ÿ%ÿ(ÿ+ÿ+ÿ*ÿ*ÿ+ÿ-ÿ+ÿ)ÿ,!ÿ3%+ÿ7(1ÿ1$-ÿ.#+ÿ.$+ÿ,#(ÿ*!%ÿ/#(ÿ=,1ÿ>-1ÿ("ÿ&#ÿ' $ÿ) %ÿ+ &ÿ,!(ÿ+ 'ÿ-!*ÿ/",ÿ/",ÿ-!+ÿ.",ÿ,!)ÿ1%+ÿ7(.ÿ8'/ÿ:*7ÿ42Hÿ89SÿH>UÿU@PÿUBOÿUBOÿNJÿS@MÿVCPÿP=IÿOHÿRÿR:@ÿL5;ÿH5>ÿ?2DÿI=WÿRBYÿR?OÿN.7ÿG6AÿUBNÿVBGÿU@@ÿL9<ÿ>/8ÿ6(0ÿ7*4ÿG9EÿD4>ÿB1:ÿO=Jÿ?-5ÿ2!'ÿ-'ÿ* (ÿ%#ÿ'#ÿ)%ÿ-!(ÿ.!)ÿ*&ÿ+ 'ÿ,"(ÿ'#ÿ#ÿ&ÿ& ÿ#%ÿ &ÿ %ÿ!'ÿ")ÿ!ÿÿÿÿ ÿÿÿÿÿ*#'ÿ.$(ÿ0%*ÿ1)2ÿ1,:ÿ00?ÿ,1Bÿ'5Iÿ$8Pÿ#7Nÿ"3Eÿ'1@ÿ&-8ÿ (.ÿ&,ÿ$,3ÿ&-6ÿ*-6ÿ/,4ÿ2*0ÿ2&+ÿ$ÿ*ÿ 1ÿ#ÿÿ!ÿ%#ÿ$"ÿ ÿÿÿ ÿ%ÿ)!ÿ' ÿ%ÿ"ÿ ÿ ÿÿÿ!ÿÿÿ"ÿ&ÿ%ÿ ÿÿÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿ ÿ +ÿ + ÿ + ÿ ÿ ÿÿÿÿÿÿÿÿR:DÿM6Cÿ@0<ÿ/'.ÿ$ÿ!ÿ ÿ!ÿ!ÿ!ÿ'!ÿ%"ÿ! ÿ8-<ÿQ?Vÿ=,?ÿ/ )ÿ+!ÿ+!ÿ* ÿ'!ÿ'!(ÿ)*4ÿ'/;ÿ,8ÿ$-ÿ!ÿÿÿÿÿ ÿÿÿÿ&ÿ".ÿ!/@ÿ):Nÿ.;Oÿ6.9ÿ8(/ÿ1#+ÿ(")ÿ*'.ÿ9/4ÿ=.5ÿ:*2ÿ;+3ÿ@2;ÿ:1<ÿ5+6ÿ5'2ÿ4'0ÿ2&-ÿ1%,ÿ3&,ÿ2&,ÿ3(-ÿ6,1ÿ2&-ÿ0#*ÿ0#)ÿ2$*ÿ5'.ÿ5'/ÿ4&.ÿ1$,ÿ4'0ÿ<.8ÿ6(1ÿ/"+ÿ/"*ÿ2)/ÿ3/2ÿ-%*ÿ1$+ÿ4%,ÿ1#)ÿ*#ÿ,!&ÿ0+.ÿ2+0ÿ2&.ÿ1%,ÿ.!)ÿ3%-ÿ5'/ÿ2%,ÿ-&ÿ,'ÿ,'ÿ1%+ÿ4'-ÿ1")ÿ, 'ÿ)!+ÿ*#.ÿ1&1ÿ8*4ÿ5&/ÿ6'/ÿ4&-ÿ3&,ÿ7*1ÿ=.8ÿD3?ÿK9FÿP=JÿR?MÿVDQÿTAMÿP=HÿPÿK6?ÿL9FÿK9IÿK8HÿPIÿC2;ÿB1=ÿP>Nÿ\HYÿXETÿP>JÿI9Dÿ?1;ÿ,%ÿ+ 'ÿ.#*ÿ/"(ÿ0"(ÿ2#*ÿ*!ÿ) ÿ'ÿ#ÿ%ÿ) ÿ+#ÿ/!)ÿ2$-ÿ1%/ÿ5(2ÿ3&/ÿ, 'ÿ("ÿ,%ÿ, %ÿ*$+ÿ"#)ÿ$ÿ$ÿ!&ÿÿÿÿ ÿ ÿ ÿÿÿ#$ÿ6,5ÿ5+5ÿ1)5ÿ,.?ÿ(5Lÿ%5Mÿ$6Mÿ"7Pÿ7Pÿ3Hÿ-;ÿ!-8ÿ )1ÿ!'ÿ!&ÿ(0ÿ+3ÿ+3ÿ#+4ÿ,,6ÿ3*3ÿ%!ÿ*ÿ)7ÿ'0ÿ"&ÿ# $ÿ&#ÿ" ÿÿÿ %ÿ ÿ ÿ' ÿ ÿÿÿÿÿÿÿÿÿÿÿ!ÿ"ÿ"ÿ %ÿ!ÿÿÿÿÿ ÿ ÿ ÿ + +ÿÿ ÿ ÿÿ  ÿ + ÿ + ÿ ÿÿÿÿÿÿÿÿ ÿ<+2ÿ8'1ÿ5-8ÿ00;ÿ%&0ÿ "ÿÿÿÿÿ!#ÿ $ÿ%ÿ+(2ÿ;1@ÿ/'5ÿ"#ÿÿ ÿ #,ÿ%/ÿ)2ÿ*5ÿ(3ÿ$-ÿ"ÿÿÿÿ ÿ ÿ ÿ ÿÿÿÿ#ÿ#/ÿ+:ÿ!/>ÿ%,9ÿ"#-ÿ!ÿÿ!ÿ$%)ÿ+#(ÿ)"ÿ,!(ÿ9.9ÿ?3?ÿ@3@ÿD6DÿG9GÿE8FÿD9FÿE:HÿENÿUAXÿL7JÿH3?ÿH3=ÿK4>ÿM6?ÿQ:DÿO8@ÿL6<ÿL6<ÿM6>ÿM7?ÿN9FÿI6CÿG4@ÿO:FÿR=IÿB/9ÿE4AÿVCTÿ_K]ÿ\I\ÿSAQÿN4@ÿ?3?ÿE6CÿK;IÿKKÿJAMÿGDOÿFGQÿKFTÿJ?NÿN>MÿRAPÿP@PÿJ;KÿH9HÿG8GÿF8GÿE9Gÿ;0:ÿ3'0ÿ2(1ÿ6.8ÿ81;ÿ8/:ÿ?2=ÿ@0;ÿ9*4ÿ2&.ÿ9-5ÿA6>ÿC8Aÿ@3=ÿ:-4ÿ/$*ÿ&"ÿ(%ÿ,"(ÿ*%ÿ,&ÿ)#ÿ/"*ÿ3&.ÿ* %ÿ& ÿ-")ÿ2&.ÿ0$+ÿ- &ÿ-!'ÿ4'0ÿ9,6ÿB3>ÿM;HÿQ>KÿZFUÿYFUÿVBPÿXDRÿT?MÿS>KÿU?QÿU?VÿN:PÿJ4AÿK5>ÿM7@ÿO8BÿQ;DÿT>IÿaL\ÿgSdÿaM[ÿR-6ÿJ:Gÿ^K]ÿ_L_ÿ^K]ÿTBRÿM;JÿC4Aÿ1%-ÿ.$-ÿ)&ÿ$ÿ%ÿ( ÿ%ÿ(ÿ)!ÿ( ÿ'ÿ'ÿ$ÿ&ÿ)!ÿ( ÿ)!ÿ-!(ÿ/#*ÿ2%.ÿ7(4ÿ7)4ÿ7-7ÿ*'.ÿ ÿÿÿÿÿÿ ÿ ÿ ÿ ÿÿ+',ÿ6+4ÿ8.7ÿ82?ÿ24Gÿ#2Gÿ+;ÿ'3ÿ&0ÿ",ÿ"ÿÿ ÿÿÿÿÿ"ÿ!%ÿ#(ÿ!&.ÿ-)2ÿ#%,ÿ&-ÿ'.ÿ!%ÿ ÿ# "ÿ%!ÿ ÿÿÿ)(+ÿ& "ÿÿ!ÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ + ÿ ÿ  ÿÿ"&ÿPJ[ÿOGWÿ70;ÿÿÿ ÿÿ#ÿ )ÿ!+ÿ*5ÿ#+ÿ!(ÿ$+ÿ"(ÿ"ÿ(ÿ$5ÿ*?ÿ*?ÿ&7ÿ-Bÿ+=ÿ#0ÿ#1ÿ'8ÿ&9ÿ&8ÿ'9ÿ*<ÿ.Aÿ%3ÿ )ÿ"*ÿ#(ÿ ÿÿÿÿÿ ÿÿÿÿ ÿ  ÿ ÿ ÿÿÿÿÿÿ ÿ ÿ$ÿ %ÿÿÿÿÿ %ÿ!'ÿ!'ÿ%(/ÿ/+4ÿ3+3ÿ;-6ÿA1;ÿC3>ÿB3=ÿC5>ÿB6?ÿ?6>ÿ=6>ÿD9EÿB5AÿL:EÿS@KÿN;HÿE5AÿF6BÿI8FÿH9GÿC6Cÿ8,5ÿ4(0ÿ7+4ÿ;/:ÿ=1<ÿ?2>ÿE5AÿE5@ÿ?/9ÿ7)2ÿ=/8ÿD6?ÿD6?ÿ?1:ÿ;-4ÿ6*1ÿ1&-ÿ/$,ÿ/$+ÿ."'ÿ0#)ÿ,&ÿ5'1ÿ:,6ÿ1%-ÿ0$,ÿ5*3ÿ8,5ÿ7)2ÿ6(0ÿ9,5ÿ?1=ÿD4@ÿMKÿ:+3ÿM=JÿcPbÿ_L_ÿ\IZÿQ?OÿJ:IÿD5Cÿ9,5ÿ8+5ÿ4(0ÿ/$*ÿ-!&ÿ-%ÿ(ÿ,#ÿ1#(ÿ1$)ÿ.!'ÿ+#ÿ&ÿ'ÿ( ÿ&ÿ%ÿ&ÿ) ÿ- &ÿ2$-ÿ4'0ÿ2(0ÿ&#)ÿÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿ!ÿ&!ÿ-%-ÿ-*7ÿ!*8ÿ$/ÿ &ÿ&ÿ'ÿÿÿÿÿÿÿÿÿ!ÿ!ÿ#ÿ!$ÿ"ÿ!ÿ#ÿ"ÿÿ!ÿ" "ÿ$ ÿÿÿÿ*!ÿ5%*ÿ9)0ÿ9(0ÿ-%ÿ'ÿ( ÿ'ÿ* "ÿ+!$ÿ*!ÿ)ÿ*!ÿ+!$ÿ-#'ÿ+ $ÿ,!$ÿ0'*ÿ%#)ÿÿ ÿ ÿ ÿ + + ÿ + +ÿ +ÿÿ3/9ÿc\nÿaWgÿEÿ*@ÿ*@ÿ+@ÿ,@ÿ.Aÿ .Aÿ*;ÿ%5ÿ"2ÿ"1ÿ$2ÿ *;ÿ(7ÿ$0ÿ!(ÿ!ÿÿÿÿÿÿÿÿÿÿ ÿÿ ÿÿÿÿÿÿÿÿÿ"ÿ$%+ÿ#")ÿ ÿÿÿ#ÿ#ÿ!ÿ%ÿ"(ÿ*'/ÿ2)0ÿ4(/ÿ5'/ÿ6(0ÿ6(/ÿ4(.ÿ3'.ÿ4(/ÿ8+4ÿ6(1ÿA09ÿI6@ÿD2;ÿ<,4ÿB2=ÿI8FÿJ9GÿC3@ÿ7)2ÿ7)2ÿ:-7ÿ>0;ÿB3?ÿE5BÿK:GÿM;HÿF5@ÿ;+5ÿ?0:ÿC4=ÿ?08ÿ8)0ÿ7)/ÿ<-6ÿ>09ÿ;-6ÿ4'/ÿ1$+ÿ4'/ÿ0#+ÿ:+5ÿA1<ÿ:+6ÿ=0;ÿ=1<ÿ<0;ÿ<.9ÿ?0:ÿF6CÿJ:GÿNJÿW?KÿW@Kÿ_FSÿY08ÿ@1;ÿ>09ÿ;-5ÿ7*0ÿ4%,ÿ- %ÿ1")ÿ7(/ÿ9*1ÿ6'.ÿ2%+ÿ- &ÿ+$ÿ+$ÿ)"ÿ("ÿ' ÿ)!ÿ,#ÿ-%ÿ- 'ÿ*!'ÿ!#ÿÿÿ ÿ ÿÿ ÿ +ÿ ÿ ÿ ÿÿÿ ÿ*!'ÿ/&/ÿ,(3ÿ!%/ÿ"*ÿ#ÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿ ÿ&&)ÿ.'/ÿ- .ÿ*(ÿ($ÿ<,2ÿO;CÿYBMÿYBOÿH5Aÿ?/8ÿA09ÿB08ÿE5:ÿH8>ÿF5;ÿD27ÿE4;ÿC38ÿG6;ÿA04ÿ=,/ÿB17ÿ1)0ÿ!ÿÿ ÿ + ÿ ÿÿ ÿ$ÿ>9Gÿ^Veÿ_TaÿI?Hÿ'!'ÿÿÿÿ"ÿ%ÿ"ÿ#ÿ#ÿ ÿÿÿB;MÿNASÿC:Mÿ'+>ÿ$6ÿ%6ÿ&5ÿ'6ÿ)8ÿ)8ÿ&5ÿ"/ÿ .ÿ"1ÿ#0ÿ#.ÿ#,ÿ")ÿ$ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿÿ")ÿ&*6ÿ.->ÿ3,=ÿ/&3ÿ!'ÿ#ÿÿÿÿ$ÿ('/ÿ7/8ÿ=1:ÿ:,7ÿ;,7ÿ9+4ÿ9+4ÿ8*2ÿ4&,ÿ8)1ÿ6(/ÿ9*2ÿ>.6ÿ?/7ÿ?/9ÿD3?ÿJ8EÿJ9FÿC2>ÿ9*4ÿ6(1ÿ:+5ÿ>/:ÿB2=ÿE4AÿK8EÿL:FÿF6@ÿ;,5ÿ=.7ÿ:,3ÿ2$)ÿ,$ÿ1#*ÿ6(2ÿ;,5ÿ8*1ÿ2%,ÿ3%.ÿ7)4ÿ2&2ÿ:-9ÿB3?ÿ@2>ÿF9FÿH;HÿC6Cÿ=/;ÿB2=ÿQ?NÿRAPÿR@OÿVCSÿZGYÿWDUÿVBQÿWAPÿVAOÿT@MÿR>OÿN;QÿJ6IÿJ5@ÿP9DÿU>HÿU>IÿWAMÿVALÿS=HÿbJXÿT58ÿN)ÿU64ÿW?HÿS>MÿJ6FÿG3?ÿL8BÿT>JÿT@Mÿ;+3ÿK;IÿbObÿ`M_ÿZGXÿQ@OÿK;IÿD4Aÿ7*3ÿ7)3ÿ:+5ÿ9*4ÿ9*4ÿ:*5ÿ4'-ÿ8)2ÿ@/9ÿC2=ÿA0:ÿ>.6ÿ7)/ÿ5'.ÿ5'/ÿ3%-ÿ/#+ÿ,!)ÿ-"*ÿ0$,ÿ1$-ÿ/#-ÿ-#+ÿ% $ÿÿÿ ÿ ÿÿÿ ÿ ÿ +ÿ ÿÿÿ!ÿ.&-ÿ/*6ÿ&)8ÿ!&2ÿ!*ÿ%ÿÿÿÿÿ ÿ ÿÿÿ$ÿÿÿÿÿÿÿÿÿÿÿÿ)&+ÿ3-6ÿ-(3ÿ4)1ÿ2&.ÿ:,4ÿPIÿS?JÿT@IÿWBMÿU@IÿS?GÿS@JÿF4<ÿK;AÿB27ÿ/"$ÿ,#&ÿ !ÿÿÿÿÿÿÿÿ#!-ÿ93Gÿ@6FÿD7Fÿ;/;ÿ('ÿÿ ÿ!(ÿ#)ÿ"'ÿ $ÿ ÿÿÿÿÿ0/=ÿ?7Fÿ82Cÿ"%6ÿ-ÿ -ÿ"/ÿ!'6ÿ#*9ÿ%3ÿ!.ÿ)ÿ)ÿ*ÿ(ÿ$ÿ$ÿ"ÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿ$ÿ"-ÿ#'4ÿ*)6ÿ*%0ÿ ÿÿÿÿÿ ÿ"#*ÿ+)2ÿ.+5ÿ1-6ÿB6?ÿI9CÿK:CÿI7AÿE4=ÿK9DÿE4=ÿ;,4ÿ9*2ÿ>-6ÿ=-7ÿC3?ÿF6AÿC2=ÿ=,5ÿ9*2ÿ9*2ÿ<,5ÿ?.8ÿ@/9ÿA09ÿB1;ÿC2;ÿ?/7ÿ7)/ÿ;,3ÿ8)0ÿ6'-ÿ;+3ÿG8BÿUDQÿZGUÿYFTÿWDRÿUAPÿP>KÿA3?ÿ>/<ÿA1?ÿA3@ÿJ;Hÿ@3>ÿ9,6ÿ>0:ÿJ:FÿYFXÿYEWÿT@PÿVCTÿ^K\ÿXETÿU@OÿWAOÿWAOÿS>LÿT?KÿO:FÿM7AÿP9BÿT>IÿZCOÿ\DQÿWAMÿQ;EÿRHÿP=NÿF4CÿD1<ÿL8BÿT@LÿUANÿ>.8ÿN=LÿbObÿ`L_ÿ]J\ÿXFVÿSAQÿQ@OÿRAOÿUCQÿWDSÿVDSÿR@NÿJ8Eÿ8)2ÿ=-6ÿC3<ÿE4>ÿD3>ÿE4=ÿA09ÿ?/8ÿ?/9ÿ<-6ÿ8)3ÿ6'1ÿ5(2ÿ6(2ÿ5'1ÿ3%/ÿ0$+ÿ)!%ÿÿÿÿ ÿ ÿÿ ÿ +ÿ +ÿ +ÿÿÿ!ÿ/%,ÿ-(2ÿ!(5ÿ(5ÿ#,ÿ%ÿÿÿÿÿ +ÿ ÿÿ#&ÿ'%1ÿ%!)ÿ!!ÿÿÿÿ!ÿ$ÿ%#)ÿ-(.ÿ"ÿÿ"!#ÿ(&)ÿ $ÿ'$'ÿ/+0ÿA4>ÿQ=Hÿ[BLÿ]EQÿ]ERÿ\ERÿ\ESÿ[DRÿWBNÿYCPÿS=IÿQÿ(%*ÿÿÿÿ(&-ÿ0*3ÿ'"*ÿ$!-ÿ>6FÿUGYÿE4?ÿS>JÿV@LÿC0:ÿÿ %ÿ%*ÿ%*ÿ$(ÿ!$ÿÿÿÿÿÿ*ÿ%%1ÿ$%2ÿ-ÿ&ÿ'ÿ(ÿ#1ÿ!'6ÿ#0ÿ(ÿ$ÿ#ÿ#ÿ!ÿ ÿ!ÿÿÿ ÿÿÿ ÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿ ÿÿÿÿÿ"ÿ%ÿ!ÿÿ ÿÿÿÿÿ!ÿ%ÿ!(ÿ#&-ÿ719ÿE7?ÿK8@ÿI6>ÿF4=ÿM:EÿI7AÿE3<ÿF4=ÿJ7@ÿJ7BÿI7BÿF4>ÿB19ÿ@.6ÿ?.5ÿA/7ÿB08ÿB19ÿC3:ÿD29ÿB18ÿC29ÿ?/6ÿ8*0ÿA18ÿB29ÿC1:ÿI6@ÿTAMÿ`M[ÿcO^ÿdO^ÿbM\ÿ^IWÿZERÿN;FÿG5AÿE5BÿD6DÿD6Bÿ9-6ÿ:,5ÿC3>ÿM;Iÿ\I[ÿ[GZÿWDTÿXEUÿ\IYÿWDSÿWCQÿXCPÿUAPÿO;LÿJ6=ÿJ57ÿJ4>ÿM6EÿU>Hÿ]EPÿeLWÿ^FPÿO8BÿK5>ÿN9Bÿ<$'ÿ4ÿ@*0ÿJ5?ÿJ9MÿD2AÿE1:ÿM9CÿS@LÿS@NÿE3@ÿR?OÿbM`ÿ`L^ÿ^K\ÿZGXÿUCTÿWEUÿ`L]ÿcN^ÿeO`ÿcN_ÿ]IXÿP=Iÿ8(0ÿ=-4ÿE3;ÿG4=ÿG4=ÿI6?ÿI6?ÿI6?ÿI6?ÿH6?ÿH4>ÿG4=ÿF4=ÿD3<ÿC1:ÿE3;ÿD2:ÿ=/6ÿ.%*ÿÿÿ +ÿ +ÿ ÿ ÿÿÿ ÿÿ&!&ÿ;07ÿ@2;ÿ5.8ÿ"(3ÿ&1ÿ%(1ÿ.(/ÿ+%*ÿ!#ÿÿÿÿ$ÿ/$)ÿ;/7ÿ80<ÿ<3=ÿ;2:ÿ6/6ÿ6.5ÿ907ÿ>2:ÿ?4=ÿ>3=ÿ:/9ÿ.*4ÿ.*2ÿ'$(ÿÿÿÿ"#%ÿ:/7ÿH4?ÿI3;ÿSÿJ6@ÿC/8ÿB/8ÿR>IÿXDQÿ^K\ÿZFVÿPIÿYDQÿ^JWÿ_KXÿ_KXÿ]HUÿXDPÿYDNÿT@JÿM:EÿG6CÿE6DÿC5BÿD6AÿH8EÿL:HÿPÿ>1Eÿ6,FÿWÿF9iÿSBgÿaL]ÿ_K]ÿ]J\ÿYFXÿTASÿVCTÿbM]ÿdM^ÿeP`ÿdO^ÿ]HVÿP=GÿE3;ÿ>-3ÿ?,3ÿB/6ÿC06ÿD18ÿG3;ÿH4;ÿI4<ÿK6>ÿL7?ÿL8@ÿL8@ÿJ7?ÿI7=ÿN:BÿM9CÿH6Aÿ=/8ÿ*!$ÿÿ ÿ +ÿÿ%ÿ7)1ÿ4'-ÿ)#ÿ)!%ÿ<07ÿR?IÿTALÿB7Cÿ+,7ÿ.,6ÿ:2<ÿE7@ÿC5=ÿ6+2ÿ-#)ÿ1',ÿ;.5ÿ@19ÿG6>ÿM;DÿD7@ÿF9CÿC8Aÿ>4<ÿ@4<ÿD6>ÿI8AÿMÿ2*0ÿÿ ÿÿÿ/$)ÿ>,3ÿ@-2ÿL6=ÿM8?ÿE16ÿ=*.ÿ<*/ÿ2#&ÿ4$(ÿ0 $ÿ2"&ÿD07ÿL7@ÿQHÿQÿE4BÿQ@NÿVETÿUDSÿSAOÿVAPÿ]J\ÿZGWÿVCRÿWCQÿYESÿ]HWÿZESÿP@YÿUGiÿeTrÿR@aÿ6*]ÿ<1gÿH9eÿE1Oÿ[?QÿW9Lÿ]EYÿ`KcÿJ:Yÿ3%JÿZF\ÿZIcÿB:]ÿ;4TÿD4GÿG3=ÿM8BÿPaÿC;‰ÿQD~ÿ`L\ÿ^K]ÿ^K]ÿ[GZÿTASÿTARÿ]JYÿ_KZÿaL[ÿaLZÿYETÿL;KÿXDQÿ@.6ÿ, ÿ0"%ÿ2#'ÿ4$)ÿ7',ÿ9).ÿ;)/ÿ=*0ÿ>+2ÿ?,3ÿ>-3ÿ>-3ÿ>.3ÿC29ÿ@.9ÿ?-<ÿ@1<ÿ;/3ÿ"ÿÿÿ#ÿ8*1ÿPIÿM;DÿB2:ÿ>.6ÿC3<ÿK9DÿN;FÿN:EÿL9AÿB3:ÿ:,3ÿ1%,ÿ/$*ÿ6)/ÿ@/5ÿD18ÿJ8BÿH7Cÿ<+3ÿ@05ÿD49ÿ8+/ÿ ÿÿ*!%ÿ!ÿ-!$ÿ?,1ÿE04ÿE05ÿD/6ÿ@,:ÿ>+;ÿ>,3ÿ0!%ÿ/$ÿ,!ÿ-#ÿ<*1ÿI3=ÿP9CÿO7?ÿV=Dÿ_GNÿ;06ÿ"$ÿ#%ÿ8/9ÿVGVÿuauÿ†nƒÿw]nÿR8BÿK7@ÿ|cqÿ€ivÿdR\ÿ7-4ÿ&',ÿ)-2ÿ329ÿ++1ÿ!ÿÿÿÿÿÿÿ&ÿ ÿÿÿÿ$ÿ!$0ÿ'*8ÿ+.:ÿ..8ÿ.-8ÿ50=ÿA8CÿJ?HÿG?Jÿ409ÿ40:ÿ?9DÿHAKÿF@Gÿ-*/ÿÿÿÿÿÿÿ ÿ ÿ ÿ ÿÿÿ ÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿÿÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿÿ !ÿ8-7ÿA1;ÿ@.7ÿ@.7ÿE2;ÿC2;ÿA09ÿB08ÿH5=ÿT?IÿE3;ÿD18ÿI5;ÿ@.6ÿA07ÿD2:ÿG5>ÿG6>ÿD3;ÿC2;ÿB1:ÿ>.5ÿ9+/ÿ8+-ÿ?07ÿ>.5ÿ>/5ÿB2:ÿG6AÿO=JÿOIÿJ7CÿQ>SÿK:ZÿUC^ÿ`M_ÿ^K]ÿ^K]ÿZGYÿTBSÿP>MÿP>LÿR>KÿR>JÿT?MÿM:Tÿ?/[ÿR>Tÿ:+4ÿ$ÿ&ÿ&ÿ' ÿ,!)ÿ4'2ÿ6)4ÿ3$,ÿ0!'ÿ-$ÿ) ÿ'ÿ* ÿ- %ÿ,%ÿ, 'ÿ/")ÿ.#'ÿ%ÿÿÿÿ*"ÿ7(/ÿ7(/ÿ3&-ÿ3&,ÿ5&,ÿ7'-ÿ7'.ÿ0&.ÿ-&/ÿ5(.ÿ5'-ÿ5'-ÿ2%*ÿ+ $ÿ&ÿ, %ÿ0"(ÿ0"(ÿ0"'ÿ- %ÿ( ÿ*!ÿ(!ÿ&ÿ:+/ÿaIPÿdJPÿ]ELÿT>FÿJ5;ÿL8<ÿL8=ÿ@04ÿ2()ÿ6*.ÿ=3;ÿ)#(ÿÿ%ÿ,ÿ*ÿ* ÿ'Hÿ%Qÿ(&ÿ&ÿ$ÿÿÿ*$ÿ8&/ÿD.7ÿG07ÿP9>ÿ[CJÿ@1=ÿ1,<ÿ61AÿTGXÿs_tÿzcvÿkTfÿR=JÿA,6ÿS>Hÿzaoÿ~esÿqXdÿXAKÿ3&.ÿ.)0ÿ:6=ÿ438ÿ %(ÿ ÿ ÿÿÿÿ #ÿ!ÿÿÿÿÿ#ÿ(ÿ*-<ÿ45Eÿ10<ÿ53>ÿ2+6ÿÿ82;ÿ51:ÿ508ÿ0+1ÿ)%)ÿ,%)ÿ%$ÿÿÿ%!ÿÿ  ÿ ÿ ÿ ÿ,ÿ%ÿ ÿÿ ÿ ÿÿÿÿÿÿÿÿÿÿ + ÿ + + ÿ ÿ + + ÿ + ÿ + + +ÿ +ÿ ÿÿ ÿ,'2ÿ?4@ÿD6@ÿ:,4ÿ=/:ÿB5?ÿ<.7ÿ5'-ÿ;,2ÿ>/5ÿ4&+ÿ4%*ÿ6',ÿ1#)ÿ7)/ÿ=/6ÿB4=ÿD6?ÿB5>ÿB3<ÿ9,3ÿ/#)ÿ-"'ÿ7,3ÿE8DÿC6@ÿG:DÿJ=GÿE6@ÿE4@ÿB1;ÿD4>ÿG8CÿG7@ÿD4=ÿ3%-ÿ:,4ÿO>Kÿ[IZÿ]K]ÿ\K]ÿZGXÿWETÿWDUÿXETÿVBQÿZFVÿ^K[ÿ]IXÿ[GUÿZESÿWBOÿR?LÿO=LÿM=Nÿ>/?ÿD4FÿK=Tÿ@6Sÿ=5Xÿ<0KÿD4EÿJ9GÿG9FÿF9FÿG7DÿH6BÿI7@ÿK8@ÿK7@ÿJ6@ÿN;FÿK9DÿA1;ÿRAPÿVCRÿYFVÿYGXÿTBRÿYGXÿYFWÿTBRÿM;JÿG5BÿD2>ÿB1;ÿF4?ÿG5GÿD3LÿP=Mÿ<-7ÿ)!ÿ&ÿ&ÿ+)ÿ0%0ÿ4)5ÿ7+6ÿ6)3ÿ4'0ÿ/$,ÿ)&ÿ%ÿ$ÿ* (ÿ()ÿ&)ÿ()ÿ-#)ÿ.$)ÿ(#ÿ#ÿ"ÿ%ÿ."(ÿ.")ÿ."*ÿ/#*ÿ-"(ÿ)"ÿ(#ÿ.$-ÿ4)4ÿ5(1ÿ/#*ÿ+ %ÿ' ÿ!ÿÿ!ÿ"ÿ!ÿ!ÿ#ÿ$ÿ$ÿ$ÿ#ÿ/"%ÿN:@ÿO:?ÿJ6;ÿM9?ÿXAHÿeHLÿwU[ÿlOSÿK8:ÿ6),ÿ4*/ÿ$"ÿÿÿ#ÿ$ÿ%ÿ"2ÿ' >ÿ5-8ÿ2)0ÿ& ÿ#ÿ1"'ÿA/6ÿG4:ÿI5:ÿE16ÿC15ÿF3:ÿ6)1ÿ1-;ÿ63BÿD;KÿREVÿSDRÿC6Dÿ6*8ÿ6*6ÿA4?ÿVCMÿTBMÿO=GÿE3;ÿ/$,ÿ*%*ÿ)*-ÿ#'*ÿ!ÿÿÿÿÿÿ!"%ÿÿÿÿ ÿ!ÿ%ÿ"!,ÿ;3@ÿPAPÿWFUÿRIYÿHH^ÿIKcÿDEYÿ-+7ÿ71:ÿ/*3ÿ(#*ÿ##ÿÿ) "ÿ/%(ÿ'$ÿÿÿ%ÿÿÿ ÿ ÿ ÿ(ÿ"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$#ÿ$#ÿ ÿÿÿÿÿÿÿ!ÿ,%0ÿ:/9ÿ;.6ÿ.!)ÿ/%.ÿ8,6ÿ5)1ÿ/"(ÿ1$*ÿ."'ÿ+$ÿ*$ÿ*%ÿ+&ÿ1$,ÿ9+4ÿ;.7ÿ:.6ÿ:-6ÿ9,3ÿ2&-ÿ)%ÿ($ÿ2'/ÿ@3>ÿ>1<ÿA4>ÿD6@ÿ@2;ÿ=-7ÿ6'.ÿ6)0ÿ<.7ÿ?/7ÿ?/8ÿ9*3ÿE5?ÿUCQÿ\JZÿ]J[ÿ\I[ÿ[HZÿYFVÿVDSÿWDSÿ[HWÿ`L]ÿaN_ÿaM^ÿ`M^ÿ]IYÿ\IXÿ[HWÿYEUÿ\HWÿQ9EÿN8JÿR?SÿP>KÿQATÿP>MÿS@LÿUBNÿTALÿXDPÿUAMÿUALÿUALÿR=HÿR=JÿPKÿL:GÿA1:ÿQ?MÿZGWÿ[GXÿTBRÿNLÿJ8Eÿ=,6ÿ5&/ÿ1#*ÿ4&.ÿ;,4ÿ@08ÿF5?ÿ@/8ÿ8+5ÿ8,;ÿ<.Aÿ3$6ÿ/!6ÿ0$4ÿ2&/ÿ2&-ÿ1%-ÿ/$+ÿ,"(ÿ'"ÿ$ÿ+ (ÿ))ÿ&)ÿ()ÿ,!(ÿ-"'ÿ(#ÿ5+3ÿ8.6ÿ#ÿ*$ÿ)$ÿ&"ÿ$ÿ"ÿ!ÿ#ÿ* (ÿ/$-ÿ/$+ÿ+ 'ÿ*$ÿ' ÿ#ÿ"ÿ#ÿ&ÿ'!ÿ($ÿ) %ÿ)!#ÿ( ÿ*!ÿ*!ÿ*!ÿ4&+ÿ5'-ÿG:AÿXGMÿaEJÿlLOÿ}Y\ÿuSVÿU/4ÿ<-1ÿ8).ÿ4&+ÿ2$*ÿ)%ÿ-'1ÿ-)4ÿ*&1ÿ'$.ÿ%!*ÿ!*ÿ$,ÿ(".ÿ)$/ÿ*&ÿ!$ÿ"#ÿ&#ÿ#%ÿ#ÿÿÿÿÿÿÿÿÿÿÿÿ"ÿ#ÿ!ÿ%)ÿ30>ÿKPgÿ]`zÿaWmÿWNbÿOPlÿLSqÿCH_ÿ'%1ÿ�ÿ%'ÿ&!ÿ'!ÿ'"ÿ,"ÿ,"ÿ'!ÿ!ÿ!ÿ%ÿ#ÿ ÿÿ ÿ"ÿ$ÿ!ÿÿÿÿÿÿÿ&ÿ'#ÿ&ÿ%ÿ&$ÿ*!%ÿ("ÿ3(/ÿ3(/ÿ-"(ÿ, &ÿ% ÿ%ÿ$ÿ"ÿ$ÿ)$ÿ2&/ÿ4'/ÿ- %ÿ$ÿ'ÿ.!'ÿ0"(ÿ1#)ÿ4&-ÿ2%,ÿ2%,ÿ3&.ÿ4&0ÿ5'1ÿ9+4ÿ=/8ÿ;,5ÿ6(1ÿ7(1ÿ6)0ÿ3&-ÿ0$+ÿ.")ÿ/#)ÿ8*2ÿ8*3ÿ7)1ÿ8)0ÿ;+3ÿ9*1ÿ2$*ÿ.!&ÿ2$*ÿ8)1ÿ;+3ÿC3=ÿN=IÿVDSÿZGWÿ[HYÿ\I[ÿ]I[ÿ[GXÿYFWÿ^L]ÿdQcÿdRdÿdQdÿfRfÿeSfÿbOaÿbPaÿbPbÿ_M_ÿcQbÿZBPÿXASÿ[G[ÿXDTÿ[GXÿYFVÿ]IYÿ_K[ÿ\HWÿ_K[ÿ\HWÿ]IWÿ^IXÿZETÿ\GWÿ[FVÿZFVÿVCQÿM:FÿQ>LÿYEVÿZFWÿTBQÿM;IÿK:GÿH8DÿH8CÿD3>ÿ7'/ÿ1")ÿ,$ÿ- %ÿ1$*ÿ5'0ÿ6'.ÿ>,5ÿ?1?ÿ?3Hÿ?0Iÿ/8ÿ&4ÿ-3ÿ5(1ÿ6)/ÿ6)0ÿ7*1ÿ6)0ÿ3'+ÿ2&%ÿ5(.ÿ2%-ÿ."*ÿ-!)ÿ-!(ÿ+%ÿ("ÿ:/8ÿ?4=ÿ& ÿ'#ÿ)$ÿ'!ÿ#ÿ#ÿ)%ÿ, (ÿ-"*ÿ.!)ÿ.!'ÿ.!(ÿ."(ÿ."(ÿ-!'ÿ-!(ÿ."(ÿ0$*ÿ2&.ÿ3'0ÿ3&0ÿ0$,ÿ4&/ÿ8)2ÿ9*3ÿ7)3ÿ8)4ÿ8*4ÿK>GÿXGNÿW<>ÿ^AEÿdDFÿ^?AÿL37ÿ5&+ÿ3$*ÿ7'.ÿ;,4ÿ?1;ÿB4>ÿ@1<ÿB1<ÿ>.7ÿ;,5ÿ<.8ÿ/'-ÿ(%)ÿ ÿÿ!"ÿ)",ÿ% 'ÿ%$ÿ,!)ÿ0$-ÿ-#-ÿ:2?ÿ92Aÿ.)9ÿ%#1ÿ$ÿÿÿÿ ÿÿ ÿ ÿ ÿÿÿÿÿ ÿÿÿ ÿ ÿ +ÿ ÿ' ÿ# ÿ(!'ÿ)"'ÿ ÿ/#*ÿ?ÿ-"*ÿ+ 'ÿ($ÿ(!ÿ' ÿ'ÿ( ÿ+"ÿ- %ÿ.!'ÿ/"'ÿ/"'ÿ0#)ÿ0$*ÿ1$+ÿ1$*ÿ1$+ÿ0#-ÿ*&ÿ)#ÿ($ÿ!ÿ" ÿ%ÿ#ÿ&ÿ1 #ÿ4!(ÿ7"%ÿ4!)ÿ3"/ÿ5&.ÿ.!&ÿ4(.ÿ6(0ÿ2$,ÿ1$*ÿ/#(ÿ1$)ÿ1$*ÿ1#*ÿ2$,ÿ6(/ÿ8*3ÿ8*3ÿ5(/ÿ2$+ÿ7'/ÿ=-5ÿ;+3ÿ;+3ÿB1=ÿA0;ÿB2<ÿD3?ÿF4AÿH6BÿK:EÿK:EÿI9DÿI9DÿK:FÿL;GÿF5Aÿ@1;ÿ=08ÿ?2;ÿJ;HÿL=JÿKÿ?/8ÿ;,4ÿ8)0ÿ8)/ÿ=-5ÿ?/8ÿJ9EÿSANÿWETÿZGWÿ\I[ÿ`M`ÿaMaÿaN`ÿcQcÿeSfÿgUhÿgUhÿgSgÿeReÿdQeÿdQdÿcPbÿaO_ÿ`M^ÿ`M]ÿWDRÿXDRÿ\GVÿXCSÿYDTÿZFUÿ\GWÿ]GXÿ^IXÿ^JZÿ_K[ÿ_K\ÿ`K\ÿaL\ÿbM]ÿaM^ÿ`M^ÿ_K[ÿYEUÿTAPÿWDTÿZEWÿWCSÿP=KÿK:EÿI8BÿF6?ÿC2<ÿ@/:ÿ?/8ÿ?.7ÿ?.7ÿ>.8ÿ9+5ÿ."(ÿ9+3ÿ@1?ÿ;-@ÿ. 5ÿ)4ÿ*2ÿ<,;ÿI9EÿL.<ÿ=.;ÿ=-:ÿ<+7ÿ;+7ÿ:+7ÿ;+7ÿ;,7ÿ:,7ÿ:+7ÿ;,8ÿ<.:ÿ=.<ÿ<-;ÿ8*7ÿ?.<ÿC1@ÿE3BÿF5EÿG5EÿC2@ÿ<,6ÿ6&-ÿ9(.ÿC07ÿ?+1ÿ8&+ÿ:)/ÿA08ÿB/7ÿF4=ÿNQkÿ?>Pÿ;2@ÿ5(2ÿ3"*ÿ4%,ÿ3%+ÿ0#(ÿ- %ÿ+#ÿ,#ÿ- #ÿ0"'ÿ1"(ÿ/"'ÿ.!&ÿ/"'ÿ/"'ÿ."'ÿ/#'ÿ/!&ÿ.!(ÿ*$ÿ,%ÿ-!(ÿ)'ÿ/")ÿ1$(ÿ,"ÿ(ÿ-!ÿ/$ÿ4#(ÿ5#.ÿ5%4ÿ9)5ÿ8'1ÿ<+3ÿ?.8ÿ@0;ÿB2>ÿD4?ÿE5AÿG6DÿH7FÿI8GÿH7EÿG6EÿE5DÿC3AÿB1>ÿD4@ÿE6BÿD3?ÿD2?ÿH7FÿF6EÿE6EÿG7EÿI8FÿJ:GÿK;HÿI9EÿM>KÿTESÿWGVÿZHZÿUCUÿH8GÿB5@ÿPBQÿaQeÿbShÿaSgÿ^PcÿXIXÿRAMÿK9CÿB19ÿC29ÿN;FÿR@MÿYGVÿ]K\ÿ^L_ÿ`M`ÿaNcÿbOeÿdRgÿdSgÿbPcÿ]K]ÿ\IYÿ^J[ÿ_J\ÿ^J\ÿ`L_ÿ_L]ÿ]JZÿZGVÿVCQÿQ>JÿR@OÿT@QÿS>NÿR=MÿWAQÿZEUÿ\GWÿ\GXÿ]HYÿ]IZÿ_K\ÿ_K]ÿ_K\ÿ_L\ÿ_K[ÿ_K\ÿ`L]ÿ_K[ÿZGVÿTANÿWDRÿ[EUÿ[DSÿXCQÿUANÿQ>KÿP=IÿOKÿN=KÿNIÿK9DÿG6AÿF4@ÿD2>ÿB0;ÿ@/8ÿ@.8ÿA0;ÿA0;ÿA/;ÿA0=ÿB2?ÿD3@ÿE3BÿD3AÿC2AÿC2BÿC2CÿB1BÿC1CÿD2DÿE2EÿE2EÿC1DÿC1DÿC1DÿC3EÿD3Eÿ@0?ÿC1AÿD1AÿC1AÿE3DÿF3FÿE3FÿD0AÿB/=ÿB1>ÿE3?ÿE3>ÿG6@ÿL;EÿP=IÿN9DÿQ=HÿS@LÿTANÿTAOÿUAPÿVAPÿUAQÿS?OÿK:Hÿ3)3ÿ)"*ÿ% &ÿ% &ÿ*$-ÿ+"/ÿ#&ÿ#"ÿ* 'ÿ,"+ÿ'&ÿ+$.ÿ/)7ÿ.*9ÿ($3ÿ!,ÿ*ÿ(ÿ%ÿ"ÿÿÿÿÿÿÿÿ!!&ÿ-(/ÿ+")ÿ#ÿÿÿÿÿ?/<ÿ;-9ÿ8./ÿ/&ÿÿ"ÿ2+4ÿG\yÿLh‹ÿ?F[ÿO;Hÿo==ÿf9>ÿJ7GÿL=OÿOARÿL?PÿG:IÿC4AÿB2<ÿF5=ÿ@-4ÿ>,2ÿC28ÿF5<ÿH6>ÿH5<ÿH5=ÿF4=ÿB1:ÿC3?ÿ@/=ÿG6EÿL;LÿI8HÿK:JÿL:JÿK9IÿJ8JÿJ8JÿJ8IÿJ8IÿI6IÿF4FÿA0@ÿ;+8ÿB0<ÿG5BÿH6EÿF4CÿG5CÿH7EÿI8FÿI9GÿKNÿRASÿUEWÿWFYÿWDXÿVDWÿWFXÿ\HZÿ^J\ÿZJ\ÿYJ\ÿ[K^ÿ^Maÿ`OdÿaPfÿbQfÿ\K_ÿ_NbÿeTiÿeSiÿcQhÿ`NdÿUCVÿJ9IÿQ@Rÿ_Ndÿ\K`ÿVFXÿSCRÿP@MÿMÿP=IÿS@NÿVCRÿWEUÿYGYÿ[I\ÿ[H\ÿ_Laÿ`Ncÿ`Obÿ`Oaÿ_M_ÿaNbÿbOdÿbOcÿ_M_ÿ_L_ÿ\I[ÿ[HXÿXFUÿQ?MÿF4@ÿM;HÿL9HÿG5CÿN:IÿU@QÿZEUÿ\GXÿ^HYÿ^HYÿ^IZÿ^IZÿ^IYÿ]IXÿ\HWÿ[GVÿ]IXÿ^JYÿ]HWÿWCOÿOKÿP=JÿPLÿR>NÿR?NÿQ=MÿPÿJ7=ÿ3&.ÿ" ÿ8*7ÿ7*7ÿ4'0ÿ*!ÿÿ4ÿe&#ÿzERÿ|P`ÿr;Bÿb38ÿi77ÿa;DÿR@QÿTEYÿUFYÿRCUÿO?OÿK:IÿJ8EÿM:EÿK6@ÿK6@ÿO;FÿS@JÿT?KÿS>JÿR=IÿO;IÿL:HÿM:KÿJ8IÿMOÿP>OÿQ>PÿQ>PÿQ>PÿP>OÿP>PÿQ?PÿQ>OÿNQÿWBUÿZEWÿ\GXÿ]HYÿ^HYÿ^HXÿ]HXÿ]HWÿ\HWÿ\GVÿZFUÿYETÿZFSÿZFSÿYDQÿT@KÿM:DÿR>JÿU@MÿS>KÿQ=IÿO;HÿN:FÿM9EÿM9EÿL9DÿK8DÿJ7CÿM;IÿQ>OÿNKÿQ=IÿQ=IÿR>JÿS?JÿT?KÿQJÿM;GÿMKÿT@NÿS?LÿM9DÿQ=IÿS?LÿS?MÿT@NÿUAOÿVCQÿXETÿZFWÿYEVÿN6Dÿ:3@ÿ82?ÿ5/=ÿ1+7ÿ#(ÿÿÿÿ"$ÿ#"ÿ<4EÿJASÿD4@ÿ?+1ÿM6:ÿJ4<ÿ:(7ÿ3%5ÿ6)7ÿ6*7ÿ:.:ÿKÿUAPÿWCRÿVBQÿTAPÿSAOÿS@MÿS?MÿS@MÿR@LÿR?LÿQ>LÿO=KÿN;JÿL:HÿM:FÿM;FÿJ8BÿH6@ÿK9EÿO>KÿM;HÿL:FÿMJÿWBPÿYDSÿYESÿZFSÿVBMÿU@Jÿ[ERÿZFQÿYEQÿYDQÿ[FSÿ]HUÿ]IVÿ]IWÿ^JWÿ^JVÿ]IUÿ[GSÿYEQÿXCPÿXCOÿWCOÿUAMÿT@LÿT?KÿS?KÿR?JÿP;EÿN:DÿP=GÿUBNÿZFSÿYFSÿYGTÿUBMÿS?JÿWDPÿQ@IÿQ@JÿVDQÿ^JXÿaLXÿU@JÿUBOÿWDRÿWCRÿXDSÿWDRÿWDRÿWDSÿYEUÿXDTÿO8Gÿ<7Fÿ<6Eÿ:2@ÿ*$.ÿÿÿ!ÿ''ÿ) (ÿ&%ÿ%#ÿ+ 'ÿ0!'ÿ/!ÿ-%ÿ01ÿ5'9ÿE7EÿF8FÿN?OÿVFWÿZHZÿ[J[ÿZGXÿZFWÿ[GYÿZH[ÿYH[ÿLJÿ[FSÿZGRÿYFRÿZGTÿgQ]ÿuZeÿ_HQÿZHUÿ\JZÿ]IYÿ]HWÿZFTÿVCQÿTANÿS@MÿR>KÿE3@ÿ4)9ÿ"*ÿÿÿÿÿÿÿÿÿ&#ÿ-#+ÿ) *ÿ%&ÿ4,7ÿ1,6ÿ,(2ÿ,(2ÿ/*5ÿ0)4ÿ""ÿÿÿ!ÿ!ÿ ÿ ÿÿÿÿÿÿÿÿN?NÿP@OÿSCTÿXGYÿ]L^ÿcReÿgUjÿhXmÿiYoÿhXnÿfVkÿZHZÿ]L^ÿgVkÿhUjÿfSgÿfShÿhVkÿjXnÿjYoÿmZqÿgUjÿcPeÿfShÿmZqÿn[qÿn[qÿo\qÿp^sÿq^tÿq^uÿq^vÿq_vÿr`vÿsaxÿtczÿsd{ÿsd|ÿue~ÿwf€ÿxg‚ÿwg�ÿvf€ÿuf~ÿn^uÿRCTÿ;-8ÿ3&.ÿ8,5ÿ>2>ÿ<0>ÿSEXÿiYqÿsc|ÿsb}ÿtc~ÿrb}ÿqb|ÿrb}ÿqa{ÿq`zÿp^wÿo\uÿmZsÿm[sÿp^vÿp^wÿn^vÿl\sÿjYpÿkZqÿl[rÿm]tÿo^vÿo]vÿm[sÿhVmÿhVlÿjXoÿiXoÿk[sÿm\tÿn^xÿp`zÿo`zÿm\uÿiXmÿ^M_ÿ\L]ÿiYoÿj[rÿj\tÿm]wÿjYpÿ\J\ÿ\IZÿgWoÿm_{ÿm`{ÿk]vÿi[sÿhXpÿfVmÿeTjÿcQfÿbOcÿQ@OÿG6BÿF5Bÿ?0;ÿ(#ÿB2AÿUCXÿ\I`ÿ\I_ÿ]J^ÿ]I\ÿ]J[ÿ]J[ÿ\IZÿ[HYÿYGVÿXFTÿYETÿYEUÿYFUÿYGWÿYHWÿYGWÿXDTÿR?NÿXDUÿ\HYÿ[GXÿZGWÿZGWÿ[HWÿYFUÿYETÿZFVÿ\HXÿ]IYÿ\IXÿ[IYÿ]JZÿZFUÿR?LÿSANÿZGUÿ]IXÿ^JYÿ]IWÿ\HWÿ[HWÿ[HWÿ[GTÿ[GUÿRAOÿ@4Aÿ.%.ÿ.%+ÿ6+3ÿZO`ÿrcvÿr]gÿhPWÿ`ITÿS>IÿK8AÿS?JÿR=IÿRIÿT?JÿS>JÿS>KÿS>KÿS?KÿT?LÿT@MÿS?KÿS?KÿT?KÿT>JÿQ=HÿR=GÿS>HÿS>IÿQ>JÿQ?IÿQ@GÿI8>ÿG5>ÿS@LÿS@KÿSALÿNKÿO?LÿN?KÿJ;Eÿ:,6ÿ.&5ÿ!*ÿÿÿÿÿ"ÿ!ÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ ÿ +ÿ  ÿ ÿ + ÿÿ ÿ +ÿÿÿ ÿ ÿZNdÿ[Ofÿ\Ogÿ\Phÿ\Phÿ\Qgÿ\Qgÿ]Rhÿ^Siÿ]Reÿ[O`ÿRCRÿUGVÿZN`ÿZK_ÿ`OcÿjXmÿn\sÿo]tÿn]tÿn]sÿdSgÿ^M_ÿbQdÿiWmÿiWmÿiWlÿjXmÿlZnÿlYnÿmYoÿlYpÿlZpÿmZpÿn[qÿn]sÿn]tÿo]tÿo]uÿo^vÿo^wÿn^vÿo_vÿo^uÿkXnÿYHZÿ>1>ÿ,"*ÿ4*4ÿB6Cÿ;/=ÿJ=Nÿ`Qfÿl[sÿm[sÿm[sÿjZqÿiYpÿiXnÿhWmÿiXnÿiWnÿiVnÿiVnÿjWnÿkYpÿkYpÿkYpÿjYoÿhWmÿgUjÿgUkÿfVjÿfUjÿeUjÿdTiÿbShÿaShÿaSgÿ`Reÿ_Rcÿ_Rdÿ_Sfÿ`Uhÿ`Uiÿ\RdÿYO_ÿQGTÿNCPÿUJZÿUK\ÿVL]ÿXL^ÿVI[ÿRFUÿXHYÿ`PbÿaSgÿ^Qeÿ[NbÿYL`ÿYL_ÿZMaÿYL`ÿTHZÿRFXÿHPÿRDXÿPDVÿOBSÿREVÿTGXÿTGXÿSFWÿRFVÿQDSÿMAOÿK?KÿK?KÿK@LÿK@LÿJAKÿJALÿI@KÿE;FÿL@LÿPDPÿODQÿPEQÿQDQÿQEQÿREQÿSERÿUETÿVFTÿVFTÿVFSÿVFSÿWFSÿTCOÿR@NÿVDRÿ[IXÿ]JYÿ^IYÿ_IYÿ^IYÿ]IXÿ[HWÿZGUÿYFTÿTDSÿHÿH8EÿM;DÿC3:ÿK?JÿTHWÿVIYÿTERÿXHWÿTFSÿNCSÿNCSÿNAMÿ@5@ÿ<5Fÿ52Bÿ--8ÿ21<ÿ<7Dÿ<6Dÿ71?ÿ1,8ÿ+'0ÿ# 'ÿ!!ÿÿÿÿÿ ÿ + ÿ + ÿ ÿ  ÿ + + +ÿ + +ÿ + + +ÿ + +ÿ +ÿÿ ÿÿ ÿ ÿÿÿÿÿUNgÿRMdÿRMdÿRMcÿOK_ÿJFZÿGCTÿD@PÿA=Lÿ?:Gÿ=7Bÿ:08ÿ:0:ÿ92>ÿ:1>ÿJ=Kÿ_NaÿgUkÿhVkÿgVkÿfVkÿ\L^ÿSBRÿUETÿ_M`ÿZI[ÿXGXÿ^L]ÿdRdÿfSeÿfSgÿgTgÿeRfÿaN`ÿ]K\ÿeRfÿhUhÿdQdÿaNaÿdReÿeRfÿeSgÿeSgÿdReÿaM_ÿVDTÿ@3?ÿ0%.ÿ4*4ÿ?4Aÿ=1@ÿG9IÿWGYÿcPdÿeRgÿeRfÿcQdÿbPcÿaPbÿbPcÿeSfÿbQeÿ_Ocÿ^Obÿ\N`ÿXK]ÿVIYÿTHXÿSHWÿRHVÿOETÿMDRÿKCPÿIBNÿIANÿHANÿGAOÿFANÿEALÿD?IÿA=EÿAGÿA>Gÿ=9Eÿ85@ÿ74?ÿ41;ÿ61<ÿ93>ÿ40:ÿ)(.ÿ,+2ÿ52;ÿ95@ÿ75?ÿ42<ÿ95@ÿ;7Cÿ:7Bÿ97Aÿ97Aÿ85?ÿ42:ÿ107ÿ106ÿ117ÿ005ÿ014ÿ025ÿ/26ÿ./3ÿ337ÿ65:ÿ65;ÿ77<ÿ86=ÿ97=ÿ:8>ÿ<9@ÿ>:Bÿ@;Bÿ?;Bÿ?;BÿA;CÿB?Pÿ9GÿJEPÿNGSÿSIYÿPFWÿE;Jÿ4,6ÿ2(0ÿ3*1ÿ819ÿ95<ÿ938ÿA7:ÿ=48ÿ926ÿ?5<ÿM?Jÿ]J\ÿcOcÿeQeÿbN`ÿZGWÿUBQÿ]HZÿbNaÿ[HYÿM:Hÿ]JZÿbO_ÿcP`ÿePbÿdQbÿ`M]ÿVDSÿXFUÿXGUÿEIÿF8@ÿaHOÿzY]ÿS=>ÿ@<@ÿGFVÿLI_ÿDBTÿ<;Iÿ:Nÿ;7Eÿ30<ÿ-+4ÿ'&.ÿ "(ÿ#ÿ"ÿ!#ÿ#$ÿ%&ÿ&'ÿ#'(ÿ*)ÿ*)ÿ**ÿ*,ÿ +/ÿ42<ÿ/.5ÿ%$*ÿ!ÿÿÿÿÿÿÿÿ& ÿ,!(ÿ3(1ÿ=0<ÿK:Bÿ3,5ÿ0%/ÿ4)5ÿ9/<ÿB6FÿL?PÿGCPÿ:@Hÿ4Cÿ:@Eÿ;AGÿ=BHÿ=AHÿ59=ÿ+./ÿ#'%ÿ#&$ÿ!%#ÿ"%#ÿ"%$ÿ"%$ÿ!%$ÿ!%#ÿ %#ÿ%#ÿ$#ÿ$"ÿ$#ÿ$"ÿ#!ÿ#!ÿ$!ÿ#!ÿ# ÿ# ÿ#!ÿ$"ÿ$!ÿ$"ÿ$!ÿ$!ÿ# ÿ"ÿ"ÿ"ÿÿÿ"ÿ$!ÿ$!ÿ%"ÿ&"ÿ'#ÿ($ÿ(%ÿ)'ÿ+*ÿ-+ÿ-+ÿ,*ÿ+)ÿ--ÿ*47ÿ&26ÿ!13ÿ"23ÿ$45ÿ%46ÿ&47ÿ@?LÿHAQÿ4,7ÿ1(1ÿ3,4ÿ/07ÿ'47ÿ&57ÿ)59ÿ)69ÿ'47ÿ)26ÿ:8BÿWJ]ÿgUlÿkXoÿhTkÿ`McÿYEZÿ^J`ÿ^JaÿWCXÿP?PÿYFYÿ\H\ÿ^J^ÿ`K_ÿ_J_ÿ\H\ÿYDYÿYEYÿ[GZÿYFYÿS@RÿL;LÿL=MÿK=Kÿ>5<ÿ402ÿ20.ÿ0.(ÿ;43ÿOCHÿRFOÿMAMÿC8Fÿ70<ÿ-(1ÿ)!)ÿ(!-ÿ$+ÿ%ÿ(%-ÿ@;DÿFLÿ<;Gÿ48Aÿ/5<ÿ,49ÿ/28ÿ,*1ÿ,%-ÿ2+4ÿ<5AÿH@OÿOHWÿCCNÿ.9?ÿ+9<ÿ,9=ÿ+8<ÿ*7;ÿ)6:ÿ*59ÿ*38ÿ,48ÿ17=ÿ.4:ÿ&'ÿ#"ÿ" ÿ"ÿ"ÿ#ÿ#ÿ#ÿ ÿÿÿ#ÿ'!ÿ(!ÿ("ÿ($ÿ*'ÿ!-+ÿ'21ÿ-89ÿ4?@ÿ:CEÿ@GKÿAFKÿEJOÿPU\ÿW[dÿ^blÿdhsÿjlyÿqr€ÿvw…ÿ{x‰ÿ}|�ÿ€€’ÿƒ‚•ÿƒ‚•ÿokyÿULQÿC87ÿB78ÿ@56ÿB66ÿB77ÿA77ÿA56ÿ@55ÿ?54ÿ=33ÿ;22ÿ:11ÿ921ÿ931ÿ821ÿ721ÿ531ÿ210ÿ//-ÿ+-,ÿ),,ÿ*,-ÿ*+,ÿ'++ÿ"+)ÿ*(ÿ*(ÿ(&ÿ&"ÿ$ÿÿÿ"ÿ&"ÿ&"ÿ&!ÿ&"ÿ'"ÿ'#ÿ)%ÿ-+ÿ%23ÿ-79ÿ.8;ÿ-9:ÿ-99ÿ.9:ÿ-9;ÿ.;=ÿ.<=ÿ.<=ÿ.=>ÿ-<=ÿ-;>ÿCESÿHDUÿ,(2ÿ/*2ÿ0,4ÿ(*0ÿ!*.ÿ&04ÿ+29ÿ-3;ÿ-3<ÿ+2;ÿ-1<ÿ:5CÿMBSÿ\MbÿeSlÿiVpÿhVoÿdRkÿ`Mfÿ]Jbÿ\Jaÿ^Jbÿ_Jaÿ^I`ÿ]I`ÿ]H_ÿ\G^ÿ[F]ÿZF\ÿ[G\ÿ\H]ÿ\H^ÿ\H^ÿ\H]ÿYG[ÿUDXÿSDVÿK?Mÿ?7=ÿ41/ÿ20-ÿ20-ÿ=9;ÿC;AÿB8@ÿ@6<ÿ4*/ÿ,#*ÿ'%(ÿ#&%ÿ##!ÿ'-&ÿ((#ÿ%$ÿ$%ÿ(%"ÿ-('ÿ1//ÿ@;IÿLD]ÿQIcÿSLfÿUOjÿUPlÿJE^ÿ-'3ÿ+(3ÿ2/:ÿ32;ÿ03:ÿ26>ÿ:Lÿ99Dÿ67Aÿ37@ÿ,4;ÿ+6=ÿ)5<ÿ%4:ÿ$48ÿ%58ÿ$25ÿ"/1ÿ"./ÿ&/2ÿ,39ÿ39Aÿ7=Eÿ2LÿGGWÿ;BMÿ$01ÿ$ÿ$ÿ!ÿÿÿÿÿÿ!ÿ+(ÿ"/.ÿ.7:ÿ@FNÿRVaÿbesÿnpÿuw‡ÿ{|‹ÿ�€‘ÿ€}�ÿys€ÿ}x†ÿ�� ÿ“�¤ÿ”‘¤ÿ•’¦ÿ–“§ÿ—•¨ÿ™•©ÿš•ªÿš–«ÿš–¬ÿ›—¬ÿš—¬ÿ‚|ŠÿbW\ÿM=;ÿJ<:ÿI:8ÿJ:7ÿK<7ÿI<6ÿH:6ÿI;7ÿI:6ÿH95ÿG85ÿG85ÿF84ÿF94ÿF83ÿF83ÿE93ÿD71ÿD61ÿB61ÿ@51ÿ@52ÿ>42ÿ<31ÿ82/ÿ721ÿ;7:ÿA=CÿA>Dÿ536ÿÿÿÿ!,*ÿ-)ÿ' ÿ$ÿ&"ÿ&36ÿ5;Bÿ79@ÿ,04ÿ,36ÿ-7:ÿ-9;ÿ-;<ÿ-<=ÿ+;=ÿ,=?ÿ->@ÿ.=@ÿ-=?ÿ,=>ÿ,<>ÿ2=Cÿ08@ÿ!,/ÿ#.1ÿ$/1ÿ!./ÿ./ÿ#13ÿ%14ÿ'04ÿ'04ÿ%04ÿ%.3ÿ(.4ÿ63?ÿD;JÿSFZÿcRkÿiVqÿjVqÿhToÿeRlÿcPjÿdPjÿdOiÿdNhÿcNgÿaMeÿ`Ldÿ^Jbÿ]H_ÿ\H^ÿ^I_ÿ_I`ÿ_I`ÿ_I`ÿ_J`ÿ_Lbÿ_K`ÿ[I[ÿSETÿK?LÿC:Cÿ857ÿ10.ÿ/,*ÿ/,*ÿ..)ÿ-&%ÿ%ÿ ÿ#ÿÿ"*ÿ%&ÿ'&$ÿ-+,ÿ6/5ÿ@5<ÿIBJÿEBMÿ==KÿAASÿMKbÿTPmÿXTsÿQLiÿ:5Gÿ:5IÿB;NÿF@TÿBAVÿ;ÿ04;ÿ/4:ÿ.19ÿ04=ÿ67CÿICSÿ[ReÿcYpÿ\Rgÿ`Vjÿ`VkÿWK_ÿK>NÿRJ^ÿSL`ÿMFYÿE?QÿC?OÿF6CÿL;JÿO>MÿQ@OÿTBRÿXDVÿYFYÿ[G[ÿ]I]ÿ]J^ÿ^I^ÿ_J`ÿaKaÿbMbÿcNdÿdOfÿfOgÿfOgÿeOfÿdNeÿdNeÿcMeÿbMeÿbMeÿcNfÿcMfÿdNgÿbNeÿaNfÿ`OfÿVI]ÿMCTÿEANÿ:>Gÿ,8=ÿ&7:ÿ"58ÿ 57ÿ58ÿ 69ÿ#7:ÿ#7:ÿ"7:ÿ"7:ÿ!79ÿ56ÿ44ÿ55ÿ55ÿ46ÿ56ÿ 56ÿ"67ÿ#67ÿ"54ÿ"22ÿ!01ÿ //ÿ --ÿ,,ÿ!,.ÿ#,.ÿ)-3ÿ55@ÿAANÿ=@KÿABNÿ25=ÿ#*-ÿ/4<ÿ ÿÿÿÿÿ)&*ÿGBNÿebsÿsp‚ÿsoÿ„�•ÿ�ŠŸÿ’�¥ÿ–”©ÿš—«ÿœ™®ÿ˜“§ÿއ—ÿ‘Š›ÿ¤ µÿ¥ ¶ÿ¦ ¶ÿ¦ ¶ÿ¥¡¶ÿ¥¡µÿ¥¡µÿ¥¡µÿ¥¡µÿ¥ ´ÿ¤ ´ÿ£Ÿ²ÿ‡€‹ÿbVXÿJ:5ÿI:5ÿH:4ÿI:3ÿJ:2ÿJ;2ÿJ;3ÿJ;4ÿJ:3ÿJ:3ÿK:4ÿJ:4ÿJ:4ÿK;4ÿL;4ÿL;3ÿL;3ÿK:1ÿL:1ÿL:1ÿK:1ÿJ:1ÿL;3ÿL;4ÿK;4ÿI:5ÿI;9ÿM@DÿYLXÿMCNÿ.(,ÿÿ""ÿE>JÿQJYÿQK\ÿMHZÿ@>Jÿ47?ÿ35<ÿ028ÿ%,.ÿ"--ÿ"01ÿ"23ÿ#43ÿ$65ÿ#77ÿ#89ÿ$99ÿ$89ÿ$88ÿ$89ÿ#88ÿ 65ÿ32ÿ32ÿ43ÿ44ÿ43ÿ43ÿ 53ÿ 32ÿ!32ÿ!33ÿ!33ÿ!23ÿ#13ÿ&16ÿ*16ÿ98AÿNDVÿ^MdÿhVpÿlYuÿkYuÿiVrÿePkÿdOiÿdOhÿcNgÿbNfÿaLeÿ`Kcÿ^Iaÿ]H_ÿ]H_ÿ^H_ÿ_H_ÿ_I`ÿ`JaÿaLbÿcMcÿbNcÿ`Maÿ]K]ÿXHXÿOAOÿE;Fÿ>5<ÿ925ÿ622ÿ3*+ÿ/"&ÿ5.1ÿ>7<ÿA6@ÿGJÿ<4>ÿ)&+ÿ,'-ÿ9/5ÿ@;CÿA?Iÿ>?Iÿ;?Iÿ;?Mÿ@BUÿGJ`ÿJKcÿGE\ÿGE^ÿIBXÿNF_ÿQLhÿOLhÿLIbÿGE]ÿCBYÿ??Sÿ6:Jÿ+4<ÿ+27ÿ67=ÿC@KÿLGWÿMHXÿYSdÿaXmÿ\PeÿPDTÿ_VlÿbYqÿ[SiÿVNcÿXQfÿ^IZÿ`K^ÿ_K^ÿ]J]ÿ]I^ÿ]H^ÿ]I_ÿ`KaÿbMdÿcMdÿeNfÿfOgÿfPgÿfOfÿeOfÿeNgÿeNhÿeNhÿdNgÿdNgÿdMfÿeNhÿcNgÿ_Mdÿ\Lcÿ[LcÿZMaÿUI[ÿOFVÿJEUÿ55ÿQ@?ÿeTeÿXK\ÿ0)/ÿÿ& 'ÿ]Odÿk]uÿfZrÿ[RhÿIDRÿ319ÿ%%ÿ%"ÿ+'ÿ+(ÿ,)ÿ,)ÿ,)ÿ.*ÿ0,ÿ2/ÿ30ÿ31ÿ32ÿ43ÿ54ÿ64ÿ64ÿ66ÿ77ÿ78ÿ77ÿ76ÿ74ÿ64ÿ65ÿ!87ÿ"99ÿ"78ÿ 67ÿ54ÿ30ÿ!31ÿ07;ÿG@MÿZMbÿfVoÿlZvÿn[xÿhTpÿePjÿcNgÿaLeÿ`KdÿaKdÿ`Jcÿ_Jaÿ^I`ÿ]H^ÿ\G]ÿ]G^ÿ^H_ÿ_H`ÿ^H`ÿaKbÿbMcÿcNcÿbNbÿbMaÿ^K^ÿ[I]ÿVEVÿRCPÿQDQÿM=IÿQAOÿ[K[ÿbRbÿbPbÿbQcÿaQeÿK@Oÿ" $ÿÿ ÿ!!%ÿ0/8ÿ;9Cÿ68?ÿ+24ÿ)25ÿ1;Bÿ@Pÿ89Eÿ/2:ÿ)06ÿ/6=ÿ>AKÿKHVÿLDSÿF=JÿXQeÿ^Wlÿ[SgÿZRgÿaXoÿ[G\ÿ[G[ÿ]H]ÿ`KaÿcMdÿdNeÿeOfÿfPgÿgPgÿgPgÿhPgÿfOgÿfOgÿfOgÿeNgÿdNhÿcNhÿdNiÿdOiÿbNgÿ`MeÿbPgÿ\NcÿQHYÿGESÿBEQÿ9AIÿ.:@ÿ%6;ÿ!69ÿ7:ÿ8:ÿ9<ÿ!9<ÿ8:ÿ78ÿ89ÿ89ÿ78ÿ68ÿ79ÿ79ÿ78ÿ66ÿ56ÿ55ÿ43ÿ21ÿ0/ÿ/.ÿ,,ÿ+*ÿ*)ÿ)'ÿ(&ÿ'$ÿ'$ÿ&"ÿ%"ÿ%"ÿ&"ÿ'#ÿ'#ÿ%"ÿ$"ÿ%#ÿÿÿ0+5ÿF?Qÿ%'ÿÿ;0;ÿTFVÿ]N_ÿ^O`ÿeYhÿ…}�ÿ–Ž ÿŽ…”ÿŸ—¬ÿ¡š°ÿœ’§ÿ–‰›ÿ”†™ÿ–ˆ›ÿŸ–«ÿ›”§ÿ˜‘£ÿ¢›®ÿ›•§ÿœ—¨ÿ¢�¯ÿ¦¢´ÿ§£µÿ¨¤µÿ¨¥µÿ¨¤µÿ©¤µÿ©¥µÿ¥¡¯ÿ€x€ÿ]POÿPB=ÿH;3ÿI:2ÿK;3ÿK;3ÿJ;3ÿK;3ÿL;4ÿL;4ÿL;4ÿL;3ÿK;4ÿK;5ÿH83ÿJ94ÿK94ÿM;5ÿVE@ÿ]JEÿ`KGÿ]GCÿVA9ÿVB7ÿXB8ÿ[E9ÿ[G9ÿYF<ÿZJKÿj[oÿVK^ÿ"!ÿÿ!"ÿdWnÿl^vÿQHXÿ,-2ÿ&'ÿ(&ÿ*&ÿ*&ÿ+'ÿ+'ÿ,'ÿ,'ÿ,'ÿ,'ÿ-'ÿ/*ÿ0-ÿ1.ÿ2/ÿ31ÿ53ÿ53ÿ53ÿ55ÿ65ÿ66ÿ76ÿ75ÿ75ÿ75ÿ75ÿ"98ÿ%;;ÿ#9:ÿ77ÿ75ÿ64ÿ42ÿ30ÿ%43ÿ:=EÿRHYÿcSkÿlZwÿo]{ÿlYuÿgSnÿdOiÿaLfÿaLeÿaKdÿ`Jbÿ_Iaÿ^I`ÿ]H_ÿ]G^ÿ\F^ÿ\F^ÿ\F^ÿ\F^ÿ]G^ÿ]H_ÿ_I`ÿbLbÿcNcÿcMcÿ`J_ÿ_J_ÿbNcÿbNaÿkXnÿq^tÿs`tÿq_sÿk[oÿgVjÿSFUÿ4,4ÿ"#ÿ ÿÿÿÿ!#ÿ-.5ÿ24;ÿ15:ÿ07:ÿ3:?ÿ4=Dÿ68@ÿ=;HÿHG\ÿRPlÿURpÿVRqÿWSsÿWStÿVSsÿSQpÿOMiÿJG`ÿCBWÿ;>Oÿ49Gÿ-4@ÿ+2:ÿ,/5ÿ407ÿEBMÿOJYÿQL\ÿTOaÿ\UkÿdNdÿeOeÿfOfÿfOfÿgPgÿhQhÿiRiÿiRiÿiQhÿhPhÿgOgÿeNfÿeNhÿeOiÿdOjÿhTqÿgTpÿjWtÿgWrÿTL_ÿDDQÿ;@Kÿ4=Fÿ.:Aÿ(8>ÿ&:=ÿ#9<ÿ 9:ÿ8:ÿ7:ÿ8:ÿ89ÿ89ÿ89ÿ89ÿ68ÿ78ÿ78ÿ67ÿ67ÿ67ÿ57ÿ33ÿ0/ÿ.-ÿ+)ÿ*(ÿ)'ÿ)&ÿ(&ÿ'%ÿ&#ÿ%"ÿ%"ÿ&#ÿ'#ÿ($ÿ($ÿ'#ÿ$!ÿ$ ÿ%!ÿ'#ÿ$!ÿ ÿ%"ÿÿ ÿÿ/)1ÿ)!&ÿ*$ÿE7CÿYIXÿ^N[ÿcUbÿ†|Žÿ›“§ÿš‘£ÿ�ƒ“ÿ ˜¬ÿ£›±ÿ–ŒŸÿ‡y‡ÿƒt�ÿŠ}Œÿœ“¦ÿ›’¦ÿ“Š›ÿš‘¢ÿ£�®ÿ¤Ÿ±ÿ¥ ±ÿ¦¡²ÿ§¡³ÿ§¢³ÿ¨¤´ÿ©¥´ÿª¥µÿª¦µÿ§¢°ÿŠ‚ŠÿsfhÿeVUÿPB:ÿPA8ÿPA8ÿO?6ÿM=5ÿL=5ÿN=6ÿN>7ÿN>6ÿO>6ÿO?7ÿN>7ÿO?:ÿRA<ÿSA=ÿTB@ÿ\IIÿcLLÿdLKÿ_HEÿZD?ÿ[G@ÿ^HAÿ^I@ÿ^H?ÿ_IDÿbPVÿm\oÿVJ[ÿ ÿÿ!"ÿcUjÿhYnÿI?Lÿ()ÿ'%ÿ'$ÿ($ÿ*%ÿ*&ÿ+'ÿ+&ÿ,%ÿ,&ÿ-&ÿ+%ÿ+&ÿ+'ÿ,)ÿ.+ÿ1.ÿ30ÿ41ÿ31ÿ32ÿ42ÿ53ÿ54ÿ44ÿ54ÿ54ÿ54ÿ76ÿ87ÿ66ÿ65ÿ65ÿ54ÿ42ÿ40ÿ2/ÿ"32ÿ/6:ÿE@Mÿ]OeÿjYtÿm\xÿn\xÿlXtÿfRmÿaKeÿ`KdÿbLeÿbLdÿ`Jbÿ_Jbÿ^Iaÿ]H`ÿ\G`ÿ]F_ÿ\F^ÿ\F^ÿ[F^ÿ\G^ÿ]G_ÿ]H^ÿ_I_ÿ`I`ÿ`Iaÿ`Jaÿ^H^ÿ\H^ÿ`MbÿhVjÿn\oÿlYkÿgTfÿ^M]ÿPAPÿA4@ÿ.$*ÿ ÿÿÿÿÿÿ!#ÿ#')ÿ*-1ÿ56=ÿ:6=ÿ65:ÿ06=ÿ3;Fÿÿ!8:ÿ7:ÿ 69ÿ68ÿ79ÿ8:ÿ89ÿ79ÿ79ÿ79ÿ78ÿ77ÿ67ÿ66ÿ45ÿ33ÿ21ÿ21ÿ11ÿ0/ÿ.-ÿ+*ÿ*(ÿ)'ÿ'$ÿ'#ÿ'#ÿ($ÿ'%ÿ'$ÿ%"ÿ%!ÿ%!ÿ&"ÿ'#ÿ(#ÿ(#ÿ&"ÿ$!ÿ$ÿ&"ÿ($ÿ$ÿÿ!$$ÿÿ ÿÿ6,3ÿWHUÿ[JXÿ[IWÿUEPÿUGQÿ{p€ÿ˜Ž£ÿ£š¯ÿ�“¦ÿ“ˆ™ÿ¡™­ÿ¤œ±ÿŸ—«ÿ›’¥ÿš’¤ÿ�•§ÿ£›®ÿ¢š­ÿ—� ÿ�ˆ˜ÿ¥ž±ÿ¨¢´ÿ§¡³ÿ§¡²ÿ¨¢²ÿª£³ÿª¤´ÿ«¦µÿ«§µÿ«§µÿª¤³ÿ’Š”ÿvjmÿ_QLÿRD:ÿSD;ÿSD;ÿQA9ÿO@7ÿP@8ÿM>5ÿM=4ÿL=4ÿK;4ÿI93ÿG94ÿJ;9ÿQAAÿYHLÿ`NWÿeR[ÿhRZÿhRXÿgSXÿgTZÿfTYÿgW\ÿfTWÿcPOÿbMQÿ`MWÿmZmÿWHXÿÿ ÿ ÿeUgÿiWjÿGÿ43ÿ30ÿ30ÿ1/ÿ/-ÿ(14ÿ>;FÿWK`ÿeUoÿlZvÿn\xÿnZwÿjVrÿdOjÿbLgÿcMgÿdNhÿbLgÿaKfÿ_Jdÿ_Icÿ^Hbÿ_Ibÿ^H`ÿ]G_ÿ\G_ÿ]G^ÿ\G]ÿ^G^ÿ^G_ÿ^G_ÿ^G_ÿ^G^ÿ[E\ÿYD[ÿZF\ÿ\J^ÿaOcÿfTgÿgTfÿcQbÿZIYÿD3=ÿ?2<ÿ7/7ÿ%"'ÿÿ ÿ  ÿÿÿÿ!$&ÿ(&)ÿ.+1ÿ54<ÿ:2ÿOA7ÿN@8ÿJ<3ÿH90ÿL<4ÿK<3ÿK<3ÿJ;3ÿH93ÿE62ÿA31ÿD54ÿO>?ÿYHMÿ`NWÿ`MXÿaLVÿaLSÿcOTÿiTZÿiTZÿiV[ÿcQUÿ]KMÿZGLÿXEPÿlWjÿWGVÿÿ ÿÿaQbÿgTgÿI2<ÿ2)2ÿ#$ÿÿ ÿ ÿ + ÿÿ##ÿ-)0ÿ007ÿ,04ÿ)/2ÿ,26ÿ39Aÿ@Mÿ.7>ÿ'7;ÿ46ÿ12ÿ23ÿ35ÿ46ÿ56ÿ55ÿ44ÿ33ÿ22ÿ32ÿ33ÿ22ÿ21ÿ31ÿ20ÿ1/ÿ0.ÿ/,ÿ.*ÿ-)ÿ*&ÿ($ÿ&"ÿ$ ÿ$ÿ$ ÿ$!ÿ# ÿ"ÿ#ÿ#ÿ&!ÿ'#ÿ'"ÿ'"ÿ'#ÿ&"ÿ&"ÿ&"ÿ&!ÿ&"ÿ&"ÿ%!ÿ$ ÿ"ÿÿ$!ÿ#!ÿÿÿ# #ÿ5+3ÿ9-6ÿ<.7ÿI;Fÿ\M\ÿVGRÿYKVÿ`R^ÿk_mÿ”‡Ÿÿ›Ž§ÿ›�¦ÿ—ŠŸÿ��•ÿ™�¥ÿš�§ÿš�¦ÿ›‘§ÿœ’§ÿš�¥ÿ’ˆœÿ–Œ¡ÿž•«ÿ —­ÿž–«ÿŸ˜«ÿ ™¬ÿ¡š­ÿ£œ­ÿ¤œ¯ÿ¥ž¯ÿ¥Ÿ°ÿ¥ ²ÿ¦ ²ÿ¤ž°ÿŠ��ÿi^bÿTHHÿTIIÿRHFÿLA=ÿJ>;ÿJ>;ÿI<5ÿI:3ÿJ;4ÿJ<6ÿI;7ÿE86ÿB43ÿC42ÿL<:ÿUCCÿXFIÿXEIÿYEIÿYCEÿ[DBÿaIHÿbIHÿbIGÿ\EBÿT@>ÿQ>?ÿUBKÿkVgÿVFTÿÿ ÿÿ^M_ÿdQdÿI=Iÿ$,-ÿ'$ÿ'#ÿ)$ÿ+%ÿ,'ÿ-(ÿ-'ÿ,'ÿ,&ÿ+%ÿ*$ÿ+%ÿ,&ÿ+&ÿ+&ÿ*&ÿ+'ÿ+'ÿ+&ÿ,'ÿ-)ÿ.,ÿ0.ÿ20ÿ31ÿ42ÿ44ÿ44ÿ44ÿ43ÿ32ÿ22ÿ23ÿ23ÿ22ÿ55ÿ43ÿ22ÿ21ÿ10ÿ01ÿ-5:ÿE@MÿYKaÿeSnÿkXuÿo\xÿn[wÿkXsÿhUpÿgQmÿfPlÿdNhÿcMfÿfNiÿdMhÿbLfÿaLeÿaLeÿ`Kdÿ_Jbÿ^Iaÿ_Ibÿ_Iaÿ^Haÿ^I`ÿ_Iaÿ`Haÿ_Haÿ]H`ÿZE\ÿXCZÿYE[ÿ\H^ÿ]I^ÿVDTÿ]J\ÿbOaÿ`M^ÿXETÿO>KÿB5@ÿ5+5ÿ)"*ÿÿÿÿÿÿÿ"ÿ()-ÿ./6ÿ03:ÿ15;ÿ16<ÿ:ÿZHFÿbMMÿdNMÿdPOÿgVXÿm]aÿm\`ÿm[^ÿm\^ÿl]^ÿk[^ÿgU^ÿnZiÿUEQÿÿ ÿ ÿbQcÿeSeÿFGÿ/8?ÿ(69ÿ&69ÿ!47ÿ45ÿ56ÿ 47ÿ"48ÿ 46ÿ34ÿ44ÿ33ÿ22ÿ10ÿ0.ÿ0-ÿ/-ÿ.,ÿ-+ÿ,*ÿ,*ÿ+)ÿ+)ÿ+)ÿ+(ÿ*(ÿ)(ÿ(&ÿ'%ÿ'$ÿ($ÿ'"ÿ& ÿ% ÿ&!ÿ'"ÿ%!ÿ#ÿ"ÿ#ÿ"ÿ"ÿ"ÿ#ÿ$ÿ%ÿ' ÿ'!ÿ("ÿ("ÿ&!ÿ&!ÿ&"ÿ&!ÿ#ÿÿÿ)%*ÿ*&+ÿ ÿÿ%!ÿUDQÿgSbÿcP^ÿTDOÿJ=@ÿUHKÿ�rƒÿ›Š£ÿ—‡Ÿÿ—‡Ÿÿ�~•ÿk~ÿpZfÿoXdÿu`oÿ‹|‘ÿ•ˆ ÿ•‰¡ÿ”‰Ÿÿ•Š¡ÿ”‰ ÿ–Š¡ÿ—Œ£ÿ—�¤ÿ˜Œ¥ÿ˜Ž¥ÿ˜�¦ÿ˜�§ÿ˜�§ÿ™‘©ÿ™’­ÿ™“°ÿ™”±ÿš•²ÿš•³ÿ™–³ÿ˜–µÿ˜—·ÿ˜˜¸ÿ’‘¯ÿsm�ÿYNTÿVMOÿYQTÿMCCÿWLQÿWLPÿNB@ÿI=8ÿM?;ÿL=9ÿPCAÿ\NOÿjX]ÿycjÿzbhÿ‚oyÿ“‡–ÿ š­ÿ š®ÿ¢›­ÿ£›«ÿ¤œ«ÿ¢™§ÿŠ|‹ÿyevÿUERÿÿ ÿÿeTfÿiWjÿK@Lÿ*14ÿ*'ÿ($ÿ)%ÿ*%ÿ+&ÿ+&ÿ+&ÿ,%ÿ,$ÿ+#ÿ*$ÿ*#ÿ+$ÿ+$ÿ+#ÿ,#ÿ,$ÿ+$ÿ*$ÿ)$ÿ*$ÿ*&ÿ*&ÿ+'ÿ,)ÿ-+ÿ.-ÿ00ÿ22ÿ24ÿ23ÿ24ÿ25ÿ24ÿ24ÿ"57ÿ 67ÿ46ÿ34ÿ34ÿ23ÿ12ÿ11ÿ12ÿ,3:ÿC?LÿWL`ÿdVoÿjZwÿn[zÿn[yÿhUpÿM=Pÿ>.=ÿ[F_ÿcMhÿdNhÿbLfÿaKdÿ`Jdÿ_Ibÿ_Ibÿ_Ibÿ^Iaÿ]H`ÿ]G_ÿ]F^ÿ\E]ÿ\E]ÿ[E]ÿ[E]ÿ[E]ÿ[D\ÿZC[ÿXBZÿVAYÿT@WÿS@UÿVDXÿ^L`ÿ`M`ÿ`L^ÿ^J[ÿ\HWÿWDSÿP>KÿC3>ÿ2&.ÿ$"ÿÿÿÿÿ ÿÿÿ!!%ÿ*'-ÿ91;ÿMBQÿ]PdÿfXmÿjZqÿ\MbÿA3@ÿVJ]ÿdWnÿdWqÿ]RoÿYQnÿ=ÿO>9ÿRA;ÿYKIÿshoÿŸ–ªÿ© µÿ©¡µÿ©¡³ÿ© °ÿª °ÿ« ¯ÿ¬¡°ÿ¥™§ÿ��ŒÿygtÿmZhÿM?Iÿÿ ÿÿVFTÿdQbÿTESÿ/14ÿ*&ÿ)$ÿ)$ÿ)$ÿ*&ÿ+&ÿ*$ÿ*#ÿ*#ÿ*"ÿ)"ÿ)"ÿ*"ÿ)"ÿ(!ÿ)!ÿ+#ÿ+%ÿ+%ÿ+&ÿ+&ÿ*&ÿ*&ÿ+'ÿ-(ÿ-)ÿ-*ÿ.,ÿ.-ÿ..ÿ..ÿ/0ÿ02ÿ12ÿ13ÿ24ÿ35ÿ34ÿ24ÿ23ÿ01ÿ11ÿ11ÿ00ÿ/.ÿ.-ÿ /0ÿ15>ÿD>OÿVI^ÿdSmÿhVqÿK.7ÿIÿD88ÿL>AÿVFJÿQA?ÿUC>ÿVD>ÿVFAÿi]aÿ˜�žÿ¤™¬ÿ¥š¬ÿ¥š«ÿ¥šªÿ¦›«ÿ¦šªÿ§œ¬ÿ˜�œÿn_iÿdP^ÿeP_ÿKÿ"47ÿ01ÿ00ÿ00ÿ0/ÿ.-ÿ+,ÿ%/2ÿ;9DÿREXÿcQkÿM?Sÿ=1BÿcRnÿn[wÿkWrÿdOhÿ]F^ÿ[C[ÿaKeÿbMfÿaKdÿ`Ibÿ^Iaÿ]I`ÿ]I`ÿ]G_ÿ[F]ÿZE[ÿ\F\ÿ]F]ÿ]F]ÿ]F\ÿ\F\ÿ[E\ÿZE\ÿ[F]ÿ\F]ÿ[E\ÿZDZÿXBYÿU@VÿQ=RÿP=QÿWFYÿ[H\ÿXDUÿXETÿ`M]ÿaN]ÿ_L\ÿYGVÿO?MÿE7Cÿ7-6ÿ)"*ÿÿÿ ÿÿÿÿÿ5'/ÿA7BÿA6DÿF;LÿNBUÿPDXÿ22ÿ11ÿ//ÿ..ÿ,,ÿ,*ÿ+)ÿ*(ÿ*(ÿ)'ÿ(&ÿ(%ÿ($ÿ'$ÿ&#ÿ%"ÿ$!ÿ$!ÿ# ÿ# ÿ"ÿ"ÿ"ÿ!ÿ"ÿ# ÿ# ÿ# ÿ#ÿ$"ÿ(.-ÿSDGÿG;>ÿ"ÿ!ÿ"ÿ"ÿ"ÿ#ÿ$ÿ#ÿ"ÿ"ÿ"ÿ#ÿ#ÿ"ÿ!ÿ ÿÿÿÿ!ÿ"ÿÿÿ ÿ=3>ÿK>Lÿ5+2ÿ0&+ÿ0',ÿE8BÿWGTÿZHTÿM>GÿWLZÿUJVÿj^sÿ�„¦ÿ’†¨ÿ‘†¨ÿ�†©ÿ�…ªÿ�…¬ÿŒ…®ÿ‹…®ÿ‹†¯ÿ‹‡±ÿЇ³ÿ†„±ÿ‚¬ÿ…„³ÿ‰‹¼ÿˆ‹¾ÿ‰‹Áÿ‰ŽÃÿ‰�ÄÿŠ�ÅÿŠ‘Çÿ‹’Êÿ‹“Ìÿ‹”ÌÿŒ”Ìÿ�–ÌÿŽ—ÏÿŽ™Ðÿ�™Ðÿ‘™Ïÿ’™Ìÿ’˜Êÿ’—Èÿ’—Çÿ’—Çÿ‘•ÅÿŒ�¾ÿ’”Âÿ}zœÿdZhÿrh{ÿf]lÿLAGÿ?10ÿD56ÿG86ÿP@<ÿXGAÿZHBÿXFAÿgX]ÿ”‡šÿ •©ÿ¢—«ÿ£—ªÿ£—©ÿ¤˜©ÿ£—©ÿ¤˜ªÿš�Ÿÿs�ÿp`oÿhUeÿM>Iÿÿÿ ÿTETÿaPbÿTEUÿ538ÿ($ÿ&ÿ'"ÿ($ÿ*%ÿ*%ÿ)$ÿ)$ÿ)#ÿ*"ÿ)!ÿ)!ÿ)"ÿ*#ÿ+$ÿ+#ÿ+&ÿ,'ÿ,(ÿ,(ÿ+'ÿ+'ÿ,(ÿ,(ÿ,(ÿ+'ÿ+'ÿ+'ÿ,(ÿ,)ÿ-*ÿ-*ÿ.,ÿ.-ÿ0/ÿ11ÿ11ÿ11ÿ01ÿ&59ÿ@GOÿ/;Aÿ02ÿ/0ÿ./ÿ.-ÿ-,ÿ,+ÿ+*ÿ*+ÿ33<ÿOCVÿG:KÿF9JÿeTnÿkYsÿn[wÿeSkÿR@RÿH4Dÿ[G_ÿ_Jcÿ\G_ÿ\G_ÿ`Jcÿ^Iaÿ\H_ÿYDZÿS=SÿO:NÿT@Sÿ\F[ÿ^H^ÿ^G]ÿ^G]ÿ\F]ÿ[F]ÿ\F]ÿ\F]ÿ\F]ÿ[E\ÿ[E\ÿ[E\ÿZD[ÿXBYÿS>TÿQ>SÿXEXÿ`M`ÿcObÿeQbÿiSeÿjTgÿhSeÿbN_ÿYFVÿL=Lÿ?5Aÿ3+6ÿ'"*ÿ #ÿÿÿ%"ÿ-!(ÿ&!(ÿ#ÿ#ÿ)(1ÿ94Aÿ,*ÿ*)ÿ('ÿ('ÿ('ÿ(&ÿ(&ÿ(%ÿ(%ÿ'$ÿ'$ÿ'#ÿ&#ÿ%"ÿ%"ÿ# ÿ"ÿ"ÿ" ÿ"ÿ# ÿ"ÿ"ÿ"ÿ"ÿ#ÿ"ÿ"ÿ"ÿ&$ÿ477ÿWFLÿJIÿ`MZÿ]HUÿ]IVÿZHSÿQ@IÿK<@ÿ]P[ÿ€v’ÿ…z—ÿ„y–ÿ“аÿ’‰°ÿ‘‡­ÿ�…¬ÿ�…­ÿ�†±ÿ‹‡´ÿ‹ˆ¶ÿЉ¸ÿ‰Š»ÿˆ‹½ÿƒ†¹ÿ{~¯ÿ�†¹ÿŠ�Æÿ‰ŽÄÿˆ�Åÿˆ�Æÿˆ�Èÿ‡‘Éÿ‡’Ëÿ‡’Îÿˆ”Ïÿ‰”ÏÿŠ”ÏÿŠ•Îÿ‹•Îÿ‹•ÎÿŒ–Îÿ�—Îÿ�—Ìÿ�–Éÿ�•Çÿ�”Æÿ�”Æÿ�”Åÿ�”Åÿ“–Æÿ„ƒ©ÿnf{ÿndtÿ|v�ÿ^UbÿH95ÿN?>ÿP@?ÿQA?ÿTE@ÿ\JGÿbMLÿnZaÿ“ƒ—ÿŸ”«ÿ¡˜¯ÿ¡—¬ÿ¡–«ÿ¢–ªÿ¢–ªÿ¢–ªÿ¡•©ÿ˜ŒŸÿ€o€ÿlYiÿK?Iÿÿÿ#ÿ^M[ÿeTdÿPDQÿ83:ÿ)&ÿ'"ÿ(#ÿ($ÿ*$ÿ*$ÿ*%ÿ*$ÿ*#ÿ)"ÿ)"ÿ)#ÿ)$ÿ*%ÿ+$ÿ*$ÿ*%ÿ+&ÿ+&ÿ,'ÿ+'ÿ,(ÿ,'ÿ+&ÿ)%ÿ)$ÿ)%ÿ)%ÿ*%ÿ*'ÿ+'ÿ+)ÿ*)ÿ+)ÿ,+ÿ-.ÿ.-ÿ/.ÿ//ÿ01ÿ"36ÿ14ÿ11ÿ10ÿ//ÿ.-ÿ,+ÿ+)ÿ))ÿ()ÿ'+ÿ/0:ÿ51=ÿE:Kÿ]MeÿfSmÿiVqÿWF\ÿ5&0ÿ1$/ÿXH^ÿQAUÿB3CÿK:Lÿ`Jbÿ\G^ÿXDZÿG5Fÿ3 )ÿ5 'ÿ5%1ÿS?Rÿ_I_ÿ_I`ÿ^G_ÿ]G^ÿ]H_ÿ]H_ÿ^H_ÿ^H_ÿ]F^ÿ]F]ÿ]F]ÿ]F]ÿ\F]ÿ[F\ÿZD[ÿXCXÿWBVÿWCWÿ[GZÿePeÿmYnÿq\qÿoZnÿmXmÿjVjÿeReÿ^L_ÿUHYÿL@PÿE9GÿD7Eÿ?2?ÿ/!(ÿ!ÿÿÿÿÿ#!ÿ#!ÿ$"ÿ%"ÿ%#ÿ%"ÿ$!ÿ$!ÿ$!ÿ$ ÿ$ ÿ# ÿ# ÿ$ ÿ$!ÿ#ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ"ÿ%!ÿ#,*ÿ;57ÿ:57ÿ'-+ÿ"ÿ"ÿ!ÿ ÿ!ÿ ÿ!ÿ!ÿ ÿ ÿ ÿ!ÿ!ÿ"ÿ#ÿ"ÿÿÿ:5AÿD?Mÿ" #ÿ ÿ ÿ ÿF:DÿgTcÿjUeÿ`LZÿYJWÿQEMÿK@AÿnfyÿŠ‚¦ÿ‘‰°ÿ�ˆ¯ÿމ²ÿ�w—ÿxi�ÿucyÿsaxÿtgƒÿ†‚¯ÿ‹‹¼ÿŠ�ÀÿŠ�ÂÿŠŽÃÿˆ�Ãÿ„‹Àÿ†�ÄÿŠ�ÈÿŠ�Çÿ‰�Çÿ‰‘Êÿ‰“Íÿˆ”Ïÿ‡”Ðÿˆ”Òÿˆ•Ñÿ‰”Ïÿ‰”ÍÿŠ”ÌÿŠ•Ìÿ‹”Ìÿ‹”ËÿŒ”Ëÿ�•Ëÿ�•ÉÿŽ•Èÿ�•Èÿ�•Çÿ�•Æÿ‘–Æÿ’—Çÿ‹Œ·ÿws�ÿe[iÿ~w“ÿeZhÿUDBÿYIJÿVEDÿWHIÿWIJÿcQTÿoW[ÿrW[ÿ~enÿŽ{�ÿ›Ž¥ÿ¡—¯ÿ¡•«ÿ¡•«ÿ¡•ªÿ¡•ªÿ ”ªÿš�¡ÿ€n€ÿgWfÿFÿ)'ÿ'"ÿ)#ÿ)$ÿ*&ÿ+'ÿ+&ÿ*$ÿ)"ÿ)"ÿ)"ÿ("ÿ)#ÿ)%ÿ*%ÿ*%ÿ*%ÿ*$ÿ*$ÿ)$ÿ)$ÿ*%ÿ*%ÿ)%ÿ(#ÿ(#ÿ'"ÿ(#ÿ($ÿ(#ÿ(#ÿ($ÿ(%ÿ)&ÿ*'ÿ*'ÿ*(ÿ*(ÿ+)ÿ+,ÿ,-ÿ,-ÿ,-ÿ,-ÿ+,ÿ)*ÿ&'ÿ&&ÿ()ÿ+/ÿ).:ÿ+0=ÿ(-:ÿ,-<ÿ93FÿE9LÿWI_ÿVG]ÿC5FÿÿNCSÿJ=HÿC5>ÿC4=ÿI9CÿUCPÿ\JXÿM>DÿODLÿwq“ÿ†€©ÿrkˆÿŒ…¯ÿ�‹¸ÿ�‹¸ÿ�жÿŽŠ´ÿŒ‡±ÿ…�§ÿ‚~¢ÿ…�§ÿЇ±ÿŒ‹¸ÿŒŒ»ÿ‚€­ÿ~{¨ÿŠ‹¼ÿŒ�ÂÿŒ‘ÄÿŒ‘Äÿ‹�ÃÿŠ�ÃÿŠ‘ÅÿŒ“ÈÿŒ•Ëÿ�•Íÿ�•Ìÿ�•ÌÿŽ–ÌÿŽ–Ëÿ�—Ëÿ�—Ìÿ�˜Íÿ�˜Íÿ�˜Íÿ‘˜Ìÿ‘˜Ìÿ‘˜Ìÿ‘˜Ëÿ‘˜Êÿ’—Éÿ“˜Éÿ“˜Éÿ“˜Éÿ’–Åÿ„ƒªÿcXhÿWHMÿVIPÿ[NVÿ[MQÿTEBÿRB=ÿQA;ÿUC>ÿVD>ÿ[KJÿvkyÿ–�§ÿ¡—´ÿ ”¯ÿ ”®ÿ ”¬ÿ “¬ÿ ’ªÿœŽ¥ÿ�€–ÿucvÿeScÿF:Eÿÿ +ÿ#!ÿYHWÿjVhÿ_M^ÿ<3<ÿ*)ÿ)$ÿ*%ÿ+&ÿ+'ÿ+&ÿ*$ÿ)"ÿ(!ÿ(!ÿ("ÿ("ÿ)#ÿ)$ÿ*%ÿ*$ÿ)"ÿ)"ÿ)#ÿ)#ÿ(#ÿ)$ÿ*%ÿ)$ÿ'#ÿ'"ÿ'"ÿ(#ÿ($ÿ)$ÿ($ÿ)%ÿ*&ÿ*'ÿ*'ÿ)&ÿ*'ÿ*'ÿ)(ÿ))ÿ*)ÿ**ÿ*+ÿ,-ÿ.0ÿ/2ÿ$4:ÿ#37ÿ..ÿ,,ÿ,/ÿ-2ÿ!,3ÿ#+4ÿ'*7ÿ.-:ÿEQÿC6FÿE6IÿbOkÿJ;Pÿ*!+ÿ8-;ÿJ5=ÿ  ÿ ÿÿ_M\ÿp[mÿ`N^ÿ:09ÿ!,+ÿ*%ÿ*%ÿ*%ÿ*$ÿ*$ÿ*%ÿ)#ÿ(!ÿ'!ÿ'"ÿ(#ÿ)#ÿ)#ÿ*#ÿ)#ÿ' ÿ'ÿ(!ÿ("ÿ)#ÿ)#ÿ)#ÿ'#ÿ&"ÿ'#ÿ(#ÿ(#ÿ)#ÿ(#ÿ($ÿ)%ÿ*%ÿ+&ÿ*&ÿ(%ÿ)&ÿ*'ÿ*'ÿ)'ÿ)'ÿ)'ÿ*)ÿ,,ÿ./ÿ04ÿ4>Hÿ0ÿD8JÿYH^ÿD6Hÿ2'3ÿE8JÿVG^ÿ/$0ÿ,+ÿ*/ÿ$ÿ ÿ0"-ÿOÿL=QÿZIbÿ=/>ÿ9*5ÿ<+@ÿ7#>ÿ,+ÿ6'3ÿQ?Tÿ^IbÿaKcÿaKcÿ`Jbÿ_Iaÿ_Iaÿ_Iaÿ_Iaÿ`JaÿaJbÿaJaÿ`I`ÿ_H_ÿ_G_ÿ_H_ÿ`I_ÿ`H`ÿ`H`ÿ`G_ÿ_H_ÿ_H_ÿ`H`ÿ_H_ÿ]H^ÿ\G]ÿ[E]ÿYC[ÿVAYÿP=TÿO>SÿUFZÿXI]ÿSBTÿT@QÿXDUÿZFWÿYDUÿU?Pÿÿÿ ÿ ÿÿÿÿ ÿ ÿ ÿÿÿ ÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿ  ÿ ÿOCQÿXK[ÿ(!&ÿÿÿÿ>3;ÿaP^ÿdP_ÿTCNÿE8AÿTLaÿhc€ÿSK[ÿ{t—ÿŽˆ²ÿ�Š´ÿ�Š´ÿ�‹µÿŒ‰µÿ�ˆµÿ�ˆµÿ�‰µÿŽŠ´ÿ�‹µÿ�Œ·ÿ�еÿˆ…¯ÿŒˆ²ÿ‘�·ÿ“�¹ÿ“�¹ÿ’�¹ÿ’�¹ÿ“�ºÿ“�»ÿ“�»ÿ’�¼ÿ’‘½ÿ’’¾ÿ’’¿ÿ’“Áÿ“”Âÿ••Äÿ–•Ãÿ–•Ãÿ–•Äÿ––Åÿ–˜Èÿ–™Èÿ–™Éÿ–™Éÿ—˜Çÿ——Äÿ—–Áÿ—•¾ÿ—”½ÿ—”½ÿ–“½ÿ–”½ÿ—”½ÿ”�µÿ„{šÿbVeÿk`qÿeYeÿVFEÿYHHÿTDAÿTEBÿRCAÿO@?ÿQB?ÿYKLÿ‘…œÿ£—²ÿ ”­ÿ ”¬ÿ “¬ÿ “¬ÿ–‹¡ÿt‡ÿcWeÿlYiÿPCNÿ)%(ÿ +ÿ ÿÿPAMÿmYjÿiUeÿ;18ÿ#+*ÿ("ÿ'!ÿ(#ÿ)#ÿ(#ÿ(!ÿ'!ÿ' ÿ( ÿ("ÿ(#ÿ'#ÿ'"ÿ'"ÿ("ÿ)#ÿ("ÿ'!ÿ("ÿ'ÿ' ÿ'"ÿ'"ÿ'"ÿ(#ÿ'"ÿ'!ÿ&!ÿ& ÿ'"ÿ(#ÿ*%ÿ*%ÿ*%ÿ($ÿ(#ÿ(#ÿ($ÿ(%ÿ*(ÿ*'ÿ)&ÿ)'ÿ(&ÿ&&ÿ&'ÿ''ÿ)(ÿ++ÿ,-ÿ,-ÿ,.ÿ+-ÿ+,ÿ+,ÿ*+ÿ'(ÿ&(ÿ'+0ÿ51<ÿ>6DÿD8HÿPAUÿZJaÿH8JÿK;OÿK:RÿC/Jÿ?+@ÿH7HÿP=QÿWBYÿ[F]ÿ]G_ÿ^H`ÿ^H`ÿ^H_ÿ^H_ÿ_Iaÿ`JbÿaJbÿaKbÿaJaÿ`I`ÿ_H_ÿ^H_ÿ^H_ÿ_H`ÿ`H`ÿ`H`ÿ_H_ÿ_H^ÿ_H^ÿ_G^ÿ_G^ÿ^G^ÿ]F^ÿ\E]ÿYC[ÿV?XÿR=TÿO=SÿO>SÿP@TÿVEXÿYFYÿ\H[ÿ^H[ÿ]FXÿÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿ ÿ#ÿ ÿÿ ÿÿPCPÿdRcÿSALÿMÿO@9ÿM>8ÿN>9ÿO@8ÿUEAÿŽ�•ÿ¢•­ÿ¡“ªÿ¡“©ÿ¡“©ÿ “§ÿž‘¤ÿ”ˆšÿƒu†ÿr^oÿM@Jÿ$"$ÿ ÿ ÿÿQ@KÿnXhÿhTcÿ8.5ÿ#**ÿ'$ÿ'"ÿ)$ÿ)%ÿ(#ÿ' ÿ&ÿ'ÿ( ÿ("ÿ($ÿ($ÿ'#ÿ($ÿ(#ÿ(#ÿ"ÿ ÿ&!ÿ' ÿ(!ÿ("ÿ(#ÿ(#ÿ(#ÿ'!ÿ& ÿ&ÿ& ÿ'"ÿ)$ÿ)%ÿ)$ÿ(#ÿ'"ÿ% ÿ&"ÿ(%ÿ)'ÿ*)ÿ*(ÿ*(ÿ*'ÿ)'ÿ)(ÿ((ÿ('ÿ)'ÿ*)ÿ+*ÿ++ÿ+-ÿ,-ÿ,-ÿ,.ÿ,-ÿ++ÿ('ÿ$#ÿ&)ÿ.,5ÿ?6FÿN@UÿWF[ÿRAVÿWE]ÿVD]ÿP=UÿPSÿR@UÿQ?TÿRAUÿWFZÿ]K_ÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿ ÿ!ÿ!ÿ ÿÿÿÿÿÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿÿÿÿÿÿ"ÿ#&&ÿ##$ÿ +ÿ ÿ ÿD6?ÿbO\ÿjTcÿeP]ÿcOYÿaMWÿXGOÿH:@ÿC67ÿD75ÿpi†ÿŽˆ´ÿ‘Œ¸ÿ�Š´ÿ‘Š´ÿ‘‰²ÿ�‡®ÿކ­ÿŽ…«ÿ�…«ÿ�ˆ¯ÿ’‹´ÿ‘‹´ÿ‘‹²ÿ’‹²ÿ“�³ÿŽˆ¬ÿƒ|žÿŠƒ§ÿ’Œ³ÿ•�¶ÿ•�µÿ–�¶ÿ–‘¶ÿ–’·ÿ–’¹ÿ–’¹ÿ–’¸ÿ—’·ÿ—‘¸ÿ–’¹ÿ•“ºÿ•“¼ÿ–”½ÿ–”½ÿ—“½ÿ–“¼ÿ–“»ÿ•‘ºÿ”‘ºÿ”’ºÿ•’»ÿ•’»ÿ”’»ÿ”‘¹ÿ•�·ÿ•�µÿ–�¶ÿ–�¶ÿ•�¶ÿ–�µÿ–�²ÿ�…¤ÿj^nÿdV_ÿbRXÿ[KKÿ\KKÿaOQÿcPRÿgQUÿhRVÿ`LKÿWFBÿŠ|‹ÿ ’¦ÿ¡“¨ÿ¡’¦ÿ¢“¦ÿ¡“¤ÿ¡“¤ÿž�¡ÿ’�“ÿu`pÿM?Hÿ$!#ÿ ÿ ÿÿMRÿVE\ÿ[Iaÿ]Kcÿ]Jbÿ]IaÿbLfÿbMgÿ`Ldÿ^Iaÿ]G^ÿ_H`ÿaKcÿcMeÿdNeÿdMfÿcMeÿcLeÿcLdÿbLdÿbLdÿcLdÿbLdÿbKcÿaJaÿaJaÿaIaÿaIaÿ`H`ÿ`G_ÿ`H^ÿ_G^ÿ_G^ÿ^F]ÿ^F]ÿ^F]ÿ]E\ÿ\E\ÿ\E\ÿ[D[ÿXAXÿR>SÿN<<ÿ044ÿ+)ÿ(%ÿ'#ÿ&"ÿ'#ÿ'$ÿ(%ÿ)&ÿ(%ÿ&#ÿ&#ÿ&$ÿ'%ÿ&$ÿ%#ÿ&$ÿ(&ÿ('ÿ)(ÿ+)ÿ+*ÿ**ÿ((ÿ$%ÿ#%ÿ()2ÿ>6FÿN?UÿYG`ÿ`MfÿcQiÿeQkÿfPlÿgQmÿkVpÿjUmÿaLcÿ_IaÿaJcÿdMfÿeOgÿfPhÿeOhÿeOgÿeNfÿdMeÿdMeÿdMfÿdNfÿdMeÿdKcÿdKcÿcLdÿbKcÿbIaÿaH`ÿaH`ÿ`H_ÿ`H`ÿ`H_ÿ_G^ÿ_F^ÿ^F^ÿ^F]ÿ]F\ÿ]E]ÿ]F^ÿ]F]ÿ[D[ÿWAWÿQGÿYIUÿOAKÿ>25ÿKBJÿqi„ÿ�†®ÿ…~¡ÿˆ�¦ÿ�ˆ±ÿ�Œ¶ÿ�Œµÿ�Œ¶ÿŽŠ³ÿ}wšÿrj‡ÿ{u”ÿqh„ÿ€z�ÿƒ}£ÿ„}¢ÿ‰ƒ©ÿwp�ÿ„~¡ÿ‰‚¦ÿ‰ƒ¦ÿ‘Œ±ÿ’‹±ÿ“‹±ÿ“Œ²ÿ“޳ÿ”�²ÿ”�²ÿ•Œ²ÿ•�²ÿ–޳ÿ–Ž´ÿ•Œ³ÿ”Œ²ÿ”Œ±ÿ”Œ°ÿ”�°ÿ”�±ÿ“�²ÿ’Œ²ÿ’Œ±ÿ”�²ÿ•޲ÿ–޲ÿ•޲ÿ”�±ÿ”�²ÿ”Ž´ÿ”޶ÿ”�·ÿ”�·ÿ”�¶ÿ”�¶ÿ–‘¸ÿ�‰¯ÿ‡€¤ÿ‰ƒ©ÿ“޵ÿpg~ÿ[MUÿ[OWÿPBBÿXHKÿQ@>ÿM;4ÿN<6ÿN=7ÿR@<ÿl]cÿ“„—ÿ™Œ¥ÿzrŒÿ˜Œ¢ÿ¢“¨ÿ¡’§ÿ”‡›ÿyl€ÿeWjÿMCQÿ/*0ÿ + ÿÿ:=PÿHHÿR@IÿSBLÿRALÿLÿQAAÿK<8ÿJ;5ÿM>8ÿO@9ÿRA;ÿ_PQÿ�sƒÿ‰~•ÿmgÿpjÿum‚ÿum‚ÿjezÿXTkÿJF\ÿ>;Nÿ-1Cÿ)=ÿ",?ÿ7:MÿVETÿjTbÿdP^ÿ:.6ÿ++/ÿ(%ÿ%ÿ$ÿ&!ÿ'#ÿ'!ÿ'!ÿ("ÿ(#ÿ($ÿ'"ÿ&!ÿ(#ÿ)$ÿ("ÿ% ÿ ÿ ÿ!ÿ% ÿ&ÿ' ÿ'!ÿ&!ÿ'!ÿ'!ÿ(#ÿ(#ÿ'"ÿ&"ÿ'$ÿ'#ÿ&"ÿ&"ÿ)%ÿ*'ÿ*'ÿ(%ÿ&!ÿ&"ÿ'"ÿ'"ÿ&"ÿ&"ÿ&#ÿ'$ÿ,39ÿ<;Fÿ>8Bÿ=6Aÿ?7Cÿ?9Dÿ@:Cÿ@:Bÿ?9Bÿ?:Bÿ@;DÿA;Eÿ@:Eÿ>:Eÿ>:Eÿ>9Eÿ?9EÿA:FÿD:GÿH?Oÿ]Rhÿtf‚ÿ‚s’ÿ„u“ÿ}mŠÿp^zÿgRnÿhRnÿiSnÿiUoÿjVpÿiTnÿfPjÿcMgÿeOiÿgQkÿiSlÿiSlÿjSmÿiRlÿhRlÿiRlÿjRlÿjRkÿiQjÿhOiÿfNhÿeNgÿeNgÿeMgÿeLfÿdKdÿcJcÿcJcÿcJcÿaJcÿ`Jbÿ`Haÿ`G`ÿ`H`ÿaHaÿaGaÿaGaÿ ÿ ÿÿÿ ÿÿÿ ÿ ÿÿ ÿ!ÿ!ÿ ÿ!ÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿÿÿÿÿÿ ÿÿ ÿ"ÿ!!ÿÿÿÿ ÿ7+5ÿYGUÿiTdÿfQ`ÿbLZÿ^JVÿVDOÿJ:Dÿ>2:ÿ;5;ÿ:33ÿhe‚ÿ‡…±ÿЉ·ÿ‹Š¸ÿŒŠ¹ÿŒ‹ºÿŒ�¼ÿ�޾ÿ�޽ÿ�¨ÿmgˆÿmf†ÿ|w›ÿ^Vpÿjc�ÿiaÿbZuÿld�ÿhb~ÿmc�ÿldƒÿxt—ÿ�Œ¶ÿ‘�·ÿ’Ž·ÿ“�¶ÿ”�¶ÿ•޶ÿ“�¶ÿ’�¶ÿ’�¶ÿ’Œ¶ÿ‘‹µÿ‘‹µÿ‘‹µÿ‘Œ¶ÿ‘�¶ÿ’�¶ÿ’�¶ÿ‘�¶ÿ�޶ÿ‘�·ÿ“�¹ÿ”�¹ÿ“�¹ÿ’�ºÿ’�»ÿ’�»ÿ’�ºÿ�‹³ÿ��µÿ“‘»ÿ“’»ÿ“’¼ÿ“‘¾ÿ�Œ¸ÿˆ‡²ÿŠˆµÿ‘޽ÿ€z�ÿnezÿ`T_ÿOA@ÿN?<ÿLA?ÿL@<ÿL>9ÿN@:ÿRB=ÿUEDÿj]iÿvk~ÿh_rÿKG[ÿ58Oÿ$/Fÿ#0Jÿ1;Wÿ+4Mÿ(@ÿ*Bÿ 0Hÿ!.Dÿ%(4ÿXFSÿpYhÿgRaÿ>3;ÿ0.3ÿ ,*ÿ)%ÿ(%ÿ)'ÿ*(ÿ*&ÿ*%ÿ*%ÿ*%ÿ*%ÿ)&ÿ)&ÿ+'ÿ,'ÿ)%ÿ$ ÿÿÿ$ÿ&"ÿ'#ÿ(#ÿ)$ÿ(#ÿ(#ÿ(#ÿ)$ÿ($ÿ($ÿ($ÿ)%ÿ($ÿ&"ÿ'"ÿ'"ÿ'"ÿ&"ÿ&"ÿ&!ÿ%!ÿ&!ÿ &!ÿ %!ÿ%"ÿ%"ÿ&#ÿ<>IÿUM^ÿYHYÿP?OÿTCUÿXHZÿZIZÿ[JYÿZJYÿZJYÿZJYÿWGVÿQCQÿVGXÿVGYÿWGZÿXHZÿXHYÿYHZÿbRiÿpb}ÿƒu”ÿ•†§ÿœ�®ÿ”…¥ÿ�pŽÿnYuÿhRmÿgQlÿeQlÿgSoÿjWrÿkVqÿePiÿdNgÿdNgÿeOhÿgQjÿiRmÿjSmÿiSmÿiRmÿjSmÿjSmÿjRlÿiQkÿhPjÿgOjÿfOiÿfOiÿfNhÿeMfÿdLeÿdKeÿdKeÿcKdÿbKdÿcJdÿbIcÿaIaÿaHaÿbHaÿaHaÿ-/4ÿ-/4ÿ-/4ÿ./5ÿ.06ÿ/06ÿ/07ÿ/06ÿ018ÿ33;ÿ45=ÿ55<ÿ55<ÿ349ÿ,/1ÿ# ÿÿ ÿÿÿÿÿÿÿÿ ÿ ÿ ÿÿÿ ÿÿ ÿÿ &&ÿ629ÿ8/7ÿ&$ÿÿÿ ÿ'%ÿTDRÿjVhÿhSdÿcO^ÿSAMÿA3;ÿ@6EÿOJaÿWVnÿQNaÿon’ÿˆ‰¹ÿŠ‹¼ÿ‹Œ½ÿ‹Œ½ÿ‹Œ¾ÿ‰Œ¾ÿˆŠ¼ÿ‰Œ½ÿpp”ÿ_Xrÿ^Vnÿ\TkÿUMaÿUK]ÿ[Riÿ]Umÿ]Uiÿng†ÿ\Siÿ`Ypÿ{w›ÿŽ‹¹ÿ‘Ž»ÿ’�»ÿ“�ºÿ”�ºÿ“Žºÿ’�ºÿ“�»ÿ”�»ÿ”�»ÿ“�¹ÿ“�¹ÿ“�¹ÿ”�ºÿ•‘ºÿ•‘ºÿ•‘»ÿ•‘»ÿ”’»ÿ•“¼ÿ—”½ÿ—”½ÿ–”¿ÿ””¿ÿ““¿ÿ”“¾ÿ‘�¼ÿ~{¢ÿ}£ÿ��¸ÿ““¿ÿ“”Âÿ“”Åÿ’”Æÿ’”Åÿ‘”Åÿ’“Ãÿ‰†¯ÿwpŒÿaU`ÿPBBÿPCCÿRNPÿOHJÿJ=;ÿN@>ÿZILÿ\KPÿfWdÿoasÿn_qÿi[nÿOHYÿ14Gÿ$0Jÿ+8Vÿ&0Mÿ&>ÿ.ÿ$ÿ&ÿ*")ÿSBOÿkVgÿjUfÿM?Jÿ@9Bÿ45:ÿ.37ÿ.48ÿ/59ÿ/6:ÿ/69ÿ/57ÿ/57ÿ.37ÿ/59ÿ07;ÿ07;ÿ/79ÿ.68ÿ.47ÿ')-ÿ ÿ "ÿ&.0ÿ,37ÿ.58ÿ-58ÿ-48ÿ/59ÿ/5:ÿ.59ÿ-48ÿ-48ÿ-48ÿ.59ÿ/59ÿ/59ÿ/59ÿ059ÿ06:ÿ/59ÿ/59ÿ049ÿ049ÿ/49ÿ/5:ÿ/5:ÿ.49ÿ-49ÿ.39ÿ.28ÿJGVÿbXlÿgWkÿWHYÿ[K^ÿbPeÿeQfÿfSgÿfSfÿeReÿaObÿWGWÿL=Jÿ[I\ÿ_M`ÿaObÿbQcÿaOaÿ]M`ÿgXnÿj\uÿqd�ÿ†x–ÿ—ˆ¨ÿ��­ÿ“ƒ¢ÿ~l‰ÿjVpÿdOiÿdPjÿdQlÿeRnÿhUpÿkWqÿgQkÿcMfÿbLeÿcLfÿeNiÿfPkÿhQlÿiRmÿiQmÿiQlÿjRlÿjRlÿiQkÿhPkÿgOjÿgOiÿfOiÿfNiÿfMhÿgNhÿfMgÿeMgÿeLfÿeLfÿeKeÿcJdÿcIcÿbHbÿaHbÿSFWÿREVÿRFWÿSGXÿSHYÿSGZÿTH[ÿUH\ÿ[NdÿfZqÿh[sÿfXmÿeViÿ`RbÿNBOÿ+,/ÿÿ ÿ ÿ ÿÿÿÿÿÿÿÿÿÿÿÿ ÿ + +ÿÿ=6@ÿ`SdÿTHWÿ4+4ÿÿÿ ÿ* &ÿWGVÿn[nÿiXhÿTDOÿ9-3ÿ2,6ÿSSpÿtw£ÿz~ªÿrs™ÿ}}¨ÿ‹Œ¾ÿ‹Œ¾ÿ‹Œ½ÿŠ‹½ÿŠŒ¿ÿƒƒ´ÿrpšÿ|z¦ÿ^Yvÿ?7Cÿ<3>ÿ>1=ÿ7-7ÿ<09ÿ>3?ÿ=4@ÿ=4>ÿCÿKANÿibÿ…‚«ÿ�޽ÿ‘�¿ÿ’�¾ÿ’�½ÿ“�½ÿ”‘½ÿ”’¾ÿ”’¾ÿ•’½ÿ–“½ÿ–“¼ÿ–“¼ÿ–“½ÿ—“¾ÿ—”¾ÿ—”¾ÿ–”¿ÿ—•¿ÿ˜•¿ÿ˜–Àÿ—•Áÿ–•Áÿ••Âÿ””Ãÿ”“Áÿ��¼ÿmk�ÿ_Zxÿxw�ÿ‘”Åÿ’•Çÿ’•Éÿ�•Éÿ�”Èÿ�”Èÿ‘•ÇÿŒ�»ÿvq�ÿWJPÿK=<ÿPDEÿRMQÿMFIÿI;:ÿUEIÿkXfÿnZkÿo]pÿo^sÿgViÿVHYÿ71@ÿ'<ÿ-Iÿ!/Mÿ+Hÿ(Bÿ"8ÿ%%5ÿ93CÿJ4Aÿ:2>ÿF>LÿSJZÿXM]ÿWL\ÿXM]ÿZO_ÿ\O`ÿYN_ÿYN^ÿYN]ÿYN^ÿ[P_ÿ\Raÿ]Scÿ^Sdÿ`Seÿ`Ufÿ_Teÿ_TeÿaTfÿbUfÿaVgÿbXiÿcXiÿbWiÿ_UgÿaUgÿaUfÿfZlÿpavÿwe|ÿr`vÿr_wÿt`zÿwb|ÿye}ÿxd|ÿr`wÿjZqÿ_QfÿUIYÿ\M_ÿgVkÿp^uÿwczÿye|ÿwc{ÿuazÿo]vÿj[vÿpc€ÿˆy˜ÿ˜‰©ÿ��­ÿ”„£ÿ€n‹ÿcQjÿ`LfÿcPkÿdQmÿeQmÿfRnÿiToÿhSnÿcNhÿ]Gaÿ`JdÿbLfÿdMhÿfOjÿiQlÿiRlÿiQkÿhPjÿhQkÿiQlÿiQkÿhOiÿfOhÿfNhÿgOiÿgOiÿgNiÿgNhÿfNgÿfLeÿdJdÿcIdÿcIdÿcJdÿcJdÿ=3Bÿ=3Bÿ=3Bÿ=4Cÿ=4Cÿ>4Eÿ?4EÿJ>QÿaSiÿue~ÿsaxÿq]sÿjWjÿ]M^ÿM@Oÿ-,2ÿÿ ÿ ÿ ÿ ÿ ÿÿÿÿÿ ÿÿÿÿÿ  +ÿÿ4,5ÿ]N`ÿo^tÿ]N`ÿB5Aÿ/$*ÿ-!%ÿ2%)ÿA19ÿYHVÿbQ`ÿRDOÿ=27ÿ.'(ÿXZ~ÿx~±ÿ‚‰¿ÿ…ŒÀÿ„‰ºÿˆ‹¼ÿ‹ŽÀÿŠ�¿ÿ‰Œ¾ÿˆŠ½ÿˆŠ¼ÿ|{§ÿ]VtÿWPhÿF;Iÿ/#'ÿ+#ÿ7&-ÿ' ÿ- %ÿ+#ÿ(!ÿ0%*ÿ*!#ÿ9+,ÿ<.1ÿLCSÿpk‹ÿ��¾ÿ’’Äÿ‘‘Àÿ‘‘¿ÿ’’¿ÿ”“¿ÿ”’¾ÿ”’¾ÿ•“¿ÿ–”¿ÿ•“½ÿ•’¼ÿ•“½ÿ•“¾ÿ”“¿ÿ””Àÿ•”Àÿ•”Àÿ••Àÿ••Âÿ”•Äÿ”•Äÿ“”Äÿ“”Äÿ‘“Âÿˆ‹¶ÿZZwÿ/(6ÿ]^€ÿŒ‘Äÿ�‘Äÿ|~¬ÿ�…¶ÿŽ”Éÿ�”Èÿ�•Éÿ�’ÅÿxwšÿWKPÿJ=9ÿK?<ÿMBAÿJ><ÿP@BÿbOZÿoZkÿr]qÿl[nÿbRcÿQBRÿ8-:ÿ(!.ÿ!%<ÿ ,Jÿ.Lÿ*Gÿ)Dÿ&(>ÿ*&7ÿ*(9ÿ:4Hÿ@6GÿC7FÿD7FÿC6DÿB5Cÿ?2@ÿ=2@ÿ>4Bÿ>6Cÿ?6Dÿ@7DÿA7DÿA7Dÿ@6DÿA8FÿA8GÿA8FÿA7EÿA6Dÿ?5Cÿ:0>ÿ4,9ÿ4,9ÿ91?ÿ@6FÿC8HÿC9HÿC9HÿD:IÿE:JÿD:JÿE;JÿE;JÿD;JÿE;JÿFNÿH>NÿG=MÿH=MÿI>OÿJ>PÿK@QÿKARÿLBSÿLBSÿJ@RÿLASÿLARÿNBTÿQEWÿUH[ÿTFZÿSEYÿ[KaÿmZrÿ~jƒÿ~j„ÿ{h�ÿuc{ÿgWmÿRDUÿPBRÿl\rÿxfÿ{g€ÿj„ÿ~jƒÿ|g�ÿvb|ÿn]wÿj\wÿoa~ÿˆy˜ÿ˜ˆ¨ÿ›‹¬ÿ“ƒ£ÿ}m‰ÿfTmÿ_KeÿcNiÿeOkÿePkÿfQmÿgRnÿhToÿhTmÿaKdÿ]H`ÿ^HaÿaJdÿcLeÿeNgÿgPiÿgPiÿgOiÿfOiÿfOiÿfOhÿeNhÿeNgÿdMfÿeNgÿfMgÿgMgÿfMfÿeKfÿeKeÿdJdÿcIcÿbIbÿcIcÿ:/;ÿ;0<ÿ;0<ÿ:0=ÿ:0=ÿ;/<ÿ>2BÿUH]ÿm]uÿwd}ÿr^rÿoZmÿcQcÿSDVÿH=Lÿ/-4ÿÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿ + ÿÿ5+5ÿ^N_ÿo\qÿfSdÿYFSÿQ>HÿN-1ÿ-"!ÿ2$&ÿ."#ÿ-""ÿ8*-ÿ/##ÿ;,-ÿ9(%ÿ?38ÿd^xÿ�Ž¿ÿ’”Æÿ’“Âÿ“”Âÿ”•Áÿ••Áÿ•“Àÿ•”Àÿ••Áÿ•”Âÿ”“Àÿ�~¤ÿ…ƒ«ÿ”“¿ÿ“”Áÿ“”Âÿ“”Ãÿ”•Ãÿ”–Äÿ“–Åÿ“•Æÿ’•Åÿ’”Åÿ“•Åÿ�“Ãÿ„ˆ´ÿPQkÿÿJMlÿ‚‡ºÿ…‹¿ÿqsŸÿy{¬ÿ‹‘ÇÿŽ”Êÿ�”Êÿ�–Ëÿ|~¥ÿ\S_ÿL>:ÿK>8ÿO@>ÿUEGÿaNXÿnYiÿq\nÿmZmÿaQbÿRDSÿD7Dÿ0&0ÿ3)2ÿ/,>ÿ )Dÿ&@ÿ$>ÿ&@ÿ.+Aÿ2*:ÿ !4ÿ+/Gÿ44Jÿ:3Dÿ:0>ÿ8/;ÿ<1>ÿ<1>ÿ=2>ÿ=2?ÿ=3@ÿ=3@ÿ;1>ÿ:0<ÿ6,8ÿ0(3ÿ5.:ÿ6.;ÿ7.;ÿ8-:ÿ7-9ÿ6,9ÿ6,9ÿ7-;ÿ8-<ÿ6-;ÿ6,;ÿ7-<ÿ:0>ÿ<2?ÿ:0=ÿ8.<ÿ7-:ÿ7-:ÿ8.<ÿ:0>ÿ9/>ÿ:0>ÿ90>ÿ90?ÿ;2@ÿ<2@ÿ=3Aÿ@6DÿB7FÿB6GÿB7GÿA6FÿA6FÿA7Gÿ?5Eÿ;1@ÿ@7FÿB9HÿA8HÿB8IÿC8JÿD9JÿN@SÿcRgÿwc|ÿyfÿyfÿwd|ÿp^uÿeTiÿaQfÿr`xÿxd}ÿwb{ÿze}ÿ{f~ÿ{fÿwc|ÿp^wÿiYsÿeWqÿse€ÿ…v“ÿ”„¤ÿ›‹¬ÿ“„£ÿ|l‡ÿfSmÿ_JdÿdNiÿeOkÿePkÿfQlÿhToÿkWrÿhTmÿbNfÿ]H`ÿ[E]ÿ[E]ÿ^H`ÿaKcÿcMeÿdMfÿdMgÿcLfÿbLeÿbLeÿbLfÿbKdÿcKdÿcJdÿdJdÿcJdÿcJdÿcJdÿbJdÿaHbÿaG`ÿ`G`ÿN?LÿO@MÿKMÿ51:ÿ""ÿ ÿ ÿ ÿ ÿ ÿ ÿ +ÿ ÿ ÿÿÿÿÿÿ +ÿÿ&$ÿL?KÿjWhÿmXiÿhR`ÿdNZÿcNXÿ`LVÿWENÿI:@ÿ@8AÿD@Lÿ925ÿba~ÿ�„²ÿŽ“Çÿ�’ÅÿŽ’ÄÿŽ’Ãÿ��Àÿ�޼ÿŽŒ¹ÿ‰‡´ÿŒ‰·ÿ~z¢ÿ`YrÿD8<ÿ<0/ÿ<..ÿ:,-ÿ:,-ÿ<--ÿ2%$ÿ6''ÿ3&&ÿ3((ÿ>//ÿ:++ÿ<,-ÿ<*(ÿD7=ÿc^zÿ��Àÿ’•Çÿ’”Äÿ”•Äÿ”–Ãÿ•–Ãÿ••Ãÿ”•Ãÿ”–Ãÿ””Ãÿ�Ž»ÿb^}ÿmjŽÿŽ�¼ÿ“”Ãÿ“•Åÿ“–Çÿ“—Çÿ“—Çÿ“—Èÿ’–Çÿ’•Çÿ’•Æÿ’•Çÿ�“Åÿ…‰·ÿSTpÿ ÿKNnÿ�‡»ÿ…ŒÂÿ|€²ÿ€„¸ÿ‹�Èÿ�”Ëÿ�•Ëÿ’˜Îÿ……°ÿmcwÿ]MQÿZJMÿ_NUÿhT`ÿoZjÿp\oÿkWjÿ`NaÿSDUÿJ=LÿE7Dÿ8,5ÿÿ,1Jÿ99Mÿ;1>ÿ:0<ÿ?5AÿA5AÿB6AÿC7BÿC6BÿC7CÿF8EÿF8EÿA4Aÿ<1=ÿF:HÿF:GÿB6Bÿ>2=ÿ;0;ÿ9/:ÿ:/;ÿ:/<ÿ9.;ÿ7-:ÿ8.;ÿ9/=ÿF7DÿO=IÿL;GÿE8EÿC6CÿB5AÿD6CÿE7Eÿ?3Aÿ=2?ÿ=2?ÿ?3AÿB6DÿE8FÿG:HÿK=LÿM?NÿM?NÿM?OÿK=MÿK>MÿL?OÿJ>MÿA7CÿL@MÿOCRÿM@PÿL?PÿN@PÿOBRÿRCTÿZI[ÿdRgÿhUkÿiWkÿjXmÿlZoÿnZqÿmZqÿo\sÿlXnÿgThÿhViÿnZoÿp[qÿo[qÿkXnÿdSiÿbShÿgZqÿqc|ÿ‚s�ÿ•‡¦ÿœŽ­ÿ‘‚ ÿ|lˆÿhUpÿ`KeÿcMiÿfPlÿfQmÿfQmÿhSoÿkWrÿiUoÿdPiÿ^Jbÿ[F^ÿZD[ÿ[E]ÿ^H`ÿaJcÿbLeÿbKeÿaJcÿ`JcÿaJdÿaJcÿaIbÿaHbÿaHbÿaHbÿaHaÿ`HaÿaIbÿaHaÿ`G`ÿ`G_ÿYIVÿYHVÿN>KÿC3>ÿF4>ÿE4?ÿXI[ÿiXnÿr^vÿs^vÿmWlÿkVjÿ`N`ÿRDTÿJ?Mÿ81;ÿ"$ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿÿÿÿ!!$ÿ&"'ÿÿ ÿÿÿ<1;ÿhUgÿmYkÿiUdÿhS`ÿhS_ÿZHSÿE7>ÿG@Nÿ]ZsÿjhƒÿRM[ÿ||¤ÿ�’Âÿ�“Ãÿ�”Ãÿ�“ÂÿŽ�ºÿŒƒ«ÿ‹|œÿ‡v“ÿxf�ÿ~l‡ÿl\tÿB8Dÿ,"$ÿ3'+ÿ."%ÿ/"&ÿ0#&ÿ*ÿ, "ÿ+ÿ,!!ÿ1&%ÿ8+*ÿ@0/ÿ>,,ÿ>*(ÿF7>ÿa\xÿ�’Âÿ”—Éÿ’•Åÿ“•Åÿ“•Åÿ“–Åÿ“–Åÿ“–Æÿ”–Æÿ‘“Âÿ�}¦ÿNG`ÿ[Zzÿ„…²ÿ‘”Äÿ’–Çÿ’—Éÿ’—Éÿ’—Éÿ’–Éÿ’–Çÿ’–Çÿ‘•Çÿ‘•Çÿ�“ÆÿŠ�¾ÿ__€ÿ( (ÿUWxÿ‹‘Çÿ‹’ÉÿŠ‘ÇÿŒ’Èÿ�”ËÿŽ”ÊÿŽ“Çÿ�’ÄÿŠ„¬ÿ€o†ÿt`nÿnZhÿo[lÿp\oÿmZlÿeReÿXFXÿLLÿF8Cÿ=-6ÿ>-6ÿ5*5ÿ /ÿ +'ÿ +(ÿ$7ÿGMÿA6Cÿ;1<ÿ:0;ÿ?3@ÿG8GÿK4>ÿ@6Bÿÿÿ ÿ ÿ2)0ÿbQaÿgUeÿhUeÿfSaÿXGRÿC5<ÿD;Dÿrn�ÿŽ‹´ÿ‰†ªÿxt�ÿŠŠ±ÿ”•Âÿ“”Áÿ“”Áÿ�“¿ÿ{Ÿÿn_vÿhO]ÿdMYÿUAMÿO?GÿH8?ÿ7(/ÿ%ÿ7)2ÿ*#ÿ*"ÿ- %ÿ ÿ, $ÿ#ÿ- ÿ7((ÿ5'%ÿB0,ÿE2/ÿB.,ÿA18ÿ[Wrÿ�“Ãÿ–›Ìÿ•™Êÿ•™Êÿ•™Êÿ”™Éÿ”™Éÿ•˜Éÿ–šËÿ�“Âÿd_}ÿ2*7ÿSOkÿ~~§ÿ�•Æÿ“™Ëÿ“™Ëÿ“™Ìÿ’—Ëÿ�•Èÿ�•Èÿ‘–Çÿ‘•Çÿ�”Çÿ‘”ÆÿŽ’Âÿqq—ÿIC[ÿVUtÿ‚†µÿ�„´ÿŠŽÂÿŽ“ÈÿŽ’Æÿ��Áÿ„…±ÿvp“ÿrayÿu^pÿs^pÿp\oÿjWjÿ`OaÿSCUÿH:JÿE7HÿL=MÿQBNÿL>FÿC5;ÿPHÿKÿ&%1ÿ)&1ÿ72@ÿQGZÿ\Qfÿ]Sgÿ]SgÿfYpÿpaxÿqbyÿl^sÿj[pÿo^uÿp`xÿo`xÿgZoÿVJ]ÿTGYÿRFXÿQEWÿPEWÿQFXÿTG[ÿTH[ÿYK]ÿdSgÿn\sÿiXoÿfVlÿhWlÿiWmÿfUkÿgWlÿ`Qeÿ\MaÿaQeÿkYlÿn[nÿo\nÿo\oÿp\qÿq]qÿq^rÿtavÿvczÿsayÿl\qÿfWjÿo_rÿtbvÿtavÿuawÿt`uÿu_sÿt]rÿq]rÿp]qÿo[oÿq]pÿs`sÿvbxÿxe}ÿzgÿxf}ÿq`vÿm^sÿravÿq_sÿxf|ÿ|j‚ÿ}k„ÿ}k…ÿyg�ÿ{m‡ÿ{oŠÿylˆÿ~qŽÿ—ˆªÿœŒ¯ÿš‹¬ÿ’‚¢ÿ}l‹ÿfSpÿaLhÿcNjÿeQlÿfSnÿhToÿhTpÿiVqÿlYsÿnZtÿlVpÿ_JcÿZD]ÿ[E^ÿ\F_ÿ]G`ÿ`JcÿbKeÿaKdÿ`JcÿbIcÿcIdÿbIdÿbJdÿaIbÿ`Haÿ_Haÿ`HaÿaHbÿbJcÿN>MÿO?NÿUESÿ]KZÿ^K[ÿN=KÿQBRÿXJ^ÿbSiÿo]tÿr^uÿp\rÿmYnÿaNaÿA3Aÿÿ +ÿ +ÿ ÿ ÿ ÿÿ ÿ ÿÿ##'ÿ7/9ÿUHXÿ]OaÿC8Dÿÿÿ ÿÿ0&-ÿWHWÿcSbÿ_N]ÿRBMÿ@39ÿ8-1ÿaZmÿˆƒ¥ÿš—¾ÿ—•ºÿ”‘µÿ–”ºÿ—–¾ÿ–•¾ÿ••¿ÿ“”¿ÿ‡…«ÿunŠÿdXhÿZHQÿK8=ÿC42ÿD33ÿ?.2ÿ6)*ÿC27ÿ3&(ÿ5')ÿ9*,ÿ+ÿ>./ÿ/!!ÿ7''ÿB//ÿ:(&ÿD0-ÿC11ÿ?/1ÿ?18ÿXSlÿ��½ÿ–™Ëÿ•›Ìÿ•œÎÿ•›Íÿ”šÌÿ“˜Êÿ“˜Éÿ•™ËÿŒ�ÁÿTRmÿ%&ÿYYyÿ�„²ÿŽ”Æÿ�•Éÿ�•Éÿ�•Éÿ�”ÈÿŽ“Çÿ�“Æÿ�“Æÿ�“Æÿ�“Æÿ�“Æÿ�’ÄÿuvžÿZVsÿSNiÿ\Zyÿ_\}ÿ{y£ÿ…‚­ÿƒ}£ÿ}t–ÿd\wÿJ@RÿP?LÿaM\ÿcQbÿ_M`ÿUEWÿL=OÿG:LÿIIÿKIÿ7*0ÿ1$)ÿ1$(ÿ5'+ÿC2:ÿXFRÿXIUÿL>Hÿ;/4ÿ4*)ÿ?68ÿwq‡ÿ•�¯ÿžš½ÿžš½ÿž›¾ÿ�™¼ÿ›˜¼ÿš˜½ÿ™—¾ÿ˜–¾ÿ”‘·ÿ‘�²ÿ{˜ÿPEPÿ@24ÿ<.-ÿ=./ÿ;,.ÿ6))ÿ=.0ÿ2%&ÿ4''ÿ7)*ÿ0"!ÿ=-.ÿ8('ÿA--ÿG11ÿ?**ÿK57ÿH6:ÿE59ÿF6?ÿRJ`ÿur–ÿ}{¢ÿ€¦ÿ„„­ÿŠ‹¶ÿ‘’Áÿ”˜Éÿ•™Ëÿ”˜ËÿŽ“ÃÿruœÿAAWÿY[|ÿ‚†¶ÿ�•Èÿ�–Éÿ�”ÈÿŽ“ÇÿŽ’Æÿ�“Æÿ�’Æÿ�“Çÿ�”Èÿ�–Êÿ‘–ÉÿŽ�Àÿrp•ÿ\ToÿKCXÿ0(4ÿ;2Dÿi^{ÿvh†ÿp`yÿeTgÿI9Eÿ/#,ÿ6+8ÿL>NÿYJ[ÿZJ^ÿI;Nÿ=3Eÿ@6HÿF;MÿJ?PÿH=MÿC8EÿC9DÿL?LÿL@Nÿ@6Dÿ=5Dÿ93Bÿ"0ÿ$ÿ +ÿ$ +ÿ*$.ÿ3+7ÿ#"/ÿ!$4ÿ0/Bÿ;7Jÿ?8IÿJARÿ]Odÿi\sÿpc|ÿqd~ÿn`xÿgXnÿdTiÿcSgÿeUjÿxe}ÿwczÿlYmÿdReÿeSfÿfSfÿdQdÿaObÿ`NaÿbQdÿcSfÿeTgÿfUhÿfUgÿdSeÿeSfÿfTgÿeTgÿdReÿcRdÿdSeÿdTfÿeUgÿeUgÿdTfÿgUgÿhWjÿhWkÿgVjÿhVkÿhWkÿgWjÿfViÿfUiÿgUjÿgUjÿfThÿeTfÿeTfÿeUhÿeShÿdTgÿcSgÿ[M`ÿH?Nÿ71<ÿ-*1ÿ409ÿF>KÿXL]ÿcTgÿfUiÿgVjÿjYnÿm\rÿm[rÿl[rÿm\rÿm\sÿm\tÿl\tÿm\uÿn]vÿo^vÿo]uÿlZrÿkZqÿlZqÿm[sÿn_xÿm^yÿjZuÿiXsÿjYtÿjWsÿePmÿfQnÿiTpÿkUrÿkVsÿkVsÿmXtÿlXrÿiUnÿdPhÿ[G^ÿYD\ÿ\F_ÿ`IcÿbJdÿcKdÿcKdÿcKeÿcKeÿcLeÿcLfÿcKfÿcKeÿbJcÿaIbÿdQdÿdRfÿgVjÿhWkÿbPdÿTDTÿWEUÿYIXÿTGVÿMBSÿVI\ÿbThÿl[rÿbRhÿ;.;ÿÿ>3?ÿLANÿH?Jÿ=5?ÿ1.4ÿ"%&ÿÿÿ +ÿ"ÿRAPÿdO`ÿdN]ÿ[FSÿR>HÿO;DÿM:CÿN;DÿS?HÿVCMÿH9@ÿ:03ÿ5,+ÿ8/-ÿOFKÿ‡€–ÿž˜µÿ¡›ºÿ¡›»ÿ ›ºÿ ›ºÿŸš»ÿ�š¼ÿœ˜»ÿ—“µÿ�Šªÿ‘Œ­ÿ€|™ÿ>5=ÿ.""ÿ1#&ÿ/"%ÿ, "ÿ.!$ÿ, !ÿ)ÿ) ÿ+ ÿ, ÿ5&'ÿ>++ÿF0/ÿG//ÿC--ÿL7<ÿL:AÿK9@ÿJ:EÿMATÿYL^ÿ`RdÿdWjÿj_vÿtk‰ÿ€zžÿˆ†°ÿŽŽ»ÿ’“Ãÿ’–ÆÿŒ�¿ÿYZyÿ[\}ÿ‚†´ÿ‘•Çÿ’–Èÿ�•Çÿ�“Åÿ�‘ÃÿŽ‘Âÿ�Ž¿ÿ‹Œ¼ÿŠ‹¹ÿˆ‰¶ÿ††²ÿ�|¤ÿka~ÿYL`ÿF;Jÿÿ(!+ÿSBTÿ]J]ÿUDUÿK=Kÿ@4Bÿ;0>ÿ9/=ÿI=Mÿ_Qdÿ`QgÿNBVÿE;LÿI?PÿMCTÿNEVÿNDUÿMDTÿLCSÿKBRÿI?PÿG>OÿH?QÿBÿ!".ÿ$"0ÿ(%3ÿ)%2ÿ&#/ÿ"!,ÿ+*:ÿ<8KÿG?RÿH>OÿJ@PÿKAQÿLCTÿNCVÿOCVÿMBTÿLARÿK@PÿGKÿN>LÿO>KÿN>KÿN>KÿO>KÿM=IÿL=JÿL>JÿL=IÿLMÿN>KÿO>KÿLÿF?QÿTJ\ÿVJ[ÿUJ[ÿZOaÿ]Sfÿ`ThÿbUiÿ`Thÿ_Tgÿ]Rdÿ[Oaÿ_Qeÿraxÿs`tÿaO_ÿM@KÿNAMÿK>KÿH=JÿL@MÿL@MÿF;EÿD:CÿD:CÿGJÿH>JÿGJÿJ?KÿK@LÿI>JÿGJÿH;FÿE9DÿH=HÿI=JÿJ?Kÿ@7Aÿ(#)ÿÿÿÿÿÿÿ?5@ÿF:FÿJ>IÿI=GÿC5?ÿQAOÿUCSÿUBRÿTBQÿUBRÿWDUÿWFWÿXFXÿZGYÿZGZÿZFYÿXEXÿWDWÿTCWÿMCZÿKGdÿ]Vsÿnc€ÿylˆÿ~p‹ÿ{l‰ÿo_|ÿhWtÿgTrÿfQnÿjUrÿhUrÿgSpÿhUqÿlYvÿp\xÿlWqÿdOgÿ^Iaÿ]G_ÿ_HaÿaJcÿbKeÿbKfÿbLgÿcLfÿbLfÿcLfÿdMfÿeNgÿ\JZÿN@MÿSDTÿfTgÿr^tÿo[pÿ`N_ÿSBOÿSBPÿ[JZÿYIYÿPCRÿH=MÿC9Iÿ:0=ÿ!ÿ8-9ÿN@Sÿ\KaÿcRiÿjYrÿk[vÿjYsÿVH\ÿÿÿ\Obÿn^sÿm\pÿlYmÿhTfÿ^KZÿUCQÿLKÿI8EÿH8CÿWFVÿhVkÿ[MaÿE:Hÿ8-7ÿ>4?ÿJBOÿMFTÿMETÿLETÿLEUÿLFUÿMGVÿMFVÿJDTÿEBUÿ?>Tÿ23Fÿ-/Bÿ--Aÿ++>ÿ))<ÿ**<ÿ1.?ÿ@:KÿNEUÿSGWÿNEUÿLEVÿMFWÿMFXÿNFWÿNFVÿQHWÿNFSÿUJYÿfYmÿm_vÿiXkÿNBMÿ(),ÿ*+-ÿ$'*ÿ"%'ÿ,.1ÿ/03ÿ $%ÿ$$ÿ$$ÿ $$ÿ"&&ÿ#''ÿ#'(ÿ"''ÿ &&ÿ &&ÿ &&ÿ $%ÿ##ÿ""ÿ""ÿ""ÿ "#ÿ "#ÿ!#$ÿ"%&ÿ$'(ÿ#('ÿ"''ÿ"''ÿ#((ÿ"((ÿ"'&ÿ$((ÿ#((ÿ"('ÿ#))ÿ#))ÿ$**ÿ'&ÿÿ ÿÿÿÿÿ +ÿ"#ÿ"&'ÿ%))ÿ%((ÿ+'+ÿD8CÿN=LÿSAPÿUCRÿUCSÿWDUÿXEWÿXEWÿXEXÿXEXÿXEXÿWEWÿUDVÿQATÿI?UÿEB\ÿHE`ÿVOjÿh]xÿwj„ÿp‹ÿoŠÿue€ÿdTpÿZHdÿaMjÿgSpÿhTqÿfSpÿeRoÿcPlÿhSnÿlXrÿkVoÿcMfÿ`IbÿaJdÿbKeÿbLfÿbLeÿcLfÿcLfÿcMfÿdNgÿeOhÿdQdÿ_M_ÿbRcÿl[mÿr^qÿhUhÿaN_ÿ[HXÿYFUÿZGVÿWDSÿUDSÿSDTÿQBSÿH;Hÿ("ÿ0&1ÿ:0?ÿ?3DÿE9JÿK>QÿOBVÿSEZÿI/1ÿ7)*ÿ1""ÿA-.ÿ>*)ÿI/.ÿL5:ÿF39ÿB-0ÿE8FÿF;LÿE9JÿK>Nÿ[K]ÿjWlÿvd|ÿ{jƒÿyjƒÿwjƒÿzm‡ÿyk†ÿuf€ÿsc}ÿsf�ÿl_xÿJ?PÿMBUÿaTlÿ\NdÿVH\ÿPBTÿK=MÿF8HÿC5Dÿ@3Aÿ?2Aÿ>2Aÿ=2@ÿ<3@ÿ=3@ÿ@5CÿB7Cÿ6,5ÿ +ÿ#!ÿF9DÿPANÿN>JÿMMÿ>@Pÿ?AQÿ>@Pÿ<>Mÿ;ÿ**<ÿ));ÿ+*<ÿ/-?ÿ85Gÿ@MÿYFUÿYGUÿVETÿSCQÿJ:Fÿ-%ÿ;.9ÿ>2?ÿ5*7ÿ2(4ÿ4+7ÿ4+7ÿ8/<ÿ6.;ÿ)#/ÿ.(7ÿJAVÿYOgÿbXqÿkb}ÿqi‡ÿulŠÿ|s’ÿ‰€¡ÿ”Œ®ÿ’‰¬ÿ‹€¡ÿ‚t�ÿsdzÿsgzÿ¢—¯ÿ©Ÿ¸ÿ¦�¶ÿ¥œ¶ÿ¤›µÿ¤›µÿ¢™µÿ ™¶ÿ“‹§ÿmdvÿE8>ÿ6)&ÿ9--ÿ8,-ÿ1$%ÿ6)*ÿ3&'ÿ0$$ÿ1%$ÿ3%'ÿ0##ÿ7**ÿ5''ÿ8''ÿD//ÿ>)(ÿM21ÿN9@ÿE6@ÿD16ÿF:IÿHOÿ;1>ÿ9-:ÿ=0=ÿ9-8ÿ5*6ÿ5)6ÿ4*6ÿ5+8ÿ9-;ÿ:.;ÿ;0<ÿ>2?ÿB5CÿE9FÿG;GÿI;HÿI;Gÿ;/8ÿÿ$!ÿ=1;ÿD6BÿC4@ÿD4?ÿD5>ÿ?19ÿOAPÿcRfÿiUjÿ_OaÿOAOÿC5@ÿ<4@ÿ:9Hÿ8NÿQ?OÿSARÿUBTÿVDUÿWDVÿWDVÿUBUÿSATÿQ@RÿL;MÿA3Dÿ8.>ÿ;5IÿAMÿaN^ÿ`M^ÿ[IYÿSBOÿD3=ÿ/%ÿA2=ÿF8Dÿ=0;ÿ5*5ÿ<1<ÿ?2?ÿ=2@ÿ80=ÿ1*7ÿ,&3ÿ' +ÿ( +ÿ.%0ÿ2'3ÿ5)8ÿGÿ4'1ÿ0$/ÿ/$0ÿ/&2ÿ/'2ÿ1)4ÿ5+8ÿ6,8ÿ6-8ÿ:1;ÿ<2=ÿ?3AÿA5BÿC6BÿC5Aÿ@1<ÿ1<ÿD7BÿJOÿNEXÿXObÿ_Wkÿ\VkÿXTjÿ]Zrÿcazÿeb{ÿdczÿecyÿdbxÿgdzÿoh�ÿoeÿp`wÿ]M_ÿ?5@ÿ82:ÿ729ÿ839ÿ839ÿ938ÿ:59ÿ<6;ÿ=7<ÿ>9>ÿ>:?ÿ=:@ÿ>GÿC?HÿC@HÿB@HÿA?GÿA>Gÿ@>Fÿ?=Dÿ>=Dÿ>>Eÿ>=Eÿ>=Eÿ>=Dÿ==Eÿ<6IÿE>TÿKE\ÿUMfÿaWqÿpb}ÿ~m‰ÿˆu‘ÿ‰w’ÿxf�ÿfUqÿ`NjÿaMjÿeQnÿfRoÿaNjÿ\JgÿaNiÿjVrÿq[wÿnXtÿhRmÿfNhÿeLeÿdKeÿdLfÿfNgÿfNhÿXFWÿ[IZÿ`M^ÿcPaÿcPaÿfReÿlWkÿfReÿ\I[ÿ\J[ÿdPbÿfReÿeReÿZIZÿC2<ÿ2")ÿ9+5ÿ@2=ÿ;.8ÿ0%.ÿ;.8ÿF6BÿF8Eÿ@4Bÿ9/>ÿ3)6ÿ6+8ÿ=0=ÿA3AÿA5DÿG=OÿcZuÿˆ¡ÿš‘¶ÿ’‡ªÿ|o‹ÿ[PfÿD:Lÿ=3Eÿ[Qcÿž’ªÿ©ž¶ÿ§�µÿ¦œ´ÿ¦œ´ÿ¥›³ÿ¡–¯ÿ…yŒÿYKRÿ?23ÿ(ÿ ÿ"ÿ ÿÿ ÿÿÿ"ÿÿ(ÿ)ÿ.ÿ8%%ÿB,.ÿG.-ÿF/0ÿF8CÿC:Hÿ>2;ÿF;KÿL?Qÿ^L]ÿuawÿ‡w”ÿ”‡©ÿ‰zšÿl\tÿH8Hÿ4)4ÿ5+5ÿ;/;ÿ?3@ÿA5BÿB5CÿC6CÿE7DÿA4@ÿA4?ÿH:FÿI:FÿJ:GÿK;GÿH9Dÿ@1;ÿ4(.ÿ*!%ÿ*#(ÿ2)2ÿ@5?ÿXGSÿ[IVÿTDPÿC5?ÿ) 'ÿ1(0ÿOBNÿTGUÿF3>ÿJ:IÿO=MÿP>OÿQ?PÿR@QÿSASÿSARÿTBSÿSASÿP?PÿL6IÿGAXÿMH`ÿQIbÿZNgÿhYrÿwf€ÿƒrŒÿ‡u‘ÿmˆÿn\wÿbOjÿaMhÿfQmÿhSpÿdPmÿ_LgÿaLhÿhSoÿoZwÿq\yÿmWrÿgQjÿdMfÿdLfÿdLfÿdLeÿlYpÿq^uÿtaxÿq^uÿgUiÿ]J]ÿ^L^ÿ^K^ÿ\I\ÿ^K]ÿ\J\ÿ[I[ÿ\I\ÿUCTÿC4?ÿ;,7ÿ?0<ÿ>0<ÿ9,7ÿ5)4ÿ/%/ÿ9-8ÿÿ;/=ÿ2'2ÿ:-8ÿE5BÿK;IÿUFYÿqd€ÿŒ‚¦ÿ˜Ž´ÿ�…§ÿvh…ÿbTiÿD:Iÿ6.=ÿ;1BÿYObÿš�¨ÿ¨œ¶ÿ¨�¶ÿ§�µÿ¦œ´ÿ¦›³ÿ‘„šÿh[iÿ>00ÿ>00ÿ(ÿ%ÿ%ÿ ÿÿ ÿÿ$ÿ)ÿ!ÿ1!ÿ. ÿ.ÿ8%'ÿB.1ÿ@()ÿD/5ÿF8EÿC:Jÿ@5CÿG;Lÿ\L^ÿo[qÿƒpŒÿ“…¦ÿ�‚£ÿteÿTEWÿC6DÿD6BÿD5@ÿH7DÿK;GÿM=IÿL>IÿK;FÿJ:Fÿ@1<ÿ=.9ÿH8Eÿ?2>ÿ5,5ÿ.'/ÿ*$,ÿ'!(ÿ!"ÿ !ÿ# &ÿ)&/ÿ=5@ÿ]M[ÿaP_ÿ\KZÿRCPÿC6Bÿ=2=ÿG;GÿH;HÿD;HÿGBRÿGDWÿ<;Lÿ^Vnÿl_xÿN=JÿK9FÿI8CÿG5@ÿD2<ÿA1;ÿJÿ>2>ÿ>2>ÿ?4@ÿA5BÿB6DÿC6DÿC7DÿC7EÿB7FÿB7FÿB7DÿC7DÿC7EÿB6EÿB6EÿB7EÿB6DÿB6CÿB7CÿB7CÿC7DÿOCRÿsbyÿm†ÿ}l…ÿyi�ÿcYkÿ9;Bÿ&!ÿ%!ÿ% ÿ%ÿ$ÿ$ÿ#ÿ#ÿ#ÿ"ÿ"ÿ"ÿ!ÿ ÿ!ÿ$!ÿ()-ÿ;1;ÿI:HÿMOÿQ@QÿSARÿTASÿSARÿR@QÿQ?PÿN>MÿG7Eÿ<.;ÿ8-=ÿA9NÿJC\ÿOHaÿQHaÿXLeÿeXqÿrb|ÿ~l‡ÿ…q�ÿƒpŒÿyg�ÿaOiÿ\HdÿcOkÿiTpÿiTpÿePkÿcNjÿePmÿkVrÿp[wÿp[uÿkVoÿeNgÿbJcÿdLeÿq`zÿuc}ÿvc|ÿl[qÿWH[ÿO?OÿQ@PÿTBRÿUCTÿXEUÿWDTÿTBRÿQ@OÿMOÿWHYÿ[K]ÿ\J^ÿ[K]ÿJ2<ÿM?JÿZIXÿ_N^ÿ]L[ÿ^L[ÿgTdÿlYiÿdScÿJ?Lÿ(&0ÿ )ÿ'ÿ%ÿ 'ÿ""+ÿ,*3ÿC:DÿI>IÿH=IÿE:Eÿ@5@ÿ:1;ÿ3+5ÿ1*5ÿTL_ÿzq‹ÿ|sŽÿqj�ÿ^WlÿNCVÿG8FÿA3@ÿC3@ÿC3?ÿ>/;ÿ9,7ÿ?2?ÿDMÿMBRÿRGWÿQGXÿXPeÿ]Voÿ`XqÿaYpÿbYoÿcYnÿcYmÿ`ViÿYOcÿUK`ÿSI\ÿPDUÿF:Iÿ7,7ÿ9.9ÿ<1=ÿ>3@ÿA7CÿE;GÿG;HÿE:FÿC9EÿC9EÿD9EÿE:EÿH=IÿI?KÿJ?LÿJ@NÿLBNÿNBPÿMAPÿKANÿKAOÿLAOÿMBRÿMBRÿLAPÿL@OÿK?NÿI>LÿI>LÿH=IÿC8DÿD:Fÿm]rÿ�n‡ÿ„q‹ÿ‚qŠÿ{lƒÿSM\ÿ$.0ÿ% ÿ% ÿ%ÿ$ÿ$ÿ$ÿ#ÿ"ÿ#ÿ#ÿ"ÿ"ÿ"ÿ"ÿ#ÿ$!ÿ,).ÿD7EÿKNÿP>OÿR@QÿSAQÿTBRÿUCTÿTBRÿN=LÿD5Bÿ:-:ÿ8.>ÿA9MÿJCZÿNF^ÿPF_ÿUKcÿ\QiÿiZtÿue€ÿ~mˆÿ�oŠÿyg‚ÿkYtÿcOkÿeOkÿiToÿjUpÿhRnÿdOkÿdPlÿiUqÿmYuÿp\wÿoZuÿkUoÿdNgÿi[sÿgWnÿfUkÿ`NbÿO?PÿH8GÿG7DÿH7DÿJ9FÿL:GÿL:HÿJ:FÿH8FÿG8GÿH9JÿN?QÿTEWÿXI[ÿXHYÿRCSÿSASÿ[IZÿ]K\ÿ[JZÿ[JYÿN>KÿA3@ÿI>PÿeZsÿ‚u”ÿ�‚¤ÿ‰{œÿugƒÿ^MdÿK1@ÿ>1Aÿ8,;ÿMAPÿ†x‹ÿ‘‚–ÿ”…™ÿ–‡œÿ��”ÿvfxÿZKXÿI8>ÿD22ÿ>+/ÿ3#$ÿ4&%ÿ2"!ÿ.ÿ1!!ÿ+ÿ/ÿ2""ÿ0! ÿ.ÿ<**ÿ9'&ÿ=*(ÿD14ÿD4<ÿK37ÿH5=ÿG8GÿG:KÿJ=NÿbQdÿxe{ÿ‡v’ÿ�� ÿ‹|šÿn]tÿN?NÿA4?ÿ;0:ÿ!#ÿ ÿ ÿ ÿ-&.ÿF9DÿYHVÿ_M\ÿ`M\ÿbN]ÿfSaÿiVeÿcRaÿJ>Jÿ#!)ÿ!ÿ 'ÿ$&.ÿ()2ÿ0/;ÿ=:GÿA?Mÿ75@ÿ-,5ÿ,*2ÿ.*3ÿ-*4ÿ/,8ÿB>Mÿibwÿ‹›ÿ‹›ÿ…z“ÿbZmÿ7/<ÿH;Iÿ;/<ÿ=0=ÿ@2?ÿÿ>6AÿB:EÿD;GÿA9Dÿ?7Bÿ?6Aÿ?6@ÿB8CÿF=HÿG>IÿG>JÿG@KÿIAMÿKAOÿKANÿKAMÿKANÿKAOÿLCQÿMCRÿMCRÿMBQÿKAOÿJ@MÿI?LÿF=Hÿ?6@ÿ>6@ÿdViÿ|i‚ÿ„pŠÿƒrŒÿƒs�ÿocyÿHDQÿ$!ÿ$ÿ%ÿ$ÿ#ÿ#ÿ#ÿ#ÿ$ÿ# ÿ# ÿ"ÿ"ÿ"ÿ"ÿ!ÿ$#ÿ61:ÿF9FÿKOÿR@QÿTBRÿSAQÿP>NÿJ:HÿA2?ÿ7+7ÿ7.<ÿB:NÿJCZÿOG`ÿRIbÿSJcÿXNgÿcVpÿo`zÿyiƒÿ€o‰ÿ{i…ÿr^zÿgSoÿbNiÿgRnÿjTpÿiSpÿfQnÿfQmÿhSpÿlWtÿp[xÿq[wÿmXrÿbUkÿ\Laÿ\K_ÿ_Nbÿ[K^ÿVFYÿTDVÿRDVÿRDVÿTDXÿTEXÿSEXÿTFZÿREXÿNASÿVH]ÿXI^ÿXH[ÿVFYÿSDVÿVEXÿYHZÿXHYÿVGVÿWGWÿYK]ÿg\sÿoe�ÿ|q‘ÿŽ‚¤ÿŒžÿ~pŽÿqc~ÿi\uÿcWnÿbUnÿcWoÿaWnÿ`Vnÿh\uÿ|m…ÿxg}ÿ}k�ÿ…tŒÿ€pŠÿsd~ÿm`xÿk^tÿi[pÿeWmÿaUjÿaVjÿ_Thÿ]Reÿ^ReÿZNaÿTFWÿYJZÿ`P`ÿ_N]ÿeRbÿgScÿjUcÿnYhÿq]mÿt\kÿs\nÿq]pÿn\pÿn^rÿ{i�ÿˆw’ÿ�œÿŽ~œÿ‚q‹ÿXHYÿL=LÿI5Aÿ3-8ÿ3-8ÿ3,7ÿ2*5ÿ8.8ÿG:EÿUDRÿXFTÿYFTÿ[HUÿZHTÿTDOÿN@KÿC7Aÿ;4>ÿE=KÿLDSÿPHXÿPGWÿQHXÿYOaÿ_VjÿOGXÿ:6Bÿ0.9ÿ3/;ÿ>9FÿNGWÿbYlÿvk�ÿ„vŽÿƒt�ÿ‚tŠÿcYjÿ<4AÿK>Mÿ:.;ÿ9.<ÿ<0>ÿ;/<ÿ9-9ÿ5,8ÿ&"-ÿ%ÿ&ÿ'ÿ$ÿ'ÿ+ÿ ,ÿ +ÿ*ÿ)ÿ*ÿ*ÿ'ÿ%ÿ$ÿ%ÿ&ÿ&ÿ$ÿ%ÿ*ÿ!!-ÿ"#.ÿ#$0ÿ"#0ÿ"#/ÿ"#/ÿ"$0ÿ!#1ÿ!"0ÿ!".ÿ#",ÿ'$,ÿ)&/ÿ+)3ÿ-,6ÿ//8ÿ22:ÿ43<ÿ33;ÿ11:ÿ109ÿ1/8ÿ52;ÿ85?ÿ75?ÿ64>ÿ76@ÿ87Bÿ97Bÿ;9Dÿ=:Eÿ=:Dÿ=9Dÿ<9Eÿ>;Gÿ@NÿP?NÿO=MÿL;JÿF6Dÿ=/<ÿ6*6ÿ90?ÿDKÿ8>Kÿ6Jÿ8>Jÿ8=Jÿ8=Jÿ7=Jÿ6=Iÿ5;Fÿ04?ÿ,-7ÿYRdÿnaxÿwfÿm†ÿ�o‹ÿƒrŽÿyl…ÿ\Tgÿ#+.ÿ$ÿ%ÿ%ÿ$ÿ"ÿ"ÿ#ÿ"ÿ !ÿ !ÿ ÿ !ÿ ÿ ÿ#ÿ%#ÿ()-ÿ9/:ÿE5EÿJ:JÿL:KÿL;KÿLMÿO=LÿM0=ÿ6*7ÿ<1BÿI@UÿSKbÿXNgÿXMgÿUKcÿTKaÿZOfÿeWoÿra{ÿ{j„ÿn‡ÿziƒÿn\wÿhSpÿiSoÿkUqÿlVrÿmWtÿjTqÿiRpÿkTrÿnXwÿ_Vlÿ]SiÿdZrÿj`yÿf\tÿka{ÿnc~ÿocÿndÿod€ÿndÿsi†ÿwl‰ÿmb|ÿWL`ÿcXnÿi^vÿsi„ÿ~s’ÿ�v•ÿs“ÿ€t“ÿ€s’ÿth‚ÿXM`ÿL@PÿNEUÿHAQÿE=NÿMEWÿLDUÿKBSÿPEWÿUI[ÿUI[ÿVH[ÿWI\ÿVI[ÿTHZÿTH[ÿRGYÿF=LÿF>MÿPFXÿXK^ÿZMaÿ\Obÿ\OcÿZM`ÿVJ^ÿXJ_ÿXJ^ÿVH[ÿSFYÿQEVÿLAPÿD9GÿH1?ÿ<0=ÿ.%.ÿÿ ÿ ÿ ÿ +ÿ +ÿ ÿ ÿ ÿ +ÿ +ÿ ÿ + ÿ ÿ + ÿ + ÿ +ÿ +ÿ +ÿ ÿ ÿ ÿ ÿ ÿÿÿÿÿÿÿ%ÿ #,ÿ%(1ÿ*-7ÿ.1;ÿ15@ÿ28Dÿ3;Fÿ4Jÿ7>Kÿ7>Kÿ9@Mÿ;AOÿ:ANÿ:@Nÿ:ANÿ;CPÿ;DRÿ;CRÿ;CRÿLÿ/7CÿNM]ÿbYnÿm_vÿud|ÿzh‚ÿo‰ÿ�qŒÿqd|ÿ@AMÿ)*ÿ$ÿ%ÿ$ÿ#ÿ#ÿ"ÿ "ÿ !ÿ !ÿ !ÿ"ÿ!ÿ ÿ!ÿ"ÿ!ÿ*'-ÿ=1>ÿI9IÿK;JÿKNÿMÿB4?ÿD6BÿH8EÿJ:GÿLMÿQ?MÿRAOÿP?KÿQ?JÿXEPÿaLXÿiQ]ÿtZfÿcnÿˆjvÿŒo{ÿŒp}ÿŽq~ÿŒo|ÿ…ivÿ}cnÿw^hÿpXbÿkR]ÿgOZÿaKVÿ\HTÿgRaÿlXjÿnZlÿlXjÿhUhÿdRdÿbSdÿ\M\ÿRCOÿJ4DÿI>SÿQH_ÿVLeÿWMfÿULeÿWOfÿ]RjÿiZsÿue~ÿ~m‡ÿ†t�ÿ‰v‘ÿ…q�ÿ{f‚ÿnYuÿiRoÿkUrÿnWtÿnXtÿnXsÿG8DÿG8DÿH:GÿJ;IÿJ;HÿK;JÿL;KÿM;KÿN;KÿONÿQ>OÿQ?PÿQ?PÿQ@OÿP>NÿQ?NÿQ?OÿSAPÿUCSÿTBRÿTASÿTASÿTASÿSBSÿSCSÿRBRÿQAQÿRAPÿSBQÿTBRÿSAQÿSARÿUCSÿUDUÿVEWÿWFXÿWFWÿXFWÿXFWÿXEVÿVEUÿVETÿWEUÿXGWÿYHYÿZIZÿ[JZÿ[JZÿ[IZÿ[HZÿ^K\ÿbM^ÿgRcÿr[lÿzbrÿ}csÿ�guÿˆm{ÿ�r�ÿ–v†ÿšz‰ÿ–w…ÿ’r�ÿ“tƒÿ’u„ÿŒo~ÿ„ixÿ€etÿ€esÿ~cqÿy_mÿu[jÿoWfÿhQaÿeN]ÿaKYÿ_JXÿ^IWÿ\HVÿZFSÿYFRÿYFRÿXFSÿWDQÿWDPÿWCPÿVCPÿUBOÿTANÿTAOÿS@MÿR@MÿQ?LÿN=IÿL;GÿH7CÿE5Aÿ:/8ÿÿ ÿ ÿ!ÿ2/0ÿ<69ÿ""ÿÿÿ ÿÿÿÿ)*5ÿ>7FÿE6Fÿ8*7ÿ7*6ÿ8+7ÿ8+7ÿ<-9ÿA1;ÿ>.6ÿ<,3ÿ2%*ÿÿ ÿÿÿÿ ÿ ÿ ÿÿÿÿÿÿÿÿÿÿ ÿ ÿÿ ÿ +ÿ!ÿÿ ÿ ÿÿDBNÿiaqÿ{q�ÿ}s‚ÿu…ÿ�w†ÿ‚yˆÿƒz‰ÿ„{Šÿ„|Šÿ…|Šÿ…|Šÿ„|Šÿ„|Šÿ„|Šÿ„}Šÿ„}‹ÿ…}‹ÿ…}‹ÿ„}Œÿ„}Œÿ…~Œÿ†~�ÿ†~Žÿ†�ÿˆ€�ÿ‰€‘ÿ‰€�ÿ„|‹ÿwp~ÿ}v…ÿƒ|Œÿ„~�ÿ‚|Œÿ~y‰ÿZZjÿSSfÿc\qÿcVlÿn\sÿubzÿ|i‚ÿnˆÿtf~ÿCAMÿ)(ÿ#ÿ$ÿ$ÿ#ÿ#ÿ$ÿ$ÿ$ÿ% ÿ% ÿ% ÿ$ÿ#ÿ"ÿ!ÿ"ÿ$'+ÿ8/;ÿB5CÿH8IÿK:KÿL;LÿNLÿO?NÿN>MÿO>NÿQ@PÿR@RÿTASÿVCUÿWDVÿWDVÿXEXÿYFYÿYFXÿXEXÿXEWÿWDUÿWDUÿXFWÿXFXÿXFXÿXFXÿYGYÿYGYÿZHYÿYGYÿZHZÿ[HYÿZGYÿZFYÿYFXÿYGXÿ[HZÿ[HZÿ[H[ÿ[I\ÿ\J\ÿ]J\ÿ]I\ÿ]J\ÿ]K\ÿ]J\ÿ\I[ÿ[I[ÿZI[ÿ[I[ÿ]J\ÿ^K]ÿ^K]ÿ^K^ÿcOaÿgRdÿnWiÿy`rÿƒi{ÿ…j|ÿ‡k|ÿŽr�ÿ˜zŠÿ™z‹ÿ–xˆÿˆkzÿ|^nÿ~apÿ{`oÿqYhÿkTcÿmTdÿqXhÿt[jÿu\lÿsZkÿmVgÿiRdÿeO_ÿbL\ÿ`K[ÿaL]ÿdO_ÿdO_ÿ`L[ÿ_KYÿ`KZÿ`KZÿ_JXÿ^IXÿ\HWÿ[GVÿZFTÿYFSÿXESÿWDRÿUBQÿSANÿP?LÿM;HÿF7Bÿ4.4ÿÿ ÿ ÿ%#ÿ857ÿE>Cÿ#((ÿÿÿÿÿÿ ÿ/-8ÿ@6Dÿ@0<ÿ9*6ÿ8*4ÿ:+6ÿ;,7ÿ>.9ÿD3>ÿJ6@ÿN9@ÿA16ÿÿ ÿÿÿÿÿ ÿÿÿ!ÿ!ÿ!ÿÿ ÿ!ÿ"ÿÿ ÿ ÿÿ ÿ ÿ%ÿ#ÿÿ + ÿÿ@?Jÿoguÿˆ|‹ÿ‹~�ÿ�Žÿ���ÿ�‚‘ÿ‘„“ÿ’…“ÿ’†”ÿ”†”ÿ”‡”ÿ“‡”ÿ“‡”ÿ“‡”ÿ“ˆ•ÿ“ˆ•ÿ“ˆ–ÿ”ˆ–ÿ”ˆ—ÿ”‰—ÿ”Š—ÿ•Š˜ÿ–Ššÿ–‹›ÿ—‹œÿ–‰šÿ•†—ÿ�€‘ÿsftÿr�ÿ�ƒ“ÿ–Š›ÿ–Š›ÿ•Š›ÿql|ÿUVgÿZWlÿf\rÿjZqÿq^uÿwd}ÿ}l‡ÿ~n‰ÿdYnÿ::Dÿ$!ÿ#ÿ$ÿ#ÿ$ÿ$ÿ$ÿ$ÿ$ÿ% ÿ$ ÿ$ÿ#ÿ"ÿ!ÿ"ÿ$"ÿ&),ÿ6.8ÿA3BÿF7GÿJ9JÿL;LÿO=OÿO=OÿL;KÿK:IÿL:IÿK9HÿI8GÿG6FÿB3Bÿ9-:ÿ2(5ÿ>5EÿIBUÿPI`ÿVMgÿYQjÿWNgÿQG`ÿUJcÿdXrÿm^yÿudÿ}k…ÿƒpŠÿ„qŒÿ|i…ÿr^zÿmWsÿlVqÿmVrÿLMÿP>NÿO>NÿP?NÿSAQÿTBSÿTBTÿVDUÿXEVÿYFWÿYFWÿYEWÿXDVÿYFYÿYFXÿYEWÿXEWÿXEWÿYFYÿYFYÿYGZÿZGYÿZHYÿYGXÿ[I[ÿ\I\ÿ\HZÿYFXÿXEXÿYFYÿ[HZÿ\I[ÿ\IZÿ[HZÿ[HZÿ\I[ÿ\J[ÿ]J\ÿ\I[ÿ[IZÿYGYÿVDVÿRARÿQARÿQASÿUCUÿYGWÿ\IZÿ\I[ÿ^J\ÿ_K\ÿ_K\ÿ_L\ÿ^L]ÿ^K]ÿ`L]ÿkUeÿy`pÿw^pÿqYjÿiPbÿfO`ÿlUfÿfQaÿ_L[ÿ^JZÿ_IYÿ^HYÿcM^ÿhQbÿhQbÿePaÿeOaÿbM^ÿ_K[ÿ]IYÿ`L]ÿiSeÿlVgÿcN^ÿ]IWÿ]IXÿ_JZÿ]IXÿ]IXÿ\HWÿ[GUÿZFTÿYESÿWDRÿUBPÿTANÿS@MÿP=JÿM;Gÿ?4=ÿ''(ÿ ÿ ÿÿÿÿÿÿÿÿ ÿ ÿ ÿ ÿÿ($*ÿ7*4ÿ5)3ÿ5)3ÿ9+6ÿ;,8ÿ9+6ÿ:,7ÿS7GÿKCXÿRJaÿTMeÿULdÿUKcÿWMfÿ]RlÿdWqÿj]vÿpazÿwg€ÿ€m‡ÿƒp‹ÿ‚n‰ÿzf€ÿq\wÿmWsÿJ:IÿM=LÿP?OÿR@QÿR@QÿRAQÿTCSÿWEVÿWEWÿWEVÿYFWÿYFWÿXEWÿWDWÿXEWÿZHZÿZGZÿZFYÿZFXÿZFXÿZGZÿ[H\ÿ[H]ÿZH[ÿXFXÿYFYÿYGYÿZGYÿYFXÿXEWÿYFYÿZHZÿ[H[ÿ\HZÿ[GYÿ[GZÿ[H[ÿ[I[ÿ\I\ÿ\I[ÿWEWÿQAQÿJ;LÿE7GÿD6EÿD6FÿH9IÿM=MÿTBSÿZGYÿ\I[ÿ\H[ÿ\H[ÿ[IZÿ[IZÿ\J[ÿ\J[ÿ]J[ÿ^K\ÿ`K]ÿ_K\ÿ\IZÿ\HYÿ^I[ÿ_K]ÿ]IZÿ[IYÿ\HYÿ]HYÿ]HYÿ]IZÿ`L]ÿ`M]ÿ`L]ÿ_K\ÿ]IZÿ\HYÿ[HXÿ\HYÿ`K]ÿbM^ÿ^JXÿZHUÿZGUÿ[GVÿ[HVÿ[GWÿZFVÿXDTÿXDSÿWCRÿVCQÿTAOÿR?LÿQ?LÿO2>ÿ;0;ÿ:.:ÿ1>ÿÿaJVÿeLXÿJ8Aÿÿ ÿÿÿÿÿÿÿÿ +ÿ +ÿ ÿÿ ÿ ÿÿÿÿ ÿÿÿÿ +ÿ ÿ +ÿÿÿ+1:ÿjamÿ‹}ŠÿŽ�Œÿ�‚�ÿ�~Šÿ…x„ÿ†y…ÿ“…‘ÿ”‡“ÿ•ˆ“ÿ”ˆ“ÿ”ˆ”ÿ•‰•ÿ•‰–ÿ•‰•ÿ•‰–ÿ•‰–ÿ•‰–ÿ–‰–ÿ•Š—ÿ”Š˜ÿ•‹˜ÿ•Š˜ÿ“„”ÿ“‘ÿ�yŒÿŒt‡ÿ†p�ÿo\kÿcQ`ÿvbsÿ�w‰ÿ•“ÿ”‚”ÿ�„•ÿpk{ÿHM]ÿXYmÿg^tÿp`wÿwd|ÿ}j„ÿ‚pŒÿƒqŽÿtg~ÿNJXÿ%#ÿ#ÿ"ÿ"ÿ"ÿ"ÿ"ÿ#ÿ "ÿ "ÿ#ÿ"ÿ"ÿ"ÿ#ÿ"ÿ!ÿÿ)%,ÿ9.<ÿC4EÿF7GÿG7GÿF6FÿG6GÿH7HÿI8HÿI7GÿI8GÿH8GÿG8FÿE6Dÿ?1>ÿ7+6ÿ6,9ÿ@8JÿMF[ÿOH_ÿNG]ÿQH`ÿXMgÿ^Slÿ`SmÿaTnÿfYsÿo`yÿvfÿ|k…ÿ‚o‰ÿ„p‹ÿ�mˆÿ|h„ÿL;IÿN=LÿR@PÿTASÿS@RÿS@RÿTBTÿXEXÿ[HZÿ[HZÿ[HZÿ[HZÿZGZÿYGZÿYFYÿ[G[ÿ[H[ÿZG[ÿZF[ÿ[G[ÿ[H\ÿ]I^ÿ\I]ÿYGZÿXFXÿXEXÿWEXÿWEXÿXEXÿYFYÿYGZÿ[H[ÿ[H[ÿ[G[ÿZGZÿZH[ÿZI[ÿZI[ÿ[I\ÿZI[ÿUEWÿL>NÿD6Fÿ@2CÿC5EÿK;MÿSCUÿXFXÿYGXÿZHYÿ[HZÿ[HZÿ[HZÿ[HZÿ[HZÿ[IZÿ\I[ÿ\IZÿ[HYÿYFXÿXEUÿWEUÿZFXÿ]HZÿ]HZÿ\IZÿ[IZÿ\HYÿ]HYÿ\HYÿ]IZÿ]J[ÿ^K\ÿ^K\ÿ]J[ÿ]IZÿ[HYÿYFWÿYFWÿZGWÿ[HXÿZGVÿXESÿWDRÿXESÿYFTÿ[GXÿ_L_ÿbOcÿ`N`ÿ\J[ÿYGWÿUBPÿQ>KÿP=KÿM;IÿL=Iÿ818ÿÿ ÿ ÿ ÿ ÿ ÿÿÿ ÿ ÿ ÿ ÿ ÿ ÿÿ,)/ÿA4Aÿ@4Aÿ?3Aÿ@3BÿA4Bÿ@3AÿC5DÿiScÿjScÿJ;Fÿÿ +ÿ ÿ ÿ ÿÿÿ ÿ ÿÿÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ +ÿ ÿ ÿ ÿ"ÿ"ÿ!ÿ$ÿ!*3ÿh`kÿŒ‹ÿ‘ƒŽÿ“„�ÿ�~‰ÿ~q}ÿrÿ•‡’ÿ•‡“ÿ”‡“ÿ”ˆ“ÿ•‰”ÿ–‰•ÿ–‰–ÿ–‰–ÿ–‰–ÿ–Š–ÿ–Š—ÿ–Š—ÿ•Š˜ÿ•‹˜ÿ–‹˜ÿ“ˆ•ÿ†y‡ÿyiyÿzfxÿ‚m~ÿ†p�ÿ�k|ÿu`qÿxdtÿ�m}ÿ€m}ÿzhyÿ�€�ÿ�yˆÿXYhÿCHZÿa[qÿk_uÿud{ÿk…ÿ‚oŠÿ‚qŒÿo‰ÿf\oÿ8;Bÿ# ÿ!ÿ"ÿ !ÿ!ÿ"ÿ$ÿ%ÿ#ÿ"ÿ!ÿ!ÿ!ÿ"ÿ!ÿ ÿÿ""ÿ/)2ÿ>0?ÿC4DÿG7GÿH8GÿH8HÿI8IÿH8GÿG6FÿF5EÿF5EÿG6EÿF6DÿC3Aÿ=/<ÿ7*7ÿ7-<ÿ@8KÿKDZÿLD[ÿNE]ÿVLeÿ_UnÿaVpÿ_Toÿ_SnÿdWrÿm_yÿue€ÿ{i„ÿ€mˆÿ„oŠÿ…q‹ÿO=LÿQ?OÿTARÿUBTÿUBTÿUBUÿWCVÿYFYÿ[H[ÿ]I\ÿ\I\ÿ]I\ÿ\I]ÿ\H\ÿ[G[ÿ[H\ÿ\I\ÿ[H\ÿZG\ÿ[H]ÿ]J^ÿ^J^ÿ\I]ÿYHZÿXFXÿVEXÿVEWÿVEWÿWEXÿYGYÿYGZÿZG[ÿ[H\ÿ[H\ÿ[H\ÿZH[ÿZI[ÿZI[ÿ[I\ÿZI[ÿTDVÿM>OÿKNÿQ@QÿVEWÿ[I\ÿ]J]ÿ[IZÿZHXÿYGXÿZGYÿZHYÿ[HYÿ[HZÿ[HYÿZHZÿ[HZÿZGXÿYFWÿWETÿYFVÿ[GXÿ\GYÿ\GYÿ\HZÿ]J[ÿ_K\ÿ`K\ÿ_K\ÿ_K\ÿ^J\ÿ_K]ÿ_L]ÿ]J[ÿ]J[ÿ[HYÿYGXÿYFWÿXGVÿYGVÿYFUÿXDSÿVCQÿVBQÿWCSÿ^K^ÿdTiÿhYoÿiYoÿeUkÿ^M`ÿVDTÿQ>MÿO=KÿL;IÿA6@ÿ+),ÿ ÿ +ÿ +ÿ ÿ ÿ ÿÿÿÿ ÿ ÿ ÿ ÿ ÿÿ+(/ÿA4BÿB5CÿA4CÿB5DÿB5Cÿ@3BÿC5EÿlXlÿkXkÿH=Iÿ!ÿ"ÿ &ÿ (ÿ!)ÿ!(ÿ")ÿ")ÿ"*ÿ#*ÿ")ÿ#*ÿ#*ÿ$*ÿ#)ÿ!(ÿ!(ÿ!(ÿ 'ÿ'ÿ 'ÿ!(ÿ#*ÿ$+ÿ"*ÿ 'ÿ#+ÿ)2ÿf_jÿ�€Œÿ”†‘ÿ•‡‘ÿ�Šÿxlwÿxmyÿ—‰”ÿ—‰”ÿ–‰•ÿ–‰•ÿ—‰•ÿ—‰–ÿ—‹–ÿ—Š—ÿ—Š—ÿ—Š—ÿ—‹—ÿ—‹˜ÿ’…‘ÿ‘„�ÿ”ˆ•ÿ’‡“ÿ{r~ÿXQ^ÿPGUÿ_R`ÿgXfÿjYhÿcSbÿ`R`ÿ_S_ÿXMYÿTKWÿ‡{‡ÿ’‡“ÿtn{ÿ=CRÿRRfÿaZpÿqbzÿ~kƒÿ‚p‰ÿ‚p‹ÿƒqŒÿxi�ÿZRcÿ**ÿ!ÿ !ÿ!ÿ"ÿ#ÿ$ÿ$ÿ#ÿ!ÿ ÿ ÿ!ÿ!ÿ!ÿ ÿ ÿ ÿ"%'ÿ2*4ÿLÿMHÿ91?ÿC4CÿF6EÿF6FÿF6FÿI8HÿI8HÿG6FÿE4DÿD4DÿE5FÿD4DÿA2@ÿ:-;ÿ3(6ÿ0)6ÿA:KÿLEZÿQJbÿVMhÿ]TnÿaVqÿbWrÿ`Vpÿ]Rmÿ_TnÿbWoÿh[rÿn`wÿsczÿSCUÿTCTÿTCTÿTBSÿSAQÿRAQÿRARÿSBRÿUCTÿWFXÿWFXÿVDVÿVDWÿWEXÿWEWÿWDWÿWEXÿYG[ÿZH\ÿXFZÿYFYÿZH[ÿWFYÿTDVÿTCVÿTCVÿVFXÿWGYÿXGYÿYGYÿWFXÿWEYÿXFZÿZH]ÿ[J_ÿZJ]ÿZJ[ÿZJ[ÿZI\ÿZH\ÿXFYÿWFXÿWFXÿXGYÿZI\ÿ[I\ÿZH[ÿYGYÿYGYÿYGZÿXGZÿXGYÿXFXÿWEWÿXEXÿZGYÿZGZÿXEXÿUDUÿTBSÿVCTÿVEUÿWEVÿXEVÿYGWÿ[IYÿ]K[ÿbM^ÿePaÿfPbÿdOaÿdN`ÿdN_ÿbM^ÿ_L\ÿ^K\ÿ[HYÿ[HYÿ\JZÿ[HXÿXGUÿVESÿUCRÿTAQÿS@PÿS@PÿSBRÿSCRÿSCRÿTCRÿSBPÿP@NÿN>LÿM=JÿKÿ)2?ÿ)2>ÿ&1=ÿ$0<ÿ"0:ÿ .8ÿ-5ÿ+3ÿ,4ÿ,5ÿ+3ÿ*2ÿ+3ÿ+4ÿ,3ÿ,3ÿ+3ÿ*1ÿ,4ÿ*4ÿYYfÿ„}�ÿ•Š›ÿ–‹›ÿ”ˆ—ÿ{q~ÿtjuÿ•‰”ÿš�šÿš�šÿš�™ÿ™�™ÿ™Œ˜ÿ˜�˜ÿ˜�—ÿ™Œ—ÿšŒ—ÿšŒ˜ÿ™‹—ÿ‘�Œÿ’‚Žÿ—Š–ÿ˜‹—ÿ•‰•ÿ‰‹ÿsnyÿ`_jÿWXcÿAHSÿBHSÿOR\ÿ\\fÿjfpÿ€x‚ÿ”ˆ’ÿ›�˜ÿ“‡“ÿ{t�ÿFIWÿYWjÿe^sÿpbyÿ…r‰ÿƒp‰ÿ‚p‰ÿ‚pŠÿ}l„ÿg[mÿ239ÿ ÿ ÿ!ÿ#ÿ"ÿ!ÿ!ÿ ÿ ÿ ÿ!ÿ!ÿ!ÿ ÿ ÿ!ÿ!ÿÿ %ÿ5,7ÿ>1?ÿC5DÿF7FÿG6EÿH7HÿI9HÿH7FÿE5DÿD4DÿD4EÿE5FÿD4Dÿ@2@ÿ9-;ÿ1(4ÿ4,8ÿB:LÿNF^ÿULgÿZQkÿ]Rlÿ`UpÿaWqÿ^Tnÿ]RlÿYOiÿZOgÿ^QgÿcSiÿTEXÿRCUÿL=LÿE6DÿE6DÿH9HÿH9IÿI:JÿMNÿK=MÿL=MÿK=LÿKÿ13@ÿ14@ÿ14Aÿ15Bÿ36Cÿ48Fÿ59Hÿ59Hÿ59Hÿ39Hÿ08Eÿ.6Bÿ.5Aÿ-5Aÿ,4@ÿ,3?ÿ*3>ÿ(2<ÿ(1<ÿ&0;ÿ%0:ÿ$09ÿ%09ÿ%09ÿ%0:ÿ$0<ÿORaÿyt‡ÿ’ˆ�ÿ“ˆ›ÿ“‡˜ÿzm|ÿl^jÿŠ|‰ÿ“…”ÿ–‰–ÿ—Š—ÿ—Š–ÿ—Š•ÿ—Š”ÿ—Š•ÿ—Š”ÿ–Š“ÿ—Š”ÿ—Š•ÿ–ˆ”ÿ–ˆ”ÿ—‰•ÿ—‰•ÿ˜‰–ÿ–‰•ÿ’†’ÿ�„�ÿŠŒÿgdqÿuo}ÿ‡~‹ÿ�„�ÿ“†‘ÿ•ˆ”ÿ—‰•ÿ˜Š–ÿ–‰–ÿŠ€�ÿWVdÿLN`ÿ`Zoÿqd{ÿzhÿ€m…ÿl†ÿmˆÿ€oˆÿwhÿMGTÿ&+.ÿ!ÿ# ÿ# ÿ# ÿ#ÿ# ÿ# ÿ" ÿ"ÿ#ÿ#ÿ#ÿ#ÿ"ÿ"ÿ"ÿ ÿ ÿ)'-ÿ7.9ÿ@2AÿD4CÿE4CÿG6DÿI8GÿI8HÿF6GÿE5FÿF5GÿF6GÿF6FÿD5EÿB4Cÿ>0?ÿ7+8ÿ9/?ÿF=SÿTKeÿZPkÿYOiÿZPjÿ^TnÿbWqÿbWpÿ^SlÿZNgÿWKcÿWJaÿH:JÿF9HÿB6DÿA4BÿF7GÿKPÿN@RÿQDVÿOAUÿH;Lÿ?4Bÿ;0<ÿB6DÿPCTÿXJ^ÿZKaÿYI_ÿUEYÿPATÿK=OÿNAUÿUG\ÿWI_ÿ[LcÿYK`ÿXJ_ÿUG\ÿN?RÿN?SÿN?TÿPBWÿSEZÿTF[ÿXI]ÿ[Maÿ]Ocÿ\NcÿXK`ÿVI_ÿUI^ÿWJ_ÿZKaÿ[Mcÿ^Ogÿ_PhÿcSkÿeUmÿbRiÿ]McÿbRhÿgVmÿhXoÿgWmÿdTjÿ_Pfÿ[McÿYLaÿYKaÿ[Mcÿ^OeÿaQgÿbRiÿaQgÿ^NcÿZJ]ÿWH[ÿVGZÿUFYÿQCUÿPCSÿOBQÿOAQÿSDUÿXHZÿ[J]ÿ_Ncÿ`Peÿ[M_ÿSEVÿRDUÿVGZÿZJ^ÿ^Mbÿ`Pfÿ`Odÿ_Ncÿ^Mbÿ\L`ÿZK^ÿ[L^ÿZK]ÿXI[ÿWH[ÿUGYÿQDUÿLAPÿI?NÿJ@PÿLAQÿNCTÿLARÿKARÿPFYÿRFYÿTH[ÿSGZÿQEWÿRHYÿUI\ÿTH[ÿVJ]ÿ\NcÿbRgÿ^NcÿUFXÿVGZÿ[L`ÿ[L`ÿ_OdÿhVlÿeTiÿ\M`ÿVJ]ÿRGZÿSGZÿTI\ÿRGYÿKBSÿMDUÿMETÿNFUÿPGXÿQHZÿNFWÿKDTÿG@OÿE>MÿGBPÿIBSÿIBRÿKCSÿLDUÿKCTÿE=Lÿ@:GÿB:IÿDÿ77?ÿ66=ÿ46=ÿ46=ÿ77=ÿ87>ÿ66<ÿ55<ÿ228ÿ-04ÿ-/5ÿ42:ÿ@8DÿG:IÿK;JÿMÿ<1>ÿ>1@ÿB4DÿI:KÿQATÿVFZÿVG[ÿUGZÿSEYÿH;Mÿ=2Aÿ9-:ÿ>1?ÿI;LÿTGZÿWI\ÿYJ^ÿYI^ÿSDXÿJ=OÿL?RÿUH\ÿWJ_ÿOATÿOAUÿMATÿL@SÿK>QÿJLÿH?MÿH?MÿH>LÿKANÿMDRÿPFUÿSHXÿSGWÿRGVÿSIXÿSIXÿQGUÿQGVÿQHVÿPFUÿMCRÿI@NÿJ@NÿNAPÿQBRÿSDTÿVFVÿUDUÿSBRÿSCTÿUDVÿTCUÿSBTÿXFWÿ[I[ÿ\J]ÿ\J\ÿ[JZÿ[J[ÿZIZÿXI[ÿZJ]ÿ^Naÿ`OcÿaQfÿcTjÿeUkÿeTjÿdThÿeSiÿfTkÿgWmÿ9-9ÿ9-:ÿ=0>ÿC4DÿI:KÿRBUÿZJ_ÿ[K`ÿUFYÿK>Nÿ:/<ÿ8-8ÿA4BÿKMÿL?OÿM?OÿSFVÿYL]ÿ[M_ÿYJ\ÿVGXÿVHYÿUGXÿVGXÿYI\ÿXI\ÿ\K`ÿ_OdÿdTiÿiXnÿeTiÿcRhÿbRiÿ^OeÿXI]ÿXH\ÿ^Mbÿ]MaÿYJ]ÿXHZÿSDUÿM?OÿQCTÿZL^ÿ^ObÿVHXÿPBPÿJ1@ÿC5FÿG9IÿOASÿWH\ÿUFYÿH;Lÿ:/<ÿ=1>ÿF:IÿOARÿRCVÿRCVÿXG[ÿRBUÿO@TÿSCXÿTEXÿJ=NÿF9JÿB6Fÿ=1@ÿ8-;ÿ8.<ÿ=2AÿA6FÿB7FÿB6EÿD7GÿB4Dÿ@2Aÿ@2@ÿB5CÿIOÿF:KÿG;LÿN@SÿOBTÿL@QÿJ>OÿM@SÿWH\ÿ]LbÿdQgÿmYoÿu_wÿxc|ÿvd}ÿq`xÿl\sÿiYpÿeUkÿhWnÿlZqÿr^uÿs`uÿ]MaÿVGZÿXG[ÿWG[ÿRDWÿPCTÿM@QÿPCTÿUHZÿUHZÿPBTÿHMÿTFVÿWHZÿPARÿN?PÿN@PÿOAPÿPAQÿL=MÿRBTÿYI\ÿ_OcÿdShÿcQeÿ\K^ÿYI]ÿYI^ÿVH[ÿTFYÿYJ^ÿXH[ÿPARÿJMÿ]NcÿbRfÿ_OcÿZK^ÿWFYÿUDUÿUDVÿ_M`ÿhUjÿn[rÿs_vÿt`wÿvaxÿvaxÿt`vÿq]sÿo\rÿlYoÿfUjÿfVlÿo]uÿq_wÿhWoÿ_Odÿ_ObÿfViÿeTiÿ_Nbÿ\J^ÿcRfÿm\rÿn]rÿr_uÿr_vÿtaxÿxd{ÿucxÿp_tÿkZnÿfViÿgWjÿkZqÿm\sÿl\rÿfVkÿ[K]ÿWGZÿTFXÿVGZÿ[K^ÿ_NbÿYI\ÿYGYÿ[I[ÿZHYÿSBRÿRAPÿ_N`ÿdTgÿ\L^ÿM?NÿN@OÿJÿ<1@ÿA6FÿE:KÿHOÿD7Eÿ?4Bÿ@5DÿB7GÿD8IÿL?PÿQDVÿSFZÿWI^ÿ_PeÿbRhÿbQgÿcQhÿfSjÿgTkÿfTkÿdTkÿbRhÿ^Odÿ\Laÿ^Nbÿ_NaÿaOcÿcRgÿ\MaÿZJ^ÿWGZÿQATÿJ=NÿGMÿSCSÿQBSÿM>NÿTEVÿWHYÿVGXÿUFWÿSETÿRCTÿSEVÿSEWÿPBTÿM@QÿQBTÿTDVÿRCTÿM@OÿI=LÿF9IÿK=NÿUEYÿ\Laÿ_PbÿRDTÿJ=MÿOARÿWHZÿ\L`ÿYJ]ÿSEVÿOAQÿM?NÿN>MÿSCSÿ\J]ÿdRfÿkWlÿjVkÿlXmÿq^sÿubxÿvbxÿvcyÿr_uÿfTiÿ]L`ÿbOdÿbPdÿ\K_ÿXH[ÿWGYÿVFXÿXI[ÿSEWÿN>PÿN>OÿUEXÿZI]ÿZJ]ÿYI\ÿ\L^ÿaPcÿ_Naÿ\K^ÿZJ\ÿ[J\ÿ[J\ÿYH[ÿ`OcÿbQeÿ]M_ÿUFWÿM>MÿG9GÿK=LÿTDUÿWEXÿQARÿO?OÿP?NÿO?MÿM=KÿL=LÿM>MÿVEVÿXHYÿN@OÿI;Iÿ@3@ÿF8GÿTEUÿ\L^ÿXHZÿL=Mÿ>3?ÿ>3AÿM@Qÿ\L`ÿ`Nbÿ`Obÿ^Obÿ[L_ÿZK]ÿXH[ÿYI\ÿZI\ÿWGZÿUEWÿXH[ÿVHZÿTFVÿUFWÿVGXÿWFXÿXGYÿXH[ÿVFYÿQASÿRCUÿWH[ÿ]M`ÿcRdÿbQdÿ\K^ÿTDVÿPASÿUEWÿ_Nbÿ_Maÿ^L`ÿ]L_ÿZJ\ÿWGYÿVGZÿYJ]ÿ]Maÿ_Maÿ\J]ÿXFYÿXFXÿVEWÿN>QÿKOÿN;KÿP=NÿTATÿYFYÿ[G[ÿ[GZÿE7GÿJOÿL>OÿH:Jÿ=0=ÿ:-9ÿA4BÿJ=LÿO@QÿPARÿWGYÿWHZÿTDWÿQBTÿN@QÿNASÿM@QÿK>OÿK>OÿL@RÿK>PÿD9Jÿ>4Cÿ?4DÿF:LÿK?RÿNATÿK?QÿD8HÿB6Eÿ>3Aÿ@5CÿF;JÿJ?NÿF;JÿIOÿUFYÿ^NcÿbRgÿeTjÿiXoÿbRhÿ\Mbÿ\Lbÿ_Oeÿ]LaÿVF[ÿVG[ÿUG[ÿL?RÿIOÿPBUÿPCVÿN@QÿK=NÿH;LÿE9JÿE:IÿE9HÿF9IÿH;KÿJ=MÿG;KÿC7FÿB6EÿF9HÿJ=MÿM?PÿF9HÿH;IÿOAQÿPCTÿN@QÿRCTÿSDUÿQCTÿOBRÿK>NÿK>NÿL?PÿL?OÿJ=MÿF:IÿINÿM?OÿL>NÿK>NÿK>MÿOARÿUEXÿYI]ÿaPdÿTEWÿK>NÿL>OÿO?PÿRCTÿTFXÿTGXÿTGYÿVGYÿRCTÿTDUÿ]M`ÿfTiÿgTjÿcPdÿdQdÿjWjÿn[oÿn[pÿp\qÿp]rÿhUiÿ\J]ÿUDVÿTCTÿTDUÿ\L]ÿ`ObÿYI^ÿXI^ÿXK`ÿRDWÿJNÿO=MÿK;JÿQAQÿSBRÿN>LÿF8GÿB5Bÿ<0<ÿA5BÿM?NÿSFVÿPAQÿM?MÿA4Aÿ6+8ÿA5DÿWG[ÿ\K_ÿbRgÿhYnÿiYnÿgWjÿ_Naÿ\K]ÿ\K^ÿ[K]ÿYI[ÿZJ[ÿWHZÿTEVÿRDTÿTDUÿVEWÿYIZÿ^M`ÿ`Ncÿ^Maÿ]L`ÿ^M`ÿ]L^ÿYIXÿZJ[ÿ\L^ÿWGYÿRBSÿVFWÿ_Naÿ_Maÿ]L_ÿ[K]ÿWFYÿRCTÿSDVÿUGZÿWI]ÿWH\ÿVFYÿO>PÿM;MÿQ@QÿSCTÿQASÿN>PÿN>OÿN?OÿLOÿK>OÿIPÿGOÿQBTÿWG[ÿYI^ÿ[J_ÿ_Nbÿ_Nbÿ_Maÿ`Obÿ_NbÿYI\ÿUFXÿVFYÿVGZÿQBSÿIOÿF:JÿE:IÿA5EÿB7FÿK>OÿREWÿQASÿYI\ÿaPeÿcRgÿaPdÿdTjÿXJ_ÿPCWÿUFYÿ\L_ÿ]M`ÿRDWÿN@SÿL?QÿC7HÿA5DÿC7GÿE9IÿG;KÿK>PÿL?PÿG:JÿC7FÿC7HÿD9JÿD9IÿF:IÿH;KÿJ=NÿM@PÿK>PÿL?PÿL?PÿL?PÿK>OÿK=OÿE9IÿG:JÿNAQÿSFXÿVGZÿVH[ÿUFYÿSDWÿSEXÿPCVÿREWÿOASÿJ=MÿK>NÿJ=MÿL>OÿL?PÿL?PÿL>NÿK=NÿN@QÿRDVÿVG[ÿ\K`ÿ`OdÿWH[ÿQCTÿQCSÿQBRÿRCTÿYJ]ÿZK`ÿWI\ÿUFXÿO@PÿPARÿYJ\ÿ_Nbÿ]K_ÿ\J]ÿ^K^ÿcPcÿhTiÿkWlÿmYoÿp\qÿmZnÿbPcÿSBTÿSCUÿVGYÿ`ObÿdRfÿ]K`ÿUDYÿWH]ÿWI]ÿTFXÿTDVÿSCUÿQARÿRCTÿRCTÿO@PÿN?OÿN>NÿSBSÿ[IYÿ^K\ÿUEUÿP@OÿRBRÿWGXÿZJ[ÿVGXÿVGXÿVHXÿXIYÿ\K]ÿ]K]ÿZI[ÿUDUÿSARÿTBSÿN>MÿTEUÿTDTÿM=LÿH:IÿH;IÿE9GÿD8FÿF9GÿF9HÿF9GÿM?NÿM?NÿB5Cÿ7+8ÿK=OÿYI]ÿ^Ocÿ`QdÿaQdÿaPbÿ\J\ÿXFXÿWFXÿWGYÿWGYÿWGXÿUEVÿRBSÿRBSÿRCTÿWHZÿ\L^ÿ`NaÿbOdÿaOdÿ`NbÿaObÿ`N`ÿZIZÿYIZÿZJ\ÿXGZÿUDUÿVEVÿZI[ÿXGYÿXGYÿZI[ÿZI\ÿWFYÿVFYÿVGYÿTFYÿTEWÿTDVÿN>OÿK:LÿN>OÿSCTÿTDUÿSBTÿQASÿP@RÿO?PÿLPÿL>PÿL?PÿI=MÿH;LÿM?QÿK>OÿM@RÿQCVÿPCVÿK?QÿH;MÿI;NÿH:LÿG:LÿK=OÿO@RÿWI\ÿYK_ÿUH[ÿTFYÿTFYÿRDVÿRCUÿSCUÿRBUÿSCWÿXH[ÿWHZÿUFXÿVGXÿTEVÿO@RÿL>OÿI;KÿC6EÿD6EÿF8GÿF9IÿF:KÿIMÿM>MÿM?NÿM>NÿL>NÿM@PÿL?NÿH;JÿD7FÿA5DÿH;KÿRDTÿXHZÿQBSÿ>0=ÿC6FÿVG[ÿ[K_ÿWGYÿTDUÿQASÿP@QÿN>OÿLOÿN?PÿM>OÿN>PÿRCTÿTEWÿYJ]ÿ\L`ÿ]K_ÿ]J^ÿ\I]ÿ[I\ÿ^L_ÿaNaÿ^L_ÿ[I]ÿYHZÿWEXÿUCVÿTCUÿVDVÿR@QÿQ@QÿUDVÿYI[ÿZI[ÿYGZÿXFXÿVFWÿVEWÿVDVÿTCUÿP@QÿN>OÿR@RÿSBSÿSBSÿQASÿQ@SÿRASÿRATÿM=OÿJ;MÿJ2CÿC5FÿLRÿN?RÿTCVÿWGZÿWI\ÿWH]ÿWG\ÿWH]ÿVGZÿUFYÿSCVÿO?RÿQAUÿQBUÿN@QÿK=NÿJ=MÿIOÿOBRÿOBRÿJ=MÿIOÿL>NÿRCSÿSDTÿXHZÿaPcÿiWkÿmZnÿp[qÿnZpÿdRfÿSBTÿJNÿL=LÿQ@QÿVEWÿWFXÿRCTÿK=KÿH:HÿK=LÿQAQÿTDUÿUEWÿSCUÿQARÿSASÿVDWÿYG[ÿZH[ÿVEVÿN>NÿE7Eÿ@2@ÿ?2@ÿC6DÿH;IÿJ=LÿJ=LÿJ=MÿJ=MÿJ>NÿVGYÿ[K^ÿ[J]ÿXFXÿPAQÿIOÿP>NÿQAPÿTCSÿUCUÿVDVÿXFXÿZH[ÿYHZÿWFXÿQASÿMPÿSDXÿWH\ÿXH]ÿVF[ÿUDXÿWEWÿSBTÿRBUÿTDXÿVEYÿXH]ÿWH\ÿSEWÿQCUÿTEYÿXH^ÿSDXÿL>OÿF:IÿE8HÿF9IÿE9IÿD8HÿF9IÿIPÿK?QÿM@SÿREXÿVG[ÿZJ^ÿ[K_ÿ[K`ÿ\Mbÿ\MbÿYK^ÿZK^ÿ^Nbÿ_PdÿYI^ÿXI]ÿZJ_ÿYI\ÿUEWÿUFXÿVGZÿWH[ÿYJ\ÿ\M_ÿ\M_ÿZJ^ÿXJ]ÿXJ]ÿWI]ÿUG[ÿZK`ÿXI]ÿSEWÿTGYÿWI[ÿWIZÿUGXÿWH[ÿ\NbÿXJ]ÿVI[ÿXJ]ÿYK]ÿVH[ÿZK^ÿ]OcÿbRgÿdSiÿcRhÿaPfÿdThÿgVkÿhWmÿhWmÿfUlÿdUkÿbSiÿdTjÿhXmÿdTiÿbQeÿbQfÿcRhÿcRhÿaPdÿ]N`ÿ[L]ÿWHZÿOAQÿJ;LÿXI[ÿ\L_ÿYH[ÿYI[ÿ[I\ÿZJ]ÿ]MaÿaQeÿaPeÿ]Laÿ[J]ÿVFXÿO@QÿL?PÿTEXÿXI[ÿ[L^ÿ`PbÿeTgÿkXmÿlXnÿeSgÿ[J\ÿRBSÿM>OÿRCUÿQBTÿJ:JÿA2@ÿB3AÿM>OÿRCUÿPBSÿM@PÿREUÿVH[ÿ[K_ÿ\L^ÿXHYÿSBUÿG9GÿB4AÿKNÿO=MÿSAQÿP>NÿG8EÿB4AÿD7FÿD7Gÿ@4BÿA4CÿJ=MÿN@PÿOBRÿQDTÿTFWÿXIZÿ\L_ÿ_M`ÿ]K^ÿ\J]ÿ\J]ÿPBSÿN@RÿUGYÿ]M`ÿ^L`ÿQARÿJ;KÿH:KÿK=OÿM@QÿM@RÿL?PÿM?PÿPBSÿVFXÿ\K]ÿ[K]ÿZI\ÿZH\ÿZH[ÿVDVÿP?PÿP@PÿP@PÿLOÿUDUÿXGYÿYI[ÿVFXÿUDVÿTBSÿRARÿSBRÿSCSÿO?PÿP?PÿUDVÿYI\ÿXHZÿUFXÿO@QÿI9JÿH8HÿO=NÿLQÿJNÿO>OÿN>NÿLOÿM?OÿXHZÿ`Obÿ^L`ÿZI]ÿWG[ÿUFYÿVGZÿSEWÿQBTÿRCTÿVFXÿZJ]ÿ^M`ÿ_Naÿ]L_ÿ[J]ÿ[J[ÿXFWÿUDUÿUDUÿTDVÿSCTÿQCRÿRBRÿVFWÿZJ\ÿ[J^ÿXGZÿZI\ÿYGZÿTCTÿQARÿQBRÿP@PÿO?PÿRBTÿVFXÿVGXÿTEXÿRBUÿQ@SÿP?QÿO?OÿQASÿO@RÿN?PÿTCUÿTBUÿQ@RÿP@QÿSCTÿVGYÿXG\ÿ]K_ÿ^L`ÿ^Laÿ`Mbÿ]Kaÿ]Kaÿ\J`ÿZI]ÿXH[ÿZL`ÿYJ]ÿXH\ÿWG]ÿUF\ÿUF[ÿYI_ÿXI^ÿTFZÿQCWÿPATÿQBVÿTFZÿWH]ÿXH^ÿZI_ÿ[KaÿYJ_ÿVG[ÿTEYÿSCXÿO@TÿN?SÿO@TÿPAUÿRCWÿTFZÿSFYÿPBUÿJ1?ÿ=1?ÿ<1?ÿ>3BÿC7HÿA6FÿE:JÿL?PÿN@RÿPBSÿN@RÿOATÿOBVÿMAUÿQDXÿVH[ÿUFXÿPBTÿPBTÿPASÿTEXÿUEYÿUFXÿVGYÿRCUÿUFXÿWGZÿVG[ÿUGZÿTFYÿYI\ÿ\J]ÿ]K^ÿ_Maÿ`NaÿbPeÿbQfÿ_NcÿYJ^ÿTFXÿYJ^ÿZK^ÿXI[ÿYI\ÿ_Ncÿ_Ncÿ\K`ÿYH]ÿYI]ÿXH\ÿWH[ÿUGZÿTFZÿWH\ÿ\Laÿ^Maÿ`Naÿ_Naÿ]L_ÿ`Ocÿ`NbÿaNcÿbPeÿaPeÿdShÿeTiÿfShÿeRfÿcQeÿeShÿhUlÿgUkÿcQfÿ`Nbÿ[J_ÿZJ^ÿZI]ÿZI]ÿ[K_ÿYJ\ÿ\K^ÿ]L_ÿ`NaÿbOaÿZHZÿYH\ÿ[J_ÿZJ_ÿYI]ÿ^M`ÿ_Naÿ]M_ÿXI[ÿRDUÿTEWÿVGYÿXHZÿWFYÿWEXÿ[I^ÿ\J^ÿVDVÿP>OÿP@QÿQCTÿWI\ÿZK^ÿYJ\ÿXI[ÿYI[ÿYI[ÿ[J\ÿ\J[ÿUDUÿM>NÿM?NÿVGYÿ]M`ÿ\L_ÿ]L_ÿZH[ÿ[I\ÿ[I]ÿVEWÿSCTÿRCTÿQARÿP@PÿPAOÿLNÿJ=MÿK>MÿL?OÿL?OÿK=MÿL>NÿQBTÿXH[ÿ^Maÿ_Laÿ[I\ÿZH[ÿ[J]ÿ]K_ÿ_MaÿSBUÿH9JÿL=NÿZJ]ÿaPeÿbPfÿ`Odÿ\K_ÿXH[ÿVFYÿSCUÿSCUÿWFXÿZJ\ÿ[K]ÿ]L_ÿ\K^ÿZI[ÿXHYÿTCTÿTDUÿVFXÿXGYÿXGYÿWHYÿVFWÿXHYÿZI\ÿYH[ÿWFYÿYI\ÿXHZÿTDVÿQARÿP?PÿN>NÿM=OÿOARÿTFWÿWGYÿXG[ÿVEYÿTCVÿQ@SÿM=MÿRBSÿSCUÿRASÿSBTÿR@TÿN=OÿM=NÿP@RÿUEXÿZJ^ÿZI]ÿXH[ÿXG\ÿ[I^ÿZH]ÿZH^ÿYH]ÿXG\ÿYI]ÿ[L`ÿ[K`ÿ[K`ÿZI`ÿWG^ÿXH^ÿ[Kbÿ]LcÿZJ`ÿTF[ÿRCWÿQCVÿTFZÿXJ_ÿYJ_ÿVF\ÿVG\ÿUH\ÿTGZÿTEXÿSDYÿPBVÿL>QÿJPÿPBUÿQDXÿREXÿQCVÿL>PÿD6Fÿ@3Cÿ=1@ÿ<1?ÿ@4DÿD7HÿD8IÿH=NÿM@RÿN@RÿSEXÿSDXÿRDWÿSDXÿRDYÿRDXÿUGYÿRDUÿM?QÿN@RÿRCVÿXH\ÿXH]ÿWH[ÿXI\ÿUFYÿUFYÿTEWÿREVÿSFXÿQEVÿTFXÿVFXÿXGYÿ[J]ÿ[J^ÿbQfÿeSiÿcRgÿ`Qfÿ_OdÿaQfÿ_Odÿ^Maÿ_ObÿaPeÿ`Odÿ\J_ÿXH[ÿZJ_ÿ[K`ÿYJ^ÿXJ^ÿZK`ÿ^NcÿbRgÿeTiÿcQeÿ^M`ÿ[J]ÿ[J]ÿZI\ÿZH]ÿZH]ÿZI\ÿ^MaÿbOcÿdQeÿaPcÿ\K^ÿbPfÿeSiÿfSiÿdShÿcQfÿaPeÿaPfÿ`Odÿ_Ncÿ`Odÿ`OcÿaOdÿaOcÿ_M`ÿ\J\ÿXFXÿZI\ÿ\L`ÿ]Mbÿ^Mbÿ^Maÿ^L`ÿ\K_ÿYH[ÿSDVÿQBTÿTEWÿWGZÿWGZÿVEXÿ[I^ÿZH]ÿUCVÿRATÿVFXÿYJ]ÿ_Pcÿ`Qdÿ^Naÿ[K]ÿYI[ÿXHYÿ\J\ÿ^K]ÿYHYÿP@PÿN?OÿSEUÿVHYÿUFWÿXHYÿZI[ÿ]K^ÿ^K^ÿZHZÿXGYÿ[J\ÿYHZÿSBSÿM?MÿL=KÿM>NÿO@QÿP@QÿN>NÿO?PÿK=MÿJ=MÿNARÿTDVÿPARÿM?OÿM@OÿOAQÿO@PÿL>MÿM?NÿQBRÿVEWÿYGZÿ]K^ÿ\J^ÿ]L_ÿ^M`ÿ_LaÿbPeÿ[J^ÿL=NÿD5FÿP@Sÿ]LaÿaOeÿbPeÿ_MaÿYI\ÿYI\ÿTDWÿTDWÿXHZÿYI[ÿYI[ÿZI[ÿYIZÿXGXÿTDUÿN>OÿN>NÿQBRÿUDVÿUEWÿVFXÿWGYÿXH[ÿXH[ÿXH[ÿXH[ÿXH[ÿWGZÿVFXÿSCUÿP@QÿM=NÿKOÿP@QÿO>OÿLQÿSDXÿSCVÿQBUÿRCUÿSCVÿSCVÿRAUÿSCWÿUFZÿWG\ÿUFZÿUFZÿXG]ÿYG]ÿUDZÿWG]ÿZJ`ÿ]Lbÿ\KaÿVG]ÿSDYÿSDYÿUG\ÿYK_ÿZJ_ÿSCXÿQCWÿTG[ÿVI\ÿUFZÿRCWÿRDVÿNARÿK>OÿL>OÿM?QÿN@SÿQBVÿSEYÿRCVÿM@RÿN@SÿL>PÿK=OÿN@SÿKNÿQCTÿQCTÿPCUÿSEWÿXGZÿXGZÿUFXÿVHZÿYI\ÿYI[ÿWGXÿWGXÿXGYÿZGZÿ\I\ÿ_L`ÿ`MaÿcPdÿdQeÿaNbÿaNcÿ`NbÿVEWÿH9IÿH9KÿWFZÿ\K`ÿ^Laÿ^Maÿ\Laÿ\LaÿWG\ÿWH[ÿ\K^ÿ\L^ÿ[J\ÿZI\ÿXHZÿUEWÿRBTÿP@QÿLPÿKOÿN?QÿPATÿN?RÿJOÿPASÿSCVÿSDWÿM>OÿK=NÿK=MÿN@QÿUFYÿVEXÿVEWÿVEWÿSBTÿO?QÿSCVÿRBTÿL=MÿIPÿTCVÿXGZÿXH\ÿXH]ÿYI^ÿWF[ÿWF[ÿ[J_ÿ\KaÿUFXÿUGXÿWHZÿXH[ÿYI\ÿWFYÿ^Laÿ]Laÿ[J^ÿ]L`ÿZH[ÿXFYÿZI]ÿ_Nbÿ`Naÿ[J\ÿXGZÿXFYÿWFXÿUDWÿTCVÿYH\ÿ^Laÿ`OdÿdQgÿdRgÿaPdÿ\K_ÿWGZÿVFYÿ\K^ÿ\K^ÿZJ]ÿXHZÿVFWÿ\J\ÿbOcÿbOdÿ`Maÿ^K_ÿ]K_ÿ]K^ÿ^MaÿaOdÿcQfÿaOdÿ]Laÿ[I]ÿZI[ÿ[K]ÿ_Naÿ]L`ÿ[J^ÿ\L_ÿ_N`ÿ[J\ÿ[J\ÿ]L`ÿ]Lbÿ\J_ÿ\J^ÿ_Maÿ`Mbÿ\J_ÿVFYÿWHZÿXI[ÿZJ]ÿYI]ÿWG[ÿZI\ÿ\K^ÿaOcÿbQeÿ^L`ÿ]K_ÿ^L`ÿ\I]ÿXFYÿWFXÿXGYÿ[J]ÿ]K^ÿ_L`ÿaNbÿ_L`ÿ^K_ÿ]K^ÿ\K^ÿ[I[ÿUDVÿUEWÿZI\ÿ]K^ÿ[I\ÿXFYÿWEWÿTCVÿO@QÿH:IÿC5CÿB4BÿG8GÿN?OÿSDWÿUGYÿTEWÿSCVÿUDWÿYGZÿ]K_ÿ^Naÿ^Nbÿ^Maÿ]L^ÿZI[ÿXGYÿWFXÿYFYÿ\J]ÿaNcÿdQfÿfSgÿfSgÿdQfÿ`Ncÿ]K_ÿVDVÿI:Iÿ@2@ÿKQÿN?QÿO@RÿQASÿP@RÿO>PÿN=NÿK;KÿH8IÿD5GÿF7HÿK;LÿM=OÿI:LÿK;LÿJ:JÿH9IÿI:KÿKPÿPASÿVEYÿVEYÿP@RÿP?RÿRASÿRBSÿPARÿO@RÿO@RÿN>OÿM>OÿO?RÿRATÿSATÿO=OÿQASÿTEXÿSBUÿVDXÿQATÿP@QÿQARÿSBSÿSBSÿQASÿRBUÿRCUÿM?NÿB5CÿD6DÿH9IÿJ:KÿK;JÿI;JÿG9HÿH9GÿL=LÿRCTÿRBTÿSBTÿO>OÿI9HÿF7EÿE7FÿF7GÿG9IÿL>OÿQASÿLPÿRBUÿUEZÿWF\ÿZI]ÿWEYÿYG[ÿ]J^ÿ[H]ÿTCUÿP@PÿP@PÿTDTÿWGWÿUDUÿXHZÿWH[ÿUEXÿVDWÿQARÿSBTÿTDWÿTDWÿTCTÿTDUÿVFXÿZJ[ÿWHYÿKOÿN>NÿQ@PÿSCUÿXHZÿUFWÿQARÿQ@QÿVEWÿ\J]ÿ\J]ÿ[J\ÿZI\ÿZI\ÿ\I\ÿYGYÿUCUÿVDVÿ[J]ÿ_Maÿ_L`ÿaNaÿbObÿ`M`ÿ]J^ÿZH\ÿXEYÿO>Oÿ?1?ÿC4CÿMRÿN>QÿQATÿRCVÿI:LÿJ;LÿL=NÿK=MÿI;KÿJ;LÿL;MÿQASÿVEWÿUEWÿSDVÿVFXÿYI]ÿYI\ÿSCUÿP?QÿO?PÿQASÿSCUÿSCUÿRBSÿN>NÿM>NÿO@QÿRASÿSASÿQ?QÿTCUÿRASÿG7GÿJ9JÿK;LÿLLÿRBRÿPAQÿQARÿO>PÿL1>ÿA4AÿM=MÿYHZÿWFXÿXGYÿVEWÿRBSÿRASÿQAQÿN?OÿM?OÿM>OÿLOÿK>OÿN@QÿOARÿL>OÿKNÿQBSÿVEWÿWEXÿUDVÿSCUÿN>PÿK;LÿLPÿKNÿWEWÿUCVÿYH[ÿ\K^ÿVEWÿXFYÿUEWÿSDUÿRBRÿM>LÿL=JÿI:HÿM=MÿSBTÿVCVÿUCUÿUCUÿTDUÿUDVÿVEXÿYHZÿ[I[ÿYHYÿWFXÿYGZÿXGYÿUDUÿSCTÿSCTÿTDUÿUEVÿRBSÿO?OÿPAQÿWFWÿYGYÿWFWÿSCSÿUCTÿ]J\ÿaM`ÿdPdÿdPdÿbNbÿ^K^ÿZIZÿVDUÿSASÿTCTÿWFWÿVEVÿXFWÿZHZÿWEWÿN=MÿI:HÿLOÿR@QÿRARÿQARÿRBSÿVEVÿ\K\ÿ^L^ÿ\J[ÿYHXÿYGYÿ[HZÿZGZÿZHZÿ\J\ÿ]J^ÿ]J]ÿ]J]ÿ]J^ÿ\I\ÿUBTÿH7FÿC3BÿH9JÿN>PÿN=OÿSCUÿWFZÿSCVÿP@QÿRCSÿSCTÿQ@RÿP@QÿO@QÿO@QÿSCTÿVFXÿXHZÿYHZÿYGYÿXFXÿYFXÿYGYÿVEWÿTCTÿUDVÿXFXÿVEVÿSBRÿR@QÿO?OÿO>OÿSASÿYGZÿ]K^ÿXGZÿSCTÿO?PÿO@QÿSCTÿP@QÿTCVÿUDVÿTCUÿTCWÿSBVÿN>PÿK;MÿLPÿM?PÿJMÿKNÿSCSÿJ:JÿRCTÿZJ\ÿZI[ÿVCUÿRAQÿPAQÿQ@RÿP>PÿL;KÿG6EÿA2@ÿA4BÿF8HÿG:JÿB4DÿG8IÿN>PÿRBTÿWFYÿ\K]ÿTDTÿQAQÿTDTÿSCSÿN>MÿTDTÿXGYÿYHZÿXFYÿRAQÿJ:HÿE6EÿD5DÿE6DÿKOÿQBRÿK=LÿH:IÿH9IÿKMÿG:HÿJMÿL=MÿN=MÿQ>OÿUCUÿXGYÿYH[ÿYI\ÿZI[ÿYHZÿZGZÿXFXÿXFXÿZH[ÿWFXÿUCUÿUDVÿVEWÿUDUÿRARÿK;JÿG9HÿL=MÿTCTÿWEVÿVEVÿTCTÿUCTÿZGYÿ^J^ÿbNbÿbObÿ`M`ÿ\J\ÿYGYÿXEWÿWEWÿXFXÿZHZÿ\I\ÿ`L^ÿ_L^ÿZHZÿTDTÿN>MÿQ?OÿR@PÿSARÿWEWÿYGYÿZHZÿ[HZÿ[GYÿYFXÿ^K]ÿTCTÿM=MÿM=NÿP>PÿSBSÿUEVÿXGYÿZHZÿ\J\ÿ]K\ÿbObÿ`M^ÿYFWÿWCUÿXCVÿXEVÿWFWÿZHZÿ_K_ÿ^J^ÿ]J]ÿ\I\ÿ[H[ÿZGXÿJ8IÿA0@ÿH8IÿO@RÿO>PÿRBUÿVEXÿVEXÿTDVÿTDVÿSCTÿRBSÿO>OÿLNÿQBSÿN=MÿTBTÿUCUÿQ?QÿM + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/thorvg-main/test/resources/test1.svg b/components/thorvg-main/test/resources/test1.svg new file mode 100644 index 0000000..0932d56 --- /dev/null +++ b/components/thorvg-main/test/resources/test1.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test10.lot b/components/thorvg-main/test/resources/test10.lot new file mode 100644 index 0000000..9672ee4 --- /dev/null +++ b/components/thorvg-main/test/resources/test10.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":90,"w":400,"h":400,"nm":"Gradient Advanced Tests","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Mask Layer - Alpha Matte","tt":1,"sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":1,"k":[{"t":0,"s":[60,60],"e":[120,120]},{"t":45,"s":[120,120],"e":[60,60]},{"t":90,"s":[60,60]}]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse Mask"},{"ty":"fl","c":{"a":0,"k":[1,1,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Content with Alpha Matte","td":1,"sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":10},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[1,0.3,0.3,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Mask Layer - Inverted Matte","tt":2,"sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[300,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"or":{"a":0,"k":[40]},"os":{"a":0,"k":[0]},"ir":{"a":0,"k":[20]},"is":{"a":0,"k":[0]},"nm":"Star Mask"},{"ty":"fl","c":{"a":0,"k":[1,1,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"Content with Inverted Matte","td":2,"sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[300,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[90,90]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[0.3,1,0.3,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":5,"ty":4,"nm":"Layer with Tint Effect","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,250,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"ef":[{"ty":20,"nm":"Tint","np":6,"mn":"ADBE Tint","ix":1,"en":1,"ef":[{"ty":2,"nm":"Map Black To","mn":"ADBE Tint-0001","ix":1,"v":{"a":1,"k":[{"t":0,"s":[0,0,1,1],"e":[1,0,0,1]},{"t":45,"s":[1,0,0,1],"e":[0,0,1,1]},{"t":90,"s":[0,0,1,1]}]}},{"ty":2,"nm":"Map White To","mn":"ADBE Tint-0002","ix":2,"v":{"a":0,"k":[1,1,1,1]}},{"ty":0,"nm":"Amount to Tint","mn":"ADBE Tint-0003","ix":3,"v":{"a":0,"k":100}}]}],"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[60,60]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":10},"nm":"Rectangle"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"bm":0,"g":{"p":3,"k":{"a":0,"k":[0,0,0,0,0.5,0.5,0.5,0.5,1,1,1,1]}},"s":{"a":0,"k":[-30,0]},"e":{"a":0,"k":[30,0]},"t":1,"nm":"Gradient Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":6,"ty":4,"nm":"Layer with Fill Effect","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[220,250,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"ef":[{"ty":21,"nm":"Fill","np":9,"mn":"ADBE Fill","ix":1,"en":1,"ef":[{"ty":10,"nm":"Fill Mask","mn":"ADBE Fill-0001","ix":1,"v":{"a":0,"k":0}},{"ty":7,"nm":"All Masks","mn":"ADBE Fill-0007","ix":2,"v":{"a":0,"k":0}},{"ty":2,"nm":"Color","mn":"ADBE Fill-0002","ix":3,"v":{"a":1,"k":[{"t":0,"s":[1,1,0,1],"e":[1,0,1,1]},{"t":90,"s":[1,0,1,1]}]}},{"ty":7,"nm":"Invert","mn":"ADBE Fill-0006","ix":4,"v":{"a":0,"k":0}},{"ty":0,"nm":"Horizontal Feather","mn":"ADBE Fill-0003","ix":5,"v":{"a":0,"k":0}},{"ty":0,"nm":"Vertical Feather","mn":"ADBE Fill-0004","ix":6,"v":{"a":0,"k":0}},{"ty":0,"nm":"Opacity","mn":"ADBE Fill-0005","ix":7,"v":{"a":0,"k":100}}]}],"shapes":[{"ty":"sr","d":1,"sy":2,"pt":{"a":0,"k":6},"p":{"a":0,"k":[0,0]},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"or":{"a":0,"k":[30]},"os":{"a":0,"k":[0]},"nm":"Polygon"},{"ty":"fl","c":{"a":0,"k":[0.5,0.5,0.5,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":7,"ty":4,"nm":"Layer with Stroke Effect","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[340,250,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"ef":[{"ty":22,"nm":"Stroke","np":13,"mn":"ADBE Stroke","ix":1,"en":1,"ef":[{"ty":2,"nm":"Color","mn":"ADBE Stroke-0001","ix":1,"v":{"a":0,"k":[1,0.5,0,1]}},{"ty":7,"nm":"All Masks","mn":"ADBE Stroke-0009","ix":2,"v":{"a":0,"k":1}},{"ty":7,"nm":"Stroke Sequentially","mn":"ADBE Stroke-0010","ix":3,"v":{"a":0,"k":0}},{"ty":0,"nm":"Brush Size","mn":"ADBE Stroke-0002","ix":4,"v":{"a":1,"k":[{"t":0,"s":[2],"e":[8]},{"t":45,"s":[8],"e":[2]},{"t":90,"s":[2]}]}},{"ty":0,"nm":"Brush Hardness","mn":"ADBE Stroke-0003","ix":5,"v":{"a":0,"k":100}},{"ty":0,"nm":"Opacity","mn":"ADBE Stroke-0004","ix":6,"v":{"a":0,"k":100}}]}],"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[50,50]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[0.2,0.8,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":8,"ty":4,"nm":"Multiply Blend Mode","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"nm":"Circle"},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":80},"r":1,"nm":"Fill","bm":2}],"ip":0,"op":90,"st":0,"bm":2},{"ddd":0,"ind":9,"ty":4,"nm":"Screen Blend Mode","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[120,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"nm":"Circle"},{"ty":"fl","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":80},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":3},{"ddd":0,"ind":10,"ty":4,"nm":"Overlay Blend Mode","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[110,120,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"nm":"Circle"},{"ty":"fl","c":{"a":0,"k":[0,0,1,1]},"o":{"a":0,"k":80},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":4},{"ddd":1,"ind":11,"ty":4,"nm":"3D Layer with Rotation","sr":1,"ks":{"o":{"a":0,"k":100},"rx":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"ry":{"a":1,"k":[{"t":0,"s":[0],"e":[180]},{"t":90,"s":[180]}]},"rz":{"a":0,"k":0},"or":{"a":0,"k":[0,0,0]},"p":{"a":0,"k":[300,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[60,60]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":5},"nm":"Rectangle"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"bm":0,"g":{"p":3,"k":{"a":0,"k":[0,1,0,0,0.5,1,1,0,1,1,1,1]}},"s":{"a":0,"k":[0,-30]},"e":{"a":0,"k":[0,30]},"t":1,"nm":"Gradient Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":12,"ty":4,"nm":"Layer with Multiple Masks","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,280,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"hasMask":true,"masksProperties":[{"inv":false,"mode":"a","pt":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[-40,-40],[40,-40],[40,40],[-40,40]],"c":true}},"o":{"a":1,"k":[{"t":0,"s":[100],"e":[50]},{"t":45,"s":[50],"e":[100]},{"t":90,"s":[100]}]},"x":{"a":1,"k":[{"t":0,"s":[0],"e":[10]},{"t":45,"s":[10],"e":[0]},{"t":90,"s":[0]}]},"nm":"Mask 1"},{"inv":false,"mode":"s","pt":{"a":1,"k":[{"t":0,"s":[{"i":[[0,-11],[11,0],[0,11],[-11,0]],"o":[[0,11],[-11,0],[0,-11],[11,0]],"v":[[20,0],[0,20],[-20,0],[0,-20]],"c":true}],"e":[{"i":[[0,-15],[15,0],[0,15],[-15,0]],"o":[[0,15],[-15,0],[0,-15],[15,0]],"v":[[27,0],[0,27],[-27,0],[0,-27]],"c":true}]},{"t":45,"s":[{"i":[[0,-15],[15,0],[0,15],[-15,0]],"o":[[0,15],[-15,0],[0,-15],[15,0]],"v":[[27,0],[0,27],[-27,0],[0,-27]],"c":true}],"e":[{"i":[[0,-11],[11,0],[0,11],[-11,0]],"o":[[0,11],[-11,0],[0,-11],[11,0]],"v":[[20,0],[0,20],[-20,0],[0,-20]],"c":true}]},{"t":90,"s":[{"i":[[0,-11],[11,0],[0,11],[-11,0]],"o":[[0,11],[-11,0],[0,-11],[11,0]],"v":[[20,0],[0,20],[-20,0],[0,-20]],"c":true}]}]},"o":{"a":0,"k":100},"x":{"a":0,"k":0},"nm":"Mask 2"}],"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":10},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[1,0.5,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":13,"ty":4,"nm":"Time Remapping Layer","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"p":{"a":0,"k":[280,280,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"tm":{"a":1,"k":[{"t":0,"s":[0],"e":[60]},{"t":60,"s":[60],"e":[0]},{"t":90,"s":[0]}]},"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":6},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":1,"k":[{"t":0,"s":[30],"e":[50]},{"t":45,"s":[50],"e":[30]},{"t":90,"s":[30]}]},"os":{"a":0,"k":[0]},"ir":{"a":0,"k":[15]},"is":{"a":0,"k":[0]},"nm":"Star"},{"ty":"fl","c":{"a":0,"k":[0.8,0.2,0.8,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":14,"ty":4,"nm":"TrimPath - Simultaneous Mode","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":8},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[40]},"os":{"a":0,"k":[0]},"ir":{"a":0,"k":[20]},"is":{"a":0,"k":[0]},"nm":"Star"},{"ty":"tm","s":{"a":1,"k":[{"t":0,"s":[0],"e":[50]},{"t":45,"s":[50],"e":[0]},{"t":90,"s":[0]}]},"e":{"a":1,"k":[{"t":0,"s":[100],"e":[50]},{"t":45,"s":[50],"e":[100]},{"t":90,"s":[100]}]},"o":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"m":2,"nm":"TrimPath Simultaneous"},{"ty":"st","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":4},"lc":2,"lj":2,"ml":4,"nm":"Stroke"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":15,"ty":4,"nm":"Radial Gradient with Zero Stop","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[250,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"bm":0,"g":{"p":2,"k":{"a":0,"k":[0,1,0.5,0,1,0,0.8,1]}},"s":{"a":0,"k":[0,0]},"e":{"a":0,"k":[40,40]},"t":2,"h":{"a":0,"k":0},"a":{"a":0,"k":0},"nm":"Radial Gradient Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":16,"ty":4,"nm":"Multiple Strokes with Dashes","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"p":{"a":0,"k":[100,250,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[70,70]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":10},"nm":"Rectangle"},{"ty":"st","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":8},"lc":1,"lj":1,"ml":4,"d":[{"n":"d","nm":"dash","v":{"a":1,"k":[{"t":0,"s":[10],"e":[20]},{"t":45,"s":[20],"e":[10]},{"t":90,"s":[10]}]}},{"n":"g","nm":"gap","v":{"a":0,"k":5}},{"n":"o","nm":"offset","v":{"a":1,"k":[{"t":0,"s":[0],"e":[50]},{"t":90,"s":[50]}]}}],"nm":"Stroke with Dashes"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":17,"ty":4,"nm":"Gradient Stroke with Opacity Zero","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[280,250,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":2,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[35]},"os":{"a":0,"k":[0]},"nm":"Pentagon"},{"ty":"gs","o":{"a":1,"k":[{"t":0,"s":[0],"e":[100]},{"t":45,"s":[100],"e":[0]},{"t":90,"s":[0]}]},"w":{"a":0,"k":6},"lc":2,"lj":2,"ml":4,"g":{"p":3,"k":{"a":0,"k":[0,1,0,1,0.5,0.5,0.5,0,1,0,1,0]}},"s":{"a":0,"k":[-35,0]},"e":{"a":0,"k":[35,0]},"t":1,"nm":"Gradient Stroke"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":18,"ty":4,"nm":"Path with Multiple TrimPaths","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[200,320,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[-50,-30],[50,-30],[50,30],[-50,30]],"c":true}},"nm":"Path"},{"ty":"tm","s":{"a":0,"k":[25]},"e":{"a":0,"k":[75]},"o":{"a":0,"k":[0]},"m":1,"nm":"TrimPath 1"},{"ty":"tm","s":{"a":1,"k":[{"t":0,"s":[0],"e":[50]},{"t":90,"s":[50]}]},"e":{"a":0,"k":[100]},"o":{"a":0,"k":[0]},"m":1,"nm":"TrimPath 2"},{"ty":"st","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"lc":2,"lj":2,"ml":4,"nm":"Stroke"}],"ip":0,"op":90,"st":0,"bm":0}],"markers":[]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test11.lot b/components/thorvg-main/test/resources/test11.lot new file mode 100644 index 0000000..404d6a9 --- /dev/null +++ b/components/thorvg-main/test/resources/test11.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":111,"w":1080,"h":1080,"fonts":{"list":[{"fName":"Arial","fFamily":"Arial","fStyle":"Regular","fPath":"fonts/Arial.ttf","fWeight":"normal","ascent":100,"origin":3},{"fName":"Roboto-Bold","fFamily":"Roboto","fStyle":"Bold","fPath":"fonts/Roboto-Bold.ttf","fWeight":"bold","ascent":95,"origin":1}]},"layers":[{"ty":4,"shapes":[{"ty":"rc","s":{"a":0,"k":[100,100]}},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]}}],"ip":0,"op":60,"ind":1,"nm":"Shape Layer from test28"},{"ty":4,"ks":{"p":{"a":1,"k":[{"t":0,"s":[100,100],"e":[300,300],"i":{"x":[0],"y":[0]},"o":{"x":[0],"y":[0]}},{"t":30,"s":[300,300]}]},"s":{"a":1,"k":[{"t":0,"s":[100,100],"e":[200,200],"i":{"x":[1],"y":[1]},"o":{"x":[1],"y":[1]}},{"t":30,"s":[200,200]}]}},"shapes":[{"ty":"rc","s":{"a":0,"k":[50,50]}},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]}}],"ip":0,"op":60,"ind":2,"nm":"Shape Layer from test30"},{"ind":3,"ty":4,"nm":"B","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":58,"s":[349.032]}],"sid":"ball_rotation"},"p":{"s":true,"x":{"a":0,"k":540},"y":{"a":1,"k":[{"i":{"x":[0.67],"y":[0.343]},"o":{"x":[0.33],"y":[0]},"t":0,"s":[152]},{"i":{"x":[0.67],"y":[1]},"o":{"x":[0.33],"y":[0]},"t":15,"s":[915]},{"i":{"x":[0.67],"y":[0.343]},"o":{"x":[0.33],"y":[0]},"t":30,"s":[152]},{"i":{"x":[0.67],"y":[1]},"o":{"x":[0.33],"y":[0]},"t":45,"s":[915]},{"t":60,"s":[152]}]}},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[270,270],"sid":"ball_size"},"p":{"a":0,"k":[0,0]},"r":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":15,"s":[135]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":30,"s":[33.75]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":45,"s":[33.75]},{"t":60,"s":[135]}]},"nm":"S"},{"ty":"fl","c":{"a":0,"k":[0.961,0.761,0.267,1],"sid":"ball_color"},"o":{"a":0,"k":100,"sid":"ball_opacity"},"r":1,"nm":"C"}],"ip":0,"op":61,"st":0},{"ind":4,"ty":4,"nm":"B","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[540,540,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[1080,1080],"sid":"bg_size"},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"R"},{"ty":"fl","c":{"a":0,"k":[0.153,0.153,0.153,1],"sid":"bg_color"},"o":{"a":0,"k":100},"r":1,"nm":"F"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"T"}],"nm":"G"}],"ip":0,"op":61,"st":0},{"ddd":0,"ind":5,"ty":4,"nm":"pointer 2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.908],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":52,"s":[80]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":57,"s":[80]},{"i":{"x":[0.485],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":71,"s":[100]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.481],"y":[0]},"t":90,"s":[-26]},{"t":101,"s":[-1]}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":52,"s":[235.313,572.313,0],"to":[-11.563,5.688,0],"ti":[5.813,-4.188,0]},{"i":{"x":0.36,"y":1},"o":{"x":0.902,"y":0},"t":57,"s":[203.313,588.563,0],"to":[-0.313,6.438,0],"ti":[-317.313,6.938,0]},{"i":{"x":0.215,"y":0.938},"o":{"x":0.659,"y":0},"t":71,"s":[705.813,508.063,0],"to":[14.563,-36.438,0],"ti":[0,0,0]},{"i":{"x":0.632,"y":1},"o":{"x":0.597,"y":0.342},"t":90,"s":[280.313,475.063,0],"to":[0,0,0],"ti":[0,0,0]},{"t":101,"s":[314.813,475.813,0]}],"ix":2,"l":2},"a":{"a":0,"k":[2.813,44.813,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":52,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-41.084,-15.705],[-41.145,-14.544],[-7.154,71.891],[-6.833,71.872],[45,72.716]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":57,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-3.258,72.832],[-2.938,72.813],[47.75,60]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.333,"y":0},"t":71,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-14.872,75.604],[-14.551,75.585],[30.964,100.71]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":90,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-40.428,-8.459],[-40.489,-7.298],[-14.677,84.044],[-14.356,84.025],[39.594,68.759]],"c":true}]},{"t":101,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-40.428,-8.459],[-40.489,-7.298],[-6.003,81.32],[-5.682,81.301],[46.375,81.38]],"c":true}]}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.505882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 2","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":52,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-41.021,-15.58],[-44.404,108.758],[-6.646,71.809]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":57,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-53.5,97],[-2.75,72.75]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.333,"y":0},"t":71,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-43.334,122.294],[-14.364,75.523]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":90,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-40.366,-8.334],[-47.623,112.553],[-14.169,83.962]],"c":true}]},{"t":101,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-40.366,-8.334],[-42.737,119.139],[-5.495,81.238]],"c":true}]}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.705882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":3,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false}],"ip":52,"op":180,"st":0,"ct":1,"bm":0},{"ddd":0,"ind":6,"ty":4,"nm":"pointer","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":9,"s":[0]},{"i":{"x":[0.908],"y":[1]},"o":{"x":[0.626],"y":[0]},"t":20,"s":[33]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":36,"s":[80]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":44,"s":[80]},{"i":{"x":[0.908],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":52,"s":[80]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":57,"s":[80]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":71,"s":[100]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":90,"s":[-26]},{"t":101,"s":[-1]}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":2,"s":[314.813,486.813,0],"to":[2.917,7.833,0],"ti":[-2.917,-7.833,0]},{"i":{"x":0.667,"y":0.667},"o":{"x":0.333,"y":0.333},"t":5,"s":[332.313,533.813,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.132,"y":1},"o":{"x":0.141,"y":0},"t":9,"s":[332.313,533.813,0],"to":[-15.917,-72.333,0],"ti":[-129.083,228.333,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":20,"s":[326.813,117.813,0],"to":[86.124,364.639,0],"ti":[38.917,-50.667,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":36,"s":[207.563,587.563,0],"to":[6.676,-4.486,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":0.667},"o":{"x":0.333,"y":0.333},"t":44,"s":[235.313,572.313,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":52,"s":[235.313,572.313,0],"to":[0,0,0],"ti":[-78.417,10.708,0]},{"i":{"x":0.36,"y":1},"o":{"x":0.902,"y":0},"t":57,"s":[203.313,588.563,0],"to":[78.417,-10.708,0],"ti":[-317.313,6.938,0]},{"i":{"x":0.36,"y":1},"o":{"x":0.333,"y":0},"t":71,"s":[705.813,508.063,0],"to":[317.313,-6.938,0],"ti":[0,0,0]},{"i":{"x":0.36,"y":1},"o":{"x":0.333,"y":0},"t":90,"s":[280.313,475.063,0],"to":[0,0,0],"ti":[0,0,0]},{"t":101,"s":[314.813,475.813,0]}],"ix":2,"l":2},"a":{"a":0,"k":[2.813,44.813,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":2,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-41.563,-18.875],[-41.623,-17.714],[-4.258,71.332],[-3.938,71.313],[47.25,70]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":5,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-3.258,72.832],[-2.938,72.813],[47.75,60]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":9,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-3.258,72.832],[-2.938,72.813],[47.75,60]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":20,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-14.872,75.604],[-14.551,75.585],[30.964,100.71]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":31,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-3.258,72.832],[-2.938,72.813],[47.75,60]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":39,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-3.258,72.832],[-2.938,72.813],[47.75,60]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":44,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-41.084,-15.705],[-41.145,-14.544],[-7.154,71.891],[-6.833,71.872],[45,72.716]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":52,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-41.084,-15.705],[-41.145,-14.544],[-7.154,71.891],[-6.833,71.872],[45,72.716]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":57,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-3.258,72.832],[-2.938,72.813],[47.75,60]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.333,"y":0},"t":71,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-39.563,-11.375],[-39.623,-10.214],[-14.872,75.604],[-14.551,75.585],[30.964,100.71]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":90,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-40.428,-8.459],[-40.489,-7.298],[-14.677,84.044],[-14.356,84.025],[39.594,68.759]],"c":true}]},{"t":101,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[-40.428,-8.459],[-40.489,-7.298],[-6.003,81.32],[-5.682,81.301],[46.375,81.38]],"c":true}]}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.505882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 2","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":2,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-41.5,-18.75],[-41.5,108.5],[-3.75,71.25]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":5,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-53.5,97],[-2.75,72.75]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":9,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-53.5,97],[-2.75,72.75]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":20,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-43.334,122.294],[-14.364,75.523]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":31,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-53.5,97],[-2.75,72.75]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":39,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-53.5,97],[-2.75,72.75]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":44,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-41.021,-15.58],[-44.404,108.758],[-6.646,71.809]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":52,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-41.021,-15.58],[-44.404,108.758],[-6.646,71.809]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":57,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-53.5,97],[-2.75,72.75]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.333,"y":0},"t":71,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-39.5,-11.25],[-43.334,122.294],[-14.364,75.523]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":90,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-40.366,-8.334],[-47.623,112.553],[-14.169,83.962]],"c":true}]},{"t":101,"s":[{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-40.366,-8.334],[-42.737,119.139],[-5.495,81.238]],"c":true}]}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.705882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":3,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":52,"st":0,"ct":1,"bm":0},{"ddd":0,"ind":7,"ty":4,"nm":"Shape Layer 2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[87.813,251.5,0],"ix":2,"l":2},"a":{"a":0,"k":[-223.625,-190.125,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[33.25,33.25],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.705882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-222.625,248.125],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 4","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[33.25,33.25],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.705882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[214.375,248.125],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 3","np":3,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[33.25,33.25],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.705882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[214.375,-190.125],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 2","np":3,"cix":2,"bm":0,"ix":3,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[33.25,33.25],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.705882352941,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-223.625,-190.125],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"bm":0,"ix":4,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":180,"st":0,"ct":1,"bm":0},{"ddd":0,"ind":8,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[312,442,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.333,"y":0},"t":12,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":13,"s":[{"i":[[0,0],[45.805,56.777],[0.912,-0.274],[12.788,-7.87],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-6.695,-8.223],[-1.003,0.046],[-31.447,18.046],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[-43.555,-248.027],[-63.941,-271.266],[-95.303,-218.046],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":14,"s":[{"i":[[0,0],[41.134,72.459],[1.636,-0.491],[19.603,-15.215],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-5.995,-10.401],[-1.8,0.082],[-44.397,35.285],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[-29.816,-287.451],[-47.975,-319.894],[-84.603,-254.785],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":15,"s":[{"i":[[0,0],[39.515,100.049],[2.339,-0.702],[20.389,-18.025],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-5.315,-12.516],[-2.573,0.117],[-57.735,55.653],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[-14.515,-311.549],[-30.512,-352.932],[-68.023,-278.267],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":16,"s":[{"i":[[0,0],[33.997,120.659],[3.015,-0.904],[22.564,-22.25],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-4.663,-14.547],[-3.316,0.151],[-70.546,75.216],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[-2.497,-326.159],[-14.917,-378.628],[-58.064,-295.75],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"t":17,"s":[{"i":[[0,0],[29.323,128.568],[3.652,-1.096],[22.82,-24.306],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-4.047,-16.464],[-4.017,0.183],[-82.631,93.67],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[8.282,-332.401],[-2.66,-392.167],[-54.283,-307.231],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.333,"y":0},"t":20,"s":[{"i":[[0,0],[19.435,145.298],[5,-1.5],[23.363,-28.656],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-2.744,-20.518],[-5.5,0.25],[-108.195,132.709],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[17.065,-323.798],[9.25,-399],[-60.305,-309.709],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":22,"s":[{"i":[[0,0],[22.637,132.221],[5.131,-1.369],[22.269,-26.077],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-3.322,-18.66],[-5.587,0.228],[-103.249,120.751],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[22.067,-305.304],[18.106,-381.799],[-48.769,-294.008],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":23,"s":[{"i":[[0,0],[27.165,113.731],[5.316,-1.184],[22.586,-21.344],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-4.139,-16.034],[-5.71,0.197],[-103.664,93.156],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[27.419,-283.075],[21,-350.258],[-44.336,-275.156],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":24,"s":[{"i":[[0,0],[22.786,71.935],[5.497,-1.003],[20.023,-17.655],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-2.214,-12.065],[-5.831,0.167],[-95.656,78.179],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[38.214,-256.935],[30.494,-320.295],[-28.273,-255.595],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":25,"s":[{"i":[[0,0],[24.013,47.801],[5.675,-0.825],[24.585,-14.669],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-6.737,-12.449],[-5.95,0.138],[-77.915,45.331],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[48.487,-228.801],[37.646,-278.627],[-17.835,-238.331],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":26,"s":[{"i":[[0,0],[13.128,21.942],[3.635,1.236],[27.63,-9.863],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-7.372,-8.308],[-6.065,0.109],[-73.62,24.637],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[53.622,-212.942],[42.865,-238.736],[-12.88,-216.637],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":27,"s":[{"i":[[0,0],[10.197,0.906],[2.982,0.207],[22.176,-3.647],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-8.553,-1.594],[-6.175,0.081],[-70.824,12.103],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[45.053,-193.406],[23.018,-199.207],[-24.176,-192.353],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"t":28,"s":[{"i":[[0,0],[23.708,-3.089],[4.111,0.141],[17.789,0.812],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-8.292,1.411],[-6.28,0.055],[-63.211,1.312],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[38.042,-179.286],[12.463,-177.538],[-32.039,-178.562],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.333,"y":0},"t":31,"s":[{"i":[[0,0],[56.177,-4.75],[6.5,0],[10.811,0.946],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-9.373,0.793],[-6.5,0],[-51.443,-4.5],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[22.823,-151.75],[-6.75,-150],[-45.557,-152.5],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.333,"y":0},"t":33,"s":[{"i":[[0,0],[56.177,-4.75],[6.5,0],[10.811,0.946],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-9.373,0.793],[-6.5,0],[-51.443,-4.5],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[22.823,-151.75],[-6.75,-150],[-45.557,-152.5],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0},"t":35,"s":[{"i":[[0,0],[56.24,2.691],[6.5,0],[8.807,-0.5],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-10.448,-0.5],[-6.5,0],[-51.363,2.916],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[24.698,-197.25],[-5,-198.25],[-46.057,-196.75],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0},"t":37,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0.167},"t":65,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":66,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-18.621,28.961],[1.142,14.464],[9.193,19.161]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[13.005,-20.226],[-1.5,-19],[-16.747,-34.907]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[274.121,82.539],[299,37],[274.247,-8.593]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":67,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-116.621,105.961],[-0.427,14.502],[20.753,15.593]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[17.797,-16.17],[0.5,-17],[-136.72,-102.725]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[332.621,79.039],[386.5,31],[346.247,-12.593]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":68,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-156.121,90.961],[-0.427,14.502],[27.253,11.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[20.777,-12.105],[0.5,-17],[-186.985,-76.108]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[363.121,73.039],[431,31],[385.247,-0.093]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":69,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-156.121,90.961],[2.5,7],[27.253,11.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[20.777,-12.105],[-3.2,-8.959],[-186.985,-76.108]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[378.621,73.039],[447,34],[397.747,6.907]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":70,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-156.121,90.961],[2.5,7],[27.253,11.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[20.777,-12.105],[-3.2,-8.959],[-186.985,-76.108]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[388.621,72.039],[458,33.5],[407.747,10.407]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":71,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-156.121,90.961],[1,6.25],[27.253,11.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[20.777,-12.105],[-1.131,-7.069],[-186.985,-76.108]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[391.621,68.039],[462,33.5],[410.247,13.907]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":72,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-156.121,90.961],[1,6.25],[27.253,11.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[20.777,-12.105],[-1.131,-7.069],[-186.985,-76.108]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[392.121,66.539],[460.5,29.5],[404.247,11.157]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":73,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-156.121,90.961],[1.132,6.227],[27.253,11.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[20.777,-12.105],[-1,-5.5],[-186.985,-76.108]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[388.871,67.039],[455,19],[397.247,3.407]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":75,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-109.871,123.961],[1.132,6.227],[22.253,6.093]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[15.094,-17.029],[-1,-5.5],[-194.715,-53.311]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[384.871,59.039],[423.75,-9],[375.747,-18.593]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":76,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-72.871,103.961],[1.132,6.227],[22.128,6.53]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[13.061,-18.634],[-1,-5.5],[-115.747,-34.157]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[361.871,52.539],[395.5,-17.75],[348.747,-21.843]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":77,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-27.371,70.461],[1.132,6.227],[8.74,1.426]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[8.24,-21.212],[-1,-5.5],[-62.247,-10.157]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[349.371,55.539],[358.25,-25.25],[323.247,-25.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":78,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-27.871,64.961],[3.559,5.234],[6.968,5.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[8.972,-20.912],[-4.25,-6.25],[-53.747,-42.157]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[315.871,61.039],[330.25,-17.25],[291.247,-47.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":79,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-23.871,66.961],[3.559,5.234],[5.572,6.883]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[7.641,-21.435],[-4.25,-6.25],[-27.247,-33.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[262.871,67.039],[274.25,-5.25],[249.747,-40.843]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":80,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[27.301,65.637],[2.153,5.952],[-1.638,8.703]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-11.871,-28.539],[-4.25,-11.75],[9.253,-49.157]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[180.871,89.539],[157.75,25.75],[155.247,-37.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":81,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[27.301,65.637],[2.153,5.952],[-1.638,8.703]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-11.871,-28.539],[-4.25,-11.75],[9.253,-49.157]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[180.871,89.539],[157.75,25.75],[155.247,-37.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":82,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[27.301,65.637],[0.699,6.291],[-2.6,8.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-11.871,-28.539],[-1.75,-15.75],[15.253,-49.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[146.371,111.039],[127.25,40.75],[134.747,-26.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":83,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[27.301,65.637],[0.699,6.291],[-2.6,8.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-11.871,-28.539],[-1.75,-15.75],[15.253,-49.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[146.371,111.039],[127.25,40.75],[134.747,-26.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":84,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[30.629,64.461],[0.699,6.291],[-2.6,8.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-13.266,-27.918],[-1.75,-15.75],[15.253,-49.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[137.871,111.039],[121.75,41.25],[130.747,-25.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":86,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[30.629,64.461],[0.699,6.291],[-2.6,8.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-13.266,-27.918],[-1.75,-15.75],[15.253,-49.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[137.871,111.039],[121.75,41.25],[130.747,-25.343]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":87,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[30.629,64.461],[0.699,6.291],[-2.6,8.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-13.266,-27.918],[-1.75,-15.75],[15.253,-49.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[141.371,111.539],[125.25,41.75],[134.247,-24.843]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":88,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[30.629,64.461],[0.699,6.291],[-2.6,8.465]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-13.266,-27.918],[-1.75,-15.75],[15.253,-49.657]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[141.371,111.539],[125.25,41.75],[134.247,-24.843]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":89,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[6.364,73.251],[0.25,14.5],[-0.502,8.841]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-2.871,-33.039],[-0.341,-19.749],[3.003,-52.907]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[200.871,116.039],[194.75,44.5],[197.497,-21.593]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0},"t":91,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[6.364,73.251],[0.25,14.5],[-0.502,8.841]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-2.871,-33.039],[-0.341,-19.749],[3.003,-52.907]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[200.871,116.039],[194.75,44.5],[197.497,-21.593]],"c":true}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0.167},"t":93,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[221,34.834],[221.5,8.25],[220.5,-23.928]],"c":true}]},{"t":95,"s":[{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[214,-190],[4.323,-190],[-9.5,-190],[-44.057,-190],[-225,-190],[-223,247.5],[214,247.5],[214,34.834],[214,9],[214,-23.428]],"c":true}]}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.870588235294,0.699884691425,0.017070357005,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":11,"ix":5},"lc":1,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":180,"st":0,"ct":1,"bm":0},{"ty":4,"nm":"Round Join Test","ip":0,"op":60,"shapes":[{"ty":"rc","nm":"Rectangle","p":{"a":0,"k":[200,200]},"s":{"a":0,"k":[150,150]},"r":{"a":0,"k":0}},{"ty":"st","nm":"Stroke with Round","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":20},"lc":2,"lj":2,"ml":4}],"ind":9}],"nm":"Basic Shapes Set 2 Tests","slots":{"ball_color":{"p":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":7,"s":[0,0.176,0.867]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":22,"s":[0.867,0,0.533]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":37,"s":[0.867,0,0.533]},{"t":51,"s":[0,0.867,0.255]}]}},"ball_opacity":{"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"s":[0],"t":0},{"s":[100],"t":100}]}},"bg_color":{"p":{"a":0,"k":[1,1,1,1]}}},"meta":{"g":"LottieFiles AE ","a":"","k":"","d":"","tc":""},"ddd":0,"markers":[],"assets":[]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test12.lot b/components/thorvg-main/test/resources/test12.lot new file mode 100644 index 0000000..b4b729b --- /dev/null +++ b/components/thorvg-main/test/resources/test12.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":60,"w":400,"h":400,"layers":[{"ty":4,"ef":[{"ty":21,"nm":"Fill","v":[{"ty":2,"nm":"Fill Mask","v":{"a":0,"k":[0]}},{"ty":0,"nm":"All Masks","v":{"a":0,"k":0}},{"ty":2,"nm":"Color","v":{"a":0,"k":[1,0,0,1]}},{"ty":0,"nm":"Opacity","v":{"a":0,"k":100}}]},{"ty":20,"nm":"Stroke","v":[{"ty":2,"nm":"Color","v":{"a":0,"k":[0,1,0,1]}},{"ty":0,"nm":"Stroke Width","v":{"a":0,"k":10}}]},{"ty":20,"nm":"Tint","v":[{"ty":2,"nm":"Map Black To","v":{"a":0,"k":[1,0,0,1]}},{"ty":2,"nm":"Map White To","v":{"a":0,"k":[0,0,1,1]}},{"ty":0,"nm":"Amount to Tint","v":{"a":0,"k":50}}]},{"ty":23,"nm":"Tritone","v":[{"ty":2,"nm":"Highlights","v":{"a":0,"k":[1,1,1,1]}},{"ty":2,"nm":"Midtones","v":{"a":0,"k":[0.5,0.5,0.5,1]}},{"ty":2,"nm":"Shadows","v":{"a":0,"k":[0,0,0,1]}}]}],"shapes":[{"ty":"rc","s":{"a":0,"k":[200,200]}},{"ty":"st","c":{"a":0,"k":[0,0,0,1]},"w":{"a":0,"k":5}}],"ip":0,"op":60,"ind":1,"nm":"Multiple Effects Layer"},{"ty":4,"nm":"Drop Shadow Effect","ip":0,"op":60,"ef":[{"ty":25,"nm":"Drop Shadow","np":8,"mn":"ADBE Drop Shadow","ix":1,"en":1,"ef":[{"ty":2,"nm":"Shadow Color","mn":"ADBE Drop Shadow-0001","ix":1,"v":{"a":0,"k":[0,0,0,1]}},{"ty":0,"nm":"Opacity","mn":"ADBE Drop Shadow-0002","ix":2,"v":{"a":0,"k":191.25}},{"ty":0,"nm":"Direction","mn":"ADBE Drop Shadow-0003","ix":3,"v":{"a":0,"k":135}},{"ty":0,"nm":"Distance","mn":"ADBE Drop Shadow-0004","ix":4,"v":{"a":0,"k":10}},{"ty":0,"nm":"Softness","mn":"ADBE Drop Shadow-0005","ix":5,"v":{"a":0,"k":20}}]}],"shapes":[{"ty":"rc","nm":"Rectangle","p":{"a":0,"k":[200,200]},"s":{"a":0,"k":[150,150]},"r":{"a":0,"k":10}},{"ty":"fl","nm":"Fill","c":{"a":0,"k":[1,0.5,0,1]},"o":{"a":0,"k":100}}],"ind":2},{"ty":4,"nm":"Gaussian Blur Effect","ip":0,"op":60,"ef":[{"ty":29,"nm":"Gaussian Blur","np":6,"mn":"ADBE Gaussian Blur 2","ix":1,"en":1,"ef":[{"ty":0,"nm":"Blurriness","mn":"ADBE Gaussian Blur 2-0001","ix":1,"v":{"a":1,"k":[{"t":0,"s":[0],"e":[20]},{"t":30,"s":[20],"e":[0]},{"t":60,"s":[0]}]}},{"ty":7,"nm":"Blur Dimensions","mn":"ADBE Gaussian Blur 2-0002","ix":2,"v":{"a":0,"k":1}},{"ty":7,"nm":"Repeat Edge Pixels","mn":"ADBE Gaussian Blur 2-0003","ix":3,"v":{"a":0,"k":0}}]}],"shapes":[{"ty":"el","nm":"Ellipse","p":{"a":0,"k":[200,200]},"s":{"a":0,"k":[120,120]}},{"ty":"fl","nm":"Fill","c":{"a":0,"k":[0,0.8,1,1]},"o":{"a":0,"k":100}}],"ind":3},{"ty":4,"nm":"Custom Effect with Various Properties","ip":0,"op":60,"ef":[{"ty":5,"nm":"Custom Effect","np":10,"mn":"Custom","ix":1,"en":1,"ef":[{"ty":0,"nm":"Slider Control","mn":"Slider","ix":1,"v":{"a":0,"k":50}},{"ty":1,"nm":"Angle Control","mn":"Angle","ix":2,"v":{"a":0,"k":45}},{"ty":2,"nm":"Color Control","mn":"Color","ix":3,"v":{"a":0,"k":[1,0,0,1]}},{"ty":3,"nm":"Point Control","mn":"Point","ix":4,"v":{"a":0,"k":[100,100]}},{"ty":4,"nm":"Checkbox Control","mn":"Checkbox","ix":5,"v":{"a":0,"k":1}},{"ty":7,"nm":"Dropdown Control","mn":"Dropdown","ix":6,"v":{"a":0,"k":2}},{"ty":10,"nm":"Effect Layer","mn":"EffectLayer","ix":7,"v":{"a":0,"k":0}}]}],"shapes":[{"ty":"sr","nm":"Star","p":{"a":0,"k":[200,200]},"or":{"a":0,"k":80},"ir":{"a":0,"k":40},"pt":{"a":0,"k":5},"sy":1},{"ty":"fl","nm":"Fill","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":100}}],"ind":4}],"nm":"Layer Effects Tests","assets":[]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test2.lot b/components/thorvg-main/test/resources/test2.lot new file mode 100644 index 0000000..4b2b5fc --- /dev/null +++ b/components/thorvg-main/test/resources/test2.lot @@ -0,0 +1,10024 @@ +{ + "v": "4.8.0", + "meta": { + "g": "LottieFiles AE 3.5.8", + "a": "", + "k": "", + "d": "", + "tc": "" + }, + "fr": 30, + "ip": 0, + "op": 90, + "w": 1000, + "h": 1000, + "nm": "door_lock v2", + "ddd": 0, + "assets": [ + { + "id": "comp_0", + "layers": [ + { + "ddd": 0, + "ind": 1, + "ty": 4, + "nm": "Layer 14 Outlines", + "parent": 2, + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 34.051, + 33.786, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 11.147, + 11.102, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + 5.6, + 0.067 + ], + [ + 0.041, + 5.685 + ], + [ + -5.729, + 0.115 + ], + [ + 0.212, + -5.836 + ] + ], + "o": [ + [ + -5.647, + -0.067 + ], + [ + -0.042, + -5.704 + ], + [ + 5.907, + -0.118 + ], + [ + -0.205, + 5.631 + ] + ], + "v": [ + [ + -0.238, + 10.784 + ], + [ + -10.855, + 0.048 + ], + [ + -0.318, + -10.734 + ], + [ + 10.685, + 0.315 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.858823597431, + 0.913725554943, + 0.933333396912, + 1 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 100, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 11.147, + 11.102 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Group 1", + "np": 2, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 45, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 2, + "ty": 4, + "nm": "Layer 16 Outlines", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 748.902, + 421.903, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 33.971, + 33.779, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -5.647, + -0.067 + ], + [ + -0.205, + 5.631 + ], + [ + 5.907, + -0.118 + ], + [ + -0.042, + -5.704 + ] + ], + "o": [ + [ + 5.6, + 0.067 + ], + [ + 0.212, + -5.836 + ], + [ + -5.729, + 0.115 + ], + [ + 0.041, + 5.685 + ] + ], + "v": [ + [ + -0.158, + 10.792 + ], + [ + 10.765, + 0.323 + ], + [ + -0.238, + -10.726 + ], + [ + -10.775, + 0.056 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ind": 1, + "ty": "sh", + "ix": 2, + "ks": { + "a": 0, + "k": { + "i": [ + [ + 18.438, + -0.076 + ], + [ + 0.207, + 18.124 + ], + [ + -18.435, + 0.037 + ], + [ + -0.218, + -18.084 + ] + ], + "o": [ + [ + -18.16, + 0.076 + ], + [ + -0.212, + -18.489 + ], + [ + 18.172, + -0.036 + ], + [ + 0.222, + 18.428 + ] + ], + "v": [ + [ + 0.09, + 33.452 + ], + [ + -33.509, + 0.436 + ], + [ + -0.134, + -33.492 + ], + [ + 33.499, + -0.484 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 2", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 4, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.086, + 0.264, + 0.221, + 0.5, + 0.227, + 0.628, + 0.497, + 1, + 0.368, + 0.991, + 0.773 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -32.412, + -9.478 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 5.257, + 49.858 + ], + "ix": 5 + }, + "t": 2, + "h": { + "a": 0, + "k": 0, + "ix": 6 + }, + "a": { + "a": 0, + "k": 0, + "ix": 7 + }, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 33.971, + 33.779 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Group 1", + "np": 3, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 45, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 3, + "ty": 4, + "nm": "Layer 15 Outlines", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 749.29, + 361.18, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 59.949, + 25.388, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + 0.761, + -3.374 + ], + [ + 3.439, + -1.118 + ], + [ + 3.606, + 1.755 + ], + [ + 9.463, + 2.666 + ], + [ + 14.915, + -12.914 + ], + [ + 3.381, + 0.409 + ], + [ + 1.162, + 3.22 + ], + [ + -2.295, + 2.587 + ], + [ + -28.413, + -29.815 + ] + ], + "o": [ + [ + -0.489, + 4.126 + ], + [ + -3.421, + 1.112 + ], + [ + -9.064, + -4.412 + ], + [ + -18.976, + -5.347 + ], + [ + -2.916, + 2.525 + ], + [ + -3.373, + -0.407 + ], + [ + -1.126, + -3.117 + ], + [ + 27.264, + -30.747 + ], + [ + 2.117, + 2.222 + ] + ], + "v": [ + [ + 58.199, + 14.194 + ], + [ + 50.823, + 23.03 + ], + [ + 38.874, + 20.798 + ], + [ + 12.165, + 6.728 + ], + [ + -38.851, + 19.989 + ], + [ + -49.598, + 24.729 + ], + [ + -58.572, + 17.492 + ], + [ + -56.177, + 6.293 + ], + [ + 54.021, + 4.676 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 4, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.086, + 0.264, + 0.221, + 0.5, + 0.227, + 0.628, + 0.497, + 1, + 0.368, + 0.991, + 0.773 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -32.412, + -9.478 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 5.257, + 49.858 + ], + "ix": 5 + }, + "t": 2, + "h": { + "a": 0, + "k": 0, + "ix": 6 + }, + "a": { + "a": 0, + "k": 0, + "ix": 7 + }, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 59.949, + 25.388 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Group 1", + "np": 3, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 5, + "op": 45, + "st": 5, + "bm": 0 + }, + { + "ddd": 0, + "ind": 4, + "ty": 4, + "nm": "Layer 17 Outlines", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 748.781, + 324.32, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 92.236, + 31.716, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -1.017, + -3.477 + ], + [ + 3.012, + -1.542 + ], + [ + 3.41, + 1.802 + ], + [ + 1.885, + 1.721 + ], + [ + 38.278, + -34.968 + ], + [ + 0.868, + -0.773 + ], + [ + 4.826, + 5.299 + ], + [ + -5.89, + 5.742 + ], + [ + -21.793, + 4.959 + ], + [ + -32.604, + -29.214 + ] + ], + "o": [ + [ + 0.233, + 4.273 + ], + [ + -2.975, + 1.523 + ], + [ + -1.988, + -1.051 + ], + [ + -38.273, + -34.931 + ], + [ + -0.858, + 0.784 + ], + [ + -6.322, + 5.632 + ], + [ + -4.709, + -5.17 + ], + [ + 16.002, + -15.601 + ], + [ + 42.771, + -9.734 + ], + [ + 2.955, + 2.647 + ] + ], + "v": [ + [ + 89.736, + 18.407 + ], + [ + 83.938, + 28.806 + ], + [ + 73.559, + 28.003 + ], + [ + 67.71, + 23.217 + ], + [ + -67.606, + 23.27 + ], + [ + -70.145, + 25.662 + ], + [ + -87.277, + 26.167 + ], + [ + -85.688, + 9.621 + ], + [ + -29.066, + -21.732 + ], + [ + 84.092, + 7.96 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 4, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.086, + 0.264, + 0.221, + 0.5, + 0.227, + 0.628, + 0.497, + 1, + 0.368, + 0.991, + 0.773 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -32.412, + -9.478 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 5.257, + 49.858 + ], + "ix": 5 + }, + "t": 2, + "h": { + "a": 0, + "k": 0, + "ix": 6 + }, + "a": { + "a": 0, + "k": 0, + "ix": 7 + }, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 92.236, + 31.716 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Group 1", + "np": 2, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 10, + "op": 45, + "st": 10, + "bm": 0 + }, + { + "ddd": 0, + "ind": 5, + "ty": 4, + "nm": "Layer 18 Outlines", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 749.117, + 289.409, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 124.326, + 35.436, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -32.953, + 0.244 + ], + [ + -32.728, + -31.835 + ], + [ + 7.629, + -3.944 + ], + [ + 4.145, + 4.028 + ], + [ + 22.028, + 6.493 + ], + [ + 41.715, + -36.318 + ], + [ + 1.791, + -1.48 + ], + [ + 4.443, + 4.653 + ], + [ + -5.303, + 4.356 + ], + [ + -13.025, + 7.862 + ] + ], + "o": [ + [ + 41.717, + 0.872 + ], + [ + 6.766, + 6.581 + ], + [ + -5.783, + 2.991 + ], + [ + -16.454, + -15.987 + ], + [ + -53.105, + -15.654 + ], + [ + -1.754, + 1.527 + ], + [ + -5.258, + 4.348 + ], + [ + -4.443, + -4.654 + ], + [ + 11.817, + -9.706 + ], + [ + 24.984, + -15.081 + ] + ], + "v": [ + [ + 3.447, + -35.186 + ], + [ + 117.31, + 13.145 + ], + [ + 115.571, + 32.194 + ], + [ + 101.258, + 28.609 + ], + [ + 43.753, + -5.803 + ], + [ + -98.523, + 25.624 + ], + [ + -103.66, + 30.348 + ], + [ + -119.206, + 29.804 + ], + [ + -118.772, + 14.377 + ], + [ + -82.216, + -13.329 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 4, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.086, + 0.264, + 0.221, + 0.5, + 0.227, + 0.628, + 0.497, + 1, + 0.368, + 0.991, + 0.773 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -32.412, + -9.478 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 5.257, + 49.858 + ], + "ix": 5 + }, + "t": 2, + "h": { + "a": 0, + "k": 0, + "ix": 6 + }, + "a": { + "a": 0, + "k": 0, + "ix": 7 + }, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 124.325, + 35.436 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Group 1", + "np": 2, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 15, + "op": 45, + "st": 15, + "bm": 0 + } + ] + } + ], + "layers": [ + { + "ddd": 0, + "ind": 1, + "ty": 4, + "nm": "pad1", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 296.202, + 240.008, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 20, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + }, + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 25, + "s": [ + { + "i": [ + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ], + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ] + ], + "o": [ + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ], + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ] + ], + "v": [ + [ + -0.074, + -14.595 + ], + [ + 14.448, + -0.074 + ], + [ + -0.074, + 14.448 + ], + [ + -14.595, + -0.074 + ] + ], + "c": true + } + ] + }, + { + "t": 30, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + } + ], + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 1, + "k": [ + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 20, + "s": [ + 2.191 + ] + }, + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 25, + "s": [ + 26.291 + ] + }, + { + "t": 30, + "s": [ + 2.191 + ] + } + ], + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 20, + "s": [ + -6.784, + -10.026 + ], + "to": [ + 2.912, + 1.444 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 25, + "s": [ + 10.687, + -1.359 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 2.912, + 1.444 + ] + }, + { + "t": 30, + "s": [ + -6.784, + -10.026 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 20, + "s": [ + -1.723, + 9.732 + ], + "to": [ + -2.587, + -3.499 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 25, + "s": [ + -17.246, + -11.259 + ], + "to": [ + 0, + 0 + ], + "ti": [ + -2.587, + -3.499 + ] + }, + { + "t": 30, + "s": [ + -1.723, + 9.732 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.5, + "y": 1 + }, + "o": { + "x": 0, + "y": 0 + }, + "t": 20, + "s": [ + -2.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 1, + "y": 1 + }, + "o": { + "x": 0.5, + "y": 0 + }, + "t": 25, + "s": [ + -31.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "t": 30, + "s": [ + -2.3, + 26.799 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.96862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 2, + "ty": 4, + "nm": "pad2", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 394.475, + 240.008, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2.191, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -6.784, + -10.026 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + -1.723, + 9.732 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -2.3, + 26.799 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.096862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 3, + "ty": 4, + "nm": "pad3", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 492.714, + 240.008, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 40, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + }, + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 45, + "s": [ + { + "i": [ + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ], + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ] + ], + "o": [ + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ], + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ] + ], + "v": [ + [ + -0.074, + -14.595 + ], + [ + 14.448, + -0.074 + ], + [ + -0.074, + 14.448 + ], + [ + -14.595, + -0.074 + ] + ], + "c": true + } + ] + }, + { + "t": 50, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + } + ], + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 1, + "k": [ + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 40, + "s": [ + 2.191 + ] + }, + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 45, + "s": [ + 26.291 + ] + }, + { + "t": 50, + "s": [ + 2.191 + ] + } + ], + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 40, + "s": [ + -6.784, + -10.026 + ], + "to": [ + 2.912, + 1.444 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 45, + "s": [ + 10.687, + -1.359 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 2.912, + 1.444 + ] + }, + { + "t": 50, + "s": [ + -6.784, + -10.026 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 40, + "s": [ + -1.723, + 9.732 + ], + "to": [ + -2.587, + -3.499 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 45, + "s": [ + -17.246, + -11.259 + ], + "to": [ + 0, + 0 + ], + "ti": [ + -2.587, + -3.499 + ] + }, + { + "t": 50, + "s": [ + -1.723, + 9.732 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.5, + "y": 1 + }, + "o": { + "x": 0, + "y": 0 + }, + "t": 40, + "s": [ + -2.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 1, + "y": 1 + }, + "o": { + "x": 0.5, + "y": 0 + }, + "t": 45, + "s": [ + -31.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "t": 50, + "s": [ + -2.3, + 26.799 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.96862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 4, + "ty": 4, + "nm": "pad4", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 296.202, + 337.035, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2.191, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -6.784, + -10.026 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + -1.723, + 9.732 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -2.3, + 26.799 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.096862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 5, + "ty": 4, + "nm": "pad5", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 341.642, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 394.475, + 337.035, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 10, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + }, + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 15, + "s": [ + { + "i": [ + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ], + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ] + ], + "o": [ + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ], + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ] + ], + "v": [ + [ + -0.074, + -14.595 + ], + [ + 14.448, + -0.074 + ], + [ + -0.074, + 14.448 + ], + [ + -14.595, + -0.074 + ] + ], + "c": true + } + ] + }, + { + "t": 20, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + } + ], + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 1, + "k": [ + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 10, + "s": [ + 2.191 + ] + }, + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 15, + "s": [ + 26.291 + ] + }, + { + "t": 20, + "s": [ + 2.191 + ] + } + ], + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 10, + "s": [ + -6.784, + -10.026 + ], + "to": [ + 2.912, + 1.444 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 15, + "s": [ + 10.687, + -1.359 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 2.912, + 1.444 + ] + }, + { + "t": 20, + "s": [ + -6.784, + -10.026 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 10, + "s": [ + -1.723, + 9.732 + ], + "to": [ + -2.587, + -3.499 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 15, + "s": [ + -17.246, + -11.259 + ], + "to": [ + 0, + 0 + ], + "ti": [ + -2.587, + -3.499 + ] + }, + { + "t": 20, + "s": [ + -1.723, + 9.732 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.5, + "y": 1 + }, + "o": { + "x": 0, + "y": 0 + }, + "t": 10, + "s": [ + -2.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 1, + "y": 1 + }, + "o": { + "x": 0.5, + "y": 0 + }, + "t": 15, + "s": [ + -31.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "t": 20, + "s": [ + -2.3, + 26.799 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.96862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 6, + "ty": 4, + "nm": "pad6", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 492.714, + 337.035, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2.191, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -6.784, + -10.026 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + -1.723, + 9.732 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -2.3, + 26.799 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.096862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 7, + "ty": 4, + "nm": "pad7", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 296.202, + 433.773, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 0, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + }, + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 5, + "s": [ + { + "i": [ + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ], + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ] + ], + "o": [ + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ], + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ] + ], + "v": [ + [ + -0.074, + -14.595 + ], + [ + 14.448, + -0.074 + ], + [ + -0.074, + 14.448 + ], + [ + -14.595, + -0.074 + ] + ], + "c": true + } + ] + }, + { + "t": 10, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + } + ], + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 1, + "k": [ + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 0, + "s": [ + 2.191 + ] + }, + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 5, + "s": [ + 26.291 + ] + }, + { + "t": 10, + "s": [ + 2.191 + ] + } + ], + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 0, + "s": [ + -6.784, + -10.026 + ], + "to": [ + 2.912, + 1.444 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 5, + "s": [ + 10.687, + -1.359 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 2.912, + 1.444 + ] + }, + { + "t": 10, + "s": [ + -6.784, + -10.026 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 0, + "s": [ + -1.723, + 9.732 + ], + "to": [ + -2.587, + -3.499 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 5, + "s": [ + -17.246, + -11.259 + ], + "to": [ + 0, + 0 + ], + "ti": [ + -2.587, + -3.499 + ] + }, + { + "t": 10, + "s": [ + -1.723, + 9.732 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.5, + "y": 1 + }, + "o": { + "x": 0, + "y": 0 + }, + "t": 0, + "s": [ + -2.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 1, + "y": 1 + }, + "o": { + "x": 0.5, + "y": 0 + }, + "t": 5, + "s": [ + -31.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "t": 10, + "s": [ + -2.3, + 26.799 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.96862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 8, + "ty": 4, + "nm": "pad8", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 394.475, + 433.773, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2.191, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -6.784, + -10.026 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + -1.723, + 9.732 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + -2.3, + 26.799 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.096862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 9, + "ty": 4, + "nm": "pad9", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 492.714, + 433.773, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 30, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + }, + { + "i": { + "x": 0.12, + "y": 0.58 + }, + "o": { + "x": 0.88, + "y": 0.42 + }, + "t": 35, + "s": [ + { + "i": [ + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ], + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ] + ], + "o": [ + [ + 8.158, + 0 + ], + [ + 0, + 8.158 + ], + [ + -8.158, + 0 + ], + [ + 0, + -8.158 + ] + ], + "v": [ + [ + -0.074, + -14.595 + ], + [ + 14.448, + -0.074 + ], + [ + -0.074, + 14.448 + ], + [ + -14.595, + -0.074 + ] + ], + "c": true + } + ] + }, + { + "t": 40, + "s": [ + { + "i": [ + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ], + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ] + ], + "o": [ + [ + 6.563, + 0 + ], + [ + 0, + 6.563 + ], + [ + -6.563, + 0 + ], + [ + 0, + -6.563 + ] + ], + "v": [ + [ + 0, + -11.683 + ], + [ + 11.683, + 0 + ], + [ + 0, + 11.683 + ], + [ + -11.683, + 0 + ] + ], + "c": true + } + ] + } + ], + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 1, + "k": [ + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 30, + "s": [ + 2.191 + ] + }, + { + "i": { + "x": [ + 0.12 + ], + "y": [ + 0.929 + ] + }, + "o": { + "x": [ + 0.88 + ], + "y": [ + 0.071 + ] + }, + "t": 35, + "s": [ + 26.291 + ] + }, + { + "t": 40, + "s": [ + 2.191 + ] + } + ], + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 1, + 1, + 1, + 0.5, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0.32, + 0.5, + 0.16, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 30, + "s": [ + -6.784, + -10.026 + ], + "to": [ + 2.912, + 1.444 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 35, + "s": [ + 10.687, + -1.359 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 2.912, + 1.444 + ] + }, + { + "t": 40, + "s": [ + -6.784, + -10.026 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 30, + "s": [ + -1.723, + 9.732 + ], + "to": [ + -2.587, + -3.499 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 35, + "s": [ + -17.246, + -11.259 + ], + "to": [ + 0, + 0 + ], + "ti": [ + -2.587, + -3.499 + ] + }, + { + "t": 40, + "s": [ + -1.723, + 9.732 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.208, + 0.996, + 0.718, + 1, + 0.208, + 0.996, + 0.718, + 0, + 1, + 0.5, + 0.66, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -0.018, + -0.266 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -0.928, + 26.32 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.839215695858, + 0.996078431606, + 0.945098042488, + 0.800000011921 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 80, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Inner Print", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "d": 1, + "ty": "el", + "s": { + "a": 0, + "k": [ + 58.339, + 58.339 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "nm": "Ellipse Path 1", + "mn": "ADBE Vector Shape - Ellipse", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 2, + "ix": 10 + }, + "g": { + "p": 5, + "k": { + "a": 0, + "k": [ + 0, + 0.141, + 0.358, + 0.3, + 0.261, + 0.226, + 0.576, + 0.483, + 0.521, + 0.312, + 0.794, + 0.666, + 0.761, + 0.235, + 0.598, + 0.501, + 1, + 0.158, + 0.402, + 0.337 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.5, + "y": 1 + }, + "o": { + "x": 0, + "y": 0 + }, + "t": 30, + "s": [ + -2.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "i": { + "x": 1, + "y": 1 + }, + "o": { + "x": 0.5, + "y": 0 + }, + "t": 35, + "s": [ + -31.3, + 26.799 + ], + "to": [ + 0, + 0 + ], + "ti": [ + 0, + 0 + ] + }, + { + "t": 40, + "s": [ + -2.3, + 26.799 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + 27.512, + 23.572 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.5, + 0.18, + 0.486, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.25, + 0.5, + 0.125, + 1, + 0 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + -2.813, + -47.219 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 21.861, + 13.823 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.96862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 16, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.133, + -0.051 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 1", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 10, + "ty": 4, + "nm": "bar", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 1, + "k": [ + { + "i": { + "x": [ + 0.1 + ], + "y": [ + 1 + ] + }, + "o": { + "x": [ + 0.9 + ], + "y": [ + 0 + ] + }, + "t": 60, + "s": [ + 0 + ] + }, + { + "i": { + "x": [ + 0.1 + ], + "y": [ + 1 + ] + }, + "o": { + "x": [ + 0.9 + ], + "y": [ + 0 + ] + }, + "t": 70, + "s": [ + 43 + ] + }, + { + "t": 80, + "s": [ + 0 + ] + } + ], + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 385.481, + 621.615, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 41.9, + 82.869, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + 22.626, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + 22.627 + ], + [ + -22.626, + 0 + ], + [ + 0, + 0 + ], + [ + 0, + -22.626 + ] + ], + "o": [ + [ + 0, + 0 + ], + [ + -22.626, + 0 + ], + [ + 0, + -22.626 + ], + [ + 0, + 0 + ], + [ + 22.626, + 0 + ], + [ + 0, + 22.627 + ] + ], + "v": [ + [ + 213.224, + 40.969 + ], + [ + -213.225, + 40.969 + ], + [ + -254.192, + 0 + ], + [ + -213.225, + -40.969 + ], + [ + 213.224, + -40.969 + ], + [ + 254.193, + 0 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 6.4, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.086, + 0.264, + 0.221, + 0.5, + 0.227, + 0.628, + 0.497, + 1, + 0.368, + 0.991, + 0.773 + ], + "ix": 8 + } + }, + "s": { + "a": 0, + "k": [ + 255.785, + -65.331 + ], + "ix": 4 + }, + "e": { + "a": 0, + "k": [ + -247.634, + 64.163 + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.162, + 0.777, + 0.56, + 1, + 0.116, + 0.558, + 0.402 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + 157.33, + -12.543 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -612.037, + 233.426 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 296.092, + 82.869 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Group 1", + "np": 3, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 11, + "ty": 4, + "nm": "Handle-Circle", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 32, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 327.241, + 622.026, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ind": 0, + "ty": "sh", + "ix": 1, + "ks": { + "a": 0, + "k": { + "i": [ + [ + -12.31, + 0 + ], + [ + 0, + -12.31 + ], + [ + 12.31, + 0 + ], + [ + 0, + 12.31 + ] + ], + "o": [ + [ + 12.31, + 0 + ], + [ + 0, + 12.31 + ], + [ + -12.31, + 0 + ], + [ + 0, + -12.31 + ] + ], + "v": [ + [ + 0, + -21.912 + ], + [ + 21.912, + 0 + ], + [ + 0, + 21.912 + ], + [ + -21.912, + 0 + ] + ], + "c": true + }, + "ix": 2 + }, + "nm": "Path 1", + "mn": "ADBE Vector Shape - Group", + "hd": false + }, + { + "ty": "rd", + "nm": "Round Corners 1", + "r": { + "a": 0, + "k": 8, + "ix": 1 + }, + "ix": 2, + "mn": "ADBE Vector Filter - RC", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.361, + 0.973, + 0.812, + 0.284, + 0.18, + 0.486, + 0.406, + 0.567, + 0, + 0, + 0, + 0, + 0.24, + 0.284, + 0.62, + 0.567, + 1 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + 12.326, + 43.735 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + 0, + -27.48 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Ellipse 6436", + "np": 3, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 12, + "ty": 4, + "nm": "Handle-Area", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 390.734, + 622.024, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ty": "rc", + "d": 1, + "s": { + "a": 0, + "k": [ + 222.305, + 131.453 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 120, + "ix": 4 + }, + "nm": "Rectangle Path 1", + "mn": "ADBE Vector Shape - Rect", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 5.478, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.38, + 0.969, + 0.812, + 0.5, + 0.19, + 0.484, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.5, + 0.5, + 0.25, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.833, + "y": 0.833 + }, + "o": { + "x": 0.167, + "y": 0.167 + }, + "t": 60, + "s": [ + -11.953, + 80.065 + ], + "to": [ + -25.824, + -9.311 + ], + "ti": [ + 8.612, + 22.746 + ] + }, + { + "i": { + "x": 0.833, + "y": 0.833 + }, + "o": { + "x": 0.167, + "y": 0.167 + }, + "t": 60, + "s": [ + -11.953, + 80.065 + ], + "to": [ + -25.824, + -9.311 + ], + "ti": [ + 8.612, + 22.746 + ] + }, + { + "t": 89, + "s": [ + -63.623, + -56.413 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.833, + "y": 0.833 + }, + "o": { + "x": 0.167, + "y": 0.167 + }, + "t": 60, + "s": [ + -2.884, + -74.535 + ], + "to": [ + 18.507, + 4.192 + ], + "ti": [ + 2.212, + -21.549 + ] + }, + { + "i": { + "x": 0.833, + "y": 0.833 + }, + "o": { + "x": 0.167, + "y": 0.167 + }, + "t": 60, + "s": [ + -2.884, + -74.535 + ], + "to": [ + 18.507, + 4.192 + ], + "ti": [ + 2.212, + -21.549 + ] + }, + { + "t": 89, + "s": [ + -16.156, + 54.76 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "st", + "c": { + "a": 0, + "k": [ + 0.380392163992, + 0.96862745285, + 0.811764717102, + 0.159999996424 + ], + "ix": 3 + }, + "o": { + "a": 0, + "k": 16, + "ix": 4 + }, + "w": { + "a": 0, + "k": 5.478, + "ix": 5 + }, + "lc": 1, + "lj": 1, + "ml": 4, + "bm": 0, + "nm": "Stroke 1", + "mn": "ADBE Vector Graphic - Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.208, + 0.996, + 0.718, + 0.5, + 0.104, + 0.931, + 0.71, + 1, + 0, + 0.867, + 0.702, + 0, + 0, + 0.5, + 0.16, + 1, + 0.32 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + 93.381, + -48.146 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -204.584, + 98.918 + ], + "ix": 6 + }, + "t": 1, + "nm": "Gradient Fill 2", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -0.128, + -0.682 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Rectangle 19102", + "np": 4, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": -59, + "op": 126, + "st": -59, + "bm": 0 + }, + { + "ddd": 0, + "ind": 13, + "ty": 4, + "nm": "Inner", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 386.579, + 467.246, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 115.9, + 115.9, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "shapes": [ + { + "ty": "gr", + "it": [ + { + "ty": "rc", + "d": 1, + "s": { + "a": 0, + "k": [ + 326.465, + 570.551 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 32, + "ix": 4 + }, + "nm": "Rectangle Path 1", + "mn": "ADBE Vector Shape - Rect", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 3.272, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.38, + 0.969, + 0.812, + 0.5, + 0.19, + 0.484, + 0.406, + 1, + 0, + 0, + 0, + 0, + 0.5, + 0.5, + 0.25, + 1, + 0 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.827, + "y": 0.495 + }, + "o": { + "x": 0.88, + "y": 0.331 + }, + "t": 0, + "s": [ + 86.346, + -243.003 + ], + "to": [ + 36.639, + 23.421 + ], + "ti": [ + -15.048, + 69.293 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.827, + "y": 0.707 + }, + "o": { + "x": 0.88, + "y": 0.192 + }, + "t": 0, + "s": [ + 8.018, + 187.979 + ], + "to": [ + -38.331, + -44.171 + ], + "ti": [ + 13.568, + -51.072 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "gf", + "o": { + "a": 0, + "k": 100, + "ix": 10 + }, + "r": 1, + "bm": 0, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.05, + 0.06, + 0.057, + 0.5, + 0.025, + 0.273, + 0.225, + 1, + 0, + 0.486, + 0.393 + ], + "ix": 9 + } + }, + "s": { + "a": 0, + "k": [ + 125.195, + -225.063 + ], + "ix": 5 + }, + "e": { + "a": 0, + "k": [ + -821.18, + 711.383 + ], + "ix": 6 + }, + "t": 2, + "h": { + "a": 0, + "k": 7.772, + "ix": 7 + }, + "a": { + "a": 0, + "k": 29.798, + "ix": 8 + }, + "nm": "Gradient Fill 1", + "mn": "ADBE Vector Graphic - G-Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + 8.205, + -0.413 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Rectangle 1", + "np": 3, + "cix": 2, + "bm": 0, + "ix": 1, + "mn": "ADBE Vector Group", + "hd": false + }, + { + "ty": "gr", + "it": [ + { + "ty": "rc", + "d": 1, + "s": { + "a": 0, + "k": [ + 326.465, + 570.551 + ], + "ix": 2 + }, + "p": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 32, + "ix": 4 + }, + "nm": "Rectangle Path 1", + "mn": "ADBE Vector Shape - Rect", + "hd": false + }, + { + "ty": "gs", + "o": { + "a": 0, + "k": 100, + "ix": 9 + }, + "w": { + "a": 0, + "k": 3.272, + "ix": 10 + }, + "g": { + "p": 3, + "k": { + "a": 0, + "k": [ + 0, + 0.38, + 0.969, + 0.812, + 0.5, + 0.19, + 0.639, + 0.561, + 1, + 0, + 0.31, + 0.31 + ], + "ix": 8 + } + }, + "s": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 0, + "s": [ + 15.048, + -216.147 + ], + "to": [ + 52.793, + 52.374 + ], + "ti": [ + 0, + 0 + ] + } + ], + "ix": 4 + }, + "e": { + "a": 1, + "k": [ + { + "i": { + "x": 0.12, + "y": 0.86 + }, + "o": { + "x": 0.88, + "y": 0.14 + }, + "t": 0, + "s": [ + 8.021, + 197.313 + ], + "to": [ + -69.685, + -22.712 + ], + "ti": [ + 0, + 0 + ] + } + ], + "ix": 5 + }, + "t": 1, + "lc": 1, + "lj": 1, + "ml": 4, + "ml2": { + "a": 0, + "k": 4, + "ix": 13 + }, + "bm": 0, + "nm": "Gradient Stroke 1", + "mn": "ADBE Vector Graphic - G-Stroke", + "hd": false + }, + { + "ty": "fl", + "c": { + "a": 0, + "k": [ + 0, + 0, + 0, + 1 + ], + "ix": 4 + }, + "o": { + "a": 0, + "k": 100, + "ix": 5 + }, + "r": 1, + "bm": 0, + "nm": "Fill 1", + "mn": "ADBE Vector Graphic - Fill", + "hd": false + }, + { + "ty": "tr", + "p": { + "a": 0, + "k": [ + -8.881, + -0.413 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 0, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100 + ], + "ix": 3 + }, + "r": { + "a": 0, + "k": 0, + "ix": 6 + }, + "o": { + "a": 0, + "k": 100, + "ix": 7 + }, + "sk": { + "a": 0, + "k": 0, + "ix": 4 + }, + "sa": { + "a": 0, + "k": 0, + "ix": 5 + }, + "nm": "Transform" + } + ], + "nm": "Rectangle 2", + "np": 3, + "cix": 2, + "bm": 0, + "ix": 2, + "mn": "ADBE Vector Group", + "hd": false + } + ], + "ip": 0, + "op": 90, + "st": 0, + "bm": 0 + }, + { + "ddd": 0, + "ind": 14, + "ty": 0, + "nm": "wi-fi ", + "refId": "comp_0", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 500, + 500, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 500, + 500, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "w": 1000, + "h": 1000, + "ip": 45, + "op": 105, + "st": 45, + "bm": 0 + }, + { + "ddd": 0, + "ind": 15, + "ty": 0, + "nm": "wi-fi ", + "refId": "comp_0", + "sr": 1, + "ks": { + "o": { + "a": 0, + "k": 100, + "ix": 11 + }, + "r": { + "a": 0, + "k": 0, + "ix": 10 + }, + "p": { + "a": 0, + "k": [ + 500, + 500, + 0 + ], + "ix": 2 + }, + "a": { + "a": 0, + "k": [ + 500, + 500, + 0 + ], + "ix": 1 + }, + "s": { + "a": 0, + "k": [ + 100, + 100, + 100 + ], + "ix": 6 + } + }, + "ao": 0, + "w": 1000, + "h": 1000, + "ip": 0, + "op": 60, + "st": 0, + "bm": 0 + } + ], + "markers": [] +} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test2.svg b/components/thorvg-main/test/resources/test2.svg new file mode 100644 index 0000000..2ec1959 --- /dev/null +++ b/components/thorvg-main/test/resources/test2.svg @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + +Verify the basic capability to handle the 'path' element, and its data attribute (d) +in combination with the straight-line path commands. +Two pairs of concentric equilateral triangles are drawn using +M and Z. No L commands are used in this test as they are implied after +an M or Z command. The shapes are identical, with one stroked and +one filled. The fill-mode default of "even-odd" means that +the inner triangle is hollow. + + +The rendered picture should match the reference image exactly, except for possible +variations in the labelling text (per CSS2 rules). + + +The test uses the 'path' element, as well as basic fill (solid primary colors), +stroke (black 1-pixel lines), font-family (Arial) and font-size properties. + + + + + paths-data-08-t + Test that viewer has the basic capability to handle the <path> element and data (d) attribute in combination with the moveto and closepath commands - M and Z. + + + + + + + + Lines drawn with commands: + M and Z + + + + + + + + + + stroked + + + + + + + + filled + + + $Revision: 1.2 $ + + diff --git a/components/thorvg-main/test/resources/test3.lot b/components/thorvg-main/test/resources/test3.lot new file mode 100644 index 0000000..631d523 --- /dev/null +++ b/components/thorvg-main/test/resources/test3.lot @@ -0,0 +1 @@ +{"v":"5.9.0","fr":59.9700012207031,"ip":0,"op":360.000036657751,"w":1200,"h":1200,"nm":"TVG","ddd":0,"assets":[],"fonts":{"list":[{"fName":"Helvetica","fFamily":"Helvetica","fStyle":"Regular","ascent":71.8994140625}]},"layers":[{"ddd":0,"ind":1,"ty":5,"nm":"ThorVG","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[432,436,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"hasMask":true,"masksProperties":[{"inv":false,"mode":"n","pt":{"a":0,"k":{"i":[[0,0],[-259.912,7.27],[-121.255,9.112],[-108.042,19.179],[-112.693,41.191],[-63.206,59.879],[-11.167,93.323],[57.248,58.644],[85.108,15.531],[100.711,-26.083],[50.89,-77.977],[-26.964,-76.745],[-71.423,-46.772],[-98.628,-27.755],[-170.142,-33.105],[-127.268,-7.905],[-201.893,-5.741]],"o":[[173.363,-0.243],[121.549,-3.4],[109.422,-8.223],[118.138,-20.971],[81.775,-29.89],[68.231,-64.64],[9.737,-81.373],[-60.432,-61.906],[-102.344,-18.676],[-90.14,23.346],[-44.458,68.121],[28.301,80.548],[85.715,56.132],[166.852,46.953],[125.166,24.354],[302.322,18.778],[0,0]],"v":[[-1228,444],[-448,436],[-84,412],[244,384],[592,292],[824,172],[972,-68],[880,-296],[643.999,-404],[332,-396],[88,-260],[84,-16],[244,184],[536,280],[1039.999,408],[1420,452],[2328,488]],"c":false},"ix":1},"o":{"a":0,"k":100,"ix":3},"x":{"a":0,"k":0,"ix":4},"nm":"Mask 1"}],"t":{"d":{"k":[{"s":{"s":200,"f":"Helvetica","t":"ThorVG","ca":0,"j":0,"tr":0,"lh":240.000015258789,"ls":0,"fc":[0.991,0.407,0.016]},"t":0}]},"p":{"m":0,"f":{"a":1,"k":[{"i":{"x":[0.499],"y":[1.746]},"o":{"x":[0.225],"y":[-0.308]},"t":0,"s":[0]},{"i":{"x":[0.58],"y":[0.978]},"o":{"x":[0.257],"y":[0.11]},"t":0,"s":[0]},{"i":{"x":[0.828],"y":[0.874]},"o":{"x":[0.462],"y":[0.016]},"t":201,"s":[2329.661]},{"i":{"x":[0.673],"y":[1.006]},"o":{"x":[0.34],"y":[-0.007]},"t":424,"s":[7000]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":426,"s":[5500]},{"t":695.00002830793,"s":[7000]}],"ix":5},"l":{"a":0,"k":0,"ix":6},"a":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":1,"ix":3},"r":{"a":0,"k":0,"ix":2}},"m":{"g":1,"a":{"a":0,"k":[0,0],"ix":2}},"a":[]},"ip":0,"op":900.000036657751,"st":0,"bm":0}],"markers":[],"chars":[{"ch":"T","size":200,"style":"Regular","w":61.08,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[1.611,-71.729],[1.611,-63.184],[25.781,-63.184],[25.781,0],[35.596,0],[35.596,-63.184],[59.766,-63.184],[59.766,-71.729]],"c":true},"ix":2},"nm":"T","mn":"ADBE Vector Shape - Group","hd":false}],"nm":"T","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}]},"fFamily":"Helvetica"},{"ch":"h","size":200,"style":"Regular","w":55.62,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[-2.962,2.507],[-3.646,0],[-1.595,-2.864],[0,-3.841],[0,0],[0,0],[0,0],[1.465,2.898],[7.584,0],[2.832,-1.855],[2.083,-2.637],[0,0],[0,0]],"o":[[0,0],[0,0],[0,-6.966],[2.962,-2.506],[4.395,0],[0.977,1.791],[0,0],[0,0],[0,0],[0,-5.143],[-2.702,-5.305],[-4.232,0],[-1.66,1.074],[0,0],[0,0],[0,0]],"v":[[6.445,0],[15.234,0],[15.234,-27.734],[19.678,-41.943],[29.59,-45.703],[38.574,-41.406],[40.039,-32.959],[40.039,0],[49.072,0],[49.072,-33.545],[46.875,-45.605],[31.445,-53.564],[20.85,-50.781],[15.234,-45.215],[15.234,-71.973],[6.445,-71.973]],"c":true},"ix":2},"nm":"h","mn":"ADBE Vector Shape - Group","hd":false}],"nm":"h","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}]},"fFamily":"Helvetica"},{"ch":"o","size":200,"style":"Regular","w":55.62,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[5.761,0],[2.414,3.706],[0,5.56],[-2.414,4.097],[-5.312,0],[-2.446,-4.812],[0,-4.877],[2.141,-4.405]],"o":[[-5.247,0],[-2.414,-3.706],[0,-5.787],[2.414,-4.097],[5.987,0],[1.545,3.056],[0,5.397],[-2.141,4.405]],"v":[[27.026,-5.713],[15.535,-11.272],[11.914,-25.172],[15.535,-39.997],[27.122,-46.143],[39.772,-38.924],[42.09,-27.025],[38.879,-12.321]],"c":true},"ix":2},"nm":"o","mn":"ADBE Vector Shape - Group","hd":false},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[6.691,0],[4.428,-5.203],[0,-8.781],[-4.202,-4.862],[-7.144,0],[-4.073,5.496],[0,8.424],[4.622,4.488]],"o":[[-7.467,0],[-4.428,5.204],[0,8.196],[4.202,4.862],[8.566,0],[4.073,-5.496],[0,-8.716],[-4.623,-4.488]],"v":[[27.366,-53.809],[9.523,-46.003],[2.881,-25.025],[9.184,-5.437],[26.202,1.855],[45.16,-6.389],[51.27,-27.27],[44.336,-47.076]],"c":true},"ix":2},"nm":"o","mn":"ADBE Vector Shape - Group","hd":false}],"nm":"o","np":5,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}]},"fFamily":"Helvetica"},{"ch":"r","size":200,"style":"Regular","w":33.3,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[-2.377,2.849],[-4.427,0],[-0.439,-0.032],[-0.521,-0.098],[0,0],[0.391,0.033],[0.163,0],[2.669,-2.522],[0.684,-1.758],[0,0],[0,0]],"o":[[0,0],[0,0],[0,-3.711],[2.376,-2.848],[0.52,0],[0.439,0.033],[0,0],[-0.945,-0.098],[-0.391,-0.032],[-3.484,0],[-2.67,2.523],[0,0],[0,0],[0,0]],"v":[[6.689,0],[15.479,0],[15.479,-30.078],[19.043,-39.917],[29.248,-44.189],[30.688,-44.141],[32.129,-43.945],[32.129,-53.223],[30.127,-53.418],[29.297,-53.467],[20.068,-49.683],[15.039,-43.262],[15.039,-52.295],[6.689,-52.295]],"c":true},"ix":2},"nm":"r","mn":"ADBE Vector Shape - Group","hd":false}],"nm":"r","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}]},"fFamily":"Helvetica"},{"ch":"V","size":200,"style":"Regular","w":66.7,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[2.563,-71.729],[28.687,0],[38.989,0],[65.161,-71.729],[54.272,-71.729],[33.911,-10.645],[13.306,-71.729]],"c":true},"ix":2},"nm":"V","mn":"ADBE Vector Shape - Group","hd":false}],"nm":"V","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}]},"fFamily":"Helvetica"},{"ch":"G","size":200,"style":"Regular","w":77.78,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[6.641,0],[6.096,-6.77],[0,-12.012],[-6.564,-6.901],[-8.358,0],[-4.195,2.409],[-3.235,3.613],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[4.163,-3.76],[6.348,0],[3.668,5.355],[0,8.529],[-4.447,4.98],[-6.503,0],[-3.603,-2.393],[-1.147,-5.241],[0,0],[7.026,3.744]],"o":[[-9.689,0],[-6.416,7.097],[0,12.045],[6.02,5.502],[6.468,0],[2.497,-1.399],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.098,8.398],[-4.163,3.76],[-8.295,0],[-3.669,-5.354],[0,-9.863],[4.446,-4.98],[5.482,0],[3.603,2.393],[0,0],[-1.572,-9.375],[-4.845,-2.604]],"v":[[38.136,-73.584],[14.458,-63.428],[4.834,-34.766],[14.68,-6.348],[36.247,1.904],[52.242,-1.709],[60.84,-9.229],[63.184,0],[69.434,0],[69.434,-38.379],[37.939,-38.379],[37.939,-30.322],[60.4,-30.322],[54.009,-12.085],[38.242,-6.445],[20.298,-14.478],[14.795,-35.303],[21.465,-57.568],[37.891,-65.039],[51.517,-61.45],[58.643,-50],[68.262,-50],[55.364,-69.678]],"c":true},"ix":2},"nm":"G","mn":"ADBE Vector Shape - Group","hd":false}],"nm":"G","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}]},"fFamily":"Helvetica"}]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test3.svg b/components/thorvg-main/test/resources/test3.svg new file mode 100644 index 0000000..3135689 --- /dev/null +++ b/components/thorvg-main/test/resources/test3.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/thorvg-main/test/resources/test4.lot b/components/thorvg-main/test/resources/test4.lot new file mode 100644 index 0000000..68d0681 --- /dev/null +++ b/components/thorvg-main/test/resources/test4.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":150,"w":500,"h":500,"nm":"Transform Tests (Skew & 3D)","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer with Skew","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]},"sk":{"a":1,"k":[{"t":0,"s":[0],"e":[30]},{"t":30,"s":[30],"e":[0]},{"t":60,"s":[0]}]},"sa":{"a":0,"k":0}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":1,"ind":2,"ty":4,"nm":"3D Rotated Shape","sr":1,"ks":{"o":{"a":0,"k":100},"rx":{"a":1,"k":[{"t":0,"s":[0],"e":[45]},{"t":30,"s":[45],"e":[0]},{"t":60,"s":[0]}]},"ry":{"a":1,"k":[{"t":0,"s":[0],"e":[30]},{"t":60,"s":[30]}]},"rz":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[60,60]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[0.2,0.5,0.9,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Skew Test Shape","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]},"sk":{"a":1,"k":[{"t":0,"s":[0],"e":[30]},{"t":15,"s":[30],"e":[60]},{"t":30,"s":[60],"e":[30]},{"t":45,"s":[30],"e":[45]},{"t":60,"s":[45],"e":[30]},{"t":75,"s":[30],"e":[0]},{"t":90,"s":[0]}]},"sa":{"a":1,"k":[{"t":0,"s":[0],"e":[0]},{"t":15,"s":[0],"e":[45]},{"t":30,"s":[45],"e":[90]},{"t":45,"s":[90],"e":[-90]},{"t":60,"s":[-90],"e":[180]},{"t":75,"s":[180],"e":[0]},{"t":90,"s":[0]}]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":10},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[0.2,0.6,0.9,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ty":4,"nm":"Rectangle 2","sr":1,"st":0,"op":150,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"sk":{"a":0,"k":0},"p":{"a":0,"k":[304.5,352.2827]},"r":{"a":0,"k":0},"sa":{"a":0,"k":0},"o":{"a":0,"k":100}},"shapes":[{"ty":"rc","bm":0,"hd":false,"nm":"Rectangle Path 2","d":1,"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"s":{"a":0,"k":[133,98.56532879503823]}},{"ty":"fl","bm":0,"hd":false,"nm":"Fill","c":{"a":1,"k":[{"o":{"x":0.167,"y":0.167},"i":{"x":0.833,"y":0.833},"s":[1,0.5569,0.9255],"t":0},{"s":[0.3176,0.0157,0.2667],"t":23}],"sid":"sdf"},"r":1,"o":{"a":0,"k":100}}],"ind":4},{"ty":4,"nm":"Rectangle 1","sr":1,"st":0,"op":150,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"sk":{"a":0,"k":0},"p":{"a":0,"k":[133,210.8551]},"r":{"a":0,"k":0},"sa":{"a":0,"k":0},"o":{"a":0,"k":100}},"shapes":[{"ty":"rc","bm":0,"hd":false,"nm":"Rectangle Path 1","d":1,"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"s":{"a":0,"k":[58.00000000000001,65.71021919669215]}},{"ty":"fl","bm":0,"hd":false,"nm":"Fill","c":{"a":0,"k":[1,0.5569,0.9255],"sid":"sdf"},"r":1,"o":{"a":0,"k":100}}],"ind":5}]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test5.lot b/components/thorvg-main/test/resources/test5.lot new file mode 100644 index 0000000..8e12a00 --- /dev/null +++ b/components/thorvg-main/test/resources/test5.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":90,"w":400,"h":400,"nm":"Basic Shapes Tests","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Rectangle Shape","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[75,75,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[60,40]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":5},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"st","c":{"a":0,"k":[0,0,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":2},"lc":1,"lj":1,"ml":4,"nm":"Stroke"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Ellipse Shape","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[225,75,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[50,50]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Polystar Shape","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,225,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","sy":1,"d":1,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":30},"ir":{"a":0,"k":15},"nm":"Polystar"},{"ty":"fl","c":{"a":0,"k":[0,0,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"Custom Path with Stroke","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[-40,-40],[40,-40],[40,40],[-40,40]],"c":true}},"nm":"Path"},{"ty":"st","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"lc":2,"lj":2,"ml":4,"d":[{"n":"d","nm":"dash","v":{"a":0,"k":10}},{"n":"g","nm":"gap","v":{"a":0,"k":5}},{"n":"o","nm":"offset","v":{"a":0,"k":0}}],"nm":"Dashed Stroke"},{"ty":"fl","c":{"a":0,"k":[0,0.8,0.4,1]},"o":{"a":0,"k":50},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":5,"ty":4,"nm":"Grouped Shapes","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":60,"s":[360]}]},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[40,40]},"p":{"a":0,"k":[20,0]},"r":{"a":0,"k":5},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[1,0.3,0.3,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Group 1"},{"ty":"gr","it":[{"ty":"el","d":1,"s":{"a":0,"k":[30,30]},"p":{"a":0,"k":[-20,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[0.3,0.3,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Group 2"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":6,"ty":4,"nm":"Expression Driven Position","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,150,0],"x":"var t = time; [150 + Math.sin(t * 2) * 50, 150 + Math.cos(t * 2) * 50]"},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[30,30]},"p":{"a":0,"k":[0,0]},"nm":"Circle"},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":7,"ty":4,"nm":"Expression Driven Rotation","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0,"x":"time * 100"},"p":{"a":0,"k":[150,150,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[60,10]},"p":{"a":0,"k":[30,0]},"r":{"a":0,"k":0},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[0,0,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":8,"ty":4,"nm":"Expression Driven Scale","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,220,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100],"x":"var s = 100 + Math.sin(time * 3) * 50; [s, s]"}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":30},"os":{"a":0,"k":0},"ir":{"a":0,"k":15},"is":{"a":0,"k":0},"nm":"Star"},{"ty":"fl","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":9,"ty":4,"nm":"Expression with Variables","sr":1,"ks":{"o":{"a":0,"k":100,"x":"var minOpacity = 30; var maxOpacity = 100; var cycle = Math.sin(time * 2); minOpacity + (maxOpacity - minOpacity) * (cycle + 1) / 2"},"r":{"a":0,"k":0},"p":{"a":0,"k":[80,80,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[40,40]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":5},"nm":"Rectangle"},{"ty":"fl","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":10,"ty":4,"nm":"Star with 5.3 Points","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","sy":1,"pt":{"a":0,"k":5.3},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[50]},"os":{"a":0,"k":[0]},"ir":{"a":0,"k":[25]},"is":{"a":0,"k":[0]},"nm":"Partial Star 5.3"},{"ty":"fl","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":11,"ty":4,"nm":"Star with 6.7 Points and Roundness","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"p":{"a":0,"k":[300,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","sy":1,"pt":{"a":0,"k":6.7},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[40]},"os":{"a":1,"k":[{"t":0,"s":[0],"e":[50]},{"t":45,"s":[50],"e":[0]},{"t":90,"s":[0]}]},"ir":{"a":0,"k":[20]},"is":{"a":1,"k":[{"t":0,"s":[0],"e":[30]},{"t":45,"s":[30],"e":[0]},{"t":90,"s":[0]}]},"nm":"Partial Star 6.7 with Roundness"},{"ty":"fl","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":12,"ty":4,"nm":"Star with 8.25 Points","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,300,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","sy":1,"pt":{"a":1,"k":[{"t":0,"s":[3.5],"e":[8.25]},{"t":45,"s":[8.25],"e":[3.5]},{"t":90,"s":[3.5]}]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[45]},"os":{"a":0,"k":[10]},"ir":{"a":0,"k":[22]},"is":{"a":0,"k":[5]},"nm":"Animated Partial Star"},{"ty":"fl","c":{"a":0,"k":[0,0,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":13,"ty":4,"nm":"Polygon with 5.5 Points","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[180]},{"t":90,"s":[180]}]},"p":{"a":0,"k":[300,300,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","sy":2,"pt":{"a":0,"k":5.5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[35]},"os":{"a":0,"k":[20]},"nm":"Partial Polygon 5.5"},{"ty":"st","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":3},"lc":2,"lj":2,"ml":4,"nm":"Stroke"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":14,"ty":4,"nm":"Mergeable Group with Non-Uniform Scale","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","bm":0,"it":[{"ty":"rc","d":1,"s":{"a":0,"k":[60,60]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":5},"nm":"Rectangle"},{"ty":"st","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":10},"lc":2,"lj":2,"ml":4,"nm":"Stroke"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":1,"k":[{"t":0,"s":[100,100],"e":[200,100]},{"t":45,"s":[200,100],"e":[100,200]},{"t":90,"s":[100,200]}]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Transform"}],"nm":"Mergeable Group"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":15,"ty":4,"nm":"Nested Groups with Transforms","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[300,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","bm":0,"it":[{"ty":"gr","bm":0,"it":[{"ty":"el","d":1,"s":{"a":0,"k":[40,40]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[0,1,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[15,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,150]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Inner Transform"}],"nm":"Inner Group"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":1,"k":[{"t":0,"s":[100,100],"e":[150,80]},{"t":90,"s":[150,80]}]},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[180]},{"t":90,"s":[180]}]},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Outer Transform"}],"nm":"Outer Group"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":16,"ty":4,"nm":"Group with Skew Transform","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,300,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","bm":0,"it":[{"ty":"rc","d":1,"s":{"a":0,"k":[50,50]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle"},{"ty":"st","c":{"a":0,"k":[0,0,1,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":1,"k":[{"t":0,"s":[0],"e":[45]},{"t":45,"s":[45],"e":[0]},{"t":90,"s":[0]}]},"sa":{"a":1,"k":[{"t":0,"s":[0],"e":[90]},{"t":45,"s":[90],"e":[0]},{"t":90,"s":[0]}]},"nm":"Skew Transform"}],"nm":"Skewed Group"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":17,"ty":4,"nm":"Multiple Shapes with Individual Transforms","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[300,300,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","bm":0,"it":[{"ty":"rc","d":1,"s":{"a":0,"k":[30,30]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":5},"nm":"Rect 1"},{"ty":"tr","p":{"a":0,"k":[-20,-20]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[90]},{"t":90,"s":[90]}]},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Transform 1"}],"nm":"Shape 1"},{"ty":"gr","bm":0,"it":[{"ty":"el","d":1,"s":{"a":0,"k":[25,25]},"p":{"a":0,"k":[0,0]},"nm":"Circle 2"},{"ty":"tr","p":{"a":0,"k":[20,20]},"a":{"a":0,"k":[0,0]},"s":{"a":1,"k":[{"t":0,"s":[100,100],"e":[150,150]},{"t":90,"s":[150,150]}]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Transform 2"}],"nm":"Shape 2"},{"ty":"fl","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0}]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test6.lot b/components/thorvg-main/test/resources/test6.lot new file mode 100644 index 0000000..e603ab2 --- /dev/null +++ b/components/thorvg-main/test/resources/test6.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":90,"w":400,"h":400,"nm":"Shape Modifiers Tests","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Trim Path Animation","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[80,80]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"tm","s":{"a":1,"k":[{"t":0,"s":[0],"e":[100]},{"t":60,"s":[100]}]},"e":{"a":0,"k":100},"o":{"a":0,"k":0},"m":1,"nm":"Trim Paths"},{"ty":"st","c":{"a":0,"k":[1,0,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"lc":2,"lj":1,"ml":4,"nm":"Stroke"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Repeated Circles","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,150,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[20,20]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[1,0.5,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"rp","c":{"a":0,"k":8},"o":{"a":0,"k":0},"m":1,"tr":{"ty":"tr","p":{"a":0,"k":[40,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":45},"so":{"a":0,"k":100},"eo":{"a":0,"k":100}},"nm":"Repeater"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Rounded Rectangle","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[100,80]},"p":{"a":0,"k":[0,0]},"r":{"a":1,"k":[{"t":0,"s":[5],"e":[30]},{"t":30,"s":[30],"e":[5]},{"t":60,"s":[5]}]},"nm":"Rectangle"},{"ty":"rd","r":{"a":0,"k":15},"nm":"Round Corners"},{"ty":"fl","c":{"a":0,"k":[0.4,0.6,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":3},{"ddd":0,"ind":4,"ty":4,"nm":"Overlay Circle","sr":1,"ks":{"o":{"a":0,"k":80},"r":{"a":0,"k":0},"p":{"a":0,"k":[200,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[70,70]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"fl","c":{"a":0,"k":[1,0.8,0.2,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":5},{"ddd":0,"ind":5,"ty":4,"nm":"Star with OffsetPath","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,150,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":60},"os":{"a":0,"k":0},"ir":{"a":0,"k":30},"is":{"a":0,"k":0},"nm":"Star"},{"ty":"op","a":{"a":1,"k":[{"t":0,"s":[0],"e":[10]},{"t":30,"s":[10],"e":[-10]},{"t":60,"s":[-10]}]},"lj":2,"ml":4,"nm":"OffsetPath 1"},{"ty":"st","c":{"a":0,"k":[1,0.5,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":3},"lc":2,"lj":2,"ml":4,"nm":"Stroke"},{"ty":"fl","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":70},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":6,"ty":4,"nm":"Rectangle with Multiple Offsets","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[80,80,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[50,50]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":5},"nm":"Rectangle"},{"ty":"op","a":{"a":0,"k":[5]},"lj":1,"ml":10,"nm":"OffsetPath Miter"},{"ty":"st","c":{"a":0,"k":[0,0.8,0.2,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":2},"lc":1,"lj":1,"ml":4,"nm":"Stroke"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":7,"ty":4,"nm":"Star with RoundedCorner","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":90,"s":[360]}]},"p":{"a":0,"k":[120,120,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":1,"k":[{"t":0,"s":[50],"e":[70]},{"t":45,"s":[70],"e":[50]},{"t":90,"s":[50]}]},"os":{"a":1,"k":[{"t":0,"s":[0],"e":[20]},{"t":45,"s":[20],"e":[0]},{"t":90,"s":[0]}]},"ir":{"a":0,"k":[25]},"is":{"a":0,"k":[0]},"nm":"Star with Roundness"},{"ty":"rd","r":{"a":1,"k":[{"t":0,"s":[5],"e":[25]},{"t":45,"s":[25],"e":[5]},{"t":90,"s":[5]}]},"nm":"RoundedCorner Animated"},{"ty":"fl","c":{"a":0,"k":[1,0.6,0,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"st","c":{"a":0,"k":[0.2,0.2,0.8,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":3},"lc":2,"lj":2,"ml":4,"nm":"Stroke"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":8,"ty":4,"nm":"Polygon with RoundedCorner","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[280,120,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":2,"pt":{"a":1,"k":[{"t":0,"s":[3],"e":[8]},{"t":45,"s":[8],"e":[3]},{"t":90,"s":[3]}]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[60]},"os":{"a":0,"k":[0]},"nm":"Polygon"},{"ty":"rd","r":{"a":0,"k":[15]},"nm":"RoundedCorner"},{"ty":"fl","c":{"a":0,"k":[0,1,0.5,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":9,"ty":4,"nm":"Star with OffsetPath","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[120,280,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":6},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[50]},"os":{"a":0,"k":[10]},"ir":{"a":0,"k":[20]},"is":{"a":0,"k":[5]},"nm":"Star"},{"ty":"op","a":{"a":1,"k":[{"t":0,"s":[0],"e":[8]},{"t":45,"s":[8],"e":[-8]},{"t":90,"s":[-8]}]},"lj":2,"ml":4,"nm":"OffsetPath Animated"},{"ty":"fl","c":{"a":0,"k":[1,0.2,0.6,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"},{"ty":"st","c":{"a":0,"k":[0.8,0.8,0,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":2},"lc":1,"lj":1,"ml":4,"nm":"Stroke"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":10,"ty":4,"nm":"Polygon with OffsetPath and RoundedCorner","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[280,280,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":2,"pt":{"a":0,"k":7},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":[55]},"os":{"a":0,"k":[0]},"nm":"Heptagon"},{"ty":"rd","r":{"a":1,"k":[{"t":0,"s":[0],"e":[20]},{"t":90,"s":[20]}]},"nm":"RoundedCorner"},{"ty":"op","a":{"a":0,"k":[5]},"lj":1,"ml":10,"nm":"OffsetPath"},{"ty":"fl","c":{"a":0,"k":[0.4,0.2,1,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":11,"ty":4,"nm":"Rectangle with Animated RoundedCorner","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,80,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[80,60]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":[10]},"nm":"Rectangle"},{"ty":"rd","r":{"a":1,"k":[{"t":0,"s":[2],"e":[30]},{"t":30,"s":[30],"e":[2]},{"t":60,"s":[2]}]},"nm":"RoundedCorner Extra"},{"ty":"fl","c":{"a":0,"k":[1,0.3,0.3,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":12,"ty":4,"nm":"Ellipse with OffsetPath","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[220,80,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[50,50]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"op","a":{"a":1,"k":[{"t":0,"s":[-10],"e":[10]},{"t":30,"s":[10],"e":[-10]},{"t":60,"s":[-10]}]},"lj":1,"ml":4,"nm":"OffsetPath"},{"ty":"st","c":{"a":0,"k":[0,0.7,1,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":4},"lc":2,"lj":2,"ml":4,"nm":"Stroke"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":13,"ty":4,"nm":"Path with OffsetPath","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,200,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[20,-10],[0,0],[-20,-10]],"o":[[-20,10],[0,0],[20,10],[0,0]],"v":[[-50,0],[0,-30],[50,0],[0,30]],"c":true}},"nm":"Custom Path"},{"ty":"op","a":{"a":1,"k":[{"t":0,"s":[0],"e":[15]},{"t":30,"s":[15],"e":[-15]},{"t":60,"s":[-15]}]},"lj":2,"ml":4,"nm":"OffsetPath Round"},{"ty":"fl","c":{"a":0,"k":[1,1,0,1]},"o":{"a":0,"k":80},"r":1,"nm":"Fill"},{"ty":"st","c":{"a":0,"k":[1,0,0.5,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":2},"lc":2,"lj":2,"ml":4,"nm":"Stroke"}],"ip":0,"op":60,"st":0,"bm":0},{"ty":4,"nm":"Round Corner Test","ip":0,"op":60,"shapes":[{"ty":"rc","nm":"Rectangle","p":{"a":0,"k":[200,200]},"s":{"a":0,"k":[150,150]},"r":{"a":0,"k":30}},{"ty":"rd","nm":"Round Corners","r":{"a":0,"k":20}},{"ty":"fl","nm":"Fill","c":{"a":0,"k":[0,0,1,1]},"o":{"a":0,"k":100}}],"ind":14},{"ty":4,"nm":"Round Corner with Path","ip":0,"op":60,"shapes":[{"ty":"sh","nm":"Custom Path","ks":{"a":0,"k":{"c":true,"v":[[100,100],[300,100],[300,300],[100,300]],"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]]}}},{"ty":"rd","nm":"Round Corners","r":{"a":0,"k":40}},{"ty":"st","nm":"Stroke","c":{"a":0,"k":[1,0,1,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":8}}],"ind":15}],"markers":[]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test7.lot b/components/thorvg-main/test/resources/test7.lot new file mode 100644 index 0000000..650530e --- /dev/null +++ b/components/thorvg-main/test/resources/test7.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":90,"w":400,"h":400,"nm":"Gradient Tests","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Linear Gradient","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[75,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[120,120]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":5,"k":{"a":0,"k":[0,1,0,0,0.25,1,0.5,0,0.5,0.5,1,0,0.75,0,1,0.5,1,0,0,1]}},"s":{"a":0,"k":[-50,0]},"e":{"a":0,"k":[50,0]},"t":1,"nm":"Linear Gradient Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Radial Gradient","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[225,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[100,100]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":3,"k":{"a":0,"k":[0,1,0.2,0.2,0.5,1,0.6,0,1,1,1,0]}},"s":{"a":0,"k":[0,0]},"e":{"a":0,"k":[50,0]},"t":2,"nm":"Radial Gradient Fill"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Gradient Stroke with Zero Opacity","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,80,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[60,60]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"gs","o":{"a":1,"k":[{"t":0,"s":[0],"e":[50]},{"t":20,"s":[50],"e":[100]},{"t":30,"s":[100]}]},"w":{"a":0,"k":8},"lc":2,"lj":2,"ml":4,"g":{"p":3,"k":{"a":0,"k":[0,1,0,0,0.5,0,1,0,1,0,0,1,0,1,0.5,1,1,1]}},"s":{"a":0,"k":[-30,0]},"e":{"a":0,"k":[30,0]},"t":1,"nm":"Gradient Stroke"}],"ip":0,"op":90,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"Gradient Stroke Varying Opacity","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[150,180,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[80,60]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":10},"nm":"Rectangle"},{"ty":"gs","o":{"a":1,"k":[{"t":30,"s":[10],"e":[30]},{"t":45,"s":[30],"e":[60]},{"t":60,"s":[60],"e":[90]},{"t":75,"s":[90],"e":[100]},{"t":90,"s":[100]}]},"w":{"a":0,"k":6},"lc":1,"lj":1,"ml":4,"g":{"p":2,"k":{"a":0,"k":[0,1,0.5,0,1,0,1,0.5,0,1,1,0.8]}},"s":{"a":0,"k":[0,-30]},"e":{"a":0,"k":[0,30]},"t":2,"nm":"Radial Gradient Stroke"}],"ip":0,"op":90,"st":0,"bm":3},{"ddd":0,"ind":5,"ty":4,"nm":"Gradient with Many Color Stops","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[100,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[120,80]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":15},"nm":"Rectangle"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":5,"k":{"a":0,"k":[0,1,0,0,0.25,1,1,0,0.5,0,1,0,0.75,0,0,1,1,1,0,1,0,1,0.25,1,0.5,1,0.75,1,1,1]}},"s":{"a":0,"k":[-60,0]},"e":{"a":0,"k":[60,0]},"t":1,"nm":"Gradient Fill 5 Stops"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":6,"ty":4,"nm":"Radial Gradient with Mismatched Stops","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[300,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[100,100]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":4,"k":{"a":1,"k":[{"t":0,"s":[0,0.2,0.4,0.8,0.33,0.4,0.6,0.9,0.67,0.8,0.2,0.6,1,1,0.5,0.3,0,1,0.33,0.9,0.67,0.7,1,0.5],"e":[0,1,0.5,0.3,0.33,0.8,0.2,0.6,0.67,0.4,0.6,0.9,1,0.2,0.4,0.8,0,0.5,0.33,0.7,0.67,0.9,1,1]},{"t":30,"s":[0,1,0.5,0.3,0.33,0.8,0.2,0.6,0.67,0.4,0.6,0.9,1,0.2,0.4,0.8,0,0.5,0.33,0.7,0.67,0.9,1,1]}]}},"s":{"a":0,"k":[0,0]},"e":{"a":0,"k":[50,0]},"t":2,"nm":"Radial Gradient Animated"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":7,"ty":4,"nm":"Linear Gradient with 3 Stops","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[200,220,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"sr","d":1,"sy":1,"pt":{"a":0,"k":5},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"or":{"a":0,"k":50},"os":{"a":0,"k":0},"ir":{"a":0,"k":25},"is":{"a":0,"k":0},"nm":"Star"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":3,"k":{"a":0,"k":[0,1,0,0,0.5,1,1,1,1,0,0,1,0,1,0.5,0.8,1,1]}},"s":{"a":1,"k":[{"t":0,"s":[0,-50],"e":[-50,50]},{"t":30,"s":[-50,50],"e":[50,-50]},{"t":60,"s":[50,-50]}]},"e":{"a":1,"k":[{"t":0,"s":[0,50],"e":[50,-50]},{"t":30,"s":[50,-50],"e":[-50,50]},{"t":60,"s":[-50,50]}]},"t":1,"nm":"Animated Linear Gradient"}],"ip":0,"op":60,"st":0,"bm":0},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":8,"nm":"Gradient Layer 1 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.6,23.28],"t":45},{"s":[8.39,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[75.07,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[395.4,214.72],"t":45},{"s":[75.07,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[23.2,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[20.000000298023224],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[20.000000298023224],"t":45},{"s":[20.000000298023224],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":9,"nm":"Gradient Layer 2 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":10,"nm":"Gradient Layer 3 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.6,23.28],"t":45},{"s":[8.39,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[75.07,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[395.4,214.72],"t":45},{"s":[75.07,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[23.2,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":11,"nm":"Gradient Layer 4 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":12,"nm":"Gradient Layer 5 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.28,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.46,23.28],"t":45},{"s":[8.28,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[58.4,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[372.35,214.72],"t":45},{"s":[58.4,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[22.91,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[20.000000298023224],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[20.000000298023224],"t":45},{"s":[20.000000298023224],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":13,"nm":"Gradient Layer 6 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":14,"nm":"Gradient Layer 7 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.28,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.46,23.28],"t":45},{"s":[8.28,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[58.4,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[372.35,214.72],"t":45},{"s":[58.4,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[22.91,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":15,"nm":"Gradient Layer 8 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":16,"nm":"Gradient Layer 9 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.6,23.28],"t":45},{"s":[8.39,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[41.73,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[349.29,214.72],"t":45},{"s":[41.73,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[23.2,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[20.000000298023224],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[20.000000298023224],"t":45},{"s":[20.000000298023224],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":17,"nm":"Gradient Layer 10 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":18,"nm":"Gradient Layer 11 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.6,23.28],"t":45},{"s":[8.39,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[41.73,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[349.29,214.72],"t":45},{"s":[41.73,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[23.2,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":19,"nm":"Gradient Layer 12 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":20,"nm":"Gradient Layer 13 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.28,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.46,23.28],"t":45},{"s":[8.28,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[25.06,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[326.24,214.72],"t":45},{"s":[25.06,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[22.91,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[20.000000298023224],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[20.000000298023224],"t":45},{"s":[20.000000298023224],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":21,"nm":"Gradient Layer 14 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":22,"nm":"Gradient Layer 15 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.28,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.46,23.28],"t":45},{"s":[8.28,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[25.06,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[326.24,214.72],"t":45},{"s":[25.06,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[22.91,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.57,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":23,"nm":"Gradient Layer 16 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":24,"nm":"Gradient Layer 17 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.6,23.28],"t":45},{"s":[8.39,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[303.18,214.72],"t":45},{"s":[8.39,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[23.2,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[20.000000298023224],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[20.000000298023224],"t":45},{"s":[20.000000298023224],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":25,"nm":"Gradient Layer 18 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":26,"nm":"Gradient Layer 19 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,16.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[11.6,23.28],"t":45},{"s":[8.39,16.83],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[8.39,220.83],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[303.18,214.72],"t":45},{"s":[8.39,220.83],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[23.2,23.28],[0,46.56]]}],"t":45},{"s":[{"c":false,"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[0,0],[16.77,16.83],[0,33.66]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":10,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[2],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[2],"t":45},{"s":[2],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]}}],"ind":27,"nm":"Gradient Layer 20 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"td":1,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[132.5,60.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[195.99,65],"t":45},{"s":[132.5,60.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[200.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[210.88,182],"t":45},{"s":[200.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,45.01],[34,0],[0,-45.01],[-47.96,23.5]],"o":[[75.54,-10.5],[-31.92,-33.5],[-45.27,0],[-25.5,65],[0,0]],"v":[[88.07,106.5],[170.03,48.5],[83.11,0],[6.11,48.5],[88.07,106.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[60.5,121],[121,60.5],[60.5,0],[0,60.5],[60.5,121]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[30,87.5],[45.27,0],[-25,-44.5],[-45.27,0]],"o":[[8.96,-46],[68.5,-82],[-45.27,0],[0,45.01],[0,0]],"v":[[283.15,130],[370.11,60],[283.15,4],[220.61,48.5],[283.15,130]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,33.41],[33.41,0],[0,-33.41],[-33.41,0]],"o":[[33.41,0],[0,-33.41],[-33.41,0],[0,33.41],[0,0]],"v":[[204.5,121],[265,60.5],[204.5,0],[144,60.5],[204.5,121]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0,0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0,0],"t":45},{"s":[0,0,0],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":28,"nm":"Gradient Layer 21 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"tt":1,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[240,87.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[240,87.5],"t":45},{"s":[240,87.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[443,171.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[147,171.5],"t":45},{"s":[443,171.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.47,8.4],[-1.28,8.28],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.47,-8.28],[0,-11.32],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,-10.5],[0.58,-8.4],[0,0],[0,0],[0,0],[0,0],[0,0],[1.28,7.82],[0.58,8.17],[0,0],[0,0],[0,0]],"v":[[0,129.5],[0,7],[32.55,7],[77.18,79.63],[50.75,79.45],[95.9,7],[127.4,7],[127.4,129.5],[91,129.5],[91,100.28],[91.7,71.92],[94.5,46.9],[98.7,57.92],[69.13,103.78],[57.58,103.78],[28.53,57.92],[32.9,46.9],[35.53,71.05],[36.4,100.28],[36.4,129.5],[0,129.5]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.47,8.4],[-1.28,8.28],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.47,-8.28],[0,-11.32],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,-10.5],[0.58,-8.4],[0,0],[0,0],[0,0],[0,0],[0,0],[1.28,7.82],[0.58,8.17],[0,0],[0,0],[0,0]],"v":[[0,129.5],[0,7],[32.55,7],[77.18,79.63],[50.75,79.45],[95.9,7],[127.4,7],[127.4,129.5],[91,129.5],[91,100.28],[91.7,71.92],[94.5,46.9],[98.7,57.92],[69.13,103.78],[57.58,103.78],[28.53,57.92],[32.9,46.9],[35.53,71.05],[36.4,100.28],[36.4,129.5],[0,129.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.47,8.4],[-1.28,8.28],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.47,-8.28],[0,-11.32],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,-10.5],[0.58,-8.4],[0,0],[0,0],[0,0],[0,0],[0,0],[1.28,7.82],[0.58,8.17],[0,0],[0,0],[0,0]],"v":[[0,129.5],[0,7],[32.55,7],[77.18,79.63],[50.75,79.45],[95.9,7],[127.4,7],[127.4,129.5],[91,129.5],[91,100.28],[91.7,71.92],[94.5,46.9],[98.7,57.92],[69.13,103.78],[57.58,103.78],[28.53,57.92],[32.9,46.9],[35.53,71.05],[36.4,100.28],[36.4,129.5],[0,129.5]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[6.07,4.08],[3.5,7.23],[0,9.45],[-3.38,7.23],[-6.07,4.08],[-8.05,0],[-3.5,-1.17],[-2.68,-2.1],[-1.98,-2.8],[-1.4,-3.15],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[2.1,-2.92],[2.8,-2.1],[3.5,-1.28],[4.2,0]],"o":[[-7.82,0],[-6.07,-4.2],[-3.5,-7.35],[0,-9.57],[3.5,-7.35],[6.18,-4.2],[4.2,0],[3.5,1.17],[2.68,2.1],[1.98,2.68],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-1.17,3.38],[-1.98,2.92],[-2.8,2.1],[-3.5,1.17],[0,0]],"v":[[187.02,131.07],[166.2,124.95],[151.85,107.8],[146.6,82.6],[151.67,57.4],[166.02,40.25],[187.37,33.95],[198.92,35.7],[208.2,40.6],[215.2,47.95],[220.27,56.7],[213.1,56.52],[213.1,35.87],[247.92,35.87],[247.92,129.5],[212.22,129.5],[212.22,106.57],[220.1,107.28],[215.2,116.72],[208.02,124.25],[198.57,129.32],[187.02,131.07]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[6.07,4.08],[3.5,7.23],[0,9.45],[-3.38,7.23],[-6.07,4.08],[-8.05,0],[-3.5,-1.17],[-2.68,-2.1],[-1.98,-2.8],[-1.4,-3.15],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[2.1,-2.92],[2.8,-2.1],[3.5,-1.28],[4.2,0]],"o":[[-7.82,0],[-6.07,-4.2],[-3.5,-7.35],[0,-9.57],[3.5,-7.35],[6.18,-4.2],[4.2,0],[3.5,1.17],[2.68,2.1],[1.98,2.68],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-1.17,3.38],[-1.98,2.92],[-2.8,2.1],[-3.5,1.17],[0,0]],"v":[[187.02,131.07],[166.2,124.95],[151.85,107.8],[146.6,82.6],[151.67,57.4],[166.02,40.25],[187.37,33.95],[198.92,35.7],[208.2,40.6],[215.2,47.95],[220.27,56.7],[213.1,56.52],[213.1,35.87],[247.92,35.87],[247.92,129.5],[212.22,129.5],[212.22,106.57],[220.1,107.28],[215.2,116.72],[208.02,124.25],[198.57,129.32],[187.02,131.07]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[6.07,4.08],[3.5,7.23],[0,9.45],[-3.38,7.23],[-6.07,4.08],[-8.05,0],[-3.5,-1.17],[-2.68,-2.1],[-1.98,-2.8],[-1.4,-3.15],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[2.1,-2.92],[2.8,-2.1],[3.5,-1.28],[4.2,0]],"o":[[-7.82,0],[-6.07,-4.2],[-3.5,-7.35],[0,-9.57],[3.5,-7.35],[6.18,-4.2],[4.2,0],[3.5,1.17],[2.68,2.1],[1.98,2.68],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-1.17,3.38],[-1.98,2.92],[-2.8,2.1],[-3.5,1.17],[0,0]],"v":[[187.02,131.07],[166.2,124.95],[151.85,107.8],[146.6,82.6],[151.67,57.4],[166.02,40.25],[187.37,33.95],[198.92,35.7],[208.2,40.6],[215.2,47.95],[220.27,56.7],[213.1,56.52],[213.1,35.87],[247.92,35.87],[247.92,129.5],[212.22,129.5],[212.22,106.57],[220.1,107.28],[215.2,116.72],[208.02,124.25],[198.57,129.32],[187.02,131.07]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[-2.33,1.52],[-1.17,2.92],[0,4.2],[1.28,2.92],[2.45,1.52],[3.38,0],[2.33,-1.52],[1.28,-3.03],[0,-4.2],[-1.17,-2.92],[-2.33,-1.52],[-3.38,0]],"o":[[3.38,0],[2.45,-1.52],[1.28,-2.92],[0,-4.2],[-1.17,-3.03],[-2.33,-1.52],[-3.38,0],[-2.33,1.52],[-1.17,2.92],[0,4.2],[1.28,2.92],[2.33,1.52],[0,0]],"v":[[197.17,102.2],[205.75,99.92],[211.17,93.28],[213.1,82.6],[211.17,71.92],[205.75,65.1],[197.17,62.83],[188.6,65.1],[183.17,71.92],[181.42,82.6],[183.17,93.28],[188.6,99.92],[197.17,102.2]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[-2.33,1.52],[-1.17,2.92],[0,4.2],[1.28,2.92],[2.45,1.52],[3.38,0],[2.33,-1.52],[1.28,-3.03],[0,-4.2],[-1.17,-2.92],[-2.33,-1.52],[-3.38,0]],"o":[[3.38,0],[2.45,-1.52],[1.28,-2.92],[0,-4.2],[-1.17,-3.03],[-2.33,-1.52],[-3.38,0],[-2.33,1.52],[-1.17,2.92],[0,4.2],[1.28,2.92],[2.33,1.52],[0,0]],"v":[[197.17,102.2],[205.75,99.92],[211.17,93.28],[213.1,82.6],[211.17,71.92],[205.75,65.1],[197.17,62.83],[188.6,65.1],[183.17,71.92],[181.42,82.6],[183.17,93.28],[188.6,99.92],[197.17,102.2]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[-2.33,1.52],[-1.17,2.92],[0,4.2],[1.28,2.92],[2.45,1.52],[3.38,0],[2.33,-1.52],[1.28,-3.03],[0,-4.2],[-1.17,-2.92],[-2.33,-1.52],[-3.38,0]],"o":[[3.38,0],[2.45,-1.52],[1.28,-2.92],[0,-4.2],[-1.17,-3.03],[-2.33,-1.52],[-3.38,0],[-2.33,1.52],[-1.17,2.92],[0,4.2],[1.28,2.92],[2.33,1.52],[0,0]],"v":[[197.17,102.2],[205.75,99.92],[211.17,93.28],[213.1,82.6],[211.17,71.92],[205.75,65.1],[197.17,62.83],[188.6,65.1],[183.17,71.92],[181.42,82.6],[183.17,93.28],[188.6,99.92],[197.17,102.2]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[7.58,3.03],[4.2,4.67],[0,0],[-4.78,-1.63],[-3.27,0],[-0.82,0.12],[-0.47,0.35],[-0.23,0.47],[0,0.7],[1.87,0.82],[2.45,0.7],[3.85,0.93],[3.85,1.75],[2.68,2.33],[1.63,3.27],[0,4.08],[-2.22,3.73],[-3.85,2.57],[-4.78,1.4],[-5.02,0],[-4.9,-1.17],[-4.32,-2.1],[-3.62,-2.8],[0,0],[2.68,1.52],[2.92,0.93],[2.45,0],[0.93,-0.23],[0.58,-0.47],[0.35,-0.58],[0,-0.7],[-0.58,-0.82],[-1.28,-0.58],[-2.45,-0.82],[-4.9,-1.4],[-3.97,-1.98],[-2.45,-2.68],[-0.93,-2.33],[0,-2.68],[3.73,-5.02],[6.42,-2.92],[8.28,0]],"o":[[-10.15,0],[-7.47,-3.15],[0,0],[3.73,3.27],[4.9,1.52],[1.17,0],[0.93,-0.23],[0.58,-0.47],[0.35,-0.47],[0,-1.75],[-1.05,-0.47],[-2.33,-0.7],[-4.55,-1.17],[-3.73,-1.75],[-2.8,-2.57],[-1.52,-3.27],[0,-4.78],[2.22,-3.73],[3.85,-2.68],[4.78,-1.4],[5.72,0],[5.02,1.05],[4.43,1.98],[0,0],[-1.98,-1.63],[-2.57,-1.52],[-2.8,-1.05],[-1.28,0],[-0.82,0.12],[-0.58,0.35],[-0.23,0.47],[0,0.93],[0.58,0.82],[1.05,0.47],[2.57,0.82],[5.25,1.52],[4.08,1.98],[1.63,1.87],[0.93,2.33],[0,6.42],[-3.62,4.9],[-6.42,2.8],[0,0]],"v":[[304.4,131.25],[277.8,126.7],[260.3,114.97],[280.95,97.3],[293.72,104.65],[305.97,106.93],[308.95,106.75],[311.05,105.88],[312.27,104.47],[312.8,102.72],[310,98.88],[304.75,97.13],[295.47,94.67],[282.87,90.3],[273.25,84.18],[266.6,75.42],[264.32,64.4],[267.65,51.62],[276.75,42.17],[289.7,36.05],[304.4,33.95],[320.32,35.7],[334.32,40.42],[346.4,47.6],[328.37,67.72],[321.37,63],[313.15,59.32],[305.27,57.75],[301.95,58.1],[299.85,58.97],[298.45,60.38],[298.1,62.13],[298.97,64.75],[301.77,66.85],[307.02,68.78],[318.22,72.1],[332.05,77.35],[341.85,84.35],[345.7,90.65],[347.1,98.18],[341.5,115.33],[326.45,127.05],[304.4,131.25]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[7.58,3.03],[4.2,4.67],[0,0],[-4.78,-1.63],[-3.27,0],[-0.82,0.12],[-0.47,0.35],[-0.23,0.47],[0,0.7],[1.87,0.82],[2.45,0.7],[3.85,0.93],[3.85,1.75],[2.68,2.33],[1.63,3.27],[0,4.08],[-2.22,3.73],[-3.85,2.57],[-4.78,1.4],[-5.02,0],[-4.9,-1.17],[-4.32,-2.1],[-3.62,-2.8],[0,0],[2.68,1.52],[2.92,0.93],[2.45,0],[0.93,-0.23],[0.58,-0.47],[0.35,-0.58],[0,-0.7],[-0.58,-0.82],[-1.28,-0.58],[-2.45,-0.82],[-4.9,-1.4],[-3.97,-1.98],[-2.45,-2.68],[-0.93,-2.33],[0,-2.68],[3.73,-5.02],[6.42,-2.92],[8.28,0]],"o":[[-10.15,0],[-7.47,-3.15],[0,0],[3.73,3.27],[4.9,1.52],[1.17,0],[0.93,-0.23],[0.58,-0.47],[0.35,-0.47],[0,-1.75],[-1.05,-0.47],[-2.33,-0.7],[-4.55,-1.17],[-3.73,-1.75],[-2.8,-2.57],[-1.52,-3.27],[0,-4.78],[2.22,-3.73],[3.85,-2.68],[4.78,-1.4],[5.72,0],[5.02,1.05],[4.43,1.98],[0,0],[-1.98,-1.63],[-2.57,-1.52],[-2.8,-1.05],[-1.28,0],[-0.82,0.12],[-0.58,0.35],[-0.23,0.47],[0,0.93],[0.58,0.82],[1.05,0.47],[2.57,0.82],[5.25,1.52],[4.08,1.98],[1.63,1.87],[0.93,2.33],[0,6.42],[-3.62,4.9],[-6.42,2.8],[0,0]],"v":[[304.4,131.25],[277.8,126.7],[260.3,114.97],[280.95,97.3],[293.72,104.65],[305.97,106.93],[308.95,106.75],[311.05,105.88],[312.27,104.47],[312.8,102.72],[310,98.88],[304.75,97.13],[295.47,94.67],[282.87,90.3],[273.25,84.18],[266.6,75.42],[264.32,64.4],[267.65,51.62],[276.75,42.17],[289.7,36.05],[304.4,33.95],[320.32,35.7],[334.32,40.42],[346.4,47.6],[328.37,67.72],[321.37,63],[313.15,59.32],[305.27,57.75],[301.95,58.1],[299.85,58.97],[298.45,60.38],[298.1,62.13],[298.97,64.75],[301.77,66.85],[307.02,68.78],[318.22,72.1],[332.05,77.35],[341.85,84.35],[345.7,90.65],[347.1,98.18],[341.5,115.33],[326.45,127.05],[304.4,131.25]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[7.58,3.03],[4.2,4.67],[0,0],[-4.78,-1.63],[-3.27,0],[-0.82,0.12],[-0.47,0.35],[-0.23,0.47],[0,0.7],[1.87,0.82],[2.45,0.7],[3.85,0.93],[3.85,1.75],[2.68,2.33],[1.63,3.27],[0,4.08],[-2.22,3.73],[-3.85,2.57],[-4.78,1.4],[-5.02,0],[-4.9,-1.17],[-4.32,-2.1],[-3.62,-2.8],[0,0],[2.68,1.52],[2.92,0.93],[2.45,0],[0.93,-0.23],[0.58,-0.47],[0.35,-0.58],[0,-0.7],[-0.58,-0.82],[-1.28,-0.58],[-2.45,-0.82],[-4.9,-1.4],[-3.97,-1.98],[-2.45,-2.68],[-0.93,-2.33],[0,-2.68],[3.73,-5.02],[6.42,-2.92],[8.28,0]],"o":[[-10.15,0],[-7.47,-3.15],[0,0],[3.73,3.27],[4.9,1.52],[1.17,0],[0.93,-0.23],[0.58,-0.47],[0.35,-0.47],[0,-1.75],[-1.05,-0.47],[-2.33,-0.7],[-4.55,-1.17],[-3.73,-1.75],[-2.8,-2.57],[-1.52,-3.27],[0,-4.78],[2.22,-3.73],[3.85,-2.68],[4.78,-1.4],[5.72,0],[5.02,1.05],[4.43,1.98],[0,0],[-1.98,-1.63],[-2.57,-1.52],[-2.8,-1.05],[-1.28,0],[-0.82,0.12],[-0.58,0.35],[-0.23,0.47],[0,0.93],[0.58,0.82],[1.05,0.47],[2.57,0.82],[5.25,1.52],[4.08,1.98],[1.63,1.87],[0.93,2.33],[0,6.42],[-3.62,4.9],[-6.42,2.8],[0,0]],"v":[[304.4,131.25],[277.8,126.7],[260.3,114.97],[280.95,97.3],[293.72,104.65],[305.97,106.93],[308.95,106.75],[311.05,105.88],[312.27,104.47],[312.8,102.72],[310,98.88],[304.75,97.13],[295.47,94.67],[282.87,90.3],[273.25,84.18],[266.6,75.42],[264.32,64.4],[267.65,51.62],[276.75,42.17],[289.7,36.05],[304.4,33.95],[320.32,35.7],[334.32,40.42],[346.4,47.6],[328.37,67.72],[321.37,63],[313.15,59.32],[305.27,57.75],[301.95,58.1],[299.85,58.97],[298.45,60.38],[298.1,62.13],[298.97,64.75],[301.77,66.85],[307.02,68.78],[318.22,72.1],[332.05,77.35],[341.85,84.35],[345.7,90.65],[347.1,98.18],[341.5,115.33],[326.45,127.05],[304.4,131.25]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[395.89,103.25],[378.39,81.2],[421.62,35.87],[467.82,35.87],[395.89,103.25]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[395.89,103.25],[378.39,81.2],[421.62,35.87],[467.82,35.87],[395.89,103.25]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[395.89,103.25],[378.39,81.2],[421.62,35.87],[467.82,35.87],[395.89,103.25]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[361.07,129.5],[361.07,0],[396.59,0],[396.59,129.5],[361.07,129.5]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[361.07,129.5],[361.07,0],[396.59,0],[396.59,129.5],[361.07,129.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[361.07,129.5],[361.07,0],[396.59,0],[396.59,129.5],[361.07,129.5]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[424.77,129.5],[393.62,85.57],[418.47,67.72],[465.37,129.5],[424.77,129.5]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[424.77,129.5],[393.62,85.57],[418.47,67.72],[465.37,129.5],[424.77,129.5]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[424.77,129.5],[393.62,85.57],[418.47,67.72],[465.37,129.5],[424.77,129.5]]}],"t":66}]}},{"ty":"gf","e":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[226,152],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[226,152],"t":45},{"s":[226,152],"t":66}]},"g":{"p":2,"k":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0,0.9799999594688416,0,1,1,0,1,0.3999999761581421],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0,0.9799999594688416,0,1,1,1,0.6000000238418579,0],"t":45},{"s":[0,0.9799999594688416,0,1,1,0,1,0.3999999761581421],"t":66}]}},"t":1,"a":{"a":0,"k":0},"h":{"a":0,"k":0},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[226,-23],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[226,-23],"t":45},{"s":[226,-23],"t":66}]},"r":1,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":29,"nm":"Gradient Layer 22 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[15.5,16],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[12.5,13],"t":45},{"s":[15.5,16],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[264.5,215],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[254,225.5],"t":45},{"s":[264.5,215],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[-90],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[-0.8,-2.03],[-1.23,1.26],[-2.51,-2.58],[3.22,-3.31],[2.22,-0.81],[-1.38,-1.42],[2.51,-2.58],[3.22,3.31],[0.79,2.35],[1.41,-1.45],[2.51,2.58],[-2.89,2.97],[-2.07,0.83],[1.22,1.26],[-2.51,2.58],[-2.89,-2.97]],"o":[[1.15,1.18],[0.81,-2.18],[2.89,-2.97],[2.51,2.58],[-1.44,1.48],[2.41,0.83],[2.89,2.97],[-2.51,2.58],[-1.48,-1.52],[-0.79,2.23],[-3.22,3.31],[-2.51,-2.58],[1.2,-1.24],[-1.86,-0.81],[-3.22,-3.31],[2.51,-2.58],[0,0]],"v":[[12.39,2.23],[15.45,7.32],[18.66,1.83],[28.33,2.41],[28.88,12.33],[23.06,15.92],[29.21,19.52],[28.66,29.45],[19,30.02],[15.44,23.84],[12,29.68],[2.34,29.11],[1.79,19.18],[7.01,15.92],[2.17,12.73],[2.73,2.8],[12.39,2.23]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[-0.65,-1.65],[-0.99,1.02],[-2.03,-2.1],[2.6,-2.69],[1.79,-0.66],[-1.11,-1.15],[2.03,-2.1],[2.6,2.69],[0.64,1.91],[1.14,-1.18],[2.03,2.1],[-2.33,2.41],[-1.67,0.68],[0.99,1.02],[-2.03,2.1],[-2.33,-2.41]],"o":[[0.93,0.96],[0.66,-1.77],[2.33,-2.41],[2.03,2.1],[-1.16,1.2],[1.94,0.67],[2.33,2.41],[-2.03,2.1],[-1.19,-1.24],[-0.64,1.81],[-2.6,2.69],[-2.03,-2.1],[0.97,-1],[-1.5,-0.66],[-2.6,-2.69],[2.03,-2.1],[0,0]],"v":[[9.99,1.82],[12.46,5.95],[15.05,1.49],[22.84,1.95],[23.29,10.02],[18.6,12.93],[23.56,15.86],[23.11,23.93],[15.32,24.39],[12.45,19.37],[9.68,24.11],[1.89,23.65],[1.44,15.58],[5.65,12.94],[1.75,10.35],[2.2,2.28],[9.99,1.82]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[-0.8,-2.03],[-1.23,1.26],[-2.51,-2.58],[3.22,-3.31],[2.22,-0.81],[-1.38,-1.42],[2.51,-2.58],[3.22,3.31],[0.79,2.35],[1.41,-1.45],[2.51,2.58],[-2.89,2.97],[-2.07,0.83],[1.22,1.26],[-2.51,2.58],[-2.89,-2.97]],"o":[[1.15,1.18],[0.81,-2.18],[2.89,-2.97],[2.51,2.58],[-1.44,1.48],[2.41,0.83],[2.89,2.97],[-2.51,2.58],[-1.48,-1.52],[-0.79,2.23],[-3.22,3.31],[-2.51,-2.58],[1.2,-1.24],[-1.86,-0.81],[-3.22,-3.31],[2.51,-2.58],[0,0]],"v":[[12.39,2.23],[15.45,7.32],[18.66,1.83],[28.33,2.41],[28.88,12.33],[23.06,15.92],[29.21,19.52],[28.66,29.45],[19,30.02],[15.44,23.84],[12,29.68],[2.34,29.11],[1.79,19.18],[7.01,15.92],[2.17,12.73],[2.73,2.8],[12.39,2.23]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[2.51,2.41],[2.34,-2.58],[-2.51,-2.41],[-2.34,2.58]],"o":[[-2.48,2.44],[2.38,2.55],[2.48,-2.44],[-2.38,-2.55],[0,0]],"v":[[19.98,11.44],[11.09,11.51],[11.15,20.64],[20.05,20.58],[19.98,11.44]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[2.02,1.96],[1.89,-2.1],[-2.02,-1.96],[-1.89,2.1]],"o":[[-2,1.98],[1.92,2.07],[2,-1.98],[-1.92,-2.07],[0,0]],"v":[[16.12,9.3],[8.95,9.35],[9,16.77],[16.17,16.72],[16.12,9.3]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[2.51,2.41],[2.34,-2.58],[-2.51,-2.41],[-2.34,2.58]],"o":[[-2.48,2.44],[2.38,2.55],[2.48,-2.44],[-2.38,-2.55],[0,0]],"v":[[19.98,11.44],[11.09,11.51],[11.15,20.64],[20.05,20.58],[19.98,11.44]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[1,1,1],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[1,1,1],"t":45},{"s":[1,1,1],"t":66}]},"r":2,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":30,"nm":"Gradient Layer 23 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[28,28.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[26,27],"t":45},{"s":[28,28.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[140,87.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[121,90],"t":45},{"s":[140,87.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[-180],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[-1.45,-3.61],[-2.21,2.24],[-4.54,-4.6],[5.82,-5.89],[4,-1.45],[-2.5,-2.53],[4.54,-4.6],[5.82,5.89],[1.42,4.18],[2.55,-2.58],[4.54,4.6],[-5.22,5.28],[-3.75,1.48],[2.21,2.24],[-4.54,4.6],[-5.22,-5.28]],"o":[[2.08,2.11],[1.47,-3.88],[5.22,-5.28],[4.54,4.6],[-2.6,2.63],[4.35,1.48],[5.22,5.28],[-4.54,4.6],[-2.68,-2.71],[-1.44,3.97],[-5.82,5.89],[-4.54,-4.6],[2.17,-2.2],[-3.36,-1.44],[-5.82,-5.89],[4.54,-4.6],[0,0]],"v":[[22.38,3.98],[27.91,13.04],[33.72,3.27],[51.17,4.28],[52.17,21.97],[41.66,28.36],[52.77,34.77],[51.77,52.46],[34.32,53.48],[27.89,42.47],[21.68,52.87],[4.23,51.85],[3.23,34.17],[12.66,28.36],[3.93,22.68],[4.93,5],[22.38,3.98]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[-1.35,-3.42],[-2.06,2.13],[-4.22,-4.36],[5.4,-5.58],[3.72,-1.37],[-2.32,-2.4],[4.22,-4.36],[5.4,5.58],[1.32,3.96],[2.36,-2.44],[4.22,4.36],[-4.84,5.01],[-3.48,1.41],[2.05,2.12],[-4.22,4.36],[-4.84,-5.01]],"o":[[1.93,1.99],[1.36,-3.67],[4.84,-5.01],[4.22,4.36],[-2.41,2.5],[4.04,1.4],[4.84,5.01],[-4.22,4.36],[-2.48,-2.57],[-1.33,3.76],[-5.4,5.58],[-4.22,-4.36],[2.02,-2.09],[-3.12,-1.36],[-5.4,-5.58],[4.22,-4.36],[0,0]],"v":[[20.78,3.77],[25.92,12.35],[31.31,3.1],[47.51,4.06],[48.45,20.81],[38.68,26.86],[49,32.94],[48.07,49.7],[31.87,50.66],[25.9,40.24],[20.13,50.08],[3.93,49.12],[3,32.37],[11.76,26.87],[3.65,21.49],[4.58,4.73],[20.78,3.77]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[-1.45,-3.61],[-2.21,2.24],[-4.54,-4.6],[5.82,-5.89],[4,-1.45],[-2.5,-2.53],[4.54,-4.6],[5.82,5.89],[1.42,4.18],[2.55,-2.58],[4.54,4.6],[-5.22,5.28],[-3.75,1.48],[2.21,2.24],[-4.54,4.6],[-5.22,-5.28]],"o":[[2.08,2.11],[1.47,-3.88],[5.22,-5.28],[4.54,4.6],[-2.6,2.63],[4.35,1.48],[5.22,5.28],[-4.54,4.6],[-2.68,-2.71],[-1.44,3.97],[-5.82,5.89],[-4.54,-4.6],[2.17,-2.2],[-3.36,-1.44],[-5.82,-5.89],[4.54,-4.6],[0,0]],"v":[[22.38,3.98],[27.91,13.04],[33.72,3.27],[51.17,4.28],[52.17,21.97],[41.66,28.36],[52.77,34.77],[51.77,52.46],[34.32,53.48],[27.89,42.47],[21.68,52.87],[4.23,51.85],[3.23,34.17],[12.66,28.36],[3.93,22.68],[4.93,5],[22.38,3.98]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[4.53,4.29],[4.23,-4.6],[-4.53,-4.29],[-4.23,4.6]],"o":[[-4.48,4.35],[4.29,4.54],[4.48,-4.35],[-4.29,-4.53],[0,0]],"v":[[36.1,20.38],[20.04,20.49],[20.15,36.77],[36.21,36.66],[36.1,20.38]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[4.21,4.06],[3.93,-4.35],[-4.21,-4.06],[-3.93,4.35]],"o":[[-4.16,4.12],[3.99,4.3],[4.16,-4.12],[-3.99,-4.3],[0,0]],"v":[[33.52,19.31],[18.61,19.42],[18.71,34.83],[33.62,34.73],[33.52,19.31]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[4.53,4.29],[4.23,-4.6],[-4.53,-4.29],[-4.23,4.6]],"o":[[-4.48,4.35],[4.29,4.54],[4.48,-4.35],[-4.29,-4.53],[0,0]],"v":[[36.1,20.38],[20.04,20.49],[20.15,36.77],[36.21,36.66],[36.1,20.38]]}],"t":66}]}},{"ty":"fl","c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[1,1,1],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[1,1,1],"t":45},{"s":[1,1,1],"t":66}]},"r":2,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}}],"ind":31,"nm":"Gradient Layer 24 from test29"},{"ty":4,"sr":1,"st":0,"op":67,"ip":0,"hasMask":false,"ao":0,"ks":{"a":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[153.5,70.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[214,71],"t":45},{"s":[153.5,70.5],"t":66}]},"s":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100,100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100,100],"t":45},{"s":[100,100],"t":66}]},"p":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[199.5,149.5],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[211,182],"t":45},{"s":[199.5,149.5],"t":66}]},"r":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[0],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[0],"t":45},{"s":[0],"t":66}]},"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]}},"shapes":[{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,38.94],[38.71,0],[0,-38.94],[-38.71,0]],"o":[[38.71,0],[0,-38.94],[-38.71,0],[0,38.94],[0,0]],"v":[[70.09,141],[140.18,70.5],[70.09,0],[0,70.5],[70.09,141]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[0,49.17],[37.12,0],[0,-49.17],[-52.37,25.67]],"o":[[82.48,-11.47],[-34.85,-36.59],[-49.42,0],[-27.84,71],[0,0]],"v":[[96.17,116.33],[185.66,52.98],[90.75,0],[6.68,52.98],[96.17,116.33]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,38.94],[38.71,0],[0,-38.94],[-38.71,0]],"o":[[38.71,0],[0,-38.94],[-38.71,0],[0,38.94],[0,0]],"v":[[70.09,141],[140.18,70.5],[70.09,0],[0,70.5],[70.09,141]]}],"t":66}]}},{"ty":"sh","d":1,"ks":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[{"c":true,"i":[[0,0],[0,38.94],[38.71,0],[0,-38.94],[-38.71,0]],"o":[[38.71,0],[0,-38.94],[-38.71,0],[0,38.94],[0,0]],"v":[[236.91,141],[307,70.5],[236.91,0],[166.82,70.5],[236.91,141]]}],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[{"c":true,"i":[[0,0],[32.76,95.58],[49.42,0],[-27.3,-48.61],[-49.42,0]],"o":[[9.78,-50.25],[74.79,-89.57],[-49.42,0],[0,49.17],[0,0]],"v":[[309.17,142],[404.12,65.54],[309.17,4.37],[240.88,52.98],[309.17,142]]}],"t":45},{"s":[{"c":true,"i":[[0,0],[0,38.94],[38.71,0],[0,-38.94],[-38.71,0]],"o":[[38.71,0],[0,-38.94],[-38.71,0],[0,38.94],[0,0]],"v":[[236.91,141],[307,70.5],[236.91,0],[166.82,70.5],[236.91,141]]}],"t":66}]}},{"ty":"st","lc":1,"lj":1,"ml":4,"o":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[100],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[100],"t":45},{"s":[100],"t":66}]},"w":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[1],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[1],"t":45},{"s":[1],"t":66}]},"c":{"a":1,"k":[{"o":{"x":0,"y":0},"i":{"x":1,"y":1},"s":[1,1,1],"t":0},{"o":{"x":0.645,"y":0.045},"i":{"x":0.355,"y":1},"s":[1,1,1],"t":45},{"s":[1,1,1],"t":66}]}}],"ind":32,"nm":"Gradient Layer 25 from test29"},{"ty":4,"shapes":[{"ty":"rc","s":{"a":0,"k":[300,200]},"p":{"a":0,"k":[200,200]}},{"ty":"gf","o":{"a":0,"k":100},"g":{"p":3,"k":{"a":0,"k":[0,1,0,0,0.5,0,1,0,1,0,0,1,0,1,0.25,0.8,0.5,0.6,0.75,0.4,1,0.2]}},"s":{"a":0,"k":[0,200]},"e":{"a":0,"k":[300,200]},"t":1}],"ip":0,"op":60,"ind":33,"nm":"Gradient Layer from test34"}],"meta":{"g":"LottieFiles Figma v37"},"markers":[]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test8.lot b/components/thorvg-main/test/resources/test8.lot new file mode 100644 index 0000000..d1838d4 --- /dev/null +++ b/components/thorvg-main/test/resources/test8.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":60,"ip":0,"op":180,"w":512,"h":512,"nm":"84_Text_Range selector (Shape)","assets":[],"fonts":{"list":[{"fName":"AvertaStd-Black","fFamily":"AvertaStd-Black","fStyle":"?","ascent":73.599}]},"layers":[{"ind":1,"ty":5,"nm":"Range selector (Shape) Triangle","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[256,234.319,0],"l":2},"a":{"a":0,"k":[-0.028,14.749,0],"l":2},"s":{"a":0,"k":[362.31,362.31,100],"l":2}},"ao":0,"t":{"d":{"k":[{"s":{"s":19,"f":"AvertaStd-Black","t":"Range\rselector\r(Shape)\rTriangle","j":2,"tr":0,"lh":20,"ls":0,"fc":[0.286,0.796,0.804]},"t":0}]},"p":{},"m":{"g":1,"a":{"a":0,"k":[0,0]}},"a":[{"nm":"Animator 1","s":{"t":0,"xe":{"a":0,"k":0},"ne":{"a":0,"k":0},"a":{"a":0,"k":100},"b":1,"rn":0,"sh":4,"e":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":90,"s":[100]},{"t":179,"s":[0]}]},"r":1},"a":{"s":{"a":0,"k":[40,40,100]}}}]},"ip":0,"op":180,"st":0},{"ind":2,"ty":5,"nm":"text","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[9.982,27.699,0],"l":2},"a":{"a":0,"k":[0.232,-7.801,0],"l":2},"s":{"a":0,"k":[100,100,100],"l":2}},"ao":0,"t":{"d":{"k":[{"s":{"s":29,"f":"AvertaStd-Black","t":"84_Text_Range selector (Shape)","j":0,"tr":0,"lh":34.8,"ls":0,"fc":[1,1,1]},"t":0}]},"p":{},"m":{"g":1,"a":{"a":0,"k":[0,0]}},"a":[]},"ip":0,"op":180,"st":0},{"ind":3,"ty":4,"nm":"Container","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[256,256,0],"l":2},"a":{"a":0,"k":[0,0,0],"l":2},"s":{"a":0,"k":[100,100,100],"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[256,-25.5],[256,25.5],[-256,25.5],[-256,-25.5]],"c":true}},"nm":"Path 1"},{"ty":"fl","c":{"a":0,"k":[0.286,0.796,0.804,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill 1"},{"ty":"tr","p":{"a":0,"k":[0,-230.375]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Transform"}],"nm":"Rectangle 2"},{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[256,-256],[256,256],[-256,256],[-256,-256]],"c":true}},"nm":"Path 1"},{"ty":"st","c":{"a":0,"k":[0.286,0.796,0.804,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":7},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Transform"}],"nm":"Rectangle 1"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"Transform"}],"nm":"Group 1"}],"ip":0,"op":180,"st":0}],"markers":[{"tm":45,"cm":"2","dr":0},{"tm":90,"cm":"1","dr":0},{"tm":135,"cm":"3","dr":0}],"chars":[{"ch":"8","size":29,"style":"?","w":55.4,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[-1.567,2.567],[0,3.134],[4.1,3.2],[6.266,0],[4.033,-3.166],[0,-5.933],[-1.6,-2.566],[-2.334,-1],[0,0],[2.266,-3.133],[0,-4.466],[-4.834,-3.633],[-7.334,0],[-4.867,3.6],[0,6.134],[2.233,3.134],[3.666,1.334]],"o":[[2.333,-1.066],[1.566,-2.566],[0,-5.866],[-4.1,-3.2],[-6.334,0],[-4.034,3.167],[0,3.2],[1.6,2.567],[0,0],[-3.6,1.4],[-2.267,3.134],[0,6.067],[4.833,3.634],[7.4,0],[4.866,-3.6],[0,-4.533],[-2.234,-3.133],[0,0]],"v":[[41.1,-37.3],[46.95,-42.75],[49.3,-51.3],[43.15,-64.9],[27.6,-69.7],[12.05,-64.95],[6,-51.3],[8.4,-42.65],[14.3,-37.3],[14.3,-37.2],[5.5,-30.4],[2.1,-19],[9.35,-4.45],[27.6,1],[46,-4.4],[53.3,-19],[49.95,-30.5],[41.1,-37.2]],"c":true}},"nm":"8"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[-1,-1.166],[0,-1.666],[1.033,-1.1],[1.466,0],[1,1.1],[0,1.6],[-1,1.167],[-1.467,0]],"o":[[1,1.167],[0,1.6],[-1.034,1.1],[-1.467,0],[-1,-1.1],[0,-1.666],[1,-1.166],[1.533,0]],"v":[[31.4,-53.85],[32.9,-49.6],[31.35,-45.55],[27.6,-43.9],[23.9,-45.55],[22.4,-49.6],[23.9,-53.85],[27.6,-55.6]],"c":true}},"nm":"8"},{"ind":2,"ty":"sh","ks":{"a":0,"k":{"i":[[1.366,1.5],[0,2.134],[-1.334,1.4],[-2,0],[-1.334,-1.4],[0,-2.133],[1.333,-1.5],[2,0]],"o":[[-1.367,-1.5],[0,-2.133],[1.333,-1.4],[2,0],[1.333,1.4],[0,2.134],[-1.334,1.5],[-1.934,0]],"v":[[22.65,-16.15],[20.6,-21.6],[22.6,-26.9],[27.6,-29],[32.6,-26.9],[34.6,-21.6],[32.6,-16.15],[27.6,-13.9]],"c":true}},"nm":"8"}],"nm":"8"}]},"fFamily":"AvertaStd-Black"},{"ch":"4","size":29,"style":"?","w":55.7,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[45.2,0],[45.2,-10.4],[53.7,-10.4],[53.7,-25.4],[45.2,-25.4],[45.2,-68.7],[31.1,-68.7],[0.7,-21],[0.7,-10.4],[27.3,-10.4],[27.3,0]],"c":true}},"nm":"4"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[29.3,-40.755],[29.3,-24],[18.739,-24]],"c":true}},"nm":"4"}],"nm":"4"}]},"fFamily":"AvertaStd-Black"},{"ch":"_","size":29,"style":"?","w":52.6,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[53.5,14.4],[53.5,2.7],[-0.9,2.7],[-0.9,14.4]],"c":true}},"nm":"_"}],"nm":"_"}]},"fFamily":"AvertaStd-Black"},{"ch":"T","size":29,"style":"?","w":58.4,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[38.7,0],[38.7,-54.1],[56.7,-54.1],[56.7,-71],[1.8,-71],[1.8,-54.1],[19.8,-54.1],[19.8,0]],"c":true}},"nm":"T"}],"nm":"T"}]},"fFamily":"AvertaStd-Black"},{"ch":"e","size":29,"style":"?","w":54.5,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[4.666,4.7],[7.066,0],[4.766,-4.8],[0,-7.4],[-4.867,-4.766],[-7.4,0],[-3.867,1.733],[-2.267,2.734],[0,0],[4.066,0],[1.833,1.2],[0.4,2.267],[0,0],[0,1.6]],"o":[[-4.667,-4.7],[-7.4,0],[-4.767,4.8],[0,7.467],[4.866,4.767],[4.933,0],[3.866,-1.733],[0,0],[-3.467,3.6],[-2.667,0],[-1.834,-1.2],[0,0],[0.266,-1.6],[0,-7.333]],"v":[[45.3,-42.95],[27.7,-50],[9.45,-42.8],[2.3,-24.5],[9.6,-6.15],[28,1],[41.2,-1.6],[50.4,-8.3],[41.2,-18.5],[29.9,-13.1],[23.15,-14.9],[19.8,-20.1],[51.9,-20.1],[52.3,-24.9]],"c":true}},"nm":"e"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[-0.867,-4.4],[0,0],[-1.4,1.167],[-2,0]],"o":[[0,0],[0.4,-2.066],[1.4,-1.166],[4.066,0]],"v":[[35,-29.8],[19.8,-29.8],[22.5,-34.65],[27.6,-36.4]],"c":true}},"nm":"e"}],"nm":"e"}]},"fFamily":"AvertaStd-Black"},{"ch":"x","size":29,"style":"?","w":52.4,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[52.1,0],[36,-25.3],[51.8,-49],[32,-49],[26.2,-38.5],[26.1,-38.5],[20.4,-49],[0.5,-49],[16.3,-25.4],[0.2,0],[19.1,0],[26.1,-10.6],[26.3,-10.6],[33.1,0]],"c":true}},"nm":"x"}],"nm":"x"}]},"fFamily":"AvertaStd-Black"},{"ch":"t","size":29,"style":"?","w":39.1,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[-4.2,2.4],[0,0],[1.2,0],[0,3.267],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-2.7,-2.766],[-4.4,0]],"o":[[0,0],[-1.2,0.467],[-2.134,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,5.4],[2.7,2.767],[5.4,0]],"v":[[35.4,-2.6],[31,-15],[27.4,-14.3],[24.2,-19.2],[24.2,-34.8],[34.8,-34.8],[34.8,-49],[24.2,-49],[24.2,-66.2],[6.3,-64.4],[6.3,-49],[1,-49],[1,-34.8],[6.3,-34.8],[6.3,-15.4],[10.35,-3.15],[21,1]],"c":true}},"nm":"t"}],"nm":"t"}]},"fFamily":"AvertaStd-Black"},{"ch":"R","size":29,"style":"?","w":64.1,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,10.267],[4.333,4.567],[8.6,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[8.066,-3.8],[0,-7.666],[-4.334,-4.566],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[47.5,-24.6],[47.5,-24.7],[59.6,-45.8],[53.1,-64.15],[33.7,-71],[5.3,-71],[5.3,0],[23.7,0],[23.7,-21.7],[28.1,-21.7],[41.5,0],[63.6,0]],"c":true}},"nm":"R"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[-1.8,-1.533],[0,-2.333],[1.933,-1.4],[3.066,0],[0,0],[0,0]],"o":[[3.333,0],[1.8,1.534],[0,2.6],[-1.934,1.4],[0,0],[0,0],[0,0]],"v":[[29.5,-54.3],[37.2,-52],[39.9,-46.2],[37,-40.2],[29.5,-38.1],[23.7,-38.1],[23.7,-54.3]],"c":true}},"nm":"R"}],"nm":"R"}]},"fFamily":"AvertaStd-Black"},{"ch":"a","size":29,"style":"?","w":58.8,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[5.133,0],[4.133,-4.766],[0,-7.466],[-4.234,-4.733],[-6.734,0],[-2.867,3.734],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[-3.4,-3.933],[-6.2,0],[-4.134,4.767],[0,7.534],[4.233,4.734],[5.533,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[36.7,-44.1],[36.6,-44.1],[23.8,-50],[8.3,-42.85],[2.1,-24.5],[8.45,-6.1],[24.9,1],[37.5,-4.6],[37.6,-4.6],[37.6,0],[54.6,0],[54.6,-49],[36.7,-49]],"c":true}},"nm":"a"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[1.6,1.8],[0,3],[-1.634,1.834],[-2.534,0],[-1.667,-1.833],[0,-2.866],[1.666,-1.833],[2.4,0]],"o":[[-1.6,-1.8],[0,-2.866],[1.633,-1.833],[2.4,0],[1.666,1.834],[0,2.934],[-1.667,1.834],[-2.6,0]],"v":[[22.6,-17.3],[20.2,-24.5],[22.65,-31.55],[28.9,-34.3],[35,-31.55],[37.5,-24.5],[35,-17.35],[28.9,-14.6]],"c":true}},"nm":"a"}],"nm":"a"}]},"fFamily":"AvertaStd-Black"},{"ch":"n","size":29,"style":"?","w":57.6,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[3.6,-4.266],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-4.734,0],[-1,-1.266],[0,-3.4],[0,0],[0,0],[0,0],[3.066,3.067],[5.466,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,-6.4],[2.266,0],[1,1.267],[0,0],[0,0],[0,0],[0,-7.466],[-3.067,-3.066],[-5.667,0]],"v":[[22.4,-43.6],[22.3,-43.6],[22.3,-49],[4.4,-49],[4.4,0],[22.3,0],[22.3,-24.6],[29.4,-34.2],[34.3,-32.3],[35.8,-25.3],[35.8,0],[53.7,0],[53.7,-29.6],[49.1,-45.4],[36.3,-50]],"c":true}},"nm":"n"}],"nm":"n"}]},"fFamily":"AvertaStd-Black"},{"ch":"g","size":29,"style":"?","w":58.8,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[5.466,0],[4.033,-4.7],[0,-7.266],[-4.1,-4.566],[-6.467,0],[-3.134,3.467],[0,0],[0,0],[2.1,-1.5],[3.8,0],[2.666,0.766],[1.8,1.133],[0,0],[-7.8,0],[-4.167,4.866],[0,8.866],[0,0],[0,0]],"o":[[0,0],[-3.534,-3.933],[-5.934,0],[-4.034,4.7],[0,6.867],[4.1,4.567],[5.533,0],[0,0],[0,0],[0,2.266],[-2.1,1.5],[-2.267,0],[-2.667,-0.767],[0,0],[5.733,3],[9.733,0],[4.166,-4.867],[0,0],[0,0],[0,0]],"v":[[36.7,-44.1],[36.6,-44.1],[23.1,-50],[8.15,-42.95],[2.1,-25],[8.25,-7.85],[24.1,-1],[37.1,-6.2],[37.2,-6.2],[37.2,-1.7],[34.05,3.95],[25.2,6.2],[17.8,5.05],[11.1,2.2],[7.2,16.3],[27.5,20.8],[48.35,13.5],[54.6,-7.1],[54.6,-49],[36.7,-49]],"c":true}},"nm":"g"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[0,2.534],[-1.667,1.634],[-2.467,0],[-1.634,-1.666],[0,-2.533],[1.633,-1.633],[2.466,0],[1.666,1.634]],"o":[[0,-2.6],[1.666,-1.633],[2.466,0],[1.633,1.667],[0,2.534],[-1.634,1.634],[-2.467,0],[-1.667,-1.633]],"v":[[20.2,-25.4],[22.7,-31.75],[28.9,-34.2],[35.05,-31.7],[37.5,-25.4],[35.05,-19.15],[28.9,-16.7],[22.7,-19.15]],"c":true}},"nm":"g"}],"nm":"g"}]},"fFamily":"AvertaStd-Black"},{"ch":" ","size":29,"style":"?","w":22.9,"data":{},"fFamily":"AvertaStd-Black"},{"ch":"s","size":29,"style":"?","w":43.5,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[-3.534,2.934],[0,4.934],[2.5,2.2],[6.066,1.934],[0,1],[-2.067,0],[-3.2,-3.4],[0,0],[6.933,0],[3.6,-2.9],[0,-5.2],[-10.4,-3],[-0.834,-0.5],[0,-0.666],[2.466,0],[4.133,3.667],[0,0],[-7.867,0]],"o":[[3.533,-2.933],[0,-4.533],[-2.5,-2.2],[-4.067,-1.333],[0,-1.333],[3.666,0],[0,0],[-5.867,-4.133],[-5.334,0],[-3.6,2.9],[0,7.6],[2.8,0.867],[0.833,0.5],[0,1.334],[-4,0],[0,0],[5.466,4.867],[6.733,0]],"v":[[36.2,-3.4],[41.5,-15.2],[37.75,-25.3],[24.9,-31.5],[18.8,-35],[21.9,-37],[32.2,-31.9],[40.5,-43.8],[21.3,-50],[7.9,-45.65],[2.5,-33.5],[18.1,-17.6],[23.55,-15.55],[24.8,-13.8],[21.1,-11.8],[8.9,-17.3],[0.8,-6.3],[20.8,1]],"c":true}},"nm":"s"}],"nm":"s"}]},"fFamily":"AvertaStd-Black"},{"ch":"l","size":29,"style":"?","w":27.5,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[22.7,0],[22.7,-73.6],[4.8,-73.6],[4.8,0]],"c":true}},"nm":"l"}],"nm":"l"}]},"fFamily":"AvertaStd-Black"},{"ch":"c","size":29,"style":"?","w":51.7,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[-3.9,1.7],[-2.267,2.8],[0,0],[3.666,0],[1.766,1.834],[0,2.867],[-1.7,1.8],[-2.8,0],[-2.467,-2.933],[0,0],[3.8,1.734],[4.2,0],[5,-4.733],[0,-7.533],[-4.867,-4.766],[-7.4,0]],"o":[[3.9,-1.7],[0,0],[-2.2,2.667],[-2.8,0],[-1.767,-1.833],[0,-2.8],[1.7,-1.8],[3.6,0],[0,0],[-2.4,-3.266],[-3.8,-1.733],[-7.934,0],[-5,4.734],[0,7.467],[4.866,4.767],[5.133,0]],"v":[[41.55,-1.55],[50.8,-8.3],[38.6,-18.8],[29.8,-14.8],[22.95,-17.55],[20.3,-24.6],[22.85,-31.5],[29.6,-34.2],[38.7,-29.8],[50.5,-39.9],[41.2,-47.4],[29.2,-50],[9.8,-42.9],[2.3,-24.5],[9.6,-6.15],[28,1]],"c":true}},"nm":"c"}],"nm":"c"}]},"fFamily":"AvertaStd-Black"},{"ch":"o","size":29,"style":"?","w":58.3,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[-5,4.734],[0,7.534],[5,4.734],[7.866,0],[5,-4.733],[0,-7.533],[-5,-4.733],[-7.934,0]],"o":[[5,-4.733],[0,-7.533],[-5,-4.733],[-7.934,0],[-5,4.734],[0,7.534],[5,4.734],[7.866,0]],"v":[[48.5,-6.1],[56,-24.5],[48.5,-42.9],[29.2,-50],[9.8,-42.9],[2.3,-24.5],[9.8,-6.1],[29.2,1]],"c":true}},"nm":"o"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[0,2.867],[-1.667,1.8],[-2.6,0],[-1.634,-1.8],[0,-2.866],[1.666,-1.833],[2.533,0],[1.7,1.834]],"o":[[0,-2.866],[1.666,-1.8],[2.6,0],[1.633,1.8],[0,2.867],[-1.667,1.834],[-2.534,0],[-1.7,-1.833]],"v":[[20.3,-24.5],[22.8,-31.5],[29.2,-34.2],[35.55,-31.5],[38,-24.5],[35.5,-17.45],[29.2,-14.7],[22.85,-17.45]],"c":true}},"nm":"o"}],"nm":"o"}]},"fFamily":"AvertaStd-Black"},{"ch":"r","size":29,"style":"?","w":37.3,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[3.6,-5.2],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-1.7,1.734],[-3.334,0],[-1,-0.066],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,-2.933],[1.7,-1.733],[1.533,0],[0,0],[0,0],[-5.534,0]],"v":[[22.4,-42.2],[22.3,-42.2],[22.3,-49],[4.4,-49],[4.4,0],[22.3,0],[22.3,-21.4],[24.85,-28.4],[32.4,-31],[36.2,-30.9],[36.2,-50],[36.1,-50]],"c":true}},"nm":"r"}],"nm":"r"}]},"fFamily":"AvertaStd-Black"},{"ch":"(","size":29,"style":"?","w":31.5,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,14.734],[-6.534,12.067],[0,0],[0,-18.4],[-8.534,-12.267]],"o":[[-6.534,-12.133],[0,-14.866],[0,0],[-8.534,12.2],[0,18.334],[0,0]],"v":[[29.2,10.9],[19.4,-29.4],[29.2,-69.8],[16.7,-75.3],[3.9,-29.4],[16.7,16.5]],"c":true}},"nm":"("}],"nm":"("}]},"fFamily":"AvertaStd-Black"},{"ch":"S","size":29,"style":"?","w":55.9,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[-2.967,0.8],[-2.734,1.734],[-1.634,3.167],[0,4.267],[5,3.4],[7.4,2.8],[1.2,1.067],[0,1.267],[-3.334,0],[-5.534,-4.266],[0,0],[9.4,-0.2],[4.5,-4.066],[0,-6.066],[-1.167,-2.666],[-2.267,-1.766],[-2.167,-1.1],[-3.2,-1.066],[-1.167,-0.933],[0,-1.466],[1,-0.9],[2.066,0],[5.2,5.267],[0,0],[-10.134,0]],"o":[[2.966,-0.8],[2.733,-1.733],[1.633,-3.166],[0,-6.6],[-2.334,-1.6],[-3.4,-1.333],[-1.2,-1.066],[0,-2.8],[3.466,0],[0,0],[-7.334,-6.533],[-6.8,0.134],[-4.5,4.067],[0,3.467],[1.166,2.667],[2.266,1.767],[2.166,1.1],[3.666,1.2],[1.166,0.934],[0,1.267],[-1,0.9],[-5.6,0],[0,0],[7.4,7.6],[3.2,0]],"v":[[36.35,-0.2],[44.9,-4],[51.45,-11.35],[53.9,-22.5],[46.4,-37.5],[31.8,-44.1],[24.9,-47.7],[23.1,-51.2],[28.1,-55.4],[41.6,-49],[52.1,-62.5],[27,-72],[10.05,-65.7],[3.3,-50.5],[5.05,-41.3],[10.2,-34.65],[16.85,-30.35],[24.9,-27.1],[32.15,-23.9],[33.9,-20.3],[32.4,-17.05],[27.8,-15.7],[11.6,-23.6],[0.8,-10.4],[27.1,1]],"c":true}},"nm":"S"}],"nm":"S"}]},"fFamily":"AvertaStd-Black"},{"ch":"h","size":29,"style":"?","w":58.1,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[3.733,-4.333],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-4.734,0],[-1.034,-1.266],[0,-3.4],[0,0],[0,0],[0,0],[3.066,3.067],[5.466,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,-6.4],[2.533,0],[1.033,1.267],[0,0],[0,0],[0,0],[0,-7.466],[-3.067,-3.066],[-5.867,0]],"v":[[22.4,-43.5],[22.3,-43.5],[22.3,-73.6],[4.4,-73.6],[4.4,0],[22.3,0],[22.3,-24.6],[29.4,-34.2],[34.75,-32.3],[36.3,-25.3],[36.3,0],[54.2,0],[54.2,-29.6],[49.6,-45.4],[36.8,-50]],"c":true}},"nm":"h"}],"nm":"h"}]},"fFamily":"AvertaStd-Black"},{"ch":"p","size":29,"style":"?","w":59.6,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[3.4,-4],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-5,0],[-4.234,4.734],[0,7.534],[4.133,4.767],[6.2,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[3.133,3.534],[6.733,0],[4.233,-4.733],[0,-7.466],[-4.134,-4.766],[-5.4,0]],"v":[[22.4,-44],[22.3,-44],[22.3,-49],[4.4,-49],[4.4,19.8],[22.2,19.8],[22.2,-4.3],[22.3,-4.3],[34.5,1],[50.95,-6.1],[57.3,-24.5],[51.1,-42.85],[35.6,-50]],"c":true}},"nm":"p"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[1.7,1.8],[0,3],[-1.7,1.834],[-2.667,0],[-1.634,-1.833],[0,-2.866],[1.633,-1.833],[2.533,0]],"o":[[-1.7,-1.8],[0,-2.866],[1.7,-1.833],[2.533,0],[1.633,1.834],[0,2.934],[-1.634,1.834],[-2.667,0]],"v":[[24.05,-17.3],[21.5,-24.5],[24.05,-31.55],[30.6,-34.3],[36.85,-31.55],[39.3,-24.5],[36.85,-17.35],[30.6,-14.6]],"c":true}},"nm":"p"}],"nm":"p"}]},"fFamily":"AvertaStd-Black"},{"ch":")","size":29,"style":"?","w":31.5,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,18.334],[8.533,12.2],[0,0],[0,-14.866],[6.533,-12.133],[0,0]],"o":[[0,-18.4],[0,0],[6.533,12.067],[0,14.734],[0,0],[8.533,-12.267]],"v":[[28.9,-29.4],[16.1,-75.3],[3.6,-69.8],[13.4,-29.4],[3.6,10.9],[16.1,16.5]],"c":true}},"nm":")"}],"nm":")"}]},"fFamily":"AvertaStd-Black"},{"ch":"\r","size":19,"style":"?","w":0,"fFamily":"AvertaStd-Black"},{"ch":"i","size":19,"style":"?","w":27.5,"data":{"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"a":0,"k":{"i":[[0,2.8],[1.9,1.8],[3,0],[1.933,-1.833],[0,-2.666],[-1.934,-1.833],[-3,0],[-1.9,1.834]],"o":[[0,-2.733],[-1.9,-1.8],[-3,0],[-1.934,1.834],[0,2.8],[1.933,1.834],[3,0],[1.9,-1.833]],"v":[[24,-64.2],[21.15,-71],[13.8,-73.7],[6.4,-70.95],[3.5,-64.2],[6.4,-57.25],[13.8,-54.5],[21.15,-57.25]],"c":true}},"nm":"i"},{"ind":1,"ty":"sh","ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[22.7,0],[22.7,-49],[4.8,-49],[4.8,0]],"c":true}},"nm":"i"}],"nm":"i"}]},"fFamily":"AvertaStd-Black"}]} \ No newline at end of file diff --git a/components/thorvg-main/test/resources/test9.lot b/components/thorvg-main/test/resources/test9.lot new file mode 100644 index 0000000..45479a7 --- /dev/null +++ b/components/thorvg-main/test/resources/test9.lot @@ -0,0 +1 @@ +{"v":"5.7.4","fr":30,"ip":0,"op":60,"w":400,"h":400,"nm":"MultipleModifiersCombination","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"RoundedCorner+TrimPath+Repeater","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"t":0,"s":[0],"e":[360]},{"t":60,"s":[360]}]},"p":{"a":0,"k":[200,200,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"rc","d":1,"s":{"a":0,"k":[30,30]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":3},"nm":"SmallRectangle"},{"ty":"rd","r":{"a":1,"k":[{"t":0,"s":[0],"e":[15]},{"t":30,"s":[15],"e":[0]},{"t":60,"s":[0]}]},"nm":"RoundCornersAnimated"},{"ty":"tm","s":{"a":1,"k":[{"t":0,"s":[0],"e":[50]},{"t":60,"s":[50]}]},"e":{"a":0,"k":[100]},"o":{"a":0,"k":[0]},"m":1,"nm":"TrimPath"},{"ty":"st","c":{"a":0,"k":[0.2,0.6,1,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":4},"lc":2,"lj":2,"ml":4,"nm":"Stroke"},{"ty":"rp","c":{"a":0,"k":6},"o":{"a":0,"k":0},"m":1,"tr":{"ty":"tr","p":{"a":0,"k":[50,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":60},"so":{"a":0,"k":100},"eo":{"a":0,"k":100}},"nm":"Repeater"}],"ip":0,"op":60,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"OffsetPath+RoundedCorner","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[200,100,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"el","d":1,"s":{"a":0,"k":[60,60]},"p":{"a":0,"k":[0,0]},"nm":"Ellipse"},{"ty":"rd","r":{"a":0,"k":20},"nm":"RoundCorners"},{"ty":"op","a":{"a":1,"k":[{"t":0,"s":[-5],"e":[5]},{"t":30,"s":[5],"e":[-5]},{"t":60,"s":[-5]}]},"lj":1,"ml":4,"nm":"OffsetPathAnimated"},{"ty":"fl","c":{"a":0,"k":[1,0.3,0.3,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill"}],"ip":0,"op":60,"st":0,"bm":0}]} \ No newline at end of file diff --git a/components/thorvg-main/test/testAccessor.cpp b/components/thorvg-main/test/testAccessor.cpp new file mode 100644 index 0000000..f73dd3f --- /dev/null +++ b/components/thorvg-main/test/testAccessor.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +TEST_CASE("Accessor Creation", "[tvgAccessor]") +{ + auto accessor = unique_ptr(Accessor::gen()); + REQUIRE(accessor); + + auto accessor2 = unique_ptr(Accessor::gen()); + REQUIRE(accessor2); +} + +#ifdef THORVG_SVG_LOADER_SUPPORT + +TEST_CASE("Set", "[tvgAccessor]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + auto picture = Picture::gen(); + REQUIRE(picture); + REQUIRE(picture->load(TEST_DIR"/test0.svg") == Result::Success); + + auto accessor = unique_ptr(Accessor::gen()); + REQUIRE(accessor); + + //Case 1 + REQUIRE(accessor->set(picture, nullptr, nullptr) == Result::InvalidArguments); + + //Case 2 + Shape* ret = nullptr; + + auto f = [](const tvg::Paint* paint, void* data) -> bool + { + if (paint->type() == Type::Shape) { + auto shape = (tvg::Shape*) paint; + uint8_t r, g, b; + shape->fill(&r, &g, &b); + if (r == 255 && g == 255 && b == 255) { + shape->fill(0, 0, 255); + shape->id = Accessor::id("TestAccessor"); + *static_cast(data) = shape; + return false; + } + } + return true; + }; + + REQUIRE(accessor->set(picture, f, &ret) == Result::Success); + REQUIRE((ret && ret->id == Accessor::id("TestAccessor"))); + + Picture::rel(picture); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif \ No newline at end of file diff --git a/components/thorvg-main/test/testAnimation.cpp b/components/thorvg-main/test/testAnimation.cpp new file mode 100644 index 0000000..5597a33 --- /dev/null +++ b/components/thorvg-main/test/testAnimation.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + + +TEST_CASE("Animation Basic", "[tvgAnimation]") +{ + auto animation = unique_ptr(Animation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + REQUIRE(picture->type() == Type::Picture); + + //Negative cases + REQUIRE(animation->frame(0.0f) == Result::InsufficientCondition); + REQUIRE(animation->curFrame() == 0.0f); + REQUIRE(animation->totalFrame() == 0.0f); + REQUIRE(animation->duration() == 0.0f); +} + +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + +TEST_CASE("Lottie Raw Data", "[tvgAnimation]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(Animation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + ifstream file(TEST_DIR"/test.lot"); + REQUIRE(file.is_open()); + file.seekg(0, std::ios::end); + auto size = file.tellg(); + file.seekg(0, std::ios::beg); + auto data = (char*)malloc(size); + file.seekg(0, ios::beg); + file.read(data, size); + file.close(); + REQUIRE(picture->load(data, size, "lot", "", true) == Result::Success); + + free(data); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Frames Counting", "[tvgAnimation]") +{ + REQUIRE(Initializer::init(1) == Result::Success); + { + auto animation = unique_ptr(Animation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + REQUIRE(picture->load(TEST_DIR"/invalid.lot") == Result::InvalidArguments); + REQUIRE(picture->load(TEST_DIR"/test.lot") == Result::Success); + + REQUIRE(animation->totalFrame() == Approx(120).margin(0.001f)); + REQUIRE(animation->curFrame() == 0); + REQUIRE(animation->duration() == Approx(4.004).margin(0.001f)); //120/29.97 + REQUIRE(animation->frame(20.0f) == Result::Success); + + for (float i = 1.0f; i < 120.0f; i += 10.0f) { + REQUIRE(animation->frame(i) == Result::Success); + REQUIRE(animation->curFrame() == i); + } + + REQUIRE(animation->frame(102.8f) == Result::Success); + REQUIRE(animation->curFrame() == Approx(102.8f)); + + REQUIRE(animation->frame(13.32f) == Result::Success); + REQUIRE(animation->curFrame() == Approx(13.32f)); + + REQUIRE(animation->frame(27.1232f) == Result::Success); + REQUIRE(animation->curFrame() == Approx(27.1232f)); + + REQUIRE(animation->frame(87.0004f) == Result::Success); + REQUIRE(animation->curFrame() == Approx(87.0004f)); + + REQUIRE(animation->frame(88.0005f) == Result::Success); + REQUIRE(animation->curFrame() == Approx(88.0005f)); + + REQUIRE(animation->frame(89.0009f) == Result::Success); + REQUIRE(animation->curFrame() == Approx(89.0009f)); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Accessor", "[tvgAnimation]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(Animation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + REQUIRE(picture->load(TEST_DIR"/test2.lot") == Result::Success); + + //specify the lottie scene first + REQUIRE(animation->frame(20.0f) == Result::Success); + + //Find specific paint nodes + REQUIRE(!picture->paint(Accessor::id("test1"))); + REQUIRE(!picture->paint(Accessor::id("abcd"))); + REQUIRE(!picture->paint(Accessor::id("abcd"))); + REQUIRE(picture->paint(Accessor::id("bar"))); + REQUIRE(picture->paint(Accessor::id("pad1"))); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Segment", "[tvgAnimation]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(Animation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + float begin, end; + + //Segment by range before loaded + REQUIRE(animation->segment(0, 0.5) == Result::InsufficientCondition); + + //Get current segment before loaded + REQUIRE(animation->segment(&begin, &end) == Result::InsufficientCondition); + + //Animation load + REQUIRE(picture->load(TEST_DIR"/segment.lot") == Result::Success); + + //Get current segment before segment + REQUIRE(animation->segment(&begin, &end) == Result::Success); + REQUIRE(begin == 0.0f); + REQUIRE(end == animation->totalFrame()); + + //Segment by range + REQUIRE(animation->segment(0.25, 0.5) == Result::Success); + + //Get current segment + REQUIRE(animation->segment(&begin, &end) == Result::Success); + REQUIRE(begin == 0.25f); + REQUIRE(end == 0.5f); + + //Get only segment begin + REQUIRE(animation->segment(&begin) == Result::Success); + REQUIRE(begin == 0.25f); + + //Get only segment end + REQUIRE(animation->segment(nullptr, &end) == Result::Success); + REQUIRE(end == 0.5f); + + //Segment by invalid range + REQUIRE(animation->segment(1.5, -0.5) == Result::InvalidArguments); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif \ No newline at end of file diff --git a/components/thorvg-main/test/testFill.cpp b/components/thorvg-main/test/testFill.cpp new file mode 100644 index 0000000..1f81b56 --- /dev/null +++ b/components/thorvg-main/test/testFill.cpp @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + + +TEST_CASE("Filling Creation", "[tvgFill]") +{ + auto linear = unique_ptr(LinearGradient::gen()); + REQUIRE(linear); + + REQUIRE(linear->type() == Type::LinearGradient); + + auto radial = unique_ptr(RadialGradient::gen()); + REQUIRE(radial); + + REQUIRE(radial->type() == Type::RadialGradient); +} + +TEST_CASE("Common Filling", "[tvgFill]") +{ + auto fill = LinearGradient::gen(); + REQUIRE(fill); + + //Options + REQUIRE(fill->spread() == FillSpread::Pad); + REQUIRE(fill->spread(FillSpread::Pad) == Result::Success); + REQUIRE(fill->spread(FillSpread::Reflect) == Result::Success); + REQUIRE(fill->spread(FillSpread::Repeat) == Result::Success); + REQUIRE(fill->spread() == FillSpread::Repeat); + + //ColorStops + const Fill::ColorStop* cs = nullptr; + REQUIRE(fill->colorStops(nullptr) == 0); + REQUIRE(fill->colorStops(&cs) == 0); + REQUIRE(cs == nullptr); + + Fill::ColorStop cs2[4] = { + {0.0f, 0, 0, 0, 0}, + {0.2f, 50, 25, 50, 25}, + {0.5f, 100, 100, 100, 125}, + {1.0f, 255, 255, 255, 255} + }; + + REQUIRE(fill->colorStops(nullptr, 4) == Result::InvalidArguments); + REQUIRE(fill->colorStops(cs2, 0) == Result::InvalidArguments); + REQUIRE(fill->colorStops(cs2, 4) == Result::Success); + REQUIRE(fill->colorStops(&cs) == 4); + + for (int i = 0; i < 4; ++i) { + REQUIRE(cs[i].offset == cs2[i].offset); + REQUIRE(cs[i].r == cs2[i].r); + REQUIRE(cs[i].g == cs2[i].g); + REQUIRE(cs[i].b == cs2[i].b); + }; + + //Reset ColorStop + REQUIRE(fill->colorStops(nullptr, 0) == Result::Success); + REQUIRE(fill->colorStops(&cs) == 0); + + //Set to Shape + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->fill(fill) == Result::Success); + REQUIRE(shape->fill() == fill); + + Paint::rel(shape); +} + +TEST_CASE("Fill Transformation", "[tvgFill]") +{ + auto fill = unique_ptr(LinearGradient::gen()); + REQUIRE(fill); + + //no transformation + auto mGet = fill->transform(); + REQUIRE(mGet.e11 == Approx(1.0f).margin(0.000001)); + REQUIRE(mGet.e12 == Approx(0.0f).margin(0.000001)); + REQUIRE(mGet.e13 == Approx(0.0f).margin(0.000001)); + REQUIRE(mGet.e21 == Approx(0.0f).margin(0.000001)); + REQUIRE(mGet.e22 == Approx(1.0f).margin(0.000001)); + REQUIRE(mGet.e23 == Approx(0.0f).margin(0.000001)); + REQUIRE(mGet.e31 == Approx(0.0f).margin(0.000001)); + REQUIRE(mGet.e32 == Approx(0.0f).margin(0.000001)); + REQUIRE(mGet.e33 == Approx(1.0f).margin(0.000001)); + + auto mSet = Matrix{1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, -7.7f, -8.8f, -9.9f}; + REQUIRE(fill->transform(mSet) == Result::Success); + + //transformation was set + mGet = fill->transform(); + REQUIRE(mGet.e11 == Approx(mSet.e11).margin(0.000001)); + REQUIRE(mGet.e12 == Approx(mSet.e12).margin(0.000001)); + REQUIRE(mGet.e13 == Approx(mSet.e13).margin(0.000001)); + REQUIRE(mGet.e21 == Approx(mSet.e21).margin(0.000001)); + REQUIRE(mGet.e22 == Approx(mSet.e22).margin(0.000001)); + REQUIRE(mGet.e23 == Approx(mSet.e23).margin(0.000001)); + REQUIRE(mGet.e31 == Approx(mSet.e31).margin(0.000001)); + REQUIRE(mGet.e32 == Approx(mSet.e32).margin(0.000001)); + REQUIRE(mGet.e33 == Approx(mSet.e33).margin(0.000001)); +} + +TEST_CASE("Linear Filling", "[tvgFill]") +{ + auto fill = unique_ptr(LinearGradient::gen()); + REQUIRE(fill); + + float x1, y1, x2, y2; + + REQUIRE(fill->linear(nullptr, nullptr, nullptr, nullptr) == Result::Success); + REQUIRE(fill->linear(0, 0, 0, 0) == Result::Success); + + REQUIRE(fill->linear(&x1, nullptr, &x2, nullptr) == Result::Success); + REQUIRE(x1 == 0.0f); + REQUIRE(x2 == 0.0f); + + REQUIRE(fill->linear(-1.0f, -1.0f, 100.0f, 100.0f) == Result::Success); + REQUIRE(fill->linear(&x1, &y1, &x2, &y2) == Result::Success); + REQUIRE(x1 == -1.0f); + REQUIRE(y1 == -1.0f); + REQUIRE(x2 == 100.0f); + REQUIRE(y2 == 100.0f); +} + +TEST_CASE("Radial Filling", "[tvgFill]") +{ + auto fill = unique_ptr(RadialGradient::gen()); + REQUIRE(fill); + + float cx, cy, r, fx, fy, fr; + + REQUIRE(fill->radial(0, 0, -1, 0, 0, 0) == Result::InvalidArguments); + REQUIRE(fill->radial(0, 0, 0, 0, 0, -1) == Result::InvalidArguments); + REQUIRE(fill->radial(nullptr, nullptr, nullptr) == Result::Success); + REQUIRE(fill->radial(100, 120, 50, 10, 20, 5) == Result::Success); + + REQUIRE(fill->radial(&cx, nullptr, &r) == Result::Success); + REQUIRE(cx == 100.0f); + REQUIRE(r == 50.0f); + + REQUIRE(fill->radial(nullptr, &cy, nullptr, &fx, &fy, &fr) == Result::Success); + REQUIRE(cy == 120); + REQUIRE(fx == 10); + REQUIRE(fy == 20); + REQUIRE(fr == 5); + + REQUIRE(fill->radial(0, 0, 0, 0, 0, 0) == Result::Success); + REQUIRE(fill->radial(&cx, &cy, &r, &fx, &fy, &fr) == Result::Success); + REQUIRE(cx == 0.0f); + REQUIRE(cy == 0.0f); + REQUIRE(r == 0.0f); + REQUIRE(fx == 0.0f); + REQUIRE(fy == 0.0f); + REQUIRE(fr == 0.0f); +} + +TEST_CASE("Linear Filling Duplication", "[tvgFill]") +{ + auto fill = unique_ptr(LinearGradient::gen()); + REQUIRE(fill); + + //Setup + Fill::ColorStop cs[4] = { + {0.0f, 0, 0, 0, 0}, + {0.2f, 50, 25, 50, 25}, + {0.5f, 100, 100, 100, 125}, + {1.0f, 255, 255, 255, 255} + }; + + REQUIRE(fill->colorStops(cs, 4) == Result::Success); + REQUIRE(fill->spread(FillSpread::Reflect) == Result::Success); + REQUIRE(fill->linear(-10.0f, 10.0f, 100.0f, 120.0f) == Result::Success); + + auto m = Matrix{1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, -7.7f, -8.8f, -9.9f}; + REQUIRE(fill->transform(m) == Result::Success); + + //Duplication + auto dup = unique_ptr((LinearGradient*)fill->duplicate()); + REQUIRE(dup); + + REQUIRE(dup->spread() == FillSpread::Reflect); + + float x1, y1, x2, y2; + REQUIRE(fill->linear(&x1, &y1, &x2, &y2) == Result::Success); + REQUIRE(x1 == -10.0f); + REQUIRE(y1 == 10.0f); + REQUIRE(x2 == 100.0f); + REQUIRE(y2 == 120.0f); + + const Fill::ColorStop* cs2 = nullptr; + REQUIRE(fill->colorStops(&cs2) == 4); + + for (int i = 0; i < 4; ++i) { + REQUIRE(cs[i].offset == cs2[i].offset); + REQUIRE(cs[i].r == cs2[i].r); + REQUIRE(cs[i].g == cs2[i].g); + REQUIRE(cs[i].b == cs2[i].b); + } + + auto mDup = dup->transform(); + REQUIRE(mDup.e11 == Approx(m.e11).margin(0.000001)); + REQUIRE(mDup.e12 == Approx(m.e12).margin(0.000001)); + REQUIRE(mDup.e13 == Approx(m.e13).margin(0.000001)); + REQUIRE(mDup.e21 == Approx(m.e21).margin(0.000001)); + REQUIRE(mDup.e22 == Approx(m.e22).margin(0.000001)); + REQUIRE(mDup.e23 == Approx(m.e23).margin(0.000001)); + REQUIRE(mDup.e31 == Approx(m.e31).margin(0.000001)); + REQUIRE(mDup.e32 == Approx(m.e32).margin(0.000001)); + REQUIRE(mDup.e33 == Approx(m.e33).margin(0.000001)); +} + +TEST_CASE("Radial Filling Duplication", "[tvgFill]") +{ + auto fill = unique_ptr(RadialGradient::gen()); + REQUIRE(fill); + + //Setup + Fill::ColorStop cs[4] = { + {0.0f, 0, 0, 0, 0}, + {0.2f, 50, 25, 50, 25}, + {0.5f, 100, 100, 100, 125}, + {1.0f, 255, 255, 255, 255} + }; + + REQUIRE(fill->colorStops(cs, 4) == Result::Success); + REQUIRE(fill->spread(FillSpread::Reflect) == Result::Success); + REQUIRE(fill->radial(100.0f, 120.0f, 50.0f, 10.0f, 20.0f, 5.0f) == Result::Success); + + auto m = Matrix{1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, -7.7f, -8.8f, -9.9f}; + REQUIRE(fill->transform(m) == Result::Success); + + //Duplication + auto dup = unique_ptr((RadialGradient*)fill->duplicate()); + REQUIRE(dup); + + REQUIRE(dup->spread() == FillSpread::Reflect); + + float cx, cy, r, fx, fy, fr; + REQUIRE(dup->radial(&cx, &cy, &r, &fx, &fy, &fr) == Result::Success); + REQUIRE(cx == 100.0f); + REQUIRE(cy == 120.0f); + REQUIRE(r == 50.0f); + REQUIRE(fx == 10.0f); + REQUIRE(fy == 20.0f); + REQUIRE(fr == 5.0f); + + const Fill::ColorStop* cs2 = nullptr; + REQUIRE(fill->colorStops(&cs2) == 4); + + for (int i = 0; i < 4; ++i) { + REQUIRE(cs[i].offset == cs2[i].offset); + REQUIRE(cs[i].r == cs2[i].r); + REQUIRE(cs[i].g == cs2[i].g); + REQUIRE(cs[i].b == cs2[i].b); + } + + auto mDup = dup->transform(); + REQUIRE(mDup.e11 == Approx(m.e11).margin(0.000001)); + REQUIRE(mDup.e12 == Approx(m.e12).margin(0.000001)); + REQUIRE(mDup.e13 == Approx(m.e13).margin(0.000001)); + REQUIRE(mDup.e21 == Approx(m.e21).margin(0.000001)); + REQUIRE(mDup.e22 == Approx(m.e22).margin(0.000001)); + REQUIRE(mDup.e23 == Approx(m.e23).margin(0.000001)); + REQUIRE(mDup.e31 == Approx(m.e31).margin(0.000001)); + REQUIRE(mDup.e32 == Approx(m.e32).margin(0.000001)); + REQUIRE(mDup.e33 == Approx(m.e33).margin(0.000001)); +} diff --git a/components/thorvg-main/test/testInitializer.cpp b/components/thorvg-main/test/testInitializer.cpp new file mode 100644 index 0000000..12dccd4 --- /dev/null +++ b/components/thorvg-main/test/testInitializer.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" +#include + +using namespace tvg; + + +TEST_CASE("Basic initialization", "[tvgInitializer]") +{ + REQUIRE(Initializer::init() == Result::Success); + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Multiple initialization", "[tvgInitializer]") +{ + REQUIRE(Initializer::init() == Result::Success); + REQUIRE(Initializer::init() == Result::Success); + REQUIRE(Initializer::term() == Result::Success); + + REQUIRE(Initializer::init() == Result::Success); + REQUIRE(Initializer::term() == Result::Success); + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Version", "[tvgInitializer]") +{ + REQUIRE(strcmp(Initializer::version(nullptr, nullptr, nullptr), THORVG_VERSION_STRING) == 0); + uint32_t major, minor, micro; + REQUIRE(strcmp(Initializer::version(&major, &minor, µ), THORVG_VERSION_STRING) == 0); + char curVersion[10]; + snprintf(curVersion, sizeof(curVersion), "%d.%d.%d", major, minor, micro); + REQUIRE(strcmp(curVersion, THORVG_VERSION_STRING) == 0); +} + +TEST_CASE("Negative termination", "[tvgInitializer]") +{ + REQUIRE(Initializer::term() == Result::InsufficientCondition); +} \ No newline at end of file diff --git a/components/thorvg-main/test/testLottie.cpp b/components/thorvg-main/test/testLottie.cpp new file mode 100644 index 0000000..fc49123 --- /dev/null +++ b/components/thorvg-main/test/testLottie.cpp @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2024 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "config.h" +#include +#ifdef THORVG_LOTTIE_LOADER_SUPPORT +#include +#endif +#include +#include +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + +TEST_CASE("Lottie Coverages", "[tvgLottie]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + #define TEST_CNT 10 + + const char* names[TEST_CNT] = { + "test3.lot", + "test4.lot", + "test5.lot", + "test6.lot", + "test7.lot", + "test8.lot", + "test9.lot", + "test10.lot", + "test11.lot", + "test12.lot" + }; + + auto animation = unique_ptr(Animation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + for (int i = 0; i < TEST_CNT; ++i) { + char buf[100]; + snprintf(buf, sizeof(buf), TEST_DIR"/%s", names[i]); + REQUIRE(picture->load(buf) == Result::Success); + REQUIRE(animation->frame(0.0f) == Result::InsufficientCondition); + REQUIRE(animation->frame(animation->totalFrame() * 0.5f) == Result::Success); + REQUIRE(animation->frame(animation->totalFrame()) == Result::Success); + } + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Slot", "[tvgLottie]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(LottieAnimation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + //Slot Test 1 + const char* slotJson = R"({"gradient_fill":{"p":{"p":2,"k":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}}})"; + + //Negative: slot generation before loaded + REQUIRE(animation->gen(slotJson) == 0); + + REQUIRE(picture->load(TEST_DIR"/slot.lot") == Result::Success); + + auto id = animation->gen(slotJson); + REQUIRE(id > 0); + + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->apply(id) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->apply(id) == Result::Success); + REQUIRE(animation->gen("") == 0); + REQUIRE(animation->del(id) == Result::Success); + + //Slot Test 2 + const char* slotJson2 = R"({"lottie-icon-outline":{"p":{"a":0,"k":[1,1,0]}},"lottie-icon-solid":{"p":{"a":0,"k":[0,0,1]}}})"; + + auto id2 = animation->gen(slotJson2); + REQUIRE(id2 > 0); + + REQUIRE(animation->apply(id2) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->apply(id2) == Result::Success); + REQUIRE(animation->del(id2) == Result::Success); + + //Slot Test 3 (Transform) + const char* positionSlot = R"({"transform_id":{"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"s":[100,100],"t":0},{"s":[200,300],"t":100}]}}})"; + auto id3 = animation->gen(positionSlot); + REQUIRE(id3 > 0); + REQUIRE(animation->apply(id3) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id3) == Result::Success); + + const char* scaleSlot = R"({"transform_id":{"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"s":[0,0],"t":0},{"s":[100,100],"t":100}]}}})"; + auto id4 = animation->gen(scaleSlot); + REQUIRE(id4 > 0); + REQUIRE(animation->apply(id4) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id4) == Result::Success); + + const char* rotationSlot = R"({"transform_id":{"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"s":[0],"t":0},{"s":[180],"t":100}]}}})"; + auto id5 = animation->gen(rotationSlot); + REQUIRE(id5 > 0); + REQUIRE(animation->apply(id5) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id5) == Result::Success); + + const char* opacitySlot = R"({"transform_id":{"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"s":[0],"t":0},{"s":[100],"t":100}]}}})"; + auto id6 = animation->gen(opacitySlot); + REQUIRE(id6 > 0); + REQUIRE(animation->apply(id6) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id6) == Result::Success); + + //Slot Test 4: Expression + const char* expressionSlot = R"({"rect_rotation":{"p":{"x":"var $bm_rt = time * 360;"}},"rect_scale":{"p":{"x":"var $bm_rt = [];$bm_rt[0] = value[0] + Math.cos(2 * Math.PI * time) * 100;$bm_rt[1] = value[1];"}},"rect_position":{"p":{"x":"var $bm_rt = [];$bm_rt[0] = value[0] + Math.cos(2 * Math.PI * time) * 100;$bm_rt[1] = value[1];"}}})"; + auto id7 = animation->gen(expressionSlot); + REQUIRE(id7 > 0); + REQUIRE(animation->apply(id7) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id7) == Result::Success); + + //Slot Test 5: Text + const char* textSlot = R"({"text_doc":{"p":{"k":[{"s":{"f":"Ubuntu Light Italic","t":"ThorVG!","j":0,"s":48,"fc":[1,1,1]},"t":0}]}}})"; + auto id8 = animation->gen(textSlot); + REQUIRE(id8 > 0); + REQUIRE(animation->apply(id8) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id8) == Result::Success); + + //Slot Test 6: Image + const char* imageSlot = R"({"path_img":{"p":{"id":"image_0","w":200,"h":300,"u":"images/","p":"logo.png","e":0}}})"; + auto id9 = animation->gen(imageSlot); + REQUIRE(id9 > 0); + REQUIRE(animation->apply(id9) == Result::Success); + REQUIRE(animation->apply(0) == Result::Success); + REQUIRE(animation->del(id9) == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Marker", "[tvgLottie]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(LottieAnimation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + //Set marker name before loaded + REQUIRE(animation->segment("sectionC") == Result::InsufficientCondition); + + //Animation load + REQUIRE(picture->load(TEST_DIR"/segment.lot") == Result::Success); + + //Set marker + REQUIRE(animation->segment("sectionA") == Result::Success); + + //Set marker by invalid name + REQUIRE(animation->segment("") == Result::InvalidArguments); + + //Get marker count + REQUIRE(animation->markersCnt() == 3); + + //Get marker name by index + REQUIRE(!strcmp(animation->marker(1), "sectionB")); + + //Get marker name by invalid index + REQUIRE(animation->marker(-1) == nullptr); + + REQUIRE(animation->segment(nullptr) == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Tween", "[tvgLottie]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(LottieAnimation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + REQUIRE(animation->tween(0.0f, 10.0f, 0.5f) == Result::InsufficientCondition); + + REQUIRE(picture->load(TEST_DIR"/test.lot") == Result::Success); + + //Set initial frame to avoid frame difference being too small + REQUIRE(animation->frame(5.0f) == Result::Success); + + //Tween between frames with different progress values + REQUIRE(animation->tween(0.0f, 10.0f, 0.5f) == Result::Success); + REQUIRE(animation->tween(10.0f, 20.0f, 0.0f) == Result::Success); + REQUIRE(animation->tween(20.0f, 30.0f, 1.0f) == Result::Success); + + //Tween with different frame ranges + REQUIRE(animation->tween(10.0f, 50.0f, 0.25f) == Result::Success); + REQUIRE(animation->tween(50.0f, 100.0f, 0.75f) == Result::Success); + + //Tween between distant frames + REQUIRE(animation->tween(0.0f, 100.0f, 0.5f) == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Quality", "[tvgLottie]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(LottieAnimation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + REQUIRE(animation->quality(50) == Result::InsufficientCondition); + + REQUIRE(picture->load(TEST_DIR"/test.lot") == Result::Success); + + //Set quality with minimum value + REQUIRE(animation->quality(0) == Result::Success); + + //Set quality with default value + REQUIRE(animation->quality(50) == Result::Success); + + //Set quality with maximum value + REQUIRE(animation->quality(100) == Result::Success); + + //Set quality with various values + REQUIRE(animation->quality(25) == Result::Success); + REQUIRE(animation->quality(75) == Result::Success); + + //Set quality with invalid value (> 100) + REQUIRE(animation->quality(101) == Result::InvalidArguments); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Lottie Asset Resolver", "[tvgLottie]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = unique_ptr(LottieAnimation::gen()); + REQUIRE(animation); + + auto picture = animation->picture(); + + auto resolver = [](Paint* p, const char* src, void* data) -> bool { + if (p->type() == Type::Picture) { + string resolvedPath = string(TEST_DIR) + "/image/test.png"; + auto ret = static_cast(p)->load(resolvedPath.c_str()); + return (ret == Result::Success); + } else if (p->type() == Type::Text) { + string fontPath = string(TEST_DIR) + "/font/Arial.ttf"; + if (Text::load(fontPath.c_str()) != Result::Success) return false; + auto ret = static_cast(p)->font("Arial"); + return (ret == Result::Success); + } + return false; + }; + + // Test unset resolver + REQUIRE(picture->resolver(resolver, nullptr) == Result::Success); + REQUIRE(picture->resolver(nullptr, nullptr) == Result::Success); + + //Resolver Test (Image and Font) + REQUIRE(picture->resolver(resolver, nullptr) == Result::Success); + REQUIRE(picture->load(TEST_DIR"/resolver.json") == Result::Success); + REQUIRE(animation->frame(animation->totalFrame() * 0.5f) == Result::Success); + + //Test that setting/unsetting resolver after load + REQUIRE(picture->resolver(resolver, nullptr) == Result::InsufficientCondition); + REQUIRE(picture->resolver(nullptr, nullptr) == Result::InsufficientCondition); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif \ No newline at end of file diff --git a/components/thorvg-main/test/testMain.cpp b/components/thorvg-main/test/testMain.cpp new file mode 100644 index 0000000..e7d1d2a --- /dev/null +++ b/components/thorvg-main/test/testMain.cpp @@ -0,0 +1,5 @@ +// The only purpose of this file is to DEFINE the catch config so it can include main() + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file + +#include "catch.hpp" diff --git a/components/thorvg-main/test/testPaint.cpp b/components/thorvg-main/test/testPaint.cpp new file mode 100644 index 0000000..9d6af8d --- /dev/null +++ b/components/thorvg-main/test/testPaint.cpp @@ -0,0 +1,430 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +TEST_CASE("Custom Transformation", "[tvgPaint]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + //Verify default transform + Matrix m1 = shape->transform(); + REQUIRE(m1.e11 == Approx(1.0f).margin(0.000001)); + REQUIRE(m1.e12 == Approx(0).margin(0.000001)); + REQUIRE(m1.e13 == Approx(0).margin(0.000001)); + REQUIRE(m1.e21 == Approx(0).margin(0.000001)); + REQUIRE(m1.e22 == Approx(1.0f).margin(0.000001)); + REQUIRE(m1.e23 == Approx(0).margin(0.000001)); + REQUIRE(m1.e31 == Approx(0).margin(0.000001)); + REQUIRE(m1.e32 == Approx(0).margin(0.000001)); + REQUIRE(m1.e33 == Approx(1.0f).margin(0.000001)); + + //Custom transform + auto m2 = Matrix{1.0f, 2.0f, 3.0f, 4.0f, 0.0f, -4.0f, -3.0f, -2.0f, -1.0f}; + REQUIRE(shape->transform(m2) == Result::Success); + + auto m3 = shape->transform(); + REQUIRE(m2.e11 == Approx(m3.e11).margin(0.000001)); + REQUIRE(m2.e12 == Approx(m3.e12).margin(0.000001)); + REQUIRE(m2.e13 == Approx(m3.e13).margin(0.000001)); + REQUIRE(m2.e21 == Approx(m3.e21).margin(0.000001)); + REQUIRE(m2.e22 == Approx(m3.e22).margin(0.000001)); + REQUIRE(m2.e23 == Approx(m3.e23).margin(0.000001)); + REQUIRE(m2.e31 == Approx(m3.e31).margin(0.000001)); + REQUIRE(m2.e32 == Approx(m3.e32).margin(0.000001)); + REQUIRE(m2.e33 == Approx(m3.e33).margin(0.000001)); + + //It's not allowed if the custom transform is applied. + REQUIRE(shape->translate(155.0f, -155.0f) == Result::InsufficientCondition); + REQUIRE(shape->scale(4.7f) == Result::InsufficientCondition); + REQUIRE(shape->rotate(45.0f) == Result::InsufficientCondition); + + //Verify Transform is not modified + auto m4 = shape->transform(); + REQUIRE(m2.e11 == Approx(m4.e11).margin(0.000001)); + REQUIRE(m2.e12 == Approx(m4.e12).margin(0.000001)); + REQUIRE(m2.e13 == Approx(m4.e13).margin(0.000001)); + REQUIRE(m2.e21 == Approx(m4.e21).margin(0.000001)); + REQUIRE(m2.e22 == Approx(m4.e22).margin(0.000001)); + REQUIRE(m2.e23 == Approx(m4.e23).margin(0.000001)); + REQUIRE(m2.e31 == Approx(m4.e31).margin(0.000001)); + REQUIRE(m2.e32 == Approx(m4.e32).margin(0.000001)); + REQUIRE(m2.e33 == Approx(m4.e33).margin(0.000001)); + + Paint::rel(shape); +} + + +TEST_CASE("Basic Transformation", "[tvgPaint]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->translate(155.0f, -155.0f) == Result::Success); + REQUIRE(shape->rotate(45.0f) == Result::Success); + REQUIRE(shape->scale(4.7f) == Result::Success); + + auto m = shape->transform(); + REQUIRE(m.e11 == Approx(3.323402f).margin(0.000001)); + REQUIRE(m.e12 == Approx(-3.323401f).margin(0.000001)); + REQUIRE(m.e13 == Approx(155.0f).margin(0.000001)); + REQUIRE(m.e21 == Approx(3.323401f).margin(0.000001)); + REQUIRE(m.e22 == Approx(3.323402f).margin(0.000001)); + REQUIRE(m.e23 == Approx(-155.0f).margin(0.000001)); + REQUIRE(m.e31 == Approx(0).margin(0.000001)); + REQUIRE(m.e32 == Approx(0).margin(0.000001)); + REQUIRE(m.e33 == Approx(1).margin(0.000001)); + + Paint::rel(shape); +} + +TEST_CASE("Opacity", "[tvgPaint]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->opacity() == 255); + + REQUIRE(shape->opacity(155) == Result::Success); + REQUIRE(shape->opacity() == 155); + + REQUIRE(shape->opacity(-1) == Result::Success); + REQUIRE(shape->opacity() == 255); + + REQUIRE(shape->opacity(0) == Result::Success); + REQUIRE(shape->opacity() == 0); + + Paint::rel(shape); +} + +TEST_CASE("Visibility", "[tvgPaint]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->visible() == true); + + REQUIRE(shape->visible(false) == Result::Success); + REQUIRE(shape->visible() == false); + + REQUIRE(shape->visible(false) == Result::Success); + REQUIRE(shape->visible() == false); + + REQUIRE(shape->visible(true) == Result::Success); + REQUIRE(shape->visible() == true); + + Paint::rel(shape); +} + +TEST_CASE("Bounding Box", "[tvgPaint]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto buffer = unique_ptr(new uint32_t[500*500]); + auto canvas = unique_ptr(SwCanvas::gen()); + canvas->target(buffer.get(), 500, 500, 500, ColorSpace::ARGB8888); + + auto shape = Shape::gen(); + canvas->add(shape); + + //Negative + float x = 0, y = 0, w = 0, h = 0; + REQUIRE(shape->bounds(&x, &y, &w, &h) == Result::InsufficientCondition); + + //Case 1 + REQUIRE(shape->appendRect(0.0f, 10.0f, 20.0f, 100.0f, 50.0f, 50.0f) == Result::Success); + REQUIRE(shape->translate(100.0f, 111.0f) == Result::Success); + + canvas->update(); + + //Positive + REQUIRE(shape->bounds(&x, &y, &w, &h) == Result::Success); + REQUIRE(x == 100.0f); + REQUIRE(y == 121.0f); + REQUIRE(w == 20.0f); + REQUIRE(h == 100.0f); + + Point pts[4]; + REQUIRE(shape->bounds(pts) == Result::Success); + REQUIRE(pts[0].x == 100.0f); + REQUIRE(pts[3].x == 100.0f); + REQUIRE(pts[0].y == 121.0f); + REQUIRE(pts[1].y == 121.0f); + REQUIRE(pts[1].x == 120.0f); + REQUIRE(pts[2].x == 120.0f); + REQUIRE(pts[2].y == 221.0f); + REQUIRE(pts[3].y == 221.0f); + + REQUIRE(canvas->sync() == Result::Success); + + //Case 2 + REQUIRE(shape->reset() == Result::Success); + REQUIRE(shape->moveTo(0.0f, 10.0f) == Result::Success); + REQUIRE(shape->lineTo(20.0f, 210.0f) == Result::Success); + auto identity = Matrix{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + REQUIRE(shape->transform(identity) == Result::Success); + + REQUIRE(canvas->update() == Result::Success); + + REQUIRE(shape->bounds(&x, &y, &w, &h) == Result::Success); + REQUIRE(x == 0.0f); + REQUIRE(y == 10.0f); + REQUIRE(w == 20.0f); + REQUIRE(h == 200.0f); + + REQUIRE(shape->bounds(pts) == Result::Success); + REQUIRE(pts[0].x == 0.0f); + REQUIRE(pts[3].x == 0.0f); + REQUIRE(pts[0].y == 10.0f); + REQUIRE(pts[1].y == 10.0f); + REQUIRE(pts[1].x == 20.0f); + REQUIRE(pts[2].x == 20.0f); + REQUIRE(pts[2].y == 210.0f); + REQUIRE(pts[3].y == 210.0f); + + REQUIRE(canvas->sync() == Result::Success); + + //Case3 + REQUIRE(shape->reset() == Result::Success); + REQUIRE(shape->moveTo(10, 10) == Result::Success); + REQUIRE(shape->lineTo(190, 10) == Result::Success); + REQUIRE(shape->strokeWidth(12.0f) == Result::Success); + REQUIRE(shape->strokeFill(255, 0, 0, 255) == Result::Success); + + REQUIRE(canvas->update() == Result::Success); + + REQUIRE(shape->bounds(&x, &y, &w, &h) == Result::Success); + REQUIRE(x == 4.0f); + REQUIRE(y == 4.0f); + REQUIRE(h == 12.0f); + REQUIRE(w == 192.0f); + + REQUIRE(shape->bounds(pts) == Result::Success); + REQUIRE(pts[0].x == 4.0f); + REQUIRE(pts[3].x == 4.0f); + REQUIRE(pts[0].y == 4.0f); + REQUIRE(pts[1].y == 4.0f); + REQUIRE(pts[1].x == 196.0f); + REQUIRE(pts[2].x == 196.0f); + REQUIRE(pts[2].y == 16.0f); + REQUIRE(pts[3].y == 16.0f); + +#ifdef THORVG_TTF_LOADER_SUPPORT + //Text + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + auto text = Text::gen(); + REQUIRE(canvas->add(text) == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + //Empty Size + REQUIRE(text->bounds(&x, &y, &w, &h) == Result::Success); + + //Case 1 + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(32) == Result::Success); + REQUIRE(text->text("TEST") == Result::Success); + REQUIRE(text->translate(100.0f, 111.0f) == Result::Success); + REQUIRE(text->bounds(&x, &y, &w, &h) == Result::Success); + + REQUIRE(x == Approx(101.0f).margin(0.000001)); + REQUIRE(y == Approx(118.5625f).margin(0.000001)); + REQUIRE(w == Approx(107.1875f).margin(0.000001)); + REQUIRE(h == Approx(31.58334f).margin(0.001f)); + + REQUIRE(canvas->update() == Result::Success); + + REQUIRE(text->bounds(pts) == Result::Success); + REQUIRE(pts[0].x == Approx(101.0f).margin(0.000001)); + REQUIRE(pts[3].x == Approx(101.0f).margin(0.000001)); + REQUIRE(pts[1].x == Approx(208.1875f).margin(0.000001)); + REQUIRE(pts[2].x == Approx(208.1875f).margin(0.000001)); + REQUIRE(pts[0].y == Approx(118.5625f).margin(0.000001)); + REQUIRE(pts[1].y == Approx(118.5625f).margin(0.000001)); + REQUIRE(pts[2].y == Approx(150.14584f).margin(0.000001)); + REQUIRE(pts[3].y == Approx(150.14584f).margin(0.000001)); + + + //Case 2 + REQUIRE(text->text("BOUNDS") == Result::Success); + identity = Matrix{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + REQUIRE(text->transform(identity) == Result::Success); + REQUIRE(text->bounds(&x, &y, &w, &h) == Result::Success); + + REQUIRE(x == Approx(3.125f).margin(0.000001)); + REQUIRE(y == Approx(7.54167f).margin(0.000001)); + REQUIRE(w == Approx(177.1875f).margin(0.000001)); + REQUIRE(h == Approx(31.60417f).margin(0.000001)); + + REQUIRE(canvas->update() == Result::Success); + REQUIRE(text->bounds(pts) == Result::Success); + REQUIRE(pts[0].x == Approx(3.125f).margin(0.000001)); + REQUIRE(pts[3].x == Approx(3.125f).margin(0.000001)); + REQUIRE(pts[1].x == Approx(180.3125f).margin(0.000001)); + REQUIRE(pts[2].x == Approx(180.3125f).margin(0.000001)); + REQUIRE(pts[0].y == Approx(7.54167f).margin(0.000001)); + REQUIRE(pts[1].y == Approx(7.54167f).margin(0.000001)); + REQUIRE(pts[2].y == Approx(39.14584f).margin(0.000001)); + REQUIRE(pts[3].y == Approx(39.14584f).margin(0.000001)); +#endif + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Intersection", "[tvgPaint]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + + uint32_t buffer[200 * 200]; + canvas->target(buffer, 200, 200, 200, ColorSpace::ARGB8888); + + auto shape = Shape::gen(); + REQUIRE(shape); + REQUIRE(shape->appendRect(50, 50, 100, 100) == Result::Success); + REQUIRE(shape->fill(255, 0, 0, 255) == Result::Success); + + REQUIRE(canvas->add(shape) == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + + // Case1. Fully contained + REQUIRE(shape->intersects(0, 0, 200, 200) == true); + + // Case2. Partially overlapping + REQUIRE(shape->intersects(25, 25, 50, 50) == true); + REQUIRE(shape->intersects(125, 125, 50, 50) == true); + + // Case3. Edge-touching + REQUIRE(shape->intersects(49, 49, 2, 2) == true); + REQUIRE(shape->intersects(149, 149, 2, 2) == true); + + // Case4. Fully separated + REQUIRE(shape->intersects(0, 0, 25, 25) == false); + REQUIRE(shape->intersects(175, 175, 25, 25) == false); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Duplication", "[tvgPaint]") +{ + vector paints; + + auto shape = Shape::gen(); + REQUIRE(shape); + paints.push_back(shape); + +#ifdef THORVG_TTF_LOADER_SUPPORT + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + auto text = Text::gen(); + REQUIRE(text); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(32) == Result::Success); + REQUIRE(text->text("Original Text") == Result::Success); + REQUIRE(text->fill(255, 0, 0) == Result::Success); + paints.push_back(text); +#endif + + for (auto& paint : paints) { + //Setup paint properties + REQUIRE(paint->opacity(0) == Result::Success); + REQUIRE(paint->translate(200.0f, 100.0f) == Result::Success); + REQUIRE(paint->scale(2.2f) == Result::Success); + REQUIRE(paint->rotate(90.0f) == Result::Success); + + auto comp = Shape::gen(); + REQUIRE(comp); + REQUIRE(paint->clip(comp) == Result::Success); + + //Duplication + auto dup = paint->duplicate(); + REQUIRE(dup); + + //Compare properties + REQUIRE(dup->opacity() == 0); + + auto m = paint->transform(); + REQUIRE(m.e11 == Approx(0.0f).margin(0.000001)); + REQUIRE(m.e12 == Approx(-2.2f).margin(0.000001)); + REQUIRE(m.e13 == Approx(200.0f).margin(0.000001)); + REQUIRE(m.e21 == Approx(2.2f).margin(0.000001)); + REQUIRE(m.e22 == Approx(0.0f).margin(0.000001)); + REQUIRE(m.e23 == Approx(100.0f).margin(0.000001)); + REQUIRE(m.e31 == Approx(0.0f).margin(0.000001)); + REQUIRE(m.e32 == Approx(0.0f).margin(0.000001)); + REQUIRE(m.e33 == Approx(1.0f).margin(0.000001)); + + Paint::rel(dup); + } + + //release + for (auto p : paints) { + Paint::rel(p); + } +} + + +TEST_CASE("Reference Count", "[tvgPaint]") +{ + auto shape = Shape::gen(); + REQUIRE(shape->refCnt() == 0); + REQUIRE(shape->unref(false) == 0); + REQUIRE(shape->ref() == 1); + REQUIRE(shape->ref() == 2); + REQUIRE(shape->ref() == 3); + REQUIRE(shape->unref() == 2); + REQUIRE(shape->unref() == 1); + REQUIRE(shape->unref() == 0); + + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + + shape = Shape::gen(); + REQUIRE(shape->ref() == 1); + canvas->add(shape); + REQUIRE(shape->refCnt() == 2); + REQUIRE(shape->unref() == 1); + + shape = Shape::gen(); + REQUIRE(shape->ref() == 1); + auto scene = Scene::gen(); + scene->add(shape); + canvas->add(scene); + REQUIRE(shape->refCnt() == 2); + REQUIRE(shape->unref() == 1); + + shape = Shape::gen(); + REQUIRE(shape->ref() == 1); + scene = Scene::gen(); + scene->add(shape); + scene->remove(); + canvas->add(scene); + REQUIRE(shape->unref() == 0); + } + Initializer::term(); +} \ No newline at end of file diff --git a/components/thorvg-main/test/testPicture.cpp b/components/thorvg-main/test/testPicture.cpp new file mode 100644 index 0000000..819867e --- /dev/null +++ b/components/thorvg-main/test/testPicture.cpp @@ -0,0 +1,460 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + + +TEST_CASE("Picture Creation", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + REQUIRE(picture->type() == Type::Picture); + + Paint::rel(picture); +} + +TEST_CASE("Load RAW Data", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + ifstream file(TEST_DIR"/rawimage_200x300.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 200 * 300); + file.close(); + + //Negative cases + REQUIRE(picture->load(nullptr, 200, 300, ColorSpace::ARGB8888, false) == Result::InvalidArguments); + REQUIRE(picture->load(data, 0, 0, ColorSpace::ARGB8888, false) == Result::InvalidArguments); + REQUIRE(picture->load(data, 200, 0, ColorSpace::ARGB8888, false) == Result::InvalidArguments); + REQUIRE(picture->load(data, 0, 300, ColorSpace::ARGB8888, false) == Result::InvalidArguments); + + //Positive cases + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, true) == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + + REQUIRE(w == 200); + REQUIRE(h == 300); + + Paint::rel(picture); + + free(data); +} + +TEST_CASE("Picture Size", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::InsufficientCondition); + + //Primary + ifstream file(TEST_DIR"/rawimage_200x300.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 200 * 300); + file.close(); + + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + + REQUIRE(picture->size(nullptr, nullptr) == Result::Success); + REQUIRE(picture->size(100, 100) == Result::Success); + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(w == 100); + REQUIRE(h == 100); + + free(data); + + //Secondary + ifstream file2(TEST_DIR"/rawimage_250x375.raw"); + if (!file2.is_open()) return; + data = (uint32_t*)malloc(sizeof(uint32_t) * (250*375)); + file2.read(reinterpret_cast(data), sizeof (uint32_t) * 250 * 375); + file2.close(); + + REQUIRE(picture->load(data, 250, 375, ColorSpace::ARGB8888, false) == Result::Success); + + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(picture->size(w, h) == Result::Success); + + free(data); + + Paint::rel(picture); +} + +TEST_CASE("Picture Origin", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::InsufficientCondition); + + //Primary + ifstream file(TEST_DIR"/rawimage_200x300.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 200 * 300); + file.close(); + + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + REQUIRE(picture->origin(0.0f, 0.0f) == Result::Success); + REQUIRE(picture->origin(0.5f, 0.5f) == Result::Success); + REQUIRE(picture->origin(1.0f, 1.0f) == Result::Success); + REQUIRE(picture->origin(-1.0f, -1.0f) == Result::Success); + + free(data); + + Paint::rel(picture); +} + +TEST_CASE("Picture Resolver", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::InsufficientCondition); + + //Primary + ifstream file(TEST_DIR"/rawimage_200x300.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 200 * 300); + file.close(); + + auto resolver = [](Paint* paint, const char* src, void *data) -> bool + { + return false; + }; + + REQUIRE(picture->resolver(resolver, nullptr) == Result::Success); + + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + + free(data); + + Paint::rel(picture); +} + +TEST_CASE("Picture Duplication", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Primary + ifstream file(TEST_DIR"/rawimage_200x300.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 200 * 300); + file.close(); + + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + REQUIRE(picture->size(100, 100) == Result::Success); + + auto dup = (Picture*)picture->duplicate(); + REQUIRE(dup); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(w == 100); + REQUIRE(h == 100); + + free(data); + + Paint::rel(dup); + Paint::rel(picture); +} + +#ifdef THORVG_SVG_LOADER_SUPPORT + +TEST_CASE("Load SVG file", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Invalid file + REQUIRE(picture->load("invalid.svg") == Result::InvalidArguments); + + //Load Svg file + REQUIRE(picture->load(TEST_DIR"/test1.svg") == Result::Success); + REQUIRE(picture->load(TEST_DIR"/test2.svg") == Result::Success); + REQUIRE(picture->load(TEST_DIR"/test3.svg") == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + + Paint::rel(picture); +} + +TEST_CASE("Load SVG Data", "[tvgPicture]") +{ + static const char* svg = ""; + + auto picture = Picture::gen(); + REQUIRE(picture); + + //Negative cases + REQUIRE(picture->load(nullptr, 100, "") == Result::InvalidArguments); + REQUIRE(picture->load(svg, 0, "") == Result::InvalidArguments); + + //Positive cases + REQUIRE(picture->load(svg, strlen(svg), "svg") == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(w == 1000); + REQUIRE(h == 1000); + + Paint::rel(picture); +} + +#endif + +#ifdef THORVG_PNG_LOADER_SUPPORT + +TEST_CASE("Load PNG file from path", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Invalid file + REQUIRE(picture->load("invalid.png") == Result::InvalidArguments); + + REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + + REQUIRE(w == 512); + REQUIRE(h == 512); + + Paint::rel(picture); +} + +TEST_CASE("Load PNG file from data", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Open file + ifstream file(TEST_DIR"/test.png", ios::in | ios::binary); + REQUIRE(file.is_open()); + auto size = sizeof(uint32_t) * (1000*1000); + auto data = (char*)malloc(size); + file.read(data, size); + file.close(); + + REQUIRE(picture->load(data, size, "") == Result::Success); + REQUIRE(picture->load(data, size, "png", "", true) == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(w == 512); + REQUIRE(h == 512); + + free(data); + + Paint::rel(picture); +} + +TEST_CASE("Load PNG file and render", "[tvgPicture]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + auto picture = Picture::gen(); + REQUIRE(picture); + + REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success); + REQUIRE(picture->opacity(192) == Result::Success); + REQUIRE(picture->scale(5.0) == Result::Success); + + REQUIRE(canvas->add(picture) == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif + +#ifdef THORVG_JPG_LOADER_SUPPORT + +TEST_CASE("Load JPG file from path", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Invalid file + REQUIRE(picture->load("invalid.jpg") == Result::InvalidArguments); + + REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + + REQUIRE(w == 512); + REQUIRE(h == 512); + + Paint::rel(picture); +} + +TEST_CASE("Load JPG file from data", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Open file + ifstream file(TEST_DIR"/test.jpg", ios::in | ios::binary); + REQUIRE(file.is_open()); + auto begin = file.tellg(); + file.seekg(0, ios::end); + auto size = file.tellg() - begin; + auto data = (char*)malloc(size); + file.seekg(0, ios::beg); + file.read(data, size); + file.close(); + + REQUIRE(picture->load(data, size, "") == Result::Success); + REQUIRE(picture->load(data, size, "jpg", "", true) == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(w == 512); + REQUIRE(h == 512); + + free(data); + + Paint::rel(picture); +} + +TEST_CASE("Load JPG file and render", "[tvgPicture]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + auto picture = Picture::gen(); + REQUIRE(picture); + + REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success); + + REQUIRE(canvas->add(picture) == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif + +#ifdef THORVG_WEBP_LOADER_SUPPORT + +TEST_CASE("Load WEBP file from path", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Invalid file + REQUIRE(picture->load("invalid.webp") == Result::InvalidArguments); + + REQUIRE(picture->load(TEST_DIR"/test.webp") == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + + REQUIRE(w == 512); + REQUIRE(h == 512); + + Paint::rel(picture); +} + +TEST_CASE("Load WEBP file from data", "[tvgPicture]") +{ + auto picture = Picture::gen(); + REQUIRE(picture); + + //Open file + ifstream file(TEST_DIR"/test.webp", ios::in | ios::binary); + REQUIRE(file.is_open()); + auto size = sizeof(uint32_t) * (1000*1000); + auto data = (char*)malloc(size); + file.read(data, size); + file.close(); + + REQUIRE(picture->load(data, size, "") == Result::Success); + REQUIRE(picture->load(data, size, "webp", "", true) == Result::Success); + + float w, h; + REQUIRE(picture->size(&w, &h) == Result::Success); + REQUIRE(w == 512); + REQUIRE(h == 512); + + free(data); + + Paint::rel(picture); +} + +TEST_CASE("Load WEBP file and render", "[tvgPicture]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + auto picture = Picture::gen(); + REQUIRE(picture); + + REQUIRE(picture->load(TEST_DIR"/test.webp") == Result::Success); + REQUIRE(picture->opacity(192) == Result::Success); + REQUIRE(picture->scale(5.0) == Result::Success); + + REQUIRE(canvas->add(picture) == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif + diff --git a/components/thorvg-main/test/testSavers.cpp b/components/thorvg-main/test/testSavers.cpp new file mode 100644 index 0000000..1177425 --- /dev/null +++ b/components/thorvg-main/test/testSavers.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +TEST_CASE("Saver Creation", "[tvgSavers]") +{ + auto saver = unique_ptr(Saver::gen()); + REQUIRE(saver); +} + +#if defined(THORVG_GIF_SAVER_SUPPORT) && defined(THORVG_LOTTIE_LOADER_SUPPORT) + +TEST_CASE("Save a lottie into gif", "[tvgSavers]") { + REQUIRE(Initializer::init() == Result::Success); + { + auto animation = Animation::gen(); + auto picture = animation->picture(); + REQUIRE(picture->load(TEST_DIR"/test.lot") == Result::Success); + REQUIRE(picture->size(100, 100) == Result::Success); + + auto bg = Shape::gen(); + REQUIRE(bg->fill(255, 255, 255) == Result::Success); + REQUIRE(bg->appendRect(0, 0, 100, 100) == Result::Success); + + auto saver = unique_ptr(Saver::gen()); + REQUIRE(saver); + + REQUIRE(saver->background(bg) == Result::Success); + REQUIRE(saver->save(animation, TEST_DIR"/test.gif") == Result::Success); + REQUIRE(saver->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} +#endif \ No newline at end of file diff --git a/components/thorvg-main/test/testScene.cpp b/components/thorvg-main/test/testScene.cpp new file mode 100644 index 0000000..0c41360 --- /dev/null +++ b/components/thorvg-main/test/testScene.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +TEST_CASE("Scene Creation", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); + + REQUIRE(scene->type() == Type::Scene); + + Paint::rel(scene); +} + +TEST_CASE("Pushing Paints Into Scene", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); + REQUIRE(scene->parent() == nullptr); + + Paint* paints[3]; + + //Pushing Paints + paints[0] = Shape::gen(); + paints[0]->ref(); + REQUIRE(paints[0]->parent() == nullptr); + REQUIRE(scene->add(paints[0]) == Result::Success); + REQUIRE(paints[0]->parent() == scene); + + paints[1] = Picture::gen(); + paints[1]->ref(); + REQUIRE(paints[1]->parent() == nullptr); + REQUIRE(scene->add(paints[1]) == Result::Success); + REQUIRE(paints[1]->parent() == scene); + + paints[2] = Picture::gen(); + paints[2]->ref(); + REQUIRE(paints[2]->parent() == nullptr); + REQUIRE(scene->add(paints[2]) == Result::Success); + REQUIRE(paints[2]->parent() == scene); + + //Pushing Null Pointer + REQUIRE(scene->add(nullptr) == Result::InvalidArguments); + + //Pushing Invalid Paint + REQUIRE(scene->add(nullptr) == Result::InvalidArguments); + + REQUIRE(scene->remove(paints[0]) == Result::Success); + REQUIRE(scene->remove(paints[0]) == Result::InsufficientCondition); + REQUIRE(scene->add(paints[0], paints[1]) == Result::Success); + REQUIRE(scene->remove(paints[1]) == Result::Success); + REQUIRE(scene->remove(paints[1]) == Result::InsufficientCondition); + REQUIRE(scene->remove(paints[2]) == Result::Success); + REQUIRE(scene->remove(paints[0]) == Result::Success); + + paints[0]->unref(); + paints[1]->unref(); + paints[2]->unref(); + + Paint::rel(scene); +} + +TEST_CASE("Scene Clear", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); + + REQUIRE(scene->add(Shape::gen()) == Result::Success); + REQUIRE(scene->remove() == Result::Success); + + Paint::rel(scene); +} + +TEST_CASE("Scene Clear And Reuse Shape", "[tvgScene]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto scene = Scene::gen(); + REQUIRE(scene); + + auto shape = Shape::gen(); + REQUIRE(shape); + REQUIRE(shape->ref() == 1); + + REQUIRE(scene->add(shape) == Result::Success); + REQUIRE(canvas->add(scene) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + + //No deallocate shape. + REQUIRE(scene->remove() == Result::Success); + + //Reuse shape. + REQUIRE(scene->add(shape) == Result::Success); + REQUIRE(shape->unref() == 1); //The scene still holds 1. + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Scene Effects", "[tvgScene]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + auto shape = Shape::gen(); + REQUIRE(shape); + REQUIRE(shape->appendCircle(50, 50, 30, 30) == Result::Success); + REQUIRE(shape->fill(0, 255, 0, 255) == Result::Success); + + auto scene = Scene::gen(); + REQUIRE(scene); + REQUIRE(scene->add(shape) == Result::Success); + + auto picture = tvg::Picture::gen(); + picture->load(TEST_DIR"/tiger.svg"); + + scene->add(picture); + REQUIRE(canvas->add(scene) == Result::Success); + + REQUIRE(scene->add(SceneEffect::Clear) == Result::Success); + REQUIRE(scene->add(SceneEffect::GaussianBlur, 1.5, 0, 0, 75) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(scene->add(SceneEffect::Clear) == Result::Success); + REQUIRE(scene->add(SceneEffect::DropShadow, 128, 128, 128, 200, 45.0, 5.0, 2.0, 60) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(scene->add(SceneEffect::Clear) == Result::Success); + REQUIRE(scene->add(SceneEffect::Fill, 255, 0, 0, 128) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(scene->add(SceneEffect::Clear) == Result::Success); + REQUIRE(scene->add(SceneEffect::Tint, 0, 0, 0, 255, 255, 255, 50.0) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(scene->add(SceneEffect::Clear) == Result::Success); + REQUIRE(scene->add(SceneEffect::Tritone, 0, 0, 0, 128, 128, 128, 255, 255, 255, 128) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(scene->add(SceneEffect::GaussianBlur, 1.5, 0, 0, 75) == Result::Success); + REQUIRE(scene->add(SceneEffect::DropShadow, 128, 128, 128, 200, 45.0, 5.0, 2.0, 60) == Result::Success); + + REQUIRE(canvas->add(scene->duplicate()) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} \ No newline at end of file diff --git a/components/thorvg-main/test/testShape.cpp b/components/thorvg-main/test/testShape.cpp new file mode 100644 index 0000000..5e61db1 --- /dev/null +++ b/components/thorvg-main/test/testShape.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +TEST_CASE("Shape Creation", "[tvgShape]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->type() == Type::Shape); + + Paint::rel(shape); +} + +TEST_CASE("Appending Commands", "[tvgShape]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->close() == Result::Success); + + REQUIRE(shape->moveTo(100, 100) == Result::Success); + REQUIRE(shape->moveTo(99999999.0f, -99999999.0f) == Result::Success); + REQUIRE(shape->moveTo(0, 0) == Result::Success); + + REQUIRE(shape->lineTo(120, 140) == Result::Success); + REQUIRE(shape->lineTo(99999999.0f, -99999999.0f) == Result::Success); + REQUIRE(shape->lineTo(0, 0) == Result::Success); + + REQUIRE(shape->cubicTo(0, 0, 0, 0, 0, 0) == Result::Success); + REQUIRE(shape->cubicTo(0, 0, 99999999.0f, -99999999.0f, 0, 0) == Result::Success); + REQUIRE(shape->cubicTo(0, 0, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success); + REQUIRE(shape->cubicTo(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f) == Result::Success); + + REQUIRE(shape->close() == Result::Success); + + REQUIRE(shape->reset() == Result::Success); + REQUIRE(shape->reset() == Result::Success); + + Paint::rel(shape); +} + +TEST_CASE("Appending Shapes", "[tvgShape]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + REQUIRE(shape->moveTo(100, 100) == Result::Success); + REQUIRE(shape->lineTo(120, 140) == Result::Success); + + REQUIRE(shape->appendRect(0, 0, 0, 0, 0, 0) == Result::Success); + REQUIRE(shape->appendRect(0, 0,99999999.0f, -99999999.0f, 0, 0, true) == Result::Success); + REQUIRE(shape->appendRect(0, 0, 0, 0, -99999999.0f, 99999999.0f, false) == Result::Success); + REQUIRE(shape->appendRect(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, true) == Result::Success); + REQUIRE(shape->appendRect(99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -99999999.0f, false) == Result::Success); + + REQUIRE(shape->appendCircle(0, 0, 0, 0) == Result::Success); + REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, 0, 0, true) == Result::Success); + REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, false) == Result::Success); + + Paint::rel(shape); +} + +TEST_CASE("Appending Paths", "[tvgShape]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + //Negative cases + REQUIRE(shape->appendPath(nullptr, 0, nullptr, 0) == Result::InvalidArguments); + REQUIRE(shape->appendPath(nullptr, 100, nullptr, 0) == Result::InvalidArguments); + REQUIRE(shape->appendPath(nullptr, 0, nullptr, 100) == Result::InvalidArguments); + + PathCommand cmds[5] = { + PathCommand::Close, + PathCommand::MoveTo, + PathCommand::LineTo, + PathCommand::CubicTo, + PathCommand::Close + }; + + Point pts[5] = { + {100, 100}, + {200, 200}, + {10, 10}, + {20, 20}, + {30, 30} + }; + + REQUIRE(shape->appendPath(cmds, 0, pts, 5) == Result::InvalidArguments); + REQUIRE(shape->appendPath(cmds, 5, pts, 0) == Result::InvalidArguments); + REQUIRE(shape->appendPath(cmds, 5, pts, 5) == Result::Success); + + const PathCommand* cmds2; + const Point* pts2; + uint32_t cmds2Cnt, pts2Cnt; + REQUIRE(shape->path(&cmds2, &cmds2Cnt, &pts2, &pts2Cnt) == Result::Success); + REQUIRE(cmds2Cnt == 5); + REQUIRE(pts2Cnt == 5); + + for (int i = 0; i < 5; ++i) { + REQUIRE(cmds2[i] == cmds[i]); + REQUIRE(pts[i].x == pts2[i].x); + REQUIRE(pts[i].y == pts2[i].y); + } + + shape->reset(); + REQUIRE(shape->path(nullptr, &cmds2Cnt, nullptr, &pts2Cnt) == Result::Success); + REQUIRE(cmds2Cnt == 0); + REQUIRE(pts2Cnt == 0); + + Paint::rel(shape); +} + +TEST_CASE("Stroking", "[tvgShape]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + //Stroke Order Before Stroke Setting + REQUIRE(shape->order(true) == Result::Success); + REQUIRE(shape->order(false) == Result::Success); + + //Stroke Width + REQUIRE(shape->strokeWidth(0) == Result::Success); + REQUIRE(shape->strokeWidth() == 0); + REQUIRE(shape->strokeWidth(300) == Result::Success); + REQUIRE(shape->strokeWidth() == 300); + + //Stroke Color + uint8_t r, g, b, a; + REQUIRE(shape->strokeFill(0, 50, 100, 200) == Result::Success); + REQUIRE(shape->strokeFill(nullptr, nullptr, &b, nullptr) == Result::Success); + REQUIRE(b == 100); + REQUIRE(shape->strokeFill(&r, &g, &b, &a) == Result::Success); + REQUIRE(r == 0); + REQUIRE(g == 50); + REQUIRE(b == 100); + REQUIRE(a == 200); + REQUIRE(shape->strokeFill(nullptr, nullptr, nullptr, nullptr) == Result::Success); + + //Stroke Dash + REQUIRE(shape->strokeDash(nullptr, 3) == Result::InvalidArguments); + + float dashPattern0[3] = {-10.0f, 1.5f, 2.22f}; + REQUIRE(shape->strokeDash(dashPattern0, 0) == Result::InvalidArguments); + REQUIRE(shape->strokeDash(dashPattern0, 3) == Result::Success); + + float dashPattern1[2] = {0.0f, 0.0f}; + REQUIRE(shape->strokeDash(dashPattern1, 2) == Result::Success); + + float dashPattern2[1] = {10.0f}; + REQUIRE(shape->strokeDash(dashPattern2, 1) == Result::Success); + + float dashPattern3[3] = {1.0f, 1.5f, 2.22f}; + REQUIRE(shape->strokeDash(dashPattern3, 3) == Result::Success); + REQUIRE(shape->strokeDash(dashPattern3, 3, 4.5) == Result::Success); + + const float* dashPattern4; + float offset; + REQUIRE(shape->strokeDash(nullptr) == 3); + REQUIRE(shape->strokeDash(&dashPattern4) == 3); + REQUIRE(shape->strokeDash(&dashPattern4, &offset) == 3); + REQUIRE(dashPattern4[0] == 1.0f); + REQUIRE(dashPattern4[1] == 1.5f); + REQUIRE(dashPattern4[2] == 2.22f); + REQUIRE(offset == 4.5f); + + REQUIRE(shape->strokeDash(nullptr, 0) == Result::Success); + + //Stroke Cap + REQUIRE(shape->strokeCap() == StrokeCap::Square); + REQUIRE(shape->strokeCap(StrokeCap::Round) == Result::Success); + REQUIRE(shape->strokeCap(StrokeCap::Butt) == Result::Success); + REQUIRE(shape->strokeCap() == StrokeCap::Butt); + + //Stroke Join + REQUIRE(shape->strokeJoin() == StrokeJoin::Bevel); + REQUIRE(shape->strokeJoin(StrokeJoin::Miter) == Result::Success); + REQUIRE(shape->strokeJoin(StrokeJoin::Round) == Result::Success); + REQUIRE(shape->strokeJoin() == StrokeJoin::Round); + + //Stroke Miterlimit + REQUIRE(shape->strokeMiterlimit() == 4.0f); + REQUIRE(shape->strokeMiterlimit(0.00001f) == Result::Success); + REQUIRE(shape->strokeMiterlimit() == 0.00001f); + REQUIRE(shape->strokeMiterlimit(1000.0f) == Result::Success); + REQUIRE(shape->strokeMiterlimit() == 1000.0f); + REQUIRE(shape->strokeMiterlimit(-0.001f) == Result::InvalidArguments); + + REQUIRE(shape->trimpath(0.3f, 0.88f, false) == Result::Success); + + //Stroke Order After Stroke Setting + REQUIRE(shape->order(true) == Result::Success); + REQUIRE(shape->order(false) == Result::Success); + + Paint::rel(shape); +} + +TEST_CASE("Shape Filling", "[tvgShape]") +{ + auto shape = Shape::gen(); + REQUIRE(shape); + + //Fill Color + uint8_t r, g, b, a; + REQUIRE(shape->fill(255, 100, 50, 5) == Result::Success); + REQUIRE(shape->fill(&r, nullptr, &b, nullptr) == Result::Success); + REQUIRE(r == 255); + REQUIRE(b == 50); + REQUIRE(shape->fill(&r, &g, &b, &a) == Result::Success); + REQUIRE(g == 100); + REQUIRE(a == 5); + + //Fill Rule + REQUIRE(shape->fillRule() == FillRule::NonZero); + REQUIRE(shape->fillRule(FillRule::EvenOdd) == Result::Success); + REQUIRE(shape->fillRule() == FillRule::EvenOdd); + + Paint::rel(shape); +} diff --git a/components/thorvg-main/test/testSwCanvas.cpp b/components/thorvg-main/test/testSwCanvas.cpp new file mode 100644 index 0000000..d594142 --- /dev/null +++ b/components/thorvg-main/test/testSwCanvas.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +#ifdef THORVG_SW_RASTER_SUPPORT + +TEST_CASE("Missing Initialization", "[tvgSwCanvas]") +{ + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas == nullptr); +} + +TEST_CASE("Basic Creation", "[tvgSwCanvas]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + auto canvas2 = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas2); + + auto canvas3 = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas3); + } + + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Target Buffer", "[tvgSwCanvas]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + REQUIRE(canvas->target(nullptr, 100, 100, 100, ColorSpace::ARGB8888) == Result::InvalidArguments); + REQUIRE(canvas->target(buffer, 0, 100, 100, ColorSpace::ARGB8888) == Result::InvalidArguments); + REQUIRE(canvas->target(buffer, 100, 0, 100, ColorSpace::ARGB8888) == Result::InvalidArguments); + REQUIRE(canvas->target(buffer, 100, 200, 100, ColorSpace::ARGB8888) == Result::InvalidArguments); + REQUIRE(canvas->target(buffer, 100, 100, 0, ColorSpace::ARGB8888) == Result::InvalidArguments); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Pushing Paints", "[tvgSwCanvas]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + //Try all types of paints. + REQUIRE(canvas->add(Shape::gen()) == Result::Success); + REQUIRE(canvas->add(Picture::gen()) == Result::Success); + REQUIRE(canvas->add(Scene::gen()) == Result::Success); + + //Cases by contexts. + REQUIRE(canvas->update() == Result::Success); + + REQUIRE(canvas->add(Shape::gen()) == Result::Success); + REQUIRE(canvas->add(Shape::gen()) == Result::Success); + + REQUIRE(canvas->remove() == Result::Success); + + Paint* paints[2]; + + paints[0] = Shape::gen(); + REQUIRE(canvas->add(paints[0]) == Result::Success); + + //Negative case 1 + REQUIRE(canvas->add(nullptr) == Result::InvalidArguments); + + paints[1] = Shape::gen(); + REQUIRE(canvas->add(paints[1]) == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + + //Check list of paints + auto list = canvas->paints(); + REQUIRE(list.size() == 2); + int idx = 0; + for (auto paint : list) { + REQUIRE(paints[idx] == paint); + ++idx; + } + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Update", "[tvgSwCanvas]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + REQUIRE(canvas->update() == Result::Success); + + REQUIRE(canvas->add(Shape::gen()) == Result::Success); + + //No added shape + auto shape = Shape::gen(); + + //Normal case + REQUIRE(canvas->add(shape) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->update() == Result::InsufficientCondition); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(canvas->update() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Synchronized Drawing", "[tvgSwCanvas]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + REQUIRE(canvas->sync() == Result::Success); + REQUIRE(canvas->draw() == Result::InsufficientCondition); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + //Invalid Shape + auto shape = Shape::gen(); + REQUIRE(shape); + REQUIRE(canvas->add(shape) == Result::Success); + + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + auto shape2 = Shape::gen(); + REQUIRE(shape2); + REQUIRE(shape2->appendRect(0, 0, 100, 100) == Result::Success); + REQUIRE(shape2->fill(255, 255, 255, 255) == Result::Success); + + REQUIRE(canvas->add(shape2) == Result::Success); + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Asynchronous Drawing", "[tvgSwCanvas]") +{ + //Use multi-threading + REQUIRE(Initializer::init(2) == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + for (int i = 0; i < 3; ++i) { + auto shape = Shape::gen(); + REQUIRE(shape); + REQUIRE(shape->appendRect(0, 0, 100, 100) == Result::Success); + REQUIRE(shape->fill(255, 255, 255, 255) == Result::Success); + REQUIRE(canvas->add(shape) == Result::Success); + } + + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Viewport", "[tvgSwCanvas]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + REQUIRE(canvas->viewport(25, 25, 100, 100) == Result::Success); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + REQUIRE(canvas->viewport(25, 25, 50, 50) == Result::Success); + + auto shape = Shape::gen(); + REQUIRE(shape); + REQUIRE(shape->appendRect(0, 0, 100, 100) == Result::Success); + REQUIRE(shape->fill(255, 255, 255, 255) == Result::Success); + + REQUIRE(canvas->add(shape) == Result::Success); + + //Negative, not allowed + REQUIRE(canvas->viewport(15, 25, 5, 5) == Result::InsufficientCondition); + + REQUIRE(canvas->draw() == Result::Success); + + //Negative, not allowed + REQUIRE(canvas->viewport(25, 25, 10, 10) == Result::InsufficientCondition); + + REQUIRE(canvas->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} +#endif \ No newline at end of file diff --git a/components/thorvg-main/test/testSwEngine.cpp b/components/thorvg-main/test/testSwEngine.cpp new file mode 100644 index 0000000..e76047a --- /dev/null +++ b/components/thorvg-main/test/testSwEngine.cpp @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +#ifdef THORVG_SW_RASTER_SUPPORT + +TEST_CASE("Basic draw", "[tvgSwEngine]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888S) == Result::Success); + + std::vector masks; + masks.push_back(MaskMethod::None); + masks.push_back(MaskMethod::Alpha); + masks.push_back(MaskMethod::InvAlpha); + masks.push_back(MaskMethod::Luma); + masks.push_back(MaskMethod::InvLuma); + masks.push_back(MaskMethod::Add); + masks.push_back(MaskMethod::Subtract); + masks.push_back(MaskMethod::Intersect); + masks.push_back(MaskMethod::Difference); + masks.push_back(MaskMethod::Lighten); + masks.push_back(MaskMethod::Darken); + + std::vector methods; + methods.push_back(BlendMethod::Normal); + methods.push_back(BlendMethod::Multiply); + methods.push_back(BlendMethod::Screen); + methods.push_back(BlendMethod::Overlay); + methods.push_back(BlendMethod::Darken); + methods.push_back(BlendMethod::Lighten); + methods.push_back(BlendMethod::ColorDodge); + methods.push_back(BlendMethod::ColorBurn); + methods.push_back(BlendMethod::HardLight); + methods.push_back(BlendMethod::SoftLight); + methods.push_back(BlendMethod::Difference); + methods.push_back(BlendMethod::Hue); + methods.push_back(BlendMethod::Saturation); + methods.push_back(BlendMethod::Color); + methods.push_back(BlendMethod::Luminosity); + methods.push_back(BlendMethod::Add); + methods.push_back(BlendMethod::Composition); + + auto mask = []() { + auto mask = Shape::gen(); + mask->appendRect(0, 10, 20, 30, 5, 5); + mask->opacity(127); + mask->fill(255, 255, 255); + return mask; + }; + + for (auto method : methods) { + for (auto maskOp : masks) { + //Arc Line + auto shape1 = Shape::gen(); + REQUIRE(shape1->strokeFill(255, 255, 255, 255) == Result::Success); + REQUIRE(shape1->strokeWidth(2) == Result::Success); + REQUIRE(shape1->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(shape1->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(shape1) == Result::Success); + + //Cubic + auto shape2 = Shape::gen(); + REQUIRE(shape2->moveTo(50, 25) == Result::Success); + REQUIRE(shape2->cubicTo(62, 25, 75, 38, 75, 50) == Result::Success); + REQUIRE(shape2->close() == Result::Success); + REQUIRE(shape2->strokeFill(255, 0, 0, 125) == Result::Success); + REQUIRE(shape2->strokeWidth(1) == Result::Success); + REQUIRE(shape2->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(shape2->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(shape2) == Result::Success); + + //Fill + auto shape3 = Shape::gen(); + REQUIRE(shape3->moveTo(0, 0) == Result::Success); + REQUIRE(shape3->lineTo(20, 0) == Result::Success); + REQUIRE(shape3->lineTo(20, 20) == Result::Success); + REQUIRE(shape3->lineTo(0, 20) == Result::Success); + REQUIRE(shape3->close() == Result::Success); + REQUIRE(shape3->fill(255, 255, 255) == Result::Success); + REQUIRE(shape3->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(shape3->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(shape3) == Result::Success); + + //Dashed Line shape + auto shape4 = Shape::gen(); + float dashPattern[2] = {2.5f, 5.0f}; + REQUIRE(shape4->moveTo(0, 0) == Result::Success); + REQUIRE(shape4->lineTo(25, 25) == Result::Success); + REQUIRE(shape4->cubicTo(50, 50, 75, -75, 50, 100) == Result::Success); + REQUIRE(shape4->close() == Result::Success); + REQUIRE(shape4->fill(255, 255, 255) == Result::Success); + REQUIRE(shape4->strokeFill(255, 0, 0, 255) == Result::Success); + REQUIRE(shape4->strokeWidth(2) == Result::Success); + REQUIRE(shape4->strokeDash(dashPattern, 2) == Result::Success); + REQUIRE(shape4->strokeCap(StrokeCap::Round) == Result::Success); + REQUIRE(shape4->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(shape4->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(shape4) == Result::Success); + } + } + REQUIRE(canvas->draw(true) == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Image Draw", "[tvgSwEngine]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + //raw image + ifstream file(TEST_DIR"/rawimage_200x300.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 200 * 300); + file.close(); + + std::vector masks; + masks.push_back(MaskMethod::None); + masks.push_back(MaskMethod::Alpha); + masks.push_back(MaskMethod::InvAlpha); + masks.push_back(MaskMethod::Luma); + masks.push_back(MaskMethod::InvLuma); + masks.push_back(MaskMethod::Add); + masks.push_back(MaskMethod::Subtract); + masks.push_back(MaskMethod::Intersect); + masks.push_back(MaskMethod::Difference); + masks.push_back(MaskMethod::Lighten); + masks.push_back(MaskMethod::Darken); + + std::vector methods; + methods.push_back(BlendMethod::Normal); + methods.push_back(BlendMethod::Multiply); + methods.push_back(BlendMethod::Screen); + methods.push_back(BlendMethod::Overlay); + methods.push_back(BlendMethod::Darken); + methods.push_back(BlendMethod::Lighten); + methods.push_back(BlendMethod::ColorDodge); + methods.push_back(BlendMethod::ColorBurn); + methods.push_back(BlendMethod::HardLight); + methods.push_back(BlendMethod::SoftLight); + methods.push_back(BlendMethod::Difference); + methods.push_back(BlendMethod::Hue); + methods.push_back(BlendMethod::Saturation); + methods.push_back(BlendMethod::Color); + methods.push_back(BlendMethod::Luminosity); + methods.push_back(BlendMethod::Add); + methods.push_back(BlendMethod::Composition); + + auto mask = []() { + auto mask = Shape::gen(); + mask->appendRect(0, 10, 20, 30, 5, 5); + mask->fill(255, 255, 255); + return mask; + }; + + for (auto method : methods) { + for (auto maskOp : masks) { + //Non-transformed images + auto picture = Picture::gen(); + REQUIRE(picture->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + REQUIRE(picture->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(picture->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(picture) == Result::Success); + + //Clipped images + auto picture2 = picture->duplicate(); + REQUIRE(picture2->clip(mask()) == Result::Success); + REQUIRE(canvas->add(picture2) == Result::Success); + + // Transformed images + auto picture3 = picture->duplicate(); + REQUIRE(picture3->rotate(45) == Result::Success); + REQUIRE(canvas->add(picture3) == Result::Success); + + //Up-scaled Image + auto picture4 = picture->duplicate(); + REQUIRE(picture4->scale(2.0f) == Result::Success); + REQUIRE(canvas->add(picture4) == Result::Success); + + //Down-scaled Image + auto picture5 = picture->duplicate(); + REQUIRE(picture5->scale(0.25f) == Result::Success); + REQUIRE(canvas->add(picture5) == Result::Success); + + //Direct Clipped image + auto picture6 = Picture::gen(); + REQUIRE(picture6->load(data, 200, 300, ColorSpace::ARGB8888, false) == Result::Success); + REQUIRE(picture6->clip(mask()) == Result::Success); + REQUIRE(picture6->blend(method) == Result::Success); + REQUIRE(canvas->add(picture6) == Result::Success); + + //Scaled Clipped image + auto picture7 = picture6->duplicate(); + REQUIRE(picture7->scale(2.0f) == Result::Success); + REQUIRE(canvas->add(picture7) == Result::Success); + } + } + + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + free(data); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Filling Draw", "[tvgSwEngine]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + uint32_t buffer[100*100]; + REQUIRE(canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888) == Result::Success); + + std::vector masks; + masks.push_back(MaskMethod::None); + masks.push_back(MaskMethod::Alpha); + masks.push_back(MaskMethod::InvAlpha); + masks.push_back(MaskMethod::Luma); + masks.push_back(MaskMethod::InvLuma); + masks.push_back(MaskMethod::Add); + masks.push_back(MaskMethod::Subtract); + masks.push_back(MaskMethod::Intersect); + masks.push_back(MaskMethod::Difference); + masks.push_back(MaskMethod::Lighten); + masks.push_back(MaskMethod::Darken); + + std::vector methods; + methods.push_back(BlendMethod::Normal); + methods.push_back(BlendMethod::Multiply); + methods.push_back(BlendMethod::Screen); + methods.push_back(BlendMethod::Overlay); + methods.push_back(BlendMethod::Darken); + methods.push_back(BlendMethod::Lighten); + methods.push_back(BlendMethod::ColorDodge); + methods.push_back(BlendMethod::ColorBurn); + methods.push_back(BlendMethod::HardLight); + methods.push_back(BlendMethod::SoftLight); + methods.push_back(BlendMethod::Difference); + methods.push_back(BlendMethod::Hue); + methods.push_back(BlendMethod::Saturation); + methods.push_back(BlendMethod::Color); + methods.push_back(BlendMethod::Luminosity); + methods.push_back(BlendMethod::Add); + methods.push_back(BlendMethod::Composition); + + auto mask = []() { + auto mask = Shape::gen(); + mask->appendRect(10, 10, 20, 30, 5, 5); + mask->opacity(127); + mask->fill(255, 255, 255); + return mask; + }; + + Fill::ColorStop cs[4] = { + {0.1f, 0, 0, 0, 0}, + {0.2f, 50, 25, 50, 25}, + {0.5f, 100, 100, 100, 125}, + {0.9f, 255, 255, 255, 255} + }; + + for (auto method : methods) { + for (auto maskOp : masks) { + //Linear Gradient + auto linear = LinearGradient::gen(); + REQUIRE(linear->colorStops(cs, 4) == Result::Success); + REQUIRE(linear->spread(FillSpread::Repeat) == Result::Success); + REQUIRE(linear->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success); + + auto shape = Shape::gen(); + REQUIRE(shape->appendRect(0, 0, 50, 50, 5, 5) == Result::Success); + REQUIRE(shape->fill(linear) == Result::Success); + REQUIRE(shape->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(shape->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(shape) == Result::Success); + + //Radial Gradient + auto radial = RadialGradient::gen(); + REQUIRE(radial->colorStops(cs, 4) == Result::Success); + REQUIRE(radial->spread(FillSpread::Pad) == Result::Success); + REQUIRE(radial->radial(50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 0.0f) == Result::Success); + + auto shape2 = Shape::gen(); + REQUIRE(shape2->appendRect(50, 0, 50, 50) == Result::Success); + REQUIRE(shape2->fill(radial) == Result::Success); + REQUIRE(shape2->blend(method) == Result::Success); + if (maskOp != MaskMethod::None) REQUIRE(shape2->mask(mask(), maskOp) == Result::Success); + REQUIRE(canvas->add(shape2) == Result::Success); + } + } + + REQUIRE(canvas->draw() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + REQUIRE(Initializer::term() == Result::Success); +} + +TEST_CASE("Image Rotation", "[tvgSwEngine]") +{ + REQUIRE(Initializer::init() == Result::Success); + { + auto canvas = unique_ptr(SwCanvas::gen()); + REQUIRE(canvas); + + const uint32_t cw = 960; + const uint32_t ch = 960; + vector buffer(static_cast(cw) * ch); + REQUIRE(canvas->target(buffer.data(), cw, ch, cw, ColorSpace::ARGB8888) == Result::Success); + + auto picture = Picture::gen(); + REQUIRE(picture); + + ifstream file(TEST_DIR"/rawimage_250x375.raw"); + if (!file.is_open()) return; + auto data = (uint32_t*)malloc(sizeof(uint32_t) * (250*375)); + file.read(reinterpret_cast(data), sizeof (uint32_t) * 250 * 375); + file.close(); + + REQUIRE(picture->load(data, 250, 375, ColorSpace::ARGB8888, false) == Result::Success); + + REQUIRE(picture->size(240, 240) == Result::Success); + REQUIRE(picture->transform({0.572866f, -4.431353f, 336.605835f, 5.198910f, -0.386219f, 30.710693f, 0.0f, 0.0f, 1.0f}) == Result::Success); + REQUIRE(canvas->add(picture) == Result::Success); + + REQUIRE(canvas->draw(true) == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + free(data); + } + REQUIRE(Initializer::term() == Result::Success); +} + +#endif \ No newline at end of file diff --git a/components/thorvg-main/test/testText.cpp b/components/thorvg-main/test/testText.cpp new file mode 100644 index 0000000..0ed2615 --- /dev/null +++ b/components/thorvg-main/test/testText.cpp @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2021 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +#ifdef THORVG_TTF_LOADER_SUPPORT + +TEST_CASE("Text Creation", "[tvgText]") +{ + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(text->type() == Type::Text); + + Paint::rel(text); +} + +TEST_CASE("Load TTF Data from a file", "[tvgText]") +{ + Initializer::init(); + { + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::unload(TEST_DIR"/invalid.ttf") == Result::InsufficientCondition); + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(Text::load(TEST_DIR"/invalid.ttf") == Result::InvalidArguments); + REQUIRE(Text::unload(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(Text::load("") == Result::InvalidArguments); + REQUIRE(Text::load(TEST_DIR"/NanumGothicCoding.ttf") == Result::Success); + + Paint::rel(text); + } + Initializer::term(); +} + +TEST_CASE("Load TTF Data from a memory", "[tvgText]") +{ + Initializer::init(); + { + ifstream file(TEST_DIR"/Arial.ttf", ios::binary); + REQUIRE(file.is_open()); + file.seekg(0, std::ios::end); + auto size = file.tellg(); + file.seekg(0, std::ios::beg); + auto data = (char*)malloc(size); + REQUIRE(data); + file.read(data, size); + file.close(); + + auto text = Text::gen(); + REQUIRE(text); + + static const char* svg = ""; + + //load + REQUIRE(Text::load(nullptr, data, size) == Result::InvalidArguments); + REQUIRE(Text::load("Arial", data, 0) == Result::InvalidArguments); + REQUIRE(Text::load("Arial", data, 0) == Result::InvalidArguments); + REQUIRE(Text::load("ArialSvg", svg, strlen(svg), "unknown") == Result::NonSupport); + REQUIRE(Text::load("ArialUnknown", data, size, "unknown") == Result::Success); + REQUIRE(Text::load("ArialTtf", data, size, "ttf", true) == Result::Success); + REQUIRE(Text::load("Arial", data, size, "") == Result::Success); + + //unload + REQUIRE(Text::load("invalid", nullptr, 0) == Result::InsufficientCondition); + REQUIRE(Text::load("ArialSvg", nullptr, 0) == Result::InsufficientCondition); + REQUIRE(Text::load("ArialUnknown", nullptr, 0) == Result::Success); + REQUIRE(Text::load("ArialTtf", nullptr, 0) == Result::Success); + REQUIRE(Text::load("Arial", nullptr, 111) == Result::Success); + + free(data); + + Paint::rel(text); + } + Initializer::term(); +} + +TEST_CASE("Text Font", "[tvgText]") +{ + Initializer::init(); + { + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(1) == Result::Success); + REQUIRE(text->size(50) == Result::Success); + REQUIRE(text->font(nullptr) == Result::Success); + REQUIRE(text->font("InvalidFont") == Result::InsufficientCondition); + + Paint::rel(text); + } + Initializer::term(); +} + +TEST_CASE("Text Basic", "[tvgText]") +{ + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->text(nullptr) == Result::Success); + REQUIRE(text->text("") == Result::Success); + REQUIRE(text->text("ABCDEFGHIJIKLMOPQRSTUVWXYZ") == Result::Success); + REQUIRE(text->text("THORVG Text") == Result::Success); + REQUIRE(text->fill(255, 255, 255) == Result::Success); + REQUIRE(canvas->add(text) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + Initializer::term(); +} + +TEST_CASE("Text with composite glyphs", "[tvgText]") +{ + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->text("\xc5\xbb\x6f\xc5\x82\xc4\x85\x64\xc5\xba \xc8\xab") == Result::Success); + REQUIRE(text->fill(255, 255, 255) == Result::Success); + REQUIRE(canvas->add(text) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + Initializer::term(); +} + +TEST_CASE("Text Styles", "[tvgText]") +{ + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->text("ThorVG Test\n Text!") == Result::Success); + REQUIRE(text->fill(255, 255, 255) == Result::Success); + + REQUIRE(text->outline(0, 0, 0, 0) == Result::Success); + REQUIRE(text->outline(3, 255, 255, 255) == Result::Success); + REQUIRE(text->outline(0, 0, 0, 0) == Result::Success); + + REQUIRE(text->italic(-10.0f) == Result::Success); + REQUIRE(text->italic(10000.0f) == Result::Success); + REQUIRE(text->italic(0.0) == Result::Success); + REQUIRE(text->italic(0.18f) == Result::Success); + + REQUIRE(canvas->add(text) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + } + Initializer::term(); +} + +TEST_CASE("Text Layout", "[tvgText]") +{ + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->fill(255, 255, 255) == Result::Success); + REQUIRE(text->text("ThorVG Test\n Text!") == Result::Success); + + REQUIRE(text->align(0.0f, 0.0f) == Result::Success); + REQUIRE(text->align(0.5f, 0.5f) == Result::Success); + REQUIRE(text->align(1.0f, 1.0f) == Result::Success); + REQUIRE(text->align(2.0f, 2.0f) == Result::Success); + REQUIRE(text->align(-1.0f, -1.0f) == Result::Success); + + REQUIRE(text->layout(0, 0) == Result::Success); + REQUIRE(text->layout(-100, -100) == Result::Success); + REQUIRE(text->layout(100, 100) == Result::Success); + + REQUIRE(canvas->add(text) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + Initializer::term(); +} + +TEST_CASE("Text Wrap Mode", "[tvgText]") +{ + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->fill(255, 255, 255) == Result::Success); + REQUIRE(text->align(0.5f, 0.5f) == Result::Success); + REQUIRE(text->text("Very Long Long Text ThorVG Test\n ABCDEFGHIJKLMNOPRSTU!") == Result::Success); + REQUIRE(text->layout(100, 100) == Result::Success); + REQUIRE(canvas->add(text) == Result::Success); + + REQUIRE(text->wrap(TextWrap::Character) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(text->wrap(TextWrap::Word) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(text->wrap(TextWrap::Smart) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + + REQUIRE(text->wrap(TextWrap::Ellipsis) == Result::Success); + REQUIRE(canvas->update() == Result::Success); + REQUIRE(canvas->sync() == Result::Success); + } + Initializer::term(); +} + +TEST_CASE("Text Spacing", "[tvgText]") +{ + Initializer::init(); + { + auto canvas = unique_ptr(SwCanvas::gen()); + uint32_t buffer[100*100]; + canvas->target(buffer, 100, 100, 100, ColorSpace::ARGB8888); + + auto text = Text::gen(); + REQUIRE(text); + + REQUIRE(Text::load(TEST_DIR"/Arial.ttf") == Result::Success); + REQUIRE(text->font("Arial") == Result::Success); + REQUIRE(text->size(80) == Result::Success); + REQUIRE(text->text("\xc5\xbb\x6f\xc5\x82\xc4\x85\x64\xc5\xba \xc8\xab") == Result::Success); + REQUIRE(text->spacing(-1.0f, -1.0f) == Result::InvalidArguments); + REQUIRE(text->spacing(0.0f, 0.0f) == Result::Success); + REQUIRE(text->spacing(1.5f, 1.5f) == Result::Success); + REQUIRE(text->spacing(2.0f, 2.0f) == Result::Success); + + REQUIRE(canvas->add(text) == Result::Success); + } + Initializer::term(); +} + +#endif \ No newline at end of file diff --git a/components/thorvg-main/tools/lottie2gif/lottie2gif.cpp b/components/thorvg-main/tools/lottie2gif/lottie2gif.cpp new file mode 100644 index 0000000..3417bb8 --- /dev/null +++ b/components/thorvg-main/tools/lottie2gif/lottie2gif.cpp @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2023 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include + #ifndef PATH_MAX + #define PATH_MAX MAX_PATH + #endif +#else + #include + #include + #include + #include +#endif + +using namespace std; +using namespace tvg; + + +struct App +{ +private: + char full[PATH_MAX]; //full path + uint32_t fps = 30; + uint32_t width = 600; + uint32_t height = 600; + uint8_t r, g, b; //background color + bool background = false; + + void helpMsg() + { + cout << "Usage: \n tvg-lottie2gif [Lottie file] or [Lottie folder] [-r resolution] [-f fps] [-b background color]\n\nExamples: \n $ tvg-lottie2gif input.json\n $ tvg-lottie2gif input.json -r 600x600\n $ tvg-lottie2gif input.json -f 30\n $ tvg-lottie2gif input.json -r 600x600 -f 30\n $ tvg-lottie2gif lottiefolder\n $ tvg-lottie2gif lottiefolder -r 600x600 -f 30 -b fa7410\n\n"; + } + + bool validate(string& lottieName) + { + string extn = ".json"; + + if (lottieName.size() <= extn.size() || lottieName.substr(lottieName.size() - extn.size()) != extn) { + cout << "Error: \"" << lottieName << "\" is invalid." << endl; + return false; + } + return true; + } + + bool convert(string& in, string& out) + { + if (Initializer::init() != Result::Success) return false; + { + auto animation = Animation::gen(); + auto picture = animation->picture(); + if (picture->load(in.c_str()) != Result::Success) return false; + + float width, height; + picture->size(&width, &height); + float scale = static_cast(this->width) / width; + picture->size(width * scale, height * scale); + + auto saver = unique_ptr(Saver::gen()); + + //set a background color + if (background) { + auto bg = Shape::gen(); + bg->fill(r, g, b); + bg->appendRect(0, 0, width * scale, height * scale); + saver->background(bg); + } + if (saver->save(animation, out.c_str(), 100, fps) != Result::Success) return false; + if (saver->sync() != Result::Success) return false; + } + return Initializer::term() == Result::Success; + } + + void convert(string& lottieName) + { + //Get gif file + auto gifName = lottieName; + gifName.replace(gifName.length() - 4, 4, "gif"); + + if (convert(lottieName, gifName)) { + cout << "Generated Gif file : " << gifName << endl; + } else { + cout << "Failed Converting Gif file : " << lottieName << endl; + } + } + + const char* realPath(const char* path) + { +#ifdef _WIN32 + return _fullpath(full, path, PATH_MAX); +#else + return realpath(path, full); +#endif + } + + bool isDirectory(const char* path) + { +#ifdef _WIN32 + DWORD attr = GetFileAttributes(path); + if (attr == INVALID_FILE_ATTRIBUTES) return false; + return attr & FILE_ATTRIBUTE_DIRECTORY; +#else + struct stat buf; + if (stat(path, &buf) != 0) return false; + return S_ISDIR(buf.st_mode); +#endif + } + + bool handleDirectory(const string& path) + { +#ifdef _WIN32 + //open directory + WIN32_FIND_DATA fd; + HANDLE h = FindFirstFileEx((path + "\\*").c_str(), FindExInfoBasic, &fd, FindExSearchNameMatch, NULL, 0); + if (h == INVALID_HANDLE_VALUE) { + cout << "Couldn't open directory \"" << path.c_str() << "\"." << endl; + return false; + } + //List directories + do { + if (*fd.cFileName == '.' || *fd.cFileName == '$') continue; + //sub directory + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + string subpath = string(path); + subpath += '\\'; + subpath += fd.cFileName; + if (!handleDirectory(subpath)) continue; + //file + } else { + string lottieName(fd.cFileName); + if (!validate(lottieName)) continue; + lottieName = string(path); + lottieName += '\\'; + lottieName += fd.cFileName; + convert(lottieName); + } + } while (FindNextFile(h, &fd)); + + FindClose(h); +#else + //open directory + auto dir = opendir(path.c_str()); + if (!dir) { + cout << "Couldn't open directory \"" << path.c_str() << "\"." << endl; + return false; + } + //List directories + while (auto entry = readdir(dir)) { + if (*entry->d_name == '.' || *entry->d_name == '$') continue; + //sub directory + if (entry->d_type == DT_DIR) { + string subpath = string(path); + subpath += '/'; + subpath += entry->d_name; + if (!handleDirectory(subpath)) continue; + //file + } else { + string svgName(entry->d_name); + if (!validate(svgName)) continue; + svgName = string(path); + svgName += '/'; + svgName += entry->d_name; + convert(svgName); + } + } +#endif + return true; + } + +public: + int setup(int argc, char** argv) + { + //Collect input files + vector inputs; + + for (int i = 1; i < argc; ++i) { + const char* p = argv[i]; + if (*p == '-') { + const char* p_arg = (i + 1 < argc) ? argv[++i] : nullptr; + + //image resolution + if (p[1] == 'r') { + if (!p_arg) { + cout << "Error: Missing resolution attribute. Expected eg. -r 600x600." << endl; + return 1; + } + + const char* x = strchr(p_arg, 'x'); + if (x) { + width = atoi(p_arg); + height = atoi(x + 1); + } + if (!x || width <= 0 || height <= 0) { + cout << "Error: Resolution (" << p_arg << ") is corrupted. Expected eg. -r 600x600." << endl; + return 1; + } + //fps + } else if (p[1] == 'f') { + if (!p_arg) { + cout << "Error: Missing fps value. Expected eg. -f 30." << endl; + return 1; + } + fps = atoi(p_arg); + } else if (p[1] == 'b') { + //background color + if (!p_arg) { + cout << "Error: Missing background color attribute. Expected eg. -b fa7410." << endl; + return 1; + } + auto bgColor = (uint32_t) strtol(p_arg, NULL, 16); + r = (uint8_t)((bgColor & 0xff0000) >> 16); + g = (uint8_t)((bgColor & 0x00ff00) >> 8); + b = (uint8_t)((bgColor & 0x0000ff)); + background = true; + } else { + cout << "Warning: Unknown flag (" << p << ")." << endl; + } + }else { + inputs.push_back(argv[i]); + } + } + + //No Input Lottie + if (inputs.empty()) { + helpMsg(); + return 0; + } + + for (auto input : inputs) { + + auto path = realPath(input); + if (!path) { + cout << "Invalid file or path name: \"" << input << "\"" << endl; + continue; + } + + if (isDirectory(path)) { + //load from directory + cout << "Directory: \"" << path << "\"" << endl; + if (!handleDirectory(path)) break; + } + else { + string lottieName(input); + if (!validate(lottieName)) continue; + convert(lottieName); + } + } + return 0; + } +}; + + +int main(int argc, char **argv) +{ + App app; + return app.setup(argc, argv); +} diff --git a/components/thorvg-main/tools/lottie2gif/meson.build b/components/thorvg-main/tools/lottie2gif/meson.build new file mode 100644 index 0000000..db5220d --- /dev/null +++ b/components/thorvg-main/tools/lottie2gif/meson.build @@ -0,0 +1,8 @@ +lottie2gif_src = files('lottie2gif.cpp') + +executable('tvg-lottie2gif', + lottie2gif_src, + include_directories : headers, + cpp_args : compiler_flags, + install : true, + link_with : thorvg_lib) diff --git a/components/thorvg-main/tools/meson.build b/components/thorvg-main/tools/meson.build new file mode 100644 index 0000000..ac84c40 --- /dev/null +++ b/components/thorvg-main/tools/meson.build @@ -0,0 +1,11 @@ +if lib_type == 'static' + compiler_flags += ['-DTVG_STATIC'] +endif + +if svg2png + subdir('svg2png') +endif + +if lottie2gif + subdir('lottie2gif') +endif diff --git a/components/thorvg-main/tools/svg2png/lodepng.cpp b/components/thorvg-main/tools/svg2png/lodepng.cpp new file mode 100644 index 0000000..3a29f6d --- /dev/null +++ b/components/thorvg-main/tools/svg2png/lodepng.cpp @@ -0,0 +1,6410 @@ +/* +LodePNG version 20200306 + +Copyright (c) 2005-2020 Lode Vandevenne + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + +/* +The manual and changelog are in the header file "lodepng.h" +Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for C. +*/ + +#include "lodepng.h" + +#ifdef LODEPNG_COMPILE_DISK +#include /* LONG_MAX */ +#include /* file handling */ +#endif /* LODEPNG_COMPILE_DISK */ + +#ifdef LODEPNG_COMPILE_ALLOCATORS +#include /* allocations */ +#endif /* LODEPNG_COMPILE_ALLOCATORS */ + +#if defined(_MSC_VER) && (_MSC_VER >= 1310) /*Visual Studio: A few warning types are not desired here.*/ +#pragma warning( disable : 4244 ) /*implicit conversions: not warned by gcc -Wall -Wextra and requires too much casts*/ +#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/ +#endif /*_MSC_VER */ + +const char* LODEPNG_VERSION_STRING = "20200306"; + +/* +This source file is built up in the following large parts. The code sections +with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way. +-Tools for C and common code for PNG and Zlib +-C Code for Zlib (huffman, deflate, ...) +-C Code for PNG (file format chunks, adam7, PNG filters, color conversions, ...) +-The C++ wrapper around all of the above +*/ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* // Tools for C, and common code for PNG and Zlib. // */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/*The malloc, realloc and free functions defined here with "lodepng_" in front +of the name, so that you can easily change them to others related to your +platform if needed. Everything else in the code calls these. Pass +-DLODEPNG_NO_COMPILE_ALLOCATORS to the compiler, or comment out +#define LODEPNG_COMPILE_ALLOCATORS in the header, to disable the ones here and +define them in your own project's source files without needing to change +lodepng source code. Don't forget to remove "static" if you copypaste them +from here.*/ + +#ifdef LODEPNG_COMPILE_ALLOCATORS +static void* lodepng_malloc(size_t size) { +#ifdef LODEPNG_MAX_ALLOC + if(size > LODEPNG_MAX_ALLOC) return 0; +#endif + return malloc(size); +} + +/* NOTE: when realloc returns NULL, it leaves the original memory untouched */ +static void* lodepng_realloc(void* ptr, size_t new_size) { +#ifdef LODEPNG_MAX_ALLOC + if(new_size > LODEPNG_MAX_ALLOC) return 0; +#endif + return realloc(ptr, new_size); +} + +static void lodepng_free(void* ptr) { + free(ptr); +} +#else /*LODEPNG_COMPILE_ALLOCATORS*/ +/* TODO: support giving additional void* payload to the custom allocators */ +void* lodepng_malloc(size_t size); +void* lodepng_realloc(void* ptr, size_t new_size); +void lodepng_free(void* ptr); +#endif /*LODEPNG_COMPILE_ALLOCATORS*/ + +/* convince the compiler to inline a function, for use when this measurably improves performance */ +/* inline is not available in C90, but use it when supported by the compiler */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined(__cplusplus) && (__cplusplus >= 199711L)) +#define LODEPNG_INLINE inline +#else +#define LODEPNG_INLINE /* not available */ +#endif + +/* restrict is not available in C90, but use it when supported by the compiler */ +#if (defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) ||\ + (defined(_MSC_VER) && (_MSC_VER >= 1400)) || \ + (defined(__WATCOMC__) && (__WATCOMC__ >= 1250) && !defined(__cplusplus)) +#define LODEPNG_RESTRICT __restrict +#else +#define LODEPNG_RESTRICT /* not available */ +#endif + +/* Replacements for C library functions such as memcpy and strlen, to support platforms +where a full C library is not available. The compiler can recognize them and compile +to something as fast. */ + +static void lodepng_memcpy(void* LODEPNG_RESTRICT dst, + const void* LODEPNG_RESTRICT src, size_t size) { + size_t i; + for(i = 0; i < size; i++) ((char*)dst)[i] = ((const char*)src)[i]; +} + +static void lodepng_memset(void* LODEPNG_RESTRICT dst, + int value, size_t num) { + size_t i; + for(i = 0; i < num; i++) ((char*)dst)[i] = (char)value; +} + +/* does not check memory out of bounds, do not use on untrusted data */ +static size_t lodepng_strlen(const char* a) { + const char* orig = a; + /* avoid warning about unused function in case of disabled COMPILE... macros */ + (void)(&lodepng_strlen); + while(*a) a++; + return (size_t)(a - orig); +} + +#define LODEPNG_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define LODEPNG_MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define LODEPNG_ABS(x) ((x) < 0 ? -(x) : (x)) + +#if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER) +/* Safely check if adding two integers will overflow (no undefined +behavior, compiler removing the code, etc...) and output result. */ +static int lodepng_addofl(size_t a, size_t b, size_t* result) { + *result = a + b; /* Unsigned addition is well defined and safe in C90 */ + return *result < a; +} +#endif /*defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)*/ + +#ifdef LODEPNG_COMPILE_DECODER +/* Safely check if multiplying two integers will overflow (no undefined +behavior, compiler removing the code, etc...) and output result. */ +static int lodepng_mulofl(size_t a, size_t b, size_t* result) { + *result = a * b; /* Unsigned multiplication is well defined and safe in C90 */ + return (a != 0 && *result / a != b); +} + +#ifdef LODEPNG_COMPILE_ZLIB +/* Safely check if a + b > c, even if overflow could happen. */ +static int lodepng_gtofl(size_t a, size_t b, size_t c) { + size_t d; + if(lodepng_addofl(a, b, &d)) return 1; + return d > c; +} +#endif /*LODEPNG_COMPILE_ZLIB*/ +#endif /*LODEPNG_COMPILE_DECODER*/ + + +/* +Often in case of an error a value is assigned to a variable and then it breaks +out of a loop (to go to the cleanup phase of a function). This macro does that. +It makes the error handling code shorter and more readable. + +Example: if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83); +*/ +#define CERROR_BREAK(errorvar, code){\ + errorvar = code;\ + break;\ +} + +/*version of CERROR_BREAK that assumes the common case where the error variable is named "error"*/ +#define ERROR_BREAK(code) CERROR_BREAK(error, code) + +/*Set error var to the error code, and return it.*/ +#define CERROR_RETURN_ERROR(errorvar, code){\ + errorvar = code;\ + return code;\ +} + +/*Try the code, if it returns error, also return the error.*/ +#define CERROR_TRY_RETURN(call){\ + unsigned error = call;\ + if(error) return error;\ +} + +/*Set error var to the error code, and return from the void function.*/ +#define CERROR_RETURN(errorvar, code){\ + errorvar = code;\ + return;\ +} + +/* +About uivector, ucvector and string: +-All of them wrap dynamic arrays or text strings in a similar way. +-LodePNG was originally written in C++. The vectors replace the std::vectors that were used in the C++ version. +-The string tools are made to avoid problems with compilers that declare things like strncat as deprecated. +-They're not used in the interface, only internally in this file as static functions. +-As with many other structs in this file, the init and cleanup functions serve as ctor and dtor. +*/ + +#ifdef LODEPNG_COMPILE_ZLIB +#ifdef LODEPNG_COMPILE_ENCODER +/*dynamic vector of unsigned ints*/ +typedef struct uivector { + unsigned* data; + size_t size; /*size in number of unsigned longs*/ + size_t allocsize; /*allocated size in bytes*/ +} uivector; + +static void uivector_cleanup(void* p) { + ((uivector*)p)->size = ((uivector*)p)->allocsize = 0; + lodepng_free(((uivector*)p)->data); + ((uivector*)p)->data = NULL; +} + +/*returns 1 if success, 0 if failure ==> nothing done*/ +static unsigned uivector_resize(uivector* p, size_t size) { + size_t allocsize = size * sizeof(unsigned); + if(allocsize > p->allocsize) { + size_t newsize = allocsize + (p->allocsize >> 1u); + void* data = lodepng_realloc(p->data, newsize); + if(data) { + p->allocsize = newsize; + p->data = (unsigned*)data; + } + else return 0; /*error: not enough memory*/ + } + p->size = size; + return 1; /*success*/ +} + +static void uivector_init(uivector* p) { + p->data = NULL; + p->size = p->allocsize = 0; +} + +/*returns 1 if success, 0 if failure ==> nothing done*/ +static unsigned uivector_push_back(uivector* p, unsigned c) { + if(!uivector_resize(p, p->size + 1)) return 0; + p->data[p->size - 1] = c; + return 1; +} +#endif /*LODEPNG_COMPILE_ENCODER*/ +#endif /*LODEPNG_COMPILE_ZLIB*/ + +/* /////////////////////////////////////////////////////////////////////////// */ + +/*dynamic vector of unsigned chars*/ +typedef struct ucvector { + unsigned char* data; + size_t size; /*used size*/ + size_t allocsize; /*allocated size*/ +} ucvector; + +/*returns 1 if success, 0 if failure ==> nothing done*/ +static unsigned ucvector_resize(ucvector* p, size_t size) { + if(size > p->allocsize) { + size_t newsize = size + (p->allocsize >> 1u); + void* data = lodepng_realloc(p->data, newsize); + if(data) { + p->allocsize = newsize; + p->data = (unsigned char*)data; + } + else return 0; /*error: not enough memory*/ + } + p->size = size; + return 1; /*success*/ +} + +static ucvector ucvector_init(unsigned char* buffer, size_t size) { + ucvector v; + v.data = buffer; + v.allocsize = v.size = size; + return v; +} + +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_PNG +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + +/*free string pointer and set it to NULL*/ +static void string_cleanup(char** out) { + lodepng_free(*out); + *out = NULL; +} + +static char* alloc_string_sized(const char* in, size_t insize) { + char* out = (char*)lodepng_malloc(insize + 1); + if(out) { + lodepng_memcpy(out, in, insize); + out[insize] = 0; + } + return out; +} + +/* dynamically allocates a new string with a copy of the null terminated input text */ +static char* alloc_string(const char* in) { + return alloc_string_sized(in, lodepng_strlen(in)); +} +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +#endif /*LODEPNG_COMPILE_PNG*/ + +/* ////////////////////////////////////////////////////////////////////////// */ + +#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG) +static unsigned lodepng_read32bitInt(const unsigned char* buffer) { + return (((unsigned)buffer[0] << 24u) | ((unsigned)buffer[1] << 16u) | + ((unsigned)buffer[2] << 8u) | (unsigned)buffer[3]); +} +#endif /*defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_PNG)*/ + +#if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER) +/*buffer must have at least 4 allocated bytes available*/ +static void lodepng_set32bitInt(unsigned char* buffer, unsigned value) { + buffer[0] = (unsigned char)((value >> 24) & 0xff); + buffer[1] = (unsigned char)((value >> 16) & 0xff); + buffer[2] = (unsigned char)((value >> 8) & 0xff); + buffer[3] = (unsigned char)((value ) & 0xff); +} +#endif /*defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_ENCODER)*/ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / File IO / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_DISK + +/* returns negative value on error. This should be pure C compatible, so no fstat. */ +static long lodepng_filesize(const char* filename) { + FILE* file; + long size; + file = fopen(filename, "rb"); + if(!file) return -1; + + if(fseek(file, 0, SEEK_END) != 0) { + fclose(file); + return -1; + } + + size = ftell(file); + /* It may give LONG_MAX as directory size, this is invalid for us. */ + if(size == LONG_MAX) size = -1; + + fclose(file); + return size; +} + +/* load file into buffer that already has the correct allocated size. Returns error code.*/ +static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) { + FILE* file; + size_t readsize; + file = fopen(filename, "rb"); + if(!file) return 78; + + readsize = fread(out, 1, size, file); + fclose(file); + + if(readsize != size) return 78; + return 0; +} + +unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) { + long size = lodepng_filesize(filename); + if(size < 0) return 78; + *outsize = (size_t)size; + + *out = (unsigned char*)lodepng_malloc((size_t)size); + if(!(*out) && size > 0) return 83; /*the above malloc failed*/ + + return lodepng_buffer_file(*out, (size_t)size, filename); +} + +/*write given buffer to the file, overwriting the file, it doesn't append to it.*/ +unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) { + FILE* file; + file = fopen(filename, "wb" ); + if(!file) return 79; + fwrite(buffer, 1, buffersize, file); + fclose(file); + return 0; +} + +#endif /*LODEPNG_COMPILE_DISK*/ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* // End of common code and tools. Begin of Zlib related code. // */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_ZLIB +#ifdef LODEPNG_COMPILE_ENCODER + +typedef struct { + ucvector* data; + unsigned char bp; /*ok to overflow, indicates bit pos inside byte*/ +} LodePNGBitWriter; + +static void LodePNGBitWriter_init(LodePNGBitWriter* writer, ucvector* data) { + writer->data = data; + writer->bp = 0; +} + +/*TODO: this ignores potential out of memory errors*/ +#define WRITEBIT(writer, bit){\ + /* append new byte */\ + if(((writer->bp) & 7u) == 0) {\ + if(!ucvector_resize(writer->data, writer->data->size + 1)) return;\ + writer->data->data[writer->data->size - 1] = 0;\ + }\ + (writer->data->data[writer->data->size - 1]) |= (bit << ((writer->bp) & 7u));\ + ++writer->bp;\ +} + +/* LSB of value is written first, and LSB of bytes is used first */ +static void writeBits(LodePNGBitWriter* writer, unsigned value, size_t nbits) { + if(nbits == 1) { /* compiler should statically compile this case if nbits == 1 */ + WRITEBIT(writer, value); + } else { + /* TODO: increase output size only once here rather than in each WRITEBIT */ + size_t i; + for(i = 0; i != nbits; ++i) { + WRITEBIT(writer, (unsigned char)((value >> i) & 1)); + } + } +} + +/* This one is to use for adding huffman symbol, the value bits are written MSB first */ +static void writeBitsReversed(LodePNGBitWriter* writer, unsigned value, size_t nbits) { + size_t i; + for(i = 0; i != nbits; ++i) { + /* TODO: increase output size only once here rather than in each WRITEBIT */ + WRITEBIT(writer, (unsigned char)((value >> (nbits - 1u - i)) & 1u)); + } +} +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_DECODER + +typedef struct { + const unsigned char* data; + size_t size; /*size of data in bytes*/ + size_t bitsize; /*size of data in bits, end of valid bp values, should be 8*size*/ + size_t bp; + unsigned buffer; /*buffer for reading bits. NOTE: 'unsigned' must support at least 32 bits*/ +} LodePNGBitReader; + +/* data size argument is in bytes. Returns error if size too large causing overflow */ +static unsigned LodePNGBitReader_init(LodePNGBitReader* reader, const unsigned char* data, size_t size) { + size_t temp; + reader->data = data; + reader->size = size; + /* size in bits, return error if overflow (if size_t is 32 bit this supports up to 500MB) */ + if(lodepng_mulofl(size, 8u, &reader->bitsize)) return 105; + /*ensure incremented bp can be compared to bitsize without overflow even when it would be incremented 32 too much and + trying to ensure 32 more bits*/ + if(lodepng_addofl(reader->bitsize, 64u, &temp)) return 105; + reader->bp = 0; + reader->buffer = 0; + return 0; /*ok*/ +} + +/* +ensureBits functions: +Ensures the reader can at least read nbits bits in one or more readBits calls, +safely even if not enough bits are available. +Returns 1 if there are enough bits available, 0 if not. +*/ + +/*See ensureBits documentation above. This one ensures exactly 1 bit */ +/*static unsigned ensureBits1(LodePNGBitReader* reader) { + if(reader->bp >= reader->bitsize) return 0; + reader->buffer = (unsigned)reader->data[reader->bp >> 3u] >> (reader->bp & 7u); + return 1; +}*/ + +/*See ensureBits documentation above. This one ensures up to 9 bits */ +static unsigned ensureBits9(LodePNGBitReader* reader, size_t nbits) { + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if(start + 1u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u); + reader->buffer >>= (reader->bp & 7u); + return 1; + } else { + reader->buffer = 0; + if(start + 0u < size) reader->buffer |= reader->data[start + 0]; + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + +/*See ensureBits documentation above. This one ensures up to 17 bits */ +static unsigned ensureBits17(LodePNGBitReader* reader, size_t nbits) { + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if(start + 2u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | + ((unsigned)reader->data[start + 2] << 16u); + reader->buffer >>= (reader->bp & 7u); + return 1; + } else { + reader->buffer = 0; + if(start + 0u < size) reader->buffer |= reader->data[start + 0]; + if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + +/*See ensureBits documentation above. This one ensures up to 25 bits */ +static LODEPNG_INLINE unsigned ensureBits25(LodePNGBitReader* reader, size_t nbits) { + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if(start + 3u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | + ((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u); + reader->buffer >>= (reader->bp & 7u); + return 1; + } else { + reader->buffer = 0; + if(start + 0u < size) reader->buffer |= reader->data[start + 0]; + if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); + if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + +/*See ensureBits documentation above. This one ensures up to 32 bits */ +static LODEPNG_INLINE unsigned ensureBits32(LodePNGBitReader* reader, size_t nbits) { + size_t start = reader->bp >> 3u; + size_t size = reader->size; + if(start + 4u < size) { + reader->buffer = (unsigned)reader->data[start + 0] | ((unsigned)reader->data[start + 1] << 8u) | + ((unsigned)reader->data[start + 2] << 16u) | ((unsigned)reader->data[start + 3] << 24u); + reader->buffer >>= (reader->bp & 7u); + reader->buffer |= (((unsigned)reader->data[start + 4] << 24u) << (8u - (reader->bp & 7u))); + return 1; + } else { + reader->buffer = 0; + if(start + 0u < size) reader->buffer |= reader->data[start + 0]; + if(start + 1u < size) reader->buffer |= ((unsigned)reader->data[start + 1] << 8u); + if(start + 2u < size) reader->buffer |= ((unsigned)reader->data[start + 2] << 16u); + if(start + 3u < size) reader->buffer |= ((unsigned)reader->data[start + 3] << 24u); + reader->buffer >>= (reader->bp & 7u); + return reader->bp + nbits <= reader->bitsize; + } +} + +/* Get bits without advancing the bit pointer. Must have enough bits available with ensureBits. Max nbits is 31. */ +static unsigned peekBits(LodePNGBitReader* reader, size_t nbits) { + /* The shift allows nbits to be only up to 31. */ + return reader->buffer & ((1u << nbits) - 1u); +} + +/* Must have enough bits available with ensureBits */ +static void advanceBits(LodePNGBitReader* reader, size_t nbits) { + reader->buffer >>= nbits; + reader->bp += nbits; +} + +/* Must have enough bits available with ensureBits */ +static unsigned readBits(LodePNGBitReader* reader, size_t nbits) { + unsigned result = peekBits(reader, nbits); + advanceBits(reader, nbits); + return result; +} + +/* Public for testing only. steps and result must have numsteps values. */ +unsigned lode_png_test_bitreader(const unsigned char* data, size_t size, + size_t numsteps, const size_t* steps, unsigned* result) { + size_t i; + LodePNGBitReader reader; + unsigned error = LodePNGBitReader_init(&reader, data, size); + if(error) return 0; + for(i = 0; i < numsteps; i++) { + size_t step = steps[i]; + unsigned ok; + if(step > 25) ok = ensureBits32(&reader, step); + else if(step > 17) ok = ensureBits25(&reader, step); + else if(step > 9) ok = ensureBits17(&reader, step); + else ok = ensureBits9(&reader, step); + if(!ok) return 0; + result[i] = readBits(&reader, step); + } + return 1; +} +#endif /*LODEPNG_COMPILE_DECODER*/ + +static unsigned reverseBits(unsigned bits, unsigned num) { + /*TODO: implement faster lookup table based version when needed*/ + unsigned i, result = 0; + for(i = 0; i < num; i++) result |= ((bits >> (num - i - 1u)) & 1u) << i; + return result; +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Deflate - Huffman / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#define FIRST_LENGTH_CODE_INDEX 257 +#define LAST_LENGTH_CODE_INDEX 285 +/*256 literals, the end code, some length codes, and 2 unused codes*/ +#define NUM_DEFLATE_CODE_SYMBOLS 288 +/*the distance codes have their own symbols, 30 used, 2 unused*/ +#define NUM_DISTANCE_SYMBOLS 32 +/*the code length codes. 0-15: code lengths, 16: copy previous 3-6 times, 17: 3-10 zeros, 18: 11-138 zeros*/ +#define NUM_CODE_LENGTH_CODES 19 + +/*the base lengths represented by codes 257-285*/ +static const unsigned LENGTHBASE[29] + = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, + 67, 83, 99, 115, 131, 163, 195, 227, 258}; + +/*the extra bits used by codes 257-285 (added to base length)*/ +static const unsigned LENGTHEXTRA[29] + = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 5, 5, 5, 5, 0}; + +/*the base backwards distances (the bits of distance codes appear after length codes and use their own huffman tree)*/ +static const unsigned DISTANCEBASE[30] + = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, + 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; + +/*the extra bits of backwards distances (added to base)*/ +static const unsigned DISTANCEEXTRA[30] + = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, + 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; + +/*the order in which "code length alphabet code lengths" are stored as specified by deflate, out of this the huffman +tree of the dynamic huffman tree lengths is generated*/ +static const unsigned CLCL_ORDER[NUM_CODE_LENGTH_CODES] + = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + +/* ////////////////////////////////////////////////////////////////////////// */ + +/* +Huffman tree struct, containing multiple representations of the tree +*/ +typedef struct HuffmanTree { + unsigned* codes; /*the huffman codes (bit patterns representing the symbols)*/ + unsigned* lengths; /*the lengths of the huffman codes*/ + unsigned maxbitlen; /*maximum number of bits a single code can get*/ + unsigned numcodes; /*number of symbols in the alphabet = number of codes*/ + /* for reading only */ + unsigned char* table_len; /*length of symbol from lookup table, or max length if secondary lookup needed*/ + unsigned short* table_value; /*value of symbol from lookup table, or pointer to secondary table if needed*/ +} HuffmanTree; + +static void HuffmanTree_init(HuffmanTree* tree) { + tree->codes = 0; + tree->lengths = 0; + tree->table_len = 0; + tree->table_value = 0; +} + +static void HuffmanTree_cleanup(HuffmanTree* tree) { + lodepng_free(tree->codes); + lodepng_free(tree->lengths); + lodepng_free(tree->table_len); + lodepng_free(tree->table_value); +} + +/* amount of bits for first huffman table lookup (aka root bits), see HuffmanTree_makeTable and huffmanDecodeSymbol.*/ +/* values 8u and 9u work the fastest */ +#define FIRSTBITS 9u + +/* a symbol value too big to represent any valid symbol, to indicate reading disallowed huffman bits combination, +which is possible in case of only 0 or 1 present symbols. */ +#define INVALIDSYMBOL 65535u + +/* make table for huffman decoding */ +static unsigned HuffmanTree_makeTable(HuffmanTree* tree) { + static const unsigned headsize = 1u << FIRSTBITS; /*size of the first table*/ + static const unsigned mask = (1u << FIRSTBITS) /*headsize*/ - 1u; + size_t i, numpresent, pointer, size; /*total table size*/ + unsigned* maxlens = (unsigned*)lodepng_malloc(headsize * sizeof(unsigned)); + if(!maxlens) return 83; /*alloc fail*/ + + /* compute maxlens: max total bit length of symbols sharing prefix in the first table*/ + lodepng_memset(maxlens, 0, headsize * sizeof(*maxlens)); + for(i = 0; i < tree->numcodes; i++) { + unsigned symbol = tree->codes[i]; + unsigned l = tree->lengths[i]; + unsigned index; + if(l <= FIRSTBITS) continue; /*symbols that fit in first table don't increase secondary table size*/ + /*get the FIRSTBITS MSBs, the MSBs of the symbol are encoded first. See later comment about the reversing*/ + index = reverseBits(symbol >> (l - FIRSTBITS), FIRSTBITS); + maxlens[index] = LODEPNG_MAX(maxlens[index], l); + } + /* compute total table size: size of first table plus all secondary tables for symbols longer than FIRSTBITS */ + size = headsize; + for(i = 0; i < headsize; ++i) { + unsigned l = maxlens[i]; + if(l > FIRSTBITS) size += (1u << (l - FIRSTBITS)); + } + tree->table_len = (unsigned char*)lodepng_malloc(size * sizeof(*tree->table_len)); + tree->table_value = (unsigned short*)lodepng_malloc(size * sizeof(*tree->table_value)); + if(!tree->table_len || !tree->table_value) { + lodepng_free(maxlens); + /* freeing tree->table values is done at a higher scope */ + return 83; /*alloc fail*/ + } + /*initialize with an invalid length to indicate unused entries*/ + for(i = 0; i < size; ++i) tree->table_len[i] = 16; + + /*fill in the first table for long symbols: max prefix size and pointer to secondary tables*/ + pointer = headsize; + for(i = 0; i < headsize; ++i) { + unsigned l = maxlens[i]; + if(l <= FIRSTBITS) continue; + tree->table_len[i] = l; + tree->table_value[i] = pointer; + pointer += (1u << (l - FIRSTBITS)); + } + lodepng_free(maxlens); + + /*fill in the first table for short symbols, or secondary table for long symbols*/ + numpresent = 0; + for(i = 0; i < tree->numcodes; ++i) { + unsigned l = tree->lengths[i]; + unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/ + /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/ + unsigned reverse = reverseBits(symbol, l); + if(l == 0) continue; + numpresent++; + + if(l <= FIRSTBITS) { + /*short symbol, fully in first table, replicated num times if l < FIRSTBITS*/ + unsigned num = 1u << (FIRSTBITS - l); + unsigned j; + for(j = 0; j < num; ++j) { + /*bit reader will read the l bits of symbol first, the remaining FIRSTBITS - l bits go to the MSB's*/ + unsigned index = reverse | (j << l); + if(tree->table_len[index] != 16) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ + tree->table_len[index] = l; + tree->table_value[index] = i; + } + } else { + /*long symbol, shares prefix with other long symbols in first lookup table, needs second lookup*/ + /*the FIRSTBITS MSBs of the symbol are the first table index*/ + unsigned index = reverse & mask; + unsigned maxlen = tree->table_len[index]; + /*log2 of secondary table length, should be >= l - FIRSTBITS*/ + unsigned tablelen = maxlen - FIRSTBITS; + unsigned start = tree->table_value[index]; /*starting index in secondary table*/ + unsigned num = 1u << (tablelen - (l - FIRSTBITS)); /*amount of entries of this symbol in secondary table*/ + unsigned j; + if(maxlen < l) return 55; /*invalid tree: long symbol shares prefix with short symbol*/ + for(j = 0; j < num; ++j) { + unsigned reverse2 = reverse >> FIRSTBITS; /* l - FIRSTBITS bits */ + unsigned index2 = start + (reverse2 | (j << (l - FIRSTBITS))); + tree->table_len[index2] = l; + tree->table_value[index2] = i; + } + } + } + + if(numpresent < 2) { + /* In case of exactly 1 symbol, in theory the huffman symbol needs 0 bits, + but deflate uses 1 bit instead. In case of 0 symbols, no symbols can + appear at all, but such huffman tree could still exist (e.g. if distance + codes are never used). In both cases, not all symbols of the table will be + filled in. Fill them in with an invalid symbol value so returning them from + huffmanDecodeSymbol will cause error. */ + for(i = 0; i < size; ++i) { + if(tree->table_len[i] == 16) { + /* As length, use a value smaller than FIRSTBITS for the head table, + and a value larger than FIRSTBITS for the secondary table, to ensure + valid behavior for advanceBits when reading this symbol. */ + tree->table_len[i] = (i < headsize) ? 1 : (FIRSTBITS + 1); + tree->table_value[i] = INVALIDSYMBOL; + } + } + } else { + /* A good huffman tree has N * 2 - 1 nodes, of which N - 1 are internal nodes. + If that is not the case (due to too long length codes), the table will not + have been fully used, and this is an error (not all bit combinations can be + decoded): an oversubscribed huffman tree, indicated by error 55. */ + for(i = 0; i < size; ++i) { + if(tree->table_len[i] == 16) return 55; + } + } + + return 0; +} + +/* +Second step for the ...makeFromLengths and ...makeFromFrequencies functions. +numcodes, lengths and maxbitlen must already be filled in correctly. return +value is error. +*/ +static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree) { + unsigned* blcount; + unsigned* nextcode; + unsigned error = 0; + unsigned bits, n; + + tree->codes = (unsigned*)lodepng_malloc(tree->numcodes * sizeof(unsigned)); + blcount = (unsigned*)lodepng_malloc((tree->maxbitlen + 1) * sizeof(unsigned)); + nextcode = (unsigned*)lodepng_malloc((tree->maxbitlen + 1) * sizeof(unsigned)); + if(!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/ + + if(!error) { + for(n = 0; n != tree->maxbitlen + 1; n++) blcount[n] = nextcode[n] = 0; + /*step 1: count number of instances of each code length*/ + for(bits = 0; bits != tree->numcodes; ++bits) ++blcount[tree->lengths[bits]]; + /*step 2: generate the nextcode values*/ + for(bits = 1; bits <= tree->maxbitlen; ++bits) { + nextcode[bits] = (nextcode[bits - 1] + blcount[bits - 1]) << 1u; + } + /*step 3: generate all the codes*/ + for(n = 0; n != tree->numcodes; ++n) { + if(tree->lengths[n] != 0) { + tree->codes[n] = nextcode[tree->lengths[n]]++; + /*remove superfluous bits from the code*/ + tree->codes[n] &= ((1u << tree->lengths[n]) - 1u); + } + } + } + + lodepng_free(blcount); + lodepng_free(nextcode); + + if(!error) error = HuffmanTree_makeTable(tree); + return error; +} + +/* +given the code lengths (as stored in the PNG file), generate the tree as defined +by Deflate. maxbitlen is the maximum bits that a code in the tree can have. +return value is error. +*/ +static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* bitlen, + size_t numcodes, unsigned maxbitlen) { + unsigned i; + tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned)); + if(!tree->lengths) return 83; /*alloc fail*/ + for(i = 0; i != numcodes; ++i) tree->lengths[i] = bitlen[i]; + tree->numcodes = (unsigned)numcodes; /*number of symbols*/ + tree->maxbitlen = maxbitlen; + return HuffmanTree_makeFromLengths2(tree); +} + +#ifdef LODEPNG_COMPILE_ENCODER + +/*BPM: Boundary Package Merge, see "A Fast and Space-Economical Algorithm for Length-Limited Coding", +Jyrki Katajainen, Alistair Moffat, Andrew Turpin, 1995.*/ + +/*chain node for boundary package merge*/ +typedef struct BPMNode { + int weight; /*the sum of all weights in this chain*/ + unsigned index; /*index of this leaf node (called "count" in the paper)*/ + struct BPMNode* tail; /*the next nodes in this chain (null if last)*/ + int in_use; +} BPMNode; + +/*lists of chains*/ +typedef struct BPMLists { + /*memory pool*/ + unsigned memsize; + BPMNode* memory; + unsigned numfree; + unsigned nextfree; + BPMNode** freelist; + /*two heads of lookahead chains per list*/ + unsigned listsize; + BPMNode** chains0; + BPMNode** chains1; +} BPMLists; + +/*creates a new chain node with the given parameters, from the memory in the lists */ +static BPMNode* bpmnode_create(BPMLists* lists, int weight, unsigned index, BPMNode* tail) { + unsigned i; + BPMNode* result; + + /*memory full, so garbage collect*/ + if(lists->nextfree >= lists->numfree) { + /*mark only those that are in use*/ + for(i = 0; i != lists->memsize; ++i) lists->memory[i].in_use = 0; + for(i = 0; i != lists->listsize; ++i) { + BPMNode* node; + for(node = lists->chains0[i]; node != 0; node = node->tail) node->in_use = 1; + for(node = lists->chains1[i]; node != 0; node = node->tail) node->in_use = 1; + } + /*collect those that are free*/ + lists->numfree = 0; + for(i = 0; i != lists->memsize; ++i) { + if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i]; + } + lists->nextfree = 0; + } + + result = lists->freelist[lists->nextfree++]; + result->weight = weight; + result->index = index; + result->tail = tail; + return result; +} + +/*sort the leaves with stable mergesort*/ +static void bpmnode_sort(BPMNode* leaves, size_t num) { + BPMNode* mem = (BPMNode*)lodepng_malloc(sizeof(*leaves) * num); + size_t width, counter = 0; + for(width = 1; width < num; width *= 2) { + BPMNode* a = (counter & 1) ? mem : leaves; + BPMNode* b = (counter & 1) ? leaves : mem; + size_t p; + for(p = 0; p < num; p += 2 * width) { + size_t q = (p + width > num) ? num : (p + width); + size_t r = (p + 2 * width > num) ? num : (p + 2 * width); + size_t i = p, j = q, k; + for(k = p; k < r; k++) { + if(i < q && (j >= r || a[i].weight <= a[j].weight)) b[k] = a[i++]; + else b[k] = a[j++]; + } + } + counter++; + } + if(counter & 1) lodepng_memcpy(leaves, mem, sizeof(*leaves) * num); + lodepng_free(mem); +} + +/*Boundary Package Merge step, numpresent is the amount of leaves, and c is the current chain.*/ +static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num) { + unsigned lastindex = lists->chains1[c]->index; + + if(c == 0) { + if(lastindex >= numpresent) return; + lists->chains0[c] = lists->chains1[c]; + lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, 0); + } else { + /*sum of the weights of the head nodes of the previous lookahead chains.*/ + int sum = lists->chains0[c - 1]->weight + lists->chains1[c - 1]->weight; + lists->chains0[c] = lists->chains1[c]; + if(lastindex < numpresent && sum > leaves[lastindex].weight) { + lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, lists->chains1[c]->tail); + return; + } + lists->chains1[c] = bpmnode_create(lists, sum, lastindex, lists->chains1[c - 1]); + /*in the end we are only interested in the chain of the last list, so no + need to recurse if we're at the last one (this gives measurable speedup)*/ + if(num + 1 < (int)(2 * numpresent - 2)) { + boundaryPM(lists, leaves, numpresent, c - 1, num); + boundaryPM(lists, leaves, numpresent, c - 1, num); + } + } +} + +unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, + size_t numcodes, unsigned maxbitlen) { + unsigned error = 0; + unsigned i; + size_t numpresent = 0; /*number of symbols with non-zero frequency*/ + BPMNode* leaves; /*the symbols, only those with > 0 frequency*/ + + if(numcodes == 0) return 80; /*error: a tree of 0 symbols is not supposed to be made*/ + if((1u << maxbitlen) < (unsigned)numcodes) return 80; /*error: represent all symbols*/ + + leaves = (BPMNode*)lodepng_malloc(numcodes * sizeof(*leaves)); + if(!leaves) return 83; /*alloc fail*/ + + for(i = 0; i != numcodes; ++i) { + if(frequencies[i] > 0) { + leaves[numpresent].weight = (int)frequencies[i]; + leaves[numpresent].index = i; + ++numpresent; + } + } + + lodepng_memset(lengths, 0, numcodes * sizeof(*lengths)); + + /*ensure at least two present symbols. There should be at least one symbol + according to RFC 1951 section 3.2.7. Some decoders incorrectly require two. To + make these work as well ensure there are at least two symbols. The + Package-Merge code below also doesn't work correctly if there's only one + symbol, it'd give it the theoretical 0 bits but in practice zlib wants 1 bit*/ + if(numpresent == 0) { + lengths[0] = lengths[1] = 1; /*note that for RFC 1951 section 3.2.7, only lengths[0] = 1 is needed*/ + } else if(numpresent == 1) { + lengths[leaves[0].index] = 1; + lengths[leaves[0].index == 0 ? 1 : 0] = 1; + } else { + BPMLists lists; + BPMNode* node; + + bpmnode_sort(leaves, numpresent); + + lists.listsize = maxbitlen; + lists.memsize = 2 * maxbitlen * (maxbitlen + 1); + lists.nextfree = 0; + lists.numfree = lists.memsize; + lists.memory = (BPMNode*)lodepng_malloc(lists.memsize * sizeof(*lists.memory)); + lists.freelist = (BPMNode**)lodepng_malloc(lists.memsize * sizeof(BPMNode*)); + lists.chains0 = (BPMNode**)lodepng_malloc(lists.listsize * sizeof(BPMNode*)); + lists.chains1 = (BPMNode**)lodepng_malloc(lists.listsize * sizeof(BPMNode*)); + if(!lists.memory || !lists.freelist || !lists.chains0 || !lists.chains1) error = 83; /*alloc fail*/ + + if(!error) { + for(i = 0; i != lists.memsize; ++i) lists.freelist[i] = &lists.memory[i]; + + bpmnode_create(&lists, leaves[0].weight, 1, 0); + bpmnode_create(&lists, leaves[1].weight, 2, 0); + + for(i = 0; i != lists.listsize; ++i) { + lists.chains0[i] = &lists.memory[0]; + lists.chains1[i] = &lists.memory[1]; + } + + /*each boundaryPM call adds one chain to the last list, and we need 2 * numpresent - 2 chains.*/ + for(i = 2; i != 2 * numpresent - 2; ++i) boundaryPM(&lists, leaves, numpresent, (int)maxbitlen - 1, (int)i); + + for(node = lists.chains1[maxbitlen - 1]; node; node = node->tail) { + for(i = 0; i != node->index; ++i) ++lengths[leaves[i].index]; + } + } + + lodepng_free(lists.memory); + lodepng_free(lists.freelist); + lodepng_free(lists.chains0); + lodepng_free(lists.chains1); + } + + lodepng_free(leaves); + return error; +} + +/*Create the Huffman tree given the symbol frequencies*/ +static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies, + size_t mincodes, size_t numcodes, unsigned maxbitlen) { + unsigned error = 0; + while(!frequencies[numcodes - 1] && numcodes > mincodes) --numcodes; /*trim zeroes*/ + tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned)); + if(!tree->lengths) return 83; /*alloc fail*/ + tree->maxbitlen = maxbitlen; + tree->numcodes = (unsigned)numcodes; /*number of symbols*/ + + error = lodepng_huffman_code_lengths(tree->lengths, frequencies, numcodes, maxbitlen); + if(!error) error = HuffmanTree_makeFromLengths2(tree); + return error; +} +#endif /*LODEPNG_COMPILE_ENCODER*/ + +/*get the literal and length code tree of a deflated block with fixed tree, as per the deflate specification*/ +static unsigned generateFixedLitLenTree(HuffmanTree* tree) { + unsigned i, error = 0; + unsigned* bitlen = (unsigned*)lodepng_malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned)); + if(!bitlen) return 83; /*alloc fail*/ + + /*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/ + for(i = 0; i <= 143; ++i) bitlen[i] = 8; + for(i = 144; i <= 255; ++i) bitlen[i] = 9; + for(i = 256; i <= 279; ++i) bitlen[i] = 7; + for(i = 280; i <= 287; ++i) bitlen[i] = 8; + + error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DEFLATE_CODE_SYMBOLS, 15); + + lodepng_free(bitlen); + return error; +} + +/*get the distance code tree of a deflated block with fixed tree, as specified in the deflate specification*/ +static unsigned generateFixedDistanceTree(HuffmanTree* tree) { + unsigned i, error = 0; + unsigned* bitlen = (unsigned*)lodepng_malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned)); + if(!bitlen) return 83; /*alloc fail*/ + + /*there are 32 distance codes, but 30-31 are unused*/ + for(i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen[i] = 5; + error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DISTANCE_SYMBOLS, 15); + + lodepng_free(bitlen); + return error; +} + +#ifdef LODEPNG_COMPILE_DECODER + +/* +returns the code. The bit reader must already have been ensured at least 15 bits +*/ +static unsigned huffmanDecodeSymbol(LodePNGBitReader* reader, const HuffmanTree* codetree) { + unsigned short code = peekBits(reader, FIRSTBITS); + unsigned short l = codetree->table_len[code]; + unsigned short value = codetree->table_value[code]; + if(l <= FIRSTBITS) { + advanceBits(reader, l); + return value; + } else { + unsigned index2; + advanceBits(reader, FIRSTBITS); + index2 = value + peekBits(reader, l - FIRSTBITS); + advanceBits(reader, codetree->table_len[index2] - FIRSTBITS); + return codetree->table_value[index2]; + } +} +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_DECODER + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Inflator (Decompressor) / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/*get the tree of a deflated block with fixed tree, as specified in the deflate specification +Returns error code.*/ +static unsigned getTreeInflateFixed(HuffmanTree* tree_ll, HuffmanTree* tree_d) { + unsigned error = generateFixedLitLenTree(tree_ll); + if(error) return error; + return generateFixedDistanceTree(tree_d); +} + +/*get the tree of a deflated block with dynamic tree, the tree itself is also Huffman compressed with a known tree*/ +static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d, + LodePNGBitReader* reader) { + /*make sure that length values that aren't filled in will be 0, or a wrong tree will be generated*/ + unsigned error = 0; + unsigned n, HLIT, HDIST, HCLEN, i; + + /*see comments in deflateDynamic for explanation of the context and these variables, it is analogous*/ + unsigned* bitlen_ll = 0; /*lit,len code lengths*/ + unsigned* bitlen_d = 0; /*dist code lengths*/ + /*code length code lengths ("clcl"), the bit lengths of the huffman tree used to compress bitlen_ll and bitlen_d*/ + unsigned* bitlen_cl = 0; + HuffmanTree tree_cl; /*the code tree for code length codes (the huffman tree for compressed huffman trees)*/ + + if(!ensureBits17(reader, 14)) return 49; /*error: the bit pointer is or will go past the memory*/ + + /*number of literal/length codes + 257. Unlike the spec, the value 257 is added to it here already*/ + HLIT = readBits(reader, 5) + 257; + /*number of distance codes. Unlike the spec, the value 1 is added to it here already*/ + HDIST = readBits(reader, 5) + 1; + /*number of code length codes. Unlike the spec, the value 4 is added to it here already*/ + HCLEN = readBits(reader, 4) + 4; + + bitlen_cl = (unsigned*)lodepng_malloc(NUM_CODE_LENGTH_CODES * sizeof(unsigned)); + if(!bitlen_cl) return 83 /*alloc fail*/; + + HuffmanTree_init(&tree_cl); + + while(!error) { + /*read the code length codes out of 3 * (amount of code length codes) bits*/ + if(lodepng_gtofl(reader->bp, HCLEN * 3, reader->bitsize)) { + ERROR_BREAK(50); /*error: the bit pointer is or will go past the memory*/ + } + for(i = 0; i != HCLEN; ++i) { + ensureBits9(reader, 3); /*out of bounds already checked above */ + bitlen_cl[CLCL_ORDER[i]] = readBits(reader, 3); + } + for(i = HCLEN; i != NUM_CODE_LENGTH_CODES; ++i) { + bitlen_cl[CLCL_ORDER[i]] = 0; + } + + error = HuffmanTree_makeFromLengths(&tree_cl, bitlen_cl, NUM_CODE_LENGTH_CODES, 7); + if(error) break; + + /*now we can use this tree to read the lengths for the tree that this function will return*/ + bitlen_ll = (unsigned*)lodepng_malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned)); + bitlen_d = (unsigned*)lodepng_malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned)); + if(!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/); + lodepng_memset(bitlen_ll, 0, NUM_DEFLATE_CODE_SYMBOLS * sizeof(*bitlen_ll)); + lodepng_memset(bitlen_d, 0, NUM_DISTANCE_SYMBOLS * sizeof(*bitlen_d)); + + /*i is the current symbol we're reading in the part that contains the code lengths of lit/len and dist codes*/ + i = 0; + while(i < HLIT + HDIST) { + unsigned code; + ensureBits25(reader, 22); /* up to 15 bits for huffman code, up to 7 extra bits below*/ + code = huffmanDecodeSymbol(reader, &tree_cl); + if(code <= 15) /*a length code*/ { + if(i < HLIT) bitlen_ll[i] = code; + else bitlen_d[i - HLIT] = code; + ++i; + } else if(code == 16) /*repeat previous*/ { + unsigned replength = 3; /*read in the 2 bits that indicate repeat length (3-6)*/ + unsigned value; /*set value to the previous code*/ + + if(i == 0) ERROR_BREAK(54); /*can't repeat previous if i is 0*/ + + replength += readBits(reader, 2); + + if(i < HLIT + 1) value = bitlen_ll[i - 1]; + else value = bitlen_d[i - HLIT - 1]; + /*repeat this value in the next lengths*/ + for(n = 0; n < replength; ++n) { + if(i >= HLIT + HDIST) ERROR_BREAK(13); /*error: i is larger than the amount of codes*/ + if(i < HLIT) bitlen_ll[i] = value; + else bitlen_d[i - HLIT] = value; + ++i; + } + } else if(code == 17) /*repeat "0" 3-10 times*/ { + unsigned replength = 3; /*read in the bits that indicate repeat length*/ + replength += readBits(reader, 3); + + /*repeat this value in the next lengths*/ + for(n = 0; n < replength; ++n) { + if(i >= HLIT + HDIST) ERROR_BREAK(14); /*error: i is larger than the amount of codes*/ + + if(i < HLIT) bitlen_ll[i] = 0; + else bitlen_d[i - HLIT] = 0; + ++i; + } + } else if(code == 18) /*repeat "0" 11-138 times*/ { + unsigned replength = 11; /*read in the bits that indicate repeat length*/ + replength += readBits(reader, 7); + + /*repeat this value in the next lengths*/ + for(n = 0; n < replength; ++n) { + if(i >= HLIT + HDIST) ERROR_BREAK(15); /*error: i is larger than the amount of codes*/ + + if(i < HLIT) bitlen_ll[i] = 0; + else bitlen_d[i - HLIT] = 0; + ++i; + } + } else /*if(code == INVALIDSYMBOL)*/ { + ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ + } + /*check if any of the ensureBits above went out of bounds*/ + if(reader->bp > reader->bitsize) { + /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol + (10=no endcode, 11=wrong jump outside of tree)*/ + /* TODO: revise error codes 10,11,50: the above comment is no longer valid */ + ERROR_BREAK(50); /*error, bit pointer jumps past memory*/ + } + } + if(error) break; + + if(bitlen_ll[256] == 0) ERROR_BREAK(64); /*the length of the end code 256 must be larger than 0*/ + + /*now we've finally got HLIT and HDIST, so generate the code trees, and the function is done*/ + error = HuffmanTree_makeFromLengths(tree_ll, bitlen_ll, NUM_DEFLATE_CODE_SYMBOLS, 15); + if(error) break; + error = HuffmanTree_makeFromLengths(tree_d, bitlen_d, NUM_DISTANCE_SYMBOLS, 15); + + break; /*end of error-while*/ + } + + lodepng_free(bitlen_cl); + lodepng_free(bitlen_ll); + lodepng_free(bitlen_d); + HuffmanTree_cleanup(&tree_cl); + + return error; +} + +/*inflate a block with dynamic of fixed Huffman tree. btype must be 1 or 2.*/ +static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader, + unsigned btype) { + unsigned error = 0; + HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/ + HuffmanTree tree_d; /*the huffman tree for distance codes*/ + + HuffmanTree_init(&tree_ll); + HuffmanTree_init(&tree_d); + + if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d); + else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader); + + while(!error) /*decode all symbols until end reached, breaks at end code*/ { + /*code_ll is literal, length or end code*/ + unsigned code_ll; + ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */ + code_ll = huffmanDecodeSymbol(reader, &tree_ll); + if(code_ll <= 255) /*literal symbol*/ { + if(!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/); + out->data[out->size - 1] = (unsigned char)code_ll; + } else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ { + unsigned code_d, distance; + unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/ + size_t start, backward, length; + + /*part 1: get length base*/ + length = LENGTHBASE[code_ll - FIRST_LENGTH_CODE_INDEX]; + + /*part 2: get extra bits and add the value of that to length*/ + numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX]; + if(numextrabits_l != 0) { + /* bits already ensured above */ + length += readBits(reader, numextrabits_l); + } + + /*part 3: get distance code*/ + ensureBits32(reader, 28); /* up to 15 for the huffman symbol, up to 13 for the extra bits */ + code_d = huffmanDecodeSymbol(reader, &tree_d); + if(code_d > 29) { + if(code_d <= 31) { + ERROR_BREAK(18); /*error: invalid distance code (30-31 are never used)*/ + } else /* if(code_d == INVALIDSYMBOL) */{ + ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ + } + } + distance = DISTANCEBASE[code_d]; + + /*part 4: get extra bits from distance*/ + numextrabits_d = DISTANCEEXTRA[code_d]; + if(numextrabits_d != 0) { + /* bits already ensured above */ + distance += readBits(reader, numextrabits_d); + } + + /*part 5: fill in all the out[n] values based on the length and dist*/ + start = out->size; + if(distance > start) ERROR_BREAK(52); /*too long backward distance*/ + backward = start - distance; + + if(!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/); + if(distance < length) { + size_t forward; + lodepng_memcpy(out->data + start, out->data + backward, distance); + start += distance; + for(forward = distance; forward < length; ++forward) { + out->data[start++] = out->data[backward++]; + } + } else { + lodepng_memcpy(out->data + start, out->data + backward, length); + } + } else if(code_ll == 256) { + break; /*end code, break the loop*/ + } else /*if(code_ll == INVALIDSYMBOL)*/ { + ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/ + } + /*check if any of the ensureBits above went out of bounds*/ + if(reader->bp > reader->bitsize) { + /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol + (10=no endcode, 11=wrong jump outside of tree)*/ + /* TODO: revise error codes 10,11,50: the above comment is no longer valid */ + ERROR_BREAK(51); /*error, bit pointer jumps past memory*/ + } + } + + HuffmanTree_cleanup(&tree_ll); + HuffmanTree_cleanup(&tree_d); + + return error; +} + +static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader, + const LodePNGDecompressSettings* settings) { + size_t bytepos; + size_t size = reader->size; + unsigned LEN, NLEN, error = 0; + + /*go to first boundary of byte*/ + bytepos = (reader->bp + 7u) >> 3u; + + /*read LEN (2 bytes) and NLEN (2 bytes)*/ + if(bytepos + 4 >= size) return 52; /*error, bit pointer will jump past memory*/ + LEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2; + NLEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2; + + /*check if 16-bit NLEN is really the one's complement of LEN*/ + if(!settings->ignore_nlen && LEN + NLEN != 65535) { + return 21; /*error: NLEN is not one's complement of LEN*/ + } + + if(!ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/ + + /*read the literal data: LEN bytes are now stored in the out buffer*/ + if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/ + + lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN); + bytepos += LEN; + + reader->bp = bytepos << 3u; + + return error; +} + +static unsigned lodepng_inflatev(ucvector* out, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings) { + unsigned BFINAL = 0; + LodePNGBitReader reader; + unsigned error = LodePNGBitReader_init(&reader, in, insize); + + if(error) return error; + + while(!BFINAL) { + unsigned BTYPE; + if(!ensureBits9(&reader, 3)) return 52; /*error, bit pointer will jump past memory*/ + BFINAL = readBits(&reader, 1); + BTYPE = readBits(&reader, 2); + + if(BTYPE == 3) return 20; /*error: invalid BTYPE*/ + else if(BTYPE == 0) error = inflateNoCompression(out, &reader, settings); /*no compression*/ + else error = inflateHuffmanBlock(out, &reader, BTYPE); /*compression, BTYPE 01 or 10*/ + + if(error) return error; + } + + return error; +} + +unsigned lodepng_inflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings) { + ucvector v = ucvector_init(*out, *outsize); + unsigned error = lodepng_inflatev(&v, in, insize, settings); + *out = v.data; + *outsize = v.size; + return error; +} + +static unsigned inflatev(ucvector* out, const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings) { + if(settings->custom_inflate) { + unsigned error = settings->custom_inflate(&out->data, &out->size, in, insize, settings); + out->allocsize = out->size; + return error; + } else { + return lodepng_inflatev(out, in, insize, settings); + } +} + +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Deflator (Compressor) / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +static const size_t MAX_SUPPORTED_DEFLATE_LENGTH = 258; + +/*search the index in the array, that has the largest value smaller than or equal to the given value, +given array must be sorted (if no value is smaller, it returns the size of the given array)*/ +static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value) { + /*binary search (only small gain over linear). TODO: use CPU log2 instruction for getting symbols instead*/ + size_t left = 1; + size_t right = array_size - 1; + + while(left <= right) { + size_t mid = (left + right) >> 1; + if(array[mid] >= value) right = mid - 1; + else left = mid + 1; + } + if(left >= array_size || array[left] > value) left--; + return left; +} + +static void addLengthDistance(uivector* values, size_t length, size_t distance) { + /*values in encoded vector are those used by deflate: + 0-255: literal bytes + 256: end + 257-285: length/distance pair (length code, followed by extra length bits, distance code, extra distance bits) + 286-287: invalid*/ + + unsigned length_code = (unsigned)searchCodeIndex(LENGTHBASE, 29, length); + unsigned extra_length = (unsigned)(length - LENGTHBASE[length_code]); + unsigned dist_code = (unsigned)searchCodeIndex(DISTANCEBASE, 30, distance); + unsigned extra_distance = (unsigned)(distance - DISTANCEBASE[dist_code]); + + size_t pos = values->size; + /*TODO: return error when this fails (out of memory)*/ + unsigned ok = uivector_resize(values, values->size + 4); + if(ok) { + values->data[pos + 0] = length_code + FIRST_LENGTH_CODE_INDEX; + values->data[pos + 1] = extra_length; + values->data[pos + 2] = dist_code; + values->data[pos + 3] = extra_distance; + } +} + +/*3 bytes of data get encoded into two bytes. The hash cannot use more than 3 +bytes as input because 3 is the minimum match length for deflate*/ +static const unsigned HASH_NUM_VALUES = 65536; +static const unsigned HASH_BIT_MASK = 65535; /*HASH_NUM_VALUES - 1, but C90 does not like that as initializer*/ + +typedef struct Hash { + int* head; /*hash value to head circular pos - can be outdated if went around window*/ + /*circular pos to prev circular pos*/ + unsigned short* chain; + int* val; /*circular pos to hash value*/ + + /*TODO: do this not only for zeros but for any repeated byte. However for PNG + it's always going to be the zeros that dominate, so not important for PNG*/ + int* headz; /*similar to head, but for chainz*/ + unsigned short* chainz; /*those with same amount of zeros*/ + unsigned short* zeros; /*length of zeros streak, used as a second hash chain*/ +} Hash; + +static unsigned hash_init(Hash* hash, unsigned windowsize) { + unsigned i; + hash->head = (int*)lodepng_malloc(sizeof(int) * HASH_NUM_VALUES); + hash->val = (int*)lodepng_malloc(sizeof(int) * windowsize); + hash->chain = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize); + + hash->zeros = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize); + hash->headz = (int*)lodepng_malloc(sizeof(int) * (MAX_SUPPORTED_DEFLATE_LENGTH + 1)); + hash->chainz = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize); + + if(!hash->head || !hash->chain || !hash->val || !hash->headz|| !hash->chainz || !hash->zeros) { + return 83; /*alloc fail*/ + } + + /*initialize hash table*/ + for(i = 0; i != HASH_NUM_VALUES; ++i) hash->head[i] = -1; + for(i = 0; i != windowsize; ++i) hash->val[i] = -1; + for(i = 0; i != windowsize; ++i) hash->chain[i] = i; /*same value as index indicates uninitialized*/ + + for(i = 0; i <= MAX_SUPPORTED_DEFLATE_LENGTH; ++i) hash->headz[i] = -1; + for(i = 0; i != windowsize; ++i) hash->chainz[i] = i; /*same value as index indicates uninitialized*/ + + return 0; +} + +static void hash_cleanup(Hash* hash) { + lodepng_free(hash->head); + lodepng_free(hash->val); + lodepng_free(hash->chain); + + lodepng_free(hash->zeros); + lodepng_free(hash->headz); + lodepng_free(hash->chainz); +} + + + +static unsigned getHash(const unsigned char* data, size_t size, size_t pos) { + unsigned result = 0; + if(pos + 2 < size) { + /*A simple shift and xor hash is used. Since the data of PNGs is dominated + by zeroes due to the filters, a better hash does not have a significant + effect on speed in traversing the chain, and causes more time spend on + calculating the hash.*/ + result ^= ((unsigned)data[pos + 0] << 0u); + result ^= ((unsigned)data[pos + 1] << 4u); + result ^= ((unsigned)data[pos + 2] << 8u); + } else { + size_t amount, i; + if(pos >= size) return 0; + amount = size - pos; + for(i = 0; i != amount; ++i) result ^= ((unsigned)data[pos + i] << (i * 8u)); + } + return result & HASH_BIT_MASK; +} + +static unsigned countZeros(const unsigned char* data, size_t size, size_t pos) { + const unsigned char* start = data + pos; + const unsigned char* end = start + MAX_SUPPORTED_DEFLATE_LENGTH; + if(end > data + size) end = data + size; + data = start; + while(data != end && *data == 0) ++data; + /*subtracting two addresses returned as 32-bit number (max value is MAX_SUPPORTED_DEFLATE_LENGTH)*/ + return (unsigned)(data - start); +} + +/*wpos = pos & (windowsize - 1)*/ +static void updateHashChain(Hash* hash, size_t wpos, unsigned hashval, unsigned short numzeros) { + hash->val[wpos] = (int)hashval; + if(hash->head[hashval] != -1) hash->chain[wpos] = hash->head[hashval]; + hash->head[hashval] = (int)wpos; + + hash->zeros[wpos] = numzeros; + if(hash->headz[numzeros] != -1) hash->chainz[wpos] = hash->headz[numzeros]; + hash->headz[numzeros] = (int)wpos; +} + +/* +LZ77-encode the data. Return value is error code. The input are raw bytes, the output +is in the form of unsigned integers with codes representing for example literal bytes, or +length/distance pairs. +It uses a hash table technique to let it encode faster. When doing LZ77 encoding, a +sliding window (of windowsize) is used, and all past bytes in that window can be used as +the "dictionary". A brute force search through all possible distances would be slow, and +this hash technique is one out of several ways to speed this up. +*/ +static unsigned encodeLZ77(uivector* out, Hash* hash, + const unsigned char* in, size_t inpos, size_t insize, unsigned windowsize, + unsigned minmatch, unsigned nicematch, unsigned lazymatching) { + size_t pos; + unsigned i, error = 0; + /*for large window lengths, assume the user wants no compression loss. Otherwise, max hash chain length speedup.*/ + unsigned maxchainlength = windowsize >= 8192 ? windowsize : windowsize / 8u; + unsigned maxlazymatch = windowsize >= 8192 ? MAX_SUPPORTED_DEFLATE_LENGTH : 64; + + unsigned usezeros = 1; /*not sure if setting it to false for windowsize < 8192 is better or worse*/ + unsigned numzeros = 0; + + unsigned offset; /*the offset represents the distance in LZ77 terminology*/ + unsigned length; + unsigned lazy = 0; + unsigned lazylength = 0, lazyoffset = 0; + unsigned hashval; + unsigned current_offset, current_length; + unsigned prev_offset; + const unsigned char *lastptr, *foreptr, *backptr; + unsigned hashpos; + + if(windowsize == 0 || windowsize > 32768) return 60; /*error: windowsize smaller/larger than allowed*/ + if((windowsize & (windowsize - 1)) != 0) return 90; /*error: must be power of two*/ + + if(nicematch > MAX_SUPPORTED_DEFLATE_LENGTH) nicematch = MAX_SUPPORTED_DEFLATE_LENGTH; + + for(pos = inpos; pos < insize; ++pos) { + size_t wpos = pos & (windowsize - 1); /*position for in 'circular' hash buffers*/ + unsigned chainlength = 0; + + hashval = getHash(in, insize, pos); + + if(usezeros && hashval == 0) { + if(numzeros == 0) numzeros = countZeros(in, insize, pos); + else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; + } else { + numzeros = 0; + } + + updateHashChain(hash, wpos, hashval, numzeros); + + /*the length and offset found for the current position*/ + length = 0; + offset = 0; + + hashpos = hash->chain[wpos]; + + lastptr = &in[insize < pos + MAX_SUPPORTED_DEFLATE_LENGTH ? insize : pos + MAX_SUPPORTED_DEFLATE_LENGTH]; + + /*search for the longest string*/ + prev_offset = 0; + for(;;) { + if(chainlength++ >= maxchainlength) break; + current_offset = (unsigned)(hashpos <= wpos ? wpos - hashpos : wpos - hashpos + windowsize); + + if(current_offset < prev_offset) break; /*stop when went completely around the circular buffer*/ + prev_offset = current_offset; + if(current_offset > 0) { + /*test the next characters*/ + foreptr = &in[pos]; + backptr = &in[pos - current_offset]; + + /*common case in PNGs is lots of zeros. Quickly skip over them as a speedup*/ + if(numzeros >= 3) { + unsigned skip = hash->zeros[hashpos]; + if(skip > numzeros) skip = numzeros; + backptr += skip; + foreptr += skip; + } + + while(foreptr != lastptr && *backptr == *foreptr) /*maximum supported length by deflate is max length*/ { + ++backptr; + ++foreptr; + } + current_length = (unsigned)(foreptr - &in[pos]); + + if(current_length > length) { + length = current_length; /*the longest length*/ + offset = current_offset; /*the offset that is related to this longest length*/ + /*jump out once a length of max length is found (speed gain). This also jumps + out if length is MAX_SUPPORTED_DEFLATE_LENGTH*/ + if(current_length >= nicematch) break; + } + } + + if(hashpos == hash->chain[hashpos]) break; + + if(numzeros >= 3 && length > numzeros) { + hashpos = hash->chainz[hashpos]; + if(hash->zeros[hashpos] != numzeros) break; + } else { + hashpos = hash->chain[hashpos]; + /*outdated hash value, happens if particular value was not encountered in whole last window*/ + if(hash->val[hashpos] != (int)hashval) break; + } + } + + if(lazymatching) { + if(!lazy && length >= 3 && length <= maxlazymatch && length < MAX_SUPPORTED_DEFLATE_LENGTH) { + lazy = 1; + lazylength = length; + lazyoffset = offset; + continue; /*try the next byte*/ + } + if(lazy) { + lazy = 0; + if(pos == 0) ERROR_BREAK(81); + if(length > lazylength + 1) { + /*push the previous character as literal*/ + if(!uivector_push_back(out, in[pos - 1])) ERROR_BREAK(83 /*alloc fail*/); + } else { + length = lazylength; + offset = lazyoffset; + hash->head[hashval] = -1; /*the same hashchain update will be done, this ensures no wrong alteration*/ + hash->headz[numzeros] = -1; /*idem*/ + --pos; + } + } + } + if(length >= 3 && offset > windowsize) ERROR_BREAK(86 /*too big (or overflown negative) offset*/); + + /*encode it as length/distance pair or literal value*/ + if(length < 3) /*only lengths of 3 or higher are supported as length/distance pair*/ { + if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); + } else if(length < minmatch || (length == 3 && offset > 4096)) { + /*compensate for the fact that longer offsets have more extra bits, a + length of only 3 may be not worth it then*/ + if(!uivector_push_back(out, in[pos])) ERROR_BREAK(83 /*alloc fail*/); + } else { + addLengthDistance(out, length, offset); + for(i = 1; i < length; ++i) { + ++pos; + wpos = pos & (windowsize - 1); + hashval = getHash(in, insize, pos); + if(usezeros && hashval == 0) { + if(numzeros == 0) numzeros = countZeros(in, insize, pos); + else if(pos + numzeros > insize || in[pos + numzeros - 1] != 0) --numzeros; + } else { + numzeros = 0; + } + updateHashChain(hash, wpos, hashval, numzeros); + } + } + } /*end of the loop through each character of input*/ + + return error; +} + +/* /////////////////////////////////////////////////////////////////////////// */ + +static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize) { + /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte, + 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/ + + size_t i, numdeflateblocks = (datasize + 65534u) / 65535u; + unsigned datapos = 0; + for(i = 0; i != numdeflateblocks; ++i) { + unsigned BFINAL, BTYPE, LEN, NLEN; + unsigned char firstbyte; + size_t pos = out->size; + + BFINAL = (i == numdeflateblocks - 1); + BTYPE = 0; + + LEN = 65535; + if(datasize - datapos < 65535u) LEN = (unsigned)datasize - datapos; + NLEN = 65535 - LEN; + + if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/ + + firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1u) << 1u) + ((BTYPE & 2u) << 1u)); + out->data[pos + 0] = firstbyte; + out->data[pos + 1] = (unsigned char)(LEN & 255); + out->data[pos + 2] = (unsigned char)(LEN >> 8u); + out->data[pos + 3] = (unsigned char)(NLEN & 255); + out->data[pos + 4] = (unsigned char)(NLEN >> 8u); + lodepng_memcpy(out->data + pos + 5, data + datapos, LEN); + datapos += LEN; + } + + return 0; +} + +/* +write the lz77-encoded data, which has lit, len and dist codes, to compressed stream using huffman trees. +tree_ll: the tree for lit and len codes. +tree_d: the tree for distance codes. +*/ +static void writeLZ77data(LodePNGBitWriter* writer, const uivector* lz77_encoded, + const HuffmanTree* tree_ll, const HuffmanTree* tree_d) { + size_t i = 0; + for(i = 0; i != lz77_encoded->size; ++i) { + unsigned val = lz77_encoded->data[i]; + writeBitsReversed(writer, tree_ll->codes[val], tree_ll->lengths[val]); + if(val > 256) /*for a length code, 3 more things have to be added*/ { + unsigned length_index = val - FIRST_LENGTH_CODE_INDEX; + unsigned n_length_extra_bits = LENGTHEXTRA[length_index]; + unsigned length_extra_bits = lz77_encoded->data[++i]; + + unsigned distance_code = lz77_encoded->data[++i]; + + unsigned distance_index = distance_code; + unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index]; + unsigned distance_extra_bits = lz77_encoded->data[++i]; + + writeBits(writer, length_extra_bits, n_length_extra_bits); + writeBitsReversed(writer, tree_d->codes[distance_code], tree_d->lengths[distance_code]); + writeBits(writer, distance_extra_bits, n_distance_extra_bits); + } + } +} + +/*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/ +static unsigned deflateDynamic(LodePNGBitWriter* writer, Hash* hash, + const unsigned char* data, size_t datapos, size_t dataend, + const LodePNGCompressSettings* settings, unsigned final) { + unsigned error = 0; + + /* + A block is compressed as follows: The PNG data is lz77 encoded, resulting in + literal bytes and length/distance pairs. This is then huffman compressed with + two huffman trees. One huffman tree is used for the lit and len values ("ll"), + another huffman tree is used for the dist values ("d"). These two trees are + stored using their code lengths, and to compress even more these code lengths + are also run-length encoded and huffman compressed. This gives a huffman tree + of code lengths "cl". The code lengths used to describe this third tree are + the code length code lengths ("clcl"). + */ + + /*The lz77 encoded data, represented with integers since there will also be length and distance codes in it*/ + uivector lz77_encoded; + HuffmanTree tree_ll; /*tree for lit,len values*/ + HuffmanTree tree_d; /*tree for distance codes*/ + HuffmanTree tree_cl; /*tree for encoding the code lengths representing tree_ll and tree_d*/ + unsigned* frequencies_ll = 0; /*frequency of lit,len codes*/ + unsigned* frequencies_d = 0; /*frequency of dist codes*/ + unsigned* frequencies_cl = 0; /*frequency of code length codes*/ + unsigned* bitlen_lld = 0; /*lit,len,dist code lengths (int bits), literally (without repeat codes).*/ + unsigned* bitlen_lld_e = 0; /*bitlen_lld encoded with repeat codes (this is a rudimentary run length compression)*/ + size_t datasize = dataend - datapos; + + /* + If we could call "bitlen_cl" the code length code lengths ("clcl"), that is the bit lengths of codes to represent + tree_cl in CLCL_ORDER, then due to the huffman compression of huffman tree representations ("two levels"), there are + some analogies: + bitlen_lld is to tree_cl what data is to tree_ll and tree_d. + bitlen_lld_e is to bitlen_lld what lz77_encoded is to data. + bitlen_cl is to bitlen_lld_e what bitlen_lld is to lz77_encoded. + */ + + unsigned BFINAL = final; + size_t i; + size_t numcodes_ll, numcodes_d, numcodes_lld, numcodes_lld_e, numcodes_cl; + unsigned HLIT, HDIST, HCLEN; + + uivector_init(&lz77_encoded); + HuffmanTree_init(&tree_ll); + HuffmanTree_init(&tree_d); + HuffmanTree_init(&tree_cl); + /* could fit on stack, but >1KB is on the larger side so allocate instead */ + frequencies_ll = (unsigned*)lodepng_malloc(286 * sizeof(*frequencies_ll)); + frequencies_d = (unsigned*)lodepng_malloc(30 * sizeof(*frequencies_d)); + frequencies_cl = (unsigned*)lodepng_malloc(NUM_CODE_LENGTH_CODES * sizeof(*frequencies_cl)); + + if(!frequencies_ll || !frequencies_d || !frequencies_cl) error = 83; /*alloc fail*/ + + /*This while loop never loops due to a break at the end, it is here to + allow breaking out of it to the cleanup phase on error conditions.*/ + while(!error) { + lodepng_memset(frequencies_ll, 0, 286 * sizeof(*frequencies_ll)); + lodepng_memset(frequencies_d, 0, 30 * sizeof(*frequencies_d)); + lodepng_memset(frequencies_cl, 0, NUM_CODE_LENGTH_CODES * sizeof(*frequencies_cl)); + + if(settings->use_lz77) { + error = encodeLZ77(&lz77_encoded, hash, data, datapos, dataend, settings->windowsize, + settings->minmatch, settings->nicematch, settings->lazymatching); + if(error) break; + } else { + if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/); + for(i = datapos; i < dataend; ++i) lz77_encoded.data[i - datapos] = data[i]; /*no LZ77, but still will be Huffman compressed*/ + } + + /*Count the frequencies of lit, len and dist codes*/ + for(i = 0; i != lz77_encoded.size; ++i) { + unsigned symbol = lz77_encoded.data[i]; + ++frequencies_ll[symbol]; + if(symbol > 256) { + unsigned dist = lz77_encoded.data[i + 2]; + ++frequencies_d[dist]; + i += 3; + } + } + frequencies_ll[256] = 1; /*there will be exactly 1 end code, at the end of the block*/ + + /*Make both huffman trees, one for the lit and len codes, one for the dist codes*/ + error = HuffmanTree_makeFromFrequencies(&tree_ll, frequencies_ll, 257, 286, 15); + if(error) break; + /*2, not 1, is chosen for mincodes: some buggy PNG decoders require at least 2 symbols in the dist tree*/ + error = HuffmanTree_makeFromFrequencies(&tree_d, frequencies_d, 2, 30, 15); + if(error) break; + + numcodes_ll = LODEPNG_MIN(tree_ll.numcodes, 286); + numcodes_d = LODEPNG_MIN(tree_d.numcodes, 30); + /*store the code lengths of both generated trees in bitlen_lld*/ + numcodes_lld = numcodes_ll + numcodes_d; + bitlen_lld = (unsigned*)lodepng_malloc(numcodes_lld * sizeof(*bitlen_lld)); + /*numcodes_lld_e never needs more size than bitlen_lld*/ + bitlen_lld_e = (unsigned*)lodepng_malloc(numcodes_lld * sizeof(*bitlen_lld_e)); + if(!bitlen_lld || !bitlen_lld_e) ERROR_BREAK(83); /*alloc fail*/ + numcodes_lld_e = 0; + + for(i = 0; i != numcodes_ll; ++i) bitlen_lld[i] = tree_ll.lengths[i]; + for(i = 0; i != numcodes_d; ++i) bitlen_lld[numcodes_ll + i] = tree_d.lengths[i]; + + /*run-length compress bitlen_ldd into bitlen_lld_e by using repeat codes 16 (copy length 3-6 times), + 17 (3-10 zeroes), 18 (11-138 zeroes)*/ + for(i = 0; i != numcodes_lld; ++i) { + unsigned j = 0; /*amount of repetitions*/ + while(i + j + 1 < numcodes_lld && bitlen_lld[i + j + 1] == bitlen_lld[i]) ++j; + + if(bitlen_lld[i] == 0 && j >= 2) /*repeat code for zeroes*/ { + ++j; /*include the first zero*/ + if(j <= 10) /*repeat code 17 supports max 10 zeroes*/ { + bitlen_lld_e[numcodes_lld_e++] = 17; + bitlen_lld_e[numcodes_lld_e++] = j - 3; + } else /*repeat code 18 supports max 138 zeroes*/ { + if(j > 138) j = 138; + bitlen_lld_e[numcodes_lld_e++] = 18; + bitlen_lld_e[numcodes_lld_e++] = j - 11; + } + i += (j - 1); + } else if(j >= 3) /*repeat code for value other than zero*/ { + size_t k; + unsigned num = j / 6u, rest = j % 6u; + bitlen_lld_e[numcodes_lld_e++] = bitlen_lld[i]; + for(k = 0; k < num; ++k) { + bitlen_lld_e[numcodes_lld_e++] = 16; + bitlen_lld_e[numcodes_lld_e++] = 6 - 3; + } + if(rest >= 3) { + bitlen_lld_e[numcodes_lld_e++] = 16; + bitlen_lld_e[numcodes_lld_e++] = rest - 3; + } + else j -= rest; + i += j; + } else /*too short to benefit from repeat code*/ { + bitlen_lld_e[numcodes_lld_e++] = bitlen_lld[i]; + } + } + + /*generate tree_cl, the huffmantree of huffmantrees*/ + for(i = 0; i != numcodes_lld_e; ++i) { + ++frequencies_cl[bitlen_lld_e[i]]; + /*after a repeat code come the bits that specify the number of repetitions, + those don't need to be in the frequencies_cl calculation*/ + if(bitlen_lld_e[i] >= 16) ++i; + } + + error = HuffmanTree_makeFromFrequencies(&tree_cl, frequencies_cl, + NUM_CODE_LENGTH_CODES, NUM_CODE_LENGTH_CODES, 7); + if(error) break; + + /*compute amount of code-length-code-lengths to output*/ + numcodes_cl = NUM_CODE_LENGTH_CODES; + /*trim zeros at the end (using CLCL_ORDER), but minimum size must be 4 (see HCLEN below)*/ + while(numcodes_cl > 4u && tree_cl.lengths[CLCL_ORDER[numcodes_cl - 1u]] == 0) { + numcodes_cl--; + } + + /* + Write everything into the output + + After the BFINAL and BTYPE, the dynamic block consists out of the following: + - 5 bits HLIT, 5 bits HDIST, 4 bits HCLEN + - (HCLEN+4)*3 bits code lengths of code length alphabet + - HLIT + 257 code lengths of lit/length alphabet (encoded using the code length + alphabet, + possible repetition codes 16, 17, 18) + - HDIST + 1 code lengths of distance alphabet (encoded using the code length + alphabet, + possible repetition codes 16, 17, 18) + - compressed data + - 256 (end code) + */ + + /*Write block type*/ + writeBits(writer, BFINAL, 1); + writeBits(writer, 0, 1); /*first bit of BTYPE "dynamic"*/ + writeBits(writer, 1, 1); /*second bit of BTYPE "dynamic"*/ + + /*write the HLIT, HDIST and HCLEN values*/ + /*all three sizes take trimmed ending zeroes into account, done either by HuffmanTree_makeFromFrequencies + or in the loop for numcodes_cl above, which saves space. */ + HLIT = (unsigned)(numcodes_ll - 257); + HDIST = (unsigned)(numcodes_d - 1); + HCLEN = (unsigned)(numcodes_cl - 4); + writeBits(writer, HLIT, 5); + writeBits(writer, HDIST, 5); + writeBits(writer, HCLEN, 4); + + /*write the code lengths of the code length alphabet ("bitlen_cl")*/ + for(i = 0; i != numcodes_cl; ++i) writeBits(writer, tree_cl.lengths[CLCL_ORDER[i]], 3); + + /*write the lengths of the lit/len AND the dist alphabet*/ + for(i = 0; i != numcodes_lld_e; ++i) { + writeBitsReversed(writer, tree_cl.codes[bitlen_lld_e[i]], tree_cl.lengths[bitlen_lld_e[i]]); + /*extra bits of repeat codes*/ + if(bitlen_lld_e[i] == 16) writeBits(writer, bitlen_lld_e[++i], 2); + else if(bitlen_lld_e[i] == 17) writeBits(writer, bitlen_lld_e[++i], 3); + else if(bitlen_lld_e[i] == 18) writeBits(writer, bitlen_lld_e[++i], 7); + } + + /*write the compressed data symbols*/ + writeLZ77data(writer, &lz77_encoded, &tree_ll, &tree_d); + /*error: the length of the end code 256 must be larger than 0*/ + if(tree_ll.lengths[256] == 0) ERROR_BREAK(64); + + /*write the end code*/ + writeBitsReversed(writer, tree_ll.codes[256], tree_ll.lengths[256]); + + break; /*end of error-while*/ + } + + /*cleanup*/ + uivector_cleanup(&lz77_encoded); + HuffmanTree_cleanup(&tree_ll); + HuffmanTree_cleanup(&tree_d); + HuffmanTree_cleanup(&tree_cl); + lodepng_free(frequencies_ll); + lodepng_free(frequencies_d); + lodepng_free(frequencies_cl); + lodepng_free(bitlen_lld); + lodepng_free(bitlen_lld_e); + + return error; +} + +static unsigned deflateFixed(LodePNGBitWriter* writer, Hash* hash, + const unsigned char* data, + size_t datapos, size_t dataend, + const LodePNGCompressSettings* settings, unsigned final) { + HuffmanTree tree_ll; /*tree for literal values and length codes*/ + HuffmanTree tree_d; /*tree for distance codes*/ + + unsigned BFINAL = final; + unsigned error = 0; + size_t i; + + HuffmanTree_init(&tree_ll); + HuffmanTree_init(&tree_d); + + error = generateFixedLitLenTree(&tree_ll); + if(!error) error = generateFixedDistanceTree(&tree_d); + + if(!error) { + writeBits(writer, BFINAL, 1); + writeBits(writer, 1, 1); /*first bit of BTYPE*/ + writeBits(writer, 0, 1); /*second bit of BTYPE*/ + + if(settings->use_lz77) /*LZ77 encoded*/ { + uivector lz77_encoded; + uivector_init(&lz77_encoded); + error = encodeLZ77(&lz77_encoded, hash, data, datapos, dataend, settings->windowsize, + settings->minmatch, settings->nicematch, settings->lazymatching); + if(!error) writeLZ77data(writer, &lz77_encoded, &tree_ll, &tree_d); + uivector_cleanup(&lz77_encoded); + } else /*no LZ77, but still will be Huffman compressed*/ { + for(i = datapos; i < dataend; ++i) { + writeBitsReversed(writer, tree_ll.codes[data[i]], tree_ll.lengths[data[i]]); + } + } + /*add END code*/ + if(!error) writeBitsReversed(writer,tree_ll.codes[256], tree_ll.lengths[256]); + } + + /*cleanup*/ + HuffmanTree_cleanup(&tree_ll); + HuffmanTree_cleanup(&tree_d); + + return error; +} + +static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings) { + unsigned error = 0; + size_t i, blocksize, numdeflateblocks; + Hash hash; + LodePNGBitWriter writer; + + LodePNGBitWriter_init(&writer, out); + + if(settings->btype > 2) return 61; + else if(settings->btype == 0) return deflateNoCompression(out, in, insize); + else if(settings->btype == 1) blocksize = insize; + else /*if(settings->btype == 2)*/ { + /*on PNGs, deflate blocks of 65-262k seem to give most dense encoding*/ + blocksize = insize / 8u + 8; + if(blocksize < 65536) blocksize = 65536; + if(blocksize > 262144) blocksize = 262144; + } + + numdeflateblocks = (insize + blocksize - 1) / blocksize; + if(numdeflateblocks == 0) numdeflateblocks = 1; + + error = hash_init(&hash, settings->windowsize); + + if(!error) { + for(i = 0; i != numdeflateblocks && !error; ++i) { + unsigned final = (i == numdeflateblocks - 1); + size_t start = i * blocksize; + size_t end = start + blocksize; + if(end > insize) end = insize; + + if(settings->btype == 1) error = deflateFixed(&writer, &hash, in, start, end, settings, final); + else if(settings->btype == 2) error = deflateDynamic(&writer, &hash, in, start, end, settings, final); + } + } + + hash_cleanup(&hash); + + return error; +} + +unsigned lodepng_deflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings) { + ucvector v = ucvector_init(*out, *outsize); + unsigned error = lodepng_deflatev(&v, in, insize, settings); + *out = v.data; + *outsize = v.size; + return error; +} + +static unsigned deflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings) { + if(settings->custom_deflate) { + return settings->custom_deflate(out, outsize, in, insize, settings); + } else { + return lodepng_deflate(out, outsize, in, insize, settings); + } +} + +#endif /*LODEPNG_COMPILE_DECODER*/ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Adler32 / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +static unsigned update_adler32(unsigned adler, const unsigned char* data, unsigned len) { + unsigned s1 = adler & 0xffffu; + unsigned s2 = (adler >> 16u) & 0xffffu; + + while(len != 0u) { + unsigned i; + /*at least 5552 sums can be done before the sums overflow, saving a lot of module divisions*/ + unsigned amount = len > 5552u ? 5552u : len; + len -= amount; + for(i = 0; i != amount; ++i) { + s1 += (*data++); + s2 += s1; + } + s1 %= 65521u; + s2 %= 65521u; + } + + return (s2 << 16u) | s1; +} + +/*Return the adler32 of the bytes data[0..len-1]*/ +static unsigned adler32(const unsigned char* data, unsigned len) { + return update_adler32(1u, data, len); +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Zlib / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_DECODER + +static unsigned lodepng_zlib_decompressv(ucvector* out, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings) { + unsigned error = 0; + unsigned CM, CINFO, FDICT; + + if(insize < 2) return 53; /*error, size of zlib data too small*/ + /*read information from zlib header*/ + if((in[0] * 256 + in[1]) % 31 != 0) { + /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/ + return 24; + } + + CM = in[0] & 15; + CINFO = (in[0] >> 4) & 15; + /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/ + FDICT = (in[1] >> 5) & 1; + /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/ + + if(CM != 8 || CINFO > 7) { + /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/ + return 25; + } + if(FDICT != 0) { + /*error: the specification of PNG says about the zlib stream: + "The additional flags shall not specify a preset dictionary."*/ + return 26; + } + + error = inflatev(out, in + 2, insize - 2, settings); + if(error) return error; + + if(!settings->ignore_adler32) { + unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]); + unsigned checksum = adler32(out->data, (unsigned)(out->size)); + if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/ + } + + return 0; /*no error*/ +} + + +unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, + size_t insize, const LodePNGDecompressSettings* settings) { + ucvector v = ucvector_init(*out, *outsize); + unsigned error = lodepng_zlib_decompressv(&v, in, insize, settings); + *out = v.data; + *outsize = v.size; + return error; +} + +/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */ +static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size, + const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { + if(settings->custom_zlib) { + return settings->custom_zlib(out, outsize, in, insize, settings); + } else { + unsigned error; + ucvector v = ucvector_init(*out, *outsize); + if(expected_size) { + /*reserve the memory to avoid intermediate reallocations*/ + ucvector_resize(&v, *outsize + expected_size); + v.size = *outsize; + } + error = lodepng_zlib_decompressv(&v, in, insize, settings); + *out = v.data; + *outsize = v.size; + return error; + } +} + +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER + +unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, + size_t insize, const LodePNGCompressSettings* settings) { + size_t i; + unsigned error; + unsigned char* deflatedata = 0; + size_t deflatesize = 0; + + error = deflate(&deflatedata, &deflatesize, in, insize, settings); + + *out = NULL; + *outsize = 0; + if(!error) { + *outsize = deflatesize + 6; + *out = (unsigned char*)lodepng_malloc(*outsize); + if(!*out) error = 83; /*alloc fail*/ + } + + if(!error) { + unsigned ADLER32 = adler32(in, (unsigned)insize); + /*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/ + unsigned CMF = 120; /*0b01111000: CM 8, CINFO 7. With CINFO 7, any window size up to 32768 can be used.*/ + unsigned FLEVEL = 0; + unsigned FDICT = 0; + unsigned CMFFLG = 256 * CMF + FDICT * 32 + FLEVEL * 64; + unsigned FCHECK = 31 - CMFFLG % 31; + CMFFLG += FCHECK; + + (*out)[0] = (unsigned char)(CMFFLG >> 8); + (*out)[1] = (unsigned char)(CMFFLG & 255); + for(i = 0; i != deflatesize; ++i) (*out)[i + 2] = deflatedata[i]; + lodepng_set32bitInt(&(*out)[*outsize - 4], ADLER32); + } + + lodepng_free(deflatedata); + return error; +} + +/* compress using the default or custom zlib function */ +static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, + size_t insize, const LodePNGCompressSettings* settings) { + if(settings->custom_zlib) { + return settings->custom_zlib(out, outsize, in, insize, settings); + } else { + return lodepng_zlib_compress(out, outsize, in, insize, settings); + } +} + +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#else /*no LODEPNG_COMPILE_ZLIB*/ + +#ifdef LODEPNG_COMPILE_DECODER +static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size, + const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { + if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ + (void)expected_size; + return settings->custom_zlib(out, outsize, in, insize, settings); +} +#endif /*LODEPNG_COMPILE_DECODER*/ +#ifdef LODEPNG_COMPILE_ENCODER +static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, + size_t insize, const LodePNGCompressSettings* settings) { + if(!settings->custom_zlib) return 87; /*no custom zlib function provided */ + return settings->custom_zlib(out, outsize, in, insize, settings); +} +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#endif /*LODEPNG_COMPILE_ZLIB*/ + +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_ENCODER + +/*this is a good tradeoff between speed and compression ratio*/ +#define DEFAULT_WINDOWSIZE 2048 + +void lodepng_compress_settings_init(LodePNGCompressSettings* settings) { + /*compress with dynamic huffman tree (not in the mathematical sense, just not the predefined one)*/ + settings->btype = 2; + settings->use_lz77 = 1; + settings->windowsize = DEFAULT_WINDOWSIZE; + settings->minmatch = 3; + settings->nicematch = 128; + settings->lazymatching = 1; + + settings->custom_zlib = 0; + settings->custom_deflate = 0; + settings->custom_context = 0; +} + +const LodePNGCompressSettings lodepng_default_compress_settings = {2, 1, DEFAULT_WINDOWSIZE, 3, 128, 1, 0, 0, 0}; + + +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_DECODER + +void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings) { + settings->ignore_adler32 = 0; + settings->ignore_nlen = 0; + + settings->custom_zlib = 0; + settings->custom_inflate = 0; + settings->custom_context = 0; +} + +const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0, 0, 0}; + +#endif /*LODEPNG_COMPILE_DECODER*/ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* // End of Zlib related code. Begin of PNG related code. // */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_PNG + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / CRC32 / */ +/* ////////////////////////////////////////////////////////////////////////// */ + + +#ifndef LODEPNG_NO_COMPILE_CRC +/* CRC polynomial: 0xedb88320 */ +static unsigned lodepng_crc32_table[256] = { + 0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u, + 249268274u, 2044508324u, 3772115230u, 2547177864u, 162941995u, 2125561021u, 3887607047u, 2428444049u, + 498536548u, 1789927666u, 4089016648u, 2227061214u, 450548861u, 1843258603u, 4107580753u, 2211677639u, + 325883990u, 1684777152u, 4251122042u, 2321926636u, 335633487u, 1661365465u, 4195302755u, 2366115317u, + 997073096u, 1281953886u, 3579855332u, 2724688242u, 1006888145u, 1258607687u, 3524101629u, 2768942443u, + 901097722u, 1119000684u, 3686517206u, 2898065728u, 853044451u, 1172266101u, 3705015759u, 2882616665u, + 651767980u, 1373503546u, 3369554304u, 3218104598u, 565507253u, 1454621731u, 3485111705u, 3099436303u, + 671266974u, 1594198024u, 3322730930u, 2970347812u, 795835527u, 1483230225u, 3244367275u, 3060149565u, + 1994146192u, 31158534u, 2563907772u, 4023717930u, 1907459465u, 112637215u, 2680153253u, 3904427059u, + 2013776290u, 251722036u, 2517215374u, 3775830040u, 2137656763u, 141376813u, 2439277719u, 3865271297u, + 1802195444u, 476864866u, 2238001368u, 4066508878u, 1812370925u, 453092731u, 2181625025u, 4111451223u, + 1706088902u, 314042704u, 2344532202u, 4240017532u, 1658658271u, 366619977u, 2362670323u, 4224994405u, + 1303535960u, 984961486u, 2747007092u, 3569037538u, 1256170817u, 1037604311u, 2765210733u, 3554079995u, + 1131014506u, 879679996u, 2909243462u, 3663771856u, 1141124467u, 855842277u, 2852801631u, 3708648649u, + 1342533948u, 654459306u, 3188396048u, 3373015174u, 1466479909u, 544179635u, 3110523913u, 3462522015u, + 1591671054u, 702138776u, 2966460450u, 3352799412u, 1504918807u, 783551873u, 3082640443u, 3233442989u, + 3988292384u, 2596254646u, 62317068u, 1957810842u, 3939845945u, 2647816111u, 81470997u, 1943803523u, + 3814918930u, 2489596804u, 225274430u, 2053790376u, 3826175755u, 2466906013u, 167816743u, 2097651377u, + 4027552580u, 2265490386u, 503444072u, 1762050814u, 4150417245u, 2154129355u, 426522225u, 1852507879u, + 4275313526u, 2312317920u, 282753626u, 1742555852u, 4189708143u, 2394877945u, 397917763u, 1622183637u, + 3604390888u, 2714866558u, 953729732u, 1340076626u, 3518719985u, 2797360999u, 1068828381u, 1219638859u, + 3624741850u, 2936675148u, 906185462u, 1090812512u, 3747672003u, 2825379669u, 829329135u, 1181335161u, + 3412177804u, 3160834842u, 628085408u, 1382605366u, 3423369109u, 3138078467u, 570562233u, 1426400815u, + 3317316542u, 2998733608u, 733239954u, 1555261956u, 3268935591u, 3050360625u, 752459403u, 1541320221u, + 2607071920u, 3965973030u, 1969922972u, 40735498u, 2617837225u, 3943577151u, 1913087877u, 83908371u, + 2512341634u, 3803740692u, 2075208622u, 213261112u, 2463272603u, 3855990285u, 2094854071u, 198958881u, + 2262029012u, 4057260610u, 1759359992u, 534414190u, 2176718541u, 4139329115u, 1873836001u, 414664567u, + 2282248934u, 4279200368u, 1711684554u, 285281116u, 2405801727u, 4167216745u, 1634467795u, 376229701u, + 2685067896u, 3608007406u, 1308918612u, 956543938u, 2808555105u, 3495958263u, 1231636301u, 1047427035u, + 2932959818u, 3654703836u, 1088359270u, 936918000u, 2847714899u, 3736837829u, 1202900863u, 817233897u, + 3183342108u, 3401237130u, 1404277552u, 615818150u, 3134207493u, 3453421203u, 1423857449u, 601450431u, + 3009837614u, 3294710456u, 1567103746u, 711928724u, 3020668471u, 3272380065u, 1510334235u, 755167117u +}; + +/*Return the CRC of the bytes buf[0..len-1].*/ +unsigned lodepng_crc32(const unsigned char* data, size_t length) { + unsigned r = 0xffffffffu; + size_t i; + for(i = 0; i < length; ++i) { + r = lodepng_crc32_table[(r ^ data[i]) & 0xffu] ^ (r >> 8u); + } + return r ^ 0xffffffffu; +} +#else /* !LODEPNG_NO_COMPILE_CRC */ +unsigned lodepng_crc32(const unsigned char* data, size_t length); +#endif /* !LODEPNG_NO_COMPILE_CRC */ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Reading and writing PNG color channel bits / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/* The color channel bits of less-than-8-bit pixels are read with the MSB of bytes first, +so LodePNGBitWriter and LodePNGBitReader can't be used for those. */ + +static unsigned char readBitFromReversedStream(size_t* bitpointer, const unsigned char* bitstream) { + unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1); + ++(*bitpointer); + return result; +} + +/* TODO: make this faster */ +static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits) { + unsigned result = 0; + size_t i; + for(i = 0 ; i < nbits; ++i) { + result <<= 1u; + result |= (unsigned)readBitFromReversedStream(bitpointer, bitstream); + } + return result; +} + +static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, unsigned char bit) { + /*the current bit in bitstream may be 0 or 1 for this to work*/ + if(bit == 0) bitstream[(*bitpointer) >> 3u] &= (unsigned char)(~(1u << (7u - ((*bitpointer) & 7u)))); + else bitstream[(*bitpointer) >> 3u] |= (1u << (7u - ((*bitpointer) & 7u))); + ++(*bitpointer); +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / PNG chunks / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +unsigned lodepng_chunk_length(const unsigned char* chunk) { + return lodepng_read32bitInt(&chunk[0]); +} + +void lodepng_chunk_type(char type[5], const unsigned char* chunk) { + unsigned i; + for(i = 0; i != 4; ++i) type[i] = (char)chunk[4 + i]; + type[4] = 0; /*null termination char*/ +} + +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type) { + if(lodepng_strlen(type) != 4) return 0; + return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]); +} + +unsigned char lodepng_chunk_ancillary(const unsigned char* chunk) { + return((chunk[4] & 32) != 0); +} + +unsigned char lodepng_chunk_private(const unsigned char* chunk) { + return((chunk[6] & 32) != 0); +} + +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk) { + return((chunk[7] & 32) != 0); +} + +unsigned char* lodepng_chunk_data(unsigned char* chunk) { + return &chunk[8]; +} + +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk) { + return &chunk[8]; +} + +unsigned lodepng_chunk_check_crc(const unsigned char* chunk) { + unsigned length = lodepng_chunk_length(chunk); + unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]); + /*the CRC is taken of the data and the 4 chunk type letters, not the length*/ + unsigned checksum = lodepng_crc32(&chunk[4], length + 4); + if(CRC != checksum) return 1; + else return 0; +} + +void lodepng_chunk_generate_crc(unsigned char* chunk) { + unsigned length = lodepng_chunk_length(chunk); + unsigned CRC = lodepng_crc32(&chunk[4], length + 4); + lodepng_set32bitInt(chunk + 8 + length, CRC); +} + +unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end) { + if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/ + if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 + && chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) { + /* Is PNG magic header at start of PNG file. Jump to first actual chunk. */ + return chunk + 8; + } else { + size_t total_chunk_length; + unsigned char* result; + if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; + result = chunk + total_chunk_length; + if(result < chunk) return end; /*pointer overflow*/ + return result; + } +} + +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end) { + if(chunk >= end || end - chunk < 12) return end; /*too small to contain a chunk*/ + if(chunk[0] == 0x89 && chunk[1] == 0x50 && chunk[2] == 0x4e && chunk[3] == 0x47 + && chunk[4] == 0x0d && chunk[5] == 0x0a && chunk[6] == 0x1a && chunk[7] == 0x0a) { + /* Is PNG magic header at start of PNG file. Jump to first actual chunk. */ + return chunk + 8; + } else { + size_t total_chunk_length; + const unsigned char* result; + if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return end; + result = chunk + total_chunk_length; + if(result < chunk) return end; /*pointer overflow*/ + return result; + } +} + +unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]) { + for(;;) { + if(chunk >= end || end - chunk < 12) return 0; /* past file end: chunk + 12 > end */ + if(lodepng_chunk_type_equals(chunk, type)) return chunk; + chunk = lodepng_chunk_next(chunk, end); + } +} + +const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]) { + for(;;) { + if(chunk >= end || end - chunk < 12) return 0; /* past file end: chunk + 12 > end */ + if(lodepng_chunk_type_equals(chunk, type)) return chunk; + chunk = lodepng_chunk_next_const(chunk, end); + } +} + +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk) { + unsigned i; + size_t total_chunk_length, new_length; + unsigned char *chunk_start, *new_buffer; + + if(lodepng_addofl(lodepng_chunk_length(chunk), 12, &total_chunk_length)) return 77; + if(lodepng_addofl(*outsize, total_chunk_length, &new_length)) return 77; + + new_buffer = (unsigned char*)lodepng_realloc(*out, new_length); + if(!new_buffer) return 83; /*alloc fail*/ + (*out) = new_buffer; + (*outsize) = new_length; + chunk_start = &(*out)[new_length - total_chunk_length]; + + for(i = 0; i != total_chunk_length; ++i) chunk_start[i] = chunk[i]; + + return 0; +} + +/*Sets length and name and allocates the space for data and crc but does not +set data or crc yet. Returns the start of the chunk in chunk. The start of +the data is at chunk + 8. To finalize chunk, add the data, then use +lodepng_chunk_generate_crc */ +static unsigned lodepng_chunk_init(unsigned char** chunk, + ucvector* out, + unsigned length, const char* type) { + size_t new_length = out->size; + if(lodepng_addofl(new_length, length, &new_length)) return 77; + if(lodepng_addofl(new_length, 12, &new_length)) return 77; + if(!ucvector_resize(out, new_length)) return 83; /*alloc fail*/ + *chunk = out->data + new_length - length - 12u; + + /*1: length*/ + lodepng_set32bitInt(*chunk, length); + + /*2: chunk name (4 letters)*/ + lodepng_memcpy(*chunk + 4, type, 4); + + return 0; +} + +/* like lodepng_chunk_create but with custom allocsize */ +static unsigned lodepng_chunk_createv(ucvector* out, + unsigned length, const char* type, const unsigned char* data) { + unsigned char* chunk; + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, length, type)); + + /*3: the data*/ + lodepng_memcpy(chunk + 8, data, length); + + /*4: CRC (of the chunkname characters and the data)*/ + lodepng_chunk_generate_crc(chunk); + + return 0; +} + +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, + unsigned length, const char* type, const unsigned char* data) { + ucvector v = ucvector_init(*out, *outsize); + unsigned error = lodepng_chunk_createv(&v, length, type, data); + *out = v.data; + *outsize = v.size; + return error; +} + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / Color types, channels, bits / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/*checks if the colortype is valid and the bitdepth bd is allowed for this colortype. +Return value is a LodePNG error code.*/ +static unsigned checkColorValidity(LodePNGColorType colortype, unsigned bd) { + switch(colortype) { + case LCT_GREY: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16)) return 37; break; + case LCT_RGB: if(!( bd == 8 || bd == 16)) return 37; break; + case LCT_PALETTE: if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8 )) return 37; break; + case LCT_GREY_ALPHA: if(!( bd == 8 || bd == 16)) return 37; break; + case LCT_RGBA: if(!( bd == 8 || bd == 16)) return 37; break; + case LCT_MAX_OCTET_VALUE: return 31; /* invalid color type */ + default: return 31; /* invalid color type */ + } + return 0; /*allowed color type / bits combination*/ +} + +static unsigned getNumColorChannels(LodePNGColorType colortype) { + switch(colortype) { + case LCT_GREY: return 1; + case LCT_RGB: return 3; + case LCT_PALETTE: return 1; + case LCT_GREY_ALPHA: return 2; + case LCT_RGBA: return 4; + case LCT_MAX_OCTET_VALUE: return 0; /* invalid color type */ + default: return 0; /*invalid color type*/ + } +} + +static unsigned lodepng_get_bpp_lct(LodePNGColorType colortype, unsigned bitdepth) { + /*bits per pixel is amount of channels * bits per channel*/ + return getNumColorChannels(colortype) * bitdepth; +} + +/* ////////////////////////////////////////////////////////////////////////// */ + +void lodepng_color_mode_init(LodePNGColorMode* info) { + info->key_defined = 0; + info->key_r = info->key_g = info->key_b = 0; + info->colortype = LCT_RGBA; + info->bitdepth = 8; + info->palette = 0; + info->palettesize = 0; +} + +/*allocates palette memory if needed, and initializes all colors to black*/ +static void lodepng_color_mode_alloc_palette(LodePNGColorMode* info) { + size_t i; + /*if the palette is already allocated, it will have size 1024 so no reallocation needed in that case*/ + /*the palette must have room for up to 256 colors with 4 bytes each.*/ + if(!info->palette) info->palette = (unsigned char*)lodepng_malloc(1024); + if(!info->palette) return; /*alloc fail*/ + for(i = 0; i != 256; ++i) { + /*Initialize all unused colors with black, the value used for invalid palette indices. + This is an error according to the PNG spec, but common PNG decoders make it black instead. + That makes color conversion slightly faster due to no error handling needed.*/ + info->palette[i * 4 + 0] = 0; + info->palette[i * 4 + 1] = 0; + info->palette[i * 4 + 2] = 0; + info->palette[i * 4 + 3] = 255; + } +} + +void lodepng_color_mode_cleanup(LodePNGColorMode* info) { + lodepng_palette_clear(info); +} + +unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source) { + lodepng_color_mode_cleanup(dest); + lodepng_memcpy(dest, source, sizeof(LodePNGColorMode)); + if(source->palette) { + dest->palette = (unsigned char*)lodepng_malloc(1024); + if(!dest->palette && source->palettesize) return 83; /*alloc fail*/ + lodepng_memcpy(dest->palette, source->palette, source->palettesize * 4); + } + return 0; +} + +LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth) { + LodePNGColorMode result; + lodepng_color_mode_init(&result); + result.colortype = colortype; + result.bitdepth = bitdepth; + return result; +} + +static int lodepng_color_mode_equal(const LodePNGColorMode* a, const LodePNGColorMode* b) { + size_t i; + if(a->colortype != b->colortype) return 0; + if(a->bitdepth != b->bitdepth) return 0; + if(a->key_defined != b->key_defined) return 0; + if(a->key_defined) { + if(a->key_r != b->key_r) return 0; + if(a->key_g != b->key_g) return 0; + if(a->key_b != b->key_b) return 0; + } + if(a->palettesize != b->palettesize) return 0; + for(i = 0; i != a->palettesize * 4; ++i) { + if(a->palette[i] != b->palette[i]) return 0; + } + return 1; +} + +void lodepng_palette_clear(LodePNGColorMode* info) { + if(info->palette) lodepng_free(info->palette); + info->palette = 0; + info->palettesize = 0; +} + +unsigned lodepng_palette_add(LodePNGColorMode* info, + unsigned char r, unsigned char g, unsigned char b, unsigned char a) { + if(!info->palette) /*allocate palette if empty*/ { + lodepng_color_mode_alloc_palette(info); + if(!info->palette) return 83; /*alloc fail*/ + } + if(info->palettesize >= 256) { + return 108; /*too many palette values*/ + } + info->palette[4 * info->palettesize + 0] = r; + info->palette[4 * info->palettesize + 1] = g; + info->palette[4 * info->palettesize + 2] = b; + info->palette[4 * info->palettesize + 3] = a; + ++info->palettesize; + return 0; +} + +/*calculate bits per pixel out of colortype and bitdepth*/ +unsigned lodepng_get_bpp(const LodePNGColorMode* info) { + return lodepng_get_bpp_lct(info->colortype, info->bitdepth); +} + +unsigned lodepng_get_channels(const LodePNGColorMode* info) { + return getNumColorChannels(info->colortype); +} + +unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info) { + return info->colortype == LCT_GREY || info->colortype == LCT_GREY_ALPHA; +} + +unsigned lodepng_is_alpha_type(const LodePNGColorMode* info) { + return (info->colortype & 4) != 0; /*4 or 6*/ +} + +unsigned lodepng_is_palette_type(const LodePNGColorMode* info) { + return info->colortype == LCT_PALETTE; +} + +unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info) { + size_t i; + for(i = 0; i != info->palettesize; ++i) { + if(info->palette[i * 4 + 3] < 255) return 1; + } + return 0; +} + +unsigned lodepng_can_have_alpha(const LodePNGColorMode* info) { + return info->key_defined + || lodepng_is_alpha_type(info) + || lodepng_has_palette_alpha(info); +} + +static size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { + size_t bpp = lodepng_get_bpp_lct(colortype, bitdepth); + size_t n = (size_t)w * (size_t)h; + return ((n / 8u) * bpp) + ((n & 7u) * bpp + 7u) / 8u; +} + +size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color) { + return lodepng_get_raw_size_lct(w, h, color->colortype, color->bitdepth); +} + + +#ifdef LODEPNG_COMPILE_PNG + +/*in an idat chunk, each scanline is a multiple of 8 bits, unlike the lodepng output buffer, +and in addition has one extra byte per line: the filter byte. So this gives a larger +result than lodepng_get_raw_size. Set h to 1 to get the size of 1 row including filter byte. */ +static size_t lodepng_get_raw_size_idat(unsigned w, unsigned h, unsigned bpp) { + /* + 1 for the filter byte, and possibly plus padding bits per line. */ + /* Ignoring casts, the expression is equal to (w * bpp + 7) / 8 + 1, but avoids overflow of w * bpp */ + size_t line = ((size_t)(w / 8u) * bpp) + 1u + ((w & 7u) * bpp + 7u) / 8u; + return (size_t)h * line; +} + +#ifdef LODEPNG_COMPILE_DECODER +/*Safely checks whether size_t overflow can be caused due to amount of pixels. +This check is overcautious rather than precise. If this check indicates no overflow, +you can safely compute in a size_t (but not an unsigned): +-(size_t)w * (size_t)h * 8 +-amount of bytes in IDAT (including filter, padding and Adam7 bytes) +-amount of bytes in raw color model +Returns 1 if overflow possible, 0 if not. +*/ +static int lodepng_pixel_overflow(unsigned w, unsigned h, + const LodePNGColorMode* pngcolor, const LodePNGColorMode* rawcolor) { + size_t bpp = LODEPNG_MAX(lodepng_get_bpp(pngcolor), lodepng_get_bpp(rawcolor)); + size_t numpixels, total; + size_t line; /* bytes per line in worst case */ + + if(lodepng_mulofl((size_t)w, (size_t)h, &numpixels)) return 1; + if(lodepng_mulofl(numpixels, 8, &total)) return 1; /* bit pointer with 8-bit color, or 8 bytes per channel color */ + + /* Bytes per scanline with the expression "(w / 8u) * bpp) + ((w & 7u) * bpp + 7u) / 8u" */ + if(lodepng_mulofl((size_t)(w / 8u), bpp, &line)) return 1; + if(lodepng_addofl(line, ((w & 7u) * bpp + 7u) / 8u, &line)) return 1; + + if(lodepng_addofl(line, 5, &line)) return 1; /* 5 bytes overhead per line: 1 filterbyte, 4 for Adam7 worst case */ + if(lodepng_mulofl(line, h, &total)) return 1; /* Total bytes in worst case */ + + return 0; /* no overflow */ +} +#endif /*LODEPNG_COMPILE_DECODER*/ +#endif /*LODEPNG_COMPILE_PNG*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + +static void LodePNGUnknownChunks_init(LodePNGInfo* info) { + unsigned i; + for(i = 0; i != 3; ++i) info->unknown_chunks_data[i] = 0; + for(i = 0; i != 3; ++i) info->unknown_chunks_size[i] = 0; +} + +static void LodePNGUnknownChunks_cleanup(LodePNGInfo* info) { + unsigned i; + for(i = 0; i != 3; ++i) lodepng_free(info->unknown_chunks_data[i]); +} + +static unsigned LodePNGUnknownChunks_copy(LodePNGInfo* dest, const LodePNGInfo* src) { + unsigned i; + + LodePNGUnknownChunks_cleanup(dest); + + for(i = 0; i != 3; ++i) { + size_t j; + dest->unknown_chunks_size[i] = src->unknown_chunks_size[i]; + dest->unknown_chunks_data[i] = (unsigned char*)lodepng_malloc(src->unknown_chunks_size[i]); + if(!dest->unknown_chunks_data[i] && dest->unknown_chunks_size[i]) return 83; /*alloc fail*/ + for(j = 0; j < src->unknown_chunks_size[i]; ++j) { + dest->unknown_chunks_data[i][j] = src->unknown_chunks_data[i][j]; + } + } + + return 0; +} + +/******************************************************************************/ + +static void LodePNGText_init(LodePNGInfo* info) { + info->text_num = 0; + info->text_keys = NULL; + info->text_strings = NULL; +} + +static void LodePNGText_cleanup(LodePNGInfo* info) { + size_t i; + for(i = 0; i != info->text_num; ++i) { + string_cleanup(&info->text_keys[i]); + string_cleanup(&info->text_strings[i]); + } + lodepng_free(info->text_keys); + lodepng_free(info->text_strings); +} + +static unsigned LodePNGText_copy(LodePNGInfo* dest, const LodePNGInfo* source) { + size_t i = 0; + dest->text_keys = 0; + dest->text_strings = 0; + dest->text_num = 0; + for(i = 0; i != source->text_num; ++i) { + CERROR_TRY_RETURN(lodepng_add_text(dest, source->text_keys[i], source->text_strings[i])); + } + return 0; +} + +static unsigned lodepng_add_text_sized(LodePNGInfo* info, const char* key, const char* str, size_t size) { + char** new_keys = (char**)(lodepng_realloc(info->text_keys, sizeof(char*) * (info->text_num + 1))); + char** new_strings = (char**)(lodepng_realloc(info->text_strings, sizeof(char*) * (info->text_num + 1))); + + if(new_keys) info->text_keys = new_keys; + if(new_strings) info->text_strings = new_strings; + + if(!new_keys || !new_strings) return 83; /*alloc fail*/ + + ++info->text_num; + info->text_keys[info->text_num - 1] = alloc_string(key); + info->text_strings[info->text_num - 1] = alloc_string_sized(str, size); + if(!info->text_keys[info->text_num - 1] || !info->text_strings[info->text_num - 1]) return 83; /*alloc fail*/ + + return 0; +} + +unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str) { + return lodepng_add_text_sized(info, key, str, lodepng_strlen(str)); +} + +void lodepng_clear_text(LodePNGInfo* info) { + LodePNGText_cleanup(info); +} + +/******************************************************************************/ + +static void LodePNGIText_init(LodePNGInfo* info) { + info->itext_num = 0; + info->itext_keys = NULL; + info->itext_langtags = NULL; + info->itext_transkeys = NULL; + info->itext_strings = NULL; +} + +static void LodePNGIText_cleanup(LodePNGInfo* info) { + size_t i; + for(i = 0; i != info->itext_num; ++i) { + string_cleanup(&info->itext_keys[i]); + string_cleanup(&info->itext_langtags[i]); + string_cleanup(&info->itext_transkeys[i]); + string_cleanup(&info->itext_strings[i]); + } + lodepng_free(info->itext_keys); + lodepng_free(info->itext_langtags); + lodepng_free(info->itext_transkeys); + lodepng_free(info->itext_strings); +} + +static unsigned LodePNGIText_copy(LodePNGInfo* dest, const LodePNGInfo* source) { + size_t i = 0; + dest->itext_keys = 0; + dest->itext_langtags = 0; + dest->itext_transkeys = 0; + dest->itext_strings = 0; + dest->itext_num = 0; + for(i = 0; i != source->itext_num; ++i) { + CERROR_TRY_RETURN(lodepng_add_itext(dest, source->itext_keys[i], source->itext_langtags[i], + source->itext_transkeys[i], source->itext_strings[i])); + } + return 0; +} + +void lodepng_clear_itext(LodePNGInfo* info) { + LodePNGIText_cleanup(info); +} + +static unsigned lodepng_add_itext_sized(LodePNGInfo* info, const char* key, const char* langtag, + const char* transkey, const char* str, size_t size) { + char** new_keys = (char**)(lodepng_realloc(info->itext_keys, sizeof(char*) * (info->itext_num + 1))); + char** new_langtags = (char**)(lodepng_realloc(info->itext_langtags, sizeof(char*) * (info->itext_num + 1))); + char** new_transkeys = (char**)(lodepng_realloc(info->itext_transkeys, sizeof(char*) * (info->itext_num + 1))); + char** new_strings = (char**)(lodepng_realloc(info->itext_strings, sizeof(char*) * (info->itext_num + 1))); + + if(new_keys) info->itext_keys = new_keys; + if(new_langtags) info->itext_langtags = new_langtags; + if(new_transkeys) info->itext_transkeys = new_transkeys; + if(new_strings) info->itext_strings = new_strings; + + if(!new_keys || !new_langtags || !new_transkeys || !new_strings) return 83; /*alloc fail*/ + + ++info->itext_num; + + info->itext_keys[info->itext_num - 1] = alloc_string(key); + info->itext_langtags[info->itext_num - 1] = alloc_string(langtag); + info->itext_transkeys[info->itext_num - 1] = alloc_string(transkey); + info->itext_strings[info->itext_num - 1] = alloc_string_sized(str, size); + + return 0; +} + +unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, + const char* transkey, const char* str) { + return lodepng_add_itext_sized(info, key, langtag, transkey, str, lodepng_strlen(str)); +} + +/* same as set but does not delete */ +static unsigned lodepng_assign_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) { + if(profile_size == 0) return 100; /*invalid ICC profile size*/ + + info->iccp_name = alloc_string(name); + info->iccp_profile = (unsigned char*)lodepng_malloc(profile_size); + + if(!info->iccp_name || !info->iccp_profile) return 83; /*alloc fail*/ + + lodepng_memcpy(info->iccp_profile, profile, profile_size); + info->iccp_profile_size = profile_size; + + return 0; /*ok*/ +} + +unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size) { + if(info->iccp_name) lodepng_clear_icc(info); + info->iccp_defined = 1; + + return lodepng_assign_icc(info, name, profile, profile_size); +} + +void lodepng_clear_icc(LodePNGInfo* info) { + string_cleanup(&info->iccp_name); + lodepng_free(info->iccp_profile); + info->iccp_profile = NULL; + info->iccp_profile_size = 0; + info->iccp_defined = 0; +} +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +void lodepng_info_init(LodePNGInfo* info) { + lodepng_color_mode_init(&info->color); + info->interlace_method = 0; + info->compression_method = 0; + info->filter_method = 0; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + info->background_defined = 0; + info->background_r = info->background_g = info->background_b = 0; + + LodePNGText_init(info); + LodePNGIText_init(info); + + info->time_defined = 0; + info->phys_defined = 0; + + info->gama_defined = 0; + info->chrm_defined = 0; + info->srgb_defined = 0; + info->iccp_defined = 0; + info->iccp_name = NULL; + info->iccp_profile = NULL; + + LodePNGUnknownChunks_init(info); +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} + +void lodepng_info_cleanup(LodePNGInfo* info) { + lodepng_color_mode_cleanup(&info->color); +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + LodePNGText_cleanup(info); + LodePNGIText_cleanup(info); + + lodepng_clear_icc(info); + + LodePNGUnknownChunks_cleanup(info); +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} + +unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source) { + lodepng_info_cleanup(dest); + lodepng_memcpy(dest, source, sizeof(LodePNGInfo)); + lodepng_color_mode_init(&dest->color); + CERROR_TRY_RETURN(lodepng_color_mode_copy(&dest->color, &source->color)); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + CERROR_TRY_RETURN(LodePNGText_copy(dest, source)); + CERROR_TRY_RETURN(LodePNGIText_copy(dest, source)); + if(source->iccp_defined) { + CERROR_TRY_RETURN(lodepng_assign_icc(dest, source->iccp_name, source->iccp_profile, source->iccp_profile_size)); + } + + LodePNGUnknownChunks_init(dest); + CERROR_TRY_RETURN(LodePNGUnknownChunks_copy(dest, source)); +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + return 0; +} + +/* ////////////////////////////////////////////////////////////////////////// */ + +/*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/ +static void addColorBits(unsigned char* out, size_t index, unsigned bits, unsigned in) { + unsigned m = bits == 1 ? 7 : bits == 2 ? 3 : 1; /*8 / bits - 1*/ + /*p = the partial index in the byte, e.g. with 4 palettebits it is 0 for first half or 1 for second half*/ + unsigned p = index & m; + in &= (1u << bits) - 1u; /*filter out any other bits of the input value*/ + in = in << (bits * (m - p)); + if(p == 0) out[index * bits / 8u] = in; + else out[index * bits / 8u] |= in; +} + +typedef struct ColorTree ColorTree; + +/* +One node of a color tree +This is the data structure used to count the number of unique colors and to get a palette +index for a color. It's like an octree, but because the alpha channel is used too, each +node has 16 instead of 8 children. +*/ +struct ColorTree { + ColorTree* children[16]; /*up to 16 pointers to ColorTree of next level*/ + int index; /*the payload. Only has a meaningful value if this is in the last level*/ +}; + +static void color_tree_init(ColorTree* tree) { + lodepng_memset(tree->children, 0, 16 * sizeof(*tree->children)); + tree->index = -1; +} + +static void color_tree_cleanup(ColorTree* tree) { + int i; + for(i = 0; i != 16; ++i) { + if(tree->children[i]) { + color_tree_cleanup(tree->children[i]); + lodepng_free(tree->children[i]); + } + } +} + +/*returns -1 if color not present, its index otherwise*/ +static int color_tree_get(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { + int bit = 0; + for(bit = 0; bit < 8; ++bit) { + int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1); + if(!tree->children[i]) return -1; + else tree = tree->children[i]; + } + return tree ? tree->index : -1; +} + +#ifdef LODEPNG_COMPILE_ENCODER +static int color_tree_has(ColorTree* tree, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { + return color_tree_get(tree, r, g, b, a) >= 0; +} +#endif /*LODEPNG_COMPILE_ENCODER*/ + +/*color is not allowed to already exist. +Index should be >= 0 (it's signed to be compatible with using -1 for "doesn't exist") +Returns error code, or 0 if ok*/ +static unsigned color_tree_add(ColorTree* tree, + unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned index) { + int bit; + for(bit = 0; bit < 8; ++bit) { + int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1); + if(!tree->children[i]) { + tree->children[i] = (ColorTree*)lodepng_malloc(sizeof(ColorTree)); + if(!tree->children[i]) return 83; /*alloc fail*/ + color_tree_init(tree->children[i]); + } + tree = tree->children[i]; + } + tree->index = (int)index; + return 0; +} + +/*put a pixel, given its RGBA color, into image of any color type*/ +static unsigned rgba8ToPixel(unsigned char* out, size_t i, + const LodePNGColorMode* mode, ColorTree* tree /*for palette*/, + unsigned char r, unsigned char g, unsigned char b, unsigned char a) { + if(mode->colortype == LCT_GREY) { + unsigned char gray = r; /*((unsigned short)r + g + b) / 3u;*/ + if(mode->bitdepth == 8) out[i] = gray; + else if(mode->bitdepth == 16) out[i * 2 + 0] = out[i * 2 + 1] = gray; + else { + /*take the most significant bits of gray*/ + gray = ((unsigned)gray >> (8u - mode->bitdepth)) & ((1u << mode->bitdepth) - 1u); + addColorBits(out, i, mode->bitdepth, gray); + } + } else if(mode->colortype == LCT_RGB) { + if(mode->bitdepth == 8) { + out[i * 3 + 0] = r; + out[i * 3 + 1] = g; + out[i * 3 + 2] = b; + } else { + out[i * 6 + 0] = out[i * 6 + 1] = r; + out[i * 6 + 2] = out[i * 6 + 3] = g; + out[i * 6 + 4] = out[i * 6 + 5] = b; + } + } else if(mode->colortype == LCT_PALETTE) { + int index = color_tree_get(tree, r, g, b, a); + if(index < 0) return 82; /*color not in palette*/ + if(mode->bitdepth == 8) out[i] = index; + else addColorBits(out, i, mode->bitdepth, (unsigned)index); + } else if(mode->colortype == LCT_GREY_ALPHA) { + unsigned char gray = r; /*((unsigned short)r + g + b) / 3u;*/ + if(mode->bitdepth == 8) { + out[i * 2 + 0] = gray; + out[i * 2 + 1] = a; + } else if(mode->bitdepth == 16) { + out[i * 4 + 0] = out[i * 4 + 1] = gray; + out[i * 4 + 2] = out[i * 4 + 3] = a; + } + } else if(mode->colortype == LCT_RGBA) { + if(mode->bitdepth == 8) { + out[i * 4 + 0] = r; + out[i * 4 + 1] = g; + out[i * 4 + 2] = b; + out[i * 4 + 3] = a; + } else { + out[i * 8 + 0] = out[i * 8 + 1] = r; + out[i * 8 + 2] = out[i * 8 + 3] = g; + out[i * 8 + 4] = out[i * 8 + 5] = b; + out[i * 8 + 6] = out[i * 8 + 7] = a; + } + } + + return 0; /*no error*/ +} + +/*put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/ +static void rgba16ToPixel(unsigned char* out, size_t i, + const LodePNGColorMode* mode, + unsigned short r, unsigned short g, unsigned short b, unsigned short a) { + if(mode->colortype == LCT_GREY) { + unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ + out[i * 2 + 0] = (gray >> 8) & 255; + out[i * 2 + 1] = gray & 255; + } else if(mode->colortype == LCT_RGB) { + out[i * 6 + 0] = (r >> 8) & 255; + out[i * 6 + 1] = r & 255; + out[i * 6 + 2] = (g >> 8) & 255; + out[i * 6 + 3] = g & 255; + out[i * 6 + 4] = (b >> 8) & 255; + out[i * 6 + 5] = b & 255; + } else if(mode->colortype == LCT_GREY_ALPHA) { + unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ + out[i * 4 + 0] = (gray >> 8) & 255; + out[i * 4 + 1] = gray & 255; + out[i * 4 + 2] = (a >> 8) & 255; + out[i * 4 + 3] = a & 255; + } else if(mode->colortype == LCT_RGBA) { + out[i * 8 + 0] = (r >> 8) & 255; + out[i * 8 + 1] = r & 255; + out[i * 8 + 2] = (g >> 8) & 255; + out[i * 8 + 3] = g & 255; + out[i * 8 + 4] = (b >> 8) & 255; + out[i * 8 + 5] = b & 255; + out[i * 8 + 6] = (a >> 8) & 255; + out[i * 8 + 7] = a & 255; + } +} + +/*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ +static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, + unsigned char* b, unsigned char* a, + const unsigned char* in, size_t i, + const LodePNGColorMode* mode) { + if(mode->colortype == LCT_GREY) { + if(mode->bitdepth == 8) { + *r = *g = *b = in[i]; + if(mode->key_defined && *r == mode->key_r) *a = 0; + else *a = 255; + } else if(mode->bitdepth == 16) { + *r = *g = *b = in[i * 2 + 0]; + if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; + else *a = 255; + } else { + unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ + size_t j = i * mode->bitdepth; + unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); + *r = *g = *b = (value * 255) / highest; + if(mode->key_defined && value == mode->key_r) *a = 0; + else *a = 255; + } + } else if(mode->colortype == LCT_RGB) { + if(mode->bitdepth == 8) { + *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2]; + if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0; + else *a = 255; + } else { + *r = in[i * 6 + 0]; + *g = in[i * 6 + 2]; + *b = in[i * 6 + 4]; + if(mode->key_defined && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r + && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g + && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; + else *a = 255; + } + } else if(mode->colortype == LCT_PALETTE) { + unsigned index; + if(mode->bitdepth == 8) index = in[i]; + else { + size_t j = i * mode->bitdepth; + index = readBitsFromReversedStream(&j, in, mode->bitdepth); + } + /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ + *r = mode->palette[index * 4 + 0]; + *g = mode->palette[index * 4 + 1]; + *b = mode->palette[index * 4 + 2]; + *a = mode->palette[index * 4 + 3]; + } else if(mode->colortype == LCT_GREY_ALPHA) { + if(mode->bitdepth == 8) { + *r = *g = *b = in[i * 2 + 0]; + *a = in[i * 2 + 1]; + } else { + *r = *g = *b = in[i * 4 + 0]; + *a = in[i * 4 + 2]; + } + } else if(mode->colortype == LCT_RGBA) { + if(mode->bitdepth == 8) { + *r = in[i * 4 + 0]; + *g = in[i * 4 + 1]; + *b = in[i * 4 + 2]; + *a = in[i * 4 + 3]; + } else { + *r = in[i * 8 + 0]; + *g = in[i * 8 + 2]; + *b = in[i * 8 + 4]; + *a = in[i * 8 + 6]; + } + } +} + +/*Similar to getPixelColorRGBA8, but with all the for loops inside of the color +mode test cases, optimized to convert the colors much faster, when converting +to the common case of RGBA with 8 bit per channel. buffer must be RGBA with +enough memory.*/ +static void getPixelColorsRGBA8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, + const unsigned char* LODEPNG_RESTRICT in, + const LodePNGColorMode* mode) { + unsigned num_channels = 4; + size_t i; + if(mode->colortype == LCT_GREY) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i]; + buffer[3] = 255; + } + if(mode->key_defined) { + buffer -= numpixels * num_channels; + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + if(buffer[0] == mode->key_r) buffer[3] = 0; + } + } + } else if(mode->bitdepth == 16) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2]; + buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255; + } + } else { + unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ + size_t j = 0; + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); + buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; + buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255; + } + } + } else if(mode->colortype == LCT_RGB) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + lodepng_memcpy(buffer, &in[i * 3], 3); + buffer[3] = 255; + } + if(mode->key_defined) { + buffer -= numpixels * num_channels; + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + if(buffer[0] == mode->key_r && buffer[1]== mode->key_g && buffer[2] == mode->key_b) buffer[3] = 0; + } + } + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 6 + 0]; + buffer[1] = in[i * 6 + 2]; + buffer[2] = in[i * 6 + 4]; + buffer[3] = mode->key_defined + && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r + && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g + && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b ? 0 : 255; + } + } + } else if(mode->colortype == LCT_PALETTE) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = in[i]; + /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ + lodepng_memcpy(buffer, &mode->palette[index * 4], 4); + } + } else { + size_t j = 0; + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); + /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ + lodepng_memcpy(buffer, &mode->palette[index * 4], 4); + } + } + } else if(mode->colortype == LCT_GREY_ALPHA) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; + buffer[3] = in[i * 2 + 1]; + } + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; + buffer[3] = in[i * 4 + 2]; + } + } + } else if(mode->colortype == LCT_RGBA) { + if(mode->bitdepth == 8) { + lodepng_memcpy(buffer, in, numpixels * 4); + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 8 + 0]; + buffer[1] = in[i * 8 + 2]; + buffer[2] = in[i * 8 + 4]; + buffer[3] = in[i * 8 + 6]; + } + } + } +} + +/*Similar to getPixelColorsRGBA8, but with 3-channel RGB output.*/ +static void getPixelColorsRGB8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels, + const unsigned char* LODEPNG_RESTRICT in, + const LodePNGColorMode* mode) { + const unsigned num_channels = 3; + size_t i; + if(mode->colortype == LCT_GREY) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i]; + } + } else if(mode->bitdepth == 16) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2]; + } + } else { + unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/ + size_t j = 0; + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth); + buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest; + } + } + } else if(mode->colortype == LCT_RGB) { + if(mode->bitdepth == 8) { + lodepng_memcpy(buffer, in, numpixels * 3); + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 6 + 0]; + buffer[1] = in[i * 6 + 2]; + buffer[2] = in[i * 6 + 4]; + } + } + } else if(mode->colortype == LCT_PALETTE) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = in[i]; + /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ + lodepng_memcpy(buffer, &mode->palette[index * 4], 3); + } + } else { + size_t j = 0; + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth); + /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/ + lodepng_memcpy(buffer, &mode->palette[index * 4], 3); + } + } + } else if(mode->colortype == LCT_GREY_ALPHA) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0]; + } + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0]; + } + } + } else if(mode->colortype == LCT_RGBA) { + if(mode->bitdepth == 8) { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + lodepng_memcpy(buffer, &in[i * 4], 3); + } + } else { + for(i = 0; i != numpixels; ++i, buffer += num_channels) { + buffer[0] = in[i * 8 + 0]; + buffer[1] = in[i * 8 + 2]; + buffer[2] = in[i * 8 + 4]; + } + } + } +} + +/*Get RGBA16 color of pixel with index i (y * width + x) from the raw image with +given color type, but the given color type must be 16-bit itself.*/ +static void getPixelColorRGBA16(unsigned short* r, unsigned short* g, unsigned short* b, unsigned short* a, + const unsigned char* in, size_t i, const LodePNGColorMode* mode) { + if(mode->colortype == LCT_GREY) { + *r = *g = *b = 256 * in[i * 2 + 0] + in[i * 2 + 1]; + if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0; + else *a = 65535; + } else if(mode->colortype == LCT_RGB) { + *r = 256u * in[i * 6 + 0] + in[i * 6 + 1]; + *g = 256u * in[i * 6 + 2] + in[i * 6 + 3]; + *b = 256u * in[i * 6 + 4] + in[i * 6 + 5]; + if(mode->key_defined + && 256u * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r + && 256u * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g + && 256u * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b) *a = 0; + else *a = 65535; + } else if(mode->colortype == LCT_GREY_ALPHA) { + *r = *g = *b = 256u * in[i * 4 + 0] + in[i * 4 + 1]; + *a = 256u * in[i * 4 + 2] + in[i * 4 + 3]; + } else if(mode->colortype == LCT_RGBA) { + *r = 256u * in[i * 8 + 0] + in[i * 8 + 1]; + *g = 256u * in[i * 8 + 2] + in[i * 8 + 3]; + *b = 256u * in[i * 8 + 4] + in[i * 8 + 5]; + *a = 256u * in[i * 8 + 6] + in[i * 8 + 7]; + } +} + +unsigned lodepng_convert(unsigned char* out, const unsigned char* in, + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, + unsigned w, unsigned h) { + size_t i; + ColorTree tree; + size_t numpixels = (size_t)w * (size_t)h; + unsigned error = 0; + + if(mode_in->colortype == LCT_PALETTE && !mode_in->palette) { + return 107; /* error: must provide palette if input mode is palette */ + } + + if(lodepng_color_mode_equal(mode_out, mode_in)) { + size_t numbytes = lodepng_get_raw_size(w, h, mode_in); + lodepng_memcpy(out, in, numbytes); + return 0; + } + + if(mode_out->colortype == LCT_PALETTE) { + size_t palettesize = mode_out->palettesize; + const unsigned char* palette = mode_out->palette; + size_t palsize = (size_t)1u << mode_out->bitdepth; + /*if the user specified output palette but did not give the values, assume + they want the values of the input color type (assuming that one is palette). + Note that we never create a new palette ourselves.*/ + if(palettesize == 0) { + palettesize = mode_in->palettesize; + palette = mode_in->palette; + /*if the input was also palette with same bitdepth, then the color types are also + equal, so copy literally. This to preserve the exact indices that were in the PNG + even in case there are duplicate colors in the palette.*/ + if(mode_in->colortype == LCT_PALETTE && mode_in->bitdepth == mode_out->bitdepth) { + size_t numbytes = lodepng_get_raw_size(w, h, mode_in); + lodepng_memcpy(out, in, numbytes); + return 0; + } + } + if(palettesize < palsize) palsize = palettesize; + color_tree_init(&tree); + for(i = 0; i != palsize; ++i) { + const unsigned char* p = &palette[i * 4]; + error = color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned)i); + if(error) break; + } + } + + if(!error) { + if(mode_in->bitdepth == 16 && mode_out->bitdepth == 16) { + for(i = 0; i != numpixels; ++i) { + unsigned short r = 0, g = 0, b = 0, a = 0; + getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); + rgba16ToPixel(out, i, mode_out, r, g, b, a); + } + } else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGBA) { + getPixelColorsRGBA8(out, numpixels, in, mode_in); + } else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB) { + getPixelColorsRGB8(out, numpixels, in, mode_in); + } else { + unsigned char r = 0, g = 0, b = 0, a = 0; + for(i = 0; i != numpixels; ++i) { + getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); + error = rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a); + if(error) break; + } + } + } + + if(mode_out->colortype == LCT_PALETTE) { + color_tree_cleanup(&tree); + } + + return error; +} + + +/* Converts a single rgb color without alpha from one type to another, color bits truncated to +their bitdepth. In case of single channel (gray or palette), only the r channel is used. Slow +function, do not use to process all pixels of an image. Alpha channel not supported on purpose: +this is for bKGD, supporting alpha may prevent it from finding a color in the palette, from the +specification it looks like bKGD should ignore the alpha values of the palette since it can use +any palette index but doesn't have an alpha channel. Idem with ignoring color key. */ +unsigned lodepng_convert_rgb( + unsigned* r_out, unsigned* g_out, unsigned* b_out, + unsigned r_in, unsigned g_in, unsigned b_in, + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in) { + unsigned r = 0, g = 0, b = 0; + unsigned mul = 65535 / ((1u << mode_in->bitdepth) - 1u); /*65535, 21845, 4369, 257, 1*/ + unsigned shift = 16 - mode_out->bitdepth; + + if(mode_in->colortype == LCT_GREY || mode_in->colortype == LCT_GREY_ALPHA) { + r = g = b = r_in * mul; + } else if(mode_in->colortype == LCT_RGB || mode_in->colortype == LCT_RGBA) { + r = r_in * mul; + g = g_in * mul; + b = b_in * mul; + } else if(mode_in->colortype == LCT_PALETTE) { + if(r_in >= mode_in->palettesize) return 82; + r = mode_in->palette[r_in * 4 + 0] * 257u; + g = mode_in->palette[r_in * 4 + 1] * 257u; + b = mode_in->palette[r_in * 4 + 2] * 257u; + } else { + return 31; + } + + /* now convert to output format */ + if(mode_out->colortype == LCT_GREY || mode_out->colortype == LCT_GREY_ALPHA) { + *r_out = r >> shift ; + } else if(mode_out->colortype == LCT_RGB || mode_out->colortype == LCT_RGBA) { + *r_out = r >> shift ; + *g_out = g >> shift ; + *b_out = b >> shift ; + } else if(mode_out->colortype == LCT_PALETTE) { + unsigned i; + /* a 16-bit color cannot be in the palette */ + if((r >> 8) != (r & 255) || (g >> 8) != (g & 255) || (b >> 8) != (b & 255)) return 82; + for(i = 0; i < mode_out->palettesize; i++) { + unsigned j = i * 4; + if((r >> 8) == mode_out->palette[j + 0] && (g >> 8) == mode_out->palette[j + 1] && + (b >> 8) == mode_out->palette[j + 2]) { + *r_out = i; + return 0; + } + } + return 82; + } else { + return 31; + } + + return 0; +} + +#ifdef LODEPNG_COMPILE_ENCODER + +void lodepng_color_stats_init(LodePNGColorStats* stats) { + /*stats*/ + stats->colored = 0; + stats->key = 0; + stats->key_r = stats->key_g = stats->key_b = 0; + stats->alpha = 0; + stats->numcolors = 0; + stats->bits = 1; + stats->numpixels = 0; + /*settings*/ + stats->allow_palette = 1; + stats->allow_greyscale = 1; +} + +/*function used for debug purposes with C++*/ +/*void printColorStats(LodePNGColorStats* p) { + std::cout << "colored: " << (int)p->colored << ", "; + std::cout << "key: " << (int)p->key << ", "; + std::cout << "key_r: " << (int)p->key_r << ", "; + std::cout << "key_g: " << (int)p->key_g << ", "; + std::cout << "key_b: " << (int)p->key_b << ", "; + std::cout << "alpha: " << (int)p->alpha << ", "; + std::cout << "numcolors: " << (int)p->numcolors << ", "; + std::cout << "bits: " << (int)p->bits << std::endl; +}*/ + +/*Returns how many bits needed to represent given value (max 8 bit)*/ +static unsigned getValueRequiredBits(unsigned char value) { + if(value == 0 || value == 255) return 1; + /*The scaling of 2-bit and 4-bit values uses multiples of 85 and 17*/ + if(value % 17 == 0) return value % 85 == 0 ? 2 : 4; + return 8; +} + +/*stats must already have been inited. */ +unsigned lodepng_compute_color_stats(LodePNGColorStats* stats, + const unsigned char* in, unsigned w, unsigned h, + const LodePNGColorMode* mode_in) { + size_t i; + ColorTree tree; + size_t numpixels = (size_t)w * (size_t)h; + unsigned error = 0; + + /* mark things as done already if it would be impossible to have a more expensive case */ + unsigned colored_done = lodepng_is_greyscale_type(mode_in) ? 1 : 0; + unsigned alpha_done = lodepng_can_have_alpha(mode_in) ? 0 : 1; + unsigned numcolors_done = 0; + unsigned bpp = lodepng_get_bpp(mode_in); + unsigned bits_done = (stats->bits == 1 && bpp == 1) ? 1 : 0; + unsigned sixteen = 0; /* whether the input image is 16 bit */ + unsigned maxnumcolors = 257; + if(bpp <= 8) maxnumcolors = LODEPNG_MIN(257, stats->numcolors + (1u << bpp)); + + stats->numpixels += numpixels; + + /*if palette not allowed, no need to compute numcolors*/ + if(!stats->allow_palette) numcolors_done = 1; + + color_tree_init(&tree); + + /*If the stats was already filled in from previous data, fill its palette in tree + and mark things as done already if we know they are the most expensive case already*/ + if(stats->alpha) alpha_done = 1; + if(stats->colored) colored_done = 1; + if(stats->bits == 16) numcolors_done = 1; + if(stats->bits >= bpp) bits_done = 1; + if(stats->numcolors >= maxnumcolors) numcolors_done = 1; + + if(!numcolors_done) { + for(i = 0; i < stats->numcolors; i++) { + const unsigned char* color = &stats->palette[i * 4]; + error = color_tree_add(&tree, color[0], color[1], color[2], color[3], i); + if(error) goto cleanup; + } + } + + /*Check if the 16-bit input is truly 16-bit*/ + if(mode_in->bitdepth == 16 && !sixteen) { + unsigned short r = 0, g = 0, b = 0, a = 0; + for(i = 0; i != numpixels; ++i) { + getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); + if((r & 255) != ((r >> 8) & 255) || (g & 255) != ((g >> 8) & 255) || + (b & 255) != ((b >> 8) & 255) || (a & 255) != ((a >> 8) & 255)) /*first and second byte differ*/ { + stats->bits = 16; + sixteen = 1; + bits_done = 1; + numcolors_done = 1; /*counting colors no longer useful, palette doesn't support 16-bit*/ + break; + } + } + } + + if(sixteen) { + unsigned short r = 0, g = 0, b = 0, a = 0; + + for(i = 0; i != numpixels; ++i) { + getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); + + if(!colored_done && (r != g || r != b)) { + stats->colored = 1; + colored_done = 1; + } + + if(!alpha_done) { + unsigned matchkey = (r == stats->key_r && g == stats->key_g && b == stats->key_b); + if(a != 65535 && (a != 0 || (stats->key && !matchkey))) { + stats->alpha = 1; + stats->key = 0; + alpha_done = 1; + } else if(a == 0 && !stats->alpha && !stats->key) { + stats->key = 1; + stats->key_r = r; + stats->key_g = g; + stats->key_b = b; + } else if(a == 65535 && stats->key && matchkey) { + /* Color key cannot be used if an opaque pixel also has that RGB color. */ + stats->alpha = 1; + stats->key = 0; + alpha_done = 1; + } + } + if(alpha_done && numcolors_done && colored_done && bits_done) break; + } + + if(stats->key && !stats->alpha) { + for(i = 0; i != numpixels; ++i) { + getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in); + if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) { + /* Color key cannot be used if an opaque pixel also has that RGB color. */ + stats->alpha = 1; + stats->key = 0; + alpha_done = 1; + } + } + } + } else /* < 16-bit */ { + unsigned char r = 0, g = 0, b = 0, a = 0; + for(i = 0; i != numpixels; ++i) { + getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); + + if(!bits_done && stats->bits < 8) { + /*only r is checked, < 8 bits is only relevant for grayscale*/ + unsigned bits = getValueRequiredBits(r); + if(bits > stats->bits) stats->bits = bits; + } + bits_done = (stats->bits >= bpp); + + if(!colored_done && (r != g || r != b)) { + stats->colored = 1; + colored_done = 1; + if(stats->bits < 8) stats->bits = 8; /*PNG has no colored modes with less than 8-bit per channel*/ + } + + if(!alpha_done) { + unsigned matchkey = (r == stats->key_r && g == stats->key_g && b == stats->key_b); + if(a != 255 && (a != 0 || (stats->key && !matchkey))) { + stats->alpha = 1; + stats->key = 0; + alpha_done = 1; + if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ + } else if(a == 0 && !stats->alpha && !stats->key) { + stats->key = 1; + stats->key_r = r; + stats->key_g = g; + stats->key_b = b; + } else if(a == 255 && stats->key && matchkey) { + /* Color key cannot be used if an opaque pixel also has that RGB color. */ + stats->alpha = 1; + stats->key = 0; + alpha_done = 1; + if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ + } + } + + if(!numcolors_done) { + if(!color_tree_has(&tree, r, g, b, a)) { + error = color_tree_add(&tree, r, g, b, a, stats->numcolors); + if(error) goto cleanup; + if(stats->numcolors < 256) { + unsigned char* p = stats->palette; + unsigned n = stats->numcolors; + p[n * 4 + 0] = r; + p[n * 4 + 1] = g; + p[n * 4 + 2] = b; + p[n * 4 + 3] = a; + } + ++stats->numcolors; + numcolors_done = stats->numcolors >= maxnumcolors; + } + } + + if(alpha_done && numcolors_done && colored_done && bits_done) break; + } + + if(stats->key && !stats->alpha) { + for(i = 0; i != numpixels; ++i) { + getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in); + if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) { + /* Color key cannot be used if an opaque pixel also has that RGB color. */ + stats->alpha = 1; + stats->key = 0; + alpha_done = 1; + if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ + } + } + } + + /*make the stats's key always 16-bit for consistency - repeat each byte twice*/ + stats->key_r += (stats->key_r << 8); + stats->key_g += (stats->key_g << 8); + stats->key_b += (stats->key_b << 8); + } + +cleanup: + color_tree_cleanup(&tree); + return error; +} + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +/*Adds a single color to the color stats. The stats must already have been inited. The color must be given as 16-bit +(with 2 bytes repeating for 8-bit and 65535 for opaque alpha channel). This function is expensive, do not call it for +all pixels of an image but only for a few additional values. */ +static unsigned lodepng_color_stats_add(LodePNGColorStats* stats, + unsigned r, unsigned g, unsigned b, unsigned a) { + unsigned error = 0; + unsigned char image[8]; + LodePNGColorMode mode; + lodepng_color_mode_init(&mode); + image[0] = r >> 8; image[1] = r; image[2] = g >> 8; image[3] = g; + image[4] = b >> 8; image[5] = b; image[6] = a >> 8; image[7] = a; + mode.bitdepth = 16; + mode.colortype = LCT_RGBA; + error = lodepng_compute_color_stats(stats, image, 1, 1, &mode); + lodepng_color_mode_cleanup(&mode); + return error; +} +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/*Computes a minimal PNG color model that can contain all colors as indicated by the stats. +The stats should be computed with lodepng_compute_color_stats. +mode_in is raw color profile of the image the stats were computed on, to copy palette order from when relevant. +Minimal PNG color model means the color type and bit depth that gives smallest amount of bits in the output image, +e.g. gray if only grayscale pixels, palette if less than 256 colors, color key if only single transparent color, ... +This is used if auto_convert is enabled (it is by default). +*/ +static unsigned auto_choose_color(LodePNGColorMode* mode_out, + const LodePNGColorMode* mode_in, + const LodePNGColorStats* stats) { + unsigned error = 0; + unsigned palettebits; + size_t i, n; + size_t numpixels = stats->numpixels; + unsigned palette_ok, gray_ok; + + unsigned alpha = stats->alpha; + unsigned key = stats->key; + unsigned bits = stats->bits; + + mode_out->key_defined = 0; + + if(key && numpixels <= 16) { + alpha = 1; /*too few pixels to justify tRNS chunk overhead*/ + key = 0; + if(bits < 8) bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/ + } + + gray_ok = !stats->colored; + if(!stats->allow_greyscale) gray_ok = 0; + if(!gray_ok && bits < 8) bits = 8; + + n = stats->numcolors; + palettebits = n <= 2 ? 1 : (n <= 4 ? 2 : (n <= 16 ? 4 : 8)); + palette_ok = n <= 256 && bits <= 8 && n != 0; /*n==0 means likely numcolors wasn't computed*/ + if(numpixels < n * 2) palette_ok = 0; /*don't add palette overhead if image has only a few pixels*/ + if(gray_ok && !alpha && bits <= palettebits) palette_ok = 0; /*gray is less overhead*/ + if(!stats->allow_palette) palette_ok = 0; + + if(palette_ok) { + const unsigned char* p = stats->palette; + lodepng_palette_clear(mode_out); /*remove potential earlier palette*/ + for(i = 0; i != stats->numcolors; ++i) { + error = lodepng_palette_add(mode_out, p[i * 4 + 0], p[i * 4 + 1], p[i * 4 + 2], p[i * 4 + 3]); + if(error) break; + } + + mode_out->colortype = LCT_PALETTE; + mode_out->bitdepth = palettebits; + + if(mode_in->colortype == LCT_PALETTE && mode_in->palettesize >= mode_out->palettesize + && mode_in->bitdepth == mode_out->bitdepth) { + /*If input should have same palette colors, keep original to preserve its order and prevent conversion*/ + lodepng_color_mode_cleanup(mode_out); + lodepng_color_mode_copy(mode_out, mode_in); + } + } else /*8-bit or 16-bit per channel*/ { + mode_out->bitdepth = bits; + mode_out->colortype = alpha ? (gray_ok ? LCT_GREY_ALPHA : LCT_RGBA) + : (gray_ok ? LCT_GREY : LCT_RGB); + if(key) { + unsigned mask = (1u << mode_out->bitdepth) - 1u; /*stats always uses 16-bit, mask converts it*/ + mode_out->key_r = stats->key_r & mask; + mode_out->key_g = stats->key_g & mask; + mode_out->key_b = stats->key_b & mask; + mode_out->key_defined = 1; + } + } + + return error; +} + +#endif /* #ifdef LODEPNG_COMPILE_ENCODER */ + +/* +Paeth predictor, used by PNG filter type 4 +The parameters are of type short, but should come from unsigned chars, the shorts +are only needed to make the paeth calculation correct. +*/ +static unsigned char paethPredictor(short a, short b, short c) { + short pa = LODEPNG_ABS(b - c); + short pb = LODEPNG_ABS(a - c); + short pc = LODEPNG_ABS(a + b - c - c); + /* return input value associated with smallest of pa, pb, pc (with certain priority if equal) */ + if(pb < pa) { a = b; pa = pb; } + return (pc < pa) ? c : a; +} + +/*shared values used by multiple Adam7 related functions*/ + +static const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }; /*x start values*/ +static const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }; /*y start values*/ +static const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }; /*x delta values*/ +static const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }; /*y delta values*/ + +/* +Outputs various dimensions and positions in the image related to the Adam7 reduced images. +passw: output containing the width of the 7 passes +passh: output containing the height of the 7 passes +filter_passstart: output containing the index of the start and end of each + reduced image with filter bytes +padded_passstart output containing the index of the start and end of each + reduced image when without filter bytes but with padded scanlines +passstart: output containing the index of the start and end of each reduced + image without padding between scanlines, but still padding between the images +w, h: width and height of non-interlaced image +bpp: bits per pixel +"padded" is only relevant if bpp is less than 8 and a scanline or image does not + end at a full byte +*/ +static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], + size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp) { + /*the passstart values have 8 values: the 8th one indicates the byte after the end of the 7th (= last) pass*/ + unsigned i; + + /*calculate width and height in pixels of each pass*/ + for(i = 0; i != 7; ++i) { + passw[i] = (w + ADAM7_DX[i] - ADAM7_IX[i] - 1) / ADAM7_DX[i]; + passh[i] = (h + ADAM7_DY[i] - ADAM7_IY[i] - 1) / ADAM7_DY[i]; + if(passw[i] == 0) passh[i] = 0; + if(passh[i] == 0) passw[i] = 0; + } + + filter_passstart[0] = padded_passstart[0] = passstart[0] = 0; + for(i = 0; i != 7; ++i) { + /*if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte)*/ + filter_passstart[i + 1] = filter_passstart[i] + + ((passw[i] && passh[i]) ? passh[i] * (1u + (passw[i] * bpp + 7u) / 8u) : 0); + /*bits padded if needed to fill full byte at end of each scanline*/ + padded_passstart[i + 1] = padded_passstart[i] + passh[i] * ((passw[i] * bpp + 7u) / 8u); + /*only padded at end of reduced image*/ + passstart[i + 1] = passstart[i] + (passh[i] * passw[i] * bpp + 7u) / 8u; + } +} + +#ifdef LODEPNG_COMPILE_DECODER + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / PNG Decoder / */ +/* ////////////////////////////////////////////////////////////////////////// */ + +/*read the information from the header and store it in the LodePNGInfo. return value is error*/ +unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, + const unsigned char* in, size_t insize) { + unsigned width, height; + LodePNGInfo* info = &state->info_png; + if(insize == 0 || in == 0) { + CERROR_RETURN_ERROR(state->error, 48); /*error: the given data is empty*/ + } + if(insize < 33) { + CERROR_RETURN_ERROR(state->error, 27); /*error: the data length is smaller than the length of a PNG header*/ + } + + /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/ + /* TODO: remove this. One should use a new LodePNGState for new sessions */ + lodepng_info_cleanup(info); + lodepng_info_init(info); + + if(in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 + || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) { + CERROR_RETURN_ERROR(state->error, 28); /*error: the first 8 bytes are not the correct PNG signature*/ + } + if(lodepng_chunk_length(in + 8) != 13) { + CERROR_RETURN_ERROR(state->error, 94); /*error: header size must be 13 bytes*/ + } + if(!lodepng_chunk_type_equals(in + 8, "IHDR")) { + CERROR_RETURN_ERROR(state->error, 29); /*error: it doesn't start with a IHDR chunk!*/ + } + + /*read the values given in the header*/ + width = lodepng_read32bitInt(&in[16]); + height = lodepng_read32bitInt(&in[20]); + /*TODO: remove the undocumented feature that allows to give null pointers to width or height*/ + if(w) *w = width; + if(h) *h = height; + info->color.bitdepth = in[24]; + info->color.colortype = (LodePNGColorType)in[25]; + info->compression_method = in[26]; + info->filter_method = in[27]; + info->interlace_method = in[28]; + + /*errors returned only after the parsing so other values are still output*/ + + /*error: invalid image size*/ + if(width == 0 || height == 0) CERROR_RETURN_ERROR(state->error, 93); + /*error: invalid colortype or bitdepth combination*/ + state->error = checkColorValidity(info->color.colortype, info->color.bitdepth); + if(state->error) return state->error; + /*error: only compression method 0 is allowed in the specification*/ + if(info->compression_method != 0) CERROR_RETURN_ERROR(state->error, 32); + /*error: only filter method 0 is allowed in the specification*/ + if(info->filter_method != 0) CERROR_RETURN_ERROR(state->error, 33); + /*error: only interlace methods 0 and 1 exist in the specification*/ + if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34); + + if(!state->decoder.ignore_crc) { + unsigned CRC = lodepng_read32bitInt(&in[29]); + unsigned checksum = lodepng_crc32(&in[12], 17); + if(CRC != checksum) { + CERROR_RETURN_ERROR(state->error, 57); /*invalid CRC*/ + } + } + + return state->error; +} + +static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, + size_t bytewidth, unsigned char filterType, size_t length) { + /* + For PNG filter method 0 + unfilter a PNG image scanline by scanline. when the pixels are smaller than 1 byte, + the filter works byte per byte (bytewidth = 1) + precon is the previous unfiltered scanline, recon the result, scanline the current one + the incoming scanlines do NOT include the filtertype byte, that one is given in the parameter filterType instead + recon and scanline MAY be the same memory address! precon must be disjoint. + */ + + size_t i; + switch(filterType) { + case 0: + for(i = 0; i != length; ++i) recon[i] = scanline[i]; + break; + case 1: + for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i]; + for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + recon[i - bytewidth]; + break; + case 2: + if(precon) { + for(i = 0; i != length; ++i) recon[i] = scanline[i] + precon[i]; + } else { + for(i = 0; i != length; ++i) recon[i] = scanline[i]; + } + break; + case 3: + if(precon) { + for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i] + (precon[i] >> 1u); + for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1u); + } else { + for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i]; + for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1u); + } + break; + case 4: + if(precon) { + for(i = 0; i != bytewidth; ++i) { + recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/ + } + + /* Unroll independent paths of the paeth predictor. A 6x and 8x version would also be possible but that + adds too much code. Whether this actually speeds anything up at all depends on compiler and settings. */ + if(bytewidth >= 4) { + for(; i + 3 < length; i += 4) { + size_t j = i - bytewidth; + unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3]; + unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3]; + unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3]; + unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2], q3 = precon[j + 3]; + recon[i + 0] = s0 + paethPredictor(r0, p0, q0); + recon[i + 1] = s1 + paethPredictor(r1, p1, q1); + recon[i + 2] = s2 + paethPredictor(r2, p2, q2); + recon[i + 3] = s3 + paethPredictor(r3, p3, q3); + } + } else if(bytewidth >= 3) { + for(; i + 2 < length; i += 3) { + size_t j = i - bytewidth; + unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2]; + unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2]; + unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2]; + unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2]; + recon[i + 0] = s0 + paethPredictor(r0, p0, q0); + recon[i + 1] = s1 + paethPredictor(r1, p1, q1); + recon[i + 2] = s2 + paethPredictor(r2, p2, q2); + } + } else if(bytewidth >= 2) { + for(; i + 1 < length; i += 2) { + size_t j = i - bytewidth; + unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1]; + unsigned char r0 = recon[j + 0], r1 = recon[j + 1]; + unsigned char p0 = precon[i + 0], p1 = precon[i + 1]; + unsigned char q0 = precon[j + 0], q1 = precon[j + 1]; + recon[i + 0] = s0 + paethPredictor(r0, p0, q0); + recon[i + 1] = s1 + paethPredictor(r1, p1, q1); + } + } + + for(; i != length; ++i) { + recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth])); + } + } else { + for(i = 0; i != bytewidth; ++i) { + recon[i] = scanline[i]; + } + for(i = bytewidth; i < length; ++i) { + /*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/ + recon[i] = (scanline[i] + recon[i - bytewidth]); + } + } + break; + default: return 36; /*error: invalid filter type given*/ + } + return 0; +} + +static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { + /* + For PNG filter method 0 + this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 seven times) + out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline + w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel + in and out are allowed to be the same memory address (but aren't the same size since in has the extra filter bytes) + */ + + unsigned y; + unsigned char* prevline = 0; + + /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ + size_t bytewidth = (bpp + 7u) / 8u; + /*the width of a scanline in bytes, not including the filter type*/ + size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u; + + for(y = 0; y < h; ++y) { + size_t outindex = linebytes * y; + size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ + unsigned char filterType = in[inindex]; + + CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes)); + + prevline = &out[outindex]; + } + + return 0; +} + +/* +in: Adam7 interlaced image, with no padding bits between scanlines, but between + reduced images so that each reduced image starts at a byte. +out: the same pixels, but re-ordered so that they're now a non-interlaced image with size w*h +bpp: bits per pixel +out has the following size in bits: w * h * bpp. +in is possibly bigger due to padding bits between reduced images. +out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation +(because that's likely a little bit faster) +NOTE: comments about padding bits are only relevant if bpp < 8 +*/ +static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { + unsigned passw[7], passh[7]; + size_t filter_passstart[8], padded_passstart[8], passstart[8]; + unsigned i; + + Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); + + if(bpp >= 8) { + for(i = 0; i != 7; ++i) { + unsigned x, y, b; + size_t bytewidth = bpp / 8u; + for(y = 0; y < passh[i]; ++y) + for(x = 0; x < passw[i]; ++x) { + size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth; + size_t pixeloutstart = ((ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * (size_t)w + + ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bytewidth; + for(b = 0; b < bytewidth; ++b) { + out[pixeloutstart + b] = in[pixelinstart + b]; + } + } + } + } else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ { + for(i = 0; i != 7; ++i) { + unsigned x, y, b; + unsigned ilinebits = bpp * passw[i]; + unsigned olinebits = bpp * w; + size_t obp, ibp; /*bit pointers (for out and in buffer)*/ + for(y = 0; y < passh[i]; ++y) + for(x = 0; x < passw[i]; ++x) { + ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp); + obp = (ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bpp; + for(b = 0; b < bpp; ++b) { + unsigned char bit = readBitFromReversedStream(&ibp, in); + setBitOfReversedStream(&obp, out, bit); + } + } + } + } +} + +static void removePaddingBits(unsigned char* out, const unsigned char* in, + size_t olinebits, size_t ilinebits, unsigned h) { + /* + After filtering there are still padding bits if scanlines have non multiple of 8 bit amounts. They need + to be removed (except at last scanline of (Adam7-reduced) image) before working with pure image buffers + for the Adam7 code, the color convert code and the output to the user. + in and out are allowed to be the same buffer, in may also be higher but still overlapping; in must + have >= ilinebits*h bits, out must have >= olinebits*h bits, olinebits must be <= ilinebits + also used to move bits after earlier such operations happened, e.g. in a sequence of reduced images from Adam7 + only useful if (ilinebits - olinebits) is a value in the range 1..7 + */ + unsigned y; + size_t diff = ilinebits - olinebits; + size_t ibp = 0, obp = 0; /*input and output bit pointers*/ + for(y = 0; y < h; ++y) { + size_t x; + for(x = 0; x < olinebits; ++x) { + unsigned char bit = readBitFromReversedStream(&ibp, in); + setBitOfReversedStream(&obp, out, bit); + } + ibp += diff; + } +} + +/*out must be buffer big enough to contain full image, and in must contain the full decompressed data from +the IDAT chunks (with filter index bytes and possible padding bits) +return value is error*/ +static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, + unsigned w, unsigned h, const LodePNGInfo* info_png) { + /* + This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype. + Steps: + *) if no Adam7: 1) unfilter 2) remove padding bits (= possible extra bits per scanline if bpp < 8) + *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace + NOTE: the in buffer will be overwritten with intermediate data! + */ + unsigned bpp = lodepng_get_bpp(&info_png->color); + if(bpp == 0) return 31; /*error: invalid colortype*/ + + if(info_png->interlace_method == 0) { + if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { + CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp)); + removePaddingBits(out, in, w * bpp, ((w * bpp + 7u) / 8u) * 8u, h); + } + /*we can immediately filter into the out buffer, no other steps needed*/ + else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp)); + } else /*interlace_method is 1 (Adam7)*/ { + unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; + unsigned i; + + Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); + + for(i = 0; i != 7; ++i) { + CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp)); + /*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline, + move bytes instead of bits or move not at all*/ + if(bpp < 8) { + /*remove padding bits in scanlines; after this there still may be padding + bits between the different reduced images: each reduced image still starts nicely at a byte*/ + removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp, + ((passw[i] * bpp + 7u) / 8u) * 8u, passh[i]); + } + } + + Adam7_deinterlace(out, in, w, h, bpp); + } + + return 0; +} + +static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) { + unsigned pos = 0, i; + color->palettesize = chunkLength / 3u; + if(color->palettesize == 0 || color->palettesize > 256) return 38; /*error: palette too small or big*/ + lodepng_color_mode_alloc_palette(color); + if(!color->palette && color->palettesize) { + color->palettesize = 0; + return 83; /*alloc fail*/ + } + + for(i = 0; i != color->palettesize; ++i) { + color->palette[4 * i + 0] = data[pos++]; /*R*/ + color->palette[4 * i + 1] = data[pos++]; /*G*/ + color->palette[4 * i + 2] = data[pos++]; /*B*/ + color->palette[4 * i + 3] = 255; /*alpha*/ + } + + return 0; /* OK */ +} + +static unsigned readChunk_tRNS(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) { + unsigned i; + if(color->colortype == LCT_PALETTE) { + /*error: more alpha values given than there are palette entries*/ + if(chunkLength > color->palettesize) return 39; + + for(i = 0; i != chunkLength; ++i) color->palette[4 * i + 3] = data[i]; + } else if(color->colortype == LCT_GREY) { + /*error: this chunk must be 2 bytes for grayscale image*/ + if(chunkLength != 2) return 30; + + color->key_defined = 1; + color->key_r = color->key_g = color->key_b = 256u * data[0] + data[1]; + } else if(color->colortype == LCT_RGB) { + /*error: this chunk must be 6 bytes for RGB image*/ + if(chunkLength != 6) return 41; + + color->key_defined = 1; + color->key_r = 256u * data[0] + data[1]; + color->key_g = 256u * data[2] + data[3]; + color->key_b = 256u * data[4] + data[5]; + } + else return 42; /*error: tRNS chunk not allowed for other color models*/ + + return 0; /* OK */ +} + + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +/*background color chunk (bKGD)*/ +static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + if(info->color.colortype == LCT_PALETTE) { + /*error: this chunk must be 1 byte for indexed color image*/ + if(chunkLength != 1) return 43; + + /*error: invalid palette index, or maybe this chunk appeared before PLTE*/ + if(data[0] >= info->color.palettesize) return 103; + + info->background_defined = 1; + info->background_r = info->background_g = info->background_b = data[0]; + } else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { + /*error: this chunk must be 2 bytes for grayscale image*/ + if(chunkLength != 2) return 44; + + /*the values are truncated to bitdepth in the PNG file*/ + info->background_defined = 1; + info->background_r = info->background_g = info->background_b = 256u * data[0] + data[1]; + } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { + /*error: this chunk must be 6 bytes for grayscale image*/ + if(chunkLength != 6) return 45; + + /*the values are truncated to bitdepth in the PNG file*/ + info->background_defined = 1; + info->background_r = 256u * data[0] + data[1]; + info->background_g = 256u * data[2] + data[3]; + info->background_b = 256u * data[4] + data[5]; + } + + return 0; /* OK */ +} + +/*text chunk (tEXt)*/ +static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + unsigned error = 0; + char *key = 0, *str = 0; + + while(!error) /*not really a while loop, only used to break on error*/ { + unsigned length, string2_begin; + + length = 0; + while(length < chunkLength && data[length] != 0) ++length; + /*even though it's not allowed by the standard, no error is thrown if + there's no null termination char, if the text is empty*/ + if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ + + key = (char*)lodepng_malloc(length + 1); + if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ + + lodepng_memcpy(key, data, length); + key[length] = 0; + + string2_begin = length + 1; /*skip keyword null terminator*/ + + length = (unsigned)(chunkLength < string2_begin ? 0 : chunkLength - string2_begin); + str = (char*)lodepng_malloc(length + 1); + if(!str) CERROR_BREAK(error, 83); /*alloc fail*/ + + lodepng_memcpy(str, data + string2_begin, length); + str[length] = 0; + + error = lodepng_add_text(info, key, str); + + break; + } + + lodepng_free(key); + lodepng_free(str); + + return error; +} + +/*compressed text chunk (zTXt)*/ +static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, + const unsigned char* data, size_t chunkLength) { + unsigned error = 0; + + unsigned length, string2_begin; + char *key = 0; + unsigned char* str = 0; + size_t size = 0; + + while(!error) /*not really a while loop, only used to break on error*/ { + for(length = 0; length < chunkLength && data[length] != 0; ++length) ; + if(length + 2 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ + if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ + + key = (char*)lodepng_malloc(length + 1); + if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ + + lodepng_memcpy(key, data, length); + key[length] = 0; + + if(data[length + 1] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/ + + string2_begin = length + 2; + if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ + + length = (unsigned)chunkLength - string2_begin; + /*will fail if zlib error, e.g. if length is too small*/ + error = zlib_decompress(&str, &size, 0, &data[string2_begin], + length, zlibsettings); + if(error) break; + error = lodepng_add_text_sized(info, key, (char*)str, size); + + break; + } + + lodepng_free(key); + lodepng_free(str); + + return error; +} + +/*international text chunk (iTXt)*/ +static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, + const unsigned char* data, size_t chunkLength) { + unsigned error = 0; + unsigned i; + + unsigned length, begin, compressed; + char *key = 0, *langtag = 0, *transkey = 0; + + while(!error) /*not really a while loop, only used to break on error*/ { + /*Quick check if the chunk length isn't too small. Even without check + it'd still fail with other error checks below if it's too short. This just gives a different error code.*/ + if(chunkLength < 5) CERROR_BREAK(error, 30); /*iTXt chunk too short*/ + + /*read the key*/ + for(length = 0; length < chunkLength && data[length] != 0; ++length) ; + if(length + 3 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination char, corrupt?*/ + if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ + + key = (char*)lodepng_malloc(length + 1); + if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ + + lodepng_memcpy(key, data, length); + key[length] = 0; + + /*read the compression method*/ + compressed = data[length + 1]; + if(data[length + 2] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/ + + /*even though it's not allowed by the standard, no error is thrown if + there's no null termination char, if the text is empty for the next 3 texts*/ + + /*read the langtag*/ + begin = length + 3; + length = 0; + for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length; + + langtag = (char*)lodepng_malloc(length + 1); + if(!langtag) CERROR_BREAK(error, 83); /*alloc fail*/ + + lodepng_memcpy(langtag, data + begin, length); + langtag[length] = 0; + + /*read the transkey*/ + begin += length + 1; + length = 0; + for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length; + + transkey = (char*)lodepng_malloc(length + 1); + if(!transkey) CERROR_BREAK(error, 83); /*alloc fail*/ + + lodepng_memcpy(transkey, data + begin, length); + transkey[length] = 0; + + /*read the actual text*/ + begin += length + 1; + + length = (unsigned)chunkLength < begin ? 0 : (unsigned)chunkLength - begin; + + if(compressed) { + unsigned char* str = 0; + size_t size = 0; + /*will fail if zlib error, e.g. if length is too small*/ + error = zlib_decompress(&str, &size, 0, &data[begin], + length, zlibsettings); + if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size); + lodepng_free(str); + } else { + error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)(data + begin), length); + } + + break; + } + + lodepng_free(key); + lodepng_free(langtag); + lodepng_free(transkey); + + return error; +} + +static unsigned readChunk_tIME(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + if(chunkLength != 7) return 73; /*invalid tIME chunk size*/ + + info->time_defined = 1; + info->time.year = 256u * data[0] + data[1]; + info->time.month = data[2]; + info->time.day = data[3]; + info->time.hour = data[4]; + info->time.minute = data[5]; + info->time.second = data[6]; + + return 0; /* OK */ +} + +static unsigned readChunk_pHYs(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + if(chunkLength != 9) return 74; /*invalid pHYs chunk size*/ + + info->phys_defined = 1; + info->phys_x = 16777216u * data[0] + 65536u * data[1] + 256u * data[2] + data[3]; + info->phys_y = 16777216u * data[4] + 65536u * data[5] + 256u * data[6] + data[7]; + info->phys_unit = data[8]; + + return 0; /* OK */ +} + +static unsigned readChunk_gAMA(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + if(chunkLength != 4) return 96; /*invalid gAMA chunk size*/ + + info->gama_defined = 1; + info->gama_gamma = 16777216u * data[0] + 65536u * data[1] + 256u * data[2] + data[3]; + + return 0; /* OK */ +} + +static unsigned readChunk_cHRM(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + if(chunkLength != 32) return 97; /*invalid cHRM chunk size*/ + + info->chrm_defined = 1; + info->chrm_white_x = 16777216u * data[ 0] + 65536u * data[ 1] + 256u * data[ 2] + data[ 3]; + info->chrm_white_y = 16777216u * data[ 4] + 65536u * data[ 5] + 256u * data[ 6] + data[ 7]; + info->chrm_red_x = 16777216u * data[ 8] + 65536u * data[ 9] + 256u * data[10] + data[11]; + info->chrm_red_y = 16777216u * data[12] + 65536u * data[13] + 256u * data[14] + data[15]; + info->chrm_green_x = 16777216u * data[16] + 65536u * data[17] + 256u * data[18] + data[19]; + info->chrm_green_y = 16777216u * data[20] + 65536u * data[21] + 256u * data[22] + data[23]; + info->chrm_blue_x = 16777216u * data[24] + 65536u * data[25] + 256u * data[26] + data[27]; + info->chrm_blue_y = 16777216u * data[28] + 65536u * data[29] + 256u * data[30] + data[31]; + + return 0; /* OK */ +} + +static unsigned readChunk_sRGB(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) { + if(chunkLength != 1) return 98; /*invalid sRGB chunk size (this one is never ignored)*/ + + info->srgb_defined = 1; + info->srgb_intent = data[0]; + + return 0; /* OK */ +} + +static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, + const unsigned char* data, size_t chunkLength) { + unsigned error = 0; + unsigned i; + size_t size = 0; + + unsigned length, string2_begin; + + info->iccp_defined = 1; + if(info->iccp_name) lodepng_clear_icc(info); + + for(length = 0; length < chunkLength && data[length] != 0; ++length) ; + if(length + 2 >= chunkLength) return 75; /*no null termination, corrupt?*/ + if(length < 1 || length > 79) return 89; /*keyword too short or long*/ + + info->iccp_name = (char*)lodepng_malloc(length + 1); + if(!info->iccp_name) return 83; /*alloc fail*/ + + info->iccp_name[length] = 0; + for(i = 0; i != length; ++i) info->iccp_name[i] = (char)data[i]; + + if(data[length + 1] != 0) return 72; /*the 0 byte indicating compression must be 0*/ + + string2_begin = length + 2; + if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/ + + length = (unsigned)chunkLength - string2_begin; + error = zlib_decompress(&info->iccp_profile, &size, 0, + &data[string2_begin], + length, zlibsettings); + info->iccp_profile_size = size; + if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/ + return error; +} +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, + const unsigned char* in, size_t insize) { + const unsigned char* chunk = in + pos; + unsigned chunkLength; + const unsigned char* data; + unsigned unhandled = 0; + unsigned error = 0; + + if(pos + 4 > insize) return 30; + chunkLength = lodepng_chunk_length(chunk); + if(chunkLength > 2147483647) return 63; + data = lodepng_chunk_data_const(chunk); + if(data + chunkLength + 4 > in + insize) return 30; + + if(lodepng_chunk_type_equals(chunk, "PLTE")) { + error = readChunk_PLTE(&state->info_png.color, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "tRNS")) { + error = readChunk_tRNS(&state->info_png.color, data, chunkLength); +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + } else if(lodepng_chunk_type_equals(chunk, "bKGD")) { + error = readChunk_bKGD(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "tEXt")) { + error = readChunk_tEXt(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "zTXt")) { + error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "iTXt")) { + error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "tIME")) { + error = readChunk_tIME(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "pHYs")) { + error = readChunk_pHYs(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "gAMA")) { + error = readChunk_gAMA(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "cHRM")) { + error = readChunk_cHRM(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "sRGB")) { + error = readChunk_sRGB(&state->info_png, data, chunkLength); + } else if(lodepng_chunk_type_equals(chunk, "iCCP")) { + error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength); +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + } else { + /* unhandled chunk is ok (is not an error) */ + unhandled = 1; + } + + if(!error && !unhandled && !state->decoder.ignore_crc) { + if(lodepng_chunk_check_crc(chunk)) return 57; /*invalid CRC*/ + } + + return error; +} + +/*read a PNG, the result will be in the same color type as the PNG (hence "generic")*/ +static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize) { + unsigned char IEND = 0; + const unsigned char* chunk; + unsigned char* idat; /*the data from idat chunks, zlib compressed*/ + size_t idatsize = 0; + unsigned char* scanlines = 0; + size_t scanlines_size = 0, expected_size = 0; + size_t outsize = 0; + + /*for unknown chunk order*/ + unsigned unknown = 0; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + unsigned critical_pos = 1; /*1 = after IHDR, 2 = after PLTE, 3 = after IDAT*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + + + /* safe output values in case error happens */ + *out = 0; + *w = *h = 0; + + state->error = lodepng_inspect(w, h, state, in, insize); /*reads header and resets other parameters in state->info_png*/ + if(state->error) return; + + if(lodepng_pixel_overflow(*w, *h, &state->info_png.color, &state->info_raw)) { + CERROR_RETURN(state->error, 92); /*overflow possible due to amount of pixels*/ + } + + /*the input filesize is a safe upper bound for the sum of idat chunks size*/ + idat = (unsigned char*)lodepng_malloc(insize); + if(!idat) CERROR_RETURN(state->error, 83); /*alloc fail*/ + + chunk = &in[33]; /*first byte of the first chunk after the header*/ + + /*loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. + IDAT data is put at the start of the in buffer*/ + while(!IEND && !state->error) { + unsigned chunkLength; + const unsigned char* data; /*the data in the chunk*/ + + /*error: size of the in buffer too small to contain next chunk*/ + if((size_t)((chunk - in) + 12) > insize || chunk < in) { + if(state->decoder.ignore_end) break; /*other errors may still happen though*/ + CERROR_BREAK(state->error, 30); + } + + /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/ + chunkLength = lodepng_chunk_length(chunk); + /*error: chunk length larger than the max PNG chunk size*/ + if(chunkLength > 2147483647) { + if(state->decoder.ignore_end) break; /*other errors may still happen though*/ + CERROR_BREAK(state->error, 63); + } + + if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in) { + CERROR_BREAK(state->error, 64); /*error: size of the in buffer too small to contain next chunk*/ + } + + data = lodepng_chunk_data_const(chunk); + + unknown = 0; + + /*IDAT chunk, containing compressed image data*/ + if(lodepng_chunk_type_equals(chunk, "IDAT")) { + size_t newsize; + if(lodepng_addofl(idatsize, chunkLength, &newsize)) CERROR_BREAK(state->error, 95); + if(newsize > insize) CERROR_BREAK(state->error, 95); + lodepng_memcpy(idat + idatsize, data, chunkLength); + idatsize += chunkLength; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + critical_pos = 3; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + } else if(lodepng_chunk_type_equals(chunk, "IEND")) { + /*IEND chunk*/ + IEND = 1; + } else if(lodepng_chunk_type_equals(chunk, "PLTE")) { + /*palette chunk (PLTE)*/ + state->error = readChunk_PLTE(&state->info_png.color, data, chunkLength); + if(state->error) break; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + critical_pos = 2; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + } else if(lodepng_chunk_type_equals(chunk, "tRNS")) { + /*palette transparency chunk (tRNS). Even though this one is an ancillary chunk , it is still compiled + in without 'LODEPNG_COMPILE_ANCILLARY_CHUNKS' because it contains essential color information that + affects the alpha channel of pixels. */ + state->error = readChunk_tRNS(&state->info_png.color, data, chunkLength); + if(state->error) break; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*background color chunk (bKGD)*/ + } else if(lodepng_chunk_type_equals(chunk, "bKGD")) { + state->error = readChunk_bKGD(&state->info_png, data, chunkLength); + if(state->error) break; + } else if(lodepng_chunk_type_equals(chunk, "tEXt")) { + /*text chunk (tEXt)*/ + if(state->decoder.read_text_chunks) { + state->error = readChunk_tEXt(&state->info_png, data, chunkLength); + if(state->error) break; + } + } else if(lodepng_chunk_type_equals(chunk, "zTXt")) { + /*compressed text chunk (zTXt)*/ + if(state->decoder.read_text_chunks) { + state->error = readChunk_zTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength); + if(state->error) break; + } + } else if(lodepng_chunk_type_equals(chunk, "iTXt")) { + /*international text chunk (iTXt)*/ + if(state->decoder.read_text_chunks) { + state->error = readChunk_iTXt(&state->info_png, &state->decoder.zlibsettings, data, chunkLength); + if(state->error) break; + } + } else if(lodepng_chunk_type_equals(chunk, "tIME")) { + state->error = readChunk_tIME(&state->info_png, data, chunkLength); + if(state->error) break; + } else if(lodepng_chunk_type_equals(chunk, "pHYs")) { + state->error = readChunk_pHYs(&state->info_png, data, chunkLength); + if(state->error) break; + } else if(lodepng_chunk_type_equals(chunk, "gAMA")) { + state->error = readChunk_gAMA(&state->info_png, data, chunkLength); + if(state->error) break; + } else if(lodepng_chunk_type_equals(chunk, "cHRM")) { + state->error = readChunk_cHRM(&state->info_png, data, chunkLength); + if(state->error) break; + } else if(lodepng_chunk_type_equals(chunk, "sRGB")) { + state->error = readChunk_sRGB(&state->info_png, data, chunkLength); + if(state->error) break; + } else if(lodepng_chunk_type_equals(chunk, "iCCP")) { + state->error = readChunk_iCCP(&state->info_png, &state->decoder.zlibsettings, data, chunkLength); + if(state->error) break; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + } else /*it's not an implemented chunk type, so ignore it: skip over the data*/ { + /*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/ + if(!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk)) { + CERROR_BREAK(state->error, 69); + } + + unknown = 1; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + if(state->decoder.remember_unknown_chunks) { + state->error = lodepng_chunk_append(&state->info_png.unknown_chunks_data[critical_pos - 1], + &state->info_png.unknown_chunks_size[critical_pos - 1], chunk); + if(state->error) break; + } +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + } + + if(!state->decoder.ignore_crc && !unknown) /*check CRC if wanted, only on known chunk types*/ { + if(lodepng_chunk_check_crc(chunk)) CERROR_BREAK(state->error, 57); /*invalid CRC*/ + } + + if(!IEND) chunk = lodepng_chunk_next_const(chunk, in + insize); + } + + if(state->info_png.color.colortype == LCT_PALETTE && !state->info_png.color.palette) { + state->error = 106; /* error: PNG file must have PLTE chunk if color type is palette */ + } + + if(!state->error) { + /*predict output size, to allocate exact size for output buffer to avoid more dynamic allocation. + If the decompressed size does not match the prediction, the image must be corrupt.*/ + if(state->info_png.interlace_method == 0) { + size_t bpp = lodepng_get_bpp(&state->info_png.color); + expected_size = lodepng_get_raw_size_idat(*w, *h, bpp); + } else { + size_t bpp = lodepng_get_bpp(&state->info_png.color); + /*Adam-7 interlaced: expected size is the sum of the 7 sub-images sizes*/ + expected_size = 0; + expected_size += lodepng_get_raw_size_idat((*w + 7) >> 3, (*h + 7) >> 3, bpp); + if(*w > 4) expected_size += lodepng_get_raw_size_idat((*w + 3) >> 3, (*h + 7) >> 3, bpp); + expected_size += lodepng_get_raw_size_idat((*w + 3) >> 2, (*h + 3) >> 3, bpp); + if(*w > 2) expected_size += lodepng_get_raw_size_idat((*w + 1) >> 2, (*h + 3) >> 2, bpp); + expected_size += lodepng_get_raw_size_idat((*w + 1) >> 1, (*h + 1) >> 2, bpp); + if(*w > 1) expected_size += lodepng_get_raw_size_idat((*w + 0) >> 1, (*h + 1) >> 1, bpp); + expected_size += lodepng_get_raw_size_idat((*w + 0), (*h + 0) >> 1, bpp); + } + + state->error = zlib_decompress(&scanlines, &scanlines_size, expected_size, idat, idatsize, &state->decoder.zlibsettings); + } + if(!state->error && scanlines_size != expected_size) state->error = 91; /*decompressed size doesn't match prediction*/ + lodepng_free(idat); + + if(!state->error) { + outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color); + *out = (unsigned char*)lodepng_malloc(outsize); + if(!*out) state->error = 83; /*alloc fail*/ + } + if(!state->error) { + lodepng_memset(*out, 0, outsize); + state->error = postProcessScanlines(*out, scanlines, *w, *h, &state->info_png); + } + lodepng_free(scanlines); +} + +unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize) { + *out = 0; + decodeGeneric(out, w, h, state, in, insize); + if(state->error) return state->error; + if(!state->decoder.color_convert || lodepng_color_mode_equal(&state->info_raw, &state->info_png.color)) { + /*same color type, no copying or converting of data needed*/ + /*store the info_png color settings on the info_raw so that the info_raw still reflects what colortype + the raw image has to the end user*/ + if(!state->decoder.color_convert) { + state->error = lodepng_color_mode_copy(&state->info_raw, &state->info_png.color); + if(state->error) return state->error; + } + } else { /*color conversion needed*/ + unsigned char* data = *out; + size_t outsize; + + /*TODO: check if this works according to the statement in the documentation: "The converter can convert + from grayscale input color type, to 8-bit grayscale or grayscale with alpha"*/ + if(!(state->info_raw.colortype == LCT_RGB || state->info_raw.colortype == LCT_RGBA) + && !(state->info_raw.bitdepth == 8)) { + return 56; /*unsupported color mode conversion*/ + } + + outsize = lodepng_get_raw_size(*w, *h, &state->info_raw); + *out = (unsigned char*)lodepng_malloc(outsize); + if(!(*out)) { + state->error = 83; /*alloc fail*/ + } + else state->error = lodepng_convert(*out, data, &state->info_raw, + &state->info_png.color, *w, *h); + lodepng_free(data); + } + return state->error; +} + +unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, + size_t insize, LodePNGColorType colortype, unsigned bitdepth) { + unsigned error; + LodePNGState state; + lodepng_state_init(&state); + state.info_raw.colortype = colortype; + state.info_raw.bitdepth = bitdepth; + error = lodepng_decode(out, w, h, &state, in, insize); + lodepng_state_cleanup(&state); + return error; +} + +unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize) { + return lodepng_decode_memory(out, w, h, in, insize, LCT_RGBA, 8); +} + +unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, const unsigned char* in, size_t insize) { + return lodepng_decode_memory(out, w, h, in, insize, LCT_RGB, 8); +} + +#ifdef LODEPNG_COMPILE_DISK +unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename, + LodePNGColorType colortype, unsigned bitdepth) { + unsigned char* buffer = 0; + size_t buffersize; + unsigned error; + /* safe output values in case error happens */ + *out = 0; + *w = *h = 0; + error = lodepng_load_file(&buffer, &buffersize, filename); + if(!error) error = lodepng_decode_memory(out, w, h, buffer, buffersize, colortype, bitdepth); + lodepng_free(buffer); + return error; +} + +unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename) { + return lodepng_decode_file(out, w, h, filename, LCT_RGBA, 8); +} + +unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, const char* filename) { + return lodepng_decode_file(out, w, h, filename, LCT_RGB, 8); +} +#endif /*LODEPNG_COMPILE_DISK*/ + +void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings) { + settings->color_convert = 1; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + settings->read_text_chunks = 1; + settings->remember_unknown_chunks = 0; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + settings->ignore_crc = 0; + settings->ignore_critical = 0; + settings->ignore_end = 0; + lodepng_decompress_settings_init(&settings->zlibsettings); +} + +#endif /*LODEPNG_COMPILE_DECODER*/ + +#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) + +void lodepng_state_init(LodePNGState* state) { +#ifdef LODEPNG_COMPILE_DECODER + lodepng_decoder_settings_init(&state->decoder); +#endif /*LODEPNG_COMPILE_DECODER*/ +#ifdef LODEPNG_COMPILE_ENCODER + lodepng_encoder_settings_init(&state->encoder); +#endif /*LODEPNG_COMPILE_ENCODER*/ + lodepng_color_mode_init(&state->info_raw); + lodepng_info_init(&state->info_png); + state->error = 1; +} + +void lodepng_state_cleanup(LodePNGState* state) { + lodepng_color_mode_cleanup(&state->info_raw); + lodepng_info_cleanup(&state->info_png); +} + +void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source) { + lodepng_state_cleanup(dest); + *dest = *source; + lodepng_color_mode_init(&dest->info_raw); + lodepng_info_init(&dest->info_png); + dest->error = lodepng_color_mode_copy(&dest->info_raw, &source->info_raw); if(dest->error) return; + dest->error = lodepng_info_copy(&dest->info_png, &source->info_png); if(dest->error) return; +} + +#endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ + +#ifdef LODEPNG_COMPILE_ENCODER + +/* ////////////////////////////////////////////////////////////////////////// */ +/* / PNG Encoder / */ +/* ////////////////////////////////////////////////////////////////////////// */ + + +static unsigned writeSignature(ucvector* out) { + size_t pos = out->size; + const unsigned char signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; + /*8 bytes PNG signature, aka the magic bytes*/ + if(!ucvector_resize(out, out->size + 8)) return 83; /*alloc fail*/ + lodepng_memcpy(out->data + pos, signature, 8); + return 0; +} + +static unsigned addChunk_IHDR(ucvector* out, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth, unsigned interlace_method) { + unsigned char *chunk, *data; + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 13, "IHDR")); + data = chunk + 8; + + lodepng_set32bitInt(data + 0, w); /*width*/ + lodepng_set32bitInt(data + 4, h); /*height*/ + data[8] = (unsigned char)bitdepth; /*bit depth*/ + data[9] = (unsigned char)colortype; /*color type*/ + data[10] = 0; /*compression method*/ + data[11] = 0; /*filter method*/ + data[12] = interlace_method; /*interlace method*/ + + lodepng_chunk_generate_crc(chunk); + return 0; +} + +/* only adds the chunk if needed (there is a key or palette with alpha) */ +static unsigned addChunk_PLTE(ucvector* out, const LodePNGColorMode* info) { + unsigned char* chunk; + size_t i, j = 8; + + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, info->palettesize * 3, "PLTE")); + + for(i = 0; i != info->palettesize; ++i) { + /*add all channels except alpha channel*/ + chunk[j++] = info->palette[i * 4 + 0]; + chunk[j++] = info->palette[i * 4 + 1]; + chunk[j++] = info->palette[i * 4 + 2]; + } + + lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) { + unsigned char* chunk = 0; + + if(info->colortype == LCT_PALETTE) { + size_t i, amount = info->palettesize; + /*the tail of palette values that all have 255 as alpha, does not have to be encoded*/ + for(i = info->palettesize; i != 0; --i) { + if(info->palette[4 * (i - 1) + 3] != 255) break; + --amount; + } + if(amount) { + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, amount, "tRNS")); + /*add the alpha channel values from the palette*/ + for(i = 0; i != amount; ++i) chunk[8 + i] = info->palette[4 * i + 3]; + } + } else if(info->colortype == LCT_GREY) { + if(info->key_defined) { + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "tRNS")); + chunk[8] = (unsigned char)(info->key_r >> 8); + chunk[9] = (unsigned char)(info->key_r & 255); + } + } else if(info->colortype == LCT_RGB) { + if(info->key_defined) { + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 6, "tRNS")); + chunk[8] = (unsigned char)(info->key_r >> 8); + chunk[9] = (unsigned char)(info->key_r & 255); + chunk[10] = (unsigned char)(info->key_g >> 8); + chunk[11] = (unsigned char)(info->key_g & 255); + chunk[12] = (unsigned char)(info->key_b >> 8); + chunk[13] = (unsigned char)(info->key_b & 255); + } + } + + if(chunk) lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_IDAT(ucvector* out, const unsigned char* data, size_t datasize, + LodePNGCompressSettings* zlibsettings) { + unsigned error = 0; + unsigned char* zlib = 0; + size_t zlibsize = 0; + + error = zlib_compress(&zlib, &zlibsize, data, datasize, zlibsettings); + if(!error) { + error = lodepng_chunk_createv(out, zlibsize, "IDAT", zlib); + } + lodepng_free(zlib); + return error; +} + +static unsigned addChunk_IEND(ucvector* out) { + return lodepng_chunk_createv(out, 0, "IEND", 0); +} + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + +static unsigned addChunk_tEXt(ucvector* out, const char* keyword, const char* textstring) { + unsigned char* chunk = 0; + size_t keysize = lodepng_strlen(keyword), textsize = lodepng_strlen(textstring); + size_t size = keysize + 1 + textsize; + if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, size, "tEXt")); + lodepng_memcpy(chunk + 8, keyword, keysize); + chunk[8 + keysize] = 0; /*null termination char*/ + lodepng_memcpy(chunk + 9 + keysize, textstring, textsize); + lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* textstring, + LodePNGCompressSettings* zlibsettings) { + unsigned error = 0; + unsigned char* chunk = 0; + unsigned char* compressed = 0; + size_t compressedsize = 0; + size_t textsize = lodepng_strlen(textstring); + size_t keysize = lodepng_strlen(keyword); + if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ + + error = zlib_compress(&compressed, &compressedsize, + (const unsigned char*)textstring, textsize, zlibsettings); + if(!error) { + size_t size = keysize + 2 + compressedsize; + error = lodepng_chunk_init(&chunk, out, size, "zTXt"); + } + if(!error) { + lodepng_memcpy(chunk + 8, keyword, keysize); + chunk[8 + keysize] = 0; /*null termination char*/ + chunk[9 + keysize] = 0; /*compression method: 0*/ + lodepng_memcpy(chunk + 10 + keysize, compressed, compressedsize); + lodepng_chunk_generate_crc(chunk); + } + + lodepng_free(compressed); + return error; +} + +static unsigned addChunk_iTXt(ucvector* out, unsigned compress, const char* keyword, const char* langtag, + const char* transkey, const char* textstring, LodePNGCompressSettings* zlibsettings) { + unsigned error = 0; + unsigned char* chunk = 0; + unsigned char* compressed = 0; + size_t compressedsize = 0; + size_t textsize = lodepng_strlen(textstring); + size_t keysize = lodepng_strlen(keyword), langsize = lodepng_strlen(langtag), transsize = lodepng_strlen(transkey); + + if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ + + if(compress) { + error = zlib_compress(&compressed, &compressedsize, + (const unsigned char*)textstring, textsize, zlibsettings); + } + if(!error) { + size_t size = keysize + 3 + langsize + 1 + transsize + 1 + (compress ? compressedsize : textsize); + error = lodepng_chunk_init(&chunk, out, size, "iTXt"); + } + if(!error) { + size_t pos = 8; + lodepng_memcpy(chunk + pos, keyword, keysize); + pos += keysize; + chunk[pos++] = 0; /*null termination char*/ + chunk[pos++] = (compress ? 1 : 0); /*compression flag*/ + chunk[pos++] = 0; /*compression method: 0*/ + lodepng_memcpy(chunk + pos, langtag, langsize); + pos += langsize; + chunk[pos++] = 0; /*null termination char*/ + lodepng_memcpy(chunk + pos, transkey, transsize); + pos += transsize; + chunk[pos++] = 0; /*null termination char*/ + if(compress) { + lodepng_memcpy(chunk + pos, compressed, compressedsize); + } else { + lodepng_memcpy(chunk + pos, textstring, textsize); + } + lodepng_chunk_generate_crc(chunk); + } + + lodepng_free(compressed); + return error; +} + +static unsigned addChunk_bKGD(ucvector* out, const LodePNGInfo* info) { + unsigned char* chunk = 0; + if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) { + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "bKGD")); + chunk[8] = (unsigned char)(info->background_r >> 8); + chunk[9] = (unsigned char)(info->background_r & 255); + } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) { + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 6, "bKGD")); + chunk[8] = (unsigned char)(info->background_r >> 8); + chunk[9] = (unsigned char)(info->background_r & 255); + chunk[10] = (unsigned char)(info->background_g >> 8); + chunk[11] = (unsigned char)(info->background_g & 255); + chunk[12] = (unsigned char)(info->background_b >> 8); + chunk[13] = (unsigned char)(info->background_b & 255); + } else if(info->color.colortype == LCT_PALETTE) { + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "bKGD")); + chunk[8] = (unsigned char)(info->background_r & 255); /*palette index*/ + } + if(chunk) lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_tIME(ucvector* out, const LodePNGTime* time) { + unsigned char* chunk; + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 7, "tIME")); + chunk[8] = (unsigned char)(time->year >> 8); + chunk[9] = (unsigned char)(time->year & 255); + chunk[10] = (unsigned char)time->month; + chunk[11] = (unsigned char)time->day; + chunk[12] = (unsigned char)time->hour; + chunk[13] = (unsigned char)time->minute; + chunk[14] = (unsigned char)time->second; + lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_pHYs(ucvector* out, const LodePNGInfo* info) { + unsigned char* chunk; + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 9, "pHYs")); + lodepng_set32bitInt(chunk + 8, info->phys_x); + lodepng_set32bitInt(chunk + 12, info->phys_y); + chunk[16] = info->phys_unit; + lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_gAMA(ucvector* out, const LodePNGInfo* info) { + unsigned char* chunk; + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "gAMA")); + lodepng_set32bitInt(chunk + 8, info->gama_gamma); + lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_cHRM(ucvector* out, const LodePNGInfo* info) { + unsigned char* chunk; + CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 32, "cHRM")); + lodepng_set32bitInt(chunk + 8, info->chrm_white_x); + lodepng_set32bitInt(chunk + 12, info->chrm_white_y); + lodepng_set32bitInt(chunk + 16, info->chrm_red_x); + lodepng_set32bitInt(chunk + 20, info->chrm_red_y); + lodepng_set32bitInt(chunk + 24, info->chrm_green_x); + lodepng_set32bitInt(chunk + 28, info->chrm_green_y); + lodepng_set32bitInt(chunk + 32, info->chrm_blue_x); + lodepng_set32bitInt(chunk + 36, info->chrm_blue_y); + lodepng_chunk_generate_crc(chunk); + return 0; +} + +static unsigned addChunk_sRGB(ucvector* out, const LodePNGInfo* info) { + unsigned char data = info->srgb_intent; + return lodepng_chunk_createv(out, 1, "sRGB", &data); +} + +static unsigned addChunk_iCCP(ucvector* out, const LodePNGInfo* info, LodePNGCompressSettings* zlibsettings) { + unsigned error = 0; + unsigned char* chunk = 0; + unsigned char* compressed = 0; + size_t compressedsize = 0; + size_t keysize = lodepng_strlen(info->iccp_name); + + if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/ + error = zlib_compress(&compressed, &compressedsize, + info->iccp_profile, info->iccp_profile_size, zlibsettings); + if(!error) { + size_t size = keysize + 2 + compressedsize; + error = lodepng_chunk_init(&chunk, out, size, "iCCP"); + } + if(!error) { + lodepng_memcpy(chunk + 8, info->iccp_name, keysize); + chunk[8 + keysize] = 0; /*null termination char*/ + chunk[9 + keysize] = 0; /*compression method: 0*/ + lodepng_memcpy(chunk + 10 + keysize, compressed, compressedsize); + lodepng_chunk_generate_crc(chunk); + } + + lodepng_free(compressed); + return error; +} + +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline, + size_t length, size_t bytewidth, unsigned char filterType) { + size_t i; + switch(filterType) { + case 0: /*None*/ + for(i = 0; i != length; ++i) out[i] = scanline[i]; + break; + case 1: /*Sub*/ + for(i = 0; i != bytewidth; ++i) out[i] = scanline[i]; + for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - scanline[i - bytewidth]; + break; + case 2: /*Up*/ + if(prevline) { + for(i = 0; i != length; ++i) out[i] = scanline[i] - prevline[i]; + } else { + for(i = 0; i != length; ++i) out[i] = scanline[i]; + } + break; + case 3: /*Average*/ + if(prevline) { + for(i = 0; i != bytewidth; ++i) out[i] = scanline[i] - (prevline[i] >> 1); + for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) >> 1); + } else { + for(i = 0; i != bytewidth; ++i) out[i] = scanline[i]; + for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - (scanline[i - bytewidth] >> 1); + } + break; + case 4: /*Paeth*/ + if(prevline) { + /*paethPredictor(0, prevline[i], 0) is always prevline[i]*/ + for(i = 0; i != bytewidth; ++i) out[i] = (scanline[i] - prevline[i]); + for(i = bytewidth; i < length; ++i) { + out[i] = (scanline[i] - paethPredictor(scanline[i - bytewidth], prevline[i], prevline[i - bytewidth])); + } + } else { + for(i = 0; i != bytewidth; ++i) out[i] = scanline[i]; + /*paethPredictor(scanline[i - bytewidth], 0, 0) is always scanline[i - bytewidth]*/ + for(i = bytewidth; i < length; ++i) out[i] = (scanline[i] - scanline[i - bytewidth]); + } + break; + default: return; /*invalid filter type given*/ + } +} + +/* integer binary logarithm, max return value is 31 */ +static size_t ilog2(size_t i) { + size_t result = 0; + if(i >= 65536) { result += 16; i >>= 16; } + if(i >= 256) { result += 8; i >>= 8; } + if(i >= 16) { result += 4; i >>= 4; } + if(i >= 4) { result += 2; i >>= 2; } + if(i >= 2) { result += 1; /*i >>= 1;*/ } + return result; +} + +/* integer approximation for i * log2(i), helper function for LFS_ENTROPY */ +static size_t ilog2i(size_t i) { + size_t l; + if(i == 0) return 0; + l = ilog2(i); + /* approximate i*log2(i): l is integer logarithm, ((i - (1u << l)) << 1u) + linearly approximates the missing fractional part multiplied by i */ + return i * l + ((i - (1u << l)) << 1u); +} + +static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, + const LodePNGColorMode* color, const LodePNGEncoderSettings* settings) { + /* + For PNG filter method 0 + out must be a buffer with as size: h + (w * h * bpp + 7u) / 8u, because there are + the scanlines with 1 extra byte per scanline + */ + + unsigned bpp = lodepng_get_bpp(color); + /*the width of a scanline in bytes, not including the filter type*/ + size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u; + + /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ + size_t bytewidth = (bpp + 7u) / 8u; + const unsigned char* prevline = 0; + unsigned x, y; + unsigned error = 0; + LodePNGFilterStrategy strategy = settings->filter_strategy; + + /* + There is a heuristic called the minimum sum of absolute differences heuristic, suggested by the PNG standard: + * If the image type is Palette, or the bit depth is smaller than 8, then do not filter the image (i.e. + use fixed filtering, with the filter None). + * (The other case) If the image type is Grayscale or RGB (with or without Alpha), and the bit depth is + not smaller than 8, then use adaptive filtering heuristic as follows: independently for each row, apply + all five filters and select the filter that produces the smallest sum of absolute values per row. + This heuristic is used if filter strategy is LFS_MINSUM and filter_palette_zero is true. + + If filter_palette_zero is true and filter_strategy is not LFS_MINSUM, the above heuristic is followed, + but for "the other case", whatever strategy filter_strategy is set to instead of the minimum sum + heuristic is used. + */ + if(settings->filter_palette_zero && + (color->colortype == LCT_PALETTE || color->bitdepth < 8)) strategy = LFS_ZERO; + + if(bpp == 0) return 31; /*error: invalid color type*/ + + if(strategy >= LFS_ZERO && strategy <= LFS_FOUR) { + unsigned char type = (unsigned char)strategy; + for(y = 0; y != h; ++y) { + size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ + size_t inindex = linebytes * y; + out[outindex] = type; /*filter type byte*/ + filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); + prevline = &in[inindex]; + } + } else if(strategy == LFS_MINSUM) { + /*adaptive filtering*/ + unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ + size_t smallest = 0; + unsigned char type, bestType = 0; + + for(type = 0; type != 5; ++type) { + attempt[type] = (unsigned char*)lodepng_malloc(linebytes); + if(!attempt[type]) error = 83; /*alloc fail*/ + } + + if(!error) { + for(y = 0; y != h; ++y) { + /*try the 5 filter types*/ + for(type = 0; type != 5; ++type) { + size_t sum = 0; + filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); + + /*calculate the sum of the result*/ + if(type == 0) { + for(x = 0; x != linebytes; ++x) sum += (unsigned char)(attempt[type][x]); + } else { + for(x = 0; x != linebytes; ++x) { + /*For differences, each byte should be treated as signed, values above 127 are negative + (converted to signed char). Filtertype 0 isn't a difference though, so use unsigned there. + This means filtertype 0 is almost never chosen, but that is justified.*/ + unsigned char s = attempt[type][x]; + sum += s < 128 ? s : (255U - s); + } + } + + /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/ + if(type == 0 || sum < smallest) { + bestType = type; + smallest = sum; + } + } + + prevline = &in[y * linebytes]; + + /*now fill the out values*/ + out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/ + for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x]; + } + } + + for(type = 0; type != 5; ++type) lodepng_free(attempt[type]); + } else if(strategy == LFS_ENTROPY) { + unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ + size_t bestSum = 0; + unsigned type, bestType = 0; + unsigned count[256]; + + for(type = 0; type != 5; ++type) { + attempt[type] = (unsigned char*)lodepng_malloc(linebytes); + if(!attempt[type]) error = 83; /*alloc fail*/ + } + + if(!error) { + for(y = 0; y != h; ++y) { + /*try the 5 filter types*/ + for(type = 0; type != 5; ++type) { + size_t sum = 0; + filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); + lodepng_memset(count, 0, 256 * sizeof(*count)); + for(x = 0; x != linebytes; ++x) ++count[attempt[type][x]]; + ++count[type]; /*the filter type itself is part of the scanline*/ + for(x = 0; x != 256; ++x) { + sum += ilog2i(count[x]); + } + /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/ + if(type == 0 || sum > bestSum) { + bestType = type; + bestSum = sum; + } + } + + prevline = &in[y * linebytes]; + + /*now fill the out values*/ + out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/ + for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x]; + } + } + + for(type = 0; type != 5; ++type) lodepng_free(attempt[type]); + } else if(strategy == LFS_PREDEFINED) { + for(y = 0; y != h; ++y) { + size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ + size_t inindex = linebytes * y; + unsigned char type = settings->predefined_filters[y]; + out[outindex] = type; /*filter type byte*/ + filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type); + prevline = &in[inindex]; + } + } else if(strategy == LFS_BRUTE_FORCE) { + /*brute force filter chooser. + deflate the scanline after every filter attempt to see which one deflates best. + This is very slow and gives only slightly smaller, sometimes even larger, result*/ + size_t size[5]; + unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ + size_t smallest = 0; + unsigned type = 0, bestType = 0; + unsigned char* dummy; + LodePNGCompressSettings zlibsettings; + lodepng_memcpy(&zlibsettings, &settings->zlibsettings, sizeof(LodePNGCompressSettings)); + /*use fixed tree on the attempts so that the tree is not adapted to the filtertype on purpose, + to simulate the true case where the tree is the same for the whole image. Sometimes it gives + better result with dynamic tree anyway. Using the fixed tree sometimes gives worse, but in rare + cases better compression. It does make this a bit less slow, so it's worth doing this.*/ + zlibsettings.btype = 1; + /*a custom encoder likely doesn't read the btype setting and is optimized for complete PNG + images only, so disable it*/ + zlibsettings.custom_zlib = 0; + zlibsettings.custom_deflate = 0; + for(type = 0; type != 5; ++type) { + attempt[type] = (unsigned char*)lodepng_malloc(linebytes); + if(!attempt[type]) error = 83; /*alloc fail*/ + } + if(!error) { + for(y = 0; y != h; ++y) /*try the 5 filter types*/ { + for(type = 0; type != 5; ++type) { + unsigned testsize = (unsigned)linebytes; + /*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/ + + filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); + size[type] = 0; + dummy = 0; + zlib_compress(&dummy, &size[type], attempt[type], testsize, &zlibsettings); + lodepng_free(dummy); + /*check if this is smallest size (or if type == 0 it's the first case so always store the values)*/ + if(type == 0 || size[type] < smallest) { + bestType = type; + smallest = size[type]; + } + } + prevline = &in[y * linebytes]; + out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/ + for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x]; + } + } + for(type = 0; type != 5; ++type) lodepng_free(attempt[type]); + } + else return 88; /* unknown filter strategy */ + + return error; +} + +static void addPaddingBits(unsigned char* out, const unsigned char* in, + size_t olinebits, size_t ilinebits, unsigned h) { + /*The opposite of the removePaddingBits function + olinebits must be >= ilinebits*/ + unsigned y; + size_t diff = olinebits - ilinebits; + size_t obp = 0, ibp = 0; /*bit pointers*/ + for(y = 0; y != h; ++y) { + size_t x; + for(x = 0; x < ilinebits; ++x) { + unsigned char bit = readBitFromReversedStream(&ibp, in); + setBitOfReversedStream(&obp, out, bit); + } + /*obp += diff; --> no, fill in some value in the padding bits too, to avoid + "Use of uninitialised value of size ###" warning from valgrind*/ + for(x = 0; x != diff; ++x) setBitOfReversedStream(&obp, out, 0); + } +} + +/* +in: non-interlaced image with size w*h +out: the same pixels, but re-ordered according to PNG's Adam7 interlacing, with + no padding bits between scanlines, but between reduced images so that each + reduced image starts at a byte. +bpp: bits per pixel +there are no padding bits, not between scanlines, not between reduced images +in has the following size in bits: w * h * bpp. +out is possibly bigger due to padding bits between reduced images +NOTE: comments about padding bits are only relevant if bpp < 8 +*/ +static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { + unsigned passw[7], passh[7]; + size_t filter_passstart[8], padded_passstart[8], passstart[8]; + unsigned i; + + Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); + + if(bpp >= 8) { + for(i = 0; i != 7; ++i) { + unsigned x, y, b; + size_t bytewidth = bpp / 8u; + for(y = 0; y < passh[i]; ++y) + for(x = 0; x < passw[i]; ++x) { + size_t pixelinstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth; + size_t pixeloutstart = passstart[i] + (y * passw[i] + x) * bytewidth; + for(b = 0; b < bytewidth; ++b) { + out[pixeloutstart + b] = in[pixelinstart + b]; + } + } + } + } else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ { + for(i = 0; i != 7; ++i) { + unsigned x, y, b; + unsigned ilinebits = bpp * passw[i]; + unsigned olinebits = bpp * w; + size_t obp, ibp; /*bit pointers (for out and in buffer)*/ + for(y = 0; y < passh[i]; ++y) + for(x = 0; x < passw[i]; ++x) { + ibp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp; + obp = (8 * passstart[i]) + (y * ilinebits + x * bpp); + for(b = 0; b < bpp; ++b) { + unsigned char bit = readBitFromReversedStream(&ibp, in); + setBitOfReversedStream(&obp, out, bit); + } + } + } + } +} + +/*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image. +return value is error**/ +static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in, + unsigned w, unsigned h, + const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings) { + /* + This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps: + *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter + *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter + */ + unsigned bpp = lodepng_get_bpp(&info_png->color); + unsigned error = 0; + + if(info_png->interlace_method == 0) { + *outsize = h + (h * ((w * bpp + 7u) / 8u)); /*image size plus an extra byte per scanline + possible padding bits*/ + *out = (unsigned char*)lodepng_malloc(*outsize); + if(!(*out) && (*outsize)) error = 83; /*alloc fail*/ + + if(!error) { + /*non multiple of 8 bits per scanline, padding bits needed per scanline*/ + if(bpp < 8 && w * bpp != ((w * bpp + 7u) / 8u) * 8u) { + unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7u) / 8u)); + if(!padded) error = 83; /*alloc fail*/ + if(!error) { + addPaddingBits(padded, in, ((w * bpp + 7u) / 8u) * 8u, w * bpp, h); + error = filter(*out, padded, w, h, &info_png->color, settings); + } + lodepng_free(padded); + } else { + /*we can immediately filter into the out buffer, no other steps needed*/ + error = filter(*out, in, w, h, &info_png->color, settings); + } + } + } else /*interlace_method is 1 (Adam7)*/ { + unsigned passw[7], passh[7]; + size_t filter_passstart[8], padded_passstart[8], passstart[8]; + unsigned char* adam7; + + Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); + + *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/ + *out = (unsigned char*)lodepng_malloc(*outsize); + if(!(*out)) error = 83; /*alloc fail*/ + + adam7 = (unsigned char*)lodepng_malloc(passstart[7]); + if(!adam7 && passstart[7]) error = 83; /*alloc fail*/ + + if(!error) { + unsigned i; + + Adam7_interlace(adam7, in, w, h, bpp); + for(i = 0; i != 7; ++i) { + if(bpp < 8) { + unsigned char* padded = (unsigned char*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]); + if(!padded) ERROR_BREAK(83); /*alloc fail*/ + addPaddingBits(padded, &adam7[passstart[i]], + ((passw[i] * bpp + 7u) / 8u) * 8u, passw[i] * bpp, passh[i]); + error = filter(&(*out)[filter_passstart[i]], padded, + passw[i], passh[i], &info_png->color, settings); + lodepng_free(padded); + } else { + error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]], + passw[i], passh[i], &info_png->color, settings); + } + + if(error) break; + } + } + + lodepng_free(adam7); + } + + return error; +} + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +static unsigned addUnknownChunks(ucvector* out, unsigned char* data, size_t datasize) { + unsigned char* inchunk = data; + while((size_t)(inchunk - data) < datasize) { + CERROR_TRY_RETURN(lodepng_chunk_append(&out->data, &out->size, inchunk)); + out->allocsize = out->size; /*fix the allocsize again*/ + inchunk = lodepng_chunk_next(inchunk, data + datasize); + } + return 0; +} + +static unsigned isGrayICCProfile(const unsigned char* profile, unsigned size) { + /* + It is a gray profile if bytes 16-19 are "GRAY", rgb profile if bytes 16-19 + are "RGB ". We do not perform any full parsing of the ICC profile here, other + than check those 4 bytes to grayscale profile. Other than that, validity of + the profile is not checked. This is needed only because the PNG specification + requires using a non-gray color model if there is an ICC profile with "RGB " + (sadly limiting compression opportunities if the input data is grayscale RGB + data), and requires using a gray color model if it is "GRAY". + */ + if(size < 20) return 0; + return profile[16] == 'G' && profile[17] == 'R' && profile[18] == 'A' && profile[19] == 'Y'; +} + +static unsigned isRGBICCProfile(const unsigned char* profile, unsigned size) { + /* See comment in isGrayICCProfile*/ + if(size < 20) return 0; + return profile[16] == 'R' && profile[17] == 'G' && profile[18] == 'B' && profile[19] == ' '; +} +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +unsigned lodepng_encode(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGState* state) { + unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/ + size_t datasize = 0; + ucvector outv = ucvector_init(NULL, 0); + LodePNGInfo info; + const LodePNGInfo* info_png = &state->info_png; + + lodepng_info_init(&info); + + /*provide some proper output values if error will happen*/ + *out = 0; + *outsize = 0; + state->error = 0; + + /*check input values validity*/ + if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette) + && (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) { + state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/ + goto cleanup; + } + if(state->encoder.zlibsettings.btype > 2) { + state->error = 61; /*error: invalid btype*/ + goto cleanup; + } + if(info_png->interlace_method > 1) { + state->error = 71; /*error: invalid interlace mode*/ + goto cleanup; + } + state->error = checkColorValidity(info_png->color.colortype, info_png->color.bitdepth); + if(state->error) goto cleanup; /*error: invalid color type given*/ + state->error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth); + if(state->error) goto cleanup; /*error: invalid color type given*/ + + /* color convert and compute scanline filter types */ + lodepng_info_copy(&info, &state->info_png); + if(state->encoder.auto_convert) { + LodePNGColorStats stats; + lodepng_color_stats_init(&stats); +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + if(info_png->iccp_defined && + isGrayICCProfile(info_png->iccp_profile, info_png->iccp_profile_size)) { + /*the PNG specification does not allow to use palette with a GRAY ICC profile, even + if the palette has only gray colors, so disallow it.*/ + stats.allow_palette = 0; + } + if(info_png->iccp_defined && + isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size)) { + /*the PNG specification does not allow to use grayscale color with RGB ICC profile, so disallow gray.*/ + stats.allow_greyscale = 0; + } +#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */ + state->error = lodepng_compute_color_stats(&stats, image, w, h, &state->info_raw); + if(state->error) goto cleanup; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + if(info_png->background_defined) { + /*the background chunk's color must be taken into account as well*/ + unsigned r = 0, g = 0, b = 0; + LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16); + lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color); + state->error = lodepng_color_stats_add(&stats, r, g, b, 65535); + if(state->error) goto cleanup; + } +#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */ + state->error = auto_choose_color(&info.color, &state->info_raw, &stats); + if(state->error) goto cleanup; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*also convert the background chunk*/ + if(info_png->background_defined) { + if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b, + info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) { + state->error = 104; + goto cleanup; + } + } +#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */ + } +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + if(info_png->iccp_defined) { + unsigned gray_icc = isGrayICCProfile(info_png->iccp_profile, info_png->iccp_profile_size); + unsigned rgb_icc = isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size); + unsigned gray_png = info.color.colortype == LCT_GREY || info.color.colortype == LCT_GREY_ALPHA; + if(!gray_icc && !rgb_icc) { + state->error = 100; /* Disallowed profile color type for PNG */ + goto cleanup; + } + if(gray_icc != gray_png) { + /*Not allowed to use RGB/RGBA/palette with GRAY ICC profile or vice versa, + or in case of auto_convert, it wasn't possible to find appropriate model*/ + state->error = state->encoder.auto_convert ? 102 : 101; + goto cleanup; + } + } +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + if(!lodepng_color_mode_equal(&state->info_raw, &info.color)) { + unsigned char* converted; + size_t size = ((size_t)w * (size_t)h * (size_t)lodepng_get_bpp(&info.color) + 7u) / 8u; + + converted = (unsigned char*)lodepng_malloc(size); + if(!converted && size) state->error = 83; /*alloc fail*/ + if(!state->error) { + state->error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h); + } + if(!state->error) { + state->error = preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder); + } + lodepng_free(converted); + if(state->error) goto cleanup; + } else { + state->error = preProcessScanlines(&data, &datasize, image, w, h, &info, &state->encoder); + if(state->error) goto cleanup; + } + + /* output all PNG chunks */ { +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + size_t i; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + /*write signature and chunks*/ + state->error = writeSignature(&outv); + if(state->error) goto cleanup; + /*IHDR*/ + state->error = addChunk_IHDR(&outv, w, h, info.color.colortype, info.color.bitdepth, info.interlace_method); + if(state->error) goto cleanup; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*unknown chunks between IHDR and PLTE*/ + if(info.unknown_chunks_data[0]) { + state->error = addUnknownChunks(&outv, info.unknown_chunks_data[0], info.unknown_chunks_size[0]); + if(state->error) goto cleanup; + } + /*color profile chunks must come before PLTE */ + if(info.iccp_defined) { + state->error = addChunk_iCCP(&outv, &info, &state->encoder.zlibsettings); + if(state->error) goto cleanup; + } + if(info.srgb_defined) { + state->error = addChunk_sRGB(&outv, &info); + if(state->error) goto cleanup; + } + if(info.gama_defined) { + state->error = addChunk_gAMA(&outv, &info); + if(state->error) goto cleanup; + } + if(info.chrm_defined) { + state->error = addChunk_cHRM(&outv, &info); + if(state->error) goto cleanup; + } +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + /*PLTE*/ + if(info.color.colortype == LCT_PALETTE) { + state->error = addChunk_PLTE(&outv, &info.color); + if(state->error) goto cleanup; + } + if(state->encoder.force_palette && (info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA)) { + /*force_palette means: write suggested palette for truecolor in PLTE chunk*/ + state->error = addChunk_PLTE(&outv, &info.color); + if(state->error) goto cleanup; + } + /*tRNS (this will only add if when necessary) */ + state->error = addChunk_tRNS(&outv, &info.color); + if(state->error) goto cleanup; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*bKGD (must come between PLTE and the IDAt chunks*/ + if(info.background_defined) { + state->error = addChunk_bKGD(&outv, &info); + if(state->error) goto cleanup; + } + /*pHYs (must come before the IDAT chunks)*/ + if(info.phys_defined) { + state->error = addChunk_pHYs(&outv, &info); + if(state->error) goto cleanup; + } + + /*unknown chunks between PLTE and IDAT*/ + if(info.unknown_chunks_data[1]) { + state->error = addUnknownChunks(&outv, info.unknown_chunks_data[1], info.unknown_chunks_size[1]); + if(state->error) goto cleanup; + } +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + /*IDAT (multiple IDAT chunks must be consecutive)*/ + state->error = addChunk_IDAT(&outv, data, datasize, &state->encoder.zlibsettings); + if(state->error) goto cleanup; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*tIME*/ + if(info.time_defined) { + state->error = addChunk_tIME(&outv, &info.time); + if(state->error) goto cleanup; + } + /*tEXt and/or zTXt*/ + for(i = 0; i != info.text_num; ++i) { + if(lodepng_strlen(info.text_keys[i]) > 79) { + state->error = 66; /*text chunk too large*/ + goto cleanup; + } + if(lodepng_strlen(info.text_keys[i]) < 1) { + state->error = 67; /*text chunk too small*/ + goto cleanup; + } + if(state->encoder.text_compression) { + state->error = addChunk_zTXt(&outv, info.text_keys[i], info.text_strings[i], &state->encoder.zlibsettings); + if(state->error) goto cleanup; + } else { + state->error = addChunk_tEXt(&outv, info.text_keys[i], info.text_strings[i]); + if(state->error) goto cleanup; + } + } + /*LodePNG version id in text chunk*/ + if(state->encoder.add_id) { + unsigned already_added_id_text = 0; + for(i = 0; i != info.text_num; ++i) { + const char* k = info.text_keys[i]; + /* Could use strcmp, but we're not calling or reimplementing this C library function for this use only */ + if(k[0] == 'L' && k[1] == 'o' && k[2] == 'd' && k[3] == 'e' && + k[4] == 'P' && k[5] == 'N' && k[6] == 'G' && k[7] == '\0') { + already_added_id_text = 1; + break; + } + } + if(already_added_id_text == 0) { + state->error = addChunk_tEXt(&outv, "LodePNG", LODEPNG_VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/ + if(state->error) goto cleanup; + } + } + /*iTXt*/ + for(i = 0; i != info.itext_num; ++i) { + if(lodepng_strlen(info.itext_keys[i]) > 79) { + state->error = 66; /*text chunk too large*/ + goto cleanup; + } + if(lodepng_strlen(info.itext_keys[i]) < 1) { + state->error = 67; /*text chunk too small*/ + goto cleanup; + } + state->error = addChunk_iTXt( + &outv, state->encoder.text_compression, + info.itext_keys[i], info.itext_langtags[i], info.itext_transkeys[i], info.itext_strings[i], + &state->encoder.zlibsettings); + if(state->error) goto cleanup; + } + + /*unknown chunks between IDAT and IEND*/ + if(info.unknown_chunks_data[2]) { + state->error = addUnknownChunks(&outv, info.unknown_chunks_data[2], info.unknown_chunks_size[2]); + if(state->error) goto cleanup; + } +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + state->error = addChunk_IEND(&outv); + if(state->error) goto cleanup; + } + +cleanup: + lodepng_info_cleanup(&info); + lodepng_free(data); + + /*instead of cleaning the vector up, give it to the output*/ + *out = outv.data; + *outsize = outv.size; + + return state->error; +} + +unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, const unsigned char* image, + unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { + unsigned error; + LodePNGState state; + lodepng_state_init(&state); + state.info_raw.colortype = colortype; + state.info_raw.bitdepth = bitdepth; + state.info_png.color.colortype = colortype; + state.info_png.color.bitdepth = bitdepth; + lodepng_encode(out, outsize, image, w, h, &state); + error = state.error; + lodepng_state_cleanup(&state); + return error; +} + +unsigned lodepng_encode32(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h) { + return lodepng_encode_memory(out, outsize, image, w, h, LCT_RGBA, 8); +} + +unsigned lodepng_encode24(unsigned char** out, size_t* outsize, const unsigned char* image, unsigned w, unsigned h) { + return lodepng_encode_memory(out, outsize, image, w, h, LCT_RGB, 8); +} + +#ifdef LODEPNG_COMPILE_DISK +unsigned lodepng_encode_file(const char* filename, const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth) { + unsigned char* buffer; + size_t buffersize; + unsigned error = lodepng_encode_memory(&buffer, &buffersize, image, w, h, colortype, bitdepth); + if(!error) error = lodepng_save_file(buffer, buffersize, filename); + lodepng_free(buffer); + return error; +} + +unsigned lodepng_encode32_file(const char* filename, const unsigned char* image, unsigned w, unsigned h) { + return lodepng_encode_file(filename, image, w, h, LCT_RGBA, 8); +} + +unsigned lodepng_encode24_file(const char* filename, const unsigned char* image, unsigned w, unsigned h) { + return lodepng_encode_file(filename, image, w, h, LCT_RGB, 8); +} +#endif /*LODEPNG_COMPILE_DISK*/ + +void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings) { + lodepng_compress_settings_init(&settings->zlibsettings); + settings->filter_palette_zero = 1; + settings->filter_strategy = LFS_MINSUM; + settings->auto_convert = 1; + settings->force_palette = 0; + settings->predefined_filters = 0; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + settings->add_id = 0; + settings->text_compression = 1; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} + +#endif /*LODEPNG_COMPILE_ENCODER*/ +#endif /*LODEPNG_COMPILE_PNG*/ + +#ifdef LODEPNG_COMPILE_ERROR_TEXT +/* +This returns the description of a numerical error code in English. This is also +the documentation of all the error codes. +*/ +const char* lodepng_error_text(unsigned code) { + switch(code) { + case 0: return "no error, everything went ok"; + case 1: return "nothing done yet"; /*the Encoder/Decoder has done nothing yet, error checking makes no sense yet*/ + case 10: return "end of input memory reached without huffman end code"; /*while huffman decoding*/ + case 11: return "error in code tree made it jump outside of huffman tree"; /*while huffman decoding*/ + case 13: return "problem while processing dynamic deflate block"; + case 14: return "problem while processing dynamic deflate block"; + case 15: return "problem while processing dynamic deflate block"; + /*this error could happen if there are only 0 or 1 symbols present in the huffman code:*/ + case 16: return "invalid code while processing dynamic deflate block"; + case 17: return "end of out buffer memory reached while inflating"; + case 18: return "invalid distance code while inflating"; + case 19: return "end of out buffer memory reached while inflating"; + case 20: return "invalid deflate block BTYPE encountered while decoding"; + case 21: return "NLEN is not ones complement of LEN in a deflate block"; + + /*end of out buffer memory reached while inflating: + This can happen if the inflated deflate data is longer than the amount of bytes required to fill up + all the pixels of the image, given the color depth and image dimensions. Something that doesn't + happen in a normal, well encoded, PNG image.*/ + case 22: return "end of out buffer memory reached while inflating"; + case 23: return "end of in buffer memory reached while inflating"; + case 24: return "invalid FCHECK in zlib header"; + case 25: return "invalid compression method in zlib header"; + case 26: return "FDICT encountered in zlib header while it's not used for PNG"; + case 27: return "PNG file is smaller than a PNG header"; + /*Checks the magic file header, the first 8 bytes of the PNG file*/ + case 28: return "incorrect PNG signature, it's no PNG or corrupted"; + case 29: return "first chunk is not the header chunk"; + case 30: return "chunk length too large, chunk broken off at end of file"; + case 31: return "illegal PNG color type or bpp"; + case 32: return "illegal PNG compression method"; + case 33: return "illegal PNG filter method"; + case 34: return "illegal PNG interlace method"; + case 35: return "chunk length of a chunk is too large or the chunk too small"; + case 36: return "illegal PNG filter type encountered"; + case 37: return "illegal bit depth for this color type given"; + case 38: return "the palette is too small or too big"; /*0, or more than 256 colors*/ + case 39: return "tRNS chunk before PLTE or has more entries than palette size"; + case 40: return "tRNS chunk has wrong size for grayscale image"; + case 41: return "tRNS chunk has wrong size for RGB image"; + case 42: return "tRNS chunk appeared while it was not allowed for this color type"; + case 43: return "bKGD chunk has wrong size for palette image"; + case 44: return "bKGD chunk has wrong size for grayscale image"; + case 45: return "bKGD chunk has wrong size for RGB image"; + case 48: return "empty input buffer given to decoder. Maybe caused by non-existing file?"; + case 49: return "jumped past memory while generating dynamic huffman tree"; + case 50: return "jumped past memory while generating dynamic huffman tree"; + case 51: return "jumped past memory while inflating huffman block"; + case 52: return "jumped past memory while inflating"; + case 53: return "size of zlib data too small"; + case 54: return "repeat symbol in tree while there was no value symbol yet"; + /*jumped past tree while generating huffman tree, this could be when the + tree will have more leaves than symbols after generating it out of the + given lengths. They call this an oversubscribed dynamic bit lengths tree in zlib.*/ + case 55: return "jumped past tree while generating huffman tree"; + case 56: return "given output image colortype or bitdepth not supported for color conversion"; + case 57: return "invalid CRC encountered (checking CRC can be disabled)"; + case 58: return "invalid ADLER32 encountered (checking ADLER32 can be disabled)"; + case 59: return "requested color conversion not supported"; + case 60: return "invalid window size given in the settings of the encoder (must be 0-32768)"; + case 61: return "invalid BTYPE given in the settings of the encoder (only 0, 1 and 2 are allowed)"; + /*LodePNG leaves the choice of RGB to grayscale conversion formula to the user.*/ + case 62: return "conversion from color to grayscale not supported"; + /*(2^31-1)*/ + case 63: return "length of a chunk too long, max allowed for PNG is 2147483647 bytes per chunk"; + /*this would result in the inability of a deflated block to ever contain an end code. It must be at least 1.*/ + case 64: return "the length of the END symbol 256 in the Huffman tree is 0"; + case 66: return "the length of a text chunk keyword given to the encoder is longer than the maximum of 79 bytes"; + case 67: return "the length of a text chunk keyword given to the encoder is smaller than the minimum of 1 byte"; + case 68: return "tried to encode a PLTE chunk with a palette that has less than 1 or more than 256 colors"; + case 69: return "unknown chunk type with 'critical' flag encountered by the decoder"; + case 71: return "invalid interlace mode given to encoder (must be 0 or 1)"; + case 72: return "while decoding, invalid compression method encountering in zTXt or iTXt chunk (it must be 0)"; + case 73: return "invalid tIME chunk size"; + case 74: return "invalid pHYs chunk size"; + /*length could be wrong, or data chopped off*/ + case 75: return "no null termination char found while decoding text chunk"; + case 76: return "iTXt chunk too short to contain required bytes"; + case 77: return "integer overflow in buffer size"; + case 78: return "failed to open file for reading"; /*file doesn't exist or couldn't be opened for reading*/ + case 79: return "failed to open file for writing"; + case 80: return "tried creating a tree of 0 symbols"; + case 81: return "lazy matching at pos 0 is impossible"; + case 82: return "color conversion to palette requested while a color isn't in palette, or index out of bounds"; + case 83: return "memory allocation failed"; + case 84: return "given image too small to contain all pixels to be encoded"; + case 86: return "impossible offset in lz77 encoding (internal bug)"; + case 87: return "must provide custom zlib function pointer if LODEPNG_COMPILE_ZLIB is not defined"; + case 88: return "invalid filter strategy given for LodePNGEncoderSettings.filter_strategy"; + case 89: return "text chunk keyword too short or long: must have size 1-79"; + /*the windowsize in the LodePNGCompressSettings. Requiring POT(==> & instead of %) makes encoding 12% faster.*/ + case 90: return "windowsize must be a power of two"; + case 91: return "invalid decompressed idat size"; + case 92: return "integer overflow due to too many pixels"; + case 93: return "zero width or height is invalid"; + case 94: return "header chunk must have a size of 13 bytes"; + case 95: return "integer overflow with combined idat chunk size"; + case 96: return "invalid gAMA chunk size"; + case 97: return "invalid cHRM chunk size"; + case 98: return "invalid sRGB chunk size"; + case 99: return "invalid sRGB rendering intent"; + case 100: return "invalid ICC profile color type, the PNG specification only allows RGB or GRAY"; + case 101: return "PNG specification does not allow RGB ICC profile on gray color types and vice versa"; + case 102: return "not allowed to set grayscale ICC profile with colored pixels by PNG specification"; + case 103: return "invalid palette index in bKGD chunk. Maybe it came before PLTE chunk?"; + case 104: return "invalid bKGD color while encoding (e.g. palette index out of range)"; + case 105: return "integer overflow of bitsize"; + case 106: return "PNG file must have PLTE chunk if color type is palette"; + case 107: return "color convert from palette mode requested without setting the palette data in it"; + case 108: return "tried to add more than 256 values to a palette"; + } + return "unknown error code"; +} +#endif /*LODEPNG_COMPILE_ERROR_TEXT*/ + +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* // C++ Wrapper // */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +#ifdef LODEPNG_COMPILE_CPP +namespace lodepng { + +#ifdef LODEPNG_COMPILE_DISK +unsigned load_file(std::vector& buffer, const std::string& filename) { + long size = lodepng_filesize(filename.c_str()); + if(size < 0) return 78; + buffer.resize((size_t)size); + return size == 0 ? 0 : lodepng_buffer_file(&buffer[0], (size_t)size, filename.c_str()); +} + +/*write given buffer to the file, overwriting the file, it doesn't append to it.*/ +unsigned save_file(const std::vector& buffer, const std::string& filename) { + return lodepng_save_file(buffer.empty() ? 0 : &buffer[0], buffer.size(), filename.c_str()); +} +#endif /* LODEPNG_COMPILE_DISK */ + +#ifdef LODEPNG_COMPILE_ZLIB +#ifdef LODEPNG_COMPILE_DECODER +unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGDecompressSettings& settings) { + unsigned char* buffer = 0; + size_t buffersize = 0; + unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings); + if(buffer) { + out.insert(out.end(), &buffer[0], &buffer[buffersize]); + lodepng_free(buffer); + } + return error; +} + +unsigned decompress(std::vector& out, const std::vector& in, + const LodePNGDecompressSettings& settings) { + return decompress(out, in.empty() ? 0 : &in[0], in.size(), settings); +} +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +unsigned compress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGCompressSettings& settings) { + unsigned char* buffer = 0; + size_t buffersize = 0; + unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings); + if(buffer) { + out.insert(out.end(), &buffer[0], &buffer[buffersize]); + lodepng_free(buffer); + } + return error; +} + +unsigned compress(std::vector& out, const std::vector& in, + const LodePNGCompressSettings& settings) { + return compress(out, in.empty() ? 0 : &in[0], in.size(), settings); +} +#endif /* LODEPNG_COMPILE_ENCODER */ +#endif /* LODEPNG_COMPILE_ZLIB */ + + +#ifdef LODEPNG_COMPILE_PNG + +State::State() { + lodepng_state_init(this); +} + +State::State(const State& other) { + lodepng_state_init(this); + lodepng_state_copy(this, &other); +} + +State::~State() { + lodepng_state_cleanup(this); +} + +State& State::operator=(const State& other) { + lodepng_state_copy(this, &other); + return *this; +} + +#ifdef LODEPNG_COMPILE_DECODER + +unsigned decode(std::vector& out, unsigned& w, unsigned& h, const unsigned char* in, + size_t insize, LodePNGColorType colortype, unsigned bitdepth) { + unsigned char* buffer = 0; + unsigned error = lodepng_decode_memory(&buffer, &w, &h, in, insize, colortype, bitdepth); + if(buffer && !error) { + State state; + state.info_raw.colortype = colortype; + state.info_raw.bitdepth = bitdepth; + size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); + out.insert(out.end(), &buffer[0], &buffer[buffersize]); + } + lodepng_free(buffer); + return error; +} + +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::vector& in, LodePNGColorType colortype, unsigned bitdepth) { + return decode(out, w, h, in.empty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); +} + +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const unsigned char* in, size_t insize) { + unsigned char* buffer = NULL; + unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize); + if(buffer && !error) { + size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); + out.insert(out.end(), &buffer[0], &buffer[buffersize]); + } + lodepng_free(buffer); + return error; +} + +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const std::vector& in) { + return decode(out, w, h, state, in.empty() ? 0 : &in[0], in.size()); +} + +#ifdef LODEPNG_COMPILE_DISK +unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, + LodePNGColorType colortype, unsigned bitdepth) { + std::vector buffer; + /* safe output values in case error happens */ + w = h = 0; + unsigned error = load_file(buffer, filename); + if(error) return error; + return decode(out, w, h, buffer, colortype, bitdepth); +} +#endif /* LODEPNG_COMPILE_DECODER */ +#endif /* LODEPNG_COMPILE_DISK */ + +#ifdef LODEPNG_COMPILE_ENCODER +unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth) { + unsigned char* buffer; + size_t buffersize; + unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth); + if(buffer) { + out.insert(out.end(), &buffer[0], &buffer[buffersize]); + lodepng_free(buffer); + } + return error; +} + +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth) { + if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; + return encode(out, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); +} + +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + State& state) { + unsigned char* buffer; + size_t buffersize; + unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state); + if(buffer) { + out.insert(out.end(), &buffer[0], &buffer[buffersize]); + lodepng_free(buffer); + } + return error; +} + +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + State& state) { + if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; + return encode(out, in.empty() ? 0 : &in[0], w, h, state); +} + +#ifdef LODEPNG_COMPILE_DISK +unsigned encode(const std::string& filename, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth) { + std::vector buffer; + unsigned error = encode(buffer, in, w, h, colortype, bitdepth); + if(!error) error = save_file(buffer, filename); + return error; +} + +unsigned encode(const std::string& filename, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth) { + if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; + return encode(filename, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); +} +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_ENCODER */ +#endif /* LODEPNG_COMPILE_PNG */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ diff --git a/components/thorvg-main/tools/svg2png/lodepng.h b/components/thorvg-main/tools/svg2png/lodepng.h new file mode 100644 index 0000000..87eedd2 --- /dev/null +++ b/components/thorvg-main/tools/svg2png/lodepng.h @@ -0,0 +1,1945 @@ +/* +LodePNG version 20200306 + +Copyright (c) 2005-2020 Lode Vandevenne + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + +#ifndef LODEPNG_H +#define LODEPNG_H + +#include /*for size_t*/ + +extern const char* LODEPNG_VERSION_STRING; + +/* +The following #defines are used to create code sections. They can be disabled +to disable code sections, which can give faster compile time and smaller binary. +The "NO_COMPILE" defines are designed to be used to pass as defines to the +compiler command to disable them without modifying this header, e.g. +-DLODEPNG_NO_COMPILE_ZLIB for gcc. +In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to +allow implementing a custom lodepng_crc32. +*/ +/*deflate & zlib. If disabled, you must specify alternative zlib functions in +the custom_zlib field of the compress and decompress settings*/ +#ifndef LODEPNG_NO_COMPILE_ZLIB +#define LODEPNG_COMPILE_ZLIB +#endif + +/*png encoder and png decoder*/ +#ifndef LODEPNG_NO_COMPILE_PNG +#define LODEPNG_COMPILE_PNG +#endif + +/*deflate&zlib decoder and png decoder*/ +#ifndef LODEPNG_NO_COMPILE_DECODER +#define LODEPNG_COMPILE_DECODER +#endif + +/*deflate&zlib encoder and png encoder*/ +#ifndef LODEPNG_NO_COMPILE_ENCODER +#define LODEPNG_COMPILE_ENCODER +#endif + +/*the optional built in harddisk file loading and saving functions*/ +#ifndef LODEPNG_NO_COMPILE_DISK +#define LODEPNG_COMPILE_DISK +#endif + +/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/ +#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS +#define LODEPNG_COMPILE_ANCILLARY_CHUNKS +#endif + +/*ability to convert error numerical codes to English text string*/ +#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT +#define LODEPNG_COMPILE_ERROR_TEXT +#endif + +/*Compile the default allocators (C's free, malloc and realloc). If you disable this, +you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your +source files with custom allocators.*/ +#ifndef LODEPNG_NO_COMPILE_ALLOCATORS +#define LODEPNG_COMPILE_ALLOCATORS +#endif + +/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/ +#ifdef __cplusplus +#ifndef LODEPNG_NO_COMPILE_CPP +#define LODEPNG_COMPILE_CPP +#endif +#endif + +#ifdef LODEPNG_COMPILE_CPP +#include +#include +#endif /*LODEPNG_COMPILE_CPP*/ + +#ifdef LODEPNG_COMPILE_PNG +/*The PNG color types (also used for raw image).*/ +typedef enum LodePNGColorType { + LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/ + LCT_RGB = 2, /*RGB: 8,16 bit*/ + LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/ + LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/ + LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/ + /*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid + byte value from 0 to 255 that could be present in an invalid PNG file header. Do + not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use + the valid color type names above, or numeric values like 1 or 7 when checking for + particular disallowed color type byte values, or cast to integer to print it.*/ + LCT_MAX_OCTET_VALUE = 255 +} LodePNGColorType; + +#ifdef LODEPNG_COMPILE_DECODER +/* +Converts PNG data in memory to raw pixel data. +out: Output parameter. Pointer to buffer that will contain the raw pixel data. + After decoding, its size is w * h * (bytes per pixel) bytes larger than + initially. Bytes per pixel depends on colortype and bitdepth. + Must be freed after usage with free(*out). + Note: for 16-bit per channel colors, uses big endian format like PNG does. +w: Output parameter. Pointer to width of pixel data. +h: Output parameter. Pointer to height of pixel data. +in: Memory buffer with the PNG file. +insize: size of the in buffer. +colortype: the desired color type for the raw output image. See explanation on PNG color types. +bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. +Return value: LodePNG error code (0 means no error). +*/ +unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/ +unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize); + +/*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/ +unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize); + +#ifdef LODEPNG_COMPILE_DISK +/* +Load PNG from disk, from file with given name. +Same as the other decode functions, but instead takes a filename as input. +*/ +unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/ +unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename); + +/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/ +unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename); +#endif /*LODEPNG_COMPILE_DISK*/ +#endif /*LODEPNG_COMPILE_DECODER*/ + + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Converts raw pixel data into a PNG image in memory. The colortype and bitdepth + of the output PNG image cannot be chosen, they are automatically determined + by the colortype, bitdepth and content of the input pixel data. + Note: for 16-bit per channel colors, needs big endian format like PNG does. +out: Output parameter. Pointer to buffer that will contain the PNG image data. + Must be freed after usage with free(*out). +outsize: Output parameter. Pointer to the size in bytes of the out buffer. +image: The raw pixel data to encode. The size of this buffer should be + w * h * (bytes per pixel), bytes per pixel depends on colortype and bitdepth. +w: width of the raw pixel data in pixels. +h: height of the raw pixel data in pixels. +colortype: the color type of the raw input image. See explanation on PNG color types. +bitdepth: the bit depth of the raw input image. See explanation on PNG color types. +Return value: LodePNG error code (0 means no error). +*/ +unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/ +unsigned lodepng_encode32(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h); + +/*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/ +unsigned lodepng_encode24(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h); + +#ifdef LODEPNG_COMPILE_DISK +/* +Converts raw pixel data into a PNG file on disk. +Same as the other encode functions, but instead takes a filename as output. +NOTE: This overwrites existing files without warning! +*/ +unsigned lodepng_encode_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/ +unsigned lodepng_encode32_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h); + +/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/ +unsigned lodepng_encode24_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h); +#endif /*LODEPNG_COMPILE_DISK*/ +#endif /*LODEPNG_COMPILE_ENCODER*/ + + +#ifdef LODEPNG_COMPILE_CPP +namespace lodepng { +#ifdef LODEPNG_COMPILE_DECODER +/*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype +is the format to output the pixels to. Default is RGBA 8-bit per channel.*/ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const unsigned char* in, size_t insize, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::vector& in, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#ifdef LODEPNG_COMPILE_DISK +/* +Converts PNG file from disk to raw pixel data in memory. +Same as the other decode functions, but instead takes a filename as input. +*/ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::string& filename, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +/*Same as lodepng_encode_memory, but encodes to an std::vector. colortype +is that of the raw input data. The output PNG color type will be auto chosen.*/ +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#ifdef LODEPNG_COMPILE_DISK +/* +Converts 32-bit RGBA raw pixel data into a PNG file on disk. +Same as the other encode functions, but instead takes a filename as output. +NOTE: This overwrites existing files without warning! +*/ +unsigned encode(const std::string& filename, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned encode(const std::string& filename, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_ENCODER */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ +#endif /*LODEPNG_COMPILE_PNG*/ + +#ifdef LODEPNG_COMPILE_ERROR_TEXT +/*Returns an English description of the numerical error code.*/ +const char* lodepng_error_text(unsigned code); +#endif /*LODEPNG_COMPILE_ERROR_TEXT*/ + +#ifdef LODEPNG_COMPILE_DECODER +/*Settings for zlib decompression*/ +typedef struct LodePNGDecompressSettings LodePNGDecompressSettings; +struct LodePNGDecompressSettings { + /* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */ + unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ + unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/ + + /*use custom zlib decoder instead of built in one (default: null)*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGDecompressSettings*); + /*use custom deflate decoder instead of built in one (default: null) + if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/ + unsigned (*custom_inflate)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGDecompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +extern const LodePNGDecompressSettings lodepng_default_decompress_settings; +void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Settings for zlib compression. Tweaking these settings tweaks the balance +between speed and compression ratio. +*/ +typedef struct LodePNGCompressSettings LodePNGCompressSettings; +struct LodePNGCompressSettings /*deflate = compress*/ { + /*LZ77 related settings*/ + unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/ + unsigned use_lz77; /*whether or not to use LZ77. Should be 1 for proper compression.*/ + unsigned windowsize; /*must be a power of two <= 32768. higher compresses more but is slower. Default value: 2048.*/ + unsigned minmatch; /*minimum lz77 length. 3 is normally best, 6 can be better for some PNGs. Default: 0*/ + unsigned nicematch; /*stop searching if >= this length found. Set to 258 for best compression. Default: 128*/ + unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/ + + /*use custom zlib encoder instead of built in one (default: null)*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGCompressSettings*); + /*use custom deflate encoder instead of built in one (default: null) + if custom_zlib is used, custom_deflate is ignored since only the built in + zlib function will call custom_deflate*/ + unsigned (*custom_deflate)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGCompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +extern const LodePNGCompressSettings lodepng_default_compress_settings; +void lodepng_compress_settings_init(LodePNGCompressSettings* settings); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_PNG +/* +Color mode of an image. Contains all information required to decode the pixel +bits to RGBA colors. This information is the same as used in the PNG file +format, and is used both for PNG and raw image data in LodePNG. +*/ +typedef struct LodePNGColorMode { + /*header (IHDR)*/ + LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/ + unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/ + + /* + palette (PLTE and tRNS) + + Dynamically allocated with the colors of the palette, including alpha. + This field may not be allocated directly, use lodepng_color_mode_init first, + then lodepng_palette_add per color to correctly initialize it (to ensure size + of exactly 1024 bytes). + + The alpha channels must be set as well, set them to 255 for opaque images. + + When decoding, by default you can ignore this palette, since LodePNG already + fills the palette colors in the pixels of the raw RGBA output. + + The palette is only supported for color type 3. + */ + unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/ + size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/ + + /* + transparent color key (tRNS) + + This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit. + For grayscale PNGs, r, g and b will all 3 be set to the same. + + When decoding, by default you can ignore this information, since LodePNG sets + pixels with this key to transparent already in the raw RGBA output. + + The color key is only supported for color types 0 and 2. + */ + unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/ + unsigned key_r; /*red/grayscale component of color key*/ + unsigned key_g; /*green component of color key*/ + unsigned key_b; /*blue component of color key*/ +} LodePNGColorMode; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_color_mode_init(LodePNGColorMode* info); +void lodepng_color_mode_cleanup(LodePNGColorMode* info); +/*return value is error code (0 means no error)*/ +unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source); +/* Makes a temporary LodePNGColorMode that does not need cleanup (no palette) */ +LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth); + +void lodepng_palette_clear(LodePNGColorMode* info); +/*add 1 color to the palette*/ +unsigned lodepng_palette_add(LodePNGColorMode* info, + unsigned char r, unsigned char g, unsigned char b, unsigned char a); + +/*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/ +unsigned lodepng_get_bpp(const LodePNGColorMode* info); +/*get the amount of color channels used, based on colortype in the struct. +If a palette is used, it counts as 1 channel.*/ +unsigned lodepng_get_channels(const LodePNGColorMode* info); +/*is it a grayscale type? (only colortype 0 or 4)*/ +unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info); +/*has it got an alpha channel? (only colortype 2 or 6)*/ +unsigned lodepng_is_alpha_type(const LodePNGColorMode* info); +/*has it got a palette? (only colortype 3)*/ +unsigned lodepng_is_palette_type(const LodePNGColorMode* info); +/*only returns true if there is a palette and there is a value in the palette with alpha < 255. +Loops through the palette to check this.*/ +unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info); +/* +Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image. +Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels). +Returns false if the image can only have opaque pixels. +In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values, +or if "key_defined" is true. +*/ +unsigned lodepng_can_have_alpha(const LodePNGColorMode* info); +/*Returns the byte size of a raw image buffer with given width, height and color mode*/ +size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +/*The information of a Time chunk in PNG.*/ +typedef struct LodePNGTime { + unsigned year; /*2 bytes used (0-65535)*/ + unsigned month; /*1-12*/ + unsigned day; /*1-31*/ + unsigned hour; /*0-23*/ + unsigned minute; /*0-59*/ + unsigned second; /*0-60 (to allow for leap seconds)*/ +} LodePNGTime; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/*Information about the PNG image, except pixels, width and height.*/ +typedef struct LodePNGInfo { + /*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/ + unsigned compression_method;/*compression method of the original file. Always 0.*/ + unsigned filter_method; /*filter method of the original file*/ + unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/ + LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /* + Suggested background color chunk (bKGD) + + This uses the same color mode and bit depth as the PNG (except no alpha channel), + with values truncated to the bit depth in the unsigned integer. + + For grayscale and palette PNGs, the value is stored in background_r. The values + in background_g and background_b are then unused. + + So when decoding, you may get these in a different color mode than the one you requested + for the raw pixels. + + When encoding with auto_convert, you must use the color model defined in info_png.color for + these values. The encoder normally ignores info_png.color when auto_convert is on, but will + use it to interpret these values (and convert copies of them to its chosen color model). + + When encoding, avoid setting this to an expensive color, such as a non-gray value + when the image is gray, or the compression will be worse since it will be forced to + write the PNG with a more expensive color mode (when auto_convert is on). + + The decoder does not use this background color to edit the color of pixels. This is a + completely optional metadata feature. + */ + unsigned background_defined; /*is a suggested background color given?*/ + unsigned background_r; /*red/gray/palette component of suggested background color*/ + unsigned background_g; /*green component of suggested background color*/ + unsigned background_b; /*blue component of suggested background color*/ + + /* + non-international text chunks (tEXt and zTXt) + + The char** arrays each contain num strings. The actual messages are in + text_strings, while text_keys are keywords that give a short description what + the actual text represents, e.g. Title, Author, Description, or anything else. + + All the string fields below including keys, names and language tags are null terminated. + The PNG specification uses null characters for the keys, names and tags, and forbids null + characters to appear in the main text which is why we can use null termination everywhere here. + + A keyword is minimum 1 character and maximum 79 characters long. It's + discouraged to use a single line length longer than 79 characters for texts. + + Don't allocate these text buffers yourself. Use the init/cleanup functions + correctly and use lodepng_add_text and lodepng_clear_text. + */ + size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/ + char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/ + char** text_strings; /*the actual text*/ + + /* + international text chunks (iTXt) + Similar to the non-international text chunks, but with additional strings + "langtags" and "transkeys". + */ + size_t itext_num; /*the amount of international texts in this PNG*/ + char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/ + char** itext_langtags; /*language tag for this text's language, ISO/IEC 646 string, e.g. ISO 639 language tag*/ + char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/ + char** itext_strings; /*the actual international text - UTF-8 string*/ + + /*time chunk (tIME)*/ + unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/ + LodePNGTime time; + + /*phys chunk (pHYs)*/ + unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/ + unsigned phys_x; /*pixels per unit in x direction*/ + unsigned phys_y; /*pixels per unit in y direction*/ + unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/ + + /* + Color profile related chunks: gAMA, cHRM, sRGB, iCPP + + LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color + profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please + use these values with a color management library. + + See the PNG, ICC and sRGB specifications for more information about the meaning of these values. + */ + + /* gAMA chunk: optional, overridden by sRGB or iCCP if those are present. */ + unsigned gama_defined; /* Whether a gAMA chunk is present (0 = not present, 1 = present). */ + unsigned gama_gamma; /* Gamma exponent times 100000 */ + + /* cHRM chunk: optional, overridden by sRGB or iCCP if those are present. */ + unsigned chrm_defined; /* Whether a cHRM chunk is present (0 = not present, 1 = present). */ + unsigned chrm_white_x; /* White Point x times 100000 */ + unsigned chrm_white_y; /* White Point y times 100000 */ + unsigned chrm_red_x; /* Red x times 100000 */ + unsigned chrm_red_y; /* Red y times 100000 */ + unsigned chrm_green_x; /* Green x times 100000 */ + unsigned chrm_green_y; /* Green y times 100000 */ + unsigned chrm_blue_x; /* Blue x times 100000 */ + unsigned chrm_blue_y; /* Blue y times 100000 */ + + /* + sRGB chunk: optional. May not appear at the same time as iCCP. + If gAMA is also present gAMA must contain value 45455. + If cHRM is also present cHRM must contain respectively 31270,32900,64000,33000,30000,60000,15000,6000. + */ + unsigned srgb_defined; /* Whether an sRGB chunk is present (0 = not present, 1 = present). */ + unsigned srgb_intent; /* Rendering intent: 0=perceptual, 1=rel. colorimetric, 2=saturation, 3=abs. colorimetric */ + + /* + iCCP chunk: optional. May not appear at the same time as sRGB. + + LodePNG does not parse or use the ICC profile (except its color space header field for an edge case), a + separate library to handle the ICC data (not included in LodePNG) format is needed to use it for color + management and conversions. + + For encoding, if iCCP is present, gAMA and cHRM are recommended to be added as well with values that match the ICC + profile as closely as possible, if you wish to do this you should provide the correct values for gAMA and cHRM and + enable their '_defined' flags since LodePNG will not automatically compute them from the ICC profile. + + For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray + PNG color types and a "GRAY" profile for gray PNG color types. If you disable auto_convert, you must ensure + the ICC profile type matches your requested color type, else the encoder gives an error. If auto_convert is + enabled (the default), and the ICC profile is not a good match for the pixel data, this will result in an encoder + error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of the pixel + data if the pixels could be encoded as grayscale but the ICC profile is RGB. + + To avoid this do not set an ICC profile in the image unless there is a good reason for it, and when doing so + make sure you compute it carefully to avoid the above problems. + */ + unsigned iccp_defined; /* Whether an iCCP chunk is present (0 = not present, 1 = present). */ + char* iccp_name; /* Null terminated string with profile name, 1-79 bytes */ + /* + The ICC profile in iccp_profile_size bytes. + Don't allocate this buffer yourself. Use the init/cleanup functions + correctly and use lodepng_set_icc and lodepng_clear_icc. + */ + unsigned char* iccp_profile; + unsigned iccp_profile_size; /* The size of iccp_profile in bytes */ + + /* End of color profile related chunks */ + + + /* + unknown chunks: chunks not known by LodePNG, passed on byte for byte. + + There are 3 buffers, one for each position in the PNG where unknown chunks can appear. + Each buffer contains all unknown chunks for that position consecutively. + The 3 positions are: + 0: between IHDR and PLTE, 1: between PLTE and IDAT, 2: between IDAT and IEND. + + For encoding, do not store critical chunks or known chunks that are enabled with a "_defined" flag + above in here, since the encoder will blindly follow this and could then encode an invalid PNG file + (such as one with two IHDR chunks or the disallowed combination of sRGB with iCCP). But do use + this if you wish to store an ancillary chunk that is not supported by LodePNG (such as sPLT or hIST), + or any non-standard PNG chunk. + + Do not allocate or traverse this data yourself. Use the chunk traversing functions declared + later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct. + */ + unsigned char* unknown_chunks_data[3]; + size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGInfo; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_info_init(LodePNGInfo* info); +void lodepng_info_cleanup(LodePNGInfo* info); +/*return value is error code (0 means no error)*/ +unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str); /*push back both texts at once*/ +void lodepng_clear_text(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ + +unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, + const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/ +void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts again after you filled them in*/ + +/*replaces if exists*/ +unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size); +void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/* +Converts raw buffer from one color type to another color type, based on +LodePNGColorMode structs to describe the input and output color type. +See the reference manual at the end of this header file to see which color conversions are supported. +return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported) +The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel +of the output color type (lodepng_get_bpp). +For < 8 bpp images, there should not be padding bits at the end of scanlines. +For 16-bit per channel colors, uses big endian format like PNG does. +Return value is LodePNG error code +*/ +unsigned lodepng_convert(unsigned char* out, const unsigned char* in, + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, + unsigned w, unsigned h); + +#ifdef LODEPNG_COMPILE_DECODER +/* +Settings for the decoder. This contains settings for the PNG and the Zlib +decoder, but not the Info settings from the Info structs. +*/ +typedef struct LodePNGDecoderSettings { + LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/ + + /* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */ + unsigned ignore_crc; /*ignore CRC checksums*/ + unsigned ignore_critical; /*ignore unknown critical chunks*/ + unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/ + /* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable + errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some + strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters + in string keys, etc... */ + + unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/ + /*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/ + unsigned remember_unknown_chunks; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGDecoderSettings; + +void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/*automatically use color type with less bits per pixel if losslessly possible. Default: AUTO*/ +typedef enum LodePNGFilterStrategy { + /*every filter at zero*/ + LFS_ZERO = 0, + /*every filter at 1, 2, 3 or 4 (paeth), unlike LFS_ZERO not a good choice, but for testing*/ + LFS_ONE = 1, + LFS_TWO = 2, + LFS_THREE = 3, + LFS_FOUR = 4, + /*Use filter that gives minimum sum, as described in the official PNG filter heuristic.*/ + LFS_MINSUM, + /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending + on the image, this is better or worse than minsum.*/ + LFS_ENTROPY, + /* + Brute-force-search PNG filters by compressing each filter for each scanline. + Experimental, very slow, and only rarely gives better compression than MINSUM. + */ + LFS_BRUTE_FORCE, + /*use predefined_filters buffer: you specify the filter type for each scanline*/ + LFS_PREDEFINED +} LodePNGFilterStrategy; + +/*Gives characteristics about the integer RGBA colors of the image (count, alpha channel usage, bit depth, ...), +which helps decide which color model to use for encoding. +Used internally by default if "auto_convert" is enabled. Public because it's useful for custom algorithms.*/ +typedef struct LodePNGColorStats { + unsigned colored; /*not grayscale*/ + unsigned key; /*image is not opaque and color key is possible instead of full alpha*/ + unsigned short key_r; /*key values, always as 16-bit, in 8-bit case the byte is duplicated, e.g. 65535 means 255*/ + unsigned short key_g; + unsigned short key_b; + unsigned alpha; /*image is not opaque and alpha channel or alpha palette required*/ + unsigned numcolors; /*amount of colors, up to 257. Not valid if bits == 16 or allow_palette is disabled.*/ + unsigned char palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order, only valid when numcolors is valid*/ + unsigned bits; /*bits per channel (not for palette). 1,2 or 4 for grayscale only. 16 if 16-bit per channel required.*/ + size_t numpixels; + + /*user settings for computing/using the stats*/ + unsigned allow_palette; /*default 1. if 0, disallow choosing palette colortype in auto_choose_color, and don't count numcolors*/ + unsigned allow_greyscale; /*default 1. if 0, choose RGB or RGBA even if the image only has gray colors*/ +} LodePNGColorStats; + +void lodepng_color_stats_init(LodePNGColorStats* stats); + +/*Get a LodePNGColorStats of the image. The stats must already have been inited. +Returns error code (e.g. alloc fail) or 0 if ok.*/ +unsigned lodepng_compute_color_stats(LodePNGColorStats* stats, + const unsigned char* image, unsigned w, unsigned h, + const LodePNGColorMode* mode_in); + +/*Settings for the encoder.*/ +typedef struct LodePNGEncoderSettings { + LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/ + + unsigned auto_convert; /*automatically choose output PNG color type. Default: true*/ + + /*If true, follows the official PNG heuristic: if the PNG uses a palette or lower than + 8 bit depth, set all filters to zero. Otherwise use the filter_strategy. Note that to + completely follow the official PNG heuristic, filter_palette_zero must be true and + filter_strategy must be LFS_MINSUM*/ + unsigned filter_palette_zero; + /*Which filter strategy to use when not using zeroes due to filter_palette_zero. + Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/ + LodePNGFilterStrategy filter_strategy; + /*used if filter_strategy is LFS_PREDEFINED. In that case, this must point to a buffer with + the same length as the amount of scanlines in the image, and each value must <= 5. You + have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero + must be set to 0 to ensure this is also used on palette or low bitdepth images.*/ + const unsigned char* predefined_filters; + + /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette). + If colortype is 3, PLTE is _always_ created.*/ + unsigned force_palette; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*add LodePNG identifier and version as a text chunk, for debugging*/ + unsigned add_id; + /*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/ + unsigned text_compression; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGEncoderSettings; + +void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings); +#endif /*LODEPNG_COMPILE_ENCODER*/ + + +#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) +/*The settings, state and information for extended encoding and decoding.*/ +typedef struct LodePNGState { +#ifdef LODEPNG_COMPILE_DECODER + LodePNGDecoderSettings decoder; /*the decoding settings*/ +#endif /*LODEPNG_COMPILE_DECODER*/ +#ifdef LODEPNG_COMPILE_ENCODER + LodePNGEncoderSettings encoder; /*the encoding settings*/ +#endif /*LODEPNG_COMPILE_ENCODER*/ + LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/ + LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ + unsigned error; +} LodePNGState; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_state_init(LodePNGState* state); +void lodepng_state_cleanup(LodePNGState* state); +void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source); +#endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ + +#ifdef LODEPNG_COMPILE_DECODER +/* +Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and +getting much more information about the PNG image and color mode. +*/ +unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize); + +/* +Read the PNG header, but not the actual data. This returns only the information +that is in the IHDR chunk of the PNG, such as width, height and color type. The +information is placed in the info_png field of the LodePNGState. +*/ +unsigned lodepng_inspect(unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize); +#endif /*LODEPNG_COMPILE_DECODER*/ + +/* +Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it +read in the state. Returns error code on failure. +Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const +to find the desired chunk type, and if non null use lodepng_inspect_chunk (with +chunk_pointer - start_of_file as pos). +Supports most metadata chunks from the PNG standard (gAMA, bKGD, tEXt, ...). +Ignores unsupported, unknown, non-metadata or IHDR chunks (without error). +Requirements: &in[pos] must point to start of a chunk, must use regular +lodepng_inspect first since format of most other chunks depends on IHDR, and if +there is a PLTE chunk, that one must be inspected before tRNS or bKGD. +*/ +unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, + const unsigned char* in, size_t insize); + +#ifdef LODEPNG_COMPILE_ENCODER +/*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/ +unsigned lodepng_encode(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGState* state); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +/* +The lodepng_chunk functions are normally not needed, except to traverse the +unknown chunks stored in the LodePNGInfo struct, or add new ones to it. +It also allows traversing the chunks of an encoded PNG file yourself. + +The chunk pointer always points to the beginning of the chunk itself, that is +the first byte of the 4 length bytes. + +In the PNG file format, chunks have the following format: +-4 bytes length: length of the data of the chunk in bytes (chunk itself is 12 bytes longer) +-4 bytes chunk type (ASCII a-z,A-Z only, see below) +-length bytes of data (may be 0 bytes if length was 0) +-4 bytes of CRC, computed on chunk name + data + +The first chunk starts at the 8th byte of the PNG file, the entire rest of the file +exists out of concatenated chunks with the above format. + +PNG standard chunk ASCII naming conventions: +-First byte: uppercase = critical, lowercase = ancillary +-Second byte: uppercase = public, lowercase = private +-Third byte: must be uppercase +-Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy +*/ + +/* +Gets the length of the data of the chunk. Total chunk length has 12 bytes more. +There must be at least 4 bytes to read from. If the result value is too large, +it may be corrupt data. +*/ +unsigned lodepng_chunk_length(const unsigned char* chunk); + +/*puts the 4-byte type in null terminated string*/ +void lodepng_chunk_type(char type[5], const unsigned char* chunk); + +/*check if the type is the given type*/ +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type); + +/*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/ +unsigned char lodepng_chunk_ancillary(const unsigned char* chunk); + +/*0: public, 1: private (see PNG standard)*/ +unsigned char lodepng_chunk_private(const unsigned char* chunk); + +/*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/ +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk); + +/*get pointer to the data of the chunk, where the input points to the header of the chunk*/ +unsigned char* lodepng_chunk_data(unsigned char* chunk); +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk); + +/*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/ +unsigned lodepng_chunk_check_crc(const unsigned char* chunk); + +/*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/ +void lodepng_chunk_generate_crc(unsigned char* chunk); + +/* +Iterate to next chunks, allows iterating through all chunks of the PNG file. +Input must be at the beginning of a chunk (result of a previous lodepng_chunk_next call, +or the 8th byte of a PNG file which always has the first chunk), or alternatively may +point to the first byte of the PNG file (which is not a chunk but the magic header, the +function will then skip over it and return the first real chunk). +Will output pointer to the start of the next chunk, or at or beyond end of the file if there +is no more chunk after this or possibly if the chunk is corrupt. +Start this process at the 8th byte of the PNG file. +In a non-corrupt PNG file, the last chunk should have name "IEND". +*/ +unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end); +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end); + +/*Finds the first chunk with the given type in the range [chunk, end), or returns NULL if not found.*/ +unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]); +const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]); + +/* +Appends chunk to the data in out. The given chunk should already have its chunk header. +The out variable and outsize are updated to reflect the new reallocated buffer. +Returns error code (0 if it went ok) +*/ +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk); + +/* +Appends new chunk to out. The chunk to append is given by giving its length, type +and data separately. The type is a 4-letter string. +The out variable and outsize are updated to reflect the new reallocated buffer. +Return error code (0 if it went ok) +*/ +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, + const char* type, const unsigned char* data); + + +/*Calculate CRC32 of buffer*/ +unsigned lodepng_crc32(const unsigned char* buf, size_t len); +#endif /*LODEPNG_COMPILE_PNG*/ + + +#ifdef LODEPNG_COMPILE_ZLIB +/* +This zlib part can be used independently to zlib compress and decompress a +buffer. It cannot be used to create gzip files however, and it only supports the +part of zlib that is required for PNG, it does not support dictionaries. +*/ + +#ifdef LODEPNG_COMPILE_DECODER +/*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/ +unsigned lodepng_inflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings); + +/* +Decompresses Zlib data. Reallocates the out buffer and appends the data. The +data must be according to the zlib specification. +Either, *out must be NULL and *outsize must be 0, or, *out must be a valid +buffer and *outsize its size in bytes. out must be freed by user after usage. +*/ +unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Compresses data with Zlib. Reallocates the out buffer and appends the data. +Zlib adds a small header and trailer around the deflate data. +The data is output in the format of the zlib specification. +Either, *out must be NULL and *outsize must be 0, or, *out must be a valid +buffer and *outsize its size in bytes. out must be freed by user after usage. +*/ +unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings); + +/* +Find length-limited Huffman code for given frequencies. This function is in the +public interface only for tests, it's used internally by lodepng_deflate. +*/ +unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, + size_t numcodes, unsigned maxbitlen); + +/*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/ +unsigned lodepng_deflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings); + +#endif /*LODEPNG_COMPILE_ENCODER*/ +#endif /*LODEPNG_COMPILE_ZLIB*/ + +#ifdef LODEPNG_COMPILE_DISK +/* +Load a file from disk into buffer. The function allocates the out buffer, and +after usage you should free it. +out: output parameter, contains pointer to loaded buffer. +outsize: output parameter, size of the allocated out buffer +filename: the path to the file to load +return value: error code (0 means ok) +*/ +unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename); + +/* +Save a file from buffer to disk. Warning, if it exists, this function overwrites +the file without warning! +buffer: the buffer to write +buffersize: size of the buffer to write +filename: the path to the file to save to +return value: error code (0 means ok) +*/ +unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); +#endif /*LODEPNG_COMPILE_DISK*/ + +#ifdef LODEPNG_COMPILE_CPP +/* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */ +namespace lodepng { +#ifdef LODEPNG_COMPILE_PNG +class State : public LodePNGState { + public: + State(); + State(const State& other); + ~State(); + State& operator=(const State& other); +}; + +#ifdef LODEPNG_COMPILE_DECODER +/* Same as other lodepng::decode, but using a State for more settings and information. */ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const unsigned char* in, size_t insize); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const std::vector& in); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* Same as other lodepng::encode, but using a State for more settings and information. */ +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + State& state); +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + State& state); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_DISK +/* +Load a file from disk into an std::vector. +return value: error code (0 means ok) +*/ +unsigned load_file(std::vector& buffer, const std::string& filename); + +/* +Save the binary data in an std::vector to a file on disk. The file is overwritten +without warning. +*/ +unsigned save_file(const std::vector& buffer, const std::string& filename); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_PNG */ + +#ifdef LODEPNG_COMPILE_ZLIB +#ifdef LODEPNG_COMPILE_DECODER +/* Zlib-decompress an unsigned char buffer */ +unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); + +/* Zlib-decompress an std::vector */ +unsigned decompress(std::vector& out, const std::vector& in, + const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +/* Zlib-compress an unsigned char buffer */ +unsigned compress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGCompressSettings& settings = lodepng_default_compress_settings); + +/* Zlib-compress an std::vector */ +unsigned compress(std::vector& out, const std::vector& in, + const LodePNGCompressSettings& settings = lodepng_default_compress_settings); +#endif /* LODEPNG_COMPILE_ENCODER */ +#endif /* LODEPNG_COMPILE_ZLIB */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ + +/* +TODO: +[.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often +[.] check compatibility with various compilers - done but needs to be redone for every newer version +[X] converting color to 16-bit per channel types +[X] support color profile chunk types (but never let them touch RGB values by default) +[ ] support all public PNG chunk types (almost done except sBIT, sPLT and hIST) +[ ] make sure encoder generates no chunks with size > (2^31)-1 +[ ] partial decoding (stream processing) +[X] let the "isFullyOpaque" function check color keys and transparent palettes too +[X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl" +[ ] allow treating some errors like warnings, when image is recoverable (e.g. 69, 57, 58) +[ ] make warnings like: oob palette, checksum fail, data after iend, wrong/unknown crit chunk, no null terminator in text, ... +[ ] error messages with line numbers (and version) +[ ] errors in state instead of as return code? +[ ] new errors/warnings like suspiciously big decompressed ztxt or iccp chunk +[ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes +[ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ... +[ ] allow user to give data (void*) to custom allocator +[X] provide alternatives for C library functions not present on some platforms (memcpy, ...) +*/ + +#endif /*LODEPNG_H inclusion guard*/ + +/* +LodePNG Documentation +--------------------- + +0. table of contents +-------------------- + + 1. about + 1.1. supported features + 1.2. features not supported + 2. C and C++ version + 3. security + 4. decoding + 5. encoding + 6. color conversions + 6.1. PNG color types + 6.2. color conversions + 6.3. padding bits + 6.4. A note about 16-bits per channel and endianness + 7. error values + 8. chunks and PNG editing + 9. compiler support + 10. examples + 10.1. decoder C++ example + 10.2. decoder C example + 11. state settings reference + 12. changes + 13. contact information + + +1. about +-------- + +PNG is a file format to store raster images losslessly with good compression, +supporting different color types and alpha channel. + +LodePNG is a PNG codec according to the Portable Network Graphics (PNG) +Specification (Second Edition) - W3C Recommendation 10 November 2003. + +The specifications used are: + +*) Portable Network Graphics (PNG) Specification (Second Edition): + http://www.w3.org/TR/2003/REC-PNG-20031110 +*) RFC 1950 ZLIB Compressed Data Format version 3.3: + http://www.gzip.org/zlib/rfc-zlib.html +*) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3: + http://www.gzip.org/zlib/rfc-deflate.html + +The most recent version of LodePNG can currently be found at +http://lodev.org/lodepng/ + +LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds +extra functionality. + +LodePNG exists out of two files: +-lodepng.h: the header file for both C and C++ +-lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage + +If you want to start using LodePNG right away without reading this doc, get the +examples from the LodePNG website to see how to use it in code, or check the +smaller examples in chapter 13 here. + +LodePNG is simple but only supports the basic requirements. To achieve +simplicity, the following design choices were made: There are no dependencies +on any external library. There are functions to decode and encode a PNG with +a single function call, and extended versions of these functions taking a +LodePNGState struct allowing to specify or get more information. By default +the colors of the raw image are always RGB or RGBA, no matter what color type +the PNG file uses. To read and write files, there are simple functions to +convert the files to/from buffers in memory. + +This all makes LodePNG suitable for loading textures in games, demos and small +programs, ... It's less suitable for full fledged image editors, loading PNGs +over network (it requires all the image data to be available before decoding can +begin), life-critical systems, ... + +1.1. supported features +----------------------- + +The following features are supported by the decoder: + +*) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image, + or the same color type as the PNG +*) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image +*) Adam7 interlace and deinterlace for any color type +*) loading the image from harddisk or decoding it from a buffer from other sources than harddisk +*) support for alpha channels, including RGBA color model, translucent palettes and color keying +*) zlib decompression (inflate) +*) zlib compression (deflate) +*) CRC32 and ADLER32 checksums +*) colorimetric color profile conversions: currently experimentally available in lodepng_util.cpp only, + plus alternatively ability to pass on chroma/gamma/ICC profile information to other color management system. +*) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks. +*) the following chunks are supported by both encoder and decoder: + IHDR: header information + PLTE: color palette + IDAT: pixel data + IEND: the final chunk + tRNS: transparency for palettized images + tEXt: textual information + zTXt: compressed textual information + iTXt: international textual information + bKGD: suggested background color + pHYs: physical dimensions + tIME: modification time + cHRM: RGB chromaticities + gAMA: RGB gamma correction + iCCP: ICC color profile + sRGB: rendering intent + +1.2. features not supported +--------------------------- + +The following features are _not_ supported: + +*) some features needed to make a conformant PNG-Editor might be still missing. +*) partial loading/stream processing. All data must be available and is processed in one call. +*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG: + sBIT + hIST + sPLT + + +2. C and C++ version +-------------------- + +The C version uses buffers allocated with alloc that you need to free() +yourself. You need to use init and cleanup functions for each struct whenever +using a struct from the C version to avoid exploits and memory leaks. + +The C++ version has extra functions with std::vectors in the interface and the +lodepng::State class which is a LodePNGState with constructor and destructor. + +These files work without modification for both C and C++ compilers because all +the additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers +ignore it, and the C code is made to compile both with strict ISO C90 and C++. + +To use the C++ version, you need to rename the source file to lodepng.cpp +(instead of lodepng.c), and compile it with a C++ compiler. + +To use the C version, you need to rename the source file to lodepng.c (instead +of lodepng.cpp), and compile it with a C compiler. + + +3. Security +----------- + +Even if carefully designed, it's always possible that LodePNG contains possible +exploits. If you discover one, please let me know, and it will be fixed. + +When using LodePNG, care has to be taken with the C version of LodePNG, as well +as the C-style structs when working with C++. The following conventions are used +for all C-style structs: + +-if a struct has a corresponding init function, always call the init function when making a new one +-if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks +-if a struct has a corresponding copy function, use the copy function instead of "=". + The destination must also be inited already. + + +4. Decoding +----------- + +Decoding converts a PNG compressed image to a raw pixel buffer. + +Most documentation on using the decoder is at its declarations in the header +above. For C, simple decoding can be done with functions such as +lodepng_decode32, and more advanced decoding can be done with the struct +LodePNGState and lodepng_decode. For C++, all decoding can be done with the +various lodepng::decode functions, and lodepng::State can be used for advanced +features. + +When using the LodePNGState, it uses the following fields for decoding: +*) LodePNGInfo info_png: it stores extra information about the PNG (the input) in here +*) LodePNGColorMode info_raw: here you can say what color mode of the raw image (the output) you want to get +*) LodePNGDecoderSettings decoder: you can specify a few extra settings for the decoder to use + +LodePNGInfo info_png +-------------------- + +After decoding, this contains extra information of the PNG image, except the actual +pixels, width and height because these are already gotten directly from the decoder +functions. + +It contains for example the original color type of the PNG image, text comments, +suggested background color, etc... More details about the LodePNGInfo struct are +at its declaration documentation. + +LodePNGColorMode info_raw +------------------------- + +When decoding, here you can specify which color type you want +the resulting raw image to be. If this is different from the colortype of the +PNG, then the decoder will automatically convert the result. This conversion +always works, except if you want it to convert a color PNG to grayscale or to +a palette with missing colors. + +By default, 32-bit color is used for the result. + +LodePNGDecoderSettings decoder +------------------------------ + +The settings can be used to ignore the errors created by invalid CRC and Adler32 +chunks, and to disable the decoding of tEXt chunks. + +There's also a setting color_convert, true by default. If false, no conversion +is done, the resulting data will be as it was in the PNG (after decompression) +and you'll have to puzzle the colors of the pixels together yourself using the +color type information in the LodePNGInfo. + + +5. Encoding +----------- + +Encoding converts a raw pixel buffer to a PNG compressed image. + +Most documentation on using the encoder is at its declarations in the header +above. For C, simple encoding can be done with functions such as +lodepng_encode32, and more advanced decoding can be done with the struct +LodePNGState and lodepng_encode. For C++, all encoding can be done with the +various lodepng::encode functions, and lodepng::State can be used for advanced +features. + +Like the decoder, the encoder can also give errors. However it gives less errors +since the encoder input is trusted, the decoder input (a PNG image that could +be forged by anyone) is not trusted. + +When using the LodePNGState, it uses the following fields for encoding: +*) LodePNGInfo info_png: here you specify how you want the PNG (the output) to be. +*) LodePNGColorMode info_raw: here you say what color type of the raw image (the input) has +*) LodePNGEncoderSettings encoder: you can specify a few settings for the encoder to use + +LodePNGInfo info_png +-------------------- + +When encoding, you use this the opposite way as when decoding: for encoding, +you fill in the values you want the PNG to have before encoding. By default it's +not needed to specify a color type for the PNG since it's automatically chosen, +but it's possible to choose it yourself given the right settings. + +The encoder will not always exactly match the LodePNGInfo struct you give, +it tries as close as possible. Some things are ignored by the encoder. The +encoder uses, for example, the following settings from it when applicable: +colortype and bitdepth, text chunks, time chunk, the color key, the palette, the +background color, the interlace method, unknown chunks, ... + +When encoding to a PNG with colortype 3, the encoder will generate a PLTE chunk. +If the palette contains any colors for which the alpha channel is not 255 (so +there are translucent colors in the palette), it'll add a tRNS chunk. + +LodePNGColorMode info_raw +------------------------- + +You specify the color type of the raw image that you give to the input here, +including a possible transparent color key and palette you happen to be using in +your raw image data. + +By default, 32-bit color is assumed, meaning your input has to be in RGBA +format with 4 bytes (unsigned chars) per pixel. + +LodePNGEncoderSettings encoder +------------------------------ + +The following settings are supported (some are in sub-structs): +*) auto_convert: when this option is enabled, the encoder will +automatically choose the smallest possible color mode (including color key) that +can encode the colors of all pixels without information loss. +*) btype: the block type for LZ77. 0 = uncompressed, 1 = fixed huffman tree, + 2 = dynamic huffman tree (best compression). Should be 2 for proper + compression. +*) use_lz77: whether or not to use LZ77 for compressed block types. Should be + true for proper compression. +*) windowsize: the window size used by the LZ77 encoder (1 - 32768). Has value + 2048 by default, but can be set to 32768 for better, but slow, compression. +*) force_palette: if colortype is 2 or 6, you can make the encoder write a PLTE + chunk if force_palette is true. This can used as suggested palette to convert + to by viewers that don't support more than 256 colors (if those still exist) +*) add_id: add text chunk "Encoder: LodePNG " to the image. +*) text_compression: default 1. If 1, it'll store texts as zTXt instead of tEXt chunks. + zTXt chunks use zlib compression on the text. This gives a smaller result on + large texts but a larger result on small texts (such as a single program name). + It's all tEXt or all zTXt though, there's no separate setting per text yet. + + +6. color conversions +-------------------- + +An important thing to note about LodePNG, is that the color type of the PNG, and +the color type of the raw image, are completely independent. By default, when +you decode a PNG, you get the result as a raw image in the color type you want, +no matter whether the PNG was encoded with a palette, grayscale or RGBA color. +And if you encode an image, by default LodePNG will automatically choose the PNG +color type that gives good compression based on the values of colors and amount +of colors in the image. It can be configured to let you control it instead as +well, though. + +To be able to do this, LodePNG does conversions from one color mode to another. +It can convert from almost any color type to any other color type, except the +following conversions: RGB to grayscale is not supported, and converting to a +palette when the palette doesn't have a required color is not supported. This is +not supported on purpose: this is information loss which requires a color +reduction algorithm that is beyond the scope of a PNG encoder (yes, RGB to gray +is easy, but there are multiple ways if you want to give some channels more +weight). + +By default, when decoding, you get the raw image in 32-bit RGBA or 24-bit RGB +color, no matter what color type the PNG has. And by default when encoding, +LodePNG automatically picks the best color model for the output PNG, and expects +the input image to be 32-bit RGBA or 24-bit RGB. So, unless you want to control +the color format of the images yourself, you can skip this chapter. + +6.1. PNG color types +-------------------- + +A PNG image can have many color types, ranging from 1-bit color to 64-bit color, +as well as palettized color modes. After the zlib decompression and unfiltering +in the PNG image is done, the raw pixel data will have that color type and thus +a certain amount of bits per pixel. If you want the output raw image after +decoding to have another color type, a conversion is done by LodePNG. + +The PNG specification gives the following color types: + +0: grayscale, bit depths 1, 2, 4, 8, 16 +2: RGB, bit depths 8 and 16 +3: palette, bit depths 1, 2, 4 and 8 +4: grayscale with alpha, bit depths 8 and 16 +6: RGBA, bit depths 8 and 16 + +Bit depth is the amount of bits per pixel per color channel. So the total amount +of bits per pixel is: amount of channels * bitdepth. + +6.2. color conversions +---------------------- + +As explained in the sections about the encoder and decoder, you can specify +color types and bit depths in info_png and info_raw to change the default +behaviour. + +If, when decoding, you want the raw image to be something else than the default, +you need to set the color type and bit depth you want in the LodePNGColorMode, +or the parameters colortype and bitdepth of the simple decoding function. + +If, when encoding, you use another color type than the default in the raw input +image, you need to specify its color type and bit depth in the LodePNGColorMode +of the raw image, or use the parameters colortype and bitdepth of the simple +encoding function. + +If, when encoding, you don't want LodePNG to choose the output PNG color type +but control it yourself, you need to set auto_convert in the encoder settings +to false, and specify the color type you want in the LodePNGInfo of the +encoder (including palette: it can generate a palette if auto_convert is true, +otherwise not). + +If the input and output color type differ (whether user chosen or auto chosen), +LodePNG will do a color conversion, which follows the rules below, and may +sometimes result in an error. + +To avoid some confusion: +-the decoder converts from PNG to raw image +-the encoder converts from raw image to PNG +-the colortype and bitdepth in LodePNGColorMode info_raw, are those of the raw image +-the colortype and bitdepth in the color field of LodePNGInfo info_png, are those of the PNG +-when encoding, the color type in LodePNGInfo is ignored if auto_convert + is enabled, it is automatically generated instead +-when decoding, the color type in LodePNGInfo is set by the decoder to that of the original + PNG image, but it can be ignored since the raw image has the color type you requested instead +-if the color type of the LodePNGColorMode and PNG image aren't the same, a conversion + between the color types is done if the color types are supported. If it is not + supported, an error is returned. If the types are the same, no conversion is done. +-even though some conversions aren't supported, LodePNG supports loading PNGs from any + colortype and saving PNGs to any colortype, sometimes it just requires preparing + the raw image correctly before encoding. +-both encoder and decoder use the same color converter. + +The function lodepng_convert does the color conversion. It is available in the +interface but normally isn't needed since the encoder and decoder already call +it. + +Non supported color conversions: +-color to grayscale when non-gray pixels are present: no error is thrown, but +the result will look ugly because only the red channel is taken (it assumes all +three channels are the same in this case so ignores green and blue). The reason +no error is given is to allow converting from three-channel grayscale images to +one-channel even if there are numerical imprecisions. +-anything to palette when the palette does not have an exact match for a from-color +in it: in this case an error is thrown + +Supported color conversions: +-anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA +-any gray or gray+alpha, to gray or gray+alpha +-anything to a palette, as long as the palette has the requested colors in it +-removing alpha channel +-higher to smaller bitdepth, and vice versa + +If you want no color conversion to be done (e.g. for speed or control): +-In the encoder, you can make it save a PNG with any color type by giving the +raw color mode and LodePNGInfo the same color mode, and setting auto_convert to +false. +-In the decoder, you can make it store the pixel data in the same color type +as the PNG has, by setting the color_convert setting to false. Settings in +info_raw are then ignored. + +6.3. padding bits +----------------- + +In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines +have a bit amount that isn't a multiple of 8, then padding bits are used so that each +scanline starts at a fresh byte. But that is NOT true for the LodePNG raw input and output. +The raw input image you give to the encoder, and the raw output image you get from the decoder +will NOT have these padding bits, e.g. in the case of a 1-bit image with a width +of 7 pixels, the first pixel of the second scanline will the 8th bit of the first byte, +not the first bit of a new byte. + +6.4. A note about 16-bits per channel and endianness +---------------------------------------------------- + +LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like +for any other color format. The 16-bit values are stored in big endian (most +significant byte first) in these arrays. This is the opposite order of the +little endian used by x86 CPU's. + +LodePNG always uses big endian because the PNG file format does so internally. +Conversions to other formats than PNG uses internally are not supported by +LodePNG on purpose, there are myriads of formats, including endianness of 16-bit +colors, the order in which you store R, G, B and A, and so on. Supporting and +converting to/from all that is outside the scope of LodePNG. + +This may mean that, depending on your use case, you may want to convert the big +endian output of LodePNG to little endian with a for loop. This is certainly not +always needed, many applications and libraries support big endian 16-bit colors +anyway, but it means you cannot simply cast the unsigned char* buffer to an +unsigned short* buffer on x86 CPUs. + + +7. error values +--------------- + +All functions in LodePNG that return an error code, return 0 if everything went +OK, or a non-zero code if there was an error. + +The meaning of the LodePNG error values can be retrieved with the function +lodepng_error_text: given the numerical error code, it returns a description +of the error in English as a string. + +Check the implementation of lodepng_error_text to see the meaning of each code. + + +8. chunks and PNG editing +------------------------- + +If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG +editor that should follow the rules about handling of unknown chunks, or if your +program is able to read other types of chunks than the ones handled by LodePNG, +then that's possible with the chunk functions of LodePNG. + +A PNG chunk has the following layout: + +4 bytes length +4 bytes type name +length bytes data +4 bytes CRC + +8.1. iterating through chunks +----------------------------- + +If you have a buffer containing the PNG image data, then the first chunk (the +IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the +signature of the PNG and are not part of a chunk. But if you start at byte 8 +then you have a chunk, and can check the following things of it. + +NOTE: none of these functions check for memory buffer boundaries. To avoid +exploits, always make sure the buffer contains all the data of the chunks. +When using lodepng_chunk_next, make sure the returned value is within the +allocated memory. + +unsigned lodepng_chunk_length(const unsigned char* chunk): + +Get the length of the chunk's data. The total chunk length is this length + 12. + +void lodepng_chunk_type(char type[5], const unsigned char* chunk): +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type): + +Get the type of the chunk or compare if it's a certain type + +unsigned char lodepng_chunk_critical(const unsigned char* chunk): +unsigned char lodepng_chunk_private(const unsigned char* chunk): +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk): + +Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are). +Check if the chunk is private (public chunks are part of the standard, private ones not). +Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical +chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your +program doesn't handle that type of unknown chunk. + +unsigned char* lodepng_chunk_data(unsigned char* chunk): +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk): + +Get a pointer to the start of the data of the chunk. + +unsigned lodepng_chunk_check_crc(const unsigned char* chunk): +void lodepng_chunk_generate_crc(unsigned char* chunk): + +Check if the crc is correct or generate a correct one. + +unsigned char* lodepng_chunk_next(unsigned char* chunk): +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk): + +Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these +functions do no boundary checking of the allocated data whatsoever, so make sure there is enough +data available in the buffer to be able to go to the next chunk. + +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk): +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, + const char* type, const unsigned char* data): + +These functions are used to create new chunks that are appended to the data in *out that has +length *outsize. The append function appends an existing chunk to the new data. The create +function creates a new chunk with the given parameters and appends it. Type is the 4-letter +name of the chunk. + +8.2. chunks in info_png +----------------------- + +The LodePNGInfo struct contains fields with the unknown chunk in it. It has 3 +buffers (each with size) to contain 3 types of unknown chunks: +the ones that come before the PLTE chunk, the ones that come between the PLTE +and the IDAT chunks, and the ones that come after the IDAT chunks. +It's necessary to make the distinction between these 3 cases because the PNG +standard forces to keep the ordering of unknown chunks compared to the critical +chunks, but does not force any other ordering rules. + +info_png.unknown_chunks_data[0] is the chunks before PLTE +info_png.unknown_chunks_data[1] is the chunks after PLTE, before IDAT +info_png.unknown_chunks_data[2] is the chunks after IDAT + +The chunks in these 3 buffers can be iterated through and read by using the same +way described in the previous subchapter. + +When using the decoder to decode a PNG, you can make it store all unknown chunks +if you set the option settings.remember_unknown_chunks to 1. By default, this +option is off (0). + +The encoder will always encode unknown chunks that are stored in the info_png. +If you need it to add a particular chunk that isn't known by LodePNG, you can +use lodepng_chunk_append or lodepng_chunk_create to the chunk data in +info_png.unknown_chunks_data[x]. + +Chunks that are known by LodePNG should not be added in that way. E.g. to make +LodePNG add a bKGD chunk, set background_defined to true and add the correct +parameters there instead. + + +9. compiler support +------------------- + +No libraries other than the current standard C library are needed to compile +LodePNG. For the C++ version, only the standard C++ library is needed on top. +Add the files lodepng.c(pp) and lodepng.h to your project, include +lodepng.h where needed, and your program can read/write PNG files. + +It is compatible with C90 and up, and C++03 and up. + +If performance is important, use optimization when compiling! For both the +encoder and decoder, this makes a large difference. + +Make sure that LodePNG is compiled with the same compiler of the same version +and with the same settings as the rest of the program, or the interfaces with +std::vectors and std::strings in C++ can be incompatible. + +CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets. + +*) gcc and g++ + +LodePNG is developed in gcc so this compiler is natively supported. It gives no +warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++ +version 4.7.1 on Linux, 32-bit and 64-bit. + +*) Clang + +Fully supported and warning-free. + +*) Mingw + +The Mingw compiler (a port of gcc for Windows) should be fully supported by +LodePNG. + +*) Visual Studio and Visual C++ Express Edition + +LodePNG should be warning-free with warning level W4. Two warnings were disabled +with pragmas though: warning 4244 about implicit conversions, and warning 4996 +where it wants to use a non-standard function fopen_s instead of the standard C +fopen. + +Visual Studio may want "stdafx.h" files to be included in each source file and +give an error "unexpected end of file while looking for precompiled header". +This is not standard C++ and will not be added to the stock LodePNG. You can +disable it for lodepng.cpp only by right clicking it, Properties, C/C++, +Precompiled Headers, and set it to Not Using Precompiled Headers there. + +NOTE: Modern versions of VS should be fully supported, but old versions, e.g. +VS6, are not guaranteed to work. + +*) Compilers on Macintosh + +LodePNG has been reported to work both with gcc and LLVM for Macintosh, both for +C and C++. + +*) Other Compilers + +If you encounter problems on any compilers, feel free to let me know and I may +try to fix it if the compiler is modern and standards compliant. + + +10. examples +------------ + +This decoder example shows the most basic usage of LodePNG. More complex +examples can be found on the LodePNG website. + +10.1. decoder C++ example +------------------------- + +#include "lodepng.h" +#include + +int main(int argc, char *argv[]) { + const char* filename = argc > 1 ? argv[1] : "test.png"; + + //load and decode + std::vector image; + unsigned width, height; + unsigned error = lodepng::decode(image, width, height, filename); + + //if there's an error, display it + if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; + + //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... +} + +10.2. decoder C example +----------------------- + +#include "lodepng.h" + +int main(int argc, char *argv[]) { + unsigned error; + unsigned char* image; + size_t width, height; + const char* filename = argc > 1 ? argv[1] : "test.png"; + + error = lodepng_decode32_file(&image, &width, &height, filename); + + if(error) printf("decoder error %u: %s\n", error, lodepng_error_text(error)); + + / * use image here * / + + free(image); + return 0; +} + +11. state settings reference +---------------------------- + +A quick reference of some settings to set on the LodePNGState + +For decoding: + +state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums +state.decoder.zlibsettings.custom_...: use custom inflate function +state.decoder.ignore_crc: ignore CRC checksums +state.decoder.ignore_critical: ignore unknown critical chunks +state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors +state.decoder.color_convert: convert internal PNG color to chosen one +state.decoder.read_text_chunks: whether to read in text metadata chunks +state.decoder.remember_unknown_chunks: whether to read in unknown chunks +state.info_raw.colortype: desired color type for decoded image +state.info_raw.bitdepth: desired bit depth for decoded image +state.info_raw....: more color settings, see struct LodePNGColorMode +state.info_png....: no settings for decoder but output, see struct LodePNGInfo + +For encoding: + +state.encoder.zlibsettings.btype: disable compression by setting it to 0 +state.encoder.zlibsettings.use_lz77: use LZ77 in compression +state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize +state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match +state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching +state.encoder.zlibsettings.lazymatching: try one more LZ77 matching +state.encoder.zlibsettings.custom_...: use custom deflate function +state.encoder.auto_convert: choose optimal PNG color type, if 0 uses info_png +state.encoder.filter_palette_zero: PNG filter strategy for palette +state.encoder.filter_strategy: PNG filter strategy to encode with +state.encoder.force_palette: add palette even if not encoding to one +state.encoder.add_id: add LodePNG identifier and version as a text chunk +state.encoder.text_compression: use compressed text chunks for metadata +state.info_raw.colortype: color type of raw input image you provide +state.info_raw.bitdepth: bit depth of raw input image you provide +state.info_raw: more color settings, see struct LodePNGColorMode +state.info_png.color.colortype: desired color type if auto_convert is false +state.info_png.color.bitdepth: desired bit depth if auto_convert is false +state.info_png.color....: more color settings, see struct LodePNGColorMode +state.info_png....: more PNG related settings, see struct LodePNGInfo + + +12. changes +----------- + +The version number of LodePNG is the date of the change given in the format +yyyymmdd. + +Some changes aren't backwards compatible. Those are indicated with a (!) +symbol. + +Not all changes are listed here, the commit history in github lists more: +https://github.com/lvandeve/lodepng + +*) 06 mar 2020: simplified some of the dynamic memory allocations. +*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct + overflow checks. +*) 14 aug 2019: around 25% faster decoding thanks to huffman lookup tables. +*) 15 jun 2019: (!) auto_choose_color API changed (for bugfix: don't use palette + if gray ICC profile) and non-ICC LodePNGColorProfile renamed to + LodePNGColorStats. +*) 30 dec 2018: code style changes only: removed newlines before opening braces. +*) 10 sep 2018: added way to inspect metadata chunks without full decoding. +*) 19 aug 2018: (!) fixed color mode bKGD is encoded with and made it use + palette index in case of palette. +*) 10 aug 2018: (!) added support for gAMA, cHRM, sRGB and iCCP chunks. This + change is backwards compatible unless you relied on unknown_chunks for those. +*) 11 jun 2018: less restrictive check for pixel size integer overflow +*) 14 jan 2018: allow optionally ignoring a few more recoverable errors +*) 17 sep 2017: fix memory leak for some encoder input error cases +*) 27 nov 2016: grey+alpha auto color model detection bugfix +*) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort). +*) 09 apr 2016: Fixed colorkey usage detection, and better file loading (within + the limits of pure C90). +*) 08 dec 2015: Made load_file function return error if file can't be opened. +*) 24 okt 2015: Bugfix with decoding to palette output. +*) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding. +*) 24 aug 2014: Moved to github +*) 23 aug 2014: Reduced needless memory usage of decoder. +*) 28 jun 2014: Removed fix_png setting, always support palette OOB for + simplicity. Made ColorProfile public. +*) 09 jun 2014: Faster encoder by fixing hash bug and more zeros optimization. +*) 22 dec 2013: Power of two windowsize required for optimization. +*) 15 apr 2013: Fixed bug with LAC_ALPHA and color key. +*) 25 mar 2013: Added an optional feature to ignore some PNG errors (fix_png). +*) 11 mar 2013: (!) Bugfix with custom free. Changed from "my" to "lodepng_" + prefix for the custom allocators and made it possible with a new #define to + use custom ones in your project without needing to change lodepng's code. +*) 28 jan 2013: Bugfix with color key. +*) 27 okt 2012: Tweaks in text chunk keyword length error handling. +*) 8 okt 2012: (!) Added new filter strategy (entropy) and new auto color mode. + (no palette). Better deflate tree encoding. New compression tweak settings. + Faster color conversions while decoding. Some internal cleanups. +*) 23 sep 2012: Reduced warnings in Visual Studio a little bit. +*) 1 sep 2012: (!) Removed #define's for giving custom (de)compression functions + and made it work with function pointers instead. +*) 23 jun 2012: Added more filter strategies. Made it easier to use custom alloc + and free functions and toggle #defines from compiler flags. Small fixes. +*) 6 may 2012: (!) Made plugging in custom zlib/deflate functions more flexible. +*) 22 apr 2012: (!) Made interface more consistent, renaming a lot. Removed + redundant C++ codec classes. Reduced amount of structs. Everything changed, + but it is cleaner now imho and functionality remains the same. Also fixed + several bugs and shrunk the implementation code. Made new samples. +*) 6 nov 2011: (!) By default, the encoder now automatically chooses the best + PNG color model and bit depth, based on the amount and type of colors of the + raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color. +*) 9 okt 2011: simpler hash chain implementation for the encoder. +*) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching. +*) 23 aug 2011: tweaked the zlib compression parameters after benchmarking. + A bug with the PNG filtertype heuristic was fixed, so that it chooses much + better ones (it's quite significant). A setting to do an experimental, slow, + brute force search for PNG filter types is added. +*) 17 aug 2011: (!) changed some C zlib related function names. +*) 16 aug 2011: made the code less wide (max 120 characters per line). +*) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors. +*) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled. +*) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman + to optimize long sequences of zeros. +*) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and + LodePNG_InfoColor_canHaveAlpha functions for convenience. +*) 7 nov 2010: added LodePNG_error_text function to get error code description. +*) 30 okt 2010: made decoding slightly faster +*) 26 okt 2010: (!) changed some C function and struct names (more consistent). + Reorganized the documentation and the declaration order in the header. +*) 08 aug 2010: only changed some comments and external samples. +*) 05 jul 2010: fixed bug thanks to warnings in the new gcc version. +*) 14 mar 2010: fixed bug where too much memory was allocated for char buffers. +*) 02 sep 2008: fixed bug where it could create empty tree that linux apps could + read by ignoring the problem but windows apps couldn't. +*) 06 jun 2008: added more error checks for out of memory cases. +*) 26 apr 2008: added a few more checks here and there to ensure more safety. +*) 06 mar 2008: crash with encoding of strings fixed +*) 02 feb 2008: support for international text chunks added (iTXt) +*) 23 jan 2008: small cleanups, and #defines to divide code in sections +*) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor. +*) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder. +*) 17 jan 2008: ability to encode and decode compressed zTXt chunks added + Also various fixes, such as in the deflate and the padding bits code. +*) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved + filtering code of encoder. +*) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A + C++ wrapper around this provides an interface almost identical to before. + Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code + are together in these files but it works both for C and C++ compilers. +*) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks +*) 30 aug 2007: bug fixed which makes this Borland C++ compatible +*) 09 aug 2007: some VS2005 warnings removed again +*) 21 jul 2007: deflate code placed in new namespace separate from zlib code +*) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images +*) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing + invalid std::vector element [0] fixed, and level 3 and 4 warnings removed +*) 02 jun 2007: made the encoder add a tag with version by default +*) 27 may 2007: zlib and png code separated (but still in the same file), + simple encoder/decoder functions added for more simple usage cases +*) 19 may 2007: minor fixes, some code cleaning, new error added (error 69), + moved some examples from here to lodepng_examples.cpp +*) 12 may 2007: palette decoding bug fixed +*) 24 apr 2007: changed the license from BSD to the zlib license +*) 11 mar 2007: very simple addition: ability to encode bKGD chunks. +*) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding + palettized PNG images. Plus little interface change with palette and texts. +*) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes. + Fixed a bug where the end code of a block had length 0 in the Huffman tree. +*) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented + and supported by the encoder, resulting in smaller PNGs at the output. +*) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone. +*) 24 jan 2007: gave encoder an error interface. Added color conversion from any + greyscale type to 8-bit greyscale with or without alpha. +*) 21 jan 2007: (!) Totally changed the interface. It allows more color types + to convert to and is more uniform. See the manual for how it works now. +*) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days: + encode/decode custom tEXt chunks, separate classes for zlib & deflate, and + at last made the decoder give errors for incorrect Adler32 or Crc. +*) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel. +*) 29 dec 2006: Added support for encoding images without alpha channel, and + cleaned out code as well as making certain parts faster. +*) 28 dec 2006: Added "Settings" to the encoder. +*) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now. + Removed some code duplication in the decoder. Fixed little bug in an example. +*) 09 dec 2006: (!) Placed output parameters of public functions as first parameter. + Fixed a bug of the decoder with 16-bit per color. +*) 15 okt 2006: Changed documentation structure +*) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the + given image buffer, however for now it's not compressed. +*) 08 sep 2006: (!) Changed to interface with a Decoder class +*) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different + way. Renamed decodePNG to decodePNGGeneric. +*) 29 jul 2006: (!) Changed the interface: image info is now returned as a + struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy. +*) 28 jul 2006: Cleaned the code and added new error checks. + Corrected terminology "deflate" into "inflate". +*) 23 jun 2006: Added SDL example in the documentation in the header, this + example allows easy debugging by displaying the PNG and its transparency. +*) 22 jun 2006: (!) Changed way to obtain error value. Added + loadFile function for convenience. Made decodePNG32 faster. +*) 21 jun 2006: (!) Changed type of info vector to unsigned. + Changed position of palette in info vector. Fixed an important bug that + happened on PNGs with an uncompressed block. +*) 16 jun 2006: Internally changed unsigned into unsigned where + needed, and performed some optimizations. +*) 07 jun 2006: (!) Renamed functions to decodePNG and placed them + in LodePNG namespace. Changed the order of the parameters. Rewrote the + documentation in the header. Renamed files to lodepng.cpp and lodepng.h +*) 22 apr 2006: Optimized and improved some code +*) 07 sep 2005: (!) Changed to std::vector interface +*) 12 aug 2005: Initial release (C++, decoder only) + + +13. contact information +----------------------- + +Feel free to contact me with suggestions, problems, comments, ... concerning +LodePNG. If you encounter a PNG image that doesn't work properly with this +decoder, feel free to send it and I'll use it to find and fix the problem. + +My email address is (puzzle the account and domain together with an @ symbol): +Domain: gmail dot com. +Account: lode dot vandevenne. + + +Copyright (c) 2005-2020 Lode Vandevenne +*/ diff --git a/components/thorvg-main/tools/svg2png/meson.build b/components/thorvg-main/tools/svg2png/meson.build new file mode 100644 index 0000000..9395bfa --- /dev/null +++ b/components/thorvg-main/tools/svg2png/meson.build @@ -0,0 +1,8 @@ +svg2png_src = files('svg2png.cpp', 'lodepng.cpp') + +executable('tvg-svg2png', + svg2png_src, + include_directories : headers, + cpp_args : compiler_flags, + install : true, + link_with : thorvg_lib) diff --git a/components/thorvg-main/tools/svg2png/svg2png.cpp b/components/thorvg-main/tools/svg2png/svg2png.cpp new file mode 100644 index 0000000..b24b861 --- /dev/null +++ b/components/thorvg-main/tools/svg2png/svg2png.cpp @@ -0,0 +1,413 @@ +/* + * Copyright (c) 2020 - 2026 ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include + #ifndef PATH_MAX + #define PATH_MAX MAX_PATH + #endif +#else + #include + #include + #include + #include +#endif +#include "lodepng.h" + +#define WIDTH_8K 7680 +#define HEIGHT_8K 4320 +#define SIZE_8K 33177600 //WIDTH_8K x HEIGHT_8K + +using namespace std; + +struct PngBuilder +{ + void build(const string& fileName, const uint32_t width, const uint32_t height, uint32_t* buffer) + { + //Used ARGB8888 so have to move pixels now + vector image; + image.resize(width * height * 4); + for (unsigned y = 0; y < height; y++) { + for (unsigned x = 0; x < width; x++) { + uint32_t n = buffer[y * width + x]; + image[4 * width * y + 4 * x + 0] = (n >> 16) & 0xff; + image[4 * width * y + 4 * x + 1] = (n >> 8) & 0xff; + image[4 * width * y + 4 * x + 2] = n & 0xff; + image[4 * width * y + 4 * x + 3] = (n >> 24) & 0xff; + } + } + + unsigned error = lodepng::encode(fileName, image, width, height); + + //if there's an error, display it + if (error) cout << "encoder error " << error << ": " << lodepng_error_text(error) << endl; + } +}; + +struct Renderer +{ +public: + int render(const char* path, int w, int h, const string& dst, uint32_t bgColor) + { + //Canvas + if (!canvas) createCanvas(); + if (!canvas) { + cout << "Error: Canvas failure" << endl; + return 1; + } + + //Picture + auto picture = tvg::Picture::gen(); + tvg::Result result = picture->load(path); + if (result == tvg::Result::Unknown) { + cout << "Error: Couldn't load image " << path << endl; + return 1; + } else if (result == tvg::Result::InvalidArguments) { + cout << "Error: Couldn't load image(Invalid path or invalid SVG image) : " << path << endl; + return 1; + } else if (result == tvg::Result::NonSupport) { + cout << "Error: Couldn't load image(Not supported extension) : " << path << endl; + return 1; + } + + if (w == 0 || h == 0) { + float fw, fh; + picture->size(&fw, &fh); + w = static_cast(fw); + h = static_cast(fh); + if (fw > w) w++; + if (fh > h) h++; + + if (w * h > SIZE_8K) { + float scale = fw / fh; + if (scale > 1) { + w = WIDTH_8K; + h = static_cast(w / scale); + } else { + h = HEIGHT_8K; + w = static_cast(h * scale); + } + cout << "Warning: The SVG width and/or height values exceed the 8k resolution. " + "To avoid the heap overflow, the conversion to the PNG file made in " << w << " x " << h << " resolution." << endl; + picture->size(static_cast(w), static_cast(h)); + } + } else { + picture->size(static_cast(w), static_cast(h)); + } + + //Buffer + createBuffer(w, h); + if (!buffer) { + cout << "Error: Buffer failure" << endl; + return 1; + } + + if (canvas->target(buffer, w, w, h, tvg::ColorSpace::ARGB8888S) != tvg::Result::Success) { + cout << "Error: Canvas target failure" << endl; + return 1; + } + + //Background color if needed + if (bgColor != 0xffffffff) { + uint8_t r = (uint8_t)((bgColor & 0xff0000) >> 16); + uint8_t g = (uint8_t)((bgColor & 0x00ff00) >> 8); + uint8_t b = (uint8_t)((bgColor & 0x0000ff)); + + auto shape = tvg::Shape::gen(); + shape->appendRect(0, 0, static_cast(w), static_cast(h), 0, 0); + shape->fill(r, g, b); + + if (canvas->add(shape) != tvg::Result::Success) return 1; + } + + //Drawing + canvas->add(picture); + canvas->draw(true); + canvas->sync(); + + //Build Png + PngBuilder builder; + builder.build(dst, w, h, buffer); + + cout << "Generated PNG file: " << dst << endl; + + return 0; + } + + void terminate() + { + tvg::Initializer::term(); + free(buffer); + } + +private: + void createCanvas() + { + //Threads Count + auto threads = thread::hardware_concurrency(); + if (threads > 0) --threads; + + //Initialize ThorVG Engine + if (tvg::Initializer::init(threads) != tvg::Result::Success) { + cout << "Error: Engine is not supported" << endl; + } + + //Create a Canvas + canvas = unique_ptr(tvg::SwCanvas::gen()); + } + + void createBuffer(int w, int h) + { + uint32_t size = w * h; + //Reuse old buffer if size is enough + if (buffer && bufferSize >= size) return; + + //Alloc or realloc buffer + buffer = (uint32_t*) realloc(buffer, sizeof(uint32_t) * size); + bufferSize = size; + } + +private: + unique_ptr canvas = nullptr; + uint32_t* buffer = nullptr; + uint32_t bufferSize = 0; +}; + +struct App +{ +public: + int setup(int argc, char** argv) + { + vector paths; + + for (int i = 1; i < argc; i++) { + const char* p = argv[i]; + if (*p == '-') { + //flags + const char* p_arg = (i + 1 < argc) ? argv[++i] : nullptr; + if (p[1] == 'r') { + //image resolution + if (!p_arg) { + cout << "Error: Missing resolution attribute. Expected eg. -r 200x200." << endl; + return 1; + } + + const char* x = strchr(p_arg, 'x'); + if (x) { + width = atoi(p_arg); + height = atoi(x + 1); + } + if (!x || width <= 0 || height <= 0) { + cout << "Error: Resolution (" << p_arg << ") is corrupted. Expected eg. -r 200x200." << endl; + return 1; + } + + } else if (p[1] == 'b') { + //image background color + if (!p_arg) { + cout << "Error: Missing background color attribute. Expected eg. -b fa7410." << endl; + return 1; + } + + bgColor = (uint32_t) strtol(p_arg, NULL, 16); + + } else { + cout << "Warning: Unknown flag (" << p << ")." << endl; + } + } else { + //arguments + paths.push_back(p); + } + } + + int ret = 0; + if (paths.empty()) { + //no attributes - print help + return help(); + + } else { + for (auto path : paths) { + auto real_path = realFile(path); + if (real_path) { + if (isDirectory(real_path)) { + //load from directory + cout << "Trying load from directory \"" << real_path << "\"." << endl; + if ((ret = handleDirectory(real_path))) break; + + } else if (svgFile(path)) { + //load single file + if ((ret = renderFile(real_path))) break; + } else { + //not a directory and not .svg file + cout << "Error: File \"" << path << "\" is not a proper svg file." << endl; + } + + } else { + cout << "Error: Invalid file or path name: \"" << path << "\"" << endl; + } + } + } + + //Terminate renderer + renderer.terminate(); + + return ret; + } + +private: + Renderer renderer; + uint32_t bgColor = 0xffffffff; + uint32_t width = 0; + uint32_t height = 0; + char full[PATH_MAX]; + +private: + int help() + { + cout << "Usage:\n tvg-svg2png [SVG file] or [SVG folder] [-r resolution] [-b bgColor]\n\nFlags:\n -r set the output image resolution.\n -b set the output image background color.\n\nExamples:\n $ tvg-svg2png input.svg\n $ tvg-svg2png input.svg -r 200x200\n $ tvg-svg2png input.svg -r 200x200 -b ff00ff\n $ tvg-svg2png input1.svg input2.svg -r 200x200 -b ff00ff\n $ tvg-svg2png . -r 200x200\n\nNote:\n In the case, where the width and height in the SVG file determine the size of the image in resolution higher than 8k (7680 x 4320), limiting the resolution to this value is enforced.\n\n"; + return 1; + } + + bool svgFile(const char* path) + { + size_t length = strlen(path); + return length > 4 && (strcmp(&path[length - 4], ".svg") == 0); + } + + const char* realFile(const char* path) + { + //real path +#ifdef _WIN32 + path = _fullpath(full, path, PATH_MAX); +#else + path = realpath(path, full); +#endif + return path; + } + + bool isDirectory(const char* path) + { +#ifdef _WIN32 + DWORD attr = GetFileAttributes(path); + if (attr == INVALID_FILE_ATTRIBUTES) + return false; + + return attr & FILE_ATTRIBUTE_DIRECTORY; +#else + struct stat buf; + + if (stat(path, &buf) != 0) { + return false; + } + + return S_ISDIR(buf.st_mode); +#endif + } + + int renderFile(const char* path) + { + if (!path) return 1; + + //destination png file + const char* dot = strrchr(path, '.'); + if (!dot) return 1; + string dst(path, dot - path); + dst += ".png"; + + return renderer.render(path, width, height, dst, bgColor); + } + + int handleDirectory(const string& path) + { + //open directory +#ifdef _WIN32 + WIN32_FIND_DATA fd; + HANDLE h = FindFirstFileEx((path + "\\*").c_str(), FindExInfoBasic, &fd, FindExSearchNameMatch, NULL, 0); + if (h == INVALID_HANDLE_VALUE) { + cout << "Couldn't open directory \"" << path.c_str() << "\"." << endl; + return 1; + } + int ret = 0; + do { + if (*fd.cFileName == '.' || *fd.cFileName == '$') continue; + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + string subpath = string(path); + subpath += '\\'; + subpath += fd.cFileName; + ret = handleDirectory(subpath); + if (ret) break; + + } else { + if (!svgFile(fd.cFileName)) continue; + string fullpath = string(path); + fullpath += '\\'; + fullpath += fd.cFileName; + ret = renderFile(fullpath.c_str()); + if (ret) break; + } + } while (FindNextFile(h, &fd)); + + FindClose(h); +#else + DIR* dir = opendir(path.c_str()); + if (!dir) { + cout << "Couldn't open directory \"" << path.c_str() << "\"." << endl; + return 1; + } + + //list directory + int ret = 0; + struct dirent* entry; + while ((entry = readdir(dir)) != NULL) { + if (*entry->d_name == '.' || *entry->d_name == '$') continue; + if (entry->d_type == DT_DIR) { + string subpath = string(path); + subpath += '/'; + subpath += entry->d_name; + ret = handleDirectory(subpath); + if (ret) break; + + } else { + if (!svgFile(entry->d_name)) continue; + string fullpath = string(path); + fullpath += '/'; + fullpath += entry->d_name; + ret = renderFile(fullpath.c_str()); + if (ret) break; + } + } + closedir(dir); +#endif + return ret; + } +}; + +int main(int argc, char** argv) +{ + App app; + return app.setup(argc, argv); +} diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3dc7b52..8f2dd8f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,6 +1,7 @@ idf_component_register( - SRCS "example_qspi_with_ram.c" "splash_screen.c" "animated_eyes.c" "animated_eyes_demo.c" - INCLUDE_DIRS ".") + SRCS "blink_animation.c" "lottie_player.c" "example_qspi_with_ram.c" "splash_screen.c" "animated_eyes.c" "animated_eyes_demo.c" "shake_detector.cpp" + INCLUDE_DIRS "." + REQUIRES SensorLib json) set_source_files_properties( ${LV_DEMOS_SOURCES} diff --git a/main/animated_eyes.c b/main/animated_eyes.c index 110f502..123b3fa 100644 --- a/main/animated_eyes.c +++ b/main/animated_eyes.c @@ -5,12 +5,12 @@ */ #include "animated_eyes.h" -#include "esp_timer.h" +#include "esp_heap_caps.h" #include "esp_log.h" +#include "esp_timer.h" +#include #include #include -#include -#include "esp_heap_caps.h" static const char *TAG = "animated_eyes"; @@ -19,64 +19,74 @@ static const char *TAG = "animated_eyes"; // Get current time in milliseconds static inline uint32_t get_millis(void) { - return (uint32_t)(esp_timer_get_time() / 1000); + return (uint32_t)(esp_timer_get_time() / 1000); } // Eye configuration structure typedef struct { - int16_t offset_x, offset_y; - int16_t height, width; - float slope_top, slope_bottom; - int16_t radius_top, radius_bottom; + int16_t offset_x, offset_y; + int16_t height, width; + float slope_top, slope_bottom; + int16_t radius_top, radius_bottom; } eye_config_t; // Transformation structure typedef struct { - int16_t move_x, move_y; - float scale_x, scale_y; + int16_t move_x, move_y; + float scale_x, scale_y; } transformation_t; // Animation state typedef struct { - uint32_t start_time; - uint32_t interval; - uint32_t t0, t1, t2, t3, t4; + uint32_t start_time; + uint32_t interval; + uint32_t t0, t1, t2, t3, t4; } animation_t; // Timer structure typedef struct { - uint32_t start_time; - uint32_t interval; - bool is_active; - bool is_expired; + uint32_t start_time; + uint32_t interval; + bool is_active; + bool is_expired; } async_timer_t; // Eye state typedef struct { - eye_config_t config; - eye_config_t final_config; - eye_config_t transition_dest; - transformation_t transform_origin, transform_current, transform_dest; - eye_config_t variation_values1, variation_values2; - animation_t transition_anim, transform_anim, variation_anim1, variation_anim2, blink_anim; - int16_t center_x, center_y; - bool is_mirrored; + eye_config_t config; + eye_config_t final_config; + eye_config_t transition_dest; + transformation_t transform_origin, transform_current, transform_dest; + eye_config_t variation_values1, variation_values2; + animation_t transition_anim, transform_anim, variation_anim1, variation_anim2, + blink_anim; + int16_t center_x, center_y; + bool is_mirrored; } eye_state_t; // Main animated eyes structure struct animated_eyes_t { - lv_obj_t *canvas; - lv_color_t *canvas_buf; - animated_eyes_config_t config; - - eye_state_t left_eye, right_eye; - - animated_eyes_emotion_t current_emotion; - float emotion_weights[EMOTION_COUNT]; - - async_timer_t behavior_timer, look_timer, blink_timer; - - uint16_t center_x, center_y; + lv_obj_t *canvas; + lv_color_t *canvas_buf; + animated_eyes_config_t config; + + eye_state_t left_eye, right_eye; + + animated_eyes_emotion_t current_emotion; + float emotion_weights[EMOTION_COUNT]; + + async_timer_t behavior_timer, look_timer, blink_timer; + + // Temporary emotion state + bool is_temporary_emotion; + animated_eyes_emotion_t saved_emotion; + async_timer_t temporary_timer; + + // Inertia state + float inertia_x; + float inertia_y; + + uint16_t center_x, center_y; }; // Eye presets for different emotions @@ -101,503 +111,735 @@ static const eye_config_t PRESET_SQUINT = {-10, -3, 35, 35, 0, 0, 8, 8}; // Timer functions static void timer_start(async_timer_t *timer, uint32_t interval) { - timer->start_time = get_millis(); - timer->interval = interval; - timer->is_active = true; - timer->is_expired = false; + timer->start_time = get_millis(); + timer->interval = interval; + timer->is_active = true; + timer->is_expired = false; } static void timer_reset(async_timer_t *timer) { - timer->start_time = get_millis(); - timer->is_expired = false; + timer->start_time = get_millis(); + timer->is_expired = false; } static void timer_update(async_timer_t *timer) { - if (!timer->is_active) return; - timer->is_expired = (get_millis() - timer->start_time) >= timer->interval; + if (!timer->is_active) + return; + uint32_t now = get_millis(); + if (now - timer->start_time >= timer->interval) { + timer->is_expired = true; + } } // Animation functions -static void anim_restart(animation_t *anim) { - anim->start_time = get_millis(); -} +static void anim_restart(animation_t *anim) { anim->start_time = get_millis(); } static float anim_get_value(animation_t *anim) { - uint32_t elapsed = get_millis() - anim->start_time; - if (anim->interval == 0) return 0.0f; - uint32_t pos = elapsed % anim->interval; - - if (pos < anim->t0) return 0.0f; - pos -= anim->t0; - if (pos < anim->t1 && anim->t1 > 0) return (float)pos / anim->t1; - pos -= anim->t1; - if (pos < anim->t2) return 1.0f; - pos -= anim->t2; - if (pos < anim->t3 && anim->t3 > 0) return 1.0f - (float)pos / anim->t3; + uint32_t elapsed = get_millis() - anim->start_time; + if (anim->interval == 0) return 0.0f; + uint32_t pos = elapsed % anim->interval; + + if (pos < anim->t0) + return 0.0f; + pos -= anim->t0; + if (pos < anim->t1 && anim->t1 > 0) + return (float)pos / anim->t1; + pos -= anim->t1; + if (pos < anim->t2) + return 1.0f; + pos -= anim->t2; + if (pos < anim->t3 && anim->t3 > 0) + return 1.0f - (float)pos / anim->t3; + return 0.0f; } static uint32_t anim_get_elapsed(animation_t *anim) { - return get_millis() - anim->start_time; + return get_millis() - anim->start_time; } -static void anim_set_trapezium(animation_t *anim, uint32_t t0, uint32_t t1, uint32_t t2, uint32_t t3, uint32_t t4) { - anim->t0 = t0; anim->t1 = t1; anim->t2 = t2; anim->t3 = t3; anim->t4 = t4; - anim->interval = t0 + t1 + t2 + t3 + t4; +static void anim_set_trapezium(animation_t *anim, uint32_t t0, uint32_t t1, + uint32_t t2, uint32_t t3, uint32_t t4) { + anim->t0 = t0; + anim->t1 = t1; + anim->t2 = t2; + anim->t3 = t3; + anim->t4 = t4; + anim->interval = t0 + t1 + t2 + t3 + t4; } // Scale preset for larger screen static eye_config_t scale_preset(const eye_config_t *preset, float scale) { - eye_config_t scaled = *preset; - scaled.offset_x = (int16_t)(preset->offset_x * scale); - scaled.offset_y = (int16_t)(preset->offset_y * scale); - scaled.height = (int16_t)(preset->height * scale); - scaled.width = (int16_t)(preset->width * scale); - scaled.radius_top = (int16_t)(preset->radius_top * scale); - scaled.radius_bottom = (int16_t)(preset->radius_bottom * scale); - return scaled; + eye_config_t scaled = *preset; + scaled.offset_x = (int16_t)(preset->offset_x * scale); + scaled.offset_y = (int16_t)(preset->offset_y * scale); + scaled.height = (int16_t)(preset->height * scale); + scaled.width = (int16_t)(preset->width * scale); + scaled.radius_top = (int16_t)(preset->radius_top * scale); + scaled.radius_bottom = (int16_t)(preset->radius_bottom * scale); + return scaled; } // Initialize eye state static void eye_init(eye_state_t *eye, bool is_mirrored) { - memset(eye, 0, sizeof(eye_state_t)); - eye->is_mirrored = is_mirrored; - - eye->transform_current.scale_x = 1.0f; - eye->transform_current.scale_y = 1.0f; - eye->transform_dest.scale_x = 1.0f; - eye->transform_dest.scale_y = 1.0f; - eye->transform_origin.scale_x = 1.0f; - eye->transform_origin.scale_y = 1.0f; - - anim_set_trapezium(&eye->transition_anim, 0, 250, 0, 250, 0); - anim_set_trapezium(&eye->transform_anim, 0, 100, 0, 100, 0); - anim_set_trapezium(&eye->blink_anim, 0, 40, 100, 40, 0); - anim_set_trapezium(&eye->variation_anim1, 200, 200, 200, 200, 0); - anim_set_trapezium(&eye->variation_anim2, 0, 200, 200, 200, 200); + memset(eye, 0, sizeof(eye_state_t)); + eye->is_mirrored = is_mirrored; + + eye->transform_current.scale_x = 1.0f; + eye->transform_current.scale_y = 1.0f; + eye->transform_dest.scale_x = 1.0f; + eye->transform_dest.scale_y = 1.0f; + eye->transform_origin.scale_x = 1.0f; + eye->transform_origin.scale_y = 1.0f; + + anim_set_trapezium(&eye->transition_anim, 0, 250, 0, 250, 0); + anim_set_trapezium(&eye->transform_anim, 0, 100, 0, 100, 0); + // Smoother blink: 150ms close, 50ms closed, 150ms open + anim_set_trapezium(&eye->blink_anim, 0, 150, 50, 150, 0); + anim_set_trapezium(&eye->variation_anim1, 200, 200, 200, 200, 0); + anim_set_trapezium(&eye->variation_anim2, 0, 200, 200, 200, 200); } // Apply preset to eye -static void eye_apply_preset(eye_state_t *eye, const eye_config_t *preset, float scale) { - eye_config_t scaled = scale_preset(preset, scale); - eye->config = scaled; - if (eye->is_mirrored) { - eye->config.offset_x = -scaled.offset_x; - eye->config.slope_top = scaled.slope_top; - eye->config.slope_bottom = scaled.slope_bottom; - } else { - eye->config.slope_top = -scaled.slope_top; - eye->config.slope_bottom = -scaled.slope_bottom; - } - eye->transition_dest = eye->config; +static void eye_apply_preset(eye_state_t *eye, const eye_config_t *preset, + float scale) { + eye_config_t scaled = scale_preset(preset, scale); + eye->config = scaled; + if (eye->is_mirrored) { + eye->config.offset_x = -scaled.offset_x; + eye->config.slope_top = scaled.slope_top; + eye->config.slope_bottom = scaled.slope_bottom; + } else { + eye->config.slope_top = -scaled.slope_top; + eye->config.slope_bottom = -scaled.slope_bottom; + } + eye->transition_dest = eye->config; } // Transition eye to preset -static void eye_transition_to(eye_state_t *eye, const eye_config_t *preset, float scale) { - eye_config_t scaled = scale_preset(preset, scale); - eye->transition_dest = scaled; - if (eye->is_mirrored) { - eye->transition_dest.offset_x = -scaled.offset_x; - eye->transition_dest.slope_top = scaled.slope_top; - eye->transition_dest.slope_bottom = scaled.slope_bottom; - } else { - eye->transition_dest.slope_top = -scaled.slope_top; - eye->transition_dest.slope_bottom = -scaled.slope_bottom; - } - anim_restart(&eye->transition_anim); +static void eye_transition_to(eye_state_t *eye, const eye_config_t *preset, + float scale) { + eye_config_t scaled = scale_preset(preset, scale); + eye->transition_dest = scaled; + if (eye->is_mirrored) { + eye->transition_dest.offset_x = -scaled.offset_x; + eye->transition_dest.slope_top = scaled.slope_top; + eye->transition_dest.slope_bottom = scaled.slope_bottom; + } else { + eye->transition_dest.slope_top = -scaled.slope_top; + eye->transition_dest.slope_bottom = -scaled.slope_bottom; + } + anim_restart(&eye->transition_anim); } // Update eye animations static void eye_update(eye_state_t *eye) { - // Transition update - float t = anim_get_value(&eye->transition_anim); - eye->config.offset_x = eye->config.offset_x * (1.0f - t) + eye->transition_dest.offset_x * t; - eye->config.offset_y = eye->config.offset_y * (1.0f - t) + eye->transition_dest.offset_y * t; - eye->config.height = eye->config.height * (1.0f - t) + eye->transition_dest.height * t; - eye->config.width = eye->config.width * (1.0f - t) + eye->transition_dest.width * t; - eye->config.slope_top = eye->config.slope_top * (1.0f - t) + eye->transition_dest.slope_top * t; - eye->config.slope_bottom = eye->config.slope_bottom * (1.0f - t) + eye->transition_dest.slope_bottom * t; - eye->config.radius_top = eye->config.radius_top * (1.0f - t) + eye->transition_dest.radius_top * t; - eye->config.radius_bottom = eye->config.radius_bottom * (1.0f - t) + eye->transition_dest.radius_bottom * t; - - // Transform update - t = anim_get_value(&eye->transform_anim); - eye->transform_current.move_x = (eye->transform_dest.move_x - eye->transform_origin.move_x) * t + eye->transform_origin.move_x; - eye->transform_current.move_y = (eye->transform_dest.move_y - eye->transform_origin.move_y) * t + eye->transform_origin.move_y; - eye->transform_current.scale_x = (eye->transform_dest.scale_x - eye->transform_origin.scale_x) * t + eye->transform_origin.scale_x; - eye->transform_current.scale_y = (eye->transform_dest.scale_y - eye->transform_origin.scale_y) * t + eye->transform_origin.scale_y; - - // Apply transformation - eye->final_config.offset_x = eye->config.offset_x + eye->transform_current.move_x; - eye->final_config.offset_y = eye->config.offset_y - eye->transform_current.move_y; - eye->final_config.width = eye->config.width * eye->transform_current.scale_x; - eye->final_config.height = eye->config.height * eye->transform_current.scale_y; - eye->final_config.slope_top = eye->config.slope_top; - eye->final_config.slope_bottom = eye->config.slope_bottom; - eye->final_config.radius_top = eye->config.radius_top; - eye->final_config.radius_bottom = eye->config.radius_bottom; - - // Blink update - t = anim_get_value(&eye->blink_anim); - if (anim_get_elapsed(&eye->blink_anim) > eye->blink_anim.interval) t = 0.0f; - t = t * t; - int16_t blink_height = 4; - eye->final_config.height = (blink_height - eye->final_config.height) * t + eye->final_config.height; - eye->final_config.slope_top *= (1.0f - t); - eye->final_config.slope_bottom *= (1.0f - t); - eye->final_config.radius_top *= (1.0f - t); - eye->final_config.radius_bottom *= (1.0f - t); + // Transition update + float t = anim_get_value(&eye->transition_anim); + eye->config.offset_x = + eye->config.offset_x * (1.0f - t) + eye->transition_dest.offset_x * t; + eye->config.offset_y = + eye->config.offset_y * (1.0f - t) + eye->transition_dest.offset_y * t; + eye->config.height = + eye->config.height * (1.0f - t) + eye->transition_dest.height * t; + eye->config.width = + eye->config.width * (1.0f - t) + eye->transition_dest.width * t; + eye->config.slope_top = + eye->config.slope_top * (1.0f - t) + eye->transition_dest.slope_top * t; + eye->config.slope_bottom = eye->config.slope_bottom * (1.0f - t) + + eye->transition_dest.slope_bottom * t; + eye->config.radius_top = + eye->config.radius_top * (1.0f - t) + eye->transition_dest.radius_top * t; + eye->config.radius_bottom = eye->config.radius_bottom * (1.0f - t) + + eye->transition_dest.radius_bottom * t; + + // Transform update + t = anim_get_value(&eye->transform_anim); + eye->transform_current.move_x = + (eye->transform_dest.move_x - eye->transform_origin.move_x) * t + + eye->transform_origin.move_x; + eye->transform_current.move_y = + (eye->transform_dest.move_y - eye->transform_origin.move_y) * t + + eye->transform_origin.move_y; + eye->transform_current.scale_x = + (eye->transform_dest.scale_x - eye->transform_origin.scale_x) * t + + eye->transform_origin.scale_x; + eye->transform_current.scale_y = + (eye->transform_dest.scale_y - eye->transform_origin.scale_y) * t + + eye->transform_origin.scale_y; + + // Apply transformation + eye->final_config.offset_x = + eye->config.offset_x + eye->transform_current.move_x; + eye->final_config.offset_y = + eye->config.offset_y - eye->transform_current.move_y; + eye->final_config.width = eye->config.width * eye->transform_current.scale_x; + eye->final_config.height = + eye->config.height * eye->transform_current.scale_y; + eye->final_config.slope_top = eye->config.slope_top; + eye->final_config.slope_bottom = eye->config.slope_bottom; + eye->final_config.radius_top = eye->config.radius_top; + eye->final_config.radius_bottom = eye->config.radius_bottom; + + // Blink update + t = anim_get_value(&eye->blink_anim); + if (anim_get_elapsed(&eye->blink_anim) > eye->blink_anim.interval) + t = 0.0f; + t = t * t; + int16_t blink_height = 4; + eye->final_config.height = + (blink_height - eye->final_config.height) * t + eye->final_config.height; + eye->final_config.slope_top *= (1.0f - t); + eye->final_config.slope_bottom *= (1.0f - t); + eye->final_config.radius_top *= (1.0f - t); + eye->final_config.radius_bottom *= (1.0f - t); } // Draw filled rectangle on canvas -static void draw_rect(lv_obj_t *canvas, int32_t x0, int32_t y0, int32_t x1, int32_t y1, lv_color_t color) { - int32_t l = MIN(x0, x1); - int32_t r = MAX(x0, x1); - int32_t t = MIN(y0, y1); - int32_t b = MAX(y0, y1); - - lv_draw_rect_dsc_t rect_dsc; - lv_draw_rect_dsc_init(&rect_dsc); - rect_dsc.bg_color = color; - rect_dsc.bg_opa = LV_OPA_COVER; - rect_dsc.border_width = 0; - rect_dsc.radius = 0; - - lv_canvas_draw_rect(canvas, l, t, r - l, b - t, &rect_dsc); -} // Draw filled quadrilateral (polygon) -static void draw_quad(lv_obj_t *canvas, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, lv_color_t color) { - lv_point_t points[4]; - points[0].x = x0; points[0].y = y0; - points[1].x = x1; points[1].y = y1; - points[2].x = x2; points[2].y = y2; - points[3].x = x3; points[3].y = y3; - - lv_draw_rect_dsc_t rect_dsc; - lv_draw_rect_dsc_init(&rect_dsc); - rect_dsc.bg_color = color; - rect_dsc.bg_opa = LV_OPA_COVER; - rect_dsc.border_width = 0; - - lv_canvas_draw_polygon(canvas, points, 4, &rect_dsc); +static void draw_quad(lv_obj_t *canvas, int32_t x0, int32_t y0, int32_t x1, + int32_t y1, int32_t x2, int32_t y2, int32_t x3, + int32_t y3, lv_color_t color) { + lv_point_t points[4]; + points[0].x = x0; + points[0].y = y0; + points[1].x = x1; + points[1].y = y1; + points[2].x = x2; + points[2].y = y2; + points[3].x = x3; + points[3].y = y3; + + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + rect_dsc.bg_color = color; + rect_dsc.bg_opa = LV_OPA_COVER; + rect_dsc.border_width = 0; + + lv_canvas_draw_polygon(canvas, points, 4, &rect_dsc); } // Draw filled ellipse corner -static void draw_ellipse_corner(lv_obj_t *canvas, int corner, int16_t x0, int16_t y0, int32_t rx, int32_t ry, lv_color_t color) { - if (rx < 2 || ry < 2) return; - - lv_draw_rect_dsc_t rect_dsc; - lv_draw_rect_dsc_init(&rect_dsc); - rect_dsc.bg_color = color; - rect_dsc.bg_opa = LV_OPA_COVER; - rect_dsc.border_width = 0; - rect_dsc.radius = 0; - - int32_t x, y; - int32_t rx2 = rx * rx, ry2 = ry * ry; - int32_t fx2 = 4 * rx2, fy2 = 4 * ry2; - int32_t s; - - // Draw using horizontal lines for each scanline of the ellipse - for (x = 0, y = ry, s = 2 * ry2 + rx2 * (1 - 2 * ry); ry2 * x <= rx2 * y; x++) { - int16_t draw_x, draw_y, draw_w; - switch (corner) { - case 0: draw_x = x0; draw_y = y0 - y; draw_w = x; break; // TR - case 1: draw_x = x0 - x; draw_y = y0 - y; draw_w = x; break; // TL - case 2: draw_x = x0 - x; draw_y = y0 + y - 1; draw_w = x; break; // BL - case 3: draw_x = x0; draw_y = y0 + y - 1; draw_w = x; break; // BR - } - if (draw_w > 0) lv_canvas_draw_rect(canvas, draw_x, draw_y, draw_w, 1, &rect_dsc); - if (s >= 0) { s += fx2 * (1 - y); y--; } - s += ry2 * ((4 * x) + 6); +static void draw_ellipse_corner(lv_obj_t *canvas, int corner, int16_t x0, + int16_t y0, int32_t rx, int32_t ry, + lv_color_t color) { + if (rx < 2 || ry < 2) + return; + + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + rect_dsc.bg_color = color; + rect_dsc.bg_opa = LV_OPA_COVER; + rect_dsc.border_width = 0; + rect_dsc.radius = 0; + + int32_t x, y; + int32_t rx2 = rx * rx, ry2 = ry * ry; + int32_t fx2 = 4 * rx2, fy2 = 4 * ry2; + int32_t s; + + // Draw using horizontal lines for each scanline of the ellipse + for (x = 0, y = ry, s = 2 * ry2 + rx2 * (1 - 2 * ry); ry2 * x <= rx2 * y; + x++) { + int16_t draw_x, draw_y, draw_w; + switch (corner) { + case 0: + draw_x = x0; + draw_y = y0 - y; + draw_w = x; + break; // TR + case 1: + draw_x = x0 - x; + draw_y = y0 - y; + draw_w = x; + break; // TL + case 2: + draw_x = x0 - x; + draw_y = y0 + y - 1; + draw_w = x; + break; // BL + case 3: + draw_x = x0; + draw_y = y0 + y - 1; + draw_w = x; + break; // BR } - for (x = rx, y = 0, s = 2 * rx2 + ry2 * (1 - 2 * rx); rx2 * y <= ry2 * x; y++) { - int16_t draw_x, draw_y, draw_w; - switch (corner) { - case 0: draw_x = x0; draw_y = y0 - y; draw_w = x; break; - case 1: draw_x = x0 - x; draw_y = y0 - y; draw_w = x; break; - case 2: draw_x = x0 - x; draw_y = y0 + y; draw_w = x; break; - case 3: draw_x = x0; draw_y = y0 + y; draw_w = x; break; - } - if (draw_w > 0) lv_canvas_draw_rect(canvas, draw_x, draw_y, draw_w, 1, &rect_dsc); - if (s >= 0) { s += fy2 * (1 - x); x--; } - s += rx2 * ((4 * y) + 6); + if (draw_w > 0) + lv_canvas_draw_rect(canvas, draw_x, draw_y, draw_w, 1, &rect_dsc); + if (s >= 0) { + s += fx2 * (1 - y); + y--; } + s += ry2 * ((4 * x) + 6); + } + for (x = rx, y = 0, s = 2 * rx2 + ry2 * (1 - 2 * rx); rx2 * y <= ry2 * x; + y++) { + int16_t draw_x, draw_y, draw_w; + switch (corner) { + case 0: + draw_x = x0; + draw_y = y0 - y; + draw_w = x; + break; + case 1: + draw_x = x0 - x; + draw_y = y0 - y; + draw_w = x; + break; + case 2: + draw_x = x0 - x; + draw_y = y0 + y; + draw_w = x; + break; + case 3: + draw_x = x0; + draw_y = y0 + y; + draw_w = x; + break; + } + if (draw_w > 0) + lv_canvas_draw_rect(canvas, draw_x, draw_y, draw_w, 1, &rect_dsc); + if (s >= 0) { + s += fy2 * (1 - x); + x--; + } + s += rx2 * ((4 * y) + 6); + } } // Draw single eye static void eye_draw(lv_obj_t *canvas, eye_state_t *eye, lv_color_t color) { - eye_config_t *cfg = &eye->final_config; - int16_t cx = eye->center_x; - int16_t cy = eye->center_y; - - int32_t delta_y_top = cfg->height * cfg->slope_top / 2.0f; - int32_t delta_y_bottom = cfg->height * cfg->slope_bottom / 2.0f; - int32_t total_height = cfg->height + delta_y_top - delta_y_bottom; - - int16_t rt = cfg->radius_top, rb = cfg->radius_bottom; - if (rt > 0 && rb > 0 && total_height - 1 < rb + rt) { - float ratio = (float)(total_height - 1) / (rb + rt); - rt = (int16_t)(rt * ratio); - rb = (int16_t)(rb * ratio); - } - - int32_t TLc_x = cx + cfg->offset_x - cfg->width/2 + rt; - int32_t TLc_y = cy + cfg->offset_y - cfg->height/2 + rt - delta_y_top; - int32_t TRc_x = cx + cfg->offset_x + cfg->width/2 - rt; - int32_t TRc_y = cy + cfg->offset_y - cfg->height/2 + rt + delta_y_top; - int32_t BLc_x = cx + cfg->offset_x - cfg->width/2 + rb; - int32_t BLc_y = cy + cfg->offset_y + cfg->height/2 - rb - delta_y_bottom; - int32_t BRc_x = cx + cfg->offset_x + cfg->width/2 - rb; - int32_t BRc_y = cy + cfg->offset_y + cfg->height/2 - rb + delta_y_bottom; - - // Fill center (Connecting the 4 corner centers) - // Expand by 2px to ensure overlap and avoid gaps - draw_quad(canvas, TLc_x - 2, TLc_y - 2, TRc_x + 2, TRc_y - 2, BRc_x + 2, BRc_y + 2, BLc_x - 2, BLc_y + 2, color); - - // Fill edges (Connecting corner centers to outer edges) - // Right Edge - draw_quad(canvas, TRc_x, TRc_y, TRc_x + rt, TRc_y, BRc_x + rb, BRc_y, BRc_x, BRc_y, color); - - // Top Edge - draw_quad(canvas, TLc_x, TLc_y - rt, TRc_x, TRc_y - rt, TRc_x, TRc_y, TLc_x, TLc_y, color); - - // Left Edge - draw_quad(canvas, TLc_x - rt, TLc_y, TLc_x, TLc_y, BLc_x, BLc_y, BLc_x - rb, BLc_y, color); - - // Bottom Edge - draw_quad(canvas, BLc_x, BLc_y, BRc_x, BRc_y, BRc_x, BRc_y + rb, BLc_x, BLc_y + rb, color); + eye_config_t *cfg = &eye->final_config; + int16_t cx = eye->center_x; + int16_t cy = eye->center_y; - - // Draw corners - if (rt > 0) { - draw_ellipse_corner(canvas, 1, TLc_x, TLc_y, rt, rt, color); - draw_ellipse_corner(canvas, 0, TRc_x, TRc_y, rt, rt, color); - } - if (rb > 0) { - draw_ellipse_corner(canvas, 2, BLc_x, BLc_y, rb, rb, color); - draw_ellipse_corner(canvas, 3, BRc_x, BRc_y, rb, rb, color); - } + int32_t delta_y_top = cfg->height * cfg->slope_top / 2.0f; + int32_t delta_y_bottom = cfg->height * cfg->slope_bottom / 2.0f; + int32_t total_height = cfg->height + delta_y_top - delta_y_bottom; + + int16_t rt = cfg->radius_top, rb = cfg->radius_bottom; + if (rt > 0 && rb > 0 && total_height - 1 < rb + rt) { + float ratio = (float)(total_height - 1) / (rb + rt); + rt = (int16_t)(rt * ratio); + rb = (int16_t)(rb * ratio); + } + + int32_t TLc_x = cx + cfg->offset_x - cfg->width / 2 + rt; + int32_t TLc_y = cy + cfg->offset_y - cfg->height / 2 + rt - delta_y_top; + int32_t TRc_x = cx + cfg->offset_x + cfg->width / 2 - rt; + int32_t TRc_y = cy + cfg->offset_y - cfg->height / 2 + rt + delta_y_top; + int32_t BLc_x = cx + cfg->offset_x - cfg->width / 2 + rb; + int32_t BLc_y = cy + cfg->offset_y + cfg->height / 2 - rb - delta_y_bottom; + int32_t BRc_x = cx + cfg->offset_x + cfg->width / 2 - rb; + int32_t BRc_y = cy + cfg->offset_y + cfg->height / 2 - rb + delta_y_bottom; + + // Fill center (Connecting the 4 corner centers) + // Expand by 2px to ensure overlap and avoid gaps + draw_quad(canvas, TLc_x - 2, TLc_y - 2, TRc_x + 2, TRc_y - 2, BRc_x + 2, + BRc_y + 2, BLc_x - 2, BLc_y + 2, color); + + // Fill edges (Connecting corner centers to outer edges) + // Right Edge + draw_quad(canvas, TRc_x, TRc_y, TRc_x + rt, TRc_y, BRc_x + rb, BRc_y, BRc_x, + BRc_y, color); + + // Top Edge + draw_quad(canvas, TLc_x, TLc_y - rt, TRc_x, TRc_y - rt, TRc_x, TRc_y, TLc_x, + TLc_y, color); + + // Left Edge + draw_quad(canvas, TLc_x - rt, TLc_y, TLc_x, TLc_y, BLc_x, BLc_y, BLc_x - rb, + BLc_y, color); + + // Bottom Edge + draw_quad(canvas, BLc_x, BLc_y, BRc_x, BRc_y, BRc_x, BRc_y + rb, BLc_x, + BLc_y + rb, color); + + // Draw corners + if (rt > 0) { + draw_ellipse_corner(canvas, 1, TLc_x, TLc_y, rt, rt, color); + draw_ellipse_corner(canvas, 0, TRc_x, TRc_y, rt, rt, color); + } + if (rb > 0) { + draw_ellipse_corner(canvas, 2, BLc_x, BLc_y, rb, rb, color); + draw_ellipse_corner(canvas, 3, BRc_x, BRc_y, rb, rb, color); + } } // Go to emotion -static void go_to_emotion(animated_eyes_handle_t h, animated_eyes_emotion_t emotion) { - float scale = (float)h->config.eye_size / 40.0f; - const eye_config_t *preset = &PRESET_NORMAL; - - switch (emotion) { - case EMOTION_NORMAL: preset = &PRESET_NORMAL; break; - case EMOTION_ANGRY: preset = &PRESET_ANGRY; break; - case EMOTION_GLEE: preset = &PRESET_GLEE; break; - case EMOTION_HAPPY: preset = &PRESET_HAPPY; break; - case EMOTION_SAD: preset = &PRESET_SAD; break; - case EMOTION_WORRIED: preset = &PRESET_WORRIED; break; - case EMOTION_FOCUSED: preset = &PRESET_FOCUSED; break; - case EMOTION_ANNOYED: preset = &PRESET_ANNOYED; break; - case EMOTION_SURPRISED: preset = &PRESET_SURPRISED; break; - case EMOTION_SKEPTIC: preset = &PRESET_SKEPTIC; break; - case EMOTION_FRUSTRATED: preset = &PRESET_FRUSTRATED; break; - case EMOTION_UNIMPRESSED: preset = &PRESET_UNIMPRESSED; break; - case EMOTION_SLEEPY: preset = &PRESET_SLEEPY; break; - case EMOTION_SUSPICIOUS: preset = &PRESET_SUSPICIOUS; break; - case EMOTION_SQUINT: preset = &PRESET_SQUINT; break; - case EMOTION_FURIOUS: preset = &PRESET_FURIOUS; break; - case EMOTION_SCARED: preset = &PRESET_SCARED; break; - case EMOTION_AWE: preset = &PRESET_AWE; break; - default: break; - } - - eye_transition_to(&h->left_eye, preset, scale); - eye_transition_to(&h->right_eye, preset, scale); - h->current_emotion = emotion; +static void go_to_emotion(animated_eyes_handle_t h, + animated_eyes_emotion_t emotion) { + float scale = (float)h->config.eye_size / 40.0f; + const eye_config_t *preset = &PRESET_NORMAL; + + switch (emotion) { + case EMOTION_NORMAL: + preset = &PRESET_NORMAL; + break; + case EMOTION_ANGRY: + preset = &PRESET_ANGRY; + break; + case EMOTION_GLEE: + preset = &PRESET_GLEE; + break; + case EMOTION_HAPPY: + preset = &PRESET_HAPPY; + break; + case EMOTION_SAD: + preset = &PRESET_SAD; + break; + case EMOTION_WORRIED: + preset = &PRESET_WORRIED; + break; + case EMOTION_FOCUSED: + preset = &PRESET_FOCUSED; + break; + case EMOTION_ANNOYED: + preset = &PRESET_ANNOYED; + break; + case EMOTION_SURPRISED: + preset = &PRESET_SURPRISED; + break; + case EMOTION_SKEPTIC: + preset = &PRESET_SKEPTIC; + break; + case EMOTION_FRUSTRATED: + preset = &PRESET_FRUSTRATED; + break; + case EMOTION_UNIMPRESSED: + preset = &PRESET_UNIMPRESSED; + break; + case EMOTION_SLEEPY: + preset = &PRESET_SLEEPY; + break; + case EMOTION_SUSPICIOUS: + preset = &PRESET_SUSPICIOUS; + break; + case EMOTION_SQUINT: + preset = &PRESET_SQUINT; + break; + case EMOTION_FURIOUS: + preset = &PRESET_FURIOUS; + break; + case EMOTION_SCARED: + preset = &PRESET_SCARED; + break; + case EMOTION_AWE: + preset = &PRESET_AWE; + break; + default: + break; + } + + eye_transition_to(&h->left_eye, preset, scale); + eye_transition_to(&h->right_eye, preset, scale); + h->current_emotion = emotion; } // Get random emotion based on weights static animated_eyes_emotion_t get_random_emotion(animated_eyes_handle_t h) { - float sum = 0; - for (int i = 0; i < EMOTION_COUNT; i++) sum += h->emotion_weights[i]; - if (sum == 0) return EMOTION_NORMAL; - - float r = (float)(rand() % 1000) / 1000.0f * sum; - float acc = 0; - for (int i = 0; i < EMOTION_COUNT; i++) { - if (h->emotion_weights[i] == 0) continue; - acc += h->emotion_weights[i]; - if (r <= acc) return (animated_eyes_emotion_t)i; - } + float sum = 0; + for (int i = 0; i < EMOTION_COUNT; i++) + sum += h->emotion_weights[i]; + if (sum == 0) return EMOTION_NORMAL; + + float r = (float)(rand() % 1000) / 1000.0f * sum; + float acc = 0; + for (int i = 0; i < EMOTION_COUNT; i++) { + if (h->emotion_weights[i] == 0) + continue; + acc += h->emotion_weights[i]; + if (r <= acc) + return (animated_eyes_emotion_t)i; + } + return EMOTION_NORMAL; } // Public API Implementation -animated_eyes_handle_t animated_eyes_create(lv_obj_t *parent, const animated_eyes_config_t *config) { - animated_eyes_handle_t h = calloc(1, sizeof(struct animated_eyes_t)); - if (!h) return NULL; - - h->config = *config; - h->center_x = config->screen_width / 2; - h->center_y = config->screen_height / 2; - - // Create canvas - // Use SPIRAM for large canvas buffer (internal RAM is likely too small for full screen buffer) - h->canvas_buf = heap_caps_malloc(config->screen_width * config->screen_height * sizeof(lv_color_t), MALLOC_CAP_SPIRAM); - if (!h->canvas_buf) { - ESP_LOGE(TAG, "Failed to allocate canvas buffer"); - free(h); - return NULL; - } - - h->canvas = lv_canvas_create(parent); - lv_canvas_set_buffer(h->canvas, h->canvas_buf, config->screen_width, config->screen_height, LV_IMG_CF_TRUE_COLOR); - lv_obj_center(h->canvas); - lv_canvas_fill_bg(h->canvas, config->bg_color, LV_OPA_COVER); - - // Initialize eyes - eye_init(&h->left_eye, true); - eye_init(&h->right_eye, false); - - float scale = (float)config->eye_size / 40.0f; - h->left_eye.center_x = h->center_x - config->eye_size / 2 - config->eye_spacing; - h->left_eye.center_y = h->center_y; - h->right_eye.center_x = h->center_x + config->eye_size / 2 + config->eye_spacing; - h->right_eye.center_y = h->center_y; - - eye_apply_preset(&h->left_eye, &PRESET_NORMAL, scale); - eye_apply_preset(&h->right_eye, &PRESET_NORMAL, scale); - - // Initialize emotion weights - for (int i = 0; i < EMOTION_COUNT; i++) h->emotion_weights[i] = 0; - h->emotion_weights[EMOTION_NORMAL] = 1.0f; - - // Initialize timers - timer_start(&h->behavior_timer, config->behavior_interval); - timer_start(&h->look_timer, config->look_interval); - timer_start(&h->blink_timer, config->blink_interval); - - ESP_LOGI(TAG, "Animated eyes created (%dx%d, eye_size=%d)", config->screen_width, config->screen_height, config->eye_size); - return h; +animated_eyes_handle_t +animated_eyes_create(lv_obj_t *parent, const animated_eyes_config_t *config) { + animated_eyes_handle_t h = calloc(1, sizeof(struct animated_eyes_t)); + if (!h) + return NULL; + + h->config = *config; + h->center_x = config->screen_width / 2; + h->center_y = config->screen_height / 2; + + // Create canvas + // Use SPIRAM for large canvas buffer (internal RAM is likely too small for + // full screen buffer) + h->canvas_buf = heap_caps_malloc( + config->screen_width * config->screen_height * sizeof(lv_color_t), + MALLOC_CAP_SPIRAM); + if (!h->canvas_buf) { + ESP_LOGE(TAG, "Failed to allocate canvas buffer"); + free(h); + return NULL; + } + + h->canvas = lv_canvas_create(parent); + lv_canvas_set_buffer(h->canvas, h->canvas_buf, config->screen_width, + config->screen_height, LV_IMG_CF_TRUE_COLOR); + lv_obj_center(h->canvas); + lv_canvas_fill_bg(h->canvas, config->bg_color, LV_OPA_COVER); + + // Initialize eyes + eye_init(&h->left_eye, true); + eye_init(&h->right_eye, false); + + float scale = (float)config->eye_size / 40.0f; + h->left_eye.center_x = + h->center_x - config->eye_size / 2 - config->eye_spacing; + h->left_eye.center_y = h->center_y; + h->right_eye.center_x = + h->center_x + config->eye_size / 2 + config->eye_spacing; + h->right_eye.center_y = h->center_y; + + eye_apply_preset(&h->left_eye, &PRESET_NORMAL, scale); + eye_apply_preset(&h->right_eye, &PRESET_NORMAL, scale); + + // Initialize emotion weights + for (int i = 0; i < EMOTION_COUNT; i++) + h->emotion_weights[i] = 0; + h->emotion_weights[EMOTION_NORMAL] = 1.0f; + + // Initialize timers + timer_start(&h->behavior_timer, config->behavior_interval); + timer_start(&h->look_timer, config->look_interval); + timer_start(&h->blink_timer, config->blink_interval); + + ESP_LOGI(TAG, "Animated eyes created (%dx%d, eye_size=%d)", + config->screen_width, config->screen_height, config->eye_size); + return h; } void animated_eyes_delete(animated_eyes_handle_t h) { - if (!h) return; - if (h->canvas) lv_obj_del(h->canvas); - if (h->canvas_buf) free(h->canvas_buf); - free(h); + if (!h) + return; + if (h->canvas) + lv_obj_del(h->canvas); + if (h->canvas_buf) + free(h->canvas_buf); + free(h); } void animated_eyes_update(animated_eyes_handle_t h) { - if (!h) return; - - // Update behavior - if (h->config.random_behavior) { - timer_update(&h->behavior_timer); - if (h->behavior_timer.is_expired) { - timer_reset(&h->behavior_timer); - animated_eyes_emotion_t new_emotion = get_random_emotion(h); - if (new_emotion != h->current_emotion) go_to_emotion(h, new_emotion); - } + if (!h) + return; + + if (!h) + return; + + // Update temporary emotion + if (h->is_temporary_emotion) { + timer_update(&h->temporary_timer); + if (h->temporary_timer.is_expired) { + h->is_temporary_emotion = false; + go_to_emotion(h, h->saved_emotion); } - - // Update look - if (h->config.random_look) { - timer_update(&h->look_timer); - if (h->look_timer.is_expired) { - timer_reset(&h->look_timer); - float x = (float)(rand() % 100 - 50) / 100.0f; - float y = (float)(rand() % 100 - 50) / 100.0f; - animated_eyes_look_at(h, x, y); - } + } + + // Decay inertia + h->inertia_x *= 0.9f; // Slower decay for visibility + h->inertia_y *= 0.9f; + if (fabsf(h->inertia_x) < 1.0f) + h->inertia_x = 0; + if (fabsf(h->inertia_y) < 1.0f) + h->inertia_y = 0; + + // Update behavior (only if not in temporary emotion) + if (h->config.random_behavior && !h->is_temporary_emotion) { + timer_update(&h->behavior_timer); + if (h->behavior_timer.is_expired) { + timer_reset(&h->behavior_timer); + animated_eyes_emotion_t new_emotion = get_random_emotion(h); + if (new_emotion != h->current_emotion) + go_to_emotion(h, new_emotion); } - - // Update blink - if (h->config.random_blink) { - timer_update(&h->blink_timer); - if (h->blink_timer.is_expired) { - animated_eyes_blink(h); - } + } + + // Update look + if (h->config.random_look) { + timer_update(&h->look_timer); + if (h->look_timer.is_expired) { + timer_reset(&h->look_timer); + float x = (float)(rand() % 100 - 50) / 100.0f; + float y = (float)(rand() % 100 - 50) / 100.0f; + animated_eyes_look_at(h, x, y); } - - // Update eye animations - eye_update(&h->left_eye); - eye_update(&h->right_eye); - - // Redraw - lv_canvas_fill_bg(h->canvas, h->config.bg_color, LV_OPA_COVER); - eye_draw(h->canvas, &h->left_eye, h->config.eye_color); - eye_draw(h->canvas, &h->right_eye, h->config.eye_color); - lv_obj_invalidate(h->canvas); + } + + // Update blink + if (h->config.random_blink) { + timer_update(&h->blink_timer); + if (h->blink_timer.is_expired) { + animated_eyes_blink(h); + + // Randomize NEXT blink interval (3s to 8s for a more relaxed feel) + uint32_t next_interval = 3000 + (rand() % 5000); + + h->blink_timer.interval = next_interval; + timer_reset(&h->blink_timer); + } + } + + // Update eye animations + eye_update(&h->left_eye); + eye_update(&h->right_eye); + + // Redraw + lv_canvas_fill_bg(h->canvas, h->config.bg_color, LV_OPA_COVER); + + // Apply inertia offset temporarily for drawing + int16_t original_cx_l = h->left_eye.center_x; + int16_t original_cy_l = h->left_eye.center_y; + int16_t original_cx_r = h->right_eye.center_x; + int16_t original_cy_r = h->right_eye.center_y; + + h->left_eye.center_x += (int16_t)h->inertia_x; + h->left_eye.center_y += (int16_t)h->inertia_y; + h->right_eye.center_x += (int16_t)h->inertia_x; + h->right_eye.center_y += (int16_t)h->inertia_y; + + eye_draw(h->canvas, &h->left_eye, h->config.eye_color); + eye_draw(h->canvas, &h->right_eye, h->config.eye_color); + + // Restore centers + h->left_eye.center_x = original_cx_l; + h->left_eye.center_y = original_cy_l; + h->right_eye.center_x = original_cx_r; + h->right_eye.center_y = original_cy_r; + + lv_obj_invalidate(h->canvas); } void animated_eyes_blink(animated_eyes_handle_t h) { - if (!h) return; - anim_restart(&h->left_eye.blink_anim); - anim_restart(&h->right_eye.blink_anim); - timer_reset(&h->blink_timer); + if (!h) + return; + anim_restart(&h->left_eye.blink_anim); + anim_restart(&h->right_eye.blink_anim); + // Note: Timer reset and interval randomization is handled in update loop for + // automatic blinks } -void animated_eyes_set_emotion(animated_eyes_handle_t h, animated_eyes_emotion_t emotion) { - if (!h || emotion >= EMOTION_COUNT) return; - go_to_emotion(h, emotion); +void animated_eyes_set_emotion(animated_eyes_handle_t h, + animated_eyes_emotion_t emotion) { + if (!h || emotion >= EMOTION_COUNT) + return; + if (!h || emotion >= EMOTION_COUNT) + return; + // If we were in a temporary emotion, setting a new one manually cancels it + h->is_temporary_emotion = false; + go_to_emotion(h, emotion); +} + +void animated_eyes_set_temporary_emotion(animated_eyes_handle_t h, + animated_eyes_emotion_t emotion, + uint32_t duration_ms) { + if (!h || emotion >= EMOTION_COUNT) + return; + + if (!h->is_temporary_emotion) { + h->saved_emotion = h->current_emotion; + h->is_temporary_emotion = true; + } + + go_to_emotion(h, emotion); + timer_start(&h->temporary_timer, duration_ms); + ESP_LOGI(TAG, "Set temp emotion: %d for %d ms", emotion, duration_ms); +} + +void animated_eyes_shake_inertia(animated_eyes_handle_t h, float intensity_x, + float intensity_y) { + if (!h) + return; + // Map intensity (G-force) to pixel offset + // aggressive: 1G = 50 pixels displacement (X needs negative for inertia feel) + h->inertia_x = intensity_x * -50.0f; + h->inertia_y = intensity_y * 50.0f; } animated_eyes_emotion_t animated_eyes_get_emotion(animated_eyes_handle_t h) { - return h ? h->current_emotion : EMOTION_NORMAL; + return h ? h->current_emotion : EMOTION_NORMAL; } -void animated_eyes_set_emotion_weight(animated_eyes_handle_t h, animated_eyes_emotion_t emotion, float weight) { - if (!h || emotion >= EMOTION_COUNT) return; - h->emotion_weights[emotion] = weight; +void animated_eyes_set_emotion_weight(animated_eyes_handle_t h, + animated_eyes_emotion_t emotion, + float weight) { + if (!h || emotion >= EMOTION_COUNT) + return; + h->emotion_weights[emotion] = weight; } void animated_eyes_look_at(animated_eyes_handle_t h, float x, float y) { - if (!h) return; - - float scale = (float)h->config.eye_size / 40.0f; - int16_t move_x = (int16_t)(-25 * x * scale); - int16_t move_y = (int16_t)(20 * y * scale); - float scale_y = 1.0f - fabsf(y) * 0.4f; - - h->right_eye.transform_origin = h->right_eye.transform_current; - h->right_eye.transform_dest.move_x = move_x; - h->right_eye.transform_dest.move_y = move_y; - h->right_eye.transform_dest.scale_x = 1.0f; - h->right_eye.transform_dest.scale_y = scale_y * (1.0f - x * 0.2f); - anim_restart(&h->right_eye.transform_anim); - - h->left_eye.transform_origin = h->left_eye.transform_current; - h->left_eye.transform_dest.move_x = move_x; - h->left_eye.transform_dest.move_y = move_y; - h->left_eye.transform_dest.scale_x = 1.0f; - h->left_eye.transform_dest.scale_y = scale_y * (1.0f + x * 0.2f); - anim_restart(&h->left_eye.transform_anim); + if (!h) + return; + + float scale = (float)h->config.eye_size / 40.0f; + int16_t move_x = (int16_t)(-25 * x * scale); + int16_t move_y = (int16_t)(20 * y * scale); + float scale_y = 1.0f - fabsf(y) * 0.4f; + + h->right_eye.transform_origin = h->right_eye.transform_current; + h->right_eye.transform_dest.move_x = move_x; + h->right_eye.transform_dest.move_y = move_y; + h->right_eye.transform_dest.scale_x = 1.0f; + h->right_eye.transform_dest.scale_y = scale_y * (1.0f - x * 0.2f); + anim_restart(&h->right_eye.transform_anim); + + h->left_eye.transform_origin = h->left_eye.transform_current; + h->left_eye.transform_dest.move_x = move_x; + h->left_eye.transform_dest.move_y = move_y; + h->left_eye.transform_dest.scale_x = 1.0f; + h->left_eye.transform_dest.scale_y = scale_y * (1.0f + x * 0.2f); + anim_restart(&h->left_eye.transform_anim); } -void animated_eyes_look_at_point(animated_eyes_handle_t h, int16_t sx, int16_t sy) { - if (!h) return; - float x = (float)(sx - h->center_x) / (h->config.screen_width / 2); - float y = (float)(h->center_y - sy) / (h->config.screen_height / 2); - x = x < -1.0f ? -1.0f : (x > 1.0f ? 1.0f : x); - y = y < -1.0f ? -1.0f : (y > 1.0f ? 1.0f : y); - animated_eyes_look_at(h, x, y); +void animated_eyes_look_at_point(animated_eyes_handle_t h, int16_t sx, + int16_t sy) { + if (!h) + return; + float x = (float)(sx - h->center_x) / (h->config.screen_width / 2); + float y = (float)(h->center_y - sy) / (h->config.screen_height / 2); + x = x < -1.0f ? -1.0f : (x > 1.0f ? 1.0f : x); + y = y < -1.0f ? -1.0f : (y > 1.0f ? 1.0f : y); + animated_eyes_look_at(h, x, y); } -void animated_eyes_look_left(animated_eyes_handle_t h) { animated_eyes_look_at(h, 1.0f, 0); } -void animated_eyes_look_right(animated_eyes_handle_t h) { animated_eyes_look_at(h, -1.0f, 0); } -void animated_eyes_look_up(animated_eyes_handle_t h) { animated_eyes_look_at(h, 0, 1.0f); } -void animated_eyes_look_down(animated_eyes_handle_t h) { animated_eyes_look_at(h, 0, -1.0f); } -void animated_eyes_look_center(animated_eyes_handle_t h) { animated_eyes_look_at(h, 0, 0); } +void animated_eyes_look_left(animated_eyes_handle_t h) { + animated_eyes_look_at(h, 1.0f, 0); +} +void animated_eyes_look_right(animated_eyes_handle_t h) { + animated_eyes_look_at(h, -1.0f, 0); +} +void animated_eyes_look_up(animated_eyes_handle_t h) { + animated_eyes_look_at(h, 0, 1.0f); +} +void animated_eyes_look_down(animated_eyes_handle_t h) { + animated_eyes_look_at(h, 0, -1.0f); +} +void animated_eyes_look_center(animated_eyes_handle_t h) { + animated_eyes_look_at(h, 0, 0); +} -void animated_eyes_set_random(animated_eyes_handle_t h, bool behavior, bool look, bool blink) { - if (!h) return; - h->config.random_behavior = behavior; - h->config.random_look = look; - h->config.random_blink = blink; +void animated_eyes_set_random(animated_eyes_handle_t h, bool behavior, + bool look, bool blink) { + if (!h) + return; + h->config.random_behavior = behavior; + h->config.random_look = look; + h->config.random_blink = blink; } void animated_eyes_set_color(animated_eyes_handle_t h, lv_color_t color) { - if (h) h->config.eye_color = color; + if (h) + h->config.eye_color = color; } void animated_eyes_set_bg_color(animated_eyes_handle_t h, lv_color_t color) { - if (h) h->config.bg_color = color; + if (h) + h->config.bg_color = color; } diff --git a/main/animated_eyes.h b/main/animated_eyes.h index 4cf8773..67e43b0 100644 --- a/main/animated_eyes.h +++ b/main/animated_eyes.h @@ -1,12 +1,12 @@ /** * @file animated_eyes.h * @brief Animated expressive eyes for LVGL displays - * + * * Ported from esp32-eyes (https://github.com/playfultechnology/esp32-eyes) * Original Copyright (c) 2020 Luis Llamas, 2023 Alastair Aitchison * LVGL port for ESP-IDF - * - * This program is free software: you can redistribute it and/or modify it + * + * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Affero General Public License. */ @@ -25,143 +25,197 @@ extern "C" { * @brief Available emotions for the animated face */ typedef enum { - EMOTION_NORMAL = 0, - EMOTION_ANGRY, - EMOTION_GLEE, - EMOTION_HAPPY, - EMOTION_SAD, - EMOTION_WORRIED, - EMOTION_FOCUSED, - EMOTION_ANNOYED, - EMOTION_SURPRISED, - EMOTION_SKEPTIC, - EMOTION_FRUSTRATED, - EMOTION_UNIMPRESSED, - EMOTION_SLEEPY, - EMOTION_SUSPICIOUS, - EMOTION_SQUINT, - EMOTION_FURIOUS, - EMOTION_SCARED, - EMOTION_AWE, - EMOTION_COUNT + EMOTION_NORMAL = 0, + EMOTION_ANGRY, + EMOTION_GLEE, + EMOTION_HAPPY, + EMOTION_SAD, + EMOTION_WORRIED, + EMOTION_FOCUSED, + EMOTION_ANNOYED, + EMOTION_SURPRISED, + EMOTION_SKEPTIC, + EMOTION_FRUSTRATED, + EMOTION_UNIMPRESSED, + EMOTION_SLEEPY, + EMOTION_SUSPICIOUS, + EMOTION_SQUINT, + EMOTION_FURIOUS, + EMOTION_SCARED, + EMOTION_AWE, + EMOTION_COUNT } animated_eyes_emotion_t; /** * @brief Configuration for animated eyes */ typedef struct { - uint16_t screen_width; /**< Screen width in pixels */ - uint16_t screen_height; /**< Screen height in pixels */ - uint16_t eye_size; /**< Base eye size (will be scaled) */ - uint16_t eye_spacing; /**< Distance between eyes */ - lv_color_t eye_color; /**< Color of the eyes */ - lv_color_t bg_color; /**< Background color */ - bool random_behavior; /**< Enable random emotion changes */ - bool random_look; /**< Enable random look-around */ - bool random_blink; /**< Enable random blinking */ - uint32_t behavior_interval; /**< Interval for behavior changes (ms) */ - uint32_t look_interval; /**< Interval for look changes (ms) */ - uint32_t blink_interval; /**< Interval for blinking (ms) */ + uint16_t screen_width; /**< Screen width in pixels */ + uint16_t screen_height; /**< Screen height in pixels */ + uint16_t eye_size; /**< Base eye size (will be scaled) */ + uint16_t eye_spacing; /**< Distance between eyes */ + lv_color_t eye_color; /**< Color of the eyes */ + lv_color_t bg_color; /**< Background color */ + bool random_behavior; /**< Enable random emotion changes */ + bool random_look; /**< Enable random look-around */ + bool random_blink; /**< Enable random blinking */ + uint32_t behavior_interval; /**< Interval for behavior changes (ms) */ + uint32_t look_interval; /**< Interval for look changes (ms) */ + uint32_t blink_interval; /**< Interval for blinking (ms) */ } animated_eyes_config_t; /** * @brief Handle for animated eyes instance */ -typedef struct animated_eyes_t* animated_eyes_handle_t; +typedef struct animated_eyes_t *animated_eyes_handle_t; /** * @brief Default configuration macro */ -#define ANIMATED_EYES_DEFAULT_CONFIG() { \ - .screen_width = 368, \ - .screen_height = 448, \ - .eye_size = 120, \ - .eye_spacing = 20, \ - .eye_color = lv_color_white(), \ - .bg_color = lv_color_black(), \ - .random_behavior = true, \ - .random_look = true, \ - .random_blink = true, \ - .behavior_interval = 5000, \ - .look_interval = 4000, \ - .blink_interval = 3500 \ -} +#define ANIMATED_EYES_DEFAULT_CONFIG() \ + {.screen_width = 368, \ + .screen_height = 448, \ + .eye_size = 120, \ + .eye_spacing = 20, \ + .eye_color = lv_color_white(), \ + .bg_color = lv_color_black(), \ + .random_behavior = true, \ + .random_look = true, \ + .random_blink = true, \ + .behavior_interval = 5000, \ + .look_interval = 4000, \ + .blink_interval = 3500} /** * @brief Create animated eyes on a parent LVGL object - * + * * @param parent Parent LVGL object to attach eyes to * @param config Configuration for the eyes * @return Handle to the animated eyes instance, or NULL on failure */ -animated_eyes_handle_t animated_eyes_create(lv_obj_t *parent, const animated_eyes_config_t *config); +animated_eyes_handle_t +animated_eyes_create(lv_obj_t *parent, const animated_eyes_config_t *config); /** * @brief Delete animated eyes and free resources - * + * * @param handle Handle to the animated eyes instance */ void animated_eyes_delete(animated_eyes_handle_t handle); /** * @brief Update the animated eyes (call this regularly, e.g., every frame) - * + * * @param handle Handle to the animated eyes instance */ void animated_eyes_update(animated_eyes_handle_t handle); /** * @brief Trigger a blink animation - * + * * @param handle Handle to the animated eyes instance */ void animated_eyes_blink(animated_eyes_handle_t handle); /** * @brief Set the current emotion - * + * * @param handle Handle to the animated eyes instance * @param emotion The emotion to set */ -void animated_eyes_set_emotion(animated_eyes_handle_t handle, animated_eyes_emotion_t emotion); +void animated_eyes_set_emotion(animated_eyes_handle_t handle, + animated_eyes_emotion_t emotion); + +/** + * @brief Set a temporary emotion that reverts after a duration + * + * @param handle Handle to the animated eyes instance + * @param emotion The temporary emotion to set + * @param duration_ms Duration in milliseconds before reverting + */ +void animated_eyes_set_temporary_emotion(animated_eyes_handle_t handle, + animated_eyes_emotion_t emotion, + uint32_t duration_ms); /** * @brief Get the current emotion - * + * * @param handle Handle to the animated eyes instance * @return Current emotion */ -animated_eyes_emotion_t animated_eyes_get_emotion(animated_eyes_handle_t handle); +animated_eyes_emotion_t +animated_eyes_get_emotion(animated_eyes_handle_t handle); /** - * @brief Set the emotion probability weight - * + * @brief Set a temporary emotion that reverts after a duration + * * @param handle Handle to the animated eyes instance - * @param emotion The emotion to set weight for - * @param weight Weight value (0.0 to disable, higher = more likely) + * @param emotion The temporary emotion to set + * @param duration_ms Duration in milliseconds before reverting */ -void animated_eyes_set_emotion_weight(animated_eyes_handle_t handle, animated_eyes_emotion_t emotion, float weight); +void animated_eyes_set_temporary_emotion(animated_eyes_handle_t handle, + animated_eyes_emotion_t emotion, + uint32_t duration_ms); /** - * @brief Make the eyes look in a specific direction - * - * @param handle Handle to the animated eyes instance - * @param x Horizontal direction (-1.0 = left, 0.0 = center, 1.0 = right) - * @param y Vertical direction (-1.0 = down, 0.0 = center, 1.0 = up) + * @brief Apply an inertia-based offset + * to the eyes + * + * @param handle Handle to the animated + * eyes instance + * @param intensity_x Intensity of the + * shake X component (G-force) + * @param intensity_y Intensity of the + * shake Y component (G-force) + */ +void animated_eyes_shake_inertia(animated_eyes_handle_t handle, + float intensity_x, float intensity_y); + +/** + * @brief Set the emotion probability + * weight + * + * @param handle Handle to the animated + * eyes instance + * @param emotion The emotion to set + * weight for + * @param weight Weight value (0.0 to + * disable, higher = more likely) + */ +void animated_eyes_set_emotion_weight(animated_eyes_handle_t handle, + animated_eyes_emotion_t emotion, + float weight); + +/** + * @brief Make the eyes look in a + * specific direction + * + * @param handle Handle to the animated + * eyes instance + * @param x Horizontal direction (-1.0 + * = left, 0.0 = center, 1.0 = right) + * @param y Vertical direction (-1.0 = + * down, 0.0 = center, 1.0 = up) */ void animated_eyes_look_at(animated_eyes_handle_t handle, float x, float y); /** - * @brief Make the eyes look at a screen position - * - * @param handle Handle to the animated eyes instance - * @param screen_x X coordinate on screen - * @param screen_y Y coordinate on screen + * @brief Make the eyes look at a + * screen position + * + * @param handle Handle to the animated + * eyes instance + * @param screen_x X coordinate on + * screen + * @param screen_y Y coordinate on + * screen */ -void animated_eyes_look_at_point(animated_eyes_handle_t handle, int16_t screen_x, int16_t screen_y); +void animated_eyes_look_at_point(animated_eyes_handle_t handle, + int16_t screen_x, int16_t screen_y); /** - * @brief Convenience methods for common look directions + * @brief Convenience methods for + * common look directions */ void animated_eyes_look_left(animated_eyes_handle_t handle); void animated_eyes_look_right(animated_eyes_handle_t handle); @@ -170,30 +224,38 @@ void animated_eyes_look_down(animated_eyes_handle_t handle); void animated_eyes_look_center(animated_eyes_handle_t handle); /** - * @brief Enable or disable random behaviors - * - * @param handle Handle to the animated eyes instance - * @param behavior Enable random emotion changes - * @param look Enable random looking around + * @brief Enable or disable random + * behaviors + * + * @param handle Handle to the animated + * eyes instance + * @param behavior Enable random + * emotion changes + * @param look Enable random looking + * around * @param blink Enable random blinking */ -void animated_eyes_set_random(animated_eyes_handle_t handle, bool behavior, bool look, bool blink); +void animated_eyes_set_random(animated_eyes_handle_t handle, bool behavior, + bool look, bool blink); /** * @brief Set the eye color - * - * @param handle Handle to the animated eyes instance + * + * @param handle Handle to the animated + * eyes instance * @param color New eye color */ void animated_eyes_set_color(animated_eyes_handle_t handle, lv_color_t color); /** * @brief Set the background color - * - * @param handle Handle to the animated eyes instance + * + * @param handle Handle to the animated + * eyes instance * @param color New background color */ -void animated_eyes_set_bg_color(animated_eyes_handle_t handle, lv_color_t color); +void animated_eyes_set_bg_color(animated_eyes_handle_t handle, + lv_color_t color); #ifdef __cplusplus } diff --git a/main/animated_eyes_demo.c b/main/animated_eyes_demo.c index f57a4f8..4a32f96 100644 --- a/main/animated_eyes_demo.c +++ b/main/animated_eyes_demo.c @@ -10,101 +10,75 @@ static const char *TAG = "eyes_demo"; static lv_timer_t *update_timer = NULL; -static lv_timer_t *emotion_timer = NULL; static animated_eyes_handle_t eyes_handle = NULL; -static int current_emotion_idx = 0; - -static const char *emotion_names[] = { - "NORMAL", "ANGRY", "GLEE", "HAPPY", "SAD", "WORRIED", - "FOCUSED", "ANNOYED", "SURPRISED", "SKEPTIC", "FRUSTRATED", - "UNIMPRESSED", "SLEEPY", "SUSPICIOUS", "SQUINT", "FURIOUS", - "SCARED", "AWE" -}; // Timer callback for updating eyes static void update_timer_callback(lv_timer_t *timer) { - if (eyes_handle) { - animated_eyes_update(eyes_handle); - } -} - -// Timer callback for cycling emotions -static void emotion_timer_callback(lv_timer_t *timer) { - if (eyes_handle) { - current_emotion_idx = (current_emotion_idx + 1) % EMOTION_COUNT; - animated_eyes_emotion_t next_emotion = (animated_eyes_emotion_t)current_emotion_idx; - - ESP_LOGI(TAG, "Switching emotion to: %s", emotion_names[next_emotion]); - animated_eyes_set_emotion(eyes_handle, next_emotion); - } + if (eyes_handle) { + animated_eyes_update(eyes_handle); + } } animated_eyes_handle_t animated_eyes_demo_start(void) { - ESP_LOGI(TAG, "Starting animated eyes demo"); - - // Get the active screen - lv_obj_t *scr = lv_scr_act(); - - // Set black background - lv_obj_set_style_bg_color(scr, lv_color_black(), 0); - lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0); - - // Configure and create animated eyes - animated_eyes_config_t config = ANIMATED_EYES_DEFAULT_CONFIG(); - - // Customize for your screen (368x448) - config.screen_width = 368; - config.screen_height = 448; - config.eye_size = 120; // Larger eyes to fill the screen better - config.eye_spacing = 20; // Closer together - config.eye_color = lv_color_white(); - config.bg_color = lv_color_black(); - - // Disable random movements for stability - config.random_behavior = false; - config.random_look = false; - config.random_blink = true; // Keep blinking for life - - // Timing settings (unused when random features disabled, but kept for reference) - config.behavior_interval = 6000; - config.look_interval = 3000; - config.blink_interval = 4000; - - eyes_handle = animated_eyes_create(scr, &config); - if (!eyes_handle) { - ESP_LOGE(TAG, "Failed to create animated eyes"); - return NULL; - } - - // Reset emotion index - current_emotion_idx = 0; - - // Create timers - // 1. Update timer: 33ms (approx 30 FPS) for smooth animation - update_timer = lv_timer_create(update_timer_callback, 33, NULL); - - // 2. Emotion cycle timer: 4000ms (4 seconds) to switch emotions - emotion_timer = lv_timer_create(emotion_timer_callback, 4000, NULL); - - ESP_LOGI(TAG, "Animated eyes started successfully"); - return eyes_handle; + ESP_LOGI(TAG, "Starting animated eyes demo"); + + // Get the active screen + lv_obj_t *scr = lv_scr_act(); + + // Set black background + lv_obj_set_style_bg_color(scr, lv_color_black(), 0); + lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0); + + // Configure and create animated eyes + animated_eyes_config_t config = ANIMATED_EYES_DEFAULT_CONFIG(); + + // Customize for your screen (368x448) + config.screen_width = 368; + config.screen_height = 448; + config.eye_size = 120; // Larger eyes to fill the screen better + config.eye_spacing = 20; // Closer together + config.eye_color = lv_color_white(); + config.bg_color = lv_color_black(); + + // Disable random movements for stability + config.random_behavior = false; + config.random_look = false; + config.random_blink = true; // Keep blinking for life + + // Timing settings (unused when random features disabled, but kept for + // reference) + config.behavior_interval = 6000; + config.look_interval = 3000; + config.blink_interval = 4000; + + eyes_handle = animated_eyes_create(scr, &config); + if (!eyes_handle) { + ESP_LOGE(TAG, "Failed to create animated eyes"); + return NULL; + } + + // Create timers + // 1. Update timer: 33ms (approx 30 FPS) for smooth animation + update_timer = lv_timer_create(update_timer_callback, 33, NULL); + + ESP_LOGI(TAG, "Animated eyes started successfully"); + return eyes_handle; +} + +animated_eyes_handle_t animated_eyes_demo_get_handle(void) { + return eyes_handle; } void animated_eyes_demo_stop(animated_eyes_handle_t handle) { - if (update_timer) { - lv_timer_del(update_timer); - update_timer = NULL; - } - - if (emotion_timer) { - lv_timer_del(emotion_timer); - emotion_timer = NULL; - } - - if (handle) { - animated_eyes_delete(handle); - eyes_handle = NULL; - } - - ESP_LOGI(TAG, "Animated eyes demo stopped"); + if (update_timer) { + lv_timer_del(update_timer); + update_timer = NULL; + } + + if (handle) { + animated_eyes_delete(handle); + eyes_handle = NULL; + } + + ESP_LOGI(TAG, "Animated eyes demo stopped"); } diff --git a/main/animated_eyes_demo.h b/main/animated_eyes_demo.h index dae49c7..47f49de 100644 --- a/main/animated_eyes_demo.h +++ b/main/animated_eyes_demo.h @@ -14,17 +14,24 @@ extern "C" { /** * @brief Start the animated eyes demo - * + * * Creates animated eyes on the current screen and starts * the animation. Call animated_eyes_demo_stop() to clean up. - * + * * @return Handle to the animated eyes, or NULL on failure */ animated_eyes_handle_t animated_eyes_demo_start(void); +/** + * @brief Get the current animated eyes handle + * + * @return animated_eyes_handle_t Handle or NULL if not started + */ +animated_eyes_handle_t animated_eyes_demo_get_handle(void); + /** * @brief Stop the animated eyes demo and clean up - * + * * @param handle Handle returned by animated_eyes_demo_start() */ void animated_eyes_demo_stop(animated_eyes_handle_t handle); diff --git a/main/blink_animation.c b/main/blink_animation.c new file mode 100644 index 0000000..838268d --- /dev/null +++ b/main/blink_animation.c @@ -0,0 +1,173 @@ +/** + * @file blink_animation.c + * @brief Embedded blink Lottie animation data + * + * This file contains the blink.json Lottie animation stored as a C string. + * The animation shows two eyes blinking on a 368x448 display at 60fps. + */ + +#include + +// Lottie JSON animation data stored in flash +const char blink_animation_data[] = + "{\"fr\":60,\"h\":448,\"ip\":0,\"layers\":[" + "{\"ind\":3,\"ty\":4,\"parent\":2,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0," + "\"shapes\":[" + "{\"ty\":\"rc\",\"p\":{\"a\":1,\"k\":[" + "{\"t\":0,\"s\":[48.5,68],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":2.952,\"s\":[48.5,13.753],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":5.898,\"s\":[48.5,-2.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":11.802,\"s\":[48.5,0.118],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":17.76,\"s\":[48.5,-0.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":18,\"s\":[48.5,-0.005],\"h\":1}," + "{\"t\":18,\"s\":[48.5,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":20.952,\"s\":[48.5,54.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":23.898,\"s\":[48.5,70.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":29.802,\"s\":[48.5,67.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":35.76,\"s\":[48.5,68.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":36,\"s\":[48.5,68.005],\"h\":1}" + "]},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":1,\"k\":[" + "{\"t\":0,\"s\":[97,136],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":2.952,\"s\":[97,27.505],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":5.898,\"s\":[97,-5.662],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":11.802,\"s\":[97,0.236],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":17.76,\"s\":[97,-0.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":18,\"s\":[97,-0.01],\"h\":1}," + "{\"t\":18,\"s\":[97,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":20.952,\"s\":[97,108.495],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":23.898,\"s\":[97,141.662],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":29.802,\"s\":[97,135.764],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":35.76,\"s\":[97,136.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":36,\"s\":[97,136.01],\"h\":1}" + "]}}," + "{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[1,1,1]},\"o\":{\"a\":0,\"k\":100}}" + "]}," + "{\"ind\":2,\"ty\":3,\"parent\":1,\"ks\":{\"p\":{\"a\":1,\"k\":[" + "{\"t\":0,\"s\":[211,88],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":2.952,\"s\":[211,142.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":5.898,\"s\":[211,158.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":11.802,\"s\":[211,155.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":17.76,\"s\":[211,156.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":18,\"s\":[211,156.005],\"h\":1}," + "{\"t\":18,\"s\":[211,156],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":20.952,\"s\":[211,101.753],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":23.898,\"s\":[211,85.169],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":29.802,\"s\":[211,88.118],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":35.76,\"s\":[211,87.995],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":36,\"s\":[211,87.995],\"h\":1}" + "]}},\"ip\":0,\"op\":37,\"st\":0}," + "{\"ind\":5,\"ty\":4,\"parent\":4,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0," + "\"shapes\":[" + "{\"ty\":\"rc\",\"p\":{\"a\":1,\"k\":[" + "{\"t\":0,\"s\":[48.5,66],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":2.952,\"s\":[48.5,13.348],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":5.898,\"s\":[48.5,-2.748],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":11.802,\"s\":[48.5,0.114],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":17.76,\"s\":[48.5,-0.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":18,\"s\":[48.5,-0.005],\"h\":1}," + "{\"t\":18,\"s\":[48.5,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":20.952,\"s\":[48.5,54.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":23.898,\"s\":[48.5,70.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":29.802,\"s\":[48.5,67.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":35.76,\"s\":[48.5,68.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":36,\"s\":[48.5,68.005],\"h\":1}" + "]},\"r\":{\"a\":0,\"k\":20},\"s\":{\"a\":1,\"k\":[" + "{\"t\":0,\"s\":[97,132],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":2.952,\"s\":[97,26.696],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":5.898,\"s\":[97,-5.496],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":11.802,\"s\":[97,0.229],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":17.76,\"s\":[97,-0.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":18,\"s\":[97,-0.009],\"h\":1}," + "{\"t\":18,\"s\":[97,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":20.952,\"s\":[97,108.495],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":23.898,\"s\":[97,141.662],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":29.802,\"s\":[97,135.764],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":35.76,\"s\":[97,136.01],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":36,\"s\":[97,136.01],\"h\":1}" + "]}}," + "{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[1,1,1]},\"o\":{\"a\":0,\"k\":100}}" + "]}," + "{\"ind\":4,\"ty\":3,\"parent\":1,\"ks\":{\"a\":{\"a\":1,\"k\":[" + "{\"t\":0,\"s\":[48.5,66],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":2.952,\"s\":[48.5,13.348],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":5.898,\"s\":[48.5,-2.748],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":11.802,\"s\":[48.5,0.114],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":17.76,\"s\":[48.5,-0.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":18,\"s\":[48.5,-0.005],\"h\":1}," + "{\"t\":18,\"s\":[48.5,0],\"i\":{\"x\":[1,0.537],\"y\":[1,0.625]},\"o\":{" + "\"x\":[0,0.283],\"y\":[0,0.035]}}," + "{\"t\":20.952,\"s\":[48.5,54.247],\"i\":{\"x\":[1,0.69],\"y\":[1,0.998]}," + "\"o\":{\"x\":[0,0.343],\"y\":[0,0.908]}}," + "{\"t\":23.898,\"s\":[48.5,70.831],\"i\":{\"x\":[1,0.282],\"y\":[1,0.996]}," + "\"o\":{\"x\":[0,0.262],\"y\":[0,0.033]}}," + "{\"t\":29.802,\"s\":[48.5,67.882],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":35.76,\"s\":[48.5,68.005],\"i\":{\"x\":[1,1],\"y\":[1,1]},\"o\":{" + "\"x\":[0,0],\"y\":[0,0]}}," + "{\"t\":36,\"s\":[48.5,68.005],\"h\":1}" + "]},\"p\":{\"a\":0,\"k\":[108.5,157]}},\"ip\":0,\"op\":37,\"st\":0}," + "{\"ind\":1,\"ty\":3,\"parent\":0,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0}," + "{\"ind\":6,\"ty\":4,\"parent\":0,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0," + "\"shapes\":[" + "{\"ty\":\"rc\",\"p\":{\"a\":0,\"k\":[184,224]},\"r\":{\"a\":0,\"k\":0}," + "\"s\":{\"a\":0,\"k\":[368,448]}}," + "{\"ty\":\"fl\",\"c\":{\"a\":0,\"k\":[0,0,0]},\"o\":{\"a\":0,\"k\":100}}" + "]}," + "{\"ind\":0,\"ty\":3,\"ks\":{},\"ip\":0,\"op\":37,\"st\":0}" + "],\"meta\":{\"g\":\"https://" + "jitter.video\"},\"op\":36,\"v\":\"5.7.4\",\"w\":368}"; diff --git a/main/example_qspi_with_ram.c b/main/example_qspi_with_ram.c index 83ecf98..9bf33c7 100644 --- a/main/example_qspi_with_ram.c +++ b/main/example_qspi_with_ram.c @@ -1,24 +1,27 @@ #include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" #include "driver/gpio.h" #include "driver/i2c.h" #include "driver/spi_master.h" -#include "esp_timer.h" -#include "esp_lcd_panel_io.h" -#include "esp_lcd_panel_vendor.h" -#include "esp_lcd_panel_ops.h" #include "esp_err.h" +#include "esp_lcd_panel_io.h" +#include "esp_lcd_panel_ops.h" +#include "esp_lcd_panel_vendor.h" #include "esp_log.h" +#include "esp_timer.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include -#include "lvgl.h" -#include "animated_eyes_demo.h" #include "esp_lcd_sh8601.h" #include "esp_lcd_touch_ft5x06.h" +#include "lottie_player.h" +#include "lvgl.h" + #include "esp_io_expander_tca9554.h" +#include "shake_detector.h" #include "splash_screen.h" static const char *TAG = "example"; @@ -34,7 +37,8 @@ static SemaphoreHandle_t lvgl_mux = NULL; #endif //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// Please update the following configuration according to your LCD spec ////////////////////////////// +//////////////////// Please update the following configuration according to your +/// LCD spec ////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL 1 #define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL @@ -81,331 +85,353 @@ static const sh8601_lcd_init_cmd_t lcd_init_cmds[] = { {0x51, (uint8_t[]){0xFF}, 1, 0}, }; -static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) -{ - lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx; - lv_disp_flush_ready(disp_driver); - return false; +static bool +example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, + esp_lcd_panel_io_event_data_t *edata, + void *user_ctx) { + lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx; + lv_disp_flush_ready(disp_driver); + return false; } -static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) -{ - esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data; - const int offsetx1 = area->x1; - const int offsetx2 = area->x2; - const int offsety1 = area->y1; - const int offsety2 = area->y2; +static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, + lv_color_t *color_map) { + esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data; + const int offsetx1 = area->x1; + const int offsetx2 = area->x2; + const int offsety1 = area->y1; + const int offsety2 = area->y2; #if LCD_BIT_PER_PIXEL == 24 - uint8_t *to = (uint8_t *)color_map; - uint8_t temp = 0; - uint16_t pixel_num = (offsetx2 - offsetx1 + 1) * (offsety2 - offsety1 + 1); + uint8_t *to = (uint8_t *)color_map; + uint8_t temp = 0; + uint16_t pixel_num = (offsetx2 - offsetx1 + 1) * (offsety2 - offsety1 + 1); - // Special dealing for first pixel - temp = color_map[0].ch.blue; - *to++ = color_map[0].ch.red; - *to++ = color_map[0].ch.green; - *to++ = temp; - // Normal dealing for other pixels - for (int i = 1; i < pixel_num; i++) - { - *to++ = color_map[i].ch.red; - *to++ = color_map[i].ch.green; - *to++ = color_map[i].ch.blue; - } + // Special dealing for first pixel + temp = color_map[0].ch.blue; + *to++ = color_map[0].ch.red; + *to++ = color_map[0].ch.green; + *to++ = temp; + // Normal dealing for other pixels + for (int i = 1; i < pixel_num; i++) { + *to++ = color_map[i].ch.red; + *to++ = color_map[i].ch.green; + *to++ = color_map[i].ch.blue; + } #endif - // copy a buffer's content to a specific area of the display - esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map); + // copy a buffer's content to a specific area of the display + esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, + offsety2 + 1, color_map); } -/* Rotate display and touch, when rotated screen in LVGL. Called when driver parameters are updated. */ -static void example_lvgl_update_cb(lv_disp_drv_t *drv) -{ - esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data; +/* Rotate display and touch, when rotated screen in LVGL. Called when driver + * parameters are updated. */ +static void example_lvgl_update_cb(lv_disp_drv_t *drv) { + esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data; - switch (drv->rotated) - { - case LV_DISP_ROT_NONE: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, false); - esp_lcd_panel_mirror(panel_handle, true, false); - break; - case LV_DISP_ROT_90: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, true); - esp_lcd_panel_mirror(panel_handle, true, true); - break; - case LV_DISP_ROT_180: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, false); - esp_lcd_panel_mirror(panel_handle, false, true); - break; - case LV_DISP_ROT_270: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, true); - esp_lcd_panel_mirror(panel_handle, false, false); - break; - } + switch (drv->rotated) { + case LV_DISP_ROT_NONE: + // Rotate LCD display + esp_lcd_panel_swap_xy(panel_handle, false); + esp_lcd_panel_mirror(panel_handle, true, false); + break; + case LV_DISP_ROT_90: + // Rotate LCD display + esp_lcd_panel_swap_xy(panel_handle, true); + esp_lcd_panel_mirror(panel_handle, true, true); + break; + case LV_DISP_ROT_180: + // Rotate LCD display + esp_lcd_panel_swap_xy(panel_handle, false); + esp_lcd_panel_mirror(panel_handle, false, true); + break; + case LV_DISP_ROT_270: + // Rotate LCD display + esp_lcd_panel_swap_xy(panel_handle, true); + esp_lcd_panel_mirror(panel_handle, false, false); + break; + } } -void example_lvgl_rounder_cb(struct _lv_disp_drv_t *disp_drv, lv_area_t *area) -{ - uint16_t x1 = area->x1; - uint16_t x2 = area->x2; +void example_lvgl_rounder_cb(struct _lv_disp_drv_t *disp_drv, lv_area_t *area) { + uint16_t x1 = area->x1; + uint16_t x2 = area->x2; - uint16_t y1 = area->y1; - uint16_t y2 = area->y2; + uint16_t y1 = area->y1; + uint16_t y2 = area->y2; - // round the start of coordinate down to the nearest 2M number - area->x1 = (x1 >> 1) << 1; - area->y1 = (y1 >> 1) << 1; - // round the end of coordinate up to the nearest 2N+1 number - area->x2 = ((x2 >> 1) << 1) + 1; - area->y2 = ((y2 >> 1) << 1) + 1; + // round the start of coordinate down to the nearest 2M number + area->x1 = (x1 >> 1) << 1; + area->y1 = (y1 >> 1) << 1; + // round the end of coordinate up to the nearest 2N+1 number + area->x2 = ((x2 >> 1) << 1) + 1; + area->y2 = ((y2 >> 1) << 1) + 1; } #if EXAMPLE_USE_TOUCH -static void example_lvgl_touch_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) -{ - esp_lcd_touch_handle_t tp = (esp_lcd_touch_handle_t)drv->user_data; - assert(tp); +static void example_lvgl_touch_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) { + esp_lcd_touch_handle_t tp = (esp_lcd_touch_handle_t)drv->user_data; + assert(tp); - uint16_t tp_x; - uint16_t tp_y; - uint8_t tp_cnt = 0; - /* Read data from touch controller into memory */ - esp_lcd_touch_read_data(tp); - /* Read data from touch controller */ - bool tp_pressed = esp_lcd_touch_get_coordinates(tp, &tp_x, &tp_y, NULL, &tp_cnt, 1); - if (tp_pressed && tp_cnt > 0) - { - data->point.x = tp_x; - data->point.y = tp_y; - data->state = LV_INDEV_STATE_PRESSED; - ESP_LOGD(TAG, "Touch position: %d,%d", tp_x, tp_y); - } - else - { - data->state = LV_INDEV_STATE_RELEASED; - } + uint16_t tp_x; + uint16_t tp_y; + uint8_t tp_cnt = 0; + /* Read data from touch controller into memory */ + esp_lcd_touch_read_data(tp); + /* Read data from touch controller */ + bool tp_pressed = + esp_lcd_touch_get_coordinates(tp, &tp_x, &tp_y, NULL, &tp_cnt, 1); + if (tp_pressed && tp_cnt > 0) { + data->point.x = tp_x; + data->point.y = tp_y; + data->state = LV_INDEV_STATE_PRESSED; + ESP_LOGD(TAG, "Touch position: %d,%d", tp_x, tp_y); + } else { + data->state = LV_INDEV_STATE_RELEASED; + } } #endif -static void example_increase_lvgl_tick(void *arg) -{ - /* Tell LVGL how many milliseconds has elapsed */ - lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS); +static void example_increase_lvgl_tick(void *arg) { + /* Tell LVGL how many milliseconds has elapsed */ + lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS); } -static bool example_lvgl_lock(int timeout_ms) -{ - assert(lvgl_mux && "bsp_display_start must be called first"); +static bool example_lvgl_lock(int timeout_ms) { + assert(lvgl_mux && "bsp_display_start must be called first"); - const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); - return xSemaphoreTake(lvgl_mux, timeout_ticks) == pdTRUE; + const TickType_t timeout_ticks = + (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); + return xSemaphoreTake(lvgl_mux, timeout_ticks) == pdTRUE; } -static void example_lvgl_unlock(void) -{ - assert(lvgl_mux && "bsp_display_start must be called first"); - xSemaphoreGive(lvgl_mux); +static void example_lvgl_unlock(void) { + assert(lvgl_mux && "bsp_display_start must be called first"); + xSemaphoreGive(lvgl_mux); } -static void example_lvgl_port_task(void *arg) -{ - ESP_LOGI(TAG, "Starting LVGL task"); - uint32_t task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; - while (1) - { - // Lock the mutex due to the LVGL APIs are not thread-safe - if (example_lvgl_lock(-1)) - { - task_delay_ms = lv_timer_handler(); - // Release the mutex - example_lvgl_unlock(); - } - if (task_delay_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) - { - task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; - } - else if (task_delay_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) - { - task_delay_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS; - } - vTaskDelay(pdMS_TO_TICKS(task_delay_ms)); +static void example_lvgl_port_task(void *arg) { + ESP_LOGI(TAG, "Starting LVGL task"); + uint32_t task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; + + while (1) { + // Lock the mutex due to the LVGL APIs being not thread-safe + if (example_lvgl_lock(-1)) { + task_delay_ms = lv_timer_handler(); + example_lvgl_unlock(); } + + if (task_delay_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) { + task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; + } else if (task_delay_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) { + task_delay_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS; + } + + vTaskDelay(pdMS_TO_TICKS(task_delay_ms)); + } } -void app_main(void) -{ - esp_log_level_set("lcd_panel.io.i2c", ESP_LOG_NONE); - esp_log_level_set("FT5x06", ESP_LOG_NONE); - static lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s) - static lv_disp_drv_t disp_drv; // contains callback functions +static void shake_task(void *arg) { + ESP_LOGI(TAG, "Shake task idle"); + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } +} - ESP_LOGI(TAG, "Initialize I2C bus"); - const i2c_config_t i2c_conf = { - .mode = I2C_MODE_MASTER, - .sda_io_num = EXAMPLE_PIN_NUM_TOUCH_SDA, - .sda_pullup_en = GPIO_PULLUP_ENABLE, - .scl_io_num = EXAMPLE_PIN_NUM_TOUCH_SCL, - .scl_pullup_en = GPIO_PULLUP_ENABLE, - .master.clk_speed = 200 * 1000, - }; - ESP_ERROR_CHECK(i2c_param_config(TOUCH_HOST, &i2c_conf)); - ESP_ERROR_CHECK(i2c_driver_install(TOUCH_HOST, i2c_conf.mode, 0, 0, 0)); +void app_main(void) { + esp_log_level_set("lcd_panel.io.i2c", ESP_LOG_NONE); + esp_log_level_set("FT5x06", ESP_LOG_NONE); + static lv_disp_draw_buf_t + disp_buf; // contains internal graphic buffer(s) called draw buffer(s) + static lv_disp_drv_t disp_drv; // contains callback functions - esp_io_expander_handle_t io_expander = NULL; - esp_io_expander_new_i2c_tca9554(TOUCH_HOST, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander); + ESP_LOGI(TAG, "Initialize I2C bus"); + const i2c_config_t i2c_conf = { + .mode = I2C_MODE_MASTER, + .sda_io_num = EXAMPLE_PIN_NUM_TOUCH_SDA, + .sda_pullup_en = GPIO_PULLUP_ENABLE, + .scl_io_num = EXAMPLE_PIN_NUM_TOUCH_SCL, + .scl_pullup_en = GPIO_PULLUP_ENABLE, + .master.clk_speed = 200 * 1000, + }; + ESP_ERROR_CHECK(i2c_param_config(TOUCH_HOST, &i2c_conf)); + ESP_ERROR_CHECK(i2c_driver_install(TOUCH_HOST, i2c_conf.mode, 0, 0, 0)); - ESP_ERROR_CHECK(esp_io_expander_new_i2c_tca9554(TOUCH_HOST, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander)); + esp_io_expander_handle_t io_expander = NULL; + esp_io_expander_new_i2c_tca9554( + TOUCH_HOST, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander); - esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1 | IO_EXPANDER_PIN_NUM_2, IO_EXPANDER_OUTPUT); - esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0, 0); - esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 0); - esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2, 0); - vTaskDelay(pdMS_TO_TICKS(200)); - esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0, 1); - esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 1); - esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2, 1); + ESP_ERROR_CHECK(esp_io_expander_new_i2c_tca9554( + TOUCH_HOST, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander)); + + esp_io_expander_set_dir(io_expander, + IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1 | + IO_EXPANDER_PIN_NUM_2, + IO_EXPANDER_OUTPUT); + esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0, 0); + esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 0); + esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2, 0); + vTaskDelay(pdMS_TO_TICKS(200)); + esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0, 1); + esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 1); + esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2, 1); #if EXAMPLE_PIN_NUM_BK_LIGHT >= 0 - ESP_LOGI(TAG, "Turn off LCD backlight"); - gpio_config_t bk_gpio_config = { - .mode = GPIO_MODE_OUTPUT, - .pin_bit_mask = 1ULL << EXAMPLE_PIN_NUM_BK_LIGHT}; - ESP_ERROR_CHECK(gpio_config(&bk_gpio_config)); + ESP_LOGI(TAG, "Turn off LCD backlight"); + gpio_config_t bk_gpio_config = {.mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = 1ULL + << EXAMPLE_PIN_NUM_BK_LIGHT}; + ESP_ERROR_CHECK(gpio_config(&bk_gpio_config)); #endif - ESP_LOGI(TAG, "Initialize SPI bus"); - const spi_bus_config_t buscfg = SH8601_PANEL_BUS_QSPI_CONFIG(EXAMPLE_PIN_NUM_LCD_PCLK, - EXAMPLE_PIN_NUM_LCD_DATA0, - EXAMPLE_PIN_NUM_LCD_DATA1, - EXAMPLE_PIN_NUM_LCD_DATA2, - EXAMPLE_PIN_NUM_LCD_DATA3, - EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES * LCD_BIT_PER_PIXEL / 8); - ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO)); + ESP_LOGI(TAG, "Initialize SPI bus"); + const spi_bus_config_t buscfg = SH8601_PANEL_BUS_QSPI_CONFIG( + EXAMPLE_PIN_NUM_LCD_PCLK, EXAMPLE_PIN_NUM_LCD_DATA0, + EXAMPLE_PIN_NUM_LCD_DATA1, EXAMPLE_PIN_NUM_LCD_DATA2, + EXAMPLE_PIN_NUM_LCD_DATA3, + EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES * LCD_BIT_PER_PIXEL / 8); + ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO)); - ESP_LOGI(TAG, "Install panel IO"); - esp_lcd_panel_io_handle_t io_handle = NULL; - const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_QSPI_CONFIG(EXAMPLE_PIN_NUM_LCD_CS, - example_notify_lvgl_flush_ready, - &disp_drv); - sh8601_vendor_config_t vendor_config = { - .init_cmds = lcd_init_cmds, - .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]), - .flags = { - .use_qspi_interface = 1, - }, - }; - // Attach the LCD to the SPI bus - ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &io_config, &io_handle)); + ESP_LOGI(TAG, "Install panel IO"); + esp_lcd_panel_io_handle_t io_handle = NULL; + const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_QSPI_CONFIG( + EXAMPLE_PIN_NUM_LCD_CS, example_notify_lvgl_flush_ready, &disp_drv); + sh8601_vendor_config_t vendor_config = { + .init_cmds = lcd_init_cmds, + .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]), + .flags = + { + .use_qspi_interface = 1, + }, + }; + // Attach the LCD to the SPI bus + ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, + &io_config, &io_handle)); - esp_lcd_panel_handle_t panel_handle = NULL; - const esp_lcd_panel_dev_config_t panel_config = { - .reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST, - .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, - .bits_per_pixel = LCD_BIT_PER_PIXEL, - .vendor_config = &vendor_config, - }; - ESP_LOGI(TAG, "Install SH8601 panel driver"); - ESP_ERROR_CHECK(esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle)); - ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle)); - ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle)); - // user can flush pre-defined pattern to the screen before we turn on the screen or backlight - ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); + esp_lcd_panel_handle_t panel_handle = NULL; + const esp_lcd_panel_dev_config_t panel_config = { + .reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST, + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, + .bits_per_pixel = LCD_BIT_PER_PIXEL, + .vendor_config = &vendor_config, + }; + ESP_LOGI(TAG, "Install SH8601 panel driver"); + ESP_ERROR_CHECK( + esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle)); + ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle)); + ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle)); + // user can flush pre-defined pattern to the screen before we turn on the + // screen or backlight + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); #if EXAMPLE_USE_TOUCH - esp_lcd_panel_io_handle_t tp_io_handle = NULL; - const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG(); - // Attach the TOUCH to the I2C bus - ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TOUCH_HOST, &tp_io_config, &tp_io_handle)); + esp_lcd_panel_io_handle_t tp_io_handle = NULL; + const esp_lcd_panel_io_i2c_config_t tp_io_config = + ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG(); + // Attach the TOUCH to the I2C bus + ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TOUCH_HOST, + &tp_io_config, &tp_io_handle)); - const esp_lcd_touch_config_t tp_cfg = { - .x_max = EXAMPLE_LCD_H_RES, - .y_max = EXAMPLE_LCD_V_RES, - .rst_gpio_num = EXAMPLE_PIN_NUM_TOUCH_RST, - .int_gpio_num = EXAMPLE_PIN_NUM_TOUCH_INT, - .levels = { - .reset = 0, - .interrupt = 0, - }, - .flags = { - .swap_xy = 0, - .mirror_x = 0, - .mirror_y = 0, - }, - }; + const esp_lcd_touch_config_t tp_cfg = { + .x_max = EXAMPLE_LCD_H_RES, + .y_max = EXAMPLE_LCD_V_RES, + .rst_gpio_num = EXAMPLE_PIN_NUM_TOUCH_RST, + .int_gpio_num = EXAMPLE_PIN_NUM_TOUCH_INT, + .levels = + { + .reset = 0, + .interrupt = 0, + }, + .flags = + { + .swap_xy = 0, + .mirror_x = 0, + .mirror_y = 0, + }, + }; - ESP_LOGI(TAG, "Initialize touch controller"); - ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, &tp)); + ESP_LOGI(TAG, "Initialize touch controller"); + ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, &tp)); #endif #if EXAMPLE_PIN_NUM_BK_LIGHT >= 0 - ESP_LOGI(TAG, "Turn on LCD backlight"); - gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL); + ESP_LOGI(TAG, "Turn on LCD backlight"); + gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL); #endif - ESP_LOGI(TAG, "Initialize LVGL library"); - lv_init(); - // alloc draw buffers used by LVGL - // it's recommended to choose the size of the draw buffer(s) to be at least 1/10 screen sized - lv_color_t *buf1 = heap_caps_malloc(EXAMPLE_LCD_H_RES * EXAMPLE_LVGL_BUF_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_DMA); - assert(buf1); - lv_color_t *buf2 = heap_caps_malloc(EXAMPLE_LCD_H_RES * EXAMPLE_LVGL_BUF_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_DMA); - assert(buf2); - // initialize LVGL draw buffers - lv_disp_draw_buf_init(&disp_buf, buf1, buf2, EXAMPLE_LCD_H_RES * EXAMPLE_LVGL_BUF_HEIGHT); + ESP_LOGI(TAG, "Initialize LVGL library"); + lv_init(); + // alloc draw buffers used by LVGL + // it's recommended to choose the size of the draw buffer(s) to be at least + // 1/10 screen sized + lv_color_t *buf1 = heap_caps_malloc( + EXAMPLE_LCD_H_RES * EXAMPLE_LVGL_BUF_HEIGHT * sizeof(lv_color_t), + MALLOC_CAP_DMA); + assert(buf1); + lv_color_t *buf2 = heap_caps_malloc( + EXAMPLE_LCD_H_RES * EXAMPLE_LVGL_BUF_HEIGHT * sizeof(lv_color_t), + MALLOC_CAP_DMA); + assert(buf2); + // initialize LVGL draw buffers + lv_disp_draw_buf_init(&disp_buf, buf1, buf2, + EXAMPLE_LCD_H_RES * EXAMPLE_LVGL_BUF_HEIGHT); - ESP_LOGI(TAG, "Register display driver to LVGL"); - lv_disp_drv_init(&disp_drv); - disp_drv.hor_res = EXAMPLE_LCD_H_RES; - disp_drv.ver_res = EXAMPLE_LCD_V_RES; - disp_drv.flush_cb = example_lvgl_flush_cb; - disp_drv.rounder_cb = example_lvgl_rounder_cb; - disp_drv.drv_update_cb = example_lvgl_update_cb; - disp_drv.draw_buf = &disp_buf; - disp_drv.user_data = panel_handle; - lv_disp_t *disp = lv_disp_drv_register(&disp_drv); + ESP_LOGI(TAG, "Register display driver to LVGL"); + lv_disp_drv_init(&disp_drv); + disp_drv.hor_res = EXAMPLE_LCD_H_RES; + disp_drv.ver_res = EXAMPLE_LCD_V_RES; + disp_drv.flush_cb = example_lvgl_flush_cb; + disp_drv.rounder_cb = example_lvgl_rounder_cb; + disp_drv.drv_update_cb = example_lvgl_update_cb; + disp_drv.draw_buf = &disp_buf; + disp_drv.user_data = panel_handle; + lv_disp_t *disp = lv_disp_drv_register(&disp_drv); - ESP_LOGI(TAG, "Install LVGL tick timer"); - // Tick interface for LVGL (using esp_timer to generate 2ms periodic event) - const esp_timer_create_args_t lvgl_tick_timer_args = { - .callback = &example_increase_lvgl_tick, - .name = "lvgl_tick"}; - esp_timer_handle_t lvgl_tick_timer = NULL; - ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer)); - ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000)); + ESP_LOGI(TAG, "Install LVGL tick timer"); + // Tick interface for LVGL (using esp_timer to generate 2ms periodic event) + const esp_timer_create_args_t lvgl_tick_timer_args = { + .callback = &example_increase_lvgl_tick, .name = "lvgl_tick"}; + esp_timer_handle_t lvgl_tick_timer = NULL; + ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer)); + ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, + EXAMPLE_LVGL_TICK_PERIOD_MS * 1000)); #if EXAMPLE_USE_TOUCH - static lv_indev_drv_t indev_drv; // Input device driver (Touch) - lv_indev_drv_init(&indev_drv); - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.disp = disp; - indev_drv.read_cb = example_lvgl_touch_cb; - indev_drv.user_data = tp; - lv_indev_drv_register(&indev_drv); + static lv_indev_drv_t indev_drv; // Input device driver (Touch) + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.disp = disp; + indev_drv.read_cb = example_lvgl_touch_cb; + indev_drv.user_data = tp; + lv_indev_drv_register(&indev_drv); #endif - lvgl_mux = xSemaphoreCreateMutex(); - assert(lvgl_mux); - xTaskCreate(example_lvgl_port_task, "LVGL", EXAMPLE_LVGL_TASK_STACK_SIZE, NULL, EXAMPLE_LVGL_TASK_PRIORITY, NULL); + lvgl_mux = xSemaphoreCreateMutex(); + assert(lvgl_mux); + xTaskCreate(example_lvgl_port_task, "LVGL", EXAMPLE_LVGL_TASK_STACK_SIZE, + NULL, EXAMPLE_LVGL_TASK_PRIORITY, NULL); - // Lock the mutex due to the LVGL APIs are not thread-safe - if (example_lvgl_lock(-1)) - { - // Show splash screen first - ESP_LOGI(TAG, "Showing splash screen"); - splash_screen_show(); + // Lock the mutex due to the LVGL APIs are not thread-safe + if (example_lvgl_lock(-1)) { + // Show splash screen first + ESP_LOGI(TAG, "Showing splash screen"); + splash_screen_show(); - // Start animated eyes demo - ESP_LOGI(TAG, "Starting animated eyes"); - animated_eyes_demo_start(); + // Start blink animation loop + ESP_LOGI(TAG, "Starting blink animation"); + extern const char blink_animation_data[]; + lottie_create_from_data(lv_scr_act(), blink_animation_data); - // Release the mutex - example_lvgl_unlock(); + // Release the mutex + example_lvgl_unlock(); + + // Initialize Shake Detector + if (shake_detector_init()) { + // Create a task to poll the shake detector + xTaskCreate(shake_task, "shake_task", 4096, NULL, 5, NULL); } + } } \ No newline at end of file diff --git a/main/lottie_player.c b/main/lottie_player.c new file mode 100644 index 0000000..b31e37b --- /dev/null +++ b/main/lottie_player.c @@ -0,0 +1,985 @@ +/** + * @file lottie_player.c + * @brief Lightweight Lottie animation player implementation for LVGL on ESP32 + * + * This implementation provides a minimal Lottie JSON parser and renderer + * optimized for simple shape-based animations. It supports: + * - Rounded rectangle shapes + * - Position, size, and corner radius animation + * - Keyframe interpolation with bezier easing + * - Solid color fills + * + * The parser extracts only the data needed for rendering, minimizing memory + * usage on resource-constrained embedded systems. + */ + +#include "lottie_player.h" +#include "cJSON.h" +#include "esp_heap_caps.h" +#include "esp_log.h" +#include "esp_random.h" +#include "esp_timer.h" +#include +#include +#include + +static const char *TAG = "lottie_player"; + +// Maximum supported keyframes per property (memory optimization) +#define MAX_KEYFRAMES 16 + +// Maximum supported layers in animation +#define MAX_LAYERS 8 + +// Maximum supported shapes per layer +#define MAX_SHAPES 4 + +/** + * Keyframe data structure for animated properties + */ +typedef struct { + float time; // Frame time + float value[2]; // Value at this keyframe (x, y or single value) + float in_tangent[2]; // Bezier in-tangent + float out_tangent[2]; // Bezier out-tangent + bool hold; // If true, hold value until next keyframe +} lottie_keyframe_t; + +/** + * Animated property that can have keyframes or static value + */ +typedef struct { + bool animated; + float static_value[2]; + lottie_keyframe_t keyframes[MAX_KEYFRAMES]; + uint8_t keyframe_count; +} lottie_property_t; + +/** + * Rounded rectangle shape definition + */ +typedef struct { + lottie_property_t position; // Center position + lottie_property_t size; // Width and height + lottie_property_t corner_radius; // Corner radius + lv_color_t fill_color; // Fill color + uint8_t fill_opacity; // Fill opacity (0-100) + bool valid; +} lottie_rounded_rect_t; + +/** + * Layer in the animation + */ +typedef struct { + int index; // Layer index + int parent; // Parent layer index (-1 if none) + int type; // Layer type (3=null, 4=shape) + lottie_property_t position; // Transform position + lottie_property_t anchor; // Anchor point + lottie_rounded_rect_t shapes[MAX_SHAPES]; + uint8_t shape_count; + bool valid; +} lottie_layer_t; + +/** + * Main player state structure + */ +struct lottie_player_t { + // Animation metadata + uint16_t width; + uint16_t height; + float framerate; + uint32_t total_frames; + uint32_t in_point; // Start frame + uint32_t out_point; // End frame + + // Layers + lottie_layer_t layers[MAX_LAYERS]; + uint8_t layer_count; + + // Playback state + float current_frame; + bool playing; + bool loop; + int64_t start_time_us; // Animation start time in microseconds + + // Natural blink mode + bool natural_blink_mode; // If true, shows idle state with random blinks + lv_timer_t *blink_timer; // Timer for triggering random blinks + + // LVGL objects + lv_obj_t *canvas; + lv_color_t *canvas_buf; + lv_timer_t *timer; +}; + +// Forward declarations +static void lottie_parse_animation(lottie_player_handle_t handle, + const cJSON *root); +static void lottie_parse_layers(lottie_player_handle_t handle, + const cJSON *layers); +static void lottie_parse_layer(lottie_layer_t *layer, const cJSON *json); +static void lottie_parse_shapes(lottie_layer_t *layer, const cJSON *shapes); +static void lottie_parse_property(lottie_property_t *prop, const cJSON *json); +static float lottie_interpolate_property(const lottie_property_t *prop, + float frame, int index); +static void lottie_render_frame(lottie_player_handle_t handle); +static void lottie_timer_cb(lv_timer_t *timer); +static void lottie_blink_timer_cb(lv_timer_t *timer); +static void lottie_schedule_next_blink(lottie_player_handle_t handle); +static float lottie_bezier_interpolate(float t, float p0, float p1, float p2, + float p3); + +/** + * Create a Lottie player from JSON data + */ +lottie_player_handle_t lottie_create_from_data(lv_obj_t *parent, + const char *json_data) { + if (!parent || !json_data) { + ESP_LOGE(TAG, "Invalid parameters"); + return NULL; + } + + // Parse JSON + cJSON *root = cJSON_Parse(json_data); + if (!root) { + ESP_LOGE(TAG, "Failed to parse JSON: %s", cJSON_GetErrorPtr()); + return NULL; + } + + // Allocate player structure + lottie_player_handle_t handle = calloc(1, sizeof(struct lottie_player_t)); + if (!handle) { + ESP_LOGE(TAG, "Failed to allocate player"); + cJSON_Delete(root); + return NULL; + } + + // Set defaults + handle->playing = false; + handle->loop = true; + handle->current_frame = 0; + + // Parse animation data + lottie_parse_animation(handle, root); + + // Cleanup JSON (we've extracted what we need) + cJSON_Delete(root); + + // Validate parsed data + if (handle->width == 0 || handle->height == 0 || handle->total_frames == 0) { + ESP_LOGE(TAG, "Invalid animation data"); + free(handle); + return NULL; + } + + ESP_LOGI(TAG, "Parsed animation: %dx%d, %lu frames at %.1f fps", + handle->width, handle->height, (unsigned long)handle->total_frames, + handle->framerate); + ESP_LOGI(TAG, "Loaded %d layers", handle->layer_count); + + // Allocate canvas buffer + size_t buf_size = handle->width * handle->height * sizeof(lv_color_t); + handle->canvas_buf = + heap_caps_malloc(buf_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); + if (!handle->canvas_buf) { + // Try regular RAM if SPIRAM not available + handle->canvas_buf = malloc(buf_size); + } + if (!handle->canvas_buf) { + ESP_LOGE(TAG, "Failed to allocate canvas buffer (%u bytes)", + (unsigned)buf_size); + free(handle); + return NULL; + } + + // Create LVGL canvas + handle->canvas = lv_canvas_create(parent); + lv_canvas_set_buffer(handle->canvas, handle->canvas_buf, handle->width, + handle->height, LV_IMG_CF_TRUE_COLOR); + lv_obj_center(handle->canvas); + + // Speed up animation for snappier blinks (2x speed) + // The canvas rendering is slow (~110ms per frame), so we need faster playback + handle->framerate *= 2.0f; + + // Create timer for animation playback (use faster period for responsiveness) + uint32_t period_ms = 16; // ~60Hz refresh attempts + handle->timer = lv_timer_create(lottie_timer_cb, period_ms, handle); + lv_timer_pause(handle->timer); + + // Enable natural blink mode by default + handle->natural_blink_mode = true; + handle->loop = false; // Don't loop in natural mode + + // Show idle state (last frame = eyes open) + handle->current_frame = handle->total_frames - 1; + lottie_render_frame(handle); + + // Create blink timer with random initial delay (2-5 seconds) + uint32_t initial_delay = 2000 + (esp_random() % 3000); + handle->blink_timer = + lv_timer_create(lottie_blink_timer_cb, initial_delay, handle); + lv_timer_set_repeat_count(handle->blink_timer, + 1); // One-shot, will be recreated + + ESP_LOGI(TAG, "Natural blink mode enabled, first blink in %lu ms", + (unsigned long)initial_delay); + + return handle; +} + +/** + * Parse top-level animation properties + */ +static void lottie_parse_animation(lottie_player_handle_t handle, + const cJSON *root) { + cJSON *item; + + // Width + item = cJSON_GetObjectItem(root, "w"); + if (item && cJSON_IsNumber(item)) { + handle->width = (uint16_t)item->valueint; + } + + // Height + item = cJSON_GetObjectItem(root, "h"); + if (item && cJSON_IsNumber(item)) { + handle->height = (uint16_t)item->valueint; + } + + // Framerate + item = cJSON_GetObjectItem(root, "fr"); + if (item && cJSON_IsNumber(item)) { + handle->framerate = (float)item->valuedouble; + } + + // In point (start frame) + item = cJSON_GetObjectItem(root, "ip"); + if (item && cJSON_IsNumber(item)) { + handle->in_point = (uint32_t)item->valueint; + } + + // Out point (end frame) + item = cJSON_GetObjectItem(root, "op"); + if (item && cJSON_IsNumber(item)) { + handle->out_point = (uint32_t)item->valueint; + } + + handle->total_frames = handle->out_point - handle->in_point; + + // Parse layers + item = cJSON_GetObjectItem(root, "layers"); + if (item && cJSON_IsArray(item)) { + lottie_parse_layers(handle, item); + } +} + +/** + * Parse layers array + */ +static void lottie_parse_layers(lottie_player_handle_t handle, + const cJSON *layers) { + int count = cJSON_GetArraySize(layers); + if (count > MAX_LAYERS) { + ESP_LOGW(TAG, "Truncating %d layers to %d", count, MAX_LAYERS); + count = MAX_LAYERS; + } + + handle->layer_count = 0; + for (int i = 0; i < count; i++) { + cJSON *layer_json = cJSON_GetArrayItem(layers, i); + if (layer_json) { + lottie_layer_t *layer = &handle->layers[handle->layer_count]; + memset(layer, 0, sizeof(lottie_layer_t)); + layer->parent = -1; + lottie_parse_layer(layer, layer_json); + if (layer->valid) { + handle->layer_count++; + } + } + } +} + +/** + * Parse a single layer + */ +static void lottie_parse_layer(lottie_layer_t *layer, const cJSON *json) { + cJSON *item; + + // Layer index + item = cJSON_GetObjectItem(json, "ind"); + if (item && cJSON_IsNumber(item)) { + layer->index = item->valueint; + } + + // Layer type + item = cJSON_GetObjectItem(json, "ty"); + if (item && cJSON_IsNumber(item)) { + layer->type = item->valueint; + } + + // Parent index + item = cJSON_GetObjectItem(json, "parent"); + if (item && cJSON_IsNumber(item)) { + layer->parent = item->valueint; + } + + // Transform (ks) + cJSON *ks = cJSON_GetObjectItem(json, "ks"); + if (ks) { + // Position + item = cJSON_GetObjectItem(ks, "p"); + if (item) { + lottie_parse_property(&layer->position, item); + } + + // Anchor point + item = cJSON_GetObjectItem(ks, "a"); + if (item) { + lottie_parse_property(&layer->anchor, item); + } + } + + // Shapes (for shape layers, type 4) + if (layer->type == 4) { + item = cJSON_GetObjectItem(json, "shapes"); + if (item && cJSON_IsArray(item)) { + lottie_parse_shapes(layer, item); + } + } + + layer->valid = true; +} + +/** + * Parse shapes array for a layer + * Uses two-pass approach: first find fill color, then parse shapes + */ +static void lottie_parse_shapes(lottie_layer_t *layer, const cJSON *shapes) { + int count = cJSON_GetArraySize(shapes); + layer->shape_count = 0; + + // PASS 1: Find fill color (it may come before or after shapes in the array) + lv_color_t fill_color = lv_color_white(); + uint8_t fill_opacity = 100; + bool fill_found = false; + + for (int i = 0; i < count; i++) { + cJSON *shape = cJSON_GetArrayItem(shapes, i); + if (!shape) + continue; + + cJSON *ty = cJSON_GetObjectItem(shape, "ty"); + if (!ty || !cJSON_IsString(ty)) + continue; + + const char *type = ty->valuestring; + + // Fill color + if (strcmp(type, "fl") == 0) { + cJSON *c = cJSON_GetObjectItem(shape, "c"); + if (c) { + cJSON *k = cJSON_GetObjectItem(c, "k"); + if (k && cJSON_IsArray(k) && cJSON_GetArraySize(k) >= 3) { + float r = (float)cJSON_GetArrayItem(k, 0)->valuedouble; + float g = (float)cJSON_GetArrayItem(k, 1)->valuedouble; + float b = (float)cJSON_GetArrayItem(k, 2)->valuedouble; + fill_color = lv_color_make((uint8_t)(r * 255), (uint8_t)(g * 255), + (uint8_t)(b * 255)); + fill_found = true; + ESP_LOGI(TAG, "Found fill: RGB(%.2f,%.2f,%.2f) -> (%d,%d,%d)", r, g, + b, (int)(r * 255), (int)(g * 255), (int)(b * 255)); + } + } + cJSON *o = cJSON_GetObjectItem(shape, "o"); + if (o) { + cJSON *k = cJSON_GetObjectItem(o, "k"); + if (k && cJSON_IsNumber(k)) { + fill_opacity = (uint8_t)k->valueint; + } + } + break; // Found fill, stop searching + } + } + + if (!fill_found) { + ESP_LOGW(TAG, "No fill found for layer, using default white"); + } + + // PASS 2: Parse shapes and apply the found fill color + for (int i = 0; i < count && layer->shape_count < MAX_SHAPES; i++) { + cJSON *shape = cJSON_GetArrayItem(shapes, i); + if (!shape) + continue; + + cJSON *ty = cJSON_GetObjectItem(shape, "ty"); + if (!ty || !cJSON_IsString(ty)) + continue; + + const char *type = ty->valuestring; + + // Rounded rectangle + if (strcmp(type, "rc") == 0) { + lottie_rounded_rect_t *rect = &layer->shapes[layer->shape_count]; + memset(rect, 0, sizeof(lottie_rounded_rect_t)); + + // Position + cJSON *p = cJSON_GetObjectItem(shape, "p"); + if (p) { + lottie_parse_property(&rect->position, p); + } + + // Size + cJSON *s = cJSON_GetObjectItem(shape, "s"); + if (s) { + lottie_parse_property(&rect->size, s); + } + + // Corner radius + cJSON *r = cJSON_GetObjectItem(shape, "r"); + if (r) { + lottie_parse_property(&rect->corner_radius, r); + } + + rect->fill_color = fill_color; + rect->fill_opacity = fill_opacity; + rect->valid = true; + layer->shape_count++; + } + } +} + +/** + * Parse an animated or static property + */ +static void lottie_parse_property(lottie_property_t *prop, const cJSON *json) { + memset(prop, 0, sizeof(lottie_property_t)); + + cJSON *a = cJSON_GetObjectItem(json, "a"); + cJSON *k = cJSON_GetObjectItem(json, "k"); + + if (!k) + return; + + // Check if animated + if (a && cJSON_IsNumber(a) && a->valueint == 1) { + prop->animated = true; + + // Parse keyframes + if (cJSON_IsArray(k)) { + int count = cJSON_GetArraySize(k); + if (count > MAX_KEYFRAMES) { + count = MAX_KEYFRAMES; + } + + for (int i = 0; i < count; i++) { + cJSON *kf = cJSON_GetArrayItem(k, i); + if (!kf) + continue; + + lottie_keyframe_t *keyframe = &prop->keyframes[prop->keyframe_count]; + + // Time + cJSON *t = cJSON_GetObjectItem(kf, "t"); + if (t && cJSON_IsNumber(t)) { + keyframe->time = (float)t->valuedouble; + } + + // Hold + cJSON *h = cJSON_GetObjectItem(kf, "h"); + if (h && cJSON_IsNumber(h)) { + keyframe->hold = h->valueint == 1; + } + + // Start value (s) + cJSON *s = cJSON_GetObjectItem(kf, "s"); + if (s && cJSON_IsArray(s)) { + int vcount = cJSON_GetArraySize(s); + for (int v = 0; v < vcount && v < 2; v++) { + cJSON *val = cJSON_GetArrayItem(s, v); + if (val && cJSON_IsNumber(val)) { + keyframe->value[v] = (float)val->valuedouble; + } + } + } + + // In tangent (i) + cJSON *in_tan = cJSON_GetObjectItem(kf, "i"); + if (in_tan) { + cJSON *x = cJSON_GetObjectItem(in_tan, "x"); + cJSON *y = cJSON_GetObjectItem(in_tan, "y"); + if (x && cJSON_IsArray(x) && cJSON_GetArraySize(x) > 0) { + keyframe->in_tangent[0] = + (float)cJSON_GetArrayItem(x, 0)->valuedouble; + } else if (x && cJSON_IsNumber(x)) { + keyframe->in_tangent[0] = (float)x->valuedouble; + } + if (y && cJSON_IsArray(y) && cJSON_GetArraySize(y) > 0) { + keyframe->in_tangent[1] = + (float)cJSON_GetArrayItem(y, 0)->valuedouble; + } else if (y && cJSON_IsNumber(y)) { + keyframe->in_tangent[1] = (float)y->valuedouble; + } + } + + // Out tangent (o) + cJSON *out_tan = cJSON_GetObjectItem(kf, "o"); + if (out_tan) { + cJSON *x = cJSON_GetObjectItem(out_tan, "x"); + cJSON *y = cJSON_GetObjectItem(out_tan, "y"); + if (x && cJSON_IsArray(x) && cJSON_GetArraySize(x) > 0) { + keyframe->out_tangent[0] = + (float)cJSON_GetArrayItem(x, 0)->valuedouble; + } else if (x && cJSON_IsNumber(x)) { + keyframe->out_tangent[0] = (float)x->valuedouble; + } + if (y && cJSON_IsArray(y) && cJSON_GetArraySize(y) > 0) { + keyframe->out_tangent[1] = + (float)cJSON_GetArrayItem(y, 0)->valuedouble; + } else if (y && cJSON_IsNumber(y)) { + keyframe->out_tangent[1] = (float)y->valuedouble; + } + } + + prop->keyframe_count++; + } + } + } else { + // Static value + prop->animated = false; + if (cJSON_IsArray(k)) { + int count = cJSON_GetArraySize(k); + for (int i = 0; i < count && i < 2; i++) { + cJSON *val = cJSON_GetArrayItem(k, i); + if (val && cJSON_IsNumber(val)) { + prop->static_value[i] = (float)val->valuedouble; + } + } + } else if (cJSON_IsNumber(k)) { + prop->static_value[0] = (float)k->valuedouble; + } + } +} + +/** + * Cubic bezier interpolation + */ +static float lottie_bezier_interpolate(float t, float p0, float p1, float p2, + float p3) { + float u = 1.0f - t; + float tt = t * t; + float uu = u * u; + float uuu = uu * u; + float ttt = tt * t; + + float result = uuu * p0; + result += 3.0f * uu * t * p1; + result += 3.0f * u * tt * p2; + result += ttt * p3; + + return result; +} + +/** + * Interpolate a property value at a given frame + */ +static float lottie_interpolate_property(const lottie_property_t *prop, + float frame, int index) { + if (!prop->animated) { + return prop->static_value[index]; + } + + if (prop->keyframe_count == 0) { + return 0.0f; + } + + // Find surrounding keyframes + const lottie_keyframe_t *prev = NULL; + const lottie_keyframe_t *next = NULL; + + for (int i = 0; i < prop->keyframe_count; i++) { + if (prop->keyframes[i].time <= frame) { + prev = &prop->keyframes[i]; + } + if (prop->keyframes[i].time >= frame && next == NULL) { + next = &prop->keyframes[i]; + } + } + + // Clamp to boundaries + if (!prev) { + return prop->keyframes[0].value[index]; + } + if (!next || prev == next) { + return prev->value[index]; + } + + // Check for hold keyframe + if (prev->hold) { + return prev->value[index]; + } + + // Calculate interpolation factor + float duration = next->time - prev->time; + if (duration <= 0) { + return prev->value[index]; + } + + float t = (frame - prev->time) / duration; + + // Apply bezier easing if tangents are present + if (prev->out_tangent[0] != 0 || prev->out_tangent[1] != 0 || + next->in_tangent[0] != 0 || next->in_tangent[1] != 0) { + // Approximate bezier curve for timing + t = lottie_bezier_interpolate(t, 0.0f, prev->out_tangent[1], + next->in_tangent[1], 1.0f); + t = fmaxf(0.0f, fminf(1.0f, t)); + } + + // Linear interpolation between values + return prev->value[index] + t * (next->value[index] - prev->value[index]); +} + +/** + * Get layer by index + */ +static lottie_layer_t *lottie_get_layer_by_index(lottie_player_handle_t handle, + int index) { + for (int i = 0; i < handle->layer_count; i++) { + if (handle->layers[i].index == index) { + return &handle->layers[i]; + } + } + return NULL; +} + +/** + * Calculate cumulative transform for a layer (following parent chain) + * In Lottie, transform = position - anchor for each layer in the hierarchy + */ +static void lottie_get_layer_transform(lottie_player_handle_t handle, + lottie_layer_t *layer, float frame, + float *offset_x, float *offset_y) { + *offset_x = 0; + *offset_y = 0; + + lottie_layer_t *current = layer; + while (current) { + // Add this layer's position and subtract anchor + float pos_x = lottie_interpolate_property(¤t->position, frame, 0); + float pos_y = lottie_interpolate_property(¤t->position, frame, 1); + float anc_x = lottie_interpolate_property(¤t->anchor, frame, 0); + float anc_y = lottie_interpolate_property(¤t->anchor, frame, 1); + + *offset_x += pos_x - anc_x; + *offset_y += pos_y - anc_y; + + // Follow parent chain + if (current->parent >= 0) { + current = lottie_get_layer_by_index(handle, current->parent); + } else { + current = NULL; + } + } +} + +/** + * Draw a rounded rectangle on the canvas + */ +static void lottie_draw_rounded_rect(lottie_player_handle_t handle, + lv_coord_t x, lv_coord_t y, lv_coord_t w, + lv_coord_t h, lv_coord_t radius, + lv_color_t color) { + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + rect_dsc.bg_color = color; + rect_dsc.bg_opa = LV_OPA_COVER; + rect_dsc.radius = radius; + rect_dsc.border_width = 0; + + lv_area_t area; + area.x1 = x - w / 2; + area.y1 = y - h / 2; + area.x2 = area.x1 + w - 1; + area.y2 = area.y1 + h - 1; + + lv_canvas_draw_rect(handle->canvas, area.x1, area.y1, w, h, &rect_dsc); +} + +/** + * Render current frame to canvas + */ +static void lottie_render_frame(lottie_player_handle_t handle) { + static bool first_frame_logged = false; + + // Clear canvas to black + lv_canvas_fill_bg(handle->canvas, lv_color_black(), LV_OPA_COVER); + + float frame = handle->current_frame + handle->in_point; + + // Render layers in reverse order (last layer = bottom) + for (int i = handle->layer_count - 1; i >= 0; i--) { + lottie_layer_t *layer = &handle->layers[i]; + if (!layer->valid || layer->type != 4) { + continue; + } + + // Get cumulative transform + float offset_x = 0, offset_y = 0; + lottie_get_layer_transform(handle, layer, frame, &offset_x, &offset_y); + + // Render shapes + for (int s = 0; s < layer->shape_count; s++) { + lottie_rounded_rect_t *rect = &layer->shapes[s]; + if (!rect->valid) { + continue; + } + + // Get animated properties + float px = lottie_interpolate_property(&rect->position, frame, 0); + float py = lottie_interpolate_property(&rect->position, frame, 1); + float w = lottie_interpolate_property(&rect->size, frame, 0); + float h = lottie_interpolate_property(&rect->size, frame, 1); + float r = lottie_interpolate_property(&rect->corner_radius, frame, 0); + + // Apply layer offset + px += offset_x; + py += offset_y; + + // Debug logging for first frame + if (!first_frame_logged) { + ESP_LOGI(TAG, + "Layer %d shape %d: pos=(%.1f,%.1f) size=(%.1f,%.1f) " + "radius=%.1f offset=(%.1f,%.1f)", + layer->index, s, px - offset_x, py - offset_y, w, h, r, + offset_x, offset_y); + } + + // Only draw if visible + if (w > 0 && h > 0) { + lottie_draw_rounded_rect(handle, (lv_coord_t)px, (lv_coord_t)py, + (lv_coord_t)w, (lv_coord_t)h, (lv_coord_t)r, + rect->fill_color); + } + } + } + + if (!first_frame_logged) { + first_frame_logged = true; + } + + // Invalidate canvas to trigger redraw + lv_obj_invalidate(handle->canvas); +} + +/** + * Timer callback for animation playback + * Uses time-based animation for accurate playback speed + */ +static void lottie_timer_cb(lv_timer_t *timer) { + lottie_player_handle_t handle = (lottie_player_handle_t)timer->user_data; + if (!handle || !handle->playing) { + return; + } + + // Calculate current frame based on elapsed time + int64_t now_us = esp_timer_get_time(); + int64_t elapsed_us = now_us - handle->start_time_us; + float elapsed_sec = (float)elapsed_us / 1000000.0f; + float frame = elapsed_sec * handle->framerate; + + // Debug: log first few frames + static int frame_log_count = 0; + if (frame_log_count < 5) { + ESP_LOGI(TAG, "Frame calc: elapsed=%.3fs, frame=%.1f/%lu", elapsed_sec, + frame, (unsigned long)handle->total_frames); + frame_log_count++; + } + + // Handle end of animation + if (frame >= handle->total_frames) { + if (handle->loop) { + // Reset start time for smooth looping + float cycles = frame / handle->total_frames; + int full_cycles = (int)cycles; + handle->start_time_us += (int64_t)(full_cycles * handle->total_frames / + handle->framerate * 1000000.0f); + frame = frame - (full_cycles * handle->total_frames); + } else { + // Animation complete - return to idle state + ESP_LOGI(TAG, "Blink animation complete after %.3fs", elapsed_sec); + frame_log_count = 0; // Reset for next blink + + handle->playing = false; + lv_timer_pause(handle->timer); + handle->current_frame = handle->total_frames - 1; // Eyes open + lottie_render_frame(handle); + + // Schedule next blink if in natural mode + if (handle->natural_blink_mode) { + lottie_schedule_next_blink(handle); + } + return; + } + } + + handle->current_frame = frame; + + // Render the new frame + lottie_render_frame(handle); +} + +/** + * Schedule next random blink + */ +static void lottie_schedule_next_blink(lottie_player_handle_t handle) { + if (!handle || !handle->natural_blink_mode) { + return; + } + + // Random delay between 3-6 seconds for natural feel + uint32_t delay_ms = 3000 + (esp_random() % 3000); + + // Create new timer (old one was already deleted or is NULL) + handle->blink_timer = + lv_timer_create(lottie_blink_timer_cb, delay_ms, handle); + lv_timer_set_repeat_count(handle->blink_timer, 1); +} + +/** + * Blink timer callback - triggers a blink animation + */ +static void lottie_blink_timer_cb(lv_timer_t *timer) { + lottie_player_handle_t handle = (lottie_player_handle_t)timer->user_data; + + // Mark timer as gone (one-shot timers auto-delete after callback returns) + if (handle) { + handle->blink_timer = NULL; + } + + if (!handle || !handle->natural_blink_mode) { + return; + } + + // Start blink animation from frame 0 + ESP_LOGI(TAG, "Blink triggered! Starting animation from frame 0"); + handle->current_frame = 0; + lottie_play(handle); +} + +/** + * Start/resume playback + */ +void lottie_play(lottie_player_handle_t handle) { + if (!handle) + return; + + // Set start time for time-based animation + // Adjust for current frame position if resuming + int64_t frame_offset_us = + (int64_t)(handle->current_frame / handle->framerate * 1000000.0f); + handle->start_time_us = esp_timer_get_time() - frame_offset_us; + + handle->playing = true; + lv_timer_resume(handle->timer); +} + +/** + * Pause playback + */ +void lottie_pause(lottie_player_handle_t handle) { + if (!handle) + return; + handle->playing = false; + lv_timer_pause(handle->timer); +} + +/** + * Stop playback and reset to first frame + */ +void lottie_stop(lottie_player_handle_t handle) { + if (!handle) + return; + handle->playing = false; + handle->current_frame = 0; + lv_timer_pause(handle->timer); + lottie_render_frame(handle); +} + +/** + * Set loop mode + */ +void lottie_set_loop(lottie_player_handle_t handle, bool loop) { + if (!handle) + return; + handle->loop = loop; +} + +/** + * Check if playing + */ +bool lottie_is_playing(lottie_player_handle_t handle) { + if (!handle) + return false; + return handle->playing; +} + +/** + * Get current frame number + */ +uint32_t lottie_get_current_frame(lottie_player_handle_t handle) { + if (!handle) + return 0; + return (uint32_t)handle->current_frame; +} + +/** + * Get total frame count + */ +uint32_t lottie_get_total_frames(lottie_player_handle_t handle) { + if (!handle) + return 0; + return handle->total_frames; +} + +/** + * Set current frame + */ +void lottie_set_frame(lottie_player_handle_t handle, uint32_t frame) { + if (!handle) + return; + if (frame >= handle->total_frames) { + frame = handle->total_frames - 1; + } + handle->current_frame = (float)frame; + lottie_render_frame(handle); +} + +/** + * Destroy player and free resources + */ +void lottie_destroy(lottie_player_handle_t handle) { + if (!handle) + return; + + // Stop timer + if (handle->timer) { + lv_timer_del(handle->timer); + } + + // Delete canvas + if (handle->canvas) { + lv_obj_del(handle->canvas); + } + + // Free canvas buffer + if (handle->canvas_buf) { + free(handle->canvas_buf); + } + + // Free player structure + free(handle); + + ESP_LOGI(TAG, "Lottie player destroyed"); +} diff --git a/main/lottie_player.h b/main/lottie_player.h new file mode 100644 index 0000000..346dc5f --- /dev/null +++ b/main/lottie_player.h @@ -0,0 +1,113 @@ +/** + * @file lottie_player.h + * @brief Lightweight Lottie animation player for LVGL on ESP32 + * + * This module provides a minimal Lottie JSON animation player optimized for + * embedded systems. It supports basic shape types (rounded rectangles) with + * keyframe animation and bezier curve interpolation. + * + * Designed for simple animations like blinking eyes on resource-constrained + * devices. Does not support the full Lottie specification. + */ + +#ifndef LOTTIE_PLAYER_H +#define LOTTIE_PLAYER_H + +#include "lvgl.h" +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Forward declaration of internal structure +typedef struct lottie_player_t *lottie_player_handle_t; + +/** + * @brief Create a Lottie animation player from embedded JSON data + * + * Parses the Lottie JSON and creates an LVGL object hierarchy for rendering. + * The animation starts in paused state - call lottie_play() to begin playback. + * + * @param parent Parent LVGL object to attach the animation to + * @param json_data Pointer to null-terminated JSON string in flash + * @return Handle to the player instance, or NULL on failure + */ +lottie_player_handle_t lottie_create_from_data(lv_obj_t *parent, + const char *json_data); + +/** + * @brief Start or resume animation playback + * + * @param handle Handle to the Lottie player instance + */ +void lottie_play(lottie_player_handle_t handle); + +/** + * @brief Pause animation playback + * + * @param handle Handle to the Lottie player instance + */ +void lottie_pause(lottie_player_handle_t handle); + +/** + * @brief Stop animation and reset to first frame + * + * @param handle Handle to the Lottie player instance + */ +void lottie_stop(lottie_player_handle_t handle); + +/** + * @brief Set whether the animation should loop + * + * @param handle Handle to the Lottie player instance + * @param loop True to enable looping, false for single playthrough + */ +void lottie_set_loop(lottie_player_handle_t handle, bool loop); + +/** + * @brief Check if animation is currently playing + * + * @param handle Handle to the Lottie player instance + * @return True if playing, false if paused or stopped + */ +bool lottie_is_playing(lottie_player_handle_t handle); + +/** + * @brief Get the current frame number + * + * @param handle Handle to the Lottie player instance + * @return Current frame number (0-indexed) + */ +uint32_t lottie_get_current_frame(lottie_player_handle_t handle); + +/** + * @brief Get total number of frames in the animation + * + * @param handle Handle to the Lottie player instance + * @return Total frame count + */ +uint32_t lottie_get_total_frames(lottie_player_handle_t handle); + +/** + * @brief Set the current frame manually + * + * @param handle Handle to the Lottie player instance + * @param frame Frame number to seek to (clamped to valid range) + */ +void lottie_set_frame(lottie_player_handle_t handle, uint32_t frame); + +/** + * @brief Destroy the Lottie player and free all resources + * + * @param handle Handle to the Lottie player instance + */ +void lottie_destroy(lottie_player_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* LOTTIE_PLAYER_H */ diff --git a/main/shake_detector.cpp b/main/shake_detector.cpp new file mode 100644 index 0000000..16a8ad8 --- /dev/null +++ b/main/shake_detector.cpp @@ -0,0 +1,213 @@ +/** + * @file shake_detector.cpp + * @brief Shake detection implementation using SensorLib QMI8658 + */ + +#include "shake_detector.h" +#include "SensorQMI8658.hpp" +#include "esp_log.h" +#include "esp_timer.h" +#include + +static const char *TAG = "shake_detector"; + +// Sensor instance +static SensorQMI8658 qmi; + +// I2C Pins (Matches example_qspi_with_ram.c) +#define I2C_MASTER_SCL 14 +#define I2C_MASTER_SDA 15 +#define I2C_MASTER_NUM I2C_NUM_0 +#define QMI8658_ADDR 0x6B + +// Shake detection thresholds +#define SHAKE_ACCEL_THRESHOLD 0.5f // 0.5G deviation from baseline +#define SHAKE_DEBOUNCE_MS 2000 // Debounce time between detections +#define BASELINE_SAMPLES 10 // Number of samples to average for baseline + +static uint32_t last_trigger_time = 0; +// Store latest readings and baseline +static float last_acc_x = 0, last_acc_y = 0, last_acc_z = 0; +static float baseline_x = 0, baseline_y = 0, baseline_z = 0; +static bool baseline_ready = false; + +static uint32_t get_millis() { return (uint32_t)(esp_timer_get_time() / 1000); } + +extern "C" bool shake_detector_init(void) { + ESP_LOGI(TAG, "Initializing Shake Detector (QMI8658)"); + + // Initialize sensor (I2C driver already installed by main app) + if (!qmi.begin(I2C_MASTER_NUM, QMI8658_ADDR, I2C_MASTER_SDA, + I2C_MASTER_SCL)) { + ESP_LOGE(TAG, "Failed to initialize QMI8658!"); + return false; + } + + uint8_t chip_id = qmi.getChipID(); + ESP_LOGI(TAG, "✓ Sensor initialized. Chip ID: 0x%02x", chip_id); + + // Configure accelerometer (match vendor demo settings exactly) + ESP_LOGI(TAG, "Configuring accelerometer (4G, 1000Hz, LPF_MODE_0)..."); + int ret_accel = qmi.configAccelerometer(SensorQMI8658::ACC_RANGE_4G, + SensorQMI8658::ACC_ODR_1000Hz, + SensorQMI8658::LPF_MODE_0, true); + if (ret_accel != 0) { + ESP_LOGE(TAG, "Failed to configure accelerometer: %d", ret_accel); + return false; + } + ESP_LOGI(TAG, "✓ Accelerometer configured"); + + // Configure gyroscope (match vendor demo settings) + ESP_LOGI(TAG, "Configuring gyroscope (64DPS, 896.8Hz, LPF_MODE_3)..."); + int ret_gyro = qmi.configGyroscope(SensorQMI8658::GYR_RANGE_64DPS, + SensorQMI8658::GYR_ODR_896_8Hz, + SensorQMI8658::LPF_MODE_3, true); + if (ret_gyro != 0) { + ESP_LOGW(TAG, "Gyroscope config failed: %d (will continue)", ret_gyro); + } else { + ESP_LOGI(TAG, "✓ Gyroscope configured"); + } + + // Enable sensors (gyro first, then accel - as in vendor demo) + // Enable sensors (vendor demo doesn't check return values - they're buggy in SensorLib) + // The SensorLib enable functions have backwards logic: they return bool but compare to DEV_WIRE_NONE (0) + // This causes them to always appear to fail even when they succeed + qmi.enableGyroscope(); + qmi.enableAccelerometer(); + + ESP_LOGI(TAG, "✓ Gyroscope enabled"); + ESP_LOGI(TAG, "✓ Accelerometer enabled"); + + // Test reading + vTaskDelay(pdMS_TO_TICKS(50)); + if (qmi.getDataReady()) { + float test_x, test_y, test_z; + if (qmi.getAccelerometer(test_x, test_y, test_z)) { + ESP_LOGI(TAG, "✓ First reading OK: x=%.3f y=%.3f z=%.3f", test_x, test_y, test_z); + } else { + ESP_LOGW(TAG, "Data ready but read failed"); + } + } else { + ESP_LOGW(TAG, "Sensor not ready for first read"); + } + + baseline_ready = false; + ESP_LOGI(TAG, "Shake Detector ready. Calibrating baseline..."); + return true; +} + +extern "C" shake_event_t shake_detector_update(void) { + uint32_t now = get_millis(); + + if (!qmi.getDataReady()) { + // Log occasionally if data is not ready, to see if sensor is stuck + static uint32_t last_not_ready_time = 0; + if (now - last_not_ready_time > 3000) { + ESP_LOGW(TAG, "QMI8658 Data Not Ready - sensor may be unresponsive"); + last_not_ready_time = now; + } + return SHAKE_NONE; + } + + float x, y, z; + if (!qmi.getAccelerometer(x, y, z)) { + static uint32_t last_read_fail_time = 0; + if (now - last_read_fail_time > 3000) { + ESP_LOGW(TAG, "Failed to read accelerometer data"); + last_read_fail_time = now; + } + return SHAKE_NONE; + } + + last_acc_x = x; + last_acc_y = y; + last_acc_z = z; + + // Baseline calibration: collect first N samples to establish device orientation + if (!baseline_ready) { + static uint32_t baseline_count = 0; + static float baseline_sum_x = 0, baseline_sum_y = 0, baseline_sum_z = 0; + + baseline_sum_x += x; + baseline_sum_y += y; + baseline_sum_z += z; + baseline_count++; + + ESP_LOGI(TAG, "[%2d/10] x=%+.3f y=%+.3f z=%+.3f", + baseline_count, x, y, z); + + if (baseline_count >= BASELINE_SAMPLES) { + baseline_x = baseline_sum_x / BASELINE_SAMPLES; + baseline_y = baseline_sum_y / BASELINE_SAMPLES; + baseline_z = baseline_sum_z / BASELINE_SAMPLES; + baseline_ready = true; + baseline_count = 0; + baseline_sum_x = baseline_sum_y = baseline_sum_z = 0; + + ESP_LOGI(TAG, "✓ Baseline: x=%+.3f y=%+.3f z=%+.3f (magnitude: %.3f)", + baseline_x, baseline_y, baseline_z, + sqrtf(baseline_x*baseline_x + baseline_y*baseline_y + baseline_z*baseline_z)); + } + return SHAKE_NONE; + } + + // Calculate deviation from baseline + float delta_x = x - baseline_x; + float delta_y = y - baseline_y; + float delta_z = z - baseline_z; + float deviation = sqrtf(delta_x * delta_x + delta_y * delta_y + delta_z * delta_z); + + // Log raw values every 1 second for monitoring + static uint32_t last_log_time = 0; + if (now - last_log_time > 1000) { + ESP_LOGI(TAG, "ACCEL: x=%+.3f y=%+.3f z=%+.3f | Δ=%+.3f", + x, y, z, deviation); + last_log_time = now; + } + + // Debounce: ignore if we just triggered a shake + if (now - last_trigger_time < SHAKE_DEBOUNCE_MS) { + return SHAKE_NONE; + } + + // Detect shake: acceleration deviation exceeds threshold + if (deviation > SHAKE_ACCEL_THRESHOLD) { + ESP_LOGI(TAG, "SHAKE! Δ=%.3f > Thr=%.3f | accel:[%+.2f,%+.2f,%+.2f]", + deviation, SHAKE_ACCEL_THRESHOLD, x, y, z); + + last_trigger_time = now; + + // Pick a random emotion for the shake + int r = rand() % 3; + switch (r) { + case 0: + ESP_LOGI(TAG, "→ Emotion: SURPRISED"); + return SHAKE_SURPRISED; + case 1: + ESP_LOGI(TAG, "→ Emotion: SAD"); + return SHAKE_SAD; + case 2: + ESP_LOGI(TAG, "→ Emotion: ANGRY"); + return SHAKE_ANGRY; + default: + return SHAKE_SURPRISED; + } + } + + return SHAKE_NONE; +} + +extern "C" bool shake_detector_get_raw_accel(float *x, float *y, float *z) { + if (!qmi.getDataReady()) { + return false; + } + + if (!qmi.getAccelerometer(*x, *y, *z)) { + return false; + } + + last_acc_x = *x; + last_acc_y = *y; + last_acc_z = *z; + return true; +} diff --git a/main/shake_detector.h b/main/shake_detector.h new file mode 100644 index 0000000..f4f4ae7 --- /dev/null +++ b/main/shake_detector.h @@ -0,0 +1,50 @@ +/** + * @file shake_detector.h + * @brief Shake detection using QMI8658 sensor + */ + +#ifndef SHAKE_DETECTOR_H +#define SHAKE_DETECTOR_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Configuration types of shakes +typedef enum { + SHAKE_NONE = 0, + SHAKE_SURPRISED, + SHAKE_SAD, + SHAKE_ANGRY, + SHAKE_COUNT +} shake_event_t; + +/** + * @brief Initialize the shake detector and QMI8658 sensor + * @return true on success, false on failure + */ +bool shake_detector_init(void); + +/** + * @brief Check for shake events. Call this loop periodically. + * @return Detected shake event, or SHAKE_NONE + */ +shake_event_t shake_detector_update(void); + +/** + * @brief Get the latest raw accelerometer reading + * @param x Pointer to store X acceleration + * @param y Pointer to store Y acceleration + * @param z Pointer to store Z acceleration + * @return true if data is available + */ +bool shake_detector_get_raw_accel(float *x, float *y, float *z); + +#ifdef __cplusplus +} +#endif + +#endif // SHAKE_DETECTOR_H